echarts.esm.mjs 3.2 MB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092209320942095209620972098209921002101210221032104210521062107210821092110211121122113211421152116211721182119212021212122212321242125212621272128212921302131213221332134213521362137213821392140214121422143214421452146214721482149215021512152215321542155215621572158215921602161216221632164216521662167216821692170217121722173217421752176217721782179218021812182218321842185218621872188218921902191219221932194219521962197219821992200220122022203220422052206220722082209221022112212221322142215221622172218221922202221222222232224222522262227222822292230223122322233223422352236223722382239224022412242224322442245224622472248224922502251225222532254225522562257225822592260226122622263226422652266226722682269227022712272227322742275227622772278227922802281228222832284228522862287228822892290229122922293229422952296229722982299230023012302230323042305230623072308230923102311231223132314231523162317231823192320232123222323232423252326232723282329233023312332233323342335233623372338233923402341234223432344234523462347234823492350235123522353235423552356235723582359236023612362236323642365236623672368236923702371237223732374237523762377237823792380238123822383238423852386238723882389239023912392239323942395239623972398239924002401240224032404240524062407240824092410241124122413241424152416241724182419242024212422242324242425242624272428242924302431243224332434243524362437243824392440244124422443244424452446244724482449245024512452245324542455245624572458245924602461246224632464246524662467246824692470247124722473247424752476247724782479248024812482248324842485248624872488248924902491249224932494249524962497249824992500250125022503250425052506250725082509251025112512251325142515251625172518251925202521252225232524252525262527252825292530253125322533253425352536253725382539254025412542254325442545254625472548254925502551255225532554255525562557255825592560256125622563256425652566256725682569257025712572257325742575257625772578257925802581258225832584258525862587258825892590259125922593259425952596259725982599260026012602260326042605260626072608260926102611261226132614261526162617261826192620262126222623262426252626262726282629263026312632263326342635263626372638263926402641264226432644264526462647264826492650265126522653265426552656265726582659266026612662266326642665266626672668266926702671267226732674267526762677267826792680268126822683268426852686268726882689269026912692269326942695269626972698269927002701270227032704270527062707270827092710271127122713271427152716271727182719272027212722272327242725272627272728272927302731273227332734273527362737273827392740274127422743274427452746274727482749275027512752275327542755275627572758275927602761276227632764276527662767276827692770277127722773277427752776277727782779278027812782278327842785278627872788278927902791279227932794279527962797279827992800280128022803280428052806280728082809281028112812281328142815281628172818281928202821282228232824282528262827282828292830283128322833283428352836283728382839284028412842284328442845284628472848284928502851285228532854285528562857285828592860286128622863286428652866286728682869287028712872287328742875287628772878287928802881288228832884288528862887288828892890289128922893289428952896289728982899290029012902290329042905290629072908290929102911291229132914291529162917291829192920292129222923292429252926292729282929293029312932293329342935293629372938293929402941294229432944294529462947294829492950295129522953295429552956295729582959296029612962296329642965296629672968296929702971297229732974297529762977297829792980298129822983298429852986298729882989299029912992299329942995299629972998299930003001300230033004300530063007300830093010301130123013301430153016301730183019302030213022302330243025302630273028302930303031303230333034303530363037303830393040304130423043304430453046304730483049305030513052305330543055305630573058305930603061306230633064306530663067306830693070307130723073307430753076307730783079308030813082308330843085308630873088308930903091309230933094309530963097309830993100310131023103310431053106310731083109311031113112311331143115311631173118311931203121312231233124312531263127312831293130313131323133313431353136313731383139314031413142314331443145314631473148314931503151315231533154315531563157315831593160316131623163316431653166316731683169317031713172317331743175317631773178317931803181318231833184318531863187318831893190319131923193319431953196319731983199320032013202320332043205320632073208320932103211321232133214321532163217321832193220322132223223322432253226322732283229323032313232323332343235323632373238323932403241324232433244324532463247324832493250325132523253325432553256325732583259326032613262326332643265326632673268326932703271327232733274327532763277327832793280328132823283328432853286328732883289329032913292329332943295329632973298329933003301330233033304330533063307330833093310331133123313331433153316331733183319332033213322332333243325332633273328332933303331333233333334333533363337333833393340334133423343334433453346334733483349335033513352335333543355335633573358335933603361336233633364336533663367336833693370337133723373337433753376337733783379338033813382338333843385338633873388338933903391339233933394339533963397339833993400340134023403340434053406340734083409341034113412341334143415341634173418341934203421342234233424342534263427342834293430343134323433343434353436343734383439344034413442344334443445344634473448344934503451345234533454345534563457345834593460346134623463346434653466346734683469347034713472347334743475347634773478347934803481348234833484348534863487348834893490349134923493349434953496349734983499350035013502350335043505350635073508350935103511351235133514351535163517351835193520352135223523352435253526352735283529353035313532353335343535353635373538353935403541354235433544354535463547354835493550355135523553355435553556355735583559356035613562356335643565356635673568356935703571357235733574357535763577357835793580358135823583358435853586358735883589359035913592359335943595359635973598359936003601360236033604360536063607360836093610361136123613361436153616361736183619362036213622362336243625362636273628362936303631363236333634363536363637363836393640364136423643364436453646364736483649365036513652365336543655365636573658365936603661366236633664366536663667366836693670367136723673367436753676367736783679368036813682368336843685368636873688368936903691369236933694369536963697369836993700370137023703370437053706370737083709371037113712371337143715371637173718371937203721372237233724372537263727372837293730373137323733373437353736373737383739374037413742374337443745374637473748374937503751375237533754375537563757375837593760376137623763376437653766376737683769377037713772377337743775377637773778377937803781378237833784378537863787378837893790379137923793379437953796379737983799380038013802380338043805380638073808380938103811381238133814381538163817381838193820382138223823382438253826382738283829383038313832383338343835383638373838383938403841384238433844384538463847384838493850385138523853385438553856385738583859386038613862386338643865386638673868386938703871387238733874387538763877387838793880388138823883388438853886388738883889389038913892389338943895389638973898389939003901390239033904390539063907390839093910391139123913391439153916391739183919392039213922392339243925392639273928392939303931393239333934393539363937393839393940394139423943394439453946394739483949395039513952395339543955395639573958395939603961396239633964396539663967396839693970397139723973397439753976397739783979398039813982398339843985398639873988398939903991399239933994399539963997399839994000400140024003400440054006400740084009401040114012401340144015401640174018401940204021402240234024402540264027402840294030403140324033403440354036403740384039404040414042404340444045404640474048404940504051405240534054405540564057405840594060406140624063406440654066406740684069407040714072407340744075407640774078407940804081408240834084408540864087408840894090409140924093409440954096409740984099410041014102410341044105410641074108410941104111411241134114411541164117411841194120412141224123412441254126412741284129413041314132413341344135413641374138413941404141414241434144414541464147414841494150415141524153415441554156415741584159416041614162416341644165416641674168416941704171417241734174417541764177417841794180418141824183418441854186418741884189419041914192419341944195419641974198419942004201420242034204420542064207420842094210421142124213421442154216421742184219422042214222422342244225422642274228422942304231423242334234423542364237423842394240424142424243424442454246424742484249425042514252425342544255425642574258425942604261426242634264426542664267426842694270427142724273427442754276427742784279428042814282428342844285428642874288428942904291429242934294429542964297429842994300430143024303430443054306430743084309431043114312431343144315431643174318431943204321432243234324432543264327432843294330433143324333433443354336433743384339434043414342434343444345434643474348434943504351435243534354435543564357435843594360436143624363436443654366436743684369437043714372437343744375437643774378437943804381438243834384438543864387438843894390439143924393439443954396439743984399440044014402440344044405440644074408440944104411441244134414441544164417441844194420442144224423442444254426442744284429443044314432443344344435443644374438443944404441444244434444444544464447444844494450445144524453445444554456445744584459446044614462446344644465446644674468446944704471447244734474447544764477447844794480448144824483448444854486448744884489449044914492449344944495449644974498449945004501450245034504450545064507450845094510451145124513451445154516451745184519452045214522452345244525452645274528452945304531453245334534453545364537453845394540454145424543454445454546454745484549455045514552455345544555455645574558455945604561456245634564456545664567456845694570457145724573457445754576457745784579458045814582458345844585458645874588458945904591459245934594459545964597459845994600460146024603460446054606460746084609461046114612461346144615461646174618461946204621462246234624462546264627462846294630463146324633463446354636463746384639464046414642464346444645464646474648464946504651465246534654465546564657465846594660466146624663466446654666466746684669467046714672467346744675467646774678467946804681468246834684468546864687468846894690469146924693469446954696469746984699470047014702470347044705470647074708470947104711471247134714471547164717471847194720472147224723472447254726472747284729473047314732473347344735473647374738473947404741474247434744474547464747474847494750475147524753475447554756475747584759476047614762476347644765476647674768476947704771477247734774477547764777477847794780478147824783478447854786478747884789479047914792479347944795479647974798479948004801480248034804480548064807480848094810481148124813481448154816481748184819482048214822482348244825482648274828482948304831483248334834483548364837483848394840484148424843484448454846484748484849485048514852485348544855485648574858485948604861486248634864486548664867486848694870487148724873487448754876487748784879488048814882488348844885488648874888488948904891489248934894489548964897489848994900490149024903490449054906490749084909491049114912491349144915491649174918491949204921492249234924492549264927492849294930493149324933493449354936493749384939494049414942494349444945494649474948494949504951495249534954495549564957495849594960496149624963496449654966496749684969497049714972497349744975497649774978497949804981498249834984498549864987498849894990499149924993499449954996499749984999500050015002500350045005500650075008500950105011501250135014501550165017501850195020502150225023502450255026502750285029503050315032503350345035503650375038503950405041504250435044504550465047504850495050505150525053505450555056505750585059506050615062506350645065506650675068506950705071507250735074507550765077507850795080508150825083508450855086508750885089509050915092509350945095509650975098509951005101510251035104510551065107510851095110511151125113511451155116511751185119512051215122512351245125512651275128512951305131513251335134513551365137513851395140514151425143514451455146514751485149515051515152515351545155515651575158515951605161516251635164516551665167516851695170517151725173517451755176517751785179518051815182518351845185518651875188518951905191519251935194519551965197519851995200520152025203520452055206520752085209521052115212521352145215521652175218521952205221522252235224522552265227522852295230523152325233523452355236523752385239524052415242524352445245524652475248524952505251525252535254525552565257525852595260526152625263526452655266526752685269527052715272527352745275527652775278527952805281528252835284528552865287528852895290529152925293529452955296529752985299530053015302530353045305530653075308530953105311531253135314531553165317531853195320532153225323532453255326532753285329533053315332533353345335533653375338533953405341534253435344534553465347534853495350535153525353535453555356535753585359536053615362536353645365536653675368536953705371537253735374537553765377537853795380538153825383538453855386538753885389539053915392539353945395539653975398539954005401540254035404540554065407540854095410541154125413541454155416541754185419542054215422542354245425542654275428542954305431543254335434543554365437543854395440544154425443544454455446544754485449545054515452545354545455545654575458545954605461546254635464546554665467546854695470547154725473547454755476547754785479548054815482548354845485548654875488548954905491549254935494549554965497549854995500550155025503550455055506550755085509551055115512551355145515551655175518551955205521552255235524552555265527552855295530553155325533553455355536553755385539554055415542554355445545554655475548554955505551555255535554555555565557555855595560556155625563556455655566556755685569557055715572557355745575557655775578557955805581558255835584558555865587558855895590559155925593559455955596559755985599560056015602560356045605560656075608560956105611561256135614561556165617561856195620562156225623562456255626562756285629563056315632563356345635563656375638563956405641564256435644564556465647564856495650565156525653565456555656565756585659566056615662566356645665566656675668566956705671567256735674567556765677567856795680568156825683568456855686568756885689569056915692569356945695569656975698569957005701570257035704570557065707570857095710571157125713571457155716571757185719572057215722572357245725572657275728572957305731573257335734573557365737573857395740574157425743574457455746574757485749575057515752575357545755575657575758575957605761576257635764576557665767576857695770577157725773577457755776577757785779578057815782578357845785578657875788578957905791579257935794579557965797579857995800580158025803580458055806580758085809581058115812581358145815581658175818581958205821582258235824582558265827582858295830583158325833583458355836583758385839584058415842584358445845584658475848584958505851585258535854585558565857585858595860586158625863586458655866586758685869587058715872587358745875587658775878587958805881588258835884588558865887588858895890589158925893589458955896589758985899590059015902590359045905590659075908590959105911591259135914591559165917591859195920592159225923592459255926592759285929593059315932593359345935593659375938593959405941594259435944594559465947594859495950595159525953595459555956595759585959596059615962596359645965596659675968596959705971597259735974597559765977597859795980598159825983598459855986598759885989599059915992599359945995599659975998599960006001600260036004600560066007600860096010601160126013601460156016601760186019602060216022602360246025602660276028602960306031603260336034603560366037603860396040604160426043604460456046604760486049605060516052605360546055605660576058605960606061606260636064606560666067606860696070607160726073607460756076607760786079608060816082608360846085608660876088608960906091609260936094609560966097609860996100610161026103610461056106610761086109611061116112611361146115611661176118611961206121612261236124612561266127612861296130613161326133613461356136613761386139614061416142614361446145614661476148614961506151615261536154615561566157615861596160616161626163616461656166616761686169617061716172617361746175617661776178617961806181618261836184618561866187618861896190619161926193619461956196619761986199620062016202620362046205620662076208620962106211621262136214621562166217621862196220622162226223622462256226622762286229623062316232623362346235623662376238623962406241624262436244624562466247624862496250625162526253625462556256625762586259626062616262626362646265626662676268626962706271627262736274627562766277627862796280628162826283628462856286628762886289629062916292629362946295629662976298629963006301630263036304630563066307630863096310631163126313631463156316631763186319632063216322632363246325632663276328632963306331633263336334633563366337633863396340634163426343634463456346634763486349635063516352635363546355635663576358635963606361636263636364636563666367636863696370637163726373637463756376637763786379638063816382638363846385638663876388638963906391639263936394639563966397639863996400640164026403640464056406640764086409641064116412641364146415641664176418641964206421642264236424642564266427642864296430643164326433643464356436643764386439644064416442644364446445644664476448644964506451645264536454645564566457645864596460646164626463646464656466646764686469647064716472647364746475647664776478647964806481648264836484648564866487648864896490649164926493649464956496649764986499650065016502650365046505650665076508650965106511651265136514651565166517651865196520652165226523652465256526652765286529653065316532653365346535653665376538653965406541654265436544654565466547654865496550655165526553655465556556655765586559656065616562656365646565656665676568656965706571657265736574657565766577657865796580658165826583658465856586658765886589659065916592659365946595659665976598659966006601660266036604660566066607660866096610661166126613661466156616661766186619662066216622662366246625662666276628662966306631663266336634663566366637663866396640664166426643664466456646664766486649665066516652665366546655665666576658665966606661666266636664666566666667666866696670667166726673667466756676667766786679668066816682668366846685668666876688668966906691669266936694669566966697669866996700670167026703670467056706670767086709671067116712671367146715671667176718671967206721672267236724672567266727672867296730673167326733673467356736673767386739674067416742674367446745674667476748674967506751675267536754675567566757675867596760676167626763676467656766676767686769677067716772677367746775677667776778677967806781678267836784678567866787678867896790679167926793679467956796679767986799680068016802680368046805680668076808680968106811681268136814681568166817681868196820682168226823682468256826682768286829683068316832683368346835683668376838683968406841684268436844684568466847684868496850685168526853685468556856685768586859686068616862686368646865686668676868686968706871687268736874687568766877687868796880688168826883688468856886688768886889689068916892689368946895689668976898689969006901690269036904690569066907690869096910691169126913691469156916691769186919692069216922692369246925692669276928692969306931693269336934693569366937693869396940694169426943694469456946694769486949695069516952695369546955695669576958695969606961696269636964696569666967696869696970697169726973697469756976697769786979698069816982698369846985698669876988698969906991699269936994699569966997699869997000700170027003700470057006700770087009701070117012701370147015701670177018701970207021702270237024702570267027702870297030703170327033703470357036703770387039704070417042704370447045704670477048704970507051705270537054705570567057705870597060706170627063706470657066706770687069707070717072707370747075707670777078707970807081708270837084708570867087708870897090709170927093709470957096709770987099710071017102710371047105710671077108710971107111711271137114711571167117711871197120712171227123712471257126712771287129713071317132713371347135713671377138713971407141714271437144714571467147714871497150715171527153715471557156715771587159716071617162716371647165716671677168716971707171717271737174717571767177717871797180718171827183718471857186718771887189719071917192719371947195719671977198719972007201720272037204720572067207720872097210721172127213721472157216721772187219722072217222722372247225722672277228722972307231723272337234723572367237723872397240724172427243724472457246724772487249725072517252725372547255725672577258725972607261726272637264726572667267726872697270727172727273727472757276727772787279728072817282728372847285728672877288728972907291729272937294729572967297729872997300730173027303730473057306730773087309731073117312731373147315731673177318731973207321732273237324732573267327732873297330733173327333733473357336733773387339734073417342734373447345734673477348734973507351735273537354735573567357735873597360736173627363736473657366736773687369737073717372737373747375737673777378737973807381738273837384738573867387738873897390739173927393739473957396739773987399740074017402740374047405740674077408740974107411741274137414741574167417741874197420742174227423742474257426742774287429743074317432743374347435743674377438743974407441744274437444744574467447744874497450745174527453745474557456745774587459746074617462746374647465746674677468746974707471747274737474747574767477747874797480748174827483748474857486748774887489749074917492749374947495749674977498749975007501750275037504750575067507750875097510751175127513751475157516751775187519752075217522752375247525752675277528752975307531753275337534753575367537753875397540754175427543754475457546754775487549755075517552755375547555755675577558755975607561756275637564756575667567756875697570757175727573757475757576757775787579758075817582758375847585758675877588758975907591759275937594759575967597759875997600760176027603760476057606760776087609761076117612761376147615761676177618761976207621762276237624762576267627762876297630763176327633763476357636763776387639764076417642764376447645764676477648764976507651765276537654765576567657765876597660766176627663766476657666766776687669767076717672767376747675767676777678767976807681768276837684768576867687768876897690769176927693769476957696769776987699770077017702770377047705770677077708770977107711771277137714771577167717771877197720772177227723772477257726772777287729773077317732773377347735773677377738773977407741774277437744774577467747774877497750775177527753775477557756775777587759776077617762776377647765776677677768776977707771777277737774777577767777777877797780778177827783778477857786778777887789779077917792779377947795779677977798779978007801780278037804780578067807780878097810781178127813781478157816781778187819782078217822782378247825782678277828782978307831783278337834783578367837783878397840784178427843784478457846784778487849785078517852785378547855785678577858785978607861786278637864786578667867786878697870787178727873787478757876787778787879788078817882788378847885788678877888788978907891789278937894789578967897789878997900790179027903790479057906790779087909791079117912791379147915791679177918791979207921792279237924792579267927792879297930793179327933793479357936793779387939794079417942794379447945794679477948794979507951795279537954795579567957795879597960796179627963796479657966796779687969797079717972797379747975797679777978797979807981798279837984798579867987798879897990799179927993799479957996799779987999800080018002800380048005800680078008800980108011801280138014801580168017801880198020802180228023802480258026802780288029803080318032803380348035803680378038803980408041804280438044804580468047804880498050805180528053805480558056805780588059806080618062806380648065806680678068806980708071807280738074807580768077807880798080808180828083808480858086808780888089809080918092809380948095809680978098809981008101810281038104810581068107810881098110811181128113811481158116811781188119812081218122812381248125812681278128812981308131813281338134813581368137813881398140814181428143814481458146814781488149815081518152815381548155815681578158815981608161816281638164816581668167816881698170817181728173817481758176817781788179818081818182818381848185818681878188818981908191819281938194819581968197819881998200820182028203820482058206820782088209821082118212821382148215821682178218821982208221822282238224822582268227822882298230823182328233823482358236823782388239824082418242824382448245824682478248824982508251825282538254825582568257825882598260826182628263826482658266826782688269827082718272827382748275827682778278827982808281828282838284828582868287828882898290829182928293829482958296829782988299830083018302830383048305830683078308830983108311831283138314831583168317831883198320832183228323832483258326832783288329833083318332833383348335833683378338833983408341834283438344834583468347834883498350835183528353835483558356835783588359836083618362836383648365836683678368836983708371837283738374837583768377837883798380838183828383838483858386838783888389839083918392839383948395839683978398839984008401840284038404840584068407840884098410841184128413841484158416841784188419842084218422842384248425842684278428842984308431843284338434843584368437843884398440844184428443844484458446844784488449845084518452845384548455845684578458845984608461846284638464846584668467846884698470847184728473847484758476847784788479848084818482848384848485848684878488848984908491849284938494849584968497849884998500850185028503850485058506850785088509851085118512851385148515851685178518851985208521852285238524852585268527852885298530853185328533853485358536853785388539854085418542854385448545854685478548854985508551855285538554855585568557855885598560856185628563856485658566856785688569857085718572857385748575857685778578857985808581858285838584858585868587858885898590859185928593859485958596859785988599860086018602860386048605860686078608860986108611861286138614861586168617861886198620862186228623862486258626862786288629863086318632863386348635863686378638863986408641864286438644864586468647864886498650865186528653865486558656865786588659866086618662866386648665866686678668866986708671867286738674867586768677867886798680868186828683868486858686868786888689869086918692869386948695869686978698869987008701870287038704870587068707870887098710871187128713871487158716871787188719872087218722872387248725872687278728872987308731873287338734873587368737873887398740874187428743874487458746874787488749875087518752875387548755875687578758875987608761876287638764876587668767876887698770877187728773877487758776877787788779878087818782878387848785878687878788878987908791879287938794879587968797879887998800880188028803880488058806880788088809881088118812881388148815881688178818881988208821882288238824882588268827882888298830883188328833883488358836883788388839884088418842884388448845884688478848884988508851885288538854885588568857885888598860886188628863886488658866886788688869887088718872887388748875887688778878887988808881888288838884888588868887888888898890889188928893889488958896889788988899890089018902890389048905890689078908890989108911891289138914891589168917891889198920892189228923892489258926892789288929893089318932893389348935893689378938893989408941894289438944894589468947894889498950895189528953895489558956895789588959896089618962896389648965896689678968896989708971897289738974897589768977897889798980898189828983898489858986898789888989899089918992899389948995899689978998899990009001900290039004900590069007900890099010901190129013901490159016901790189019902090219022902390249025902690279028902990309031903290339034903590369037903890399040904190429043904490459046904790489049905090519052905390549055905690579058905990609061906290639064906590669067906890699070907190729073907490759076907790789079908090819082908390849085908690879088908990909091909290939094909590969097909890999100910191029103910491059106910791089109911091119112911391149115911691179118911991209121912291239124912591269127912891299130913191329133913491359136913791389139914091419142914391449145914691479148914991509151915291539154915591569157915891599160916191629163916491659166916791689169917091719172917391749175917691779178917991809181918291839184918591869187918891899190919191929193919491959196919791989199920092019202920392049205920692079208920992109211921292139214921592169217921892199220922192229223922492259226922792289229923092319232923392349235923692379238923992409241924292439244924592469247924892499250925192529253925492559256925792589259926092619262926392649265926692679268926992709271927292739274927592769277927892799280928192829283928492859286928792889289929092919292929392949295929692979298929993009301930293039304930593069307930893099310931193129313931493159316931793189319932093219322932393249325932693279328932993309331933293339334933593369337933893399340934193429343934493459346934793489349935093519352935393549355935693579358935993609361936293639364936593669367936893699370937193729373937493759376937793789379938093819382938393849385938693879388938993909391939293939394939593969397939893999400940194029403940494059406940794089409941094119412941394149415941694179418941994209421942294239424942594269427942894299430943194329433943494359436943794389439944094419442944394449445944694479448944994509451945294539454945594569457945894599460946194629463946494659466946794689469947094719472947394749475947694779478947994809481948294839484948594869487948894899490949194929493949494959496949794989499950095019502950395049505950695079508950995109511951295139514951595169517951895199520952195229523952495259526952795289529953095319532953395349535953695379538953995409541954295439544954595469547954895499550955195529553955495559556955795589559956095619562956395649565956695679568956995709571957295739574957595769577957895799580958195829583958495859586958795889589959095919592959395949595959695979598959996009601960296039604960596069607960896099610961196129613961496159616961796189619962096219622962396249625962696279628962996309631963296339634963596369637963896399640964196429643964496459646964796489649965096519652965396549655965696579658965996609661966296639664966596669667966896699670967196729673967496759676967796789679968096819682968396849685968696879688968996909691969296939694969596969697969896999700970197029703970497059706970797089709971097119712971397149715971697179718971997209721972297239724972597269727972897299730973197329733973497359736973797389739974097419742974397449745974697479748974997509751975297539754975597569757975897599760976197629763976497659766976797689769977097719772977397749775977697779778977997809781978297839784978597869787978897899790979197929793979497959796979797989799980098019802980398049805980698079808980998109811981298139814981598169817981898199820982198229823982498259826982798289829983098319832983398349835983698379838983998409841984298439844984598469847984898499850985198529853985498559856985798589859986098619862986398649865986698679868986998709871987298739874987598769877987898799880988198829883988498859886988798889889989098919892989398949895989698979898989999009901990299039904990599069907990899099910991199129913991499159916991799189919992099219922992399249925992699279928992999309931993299339934993599369937993899399940994199429943994499459946994799489949995099519952995399549955995699579958995999609961996299639964996599669967996899699970997199729973997499759976997799789979998099819982998399849985998699879988998999909991999299939994999599969997999899991000010001100021000310004100051000610007100081000910010100111001210013100141001510016100171001810019100201002110022100231002410025100261002710028100291003010031100321003310034100351003610037100381003910040100411004210043100441004510046100471004810049100501005110052100531005410055100561005710058100591006010061100621006310064100651006610067100681006910070100711007210073100741007510076100771007810079100801008110082100831008410085100861008710088100891009010091100921009310094100951009610097100981009910100101011010210103101041010510106101071010810109101101011110112101131011410115101161011710118101191012010121101221012310124101251012610127101281012910130101311013210133101341013510136101371013810139101401014110142101431014410145101461014710148101491015010151101521015310154101551015610157101581015910160101611016210163101641016510166101671016810169101701017110172101731017410175101761017710178101791018010181101821018310184101851018610187101881018910190101911019210193101941019510196101971019810199102001020110202102031020410205102061020710208102091021010211102121021310214102151021610217102181021910220102211022210223102241022510226102271022810229102301023110232102331023410235102361023710238102391024010241102421024310244102451024610247102481024910250102511025210253102541025510256102571025810259102601026110262102631026410265102661026710268102691027010271102721027310274102751027610277102781027910280102811028210283102841028510286102871028810289102901029110292102931029410295102961029710298102991030010301103021030310304103051030610307103081030910310103111031210313103141031510316103171031810319103201032110322103231032410325103261032710328103291033010331103321033310334103351033610337103381033910340103411034210343103441034510346103471034810349103501035110352103531035410355103561035710358103591036010361103621036310364103651036610367103681036910370103711037210373103741037510376103771037810379103801038110382103831038410385103861038710388103891039010391103921039310394103951039610397103981039910400104011040210403104041040510406104071040810409104101041110412104131041410415104161041710418104191042010421104221042310424104251042610427104281042910430104311043210433104341043510436104371043810439104401044110442104431044410445104461044710448104491045010451104521045310454104551045610457104581045910460104611046210463104641046510466104671046810469104701047110472104731047410475104761047710478104791048010481104821048310484104851048610487104881048910490104911049210493104941049510496104971049810499105001050110502105031050410505105061050710508105091051010511105121051310514105151051610517105181051910520105211052210523105241052510526105271052810529105301053110532105331053410535105361053710538105391054010541105421054310544105451054610547105481054910550105511055210553105541055510556105571055810559105601056110562105631056410565105661056710568105691057010571105721057310574105751057610577105781057910580105811058210583105841058510586105871058810589105901059110592105931059410595105961059710598105991060010601106021060310604106051060610607106081060910610106111061210613106141061510616106171061810619106201062110622106231062410625106261062710628106291063010631106321063310634106351063610637106381063910640106411064210643106441064510646106471064810649106501065110652106531065410655106561065710658106591066010661106621066310664106651066610667106681066910670106711067210673106741067510676106771067810679106801068110682106831068410685106861068710688106891069010691106921069310694106951069610697106981069910700107011070210703107041070510706107071070810709107101071110712107131071410715107161071710718107191072010721107221072310724107251072610727107281072910730107311073210733107341073510736107371073810739107401074110742107431074410745107461074710748107491075010751107521075310754107551075610757107581075910760107611076210763107641076510766107671076810769107701077110772107731077410775107761077710778107791078010781107821078310784107851078610787107881078910790107911079210793107941079510796107971079810799108001080110802108031080410805108061080710808108091081010811108121081310814108151081610817108181081910820108211082210823108241082510826108271082810829108301083110832108331083410835108361083710838108391084010841108421084310844108451084610847108481084910850108511085210853108541085510856108571085810859108601086110862108631086410865108661086710868108691087010871108721087310874108751087610877108781087910880108811088210883108841088510886108871088810889108901089110892108931089410895108961089710898108991090010901109021090310904109051090610907109081090910910109111091210913109141091510916109171091810919109201092110922109231092410925109261092710928109291093010931109321093310934109351093610937109381093910940109411094210943109441094510946109471094810949109501095110952109531095410955109561095710958109591096010961109621096310964109651096610967109681096910970109711097210973109741097510976109771097810979109801098110982109831098410985109861098710988109891099010991109921099310994109951099610997109981099911000110011100211003110041100511006110071100811009110101101111012110131101411015110161101711018110191102011021110221102311024110251102611027110281102911030110311103211033110341103511036110371103811039110401104111042110431104411045110461104711048110491105011051110521105311054110551105611057110581105911060110611106211063110641106511066110671106811069110701107111072110731107411075110761107711078110791108011081110821108311084110851108611087110881108911090110911109211093110941109511096110971109811099111001110111102111031110411105111061110711108111091111011111111121111311114111151111611117111181111911120111211112211123111241112511126111271112811129111301113111132111331113411135111361113711138111391114011141111421114311144111451114611147111481114911150111511115211153111541115511156111571115811159111601116111162111631116411165111661116711168111691117011171111721117311174111751117611177111781117911180111811118211183111841118511186111871118811189111901119111192111931119411195111961119711198111991120011201112021120311204112051120611207112081120911210112111121211213112141121511216112171121811219112201122111222112231122411225112261122711228112291123011231112321123311234112351123611237112381123911240112411124211243112441124511246112471124811249112501125111252112531125411255112561125711258112591126011261112621126311264112651126611267112681126911270112711127211273112741127511276112771127811279112801128111282112831128411285112861128711288112891129011291112921129311294112951129611297112981129911300113011130211303113041130511306113071130811309113101131111312113131131411315113161131711318113191132011321113221132311324113251132611327113281132911330113311133211333113341133511336113371133811339113401134111342113431134411345113461134711348113491135011351113521135311354113551135611357113581135911360113611136211363113641136511366113671136811369113701137111372113731137411375113761137711378113791138011381113821138311384113851138611387113881138911390113911139211393113941139511396113971139811399114001140111402114031140411405114061140711408114091141011411114121141311414114151141611417114181141911420114211142211423114241142511426114271142811429114301143111432114331143411435114361143711438114391144011441114421144311444114451144611447114481144911450114511145211453114541145511456114571145811459114601146111462114631146411465114661146711468114691147011471114721147311474114751147611477114781147911480114811148211483114841148511486114871148811489114901149111492114931149411495114961149711498114991150011501115021150311504115051150611507115081150911510115111151211513115141151511516115171151811519115201152111522115231152411525115261152711528115291153011531115321153311534115351153611537115381153911540115411154211543115441154511546115471154811549115501155111552115531155411555115561155711558115591156011561115621156311564115651156611567115681156911570115711157211573115741157511576115771157811579115801158111582115831158411585115861158711588115891159011591115921159311594115951159611597115981159911600116011160211603116041160511606116071160811609116101161111612116131161411615116161161711618116191162011621116221162311624116251162611627116281162911630116311163211633116341163511636116371163811639116401164111642116431164411645116461164711648116491165011651116521165311654116551165611657116581165911660116611166211663116641166511666116671166811669116701167111672116731167411675116761167711678116791168011681116821168311684116851168611687116881168911690116911169211693116941169511696116971169811699117001170111702117031170411705117061170711708117091171011711117121171311714117151171611717117181171911720117211172211723117241172511726117271172811729117301173111732117331173411735117361173711738117391174011741117421174311744117451174611747117481174911750117511175211753117541175511756117571175811759117601176111762117631176411765117661176711768117691177011771117721177311774117751177611777117781177911780117811178211783117841178511786117871178811789117901179111792117931179411795117961179711798117991180011801118021180311804118051180611807118081180911810118111181211813118141181511816118171181811819118201182111822118231182411825118261182711828118291183011831118321183311834118351183611837118381183911840118411184211843118441184511846118471184811849118501185111852118531185411855118561185711858118591186011861118621186311864118651186611867118681186911870118711187211873118741187511876118771187811879118801188111882118831188411885118861188711888118891189011891118921189311894118951189611897118981189911900119011190211903119041190511906119071190811909119101191111912119131191411915119161191711918119191192011921119221192311924119251192611927119281192911930119311193211933119341193511936119371193811939119401194111942119431194411945119461194711948119491195011951119521195311954119551195611957119581195911960119611196211963119641196511966119671196811969119701197111972119731197411975119761197711978119791198011981119821198311984119851198611987119881198911990119911199211993119941199511996119971199811999120001200112002120031200412005120061200712008120091201012011120121201312014120151201612017120181201912020120211202212023120241202512026120271202812029120301203112032120331203412035120361203712038120391204012041120421204312044120451204612047120481204912050120511205212053120541205512056120571205812059120601206112062120631206412065120661206712068120691207012071120721207312074120751207612077120781207912080120811208212083120841208512086120871208812089120901209112092120931209412095120961209712098120991210012101121021210312104121051210612107121081210912110121111211212113121141211512116121171211812119121201212112122121231212412125121261212712128121291213012131121321213312134121351213612137121381213912140121411214212143121441214512146121471214812149121501215112152121531215412155121561215712158121591216012161121621216312164121651216612167121681216912170121711217212173121741217512176121771217812179121801218112182121831218412185121861218712188121891219012191121921219312194121951219612197121981219912200122011220212203122041220512206122071220812209122101221112212122131221412215122161221712218122191222012221122221222312224122251222612227122281222912230122311223212233122341223512236122371223812239122401224112242122431224412245122461224712248122491225012251122521225312254122551225612257122581225912260122611226212263122641226512266122671226812269122701227112272122731227412275122761227712278122791228012281122821228312284122851228612287122881228912290122911229212293122941229512296122971229812299123001230112302123031230412305123061230712308123091231012311123121231312314123151231612317123181231912320123211232212323123241232512326123271232812329123301233112332123331233412335123361233712338123391234012341123421234312344123451234612347123481234912350123511235212353123541235512356123571235812359123601236112362123631236412365123661236712368123691237012371123721237312374123751237612377123781237912380123811238212383123841238512386123871238812389123901239112392123931239412395123961239712398123991240012401124021240312404124051240612407124081240912410124111241212413124141241512416124171241812419124201242112422124231242412425124261242712428124291243012431124321243312434124351243612437124381243912440124411244212443124441244512446124471244812449124501245112452124531245412455124561245712458124591246012461124621246312464124651246612467124681246912470124711247212473124741247512476124771247812479124801248112482124831248412485124861248712488124891249012491124921249312494124951249612497124981249912500125011250212503125041250512506125071250812509125101251112512125131251412515125161251712518125191252012521125221252312524125251252612527125281252912530125311253212533125341253512536125371253812539125401254112542125431254412545125461254712548125491255012551125521255312554125551255612557125581255912560125611256212563125641256512566125671256812569125701257112572125731257412575125761257712578125791258012581125821258312584125851258612587125881258912590125911259212593125941259512596125971259812599126001260112602126031260412605126061260712608126091261012611126121261312614126151261612617126181261912620126211262212623126241262512626126271262812629126301263112632126331263412635126361263712638126391264012641126421264312644126451264612647126481264912650126511265212653126541265512656126571265812659126601266112662126631266412665126661266712668126691267012671126721267312674126751267612677126781267912680126811268212683126841268512686126871268812689126901269112692126931269412695126961269712698126991270012701127021270312704127051270612707127081270912710127111271212713127141271512716127171271812719127201272112722127231272412725127261272712728127291273012731127321273312734127351273612737127381273912740127411274212743127441274512746127471274812749127501275112752127531275412755127561275712758127591276012761127621276312764127651276612767127681276912770127711277212773127741277512776127771277812779127801278112782127831278412785127861278712788127891279012791127921279312794127951279612797127981279912800128011280212803128041280512806128071280812809128101281112812128131281412815128161281712818128191282012821128221282312824128251282612827128281282912830128311283212833128341283512836128371283812839128401284112842128431284412845128461284712848128491285012851128521285312854128551285612857128581285912860128611286212863128641286512866128671286812869128701287112872128731287412875128761287712878128791288012881128821288312884128851288612887128881288912890128911289212893128941289512896128971289812899129001290112902129031290412905129061290712908129091291012911129121291312914129151291612917129181291912920129211292212923129241292512926129271292812929129301293112932129331293412935129361293712938129391294012941129421294312944129451294612947129481294912950129511295212953129541295512956129571295812959129601296112962129631296412965129661296712968129691297012971129721297312974129751297612977129781297912980129811298212983129841298512986129871298812989129901299112992129931299412995129961299712998129991300013001130021300313004130051300613007130081300913010130111301213013130141301513016130171301813019130201302113022130231302413025130261302713028130291303013031130321303313034130351303613037130381303913040130411304213043130441304513046130471304813049130501305113052130531305413055130561305713058130591306013061130621306313064130651306613067130681306913070130711307213073130741307513076130771307813079130801308113082130831308413085130861308713088130891309013091130921309313094130951309613097130981309913100131011310213103131041310513106131071310813109131101311113112131131311413115131161311713118131191312013121131221312313124131251312613127131281312913130131311313213133131341313513136131371313813139131401314113142131431314413145131461314713148131491315013151131521315313154131551315613157131581315913160131611316213163131641316513166131671316813169131701317113172131731317413175131761317713178131791318013181131821318313184131851318613187131881318913190131911319213193131941319513196131971319813199132001320113202132031320413205132061320713208132091321013211132121321313214132151321613217132181321913220132211322213223132241322513226132271322813229132301323113232132331323413235132361323713238132391324013241132421324313244132451324613247132481324913250132511325213253132541325513256132571325813259132601326113262132631326413265132661326713268132691327013271132721327313274132751327613277132781327913280132811328213283132841328513286132871328813289132901329113292132931329413295132961329713298132991330013301133021330313304133051330613307133081330913310133111331213313133141331513316133171331813319133201332113322133231332413325133261332713328133291333013331133321333313334133351333613337133381333913340133411334213343133441334513346133471334813349133501335113352133531335413355133561335713358133591336013361133621336313364133651336613367133681336913370133711337213373133741337513376133771337813379133801338113382133831338413385133861338713388133891339013391133921339313394133951339613397133981339913400134011340213403134041340513406134071340813409134101341113412134131341413415134161341713418134191342013421134221342313424134251342613427134281342913430134311343213433134341343513436134371343813439134401344113442134431344413445134461344713448134491345013451134521345313454134551345613457134581345913460134611346213463134641346513466134671346813469134701347113472134731347413475134761347713478134791348013481134821348313484134851348613487134881348913490134911349213493134941349513496134971349813499135001350113502135031350413505135061350713508135091351013511135121351313514135151351613517135181351913520135211352213523135241352513526135271352813529135301353113532135331353413535135361353713538135391354013541135421354313544135451354613547135481354913550135511355213553135541355513556135571355813559135601356113562135631356413565135661356713568135691357013571135721357313574135751357613577135781357913580135811358213583135841358513586135871358813589135901359113592135931359413595135961359713598135991360013601136021360313604136051360613607136081360913610136111361213613136141361513616136171361813619136201362113622136231362413625136261362713628136291363013631136321363313634136351363613637136381363913640136411364213643136441364513646136471364813649136501365113652136531365413655136561365713658136591366013661136621366313664136651366613667136681366913670136711367213673136741367513676136771367813679136801368113682136831368413685136861368713688136891369013691136921369313694136951369613697136981369913700137011370213703137041370513706137071370813709137101371113712137131371413715137161371713718137191372013721137221372313724137251372613727137281372913730137311373213733137341373513736137371373813739137401374113742137431374413745137461374713748137491375013751137521375313754137551375613757137581375913760137611376213763137641376513766137671376813769137701377113772137731377413775137761377713778137791378013781137821378313784137851378613787137881378913790137911379213793137941379513796137971379813799138001380113802138031380413805138061380713808138091381013811138121381313814138151381613817138181381913820138211382213823138241382513826138271382813829138301383113832138331383413835138361383713838138391384013841138421384313844138451384613847138481384913850138511385213853138541385513856138571385813859138601386113862138631386413865138661386713868138691387013871138721387313874138751387613877138781387913880138811388213883138841388513886138871388813889138901389113892138931389413895138961389713898138991390013901139021390313904139051390613907139081390913910139111391213913139141391513916139171391813919139201392113922139231392413925139261392713928139291393013931139321393313934139351393613937139381393913940139411394213943139441394513946139471394813949139501395113952139531395413955139561395713958139591396013961139621396313964139651396613967139681396913970139711397213973139741397513976139771397813979139801398113982139831398413985139861398713988139891399013991139921399313994139951399613997139981399914000140011400214003140041400514006140071400814009140101401114012140131401414015140161401714018140191402014021140221402314024140251402614027140281402914030140311403214033140341403514036140371403814039140401404114042140431404414045140461404714048140491405014051140521405314054140551405614057140581405914060140611406214063140641406514066140671406814069140701407114072140731407414075140761407714078140791408014081140821408314084140851408614087140881408914090140911409214093140941409514096140971409814099141001410114102141031410414105141061410714108141091411014111141121411314114141151411614117141181411914120141211412214123141241412514126141271412814129141301413114132141331413414135141361413714138141391414014141141421414314144141451414614147141481414914150141511415214153141541415514156141571415814159141601416114162141631416414165141661416714168141691417014171141721417314174141751417614177141781417914180141811418214183141841418514186141871418814189141901419114192141931419414195141961419714198141991420014201142021420314204142051420614207142081420914210142111421214213142141421514216142171421814219142201422114222142231422414225142261422714228142291423014231142321423314234142351423614237142381423914240142411424214243142441424514246142471424814249142501425114252142531425414255142561425714258142591426014261142621426314264142651426614267142681426914270142711427214273142741427514276142771427814279142801428114282142831428414285142861428714288142891429014291142921429314294142951429614297142981429914300143011430214303143041430514306143071430814309143101431114312143131431414315143161431714318143191432014321143221432314324143251432614327143281432914330143311433214333143341433514336143371433814339143401434114342143431434414345143461434714348143491435014351143521435314354143551435614357143581435914360143611436214363143641436514366143671436814369143701437114372143731437414375143761437714378143791438014381143821438314384143851438614387143881438914390143911439214393143941439514396143971439814399144001440114402144031440414405144061440714408144091441014411144121441314414144151441614417144181441914420144211442214423144241442514426144271442814429144301443114432144331443414435144361443714438144391444014441144421444314444144451444614447144481444914450144511445214453144541445514456144571445814459144601446114462144631446414465144661446714468144691447014471144721447314474144751447614477144781447914480144811448214483144841448514486144871448814489144901449114492144931449414495144961449714498144991450014501145021450314504145051450614507145081450914510145111451214513145141451514516145171451814519145201452114522145231452414525145261452714528145291453014531145321453314534145351453614537145381453914540145411454214543145441454514546145471454814549145501455114552145531455414555145561455714558145591456014561145621456314564145651456614567145681456914570145711457214573145741457514576145771457814579145801458114582145831458414585145861458714588145891459014591145921459314594145951459614597145981459914600146011460214603146041460514606146071460814609146101461114612146131461414615146161461714618146191462014621146221462314624146251462614627146281462914630146311463214633146341463514636146371463814639146401464114642146431464414645146461464714648146491465014651146521465314654146551465614657146581465914660146611466214663146641466514666146671466814669146701467114672146731467414675146761467714678146791468014681146821468314684146851468614687146881468914690146911469214693146941469514696146971469814699147001470114702147031470414705147061470714708147091471014711147121471314714147151471614717147181471914720147211472214723147241472514726147271472814729147301473114732147331473414735147361473714738147391474014741147421474314744147451474614747147481474914750147511475214753147541475514756147571475814759147601476114762147631476414765147661476714768147691477014771147721477314774147751477614777147781477914780147811478214783147841478514786147871478814789147901479114792147931479414795147961479714798147991480014801148021480314804148051480614807148081480914810148111481214813148141481514816148171481814819148201482114822148231482414825148261482714828148291483014831148321483314834148351483614837148381483914840148411484214843148441484514846148471484814849148501485114852148531485414855148561485714858148591486014861148621486314864148651486614867148681486914870148711487214873148741487514876148771487814879148801488114882148831488414885148861488714888148891489014891148921489314894148951489614897148981489914900149011490214903149041490514906149071490814909149101491114912149131491414915149161491714918149191492014921149221492314924149251492614927149281492914930149311493214933149341493514936149371493814939149401494114942149431494414945149461494714948149491495014951149521495314954149551495614957149581495914960149611496214963149641496514966149671496814969149701497114972149731497414975149761497714978149791498014981149821498314984149851498614987149881498914990149911499214993149941499514996149971499814999150001500115002150031500415005150061500715008150091501015011150121501315014150151501615017150181501915020150211502215023150241502515026150271502815029150301503115032150331503415035150361503715038150391504015041150421504315044150451504615047150481504915050150511505215053150541505515056150571505815059150601506115062150631506415065150661506715068150691507015071150721507315074150751507615077150781507915080150811508215083150841508515086150871508815089150901509115092150931509415095150961509715098150991510015101151021510315104151051510615107151081510915110151111511215113151141511515116151171511815119151201512115122151231512415125151261512715128151291513015131151321513315134151351513615137151381513915140151411514215143151441514515146151471514815149151501515115152151531515415155151561515715158151591516015161151621516315164151651516615167151681516915170151711517215173151741517515176151771517815179151801518115182151831518415185151861518715188151891519015191151921519315194151951519615197151981519915200152011520215203152041520515206152071520815209152101521115212152131521415215152161521715218152191522015221152221522315224152251522615227152281522915230152311523215233152341523515236152371523815239152401524115242152431524415245152461524715248152491525015251152521525315254152551525615257152581525915260152611526215263152641526515266152671526815269152701527115272152731527415275152761527715278152791528015281152821528315284152851528615287152881528915290152911529215293152941529515296152971529815299153001530115302153031530415305153061530715308153091531015311153121531315314153151531615317153181531915320153211532215323153241532515326153271532815329153301533115332153331533415335153361533715338153391534015341153421534315344153451534615347153481534915350153511535215353153541535515356153571535815359153601536115362153631536415365153661536715368153691537015371153721537315374153751537615377153781537915380153811538215383153841538515386153871538815389153901539115392153931539415395153961539715398153991540015401154021540315404154051540615407154081540915410154111541215413154141541515416154171541815419154201542115422154231542415425154261542715428154291543015431154321543315434154351543615437154381543915440154411544215443154441544515446154471544815449154501545115452154531545415455154561545715458154591546015461154621546315464154651546615467154681546915470154711547215473154741547515476154771547815479154801548115482154831548415485154861548715488154891549015491154921549315494154951549615497154981549915500155011550215503155041550515506155071550815509155101551115512155131551415515155161551715518155191552015521155221552315524155251552615527155281552915530155311553215533155341553515536155371553815539155401554115542155431554415545155461554715548155491555015551155521555315554155551555615557155581555915560155611556215563155641556515566155671556815569155701557115572155731557415575155761557715578155791558015581155821558315584155851558615587155881558915590155911559215593155941559515596155971559815599156001560115602156031560415605156061560715608156091561015611156121561315614156151561615617156181561915620156211562215623156241562515626156271562815629156301563115632156331563415635156361563715638156391564015641156421564315644156451564615647156481564915650156511565215653156541565515656156571565815659156601566115662156631566415665156661566715668156691567015671156721567315674156751567615677156781567915680156811568215683156841568515686156871568815689156901569115692156931569415695156961569715698156991570015701157021570315704157051570615707157081570915710157111571215713157141571515716157171571815719157201572115722157231572415725157261572715728157291573015731157321573315734157351573615737157381573915740157411574215743157441574515746157471574815749157501575115752157531575415755157561575715758157591576015761157621576315764157651576615767157681576915770157711577215773157741577515776157771577815779157801578115782157831578415785157861578715788157891579015791157921579315794157951579615797157981579915800158011580215803158041580515806158071580815809158101581115812158131581415815158161581715818158191582015821158221582315824158251582615827158281582915830158311583215833158341583515836158371583815839158401584115842158431584415845158461584715848158491585015851158521585315854158551585615857158581585915860158611586215863158641586515866158671586815869158701587115872158731587415875158761587715878158791588015881158821588315884158851588615887158881588915890158911589215893158941589515896158971589815899159001590115902159031590415905159061590715908159091591015911159121591315914159151591615917159181591915920159211592215923159241592515926159271592815929159301593115932159331593415935159361593715938159391594015941159421594315944159451594615947159481594915950159511595215953159541595515956159571595815959159601596115962159631596415965159661596715968159691597015971159721597315974159751597615977159781597915980159811598215983159841598515986159871598815989159901599115992159931599415995159961599715998159991600016001160021600316004160051600616007160081600916010160111601216013160141601516016160171601816019160201602116022160231602416025160261602716028160291603016031160321603316034160351603616037160381603916040160411604216043160441604516046160471604816049160501605116052160531605416055160561605716058160591606016061160621606316064160651606616067160681606916070160711607216073160741607516076160771607816079160801608116082160831608416085160861608716088160891609016091160921609316094160951609616097160981609916100161011610216103161041610516106161071610816109161101611116112161131611416115161161611716118161191612016121161221612316124161251612616127161281612916130161311613216133161341613516136161371613816139161401614116142161431614416145161461614716148161491615016151161521615316154161551615616157161581615916160161611616216163161641616516166161671616816169161701617116172161731617416175161761617716178161791618016181161821618316184161851618616187161881618916190161911619216193161941619516196161971619816199162001620116202162031620416205162061620716208162091621016211162121621316214162151621616217162181621916220162211622216223162241622516226162271622816229162301623116232162331623416235162361623716238162391624016241162421624316244162451624616247162481624916250162511625216253162541625516256162571625816259162601626116262162631626416265162661626716268162691627016271162721627316274162751627616277162781627916280162811628216283162841628516286162871628816289162901629116292162931629416295162961629716298162991630016301163021630316304163051630616307163081630916310163111631216313163141631516316163171631816319163201632116322163231632416325163261632716328163291633016331163321633316334163351633616337163381633916340163411634216343163441634516346163471634816349163501635116352163531635416355163561635716358163591636016361163621636316364163651636616367163681636916370163711637216373163741637516376163771637816379163801638116382163831638416385163861638716388163891639016391163921639316394163951639616397163981639916400164011640216403164041640516406164071640816409164101641116412164131641416415164161641716418164191642016421164221642316424164251642616427164281642916430164311643216433164341643516436164371643816439164401644116442164431644416445164461644716448164491645016451164521645316454164551645616457164581645916460164611646216463164641646516466164671646816469164701647116472164731647416475164761647716478164791648016481164821648316484164851648616487164881648916490164911649216493164941649516496164971649816499165001650116502165031650416505165061650716508165091651016511165121651316514165151651616517165181651916520165211652216523165241652516526165271652816529165301653116532165331653416535165361653716538165391654016541165421654316544165451654616547165481654916550165511655216553165541655516556165571655816559165601656116562165631656416565165661656716568165691657016571165721657316574165751657616577165781657916580165811658216583165841658516586165871658816589165901659116592165931659416595165961659716598165991660016601166021660316604166051660616607166081660916610166111661216613166141661516616166171661816619166201662116622166231662416625166261662716628166291663016631166321663316634166351663616637166381663916640166411664216643166441664516646166471664816649166501665116652166531665416655166561665716658166591666016661166621666316664166651666616667166681666916670166711667216673166741667516676166771667816679166801668116682166831668416685166861668716688166891669016691166921669316694166951669616697166981669916700167011670216703167041670516706167071670816709167101671116712167131671416715167161671716718167191672016721167221672316724167251672616727167281672916730167311673216733167341673516736167371673816739167401674116742167431674416745167461674716748167491675016751167521675316754167551675616757167581675916760167611676216763167641676516766167671676816769167701677116772167731677416775167761677716778167791678016781167821678316784167851678616787167881678916790167911679216793167941679516796167971679816799168001680116802168031680416805168061680716808168091681016811168121681316814168151681616817168181681916820168211682216823168241682516826168271682816829168301683116832168331683416835168361683716838168391684016841168421684316844168451684616847168481684916850168511685216853168541685516856168571685816859168601686116862168631686416865168661686716868168691687016871168721687316874168751687616877168781687916880168811688216883168841688516886168871688816889168901689116892168931689416895168961689716898168991690016901169021690316904169051690616907169081690916910169111691216913169141691516916169171691816919169201692116922169231692416925169261692716928169291693016931169321693316934169351693616937169381693916940169411694216943169441694516946169471694816949169501695116952169531695416955169561695716958169591696016961169621696316964169651696616967169681696916970169711697216973169741697516976169771697816979169801698116982169831698416985169861698716988169891699016991169921699316994169951699616997169981699917000170011700217003170041700517006170071700817009170101701117012170131701417015170161701717018170191702017021170221702317024170251702617027170281702917030170311703217033170341703517036170371703817039170401704117042170431704417045170461704717048170491705017051170521705317054170551705617057170581705917060170611706217063170641706517066170671706817069170701707117072170731707417075170761707717078170791708017081170821708317084170851708617087170881708917090170911709217093170941709517096170971709817099171001710117102171031710417105171061710717108171091711017111171121711317114171151711617117171181711917120171211712217123171241712517126171271712817129171301713117132171331713417135171361713717138171391714017141171421714317144171451714617147171481714917150171511715217153171541715517156171571715817159171601716117162171631716417165171661716717168171691717017171171721717317174171751717617177171781717917180171811718217183171841718517186171871718817189171901719117192171931719417195171961719717198171991720017201172021720317204172051720617207172081720917210172111721217213172141721517216172171721817219172201722117222172231722417225172261722717228172291723017231172321723317234172351723617237172381723917240172411724217243172441724517246172471724817249172501725117252172531725417255172561725717258172591726017261172621726317264172651726617267172681726917270172711727217273172741727517276172771727817279172801728117282172831728417285172861728717288172891729017291172921729317294172951729617297172981729917300173011730217303173041730517306173071730817309173101731117312173131731417315173161731717318173191732017321173221732317324173251732617327173281732917330173311733217333173341733517336173371733817339173401734117342173431734417345173461734717348173491735017351173521735317354173551735617357173581735917360173611736217363173641736517366173671736817369173701737117372173731737417375173761737717378173791738017381173821738317384173851738617387173881738917390173911739217393173941739517396173971739817399174001740117402174031740417405174061740717408174091741017411174121741317414174151741617417174181741917420174211742217423174241742517426174271742817429174301743117432174331743417435174361743717438174391744017441174421744317444174451744617447174481744917450174511745217453174541745517456174571745817459174601746117462174631746417465174661746717468174691747017471174721747317474174751747617477174781747917480174811748217483174841748517486174871748817489174901749117492174931749417495174961749717498174991750017501175021750317504175051750617507175081750917510175111751217513175141751517516175171751817519175201752117522175231752417525175261752717528175291753017531175321753317534175351753617537175381753917540175411754217543175441754517546175471754817549175501755117552175531755417555175561755717558175591756017561175621756317564175651756617567175681756917570175711757217573175741757517576175771757817579175801758117582175831758417585175861758717588175891759017591175921759317594175951759617597175981759917600176011760217603176041760517606176071760817609176101761117612176131761417615176161761717618176191762017621176221762317624176251762617627176281762917630176311763217633176341763517636176371763817639176401764117642176431764417645176461764717648176491765017651176521765317654176551765617657176581765917660176611766217663176641766517666176671766817669176701767117672176731767417675176761767717678176791768017681176821768317684176851768617687176881768917690176911769217693176941769517696176971769817699177001770117702177031770417705177061770717708177091771017711177121771317714177151771617717177181771917720177211772217723177241772517726177271772817729177301773117732177331773417735177361773717738177391774017741177421774317744177451774617747177481774917750177511775217753177541775517756177571775817759177601776117762177631776417765177661776717768177691777017771177721777317774177751777617777177781777917780177811778217783177841778517786177871778817789177901779117792177931779417795177961779717798177991780017801178021780317804178051780617807178081780917810178111781217813178141781517816178171781817819178201782117822178231782417825178261782717828178291783017831178321783317834178351783617837178381783917840178411784217843178441784517846178471784817849178501785117852178531785417855178561785717858178591786017861178621786317864178651786617867178681786917870178711787217873178741787517876178771787817879178801788117882178831788417885178861788717888178891789017891178921789317894178951789617897178981789917900179011790217903179041790517906179071790817909179101791117912179131791417915179161791717918179191792017921179221792317924179251792617927179281792917930179311793217933179341793517936179371793817939179401794117942179431794417945179461794717948179491795017951179521795317954179551795617957179581795917960179611796217963179641796517966179671796817969179701797117972179731797417975179761797717978179791798017981179821798317984179851798617987179881798917990179911799217993179941799517996179971799817999180001800118002180031800418005180061800718008180091801018011180121801318014180151801618017180181801918020180211802218023180241802518026180271802818029180301803118032180331803418035180361803718038180391804018041180421804318044180451804618047180481804918050180511805218053180541805518056180571805818059180601806118062180631806418065180661806718068180691807018071180721807318074180751807618077180781807918080180811808218083180841808518086180871808818089180901809118092180931809418095180961809718098180991810018101181021810318104181051810618107181081810918110181111811218113181141811518116181171811818119181201812118122181231812418125181261812718128181291813018131181321813318134181351813618137181381813918140181411814218143181441814518146181471814818149181501815118152181531815418155181561815718158181591816018161181621816318164181651816618167181681816918170181711817218173181741817518176181771817818179181801818118182181831818418185181861818718188181891819018191181921819318194181951819618197181981819918200182011820218203182041820518206182071820818209182101821118212182131821418215182161821718218182191822018221182221822318224182251822618227182281822918230182311823218233182341823518236182371823818239182401824118242182431824418245182461824718248182491825018251182521825318254182551825618257182581825918260182611826218263182641826518266182671826818269182701827118272182731827418275182761827718278182791828018281182821828318284182851828618287182881828918290182911829218293182941829518296182971829818299183001830118302183031830418305183061830718308183091831018311183121831318314183151831618317183181831918320183211832218323183241832518326183271832818329183301833118332183331833418335183361833718338183391834018341183421834318344183451834618347183481834918350183511835218353183541835518356183571835818359183601836118362183631836418365183661836718368183691837018371183721837318374183751837618377183781837918380183811838218383183841838518386183871838818389183901839118392183931839418395183961839718398183991840018401184021840318404184051840618407184081840918410184111841218413184141841518416184171841818419184201842118422184231842418425184261842718428184291843018431184321843318434184351843618437184381843918440184411844218443184441844518446184471844818449184501845118452184531845418455184561845718458184591846018461184621846318464184651846618467184681846918470184711847218473184741847518476184771847818479184801848118482184831848418485184861848718488184891849018491184921849318494184951849618497184981849918500185011850218503185041850518506185071850818509185101851118512185131851418515185161851718518185191852018521185221852318524185251852618527185281852918530185311853218533185341853518536185371853818539185401854118542185431854418545185461854718548185491855018551185521855318554185551855618557185581855918560185611856218563185641856518566185671856818569185701857118572185731857418575185761857718578185791858018581185821858318584185851858618587185881858918590185911859218593185941859518596185971859818599186001860118602186031860418605186061860718608186091861018611186121861318614186151861618617186181861918620186211862218623186241862518626186271862818629186301863118632186331863418635186361863718638186391864018641186421864318644186451864618647186481864918650186511865218653186541865518656186571865818659186601866118662186631866418665186661866718668186691867018671186721867318674186751867618677186781867918680186811868218683186841868518686186871868818689186901869118692186931869418695186961869718698186991870018701187021870318704187051870618707187081870918710187111871218713187141871518716187171871818719187201872118722187231872418725187261872718728187291873018731187321873318734187351873618737187381873918740187411874218743187441874518746187471874818749187501875118752187531875418755187561875718758187591876018761187621876318764187651876618767187681876918770187711877218773187741877518776187771877818779187801878118782187831878418785187861878718788187891879018791187921879318794187951879618797187981879918800188011880218803188041880518806188071880818809188101881118812188131881418815188161881718818188191882018821188221882318824188251882618827188281882918830188311883218833188341883518836188371883818839188401884118842188431884418845188461884718848188491885018851188521885318854188551885618857188581885918860188611886218863188641886518866188671886818869188701887118872188731887418875188761887718878188791888018881188821888318884188851888618887188881888918890188911889218893188941889518896188971889818899189001890118902189031890418905189061890718908189091891018911189121891318914189151891618917189181891918920189211892218923189241892518926189271892818929189301893118932189331893418935189361893718938189391894018941189421894318944189451894618947189481894918950189511895218953189541895518956189571895818959189601896118962189631896418965189661896718968189691897018971189721897318974189751897618977189781897918980189811898218983189841898518986189871898818989189901899118992189931899418995189961899718998189991900019001190021900319004190051900619007190081900919010190111901219013190141901519016190171901819019190201902119022190231902419025190261902719028190291903019031190321903319034190351903619037190381903919040190411904219043190441904519046190471904819049190501905119052190531905419055190561905719058190591906019061190621906319064190651906619067190681906919070190711907219073190741907519076190771907819079190801908119082190831908419085190861908719088190891909019091190921909319094190951909619097190981909919100191011910219103191041910519106191071910819109191101911119112191131911419115191161911719118191191912019121191221912319124191251912619127191281912919130191311913219133191341913519136191371913819139191401914119142191431914419145191461914719148191491915019151191521915319154191551915619157191581915919160191611916219163191641916519166191671916819169191701917119172191731917419175191761917719178191791918019181191821918319184191851918619187191881918919190191911919219193191941919519196191971919819199192001920119202192031920419205192061920719208192091921019211192121921319214192151921619217192181921919220192211922219223192241922519226192271922819229192301923119232192331923419235192361923719238192391924019241192421924319244192451924619247192481924919250192511925219253192541925519256192571925819259192601926119262192631926419265192661926719268192691927019271192721927319274192751927619277192781927919280192811928219283192841928519286192871928819289192901929119292192931929419295192961929719298192991930019301193021930319304193051930619307193081930919310193111931219313193141931519316193171931819319193201932119322193231932419325193261932719328193291933019331193321933319334193351933619337193381933919340193411934219343193441934519346193471934819349193501935119352193531935419355193561935719358193591936019361193621936319364193651936619367193681936919370193711937219373193741937519376193771937819379193801938119382193831938419385193861938719388193891939019391193921939319394193951939619397193981939919400194011940219403194041940519406194071940819409194101941119412194131941419415194161941719418194191942019421194221942319424194251942619427194281942919430194311943219433194341943519436194371943819439194401944119442194431944419445194461944719448194491945019451194521945319454194551945619457194581945919460194611946219463194641946519466194671946819469194701947119472194731947419475194761947719478194791948019481194821948319484194851948619487194881948919490194911949219493194941949519496194971949819499195001950119502195031950419505195061950719508195091951019511195121951319514195151951619517195181951919520195211952219523195241952519526195271952819529195301953119532195331953419535195361953719538195391954019541195421954319544195451954619547195481954919550195511955219553195541955519556195571955819559195601956119562195631956419565195661956719568195691957019571195721957319574195751957619577195781957919580195811958219583195841958519586195871958819589195901959119592195931959419595195961959719598195991960019601196021960319604196051960619607196081960919610196111961219613196141961519616196171961819619196201962119622196231962419625196261962719628196291963019631196321963319634196351963619637196381963919640196411964219643196441964519646196471964819649196501965119652196531965419655196561965719658196591966019661196621966319664196651966619667196681966919670196711967219673196741967519676196771967819679196801968119682196831968419685196861968719688196891969019691196921969319694196951969619697196981969919700197011970219703197041970519706197071970819709197101971119712197131971419715197161971719718197191972019721197221972319724197251972619727197281972919730197311973219733197341973519736197371973819739197401974119742197431974419745197461974719748197491975019751197521975319754197551975619757197581975919760197611976219763197641976519766197671976819769197701977119772197731977419775197761977719778197791978019781197821978319784197851978619787197881978919790197911979219793197941979519796197971979819799198001980119802198031980419805198061980719808198091981019811198121981319814198151981619817198181981919820198211982219823198241982519826198271982819829198301983119832198331983419835198361983719838198391984019841198421984319844198451984619847198481984919850198511985219853198541985519856198571985819859198601986119862198631986419865198661986719868198691987019871198721987319874198751987619877198781987919880198811988219883198841988519886198871988819889198901989119892198931989419895198961989719898198991990019901199021990319904199051990619907199081990919910199111991219913199141991519916199171991819919199201992119922199231992419925199261992719928199291993019931199321993319934199351993619937199381993919940199411994219943199441994519946199471994819949199501995119952199531995419955199561995719958199591996019961199621996319964199651996619967199681996919970199711997219973199741997519976199771997819979199801998119982199831998419985199861998719988199891999019991199921999319994199951999619997199981999920000200012000220003200042000520006200072000820009200102001120012200132001420015200162001720018200192002020021200222002320024200252002620027200282002920030200312003220033200342003520036200372003820039200402004120042200432004420045200462004720048200492005020051200522005320054200552005620057200582005920060200612006220063200642006520066200672006820069200702007120072200732007420075200762007720078200792008020081200822008320084200852008620087200882008920090200912009220093200942009520096200972009820099201002010120102201032010420105201062010720108201092011020111201122011320114201152011620117201182011920120201212012220123201242012520126201272012820129201302013120132201332013420135201362013720138201392014020141201422014320144201452014620147201482014920150201512015220153201542015520156201572015820159201602016120162201632016420165201662016720168201692017020171201722017320174201752017620177201782017920180201812018220183201842018520186201872018820189201902019120192201932019420195201962019720198201992020020201202022020320204202052020620207202082020920210202112021220213202142021520216202172021820219202202022120222202232022420225202262022720228202292023020231202322023320234202352023620237202382023920240202412024220243202442024520246202472024820249202502025120252202532025420255202562025720258202592026020261202622026320264202652026620267202682026920270202712027220273202742027520276202772027820279202802028120282202832028420285202862028720288202892029020291202922029320294202952029620297202982029920300203012030220303203042030520306203072030820309203102031120312203132031420315203162031720318203192032020321203222032320324203252032620327203282032920330203312033220333203342033520336203372033820339203402034120342203432034420345203462034720348203492035020351203522035320354203552035620357203582035920360203612036220363203642036520366203672036820369203702037120372203732037420375203762037720378203792038020381203822038320384203852038620387203882038920390203912039220393203942039520396203972039820399204002040120402204032040420405204062040720408204092041020411204122041320414204152041620417204182041920420204212042220423204242042520426204272042820429204302043120432204332043420435204362043720438204392044020441204422044320444204452044620447204482044920450204512045220453204542045520456204572045820459204602046120462204632046420465204662046720468204692047020471204722047320474204752047620477204782047920480204812048220483204842048520486204872048820489204902049120492204932049420495204962049720498204992050020501205022050320504205052050620507205082050920510205112051220513205142051520516205172051820519205202052120522205232052420525205262052720528205292053020531205322053320534205352053620537205382053920540205412054220543205442054520546205472054820549205502055120552205532055420555205562055720558205592056020561205622056320564205652056620567205682056920570205712057220573205742057520576205772057820579205802058120582205832058420585205862058720588205892059020591205922059320594205952059620597205982059920600206012060220603206042060520606206072060820609206102061120612206132061420615206162061720618206192062020621206222062320624206252062620627206282062920630206312063220633206342063520636206372063820639206402064120642206432064420645206462064720648206492065020651206522065320654206552065620657206582065920660206612066220663206642066520666206672066820669206702067120672206732067420675206762067720678206792068020681206822068320684206852068620687206882068920690206912069220693206942069520696206972069820699207002070120702207032070420705207062070720708207092071020711207122071320714207152071620717207182071920720207212072220723207242072520726207272072820729207302073120732207332073420735207362073720738207392074020741207422074320744207452074620747207482074920750207512075220753207542075520756207572075820759207602076120762207632076420765207662076720768207692077020771207722077320774207752077620777207782077920780207812078220783207842078520786207872078820789207902079120792207932079420795207962079720798207992080020801208022080320804208052080620807208082080920810208112081220813208142081520816208172081820819208202082120822208232082420825208262082720828208292083020831208322083320834208352083620837208382083920840208412084220843208442084520846208472084820849208502085120852208532085420855208562085720858208592086020861208622086320864208652086620867208682086920870208712087220873208742087520876208772087820879208802088120882208832088420885208862088720888208892089020891208922089320894208952089620897208982089920900209012090220903209042090520906209072090820909209102091120912209132091420915209162091720918209192092020921209222092320924209252092620927209282092920930209312093220933209342093520936209372093820939209402094120942209432094420945209462094720948209492095020951209522095320954209552095620957209582095920960209612096220963209642096520966209672096820969209702097120972209732097420975209762097720978209792098020981209822098320984209852098620987209882098920990209912099220993209942099520996209972099820999210002100121002210032100421005210062100721008210092101021011210122101321014210152101621017210182101921020210212102221023210242102521026210272102821029210302103121032210332103421035210362103721038210392104021041210422104321044210452104621047210482104921050210512105221053210542105521056210572105821059210602106121062210632106421065210662106721068210692107021071210722107321074210752107621077210782107921080210812108221083210842108521086210872108821089210902109121092210932109421095210962109721098210992110021101211022110321104211052110621107211082110921110211112111221113211142111521116211172111821119211202112121122211232112421125211262112721128211292113021131211322113321134211352113621137211382113921140211412114221143211442114521146211472114821149211502115121152211532115421155211562115721158211592116021161211622116321164211652116621167211682116921170211712117221173211742117521176211772117821179211802118121182211832118421185211862118721188211892119021191211922119321194211952119621197211982119921200212012120221203212042120521206212072120821209212102121121212212132121421215212162121721218212192122021221212222122321224212252122621227212282122921230212312123221233212342123521236212372123821239212402124121242212432124421245212462124721248212492125021251212522125321254212552125621257212582125921260212612126221263212642126521266212672126821269212702127121272212732127421275212762127721278212792128021281212822128321284212852128621287212882128921290212912129221293212942129521296212972129821299213002130121302213032130421305213062130721308213092131021311213122131321314213152131621317213182131921320213212132221323213242132521326213272132821329213302133121332213332133421335213362133721338213392134021341213422134321344213452134621347213482134921350213512135221353213542135521356213572135821359213602136121362213632136421365213662136721368213692137021371213722137321374213752137621377213782137921380213812138221383213842138521386213872138821389213902139121392213932139421395213962139721398213992140021401214022140321404214052140621407214082140921410214112141221413214142141521416214172141821419214202142121422214232142421425214262142721428214292143021431214322143321434214352143621437214382143921440214412144221443214442144521446214472144821449214502145121452214532145421455214562145721458214592146021461214622146321464214652146621467214682146921470214712147221473214742147521476214772147821479214802148121482214832148421485214862148721488214892149021491214922149321494214952149621497214982149921500215012150221503215042150521506215072150821509215102151121512215132151421515215162151721518215192152021521215222152321524215252152621527215282152921530215312153221533215342153521536215372153821539215402154121542215432154421545215462154721548215492155021551215522155321554215552155621557215582155921560215612156221563215642156521566215672156821569215702157121572215732157421575215762157721578215792158021581215822158321584215852158621587215882158921590215912159221593215942159521596215972159821599216002160121602216032160421605216062160721608216092161021611216122161321614216152161621617216182161921620216212162221623216242162521626216272162821629216302163121632216332163421635216362163721638216392164021641216422164321644216452164621647216482164921650216512165221653216542165521656216572165821659216602166121662216632166421665216662166721668216692167021671216722167321674216752167621677216782167921680216812168221683216842168521686216872168821689216902169121692216932169421695216962169721698216992170021701217022170321704217052170621707217082170921710217112171221713217142171521716217172171821719217202172121722217232172421725217262172721728217292173021731217322173321734217352173621737217382173921740217412174221743217442174521746217472174821749217502175121752217532175421755217562175721758217592176021761217622176321764217652176621767217682176921770217712177221773217742177521776217772177821779217802178121782217832178421785217862178721788217892179021791217922179321794217952179621797217982179921800218012180221803218042180521806218072180821809218102181121812218132181421815218162181721818218192182021821218222182321824218252182621827218282182921830218312183221833218342183521836218372183821839218402184121842218432184421845218462184721848218492185021851218522185321854218552185621857218582185921860218612186221863218642186521866218672186821869218702187121872218732187421875218762187721878218792188021881218822188321884218852188621887218882188921890218912189221893218942189521896218972189821899219002190121902219032190421905219062190721908219092191021911219122191321914219152191621917219182191921920219212192221923219242192521926219272192821929219302193121932219332193421935219362193721938219392194021941219422194321944219452194621947219482194921950219512195221953219542195521956219572195821959219602196121962219632196421965219662196721968219692197021971219722197321974219752197621977219782197921980219812198221983219842198521986219872198821989219902199121992219932199421995219962199721998219992200022001220022200322004220052200622007220082200922010220112201222013220142201522016220172201822019220202202122022220232202422025220262202722028220292203022031220322203322034220352203622037220382203922040220412204222043220442204522046220472204822049220502205122052220532205422055220562205722058220592206022061220622206322064220652206622067220682206922070220712207222073220742207522076220772207822079220802208122082220832208422085220862208722088220892209022091220922209322094220952209622097220982209922100221012210222103221042210522106221072210822109221102211122112221132211422115221162211722118221192212022121221222212322124221252212622127221282212922130221312213222133221342213522136221372213822139221402214122142221432214422145221462214722148221492215022151221522215322154221552215622157221582215922160221612216222163221642216522166221672216822169221702217122172221732217422175221762217722178221792218022181221822218322184221852218622187221882218922190221912219222193221942219522196221972219822199222002220122202222032220422205222062220722208222092221022211222122221322214222152221622217222182221922220222212222222223222242222522226222272222822229222302223122232222332223422235222362223722238222392224022241222422224322244222452224622247222482224922250222512225222253222542225522256222572225822259222602226122262222632226422265222662226722268222692227022271222722227322274222752227622277222782227922280222812228222283222842228522286222872228822289222902229122292222932229422295222962229722298222992230022301223022230322304223052230622307223082230922310223112231222313223142231522316223172231822319223202232122322223232232422325223262232722328223292233022331223322233322334223352233622337223382233922340223412234222343223442234522346223472234822349223502235122352223532235422355223562235722358223592236022361223622236322364223652236622367223682236922370223712237222373223742237522376223772237822379223802238122382223832238422385223862238722388223892239022391223922239322394223952239622397223982239922400224012240222403224042240522406224072240822409224102241122412224132241422415224162241722418224192242022421224222242322424224252242622427224282242922430224312243222433224342243522436224372243822439224402244122442224432244422445224462244722448224492245022451224522245322454224552245622457224582245922460224612246222463224642246522466224672246822469224702247122472224732247422475224762247722478224792248022481224822248322484224852248622487224882248922490224912249222493224942249522496224972249822499225002250122502225032250422505225062250722508225092251022511225122251322514225152251622517225182251922520225212252222523225242252522526225272252822529225302253122532225332253422535225362253722538225392254022541225422254322544225452254622547225482254922550225512255222553225542255522556225572255822559225602256122562225632256422565225662256722568225692257022571225722257322574225752257622577225782257922580225812258222583225842258522586225872258822589225902259122592225932259422595225962259722598225992260022601226022260322604226052260622607226082260922610226112261222613226142261522616226172261822619226202262122622226232262422625226262262722628226292263022631226322263322634226352263622637226382263922640226412264222643226442264522646226472264822649226502265122652226532265422655226562265722658226592266022661226622266322664226652266622667226682266922670226712267222673226742267522676226772267822679226802268122682226832268422685226862268722688226892269022691226922269322694226952269622697226982269922700227012270222703227042270522706227072270822709227102271122712227132271422715227162271722718227192272022721227222272322724227252272622727227282272922730227312273222733227342273522736227372273822739227402274122742227432274422745227462274722748227492275022751227522275322754227552275622757227582275922760227612276222763227642276522766227672276822769227702277122772227732277422775227762277722778227792278022781227822278322784227852278622787227882278922790227912279222793227942279522796227972279822799228002280122802228032280422805228062280722808228092281022811228122281322814228152281622817228182281922820228212282222823228242282522826228272282822829228302283122832228332283422835228362283722838228392284022841228422284322844228452284622847228482284922850228512285222853228542285522856228572285822859228602286122862228632286422865228662286722868228692287022871228722287322874228752287622877228782287922880228812288222883228842288522886228872288822889228902289122892228932289422895228962289722898228992290022901229022290322904229052290622907229082290922910229112291222913229142291522916229172291822919229202292122922229232292422925229262292722928229292293022931229322293322934229352293622937229382293922940229412294222943229442294522946229472294822949229502295122952229532295422955229562295722958229592296022961229622296322964229652296622967229682296922970229712297222973229742297522976229772297822979229802298122982229832298422985229862298722988229892299022991229922299322994229952299622997229982299923000230012300223003230042300523006230072300823009230102301123012230132301423015230162301723018230192302023021230222302323024230252302623027230282302923030230312303223033230342303523036230372303823039230402304123042230432304423045230462304723048230492305023051230522305323054230552305623057230582305923060230612306223063230642306523066230672306823069230702307123072230732307423075230762307723078230792308023081230822308323084230852308623087230882308923090230912309223093230942309523096230972309823099231002310123102231032310423105231062310723108231092311023111231122311323114231152311623117231182311923120231212312223123231242312523126231272312823129231302313123132231332313423135231362313723138231392314023141231422314323144231452314623147231482314923150231512315223153231542315523156231572315823159231602316123162231632316423165231662316723168231692317023171231722317323174231752317623177231782317923180231812318223183231842318523186231872318823189231902319123192231932319423195231962319723198231992320023201232022320323204232052320623207232082320923210232112321223213232142321523216232172321823219232202322123222232232322423225232262322723228232292323023231232322323323234232352323623237232382323923240232412324223243232442324523246232472324823249232502325123252232532325423255232562325723258232592326023261232622326323264232652326623267232682326923270232712327223273232742327523276232772327823279232802328123282232832328423285232862328723288232892329023291232922329323294232952329623297232982329923300233012330223303233042330523306233072330823309233102331123312233132331423315233162331723318233192332023321233222332323324233252332623327233282332923330233312333223333233342333523336233372333823339233402334123342233432334423345233462334723348233492335023351233522335323354233552335623357233582335923360233612336223363233642336523366233672336823369233702337123372233732337423375233762337723378233792338023381233822338323384233852338623387233882338923390233912339223393233942339523396233972339823399234002340123402234032340423405234062340723408234092341023411234122341323414234152341623417234182341923420234212342223423234242342523426234272342823429234302343123432234332343423435234362343723438234392344023441234422344323444234452344623447234482344923450234512345223453234542345523456234572345823459234602346123462234632346423465234662346723468234692347023471234722347323474234752347623477234782347923480234812348223483234842348523486234872348823489234902349123492234932349423495234962349723498234992350023501235022350323504235052350623507235082350923510235112351223513235142351523516235172351823519235202352123522235232352423525235262352723528235292353023531235322353323534235352353623537235382353923540235412354223543235442354523546235472354823549235502355123552235532355423555235562355723558235592356023561235622356323564235652356623567235682356923570235712357223573235742357523576235772357823579235802358123582235832358423585235862358723588235892359023591235922359323594235952359623597235982359923600236012360223603236042360523606236072360823609236102361123612236132361423615236162361723618236192362023621236222362323624236252362623627236282362923630236312363223633236342363523636236372363823639236402364123642236432364423645236462364723648236492365023651236522365323654236552365623657236582365923660236612366223663236642366523666236672366823669236702367123672236732367423675236762367723678236792368023681236822368323684236852368623687236882368923690236912369223693236942369523696236972369823699237002370123702237032370423705237062370723708237092371023711237122371323714237152371623717237182371923720237212372223723237242372523726237272372823729237302373123732237332373423735237362373723738237392374023741237422374323744237452374623747237482374923750237512375223753237542375523756237572375823759237602376123762237632376423765237662376723768237692377023771237722377323774237752377623777237782377923780237812378223783237842378523786237872378823789237902379123792237932379423795237962379723798237992380023801238022380323804238052380623807238082380923810238112381223813238142381523816238172381823819238202382123822238232382423825238262382723828238292383023831238322383323834238352383623837238382383923840238412384223843238442384523846238472384823849238502385123852238532385423855238562385723858238592386023861238622386323864238652386623867238682386923870238712387223873238742387523876238772387823879238802388123882238832388423885238862388723888238892389023891238922389323894238952389623897238982389923900239012390223903239042390523906239072390823909239102391123912239132391423915239162391723918239192392023921239222392323924239252392623927239282392923930239312393223933239342393523936239372393823939239402394123942239432394423945239462394723948239492395023951239522395323954239552395623957239582395923960239612396223963239642396523966239672396823969239702397123972239732397423975239762397723978239792398023981239822398323984239852398623987239882398923990239912399223993239942399523996239972399823999240002400124002240032400424005240062400724008240092401024011240122401324014240152401624017240182401924020240212402224023240242402524026240272402824029240302403124032240332403424035240362403724038240392404024041240422404324044240452404624047240482404924050240512405224053240542405524056240572405824059240602406124062240632406424065240662406724068240692407024071240722407324074240752407624077240782407924080240812408224083240842408524086240872408824089240902409124092240932409424095240962409724098240992410024101241022410324104241052410624107241082410924110241112411224113241142411524116241172411824119241202412124122241232412424125241262412724128241292413024131241322413324134241352413624137241382413924140241412414224143241442414524146241472414824149241502415124152241532415424155241562415724158241592416024161241622416324164241652416624167241682416924170241712417224173241742417524176241772417824179241802418124182241832418424185241862418724188241892419024191241922419324194241952419624197241982419924200242012420224203242042420524206242072420824209242102421124212242132421424215242162421724218242192422024221242222422324224242252422624227242282422924230242312423224233242342423524236242372423824239242402424124242242432424424245242462424724248242492425024251242522425324254242552425624257242582425924260242612426224263242642426524266242672426824269242702427124272242732427424275242762427724278242792428024281242822428324284242852428624287242882428924290242912429224293242942429524296242972429824299243002430124302243032430424305243062430724308243092431024311243122431324314243152431624317243182431924320243212432224323243242432524326243272432824329243302433124332243332433424335243362433724338243392434024341243422434324344243452434624347243482434924350243512435224353243542435524356243572435824359243602436124362243632436424365243662436724368243692437024371243722437324374243752437624377243782437924380243812438224383243842438524386243872438824389243902439124392243932439424395243962439724398243992440024401244022440324404244052440624407244082440924410244112441224413244142441524416244172441824419244202442124422244232442424425244262442724428244292443024431244322443324434244352443624437244382443924440244412444224443244442444524446244472444824449244502445124452244532445424455244562445724458244592446024461244622446324464244652446624467244682446924470244712447224473244742447524476244772447824479244802448124482244832448424485244862448724488244892449024491244922449324494244952449624497244982449924500245012450224503245042450524506245072450824509245102451124512245132451424515245162451724518245192452024521245222452324524245252452624527245282452924530245312453224533245342453524536245372453824539245402454124542245432454424545245462454724548245492455024551245522455324554245552455624557245582455924560245612456224563245642456524566245672456824569245702457124572245732457424575245762457724578245792458024581245822458324584245852458624587245882458924590245912459224593245942459524596245972459824599246002460124602246032460424605246062460724608246092461024611246122461324614246152461624617246182461924620246212462224623246242462524626246272462824629246302463124632246332463424635246362463724638246392464024641246422464324644246452464624647246482464924650246512465224653246542465524656246572465824659246602466124662246632466424665246662466724668246692467024671246722467324674246752467624677246782467924680246812468224683246842468524686246872468824689246902469124692246932469424695246962469724698246992470024701247022470324704247052470624707247082470924710247112471224713247142471524716247172471824719247202472124722247232472424725247262472724728247292473024731247322473324734247352473624737247382473924740247412474224743247442474524746247472474824749247502475124752247532475424755247562475724758247592476024761247622476324764247652476624767247682476924770247712477224773247742477524776247772477824779247802478124782247832478424785247862478724788247892479024791247922479324794247952479624797247982479924800248012480224803248042480524806248072480824809248102481124812248132481424815248162481724818248192482024821248222482324824248252482624827248282482924830248312483224833248342483524836248372483824839248402484124842248432484424845248462484724848248492485024851248522485324854248552485624857248582485924860248612486224863248642486524866248672486824869248702487124872248732487424875248762487724878248792488024881248822488324884248852488624887248882488924890248912489224893248942489524896248972489824899249002490124902249032490424905249062490724908249092491024911249122491324914249152491624917249182491924920249212492224923249242492524926249272492824929249302493124932249332493424935249362493724938249392494024941249422494324944249452494624947249482494924950249512495224953249542495524956249572495824959249602496124962249632496424965249662496724968249692497024971249722497324974249752497624977249782497924980249812498224983249842498524986249872498824989249902499124992249932499424995249962499724998249992500025001250022500325004250052500625007250082500925010250112501225013250142501525016250172501825019250202502125022250232502425025250262502725028250292503025031250322503325034250352503625037250382503925040250412504225043250442504525046250472504825049250502505125052250532505425055250562505725058250592506025061250622506325064250652506625067250682506925070250712507225073250742507525076250772507825079250802508125082250832508425085250862508725088250892509025091250922509325094250952509625097250982509925100251012510225103251042510525106251072510825109251102511125112251132511425115251162511725118251192512025121251222512325124251252512625127251282512925130251312513225133251342513525136251372513825139251402514125142251432514425145251462514725148251492515025151251522515325154251552515625157251582515925160251612516225163251642516525166251672516825169251702517125172251732517425175251762517725178251792518025181251822518325184251852518625187251882518925190251912519225193251942519525196251972519825199252002520125202252032520425205252062520725208252092521025211252122521325214252152521625217252182521925220252212522225223252242522525226252272522825229252302523125232252332523425235252362523725238252392524025241252422524325244252452524625247252482524925250252512525225253252542525525256252572525825259252602526125262252632526425265252662526725268252692527025271252722527325274252752527625277252782527925280252812528225283252842528525286252872528825289252902529125292252932529425295252962529725298252992530025301253022530325304253052530625307253082530925310253112531225313253142531525316253172531825319253202532125322253232532425325253262532725328253292533025331253322533325334253352533625337253382533925340253412534225343253442534525346253472534825349253502535125352253532535425355253562535725358253592536025361253622536325364253652536625367253682536925370253712537225373253742537525376253772537825379253802538125382253832538425385253862538725388253892539025391253922539325394253952539625397253982539925400254012540225403254042540525406254072540825409254102541125412254132541425415254162541725418254192542025421254222542325424254252542625427254282542925430254312543225433254342543525436254372543825439254402544125442254432544425445254462544725448254492545025451254522545325454254552545625457254582545925460254612546225463254642546525466254672546825469254702547125472254732547425475254762547725478254792548025481254822548325484254852548625487254882548925490254912549225493254942549525496254972549825499255002550125502255032550425505255062550725508255092551025511255122551325514255152551625517255182551925520255212552225523255242552525526255272552825529255302553125532255332553425535255362553725538255392554025541255422554325544255452554625547255482554925550255512555225553255542555525556255572555825559255602556125562255632556425565255662556725568255692557025571255722557325574255752557625577255782557925580255812558225583255842558525586255872558825589255902559125592255932559425595255962559725598255992560025601256022560325604256052560625607256082560925610256112561225613256142561525616256172561825619256202562125622256232562425625256262562725628256292563025631256322563325634256352563625637256382563925640256412564225643256442564525646256472564825649256502565125652256532565425655256562565725658256592566025661256622566325664256652566625667256682566925670256712567225673256742567525676256772567825679256802568125682256832568425685256862568725688256892569025691256922569325694256952569625697256982569925700257012570225703257042570525706257072570825709257102571125712257132571425715257162571725718257192572025721257222572325724257252572625727257282572925730257312573225733257342573525736257372573825739257402574125742257432574425745257462574725748257492575025751257522575325754257552575625757257582575925760257612576225763257642576525766257672576825769257702577125772257732577425775257762577725778257792578025781257822578325784257852578625787257882578925790257912579225793257942579525796257972579825799258002580125802258032580425805258062580725808258092581025811258122581325814258152581625817258182581925820258212582225823258242582525826258272582825829258302583125832258332583425835258362583725838258392584025841258422584325844258452584625847258482584925850258512585225853258542585525856258572585825859258602586125862258632586425865258662586725868258692587025871258722587325874258752587625877258782587925880258812588225883258842588525886258872588825889258902589125892258932589425895258962589725898258992590025901259022590325904259052590625907259082590925910259112591225913259142591525916259172591825919259202592125922259232592425925259262592725928259292593025931259322593325934259352593625937259382593925940259412594225943259442594525946259472594825949259502595125952259532595425955259562595725958259592596025961259622596325964259652596625967259682596925970259712597225973259742597525976259772597825979259802598125982259832598425985259862598725988259892599025991259922599325994259952599625997259982599926000260012600226003260042600526006260072600826009260102601126012260132601426015260162601726018260192602026021260222602326024260252602626027260282602926030260312603226033260342603526036260372603826039260402604126042260432604426045260462604726048260492605026051260522605326054260552605626057260582605926060260612606226063260642606526066260672606826069260702607126072260732607426075260762607726078260792608026081260822608326084260852608626087260882608926090260912609226093260942609526096260972609826099261002610126102261032610426105261062610726108261092611026111261122611326114261152611626117261182611926120261212612226123261242612526126261272612826129261302613126132261332613426135261362613726138261392614026141261422614326144261452614626147261482614926150261512615226153261542615526156261572615826159261602616126162261632616426165261662616726168261692617026171261722617326174261752617626177261782617926180261812618226183261842618526186261872618826189261902619126192261932619426195261962619726198261992620026201262022620326204262052620626207262082620926210262112621226213262142621526216262172621826219262202622126222262232622426225262262622726228262292623026231262322623326234262352623626237262382623926240262412624226243262442624526246262472624826249262502625126252262532625426255262562625726258262592626026261262622626326264262652626626267262682626926270262712627226273262742627526276262772627826279262802628126282262832628426285262862628726288262892629026291262922629326294262952629626297262982629926300263012630226303263042630526306263072630826309263102631126312263132631426315263162631726318263192632026321263222632326324263252632626327263282632926330263312633226333263342633526336263372633826339263402634126342263432634426345263462634726348263492635026351263522635326354263552635626357263582635926360263612636226363263642636526366263672636826369263702637126372263732637426375263762637726378263792638026381263822638326384263852638626387263882638926390263912639226393263942639526396263972639826399264002640126402264032640426405264062640726408264092641026411264122641326414264152641626417264182641926420264212642226423264242642526426264272642826429264302643126432264332643426435264362643726438264392644026441264422644326444264452644626447264482644926450264512645226453264542645526456264572645826459264602646126462264632646426465264662646726468264692647026471264722647326474264752647626477264782647926480264812648226483264842648526486264872648826489264902649126492264932649426495264962649726498264992650026501265022650326504265052650626507265082650926510265112651226513265142651526516265172651826519265202652126522265232652426525265262652726528265292653026531265322653326534265352653626537265382653926540265412654226543265442654526546265472654826549265502655126552265532655426555265562655726558265592656026561265622656326564265652656626567265682656926570265712657226573265742657526576265772657826579265802658126582265832658426585265862658726588265892659026591265922659326594265952659626597265982659926600266012660226603266042660526606266072660826609266102661126612266132661426615266162661726618266192662026621266222662326624266252662626627266282662926630266312663226633266342663526636266372663826639266402664126642266432664426645266462664726648266492665026651266522665326654266552665626657266582665926660266612666226663266642666526666266672666826669266702667126672266732667426675266762667726678266792668026681266822668326684266852668626687266882668926690266912669226693266942669526696266972669826699267002670126702267032670426705267062670726708267092671026711267122671326714267152671626717267182671926720267212672226723267242672526726267272672826729267302673126732267332673426735267362673726738267392674026741267422674326744267452674626747267482674926750267512675226753267542675526756267572675826759267602676126762267632676426765267662676726768267692677026771267722677326774267752677626777267782677926780267812678226783267842678526786267872678826789267902679126792267932679426795267962679726798267992680026801268022680326804268052680626807268082680926810268112681226813268142681526816268172681826819268202682126822268232682426825268262682726828268292683026831268322683326834268352683626837268382683926840268412684226843268442684526846268472684826849268502685126852268532685426855268562685726858268592686026861268622686326864268652686626867268682686926870268712687226873268742687526876268772687826879268802688126882268832688426885268862688726888268892689026891268922689326894268952689626897268982689926900269012690226903269042690526906269072690826909269102691126912269132691426915269162691726918269192692026921269222692326924269252692626927269282692926930269312693226933269342693526936269372693826939269402694126942269432694426945269462694726948269492695026951269522695326954269552695626957269582695926960269612696226963269642696526966269672696826969269702697126972269732697426975269762697726978269792698026981269822698326984269852698626987269882698926990269912699226993269942699526996269972699826999270002700127002270032700427005270062700727008270092701027011270122701327014270152701627017270182701927020270212702227023270242702527026270272702827029270302703127032270332703427035270362703727038270392704027041270422704327044270452704627047270482704927050270512705227053270542705527056270572705827059270602706127062270632706427065270662706727068270692707027071270722707327074270752707627077270782707927080270812708227083270842708527086270872708827089270902709127092270932709427095270962709727098270992710027101271022710327104271052710627107271082710927110271112711227113271142711527116271172711827119271202712127122271232712427125271262712727128271292713027131271322713327134271352713627137271382713927140271412714227143271442714527146271472714827149271502715127152271532715427155271562715727158271592716027161271622716327164271652716627167271682716927170271712717227173271742717527176271772717827179271802718127182271832718427185271862718727188271892719027191271922719327194271952719627197271982719927200272012720227203272042720527206272072720827209272102721127212272132721427215272162721727218272192722027221272222722327224272252722627227272282722927230272312723227233272342723527236272372723827239272402724127242272432724427245272462724727248272492725027251272522725327254272552725627257272582725927260272612726227263272642726527266272672726827269272702727127272272732727427275272762727727278272792728027281272822728327284272852728627287272882728927290272912729227293272942729527296272972729827299273002730127302273032730427305273062730727308273092731027311273122731327314273152731627317273182731927320273212732227323273242732527326273272732827329273302733127332273332733427335273362733727338273392734027341273422734327344273452734627347273482734927350273512735227353273542735527356273572735827359273602736127362273632736427365273662736727368273692737027371273722737327374273752737627377273782737927380273812738227383273842738527386273872738827389273902739127392273932739427395273962739727398273992740027401274022740327404274052740627407274082740927410274112741227413274142741527416274172741827419274202742127422274232742427425274262742727428274292743027431274322743327434274352743627437274382743927440274412744227443274442744527446274472744827449274502745127452274532745427455274562745727458274592746027461274622746327464274652746627467274682746927470274712747227473274742747527476274772747827479274802748127482274832748427485274862748727488274892749027491274922749327494274952749627497274982749927500275012750227503275042750527506275072750827509275102751127512275132751427515275162751727518275192752027521275222752327524275252752627527275282752927530275312753227533275342753527536275372753827539275402754127542275432754427545275462754727548275492755027551275522755327554275552755627557275582755927560275612756227563275642756527566275672756827569275702757127572275732757427575275762757727578275792758027581275822758327584275852758627587275882758927590275912759227593275942759527596275972759827599276002760127602276032760427605276062760727608276092761027611276122761327614276152761627617276182761927620276212762227623276242762527626276272762827629276302763127632276332763427635276362763727638276392764027641276422764327644276452764627647276482764927650276512765227653276542765527656276572765827659276602766127662276632766427665276662766727668276692767027671276722767327674276752767627677276782767927680276812768227683276842768527686276872768827689276902769127692276932769427695276962769727698276992770027701277022770327704277052770627707277082770927710277112771227713277142771527716277172771827719277202772127722277232772427725277262772727728277292773027731277322773327734277352773627737277382773927740277412774227743277442774527746277472774827749277502775127752277532775427755277562775727758277592776027761277622776327764277652776627767277682776927770277712777227773277742777527776277772777827779277802778127782277832778427785277862778727788277892779027791277922779327794277952779627797277982779927800278012780227803278042780527806278072780827809278102781127812278132781427815278162781727818278192782027821278222782327824278252782627827278282782927830278312783227833278342783527836278372783827839278402784127842278432784427845278462784727848278492785027851278522785327854278552785627857278582785927860278612786227863278642786527866278672786827869278702787127872278732787427875278762787727878278792788027881278822788327884278852788627887278882788927890278912789227893278942789527896278972789827899279002790127902279032790427905279062790727908279092791027911279122791327914279152791627917279182791927920279212792227923279242792527926279272792827929279302793127932279332793427935279362793727938279392794027941279422794327944279452794627947279482794927950279512795227953279542795527956279572795827959279602796127962279632796427965279662796727968279692797027971279722797327974279752797627977279782797927980279812798227983279842798527986279872798827989279902799127992279932799427995279962799727998279992800028001280022800328004280052800628007280082800928010280112801228013280142801528016280172801828019280202802128022280232802428025280262802728028280292803028031280322803328034280352803628037280382803928040280412804228043280442804528046280472804828049280502805128052280532805428055280562805728058280592806028061280622806328064280652806628067280682806928070280712807228073280742807528076280772807828079280802808128082280832808428085280862808728088280892809028091280922809328094280952809628097280982809928100281012810228103281042810528106281072810828109281102811128112281132811428115281162811728118281192812028121281222812328124281252812628127281282812928130281312813228133281342813528136281372813828139281402814128142281432814428145281462814728148281492815028151281522815328154281552815628157281582815928160281612816228163281642816528166281672816828169281702817128172281732817428175281762817728178281792818028181281822818328184281852818628187281882818928190281912819228193281942819528196281972819828199282002820128202282032820428205282062820728208282092821028211282122821328214282152821628217282182821928220282212822228223282242822528226282272822828229282302823128232282332823428235282362823728238282392824028241282422824328244282452824628247282482824928250282512825228253282542825528256282572825828259282602826128262282632826428265282662826728268282692827028271282722827328274282752827628277282782827928280282812828228283282842828528286282872828828289282902829128292282932829428295282962829728298282992830028301283022830328304283052830628307283082830928310283112831228313283142831528316283172831828319283202832128322283232832428325283262832728328283292833028331283322833328334283352833628337283382833928340283412834228343283442834528346283472834828349283502835128352283532835428355283562835728358283592836028361283622836328364283652836628367283682836928370283712837228373283742837528376283772837828379283802838128382283832838428385283862838728388283892839028391283922839328394283952839628397283982839928400284012840228403284042840528406284072840828409284102841128412284132841428415284162841728418284192842028421284222842328424284252842628427284282842928430284312843228433284342843528436284372843828439284402844128442284432844428445284462844728448284492845028451284522845328454284552845628457284582845928460284612846228463284642846528466284672846828469284702847128472284732847428475284762847728478284792848028481284822848328484284852848628487284882848928490284912849228493284942849528496284972849828499285002850128502285032850428505285062850728508285092851028511285122851328514285152851628517285182851928520285212852228523285242852528526285272852828529285302853128532285332853428535285362853728538285392854028541285422854328544285452854628547285482854928550285512855228553285542855528556285572855828559285602856128562285632856428565285662856728568285692857028571285722857328574285752857628577285782857928580285812858228583285842858528586285872858828589285902859128592285932859428595285962859728598285992860028601286022860328604286052860628607286082860928610286112861228613286142861528616286172861828619286202862128622286232862428625286262862728628286292863028631286322863328634286352863628637286382863928640286412864228643286442864528646286472864828649286502865128652286532865428655286562865728658286592866028661286622866328664286652866628667286682866928670286712867228673286742867528676286772867828679286802868128682286832868428685286862868728688286892869028691286922869328694286952869628697286982869928700287012870228703287042870528706287072870828709287102871128712287132871428715287162871728718287192872028721287222872328724287252872628727287282872928730287312873228733287342873528736287372873828739287402874128742287432874428745287462874728748287492875028751287522875328754287552875628757287582875928760287612876228763287642876528766287672876828769287702877128772287732877428775287762877728778287792878028781287822878328784287852878628787287882878928790287912879228793287942879528796287972879828799288002880128802288032880428805288062880728808288092881028811288122881328814288152881628817288182881928820288212882228823288242882528826288272882828829288302883128832288332883428835288362883728838288392884028841288422884328844288452884628847288482884928850288512885228853288542885528856288572885828859288602886128862288632886428865288662886728868288692887028871288722887328874288752887628877288782887928880288812888228883288842888528886288872888828889288902889128892288932889428895288962889728898288992890028901289022890328904289052890628907289082890928910289112891228913289142891528916289172891828919289202892128922289232892428925289262892728928289292893028931289322893328934289352893628937289382893928940289412894228943289442894528946289472894828949289502895128952289532895428955289562895728958289592896028961289622896328964289652896628967289682896928970289712897228973289742897528976289772897828979289802898128982289832898428985289862898728988289892899028991289922899328994289952899628997289982899929000290012900229003290042900529006290072900829009290102901129012290132901429015290162901729018290192902029021290222902329024290252902629027290282902929030290312903229033290342903529036290372903829039290402904129042290432904429045290462904729048290492905029051290522905329054290552905629057290582905929060290612906229063290642906529066290672906829069290702907129072290732907429075290762907729078290792908029081290822908329084290852908629087290882908929090290912909229093290942909529096290972909829099291002910129102291032910429105291062910729108291092911029111291122911329114291152911629117291182911929120291212912229123291242912529126291272912829129291302913129132291332913429135291362913729138291392914029141291422914329144291452914629147291482914929150291512915229153291542915529156291572915829159291602916129162291632916429165291662916729168291692917029171291722917329174291752917629177291782917929180291812918229183291842918529186291872918829189291902919129192291932919429195291962919729198291992920029201292022920329204292052920629207292082920929210292112921229213292142921529216292172921829219292202922129222292232922429225292262922729228292292923029231292322923329234292352923629237292382923929240292412924229243292442924529246292472924829249292502925129252292532925429255292562925729258292592926029261292622926329264292652926629267292682926929270292712927229273292742927529276292772927829279292802928129282292832928429285292862928729288292892929029291292922929329294292952929629297292982929929300293012930229303293042930529306293072930829309293102931129312293132931429315293162931729318293192932029321293222932329324293252932629327293282932929330293312933229333293342933529336293372933829339293402934129342293432934429345293462934729348293492935029351293522935329354293552935629357293582935929360293612936229363293642936529366293672936829369293702937129372293732937429375293762937729378293792938029381293822938329384293852938629387293882938929390293912939229393293942939529396293972939829399294002940129402294032940429405294062940729408294092941029411294122941329414294152941629417294182941929420294212942229423294242942529426294272942829429294302943129432294332943429435294362943729438294392944029441294422944329444294452944629447294482944929450294512945229453294542945529456294572945829459294602946129462294632946429465294662946729468294692947029471294722947329474294752947629477294782947929480294812948229483294842948529486294872948829489294902949129492294932949429495294962949729498294992950029501295022950329504295052950629507295082950929510295112951229513295142951529516295172951829519295202952129522295232952429525295262952729528295292953029531295322953329534295352953629537295382953929540295412954229543295442954529546295472954829549295502955129552295532955429555295562955729558295592956029561295622956329564295652956629567295682956929570295712957229573295742957529576295772957829579295802958129582295832958429585295862958729588295892959029591295922959329594295952959629597295982959929600296012960229603296042960529606296072960829609296102961129612296132961429615296162961729618296192962029621296222962329624296252962629627296282962929630296312963229633296342963529636296372963829639296402964129642296432964429645296462964729648296492965029651296522965329654296552965629657296582965929660296612966229663296642966529666296672966829669296702967129672296732967429675296762967729678296792968029681296822968329684296852968629687296882968929690296912969229693296942969529696296972969829699297002970129702297032970429705297062970729708297092971029711297122971329714297152971629717297182971929720297212972229723297242972529726297272972829729297302973129732297332973429735297362973729738297392974029741297422974329744297452974629747297482974929750297512975229753297542975529756297572975829759297602976129762297632976429765297662976729768297692977029771297722977329774297752977629777297782977929780297812978229783297842978529786297872978829789297902979129792297932979429795297962979729798297992980029801298022980329804298052980629807298082980929810298112981229813298142981529816298172981829819298202982129822298232982429825298262982729828298292983029831298322983329834298352983629837298382983929840298412984229843298442984529846298472984829849298502985129852298532985429855298562985729858298592986029861298622986329864298652986629867298682986929870298712987229873298742987529876298772987829879298802988129882298832988429885298862988729888298892989029891298922989329894298952989629897298982989929900299012990229903299042990529906299072990829909299102991129912299132991429915299162991729918299192992029921299222992329924299252992629927299282992929930299312993229933299342993529936299372993829939299402994129942299432994429945299462994729948299492995029951299522995329954299552995629957299582995929960299612996229963299642996529966299672996829969299702997129972299732997429975299762997729978299792998029981299822998329984299852998629987299882998929990299912999229993299942999529996299972999829999300003000130002300033000430005300063000730008300093001030011300123001330014300153001630017300183001930020300213002230023300243002530026300273002830029300303003130032300333003430035300363003730038300393004030041300423004330044300453004630047300483004930050300513005230053300543005530056300573005830059300603006130062300633006430065300663006730068300693007030071300723007330074300753007630077300783007930080300813008230083300843008530086300873008830089300903009130092300933009430095300963009730098300993010030101301023010330104301053010630107301083010930110301113011230113301143011530116301173011830119301203012130122301233012430125301263012730128301293013030131301323013330134301353013630137301383013930140301413014230143301443014530146301473014830149301503015130152301533015430155301563015730158301593016030161301623016330164301653016630167301683016930170301713017230173301743017530176301773017830179301803018130182301833018430185301863018730188301893019030191301923019330194301953019630197301983019930200302013020230203302043020530206302073020830209302103021130212302133021430215302163021730218302193022030221302223022330224302253022630227302283022930230302313023230233302343023530236302373023830239302403024130242302433024430245302463024730248302493025030251302523025330254302553025630257302583025930260302613026230263302643026530266302673026830269302703027130272302733027430275302763027730278302793028030281302823028330284302853028630287302883028930290302913029230293302943029530296302973029830299303003030130302303033030430305303063030730308303093031030311303123031330314303153031630317303183031930320303213032230323303243032530326303273032830329303303033130332303333033430335303363033730338303393034030341303423034330344303453034630347303483034930350303513035230353303543035530356303573035830359303603036130362303633036430365303663036730368303693037030371303723037330374303753037630377303783037930380303813038230383303843038530386303873038830389303903039130392303933039430395303963039730398303993040030401304023040330404304053040630407304083040930410304113041230413304143041530416304173041830419304203042130422304233042430425304263042730428304293043030431304323043330434304353043630437304383043930440304413044230443304443044530446304473044830449304503045130452304533045430455304563045730458304593046030461304623046330464304653046630467304683046930470304713047230473304743047530476304773047830479304803048130482304833048430485304863048730488304893049030491304923049330494304953049630497304983049930500305013050230503305043050530506305073050830509305103051130512305133051430515305163051730518305193052030521305223052330524305253052630527305283052930530305313053230533305343053530536305373053830539305403054130542305433054430545305463054730548305493055030551305523055330554305553055630557305583055930560305613056230563305643056530566305673056830569305703057130572305733057430575305763057730578305793058030581305823058330584305853058630587305883058930590305913059230593305943059530596305973059830599306003060130602306033060430605306063060730608306093061030611306123061330614306153061630617306183061930620306213062230623306243062530626306273062830629306303063130632306333063430635306363063730638306393064030641306423064330644306453064630647306483064930650306513065230653306543065530656306573065830659306603066130662306633066430665306663066730668306693067030671306723067330674306753067630677306783067930680306813068230683306843068530686306873068830689306903069130692306933069430695306963069730698306993070030701307023070330704307053070630707307083070930710307113071230713307143071530716307173071830719307203072130722307233072430725307263072730728307293073030731307323073330734307353073630737307383073930740307413074230743307443074530746307473074830749307503075130752307533075430755307563075730758307593076030761307623076330764307653076630767307683076930770307713077230773307743077530776307773077830779307803078130782307833078430785307863078730788307893079030791307923079330794307953079630797307983079930800308013080230803308043080530806308073080830809308103081130812308133081430815308163081730818308193082030821308223082330824308253082630827308283082930830308313083230833308343083530836308373083830839308403084130842308433084430845308463084730848308493085030851308523085330854308553085630857308583085930860308613086230863308643086530866308673086830869308703087130872308733087430875308763087730878308793088030881308823088330884308853088630887308883088930890308913089230893308943089530896308973089830899309003090130902309033090430905309063090730908309093091030911309123091330914309153091630917309183091930920309213092230923309243092530926309273092830929309303093130932309333093430935309363093730938309393094030941309423094330944309453094630947309483094930950309513095230953309543095530956309573095830959309603096130962309633096430965309663096730968309693097030971309723097330974309753097630977309783097930980309813098230983309843098530986309873098830989309903099130992309933099430995309963099730998309993100031001310023100331004310053100631007310083100931010310113101231013310143101531016310173101831019310203102131022310233102431025310263102731028310293103031031310323103331034310353103631037310383103931040310413104231043310443104531046310473104831049310503105131052310533105431055310563105731058310593106031061310623106331064310653106631067310683106931070310713107231073310743107531076310773107831079310803108131082310833108431085310863108731088310893109031091310923109331094310953109631097310983109931100311013110231103311043110531106311073110831109311103111131112311133111431115311163111731118311193112031121311223112331124311253112631127311283112931130311313113231133311343113531136311373113831139311403114131142311433114431145311463114731148311493115031151311523115331154311553115631157311583115931160311613116231163311643116531166311673116831169311703117131172311733117431175311763117731178311793118031181311823118331184311853118631187311883118931190311913119231193311943119531196311973119831199312003120131202312033120431205312063120731208312093121031211312123121331214312153121631217312183121931220312213122231223312243122531226312273122831229312303123131232312333123431235312363123731238312393124031241312423124331244312453124631247312483124931250312513125231253312543125531256312573125831259312603126131262312633126431265312663126731268312693127031271312723127331274312753127631277312783127931280312813128231283312843128531286312873128831289312903129131292312933129431295312963129731298312993130031301313023130331304313053130631307313083130931310313113131231313313143131531316313173131831319313203132131322313233132431325313263132731328313293133031331313323133331334313353133631337313383133931340313413134231343313443134531346313473134831349313503135131352313533135431355313563135731358313593136031361313623136331364313653136631367313683136931370313713137231373313743137531376313773137831379313803138131382313833138431385313863138731388313893139031391313923139331394313953139631397313983139931400314013140231403314043140531406314073140831409314103141131412314133141431415314163141731418314193142031421314223142331424314253142631427314283142931430314313143231433314343143531436314373143831439314403144131442314433144431445314463144731448314493145031451314523145331454314553145631457314583145931460314613146231463314643146531466314673146831469314703147131472314733147431475314763147731478314793148031481314823148331484314853148631487314883148931490314913149231493314943149531496314973149831499315003150131502315033150431505315063150731508315093151031511315123151331514315153151631517315183151931520315213152231523315243152531526315273152831529315303153131532315333153431535315363153731538315393154031541315423154331544315453154631547315483154931550315513155231553315543155531556315573155831559315603156131562315633156431565315663156731568315693157031571315723157331574315753157631577315783157931580315813158231583315843158531586315873158831589315903159131592315933159431595315963159731598315993160031601316023160331604316053160631607316083160931610316113161231613316143161531616316173161831619316203162131622316233162431625316263162731628316293163031631316323163331634316353163631637316383163931640316413164231643316443164531646316473164831649316503165131652316533165431655316563165731658316593166031661316623166331664316653166631667316683166931670316713167231673316743167531676316773167831679316803168131682316833168431685316863168731688316893169031691316923169331694316953169631697316983169931700317013170231703317043170531706317073170831709317103171131712317133171431715317163171731718317193172031721317223172331724317253172631727317283172931730317313173231733317343173531736317373173831739317403174131742317433174431745317463174731748317493175031751317523175331754317553175631757317583175931760317613176231763317643176531766317673176831769317703177131772317733177431775317763177731778317793178031781317823178331784317853178631787317883178931790317913179231793317943179531796317973179831799318003180131802318033180431805318063180731808318093181031811318123181331814318153181631817318183181931820318213182231823318243182531826318273182831829318303183131832318333183431835318363183731838318393184031841318423184331844318453184631847318483184931850318513185231853318543185531856318573185831859318603186131862318633186431865318663186731868318693187031871318723187331874318753187631877318783187931880318813188231883318843188531886318873188831889318903189131892318933189431895318963189731898318993190031901319023190331904319053190631907319083190931910319113191231913319143191531916319173191831919319203192131922319233192431925319263192731928319293193031931319323193331934319353193631937319383193931940319413194231943319443194531946319473194831949319503195131952319533195431955319563195731958319593196031961319623196331964319653196631967319683196931970319713197231973319743197531976319773197831979319803198131982319833198431985319863198731988319893199031991319923199331994319953199631997319983199932000320013200232003320043200532006320073200832009320103201132012320133201432015320163201732018320193202032021320223202332024320253202632027320283202932030320313203232033320343203532036320373203832039320403204132042320433204432045320463204732048320493205032051320523205332054320553205632057320583205932060320613206232063320643206532066320673206832069320703207132072320733207432075320763207732078320793208032081320823208332084320853208632087320883208932090320913209232093320943209532096320973209832099321003210132102321033210432105321063210732108321093211032111321123211332114321153211632117321183211932120321213212232123321243212532126321273212832129321303213132132321333213432135321363213732138321393214032141321423214332144321453214632147321483214932150321513215232153321543215532156321573215832159321603216132162321633216432165321663216732168321693217032171321723217332174321753217632177321783217932180321813218232183321843218532186321873218832189321903219132192321933219432195321963219732198321993220032201322023220332204322053220632207322083220932210322113221232213322143221532216322173221832219322203222132222322233222432225322263222732228322293223032231322323223332234322353223632237322383223932240322413224232243322443224532246322473224832249322503225132252322533225432255322563225732258322593226032261322623226332264322653226632267322683226932270322713227232273322743227532276322773227832279322803228132282322833228432285322863228732288322893229032291322923229332294322953229632297322983229932300323013230232303323043230532306323073230832309323103231132312323133231432315323163231732318323193232032321323223232332324323253232632327323283232932330323313233232333323343233532336323373233832339323403234132342323433234432345323463234732348323493235032351323523235332354323553235632357323583235932360323613236232363323643236532366323673236832369323703237132372323733237432375323763237732378323793238032381323823238332384323853238632387323883238932390323913239232393323943239532396323973239832399324003240132402324033240432405324063240732408324093241032411324123241332414324153241632417324183241932420324213242232423324243242532426324273242832429324303243132432324333243432435324363243732438324393244032441324423244332444324453244632447324483244932450324513245232453324543245532456324573245832459324603246132462324633246432465324663246732468324693247032471324723247332474324753247632477324783247932480324813248232483324843248532486324873248832489324903249132492324933249432495324963249732498324993250032501325023250332504325053250632507325083250932510325113251232513325143251532516325173251832519325203252132522325233252432525325263252732528325293253032531325323253332534325353253632537325383253932540325413254232543325443254532546325473254832549325503255132552325533255432555325563255732558325593256032561325623256332564325653256632567325683256932570325713257232573325743257532576325773257832579325803258132582325833258432585325863258732588325893259032591325923259332594325953259632597325983259932600326013260232603326043260532606326073260832609326103261132612326133261432615326163261732618326193262032621326223262332624326253262632627326283262932630326313263232633326343263532636326373263832639326403264132642326433264432645326463264732648326493265032651326523265332654326553265632657326583265932660326613266232663326643266532666326673266832669326703267132672326733267432675326763267732678326793268032681326823268332684326853268632687326883268932690326913269232693326943269532696326973269832699327003270132702327033270432705327063270732708327093271032711327123271332714327153271632717327183271932720327213272232723327243272532726327273272832729327303273132732327333273432735327363273732738327393274032741327423274332744327453274632747327483274932750327513275232753327543275532756327573275832759327603276132762327633276432765327663276732768327693277032771327723277332774327753277632777327783277932780327813278232783327843278532786327873278832789327903279132792327933279432795327963279732798327993280032801328023280332804328053280632807328083280932810328113281232813328143281532816328173281832819328203282132822328233282432825328263282732828328293283032831328323283332834328353283632837328383283932840328413284232843328443284532846328473284832849328503285132852328533285432855328563285732858328593286032861328623286332864328653286632867328683286932870328713287232873328743287532876328773287832879328803288132882328833288432885328863288732888328893289032891328923289332894328953289632897328983289932900329013290232903329043290532906329073290832909329103291132912329133291432915329163291732918329193292032921329223292332924329253292632927329283292932930329313293232933329343293532936329373293832939329403294132942329433294432945329463294732948329493295032951329523295332954329553295632957329583295932960329613296232963329643296532966329673296832969329703297132972329733297432975329763297732978329793298032981329823298332984329853298632987329883298932990329913299232993329943299532996329973299832999330003300133002330033300433005330063300733008330093301033011330123301333014330153301633017330183301933020330213302233023330243302533026330273302833029330303303133032330333303433035330363303733038330393304033041330423304333044330453304633047330483304933050330513305233053330543305533056330573305833059330603306133062330633306433065330663306733068330693307033071330723307333074330753307633077330783307933080330813308233083330843308533086330873308833089330903309133092330933309433095330963309733098330993310033101331023310333104331053310633107331083310933110331113311233113331143311533116331173311833119331203312133122331233312433125331263312733128331293313033131331323313333134331353313633137331383313933140331413314233143331443314533146331473314833149331503315133152331533315433155331563315733158331593316033161331623316333164331653316633167331683316933170331713317233173331743317533176331773317833179331803318133182331833318433185331863318733188331893319033191331923319333194331953319633197331983319933200332013320233203332043320533206332073320833209332103321133212332133321433215332163321733218332193322033221332223322333224332253322633227332283322933230332313323233233332343323533236332373323833239332403324133242332433324433245332463324733248332493325033251332523325333254332553325633257332583325933260332613326233263332643326533266332673326833269332703327133272332733327433275332763327733278332793328033281332823328333284332853328633287332883328933290332913329233293332943329533296332973329833299333003330133302333033330433305333063330733308333093331033311333123331333314333153331633317333183331933320333213332233323333243332533326333273332833329333303333133332333333333433335333363333733338333393334033341333423334333344333453334633347333483334933350333513335233353333543335533356333573335833359333603336133362333633336433365333663336733368333693337033371333723337333374333753337633377333783337933380333813338233383333843338533386333873338833389333903339133392333933339433395333963339733398333993340033401334023340333404334053340633407334083340933410334113341233413334143341533416334173341833419334203342133422334233342433425334263342733428334293343033431334323343333434334353343633437334383343933440334413344233443334443344533446334473344833449334503345133452334533345433455334563345733458334593346033461334623346333464334653346633467334683346933470334713347233473334743347533476334773347833479334803348133482334833348433485334863348733488334893349033491334923349333494334953349633497334983349933500335013350233503335043350533506335073350833509335103351133512335133351433515335163351733518335193352033521335223352333524335253352633527335283352933530335313353233533335343353533536335373353833539335403354133542335433354433545335463354733548335493355033551335523355333554335553355633557335583355933560335613356233563335643356533566335673356833569335703357133572335733357433575335763357733578335793358033581335823358333584335853358633587335883358933590335913359233593335943359533596335973359833599336003360133602336033360433605336063360733608336093361033611336123361333614336153361633617336183361933620336213362233623336243362533626336273362833629336303363133632336333363433635336363363733638336393364033641336423364333644336453364633647336483364933650336513365233653336543365533656336573365833659336603366133662336633366433665336663366733668336693367033671336723367333674336753367633677336783367933680336813368233683336843368533686336873368833689336903369133692336933369433695336963369733698336993370033701337023370333704337053370633707337083370933710337113371233713337143371533716337173371833719337203372133722337233372433725337263372733728337293373033731337323373333734337353373633737337383373933740337413374233743337443374533746337473374833749337503375133752337533375433755337563375733758337593376033761337623376333764337653376633767337683376933770337713377233773337743377533776337773377833779337803378133782337833378433785337863378733788337893379033791337923379333794337953379633797337983379933800338013380233803338043380533806338073380833809338103381133812338133381433815338163381733818338193382033821338223382333824338253382633827338283382933830338313383233833338343383533836338373383833839338403384133842338433384433845338463384733848338493385033851338523385333854338553385633857338583385933860338613386233863338643386533866338673386833869338703387133872338733387433875338763387733878338793388033881338823388333884338853388633887338883388933890338913389233893338943389533896338973389833899339003390133902339033390433905339063390733908339093391033911339123391333914339153391633917339183391933920339213392233923339243392533926339273392833929339303393133932339333393433935339363393733938339393394033941339423394333944339453394633947339483394933950339513395233953339543395533956339573395833959339603396133962339633396433965339663396733968339693397033971339723397333974339753397633977339783397933980339813398233983339843398533986339873398833989339903399133992339933399433995339963399733998339993400034001340023400334004340053400634007340083400934010340113401234013340143401534016340173401834019340203402134022340233402434025340263402734028340293403034031340323403334034340353403634037340383403934040340413404234043340443404534046340473404834049340503405134052340533405434055340563405734058340593406034061340623406334064340653406634067340683406934070340713407234073340743407534076340773407834079340803408134082340833408434085340863408734088340893409034091340923409334094340953409634097340983409934100341013410234103341043410534106341073410834109341103411134112341133411434115341163411734118341193412034121341223412334124341253412634127341283412934130341313413234133341343413534136341373413834139341403414134142341433414434145341463414734148341493415034151341523415334154341553415634157341583415934160341613416234163341643416534166341673416834169341703417134172341733417434175341763417734178341793418034181341823418334184341853418634187341883418934190341913419234193341943419534196341973419834199342003420134202342033420434205342063420734208342093421034211342123421334214342153421634217342183421934220342213422234223342243422534226342273422834229342303423134232342333423434235342363423734238342393424034241342423424334244342453424634247342483424934250342513425234253342543425534256342573425834259342603426134262342633426434265342663426734268342693427034271342723427334274342753427634277342783427934280342813428234283342843428534286342873428834289342903429134292342933429434295342963429734298342993430034301343023430334304343053430634307343083430934310343113431234313343143431534316343173431834319343203432134322343233432434325343263432734328343293433034331343323433334334343353433634337343383433934340343413434234343343443434534346343473434834349343503435134352343533435434355343563435734358343593436034361343623436334364343653436634367343683436934370343713437234373343743437534376343773437834379343803438134382343833438434385343863438734388343893439034391343923439334394343953439634397343983439934400344013440234403344043440534406344073440834409344103441134412344133441434415344163441734418344193442034421344223442334424344253442634427344283442934430344313443234433344343443534436344373443834439344403444134442344433444434445344463444734448344493445034451344523445334454344553445634457344583445934460344613446234463344643446534466344673446834469344703447134472344733447434475344763447734478344793448034481344823448334484344853448634487344883448934490344913449234493344943449534496344973449834499345003450134502345033450434505345063450734508345093451034511345123451334514345153451634517345183451934520345213452234523345243452534526345273452834529345303453134532345333453434535345363453734538345393454034541345423454334544345453454634547345483454934550345513455234553345543455534556345573455834559345603456134562345633456434565345663456734568345693457034571345723457334574345753457634577345783457934580345813458234583345843458534586345873458834589345903459134592345933459434595345963459734598345993460034601346023460334604346053460634607346083460934610346113461234613346143461534616346173461834619346203462134622346233462434625346263462734628346293463034631346323463334634346353463634637346383463934640346413464234643346443464534646346473464834649346503465134652346533465434655346563465734658346593466034661346623466334664346653466634667346683466934670346713467234673346743467534676346773467834679346803468134682346833468434685346863468734688346893469034691346923469334694346953469634697346983469934700347013470234703347043470534706347073470834709347103471134712347133471434715347163471734718347193472034721347223472334724347253472634727347283472934730347313473234733347343473534736347373473834739347403474134742347433474434745347463474734748347493475034751347523475334754347553475634757347583475934760347613476234763347643476534766347673476834769347703477134772347733477434775347763477734778347793478034781347823478334784347853478634787347883478934790347913479234793347943479534796347973479834799348003480134802348033480434805348063480734808348093481034811348123481334814348153481634817348183481934820348213482234823348243482534826348273482834829348303483134832348333483434835348363483734838348393484034841348423484334844348453484634847348483484934850348513485234853348543485534856348573485834859348603486134862348633486434865348663486734868348693487034871348723487334874348753487634877348783487934880348813488234883348843488534886348873488834889348903489134892348933489434895348963489734898348993490034901349023490334904349053490634907349083490934910349113491234913349143491534916349173491834919349203492134922349233492434925349263492734928349293493034931349323493334934349353493634937349383493934940349413494234943349443494534946349473494834949349503495134952349533495434955349563495734958349593496034961349623496334964349653496634967349683496934970349713497234973349743497534976349773497834979349803498134982349833498434985349863498734988349893499034991349923499334994349953499634997349983499935000350013500235003350043500535006350073500835009350103501135012350133501435015350163501735018350193502035021350223502335024350253502635027350283502935030350313503235033350343503535036350373503835039350403504135042350433504435045350463504735048350493505035051350523505335054350553505635057350583505935060350613506235063350643506535066350673506835069350703507135072350733507435075350763507735078350793508035081350823508335084350853508635087350883508935090350913509235093350943509535096350973509835099351003510135102351033510435105351063510735108351093511035111351123511335114351153511635117351183511935120351213512235123351243512535126351273512835129351303513135132351333513435135351363513735138351393514035141351423514335144351453514635147351483514935150351513515235153351543515535156351573515835159351603516135162351633516435165351663516735168351693517035171351723517335174351753517635177351783517935180351813518235183351843518535186351873518835189351903519135192351933519435195351963519735198351993520035201352023520335204352053520635207352083520935210352113521235213352143521535216352173521835219352203522135222352233522435225352263522735228352293523035231352323523335234352353523635237352383523935240352413524235243352443524535246352473524835249352503525135252352533525435255352563525735258352593526035261352623526335264352653526635267352683526935270352713527235273352743527535276352773527835279352803528135282352833528435285352863528735288352893529035291352923529335294352953529635297352983529935300353013530235303353043530535306353073530835309353103531135312353133531435315353163531735318353193532035321353223532335324353253532635327353283532935330353313533235333353343533535336353373533835339353403534135342353433534435345353463534735348353493535035351353523535335354353553535635357353583535935360353613536235363353643536535366353673536835369353703537135372353733537435375353763537735378353793538035381353823538335384353853538635387353883538935390353913539235393353943539535396353973539835399354003540135402354033540435405354063540735408354093541035411354123541335414354153541635417354183541935420354213542235423354243542535426354273542835429354303543135432354333543435435354363543735438354393544035441354423544335444354453544635447354483544935450354513545235453354543545535456354573545835459354603546135462354633546435465354663546735468354693547035471354723547335474354753547635477354783547935480354813548235483354843548535486354873548835489354903549135492354933549435495354963549735498354993550035501355023550335504355053550635507355083550935510355113551235513355143551535516355173551835519355203552135522355233552435525355263552735528355293553035531355323553335534355353553635537355383553935540355413554235543355443554535546355473554835549355503555135552355533555435555355563555735558355593556035561355623556335564355653556635567355683556935570355713557235573355743557535576355773557835579355803558135582355833558435585355863558735588355893559035591355923559335594355953559635597355983559935600356013560235603356043560535606356073560835609356103561135612356133561435615356163561735618356193562035621356223562335624356253562635627356283562935630356313563235633356343563535636356373563835639356403564135642356433564435645356463564735648356493565035651356523565335654356553565635657356583565935660356613566235663356643566535666356673566835669356703567135672356733567435675356763567735678356793568035681356823568335684356853568635687356883568935690356913569235693356943569535696356973569835699357003570135702357033570435705357063570735708357093571035711357123571335714357153571635717357183571935720357213572235723357243572535726357273572835729357303573135732357333573435735357363573735738357393574035741357423574335744357453574635747357483574935750357513575235753357543575535756357573575835759357603576135762357633576435765357663576735768357693577035771357723577335774357753577635777357783577935780357813578235783357843578535786357873578835789357903579135792357933579435795357963579735798357993580035801358023580335804358053580635807358083580935810358113581235813358143581535816358173581835819358203582135822358233582435825358263582735828358293583035831358323583335834358353583635837358383583935840358413584235843358443584535846358473584835849358503585135852358533585435855358563585735858358593586035861358623586335864358653586635867358683586935870358713587235873358743587535876358773587835879358803588135882358833588435885358863588735888358893589035891358923589335894358953589635897358983589935900359013590235903359043590535906359073590835909359103591135912359133591435915359163591735918359193592035921359223592335924359253592635927359283592935930359313593235933359343593535936359373593835939359403594135942359433594435945359463594735948359493595035951359523595335954359553595635957359583595935960359613596235963359643596535966359673596835969359703597135972359733597435975359763597735978359793598035981359823598335984359853598635987359883598935990359913599235993359943599535996359973599835999360003600136002360033600436005360063600736008360093601036011360123601336014360153601636017360183601936020360213602236023360243602536026360273602836029360303603136032360333603436035360363603736038360393604036041360423604336044360453604636047360483604936050360513605236053360543605536056360573605836059360603606136062360633606436065360663606736068360693607036071360723607336074360753607636077360783607936080360813608236083360843608536086360873608836089360903609136092360933609436095360963609736098360993610036101361023610336104361053610636107361083610936110361113611236113361143611536116361173611836119361203612136122361233612436125361263612736128361293613036131361323613336134361353613636137361383613936140361413614236143361443614536146361473614836149361503615136152361533615436155361563615736158361593616036161361623616336164361653616636167361683616936170361713617236173361743617536176361773617836179361803618136182361833618436185361863618736188361893619036191361923619336194361953619636197361983619936200362013620236203362043620536206362073620836209362103621136212362133621436215362163621736218362193622036221362223622336224362253622636227362283622936230362313623236233362343623536236362373623836239362403624136242362433624436245362463624736248362493625036251362523625336254362553625636257362583625936260362613626236263362643626536266362673626836269362703627136272362733627436275362763627736278362793628036281362823628336284362853628636287362883628936290362913629236293362943629536296362973629836299363003630136302363033630436305363063630736308363093631036311363123631336314363153631636317363183631936320363213632236323363243632536326363273632836329363303633136332363333633436335363363633736338363393634036341363423634336344363453634636347363483634936350363513635236353363543635536356363573635836359363603636136362363633636436365363663636736368363693637036371363723637336374363753637636377363783637936380363813638236383363843638536386363873638836389363903639136392363933639436395363963639736398363993640036401364023640336404364053640636407364083640936410364113641236413364143641536416364173641836419364203642136422364233642436425364263642736428364293643036431364323643336434364353643636437364383643936440364413644236443364443644536446364473644836449364503645136452364533645436455364563645736458364593646036461364623646336464364653646636467364683646936470364713647236473364743647536476364773647836479364803648136482364833648436485364863648736488364893649036491364923649336494364953649636497364983649936500365013650236503365043650536506365073650836509365103651136512365133651436515365163651736518365193652036521365223652336524365253652636527365283652936530365313653236533365343653536536365373653836539365403654136542365433654436545365463654736548365493655036551365523655336554365553655636557365583655936560365613656236563365643656536566365673656836569365703657136572365733657436575365763657736578365793658036581365823658336584365853658636587365883658936590365913659236593365943659536596365973659836599366003660136602366033660436605366063660736608366093661036611366123661336614366153661636617366183661936620366213662236623366243662536626366273662836629366303663136632366333663436635366363663736638366393664036641366423664336644366453664636647366483664936650366513665236653366543665536656366573665836659366603666136662366633666436665366663666736668366693667036671366723667336674366753667636677366783667936680366813668236683366843668536686366873668836689366903669136692366933669436695366963669736698366993670036701367023670336704367053670636707367083670936710367113671236713367143671536716367173671836719367203672136722367233672436725367263672736728367293673036731367323673336734367353673636737367383673936740367413674236743367443674536746367473674836749367503675136752367533675436755367563675736758367593676036761367623676336764367653676636767367683676936770367713677236773367743677536776367773677836779367803678136782367833678436785367863678736788367893679036791367923679336794367953679636797367983679936800368013680236803368043680536806368073680836809368103681136812368133681436815368163681736818368193682036821368223682336824368253682636827368283682936830368313683236833368343683536836368373683836839368403684136842368433684436845368463684736848368493685036851368523685336854368553685636857368583685936860368613686236863368643686536866368673686836869368703687136872368733687436875368763687736878368793688036881368823688336884368853688636887368883688936890368913689236893368943689536896368973689836899369003690136902369033690436905369063690736908369093691036911369123691336914369153691636917369183691936920369213692236923369243692536926369273692836929369303693136932369333693436935369363693736938369393694036941369423694336944369453694636947369483694936950369513695236953369543695536956369573695836959369603696136962369633696436965369663696736968369693697036971369723697336974369753697636977369783697936980369813698236983369843698536986369873698836989369903699136992369933699436995369963699736998369993700037001370023700337004370053700637007370083700937010370113701237013370143701537016370173701837019370203702137022370233702437025370263702737028370293703037031370323703337034370353703637037370383703937040370413704237043370443704537046370473704837049370503705137052370533705437055370563705737058370593706037061370623706337064370653706637067370683706937070370713707237073370743707537076370773707837079370803708137082370833708437085370863708737088370893709037091370923709337094370953709637097370983709937100371013710237103371043710537106371073710837109371103711137112371133711437115371163711737118371193712037121371223712337124371253712637127371283712937130371313713237133371343713537136371373713837139371403714137142371433714437145371463714737148371493715037151371523715337154371553715637157371583715937160371613716237163371643716537166371673716837169371703717137172371733717437175371763717737178371793718037181371823718337184371853718637187371883718937190371913719237193371943719537196371973719837199372003720137202372033720437205372063720737208372093721037211372123721337214372153721637217372183721937220372213722237223372243722537226372273722837229372303723137232372333723437235372363723737238372393724037241372423724337244372453724637247372483724937250372513725237253372543725537256372573725837259372603726137262372633726437265372663726737268372693727037271372723727337274372753727637277372783727937280372813728237283372843728537286372873728837289372903729137292372933729437295372963729737298372993730037301373023730337304373053730637307373083730937310373113731237313373143731537316373173731837319373203732137322373233732437325373263732737328373293733037331373323733337334373353733637337373383733937340373413734237343373443734537346373473734837349373503735137352373533735437355373563735737358373593736037361373623736337364373653736637367373683736937370373713737237373373743737537376373773737837379373803738137382373833738437385373863738737388373893739037391373923739337394373953739637397373983739937400374013740237403374043740537406374073740837409374103741137412374133741437415374163741737418374193742037421374223742337424374253742637427374283742937430374313743237433374343743537436374373743837439374403744137442374433744437445374463744737448374493745037451374523745337454374553745637457374583745937460374613746237463374643746537466374673746837469374703747137472374733747437475374763747737478374793748037481374823748337484374853748637487374883748937490374913749237493374943749537496374973749837499375003750137502375033750437505375063750737508375093751037511375123751337514375153751637517375183751937520375213752237523375243752537526375273752837529375303753137532375333753437535375363753737538375393754037541375423754337544375453754637547375483754937550375513755237553375543755537556375573755837559375603756137562375633756437565375663756737568375693757037571375723757337574375753757637577375783757937580375813758237583375843758537586375873758837589375903759137592375933759437595375963759737598375993760037601376023760337604376053760637607376083760937610376113761237613376143761537616376173761837619376203762137622376233762437625376263762737628376293763037631376323763337634376353763637637376383763937640376413764237643376443764537646376473764837649376503765137652376533765437655376563765737658376593766037661376623766337664376653766637667376683766937670376713767237673376743767537676376773767837679376803768137682376833768437685376863768737688376893769037691376923769337694376953769637697376983769937700377013770237703377043770537706377073770837709377103771137712377133771437715377163771737718377193772037721377223772337724377253772637727377283772937730377313773237733377343773537736377373773837739377403774137742377433774437745377463774737748377493775037751377523775337754377553775637757377583775937760377613776237763377643776537766377673776837769377703777137772377733777437775377763777737778377793778037781377823778337784377853778637787377883778937790377913779237793377943779537796377973779837799378003780137802378033780437805378063780737808378093781037811378123781337814378153781637817378183781937820378213782237823378243782537826378273782837829378303783137832378333783437835378363783737838378393784037841378423784337844378453784637847378483784937850378513785237853378543785537856378573785837859378603786137862378633786437865378663786737868378693787037871378723787337874378753787637877378783787937880378813788237883378843788537886378873788837889378903789137892378933789437895378963789737898378993790037901379023790337904379053790637907379083790937910379113791237913379143791537916379173791837919379203792137922379233792437925379263792737928379293793037931379323793337934379353793637937379383793937940379413794237943379443794537946379473794837949379503795137952379533795437955379563795737958379593796037961379623796337964379653796637967379683796937970379713797237973379743797537976379773797837979379803798137982379833798437985379863798737988379893799037991379923799337994379953799637997379983799938000380013800238003380043800538006380073800838009380103801138012380133801438015380163801738018380193802038021380223802338024380253802638027380283802938030380313803238033380343803538036380373803838039380403804138042380433804438045380463804738048380493805038051380523805338054380553805638057380583805938060380613806238063380643806538066380673806838069380703807138072380733807438075380763807738078380793808038081380823808338084380853808638087380883808938090380913809238093380943809538096380973809838099381003810138102381033810438105381063810738108381093811038111381123811338114381153811638117381183811938120381213812238123381243812538126381273812838129381303813138132381333813438135381363813738138381393814038141381423814338144381453814638147381483814938150381513815238153381543815538156381573815838159381603816138162381633816438165381663816738168381693817038171381723817338174381753817638177381783817938180381813818238183381843818538186381873818838189381903819138192381933819438195381963819738198381993820038201382023820338204382053820638207382083820938210382113821238213382143821538216382173821838219382203822138222382233822438225382263822738228382293823038231382323823338234382353823638237382383823938240382413824238243382443824538246382473824838249382503825138252382533825438255382563825738258382593826038261382623826338264382653826638267382683826938270382713827238273382743827538276382773827838279382803828138282382833828438285382863828738288382893829038291382923829338294382953829638297382983829938300383013830238303383043830538306383073830838309383103831138312383133831438315383163831738318383193832038321383223832338324383253832638327383283832938330383313833238333383343833538336383373833838339383403834138342383433834438345383463834738348383493835038351383523835338354383553835638357383583835938360383613836238363383643836538366383673836838369383703837138372383733837438375383763837738378383793838038381383823838338384383853838638387383883838938390383913839238393383943839538396383973839838399384003840138402384033840438405384063840738408384093841038411384123841338414384153841638417384183841938420384213842238423384243842538426384273842838429384303843138432384333843438435384363843738438384393844038441384423844338444384453844638447384483844938450384513845238453384543845538456384573845838459384603846138462384633846438465384663846738468384693847038471384723847338474384753847638477384783847938480384813848238483384843848538486384873848838489384903849138492384933849438495384963849738498384993850038501385023850338504385053850638507385083850938510385113851238513385143851538516385173851838519385203852138522385233852438525385263852738528385293853038531385323853338534385353853638537385383853938540385413854238543385443854538546385473854838549385503855138552385533855438555385563855738558385593856038561385623856338564385653856638567385683856938570385713857238573385743857538576385773857838579385803858138582385833858438585385863858738588385893859038591385923859338594385953859638597385983859938600386013860238603386043860538606386073860838609386103861138612386133861438615386163861738618386193862038621386223862338624386253862638627386283862938630386313863238633386343863538636386373863838639386403864138642386433864438645386463864738648386493865038651386523865338654386553865638657386583865938660386613866238663386643866538666386673866838669386703867138672386733867438675386763867738678386793868038681386823868338684386853868638687386883868938690386913869238693386943869538696386973869838699387003870138702387033870438705387063870738708387093871038711387123871338714387153871638717387183871938720387213872238723387243872538726387273872838729387303873138732387333873438735387363873738738387393874038741387423874338744387453874638747387483874938750387513875238753387543875538756387573875838759387603876138762387633876438765387663876738768387693877038771387723877338774387753877638777387783877938780387813878238783387843878538786387873878838789387903879138792387933879438795387963879738798387993880038801388023880338804388053880638807388083880938810388113881238813388143881538816388173881838819388203882138822388233882438825388263882738828388293883038831388323883338834388353883638837388383883938840388413884238843388443884538846388473884838849388503885138852388533885438855388563885738858388593886038861388623886338864388653886638867388683886938870388713887238873388743887538876388773887838879388803888138882388833888438885388863888738888388893889038891388923889338894388953889638897388983889938900389013890238903389043890538906389073890838909389103891138912389133891438915389163891738918389193892038921389223892338924389253892638927389283892938930389313893238933389343893538936389373893838939389403894138942389433894438945389463894738948389493895038951389523895338954389553895638957389583895938960389613896238963389643896538966389673896838969389703897138972389733897438975389763897738978389793898038981389823898338984389853898638987389883898938990389913899238993389943899538996389973899838999390003900139002390033900439005390063900739008390093901039011390123901339014390153901639017390183901939020390213902239023390243902539026390273902839029390303903139032390333903439035390363903739038390393904039041390423904339044390453904639047390483904939050390513905239053390543905539056390573905839059390603906139062390633906439065390663906739068390693907039071390723907339074390753907639077390783907939080390813908239083390843908539086390873908839089390903909139092390933909439095390963909739098390993910039101391023910339104391053910639107391083910939110391113911239113391143911539116391173911839119391203912139122391233912439125391263912739128391293913039131391323913339134391353913639137391383913939140391413914239143391443914539146391473914839149391503915139152391533915439155391563915739158391593916039161391623916339164391653916639167391683916939170391713917239173391743917539176391773917839179391803918139182391833918439185391863918739188391893919039191391923919339194391953919639197391983919939200392013920239203392043920539206392073920839209392103921139212392133921439215392163921739218392193922039221392223922339224392253922639227392283922939230392313923239233392343923539236392373923839239392403924139242392433924439245392463924739248392493925039251392523925339254392553925639257392583925939260392613926239263392643926539266392673926839269392703927139272392733927439275392763927739278392793928039281392823928339284392853928639287392883928939290392913929239293392943929539296392973929839299393003930139302393033930439305393063930739308393093931039311393123931339314393153931639317393183931939320393213932239323393243932539326393273932839329393303933139332393333933439335393363933739338393393934039341393423934339344393453934639347393483934939350393513935239353393543935539356393573935839359393603936139362393633936439365393663936739368393693937039371393723937339374393753937639377393783937939380393813938239383393843938539386393873938839389393903939139392393933939439395393963939739398393993940039401394023940339404394053940639407394083940939410394113941239413394143941539416394173941839419394203942139422394233942439425394263942739428394293943039431394323943339434394353943639437394383943939440394413944239443394443944539446394473944839449394503945139452394533945439455394563945739458394593946039461394623946339464394653946639467394683946939470394713947239473394743947539476394773947839479394803948139482394833948439485394863948739488394893949039491394923949339494394953949639497394983949939500395013950239503395043950539506395073950839509395103951139512395133951439515395163951739518395193952039521395223952339524395253952639527395283952939530395313953239533395343953539536395373953839539395403954139542395433954439545395463954739548395493955039551395523955339554395553955639557395583955939560395613956239563395643956539566395673956839569395703957139572395733957439575395763957739578395793958039581395823958339584395853958639587395883958939590395913959239593395943959539596395973959839599396003960139602396033960439605396063960739608396093961039611396123961339614396153961639617396183961939620396213962239623396243962539626396273962839629396303963139632396333963439635396363963739638396393964039641396423964339644396453964639647396483964939650396513965239653396543965539656396573965839659396603966139662396633966439665396663966739668396693967039671396723967339674396753967639677396783967939680396813968239683396843968539686396873968839689396903969139692396933969439695396963969739698396993970039701397023970339704397053970639707397083970939710397113971239713397143971539716397173971839719397203972139722397233972439725397263972739728397293973039731397323973339734397353973639737397383973939740397413974239743397443974539746397473974839749397503975139752397533975439755397563975739758397593976039761397623976339764397653976639767397683976939770397713977239773397743977539776397773977839779397803978139782397833978439785397863978739788397893979039791397923979339794397953979639797397983979939800398013980239803398043980539806398073980839809398103981139812398133981439815398163981739818398193982039821398223982339824398253982639827398283982939830398313983239833398343983539836398373983839839398403984139842398433984439845398463984739848398493985039851398523985339854398553985639857398583985939860398613986239863398643986539866398673986839869398703987139872398733987439875398763987739878398793988039881398823988339884398853988639887398883988939890398913989239893398943989539896398973989839899399003990139902399033990439905399063990739908399093991039911399123991339914399153991639917399183991939920399213992239923399243992539926399273992839929399303993139932399333993439935399363993739938399393994039941399423994339944399453994639947399483994939950399513995239953399543995539956399573995839959399603996139962399633996439965399663996739968399693997039971399723997339974399753997639977399783997939980399813998239983399843998539986399873998839989399903999139992399933999439995399963999739998399994000040001400024000340004400054000640007400084000940010400114001240013400144001540016400174001840019400204002140022400234002440025400264002740028400294003040031400324003340034400354003640037400384003940040400414004240043400444004540046400474004840049400504005140052400534005440055400564005740058400594006040061400624006340064400654006640067400684006940070400714007240073400744007540076400774007840079400804008140082400834008440085400864008740088400894009040091400924009340094400954009640097400984009940100401014010240103401044010540106401074010840109401104011140112401134011440115401164011740118401194012040121401224012340124401254012640127401284012940130401314013240133401344013540136401374013840139401404014140142401434014440145401464014740148401494015040151401524015340154401554015640157401584015940160401614016240163401644016540166401674016840169401704017140172401734017440175401764017740178401794018040181401824018340184401854018640187401884018940190401914019240193401944019540196401974019840199402004020140202402034020440205402064020740208402094021040211402124021340214402154021640217402184021940220402214022240223402244022540226402274022840229402304023140232402334023440235402364023740238402394024040241402424024340244402454024640247402484024940250402514025240253402544025540256402574025840259402604026140262402634026440265402664026740268402694027040271402724027340274402754027640277402784027940280402814028240283402844028540286402874028840289402904029140292402934029440295402964029740298402994030040301403024030340304403054030640307403084030940310403114031240313403144031540316403174031840319403204032140322403234032440325403264032740328403294033040331403324033340334403354033640337403384033940340403414034240343403444034540346403474034840349403504035140352403534035440355403564035740358403594036040361403624036340364403654036640367403684036940370403714037240373403744037540376403774037840379403804038140382403834038440385403864038740388403894039040391403924039340394403954039640397403984039940400404014040240403404044040540406404074040840409404104041140412404134041440415404164041740418404194042040421404224042340424404254042640427404284042940430404314043240433404344043540436404374043840439404404044140442404434044440445404464044740448404494045040451404524045340454404554045640457404584045940460404614046240463404644046540466404674046840469404704047140472404734047440475404764047740478404794048040481404824048340484404854048640487404884048940490404914049240493404944049540496404974049840499405004050140502405034050440505405064050740508405094051040511405124051340514405154051640517405184051940520405214052240523405244052540526405274052840529405304053140532405334053440535405364053740538405394054040541405424054340544405454054640547405484054940550405514055240553405544055540556405574055840559405604056140562405634056440565405664056740568405694057040571405724057340574405754057640577405784057940580405814058240583405844058540586405874058840589405904059140592405934059440595405964059740598405994060040601406024060340604406054060640607406084060940610406114061240613406144061540616406174061840619406204062140622406234062440625406264062740628406294063040631406324063340634406354063640637406384063940640406414064240643406444064540646406474064840649406504065140652406534065440655406564065740658406594066040661406624066340664406654066640667406684066940670406714067240673406744067540676406774067840679406804068140682406834068440685406864068740688406894069040691406924069340694406954069640697406984069940700407014070240703407044070540706407074070840709407104071140712407134071440715407164071740718407194072040721407224072340724407254072640727407284072940730407314073240733407344073540736407374073840739407404074140742407434074440745407464074740748407494075040751407524075340754407554075640757407584075940760407614076240763407644076540766407674076840769407704077140772407734077440775407764077740778407794078040781407824078340784407854078640787407884078940790407914079240793407944079540796407974079840799408004080140802408034080440805408064080740808408094081040811408124081340814408154081640817408184081940820408214082240823408244082540826408274082840829408304083140832408334083440835408364083740838408394084040841408424084340844408454084640847408484084940850408514085240853408544085540856408574085840859408604086140862408634086440865408664086740868408694087040871408724087340874408754087640877408784087940880408814088240883408844088540886408874088840889408904089140892408934089440895408964089740898408994090040901409024090340904409054090640907409084090940910409114091240913409144091540916409174091840919409204092140922409234092440925409264092740928409294093040931409324093340934409354093640937409384093940940409414094240943409444094540946409474094840949409504095140952409534095440955409564095740958409594096040961409624096340964409654096640967409684096940970409714097240973409744097540976409774097840979409804098140982409834098440985409864098740988409894099040991409924099340994409954099640997409984099941000410014100241003410044100541006410074100841009410104101141012410134101441015410164101741018410194102041021410224102341024410254102641027410284102941030410314103241033410344103541036410374103841039410404104141042410434104441045410464104741048410494105041051410524105341054410554105641057410584105941060410614106241063410644106541066410674106841069410704107141072410734107441075410764107741078410794108041081410824108341084410854108641087410884108941090410914109241093410944109541096410974109841099411004110141102411034110441105411064110741108411094111041111411124111341114411154111641117411184111941120411214112241123411244112541126411274112841129411304113141132411334113441135411364113741138411394114041141411424114341144411454114641147411484114941150411514115241153411544115541156411574115841159411604116141162411634116441165411664116741168411694117041171411724117341174411754117641177411784117941180411814118241183411844118541186411874118841189411904119141192411934119441195411964119741198411994120041201412024120341204412054120641207412084120941210412114121241213412144121541216412174121841219412204122141222412234122441225412264122741228412294123041231412324123341234412354123641237412384123941240412414124241243412444124541246412474124841249412504125141252412534125441255412564125741258412594126041261412624126341264412654126641267412684126941270412714127241273412744127541276412774127841279412804128141282412834128441285412864128741288412894129041291412924129341294412954129641297412984129941300413014130241303413044130541306413074130841309413104131141312413134131441315413164131741318413194132041321413224132341324413254132641327413284132941330413314133241333413344133541336413374133841339413404134141342413434134441345413464134741348413494135041351413524135341354413554135641357413584135941360413614136241363413644136541366413674136841369413704137141372413734137441375413764137741378413794138041381413824138341384413854138641387413884138941390413914139241393413944139541396413974139841399414004140141402414034140441405414064140741408414094141041411414124141341414414154141641417414184141941420414214142241423414244142541426414274142841429414304143141432414334143441435414364143741438414394144041441414424144341444414454144641447414484144941450414514145241453414544145541456414574145841459414604146141462414634146441465414664146741468414694147041471414724147341474414754147641477414784147941480414814148241483414844148541486414874148841489414904149141492414934149441495414964149741498414994150041501415024150341504415054150641507415084150941510415114151241513415144151541516415174151841519415204152141522415234152441525415264152741528415294153041531415324153341534415354153641537415384153941540415414154241543415444154541546415474154841549415504155141552415534155441555415564155741558415594156041561415624156341564415654156641567415684156941570415714157241573415744157541576415774157841579415804158141582415834158441585415864158741588415894159041591415924159341594415954159641597415984159941600416014160241603416044160541606416074160841609416104161141612416134161441615416164161741618416194162041621416224162341624416254162641627416284162941630416314163241633416344163541636416374163841639416404164141642416434164441645416464164741648416494165041651416524165341654416554165641657416584165941660416614166241663416644166541666416674166841669416704167141672416734167441675416764167741678416794168041681416824168341684416854168641687416884168941690416914169241693416944169541696416974169841699417004170141702417034170441705417064170741708417094171041711417124171341714417154171641717417184171941720417214172241723417244172541726417274172841729417304173141732417334173441735417364173741738417394174041741417424174341744417454174641747417484174941750417514175241753417544175541756417574175841759417604176141762417634176441765417664176741768417694177041771417724177341774417754177641777417784177941780417814178241783417844178541786417874178841789417904179141792417934179441795417964179741798417994180041801418024180341804418054180641807418084180941810418114181241813418144181541816418174181841819418204182141822418234182441825418264182741828418294183041831418324183341834418354183641837418384183941840418414184241843418444184541846418474184841849418504185141852418534185441855418564185741858418594186041861418624186341864418654186641867418684186941870418714187241873418744187541876418774187841879418804188141882418834188441885418864188741888418894189041891418924189341894418954189641897418984189941900419014190241903419044190541906419074190841909419104191141912419134191441915419164191741918419194192041921419224192341924419254192641927419284192941930419314193241933419344193541936419374193841939419404194141942419434194441945419464194741948419494195041951419524195341954419554195641957419584195941960419614196241963419644196541966419674196841969419704197141972419734197441975419764197741978419794198041981419824198341984419854198641987419884198941990419914199241993419944199541996419974199841999420004200142002420034200442005420064200742008420094201042011420124201342014420154201642017420184201942020420214202242023420244202542026420274202842029420304203142032420334203442035420364203742038420394204042041420424204342044420454204642047420484204942050420514205242053420544205542056420574205842059420604206142062420634206442065420664206742068420694207042071420724207342074420754207642077420784207942080420814208242083420844208542086420874208842089420904209142092420934209442095420964209742098420994210042101421024210342104421054210642107421084210942110421114211242113421144211542116421174211842119421204212142122421234212442125421264212742128421294213042131421324213342134421354213642137421384213942140421414214242143421444214542146421474214842149421504215142152421534215442155421564215742158421594216042161421624216342164421654216642167421684216942170421714217242173421744217542176421774217842179421804218142182421834218442185421864218742188421894219042191421924219342194421954219642197421984219942200422014220242203422044220542206422074220842209422104221142212422134221442215422164221742218422194222042221422224222342224422254222642227422284222942230422314223242233422344223542236422374223842239422404224142242422434224442245422464224742248422494225042251422524225342254422554225642257422584225942260422614226242263422644226542266422674226842269422704227142272422734227442275422764227742278422794228042281422824228342284422854228642287422884228942290422914229242293422944229542296422974229842299423004230142302423034230442305423064230742308423094231042311423124231342314423154231642317423184231942320423214232242323423244232542326423274232842329423304233142332423334233442335423364233742338423394234042341423424234342344423454234642347423484234942350423514235242353423544235542356423574235842359423604236142362423634236442365423664236742368423694237042371423724237342374423754237642377423784237942380423814238242383423844238542386423874238842389423904239142392423934239442395423964239742398423994240042401424024240342404424054240642407424084240942410424114241242413424144241542416424174241842419424204242142422424234242442425424264242742428424294243042431424324243342434424354243642437424384243942440424414244242443424444244542446424474244842449424504245142452424534245442455424564245742458424594246042461424624246342464424654246642467424684246942470424714247242473424744247542476424774247842479424804248142482424834248442485424864248742488424894249042491424924249342494424954249642497424984249942500425014250242503425044250542506425074250842509425104251142512425134251442515425164251742518425194252042521425224252342524425254252642527425284252942530425314253242533425344253542536425374253842539425404254142542425434254442545425464254742548425494255042551425524255342554425554255642557425584255942560425614256242563425644256542566425674256842569425704257142572425734257442575425764257742578425794258042581425824258342584425854258642587425884258942590425914259242593425944259542596425974259842599426004260142602426034260442605426064260742608426094261042611426124261342614426154261642617426184261942620426214262242623426244262542626426274262842629426304263142632426334263442635426364263742638426394264042641426424264342644426454264642647426484264942650426514265242653426544265542656426574265842659426604266142662426634266442665426664266742668426694267042671426724267342674426754267642677426784267942680426814268242683426844268542686426874268842689426904269142692426934269442695426964269742698426994270042701427024270342704427054270642707427084270942710427114271242713427144271542716427174271842719427204272142722427234272442725427264272742728427294273042731427324273342734427354273642737427384273942740427414274242743427444274542746427474274842749427504275142752427534275442755427564275742758427594276042761427624276342764427654276642767427684276942770427714277242773427744277542776427774277842779427804278142782427834278442785427864278742788427894279042791427924279342794427954279642797427984279942800428014280242803428044280542806428074280842809428104281142812428134281442815428164281742818428194282042821428224282342824428254282642827428284282942830428314283242833428344283542836428374283842839428404284142842428434284442845428464284742848428494285042851428524285342854428554285642857428584285942860428614286242863428644286542866428674286842869428704287142872428734287442875428764287742878428794288042881428824288342884428854288642887428884288942890428914289242893428944289542896428974289842899429004290142902429034290442905429064290742908429094291042911429124291342914429154291642917429184291942920429214292242923429244292542926429274292842929429304293142932429334293442935429364293742938429394294042941429424294342944429454294642947429484294942950429514295242953429544295542956429574295842959429604296142962429634296442965429664296742968429694297042971429724297342974429754297642977429784297942980429814298242983429844298542986429874298842989429904299142992429934299442995429964299742998429994300043001430024300343004430054300643007430084300943010430114301243013430144301543016430174301843019430204302143022430234302443025430264302743028430294303043031430324303343034430354303643037430384303943040430414304243043430444304543046430474304843049430504305143052430534305443055430564305743058430594306043061430624306343064430654306643067430684306943070430714307243073430744307543076430774307843079430804308143082430834308443085430864308743088430894309043091430924309343094430954309643097430984309943100431014310243103431044310543106431074310843109431104311143112431134311443115431164311743118431194312043121431224312343124431254312643127431284312943130431314313243133431344313543136431374313843139431404314143142431434314443145431464314743148431494315043151431524315343154431554315643157431584315943160431614316243163431644316543166431674316843169431704317143172431734317443175431764317743178431794318043181431824318343184431854318643187431884318943190431914319243193431944319543196431974319843199432004320143202432034320443205432064320743208432094321043211432124321343214432154321643217432184321943220432214322243223432244322543226432274322843229432304323143232432334323443235432364323743238432394324043241432424324343244432454324643247432484324943250432514325243253432544325543256432574325843259432604326143262432634326443265432664326743268432694327043271432724327343274432754327643277432784327943280432814328243283432844328543286432874328843289432904329143292432934329443295432964329743298432994330043301433024330343304433054330643307433084330943310433114331243313433144331543316433174331843319433204332143322433234332443325433264332743328433294333043331433324333343334433354333643337433384333943340433414334243343433444334543346433474334843349433504335143352433534335443355433564335743358433594336043361433624336343364433654336643367433684336943370433714337243373433744337543376433774337843379433804338143382433834338443385433864338743388433894339043391433924339343394433954339643397433984339943400434014340243403434044340543406434074340843409434104341143412434134341443415434164341743418434194342043421434224342343424434254342643427434284342943430434314343243433434344343543436434374343843439434404344143442434434344443445434464344743448434494345043451434524345343454434554345643457434584345943460434614346243463434644346543466434674346843469434704347143472434734347443475434764347743478434794348043481434824348343484434854348643487434884348943490434914349243493434944349543496434974349843499435004350143502435034350443505435064350743508435094351043511435124351343514435154351643517435184351943520435214352243523435244352543526435274352843529435304353143532435334353443535435364353743538435394354043541435424354343544435454354643547435484354943550435514355243553435544355543556435574355843559435604356143562435634356443565435664356743568435694357043571435724357343574435754357643577435784357943580435814358243583435844358543586435874358843589435904359143592435934359443595435964359743598435994360043601436024360343604436054360643607436084360943610436114361243613436144361543616436174361843619436204362143622436234362443625436264362743628436294363043631436324363343634436354363643637436384363943640436414364243643436444364543646436474364843649436504365143652436534365443655436564365743658436594366043661436624366343664436654366643667436684366943670436714367243673436744367543676436774367843679436804368143682436834368443685436864368743688436894369043691436924369343694436954369643697436984369943700437014370243703437044370543706437074370843709437104371143712437134371443715437164371743718437194372043721437224372343724437254372643727437284372943730437314373243733437344373543736437374373843739437404374143742437434374443745437464374743748437494375043751437524375343754437554375643757437584375943760437614376243763437644376543766437674376843769437704377143772437734377443775437764377743778437794378043781437824378343784437854378643787437884378943790437914379243793437944379543796437974379843799438004380143802438034380443805438064380743808438094381043811438124381343814438154381643817438184381943820438214382243823438244382543826438274382843829438304383143832438334383443835438364383743838438394384043841438424384343844438454384643847438484384943850438514385243853438544385543856438574385843859438604386143862438634386443865438664386743868438694387043871438724387343874438754387643877438784387943880438814388243883438844388543886438874388843889438904389143892438934389443895438964389743898438994390043901439024390343904439054390643907439084390943910439114391243913439144391543916439174391843919439204392143922439234392443925439264392743928439294393043931439324393343934439354393643937439384393943940439414394243943439444394543946439474394843949439504395143952439534395443955439564395743958439594396043961439624396343964439654396643967439684396943970439714397243973439744397543976439774397843979439804398143982439834398443985439864398743988439894399043991439924399343994439954399643997439984399944000440014400244003440044400544006440074400844009440104401144012440134401444015440164401744018440194402044021440224402344024440254402644027440284402944030440314403244033440344403544036440374403844039440404404144042440434404444045440464404744048440494405044051440524405344054440554405644057440584405944060440614406244063440644406544066440674406844069440704407144072440734407444075440764407744078440794408044081440824408344084440854408644087440884408944090440914409244093440944409544096440974409844099441004410144102441034410444105441064410744108441094411044111441124411344114441154411644117441184411944120441214412244123441244412544126441274412844129441304413144132441334413444135441364413744138441394414044141441424414344144441454414644147441484414944150441514415244153441544415544156441574415844159441604416144162441634416444165441664416744168441694417044171441724417344174441754417644177441784417944180441814418244183441844418544186441874418844189441904419144192441934419444195441964419744198441994420044201442024420344204442054420644207442084420944210442114421244213442144421544216442174421844219442204422144222442234422444225442264422744228442294423044231442324423344234442354423644237442384423944240442414424244243442444424544246442474424844249442504425144252442534425444255442564425744258442594426044261442624426344264442654426644267442684426944270442714427244273442744427544276442774427844279442804428144282442834428444285442864428744288442894429044291442924429344294442954429644297442984429944300443014430244303443044430544306443074430844309443104431144312443134431444315443164431744318443194432044321443224432344324443254432644327443284432944330443314433244333443344433544336443374433844339443404434144342443434434444345443464434744348443494435044351443524435344354443554435644357443584435944360443614436244363443644436544366443674436844369443704437144372443734437444375443764437744378443794438044381443824438344384443854438644387443884438944390443914439244393443944439544396443974439844399444004440144402444034440444405444064440744408444094441044411444124441344414444154441644417444184441944420444214442244423444244442544426444274442844429444304443144432444334443444435444364443744438444394444044441444424444344444444454444644447444484444944450444514445244453444544445544456444574445844459444604446144462444634446444465444664446744468444694447044471444724447344474444754447644477444784447944480444814448244483444844448544486444874448844489444904449144492444934449444495444964449744498444994450044501445024450344504445054450644507445084450944510445114451244513445144451544516445174451844519445204452144522445234452444525445264452744528445294453044531445324453344534445354453644537445384453944540445414454244543445444454544546445474454844549445504455144552445534455444555445564455744558445594456044561445624456344564445654456644567445684456944570445714457244573445744457544576445774457844579445804458144582445834458444585445864458744588445894459044591445924459344594445954459644597445984459944600446014460244603446044460544606446074460844609446104461144612446134461444615446164461744618446194462044621446224462344624446254462644627446284462944630446314463244633446344463544636446374463844639446404464144642446434464444645446464464744648446494465044651446524465344654446554465644657446584465944660446614466244663446644466544666446674466844669446704467144672446734467444675446764467744678446794468044681446824468344684446854468644687446884468944690446914469244693446944469544696446974469844699447004470144702447034470444705447064470744708447094471044711447124471344714447154471644717447184471944720447214472244723447244472544726447274472844729447304473144732447334473444735447364473744738447394474044741447424474344744447454474644747447484474944750447514475244753447544475544756447574475844759447604476144762447634476444765447664476744768447694477044771447724477344774447754477644777447784477944780447814478244783447844478544786447874478844789447904479144792447934479444795447964479744798447994480044801448024480344804448054480644807448084480944810448114481244813448144481544816448174481844819448204482144822448234482444825448264482744828448294483044831448324483344834448354483644837448384483944840448414484244843448444484544846448474484844849448504485144852448534485444855448564485744858448594486044861448624486344864448654486644867448684486944870448714487244873448744487544876448774487844879448804488144882448834488444885448864488744888448894489044891448924489344894448954489644897448984489944900449014490244903449044490544906449074490844909449104491144912449134491444915449164491744918449194492044921449224492344924449254492644927449284492944930449314493244933449344493544936449374493844939449404494144942449434494444945449464494744948449494495044951449524495344954449554495644957449584495944960449614496244963449644496544966449674496844969449704497144972449734497444975449764497744978449794498044981449824498344984449854498644987449884498944990449914499244993449944499544996449974499844999450004500145002450034500445005450064500745008450094501045011450124501345014450154501645017450184501945020450214502245023450244502545026450274502845029450304503145032450334503445035450364503745038450394504045041450424504345044450454504645047450484504945050450514505245053450544505545056450574505845059450604506145062450634506445065450664506745068450694507045071450724507345074450754507645077450784507945080450814508245083450844508545086450874508845089450904509145092450934509445095450964509745098450994510045101451024510345104451054510645107451084510945110451114511245113451144511545116451174511845119451204512145122451234512445125451264512745128451294513045131451324513345134451354513645137451384513945140451414514245143451444514545146451474514845149451504515145152451534515445155451564515745158451594516045161451624516345164451654516645167451684516945170451714517245173451744517545176451774517845179451804518145182451834518445185451864518745188451894519045191451924519345194451954519645197451984519945200452014520245203452044520545206452074520845209452104521145212452134521445215452164521745218452194522045221452224522345224452254522645227452284522945230452314523245233452344523545236452374523845239452404524145242452434524445245452464524745248452494525045251452524525345254452554525645257452584525945260452614526245263452644526545266452674526845269452704527145272452734527445275452764527745278452794528045281452824528345284452854528645287452884528945290452914529245293452944529545296452974529845299453004530145302453034530445305453064530745308453094531045311453124531345314453154531645317453184531945320453214532245323453244532545326453274532845329453304533145332453334533445335453364533745338453394534045341453424534345344453454534645347453484534945350453514535245353453544535545356453574535845359453604536145362453634536445365453664536745368453694537045371453724537345374453754537645377453784537945380453814538245383453844538545386453874538845389453904539145392453934539445395453964539745398453994540045401454024540345404454054540645407454084540945410454114541245413454144541545416454174541845419454204542145422454234542445425454264542745428454294543045431454324543345434454354543645437454384543945440454414544245443454444544545446454474544845449454504545145452454534545445455454564545745458454594546045461454624546345464454654546645467454684546945470454714547245473454744547545476454774547845479454804548145482454834548445485454864548745488454894549045491454924549345494454954549645497454984549945500455014550245503455044550545506455074550845509455104551145512455134551445515455164551745518455194552045521455224552345524455254552645527455284552945530455314553245533455344553545536455374553845539455404554145542455434554445545455464554745548455494555045551455524555345554455554555645557455584555945560455614556245563455644556545566455674556845569455704557145572455734557445575455764557745578455794558045581455824558345584455854558645587455884558945590455914559245593455944559545596455974559845599456004560145602456034560445605456064560745608456094561045611456124561345614456154561645617456184561945620456214562245623456244562545626456274562845629456304563145632456334563445635456364563745638456394564045641456424564345644456454564645647456484564945650456514565245653456544565545656456574565845659456604566145662456634566445665456664566745668456694567045671456724567345674456754567645677456784567945680456814568245683456844568545686456874568845689456904569145692456934569445695456964569745698456994570045701457024570345704457054570645707457084570945710457114571245713457144571545716457174571845719457204572145722457234572445725457264572745728457294573045731457324573345734457354573645737457384573945740457414574245743457444574545746457474574845749457504575145752457534575445755457564575745758457594576045761457624576345764457654576645767457684576945770457714577245773457744577545776457774577845779457804578145782457834578445785457864578745788457894579045791457924579345794457954579645797457984579945800458014580245803458044580545806458074580845809458104581145812458134581445815458164581745818458194582045821458224582345824458254582645827458284582945830458314583245833458344583545836458374583845839458404584145842458434584445845458464584745848458494585045851458524585345854458554585645857458584585945860458614586245863458644586545866458674586845869458704587145872458734587445875458764587745878458794588045881458824588345884458854588645887458884588945890458914589245893458944589545896458974589845899459004590145902459034590445905459064590745908459094591045911459124591345914459154591645917459184591945920459214592245923459244592545926459274592845929459304593145932459334593445935459364593745938459394594045941459424594345944459454594645947459484594945950459514595245953459544595545956459574595845959459604596145962459634596445965459664596745968459694597045971459724597345974459754597645977459784597945980459814598245983459844598545986459874598845989459904599145992459934599445995459964599745998459994600046001460024600346004460054600646007460084600946010460114601246013460144601546016460174601846019460204602146022460234602446025460264602746028460294603046031460324603346034460354603646037460384603946040460414604246043460444604546046460474604846049460504605146052460534605446055460564605746058460594606046061460624606346064460654606646067460684606946070460714607246073460744607546076460774607846079460804608146082460834608446085460864608746088460894609046091460924609346094460954609646097460984609946100461014610246103461044610546106461074610846109461104611146112461134611446115461164611746118461194612046121461224612346124461254612646127461284612946130461314613246133461344613546136461374613846139461404614146142461434614446145461464614746148461494615046151461524615346154461554615646157461584615946160461614616246163461644616546166461674616846169461704617146172461734617446175461764617746178461794618046181461824618346184461854618646187461884618946190461914619246193461944619546196461974619846199462004620146202462034620446205462064620746208462094621046211462124621346214462154621646217462184621946220462214622246223462244622546226462274622846229462304623146232462334623446235462364623746238462394624046241462424624346244462454624646247462484624946250462514625246253462544625546256462574625846259462604626146262462634626446265462664626746268462694627046271462724627346274462754627646277462784627946280462814628246283462844628546286462874628846289462904629146292462934629446295462964629746298462994630046301463024630346304463054630646307463084630946310463114631246313463144631546316463174631846319463204632146322463234632446325463264632746328463294633046331463324633346334463354633646337463384633946340463414634246343463444634546346463474634846349463504635146352463534635446355463564635746358463594636046361463624636346364463654636646367463684636946370463714637246373463744637546376463774637846379463804638146382463834638446385463864638746388463894639046391463924639346394463954639646397463984639946400464014640246403464044640546406464074640846409464104641146412464134641446415464164641746418464194642046421464224642346424464254642646427464284642946430464314643246433464344643546436464374643846439464404644146442464434644446445464464644746448464494645046451464524645346454464554645646457464584645946460464614646246463464644646546466464674646846469464704647146472464734647446475464764647746478464794648046481464824648346484464854648646487464884648946490464914649246493464944649546496464974649846499465004650146502465034650446505465064650746508465094651046511465124651346514465154651646517465184651946520465214652246523465244652546526465274652846529465304653146532465334653446535465364653746538465394654046541465424654346544465454654646547465484654946550465514655246553465544655546556465574655846559465604656146562465634656446565465664656746568465694657046571465724657346574465754657646577465784657946580465814658246583465844658546586465874658846589465904659146592465934659446595465964659746598465994660046601466024660346604466054660646607466084660946610466114661246613466144661546616466174661846619466204662146622466234662446625466264662746628466294663046631466324663346634466354663646637466384663946640466414664246643466444664546646466474664846649466504665146652466534665446655466564665746658466594666046661466624666346664466654666646667466684666946670466714667246673466744667546676466774667846679466804668146682466834668446685466864668746688466894669046691466924669346694466954669646697466984669946700467014670246703467044670546706467074670846709467104671146712467134671446715467164671746718467194672046721467224672346724467254672646727467284672946730467314673246733467344673546736467374673846739467404674146742467434674446745467464674746748467494675046751467524675346754467554675646757467584675946760467614676246763467644676546766467674676846769467704677146772467734677446775467764677746778467794678046781467824678346784467854678646787467884678946790467914679246793467944679546796467974679846799468004680146802468034680446805468064680746808468094681046811468124681346814468154681646817468184681946820468214682246823468244682546826468274682846829468304683146832468334683446835468364683746838468394684046841468424684346844468454684646847468484684946850468514685246853468544685546856468574685846859468604686146862468634686446865468664686746868468694687046871468724687346874468754687646877468784687946880468814688246883468844688546886468874688846889468904689146892468934689446895468964689746898468994690046901469024690346904469054690646907469084690946910469114691246913469144691546916469174691846919469204692146922469234692446925469264692746928469294693046931469324693346934469354693646937469384693946940469414694246943469444694546946469474694846949469504695146952469534695446955469564695746958469594696046961469624696346964469654696646967469684696946970469714697246973469744697546976469774697846979469804698146982469834698446985469864698746988469894699046991469924699346994469954699646997469984699947000470014700247003470044700547006470074700847009470104701147012470134701447015470164701747018470194702047021470224702347024470254702647027470284702947030470314703247033470344703547036470374703847039470404704147042470434704447045470464704747048470494705047051470524705347054470554705647057470584705947060470614706247063470644706547066470674706847069470704707147072470734707447075470764707747078470794708047081470824708347084470854708647087470884708947090470914709247093470944709547096470974709847099471004710147102471034710447105471064710747108471094711047111471124711347114471154711647117471184711947120471214712247123471244712547126471274712847129471304713147132471334713447135471364713747138471394714047141471424714347144471454714647147471484714947150471514715247153471544715547156471574715847159471604716147162471634716447165471664716747168471694717047171471724717347174471754717647177471784717947180471814718247183471844718547186471874718847189471904719147192471934719447195471964719747198471994720047201472024720347204472054720647207472084720947210472114721247213472144721547216472174721847219472204722147222472234722447225472264722747228472294723047231472324723347234472354723647237472384723947240472414724247243472444724547246472474724847249472504725147252472534725447255472564725747258472594726047261472624726347264472654726647267472684726947270472714727247273472744727547276472774727847279472804728147282472834728447285472864728747288472894729047291472924729347294472954729647297472984729947300473014730247303473044730547306473074730847309473104731147312473134731447315473164731747318473194732047321473224732347324473254732647327473284732947330473314733247333473344733547336473374733847339473404734147342473434734447345473464734747348473494735047351473524735347354473554735647357473584735947360473614736247363473644736547366473674736847369473704737147372473734737447375473764737747378473794738047381473824738347384473854738647387473884738947390473914739247393473944739547396473974739847399474004740147402474034740447405474064740747408474094741047411474124741347414474154741647417474184741947420474214742247423474244742547426474274742847429474304743147432474334743447435474364743747438474394744047441474424744347444474454744647447474484744947450474514745247453474544745547456474574745847459474604746147462474634746447465474664746747468474694747047471474724747347474474754747647477474784747947480474814748247483474844748547486474874748847489474904749147492474934749447495474964749747498474994750047501475024750347504475054750647507475084750947510475114751247513475144751547516475174751847519475204752147522475234752447525475264752747528475294753047531475324753347534475354753647537475384753947540475414754247543475444754547546475474754847549475504755147552475534755447555475564755747558475594756047561475624756347564475654756647567475684756947570475714757247573475744757547576475774757847579475804758147582475834758447585475864758747588475894759047591475924759347594475954759647597475984759947600476014760247603476044760547606476074760847609476104761147612476134761447615476164761747618476194762047621476224762347624476254762647627476284762947630476314763247633476344763547636476374763847639476404764147642476434764447645476464764747648476494765047651476524765347654476554765647657476584765947660476614766247663476644766547666476674766847669476704767147672476734767447675476764767747678476794768047681476824768347684476854768647687476884768947690476914769247693476944769547696476974769847699477004770147702477034770447705477064770747708477094771047711477124771347714477154771647717477184771947720477214772247723477244772547726477274772847729477304773147732477334773447735477364773747738477394774047741477424774347744477454774647747477484774947750477514775247753477544775547756477574775847759477604776147762477634776447765477664776747768477694777047771477724777347774477754777647777477784777947780477814778247783477844778547786477874778847789477904779147792477934779447795477964779747798477994780047801478024780347804478054780647807478084780947810478114781247813478144781547816478174781847819478204782147822478234782447825478264782747828478294783047831478324783347834478354783647837478384783947840478414784247843478444784547846478474784847849478504785147852478534785447855478564785747858478594786047861478624786347864478654786647867478684786947870478714787247873478744787547876478774787847879478804788147882478834788447885478864788747888478894789047891478924789347894478954789647897478984789947900479014790247903479044790547906479074790847909479104791147912479134791447915479164791747918479194792047921479224792347924479254792647927479284792947930479314793247933479344793547936479374793847939479404794147942479434794447945479464794747948479494795047951479524795347954479554795647957479584795947960479614796247963479644796547966479674796847969479704797147972479734797447975479764797747978479794798047981479824798347984479854798647987479884798947990479914799247993479944799547996479974799847999480004800148002480034800448005480064800748008480094801048011480124801348014480154801648017480184801948020480214802248023480244802548026480274802848029480304803148032480334803448035480364803748038480394804048041480424804348044480454804648047480484804948050480514805248053480544805548056480574805848059480604806148062480634806448065480664806748068480694807048071480724807348074480754807648077480784807948080480814808248083480844808548086480874808848089480904809148092480934809448095480964809748098480994810048101481024810348104481054810648107481084810948110481114811248113481144811548116481174811848119481204812148122481234812448125481264812748128481294813048131481324813348134481354813648137481384813948140481414814248143481444814548146481474814848149481504815148152481534815448155481564815748158481594816048161481624816348164481654816648167481684816948170481714817248173481744817548176481774817848179481804818148182481834818448185481864818748188481894819048191481924819348194481954819648197481984819948200482014820248203482044820548206482074820848209482104821148212482134821448215482164821748218482194822048221482224822348224482254822648227482284822948230482314823248233482344823548236482374823848239482404824148242482434824448245482464824748248482494825048251482524825348254482554825648257482584825948260482614826248263482644826548266482674826848269482704827148272482734827448275482764827748278482794828048281482824828348284482854828648287482884828948290482914829248293482944829548296482974829848299483004830148302483034830448305483064830748308483094831048311483124831348314483154831648317483184831948320483214832248323483244832548326483274832848329483304833148332483334833448335483364833748338483394834048341483424834348344483454834648347483484834948350483514835248353483544835548356483574835848359483604836148362483634836448365483664836748368483694837048371483724837348374483754837648377483784837948380483814838248383483844838548386483874838848389483904839148392483934839448395483964839748398483994840048401484024840348404484054840648407484084840948410484114841248413484144841548416484174841848419484204842148422484234842448425484264842748428484294843048431484324843348434484354843648437484384843948440484414844248443484444844548446484474844848449484504845148452484534845448455484564845748458484594846048461484624846348464484654846648467484684846948470484714847248473484744847548476484774847848479484804848148482484834848448485484864848748488484894849048491484924849348494484954849648497484984849948500485014850248503485044850548506485074850848509485104851148512485134851448515485164851748518485194852048521485224852348524485254852648527485284852948530485314853248533485344853548536485374853848539485404854148542485434854448545485464854748548485494855048551485524855348554485554855648557485584855948560485614856248563485644856548566485674856848569485704857148572485734857448575485764857748578485794858048581485824858348584485854858648587485884858948590485914859248593485944859548596485974859848599486004860148602486034860448605486064860748608486094861048611486124861348614486154861648617486184861948620486214862248623486244862548626486274862848629486304863148632486334863448635486364863748638486394864048641486424864348644486454864648647486484864948650486514865248653486544865548656486574865848659486604866148662486634866448665486664866748668486694867048671486724867348674486754867648677486784867948680486814868248683486844868548686486874868848689486904869148692486934869448695486964869748698486994870048701487024870348704487054870648707487084870948710487114871248713487144871548716487174871848719487204872148722487234872448725487264872748728487294873048731487324873348734487354873648737487384873948740487414874248743487444874548746487474874848749487504875148752487534875448755487564875748758487594876048761487624876348764487654876648767487684876948770487714877248773487744877548776487774877848779487804878148782487834878448785487864878748788487894879048791487924879348794487954879648797487984879948800488014880248803488044880548806488074880848809488104881148812488134881448815488164881748818488194882048821488224882348824488254882648827488284882948830488314883248833488344883548836488374883848839488404884148842488434884448845488464884748848488494885048851488524885348854488554885648857488584885948860488614886248863488644886548866488674886848869488704887148872488734887448875488764887748878488794888048881488824888348884488854888648887488884888948890488914889248893488944889548896488974889848899489004890148902489034890448905489064890748908489094891048911489124891348914489154891648917489184891948920489214892248923489244892548926489274892848929489304893148932489334893448935489364893748938489394894048941489424894348944489454894648947489484894948950489514895248953489544895548956489574895848959489604896148962489634896448965489664896748968489694897048971489724897348974489754897648977489784897948980489814898248983489844898548986489874898848989489904899148992489934899448995489964899748998489994900049001490024900349004490054900649007490084900949010490114901249013490144901549016490174901849019490204902149022490234902449025490264902749028490294903049031490324903349034490354903649037490384903949040490414904249043490444904549046490474904849049490504905149052490534905449055490564905749058490594906049061490624906349064490654906649067490684906949070490714907249073490744907549076490774907849079490804908149082490834908449085490864908749088490894909049091490924909349094490954909649097490984909949100491014910249103491044910549106491074910849109491104911149112491134911449115491164911749118491194912049121491224912349124491254912649127491284912949130491314913249133491344913549136491374913849139491404914149142491434914449145491464914749148491494915049151491524915349154491554915649157491584915949160491614916249163491644916549166491674916849169491704917149172491734917449175491764917749178491794918049181491824918349184491854918649187491884918949190491914919249193491944919549196491974919849199492004920149202492034920449205492064920749208492094921049211492124921349214492154921649217492184921949220492214922249223492244922549226492274922849229492304923149232492334923449235492364923749238492394924049241492424924349244492454924649247492484924949250492514925249253492544925549256492574925849259492604926149262492634926449265492664926749268492694927049271492724927349274492754927649277492784927949280492814928249283492844928549286492874928849289492904929149292492934929449295492964929749298492994930049301493024930349304493054930649307493084930949310493114931249313493144931549316493174931849319493204932149322493234932449325493264932749328493294933049331493324933349334493354933649337493384933949340493414934249343493444934549346493474934849349493504935149352493534935449355493564935749358493594936049361493624936349364493654936649367493684936949370493714937249373493744937549376493774937849379493804938149382493834938449385493864938749388493894939049391493924939349394493954939649397493984939949400494014940249403494044940549406494074940849409494104941149412494134941449415494164941749418494194942049421494224942349424494254942649427494284942949430494314943249433494344943549436494374943849439494404944149442494434944449445494464944749448494494945049451494524945349454494554945649457494584945949460494614946249463494644946549466494674946849469494704947149472494734947449475494764947749478494794948049481494824948349484494854948649487494884948949490494914949249493494944949549496494974949849499495004950149502495034950449505495064950749508495094951049511495124951349514495154951649517495184951949520495214952249523495244952549526495274952849529495304953149532495334953449535495364953749538495394954049541495424954349544495454954649547495484954949550495514955249553495544955549556495574955849559495604956149562495634956449565495664956749568495694957049571495724957349574495754957649577495784957949580495814958249583495844958549586495874958849589495904959149592495934959449595495964959749598495994960049601496024960349604496054960649607496084960949610496114961249613496144961549616496174961849619496204962149622496234962449625496264962749628496294963049631496324963349634496354963649637496384963949640496414964249643496444964549646496474964849649496504965149652496534965449655496564965749658496594966049661496624966349664496654966649667496684966949670496714967249673496744967549676496774967849679496804968149682496834968449685496864968749688496894969049691496924969349694496954969649697496984969949700497014970249703497044970549706497074970849709497104971149712497134971449715497164971749718497194972049721497224972349724497254972649727497284972949730497314973249733497344973549736497374973849739497404974149742497434974449745497464974749748497494975049751497524975349754497554975649757497584975949760497614976249763497644976549766497674976849769497704977149772497734977449775497764977749778497794978049781497824978349784497854978649787497884978949790497914979249793497944979549796497974979849799498004980149802498034980449805498064980749808498094981049811498124981349814498154981649817498184981949820498214982249823498244982549826498274982849829498304983149832498334983449835498364983749838498394984049841498424984349844498454984649847498484984949850498514985249853498544985549856498574985849859498604986149862498634986449865498664986749868498694987049871498724987349874498754987649877498784987949880498814988249883498844988549886498874988849889498904989149892498934989449895498964989749898498994990049901499024990349904499054990649907499084990949910499114991249913499144991549916499174991849919499204992149922499234992449925499264992749928499294993049931499324993349934499354993649937499384993949940499414994249943499444994549946499474994849949499504995149952499534995449955499564995749958499594996049961499624996349964499654996649967499684996949970499714997249973499744997549976499774997849979499804998149982499834998449985499864998749988499894999049991499924999349994499954999649997499984999950000500015000250003500045000550006500075000850009500105001150012500135001450015500165001750018500195002050021500225002350024500255002650027500285002950030500315003250033500345003550036500375003850039500405004150042500435004450045500465004750048500495005050051500525005350054500555005650057500585005950060500615006250063500645006550066500675006850069500705007150072500735007450075500765007750078500795008050081500825008350084500855008650087500885008950090500915009250093500945009550096500975009850099501005010150102501035010450105501065010750108501095011050111501125011350114501155011650117501185011950120501215012250123501245012550126501275012850129501305013150132501335013450135501365013750138501395014050141501425014350144501455014650147501485014950150501515015250153501545015550156501575015850159501605016150162501635016450165501665016750168501695017050171501725017350174501755017650177501785017950180501815018250183501845018550186501875018850189501905019150192501935019450195501965019750198501995020050201502025020350204502055020650207502085020950210502115021250213502145021550216502175021850219502205022150222502235022450225502265022750228502295023050231502325023350234502355023650237502385023950240502415024250243502445024550246502475024850249502505025150252502535025450255502565025750258502595026050261502625026350264502655026650267502685026950270502715027250273502745027550276502775027850279502805028150282502835028450285502865028750288502895029050291502925029350294502955029650297502985029950300503015030250303503045030550306503075030850309503105031150312503135031450315503165031750318503195032050321503225032350324503255032650327503285032950330503315033250333503345033550336503375033850339503405034150342503435034450345503465034750348503495035050351503525035350354503555035650357503585035950360503615036250363503645036550366503675036850369503705037150372503735037450375503765037750378503795038050381503825038350384503855038650387503885038950390503915039250393503945039550396503975039850399504005040150402504035040450405504065040750408504095041050411504125041350414504155041650417504185041950420504215042250423504245042550426504275042850429504305043150432504335043450435504365043750438504395044050441504425044350444504455044650447504485044950450504515045250453504545045550456504575045850459504605046150462504635046450465504665046750468504695047050471504725047350474504755047650477504785047950480504815048250483504845048550486504875048850489504905049150492504935049450495504965049750498504995050050501505025050350504505055050650507505085050950510505115051250513505145051550516505175051850519505205052150522505235052450525505265052750528505295053050531505325053350534505355053650537505385053950540505415054250543505445054550546505475054850549505505055150552505535055450555505565055750558505595056050561505625056350564505655056650567505685056950570505715057250573505745057550576505775057850579505805058150582505835058450585505865058750588505895059050591505925059350594505955059650597505985059950600506015060250603506045060550606506075060850609506105061150612506135061450615506165061750618506195062050621506225062350624506255062650627506285062950630506315063250633506345063550636506375063850639506405064150642506435064450645506465064750648506495065050651506525065350654506555065650657506585065950660506615066250663506645066550666506675066850669506705067150672506735067450675506765067750678506795068050681506825068350684506855068650687506885068950690506915069250693506945069550696506975069850699507005070150702507035070450705507065070750708507095071050711507125071350714507155071650717507185071950720507215072250723507245072550726507275072850729507305073150732507335073450735507365073750738507395074050741507425074350744507455074650747507485074950750507515075250753507545075550756507575075850759507605076150762507635076450765507665076750768507695077050771507725077350774507755077650777507785077950780507815078250783507845078550786507875078850789507905079150792507935079450795507965079750798507995080050801508025080350804508055080650807508085080950810508115081250813508145081550816508175081850819508205082150822508235082450825508265082750828508295083050831508325083350834508355083650837508385083950840508415084250843508445084550846508475084850849508505085150852508535085450855508565085750858508595086050861508625086350864508655086650867508685086950870508715087250873508745087550876508775087850879508805088150882508835088450885508865088750888508895089050891508925089350894508955089650897508985089950900509015090250903509045090550906509075090850909509105091150912509135091450915509165091750918509195092050921509225092350924509255092650927509285092950930509315093250933509345093550936509375093850939509405094150942509435094450945509465094750948509495095050951509525095350954509555095650957509585095950960509615096250963509645096550966509675096850969509705097150972509735097450975509765097750978509795098050981509825098350984509855098650987509885098950990509915099250993509945099550996509975099850999510005100151002510035100451005510065100751008510095101051011510125101351014510155101651017510185101951020510215102251023510245102551026510275102851029510305103151032510335103451035510365103751038510395104051041510425104351044510455104651047510485104951050510515105251053510545105551056510575105851059510605106151062510635106451065510665106751068510695107051071510725107351074510755107651077510785107951080510815108251083510845108551086510875108851089510905109151092510935109451095510965109751098510995110051101511025110351104511055110651107511085110951110511115111251113511145111551116511175111851119511205112151122511235112451125511265112751128511295113051131511325113351134511355113651137511385113951140511415114251143511445114551146511475114851149511505115151152511535115451155511565115751158511595116051161511625116351164511655116651167511685116951170511715117251173511745117551176511775117851179511805118151182511835118451185511865118751188511895119051191511925119351194511955119651197511985119951200512015120251203512045120551206512075120851209512105121151212512135121451215512165121751218512195122051221512225122351224512255122651227512285122951230512315123251233512345123551236512375123851239512405124151242512435124451245512465124751248512495125051251512525125351254512555125651257512585125951260512615126251263512645126551266512675126851269512705127151272512735127451275512765127751278512795128051281512825128351284512855128651287512885128951290512915129251293512945129551296512975129851299513005130151302513035130451305513065130751308513095131051311513125131351314513155131651317513185131951320513215132251323513245132551326513275132851329513305133151332513335133451335513365133751338513395134051341513425134351344513455134651347513485134951350513515135251353513545135551356513575135851359513605136151362513635136451365513665136751368513695137051371513725137351374513755137651377513785137951380513815138251383513845138551386513875138851389513905139151392513935139451395513965139751398513995140051401514025140351404514055140651407514085140951410514115141251413514145141551416514175141851419514205142151422514235142451425514265142751428514295143051431514325143351434514355143651437514385143951440514415144251443514445144551446514475144851449514505145151452514535145451455514565145751458514595146051461514625146351464514655146651467514685146951470514715147251473514745147551476514775147851479514805148151482514835148451485514865148751488514895149051491514925149351494514955149651497514985149951500515015150251503515045150551506515075150851509515105151151512515135151451515515165151751518515195152051521515225152351524515255152651527515285152951530515315153251533515345153551536515375153851539515405154151542515435154451545515465154751548515495155051551515525155351554515555155651557515585155951560515615156251563515645156551566515675156851569515705157151572515735157451575515765157751578515795158051581515825158351584515855158651587515885158951590515915159251593515945159551596515975159851599516005160151602516035160451605516065160751608516095161051611516125161351614516155161651617516185161951620516215162251623516245162551626516275162851629516305163151632516335163451635516365163751638516395164051641516425164351644516455164651647516485164951650516515165251653516545165551656516575165851659516605166151662516635166451665516665166751668516695167051671516725167351674516755167651677516785167951680516815168251683516845168551686516875168851689516905169151692516935169451695516965169751698516995170051701517025170351704517055170651707517085170951710517115171251713517145171551716517175171851719517205172151722517235172451725517265172751728517295173051731517325173351734517355173651737517385173951740517415174251743517445174551746517475174851749517505175151752517535175451755517565175751758517595176051761517625176351764517655176651767517685176951770517715177251773517745177551776517775177851779517805178151782517835178451785517865178751788517895179051791517925179351794517955179651797517985179951800518015180251803518045180551806518075180851809518105181151812518135181451815518165181751818518195182051821518225182351824518255182651827518285182951830518315183251833518345183551836518375183851839518405184151842518435184451845518465184751848518495185051851518525185351854518555185651857518585185951860518615186251863518645186551866518675186851869518705187151872518735187451875518765187751878518795188051881518825188351884518855188651887518885188951890518915189251893518945189551896518975189851899519005190151902519035190451905519065190751908519095191051911519125191351914519155191651917519185191951920519215192251923519245192551926519275192851929519305193151932519335193451935519365193751938519395194051941519425194351944519455194651947519485194951950519515195251953519545195551956519575195851959519605196151962519635196451965519665196751968519695197051971519725197351974519755197651977519785197951980519815198251983519845198551986519875198851989519905199151992519935199451995519965199751998519995200052001520025200352004520055200652007520085200952010520115201252013520145201552016520175201852019520205202152022520235202452025520265202752028520295203052031520325203352034520355203652037520385203952040520415204252043520445204552046520475204852049520505205152052520535205452055520565205752058520595206052061520625206352064520655206652067520685206952070520715207252073520745207552076520775207852079520805208152082520835208452085520865208752088520895209052091520925209352094520955209652097520985209952100521015210252103521045210552106521075210852109521105211152112521135211452115521165211752118521195212052121521225212352124521255212652127521285212952130521315213252133521345213552136521375213852139521405214152142521435214452145521465214752148521495215052151521525215352154521555215652157521585215952160521615216252163521645216552166521675216852169521705217152172521735217452175521765217752178521795218052181521825218352184521855218652187521885218952190521915219252193521945219552196521975219852199522005220152202522035220452205522065220752208522095221052211522125221352214522155221652217522185221952220522215222252223522245222552226522275222852229522305223152232522335223452235522365223752238522395224052241522425224352244522455224652247522485224952250522515225252253522545225552256522575225852259522605226152262522635226452265522665226752268522695227052271522725227352274522755227652277522785227952280522815228252283522845228552286522875228852289522905229152292522935229452295522965229752298522995230052301523025230352304523055230652307523085230952310523115231252313523145231552316523175231852319523205232152322523235232452325523265232752328523295233052331523325233352334523355233652337523385233952340523415234252343523445234552346523475234852349523505235152352523535235452355523565235752358523595236052361523625236352364523655236652367523685236952370523715237252373523745237552376523775237852379523805238152382523835238452385523865238752388523895239052391523925239352394523955239652397523985239952400524015240252403524045240552406524075240852409524105241152412524135241452415524165241752418524195242052421524225242352424524255242652427524285242952430524315243252433524345243552436524375243852439524405244152442524435244452445524465244752448524495245052451524525245352454524555245652457524585245952460524615246252463524645246552466524675246852469524705247152472524735247452475524765247752478524795248052481524825248352484524855248652487524885248952490524915249252493524945249552496524975249852499525005250152502525035250452505525065250752508525095251052511525125251352514525155251652517525185251952520525215252252523525245252552526525275252852529525305253152532525335253452535525365253752538525395254052541525425254352544525455254652547525485254952550525515255252553525545255552556525575255852559525605256152562525635256452565525665256752568525695257052571525725257352574525755257652577525785257952580525815258252583525845258552586525875258852589525905259152592525935259452595525965259752598525995260052601526025260352604526055260652607526085260952610526115261252613526145261552616526175261852619526205262152622526235262452625526265262752628526295263052631526325263352634526355263652637526385263952640526415264252643526445264552646526475264852649526505265152652526535265452655526565265752658526595266052661526625266352664526655266652667526685266952670526715267252673526745267552676526775267852679526805268152682526835268452685526865268752688526895269052691526925269352694526955269652697526985269952700527015270252703527045270552706527075270852709527105271152712527135271452715527165271752718527195272052721527225272352724527255272652727527285272952730527315273252733527345273552736527375273852739527405274152742527435274452745527465274752748527495275052751527525275352754527555275652757527585275952760527615276252763527645276552766527675276852769527705277152772527735277452775527765277752778527795278052781527825278352784527855278652787527885278952790527915279252793527945279552796527975279852799528005280152802528035280452805528065280752808528095281052811528125281352814528155281652817528185281952820528215282252823528245282552826528275282852829528305283152832528335283452835528365283752838528395284052841528425284352844528455284652847528485284952850528515285252853528545285552856528575285852859528605286152862528635286452865528665286752868528695287052871528725287352874528755287652877528785287952880528815288252883528845288552886528875288852889528905289152892528935289452895528965289752898528995290052901529025290352904529055290652907529085290952910529115291252913529145291552916529175291852919529205292152922529235292452925529265292752928529295293052931529325293352934529355293652937529385293952940529415294252943529445294552946529475294852949529505295152952529535295452955529565295752958529595296052961529625296352964529655296652967529685296952970529715297252973529745297552976529775297852979529805298152982529835298452985529865298752988529895299052991529925299352994529955299652997529985299953000530015300253003530045300553006530075300853009530105301153012530135301453015530165301753018530195302053021530225302353024530255302653027530285302953030530315303253033530345303553036530375303853039530405304153042530435304453045530465304753048530495305053051530525305353054530555305653057530585305953060530615306253063530645306553066530675306853069530705307153072530735307453075530765307753078530795308053081530825308353084530855308653087530885308953090530915309253093530945309553096530975309853099531005310153102531035310453105531065310753108531095311053111531125311353114531155311653117531185311953120531215312253123531245312553126531275312853129531305313153132531335313453135531365313753138531395314053141531425314353144531455314653147531485314953150531515315253153531545315553156531575315853159531605316153162531635316453165531665316753168531695317053171531725317353174531755317653177531785317953180531815318253183531845318553186531875318853189531905319153192531935319453195531965319753198531995320053201532025320353204532055320653207532085320953210532115321253213532145321553216532175321853219532205322153222532235322453225532265322753228532295323053231532325323353234532355323653237532385323953240532415324253243532445324553246532475324853249532505325153252532535325453255532565325753258532595326053261532625326353264532655326653267532685326953270532715327253273532745327553276532775327853279532805328153282532835328453285532865328753288532895329053291532925329353294532955329653297532985329953300533015330253303533045330553306533075330853309533105331153312533135331453315533165331753318533195332053321533225332353324533255332653327533285332953330533315333253333533345333553336533375333853339533405334153342533435334453345533465334753348533495335053351533525335353354533555335653357533585335953360533615336253363533645336553366533675336853369533705337153372533735337453375533765337753378533795338053381533825338353384533855338653387533885338953390533915339253393533945339553396533975339853399534005340153402534035340453405534065340753408534095341053411534125341353414534155341653417534185341953420534215342253423534245342553426534275342853429534305343153432534335343453435534365343753438534395344053441534425344353444534455344653447534485344953450534515345253453534545345553456534575345853459534605346153462534635346453465534665346753468534695347053471534725347353474534755347653477534785347953480534815348253483534845348553486534875348853489534905349153492534935349453495534965349753498534995350053501535025350353504535055350653507535085350953510535115351253513535145351553516535175351853519535205352153522535235352453525535265352753528535295353053531535325353353534535355353653537535385353953540535415354253543535445354553546535475354853549535505355153552535535355453555535565355753558535595356053561535625356353564535655356653567535685356953570535715357253573535745357553576535775357853579535805358153582535835358453585535865358753588535895359053591535925359353594535955359653597535985359953600536015360253603536045360553606536075360853609536105361153612536135361453615536165361753618536195362053621536225362353624536255362653627536285362953630536315363253633536345363553636536375363853639536405364153642536435364453645536465364753648536495365053651536525365353654536555365653657536585365953660536615366253663536645366553666536675366853669536705367153672536735367453675536765367753678536795368053681536825368353684536855368653687536885368953690536915369253693536945369553696536975369853699537005370153702537035370453705537065370753708537095371053711537125371353714537155371653717537185371953720537215372253723537245372553726537275372853729537305373153732537335373453735537365373753738537395374053741537425374353744537455374653747537485374953750537515375253753537545375553756537575375853759537605376153762537635376453765537665376753768537695377053771537725377353774537755377653777537785377953780537815378253783537845378553786537875378853789537905379153792537935379453795537965379753798537995380053801538025380353804538055380653807538085380953810538115381253813538145381553816538175381853819538205382153822538235382453825538265382753828538295383053831538325383353834538355383653837538385383953840538415384253843538445384553846538475384853849538505385153852538535385453855538565385753858538595386053861538625386353864538655386653867538685386953870538715387253873538745387553876538775387853879538805388153882538835388453885538865388753888538895389053891538925389353894538955389653897538985389953900539015390253903539045390553906539075390853909539105391153912539135391453915539165391753918539195392053921539225392353924539255392653927539285392953930539315393253933539345393553936539375393853939539405394153942539435394453945539465394753948539495395053951539525395353954539555395653957539585395953960539615396253963539645396553966539675396853969539705397153972539735397453975539765397753978539795398053981539825398353984539855398653987539885398953990539915399253993539945399553996539975399853999540005400154002540035400454005540065400754008540095401054011540125401354014540155401654017540185401954020540215402254023540245402554026540275402854029540305403154032540335403454035540365403754038540395404054041540425404354044540455404654047540485404954050540515405254053540545405554056540575405854059540605406154062540635406454065540665406754068540695407054071540725407354074540755407654077540785407954080540815408254083540845408554086540875408854089540905409154092540935409454095540965409754098540995410054101541025410354104541055410654107541085410954110541115411254113541145411554116541175411854119541205412154122541235412454125541265412754128541295413054131541325413354134541355413654137541385413954140541415414254143541445414554146541475414854149541505415154152541535415454155541565415754158541595416054161541625416354164541655416654167541685416954170541715417254173541745417554176541775417854179541805418154182541835418454185541865418754188541895419054191541925419354194541955419654197541985419954200542015420254203542045420554206542075420854209542105421154212542135421454215542165421754218542195422054221542225422354224542255422654227542285422954230542315423254233542345423554236542375423854239542405424154242542435424454245542465424754248542495425054251542525425354254542555425654257542585425954260542615426254263542645426554266542675426854269542705427154272542735427454275542765427754278542795428054281542825428354284542855428654287542885428954290542915429254293542945429554296542975429854299543005430154302543035430454305543065430754308543095431054311543125431354314543155431654317543185431954320543215432254323543245432554326543275432854329543305433154332543335433454335543365433754338543395434054341543425434354344543455434654347543485434954350543515435254353543545435554356543575435854359543605436154362543635436454365543665436754368543695437054371543725437354374543755437654377543785437954380543815438254383543845438554386543875438854389543905439154392543935439454395543965439754398543995440054401544025440354404544055440654407544085440954410544115441254413544145441554416544175441854419544205442154422544235442454425544265442754428544295443054431544325443354434544355443654437544385443954440544415444254443544445444554446544475444854449544505445154452544535445454455544565445754458544595446054461544625446354464544655446654467544685446954470544715447254473544745447554476544775447854479544805448154482544835448454485544865448754488544895449054491544925449354494544955449654497544985449954500545015450254503545045450554506545075450854509545105451154512545135451454515545165451754518545195452054521545225452354524545255452654527545285452954530545315453254533545345453554536545375453854539545405454154542545435454454545545465454754548545495455054551545525455354554545555455654557545585455954560545615456254563545645456554566545675456854569545705457154572545735457454575545765457754578545795458054581545825458354584545855458654587545885458954590545915459254593545945459554596545975459854599546005460154602546035460454605546065460754608546095461054611546125461354614546155461654617546185461954620546215462254623546245462554626546275462854629546305463154632546335463454635546365463754638546395464054641546425464354644546455464654647546485464954650546515465254653546545465554656546575465854659546605466154662546635466454665546665466754668546695467054671546725467354674546755467654677546785467954680546815468254683546845468554686546875468854689546905469154692546935469454695546965469754698546995470054701547025470354704547055470654707547085470954710547115471254713547145471554716547175471854719547205472154722547235472454725547265472754728547295473054731547325473354734547355473654737547385473954740547415474254743547445474554746547475474854749547505475154752547535475454755547565475754758547595476054761547625476354764547655476654767547685476954770547715477254773547745477554776547775477854779547805478154782547835478454785547865478754788547895479054791547925479354794547955479654797547985479954800548015480254803548045480554806548075480854809548105481154812548135481454815548165481754818548195482054821548225482354824548255482654827548285482954830548315483254833548345483554836548375483854839548405484154842548435484454845548465484754848548495485054851548525485354854548555485654857548585485954860548615486254863548645486554866548675486854869548705487154872548735487454875548765487754878548795488054881548825488354884548855488654887548885488954890548915489254893548945489554896548975489854899549005490154902549035490454905549065490754908549095491054911549125491354914549155491654917549185491954920549215492254923549245492554926549275492854929549305493154932549335493454935549365493754938549395494054941549425494354944549455494654947549485494954950549515495254953549545495554956549575495854959549605496154962549635496454965549665496754968549695497054971549725497354974549755497654977549785497954980549815498254983549845498554986549875498854989549905499154992549935499454995549965499754998549995500055001550025500355004550055500655007550085500955010550115501255013550145501555016550175501855019550205502155022550235502455025550265502755028550295503055031550325503355034550355503655037550385503955040550415504255043550445504555046550475504855049550505505155052550535505455055550565505755058550595506055061550625506355064550655506655067550685506955070550715507255073550745507555076550775507855079550805508155082550835508455085550865508755088550895509055091550925509355094550955509655097550985509955100551015510255103551045510555106551075510855109551105511155112551135511455115551165511755118551195512055121551225512355124551255512655127551285512955130551315513255133551345513555136551375513855139551405514155142551435514455145551465514755148551495515055151551525515355154551555515655157551585515955160551615516255163551645516555166551675516855169551705517155172551735517455175551765517755178551795518055181551825518355184551855518655187551885518955190551915519255193551945519555196551975519855199552005520155202552035520455205552065520755208552095521055211552125521355214552155521655217552185521955220552215522255223552245522555226552275522855229552305523155232552335523455235552365523755238552395524055241552425524355244552455524655247552485524955250552515525255253552545525555256552575525855259552605526155262552635526455265552665526755268552695527055271552725527355274552755527655277552785527955280552815528255283552845528555286552875528855289552905529155292552935529455295552965529755298552995530055301553025530355304553055530655307553085530955310553115531255313553145531555316553175531855319553205532155322553235532455325553265532755328553295533055331553325533355334553355533655337553385533955340553415534255343553445534555346553475534855349553505535155352553535535455355553565535755358553595536055361553625536355364553655536655367553685536955370553715537255373553745537555376553775537855379553805538155382553835538455385553865538755388553895539055391553925539355394553955539655397553985539955400554015540255403554045540555406554075540855409554105541155412554135541455415554165541755418554195542055421554225542355424554255542655427554285542955430554315543255433554345543555436554375543855439554405544155442554435544455445554465544755448554495545055451554525545355454554555545655457554585545955460554615546255463554645546555466554675546855469554705547155472554735547455475554765547755478554795548055481554825548355484554855548655487554885548955490554915549255493554945549555496554975549855499555005550155502555035550455505555065550755508555095551055511555125551355514555155551655517555185551955520555215552255523555245552555526555275552855529555305553155532555335553455535555365553755538555395554055541555425554355544555455554655547555485554955550555515555255553555545555555556555575555855559555605556155562555635556455565555665556755568555695557055571555725557355574555755557655577555785557955580555815558255583555845558555586555875558855589555905559155592555935559455595555965559755598555995560055601556025560355604556055560655607556085560955610556115561255613556145561555616556175561855619556205562155622556235562455625556265562755628556295563055631556325563355634556355563655637556385563955640556415564255643556445564555646556475564855649556505565155652556535565455655556565565755658556595566055661556625566355664556655566655667556685566955670556715567255673556745567555676556775567855679556805568155682556835568455685556865568755688556895569055691556925569355694556955569655697556985569955700557015570255703557045570555706557075570855709557105571155712557135571455715557165571755718557195572055721557225572355724557255572655727557285572955730557315573255733557345573555736557375573855739557405574155742557435574455745557465574755748557495575055751557525575355754557555575655757557585575955760557615576255763557645576555766557675576855769557705577155772557735577455775557765577755778557795578055781557825578355784557855578655787557885578955790557915579255793557945579555796557975579855799558005580155802558035580455805558065580755808558095581055811558125581355814558155581655817558185581955820558215582255823558245582555826558275582855829558305583155832558335583455835558365583755838558395584055841558425584355844558455584655847558485584955850558515585255853558545585555856558575585855859558605586155862558635586455865558665586755868558695587055871558725587355874558755587655877558785587955880558815588255883558845588555886558875588855889558905589155892558935589455895558965589755898558995590055901559025590355904559055590655907559085590955910559115591255913559145591555916559175591855919559205592155922559235592455925559265592755928559295593055931559325593355934559355593655937559385593955940559415594255943559445594555946559475594855949559505595155952559535595455955559565595755958559595596055961559625596355964559655596655967559685596955970559715597255973559745597555976559775597855979559805598155982559835598455985559865598755988559895599055991559925599355994559955599655997559985599956000560015600256003560045600556006560075600856009560105601156012560135601456015560165601756018560195602056021560225602356024560255602656027560285602956030560315603256033560345603556036560375603856039560405604156042560435604456045560465604756048560495605056051560525605356054560555605656057560585605956060560615606256063560645606556066560675606856069560705607156072560735607456075560765607756078560795608056081560825608356084560855608656087560885608956090560915609256093560945609556096560975609856099561005610156102561035610456105561065610756108561095611056111561125611356114561155611656117561185611956120561215612256123561245612556126561275612856129561305613156132561335613456135561365613756138561395614056141561425614356144561455614656147561485614956150561515615256153561545615556156561575615856159561605616156162561635616456165561665616756168561695617056171561725617356174561755617656177561785617956180561815618256183561845618556186561875618856189561905619156192561935619456195561965619756198561995620056201562025620356204562055620656207562085620956210562115621256213562145621556216562175621856219562205622156222562235622456225562265622756228562295623056231562325623356234562355623656237562385623956240562415624256243562445624556246562475624856249562505625156252562535625456255562565625756258562595626056261562625626356264562655626656267562685626956270562715627256273562745627556276562775627856279562805628156282562835628456285562865628756288562895629056291562925629356294562955629656297562985629956300563015630256303563045630556306563075630856309563105631156312563135631456315563165631756318563195632056321563225632356324563255632656327563285632956330563315633256333563345633556336563375633856339563405634156342563435634456345563465634756348563495635056351563525635356354563555635656357563585635956360563615636256363563645636556366563675636856369563705637156372563735637456375563765637756378563795638056381563825638356384563855638656387563885638956390563915639256393563945639556396563975639856399564005640156402564035640456405564065640756408564095641056411564125641356414564155641656417564185641956420564215642256423564245642556426564275642856429564305643156432564335643456435564365643756438564395644056441564425644356444564455644656447564485644956450564515645256453564545645556456564575645856459564605646156462564635646456465564665646756468564695647056471564725647356474564755647656477564785647956480564815648256483564845648556486564875648856489564905649156492564935649456495564965649756498564995650056501565025650356504565055650656507565085650956510565115651256513565145651556516565175651856519565205652156522565235652456525565265652756528565295653056531565325653356534565355653656537565385653956540565415654256543565445654556546565475654856549565505655156552565535655456555565565655756558565595656056561565625656356564565655656656567565685656956570565715657256573565745657556576565775657856579565805658156582565835658456585565865658756588565895659056591565925659356594565955659656597565985659956600566015660256603566045660556606566075660856609566105661156612566135661456615566165661756618566195662056621566225662356624566255662656627566285662956630566315663256633566345663556636566375663856639566405664156642566435664456645566465664756648566495665056651566525665356654566555665656657566585665956660566615666256663566645666556666566675666856669566705667156672566735667456675566765667756678566795668056681566825668356684566855668656687566885668956690566915669256693566945669556696566975669856699567005670156702567035670456705567065670756708567095671056711567125671356714567155671656717567185671956720567215672256723567245672556726567275672856729567305673156732567335673456735567365673756738567395674056741567425674356744567455674656747567485674956750567515675256753567545675556756567575675856759567605676156762567635676456765567665676756768567695677056771567725677356774567755677656777567785677956780567815678256783567845678556786567875678856789567905679156792567935679456795567965679756798567995680056801568025680356804568055680656807568085680956810568115681256813568145681556816568175681856819568205682156822568235682456825568265682756828568295683056831568325683356834568355683656837568385683956840568415684256843568445684556846568475684856849568505685156852568535685456855568565685756858568595686056861568625686356864568655686656867568685686956870568715687256873568745687556876568775687856879568805688156882568835688456885568865688756888568895689056891568925689356894568955689656897568985689956900569015690256903569045690556906569075690856909569105691156912569135691456915569165691756918569195692056921569225692356924569255692656927569285692956930569315693256933569345693556936569375693856939569405694156942569435694456945569465694756948569495695056951569525695356954569555695656957569585695956960569615696256963569645696556966569675696856969569705697156972569735697456975569765697756978569795698056981569825698356984569855698656987569885698956990569915699256993569945699556996569975699856999570005700157002570035700457005570065700757008570095701057011570125701357014570155701657017570185701957020570215702257023570245702557026570275702857029570305703157032570335703457035570365703757038570395704057041570425704357044570455704657047570485704957050570515705257053570545705557056570575705857059570605706157062570635706457065570665706757068570695707057071570725707357074570755707657077570785707957080570815708257083570845708557086570875708857089570905709157092570935709457095570965709757098570995710057101571025710357104571055710657107571085710957110571115711257113571145711557116571175711857119571205712157122571235712457125571265712757128571295713057131571325713357134571355713657137571385713957140571415714257143571445714557146571475714857149571505715157152571535715457155571565715757158571595716057161571625716357164571655716657167571685716957170571715717257173571745717557176571775717857179571805718157182571835718457185571865718757188571895719057191571925719357194571955719657197571985719957200572015720257203572045720557206572075720857209572105721157212572135721457215572165721757218572195722057221572225722357224572255722657227572285722957230572315723257233572345723557236572375723857239572405724157242572435724457245572465724757248572495725057251572525725357254572555725657257572585725957260572615726257263572645726557266572675726857269572705727157272572735727457275572765727757278572795728057281572825728357284572855728657287572885728957290572915729257293572945729557296572975729857299573005730157302573035730457305573065730757308573095731057311573125731357314573155731657317573185731957320573215732257323573245732557326573275732857329573305733157332573335733457335573365733757338573395734057341573425734357344573455734657347573485734957350573515735257353573545735557356573575735857359573605736157362573635736457365573665736757368573695737057371573725737357374573755737657377573785737957380573815738257383573845738557386573875738857389573905739157392573935739457395573965739757398573995740057401574025740357404574055740657407574085740957410574115741257413574145741557416574175741857419574205742157422574235742457425574265742757428574295743057431574325743357434574355743657437574385743957440574415744257443574445744557446574475744857449574505745157452574535745457455574565745757458574595746057461574625746357464574655746657467574685746957470574715747257473574745747557476574775747857479574805748157482574835748457485574865748757488574895749057491574925749357494574955749657497574985749957500575015750257503575045750557506575075750857509575105751157512575135751457515575165751757518575195752057521575225752357524575255752657527575285752957530575315753257533575345753557536575375753857539575405754157542575435754457545575465754757548575495755057551575525755357554575555755657557575585755957560575615756257563575645756557566575675756857569575705757157572575735757457575575765757757578575795758057581575825758357584575855758657587575885758957590575915759257593575945759557596575975759857599576005760157602576035760457605576065760757608576095761057611576125761357614576155761657617576185761957620576215762257623576245762557626576275762857629576305763157632576335763457635576365763757638576395764057641576425764357644576455764657647576485764957650576515765257653576545765557656576575765857659576605766157662576635766457665576665766757668576695767057671576725767357674576755767657677576785767957680576815768257683576845768557686576875768857689576905769157692576935769457695576965769757698576995770057701577025770357704577055770657707577085770957710577115771257713577145771557716577175771857719577205772157722577235772457725577265772757728577295773057731577325773357734577355773657737577385773957740577415774257743577445774557746577475774857749577505775157752577535775457755577565775757758577595776057761577625776357764577655776657767577685776957770577715777257773577745777557776577775777857779577805778157782577835778457785577865778757788577895779057791577925779357794577955779657797577985779957800578015780257803578045780557806578075780857809578105781157812578135781457815578165781757818578195782057821578225782357824578255782657827578285782957830578315783257833578345783557836578375783857839578405784157842578435784457845578465784757848578495785057851578525785357854578555785657857578585785957860578615786257863578645786557866578675786857869578705787157872578735787457875578765787757878578795788057881578825788357884578855788657887578885788957890578915789257893578945789557896578975789857899579005790157902579035790457905579065790757908579095791057911579125791357914579155791657917579185791957920579215792257923579245792557926579275792857929579305793157932579335793457935579365793757938579395794057941579425794357944579455794657947579485794957950579515795257953579545795557956579575795857959579605796157962579635796457965579665796757968579695797057971579725797357974579755797657977579785797957980579815798257983579845798557986579875798857989579905799157992579935799457995579965799757998579995800058001580025800358004580055800658007580085800958010580115801258013580145801558016580175801858019580205802158022580235802458025580265802758028580295803058031580325803358034580355803658037580385803958040580415804258043580445804558046580475804858049580505805158052580535805458055580565805758058580595806058061580625806358064580655806658067580685806958070580715807258073580745807558076580775807858079580805808158082580835808458085580865808758088580895809058091580925809358094580955809658097580985809958100581015810258103581045810558106581075810858109581105811158112581135811458115581165811758118581195812058121581225812358124581255812658127581285812958130581315813258133581345813558136581375813858139581405814158142581435814458145581465814758148581495815058151581525815358154581555815658157581585815958160581615816258163581645816558166581675816858169581705817158172581735817458175581765817758178581795818058181581825818358184581855818658187581885818958190581915819258193581945819558196581975819858199582005820158202582035820458205582065820758208582095821058211582125821358214582155821658217582185821958220582215822258223582245822558226582275822858229582305823158232582335823458235582365823758238582395824058241582425824358244582455824658247582485824958250582515825258253582545825558256582575825858259582605826158262582635826458265582665826758268582695827058271582725827358274582755827658277582785827958280582815828258283582845828558286582875828858289582905829158292582935829458295582965829758298582995830058301583025830358304583055830658307583085830958310583115831258313583145831558316583175831858319583205832158322583235832458325583265832758328583295833058331583325833358334583355833658337583385833958340583415834258343583445834558346583475834858349583505835158352583535835458355583565835758358583595836058361583625836358364583655836658367583685836958370583715837258373583745837558376583775837858379583805838158382583835838458385583865838758388583895839058391583925839358394583955839658397583985839958400584015840258403584045840558406584075840858409584105841158412584135841458415584165841758418584195842058421584225842358424584255842658427584285842958430584315843258433584345843558436584375843858439584405844158442584435844458445584465844758448584495845058451584525845358454584555845658457584585845958460584615846258463584645846558466584675846858469584705847158472584735847458475584765847758478584795848058481584825848358484584855848658487584885848958490584915849258493584945849558496584975849858499585005850158502585035850458505585065850758508585095851058511585125851358514585155851658517585185851958520585215852258523585245852558526585275852858529585305853158532585335853458535585365853758538585395854058541585425854358544585455854658547585485854958550585515855258553585545855558556585575855858559585605856158562585635856458565585665856758568585695857058571585725857358574585755857658577585785857958580585815858258583585845858558586585875858858589585905859158592585935859458595585965859758598585995860058601586025860358604586055860658607586085860958610586115861258613586145861558616586175861858619586205862158622586235862458625586265862758628586295863058631586325863358634586355863658637586385863958640586415864258643586445864558646586475864858649586505865158652586535865458655586565865758658586595866058661586625866358664586655866658667586685866958670586715867258673586745867558676586775867858679586805868158682586835868458685586865868758688586895869058691586925869358694586955869658697586985869958700587015870258703587045870558706587075870858709587105871158712587135871458715587165871758718587195872058721587225872358724587255872658727587285872958730587315873258733587345873558736587375873858739587405874158742587435874458745587465874758748587495875058751587525875358754587555875658757587585875958760587615876258763587645876558766587675876858769587705877158772587735877458775587765877758778587795878058781587825878358784587855878658787587885878958790587915879258793587945879558796587975879858799588005880158802588035880458805588065880758808588095881058811588125881358814588155881658817588185881958820588215882258823588245882558826588275882858829588305883158832588335883458835588365883758838588395884058841588425884358844588455884658847588485884958850588515885258853588545885558856588575885858859588605886158862588635886458865588665886758868588695887058871588725887358874588755887658877588785887958880588815888258883588845888558886588875888858889588905889158892588935889458895588965889758898588995890058901589025890358904589055890658907589085890958910589115891258913589145891558916589175891858919589205892158922589235892458925589265892758928589295893058931589325893358934589355893658937589385893958940589415894258943589445894558946589475894858949589505895158952589535895458955589565895758958589595896058961589625896358964589655896658967589685896958970589715897258973589745897558976589775897858979589805898158982589835898458985589865898758988589895899058991589925899358994589955899658997589985899959000590015900259003590045900559006590075900859009590105901159012590135901459015590165901759018590195902059021590225902359024590255902659027590285902959030590315903259033590345903559036590375903859039590405904159042590435904459045590465904759048590495905059051590525905359054590555905659057590585905959060590615906259063590645906559066590675906859069590705907159072590735907459075590765907759078590795908059081590825908359084590855908659087590885908959090590915909259093590945909559096590975909859099591005910159102591035910459105591065910759108591095911059111591125911359114591155911659117591185911959120591215912259123591245912559126591275912859129591305913159132591335913459135591365913759138591395914059141591425914359144591455914659147591485914959150591515915259153591545915559156591575915859159591605916159162591635916459165591665916759168591695917059171591725917359174591755917659177591785917959180591815918259183591845918559186591875918859189591905919159192591935919459195591965919759198591995920059201592025920359204592055920659207592085920959210592115921259213592145921559216592175921859219592205922159222592235922459225592265922759228592295923059231592325923359234592355923659237592385923959240592415924259243592445924559246592475924859249592505925159252592535925459255592565925759258592595926059261592625926359264592655926659267592685926959270592715927259273592745927559276592775927859279592805928159282592835928459285592865928759288592895929059291592925929359294592955929659297592985929959300593015930259303593045930559306593075930859309593105931159312593135931459315593165931759318593195932059321593225932359324593255932659327593285932959330593315933259333593345933559336593375933859339593405934159342593435934459345593465934759348593495935059351593525935359354593555935659357593585935959360593615936259363593645936559366593675936859369593705937159372593735937459375593765937759378593795938059381593825938359384593855938659387593885938959390593915939259393593945939559396593975939859399594005940159402594035940459405594065940759408594095941059411594125941359414594155941659417594185941959420594215942259423594245942559426594275942859429594305943159432594335943459435594365943759438594395944059441594425944359444594455944659447594485944959450594515945259453594545945559456594575945859459594605946159462594635946459465594665946759468594695947059471594725947359474594755947659477594785947959480594815948259483594845948559486594875948859489594905949159492594935949459495594965949759498594995950059501595025950359504595055950659507595085950959510595115951259513595145951559516595175951859519595205952159522595235952459525595265952759528595295953059531595325953359534595355953659537595385953959540595415954259543595445954559546595475954859549595505955159552595535955459555595565955759558595595956059561595625956359564595655956659567595685956959570595715957259573595745957559576595775957859579595805958159582595835958459585595865958759588595895959059591595925959359594595955959659597595985959959600596015960259603596045960559606596075960859609596105961159612596135961459615596165961759618596195962059621596225962359624596255962659627596285962959630596315963259633596345963559636596375963859639596405964159642596435964459645596465964759648596495965059651596525965359654596555965659657596585965959660596615966259663596645966559666596675966859669596705967159672596735967459675596765967759678596795968059681596825968359684596855968659687596885968959690596915969259693596945969559696596975969859699597005970159702597035970459705597065970759708597095971059711597125971359714597155971659717597185971959720597215972259723597245972559726597275972859729597305973159732597335973459735597365973759738597395974059741597425974359744597455974659747597485974959750597515975259753597545975559756597575975859759597605976159762597635976459765597665976759768597695977059771597725977359774597755977659777597785977959780597815978259783597845978559786597875978859789597905979159792597935979459795597965979759798597995980059801598025980359804598055980659807598085980959810598115981259813598145981559816598175981859819598205982159822598235982459825598265982759828598295983059831598325983359834598355983659837598385983959840598415984259843598445984559846598475984859849598505985159852598535985459855598565985759858598595986059861598625986359864598655986659867598685986959870598715987259873598745987559876598775987859879598805988159882598835988459885598865988759888598895989059891598925989359894598955989659897598985989959900599015990259903599045990559906599075990859909599105991159912599135991459915599165991759918599195992059921599225992359924599255992659927599285992959930599315993259933599345993559936599375993859939599405994159942599435994459945599465994759948599495995059951599525995359954599555995659957599585995959960599615996259963599645996559966599675996859969599705997159972599735997459975599765997759978599795998059981599825998359984599855998659987599885998959990599915999259993599945999559996599975999859999600006000160002600036000460005600066000760008600096001060011600126001360014600156001660017600186001960020600216002260023600246002560026600276002860029600306003160032600336003460035600366003760038600396004060041600426004360044600456004660047600486004960050600516005260053600546005560056600576005860059600606006160062600636006460065600666006760068600696007060071600726007360074600756007660077600786007960080600816008260083600846008560086600876008860089600906009160092600936009460095600966009760098600996010060101601026010360104601056010660107601086010960110601116011260113601146011560116601176011860119601206012160122601236012460125601266012760128601296013060131601326013360134601356013660137601386013960140601416014260143601446014560146601476014860149601506015160152601536015460155601566015760158601596016060161601626016360164601656016660167601686016960170601716017260173601746017560176601776017860179601806018160182601836018460185601866018760188601896019060191601926019360194601956019660197601986019960200602016020260203602046020560206602076020860209602106021160212602136021460215602166021760218602196022060221602226022360224602256022660227602286022960230602316023260233602346023560236602376023860239602406024160242602436024460245602466024760248602496025060251602526025360254602556025660257602586025960260602616026260263602646026560266602676026860269602706027160272602736027460275602766027760278602796028060281602826028360284602856028660287602886028960290602916029260293602946029560296602976029860299603006030160302603036030460305603066030760308603096031060311603126031360314603156031660317603186031960320603216032260323603246032560326603276032860329603306033160332603336033460335603366033760338603396034060341603426034360344603456034660347603486034960350603516035260353603546035560356603576035860359603606036160362603636036460365603666036760368603696037060371603726037360374603756037660377603786037960380603816038260383603846038560386603876038860389603906039160392603936039460395603966039760398603996040060401604026040360404604056040660407604086040960410604116041260413604146041560416604176041860419604206042160422604236042460425604266042760428604296043060431604326043360434604356043660437604386043960440604416044260443604446044560446604476044860449604506045160452604536045460455604566045760458604596046060461604626046360464604656046660467604686046960470604716047260473604746047560476604776047860479604806048160482604836048460485604866048760488604896049060491604926049360494604956049660497604986049960500605016050260503605046050560506605076050860509605106051160512605136051460515605166051760518605196052060521605226052360524605256052660527605286052960530605316053260533605346053560536605376053860539605406054160542605436054460545605466054760548605496055060551605526055360554605556055660557605586055960560605616056260563605646056560566605676056860569605706057160572605736057460575605766057760578605796058060581605826058360584605856058660587605886058960590605916059260593605946059560596605976059860599606006060160602606036060460605606066060760608606096061060611606126061360614606156061660617606186061960620606216062260623606246062560626606276062860629606306063160632606336063460635606366063760638606396064060641606426064360644606456064660647606486064960650606516065260653606546065560656606576065860659606606066160662606636066460665606666066760668606696067060671606726067360674606756067660677606786067960680606816068260683606846068560686606876068860689606906069160692606936069460695606966069760698606996070060701607026070360704607056070660707607086070960710607116071260713607146071560716607176071860719607206072160722607236072460725607266072760728607296073060731607326073360734607356073660737607386073960740607416074260743607446074560746607476074860749607506075160752607536075460755607566075760758607596076060761607626076360764607656076660767607686076960770607716077260773607746077560776607776077860779607806078160782607836078460785607866078760788607896079060791607926079360794607956079660797607986079960800608016080260803608046080560806608076080860809608106081160812608136081460815608166081760818608196082060821608226082360824608256082660827608286082960830608316083260833608346083560836608376083860839608406084160842608436084460845608466084760848608496085060851608526085360854608556085660857608586085960860608616086260863608646086560866608676086860869608706087160872608736087460875608766087760878608796088060881608826088360884608856088660887608886088960890608916089260893608946089560896608976089860899609006090160902609036090460905609066090760908609096091060911609126091360914609156091660917609186091960920609216092260923609246092560926609276092860929609306093160932609336093460935609366093760938609396094060941609426094360944609456094660947609486094960950609516095260953609546095560956609576095860959609606096160962609636096460965609666096760968609696097060971609726097360974609756097660977609786097960980609816098260983609846098560986609876098860989609906099160992609936099460995609966099760998609996100061001610026100361004610056100661007610086100961010610116101261013610146101561016610176101861019610206102161022610236102461025610266102761028610296103061031610326103361034610356103661037610386103961040610416104261043610446104561046610476104861049610506105161052610536105461055610566105761058610596106061061610626106361064610656106661067610686106961070610716107261073610746107561076610776107861079610806108161082610836108461085610866108761088610896109061091610926109361094610956109661097610986109961100611016110261103611046110561106611076110861109611106111161112611136111461115611166111761118611196112061121611226112361124611256112661127611286112961130611316113261133611346113561136611376113861139611406114161142611436114461145611466114761148611496115061151611526115361154611556115661157611586115961160611616116261163611646116561166611676116861169611706117161172611736117461175611766117761178611796118061181611826118361184611856118661187611886118961190611916119261193611946119561196611976119861199612006120161202612036120461205612066120761208612096121061211612126121361214612156121661217612186121961220612216122261223612246122561226612276122861229612306123161232612336123461235612366123761238612396124061241612426124361244612456124661247612486124961250612516125261253612546125561256612576125861259612606126161262612636126461265612666126761268612696127061271612726127361274612756127661277612786127961280612816128261283612846128561286612876128861289612906129161292612936129461295612966129761298612996130061301613026130361304613056130661307613086130961310613116131261313613146131561316613176131861319613206132161322613236132461325613266132761328613296133061331613326133361334613356133661337613386133961340613416134261343613446134561346613476134861349613506135161352613536135461355613566135761358613596136061361613626136361364613656136661367613686136961370613716137261373613746137561376613776137861379613806138161382613836138461385613866138761388613896139061391613926139361394613956139661397613986139961400614016140261403614046140561406614076140861409614106141161412614136141461415614166141761418614196142061421614226142361424614256142661427614286142961430614316143261433614346143561436614376143861439614406144161442614436144461445614466144761448614496145061451614526145361454614556145661457614586145961460614616146261463614646146561466614676146861469614706147161472614736147461475614766147761478614796148061481614826148361484614856148661487614886148961490614916149261493614946149561496614976149861499615006150161502615036150461505615066150761508615096151061511615126151361514615156151661517615186151961520615216152261523615246152561526615276152861529615306153161532615336153461535615366153761538615396154061541615426154361544615456154661547615486154961550615516155261553615546155561556615576155861559615606156161562615636156461565615666156761568615696157061571615726157361574615756157661577615786157961580615816158261583615846158561586615876158861589615906159161592615936159461595615966159761598615996160061601616026160361604616056160661607616086160961610616116161261613616146161561616616176161861619616206162161622616236162461625616266162761628616296163061631616326163361634616356163661637616386163961640616416164261643616446164561646616476164861649616506165161652616536165461655616566165761658616596166061661616626166361664616656166661667616686166961670616716167261673616746167561676616776167861679616806168161682616836168461685616866168761688616896169061691616926169361694616956169661697616986169961700617016170261703617046170561706617076170861709617106171161712617136171461715617166171761718617196172061721617226172361724617256172661727617286172961730617316173261733617346173561736617376173861739617406174161742617436174461745617466174761748617496175061751617526175361754617556175661757617586175961760617616176261763617646176561766617676176861769617706177161772617736177461775617766177761778617796178061781617826178361784617856178661787617886178961790617916179261793617946179561796617976179861799618006180161802618036180461805618066180761808618096181061811618126181361814618156181661817618186181961820618216182261823618246182561826618276182861829618306183161832618336183461835618366183761838618396184061841618426184361844618456184661847618486184961850618516185261853618546185561856618576185861859618606186161862618636186461865618666186761868618696187061871618726187361874618756187661877618786187961880618816188261883618846188561886618876188861889618906189161892618936189461895618966189761898618996190061901619026190361904619056190661907619086190961910619116191261913619146191561916619176191861919619206192161922619236192461925619266192761928619296193061931619326193361934619356193661937619386193961940619416194261943619446194561946619476194861949619506195161952619536195461955619566195761958619596196061961619626196361964619656196661967619686196961970619716197261973619746197561976619776197861979619806198161982619836198461985619866198761988619896199061991619926199361994619956199661997619986199962000620016200262003620046200562006620076200862009620106201162012620136201462015620166201762018620196202062021620226202362024620256202662027620286202962030620316203262033620346203562036620376203862039620406204162042620436204462045620466204762048620496205062051620526205362054620556205662057620586205962060620616206262063620646206562066620676206862069620706207162072620736207462075620766207762078620796208062081620826208362084620856208662087620886208962090620916209262093620946209562096620976209862099621006210162102621036210462105621066210762108621096211062111621126211362114621156211662117621186211962120621216212262123621246212562126621276212862129621306213162132621336213462135621366213762138621396214062141621426214362144621456214662147621486214962150621516215262153621546215562156621576215862159621606216162162621636216462165621666216762168621696217062171621726217362174621756217662177621786217962180621816218262183621846218562186621876218862189621906219162192621936219462195621966219762198621996220062201622026220362204622056220662207622086220962210622116221262213622146221562216622176221862219622206222162222622236222462225622266222762228622296223062231622326223362234622356223662237622386223962240622416224262243622446224562246622476224862249622506225162252622536225462255622566225762258622596226062261622626226362264622656226662267622686226962270622716227262273622746227562276622776227862279622806228162282622836228462285622866228762288622896229062291622926229362294622956229662297622986229962300623016230262303623046230562306623076230862309623106231162312623136231462315623166231762318623196232062321623226232362324623256232662327623286232962330623316233262333623346233562336623376233862339623406234162342623436234462345623466234762348623496235062351623526235362354623556235662357623586235962360623616236262363623646236562366623676236862369623706237162372623736237462375623766237762378623796238062381623826238362384623856238662387623886238962390623916239262393623946239562396623976239862399624006240162402624036240462405624066240762408624096241062411624126241362414624156241662417624186241962420624216242262423624246242562426624276242862429624306243162432624336243462435624366243762438624396244062441624426244362444624456244662447624486244962450624516245262453624546245562456624576245862459624606246162462624636246462465624666246762468624696247062471624726247362474624756247662477624786247962480624816248262483624846248562486624876248862489624906249162492624936249462495624966249762498624996250062501625026250362504625056250662507625086250962510625116251262513625146251562516625176251862519625206252162522625236252462525625266252762528625296253062531625326253362534625356253662537625386253962540625416254262543625446254562546625476254862549625506255162552625536255462555625566255762558625596256062561625626256362564625656256662567625686256962570625716257262573625746257562576625776257862579625806258162582625836258462585625866258762588625896259062591625926259362594625956259662597625986259962600626016260262603626046260562606626076260862609626106261162612626136261462615626166261762618626196262062621626226262362624626256262662627626286262962630626316263262633626346263562636626376263862639626406264162642626436264462645626466264762648626496265062651626526265362654626556265662657626586265962660626616266262663626646266562666626676266862669626706267162672626736267462675626766267762678626796268062681626826268362684626856268662687626886268962690626916269262693626946269562696626976269862699627006270162702627036270462705627066270762708627096271062711627126271362714627156271662717627186271962720627216272262723627246272562726627276272862729627306273162732627336273462735627366273762738627396274062741627426274362744627456274662747627486274962750627516275262753627546275562756627576275862759627606276162762627636276462765627666276762768627696277062771627726277362774627756277662777627786277962780627816278262783627846278562786627876278862789627906279162792627936279462795627966279762798627996280062801628026280362804628056280662807628086280962810628116281262813628146281562816628176281862819628206282162822628236282462825628266282762828628296283062831628326283362834628356283662837628386283962840628416284262843628446284562846628476284862849628506285162852628536285462855628566285762858628596286062861628626286362864628656286662867628686286962870628716287262873628746287562876628776287862879628806288162882628836288462885628866288762888628896289062891628926289362894628956289662897628986289962900629016290262903629046290562906629076290862909629106291162912629136291462915629166291762918629196292062921629226292362924629256292662927629286292962930629316293262933629346293562936629376293862939629406294162942629436294462945629466294762948629496295062951629526295362954629556295662957629586295962960629616296262963629646296562966629676296862969629706297162972629736297462975629766297762978629796298062981629826298362984629856298662987629886298962990629916299262993629946299562996629976299862999630006300163002630036300463005630066300763008630096301063011630126301363014630156301663017630186301963020630216302263023630246302563026630276302863029630306303163032630336303463035630366303763038630396304063041630426304363044630456304663047630486304963050630516305263053630546305563056630576305863059630606306163062630636306463065630666306763068630696307063071630726307363074630756307663077630786307963080630816308263083630846308563086630876308863089630906309163092630936309463095630966309763098630996310063101631026310363104631056310663107631086310963110631116311263113631146311563116631176311863119631206312163122631236312463125631266312763128631296313063131631326313363134631356313663137631386313963140631416314263143631446314563146631476314863149631506315163152631536315463155631566315763158631596316063161631626316363164631656316663167631686316963170631716317263173631746317563176631776317863179631806318163182631836318463185631866318763188631896319063191631926319363194631956319663197631986319963200632016320263203632046320563206632076320863209632106321163212632136321463215632166321763218632196322063221632226322363224632256322663227632286322963230632316323263233632346323563236632376323863239632406324163242632436324463245632466324763248632496325063251632526325363254632556325663257632586325963260632616326263263632646326563266632676326863269632706327163272632736327463275632766327763278632796328063281632826328363284632856328663287632886328963290632916329263293632946329563296632976329863299633006330163302633036330463305633066330763308633096331063311633126331363314633156331663317633186331963320633216332263323633246332563326633276332863329633306333163332633336333463335633366333763338633396334063341633426334363344633456334663347633486334963350633516335263353633546335563356633576335863359633606336163362633636336463365633666336763368633696337063371633726337363374633756337663377633786337963380633816338263383633846338563386633876338863389633906339163392633936339463395633966339763398633996340063401634026340363404634056340663407634086340963410634116341263413634146341563416634176341863419634206342163422634236342463425634266342763428634296343063431634326343363434634356343663437634386343963440634416344263443634446344563446634476344863449634506345163452634536345463455634566345763458634596346063461634626346363464634656346663467634686346963470634716347263473634746347563476634776347863479634806348163482634836348463485634866348763488634896349063491634926349363494634956349663497634986349963500635016350263503635046350563506635076350863509635106351163512635136351463515635166351763518635196352063521635226352363524635256352663527635286352963530635316353263533635346353563536635376353863539635406354163542635436354463545635466354763548635496355063551635526355363554635556355663557635586355963560635616356263563635646356563566635676356863569635706357163572635736357463575635766357763578635796358063581635826358363584635856358663587635886358963590635916359263593635946359563596635976359863599636006360163602636036360463605636066360763608636096361063611636126361363614636156361663617636186361963620636216362263623636246362563626636276362863629636306363163632636336363463635636366363763638636396364063641636426364363644636456364663647636486364963650636516365263653636546365563656636576365863659636606366163662636636366463665636666366763668636696367063671636726367363674636756367663677636786367963680636816368263683636846368563686636876368863689636906369163692636936369463695636966369763698636996370063701637026370363704637056370663707637086370963710637116371263713637146371563716637176371863719637206372163722637236372463725637266372763728637296373063731637326373363734637356373663737637386373963740637416374263743637446374563746637476374863749637506375163752637536375463755637566375763758637596376063761637626376363764637656376663767637686376963770637716377263773637746377563776637776377863779637806378163782637836378463785637866378763788637896379063791637926379363794637956379663797637986379963800638016380263803638046380563806638076380863809638106381163812638136381463815638166381763818638196382063821638226382363824638256382663827638286382963830638316383263833638346383563836638376383863839638406384163842638436384463845638466384763848638496385063851638526385363854638556385663857638586385963860638616386263863638646386563866638676386863869638706387163872638736387463875638766387763878638796388063881638826388363884638856388663887638886388963890638916389263893638946389563896638976389863899639006390163902639036390463905639066390763908639096391063911639126391363914639156391663917639186391963920639216392263923639246392563926639276392863929639306393163932639336393463935639366393763938639396394063941639426394363944639456394663947639486394963950639516395263953639546395563956639576395863959639606396163962639636396463965639666396763968639696397063971639726397363974639756397663977639786397963980639816398263983639846398563986639876398863989639906399163992639936399463995639966399763998639996400064001640026400364004640056400664007640086400964010640116401264013640146401564016640176401864019640206402164022640236402464025640266402764028640296403064031640326403364034640356403664037640386403964040640416404264043640446404564046640476404864049640506405164052640536405464055640566405764058640596406064061640626406364064640656406664067640686406964070640716407264073640746407564076640776407864079640806408164082640836408464085640866408764088640896409064091640926409364094640956409664097640986409964100641016410264103641046410564106641076410864109641106411164112641136411464115641166411764118641196412064121641226412364124641256412664127641286412964130641316413264133641346413564136641376413864139641406414164142641436414464145641466414764148641496415064151641526415364154641556415664157641586415964160641616416264163641646416564166641676416864169641706417164172641736417464175641766417764178641796418064181641826418364184641856418664187641886418964190641916419264193641946419564196641976419864199642006420164202642036420464205642066420764208642096421064211642126421364214642156421664217642186421964220642216422264223642246422564226642276422864229642306423164232642336423464235642366423764238642396424064241642426424364244642456424664247642486424964250642516425264253642546425564256642576425864259642606426164262642636426464265642666426764268642696427064271642726427364274642756427664277642786427964280642816428264283642846428564286642876428864289642906429164292642936429464295642966429764298642996430064301643026430364304643056430664307643086430964310643116431264313643146431564316643176431864319643206432164322643236432464325643266432764328643296433064331643326433364334643356433664337643386433964340643416434264343643446434564346643476434864349643506435164352643536435464355643566435764358643596436064361643626436364364643656436664367643686436964370643716437264373643746437564376643776437864379643806438164382643836438464385643866438764388643896439064391643926439364394643956439664397643986439964400644016440264403644046440564406644076440864409644106441164412644136441464415644166441764418644196442064421644226442364424644256442664427644286442964430644316443264433644346443564436644376443864439644406444164442644436444464445644466444764448644496445064451644526445364454644556445664457644586445964460644616446264463644646446564466644676446864469644706447164472644736447464475644766447764478644796448064481644826448364484644856448664487644886448964490644916449264493644946449564496644976449864499645006450164502645036450464505645066450764508645096451064511645126451364514645156451664517645186451964520645216452264523645246452564526645276452864529645306453164532645336453464535645366453764538645396454064541645426454364544645456454664547645486454964550645516455264553645546455564556645576455864559645606456164562645636456464565645666456764568645696457064571645726457364574645756457664577645786457964580645816458264583645846458564586645876458864589645906459164592645936459464595645966459764598645996460064601646026460364604646056460664607646086460964610646116461264613646146461564616646176461864619646206462164622646236462464625646266462764628646296463064631646326463364634646356463664637646386463964640646416464264643646446464564646646476464864649646506465164652646536465464655646566465764658646596466064661646626466364664646656466664667646686466964670646716467264673646746467564676646776467864679646806468164682646836468464685646866468764688646896469064691646926469364694646956469664697646986469964700647016470264703647046470564706647076470864709647106471164712647136471464715647166471764718647196472064721647226472364724647256472664727647286472964730647316473264733647346473564736647376473864739647406474164742647436474464745647466474764748647496475064751647526475364754647556475664757647586475964760647616476264763647646476564766647676476864769647706477164772647736477464775647766477764778647796478064781647826478364784647856478664787647886478964790647916479264793647946479564796647976479864799648006480164802648036480464805648066480764808648096481064811648126481364814648156481664817648186481964820648216482264823648246482564826648276482864829648306483164832648336483464835648366483764838648396484064841648426484364844648456484664847648486484964850648516485264853648546485564856648576485864859648606486164862648636486464865648666486764868648696487064871648726487364874648756487664877648786487964880648816488264883648846488564886648876488864889648906489164892648936489464895648966489764898648996490064901649026490364904649056490664907649086490964910649116491264913649146491564916649176491864919649206492164922649236492464925649266492764928649296493064931649326493364934649356493664937649386493964940649416494264943649446494564946649476494864949649506495164952649536495464955649566495764958649596496064961649626496364964649656496664967649686496964970649716497264973649746497564976649776497864979649806498164982649836498464985649866498764988649896499064991649926499364994649956499664997649986499965000650016500265003650046500565006650076500865009650106501165012650136501465015650166501765018650196502065021650226502365024650256502665027650286502965030650316503265033650346503565036650376503865039650406504165042650436504465045650466504765048650496505065051650526505365054650556505665057650586505965060650616506265063650646506565066650676506865069650706507165072650736507465075650766507765078650796508065081650826508365084650856508665087650886508965090650916509265093650946509565096650976509865099651006510165102651036510465105651066510765108651096511065111651126511365114651156511665117651186511965120651216512265123651246512565126651276512865129651306513165132651336513465135651366513765138651396514065141651426514365144651456514665147651486514965150651516515265153651546515565156651576515865159651606516165162651636516465165651666516765168651696517065171651726517365174651756517665177651786517965180651816518265183651846518565186651876518865189651906519165192651936519465195651966519765198651996520065201652026520365204652056520665207652086520965210652116521265213652146521565216652176521865219652206522165222652236522465225652266522765228652296523065231652326523365234652356523665237652386523965240652416524265243652446524565246652476524865249652506525165252652536525465255652566525765258652596526065261652626526365264652656526665267652686526965270652716527265273652746527565276652776527865279652806528165282652836528465285652866528765288652896529065291652926529365294652956529665297652986529965300653016530265303653046530565306653076530865309653106531165312653136531465315653166531765318653196532065321653226532365324653256532665327653286532965330653316533265333653346533565336653376533865339653406534165342653436534465345653466534765348653496535065351653526535365354653556535665357653586535965360653616536265363653646536565366653676536865369653706537165372653736537465375653766537765378653796538065381653826538365384653856538665387653886538965390653916539265393653946539565396653976539865399654006540165402654036540465405654066540765408654096541065411654126541365414654156541665417654186541965420654216542265423654246542565426654276542865429654306543165432654336543465435654366543765438654396544065441654426544365444654456544665447654486544965450654516545265453654546545565456654576545865459654606546165462654636546465465654666546765468654696547065471654726547365474654756547665477654786547965480654816548265483654846548565486654876548865489654906549165492654936549465495654966549765498654996550065501655026550365504655056550665507655086550965510655116551265513655146551565516655176551865519655206552165522655236552465525655266552765528655296553065531655326553365534655356553665537655386553965540655416554265543655446554565546655476554865549655506555165552655536555465555655566555765558655596556065561655626556365564655656556665567655686556965570655716557265573655746557565576655776557865579655806558165582655836558465585655866558765588655896559065591655926559365594655956559665597655986559965600656016560265603656046560565606656076560865609656106561165612656136561465615656166561765618656196562065621656226562365624656256562665627656286562965630656316563265633656346563565636656376563865639656406564165642656436564465645656466564765648656496565065651656526565365654656556565665657656586565965660656616566265663656646566565666656676566865669656706567165672656736567465675656766567765678656796568065681656826568365684656856568665687656886568965690656916569265693656946569565696656976569865699657006570165702657036570465705657066570765708657096571065711657126571365714657156571665717657186571965720657216572265723657246572565726657276572865729657306573165732657336573465735657366573765738657396574065741657426574365744657456574665747657486574965750657516575265753657546575565756657576575865759657606576165762657636576465765657666576765768657696577065771657726577365774657756577665777657786577965780657816578265783657846578565786657876578865789657906579165792657936579465795657966579765798657996580065801658026580365804658056580665807658086580965810658116581265813658146581565816658176581865819658206582165822658236582465825658266582765828658296583065831658326583365834658356583665837658386583965840658416584265843658446584565846658476584865849658506585165852658536585465855658566585765858658596586065861658626586365864658656586665867658686586965870658716587265873658746587565876658776587865879658806588165882658836588465885658866588765888658896589065891658926589365894658956589665897658986589965900659016590265903659046590565906659076590865909659106591165912659136591465915659166591765918659196592065921659226592365924659256592665927659286592965930659316593265933659346593565936659376593865939659406594165942659436594465945659466594765948659496595065951659526595365954659556595665957659586595965960659616596265963659646596565966659676596865969659706597165972659736597465975659766597765978659796598065981659826598365984659856598665987659886598965990659916599265993659946599565996659976599865999660006600166002660036600466005660066600766008660096601066011660126601366014660156601666017660186601966020660216602266023660246602566026660276602866029660306603166032660336603466035660366603766038660396604066041660426604366044660456604666047660486604966050660516605266053660546605566056660576605866059660606606166062660636606466065660666606766068660696607066071660726607366074660756607666077660786607966080660816608266083660846608566086660876608866089660906609166092660936609466095660966609766098660996610066101661026610366104661056610666107661086610966110661116611266113661146611566116661176611866119661206612166122661236612466125661266612766128661296613066131661326613366134661356613666137661386613966140661416614266143661446614566146661476614866149661506615166152661536615466155661566615766158661596616066161661626616366164661656616666167661686616966170661716617266173661746617566176661776617866179661806618166182661836618466185661866618766188661896619066191661926619366194661956619666197661986619966200662016620266203662046620566206662076620866209662106621166212662136621466215662166621766218662196622066221662226622366224662256622666227662286622966230662316623266233662346623566236662376623866239662406624166242662436624466245662466624766248662496625066251662526625366254662556625666257662586625966260662616626266263662646626566266662676626866269662706627166272662736627466275662766627766278662796628066281662826628366284662856628666287662886628966290662916629266293662946629566296662976629866299663006630166302663036630466305663066630766308663096631066311663126631366314663156631666317663186631966320663216632266323663246632566326663276632866329663306633166332663336633466335663366633766338663396634066341663426634366344663456634666347663486634966350663516635266353663546635566356663576635866359663606636166362663636636466365663666636766368663696637066371663726637366374663756637666377663786637966380663816638266383663846638566386663876638866389663906639166392663936639466395663966639766398663996640066401664026640366404664056640666407664086640966410664116641266413664146641566416664176641866419664206642166422664236642466425664266642766428664296643066431664326643366434664356643666437664386643966440664416644266443664446644566446664476644866449664506645166452664536645466455664566645766458664596646066461664626646366464664656646666467664686646966470664716647266473664746647566476664776647866479664806648166482664836648466485664866648766488664896649066491664926649366494664956649666497664986649966500665016650266503665046650566506665076650866509665106651166512665136651466515665166651766518665196652066521665226652366524665256652666527665286652966530665316653266533665346653566536665376653866539665406654166542665436654466545665466654766548665496655066551665526655366554665556655666557665586655966560665616656266563665646656566566665676656866569665706657166572665736657466575665766657766578665796658066581665826658366584665856658666587665886658966590665916659266593665946659566596665976659866599666006660166602666036660466605666066660766608666096661066611666126661366614666156661666617666186661966620666216662266623666246662566626666276662866629666306663166632666336663466635666366663766638666396664066641666426664366644666456664666647666486664966650666516665266653666546665566656666576665866659666606666166662666636666466665666666666766668666696667066671666726667366674666756667666677666786667966680666816668266683666846668566686666876668866689666906669166692666936669466695666966669766698666996670066701667026670366704667056670666707667086670966710667116671266713667146671566716667176671866719667206672166722667236672466725667266672766728667296673066731667326673366734667356673666737667386673966740667416674266743667446674566746667476674866749667506675166752667536675466755667566675766758667596676066761667626676366764667656676666767667686676966770667716677266773667746677566776667776677866779667806678166782667836678466785667866678766788667896679066791667926679366794667956679666797667986679966800668016680266803668046680566806668076680866809668106681166812668136681466815668166681766818668196682066821668226682366824668256682666827668286682966830668316683266833668346683566836668376683866839668406684166842668436684466845668466684766848668496685066851668526685366854668556685666857668586685966860668616686266863668646686566866668676686866869668706687166872668736687466875668766687766878668796688066881668826688366884668856688666887668886688966890668916689266893668946689566896668976689866899669006690166902669036690466905669066690766908669096691066911669126691366914669156691666917669186691966920669216692266923669246692566926669276692866929669306693166932669336693466935669366693766938669396694066941669426694366944669456694666947669486694966950669516695266953669546695566956669576695866959669606696166962669636696466965669666696766968669696697066971669726697366974669756697666977669786697966980669816698266983669846698566986669876698866989669906699166992669936699466995669966699766998669996700067001670026700367004670056700667007670086700967010670116701267013670146701567016670176701867019670206702167022670236702467025670266702767028670296703067031670326703367034670356703667037670386703967040670416704267043670446704567046670476704867049670506705167052670536705467055670566705767058670596706067061670626706367064670656706667067670686706967070670716707267073670746707567076670776707867079670806708167082670836708467085670866708767088670896709067091670926709367094670956709667097670986709967100671016710267103671046710567106671076710867109671106711167112671136711467115671166711767118671196712067121671226712367124671256712667127671286712967130671316713267133671346713567136671376713867139671406714167142671436714467145671466714767148671496715067151671526715367154671556715667157671586715967160671616716267163671646716567166671676716867169671706717167172671736717467175671766717767178671796718067181671826718367184671856718667187671886718967190671916719267193671946719567196671976719867199672006720167202672036720467205672066720767208672096721067211672126721367214672156721667217672186721967220672216722267223672246722567226672276722867229672306723167232672336723467235672366723767238672396724067241672426724367244672456724667247672486724967250672516725267253672546725567256672576725867259672606726167262672636726467265672666726767268672696727067271672726727367274672756727667277672786727967280672816728267283672846728567286672876728867289672906729167292672936729467295672966729767298672996730067301673026730367304673056730667307673086730967310673116731267313673146731567316673176731867319673206732167322673236732467325673266732767328673296733067331673326733367334673356733667337673386733967340673416734267343673446734567346673476734867349673506735167352673536735467355673566735767358673596736067361673626736367364673656736667367673686736967370673716737267373673746737567376673776737867379673806738167382673836738467385673866738767388673896739067391673926739367394673956739667397673986739967400674016740267403674046740567406674076740867409674106741167412674136741467415674166741767418674196742067421674226742367424674256742667427674286742967430674316743267433674346743567436674376743867439674406744167442674436744467445674466744767448674496745067451674526745367454674556745667457674586745967460674616746267463674646746567466674676746867469674706747167472674736747467475674766747767478674796748067481674826748367484674856748667487674886748967490674916749267493674946749567496674976749867499675006750167502675036750467505675066750767508675096751067511675126751367514675156751667517675186751967520675216752267523675246752567526675276752867529675306753167532675336753467535675366753767538675396754067541675426754367544675456754667547675486754967550675516755267553675546755567556675576755867559675606756167562675636756467565675666756767568675696757067571675726757367574675756757667577675786757967580675816758267583675846758567586675876758867589675906759167592675936759467595675966759767598675996760067601676026760367604676056760667607676086760967610676116761267613676146761567616676176761867619676206762167622676236762467625676266762767628676296763067631676326763367634676356763667637676386763967640676416764267643676446764567646676476764867649676506765167652676536765467655676566765767658676596766067661676626766367664676656766667667676686766967670676716767267673676746767567676676776767867679676806768167682676836768467685676866768767688676896769067691676926769367694676956769667697676986769967700677016770267703677046770567706677076770867709677106771167712677136771467715677166771767718677196772067721677226772367724677256772667727677286772967730677316773267733677346773567736677376773867739677406774167742677436774467745677466774767748677496775067751677526775367754677556775667757677586775967760677616776267763677646776567766677676776867769677706777167772677736777467775677766777767778677796778067781677826778367784677856778667787677886778967790677916779267793677946779567796677976779867799678006780167802678036780467805678066780767808678096781067811678126781367814678156781667817678186781967820678216782267823678246782567826678276782867829678306783167832678336783467835678366783767838678396784067841678426784367844678456784667847678486784967850678516785267853678546785567856678576785867859678606786167862678636786467865678666786767868678696787067871678726787367874678756787667877678786787967880678816788267883678846788567886678876788867889678906789167892678936789467895678966789767898678996790067901679026790367904679056790667907679086790967910679116791267913679146791567916679176791867919679206792167922679236792467925679266792767928679296793067931679326793367934679356793667937679386793967940679416794267943679446794567946679476794867949679506795167952679536795467955679566795767958679596796067961679626796367964679656796667967679686796967970679716797267973679746797567976679776797867979679806798167982679836798467985679866798767988679896799067991679926799367994679956799667997679986799968000680016800268003680046800568006680076800868009680106801168012680136801468015680166801768018680196802068021680226802368024680256802668027680286802968030680316803268033680346803568036680376803868039680406804168042680436804468045680466804768048680496805068051680526805368054680556805668057680586805968060680616806268063680646806568066680676806868069680706807168072680736807468075680766807768078680796808068081680826808368084680856808668087680886808968090680916809268093680946809568096680976809868099681006810168102681036810468105681066810768108681096811068111681126811368114681156811668117681186811968120681216812268123681246812568126681276812868129681306813168132681336813468135681366813768138681396814068141681426814368144681456814668147681486814968150681516815268153681546815568156681576815868159681606816168162681636816468165681666816768168681696817068171681726817368174681756817668177681786817968180681816818268183681846818568186681876818868189681906819168192681936819468195681966819768198681996820068201682026820368204682056820668207682086820968210682116821268213682146821568216682176821868219682206822168222682236822468225682266822768228682296823068231682326823368234682356823668237682386823968240682416824268243682446824568246682476824868249682506825168252682536825468255682566825768258682596826068261682626826368264682656826668267682686826968270682716827268273682746827568276682776827868279682806828168282682836828468285682866828768288682896829068291682926829368294682956829668297682986829968300683016830268303683046830568306683076830868309683106831168312683136831468315683166831768318683196832068321683226832368324683256832668327683286832968330683316833268333683346833568336683376833868339683406834168342683436834468345683466834768348683496835068351683526835368354683556835668357683586835968360683616836268363683646836568366683676836868369683706837168372683736837468375683766837768378683796838068381683826838368384683856838668387683886838968390683916839268393683946839568396683976839868399684006840168402684036840468405684066840768408684096841068411684126841368414684156841668417684186841968420684216842268423684246842568426684276842868429684306843168432684336843468435684366843768438684396844068441684426844368444684456844668447684486844968450684516845268453684546845568456684576845868459684606846168462684636846468465684666846768468684696847068471684726847368474684756847668477684786847968480684816848268483684846848568486684876848868489684906849168492684936849468495684966849768498684996850068501685026850368504685056850668507685086850968510685116851268513685146851568516685176851868519685206852168522685236852468525685266852768528685296853068531685326853368534685356853668537685386853968540685416854268543685446854568546685476854868549685506855168552685536855468555685566855768558685596856068561685626856368564685656856668567685686856968570685716857268573685746857568576685776857868579685806858168582685836858468585685866858768588685896859068591685926859368594685956859668597685986859968600686016860268603686046860568606686076860868609686106861168612686136861468615686166861768618686196862068621686226862368624686256862668627686286862968630686316863268633686346863568636686376863868639686406864168642686436864468645686466864768648686496865068651686526865368654686556865668657686586865968660686616866268663686646866568666686676866868669686706867168672686736867468675686766867768678686796868068681686826868368684686856868668687686886868968690686916869268693686946869568696686976869868699687006870168702687036870468705687066870768708687096871068711687126871368714687156871668717687186871968720687216872268723687246872568726687276872868729687306873168732687336873468735687366873768738687396874068741687426874368744687456874668747687486874968750687516875268753687546875568756687576875868759687606876168762687636876468765687666876768768687696877068771687726877368774687756877668777687786877968780687816878268783687846878568786687876878868789687906879168792687936879468795687966879768798687996880068801688026880368804688056880668807688086880968810688116881268813688146881568816688176881868819688206882168822688236882468825688266882768828688296883068831688326883368834688356883668837688386883968840688416884268843688446884568846688476884868849688506885168852688536885468855688566885768858688596886068861688626886368864688656886668867688686886968870688716887268873688746887568876688776887868879688806888168882688836888468885688866888768888688896889068891688926889368894688956889668897688986889968900689016890268903689046890568906689076890868909689106891168912689136891468915689166891768918689196892068921689226892368924689256892668927689286892968930689316893268933689346893568936689376893868939689406894168942689436894468945689466894768948689496895068951689526895368954689556895668957689586895968960689616896268963689646896568966689676896868969689706897168972689736897468975689766897768978689796898068981689826898368984689856898668987689886898968990689916899268993689946899568996689976899868999690006900169002690036900469005690066900769008690096901069011690126901369014690156901669017690186901969020690216902269023690246902569026690276902869029690306903169032690336903469035690366903769038690396904069041690426904369044690456904669047690486904969050690516905269053690546905569056690576905869059690606906169062690636906469065690666906769068690696907069071690726907369074690756907669077690786907969080690816908269083690846908569086690876908869089690906909169092690936909469095690966909769098690996910069101691026910369104691056910669107691086910969110691116911269113691146911569116691176911869119691206912169122691236912469125691266912769128691296913069131691326913369134691356913669137691386913969140691416914269143691446914569146691476914869149691506915169152691536915469155691566915769158691596916069161691626916369164691656916669167691686916969170691716917269173691746917569176691776917869179691806918169182691836918469185691866918769188691896919069191691926919369194691956919669197691986919969200692016920269203692046920569206692076920869209692106921169212692136921469215692166921769218692196922069221692226922369224692256922669227692286922969230692316923269233692346923569236692376923869239692406924169242692436924469245692466924769248692496925069251692526925369254692556925669257692586925969260692616926269263692646926569266692676926869269692706927169272692736927469275692766927769278692796928069281692826928369284692856928669287692886928969290692916929269293692946929569296692976929869299693006930169302693036930469305693066930769308693096931069311693126931369314693156931669317693186931969320693216932269323693246932569326693276932869329693306933169332693336933469335693366933769338693396934069341693426934369344693456934669347693486934969350693516935269353693546935569356693576935869359693606936169362693636936469365693666936769368693696937069371693726937369374693756937669377693786937969380693816938269383693846938569386693876938869389693906939169392693936939469395693966939769398693996940069401694026940369404694056940669407694086940969410694116941269413694146941569416694176941869419694206942169422694236942469425694266942769428694296943069431694326943369434694356943669437694386943969440694416944269443694446944569446694476944869449694506945169452694536945469455694566945769458694596946069461694626946369464694656946669467694686946969470694716947269473694746947569476694776947869479694806948169482694836948469485694866948769488694896949069491694926949369494694956949669497694986949969500695016950269503695046950569506695076950869509695106951169512695136951469515695166951769518695196952069521695226952369524695256952669527695286952969530695316953269533695346953569536695376953869539695406954169542695436954469545695466954769548695496955069551695526955369554695556955669557695586955969560695616956269563695646956569566695676956869569695706957169572695736957469575695766957769578695796958069581695826958369584695856958669587695886958969590695916959269593695946959569596695976959869599696006960169602696036960469605696066960769608696096961069611696126961369614696156961669617696186961969620696216962269623696246962569626696276962869629696306963169632696336963469635696366963769638696396964069641696426964369644696456964669647696486964969650696516965269653696546965569656696576965869659696606966169662696636966469665696666966769668696696967069671696726967369674696756967669677696786967969680696816968269683696846968569686696876968869689696906969169692696936969469695696966969769698696996970069701697026970369704697056970669707697086970969710697116971269713697146971569716697176971869719697206972169722697236972469725697266972769728697296973069731697326973369734697356973669737697386973969740697416974269743697446974569746697476974869749697506975169752697536975469755697566975769758697596976069761697626976369764697656976669767697686976969770697716977269773697746977569776697776977869779697806978169782697836978469785697866978769788697896979069791697926979369794697956979669797697986979969800698016980269803698046980569806698076980869809698106981169812698136981469815698166981769818698196982069821698226982369824698256982669827698286982969830698316983269833698346983569836698376983869839698406984169842698436984469845698466984769848698496985069851698526985369854698556985669857698586985969860698616986269863698646986569866698676986869869698706987169872698736987469875698766987769878698796988069881698826988369884698856988669887698886988969890698916989269893698946989569896698976989869899699006990169902699036990469905699066990769908699096991069911699126991369914699156991669917699186991969920699216992269923699246992569926699276992869929699306993169932699336993469935699366993769938699396994069941699426994369944699456994669947699486994969950699516995269953699546995569956699576995869959699606996169962699636996469965699666996769968699696997069971699726997369974699756997669977699786997969980699816998269983699846998569986699876998869989699906999169992699936999469995699966999769998699997000070001700027000370004700057000670007700087000970010700117001270013700147001570016700177001870019700207002170022700237002470025700267002770028700297003070031700327003370034700357003670037700387003970040700417004270043700447004570046700477004870049700507005170052700537005470055700567005770058700597006070061700627006370064700657006670067700687006970070700717007270073700747007570076700777007870079700807008170082700837008470085700867008770088700897009070091700927009370094700957009670097700987009970100701017010270103701047010570106701077010870109701107011170112701137011470115701167011770118701197012070121701227012370124701257012670127701287012970130701317013270133701347013570136701377013870139701407014170142701437014470145701467014770148701497015070151701527015370154701557015670157701587015970160701617016270163701647016570166701677016870169701707017170172701737017470175701767017770178701797018070181701827018370184701857018670187701887018970190701917019270193701947019570196701977019870199702007020170202702037020470205702067020770208702097021070211702127021370214702157021670217702187021970220702217022270223702247022570226702277022870229702307023170232702337023470235702367023770238702397024070241702427024370244702457024670247702487024970250702517025270253702547025570256702577025870259702607026170262702637026470265702667026770268702697027070271702727027370274702757027670277702787027970280702817028270283702847028570286702877028870289702907029170292702937029470295702967029770298702997030070301703027030370304703057030670307703087030970310703117031270313703147031570316703177031870319703207032170322703237032470325703267032770328703297033070331703327033370334703357033670337703387033970340703417034270343703447034570346703477034870349703507035170352703537035470355703567035770358703597036070361703627036370364703657036670367703687036970370703717037270373703747037570376703777037870379703807038170382703837038470385703867038770388703897039070391703927039370394703957039670397703987039970400704017040270403704047040570406704077040870409704107041170412704137041470415704167041770418704197042070421704227042370424704257042670427704287042970430704317043270433704347043570436704377043870439704407044170442704437044470445704467044770448704497045070451704527045370454704557045670457704587045970460704617046270463704647046570466704677046870469704707047170472704737047470475704767047770478704797048070481704827048370484704857048670487704887048970490704917049270493704947049570496704977049870499705007050170502705037050470505705067050770508705097051070511705127051370514705157051670517705187051970520705217052270523705247052570526705277052870529705307053170532705337053470535705367053770538705397054070541705427054370544705457054670547705487054970550705517055270553705547055570556705577055870559705607056170562705637056470565705667056770568705697057070571705727057370574705757057670577705787057970580705817058270583705847058570586705877058870589705907059170592705937059470595705967059770598705997060070601706027060370604706057060670607706087060970610706117061270613706147061570616706177061870619706207062170622706237062470625706267062770628706297063070631706327063370634706357063670637706387063970640706417064270643706447064570646706477064870649706507065170652706537065470655706567065770658706597066070661706627066370664706657066670667706687066970670706717067270673706747067570676706777067870679706807068170682706837068470685706867068770688706897069070691706927069370694706957069670697706987069970700707017070270703707047070570706707077070870709707107071170712707137071470715707167071770718707197072070721707227072370724707257072670727707287072970730707317073270733707347073570736707377073870739707407074170742707437074470745707467074770748707497075070751707527075370754707557075670757707587075970760707617076270763707647076570766707677076870769707707077170772707737077470775707767077770778707797078070781707827078370784707857078670787707887078970790707917079270793707947079570796707977079870799708007080170802708037080470805708067080770808708097081070811708127081370814708157081670817708187081970820708217082270823708247082570826708277082870829708307083170832708337083470835708367083770838708397084070841708427084370844708457084670847708487084970850708517085270853708547085570856708577085870859708607086170862708637086470865708667086770868708697087070871708727087370874708757087670877708787087970880708817088270883708847088570886708877088870889708907089170892708937089470895708967089770898708997090070901709027090370904709057090670907709087090970910709117091270913709147091570916709177091870919709207092170922709237092470925709267092770928709297093070931709327093370934709357093670937709387093970940709417094270943709447094570946709477094870949709507095170952709537095470955709567095770958709597096070961709627096370964709657096670967709687096970970709717097270973709747097570976709777097870979709807098170982709837098470985709867098770988709897099070991709927099370994709957099670997709987099971000710017100271003710047100571006710077100871009710107101171012710137101471015710167101771018710197102071021710227102371024710257102671027710287102971030710317103271033710347103571036710377103871039710407104171042710437104471045710467104771048710497105071051710527105371054710557105671057710587105971060710617106271063710647106571066710677106871069710707107171072710737107471075710767107771078710797108071081710827108371084710857108671087710887108971090710917109271093710947109571096710977109871099711007110171102711037110471105711067110771108711097111071111711127111371114711157111671117711187111971120711217112271123711247112571126711277112871129711307113171132711337113471135711367113771138711397114071141711427114371144711457114671147711487114971150711517115271153711547115571156711577115871159711607116171162711637116471165711667116771168711697117071171711727117371174711757117671177711787117971180711817118271183711847118571186711877118871189711907119171192711937119471195711967119771198711997120071201712027120371204712057120671207712087120971210712117121271213712147121571216712177121871219712207122171222712237122471225712267122771228712297123071231712327123371234712357123671237712387123971240712417124271243712447124571246712477124871249712507125171252712537125471255712567125771258712597126071261712627126371264712657126671267712687126971270712717127271273712747127571276712777127871279712807128171282712837128471285712867128771288712897129071291712927129371294712957129671297712987129971300713017130271303713047130571306713077130871309713107131171312713137131471315713167131771318713197132071321713227132371324713257132671327713287132971330713317133271333713347133571336713377133871339713407134171342713437134471345713467134771348713497135071351713527135371354713557135671357713587135971360713617136271363713647136571366713677136871369713707137171372713737137471375713767137771378713797138071381713827138371384713857138671387713887138971390713917139271393713947139571396713977139871399714007140171402714037140471405714067140771408714097141071411714127141371414714157141671417714187141971420714217142271423714247142571426714277142871429714307143171432714337143471435714367143771438714397144071441714427144371444714457144671447714487144971450714517145271453714547145571456714577145871459714607146171462714637146471465714667146771468714697147071471714727147371474714757147671477714787147971480714817148271483714847148571486714877148871489714907149171492714937149471495714967149771498714997150071501715027150371504715057150671507715087150971510715117151271513715147151571516715177151871519715207152171522715237152471525715267152771528715297153071531715327153371534715357153671537715387153971540715417154271543715447154571546715477154871549715507155171552715537155471555715567155771558715597156071561715627156371564715657156671567715687156971570715717157271573715747157571576715777157871579715807158171582715837158471585715867158771588715897159071591715927159371594715957159671597715987159971600716017160271603716047160571606716077160871609716107161171612716137161471615716167161771618716197162071621716227162371624716257162671627716287162971630716317163271633716347163571636716377163871639716407164171642716437164471645716467164771648716497165071651716527165371654716557165671657716587165971660716617166271663716647166571666716677166871669716707167171672716737167471675716767167771678716797168071681716827168371684716857168671687716887168971690716917169271693716947169571696716977169871699717007170171702717037170471705717067170771708717097171071711717127171371714717157171671717717187171971720717217172271723717247172571726717277172871729717307173171732717337173471735717367173771738717397174071741717427174371744717457174671747717487174971750717517175271753717547175571756717577175871759717607176171762717637176471765717667176771768717697177071771717727177371774717757177671777717787177971780717817178271783717847178571786717877178871789717907179171792717937179471795717967179771798717997180071801718027180371804718057180671807718087180971810718117181271813718147181571816718177181871819718207182171822718237182471825718267182771828718297183071831718327183371834718357183671837718387183971840718417184271843718447184571846718477184871849718507185171852718537185471855718567185771858718597186071861718627186371864718657186671867718687186971870718717187271873718747187571876718777187871879718807188171882718837188471885718867188771888718897189071891718927189371894718957189671897718987189971900719017190271903719047190571906719077190871909719107191171912719137191471915719167191771918719197192071921719227192371924719257192671927719287192971930719317193271933719347193571936719377193871939719407194171942719437194471945719467194771948719497195071951719527195371954719557195671957719587195971960719617196271963719647196571966719677196871969719707197171972719737197471975719767197771978719797198071981719827198371984719857198671987719887198971990719917199271993719947199571996719977199871999720007200172002720037200472005720067200772008720097201072011720127201372014720157201672017720187201972020720217202272023720247202572026720277202872029720307203172032720337203472035720367203772038720397204072041720427204372044720457204672047720487204972050720517205272053720547205572056720577205872059720607206172062720637206472065720667206772068720697207072071720727207372074720757207672077720787207972080720817208272083720847208572086720877208872089720907209172092720937209472095720967209772098720997210072101721027210372104721057210672107721087210972110721117211272113721147211572116721177211872119721207212172122721237212472125721267212772128721297213072131721327213372134721357213672137721387213972140721417214272143721447214572146721477214872149721507215172152721537215472155721567215772158721597216072161721627216372164721657216672167721687216972170721717217272173721747217572176721777217872179721807218172182721837218472185721867218772188721897219072191721927219372194721957219672197721987219972200722017220272203722047220572206722077220872209722107221172212722137221472215722167221772218722197222072221722227222372224722257222672227722287222972230722317223272233722347223572236722377223872239722407224172242722437224472245722467224772248722497225072251722527225372254722557225672257722587225972260722617226272263722647226572266722677226872269722707227172272722737227472275722767227772278722797228072281722827228372284722857228672287722887228972290722917229272293722947229572296722977229872299723007230172302723037230472305723067230772308723097231072311723127231372314723157231672317723187231972320723217232272323723247232572326723277232872329723307233172332723337233472335723367233772338723397234072341723427234372344723457234672347723487234972350723517235272353723547235572356723577235872359723607236172362723637236472365723667236772368723697237072371723727237372374723757237672377723787237972380723817238272383723847238572386723877238872389723907239172392723937239472395723967239772398723997240072401724027240372404724057240672407724087240972410724117241272413724147241572416724177241872419724207242172422724237242472425724267242772428724297243072431724327243372434724357243672437724387243972440724417244272443724447244572446724477244872449724507245172452724537245472455724567245772458724597246072461724627246372464724657246672467724687246972470724717247272473724747247572476724777247872479724807248172482724837248472485724867248772488724897249072491724927249372494724957249672497724987249972500725017250272503725047250572506725077250872509725107251172512725137251472515725167251772518725197252072521725227252372524725257252672527725287252972530725317253272533725347253572536725377253872539725407254172542725437254472545725467254772548725497255072551725527255372554725557255672557725587255972560725617256272563725647256572566725677256872569725707257172572725737257472575725767257772578725797258072581725827258372584725857258672587725887258972590725917259272593725947259572596725977259872599726007260172602726037260472605726067260772608726097261072611726127261372614726157261672617726187261972620726217262272623726247262572626726277262872629726307263172632726337263472635726367263772638726397264072641726427264372644726457264672647726487264972650726517265272653726547265572656726577265872659726607266172662726637266472665726667266772668726697267072671726727267372674726757267672677726787267972680726817268272683726847268572686726877268872689726907269172692726937269472695726967269772698726997270072701727027270372704727057270672707727087270972710727117271272713727147271572716727177271872719727207272172722727237272472725727267272772728727297273072731727327273372734727357273672737727387273972740727417274272743727447274572746727477274872749727507275172752727537275472755727567275772758727597276072761727627276372764727657276672767727687276972770727717277272773727747277572776727777277872779727807278172782727837278472785727867278772788727897279072791727927279372794727957279672797727987279972800728017280272803728047280572806728077280872809728107281172812728137281472815728167281772818728197282072821728227282372824728257282672827728287282972830728317283272833728347283572836728377283872839728407284172842728437284472845728467284772848728497285072851728527285372854728557285672857728587285972860728617286272863728647286572866728677286872869728707287172872728737287472875728767287772878728797288072881728827288372884728857288672887728887288972890728917289272893728947289572896728977289872899729007290172902729037290472905729067290772908729097291072911729127291372914729157291672917729187291972920729217292272923729247292572926729277292872929729307293172932729337293472935729367293772938729397294072941729427294372944729457294672947729487294972950729517295272953729547295572956729577295872959729607296172962729637296472965729667296772968729697297072971729727297372974729757297672977729787297972980729817298272983729847298572986729877298872989729907299172992729937299472995729967299772998729997300073001730027300373004730057300673007730087300973010730117301273013730147301573016730177301873019730207302173022730237302473025730267302773028730297303073031730327303373034730357303673037730387303973040730417304273043730447304573046730477304873049730507305173052730537305473055730567305773058730597306073061730627306373064730657306673067730687306973070730717307273073730747307573076730777307873079730807308173082730837308473085730867308773088730897309073091730927309373094730957309673097730987309973100731017310273103731047310573106731077310873109731107311173112731137311473115731167311773118731197312073121731227312373124731257312673127731287312973130731317313273133731347313573136731377313873139731407314173142731437314473145731467314773148731497315073151731527315373154731557315673157731587315973160731617316273163731647316573166731677316873169731707317173172731737317473175731767317773178731797318073181731827318373184731857318673187731887318973190731917319273193731947319573196731977319873199732007320173202732037320473205732067320773208732097321073211732127321373214732157321673217732187321973220732217322273223732247322573226732277322873229732307323173232732337323473235732367323773238732397324073241732427324373244732457324673247732487324973250732517325273253732547325573256732577325873259732607326173262732637326473265732667326773268732697327073271732727327373274732757327673277732787327973280732817328273283732847328573286732877328873289732907329173292732937329473295732967329773298732997330073301733027330373304733057330673307733087330973310733117331273313733147331573316733177331873319733207332173322733237332473325733267332773328733297333073331733327333373334733357333673337733387333973340733417334273343733447334573346733477334873349733507335173352733537335473355733567335773358733597336073361733627336373364733657336673367733687336973370733717337273373733747337573376733777337873379733807338173382733837338473385733867338773388733897339073391733927339373394733957339673397733987339973400734017340273403734047340573406734077340873409734107341173412734137341473415734167341773418734197342073421734227342373424734257342673427734287342973430734317343273433734347343573436734377343873439734407344173442734437344473445734467344773448734497345073451734527345373454734557345673457734587345973460734617346273463734647346573466734677346873469734707347173472734737347473475734767347773478734797348073481734827348373484734857348673487734887348973490734917349273493734947349573496734977349873499735007350173502735037350473505735067350773508735097351073511735127351373514735157351673517735187351973520735217352273523735247352573526735277352873529735307353173532735337353473535735367353773538735397354073541735427354373544735457354673547735487354973550735517355273553735547355573556735577355873559735607356173562735637356473565735667356773568735697357073571735727357373574735757357673577735787357973580735817358273583735847358573586735877358873589735907359173592735937359473595735967359773598735997360073601736027360373604736057360673607736087360973610736117361273613736147361573616736177361873619736207362173622736237362473625736267362773628736297363073631736327363373634736357363673637736387363973640736417364273643736447364573646736477364873649736507365173652736537365473655736567365773658736597366073661736627366373664736657366673667736687366973670736717367273673736747367573676736777367873679736807368173682736837368473685736867368773688736897369073691736927369373694736957369673697736987369973700737017370273703737047370573706737077370873709737107371173712737137371473715737167371773718737197372073721737227372373724737257372673727737287372973730737317373273733737347373573736737377373873739737407374173742737437374473745737467374773748737497375073751737527375373754737557375673757737587375973760737617376273763737647376573766737677376873769737707377173772737737377473775737767377773778737797378073781737827378373784737857378673787737887378973790737917379273793737947379573796737977379873799738007380173802738037380473805738067380773808738097381073811738127381373814738157381673817738187381973820738217382273823738247382573826738277382873829738307383173832738337383473835738367383773838738397384073841738427384373844738457384673847738487384973850738517385273853738547385573856738577385873859738607386173862738637386473865738667386773868738697387073871738727387373874738757387673877738787387973880738817388273883738847388573886738877388873889738907389173892738937389473895738967389773898738997390073901739027390373904739057390673907739087390973910739117391273913739147391573916739177391873919739207392173922739237392473925739267392773928739297393073931739327393373934739357393673937739387393973940739417394273943739447394573946739477394873949739507395173952739537395473955739567395773958739597396073961739627396373964739657396673967739687396973970739717397273973739747397573976739777397873979739807398173982739837398473985739867398773988739897399073991739927399373994739957399673997739987399974000740017400274003740047400574006740077400874009740107401174012740137401474015740167401774018740197402074021740227402374024740257402674027740287402974030740317403274033740347403574036740377403874039740407404174042740437404474045740467404774048740497405074051740527405374054740557405674057740587405974060740617406274063740647406574066740677406874069740707407174072740737407474075740767407774078740797408074081740827408374084740857408674087740887408974090740917409274093740947409574096740977409874099741007410174102741037410474105741067410774108741097411074111741127411374114741157411674117741187411974120741217412274123741247412574126741277412874129741307413174132741337413474135741367413774138741397414074141741427414374144741457414674147741487414974150741517415274153741547415574156741577415874159741607416174162741637416474165741667416774168741697417074171741727417374174741757417674177741787417974180741817418274183741847418574186741877418874189741907419174192741937419474195741967419774198741997420074201742027420374204742057420674207742087420974210742117421274213742147421574216742177421874219742207422174222742237422474225742267422774228742297423074231742327423374234742357423674237742387423974240742417424274243742447424574246742477424874249742507425174252742537425474255742567425774258742597426074261742627426374264742657426674267742687426974270742717427274273742747427574276742777427874279742807428174282742837428474285742867428774288742897429074291742927429374294742957429674297742987429974300743017430274303743047430574306743077430874309743107431174312743137431474315743167431774318743197432074321743227432374324743257432674327743287432974330743317433274333743347433574336743377433874339743407434174342743437434474345743467434774348743497435074351743527435374354743557435674357743587435974360743617436274363743647436574366743677436874369743707437174372743737437474375743767437774378743797438074381743827438374384743857438674387743887438974390743917439274393743947439574396743977439874399744007440174402744037440474405744067440774408744097441074411744127441374414744157441674417744187441974420744217442274423744247442574426744277442874429744307443174432744337443474435744367443774438744397444074441744427444374444744457444674447744487444974450744517445274453744547445574456744577445874459744607446174462744637446474465744667446774468744697447074471744727447374474744757447674477744787447974480744817448274483744847448574486744877448874489744907449174492744937449474495744967449774498744997450074501745027450374504745057450674507745087450974510745117451274513745147451574516745177451874519745207452174522745237452474525745267452774528745297453074531745327453374534745357453674537745387453974540745417454274543745447454574546745477454874549745507455174552745537455474555745567455774558745597456074561745627456374564745657456674567745687456974570745717457274573745747457574576745777457874579745807458174582745837458474585745867458774588745897459074591745927459374594745957459674597745987459974600746017460274603746047460574606746077460874609746107461174612746137461474615746167461774618746197462074621746227462374624746257462674627746287462974630746317463274633746347463574636746377463874639746407464174642746437464474645746467464774648746497465074651746527465374654746557465674657746587465974660746617466274663746647466574666746677466874669746707467174672746737467474675746767467774678746797468074681746827468374684746857468674687746887468974690746917469274693746947469574696746977469874699747007470174702747037470474705747067470774708747097471074711747127471374714747157471674717747187471974720747217472274723747247472574726747277472874729747307473174732747337473474735747367473774738747397474074741747427474374744747457474674747747487474974750747517475274753747547475574756747577475874759747607476174762747637476474765747667476774768747697477074771747727477374774747757477674777747787477974780747817478274783747847478574786747877478874789747907479174792747937479474795747967479774798747997480074801748027480374804748057480674807748087480974810748117481274813748147481574816748177481874819748207482174822748237482474825748267482774828748297483074831748327483374834748357483674837748387483974840748417484274843748447484574846748477484874849748507485174852748537485474855748567485774858748597486074861748627486374864748657486674867748687486974870748717487274873748747487574876748777487874879748807488174882748837488474885748867488774888748897489074891748927489374894748957489674897748987489974900749017490274903749047490574906749077490874909749107491174912749137491474915749167491774918749197492074921749227492374924749257492674927749287492974930749317493274933749347493574936749377493874939749407494174942749437494474945749467494774948749497495074951749527495374954749557495674957749587495974960749617496274963749647496574966749677496874969749707497174972749737497474975749767497774978749797498074981749827498374984749857498674987749887498974990749917499274993749947499574996749977499874999750007500175002750037500475005750067500775008750097501075011750127501375014750157501675017750187501975020750217502275023750247502575026750277502875029750307503175032750337503475035750367503775038750397504075041750427504375044750457504675047750487504975050750517505275053750547505575056750577505875059750607506175062750637506475065750667506775068750697507075071750727507375074750757507675077750787507975080750817508275083750847508575086750877508875089750907509175092750937509475095750967509775098750997510075101751027510375104751057510675107751087510975110751117511275113751147511575116751177511875119751207512175122751237512475125751267512775128751297513075131751327513375134751357513675137751387513975140751417514275143751447514575146751477514875149751507515175152751537515475155751567515775158751597516075161751627516375164751657516675167751687516975170751717517275173751747517575176751777517875179751807518175182751837518475185751867518775188751897519075191751927519375194751957519675197751987519975200752017520275203752047520575206752077520875209752107521175212752137521475215752167521775218752197522075221752227522375224752257522675227752287522975230752317523275233752347523575236752377523875239752407524175242752437524475245752467524775248752497525075251752527525375254752557525675257752587525975260752617526275263752647526575266752677526875269752707527175272752737527475275752767527775278752797528075281752827528375284752857528675287752887528975290752917529275293752947529575296752977529875299753007530175302753037530475305753067530775308753097531075311753127531375314753157531675317753187531975320753217532275323753247532575326753277532875329753307533175332753337533475335753367533775338753397534075341753427534375344753457534675347753487534975350753517535275353753547535575356753577535875359753607536175362753637536475365753667536775368753697537075371753727537375374753757537675377753787537975380753817538275383753847538575386753877538875389753907539175392753937539475395753967539775398753997540075401754027540375404754057540675407754087540975410754117541275413754147541575416754177541875419754207542175422754237542475425754267542775428754297543075431754327543375434754357543675437754387543975440754417544275443754447544575446754477544875449754507545175452754537545475455754567545775458754597546075461754627546375464754657546675467754687546975470754717547275473754747547575476754777547875479754807548175482754837548475485754867548775488754897549075491754927549375494754957549675497754987549975500755017550275503755047550575506755077550875509755107551175512755137551475515755167551775518755197552075521755227552375524755257552675527755287552975530755317553275533755347553575536755377553875539755407554175542755437554475545755467554775548755497555075551755527555375554755557555675557755587555975560755617556275563755647556575566755677556875569755707557175572755737557475575755767557775578755797558075581755827558375584755857558675587755887558975590755917559275593755947559575596755977559875599756007560175602756037560475605756067560775608756097561075611756127561375614756157561675617756187561975620756217562275623756247562575626756277562875629756307563175632756337563475635756367563775638756397564075641756427564375644756457564675647756487564975650756517565275653756547565575656756577565875659756607566175662756637566475665756667566775668756697567075671756727567375674756757567675677756787567975680756817568275683756847568575686756877568875689756907569175692756937569475695756967569775698756997570075701757027570375704757057570675707757087570975710757117571275713757147571575716757177571875719757207572175722757237572475725757267572775728757297573075731757327573375734757357573675737757387573975740757417574275743757447574575746757477574875749757507575175752757537575475755757567575775758757597576075761757627576375764757657576675767757687576975770757717577275773757747577575776757777577875779757807578175782757837578475785757867578775788757897579075791757927579375794757957579675797757987579975800758017580275803758047580575806758077580875809758107581175812758137581475815758167581775818758197582075821758227582375824758257582675827758287582975830758317583275833758347583575836758377583875839758407584175842758437584475845758467584775848758497585075851758527585375854758557585675857758587585975860758617586275863758647586575866758677586875869758707587175872758737587475875758767587775878758797588075881758827588375884758857588675887758887588975890758917589275893758947589575896758977589875899759007590175902759037590475905759067590775908759097591075911759127591375914759157591675917759187591975920759217592275923759247592575926759277592875929759307593175932759337593475935759367593775938759397594075941759427594375944759457594675947759487594975950759517595275953759547595575956759577595875959759607596175962759637596475965759667596775968759697597075971759727597375974759757597675977759787597975980759817598275983759847598575986759877598875989759907599175992759937599475995759967599775998759997600076001760027600376004760057600676007760087600976010760117601276013760147601576016760177601876019760207602176022760237602476025760267602776028760297603076031760327603376034760357603676037760387603976040760417604276043760447604576046760477604876049760507605176052760537605476055760567605776058760597606076061760627606376064760657606676067760687606976070760717607276073760747607576076760777607876079760807608176082760837608476085760867608776088760897609076091760927609376094760957609676097760987609976100761017610276103761047610576106761077610876109761107611176112761137611476115761167611776118761197612076121761227612376124761257612676127761287612976130761317613276133761347613576136761377613876139761407614176142761437614476145761467614776148761497615076151761527615376154761557615676157761587615976160761617616276163761647616576166761677616876169761707617176172761737617476175761767617776178761797618076181761827618376184761857618676187761887618976190761917619276193761947619576196761977619876199762007620176202762037620476205762067620776208762097621076211762127621376214762157621676217762187621976220762217622276223762247622576226762277622876229762307623176232762337623476235762367623776238762397624076241762427624376244762457624676247762487624976250762517625276253762547625576256762577625876259762607626176262762637626476265762667626776268762697627076271762727627376274762757627676277762787627976280762817628276283762847628576286762877628876289762907629176292762937629476295762967629776298762997630076301763027630376304763057630676307763087630976310763117631276313763147631576316763177631876319763207632176322763237632476325763267632776328763297633076331763327633376334763357633676337763387633976340763417634276343763447634576346763477634876349763507635176352763537635476355763567635776358763597636076361763627636376364763657636676367763687636976370763717637276373763747637576376763777637876379763807638176382763837638476385763867638776388763897639076391763927639376394763957639676397763987639976400764017640276403764047640576406764077640876409764107641176412764137641476415764167641776418764197642076421764227642376424764257642676427764287642976430764317643276433764347643576436764377643876439764407644176442764437644476445764467644776448764497645076451764527645376454764557645676457764587645976460764617646276463764647646576466764677646876469764707647176472764737647476475764767647776478764797648076481764827648376484764857648676487764887648976490764917649276493764947649576496764977649876499765007650176502765037650476505765067650776508765097651076511765127651376514765157651676517765187651976520765217652276523765247652576526765277652876529765307653176532765337653476535765367653776538765397654076541765427654376544765457654676547765487654976550765517655276553765547655576556765577655876559765607656176562765637656476565765667656776568765697657076571765727657376574765757657676577765787657976580765817658276583765847658576586765877658876589765907659176592765937659476595765967659776598765997660076601766027660376604766057660676607766087660976610766117661276613766147661576616766177661876619766207662176622766237662476625766267662776628766297663076631766327663376634766357663676637766387663976640766417664276643766447664576646766477664876649766507665176652766537665476655766567665776658766597666076661766627666376664766657666676667766687666976670766717667276673766747667576676766777667876679766807668176682766837668476685766867668776688766897669076691766927669376694766957669676697766987669976700767017670276703767047670576706767077670876709767107671176712767137671476715767167671776718767197672076721767227672376724767257672676727767287672976730767317673276733767347673576736767377673876739767407674176742767437674476745767467674776748767497675076751767527675376754767557675676757767587675976760767617676276763767647676576766767677676876769767707677176772767737677476775767767677776778767797678076781767827678376784767857678676787767887678976790767917679276793767947679576796767977679876799768007680176802768037680476805768067680776808768097681076811768127681376814768157681676817768187681976820768217682276823768247682576826768277682876829768307683176832768337683476835768367683776838768397684076841768427684376844768457684676847768487684976850768517685276853768547685576856768577685876859768607686176862768637686476865768667686776868768697687076871768727687376874768757687676877768787687976880768817688276883768847688576886768877688876889768907689176892768937689476895768967689776898768997690076901769027690376904769057690676907769087690976910769117691276913769147691576916769177691876919769207692176922769237692476925769267692776928769297693076931769327693376934769357693676937769387693976940769417694276943769447694576946769477694876949769507695176952769537695476955769567695776958769597696076961769627696376964769657696676967769687696976970769717697276973769747697576976769777697876979769807698176982769837698476985769867698776988769897699076991769927699376994769957699676997769987699977000770017700277003770047700577006770077700877009770107701177012770137701477015770167701777018770197702077021770227702377024770257702677027770287702977030770317703277033770347703577036770377703877039770407704177042770437704477045770467704777048770497705077051770527705377054770557705677057770587705977060770617706277063770647706577066770677706877069770707707177072770737707477075770767707777078770797708077081770827708377084770857708677087770887708977090770917709277093770947709577096770977709877099771007710177102771037710477105771067710777108771097711077111771127711377114771157711677117771187711977120771217712277123771247712577126771277712877129771307713177132771337713477135771367713777138771397714077141771427714377144771457714677147771487714977150771517715277153771547715577156771577715877159771607716177162771637716477165771667716777168771697717077171771727717377174771757717677177771787717977180771817718277183771847718577186771877718877189771907719177192771937719477195771967719777198771997720077201772027720377204772057720677207772087720977210772117721277213772147721577216772177721877219772207722177222772237722477225772267722777228772297723077231772327723377234772357723677237772387723977240772417724277243772447724577246772477724877249772507725177252772537725477255772567725777258772597726077261772627726377264772657726677267772687726977270772717727277273772747727577276772777727877279772807728177282772837728477285772867728777288772897729077291772927729377294772957729677297772987729977300773017730277303773047730577306773077730877309773107731177312773137731477315773167731777318773197732077321773227732377324773257732677327773287732977330773317733277333773347733577336773377733877339773407734177342773437734477345773467734777348773497735077351773527735377354773557735677357773587735977360773617736277363773647736577366773677736877369773707737177372773737737477375773767737777378773797738077381773827738377384773857738677387773887738977390773917739277393773947739577396773977739877399774007740177402774037740477405774067740777408774097741077411774127741377414774157741677417774187741977420774217742277423774247742577426774277742877429774307743177432774337743477435774367743777438774397744077441774427744377444774457744677447774487744977450774517745277453774547745577456774577745877459774607746177462774637746477465774667746777468774697747077471774727747377474774757747677477774787747977480774817748277483774847748577486774877748877489774907749177492774937749477495774967749777498774997750077501775027750377504775057750677507775087750977510775117751277513775147751577516775177751877519775207752177522775237752477525775267752777528775297753077531775327753377534775357753677537775387753977540775417754277543775447754577546775477754877549775507755177552775537755477555775567755777558775597756077561775627756377564775657756677567775687756977570775717757277573775747757577576775777757877579775807758177582775837758477585775867758777588775897759077591775927759377594775957759677597775987759977600776017760277603776047760577606776077760877609776107761177612776137761477615776167761777618776197762077621776227762377624776257762677627776287762977630776317763277633776347763577636776377763877639776407764177642776437764477645776467764777648776497765077651776527765377654776557765677657776587765977660776617766277663776647766577666776677766877669776707767177672776737767477675776767767777678776797768077681776827768377684776857768677687776887768977690776917769277693776947769577696776977769877699777007770177702777037770477705777067770777708777097771077711777127771377714777157771677717777187771977720777217772277723777247772577726777277772877729777307773177732777337773477735777367773777738777397774077741777427774377744777457774677747777487774977750777517775277753777547775577756777577775877759777607776177762777637776477765777667776777768777697777077771777727777377774777757777677777777787777977780777817778277783777847778577786777877778877789777907779177792777937779477795777967779777798777997780077801778027780377804778057780677807778087780977810778117781277813778147781577816778177781877819778207782177822778237782477825778267782777828778297783077831778327783377834778357783677837778387783977840778417784277843778447784577846778477784877849778507785177852778537785477855778567785777858778597786077861778627786377864778657786677867778687786977870778717787277873778747787577876778777787877879778807788177882778837788477885778867788777888778897789077891778927789377894778957789677897778987789977900779017790277903779047790577906779077790877909779107791177912779137791477915779167791777918779197792077921779227792377924779257792677927779287792977930779317793277933779347793577936779377793877939779407794177942779437794477945779467794777948779497795077951779527795377954779557795677957779587795977960779617796277963779647796577966779677796877969779707797177972779737797477975779767797777978779797798077981779827798377984779857798677987779887798977990779917799277993779947799577996779977799877999780007800178002780037800478005780067800778008780097801078011780127801378014780157801678017780187801978020780217802278023780247802578026780277802878029780307803178032780337803478035780367803778038780397804078041780427804378044780457804678047780487804978050780517805278053780547805578056780577805878059780607806178062780637806478065780667806778068780697807078071780727807378074780757807678077780787807978080780817808278083780847808578086780877808878089780907809178092780937809478095780967809778098780997810078101781027810378104781057810678107781087810978110781117811278113781147811578116781177811878119781207812178122781237812478125781267812778128781297813078131781327813378134781357813678137781387813978140781417814278143781447814578146781477814878149781507815178152781537815478155781567815778158781597816078161781627816378164781657816678167781687816978170781717817278173781747817578176781777817878179781807818178182781837818478185781867818778188781897819078191781927819378194781957819678197781987819978200782017820278203782047820578206782077820878209782107821178212782137821478215782167821778218782197822078221782227822378224782257822678227782287822978230782317823278233782347823578236782377823878239782407824178242782437824478245782467824778248782497825078251782527825378254782557825678257782587825978260782617826278263782647826578266782677826878269782707827178272782737827478275782767827778278782797828078281782827828378284782857828678287782887828978290782917829278293782947829578296782977829878299783007830178302783037830478305783067830778308783097831078311783127831378314783157831678317783187831978320783217832278323783247832578326783277832878329783307833178332783337833478335783367833778338783397834078341783427834378344783457834678347783487834978350783517835278353783547835578356783577835878359783607836178362783637836478365783667836778368783697837078371783727837378374783757837678377783787837978380783817838278383783847838578386783877838878389783907839178392783937839478395783967839778398783997840078401784027840378404784057840678407784087840978410784117841278413784147841578416784177841878419784207842178422784237842478425784267842778428784297843078431784327843378434784357843678437784387843978440784417844278443784447844578446784477844878449784507845178452784537845478455784567845778458784597846078461784627846378464784657846678467784687846978470784717847278473784747847578476784777847878479784807848178482784837848478485784867848778488784897849078491784927849378494784957849678497784987849978500785017850278503785047850578506785077850878509785107851178512785137851478515785167851778518785197852078521785227852378524785257852678527785287852978530785317853278533785347853578536785377853878539785407854178542785437854478545785467854778548785497855078551785527855378554785557855678557785587855978560785617856278563785647856578566785677856878569785707857178572785737857478575785767857778578785797858078581785827858378584785857858678587785887858978590785917859278593785947859578596785977859878599786007860178602786037860478605786067860778608786097861078611786127861378614786157861678617786187861978620786217862278623786247862578626786277862878629786307863178632786337863478635786367863778638786397864078641786427864378644786457864678647786487864978650786517865278653786547865578656786577865878659786607866178662786637866478665786667866778668786697867078671786727867378674786757867678677786787867978680786817868278683786847868578686786877868878689786907869178692786937869478695786967869778698786997870078701787027870378704787057870678707787087870978710787117871278713787147871578716787177871878719787207872178722787237872478725787267872778728787297873078731787327873378734787357873678737787387873978740787417874278743787447874578746787477874878749787507875178752787537875478755787567875778758787597876078761787627876378764787657876678767787687876978770787717877278773787747877578776787777877878779787807878178782787837878478785787867878778788787897879078791787927879378794787957879678797787987879978800788017880278803788047880578806788077880878809788107881178812788137881478815788167881778818788197882078821788227882378824788257882678827788287882978830788317883278833788347883578836788377883878839788407884178842788437884478845788467884778848788497885078851788527885378854788557885678857788587885978860788617886278863788647886578866788677886878869788707887178872788737887478875788767887778878788797888078881788827888378884788857888678887788887888978890788917889278893788947889578896788977889878899789007890178902789037890478905789067890778908789097891078911789127891378914789157891678917789187891978920789217892278923789247892578926789277892878929789307893178932789337893478935789367893778938789397894078941789427894378944789457894678947789487894978950789517895278953789547895578956789577895878959789607896178962789637896478965789667896778968789697897078971789727897378974789757897678977789787897978980789817898278983789847898578986789877898878989789907899178992789937899478995789967899778998789997900079001790027900379004790057900679007790087900979010790117901279013790147901579016790177901879019790207902179022790237902479025790267902779028790297903079031790327903379034790357903679037790387903979040790417904279043790447904579046790477904879049790507905179052790537905479055790567905779058790597906079061790627906379064790657906679067790687906979070790717907279073790747907579076790777907879079790807908179082790837908479085790867908779088790897909079091790927909379094790957909679097790987909979100791017910279103791047910579106791077910879109791107911179112791137911479115791167911779118791197912079121791227912379124791257912679127791287912979130791317913279133791347913579136791377913879139791407914179142791437914479145791467914779148791497915079151791527915379154791557915679157791587915979160791617916279163791647916579166791677916879169791707917179172791737917479175791767917779178791797918079181791827918379184791857918679187791887918979190791917919279193791947919579196791977919879199792007920179202792037920479205792067920779208792097921079211792127921379214792157921679217792187921979220792217922279223792247922579226792277922879229792307923179232792337923479235792367923779238792397924079241792427924379244792457924679247792487924979250792517925279253792547925579256792577925879259792607926179262792637926479265792667926779268792697927079271792727927379274792757927679277792787927979280792817928279283792847928579286792877928879289792907929179292792937929479295792967929779298792997930079301793027930379304793057930679307793087930979310793117931279313793147931579316793177931879319793207932179322793237932479325793267932779328793297933079331793327933379334793357933679337793387933979340793417934279343793447934579346793477934879349793507935179352793537935479355793567935779358793597936079361793627936379364793657936679367793687936979370793717937279373793747937579376793777937879379793807938179382793837938479385793867938779388793897939079391793927939379394793957939679397793987939979400794017940279403794047940579406794077940879409794107941179412794137941479415794167941779418794197942079421794227942379424794257942679427794287942979430794317943279433794347943579436794377943879439794407944179442794437944479445794467944779448794497945079451794527945379454794557945679457794587945979460794617946279463794647946579466794677946879469794707947179472794737947479475794767947779478794797948079481794827948379484794857948679487794887948979490794917949279493794947949579496794977949879499795007950179502795037950479505795067950779508795097951079511795127951379514795157951679517795187951979520795217952279523795247952579526795277952879529795307953179532795337953479535795367953779538795397954079541795427954379544795457954679547795487954979550795517955279553795547955579556795577955879559795607956179562795637956479565795667956779568795697957079571795727957379574795757957679577795787957979580795817958279583795847958579586795877958879589795907959179592795937959479595795967959779598795997960079601796027960379604796057960679607796087960979610796117961279613796147961579616796177961879619796207962179622796237962479625796267962779628796297963079631796327963379634796357963679637796387963979640796417964279643796447964579646796477964879649796507965179652796537965479655796567965779658796597966079661796627966379664796657966679667796687966979670796717967279673796747967579676796777967879679796807968179682796837968479685796867968779688796897969079691796927969379694796957969679697796987969979700797017970279703797047970579706797077970879709797107971179712797137971479715797167971779718797197972079721797227972379724797257972679727797287972979730797317973279733797347973579736797377973879739797407974179742797437974479745797467974779748797497975079751797527975379754797557975679757797587975979760797617976279763797647976579766797677976879769797707977179772797737977479775797767977779778797797978079781797827978379784797857978679787797887978979790797917979279793797947979579796797977979879799798007980179802798037980479805798067980779808798097981079811798127981379814798157981679817798187981979820798217982279823798247982579826798277982879829798307983179832798337983479835798367983779838798397984079841798427984379844798457984679847798487984979850798517985279853798547985579856798577985879859798607986179862798637986479865798667986779868798697987079871798727987379874798757987679877798787987979880798817988279883798847988579886798877988879889798907989179892798937989479895798967989779898798997990079901799027990379904799057990679907799087990979910799117991279913799147991579916799177991879919799207992179922799237992479925799267992779928799297993079931799327993379934799357993679937799387993979940799417994279943799447994579946799477994879949799507995179952799537995479955799567995779958799597996079961799627996379964799657996679967799687996979970799717997279973799747997579976799777997879979799807998179982799837998479985799867998779988799897999079991799927999379994799957999679997799987999980000800018000280003800048000580006800078000880009800108001180012800138001480015800168001780018800198002080021800228002380024800258002680027800288002980030800318003280033800348003580036800378003880039800408004180042800438004480045800468004780048800498005080051800528005380054800558005680057800588005980060800618006280063800648006580066800678006880069800708007180072800738007480075800768007780078800798008080081800828008380084800858008680087800888008980090800918009280093800948009580096800978009880099801008010180102801038010480105801068010780108801098011080111801128011380114801158011680117801188011980120801218012280123801248012580126801278012880129801308013180132801338013480135801368013780138801398014080141801428014380144801458014680147801488014980150801518015280153801548015580156801578015880159801608016180162801638016480165801668016780168801698017080171801728017380174801758017680177801788017980180801818018280183801848018580186801878018880189801908019180192801938019480195801968019780198801998020080201802028020380204802058020680207802088020980210802118021280213802148021580216802178021880219802208022180222802238022480225802268022780228802298023080231802328023380234802358023680237802388023980240802418024280243802448024580246802478024880249802508025180252802538025480255802568025780258802598026080261802628026380264802658026680267802688026980270802718027280273802748027580276802778027880279802808028180282802838028480285802868028780288802898029080291802928029380294802958029680297802988029980300803018030280303803048030580306803078030880309803108031180312803138031480315803168031780318803198032080321803228032380324803258032680327803288032980330803318033280333803348033580336803378033880339803408034180342803438034480345803468034780348803498035080351803528035380354803558035680357803588035980360803618036280363803648036580366803678036880369803708037180372803738037480375803768037780378803798038080381803828038380384803858038680387803888038980390803918039280393803948039580396803978039880399804008040180402804038040480405804068040780408804098041080411804128041380414804158041680417804188041980420804218042280423804248042580426804278042880429804308043180432804338043480435804368043780438804398044080441804428044380444804458044680447804488044980450804518045280453804548045580456804578045880459804608046180462804638046480465804668046780468804698047080471804728047380474804758047680477804788047980480804818048280483804848048580486804878048880489804908049180492804938049480495804968049780498804998050080501805028050380504805058050680507805088050980510805118051280513805148051580516805178051880519805208052180522805238052480525805268052780528805298053080531805328053380534805358053680537805388053980540805418054280543805448054580546805478054880549805508055180552805538055480555805568055780558805598056080561805628056380564805658056680567805688056980570805718057280573805748057580576805778057880579805808058180582805838058480585805868058780588805898059080591805928059380594805958059680597805988059980600806018060280603806048060580606806078060880609806108061180612806138061480615806168061780618806198062080621806228062380624806258062680627806288062980630806318063280633806348063580636806378063880639806408064180642806438064480645806468064780648806498065080651806528065380654806558065680657806588065980660806618066280663806648066580666806678066880669806708067180672806738067480675806768067780678806798068080681806828068380684806858068680687806888068980690806918069280693806948069580696806978069880699807008070180702807038070480705807068070780708807098071080711807128071380714807158071680717807188071980720807218072280723807248072580726807278072880729807308073180732807338073480735807368073780738807398074080741807428074380744807458074680747807488074980750807518075280753807548075580756807578075880759807608076180762807638076480765807668076780768807698077080771807728077380774807758077680777807788077980780807818078280783807848078580786807878078880789807908079180792807938079480795807968079780798807998080080801808028080380804808058080680807808088080980810808118081280813808148081580816808178081880819808208082180822808238082480825808268082780828808298083080831808328083380834808358083680837808388083980840808418084280843808448084580846808478084880849808508085180852808538085480855808568085780858808598086080861808628086380864808658086680867808688086980870808718087280873808748087580876808778087880879808808088180882808838088480885808868088780888808898089080891808928089380894808958089680897808988089980900809018090280903809048090580906809078090880909809108091180912809138091480915809168091780918809198092080921809228092380924809258092680927809288092980930809318093280933809348093580936809378093880939809408094180942809438094480945809468094780948809498095080951809528095380954809558095680957809588095980960809618096280963809648096580966809678096880969809708097180972809738097480975809768097780978809798098080981809828098380984809858098680987809888098980990809918099280993809948099580996809978099880999810008100181002810038100481005810068100781008810098101081011810128101381014810158101681017810188101981020810218102281023810248102581026810278102881029810308103181032810338103481035810368103781038810398104081041810428104381044810458104681047810488104981050810518105281053810548105581056810578105881059810608106181062810638106481065810668106781068810698107081071810728107381074810758107681077810788107981080810818108281083810848108581086810878108881089810908109181092810938109481095810968109781098810998110081101811028110381104811058110681107811088110981110811118111281113811148111581116811178111881119811208112181122811238112481125811268112781128811298113081131811328113381134811358113681137811388113981140811418114281143811448114581146811478114881149811508115181152811538115481155811568115781158811598116081161811628116381164811658116681167811688116981170811718117281173811748117581176811778117881179811808118181182811838118481185811868118781188811898119081191811928119381194811958119681197811988119981200812018120281203812048120581206812078120881209812108121181212812138121481215812168121781218812198122081221812228122381224812258122681227812288122981230812318123281233812348123581236812378123881239812408124181242812438124481245812468124781248812498125081251812528125381254812558125681257812588125981260812618126281263812648126581266812678126881269812708127181272812738127481275812768127781278812798128081281812828128381284812858128681287812888128981290812918129281293812948129581296812978129881299813008130181302813038130481305813068130781308813098131081311813128131381314813158131681317813188131981320813218132281323813248132581326813278132881329813308133181332813338133481335813368133781338813398134081341813428134381344813458134681347813488134981350813518135281353813548135581356813578135881359813608136181362813638136481365813668136781368813698137081371813728137381374813758137681377813788137981380813818138281383813848138581386813878138881389813908139181392813938139481395813968139781398813998140081401814028140381404814058140681407814088140981410814118141281413814148141581416814178141881419814208142181422814238142481425814268142781428814298143081431814328143381434814358143681437814388143981440814418144281443814448144581446814478144881449814508145181452814538145481455814568145781458814598146081461814628146381464814658146681467814688146981470814718147281473814748147581476814778147881479814808148181482814838148481485814868148781488814898149081491814928149381494814958149681497814988149981500815018150281503815048150581506815078150881509815108151181512815138151481515815168151781518815198152081521815228152381524815258152681527815288152981530815318153281533815348153581536815378153881539815408154181542815438154481545815468154781548815498155081551815528155381554815558155681557815588155981560815618156281563815648156581566815678156881569815708157181572815738157481575815768157781578815798158081581815828158381584815858158681587815888158981590815918159281593815948159581596815978159881599816008160181602816038160481605816068160781608816098161081611816128161381614816158161681617816188161981620816218162281623816248162581626816278162881629816308163181632816338163481635816368163781638816398164081641816428164381644816458164681647816488164981650816518165281653816548165581656816578165881659816608166181662816638166481665816668166781668816698167081671816728167381674816758167681677816788167981680816818168281683816848168581686816878168881689816908169181692816938169481695816968169781698816998170081701817028170381704817058170681707817088170981710817118171281713817148171581716817178171881719817208172181722817238172481725817268172781728817298173081731817328173381734817358173681737817388173981740817418174281743817448174581746817478174881749817508175181752817538175481755817568175781758817598176081761817628176381764817658176681767817688176981770817718177281773817748177581776817778177881779817808178181782817838178481785817868178781788817898179081791817928179381794817958179681797817988179981800818018180281803818048180581806818078180881809818108181181812818138181481815818168181781818818198182081821818228182381824818258182681827818288182981830818318183281833818348183581836818378183881839818408184181842818438184481845818468184781848818498185081851818528185381854818558185681857818588185981860818618186281863818648186581866818678186881869818708187181872818738187481875818768187781878818798188081881818828188381884818858188681887818888188981890818918189281893818948189581896818978189881899819008190181902819038190481905819068190781908819098191081911819128191381914819158191681917819188191981920819218192281923819248192581926819278192881929819308193181932819338193481935819368193781938819398194081941819428194381944819458194681947819488194981950819518195281953819548195581956819578195881959819608196181962819638196481965819668196781968819698197081971819728197381974819758197681977819788197981980819818198281983819848198581986819878198881989819908199181992819938199481995819968199781998819998200082001820028200382004820058200682007820088200982010820118201282013820148201582016820178201882019820208202182022820238202482025820268202782028820298203082031820328203382034820358203682037820388203982040820418204282043820448204582046820478204882049820508205182052820538205482055820568205782058820598206082061820628206382064820658206682067820688206982070820718207282073820748207582076820778207882079820808208182082820838208482085820868208782088820898209082091820928209382094820958209682097820988209982100821018210282103821048210582106821078210882109821108211182112821138211482115821168211782118821198212082121821228212382124821258212682127821288212982130821318213282133821348213582136821378213882139821408214182142821438214482145821468214782148821498215082151821528215382154821558215682157821588215982160821618216282163821648216582166821678216882169821708217182172821738217482175821768217782178821798218082181821828218382184821858218682187821888218982190821918219282193821948219582196821978219882199822008220182202822038220482205822068220782208822098221082211822128221382214822158221682217822188221982220822218222282223822248222582226822278222882229822308223182232822338223482235822368223782238822398224082241822428224382244822458224682247822488224982250822518225282253822548225582256822578225882259822608226182262822638226482265822668226782268822698227082271822728227382274822758227682277822788227982280822818228282283822848228582286822878228882289822908229182292822938229482295822968229782298822998230082301823028230382304823058230682307823088230982310823118231282313823148231582316823178231882319823208232182322823238232482325823268232782328823298233082331823328233382334823358233682337823388233982340823418234282343823448234582346823478234882349823508235182352823538235482355823568235782358823598236082361823628236382364823658236682367823688236982370823718237282373823748237582376823778237882379823808238182382823838238482385823868238782388823898239082391823928239382394823958239682397823988239982400824018240282403824048240582406824078240882409824108241182412824138241482415824168241782418824198242082421824228242382424824258242682427824288242982430824318243282433824348243582436824378243882439824408244182442824438244482445824468244782448824498245082451824528245382454824558245682457824588245982460824618246282463824648246582466824678246882469824708247182472824738247482475824768247782478824798248082481824828248382484824858248682487824888248982490824918249282493824948249582496824978249882499825008250182502825038250482505825068250782508825098251082511825128251382514825158251682517825188251982520825218252282523825248252582526825278252882529825308253182532825338253482535825368253782538825398254082541825428254382544825458254682547825488254982550825518255282553825548255582556825578255882559825608256182562825638256482565825668256782568825698257082571825728257382574825758257682577825788257982580825818258282583825848258582586825878258882589825908259182592825938259482595825968259782598825998260082601826028260382604826058260682607826088260982610826118261282613826148261582616826178261882619826208262182622826238262482625826268262782628826298263082631826328263382634826358263682637826388263982640826418264282643826448264582646826478264882649826508265182652826538265482655826568265782658826598266082661826628266382664826658266682667826688266982670826718267282673826748267582676826778267882679826808268182682826838268482685826868268782688826898269082691826928269382694826958269682697826988269982700827018270282703827048270582706827078270882709827108271182712827138271482715827168271782718827198272082721827228272382724827258272682727827288272982730827318273282733827348273582736827378273882739827408274182742827438274482745827468274782748827498275082751827528275382754827558275682757827588275982760827618276282763827648276582766827678276882769827708277182772827738277482775827768277782778827798278082781827828278382784827858278682787827888278982790827918279282793827948279582796827978279882799828008280182802828038280482805828068280782808828098281082811828128281382814828158281682817828188281982820828218282282823828248282582826828278282882829828308283182832828338283482835828368283782838828398284082841828428284382844828458284682847828488284982850828518285282853828548285582856828578285882859828608286182862828638286482865828668286782868828698287082871828728287382874828758287682877828788287982880828818288282883828848288582886828878288882889828908289182892828938289482895828968289782898828998290082901829028290382904829058290682907829088290982910829118291282913829148291582916829178291882919829208292182922829238292482925829268292782928829298293082931829328293382934829358293682937829388293982940829418294282943829448294582946829478294882949829508295182952829538295482955829568295782958829598296082961829628296382964829658296682967829688296982970829718297282973829748297582976829778297882979829808298182982829838298482985829868298782988829898299082991829928299382994829958299682997829988299983000830018300283003830048300583006830078300883009830108301183012830138301483015830168301783018830198302083021830228302383024830258302683027830288302983030830318303283033830348303583036830378303883039830408304183042830438304483045830468304783048830498305083051830528305383054830558305683057830588305983060830618306283063830648306583066830678306883069830708307183072830738307483075830768307783078830798308083081830828308383084830858308683087830888308983090830918309283093830948309583096830978309883099831008310183102831038310483105831068310783108831098311083111831128311383114831158311683117831188311983120831218312283123831248312583126831278312883129831308313183132831338313483135831368313783138831398314083141831428314383144831458314683147831488314983150831518315283153831548315583156831578315883159831608316183162831638316483165831668316783168831698317083171831728317383174831758317683177831788317983180831818318283183831848318583186831878318883189831908319183192831938319483195831968319783198831998320083201832028320383204832058320683207832088320983210832118321283213832148321583216832178321883219832208322183222832238322483225832268322783228832298323083231832328323383234832358323683237832388323983240832418324283243832448324583246832478324883249832508325183252832538325483255832568325783258832598326083261832628326383264832658326683267832688326983270832718327283273832748327583276832778327883279832808328183282832838328483285832868328783288832898329083291832928329383294832958329683297832988329983300833018330283303833048330583306833078330883309833108331183312833138331483315833168331783318833198332083321833228332383324833258332683327833288332983330833318333283333833348333583336833378333883339833408334183342833438334483345833468334783348833498335083351833528335383354833558335683357833588335983360833618336283363833648336583366833678336883369833708337183372833738337483375833768337783378833798338083381833828338383384833858338683387833888338983390833918339283393833948339583396833978339883399834008340183402834038340483405834068340783408834098341083411834128341383414834158341683417834188341983420834218342283423834248342583426834278342883429834308343183432834338343483435834368343783438834398344083441834428344383444834458344683447834488344983450834518345283453834548345583456834578345883459834608346183462834638346483465834668346783468834698347083471834728347383474834758347683477834788347983480834818348283483834848348583486834878348883489834908349183492834938349483495834968349783498834998350083501835028350383504835058350683507835088350983510835118351283513835148351583516835178351883519835208352183522835238352483525835268352783528835298353083531835328353383534835358353683537835388353983540835418354283543835448354583546835478354883549835508355183552835538355483555835568355783558835598356083561835628356383564835658356683567835688356983570835718357283573835748357583576835778357883579835808358183582835838358483585835868358783588835898359083591835928359383594835958359683597835988359983600836018360283603836048360583606836078360883609836108361183612836138361483615836168361783618836198362083621836228362383624836258362683627836288362983630836318363283633836348363583636836378363883639836408364183642836438364483645836468364783648836498365083651836528365383654836558365683657836588365983660836618366283663836648366583666836678366883669836708367183672836738367483675836768367783678836798368083681836828368383684836858368683687836888368983690836918369283693836948369583696836978369883699837008370183702837038370483705837068370783708837098371083711837128371383714837158371683717837188371983720837218372283723837248372583726837278372883729837308373183732837338373483735837368373783738837398374083741837428374383744837458374683747837488374983750837518375283753837548375583756837578375883759837608376183762837638376483765837668376783768837698377083771837728377383774837758377683777837788377983780837818378283783837848378583786837878378883789837908379183792837938379483795837968379783798837998380083801838028380383804838058380683807838088380983810838118381283813838148381583816838178381883819838208382183822838238382483825838268382783828838298383083831838328383383834838358383683837838388383983840838418384283843838448384583846838478384883849838508385183852838538385483855838568385783858838598386083861838628386383864838658386683867838688386983870838718387283873838748387583876838778387883879838808388183882838838388483885838868388783888838898389083891838928389383894838958389683897838988389983900839018390283903839048390583906839078390883909839108391183912839138391483915839168391783918839198392083921839228392383924839258392683927839288392983930839318393283933839348393583936839378393883939839408394183942839438394483945839468394783948839498395083951839528395383954839558395683957839588395983960839618396283963839648396583966839678396883969839708397183972839738397483975839768397783978839798398083981839828398383984839858398683987839888398983990839918399283993839948399583996839978399883999840008400184002840038400484005840068400784008840098401084011840128401384014840158401684017840188401984020840218402284023840248402584026840278402884029840308403184032840338403484035840368403784038840398404084041840428404384044840458404684047840488404984050840518405284053840548405584056840578405884059840608406184062840638406484065840668406784068840698407084071840728407384074840758407684077840788407984080840818408284083840848408584086840878408884089840908409184092840938409484095840968409784098840998410084101841028410384104841058410684107841088410984110841118411284113841148411584116841178411884119841208412184122841238412484125841268412784128841298413084131841328413384134841358413684137841388413984140841418414284143841448414584146841478414884149841508415184152841538415484155841568415784158841598416084161841628416384164841658416684167841688416984170841718417284173841748417584176841778417884179841808418184182841838418484185841868418784188841898419084191841928419384194841958419684197841988419984200842018420284203842048420584206842078420884209842108421184212842138421484215842168421784218842198422084221842228422384224842258422684227842288422984230842318423284233842348423584236842378423884239842408424184242842438424484245842468424784248842498425084251842528425384254842558425684257842588425984260842618426284263842648426584266842678426884269842708427184272842738427484275842768427784278842798428084281842828428384284842858428684287842888428984290842918429284293842948429584296842978429884299843008430184302843038430484305843068430784308843098431084311843128431384314843158431684317843188431984320843218432284323843248432584326843278432884329843308433184332843338433484335843368433784338843398434084341843428434384344843458434684347843488434984350843518435284353843548435584356843578435884359843608436184362843638436484365843668436784368843698437084371843728437384374843758437684377843788437984380843818438284383843848438584386843878438884389843908439184392843938439484395843968439784398843998440084401844028440384404844058440684407844088440984410844118441284413844148441584416844178441884419844208442184422844238442484425844268442784428844298443084431844328443384434844358443684437844388443984440844418444284443844448444584446844478444884449844508445184452844538445484455844568445784458844598446084461844628446384464844658446684467844688446984470844718447284473844748447584476844778447884479844808448184482844838448484485844868448784488844898449084491844928449384494844958449684497844988449984500845018450284503845048450584506845078450884509845108451184512845138451484515845168451784518845198452084521845228452384524845258452684527845288452984530845318453284533845348453584536845378453884539845408454184542845438454484545845468454784548845498455084551845528455384554845558455684557845588455984560845618456284563845648456584566845678456884569845708457184572845738457484575845768457784578845798458084581845828458384584845858458684587845888458984590845918459284593845948459584596845978459884599846008460184602846038460484605846068460784608846098461084611846128461384614846158461684617846188461984620846218462284623846248462584626846278462884629846308463184632846338463484635846368463784638846398464084641846428464384644846458464684647846488464984650846518465284653846548465584656846578465884659846608466184662846638466484665846668466784668846698467084671846728467384674846758467684677846788467984680846818468284683846848468584686846878468884689846908469184692846938469484695846968469784698846998470084701847028470384704847058470684707847088470984710847118471284713847148471584716847178471884719847208472184722847238472484725847268472784728847298473084731847328473384734847358473684737847388473984740847418474284743847448474584746847478474884749847508475184752847538475484755847568475784758847598476084761847628476384764847658476684767847688476984770847718477284773847748477584776847778477884779847808478184782847838478484785847868478784788847898479084791847928479384794847958479684797847988479984800848018480284803848048480584806848078480884809848108481184812848138481484815848168481784818848198482084821848228482384824848258482684827848288482984830848318483284833848348483584836848378483884839848408484184842848438484484845848468484784848848498485084851848528485384854848558485684857848588485984860848618486284863848648486584866848678486884869848708487184872848738487484875848768487784878848798488084881848828488384884848858488684887848888488984890848918489284893848948489584896848978489884899849008490184902849038490484905849068490784908849098491084911849128491384914849158491684917849188491984920849218492284923849248492584926849278492884929849308493184932849338493484935849368493784938849398494084941849428494384944849458494684947849488494984950849518495284953849548495584956849578495884959849608496184962849638496484965849668496784968849698497084971849728497384974849758497684977849788497984980849818498284983849848498584986849878498884989849908499184992849938499484995849968499784998849998500085001850028500385004850058500685007850088500985010850118501285013850148501585016850178501885019850208502185022850238502485025850268502785028850298503085031850328503385034850358503685037850388503985040850418504285043850448504585046850478504885049850508505185052850538505485055850568505785058850598506085061850628506385064850658506685067850688506985070850718507285073850748507585076850778507885079850808508185082850838508485085850868508785088850898509085091850928509385094850958509685097850988509985100851018510285103851048510585106851078510885109851108511185112851138511485115851168511785118851198512085121851228512385124851258512685127851288512985130851318513285133851348513585136851378513885139851408514185142851438514485145851468514785148851498515085151851528515385154851558515685157851588515985160851618516285163851648516585166851678516885169851708517185172851738517485175851768517785178851798518085181851828518385184851858518685187851888518985190851918519285193851948519585196851978519885199852008520185202852038520485205852068520785208852098521085211852128521385214852158521685217852188521985220852218522285223852248522585226852278522885229852308523185232852338523485235852368523785238852398524085241852428524385244852458524685247852488524985250852518525285253852548525585256852578525885259852608526185262852638526485265852668526785268852698527085271852728527385274852758527685277852788527985280852818528285283852848528585286852878528885289852908529185292852938529485295852968529785298852998530085301853028530385304853058530685307853088530985310853118531285313853148531585316853178531885319853208532185322853238532485325853268532785328853298533085331853328533385334853358533685337853388533985340853418534285343853448534585346853478534885349853508535185352853538535485355853568535785358853598536085361853628536385364853658536685367853688536985370853718537285373853748537585376853778537885379853808538185382853838538485385853868538785388853898539085391853928539385394853958539685397853988539985400854018540285403854048540585406854078540885409854108541185412854138541485415854168541785418854198542085421854228542385424854258542685427854288542985430854318543285433854348543585436854378543885439854408544185442854438544485445854468544785448854498545085451854528545385454854558545685457854588545985460854618546285463854648546585466854678546885469854708547185472854738547485475854768547785478854798548085481854828548385484854858548685487854888548985490854918549285493854948549585496854978549885499855008550185502855038550485505855068550785508855098551085511855128551385514855158551685517855188551985520855218552285523855248552585526855278552885529855308553185532855338553485535855368553785538855398554085541855428554385544855458554685547855488554985550855518555285553855548555585556855578555885559855608556185562855638556485565855668556785568855698557085571855728557385574855758557685577855788557985580855818558285583855848558585586855878558885589855908559185592855938559485595855968559785598855998560085601856028560385604856058560685607856088560985610856118561285613856148561585616856178561885619856208562185622856238562485625856268562785628856298563085631856328563385634856358563685637856388563985640856418564285643856448564585646856478564885649856508565185652856538565485655856568565785658856598566085661856628566385664856658566685667856688566985670856718567285673856748567585676856778567885679856808568185682856838568485685856868568785688856898569085691856928569385694856958569685697856988569985700857018570285703857048570585706857078570885709857108571185712857138571485715857168571785718857198572085721857228572385724857258572685727857288572985730857318573285733857348573585736857378573885739857408574185742857438574485745857468574785748857498575085751857528575385754857558575685757857588575985760857618576285763857648576585766857678576885769857708577185772857738577485775857768577785778857798578085781857828578385784857858578685787857888578985790857918579285793857948579585796857978579885799858008580185802858038580485805858068580785808858098581085811858128581385814858158581685817858188581985820858218582285823858248582585826858278582885829858308583185832858338583485835858368583785838858398584085841858428584385844858458584685847858488584985850858518585285853858548585585856858578585885859858608586185862858638586485865858668586785868858698587085871858728587385874858758587685877858788587985880858818588285883858848588585886858878588885889858908589185892858938589485895858968589785898858998590085901859028590385904859058590685907859088590985910859118591285913859148591585916859178591885919859208592185922859238592485925859268592785928859298593085931859328593385934859358593685937859388593985940859418594285943859448594585946859478594885949859508595185952859538595485955859568595785958859598596085961859628596385964859658596685967859688596985970859718597285973859748597585976859778597885979859808598185982859838598485985859868598785988859898599085991859928599385994859958599685997859988599986000860018600286003860048600586006860078600886009860108601186012860138601486015860168601786018860198602086021860228602386024860258602686027860288602986030860318603286033860348603586036860378603886039860408604186042860438604486045860468604786048860498605086051860528605386054860558605686057860588605986060860618606286063860648606586066860678606886069860708607186072860738607486075860768607786078860798608086081860828608386084860858608686087860888608986090860918609286093860948609586096860978609886099861008610186102861038610486105861068610786108861098611086111861128611386114861158611686117861188611986120861218612286123861248612586126861278612886129861308613186132861338613486135861368613786138861398614086141861428614386144861458614686147861488614986150861518615286153861548615586156861578615886159861608616186162861638616486165861668616786168861698617086171861728617386174861758617686177861788617986180861818618286183861848618586186861878618886189861908619186192861938619486195861968619786198861998620086201862028620386204862058620686207862088620986210862118621286213862148621586216862178621886219862208622186222862238622486225862268622786228862298623086231862328623386234862358623686237862388623986240862418624286243862448624586246862478624886249862508625186252862538625486255862568625786258862598626086261862628626386264862658626686267862688626986270862718627286273862748627586276862778627886279862808628186282862838628486285862868628786288862898629086291862928629386294862958629686297862988629986300863018630286303863048630586306863078630886309863108631186312863138631486315863168631786318863198632086321863228632386324863258632686327863288632986330863318633286333863348633586336863378633886339863408634186342863438634486345863468634786348863498635086351863528635386354863558635686357863588635986360863618636286363863648636586366863678636886369863708637186372863738637486375863768637786378863798638086381863828638386384863858638686387863888638986390863918639286393863948639586396863978639886399864008640186402864038640486405864068640786408864098641086411864128641386414864158641686417864188641986420864218642286423864248642586426864278642886429864308643186432864338643486435864368643786438864398644086441864428644386444864458644686447864488644986450864518645286453864548645586456864578645886459864608646186462864638646486465864668646786468864698647086471864728647386474864758647686477864788647986480864818648286483864848648586486864878648886489864908649186492864938649486495864968649786498864998650086501865028650386504865058650686507865088650986510865118651286513865148651586516865178651886519865208652186522865238652486525865268652786528865298653086531865328653386534865358653686537865388653986540865418654286543865448654586546865478654886549865508655186552865538655486555865568655786558865598656086561865628656386564865658656686567865688656986570865718657286573865748657586576865778657886579865808658186582865838658486585865868658786588865898659086591865928659386594865958659686597865988659986600866018660286603866048660586606866078660886609866108661186612866138661486615866168661786618866198662086621866228662386624866258662686627866288662986630866318663286633866348663586636866378663886639866408664186642866438664486645866468664786648866498665086651866528665386654866558665686657866588665986660866618666286663866648666586666866678666886669866708667186672866738667486675866768667786678866798668086681866828668386684866858668686687866888668986690866918669286693866948669586696866978669886699867008670186702867038670486705867068670786708867098671086711867128671386714867158671686717867188671986720867218672286723867248672586726867278672886729867308673186732867338673486735867368673786738867398674086741867428674386744867458674686747867488674986750867518675286753867548675586756867578675886759867608676186762867638676486765867668676786768867698677086771867728677386774867758677686777867788677986780867818678286783867848678586786867878678886789867908679186792867938679486795867968679786798867998680086801868028680386804868058680686807868088680986810868118681286813868148681586816868178681886819868208682186822868238682486825868268682786828868298683086831868328683386834868358683686837868388683986840868418684286843868448684586846868478684886849868508685186852868538685486855868568685786858868598686086861868628686386864868658686686867868688686986870868718687286873868748687586876868778687886879868808688186882868838688486885868868688786888868898689086891868928689386894868958689686897868988689986900869018690286903869048690586906869078690886909869108691186912869138691486915869168691786918869198692086921869228692386924869258692686927869288692986930869318693286933869348693586936869378693886939869408694186942869438694486945869468694786948869498695086951869528695386954869558695686957869588695986960869618696286963869648696586966869678696886969869708697186972869738697486975869768697786978869798698086981869828698386984869858698686987869888698986990869918699286993869948699586996869978699886999870008700187002870038700487005870068700787008870098701087011870128701387014870158701687017870188701987020870218702287023870248702587026870278702887029870308703187032870338703487035870368703787038870398704087041870428704387044870458704687047870488704987050870518705287053870548705587056870578705887059870608706187062870638706487065870668706787068870698707087071870728707387074870758707687077870788707987080870818708287083870848708587086870878708887089870908709187092870938709487095870968709787098870998710087101871028710387104871058710687107871088710987110871118711287113871148711587116871178711887119871208712187122871238712487125871268712787128871298713087131871328713387134871358713687137871388713987140871418714287143871448714587146871478714887149871508715187152871538715487155871568715787158871598716087161871628716387164871658716687167871688716987170871718717287173871748717587176871778717887179871808718187182871838718487185871868718787188871898719087191871928719387194871958719687197871988719987200872018720287203872048720587206872078720887209872108721187212872138721487215872168721787218872198722087221872228722387224872258722687227872288722987230872318723287233872348723587236872378723887239872408724187242872438724487245872468724787248872498725087251872528725387254872558725687257872588725987260872618726287263872648726587266872678726887269872708727187272872738727487275872768727787278872798728087281872828728387284872858728687287872888728987290872918729287293872948729587296872978729887299873008730187302873038730487305873068730787308873098731087311873128731387314873158731687317873188731987320873218732287323873248732587326873278732887329873308733187332873338733487335873368733787338873398734087341873428734387344873458734687347873488734987350873518735287353873548735587356873578735887359873608736187362873638736487365873668736787368873698737087371873728737387374873758737687377873788737987380873818738287383873848738587386873878738887389873908739187392873938739487395873968739787398873998740087401874028740387404874058740687407874088740987410874118741287413874148741587416874178741887419874208742187422874238742487425874268742787428874298743087431874328743387434874358743687437874388743987440874418744287443874448744587446874478744887449874508745187452874538745487455874568745787458874598746087461874628746387464874658746687467874688746987470874718747287473874748747587476874778747887479874808748187482874838748487485874868748787488874898749087491874928749387494874958749687497874988749987500875018750287503875048750587506875078750887509875108751187512875138751487515875168751787518875198752087521875228752387524875258752687527875288752987530875318753287533875348753587536875378753887539875408754187542875438754487545875468754787548875498755087551875528755387554875558755687557875588755987560875618756287563875648756587566875678756887569875708757187572875738757487575875768757787578875798758087581875828758387584875858758687587875888758987590875918759287593875948759587596875978759887599876008760187602876038760487605876068760787608876098761087611876128761387614876158761687617876188761987620876218762287623876248762587626876278762887629876308763187632876338763487635876368763787638876398764087641876428764387644876458764687647876488764987650876518765287653876548765587656876578765887659876608766187662876638766487665876668766787668876698767087671876728767387674876758767687677876788767987680876818768287683876848768587686876878768887689876908769187692876938769487695876968769787698876998770087701877028770387704877058770687707877088770987710877118771287713877148771587716877178771887719877208772187722877238772487725877268772787728877298773087731877328773387734877358773687737877388773987740877418774287743877448774587746877478774887749877508775187752877538775487755877568775787758877598776087761877628776387764877658776687767877688776987770877718777287773877748777587776877778777887779877808778187782877838778487785877868778787788877898779087791877928779387794877958779687797877988779987800878018780287803878048780587806878078780887809878108781187812878138781487815878168781787818878198782087821878228782387824878258782687827878288782987830878318783287833878348783587836878378783887839878408784187842878438784487845878468784787848878498785087851878528785387854878558785687857878588785987860878618786287863878648786587866878678786887869878708787187872878738787487875878768787787878878798788087881878828788387884878858788687887878888788987890878918789287893878948789587896878978789887899879008790187902879038790487905879068790787908879098791087911879128791387914879158791687917879188791987920879218792287923879248792587926879278792887929879308793187932879338793487935879368793787938879398794087941879428794387944879458794687947879488794987950879518795287953879548795587956879578795887959879608796187962879638796487965879668796787968879698797087971879728797387974879758797687977879788797987980879818798287983879848798587986879878798887989879908799187992879938799487995879968799787998879998800088001880028800388004880058800688007880088800988010880118801288013880148801588016880178801888019880208802188022880238802488025880268802788028880298803088031880328803388034880358803688037880388803988040880418804288043880448804588046880478804888049880508805188052880538805488055880568805788058880598806088061880628806388064880658806688067880688806988070880718807288073880748807588076880778807888079880808808188082880838808488085880868808788088880898809088091880928809388094880958809688097880988809988100881018810288103881048810588106881078810888109881108811188112881138811488115881168811788118881198812088121881228812388124881258812688127881288812988130881318813288133881348813588136881378813888139881408814188142881438814488145881468814788148881498815088151881528815388154881558815688157881588815988160881618816288163881648816588166881678816888169881708817188172881738817488175881768817788178881798818088181881828818388184881858818688187881888818988190881918819288193881948819588196881978819888199882008820188202882038820488205882068820788208882098821088211882128821388214882158821688217882188821988220882218822288223882248822588226882278822888229882308823188232882338823488235882368823788238882398824088241882428824388244882458824688247882488824988250882518825288253882548825588256882578825888259882608826188262882638826488265882668826788268882698827088271882728827388274882758827688277882788827988280882818828288283882848828588286882878828888289882908829188292882938829488295882968829788298882998830088301883028830388304883058830688307883088830988310883118831288313883148831588316883178831888319883208832188322883238832488325883268832788328883298833088331883328833388334883358833688337883388833988340883418834288343883448834588346883478834888349883508835188352883538835488355883568835788358883598836088361883628836388364883658836688367883688836988370883718837288373883748837588376883778837888379883808838188382883838838488385883868838788388883898839088391883928839388394883958839688397883988839988400884018840288403884048840588406884078840888409884108841188412884138841488415884168841788418884198842088421884228842388424884258842688427884288842988430884318843288433884348843588436884378843888439884408844188442884438844488445884468844788448884498845088451884528845388454884558845688457884588845988460884618846288463884648846588466884678846888469884708847188472884738847488475884768847788478884798848088481884828848388484884858848688487884888848988490884918849288493884948849588496884978849888499885008850188502885038850488505885068850788508885098851088511885128851388514885158851688517885188851988520885218852288523885248852588526885278852888529885308853188532885338853488535885368853788538885398854088541885428854388544885458854688547885488854988550885518855288553885548855588556885578855888559885608856188562885638856488565885668856788568885698857088571885728857388574885758857688577885788857988580885818858288583885848858588586885878858888589885908859188592885938859488595885968859788598885998860088601886028860388604886058860688607886088860988610886118861288613886148861588616886178861888619886208862188622886238862488625886268862788628886298863088631886328863388634886358863688637886388863988640886418864288643886448864588646886478864888649886508865188652886538865488655886568865788658886598866088661886628866388664886658866688667886688866988670886718867288673886748867588676886778867888679886808868188682886838868488685886868868788688886898869088691886928869388694886958869688697886988869988700887018870288703887048870588706887078870888709887108871188712887138871488715887168871788718887198872088721887228872388724887258872688727887288872988730887318873288733887348873588736887378873888739887408874188742887438874488745887468874788748887498875088751887528875388754887558875688757887588875988760887618876288763887648876588766887678876888769887708877188772887738877488775887768877788778887798878088781887828878388784887858878688787887888878988790887918879288793887948879588796887978879888799888008880188802888038880488805888068880788808888098881088811888128881388814888158881688817888188881988820888218882288823888248882588826888278882888829888308883188832888338883488835888368883788838888398884088841888428884388844888458884688847888488884988850888518885288853888548885588856888578885888859888608886188862888638886488865888668886788868888698887088871888728887388874888758887688877888788887988880888818888288883888848888588886888878888888889888908889188892888938889488895888968889788898888998890088901889028890388904889058890688907889088890988910889118891288913889148891588916889178891888919889208892188922889238892488925889268892788928889298893088931889328893388934889358893688937889388893988940889418894288943889448894588946889478894888949889508895188952889538895488955889568895788958889598896088961889628896388964889658896688967889688896988970889718897288973889748897588976889778897888979889808898188982889838898488985889868898788988889898899088991889928899388994889958899688997889988899989000890018900289003890048900589006890078900889009890108901189012890138901489015890168901789018890198902089021890228902389024890258902689027890288902989030890318903289033890348903589036890378903889039890408904189042890438904489045890468904789048890498905089051890528905389054890558905689057890588905989060890618906289063890648906589066890678906889069890708907189072890738907489075890768907789078890798908089081890828908389084890858908689087890888908989090890918909289093890948909589096890978909889099891008910189102891038910489105891068910789108891098911089111891128911389114891158911689117891188911989120891218912289123891248912589126891278912889129891308913189132891338913489135891368913789138891398914089141891428914389144891458914689147891488914989150891518915289153891548915589156891578915889159891608916189162891638916489165891668916789168891698917089171891728917389174891758917689177891788917989180891818918289183891848918589186891878918889189891908919189192891938919489195891968919789198891998920089201892028920389204892058920689207892088920989210892118921289213892148921589216892178921889219892208922189222892238922489225892268922789228892298923089231892328923389234892358923689237892388923989240892418924289243892448924589246892478924889249892508925189252892538925489255892568925789258892598926089261892628926389264892658926689267892688926989270892718927289273892748927589276892778927889279892808928189282892838928489285892868928789288892898929089291892928929389294892958929689297892988929989300893018930289303893048930589306893078930889309893108931189312893138931489315893168931789318893198932089321893228932389324893258932689327893288932989330893318933289333893348933589336893378933889339893408934189342893438934489345893468934789348893498935089351893528935389354893558935689357893588935989360893618936289363893648936589366893678936889369893708937189372893738937489375893768937789378893798938089381893828938389384893858938689387893888938989390893918939289393893948939589396893978939889399894008940189402894038940489405894068940789408894098941089411894128941389414894158941689417894188941989420894218942289423894248942589426894278942889429894308943189432894338943489435894368943789438894398944089441894428944389444894458944689447894488944989450894518945289453894548945589456894578945889459894608946189462894638946489465894668946789468894698947089471894728947389474894758947689477894788947989480894818948289483894848948589486894878948889489894908949189492894938949489495894968949789498894998950089501895028950389504895058950689507895088950989510895118951289513895148951589516895178951889519895208952189522895238952489525895268952789528895298953089531895328953389534895358953689537895388953989540895418954289543895448954589546895478954889549895508955189552895538955489555895568955789558895598956089561895628956389564895658956689567895688956989570895718957289573895748957589576895778957889579895808958189582895838958489585895868958789588895898959089591895928959389594895958959689597895988959989600896018960289603896048960589606896078960889609896108961189612896138961489615896168961789618896198962089621896228962389624896258962689627896288962989630896318963289633896348963589636896378963889639896408964189642896438964489645896468964789648896498965089651896528965389654896558965689657896588965989660896618966289663896648966589666896678966889669896708967189672896738967489675896768967789678896798968089681896828968389684896858968689687896888968989690896918969289693896948969589696896978969889699897008970189702897038970489705897068970789708897098971089711897128971389714897158971689717897188971989720897218972289723897248972589726897278972889729897308973189732897338973489735897368973789738897398974089741897428974389744897458974689747897488974989750897518975289753897548975589756897578975889759897608976189762897638976489765897668976789768897698977089771897728977389774897758977689777897788977989780897818978289783897848978589786897878978889789897908979189792897938979489795897968979789798897998980089801898028980389804898058980689807898088980989810898118981289813898148981589816898178981889819898208982189822898238982489825898268982789828898298983089831898328983389834898358983689837898388983989840898418984289843898448984589846898478984889849898508985189852898538985489855898568985789858898598986089861898628986389864898658986689867898688986989870898718987289873898748987589876898778987889879898808988189882898838988489885898868988789888898898989089891898928989389894898958989689897898988989989900899018990289903899048990589906899078990889909899108991189912899138991489915899168991789918899198992089921899228992389924899258992689927899288992989930899318993289933899348993589936899378993889939899408994189942899438994489945899468994789948899498995089951899528995389954899558995689957899588995989960899618996289963899648996589966899678996889969899708997189972899738997489975899768997789978899798998089981899828998389984899858998689987899888998989990899918999289993899948999589996899978999889999900009000190002900039000490005900069000790008900099001090011900129001390014900159001690017900189001990020900219002290023900249002590026900279002890029900309003190032900339003490035900369003790038900399004090041900429004390044900459004690047900489004990050900519005290053900549005590056900579005890059900609006190062900639006490065900669006790068900699007090071900729007390074900759007690077900789007990080900819008290083900849008590086900879008890089900909009190092900939009490095900969009790098900999010090101901029010390104901059010690107901089010990110901119011290113901149011590116901179011890119901209012190122901239012490125901269012790128901299013090131901329013390134901359013690137901389013990140901419014290143901449014590146901479014890149901509015190152901539015490155901569015790158901599016090161901629016390164901659016690167901689016990170901719017290173901749017590176901779017890179901809018190182901839018490185901869018790188901899019090191901929019390194901959019690197901989019990200902019020290203902049020590206902079020890209902109021190212902139021490215902169021790218902199022090221902229022390224902259022690227902289022990230902319023290233902349023590236902379023890239902409024190242902439024490245902469024790248902499025090251902529025390254902559025690257902589025990260902619026290263902649026590266902679026890269902709027190272902739027490275902769027790278902799028090281902829028390284902859028690287902889028990290902919029290293902949029590296902979029890299903009030190302903039030490305903069030790308903099031090311903129031390314903159031690317903189031990320903219032290323903249032590326903279032890329903309033190332903339033490335903369033790338903399034090341903429034390344903459034690347903489034990350903519035290353903549035590356903579035890359903609036190362903639036490365903669036790368903699037090371903729037390374903759037690377903789037990380903819038290383903849038590386903879038890389903909039190392903939039490395903969039790398903999040090401904029040390404904059040690407904089040990410904119041290413904149041590416904179041890419904209042190422904239042490425904269042790428904299043090431904329043390434904359043690437904389043990440904419044290443904449044590446904479044890449904509045190452904539045490455904569045790458904599046090461904629046390464904659046690467904689046990470904719047290473904749047590476904779047890479904809048190482904839048490485904869048790488904899049090491904929049390494904959049690497904989049990500905019050290503905049050590506905079050890509905109051190512905139051490515905169051790518905199052090521905229052390524905259052690527905289052990530905319053290533905349053590536905379053890539905409054190542905439054490545905469054790548905499055090551905529055390554905559055690557905589055990560905619056290563905649056590566905679056890569905709057190572905739057490575905769057790578905799058090581905829058390584905859058690587905889058990590905919059290593905949059590596905979059890599906009060190602906039060490605906069060790608906099061090611906129061390614906159061690617906189061990620906219062290623906249062590626906279062890629906309063190632906339063490635906369063790638906399064090641906429064390644906459064690647906489064990650906519065290653906549065590656906579065890659906609066190662906639066490665906669066790668906699067090671906729067390674906759067690677906789067990680906819068290683906849068590686906879068890689906909069190692906939069490695906969069790698906999070090701907029070390704907059070690707907089070990710907119071290713907149071590716907179071890719907209072190722907239072490725907269072790728907299073090731907329073390734907359073690737907389073990740907419074290743907449074590746907479074890749907509075190752907539075490755907569075790758907599076090761907629076390764907659076690767907689076990770907719077290773907749077590776907779077890779907809078190782907839078490785907869078790788907899079090791907929079390794907959079690797907989079990800908019080290803908049080590806908079080890809908109081190812908139081490815908169081790818908199082090821908229082390824908259082690827908289082990830908319083290833908349083590836908379083890839908409084190842908439084490845908469084790848908499085090851908529085390854908559085690857908589085990860908619086290863908649086590866908679086890869908709087190872908739087490875908769087790878908799088090881908829088390884908859088690887908889088990890908919089290893908949089590896908979089890899909009090190902909039090490905909069090790908909099091090911909129091390914909159091690917909189091990920909219092290923909249092590926909279092890929909309093190932909339093490935909369093790938909399094090941909429094390944909459094690947909489094990950909519095290953909549095590956909579095890959909609096190962909639096490965909669096790968909699097090971909729097390974909759097690977909789097990980909819098290983909849098590986909879098890989909909099190992909939099490995909969099790998909999100091001910029100391004910059100691007910089100991010910119101291013910149101591016910179101891019910209102191022910239102491025910269102791028910299103091031910329103391034910359103691037910389103991040910419104291043910449104591046910479104891049910509105191052910539105491055910569105791058910599106091061910629106391064910659106691067910689106991070910719107291073910749107591076910779107891079910809108191082910839108491085910869108791088910899109091091910929109391094910959109691097910989109991100911019110291103911049110591106911079110891109911109111191112911139111491115911169111791118911199112091121911229112391124911259112691127911289112991130911319113291133911349113591136911379113891139911409114191142911439114491145911469114791148911499115091151911529115391154911559115691157911589115991160911619116291163911649116591166911679116891169911709117191172911739117491175911769117791178911799118091181911829118391184911859118691187911889118991190911919119291193911949119591196911979119891199912009120191202912039120491205912069120791208912099121091211912129121391214912159121691217912189121991220912219122291223912249122591226912279122891229912309123191232912339123491235912369123791238912399124091241912429124391244912459124691247912489124991250912519125291253912549125591256912579125891259912609126191262912639126491265912669126791268912699127091271912729127391274912759127691277912789127991280912819128291283912849128591286912879128891289912909129191292912939129491295912969129791298912999130091301913029130391304913059130691307913089130991310913119131291313913149131591316913179131891319913209132191322913239132491325913269132791328913299133091331913329133391334913359133691337913389133991340913419134291343913449134591346913479134891349913509135191352913539135491355913569135791358913599136091361913629136391364913659136691367913689136991370913719137291373913749137591376913779137891379913809138191382913839138491385913869138791388913899139091391913929139391394913959139691397913989139991400914019140291403914049140591406914079140891409914109141191412914139141491415914169141791418914199142091421914229142391424914259142691427914289142991430914319143291433914349143591436914379143891439914409144191442914439144491445914469144791448914499145091451914529145391454914559145691457914589145991460914619146291463914649146591466914679146891469914709147191472914739147491475914769147791478914799148091481914829148391484914859148691487914889148991490914919149291493914949149591496914979149891499915009150191502915039150491505915069150791508915099151091511915129151391514915159151691517915189151991520915219152291523915249152591526915279152891529915309153191532915339153491535915369153791538915399154091541915429154391544915459154691547915489154991550915519155291553915549155591556915579155891559915609156191562915639156491565915669156791568915699157091571915729157391574915759157691577915789157991580915819158291583915849158591586915879158891589915909159191592915939159491595915969159791598915999160091601916029160391604916059160691607916089160991610916119161291613916149161591616916179161891619916209162191622916239162491625916269162791628916299163091631916329163391634916359163691637916389163991640916419164291643916449164591646916479164891649916509165191652916539165491655916569165791658916599166091661916629166391664916659166691667916689166991670916719167291673916749167591676916779167891679916809168191682916839168491685916869168791688916899169091691916929169391694916959169691697916989169991700917019170291703917049170591706917079170891709917109171191712917139171491715917169171791718917199172091721917229172391724917259172691727917289172991730917319173291733917349173591736917379173891739917409174191742917439174491745917469174791748917499175091751917529175391754917559175691757917589175991760917619176291763917649176591766917679176891769917709177191772917739177491775917769177791778917799178091781917829178391784917859178691787917889178991790917919179291793917949179591796917979179891799918009180191802918039180491805918069180791808918099181091811918129181391814918159181691817918189181991820918219182291823918249182591826918279182891829918309183191832918339183491835918369183791838918399184091841918429184391844918459184691847918489184991850918519185291853918549185591856918579185891859918609186191862918639186491865918669186791868918699187091871918729187391874918759187691877918789187991880918819188291883918849188591886918879188891889918909189191892918939189491895918969189791898918999190091901919029190391904919059190691907919089190991910919119191291913919149191591916919179191891919919209192191922919239192491925919269192791928919299193091931919329193391934919359193691937919389193991940919419194291943919449194591946919479194891949919509195191952919539195491955919569195791958919599196091961919629196391964919659196691967919689196991970919719197291973919749197591976919779197891979919809198191982919839198491985919869198791988919899199091991919929199391994919959199691997919989199992000920019200292003920049200592006920079200892009920109201192012920139201492015920169201792018920199202092021920229202392024920259202692027920289202992030920319203292033920349203592036920379203892039920409204192042920439204492045920469204792048920499205092051920529205392054920559205692057920589205992060920619206292063920649206592066920679206892069920709207192072920739207492075920769207792078920799208092081920829208392084920859208692087920889208992090920919209292093920949209592096920979209892099921009210192102921039210492105921069210792108921099211092111921129211392114921159211692117921189211992120921219212292123921249212592126921279212892129921309213192132921339213492135921369213792138921399214092141921429214392144921459214692147921489214992150921519215292153921549215592156921579215892159921609216192162921639216492165921669216792168921699217092171921729217392174921759217692177921789217992180921819218292183921849218592186921879218892189921909219192192921939219492195921969219792198921999220092201922029220392204922059220692207922089220992210922119221292213922149221592216922179221892219922209222192222922239222492225922269222792228922299223092231922329223392234922359223692237922389223992240922419224292243922449224592246922479224892249922509225192252922539225492255922569225792258922599226092261922629226392264922659226692267922689226992270922719227292273922749227592276922779227892279922809228192282922839228492285922869228792288922899229092291922929229392294922959229692297922989229992300923019230292303923049230592306923079230892309923109231192312923139231492315923169231792318923199232092321923229232392324923259232692327923289232992330923319233292333923349233592336923379233892339923409234192342923439234492345923469234792348923499235092351923529235392354923559235692357923589235992360923619236292363923649236592366923679236892369923709237192372923739237492375923769237792378923799238092381923829238392384923859238692387923889238992390923919239292393923949239592396923979239892399924009240192402924039240492405924069240792408924099241092411924129241392414924159241692417924189241992420924219242292423924249242592426924279242892429924309243192432924339243492435924369243792438924399244092441924429244392444924459244692447924489244992450924519245292453924549245592456924579245892459924609246192462924639246492465924669246792468924699247092471924729247392474924759247692477924789247992480924819248292483924849248592486924879248892489924909249192492924939249492495924969249792498924999250092501925029250392504925059250692507925089250992510925119251292513925149251592516925179251892519925209252192522925239252492525925269252792528925299253092531925329253392534925359253692537925389253992540925419254292543925449254592546925479254892549925509255192552925539255492555925569255792558925599256092561925629256392564925659256692567925689256992570925719257292573925749257592576925779257892579925809258192582925839258492585925869258792588925899259092591925929259392594925959259692597925989259992600926019260292603926049260592606926079260892609926109261192612926139261492615926169261792618926199262092621926229262392624926259262692627926289262992630926319263292633926349263592636926379263892639926409264192642926439264492645926469264792648926499265092651926529265392654926559265692657926589265992660926619266292663926649266592666926679266892669926709267192672926739267492675926769267792678926799268092681926829268392684926859268692687926889268992690926919269292693926949269592696926979269892699927009270192702927039270492705927069270792708927099271092711927129271392714927159271692717927189271992720927219272292723927249272592726927279272892729927309273192732927339273492735927369273792738927399274092741927429274392744927459274692747927489274992750927519275292753927549275592756927579275892759927609276192762927639276492765927669276792768927699277092771927729277392774927759277692777927789277992780927819278292783927849278592786927879278892789927909279192792927939279492795927969279792798927999280092801928029280392804928059280692807928089280992810928119281292813928149281592816928179281892819928209282192822928239282492825928269282792828928299283092831928329283392834928359283692837928389283992840928419284292843928449284592846928479284892849928509285192852928539285492855928569285792858928599286092861928629286392864928659286692867928689286992870928719287292873928749287592876928779287892879928809288192882928839288492885928869288792888928899289092891928929289392894928959289692897928989289992900929019290292903929049290592906929079290892909929109291192912929139291492915929169291792918929199292092921929229292392924929259292692927929289292992930929319293292933929349293592936929379293892939929409294192942929439294492945929469294792948929499295092951929529295392954929559295692957929589295992960929619296292963929649296592966929679296892969929709297192972929739297492975929769297792978929799298092981929829298392984929859298692987929889298992990929919299292993929949299592996929979299892999930009300193002930039300493005930069300793008930099301093011930129301393014930159301693017930189301993020930219302293023930249302593026930279302893029930309303193032930339303493035930369303793038930399304093041930429304393044930459304693047930489304993050930519305293053930549305593056930579305893059930609306193062930639306493065930669306793068930699307093071930729307393074930759307693077930789307993080930819308293083930849308593086930879308893089930909309193092930939309493095930969309793098930999310093101931029310393104931059310693107931089310993110
  1. /*
  2. * Licensed to the Apache Software Foundation (ASF) under one
  3. * or more contributor license agreements. See the NOTICE file
  4. * distributed with this work for additional information
  5. * regarding copyright ownership. The ASF licenses this file
  6. * to you under the Apache License, Version 2.0 (the
  7. * "License"); you may not use this file except in compliance
  8. * with the License. You may obtain a copy of the License at
  9. *
  10. * http://www.apache.org/licenses/LICENSE-2.0
  11. *
  12. * Unless required by applicable law or agreed to in writing,
  13. * software distributed under the License is distributed on an
  14. * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
  15. * KIND, either express or implied. See the License for the
  16. * specific language governing permissions and limitations
  17. * under the License.
  18. */
  19. /*! *****************************************************************************
  20. Copyright (c) Microsoft Corporation.
  21. Permission to use, copy, modify, and/or distribute this software for any
  22. purpose with or without fee is hereby granted.
  23. THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES WITH
  24. REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY
  25. AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT,
  26. INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM
  27. LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR
  28. OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
  29. PERFORMANCE OF THIS SOFTWARE.
  30. ***************************************************************************** */
  31. /* global Reflect, Promise */
  32. var extendStatics = function(d, b) {
  33. extendStatics = Object.setPrototypeOf ||
  34. ({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) ||
  35. function (d, b) { for (var p in b) if (Object.prototype.hasOwnProperty.call(b, p)) d[p] = b[p]; };
  36. return extendStatics(d, b);
  37. };
  38. function __extends(d, b) {
  39. if (typeof b !== "function" && b !== null)
  40. throw new TypeError("Class extends value " + String(b) + " is not a constructor or null");
  41. extendStatics(d, b);
  42. function __() { this.constructor = d; }
  43. d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
  44. }
  45. var Browser = (function () {
  46. function Browser() {
  47. this.firefox = false;
  48. this.ie = false;
  49. this.edge = false;
  50. this.newEdge = false;
  51. this.weChat = false;
  52. }
  53. return Browser;
  54. }());
  55. var Env = (function () {
  56. function Env() {
  57. this.browser = new Browser();
  58. this.node = false;
  59. this.wxa = false;
  60. this.worker = false;
  61. this.svgSupported = false;
  62. this.touchEventsSupported = false;
  63. this.pointerEventsSupported = false;
  64. this.domSupported = false;
  65. this.transformSupported = false;
  66. this.transform3dSupported = false;
  67. this.hasGlobalWindow = typeof window !== 'undefined';
  68. }
  69. return Env;
  70. }());
  71. var env = new Env();
  72. if (typeof wx === 'object' && typeof wx.getSystemInfoSync === 'function') {
  73. env.wxa = true;
  74. env.touchEventsSupported = true;
  75. }
  76. else if (typeof document === 'undefined' && typeof self !== 'undefined') {
  77. env.worker = true;
  78. }
  79. else if (!env.hasGlobalWindow
  80. || 'Deno' in window
  81. || (typeof navigator !== 'undefined' && typeof navigator.userAgent === 'string'
  82. && navigator.userAgent.indexOf('Node.js') > -1)) {
  83. env.node = true;
  84. env.svgSupported = true;
  85. }
  86. else {
  87. detect(navigator.userAgent, env);
  88. }
  89. function detect(ua, env) {
  90. var browser = env.browser;
  91. var firefox = ua.match(/Firefox\/([\d.]+)/);
  92. var ie = ua.match(/MSIE\s([\d.]+)/)
  93. || ua.match(/Trident\/.+?rv:(([\d.]+))/);
  94. var edge = ua.match(/Edge?\/([\d.]+)/);
  95. var weChat = (/micromessenger/i).test(ua);
  96. if (firefox) {
  97. browser.firefox = true;
  98. browser.version = firefox[1];
  99. }
  100. if (ie) {
  101. browser.ie = true;
  102. browser.version = ie[1];
  103. }
  104. if (edge) {
  105. browser.edge = true;
  106. browser.version = edge[1];
  107. browser.newEdge = +edge[1].split('.')[0] > 18;
  108. }
  109. if (weChat) {
  110. browser.weChat = true;
  111. }
  112. env.svgSupported = typeof SVGRect !== 'undefined';
  113. env.touchEventsSupported = 'ontouchstart' in window && !browser.ie && !browser.edge;
  114. env.pointerEventsSupported = 'onpointerdown' in window
  115. && (browser.edge || (browser.ie && +browser.version >= 11));
  116. var domSupported = env.domSupported = typeof document !== 'undefined';
  117. if (domSupported) {
  118. var style = document.documentElement.style;
  119. env.transform3dSupported = ((browser.ie && 'transition' in style)
  120. || browser.edge
  121. || (('WebKitCSSMatrix' in window) && ('m11' in new WebKitCSSMatrix()))
  122. || 'MozPerspective' in style)
  123. && !('OTransition' in style);
  124. env.transformSupported = env.transform3dSupported
  125. || (browser.ie && +browser.version >= 9);
  126. }
  127. }
  128. var DEFAULT_FONT_SIZE = 12;
  129. var DEFAULT_FONT_FAMILY = 'sans-serif';
  130. var DEFAULT_FONT = DEFAULT_FONT_SIZE + "px " + DEFAULT_FONT_FAMILY;
  131. var OFFSET = 20;
  132. var SCALE = 100;
  133. var defaultWidthMapStr = "007LLmW'55;N0500LLLLLLLLLL00NNNLzWW\\\\WQb\\0FWLg\\bWb\\WQ\\WrWWQ000CL5LLFLL0LL**F*gLLLL5F0LF\\FFF5.5N";
  134. function getTextWidthMap(mapStr) {
  135. var map = {};
  136. if (typeof JSON === 'undefined') {
  137. return map;
  138. }
  139. for (var i = 0; i < mapStr.length; i++) {
  140. var char = String.fromCharCode(i + 32);
  141. var size = (mapStr.charCodeAt(i) - OFFSET) / SCALE;
  142. map[char] = size;
  143. }
  144. return map;
  145. }
  146. var DEFAULT_TEXT_WIDTH_MAP = getTextWidthMap(defaultWidthMapStr);
  147. var platformApi = {
  148. createCanvas: function () {
  149. return typeof document !== 'undefined'
  150. && document.createElement('canvas');
  151. },
  152. measureText: (function () {
  153. var _ctx;
  154. var _cachedFont;
  155. return function (text, font) {
  156. if (!_ctx) {
  157. var canvas = platformApi.createCanvas();
  158. _ctx = canvas && canvas.getContext('2d');
  159. }
  160. if (_ctx) {
  161. if (_cachedFont !== font) {
  162. _cachedFont = _ctx.font = font || DEFAULT_FONT;
  163. }
  164. return _ctx.measureText(text);
  165. }
  166. else {
  167. text = text || '';
  168. font = font || DEFAULT_FONT;
  169. var res = /((?:\d+)?\.?\d*)px/.exec(font);
  170. var fontSize = res && +res[1] || DEFAULT_FONT_SIZE;
  171. var width = 0;
  172. if (font.indexOf('mono') >= 0) {
  173. width = fontSize * text.length;
  174. }
  175. else {
  176. for (var i = 0; i < text.length; i++) {
  177. var preCalcWidth = DEFAULT_TEXT_WIDTH_MAP[text[i]];
  178. width += preCalcWidth == null ? fontSize : (preCalcWidth * fontSize);
  179. }
  180. }
  181. return { width: width };
  182. }
  183. };
  184. })(),
  185. loadImage: function (src, onload, onerror) {
  186. var image = new Image();
  187. image.onload = onload;
  188. image.onerror = onerror;
  189. image.src = src;
  190. return image;
  191. }
  192. };
  193. function setPlatformAPI(newPlatformApis) {
  194. for (var key in platformApi) {
  195. if (newPlatformApis[key]) {
  196. platformApi[key] = newPlatformApis[key];
  197. }
  198. }
  199. }
  200. var BUILTIN_OBJECT = reduce([
  201. 'Function',
  202. 'RegExp',
  203. 'Date',
  204. 'Error',
  205. 'CanvasGradient',
  206. 'CanvasPattern',
  207. 'Image',
  208. 'Canvas'
  209. ], function (obj, val) {
  210. obj['[object ' + val + ']'] = true;
  211. return obj;
  212. }, {});
  213. var TYPED_ARRAY = reduce([
  214. 'Int8',
  215. 'Uint8',
  216. 'Uint8Clamped',
  217. 'Int16',
  218. 'Uint16',
  219. 'Int32',
  220. 'Uint32',
  221. 'Float32',
  222. 'Float64'
  223. ], function (obj, val) {
  224. obj['[object ' + val + 'Array]'] = true;
  225. return obj;
  226. }, {});
  227. var objToString = Object.prototype.toString;
  228. var arrayProto = Array.prototype;
  229. var nativeForEach = arrayProto.forEach;
  230. var nativeFilter = arrayProto.filter;
  231. var nativeSlice = arrayProto.slice;
  232. var nativeMap = arrayProto.map;
  233. var ctorFunction = function () { }.constructor;
  234. var protoFunction = ctorFunction ? ctorFunction.prototype : null;
  235. var protoKey = '__proto__';
  236. var idStart = 0x0907;
  237. function guid() {
  238. return idStart++;
  239. }
  240. function logError() {
  241. var args = [];
  242. for (var _i = 0; _i < arguments.length; _i++) {
  243. args[_i] = arguments[_i];
  244. }
  245. if (typeof console !== 'undefined') {
  246. console.error.apply(console, args);
  247. }
  248. }
  249. function clone(source) {
  250. if (source == null || typeof source !== 'object') {
  251. return source;
  252. }
  253. var result = source;
  254. var typeStr = objToString.call(source);
  255. if (typeStr === '[object Array]') {
  256. if (!isPrimitive(source)) {
  257. result = [];
  258. for (var i = 0, len = source.length; i < len; i++) {
  259. result[i] = clone(source[i]);
  260. }
  261. }
  262. }
  263. else if (TYPED_ARRAY[typeStr]) {
  264. if (!isPrimitive(source)) {
  265. var Ctor = source.constructor;
  266. if (Ctor.from) {
  267. result = Ctor.from(source);
  268. }
  269. else {
  270. result = new Ctor(source.length);
  271. for (var i = 0, len = source.length; i < len; i++) {
  272. result[i] = source[i];
  273. }
  274. }
  275. }
  276. }
  277. else if (!BUILTIN_OBJECT[typeStr] && !isPrimitive(source) && !isDom(source)) {
  278. result = {};
  279. for (var key in source) {
  280. if (source.hasOwnProperty(key) && key !== protoKey) {
  281. result[key] = clone(source[key]);
  282. }
  283. }
  284. }
  285. return result;
  286. }
  287. function merge(target, source, overwrite) {
  288. if (!isObject(source) || !isObject(target)) {
  289. return overwrite ? clone(source) : target;
  290. }
  291. for (var key in source) {
  292. if (source.hasOwnProperty(key) && key !== protoKey) {
  293. var targetProp = target[key];
  294. var sourceProp = source[key];
  295. if (isObject(sourceProp)
  296. && isObject(targetProp)
  297. && !isArray(sourceProp)
  298. && !isArray(targetProp)
  299. && !isDom(sourceProp)
  300. && !isDom(targetProp)
  301. && !isBuiltInObject(sourceProp)
  302. && !isBuiltInObject(targetProp)
  303. && !isPrimitive(sourceProp)
  304. && !isPrimitive(targetProp)) {
  305. merge(targetProp, sourceProp, overwrite);
  306. }
  307. else if (overwrite || !(key in target)) {
  308. target[key] = clone(source[key]);
  309. }
  310. }
  311. }
  312. return target;
  313. }
  314. function mergeAll(targetAndSources, overwrite) {
  315. var result = targetAndSources[0];
  316. for (var i = 1, len = targetAndSources.length; i < len; i++) {
  317. result = merge(result, targetAndSources[i], overwrite);
  318. }
  319. return result;
  320. }
  321. function extend(target, source) {
  322. if (Object.assign) {
  323. Object.assign(target, source);
  324. }
  325. else {
  326. for (var key in source) {
  327. if (source.hasOwnProperty(key) && key !== protoKey) {
  328. target[key] = source[key];
  329. }
  330. }
  331. }
  332. return target;
  333. }
  334. function defaults(target, source, overlay) {
  335. var keysArr = keys(source);
  336. for (var i = 0, len = keysArr.length; i < len; i++) {
  337. var key = keysArr[i];
  338. if ((overlay ? source[key] != null : target[key] == null)) {
  339. target[key] = source[key];
  340. }
  341. }
  342. return target;
  343. }
  344. var createCanvas = platformApi.createCanvas;
  345. function indexOf(array, value) {
  346. if (array) {
  347. if (array.indexOf) {
  348. return array.indexOf(value);
  349. }
  350. for (var i = 0, len = array.length; i < len; i++) {
  351. if (array[i] === value) {
  352. return i;
  353. }
  354. }
  355. }
  356. return -1;
  357. }
  358. function inherits(clazz, baseClazz) {
  359. var clazzPrototype = clazz.prototype;
  360. function F() { }
  361. F.prototype = baseClazz.prototype;
  362. clazz.prototype = new F();
  363. for (var prop in clazzPrototype) {
  364. if (clazzPrototype.hasOwnProperty(prop)) {
  365. clazz.prototype[prop] = clazzPrototype[prop];
  366. }
  367. }
  368. clazz.prototype.constructor = clazz;
  369. clazz.superClass = baseClazz;
  370. }
  371. function mixin(target, source, override) {
  372. target = 'prototype' in target ? target.prototype : target;
  373. source = 'prototype' in source ? source.prototype : source;
  374. if (Object.getOwnPropertyNames) {
  375. var keyList = Object.getOwnPropertyNames(source);
  376. for (var i = 0; i < keyList.length; i++) {
  377. var key = keyList[i];
  378. if (key !== 'constructor') {
  379. if ((override ? source[key] != null : target[key] == null)) {
  380. target[key] = source[key];
  381. }
  382. }
  383. }
  384. }
  385. else {
  386. defaults(target, source, override);
  387. }
  388. }
  389. function isArrayLike(data) {
  390. if (!data) {
  391. return false;
  392. }
  393. if (typeof data === 'string') {
  394. return false;
  395. }
  396. return typeof data.length === 'number';
  397. }
  398. function each(arr, cb, context) {
  399. if (!(arr && cb)) {
  400. return;
  401. }
  402. if (arr.forEach && arr.forEach === nativeForEach) {
  403. arr.forEach(cb, context);
  404. }
  405. else if (arr.length === +arr.length) {
  406. for (var i = 0, len = arr.length; i < len; i++) {
  407. cb.call(context, arr[i], i, arr);
  408. }
  409. }
  410. else {
  411. for (var key in arr) {
  412. if (arr.hasOwnProperty(key)) {
  413. cb.call(context, arr[key], key, arr);
  414. }
  415. }
  416. }
  417. }
  418. function map(arr, cb, context) {
  419. if (!arr) {
  420. return [];
  421. }
  422. if (!cb) {
  423. return slice(arr);
  424. }
  425. if (arr.map && arr.map === nativeMap) {
  426. return arr.map(cb, context);
  427. }
  428. else {
  429. var result = [];
  430. for (var i = 0, len = arr.length; i < len; i++) {
  431. result.push(cb.call(context, arr[i], i, arr));
  432. }
  433. return result;
  434. }
  435. }
  436. function reduce(arr, cb, memo, context) {
  437. if (!(arr && cb)) {
  438. return;
  439. }
  440. for (var i = 0, len = arr.length; i < len; i++) {
  441. memo = cb.call(context, memo, arr[i], i, arr);
  442. }
  443. return memo;
  444. }
  445. function filter(arr, cb, context) {
  446. if (!arr) {
  447. return [];
  448. }
  449. if (!cb) {
  450. return slice(arr);
  451. }
  452. if (arr.filter && arr.filter === nativeFilter) {
  453. return arr.filter(cb, context);
  454. }
  455. else {
  456. var result = [];
  457. for (var i = 0, len = arr.length; i < len; i++) {
  458. if (cb.call(context, arr[i], i, arr)) {
  459. result.push(arr[i]);
  460. }
  461. }
  462. return result;
  463. }
  464. }
  465. function find(arr, cb, context) {
  466. if (!(arr && cb)) {
  467. return;
  468. }
  469. for (var i = 0, len = arr.length; i < len; i++) {
  470. if (cb.call(context, arr[i], i, arr)) {
  471. return arr[i];
  472. }
  473. }
  474. }
  475. function keys(obj) {
  476. if (!obj) {
  477. return [];
  478. }
  479. if (Object.keys) {
  480. return Object.keys(obj);
  481. }
  482. var keyList = [];
  483. for (var key in obj) {
  484. if (obj.hasOwnProperty(key)) {
  485. keyList.push(key);
  486. }
  487. }
  488. return keyList;
  489. }
  490. function bindPolyfill(func, context) {
  491. var args = [];
  492. for (var _i = 2; _i < arguments.length; _i++) {
  493. args[_i - 2] = arguments[_i];
  494. }
  495. return function () {
  496. return func.apply(context, args.concat(nativeSlice.call(arguments)));
  497. };
  498. }
  499. var bind = (protoFunction && isFunction(protoFunction.bind))
  500. ? protoFunction.call.bind(protoFunction.bind)
  501. : bindPolyfill;
  502. function curry(func) {
  503. var args = [];
  504. for (var _i = 1; _i < arguments.length; _i++) {
  505. args[_i - 1] = arguments[_i];
  506. }
  507. return function () {
  508. return func.apply(this, args.concat(nativeSlice.call(arguments)));
  509. };
  510. }
  511. function isArray(value) {
  512. if (Array.isArray) {
  513. return Array.isArray(value);
  514. }
  515. return objToString.call(value) === '[object Array]';
  516. }
  517. function isFunction(value) {
  518. return typeof value === 'function';
  519. }
  520. function isString(value) {
  521. return typeof value === 'string';
  522. }
  523. function isStringSafe(value) {
  524. return objToString.call(value) === '[object String]';
  525. }
  526. function isNumber(value) {
  527. return typeof value === 'number';
  528. }
  529. function isObject(value) {
  530. var type = typeof value;
  531. return type === 'function' || (!!value && type === 'object');
  532. }
  533. function isBuiltInObject(value) {
  534. return !!BUILTIN_OBJECT[objToString.call(value)];
  535. }
  536. function isTypedArray(value) {
  537. return !!TYPED_ARRAY[objToString.call(value)];
  538. }
  539. function isDom(value) {
  540. return typeof value === 'object'
  541. && typeof value.nodeType === 'number'
  542. && typeof value.ownerDocument === 'object';
  543. }
  544. function isGradientObject(value) {
  545. return value.colorStops != null;
  546. }
  547. function isImagePatternObject(value) {
  548. return value.image != null;
  549. }
  550. function isRegExp(value) {
  551. return objToString.call(value) === '[object RegExp]';
  552. }
  553. function eqNaN(value) {
  554. return value !== value;
  555. }
  556. function retrieve() {
  557. var args = [];
  558. for (var _i = 0; _i < arguments.length; _i++) {
  559. args[_i] = arguments[_i];
  560. }
  561. for (var i = 0, len = args.length; i < len; i++) {
  562. if (args[i] != null) {
  563. return args[i];
  564. }
  565. }
  566. }
  567. function retrieve2(value0, value1) {
  568. return value0 != null
  569. ? value0
  570. : value1;
  571. }
  572. function retrieve3(value0, value1, value2) {
  573. return value0 != null
  574. ? value0
  575. : value1 != null
  576. ? value1
  577. : value2;
  578. }
  579. function slice(arr) {
  580. var args = [];
  581. for (var _i = 1; _i < arguments.length; _i++) {
  582. args[_i - 1] = arguments[_i];
  583. }
  584. return nativeSlice.apply(arr, args);
  585. }
  586. function normalizeCssArray(val) {
  587. if (typeof (val) === 'number') {
  588. return [val, val, val, val];
  589. }
  590. var len = val.length;
  591. if (len === 2) {
  592. return [val[0], val[1], val[0], val[1]];
  593. }
  594. else if (len === 3) {
  595. return [val[0], val[1], val[2], val[1]];
  596. }
  597. return val;
  598. }
  599. function assert(condition, message) {
  600. if (!condition) {
  601. throw new Error(message);
  602. }
  603. }
  604. function trim(str) {
  605. if (str == null) {
  606. return null;
  607. }
  608. else if (typeof str.trim === 'function') {
  609. return str.trim();
  610. }
  611. else {
  612. return str.replace(/^[\s\uFEFF\xA0]+|[\s\uFEFF\xA0]+$/g, '');
  613. }
  614. }
  615. var primitiveKey = '__ec_primitive__';
  616. function setAsPrimitive(obj) {
  617. obj[primitiveKey] = true;
  618. }
  619. function isPrimitive(obj) {
  620. return obj[primitiveKey];
  621. }
  622. var MapPolyfill = (function () {
  623. function MapPolyfill() {
  624. this.data = {};
  625. }
  626. MapPolyfill.prototype["delete"] = function (key) {
  627. var existed = this.has(key);
  628. if (existed) {
  629. delete this.data[key];
  630. }
  631. return existed;
  632. };
  633. MapPolyfill.prototype.has = function (key) {
  634. return this.data.hasOwnProperty(key);
  635. };
  636. MapPolyfill.prototype.get = function (key) {
  637. return this.data[key];
  638. };
  639. MapPolyfill.prototype.set = function (key, value) {
  640. this.data[key] = value;
  641. return this;
  642. };
  643. MapPolyfill.prototype.keys = function () {
  644. return keys(this.data);
  645. };
  646. MapPolyfill.prototype.forEach = function (callback) {
  647. var data = this.data;
  648. for (var key in data) {
  649. if (data.hasOwnProperty(key)) {
  650. callback(data[key], key);
  651. }
  652. }
  653. };
  654. return MapPolyfill;
  655. }());
  656. var isNativeMapSupported = typeof Map === 'function';
  657. function maybeNativeMap() {
  658. return (isNativeMapSupported ? new Map() : new MapPolyfill());
  659. }
  660. var HashMap = (function () {
  661. function HashMap(obj) {
  662. var isArr = isArray(obj);
  663. this.data = maybeNativeMap();
  664. var thisMap = this;
  665. (obj instanceof HashMap)
  666. ? obj.each(visit)
  667. : (obj && each(obj, visit));
  668. function visit(value, key) {
  669. isArr ? thisMap.set(value, key) : thisMap.set(key, value);
  670. }
  671. }
  672. HashMap.prototype.hasKey = function (key) {
  673. return this.data.has(key);
  674. };
  675. HashMap.prototype.get = function (key) {
  676. return this.data.get(key);
  677. };
  678. HashMap.prototype.set = function (key, value) {
  679. this.data.set(key, value);
  680. return value;
  681. };
  682. HashMap.prototype.each = function (cb, context) {
  683. this.data.forEach(function (value, key) {
  684. cb.call(context, value, key);
  685. });
  686. };
  687. HashMap.prototype.keys = function () {
  688. var keys = this.data.keys();
  689. return isNativeMapSupported
  690. ? Array.from(keys)
  691. : keys;
  692. };
  693. HashMap.prototype.removeKey = function (key) {
  694. this.data["delete"](key);
  695. };
  696. return HashMap;
  697. }());
  698. function createHashMap(obj) {
  699. return new HashMap(obj);
  700. }
  701. function concatArray(a, b) {
  702. var newArray = new a.constructor(a.length + b.length);
  703. for (var i = 0; i < a.length; i++) {
  704. newArray[i] = a[i];
  705. }
  706. var offset = a.length;
  707. for (var i = 0; i < b.length; i++) {
  708. newArray[i + offset] = b[i];
  709. }
  710. return newArray;
  711. }
  712. function createObject(proto, properties) {
  713. var obj;
  714. if (Object.create) {
  715. obj = Object.create(proto);
  716. }
  717. else {
  718. var StyleCtor = function () { };
  719. StyleCtor.prototype = proto;
  720. obj = new StyleCtor();
  721. }
  722. if (properties) {
  723. extend(obj, properties);
  724. }
  725. return obj;
  726. }
  727. function disableUserSelect(dom) {
  728. var domStyle = dom.style;
  729. domStyle.webkitUserSelect = 'none';
  730. domStyle.userSelect = 'none';
  731. domStyle.webkitTapHighlightColor = 'rgba(0,0,0,0)';
  732. domStyle['-webkit-touch-callout'] = 'none';
  733. }
  734. function hasOwn(own, prop) {
  735. return own.hasOwnProperty(prop);
  736. }
  737. function noop() { }
  738. var RADIAN_TO_DEGREE = 180 / Math.PI;
  739. var EPSILON = Number.EPSILON || Math.pow(2, -52);
  740. var util = /*#__PURE__*/Object.freeze({
  741. __proto__: null,
  742. guid: guid,
  743. logError: logError,
  744. clone: clone,
  745. merge: merge,
  746. mergeAll: mergeAll,
  747. extend: extend,
  748. defaults: defaults,
  749. createCanvas: createCanvas,
  750. indexOf: indexOf,
  751. inherits: inherits,
  752. mixin: mixin,
  753. isArrayLike: isArrayLike,
  754. each: each,
  755. map: map,
  756. reduce: reduce,
  757. filter: filter,
  758. find: find,
  759. keys: keys,
  760. bind: bind,
  761. curry: curry,
  762. isArray: isArray,
  763. isFunction: isFunction,
  764. isString: isString,
  765. isStringSafe: isStringSafe,
  766. isNumber: isNumber,
  767. isObject: isObject,
  768. isBuiltInObject: isBuiltInObject,
  769. isTypedArray: isTypedArray,
  770. isDom: isDom,
  771. isGradientObject: isGradientObject,
  772. isImagePatternObject: isImagePatternObject,
  773. isRegExp: isRegExp,
  774. eqNaN: eqNaN,
  775. retrieve: retrieve,
  776. retrieve2: retrieve2,
  777. retrieve3: retrieve3,
  778. slice: slice,
  779. normalizeCssArray: normalizeCssArray,
  780. assert: assert,
  781. trim: trim,
  782. setAsPrimitive: setAsPrimitive,
  783. isPrimitive: isPrimitive,
  784. HashMap: HashMap,
  785. createHashMap: createHashMap,
  786. concatArray: concatArray,
  787. createObject: createObject,
  788. disableUserSelect: disableUserSelect,
  789. hasOwn: hasOwn,
  790. noop: noop,
  791. RADIAN_TO_DEGREE: RADIAN_TO_DEGREE,
  792. EPSILON: EPSILON
  793. });
  794. function create(x, y) {
  795. if (x == null) {
  796. x = 0;
  797. }
  798. if (y == null) {
  799. y = 0;
  800. }
  801. return [x, y];
  802. }
  803. function copy(out, v) {
  804. out[0] = v[0];
  805. out[1] = v[1];
  806. return out;
  807. }
  808. function clone$1(v) {
  809. return [v[0], v[1]];
  810. }
  811. function set(out, a, b) {
  812. out[0] = a;
  813. out[1] = b;
  814. return out;
  815. }
  816. function add(out, v1, v2) {
  817. out[0] = v1[0] + v2[0];
  818. out[1] = v1[1] + v2[1];
  819. return out;
  820. }
  821. function scaleAndAdd(out, v1, v2, a) {
  822. out[0] = v1[0] + v2[0] * a;
  823. out[1] = v1[1] + v2[1] * a;
  824. return out;
  825. }
  826. function sub(out, v1, v2) {
  827. out[0] = v1[0] - v2[0];
  828. out[1] = v1[1] - v2[1];
  829. return out;
  830. }
  831. function len(v) {
  832. return Math.sqrt(lenSquare(v));
  833. }
  834. var length = len;
  835. function lenSquare(v) {
  836. return v[0] * v[0] + v[1] * v[1];
  837. }
  838. var lengthSquare = lenSquare;
  839. function mul(out, v1, v2) {
  840. out[0] = v1[0] * v2[0];
  841. out[1] = v1[1] * v2[1];
  842. return out;
  843. }
  844. function div(out, v1, v2) {
  845. out[0] = v1[0] / v2[0];
  846. out[1] = v1[1] / v2[1];
  847. return out;
  848. }
  849. function dot(v1, v2) {
  850. return v1[0] * v2[0] + v1[1] * v2[1];
  851. }
  852. function scale(out, v, s) {
  853. out[0] = v[0] * s;
  854. out[1] = v[1] * s;
  855. return out;
  856. }
  857. function normalize(out, v) {
  858. var d = len(v);
  859. if (d === 0) {
  860. out[0] = 0;
  861. out[1] = 0;
  862. }
  863. else {
  864. out[0] = v[0] / d;
  865. out[1] = v[1] / d;
  866. }
  867. return out;
  868. }
  869. function distance(v1, v2) {
  870. return Math.sqrt((v1[0] - v2[0]) * (v1[0] - v2[0])
  871. + (v1[1] - v2[1]) * (v1[1] - v2[1]));
  872. }
  873. var dist = distance;
  874. function distanceSquare(v1, v2) {
  875. return (v1[0] - v2[0]) * (v1[0] - v2[0])
  876. + (v1[1] - v2[1]) * (v1[1] - v2[1]);
  877. }
  878. var distSquare = distanceSquare;
  879. function negate(out, v) {
  880. out[0] = -v[0];
  881. out[1] = -v[1];
  882. return out;
  883. }
  884. function lerp(out, v1, v2, t) {
  885. out[0] = v1[0] + t * (v2[0] - v1[0]);
  886. out[1] = v1[1] + t * (v2[1] - v1[1]);
  887. return out;
  888. }
  889. function applyTransform(out, v, m) {
  890. var x = v[0];
  891. var y = v[1];
  892. out[0] = m[0] * x + m[2] * y + m[4];
  893. out[1] = m[1] * x + m[3] * y + m[5];
  894. return out;
  895. }
  896. function min(out, v1, v2) {
  897. out[0] = Math.min(v1[0], v2[0]);
  898. out[1] = Math.min(v1[1], v2[1]);
  899. return out;
  900. }
  901. function max(out, v1, v2) {
  902. out[0] = Math.max(v1[0], v2[0]);
  903. out[1] = Math.max(v1[1], v2[1]);
  904. return out;
  905. }
  906. var vector = /*#__PURE__*/Object.freeze({
  907. __proto__: null,
  908. create: create,
  909. copy: copy,
  910. clone: clone$1,
  911. set: set,
  912. add: add,
  913. scaleAndAdd: scaleAndAdd,
  914. sub: sub,
  915. len: len,
  916. length: length,
  917. lenSquare: lenSquare,
  918. lengthSquare: lengthSquare,
  919. mul: mul,
  920. div: div,
  921. dot: dot,
  922. scale: scale,
  923. normalize: normalize,
  924. distance: distance,
  925. dist: dist,
  926. distanceSquare: distanceSquare,
  927. distSquare: distSquare,
  928. negate: negate,
  929. lerp: lerp,
  930. applyTransform: applyTransform,
  931. min: min,
  932. max: max
  933. });
  934. var Param = (function () {
  935. function Param(target, e) {
  936. this.target = target;
  937. this.topTarget = e && e.topTarget;
  938. }
  939. return Param;
  940. }());
  941. var Draggable = (function () {
  942. function Draggable(handler) {
  943. this.handler = handler;
  944. handler.on('mousedown', this._dragStart, this);
  945. handler.on('mousemove', this._drag, this);
  946. handler.on('mouseup', this._dragEnd, this);
  947. }
  948. Draggable.prototype._dragStart = function (e) {
  949. var draggingTarget = e.target;
  950. while (draggingTarget && !draggingTarget.draggable) {
  951. draggingTarget = draggingTarget.parent || draggingTarget.__hostTarget;
  952. }
  953. if (draggingTarget) {
  954. this._draggingTarget = draggingTarget;
  955. draggingTarget.dragging = true;
  956. this._x = e.offsetX;
  957. this._y = e.offsetY;
  958. this.handler.dispatchToElement(new Param(draggingTarget, e), 'dragstart', e.event);
  959. }
  960. };
  961. Draggable.prototype._drag = function (e) {
  962. var draggingTarget = this._draggingTarget;
  963. if (draggingTarget) {
  964. var x = e.offsetX;
  965. var y = e.offsetY;
  966. var dx = x - this._x;
  967. var dy = y - this._y;
  968. this._x = x;
  969. this._y = y;
  970. draggingTarget.drift(dx, dy, e);
  971. this.handler.dispatchToElement(new Param(draggingTarget, e), 'drag', e.event);
  972. var dropTarget = this.handler.findHover(x, y, draggingTarget).target;
  973. var lastDropTarget = this._dropTarget;
  974. this._dropTarget = dropTarget;
  975. if (draggingTarget !== dropTarget) {
  976. if (lastDropTarget && dropTarget !== lastDropTarget) {
  977. this.handler.dispatchToElement(new Param(lastDropTarget, e), 'dragleave', e.event);
  978. }
  979. if (dropTarget && dropTarget !== lastDropTarget) {
  980. this.handler.dispatchToElement(new Param(dropTarget, e), 'dragenter', e.event);
  981. }
  982. }
  983. }
  984. };
  985. Draggable.prototype._dragEnd = function (e) {
  986. var draggingTarget = this._draggingTarget;
  987. if (draggingTarget) {
  988. draggingTarget.dragging = false;
  989. }
  990. this.handler.dispatchToElement(new Param(draggingTarget, e), 'dragend', e.event);
  991. if (this._dropTarget) {
  992. this.handler.dispatchToElement(new Param(this._dropTarget, e), 'drop', e.event);
  993. }
  994. this._draggingTarget = null;
  995. this._dropTarget = null;
  996. };
  997. return Draggable;
  998. }());
  999. var Eventful = (function () {
  1000. function Eventful(eventProcessors) {
  1001. if (eventProcessors) {
  1002. this._$eventProcessor = eventProcessors;
  1003. }
  1004. }
  1005. Eventful.prototype.on = function (event, query, handler, context) {
  1006. if (!this._$handlers) {
  1007. this._$handlers = {};
  1008. }
  1009. var _h = this._$handlers;
  1010. if (typeof query === 'function') {
  1011. context = handler;
  1012. handler = query;
  1013. query = null;
  1014. }
  1015. if (!handler || !event) {
  1016. return this;
  1017. }
  1018. var eventProcessor = this._$eventProcessor;
  1019. if (query != null && eventProcessor && eventProcessor.normalizeQuery) {
  1020. query = eventProcessor.normalizeQuery(query);
  1021. }
  1022. if (!_h[event]) {
  1023. _h[event] = [];
  1024. }
  1025. for (var i = 0; i < _h[event].length; i++) {
  1026. if (_h[event][i].h === handler) {
  1027. return this;
  1028. }
  1029. }
  1030. var wrap = {
  1031. h: handler,
  1032. query: query,
  1033. ctx: (context || this),
  1034. callAtLast: handler.zrEventfulCallAtLast
  1035. };
  1036. var lastIndex = _h[event].length - 1;
  1037. var lastWrap = _h[event][lastIndex];
  1038. (lastWrap && lastWrap.callAtLast)
  1039. ? _h[event].splice(lastIndex, 0, wrap)
  1040. : _h[event].push(wrap);
  1041. return this;
  1042. };
  1043. Eventful.prototype.isSilent = function (eventName) {
  1044. var _h = this._$handlers;
  1045. return !_h || !_h[eventName] || !_h[eventName].length;
  1046. };
  1047. Eventful.prototype.off = function (eventType, handler) {
  1048. var _h = this._$handlers;
  1049. if (!_h) {
  1050. return this;
  1051. }
  1052. if (!eventType) {
  1053. this._$handlers = {};
  1054. return this;
  1055. }
  1056. if (handler) {
  1057. if (_h[eventType]) {
  1058. var newList = [];
  1059. for (var i = 0, l = _h[eventType].length; i < l; i++) {
  1060. if (_h[eventType][i].h !== handler) {
  1061. newList.push(_h[eventType][i]);
  1062. }
  1063. }
  1064. _h[eventType] = newList;
  1065. }
  1066. if (_h[eventType] && _h[eventType].length === 0) {
  1067. delete _h[eventType];
  1068. }
  1069. }
  1070. else {
  1071. delete _h[eventType];
  1072. }
  1073. return this;
  1074. };
  1075. Eventful.prototype.trigger = function (eventType) {
  1076. var args = [];
  1077. for (var _i = 1; _i < arguments.length; _i++) {
  1078. args[_i - 1] = arguments[_i];
  1079. }
  1080. if (!this._$handlers) {
  1081. return this;
  1082. }
  1083. var _h = this._$handlers[eventType];
  1084. var eventProcessor = this._$eventProcessor;
  1085. if (_h) {
  1086. var argLen = args.length;
  1087. var len = _h.length;
  1088. for (var i = 0; i < len; i++) {
  1089. var hItem = _h[i];
  1090. if (eventProcessor
  1091. && eventProcessor.filter
  1092. && hItem.query != null
  1093. && !eventProcessor.filter(eventType, hItem.query)) {
  1094. continue;
  1095. }
  1096. switch (argLen) {
  1097. case 0:
  1098. hItem.h.call(hItem.ctx);
  1099. break;
  1100. case 1:
  1101. hItem.h.call(hItem.ctx, args[0]);
  1102. break;
  1103. case 2:
  1104. hItem.h.call(hItem.ctx, args[0], args[1]);
  1105. break;
  1106. default:
  1107. hItem.h.apply(hItem.ctx, args);
  1108. break;
  1109. }
  1110. }
  1111. }
  1112. eventProcessor && eventProcessor.afterTrigger
  1113. && eventProcessor.afterTrigger(eventType);
  1114. return this;
  1115. };
  1116. Eventful.prototype.triggerWithContext = function (type) {
  1117. var args = [];
  1118. for (var _i = 1; _i < arguments.length; _i++) {
  1119. args[_i - 1] = arguments[_i];
  1120. }
  1121. if (!this._$handlers) {
  1122. return this;
  1123. }
  1124. var _h = this._$handlers[type];
  1125. var eventProcessor = this._$eventProcessor;
  1126. if (_h) {
  1127. var argLen = args.length;
  1128. var ctx = args[argLen - 1];
  1129. var len = _h.length;
  1130. for (var i = 0; i < len; i++) {
  1131. var hItem = _h[i];
  1132. if (eventProcessor
  1133. && eventProcessor.filter
  1134. && hItem.query != null
  1135. && !eventProcessor.filter(type, hItem.query)) {
  1136. continue;
  1137. }
  1138. switch (argLen) {
  1139. case 0:
  1140. hItem.h.call(ctx);
  1141. break;
  1142. case 1:
  1143. hItem.h.call(ctx, args[0]);
  1144. break;
  1145. case 2:
  1146. hItem.h.call(ctx, args[0], args[1]);
  1147. break;
  1148. default:
  1149. hItem.h.apply(ctx, args.slice(1, argLen - 1));
  1150. break;
  1151. }
  1152. }
  1153. }
  1154. eventProcessor && eventProcessor.afterTrigger
  1155. && eventProcessor.afterTrigger(type);
  1156. return this;
  1157. };
  1158. return Eventful;
  1159. }());
  1160. var LN2 = Math.log(2);
  1161. function determinant(rows, rank, rowStart, rowMask, colMask, detCache) {
  1162. var cacheKey = rowMask + '-' + colMask;
  1163. var fullRank = rows.length;
  1164. if (detCache.hasOwnProperty(cacheKey)) {
  1165. return detCache[cacheKey];
  1166. }
  1167. if (rank === 1) {
  1168. var colStart = Math.round(Math.log(((1 << fullRank) - 1) & ~colMask) / LN2);
  1169. return rows[rowStart][colStart];
  1170. }
  1171. var subRowMask = rowMask | (1 << rowStart);
  1172. var subRowStart = rowStart + 1;
  1173. while (rowMask & (1 << subRowStart)) {
  1174. subRowStart++;
  1175. }
  1176. var sum = 0;
  1177. for (var j = 0, colLocalIdx = 0; j < fullRank; j++) {
  1178. var colTag = 1 << j;
  1179. if (!(colTag & colMask)) {
  1180. sum += (colLocalIdx % 2 ? -1 : 1) * rows[rowStart][j]
  1181. * determinant(rows, rank - 1, subRowStart, subRowMask, colMask | colTag, detCache);
  1182. colLocalIdx++;
  1183. }
  1184. }
  1185. detCache[cacheKey] = sum;
  1186. return sum;
  1187. }
  1188. function buildTransformer(src, dest) {
  1189. var mA = [
  1190. [src[0], src[1], 1, 0, 0, 0, -dest[0] * src[0], -dest[0] * src[1]],
  1191. [0, 0, 0, src[0], src[1], 1, -dest[1] * src[0], -dest[1] * src[1]],
  1192. [src[2], src[3], 1, 0, 0, 0, -dest[2] * src[2], -dest[2] * src[3]],
  1193. [0, 0, 0, src[2], src[3], 1, -dest[3] * src[2], -dest[3] * src[3]],
  1194. [src[4], src[5], 1, 0, 0, 0, -dest[4] * src[4], -dest[4] * src[5]],
  1195. [0, 0, 0, src[4], src[5], 1, -dest[5] * src[4], -dest[5] * src[5]],
  1196. [src[6], src[7], 1, 0, 0, 0, -dest[6] * src[6], -dest[6] * src[7]],
  1197. [0, 0, 0, src[6], src[7], 1, -dest[7] * src[6], -dest[7] * src[7]]
  1198. ];
  1199. var detCache = {};
  1200. var det = determinant(mA, 8, 0, 0, 0, detCache);
  1201. if (det === 0) {
  1202. return;
  1203. }
  1204. var vh = [];
  1205. for (var i = 0; i < 8; i++) {
  1206. for (var j = 0; j < 8; j++) {
  1207. vh[j] == null && (vh[j] = 0);
  1208. vh[j] += ((i + j) % 2 ? -1 : 1)
  1209. * determinant(mA, 7, i === 0 ? 1 : 0, 1 << i, 1 << j, detCache)
  1210. / det * dest[i];
  1211. }
  1212. }
  1213. return function (out, srcPointX, srcPointY) {
  1214. var pk = srcPointX * vh[6] + srcPointY * vh[7] + 1;
  1215. out[0] = (srcPointX * vh[0] + srcPointY * vh[1] + vh[2]) / pk;
  1216. out[1] = (srcPointX * vh[3] + srcPointY * vh[4] + vh[5]) / pk;
  1217. };
  1218. }
  1219. var EVENT_SAVED_PROP = '___zrEVENTSAVED';
  1220. var _calcOut = [];
  1221. function transformLocalCoord(out, elFrom, elTarget, inX, inY) {
  1222. return transformCoordWithViewport(_calcOut, elFrom, inX, inY, true)
  1223. && transformCoordWithViewport(out, elTarget, _calcOut[0], _calcOut[1]);
  1224. }
  1225. function transformLocalCoordClear(elFrom, elTarget) {
  1226. elFrom && dealClear(elFrom);
  1227. elTarget && dealClear(elTarget);
  1228. function dealClear(el) {
  1229. var saved = el[EVENT_SAVED_PROP];
  1230. if (saved) {
  1231. saved.clearMarkers && saved.clearMarkers();
  1232. delete el[EVENT_SAVED_PROP];
  1233. }
  1234. }
  1235. }
  1236. function transformCoordWithViewport(out, el, inX, inY, inverse) {
  1237. if (el.getBoundingClientRect && env.domSupported && !isCanvasEl(el)) {
  1238. var saved = el[EVENT_SAVED_PROP] || (el[EVENT_SAVED_PROP] = {});
  1239. var markers = prepareCoordMarkers(el, saved);
  1240. var transformer = preparePointerTransformer(markers, saved, inverse);
  1241. if (transformer) {
  1242. transformer(out, inX, inY);
  1243. return true;
  1244. }
  1245. }
  1246. return false;
  1247. }
  1248. function prepareCoordMarkers(el, saved) {
  1249. var markers = saved.markers;
  1250. if (markers) {
  1251. return markers;
  1252. }
  1253. markers = saved.markers = [];
  1254. var propLR = ['left', 'right'];
  1255. var propTB = ['top', 'bottom'];
  1256. for (var i = 0; i < 4; i++) {
  1257. var marker = document.createElement('div');
  1258. var stl = marker.style;
  1259. var idxLR = i % 2;
  1260. var idxTB = (i >> 1) % 2;
  1261. stl.cssText = [
  1262. 'position: absolute',
  1263. 'visibility: hidden',
  1264. 'padding: 0',
  1265. 'margin: 0',
  1266. 'border-width: 0',
  1267. 'user-select: none',
  1268. 'width:0',
  1269. 'height:0',
  1270. propLR[idxLR] + ':0',
  1271. propTB[idxTB] + ':0',
  1272. propLR[1 - idxLR] + ':auto',
  1273. propTB[1 - idxTB] + ':auto',
  1274. ''
  1275. ].join('!important;');
  1276. el.appendChild(marker);
  1277. markers.push(marker);
  1278. }
  1279. saved.clearMarkers = function () {
  1280. each(markers, function (marker) {
  1281. marker.parentNode && marker.parentNode.removeChild(marker);
  1282. });
  1283. };
  1284. return markers;
  1285. }
  1286. function preparePointerTransformer(markers, saved, inverse) {
  1287. var transformerName = inverse ? 'invTrans' : 'trans';
  1288. var transformer = saved[transformerName];
  1289. var oldSrcCoords = saved.srcCoords;
  1290. var srcCoords = [];
  1291. var destCoords = [];
  1292. var oldCoordTheSame = true;
  1293. for (var i = 0; i < 4; i++) {
  1294. var rect = markers[i].getBoundingClientRect();
  1295. var ii = 2 * i;
  1296. var x = rect.left;
  1297. var y = rect.top;
  1298. srcCoords.push(x, y);
  1299. oldCoordTheSame = oldCoordTheSame && oldSrcCoords && x === oldSrcCoords[ii] && y === oldSrcCoords[ii + 1];
  1300. destCoords.push(markers[i].offsetLeft, markers[i].offsetTop);
  1301. }
  1302. return (oldCoordTheSame && transformer)
  1303. ? transformer
  1304. : (saved.srcCoords = srcCoords,
  1305. saved[transformerName] = inverse
  1306. ? buildTransformer(destCoords, srcCoords)
  1307. : buildTransformer(srcCoords, destCoords));
  1308. }
  1309. function isCanvasEl(el) {
  1310. return el.nodeName.toUpperCase() === 'CANVAS';
  1311. }
  1312. var replaceReg = /([&<>"'])/g;
  1313. var replaceMap = {
  1314. '&': '&amp;',
  1315. '<': '&lt;',
  1316. '>': '&gt;',
  1317. '"': '&quot;',
  1318. '\'': '&#39;'
  1319. };
  1320. function encodeHTML(source) {
  1321. return source == null
  1322. ? ''
  1323. : (source + '').replace(replaceReg, function (str, c) {
  1324. return replaceMap[c];
  1325. });
  1326. }
  1327. var MOUSE_EVENT_REG = /^(?:mouse|pointer|contextmenu|drag|drop)|click/;
  1328. var _calcOut$1 = [];
  1329. var firefoxNotSupportOffsetXY = env.browser.firefox
  1330. && +env.browser.version.split('.')[0] < 39;
  1331. function clientToLocal(el, e, out, calculate) {
  1332. out = out || {};
  1333. if (calculate) {
  1334. calculateZrXY(el, e, out);
  1335. }
  1336. else if (firefoxNotSupportOffsetXY
  1337. && e.layerX != null
  1338. && e.layerX !== e.offsetX) {
  1339. out.zrX = e.layerX;
  1340. out.zrY = e.layerY;
  1341. }
  1342. else if (e.offsetX != null) {
  1343. out.zrX = e.offsetX;
  1344. out.zrY = e.offsetY;
  1345. }
  1346. else {
  1347. calculateZrXY(el, e, out);
  1348. }
  1349. return out;
  1350. }
  1351. function calculateZrXY(el, e, out) {
  1352. if (env.domSupported && el.getBoundingClientRect) {
  1353. var ex = e.clientX;
  1354. var ey = e.clientY;
  1355. if (isCanvasEl(el)) {
  1356. var box = el.getBoundingClientRect();
  1357. out.zrX = ex - box.left;
  1358. out.zrY = ey - box.top;
  1359. return;
  1360. }
  1361. else {
  1362. if (transformCoordWithViewport(_calcOut$1, el, ex, ey)) {
  1363. out.zrX = _calcOut$1[0];
  1364. out.zrY = _calcOut$1[1];
  1365. return;
  1366. }
  1367. }
  1368. }
  1369. out.zrX = out.zrY = 0;
  1370. }
  1371. function getNativeEvent(e) {
  1372. return e
  1373. || window.event;
  1374. }
  1375. function normalizeEvent(el, e, calculate) {
  1376. e = getNativeEvent(e);
  1377. if (e.zrX != null) {
  1378. return e;
  1379. }
  1380. var eventType = e.type;
  1381. var isTouch = eventType && eventType.indexOf('touch') >= 0;
  1382. if (!isTouch) {
  1383. clientToLocal(el, e, e, calculate);
  1384. var wheelDelta = getWheelDeltaMayPolyfill(e);
  1385. e.zrDelta = wheelDelta ? wheelDelta / 120 : -(e.detail || 0) / 3;
  1386. }
  1387. else {
  1388. var touch = eventType !== 'touchend'
  1389. ? e.targetTouches[0]
  1390. : e.changedTouches[0];
  1391. touch && clientToLocal(el, touch, e, calculate);
  1392. }
  1393. var button = e.button;
  1394. if (e.which == null && button !== undefined && MOUSE_EVENT_REG.test(e.type)) {
  1395. e.which = (button & 1 ? 1 : (button & 2 ? 3 : (button & 4 ? 2 : 0)));
  1396. }
  1397. return e;
  1398. }
  1399. function getWheelDeltaMayPolyfill(e) {
  1400. var rawWheelDelta = e.wheelDelta;
  1401. if (rawWheelDelta) {
  1402. return rawWheelDelta;
  1403. }
  1404. var deltaX = e.deltaX;
  1405. var deltaY = e.deltaY;
  1406. if (deltaX == null || deltaY == null) {
  1407. return rawWheelDelta;
  1408. }
  1409. var delta = deltaY !== 0 ? Math.abs(deltaY) : Math.abs(deltaX);
  1410. var sign = deltaY > 0 ? -1
  1411. : deltaY < 0 ? 1
  1412. : deltaX > 0 ? -1
  1413. : 1;
  1414. return 3 * delta * sign;
  1415. }
  1416. function addEventListener(el, name, handler, opt) {
  1417. el.addEventListener(name, handler, opt);
  1418. }
  1419. function removeEventListener(el, name, handler, opt) {
  1420. el.removeEventListener(name, handler, opt);
  1421. }
  1422. var stop = function (e) {
  1423. e.preventDefault();
  1424. e.stopPropagation();
  1425. e.cancelBubble = true;
  1426. };
  1427. function isMiddleOrRightButtonOnMouseUpDown(e) {
  1428. return e.which === 2 || e.which === 3;
  1429. }
  1430. var GestureMgr = (function () {
  1431. function GestureMgr() {
  1432. this._track = [];
  1433. }
  1434. GestureMgr.prototype.recognize = function (event, target, root) {
  1435. this._doTrack(event, target, root);
  1436. return this._recognize(event);
  1437. };
  1438. GestureMgr.prototype.clear = function () {
  1439. this._track.length = 0;
  1440. return this;
  1441. };
  1442. GestureMgr.prototype._doTrack = function (event, target, root) {
  1443. var touches = event.touches;
  1444. if (!touches) {
  1445. return;
  1446. }
  1447. var trackItem = {
  1448. points: [],
  1449. touches: [],
  1450. target: target,
  1451. event: event
  1452. };
  1453. for (var i = 0, len = touches.length; i < len; i++) {
  1454. var touch = touches[i];
  1455. var pos = clientToLocal(root, touch, {});
  1456. trackItem.points.push([pos.zrX, pos.zrY]);
  1457. trackItem.touches.push(touch);
  1458. }
  1459. this._track.push(trackItem);
  1460. };
  1461. GestureMgr.prototype._recognize = function (event) {
  1462. for (var eventName in recognizers) {
  1463. if (recognizers.hasOwnProperty(eventName)) {
  1464. var gestureInfo = recognizers[eventName](this._track, event);
  1465. if (gestureInfo) {
  1466. return gestureInfo;
  1467. }
  1468. }
  1469. }
  1470. };
  1471. return GestureMgr;
  1472. }());
  1473. function dist$1(pointPair) {
  1474. var dx = pointPair[1][0] - pointPair[0][0];
  1475. var dy = pointPair[1][1] - pointPair[0][1];
  1476. return Math.sqrt(dx * dx + dy * dy);
  1477. }
  1478. function center(pointPair) {
  1479. return [
  1480. (pointPair[0][0] + pointPair[1][0]) / 2,
  1481. (pointPair[0][1] + pointPair[1][1]) / 2
  1482. ];
  1483. }
  1484. var recognizers = {
  1485. pinch: function (tracks, event) {
  1486. var trackLen = tracks.length;
  1487. if (!trackLen) {
  1488. return;
  1489. }
  1490. var pinchEnd = (tracks[trackLen - 1] || {}).points;
  1491. var pinchPre = (tracks[trackLen - 2] || {}).points || pinchEnd;
  1492. if (pinchPre
  1493. && pinchPre.length > 1
  1494. && pinchEnd
  1495. && pinchEnd.length > 1) {
  1496. var pinchScale = dist$1(pinchEnd) / dist$1(pinchPre);
  1497. !isFinite(pinchScale) && (pinchScale = 1);
  1498. event.pinchScale = pinchScale;
  1499. var pinchCenter = center(pinchEnd);
  1500. event.pinchX = pinchCenter[0];
  1501. event.pinchY = pinchCenter[1];
  1502. return {
  1503. type: 'pinch',
  1504. target: tracks[0].target,
  1505. event: event
  1506. };
  1507. }
  1508. }
  1509. };
  1510. function create$1() {
  1511. return [1, 0, 0, 1, 0, 0];
  1512. }
  1513. function identity(out) {
  1514. out[0] = 1;
  1515. out[1] = 0;
  1516. out[2] = 0;
  1517. out[3] = 1;
  1518. out[4] = 0;
  1519. out[5] = 0;
  1520. return out;
  1521. }
  1522. function copy$1(out, m) {
  1523. out[0] = m[0];
  1524. out[1] = m[1];
  1525. out[2] = m[2];
  1526. out[3] = m[3];
  1527. out[4] = m[4];
  1528. out[5] = m[5];
  1529. return out;
  1530. }
  1531. function mul$1(out, m1, m2) {
  1532. var out0 = m1[0] * m2[0] + m1[2] * m2[1];
  1533. var out1 = m1[1] * m2[0] + m1[3] * m2[1];
  1534. var out2 = m1[0] * m2[2] + m1[2] * m2[3];
  1535. var out3 = m1[1] * m2[2] + m1[3] * m2[3];
  1536. var out4 = m1[0] * m2[4] + m1[2] * m2[5] + m1[4];
  1537. var out5 = m1[1] * m2[4] + m1[3] * m2[5] + m1[5];
  1538. out[0] = out0;
  1539. out[1] = out1;
  1540. out[2] = out2;
  1541. out[3] = out3;
  1542. out[4] = out4;
  1543. out[5] = out5;
  1544. return out;
  1545. }
  1546. function translate(out, a, v) {
  1547. out[0] = a[0];
  1548. out[1] = a[1];
  1549. out[2] = a[2];
  1550. out[3] = a[3];
  1551. out[4] = a[4] + v[0];
  1552. out[5] = a[5] + v[1];
  1553. return out;
  1554. }
  1555. function rotate(out, a, rad, pivot) {
  1556. if (pivot === void 0) { pivot = [0, 0]; }
  1557. var aa = a[0];
  1558. var ac = a[2];
  1559. var atx = a[4];
  1560. var ab = a[1];
  1561. var ad = a[3];
  1562. var aty = a[5];
  1563. var st = Math.sin(rad);
  1564. var ct = Math.cos(rad);
  1565. out[0] = aa * ct + ab * st;
  1566. out[1] = -aa * st + ab * ct;
  1567. out[2] = ac * ct + ad * st;
  1568. out[3] = -ac * st + ct * ad;
  1569. out[4] = ct * (atx - pivot[0]) + st * (aty - pivot[1]) + pivot[0];
  1570. out[5] = ct * (aty - pivot[1]) - st * (atx - pivot[0]) + pivot[1];
  1571. return out;
  1572. }
  1573. function scale$1(out, a, v) {
  1574. var vx = v[0];
  1575. var vy = v[1];
  1576. out[0] = a[0] * vx;
  1577. out[1] = a[1] * vy;
  1578. out[2] = a[2] * vx;
  1579. out[3] = a[3] * vy;
  1580. out[4] = a[4] * vx;
  1581. out[5] = a[5] * vy;
  1582. return out;
  1583. }
  1584. function invert(out, a) {
  1585. var aa = a[0];
  1586. var ac = a[2];
  1587. var atx = a[4];
  1588. var ab = a[1];
  1589. var ad = a[3];
  1590. var aty = a[5];
  1591. var det = aa * ad - ab * ac;
  1592. if (!det) {
  1593. return null;
  1594. }
  1595. det = 1.0 / det;
  1596. out[0] = ad * det;
  1597. out[1] = -ab * det;
  1598. out[2] = -ac * det;
  1599. out[3] = aa * det;
  1600. out[4] = (ac * aty - ad * atx) * det;
  1601. out[5] = (ab * atx - aa * aty) * det;
  1602. return out;
  1603. }
  1604. function clone$2(a) {
  1605. var b = create$1();
  1606. copy$1(b, a);
  1607. return b;
  1608. }
  1609. var matrix = /*#__PURE__*/Object.freeze({
  1610. __proto__: null,
  1611. create: create$1,
  1612. identity: identity,
  1613. copy: copy$1,
  1614. mul: mul$1,
  1615. translate: translate,
  1616. rotate: rotate,
  1617. scale: scale$1,
  1618. invert: invert,
  1619. clone: clone$2
  1620. });
  1621. var Point = (function () {
  1622. function Point(x, y) {
  1623. this.x = x || 0;
  1624. this.y = y || 0;
  1625. }
  1626. Point.prototype.copy = function (other) {
  1627. this.x = other.x;
  1628. this.y = other.y;
  1629. return this;
  1630. };
  1631. Point.prototype.clone = function () {
  1632. return new Point(this.x, this.y);
  1633. };
  1634. Point.prototype.set = function (x, y) {
  1635. this.x = x;
  1636. this.y = y;
  1637. return this;
  1638. };
  1639. Point.prototype.equal = function (other) {
  1640. return other.x === this.x && other.y === this.y;
  1641. };
  1642. Point.prototype.add = function (other) {
  1643. this.x += other.x;
  1644. this.y += other.y;
  1645. return this;
  1646. };
  1647. Point.prototype.scale = function (scalar) {
  1648. this.x *= scalar;
  1649. this.y *= scalar;
  1650. };
  1651. Point.prototype.scaleAndAdd = function (other, scalar) {
  1652. this.x += other.x * scalar;
  1653. this.y += other.y * scalar;
  1654. };
  1655. Point.prototype.sub = function (other) {
  1656. this.x -= other.x;
  1657. this.y -= other.y;
  1658. return this;
  1659. };
  1660. Point.prototype.dot = function (other) {
  1661. return this.x * other.x + this.y * other.y;
  1662. };
  1663. Point.prototype.len = function () {
  1664. return Math.sqrt(this.x * this.x + this.y * this.y);
  1665. };
  1666. Point.prototype.lenSquare = function () {
  1667. return this.x * this.x + this.y * this.y;
  1668. };
  1669. Point.prototype.normalize = function () {
  1670. var len = this.len();
  1671. this.x /= len;
  1672. this.y /= len;
  1673. return this;
  1674. };
  1675. Point.prototype.distance = function (other) {
  1676. var dx = this.x - other.x;
  1677. var dy = this.y - other.y;
  1678. return Math.sqrt(dx * dx + dy * dy);
  1679. };
  1680. Point.prototype.distanceSquare = function (other) {
  1681. var dx = this.x - other.x;
  1682. var dy = this.y - other.y;
  1683. return dx * dx + dy * dy;
  1684. };
  1685. Point.prototype.negate = function () {
  1686. this.x = -this.x;
  1687. this.y = -this.y;
  1688. return this;
  1689. };
  1690. Point.prototype.transform = function (m) {
  1691. if (!m) {
  1692. return;
  1693. }
  1694. var x = this.x;
  1695. var y = this.y;
  1696. this.x = m[0] * x + m[2] * y + m[4];
  1697. this.y = m[1] * x + m[3] * y + m[5];
  1698. return this;
  1699. };
  1700. Point.prototype.toArray = function (out) {
  1701. out[0] = this.x;
  1702. out[1] = this.y;
  1703. return out;
  1704. };
  1705. Point.prototype.fromArray = function (input) {
  1706. this.x = input[0];
  1707. this.y = input[1];
  1708. };
  1709. Point.set = function (p, x, y) {
  1710. p.x = x;
  1711. p.y = y;
  1712. };
  1713. Point.copy = function (p, p2) {
  1714. p.x = p2.x;
  1715. p.y = p2.y;
  1716. };
  1717. Point.len = function (p) {
  1718. return Math.sqrt(p.x * p.x + p.y * p.y);
  1719. };
  1720. Point.lenSquare = function (p) {
  1721. return p.x * p.x + p.y * p.y;
  1722. };
  1723. Point.dot = function (p0, p1) {
  1724. return p0.x * p1.x + p0.y * p1.y;
  1725. };
  1726. Point.add = function (out, p0, p1) {
  1727. out.x = p0.x + p1.x;
  1728. out.y = p0.y + p1.y;
  1729. };
  1730. Point.sub = function (out, p0, p1) {
  1731. out.x = p0.x - p1.x;
  1732. out.y = p0.y - p1.y;
  1733. };
  1734. Point.scale = function (out, p0, scalar) {
  1735. out.x = p0.x * scalar;
  1736. out.y = p0.y * scalar;
  1737. };
  1738. Point.scaleAndAdd = function (out, p0, p1, scalar) {
  1739. out.x = p0.x + p1.x * scalar;
  1740. out.y = p0.y + p1.y * scalar;
  1741. };
  1742. Point.lerp = function (out, p0, p1, t) {
  1743. var onet = 1 - t;
  1744. out.x = onet * p0.x + t * p1.x;
  1745. out.y = onet * p0.y + t * p1.y;
  1746. };
  1747. return Point;
  1748. }());
  1749. var mathMin = Math.min;
  1750. var mathMax = Math.max;
  1751. var mathAbs = Math.abs;
  1752. var XY = ['x', 'y'];
  1753. var WH = ['width', 'height'];
  1754. var lt = new Point();
  1755. var rb = new Point();
  1756. var lb = new Point();
  1757. var rt = new Point();
  1758. var _intersectCtx = createIntersectContext();
  1759. var _minTv = _intersectCtx.minTv;
  1760. var _maxTv = _intersectCtx.maxTv;
  1761. var _lenMinMax = [0, 0];
  1762. var BoundingRect = (function () {
  1763. function BoundingRect(x, y, width, height) {
  1764. BoundingRect.set(this, x, y, width, height);
  1765. }
  1766. BoundingRect.set = function (target, x, y, width, height) {
  1767. if (width < 0) {
  1768. x = x + width;
  1769. width = -width;
  1770. }
  1771. if (height < 0) {
  1772. y = y + height;
  1773. height = -height;
  1774. }
  1775. target.x = x;
  1776. target.y = y;
  1777. target.width = width;
  1778. target.height = height;
  1779. return target;
  1780. };
  1781. BoundingRect.prototype.union = function (other) {
  1782. var x = mathMin(other.x, this.x);
  1783. var y = mathMin(other.y, this.y);
  1784. if (isFinite(this.x) && isFinite(this.width)) {
  1785. this.width = mathMax(other.x + other.width, this.x + this.width) - x;
  1786. }
  1787. else {
  1788. this.width = other.width;
  1789. }
  1790. if (isFinite(this.y) && isFinite(this.height)) {
  1791. this.height = mathMax(other.y + other.height, this.y + this.height) - y;
  1792. }
  1793. else {
  1794. this.height = other.height;
  1795. }
  1796. this.x = x;
  1797. this.y = y;
  1798. };
  1799. BoundingRect.prototype.applyTransform = function (m) {
  1800. BoundingRect.applyTransform(this, this, m);
  1801. };
  1802. BoundingRect.prototype.calculateTransform = function (b) {
  1803. var a = this;
  1804. var sx = b.width / a.width;
  1805. var sy = b.height / a.height;
  1806. var m = create$1();
  1807. translate(m, m, [-a.x, -a.y]);
  1808. scale$1(m, m, [sx, sy]);
  1809. translate(m, m, [b.x, b.y]);
  1810. return m;
  1811. };
  1812. BoundingRect.prototype.intersect = function (b, mtv, opt) {
  1813. return BoundingRect.intersect(this, b, mtv, opt);
  1814. };
  1815. BoundingRect.intersect = function (a, b, mtv, opt) {
  1816. if (mtv) {
  1817. Point.set(mtv, 0, 0);
  1818. }
  1819. var outIntersectRect = opt && opt.outIntersectRect || null;
  1820. var clamp = opt && opt.clamp;
  1821. if (outIntersectRect) {
  1822. outIntersectRect.x = outIntersectRect.y = outIntersectRect.width = outIntersectRect.height = NaN;
  1823. }
  1824. if (!a || !b) {
  1825. return false;
  1826. }
  1827. if (!(a instanceof BoundingRect)) {
  1828. a = BoundingRect.set(_tmpIntersectA, a.x, a.y, a.width, a.height);
  1829. }
  1830. if (!(b instanceof BoundingRect)) {
  1831. b = BoundingRect.set(_tmpIntersectB, b.x, b.y, b.width, b.height);
  1832. }
  1833. var useMTV = !!mtv;
  1834. _intersectCtx.reset(opt, useMTV);
  1835. var touchThreshold = _intersectCtx.touchThreshold;
  1836. var ax0 = a.x + touchThreshold;
  1837. var ax1 = a.x + a.width - touchThreshold;
  1838. var ay0 = a.y + touchThreshold;
  1839. var ay1 = a.y + a.height - touchThreshold;
  1840. var bx0 = b.x + touchThreshold;
  1841. var bx1 = b.x + b.width - touchThreshold;
  1842. var by0 = b.y + touchThreshold;
  1843. var by1 = b.y + b.height - touchThreshold;
  1844. if (ax0 > ax1 || ay0 > ay1 || bx0 > bx1 || by0 > by1) {
  1845. return false;
  1846. }
  1847. var overlap = !(ax1 < bx0 || bx1 < ax0 || ay1 < by0 || by1 < ay0);
  1848. if (useMTV || outIntersectRect) {
  1849. _lenMinMax[0] = Infinity;
  1850. _lenMinMax[1] = 0;
  1851. intersectOneDim(ax0, ax1, bx0, bx1, 0, useMTV, outIntersectRect, clamp);
  1852. intersectOneDim(ay0, ay1, by0, by1, 1, useMTV, outIntersectRect, clamp);
  1853. if (useMTV) {
  1854. Point.copy(mtv, overlap
  1855. ? (_intersectCtx.useDir ? _intersectCtx.dirMinTv : _minTv)
  1856. : _maxTv);
  1857. }
  1858. }
  1859. return overlap;
  1860. };
  1861. BoundingRect.contain = function (rect, x, y) {
  1862. return x >= rect.x
  1863. && x <= (rect.x + rect.width)
  1864. && y >= rect.y
  1865. && y <= (rect.y + rect.height);
  1866. };
  1867. BoundingRect.prototype.contain = function (x, y) {
  1868. return BoundingRect.contain(this, x, y);
  1869. };
  1870. BoundingRect.prototype.clone = function () {
  1871. return new BoundingRect(this.x, this.y, this.width, this.height);
  1872. };
  1873. BoundingRect.prototype.copy = function (other) {
  1874. BoundingRect.copy(this, other);
  1875. };
  1876. BoundingRect.prototype.plain = function () {
  1877. return {
  1878. x: this.x,
  1879. y: this.y,
  1880. width: this.width,
  1881. height: this.height
  1882. };
  1883. };
  1884. BoundingRect.prototype.isFinite = function () {
  1885. return isFinite(this.x)
  1886. && isFinite(this.y)
  1887. && isFinite(this.width)
  1888. && isFinite(this.height);
  1889. };
  1890. BoundingRect.prototype.isZero = function () {
  1891. return this.width === 0 || this.height === 0;
  1892. };
  1893. BoundingRect.create = function (rect) {
  1894. return new BoundingRect(rect.x, rect.y, rect.width, rect.height);
  1895. };
  1896. BoundingRect.copy = function (target, source) {
  1897. target.x = source.x;
  1898. target.y = source.y;
  1899. target.width = source.width;
  1900. target.height = source.height;
  1901. return target;
  1902. };
  1903. BoundingRect.applyTransform = function (target, source, m) {
  1904. if (!m) {
  1905. if (target !== source) {
  1906. BoundingRect.copy(target, source);
  1907. }
  1908. return;
  1909. }
  1910. if (m[1] < 1e-5 && m[1] > -1e-5 && m[2] < 1e-5 && m[2] > -1e-5) {
  1911. var sx = m[0];
  1912. var sy = m[3];
  1913. var tx = m[4];
  1914. var ty = m[5];
  1915. target.x = source.x * sx + tx;
  1916. target.y = source.y * sy + ty;
  1917. target.width = source.width * sx;
  1918. target.height = source.height * sy;
  1919. if (target.width < 0) {
  1920. target.x += target.width;
  1921. target.width = -target.width;
  1922. }
  1923. if (target.height < 0) {
  1924. target.y += target.height;
  1925. target.height = -target.height;
  1926. }
  1927. return;
  1928. }
  1929. lt.x = lb.x = source.x;
  1930. lt.y = rt.y = source.y;
  1931. rb.x = rt.x = source.x + source.width;
  1932. rb.y = lb.y = source.y + source.height;
  1933. lt.transform(m);
  1934. rt.transform(m);
  1935. rb.transform(m);
  1936. lb.transform(m);
  1937. target.x = mathMin(lt.x, rb.x, lb.x, rt.x);
  1938. target.y = mathMin(lt.y, rb.y, lb.y, rt.y);
  1939. var maxX = mathMax(lt.x, rb.x, lb.x, rt.x);
  1940. var maxY = mathMax(lt.y, rb.y, lb.y, rt.y);
  1941. target.width = maxX - target.x;
  1942. target.height = maxY - target.y;
  1943. };
  1944. return BoundingRect;
  1945. }());
  1946. var _tmpIntersectA = new BoundingRect(0, 0, 0, 0);
  1947. var _tmpIntersectB = new BoundingRect(0, 0, 0, 0);
  1948. function intersectOneDim(a0, a1, b0, b1, updateDimIdx, useMTV, outIntersectRect, clamp) {
  1949. var d0 = mathAbs(a1 - b0);
  1950. var d1 = mathAbs(b1 - a0);
  1951. var d01min = mathMin(d0, d1);
  1952. var updateDim = XY[updateDimIdx];
  1953. var zeroDim = XY[1 - updateDimIdx];
  1954. var wh = WH[updateDimIdx];
  1955. if (a1 < b0 || b1 < a0) {
  1956. if (d0 < d1) {
  1957. if (useMTV) {
  1958. _maxTv[updateDim] = -d0;
  1959. }
  1960. if (clamp) {
  1961. outIntersectRect[updateDim] = a1;
  1962. outIntersectRect[wh] = 0;
  1963. }
  1964. }
  1965. else {
  1966. if (useMTV) {
  1967. _maxTv[updateDim] = d1;
  1968. }
  1969. if (clamp) {
  1970. outIntersectRect[updateDim] = a0;
  1971. outIntersectRect[wh] = 0;
  1972. }
  1973. }
  1974. }
  1975. else {
  1976. if (outIntersectRect) {
  1977. outIntersectRect[updateDim] = mathMax(a0, b0);
  1978. outIntersectRect[wh] = mathMin(a1, b1) - outIntersectRect[updateDim];
  1979. }
  1980. if (useMTV) {
  1981. if (d01min < _lenMinMax[0] || _intersectCtx.useDir) {
  1982. _lenMinMax[0] = mathMin(d01min, _lenMinMax[0]);
  1983. if (d0 < d1 || !_intersectCtx.bidirectional) {
  1984. _minTv[updateDim] = d0;
  1985. _minTv[zeroDim] = 0;
  1986. if (_intersectCtx.useDir) {
  1987. _intersectCtx.calcDirMTV();
  1988. }
  1989. }
  1990. if (d0 >= d1 || !_intersectCtx.bidirectional) {
  1991. _minTv[updateDim] = -d1;
  1992. _minTv[zeroDim] = 0;
  1993. if (_intersectCtx.useDir) {
  1994. _intersectCtx.calcDirMTV();
  1995. }
  1996. }
  1997. }
  1998. }
  1999. }
  2000. }
  2001. function createIntersectContext() {
  2002. var _direction = 0;
  2003. var _dirCheckVec = new Point();
  2004. var _dirTmp = new Point();
  2005. var _ctx = {
  2006. minTv: new Point(),
  2007. maxTv: new Point(),
  2008. useDir: false,
  2009. dirMinTv: new Point(),
  2010. touchThreshold: 0,
  2011. bidirectional: true,
  2012. negativeSize: false,
  2013. reset: function (opt, useMTV) {
  2014. _ctx.touchThreshold = 0;
  2015. if (opt && opt.touchThreshold != null) {
  2016. _ctx.touchThreshold = mathMax(0, opt.touchThreshold);
  2017. }
  2018. _ctx.negativeSize = false;
  2019. if (!useMTV) {
  2020. return;
  2021. }
  2022. _ctx.minTv.set(Infinity, Infinity);
  2023. _ctx.maxTv.set(0, 0);
  2024. _ctx.useDir = false;
  2025. if (opt && opt.direction != null) {
  2026. _ctx.useDir = true;
  2027. _ctx.dirMinTv.copy(_ctx.minTv);
  2028. _dirTmp.copy(_ctx.minTv);
  2029. _direction = opt.direction;
  2030. _ctx.bidirectional = opt.bidirectional == null || !!opt.bidirectional;
  2031. if (!_ctx.bidirectional) {
  2032. _dirCheckVec.set(Math.cos(_direction), Math.sin(_direction));
  2033. }
  2034. }
  2035. },
  2036. calcDirMTV: function () {
  2037. var minTv = _ctx.minTv;
  2038. var dirMinTv = _ctx.dirMinTv;
  2039. var squareMag = minTv.y * minTv.y + minTv.x * minTv.x;
  2040. var dirSin = Math.sin(_direction);
  2041. var dirCos = Math.cos(_direction);
  2042. var dotProd = dirSin * minTv.y + dirCos * minTv.x;
  2043. if (nearZero(dotProd)) {
  2044. if (nearZero(minTv.x) && nearZero(minTv.y)) {
  2045. dirMinTv.set(0, 0);
  2046. }
  2047. return;
  2048. }
  2049. _dirTmp.x = squareMag * dirCos / dotProd;
  2050. _dirTmp.y = squareMag * dirSin / dotProd;
  2051. if (nearZero(_dirTmp.x) && nearZero(_dirTmp.y)) {
  2052. dirMinTv.set(0, 0);
  2053. return;
  2054. }
  2055. if ((_ctx.bidirectional
  2056. || _dirCheckVec.dot(_dirTmp) > 0)
  2057. && _dirTmp.len() < dirMinTv.len()) {
  2058. dirMinTv.copy(_dirTmp);
  2059. }
  2060. }
  2061. };
  2062. function nearZero(val) {
  2063. return mathAbs(val) < 1e-10;
  2064. }
  2065. return _ctx;
  2066. }
  2067. var SILENT = 'silent';
  2068. function makeEventPacket(eveType, targetInfo, event) {
  2069. return {
  2070. type: eveType,
  2071. event: event,
  2072. target: targetInfo.target,
  2073. topTarget: targetInfo.topTarget,
  2074. cancelBubble: false,
  2075. offsetX: event.zrX,
  2076. offsetY: event.zrY,
  2077. gestureEvent: event.gestureEvent,
  2078. pinchX: event.pinchX,
  2079. pinchY: event.pinchY,
  2080. pinchScale: event.pinchScale,
  2081. wheelDelta: event.zrDelta,
  2082. zrByTouch: event.zrByTouch,
  2083. which: event.which,
  2084. stop: stopEvent
  2085. };
  2086. }
  2087. function stopEvent() {
  2088. stop(this.event);
  2089. }
  2090. var EmptyProxy = (function (_super) {
  2091. __extends(EmptyProxy, _super);
  2092. function EmptyProxy() {
  2093. var _this = _super !== null && _super.apply(this, arguments) || this;
  2094. _this.handler = null;
  2095. return _this;
  2096. }
  2097. EmptyProxy.prototype.dispose = function () { };
  2098. EmptyProxy.prototype.setCursor = function () { };
  2099. return EmptyProxy;
  2100. }(Eventful));
  2101. var HoveredResult = (function () {
  2102. function HoveredResult(x, y) {
  2103. this.x = x;
  2104. this.y = y;
  2105. }
  2106. return HoveredResult;
  2107. }());
  2108. var handlerNames = [
  2109. 'click', 'dblclick', 'mousewheel', 'mouseout',
  2110. 'mouseup', 'mousedown', 'mousemove', 'contextmenu'
  2111. ];
  2112. var tmpRect = new BoundingRect(0, 0, 0, 0);
  2113. var Handler = (function (_super) {
  2114. __extends(Handler, _super);
  2115. function Handler(storage, painter, proxy, painterRoot, pointerSize) {
  2116. var _this = _super.call(this) || this;
  2117. _this._hovered = new HoveredResult(0, 0);
  2118. _this.storage = storage;
  2119. _this.painter = painter;
  2120. _this.painterRoot = painterRoot;
  2121. _this._pointerSize = pointerSize;
  2122. proxy = proxy || new EmptyProxy();
  2123. _this.proxy = null;
  2124. _this.setHandlerProxy(proxy);
  2125. _this._draggingMgr = new Draggable(_this);
  2126. return _this;
  2127. }
  2128. Handler.prototype.setHandlerProxy = function (proxy) {
  2129. if (this.proxy) {
  2130. this.proxy.dispose();
  2131. }
  2132. if (proxy) {
  2133. each(handlerNames, function (name) {
  2134. proxy.on && proxy.on(name, this[name], this);
  2135. }, this);
  2136. proxy.handler = this;
  2137. }
  2138. this.proxy = proxy;
  2139. };
  2140. Handler.prototype.mousemove = function (event) {
  2141. var x = event.zrX;
  2142. var y = event.zrY;
  2143. var isOutside = isOutsideBoundary(this, x, y);
  2144. var lastHovered = this._hovered;
  2145. var lastHoveredTarget = lastHovered.target;
  2146. if (lastHoveredTarget && !lastHoveredTarget.__zr) {
  2147. lastHovered = this.findHover(lastHovered.x, lastHovered.y);
  2148. lastHoveredTarget = lastHovered.target;
  2149. }
  2150. var hovered = this._hovered = isOutside ? new HoveredResult(x, y) : this.findHover(x, y);
  2151. var hoveredTarget = hovered.target;
  2152. var proxy = this.proxy;
  2153. proxy.setCursor && proxy.setCursor(hoveredTarget ? hoveredTarget.cursor : 'default');
  2154. if (lastHoveredTarget && hoveredTarget !== lastHoveredTarget) {
  2155. this.dispatchToElement(lastHovered, 'mouseout', event);
  2156. }
  2157. this.dispatchToElement(hovered, 'mousemove', event);
  2158. if (hoveredTarget && hoveredTarget !== lastHoveredTarget) {
  2159. this.dispatchToElement(hovered, 'mouseover', event);
  2160. }
  2161. };
  2162. Handler.prototype.mouseout = function (event) {
  2163. var eventControl = event.zrEventControl;
  2164. if (eventControl !== 'only_globalout') {
  2165. this.dispatchToElement(this._hovered, 'mouseout', event);
  2166. }
  2167. if (eventControl !== 'no_globalout') {
  2168. this.trigger('globalout', { type: 'globalout', event: event });
  2169. }
  2170. };
  2171. Handler.prototype.resize = function () {
  2172. this._hovered = new HoveredResult(0, 0);
  2173. };
  2174. Handler.prototype.dispatch = function (eventName, eventArgs) {
  2175. var handler = this[eventName];
  2176. handler && handler.call(this, eventArgs);
  2177. };
  2178. Handler.prototype.dispose = function () {
  2179. this.proxy.dispose();
  2180. this.storage = null;
  2181. this.proxy = null;
  2182. this.painter = null;
  2183. };
  2184. Handler.prototype.setCursorStyle = function (cursorStyle) {
  2185. var proxy = this.proxy;
  2186. proxy.setCursor && proxy.setCursor(cursorStyle);
  2187. };
  2188. Handler.prototype.dispatchToElement = function (targetInfo, eventName, event) {
  2189. targetInfo = targetInfo || {};
  2190. var el = targetInfo.target;
  2191. if (el && el.silent) {
  2192. return;
  2193. }
  2194. var eventKey = ('on' + eventName);
  2195. var eventPacket = makeEventPacket(eventName, targetInfo, event);
  2196. while (el) {
  2197. el[eventKey]
  2198. && (eventPacket.cancelBubble = !!el[eventKey].call(el, eventPacket));
  2199. el.trigger(eventName, eventPacket);
  2200. el = el.__hostTarget ? el.__hostTarget : el.parent;
  2201. if (eventPacket.cancelBubble) {
  2202. break;
  2203. }
  2204. }
  2205. if (!eventPacket.cancelBubble) {
  2206. this.trigger(eventName, eventPacket);
  2207. if (this.painter && this.painter.eachOtherLayer) {
  2208. this.painter.eachOtherLayer(function (layer) {
  2209. if (typeof (layer[eventKey]) === 'function') {
  2210. layer[eventKey].call(layer, eventPacket);
  2211. }
  2212. if (layer.trigger) {
  2213. layer.trigger(eventName, eventPacket);
  2214. }
  2215. });
  2216. }
  2217. }
  2218. };
  2219. Handler.prototype.findHover = function (x, y, exclude) {
  2220. var list = this.storage.getDisplayList();
  2221. var out = new HoveredResult(x, y);
  2222. setHoverTarget(list, out, x, y, exclude);
  2223. if (this._pointerSize && !out.target) {
  2224. var candidates = [];
  2225. var pointerSize = this._pointerSize;
  2226. var targetSizeHalf = pointerSize / 2;
  2227. var pointerRect = new BoundingRect(x - targetSizeHalf, y - targetSizeHalf, pointerSize, pointerSize);
  2228. for (var i = list.length - 1; i >= 0; i--) {
  2229. var el = list[i];
  2230. if (el !== exclude
  2231. && !el.ignore
  2232. && !el.ignoreCoarsePointer
  2233. && (!el.parent || !el.parent.ignoreCoarsePointer)) {
  2234. tmpRect.copy(el.getBoundingRect());
  2235. if (el.transform) {
  2236. tmpRect.applyTransform(el.transform);
  2237. }
  2238. if (tmpRect.intersect(pointerRect)) {
  2239. candidates.push(el);
  2240. }
  2241. }
  2242. }
  2243. if (candidates.length) {
  2244. var rStep = 4;
  2245. var thetaStep = Math.PI / 12;
  2246. var PI2 = Math.PI * 2;
  2247. for (var r = 0; r < targetSizeHalf; r += rStep) {
  2248. for (var theta = 0; theta < PI2; theta += thetaStep) {
  2249. var x1 = x + r * Math.cos(theta);
  2250. var y1 = y + r * Math.sin(theta);
  2251. setHoverTarget(candidates, out, x1, y1, exclude);
  2252. if (out.target) {
  2253. return out;
  2254. }
  2255. }
  2256. }
  2257. }
  2258. }
  2259. return out;
  2260. };
  2261. Handler.prototype.processGesture = function (event, stage) {
  2262. if (!this._gestureMgr) {
  2263. this._gestureMgr = new GestureMgr();
  2264. }
  2265. var gestureMgr = this._gestureMgr;
  2266. stage === 'start' && gestureMgr.clear();
  2267. var gestureInfo = gestureMgr.recognize(event, this.findHover(event.zrX, event.zrY, null).target, this.proxy.dom);
  2268. stage === 'end' && gestureMgr.clear();
  2269. if (gestureInfo) {
  2270. var type = gestureInfo.type;
  2271. event.gestureEvent = type;
  2272. var res = new HoveredResult();
  2273. res.target = gestureInfo.target;
  2274. this.dispatchToElement(res, type, gestureInfo.event);
  2275. }
  2276. };
  2277. return Handler;
  2278. }(Eventful));
  2279. each(['click', 'mousedown', 'mouseup', 'mousewheel', 'dblclick', 'contextmenu'], function (name) {
  2280. Handler.prototype[name] = function (event) {
  2281. var x = event.zrX;
  2282. var y = event.zrY;
  2283. var isOutside = isOutsideBoundary(this, x, y);
  2284. var hovered;
  2285. var hoveredTarget;
  2286. if (name !== 'mouseup' || !isOutside) {
  2287. hovered = this.findHover(x, y);
  2288. hoveredTarget = hovered.target;
  2289. }
  2290. if (name === 'mousedown') {
  2291. this._downEl = hoveredTarget;
  2292. this._downPoint = [event.zrX, event.zrY];
  2293. this._upEl = hoveredTarget;
  2294. }
  2295. else if (name === 'mouseup') {
  2296. this._upEl = hoveredTarget;
  2297. }
  2298. else if (name === 'click') {
  2299. if (this._downEl !== this._upEl
  2300. || !this._downPoint
  2301. || dist(this._downPoint, [event.zrX, event.zrY]) > 4) {
  2302. return;
  2303. }
  2304. this._downPoint = null;
  2305. }
  2306. this.dispatchToElement(hovered, name, event);
  2307. };
  2308. });
  2309. function isHover(displayable, x, y) {
  2310. if (displayable[displayable.rectHover ? 'rectContain' : 'contain'](x, y)) {
  2311. var el = displayable;
  2312. var isSilent = void 0;
  2313. var ignoreClip = false;
  2314. while (el) {
  2315. if (el.ignoreClip) {
  2316. ignoreClip = true;
  2317. }
  2318. if (!ignoreClip) {
  2319. var clipPath = el.getClipPath();
  2320. if (clipPath && !clipPath.contain(x, y)) {
  2321. return false;
  2322. }
  2323. }
  2324. if (el.silent) {
  2325. isSilent = true;
  2326. }
  2327. var hostEl = el.__hostTarget;
  2328. el = hostEl ? (el.ignoreHostSilent ? null : hostEl) : el.parent;
  2329. }
  2330. return isSilent ? SILENT : true;
  2331. }
  2332. return false;
  2333. }
  2334. function setHoverTarget(list, out, x, y, exclude) {
  2335. for (var i = list.length - 1; i >= 0; i--) {
  2336. var el = list[i];
  2337. var hoverCheckResult = void 0;
  2338. if (el !== exclude
  2339. && !el.ignore
  2340. && (hoverCheckResult = isHover(el, x, y))) {
  2341. !out.topTarget && (out.topTarget = el);
  2342. if (hoverCheckResult !== SILENT) {
  2343. out.target = el;
  2344. break;
  2345. }
  2346. }
  2347. }
  2348. }
  2349. function isOutsideBoundary(handlerInstance, x, y) {
  2350. var painter = handlerInstance.painter;
  2351. return x < 0 || x > painter.getWidth() || y < 0 || y > painter.getHeight();
  2352. }
  2353. var DEFAULT_MIN_MERGE = 32;
  2354. var DEFAULT_MIN_GALLOPING = 7;
  2355. function minRunLength(n) {
  2356. var r = 0;
  2357. while (n >= DEFAULT_MIN_MERGE) {
  2358. r |= n & 1;
  2359. n >>= 1;
  2360. }
  2361. return n + r;
  2362. }
  2363. function makeAscendingRun(array, lo, hi, compare) {
  2364. var runHi = lo + 1;
  2365. if (runHi === hi) {
  2366. return 1;
  2367. }
  2368. if (compare(array[runHi++], array[lo]) < 0) {
  2369. while (runHi < hi && compare(array[runHi], array[runHi - 1]) < 0) {
  2370. runHi++;
  2371. }
  2372. reverseRun(array, lo, runHi);
  2373. }
  2374. else {
  2375. while (runHi < hi && compare(array[runHi], array[runHi - 1]) >= 0) {
  2376. runHi++;
  2377. }
  2378. }
  2379. return runHi - lo;
  2380. }
  2381. function reverseRun(array, lo, hi) {
  2382. hi--;
  2383. while (lo < hi) {
  2384. var t = array[lo];
  2385. array[lo++] = array[hi];
  2386. array[hi--] = t;
  2387. }
  2388. }
  2389. function binaryInsertionSort(array, lo, hi, start, compare) {
  2390. if (start === lo) {
  2391. start++;
  2392. }
  2393. for (; start < hi; start++) {
  2394. var pivot = array[start];
  2395. var left = lo;
  2396. var right = start;
  2397. var mid;
  2398. while (left < right) {
  2399. mid = left + right >>> 1;
  2400. if (compare(pivot, array[mid]) < 0) {
  2401. right = mid;
  2402. }
  2403. else {
  2404. left = mid + 1;
  2405. }
  2406. }
  2407. var n = start - left;
  2408. switch (n) {
  2409. case 3:
  2410. array[left + 3] = array[left + 2];
  2411. case 2:
  2412. array[left + 2] = array[left + 1];
  2413. case 1:
  2414. array[left + 1] = array[left];
  2415. break;
  2416. default:
  2417. while (n > 0) {
  2418. array[left + n] = array[left + n - 1];
  2419. n--;
  2420. }
  2421. }
  2422. array[left] = pivot;
  2423. }
  2424. }
  2425. function gallopLeft(value, array, start, length, hint, compare) {
  2426. var lastOffset = 0;
  2427. var maxOffset = 0;
  2428. var offset = 1;
  2429. if (compare(value, array[start + hint]) > 0) {
  2430. maxOffset = length - hint;
  2431. while (offset < maxOffset && compare(value, array[start + hint + offset]) > 0) {
  2432. lastOffset = offset;
  2433. offset = (offset << 1) + 1;
  2434. if (offset <= 0) {
  2435. offset = maxOffset;
  2436. }
  2437. }
  2438. if (offset > maxOffset) {
  2439. offset = maxOffset;
  2440. }
  2441. lastOffset += hint;
  2442. offset += hint;
  2443. }
  2444. else {
  2445. maxOffset = hint + 1;
  2446. while (offset < maxOffset && compare(value, array[start + hint - offset]) <= 0) {
  2447. lastOffset = offset;
  2448. offset = (offset << 1) + 1;
  2449. if (offset <= 0) {
  2450. offset = maxOffset;
  2451. }
  2452. }
  2453. if (offset > maxOffset) {
  2454. offset = maxOffset;
  2455. }
  2456. var tmp = lastOffset;
  2457. lastOffset = hint - offset;
  2458. offset = hint - tmp;
  2459. }
  2460. lastOffset++;
  2461. while (lastOffset < offset) {
  2462. var m = lastOffset + (offset - lastOffset >>> 1);
  2463. if (compare(value, array[start + m]) > 0) {
  2464. lastOffset = m + 1;
  2465. }
  2466. else {
  2467. offset = m;
  2468. }
  2469. }
  2470. return offset;
  2471. }
  2472. function gallopRight(value, array, start, length, hint, compare) {
  2473. var lastOffset = 0;
  2474. var maxOffset = 0;
  2475. var offset = 1;
  2476. if (compare(value, array[start + hint]) < 0) {
  2477. maxOffset = hint + 1;
  2478. while (offset < maxOffset && compare(value, array[start + hint - offset]) < 0) {
  2479. lastOffset = offset;
  2480. offset = (offset << 1) + 1;
  2481. if (offset <= 0) {
  2482. offset = maxOffset;
  2483. }
  2484. }
  2485. if (offset > maxOffset) {
  2486. offset = maxOffset;
  2487. }
  2488. var tmp = lastOffset;
  2489. lastOffset = hint - offset;
  2490. offset = hint - tmp;
  2491. }
  2492. else {
  2493. maxOffset = length - hint;
  2494. while (offset < maxOffset && compare(value, array[start + hint + offset]) >= 0) {
  2495. lastOffset = offset;
  2496. offset = (offset << 1) + 1;
  2497. if (offset <= 0) {
  2498. offset = maxOffset;
  2499. }
  2500. }
  2501. if (offset > maxOffset) {
  2502. offset = maxOffset;
  2503. }
  2504. lastOffset += hint;
  2505. offset += hint;
  2506. }
  2507. lastOffset++;
  2508. while (lastOffset < offset) {
  2509. var m = lastOffset + (offset - lastOffset >>> 1);
  2510. if (compare(value, array[start + m]) < 0) {
  2511. offset = m;
  2512. }
  2513. else {
  2514. lastOffset = m + 1;
  2515. }
  2516. }
  2517. return offset;
  2518. }
  2519. function TimSort(array, compare) {
  2520. var minGallop = DEFAULT_MIN_GALLOPING;
  2521. var runStart;
  2522. var runLength;
  2523. var stackSize = 0;
  2524. var tmp = [];
  2525. runStart = [];
  2526. runLength = [];
  2527. function pushRun(_runStart, _runLength) {
  2528. runStart[stackSize] = _runStart;
  2529. runLength[stackSize] = _runLength;
  2530. stackSize += 1;
  2531. }
  2532. function mergeRuns() {
  2533. while (stackSize > 1) {
  2534. var n = stackSize - 2;
  2535. if ((n >= 1 && runLength[n - 1] <= runLength[n] + runLength[n + 1])
  2536. || (n >= 2 && runLength[n - 2] <= runLength[n] + runLength[n - 1])) {
  2537. if (runLength[n - 1] < runLength[n + 1]) {
  2538. n--;
  2539. }
  2540. }
  2541. else if (runLength[n] > runLength[n + 1]) {
  2542. break;
  2543. }
  2544. mergeAt(n);
  2545. }
  2546. }
  2547. function forceMergeRuns() {
  2548. while (stackSize > 1) {
  2549. var n = stackSize - 2;
  2550. if (n > 0 && runLength[n - 1] < runLength[n + 1]) {
  2551. n--;
  2552. }
  2553. mergeAt(n);
  2554. }
  2555. }
  2556. function mergeAt(i) {
  2557. var start1 = runStart[i];
  2558. var length1 = runLength[i];
  2559. var start2 = runStart[i + 1];
  2560. var length2 = runLength[i + 1];
  2561. runLength[i] = length1 + length2;
  2562. if (i === stackSize - 3) {
  2563. runStart[i + 1] = runStart[i + 2];
  2564. runLength[i + 1] = runLength[i + 2];
  2565. }
  2566. stackSize--;
  2567. var k = gallopRight(array[start2], array, start1, length1, 0, compare);
  2568. start1 += k;
  2569. length1 -= k;
  2570. if (length1 === 0) {
  2571. return;
  2572. }
  2573. length2 = gallopLeft(array[start1 + length1 - 1], array, start2, length2, length2 - 1, compare);
  2574. if (length2 === 0) {
  2575. return;
  2576. }
  2577. if (length1 <= length2) {
  2578. mergeLow(start1, length1, start2, length2);
  2579. }
  2580. else {
  2581. mergeHigh(start1, length1, start2, length2);
  2582. }
  2583. }
  2584. function mergeLow(start1, length1, start2, length2) {
  2585. var i = 0;
  2586. for (i = 0; i < length1; i++) {
  2587. tmp[i] = array[start1 + i];
  2588. }
  2589. var cursor1 = 0;
  2590. var cursor2 = start2;
  2591. var dest = start1;
  2592. array[dest++] = array[cursor2++];
  2593. if (--length2 === 0) {
  2594. for (i = 0; i < length1; i++) {
  2595. array[dest + i] = tmp[cursor1 + i];
  2596. }
  2597. return;
  2598. }
  2599. if (length1 === 1) {
  2600. for (i = 0; i < length2; i++) {
  2601. array[dest + i] = array[cursor2 + i];
  2602. }
  2603. array[dest + length2] = tmp[cursor1];
  2604. return;
  2605. }
  2606. var _minGallop = minGallop;
  2607. var count1;
  2608. var count2;
  2609. var exit;
  2610. while (1) {
  2611. count1 = 0;
  2612. count2 = 0;
  2613. exit = false;
  2614. do {
  2615. if (compare(array[cursor2], tmp[cursor1]) < 0) {
  2616. array[dest++] = array[cursor2++];
  2617. count2++;
  2618. count1 = 0;
  2619. if (--length2 === 0) {
  2620. exit = true;
  2621. break;
  2622. }
  2623. }
  2624. else {
  2625. array[dest++] = tmp[cursor1++];
  2626. count1++;
  2627. count2 = 0;
  2628. if (--length1 === 1) {
  2629. exit = true;
  2630. break;
  2631. }
  2632. }
  2633. } while ((count1 | count2) < _minGallop);
  2634. if (exit) {
  2635. break;
  2636. }
  2637. do {
  2638. count1 = gallopRight(array[cursor2], tmp, cursor1, length1, 0, compare);
  2639. if (count1 !== 0) {
  2640. for (i = 0; i < count1; i++) {
  2641. array[dest + i] = tmp[cursor1 + i];
  2642. }
  2643. dest += count1;
  2644. cursor1 += count1;
  2645. length1 -= count1;
  2646. if (length1 <= 1) {
  2647. exit = true;
  2648. break;
  2649. }
  2650. }
  2651. array[dest++] = array[cursor2++];
  2652. if (--length2 === 0) {
  2653. exit = true;
  2654. break;
  2655. }
  2656. count2 = gallopLeft(tmp[cursor1], array, cursor2, length2, 0, compare);
  2657. if (count2 !== 0) {
  2658. for (i = 0; i < count2; i++) {
  2659. array[dest + i] = array[cursor2 + i];
  2660. }
  2661. dest += count2;
  2662. cursor2 += count2;
  2663. length2 -= count2;
  2664. if (length2 === 0) {
  2665. exit = true;
  2666. break;
  2667. }
  2668. }
  2669. array[dest++] = tmp[cursor1++];
  2670. if (--length1 === 1) {
  2671. exit = true;
  2672. break;
  2673. }
  2674. _minGallop--;
  2675. } while (count1 >= DEFAULT_MIN_GALLOPING || count2 >= DEFAULT_MIN_GALLOPING);
  2676. if (exit) {
  2677. break;
  2678. }
  2679. if (_minGallop < 0) {
  2680. _minGallop = 0;
  2681. }
  2682. _minGallop += 2;
  2683. }
  2684. minGallop = _minGallop;
  2685. minGallop < 1 && (minGallop = 1);
  2686. if (length1 === 1) {
  2687. for (i = 0; i < length2; i++) {
  2688. array[dest + i] = array[cursor2 + i];
  2689. }
  2690. array[dest + length2] = tmp[cursor1];
  2691. }
  2692. else if (length1 === 0) {
  2693. throw new Error();
  2694. }
  2695. else {
  2696. for (i = 0; i < length1; i++) {
  2697. array[dest + i] = tmp[cursor1 + i];
  2698. }
  2699. }
  2700. }
  2701. function mergeHigh(start1, length1, start2, length2) {
  2702. var i = 0;
  2703. for (i = 0; i < length2; i++) {
  2704. tmp[i] = array[start2 + i];
  2705. }
  2706. var cursor1 = start1 + length1 - 1;
  2707. var cursor2 = length2 - 1;
  2708. var dest = start2 + length2 - 1;
  2709. var customCursor = 0;
  2710. var customDest = 0;
  2711. array[dest--] = array[cursor1--];
  2712. if (--length1 === 0) {
  2713. customCursor = dest - (length2 - 1);
  2714. for (i = 0; i < length2; i++) {
  2715. array[customCursor + i] = tmp[i];
  2716. }
  2717. return;
  2718. }
  2719. if (length2 === 1) {
  2720. dest -= length1;
  2721. cursor1 -= length1;
  2722. customDest = dest + 1;
  2723. customCursor = cursor1 + 1;
  2724. for (i = length1 - 1; i >= 0; i--) {
  2725. array[customDest + i] = array[customCursor + i];
  2726. }
  2727. array[dest] = tmp[cursor2];
  2728. return;
  2729. }
  2730. var _minGallop = minGallop;
  2731. while (true) {
  2732. var count1 = 0;
  2733. var count2 = 0;
  2734. var exit = false;
  2735. do {
  2736. if (compare(tmp[cursor2], array[cursor1]) < 0) {
  2737. array[dest--] = array[cursor1--];
  2738. count1++;
  2739. count2 = 0;
  2740. if (--length1 === 0) {
  2741. exit = true;
  2742. break;
  2743. }
  2744. }
  2745. else {
  2746. array[dest--] = tmp[cursor2--];
  2747. count2++;
  2748. count1 = 0;
  2749. if (--length2 === 1) {
  2750. exit = true;
  2751. break;
  2752. }
  2753. }
  2754. } while ((count1 | count2) < _minGallop);
  2755. if (exit) {
  2756. break;
  2757. }
  2758. do {
  2759. count1 = length1 - gallopRight(tmp[cursor2], array, start1, length1, length1 - 1, compare);
  2760. if (count1 !== 0) {
  2761. dest -= count1;
  2762. cursor1 -= count1;
  2763. length1 -= count1;
  2764. customDest = dest + 1;
  2765. customCursor = cursor1 + 1;
  2766. for (i = count1 - 1; i >= 0; i--) {
  2767. array[customDest + i] = array[customCursor + i];
  2768. }
  2769. if (length1 === 0) {
  2770. exit = true;
  2771. break;
  2772. }
  2773. }
  2774. array[dest--] = tmp[cursor2--];
  2775. if (--length2 === 1) {
  2776. exit = true;
  2777. break;
  2778. }
  2779. count2 = length2 - gallopLeft(array[cursor1], tmp, 0, length2, length2 - 1, compare);
  2780. if (count2 !== 0) {
  2781. dest -= count2;
  2782. cursor2 -= count2;
  2783. length2 -= count2;
  2784. customDest = dest + 1;
  2785. customCursor = cursor2 + 1;
  2786. for (i = 0; i < count2; i++) {
  2787. array[customDest + i] = tmp[customCursor + i];
  2788. }
  2789. if (length2 <= 1) {
  2790. exit = true;
  2791. break;
  2792. }
  2793. }
  2794. array[dest--] = array[cursor1--];
  2795. if (--length1 === 0) {
  2796. exit = true;
  2797. break;
  2798. }
  2799. _minGallop--;
  2800. } while (count1 >= DEFAULT_MIN_GALLOPING || count2 >= DEFAULT_MIN_GALLOPING);
  2801. if (exit) {
  2802. break;
  2803. }
  2804. if (_minGallop < 0) {
  2805. _minGallop = 0;
  2806. }
  2807. _minGallop += 2;
  2808. }
  2809. minGallop = _minGallop;
  2810. if (minGallop < 1) {
  2811. minGallop = 1;
  2812. }
  2813. if (length2 === 1) {
  2814. dest -= length1;
  2815. cursor1 -= length1;
  2816. customDest = dest + 1;
  2817. customCursor = cursor1 + 1;
  2818. for (i = length1 - 1; i >= 0; i--) {
  2819. array[customDest + i] = array[customCursor + i];
  2820. }
  2821. array[dest] = tmp[cursor2];
  2822. }
  2823. else if (length2 === 0) {
  2824. throw new Error();
  2825. }
  2826. else {
  2827. customCursor = dest - (length2 - 1);
  2828. for (i = 0; i < length2; i++) {
  2829. array[customCursor + i] = tmp[i];
  2830. }
  2831. }
  2832. }
  2833. return {
  2834. mergeRuns: mergeRuns,
  2835. forceMergeRuns: forceMergeRuns,
  2836. pushRun: pushRun
  2837. };
  2838. }
  2839. function sort(array, compare, lo, hi) {
  2840. if (!lo) {
  2841. lo = 0;
  2842. }
  2843. if (!hi) {
  2844. hi = array.length;
  2845. }
  2846. var remaining = hi - lo;
  2847. if (remaining < 2) {
  2848. return;
  2849. }
  2850. var runLength = 0;
  2851. if (remaining < DEFAULT_MIN_MERGE) {
  2852. runLength = makeAscendingRun(array, lo, hi, compare);
  2853. binaryInsertionSort(array, lo, hi, lo + runLength, compare);
  2854. return;
  2855. }
  2856. var ts = TimSort(array, compare);
  2857. var minRun = minRunLength(remaining);
  2858. do {
  2859. runLength = makeAscendingRun(array, lo, hi, compare);
  2860. if (runLength < minRun) {
  2861. var force = remaining;
  2862. if (force > minRun) {
  2863. force = minRun;
  2864. }
  2865. binaryInsertionSort(array, lo, lo + force, lo + runLength, compare);
  2866. runLength = force;
  2867. }
  2868. ts.pushRun(lo, runLength);
  2869. ts.mergeRuns();
  2870. remaining -= runLength;
  2871. lo += runLength;
  2872. } while (remaining !== 0);
  2873. ts.forceMergeRuns();
  2874. }
  2875. var REDRAW_BIT = 1;
  2876. var STYLE_CHANGED_BIT = 2;
  2877. var SHAPE_CHANGED_BIT = 4;
  2878. var invalidZErrorLogged = false;
  2879. function logInvalidZError() {
  2880. if (invalidZErrorLogged) {
  2881. return;
  2882. }
  2883. invalidZErrorLogged = true;
  2884. console.warn('z / z2 / zlevel of displayable is invalid, which may cause unexpected errors');
  2885. }
  2886. function shapeCompareFunc(a, b) {
  2887. if (a.zlevel === b.zlevel) {
  2888. if (a.z === b.z) {
  2889. return a.z2 - b.z2;
  2890. }
  2891. return a.z - b.z;
  2892. }
  2893. return a.zlevel - b.zlevel;
  2894. }
  2895. var Storage = (function () {
  2896. function Storage() {
  2897. this._roots = [];
  2898. this._displayList = [];
  2899. this._displayListLen = 0;
  2900. this.displayableSortFunc = shapeCompareFunc;
  2901. }
  2902. Storage.prototype.traverse = function (cb, context) {
  2903. for (var i = 0; i < this._roots.length; i++) {
  2904. this._roots[i].traverse(cb, context);
  2905. }
  2906. };
  2907. Storage.prototype.getDisplayList = function (update, includeIgnore) {
  2908. includeIgnore = includeIgnore || false;
  2909. var displayList = this._displayList;
  2910. if (update || !displayList.length) {
  2911. this.updateDisplayList(includeIgnore);
  2912. }
  2913. return displayList;
  2914. };
  2915. Storage.prototype.updateDisplayList = function (includeIgnore) {
  2916. this._displayListLen = 0;
  2917. var roots = this._roots;
  2918. var displayList = this._displayList;
  2919. for (var i = 0, len = roots.length; i < len; i++) {
  2920. this._updateAndAddDisplayable(roots[i], null, includeIgnore);
  2921. }
  2922. displayList.length = this._displayListLen;
  2923. sort(displayList, shapeCompareFunc);
  2924. };
  2925. Storage.prototype._updateAndAddDisplayable = function (el, parentClipPaths, includeIgnore) {
  2926. if (el.ignore && !includeIgnore) {
  2927. return;
  2928. }
  2929. el.beforeUpdate();
  2930. el.update();
  2931. el.afterUpdate();
  2932. var userSetClipPath = el.getClipPath();
  2933. var parentHasClipPaths = parentClipPaths && parentClipPaths.length;
  2934. var clipPathIdx = 0;
  2935. var thisClipPaths = el.__clipPaths;
  2936. if (!el.ignoreClip
  2937. && (parentHasClipPaths || userSetClipPath)) {
  2938. if (!thisClipPaths) {
  2939. thisClipPaths = el.__clipPaths = [];
  2940. }
  2941. if (parentHasClipPaths) {
  2942. for (var idx = 0; idx < parentClipPaths.length; idx++) {
  2943. thisClipPaths[clipPathIdx++] = parentClipPaths[idx];
  2944. }
  2945. }
  2946. var currentClipPath = userSetClipPath;
  2947. var parentClipPath = el;
  2948. while (currentClipPath) {
  2949. currentClipPath.parent = parentClipPath;
  2950. currentClipPath.updateTransform();
  2951. thisClipPaths[clipPathIdx++] = currentClipPath;
  2952. parentClipPath = currentClipPath;
  2953. currentClipPath = currentClipPath.getClipPath();
  2954. }
  2955. }
  2956. if (thisClipPaths) {
  2957. thisClipPaths.length = clipPathIdx;
  2958. }
  2959. if (el.childrenRef) {
  2960. var children = el.childrenRef();
  2961. for (var i = 0; i < children.length; i++) {
  2962. var child = children[i];
  2963. if (el.__dirty) {
  2964. child.__dirty |= REDRAW_BIT;
  2965. }
  2966. this._updateAndAddDisplayable(child, thisClipPaths, includeIgnore);
  2967. }
  2968. el.__dirty = 0;
  2969. }
  2970. else {
  2971. var disp = el;
  2972. if (isNaN(disp.z)) {
  2973. logInvalidZError();
  2974. disp.z = 0;
  2975. }
  2976. if (isNaN(disp.z2)) {
  2977. logInvalidZError();
  2978. disp.z2 = 0;
  2979. }
  2980. if (isNaN(disp.zlevel)) {
  2981. logInvalidZError();
  2982. disp.zlevel = 0;
  2983. }
  2984. this._displayList[this._displayListLen++] = disp;
  2985. }
  2986. var decalEl = el.getDecalElement && el.getDecalElement();
  2987. if (decalEl) {
  2988. this._updateAndAddDisplayable(decalEl, thisClipPaths, includeIgnore);
  2989. }
  2990. var textGuide = el.getTextGuideLine();
  2991. if (textGuide) {
  2992. this._updateAndAddDisplayable(textGuide, thisClipPaths, includeIgnore);
  2993. }
  2994. var textEl = el.getTextContent();
  2995. if (textEl) {
  2996. this._updateAndAddDisplayable(textEl, thisClipPaths, includeIgnore);
  2997. }
  2998. };
  2999. Storage.prototype.addRoot = function (el) {
  3000. if (el.__zr && el.__zr.storage === this) {
  3001. return;
  3002. }
  3003. this._roots.push(el);
  3004. };
  3005. Storage.prototype.delRoot = function (el) {
  3006. if (el instanceof Array) {
  3007. for (var i = 0, l = el.length; i < l; i++) {
  3008. this.delRoot(el[i]);
  3009. }
  3010. return;
  3011. }
  3012. var idx = indexOf(this._roots, el);
  3013. if (idx >= 0) {
  3014. this._roots.splice(idx, 1);
  3015. }
  3016. };
  3017. Storage.prototype.delAllRoots = function () {
  3018. this._roots = [];
  3019. this._displayList = [];
  3020. this._displayListLen = 0;
  3021. return;
  3022. };
  3023. Storage.prototype.getRoots = function () {
  3024. return this._roots;
  3025. };
  3026. Storage.prototype.dispose = function () {
  3027. this._displayList = null;
  3028. this._roots = null;
  3029. };
  3030. return Storage;
  3031. }());
  3032. var requestAnimationFrame;
  3033. requestAnimationFrame = (env.hasGlobalWindow
  3034. && ((window.requestAnimationFrame && window.requestAnimationFrame.bind(window))
  3035. || (window.msRequestAnimationFrame && window.msRequestAnimationFrame.bind(window))
  3036. || window.mozRequestAnimationFrame
  3037. || window.webkitRequestAnimationFrame)) || function (func) {
  3038. return setTimeout(func, 16);
  3039. };
  3040. var requestAnimationFrame$1 = requestAnimationFrame;
  3041. var easingFuncs = {
  3042. linear: function (k) {
  3043. return k;
  3044. },
  3045. quadraticIn: function (k) {
  3046. return k * k;
  3047. },
  3048. quadraticOut: function (k) {
  3049. return k * (2 - k);
  3050. },
  3051. quadraticInOut: function (k) {
  3052. if ((k *= 2) < 1) {
  3053. return 0.5 * k * k;
  3054. }
  3055. return -0.5 * (--k * (k - 2) - 1);
  3056. },
  3057. cubicIn: function (k) {
  3058. return k * k * k;
  3059. },
  3060. cubicOut: function (k) {
  3061. return --k * k * k + 1;
  3062. },
  3063. cubicInOut: function (k) {
  3064. if ((k *= 2) < 1) {
  3065. return 0.5 * k * k * k;
  3066. }
  3067. return 0.5 * ((k -= 2) * k * k + 2);
  3068. },
  3069. quarticIn: function (k) {
  3070. return k * k * k * k;
  3071. },
  3072. quarticOut: function (k) {
  3073. return 1 - (--k * k * k * k);
  3074. },
  3075. quarticInOut: function (k) {
  3076. if ((k *= 2) < 1) {
  3077. return 0.5 * k * k * k * k;
  3078. }
  3079. return -0.5 * ((k -= 2) * k * k * k - 2);
  3080. },
  3081. quinticIn: function (k) {
  3082. return k * k * k * k * k;
  3083. },
  3084. quinticOut: function (k) {
  3085. return --k * k * k * k * k + 1;
  3086. },
  3087. quinticInOut: function (k) {
  3088. if ((k *= 2) < 1) {
  3089. return 0.5 * k * k * k * k * k;
  3090. }
  3091. return 0.5 * ((k -= 2) * k * k * k * k + 2);
  3092. },
  3093. sinusoidalIn: function (k) {
  3094. return 1 - Math.cos(k * Math.PI / 2);
  3095. },
  3096. sinusoidalOut: function (k) {
  3097. return Math.sin(k * Math.PI / 2);
  3098. },
  3099. sinusoidalInOut: function (k) {
  3100. return 0.5 * (1 - Math.cos(Math.PI * k));
  3101. },
  3102. exponentialIn: function (k) {
  3103. return k === 0 ? 0 : Math.pow(1024, k - 1);
  3104. },
  3105. exponentialOut: function (k) {
  3106. return k === 1 ? 1 : 1 - Math.pow(2, -10 * k);
  3107. },
  3108. exponentialInOut: function (k) {
  3109. if (k === 0) {
  3110. return 0;
  3111. }
  3112. if (k === 1) {
  3113. return 1;
  3114. }
  3115. if ((k *= 2) < 1) {
  3116. return 0.5 * Math.pow(1024, k - 1);
  3117. }
  3118. return 0.5 * (-Math.pow(2, -10 * (k - 1)) + 2);
  3119. },
  3120. circularIn: function (k) {
  3121. return 1 - Math.sqrt(1 - k * k);
  3122. },
  3123. circularOut: function (k) {
  3124. return Math.sqrt(1 - (--k * k));
  3125. },
  3126. circularInOut: function (k) {
  3127. if ((k *= 2) < 1) {
  3128. return -0.5 * (Math.sqrt(1 - k * k) - 1);
  3129. }
  3130. return 0.5 * (Math.sqrt(1 - (k -= 2) * k) + 1);
  3131. },
  3132. elasticIn: function (k) {
  3133. var s;
  3134. var a = 0.1;
  3135. var p = 0.4;
  3136. if (k === 0) {
  3137. return 0;
  3138. }
  3139. if (k === 1) {
  3140. return 1;
  3141. }
  3142. if (!a || a < 1) {
  3143. a = 1;
  3144. s = p / 4;
  3145. }
  3146. else {
  3147. s = p * Math.asin(1 / a) / (2 * Math.PI);
  3148. }
  3149. return -(a * Math.pow(2, 10 * (k -= 1))
  3150. * Math.sin((k - s) * (2 * Math.PI) / p));
  3151. },
  3152. elasticOut: function (k) {
  3153. var s;
  3154. var a = 0.1;
  3155. var p = 0.4;
  3156. if (k === 0) {
  3157. return 0;
  3158. }
  3159. if (k === 1) {
  3160. return 1;
  3161. }
  3162. if (!a || a < 1) {
  3163. a = 1;
  3164. s = p / 4;
  3165. }
  3166. else {
  3167. s = p * Math.asin(1 / a) / (2 * Math.PI);
  3168. }
  3169. return (a * Math.pow(2, -10 * k)
  3170. * Math.sin((k - s) * (2 * Math.PI) / p) + 1);
  3171. },
  3172. elasticInOut: function (k) {
  3173. var s;
  3174. var a = 0.1;
  3175. var p = 0.4;
  3176. if (k === 0) {
  3177. return 0;
  3178. }
  3179. if (k === 1) {
  3180. return 1;
  3181. }
  3182. if (!a || a < 1) {
  3183. a = 1;
  3184. s = p / 4;
  3185. }
  3186. else {
  3187. s = p * Math.asin(1 / a) / (2 * Math.PI);
  3188. }
  3189. if ((k *= 2) < 1) {
  3190. return -0.5 * (a * Math.pow(2, 10 * (k -= 1))
  3191. * Math.sin((k - s) * (2 * Math.PI) / p));
  3192. }
  3193. return a * Math.pow(2, -10 * (k -= 1))
  3194. * Math.sin((k - s) * (2 * Math.PI) / p) * 0.5 + 1;
  3195. },
  3196. backIn: function (k) {
  3197. var s = 1.70158;
  3198. return k * k * ((s + 1) * k - s);
  3199. },
  3200. backOut: function (k) {
  3201. var s = 1.70158;
  3202. return --k * k * ((s + 1) * k + s) + 1;
  3203. },
  3204. backInOut: function (k) {
  3205. var s = 1.70158 * 1.525;
  3206. if ((k *= 2) < 1) {
  3207. return 0.5 * (k * k * ((s + 1) * k - s));
  3208. }
  3209. return 0.5 * ((k -= 2) * k * ((s + 1) * k + s) + 2);
  3210. },
  3211. bounceIn: function (k) {
  3212. return 1 - easingFuncs.bounceOut(1 - k);
  3213. },
  3214. bounceOut: function (k) {
  3215. if (k < (1 / 2.75)) {
  3216. return 7.5625 * k * k;
  3217. }
  3218. else if (k < (2 / 2.75)) {
  3219. return 7.5625 * (k -= (1.5 / 2.75)) * k + 0.75;
  3220. }
  3221. else if (k < (2.5 / 2.75)) {
  3222. return 7.5625 * (k -= (2.25 / 2.75)) * k + 0.9375;
  3223. }
  3224. else {
  3225. return 7.5625 * (k -= (2.625 / 2.75)) * k + 0.984375;
  3226. }
  3227. },
  3228. bounceInOut: function (k) {
  3229. if (k < 0.5) {
  3230. return easingFuncs.bounceIn(k * 2) * 0.5;
  3231. }
  3232. return easingFuncs.bounceOut(k * 2 - 1) * 0.5 + 0.5;
  3233. }
  3234. };
  3235. var mathPow = Math.pow;
  3236. var mathSqrt = Math.sqrt;
  3237. var EPSILON$1 = 1e-8;
  3238. var EPSILON_NUMERIC = 1e-4;
  3239. var THREE_SQRT = mathSqrt(3);
  3240. var ONE_THIRD = 1 / 3;
  3241. var _v0 = create();
  3242. var _v1 = create();
  3243. var _v2 = create();
  3244. function isAroundZero(val) {
  3245. return val > -EPSILON$1 && val < EPSILON$1;
  3246. }
  3247. function isNotAroundZero(val) {
  3248. return val > EPSILON$1 || val < -EPSILON$1;
  3249. }
  3250. function cubicAt(p0, p1, p2, p3, t) {
  3251. var onet = 1 - t;
  3252. return onet * onet * (onet * p0 + 3 * t * p1)
  3253. + t * t * (t * p3 + 3 * onet * p2);
  3254. }
  3255. function cubicDerivativeAt(p0, p1, p2, p3, t) {
  3256. var onet = 1 - t;
  3257. return 3 * (((p1 - p0) * onet + 2 * (p2 - p1) * t) * onet
  3258. + (p3 - p2) * t * t);
  3259. }
  3260. function cubicRootAt(p0, p1, p2, p3, val, roots) {
  3261. var a = p3 + 3 * (p1 - p2) - p0;
  3262. var b = 3 * (p2 - p1 * 2 + p0);
  3263. var c = 3 * (p1 - p0);
  3264. var d = p0 - val;
  3265. var A = b * b - 3 * a * c;
  3266. var B = b * c - 9 * a * d;
  3267. var C = c * c - 3 * b * d;
  3268. var n = 0;
  3269. if (isAroundZero(A) && isAroundZero(B)) {
  3270. if (isAroundZero(b)) {
  3271. roots[0] = 0;
  3272. }
  3273. else {
  3274. var t1 = -c / b;
  3275. if (t1 >= 0 && t1 <= 1) {
  3276. roots[n++] = t1;
  3277. }
  3278. }
  3279. }
  3280. else {
  3281. var disc = B * B - 4 * A * C;
  3282. if (isAroundZero(disc)) {
  3283. var K = B / A;
  3284. var t1 = -b / a + K;
  3285. var t2 = -K / 2;
  3286. if (t1 >= 0 && t1 <= 1) {
  3287. roots[n++] = t1;
  3288. }
  3289. if (t2 >= 0 && t2 <= 1) {
  3290. roots[n++] = t2;
  3291. }
  3292. }
  3293. else if (disc > 0) {
  3294. var discSqrt = mathSqrt(disc);
  3295. var Y1 = A * b + 1.5 * a * (-B + discSqrt);
  3296. var Y2 = A * b + 1.5 * a * (-B - discSqrt);
  3297. if (Y1 < 0) {
  3298. Y1 = -mathPow(-Y1, ONE_THIRD);
  3299. }
  3300. else {
  3301. Y1 = mathPow(Y1, ONE_THIRD);
  3302. }
  3303. if (Y2 < 0) {
  3304. Y2 = -mathPow(-Y2, ONE_THIRD);
  3305. }
  3306. else {
  3307. Y2 = mathPow(Y2, ONE_THIRD);
  3308. }
  3309. var t1 = (-b - (Y1 + Y2)) / (3 * a);
  3310. if (t1 >= 0 && t1 <= 1) {
  3311. roots[n++] = t1;
  3312. }
  3313. }
  3314. else {
  3315. var T = (2 * A * b - 3 * a * B) / (2 * mathSqrt(A * A * A));
  3316. var theta = Math.acos(T) / 3;
  3317. var ASqrt = mathSqrt(A);
  3318. var tmp = Math.cos(theta);
  3319. var t1 = (-b - 2 * ASqrt * tmp) / (3 * a);
  3320. var t2 = (-b + ASqrt * (tmp + THREE_SQRT * Math.sin(theta))) / (3 * a);
  3321. var t3 = (-b + ASqrt * (tmp - THREE_SQRT * Math.sin(theta))) / (3 * a);
  3322. if (t1 >= 0 && t1 <= 1) {
  3323. roots[n++] = t1;
  3324. }
  3325. if (t2 >= 0 && t2 <= 1) {
  3326. roots[n++] = t2;
  3327. }
  3328. if (t3 >= 0 && t3 <= 1) {
  3329. roots[n++] = t3;
  3330. }
  3331. }
  3332. }
  3333. return n;
  3334. }
  3335. function cubicExtrema(p0, p1, p2, p3, extrema) {
  3336. var b = 6 * p2 - 12 * p1 + 6 * p0;
  3337. var a = 9 * p1 + 3 * p3 - 3 * p0 - 9 * p2;
  3338. var c = 3 * p1 - 3 * p0;
  3339. var n = 0;
  3340. if (isAroundZero(a)) {
  3341. if (isNotAroundZero(b)) {
  3342. var t1 = -c / b;
  3343. if (t1 >= 0 && t1 <= 1) {
  3344. extrema[n++] = t1;
  3345. }
  3346. }
  3347. }
  3348. else {
  3349. var disc = b * b - 4 * a * c;
  3350. if (isAroundZero(disc)) {
  3351. extrema[0] = -b / (2 * a);
  3352. }
  3353. else if (disc > 0) {
  3354. var discSqrt = mathSqrt(disc);
  3355. var t1 = (-b + discSqrt) / (2 * a);
  3356. var t2 = (-b - discSqrt) / (2 * a);
  3357. if (t1 >= 0 && t1 <= 1) {
  3358. extrema[n++] = t1;
  3359. }
  3360. if (t2 >= 0 && t2 <= 1) {
  3361. extrema[n++] = t2;
  3362. }
  3363. }
  3364. }
  3365. return n;
  3366. }
  3367. function cubicSubdivide(p0, p1, p2, p3, t, out) {
  3368. var p01 = (p1 - p0) * t + p0;
  3369. var p12 = (p2 - p1) * t + p1;
  3370. var p23 = (p3 - p2) * t + p2;
  3371. var p012 = (p12 - p01) * t + p01;
  3372. var p123 = (p23 - p12) * t + p12;
  3373. var p0123 = (p123 - p012) * t + p012;
  3374. out[0] = p0;
  3375. out[1] = p01;
  3376. out[2] = p012;
  3377. out[3] = p0123;
  3378. out[4] = p0123;
  3379. out[5] = p123;
  3380. out[6] = p23;
  3381. out[7] = p3;
  3382. }
  3383. function cubicProjectPoint(x0, y0, x1, y1, x2, y2, x3, y3, x, y, out) {
  3384. var t;
  3385. var interval = 0.005;
  3386. var d = Infinity;
  3387. var prev;
  3388. var next;
  3389. var d1;
  3390. var d2;
  3391. _v0[0] = x;
  3392. _v0[1] = y;
  3393. for (var _t = 0; _t < 1; _t += 0.05) {
  3394. _v1[0] = cubicAt(x0, x1, x2, x3, _t);
  3395. _v1[1] = cubicAt(y0, y1, y2, y3, _t);
  3396. d1 = distSquare(_v0, _v1);
  3397. if (d1 < d) {
  3398. t = _t;
  3399. d = d1;
  3400. }
  3401. }
  3402. d = Infinity;
  3403. for (var i = 0; i < 32; i++) {
  3404. if (interval < EPSILON_NUMERIC) {
  3405. break;
  3406. }
  3407. prev = t - interval;
  3408. next = t + interval;
  3409. _v1[0] = cubicAt(x0, x1, x2, x3, prev);
  3410. _v1[1] = cubicAt(y0, y1, y2, y3, prev);
  3411. d1 = distSquare(_v1, _v0);
  3412. if (prev >= 0 && d1 < d) {
  3413. t = prev;
  3414. d = d1;
  3415. }
  3416. else {
  3417. _v2[0] = cubicAt(x0, x1, x2, x3, next);
  3418. _v2[1] = cubicAt(y0, y1, y2, y3, next);
  3419. d2 = distSquare(_v2, _v0);
  3420. if (next <= 1 && d2 < d) {
  3421. t = next;
  3422. d = d2;
  3423. }
  3424. else {
  3425. interval *= 0.5;
  3426. }
  3427. }
  3428. }
  3429. if (out) {
  3430. out[0] = cubicAt(x0, x1, x2, x3, t);
  3431. out[1] = cubicAt(y0, y1, y2, y3, t);
  3432. }
  3433. return mathSqrt(d);
  3434. }
  3435. function cubicLength(x0, y0, x1, y1, x2, y2, x3, y3, iteration) {
  3436. var px = x0;
  3437. var py = y0;
  3438. var d = 0;
  3439. var step = 1 / iteration;
  3440. for (var i = 1; i <= iteration; i++) {
  3441. var t = i * step;
  3442. var x = cubicAt(x0, x1, x2, x3, t);
  3443. var y = cubicAt(y0, y1, y2, y3, t);
  3444. var dx = x - px;
  3445. var dy = y - py;
  3446. d += Math.sqrt(dx * dx + dy * dy);
  3447. px = x;
  3448. py = y;
  3449. }
  3450. return d;
  3451. }
  3452. function quadraticAt(p0, p1, p2, t) {
  3453. var onet = 1 - t;
  3454. return onet * (onet * p0 + 2 * t * p1) + t * t * p2;
  3455. }
  3456. function quadraticDerivativeAt(p0, p1, p2, t) {
  3457. return 2 * ((1 - t) * (p1 - p0) + t * (p2 - p1));
  3458. }
  3459. function quadraticRootAt(p0, p1, p2, val, roots) {
  3460. var a = p0 - 2 * p1 + p2;
  3461. var b = 2 * (p1 - p0);
  3462. var c = p0 - val;
  3463. var n = 0;
  3464. if (isAroundZero(a)) {
  3465. if (isNotAroundZero(b)) {
  3466. var t1 = -c / b;
  3467. if (t1 >= 0 && t1 <= 1) {
  3468. roots[n++] = t1;
  3469. }
  3470. }
  3471. }
  3472. else {
  3473. var disc = b * b - 4 * a * c;
  3474. if (isAroundZero(disc)) {
  3475. var t1 = -b / (2 * a);
  3476. if (t1 >= 0 && t1 <= 1) {
  3477. roots[n++] = t1;
  3478. }
  3479. }
  3480. else if (disc > 0) {
  3481. var discSqrt = mathSqrt(disc);
  3482. var t1 = (-b + discSqrt) / (2 * a);
  3483. var t2 = (-b - discSqrt) / (2 * a);
  3484. if (t1 >= 0 && t1 <= 1) {
  3485. roots[n++] = t1;
  3486. }
  3487. if (t2 >= 0 && t2 <= 1) {
  3488. roots[n++] = t2;
  3489. }
  3490. }
  3491. }
  3492. return n;
  3493. }
  3494. function quadraticExtremum(p0, p1, p2) {
  3495. var divider = p0 + p2 - 2 * p1;
  3496. if (divider === 0) {
  3497. return 0.5;
  3498. }
  3499. else {
  3500. return (p0 - p1) / divider;
  3501. }
  3502. }
  3503. function quadraticSubdivide(p0, p1, p2, t, out) {
  3504. var p01 = (p1 - p0) * t + p0;
  3505. var p12 = (p2 - p1) * t + p1;
  3506. var p012 = (p12 - p01) * t + p01;
  3507. out[0] = p0;
  3508. out[1] = p01;
  3509. out[2] = p012;
  3510. out[3] = p012;
  3511. out[4] = p12;
  3512. out[5] = p2;
  3513. }
  3514. function quadraticProjectPoint(x0, y0, x1, y1, x2, y2, x, y, out) {
  3515. var t;
  3516. var interval = 0.005;
  3517. var d = Infinity;
  3518. _v0[0] = x;
  3519. _v0[1] = y;
  3520. for (var _t = 0; _t < 1; _t += 0.05) {
  3521. _v1[0] = quadraticAt(x0, x1, x2, _t);
  3522. _v1[1] = quadraticAt(y0, y1, y2, _t);
  3523. var d1 = distSquare(_v0, _v1);
  3524. if (d1 < d) {
  3525. t = _t;
  3526. d = d1;
  3527. }
  3528. }
  3529. d = Infinity;
  3530. for (var i = 0; i < 32; i++) {
  3531. if (interval < EPSILON_NUMERIC) {
  3532. break;
  3533. }
  3534. var prev = t - interval;
  3535. var next = t + interval;
  3536. _v1[0] = quadraticAt(x0, x1, x2, prev);
  3537. _v1[1] = quadraticAt(y0, y1, y2, prev);
  3538. var d1 = distSquare(_v1, _v0);
  3539. if (prev >= 0 && d1 < d) {
  3540. t = prev;
  3541. d = d1;
  3542. }
  3543. else {
  3544. _v2[0] = quadraticAt(x0, x1, x2, next);
  3545. _v2[1] = quadraticAt(y0, y1, y2, next);
  3546. var d2 = distSquare(_v2, _v0);
  3547. if (next <= 1 && d2 < d) {
  3548. t = next;
  3549. d = d2;
  3550. }
  3551. else {
  3552. interval *= 0.5;
  3553. }
  3554. }
  3555. }
  3556. if (out) {
  3557. out[0] = quadraticAt(x0, x1, x2, t);
  3558. out[1] = quadraticAt(y0, y1, y2, t);
  3559. }
  3560. return mathSqrt(d);
  3561. }
  3562. function quadraticLength(x0, y0, x1, y1, x2, y2, iteration) {
  3563. var px = x0;
  3564. var py = y0;
  3565. var d = 0;
  3566. var step = 1 / iteration;
  3567. for (var i = 1; i <= iteration; i++) {
  3568. var t = i * step;
  3569. var x = quadraticAt(x0, x1, x2, t);
  3570. var y = quadraticAt(y0, y1, y2, t);
  3571. var dx = x - px;
  3572. var dy = y - py;
  3573. d += Math.sqrt(dx * dx + dy * dy);
  3574. px = x;
  3575. py = y;
  3576. }
  3577. return d;
  3578. }
  3579. var regexp = /cubic-bezier\(([0-9,\.e ]+)\)/;
  3580. function createCubicEasingFunc(cubicEasingStr) {
  3581. var cubic = cubicEasingStr && regexp.exec(cubicEasingStr);
  3582. if (cubic) {
  3583. var points = cubic[1].split(',');
  3584. var a_1 = +trim(points[0]);
  3585. var b_1 = +trim(points[1]);
  3586. var c_1 = +trim(points[2]);
  3587. var d_1 = +trim(points[3]);
  3588. if (isNaN(a_1 + b_1 + c_1 + d_1)) {
  3589. return;
  3590. }
  3591. var roots_1 = [];
  3592. return function (p) {
  3593. return p <= 0
  3594. ? 0 : p >= 1
  3595. ? 1
  3596. : cubicRootAt(0, a_1, c_1, 1, p, roots_1) && cubicAt(0, b_1, d_1, 1, roots_1[0]);
  3597. };
  3598. }
  3599. }
  3600. var Clip = (function () {
  3601. function Clip(opts) {
  3602. this._inited = false;
  3603. this._startTime = 0;
  3604. this._pausedTime = 0;
  3605. this._paused = false;
  3606. this._life = opts.life || 1000;
  3607. this._delay = opts.delay || 0;
  3608. this.loop = opts.loop || false;
  3609. this.onframe = opts.onframe || noop;
  3610. this.ondestroy = opts.ondestroy || noop;
  3611. this.onrestart = opts.onrestart || noop;
  3612. opts.easing && this.setEasing(opts.easing);
  3613. }
  3614. Clip.prototype.step = function (globalTime, deltaTime) {
  3615. if (!this._inited) {
  3616. this._startTime = globalTime + this._delay;
  3617. this._inited = true;
  3618. }
  3619. if (this._paused) {
  3620. this._pausedTime += deltaTime;
  3621. return;
  3622. }
  3623. var life = this._life;
  3624. var elapsedTime = globalTime - this._startTime - this._pausedTime;
  3625. var percent = elapsedTime / life;
  3626. if (percent < 0) {
  3627. percent = 0;
  3628. }
  3629. percent = Math.min(percent, 1);
  3630. var easingFunc = this.easingFunc;
  3631. var schedule = easingFunc ? easingFunc(percent) : percent;
  3632. this.onframe(schedule);
  3633. if (percent === 1) {
  3634. if (this.loop) {
  3635. var remainder = elapsedTime % life;
  3636. this._startTime = globalTime - remainder;
  3637. this._pausedTime = 0;
  3638. this.onrestart();
  3639. }
  3640. else {
  3641. return true;
  3642. }
  3643. }
  3644. return false;
  3645. };
  3646. Clip.prototype.pause = function () {
  3647. this._paused = true;
  3648. };
  3649. Clip.prototype.resume = function () {
  3650. this._paused = false;
  3651. };
  3652. Clip.prototype.setEasing = function (easing) {
  3653. this.easing = easing;
  3654. this.easingFunc = isFunction(easing)
  3655. ? easing
  3656. : easingFuncs[easing] || createCubicEasingFunc(easing);
  3657. };
  3658. return Clip;
  3659. }());
  3660. var Entry = (function () {
  3661. function Entry(val) {
  3662. this.value = val;
  3663. }
  3664. return Entry;
  3665. }());
  3666. var LinkedList = (function () {
  3667. function LinkedList() {
  3668. this._len = 0;
  3669. }
  3670. LinkedList.prototype.insert = function (val) {
  3671. var entry = new Entry(val);
  3672. this.insertEntry(entry);
  3673. return entry;
  3674. };
  3675. LinkedList.prototype.insertEntry = function (entry) {
  3676. if (!this.head) {
  3677. this.head = this.tail = entry;
  3678. }
  3679. else {
  3680. this.tail.next = entry;
  3681. entry.prev = this.tail;
  3682. entry.next = null;
  3683. this.tail = entry;
  3684. }
  3685. this._len++;
  3686. };
  3687. LinkedList.prototype.remove = function (entry) {
  3688. var prev = entry.prev;
  3689. var next = entry.next;
  3690. if (prev) {
  3691. prev.next = next;
  3692. }
  3693. else {
  3694. this.head = next;
  3695. }
  3696. if (next) {
  3697. next.prev = prev;
  3698. }
  3699. else {
  3700. this.tail = prev;
  3701. }
  3702. entry.next = entry.prev = null;
  3703. this._len--;
  3704. };
  3705. LinkedList.prototype.len = function () {
  3706. return this._len;
  3707. };
  3708. LinkedList.prototype.clear = function () {
  3709. this.head = this.tail = null;
  3710. this._len = 0;
  3711. };
  3712. return LinkedList;
  3713. }());
  3714. var LRU = (function () {
  3715. function LRU(maxSize) {
  3716. this._list = new LinkedList();
  3717. this._maxSize = 10;
  3718. this._map = {};
  3719. this._maxSize = maxSize;
  3720. }
  3721. LRU.prototype.put = function (key, value) {
  3722. var list = this._list;
  3723. var map = this._map;
  3724. var removed = null;
  3725. if (map[key] == null) {
  3726. var len = list.len();
  3727. var entry = this._lastRemovedEntry;
  3728. if (len >= this._maxSize && len > 0) {
  3729. var leastUsedEntry = list.head;
  3730. list.remove(leastUsedEntry);
  3731. delete map[leastUsedEntry.key];
  3732. removed = leastUsedEntry.value;
  3733. this._lastRemovedEntry = leastUsedEntry;
  3734. }
  3735. if (entry) {
  3736. entry.value = value;
  3737. }
  3738. else {
  3739. entry = new Entry(value);
  3740. }
  3741. entry.key = key;
  3742. list.insertEntry(entry);
  3743. map[key] = entry;
  3744. }
  3745. return removed;
  3746. };
  3747. LRU.prototype.get = function (key) {
  3748. var entry = this._map[key];
  3749. var list = this._list;
  3750. if (entry != null) {
  3751. if (entry !== list.tail) {
  3752. list.remove(entry);
  3753. list.insertEntry(entry);
  3754. }
  3755. return entry.value;
  3756. }
  3757. };
  3758. LRU.prototype.clear = function () {
  3759. this._list.clear();
  3760. this._map = {};
  3761. };
  3762. LRU.prototype.len = function () {
  3763. return this._list.len();
  3764. };
  3765. return LRU;
  3766. }());
  3767. var kCSSColorTable = {
  3768. 'transparent': [0, 0, 0, 0], 'aliceblue': [240, 248, 255, 1],
  3769. 'antiquewhite': [250, 235, 215, 1], 'aqua': [0, 255, 255, 1],
  3770. 'aquamarine': [127, 255, 212, 1], 'azure': [240, 255, 255, 1],
  3771. 'beige': [245, 245, 220, 1], 'bisque': [255, 228, 196, 1],
  3772. 'black': [0, 0, 0, 1], 'blanchedalmond': [255, 235, 205, 1],
  3773. 'blue': [0, 0, 255, 1], 'blueviolet': [138, 43, 226, 1],
  3774. 'brown': [165, 42, 42, 1], 'burlywood': [222, 184, 135, 1],
  3775. 'cadetblue': [95, 158, 160, 1], 'chartreuse': [127, 255, 0, 1],
  3776. 'chocolate': [210, 105, 30, 1], 'coral': [255, 127, 80, 1],
  3777. 'cornflowerblue': [100, 149, 237, 1], 'cornsilk': [255, 248, 220, 1],
  3778. 'crimson': [220, 20, 60, 1], 'cyan': [0, 255, 255, 1],
  3779. 'darkblue': [0, 0, 139, 1], 'darkcyan': [0, 139, 139, 1],
  3780. 'darkgoldenrod': [184, 134, 11, 1], 'darkgray': [169, 169, 169, 1],
  3781. 'darkgreen': [0, 100, 0, 1], 'darkgrey': [169, 169, 169, 1],
  3782. 'darkkhaki': [189, 183, 107, 1], 'darkmagenta': [139, 0, 139, 1],
  3783. 'darkolivegreen': [85, 107, 47, 1], 'darkorange': [255, 140, 0, 1],
  3784. 'darkorchid': [153, 50, 204, 1], 'darkred': [139, 0, 0, 1],
  3785. 'darksalmon': [233, 150, 122, 1], 'darkseagreen': [143, 188, 143, 1],
  3786. 'darkslateblue': [72, 61, 139, 1], 'darkslategray': [47, 79, 79, 1],
  3787. 'darkslategrey': [47, 79, 79, 1], 'darkturquoise': [0, 206, 209, 1],
  3788. 'darkviolet': [148, 0, 211, 1], 'deeppink': [255, 20, 147, 1],
  3789. 'deepskyblue': [0, 191, 255, 1], 'dimgray': [105, 105, 105, 1],
  3790. 'dimgrey': [105, 105, 105, 1], 'dodgerblue': [30, 144, 255, 1],
  3791. 'firebrick': [178, 34, 34, 1], 'floralwhite': [255, 250, 240, 1],
  3792. 'forestgreen': [34, 139, 34, 1], 'fuchsia': [255, 0, 255, 1],
  3793. 'gainsboro': [220, 220, 220, 1], 'ghostwhite': [248, 248, 255, 1],
  3794. 'gold': [255, 215, 0, 1], 'goldenrod': [218, 165, 32, 1],
  3795. 'gray': [128, 128, 128, 1], 'green': [0, 128, 0, 1],
  3796. 'greenyellow': [173, 255, 47, 1], 'grey': [128, 128, 128, 1],
  3797. 'honeydew': [240, 255, 240, 1], 'hotpink': [255, 105, 180, 1],
  3798. 'indianred': [205, 92, 92, 1], 'indigo': [75, 0, 130, 1],
  3799. 'ivory': [255, 255, 240, 1], 'khaki': [240, 230, 140, 1],
  3800. 'lavender': [230, 230, 250, 1], 'lavenderblush': [255, 240, 245, 1],
  3801. 'lawngreen': [124, 252, 0, 1], 'lemonchiffon': [255, 250, 205, 1],
  3802. 'lightblue': [173, 216, 230, 1], 'lightcoral': [240, 128, 128, 1],
  3803. 'lightcyan': [224, 255, 255, 1], 'lightgoldenrodyellow': [250, 250, 210, 1],
  3804. 'lightgray': [211, 211, 211, 1], 'lightgreen': [144, 238, 144, 1],
  3805. 'lightgrey': [211, 211, 211, 1], 'lightpink': [255, 182, 193, 1],
  3806. 'lightsalmon': [255, 160, 122, 1], 'lightseagreen': [32, 178, 170, 1],
  3807. 'lightskyblue': [135, 206, 250, 1], 'lightslategray': [119, 136, 153, 1],
  3808. 'lightslategrey': [119, 136, 153, 1], 'lightsteelblue': [176, 196, 222, 1],
  3809. 'lightyellow': [255, 255, 224, 1], 'lime': [0, 255, 0, 1],
  3810. 'limegreen': [50, 205, 50, 1], 'linen': [250, 240, 230, 1],
  3811. 'magenta': [255, 0, 255, 1], 'maroon': [128, 0, 0, 1],
  3812. 'mediumaquamarine': [102, 205, 170, 1], 'mediumblue': [0, 0, 205, 1],
  3813. 'mediumorchid': [186, 85, 211, 1], 'mediumpurple': [147, 112, 219, 1],
  3814. 'mediumseagreen': [60, 179, 113, 1], 'mediumslateblue': [123, 104, 238, 1],
  3815. 'mediumspringgreen': [0, 250, 154, 1], 'mediumturquoise': [72, 209, 204, 1],
  3816. 'mediumvioletred': [199, 21, 133, 1], 'midnightblue': [25, 25, 112, 1],
  3817. 'mintcream': [245, 255, 250, 1], 'mistyrose': [255, 228, 225, 1],
  3818. 'moccasin': [255, 228, 181, 1], 'navajowhite': [255, 222, 173, 1],
  3819. 'navy': [0, 0, 128, 1], 'oldlace': [253, 245, 230, 1],
  3820. 'olive': [128, 128, 0, 1], 'olivedrab': [107, 142, 35, 1],
  3821. 'orange': [255, 165, 0, 1], 'orangered': [255, 69, 0, 1],
  3822. 'orchid': [218, 112, 214, 1], 'palegoldenrod': [238, 232, 170, 1],
  3823. 'palegreen': [152, 251, 152, 1], 'paleturquoise': [175, 238, 238, 1],
  3824. 'palevioletred': [219, 112, 147, 1], 'papayawhip': [255, 239, 213, 1],
  3825. 'peachpuff': [255, 218, 185, 1], 'peru': [205, 133, 63, 1],
  3826. 'pink': [255, 192, 203, 1], 'plum': [221, 160, 221, 1],
  3827. 'powderblue': [176, 224, 230, 1], 'purple': [128, 0, 128, 1],
  3828. 'red': [255, 0, 0, 1], 'rosybrown': [188, 143, 143, 1],
  3829. 'royalblue': [65, 105, 225, 1], 'saddlebrown': [139, 69, 19, 1],
  3830. 'salmon': [250, 128, 114, 1], 'sandybrown': [244, 164, 96, 1],
  3831. 'seagreen': [46, 139, 87, 1], 'seashell': [255, 245, 238, 1],
  3832. 'sienna': [160, 82, 45, 1], 'silver': [192, 192, 192, 1],
  3833. 'skyblue': [135, 206, 235, 1], 'slateblue': [106, 90, 205, 1],
  3834. 'slategray': [112, 128, 144, 1], 'slategrey': [112, 128, 144, 1],
  3835. 'snow': [255, 250, 250, 1], 'springgreen': [0, 255, 127, 1],
  3836. 'steelblue': [70, 130, 180, 1], 'tan': [210, 180, 140, 1],
  3837. 'teal': [0, 128, 128, 1], 'thistle': [216, 191, 216, 1],
  3838. 'tomato': [255, 99, 71, 1], 'turquoise': [64, 224, 208, 1],
  3839. 'violet': [238, 130, 238, 1], 'wheat': [245, 222, 179, 1],
  3840. 'white': [255, 255, 255, 1], 'whitesmoke': [245, 245, 245, 1],
  3841. 'yellow': [255, 255, 0, 1], 'yellowgreen': [154, 205, 50, 1]
  3842. };
  3843. function clampCssByte(i) {
  3844. i = Math.round(i);
  3845. return i < 0 ? 0 : i > 255 ? 255 : i;
  3846. }
  3847. function clampCssAngle(i) {
  3848. i = Math.round(i);
  3849. return i < 0 ? 0 : i > 360 ? 360 : i;
  3850. }
  3851. function clampCssFloat(f) {
  3852. return f < 0 ? 0 : f > 1 ? 1 : f;
  3853. }
  3854. function parseCssInt(val) {
  3855. var str = val;
  3856. if (str.length && str.charAt(str.length - 1) === '%') {
  3857. return clampCssByte(parseFloat(str) / 100 * 255);
  3858. }
  3859. return clampCssByte(parseInt(str, 10));
  3860. }
  3861. function parseCssFloat(val) {
  3862. var str = val;
  3863. if (str.length && str.charAt(str.length - 1) === '%') {
  3864. return clampCssFloat(parseFloat(str) / 100);
  3865. }
  3866. return clampCssFloat(parseFloat(str));
  3867. }
  3868. function cssHueToRgb(m1, m2, h) {
  3869. if (h < 0) {
  3870. h += 1;
  3871. }
  3872. else if (h > 1) {
  3873. h -= 1;
  3874. }
  3875. if (h * 6 < 1) {
  3876. return m1 + (m2 - m1) * h * 6;
  3877. }
  3878. if (h * 2 < 1) {
  3879. return m2;
  3880. }
  3881. if (h * 3 < 2) {
  3882. return m1 + (m2 - m1) * (2 / 3 - h) * 6;
  3883. }
  3884. return m1;
  3885. }
  3886. function lerpNumber(a, b, p) {
  3887. return a + (b - a) * p;
  3888. }
  3889. function setRgba(out, r, g, b, a) {
  3890. out[0] = r;
  3891. out[1] = g;
  3892. out[2] = b;
  3893. out[3] = a;
  3894. return out;
  3895. }
  3896. function copyRgba(out, a) {
  3897. out[0] = a[0];
  3898. out[1] = a[1];
  3899. out[2] = a[2];
  3900. out[3] = a[3];
  3901. return out;
  3902. }
  3903. var colorCache = new LRU(20);
  3904. var lastRemovedArr = null;
  3905. function putToCache(colorStr, rgbaArr) {
  3906. if (lastRemovedArr) {
  3907. copyRgba(lastRemovedArr, rgbaArr);
  3908. }
  3909. lastRemovedArr = colorCache.put(colorStr, lastRemovedArr || (rgbaArr.slice()));
  3910. }
  3911. function parse(colorStr, rgbaArr) {
  3912. if (!colorStr) {
  3913. return;
  3914. }
  3915. rgbaArr = rgbaArr || [];
  3916. var cached = colorCache.get(colorStr);
  3917. if (cached) {
  3918. return copyRgba(rgbaArr, cached);
  3919. }
  3920. colorStr = colorStr + '';
  3921. var str = colorStr.replace(/ /g, '').toLowerCase();
  3922. if (str in kCSSColorTable) {
  3923. copyRgba(rgbaArr, kCSSColorTable[str]);
  3924. putToCache(colorStr, rgbaArr);
  3925. return rgbaArr;
  3926. }
  3927. var strLen = str.length;
  3928. if (str.charAt(0) === '#') {
  3929. if (strLen === 4 || strLen === 5) {
  3930. var iv = parseInt(str.slice(1, 4), 16);
  3931. if (!(iv >= 0 && iv <= 0xfff)) {
  3932. setRgba(rgbaArr, 0, 0, 0, 1);
  3933. return;
  3934. }
  3935. setRgba(rgbaArr, ((iv & 0xf00) >> 4) | ((iv & 0xf00) >> 8), (iv & 0xf0) | ((iv & 0xf0) >> 4), (iv & 0xf) | ((iv & 0xf) << 4), strLen === 5 ? parseInt(str.slice(4), 16) / 0xf : 1);
  3936. putToCache(colorStr, rgbaArr);
  3937. return rgbaArr;
  3938. }
  3939. else if (strLen === 7 || strLen === 9) {
  3940. var iv = parseInt(str.slice(1, 7), 16);
  3941. if (!(iv >= 0 && iv <= 0xffffff)) {
  3942. setRgba(rgbaArr, 0, 0, 0, 1);
  3943. return;
  3944. }
  3945. setRgba(rgbaArr, (iv & 0xff0000) >> 16, (iv & 0xff00) >> 8, iv & 0xff, strLen === 9 ? parseInt(str.slice(7), 16) / 0xff : 1);
  3946. putToCache(colorStr, rgbaArr);
  3947. return rgbaArr;
  3948. }
  3949. return;
  3950. }
  3951. var op = str.indexOf('(');
  3952. var ep = str.indexOf(')');
  3953. if (op !== -1 && ep + 1 === strLen) {
  3954. var fname = str.substr(0, op);
  3955. var params = str.substr(op + 1, ep - (op + 1)).split(',');
  3956. var alpha = 1;
  3957. switch (fname) {
  3958. case 'rgba':
  3959. if (params.length !== 4) {
  3960. return params.length === 3
  3961. ? setRgba(rgbaArr, +params[0], +params[1], +params[2], 1)
  3962. : setRgba(rgbaArr, 0, 0, 0, 1);
  3963. }
  3964. alpha = parseCssFloat(params.pop());
  3965. case 'rgb':
  3966. if (params.length >= 3) {
  3967. setRgba(rgbaArr, parseCssInt(params[0]), parseCssInt(params[1]), parseCssInt(params[2]), params.length === 3 ? alpha : parseCssFloat(params[3]));
  3968. putToCache(colorStr, rgbaArr);
  3969. return rgbaArr;
  3970. }
  3971. else {
  3972. setRgba(rgbaArr, 0, 0, 0, 1);
  3973. return;
  3974. }
  3975. case 'hsla':
  3976. if (params.length !== 4) {
  3977. setRgba(rgbaArr, 0, 0, 0, 1);
  3978. return;
  3979. }
  3980. params[3] = parseCssFloat(params[3]);
  3981. hsla2rgba(params, rgbaArr);
  3982. putToCache(colorStr, rgbaArr);
  3983. return rgbaArr;
  3984. case 'hsl':
  3985. if (params.length !== 3) {
  3986. setRgba(rgbaArr, 0, 0, 0, 1);
  3987. return;
  3988. }
  3989. hsla2rgba(params, rgbaArr);
  3990. putToCache(colorStr, rgbaArr);
  3991. return rgbaArr;
  3992. default:
  3993. return;
  3994. }
  3995. }
  3996. setRgba(rgbaArr, 0, 0, 0, 1);
  3997. return;
  3998. }
  3999. function hsla2rgba(hsla, rgba) {
  4000. var h = (((parseFloat(hsla[0]) % 360) + 360) % 360) / 360;
  4001. var s = parseCssFloat(hsla[1]);
  4002. var l = parseCssFloat(hsla[2]);
  4003. var m2 = l <= 0.5 ? l * (s + 1) : l + s - l * s;
  4004. var m1 = l * 2 - m2;
  4005. rgba = rgba || [];
  4006. setRgba(rgba, clampCssByte(cssHueToRgb(m1, m2, h + 1 / 3) * 255), clampCssByte(cssHueToRgb(m1, m2, h) * 255), clampCssByte(cssHueToRgb(m1, m2, h - 1 / 3) * 255), 1);
  4007. if (hsla.length === 4) {
  4008. rgba[3] = hsla[3];
  4009. }
  4010. return rgba;
  4011. }
  4012. function rgba2hsla(rgba) {
  4013. if (!rgba) {
  4014. return;
  4015. }
  4016. var R = rgba[0] / 255;
  4017. var G = rgba[1] / 255;
  4018. var B = rgba[2] / 255;
  4019. var vMin = Math.min(R, G, B);
  4020. var vMax = Math.max(R, G, B);
  4021. var delta = vMax - vMin;
  4022. var L = (vMax + vMin) / 2;
  4023. var H;
  4024. var S;
  4025. if (delta === 0) {
  4026. H = 0;
  4027. S = 0;
  4028. }
  4029. else {
  4030. if (L < 0.5) {
  4031. S = delta / (vMax + vMin);
  4032. }
  4033. else {
  4034. S = delta / (2 - vMax - vMin);
  4035. }
  4036. var deltaR = (((vMax - R) / 6) + (delta / 2)) / delta;
  4037. var deltaG = (((vMax - G) / 6) + (delta / 2)) / delta;
  4038. var deltaB = (((vMax - B) / 6) + (delta / 2)) / delta;
  4039. if (R === vMax) {
  4040. H = deltaB - deltaG;
  4041. }
  4042. else if (G === vMax) {
  4043. H = (1 / 3) + deltaR - deltaB;
  4044. }
  4045. else if (B === vMax) {
  4046. H = (2 / 3) + deltaG - deltaR;
  4047. }
  4048. if (H < 0) {
  4049. H += 1;
  4050. }
  4051. if (H > 1) {
  4052. H -= 1;
  4053. }
  4054. }
  4055. var hsla = [H * 360, S, L];
  4056. if (rgba[3] != null) {
  4057. hsla.push(rgba[3]);
  4058. }
  4059. return hsla;
  4060. }
  4061. function lift(color, level) {
  4062. var colorArr = parse(color);
  4063. if (colorArr) {
  4064. for (var i = 0; i < 3; i++) {
  4065. if (level < 0) {
  4066. colorArr[i] = colorArr[i] * (1 - level) | 0;
  4067. }
  4068. else {
  4069. colorArr[i] = ((255 - colorArr[i]) * level + colorArr[i]) | 0;
  4070. }
  4071. if (colorArr[i] > 255) {
  4072. colorArr[i] = 255;
  4073. }
  4074. else if (colorArr[i] < 0) {
  4075. colorArr[i] = 0;
  4076. }
  4077. }
  4078. return stringify(colorArr, colorArr.length === 4 ? 'rgba' : 'rgb');
  4079. }
  4080. }
  4081. function toHex(color) {
  4082. var colorArr = parse(color);
  4083. if (colorArr) {
  4084. return ((1 << 24) + (colorArr[0] << 16) + (colorArr[1] << 8) + (+colorArr[2])).toString(16).slice(1);
  4085. }
  4086. }
  4087. function fastLerp(normalizedValue, colors, out) {
  4088. if (!(colors && colors.length)
  4089. || !(normalizedValue >= 0 && normalizedValue <= 1)) {
  4090. return;
  4091. }
  4092. out = out || [];
  4093. var value = normalizedValue * (colors.length - 1);
  4094. var leftIndex = Math.floor(value);
  4095. var rightIndex = Math.ceil(value);
  4096. var leftColor = colors[leftIndex];
  4097. var rightColor = colors[rightIndex];
  4098. var dv = value - leftIndex;
  4099. out[0] = clampCssByte(lerpNumber(leftColor[0], rightColor[0], dv));
  4100. out[1] = clampCssByte(lerpNumber(leftColor[1], rightColor[1], dv));
  4101. out[2] = clampCssByte(lerpNumber(leftColor[2], rightColor[2], dv));
  4102. out[3] = clampCssFloat(lerpNumber(leftColor[3], rightColor[3], dv));
  4103. return out;
  4104. }
  4105. var fastMapToColor = fastLerp;
  4106. function lerp$1(normalizedValue, colors, fullOutput) {
  4107. if (!(colors && colors.length)
  4108. || !(normalizedValue >= 0 && normalizedValue <= 1)) {
  4109. return;
  4110. }
  4111. var value = normalizedValue * (colors.length - 1);
  4112. var leftIndex = Math.floor(value);
  4113. var rightIndex = Math.ceil(value);
  4114. var leftColor = parse(colors[leftIndex]);
  4115. var rightColor = parse(colors[rightIndex]);
  4116. var dv = value - leftIndex;
  4117. var color = stringify([
  4118. clampCssByte(lerpNumber(leftColor[0], rightColor[0], dv)),
  4119. clampCssByte(lerpNumber(leftColor[1], rightColor[1], dv)),
  4120. clampCssByte(lerpNumber(leftColor[2], rightColor[2], dv)),
  4121. clampCssFloat(lerpNumber(leftColor[3], rightColor[3], dv))
  4122. ], 'rgba');
  4123. return fullOutput
  4124. ? {
  4125. color: color,
  4126. leftIndex: leftIndex,
  4127. rightIndex: rightIndex,
  4128. value: value
  4129. }
  4130. : color;
  4131. }
  4132. var mapToColor = lerp$1;
  4133. function modifyHSL(color, h, s, l) {
  4134. var colorArr = parse(color);
  4135. if (color) {
  4136. colorArr = rgba2hsla(colorArr);
  4137. h != null && (colorArr[0] = clampCssAngle(isFunction(h) ? h(colorArr[0]) : h));
  4138. s != null && (colorArr[1] = parseCssFloat(isFunction(s) ? s(colorArr[1]) : s));
  4139. l != null && (colorArr[2] = parseCssFloat(isFunction(l) ? l(colorArr[2]) : l));
  4140. return stringify(hsla2rgba(colorArr), 'rgba');
  4141. }
  4142. }
  4143. function modifyAlpha(color, alpha) {
  4144. var colorArr = parse(color);
  4145. if (colorArr && alpha != null) {
  4146. colorArr[3] = clampCssFloat(alpha);
  4147. return stringify(colorArr, 'rgba');
  4148. }
  4149. }
  4150. function stringify(arrColor, type) {
  4151. if (!arrColor || !arrColor.length) {
  4152. return;
  4153. }
  4154. var colorStr = arrColor[0] + ',' + arrColor[1] + ',' + arrColor[2];
  4155. if (type === 'rgba' || type === 'hsva' || type === 'hsla') {
  4156. colorStr += ',' + arrColor[3];
  4157. }
  4158. return type + '(' + colorStr + ')';
  4159. }
  4160. function lum(color, backgroundLum) {
  4161. var arr = parse(color);
  4162. return arr
  4163. ? (0.299 * arr[0] + 0.587 * arr[1] + 0.114 * arr[2]) * arr[3] / 255
  4164. + (1 - arr[3]) * backgroundLum
  4165. : 0;
  4166. }
  4167. function random() {
  4168. return stringify([
  4169. Math.round(Math.random() * 255),
  4170. Math.round(Math.random() * 255),
  4171. Math.round(Math.random() * 255)
  4172. ], 'rgb');
  4173. }
  4174. var liftedColorCache = new LRU(100);
  4175. function liftColor(color) {
  4176. if (isString(color)) {
  4177. var liftedColor = liftedColorCache.get(color);
  4178. if (!liftedColor) {
  4179. liftedColor = lift(color, -0.1);
  4180. liftedColorCache.put(color, liftedColor);
  4181. }
  4182. return liftedColor;
  4183. }
  4184. else if (isGradientObject(color)) {
  4185. var ret = extend({}, color);
  4186. ret.colorStops = map(color.colorStops, function (stop) { return ({
  4187. offset: stop.offset,
  4188. color: lift(stop.color, -0.1)
  4189. }); });
  4190. return ret;
  4191. }
  4192. return color;
  4193. }
  4194. var color = /*#__PURE__*/Object.freeze({
  4195. __proto__: null,
  4196. parseCssInt: parseCssInt,
  4197. parseCssFloat: parseCssFloat,
  4198. parse: parse,
  4199. lift: lift,
  4200. toHex: toHex,
  4201. fastLerp: fastLerp,
  4202. fastMapToColor: fastMapToColor,
  4203. lerp: lerp$1,
  4204. mapToColor: mapToColor,
  4205. modifyHSL: modifyHSL,
  4206. modifyAlpha: modifyAlpha,
  4207. stringify: stringify,
  4208. lum: lum,
  4209. random: random,
  4210. liftColor: liftColor
  4211. });
  4212. var mathRound = Math.round;
  4213. function normalizeColor(color) {
  4214. var opacity;
  4215. if (!color || color === 'transparent') {
  4216. color = 'none';
  4217. }
  4218. else if (typeof color === 'string' && color.indexOf('rgba') > -1) {
  4219. var arr = parse(color);
  4220. if (arr) {
  4221. color = 'rgb(' + arr[0] + ',' + arr[1] + ',' + arr[2] + ')';
  4222. opacity = arr[3];
  4223. }
  4224. }
  4225. return {
  4226. color: color,
  4227. opacity: opacity == null ? 1 : opacity
  4228. };
  4229. }
  4230. var EPSILON$2 = 1e-4;
  4231. function isAroundZero$1(transform) {
  4232. return transform < EPSILON$2 && transform > -EPSILON$2;
  4233. }
  4234. function round3(transform) {
  4235. return mathRound(transform * 1e3) / 1e3;
  4236. }
  4237. function round4(transform) {
  4238. return mathRound(transform * 1e4) / 1e4;
  4239. }
  4240. function getMatrixStr(m) {
  4241. return 'matrix('
  4242. + round3(m[0]) + ','
  4243. + round3(m[1]) + ','
  4244. + round3(m[2]) + ','
  4245. + round3(m[3]) + ','
  4246. + round4(m[4]) + ','
  4247. + round4(m[5])
  4248. + ')';
  4249. }
  4250. var TEXT_ALIGN_TO_ANCHOR = {
  4251. left: 'start',
  4252. right: 'end',
  4253. center: 'middle',
  4254. middle: 'middle'
  4255. };
  4256. function adjustTextY(y, lineHeight, textBaseline) {
  4257. if (textBaseline === 'top') {
  4258. y += lineHeight / 2;
  4259. }
  4260. else if (textBaseline === 'bottom') {
  4261. y -= lineHeight / 2;
  4262. }
  4263. return y;
  4264. }
  4265. function hasShadow(style) {
  4266. return style
  4267. && (style.shadowBlur || style.shadowOffsetX || style.shadowOffsetY);
  4268. }
  4269. function getShadowKey(displayable) {
  4270. var style = displayable.style;
  4271. var globalScale = displayable.getGlobalScale();
  4272. return [
  4273. style.shadowColor,
  4274. (style.shadowBlur || 0).toFixed(2),
  4275. (style.shadowOffsetX || 0).toFixed(2),
  4276. (style.shadowOffsetY || 0).toFixed(2),
  4277. globalScale[0],
  4278. globalScale[1]
  4279. ].join(',');
  4280. }
  4281. function isImagePattern(val) {
  4282. return val && (!!val.image);
  4283. }
  4284. function isSVGPattern(val) {
  4285. return val && (!!val.svgElement);
  4286. }
  4287. function isPattern(val) {
  4288. return isImagePattern(val) || isSVGPattern(val);
  4289. }
  4290. function isLinearGradient(val) {
  4291. return val.type === 'linear';
  4292. }
  4293. function isRadialGradient(val) {
  4294. return val.type === 'radial';
  4295. }
  4296. function isGradient(val) {
  4297. return val && (val.type === 'linear'
  4298. || val.type === 'radial');
  4299. }
  4300. function getIdURL(id) {
  4301. return "url(#" + id + ")";
  4302. }
  4303. function getPathPrecision(el) {
  4304. var scale = el.getGlobalScale();
  4305. var size = Math.max(scale[0], scale[1]);
  4306. return Math.max(Math.ceil(Math.log(size) / Math.log(10)), 1);
  4307. }
  4308. function getSRTTransformString(transform) {
  4309. var x = transform.x || 0;
  4310. var y = transform.y || 0;
  4311. var rotation = (transform.rotation || 0) * RADIAN_TO_DEGREE;
  4312. var scaleX = retrieve2(transform.scaleX, 1);
  4313. var scaleY = retrieve2(transform.scaleY, 1);
  4314. var skewX = transform.skewX || 0;
  4315. var skewY = transform.skewY || 0;
  4316. var res = [];
  4317. if (x || y) {
  4318. res.push("translate(" + x + "px," + y + "px)");
  4319. }
  4320. if (rotation) {
  4321. res.push("rotate(" + rotation + ")");
  4322. }
  4323. if (scaleX !== 1 || scaleY !== 1) {
  4324. res.push("scale(" + scaleX + "," + scaleY + ")");
  4325. }
  4326. if (skewX || skewY) {
  4327. res.push("skew(" + mathRound(skewX * RADIAN_TO_DEGREE) + "deg, " + mathRound(skewY * RADIAN_TO_DEGREE) + "deg)");
  4328. }
  4329. return res.join(' ');
  4330. }
  4331. var encodeBase64 = (function () {
  4332. if (env.hasGlobalWindow && isFunction(window.btoa)) {
  4333. return function (str) {
  4334. return window.btoa(unescape(encodeURIComponent(str)));
  4335. };
  4336. }
  4337. if (typeof Buffer !== 'undefined') {
  4338. return function (str) {
  4339. return Buffer.from(str).toString('base64');
  4340. };
  4341. }
  4342. return function (str) {
  4343. if ("development" !== 'production') {
  4344. logError('Base64 isn\'t natively supported in the current environment.');
  4345. }
  4346. return null;
  4347. };
  4348. })();
  4349. var arraySlice = Array.prototype.slice;
  4350. function interpolateNumber(p0, p1, percent) {
  4351. return (p1 - p0) * percent + p0;
  4352. }
  4353. function interpolate1DArray(out, p0, p1, percent) {
  4354. var len = p0.length;
  4355. for (var i = 0; i < len; i++) {
  4356. out[i] = interpolateNumber(p0[i], p1[i], percent);
  4357. }
  4358. return out;
  4359. }
  4360. function interpolate2DArray(out, p0, p1, percent) {
  4361. var len = p0.length;
  4362. var len2 = len && p0[0].length;
  4363. for (var i = 0; i < len; i++) {
  4364. if (!out[i]) {
  4365. out[i] = [];
  4366. }
  4367. for (var j = 0; j < len2; j++) {
  4368. out[i][j] = interpolateNumber(p0[i][j], p1[i][j], percent);
  4369. }
  4370. }
  4371. return out;
  4372. }
  4373. function add1DArray(out, p0, p1, sign) {
  4374. var len = p0.length;
  4375. for (var i = 0; i < len; i++) {
  4376. out[i] = p0[i] + p1[i] * sign;
  4377. }
  4378. return out;
  4379. }
  4380. function add2DArray(out, p0, p1, sign) {
  4381. var len = p0.length;
  4382. var len2 = len && p0[0].length;
  4383. for (var i = 0; i < len; i++) {
  4384. if (!out[i]) {
  4385. out[i] = [];
  4386. }
  4387. for (var j = 0; j < len2; j++) {
  4388. out[i][j] = p0[i][j] + p1[i][j] * sign;
  4389. }
  4390. }
  4391. return out;
  4392. }
  4393. function fillColorStops(val0, val1) {
  4394. var len0 = val0.length;
  4395. var len1 = val1.length;
  4396. var shorterArr = len0 > len1 ? val1 : val0;
  4397. var shorterLen = Math.min(len0, len1);
  4398. var last = shorterArr[shorterLen - 1] || { color: [0, 0, 0, 0], offset: 0 };
  4399. for (var i = shorterLen; i < Math.max(len0, len1); i++) {
  4400. shorterArr.push({
  4401. offset: last.offset,
  4402. color: last.color.slice()
  4403. });
  4404. }
  4405. }
  4406. function fillArray(val0, val1, arrDim) {
  4407. var arr0 = val0;
  4408. var arr1 = val1;
  4409. if (!arr0.push || !arr1.push) {
  4410. return;
  4411. }
  4412. var arr0Len = arr0.length;
  4413. var arr1Len = arr1.length;
  4414. if (arr0Len !== arr1Len) {
  4415. var isPreviousLarger = arr0Len > arr1Len;
  4416. if (isPreviousLarger) {
  4417. arr0.length = arr1Len;
  4418. }
  4419. else {
  4420. for (var i = arr0Len; i < arr1Len; i++) {
  4421. arr0.push(arrDim === 1 ? arr1[i] : arraySlice.call(arr1[i]));
  4422. }
  4423. }
  4424. }
  4425. var len2 = arr0[0] && arr0[0].length;
  4426. for (var i = 0; i < arr0.length; i++) {
  4427. if (arrDim === 1) {
  4428. if (isNaN(arr0[i])) {
  4429. arr0[i] = arr1[i];
  4430. }
  4431. }
  4432. else {
  4433. for (var j = 0; j < len2; j++) {
  4434. if (isNaN(arr0[i][j])) {
  4435. arr0[i][j] = arr1[i][j];
  4436. }
  4437. }
  4438. }
  4439. }
  4440. }
  4441. function cloneValue(value) {
  4442. if (isArrayLike(value)) {
  4443. var len = value.length;
  4444. if (isArrayLike(value[0])) {
  4445. var ret = [];
  4446. for (var i = 0; i < len; i++) {
  4447. ret.push(arraySlice.call(value[i]));
  4448. }
  4449. return ret;
  4450. }
  4451. return arraySlice.call(value);
  4452. }
  4453. return value;
  4454. }
  4455. function rgba2String(rgba) {
  4456. rgba[0] = Math.floor(rgba[0]) || 0;
  4457. rgba[1] = Math.floor(rgba[1]) || 0;
  4458. rgba[2] = Math.floor(rgba[2]) || 0;
  4459. rgba[3] = rgba[3] == null ? 1 : rgba[3];
  4460. return 'rgba(' + rgba.join(',') + ')';
  4461. }
  4462. function guessArrayDim(value) {
  4463. return isArrayLike(value && value[0]) ? 2 : 1;
  4464. }
  4465. var VALUE_TYPE_NUMBER = 0;
  4466. var VALUE_TYPE_1D_ARRAY = 1;
  4467. var VALUE_TYPE_2D_ARRAY = 2;
  4468. var VALUE_TYPE_COLOR = 3;
  4469. var VALUE_TYPE_LINEAR_GRADIENT = 4;
  4470. var VALUE_TYPE_RADIAL_GRADIENT = 5;
  4471. var VALUE_TYPE_UNKOWN = 6;
  4472. function isGradientValueType(valType) {
  4473. return valType === VALUE_TYPE_LINEAR_GRADIENT || valType === VALUE_TYPE_RADIAL_GRADIENT;
  4474. }
  4475. function isArrayValueType(valType) {
  4476. return valType === VALUE_TYPE_1D_ARRAY || valType === VALUE_TYPE_2D_ARRAY;
  4477. }
  4478. var tmpRgba = [0, 0, 0, 0];
  4479. var Track = (function () {
  4480. function Track(propName) {
  4481. this.keyframes = [];
  4482. this.discrete = false;
  4483. this._invalid = false;
  4484. this._needsSort = false;
  4485. this._lastFr = 0;
  4486. this._lastFrP = 0;
  4487. this.propName = propName;
  4488. }
  4489. Track.prototype.isFinished = function () {
  4490. return this._finished;
  4491. };
  4492. Track.prototype.setFinished = function () {
  4493. this._finished = true;
  4494. if (this._additiveTrack) {
  4495. this._additiveTrack.setFinished();
  4496. }
  4497. };
  4498. Track.prototype.needsAnimate = function () {
  4499. return this.keyframes.length >= 1;
  4500. };
  4501. Track.prototype.getAdditiveTrack = function () {
  4502. return this._additiveTrack;
  4503. };
  4504. Track.prototype.addKeyframe = function (time, rawValue, easing) {
  4505. this._needsSort = true;
  4506. var keyframes = this.keyframes;
  4507. var len = keyframes.length;
  4508. var discrete = false;
  4509. var valType = VALUE_TYPE_UNKOWN;
  4510. var value = rawValue;
  4511. if (isArrayLike(rawValue)) {
  4512. var arrayDim = guessArrayDim(rawValue);
  4513. valType = arrayDim;
  4514. if (arrayDim === 1 && !isNumber(rawValue[0])
  4515. || arrayDim === 2 && !isNumber(rawValue[0][0])) {
  4516. discrete = true;
  4517. }
  4518. }
  4519. else {
  4520. if (isNumber(rawValue) && !eqNaN(rawValue)) {
  4521. valType = VALUE_TYPE_NUMBER;
  4522. }
  4523. else if (isString(rawValue)) {
  4524. if (!isNaN(+rawValue)) {
  4525. valType = VALUE_TYPE_NUMBER;
  4526. }
  4527. else {
  4528. var colorArray = parse(rawValue);
  4529. if (colorArray) {
  4530. value = colorArray;
  4531. valType = VALUE_TYPE_COLOR;
  4532. }
  4533. }
  4534. }
  4535. else if (isGradientObject(rawValue)) {
  4536. var parsedGradient = extend({}, value);
  4537. parsedGradient.colorStops = map(rawValue.colorStops, function (colorStop) { return ({
  4538. offset: colorStop.offset,
  4539. color: parse(colorStop.color)
  4540. }); });
  4541. if (isLinearGradient(rawValue)) {
  4542. valType = VALUE_TYPE_LINEAR_GRADIENT;
  4543. }
  4544. else if (isRadialGradient(rawValue)) {
  4545. valType = VALUE_TYPE_RADIAL_GRADIENT;
  4546. }
  4547. value = parsedGradient;
  4548. }
  4549. }
  4550. if (len === 0) {
  4551. this.valType = valType;
  4552. }
  4553. else if (valType !== this.valType || valType === VALUE_TYPE_UNKOWN) {
  4554. discrete = true;
  4555. }
  4556. this.discrete = this.discrete || discrete;
  4557. var kf = {
  4558. time: time,
  4559. value: value,
  4560. rawValue: rawValue,
  4561. percent: 0
  4562. };
  4563. if (easing) {
  4564. kf.easing = easing;
  4565. kf.easingFunc = isFunction(easing)
  4566. ? easing
  4567. : easingFuncs[easing] || createCubicEasingFunc(easing);
  4568. }
  4569. keyframes.push(kf);
  4570. return kf;
  4571. };
  4572. Track.prototype.prepare = function (maxTime, additiveTrack) {
  4573. var kfs = this.keyframes;
  4574. if (this._needsSort) {
  4575. kfs.sort(function (a, b) {
  4576. return a.time - b.time;
  4577. });
  4578. }
  4579. var valType = this.valType;
  4580. var kfsLen = kfs.length;
  4581. var lastKf = kfs[kfsLen - 1];
  4582. var isDiscrete = this.discrete;
  4583. var isArr = isArrayValueType(valType);
  4584. var isGradient = isGradientValueType(valType);
  4585. for (var i = 0; i < kfsLen; i++) {
  4586. var kf = kfs[i];
  4587. var value = kf.value;
  4588. var lastValue = lastKf.value;
  4589. kf.percent = kf.time / maxTime;
  4590. if (!isDiscrete) {
  4591. if (isArr && i !== kfsLen - 1) {
  4592. fillArray(value, lastValue, valType);
  4593. }
  4594. else if (isGradient) {
  4595. fillColorStops(value.colorStops, lastValue.colorStops);
  4596. }
  4597. }
  4598. }
  4599. if (!isDiscrete
  4600. && valType !== VALUE_TYPE_RADIAL_GRADIENT
  4601. && additiveTrack
  4602. && this.needsAnimate()
  4603. && additiveTrack.needsAnimate()
  4604. && valType === additiveTrack.valType
  4605. && !additiveTrack._finished) {
  4606. this._additiveTrack = additiveTrack;
  4607. var startValue = kfs[0].value;
  4608. for (var i = 0; i < kfsLen; i++) {
  4609. if (valType === VALUE_TYPE_NUMBER) {
  4610. kfs[i].additiveValue = kfs[i].value - startValue;
  4611. }
  4612. else if (valType === VALUE_TYPE_COLOR) {
  4613. kfs[i].additiveValue =
  4614. add1DArray([], kfs[i].value, startValue, -1);
  4615. }
  4616. else if (isArrayValueType(valType)) {
  4617. kfs[i].additiveValue = valType === VALUE_TYPE_1D_ARRAY
  4618. ? add1DArray([], kfs[i].value, startValue, -1)
  4619. : add2DArray([], kfs[i].value, startValue, -1);
  4620. }
  4621. }
  4622. }
  4623. };
  4624. Track.prototype.step = function (target, percent) {
  4625. if (this._finished) {
  4626. return;
  4627. }
  4628. if (this._additiveTrack && this._additiveTrack._finished) {
  4629. this._additiveTrack = null;
  4630. }
  4631. var isAdditive = this._additiveTrack != null;
  4632. var valueKey = isAdditive ? 'additiveValue' : 'value';
  4633. var valType = this.valType;
  4634. var keyframes = this.keyframes;
  4635. var kfsNum = keyframes.length;
  4636. var propName = this.propName;
  4637. var isValueColor = valType === VALUE_TYPE_COLOR;
  4638. var frameIdx;
  4639. var lastFrame = this._lastFr;
  4640. var mathMin = Math.min;
  4641. var frame;
  4642. var nextFrame;
  4643. if (kfsNum === 1) {
  4644. frame = nextFrame = keyframes[0];
  4645. }
  4646. else {
  4647. if (percent < 0) {
  4648. frameIdx = 0;
  4649. }
  4650. else if (percent < this._lastFrP) {
  4651. var start = mathMin(lastFrame + 1, kfsNum - 1);
  4652. for (frameIdx = start; frameIdx >= 0; frameIdx--) {
  4653. if (keyframes[frameIdx].percent <= percent) {
  4654. break;
  4655. }
  4656. }
  4657. frameIdx = mathMin(frameIdx, kfsNum - 2);
  4658. }
  4659. else {
  4660. for (frameIdx = lastFrame; frameIdx < kfsNum; frameIdx++) {
  4661. if (keyframes[frameIdx].percent > percent) {
  4662. break;
  4663. }
  4664. }
  4665. frameIdx = mathMin(frameIdx - 1, kfsNum - 2);
  4666. }
  4667. nextFrame = keyframes[frameIdx + 1];
  4668. frame = keyframes[frameIdx];
  4669. }
  4670. if (!(frame && nextFrame)) {
  4671. return;
  4672. }
  4673. this._lastFr = frameIdx;
  4674. this._lastFrP = percent;
  4675. var interval = (nextFrame.percent - frame.percent);
  4676. var w = interval === 0 ? 1 : mathMin((percent - frame.percent) / interval, 1);
  4677. if (nextFrame.easingFunc) {
  4678. w = nextFrame.easingFunc(w);
  4679. }
  4680. var targetArr = isAdditive ? this._additiveValue
  4681. : (isValueColor ? tmpRgba : target[propName]);
  4682. if ((isArrayValueType(valType) || isValueColor) && !targetArr) {
  4683. targetArr = this._additiveValue = [];
  4684. }
  4685. if (this.discrete) {
  4686. target[propName] = w < 1 ? frame.rawValue : nextFrame.rawValue;
  4687. }
  4688. else if (isArrayValueType(valType)) {
  4689. valType === VALUE_TYPE_1D_ARRAY
  4690. ? interpolate1DArray(targetArr, frame[valueKey], nextFrame[valueKey], w)
  4691. : interpolate2DArray(targetArr, frame[valueKey], nextFrame[valueKey], w);
  4692. }
  4693. else if (isGradientValueType(valType)) {
  4694. var val = frame[valueKey];
  4695. var nextVal_1 = nextFrame[valueKey];
  4696. var isLinearGradient_1 = valType === VALUE_TYPE_LINEAR_GRADIENT;
  4697. target[propName] = {
  4698. type: isLinearGradient_1 ? 'linear' : 'radial',
  4699. x: interpolateNumber(val.x, nextVal_1.x, w),
  4700. y: interpolateNumber(val.y, nextVal_1.y, w),
  4701. colorStops: map(val.colorStops, function (colorStop, idx) {
  4702. var nextColorStop = nextVal_1.colorStops[idx];
  4703. return {
  4704. offset: interpolateNumber(colorStop.offset, nextColorStop.offset, w),
  4705. color: rgba2String(interpolate1DArray([], colorStop.color, nextColorStop.color, w))
  4706. };
  4707. }),
  4708. global: nextVal_1.global
  4709. };
  4710. if (isLinearGradient_1) {
  4711. target[propName].x2 = interpolateNumber(val.x2, nextVal_1.x2, w);
  4712. target[propName].y2 = interpolateNumber(val.y2, nextVal_1.y2, w);
  4713. }
  4714. else {
  4715. target[propName].r = interpolateNumber(val.r, nextVal_1.r, w);
  4716. }
  4717. }
  4718. else if (isValueColor) {
  4719. interpolate1DArray(targetArr, frame[valueKey], nextFrame[valueKey], w);
  4720. if (!isAdditive) {
  4721. target[propName] = rgba2String(targetArr);
  4722. }
  4723. }
  4724. else {
  4725. var value = interpolateNumber(frame[valueKey], nextFrame[valueKey], w);
  4726. if (isAdditive) {
  4727. this._additiveValue = value;
  4728. }
  4729. else {
  4730. target[propName] = value;
  4731. }
  4732. }
  4733. if (isAdditive) {
  4734. this._addToTarget(target);
  4735. }
  4736. };
  4737. Track.prototype._addToTarget = function (target) {
  4738. var valType = this.valType;
  4739. var propName = this.propName;
  4740. var additiveValue = this._additiveValue;
  4741. if (valType === VALUE_TYPE_NUMBER) {
  4742. target[propName] = target[propName] + additiveValue;
  4743. }
  4744. else if (valType === VALUE_TYPE_COLOR) {
  4745. parse(target[propName], tmpRgba);
  4746. add1DArray(tmpRgba, tmpRgba, additiveValue, 1);
  4747. target[propName] = rgba2String(tmpRgba);
  4748. }
  4749. else if (valType === VALUE_TYPE_1D_ARRAY) {
  4750. add1DArray(target[propName], target[propName], additiveValue, 1);
  4751. }
  4752. else if (valType === VALUE_TYPE_2D_ARRAY) {
  4753. add2DArray(target[propName], target[propName], additiveValue, 1);
  4754. }
  4755. };
  4756. return Track;
  4757. }());
  4758. var Animator = (function () {
  4759. function Animator(target, loop, allowDiscreteAnimation, additiveTo) {
  4760. this._tracks = {};
  4761. this._trackKeys = [];
  4762. this._maxTime = 0;
  4763. this._started = 0;
  4764. this._clip = null;
  4765. this._target = target;
  4766. this._loop = loop;
  4767. if (loop && additiveTo) {
  4768. logError('Can\' use additive animation on looped animation.');
  4769. return;
  4770. }
  4771. this._additiveAnimators = additiveTo;
  4772. this._allowDiscrete = allowDiscreteAnimation;
  4773. }
  4774. Animator.prototype.getMaxTime = function () {
  4775. return this._maxTime;
  4776. };
  4777. Animator.prototype.getDelay = function () {
  4778. return this._delay;
  4779. };
  4780. Animator.prototype.getLoop = function () {
  4781. return this._loop;
  4782. };
  4783. Animator.prototype.getTarget = function () {
  4784. return this._target;
  4785. };
  4786. Animator.prototype.changeTarget = function (target) {
  4787. this._target = target;
  4788. };
  4789. Animator.prototype.when = function (time, props, easing) {
  4790. return this.whenWithKeys(time, props, keys(props), easing);
  4791. };
  4792. Animator.prototype.whenWithKeys = function (time, props, propNames, easing) {
  4793. var tracks = this._tracks;
  4794. for (var i = 0; i < propNames.length; i++) {
  4795. var propName = propNames[i];
  4796. var track = tracks[propName];
  4797. if (!track) {
  4798. track = tracks[propName] = new Track(propName);
  4799. var initialValue = void 0;
  4800. var additiveTrack = this._getAdditiveTrack(propName);
  4801. if (additiveTrack) {
  4802. var addtiveTrackKfs = additiveTrack.keyframes;
  4803. var lastFinalKf = addtiveTrackKfs[addtiveTrackKfs.length - 1];
  4804. initialValue = lastFinalKf && lastFinalKf.value;
  4805. if (additiveTrack.valType === VALUE_TYPE_COLOR && initialValue) {
  4806. initialValue = rgba2String(initialValue);
  4807. }
  4808. }
  4809. else {
  4810. initialValue = this._target[propName];
  4811. }
  4812. if (initialValue == null) {
  4813. continue;
  4814. }
  4815. if (time > 0) {
  4816. track.addKeyframe(0, cloneValue(initialValue), easing);
  4817. }
  4818. this._trackKeys.push(propName);
  4819. }
  4820. track.addKeyframe(time, cloneValue(props[propName]), easing);
  4821. }
  4822. this._maxTime = Math.max(this._maxTime, time);
  4823. return this;
  4824. };
  4825. Animator.prototype.pause = function () {
  4826. this._clip.pause();
  4827. this._paused = true;
  4828. };
  4829. Animator.prototype.resume = function () {
  4830. this._clip.resume();
  4831. this._paused = false;
  4832. };
  4833. Animator.prototype.isPaused = function () {
  4834. return !!this._paused;
  4835. };
  4836. Animator.prototype.duration = function (duration) {
  4837. this._maxTime = duration;
  4838. this._force = true;
  4839. return this;
  4840. };
  4841. Animator.prototype._doneCallback = function () {
  4842. this._setTracksFinished();
  4843. this._clip = null;
  4844. var doneList = this._doneCbs;
  4845. if (doneList) {
  4846. var len = doneList.length;
  4847. for (var i = 0; i < len; i++) {
  4848. doneList[i].call(this);
  4849. }
  4850. }
  4851. };
  4852. Animator.prototype._abortedCallback = function () {
  4853. this._setTracksFinished();
  4854. var animation = this.animation;
  4855. var abortedList = this._abortedCbs;
  4856. if (animation) {
  4857. animation.removeClip(this._clip);
  4858. }
  4859. this._clip = null;
  4860. if (abortedList) {
  4861. for (var i = 0; i < abortedList.length; i++) {
  4862. abortedList[i].call(this);
  4863. }
  4864. }
  4865. };
  4866. Animator.prototype._setTracksFinished = function () {
  4867. var tracks = this._tracks;
  4868. var tracksKeys = this._trackKeys;
  4869. for (var i = 0; i < tracksKeys.length; i++) {
  4870. tracks[tracksKeys[i]].setFinished();
  4871. }
  4872. };
  4873. Animator.prototype._getAdditiveTrack = function (trackName) {
  4874. var additiveTrack;
  4875. var additiveAnimators = this._additiveAnimators;
  4876. if (additiveAnimators) {
  4877. for (var i = 0; i < additiveAnimators.length; i++) {
  4878. var track = additiveAnimators[i].getTrack(trackName);
  4879. if (track) {
  4880. additiveTrack = track;
  4881. }
  4882. }
  4883. }
  4884. return additiveTrack;
  4885. };
  4886. Animator.prototype.start = function (easing) {
  4887. if (this._started > 0) {
  4888. return;
  4889. }
  4890. this._started = 1;
  4891. var self = this;
  4892. var tracks = [];
  4893. var maxTime = this._maxTime || 0;
  4894. for (var i = 0; i < this._trackKeys.length; i++) {
  4895. var propName = this._trackKeys[i];
  4896. var track = this._tracks[propName];
  4897. var additiveTrack = this._getAdditiveTrack(propName);
  4898. var kfs = track.keyframes;
  4899. var kfsNum = kfs.length;
  4900. track.prepare(maxTime, additiveTrack);
  4901. if (track.needsAnimate()) {
  4902. if (!this._allowDiscrete && track.discrete) {
  4903. var lastKf = kfs[kfsNum - 1];
  4904. if (lastKf) {
  4905. self._target[track.propName] = lastKf.rawValue;
  4906. }
  4907. track.setFinished();
  4908. }
  4909. else {
  4910. tracks.push(track);
  4911. }
  4912. }
  4913. }
  4914. if (tracks.length || this._force) {
  4915. var clip = new Clip({
  4916. life: maxTime,
  4917. loop: this._loop,
  4918. delay: this._delay || 0,
  4919. onframe: function (percent) {
  4920. self._started = 2;
  4921. var additiveAnimators = self._additiveAnimators;
  4922. if (additiveAnimators) {
  4923. var stillHasAdditiveAnimator = false;
  4924. for (var i = 0; i < additiveAnimators.length; i++) {
  4925. if (additiveAnimators[i]._clip) {
  4926. stillHasAdditiveAnimator = true;
  4927. break;
  4928. }
  4929. }
  4930. if (!stillHasAdditiveAnimator) {
  4931. self._additiveAnimators = null;
  4932. }
  4933. }
  4934. for (var i = 0; i < tracks.length; i++) {
  4935. tracks[i].step(self._target, percent);
  4936. }
  4937. var onframeList = self._onframeCbs;
  4938. if (onframeList) {
  4939. for (var i = 0; i < onframeList.length; i++) {
  4940. onframeList[i](self._target, percent);
  4941. }
  4942. }
  4943. },
  4944. ondestroy: function () {
  4945. self._doneCallback();
  4946. }
  4947. });
  4948. this._clip = clip;
  4949. if (this.animation) {
  4950. this.animation.addClip(clip);
  4951. }
  4952. if (easing) {
  4953. clip.setEasing(easing);
  4954. }
  4955. }
  4956. else {
  4957. this._doneCallback();
  4958. }
  4959. return this;
  4960. };
  4961. Animator.prototype.stop = function (forwardToLast) {
  4962. if (!this._clip) {
  4963. return;
  4964. }
  4965. var clip = this._clip;
  4966. if (forwardToLast) {
  4967. clip.onframe(1);
  4968. }
  4969. this._abortedCallback();
  4970. };
  4971. Animator.prototype.delay = function (time) {
  4972. this._delay = time;
  4973. return this;
  4974. };
  4975. Animator.prototype.during = function (cb) {
  4976. if (cb) {
  4977. if (!this._onframeCbs) {
  4978. this._onframeCbs = [];
  4979. }
  4980. this._onframeCbs.push(cb);
  4981. }
  4982. return this;
  4983. };
  4984. Animator.prototype.done = function (cb) {
  4985. if (cb) {
  4986. if (!this._doneCbs) {
  4987. this._doneCbs = [];
  4988. }
  4989. this._doneCbs.push(cb);
  4990. }
  4991. return this;
  4992. };
  4993. Animator.prototype.aborted = function (cb) {
  4994. if (cb) {
  4995. if (!this._abortedCbs) {
  4996. this._abortedCbs = [];
  4997. }
  4998. this._abortedCbs.push(cb);
  4999. }
  5000. return this;
  5001. };
  5002. Animator.prototype.getClip = function () {
  5003. return this._clip;
  5004. };
  5005. Animator.prototype.getTrack = function (propName) {
  5006. return this._tracks[propName];
  5007. };
  5008. Animator.prototype.getTracks = function () {
  5009. var _this = this;
  5010. return map(this._trackKeys, function (key) { return _this._tracks[key]; });
  5011. };
  5012. Animator.prototype.stopTracks = function (propNames, forwardToLast) {
  5013. if (!propNames.length || !this._clip) {
  5014. return true;
  5015. }
  5016. var tracks = this._tracks;
  5017. var tracksKeys = this._trackKeys;
  5018. for (var i = 0; i < propNames.length; i++) {
  5019. var track = tracks[propNames[i]];
  5020. if (track && !track.isFinished()) {
  5021. if (forwardToLast) {
  5022. track.step(this._target, 1);
  5023. }
  5024. else if (this._started === 1) {
  5025. track.step(this._target, 0);
  5026. }
  5027. track.setFinished();
  5028. }
  5029. }
  5030. var allAborted = true;
  5031. for (var i = 0; i < tracksKeys.length; i++) {
  5032. if (!tracks[tracksKeys[i]].isFinished()) {
  5033. allAborted = false;
  5034. break;
  5035. }
  5036. }
  5037. if (allAborted) {
  5038. this._abortedCallback();
  5039. }
  5040. return allAborted;
  5041. };
  5042. Animator.prototype.saveTo = function (target, trackKeys, firstOrLast) {
  5043. if (!target) {
  5044. return;
  5045. }
  5046. trackKeys = trackKeys || this._trackKeys;
  5047. for (var i = 0; i < trackKeys.length; i++) {
  5048. var propName = trackKeys[i];
  5049. var track = this._tracks[propName];
  5050. if (!track || track.isFinished()) {
  5051. continue;
  5052. }
  5053. var kfs = track.keyframes;
  5054. var kf = kfs[firstOrLast ? 0 : kfs.length - 1];
  5055. if (kf) {
  5056. target[propName] = cloneValue(kf.rawValue);
  5057. }
  5058. }
  5059. };
  5060. Animator.prototype.__changeFinalValue = function (finalProps, trackKeys) {
  5061. trackKeys = trackKeys || keys(finalProps);
  5062. for (var i = 0; i < trackKeys.length; i++) {
  5063. var propName = trackKeys[i];
  5064. var track = this._tracks[propName];
  5065. if (!track) {
  5066. continue;
  5067. }
  5068. var kfs = track.keyframes;
  5069. if (kfs.length > 1) {
  5070. var lastKf = kfs.pop();
  5071. track.addKeyframe(lastKf.time, finalProps[propName]);
  5072. track.prepare(this._maxTime, track.getAdditiveTrack());
  5073. }
  5074. }
  5075. };
  5076. return Animator;
  5077. }());
  5078. function getTime() {
  5079. return new Date().getTime();
  5080. }
  5081. var Animation = (function (_super) {
  5082. __extends(Animation, _super);
  5083. function Animation(opts) {
  5084. var _this = _super.call(this) || this;
  5085. _this._running = false;
  5086. _this._time = 0;
  5087. _this._pausedTime = 0;
  5088. _this._pauseStart = 0;
  5089. _this._paused = false;
  5090. opts = opts || {};
  5091. _this.stage = opts.stage || {};
  5092. return _this;
  5093. }
  5094. Animation.prototype.addClip = function (clip) {
  5095. if (clip.animation) {
  5096. this.removeClip(clip);
  5097. }
  5098. if (!this._head) {
  5099. this._head = this._tail = clip;
  5100. }
  5101. else {
  5102. this._tail.next = clip;
  5103. clip.prev = this._tail;
  5104. clip.next = null;
  5105. this._tail = clip;
  5106. }
  5107. clip.animation = this;
  5108. };
  5109. Animation.prototype.addAnimator = function (animator) {
  5110. animator.animation = this;
  5111. var clip = animator.getClip();
  5112. if (clip) {
  5113. this.addClip(clip);
  5114. }
  5115. };
  5116. Animation.prototype.removeClip = function (clip) {
  5117. if (!clip.animation) {
  5118. return;
  5119. }
  5120. var prev = clip.prev;
  5121. var next = clip.next;
  5122. if (prev) {
  5123. prev.next = next;
  5124. }
  5125. else {
  5126. this._head = next;
  5127. }
  5128. if (next) {
  5129. next.prev = prev;
  5130. }
  5131. else {
  5132. this._tail = prev;
  5133. }
  5134. clip.next = clip.prev = clip.animation = null;
  5135. };
  5136. Animation.prototype.removeAnimator = function (animator) {
  5137. var clip = animator.getClip();
  5138. if (clip) {
  5139. this.removeClip(clip);
  5140. }
  5141. animator.animation = null;
  5142. };
  5143. Animation.prototype.update = function (notTriggerFrameAndStageUpdate) {
  5144. var time = getTime() - this._pausedTime;
  5145. var delta = time - this._time;
  5146. var clip = this._head;
  5147. while (clip) {
  5148. var nextClip = clip.next;
  5149. var finished = clip.step(time, delta);
  5150. if (finished) {
  5151. clip.ondestroy();
  5152. this.removeClip(clip);
  5153. clip = nextClip;
  5154. }
  5155. else {
  5156. clip = nextClip;
  5157. }
  5158. }
  5159. this._time = time;
  5160. if (!notTriggerFrameAndStageUpdate) {
  5161. this.trigger('frame', delta);
  5162. this.stage.update && this.stage.update();
  5163. }
  5164. };
  5165. Animation.prototype._startLoop = function () {
  5166. var self = this;
  5167. this._running = true;
  5168. function step() {
  5169. if (self._running) {
  5170. requestAnimationFrame$1(step);
  5171. !self._paused && self.update();
  5172. }
  5173. }
  5174. requestAnimationFrame$1(step);
  5175. };
  5176. Animation.prototype.start = function () {
  5177. if (this._running) {
  5178. return;
  5179. }
  5180. this._time = getTime();
  5181. this._pausedTime = 0;
  5182. this._startLoop();
  5183. };
  5184. Animation.prototype.stop = function () {
  5185. this._running = false;
  5186. };
  5187. Animation.prototype.pause = function () {
  5188. if (!this._paused) {
  5189. this._pauseStart = getTime();
  5190. this._paused = true;
  5191. }
  5192. };
  5193. Animation.prototype.resume = function () {
  5194. if (this._paused) {
  5195. this._pausedTime += getTime() - this._pauseStart;
  5196. this._paused = false;
  5197. }
  5198. };
  5199. Animation.prototype.clear = function () {
  5200. var clip = this._head;
  5201. while (clip) {
  5202. var nextClip = clip.next;
  5203. clip.prev = clip.next = clip.animation = null;
  5204. clip = nextClip;
  5205. }
  5206. this._head = this._tail = null;
  5207. };
  5208. Animation.prototype.isFinished = function () {
  5209. return this._head == null;
  5210. };
  5211. Animation.prototype.animate = function (target, options) {
  5212. options = options || {};
  5213. this.start();
  5214. var animator = new Animator(target, options.loop);
  5215. this.addAnimator(animator);
  5216. return animator;
  5217. };
  5218. return Animation;
  5219. }(Eventful));
  5220. var TOUCH_CLICK_DELAY = 300;
  5221. var globalEventSupported = env.domSupported;
  5222. var localNativeListenerNames = (function () {
  5223. var mouseHandlerNames = [
  5224. 'click', 'dblclick', 'mousewheel', 'wheel', 'mouseout',
  5225. 'mouseup', 'mousedown', 'mousemove', 'contextmenu'
  5226. ];
  5227. var touchHandlerNames = [
  5228. 'touchstart', 'touchend', 'touchmove'
  5229. ];
  5230. var pointerEventNameMap = {
  5231. pointerdown: 1, pointerup: 1, pointermove: 1, pointerout: 1
  5232. };
  5233. var pointerHandlerNames = map(mouseHandlerNames, function (name) {
  5234. var nm = name.replace('mouse', 'pointer');
  5235. return pointerEventNameMap.hasOwnProperty(nm) ? nm : name;
  5236. });
  5237. return {
  5238. mouse: mouseHandlerNames,
  5239. touch: touchHandlerNames,
  5240. pointer: pointerHandlerNames
  5241. };
  5242. })();
  5243. var globalNativeListenerNames = {
  5244. mouse: ['mousemove', 'mouseup'],
  5245. pointer: ['pointermove', 'pointerup']
  5246. };
  5247. var wheelEventSupported = false;
  5248. function isPointerFromTouch(event) {
  5249. var pointerType = event.pointerType;
  5250. return pointerType === 'pen' || pointerType === 'touch';
  5251. }
  5252. function setTouchTimer(scope) {
  5253. scope.touching = true;
  5254. if (scope.touchTimer != null) {
  5255. clearTimeout(scope.touchTimer);
  5256. scope.touchTimer = null;
  5257. }
  5258. scope.touchTimer = setTimeout(function () {
  5259. scope.touching = false;
  5260. scope.touchTimer = null;
  5261. }, 700);
  5262. }
  5263. function markTouch(event) {
  5264. event && (event.zrByTouch = true);
  5265. }
  5266. function normalizeGlobalEvent(instance, event) {
  5267. return normalizeEvent(instance.dom, new FakeGlobalEvent(instance, event), true);
  5268. }
  5269. function isLocalEl(instance, el) {
  5270. var elTmp = el;
  5271. var isLocal = false;
  5272. while (elTmp && elTmp.nodeType !== 9
  5273. && !(isLocal = elTmp.domBelongToZr
  5274. || (elTmp !== el && elTmp === instance.painterRoot))) {
  5275. elTmp = elTmp.parentNode;
  5276. }
  5277. return isLocal;
  5278. }
  5279. var FakeGlobalEvent = (function () {
  5280. function FakeGlobalEvent(instance, event) {
  5281. this.stopPropagation = noop;
  5282. this.stopImmediatePropagation = noop;
  5283. this.preventDefault = noop;
  5284. this.type = event.type;
  5285. this.target = this.currentTarget = instance.dom;
  5286. this.pointerType = event.pointerType;
  5287. this.clientX = event.clientX;
  5288. this.clientY = event.clientY;
  5289. }
  5290. return FakeGlobalEvent;
  5291. }());
  5292. var localDOMHandlers = {
  5293. mousedown: function (event) {
  5294. event = normalizeEvent(this.dom, event);
  5295. this.__mayPointerCapture = [event.zrX, event.zrY];
  5296. this.trigger('mousedown', event);
  5297. },
  5298. mousemove: function (event) {
  5299. event = normalizeEvent(this.dom, event);
  5300. var downPoint = this.__mayPointerCapture;
  5301. if (downPoint && (event.zrX !== downPoint[0] || event.zrY !== downPoint[1])) {
  5302. this.__togglePointerCapture(true);
  5303. }
  5304. this.trigger('mousemove', event);
  5305. },
  5306. mouseup: function (event) {
  5307. event = normalizeEvent(this.dom, event);
  5308. this.__togglePointerCapture(false);
  5309. this.trigger('mouseup', event);
  5310. },
  5311. mouseout: function (event) {
  5312. event = normalizeEvent(this.dom, event);
  5313. var element = event.toElement || event.relatedTarget;
  5314. if (!isLocalEl(this, element)) {
  5315. if (this.__pointerCapturing) {
  5316. event.zrEventControl = 'no_globalout';
  5317. }
  5318. this.trigger('mouseout', event);
  5319. }
  5320. },
  5321. wheel: function (event) {
  5322. wheelEventSupported = true;
  5323. event = normalizeEvent(this.dom, event);
  5324. this.trigger('mousewheel', event);
  5325. },
  5326. mousewheel: function (event) {
  5327. if (wheelEventSupported) {
  5328. return;
  5329. }
  5330. event = normalizeEvent(this.dom, event);
  5331. this.trigger('mousewheel', event);
  5332. },
  5333. touchstart: function (event) {
  5334. event = normalizeEvent(this.dom, event);
  5335. markTouch(event);
  5336. this.__lastTouchMoment = new Date();
  5337. this.handler.processGesture(event, 'start');
  5338. localDOMHandlers.mousemove.call(this, event);
  5339. localDOMHandlers.mousedown.call(this, event);
  5340. },
  5341. touchmove: function (event) {
  5342. event = normalizeEvent(this.dom, event);
  5343. markTouch(event);
  5344. this.handler.processGesture(event, 'change');
  5345. localDOMHandlers.mousemove.call(this, event);
  5346. },
  5347. touchend: function (event) {
  5348. event = normalizeEvent(this.dom, event);
  5349. markTouch(event);
  5350. this.handler.processGesture(event, 'end');
  5351. localDOMHandlers.mouseup.call(this, event);
  5352. if (+new Date() - (+this.__lastTouchMoment) < TOUCH_CLICK_DELAY) {
  5353. localDOMHandlers.click.call(this, event);
  5354. }
  5355. },
  5356. pointerdown: function (event) {
  5357. localDOMHandlers.mousedown.call(this, event);
  5358. },
  5359. pointermove: function (event) {
  5360. if (!isPointerFromTouch(event)) {
  5361. localDOMHandlers.mousemove.call(this, event);
  5362. }
  5363. },
  5364. pointerup: function (event) {
  5365. localDOMHandlers.mouseup.call(this, event);
  5366. },
  5367. pointerout: function (event) {
  5368. if (!isPointerFromTouch(event)) {
  5369. localDOMHandlers.mouseout.call(this, event);
  5370. }
  5371. }
  5372. };
  5373. each(['click', 'dblclick', 'contextmenu'], function (name) {
  5374. localDOMHandlers[name] = function (event) {
  5375. event = normalizeEvent(this.dom, event);
  5376. this.trigger(name, event);
  5377. };
  5378. });
  5379. var globalDOMHandlers = {
  5380. pointermove: function (event) {
  5381. if (!isPointerFromTouch(event)) {
  5382. globalDOMHandlers.mousemove.call(this, event);
  5383. }
  5384. },
  5385. pointerup: function (event) {
  5386. globalDOMHandlers.mouseup.call(this, event);
  5387. },
  5388. mousemove: function (event) {
  5389. this.trigger('mousemove', event);
  5390. },
  5391. mouseup: function (event) {
  5392. var pointerCaptureReleasing = this.__pointerCapturing;
  5393. this.__togglePointerCapture(false);
  5394. this.trigger('mouseup', event);
  5395. if (pointerCaptureReleasing) {
  5396. event.zrEventControl = 'only_globalout';
  5397. this.trigger('mouseout', event);
  5398. }
  5399. }
  5400. };
  5401. function mountLocalDOMEventListeners(instance, scope) {
  5402. var domHandlers = scope.domHandlers;
  5403. if (env.pointerEventsSupported) {
  5404. each(localNativeListenerNames.pointer, function (nativeEventName) {
  5405. mountSingleDOMEventListener(scope, nativeEventName, function (event) {
  5406. domHandlers[nativeEventName].call(instance, event);
  5407. });
  5408. });
  5409. }
  5410. else {
  5411. if (env.touchEventsSupported) {
  5412. each(localNativeListenerNames.touch, function (nativeEventName) {
  5413. mountSingleDOMEventListener(scope, nativeEventName, function (event) {
  5414. domHandlers[nativeEventName].call(instance, event);
  5415. setTouchTimer(scope);
  5416. });
  5417. });
  5418. }
  5419. each(localNativeListenerNames.mouse, function (nativeEventName) {
  5420. mountSingleDOMEventListener(scope, nativeEventName, function (event) {
  5421. event = getNativeEvent(event);
  5422. if (!scope.touching) {
  5423. domHandlers[nativeEventName].call(instance, event);
  5424. }
  5425. });
  5426. });
  5427. }
  5428. }
  5429. function mountGlobalDOMEventListeners(instance, scope) {
  5430. if (env.pointerEventsSupported) {
  5431. each(globalNativeListenerNames.pointer, mount);
  5432. }
  5433. else if (!env.touchEventsSupported) {
  5434. each(globalNativeListenerNames.mouse, mount);
  5435. }
  5436. function mount(nativeEventName) {
  5437. function nativeEventListener(event) {
  5438. event = getNativeEvent(event);
  5439. if (!isLocalEl(instance, event.target)) {
  5440. event = normalizeGlobalEvent(instance, event);
  5441. scope.domHandlers[nativeEventName].call(instance, event);
  5442. }
  5443. }
  5444. mountSingleDOMEventListener(scope, nativeEventName, nativeEventListener, { capture: true });
  5445. }
  5446. }
  5447. function mountSingleDOMEventListener(scope, nativeEventName, listener, opt) {
  5448. scope.mounted[nativeEventName] = listener;
  5449. scope.listenerOpts[nativeEventName] = opt;
  5450. addEventListener(scope.domTarget, nativeEventName, listener, opt);
  5451. }
  5452. function unmountDOMEventListeners(scope) {
  5453. var mounted = scope.mounted;
  5454. for (var nativeEventName in mounted) {
  5455. if (mounted.hasOwnProperty(nativeEventName)) {
  5456. removeEventListener(scope.domTarget, nativeEventName, mounted[nativeEventName], scope.listenerOpts[nativeEventName]);
  5457. }
  5458. }
  5459. scope.mounted = {};
  5460. }
  5461. var DOMHandlerScope = (function () {
  5462. function DOMHandlerScope(domTarget, domHandlers) {
  5463. this.mounted = {};
  5464. this.listenerOpts = {};
  5465. this.touching = false;
  5466. this.domTarget = domTarget;
  5467. this.domHandlers = domHandlers;
  5468. }
  5469. return DOMHandlerScope;
  5470. }());
  5471. var HandlerDomProxy = (function (_super) {
  5472. __extends(HandlerDomProxy, _super);
  5473. function HandlerDomProxy(dom, painterRoot) {
  5474. var _this = _super.call(this) || this;
  5475. _this.__pointerCapturing = false;
  5476. _this.dom = dom;
  5477. _this.painterRoot = painterRoot;
  5478. _this._localHandlerScope = new DOMHandlerScope(dom, localDOMHandlers);
  5479. if (globalEventSupported) {
  5480. _this._globalHandlerScope = new DOMHandlerScope(document, globalDOMHandlers);
  5481. }
  5482. mountLocalDOMEventListeners(_this, _this._localHandlerScope);
  5483. return _this;
  5484. }
  5485. HandlerDomProxy.prototype.dispose = function () {
  5486. unmountDOMEventListeners(this._localHandlerScope);
  5487. if (globalEventSupported) {
  5488. unmountDOMEventListeners(this._globalHandlerScope);
  5489. }
  5490. };
  5491. HandlerDomProxy.prototype.setCursor = function (cursorStyle) {
  5492. this.dom.style && (this.dom.style.cursor = cursorStyle || 'default');
  5493. };
  5494. HandlerDomProxy.prototype.__togglePointerCapture = function (isPointerCapturing) {
  5495. this.__mayPointerCapture = null;
  5496. if (globalEventSupported
  5497. && ((+this.__pointerCapturing) ^ (+isPointerCapturing))) {
  5498. this.__pointerCapturing = isPointerCapturing;
  5499. var globalHandlerScope = this._globalHandlerScope;
  5500. isPointerCapturing
  5501. ? mountGlobalDOMEventListeners(this, globalHandlerScope)
  5502. : unmountDOMEventListeners(globalHandlerScope);
  5503. }
  5504. };
  5505. return HandlerDomProxy;
  5506. }(Eventful));
  5507. var dpr = 1;
  5508. if (env.hasGlobalWindow) {
  5509. dpr = Math.max(window.devicePixelRatio
  5510. || (window.screen && window.screen.deviceXDPI / window.screen.logicalXDPI)
  5511. || 1, 1);
  5512. }
  5513. var devicePixelRatio = dpr;
  5514. var DARK_MODE_THRESHOLD = 0.4;
  5515. var DARK_LABEL_COLOR = '#333';
  5516. var LIGHT_LABEL_COLOR = '#ccc';
  5517. var LIGHTER_LABEL_COLOR = '#eee';
  5518. var mIdentity = identity;
  5519. var EPSILON$3 = 5e-5;
  5520. function isNotAroundZero$1(val) {
  5521. return val > EPSILON$3 || val < -EPSILON$3;
  5522. }
  5523. var scaleTmp = [];
  5524. var tmpTransform = [];
  5525. var originTransform = create$1();
  5526. var abs = Math.abs;
  5527. var Transformable = (function () {
  5528. function Transformable() {
  5529. }
  5530. Transformable.prototype.getLocalTransform = function (m) {
  5531. return Transformable.getLocalTransform(this, m);
  5532. };
  5533. Transformable.prototype.setPosition = function (arr) {
  5534. this.x = arr[0];
  5535. this.y = arr[1];
  5536. };
  5537. Transformable.prototype.setScale = function (arr) {
  5538. this.scaleX = arr[0];
  5539. this.scaleY = arr[1];
  5540. };
  5541. Transformable.prototype.setSkew = function (arr) {
  5542. this.skewX = arr[0];
  5543. this.skewY = arr[1];
  5544. };
  5545. Transformable.prototype.setOrigin = function (arr) {
  5546. this.originX = arr[0];
  5547. this.originY = arr[1];
  5548. };
  5549. Transformable.prototype.needLocalTransform = function () {
  5550. return isNotAroundZero$1(this.rotation)
  5551. || isNotAroundZero$1(this.x)
  5552. || isNotAroundZero$1(this.y)
  5553. || isNotAroundZero$1(this.scaleX - 1)
  5554. || isNotAroundZero$1(this.scaleY - 1)
  5555. || isNotAroundZero$1(this.skewX)
  5556. || isNotAroundZero$1(this.skewY);
  5557. };
  5558. Transformable.prototype.updateTransform = function () {
  5559. var parentTransform = this.parent && this.parent.transform;
  5560. var needLocalTransform = this.needLocalTransform();
  5561. var m = this.transform;
  5562. if (!(needLocalTransform || parentTransform)) {
  5563. if (m) {
  5564. mIdentity(m);
  5565. this.invTransform = null;
  5566. }
  5567. return;
  5568. }
  5569. m = m || create$1();
  5570. if (needLocalTransform) {
  5571. this.getLocalTransform(m);
  5572. }
  5573. else {
  5574. mIdentity(m);
  5575. }
  5576. if (parentTransform) {
  5577. if (needLocalTransform) {
  5578. mul$1(m, parentTransform, m);
  5579. }
  5580. else {
  5581. copy$1(m, parentTransform);
  5582. }
  5583. }
  5584. this.transform = m;
  5585. this._resolveGlobalScaleRatio(m);
  5586. };
  5587. Transformable.prototype._resolveGlobalScaleRatio = function (m) {
  5588. var globalScaleRatio = this.globalScaleRatio;
  5589. if (globalScaleRatio != null && globalScaleRatio !== 1) {
  5590. this.getGlobalScale(scaleTmp);
  5591. var relX = scaleTmp[0] < 0 ? -1 : 1;
  5592. var relY = scaleTmp[1] < 0 ? -1 : 1;
  5593. var sx = ((scaleTmp[0] - relX) * globalScaleRatio + relX) / scaleTmp[0] || 0;
  5594. var sy = ((scaleTmp[1] - relY) * globalScaleRatio + relY) / scaleTmp[1] || 0;
  5595. m[0] *= sx;
  5596. m[1] *= sx;
  5597. m[2] *= sy;
  5598. m[3] *= sy;
  5599. }
  5600. this.invTransform = this.invTransform || create$1();
  5601. invert(this.invTransform, m);
  5602. };
  5603. Transformable.prototype.getComputedTransform = function () {
  5604. var transformNode = this;
  5605. var ancestors = [];
  5606. while (transformNode) {
  5607. ancestors.push(transformNode);
  5608. transformNode = transformNode.parent;
  5609. }
  5610. while (transformNode = ancestors.pop()) {
  5611. transformNode.updateTransform();
  5612. }
  5613. return this.transform;
  5614. };
  5615. Transformable.prototype.setLocalTransform = function (m) {
  5616. if (!m) {
  5617. return;
  5618. }
  5619. var sx = m[0] * m[0] + m[1] * m[1];
  5620. var sy = m[2] * m[2] + m[3] * m[3];
  5621. var rotation = Math.atan2(m[1], m[0]);
  5622. var shearX = Math.PI / 2 + rotation - Math.atan2(m[3], m[2]);
  5623. sy = Math.sqrt(sy) * Math.cos(shearX);
  5624. sx = Math.sqrt(sx);
  5625. this.skewX = shearX;
  5626. this.skewY = 0;
  5627. this.rotation = -rotation;
  5628. this.x = +m[4];
  5629. this.y = +m[5];
  5630. this.scaleX = sx;
  5631. this.scaleY = sy;
  5632. this.originX = 0;
  5633. this.originY = 0;
  5634. };
  5635. Transformable.prototype.decomposeTransform = function () {
  5636. if (!this.transform) {
  5637. return;
  5638. }
  5639. var parent = this.parent;
  5640. var m = this.transform;
  5641. if (parent && parent.transform) {
  5642. parent.invTransform = parent.invTransform || create$1();
  5643. mul$1(tmpTransform, parent.invTransform, m);
  5644. m = tmpTransform;
  5645. }
  5646. var ox = this.originX;
  5647. var oy = this.originY;
  5648. if (ox || oy) {
  5649. originTransform[4] = ox;
  5650. originTransform[5] = oy;
  5651. mul$1(tmpTransform, m, originTransform);
  5652. tmpTransform[4] -= ox;
  5653. tmpTransform[5] -= oy;
  5654. m = tmpTransform;
  5655. }
  5656. this.setLocalTransform(m);
  5657. };
  5658. Transformable.prototype.getGlobalScale = function (out) {
  5659. var m = this.transform;
  5660. out = out || [];
  5661. if (!m) {
  5662. out[0] = 1;
  5663. out[1] = 1;
  5664. return out;
  5665. }
  5666. out[0] = Math.sqrt(m[0] * m[0] + m[1] * m[1]);
  5667. out[1] = Math.sqrt(m[2] * m[2] + m[3] * m[3]);
  5668. if (m[0] < 0) {
  5669. out[0] = -out[0];
  5670. }
  5671. if (m[3] < 0) {
  5672. out[1] = -out[1];
  5673. }
  5674. return out;
  5675. };
  5676. Transformable.prototype.transformCoordToLocal = function (x, y) {
  5677. var v2 = [x, y];
  5678. var invTransform = this.invTransform;
  5679. if (invTransform) {
  5680. applyTransform(v2, v2, invTransform);
  5681. }
  5682. return v2;
  5683. };
  5684. Transformable.prototype.transformCoordToGlobal = function (x, y) {
  5685. var v2 = [x, y];
  5686. var transform = this.transform;
  5687. if (transform) {
  5688. applyTransform(v2, v2, transform);
  5689. }
  5690. return v2;
  5691. };
  5692. Transformable.prototype.getLineScale = function () {
  5693. var m = this.transform;
  5694. return m && abs(m[0] - 1) > 1e-10 && abs(m[3] - 1) > 1e-10
  5695. ? Math.sqrt(abs(m[0] * m[3] - m[2] * m[1]))
  5696. : 1;
  5697. };
  5698. Transformable.prototype.copyTransform = function (source) {
  5699. copyTransform(this, source);
  5700. };
  5701. Transformable.getLocalTransform = function (target, m) {
  5702. m = m || [];
  5703. var ox = target.originX || 0;
  5704. var oy = target.originY || 0;
  5705. var sx = target.scaleX;
  5706. var sy = target.scaleY;
  5707. var ax = target.anchorX;
  5708. var ay = target.anchorY;
  5709. var rotation = target.rotation || 0;
  5710. var x = target.x;
  5711. var y = target.y;
  5712. var skewX = target.skewX ? Math.tan(target.skewX) : 0;
  5713. var skewY = target.skewY ? Math.tan(-target.skewY) : 0;
  5714. if (ox || oy || ax || ay) {
  5715. var dx = ox + ax;
  5716. var dy = oy + ay;
  5717. m[4] = -dx * sx - skewX * dy * sy;
  5718. m[5] = -dy * sy - skewY * dx * sx;
  5719. }
  5720. else {
  5721. m[4] = m[5] = 0;
  5722. }
  5723. m[0] = sx;
  5724. m[3] = sy;
  5725. m[1] = skewY * sx;
  5726. m[2] = skewX * sy;
  5727. rotation && rotate(m, m, rotation);
  5728. m[4] += ox + x;
  5729. m[5] += oy + y;
  5730. return m;
  5731. };
  5732. Transformable.initDefaultProps = (function () {
  5733. var proto = Transformable.prototype;
  5734. proto.scaleX =
  5735. proto.scaleY =
  5736. proto.globalScaleRatio = 1;
  5737. proto.x =
  5738. proto.y =
  5739. proto.originX =
  5740. proto.originY =
  5741. proto.skewX =
  5742. proto.skewY =
  5743. proto.rotation =
  5744. proto.anchorX =
  5745. proto.anchorY = 0;
  5746. })();
  5747. return Transformable;
  5748. }());
  5749. var TRANSFORMABLE_PROPS = [
  5750. 'x', 'y', 'originX', 'originY', 'anchorX', 'anchorY', 'rotation', 'scaleX', 'scaleY', 'skewX', 'skewY'
  5751. ];
  5752. function copyTransform(target, source) {
  5753. for (var i = 0; i < TRANSFORMABLE_PROPS.length; i++) {
  5754. var propName = TRANSFORMABLE_PROPS[i];
  5755. target[propName] = source[propName];
  5756. }
  5757. }
  5758. function ensureFontMeasureInfo(font) {
  5759. if (!_fontMeasureInfoCache) {
  5760. _fontMeasureInfoCache = new LRU(100);
  5761. }
  5762. font = font || DEFAULT_FONT;
  5763. var measureInfo = _fontMeasureInfoCache.get(font);
  5764. if (!measureInfo) {
  5765. measureInfo = {
  5766. font: font,
  5767. strWidthCache: new LRU(500),
  5768. asciiWidthMap: null,
  5769. asciiWidthMapTried: false,
  5770. stWideCharWidth: platformApi.measureText('国', font).width,
  5771. asciiCharWidth: platformApi.measureText('a', font).width
  5772. };
  5773. _fontMeasureInfoCache.put(font, measureInfo);
  5774. }
  5775. return measureInfo;
  5776. }
  5777. var _fontMeasureInfoCache;
  5778. function tryCreateASCIIWidthMap(font) {
  5779. if (_getASCIIWidthMapLongCount >= GET_ASCII_WIDTH_LONG_COUNT_MAX) {
  5780. return;
  5781. }
  5782. font = font || DEFAULT_FONT;
  5783. var asciiWidthMap = [];
  5784. var start = +(new Date());
  5785. for (var code = 0; code <= 127; code++) {
  5786. asciiWidthMap[code] = platformApi.measureText(String.fromCharCode(code), font).width;
  5787. }
  5788. var cost = +(new Date()) - start;
  5789. if (cost > 16) {
  5790. _getASCIIWidthMapLongCount = GET_ASCII_WIDTH_LONG_COUNT_MAX;
  5791. }
  5792. else if (cost > 2) {
  5793. _getASCIIWidthMapLongCount++;
  5794. }
  5795. return asciiWidthMap;
  5796. }
  5797. var _getASCIIWidthMapLongCount = 0;
  5798. var GET_ASCII_WIDTH_LONG_COUNT_MAX = 5;
  5799. function measureCharWidth(fontMeasureInfo, charCode) {
  5800. if (!fontMeasureInfo.asciiWidthMapTried) {
  5801. fontMeasureInfo.asciiWidthMap = tryCreateASCIIWidthMap(fontMeasureInfo.font);
  5802. fontMeasureInfo.asciiWidthMapTried = true;
  5803. }
  5804. return (0 <= charCode && charCode <= 127)
  5805. ? (fontMeasureInfo.asciiWidthMap != null
  5806. ? fontMeasureInfo.asciiWidthMap[charCode]
  5807. : fontMeasureInfo.asciiCharWidth)
  5808. : fontMeasureInfo.stWideCharWidth;
  5809. }
  5810. function measureWidth(fontMeasureInfo, text) {
  5811. var strWidthCache = fontMeasureInfo.strWidthCache;
  5812. var width = strWidthCache.get(text);
  5813. if (width == null) {
  5814. width = platformApi.measureText(text, fontMeasureInfo.font).width;
  5815. strWidthCache.put(text, width);
  5816. }
  5817. return width;
  5818. }
  5819. function innerGetBoundingRect(text, font, textAlign, textBaseline) {
  5820. var width = measureWidth(ensureFontMeasureInfo(font), text);
  5821. var height = getLineHeight(font);
  5822. var x = adjustTextX(0, width, textAlign);
  5823. var y = adjustTextY$1(0, height, textBaseline);
  5824. var rect = new BoundingRect(x, y, width, height);
  5825. return rect;
  5826. }
  5827. function getBoundingRect(text, font, textAlign, textBaseline) {
  5828. var textLines = ((text || '') + '').split('\n');
  5829. var len = textLines.length;
  5830. if (len === 1) {
  5831. return innerGetBoundingRect(textLines[0], font, textAlign, textBaseline);
  5832. }
  5833. else {
  5834. var uniondRect = new BoundingRect(0, 0, 0, 0);
  5835. for (var i = 0; i < textLines.length; i++) {
  5836. var rect = innerGetBoundingRect(textLines[i], font, textAlign, textBaseline);
  5837. i === 0 ? uniondRect.copy(rect) : uniondRect.union(rect);
  5838. }
  5839. return uniondRect;
  5840. }
  5841. }
  5842. function adjustTextX(x, width, textAlign, inverse) {
  5843. if (textAlign === 'right') {
  5844. !inverse ? (x -= width) : (x += width);
  5845. }
  5846. else if (textAlign === 'center') {
  5847. !inverse ? (x -= width / 2) : (x += width / 2);
  5848. }
  5849. return x;
  5850. }
  5851. function adjustTextY$1(y, height, verticalAlign, inverse) {
  5852. if (verticalAlign === 'middle') {
  5853. !inverse ? (y -= height / 2) : (y += height / 2);
  5854. }
  5855. else if (verticalAlign === 'bottom') {
  5856. !inverse ? (y -= height) : (y += height);
  5857. }
  5858. return y;
  5859. }
  5860. function getLineHeight(font) {
  5861. return ensureFontMeasureInfo(font).stWideCharWidth;
  5862. }
  5863. function parsePercent(value, maxValue) {
  5864. if (typeof value === 'string') {
  5865. if (value.lastIndexOf('%') >= 0) {
  5866. return parseFloat(value) / 100 * maxValue;
  5867. }
  5868. return parseFloat(value);
  5869. }
  5870. return value;
  5871. }
  5872. function calculateTextPosition(out, opts, rect) {
  5873. var textPosition = opts.position || 'inside';
  5874. var distance = opts.distance != null ? opts.distance : 5;
  5875. var height = rect.height;
  5876. var width = rect.width;
  5877. var halfHeight = height / 2;
  5878. var x = rect.x;
  5879. var y = rect.y;
  5880. var textAlign = 'left';
  5881. var textVerticalAlign = 'top';
  5882. if (textPosition instanceof Array) {
  5883. x += parsePercent(textPosition[0], rect.width);
  5884. y += parsePercent(textPosition[1], rect.height);
  5885. textAlign = null;
  5886. textVerticalAlign = null;
  5887. }
  5888. else {
  5889. switch (textPosition) {
  5890. case 'left':
  5891. x -= distance;
  5892. y += halfHeight;
  5893. textAlign = 'right';
  5894. textVerticalAlign = 'middle';
  5895. break;
  5896. case 'right':
  5897. x += distance + width;
  5898. y += halfHeight;
  5899. textVerticalAlign = 'middle';
  5900. break;
  5901. case 'top':
  5902. x += width / 2;
  5903. y -= distance;
  5904. textAlign = 'center';
  5905. textVerticalAlign = 'bottom';
  5906. break;
  5907. case 'bottom':
  5908. x += width / 2;
  5909. y += height + distance;
  5910. textAlign = 'center';
  5911. break;
  5912. case 'inside':
  5913. x += width / 2;
  5914. y += halfHeight;
  5915. textAlign = 'center';
  5916. textVerticalAlign = 'middle';
  5917. break;
  5918. case 'insideLeft':
  5919. x += distance;
  5920. y += halfHeight;
  5921. textVerticalAlign = 'middle';
  5922. break;
  5923. case 'insideRight':
  5924. x += width - distance;
  5925. y += halfHeight;
  5926. textAlign = 'right';
  5927. textVerticalAlign = 'middle';
  5928. break;
  5929. case 'insideTop':
  5930. x += width / 2;
  5931. y += distance;
  5932. textAlign = 'center';
  5933. break;
  5934. case 'insideBottom':
  5935. x += width / 2;
  5936. y += height - distance;
  5937. textAlign = 'center';
  5938. textVerticalAlign = 'bottom';
  5939. break;
  5940. case 'insideTopLeft':
  5941. x += distance;
  5942. y += distance;
  5943. break;
  5944. case 'insideTopRight':
  5945. x += width - distance;
  5946. y += distance;
  5947. textAlign = 'right';
  5948. break;
  5949. case 'insideBottomLeft':
  5950. x += distance;
  5951. y += height - distance;
  5952. textVerticalAlign = 'bottom';
  5953. break;
  5954. case 'insideBottomRight':
  5955. x += width - distance;
  5956. y += height - distance;
  5957. textAlign = 'right';
  5958. textVerticalAlign = 'bottom';
  5959. break;
  5960. }
  5961. }
  5962. out = out || {};
  5963. out.x = x;
  5964. out.y = y;
  5965. out.align = textAlign;
  5966. out.verticalAlign = textVerticalAlign;
  5967. return out;
  5968. }
  5969. var PRESERVED_NORMAL_STATE = '__zr_normal__';
  5970. var PRIMARY_STATES_KEYS = TRANSFORMABLE_PROPS.concat(['ignore']);
  5971. var DEFAULT_ANIMATABLE_MAP = reduce(TRANSFORMABLE_PROPS, function (obj, key) {
  5972. obj[key] = true;
  5973. return obj;
  5974. }, { ignore: false });
  5975. var tmpTextPosCalcRes = {};
  5976. var tmpBoundingRect = new BoundingRect(0, 0, 0, 0);
  5977. var tmpInnerTextTrans = [];
  5978. var Element = (function () {
  5979. function Element(props) {
  5980. this.id = guid();
  5981. this.animators = [];
  5982. this.currentStates = [];
  5983. this.states = {};
  5984. this._init(props);
  5985. }
  5986. Element.prototype._init = function (props) {
  5987. this.attr(props);
  5988. };
  5989. Element.prototype.drift = function (dx, dy, e) {
  5990. switch (this.draggable) {
  5991. case 'horizontal':
  5992. dy = 0;
  5993. break;
  5994. case 'vertical':
  5995. dx = 0;
  5996. break;
  5997. }
  5998. var m = this.transform;
  5999. if (!m) {
  6000. m = this.transform = [1, 0, 0, 1, 0, 0];
  6001. }
  6002. m[4] += dx;
  6003. m[5] += dy;
  6004. this.decomposeTransform();
  6005. this.markRedraw();
  6006. };
  6007. Element.prototype.beforeUpdate = function () { };
  6008. Element.prototype.afterUpdate = function () { };
  6009. Element.prototype.update = function () {
  6010. this.updateTransform();
  6011. if (this.__dirty) {
  6012. this.updateInnerText();
  6013. }
  6014. };
  6015. Element.prototype.updateInnerText = function (forceUpdate) {
  6016. var textEl = this._textContent;
  6017. if (textEl && (!textEl.ignore || forceUpdate)) {
  6018. if (!this.textConfig) {
  6019. this.textConfig = {};
  6020. }
  6021. var textConfig = this.textConfig;
  6022. var isLocal = textConfig.local;
  6023. var innerTransformable = textEl.innerTransformable;
  6024. var textAlign = void 0;
  6025. var textVerticalAlign = void 0;
  6026. var textStyleChanged = false;
  6027. innerTransformable.parent = isLocal ? this : null;
  6028. var innerOrigin = false;
  6029. innerTransformable.copyTransform(textEl);
  6030. var hasPosition = textConfig.position != null;
  6031. var autoOverflowArea = textConfig.autoOverflowArea;
  6032. var layoutRect = void 0;
  6033. if (autoOverflowArea || hasPosition) {
  6034. layoutRect = tmpBoundingRect;
  6035. if (textConfig.layoutRect) {
  6036. layoutRect.copy(textConfig.layoutRect);
  6037. }
  6038. else {
  6039. layoutRect.copy(this.getBoundingRect());
  6040. }
  6041. if (!isLocal) {
  6042. layoutRect.applyTransform(this.transform);
  6043. }
  6044. }
  6045. if (hasPosition) {
  6046. if (this.calculateTextPosition) {
  6047. this.calculateTextPosition(tmpTextPosCalcRes, textConfig, layoutRect);
  6048. }
  6049. else {
  6050. calculateTextPosition(tmpTextPosCalcRes, textConfig, layoutRect);
  6051. }
  6052. innerTransformable.x = tmpTextPosCalcRes.x;
  6053. innerTransformable.y = tmpTextPosCalcRes.y;
  6054. textAlign = tmpTextPosCalcRes.align;
  6055. textVerticalAlign = tmpTextPosCalcRes.verticalAlign;
  6056. var textOrigin = textConfig.origin;
  6057. if (textOrigin && textConfig.rotation != null) {
  6058. var relOriginX = void 0;
  6059. var relOriginY = void 0;
  6060. if (textOrigin === 'center') {
  6061. relOriginX = layoutRect.width * 0.5;
  6062. relOriginY = layoutRect.height * 0.5;
  6063. }
  6064. else {
  6065. relOriginX = parsePercent(textOrigin[0], layoutRect.width);
  6066. relOriginY = parsePercent(textOrigin[1], layoutRect.height);
  6067. }
  6068. innerOrigin = true;
  6069. innerTransformable.originX = -innerTransformable.x + relOriginX + (isLocal ? 0 : layoutRect.x);
  6070. innerTransformable.originY = -innerTransformable.y + relOriginY + (isLocal ? 0 : layoutRect.y);
  6071. }
  6072. }
  6073. if (textConfig.rotation != null) {
  6074. innerTransformable.rotation = textConfig.rotation;
  6075. }
  6076. var textOffset = textConfig.offset;
  6077. if (textOffset) {
  6078. innerTransformable.x += textOffset[0];
  6079. innerTransformable.y += textOffset[1];
  6080. if (!innerOrigin) {
  6081. innerTransformable.originX = -textOffset[0];
  6082. innerTransformable.originY = -textOffset[1];
  6083. }
  6084. }
  6085. var innerTextDefaultStyle = this._innerTextDefaultStyle || (this._innerTextDefaultStyle = {});
  6086. if (autoOverflowArea) {
  6087. var overflowRect = innerTextDefaultStyle.overflowRect =
  6088. innerTextDefaultStyle.overflowRect || new BoundingRect(0, 0, 0, 0);
  6089. innerTransformable.getLocalTransform(tmpInnerTextTrans);
  6090. invert(tmpInnerTextTrans, tmpInnerTextTrans);
  6091. BoundingRect.copy(overflowRect, layoutRect);
  6092. overflowRect.applyTransform(tmpInnerTextTrans);
  6093. }
  6094. else {
  6095. innerTextDefaultStyle.overflowRect = null;
  6096. }
  6097. var isInside = textConfig.inside == null
  6098. ? (typeof textConfig.position === 'string' && textConfig.position.indexOf('inside') >= 0)
  6099. : textConfig.inside;
  6100. var textFill = void 0;
  6101. var textStroke = void 0;
  6102. var autoStroke = void 0;
  6103. if (isInside && this.canBeInsideText()) {
  6104. textFill = textConfig.insideFill;
  6105. textStroke = textConfig.insideStroke;
  6106. if (textFill == null || textFill === 'auto') {
  6107. textFill = this.getInsideTextFill();
  6108. }
  6109. if (textStroke == null || textStroke === 'auto') {
  6110. textStroke = this.getInsideTextStroke(textFill);
  6111. autoStroke = true;
  6112. }
  6113. }
  6114. else {
  6115. textFill = textConfig.outsideFill;
  6116. textStroke = textConfig.outsideStroke;
  6117. if (textFill == null || textFill === 'auto') {
  6118. textFill = this.getOutsideFill();
  6119. }
  6120. if (textStroke == null || textStroke === 'auto') {
  6121. textStroke = this.getOutsideStroke(textFill);
  6122. autoStroke = true;
  6123. }
  6124. }
  6125. textFill = textFill || '#000';
  6126. if (textFill !== innerTextDefaultStyle.fill
  6127. || textStroke !== innerTextDefaultStyle.stroke
  6128. || autoStroke !== innerTextDefaultStyle.autoStroke
  6129. || textAlign !== innerTextDefaultStyle.align
  6130. || textVerticalAlign !== innerTextDefaultStyle.verticalAlign) {
  6131. textStyleChanged = true;
  6132. innerTextDefaultStyle.fill = textFill;
  6133. innerTextDefaultStyle.stroke = textStroke;
  6134. innerTextDefaultStyle.autoStroke = autoStroke;
  6135. innerTextDefaultStyle.align = textAlign;
  6136. innerTextDefaultStyle.verticalAlign = textVerticalAlign;
  6137. textEl.setDefaultTextStyle(innerTextDefaultStyle);
  6138. }
  6139. textEl.__dirty |= REDRAW_BIT;
  6140. if (textStyleChanged) {
  6141. textEl.dirtyStyle(true);
  6142. }
  6143. }
  6144. };
  6145. Element.prototype.canBeInsideText = function () {
  6146. return true;
  6147. };
  6148. Element.prototype.getInsideTextFill = function () {
  6149. return '#fff';
  6150. };
  6151. Element.prototype.getInsideTextStroke = function (textFill) {
  6152. return '#000';
  6153. };
  6154. Element.prototype.getOutsideFill = function () {
  6155. return this.__zr && this.__zr.isDarkMode() ? LIGHT_LABEL_COLOR : DARK_LABEL_COLOR;
  6156. };
  6157. Element.prototype.getOutsideStroke = function (textFill) {
  6158. var backgroundColor = this.__zr && this.__zr.getBackgroundColor();
  6159. var colorArr = typeof backgroundColor === 'string' && parse(backgroundColor);
  6160. if (!colorArr) {
  6161. colorArr = [255, 255, 255, 1];
  6162. }
  6163. var alpha = colorArr[3];
  6164. var isDark = this.__zr.isDarkMode();
  6165. for (var i = 0; i < 3; i++) {
  6166. colorArr[i] = colorArr[i] * alpha + (isDark ? 0 : 255) * (1 - alpha);
  6167. }
  6168. colorArr[3] = 1;
  6169. return stringify(colorArr, 'rgba');
  6170. };
  6171. Element.prototype.traverse = function (cb, context) { };
  6172. Element.prototype.attrKV = function (key, value) {
  6173. if (key === 'textConfig') {
  6174. this.setTextConfig(value);
  6175. }
  6176. else if (key === 'textContent') {
  6177. this.setTextContent(value);
  6178. }
  6179. else if (key === 'clipPath') {
  6180. this.setClipPath(value);
  6181. }
  6182. else if (key === 'extra') {
  6183. this.extra = this.extra || {};
  6184. extend(this.extra, value);
  6185. }
  6186. else {
  6187. this[key] = value;
  6188. }
  6189. };
  6190. Element.prototype.hide = function () {
  6191. this.ignore = true;
  6192. this.markRedraw();
  6193. };
  6194. Element.prototype.show = function () {
  6195. this.ignore = false;
  6196. this.markRedraw();
  6197. };
  6198. Element.prototype.attr = function (keyOrObj, value) {
  6199. if (typeof keyOrObj === 'string') {
  6200. this.attrKV(keyOrObj, value);
  6201. }
  6202. else if (isObject(keyOrObj)) {
  6203. var obj = keyOrObj;
  6204. var keysArr = keys(obj);
  6205. for (var i = 0; i < keysArr.length; i++) {
  6206. var key = keysArr[i];
  6207. this.attrKV(key, keyOrObj[key]);
  6208. }
  6209. }
  6210. this.markRedraw();
  6211. return this;
  6212. };
  6213. Element.prototype.saveCurrentToNormalState = function (toState) {
  6214. this._innerSaveToNormal(toState);
  6215. var normalState = this._normalState;
  6216. for (var i = 0; i < this.animators.length; i++) {
  6217. var animator = this.animators[i];
  6218. var fromStateTransition = animator.__fromStateTransition;
  6219. if (animator.getLoop() || fromStateTransition && fromStateTransition !== PRESERVED_NORMAL_STATE) {
  6220. continue;
  6221. }
  6222. var targetName = animator.targetName;
  6223. var target = targetName
  6224. ? normalState[targetName] : normalState;
  6225. animator.saveTo(target);
  6226. }
  6227. };
  6228. Element.prototype._innerSaveToNormal = function (toState) {
  6229. var normalState = this._normalState;
  6230. if (!normalState) {
  6231. normalState = this._normalState = {};
  6232. }
  6233. if (toState.textConfig && !normalState.textConfig) {
  6234. normalState.textConfig = this.textConfig;
  6235. }
  6236. this._savePrimaryToNormal(toState, normalState, PRIMARY_STATES_KEYS);
  6237. };
  6238. Element.prototype._savePrimaryToNormal = function (toState, normalState, primaryKeys) {
  6239. for (var i = 0; i < primaryKeys.length; i++) {
  6240. var key = primaryKeys[i];
  6241. if (toState[key] != null && !(key in normalState)) {
  6242. normalState[key] = this[key];
  6243. }
  6244. }
  6245. };
  6246. Element.prototype.hasState = function () {
  6247. return this.currentStates.length > 0;
  6248. };
  6249. Element.prototype.getState = function (name) {
  6250. return this.states[name];
  6251. };
  6252. Element.prototype.ensureState = function (name) {
  6253. var states = this.states;
  6254. if (!states[name]) {
  6255. states[name] = {};
  6256. }
  6257. return states[name];
  6258. };
  6259. Element.prototype.clearStates = function (noAnimation) {
  6260. this.useState(PRESERVED_NORMAL_STATE, false, noAnimation);
  6261. };
  6262. Element.prototype.useState = function (stateName, keepCurrentStates, noAnimation, forceUseHoverLayer) {
  6263. var toNormalState = stateName === PRESERVED_NORMAL_STATE;
  6264. var hasStates = this.hasState();
  6265. if (!hasStates && toNormalState) {
  6266. return;
  6267. }
  6268. var currentStates = this.currentStates;
  6269. var animationCfg = this.stateTransition;
  6270. if (indexOf(currentStates, stateName) >= 0 && (keepCurrentStates || currentStates.length === 1)) {
  6271. return;
  6272. }
  6273. var state;
  6274. if (this.stateProxy && !toNormalState) {
  6275. state = this.stateProxy(stateName);
  6276. }
  6277. if (!state) {
  6278. state = (this.states && this.states[stateName]);
  6279. }
  6280. if (!state && !toNormalState) {
  6281. logError("State " + stateName + " not exists.");
  6282. return;
  6283. }
  6284. if (!toNormalState) {
  6285. this.saveCurrentToNormalState(state);
  6286. }
  6287. var useHoverLayer = !!((state && state.hoverLayer) || forceUseHoverLayer);
  6288. if (useHoverLayer) {
  6289. this._toggleHoverLayerFlag(true);
  6290. }
  6291. this._applyStateObj(stateName, state, this._normalState, keepCurrentStates, !noAnimation && !this.__inHover && animationCfg && animationCfg.duration > 0, animationCfg);
  6292. var textContent = this._textContent;
  6293. var textGuide = this._textGuide;
  6294. if (textContent) {
  6295. textContent.useState(stateName, keepCurrentStates, noAnimation, useHoverLayer);
  6296. }
  6297. if (textGuide) {
  6298. textGuide.useState(stateName, keepCurrentStates, noAnimation, useHoverLayer);
  6299. }
  6300. if (toNormalState) {
  6301. this.currentStates = [];
  6302. this._normalState = {};
  6303. }
  6304. else {
  6305. if (!keepCurrentStates) {
  6306. this.currentStates = [stateName];
  6307. }
  6308. else {
  6309. this.currentStates.push(stateName);
  6310. }
  6311. }
  6312. this._updateAnimationTargets();
  6313. this.markRedraw();
  6314. if (!useHoverLayer && this.__inHover) {
  6315. this._toggleHoverLayerFlag(false);
  6316. this.__dirty &= ~REDRAW_BIT;
  6317. }
  6318. return state;
  6319. };
  6320. Element.prototype.useStates = function (states, noAnimation, forceUseHoverLayer) {
  6321. if (!states.length) {
  6322. this.clearStates();
  6323. }
  6324. else {
  6325. var stateObjects = [];
  6326. var currentStates = this.currentStates;
  6327. var len = states.length;
  6328. var notChange = len === currentStates.length;
  6329. if (notChange) {
  6330. for (var i = 0; i < len; i++) {
  6331. if (states[i] !== currentStates[i]) {
  6332. notChange = false;
  6333. break;
  6334. }
  6335. }
  6336. }
  6337. if (notChange) {
  6338. return;
  6339. }
  6340. for (var i = 0; i < len; i++) {
  6341. var stateName = states[i];
  6342. var stateObj = void 0;
  6343. if (this.stateProxy) {
  6344. stateObj = this.stateProxy(stateName, states);
  6345. }
  6346. if (!stateObj) {
  6347. stateObj = this.states[stateName];
  6348. }
  6349. if (stateObj) {
  6350. stateObjects.push(stateObj);
  6351. }
  6352. }
  6353. var lastStateObj = stateObjects[len - 1];
  6354. var useHoverLayer = !!((lastStateObj && lastStateObj.hoverLayer) || forceUseHoverLayer);
  6355. if (useHoverLayer) {
  6356. this._toggleHoverLayerFlag(true);
  6357. }
  6358. var mergedState = this._mergeStates(stateObjects);
  6359. var animationCfg = this.stateTransition;
  6360. this.saveCurrentToNormalState(mergedState);
  6361. this._applyStateObj(states.join(','), mergedState, this._normalState, false, !noAnimation && !this.__inHover && animationCfg && animationCfg.duration > 0, animationCfg);
  6362. var textContent = this._textContent;
  6363. var textGuide = this._textGuide;
  6364. if (textContent) {
  6365. textContent.useStates(states, noAnimation, useHoverLayer);
  6366. }
  6367. if (textGuide) {
  6368. textGuide.useStates(states, noAnimation, useHoverLayer);
  6369. }
  6370. this._updateAnimationTargets();
  6371. this.currentStates = states.slice();
  6372. this.markRedraw();
  6373. if (!useHoverLayer && this.__inHover) {
  6374. this._toggleHoverLayerFlag(false);
  6375. this.__dirty &= ~REDRAW_BIT;
  6376. }
  6377. }
  6378. };
  6379. Element.prototype.isSilent = function () {
  6380. var el = this;
  6381. while (el) {
  6382. if (el.silent) {
  6383. return true;
  6384. }
  6385. var hostEl = el.__hostTarget;
  6386. el = hostEl ? (el.ignoreHostSilent ? null : hostEl) : el.parent;
  6387. }
  6388. return false;
  6389. };
  6390. Element.prototype._updateAnimationTargets = function () {
  6391. for (var i = 0; i < this.animators.length; i++) {
  6392. var animator = this.animators[i];
  6393. if (animator.targetName) {
  6394. animator.changeTarget(this[animator.targetName]);
  6395. }
  6396. }
  6397. };
  6398. Element.prototype.removeState = function (state) {
  6399. var idx = indexOf(this.currentStates, state);
  6400. if (idx >= 0) {
  6401. var currentStates = this.currentStates.slice();
  6402. currentStates.splice(idx, 1);
  6403. this.useStates(currentStates);
  6404. }
  6405. };
  6406. Element.prototype.replaceState = function (oldState, newState, forceAdd) {
  6407. var currentStates = this.currentStates.slice();
  6408. var idx = indexOf(currentStates, oldState);
  6409. var newStateExists = indexOf(currentStates, newState) >= 0;
  6410. if (idx >= 0) {
  6411. if (!newStateExists) {
  6412. currentStates[idx] = newState;
  6413. }
  6414. else {
  6415. currentStates.splice(idx, 1);
  6416. }
  6417. }
  6418. else if (forceAdd && !newStateExists) {
  6419. currentStates.push(newState);
  6420. }
  6421. this.useStates(currentStates);
  6422. };
  6423. Element.prototype.toggleState = function (state, enable) {
  6424. if (enable) {
  6425. this.useState(state, true);
  6426. }
  6427. else {
  6428. this.removeState(state);
  6429. }
  6430. };
  6431. Element.prototype._mergeStates = function (states) {
  6432. var mergedState = {};
  6433. var mergedTextConfig;
  6434. for (var i = 0; i < states.length; i++) {
  6435. var state = states[i];
  6436. extend(mergedState, state);
  6437. if (state.textConfig) {
  6438. mergedTextConfig = mergedTextConfig || {};
  6439. extend(mergedTextConfig, state.textConfig);
  6440. }
  6441. }
  6442. if (mergedTextConfig) {
  6443. mergedState.textConfig = mergedTextConfig;
  6444. }
  6445. return mergedState;
  6446. };
  6447. Element.prototype._applyStateObj = function (stateName, state, normalState, keepCurrentStates, transition, animationCfg) {
  6448. var needsRestoreToNormal = !(state && keepCurrentStates);
  6449. if (state && state.textConfig) {
  6450. this.textConfig = extend({}, keepCurrentStates ? this.textConfig : normalState.textConfig);
  6451. extend(this.textConfig, state.textConfig);
  6452. }
  6453. else if (needsRestoreToNormal) {
  6454. if (normalState.textConfig) {
  6455. this.textConfig = normalState.textConfig;
  6456. }
  6457. }
  6458. var transitionTarget = {};
  6459. var hasTransition = false;
  6460. for (var i = 0; i < PRIMARY_STATES_KEYS.length; i++) {
  6461. var key = PRIMARY_STATES_KEYS[i];
  6462. var propNeedsTransition = transition && DEFAULT_ANIMATABLE_MAP[key];
  6463. if (state && state[key] != null) {
  6464. if (propNeedsTransition) {
  6465. hasTransition = true;
  6466. transitionTarget[key] = state[key];
  6467. }
  6468. else {
  6469. this[key] = state[key];
  6470. }
  6471. }
  6472. else if (needsRestoreToNormal) {
  6473. if (normalState[key] != null) {
  6474. if (propNeedsTransition) {
  6475. hasTransition = true;
  6476. transitionTarget[key] = normalState[key];
  6477. }
  6478. else {
  6479. this[key] = normalState[key];
  6480. }
  6481. }
  6482. }
  6483. }
  6484. if (!transition) {
  6485. for (var i = 0; i < this.animators.length; i++) {
  6486. var animator = this.animators[i];
  6487. var targetName = animator.targetName;
  6488. if (!animator.getLoop()) {
  6489. animator.__changeFinalValue(targetName
  6490. ? (state || normalState)[targetName]
  6491. : (state || normalState));
  6492. }
  6493. }
  6494. }
  6495. if (hasTransition) {
  6496. this._transitionState(stateName, transitionTarget, animationCfg);
  6497. }
  6498. };
  6499. Element.prototype._attachComponent = function (componentEl) {
  6500. if (componentEl.__zr && !componentEl.__hostTarget) {
  6501. if ("development" !== 'production') {
  6502. throw new Error('Text element has been added to zrender.');
  6503. }
  6504. return;
  6505. }
  6506. if (componentEl === this) {
  6507. if ("development" !== 'production') {
  6508. throw new Error('Recursive component attachment.');
  6509. }
  6510. return;
  6511. }
  6512. var zr = this.__zr;
  6513. if (zr) {
  6514. componentEl.addSelfToZr(zr);
  6515. }
  6516. componentEl.__zr = zr;
  6517. componentEl.__hostTarget = this;
  6518. };
  6519. Element.prototype._detachComponent = function (componentEl) {
  6520. if (componentEl.__zr) {
  6521. componentEl.removeSelfFromZr(componentEl.__zr);
  6522. }
  6523. componentEl.__zr = null;
  6524. componentEl.__hostTarget = null;
  6525. };
  6526. Element.prototype.getClipPath = function () {
  6527. return this._clipPath;
  6528. };
  6529. Element.prototype.setClipPath = function (clipPath) {
  6530. if (this._clipPath && this._clipPath !== clipPath) {
  6531. this.removeClipPath();
  6532. }
  6533. this._attachComponent(clipPath);
  6534. this._clipPath = clipPath;
  6535. this.markRedraw();
  6536. };
  6537. Element.prototype.removeClipPath = function () {
  6538. var clipPath = this._clipPath;
  6539. if (clipPath) {
  6540. this._detachComponent(clipPath);
  6541. this._clipPath = null;
  6542. this.markRedraw();
  6543. }
  6544. };
  6545. Element.prototype.getTextContent = function () {
  6546. return this._textContent;
  6547. };
  6548. Element.prototype.setTextContent = function (textEl) {
  6549. var previousTextContent = this._textContent;
  6550. if (previousTextContent === textEl) {
  6551. return;
  6552. }
  6553. if (previousTextContent && previousTextContent !== textEl) {
  6554. this.removeTextContent();
  6555. }
  6556. if ("development" !== 'production') {
  6557. if (textEl.__zr && !textEl.__hostTarget) {
  6558. throw new Error('Text element has been added to zrender.');
  6559. }
  6560. }
  6561. textEl.innerTransformable = new Transformable();
  6562. this._attachComponent(textEl);
  6563. this._textContent = textEl;
  6564. this.markRedraw();
  6565. };
  6566. Element.prototype.setTextConfig = function (cfg) {
  6567. if (!this.textConfig) {
  6568. this.textConfig = {};
  6569. }
  6570. extend(this.textConfig, cfg);
  6571. this.markRedraw();
  6572. };
  6573. Element.prototype.removeTextConfig = function () {
  6574. this.textConfig = null;
  6575. this.markRedraw();
  6576. };
  6577. Element.prototype.removeTextContent = function () {
  6578. var textEl = this._textContent;
  6579. if (textEl) {
  6580. textEl.innerTransformable = null;
  6581. this._detachComponent(textEl);
  6582. this._textContent = null;
  6583. this._innerTextDefaultStyle = null;
  6584. this.markRedraw();
  6585. }
  6586. };
  6587. Element.prototype.getTextGuideLine = function () {
  6588. return this._textGuide;
  6589. };
  6590. Element.prototype.setTextGuideLine = function (guideLine) {
  6591. if (this._textGuide && this._textGuide !== guideLine) {
  6592. this.removeTextGuideLine();
  6593. }
  6594. this._attachComponent(guideLine);
  6595. this._textGuide = guideLine;
  6596. this.markRedraw();
  6597. };
  6598. Element.prototype.removeTextGuideLine = function () {
  6599. var textGuide = this._textGuide;
  6600. if (textGuide) {
  6601. this._detachComponent(textGuide);
  6602. this._textGuide = null;
  6603. this.markRedraw();
  6604. }
  6605. };
  6606. Element.prototype.markRedraw = function () {
  6607. this.__dirty |= REDRAW_BIT;
  6608. var zr = this.__zr;
  6609. if (zr) {
  6610. if (this.__inHover) {
  6611. zr.refreshHover();
  6612. }
  6613. else {
  6614. zr.refresh();
  6615. }
  6616. }
  6617. if (this.__hostTarget) {
  6618. this.__hostTarget.markRedraw();
  6619. }
  6620. };
  6621. Element.prototype.dirty = function () {
  6622. this.markRedraw();
  6623. };
  6624. Element.prototype._toggleHoverLayerFlag = function (inHover) {
  6625. this.__inHover = inHover;
  6626. var textContent = this._textContent;
  6627. var textGuide = this._textGuide;
  6628. if (textContent) {
  6629. textContent.__inHover = inHover;
  6630. }
  6631. if (textGuide) {
  6632. textGuide.__inHover = inHover;
  6633. }
  6634. };
  6635. Element.prototype.addSelfToZr = function (zr) {
  6636. if (this.__zr === zr) {
  6637. return;
  6638. }
  6639. this.__zr = zr;
  6640. var animators = this.animators;
  6641. if (animators) {
  6642. for (var i = 0; i < animators.length; i++) {
  6643. zr.animation.addAnimator(animators[i]);
  6644. }
  6645. }
  6646. if (this._clipPath) {
  6647. this._clipPath.addSelfToZr(zr);
  6648. }
  6649. if (this._textContent) {
  6650. this._textContent.addSelfToZr(zr);
  6651. }
  6652. if (this._textGuide) {
  6653. this._textGuide.addSelfToZr(zr);
  6654. }
  6655. };
  6656. Element.prototype.removeSelfFromZr = function (zr) {
  6657. if (!this.__zr) {
  6658. return;
  6659. }
  6660. this.__zr = null;
  6661. var animators = this.animators;
  6662. if (animators) {
  6663. for (var i = 0; i < animators.length; i++) {
  6664. zr.animation.removeAnimator(animators[i]);
  6665. }
  6666. }
  6667. if (this._clipPath) {
  6668. this._clipPath.removeSelfFromZr(zr);
  6669. }
  6670. if (this._textContent) {
  6671. this._textContent.removeSelfFromZr(zr);
  6672. }
  6673. if (this._textGuide) {
  6674. this._textGuide.removeSelfFromZr(zr);
  6675. }
  6676. };
  6677. Element.prototype.animate = function (key, loop, allowDiscreteAnimation) {
  6678. var target = key ? this[key] : this;
  6679. if ("development" !== 'production') {
  6680. if (!target) {
  6681. logError('Property "'
  6682. + key
  6683. + '" is not existed in element '
  6684. + this.id);
  6685. return;
  6686. }
  6687. }
  6688. var animator = new Animator(target, loop, allowDiscreteAnimation);
  6689. key && (animator.targetName = key);
  6690. this.addAnimator(animator, key);
  6691. return animator;
  6692. };
  6693. Element.prototype.addAnimator = function (animator, key) {
  6694. var zr = this.__zr;
  6695. var el = this;
  6696. animator.during(function () {
  6697. el.updateDuringAnimation(key);
  6698. }).done(function () {
  6699. var animators = el.animators;
  6700. var idx = indexOf(animators, animator);
  6701. if (idx >= 0) {
  6702. animators.splice(idx, 1);
  6703. }
  6704. });
  6705. this.animators.push(animator);
  6706. if (zr) {
  6707. zr.animation.addAnimator(animator);
  6708. }
  6709. zr && zr.wakeUp();
  6710. };
  6711. Element.prototype.updateDuringAnimation = function (key) {
  6712. this.markRedraw();
  6713. };
  6714. Element.prototype.stopAnimation = function (scope, forwardToLast) {
  6715. var animators = this.animators;
  6716. var len = animators.length;
  6717. var leftAnimators = [];
  6718. for (var i = 0; i < len; i++) {
  6719. var animator = animators[i];
  6720. if (!scope || scope === animator.scope) {
  6721. animator.stop(forwardToLast);
  6722. }
  6723. else {
  6724. leftAnimators.push(animator);
  6725. }
  6726. }
  6727. this.animators = leftAnimators;
  6728. return this;
  6729. };
  6730. Element.prototype.animateTo = function (target, cfg, animationProps) {
  6731. animateTo(this, target, cfg, animationProps);
  6732. };
  6733. Element.prototype.animateFrom = function (target, cfg, animationProps) {
  6734. animateTo(this, target, cfg, animationProps, true);
  6735. };
  6736. Element.prototype._transitionState = function (stateName, target, cfg, animationProps) {
  6737. var animators = animateTo(this, target, cfg, animationProps);
  6738. for (var i = 0; i < animators.length; i++) {
  6739. animators[i].__fromStateTransition = stateName;
  6740. }
  6741. };
  6742. Element.prototype.getBoundingRect = function () {
  6743. return null;
  6744. };
  6745. Element.prototype.getPaintRect = function () {
  6746. return null;
  6747. };
  6748. Element.initDefaultProps = (function () {
  6749. var elProto = Element.prototype;
  6750. elProto.type = 'element';
  6751. elProto.name = '';
  6752. elProto.ignore =
  6753. elProto.silent =
  6754. elProto.ignoreHostSilent =
  6755. elProto.isGroup =
  6756. elProto.draggable =
  6757. elProto.dragging =
  6758. elProto.ignoreClip =
  6759. elProto.__inHover = false;
  6760. elProto.__dirty = REDRAW_BIT;
  6761. var logs = {};
  6762. function logDeprecatedError(key, xKey, yKey) {
  6763. if (!logs[key + xKey + yKey]) {
  6764. console.warn("DEPRECATED: '" + key + "' has been deprecated. use '" + xKey + "', '" + yKey + "' instead");
  6765. logs[key + xKey + yKey] = true;
  6766. }
  6767. }
  6768. function createLegacyProperty(key, privateKey, xKey, yKey) {
  6769. Object.defineProperty(elProto, key, {
  6770. get: function () {
  6771. if ("development" !== 'production') {
  6772. logDeprecatedError(key, xKey, yKey);
  6773. }
  6774. if (!this[privateKey]) {
  6775. var pos = this[privateKey] = [];
  6776. enhanceArray(this, pos);
  6777. }
  6778. return this[privateKey];
  6779. },
  6780. set: function (pos) {
  6781. if ("development" !== 'production') {
  6782. logDeprecatedError(key, xKey, yKey);
  6783. }
  6784. this[xKey] = pos[0];
  6785. this[yKey] = pos[1];
  6786. this[privateKey] = pos;
  6787. enhanceArray(this, pos);
  6788. }
  6789. });
  6790. function enhanceArray(self, pos) {
  6791. Object.defineProperty(pos, 0, {
  6792. get: function () {
  6793. return self[xKey];
  6794. },
  6795. set: function (val) {
  6796. self[xKey] = val;
  6797. }
  6798. });
  6799. Object.defineProperty(pos, 1, {
  6800. get: function () {
  6801. return self[yKey];
  6802. },
  6803. set: function (val) {
  6804. self[yKey] = val;
  6805. }
  6806. });
  6807. }
  6808. }
  6809. if (Object.defineProperty) {
  6810. createLegacyProperty('position', '_legacyPos', 'x', 'y');
  6811. createLegacyProperty('scale', '_legacyScale', 'scaleX', 'scaleY');
  6812. createLegacyProperty('origin', '_legacyOrigin', 'originX', 'originY');
  6813. }
  6814. })();
  6815. return Element;
  6816. }());
  6817. mixin(Element, Eventful);
  6818. mixin(Element, Transformable);
  6819. function animateTo(animatable, target, cfg, animationProps, reverse) {
  6820. cfg = cfg || {};
  6821. var animators = [];
  6822. animateToShallow(animatable, '', animatable, target, cfg, animationProps, animators, reverse);
  6823. var finishCount = animators.length;
  6824. var doneHappened = false;
  6825. var cfgDone = cfg.done;
  6826. var cfgAborted = cfg.aborted;
  6827. var doneCb = function () {
  6828. doneHappened = true;
  6829. finishCount--;
  6830. if (finishCount <= 0) {
  6831. doneHappened
  6832. ? (cfgDone && cfgDone())
  6833. : (cfgAborted && cfgAborted());
  6834. }
  6835. };
  6836. var abortedCb = function () {
  6837. finishCount--;
  6838. if (finishCount <= 0) {
  6839. doneHappened
  6840. ? (cfgDone && cfgDone())
  6841. : (cfgAborted && cfgAborted());
  6842. }
  6843. };
  6844. if (!finishCount) {
  6845. cfgDone && cfgDone();
  6846. }
  6847. if (animators.length > 0 && cfg.during) {
  6848. animators[0].during(function (target, percent) {
  6849. cfg.during(percent);
  6850. });
  6851. }
  6852. for (var i = 0; i < animators.length; i++) {
  6853. var animator = animators[i];
  6854. if (doneCb) {
  6855. animator.done(doneCb);
  6856. }
  6857. if (abortedCb) {
  6858. animator.aborted(abortedCb);
  6859. }
  6860. if (cfg.force) {
  6861. animator.duration(cfg.duration);
  6862. }
  6863. animator.start(cfg.easing);
  6864. }
  6865. return animators;
  6866. }
  6867. function copyArrShallow(source, target, len) {
  6868. for (var i = 0; i < len; i++) {
  6869. source[i] = target[i];
  6870. }
  6871. }
  6872. function is2DArray(value) {
  6873. return isArrayLike(value[0]);
  6874. }
  6875. function copyValue(target, source, key) {
  6876. if (isArrayLike(source[key])) {
  6877. if (!isArrayLike(target[key])) {
  6878. target[key] = [];
  6879. }
  6880. if (isTypedArray(source[key])) {
  6881. var len = source[key].length;
  6882. if (target[key].length !== len) {
  6883. target[key] = new (source[key].constructor)(len);
  6884. copyArrShallow(target[key], source[key], len);
  6885. }
  6886. }
  6887. else {
  6888. var sourceArr = source[key];
  6889. var targetArr = target[key];
  6890. var len0 = sourceArr.length;
  6891. if (is2DArray(sourceArr)) {
  6892. var len1 = sourceArr[0].length;
  6893. for (var i = 0; i < len0; i++) {
  6894. if (!targetArr[i]) {
  6895. targetArr[i] = Array.prototype.slice.call(sourceArr[i]);
  6896. }
  6897. else {
  6898. copyArrShallow(targetArr[i], sourceArr[i], len1);
  6899. }
  6900. }
  6901. }
  6902. else {
  6903. copyArrShallow(targetArr, sourceArr, len0);
  6904. }
  6905. targetArr.length = sourceArr.length;
  6906. }
  6907. }
  6908. else {
  6909. target[key] = source[key];
  6910. }
  6911. }
  6912. function isValueSame(val1, val2) {
  6913. return val1 === val2
  6914. || isArrayLike(val1) && isArrayLike(val2) && is1DArraySame(val1, val2);
  6915. }
  6916. function is1DArraySame(arr0, arr1) {
  6917. var len = arr0.length;
  6918. if (len !== arr1.length) {
  6919. return false;
  6920. }
  6921. for (var i = 0; i < len; i++) {
  6922. if (arr0[i] !== arr1[i]) {
  6923. return false;
  6924. }
  6925. }
  6926. return true;
  6927. }
  6928. function animateToShallow(animatable, topKey, animateObj, target, cfg, animationProps, animators, reverse) {
  6929. var targetKeys = keys(target);
  6930. var duration = cfg.duration;
  6931. var delay = cfg.delay;
  6932. var additive = cfg.additive;
  6933. var setToFinal = cfg.setToFinal;
  6934. var animateAll = !isObject(animationProps);
  6935. var existsAnimators = animatable.animators;
  6936. var animationKeys = [];
  6937. for (var k = 0; k < targetKeys.length; k++) {
  6938. var innerKey = targetKeys[k];
  6939. var targetVal = target[innerKey];
  6940. if (targetVal != null && animateObj[innerKey] != null
  6941. && (animateAll || animationProps[innerKey])) {
  6942. if (isObject(targetVal)
  6943. && !isArrayLike(targetVal)
  6944. && !isGradientObject(targetVal)) {
  6945. if (topKey) {
  6946. if (!reverse) {
  6947. animateObj[innerKey] = targetVal;
  6948. animatable.updateDuringAnimation(topKey);
  6949. }
  6950. continue;
  6951. }
  6952. animateToShallow(animatable, innerKey, animateObj[innerKey], targetVal, cfg, animationProps && animationProps[innerKey], animators, reverse);
  6953. }
  6954. else {
  6955. animationKeys.push(innerKey);
  6956. }
  6957. }
  6958. else if (!reverse) {
  6959. animateObj[innerKey] = targetVal;
  6960. animatable.updateDuringAnimation(topKey);
  6961. animationKeys.push(innerKey);
  6962. }
  6963. }
  6964. var keyLen = animationKeys.length;
  6965. if (!additive && keyLen) {
  6966. for (var i = 0; i < existsAnimators.length; i++) {
  6967. var animator = existsAnimators[i];
  6968. if (animator.targetName === topKey) {
  6969. var allAborted = animator.stopTracks(animationKeys);
  6970. if (allAborted) {
  6971. var idx = indexOf(existsAnimators, animator);
  6972. existsAnimators.splice(idx, 1);
  6973. }
  6974. }
  6975. }
  6976. }
  6977. if (!cfg.force) {
  6978. animationKeys = filter(animationKeys, function (key) { return !isValueSame(target[key], animateObj[key]); });
  6979. keyLen = animationKeys.length;
  6980. }
  6981. if (keyLen > 0
  6982. || (cfg.force && !animators.length)) {
  6983. var revertedSource = void 0;
  6984. var reversedTarget = void 0;
  6985. var sourceClone = void 0;
  6986. if (reverse) {
  6987. reversedTarget = {};
  6988. if (setToFinal) {
  6989. revertedSource = {};
  6990. }
  6991. for (var i = 0; i < keyLen; i++) {
  6992. var innerKey = animationKeys[i];
  6993. reversedTarget[innerKey] = animateObj[innerKey];
  6994. if (setToFinal) {
  6995. revertedSource[innerKey] = target[innerKey];
  6996. }
  6997. else {
  6998. animateObj[innerKey] = target[innerKey];
  6999. }
  7000. }
  7001. }
  7002. else if (setToFinal) {
  7003. sourceClone = {};
  7004. for (var i = 0; i < keyLen; i++) {
  7005. var innerKey = animationKeys[i];
  7006. sourceClone[innerKey] = cloneValue(animateObj[innerKey]);
  7007. copyValue(animateObj, target, innerKey);
  7008. }
  7009. }
  7010. var animator = new Animator(animateObj, false, false, additive ? filter(existsAnimators, function (animator) { return animator.targetName === topKey; }) : null);
  7011. animator.targetName = topKey;
  7012. if (cfg.scope) {
  7013. animator.scope = cfg.scope;
  7014. }
  7015. if (setToFinal && revertedSource) {
  7016. animator.whenWithKeys(0, revertedSource, animationKeys);
  7017. }
  7018. if (sourceClone) {
  7019. animator.whenWithKeys(0, sourceClone, animationKeys);
  7020. }
  7021. animator.whenWithKeys(duration == null ? 500 : duration, reverse ? reversedTarget : target, animationKeys).delay(delay || 0);
  7022. animatable.addAnimator(animator, topKey);
  7023. animators.push(animator);
  7024. }
  7025. }
  7026. var Group = (function (_super) {
  7027. __extends(Group, _super);
  7028. function Group(opts) {
  7029. var _this = _super.call(this) || this;
  7030. _this.isGroup = true;
  7031. _this._children = [];
  7032. _this.attr(opts);
  7033. return _this;
  7034. }
  7035. Group.prototype.childrenRef = function () {
  7036. return this._children;
  7037. };
  7038. Group.prototype.children = function () {
  7039. return this._children.slice();
  7040. };
  7041. Group.prototype.childAt = function (idx) {
  7042. return this._children[idx];
  7043. };
  7044. Group.prototype.childOfName = function (name) {
  7045. var children = this._children;
  7046. for (var i = 0; i < children.length; i++) {
  7047. if (children[i].name === name) {
  7048. return children[i];
  7049. }
  7050. }
  7051. };
  7052. Group.prototype.childCount = function () {
  7053. return this._children.length;
  7054. };
  7055. Group.prototype.add = function (child) {
  7056. if (child) {
  7057. if (child !== this && child.parent !== this) {
  7058. this._children.push(child);
  7059. this._doAdd(child);
  7060. }
  7061. if ("development" !== 'production') {
  7062. if (child.__hostTarget) {
  7063. throw 'This elemenet has been used as an attachment';
  7064. }
  7065. }
  7066. }
  7067. return this;
  7068. };
  7069. Group.prototype.addBefore = function (child, nextSibling) {
  7070. if (child && child !== this && child.parent !== this
  7071. && nextSibling && nextSibling.parent === this) {
  7072. var children = this._children;
  7073. var idx = children.indexOf(nextSibling);
  7074. if (idx >= 0) {
  7075. children.splice(idx, 0, child);
  7076. this._doAdd(child);
  7077. }
  7078. }
  7079. return this;
  7080. };
  7081. Group.prototype.replace = function (oldChild, newChild) {
  7082. var idx = indexOf(this._children, oldChild);
  7083. if (idx >= 0) {
  7084. this.replaceAt(newChild, idx);
  7085. }
  7086. return this;
  7087. };
  7088. Group.prototype.replaceAt = function (child, index) {
  7089. var children = this._children;
  7090. var old = children[index];
  7091. if (child && child !== this && child.parent !== this && child !== old) {
  7092. children[index] = child;
  7093. old.parent = null;
  7094. var zr = this.__zr;
  7095. if (zr) {
  7096. old.removeSelfFromZr(zr);
  7097. }
  7098. this._doAdd(child);
  7099. }
  7100. return this;
  7101. };
  7102. Group.prototype._doAdd = function (child) {
  7103. if (child.parent) {
  7104. child.parent.remove(child);
  7105. }
  7106. child.parent = this;
  7107. var zr = this.__zr;
  7108. if (zr && zr !== child.__zr) {
  7109. child.addSelfToZr(zr);
  7110. }
  7111. zr && zr.refresh();
  7112. };
  7113. Group.prototype.remove = function (child) {
  7114. var zr = this.__zr;
  7115. var children = this._children;
  7116. var idx = indexOf(children, child);
  7117. if (idx < 0) {
  7118. return this;
  7119. }
  7120. children.splice(idx, 1);
  7121. child.parent = null;
  7122. if (zr) {
  7123. child.removeSelfFromZr(zr);
  7124. }
  7125. zr && zr.refresh();
  7126. return this;
  7127. };
  7128. Group.prototype.removeAll = function () {
  7129. var children = this._children;
  7130. var zr = this.__zr;
  7131. for (var i = 0; i < children.length; i++) {
  7132. var child = children[i];
  7133. if (zr) {
  7134. child.removeSelfFromZr(zr);
  7135. }
  7136. child.parent = null;
  7137. }
  7138. children.length = 0;
  7139. return this;
  7140. };
  7141. Group.prototype.eachChild = function (cb, context) {
  7142. var children = this._children;
  7143. for (var i = 0; i < children.length; i++) {
  7144. var child = children[i];
  7145. cb.call(context, child, i);
  7146. }
  7147. return this;
  7148. };
  7149. Group.prototype.traverse = function (cb, context) {
  7150. for (var i = 0; i < this._children.length; i++) {
  7151. var child = this._children[i];
  7152. var stopped = cb.call(context, child);
  7153. if (child.isGroup && !stopped) {
  7154. child.traverse(cb, context);
  7155. }
  7156. }
  7157. return this;
  7158. };
  7159. Group.prototype.addSelfToZr = function (zr) {
  7160. _super.prototype.addSelfToZr.call(this, zr);
  7161. for (var i = 0; i < this._children.length; i++) {
  7162. var child = this._children[i];
  7163. child.addSelfToZr(zr);
  7164. }
  7165. };
  7166. Group.prototype.removeSelfFromZr = function (zr) {
  7167. _super.prototype.removeSelfFromZr.call(this, zr);
  7168. for (var i = 0; i < this._children.length; i++) {
  7169. var child = this._children[i];
  7170. child.removeSelfFromZr(zr);
  7171. }
  7172. };
  7173. Group.prototype.getBoundingRect = function (includeChildren) {
  7174. var tmpRect = new BoundingRect(0, 0, 0, 0);
  7175. var children = includeChildren || this._children;
  7176. var tmpMat = [];
  7177. var rect = null;
  7178. for (var i = 0; i < children.length; i++) {
  7179. var child = children[i];
  7180. if (child.ignore || child.invisible) {
  7181. continue;
  7182. }
  7183. var childRect = child.getBoundingRect();
  7184. var transform = child.getLocalTransform(tmpMat);
  7185. if (transform) {
  7186. BoundingRect.applyTransform(tmpRect, childRect, transform);
  7187. rect = rect || tmpRect.clone();
  7188. rect.union(tmpRect);
  7189. }
  7190. else {
  7191. rect = rect || childRect.clone();
  7192. rect.union(childRect);
  7193. }
  7194. }
  7195. return rect || tmpRect;
  7196. };
  7197. return Group;
  7198. }(Element));
  7199. Group.prototype.type = 'group';
  7200. /*!
  7201. * ZRender, a high performance 2d drawing library.
  7202. *
  7203. * Copyright (c) 2013, Baidu Inc.
  7204. * All rights reserved.
  7205. *
  7206. * LICENSE
  7207. * https://github.com/ecomfe/zrender/blob/master/LICENSE.txt
  7208. */
  7209. var painterCtors = {};
  7210. var instances = {};
  7211. function delInstance(id) {
  7212. delete instances[id];
  7213. }
  7214. function isDarkMode(backgroundColor) {
  7215. if (!backgroundColor) {
  7216. return false;
  7217. }
  7218. if (typeof backgroundColor === 'string') {
  7219. return lum(backgroundColor, 1) < DARK_MODE_THRESHOLD;
  7220. }
  7221. else if (backgroundColor.colorStops) {
  7222. var colorStops = backgroundColor.colorStops;
  7223. var totalLum = 0;
  7224. var len = colorStops.length;
  7225. for (var i = 0; i < len; i++) {
  7226. totalLum += lum(colorStops[i].color, 1);
  7227. }
  7228. totalLum /= len;
  7229. return totalLum < DARK_MODE_THRESHOLD;
  7230. }
  7231. return false;
  7232. }
  7233. var ZRender = (function () {
  7234. function ZRender(id, dom, opts) {
  7235. var _this = this;
  7236. this._sleepAfterStill = 10;
  7237. this._stillFrameAccum = 0;
  7238. this._needsRefresh = true;
  7239. this._needsRefreshHover = true;
  7240. this._darkMode = false;
  7241. opts = opts || {};
  7242. this.dom = dom;
  7243. this.id = id;
  7244. var storage = new Storage();
  7245. var rendererType = opts.renderer || 'canvas';
  7246. if (!painterCtors[rendererType]) {
  7247. rendererType = keys(painterCtors)[0];
  7248. }
  7249. if ("development" !== 'production') {
  7250. if (!painterCtors[rendererType]) {
  7251. throw new Error("Renderer '" + rendererType + "' is not imported. Please import it first.");
  7252. }
  7253. }
  7254. opts.useDirtyRect = opts.useDirtyRect == null
  7255. ? false
  7256. : opts.useDirtyRect;
  7257. var painter = new painterCtors[rendererType](dom, storage, opts, id);
  7258. var ssrMode = opts.ssr || painter.ssrOnly;
  7259. this.storage = storage;
  7260. this.painter = painter;
  7261. var handlerProxy = (!env.node && !env.worker && !ssrMode)
  7262. ? new HandlerDomProxy(painter.getViewportRoot(), painter.root)
  7263. : null;
  7264. var useCoarsePointer = opts.useCoarsePointer;
  7265. var usePointerSize = (useCoarsePointer == null || useCoarsePointer === 'auto')
  7266. ? env.touchEventsSupported
  7267. : !!useCoarsePointer;
  7268. var defaultPointerSize = 44;
  7269. var pointerSize;
  7270. if (usePointerSize) {
  7271. pointerSize = retrieve2(opts.pointerSize, defaultPointerSize);
  7272. }
  7273. this.handler = new Handler(storage, painter, handlerProxy, painter.root, pointerSize);
  7274. this.animation = new Animation({
  7275. stage: {
  7276. update: ssrMode ? null : function () { return _this._flush(true); }
  7277. }
  7278. });
  7279. if (!ssrMode) {
  7280. this.animation.start();
  7281. }
  7282. }
  7283. ZRender.prototype.add = function (el) {
  7284. if (this._disposed || !el) {
  7285. return;
  7286. }
  7287. this.storage.addRoot(el);
  7288. el.addSelfToZr(this);
  7289. this.refresh();
  7290. };
  7291. ZRender.prototype.remove = function (el) {
  7292. if (this._disposed || !el) {
  7293. return;
  7294. }
  7295. this.storage.delRoot(el);
  7296. el.removeSelfFromZr(this);
  7297. this.refresh();
  7298. };
  7299. ZRender.prototype.configLayer = function (zLevel, config) {
  7300. if (this._disposed) {
  7301. return;
  7302. }
  7303. if (this.painter.configLayer) {
  7304. this.painter.configLayer(zLevel, config);
  7305. }
  7306. this.refresh();
  7307. };
  7308. ZRender.prototype.setBackgroundColor = function (backgroundColor) {
  7309. if (this._disposed) {
  7310. return;
  7311. }
  7312. if (this.painter.setBackgroundColor) {
  7313. this.painter.setBackgroundColor(backgroundColor);
  7314. }
  7315. this.refresh();
  7316. this._backgroundColor = backgroundColor;
  7317. this._darkMode = isDarkMode(backgroundColor);
  7318. };
  7319. ZRender.prototype.getBackgroundColor = function () {
  7320. return this._backgroundColor;
  7321. };
  7322. ZRender.prototype.setDarkMode = function (darkMode) {
  7323. this._darkMode = darkMode;
  7324. };
  7325. ZRender.prototype.isDarkMode = function () {
  7326. return this._darkMode;
  7327. };
  7328. ZRender.prototype.refreshImmediately = function (fromInside) {
  7329. if (this._disposed) {
  7330. return;
  7331. }
  7332. if (!fromInside) {
  7333. this.animation.update(true);
  7334. }
  7335. this._needsRefresh = false;
  7336. this.painter.refresh();
  7337. this._needsRefresh = false;
  7338. };
  7339. ZRender.prototype.refresh = function () {
  7340. if (this._disposed) {
  7341. return;
  7342. }
  7343. this._needsRefresh = true;
  7344. this.animation.start();
  7345. };
  7346. ZRender.prototype.flush = function () {
  7347. if (this._disposed) {
  7348. return;
  7349. }
  7350. this._flush(false);
  7351. };
  7352. ZRender.prototype._flush = function (fromInside) {
  7353. var triggerRendered;
  7354. var start = getTime();
  7355. if (this._needsRefresh) {
  7356. triggerRendered = true;
  7357. this.refreshImmediately(fromInside);
  7358. }
  7359. if (this._needsRefreshHover) {
  7360. triggerRendered = true;
  7361. this.refreshHoverImmediately();
  7362. }
  7363. var end = getTime();
  7364. if (triggerRendered) {
  7365. this._stillFrameAccum = 0;
  7366. this.trigger('rendered', {
  7367. elapsedTime: end - start
  7368. });
  7369. }
  7370. else if (this._sleepAfterStill > 0) {
  7371. this._stillFrameAccum++;
  7372. if (this._stillFrameAccum > this._sleepAfterStill) {
  7373. this.animation.stop();
  7374. }
  7375. }
  7376. };
  7377. ZRender.prototype.setSleepAfterStill = function (stillFramesCount) {
  7378. this._sleepAfterStill = stillFramesCount;
  7379. };
  7380. ZRender.prototype.wakeUp = function () {
  7381. if (this._disposed) {
  7382. return;
  7383. }
  7384. this.animation.start();
  7385. this._stillFrameAccum = 0;
  7386. };
  7387. ZRender.prototype.refreshHover = function () {
  7388. this._needsRefreshHover = true;
  7389. };
  7390. ZRender.prototype.refreshHoverImmediately = function () {
  7391. if (this._disposed) {
  7392. return;
  7393. }
  7394. this._needsRefreshHover = false;
  7395. if (this.painter.refreshHover && this.painter.getType() === 'canvas') {
  7396. this.painter.refreshHover();
  7397. }
  7398. };
  7399. ZRender.prototype.resize = function (opts) {
  7400. if (this._disposed) {
  7401. return;
  7402. }
  7403. opts = opts || {};
  7404. this.painter.resize(opts.width, opts.height);
  7405. this.handler.resize();
  7406. };
  7407. ZRender.prototype.clearAnimation = function () {
  7408. if (this._disposed) {
  7409. return;
  7410. }
  7411. this.animation.clear();
  7412. };
  7413. ZRender.prototype.getWidth = function () {
  7414. if (this._disposed) {
  7415. return;
  7416. }
  7417. return this.painter.getWidth();
  7418. };
  7419. ZRender.prototype.getHeight = function () {
  7420. if (this._disposed) {
  7421. return;
  7422. }
  7423. return this.painter.getHeight();
  7424. };
  7425. ZRender.prototype.setCursorStyle = function (cursorStyle) {
  7426. if (this._disposed) {
  7427. return;
  7428. }
  7429. this.handler.setCursorStyle(cursorStyle);
  7430. };
  7431. ZRender.prototype.findHover = function (x, y) {
  7432. if (this._disposed) {
  7433. return;
  7434. }
  7435. return this.handler.findHover(x, y);
  7436. };
  7437. ZRender.prototype.on = function (eventName, eventHandler, context) {
  7438. if (!this._disposed) {
  7439. this.handler.on(eventName, eventHandler, context);
  7440. }
  7441. return this;
  7442. };
  7443. ZRender.prototype.off = function (eventName, eventHandler) {
  7444. if (this._disposed) {
  7445. return;
  7446. }
  7447. this.handler.off(eventName, eventHandler);
  7448. };
  7449. ZRender.prototype.trigger = function (eventName, event) {
  7450. if (this._disposed) {
  7451. return;
  7452. }
  7453. this.handler.trigger(eventName, event);
  7454. };
  7455. ZRender.prototype.clear = function () {
  7456. if (this._disposed) {
  7457. return;
  7458. }
  7459. var roots = this.storage.getRoots();
  7460. for (var i = 0; i < roots.length; i++) {
  7461. if (roots[i] instanceof Group) {
  7462. roots[i].removeSelfFromZr(this);
  7463. }
  7464. }
  7465. this.storage.delAllRoots();
  7466. this.painter.clear();
  7467. };
  7468. ZRender.prototype.dispose = function () {
  7469. if (this._disposed) {
  7470. return;
  7471. }
  7472. this.animation.stop();
  7473. this.clear();
  7474. this.storage.dispose();
  7475. this.painter.dispose();
  7476. this.handler.dispose();
  7477. this.animation =
  7478. this.storage =
  7479. this.painter =
  7480. this.handler = null;
  7481. this._disposed = true;
  7482. delInstance(this.id);
  7483. };
  7484. return ZRender;
  7485. }());
  7486. function init(dom, opts) {
  7487. var zr = new ZRender(guid(), dom, opts);
  7488. instances[zr.id] = zr;
  7489. return zr;
  7490. }
  7491. function dispose(zr) {
  7492. zr.dispose();
  7493. }
  7494. function disposeAll() {
  7495. for (var key in instances) {
  7496. if (instances.hasOwnProperty(key)) {
  7497. instances[key].dispose();
  7498. }
  7499. }
  7500. instances = {};
  7501. }
  7502. function getInstance(id) {
  7503. return instances[id];
  7504. }
  7505. function registerPainter(name, Ctor) {
  7506. painterCtors[name] = Ctor;
  7507. }
  7508. var ssrDataGetter;
  7509. function getElementSSRData(el) {
  7510. if (typeof ssrDataGetter === 'function') {
  7511. return ssrDataGetter(el);
  7512. }
  7513. }
  7514. function registerSSRDataGetter(getter) {
  7515. ssrDataGetter = getter;
  7516. }
  7517. var version = '6.0.0';
  7518. var zrender = /*#__PURE__*/Object.freeze({
  7519. __proto__: null,
  7520. init: init,
  7521. dispose: dispose,
  7522. disposeAll: disposeAll,
  7523. getInstance: getInstance,
  7524. registerPainter: registerPainter,
  7525. getElementSSRData: getElementSSRData,
  7526. registerSSRDataGetter: registerSSRDataGetter,
  7527. version: version
  7528. });
  7529. var RADIAN_EPSILON = 1e-4;
  7530. // Although chrome already enlarge this number to 100 for `toFixed`, but
  7531. // we sill follow the spec for compatibility.
  7532. var ROUND_SUPPORTED_PRECISION_MAX = 20;
  7533. function _trim(str) {
  7534. return str.replace(/^\s+|\s+$/g, '');
  7535. }
  7536. var mathMin$1 = Math.min;
  7537. var mathMax$1 = Math.max;
  7538. var mathAbs$1 = Math.abs;
  7539. /**
  7540. * Linear mapping a value from domain to range
  7541. * @param val
  7542. * @param domain Domain extent domain[0] can be bigger than domain[1]
  7543. * @param range Range extent range[0] can be bigger than range[1]
  7544. * @param clamp Default to be false
  7545. */
  7546. function linearMap(val, domain, range, clamp) {
  7547. var d0 = domain[0];
  7548. var d1 = domain[1];
  7549. var r0 = range[0];
  7550. var r1 = range[1];
  7551. var subDomain = d1 - d0;
  7552. var subRange = r1 - r0;
  7553. if (subDomain === 0) {
  7554. return subRange === 0 ? r0 : (r0 + r1) / 2;
  7555. }
  7556. // Avoid accuracy problem in edge, such as
  7557. // 146.39 - 62.83 === 83.55999999999999.
  7558. // See echarts/test/ut/spec/util/number.js#linearMap#accuracyError
  7559. // It is a little verbose for efficiency considering this method
  7560. // is a hotspot.
  7561. if (clamp) {
  7562. if (subDomain > 0) {
  7563. if (val <= d0) {
  7564. return r0;
  7565. } else if (val >= d1) {
  7566. return r1;
  7567. }
  7568. } else {
  7569. if (val >= d0) {
  7570. return r0;
  7571. } else if (val <= d1) {
  7572. return r1;
  7573. }
  7574. }
  7575. } else {
  7576. if (val === d0) {
  7577. return r0;
  7578. }
  7579. if (val === d1) {
  7580. return r1;
  7581. }
  7582. }
  7583. return (val - d0) / subDomain * subRange + r0;
  7584. }
  7585. /**
  7586. * Preserve the name `parsePercent` for backward compatibility,
  7587. * and it's effectively published as `echarts.number.parsePercent`.
  7588. */
  7589. var parsePercent$1 = parsePositionOption;
  7590. /**
  7591. * @see {parsePositionSizeOption} and also accept a string preset.
  7592. * @see {PositionSizeOption}
  7593. */
  7594. function parsePositionOption(option, percentBase, percentOffset) {
  7595. switch (option) {
  7596. case 'center':
  7597. case 'middle':
  7598. option = '50%';
  7599. break;
  7600. case 'left':
  7601. case 'top':
  7602. option = '0%';
  7603. break;
  7604. case 'right':
  7605. case 'bottom':
  7606. option = '100%';
  7607. break;
  7608. }
  7609. return parsePositionSizeOption(option, percentBase, percentOffset);
  7610. }
  7611. /**
  7612. * Accept number, or numeric stirng (`'123'`), or percentage ('100%'), as x/y/width/height pixel number.
  7613. * If null/undefined or invalid, return NaN.
  7614. * (But allow JS type coercion (`+option`) due to backward compatibility)
  7615. * @see {PositionSizeOption}
  7616. */
  7617. function parsePositionSizeOption(option, percentBase, percentOffset) {
  7618. if (isString(option)) {
  7619. if (_trim(option).match(/%$/)) {
  7620. return parseFloat(option) / 100 * percentBase + (percentOffset || 0);
  7621. }
  7622. return parseFloat(option);
  7623. }
  7624. // Allow flexible input due to backward compatibility.
  7625. return option == null ? NaN : +option;
  7626. }
  7627. function round(x, precision, returnStr) {
  7628. if (precision == null) {
  7629. // FIXME: the default precision should not be provided, since there is no universally adaptable
  7630. // precision. The caller need to input a precision according to the scenarios.
  7631. precision = 10;
  7632. }
  7633. // Avoid range error
  7634. precision = Math.min(Math.max(0, precision), ROUND_SUPPORTED_PRECISION_MAX);
  7635. // PENDING: 1.005.toFixed(2) is '1.00' rather than '1.01'
  7636. x = (+x).toFixed(precision);
  7637. return returnStr ? x : +x;
  7638. }
  7639. /**
  7640. * Inplacd asc sort arr.
  7641. * The input arr will be modified.
  7642. */
  7643. function asc(arr) {
  7644. arr.sort(function (a, b) {
  7645. return a - b;
  7646. });
  7647. return arr;
  7648. }
  7649. /**
  7650. * Get precision.
  7651. */
  7652. function getPrecision(val) {
  7653. val = +val;
  7654. if (isNaN(val)) {
  7655. return 0;
  7656. }
  7657. // It is much faster than methods converting number to string as follows
  7658. // let tmp = val.toString();
  7659. // return tmp.length - 1 - tmp.indexOf('.');
  7660. // especially when precision is low
  7661. // Notice:
  7662. // (1) If the loop count is over about 20, it is slower than `getPrecisionSafe`.
  7663. // (see https://jsbench.me/2vkpcekkvw/1)
  7664. // (2) If the val is less than for example 1e-15, the result may be incorrect.
  7665. // (see test/ut/spec/util/number.test.ts `getPrecision_equal_random`)
  7666. if (val > 1e-14) {
  7667. var e = 1;
  7668. for (var i = 0; i < 15; i++, e *= 10) {
  7669. if (Math.round(val * e) / e === val) {
  7670. return i;
  7671. }
  7672. }
  7673. }
  7674. return getPrecisionSafe(val);
  7675. }
  7676. /**
  7677. * Get precision with slow but safe method
  7678. */
  7679. function getPrecisionSafe(val) {
  7680. // toLowerCase for: '3.4E-12'
  7681. var str = val.toString().toLowerCase();
  7682. // Consider scientific notation: '3.4e-12' '3.4e+12'
  7683. var eIndex = str.indexOf('e');
  7684. var exp = eIndex > 0 ? +str.slice(eIndex + 1) : 0;
  7685. var significandPartLen = eIndex > 0 ? eIndex : str.length;
  7686. var dotIndex = str.indexOf('.');
  7687. var decimalPartLen = dotIndex < 0 ? 0 : significandPartLen - 1 - dotIndex;
  7688. return Math.max(0, decimalPartLen - exp);
  7689. }
  7690. /**
  7691. * Minimal dicernible data precisioin according to a single pixel.
  7692. */
  7693. function getPixelPrecision(dataExtent, pixelExtent) {
  7694. var log = Math.log;
  7695. var LN10 = Math.LN10;
  7696. var dataQuantity = Math.floor(log(dataExtent[1] - dataExtent[0]) / LN10);
  7697. var sizeQuantity = Math.round(log(mathAbs$1(pixelExtent[1] - pixelExtent[0])) / LN10);
  7698. // toFixed() digits argument must be between 0 and 20.
  7699. var precision = Math.min(Math.max(-dataQuantity + sizeQuantity, 0), 20);
  7700. return !isFinite(precision) ? 20 : precision;
  7701. }
  7702. /**
  7703. * Get a data of given precision, assuring the sum of percentages
  7704. * in valueList is 1.
  7705. * The largest remainder method is used.
  7706. * https://en.wikipedia.org/wiki/Largest_remainder_method
  7707. *
  7708. * @param valueList a list of all data
  7709. * @param idx index of the data to be processed in valueList
  7710. * @param precision integer number showing digits of precision
  7711. * @return percent ranging from 0 to 100
  7712. */
  7713. function getPercentWithPrecision(valueList, idx, precision) {
  7714. if (!valueList[idx]) {
  7715. return 0;
  7716. }
  7717. var seats = getPercentSeats(valueList, precision);
  7718. return seats[idx] || 0;
  7719. }
  7720. /**
  7721. * Get a data of given precision, assuring the sum of percentages
  7722. * in valueList is 1.
  7723. * The largest remainder method is used.
  7724. * https://en.wikipedia.org/wiki/Largest_remainder_method
  7725. *
  7726. * @param valueList a list of all data
  7727. * @param precision integer number showing digits of precision
  7728. * @return {Array<number>}
  7729. */
  7730. function getPercentSeats(valueList, precision) {
  7731. var sum = reduce(valueList, function (acc, val) {
  7732. return acc + (isNaN(val) ? 0 : val);
  7733. }, 0);
  7734. if (sum === 0) {
  7735. return [];
  7736. }
  7737. var digits = Math.pow(10, precision);
  7738. var votesPerQuota = map(valueList, function (val) {
  7739. return (isNaN(val) ? 0 : val) / sum * digits * 100;
  7740. });
  7741. var targetSeats = digits * 100;
  7742. var seats = map(votesPerQuota, function (votes) {
  7743. // Assign automatic seats.
  7744. return Math.floor(votes);
  7745. });
  7746. var currentSum = reduce(seats, function (acc, val) {
  7747. return acc + val;
  7748. }, 0);
  7749. var remainder = map(votesPerQuota, function (votes, idx) {
  7750. return votes - seats[idx];
  7751. });
  7752. // Has remainding votes.
  7753. while (currentSum < targetSeats) {
  7754. // Find next largest remainder.
  7755. var max = Number.NEGATIVE_INFINITY;
  7756. var maxId = null;
  7757. for (var i = 0, len = remainder.length; i < len; ++i) {
  7758. if (remainder[i] > max) {
  7759. max = remainder[i];
  7760. maxId = i;
  7761. }
  7762. }
  7763. // Add a vote to max remainder.
  7764. ++seats[maxId];
  7765. remainder[maxId] = 0;
  7766. ++currentSum;
  7767. }
  7768. return map(seats, function (seat) {
  7769. return seat / digits;
  7770. });
  7771. }
  7772. /**
  7773. * Solve the floating point adding problem like 0.1 + 0.2 === 0.30000000000000004
  7774. * See <http://0.30000000000000004.com/>
  7775. */
  7776. function addSafe(val0, val1) {
  7777. var maxPrecision = Math.max(getPrecision(val0), getPrecision(val1));
  7778. // const multiplier = Math.pow(10, maxPrecision);
  7779. // return (Math.round(val0 * multiplier) + Math.round(val1 * multiplier)) / multiplier;
  7780. var sum = val0 + val1;
  7781. // // PENDING: support more?
  7782. return maxPrecision > ROUND_SUPPORTED_PRECISION_MAX ? sum : round(sum, maxPrecision);
  7783. }
  7784. // Number.MAX_SAFE_INTEGER, ie do not support.
  7785. var MAX_SAFE_INTEGER = 9007199254740991;
  7786. /**
  7787. * To 0 - 2 * PI, considering negative radian.
  7788. */
  7789. function remRadian(radian) {
  7790. var pi2 = Math.PI * 2;
  7791. return (radian % pi2 + pi2) % pi2;
  7792. }
  7793. /**
  7794. * @param {type} radian
  7795. * @return {boolean}
  7796. */
  7797. function isRadianAroundZero(val) {
  7798. return val > -RADIAN_EPSILON && val < RADIAN_EPSILON;
  7799. }
  7800. // eslint-disable-next-line
  7801. var TIME_REG = /^(?:(\d{4})(?:[-\/](\d{1,2})(?:[-\/](\d{1,2})(?:[T ](\d{1,2})(?::(\d{1,2})(?::(\d{1,2})(?:[.,](\d+))?)?)?(Z|[\+\-]\d\d:?\d\d)?)?)?)?)?$/; // jshint ignore:line
  7802. /**
  7803. * @param value valid type: number | string | Date, otherwise return `new Date(NaN)`
  7804. * These values can be accepted:
  7805. * + An instance of Date, represent a time in its own time zone.
  7806. * + Or string in a subset of ISO 8601, only including:
  7807. * + only year, month, date: '2012-03', '2012-03-01', '2012-03-01 05', '2012-03-01 05:06',
  7808. * + separated with T or space: '2012-03-01T12:22:33.123', '2012-03-01 12:22:33.123',
  7809. * + time zone: '2012-03-01T12:22:33Z', '2012-03-01T12:22:33+8000', '2012-03-01T12:22:33-05:00',
  7810. * all of which will be treated as local time if time zone is not specified
  7811. * (see <https://momentjs.com/>).
  7812. * + Or other string format, including (all of which will be treated as local time):
  7813. * '2012', '2012-3-1', '2012/3/1', '2012/03/01',
  7814. * '2009/6/12 2:00', '2009/6/12 2:05:08', '2009/6/12 2:05:08.123'
  7815. * + a timestamp, which represent a time in UTC.
  7816. * @return date Never be null/undefined. If invalid, return `new Date(NaN)`.
  7817. */
  7818. function parseDate(value) {
  7819. if (value instanceof Date) {
  7820. return value;
  7821. } else if (isString(value)) {
  7822. // Different browsers parse date in different way, so we parse it manually.
  7823. // Some other issues:
  7824. // new Date('1970-01-01') is UTC,
  7825. // new Date('1970/01/01') and new Date('1970-1-01') is local.
  7826. // See issue #3623
  7827. var match = TIME_REG.exec(value);
  7828. if (!match) {
  7829. // return Invalid Date.
  7830. return new Date(NaN);
  7831. }
  7832. // Use local time when no timezone offset is specified.
  7833. if (!match[8]) {
  7834. // match[n] can only be string or undefined.
  7835. // But take care of '12' + 1 => '121'.
  7836. return new Date(+match[1], +(match[2] || 1) - 1, +match[3] || 1, +match[4] || 0, +(match[5] || 0), +match[6] || 0, match[7] ? +match[7].substring(0, 3) : 0);
  7837. }
  7838. // Timezoneoffset of Javascript Date has considered DST (Daylight Saving Time,
  7839. // https://tc39.github.io/ecma262/#sec-daylight-saving-time-adjustment).
  7840. // For example, system timezone is set as "Time Zone: America/Toronto",
  7841. // then these code will get different result:
  7842. // `new Date(1478411999999).getTimezoneOffset(); // get 240`
  7843. // `new Date(1478412000000).getTimezoneOffset(); // get 300`
  7844. // So we should not use `new Date`, but use `Date.UTC`.
  7845. else {
  7846. var hour = +match[4] || 0;
  7847. if (match[8].toUpperCase() !== 'Z') {
  7848. hour -= +match[8].slice(0, 3);
  7849. }
  7850. return new Date(Date.UTC(+match[1], +(match[2] || 1) - 1, +match[3] || 1, hour, +(match[5] || 0), +match[6] || 0, match[7] ? +match[7].substring(0, 3) : 0));
  7851. }
  7852. } else if (value == null) {
  7853. return new Date(NaN);
  7854. }
  7855. return new Date(Math.round(value));
  7856. }
  7857. /**
  7858. * Quantity of a number. e.g. 0.1, 1, 10, 100
  7859. *
  7860. * @param val
  7861. * @return
  7862. */
  7863. function quantity(val) {
  7864. return Math.pow(10, quantityExponent(val));
  7865. }
  7866. /**
  7867. * Exponent of the quantity of a number
  7868. * e.g., 1234 equals to 1.234*10^3, so quantityExponent(1234) is 3
  7869. *
  7870. * @param val non-negative value
  7871. * @return
  7872. */
  7873. function quantityExponent(val) {
  7874. if (val === 0) {
  7875. return 0;
  7876. }
  7877. var exp = Math.floor(Math.log(val) / Math.LN10);
  7878. /**
  7879. * exp is expected to be the rounded-down result of the base-10 log of val.
  7880. * But due to the precision loss with Math.log(val), we need to restore it
  7881. * using 10^exp to make sure we can get val back from exp. #11249
  7882. */
  7883. if (val / Math.pow(10, exp) >= 10) {
  7884. exp++;
  7885. }
  7886. return exp;
  7887. }
  7888. /**
  7889. * find a “nice” number approximately equal to x. Round the number if round = true,
  7890. * take ceiling if round = false. The primary observation is that the “nicest”
  7891. * numbers in decimal are 1, 2, and 5, and all power-of-ten multiples of these numbers.
  7892. *
  7893. * See "Nice Numbers for Graph Labels" of Graphic Gems.
  7894. *
  7895. * @param val Non-negative value.
  7896. * @param round
  7897. * @return Niced number
  7898. */
  7899. function nice(val, round) {
  7900. var exponent = quantityExponent(val);
  7901. var exp10 = Math.pow(10, exponent);
  7902. var f = val / exp10; // 1 <= f < 10
  7903. var nf;
  7904. if (round) {
  7905. if (f < 1.5) {
  7906. nf = 1;
  7907. } else if (f < 2.5) {
  7908. nf = 2;
  7909. } else if (f < 4) {
  7910. nf = 3;
  7911. } else if (f < 7) {
  7912. nf = 5;
  7913. } else {
  7914. nf = 10;
  7915. }
  7916. } else {
  7917. if (f < 1) {
  7918. nf = 1;
  7919. } else if (f < 2) {
  7920. nf = 2;
  7921. } else if (f < 3) {
  7922. nf = 3;
  7923. } else if (f < 5) {
  7924. nf = 5;
  7925. } else {
  7926. nf = 10;
  7927. }
  7928. }
  7929. val = nf * exp10;
  7930. // Fix 3 * 0.1 === 0.30000000000000004 issue (see IEEE 754).
  7931. // 20 is the uppper bound of toFixed.
  7932. return exponent >= -20 ? +val.toFixed(exponent < 0 ? -exponent : 0) : val;
  7933. }
  7934. /**
  7935. * This code was copied from "d3.js"
  7936. * <https://github.com/d3/d3/blob/9cc9a875e636a1dcf36cc1e07bdf77e1ad6e2c74/src/arrays/quantile.js>.
  7937. * See the license statement at the head of this file.
  7938. * @param ascArr
  7939. */
  7940. function quantile(ascArr, p) {
  7941. var H = (ascArr.length - 1) * p + 1;
  7942. var h = Math.floor(H);
  7943. var v = +ascArr[h - 1];
  7944. var e = H - h;
  7945. return e ? v + e * (ascArr[h] - v) : v;
  7946. }
  7947. /**
  7948. * Order intervals asc, and split them when overlap.
  7949. * expect(numberUtil.reformIntervals([
  7950. * {interval: [18, 62], close: [1, 1]},
  7951. * {interval: [-Infinity, -70], close: [0, 0]},
  7952. * {interval: [-70, -26], close: [1, 1]},
  7953. * {interval: [-26, 18], close: [1, 1]},
  7954. * {interval: [62, 150], close: [1, 1]},
  7955. * {interval: [106, 150], close: [1, 1]},
  7956. * {interval: [150, Infinity], close: [0, 0]}
  7957. * ])).toEqual([
  7958. * {interval: [-Infinity, -70], close: [0, 0]},
  7959. * {interval: [-70, -26], close: [1, 1]},
  7960. * {interval: [-26, 18], close: [0, 1]},
  7961. * {interval: [18, 62], close: [0, 1]},
  7962. * {interval: [62, 150], close: [0, 1]},
  7963. * {interval: [150, Infinity], close: [0, 0]}
  7964. * ]);
  7965. * @param list, where `close` mean open or close
  7966. * of the interval, and Infinity can be used.
  7967. * @return The origin list, which has been reformed.
  7968. */
  7969. function reformIntervals(list) {
  7970. list.sort(function (a, b) {
  7971. return littleThan(a, b, 0) ? -1 : 1;
  7972. });
  7973. var curr = -Infinity;
  7974. var currClose = 1;
  7975. for (var i = 0; i < list.length;) {
  7976. var interval = list[i].interval;
  7977. var close_1 = list[i].close;
  7978. for (var lg = 0; lg < 2; lg++) {
  7979. if (interval[lg] <= curr) {
  7980. interval[lg] = curr;
  7981. close_1[lg] = !lg ? 1 - currClose : 1;
  7982. }
  7983. curr = interval[lg];
  7984. currClose = close_1[lg];
  7985. }
  7986. if (interval[0] === interval[1] && close_1[0] * close_1[1] !== 1) {
  7987. list.splice(i, 1);
  7988. } else {
  7989. i++;
  7990. }
  7991. }
  7992. return list;
  7993. function littleThan(a, b, lg) {
  7994. return a.interval[lg] < b.interval[lg] || a.interval[lg] === b.interval[lg] && (a.close[lg] - b.close[lg] === (!lg ? 1 : -1) || !lg && littleThan(a, b, 1));
  7995. }
  7996. }
  7997. /**
  7998. * [Numeric is defined as]:
  7999. * `parseFloat(val) == val`
  8000. * For example:
  8001. * numeric:
  8002. * typeof number except NaN, '-123', '123', '2e3', '-2e3', '011', 'Infinity', Infinity,
  8003. * and they rounded by white-spaces or line-terminal like ' -123 \n ' (see es spec)
  8004. * not-numeric:
  8005. * null, undefined, [], {}, true, false, 'NaN', NaN, '123ab',
  8006. * empty string, string with only white-spaces or line-terminal (see es spec),
  8007. * 0x12, '0x12', '-0x12', 012, '012', '-012',
  8008. * non-string, ...
  8009. *
  8010. * @test See full test cases in `test/ut/spec/util/number.js`.
  8011. * @return Must be a typeof number. If not numeric, return NaN.
  8012. */
  8013. function numericToNumber(val) {
  8014. var valFloat = parseFloat(val);
  8015. return valFloat == val // eslint-disable-line eqeqeq
  8016. && (valFloat !== 0 || !isString(val) || val.indexOf('x') <= 0) // For case ' 0x0 '.
  8017. ? valFloat : NaN;
  8018. }
  8019. /**
  8020. * Definition of "numeric": see `numericToNumber`.
  8021. */
  8022. function isNumeric(val) {
  8023. return !isNaN(numericToNumber(val));
  8024. }
  8025. /**
  8026. * Use random base to prevent users hard code depending on
  8027. * this auto generated marker id.
  8028. * @return An positive integer.
  8029. */
  8030. function getRandomIdBase() {
  8031. return Math.round(Math.random() * 9);
  8032. }
  8033. /**
  8034. * Get the greatest common divisor.
  8035. *
  8036. * @param {number} a one number
  8037. * @param {number} b the other number
  8038. */
  8039. function getGreatestCommonDividor(a, b) {
  8040. if (b === 0) {
  8041. return a;
  8042. }
  8043. return getGreatestCommonDividor(b, a % b);
  8044. }
  8045. /**
  8046. * Get the least common multiple.
  8047. *
  8048. * @param {number} a one number
  8049. * @param {number} b the other number
  8050. */
  8051. function getLeastCommonMultiple(a, b) {
  8052. if (a == null) {
  8053. return b;
  8054. }
  8055. if (b == null) {
  8056. return a;
  8057. }
  8058. return a * b / getGreatestCommonDividor(a, b);
  8059. }
  8060. var ECHARTS_PREFIX = '[ECharts] ';
  8061. var storedLogs = {};
  8062. var hasConsole = typeof console !== 'undefined'
  8063. // eslint-disable-next-line
  8064. && console.warn && console.log;
  8065. function outputLog(type, str, onlyOnce) {
  8066. if (hasConsole) {
  8067. if (onlyOnce) {
  8068. if (storedLogs[str]) {
  8069. return;
  8070. }
  8071. storedLogs[str] = true;
  8072. }
  8073. // eslint-disable-next-line
  8074. console[type](ECHARTS_PREFIX + str);
  8075. }
  8076. }
  8077. function log(str, onlyOnce) {
  8078. outputLog('log', str, onlyOnce);
  8079. }
  8080. function warn(str, onlyOnce) {
  8081. outputLog('warn', str, onlyOnce);
  8082. }
  8083. function error(str, onlyOnce) {
  8084. outputLog('error', str, onlyOnce);
  8085. }
  8086. function deprecateLog(str) {
  8087. if ("development" !== 'production') {
  8088. // Not display duplicate message.
  8089. outputLog('warn', 'DEPRECATED: ' + str, true);
  8090. }
  8091. }
  8092. function deprecateReplaceLog(oldOpt, newOpt, scope) {
  8093. if ("development" !== 'production') {
  8094. deprecateLog((scope ? "[" + scope + "]" : '') + (oldOpt + " is deprecated; use " + newOpt + " instead."));
  8095. }
  8096. }
  8097. /**
  8098. * If in __DEV__ environment, get console printable message for users hint.
  8099. * Parameters are separated by ' '.
  8100. * @usage
  8101. * makePrintable('This is an error on', someVar, someObj);
  8102. *
  8103. * @param hintInfo anything about the current execution context to hint users.
  8104. * @throws Error
  8105. */
  8106. function makePrintable() {
  8107. var hintInfo = [];
  8108. for (var _i = 0; _i < arguments.length; _i++) {
  8109. hintInfo[_i] = arguments[_i];
  8110. }
  8111. var msg = '';
  8112. if ("development" !== 'production') {
  8113. // Fuzzy stringify for print.
  8114. // This code only exist in dev environment.
  8115. var makePrintableStringIfPossible_1 = function (val) {
  8116. return val === void 0 ? 'undefined' : val === Infinity ? 'Infinity' : val === -Infinity ? '-Infinity' : eqNaN(val) ? 'NaN' : val instanceof Date ? 'Date(' + val.toISOString() + ')' : isFunction(val) ? 'function () { ... }' : isRegExp(val) ? val + '' : null;
  8117. };
  8118. msg = map(hintInfo, function (arg) {
  8119. if (isString(arg)) {
  8120. // Print without quotation mark for some statement.
  8121. return arg;
  8122. } else {
  8123. var printableStr = makePrintableStringIfPossible_1(arg);
  8124. if (printableStr != null) {
  8125. return printableStr;
  8126. } else if (typeof JSON !== 'undefined' && JSON.stringify) {
  8127. try {
  8128. return JSON.stringify(arg, function (n, val) {
  8129. var printableStr = makePrintableStringIfPossible_1(val);
  8130. return printableStr == null ? val : printableStr;
  8131. });
  8132. // In most cases the info object is small, so do not line break.
  8133. } catch (err) {
  8134. return '?';
  8135. }
  8136. } else {
  8137. return '?';
  8138. }
  8139. }
  8140. }).join(' ');
  8141. }
  8142. return msg;
  8143. }
  8144. /**
  8145. * @throws Error
  8146. */
  8147. function throwError(msg) {
  8148. throw new Error(msg);
  8149. }
  8150. function interpolateNumber$1(p0, p1, percent) {
  8151. return (p1 - p0) * percent + p0;
  8152. }
  8153. /**
  8154. * Make the name displayable. But we should
  8155. * make sure it is not duplicated with user
  8156. * specified name, so use '\0';
  8157. */
  8158. var DUMMY_COMPONENT_NAME_PREFIX = 'series\0';
  8159. var INTERNAL_COMPONENT_ID_PREFIX = '\0_ec_\0';
  8160. /**
  8161. * If value is not array, then translate it to array.
  8162. * @param {*} value
  8163. * @return {Array} [value] or value
  8164. */
  8165. function normalizeToArray(value) {
  8166. return value instanceof Array ? value : value == null ? [] : [value];
  8167. }
  8168. /**
  8169. * Sync default option between normal and emphasis like `position` and `show`
  8170. * In case some one will write code like
  8171. * label: {
  8172. * show: false,
  8173. * position: 'outside',
  8174. * fontSize: 18
  8175. * },
  8176. * emphasis: {
  8177. * label: { show: true }
  8178. * }
  8179. */
  8180. function defaultEmphasis(opt, key, subOpts) {
  8181. // Caution: performance sensitive.
  8182. if (opt) {
  8183. opt[key] = opt[key] || {};
  8184. opt.emphasis = opt.emphasis || {};
  8185. opt.emphasis[key] = opt.emphasis[key] || {};
  8186. // Default emphasis option from normal
  8187. for (var i = 0, len = subOpts.length; i < len; i++) {
  8188. var subOptName = subOpts[i];
  8189. if (!opt.emphasis[key].hasOwnProperty(subOptName) && opt[key].hasOwnProperty(subOptName)) {
  8190. opt.emphasis[key][subOptName] = opt[key][subOptName];
  8191. }
  8192. }
  8193. }
  8194. }
  8195. var TEXT_STYLE_OPTIONS = ['fontStyle', 'fontWeight', 'fontSize', 'fontFamily', 'rich', 'tag', 'color', 'textBorderColor', 'textBorderWidth', 'width', 'height', 'lineHeight', 'align', 'verticalAlign', 'baseline', 'shadowColor', 'shadowBlur', 'shadowOffsetX', 'shadowOffsetY', 'textShadowColor', 'textShadowBlur', 'textShadowOffsetX', 'textShadowOffsetY', 'backgroundColor', 'borderColor', 'borderWidth', 'borderRadius', 'padding'];
  8196. // modelUtil.LABEL_OPTIONS = modelUtil.TEXT_STYLE_OPTIONS.concat([
  8197. // 'position', 'offset', 'rotate', 'origin', 'show', 'distance', 'formatter',
  8198. // 'fontStyle', 'fontWeight', 'fontSize', 'fontFamily',
  8199. // // FIXME: deprecated, check and remove it.
  8200. // 'textStyle'
  8201. // ]);
  8202. /**
  8203. * The method does not ensure performance.
  8204. * data could be [12, 2323, {value: 223}, [1221, 23], {value: [2, 23]}]
  8205. * This helper method retrieves value from data.
  8206. */
  8207. function getDataItemValue(dataItem) {
  8208. return isObject(dataItem) && !isArray(dataItem) && !(dataItem instanceof Date) ? dataItem.value : dataItem;
  8209. }
  8210. /**
  8211. * data could be [12, 2323, {value: 223}, [1221, 23], {value: [2, 23]}]
  8212. * This helper method determine if dataItem has extra option besides value
  8213. */
  8214. function isDataItemOption(dataItem) {
  8215. return isObject(dataItem) && !(dataItem instanceof Array);
  8216. // // markLine data can be array
  8217. // && !(dataItem[0] && isObject(dataItem[0]) && !(dataItem[0] instanceof Array));
  8218. }
  8219. /**
  8220. * Mapping to existings for merge.
  8221. *
  8222. * Mode "normalMege":
  8223. * The mapping result (merge result) will keep the order of the existing
  8224. * component, rather than the order of new option. Because we should ensure
  8225. * some specified index reference (like xAxisIndex) keep work.
  8226. * And in most cases, "merge option" is used to update partial option but not
  8227. * be expected to change the order.
  8228. *
  8229. * Mode "replaceMege":
  8230. * (1) Only the id mapped components will be merged.
  8231. * (2) Other existing components (except internal components) will be removed.
  8232. * (3) Other new options will be used to create new component.
  8233. * (4) The index of the existing components will not be modified.
  8234. * That means their might be "hole" after the removal.
  8235. * The new components are created first at those available index.
  8236. *
  8237. * Mode "replaceAll":
  8238. * This mode try to support that reproduce an echarts instance from another
  8239. * echarts instance (via `getOption`) in some simple cases.
  8240. * In this scenario, the `result` index are exactly the consistent with the `newCmptOptions`,
  8241. * which ensures the component index referring (like `xAxisIndex: ?`) corrent. That is,
  8242. * the "hole" in `newCmptOptions` will also be kept.
  8243. * On the contrary, other modes try best to eliminate holes.
  8244. * PENDING: This is an experimental mode yet.
  8245. *
  8246. * @return See the comment of <MappingResult>.
  8247. */
  8248. function mappingToExists(existings, newCmptOptions, mode) {
  8249. var isNormalMergeMode = mode === 'normalMerge';
  8250. var isReplaceMergeMode = mode === 'replaceMerge';
  8251. var isReplaceAllMode = mode === 'replaceAll';
  8252. existings = existings || [];
  8253. newCmptOptions = (newCmptOptions || []).slice();
  8254. var existingIdIdxMap = createHashMap();
  8255. // Validate id and name on user input option.
  8256. each(newCmptOptions, function (cmptOption, index) {
  8257. if (!isObject(cmptOption)) {
  8258. newCmptOptions[index] = null;
  8259. return;
  8260. }
  8261. if ("development" !== 'production') {
  8262. // There is some legacy case that name is set as `false`.
  8263. // But should work normally rather than throw error.
  8264. if (cmptOption.id != null && !isValidIdOrName(cmptOption.id)) {
  8265. warnInvalidateIdOrName(cmptOption.id);
  8266. }
  8267. if (cmptOption.name != null && !isValidIdOrName(cmptOption.name)) {
  8268. warnInvalidateIdOrName(cmptOption.name);
  8269. }
  8270. }
  8271. });
  8272. var result = prepareResult(existings, existingIdIdxMap, mode);
  8273. if (isNormalMergeMode || isReplaceMergeMode) {
  8274. mappingById(result, existings, existingIdIdxMap, newCmptOptions);
  8275. }
  8276. if (isNormalMergeMode) {
  8277. mappingByName(result, newCmptOptions);
  8278. }
  8279. if (isNormalMergeMode || isReplaceMergeMode) {
  8280. mappingByIndex(result, newCmptOptions, isReplaceMergeMode);
  8281. } else if (isReplaceAllMode) {
  8282. mappingInReplaceAllMode(result, newCmptOptions);
  8283. }
  8284. makeIdAndName(result);
  8285. // The array `result` MUST NOT contain elided items, otherwise the
  8286. // forEach will omit those items and result in incorrect result.
  8287. return result;
  8288. }
  8289. function prepareResult(existings, existingIdIdxMap, mode) {
  8290. var result = [];
  8291. if (mode === 'replaceAll') {
  8292. return result;
  8293. }
  8294. // Do not use native `map` to in case that the array `existings`
  8295. // contains elided items, which will be omitted.
  8296. for (var index = 0; index < existings.length; index++) {
  8297. var existing = existings[index];
  8298. // Because of replaceMerge, `existing` may be null/undefined.
  8299. if (existing && existing.id != null) {
  8300. existingIdIdxMap.set(existing.id, index);
  8301. }
  8302. // For non-internal-componnets:
  8303. // Mode "normalMerge": all existings kept.
  8304. // Mode "replaceMerge": all existing removed unless mapped by id.
  8305. // For internal-components:
  8306. // go with "replaceMerge" approach in both mode.
  8307. result.push({
  8308. existing: mode === 'replaceMerge' || isComponentIdInternal(existing) ? null : existing,
  8309. newOption: null,
  8310. keyInfo: null,
  8311. brandNew: null
  8312. });
  8313. }
  8314. return result;
  8315. }
  8316. function mappingById(result, existings, existingIdIdxMap, newCmptOptions) {
  8317. // Mapping by id if specified.
  8318. each(newCmptOptions, function (cmptOption, index) {
  8319. if (!cmptOption || cmptOption.id == null) {
  8320. return;
  8321. }
  8322. var optionId = makeComparableKey(cmptOption.id);
  8323. var existingIdx = existingIdIdxMap.get(optionId);
  8324. if (existingIdx != null) {
  8325. var resultItem = result[existingIdx];
  8326. assert(!resultItem.newOption, 'Duplicated option on id "' + optionId + '".');
  8327. resultItem.newOption = cmptOption;
  8328. // In both mode, if id matched, new option will be merged to
  8329. // the existings rather than creating new component model.
  8330. resultItem.existing = existings[existingIdx];
  8331. newCmptOptions[index] = null;
  8332. }
  8333. });
  8334. }
  8335. function mappingByName(result, newCmptOptions) {
  8336. // Mapping by name if specified.
  8337. each(newCmptOptions, function (cmptOption, index) {
  8338. if (!cmptOption || cmptOption.name == null) {
  8339. return;
  8340. }
  8341. for (var i = 0; i < result.length; i++) {
  8342. var existing = result[i].existing;
  8343. if (!result[i].newOption // Consider name: two map to one.
  8344. // Can not match when both ids existing but different.
  8345. && existing && (existing.id == null || cmptOption.id == null) && !isComponentIdInternal(cmptOption) && !isComponentIdInternal(existing) && keyExistAndEqual('name', existing, cmptOption)) {
  8346. result[i].newOption = cmptOption;
  8347. newCmptOptions[index] = null;
  8348. return;
  8349. }
  8350. }
  8351. });
  8352. }
  8353. function mappingByIndex(result, newCmptOptions, brandNew) {
  8354. each(newCmptOptions, function (cmptOption) {
  8355. if (!cmptOption) {
  8356. return;
  8357. }
  8358. // Find the first place that not mapped by id and not internal component (consider the "hole").
  8359. var resultItem;
  8360. var nextIdx = 0;
  8361. while (
  8362. // Be `!resultItem` only when `nextIdx >= result.length`.
  8363. (resultItem = result[nextIdx]
  8364. // (1) Existing models that already have id should be able to mapped to. Because
  8365. // after mapping performed, model will always be assigned with an id if user not given.
  8366. // After that all models have id.
  8367. // (2) If new option has id, it can only set to a hole or append to the last. It should
  8368. // not be merged to the existings with different id. Because id should not be overwritten.
  8369. // (3) Name can be overwritten, because axis use name as 'show label text'.
  8370. ) && (resultItem.newOption || isComponentIdInternal(resultItem.existing) ||
  8371. // In mode "replaceMerge", here no not-mapped-non-internal-existing.
  8372. resultItem.existing && cmptOption.id != null && !keyExistAndEqual('id', cmptOption, resultItem.existing))) {
  8373. nextIdx++;
  8374. }
  8375. if (resultItem) {
  8376. resultItem.newOption = cmptOption;
  8377. resultItem.brandNew = brandNew;
  8378. } else {
  8379. result.push({
  8380. newOption: cmptOption,
  8381. brandNew: brandNew,
  8382. existing: null,
  8383. keyInfo: null
  8384. });
  8385. }
  8386. nextIdx++;
  8387. });
  8388. }
  8389. function mappingInReplaceAllMode(result, newCmptOptions) {
  8390. each(newCmptOptions, function (cmptOption) {
  8391. // The feature "reproduce" requires "hole" will also reproduced
  8392. // in case that component index referring are broken.
  8393. result.push({
  8394. newOption: cmptOption,
  8395. brandNew: true,
  8396. existing: null,
  8397. keyInfo: null
  8398. });
  8399. });
  8400. }
  8401. /**
  8402. * Make id and name for mapping result (result of mappingToExists)
  8403. * into `keyInfo` field.
  8404. */
  8405. function makeIdAndName(mapResult) {
  8406. // We use this id to hash component models and view instances
  8407. // in echarts. id can be specified by user, or auto generated.
  8408. // The id generation rule ensures new view instance are able
  8409. // to mapped to old instance when setOption are called in
  8410. // no-merge mode. So we generate model id by name and plus
  8411. // type in view id.
  8412. // name can be duplicated among components, which is convenient
  8413. // to specify multi components (like series) by one name.
  8414. // Ensure that each id is distinct.
  8415. var idMap = createHashMap();
  8416. each(mapResult, function (item) {
  8417. var existing = item.existing;
  8418. existing && idMap.set(existing.id, item);
  8419. });
  8420. each(mapResult, function (item) {
  8421. var opt = item.newOption;
  8422. // Force ensure id not duplicated.
  8423. assert(!opt || opt.id == null || !idMap.get(opt.id) || idMap.get(opt.id) === item, 'id duplicates: ' + (opt && opt.id));
  8424. opt && opt.id != null && idMap.set(opt.id, item);
  8425. !item.keyInfo && (item.keyInfo = {});
  8426. });
  8427. // Make name and id.
  8428. each(mapResult, function (item, index) {
  8429. var existing = item.existing;
  8430. var opt = item.newOption;
  8431. var keyInfo = item.keyInfo;
  8432. if (!isObject(opt)) {
  8433. return;
  8434. }
  8435. // Name can be overwritten. Consider case: axis.name = '20km'.
  8436. // But id generated by name will not be changed, which affect
  8437. // only in that case: setOption with 'not merge mode' and view
  8438. // instance will be recreated, which can be accepted.
  8439. keyInfo.name = opt.name != null ? makeComparableKey(opt.name) : existing ? existing.name
  8440. // Avoid that different series has the same name,
  8441. // because name may be used like in color pallet.
  8442. : DUMMY_COMPONENT_NAME_PREFIX + index;
  8443. if (existing) {
  8444. keyInfo.id = makeComparableKey(existing.id);
  8445. } else if (opt.id != null) {
  8446. keyInfo.id = makeComparableKey(opt.id);
  8447. } else {
  8448. // Consider this situatoin:
  8449. // optionA: [{name: 'a'}, {name: 'a'}, {..}]
  8450. // optionB [{..}, {name: 'a'}, {name: 'a'}]
  8451. // Series with the same name between optionA and optionB
  8452. // should be mapped.
  8453. var idNum = 0;
  8454. do {
  8455. keyInfo.id = '\0' + keyInfo.name + '\0' + idNum++;
  8456. } while (idMap.get(keyInfo.id));
  8457. }
  8458. idMap.set(keyInfo.id, item);
  8459. });
  8460. }
  8461. function keyExistAndEqual(attr, obj1, obj2) {
  8462. var key1 = convertOptionIdName(obj1[attr], null);
  8463. var key2 = convertOptionIdName(obj2[attr], null);
  8464. // See `MappingExistingItem`. `id` and `name` trade string equals to number.
  8465. return key1 != null && key2 != null && key1 === key2;
  8466. }
  8467. /**
  8468. * @return return null if not exist.
  8469. */
  8470. function makeComparableKey(val) {
  8471. if ("development" !== 'production') {
  8472. if (val == null) {
  8473. throw new Error();
  8474. }
  8475. }
  8476. return convertOptionIdName(val, '');
  8477. }
  8478. function convertOptionIdName(idOrName, defaultValue) {
  8479. if (idOrName == null) {
  8480. return defaultValue;
  8481. }
  8482. return isString(idOrName) ? idOrName : isNumber(idOrName) || isStringSafe(idOrName) ? idOrName + '' : defaultValue;
  8483. }
  8484. function warnInvalidateIdOrName(idOrName) {
  8485. if ("development" !== 'production') {
  8486. warn('`' + idOrName + '` is invalid id or name. Must be a string or number.');
  8487. }
  8488. }
  8489. function isValidIdOrName(idOrName) {
  8490. return isStringSafe(idOrName) || isNumeric(idOrName);
  8491. }
  8492. function isNameSpecified(componentModel) {
  8493. var name = componentModel.name;
  8494. // Is specified when `indexOf` get -1 or > 0.
  8495. return !!(name && name.indexOf(DUMMY_COMPONENT_NAME_PREFIX));
  8496. }
  8497. /**
  8498. * @public
  8499. * @param {Object} cmptOption
  8500. * @return {boolean}
  8501. */
  8502. function isComponentIdInternal(cmptOption) {
  8503. return cmptOption && cmptOption.id != null && makeComparableKey(cmptOption.id).indexOf(INTERNAL_COMPONENT_ID_PREFIX) === 0;
  8504. }
  8505. function makeInternalComponentId(idSuffix) {
  8506. return INTERNAL_COMPONENT_ID_PREFIX + idSuffix;
  8507. }
  8508. function setComponentTypeToKeyInfo(mappingResult, mainType, componentModelCtor) {
  8509. // Set mainType and complete subType.
  8510. each(mappingResult, function (item) {
  8511. var newOption = item.newOption;
  8512. if (isObject(newOption)) {
  8513. item.keyInfo.mainType = mainType;
  8514. item.keyInfo.subType = determineSubType(mainType, newOption, item.existing, componentModelCtor);
  8515. }
  8516. });
  8517. }
  8518. function determineSubType(mainType, newCmptOption, existComponent, componentModelCtor) {
  8519. var subType = newCmptOption.type ? newCmptOption.type : existComponent ? existComponent.subType
  8520. // Use determineSubType only when there is no existComponent.
  8521. : componentModelCtor.determineSubType(mainType, newCmptOption);
  8522. // tooltip, markline, markpoint may always has no subType
  8523. return subType;
  8524. }
  8525. /**
  8526. * A helper for removing duplicate items between batchA and batchB,
  8527. * and in themselves, and categorize by series.
  8528. *
  8529. * @param batchA Like: [{seriesId: 2, dataIndex: [32, 4, 5]}, ...]
  8530. * @param batchB Like: [{seriesId: 2, dataIndex: [32, 4, 5]}, ...]
  8531. * @return result: [resultBatchA, resultBatchB]
  8532. */
  8533. function compressBatches(batchA, batchB) {
  8534. var mapA = {};
  8535. var mapB = {};
  8536. makeMap(batchA || [], mapA);
  8537. makeMap(batchB || [], mapB, mapA);
  8538. return [mapToArray(mapA), mapToArray(mapB)];
  8539. function makeMap(sourceBatch, map, otherMap) {
  8540. for (var i = 0, len = sourceBatch.length; i < len; i++) {
  8541. var seriesId = convertOptionIdName(sourceBatch[i].seriesId, null);
  8542. if (seriesId == null) {
  8543. return;
  8544. }
  8545. var dataIndices = normalizeToArray(sourceBatch[i].dataIndex);
  8546. var otherDataIndices = otherMap && otherMap[seriesId];
  8547. for (var j = 0, lenj = dataIndices.length; j < lenj; j++) {
  8548. var dataIndex = dataIndices[j];
  8549. if (otherDataIndices && otherDataIndices[dataIndex]) {
  8550. otherDataIndices[dataIndex] = null;
  8551. } else {
  8552. (map[seriesId] || (map[seriesId] = {}))[dataIndex] = 1;
  8553. }
  8554. }
  8555. }
  8556. }
  8557. function mapToArray(map, isData) {
  8558. var result = [];
  8559. for (var i in map) {
  8560. if (map.hasOwnProperty(i) && map[i] != null) {
  8561. if (isData) {
  8562. result.push(+i);
  8563. } else {
  8564. var dataIndices = mapToArray(map[i], true);
  8565. dataIndices.length && result.push({
  8566. seriesId: i,
  8567. dataIndex: dataIndices
  8568. });
  8569. }
  8570. }
  8571. }
  8572. return result;
  8573. }
  8574. }
  8575. /**
  8576. * @param payload Contains dataIndex (means rawIndex) / dataIndexInside / name
  8577. * each of which can be Array or primary type.
  8578. * @return dataIndex If not found, return undefined/null.
  8579. */
  8580. function queryDataIndex(data, payload) {
  8581. if (payload.dataIndexInside != null) {
  8582. return payload.dataIndexInside;
  8583. } else if (payload.dataIndex != null) {
  8584. return isArray(payload.dataIndex) ? map(payload.dataIndex, function (value) {
  8585. return data.indexOfRawIndex(value);
  8586. }) : data.indexOfRawIndex(payload.dataIndex);
  8587. } else if (payload.name != null) {
  8588. return isArray(payload.name) ? map(payload.name, function (value) {
  8589. return data.indexOfName(value);
  8590. }) : data.indexOfName(payload.name);
  8591. }
  8592. }
  8593. /**
  8594. * Enable property storage to any host object.
  8595. * Notice: Serialization is not supported.
  8596. *
  8597. * For example:
  8598. * let inner = zrUitl.makeInner();
  8599. *
  8600. * function some1(hostObj) {
  8601. * inner(hostObj).someProperty = 1212;
  8602. * ...
  8603. * }
  8604. * function some2() {
  8605. * let fields = inner(this);
  8606. * fields.someProperty1 = 1212;
  8607. * fields.someProperty2 = 'xx';
  8608. * ...
  8609. * }
  8610. *
  8611. * @return {Function}
  8612. */
  8613. function makeInner() {
  8614. var key = '__ec_inner_' + innerUniqueIndex++;
  8615. return function (hostObj) {
  8616. return hostObj[key] || (hostObj[key] = {});
  8617. };
  8618. }
  8619. var innerUniqueIndex = getRandomIdBase();
  8620. /**
  8621. * The same behavior as `component.getReferringComponents`.
  8622. */
  8623. function parseFinder(ecModel, finderInput, opt) {
  8624. var _a = preParseFinder(finderInput, opt),
  8625. mainTypeSpecified = _a.mainTypeSpecified,
  8626. queryOptionMap = _a.queryOptionMap,
  8627. others = _a.others;
  8628. var result = others;
  8629. var defaultMainType = opt ? opt.defaultMainType : null;
  8630. if (!mainTypeSpecified && defaultMainType) {
  8631. queryOptionMap.set(defaultMainType, {});
  8632. }
  8633. queryOptionMap.each(function (queryOption, mainType) {
  8634. var queryResult = queryReferringComponents(ecModel, mainType, queryOption, {
  8635. useDefault: defaultMainType === mainType,
  8636. enableAll: opt && opt.enableAll != null ? opt.enableAll : true,
  8637. enableNone: opt && opt.enableNone != null ? opt.enableNone : true
  8638. });
  8639. result[mainType + 'Models'] = queryResult.models;
  8640. result[mainType + 'Model'] = queryResult.models[0];
  8641. });
  8642. return result;
  8643. }
  8644. function preParseFinder(finderInput, opt) {
  8645. var finder;
  8646. if (isString(finderInput)) {
  8647. var obj = {};
  8648. obj[finderInput + 'Index'] = 0;
  8649. finder = obj;
  8650. } else {
  8651. finder = finderInput;
  8652. }
  8653. var queryOptionMap = createHashMap();
  8654. var others = {};
  8655. var mainTypeSpecified = false;
  8656. each(finder, function (value, key) {
  8657. // Exclude 'dataIndex' and other illegal keys.
  8658. if (key === 'dataIndex' || key === 'dataIndexInside') {
  8659. others[key] = value;
  8660. return;
  8661. }
  8662. var parsedKey = key.match(/^(\w+)(Index|Id|Name)$/) || [];
  8663. var mainType = parsedKey[1];
  8664. var queryType = (parsedKey[2] || '').toLowerCase();
  8665. if (!mainType || !queryType || opt && opt.includeMainTypes && indexOf(opt.includeMainTypes, mainType) < 0) {
  8666. return;
  8667. }
  8668. mainTypeSpecified = mainTypeSpecified || !!mainType;
  8669. var queryOption = queryOptionMap.get(mainType) || queryOptionMap.set(mainType, {});
  8670. queryOption[queryType] = value;
  8671. });
  8672. return {
  8673. mainTypeSpecified: mainTypeSpecified,
  8674. queryOptionMap: queryOptionMap,
  8675. others: others
  8676. };
  8677. }
  8678. var SINGLE_REFERRING = {
  8679. useDefault: true,
  8680. enableAll: false,
  8681. enableNone: false
  8682. };
  8683. var MULTIPLE_REFERRING = {
  8684. useDefault: false,
  8685. enableAll: true,
  8686. enableNone: true
  8687. };
  8688. function queryReferringComponents(ecModel, mainType, userOption, opt) {
  8689. opt = opt || SINGLE_REFERRING;
  8690. var indexOption = userOption.index;
  8691. var idOption = userOption.id;
  8692. var nameOption = userOption.name;
  8693. var result = {
  8694. models: null,
  8695. specified: indexOption != null || idOption != null || nameOption != null
  8696. };
  8697. if (!result.specified) {
  8698. // Use the first as default if `useDefault`.
  8699. var firstCmpt = void 0;
  8700. result.models = opt.useDefault && (firstCmpt = ecModel.getComponent(mainType)) ? [firstCmpt] : [];
  8701. return result;
  8702. }
  8703. if (indexOption === 'none' || indexOption === false) {
  8704. if (opt.enableNone) {
  8705. result.models = [];
  8706. return result;
  8707. } else {
  8708. // Do not throw; consider if some component previously does not use this method,
  8709. // and start to use it, need to be fault-tolerant for backward compatibility.
  8710. if ("development" !== 'production') {
  8711. error('`"none"` or `false` is not a valid value on index option.');
  8712. }
  8713. indexOption = -1; // Can not query by index but may still query by id/name if specified.
  8714. }
  8715. }
  8716. // `queryComponents` will return all components if
  8717. // both all of index/id/name are null/undefined.
  8718. if (indexOption === 'all') {
  8719. if (opt.enableAll) {
  8720. indexOption = idOption = nameOption = null;
  8721. } else {
  8722. if ("development" !== 'production') {
  8723. error('`"all"` is not a valid value on index option.');
  8724. }
  8725. indexOption = -1;
  8726. }
  8727. }
  8728. result.models = ecModel.queryComponents({
  8729. mainType: mainType,
  8730. index: indexOption,
  8731. id: idOption,
  8732. name: nameOption
  8733. });
  8734. return result;
  8735. }
  8736. function setAttribute(dom, key, value) {
  8737. dom.setAttribute ? dom.setAttribute(key, value) : dom[key] = value;
  8738. }
  8739. function getAttribute(dom, key) {
  8740. return dom.getAttribute ? dom.getAttribute(key) : dom[key];
  8741. }
  8742. function getTooltipRenderMode(renderModeOption) {
  8743. if (renderModeOption === 'auto') {
  8744. // Using html when `document` exists, use richText otherwise
  8745. return env.domSupported ? 'html' : 'richText';
  8746. } else {
  8747. return renderModeOption || 'html';
  8748. }
  8749. }
  8750. /**
  8751. * Group a list by key.
  8752. */
  8753. function groupData(array, getKey // return key
  8754. ) {
  8755. var buckets = createHashMap();
  8756. var keys = [];
  8757. each(array, function (item) {
  8758. var key = getKey(item);
  8759. (buckets.get(key) || (keys.push(key), buckets.set(key, []))).push(item);
  8760. });
  8761. return {
  8762. keys: keys,
  8763. buckets: buckets
  8764. };
  8765. }
  8766. /**
  8767. * Interpolate raw values of a series with percent
  8768. *
  8769. * @param data data
  8770. * @param labelModel label model of the text element
  8771. * @param sourceValue start value. May be null/undefined when init.
  8772. * @param targetValue end value
  8773. * @param percent 0~1 percentage; 0 uses start value while 1 uses end value
  8774. * @return interpolated values
  8775. * If `sourceValue` and `targetValue` are `number`, return `number`.
  8776. * If `sourceValue` and `targetValue` are `string`, return `string`.
  8777. * If `sourceValue` and `targetValue` are `(string | number)[]`, return `(string | number)[]`.
  8778. * Other cases do not supported.
  8779. */
  8780. function interpolateRawValues(data, precision, sourceValue, targetValue, percent) {
  8781. var isAutoPrecision = precision == null || precision === 'auto';
  8782. if (targetValue == null) {
  8783. return targetValue;
  8784. }
  8785. if (isNumber(targetValue)) {
  8786. var value = interpolateNumber$1(sourceValue || 0, targetValue, percent);
  8787. return round(value, isAutoPrecision ? Math.max(getPrecision(sourceValue || 0), getPrecision(targetValue)) : precision);
  8788. } else if (isString(targetValue)) {
  8789. return percent < 1 ? sourceValue : targetValue;
  8790. } else {
  8791. var interpolated = [];
  8792. var leftArr = sourceValue;
  8793. var rightArr = targetValue;
  8794. var length_1 = Math.max(leftArr ? leftArr.length : 0, rightArr.length);
  8795. for (var i = 0; i < length_1; ++i) {
  8796. var info = data.getDimensionInfo(i);
  8797. // Don't interpolate ordinal dims
  8798. if (info && info.type === 'ordinal') {
  8799. // In init, there is no `sourceValue`, but should better not to get undefined result.
  8800. interpolated[i] = (percent < 1 && leftArr ? leftArr : rightArr)[i];
  8801. } else {
  8802. var leftVal = leftArr && leftArr[i] ? leftArr[i] : 0;
  8803. var rightVal = rightArr[i];
  8804. var value = interpolateNumber$1(leftVal, rightVal, percent);
  8805. interpolated[i] = round(value, isAutoPrecision ? Math.max(getPrecision(leftVal), getPrecision(rightVal)) : precision);
  8806. }
  8807. }
  8808. return interpolated;
  8809. }
  8810. }
  8811. /**
  8812. * Use an iterator to avoid exposing the internal list or duplicating it
  8813. * for the outside traveller, and no extra heap allocation.
  8814. * @usage
  8815. * for (const it = resetIterator(); it.next();) {
  8816. * const item = it.item;
  8817. * const key = it.key;
  8818. * const itIdx = it.itIdx;
  8819. * // ...
  8820. * }
  8821. * @usage
  8822. * const it = resetIterator();
  8823. * while (it.next()) { ... }
  8824. * @usage
  8825. * for (resetIterator(it); it.next();) { ... }
  8826. */
  8827. var ListIterator = /** @class */function () {
  8828. function ListIterator() {}
  8829. /**
  8830. * The loop condition is `idx < end` if `step > 0`;
  8831. * The loop condition is `idx >= end` if `step < 0`.
  8832. *
  8833. * @param end By default `list.length` if `step > 0`; `0` if `step < 0`.
  8834. * @param step By default `1`.
  8835. */
  8836. ListIterator.prototype.reset = function (list, start, end, step) {
  8837. this._list = list;
  8838. this._step = step = step || 1;
  8839. this._idx = start;
  8840. this._end = end != null ? end : step > 0 ? list.length : 0;
  8841. this.item = null;
  8842. this.key = NaN;
  8843. return this;
  8844. };
  8845. ListIterator.prototype.next = function () {
  8846. if (this._step > 0 ? this._idx < this._end : this._idx >= this._end) {
  8847. this.item = this._list[this._idx];
  8848. this.key = this._idx = this._idx + this._step;
  8849. return true;
  8850. }
  8851. return false;
  8852. };
  8853. return ListIterator;
  8854. }();
  8855. function clearTmpModel(model) {
  8856. // Clear to avoid memory leak.
  8857. model.option = model.parentModel = model.ecModel = null;
  8858. }
  8859. var TYPE_DELIMITER = '.';
  8860. var IS_CONTAINER = '___EC__COMPONENT__CONTAINER___';
  8861. var IS_EXTENDED_CLASS = '___EC__EXTENDED_CLASS___';
  8862. /**
  8863. * Notice, parseClassType('') should returns {main: '', sub: ''}
  8864. * @public
  8865. */
  8866. function parseClassType(componentType) {
  8867. var ret = {
  8868. main: '',
  8869. sub: ''
  8870. };
  8871. if (componentType) {
  8872. var typeArr = componentType.split(TYPE_DELIMITER);
  8873. ret.main = typeArr[0] || '';
  8874. ret.sub = typeArr[1] || '';
  8875. }
  8876. return ret;
  8877. }
  8878. /**
  8879. * @public
  8880. */
  8881. function checkClassType(componentType) {
  8882. assert(/^[a-zA-Z0-9_]+([.][a-zA-Z0-9_]+)?$/.test(componentType), 'componentType "' + componentType + '" illegal');
  8883. }
  8884. function isExtendedClass(clz) {
  8885. return !!(clz && clz[IS_EXTENDED_CLASS]);
  8886. }
  8887. /**
  8888. * Implements `ExtendableConstructor` for `rootClz`.
  8889. *
  8890. * @usage
  8891. * ```ts
  8892. * class Xxx {}
  8893. * type XxxConstructor = typeof Xxx & ExtendableConstructor
  8894. * enableClassExtend(Xxx as XxxConstructor);
  8895. * ```
  8896. */
  8897. function enableClassExtend(rootClz, mandatoryMethods) {
  8898. rootClz.$constructor = rootClz; // FIXME: not necessary?
  8899. rootClz.extend = function (proto) {
  8900. if ("development" !== 'production') {
  8901. each(mandatoryMethods, function (method) {
  8902. if (!proto[method]) {
  8903. console.warn('Method `' + method + '` should be implemented' + (proto.type ? ' in ' + proto.type : '') + '.');
  8904. }
  8905. });
  8906. }
  8907. var superClass = this;
  8908. var ExtendedClass;
  8909. if (isESClass(superClass)) {
  8910. ExtendedClass = /** @class */function (_super) {
  8911. __extends(class_1, _super);
  8912. function class_1() {
  8913. return _super.apply(this, arguments) || this;
  8914. }
  8915. return class_1;
  8916. }(superClass);
  8917. } else {
  8918. // For backward compat, we both support ts class inheritance and this
  8919. // "extend" approach.
  8920. // The constructor should keep the same behavior as ts class inheritance:
  8921. // If this constructor/$constructor is not declared, auto invoke the super
  8922. // constructor.
  8923. // If this constructor/$constructor is declared, it is responsible for
  8924. // calling the super constructor.
  8925. ExtendedClass = function () {
  8926. (proto.$constructor || superClass).apply(this, arguments);
  8927. };
  8928. inherits(ExtendedClass, this);
  8929. }
  8930. extend(ExtendedClass.prototype, proto);
  8931. ExtendedClass[IS_EXTENDED_CLASS] = true;
  8932. ExtendedClass.extend = this.extend;
  8933. ExtendedClass.superCall = superCall;
  8934. ExtendedClass.superApply = superApply;
  8935. ExtendedClass.superClass = superClass;
  8936. return ExtendedClass;
  8937. };
  8938. }
  8939. function isESClass(fn) {
  8940. return isFunction(fn) && /^class\s/.test(Function.prototype.toString.call(fn));
  8941. }
  8942. /**
  8943. * A work around to both support ts extend and this extend mechanism.
  8944. * on sub-class.
  8945. * @usage
  8946. * ```ts
  8947. * class Component { ... }
  8948. * classUtil.enableClassExtend(Component);
  8949. * classUtil.enableClassManagement(Component, {registerWhenExtend: true});
  8950. *
  8951. * class Series extends Component { ... }
  8952. * // Without calling `markExtend`, `registerWhenExtend` will not work.
  8953. * Component.markExtend(Series);
  8954. * ```
  8955. */
  8956. function mountExtend(SubClz, SupperClz) {
  8957. SubClz.extend = SupperClz.extend;
  8958. }
  8959. // A random offset.
  8960. var classBase = Math.round(Math.random() * 10);
  8961. /**
  8962. * Implements `CheckableConstructor` for `target`.
  8963. * Can not use instanceof, consider different scope by
  8964. * cross domain or es module import in ec extensions.
  8965. * Mount a method "isInstance()" to Clz.
  8966. *
  8967. * @usage
  8968. * ```ts
  8969. * class Xxx {}
  8970. * type XxxConstructor = typeof Xxx & CheckableConstructor;
  8971. * enableClassCheck(Xxx as XxxConstructor)
  8972. * ```
  8973. */
  8974. function enableClassCheck(target) {
  8975. var classAttr = ['__\0is_clz', classBase++].join('_');
  8976. target.prototype[classAttr] = true;
  8977. if ("development" !== 'production') {
  8978. assert(!target.isInstance, 'The method "is" can not be defined.');
  8979. }
  8980. target.isInstance = function (obj) {
  8981. return !!(obj && obj[classAttr]);
  8982. };
  8983. }
  8984. // superCall should have class info, which can not be fetched from 'this'.
  8985. // Consider this case:
  8986. // class A has method f,
  8987. // class B inherits class A, overrides method f, f call superApply('f'),
  8988. // class C inherits class B, does not override method f,
  8989. // then when method of class C is called, dead loop occurred.
  8990. function superCall(context, methodName) {
  8991. var args = [];
  8992. for (var _i = 2; _i < arguments.length; _i++) {
  8993. args[_i - 2] = arguments[_i];
  8994. }
  8995. return this.superClass.prototype[methodName].apply(context, args);
  8996. }
  8997. function superApply(context, methodName, args) {
  8998. return this.superClass.prototype[methodName].apply(context, args);
  8999. }
  9000. /**
  9001. * Implements `ClassManager` for `target`
  9002. *
  9003. * @usage
  9004. * ```ts
  9005. * class Xxx {}
  9006. * type XxxConstructor = typeof Xxx & ClassManager
  9007. * enableClassManagement(Xxx as XxxConstructor);
  9008. * ```
  9009. */
  9010. function enableClassManagement(target) {
  9011. /**
  9012. * Component model classes
  9013. * key: componentType,
  9014. * value:
  9015. * componentClass, when componentType is 'a'
  9016. * or Object.<subKey, componentClass>, when componentType is 'a.b'
  9017. */
  9018. var storage = {};
  9019. target.registerClass = function (clz) {
  9020. // `type` should not be a "instance member".
  9021. // If using TS class, should better declared as `static type = 'series.pie'`.
  9022. // otherwise users have to mount `type` on prototype manually.
  9023. // For backward compat and enable instance visit type via `this.type`,
  9024. // we still support fetch `type` from prototype.
  9025. var componentFullType = clz.type || clz.prototype.type;
  9026. if (componentFullType) {
  9027. checkClassType(componentFullType);
  9028. // If only static type declared, we assign it to prototype mandatorily.
  9029. clz.prototype.type = componentFullType;
  9030. var componentTypeInfo = parseClassType(componentFullType);
  9031. if (!componentTypeInfo.sub) {
  9032. if ("development" !== 'production') {
  9033. if (storage[componentTypeInfo.main]) {
  9034. console.warn(componentTypeInfo.main + ' exists.');
  9035. }
  9036. }
  9037. storage[componentTypeInfo.main] = clz;
  9038. } else if (componentTypeInfo.sub !== IS_CONTAINER) {
  9039. var container = makeContainer(componentTypeInfo);
  9040. container[componentTypeInfo.sub] = clz;
  9041. }
  9042. }
  9043. return clz;
  9044. };
  9045. target.getClass = function (mainType, subType, throwWhenNotFound) {
  9046. var clz = storage[mainType];
  9047. if (clz && clz[IS_CONTAINER]) {
  9048. clz = subType ? clz[subType] : null;
  9049. }
  9050. if (throwWhenNotFound && !clz) {
  9051. throw new Error(!subType ? mainType + '.' + 'type should be specified.' : 'Component ' + mainType + '.' + (subType || '') + ' is used but not imported.');
  9052. }
  9053. return clz;
  9054. };
  9055. target.getClassesByMainType = function (componentType) {
  9056. var componentTypeInfo = parseClassType(componentType);
  9057. var result = [];
  9058. var obj = storage[componentTypeInfo.main];
  9059. if (obj && obj[IS_CONTAINER]) {
  9060. each(obj, function (o, type) {
  9061. type !== IS_CONTAINER && result.push(o);
  9062. });
  9063. } else {
  9064. result.push(obj);
  9065. }
  9066. return result;
  9067. };
  9068. target.hasClass = function (componentType) {
  9069. // Just consider componentType.main.
  9070. var componentTypeInfo = parseClassType(componentType);
  9071. return !!storage[componentTypeInfo.main];
  9072. };
  9073. /**
  9074. * @return Like ['aa', 'bb'], but can not be ['aa.xx']
  9075. */
  9076. target.getAllClassMainTypes = function () {
  9077. var types = [];
  9078. each(storage, function (obj, type) {
  9079. types.push(type);
  9080. });
  9081. return types;
  9082. };
  9083. /**
  9084. * If a main type is container and has sub types
  9085. */
  9086. target.hasSubTypes = function (componentType) {
  9087. var componentTypeInfo = parseClassType(componentType);
  9088. var obj = storage[componentTypeInfo.main];
  9089. return obj && obj[IS_CONTAINER];
  9090. };
  9091. function makeContainer(componentTypeInfo) {
  9092. var container = storage[componentTypeInfo.main];
  9093. if (!container || !container[IS_CONTAINER]) {
  9094. container = storage[componentTypeInfo.main] = {};
  9095. container[IS_CONTAINER] = true;
  9096. }
  9097. return container;
  9098. }
  9099. }
  9100. // /**
  9101. // * @param {string|Array.<string>} properties
  9102. // */
  9103. // export function setReadOnly(obj, properties) {
  9104. // FIXME It seems broken in IE8 simulation of IE11
  9105. // if (!zrUtil.isArray(properties)) {
  9106. // properties = properties != null ? [properties] : [];
  9107. // }
  9108. // zrUtil.each(properties, function (prop) {
  9109. // let value = obj[prop];
  9110. // Object.defineProperty
  9111. // && Object.defineProperty(obj, prop, {
  9112. // value: value, writable: false
  9113. // });
  9114. // zrUtil.isArray(obj[prop])
  9115. // && Object.freeze
  9116. // && Object.freeze(obj[prop]);
  9117. // });
  9118. // }
  9119. function makeStyleMapper(properties, ignoreParent) {
  9120. // Normalize
  9121. for (var i = 0; i < properties.length; i++) {
  9122. if (!properties[i][1]) {
  9123. properties[i][1] = properties[i][0];
  9124. }
  9125. }
  9126. ignoreParent = ignoreParent || false;
  9127. return function (model, excludes, includes) {
  9128. var style = {};
  9129. for (var i = 0; i < properties.length; i++) {
  9130. var propName = properties[i][1];
  9131. if (excludes && indexOf(excludes, propName) >= 0 || includes && indexOf(includes, propName) < 0) {
  9132. continue;
  9133. }
  9134. var val = model.getShallow(propName, ignoreParent);
  9135. if (val != null) {
  9136. style[properties[i][0]] = val;
  9137. }
  9138. }
  9139. // TODO Text or image?
  9140. return style;
  9141. };
  9142. }
  9143. var AREA_STYLE_KEY_MAP = [['fill', 'color'], ['shadowBlur'], ['shadowOffsetX'], ['shadowOffsetY'], ['opacity'], ['shadowColor']
  9144. // Option decal is in `DecalObject` but style.decal is in `PatternObject`.
  9145. // So do not transfer decal directly.
  9146. ];
  9147. var getAreaStyle = makeStyleMapper(AREA_STYLE_KEY_MAP);
  9148. var AreaStyleMixin = /** @class */function () {
  9149. function AreaStyleMixin() {}
  9150. AreaStyleMixin.prototype.getAreaStyle = function (excludes, includes) {
  9151. return getAreaStyle(this, excludes, includes);
  9152. };
  9153. return AreaStyleMixin;
  9154. }();
  9155. var globalImageCache = new LRU(50);
  9156. function findExistImage(newImageOrSrc) {
  9157. if (typeof newImageOrSrc === 'string') {
  9158. var cachedImgObj = globalImageCache.get(newImageOrSrc);
  9159. return cachedImgObj && cachedImgObj.image;
  9160. }
  9161. else {
  9162. return newImageOrSrc;
  9163. }
  9164. }
  9165. function createOrUpdateImage(newImageOrSrc, image, hostEl, onload, cbPayload) {
  9166. if (!newImageOrSrc) {
  9167. return image;
  9168. }
  9169. else if (typeof newImageOrSrc === 'string') {
  9170. if ((image && image.__zrImageSrc === newImageOrSrc) || !hostEl) {
  9171. return image;
  9172. }
  9173. var cachedImgObj = globalImageCache.get(newImageOrSrc);
  9174. var pendingWrap = { hostEl: hostEl, cb: onload, cbPayload: cbPayload };
  9175. if (cachedImgObj) {
  9176. image = cachedImgObj.image;
  9177. !isImageReady(image) && cachedImgObj.pending.push(pendingWrap);
  9178. }
  9179. else {
  9180. image = platformApi.loadImage(newImageOrSrc, imageOnLoad, imageOnLoad);
  9181. image.__zrImageSrc = newImageOrSrc;
  9182. globalImageCache.put(newImageOrSrc, image.__cachedImgObj = {
  9183. image: image,
  9184. pending: [pendingWrap]
  9185. });
  9186. }
  9187. return image;
  9188. }
  9189. else {
  9190. return newImageOrSrc;
  9191. }
  9192. }
  9193. function imageOnLoad() {
  9194. var cachedImgObj = this.__cachedImgObj;
  9195. this.onload = this.onerror = this.__cachedImgObj = null;
  9196. for (var i = 0; i < cachedImgObj.pending.length; i++) {
  9197. var pendingWrap = cachedImgObj.pending[i];
  9198. var cb = pendingWrap.cb;
  9199. cb && cb(this, pendingWrap.cbPayload);
  9200. pendingWrap.hostEl.dirty();
  9201. }
  9202. cachedImgObj.pending.length = 0;
  9203. }
  9204. function isImageReady(image) {
  9205. return image && image.width && image.height;
  9206. }
  9207. var STYLE_REG = /\{([a-zA-Z0-9_]+)\|([^}]*)\}/g;
  9208. function truncateText(text, containerWidth, font, ellipsis, options) {
  9209. var out = {};
  9210. truncateText2(out, text, containerWidth, font, ellipsis, options);
  9211. return out.text;
  9212. }
  9213. function truncateText2(out, text, containerWidth, font, ellipsis, options) {
  9214. if (!containerWidth) {
  9215. out.text = '';
  9216. out.isTruncated = false;
  9217. return;
  9218. }
  9219. var textLines = (text + '').split('\n');
  9220. options = prepareTruncateOptions(containerWidth, font, ellipsis, options);
  9221. var isTruncated = false;
  9222. var truncateOut = {};
  9223. for (var i = 0, len = textLines.length; i < len; i++) {
  9224. truncateSingleLine(truncateOut, textLines[i], options);
  9225. textLines[i] = truncateOut.textLine;
  9226. isTruncated = isTruncated || truncateOut.isTruncated;
  9227. }
  9228. out.text = textLines.join('\n');
  9229. out.isTruncated = isTruncated;
  9230. }
  9231. function prepareTruncateOptions(containerWidth, font, ellipsis, options) {
  9232. options = options || {};
  9233. var preparedOpts = extend({}, options);
  9234. ellipsis = retrieve2(ellipsis, '...');
  9235. preparedOpts.maxIterations = retrieve2(options.maxIterations, 2);
  9236. var minChar = preparedOpts.minChar = retrieve2(options.minChar, 0);
  9237. var fontMeasureInfo = preparedOpts.fontMeasureInfo = ensureFontMeasureInfo(font);
  9238. var ascCharWidth = fontMeasureInfo.asciiCharWidth;
  9239. preparedOpts.placeholder = retrieve2(options.placeholder, '');
  9240. var contentWidth = containerWidth = Math.max(0, containerWidth - 1);
  9241. for (var i = 0; i < minChar && contentWidth >= ascCharWidth; i++) {
  9242. contentWidth -= ascCharWidth;
  9243. }
  9244. var ellipsisWidth = measureWidth(fontMeasureInfo, ellipsis);
  9245. if (ellipsisWidth > contentWidth) {
  9246. ellipsis = '';
  9247. ellipsisWidth = 0;
  9248. }
  9249. contentWidth = containerWidth - ellipsisWidth;
  9250. preparedOpts.ellipsis = ellipsis;
  9251. preparedOpts.ellipsisWidth = ellipsisWidth;
  9252. preparedOpts.contentWidth = contentWidth;
  9253. preparedOpts.containerWidth = containerWidth;
  9254. return preparedOpts;
  9255. }
  9256. function truncateSingleLine(out, textLine, options) {
  9257. var containerWidth = options.containerWidth;
  9258. var contentWidth = options.contentWidth;
  9259. var fontMeasureInfo = options.fontMeasureInfo;
  9260. if (!containerWidth) {
  9261. out.textLine = '';
  9262. out.isTruncated = false;
  9263. return;
  9264. }
  9265. var lineWidth = measureWidth(fontMeasureInfo, textLine);
  9266. if (lineWidth <= containerWidth) {
  9267. out.textLine = textLine;
  9268. out.isTruncated = false;
  9269. return;
  9270. }
  9271. for (var j = 0;; j++) {
  9272. if (lineWidth <= contentWidth || j >= options.maxIterations) {
  9273. textLine += options.ellipsis;
  9274. break;
  9275. }
  9276. var subLength = j === 0
  9277. ? estimateLength(textLine, contentWidth, fontMeasureInfo)
  9278. : lineWidth > 0
  9279. ? Math.floor(textLine.length * contentWidth / lineWidth)
  9280. : 0;
  9281. textLine = textLine.substr(0, subLength);
  9282. lineWidth = measureWidth(fontMeasureInfo, textLine);
  9283. }
  9284. if (textLine === '') {
  9285. textLine = options.placeholder;
  9286. }
  9287. out.textLine = textLine;
  9288. out.isTruncated = true;
  9289. }
  9290. function estimateLength(text, contentWidth, fontMeasureInfo) {
  9291. var width = 0;
  9292. var i = 0;
  9293. for (var len = text.length; i < len && width < contentWidth; i++) {
  9294. width += measureCharWidth(fontMeasureInfo, text.charCodeAt(i));
  9295. }
  9296. return i;
  9297. }
  9298. function parsePlainText(rawText, style, defaultOuterWidth, defaultOuterHeight) {
  9299. var text = formatText(rawText);
  9300. var overflow = style.overflow;
  9301. var padding = style.padding;
  9302. var paddingH = padding ? padding[1] + padding[3] : 0;
  9303. var paddingV = padding ? padding[0] + padding[2] : 0;
  9304. var font = style.font;
  9305. var truncate = overflow === 'truncate';
  9306. var calculatedLineHeight = getLineHeight(font);
  9307. var lineHeight = retrieve2(style.lineHeight, calculatedLineHeight);
  9308. var truncateLineOverflow = style.lineOverflow === 'truncate';
  9309. var isTruncated = false;
  9310. var width = style.width;
  9311. if (width == null && defaultOuterWidth != null) {
  9312. width = defaultOuterWidth - paddingH;
  9313. }
  9314. var height = style.height;
  9315. if (height == null && defaultOuterHeight != null) {
  9316. height = defaultOuterHeight - paddingV;
  9317. }
  9318. var lines;
  9319. if (width != null && (overflow === 'break' || overflow === 'breakAll')) {
  9320. lines = text ? wrapText(text, style.font, width, overflow === 'breakAll', 0).lines : [];
  9321. }
  9322. else {
  9323. lines = text ? text.split('\n') : [];
  9324. }
  9325. var contentHeight = lines.length * lineHeight;
  9326. if (height == null) {
  9327. height = contentHeight;
  9328. }
  9329. if (contentHeight > height && truncateLineOverflow) {
  9330. var lineCount = Math.floor(height / lineHeight);
  9331. isTruncated = isTruncated || (lines.length > lineCount);
  9332. lines = lines.slice(0, lineCount);
  9333. contentHeight = lines.length * lineHeight;
  9334. }
  9335. if (text && truncate && width != null) {
  9336. var options = prepareTruncateOptions(width, font, style.ellipsis, {
  9337. minChar: style.truncateMinChar,
  9338. placeholder: style.placeholder
  9339. });
  9340. var singleOut = {};
  9341. for (var i = 0; i < lines.length; i++) {
  9342. truncateSingleLine(singleOut, lines[i], options);
  9343. lines[i] = singleOut.textLine;
  9344. isTruncated = isTruncated || singleOut.isTruncated;
  9345. }
  9346. }
  9347. var outerHeight = height;
  9348. var contentWidth = 0;
  9349. var fontMeasureInfo = ensureFontMeasureInfo(font);
  9350. for (var i = 0; i < lines.length; i++) {
  9351. contentWidth = Math.max(measureWidth(fontMeasureInfo, lines[i]), contentWidth);
  9352. }
  9353. if (width == null) {
  9354. width = contentWidth;
  9355. }
  9356. var outerWidth = width;
  9357. outerHeight += paddingV;
  9358. outerWidth += paddingH;
  9359. return {
  9360. lines: lines,
  9361. height: height,
  9362. outerWidth: outerWidth,
  9363. outerHeight: outerHeight,
  9364. lineHeight: lineHeight,
  9365. calculatedLineHeight: calculatedLineHeight,
  9366. contentWidth: contentWidth,
  9367. contentHeight: contentHeight,
  9368. width: width,
  9369. isTruncated: isTruncated
  9370. };
  9371. }
  9372. var RichTextToken = (function () {
  9373. function RichTextToken() {
  9374. }
  9375. return RichTextToken;
  9376. }());
  9377. var RichTextLine = (function () {
  9378. function RichTextLine(tokens) {
  9379. this.tokens = [];
  9380. if (tokens) {
  9381. this.tokens = tokens;
  9382. }
  9383. }
  9384. return RichTextLine;
  9385. }());
  9386. var RichTextContentBlock = (function () {
  9387. function RichTextContentBlock() {
  9388. this.width = 0;
  9389. this.height = 0;
  9390. this.contentWidth = 0;
  9391. this.contentHeight = 0;
  9392. this.outerWidth = 0;
  9393. this.outerHeight = 0;
  9394. this.lines = [];
  9395. this.isTruncated = false;
  9396. }
  9397. return RichTextContentBlock;
  9398. }());
  9399. function parseRichText(rawText, style, defaultOuterWidth, defaultOuterHeight, topTextAlign) {
  9400. var contentBlock = new RichTextContentBlock();
  9401. var text = formatText(rawText);
  9402. if (!text) {
  9403. return contentBlock;
  9404. }
  9405. var stlPadding = style.padding;
  9406. var stlPaddingH = stlPadding ? stlPadding[1] + stlPadding[3] : 0;
  9407. var stlPaddingV = stlPadding ? stlPadding[0] + stlPadding[2] : 0;
  9408. var topWidth = style.width;
  9409. if (topWidth == null && defaultOuterWidth != null) {
  9410. topWidth = defaultOuterWidth - stlPaddingH;
  9411. }
  9412. var topHeight = style.height;
  9413. if (topHeight == null && defaultOuterHeight != null) {
  9414. topHeight = defaultOuterHeight - stlPaddingV;
  9415. }
  9416. var overflow = style.overflow;
  9417. var wrapInfo = (overflow === 'break' || overflow === 'breakAll') && topWidth != null
  9418. ? { width: topWidth, accumWidth: 0, breakAll: overflow === 'breakAll' }
  9419. : null;
  9420. var lastIndex = STYLE_REG.lastIndex = 0;
  9421. var result;
  9422. while ((result = STYLE_REG.exec(text)) != null) {
  9423. var matchedIndex = result.index;
  9424. if (matchedIndex > lastIndex) {
  9425. pushTokens(contentBlock, text.substring(lastIndex, matchedIndex), style, wrapInfo);
  9426. }
  9427. pushTokens(contentBlock, result[2], style, wrapInfo, result[1]);
  9428. lastIndex = STYLE_REG.lastIndex;
  9429. }
  9430. if (lastIndex < text.length) {
  9431. pushTokens(contentBlock, text.substring(lastIndex, text.length), style, wrapInfo);
  9432. }
  9433. var pendingList = [];
  9434. var calculatedHeight = 0;
  9435. var calculatedWidth = 0;
  9436. var truncate = overflow === 'truncate';
  9437. var truncateLine = style.lineOverflow === 'truncate';
  9438. var tmpTruncateOut = {};
  9439. function finishLine(line, lineWidth, lineHeight) {
  9440. line.width = lineWidth;
  9441. line.lineHeight = lineHeight;
  9442. calculatedHeight += lineHeight;
  9443. calculatedWidth = Math.max(calculatedWidth, lineWidth);
  9444. }
  9445. outer: for (var i = 0; i < contentBlock.lines.length; i++) {
  9446. var line = contentBlock.lines[i];
  9447. var lineHeight = 0;
  9448. var lineWidth = 0;
  9449. for (var j = 0; j < line.tokens.length; j++) {
  9450. var token = line.tokens[j];
  9451. var tokenStyle = token.styleName && style.rich[token.styleName] || {};
  9452. var textPadding = token.textPadding = tokenStyle.padding;
  9453. var paddingH = textPadding ? textPadding[1] + textPadding[3] : 0;
  9454. var font = token.font = tokenStyle.font || style.font;
  9455. token.contentHeight = getLineHeight(font);
  9456. var tokenHeight = retrieve2(tokenStyle.height, token.contentHeight);
  9457. token.innerHeight = tokenHeight;
  9458. textPadding && (tokenHeight += textPadding[0] + textPadding[2]);
  9459. token.height = tokenHeight;
  9460. token.lineHeight = retrieve3(tokenStyle.lineHeight, style.lineHeight, tokenHeight);
  9461. token.align = tokenStyle && tokenStyle.align || topTextAlign;
  9462. token.verticalAlign = tokenStyle && tokenStyle.verticalAlign || 'middle';
  9463. if (truncateLine && topHeight != null && calculatedHeight + token.lineHeight > topHeight) {
  9464. var originalLength = contentBlock.lines.length;
  9465. if (j > 0) {
  9466. line.tokens = line.tokens.slice(0, j);
  9467. finishLine(line, lineWidth, lineHeight);
  9468. contentBlock.lines = contentBlock.lines.slice(0, i + 1);
  9469. }
  9470. else {
  9471. contentBlock.lines = contentBlock.lines.slice(0, i);
  9472. }
  9473. contentBlock.isTruncated = contentBlock.isTruncated || (contentBlock.lines.length < originalLength);
  9474. break outer;
  9475. }
  9476. var styleTokenWidth = tokenStyle.width;
  9477. var tokenWidthNotSpecified = styleTokenWidth == null || styleTokenWidth === 'auto';
  9478. if (typeof styleTokenWidth === 'string' && styleTokenWidth.charAt(styleTokenWidth.length - 1) === '%') {
  9479. token.percentWidth = styleTokenWidth;
  9480. pendingList.push(token);
  9481. token.contentWidth = measureWidth(ensureFontMeasureInfo(font), token.text);
  9482. }
  9483. else {
  9484. if (tokenWidthNotSpecified) {
  9485. var textBackgroundColor = tokenStyle.backgroundColor;
  9486. var bgImg = textBackgroundColor && textBackgroundColor.image;
  9487. if (bgImg) {
  9488. bgImg = findExistImage(bgImg);
  9489. if (isImageReady(bgImg)) {
  9490. token.width = Math.max(token.width, bgImg.width * tokenHeight / bgImg.height);
  9491. }
  9492. }
  9493. }
  9494. var remainTruncWidth = truncate && topWidth != null
  9495. ? topWidth - lineWidth : null;
  9496. if (remainTruncWidth != null && remainTruncWidth < token.width) {
  9497. if (!tokenWidthNotSpecified || remainTruncWidth < paddingH) {
  9498. token.text = '';
  9499. token.width = token.contentWidth = 0;
  9500. }
  9501. else {
  9502. truncateText2(tmpTruncateOut, token.text, remainTruncWidth - paddingH, font, style.ellipsis, { minChar: style.truncateMinChar });
  9503. token.text = tmpTruncateOut.text;
  9504. contentBlock.isTruncated = contentBlock.isTruncated || tmpTruncateOut.isTruncated;
  9505. token.width = token.contentWidth = measureWidth(ensureFontMeasureInfo(font), token.text);
  9506. }
  9507. }
  9508. else {
  9509. token.contentWidth = measureWidth(ensureFontMeasureInfo(font), token.text);
  9510. }
  9511. }
  9512. token.width += paddingH;
  9513. lineWidth += token.width;
  9514. tokenStyle && (lineHeight = Math.max(lineHeight, token.lineHeight));
  9515. }
  9516. finishLine(line, lineWidth, lineHeight);
  9517. }
  9518. contentBlock.outerWidth = contentBlock.width = retrieve2(topWidth, calculatedWidth);
  9519. contentBlock.outerHeight = contentBlock.height = retrieve2(topHeight, calculatedHeight);
  9520. contentBlock.contentHeight = calculatedHeight;
  9521. contentBlock.contentWidth = calculatedWidth;
  9522. contentBlock.outerWidth += stlPaddingH;
  9523. contentBlock.outerHeight += stlPaddingV;
  9524. for (var i = 0; i < pendingList.length; i++) {
  9525. var token = pendingList[i];
  9526. var percentWidth = token.percentWidth;
  9527. token.width = parseInt(percentWidth, 10) / 100 * contentBlock.width;
  9528. }
  9529. return contentBlock;
  9530. }
  9531. function pushTokens(block, str, style, wrapInfo, styleName) {
  9532. var isEmptyStr = str === '';
  9533. var tokenStyle = styleName && style.rich[styleName] || {};
  9534. var lines = block.lines;
  9535. var font = tokenStyle.font || style.font;
  9536. var newLine = false;
  9537. var strLines;
  9538. var linesWidths;
  9539. if (wrapInfo) {
  9540. var tokenPadding = tokenStyle.padding;
  9541. var tokenPaddingH = tokenPadding ? tokenPadding[1] + tokenPadding[3] : 0;
  9542. if (tokenStyle.width != null && tokenStyle.width !== 'auto') {
  9543. var outerWidth_1 = parsePercent(tokenStyle.width, wrapInfo.width) + tokenPaddingH;
  9544. if (lines.length > 0) {
  9545. if (outerWidth_1 + wrapInfo.accumWidth > wrapInfo.width) {
  9546. strLines = str.split('\n');
  9547. newLine = true;
  9548. }
  9549. }
  9550. wrapInfo.accumWidth = outerWidth_1;
  9551. }
  9552. else {
  9553. var res = wrapText(str, font, wrapInfo.width, wrapInfo.breakAll, wrapInfo.accumWidth);
  9554. wrapInfo.accumWidth = res.accumWidth + tokenPaddingH;
  9555. linesWidths = res.linesWidths;
  9556. strLines = res.lines;
  9557. }
  9558. }
  9559. if (!strLines) {
  9560. strLines = str.split('\n');
  9561. }
  9562. var fontMeasureInfo = ensureFontMeasureInfo(font);
  9563. for (var i = 0; i < strLines.length; i++) {
  9564. var text = strLines[i];
  9565. var token = new RichTextToken();
  9566. token.styleName = styleName;
  9567. token.text = text;
  9568. token.isLineHolder = !text && !isEmptyStr;
  9569. if (typeof tokenStyle.width === 'number') {
  9570. token.width = tokenStyle.width;
  9571. }
  9572. else {
  9573. token.width = linesWidths
  9574. ? linesWidths[i]
  9575. : measureWidth(fontMeasureInfo, text);
  9576. }
  9577. if (!i && !newLine) {
  9578. var tokens = (lines[lines.length - 1] || (lines[0] = new RichTextLine())).tokens;
  9579. var tokensLen = tokens.length;
  9580. (tokensLen === 1 && tokens[0].isLineHolder)
  9581. ? (tokens[0] = token)
  9582. : ((text || !tokensLen || isEmptyStr) && tokens.push(token));
  9583. }
  9584. else {
  9585. lines.push(new RichTextLine([token]));
  9586. }
  9587. }
  9588. }
  9589. function isAlphabeticLetter(ch) {
  9590. var code = ch.charCodeAt(0);
  9591. return code >= 0x20 && code <= 0x24F
  9592. || code >= 0x370 && code <= 0x10FF
  9593. || code >= 0x1200 && code <= 0x13FF
  9594. || code >= 0x1E00 && code <= 0x206F;
  9595. }
  9596. var breakCharMap = reduce(',&?/;] '.split(''), function (obj, ch) {
  9597. obj[ch] = true;
  9598. return obj;
  9599. }, {});
  9600. function isWordBreakChar(ch) {
  9601. if (isAlphabeticLetter(ch)) {
  9602. if (breakCharMap[ch]) {
  9603. return true;
  9604. }
  9605. return false;
  9606. }
  9607. return true;
  9608. }
  9609. function wrapText(text, font, lineWidth, isBreakAll, lastAccumWidth) {
  9610. var lines = [];
  9611. var linesWidths = [];
  9612. var line = '';
  9613. var currentWord = '';
  9614. var currentWordWidth = 0;
  9615. var accumWidth = 0;
  9616. var fontMeasureInfo = ensureFontMeasureInfo(font);
  9617. for (var i = 0; i < text.length; i++) {
  9618. var ch = text.charAt(i);
  9619. if (ch === '\n') {
  9620. if (currentWord) {
  9621. line += currentWord;
  9622. accumWidth += currentWordWidth;
  9623. }
  9624. lines.push(line);
  9625. linesWidths.push(accumWidth);
  9626. line = '';
  9627. currentWord = '';
  9628. currentWordWidth = 0;
  9629. accumWidth = 0;
  9630. continue;
  9631. }
  9632. var chWidth = measureCharWidth(fontMeasureInfo, ch.charCodeAt(0));
  9633. var inWord = isBreakAll ? false : !isWordBreakChar(ch);
  9634. if (!lines.length
  9635. ? lastAccumWidth + accumWidth + chWidth > lineWidth
  9636. : accumWidth + chWidth > lineWidth) {
  9637. if (!accumWidth) {
  9638. if (inWord) {
  9639. lines.push(currentWord);
  9640. linesWidths.push(currentWordWidth);
  9641. currentWord = ch;
  9642. currentWordWidth = chWidth;
  9643. }
  9644. else {
  9645. lines.push(ch);
  9646. linesWidths.push(chWidth);
  9647. }
  9648. }
  9649. else if (line || currentWord) {
  9650. if (inWord) {
  9651. if (!line) {
  9652. line = currentWord;
  9653. currentWord = '';
  9654. currentWordWidth = 0;
  9655. accumWidth = currentWordWidth;
  9656. }
  9657. lines.push(line);
  9658. linesWidths.push(accumWidth - currentWordWidth);
  9659. currentWord += ch;
  9660. currentWordWidth += chWidth;
  9661. line = '';
  9662. accumWidth = currentWordWidth;
  9663. }
  9664. else {
  9665. if (currentWord) {
  9666. line += currentWord;
  9667. currentWord = '';
  9668. currentWordWidth = 0;
  9669. }
  9670. lines.push(line);
  9671. linesWidths.push(accumWidth);
  9672. line = ch;
  9673. accumWidth = chWidth;
  9674. }
  9675. }
  9676. continue;
  9677. }
  9678. accumWidth += chWidth;
  9679. if (inWord) {
  9680. currentWord += ch;
  9681. currentWordWidth += chWidth;
  9682. }
  9683. else {
  9684. if (currentWord) {
  9685. line += currentWord;
  9686. currentWord = '';
  9687. currentWordWidth = 0;
  9688. }
  9689. line += ch;
  9690. }
  9691. }
  9692. if (currentWord) {
  9693. line += currentWord;
  9694. }
  9695. if (line) {
  9696. lines.push(line);
  9697. linesWidths.push(accumWidth);
  9698. }
  9699. if (lines.length === 1) {
  9700. accumWidth += lastAccumWidth;
  9701. }
  9702. return {
  9703. accumWidth: accumWidth,
  9704. lines: lines,
  9705. linesWidths: linesWidths
  9706. };
  9707. }
  9708. function calcInnerTextOverflowArea(out, overflowRect, baseX, baseY, textAlign, textVerticalAlign) {
  9709. out.baseX = baseX;
  9710. out.baseY = baseY;
  9711. out.outerWidth = out.outerHeight = null;
  9712. if (!overflowRect) {
  9713. return;
  9714. }
  9715. var textWidth = overflowRect.width * 2;
  9716. var textHeight = overflowRect.height * 2;
  9717. BoundingRect.set(tmpCITCTextRect, adjustTextX(baseX, textWidth, textAlign), adjustTextY$1(baseY, textHeight, textVerticalAlign), textWidth, textHeight);
  9718. BoundingRect.intersect(overflowRect, tmpCITCTextRect, null, tmpCITCIntersectRectOpt);
  9719. var outIntersectRect = tmpCITCIntersectRectOpt.outIntersectRect;
  9720. out.outerWidth = outIntersectRect.width;
  9721. out.outerHeight = outIntersectRect.height;
  9722. out.baseX = adjustTextX(outIntersectRect.x, outIntersectRect.width, textAlign, true);
  9723. out.baseY = adjustTextY$1(outIntersectRect.y, outIntersectRect.height, textVerticalAlign, true);
  9724. }
  9725. var tmpCITCTextRect = new BoundingRect(0, 0, 0, 0);
  9726. var tmpCITCIntersectRectOpt = { outIntersectRect: {}, clamp: true };
  9727. function formatText(text) {
  9728. return text != null ? (text += '') : (text = '');
  9729. }
  9730. function tSpanCreateBoundingRect(style) {
  9731. var text = formatText(style.text);
  9732. var font = style.font;
  9733. var contentWidth = measureWidth(ensureFontMeasureInfo(font), text);
  9734. var contentHeight = getLineHeight(font);
  9735. return tSpanCreateBoundingRect2(style, contentWidth, contentHeight, null);
  9736. }
  9737. function tSpanCreateBoundingRect2(style, contentWidth, contentHeight, forceLineWidth) {
  9738. var rect = new BoundingRect(adjustTextX(style.x || 0, contentWidth, style.textAlign), adjustTextY$1(style.y || 0, contentHeight, style.textBaseline), contentWidth, contentHeight);
  9739. var lineWidth = forceLineWidth != null
  9740. ? forceLineWidth
  9741. : (tSpanHasStroke(style) ? style.lineWidth : 0);
  9742. if (lineWidth > 0) {
  9743. rect.x -= lineWidth / 2;
  9744. rect.y -= lineWidth / 2;
  9745. rect.width += lineWidth;
  9746. rect.height += lineWidth;
  9747. }
  9748. return rect;
  9749. }
  9750. function tSpanHasStroke(style) {
  9751. var stroke = style.stroke;
  9752. return stroke != null && stroke !== 'none' && style.lineWidth > 0;
  9753. }
  9754. var STYLE_MAGIC_KEY = '__zr_style_' + Math.round((Math.random() * 10));
  9755. var DEFAULT_COMMON_STYLE = {
  9756. shadowBlur: 0,
  9757. shadowOffsetX: 0,
  9758. shadowOffsetY: 0,
  9759. shadowColor: '#000',
  9760. opacity: 1,
  9761. blend: 'source-over'
  9762. };
  9763. var DEFAULT_COMMON_ANIMATION_PROPS = {
  9764. style: {
  9765. shadowBlur: true,
  9766. shadowOffsetX: true,
  9767. shadowOffsetY: true,
  9768. shadowColor: true,
  9769. opacity: true
  9770. }
  9771. };
  9772. DEFAULT_COMMON_STYLE[STYLE_MAGIC_KEY] = true;
  9773. var PRIMARY_STATES_KEYS$1 = ['z', 'z2', 'invisible'];
  9774. var PRIMARY_STATES_KEYS_IN_HOVER_LAYER = ['invisible'];
  9775. var Displayable = (function (_super) {
  9776. __extends(Displayable, _super);
  9777. function Displayable(props) {
  9778. return _super.call(this, props) || this;
  9779. }
  9780. Displayable.prototype._init = function (props) {
  9781. var keysArr = keys(props);
  9782. for (var i = 0; i < keysArr.length; i++) {
  9783. var key = keysArr[i];
  9784. if (key === 'style') {
  9785. this.useStyle(props[key]);
  9786. }
  9787. else {
  9788. _super.prototype.attrKV.call(this, key, props[key]);
  9789. }
  9790. }
  9791. if (!this.style) {
  9792. this.useStyle({});
  9793. }
  9794. };
  9795. Displayable.prototype.beforeBrush = function () { };
  9796. Displayable.prototype.afterBrush = function () { };
  9797. Displayable.prototype.innerBeforeBrush = function () { };
  9798. Displayable.prototype.innerAfterBrush = function () { };
  9799. Displayable.prototype.shouldBePainted = function (viewWidth, viewHeight, considerClipPath, considerAncestors) {
  9800. var m = this.transform;
  9801. if (this.ignore
  9802. || this.invisible
  9803. || this.style.opacity === 0
  9804. || (this.culling
  9805. && isDisplayableCulled(this, viewWidth, viewHeight))
  9806. || (m && !m[0] && !m[3])) {
  9807. return false;
  9808. }
  9809. if (considerClipPath && this.__clipPaths && this.__clipPaths.length) {
  9810. for (var i = 0; i < this.__clipPaths.length; ++i) {
  9811. if (this.__clipPaths[i].isZeroArea()) {
  9812. return false;
  9813. }
  9814. }
  9815. }
  9816. if (considerAncestors && this.parent) {
  9817. var parent_1 = this.parent;
  9818. while (parent_1) {
  9819. if (parent_1.ignore) {
  9820. return false;
  9821. }
  9822. parent_1 = parent_1.parent;
  9823. }
  9824. }
  9825. return true;
  9826. };
  9827. Displayable.prototype.contain = function (x, y) {
  9828. return this.rectContain(x, y);
  9829. };
  9830. Displayable.prototype.traverse = function (cb, context) {
  9831. cb.call(context, this);
  9832. };
  9833. Displayable.prototype.rectContain = function (x, y) {
  9834. var coord = this.transformCoordToLocal(x, y);
  9835. var rect = this.getBoundingRect();
  9836. return rect.contain(coord[0], coord[1]);
  9837. };
  9838. Displayable.prototype.getPaintRect = function () {
  9839. var rect = this._paintRect;
  9840. if (!this._paintRect || this.__dirty) {
  9841. var transform = this.transform;
  9842. var elRect = this.getBoundingRect();
  9843. var style = this.style;
  9844. var shadowSize = style.shadowBlur || 0;
  9845. var shadowOffsetX = style.shadowOffsetX || 0;
  9846. var shadowOffsetY = style.shadowOffsetY || 0;
  9847. rect = this._paintRect || (this._paintRect = new BoundingRect(0, 0, 0, 0));
  9848. if (transform) {
  9849. BoundingRect.applyTransform(rect, elRect, transform);
  9850. }
  9851. else {
  9852. rect.copy(elRect);
  9853. }
  9854. if (shadowSize || shadowOffsetX || shadowOffsetY) {
  9855. rect.width += shadowSize * 2 + Math.abs(shadowOffsetX);
  9856. rect.height += shadowSize * 2 + Math.abs(shadowOffsetY);
  9857. rect.x = Math.min(rect.x, rect.x + shadowOffsetX - shadowSize);
  9858. rect.y = Math.min(rect.y, rect.y + shadowOffsetY - shadowSize);
  9859. }
  9860. var tolerance = this.dirtyRectTolerance;
  9861. if (!rect.isZero()) {
  9862. rect.x = Math.floor(rect.x - tolerance);
  9863. rect.y = Math.floor(rect.y - tolerance);
  9864. rect.width = Math.ceil(rect.width + 1 + tolerance * 2);
  9865. rect.height = Math.ceil(rect.height + 1 + tolerance * 2);
  9866. }
  9867. }
  9868. return rect;
  9869. };
  9870. Displayable.prototype.setPrevPaintRect = function (paintRect) {
  9871. if (paintRect) {
  9872. this._prevPaintRect = this._prevPaintRect || new BoundingRect(0, 0, 0, 0);
  9873. this._prevPaintRect.copy(paintRect);
  9874. }
  9875. else {
  9876. this._prevPaintRect = null;
  9877. }
  9878. };
  9879. Displayable.prototype.getPrevPaintRect = function () {
  9880. return this._prevPaintRect;
  9881. };
  9882. Displayable.prototype.animateStyle = function (loop) {
  9883. return this.animate('style', loop);
  9884. };
  9885. Displayable.prototype.updateDuringAnimation = function (targetKey) {
  9886. if (targetKey === 'style') {
  9887. this.dirtyStyle();
  9888. }
  9889. else {
  9890. this.markRedraw();
  9891. }
  9892. };
  9893. Displayable.prototype.attrKV = function (key, value) {
  9894. if (key !== 'style') {
  9895. _super.prototype.attrKV.call(this, key, value);
  9896. }
  9897. else {
  9898. if (!this.style) {
  9899. this.useStyle(value);
  9900. }
  9901. else {
  9902. this.setStyle(value);
  9903. }
  9904. }
  9905. };
  9906. Displayable.prototype.setStyle = function (keyOrObj, value) {
  9907. if (typeof keyOrObj === 'string') {
  9908. this.style[keyOrObj] = value;
  9909. }
  9910. else {
  9911. extend(this.style, keyOrObj);
  9912. }
  9913. this.dirtyStyle();
  9914. return this;
  9915. };
  9916. Displayable.prototype.dirtyStyle = function (notRedraw) {
  9917. if (!notRedraw) {
  9918. this.markRedraw();
  9919. }
  9920. this.__dirty |= STYLE_CHANGED_BIT;
  9921. if (this._rect) {
  9922. this._rect = null;
  9923. }
  9924. };
  9925. Displayable.prototype.dirty = function () {
  9926. this.dirtyStyle();
  9927. };
  9928. Displayable.prototype.styleChanged = function () {
  9929. return !!(this.__dirty & STYLE_CHANGED_BIT);
  9930. };
  9931. Displayable.prototype.styleUpdated = function () {
  9932. this.__dirty &= ~STYLE_CHANGED_BIT;
  9933. };
  9934. Displayable.prototype.createStyle = function (obj) {
  9935. return createObject(DEFAULT_COMMON_STYLE, obj);
  9936. };
  9937. Displayable.prototype.useStyle = function (obj) {
  9938. if (!obj[STYLE_MAGIC_KEY]) {
  9939. obj = this.createStyle(obj);
  9940. }
  9941. if (this.__inHover) {
  9942. this.__hoverStyle = obj;
  9943. }
  9944. else {
  9945. this.style = obj;
  9946. }
  9947. this.dirtyStyle();
  9948. };
  9949. Displayable.prototype.isStyleObject = function (obj) {
  9950. return obj[STYLE_MAGIC_KEY];
  9951. };
  9952. Displayable.prototype._innerSaveToNormal = function (toState) {
  9953. _super.prototype._innerSaveToNormal.call(this, toState);
  9954. var normalState = this._normalState;
  9955. if (toState.style && !normalState.style) {
  9956. normalState.style = this._mergeStyle(this.createStyle(), this.style);
  9957. }
  9958. this._savePrimaryToNormal(toState, normalState, PRIMARY_STATES_KEYS$1);
  9959. };
  9960. Displayable.prototype._applyStateObj = function (stateName, state, normalState, keepCurrentStates, transition, animationCfg) {
  9961. _super.prototype._applyStateObj.call(this, stateName, state, normalState, keepCurrentStates, transition, animationCfg);
  9962. var needsRestoreToNormal = !(state && keepCurrentStates);
  9963. var targetStyle;
  9964. if (state && state.style) {
  9965. if (transition) {
  9966. if (keepCurrentStates) {
  9967. targetStyle = state.style;
  9968. }
  9969. else {
  9970. targetStyle = this._mergeStyle(this.createStyle(), normalState.style);
  9971. this._mergeStyle(targetStyle, state.style);
  9972. }
  9973. }
  9974. else {
  9975. targetStyle = this._mergeStyle(this.createStyle(), keepCurrentStates ? this.style : normalState.style);
  9976. this._mergeStyle(targetStyle, state.style);
  9977. }
  9978. }
  9979. else if (needsRestoreToNormal) {
  9980. targetStyle = normalState.style;
  9981. }
  9982. if (targetStyle) {
  9983. if (transition) {
  9984. var sourceStyle = this.style;
  9985. this.style = this.createStyle(needsRestoreToNormal ? {} : sourceStyle);
  9986. if (needsRestoreToNormal) {
  9987. var changedKeys = keys(sourceStyle);
  9988. for (var i = 0; i < changedKeys.length; i++) {
  9989. var key = changedKeys[i];
  9990. if (key in targetStyle) {
  9991. targetStyle[key] = targetStyle[key];
  9992. this.style[key] = sourceStyle[key];
  9993. }
  9994. }
  9995. }
  9996. var targetKeys = keys(targetStyle);
  9997. for (var i = 0; i < targetKeys.length; i++) {
  9998. var key = targetKeys[i];
  9999. this.style[key] = this.style[key];
  10000. }
  10001. this._transitionState(stateName, {
  10002. style: targetStyle
  10003. }, animationCfg, this.getAnimationStyleProps());
  10004. }
  10005. else {
  10006. this.useStyle(targetStyle);
  10007. }
  10008. }
  10009. var statesKeys = this.__inHover ? PRIMARY_STATES_KEYS_IN_HOVER_LAYER : PRIMARY_STATES_KEYS$1;
  10010. for (var i = 0; i < statesKeys.length; i++) {
  10011. var key = statesKeys[i];
  10012. if (state && state[key] != null) {
  10013. this[key] = state[key];
  10014. }
  10015. else if (needsRestoreToNormal) {
  10016. if (normalState[key] != null) {
  10017. this[key] = normalState[key];
  10018. }
  10019. }
  10020. }
  10021. };
  10022. Displayable.prototype._mergeStates = function (states) {
  10023. var mergedState = _super.prototype._mergeStates.call(this, states);
  10024. var mergedStyle;
  10025. for (var i = 0; i < states.length; i++) {
  10026. var state = states[i];
  10027. if (state.style) {
  10028. mergedStyle = mergedStyle || {};
  10029. this._mergeStyle(mergedStyle, state.style);
  10030. }
  10031. }
  10032. if (mergedStyle) {
  10033. mergedState.style = mergedStyle;
  10034. }
  10035. return mergedState;
  10036. };
  10037. Displayable.prototype._mergeStyle = function (targetStyle, sourceStyle) {
  10038. extend(targetStyle, sourceStyle);
  10039. return targetStyle;
  10040. };
  10041. Displayable.prototype.getAnimationStyleProps = function () {
  10042. return DEFAULT_COMMON_ANIMATION_PROPS;
  10043. };
  10044. Displayable.initDefaultProps = (function () {
  10045. var dispProto = Displayable.prototype;
  10046. dispProto.type = 'displayable';
  10047. dispProto.invisible = false;
  10048. dispProto.z = 0;
  10049. dispProto.z2 = 0;
  10050. dispProto.zlevel = 0;
  10051. dispProto.culling = false;
  10052. dispProto.cursor = 'pointer';
  10053. dispProto.rectHover = false;
  10054. dispProto.incremental = false;
  10055. dispProto._rect = null;
  10056. dispProto.dirtyRectTolerance = 0;
  10057. dispProto.__dirty = REDRAW_BIT | STYLE_CHANGED_BIT;
  10058. })();
  10059. return Displayable;
  10060. }(Element));
  10061. var tmpRect$1 = new BoundingRect(0, 0, 0, 0);
  10062. var viewRect = new BoundingRect(0, 0, 0, 0);
  10063. function isDisplayableCulled(el, width, height) {
  10064. tmpRect$1.copy(el.getBoundingRect());
  10065. if (el.transform) {
  10066. tmpRect$1.applyTransform(el.transform);
  10067. }
  10068. viewRect.width = width;
  10069. viewRect.height = height;
  10070. return !tmpRect$1.intersect(viewRect);
  10071. }
  10072. var mathMin$2 = Math.min;
  10073. var mathMax$2 = Math.max;
  10074. var mathSin = Math.sin;
  10075. var mathCos = Math.cos;
  10076. var PI2 = Math.PI * 2;
  10077. var start = create();
  10078. var end = create();
  10079. var extremity = create();
  10080. function fromPoints(points, min, max) {
  10081. if (points.length === 0) {
  10082. return;
  10083. }
  10084. var p = points[0];
  10085. var left = p[0];
  10086. var right = p[0];
  10087. var top = p[1];
  10088. var bottom = p[1];
  10089. for (var i = 1; i < points.length; i++) {
  10090. p = points[i];
  10091. left = mathMin$2(left, p[0]);
  10092. right = mathMax$2(right, p[0]);
  10093. top = mathMin$2(top, p[1]);
  10094. bottom = mathMax$2(bottom, p[1]);
  10095. }
  10096. min[0] = left;
  10097. min[1] = top;
  10098. max[0] = right;
  10099. max[1] = bottom;
  10100. }
  10101. function fromLine(x0, y0, x1, y1, min, max) {
  10102. min[0] = mathMin$2(x0, x1);
  10103. min[1] = mathMin$2(y0, y1);
  10104. max[0] = mathMax$2(x0, x1);
  10105. max[1] = mathMax$2(y0, y1);
  10106. }
  10107. var xDim = [];
  10108. var yDim = [];
  10109. function fromCubic(x0, y0, x1, y1, x2, y2, x3, y3, min, max) {
  10110. var cubicExtrema$1 = cubicExtrema;
  10111. var cubicAt$1 = cubicAt;
  10112. var n = cubicExtrema$1(x0, x1, x2, x3, xDim);
  10113. min[0] = Infinity;
  10114. min[1] = Infinity;
  10115. max[0] = -Infinity;
  10116. max[1] = -Infinity;
  10117. for (var i = 0; i < n; i++) {
  10118. var x = cubicAt$1(x0, x1, x2, x3, xDim[i]);
  10119. min[0] = mathMin$2(x, min[0]);
  10120. max[0] = mathMax$2(x, max[0]);
  10121. }
  10122. n = cubicExtrema$1(y0, y1, y2, y3, yDim);
  10123. for (var i = 0; i < n; i++) {
  10124. var y = cubicAt$1(y0, y1, y2, y3, yDim[i]);
  10125. min[1] = mathMin$2(y, min[1]);
  10126. max[1] = mathMax$2(y, max[1]);
  10127. }
  10128. min[0] = mathMin$2(x0, min[0]);
  10129. max[0] = mathMax$2(x0, max[0]);
  10130. min[0] = mathMin$2(x3, min[0]);
  10131. max[0] = mathMax$2(x3, max[0]);
  10132. min[1] = mathMin$2(y0, min[1]);
  10133. max[1] = mathMax$2(y0, max[1]);
  10134. min[1] = mathMin$2(y3, min[1]);
  10135. max[1] = mathMax$2(y3, max[1]);
  10136. }
  10137. function fromQuadratic(x0, y0, x1, y1, x2, y2, min, max) {
  10138. var quadraticExtremum$1 = quadraticExtremum;
  10139. var quadraticAt$1 = quadraticAt;
  10140. var tx = mathMax$2(mathMin$2(quadraticExtremum$1(x0, x1, x2), 1), 0);
  10141. var ty = mathMax$2(mathMin$2(quadraticExtremum$1(y0, y1, y2), 1), 0);
  10142. var x = quadraticAt$1(x0, x1, x2, tx);
  10143. var y = quadraticAt$1(y0, y1, y2, ty);
  10144. min[0] = mathMin$2(x0, x2, x);
  10145. min[1] = mathMin$2(y0, y2, y);
  10146. max[0] = mathMax$2(x0, x2, x);
  10147. max[1] = mathMax$2(y0, y2, y);
  10148. }
  10149. function fromArc(x, y, rx, ry, startAngle, endAngle, anticlockwise, min$1, max$1) {
  10150. var vec2Min = min;
  10151. var vec2Max = max;
  10152. var diff = Math.abs(startAngle - endAngle);
  10153. if (diff % PI2 < 1e-4 && diff > 1e-4) {
  10154. min$1[0] = x - rx;
  10155. min$1[1] = y - ry;
  10156. max$1[0] = x + rx;
  10157. max$1[1] = y + ry;
  10158. return;
  10159. }
  10160. start[0] = mathCos(startAngle) * rx + x;
  10161. start[1] = mathSin(startAngle) * ry + y;
  10162. end[0] = mathCos(endAngle) * rx + x;
  10163. end[1] = mathSin(endAngle) * ry + y;
  10164. vec2Min(min$1, start, end);
  10165. vec2Max(max$1, start, end);
  10166. startAngle = startAngle % (PI2);
  10167. if (startAngle < 0) {
  10168. startAngle = startAngle + PI2;
  10169. }
  10170. endAngle = endAngle % (PI2);
  10171. if (endAngle < 0) {
  10172. endAngle = endAngle + PI2;
  10173. }
  10174. if (startAngle > endAngle && !anticlockwise) {
  10175. endAngle += PI2;
  10176. }
  10177. else if (startAngle < endAngle && anticlockwise) {
  10178. startAngle += PI2;
  10179. }
  10180. if (anticlockwise) {
  10181. var tmp = endAngle;
  10182. endAngle = startAngle;
  10183. startAngle = tmp;
  10184. }
  10185. for (var angle = 0; angle < endAngle; angle += Math.PI / 2) {
  10186. if (angle > startAngle) {
  10187. extremity[0] = mathCos(angle) * rx + x;
  10188. extremity[1] = mathSin(angle) * ry + y;
  10189. vec2Min(min$1, extremity, min$1);
  10190. vec2Max(max$1, extremity, max$1);
  10191. }
  10192. }
  10193. }
  10194. var CMD = {
  10195. M: 1,
  10196. L: 2,
  10197. C: 3,
  10198. Q: 4,
  10199. A: 5,
  10200. Z: 6,
  10201. R: 7
  10202. };
  10203. var tmpOutX = [];
  10204. var tmpOutY = [];
  10205. var min$1 = [];
  10206. var max$1 = [];
  10207. var min2 = [];
  10208. var max2 = [];
  10209. var mathMin$3 = Math.min;
  10210. var mathMax$3 = Math.max;
  10211. var mathCos$1 = Math.cos;
  10212. var mathSin$1 = Math.sin;
  10213. var mathAbs$2 = Math.abs;
  10214. var PI = Math.PI;
  10215. var PI2$1 = PI * 2;
  10216. var hasTypedArray = typeof Float32Array !== 'undefined';
  10217. var tmpAngles = [];
  10218. function modPI2(radian) {
  10219. var n = Math.round(radian / PI * 1e8) / 1e8;
  10220. return (n % 2) * PI;
  10221. }
  10222. function normalizeArcAngles(angles, anticlockwise) {
  10223. var newStartAngle = modPI2(angles[0]);
  10224. if (newStartAngle < 0) {
  10225. newStartAngle += PI2$1;
  10226. }
  10227. var delta = newStartAngle - angles[0];
  10228. var newEndAngle = angles[1];
  10229. newEndAngle += delta;
  10230. if (!anticlockwise && newEndAngle - newStartAngle >= PI2$1) {
  10231. newEndAngle = newStartAngle + PI2$1;
  10232. }
  10233. else if (anticlockwise && newStartAngle - newEndAngle >= PI2$1) {
  10234. newEndAngle = newStartAngle - PI2$1;
  10235. }
  10236. else if (!anticlockwise && newStartAngle > newEndAngle) {
  10237. newEndAngle = newStartAngle + (PI2$1 - modPI2(newStartAngle - newEndAngle));
  10238. }
  10239. else if (anticlockwise && newStartAngle < newEndAngle) {
  10240. newEndAngle = newStartAngle - (PI2$1 - modPI2(newEndAngle - newStartAngle));
  10241. }
  10242. angles[0] = newStartAngle;
  10243. angles[1] = newEndAngle;
  10244. }
  10245. var PathProxy = (function () {
  10246. function PathProxy(notSaveData) {
  10247. this.dpr = 1;
  10248. this._xi = 0;
  10249. this._yi = 0;
  10250. this._x0 = 0;
  10251. this._y0 = 0;
  10252. this._len = 0;
  10253. if (notSaveData) {
  10254. this._saveData = false;
  10255. }
  10256. if (this._saveData) {
  10257. this.data = [];
  10258. }
  10259. }
  10260. PathProxy.prototype.increaseVersion = function () {
  10261. this._version++;
  10262. };
  10263. PathProxy.prototype.getVersion = function () {
  10264. return this._version;
  10265. };
  10266. PathProxy.prototype.setScale = function (sx, sy, segmentIgnoreThreshold) {
  10267. segmentIgnoreThreshold = segmentIgnoreThreshold || 0;
  10268. if (segmentIgnoreThreshold > 0) {
  10269. this._ux = mathAbs$2(segmentIgnoreThreshold / devicePixelRatio / sx) || 0;
  10270. this._uy = mathAbs$2(segmentIgnoreThreshold / devicePixelRatio / sy) || 0;
  10271. }
  10272. };
  10273. PathProxy.prototype.setDPR = function (dpr) {
  10274. this.dpr = dpr;
  10275. };
  10276. PathProxy.prototype.setContext = function (ctx) {
  10277. this._ctx = ctx;
  10278. };
  10279. PathProxy.prototype.getContext = function () {
  10280. return this._ctx;
  10281. };
  10282. PathProxy.prototype.beginPath = function () {
  10283. this._ctx && this._ctx.beginPath();
  10284. this.reset();
  10285. return this;
  10286. };
  10287. PathProxy.prototype.reset = function () {
  10288. if (this._saveData) {
  10289. this._len = 0;
  10290. }
  10291. if (this._pathSegLen) {
  10292. this._pathSegLen = null;
  10293. this._pathLen = 0;
  10294. }
  10295. this._version++;
  10296. };
  10297. PathProxy.prototype.moveTo = function (x, y) {
  10298. this._drawPendingPt();
  10299. this.addData(CMD.M, x, y);
  10300. this._ctx && this._ctx.moveTo(x, y);
  10301. this._x0 = x;
  10302. this._y0 = y;
  10303. this._xi = x;
  10304. this._yi = y;
  10305. return this;
  10306. };
  10307. PathProxy.prototype.lineTo = function (x, y) {
  10308. var dx = mathAbs$2(x - this._xi);
  10309. var dy = mathAbs$2(y - this._yi);
  10310. var exceedUnit = dx > this._ux || dy > this._uy;
  10311. this.addData(CMD.L, x, y);
  10312. if (this._ctx && exceedUnit) {
  10313. this._ctx.lineTo(x, y);
  10314. }
  10315. if (exceedUnit) {
  10316. this._xi = x;
  10317. this._yi = y;
  10318. this._pendingPtDist = 0;
  10319. }
  10320. else {
  10321. var d2 = dx * dx + dy * dy;
  10322. if (d2 > this._pendingPtDist) {
  10323. this._pendingPtX = x;
  10324. this._pendingPtY = y;
  10325. this._pendingPtDist = d2;
  10326. }
  10327. }
  10328. return this;
  10329. };
  10330. PathProxy.prototype.bezierCurveTo = function (x1, y1, x2, y2, x3, y3) {
  10331. this._drawPendingPt();
  10332. this.addData(CMD.C, x1, y1, x2, y2, x3, y3);
  10333. if (this._ctx) {
  10334. this._ctx.bezierCurveTo(x1, y1, x2, y2, x3, y3);
  10335. }
  10336. this._xi = x3;
  10337. this._yi = y3;
  10338. return this;
  10339. };
  10340. PathProxy.prototype.quadraticCurveTo = function (x1, y1, x2, y2) {
  10341. this._drawPendingPt();
  10342. this.addData(CMD.Q, x1, y1, x2, y2);
  10343. if (this._ctx) {
  10344. this._ctx.quadraticCurveTo(x1, y1, x2, y2);
  10345. }
  10346. this._xi = x2;
  10347. this._yi = y2;
  10348. return this;
  10349. };
  10350. PathProxy.prototype.arc = function (cx, cy, r, startAngle, endAngle, anticlockwise) {
  10351. this._drawPendingPt();
  10352. tmpAngles[0] = startAngle;
  10353. tmpAngles[1] = endAngle;
  10354. normalizeArcAngles(tmpAngles, anticlockwise);
  10355. startAngle = tmpAngles[0];
  10356. endAngle = tmpAngles[1];
  10357. var delta = endAngle - startAngle;
  10358. this.addData(CMD.A, cx, cy, r, r, startAngle, delta, 0, anticlockwise ? 0 : 1);
  10359. this._ctx && this._ctx.arc(cx, cy, r, startAngle, endAngle, anticlockwise);
  10360. this._xi = mathCos$1(endAngle) * r + cx;
  10361. this._yi = mathSin$1(endAngle) * r + cy;
  10362. return this;
  10363. };
  10364. PathProxy.prototype.arcTo = function (x1, y1, x2, y2, radius) {
  10365. this._drawPendingPt();
  10366. if (this._ctx) {
  10367. this._ctx.arcTo(x1, y1, x2, y2, radius);
  10368. }
  10369. return this;
  10370. };
  10371. PathProxy.prototype.rect = function (x, y, w, h) {
  10372. this._drawPendingPt();
  10373. this._ctx && this._ctx.rect(x, y, w, h);
  10374. this.addData(CMD.R, x, y, w, h);
  10375. return this;
  10376. };
  10377. PathProxy.prototype.closePath = function () {
  10378. this._drawPendingPt();
  10379. this.addData(CMD.Z);
  10380. var ctx = this._ctx;
  10381. var x0 = this._x0;
  10382. var y0 = this._y0;
  10383. if (ctx) {
  10384. ctx.closePath();
  10385. }
  10386. this._xi = x0;
  10387. this._yi = y0;
  10388. return this;
  10389. };
  10390. PathProxy.prototype.fill = function (ctx) {
  10391. ctx && ctx.fill();
  10392. this.toStatic();
  10393. };
  10394. PathProxy.prototype.stroke = function (ctx) {
  10395. ctx && ctx.stroke();
  10396. this.toStatic();
  10397. };
  10398. PathProxy.prototype.len = function () {
  10399. return this._len;
  10400. };
  10401. PathProxy.prototype.setData = function (data) {
  10402. if (!this._saveData) {
  10403. return;
  10404. }
  10405. var len = data.length;
  10406. if (!(this.data && this.data.length === len) && hasTypedArray) {
  10407. this.data = new Float32Array(len);
  10408. }
  10409. for (var i = 0; i < len; i++) {
  10410. this.data[i] = data[i];
  10411. }
  10412. this._len = len;
  10413. };
  10414. PathProxy.prototype.appendPath = function (path) {
  10415. if (!this._saveData) {
  10416. return;
  10417. }
  10418. if (!(path instanceof Array)) {
  10419. path = [path];
  10420. }
  10421. var len = path.length;
  10422. var appendSize = 0;
  10423. var offset = this._len;
  10424. for (var i = 0; i < len; i++) {
  10425. appendSize += path[i].len();
  10426. }
  10427. var oldData = this.data;
  10428. if (hasTypedArray && (oldData instanceof Float32Array || !oldData)) {
  10429. this.data = new Float32Array(offset + appendSize);
  10430. if (offset > 0 && oldData) {
  10431. for (var k = 0; k < offset; k++) {
  10432. this.data[k] = oldData[k];
  10433. }
  10434. }
  10435. }
  10436. for (var i = 0; i < len; i++) {
  10437. var appendPathData = path[i].data;
  10438. for (var k = 0; k < appendPathData.length; k++) {
  10439. this.data[offset++] = appendPathData[k];
  10440. }
  10441. }
  10442. this._len = offset;
  10443. };
  10444. PathProxy.prototype.addData = function (cmd, a, b, c, d, e, f, g, h) {
  10445. if (!this._saveData) {
  10446. return;
  10447. }
  10448. var data = this.data;
  10449. if (this._len + arguments.length > data.length) {
  10450. this._expandData();
  10451. data = this.data;
  10452. }
  10453. for (var i = 0; i < arguments.length; i++) {
  10454. data[this._len++] = arguments[i];
  10455. }
  10456. };
  10457. PathProxy.prototype._drawPendingPt = function () {
  10458. if (this._pendingPtDist > 0) {
  10459. this._ctx && this._ctx.lineTo(this._pendingPtX, this._pendingPtY);
  10460. this._pendingPtDist = 0;
  10461. }
  10462. };
  10463. PathProxy.prototype._expandData = function () {
  10464. if (!(this.data instanceof Array)) {
  10465. var newData = [];
  10466. for (var i = 0; i < this._len; i++) {
  10467. newData[i] = this.data[i];
  10468. }
  10469. this.data = newData;
  10470. }
  10471. };
  10472. PathProxy.prototype.toStatic = function () {
  10473. if (!this._saveData) {
  10474. return;
  10475. }
  10476. this._drawPendingPt();
  10477. var data = this.data;
  10478. if (data instanceof Array) {
  10479. data.length = this._len;
  10480. if (hasTypedArray && this._len > 11) {
  10481. this.data = new Float32Array(data);
  10482. }
  10483. }
  10484. };
  10485. PathProxy.prototype.getBoundingRect = function () {
  10486. min$1[0] = min$1[1] = min2[0] = min2[1] = Number.MAX_VALUE;
  10487. max$1[0] = max$1[1] = max2[0] = max2[1] = -Number.MAX_VALUE;
  10488. var data = this.data;
  10489. var xi = 0;
  10490. var yi = 0;
  10491. var x0 = 0;
  10492. var y0 = 0;
  10493. var i;
  10494. for (i = 0; i < this._len;) {
  10495. var cmd = data[i++];
  10496. var isFirst = i === 1;
  10497. if (isFirst) {
  10498. xi = data[i];
  10499. yi = data[i + 1];
  10500. x0 = xi;
  10501. y0 = yi;
  10502. }
  10503. switch (cmd) {
  10504. case CMD.M:
  10505. xi = x0 = data[i++];
  10506. yi = y0 = data[i++];
  10507. min2[0] = x0;
  10508. min2[1] = y0;
  10509. max2[0] = x0;
  10510. max2[1] = y0;
  10511. break;
  10512. case CMD.L:
  10513. fromLine(xi, yi, data[i], data[i + 1], min2, max2);
  10514. xi = data[i++];
  10515. yi = data[i++];
  10516. break;
  10517. case CMD.C:
  10518. fromCubic(xi, yi, data[i++], data[i++], data[i++], data[i++], data[i], data[i + 1], min2, max2);
  10519. xi = data[i++];
  10520. yi = data[i++];
  10521. break;
  10522. case CMD.Q:
  10523. fromQuadratic(xi, yi, data[i++], data[i++], data[i], data[i + 1], min2, max2);
  10524. xi = data[i++];
  10525. yi = data[i++];
  10526. break;
  10527. case CMD.A:
  10528. var cx = data[i++];
  10529. var cy = data[i++];
  10530. var rx = data[i++];
  10531. var ry = data[i++];
  10532. var startAngle = data[i++];
  10533. var endAngle = data[i++] + startAngle;
  10534. i += 1;
  10535. var anticlockwise = !data[i++];
  10536. if (isFirst) {
  10537. x0 = mathCos$1(startAngle) * rx + cx;
  10538. y0 = mathSin$1(startAngle) * ry + cy;
  10539. }
  10540. fromArc(cx, cy, rx, ry, startAngle, endAngle, anticlockwise, min2, max2);
  10541. xi = mathCos$1(endAngle) * rx + cx;
  10542. yi = mathSin$1(endAngle) * ry + cy;
  10543. break;
  10544. case CMD.R:
  10545. x0 = xi = data[i++];
  10546. y0 = yi = data[i++];
  10547. var width = data[i++];
  10548. var height = data[i++];
  10549. fromLine(x0, y0, x0 + width, y0 + height, min2, max2);
  10550. break;
  10551. case CMD.Z:
  10552. xi = x0;
  10553. yi = y0;
  10554. break;
  10555. }
  10556. min(min$1, min$1, min2);
  10557. max(max$1, max$1, max2);
  10558. }
  10559. if (i === 0) {
  10560. min$1[0] = min$1[1] = max$1[0] = max$1[1] = 0;
  10561. }
  10562. return new BoundingRect(min$1[0], min$1[1], max$1[0] - min$1[0], max$1[1] - min$1[1]);
  10563. };
  10564. PathProxy.prototype._calculateLength = function () {
  10565. var data = this.data;
  10566. var len = this._len;
  10567. var ux = this._ux;
  10568. var uy = this._uy;
  10569. var xi = 0;
  10570. var yi = 0;
  10571. var x0 = 0;
  10572. var y0 = 0;
  10573. if (!this._pathSegLen) {
  10574. this._pathSegLen = [];
  10575. }
  10576. var pathSegLen = this._pathSegLen;
  10577. var pathTotalLen = 0;
  10578. var segCount = 0;
  10579. for (var i = 0; i < len;) {
  10580. var cmd = data[i++];
  10581. var isFirst = i === 1;
  10582. if (isFirst) {
  10583. xi = data[i];
  10584. yi = data[i + 1];
  10585. x0 = xi;
  10586. y0 = yi;
  10587. }
  10588. var l = -1;
  10589. switch (cmd) {
  10590. case CMD.M:
  10591. xi = x0 = data[i++];
  10592. yi = y0 = data[i++];
  10593. break;
  10594. case CMD.L: {
  10595. var x2 = data[i++];
  10596. var y2 = data[i++];
  10597. var dx = x2 - xi;
  10598. var dy = y2 - yi;
  10599. if (mathAbs$2(dx) > ux || mathAbs$2(dy) > uy || i === len - 1) {
  10600. l = Math.sqrt(dx * dx + dy * dy);
  10601. xi = x2;
  10602. yi = y2;
  10603. }
  10604. break;
  10605. }
  10606. case CMD.C: {
  10607. var x1 = data[i++];
  10608. var y1 = data[i++];
  10609. var x2 = data[i++];
  10610. var y2 = data[i++];
  10611. var x3 = data[i++];
  10612. var y3 = data[i++];
  10613. l = cubicLength(xi, yi, x1, y1, x2, y2, x3, y3, 10);
  10614. xi = x3;
  10615. yi = y3;
  10616. break;
  10617. }
  10618. case CMD.Q: {
  10619. var x1 = data[i++];
  10620. var y1 = data[i++];
  10621. var x2 = data[i++];
  10622. var y2 = data[i++];
  10623. l = quadraticLength(xi, yi, x1, y1, x2, y2, 10);
  10624. xi = x2;
  10625. yi = y2;
  10626. break;
  10627. }
  10628. case CMD.A:
  10629. var cx = data[i++];
  10630. var cy = data[i++];
  10631. var rx = data[i++];
  10632. var ry = data[i++];
  10633. var startAngle = data[i++];
  10634. var delta = data[i++];
  10635. var endAngle = delta + startAngle;
  10636. i += 1;
  10637. if (isFirst) {
  10638. x0 = mathCos$1(startAngle) * rx + cx;
  10639. y0 = mathSin$1(startAngle) * ry + cy;
  10640. }
  10641. l = mathMax$3(rx, ry) * mathMin$3(PI2$1, Math.abs(delta));
  10642. xi = mathCos$1(endAngle) * rx + cx;
  10643. yi = mathSin$1(endAngle) * ry + cy;
  10644. break;
  10645. case CMD.R: {
  10646. x0 = xi = data[i++];
  10647. y0 = yi = data[i++];
  10648. var width = data[i++];
  10649. var height = data[i++];
  10650. l = width * 2 + height * 2;
  10651. break;
  10652. }
  10653. case CMD.Z: {
  10654. var dx = x0 - xi;
  10655. var dy = y0 - yi;
  10656. l = Math.sqrt(dx * dx + dy * dy);
  10657. xi = x0;
  10658. yi = y0;
  10659. break;
  10660. }
  10661. }
  10662. if (l >= 0) {
  10663. pathSegLen[segCount++] = l;
  10664. pathTotalLen += l;
  10665. }
  10666. }
  10667. this._pathLen = pathTotalLen;
  10668. return pathTotalLen;
  10669. };
  10670. PathProxy.prototype.rebuildPath = function (ctx, percent) {
  10671. var d = this.data;
  10672. var ux = this._ux;
  10673. var uy = this._uy;
  10674. var len = this._len;
  10675. var x0;
  10676. var y0;
  10677. var xi;
  10678. var yi;
  10679. var x;
  10680. var y;
  10681. var drawPart = percent < 1;
  10682. var pathSegLen;
  10683. var pathTotalLen;
  10684. var accumLength = 0;
  10685. var segCount = 0;
  10686. var displayedLength;
  10687. var pendingPtDist = 0;
  10688. var pendingPtX;
  10689. var pendingPtY;
  10690. if (drawPart) {
  10691. if (!this._pathSegLen) {
  10692. this._calculateLength();
  10693. }
  10694. pathSegLen = this._pathSegLen;
  10695. pathTotalLen = this._pathLen;
  10696. displayedLength = percent * pathTotalLen;
  10697. if (!displayedLength) {
  10698. return;
  10699. }
  10700. }
  10701. lo: for (var i = 0; i < len;) {
  10702. var cmd = d[i++];
  10703. var isFirst = i === 1;
  10704. if (isFirst) {
  10705. xi = d[i];
  10706. yi = d[i + 1];
  10707. x0 = xi;
  10708. y0 = yi;
  10709. }
  10710. if (cmd !== CMD.L && pendingPtDist > 0) {
  10711. ctx.lineTo(pendingPtX, pendingPtY);
  10712. pendingPtDist = 0;
  10713. }
  10714. switch (cmd) {
  10715. case CMD.M:
  10716. x0 = xi = d[i++];
  10717. y0 = yi = d[i++];
  10718. ctx.moveTo(xi, yi);
  10719. break;
  10720. case CMD.L: {
  10721. x = d[i++];
  10722. y = d[i++];
  10723. var dx = mathAbs$2(x - xi);
  10724. var dy = mathAbs$2(y - yi);
  10725. if (dx > ux || dy > uy) {
  10726. if (drawPart) {
  10727. var l = pathSegLen[segCount++];
  10728. if (accumLength + l > displayedLength) {
  10729. var t = (displayedLength - accumLength) / l;
  10730. ctx.lineTo(xi * (1 - t) + x * t, yi * (1 - t) + y * t);
  10731. break lo;
  10732. }
  10733. accumLength += l;
  10734. }
  10735. ctx.lineTo(x, y);
  10736. xi = x;
  10737. yi = y;
  10738. pendingPtDist = 0;
  10739. }
  10740. else {
  10741. var d2 = dx * dx + dy * dy;
  10742. if (d2 > pendingPtDist) {
  10743. pendingPtX = x;
  10744. pendingPtY = y;
  10745. pendingPtDist = d2;
  10746. }
  10747. }
  10748. break;
  10749. }
  10750. case CMD.C: {
  10751. var x1 = d[i++];
  10752. var y1 = d[i++];
  10753. var x2 = d[i++];
  10754. var y2 = d[i++];
  10755. var x3 = d[i++];
  10756. var y3 = d[i++];
  10757. if (drawPart) {
  10758. var l = pathSegLen[segCount++];
  10759. if (accumLength + l > displayedLength) {
  10760. var t = (displayedLength - accumLength) / l;
  10761. cubicSubdivide(xi, x1, x2, x3, t, tmpOutX);
  10762. cubicSubdivide(yi, y1, y2, y3, t, tmpOutY);
  10763. ctx.bezierCurveTo(tmpOutX[1], tmpOutY[1], tmpOutX[2], tmpOutY[2], tmpOutX[3], tmpOutY[3]);
  10764. break lo;
  10765. }
  10766. accumLength += l;
  10767. }
  10768. ctx.bezierCurveTo(x1, y1, x2, y2, x3, y3);
  10769. xi = x3;
  10770. yi = y3;
  10771. break;
  10772. }
  10773. case CMD.Q: {
  10774. var x1 = d[i++];
  10775. var y1 = d[i++];
  10776. var x2 = d[i++];
  10777. var y2 = d[i++];
  10778. if (drawPart) {
  10779. var l = pathSegLen[segCount++];
  10780. if (accumLength + l > displayedLength) {
  10781. var t = (displayedLength - accumLength) / l;
  10782. quadraticSubdivide(xi, x1, x2, t, tmpOutX);
  10783. quadraticSubdivide(yi, y1, y2, t, tmpOutY);
  10784. ctx.quadraticCurveTo(tmpOutX[1], tmpOutY[1], tmpOutX[2], tmpOutY[2]);
  10785. break lo;
  10786. }
  10787. accumLength += l;
  10788. }
  10789. ctx.quadraticCurveTo(x1, y1, x2, y2);
  10790. xi = x2;
  10791. yi = y2;
  10792. break;
  10793. }
  10794. case CMD.A:
  10795. var cx = d[i++];
  10796. var cy = d[i++];
  10797. var rx = d[i++];
  10798. var ry = d[i++];
  10799. var startAngle = d[i++];
  10800. var delta = d[i++];
  10801. var psi = d[i++];
  10802. var anticlockwise = !d[i++];
  10803. var r = (rx > ry) ? rx : ry;
  10804. var isEllipse = mathAbs$2(rx - ry) > 1e-3;
  10805. var endAngle = startAngle + delta;
  10806. var breakBuild = false;
  10807. if (drawPart) {
  10808. var l = pathSegLen[segCount++];
  10809. if (accumLength + l > displayedLength) {
  10810. endAngle = startAngle + delta * (displayedLength - accumLength) / l;
  10811. breakBuild = true;
  10812. }
  10813. accumLength += l;
  10814. }
  10815. if (isEllipse && ctx.ellipse) {
  10816. ctx.ellipse(cx, cy, rx, ry, psi, startAngle, endAngle, anticlockwise);
  10817. }
  10818. else {
  10819. ctx.arc(cx, cy, r, startAngle, endAngle, anticlockwise);
  10820. }
  10821. if (breakBuild) {
  10822. break lo;
  10823. }
  10824. if (isFirst) {
  10825. x0 = mathCos$1(startAngle) * rx + cx;
  10826. y0 = mathSin$1(startAngle) * ry + cy;
  10827. }
  10828. xi = mathCos$1(endAngle) * rx + cx;
  10829. yi = mathSin$1(endAngle) * ry + cy;
  10830. break;
  10831. case CMD.R:
  10832. x0 = xi = d[i];
  10833. y0 = yi = d[i + 1];
  10834. x = d[i++];
  10835. y = d[i++];
  10836. var width = d[i++];
  10837. var height = d[i++];
  10838. if (drawPart) {
  10839. var l = pathSegLen[segCount++];
  10840. if (accumLength + l > displayedLength) {
  10841. var d_1 = displayedLength - accumLength;
  10842. ctx.moveTo(x, y);
  10843. ctx.lineTo(x + mathMin$3(d_1, width), y);
  10844. d_1 -= width;
  10845. if (d_1 > 0) {
  10846. ctx.lineTo(x + width, y + mathMin$3(d_1, height));
  10847. }
  10848. d_1 -= height;
  10849. if (d_1 > 0) {
  10850. ctx.lineTo(x + mathMax$3(width - d_1, 0), y + height);
  10851. }
  10852. d_1 -= width;
  10853. if (d_1 > 0) {
  10854. ctx.lineTo(x, y + mathMax$3(height - d_1, 0));
  10855. }
  10856. break lo;
  10857. }
  10858. accumLength += l;
  10859. }
  10860. ctx.rect(x, y, width, height);
  10861. break;
  10862. case CMD.Z:
  10863. if (drawPart) {
  10864. var l = pathSegLen[segCount++];
  10865. if (accumLength + l > displayedLength) {
  10866. var t = (displayedLength - accumLength) / l;
  10867. ctx.lineTo(xi * (1 - t) + x0 * t, yi * (1 - t) + y0 * t);
  10868. break lo;
  10869. }
  10870. accumLength += l;
  10871. }
  10872. ctx.closePath();
  10873. xi = x0;
  10874. yi = y0;
  10875. }
  10876. }
  10877. };
  10878. PathProxy.prototype.clone = function () {
  10879. var newProxy = new PathProxy();
  10880. var data = this.data;
  10881. newProxy.data = data.slice ? data.slice()
  10882. : Array.prototype.slice.call(data);
  10883. newProxy._len = this._len;
  10884. return newProxy;
  10885. };
  10886. PathProxy.prototype.canSave = function () {
  10887. return !!this._saveData;
  10888. };
  10889. PathProxy.CMD = CMD;
  10890. PathProxy.initDefaultProps = (function () {
  10891. var proto = PathProxy.prototype;
  10892. proto._saveData = true;
  10893. proto._ux = 0;
  10894. proto._uy = 0;
  10895. proto._pendingPtDist = 0;
  10896. proto._version = 0;
  10897. })();
  10898. return PathProxy;
  10899. }());
  10900. function containStroke(x0, y0, x1, y1, lineWidth, x, y) {
  10901. if (lineWidth === 0) {
  10902. return false;
  10903. }
  10904. var _l = lineWidth;
  10905. var _a = 0;
  10906. var _b = x0;
  10907. if ((y > y0 + _l && y > y1 + _l)
  10908. || (y < y0 - _l && y < y1 - _l)
  10909. || (x > x0 + _l && x > x1 + _l)
  10910. || (x < x0 - _l && x < x1 - _l)) {
  10911. return false;
  10912. }
  10913. if (x0 !== x1) {
  10914. _a = (y0 - y1) / (x0 - x1);
  10915. _b = (x0 * y1 - x1 * y0) / (x0 - x1);
  10916. }
  10917. else {
  10918. return Math.abs(x - x0) <= _l / 2;
  10919. }
  10920. var tmp = _a * x - y + _b;
  10921. var _s = tmp * tmp / (_a * _a + 1);
  10922. return _s <= _l / 2 * _l / 2;
  10923. }
  10924. function containStroke$1(x0, y0, x1, y1, x2, y2, x3, y3, lineWidth, x, y) {
  10925. if (lineWidth === 0) {
  10926. return false;
  10927. }
  10928. var _l = lineWidth;
  10929. if ((y > y0 + _l && y > y1 + _l && y > y2 + _l && y > y3 + _l)
  10930. || (y < y0 - _l && y < y1 - _l && y < y2 - _l && y < y3 - _l)
  10931. || (x > x0 + _l && x > x1 + _l && x > x2 + _l && x > x3 + _l)
  10932. || (x < x0 - _l && x < x1 - _l && x < x2 - _l && x < x3 - _l)) {
  10933. return false;
  10934. }
  10935. var d = cubicProjectPoint(x0, y0, x1, y1, x2, y2, x3, y3, x, y, null);
  10936. return d <= _l / 2;
  10937. }
  10938. function containStroke$2(x0, y0, x1, y1, x2, y2, lineWidth, x, y) {
  10939. if (lineWidth === 0) {
  10940. return false;
  10941. }
  10942. var _l = lineWidth;
  10943. if ((y > y0 + _l && y > y1 + _l && y > y2 + _l)
  10944. || (y < y0 - _l && y < y1 - _l && y < y2 - _l)
  10945. || (x > x0 + _l && x > x1 + _l && x > x2 + _l)
  10946. || (x < x0 - _l && x < x1 - _l && x < x2 - _l)) {
  10947. return false;
  10948. }
  10949. var d = quadraticProjectPoint(x0, y0, x1, y1, x2, y2, x, y, null);
  10950. return d <= _l / 2;
  10951. }
  10952. var PI2$2 = Math.PI * 2;
  10953. function normalizeRadian(angle) {
  10954. angle %= PI2$2;
  10955. if (angle < 0) {
  10956. angle += PI2$2;
  10957. }
  10958. return angle;
  10959. }
  10960. var PI2$3 = Math.PI * 2;
  10961. function containStroke$3(cx, cy, r, startAngle, endAngle, anticlockwise, lineWidth, x, y) {
  10962. if (lineWidth === 0) {
  10963. return false;
  10964. }
  10965. var _l = lineWidth;
  10966. x -= cx;
  10967. y -= cy;
  10968. var d = Math.sqrt(x * x + y * y);
  10969. if ((d - _l > r) || (d + _l < r)) {
  10970. return false;
  10971. }
  10972. if (Math.abs(startAngle - endAngle) % PI2$3 < 1e-4) {
  10973. return true;
  10974. }
  10975. if (anticlockwise) {
  10976. var tmp = startAngle;
  10977. startAngle = normalizeRadian(endAngle);
  10978. endAngle = normalizeRadian(tmp);
  10979. }
  10980. else {
  10981. startAngle = normalizeRadian(startAngle);
  10982. endAngle = normalizeRadian(endAngle);
  10983. }
  10984. if (startAngle > endAngle) {
  10985. endAngle += PI2$3;
  10986. }
  10987. var angle = Math.atan2(y, x);
  10988. if (angle < 0) {
  10989. angle += PI2$3;
  10990. }
  10991. return (angle >= startAngle && angle <= endAngle)
  10992. || (angle + PI2$3 >= startAngle && angle + PI2$3 <= endAngle);
  10993. }
  10994. function windingLine(x0, y0, x1, y1, x, y) {
  10995. if ((y > y0 && y > y1) || (y < y0 && y < y1)) {
  10996. return 0;
  10997. }
  10998. if (y1 === y0) {
  10999. return 0;
  11000. }
  11001. var t = (y - y0) / (y1 - y0);
  11002. var dir = y1 < y0 ? 1 : -1;
  11003. if (t === 1 || t === 0) {
  11004. dir = y1 < y0 ? 0.5 : -0.5;
  11005. }
  11006. var x_ = t * (x1 - x0) + x0;
  11007. return x_ === x ? Infinity : x_ > x ? dir : 0;
  11008. }
  11009. var CMD$1 = PathProxy.CMD;
  11010. var PI2$4 = Math.PI * 2;
  11011. var EPSILON$4 = 1e-4;
  11012. function isAroundEqual(a, b) {
  11013. return Math.abs(a - b) < EPSILON$4;
  11014. }
  11015. var roots = [-1, -1, -1];
  11016. var extrema = [-1, -1];
  11017. function swapExtrema() {
  11018. var tmp = extrema[0];
  11019. extrema[0] = extrema[1];
  11020. extrema[1] = tmp;
  11021. }
  11022. function windingCubic(x0, y0, x1, y1, x2, y2, x3, y3, x, y) {
  11023. if ((y > y0 && y > y1 && y > y2 && y > y3)
  11024. || (y < y0 && y < y1 && y < y2 && y < y3)) {
  11025. return 0;
  11026. }
  11027. var nRoots = cubicRootAt(y0, y1, y2, y3, y, roots);
  11028. if (nRoots === 0) {
  11029. return 0;
  11030. }
  11031. else {
  11032. var w = 0;
  11033. var nExtrema = -1;
  11034. var y0_ = void 0;
  11035. var y1_ = void 0;
  11036. for (var i = 0; i < nRoots; i++) {
  11037. var t = roots[i];
  11038. var unit = (t === 0 || t === 1) ? 0.5 : 1;
  11039. var x_ = cubicAt(x0, x1, x2, x3, t);
  11040. if (x_ < x) {
  11041. continue;
  11042. }
  11043. if (nExtrema < 0) {
  11044. nExtrema = cubicExtrema(y0, y1, y2, y3, extrema);
  11045. if (extrema[1] < extrema[0] && nExtrema > 1) {
  11046. swapExtrema();
  11047. }
  11048. y0_ = cubicAt(y0, y1, y2, y3, extrema[0]);
  11049. if (nExtrema > 1) {
  11050. y1_ = cubicAt(y0, y1, y2, y3, extrema[1]);
  11051. }
  11052. }
  11053. if (nExtrema === 2) {
  11054. if (t < extrema[0]) {
  11055. w += y0_ < y0 ? unit : -unit;
  11056. }
  11057. else if (t < extrema[1]) {
  11058. w += y1_ < y0_ ? unit : -unit;
  11059. }
  11060. else {
  11061. w += y3 < y1_ ? unit : -unit;
  11062. }
  11063. }
  11064. else {
  11065. if (t < extrema[0]) {
  11066. w += y0_ < y0 ? unit : -unit;
  11067. }
  11068. else {
  11069. w += y3 < y0_ ? unit : -unit;
  11070. }
  11071. }
  11072. }
  11073. return w;
  11074. }
  11075. }
  11076. function windingQuadratic(x0, y0, x1, y1, x2, y2, x, y) {
  11077. if ((y > y0 && y > y1 && y > y2)
  11078. || (y < y0 && y < y1 && y < y2)) {
  11079. return 0;
  11080. }
  11081. var nRoots = quadraticRootAt(y0, y1, y2, y, roots);
  11082. if (nRoots === 0) {
  11083. return 0;
  11084. }
  11085. else {
  11086. var t = quadraticExtremum(y0, y1, y2);
  11087. if (t >= 0 && t <= 1) {
  11088. var w = 0;
  11089. var y_ = quadraticAt(y0, y1, y2, t);
  11090. for (var i = 0; i < nRoots; i++) {
  11091. var unit = (roots[i] === 0 || roots[i] === 1) ? 0.5 : 1;
  11092. var x_ = quadraticAt(x0, x1, x2, roots[i]);
  11093. if (x_ < x) {
  11094. continue;
  11095. }
  11096. if (roots[i] < t) {
  11097. w += y_ < y0 ? unit : -unit;
  11098. }
  11099. else {
  11100. w += y2 < y_ ? unit : -unit;
  11101. }
  11102. }
  11103. return w;
  11104. }
  11105. else {
  11106. var unit = (roots[0] === 0 || roots[0] === 1) ? 0.5 : 1;
  11107. var x_ = quadraticAt(x0, x1, x2, roots[0]);
  11108. if (x_ < x) {
  11109. return 0;
  11110. }
  11111. return y2 < y0 ? unit : -unit;
  11112. }
  11113. }
  11114. }
  11115. function windingArc(cx, cy, r, startAngle, endAngle, anticlockwise, x, y) {
  11116. y -= cy;
  11117. if (y > r || y < -r) {
  11118. return 0;
  11119. }
  11120. var tmp = Math.sqrt(r * r - y * y);
  11121. roots[0] = -tmp;
  11122. roots[1] = tmp;
  11123. var dTheta = Math.abs(startAngle - endAngle);
  11124. if (dTheta < 1e-4) {
  11125. return 0;
  11126. }
  11127. if (dTheta >= PI2$4 - 1e-4) {
  11128. startAngle = 0;
  11129. endAngle = PI2$4;
  11130. var dir = anticlockwise ? 1 : -1;
  11131. if (x >= roots[0] + cx && x <= roots[1] + cx) {
  11132. return dir;
  11133. }
  11134. else {
  11135. return 0;
  11136. }
  11137. }
  11138. if (startAngle > endAngle) {
  11139. var tmp_1 = startAngle;
  11140. startAngle = endAngle;
  11141. endAngle = tmp_1;
  11142. }
  11143. if (startAngle < 0) {
  11144. startAngle += PI2$4;
  11145. endAngle += PI2$4;
  11146. }
  11147. var w = 0;
  11148. for (var i = 0; i < 2; i++) {
  11149. var x_ = roots[i];
  11150. if (x_ + cx > x) {
  11151. var angle = Math.atan2(y, x_);
  11152. var dir = anticlockwise ? 1 : -1;
  11153. if (angle < 0) {
  11154. angle = PI2$4 + angle;
  11155. }
  11156. if ((angle >= startAngle && angle <= endAngle)
  11157. || (angle + PI2$4 >= startAngle && angle + PI2$4 <= endAngle)) {
  11158. if (angle > Math.PI / 2 && angle < Math.PI * 1.5) {
  11159. dir = -dir;
  11160. }
  11161. w += dir;
  11162. }
  11163. }
  11164. }
  11165. return w;
  11166. }
  11167. function containPath(path, lineWidth, isStroke, x, y) {
  11168. var data = path.data;
  11169. var len = path.len();
  11170. var w = 0;
  11171. var xi = 0;
  11172. var yi = 0;
  11173. var x0 = 0;
  11174. var y0 = 0;
  11175. var x1;
  11176. var y1;
  11177. for (var i = 0; i < len;) {
  11178. var cmd = data[i++];
  11179. var isFirst = i === 1;
  11180. if (cmd === CMD$1.M && i > 1) {
  11181. if (!isStroke) {
  11182. w += windingLine(xi, yi, x0, y0, x, y);
  11183. }
  11184. }
  11185. if (isFirst) {
  11186. xi = data[i];
  11187. yi = data[i + 1];
  11188. x0 = xi;
  11189. y0 = yi;
  11190. }
  11191. switch (cmd) {
  11192. case CMD$1.M:
  11193. x0 = data[i++];
  11194. y0 = data[i++];
  11195. xi = x0;
  11196. yi = y0;
  11197. break;
  11198. case CMD$1.L:
  11199. if (isStroke) {
  11200. if (containStroke(xi, yi, data[i], data[i + 1], lineWidth, x, y)) {
  11201. return true;
  11202. }
  11203. }
  11204. else {
  11205. w += windingLine(xi, yi, data[i], data[i + 1], x, y) || 0;
  11206. }
  11207. xi = data[i++];
  11208. yi = data[i++];
  11209. break;
  11210. case CMD$1.C:
  11211. if (isStroke) {
  11212. if (containStroke$1(xi, yi, data[i++], data[i++], data[i++], data[i++], data[i], data[i + 1], lineWidth, x, y)) {
  11213. return true;
  11214. }
  11215. }
  11216. else {
  11217. w += windingCubic(xi, yi, data[i++], data[i++], data[i++], data[i++], data[i], data[i + 1], x, y) || 0;
  11218. }
  11219. xi = data[i++];
  11220. yi = data[i++];
  11221. break;
  11222. case CMD$1.Q:
  11223. if (isStroke) {
  11224. if (containStroke$2(xi, yi, data[i++], data[i++], data[i], data[i + 1], lineWidth, x, y)) {
  11225. return true;
  11226. }
  11227. }
  11228. else {
  11229. w += windingQuadratic(xi, yi, data[i++], data[i++], data[i], data[i + 1], x, y) || 0;
  11230. }
  11231. xi = data[i++];
  11232. yi = data[i++];
  11233. break;
  11234. case CMD$1.A:
  11235. var cx = data[i++];
  11236. var cy = data[i++];
  11237. var rx = data[i++];
  11238. var ry = data[i++];
  11239. var theta = data[i++];
  11240. var dTheta = data[i++];
  11241. i += 1;
  11242. var anticlockwise = !!(1 - data[i++]);
  11243. x1 = Math.cos(theta) * rx + cx;
  11244. y1 = Math.sin(theta) * ry + cy;
  11245. if (!isFirst) {
  11246. w += windingLine(xi, yi, x1, y1, x, y);
  11247. }
  11248. else {
  11249. x0 = x1;
  11250. y0 = y1;
  11251. }
  11252. var _x = (x - cx) * ry / rx + cx;
  11253. if (isStroke) {
  11254. if (containStroke$3(cx, cy, ry, theta, theta + dTheta, anticlockwise, lineWidth, _x, y)) {
  11255. return true;
  11256. }
  11257. }
  11258. else {
  11259. w += windingArc(cx, cy, ry, theta, theta + dTheta, anticlockwise, _x, y);
  11260. }
  11261. xi = Math.cos(theta + dTheta) * rx + cx;
  11262. yi = Math.sin(theta + dTheta) * ry + cy;
  11263. break;
  11264. case CMD$1.R:
  11265. x0 = xi = data[i++];
  11266. y0 = yi = data[i++];
  11267. var width = data[i++];
  11268. var height = data[i++];
  11269. x1 = x0 + width;
  11270. y1 = y0 + height;
  11271. if (isStroke) {
  11272. if (containStroke(x0, y0, x1, y0, lineWidth, x, y)
  11273. || containStroke(x1, y0, x1, y1, lineWidth, x, y)
  11274. || containStroke(x1, y1, x0, y1, lineWidth, x, y)
  11275. || containStroke(x0, y1, x0, y0, lineWidth, x, y)) {
  11276. return true;
  11277. }
  11278. }
  11279. else {
  11280. w += windingLine(x1, y0, x1, y1, x, y);
  11281. w += windingLine(x0, y1, x0, y0, x, y);
  11282. }
  11283. break;
  11284. case CMD$1.Z:
  11285. if (isStroke) {
  11286. if (containStroke(xi, yi, x0, y0, lineWidth, x, y)) {
  11287. return true;
  11288. }
  11289. }
  11290. else {
  11291. w += windingLine(xi, yi, x0, y0, x, y);
  11292. }
  11293. xi = x0;
  11294. yi = y0;
  11295. break;
  11296. }
  11297. }
  11298. if (!isStroke && !isAroundEqual(yi, y0)) {
  11299. w += windingLine(xi, yi, x0, y0, x, y) || 0;
  11300. }
  11301. return w !== 0;
  11302. }
  11303. function contain(pathProxy, x, y) {
  11304. return containPath(pathProxy, 0, false, x, y);
  11305. }
  11306. function containStroke$4(pathProxy, lineWidth, x, y) {
  11307. return containPath(pathProxy, lineWidth, true, x, y);
  11308. }
  11309. var DEFAULT_PATH_STYLE = defaults({
  11310. fill: '#000',
  11311. stroke: null,
  11312. strokePercent: 1,
  11313. fillOpacity: 1,
  11314. strokeOpacity: 1,
  11315. lineDashOffset: 0,
  11316. lineWidth: 1,
  11317. lineCap: 'butt',
  11318. miterLimit: 10,
  11319. strokeNoScale: false,
  11320. strokeFirst: false
  11321. }, DEFAULT_COMMON_STYLE);
  11322. var DEFAULT_PATH_ANIMATION_PROPS = {
  11323. style: defaults({
  11324. fill: true,
  11325. stroke: true,
  11326. strokePercent: true,
  11327. fillOpacity: true,
  11328. strokeOpacity: true,
  11329. lineDashOffset: true,
  11330. lineWidth: true,
  11331. miterLimit: true
  11332. }, DEFAULT_COMMON_ANIMATION_PROPS.style)
  11333. };
  11334. var pathCopyParams = TRANSFORMABLE_PROPS.concat(['invisible',
  11335. 'culling', 'z', 'z2', 'zlevel', 'parent'
  11336. ]);
  11337. var Path = (function (_super) {
  11338. __extends(Path, _super);
  11339. function Path(opts) {
  11340. return _super.call(this, opts) || this;
  11341. }
  11342. Path.prototype.update = function () {
  11343. var _this = this;
  11344. _super.prototype.update.call(this);
  11345. var style = this.style;
  11346. if (style.decal) {
  11347. var decalEl = this._decalEl = this._decalEl || new Path();
  11348. if (decalEl.buildPath === Path.prototype.buildPath) {
  11349. decalEl.buildPath = function (ctx) {
  11350. _this.buildPath(ctx, _this.shape);
  11351. };
  11352. }
  11353. decalEl.silent = true;
  11354. var decalElStyle = decalEl.style;
  11355. for (var key in style) {
  11356. if (decalElStyle[key] !== style[key]) {
  11357. decalElStyle[key] = style[key];
  11358. }
  11359. }
  11360. decalElStyle.fill = style.fill ? style.decal : null;
  11361. decalElStyle.decal = null;
  11362. decalElStyle.shadowColor = null;
  11363. style.strokeFirst && (decalElStyle.stroke = null);
  11364. for (var i = 0; i < pathCopyParams.length; ++i) {
  11365. decalEl[pathCopyParams[i]] = this[pathCopyParams[i]];
  11366. }
  11367. decalEl.__dirty |= REDRAW_BIT;
  11368. }
  11369. else if (this._decalEl) {
  11370. this._decalEl = null;
  11371. }
  11372. };
  11373. Path.prototype.getDecalElement = function () {
  11374. return this._decalEl;
  11375. };
  11376. Path.prototype._init = function (props) {
  11377. var keysArr = keys(props);
  11378. this.shape = this.getDefaultShape();
  11379. var defaultStyle = this.getDefaultStyle();
  11380. if (defaultStyle) {
  11381. this.useStyle(defaultStyle);
  11382. }
  11383. for (var i = 0; i < keysArr.length; i++) {
  11384. var key = keysArr[i];
  11385. var value = props[key];
  11386. if (key === 'style') {
  11387. if (!this.style) {
  11388. this.useStyle(value);
  11389. }
  11390. else {
  11391. extend(this.style, value);
  11392. }
  11393. }
  11394. else if (key === 'shape') {
  11395. extend(this.shape, value);
  11396. }
  11397. else {
  11398. _super.prototype.attrKV.call(this, key, value);
  11399. }
  11400. }
  11401. if (!this.style) {
  11402. this.useStyle({});
  11403. }
  11404. };
  11405. Path.prototype.getDefaultStyle = function () {
  11406. return null;
  11407. };
  11408. Path.prototype.getDefaultShape = function () {
  11409. return {};
  11410. };
  11411. Path.prototype.canBeInsideText = function () {
  11412. return this.hasFill();
  11413. };
  11414. Path.prototype.getInsideTextFill = function () {
  11415. var pathFill = this.style.fill;
  11416. if (pathFill !== 'none') {
  11417. if (isString(pathFill)) {
  11418. var fillLum = lum(pathFill, 0);
  11419. if (fillLum > 0.5) {
  11420. return DARK_LABEL_COLOR;
  11421. }
  11422. else if (fillLum > 0.2) {
  11423. return LIGHTER_LABEL_COLOR;
  11424. }
  11425. return LIGHT_LABEL_COLOR;
  11426. }
  11427. else if (pathFill) {
  11428. return LIGHT_LABEL_COLOR;
  11429. }
  11430. }
  11431. return DARK_LABEL_COLOR;
  11432. };
  11433. Path.prototype.getInsideTextStroke = function (textFill) {
  11434. var pathFill = this.style.fill;
  11435. if (isString(pathFill)) {
  11436. var zr = this.__zr;
  11437. var isDarkMode = !!(zr && zr.isDarkMode());
  11438. var isDarkLabel = lum(textFill, 0) < DARK_MODE_THRESHOLD;
  11439. if (isDarkMode === isDarkLabel) {
  11440. return pathFill;
  11441. }
  11442. }
  11443. };
  11444. Path.prototype.buildPath = function (ctx, shapeCfg, inBatch) { };
  11445. Path.prototype.pathUpdated = function () {
  11446. this.__dirty &= ~SHAPE_CHANGED_BIT;
  11447. };
  11448. Path.prototype.getUpdatedPathProxy = function (inBatch) {
  11449. !this.path && this.createPathProxy();
  11450. this.path.beginPath();
  11451. this.buildPath(this.path, this.shape, inBatch);
  11452. return this.path;
  11453. };
  11454. Path.prototype.createPathProxy = function () {
  11455. this.path = new PathProxy(false);
  11456. };
  11457. Path.prototype.hasStroke = function () {
  11458. var style = this.style;
  11459. var stroke = style.stroke;
  11460. return !(stroke == null || stroke === 'none' || !(style.lineWidth > 0));
  11461. };
  11462. Path.prototype.hasFill = function () {
  11463. var style = this.style;
  11464. var fill = style.fill;
  11465. return fill != null && fill !== 'none';
  11466. };
  11467. Path.prototype.getBoundingRect = function () {
  11468. var rect = this._rect;
  11469. var style = this.style;
  11470. var needsUpdateRect = !rect;
  11471. if (needsUpdateRect) {
  11472. var firstInvoke = false;
  11473. if (!this.path) {
  11474. firstInvoke = true;
  11475. this.createPathProxy();
  11476. }
  11477. var path = this.path;
  11478. if (firstInvoke || (this.__dirty & SHAPE_CHANGED_BIT)) {
  11479. path.beginPath();
  11480. this.buildPath(path, this.shape, false);
  11481. this.pathUpdated();
  11482. }
  11483. rect = path.getBoundingRect();
  11484. }
  11485. this._rect = rect;
  11486. if (this.hasStroke() && this.path && this.path.len() > 0) {
  11487. var rectStroke = this._rectStroke || (this._rectStroke = rect.clone());
  11488. if (this.__dirty || needsUpdateRect) {
  11489. rectStroke.copy(rect);
  11490. var lineScale = style.strokeNoScale ? this.getLineScale() : 1;
  11491. var w = style.lineWidth;
  11492. if (!this.hasFill()) {
  11493. var strokeContainThreshold = this.strokeContainThreshold;
  11494. w = Math.max(w, strokeContainThreshold == null ? 4 : strokeContainThreshold);
  11495. }
  11496. if (lineScale > 1e-10) {
  11497. rectStroke.width += w / lineScale;
  11498. rectStroke.height += w / lineScale;
  11499. rectStroke.x -= w / lineScale / 2;
  11500. rectStroke.y -= w / lineScale / 2;
  11501. }
  11502. }
  11503. return rectStroke;
  11504. }
  11505. return rect;
  11506. };
  11507. Path.prototype.contain = function (x, y) {
  11508. var localPos = this.transformCoordToLocal(x, y);
  11509. var rect = this.getBoundingRect();
  11510. var style = this.style;
  11511. x = localPos[0];
  11512. y = localPos[1];
  11513. if (rect.contain(x, y)) {
  11514. var pathProxy = this.path;
  11515. if (this.hasStroke()) {
  11516. var lineWidth = style.lineWidth;
  11517. var lineScale = style.strokeNoScale ? this.getLineScale() : 1;
  11518. if (lineScale > 1e-10) {
  11519. if (!this.hasFill()) {
  11520. lineWidth = Math.max(lineWidth, this.strokeContainThreshold);
  11521. }
  11522. if (containStroke$4(pathProxy, lineWidth / lineScale, x, y)) {
  11523. return true;
  11524. }
  11525. }
  11526. }
  11527. if (this.hasFill()) {
  11528. return contain(pathProxy, x, y);
  11529. }
  11530. }
  11531. return false;
  11532. };
  11533. Path.prototype.dirtyShape = function () {
  11534. this.__dirty |= SHAPE_CHANGED_BIT;
  11535. if (this._rect) {
  11536. this._rect = null;
  11537. }
  11538. if (this._decalEl) {
  11539. this._decalEl.dirtyShape();
  11540. }
  11541. this.markRedraw();
  11542. };
  11543. Path.prototype.dirty = function () {
  11544. this.dirtyStyle();
  11545. this.dirtyShape();
  11546. };
  11547. Path.prototype.animateShape = function (loop) {
  11548. return this.animate('shape', loop);
  11549. };
  11550. Path.prototype.updateDuringAnimation = function (targetKey) {
  11551. if (targetKey === 'style') {
  11552. this.dirtyStyle();
  11553. }
  11554. else if (targetKey === 'shape') {
  11555. this.dirtyShape();
  11556. }
  11557. else {
  11558. this.markRedraw();
  11559. }
  11560. };
  11561. Path.prototype.attrKV = function (key, value) {
  11562. if (key === 'shape') {
  11563. this.setShape(value);
  11564. }
  11565. else {
  11566. _super.prototype.attrKV.call(this, key, value);
  11567. }
  11568. };
  11569. Path.prototype.setShape = function (keyOrObj, value) {
  11570. var shape = this.shape;
  11571. if (!shape) {
  11572. shape = this.shape = {};
  11573. }
  11574. if (typeof keyOrObj === 'string') {
  11575. shape[keyOrObj] = value;
  11576. }
  11577. else {
  11578. extend(shape, keyOrObj);
  11579. }
  11580. this.dirtyShape();
  11581. return this;
  11582. };
  11583. Path.prototype.shapeChanged = function () {
  11584. return !!(this.__dirty & SHAPE_CHANGED_BIT);
  11585. };
  11586. Path.prototype.createStyle = function (obj) {
  11587. return createObject(DEFAULT_PATH_STYLE, obj);
  11588. };
  11589. Path.prototype._innerSaveToNormal = function (toState) {
  11590. _super.prototype._innerSaveToNormal.call(this, toState);
  11591. var normalState = this._normalState;
  11592. if (toState.shape && !normalState.shape) {
  11593. normalState.shape = extend({}, this.shape);
  11594. }
  11595. };
  11596. Path.prototype._applyStateObj = function (stateName, state, normalState, keepCurrentStates, transition, animationCfg) {
  11597. _super.prototype._applyStateObj.call(this, stateName, state, normalState, keepCurrentStates, transition, animationCfg);
  11598. var needsRestoreToNormal = !(state && keepCurrentStates);
  11599. var targetShape;
  11600. if (state && state.shape) {
  11601. if (transition) {
  11602. if (keepCurrentStates) {
  11603. targetShape = state.shape;
  11604. }
  11605. else {
  11606. targetShape = extend({}, normalState.shape);
  11607. extend(targetShape, state.shape);
  11608. }
  11609. }
  11610. else {
  11611. targetShape = extend({}, keepCurrentStates ? this.shape : normalState.shape);
  11612. extend(targetShape, state.shape);
  11613. }
  11614. }
  11615. else if (needsRestoreToNormal) {
  11616. targetShape = normalState.shape;
  11617. }
  11618. if (targetShape) {
  11619. if (transition) {
  11620. this.shape = extend({}, this.shape);
  11621. var targetShapePrimaryProps = {};
  11622. var shapeKeys = keys(targetShape);
  11623. for (var i = 0; i < shapeKeys.length; i++) {
  11624. var key = shapeKeys[i];
  11625. if (typeof targetShape[key] === 'object') {
  11626. this.shape[key] = targetShape[key];
  11627. }
  11628. else {
  11629. targetShapePrimaryProps[key] = targetShape[key];
  11630. }
  11631. }
  11632. this._transitionState(stateName, {
  11633. shape: targetShapePrimaryProps
  11634. }, animationCfg);
  11635. }
  11636. else {
  11637. this.shape = targetShape;
  11638. this.dirtyShape();
  11639. }
  11640. }
  11641. };
  11642. Path.prototype._mergeStates = function (states) {
  11643. var mergedState = _super.prototype._mergeStates.call(this, states);
  11644. var mergedShape;
  11645. for (var i = 0; i < states.length; i++) {
  11646. var state = states[i];
  11647. if (state.shape) {
  11648. mergedShape = mergedShape || {};
  11649. this._mergeStyle(mergedShape, state.shape);
  11650. }
  11651. }
  11652. if (mergedShape) {
  11653. mergedState.shape = mergedShape;
  11654. }
  11655. return mergedState;
  11656. };
  11657. Path.prototype.getAnimationStyleProps = function () {
  11658. return DEFAULT_PATH_ANIMATION_PROPS;
  11659. };
  11660. Path.prototype.isZeroArea = function () {
  11661. return false;
  11662. };
  11663. Path.extend = function (defaultProps) {
  11664. var Sub = (function (_super) {
  11665. __extends(Sub, _super);
  11666. function Sub(opts) {
  11667. var _this = _super.call(this, opts) || this;
  11668. defaultProps.init && defaultProps.init.call(_this, opts);
  11669. return _this;
  11670. }
  11671. Sub.prototype.getDefaultStyle = function () {
  11672. return clone(defaultProps.style);
  11673. };
  11674. Sub.prototype.getDefaultShape = function () {
  11675. return clone(defaultProps.shape);
  11676. };
  11677. return Sub;
  11678. }(Path));
  11679. for (var key in defaultProps) {
  11680. if (typeof defaultProps[key] === 'function') {
  11681. Sub.prototype[key] = defaultProps[key];
  11682. }
  11683. }
  11684. return Sub;
  11685. };
  11686. Path.initDefaultProps = (function () {
  11687. var pathProto = Path.prototype;
  11688. pathProto.type = 'path';
  11689. pathProto.strokeContainThreshold = 5;
  11690. pathProto.segmentIgnoreThreshold = 0;
  11691. pathProto.subPixelOptimize = false;
  11692. pathProto.autoBatch = false;
  11693. pathProto.__dirty = REDRAW_BIT | STYLE_CHANGED_BIT | SHAPE_CHANGED_BIT;
  11694. })();
  11695. return Path;
  11696. }(Displayable));
  11697. var DEFAULT_TSPAN_STYLE = defaults({
  11698. strokeFirst: true,
  11699. font: DEFAULT_FONT,
  11700. x: 0,
  11701. y: 0,
  11702. textAlign: 'left',
  11703. textBaseline: 'top',
  11704. miterLimit: 2
  11705. }, DEFAULT_PATH_STYLE);
  11706. var TSpan = (function (_super) {
  11707. __extends(TSpan, _super);
  11708. function TSpan() {
  11709. return _super !== null && _super.apply(this, arguments) || this;
  11710. }
  11711. TSpan.prototype.hasStroke = function () {
  11712. return tSpanHasStroke(this.style);
  11713. };
  11714. TSpan.prototype.hasFill = function () {
  11715. var style = this.style;
  11716. var fill = style.fill;
  11717. return fill != null && fill !== 'none';
  11718. };
  11719. TSpan.prototype.createStyle = function (obj) {
  11720. return createObject(DEFAULT_TSPAN_STYLE, obj);
  11721. };
  11722. TSpan.prototype.setBoundingRect = function (rect) {
  11723. this._rect = rect;
  11724. };
  11725. TSpan.prototype.getBoundingRect = function () {
  11726. if (!this._rect) {
  11727. this._rect = tSpanCreateBoundingRect(this.style);
  11728. }
  11729. return this._rect;
  11730. };
  11731. TSpan.initDefaultProps = (function () {
  11732. var tspanProto = TSpan.prototype;
  11733. tspanProto.dirtyRectTolerance = 10;
  11734. })();
  11735. return TSpan;
  11736. }(Displayable));
  11737. TSpan.prototype.type = 'tspan';
  11738. var DEFAULT_IMAGE_STYLE = defaults({
  11739. x: 0,
  11740. y: 0
  11741. }, DEFAULT_COMMON_STYLE);
  11742. var DEFAULT_IMAGE_ANIMATION_PROPS = {
  11743. style: defaults({
  11744. x: true,
  11745. y: true,
  11746. width: true,
  11747. height: true,
  11748. sx: true,
  11749. sy: true,
  11750. sWidth: true,
  11751. sHeight: true
  11752. }, DEFAULT_COMMON_ANIMATION_PROPS.style)
  11753. };
  11754. function isImageLike(source) {
  11755. return !!(source
  11756. && typeof source !== 'string'
  11757. && source.width && source.height);
  11758. }
  11759. var ZRImage = (function (_super) {
  11760. __extends(ZRImage, _super);
  11761. function ZRImage() {
  11762. return _super !== null && _super.apply(this, arguments) || this;
  11763. }
  11764. ZRImage.prototype.createStyle = function (obj) {
  11765. return createObject(DEFAULT_IMAGE_STYLE, obj);
  11766. };
  11767. ZRImage.prototype._getSize = function (dim) {
  11768. var style = this.style;
  11769. var size = style[dim];
  11770. if (size != null) {
  11771. return size;
  11772. }
  11773. var imageSource = isImageLike(style.image)
  11774. ? style.image : this.__image;
  11775. if (!imageSource) {
  11776. return 0;
  11777. }
  11778. var otherDim = dim === 'width' ? 'height' : 'width';
  11779. var otherDimSize = style[otherDim];
  11780. if (otherDimSize == null) {
  11781. return imageSource[dim];
  11782. }
  11783. else {
  11784. return imageSource[dim] / imageSource[otherDim] * otherDimSize;
  11785. }
  11786. };
  11787. ZRImage.prototype.getWidth = function () {
  11788. return this._getSize('width');
  11789. };
  11790. ZRImage.prototype.getHeight = function () {
  11791. return this._getSize('height');
  11792. };
  11793. ZRImage.prototype.getAnimationStyleProps = function () {
  11794. return DEFAULT_IMAGE_ANIMATION_PROPS;
  11795. };
  11796. ZRImage.prototype.getBoundingRect = function () {
  11797. var style = this.style;
  11798. if (!this._rect) {
  11799. this._rect = new BoundingRect(style.x || 0, style.y || 0, this.getWidth(), this.getHeight());
  11800. }
  11801. return this._rect;
  11802. };
  11803. return ZRImage;
  11804. }(Displayable));
  11805. ZRImage.prototype.type = 'image';
  11806. function buildPath(ctx, shape) {
  11807. var x = shape.x;
  11808. var y = shape.y;
  11809. var width = shape.width;
  11810. var height = shape.height;
  11811. var r = shape.r;
  11812. var r1;
  11813. var r2;
  11814. var r3;
  11815. var r4;
  11816. if (width < 0) {
  11817. x = x + width;
  11818. width = -width;
  11819. }
  11820. if (height < 0) {
  11821. y = y + height;
  11822. height = -height;
  11823. }
  11824. if (typeof r === 'number') {
  11825. r1 = r2 = r3 = r4 = r;
  11826. }
  11827. else if (r instanceof Array) {
  11828. if (r.length === 1) {
  11829. r1 = r2 = r3 = r4 = r[0];
  11830. }
  11831. else if (r.length === 2) {
  11832. r1 = r3 = r[0];
  11833. r2 = r4 = r[1];
  11834. }
  11835. else if (r.length === 3) {
  11836. r1 = r[0];
  11837. r2 = r4 = r[1];
  11838. r3 = r[2];
  11839. }
  11840. else {
  11841. r1 = r[0];
  11842. r2 = r[1];
  11843. r3 = r[2];
  11844. r4 = r[3];
  11845. }
  11846. }
  11847. else {
  11848. r1 = r2 = r3 = r4 = 0;
  11849. }
  11850. var total;
  11851. if (r1 + r2 > width) {
  11852. total = r1 + r2;
  11853. r1 *= width / total;
  11854. r2 *= width / total;
  11855. }
  11856. if (r3 + r4 > width) {
  11857. total = r3 + r4;
  11858. r3 *= width / total;
  11859. r4 *= width / total;
  11860. }
  11861. if (r2 + r3 > height) {
  11862. total = r2 + r3;
  11863. r2 *= height / total;
  11864. r3 *= height / total;
  11865. }
  11866. if (r1 + r4 > height) {
  11867. total = r1 + r4;
  11868. r1 *= height / total;
  11869. r4 *= height / total;
  11870. }
  11871. ctx.moveTo(x + r1, y);
  11872. ctx.lineTo(x + width - r2, y);
  11873. r2 !== 0 && ctx.arc(x + width - r2, y + r2, r2, -Math.PI / 2, 0);
  11874. ctx.lineTo(x + width, y + height - r3);
  11875. r3 !== 0 && ctx.arc(x + width - r3, y + height - r3, r3, 0, Math.PI / 2);
  11876. ctx.lineTo(x + r4, y + height);
  11877. r4 !== 0 && ctx.arc(x + r4, y + height - r4, r4, Math.PI / 2, Math.PI);
  11878. ctx.lineTo(x, y + r1);
  11879. r1 !== 0 && ctx.arc(x + r1, y + r1, r1, Math.PI, Math.PI * 1.5);
  11880. }
  11881. var round$1 = Math.round;
  11882. function subPixelOptimizeLine(outputShape, inputShape, style) {
  11883. if (!inputShape) {
  11884. return;
  11885. }
  11886. var x1 = inputShape.x1;
  11887. var x2 = inputShape.x2;
  11888. var y1 = inputShape.y1;
  11889. var y2 = inputShape.y2;
  11890. outputShape.x1 = x1;
  11891. outputShape.x2 = x2;
  11892. outputShape.y1 = y1;
  11893. outputShape.y2 = y2;
  11894. var lineWidth = style && style.lineWidth;
  11895. if (!lineWidth) {
  11896. return outputShape;
  11897. }
  11898. if (round$1(x1 * 2) === round$1(x2 * 2)) {
  11899. outputShape.x1 = outputShape.x2 = subPixelOptimize(x1, lineWidth, true);
  11900. }
  11901. if (round$1(y1 * 2) === round$1(y2 * 2)) {
  11902. outputShape.y1 = outputShape.y2 = subPixelOptimize(y1, lineWidth, true);
  11903. }
  11904. return outputShape;
  11905. }
  11906. function subPixelOptimizeRect(outputShape, inputShape, style) {
  11907. if (!inputShape) {
  11908. return;
  11909. }
  11910. var originX = inputShape.x;
  11911. var originY = inputShape.y;
  11912. var originWidth = inputShape.width;
  11913. var originHeight = inputShape.height;
  11914. outputShape.x = originX;
  11915. outputShape.y = originY;
  11916. outputShape.width = originWidth;
  11917. outputShape.height = originHeight;
  11918. var lineWidth = style && style.lineWidth;
  11919. if (!lineWidth) {
  11920. return outputShape;
  11921. }
  11922. outputShape.x = subPixelOptimize(originX, lineWidth, true);
  11923. outputShape.y = subPixelOptimize(originY, lineWidth, true);
  11924. outputShape.width = Math.max(subPixelOptimize(originX + originWidth, lineWidth, false) - outputShape.x, originWidth === 0 ? 0 : 1);
  11925. outputShape.height = Math.max(subPixelOptimize(originY + originHeight, lineWidth, false) - outputShape.y, originHeight === 0 ? 0 : 1);
  11926. return outputShape;
  11927. }
  11928. function subPixelOptimize(position, lineWidth, positiveOrNegative) {
  11929. if (!lineWidth) {
  11930. return position;
  11931. }
  11932. var doubledPosition = round$1(position * 2);
  11933. return (doubledPosition + round$1(lineWidth)) % 2 === 0
  11934. ? doubledPosition / 2
  11935. : (doubledPosition + (positiveOrNegative ? 1 : -1)) / 2;
  11936. }
  11937. var RectShape = (function () {
  11938. function RectShape() {
  11939. this.x = 0;
  11940. this.y = 0;
  11941. this.width = 0;
  11942. this.height = 0;
  11943. }
  11944. return RectShape;
  11945. }());
  11946. var subPixelOptimizeOutputShape = {};
  11947. var Rect = (function (_super) {
  11948. __extends(Rect, _super);
  11949. function Rect(opts) {
  11950. return _super.call(this, opts) || this;
  11951. }
  11952. Rect.prototype.getDefaultShape = function () {
  11953. return new RectShape();
  11954. };
  11955. Rect.prototype.buildPath = function (ctx, shape) {
  11956. var x;
  11957. var y;
  11958. var width;
  11959. var height;
  11960. if (this.subPixelOptimize) {
  11961. var optimizedShape = subPixelOptimizeRect(subPixelOptimizeOutputShape, shape, this.style);
  11962. x = optimizedShape.x;
  11963. y = optimizedShape.y;
  11964. width = optimizedShape.width;
  11965. height = optimizedShape.height;
  11966. optimizedShape.r = shape.r;
  11967. shape = optimizedShape;
  11968. }
  11969. else {
  11970. x = shape.x;
  11971. y = shape.y;
  11972. width = shape.width;
  11973. height = shape.height;
  11974. }
  11975. if (!shape.r) {
  11976. ctx.rect(x, y, width, height);
  11977. }
  11978. else {
  11979. buildPath(ctx, shape);
  11980. }
  11981. };
  11982. Rect.prototype.isZeroArea = function () {
  11983. return !this.shape.width || !this.shape.height;
  11984. };
  11985. return Rect;
  11986. }(Path));
  11987. Rect.prototype.type = 'rect';
  11988. var DEFAULT_RICH_TEXT_COLOR = {
  11989. fill: '#000'
  11990. };
  11991. var DEFAULT_STROKE_LINE_WIDTH = 2;
  11992. var tmpCITOverflowAreaOut = {};
  11993. var DEFAULT_TEXT_ANIMATION_PROPS = {
  11994. style: defaults({
  11995. fill: true,
  11996. stroke: true,
  11997. fillOpacity: true,
  11998. strokeOpacity: true,
  11999. lineWidth: true,
  12000. fontSize: true,
  12001. lineHeight: true,
  12002. width: true,
  12003. height: true,
  12004. textShadowColor: true,
  12005. textShadowBlur: true,
  12006. textShadowOffsetX: true,
  12007. textShadowOffsetY: true,
  12008. backgroundColor: true,
  12009. padding: true,
  12010. borderColor: true,
  12011. borderWidth: true,
  12012. borderRadius: true
  12013. }, DEFAULT_COMMON_ANIMATION_PROPS.style)
  12014. };
  12015. var ZRText = (function (_super) {
  12016. __extends(ZRText, _super);
  12017. function ZRText(opts) {
  12018. var _this = _super.call(this) || this;
  12019. _this.type = 'text';
  12020. _this._children = [];
  12021. _this._defaultStyle = DEFAULT_RICH_TEXT_COLOR;
  12022. _this.attr(opts);
  12023. return _this;
  12024. }
  12025. ZRText.prototype.childrenRef = function () {
  12026. return this._children;
  12027. };
  12028. ZRText.prototype.update = function () {
  12029. _super.prototype.update.call(this);
  12030. if (this.styleChanged()) {
  12031. this._updateSubTexts();
  12032. }
  12033. for (var i = 0; i < this._children.length; i++) {
  12034. var child = this._children[i];
  12035. child.zlevel = this.zlevel;
  12036. child.z = this.z;
  12037. child.z2 = this.z2;
  12038. child.culling = this.culling;
  12039. child.cursor = this.cursor;
  12040. child.invisible = this.invisible;
  12041. }
  12042. };
  12043. ZRText.prototype.updateTransform = function () {
  12044. var innerTransformable = this.innerTransformable;
  12045. if (innerTransformable) {
  12046. innerTransformable.updateTransform();
  12047. if (innerTransformable.transform) {
  12048. this.transform = innerTransformable.transform;
  12049. }
  12050. }
  12051. else {
  12052. _super.prototype.updateTransform.call(this);
  12053. }
  12054. };
  12055. ZRText.prototype.getLocalTransform = function (m) {
  12056. var innerTransformable = this.innerTransformable;
  12057. return innerTransformable
  12058. ? innerTransformable.getLocalTransform(m)
  12059. : _super.prototype.getLocalTransform.call(this, m);
  12060. };
  12061. ZRText.prototype.getComputedTransform = function () {
  12062. if (this.__hostTarget) {
  12063. this.__hostTarget.getComputedTransform();
  12064. this.__hostTarget.updateInnerText(true);
  12065. }
  12066. return _super.prototype.getComputedTransform.call(this);
  12067. };
  12068. ZRText.prototype._updateSubTexts = function () {
  12069. this._childCursor = 0;
  12070. normalizeTextStyle(this.style);
  12071. this.style.rich
  12072. ? this._updateRichTexts()
  12073. : this._updatePlainTexts();
  12074. this._children.length = this._childCursor;
  12075. this.styleUpdated();
  12076. };
  12077. ZRText.prototype.addSelfToZr = function (zr) {
  12078. _super.prototype.addSelfToZr.call(this, zr);
  12079. for (var i = 0; i < this._children.length; i++) {
  12080. this._children[i].__zr = zr;
  12081. }
  12082. };
  12083. ZRText.prototype.removeSelfFromZr = function (zr) {
  12084. _super.prototype.removeSelfFromZr.call(this, zr);
  12085. for (var i = 0; i < this._children.length; i++) {
  12086. this._children[i].__zr = null;
  12087. }
  12088. };
  12089. ZRText.prototype.getBoundingRect = function () {
  12090. if (this.styleChanged()) {
  12091. this._updateSubTexts();
  12092. }
  12093. if (!this._rect) {
  12094. var tmpRect = new BoundingRect(0, 0, 0, 0);
  12095. var children = this._children;
  12096. var tmpMat = [];
  12097. var rect = null;
  12098. for (var i = 0; i < children.length; i++) {
  12099. var child = children[i];
  12100. var childRect = child.getBoundingRect();
  12101. var transform = child.getLocalTransform(tmpMat);
  12102. if (transform) {
  12103. tmpRect.copy(childRect);
  12104. tmpRect.applyTransform(transform);
  12105. rect = rect || tmpRect.clone();
  12106. rect.union(tmpRect);
  12107. }
  12108. else {
  12109. rect = rect || childRect.clone();
  12110. rect.union(childRect);
  12111. }
  12112. }
  12113. this._rect = rect || tmpRect;
  12114. }
  12115. return this._rect;
  12116. };
  12117. ZRText.prototype.setDefaultTextStyle = function (defaultTextStyle) {
  12118. this._defaultStyle = defaultTextStyle || DEFAULT_RICH_TEXT_COLOR;
  12119. };
  12120. ZRText.prototype.setTextContent = function (textContent) {
  12121. if ("development" !== 'production') {
  12122. throw new Error('Can\'t attach text on another text');
  12123. }
  12124. };
  12125. ZRText.prototype._mergeStyle = function (targetStyle, sourceStyle) {
  12126. if (!sourceStyle) {
  12127. return targetStyle;
  12128. }
  12129. var sourceRich = sourceStyle.rich;
  12130. var targetRich = targetStyle.rich || (sourceRich && {});
  12131. extend(targetStyle, sourceStyle);
  12132. if (sourceRich && targetRich) {
  12133. this._mergeRich(targetRich, sourceRich);
  12134. targetStyle.rich = targetRich;
  12135. }
  12136. else if (targetRich) {
  12137. targetStyle.rich = targetRich;
  12138. }
  12139. return targetStyle;
  12140. };
  12141. ZRText.prototype._mergeRich = function (targetRich, sourceRich) {
  12142. var richNames = keys(sourceRich);
  12143. for (var i = 0; i < richNames.length; i++) {
  12144. var richName = richNames[i];
  12145. targetRich[richName] = targetRich[richName] || {};
  12146. extend(targetRich[richName], sourceRich[richName]);
  12147. }
  12148. };
  12149. ZRText.prototype.getAnimationStyleProps = function () {
  12150. return DEFAULT_TEXT_ANIMATION_PROPS;
  12151. };
  12152. ZRText.prototype._getOrCreateChild = function (Ctor) {
  12153. var child = this._children[this._childCursor];
  12154. if (!child || !(child instanceof Ctor)) {
  12155. child = new Ctor();
  12156. }
  12157. this._children[this._childCursor++] = child;
  12158. child.__zr = this.__zr;
  12159. child.parent = this;
  12160. return child;
  12161. };
  12162. ZRText.prototype._updatePlainTexts = function () {
  12163. var style = this.style;
  12164. var textFont = style.font || DEFAULT_FONT;
  12165. var textPadding = style.padding;
  12166. var defaultStyle = this._defaultStyle;
  12167. var baseX = style.x || 0;
  12168. var baseY = style.y || 0;
  12169. var textAlign = style.align || defaultStyle.align || 'left';
  12170. var verticalAlign = style.verticalAlign || defaultStyle.verticalAlign || 'top';
  12171. calcInnerTextOverflowArea(tmpCITOverflowAreaOut, defaultStyle.overflowRect, baseX, baseY, textAlign, verticalAlign);
  12172. baseX = tmpCITOverflowAreaOut.baseX;
  12173. baseY = tmpCITOverflowAreaOut.baseY;
  12174. var text = getStyleText(style);
  12175. var contentBlock = parsePlainText(text, style, tmpCITOverflowAreaOut.outerWidth, tmpCITOverflowAreaOut.outerHeight);
  12176. var needDrawBg = needDrawBackground(style);
  12177. var bgColorDrawn = !!(style.backgroundColor);
  12178. var outerHeight = contentBlock.outerHeight;
  12179. var outerWidth = contentBlock.outerWidth;
  12180. var textLines = contentBlock.lines;
  12181. var lineHeight = contentBlock.lineHeight;
  12182. this.isTruncated = !!contentBlock.isTruncated;
  12183. var textX = baseX;
  12184. var textY = adjustTextY$1(baseY, contentBlock.contentHeight, verticalAlign);
  12185. if (needDrawBg || textPadding) {
  12186. var boxX = adjustTextX(baseX, outerWidth, textAlign);
  12187. var boxY = adjustTextY$1(baseY, outerHeight, verticalAlign);
  12188. needDrawBg && this._renderBackground(style, style, boxX, boxY, outerWidth, outerHeight);
  12189. }
  12190. textY += lineHeight / 2;
  12191. if (textPadding) {
  12192. textX = getTextXForPadding(baseX, textAlign, textPadding);
  12193. if (verticalAlign === 'top') {
  12194. textY += textPadding[0];
  12195. }
  12196. else if (verticalAlign === 'bottom') {
  12197. textY -= textPadding[2];
  12198. }
  12199. }
  12200. var defaultLineWidth = 0;
  12201. var usingDefaultStroke = false;
  12202. var useDefaultFill = false;
  12203. var textFill = getFill('fill' in style
  12204. ? style.fill
  12205. : (useDefaultFill = true, defaultStyle.fill));
  12206. var textStroke = getStroke('stroke' in style
  12207. ? style.stroke
  12208. : (!bgColorDrawn
  12209. && (!defaultStyle.autoStroke || useDefaultFill))
  12210. ? (defaultLineWidth = DEFAULT_STROKE_LINE_WIDTH, usingDefaultStroke = true, defaultStyle.stroke)
  12211. : null);
  12212. var hasShadow = style.textShadowBlur > 0;
  12213. for (var i = 0; i < textLines.length; i++) {
  12214. var el = this._getOrCreateChild(TSpan);
  12215. var subElStyle = el.createStyle();
  12216. el.useStyle(subElStyle);
  12217. subElStyle.text = textLines[i];
  12218. subElStyle.x = textX;
  12219. subElStyle.y = textY;
  12220. if (textAlign) {
  12221. subElStyle.textAlign = textAlign;
  12222. }
  12223. subElStyle.textBaseline = 'middle';
  12224. subElStyle.opacity = style.opacity;
  12225. subElStyle.strokeFirst = true;
  12226. if (hasShadow) {
  12227. subElStyle.shadowBlur = style.textShadowBlur || 0;
  12228. subElStyle.shadowColor = style.textShadowColor || 'transparent';
  12229. subElStyle.shadowOffsetX = style.textShadowOffsetX || 0;
  12230. subElStyle.shadowOffsetY = style.textShadowOffsetY || 0;
  12231. }
  12232. subElStyle.stroke = textStroke;
  12233. subElStyle.fill = textFill;
  12234. if (textStroke) {
  12235. subElStyle.lineWidth = style.lineWidth || defaultLineWidth;
  12236. subElStyle.lineDash = style.lineDash;
  12237. subElStyle.lineDashOffset = style.lineDashOffset || 0;
  12238. }
  12239. subElStyle.font = textFont;
  12240. setSeparateFont(subElStyle, style);
  12241. textY += lineHeight;
  12242. el.setBoundingRect(tSpanCreateBoundingRect2(subElStyle, contentBlock.contentWidth, contentBlock.calculatedLineHeight, usingDefaultStroke ? 0 : null));
  12243. }
  12244. };
  12245. ZRText.prototype._updateRichTexts = function () {
  12246. var style = this.style;
  12247. var defaultStyle = this._defaultStyle;
  12248. var textAlign = style.align || defaultStyle.align;
  12249. var verticalAlign = style.verticalAlign || defaultStyle.verticalAlign;
  12250. var baseX = style.x || 0;
  12251. var baseY = style.y || 0;
  12252. calcInnerTextOverflowArea(tmpCITOverflowAreaOut, defaultStyle.overflowRect, baseX, baseY, textAlign, verticalAlign);
  12253. baseX = tmpCITOverflowAreaOut.baseX;
  12254. baseY = tmpCITOverflowAreaOut.baseY;
  12255. var text = getStyleText(style);
  12256. var contentBlock = parseRichText(text, style, tmpCITOverflowAreaOut.outerWidth, tmpCITOverflowAreaOut.outerHeight, textAlign);
  12257. var contentWidth = contentBlock.width;
  12258. var outerWidth = contentBlock.outerWidth;
  12259. var outerHeight = contentBlock.outerHeight;
  12260. var textPadding = style.padding;
  12261. this.isTruncated = !!contentBlock.isTruncated;
  12262. var boxX = adjustTextX(baseX, outerWidth, textAlign);
  12263. var boxY = adjustTextY$1(baseY, outerHeight, verticalAlign);
  12264. var xLeft = boxX;
  12265. var lineTop = boxY;
  12266. if (textPadding) {
  12267. xLeft += textPadding[3];
  12268. lineTop += textPadding[0];
  12269. }
  12270. var xRight = xLeft + contentWidth;
  12271. if (needDrawBackground(style)) {
  12272. this._renderBackground(style, style, boxX, boxY, outerWidth, outerHeight);
  12273. }
  12274. var bgColorDrawn = !!(style.backgroundColor);
  12275. for (var i = 0; i < contentBlock.lines.length; i++) {
  12276. var line = contentBlock.lines[i];
  12277. var tokens = line.tokens;
  12278. var tokenCount = tokens.length;
  12279. var lineHeight = line.lineHeight;
  12280. var remainedWidth = line.width;
  12281. var leftIndex = 0;
  12282. var lineXLeft = xLeft;
  12283. var lineXRight = xRight;
  12284. var rightIndex = tokenCount - 1;
  12285. var token = void 0;
  12286. while (leftIndex < tokenCount
  12287. && (token = tokens[leftIndex], !token.align || token.align === 'left')) {
  12288. this._placeToken(token, style, lineHeight, lineTop, lineXLeft, 'left', bgColorDrawn);
  12289. remainedWidth -= token.width;
  12290. lineXLeft += token.width;
  12291. leftIndex++;
  12292. }
  12293. while (rightIndex >= 0
  12294. && (token = tokens[rightIndex], token.align === 'right')) {
  12295. this._placeToken(token, style, lineHeight, lineTop, lineXRight, 'right', bgColorDrawn);
  12296. remainedWidth -= token.width;
  12297. lineXRight -= token.width;
  12298. rightIndex--;
  12299. }
  12300. lineXLeft += (contentWidth - (lineXLeft - xLeft) - (xRight - lineXRight) - remainedWidth) / 2;
  12301. while (leftIndex <= rightIndex) {
  12302. token = tokens[leftIndex];
  12303. this._placeToken(token, style, lineHeight, lineTop, lineXLeft + token.width / 2, 'center', bgColorDrawn);
  12304. lineXLeft += token.width;
  12305. leftIndex++;
  12306. }
  12307. lineTop += lineHeight;
  12308. }
  12309. };
  12310. ZRText.prototype._placeToken = function (token, style, lineHeight, lineTop, x, textAlign, parentBgColorDrawn) {
  12311. var tokenStyle = style.rich[token.styleName] || {};
  12312. tokenStyle.text = token.text;
  12313. var verticalAlign = token.verticalAlign;
  12314. var y = lineTop + lineHeight / 2;
  12315. if (verticalAlign === 'top') {
  12316. y = lineTop + token.height / 2;
  12317. }
  12318. else if (verticalAlign === 'bottom') {
  12319. y = lineTop + lineHeight - token.height / 2;
  12320. }
  12321. var needDrawBg = !token.isLineHolder && needDrawBackground(tokenStyle);
  12322. needDrawBg && this._renderBackground(tokenStyle, style, textAlign === 'right'
  12323. ? x - token.width
  12324. : textAlign === 'center'
  12325. ? x - token.width / 2
  12326. : x, y - token.height / 2, token.width, token.height);
  12327. var bgColorDrawn = !!tokenStyle.backgroundColor;
  12328. var textPadding = token.textPadding;
  12329. if (textPadding) {
  12330. x = getTextXForPadding(x, textAlign, textPadding);
  12331. y -= token.height / 2 - textPadding[0] - token.innerHeight / 2;
  12332. }
  12333. var el = this._getOrCreateChild(TSpan);
  12334. var subElStyle = el.createStyle();
  12335. el.useStyle(subElStyle);
  12336. var defaultStyle = this._defaultStyle;
  12337. var useDefaultFill = false;
  12338. var defaultLineWidth = 0;
  12339. var usingDefaultStroke = false;
  12340. var textFill = getFill('fill' in tokenStyle ? tokenStyle.fill
  12341. : 'fill' in style ? style.fill
  12342. : (useDefaultFill = true, defaultStyle.fill));
  12343. var textStroke = getStroke('stroke' in tokenStyle ? tokenStyle.stroke
  12344. : 'stroke' in style ? style.stroke
  12345. : (!bgColorDrawn
  12346. && !parentBgColorDrawn
  12347. && (!defaultStyle.autoStroke || useDefaultFill)) ? (defaultLineWidth = DEFAULT_STROKE_LINE_WIDTH, usingDefaultStroke = true, defaultStyle.stroke)
  12348. : null);
  12349. var hasShadow = tokenStyle.textShadowBlur > 0
  12350. || style.textShadowBlur > 0;
  12351. subElStyle.text = token.text;
  12352. subElStyle.x = x;
  12353. subElStyle.y = y;
  12354. if (hasShadow) {
  12355. subElStyle.shadowBlur = tokenStyle.textShadowBlur || style.textShadowBlur || 0;
  12356. subElStyle.shadowColor = tokenStyle.textShadowColor || style.textShadowColor || 'transparent';
  12357. subElStyle.shadowOffsetX = tokenStyle.textShadowOffsetX || style.textShadowOffsetX || 0;
  12358. subElStyle.shadowOffsetY = tokenStyle.textShadowOffsetY || style.textShadowOffsetY || 0;
  12359. }
  12360. subElStyle.textAlign = textAlign;
  12361. subElStyle.textBaseline = 'middle';
  12362. subElStyle.font = token.font || DEFAULT_FONT;
  12363. subElStyle.opacity = retrieve3(tokenStyle.opacity, style.opacity, 1);
  12364. setSeparateFont(subElStyle, tokenStyle);
  12365. if (textStroke) {
  12366. subElStyle.lineWidth = retrieve3(tokenStyle.lineWidth, style.lineWidth, defaultLineWidth);
  12367. subElStyle.lineDash = retrieve2(tokenStyle.lineDash, style.lineDash);
  12368. subElStyle.lineDashOffset = style.lineDashOffset || 0;
  12369. subElStyle.stroke = textStroke;
  12370. }
  12371. if (textFill) {
  12372. subElStyle.fill = textFill;
  12373. }
  12374. el.setBoundingRect(tSpanCreateBoundingRect2(subElStyle, token.contentWidth, token.contentHeight, usingDefaultStroke ? 0 : null));
  12375. };
  12376. ZRText.prototype._renderBackground = function (style, topStyle, x, y, width, height) {
  12377. var textBackgroundColor = style.backgroundColor;
  12378. var textBorderWidth = style.borderWidth;
  12379. var textBorderColor = style.borderColor;
  12380. var isImageBg = textBackgroundColor && textBackgroundColor.image;
  12381. var isPlainOrGradientBg = textBackgroundColor && !isImageBg;
  12382. var textBorderRadius = style.borderRadius;
  12383. var self = this;
  12384. var rectEl;
  12385. var imgEl;
  12386. if (isPlainOrGradientBg || style.lineHeight || (textBorderWidth && textBorderColor)) {
  12387. rectEl = this._getOrCreateChild(Rect);
  12388. rectEl.useStyle(rectEl.createStyle());
  12389. rectEl.style.fill = null;
  12390. var rectShape = rectEl.shape;
  12391. rectShape.x = x;
  12392. rectShape.y = y;
  12393. rectShape.width = width;
  12394. rectShape.height = height;
  12395. rectShape.r = textBorderRadius;
  12396. rectEl.dirtyShape();
  12397. }
  12398. if (isPlainOrGradientBg) {
  12399. var rectStyle = rectEl.style;
  12400. rectStyle.fill = textBackgroundColor || null;
  12401. rectStyle.fillOpacity = retrieve2(style.fillOpacity, 1);
  12402. }
  12403. else if (isImageBg) {
  12404. imgEl = this._getOrCreateChild(ZRImage);
  12405. imgEl.onload = function () {
  12406. self.dirtyStyle();
  12407. };
  12408. var imgStyle = imgEl.style;
  12409. imgStyle.image = textBackgroundColor.image;
  12410. imgStyle.x = x;
  12411. imgStyle.y = y;
  12412. imgStyle.width = width;
  12413. imgStyle.height = height;
  12414. }
  12415. if (textBorderWidth && textBorderColor) {
  12416. var rectStyle = rectEl.style;
  12417. rectStyle.lineWidth = textBorderWidth;
  12418. rectStyle.stroke = textBorderColor;
  12419. rectStyle.strokeOpacity = retrieve2(style.strokeOpacity, 1);
  12420. rectStyle.lineDash = style.borderDash;
  12421. rectStyle.lineDashOffset = style.borderDashOffset || 0;
  12422. rectEl.strokeContainThreshold = 0;
  12423. if (rectEl.hasFill() && rectEl.hasStroke()) {
  12424. rectStyle.strokeFirst = true;
  12425. rectStyle.lineWidth *= 2;
  12426. }
  12427. }
  12428. var commonStyle = (rectEl || imgEl).style;
  12429. commonStyle.shadowBlur = style.shadowBlur || 0;
  12430. commonStyle.shadowColor = style.shadowColor || 'transparent';
  12431. commonStyle.shadowOffsetX = style.shadowOffsetX || 0;
  12432. commonStyle.shadowOffsetY = style.shadowOffsetY || 0;
  12433. commonStyle.opacity = retrieve3(style.opacity, topStyle.opacity, 1);
  12434. };
  12435. ZRText.makeFont = function (style) {
  12436. var font = '';
  12437. if (hasSeparateFont(style)) {
  12438. font = [
  12439. style.fontStyle,
  12440. style.fontWeight,
  12441. parseFontSize(style.fontSize),
  12442. style.fontFamily || 'sans-serif'
  12443. ].join(' ');
  12444. }
  12445. return font && trim(font) || style.textFont || style.font;
  12446. };
  12447. return ZRText;
  12448. }(Displayable));
  12449. var VALID_TEXT_ALIGN = { left: true, right: 1, center: 1 };
  12450. var VALID_TEXT_VERTICAL_ALIGN = { top: 1, bottom: 1, middle: 1 };
  12451. var FONT_PARTS = ['fontStyle', 'fontWeight', 'fontSize', 'fontFamily'];
  12452. function parseFontSize(fontSize) {
  12453. if (typeof fontSize === 'string'
  12454. && (fontSize.indexOf('px') !== -1
  12455. || fontSize.indexOf('rem') !== -1
  12456. || fontSize.indexOf('em') !== -1)) {
  12457. return fontSize;
  12458. }
  12459. else if (!isNaN(+fontSize)) {
  12460. return fontSize + 'px';
  12461. }
  12462. else {
  12463. return DEFAULT_FONT_SIZE + 'px';
  12464. }
  12465. }
  12466. function setSeparateFont(targetStyle, sourceStyle) {
  12467. for (var i = 0; i < FONT_PARTS.length; i++) {
  12468. var fontProp = FONT_PARTS[i];
  12469. var val = sourceStyle[fontProp];
  12470. if (val != null) {
  12471. targetStyle[fontProp] = val;
  12472. }
  12473. }
  12474. }
  12475. function hasSeparateFont(style) {
  12476. return style.fontSize != null || style.fontFamily || style.fontWeight;
  12477. }
  12478. function normalizeTextStyle(style) {
  12479. normalizeStyle(style);
  12480. each(style.rich, normalizeStyle);
  12481. return style;
  12482. }
  12483. function normalizeStyle(style) {
  12484. if (style) {
  12485. style.font = ZRText.makeFont(style);
  12486. var textAlign = style.align;
  12487. textAlign === 'middle' && (textAlign = 'center');
  12488. style.align = (textAlign == null || VALID_TEXT_ALIGN[textAlign]) ? textAlign : 'left';
  12489. var verticalAlign = style.verticalAlign;
  12490. verticalAlign === 'center' && (verticalAlign = 'middle');
  12491. style.verticalAlign = (verticalAlign == null || VALID_TEXT_VERTICAL_ALIGN[verticalAlign]) ? verticalAlign : 'top';
  12492. var textPadding = style.padding;
  12493. if (textPadding) {
  12494. style.padding = normalizeCssArray(style.padding);
  12495. }
  12496. }
  12497. }
  12498. function getStroke(stroke, lineWidth) {
  12499. return (stroke == null || lineWidth <= 0 || stroke === 'transparent' || stroke === 'none')
  12500. ? null
  12501. : (stroke.image || stroke.colorStops)
  12502. ? '#000'
  12503. : stroke;
  12504. }
  12505. function getFill(fill) {
  12506. return (fill == null || fill === 'none')
  12507. ? null
  12508. : (fill.image || fill.colorStops)
  12509. ? '#000'
  12510. : fill;
  12511. }
  12512. function getTextXForPadding(x, textAlign, textPadding) {
  12513. return textAlign === 'right'
  12514. ? (x - textPadding[1])
  12515. : textAlign === 'center'
  12516. ? (x + textPadding[3] / 2 - textPadding[1] / 2)
  12517. : (x + textPadding[3]);
  12518. }
  12519. function getStyleText(style) {
  12520. var text = style.text;
  12521. text != null && (text += '');
  12522. return text;
  12523. }
  12524. function needDrawBackground(style) {
  12525. return !!(style.backgroundColor
  12526. || style.lineHeight
  12527. || (style.borderWidth && style.borderColor));
  12528. }
  12529. var getECData = makeInner();
  12530. var setCommonECData = function (seriesIndex, dataType, dataIdx, el) {
  12531. if (el) {
  12532. var ecData = getECData(el);
  12533. // Add data index and series index for indexing the data by element
  12534. // Useful in tooltip
  12535. ecData.dataIndex = dataIdx;
  12536. ecData.dataType = dataType;
  12537. ecData.seriesIndex = seriesIndex;
  12538. ecData.ssrType = 'chart';
  12539. // TODO: not store dataIndex on children.
  12540. if (el.type === 'group') {
  12541. el.traverse(function (child) {
  12542. var childECData = getECData(child);
  12543. childECData.seriesIndex = seriesIndex;
  12544. childECData.dataIndex = dataIdx;
  12545. childECData.dataType = dataType;
  12546. childECData.ssrType = 'chart';
  12547. });
  12548. }
  12549. }
  12550. };
  12551. // Reserve 0 as default.
  12552. var _highlightNextDigit = 1;
  12553. var _highlightKeyMap = {};
  12554. var getSavedStates = makeInner();
  12555. var getComponentStates = makeInner();
  12556. var HOVER_STATE_NORMAL = 0;
  12557. var HOVER_STATE_BLUR = 1;
  12558. var HOVER_STATE_EMPHASIS = 2;
  12559. var SPECIAL_STATES = ['emphasis', 'blur', 'select'];
  12560. var DISPLAY_STATES = ['normal', 'emphasis', 'blur', 'select'];
  12561. var Z2_EMPHASIS_LIFT = 10;
  12562. var Z2_SELECT_LIFT = 9;
  12563. var HIGHLIGHT_ACTION_TYPE = 'highlight';
  12564. var DOWNPLAY_ACTION_TYPE = 'downplay';
  12565. var SELECT_ACTION_TYPE = 'select';
  12566. var UNSELECT_ACTION_TYPE = 'unselect';
  12567. var TOGGLE_SELECT_ACTION_TYPE = 'toggleSelect';
  12568. var SELECT_CHANGED_EVENT_TYPE = 'selectchanged';
  12569. function hasFillOrStroke(fillOrStroke) {
  12570. return fillOrStroke != null && fillOrStroke !== 'none';
  12571. }
  12572. function doChangeHoverState(el, stateName, hoverStateEnum) {
  12573. if (el.onHoverStateChange && (el.hoverState || 0) !== hoverStateEnum) {
  12574. el.onHoverStateChange(stateName);
  12575. }
  12576. el.hoverState = hoverStateEnum;
  12577. }
  12578. function singleEnterEmphasis(el) {
  12579. // Only mark the flag.
  12580. // States will be applied in the echarts.ts in next frame.
  12581. doChangeHoverState(el, 'emphasis', HOVER_STATE_EMPHASIS);
  12582. }
  12583. function singleLeaveEmphasis(el) {
  12584. // Only mark the flag.
  12585. // States will be applied in the echarts.ts in next frame.
  12586. if (el.hoverState === HOVER_STATE_EMPHASIS) {
  12587. doChangeHoverState(el, 'normal', HOVER_STATE_NORMAL);
  12588. }
  12589. }
  12590. function singleEnterBlur(el) {
  12591. doChangeHoverState(el, 'blur', HOVER_STATE_BLUR);
  12592. }
  12593. function singleLeaveBlur(el) {
  12594. if (el.hoverState === HOVER_STATE_BLUR) {
  12595. doChangeHoverState(el, 'normal', HOVER_STATE_NORMAL);
  12596. }
  12597. }
  12598. function singleEnterSelect(el) {
  12599. el.selected = true;
  12600. }
  12601. function singleLeaveSelect(el) {
  12602. el.selected = false;
  12603. }
  12604. function updateElementState(el, updater, commonParam) {
  12605. updater(el, commonParam);
  12606. }
  12607. function traverseUpdateState(el, updater, commonParam) {
  12608. updateElementState(el, updater, commonParam);
  12609. el.isGroup && el.traverse(function (child) {
  12610. updateElementState(child, updater, commonParam);
  12611. });
  12612. }
  12613. function setStatesFlag(el, stateName) {
  12614. switch (stateName) {
  12615. case 'emphasis':
  12616. el.hoverState = HOVER_STATE_EMPHASIS;
  12617. break;
  12618. case 'normal':
  12619. el.hoverState = HOVER_STATE_NORMAL;
  12620. break;
  12621. case 'blur':
  12622. el.hoverState = HOVER_STATE_BLUR;
  12623. break;
  12624. case 'select':
  12625. el.selected = true;
  12626. }
  12627. }
  12628. function getFromStateStyle(el, props, toStateName, defaultValue) {
  12629. var style = el.style;
  12630. var fromState = {};
  12631. for (var i = 0; i < props.length; i++) {
  12632. var propName = props[i];
  12633. var val = style[propName];
  12634. fromState[propName] = val == null ? defaultValue && defaultValue[propName] : val;
  12635. }
  12636. for (var i = 0; i < el.animators.length; i++) {
  12637. var animator = el.animators[i];
  12638. if (animator.__fromStateTransition
  12639. // Don't consider the animation to emphasis state.
  12640. && animator.__fromStateTransition.indexOf(toStateName) < 0 && animator.targetName === 'style') {
  12641. animator.saveTo(fromState, props);
  12642. }
  12643. }
  12644. return fromState;
  12645. }
  12646. function createEmphasisDefaultState(el, stateName, targetStates, state) {
  12647. var hasSelect = targetStates && indexOf(targetStates, 'select') >= 0;
  12648. var cloned = false;
  12649. if (el instanceof Path) {
  12650. var store = getSavedStates(el);
  12651. var fromFill = hasSelect ? store.selectFill || store.normalFill : store.normalFill;
  12652. var fromStroke = hasSelect ? store.selectStroke || store.normalStroke : store.normalStroke;
  12653. if (hasFillOrStroke(fromFill) || hasFillOrStroke(fromStroke)) {
  12654. state = state || {};
  12655. var emphasisStyle = state.style || {};
  12656. // inherit case
  12657. if (emphasisStyle.fill === 'inherit') {
  12658. cloned = true;
  12659. state = extend({}, state);
  12660. emphasisStyle = extend({}, emphasisStyle);
  12661. emphasisStyle.fill = fromFill;
  12662. }
  12663. // Apply default color lift
  12664. else if (!hasFillOrStroke(emphasisStyle.fill) && hasFillOrStroke(fromFill)) {
  12665. cloned = true;
  12666. // Not modify the original value.
  12667. state = extend({}, state);
  12668. emphasisStyle = extend({}, emphasisStyle);
  12669. // Already being applied 'emphasis'. DON'T lift color multiple times.
  12670. emphasisStyle.fill = liftColor(fromFill);
  12671. }
  12672. // Not highlight stroke if fill has been highlighted.
  12673. else if (!hasFillOrStroke(emphasisStyle.stroke) && hasFillOrStroke(fromStroke)) {
  12674. if (!cloned) {
  12675. state = extend({}, state);
  12676. emphasisStyle = extend({}, emphasisStyle);
  12677. }
  12678. emphasisStyle.stroke = liftColor(fromStroke);
  12679. }
  12680. state.style = emphasisStyle;
  12681. }
  12682. }
  12683. if (state) {
  12684. // TODO Share with textContent?
  12685. if (state.z2 == null) {
  12686. if (!cloned) {
  12687. state = extend({}, state);
  12688. }
  12689. var z2EmphasisLift = el.z2EmphasisLift;
  12690. state.z2 = el.z2 + (z2EmphasisLift != null ? z2EmphasisLift : Z2_EMPHASIS_LIFT);
  12691. }
  12692. }
  12693. return state;
  12694. }
  12695. function createSelectDefaultState(el, stateName, state) {
  12696. // const hasSelect = indexOf(el.currentStates, stateName) >= 0;
  12697. if (state) {
  12698. // TODO Share with textContent?
  12699. if (state.z2 == null) {
  12700. state = extend({}, state);
  12701. var z2SelectLift = el.z2SelectLift;
  12702. state.z2 = el.z2 + (z2SelectLift != null ? z2SelectLift : Z2_SELECT_LIFT);
  12703. }
  12704. }
  12705. return state;
  12706. }
  12707. function createBlurDefaultState(el, stateName, state) {
  12708. var hasBlur = indexOf(el.currentStates, stateName) >= 0;
  12709. var currentOpacity = el.style.opacity;
  12710. var fromState = !hasBlur ? getFromStateStyle(el, ['opacity'], stateName, {
  12711. opacity: 1
  12712. }) : null;
  12713. state = state || {};
  12714. var blurStyle = state.style || {};
  12715. if (blurStyle.opacity == null) {
  12716. // clone state
  12717. state = extend({}, state);
  12718. blurStyle = extend({
  12719. // Already being applied 'emphasis'. DON'T mul opacity multiple times.
  12720. opacity: hasBlur ? currentOpacity : fromState.opacity * 0.1
  12721. }, blurStyle);
  12722. state.style = blurStyle;
  12723. }
  12724. return state;
  12725. }
  12726. function elementStateProxy(stateName, targetStates) {
  12727. var state = this.states[stateName];
  12728. if (this.style) {
  12729. if (stateName === 'emphasis') {
  12730. return createEmphasisDefaultState(this, stateName, targetStates, state);
  12731. } else if (stateName === 'blur') {
  12732. return createBlurDefaultState(this, stateName, state);
  12733. } else if (stateName === 'select') {
  12734. return createSelectDefaultState(this, stateName, state);
  12735. }
  12736. }
  12737. return state;
  12738. }
  12739. /**
  12740. * Set hover style (namely "emphasis style") of element.
  12741. * @param el Should not be `zrender/graphic/Group`.
  12742. * @param focus 'self' | 'selfInSeries' | 'series'
  12743. */
  12744. function setDefaultStateProxy(el) {
  12745. el.stateProxy = elementStateProxy;
  12746. var textContent = el.getTextContent();
  12747. var textGuide = el.getTextGuideLine();
  12748. if (textContent) {
  12749. textContent.stateProxy = elementStateProxy;
  12750. }
  12751. if (textGuide) {
  12752. textGuide.stateProxy = elementStateProxy;
  12753. }
  12754. }
  12755. function enterEmphasisWhenMouseOver(el, e) {
  12756. !shouldSilent(el, e)
  12757. // "emphasis" event highlight has higher priority than mouse highlight.
  12758. && !el.__highByOuter && traverseUpdateState(el, singleEnterEmphasis);
  12759. }
  12760. function leaveEmphasisWhenMouseOut(el, e) {
  12761. !shouldSilent(el, e)
  12762. // "emphasis" event highlight has higher priority than mouse highlight.
  12763. && !el.__highByOuter && traverseUpdateState(el, singleLeaveEmphasis);
  12764. }
  12765. function enterEmphasis(el, highlightDigit) {
  12766. el.__highByOuter |= 1 << (highlightDigit || 0);
  12767. traverseUpdateState(el, singleEnterEmphasis);
  12768. }
  12769. function leaveEmphasis(el, highlightDigit) {
  12770. !(el.__highByOuter &= ~(1 << (highlightDigit || 0))) && traverseUpdateState(el, singleLeaveEmphasis);
  12771. }
  12772. function enterBlur(el) {
  12773. traverseUpdateState(el, singleEnterBlur);
  12774. }
  12775. function leaveBlur(el) {
  12776. traverseUpdateState(el, singleLeaveBlur);
  12777. }
  12778. function enterSelect(el) {
  12779. traverseUpdateState(el, singleEnterSelect);
  12780. }
  12781. function leaveSelect(el) {
  12782. traverseUpdateState(el, singleLeaveSelect);
  12783. }
  12784. function shouldSilent(el, e) {
  12785. return el.__highDownSilentOnTouch && e.zrByTouch;
  12786. }
  12787. function allLeaveBlur(api) {
  12788. var model = api.getModel();
  12789. var leaveBlurredSeries = [];
  12790. var allComponentViews = [];
  12791. model.eachComponent(function (componentType, componentModel) {
  12792. var componentStates = getComponentStates(componentModel);
  12793. var isSeries = componentType === 'series';
  12794. var view = isSeries ? api.getViewOfSeriesModel(componentModel) : api.getViewOfComponentModel(componentModel);
  12795. !isSeries && allComponentViews.push(view);
  12796. if (componentStates.isBlured) {
  12797. // Leave blur anyway
  12798. view.group.traverse(function (child) {
  12799. singleLeaveBlur(child);
  12800. });
  12801. isSeries && leaveBlurredSeries.push(componentModel);
  12802. }
  12803. componentStates.isBlured = false;
  12804. });
  12805. each(allComponentViews, function (view) {
  12806. if (view && view.toggleBlurSeries) {
  12807. view.toggleBlurSeries(leaveBlurredSeries, false, model);
  12808. }
  12809. });
  12810. }
  12811. function blurSeries(targetSeriesIndex, focus, blurScope, api) {
  12812. var ecModel = api.getModel();
  12813. blurScope = blurScope || 'coordinateSystem';
  12814. function leaveBlurOfIndices(data, dataIndices) {
  12815. for (var i = 0; i < dataIndices.length; i++) {
  12816. var itemEl = data.getItemGraphicEl(dataIndices[i]);
  12817. itemEl && leaveBlur(itemEl);
  12818. }
  12819. }
  12820. if (targetSeriesIndex == null) {
  12821. return;
  12822. }
  12823. if (!focus || focus === 'none') {
  12824. return;
  12825. }
  12826. var targetSeriesModel = ecModel.getSeriesByIndex(targetSeriesIndex);
  12827. var targetCoordSys = targetSeriesModel.coordinateSystem;
  12828. if (targetCoordSys && targetCoordSys.master) {
  12829. targetCoordSys = targetCoordSys.master;
  12830. }
  12831. var blurredSeries = [];
  12832. ecModel.eachSeries(function (seriesModel) {
  12833. var sameSeries = targetSeriesModel === seriesModel;
  12834. var coordSys = seriesModel.coordinateSystem;
  12835. if (coordSys && coordSys.master) {
  12836. coordSys = coordSys.master;
  12837. }
  12838. var sameCoordSys = coordSys && targetCoordSys ? coordSys === targetCoordSys : sameSeries; // If there is no coordinate system. use sameSeries instead.
  12839. if (!(
  12840. // Not blur other series if blurScope series
  12841. blurScope === 'series' && !sameSeries
  12842. // Not blur other coordinate system if blurScope is coordinateSystem
  12843. || blurScope === 'coordinateSystem' && !sameCoordSys
  12844. // Not blur self series if focus is series.
  12845. || focus === 'series' && sameSeries
  12846. // TODO blurScope: coordinate system
  12847. )) {
  12848. var view = api.getViewOfSeriesModel(seriesModel);
  12849. view.group.traverse(function (child) {
  12850. // For the elements that have been triggered by other components,
  12851. // and are still required to be highlighted,
  12852. // because the current is directly forced to blur the element,
  12853. // it will cause the focus self to be unable to highlight, so skip the blur of this element.
  12854. if (child.__highByOuter && sameSeries && focus === 'self') {
  12855. return;
  12856. }
  12857. singleEnterBlur(child);
  12858. });
  12859. if (isArrayLike(focus)) {
  12860. leaveBlurOfIndices(seriesModel.getData(), focus);
  12861. } else if (isObject(focus)) {
  12862. var dataTypes = keys(focus);
  12863. for (var d = 0; d < dataTypes.length; d++) {
  12864. leaveBlurOfIndices(seriesModel.getData(dataTypes[d]), focus[dataTypes[d]]);
  12865. }
  12866. }
  12867. blurredSeries.push(seriesModel);
  12868. getComponentStates(seriesModel).isBlured = true;
  12869. }
  12870. });
  12871. ecModel.eachComponent(function (componentType, componentModel) {
  12872. if (componentType === 'series') {
  12873. return;
  12874. }
  12875. var view = api.getViewOfComponentModel(componentModel);
  12876. if (view && view.toggleBlurSeries) {
  12877. view.toggleBlurSeries(blurredSeries, true, ecModel);
  12878. }
  12879. });
  12880. }
  12881. function blurComponent(componentMainType, componentIndex, api) {
  12882. if (componentMainType == null || componentIndex == null) {
  12883. return;
  12884. }
  12885. var componentModel = api.getModel().getComponent(componentMainType, componentIndex);
  12886. if (!componentModel) {
  12887. return;
  12888. }
  12889. getComponentStates(componentModel).isBlured = true;
  12890. var view = api.getViewOfComponentModel(componentModel);
  12891. if (!view || !view.focusBlurEnabled) {
  12892. return;
  12893. }
  12894. view.group.traverse(function (child) {
  12895. singleEnterBlur(child);
  12896. });
  12897. }
  12898. function blurSeriesFromHighlightPayload(seriesModel, payload, api) {
  12899. var seriesIndex = seriesModel.seriesIndex;
  12900. var data = seriesModel.getData(payload.dataType);
  12901. if (!data) {
  12902. if ("development" !== 'production') {
  12903. error("Unknown dataType " + payload.dataType);
  12904. }
  12905. return;
  12906. }
  12907. var dataIndex = queryDataIndex(data, payload);
  12908. // Pick the first one if there is multiple/none exists.
  12909. dataIndex = (isArray(dataIndex) ? dataIndex[0] : dataIndex) || 0;
  12910. var el = data.getItemGraphicEl(dataIndex);
  12911. if (!el) {
  12912. var count = data.count();
  12913. var current = 0;
  12914. // If data on dataIndex is NaN.
  12915. while (!el && current < count) {
  12916. el = data.getItemGraphicEl(current++);
  12917. }
  12918. }
  12919. if (el) {
  12920. var ecData = getECData(el);
  12921. blurSeries(seriesIndex, ecData.focus, ecData.blurScope, api);
  12922. } else {
  12923. // If there is no element put on the data. Try getting it from raw option
  12924. // TODO Should put it on seriesModel?
  12925. var focus_1 = seriesModel.get(['emphasis', 'focus']);
  12926. var blurScope = seriesModel.get(['emphasis', 'blurScope']);
  12927. if (focus_1 != null) {
  12928. blurSeries(seriesIndex, focus_1, blurScope, api);
  12929. }
  12930. }
  12931. }
  12932. function findComponentHighDownDispatchers(componentMainType, componentIndex, name, api) {
  12933. var ret = {
  12934. focusSelf: false,
  12935. dispatchers: null
  12936. };
  12937. if (componentMainType == null || componentMainType === 'series' || componentIndex == null || name == null) {
  12938. return ret;
  12939. }
  12940. var componentModel = api.getModel().getComponent(componentMainType, componentIndex);
  12941. if (!componentModel) {
  12942. return ret;
  12943. }
  12944. var view = api.getViewOfComponentModel(componentModel);
  12945. if (!view || !view.findHighDownDispatchers) {
  12946. return ret;
  12947. }
  12948. var dispatchers = view.findHighDownDispatchers(name);
  12949. // At presnet, the component (like Geo) only blur inside itself.
  12950. // So we do not use `blurScope` in component.
  12951. var focusSelf;
  12952. for (var i = 0; i < dispatchers.length; i++) {
  12953. if ("development" !== 'production' && !isHighDownDispatcher(dispatchers[i])) {
  12954. error('param should be highDownDispatcher');
  12955. }
  12956. if (getECData(dispatchers[i]).focus === 'self') {
  12957. focusSelf = true;
  12958. break;
  12959. }
  12960. }
  12961. return {
  12962. focusSelf: focusSelf,
  12963. dispatchers: dispatchers
  12964. };
  12965. }
  12966. function handleGlobalMouseOverForHighDown(dispatcher, e, api) {
  12967. if ("development" !== 'production' && !isHighDownDispatcher(dispatcher)) {
  12968. error('param should be highDownDispatcher');
  12969. }
  12970. var ecData = getECData(dispatcher);
  12971. var _a = findComponentHighDownDispatchers(ecData.componentMainType, ecData.componentIndex, ecData.componentHighDownName, api),
  12972. dispatchers = _a.dispatchers,
  12973. focusSelf = _a.focusSelf;
  12974. // If `findHighDownDispatchers` is supported on the component,
  12975. // highlight/downplay elements with the same name.
  12976. if (dispatchers) {
  12977. if (focusSelf) {
  12978. blurComponent(ecData.componentMainType, ecData.componentIndex, api);
  12979. }
  12980. each(dispatchers, function (dispatcher) {
  12981. return enterEmphasisWhenMouseOver(dispatcher, e);
  12982. });
  12983. } else {
  12984. // Try blur all in the related series. Then emphasis the hoverred.
  12985. // TODO. progressive mode.
  12986. blurSeries(ecData.seriesIndex, ecData.focus, ecData.blurScope, api);
  12987. if (ecData.focus === 'self') {
  12988. blurComponent(ecData.componentMainType, ecData.componentIndex, api);
  12989. }
  12990. // Other than series, component that not support `findHighDownDispatcher` will
  12991. // also use it. But in this case, highlight/downplay are only supported in
  12992. // mouse hover but not in dispatchAction.
  12993. enterEmphasisWhenMouseOver(dispatcher, e);
  12994. }
  12995. }
  12996. function handleGlobalMouseOutForHighDown(dispatcher, e, api) {
  12997. if ("development" !== 'production' && !isHighDownDispatcher(dispatcher)) {
  12998. error('param should be highDownDispatcher');
  12999. }
  13000. allLeaveBlur(api);
  13001. var ecData = getECData(dispatcher);
  13002. var dispatchers = findComponentHighDownDispatchers(ecData.componentMainType, ecData.componentIndex, ecData.componentHighDownName, api).dispatchers;
  13003. if (dispatchers) {
  13004. each(dispatchers, function (dispatcher) {
  13005. return leaveEmphasisWhenMouseOut(dispatcher, e);
  13006. });
  13007. } else {
  13008. leaveEmphasisWhenMouseOut(dispatcher, e);
  13009. }
  13010. }
  13011. function toggleSelectionFromPayload(seriesModel, payload, api) {
  13012. if (!isSelectChangePayload(payload)) {
  13013. return;
  13014. }
  13015. var dataType = payload.dataType;
  13016. var data = seriesModel.getData(dataType);
  13017. var dataIndex = queryDataIndex(data, payload);
  13018. if (!isArray(dataIndex)) {
  13019. dataIndex = [dataIndex];
  13020. }
  13021. seriesModel[payload.type === TOGGLE_SELECT_ACTION_TYPE ? 'toggleSelect' : payload.type === SELECT_ACTION_TYPE ? 'select' : 'unselect'](dataIndex, dataType);
  13022. }
  13023. function updateSeriesElementSelection(seriesModel) {
  13024. var allData = seriesModel.getAllData();
  13025. each(allData, function (_a) {
  13026. var data = _a.data,
  13027. type = _a.type;
  13028. data.eachItemGraphicEl(function (el, idx) {
  13029. seriesModel.isSelected(idx, type) ? enterSelect(el) : leaveSelect(el);
  13030. });
  13031. });
  13032. }
  13033. function getAllSelectedIndices(ecModel) {
  13034. var ret = [];
  13035. ecModel.eachSeries(function (seriesModel) {
  13036. var allData = seriesModel.getAllData();
  13037. each(allData, function (_a) {
  13038. var data = _a.data,
  13039. type = _a.type;
  13040. var dataIndices = seriesModel.getSelectedDataIndices();
  13041. if (dataIndices.length > 0) {
  13042. var item = {
  13043. dataIndex: dataIndices,
  13044. seriesIndex: seriesModel.seriesIndex
  13045. };
  13046. if (type != null) {
  13047. item.dataType = type;
  13048. }
  13049. ret.push(item);
  13050. }
  13051. });
  13052. });
  13053. return ret;
  13054. }
  13055. /**
  13056. * Enable the function that mouseover will trigger the emphasis state.
  13057. *
  13058. * NOTE:
  13059. * This function should be used on the element with dataIndex, seriesIndex.
  13060. *
  13061. */
  13062. function enableHoverEmphasis(el, focus, blurScope) {
  13063. setAsHighDownDispatcher(el, true);
  13064. traverseUpdateState(el, setDefaultStateProxy);
  13065. enableHoverFocus(el, focus, blurScope);
  13066. }
  13067. function disableHoverEmphasis(el) {
  13068. setAsHighDownDispatcher(el, false);
  13069. }
  13070. function toggleHoverEmphasis(el, focus, blurScope, isDisabled) {
  13071. isDisabled ? disableHoverEmphasis(el) : enableHoverEmphasis(el, focus, blurScope);
  13072. }
  13073. function enableHoverFocus(el, focus, blurScope) {
  13074. var ecData = getECData(el);
  13075. if (focus != null) {
  13076. // TODO dataIndex may be set after this function. This check is not useful.
  13077. // if (ecData.dataIndex == null) {
  13078. // if (__DEV__) {
  13079. // console.warn('focus can only been set on element with dataIndex');
  13080. // }
  13081. // }
  13082. // else {
  13083. ecData.focus = focus;
  13084. ecData.blurScope = blurScope;
  13085. // }
  13086. } else if (ecData.focus) {
  13087. ecData.focus = null;
  13088. }
  13089. }
  13090. var OTHER_STATES = ['emphasis', 'blur', 'select'];
  13091. var defaultStyleGetterMap = {
  13092. itemStyle: 'getItemStyle',
  13093. lineStyle: 'getLineStyle',
  13094. areaStyle: 'getAreaStyle'
  13095. };
  13096. /**
  13097. * Set emphasis/blur/selected states of element.
  13098. */
  13099. function setStatesStylesFromModel(el, itemModel, styleType,
  13100. // default itemStyle
  13101. getter) {
  13102. styleType = styleType || 'itemStyle';
  13103. for (var i = 0; i < OTHER_STATES.length; i++) {
  13104. var stateName = OTHER_STATES[i];
  13105. var model = itemModel.getModel([stateName, styleType]);
  13106. var state = el.ensureState(stateName);
  13107. // Let it throw error if getterType is not found.
  13108. state.style = getter ? getter(model) : model[defaultStyleGetterMap[styleType]]();
  13109. }
  13110. }
  13111. /**
  13112. *
  13113. * Set element as highlight / downplay dispatcher.
  13114. * It will be checked when element received mouseover event or from highlight action.
  13115. * It's in change of all highlight/downplay behavior of it's children.
  13116. *
  13117. * @param el
  13118. * @param el.highDownSilentOnTouch
  13119. * In touch device, mouseover event will be trigger on touchstart event
  13120. * (see module:zrender/dom/HandlerProxy). By this mechanism, we can
  13121. * conveniently use hoverStyle when tap on touch screen without additional
  13122. * code for compatibility.
  13123. * But if the chart/component has select feature, which usually also use
  13124. * hoverStyle, there might be conflict between 'select-highlight' and
  13125. * 'hover-highlight' especially when roam is enabled (see geo for example).
  13126. * In this case, `highDownSilentOnTouch` should be used to disable
  13127. * hover-highlight on touch device.
  13128. * @param asDispatcher If `false`, do not set as "highDownDispatcher".
  13129. */
  13130. function setAsHighDownDispatcher(el, asDispatcher) {
  13131. var disable = asDispatcher === false;
  13132. var extendedEl = el;
  13133. // Make `highDownSilentOnTouch` and `onStateChange` only work after
  13134. // `setAsHighDownDispatcher` called. Avoid it is modified by user unexpectedly.
  13135. if (el.highDownSilentOnTouch) {
  13136. extendedEl.__highDownSilentOnTouch = el.highDownSilentOnTouch;
  13137. }
  13138. // Simple optimize, since this method might be
  13139. // called for each elements of a group in some cases.
  13140. if (!disable || extendedEl.__highDownDispatcher) {
  13141. // Emphasis, normal can be triggered manually by API or other components like hover link.
  13142. // el[method]('emphasis', onElementEmphasisEvent)[method]('normal', onElementNormalEvent);
  13143. // Also keep previous record.
  13144. extendedEl.__highByOuter = extendedEl.__highByOuter || 0;
  13145. extendedEl.__highDownDispatcher = !disable;
  13146. }
  13147. }
  13148. function isHighDownDispatcher(el) {
  13149. return !!(el && el.__highDownDispatcher);
  13150. }
  13151. /**
  13152. * Enable component highlight/downplay features:
  13153. * + hover link (within the same name)
  13154. * + focus blur in component
  13155. */
  13156. function enableComponentHighDownFeatures(el, componentModel, componentHighDownName) {
  13157. var ecData = getECData(el);
  13158. ecData.componentMainType = componentModel.mainType;
  13159. ecData.componentIndex = componentModel.componentIndex;
  13160. ecData.componentHighDownName = componentHighDownName;
  13161. }
  13162. /**
  13163. * Support highlight/downplay record on each elements.
  13164. * For the case: hover highlight/downplay (legend, visualMap, ...) and
  13165. * user triggered highlight/downplay should not conflict.
  13166. * Only all of the highlightDigit cleared, return to normal.
  13167. * @param {string} highlightKey
  13168. * @return {number} highlightDigit
  13169. */
  13170. function getHighlightDigit(highlightKey) {
  13171. var highlightDigit = _highlightKeyMap[highlightKey];
  13172. if (highlightDigit == null && _highlightNextDigit <= 32) {
  13173. highlightDigit = _highlightKeyMap[highlightKey] = _highlightNextDigit++;
  13174. }
  13175. return highlightDigit;
  13176. }
  13177. function isSelectChangePayload(payload) {
  13178. var payloadType = payload.type;
  13179. return payloadType === SELECT_ACTION_TYPE || payloadType === UNSELECT_ACTION_TYPE || payloadType === TOGGLE_SELECT_ACTION_TYPE;
  13180. }
  13181. function isHighDownPayload(payload) {
  13182. var payloadType = payload.type;
  13183. return payloadType === HIGHLIGHT_ACTION_TYPE || payloadType === DOWNPLAY_ACTION_TYPE;
  13184. }
  13185. function savePathStates(el) {
  13186. var store = getSavedStates(el);
  13187. store.normalFill = el.style.fill;
  13188. store.normalStroke = el.style.stroke;
  13189. var selectState = el.states.select || {};
  13190. store.selectFill = selectState.style && selectState.style.fill || null;
  13191. store.selectStroke = selectState.style && selectState.style.stroke || null;
  13192. }
  13193. var CMD$2 = PathProxy.CMD;
  13194. var points = [[], [], []];
  13195. var mathSqrt$1 = Math.sqrt;
  13196. var mathAtan2 = Math.atan2;
  13197. function transformPath(path, m) {
  13198. if (!m) {
  13199. return;
  13200. }
  13201. var data = path.data;
  13202. var len = path.len();
  13203. var cmd;
  13204. var nPoint;
  13205. var i;
  13206. var j;
  13207. var k;
  13208. var p;
  13209. var M = CMD$2.M;
  13210. var C = CMD$2.C;
  13211. var L = CMD$2.L;
  13212. var R = CMD$2.R;
  13213. var A = CMD$2.A;
  13214. var Q = CMD$2.Q;
  13215. for (i = 0, j = 0; i < len;) {
  13216. cmd = data[i++];
  13217. j = i;
  13218. nPoint = 0;
  13219. switch (cmd) {
  13220. case M:
  13221. nPoint = 1;
  13222. break;
  13223. case L:
  13224. nPoint = 1;
  13225. break;
  13226. case C:
  13227. nPoint = 3;
  13228. break;
  13229. case Q:
  13230. nPoint = 2;
  13231. break;
  13232. case A:
  13233. var x = m[4];
  13234. var y = m[5];
  13235. var sx = mathSqrt$1(m[0] * m[0] + m[1] * m[1]);
  13236. var sy = mathSqrt$1(m[2] * m[2] + m[3] * m[3]);
  13237. var angle = mathAtan2(-m[1] / sy, m[0] / sx);
  13238. data[i] *= sx;
  13239. data[i++] += x;
  13240. data[i] *= sy;
  13241. data[i++] += y;
  13242. data[i++] *= sx;
  13243. data[i++] *= sy;
  13244. data[i++] += angle;
  13245. data[i++] += angle;
  13246. i += 2;
  13247. j = i;
  13248. break;
  13249. case R:
  13250. p[0] = data[i++];
  13251. p[1] = data[i++];
  13252. applyTransform(p, p, m);
  13253. data[j++] = p[0];
  13254. data[j++] = p[1];
  13255. p[0] += data[i++];
  13256. p[1] += data[i++];
  13257. applyTransform(p, p, m);
  13258. data[j++] = p[0];
  13259. data[j++] = p[1];
  13260. }
  13261. for (k = 0; k < nPoint; k++) {
  13262. var p_1 = points[k];
  13263. p_1[0] = data[i++];
  13264. p_1[1] = data[i++];
  13265. applyTransform(p_1, p_1, m);
  13266. data[j++] = p_1[0];
  13267. data[j++] = p_1[1];
  13268. }
  13269. }
  13270. path.increaseVersion();
  13271. }
  13272. var mathSqrt$2 = Math.sqrt;
  13273. var mathSin$2 = Math.sin;
  13274. var mathCos$2 = Math.cos;
  13275. var PI$1 = Math.PI;
  13276. function vMag(v) {
  13277. return Math.sqrt(v[0] * v[0] + v[1] * v[1]);
  13278. }
  13279. function vRatio(u, v) {
  13280. return (u[0] * v[0] + u[1] * v[1]) / (vMag(u) * vMag(v));
  13281. }
  13282. function vAngle(u, v) {
  13283. return (u[0] * v[1] < u[1] * v[0] ? -1 : 1)
  13284. * Math.acos(vRatio(u, v));
  13285. }
  13286. function processArc(x1, y1, x2, y2, fa, fs, rx, ry, psiDeg, cmd, path) {
  13287. var psi = psiDeg * (PI$1 / 180.0);
  13288. var xp = mathCos$2(psi) * (x1 - x2) / 2.0
  13289. + mathSin$2(psi) * (y1 - y2) / 2.0;
  13290. var yp = -1 * mathSin$2(psi) * (x1 - x2) / 2.0
  13291. + mathCos$2(psi) * (y1 - y2) / 2.0;
  13292. var lambda = (xp * xp) / (rx * rx) + (yp * yp) / (ry * ry);
  13293. if (lambda > 1) {
  13294. rx *= mathSqrt$2(lambda);
  13295. ry *= mathSqrt$2(lambda);
  13296. }
  13297. var f = (fa === fs ? -1 : 1)
  13298. * mathSqrt$2((((rx * rx) * (ry * ry))
  13299. - ((rx * rx) * (yp * yp))
  13300. - ((ry * ry) * (xp * xp))) / ((rx * rx) * (yp * yp)
  13301. + (ry * ry) * (xp * xp))) || 0;
  13302. var cxp = f * rx * yp / ry;
  13303. var cyp = f * -ry * xp / rx;
  13304. var cx = (x1 + x2) / 2.0
  13305. + mathCos$2(psi) * cxp
  13306. - mathSin$2(psi) * cyp;
  13307. var cy = (y1 + y2) / 2.0
  13308. + mathSin$2(psi) * cxp
  13309. + mathCos$2(psi) * cyp;
  13310. var theta = vAngle([1, 0], [(xp - cxp) / rx, (yp - cyp) / ry]);
  13311. var u = [(xp - cxp) / rx, (yp - cyp) / ry];
  13312. var v = [(-1 * xp - cxp) / rx, (-1 * yp - cyp) / ry];
  13313. var dTheta = vAngle(u, v);
  13314. if (vRatio(u, v) <= -1) {
  13315. dTheta = PI$1;
  13316. }
  13317. if (vRatio(u, v) >= 1) {
  13318. dTheta = 0;
  13319. }
  13320. if (dTheta < 0) {
  13321. var n = Math.round(dTheta / PI$1 * 1e6) / 1e6;
  13322. dTheta = PI$1 * 2 + (n % 2) * PI$1;
  13323. }
  13324. path.addData(cmd, cx, cy, rx, ry, theta, dTheta, psi, fs);
  13325. }
  13326. var commandReg = /([mlvhzcqtsa])([^mlvhzcqtsa]*)/ig;
  13327. var numberReg = /-?([0-9]*\.)?[0-9]+([eE]-?[0-9]+)?/g;
  13328. function createPathProxyFromString(data) {
  13329. var path = new PathProxy();
  13330. if (!data) {
  13331. return path;
  13332. }
  13333. var cpx = 0;
  13334. var cpy = 0;
  13335. var subpathX = cpx;
  13336. var subpathY = cpy;
  13337. var prevCmd;
  13338. var CMD = PathProxy.CMD;
  13339. var cmdList = data.match(commandReg);
  13340. if (!cmdList) {
  13341. return path;
  13342. }
  13343. for (var l = 0; l < cmdList.length; l++) {
  13344. var cmdText = cmdList[l];
  13345. var cmdStr = cmdText.charAt(0);
  13346. var cmd = void 0;
  13347. var p = cmdText.match(numberReg) || [];
  13348. var pLen = p.length;
  13349. for (var i = 0; i < pLen; i++) {
  13350. p[i] = parseFloat(p[i]);
  13351. }
  13352. var off = 0;
  13353. while (off < pLen) {
  13354. var ctlPtx = void 0;
  13355. var ctlPty = void 0;
  13356. var rx = void 0;
  13357. var ry = void 0;
  13358. var psi = void 0;
  13359. var fa = void 0;
  13360. var fs = void 0;
  13361. var x1 = cpx;
  13362. var y1 = cpy;
  13363. var len = void 0;
  13364. var pathData = void 0;
  13365. switch (cmdStr) {
  13366. case 'l':
  13367. cpx += p[off++];
  13368. cpy += p[off++];
  13369. cmd = CMD.L;
  13370. path.addData(cmd, cpx, cpy);
  13371. break;
  13372. case 'L':
  13373. cpx = p[off++];
  13374. cpy = p[off++];
  13375. cmd = CMD.L;
  13376. path.addData(cmd, cpx, cpy);
  13377. break;
  13378. case 'm':
  13379. cpx += p[off++];
  13380. cpy += p[off++];
  13381. cmd = CMD.M;
  13382. path.addData(cmd, cpx, cpy);
  13383. subpathX = cpx;
  13384. subpathY = cpy;
  13385. cmdStr = 'l';
  13386. break;
  13387. case 'M':
  13388. cpx = p[off++];
  13389. cpy = p[off++];
  13390. cmd = CMD.M;
  13391. path.addData(cmd, cpx, cpy);
  13392. subpathX = cpx;
  13393. subpathY = cpy;
  13394. cmdStr = 'L';
  13395. break;
  13396. case 'h':
  13397. cpx += p[off++];
  13398. cmd = CMD.L;
  13399. path.addData(cmd, cpx, cpy);
  13400. break;
  13401. case 'H':
  13402. cpx = p[off++];
  13403. cmd = CMD.L;
  13404. path.addData(cmd, cpx, cpy);
  13405. break;
  13406. case 'v':
  13407. cpy += p[off++];
  13408. cmd = CMD.L;
  13409. path.addData(cmd, cpx, cpy);
  13410. break;
  13411. case 'V':
  13412. cpy = p[off++];
  13413. cmd = CMD.L;
  13414. path.addData(cmd, cpx, cpy);
  13415. break;
  13416. case 'C':
  13417. cmd = CMD.C;
  13418. path.addData(cmd, p[off++], p[off++], p[off++], p[off++], p[off++], p[off++]);
  13419. cpx = p[off - 2];
  13420. cpy = p[off - 1];
  13421. break;
  13422. case 'c':
  13423. cmd = CMD.C;
  13424. path.addData(cmd, p[off++] + cpx, p[off++] + cpy, p[off++] + cpx, p[off++] + cpy, p[off++] + cpx, p[off++] + cpy);
  13425. cpx += p[off - 2];
  13426. cpy += p[off - 1];
  13427. break;
  13428. case 'S':
  13429. ctlPtx = cpx;
  13430. ctlPty = cpy;
  13431. len = path.len();
  13432. pathData = path.data;
  13433. if (prevCmd === CMD.C) {
  13434. ctlPtx += cpx - pathData[len - 4];
  13435. ctlPty += cpy - pathData[len - 3];
  13436. }
  13437. cmd = CMD.C;
  13438. x1 = p[off++];
  13439. y1 = p[off++];
  13440. cpx = p[off++];
  13441. cpy = p[off++];
  13442. path.addData(cmd, ctlPtx, ctlPty, x1, y1, cpx, cpy);
  13443. break;
  13444. case 's':
  13445. ctlPtx = cpx;
  13446. ctlPty = cpy;
  13447. len = path.len();
  13448. pathData = path.data;
  13449. if (prevCmd === CMD.C) {
  13450. ctlPtx += cpx - pathData[len - 4];
  13451. ctlPty += cpy - pathData[len - 3];
  13452. }
  13453. cmd = CMD.C;
  13454. x1 = cpx + p[off++];
  13455. y1 = cpy + p[off++];
  13456. cpx += p[off++];
  13457. cpy += p[off++];
  13458. path.addData(cmd, ctlPtx, ctlPty, x1, y1, cpx, cpy);
  13459. break;
  13460. case 'Q':
  13461. x1 = p[off++];
  13462. y1 = p[off++];
  13463. cpx = p[off++];
  13464. cpy = p[off++];
  13465. cmd = CMD.Q;
  13466. path.addData(cmd, x1, y1, cpx, cpy);
  13467. break;
  13468. case 'q':
  13469. x1 = p[off++] + cpx;
  13470. y1 = p[off++] + cpy;
  13471. cpx += p[off++];
  13472. cpy += p[off++];
  13473. cmd = CMD.Q;
  13474. path.addData(cmd, x1, y1, cpx, cpy);
  13475. break;
  13476. case 'T':
  13477. ctlPtx = cpx;
  13478. ctlPty = cpy;
  13479. len = path.len();
  13480. pathData = path.data;
  13481. if (prevCmd === CMD.Q) {
  13482. ctlPtx += cpx - pathData[len - 4];
  13483. ctlPty += cpy - pathData[len - 3];
  13484. }
  13485. cpx = p[off++];
  13486. cpy = p[off++];
  13487. cmd = CMD.Q;
  13488. path.addData(cmd, ctlPtx, ctlPty, cpx, cpy);
  13489. break;
  13490. case 't':
  13491. ctlPtx = cpx;
  13492. ctlPty = cpy;
  13493. len = path.len();
  13494. pathData = path.data;
  13495. if (prevCmd === CMD.Q) {
  13496. ctlPtx += cpx - pathData[len - 4];
  13497. ctlPty += cpy - pathData[len - 3];
  13498. }
  13499. cpx += p[off++];
  13500. cpy += p[off++];
  13501. cmd = CMD.Q;
  13502. path.addData(cmd, ctlPtx, ctlPty, cpx, cpy);
  13503. break;
  13504. case 'A':
  13505. rx = p[off++];
  13506. ry = p[off++];
  13507. psi = p[off++];
  13508. fa = p[off++];
  13509. fs = p[off++];
  13510. x1 = cpx, y1 = cpy;
  13511. cpx = p[off++];
  13512. cpy = p[off++];
  13513. cmd = CMD.A;
  13514. processArc(x1, y1, cpx, cpy, fa, fs, rx, ry, psi, cmd, path);
  13515. break;
  13516. case 'a':
  13517. rx = p[off++];
  13518. ry = p[off++];
  13519. psi = p[off++];
  13520. fa = p[off++];
  13521. fs = p[off++];
  13522. x1 = cpx, y1 = cpy;
  13523. cpx += p[off++];
  13524. cpy += p[off++];
  13525. cmd = CMD.A;
  13526. processArc(x1, y1, cpx, cpy, fa, fs, rx, ry, psi, cmd, path);
  13527. break;
  13528. }
  13529. }
  13530. if (cmdStr === 'z' || cmdStr === 'Z') {
  13531. cmd = CMD.Z;
  13532. path.addData(cmd);
  13533. cpx = subpathX;
  13534. cpy = subpathY;
  13535. }
  13536. prevCmd = cmd;
  13537. }
  13538. path.toStatic();
  13539. return path;
  13540. }
  13541. var SVGPath = (function (_super) {
  13542. __extends(SVGPath, _super);
  13543. function SVGPath() {
  13544. return _super !== null && _super.apply(this, arguments) || this;
  13545. }
  13546. SVGPath.prototype.applyTransform = function (m) { };
  13547. return SVGPath;
  13548. }(Path));
  13549. function isPathProxy(path) {
  13550. return path.setData != null;
  13551. }
  13552. function createPathOptions(str, opts) {
  13553. var pathProxy = createPathProxyFromString(str);
  13554. var innerOpts = extend({}, opts);
  13555. innerOpts.buildPath = function (path) {
  13556. var beProxy = isPathProxy(path);
  13557. if (beProxy && path.canSave()) {
  13558. path.appendPath(pathProxy);
  13559. var ctx = path.getContext();
  13560. if (ctx) {
  13561. path.rebuildPath(ctx, 1);
  13562. }
  13563. }
  13564. else {
  13565. var ctx = beProxy ? path.getContext() : path;
  13566. if (ctx) {
  13567. pathProxy.rebuildPath(ctx, 1);
  13568. }
  13569. }
  13570. };
  13571. innerOpts.applyTransform = function (m) {
  13572. transformPath(pathProxy, m);
  13573. this.dirtyShape();
  13574. };
  13575. return innerOpts;
  13576. }
  13577. function createFromString(str, opts) {
  13578. return new SVGPath(createPathOptions(str, opts));
  13579. }
  13580. function extendFromString(str, defaultOpts) {
  13581. var innerOpts = createPathOptions(str, defaultOpts);
  13582. var Sub = (function (_super) {
  13583. __extends(Sub, _super);
  13584. function Sub(opts) {
  13585. var _this = _super.call(this, opts) || this;
  13586. _this.applyTransform = innerOpts.applyTransform;
  13587. _this.buildPath = innerOpts.buildPath;
  13588. return _this;
  13589. }
  13590. return Sub;
  13591. }(SVGPath));
  13592. return Sub;
  13593. }
  13594. function mergePath(pathEls, opts) {
  13595. var pathList = [];
  13596. var len = pathEls.length;
  13597. for (var i = 0; i < len; i++) {
  13598. var pathEl = pathEls[i];
  13599. pathList.push(pathEl.getUpdatedPathProxy(true));
  13600. }
  13601. var pathBundle = new Path(opts);
  13602. pathBundle.createPathProxy();
  13603. pathBundle.buildPath = function (path) {
  13604. if (isPathProxy(path)) {
  13605. path.appendPath(pathList);
  13606. var ctx = path.getContext();
  13607. if (ctx) {
  13608. path.rebuildPath(ctx, 1);
  13609. }
  13610. }
  13611. };
  13612. return pathBundle;
  13613. }
  13614. function clonePath(sourcePath, opts) {
  13615. opts = opts || {};
  13616. var path = new Path();
  13617. if (sourcePath.shape) {
  13618. path.setShape(sourcePath.shape);
  13619. }
  13620. path.setStyle(sourcePath.style);
  13621. if (opts.bakeTransform) {
  13622. transformPath(path.path, sourcePath.getComputedTransform());
  13623. }
  13624. else {
  13625. if (opts.toLocal) {
  13626. path.setLocalTransform(sourcePath.getComputedTransform());
  13627. }
  13628. else {
  13629. path.copyTransform(sourcePath);
  13630. }
  13631. }
  13632. path.buildPath = sourcePath.buildPath;
  13633. path.applyTransform = path.applyTransform;
  13634. path.z = sourcePath.z;
  13635. path.z2 = sourcePath.z2;
  13636. path.zlevel = sourcePath.zlevel;
  13637. return path;
  13638. }
  13639. var CircleShape = (function () {
  13640. function CircleShape() {
  13641. this.cx = 0;
  13642. this.cy = 0;
  13643. this.r = 0;
  13644. }
  13645. return CircleShape;
  13646. }());
  13647. var Circle = (function (_super) {
  13648. __extends(Circle, _super);
  13649. function Circle(opts) {
  13650. return _super.call(this, opts) || this;
  13651. }
  13652. Circle.prototype.getDefaultShape = function () {
  13653. return new CircleShape();
  13654. };
  13655. Circle.prototype.buildPath = function (ctx, shape) {
  13656. ctx.moveTo(shape.cx + shape.r, shape.cy);
  13657. ctx.arc(shape.cx, shape.cy, shape.r, 0, Math.PI * 2);
  13658. };
  13659. return Circle;
  13660. }(Path));
  13661. Circle.prototype.type = 'circle';
  13662. var EllipseShape = (function () {
  13663. function EllipseShape() {
  13664. this.cx = 0;
  13665. this.cy = 0;
  13666. this.rx = 0;
  13667. this.ry = 0;
  13668. }
  13669. return EllipseShape;
  13670. }());
  13671. var Ellipse = (function (_super) {
  13672. __extends(Ellipse, _super);
  13673. function Ellipse(opts) {
  13674. return _super.call(this, opts) || this;
  13675. }
  13676. Ellipse.prototype.getDefaultShape = function () {
  13677. return new EllipseShape();
  13678. };
  13679. Ellipse.prototype.buildPath = function (ctx, shape) {
  13680. var k = 0.5522848;
  13681. var x = shape.cx;
  13682. var y = shape.cy;
  13683. var a = shape.rx;
  13684. var b = shape.ry;
  13685. var ox = a * k;
  13686. var oy = b * k;
  13687. ctx.moveTo(x - a, y);
  13688. ctx.bezierCurveTo(x - a, y - oy, x - ox, y - b, x, y - b);
  13689. ctx.bezierCurveTo(x + ox, y - b, x + a, y - oy, x + a, y);
  13690. ctx.bezierCurveTo(x + a, y + oy, x + ox, y + b, x, y + b);
  13691. ctx.bezierCurveTo(x - ox, y + b, x - a, y + oy, x - a, y);
  13692. ctx.closePath();
  13693. };
  13694. return Ellipse;
  13695. }(Path));
  13696. Ellipse.prototype.type = 'ellipse';
  13697. var PI$2 = Math.PI;
  13698. var PI2$5 = PI$2 * 2;
  13699. var mathSin$3 = Math.sin;
  13700. var mathCos$3 = Math.cos;
  13701. var mathACos = Math.acos;
  13702. var mathATan2 = Math.atan2;
  13703. var mathAbs$3 = Math.abs;
  13704. var mathSqrt$3 = Math.sqrt;
  13705. var mathMax$4 = Math.max;
  13706. var mathMin$4 = Math.min;
  13707. var e = 1e-4;
  13708. function intersect(x0, y0, x1, y1, x2, y2, x3, y3) {
  13709. var dx10 = x1 - x0;
  13710. var dy10 = y1 - y0;
  13711. var dx32 = x3 - x2;
  13712. var dy32 = y3 - y2;
  13713. var t = dy32 * dx10 - dx32 * dy10;
  13714. if (t * t < e) {
  13715. return;
  13716. }
  13717. t = (dx32 * (y0 - y2) - dy32 * (x0 - x2)) / t;
  13718. return [x0 + t * dx10, y0 + t * dy10];
  13719. }
  13720. function computeCornerTangents(x0, y0, x1, y1, radius, cr, clockwise) {
  13721. var x01 = x0 - x1;
  13722. var y01 = y0 - y1;
  13723. var lo = (clockwise ? cr : -cr) / mathSqrt$3(x01 * x01 + y01 * y01);
  13724. var ox = lo * y01;
  13725. var oy = -lo * x01;
  13726. var x11 = x0 + ox;
  13727. var y11 = y0 + oy;
  13728. var x10 = x1 + ox;
  13729. var y10 = y1 + oy;
  13730. var x00 = (x11 + x10) / 2;
  13731. var y00 = (y11 + y10) / 2;
  13732. var dx = x10 - x11;
  13733. var dy = y10 - y11;
  13734. var d2 = dx * dx + dy * dy;
  13735. var r = radius - cr;
  13736. var s = x11 * y10 - x10 * y11;
  13737. var d = (dy < 0 ? -1 : 1) * mathSqrt$3(mathMax$4(0, r * r * d2 - s * s));
  13738. var cx0 = (s * dy - dx * d) / d2;
  13739. var cy0 = (-s * dx - dy * d) / d2;
  13740. var cx1 = (s * dy + dx * d) / d2;
  13741. var cy1 = (-s * dx + dy * d) / d2;
  13742. var dx0 = cx0 - x00;
  13743. var dy0 = cy0 - y00;
  13744. var dx1 = cx1 - x00;
  13745. var dy1 = cy1 - y00;
  13746. if (dx0 * dx0 + dy0 * dy0 > dx1 * dx1 + dy1 * dy1) {
  13747. cx0 = cx1;
  13748. cy0 = cy1;
  13749. }
  13750. return {
  13751. cx: cx0,
  13752. cy: cy0,
  13753. x0: -ox,
  13754. y0: -oy,
  13755. x1: cx0 * (radius / r - 1),
  13756. y1: cy0 * (radius / r - 1)
  13757. };
  13758. }
  13759. function normalizeCornerRadius(cr) {
  13760. var arr;
  13761. if (isArray(cr)) {
  13762. var len = cr.length;
  13763. if (!len) {
  13764. return cr;
  13765. }
  13766. if (len === 1) {
  13767. arr = [cr[0], cr[0], 0, 0];
  13768. }
  13769. else if (len === 2) {
  13770. arr = [cr[0], cr[0], cr[1], cr[1]];
  13771. }
  13772. else if (len === 3) {
  13773. arr = cr.concat(cr[2]);
  13774. }
  13775. else {
  13776. arr = cr;
  13777. }
  13778. }
  13779. else {
  13780. arr = [cr, cr, cr, cr];
  13781. }
  13782. return arr;
  13783. }
  13784. function buildPath$1(ctx, shape) {
  13785. var _a;
  13786. var radius = mathMax$4(shape.r, 0);
  13787. var innerRadius = mathMax$4(shape.r0 || 0, 0);
  13788. var hasRadius = radius > 0;
  13789. var hasInnerRadius = innerRadius > 0;
  13790. if (!hasRadius && !hasInnerRadius) {
  13791. return;
  13792. }
  13793. if (!hasRadius) {
  13794. radius = innerRadius;
  13795. innerRadius = 0;
  13796. }
  13797. if (innerRadius > radius) {
  13798. var tmp = radius;
  13799. radius = innerRadius;
  13800. innerRadius = tmp;
  13801. }
  13802. var startAngle = shape.startAngle, endAngle = shape.endAngle;
  13803. if (isNaN(startAngle) || isNaN(endAngle)) {
  13804. return;
  13805. }
  13806. var cx = shape.cx, cy = shape.cy;
  13807. var clockwise = !!shape.clockwise;
  13808. var arc = mathAbs$3(endAngle - startAngle);
  13809. var mod = arc > PI2$5 && arc % PI2$5;
  13810. mod > e && (arc = mod);
  13811. if (!(radius > e)) {
  13812. ctx.moveTo(cx, cy);
  13813. }
  13814. else if (arc > PI2$5 - e) {
  13815. ctx.moveTo(cx + radius * mathCos$3(startAngle), cy + radius * mathSin$3(startAngle));
  13816. ctx.arc(cx, cy, radius, startAngle, endAngle, !clockwise);
  13817. if (innerRadius > e) {
  13818. ctx.moveTo(cx + innerRadius * mathCos$3(endAngle), cy + innerRadius * mathSin$3(endAngle));
  13819. ctx.arc(cx, cy, innerRadius, endAngle, startAngle, clockwise);
  13820. }
  13821. }
  13822. else {
  13823. var icrStart = void 0;
  13824. var icrEnd = void 0;
  13825. var ocrStart = void 0;
  13826. var ocrEnd = void 0;
  13827. var ocrs = void 0;
  13828. var ocre = void 0;
  13829. var icrs = void 0;
  13830. var icre = void 0;
  13831. var ocrMax = void 0;
  13832. var icrMax = void 0;
  13833. var limitedOcrMax = void 0;
  13834. var limitedIcrMax = void 0;
  13835. var xre = void 0;
  13836. var yre = void 0;
  13837. var xirs = void 0;
  13838. var yirs = void 0;
  13839. var xrs = radius * mathCos$3(startAngle);
  13840. var yrs = radius * mathSin$3(startAngle);
  13841. var xire = innerRadius * mathCos$3(endAngle);
  13842. var yire = innerRadius * mathSin$3(endAngle);
  13843. var hasArc = arc > e;
  13844. if (hasArc) {
  13845. var cornerRadius = shape.cornerRadius;
  13846. if (cornerRadius) {
  13847. _a = normalizeCornerRadius(cornerRadius), icrStart = _a[0], icrEnd = _a[1], ocrStart = _a[2], ocrEnd = _a[3];
  13848. }
  13849. var halfRd = mathAbs$3(radius - innerRadius) / 2;
  13850. ocrs = mathMin$4(halfRd, ocrStart);
  13851. ocre = mathMin$4(halfRd, ocrEnd);
  13852. icrs = mathMin$4(halfRd, icrStart);
  13853. icre = mathMin$4(halfRd, icrEnd);
  13854. limitedOcrMax = ocrMax = mathMax$4(ocrs, ocre);
  13855. limitedIcrMax = icrMax = mathMax$4(icrs, icre);
  13856. if (ocrMax > e || icrMax > e) {
  13857. xre = radius * mathCos$3(endAngle);
  13858. yre = radius * mathSin$3(endAngle);
  13859. xirs = innerRadius * mathCos$3(startAngle);
  13860. yirs = innerRadius * mathSin$3(startAngle);
  13861. if (arc < PI$2) {
  13862. var it_1 = intersect(xrs, yrs, xirs, yirs, xre, yre, xire, yire);
  13863. if (it_1) {
  13864. var x0 = xrs - it_1[0];
  13865. var y0 = yrs - it_1[1];
  13866. var x1 = xre - it_1[0];
  13867. var y1 = yre - it_1[1];
  13868. var a = 1 / mathSin$3(mathACos((x0 * x1 + y0 * y1) / (mathSqrt$3(x0 * x0 + y0 * y0) * mathSqrt$3(x1 * x1 + y1 * y1))) / 2);
  13869. var b = mathSqrt$3(it_1[0] * it_1[0] + it_1[1] * it_1[1]);
  13870. limitedOcrMax = mathMin$4(ocrMax, (radius - b) / (a + 1));
  13871. limitedIcrMax = mathMin$4(icrMax, (innerRadius - b) / (a - 1));
  13872. }
  13873. }
  13874. }
  13875. }
  13876. if (!hasArc) {
  13877. ctx.moveTo(cx + xrs, cy + yrs);
  13878. }
  13879. else if (limitedOcrMax > e) {
  13880. var crStart = mathMin$4(ocrStart, limitedOcrMax);
  13881. var crEnd = mathMin$4(ocrEnd, limitedOcrMax);
  13882. var ct0 = computeCornerTangents(xirs, yirs, xrs, yrs, radius, crStart, clockwise);
  13883. var ct1 = computeCornerTangents(xre, yre, xire, yire, radius, crEnd, clockwise);
  13884. ctx.moveTo(cx + ct0.cx + ct0.x0, cy + ct0.cy + ct0.y0);
  13885. if (limitedOcrMax < ocrMax && crStart === crEnd) {
  13886. ctx.arc(cx + ct0.cx, cy + ct0.cy, limitedOcrMax, mathATan2(ct0.y0, ct0.x0), mathATan2(ct1.y0, ct1.x0), !clockwise);
  13887. }
  13888. else {
  13889. crStart > 0 && ctx.arc(cx + ct0.cx, cy + ct0.cy, crStart, mathATan2(ct0.y0, ct0.x0), mathATan2(ct0.y1, ct0.x1), !clockwise);
  13890. ctx.arc(cx, cy, radius, mathATan2(ct0.cy + ct0.y1, ct0.cx + ct0.x1), mathATan2(ct1.cy + ct1.y1, ct1.cx + ct1.x1), !clockwise);
  13891. crEnd > 0 && ctx.arc(cx + ct1.cx, cy + ct1.cy, crEnd, mathATan2(ct1.y1, ct1.x1), mathATan2(ct1.y0, ct1.x0), !clockwise);
  13892. }
  13893. }
  13894. else {
  13895. ctx.moveTo(cx + xrs, cy + yrs);
  13896. ctx.arc(cx, cy, radius, startAngle, endAngle, !clockwise);
  13897. }
  13898. if (!(innerRadius > e) || !hasArc) {
  13899. ctx.lineTo(cx + xire, cy + yire);
  13900. }
  13901. else if (limitedIcrMax > e) {
  13902. var crStart = mathMin$4(icrStart, limitedIcrMax);
  13903. var crEnd = mathMin$4(icrEnd, limitedIcrMax);
  13904. var ct0 = computeCornerTangents(xire, yire, xre, yre, innerRadius, -crEnd, clockwise);
  13905. var ct1 = computeCornerTangents(xrs, yrs, xirs, yirs, innerRadius, -crStart, clockwise);
  13906. ctx.lineTo(cx + ct0.cx + ct0.x0, cy + ct0.cy + ct0.y0);
  13907. if (limitedIcrMax < icrMax && crStart === crEnd) {
  13908. ctx.arc(cx + ct0.cx, cy + ct0.cy, limitedIcrMax, mathATan2(ct0.y0, ct0.x0), mathATan2(ct1.y0, ct1.x0), !clockwise);
  13909. }
  13910. else {
  13911. crEnd > 0 && ctx.arc(cx + ct0.cx, cy + ct0.cy, crEnd, mathATan2(ct0.y0, ct0.x0), mathATan2(ct0.y1, ct0.x1), !clockwise);
  13912. ctx.arc(cx, cy, innerRadius, mathATan2(ct0.cy + ct0.y1, ct0.cx + ct0.x1), mathATan2(ct1.cy + ct1.y1, ct1.cx + ct1.x1), clockwise);
  13913. crStart > 0 && ctx.arc(cx + ct1.cx, cy + ct1.cy, crStart, mathATan2(ct1.y1, ct1.x1), mathATan2(ct1.y0, ct1.x0), !clockwise);
  13914. }
  13915. }
  13916. else {
  13917. ctx.lineTo(cx + xire, cy + yire);
  13918. ctx.arc(cx, cy, innerRadius, endAngle, startAngle, clockwise);
  13919. }
  13920. }
  13921. ctx.closePath();
  13922. }
  13923. var SectorShape = (function () {
  13924. function SectorShape() {
  13925. this.cx = 0;
  13926. this.cy = 0;
  13927. this.r0 = 0;
  13928. this.r = 0;
  13929. this.startAngle = 0;
  13930. this.endAngle = Math.PI * 2;
  13931. this.clockwise = true;
  13932. this.cornerRadius = 0;
  13933. }
  13934. return SectorShape;
  13935. }());
  13936. var Sector = (function (_super) {
  13937. __extends(Sector, _super);
  13938. function Sector(opts) {
  13939. return _super.call(this, opts) || this;
  13940. }
  13941. Sector.prototype.getDefaultShape = function () {
  13942. return new SectorShape();
  13943. };
  13944. Sector.prototype.buildPath = function (ctx, shape) {
  13945. buildPath$1(ctx, shape);
  13946. };
  13947. Sector.prototype.isZeroArea = function () {
  13948. return this.shape.startAngle === this.shape.endAngle
  13949. || this.shape.r === this.shape.r0;
  13950. };
  13951. return Sector;
  13952. }(Path));
  13953. Sector.prototype.type = 'sector';
  13954. var RingShape = (function () {
  13955. function RingShape() {
  13956. this.cx = 0;
  13957. this.cy = 0;
  13958. this.r = 0;
  13959. this.r0 = 0;
  13960. }
  13961. return RingShape;
  13962. }());
  13963. var Ring = (function (_super) {
  13964. __extends(Ring, _super);
  13965. function Ring(opts) {
  13966. return _super.call(this, opts) || this;
  13967. }
  13968. Ring.prototype.getDefaultShape = function () {
  13969. return new RingShape();
  13970. };
  13971. Ring.prototype.buildPath = function (ctx, shape) {
  13972. var x = shape.cx;
  13973. var y = shape.cy;
  13974. var PI2 = Math.PI * 2;
  13975. ctx.moveTo(x + shape.r, y);
  13976. ctx.arc(x, y, shape.r, 0, PI2, false);
  13977. ctx.moveTo(x + shape.r0, y);
  13978. ctx.arc(x, y, shape.r0, 0, PI2, true);
  13979. };
  13980. return Ring;
  13981. }(Path));
  13982. Ring.prototype.type = 'ring';
  13983. function smoothBezier(points, smooth, isLoop, constraint) {
  13984. var cps = [];
  13985. var v = [];
  13986. var v1 = [];
  13987. var v2 = [];
  13988. var prevPoint;
  13989. var nextPoint;
  13990. var min$1;
  13991. var max$1;
  13992. if (constraint) {
  13993. min$1 = [Infinity, Infinity];
  13994. max$1 = [-Infinity, -Infinity];
  13995. for (var i = 0, len = points.length; i < len; i++) {
  13996. min(min$1, min$1, points[i]);
  13997. max(max$1, max$1, points[i]);
  13998. }
  13999. min(min$1, min$1, constraint[0]);
  14000. max(max$1, max$1, constraint[1]);
  14001. }
  14002. for (var i = 0, len = points.length; i < len; i++) {
  14003. var point = points[i];
  14004. if (isLoop) {
  14005. prevPoint = points[i ? i - 1 : len - 1];
  14006. nextPoint = points[(i + 1) % len];
  14007. }
  14008. else {
  14009. if (i === 0 || i === len - 1) {
  14010. cps.push(clone$1(points[i]));
  14011. continue;
  14012. }
  14013. else {
  14014. prevPoint = points[i - 1];
  14015. nextPoint = points[i + 1];
  14016. }
  14017. }
  14018. sub(v, nextPoint, prevPoint);
  14019. scale(v, v, smooth);
  14020. var d0 = distance(point, prevPoint);
  14021. var d1 = distance(point, nextPoint);
  14022. var sum = d0 + d1;
  14023. if (sum !== 0) {
  14024. d0 /= sum;
  14025. d1 /= sum;
  14026. }
  14027. scale(v1, v, -d0);
  14028. scale(v2, v, d1);
  14029. var cp0 = add([], point, v1);
  14030. var cp1 = add([], point, v2);
  14031. if (constraint) {
  14032. max(cp0, cp0, min$1);
  14033. min(cp0, cp0, max$1);
  14034. max(cp1, cp1, min$1);
  14035. min(cp1, cp1, max$1);
  14036. }
  14037. cps.push(cp0);
  14038. cps.push(cp1);
  14039. }
  14040. if (isLoop) {
  14041. cps.push(cps.shift());
  14042. }
  14043. return cps;
  14044. }
  14045. function buildPath$2(ctx, shape, closePath) {
  14046. var smooth = shape.smooth;
  14047. var points = shape.points;
  14048. if (points && points.length >= 2) {
  14049. if (smooth) {
  14050. var controlPoints = smoothBezier(points, smooth, closePath, shape.smoothConstraint);
  14051. ctx.moveTo(points[0][0], points[0][1]);
  14052. var len = points.length;
  14053. for (var i = 0; i < (closePath ? len : len - 1); i++) {
  14054. var cp1 = controlPoints[i * 2];
  14055. var cp2 = controlPoints[i * 2 + 1];
  14056. var p = points[(i + 1) % len];
  14057. ctx.bezierCurveTo(cp1[0], cp1[1], cp2[0], cp2[1], p[0], p[1]);
  14058. }
  14059. }
  14060. else {
  14061. ctx.moveTo(points[0][0], points[0][1]);
  14062. for (var i = 1, l = points.length; i < l; i++) {
  14063. ctx.lineTo(points[i][0], points[i][1]);
  14064. }
  14065. }
  14066. closePath && ctx.closePath();
  14067. }
  14068. }
  14069. var PolygonShape = (function () {
  14070. function PolygonShape() {
  14071. this.points = null;
  14072. this.smooth = 0;
  14073. this.smoothConstraint = null;
  14074. }
  14075. return PolygonShape;
  14076. }());
  14077. var Polygon = (function (_super) {
  14078. __extends(Polygon, _super);
  14079. function Polygon(opts) {
  14080. return _super.call(this, opts) || this;
  14081. }
  14082. Polygon.prototype.getDefaultShape = function () {
  14083. return new PolygonShape();
  14084. };
  14085. Polygon.prototype.buildPath = function (ctx, shape) {
  14086. buildPath$2(ctx, shape, true);
  14087. };
  14088. return Polygon;
  14089. }(Path));
  14090. Polygon.prototype.type = 'polygon';
  14091. var PolylineShape = (function () {
  14092. function PolylineShape() {
  14093. this.points = null;
  14094. this.percent = 1;
  14095. this.smooth = 0;
  14096. this.smoothConstraint = null;
  14097. }
  14098. return PolylineShape;
  14099. }());
  14100. var Polyline = (function (_super) {
  14101. __extends(Polyline, _super);
  14102. function Polyline(opts) {
  14103. return _super.call(this, opts) || this;
  14104. }
  14105. Polyline.prototype.getDefaultStyle = function () {
  14106. return {
  14107. stroke: '#000',
  14108. fill: null
  14109. };
  14110. };
  14111. Polyline.prototype.getDefaultShape = function () {
  14112. return new PolylineShape();
  14113. };
  14114. Polyline.prototype.buildPath = function (ctx, shape) {
  14115. buildPath$2(ctx, shape, false);
  14116. };
  14117. return Polyline;
  14118. }(Path));
  14119. Polyline.prototype.type = 'polyline';
  14120. var subPixelOptimizeOutputShape$1 = {};
  14121. var LineShape = (function () {
  14122. function LineShape() {
  14123. this.x1 = 0;
  14124. this.y1 = 0;
  14125. this.x2 = 0;
  14126. this.y2 = 0;
  14127. this.percent = 1;
  14128. }
  14129. return LineShape;
  14130. }());
  14131. var Line = (function (_super) {
  14132. __extends(Line, _super);
  14133. function Line(opts) {
  14134. return _super.call(this, opts) || this;
  14135. }
  14136. Line.prototype.getDefaultStyle = function () {
  14137. return {
  14138. stroke: '#000',
  14139. fill: null
  14140. };
  14141. };
  14142. Line.prototype.getDefaultShape = function () {
  14143. return new LineShape();
  14144. };
  14145. Line.prototype.buildPath = function (ctx, shape) {
  14146. var x1;
  14147. var y1;
  14148. var x2;
  14149. var y2;
  14150. if (this.subPixelOptimize) {
  14151. var optimizedShape = subPixelOptimizeLine(subPixelOptimizeOutputShape$1, shape, this.style);
  14152. x1 = optimizedShape.x1;
  14153. y1 = optimizedShape.y1;
  14154. x2 = optimizedShape.x2;
  14155. y2 = optimizedShape.y2;
  14156. }
  14157. else {
  14158. x1 = shape.x1;
  14159. y1 = shape.y1;
  14160. x2 = shape.x2;
  14161. y2 = shape.y2;
  14162. }
  14163. var percent = shape.percent;
  14164. if (percent === 0) {
  14165. return;
  14166. }
  14167. ctx.moveTo(x1, y1);
  14168. if (percent < 1) {
  14169. x2 = x1 * (1 - percent) + x2 * percent;
  14170. y2 = y1 * (1 - percent) + y2 * percent;
  14171. }
  14172. ctx.lineTo(x2, y2);
  14173. };
  14174. Line.prototype.pointAt = function (p) {
  14175. var shape = this.shape;
  14176. return [
  14177. shape.x1 * (1 - p) + shape.x2 * p,
  14178. shape.y1 * (1 - p) + shape.y2 * p
  14179. ];
  14180. };
  14181. return Line;
  14182. }(Path));
  14183. Line.prototype.type = 'line';
  14184. var out = [];
  14185. var BezierCurveShape = (function () {
  14186. function BezierCurveShape() {
  14187. this.x1 = 0;
  14188. this.y1 = 0;
  14189. this.x2 = 0;
  14190. this.y2 = 0;
  14191. this.cpx1 = 0;
  14192. this.cpy1 = 0;
  14193. this.percent = 1;
  14194. }
  14195. return BezierCurveShape;
  14196. }());
  14197. function someVectorAt(shape, t, isTangent) {
  14198. var cpx2 = shape.cpx2;
  14199. var cpy2 = shape.cpy2;
  14200. if (cpx2 != null || cpy2 != null) {
  14201. return [
  14202. (isTangent ? cubicDerivativeAt : cubicAt)(shape.x1, shape.cpx1, shape.cpx2, shape.x2, t),
  14203. (isTangent ? cubicDerivativeAt : cubicAt)(shape.y1, shape.cpy1, shape.cpy2, shape.y2, t)
  14204. ];
  14205. }
  14206. else {
  14207. return [
  14208. (isTangent ? quadraticDerivativeAt : quadraticAt)(shape.x1, shape.cpx1, shape.x2, t),
  14209. (isTangent ? quadraticDerivativeAt : quadraticAt)(shape.y1, shape.cpy1, shape.y2, t)
  14210. ];
  14211. }
  14212. }
  14213. var BezierCurve = (function (_super) {
  14214. __extends(BezierCurve, _super);
  14215. function BezierCurve(opts) {
  14216. return _super.call(this, opts) || this;
  14217. }
  14218. BezierCurve.prototype.getDefaultStyle = function () {
  14219. return {
  14220. stroke: '#000',
  14221. fill: null
  14222. };
  14223. };
  14224. BezierCurve.prototype.getDefaultShape = function () {
  14225. return new BezierCurveShape();
  14226. };
  14227. BezierCurve.prototype.buildPath = function (ctx, shape) {
  14228. var x1 = shape.x1;
  14229. var y1 = shape.y1;
  14230. var x2 = shape.x2;
  14231. var y2 = shape.y2;
  14232. var cpx1 = shape.cpx1;
  14233. var cpy1 = shape.cpy1;
  14234. var cpx2 = shape.cpx2;
  14235. var cpy2 = shape.cpy2;
  14236. var percent = shape.percent;
  14237. if (percent === 0) {
  14238. return;
  14239. }
  14240. ctx.moveTo(x1, y1);
  14241. if (cpx2 == null || cpy2 == null) {
  14242. if (percent < 1) {
  14243. quadraticSubdivide(x1, cpx1, x2, percent, out);
  14244. cpx1 = out[1];
  14245. x2 = out[2];
  14246. quadraticSubdivide(y1, cpy1, y2, percent, out);
  14247. cpy1 = out[1];
  14248. y2 = out[2];
  14249. }
  14250. ctx.quadraticCurveTo(cpx1, cpy1, x2, y2);
  14251. }
  14252. else {
  14253. if (percent < 1) {
  14254. cubicSubdivide(x1, cpx1, cpx2, x2, percent, out);
  14255. cpx1 = out[1];
  14256. cpx2 = out[2];
  14257. x2 = out[3];
  14258. cubicSubdivide(y1, cpy1, cpy2, y2, percent, out);
  14259. cpy1 = out[1];
  14260. cpy2 = out[2];
  14261. y2 = out[3];
  14262. }
  14263. ctx.bezierCurveTo(cpx1, cpy1, cpx2, cpy2, x2, y2);
  14264. }
  14265. };
  14266. BezierCurve.prototype.pointAt = function (t) {
  14267. return someVectorAt(this.shape, t, false);
  14268. };
  14269. BezierCurve.prototype.tangentAt = function (t) {
  14270. var p = someVectorAt(this.shape, t, true);
  14271. return normalize(p, p);
  14272. };
  14273. return BezierCurve;
  14274. }(Path));
  14275. BezierCurve.prototype.type = 'bezier-curve';
  14276. var ArcShape = (function () {
  14277. function ArcShape() {
  14278. this.cx = 0;
  14279. this.cy = 0;
  14280. this.r = 0;
  14281. this.startAngle = 0;
  14282. this.endAngle = Math.PI * 2;
  14283. this.clockwise = true;
  14284. }
  14285. return ArcShape;
  14286. }());
  14287. var Arc = (function (_super) {
  14288. __extends(Arc, _super);
  14289. function Arc(opts) {
  14290. return _super.call(this, opts) || this;
  14291. }
  14292. Arc.prototype.getDefaultStyle = function () {
  14293. return {
  14294. stroke: '#000',
  14295. fill: null
  14296. };
  14297. };
  14298. Arc.prototype.getDefaultShape = function () {
  14299. return new ArcShape();
  14300. };
  14301. Arc.prototype.buildPath = function (ctx, shape) {
  14302. var x = shape.cx;
  14303. var y = shape.cy;
  14304. var r = Math.max(shape.r, 0);
  14305. var startAngle = shape.startAngle;
  14306. var endAngle = shape.endAngle;
  14307. var clockwise = shape.clockwise;
  14308. var unitX = Math.cos(startAngle);
  14309. var unitY = Math.sin(startAngle);
  14310. ctx.moveTo(unitX * r + x, unitY * r + y);
  14311. ctx.arc(x, y, r, startAngle, endAngle, !clockwise);
  14312. };
  14313. return Arc;
  14314. }(Path));
  14315. Arc.prototype.type = 'arc';
  14316. var CompoundPath = (function (_super) {
  14317. __extends(CompoundPath, _super);
  14318. function CompoundPath() {
  14319. var _this = _super !== null && _super.apply(this, arguments) || this;
  14320. _this.type = 'compound';
  14321. return _this;
  14322. }
  14323. CompoundPath.prototype._updatePathDirty = function () {
  14324. var paths = this.shape.paths;
  14325. var dirtyPath = this.shapeChanged();
  14326. for (var i = 0; i < paths.length; i++) {
  14327. dirtyPath = dirtyPath || paths[i].shapeChanged();
  14328. }
  14329. if (dirtyPath) {
  14330. this.dirtyShape();
  14331. }
  14332. };
  14333. CompoundPath.prototype.beforeBrush = function () {
  14334. this._updatePathDirty();
  14335. var paths = this.shape.paths || [];
  14336. var scale = this.getGlobalScale();
  14337. for (var i = 0; i < paths.length; i++) {
  14338. if (!paths[i].path) {
  14339. paths[i].createPathProxy();
  14340. }
  14341. paths[i].path.setScale(scale[0], scale[1], paths[i].segmentIgnoreThreshold);
  14342. }
  14343. };
  14344. CompoundPath.prototype.buildPath = function (ctx, shape) {
  14345. var paths = shape.paths || [];
  14346. for (var i = 0; i < paths.length; i++) {
  14347. paths[i].buildPath(ctx, paths[i].shape, true);
  14348. }
  14349. };
  14350. CompoundPath.prototype.afterBrush = function () {
  14351. var paths = this.shape.paths || [];
  14352. for (var i = 0; i < paths.length; i++) {
  14353. paths[i].pathUpdated();
  14354. }
  14355. };
  14356. CompoundPath.prototype.getBoundingRect = function () {
  14357. this._updatePathDirty.call(this);
  14358. return Path.prototype.getBoundingRect.call(this);
  14359. };
  14360. return CompoundPath;
  14361. }(Path));
  14362. var Gradient = (function () {
  14363. function Gradient(colorStops) {
  14364. this.colorStops = colorStops || [];
  14365. }
  14366. Gradient.prototype.addColorStop = function (offset, color) {
  14367. this.colorStops.push({
  14368. offset: offset,
  14369. color: color
  14370. });
  14371. };
  14372. return Gradient;
  14373. }());
  14374. var LinearGradient = (function (_super) {
  14375. __extends(LinearGradient, _super);
  14376. function LinearGradient(x, y, x2, y2, colorStops, globalCoord) {
  14377. var _this = _super.call(this, colorStops) || this;
  14378. _this.x = x == null ? 0 : x;
  14379. _this.y = y == null ? 0 : y;
  14380. _this.x2 = x2 == null ? 1 : x2;
  14381. _this.y2 = y2 == null ? 0 : y2;
  14382. _this.type = 'linear';
  14383. _this.global = globalCoord || false;
  14384. return _this;
  14385. }
  14386. return LinearGradient;
  14387. }(Gradient));
  14388. var RadialGradient = (function (_super) {
  14389. __extends(RadialGradient, _super);
  14390. function RadialGradient(x, y, r, colorStops, globalCoord) {
  14391. var _this = _super.call(this, colorStops) || this;
  14392. _this.x = x == null ? 0.5 : x;
  14393. _this.y = y == null ? 0.5 : y;
  14394. _this.r = r == null ? 0.5 : r;
  14395. _this.type = 'radial';
  14396. _this.global = globalCoord || false;
  14397. return _this;
  14398. }
  14399. return RadialGradient;
  14400. }(Gradient));
  14401. var mathMin$5 = Math.min;
  14402. var mathMax$5 = Math.max;
  14403. var mathAbs$4 = Math.abs;
  14404. var _extent = [0, 0];
  14405. var _extent2 = [0, 0];
  14406. var _intersectCtx$1 = createIntersectContext();
  14407. var _minTv$1 = _intersectCtx$1.minTv;
  14408. var _maxTv$1 = _intersectCtx$1.maxTv;
  14409. var OrientedBoundingRect = (function () {
  14410. function OrientedBoundingRect(rect, transform) {
  14411. this._corners = [];
  14412. this._axes = [];
  14413. this._origin = [0, 0];
  14414. for (var i = 0; i < 4; i++) {
  14415. this._corners[i] = new Point();
  14416. }
  14417. for (var i = 0; i < 2; i++) {
  14418. this._axes[i] = new Point();
  14419. }
  14420. if (rect) {
  14421. this.fromBoundingRect(rect, transform);
  14422. }
  14423. }
  14424. OrientedBoundingRect.prototype.fromBoundingRect = function (rect, transform) {
  14425. var corners = this._corners;
  14426. var axes = this._axes;
  14427. var x = rect.x;
  14428. var y = rect.y;
  14429. var x2 = x + rect.width;
  14430. var y2 = y + rect.height;
  14431. corners[0].set(x, y);
  14432. corners[1].set(x2, y);
  14433. corners[2].set(x2, y2);
  14434. corners[3].set(x, y2);
  14435. if (transform) {
  14436. for (var i = 0; i < 4; i++) {
  14437. corners[i].transform(transform);
  14438. }
  14439. }
  14440. Point.sub(axes[0], corners[1], corners[0]);
  14441. Point.sub(axes[1], corners[3], corners[0]);
  14442. axes[0].normalize();
  14443. axes[1].normalize();
  14444. for (var i = 0; i < 2; i++) {
  14445. this._origin[i] = axes[i].dot(corners[0]);
  14446. }
  14447. };
  14448. OrientedBoundingRect.prototype.intersect = function (other, mtv, opt) {
  14449. var overlapped = true;
  14450. var noMtv = !mtv;
  14451. if (mtv) {
  14452. Point.set(mtv, 0, 0);
  14453. }
  14454. _intersectCtx$1.reset(opt, !noMtv);
  14455. if (!this._intersectCheckOneSide(this, other, noMtv, 1)) {
  14456. overlapped = false;
  14457. if (noMtv) {
  14458. return overlapped;
  14459. }
  14460. }
  14461. if (!this._intersectCheckOneSide(other, this, noMtv, -1)) {
  14462. overlapped = false;
  14463. if (noMtv) {
  14464. return overlapped;
  14465. }
  14466. }
  14467. if (!noMtv && !_intersectCtx$1.negativeSize) {
  14468. Point.copy(mtv, overlapped
  14469. ? (_intersectCtx$1.useDir ? _intersectCtx$1.dirMinTv : _minTv$1)
  14470. : _maxTv$1);
  14471. }
  14472. return overlapped;
  14473. };
  14474. OrientedBoundingRect.prototype._intersectCheckOneSide = function (self, other, noMtv, inverse) {
  14475. var overlapped = true;
  14476. for (var i = 0; i < 2; i++) {
  14477. var axis = self._axes[i];
  14478. self._getProjMinMaxOnAxis(i, self._corners, _extent);
  14479. self._getProjMinMaxOnAxis(i, other._corners, _extent2);
  14480. if (_intersectCtx$1.negativeSize || _extent[1] < _extent2[0] || _extent[0] > _extent2[1]) {
  14481. overlapped = false;
  14482. if (_intersectCtx$1.negativeSize || noMtv) {
  14483. return overlapped;
  14484. }
  14485. var dist0 = mathAbs$4(_extent2[0] - _extent[1]);
  14486. var dist1 = mathAbs$4(_extent[0] - _extent2[1]);
  14487. if (mathMin$5(dist0, dist1) > _maxTv$1.len()) {
  14488. if (dist0 < dist1) {
  14489. Point.scale(_maxTv$1, axis, -dist0 * inverse);
  14490. }
  14491. else {
  14492. Point.scale(_maxTv$1, axis, dist1 * inverse);
  14493. }
  14494. }
  14495. }
  14496. else if (!noMtv) {
  14497. var dist0 = mathAbs$4(_extent2[0] - _extent[1]);
  14498. var dist1 = mathAbs$4(_extent[0] - _extent2[1]);
  14499. if (_intersectCtx$1.useDir || mathMin$5(dist0, dist1) < _minTv$1.len()) {
  14500. if (dist0 < dist1 || !_intersectCtx$1.bidirectional) {
  14501. Point.scale(_minTv$1, axis, dist0 * inverse);
  14502. if (_intersectCtx$1.useDir) {
  14503. _intersectCtx$1.calcDirMTV();
  14504. }
  14505. }
  14506. if (dist0 >= dist1 || !_intersectCtx$1.bidirectional) {
  14507. Point.scale(_minTv$1, axis, -dist1 * inverse);
  14508. if (_intersectCtx$1.useDir) {
  14509. _intersectCtx$1.calcDirMTV();
  14510. }
  14511. }
  14512. }
  14513. }
  14514. }
  14515. return overlapped;
  14516. };
  14517. OrientedBoundingRect.prototype._getProjMinMaxOnAxis = function (dim, corners, out) {
  14518. var axis = this._axes[dim];
  14519. var origin = this._origin;
  14520. var proj = corners[0].dot(axis) + origin[dim];
  14521. var min = proj;
  14522. var max = proj;
  14523. for (var i = 1; i < corners.length; i++) {
  14524. var proj_1 = corners[i].dot(axis) + origin[dim];
  14525. min = mathMin$5(proj_1, min);
  14526. max = mathMax$5(proj_1, max);
  14527. }
  14528. out[0] = min + _intersectCtx$1.touchThreshold;
  14529. out[1] = max - _intersectCtx$1.touchThreshold;
  14530. _intersectCtx$1.negativeSize = out[1] < out[0];
  14531. };
  14532. return OrientedBoundingRect;
  14533. }());
  14534. var m = [];
  14535. var IncrementalDisplayable = (function (_super) {
  14536. __extends(IncrementalDisplayable, _super);
  14537. function IncrementalDisplayable() {
  14538. var _this = _super !== null && _super.apply(this, arguments) || this;
  14539. _this.notClear = true;
  14540. _this.incremental = true;
  14541. _this._displayables = [];
  14542. _this._temporaryDisplayables = [];
  14543. _this._cursor = 0;
  14544. return _this;
  14545. }
  14546. IncrementalDisplayable.prototype.traverse = function (cb, context) {
  14547. cb.call(context, this);
  14548. };
  14549. IncrementalDisplayable.prototype.useStyle = function () {
  14550. this.style = {};
  14551. };
  14552. IncrementalDisplayable.prototype.getCursor = function () {
  14553. return this._cursor;
  14554. };
  14555. IncrementalDisplayable.prototype.innerAfterBrush = function () {
  14556. this._cursor = this._displayables.length;
  14557. };
  14558. IncrementalDisplayable.prototype.clearDisplaybles = function () {
  14559. this._displayables = [];
  14560. this._temporaryDisplayables = [];
  14561. this._cursor = 0;
  14562. this.markRedraw();
  14563. this.notClear = false;
  14564. };
  14565. IncrementalDisplayable.prototype.clearTemporalDisplayables = function () {
  14566. this._temporaryDisplayables = [];
  14567. };
  14568. IncrementalDisplayable.prototype.addDisplayable = function (displayable, notPersistent) {
  14569. if (notPersistent) {
  14570. this._temporaryDisplayables.push(displayable);
  14571. }
  14572. else {
  14573. this._displayables.push(displayable);
  14574. }
  14575. this.markRedraw();
  14576. };
  14577. IncrementalDisplayable.prototype.addDisplayables = function (displayables, notPersistent) {
  14578. notPersistent = notPersistent || false;
  14579. for (var i = 0; i < displayables.length; i++) {
  14580. this.addDisplayable(displayables[i], notPersistent);
  14581. }
  14582. };
  14583. IncrementalDisplayable.prototype.getDisplayables = function () {
  14584. return this._displayables;
  14585. };
  14586. IncrementalDisplayable.prototype.getTemporalDisplayables = function () {
  14587. return this._temporaryDisplayables;
  14588. };
  14589. IncrementalDisplayable.prototype.eachPendingDisplayable = function (cb) {
  14590. for (var i = this._cursor; i < this._displayables.length; i++) {
  14591. cb && cb(this._displayables[i]);
  14592. }
  14593. for (var i = 0; i < this._temporaryDisplayables.length; i++) {
  14594. cb && cb(this._temporaryDisplayables[i]);
  14595. }
  14596. };
  14597. IncrementalDisplayable.prototype.update = function () {
  14598. this.updateTransform();
  14599. for (var i = this._cursor; i < this._displayables.length; i++) {
  14600. var displayable = this._displayables[i];
  14601. displayable.parent = this;
  14602. displayable.update();
  14603. displayable.parent = null;
  14604. }
  14605. for (var i = 0; i < this._temporaryDisplayables.length; i++) {
  14606. var displayable = this._temporaryDisplayables[i];
  14607. displayable.parent = this;
  14608. displayable.update();
  14609. displayable.parent = null;
  14610. }
  14611. };
  14612. IncrementalDisplayable.prototype.getBoundingRect = function () {
  14613. if (!this._rect) {
  14614. var rect = new BoundingRect(Infinity, Infinity, -Infinity, -Infinity);
  14615. for (var i = 0; i < this._displayables.length; i++) {
  14616. var displayable = this._displayables[i];
  14617. var childRect = displayable.getBoundingRect().clone();
  14618. if (displayable.needLocalTransform()) {
  14619. childRect.applyTransform(displayable.getLocalTransform(m));
  14620. }
  14621. rect.union(childRect);
  14622. }
  14623. this._rect = rect;
  14624. }
  14625. return this._rect;
  14626. };
  14627. IncrementalDisplayable.prototype.contain = function (x, y) {
  14628. var localPos = this.transformCoordToLocal(x, y);
  14629. var rect = this.getBoundingRect();
  14630. if (rect.contain(localPos[0], localPos[1])) {
  14631. for (var i = 0; i < this._displayables.length; i++) {
  14632. var displayable = this._displayables[i];
  14633. if (displayable.contain(x, y)) {
  14634. return true;
  14635. }
  14636. }
  14637. }
  14638. return false;
  14639. };
  14640. return IncrementalDisplayable;
  14641. }(Displayable));
  14642. // Stored properties for further transition.
  14643. var transitionStore = makeInner();
  14644. /**
  14645. * Return null if animation is disabled.
  14646. */
  14647. function getAnimationConfig(animationType, animatableModel, dataIndex,
  14648. // Extra opts can override the option in animatable model.
  14649. extraOpts,
  14650. // TODO It's only for pictorial bar now.
  14651. extraDelayParams) {
  14652. var animationPayload;
  14653. // Check if there is global animation configuration from dataZoom/resize can override the config in option.
  14654. // If animation is enabled. Will use this animation config in payload.
  14655. // If animation is disabled. Just ignore it.
  14656. if (animatableModel && animatableModel.ecModel) {
  14657. var updatePayload = animatableModel.ecModel.getUpdatePayload();
  14658. animationPayload = updatePayload && updatePayload.animation;
  14659. }
  14660. var animationEnabled = animatableModel && animatableModel.isAnimationEnabled();
  14661. var isUpdate = animationType === 'update';
  14662. if (animationEnabled) {
  14663. var duration = void 0;
  14664. var easing = void 0;
  14665. var delay = void 0;
  14666. if (extraOpts) {
  14667. duration = retrieve2(extraOpts.duration, 200);
  14668. easing = retrieve2(extraOpts.easing, 'cubicOut');
  14669. delay = 0;
  14670. } else {
  14671. duration = animatableModel.getShallow(isUpdate ? 'animationDurationUpdate' : 'animationDuration');
  14672. easing = animatableModel.getShallow(isUpdate ? 'animationEasingUpdate' : 'animationEasing');
  14673. delay = animatableModel.getShallow(isUpdate ? 'animationDelayUpdate' : 'animationDelay');
  14674. }
  14675. // animation from payload has highest priority.
  14676. if (animationPayload) {
  14677. animationPayload.duration != null && (duration = animationPayload.duration);
  14678. animationPayload.easing != null && (easing = animationPayload.easing);
  14679. animationPayload.delay != null && (delay = animationPayload.delay);
  14680. }
  14681. if (isFunction(delay)) {
  14682. delay = delay(dataIndex, extraDelayParams);
  14683. }
  14684. if (isFunction(duration)) {
  14685. duration = duration(dataIndex);
  14686. }
  14687. var config = {
  14688. duration: duration || 0,
  14689. delay: delay,
  14690. easing: easing
  14691. };
  14692. return config;
  14693. } else {
  14694. return null;
  14695. }
  14696. }
  14697. function animateOrSetProps(animationType, el, props, animatableModel, dataIndex, cb, during) {
  14698. var isFrom = false;
  14699. var removeOpt;
  14700. if (isFunction(dataIndex)) {
  14701. during = cb;
  14702. cb = dataIndex;
  14703. dataIndex = null;
  14704. } else if (isObject(dataIndex)) {
  14705. cb = dataIndex.cb;
  14706. during = dataIndex.during;
  14707. isFrom = dataIndex.isFrom;
  14708. removeOpt = dataIndex.removeOpt;
  14709. dataIndex = dataIndex.dataIndex;
  14710. }
  14711. var isRemove = animationType === 'leave';
  14712. if (!isRemove) {
  14713. // Must stop the remove animation.
  14714. el.stopAnimation('leave');
  14715. }
  14716. var animationConfig = getAnimationConfig(animationType, animatableModel, dataIndex, isRemove ? removeOpt || {} : null, animatableModel && animatableModel.getAnimationDelayParams ? animatableModel.getAnimationDelayParams(el, dataIndex) : null);
  14717. if (animationConfig && animationConfig.duration > 0) {
  14718. var duration = animationConfig.duration;
  14719. var animationDelay = animationConfig.delay;
  14720. var animationEasing = animationConfig.easing;
  14721. var animateConfig = {
  14722. duration: duration,
  14723. delay: animationDelay || 0,
  14724. easing: animationEasing,
  14725. done: cb,
  14726. force: !!cb || !!during,
  14727. // Set to final state in update/init animation.
  14728. // So the post processing based on the path shape can be done correctly.
  14729. setToFinal: !isRemove,
  14730. scope: animationType,
  14731. during: during
  14732. };
  14733. isFrom ? el.animateFrom(props, animateConfig) : el.animateTo(props, animateConfig);
  14734. } else {
  14735. el.stopAnimation();
  14736. // If `isFrom`, the props is the "from" props.
  14737. !isFrom && el.attr(props);
  14738. // Call during at least once.
  14739. during && during(1);
  14740. cb && cb();
  14741. }
  14742. }
  14743. /**
  14744. * Update graphic element properties with or without animation according to the
  14745. * configuration in series.
  14746. *
  14747. * Caution: this method will stop previous animation.
  14748. * So do not use this method to one element twice before
  14749. * animation starts, unless you know what you are doing.
  14750. * @example
  14751. * graphic.updateProps(el, {
  14752. * position: [100, 100]
  14753. * }, seriesModel, dataIndex, function () { console.log('Animation done!'); });
  14754. * // Or
  14755. * graphic.updateProps(el, {
  14756. * position: [100, 100]
  14757. * }, seriesModel, function () { console.log('Animation done!'); });
  14758. */
  14759. function updateProps(el, props,
  14760. // TODO: TYPE AnimatableModel
  14761. animatableModel, dataIndex, cb, during) {
  14762. animateOrSetProps('update', el, props, animatableModel, dataIndex, cb, during);
  14763. }
  14764. /**
  14765. * Init graphic element properties with or without animation according to the
  14766. * configuration in series.
  14767. *
  14768. * Caution: this method will stop previous animation.
  14769. * So do not use this method to one element twice before
  14770. * animation starts, unless you know what you are doing.
  14771. */
  14772. function initProps(el, props, animatableModel, dataIndex, cb, during) {
  14773. animateOrSetProps('enter', el, props, animatableModel, dataIndex, cb, during);
  14774. }
  14775. /**
  14776. * If element is removed.
  14777. * It can determine if element is having remove animation.
  14778. */
  14779. function isElementRemoved(el) {
  14780. if (!el.__zr) {
  14781. return true;
  14782. }
  14783. for (var i = 0; i < el.animators.length; i++) {
  14784. var animator = el.animators[i];
  14785. if (animator.scope === 'leave') {
  14786. return true;
  14787. }
  14788. }
  14789. return false;
  14790. }
  14791. /**
  14792. * Remove graphic element
  14793. */
  14794. function removeElement(el, props, animatableModel, dataIndex, cb, during) {
  14795. // Don't do remove animation twice.
  14796. if (isElementRemoved(el)) {
  14797. return;
  14798. }
  14799. animateOrSetProps('leave', el, props, animatableModel, dataIndex, cb, during);
  14800. }
  14801. function fadeOutDisplayable(el, animatableModel, dataIndex, done) {
  14802. el.removeTextContent();
  14803. el.removeTextGuideLine();
  14804. removeElement(el, {
  14805. style: {
  14806. opacity: 0
  14807. }
  14808. }, animatableModel, dataIndex, done);
  14809. }
  14810. function removeElementWithFadeOut(el, animatableModel, dataIndex) {
  14811. function doRemove() {
  14812. el.parent && el.parent.remove(el);
  14813. }
  14814. // Hide label and labelLine first
  14815. // TODO Also use fade out animation?
  14816. if (!el.isGroup) {
  14817. fadeOutDisplayable(el, animatableModel, dataIndex, doRemove);
  14818. } else {
  14819. el.traverse(function (disp) {
  14820. if (!disp.isGroup) {
  14821. // Can invoke doRemove multiple times.
  14822. fadeOutDisplayable(disp, animatableModel, dataIndex, doRemove);
  14823. }
  14824. });
  14825. }
  14826. }
  14827. /**
  14828. * Save old style for style transition in universalTransition module.
  14829. * It's used when element will be reused in each render.
  14830. * For chart like map, heatmap, which will always create new element.
  14831. * We don't need to save this because universalTransition can get old style from the old element
  14832. */
  14833. function saveOldStyle(el) {
  14834. transitionStore(el).oldStyle = el.style;
  14835. }
  14836. function getOldStyle(el) {
  14837. return transitionStore(el).oldStyle;
  14838. }
  14839. var _customShapeMap = {};
  14840. var XY$1 = ['x', 'y'];
  14841. var WH$1 = ['width', 'height'];
  14842. /**
  14843. * Extend shape with parameters
  14844. */
  14845. function extendShape(opts) {
  14846. return Path.extend(opts);
  14847. }
  14848. var extendPathFromString = extendFromString;
  14849. /**
  14850. * Extend path
  14851. */
  14852. function extendPath(pathData, opts) {
  14853. return extendPathFromString(pathData, opts);
  14854. }
  14855. /**
  14856. * Register a user defined shape.
  14857. * The shape class can be fetched by `getShapeClass`
  14858. * This method will overwrite the registered shapes, including
  14859. * the registered built-in shapes, if using the same `name`.
  14860. * The shape can be used in `custom series` and
  14861. * `graphic component` by declaring `{type: name}`.
  14862. *
  14863. * @param name
  14864. * @param ShapeClass Can be generated by `extendShape`.
  14865. */
  14866. function registerShape(name, ShapeClass) {
  14867. _customShapeMap[name] = ShapeClass;
  14868. }
  14869. /**
  14870. * Find shape class registered by `registerShape`. Usually used in
  14871. * fetching user defined shape.
  14872. *
  14873. * [Caution]:
  14874. * (1) This method **MUST NOT be used inside echarts !!!**, unless it is prepared
  14875. * to use user registered shapes.
  14876. * Because the built-in shape (see `getBuiltInShape`) will be registered by
  14877. * `registerShape` by default. That enables users to get both built-in
  14878. * shapes as well as the shapes belonging to themsleves. But users can overwrite
  14879. * the built-in shapes by using names like 'circle', 'rect' via calling
  14880. * `registerShape`. So the echarts inner featrues should not fetch shapes from here
  14881. * in case that it is overwritten by users, except that some features, like
  14882. * `custom series`, `graphic component`, do it deliberately.
  14883. *
  14884. * (2) In the features like `custom series`, `graphic component`, the user input
  14885. * `{tpye: 'xxx'}` does not only specify shapes but also specify other graphic
  14886. * elements like `'group'`, `'text'`, `'image'` or event `'path'`. Those names
  14887. * are reserved names, that is, if some user registers a shape named `'image'`,
  14888. * the shape will not be used. If we intending to add some more reserved names
  14889. * in feature, that might bring break changes (disable some existing user shape
  14890. * names). But that case probably rarely happens. So we don't make more mechanism
  14891. * to resolve this issue here.
  14892. *
  14893. * @param name
  14894. * @return The shape class. If not found, return nothing.
  14895. */
  14896. function getShapeClass(name) {
  14897. if (_customShapeMap.hasOwnProperty(name)) {
  14898. return _customShapeMap[name];
  14899. }
  14900. }
  14901. /**
  14902. * Create a path element from path data string
  14903. * @param pathData
  14904. * @param opts
  14905. * @param rect
  14906. * @param layout 'center' or 'cover' default to be cover
  14907. */
  14908. function makePath(pathData, opts, rect, layout) {
  14909. var path = createFromString(pathData, opts);
  14910. if (rect) {
  14911. if (layout === 'center') {
  14912. rect = centerGraphic(rect, path.getBoundingRect());
  14913. }
  14914. resizePath(path, rect);
  14915. }
  14916. return path;
  14917. }
  14918. /**
  14919. * Create a image element from image url
  14920. * @param imageUrl image url
  14921. * @param opts options
  14922. * @param rect constrain rect
  14923. * @param layout 'center' or 'cover'. Default to be 'cover'
  14924. */
  14925. function makeImage(imageUrl, rect, layout) {
  14926. var zrImg = new ZRImage({
  14927. style: {
  14928. image: imageUrl,
  14929. x: rect.x,
  14930. y: rect.y,
  14931. width: rect.width,
  14932. height: rect.height
  14933. },
  14934. onload: function (img) {
  14935. if (layout === 'center') {
  14936. var boundingRect = {
  14937. width: img.width,
  14938. height: img.height
  14939. };
  14940. zrImg.setStyle(centerGraphic(rect, boundingRect));
  14941. }
  14942. }
  14943. });
  14944. return zrImg;
  14945. }
  14946. /**
  14947. * Get position of centered element in bounding box.
  14948. *
  14949. * @param rect element local bounding box
  14950. * @param boundingRect constraint bounding box
  14951. * @return element position containing x, y, width, and height
  14952. */
  14953. function centerGraphic(rect, boundingRect) {
  14954. // Set rect to center, keep width / height ratio.
  14955. var aspect = boundingRect.width / boundingRect.height;
  14956. var width = rect.height * aspect;
  14957. var height;
  14958. if (width <= rect.width) {
  14959. height = rect.height;
  14960. } else {
  14961. width = rect.width;
  14962. height = width / aspect;
  14963. }
  14964. var cx = rect.x + rect.width / 2;
  14965. var cy = rect.y + rect.height / 2;
  14966. return {
  14967. x: cx - width / 2,
  14968. y: cy - height / 2,
  14969. width: width,
  14970. height: height
  14971. };
  14972. }
  14973. var mergePath$1 = mergePath;
  14974. /**
  14975. * Resize a path to fit the rect
  14976. * @param path
  14977. * @param rect
  14978. */
  14979. function resizePath(path, rect) {
  14980. if (!path.applyTransform) {
  14981. return;
  14982. }
  14983. var pathRect = path.getBoundingRect();
  14984. var m = pathRect.calculateTransform(rect);
  14985. path.applyTransform(m);
  14986. }
  14987. /**
  14988. * Sub pixel optimize line for canvas
  14989. */
  14990. function subPixelOptimizeLine$1(shape, lineWidth) {
  14991. subPixelOptimizeLine(shape, shape, {
  14992. lineWidth: lineWidth
  14993. });
  14994. return shape;
  14995. }
  14996. /**
  14997. * Sub pixel optimize rect for canvas
  14998. */
  14999. function subPixelOptimizeRect$1(shape, style) {
  15000. subPixelOptimizeRect(shape, shape, style);
  15001. return shape;
  15002. }
  15003. /**
  15004. * Sub pixel optimize for canvas
  15005. *
  15006. * @param position Coordinate, such as x, y
  15007. * @param lineWidth Should be nonnegative integer.
  15008. * @param positiveOrNegative Default false (negative).
  15009. * @return Optimized position.
  15010. */
  15011. var subPixelOptimize$1 = subPixelOptimize;
  15012. /**
  15013. * Get transform matrix of target (param target),
  15014. * in coordinate of its ancestor (param ancestor)
  15015. *
  15016. * @param target
  15017. * @param [ancestor]
  15018. */
  15019. function getTransform(target, ancestor) {
  15020. var mat = identity([]);
  15021. while (target && target !== ancestor) {
  15022. mul$1(mat, target.getLocalTransform(), mat);
  15023. target = target.parent;
  15024. }
  15025. return mat;
  15026. }
  15027. /**
  15028. * Apply transform to an vertex.
  15029. * @param target [x, y]
  15030. * @param transform Can be:
  15031. * + Transform matrix: like [1, 0, 0, 1, 0, 0]
  15032. * + {position, rotation, scale}, the same as `zrender/Transformable`.
  15033. * @param invert Whether use invert matrix.
  15034. * @return [x, y]
  15035. */
  15036. function applyTransform$1(target, transform, invert$1) {
  15037. if (transform && !isArrayLike(transform)) {
  15038. transform = Transformable.getLocalTransform(transform);
  15039. }
  15040. if (invert$1) {
  15041. transform = invert([], transform);
  15042. }
  15043. return applyTransform([], target, transform);
  15044. }
  15045. /**
  15046. * @param direction 'left' 'right' 'top' 'bottom'
  15047. * @param transform Transform matrix: like [1, 0, 0, 1, 0, 0]
  15048. * @param invert Whether use invert matrix.
  15049. * @return Transformed direction. 'left' 'right' 'top' 'bottom'
  15050. */
  15051. function transformDirection(direction, transform, invert) {
  15052. // Pick a base, ensure that transform result will not be (0, 0).
  15053. var hBase = transform[4] === 0 || transform[5] === 0 || transform[0] === 0 ? 1 : mathAbs$1(2 * transform[4] / transform[0]);
  15054. var vBase = transform[4] === 0 || transform[5] === 0 || transform[2] === 0 ? 1 : mathAbs$1(2 * transform[4] / transform[2]);
  15055. var vertex = [direction === 'left' ? -hBase : direction === 'right' ? hBase : 0, direction === 'top' ? -vBase : direction === 'bottom' ? vBase : 0];
  15056. vertex = applyTransform$1(vertex, transform, invert);
  15057. return mathAbs$1(vertex[0]) > mathAbs$1(vertex[1]) ? vertex[0] > 0 ? 'right' : 'left' : vertex[1] > 0 ? 'bottom' : 'top';
  15058. }
  15059. function isNotGroup(el) {
  15060. return !el.isGroup;
  15061. }
  15062. function isPath(el) {
  15063. return el.shape != null;
  15064. }
  15065. /**
  15066. * Apply group transition animation from g1 to g2.
  15067. * If no animatableModel, no animation.
  15068. */
  15069. function groupTransition(g1, g2, animatableModel) {
  15070. if (!g1 || !g2) {
  15071. return;
  15072. }
  15073. function getElMap(g) {
  15074. var elMap = {};
  15075. g.traverse(function (el) {
  15076. if (isNotGroup(el) && el.anid) {
  15077. elMap[el.anid] = el;
  15078. }
  15079. });
  15080. return elMap;
  15081. }
  15082. function getAnimatableProps(el) {
  15083. var obj = {
  15084. x: el.x,
  15085. y: el.y,
  15086. rotation: el.rotation
  15087. };
  15088. if (isPath(el)) {
  15089. obj.shape = clone(el.shape);
  15090. }
  15091. return obj;
  15092. }
  15093. var elMap1 = getElMap(g1);
  15094. g2.traverse(function (el) {
  15095. if (isNotGroup(el) && el.anid) {
  15096. var oldEl = elMap1[el.anid];
  15097. if (oldEl) {
  15098. var newProp = getAnimatableProps(el);
  15099. el.attr(getAnimatableProps(oldEl));
  15100. updateProps(el, newProp, animatableModel, getECData(el).dataIndex);
  15101. }
  15102. }
  15103. });
  15104. }
  15105. function clipPointsByRect(points, rect) {
  15106. // FIXME: This way might be incorrect when graphic clipped by a corner
  15107. // and when element has a border.
  15108. return map(points, function (point) {
  15109. var x = point[0];
  15110. x = mathMax$1(x, rect.x);
  15111. x = mathMin$1(x, rect.x + rect.width);
  15112. var y = point[1];
  15113. y = mathMax$1(y, rect.y);
  15114. y = mathMin$1(y, rect.y + rect.height);
  15115. return [x, y];
  15116. });
  15117. }
  15118. /**
  15119. * Return a new clipped rect. If rect size are negative, return undefined.
  15120. */
  15121. function clipRectByRect(targetRect, rect) {
  15122. var x = mathMax$1(targetRect.x, rect.x);
  15123. var x2 = mathMin$1(targetRect.x + targetRect.width, rect.x + rect.width);
  15124. var y = mathMax$1(targetRect.y, rect.y);
  15125. var y2 = mathMin$1(targetRect.y + targetRect.height, rect.y + rect.height);
  15126. // If the total rect is cliped, nothing, including the border,
  15127. // should be painted. So return undefined.
  15128. if (x2 >= x && y2 >= y) {
  15129. return {
  15130. x: x,
  15131. y: y,
  15132. width: x2 - x,
  15133. height: y2 - y
  15134. };
  15135. }
  15136. }
  15137. function createIcon(iconStr,
  15138. // Support 'image://' or 'path://' or direct svg path.
  15139. opt, rect) {
  15140. var innerOpts = extend({
  15141. rectHover: true
  15142. }, opt);
  15143. var style = innerOpts.style = {
  15144. strokeNoScale: true
  15145. };
  15146. rect = rect || {
  15147. x: -1,
  15148. y: -1,
  15149. width: 2,
  15150. height: 2
  15151. };
  15152. if (iconStr) {
  15153. return iconStr.indexOf('image://') === 0 ? (style.image = iconStr.slice(8), defaults(style, rect), new ZRImage(innerOpts)) : makePath(iconStr.replace('path://', ''), innerOpts, rect, 'center');
  15154. }
  15155. }
  15156. /**
  15157. * Return `true` if the given line (line `a`) and the given polygon
  15158. * are intersect.
  15159. * Note that we do not count colinear as intersect here because no
  15160. * requirement for that. We could do that if required in future.
  15161. */
  15162. function linePolygonIntersect(a1x, a1y, a2x, a2y, points) {
  15163. for (var i = 0, p2 = points[points.length - 1]; i < points.length; i++) {
  15164. var p = points[i];
  15165. if (lineLineIntersect(a1x, a1y, a2x, a2y, p[0], p[1], p2[0], p2[1])) {
  15166. return true;
  15167. }
  15168. p2 = p;
  15169. }
  15170. }
  15171. /**
  15172. * Return `true` if the given two lines (line `a` and line `b`)
  15173. * are intersect.
  15174. * Note that we do not count colinear as intersect here because no
  15175. * requirement for that. We could do that if required in future.
  15176. */
  15177. function lineLineIntersect(a1x, a1y, a2x, a2y, b1x, b1y, b2x, b2y) {
  15178. // let `vec_m` to be `vec_a2 - vec_a1` and `vec_n` to be `vec_b2 - vec_b1`.
  15179. var mx = a2x - a1x;
  15180. var my = a2y - a1y;
  15181. var nx = b2x - b1x;
  15182. var ny = b2y - b1y;
  15183. // `vec_m` and `vec_n` are parallel iff
  15184. // existing `k` such that `vec_m = k · vec_n`, equivalent to `vec_m X vec_n = 0`.
  15185. var nmCrossProduct = crossProduct2d(nx, ny, mx, my);
  15186. if (nearZero(nmCrossProduct)) {
  15187. return false;
  15188. }
  15189. // `vec_m` and `vec_n` are intersect iff
  15190. // existing `p` and `q` in [0, 1] such that `vec_a1 + p * vec_m = vec_b1 + q * vec_n`,
  15191. // such that `q = ((vec_a1 - vec_b1) X vec_m) / (vec_n X vec_m)`
  15192. // and `p = ((vec_a1 - vec_b1) X vec_n) / (vec_n X vec_m)`.
  15193. var b1a1x = a1x - b1x;
  15194. var b1a1y = a1y - b1y;
  15195. var q = crossProduct2d(b1a1x, b1a1y, mx, my) / nmCrossProduct;
  15196. if (q < 0 || q > 1) {
  15197. return false;
  15198. }
  15199. var p = crossProduct2d(b1a1x, b1a1y, nx, ny) / nmCrossProduct;
  15200. if (p < 0 || p > 1) {
  15201. return false;
  15202. }
  15203. return true;
  15204. }
  15205. /**
  15206. * Cross product of 2-dimension vector.
  15207. */
  15208. function crossProduct2d(x1, y1, x2, y2) {
  15209. return x1 * y2 - x2 * y1;
  15210. }
  15211. function nearZero(val) {
  15212. return val <= 1e-6 && val >= -1e-6;
  15213. }
  15214. /**
  15215. * NOTE:
  15216. * A negative-width/height rect (due to negative margins) is not supported;
  15217. * it will be clampped to zero width/height.
  15218. * Although negative-width/height rects can be defined reasonably following the
  15219. * similar sense in CSS, but they are rarely used, hard to understand and complicated.
  15220. *
  15221. * @param rect Assume its width/height >= 0 if existing.
  15222. * x/y/width/height is allowed to be NaN,
  15223. * for the case that only x/width or y/height is intended to be computed.
  15224. * @param delta
  15225. * If be `number[]`, should be `[top, right, bottom, left]`,
  15226. * which can be used in padding or margin case.
  15227. * @see `normalizeCssArray` in `util/format.ts`
  15228. * If be `number`, it means [delta, delta, delta, delta],
  15229. * which can be used in lineWidth (borderWith) case,
  15230. * [NOTICE]: commonly pass lineWidth / 2, following the convention that border is
  15231. * half inside half outside of the rect.
  15232. * @param shrinkOrExpand
  15233. * `true` - shrink if `delta[i]` is positive, commmonly used in `padding` case.
  15234. * `false` - expand if `delta[i]` is positive, commmonly used in `margin` case. (default)
  15235. * @param noNegative
  15236. * `true` - negative `delta[i]` will be clampped to 0.
  15237. * `false` - No clamp to `delta`. (default).
  15238. * @return The input `rect`.
  15239. */
  15240. function expandOrShrinkRect(rect, delta, shrinkOrExpand, noNegative, minSize // by default [0, 0].
  15241. ) {
  15242. if (delta == null) {
  15243. return rect;
  15244. } else if (isNumber(delta)) {
  15245. _tmpExpandRectDelta[0] = _tmpExpandRectDelta[1] = _tmpExpandRectDelta[2] = _tmpExpandRectDelta[3] = delta;
  15246. } else {
  15247. if ("development" !== 'production') {
  15248. assert(delta.length === 4);
  15249. }
  15250. _tmpExpandRectDelta[0] = delta[0];
  15251. _tmpExpandRectDelta[1] = delta[1];
  15252. _tmpExpandRectDelta[2] = delta[2];
  15253. _tmpExpandRectDelta[3] = delta[3];
  15254. }
  15255. if (noNegative) {
  15256. _tmpExpandRectDelta[0] = mathMax$1(0, _tmpExpandRectDelta[0]);
  15257. _tmpExpandRectDelta[1] = mathMax$1(0, _tmpExpandRectDelta[1]);
  15258. _tmpExpandRectDelta[2] = mathMax$1(0, _tmpExpandRectDelta[2]);
  15259. _tmpExpandRectDelta[3] = mathMax$1(0, _tmpExpandRectDelta[3]);
  15260. }
  15261. if (shrinkOrExpand) {
  15262. _tmpExpandRectDelta[0] = -_tmpExpandRectDelta[0];
  15263. _tmpExpandRectDelta[1] = -_tmpExpandRectDelta[1];
  15264. _tmpExpandRectDelta[2] = -_tmpExpandRectDelta[2];
  15265. _tmpExpandRectDelta[3] = -_tmpExpandRectDelta[3];
  15266. }
  15267. expandRectOnOneDimension(rect, _tmpExpandRectDelta, 'x', 'width', 3, 1, minSize && minSize[0] || 0);
  15268. expandRectOnOneDimension(rect, _tmpExpandRectDelta, 'y', 'height', 0, 2, minSize && minSize[1] || 0);
  15269. return rect;
  15270. }
  15271. var _tmpExpandRectDelta = [0, 0, 0, 0];
  15272. function expandRectOnOneDimension(rect, delta, xy, wh, ltIdx, rbIdx, minSize) {
  15273. var deltaSum = delta[rbIdx] + delta[ltIdx];
  15274. var oldSize = rect[wh];
  15275. rect[wh] += deltaSum;
  15276. minSize = mathMax$1(0, mathMin$1(minSize, oldSize));
  15277. if (rect[wh] < minSize) {
  15278. rect[wh] = minSize;
  15279. // Try to make the position of the zero rect reasonable in most visual cases.
  15280. rect[xy] += delta[ltIdx] >= 0 ? -delta[ltIdx] : delta[rbIdx] >= 0 ? oldSize + delta[rbIdx] : mathAbs$1(deltaSum) > 1e-8 ? (oldSize - minSize) * delta[ltIdx] / deltaSum : 0;
  15281. } else {
  15282. rect[xy] -= delta[ltIdx];
  15283. }
  15284. }
  15285. function setTooltipConfig(opt) {
  15286. var itemTooltipOption = opt.itemTooltipOption;
  15287. var componentModel = opt.componentModel;
  15288. var itemName = opt.itemName;
  15289. var itemTooltipOptionObj = isString(itemTooltipOption) ? {
  15290. formatter: itemTooltipOption
  15291. } : itemTooltipOption;
  15292. var mainType = componentModel.mainType;
  15293. var componentIndex = componentModel.componentIndex;
  15294. var formatterParams = {
  15295. componentType: mainType,
  15296. name: itemName,
  15297. $vars: ['name']
  15298. };
  15299. formatterParams[mainType + 'Index'] = componentIndex;
  15300. var formatterParamsExtra = opt.formatterParamsExtra;
  15301. if (formatterParamsExtra) {
  15302. each(keys(formatterParamsExtra), function (key) {
  15303. if (!hasOwn(formatterParams, key)) {
  15304. formatterParams[key] = formatterParamsExtra[key];
  15305. formatterParams.$vars.push(key);
  15306. }
  15307. });
  15308. }
  15309. var ecData = getECData(opt.el);
  15310. ecData.componentMainType = mainType;
  15311. ecData.componentIndex = componentIndex;
  15312. ecData.tooltipConfig = {
  15313. name: itemName,
  15314. option: defaults({
  15315. content: itemName,
  15316. encodeHTMLContent: true,
  15317. formatterParams: formatterParams
  15318. }, itemTooltipOptionObj)
  15319. };
  15320. }
  15321. function traverseElement(el, cb) {
  15322. var stopped;
  15323. // TODO
  15324. // Polyfill for fixing zrender group traverse don't visit it's root issue.
  15325. if (el.isGroup) {
  15326. stopped = cb(el);
  15327. }
  15328. if (!stopped) {
  15329. el.traverse(cb);
  15330. }
  15331. }
  15332. function traverseElements(els, cb) {
  15333. if (els) {
  15334. if (isArray(els)) {
  15335. for (var i = 0; i < els.length; i++) {
  15336. traverseElement(els[i], cb);
  15337. }
  15338. } else {
  15339. traverseElement(els, cb);
  15340. }
  15341. }
  15342. }
  15343. /**
  15344. * After a boundingRect applying a `transform`, whether to be still parallel screen X and Y.
  15345. */
  15346. function isBoundingRectAxisAligned(transform) {
  15347. return !transform || mathAbs$1(transform[1]) < AXIS_ALIGN_EPSILON && mathAbs$1(transform[2]) < AXIS_ALIGN_EPSILON || mathAbs$1(transform[0]) < AXIS_ALIGN_EPSILON && mathAbs$1(transform[3]) < AXIS_ALIGN_EPSILON;
  15348. }
  15349. var AXIS_ALIGN_EPSILON = 1e-5;
  15350. /**
  15351. * Create or copy to the existing bounding rect to avoid modifying `source`.
  15352. *
  15353. * @usage
  15354. * out.rect = ensureCopyRect(out.rect, sourceRect);
  15355. */
  15356. function ensureCopyRect(target, source) {
  15357. return target ? BoundingRect.copy(target, source) : source.clone();
  15358. }
  15359. /**
  15360. * Create or copy to the existing transform to avoid modifying `source`.
  15361. *
  15362. * [CAUTION]: transform is `NullUndefined` if no transform, following convention of zrender,
  15363. * and enable to bypass some unnecessary calculation, since in most cases there is no transform.
  15364. *
  15365. * @usage
  15366. * out.transform = ensureCopyTransform(out.transform, sourceTransform);
  15367. */
  15368. function ensureCopyTransform(target, source) {
  15369. return source ? copy$1(target || create$1(), source) : undefined;
  15370. }
  15371. function retrieveZInfo(model) {
  15372. return {
  15373. z: model.get('z') || 0,
  15374. zlevel: model.get('zlevel') || 0
  15375. };
  15376. }
  15377. /**
  15378. * Assume all of the elements has the same `z` and `zlevel`.
  15379. */
  15380. function calcZ2Range(el) {
  15381. var max = -Infinity;
  15382. var min = Infinity;
  15383. traverseElement(el, function (el) {
  15384. visitEl(el);
  15385. visitEl(el.getTextContent());
  15386. visitEl(el.getTextGuideLine());
  15387. });
  15388. function visitEl(el) {
  15389. if (!el || el.isGroup) {
  15390. return;
  15391. }
  15392. var currentStates = el.currentStates;
  15393. if (currentStates.length) {
  15394. for (var idx = 0; idx < currentStates.length; idx++) {
  15395. calcZ2(el.states[currentStates[idx]]);
  15396. }
  15397. }
  15398. calcZ2(el);
  15399. }
  15400. function calcZ2(entity) {
  15401. if (entity) {
  15402. var z2 = entity.z2;
  15403. // Consider z2 may be NullUndefined
  15404. if (z2 > max) {
  15405. max = z2;
  15406. }
  15407. if (z2 < min) {
  15408. min = z2;
  15409. }
  15410. }
  15411. }
  15412. if (min > max) {
  15413. min = max = 0;
  15414. }
  15415. return {
  15416. min: min,
  15417. max: max
  15418. };
  15419. }
  15420. function traverseUpdateZ(el, z, zlevel) {
  15421. doUpdateZ(el, z, zlevel, -Infinity);
  15422. }
  15423. function doUpdateZ(el, z, zlevel,
  15424. // FIXME: Ideally all the labels should be above all the glyphs by default,
  15425. // e.g. in graph, edge labels should be above node elements.
  15426. // Currently impl does not guarantee that.
  15427. maxZ2) {
  15428. // `ignoreModelZ` is used to intentionally lift elements to cover other elements,
  15429. // where maxZ2 (for label.z2) should also not be counted for its parents.
  15430. if (el.ignoreModelZ) {
  15431. return maxZ2;
  15432. }
  15433. // Group may also have textContent
  15434. var label = el.getTextContent();
  15435. var labelLine = el.getTextGuideLine();
  15436. var isGroup = el.isGroup;
  15437. if (isGroup) {
  15438. // set z & zlevel of children elements of Group
  15439. var children = el.childrenRef();
  15440. for (var i = 0; i < children.length; i++) {
  15441. maxZ2 = mathMax$1(doUpdateZ(children[i], z, zlevel, maxZ2), maxZ2);
  15442. }
  15443. } else {
  15444. // not Group
  15445. el.z = z;
  15446. el.zlevel = zlevel;
  15447. maxZ2 = mathMax$1(el.z2 || 0, maxZ2);
  15448. }
  15449. // always set z and zlevel if label/labelLine exists
  15450. if (label) {
  15451. label.z = z;
  15452. label.zlevel = zlevel;
  15453. // lift z2 of text content
  15454. // TODO if el.emphasis.z2 is spcefied, what about textContent.
  15455. isFinite(maxZ2) && (label.z2 = maxZ2 + 2);
  15456. }
  15457. if (labelLine) {
  15458. var textGuideLineConfig = el.textGuideLineConfig;
  15459. labelLine.z = z;
  15460. labelLine.zlevel = zlevel;
  15461. isFinite(maxZ2) && (labelLine.z2 = maxZ2 + (textGuideLineConfig && textGuideLineConfig.showAbove ? 1 : -1));
  15462. }
  15463. return maxZ2;
  15464. }
  15465. // Register built-in shapes. These shapes might be overwritten
  15466. // by users, although we do not recommend that.
  15467. registerShape('circle', Circle);
  15468. registerShape('ellipse', Ellipse);
  15469. registerShape('sector', Sector);
  15470. registerShape('ring', Ring);
  15471. registerShape('polygon', Polygon);
  15472. registerShape('polyline', Polyline);
  15473. registerShape('rect', Rect);
  15474. registerShape('line', Line);
  15475. registerShape('bezierCurve', BezierCurve);
  15476. registerShape('arc', Arc);
  15477. var graphic = /*#__PURE__*/Object.freeze({
  15478. __proto__: null,
  15479. updateProps: updateProps,
  15480. initProps: initProps,
  15481. removeElement: removeElement,
  15482. removeElementWithFadeOut: removeElementWithFadeOut,
  15483. isElementRemoved: isElementRemoved,
  15484. XY: XY$1,
  15485. WH: WH$1,
  15486. extendShape: extendShape,
  15487. extendPath: extendPath,
  15488. registerShape: registerShape,
  15489. getShapeClass: getShapeClass,
  15490. makePath: makePath,
  15491. makeImage: makeImage,
  15492. mergePath: mergePath$1,
  15493. resizePath: resizePath,
  15494. subPixelOptimizeLine: subPixelOptimizeLine$1,
  15495. subPixelOptimizeRect: subPixelOptimizeRect$1,
  15496. subPixelOptimize: subPixelOptimize$1,
  15497. getTransform: getTransform,
  15498. applyTransform: applyTransform$1,
  15499. transformDirection: transformDirection,
  15500. groupTransition: groupTransition,
  15501. clipPointsByRect: clipPointsByRect,
  15502. clipRectByRect: clipRectByRect,
  15503. createIcon: createIcon,
  15504. linePolygonIntersect: linePolygonIntersect,
  15505. lineLineIntersect: lineLineIntersect,
  15506. expandOrShrinkRect: expandOrShrinkRect,
  15507. setTooltipConfig: setTooltipConfig,
  15508. traverseElements: traverseElements,
  15509. isBoundingRectAxisAligned: isBoundingRectAxisAligned,
  15510. ensureCopyRect: ensureCopyRect,
  15511. ensureCopyTransform: ensureCopyTransform,
  15512. retrieveZInfo: retrieveZInfo,
  15513. calcZ2Range: calcZ2Range,
  15514. traverseUpdateZ: traverseUpdateZ,
  15515. Group: Group,
  15516. Image: ZRImage,
  15517. Text: ZRText,
  15518. Circle: Circle,
  15519. Ellipse: Ellipse,
  15520. Sector: Sector,
  15521. Ring: Ring,
  15522. Polygon: Polygon,
  15523. Polyline: Polyline,
  15524. Rect: Rect,
  15525. Line: Line,
  15526. BezierCurve: BezierCurve,
  15527. Arc: Arc,
  15528. IncrementalDisplayable: IncrementalDisplayable,
  15529. CompoundPath: CompoundPath,
  15530. LinearGradient: LinearGradient,
  15531. RadialGradient: RadialGradient,
  15532. BoundingRect: BoundingRect,
  15533. OrientedBoundingRect: OrientedBoundingRect,
  15534. Point: Point,
  15535. Path: Path
  15536. });
  15537. var EMPTY_OBJ = {};
  15538. function setLabelText(label, labelTexts) {
  15539. for (var i = 0; i < SPECIAL_STATES.length; i++) {
  15540. var stateName = SPECIAL_STATES[i];
  15541. var text = labelTexts[stateName];
  15542. var state = label.ensureState(stateName);
  15543. state.style = state.style || {};
  15544. state.style.text = text;
  15545. }
  15546. var oldStates = label.currentStates.slice();
  15547. label.clearStates(true);
  15548. label.setStyle({
  15549. text: labelTexts.normal
  15550. });
  15551. label.useStates(oldStates, true);
  15552. }
  15553. function getLabelText(opt, stateModels, interpolatedValue) {
  15554. var labelFetcher = opt.labelFetcher;
  15555. var labelDataIndex = opt.labelDataIndex;
  15556. var labelDimIndex = opt.labelDimIndex;
  15557. var normalModel = stateModels.normal;
  15558. var baseText;
  15559. if (labelFetcher) {
  15560. baseText = labelFetcher.getFormattedLabel(labelDataIndex, 'normal', null, labelDimIndex, normalModel && normalModel.get('formatter'), interpolatedValue != null ? {
  15561. interpolatedValue: interpolatedValue
  15562. } : null);
  15563. }
  15564. if (baseText == null) {
  15565. baseText = isFunction(opt.defaultText) ? opt.defaultText(labelDataIndex, opt, interpolatedValue) : opt.defaultText;
  15566. }
  15567. var statesText = {
  15568. normal: baseText
  15569. };
  15570. for (var i = 0; i < SPECIAL_STATES.length; i++) {
  15571. var stateName = SPECIAL_STATES[i];
  15572. var stateModel = stateModels[stateName];
  15573. statesText[stateName] = retrieve2(labelFetcher ? labelFetcher.getFormattedLabel(labelDataIndex, stateName, null, labelDimIndex, stateModel && stateModel.get('formatter')) : null, baseText);
  15574. }
  15575. return statesText;
  15576. }
  15577. function setLabelStyle(targetEl, labelStatesModels, opt, stateSpecified
  15578. // TODO specified position?
  15579. ) {
  15580. opt = opt || EMPTY_OBJ;
  15581. var isSetOnText = targetEl instanceof ZRText;
  15582. var needsCreateText = false;
  15583. for (var i = 0; i < DISPLAY_STATES.length; i++) {
  15584. var stateModel = labelStatesModels[DISPLAY_STATES[i]];
  15585. if (stateModel && stateModel.getShallow('show')) {
  15586. needsCreateText = true;
  15587. break;
  15588. }
  15589. }
  15590. var textContent = isSetOnText ? targetEl : targetEl.getTextContent();
  15591. if (needsCreateText) {
  15592. if (!isSetOnText) {
  15593. // Reuse the previous
  15594. if (!textContent) {
  15595. textContent = new ZRText();
  15596. targetEl.setTextContent(textContent);
  15597. }
  15598. // Use same state proxy
  15599. if (targetEl.stateProxy) {
  15600. textContent.stateProxy = targetEl.stateProxy;
  15601. }
  15602. }
  15603. var labelStatesTexts = getLabelText(opt, labelStatesModels);
  15604. var normalModel = labelStatesModels.normal;
  15605. var showNormal = !!normalModel.getShallow('show');
  15606. var normalStyle = createTextStyle(normalModel, stateSpecified && stateSpecified.normal, opt, false, !isSetOnText);
  15607. normalStyle.text = labelStatesTexts.normal;
  15608. if (!isSetOnText) {
  15609. // Always create new
  15610. targetEl.setTextConfig(createTextConfig(normalModel, opt, false));
  15611. }
  15612. for (var i = 0; i < SPECIAL_STATES.length; i++) {
  15613. var stateName = SPECIAL_STATES[i];
  15614. var stateModel = labelStatesModels[stateName];
  15615. if (stateModel) {
  15616. var stateObj = textContent.ensureState(stateName);
  15617. var stateShow = !!retrieve2(stateModel.getShallow('show'), showNormal);
  15618. if (stateShow !== showNormal) {
  15619. stateObj.ignore = !stateShow;
  15620. }
  15621. stateObj.style = createTextStyle(stateModel, stateSpecified && stateSpecified[stateName], opt, true, !isSetOnText);
  15622. stateObj.style.text = labelStatesTexts[stateName];
  15623. if (!isSetOnText) {
  15624. var targetElEmphasisState = targetEl.ensureState(stateName);
  15625. targetElEmphasisState.textConfig = createTextConfig(stateModel, opt, true);
  15626. }
  15627. }
  15628. }
  15629. // PENDING: if there is many requirements that emphasis position
  15630. // need to be different from normal position, we might consider
  15631. // auto silent is those cases.
  15632. textContent.silent = !!normalModel.getShallow('silent');
  15633. // Keep x and y
  15634. if (textContent.style.x != null) {
  15635. normalStyle.x = textContent.style.x;
  15636. }
  15637. if (textContent.style.y != null) {
  15638. normalStyle.y = textContent.style.y;
  15639. }
  15640. textContent.ignore = !showNormal;
  15641. // Always create new style.
  15642. textContent.useStyle(normalStyle);
  15643. textContent.dirty();
  15644. if (opt.enableTextSetter) {
  15645. labelInner(textContent).setLabelText = function (interpolatedValue) {
  15646. var labelStatesTexts = getLabelText(opt, labelStatesModels, interpolatedValue);
  15647. setLabelText(textContent, labelStatesTexts);
  15648. };
  15649. }
  15650. } else if (textContent) {
  15651. // Not display rich text.
  15652. textContent.ignore = true;
  15653. }
  15654. targetEl.dirty();
  15655. }
  15656. function getLabelStatesModels(itemModel, labelName) {
  15657. labelName = labelName || 'label';
  15658. var statesModels = {
  15659. normal: itemModel.getModel(labelName)
  15660. };
  15661. for (var i = 0; i < SPECIAL_STATES.length; i++) {
  15662. var stateName = SPECIAL_STATES[i];
  15663. statesModels[stateName] = itemModel.getModel([stateName, labelName]);
  15664. }
  15665. return statesModels;
  15666. }
  15667. /**
  15668. * Set basic textStyle properties.
  15669. */
  15670. function createTextStyle(textStyleModel, specifiedTextStyle,
  15671. // Fixed style in the code. Can't be set by model.
  15672. opt, isNotNormal, isAttached // If text is attached on an element. If so, auto color will handling in zrender.
  15673. ) {
  15674. var textStyle = {};
  15675. setTextStyleCommon(textStyle, textStyleModel, opt, isNotNormal, isAttached);
  15676. specifiedTextStyle && extend(textStyle, specifiedTextStyle);
  15677. // textStyle.host && textStyle.host.dirty && textStyle.host.dirty(false);
  15678. return textStyle;
  15679. }
  15680. function createTextConfig(textStyleModel, opt, isNotNormal) {
  15681. opt = opt || {};
  15682. var textConfig = {};
  15683. var labelPosition;
  15684. var labelRotate = textStyleModel.getShallow('rotate');
  15685. var labelDistance = retrieve2(textStyleModel.getShallow('distance'), isNotNormal ? null : 5);
  15686. var labelOffset = textStyleModel.getShallow('offset');
  15687. labelPosition = textStyleModel.getShallow('position') || (isNotNormal ? null : 'inside');
  15688. // 'outside' is not a valid zr textPostion value, but used
  15689. // in bar series, and magic type should be considered.
  15690. labelPosition === 'outside' && (labelPosition = opt.defaultOutsidePosition || 'top');
  15691. if (labelPosition != null) {
  15692. textConfig.position = labelPosition;
  15693. }
  15694. if (labelOffset != null) {
  15695. textConfig.offset = labelOffset;
  15696. }
  15697. if (labelRotate != null) {
  15698. labelRotate *= Math.PI / 180;
  15699. textConfig.rotation = labelRotate;
  15700. }
  15701. if (labelDistance != null) {
  15702. textConfig.distance = labelDistance;
  15703. }
  15704. // fill and auto is determined by the color of path fill if it's not specified by developers.
  15705. textConfig.outsideFill = textStyleModel.get('color') === 'inherit' ? opt.inheritColor || null : 'auto';
  15706. if (opt.autoOverflowArea != null) {
  15707. textConfig.autoOverflowArea = opt.autoOverflowArea;
  15708. }
  15709. if (opt.layoutRect != null) {
  15710. textConfig.layoutRect = opt.layoutRect;
  15711. }
  15712. return textConfig;
  15713. }
  15714. /**
  15715. * The uniform entry of set text style, that is, retrieve style definitions
  15716. * from `model` and set to `textStyle` object.
  15717. *
  15718. * Never in merge mode, but in overwrite mode, that is, all of the text style
  15719. * properties will be set. (Consider the states of normal and emphasis and
  15720. * default value can be adopted, merge would make the logic too complicated
  15721. * to manage.)
  15722. */
  15723. function setTextStyleCommon(textStyle, textStyleModel, opt, isNotNormal, isAttached) {
  15724. // Consider there will be abnormal when merge hover style to normal style if given default value.
  15725. opt = opt || EMPTY_OBJ;
  15726. var ecModel = textStyleModel.ecModel;
  15727. var globalTextStyle = ecModel && ecModel.option.textStyle;
  15728. // Consider case:
  15729. // {
  15730. // data: [{
  15731. // value: 12,
  15732. // label: {
  15733. // rich: {
  15734. // // no 'a' here but using parent 'a'.
  15735. // }
  15736. // }
  15737. // }],
  15738. // rich: {
  15739. // a: { ... }
  15740. // }
  15741. // }
  15742. var richItemNames = getRichItemNames(textStyleModel);
  15743. var richResult;
  15744. if (richItemNames) {
  15745. richResult = {};
  15746. var richInheritPlainLabelOptionName = 'richInheritPlainLabel';
  15747. var richInheritPlainLabel = retrieve2(textStyleModel.get(richInheritPlainLabelOptionName), ecModel ? ecModel.get(richInheritPlainLabelOptionName) : undefined);
  15748. for (var name_1 in richItemNames) {
  15749. if (richItemNames.hasOwnProperty(name_1)) {
  15750. // Cascade is supported in rich.
  15751. var richTextStyle = textStyleModel.getModel(['rich', name_1]);
  15752. // In rich, never `disableBox`.
  15753. // consider `label: {formatter: '{a|xx}', color: 'blue', rich: {a: {}}}`,
  15754. // the default color `'blue'` will not be adopted if no color declared in `rich`.
  15755. // That might confuses users. So probably we should put `textStyleModel` as the
  15756. // root ancestor of the `richTextStyle`. But that would be a break change.
  15757. // Since v6, the rich style inherits plain label by default
  15758. // but this behavior can be disabled by setting `richInheritPlainLabel` to `false`.
  15759. setTokenTextStyle(richResult[name_1] = {}, richTextStyle, globalTextStyle, textStyleModel, richInheritPlainLabel, opt, isNotNormal, isAttached, false, true);
  15760. }
  15761. }
  15762. }
  15763. if (richResult) {
  15764. textStyle.rich = richResult;
  15765. }
  15766. var overflow = textStyleModel.get('overflow');
  15767. if (overflow) {
  15768. textStyle.overflow = overflow;
  15769. }
  15770. var lineOverflow = textStyleModel.get('lineOverflow');
  15771. if (lineOverflow) {
  15772. textStyle.lineOverflow = lineOverflow;
  15773. }
  15774. var labelTextStyle = textStyle;
  15775. // `minMargin` has a higher precedence than `textMargin`, because `textMargin` is allowed
  15776. // to be set in `defaultOption`.
  15777. var minMargin = textStyleModel.get('minMargin');
  15778. if (minMargin != null) {
  15779. // `minMargin` only support number value.
  15780. minMargin = !isNumber(minMargin) ? 0 : minMargin / 2;
  15781. labelTextStyle.margin = [minMargin, minMargin, minMargin, minMargin];
  15782. labelTextStyle.__marginType = LabelMarginType.minMargin;
  15783. } else {
  15784. var textMargin = textStyleModel.get('textMargin');
  15785. if (textMargin != null) {
  15786. labelTextStyle.margin = normalizeCssArray(textMargin);
  15787. labelTextStyle.__marginType = LabelMarginType.textMargin;
  15788. }
  15789. }
  15790. setTokenTextStyle(textStyle, textStyleModel, globalTextStyle, null, null, opt, isNotNormal, isAttached, true, false);
  15791. }
  15792. // Consider case:
  15793. // {
  15794. // data: [{
  15795. // value: 12,
  15796. // label: {
  15797. // rich: {
  15798. // // no 'a' here but using parent 'a'.
  15799. // }
  15800. // }
  15801. // }],
  15802. // rich: {
  15803. // a: { ... }
  15804. // }
  15805. // }
  15806. // TODO TextStyleModel
  15807. function getRichItemNames(textStyleModel) {
  15808. // Use object to remove duplicated names.
  15809. var richItemNameMap;
  15810. while (textStyleModel && textStyleModel !== textStyleModel.ecModel) {
  15811. var rich = (textStyleModel.option || EMPTY_OBJ).rich;
  15812. if (rich) {
  15813. richItemNameMap = richItemNameMap || {};
  15814. var richKeys = keys(rich);
  15815. for (var i = 0; i < richKeys.length; i++) {
  15816. var richKey = richKeys[i];
  15817. richItemNameMap[richKey] = 1;
  15818. }
  15819. }
  15820. textStyleModel = textStyleModel.parentModel;
  15821. }
  15822. return richItemNameMap;
  15823. }
  15824. var TEXT_PROPS_WITH_GLOBAL = ['fontStyle', 'fontWeight', 'fontSize', 'fontFamily', 'textShadowColor', 'textShadowBlur', 'textShadowOffsetX', 'textShadowOffsetY'];
  15825. var TEXT_PROPS_SELF = ['align', 'lineHeight', 'width', 'height', 'tag', 'verticalAlign', 'ellipsis'];
  15826. var TEXT_PROPS_BOX = ['padding', 'borderWidth', 'borderRadius', 'borderDashOffset', 'backgroundColor', 'borderColor', 'shadowColor', 'shadowBlur', 'shadowOffsetX', 'shadowOffsetY'];
  15827. function setTokenTextStyle(textStyle,
  15828. // FIXME: check/refactor for ellipsis handling of rich text.
  15829. textStyleModel, globalTextStyle, plainTextModel, richInheritPlainLabel, opt, isNotNormal, isAttached, isBlock, inRich) {
  15830. // In merge mode, default value should not be given.
  15831. globalTextStyle = !isNotNormal && globalTextStyle || EMPTY_OBJ;
  15832. var inheritColor = opt && opt.inheritColor;
  15833. var fillColor = textStyleModel.getShallow('color');
  15834. var strokeColor = textStyleModel.getShallow('textBorderColor');
  15835. var opacity = retrieve2(textStyleModel.getShallow('opacity'), globalTextStyle.opacity);
  15836. if (fillColor === 'inherit' || fillColor === 'auto') {
  15837. if ("development" !== 'production') {
  15838. if (fillColor === 'auto') {
  15839. deprecateReplaceLog('color: \'auto\'', 'color: \'inherit\'');
  15840. }
  15841. }
  15842. if (inheritColor) {
  15843. fillColor = inheritColor;
  15844. } else {
  15845. fillColor = null;
  15846. }
  15847. }
  15848. if (strokeColor === 'inherit' || strokeColor === 'auto') {
  15849. if ("development" !== 'production') {
  15850. if (strokeColor === 'auto') {
  15851. deprecateReplaceLog('color: \'auto\'', 'color: \'inherit\'');
  15852. }
  15853. }
  15854. if (inheritColor) {
  15855. strokeColor = inheritColor;
  15856. } else {
  15857. strokeColor = null;
  15858. }
  15859. }
  15860. if (!isAttached) {
  15861. // Only use default global textStyle.color if text is individual.
  15862. // Otherwise it will use the strategy of attached text color because text may be on a path.
  15863. fillColor = fillColor || globalTextStyle.color;
  15864. strokeColor = strokeColor || globalTextStyle.textBorderColor;
  15865. }
  15866. if (fillColor != null) {
  15867. // Might not be a string, e.g, it's a function in axisLabel case; but assume that it will
  15868. // be erased by a correct value outside.
  15869. textStyle.fill = fillColor;
  15870. }
  15871. if (strokeColor != null) {
  15872. textStyle.stroke = strokeColor;
  15873. }
  15874. var textBorderWidth = retrieve2(textStyleModel.getShallow('textBorderWidth'), globalTextStyle.textBorderWidth);
  15875. if (textBorderWidth != null) {
  15876. textStyle.lineWidth = textBorderWidth;
  15877. }
  15878. var textBorderType = retrieve2(textStyleModel.getShallow('textBorderType'), globalTextStyle.textBorderType);
  15879. if (textBorderType != null) {
  15880. textStyle.lineDash = textBorderType;
  15881. }
  15882. var textBorderDashOffset = retrieve2(textStyleModel.getShallow('textBorderDashOffset'), globalTextStyle.textBorderDashOffset);
  15883. if (textBorderDashOffset != null) {
  15884. textStyle.lineDashOffset = textBorderDashOffset;
  15885. }
  15886. if (!isNotNormal && opacity == null && !inRich) {
  15887. opacity = opt && opt.defaultOpacity;
  15888. }
  15889. if (opacity != null) {
  15890. textStyle.opacity = opacity;
  15891. }
  15892. // TODO
  15893. if (!isNotNormal && !isAttached) {
  15894. // Set default finally.
  15895. if (textStyle.fill == null && opt.inheritColor) {
  15896. textStyle.fill = opt.inheritColor;
  15897. }
  15898. }
  15899. // Do not use `getFont` here, because merge should be supported, where
  15900. // part of these properties may be changed in emphasis style, and the
  15901. // others should remain their original value got from normal style.
  15902. for (var i = 0; i < TEXT_PROPS_WITH_GLOBAL.length; i++) {
  15903. var key = TEXT_PROPS_WITH_GLOBAL[i];
  15904. // props width, height, padding, margin, tag, backgroundColor, borderColor,
  15905. // borderWidth, borderRadius, shadowColor, shadowBlur, shadowOffsetX, shadowOffsetY
  15906. // may inappropriate to inherit from plainTextStyle.
  15907. // And if some props is specified in default options, users may have to reset them one by one.
  15908. // Therefore, we only allow these props to inherit from plainTextStyle.
  15909. // `richInheritPlainLabel` is switch for backward compatibility
  15910. var val = richInheritPlainLabel !== false && plainTextModel ? retrieve3(textStyleModel.getShallow(key), plainTextModel.getShallow(key), globalTextStyle[key]) : retrieve2(textStyleModel.getShallow(key), globalTextStyle[key]);
  15911. if (val != null) {
  15912. textStyle[key] = val;
  15913. }
  15914. }
  15915. for (var i = 0; i < TEXT_PROPS_SELF.length; i++) {
  15916. var key = TEXT_PROPS_SELF[i];
  15917. var val = textStyleModel.getShallow(key);
  15918. if (val != null) {
  15919. textStyle[key] = val;
  15920. }
  15921. }
  15922. if (textStyle.verticalAlign == null) {
  15923. var baseline = textStyleModel.getShallow('baseline');
  15924. if (baseline != null) {
  15925. textStyle.verticalAlign = baseline;
  15926. }
  15927. }
  15928. if (!isBlock || !opt.disableBox) {
  15929. for (var i = 0; i < TEXT_PROPS_BOX.length; i++) {
  15930. var key = TEXT_PROPS_BOX[i];
  15931. var val = textStyleModel.getShallow(key);
  15932. if (val != null) {
  15933. textStyle[key] = val;
  15934. }
  15935. }
  15936. var borderType = textStyleModel.getShallow('borderType');
  15937. if (borderType != null) {
  15938. textStyle.borderDash = borderType;
  15939. }
  15940. if ((textStyle.backgroundColor === 'auto' || textStyle.backgroundColor === 'inherit') && inheritColor) {
  15941. if ("development" !== 'production') {
  15942. if (textStyle.backgroundColor === 'auto') {
  15943. deprecateReplaceLog('backgroundColor: \'auto\'', 'backgroundColor: \'inherit\'');
  15944. }
  15945. }
  15946. textStyle.backgroundColor = inheritColor;
  15947. }
  15948. if ((textStyle.borderColor === 'auto' || textStyle.borderColor === 'inherit') && inheritColor) {
  15949. if ("development" !== 'production') {
  15950. if (textStyle.borderColor === 'auto') {
  15951. deprecateReplaceLog('borderColor: \'auto\'', 'borderColor: \'inherit\'');
  15952. }
  15953. }
  15954. textStyle.borderColor = inheritColor;
  15955. }
  15956. }
  15957. }
  15958. function getFont(opt, ecModel) {
  15959. var gTextStyleModel = ecModel && ecModel.getModel('textStyle');
  15960. return trim([
  15961. // FIXME in node-canvas fontWeight is before fontStyle
  15962. opt.fontStyle || gTextStyleModel && gTextStyleModel.getShallow('fontStyle') || '', opt.fontWeight || gTextStyleModel && gTextStyleModel.getShallow('fontWeight') || '', (opt.fontSize || gTextStyleModel && gTextStyleModel.getShallow('fontSize') || 12) + 'px', opt.fontFamily || gTextStyleModel && gTextStyleModel.getShallow('fontFamily') || 'sans-serif'].join(' '));
  15963. }
  15964. var labelInner = makeInner();
  15965. function setLabelValueAnimation(label, labelStatesModels, value, getDefaultText) {
  15966. if (!label) {
  15967. return;
  15968. }
  15969. var obj = labelInner(label);
  15970. obj.prevValue = obj.value;
  15971. obj.value = value;
  15972. var normalLabelModel = labelStatesModels.normal;
  15973. obj.valueAnimation = normalLabelModel.get('valueAnimation');
  15974. if (obj.valueAnimation) {
  15975. obj.precision = normalLabelModel.get('precision');
  15976. obj.defaultInterpolatedText = getDefaultText;
  15977. obj.statesModels = labelStatesModels;
  15978. }
  15979. }
  15980. function animateLabelValue(textEl, dataIndex, data, animatableModel, labelFetcher) {
  15981. var labelInnerStore = labelInner(textEl);
  15982. if (!labelInnerStore.valueAnimation || labelInnerStore.prevValue === labelInnerStore.value) {
  15983. // Value not changed, no new label animation
  15984. return;
  15985. }
  15986. var defaultInterpolatedText = labelInnerStore.defaultInterpolatedText;
  15987. // Consider the case that being animating, do not use the `obj.value`,
  15988. // Otherwise it will jump to the `obj.value` when this new animation started.
  15989. var currValue = retrieve2(labelInnerStore.interpolatedValue, labelInnerStore.prevValue);
  15990. var targetValue = labelInnerStore.value;
  15991. function during(percent) {
  15992. var interpolated = interpolateRawValues(data, labelInnerStore.precision, currValue, targetValue, percent);
  15993. labelInnerStore.interpolatedValue = percent === 1 ? null : interpolated;
  15994. var labelText = getLabelText({
  15995. labelDataIndex: dataIndex,
  15996. labelFetcher: labelFetcher,
  15997. defaultText: defaultInterpolatedText ? defaultInterpolatedText(interpolated) : interpolated + ''
  15998. }, labelInnerStore.statesModels, interpolated);
  15999. setLabelText(textEl, labelText);
  16000. }
  16001. textEl.percent = 0;
  16002. (labelInnerStore.prevValue == null ? initProps : updateProps)(textEl, {
  16003. // percent is used to prevent animation from being aborted #15916
  16004. percent: 1
  16005. }, animatableModel, dataIndex, null, during);
  16006. }
  16007. /**
  16008. * PENDING: Temporary impl. unify them?
  16009. * @see {LabelCommonOption['textMargin']}
  16010. * @see {LabelCommonOption['minMargin']}
  16011. */
  16012. var LabelMarginType = {
  16013. minMargin: 1,
  16014. textMargin: 2
  16015. };
  16016. var PATH_COLOR = ['textStyle', 'color'];
  16017. var textStyleParams = ['fontStyle', 'fontWeight', 'fontSize', 'fontFamily', 'padding', 'lineHeight', 'rich', 'width', 'height', 'overflow'];
  16018. // TODO Performance improvement?
  16019. var tmpText = new ZRText();
  16020. var TextStyleMixin = /** @class */function () {
  16021. function TextStyleMixin() {}
  16022. /**
  16023. * Get color property or get color from option.textStyle.color
  16024. */
  16025. // TODO Callback
  16026. TextStyleMixin.prototype.getTextColor = function (isEmphasis) {
  16027. var ecModel = this.ecModel;
  16028. return this.getShallow('color') || (!isEmphasis && ecModel ? ecModel.get(PATH_COLOR) : null);
  16029. };
  16030. /**
  16031. * Create font string from fontStyle, fontWeight, fontSize, fontFamily
  16032. * @return {string}
  16033. */
  16034. TextStyleMixin.prototype.getFont = function () {
  16035. return getFont({
  16036. fontStyle: this.getShallow('fontStyle'),
  16037. fontWeight: this.getShallow('fontWeight'),
  16038. fontSize: this.getShallow('fontSize'),
  16039. fontFamily: this.getShallow('fontFamily')
  16040. }, this.ecModel);
  16041. };
  16042. TextStyleMixin.prototype.getTextRect = function (text) {
  16043. var style = {
  16044. text: text,
  16045. verticalAlign: this.getShallow('verticalAlign') || this.getShallow('baseline')
  16046. };
  16047. for (var i = 0; i < textStyleParams.length; i++) {
  16048. style[textStyleParams[i]] = this.getShallow(textStyleParams[i]);
  16049. }
  16050. tmpText.useStyle(style);
  16051. tmpText.update();
  16052. return tmpText.getBoundingRect();
  16053. };
  16054. return TextStyleMixin;
  16055. }();
  16056. var LINE_STYLE_KEY_MAP = [['lineWidth', 'width'], ['stroke', 'color'], ['opacity'], ['shadowBlur'], ['shadowOffsetX'], ['shadowOffsetY'], ['shadowColor'], ['lineDash', 'type'], ['lineDashOffset', 'dashOffset'], ['lineCap', 'cap'], ['lineJoin', 'join'], ['miterLimit']
  16057. // Option decal is in `DecalObject` but style.decal is in `PatternObject`.
  16058. // So do not transfer decal directly.
  16059. ];
  16060. var getLineStyle = makeStyleMapper(LINE_STYLE_KEY_MAP);
  16061. var LineStyleMixin = /** @class */function () {
  16062. function LineStyleMixin() {}
  16063. LineStyleMixin.prototype.getLineStyle = function (excludes) {
  16064. return getLineStyle(this, excludes);
  16065. };
  16066. return LineStyleMixin;
  16067. }();
  16068. var ITEM_STYLE_KEY_MAP = [['fill', 'color'], ['stroke', 'borderColor'], ['lineWidth', 'borderWidth'], ['opacity'], ['shadowBlur'], ['shadowOffsetX'], ['shadowOffsetY'], ['shadowColor'], ['lineDash', 'borderType'], ['lineDashOffset', 'borderDashOffset'], ['lineCap', 'borderCap'], ['lineJoin', 'borderJoin'], ['miterLimit', 'borderMiterLimit']
  16069. // Option decal is in `DecalObject` but style.decal is in `PatternObject`.
  16070. // So do not transfer decal directly.
  16071. ];
  16072. var getItemStyle = makeStyleMapper(ITEM_STYLE_KEY_MAP);
  16073. var ItemStyleMixin = /** @class */function () {
  16074. function ItemStyleMixin() {}
  16075. ItemStyleMixin.prototype.getItemStyle = function (excludes, includes) {
  16076. return getItemStyle(this, excludes, includes);
  16077. };
  16078. return ItemStyleMixin;
  16079. }();
  16080. var Model = /** @class */function () {
  16081. function Model(option, parentModel, ecModel) {
  16082. this.parentModel = parentModel;
  16083. this.ecModel = ecModel;
  16084. this.option = option;
  16085. // Simple optimization
  16086. // if (this.init) {
  16087. // if (arguments.length <= 4) {
  16088. // this.init(option, parentModel, ecModel, extraOpt);
  16089. // }
  16090. // else {
  16091. // this.init.apply(this, arguments);
  16092. // }
  16093. // }
  16094. }
  16095. Model.prototype.init = function (option, parentModel, ecModel) {
  16096. var rest = [];
  16097. for (var _i = 3; _i < arguments.length; _i++) {
  16098. rest[_i - 3] = arguments[_i];
  16099. }
  16100. };
  16101. /**
  16102. * Merge the input option to me.
  16103. */
  16104. Model.prototype.mergeOption = function (option, ecModel) {
  16105. merge(this.option, option, true);
  16106. };
  16107. // `path` can be 'a.b.c', so the return value type have to be `ModelOption`
  16108. // TODO: TYPE strict key check?
  16109. // get(path: string | string[], ignoreParent?: boolean): ModelOption;
  16110. Model.prototype.get = function (path, ignoreParent) {
  16111. if (path == null) {
  16112. return this.option;
  16113. }
  16114. return this._doGet(this.parsePath(path), !ignoreParent && this.parentModel);
  16115. };
  16116. Model.prototype.getShallow = function (key, ignoreParent) {
  16117. var option = this.option;
  16118. var val = option == null ? option : option[key];
  16119. if (val == null && !ignoreParent) {
  16120. var parentModel = this.parentModel;
  16121. if (parentModel) {
  16122. // FIXME:TS do not know how to make it works
  16123. val = parentModel.getShallow(key);
  16124. }
  16125. }
  16126. return val;
  16127. };
  16128. // `path` can be 'a.b.c', so the return value type have to be `Model<ModelOption>`
  16129. // getModel(path: string | string[], parentModel?: Model): Model;
  16130. // TODO 'a.b.c' is deprecated
  16131. Model.prototype.getModel = function (path, parentModel) {
  16132. var hasPath = path != null;
  16133. var pathFinal = hasPath ? this.parsePath(path) : null;
  16134. var obj = hasPath ? this._doGet(pathFinal) : this.option;
  16135. parentModel = parentModel || this.parentModel && this.parentModel.getModel(this.resolveParentPath(pathFinal));
  16136. return new Model(obj, parentModel, this.ecModel);
  16137. };
  16138. /**
  16139. * If model has option
  16140. */
  16141. Model.prototype.isEmpty = function () {
  16142. return this.option == null;
  16143. };
  16144. Model.prototype.restoreData = function () {};
  16145. // Pending
  16146. Model.prototype.clone = function () {
  16147. var Ctor = this.constructor;
  16148. return new Ctor(clone(this.option));
  16149. };
  16150. // setReadOnly(properties): void {
  16151. // clazzUtil.setReadOnly(this, properties);
  16152. // }
  16153. // If path is null/undefined, return null/undefined.
  16154. Model.prototype.parsePath = function (path) {
  16155. if (typeof path === 'string') {
  16156. return path.split('.');
  16157. }
  16158. return path;
  16159. };
  16160. // Resolve path for parent. Perhaps useful when parent use a different property.
  16161. // Default to be a identity resolver.
  16162. // Can be modified to a different resolver.
  16163. Model.prototype.resolveParentPath = function (path) {
  16164. return path;
  16165. };
  16166. // FIXME:TS check whether put this method here
  16167. Model.prototype.isAnimationEnabled = function () {
  16168. if (!env.node && this.option) {
  16169. if (this.option.animation != null) {
  16170. return !!this.option.animation;
  16171. } else if (this.parentModel) {
  16172. return this.parentModel.isAnimationEnabled();
  16173. }
  16174. }
  16175. };
  16176. Model.prototype._doGet = function (pathArr, parentModel) {
  16177. var obj = this.option;
  16178. if (!pathArr) {
  16179. return obj;
  16180. }
  16181. for (var i = 0; i < pathArr.length; i++) {
  16182. // Ignore empty
  16183. if (!pathArr[i]) {
  16184. continue;
  16185. }
  16186. // obj could be number/string/... (like 0)
  16187. obj = obj && typeof obj === 'object' ? obj[pathArr[i]] : null;
  16188. if (obj == null) {
  16189. break;
  16190. }
  16191. }
  16192. if (obj == null && parentModel) {
  16193. obj = parentModel._doGet(this.resolveParentPath(pathArr), parentModel.parentModel);
  16194. }
  16195. return obj;
  16196. };
  16197. return Model;
  16198. }();
  16199. // Enable Model.extend.
  16200. enableClassExtend(Model);
  16201. enableClassCheck(Model);
  16202. mixin(Model, LineStyleMixin);
  16203. mixin(Model, ItemStyleMixin);
  16204. mixin(Model, AreaStyleMixin);
  16205. mixin(Model, TextStyleMixin);
  16206. // A random offset
  16207. var base = Math.round(Math.random() * 10);
  16208. /**
  16209. * @public
  16210. * @param {string} type
  16211. * @return {string}
  16212. */
  16213. function getUID(type) {
  16214. // Considering the case of crossing js context,
  16215. // use Math.random to make id as unique as possible.
  16216. return [type || '', base++].join('_');
  16217. }
  16218. /**
  16219. * Implements `SubTypeDefaulterManager` for `target`.
  16220. */
  16221. function enableSubTypeDefaulter(target) {
  16222. var subTypeDefaulters = {};
  16223. target.registerSubTypeDefaulter = function (componentType, defaulter) {
  16224. var componentTypeInfo = parseClassType(componentType);
  16225. subTypeDefaulters[componentTypeInfo.main] = defaulter;
  16226. };
  16227. target.determineSubType = function (componentType, option) {
  16228. var type = option.type;
  16229. if (!type) {
  16230. var componentTypeMain = parseClassType(componentType).main;
  16231. if (target.hasSubTypes(componentType) && subTypeDefaulters[componentTypeMain]) {
  16232. type = subTypeDefaulters[componentTypeMain](option);
  16233. }
  16234. }
  16235. return type;
  16236. };
  16237. }
  16238. /**
  16239. * Implements `TopologicalTravelable<any>` for `entity`.
  16240. *
  16241. * Topological travel on Activity Network (Activity On Vertices).
  16242. * Dependencies is defined in Model.prototype.dependencies, like ['xAxis', 'yAxis'].
  16243. * If 'xAxis' or 'yAxis' is absent in componentTypeList, just ignore it in topology.
  16244. * If there is circular dependencey, Error will be thrown.
  16245. */
  16246. function enableTopologicalTravel(entity, dependencyGetter) {
  16247. /**
  16248. * @param targetNameList Target Component type list.
  16249. * Can be ['aa', 'bb', 'aa.xx']
  16250. * @param fullNameList By which we can build dependency graph.
  16251. * @param callback Params: componentType, dependencies.
  16252. * @param context Scope of callback.
  16253. */
  16254. entity.topologicalTravel = function (targetNameList, fullNameList, callback, context) {
  16255. if (!targetNameList.length) {
  16256. return;
  16257. }
  16258. var result = makeDepndencyGraph(fullNameList);
  16259. var graph = result.graph;
  16260. var noEntryList = result.noEntryList;
  16261. var targetNameSet = {};
  16262. each(targetNameList, function (name) {
  16263. targetNameSet[name] = true;
  16264. });
  16265. while (noEntryList.length) {
  16266. var currComponentType = noEntryList.pop();
  16267. var currVertex = graph[currComponentType];
  16268. var isInTargetNameSet = !!targetNameSet[currComponentType];
  16269. if (isInTargetNameSet) {
  16270. callback.call(context, currComponentType, currVertex.originalDeps.slice());
  16271. delete targetNameSet[currComponentType];
  16272. }
  16273. each(currVertex.successor, isInTargetNameSet ? removeEdgeAndAdd : removeEdge);
  16274. }
  16275. each(targetNameSet, function () {
  16276. var errMsg = '';
  16277. if ("development" !== 'production') {
  16278. errMsg = makePrintable('Circular dependency may exists: ', targetNameSet, targetNameList, fullNameList);
  16279. }
  16280. throw new Error(errMsg);
  16281. });
  16282. function removeEdge(succComponentType) {
  16283. graph[succComponentType].entryCount--;
  16284. if (graph[succComponentType].entryCount === 0) {
  16285. noEntryList.push(succComponentType);
  16286. }
  16287. }
  16288. // Consider this case: legend depends on series, and we call
  16289. // chart.setOption({series: [...]}), where only series is in option.
  16290. // If we do not have 'removeEdgeAndAdd', legendModel.mergeOption will
  16291. // not be called, but only sereis.mergeOption is called. Thus legend
  16292. // have no chance to update its local record about series (like which
  16293. // name of series is available in legend).
  16294. function removeEdgeAndAdd(succComponentType) {
  16295. targetNameSet[succComponentType] = true;
  16296. removeEdge(succComponentType);
  16297. }
  16298. };
  16299. function makeDepndencyGraph(fullNameList) {
  16300. var graph = {};
  16301. var noEntryList = [];
  16302. each(fullNameList, function (name) {
  16303. var thisItem = createDependencyGraphItem(graph, name);
  16304. var originalDeps = thisItem.originalDeps = dependencyGetter(name);
  16305. var availableDeps = getAvailableDependencies(originalDeps, fullNameList);
  16306. thisItem.entryCount = availableDeps.length;
  16307. if (thisItem.entryCount === 0) {
  16308. noEntryList.push(name);
  16309. }
  16310. each(availableDeps, function (dependentName) {
  16311. if (indexOf(thisItem.predecessor, dependentName) < 0) {
  16312. thisItem.predecessor.push(dependentName);
  16313. }
  16314. var thatItem = createDependencyGraphItem(graph, dependentName);
  16315. if (indexOf(thatItem.successor, dependentName) < 0) {
  16316. thatItem.successor.push(name);
  16317. }
  16318. });
  16319. });
  16320. return {
  16321. graph: graph,
  16322. noEntryList: noEntryList
  16323. };
  16324. }
  16325. function createDependencyGraphItem(graph, name) {
  16326. if (!graph[name]) {
  16327. graph[name] = {
  16328. predecessor: [],
  16329. successor: []
  16330. };
  16331. }
  16332. return graph[name];
  16333. }
  16334. function getAvailableDependencies(originalDeps, fullNameList) {
  16335. var availableDeps = [];
  16336. each(originalDeps, function (dep) {
  16337. indexOf(fullNameList, dep) >= 0 && availableDeps.push(dep);
  16338. });
  16339. return availableDeps;
  16340. }
  16341. }
  16342. function inheritDefaultOption(superOption, subOption) {
  16343. // See also `model/Component.ts#getDefaultOption`
  16344. return merge(merge({}, superOption, true), subOption, true);
  16345. }
  16346. /*
  16347. * Licensed to the Apache Software Foundation (ASF) under one
  16348. * or more contributor license agreements. See the NOTICE file
  16349. * distributed with this work for additional information
  16350. * regarding copyright ownership. The ASF licenses this file
  16351. * to you under the Apache License, Version 2.0 (the
  16352. * "License"); you may not use this file except in compliance
  16353. * with the License. You may obtain a copy of the License at
  16354. *
  16355. * http://www.apache.org/licenses/LICENSE-2.0
  16356. *
  16357. * Unless required by applicable law or agreed to in writing,
  16358. * software distributed under the License is distributed on an
  16359. * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
  16360. * KIND, either express or implied. See the License for the
  16361. * specific language governing permissions and limitations
  16362. * under the License.
  16363. */
  16364. /**
  16365. * AUTO-GENERATED FILE. DO NOT MODIFY.
  16366. */
  16367. /*
  16368. * Licensed to the Apache Software Foundation (ASF) under one
  16369. * or more contributor license agreements. See the NOTICE file
  16370. * distributed with this work for additional information
  16371. * regarding copyright ownership. The ASF licenses this file
  16372. * to you under the Apache License, Version 2.0 (the
  16373. * "License"); you may not use this file except in compliance
  16374. * with the License. You may obtain a copy of the License at
  16375. *
  16376. * http://www.apache.org/licenses/LICENSE-2.0
  16377. *
  16378. * Unless required by applicable law or agreed to in writing,
  16379. * software distributed under the License is distributed on an
  16380. * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
  16381. * KIND, either express or implied. See the License for the
  16382. * specific language governing permissions and limitations
  16383. * under the License.
  16384. */
  16385. /**
  16386. * Language: English.
  16387. */
  16388. var langEN = {
  16389. time: {
  16390. month: ['January', 'February', 'March', 'April', 'May', 'June', 'July', 'August', 'September', 'October', 'November', 'December'],
  16391. monthAbbr: ['Jan', 'Feb', 'Mar', 'Apr', 'May', 'Jun', 'Jul', 'Aug', 'Sep', 'Oct', 'Nov', 'Dec'],
  16392. dayOfWeek: ['Sunday', 'Monday', 'Tuesday', 'Wednesday', 'Thursday', 'Friday', 'Saturday'],
  16393. dayOfWeekAbbr: ['Sun', 'Mon', 'Tue', 'Wed', 'Thu', 'Fri', 'Sat']
  16394. },
  16395. legend: {
  16396. selector: {
  16397. all: 'All',
  16398. inverse: 'Inv'
  16399. }
  16400. },
  16401. toolbox: {
  16402. brush: {
  16403. title: {
  16404. rect: 'Box Select',
  16405. polygon: 'Lasso Select',
  16406. lineX: 'Horizontally Select',
  16407. lineY: 'Vertically Select',
  16408. keep: 'Keep Selections',
  16409. clear: 'Clear Selections'
  16410. }
  16411. },
  16412. dataView: {
  16413. title: 'Data View',
  16414. lang: ['Data View', 'Close', 'Refresh']
  16415. },
  16416. dataZoom: {
  16417. title: {
  16418. zoom: 'Zoom',
  16419. back: 'Zoom Reset'
  16420. }
  16421. },
  16422. magicType: {
  16423. title: {
  16424. line: 'Switch to Line Chart',
  16425. bar: 'Switch to Bar Chart',
  16426. stack: 'Stack',
  16427. tiled: 'Tile'
  16428. }
  16429. },
  16430. restore: {
  16431. title: 'Restore'
  16432. },
  16433. saveAsImage: {
  16434. title: 'Save as Image',
  16435. lang: ['Right Click to Save Image']
  16436. }
  16437. },
  16438. series: {
  16439. typeNames: {
  16440. pie: 'Pie chart',
  16441. bar: 'Bar chart',
  16442. line: 'Line chart',
  16443. scatter: 'Scatter plot',
  16444. effectScatter: 'Ripple scatter plot',
  16445. radar: 'Radar chart',
  16446. tree: 'Tree',
  16447. treemap: 'Treemap',
  16448. boxplot: 'Boxplot',
  16449. candlestick: 'Candlestick',
  16450. k: 'K line chart',
  16451. heatmap: 'Heat map',
  16452. map: 'Map',
  16453. parallel: 'Parallel coordinate map',
  16454. lines: 'Line graph',
  16455. graph: 'Relationship graph',
  16456. sankey: 'Sankey diagram',
  16457. funnel: 'Funnel chart',
  16458. gauge: 'Gauge',
  16459. pictorialBar: 'Pictorial bar',
  16460. themeRiver: 'Theme River Map',
  16461. sunburst: 'Sunburst',
  16462. custom: 'Custom chart',
  16463. chart: 'Chart'
  16464. }
  16465. },
  16466. aria: {
  16467. general: {
  16468. withTitle: 'This is a chart about "{title}"',
  16469. withoutTitle: 'This is a chart'
  16470. },
  16471. series: {
  16472. single: {
  16473. prefix: '',
  16474. withName: ' with type {seriesType} named {seriesName}.',
  16475. withoutName: ' with type {seriesType}.'
  16476. },
  16477. multiple: {
  16478. prefix: '. It consists of {seriesCount} series count.',
  16479. withName: ' The {seriesId} series is a {seriesType} representing {seriesName}.',
  16480. withoutName: ' The {seriesId} series is a {seriesType}.',
  16481. separator: {
  16482. middle: '',
  16483. end: ''
  16484. }
  16485. }
  16486. },
  16487. data: {
  16488. allData: 'The data is as follows: ',
  16489. partialData: 'The first {displayCnt} items are: ',
  16490. withName: 'the data for {name} is {value}',
  16491. withoutName: '{value}',
  16492. separator: {
  16493. middle: ', ',
  16494. end: '. '
  16495. }
  16496. }
  16497. }
  16498. };
  16499. /*
  16500. * Licensed to the Apache Software Foundation (ASF) under one
  16501. * or more contributor license agreements. See the NOTICE file
  16502. * distributed with this work for additional information
  16503. * regarding copyright ownership. The ASF licenses this file
  16504. * to you under the Apache License, Version 2.0 (the
  16505. * "License"); you may not use this file except in compliance
  16506. * with the License. You may obtain a copy of the License at
  16507. *
  16508. * http://www.apache.org/licenses/LICENSE-2.0
  16509. *
  16510. * Unless required by applicable law or agreed to in writing,
  16511. * software distributed under the License is distributed on an
  16512. * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
  16513. * KIND, either express or implied. See the License for the
  16514. * specific language governing permissions and limitations
  16515. * under the License.
  16516. */
  16517. /**
  16518. * AUTO-GENERATED FILE. DO NOT MODIFY.
  16519. */
  16520. /*
  16521. * Licensed to the Apache Software Foundation (ASF) under one
  16522. * or more contributor license agreements. See the NOTICE file
  16523. * distributed with this work for additional information
  16524. * regarding copyright ownership. The ASF licenses this file
  16525. * to you under the Apache License, Version 2.0 (the
  16526. * "License"); you may not use this file except in compliance
  16527. * with the License. You may obtain a copy of the License at
  16528. *
  16529. * http://www.apache.org/licenses/LICENSE-2.0
  16530. *
  16531. * Unless required by applicable law or agreed to in writing,
  16532. * software distributed under the License is distributed on an
  16533. * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
  16534. * KIND, either express or implied. See the License for the
  16535. * specific language governing permissions and limitations
  16536. * under the License.
  16537. */
  16538. var langZH = {
  16539. time: {
  16540. month: ['一月', '二月', '三月', '四月', '五月', '六月', '七月', '八月', '九月', '十月', '十一月', '十二月'],
  16541. monthAbbr: ['1月', '2月', '3月', '4月', '5月', '6月', '7月', '8月', '9月', '10月', '11月', '12月'],
  16542. dayOfWeek: ['星期日', '星期一', '星期二', '星期三', '星期四', '星期五', '星期六'],
  16543. dayOfWeekAbbr: ['日', '一', '二', '三', '四', '五', '六']
  16544. },
  16545. legend: {
  16546. selector: {
  16547. all: '全选',
  16548. inverse: '反选'
  16549. }
  16550. },
  16551. toolbox: {
  16552. brush: {
  16553. title: {
  16554. rect: '矩形选择',
  16555. polygon: '圈选',
  16556. lineX: '横向选择',
  16557. lineY: '纵向选择',
  16558. keep: '保持选择',
  16559. clear: '清除选择'
  16560. }
  16561. },
  16562. dataView: {
  16563. title: '数据视图',
  16564. lang: ['数据视图', '关闭', '刷新']
  16565. },
  16566. dataZoom: {
  16567. title: {
  16568. zoom: '区域缩放',
  16569. back: '区域缩放还原'
  16570. }
  16571. },
  16572. magicType: {
  16573. title: {
  16574. line: '切换为折线图',
  16575. bar: '切换为柱状图',
  16576. stack: '切换为堆叠',
  16577. tiled: '切换为平铺'
  16578. }
  16579. },
  16580. restore: {
  16581. title: '还原'
  16582. },
  16583. saveAsImage: {
  16584. title: '保存为图片',
  16585. lang: ['右键另存为图片']
  16586. }
  16587. },
  16588. series: {
  16589. typeNames: {
  16590. pie: '饼图',
  16591. bar: '柱状图',
  16592. line: '折线图',
  16593. scatter: '散点图',
  16594. effectScatter: '涟漪散点图',
  16595. radar: '雷达图',
  16596. tree: '树图',
  16597. treemap: '矩形树图',
  16598. boxplot: '箱型图',
  16599. candlestick: 'K线图',
  16600. k: 'K线图',
  16601. heatmap: '热力图',
  16602. map: '地图',
  16603. parallel: '平行坐标图',
  16604. lines: '线图',
  16605. graph: '关系图',
  16606. sankey: '桑基图',
  16607. funnel: '漏斗图',
  16608. gauge: '仪表盘图',
  16609. pictorialBar: '象形柱图',
  16610. themeRiver: '主题河流图',
  16611. sunburst: '旭日图',
  16612. custom: '自定义图表',
  16613. chart: '图表'
  16614. }
  16615. },
  16616. aria: {
  16617. general: {
  16618. withTitle: '这是一个关于“{title}”的图表。',
  16619. withoutTitle: '这是一个图表,'
  16620. },
  16621. series: {
  16622. single: {
  16623. prefix: '',
  16624. withName: '图表类型是{seriesType},表示{seriesName}。',
  16625. withoutName: '图表类型是{seriesType}。'
  16626. },
  16627. multiple: {
  16628. prefix: '它由{seriesCount}个图表系列组成。',
  16629. withName: '第{seriesId}个系列是一个表示{seriesName}的{seriesType},',
  16630. withoutName: '第{seriesId}个系列是一个{seriesType},',
  16631. separator: {
  16632. middle: ';',
  16633. end: '。'
  16634. }
  16635. }
  16636. },
  16637. data: {
  16638. allData: '其数据是——',
  16639. partialData: '其中,前{displayCnt}项是——',
  16640. withName: '{name}的数据是{value}',
  16641. withoutName: '{value}',
  16642. separator: {
  16643. middle: ',',
  16644. end: ''
  16645. }
  16646. }
  16647. }
  16648. };
  16649. var LOCALE_ZH = 'ZH';
  16650. var LOCALE_EN = 'EN';
  16651. var DEFAULT_LOCALE = LOCALE_EN;
  16652. var localeStorage = {};
  16653. var localeModels = {};
  16654. var SYSTEM_LANG = !env.domSupported ? DEFAULT_LOCALE : function () {
  16655. var langStr = (/* eslint-disable-next-line */
  16656. document.documentElement.lang || navigator.language || navigator.browserLanguage || DEFAULT_LOCALE).toUpperCase();
  16657. return langStr.indexOf(LOCALE_ZH) > -1 ? LOCALE_ZH : DEFAULT_LOCALE;
  16658. }();
  16659. function registerLocale(locale, localeObj) {
  16660. locale = locale.toUpperCase();
  16661. localeModels[locale] = new Model(localeObj);
  16662. localeStorage[locale] = localeObj;
  16663. }
  16664. // export function getLocale(locale: string) {
  16665. // return localeStorage[locale];
  16666. // }
  16667. function createLocaleObject(locale) {
  16668. if (isString(locale)) {
  16669. var localeObj = localeStorage[locale.toUpperCase()] || {};
  16670. if (locale === LOCALE_ZH || locale === LOCALE_EN) {
  16671. return clone(localeObj);
  16672. } else {
  16673. return merge(clone(localeObj), clone(localeStorage[DEFAULT_LOCALE]), false);
  16674. }
  16675. } else {
  16676. return merge(clone(locale), clone(localeStorage[DEFAULT_LOCALE]), false);
  16677. }
  16678. }
  16679. function getLocaleModel(lang) {
  16680. return localeModels[lang];
  16681. }
  16682. function getDefaultLocaleModel() {
  16683. return localeModels[DEFAULT_LOCALE];
  16684. }
  16685. // Default locale
  16686. registerLocale(LOCALE_EN, langEN);
  16687. registerLocale(LOCALE_ZH, langZH);
  16688. var _impl = null;
  16689. function registerScaleBreakHelperImpl(impl) {
  16690. if (!_impl) {
  16691. _impl = impl;
  16692. }
  16693. }
  16694. function getScaleBreakHelper() {
  16695. return _impl;
  16696. }
  16697. var ONE_SECOND = 1000;
  16698. var ONE_MINUTE = ONE_SECOND * 60;
  16699. var ONE_HOUR = ONE_MINUTE * 60;
  16700. var ONE_DAY = ONE_HOUR * 24;
  16701. var ONE_YEAR = ONE_DAY * 365;
  16702. var primaryTimeUnitFormatterMatchers = {
  16703. year: /({yyyy}|{yy})/,
  16704. month: /({MMMM}|{MMM}|{MM}|{M})/,
  16705. day: /({dd}|{d})/,
  16706. hour: /({HH}|{H}|{hh}|{h})/,
  16707. minute: /({mm}|{m})/,
  16708. second: /({ss}|{s})/,
  16709. millisecond: /({SSS}|{S})/
  16710. };
  16711. var defaultFormatterSeed = {
  16712. year: '{yyyy}',
  16713. month: '{MMM}',
  16714. day: '{d}',
  16715. hour: '{HH}:{mm}',
  16716. minute: '{HH}:{mm}',
  16717. second: '{HH}:{mm}:{ss}',
  16718. millisecond: '{HH}:{mm}:{ss} {SSS}'
  16719. };
  16720. var defaultFullFormatter = '{yyyy}-{MM}-{dd} {HH}:{mm}:{ss} {SSS}';
  16721. var fullDayFormatter = '{yyyy}-{MM}-{dd}';
  16722. var fullLeveledFormatter = {
  16723. year: '{yyyy}',
  16724. month: '{yyyy}-{MM}',
  16725. day: fullDayFormatter,
  16726. hour: fullDayFormatter + ' ' + defaultFormatterSeed.hour,
  16727. minute: fullDayFormatter + ' ' + defaultFormatterSeed.minute,
  16728. second: fullDayFormatter + ' ' + defaultFormatterSeed.second,
  16729. millisecond: defaultFullFormatter
  16730. };
  16731. // Order must be ensured from big to small.
  16732. var primaryTimeUnits = ['year', 'month', 'day', 'hour', 'minute', 'second', 'millisecond'];
  16733. var timeUnits = ['year', 'half-year', 'quarter', 'month', 'week', 'half-week', 'day', 'half-day', 'quarter-day', 'hour', 'minute', 'second', 'millisecond'];
  16734. function parseTimeAxisLabelFormatter(formatter) {
  16735. // Keep the logic the same with function `leveledFormat`.
  16736. return !isString(formatter) && !isFunction(formatter) ? parseTimeAxisLabelFormatterDictionary(formatter) : formatter;
  16737. }
  16738. /**
  16739. * The final generated dictionary is like:
  16740. * generated_dict = {
  16741. * year: {
  16742. * year: ['{yyyy}', ...<higher_levels_if_any>]
  16743. * },
  16744. * month: {
  16745. * year: ['{yyyy} {MMM}', ...<higher_levels_if_any>],
  16746. * month: ['{MMM}', ...<higher_levels_if_any>]
  16747. * },
  16748. * day: {
  16749. * year: ['{yyyy} {MMM} {d}', ...<higher_levels_if_any>],
  16750. * month: ['{MMM} {d}', ...<higher_levels_if_any>],
  16751. * day: ['{d}', ...<higher_levels_if_any>]
  16752. * },
  16753. * ...
  16754. * }
  16755. *
  16756. * In echarts option, users can specify the entire dictionary or typically just:
  16757. * {formatter: {
  16758. * year: '{yyyy}', // Or an array of leveled templates: `['{yyyy}', '{bold1|{yyyy}}', ...]`,
  16759. * // corresponding to `[level0, level1, level2, ...]`.
  16760. * month: '{MMM}',
  16761. * day: '{d}',
  16762. * hour: '{HH}:{mm}',
  16763. * second: '{HH}:{mm}',
  16764. * ...
  16765. * }}
  16766. * If any time unit is not specified in echarts option, the default template is used,
  16767. * such as `['{yyyy}', {primary|{yyyy}']`.
  16768. *
  16769. * The `tick.level` is only used to read string from each array, meaning the style type.
  16770. *
  16771. * Let `lowerUnit = getUnitFromValue(tick.value)`.
  16772. * The non-break axis ticks only use `generated_dict[lowerUnit][lowerUnit][level]`.
  16773. * The break axis ticks may use `generated_dict[lowerUnit][upperUnit][level]`, because:
  16774. * Consider the case: the non-break ticks are `16th, 23th, Feb, 7th, ...`, where `Feb` is in the break
  16775. * range and pruned by breaks, and the break ends might be in lower time unit than day. e.g., break start
  16776. * is `Jan 25th 18:00`(in unit `hour`) and break end is `Feb 6th 18:30` (in unit `minute`). Thus the break
  16777. * label prefers `Jan 25th 18:00` and `Feb 6th 18:30` rather than only `18:00` and `18:30`, otherwise it
  16778. * causes misleading.
  16779. * In this case, the tick of the break start and end will both be:
  16780. * `{level: 1, lowerTimeUnit: 'minute', upperTimeUnit: 'month'}`
  16781. * And get the final template by `generated_dict[lowerTimeUnit][upperTimeUnit][level]`.
  16782. * Note that the time unit can not be calculated directly by a single tick value, since the two breaks have
  16783. * to be at the same time unit to avoid awkward appearance. i.e., `Jan 25th 18:00` is in the time unit "hour"
  16784. * but we need it to be "minute", following `Feb 6th 18:30`.
  16785. */
  16786. function parseTimeAxisLabelFormatterDictionary(dictOption) {
  16787. dictOption = dictOption || {};
  16788. var dict = {};
  16789. // Currently if any template is specified by user, it may contain rich text tag,
  16790. // such as `'{my_bold|{YYYY}}'`, thus we do add highlight style to it.
  16791. // (Note that nested tag (`'{some|{some2|xxx}}'`) in rich text is not supported yet.)
  16792. var canAddHighlight = true;
  16793. each(primaryTimeUnits, function (lowestUnit) {
  16794. canAddHighlight && (canAddHighlight = dictOption[lowestUnit] == null);
  16795. });
  16796. each(primaryTimeUnits, function (lowestUnit, lowestUnitIdx) {
  16797. var upperDictOption = dictOption[lowestUnit];
  16798. dict[lowestUnit] = {};
  16799. var lowerTpl = null;
  16800. for (var upperUnitIdx = lowestUnitIdx; upperUnitIdx >= 0; upperUnitIdx--) {
  16801. var upperUnit = primaryTimeUnits[upperUnitIdx];
  16802. var upperDictItemOption = isObject(upperDictOption) && !isArray(upperDictOption) ? upperDictOption[upperUnit] : upperDictOption;
  16803. var tplArr = void 0;
  16804. if (isArray(upperDictItemOption)) {
  16805. tplArr = upperDictItemOption.slice();
  16806. lowerTpl = tplArr[0] || '';
  16807. } else if (isString(upperDictItemOption)) {
  16808. lowerTpl = upperDictItemOption;
  16809. tplArr = [lowerTpl];
  16810. } else {
  16811. if (lowerTpl == null) {
  16812. lowerTpl = defaultFormatterSeed[lowestUnit];
  16813. }
  16814. // Generate the dict by the rule as follows:
  16815. // If the user specify (or by default):
  16816. // {formatter: {
  16817. // year: '{yyyy}',
  16818. // month: '{MMM}',
  16819. // day: '{d}',
  16820. // ...
  16821. // }}
  16822. // Concat them to make the final dictionary:
  16823. // {formatter: {
  16824. // year: {year: ['{yyyy}']},
  16825. // month: {year: ['{yyyy} {MMM}'], month: ['{MMM}']},
  16826. // day: {year: ['{yyyy} {MMM} {d}'], month: ['{MMM} {d}'], day: ['{d}']}
  16827. // ...
  16828. // }}
  16829. // And then add `{primary|...}` to each array if from default template.
  16830. // This strategy is convinient for user configurating and works for most cases.
  16831. // If bad cases encountered, users can specify the entire dictionary themselves
  16832. // instead of going through this logic.
  16833. else if (!primaryTimeUnitFormatterMatchers[upperUnit].test(lowerTpl)) {
  16834. lowerTpl = dict[upperUnit][upperUnit][0] + " " + lowerTpl;
  16835. }
  16836. tplArr = [lowerTpl];
  16837. if (canAddHighlight) {
  16838. tplArr[1] = "{primary|" + lowerTpl + "}";
  16839. }
  16840. }
  16841. dict[lowestUnit][upperUnit] = tplArr;
  16842. }
  16843. });
  16844. return dict;
  16845. }
  16846. function pad(str, len) {
  16847. str += '';
  16848. return '0000'.substr(0, len - str.length) + str;
  16849. }
  16850. function getPrimaryTimeUnit(timeUnit) {
  16851. switch (timeUnit) {
  16852. case 'half-year':
  16853. case 'quarter':
  16854. return 'month';
  16855. case 'week':
  16856. case 'half-week':
  16857. return 'day';
  16858. case 'half-day':
  16859. case 'quarter-day':
  16860. return 'hour';
  16861. default:
  16862. // year, minutes, second, milliseconds
  16863. return timeUnit;
  16864. }
  16865. }
  16866. function isPrimaryTimeUnit(timeUnit) {
  16867. return timeUnit === getPrimaryTimeUnit(timeUnit);
  16868. }
  16869. function getDefaultFormatPrecisionOfInterval(timeUnit) {
  16870. switch (timeUnit) {
  16871. case 'year':
  16872. case 'month':
  16873. return 'day';
  16874. case 'millisecond':
  16875. return 'millisecond';
  16876. default:
  16877. // Also for day, hour, minute, second
  16878. return 'second';
  16879. }
  16880. }
  16881. function format(
  16882. // Note: The result based on `isUTC` are totally different, which can not be just simply
  16883. // substituted by the result without `isUTC`. So we make the param `isUTC` mandatory.
  16884. time, template, isUTC, lang) {
  16885. var date = parseDate(time);
  16886. var y = date[fullYearGetterName(isUTC)]();
  16887. var M = date[monthGetterName(isUTC)]() + 1;
  16888. var q = Math.floor((M - 1) / 3) + 1;
  16889. var d = date[dateGetterName(isUTC)]();
  16890. var e = date['get' + (isUTC ? 'UTC' : '') + 'Day']();
  16891. var H = date[hoursGetterName(isUTC)]();
  16892. var h = (H - 1) % 12 + 1;
  16893. var m = date[minutesGetterName(isUTC)]();
  16894. var s = date[secondsGetterName(isUTC)]();
  16895. var S = date[millisecondsGetterName(isUTC)]();
  16896. var a = H >= 12 ? 'pm' : 'am';
  16897. var A = a.toUpperCase();
  16898. var localeModel = lang instanceof Model ? lang : getLocaleModel(lang || SYSTEM_LANG) || getDefaultLocaleModel();
  16899. var timeModel = localeModel.getModel('time');
  16900. var month = timeModel.get('month');
  16901. var monthAbbr = timeModel.get('monthAbbr');
  16902. var dayOfWeek = timeModel.get('dayOfWeek');
  16903. var dayOfWeekAbbr = timeModel.get('dayOfWeekAbbr');
  16904. return (template || '').replace(/{a}/g, a + '').replace(/{A}/g, A + '').replace(/{yyyy}/g, y + '').replace(/{yy}/g, pad(y % 100 + '', 2)).replace(/{Q}/g, q + '').replace(/{MMMM}/g, month[M - 1]).replace(/{MMM}/g, monthAbbr[M - 1]).replace(/{MM}/g, pad(M, 2)).replace(/{M}/g, M + '').replace(/{dd}/g, pad(d, 2)).replace(/{d}/g, d + '').replace(/{eeee}/g, dayOfWeek[e]).replace(/{ee}/g, dayOfWeekAbbr[e]).replace(/{e}/g, e + '').replace(/{HH}/g, pad(H, 2)).replace(/{H}/g, H + '').replace(/{hh}/g, pad(h + '', 2)).replace(/{h}/g, h + '').replace(/{mm}/g, pad(m, 2)).replace(/{m}/g, m + '').replace(/{ss}/g, pad(s, 2)).replace(/{s}/g, s + '').replace(/{SSS}/g, pad(S, 3)).replace(/{S}/g, S + '');
  16905. }
  16906. function leveledFormat(tick, idx, formatter, lang, isUTC) {
  16907. var template = null;
  16908. if (isString(formatter)) {
  16909. // Single formatter for all units at all levels
  16910. template = formatter;
  16911. } else if (isFunction(formatter)) {
  16912. var extra = {
  16913. time: tick.time,
  16914. level: tick.time.level
  16915. };
  16916. var scaleBreakHelper = getScaleBreakHelper();
  16917. if (scaleBreakHelper) {
  16918. scaleBreakHelper.makeAxisLabelFormatterParamBreak(extra, tick["break"]);
  16919. }
  16920. template = formatter(tick.value, idx, extra);
  16921. } else {
  16922. var tickTime = tick.time;
  16923. if (tickTime) {
  16924. var leveledTplArr = formatter[tickTime.lowerTimeUnit][tickTime.upperTimeUnit];
  16925. template = leveledTplArr[Math.min(tickTime.level, leveledTplArr.length - 1)] || '';
  16926. } else {
  16927. // tick may be from customTicks or timeline therefore no tick.time.
  16928. var unit = getUnitFromValue(tick.value, isUTC);
  16929. template = formatter[unit][unit][0];
  16930. }
  16931. }
  16932. return format(new Date(tick.value), template, isUTC, lang);
  16933. }
  16934. function getUnitFromValue(value, isUTC) {
  16935. var date = parseDate(value);
  16936. var M = date[monthGetterName(isUTC)]() + 1;
  16937. var d = date[dateGetterName(isUTC)]();
  16938. var h = date[hoursGetterName(isUTC)]();
  16939. var m = date[minutesGetterName(isUTC)]();
  16940. var s = date[secondsGetterName(isUTC)]();
  16941. var S = date[millisecondsGetterName(isUTC)]();
  16942. var isSecond = S === 0;
  16943. var isMinute = isSecond && s === 0;
  16944. var isHour = isMinute && m === 0;
  16945. var isDay = isHour && h === 0;
  16946. var isMonth = isDay && d === 1;
  16947. var isYear = isMonth && M === 1;
  16948. if (isYear) {
  16949. return 'year';
  16950. } else if (isMonth) {
  16951. return 'month';
  16952. } else if (isDay) {
  16953. return 'day';
  16954. } else if (isHour) {
  16955. return 'hour';
  16956. } else if (isMinute) {
  16957. return 'minute';
  16958. } else if (isSecond) {
  16959. return 'second';
  16960. } else {
  16961. return 'millisecond';
  16962. }
  16963. }
  16964. // export function getUnitValue(
  16965. // value: number | Date,
  16966. // unit: TimeUnit,
  16967. // isUTC: boolean
  16968. // ) : number {
  16969. // const date = zrUtil.isNumber(value)
  16970. // ? numberUtil.parseDate(value)
  16971. // : value;
  16972. // unit = unit || getUnitFromValue(value, isUTC);
  16973. // switch (unit) {
  16974. // case 'year':
  16975. // return date[fullYearGetterName(isUTC)]();
  16976. // case 'half-year':
  16977. // return date[monthGetterName(isUTC)]() >= 6 ? 1 : 0;
  16978. // case 'quarter':
  16979. // return Math.floor((date[monthGetterName(isUTC)]() + 1) / 4);
  16980. // case 'month':
  16981. // return date[monthGetterName(isUTC)]();
  16982. // case 'day':
  16983. // return date[dateGetterName(isUTC)]();
  16984. // case 'half-day':
  16985. // return date[hoursGetterName(isUTC)]() / 24;
  16986. // case 'hour':
  16987. // return date[hoursGetterName(isUTC)]();
  16988. // case 'minute':
  16989. // return date[minutesGetterName(isUTC)]();
  16990. // case 'second':
  16991. // return date[secondsGetterName(isUTC)]();
  16992. // case 'millisecond':
  16993. // return date[millisecondsGetterName(isUTC)]();
  16994. // }
  16995. // }
  16996. /**
  16997. * e.g.,
  16998. * If timeUnit is 'year', return the Jan 1st 00:00:00 000 of that year.
  16999. * If timeUnit is 'day', return the 00:00:00 000 of that day.
  17000. *
  17001. * @return The input date.
  17002. */
  17003. function roundTime(date, timeUnit, isUTC) {
  17004. switch (timeUnit) {
  17005. case 'year':
  17006. date[monthSetterName(isUTC)](0);
  17007. case 'month':
  17008. date[dateSetterName(isUTC)](1);
  17009. case 'day':
  17010. date[hoursSetterName(isUTC)](0);
  17011. case 'hour':
  17012. date[minutesSetterName(isUTC)](0);
  17013. case 'minute':
  17014. date[secondsSetterName(isUTC)](0);
  17015. case 'second':
  17016. date[millisecondsSetterName(isUTC)](0);
  17017. }
  17018. return date;
  17019. }
  17020. function fullYearGetterName(isUTC) {
  17021. return isUTC ? 'getUTCFullYear' : 'getFullYear';
  17022. }
  17023. function monthGetterName(isUTC) {
  17024. return isUTC ? 'getUTCMonth' : 'getMonth';
  17025. }
  17026. function dateGetterName(isUTC) {
  17027. return isUTC ? 'getUTCDate' : 'getDate';
  17028. }
  17029. function hoursGetterName(isUTC) {
  17030. return isUTC ? 'getUTCHours' : 'getHours';
  17031. }
  17032. function minutesGetterName(isUTC) {
  17033. return isUTC ? 'getUTCMinutes' : 'getMinutes';
  17034. }
  17035. function secondsGetterName(isUTC) {
  17036. return isUTC ? 'getUTCSeconds' : 'getSeconds';
  17037. }
  17038. function millisecondsGetterName(isUTC) {
  17039. return isUTC ? 'getUTCMilliseconds' : 'getMilliseconds';
  17040. }
  17041. function fullYearSetterName(isUTC) {
  17042. return isUTC ? 'setUTCFullYear' : 'setFullYear';
  17043. }
  17044. function monthSetterName(isUTC) {
  17045. return isUTC ? 'setUTCMonth' : 'setMonth';
  17046. }
  17047. function dateSetterName(isUTC) {
  17048. return isUTC ? 'setUTCDate' : 'setDate';
  17049. }
  17050. function hoursSetterName(isUTC) {
  17051. return isUTC ? 'setUTCHours' : 'setHours';
  17052. }
  17053. function minutesSetterName(isUTC) {
  17054. return isUTC ? 'setUTCMinutes' : 'setMinutes';
  17055. }
  17056. function secondsSetterName(isUTC) {
  17057. return isUTC ? 'setUTCSeconds' : 'setSeconds';
  17058. }
  17059. function millisecondsSetterName(isUTC) {
  17060. return isUTC ? 'setUTCMilliseconds' : 'setMilliseconds';
  17061. }
  17062. function getTextRect(text, font, align, verticalAlign, padding, rich, truncate, lineHeight) {
  17063. var textEl = new ZRText({
  17064. style: {
  17065. text: text,
  17066. font: font,
  17067. align: align,
  17068. verticalAlign: verticalAlign,
  17069. padding: padding,
  17070. rich: rich,
  17071. overflow: truncate ? 'truncate' : null,
  17072. lineHeight: lineHeight
  17073. }
  17074. });
  17075. return textEl.getBoundingRect();
  17076. }
  17077. /**
  17078. * Add a comma each three digit.
  17079. */
  17080. function addCommas(x) {
  17081. if (!isNumeric(x)) {
  17082. return isString(x) ? x : '-';
  17083. }
  17084. var parts = (x + '').split('.');
  17085. return parts[0].replace(/(\d{1,3})(?=(?:\d{3})+(?!\d))/g, '$1,') + (parts.length > 1 ? '.' + parts[1] : '');
  17086. }
  17087. function toCamelCase(str, upperCaseFirst) {
  17088. str = (str || '').toLowerCase().replace(/-(.)/g, function (match, group1) {
  17089. return group1.toUpperCase();
  17090. });
  17091. if (upperCaseFirst && str) {
  17092. str = str.charAt(0).toUpperCase() + str.slice(1);
  17093. }
  17094. return str;
  17095. }
  17096. var normalizeCssArray$1 = normalizeCssArray;
  17097. /**
  17098. * Make value user readable for tooltip and label.
  17099. * "User readable":
  17100. * Try to not print programmer-specific text like NaN, Infinity, null, undefined.
  17101. * Avoid to display an empty string, which users can not recognize there is
  17102. * a value and it might look like a bug.
  17103. */
  17104. function makeValueReadable(value, valueType, useUTC) {
  17105. var USER_READABLE_DEFUALT_TIME_PATTERN = '{yyyy}-{MM}-{dd} {HH}:{mm}:{ss}';
  17106. function stringToUserReadable(str) {
  17107. return str && trim(str) ? str : '-';
  17108. }
  17109. function isNumberUserReadable(num) {
  17110. return !!(num != null && !isNaN(num) && isFinite(num));
  17111. }
  17112. var isTypeTime = valueType === 'time';
  17113. var isValueDate = value instanceof Date;
  17114. if (isTypeTime || isValueDate) {
  17115. var date = isTypeTime ? parseDate(value) : value;
  17116. if (!isNaN(+date)) {
  17117. return format(date, USER_READABLE_DEFUALT_TIME_PATTERN, useUTC);
  17118. } else if (isValueDate) {
  17119. return '-';
  17120. }
  17121. // In other cases, continue to try to display the value in the following code.
  17122. }
  17123. if (valueType === 'ordinal') {
  17124. return isStringSafe(value) ? stringToUserReadable(value) : isNumber(value) ? isNumberUserReadable(value) ? value + '' : '-' : '-';
  17125. }
  17126. // By default.
  17127. var numericResult = numericToNumber(value);
  17128. return isNumberUserReadable(numericResult) ? addCommas(numericResult) : isStringSafe(value) ? stringToUserReadable(value) : typeof value === 'boolean' ? value + '' : '-';
  17129. }
  17130. var TPL_VAR_ALIAS = ['a', 'b', 'c', 'd', 'e', 'f', 'g'];
  17131. var wrapVar = function (varName, seriesIdx) {
  17132. return '{' + varName + (seriesIdx == null ? '' : seriesIdx) + '}';
  17133. };
  17134. /**
  17135. * Template formatter
  17136. * @param {Array.<Object>|Object} paramsList
  17137. */
  17138. function formatTpl(tpl, paramsList, encode) {
  17139. if (!isArray(paramsList)) {
  17140. paramsList = [paramsList];
  17141. }
  17142. var seriesLen = paramsList.length;
  17143. if (!seriesLen) {
  17144. return '';
  17145. }
  17146. var $vars = paramsList[0].$vars || [];
  17147. for (var i = 0; i < $vars.length; i++) {
  17148. var alias = TPL_VAR_ALIAS[i];
  17149. tpl = tpl.replace(wrapVar(alias), wrapVar(alias, 0));
  17150. }
  17151. for (var seriesIdx = 0; seriesIdx < seriesLen; seriesIdx++) {
  17152. for (var k = 0; k < $vars.length; k++) {
  17153. var val = paramsList[seriesIdx][$vars[k]];
  17154. tpl = tpl.replace(wrapVar(TPL_VAR_ALIAS[k], seriesIdx), encode ? encodeHTML(val) : val);
  17155. }
  17156. }
  17157. return tpl;
  17158. }
  17159. /**
  17160. * simple Template formatter
  17161. */
  17162. function formatTplSimple(tpl, param, encode) {
  17163. each(param, function (value, key) {
  17164. tpl = tpl.replace('{' + key + '}', encode ? encodeHTML(value) : value);
  17165. });
  17166. return tpl;
  17167. }
  17168. function getTooltipMarker(inOpt, extraCssText) {
  17169. var opt = isString(inOpt) ? {
  17170. color: inOpt,
  17171. extraCssText: extraCssText
  17172. } : inOpt || {};
  17173. var color = opt.color;
  17174. var type = opt.type;
  17175. extraCssText = opt.extraCssText;
  17176. var renderMode = opt.renderMode || 'html';
  17177. if (!color) {
  17178. return '';
  17179. }
  17180. if (renderMode === 'html') {
  17181. return type === 'subItem' ? '<span style="display:inline-block;vertical-align:middle;margin-right:8px;margin-left:3px;' + 'border-radius:4px;width:4px;height:4px;background-color:'
  17182. // Only support string
  17183. + encodeHTML(color) + ';' + (extraCssText || '') + '"></span>' : '<span style="display:inline-block;margin-right:4px;' + 'border-radius:10px;width:10px;height:10px;background-color:' + encodeHTML(color) + ';' + (extraCssText || '') + '"></span>';
  17184. } else {
  17185. // Should better not to auto generate style name by auto-increment number here.
  17186. // Because this util is usually called in tooltip formatter, which is probably
  17187. // called repeatedly when mouse move and the auto-increment number increases fast.
  17188. // Users can make their own style name by theirselves, make it unique and readable.
  17189. var markerId = opt.markerId || 'markerX';
  17190. return {
  17191. renderMode: renderMode,
  17192. content: '{' + markerId + '|} ',
  17193. style: type === 'subItem' ? {
  17194. width: 4,
  17195. height: 4,
  17196. borderRadius: 2,
  17197. backgroundColor: color
  17198. } : {
  17199. width: 10,
  17200. height: 10,
  17201. borderRadius: 5,
  17202. backgroundColor: color
  17203. }
  17204. };
  17205. }
  17206. }
  17207. /**
  17208. * @deprecated Use `time/format` instead.
  17209. * ISO Date format
  17210. * @param {string} tpl
  17211. * @param {number} value
  17212. * @param {boolean} [isUTC=false] Default in local time.
  17213. * see `module:echarts/scale/Time`
  17214. * and `module:echarts/util/number#parseDate`.
  17215. * @inner
  17216. */
  17217. function formatTime(tpl, value, isUTC) {
  17218. if ("development" !== 'production') {
  17219. deprecateReplaceLog('echarts.format.formatTime', 'echarts.time.format');
  17220. }
  17221. if (tpl === 'week' || tpl === 'month' || tpl === 'quarter' || tpl === 'half-year' || tpl === 'year') {
  17222. tpl = 'MM-dd\nyyyy';
  17223. }
  17224. var date = parseDate(value);
  17225. var getUTC = isUTC ? 'getUTC' : 'get';
  17226. var y = date[getUTC + 'FullYear']();
  17227. var M = date[getUTC + 'Month']() + 1;
  17228. var d = date[getUTC + 'Date']();
  17229. var h = date[getUTC + 'Hours']();
  17230. var m = date[getUTC + 'Minutes']();
  17231. var s = date[getUTC + 'Seconds']();
  17232. var S = date[getUTC + 'Milliseconds']();
  17233. tpl = tpl.replace('MM', pad(M, 2)).replace('M', M).replace('yyyy', y).replace('yy', pad(y % 100 + '', 2)).replace('dd', pad(d, 2)).replace('d', d).replace('hh', pad(h, 2)).replace('h', h).replace('mm', pad(m, 2)).replace('m', m).replace('ss', pad(s, 2)).replace('s', s).replace('SSS', pad(S, 3));
  17234. return tpl;
  17235. }
  17236. /**
  17237. * Capital first
  17238. * @param {string} str
  17239. * @return {string}
  17240. */
  17241. function capitalFirst(str) {
  17242. return str ? str.charAt(0).toUpperCase() + str.substr(1) : str;
  17243. }
  17244. /**
  17245. * @return Never be null/undefined.
  17246. */
  17247. function convertToColorString(color, defaultColor) {
  17248. defaultColor = defaultColor || 'transparent';
  17249. return isString(color) ? color : isObject(color) ? color.colorStops && (color.colorStops[0] || {}).color || defaultColor : defaultColor;
  17250. }
  17251. /**
  17252. * open new tab
  17253. * @param link url
  17254. * @param target blank or self
  17255. */
  17256. function windowOpen(link, target) {
  17257. /* global window */
  17258. if (target === '_blank' || target === 'blank') {
  17259. var blank = window.open();
  17260. blank.opener = null;
  17261. blank.location.href = link;
  17262. } else {
  17263. window.open(link, target);
  17264. }
  17265. }
  17266. /**
  17267. * FIXME:
  17268. * `nonSeriesBoxCoordSysCreators` and `_nonSeriesBoxMasterList` are hardcoded implementations.
  17269. * Regarding "coord sys layout based on another coord sys", currently we only exprimentally support one level
  17270. * dpendency, such as, "grid(cartesian)s can be laid out based on matrix/calendar coord sys."
  17271. * But a comprehensive implementation may need to support:
  17272. * - Recursive dependencies. e.g., a matrix coord sys lays out based on another matrix coord sys.
  17273. * That requires in the implementation `create` and `update` of coord sys are called by a dependency graph.
  17274. * (@see enableTopologicalTravel in `util/component.ts`)
  17275. */
  17276. var nonSeriesBoxCoordSysCreators = {};
  17277. var normalCoordSysCreators = {};
  17278. var CoordinateSystemManager = /** @class */function () {
  17279. function CoordinateSystemManager() {
  17280. this._normalMasterList = [];
  17281. this._nonSeriesBoxMasterList = [];
  17282. }
  17283. /**
  17284. * Typically,
  17285. * - in `create`, a coord sys lays out based on a given rect;
  17286. * - in `update`, update the pixel and data extent of there axes (if any) based on processed `series.data`.
  17287. * After that, a coord sys can serve (typically by `dataToPoint`/`dataToLayout`/`pointToData`).
  17288. * If the coordinate system do not lay out based on `series.data`, `update` is not needed.
  17289. */
  17290. CoordinateSystemManager.prototype.create = function (ecModel, api) {
  17291. this._nonSeriesBoxMasterList = dealCreate(nonSeriesBoxCoordSysCreators, true);
  17292. this._normalMasterList = dealCreate(normalCoordSysCreators, false);
  17293. function dealCreate(creatorMap, canBeNonSeriesBox) {
  17294. var coordinateSystems = [];
  17295. each(creatorMap, function (creator, type) {
  17296. var list = creator.create(ecModel, api);
  17297. coordinateSystems = coordinateSystems.concat(list || []);
  17298. if ("development" !== 'production') {
  17299. if (canBeNonSeriesBox) {
  17300. // Disallow `update` is a brutal way to ensure `_nonSeriesBoxMasterList`s are ready to
  17301. // serve after `create`. But if `update` has to be involved in `_nonSeriesBoxMasterList`
  17302. // for some future case, more complicated mechanisms need to be introduced.
  17303. each(list, function (master) {
  17304. return assert(!master.update);
  17305. });
  17306. }
  17307. }
  17308. });
  17309. return coordinateSystems;
  17310. }
  17311. };
  17312. /**
  17313. * @see CoordinateSystem['create']
  17314. */
  17315. CoordinateSystemManager.prototype.update = function (ecModel, api) {
  17316. each(this._normalMasterList, function (coordSys) {
  17317. coordSys.update && coordSys.update(ecModel, api);
  17318. });
  17319. };
  17320. CoordinateSystemManager.prototype.getCoordinateSystems = function () {
  17321. return this._normalMasterList.concat(this._nonSeriesBoxMasterList);
  17322. };
  17323. CoordinateSystemManager.register = function (type, creator) {
  17324. if (type === 'matrix' || type === 'calendar') {
  17325. // FIXME: hardcode, @see nonSeriesBoxCoordSysCreators
  17326. nonSeriesBoxCoordSysCreators[type] = creator;
  17327. return;
  17328. }
  17329. normalCoordSysCreators[type] = creator;
  17330. };
  17331. CoordinateSystemManager.get = function (type) {
  17332. return normalCoordSysCreators[type] || nonSeriesBoxCoordSysCreators[type];
  17333. };
  17334. return CoordinateSystemManager;
  17335. }();
  17336. function canBeNonSeriesBoxCoordSys(coordSysType) {
  17337. return !!nonSeriesBoxCoordSysCreators[coordSysType];
  17338. }
  17339. var BoxCoordinateSystemCoordFrom = {
  17340. // By default fetch coord from `model.get('coord')`.
  17341. coord: 1,
  17342. // Some model/series, such as pie, is allowed to also get coord from `model.get('center')`,
  17343. // if cannot get from `model.get('coord')`. But historically pie use `center` option, but
  17344. // geo use `layoutCenter` option to specify layout center; they are not able to be unified.
  17345. // Therefor it is not recommended.
  17346. coord2: 2
  17347. };
  17348. /**
  17349. * @see_also `createBoxLayoutReference`
  17350. * @see_also `injectCoordSysByOption`
  17351. */
  17352. function registerLayOutOnCoordSysUsage(opt) {
  17353. if ("development" !== 'production') {
  17354. assert(!coordSysUseMap.get(opt.fullType));
  17355. }
  17356. coordSysUseMap.set(opt.fullType, {
  17357. getCoord2: undefined
  17358. }).getCoord2 = opt.getCoord2;
  17359. }
  17360. var coordSysUseMap = createHashMap();
  17361. /**
  17362. * @return Be an object, but never be NullUndefined.
  17363. */
  17364. function getCoordForBoxCoordSys(model) {
  17365. var coord = model.getShallow('coord', true);
  17366. var from = BoxCoordinateSystemCoordFrom.coord;
  17367. if (coord == null) {
  17368. var store = coordSysUseMap.get(model.type);
  17369. if (store && store.getCoord2) {
  17370. from = BoxCoordinateSystemCoordFrom.coord2;
  17371. coord = store.getCoord2(model);
  17372. }
  17373. }
  17374. return {
  17375. coord: coord,
  17376. from: from
  17377. };
  17378. }
  17379. /**
  17380. * - "dataCoordSys": each data item is laid out based on a coord sys.
  17381. * - "boxCoordSys": the overall bounding rect or anchor point is calculated based on a coord sys.
  17382. * e.g.,
  17383. * grid rect (cartesian rect) is calculate based on matrix/calendar coord sys;
  17384. * pie center is calculated based on calendar/cartesian;
  17385. *
  17386. * The default value (if not declared in option `coordinateSystemUsage`):
  17387. * For series, use `dataCoordSys`, since this is the most case and backward compatible.
  17388. * For non-series components, use `boxCoordSys`, since `dataCoordSys` is not applicable.
  17389. */
  17390. var CoordinateSystemUsageKind = {
  17391. none: 0,
  17392. dataCoordSys: 1,
  17393. boxCoordSys: 2
  17394. };
  17395. function decideCoordSysUsageKind(
  17396. // Component or series
  17397. model, printError) {
  17398. // For backward compat, still not use `true` in model.get.
  17399. var coordSysType = model.getShallow('coordinateSystem');
  17400. var coordSysUsageOption = model.getShallow('coordinateSystemUsage', true);
  17401. var isDeclaredExplicitly = coordSysUsageOption != null;
  17402. var kind = CoordinateSystemUsageKind.none;
  17403. if (coordSysType) {
  17404. var isSeries = model.mainType === 'series';
  17405. if (coordSysUsageOption == null) {
  17406. coordSysUsageOption = isSeries ? 'data' : 'box';
  17407. }
  17408. if (coordSysUsageOption === 'data') {
  17409. kind = CoordinateSystemUsageKind.dataCoordSys;
  17410. if (!isSeries) {
  17411. if ("development" !== 'production') {
  17412. if (isDeclaredExplicitly && printError) {
  17413. error('coordinateSystemUsage "data" is not supported in non-series components.');
  17414. }
  17415. }
  17416. kind = CoordinateSystemUsageKind.none;
  17417. }
  17418. } else if (coordSysUsageOption === 'box') {
  17419. kind = CoordinateSystemUsageKind.boxCoordSys;
  17420. if (!isSeries && !canBeNonSeriesBoxCoordSys(coordSysType)) {
  17421. if ("development" !== 'production') {
  17422. if (isDeclaredExplicitly && printError) {
  17423. error("coordinateSystem \"" + coordSysType + "\" cannot be used" + (" as coordinateSystemUsage \"box\" for \"" + model.type + "\" yet."));
  17424. }
  17425. }
  17426. kind = CoordinateSystemUsageKind.none;
  17427. }
  17428. }
  17429. }
  17430. return {
  17431. coordSysType: coordSysType,
  17432. kind: kind
  17433. };
  17434. }
  17435. /**
  17436. * These cases are considered:
  17437. * (A) Most series can use only "dataCoordSys", but "boxCoordSys" is not applicable:
  17438. * - e.g., series.heatmap, series.line, series.bar, series.scatter, ...
  17439. * (B) Some series and most components can use only "boxCoordSys", but "dataCoordSys" is not applicable:
  17440. * - e.g., series.pie, series.funnel, ...
  17441. * - e.g., grid, polar, geo, title, ...
  17442. * (C) Several series can use both "boxCoordSys" and "dataCoordSys", even at the same time:
  17443. * - e.g., series.graph, series.map
  17444. * - If graph or map series use a "boxCoordSys", it creates a internal "dataCoordSys" to lay out its data.
  17445. * - Graph series can use matrix coord sys as either the "dataCoordSys" (each item layout on one cell)
  17446. * or "boxCoordSys" (the entire series are layout within one cell).
  17447. * - To achieve this effect,
  17448. * `series.coordinateSystemUsage: 'box'` needs to be specified explicitly.
  17449. *
  17450. * Check these echarts option settings:
  17451. * - If `series: {type: 'bar'}`:
  17452. * dataCoordSys: "cartesian2d", boxCoordSys: "none".
  17453. * (since `coordinateSystem: 'cartesian2d'` is the default option in bar.)
  17454. * - If `grid: {coordinateSystem: 'matrix'}`
  17455. * dataCoordSys: "none", boxCoordSys: "matrix".
  17456. * - If `series: {type: 'pie', coordinateSystem: 'matrix'}`:
  17457. * dataCoordSys: "none", boxCoordSys: "matrix".
  17458. * (since `coordinateSystemUsage: 'box'` is the default option in pie.)
  17459. * - If `series: {type: 'graph', coordinateSystem: 'matrix'}`:
  17460. * dataCoordSys: "matrix", boxCoordSys: "none"
  17461. * - If `series: {type: 'graph', coordinateSystem: 'matrix', coordinateSystemUsage: 'box'}`:
  17462. * dataCoordSys: "an internal view", boxCoordSys: "the internal view is laid out on a matrix"
  17463. * - If `series: {type: 'map'}`:
  17464. * dataCoordSys: "a internal geo", boxCoordSys: "none"
  17465. * - If `series: {type: 'map', coordinateSystem: 'geo', geoIndex: 0}`:
  17466. * dataCoordSys: "a geo", boxCoordSys: "none"
  17467. * - If `series: {type: 'map', coordinateSystem: 'matrix'}`:
  17468. * not_applicable
  17469. * - If `series: {type: 'map', coordinateSystem: 'matrix', coordinateSystemUsage: 'box'}`:
  17470. * dataCoordSys: "an internal geo", boxCoordSys: "the internal geo is laid out on a matrix"
  17471. *
  17472. * @usage
  17473. * For case (A) & (B),
  17474. * call `injectCoordSysByOption({coordSysType: 'aaa', ...})` once for each series/components.
  17475. * For case (C),
  17476. * call `injectCoordSysByOption({coordSysType: 'aaa', ...})` once for each series/components,
  17477. * and then call `injectCoordSysByOption({coordSysType: 'bbb', ..., isDefaultDataCoordSys: true})`
  17478. * once for each series/components.
  17479. *
  17480. * @return Whether injected.
  17481. */
  17482. function injectCoordSysByOption(opt) {
  17483. var targetModel = opt.targetModel,
  17484. coordSysType = opt.coordSysType,
  17485. coordSysProvider = opt.coordSysProvider,
  17486. isDefaultDataCoordSys = opt.isDefaultDataCoordSys,
  17487. allowNotFound = opt.allowNotFound;
  17488. if ("development" !== 'production') {
  17489. assert(!!coordSysType);
  17490. }
  17491. var _a = decideCoordSysUsageKind(targetModel, true),
  17492. kind = _a.kind,
  17493. declaredType = _a.coordSysType;
  17494. if (isDefaultDataCoordSys && kind !== CoordinateSystemUsageKind.dataCoordSys) {
  17495. // If both dataCoordSys and boxCoordSys declared in one model.
  17496. // There is the only case in series-graph, and no other cases yet.
  17497. kind = CoordinateSystemUsageKind.dataCoordSys;
  17498. declaredType = coordSysType;
  17499. }
  17500. if (kind === CoordinateSystemUsageKind.none || declaredType !== coordSysType) {
  17501. return false;
  17502. }
  17503. var coordSys = coordSysProvider(coordSysType, targetModel);
  17504. if (!coordSys) {
  17505. if ("development" !== 'production') {
  17506. if (!allowNotFound) {
  17507. error(coordSysType + " cannot be found for" + (" " + targetModel.type + " (index: " + targetModel.componentIndex + ")."));
  17508. }
  17509. }
  17510. return false;
  17511. }
  17512. if (kind === CoordinateSystemUsageKind.dataCoordSys) {
  17513. if ("development" !== 'production') {
  17514. assert(targetModel.mainType === 'series');
  17515. }
  17516. targetModel.coordinateSystem = coordSys;
  17517. } else {
  17518. // kind === 'boxCoordSys'
  17519. targetModel.boxCoordinateSystem = coordSys;
  17520. }
  17521. return true;
  17522. }
  17523. var simpleCoordSysInjectionProvider = function (coordSysType, injectTargetModel) {
  17524. var coordSysModel = injectTargetModel.getReferringComponents(coordSysType, SINGLE_REFERRING).models[0];
  17525. return coordSysModel && coordSysModel.coordinateSystem;
  17526. };
  17527. var each$1 = each;
  17528. /**
  17529. * @public
  17530. */
  17531. var LOCATION_PARAMS = ['left', 'right', 'top', 'bottom', 'width', 'height'];
  17532. /**
  17533. * @public
  17534. */
  17535. var HV_NAMES = [['width', 'left', 'right'], ['height', 'top', 'bottom']];
  17536. function boxLayout(orient, group, gap, maxWidth, maxHeight) {
  17537. var x = 0;
  17538. var y = 0;
  17539. if (maxWidth == null) {
  17540. maxWidth = Infinity;
  17541. }
  17542. if (maxHeight == null) {
  17543. maxHeight = Infinity;
  17544. }
  17545. var currentLineMaxSize = 0;
  17546. group.eachChild(function (child, idx) {
  17547. var rect = child.getBoundingRect();
  17548. var nextChild = group.childAt(idx + 1);
  17549. var nextChildRect = nextChild && nextChild.getBoundingRect();
  17550. var nextX;
  17551. var nextY;
  17552. if (orient === 'horizontal') {
  17553. var moveX = rect.width + (nextChildRect ? -nextChildRect.x + rect.x : 0);
  17554. nextX = x + moveX;
  17555. // Wrap when width exceeds maxWidth or meet a `newline` group
  17556. // FIXME compare before adding gap?
  17557. if (nextX > maxWidth || child.newline) {
  17558. x = 0;
  17559. nextX = moveX;
  17560. y += currentLineMaxSize + gap;
  17561. currentLineMaxSize = rect.height;
  17562. } else {
  17563. // FIXME: consider rect.y is not `0`?
  17564. currentLineMaxSize = Math.max(currentLineMaxSize, rect.height);
  17565. }
  17566. } else {
  17567. var moveY = rect.height + (nextChildRect ? -nextChildRect.y + rect.y : 0);
  17568. nextY = y + moveY;
  17569. // Wrap when width exceeds maxHeight or meet a `newline` group
  17570. if (nextY > maxHeight || child.newline) {
  17571. x += currentLineMaxSize + gap;
  17572. y = 0;
  17573. nextY = moveY;
  17574. currentLineMaxSize = rect.width;
  17575. } else {
  17576. currentLineMaxSize = Math.max(currentLineMaxSize, rect.width);
  17577. }
  17578. }
  17579. if (child.newline) {
  17580. return;
  17581. }
  17582. child.x = x;
  17583. child.y = y;
  17584. child.markRedraw();
  17585. orient === 'horizontal' ? x = nextX + gap : y = nextY + gap;
  17586. });
  17587. }
  17588. /**
  17589. * VBox or HBox layouting
  17590. * @param {string} orient
  17591. * @param {module:zrender/graphic/Group} group
  17592. * @param {number} gap
  17593. * @param {number} [width=Infinity]
  17594. * @param {number} [height=Infinity]
  17595. */
  17596. var box = boxLayout;
  17597. /**
  17598. * VBox layouting
  17599. * @param {module:zrender/graphic/Group} group
  17600. * @param {number} gap
  17601. * @param {number} [width=Infinity]
  17602. * @param {number} [height=Infinity]
  17603. */
  17604. var vbox = curry(boxLayout, 'vertical');
  17605. /**
  17606. * HBox layouting
  17607. * @param {module:zrender/graphic/Group} group
  17608. * @param {number} gap
  17609. * @param {number} [width=Infinity]
  17610. * @param {number} [height=Infinity]
  17611. */
  17612. var hbox = curry(boxLayout, 'horizontal');
  17613. function getBoxLayoutParams(boxLayoutModel, ignoreParent) {
  17614. return {
  17615. left: boxLayoutModel.getShallow('left', ignoreParent),
  17616. top: boxLayoutModel.getShallow('top', ignoreParent),
  17617. right: boxLayoutModel.getShallow('right', ignoreParent),
  17618. bottom: boxLayoutModel.getShallow('bottom', ignoreParent),
  17619. width: boxLayoutModel.getShallow('width', ignoreParent),
  17620. height: boxLayoutModel.getShallow('height', ignoreParent)
  17621. };
  17622. }
  17623. function getViewRectAndCenterForCircleLayout(seriesModel, api) {
  17624. var layoutRef = createBoxLayoutReference(seriesModel, api, {
  17625. enableLayoutOnlyByCenter: true
  17626. });
  17627. var boxLayoutParams = seriesModel.getBoxLayoutParams();
  17628. var viewRect;
  17629. var center;
  17630. if (layoutRef.type === BoxLayoutReferenceType.point) {
  17631. center = layoutRef.refPoint;
  17632. // `viewRect` is required in `pie/labelLayout.ts`.
  17633. viewRect = getLayoutRect(boxLayoutParams, {
  17634. width: api.getWidth(),
  17635. height: api.getHeight()
  17636. });
  17637. } else {
  17638. // layoutRef.type === layout.BoxLayoutReferenceType.rect
  17639. var centerOption = seriesModel.get('center');
  17640. var centerOptionArr = isArray(centerOption) ? centerOption : [centerOption, centerOption];
  17641. viewRect = getLayoutRect(boxLayoutParams, layoutRef.refContainer);
  17642. center = layoutRef.boxCoordFrom === BoxCoordinateSystemCoordFrom.coord2 ? layoutRef.refPoint // option `series.center` has been used as coord.
  17643. : [parsePercent$1(centerOptionArr[0], viewRect.width) + viewRect.x, parsePercent$1(centerOptionArr[1], viewRect.height) + viewRect.y];
  17644. }
  17645. return {
  17646. viewRect: viewRect,
  17647. center: center
  17648. };
  17649. }
  17650. function getCircleLayout(seriesModel, api) {
  17651. // center can be string or number when coordinateSystem is specified
  17652. var _a = getViewRectAndCenterForCircleLayout(seriesModel, api),
  17653. viewRect = _a.viewRect,
  17654. center = _a.center;
  17655. var radius = seriesModel.get('radius');
  17656. if (!isArray(radius)) {
  17657. radius = [0, radius];
  17658. }
  17659. var width = parsePercent$1(viewRect.width, api.getWidth());
  17660. var height = parsePercent$1(viewRect.height, api.getHeight());
  17661. var size = Math.min(width, height);
  17662. var r0 = parsePercent$1(radius[0], size / 2);
  17663. var r = parsePercent$1(radius[1], size / 2);
  17664. return {
  17665. cx: center[0],
  17666. cy: center[1],
  17667. r0: r0,
  17668. r: r,
  17669. viewRect: viewRect
  17670. };
  17671. }
  17672. /**
  17673. * Parse position info.
  17674. */
  17675. function getLayoutRect(positionInfo, containerRect,
  17676. // This is the space from the `containerRect` to the returned bounding rect.
  17677. // Commonly used in option `legend.padding`, `timeline.padding`, `title.padding`,
  17678. // `visualMap.padding`, ...
  17679. // [NOTICE]:
  17680. // It's named `margin`, because it's the space that outside the bounding rect. But from
  17681. // the perspective of the the caller, it's commonly used as the `padding` of a component,
  17682. // because conventionally background color covers this space.
  17683. // [BEHAVIOR]:
  17684. // - If width/height is specified, `margin` does not effect them.
  17685. // - Otherwise, they are calculated based on the rect that `containerRect` shrinked by `margin`.
  17686. // - left/right/top/bottom are based on the rect that `containerRect` shrinked by `margin`.
  17687. margin) {
  17688. margin = normalizeCssArray$1(margin || 0);
  17689. var containerWidth = containerRect.width;
  17690. var containerHeight = containerRect.height;
  17691. var left = parsePercent$1(positionInfo.left, containerWidth);
  17692. var top = parsePercent$1(positionInfo.top, containerHeight);
  17693. var right = parsePercent$1(positionInfo.right, containerWidth);
  17694. var bottom = parsePercent$1(positionInfo.bottom, containerHeight);
  17695. var width = parsePercent$1(positionInfo.width, containerWidth);
  17696. var height = parsePercent$1(positionInfo.height, containerHeight);
  17697. var verticalMargin = margin[2] + margin[0];
  17698. var horizontalMargin = margin[1] + margin[3];
  17699. var aspect = positionInfo.aspect;
  17700. // If width is not specified, calculate width from left and right
  17701. if (isNaN(width)) {
  17702. width = containerWidth - right - horizontalMargin - left;
  17703. }
  17704. if (isNaN(height)) {
  17705. height = containerHeight - bottom - verticalMargin - top;
  17706. }
  17707. if (aspect != null) {
  17708. // If width and height are not given
  17709. // 1. Graph should not exceeds the container
  17710. // 2. Aspect must be keeped
  17711. // 3. Graph should take the space as more as possible
  17712. // FIXME
  17713. // Margin is not considered, because there is no case that both
  17714. // using margin and aspect so far.
  17715. if (isNaN(width) && isNaN(height)) {
  17716. // PENDING: if only `left` or `right` is defined, perhaps it's more preferable to
  17717. // calculate size based on `containerWidth - left` or `containerWidth - left` here,
  17718. // but for backward compatibility we do not change it.
  17719. if (aspect > containerWidth / containerHeight) {
  17720. width = containerWidth * 0.8;
  17721. } else {
  17722. height = containerHeight * 0.8;
  17723. }
  17724. }
  17725. // Calculate width or height with given aspect
  17726. if (isNaN(width)) {
  17727. width = aspect * height;
  17728. }
  17729. if (isNaN(height)) {
  17730. height = width / aspect;
  17731. }
  17732. }
  17733. // If left is not specified, calculate left from right and width
  17734. if (isNaN(left)) {
  17735. left = containerWidth - right - width - horizontalMargin;
  17736. }
  17737. if (isNaN(top)) {
  17738. top = containerHeight - bottom - height - verticalMargin;
  17739. }
  17740. // Align left and top
  17741. switch (positionInfo.left || positionInfo.right) {
  17742. case 'center':
  17743. left = containerWidth / 2 - width / 2 - margin[3];
  17744. break;
  17745. case 'right':
  17746. left = containerWidth - width - horizontalMargin;
  17747. break;
  17748. }
  17749. switch (positionInfo.top || positionInfo.bottom) {
  17750. case 'middle':
  17751. case 'center':
  17752. top = containerHeight / 2 - height / 2 - margin[0];
  17753. break;
  17754. case 'bottom':
  17755. top = containerHeight - height - verticalMargin;
  17756. break;
  17757. }
  17758. // If something is wrong and left, top, width, height are calculated as NaN
  17759. left = left || 0;
  17760. top = top || 0;
  17761. if (isNaN(width)) {
  17762. // Width may be NaN if only one value is given except width
  17763. width = containerWidth - horizontalMargin - left - (right || 0);
  17764. }
  17765. if (isNaN(height)) {
  17766. // Height may be NaN if only one value is given except height
  17767. height = containerHeight - verticalMargin - top - (bottom || 0);
  17768. }
  17769. var rect = new BoundingRect((containerRect.x || 0) + left + margin[3], (containerRect.y || 0) + top + margin[0], width, height);
  17770. rect.margin = margin;
  17771. return rect;
  17772. }
  17773. /**
  17774. * PENDING:
  17775. * when preserveAspect: 'cover' and aspect is near Infinity
  17776. * or when preserveAspect: 'contain' and aspect is near 0,
  17777. * the result width or height is near Inifity. It's logically correct,
  17778. * Therefore currently we do not handle it, until bad cases arise.
  17779. */
  17780. function applyPreserveAspect(component, layoutRect,
  17781. // That is, `width / height`.
  17782. // Assume `aspect` is positive.
  17783. aspect) {
  17784. var preserveAspect = component.getShallow('preserveAspect', true);
  17785. if (!preserveAspect) {
  17786. return layoutRect;
  17787. }
  17788. var actualAspect = layoutRect.width / layoutRect.height;
  17789. if (Math.abs(Math.atan(aspect) - Math.atan(actualAspect)) < 1e-9) {
  17790. return layoutRect;
  17791. }
  17792. var preserveAspectAlign = component.getShallow('preserveAspectAlign', true);
  17793. var preserveAspectVerticalAlign = component.getShallow('preserveAspectVerticalAlign', true);
  17794. var layoutOptInner = {
  17795. width: layoutRect.width,
  17796. height: layoutRect.height
  17797. };
  17798. var isCover = preserveAspect === 'cover';
  17799. if (actualAspect > aspect && !isCover || actualAspect < aspect && isCover) {
  17800. layoutOptInner.width = layoutRect.height * aspect;
  17801. preserveAspectAlign === 'left' ? layoutOptInner.left = 0 : preserveAspectAlign === 'right' ? layoutOptInner.right = 0 : layoutOptInner.left = 'center';
  17802. } else {
  17803. layoutOptInner.height = layoutRect.width / aspect;
  17804. preserveAspectVerticalAlign === 'top' ? layoutOptInner.top = 0 : preserveAspectVerticalAlign === 'bottom' ? layoutOptInner.bottom = 0 : layoutOptInner.top = 'middle';
  17805. }
  17806. return getLayoutRect(layoutOptInner, layoutRect);
  17807. }
  17808. var BoxLayoutReferenceType = {
  17809. rect: 1,
  17810. point: 2
  17811. };
  17812. /**
  17813. * Uniformly calculate layout reference (rect or center) based on either:
  17814. * - viewport:
  17815. * - Get `refContainer` as `{x: 0, y: 0, width: api.getWidth(), height: api.getHeight()}`
  17816. * - coordinate system, which can serve in several ways:
  17817. * - Use `dataToPoint` to get the `refPoint`, such as, in cartesian2d coord sys.
  17818. * - Use `dataToLayout` to get the `refContainer`, such as, in matrix coord sys.
  17819. */
  17820. function createBoxLayoutReference(model, api, opt) {
  17821. var refContainer;
  17822. var refPoint;
  17823. var layoutRefType;
  17824. var boxCoordSys = model.boxCoordinateSystem;
  17825. var boxCoordFrom;
  17826. if (boxCoordSys) {
  17827. var _a = getCoordForBoxCoordSys(model),
  17828. coord = _a.coord,
  17829. from = _a.from;
  17830. // Do not use `clamp` in `dataToLayout` and `dataToPoint`, because:
  17831. // 1. Should support overflow (such as, by dataZoom), where NaN should be in the result.
  17832. // 2. Be consistent with the way used in `series.data`
  17833. if (boxCoordSys.dataToLayout) {
  17834. layoutRefType = BoxLayoutReferenceType.rect;
  17835. boxCoordFrom = from;
  17836. var result = boxCoordSys.dataToLayout(coord);
  17837. refContainer = result.contentRect || result.rect;
  17838. } else if (opt && opt.enableLayoutOnlyByCenter && boxCoordSys.dataToPoint) {
  17839. layoutRefType = BoxLayoutReferenceType.point;
  17840. boxCoordFrom = from;
  17841. refPoint = boxCoordSys.dataToPoint(coord);
  17842. } else {
  17843. if ("development" !== 'production') {
  17844. error(model.type + "[" + model.componentIndex + "]" + (" layout based on " + boxCoordSys.type + " is not supported."));
  17845. }
  17846. }
  17847. }
  17848. if (layoutRefType == null) {
  17849. layoutRefType = BoxLayoutReferenceType.rect;
  17850. }
  17851. if (layoutRefType === BoxLayoutReferenceType.rect) {
  17852. if (!refContainer) {
  17853. refContainer = {
  17854. x: 0,
  17855. y: 0,
  17856. width: api.getWidth(),
  17857. height: api.getHeight()
  17858. };
  17859. }
  17860. refPoint = [refContainer.x + refContainer.width / 2, refContainer.y + refContainer.height / 2];
  17861. }
  17862. return {
  17863. type: layoutRefType,
  17864. refContainer: refContainer,
  17865. refPoint: refPoint,
  17866. boxCoordFrom: boxCoordFrom
  17867. };
  17868. }
  17869. /**
  17870. * Position a zr element in viewport
  17871. * Group position is specified by either
  17872. * {left, top}, {right, bottom}
  17873. * If all properties exists, right and bottom will be igonred.
  17874. *
  17875. * Logic:
  17876. * 1. Scale (against origin point in parent coord)
  17877. * 2. Rotate (against origin point in parent coord)
  17878. * 3. Translate (with el.position by this method)
  17879. * So this method only fixes the last step 'Translate', which does not affect
  17880. * scaling and rotating.
  17881. *
  17882. * If be called repeatedly with the same input el, the same result will be gotten.
  17883. *
  17884. * Return true if the layout happened.
  17885. *
  17886. * @param el Should have `getBoundingRect` method.
  17887. * @param positionInfo
  17888. * @param positionInfo.left
  17889. * @param positionInfo.top
  17890. * @param positionInfo.right
  17891. * @param positionInfo.bottom
  17892. * @param positionInfo.width Only for opt.boundingModel: 'raw'
  17893. * @param positionInfo.height Only for opt.boundingModel: 'raw'
  17894. * @param containerRect
  17895. * @param margin
  17896. * @param opt
  17897. * @param opt.hv Only horizontal or only vertical. Default to be [1, 1]
  17898. * @param opt.boundingMode
  17899. * Specify how to calculate boundingRect when locating.
  17900. * 'all': Position the boundingRect that is transformed and uioned
  17901. * both itself and its descendants.
  17902. * This mode simplies confine the elements in the bounding
  17903. * of their container (e.g., using 'right: 0').
  17904. * 'raw': Position the boundingRect that is not transformed and only itself.
  17905. * This mode is useful when you want a element can overflow its
  17906. * container. (Consider a rotated circle needs to be located in a corner.)
  17907. * In this mode positionInfo.width/height can only be number.
  17908. */
  17909. function positionElement(el, positionInfo, containerRect, margin, opt, out) {
  17910. var h = !opt || !opt.hv || opt.hv[0];
  17911. var v = !opt || !opt.hv || opt.hv[1];
  17912. var boundingMode = opt && opt.boundingMode || 'all';
  17913. out = out || el;
  17914. out.x = el.x;
  17915. out.y = el.y;
  17916. if (!h && !v) {
  17917. return false;
  17918. }
  17919. var rect;
  17920. if (boundingMode === 'raw') {
  17921. rect = el.type === 'group' ? new BoundingRect(0, 0, +positionInfo.width || 0, +positionInfo.height || 0) : el.getBoundingRect();
  17922. } else {
  17923. rect = el.getBoundingRect();
  17924. if (el.needLocalTransform()) {
  17925. var transform = el.getLocalTransform();
  17926. // Notice: raw rect may be inner object of el,
  17927. // which should not be modified.
  17928. rect = rect.clone();
  17929. rect.applyTransform(transform);
  17930. }
  17931. }
  17932. // The real width and height can not be specified but calculated by the given el.
  17933. var layoutRect = getLayoutRect(defaults({
  17934. width: rect.width,
  17935. height: rect.height
  17936. }, positionInfo), containerRect, margin);
  17937. // Because 'tranlate' is the last step in transform
  17938. // (see zrender/core/Transformable#getLocalTransform),
  17939. // we can just only modify el.position to get final result.
  17940. var dx = h ? layoutRect.x - rect.x : 0;
  17941. var dy = v ? layoutRect.y - rect.y : 0;
  17942. if (boundingMode === 'raw') {
  17943. out.x = dx;
  17944. out.y = dy;
  17945. } else {
  17946. out.x += dx;
  17947. out.y += dy;
  17948. }
  17949. if (out === el) {
  17950. el.markRedraw();
  17951. }
  17952. return true;
  17953. }
  17954. /**
  17955. * @param option Contains some of the properties in HV_NAMES.
  17956. * @param hvIdx 0: horizontal; 1: vertical.
  17957. */
  17958. function sizeCalculable(option, hvIdx) {
  17959. return option[HV_NAMES[hvIdx][0]] != null || option[HV_NAMES[hvIdx][1]] != null && option[HV_NAMES[hvIdx][2]] != null;
  17960. }
  17961. function fetchLayoutMode(ins) {
  17962. var layoutMode = ins.layoutMode || ins.constructor.layoutMode;
  17963. return isObject(layoutMode) ? layoutMode : layoutMode ? {
  17964. type: layoutMode
  17965. } : null;
  17966. }
  17967. /**
  17968. * Consider Case:
  17969. * When default option has {left: 0, width: 100}, and we set {right: 0}
  17970. * through setOption or media query, using normal zrUtil.merge will cause
  17971. * {right: 0} does not take effect.
  17972. *
  17973. * @example
  17974. * ComponentModel.extend({
  17975. * init: function () {
  17976. * ...
  17977. * let inputPositionParams = layout.getLayoutParams(option);
  17978. * this.mergeOption(inputPositionParams);
  17979. * },
  17980. * mergeOption: function (newOption) {
  17981. * newOption && zrUtil.merge(thisOption, newOption, true);
  17982. * layout.mergeLayoutParam(thisOption, newOption);
  17983. * }
  17984. * });
  17985. *
  17986. * @param targetOption
  17987. * @param newOption
  17988. * @param opt
  17989. */
  17990. function mergeLayoutParam(targetOption, newOption, opt) {
  17991. var ignoreSize = opt && opt.ignoreSize;
  17992. !isArray(ignoreSize) && (ignoreSize = [ignoreSize, ignoreSize]);
  17993. var hResult = merge(HV_NAMES[0], 0);
  17994. var vResult = merge(HV_NAMES[1], 1);
  17995. copy(HV_NAMES[0], targetOption, hResult);
  17996. copy(HV_NAMES[1], targetOption, vResult);
  17997. function merge(names, hvIdx) {
  17998. var newParams = {};
  17999. var newValueCount = 0;
  18000. var merged = {};
  18001. var mergedValueCount = 0;
  18002. var enoughParamNumber = 2;
  18003. each$1(names, function (name) {
  18004. merged[name] = targetOption[name];
  18005. });
  18006. each$1(names, function (name) {
  18007. // Consider case: newOption.width is null, which is
  18008. // set by user for removing width setting.
  18009. hasOwn(newOption, name) && (newParams[name] = merged[name] = newOption[name]);
  18010. hasValue(newParams, name) && newValueCount++;
  18011. hasValue(merged, name) && mergedValueCount++;
  18012. });
  18013. if (ignoreSize[hvIdx]) {
  18014. // Only one of left/right is premitted to exist.
  18015. if (hasValue(newOption, names[1])) {
  18016. merged[names[2]] = null;
  18017. } else if (hasValue(newOption, names[2])) {
  18018. merged[names[1]] = null;
  18019. }
  18020. return merged;
  18021. }
  18022. // Case: newOption: {width: ..., right: ...},
  18023. // or targetOption: {right: ...} and newOption: {width: ...},
  18024. // There is no conflict when merged only has params count
  18025. // little than enoughParamNumber.
  18026. if (mergedValueCount === enoughParamNumber || !newValueCount) {
  18027. return merged;
  18028. }
  18029. // Case: newOption: {width: ..., right: ...},
  18030. // Than we can make sure user only want those two, and ignore
  18031. // all origin params in targetOption.
  18032. else if (newValueCount >= enoughParamNumber) {
  18033. return newParams;
  18034. } else {
  18035. // Chose another param from targetOption by priority.
  18036. for (var i = 0; i < names.length; i++) {
  18037. var name_1 = names[i];
  18038. if (!hasOwn(newParams, name_1) && hasOwn(targetOption, name_1)) {
  18039. newParams[name_1] = targetOption[name_1];
  18040. break;
  18041. }
  18042. }
  18043. return newParams;
  18044. }
  18045. }
  18046. function hasValue(obj, name) {
  18047. return obj[name] != null && obj[name] !== 'auto';
  18048. }
  18049. function copy(names, target, source) {
  18050. each$1(names, function (name) {
  18051. target[name] = source[name];
  18052. });
  18053. }
  18054. }
  18055. /**
  18056. * Retrieve 'left', 'right', 'top', 'bottom', 'width', 'height' from object.
  18057. */
  18058. function getLayoutParams(source) {
  18059. return copyLayoutParams({}, source);
  18060. }
  18061. /**
  18062. * Retrieve 'left', 'right', 'top', 'bottom', 'width', 'height' from object.
  18063. * @param {Object} source
  18064. * @return {Object} Result contains those props.
  18065. */
  18066. function copyLayoutParams(target, source) {
  18067. source && target && each$1(LOCATION_PARAMS, function (name) {
  18068. hasOwn(source, name) && (target[name] = source[name]);
  18069. });
  18070. return target;
  18071. }
  18072. var inner = makeInner();
  18073. var ComponentModel = /** @class */function (_super) {
  18074. __extends(ComponentModel, _super);
  18075. function ComponentModel(option, parentModel, ecModel) {
  18076. var _this = _super.call(this, option, parentModel, ecModel) || this;
  18077. _this.uid = getUID('ec_cpt_model');
  18078. return _this;
  18079. }
  18080. ComponentModel.prototype.init = function (option, parentModel, ecModel) {
  18081. this.mergeDefaultAndTheme(option, ecModel);
  18082. };
  18083. ComponentModel.prototype.mergeDefaultAndTheme = function (option, ecModel) {
  18084. var layoutMode = fetchLayoutMode(this);
  18085. var inputPositionParams = layoutMode ? getLayoutParams(option) : {};
  18086. var themeModel = ecModel.getTheme();
  18087. merge(option, themeModel.get(this.mainType));
  18088. merge(option, this.getDefaultOption());
  18089. if (layoutMode) {
  18090. mergeLayoutParam(option, inputPositionParams, layoutMode);
  18091. }
  18092. };
  18093. ComponentModel.prototype.mergeOption = function (option, ecModel) {
  18094. merge(this.option, option, true);
  18095. var layoutMode = fetchLayoutMode(this);
  18096. if (layoutMode) {
  18097. mergeLayoutParam(this.option, option, layoutMode);
  18098. }
  18099. };
  18100. /**
  18101. * Called immediately after `init` or `mergeOption` of this instance called.
  18102. */
  18103. ComponentModel.prototype.optionUpdated = function (newCptOption, isInit) {};
  18104. /**
  18105. * [How to declare defaultOption]:
  18106. *
  18107. * (A) If using class declaration in typescript (since echarts 5):
  18108. * ```ts
  18109. * import {ComponentOption} from '../model/option.js';
  18110. * export interface XxxOption extends ComponentOption {
  18111. * aaa: number
  18112. * }
  18113. * export class XxxModel extends Component {
  18114. * static type = 'xxx';
  18115. * static defaultOption: XxxOption = {
  18116. * aaa: 123
  18117. * }
  18118. * }
  18119. * Component.registerClass(XxxModel);
  18120. * ```
  18121. * ```ts
  18122. * import {inheritDefaultOption} from '../util/component.js';
  18123. * import {XxxModel, XxxOption} from './XxxModel.js';
  18124. * export interface XxxSubOption extends XxxOption {
  18125. * bbb: number
  18126. * }
  18127. * class XxxSubModel extends XxxModel {
  18128. * static defaultOption: XxxSubOption = inheritDefaultOption(XxxModel.defaultOption, {
  18129. * bbb: 456
  18130. * })
  18131. * fn() {
  18132. * let opt = this.getDefaultOption();
  18133. * // opt is {aaa: 123, bbb: 456}
  18134. * }
  18135. * }
  18136. * ```
  18137. *
  18138. * (B) If using class extend (previous approach in echarts 3 & 4):
  18139. * ```js
  18140. * let XxxComponent = Component.extend({
  18141. * defaultOption: {
  18142. * xx: 123
  18143. * }
  18144. * })
  18145. * ```
  18146. * ```js
  18147. * let XxxSubComponent = XxxComponent.extend({
  18148. * defaultOption: {
  18149. * yy: 456
  18150. * },
  18151. * fn: function () {
  18152. * let opt = this.getDefaultOption();
  18153. * // opt is {xx: 123, yy: 456}
  18154. * }
  18155. * })
  18156. * ```
  18157. */
  18158. ComponentModel.prototype.getDefaultOption = function () {
  18159. var ctor = this.constructor;
  18160. if (!isExtendedClass(ctor)) {
  18161. // When using ES class declaration, defaultOption must be declared as static.
  18162. // And manually inherit the defaultOption from its parent class if needed, such as,
  18163. // ```ts
  18164. // static defaultOption = inheritDefaultOption(ParentModel.defaultOption, {...});
  18165. // ```
  18166. return ctor.defaultOption;
  18167. }
  18168. // FIXME: remove this approach?
  18169. // Legacy: auto merge defaultOption from ancestor classes if using ParentClass.extend(subProto)
  18170. var fields = inner(this);
  18171. if (!fields.defaultOption) {
  18172. var optList = [];
  18173. var clz = ctor;
  18174. while (clz) {
  18175. var opt = clz.prototype.defaultOption;
  18176. opt && optList.push(opt);
  18177. clz = clz.superClass;
  18178. }
  18179. var defaultOption = {};
  18180. for (var i = optList.length - 1; i >= 0; i--) {
  18181. defaultOption = merge(defaultOption, optList[i], true);
  18182. }
  18183. fields.defaultOption = defaultOption;
  18184. }
  18185. return fields.defaultOption;
  18186. };
  18187. /**
  18188. * Notice: always force to input param `useDefault` in case that forget to consider it.
  18189. * The same behavior as `modelUtil.parseFinder`.
  18190. *
  18191. * @param useDefault In many cases like series refer axis and axis refer grid,
  18192. * If axis index / axis id not specified, use the first target as default.
  18193. * In other cases like dataZoom refer axis, if not specified, measn no refer.
  18194. */
  18195. ComponentModel.prototype.getReferringComponents = function (mainType, opt) {
  18196. var indexKey = mainType + 'Index';
  18197. var idKey = mainType + 'Id';
  18198. return queryReferringComponents(this.ecModel, mainType, {
  18199. index: this.get(indexKey, true),
  18200. id: this.get(idKey, true)
  18201. }, opt);
  18202. };
  18203. ComponentModel.prototype.getBoxLayoutParams = function () {
  18204. // Consider itself having box layout configs.
  18205. // For backward compatibility, by default do not `ignoreParent`.
  18206. return getBoxLayoutParams(this, false);
  18207. };
  18208. /**
  18209. * Get key for zlevel.
  18210. * If developers don't configure zlevel. We will assign zlevel to series based on the key.
  18211. * For example, lines with trail effect and progressive series will in an individual zlevel.
  18212. */
  18213. ComponentModel.prototype.getZLevelKey = function () {
  18214. return '';
  18215. };
  18216. ComponentModel.prototype.setZLevel = function (zlevel) {
  18217. this.option.zlevel = zlevel;
  18218. };
  18219. ComponentModel.protoInitialize = function () {
  18220. var proto = ComponentModel.prototype;
  18221. proto.type = 'component';
  18222. proto.id = '';
  18223. proto.name = '';
  18224. proto.mainType = '';
  18225. proto.subType = '';
  18226. proto.componentIndex = 0;
  18227. }();
  18228. return ComponentModel;
  18229. }(Model);
  18230. mountExtend(ComponentModel, Model);
  18231. enableClassManagement(ComponentModel);
  18232. enableSubTypeDefaulter(ComponentModel);
  18233. enableTopologicalTravel(ComponentModel, getDependencies);
  18234. function getDependencies(componentType) {
  18235. var deps = [];
  18236. each(ComponentModel.getClassesByMainType(componentType), function (clz) {
  18237. deps = deps.concat(clz.dependencies || clz.prototype.dependencies || []);
  18238. });
  18239. // Ensure main type.
  18240. deps = map(deps, function (type) {
  18241. return parseClassType(type).main;
  18242. });
  18243. // Hack dataset for convenience.
  18244. if (componentType !== 'dataset' && indexOf(deps, 'dataset') <= 0) {
  18245. deps.unshift('dataset');
  18246. }
  18247. return deps;
  18248. }
  18249. var tokens = {
  18250. color: {},
  18251. darkColor: {},
  18252. size: {}
  18253. };
  18254. var color$1 = tokens.color = {
  18255. theme: ['#5070dd', '#b6d634', '#505372', '#ff994d', '#0ca8df', '#ffd10a', '#fb628b', '#785db0', '#3fbe95'],
  18256. neutral00: '#fff',
  18257. neutral05: '#f4f7fd',
  18258. neutral10: '#e8ebf0',
  18259. neutral15: '#dbdee4',
  18260. neutral20: '#cfd2d7',
  18261. neutral25: '#c3c5cb',
  18262. neutral30: '#b7b9be',
  18263. neutral35: '#aaacb2',
  18264. neutral40: '#9ea0a5',
  18265. neutral45: '#929399',
  18266. neutral50: '#86878c',
  18267. neutral55: '#797b7f',
  18268. neutral60: '#6d6e73',
  18269. neutral65: '#616266',
  18270. neutral70: '#54555a',
  18271. neutral75: '#48494d',
  18272. neutral80: '#3c3c41',
  18273. neutral85: '#303034',
  18274. neutral90: '#232328',
  18275. neutral95: '#17171b',
  18276. neutral99: '#000',
  18277. accent05: '#eff1f9',
  18278. accent10: '#e0e4f2',
  18279. accent15: '#d0d6ec',
  18280. accent20: '#c0c9e6',
  18281. accent25: '#b1bbdf',
  18282. accent30: '#a1aed9',
  18283. accent35: '#91a0d3',
  18284. accent40: '#8292cc',
  18285. accent45: '#7285c6',
  18286. accent50: '#6578ba',
  18287. accent55: '#5c6da9',
  18288. accent60: '#536298',
  18289. accent65: '#4a5787',
  18290. accent70: '#404c76',
  18291. accent75: '#374165',
  18292. accent80: '#2e3654',
  18293. accent85: '#252b43',
  18294. accent90: '#1b2032',
  18295. accent95: '#121521',
  18296. transparent: 'rgba(0,0,0,0)',
  18297. highlight: 'rgba(255,231,130,0.8)'
  18298. };
  18299. extend(color$1, {
  18300. primary: color$1.neutral80,
  18301. secondary: color$1.neutral70,
  18302. tertiary: color$1.neutral60,
  18303. quaternary: color$1.neutral50,
  18304. disabled: color$1.neutral20,
  18305. border: color$1.neutral30,
  18306. borderTint: color$1.neutral20,
  18307. borderShade: color$1.neutral40,
  18308. background: color$1.neutral05,
  18309. backgroundTint: 'rgba(234,237,245,0.5)',
  18310. backgroundTransparent: 'rgba(255,255,255,0)',
  18311. backgroundShade: color$1.neutral10,
  18312. shadow: 'rgba(0,0,0,0.2)',
  18313. shadowTint: 'rgba(129,130,136,0.2)',
  18314. axisLine: color$1.neutral70,
  18315. axisLineTint: color$1.neutral40,
  18316. axisTick: color$1.neutral70,
  18317. axisTickMinor: color$1.neutral60,
  18318. axisLabel: color$1.neutral70,
  18319. axisSplitLine: color$1.neutral15,
  18320. axisMinorSplitLine: color$1.neutral05
  18321. });
  18322. for (var key in color$1) {
  18323. if (color$1.hasOwnProperty(key)) {
  18324. var hex = color$1[key];
  18325. if (key === 'theme') {
  18326. // Don't modify theme colors.
  18327. tokens.darkColor.theme = color$1.theme.slice();
  18328. } else if (key === 'highlight') {
  18329. tokens.darkColor.highlight = 'rgba(255,231,130,0.4)';
  18330. } else if (key.indexOf('accent') === 0) {
  18331. // Desaturate and lighten accent colors.
  18332. tokens.darkColor[key] = modifyHSL(hex, null, function (s) {
  18333. return s * 0.5;
  18334. }, function (l) {
  18335. return Math.min(1, 1.3 - l);
  18336. });
  18337. } else {
  18338. tokens.darkColor[key] = modifyHSL(hex, null, function (s) {
  18339. return s * 0.9;
  18340. }, function (l) {
  18341. return 1 - Math.pow(l, 1.5);
  18342. });
  18343. }
  18344. }
  18345. }
  18346. tokens.size = {
  18347. xxs: 2,
  18348. xs: 5,
  18349. s: 10,
  18350. m: 15,
  18351. l: 20,
  18352. xl: 30,
  18353. xxl: 40,
  18354. xxxl: 50
  18355. };
  18356. var platform = '';
  18357. // Navigator not exists in node
  18358. if (typeof navigator !== 'undefined') {
  18359. /* global navigator */
  18360. platform = navigator.platform || '';
  18361. }
  18362. var decalColor = 'rgba(0, 0, 0, 0.2)';
  18363. var themeColor = tokens.color.theme[0];
  18364. var lightThemeColor = modifyHSL(themeColor, null, null, 0.9);
  18365. var globalDefault = {
  18366. darkMode: 'auto',
  18367. // backgroundColor: 'rgba(0,0,0,0)',
  18368. colorBy: 'series',
  18369. color: tokens.color.theme,
  18370. gradientColor: [lightThemeColor, themeColor],
  18371. aria: {
  18372. decal: {
  18373. decals: [{
  18374. color: decalColor,
  18375. dashArrayX: [1, 0],
  18376. dashArrayY: [2, 5],
  18377. symbolSize: 1,
  18378. rotation: Math.PI / 6
  18379. }, {
  18380. color: decalColor,
  18381. symbol: 'circle',
  18382. dashArrayX: [[8, 8], [0, 8, 8, 0]],
  18383. dashArrayY: [6, 0],
  18384. symbolSize: 0.8
  18385. }, {
  18386. color: decalColor,
  18387. dashArrayX: [1, 0],
  18388. dashArrayY: [4, 3],
  18389. rotation: -Math.PI / 4
  18390. }, {
  18391. color: decalColor,
  18392. dashArrayX: [[6, 6], [0, 6, 6, 0]],
  18393. dashArrayY: [6, 0]
  18394. }, {
  18395. color: decalColor,
  18396. dashArrayX: [[1, 0], [1, 6]],
  18397. dashArrayY: [1, 0, 6, 0],
  18398. rotation: Math.PI / 4
  18399. }, {
  18400. color: decalColor,
  18401. symbol: 'triangle',
  18402. dashArrayX: [[9, 9], [0, 9, 9, 0]],
  18403. dashArrayY: [7, 2],
  18404. symbolSize: 0.75
  18405. }]
  18406. }
  18407. },
  18408. // If xAxis and yAxis declared, grid is created by default.
  18409. // grid: {},
  18410. textStyle: {
  18411. // color: '#000',
  18412. // decoration: 'none',
  18413. // PENDING
  18414. fontFamily: platform.match(/^Win/) ? 'Microsoft YaHei' : 'sans-serif',
  18415. // fontFamily: 'Arial, Verdana, sans-serif',
  18416. fontSize: 12,
  18417. fontStyle: 'normal',
  18418. fontWeight: 'normal'
  18419. },
  18420. // http://blogs.adobe.com/webplatform/2014/02/24/using-blend-modes-in-html-canvas/
  18421. // https://developer.mozilla.org/en-US/docs/Web/API/CanvasRenderingContext2D/globalCompositeOperation
  18422. // Default is source-over
  18423. blendMode: null,
  18424. stateAnimation: {
  18425. duration: 300,
  18426. easing: 'cubicOut'
  18427. },
  18428. animation: 'auto',
  18429. animationDuration: 1000,
  18430. animationDurationUpdate: 500,
  18431. animationEasing: 'cubicInOut',
  18432. animationEasingUpdate: 'cubicInOut',
  18433. animationThreshold: 2000,
  18434. // Configuration for progressive/incremental rendering
  18435. progressiveThreshold: 3000,
  18436. progressive: 400,
  18437. // Threshold of if use single hover layer to optimize.
  18438. // It is recommended that `hoverLayerThreshold` is equivalent to or less than
  18439. // `progressiveThreshold`, otherwise hover will cause restart of progressive,
  18440. // which is unexpected.
  18441. // see example <echarts/test/heatmap-large.html>.
  18442. hoverLayerThreshold: 3000,
  18443. // See: module:echarts/scale/Time
  18444. useUTC: false
  18445. };
  18446. var VISUAL_DIMENSIONS = createHashMap(['tooltip', 'label', 'itemName', 'itemId', 'itemGroupId', 'itemChildGroupId', 'seriesName']);
  18447. var SOURCE_FORMAT_ORIGINAL = 'original';
  18448. var SOURCE_FORMAT_ARRAY_ROWS = 'arrayRows';
  18449. var SOURCE_FORMAT_OBJECT_ROWS = 'objectRows';
  18450. var SOURCE_FORMAT_KEYED_COLUMNS = 'keyedColumns';
  18451. var SOURCE_FORMAT_TYPED_ARRAY = 'typedArray';
  18452. var SOURCE_FORMAT_UNKNOWN = 'unknown';
  18453. var SERIES_LAYOUT_BY_COLUMN = 'column';
  18454. var SERIES_LAYOUT_BY_ROW = 'row';
  18455. // The result of `guessOrdinal`.
  18456. var BE_ORDINAL = {
  18457. Must: 1,
  18458. Might: 2,
  18459. Not: 3 // Other cases
  18460. };
  18461. var innerGlobalModel = makeInner();
  18462. /**
  18463. * MUST be called before mergeOption of all series.
  18464. */
  18465. function resetSourceDefaulter(ecModel) {
  18466. // `datasetMap` is used to make default encode.
  18467. innerGlobalModel(ecModel).datasetMap = createHashMap();
  18468. }
  18469. /**
  18470. * [The strategy of the arrengment of data dimensions for dataset]:
  18471. * "value way": all axes are non-category axes. So series one by one take
  18472. * several (the number is coordSysDims.length) dimensions from dataset.
  18473. * The result of data arrengment of data dimensions like:
  18474. * | ser0_x | ser0_y | ser1_x | ser1_y | ser2_x | ser2_y |
  18475. * "category way": at least one axis is category axis. So the the first data
  18476. * dimension is always mapped to the first category axis and shared by
  18477. * all of the series. The other data dimensions are taken by series like
  18478. * "value way" does.
  18479. * The result of data arrengment of data dimensions like:
  18480. * | ser_shared_x | ser0_y | ser1_y | ser2_y |
  18481. *
  18482. * @return encode Never be `null/undefined`.
  18483. */
  18484. function makeSeriesEncodeForAxisCoordSys(coordDimensions, seriesModel, source) {
  18485. var encode = {};
  18486. var datasetModel = querySeriesUpstreamDatasetModel(seriesModel);
  18487. // Currently only make default when using dataset, util more reqirements occur.
  18488. if (!datasetModel || !coordDimensions) {
  18489. return encode;
  18490. }
  18491. var encodeItemName = [];
  18492. var encodeSeriesName = [];
  18493. var ecModel = seriesModel.ecModel;
  18494. var datasetMap = innerGlobalModel(ecModel).datasetMap;
  18495. var key = datasetModel.uid + '_' + source.seriesLayoutBy;
  18496. var baseCategoryDimIndex;
  18497. var categoryWayValueDimStart;
  18498. coordDimensions = coordDimensions.slice();
  18499. each(coordDimensions, function (coordDimInfoLoose, coordDimIdx) {
  18500. var coordDimInfo = isObject(coordDimInfoLoose) ? coordDimInfoLoose : coordDimensions[coordDimIdx] = {
  18501. name: coordDimInfoLoose
  18502. };
  18503. if (coordDimInfo.type === 'ordinal' && baseCategoryDimIndex == null) {
  18504. baseCategoryDimIndex = coordDimIdx;
  18505. categoryWayValueDimStart = getDataDimCountOnCoordDim(coordDimInfo);
  18506. }
  18507. encode[coordDimInfo.name] = [];
  18508. });
  18509. var datasetRecord = datasetMap.get(key) || datasetMap.set(key, {
  18510. categoryWayDim: categoryWayValueDimStart,
  18511. valueWayDim: 0
  18512. });
  18513. // TODO
  18514. // Auto detect first time axis and do arrangement.
  18515. each(coordDimensions, function (coordDimInfo, coordDimIdx) {
  18516. var coordDimName = coordDimInfo.name;
  18517. var count = getDataDimCountOnCoordDim(coordDimInfo);
  18518. // In value way.
  18519. if (baseCategoryDimIndex == null) {
  18520. var start = datasetRecord.valueWayDim;
  18521. pushDim(encode[coordDimName], start, count);
  18522. pushDim(encodeSeriesName, start, count);
  18523. datasetRecord.valueWayDim += count;
  18524. // ??? TODO give a better default series name rule?
  18525. // especially when encode x y specified.
  18526. // consider: when multiple series share one dimension
  18527. // category axis, series name should better use
  18528. // the other dimension name. On the other hand, use
  18529. // both dimensions name.
  18530. }
  18531. // In category way, the first category axis.
  18532. else if (baseCategoryDimIndex === coordDimIdx) {
  18533. pushDim(encode[coordDimName], 0, count);
  18534. pushDim(encodeItemName, 0, count);
  18535. }
  18536. // In category way, the other axis.
  18537. else {
  18538. var start = datasetRecord.categoryWayDim;
  18539. pushDim(encode[coordDimName], start, count);
  18540. pushDim(encodeSeriesName, start, count);
  18541. datasetRecord.categoryWayDim += count;
  18542. }
  18543. });
  18544. function pushDim(dimIdxArr, idxFrom, idxCount) {
  18545. for (var i = 0; i < idxCount; i++) {
  18546. dimIdxArr.push(idxFrom + i);
  18547. }
  18548. }
  18549. function getDataDimCountOnCoordDim(coordDimInfo) {
  18550. var dimsDef = coordDimInfo.dimsDef;
  18551. return dimsDef ? dimsDef.length : 1;
  18552. }
  18553. encodeItemName.length && (encode.itemName = encodeItemName);
  18554. encodeSeriesName.length && (encode.seriesName = encodeSeriesName);
  18555. return encode;
  18556. }
  18557. /**
  18558. * Work for data like [{name: ..., value: ...}, ...].
  18559. *
  18560. * @return encode Never be `null/undefined`.
  18561. */
  18562. function makeSeriesEncodeForNameBased(seriesModel, source, dimCount) {
  18563. var encode = {};
  18564. var datasetModel = querySeriesUpstreamDatasetModel(seriesModel);
  18565. // Currently only make default when using dataset, util more reqirements occur.
  18566. if (!datasetModel) {
  18567. return encode;
  18568. }
  18569. var sourceFormat = source.sourceFormat;
  18570. var dimensionsDefine = source.dimensionsDefine;
  18571. var potentialNameDimIndex;
  18572. if (sourceFormat === SOURCE_FORMAT_OBJECT_ROWS || sourceFormat === SOURCE_FORMAT_KEYED_COLUMNS) {
  18573. each(dimensionsDefine, function (dim, idx) {
  18574. if ((isObject(dim) ? dim.name : dim) === 'name') {
  18575. potentialNameDimIndex = idx;
  18576. }
  18577. });
  18578. }
  18579. var idxResult = function () {
  18580. var idxRes0 = {};
  18581. var idxRes1 = {};
  18582. var guessRecords = [];
  18583. // 5 is an experience value.
  18584. for (var i = 0, len = Math.min(5, dimCount); i < len; i++) {
  18585. var guessResult = doGuessOrdinal(source.data, sourceFormat, source.seriesLayoutBy, dimensionsDefine, source.startIndex, i);
  18586. guessRecords.push(guessResult);
  18587. var isPureNumber = guessResult === BE_ORDINAL.Not;
  18588. // [Strategy of idxRes0]: find the first BE_ORDINAL.Not as the value dim,
  18589. // and then find a name dim with the priority:
  18590. // "BE_ORDINAL.Might|BE_ORDINAL.Must" > "other dim" > "the value dim itself".
  18591. if (isPureNumber && idxRes0.v == null && i !== potentialNameDimIndex) {
  18592. idxRes0.v = i;
  18593. }
  18594. if (idxRes0.n == null || idxRes0.n === idxRes0.v || !isPureNumber && guessRecords[idxRes0.n] === BE_ORDINAL.Not) {
  18595. idxRes0.n = i;
  18596. }
  18597. if (fulfilled(idxRes0) && guessRecords[idxRes0.n] !== BE_ORDINAL.Not) {
  18598. return idxRes0;
  18599. }
  18600. // [Strategy of idxRes1]: if idxRes0 not satisfied (that is, no BE_ORDINAL.Not),
  18601. // find the first BE_ORDINAL.Might as the value dim,
  18602. // and then find a name dim with the priority:
  18603. // "other dim" > "the value dim itself".
  18604. // That is for backward compat: number-like (e.g., `'3'`, `'55'`) can be
  18605. // treated as number.
  18606. if (!isPureNumber) {
  18607. if (guessResult === BE_ORDINAL.Might && idxRes1.v == null && i !== potentialNameDimIndex) {
  18608. idxRes1.v = i;
  18609. }
  18610. if (idxRes1.n == null || idxRes1.n === idxRes1.v) {
  18611. idxRes1.n = i;
  18612. }
  18613. }
  18614. }
  18615. function fulfilled(idxResult) {
  18616. return idxResult.v != null && idxResult.n != null;
  18617. }
  18618. return fulfilled(idxRes0) ? idxRes0 : fulfilled(idxRes1) ? idxRes1 : null;
  18619. }();
  18620. if (idxResult) {
  18621. encode.value = [idxResult.v];
  18622. // `potentialNameDimIndex` has highest priority.
  18623. var nameDimIndex = potentialNameDimIndex != null ? potentialNameDimIndex : idxResult.n;
  18624. // By default, label uses itemName in charts.
  18625. // So we don't set encodeLabel here.
  18626. encode.itemName = [nameDimIndex];
  18627. encode.seriesName = [nameDimIndex];
  18628. }
  18629. return encode;
  18630. }
  18631. /**
  18632. * @return If return null/undefined, indicate that should not use datasetModel.
  18633. */
  18634. function querySeriesUpstreamDatasetModel(seriesModel) {
  18635. // Caution: consider the scenario:
  18636. // A dataset is declared and a series is not expected to use the dataset,
  18637. // and at the beginning `setOption({series: { noData })` (just prepare other
  18638. // option but no data), then `setOption({series: {data: [...]}); In this case,
  18639. // the user should set an empty array to avoid that dataset is used by default.
  18640. var thisData = seriesModel.get('data', true);
  18641. if (!thisData) {
  18642. return queryReferringComponents(seriesModel.ecModel, 'dataset', {
  18643. index: seriesModel.get('datasetIndex', true),
  18644. id: seriesModel.get('datasetId', true)
  18645. }, SINGLE_REFERRING).models[0];
  18646. }
  18647. }
  18648. /**
  18649. * @return Always return an array event empty.
  18650. */
  18651. function queryDatasetUpstreamDatasetModels(datasetModel) {
  18652. // Only these attributes declared, we by default reference to `datasetIndex: 0`.
  18653. // Otherwise, no reference.
  18654. if (!datasetModel.get('transform', true) && !datasetModel.get('fromTransformResult', true)) {
  18655. return [];
  18656. }
  18657. return queryReferringComponents(datasetModel.ecModel, 'dataset', {
  18658. index: datasetModel.get('fromDatasetIndex', true),
  18659. id: datasetModel.get('fromDatasetId', true)
  18660. }, SINGLE_REFERRING).models;
  18661. }
  18662. /**
  18663. * The rule should not be complex, otherwise user might not
  18664. * be able to known where the data is wrong.
  18665. * The code is ugly, but how to make it neat?
  18666. */
  18667. function guessOrdinal(source, dimIndex) {
  18668. return doGuessOrdinal(source.data, source.sourceFormat, source.seriesLayoutBy, source.dimensionsDefine, source.startIndex, dimIndex);
  18669. }
  18670. // dimIndex may be overflow source data.
  18671. // return {BE_ORDINAL}
  18672. function doGuessOrdinal(data, sourceFormat, seriesLayoutBy, dimensionsDefine, startIndex, dimIndex) {
  18673. var result;
  18674. // Experience value.
  18675. var maxLoop = 5;
  18676. if (isTypedArray(data)) {
  18677. return BE_ORDINAL.Not;
  18678. }
  18679. // When sourceType is 'objectRows' or 'keyedColumns', dimensionsDefine
  18680. // always exists in source.
  18681. var dimName;
  18682. var dimType;
  18683. if (dimensionsDefine) {
  18684. var dimDefItem = dimensionsDefine[dimIndex];
  18685. if (isObject(dimDefItem)) {
  18686. dimName = dimDefItem.name;
  18687. dimType = dimDefItem.type;
  18688. } else if (isString(dimDefItem)) {
  18689. dimName = dimDefItem;
  18690. }
  18691. }
  18692. if (dimType != null) {
  18693. return dimType === 'ordinal' ? BE_ORDINAL.Must : BE_ORDINAL.Not;
  18694. }
  18695. if (sourceFormat === SOURCE_FORMAT_ARRAY_ROWS) {
  18696. var dataArrayRows = data;
  18697. if (seriesLayoutBy === SERIES_LAYOUT_BY_ROW) {
  18698. var sample = dataArrayRows[dimIndex];
  18699. for (var i = 0; i < (sample || []).length && i < maxLoop; i++) {
  18700. if ((result = detectValue(sample[startIndex + i])) != null) {
  18701. return result;
  18702. }
  18703. }
  18704. } else {
  18705. for (var i = 0; i < dataArrayRows.length && i < maxLoop; i++) {
  18706. var row = dataArrayRows[startIndex + i];
  18707. if (row && (result = detectValue(row[dimIndex])) != null) {
  18708. return result;
  18709. }
  18710. }
  18711. }
  18712. } else if (sourceFormat === SOURCE_FORMAT_OBJECT_ROWS) {
  18713. var dataObjectRows = data;
  18714. if (!dimName) {
  18715. return BE_ORDINAL.Not;
  18716. }
  18717. for (var i = 0; i < dataObjectRows.length && i < maxLoop; i++) {
  18718. var item = dataObjectRows[i];
  18719. if (item && (result = detectValue(item[dimName])) != null) {
  18720. return result;
  18721. }
  18722. }
  18723. } else if (sourceFormat === SOURCE_FORMAT_KEYED_COLUMNS) {
  18724. var dataKeyedColumns = data;
  18725. if (!dimName) {
  18726. return BE_ORDINAL.Not;
  18727. }
  18728. var sample = dataKeyedColumns[dimName];
  18729. if (!sample || isTypedArray(sample)) {
  18730. return BE_ORDINAL.Not;
  18731. }
  18732. for (var i = 0; i < sample.length && i < maxLoop; i++) {
  18733. if ((result = detectValue(sample[i])) != null) {
  18734. return result;
  18735. }
  18736. }
  18737. } else if (sourceFormat === SOURCE_FORMAT_ORIGINAL) {
  18738. var dataOriginal = data;
  18739. for (var i = 0; i < dataOriginal.length && i < maxLoop; i++) {
  18740. var item = dataOriginal[i];
  18741. var val = getDataItemValue(item);
  18742. if (!isArray(val)) {
  18743. return BE_ORDINAL.Not;
  18744. }
  18745. if ((result = detectValue(val[dimIndex])) != null) {
  18746. return result;
  18747. }
  18748. }
  18749. }
  18750. function detectValue(val) {
  18751. var beStr = isString(val);
  18752. // Consider usage convenience, '1', '2' will be treated as "number".
  18753. // `Number('')` (or any whitespace) is `0`.
  18754. if (val != null && Number.isFinite(Number(val)) && val !== '') {
  18755. return beStr ? BE_ORDINAL.Might : BE_ORDINAL.Not;
  18756. } else if (beStr && val !== '-') {
  18757. return BE_ORDINAL.Must;
  18758. }
  18759. }
  18760. return BE_ORDINAL.Not;
  18761. }
  18762. var internalOptionCreatorMap = createHashMap();
  18763. function registerInternalOptionCreator(mainType, creator) {
  18764. assert(internalOptionCreatorMap.get(mainType) == null && creator);
  18765. internalOptionCreatorMap.set(mainType, creator);
  18766. }
  18767. function concatInternalOptions(ecModel, mainType, newCmptOptionList) {
  18768. var internalOptionCreator = internalOptionCreatorMap.get(mainType);
  18769. if (!internalOptionCreator) {
  18770. return newCmptOptionList;
  18771. }
  18772. var internalOptions = internalOptionCreator(ecModel);
  18773. if (!internalOptions) {
  18774. return newCmptOptionList;
  18775. }
  18776. if ("development" !== 'production') {
  18777. for (var i = 0; i < internalOptions.length; i++) {
  18778. assert(isComponentIdInternal(internalOptions[i]));
  18779. }
  18780. }
  18781. return newCmptOptionList.concat(internalOptions);
  18782. }
  18783. var innerColor = makeInner();
  18784. var innerDecal = makeInner();
  18785. var PaletteMixin = /** @class */function () {
  18786. function PaletteMixin() {}
  18787. PaletteMixin.prototype.getColorFromPalette = function (name, scope, requestNum) {
  18788. var defaultPalette = normalizeToArray(this.get('color', true));
  18789. var layeredPalette = this.get('colorLayer', true);
  18790. return getFromPalette(this, innerColor, defaultPalette, layeredPalette, name, scope, requestNum);
  18791. };
  18792. PaletteMixin.prototype.clearColorPalette = function () {
  18793. clearPalette(this, innerColor);
  18794. };
  18795. return PaletteMixin;
  18796. }();
  18797. function getDecalFromPalette(ecModel, name, scope, requestNum) {
  18798. var defaultDecals = normalizeToArray(ecModel.get(['aria', 'decal', 'decals']));
  18799. return getFromPalette(ecModel, innerDecal, defaultDecals, null, name, scope, requestNum);
  18800. }
  18801. function getNearestPalette(palettes, requestColorNum) {
  18802. var paletteNum = palettes.length;
  18803. // TODO palettes must be in order
  18804. for (var i = 0; i < paletteNum; i++) {
  18805. if (palettes[i].length > requestColorNum) {
  18806. return palettes[i];
  18807. }
  18808. }
  18809. return palettes[paletteNum - 1];
  18810. }
  18811. /**
  18812. * @param name MUST NOT be null/undefined. Otherwise call this function
  18813. * twise with the same parameters will get different result.
  18814. * @param scope default this.
  18815. * @return Can be null/undefined
  18816. */
  18817. function getFromPalette(that, inner, defaultPalette, layeredPalette, name, scope, requestNum) {
  18818. scope = scope || that;
  18819. var scopeFields = inner(scope);
  18820. var paletteIdx = scopeFields.paletteIdx || 0;
  18821. var paletteNameMap = scopeFields.paletteNameMap = scopeFields.paletteNameMap || {};
  18822. // Use `hasOwnProperty` to avoid conflict with Object.prototype.
  18823. if (paletteNameMap.hasOwnProperty(name)) {
  18824. return paletteNameMap[name];
  18825. }
  18826. var palette = requestNum == null || !layeredPalette ? defaultPalette : getNearestPalette(layeredPalette, requestNum);
  18827. // In case can't find in layered color palette.
  18828. palette = palette || defaultPalette;
  18829. if (!palette || !palette.length) {
  18830. return;
  18831. }
  18832. var pickedPaletteItem = palette[paletteIdx];
  18833. if (name) {
  18834. paletteNameMap[name] = pickedPaletteItem;
  18835. }
  18836. scopeFields.paletteIdx = (paletteIdx + 1) % palette.length;
  18837. return pickedPaletteItem;
  18838. }
  18839. function clearPalette(that, inner) {
  18840. inner(that).paletteIdx = 0;
  18841. inner(that).paletteNameMap = {};
  18842. }
  18843. // -----------------------
  18844. // Internal method names:
  18845. // -----------------------
  18846. var reCreateSeriesIndices;
  18847. var assertSeriesInitialized;
  18848. var initBase;
  18849. var OPTION_INNER_KEY = '\0_ec_inner';
  18850. var OPTION_INNER_VALUE = 1;
  18851. var BUITIN_COMPONENTS_MAP = {
  18852. grid: 'GridComponent',
  18853. polar: 'PolarComponent',
  18854. geo: 'GeoComponent',
  18855. singleAxis: 'SingleAxisComponent',
  18856. parallel: 'ParallelComponent',
  18857. calendar: 'CalendarComponent',
  18858. matrix: 'MatrixComponent',
  18859. graphic: 'GraphicComponent',
  18860. toolbox: 'ToolboxComponent',
  18861. tooltip: 'TooltipComponent',
  18862. axisPointer: 'AxisPointerComponent',
  18863. brush: 'BrushComponent',
  18864. title: 'TitleComponent',
  18865. timeline: 'TimelineComponent',
  18866. markPoint: 'MarkPointComponent',
  18867. markLine: 'MarkLineComponent',
  18868. markArea: 'MarkAreaComponent',
  18869. legend: 'LegendComponent',
  18870. dataZoom: 'DataZoomComponent',
  18871. visualMap: 'VisualMapComponent',
  18872. // aria: 'AriaComponent',
  18873. // dataset: 'DatasetComponent',
  18874. // Dependencies
  18875. xAxis: 'GridComponent',
  18876. yAxis: 'GridComponent',
  18877. angleAxis: 'PolarComponent',
  18878. radiusAxis: 'PolarComponent'
  18879. };
  18880. var BUILTIN_CHARTS_MAP = {
  18881. line: 'LineChart',
  18882. bar: 'BarChart',
  18883. pie: 'PieChart',
  18884. scatter: 'ScatterChart',
  18885. radar: 'RadarChart',
  18886. map: 'MapChart',
  18887. tree: 'TreeChart',
  18888. treemap: 'TreemapChart',
  18889. graph: 'GraphChart',
  18890. chord: 'ChordChart',
  18891. gauge: 'GaugeChart',
  18892. funnel: 'FunnelChart',
  18893. parallel: 'ParallelChart',
  18894. sankey: 'SankeyChart',
  18895. boxplot: 'BoxplotChart',
  18896. candlestick: 'CandlestickChart',
  18897. effectScatter: 'EffectScatterChart',
  18898. lines: 'LinesChart',
  18899. heatmap: 'HeatmapChart',
  18900. pictorialBar: 'PictorialBarChart',
  18901. themeRiver: 'ThemeRiverChart',
  18902. sunburst: 'SunburstChart',
  18903. custom: 'CustomChart'
  18904. };
  18905. var componetsMissingLogPrinted = {};
  18906. function checkMissingComponents(option) {
  18907. each(option, function (componentOption, mainType) {
  18908. if (!ComponentModel.hasClass(mainType)) {
  18909. var componentImportName = BUITIN_COMPONENTS_MAP[mainType];
  18910. if (componentImportName && !componetsMissingLogPrinted[componentImportName]) {
  18911. error("Component " + mainType + " is used but not imported.\nimport { " + componentImportName + " } from 'echarts/components';\necharts.use([" + componentImportName + "]);");
  18912. componetsMissingLogPrinted[componentImportName] = true;
  18913. }
  18914. }
  18915. });
  18916. }
  18917. var GlobalModel = /** @class */function (_super) {
  18918. __extends(GlobalModel, _super);
  18919. function GlobalModel() {
  18920. return _super !== null && _super.apply(this, arguments) || this;
  18921. }
  18922. GlobalModel.prototype.init = function (option, parentModel, ecModel, theme, locale, optionManager) {
  18923. theme = theme || {};
  18924. this.option = null; // Mark as not initialized.
  18925. this._theme = new Model(theme);
  18926. this._locale = new Model(locale);
  18927. this._optionManager = optionManager;
  18928. };
  18929. GlobalModel.prototype.setOption = function (option, opts, optionPreprocessorFuncs) {
  18930. if ("development" !== 'production') {
  18931. assert(option != null, 'option is null/undefined');
  18932. assert(option[OPTION_INNER_KEY] !== OPTION_INNER_VALUE, 'please use chart.getOption()');
  18933. }
  18934. var innerOpt = normalizeSetOptionInput(opts);
  18935. this._optionManager.setOption(option, optionPreprocessorFuncs, innerOpt);
  18936. this._resetOption(null, innerOpt);
  18937. };
  18938. /**
  18939. * @param type null/undefined: reset all.
  18940. * 'recreate': force recreate all.
  18941. * 'timeline': only reset timeline option
  18942. * 'media': only reset media query option
  18943. * @return Whether option changed.
  18944. */
  18945. GlobalModel.prototype.resetOption = function (type, opt) {
  18946. return this._resetOption(type, normalizeSetOptionInput(opt));
  18947. };
  18948. GlobalModel.prototype._resetOption = function (type, opt) {
  18949. var optionChanged = false;
  18950. var optionManager = this._optionManager;
  18951. if (!type || type === 'recreate') {
  18952. var baseOption = optionManager.mountOption(type === 'recreate');
  18953. if ("development" !== 'production') {
  18954. checkMissingComponents(baseOption);
  18955. }
  18956. if (!this.option || type === 'recreate') {
  18957. initBase(this, baseOption);
  18958. } else {
  18959. this.restoreData();
  18960. this._mergeOption(baseOption, opt);
  18961. }
  18962. optionChanged = true;
  18963. }
  18964. if (type === 'timeline' || type === 'media') {
  18965. this.restoreData();
  18966. }
  18967. // By design, if `setOption(option2)` at the second time, and `option2` is a `ECUnitOption`,
  18968. // it should better not have the same props with `MediaUnit['option']`.
  18969. // Because either `option2` or `MediaUnit['option']` will be always merged to "current option"
  18970. // rather than original "baseOption". If they both override a prop, the result might be
  18971. // unexpected when media state changed after `setOption` called.
  18972. // If we really need to modify a props in each `MediaUnit['option']`, use the full version
  18973. // (`{baseOption, media}`) in `setOption`.
  18974. // For `timeline`, the case is the same.
  18975. if (!type || type === 'recreate' || type === 'timeline') {
  18976. var timelineOption = optionManager.getTimelineOption(this);
  18977. if (timelineOption) {
  18978. optionChanged = true;
  18979. this._mergeOption(timelineOption, opt);
  18980. }
  18981. }
  18982. if (!type || type === 'recreate' || type === 'media') {
  18983. var mediaOptions = optionManager.getMediaOption(this);
  18984. if (mediaOptions.length) {
  18985. each(mediaOptions, function (mediaOption) {
  18986. optionChanged = true;
  18987. this._mergeOption(mediaOption, opt);
  18988. }, this);
  18989. }
  18990. }
  18991. return optionChanged;
  18992. };
  18993. GlobalModel.prototype.mergeOption = function (option) {
  18994. this._mergeOption(option, null);
  18995. };
  18996. GlobalModel.prototype._mergeOption = function (newOption, opt) {
  18997. var option = this.option;
  18998. var componentsMap = this._componentsMap;
  18999. var componentsCount = this._componentsCount;
  19000. var newCmptTypes = [];
  19001. var newCmptTypeMap = createHashMap();
  19002. var replaceMergeMainTypeMap = opt && opt.replaceMergeMainTypeMap;
  19003. resetSourceDefaulter(this);
  19004. // If no component class, merge directly.
  19005. // For example: color, animaiton options, etc.
  19006. each(newOption, function (componentOption, mainType) {
  19007. if (componentOption == null) {
  19008. return;
  19009. }
  19010. if (!ComponentModel.hasClass(mainType)) {
  19011. // globalSettingTask.dirty();
  19012. option[mainType] = option[mainType] == null ? clone(componentOption) : merge(option[mainType], componentOption, true);
  19013. } else if (mainType) {
  19014. newCmptTypes.push(mainType);
  19015. newCmptTypeMap.set(mainType, true);
  19016. }
  19017. });
  19018. if (replaceMergeMainTypeMap) {
  19019. // If there is a mainType `xxx` in `replaceMerge` but not declared in option,
  19020. // we trade it as it is declared in option as `{xxx: []}`. Because:
  19021. // (1) for normal merge, `{xxx: null/undefined}` are the same meaning as `{xxx: []}`.
  19022. // (2) some preprocessor may convert some of `{xxx: null/undefined}` to `{xxx: []}`.
  19023. replaceMergeMainTypeMap.each(function (val, mainTypeInReplaceMerge) {
  19024. if (ComponentModel.hasClass(mainTypeInReplaceMerge) && !newCmptTypeMap.get(mainTypeInReplaceMerge)) {
  19025. newCmptTypes.push(mainTypeInReplaceMerge);
  19026. newCmptTypeMap.set(mainTypeInReplaceMerge, true);
  19027. }
  19028. });
  19029. }
  19030. ComponentModel.topologicalTravel(newCmptTypes, ComponentModel.getAllClassMainTypes(), visitComponent, this);
  19031. function visitComponent(mainType) {
  19032. var newCmptOptionList = concatInternalOptions(this, mainType, normalizeToArray(newOption[mainType]));
  19033. var oldCmptList = componentsMap.get(mainType);
  19034. var mergeMode =
  19035. // `!oldCmptList` means init. See the comment in `mappingToExists`
  19036. !oldCmptList ? 'replaceAll' : replaceMergeMainTypeMap && replaceMergeMainTypeMap.get(mainType) ? 'replaceMerge' : 'normalMerge';
  19037. var mappingResult = mappingToExists(oldCmptList, newCmptOptionList, mergeMode);
  19038. // Set mainType and complete subType.
  19039. setComponentTypeToKeyInfo(mappingResult, mainType, ComponentModel);
  19040. // Empty it before the travel, in order to prevent `this._componentsMap`
  19041. // from being used in the `init`/`mergeOption`/`optionUpdated` of some
  19042. // components, which is probably incorrect logic.
  19043. option[mainType] = null;
  19044. componentsMap.set(mainType, null);
  19045. componentsCount.set(mainType, 0);
  19046. var optionsByMainType = [];
  19047. var cmptsByMainType = [];
  19048. var cmptsCountByMainType = 0;
  19049. var tooltipExists;
  19050. var tooltipWarningLogged;
  19051. each(mappingResult, function (resultItem, index) {
  19052. var componentModel = resultItem.existing;
  19053. var newCmptOption = resultItem.newOption;
  19054. if (!newCmptOption) {
  19055. if (componentModel) {
  19056. // Consider where is no new option and should be merged using {},
  19057. // see removeEdgeAndAdd in topologicalTravel and
  19058. // ComponentModel.getAllClassMainTypes.
  19059. componentModel.mergeOption({}, this);
  19060. componentModel.optionUpdated({}, false);
  19061. }
  19062. // If no both `resultItem.exist` and `resultItem.option`,
  19063. // either it is in `replaceMerge` and not matched by any id,
  19064. // or it has been removed in previous `replaceMerge` and left a "hole" in this component index.
  19065. } else {
  19066. var isSeriesType = mainType === 'series';
  19067. var ComponentModelClass = ComponentModel.getClass(mainType, resultItem.keyInfo.subType, !isSeriesType // Give a more detailed warn later if series don't exists
  19068. );
  19069. if (!ComponentModelClass) {
  19070. if ("development" !== 'production') {
  19071. var subType = resultItem.keyInfo.subType;
  19072. var seriesImportName = BUILTIN_CHARTS_MAP[subType];
  19073. if (!componetsMissingLogPrinted[subType]) {
  19074. componetsMissingLogPrinted[subType] = true;
  19075. if (seriesImportName) {
  19076. error("Series " + subType + " is used but not imported.\nimport { " + seriesImportName + " } from 'echarts/charts';\necharts.use([" + seriesImportName + "]);");
  19077. } else {
  19078. error("Unknown series " + subType);
  19079. }
  19080. }
  19081. }
  19082. return;
  19083. }
  19084. // TODO Before multiple tooltips get supported, we do this check to avoid unexpected exception.
  19085. if (mainType === 'tooltip') {
  19086. if (tooltipExists) {
  19087. if ("development" !== 'production') {
  19088. if (!tooltipWarningLogged) {
  19089. warn('Currently only one tooltip component is allowed.');
  19090. tooltipWarningLogged = true;
  19091. }
  19092. }
  19093. return;
  19094. }
  19095. tooltipExists = true;
  19096. }
  19097. if (componentModel && componentModel.constructor === ComponentModelClass) {
  19098. componentModel.name = resultItem.keyInfo.name;
  19099. // componentModel.settingTask && componentModel.settingTask.dirty();
  19100. componentModel.mergeOption(newCmptOption, this);
  19101. componentModel.optionUpdated(newCmptOption, false);
  19102. } else {
  19103. // PENDING Global as parent ?
  19104. var extraOpt = extend({
  19105. componentIndex: index
  19106. }, resultItem.keyInfo);
  19107. componentModel = new ComponentModelClass(newCmptOption, this, this, extraOpt);
  19108. // Assign `keyInfo`
  19109. extend(componentModel, extraOpt);
  19110. if (resultItem.brandNew) {
  19111. componentModel.__requireNewView = true;
  19112. }
  19113. componentModel.init(newCmptOption, this, this);
  19114. // Call optionUpdated after init.
  19115. // newCmptOption has been used as componentModel.option
  19116. // and may be merged with theme and default, so pass null
  19117. // to avoid confusion.
  19118. componentModel.optionUpdated(null, true);
  19119. }
  19120. }
  19121. if (componentModel) {
  19122. optionsByMainType.push(componentModel.option);
  19123. cmptsByMainType.push(componentModel);
  19124. cmptsCountByMainType++;
  19125. } else {
  19126. // Always do assign to avoid elided item in array.
  19127. optionsByMainType.push(void 0);
  19128. cmptsByMainType.push(void 0);
  19129. }
  19130. }, this);
  19131. option[mainType] = optionsByMainType;
  19132. componentsMap.set(mainType, cmptsByMainType);
  19133. componentsCount.set(mainType, cmptsCountByMainType);
  19134. // Backup series for filtering.
  19135. if (mainType === 'series') {
  19136. reCreateSeriesIndices(this);
  19137. }
  19138. }
  19139. // If no series declared, ensure `_seriesIndices` initialized.
  19140. if (!this._seriesIndices) {
  19141. reCreateSeriesIndices(this);
  19142. }
  19143. };
  19144. /**
  19145. * Get option for output (cloned option and inner info removed)
  19146. */
  19147. GlobalModel.prototype.getOption = function () {
  19148. var option = clone(this.option);
  19149. each(option, function (optInMainType, mainType) {
  19150. if (ComponentModel.hasClass(mainType)) {
  19151. var opts = normalizeToArray(optInMainType);
  19152. // Inner cmpts need to be removed.
  19153. // Inner cmpts might not be at last since ec5.0, but still
  19154. // compatible for users: if inner cmpt at last, splice the returned array.
  19155. var realLen = opts.length;
  19156. var metNonInner = false;
  19157. for (var i = realLen - 1; i >= 0; i--) {
  19158. // Remove options with inner id.
  19159. if (opts[i] && !isComponentIdInternal(opts[i])) {
  19160. metNonInner = true;
  19161. } else {
  19162. opts[i] = null;
  19163. !metNonInner && realLen--;
  19164. }
  19165. }
  19166. opts.length = realLen;
  19167. option[mainType] = opts;
  19168. }
  19169. });
  19170. delete option[OPTION_INNER_KEY];
  19171. return option;
  19172. };
  19173. GlobalModel.prototype.setTheme = function (theme) {
  19174. this._theme = new Model(theme);
  19175. this._resetOption('recreate', null);
  19176. };
  19177. GlobalModel.prototype.getTheme = function () {
  19178. return this._theme;
  19179. };
  19180. GlobalModel.prototype.getLocaleModel = function () {
  19181. return this._locale;
  19182. };
  19183. GlobalModel.prototype.setUpdatePayload = function (payload) {
  19184. this._payload = payload;
  19185. };
  19186. GlobalModel.prototype.getUpdatePayload = function () {
  19187. return this._payload;
  19188. };
  19189. /**
  19190. * @param idx If not specified, return the first one.
  19191. */
  19192. GlobalModel.prototype.getComponent = function (mainType, idx) {
  19193. var list = this._componentsMap.get(mainType);
  19194. if (list) {
  19195. var cmpt = list[idx || 0];
  19196. if (cmpt) {
  19197. return cmpt;
  19198. } else if (idx == null) {
  19199. for (var i = 0; i < list.length; i++) {
  19200. if (list[i]) {
  19201. return list[i];
  19202. }
  19203. }
  19204. }
  19205. }
  19206. };
  19207. /**
  19208. * @return Never be null/undefined.
  19209. */
  19210. GlobalModel.prototype.queryComponents = function (condition) {
  19211. var mainType = condition.mainType;
  19212. if (!mainType) {
  19213. return [];
  19214. }
  19215. var index = condition.index;
  19216. var id = condition.id;
  19217. var name = condition.name;
  19218. var cmpts = this._componentsMap.get(mainType);
  19219. if (!cmpts || !cmpts.length) {
  19220. return [];
  19221. }
  19222. var result;
  19223. if (index != null) {
  19224. result = [];
  19225. each(normalizeToArray(index), function (idx) {
  19226. cmpts[idx] && result.push(cmpts[idx]);
  19227. });
  19228. } else if (id != null) {
  19229. result = queryByIdOrName('id', id, cmpts);
  19230. } else if (name != null) {
  19231. result = queryByIdOrName('name', name, cmpts);
  19232. } else {
  19233. // Return all non-empty components in that mainType
  19234. result = filter(cmpts, function (cmpt) {
  19235. return !!cmpt;
  19236. });
  19237. }
  19238. return filterBySubType(result, condition);
  19239. };
  19240. /**
  19241. * The interface is different from queryComponents,
  19242. * which is convenient for inner usage.
  19243. *
  19244. * @usage
  19245. * let result = findComponents(
  19246. * {mainType: 'dataZoom', query: {dataZoomId: 'abc'}}
  19247. * );
  19248. * let result = findComponents(
  19249. * {mainType: 'series', subType: 'pie', query: {seriesName: 'uio'}}
  19250. * );
  19251. * let result = findComponents(
  19252. * {mainType: 'series',
  19253. * filter: function (model, index) {...}}
  19254. * );
  19255. * // result like [component0, componnet1, ...]
  19256. */
  19257. GlobalModel.prototype.findComponents = function (condition) {
  19258. var query = condition.query;
  19259. var mainType = condition.mainType;
  19260. var queryCond = getQueryCond(query);
  19261. var result = queryCond ? this.queryComponents(queryCond)
  19262. // Retrieve all non-empty components.
  19263. : filter(this._componentsMap.get(mainType), function (cmpt) {
  19264. return !!cmpt;
  19265. });
  19266. return doFilter(filterBySubType(result, condition));
  19267. function getQueryCond(q) {
  19268. var indexAttr = mainType + 'Index';
  19269. var idAttr = mainType + 'Id';
  19270. var nameAttr = mainType + 'Name';
  19271. return q && (q[indexAttr] != null || q[idAttr] != null || q[nameAttr] != null) ? {
  19272. mainType: mainType,
  19273. // subType will be filtered finally.
  19274. index: q[indexAttr],
  19275. id: q[idAttr],
  19276. name: q[nameAttr]
  19277. } : null;
  19278. }
  19279. function doFilter(res) {
  19280. return condition.filter ? filter(res, condition.filter) : res;
  19281. }
  19282. };
  19283. GlobalModel.prototype.eachComponent = function (mainType, cb, context) {
  19284. var componentsMap = this._componentsMap;
  19285. if (isFunction(mainType)) {
  19286. var ctxForAll_1 = cb;
  19287. var cbForAll_1 = mainType;
  19288. componentsMap.each(function (cmpts, componentType) {
  19289. for (var i = 0; cmpts && i < cmpts.length; i++) {
  19290. var cmpt = cmpts[i];
  19291. cmpt && cbForAll_1.call(ctxForAll_1, componentType, cmpt, cmpt.componentIndex);
  19292. }
  19293. });
  19294. } else {
  19295. var cmpts = isString(mainType) ? componentsMap.get(mainType) : isObject(mainType) ? this.findComponents(mainType) : null;
  19296. for (var i = 0; cmpts && i < cmpts.length; i++) {
  19297. var cmpt = cmpts[i];
  19298. cmpt && cb.call(context, cmpt, cmpt.componentIndex);
  19299. }
  19300. }
  19301. };
  19302. /**
  19303. * Get series list before filtered by name.
  19304. */
  19305. GlobalModel.prototype.getSeriesByName = function (name) {
  19306. var nameStr = convertOptionIdName(name, null);
  19307. return filter(this._componentsMap.get('series'), function (oneSeries) {
  19308. return !!oneSeries && nameStr != null && oneSeries.name === nameStr;
  19309. });
  19310. };
  19311. /**
  19312. * Get series list before filtered by index.
  19313. */
  19314. GlobalModel.prototype.getSeriesByIndex = function (seriesIndex) {
  19315. return this._componentsMap.get('series')[seriesIndex];
  19316. };
  19317. /**
  19318. * Get series list before filtered by type.
  19319. * FIXME: rename to getRawSeriesByType?
  19320. */
  19321. GlobalModel.prototype.getSeriesByType = function (subType) {
  19322. return filter(this._componentsMap.get('series'), function (oneSeries) {
  19323. return !!oneSeries && oneSeries.subType === subType;
  19324. });
  19325. };
  19326. /**
  19327. * Get all series before filtered.
  19328. */
  19329. GlobalModel.prototype.getSeries = function () {
  19330. return filter(this._componentsMap.get('series'), function (oneSeries) {
  19331. return !!oneSeries;
  19332. });
  19333. };
  19334. /**
  19335. * Count series before filtered.
  19336. */
  19337. GlobalModel.prototype.getSeriesCount = function () {
  19338. return this._componentsCount.get('series');
  19339. };
  19340. /**
  19341. * After filtering, series may be different
  19342. * from raw series.
  19343. */
  19344. GlobalModel.prototype.eachSeries = function (cb, context) {
  19345. assertSeriesInitialized(this);
  19346. each(this._seriesIndices, function (rawSeriesIndex) {
  19347. var series = this._componentsMap.get('series')[rawSeriesIndex];
  19348. cb.call(context, series, rawSeriesIndex);
  19349. }, this);
  19350. };
  19351. /**
  19352. * Iterate raw series before filtered.
  19353. *
  19354. * @param {Function} cb
  19355. * @param {*} context
  19356. */
  19357. GlobalModel.prototype.eachRawSeries = function (cb, context) {
  19358. each(this._componentsMap.get('series'), function (series) {
  19359. series && cb.call(context, series, series.componentIndex);
  19360. });
  19361. };
  19362. /**
  19363. * After filtering, series may be different.
  19364. * from raw series.
  19365. */
  19366. GlobalModel.prototype.eachSeriesByType = function (subType, cb, context) {
  19367. assertSeriesInitialized(this);
  19368. each(this._seriesIndices, function (rawSeriesIndex) {
  19369. var series = this._componentsMap.get('series')[rawSeriesIndex];
  19370. if (series.subType === subType) {
  19371. cb.call(context, series, rawSeriesIndex);
  19372. }
  19373. }, this);
  19374. };
  19375. /**
  19376. * Iterate raw series before filtered of given type.
  19377. */
  19378. GlobalModel.prototype.eachRawSeriesByType = function (subType, cb, context) {
  19379. return each(this.getSeriesByType(subType), cb, context);
  19380. };
  19381. GlobalModel.prototype.isSeriesFiltered = function (seriesModel) {
  19382. assertSeriesInitialized(this);
  19383. return this._seriesIndicesMap.get(seriesModel.componentIndex) == null;
  19384. };
  19385. GlobalModel.prototype.getCurrentSeriesIndices = function () {
  19386. return (this._seriesIndices || []).slice();
  19387. };
  19388. GlobalModel.prototype.filterSeries = function (cb, context) {
  19389. assertSeriesInitialized(this);
  19390. var newSeriesIndices = [];
  19391. each(this._seriesIndices, function (seriesRawIdx) {
  19392. var series = this._componentsMap.get('series')[seriesRawIdx];
  19393. cb.call(context, series, seriesRawIdx) && newSeriesIndices.push(seriesRawIdx);
  19394. }, this);
  19395. this._seriesIndices = newSeriesIndices;
  19396. this._seriesIndicesMap = createHashMap(newSeriesIndices);
  19397. };
  19398. GlobalModel.prototype.restoreData = function (payload) {
  19399. reCreateSeriesIndices(this);
  19400. var componentsMap = this._componentsMap;
  19401. var componentTypes = [];
  19402. componentsMap.each(function (components, componentType) {
  19403. if (ComponentModel.hasClass(componentType)) {
  19404. componentTypes.push(componentType);
  19405. }
  19406. });
  19407. ComponentModel.topologicalTravel(componentTypes, ComponentModel.getAllClassMainTypes(), function (componentType) {
  19408. each(componentsMap.get(componentType), function (component) {
  19409. if (component && (componentType !== 'series' || !isNotTargetSeries(component, payload))) {
  19410. component.restoreData();
  19411. }
  19412. });
  19413. });
  19414. };
  19415. GlobalModel.internalField = function () {
  19416. reCreateSeriesIndices = function (ecModel) {
  19417. var seriesIndices = ecModel._seriesIndices = [];
  19418. each(ecModel._componentsMap.get('series'), function (series) {
  19419. // series may have been removed by `replaceMerge`.
  19420. series && seriesIndices.push(series.componentIndex);
  19421. });
  19422. ecModel._seriesIndicesMap = createHashMap(seriesIndices);
  19423. };
  19424. assertSeriesInitialized = function (ecModel) {
  19425. // Components that use _seriesIndices should depends on series component,
  19426. // which make sure that their initialization is after series.
  19427. if ("development" !== 'production') {
  19428. if (!ecModel._seriesIndices) {
  19429. throw new Error('Option should contains series.');
  19430. }
  19431. }
  19432. };
  19433. initBase = function (ecModel, baseOption) {
  19434. // Using OPTION_INNER_KEY to mark that this option cannot be used outside,
  19435. // i.e. `chart.setOption(chart.getModel().option);` is forbidden.
  19436. ecModel.option = {};
  19437. ecModel.option[OPTION_INNER_KEY] = OPTION_INNER_VALUE;
  19438. // Init with series: [], in case of calling findSeries method
  19439. // before series initialized.
  19440. ecModel._componentsMap = createHashMap({
  19441. series: []
  19442. });
  19443. ecModel._componentsCount = createHashMap();
  19444. // If user spefied `option.aria`, aria will be enable. This detection should be
  19445. // performed before theme and globalDefault merge.
  19446. var airaOption = baseOption.aria;
  19447. if (isObject(airaOption) && airaOption.enabled == null) {
  19448. airaOption.enabled = true;
  19449. }
  19450. mergeTheme(baseOption, ecModel._theme.option);
  19451. // TODO Needs clone when merging to the unexisted property
  19452. merge(baseOption, globalDefault, false);
  19453. ecModel._mergeOption(baseOption, null);
  19454. };
  19455. }();
  19456. return GlobalModel;
  19457. }(Model);
  19458. function isNotTargetSeries(seriesModel, payload) {
  19459. if (payload) {
  19460. var index = payload.seriesIndex;
  19461. var id = payload.seriesId;
  19462. var name_1 = payload.seriesName;
  19463. return index != null && seriesModel.componentIndex !== index || id != null && seriesModel.id !== id || name_1 != null && seriesModel.name !== name_1;
  19464. }
  19465. }
  19466. function mergeTheme(option, theme) {
  19467. // PENDING
  19468. // NOT use `colorLayer` in theme if option has `color`
  19469. var notMergeColorLayer = option.color && !option.colorLayer;
  19470. each(theme, function (themeItem, name) {
  19471. if (name === 'colorLayer' && notMergeColorLayer || name === 'color' && option.color) {
  19472. return;
  19473. }
  19474. // If it is component model mainType, the model handles that merge later.
  19475. // otherwise, merge them here.
  19476. if (!ComponentModel.hasClass(name)) {
  19477. if (typeof themeItem === 'object') {
  19478. option[name] = !option[name] ? clone(themeItem) : merge(option[name], themeItem, false);
  19479. } else {
  19480. if (option[name] == null) {
  19481. option[name] = themeItem;
  19482. }
  19483. }
  19484. }
  19485. });
  19486. }
  19487. function queryByIdOrName(attr, idOrName, cmpts) {
  19488. // Here is a break from echarts4: string and number are
  19489. // treated as equal.
  19490. if (isArray(idOrName)) {
  19491. var keyMap_1 = createHashMap();
  19492. each(idOrName, function (idOrNameItem) {
  19493. if (idOrNameItem != null) {
  19494. var idName = convertOptionIdName(idOrNameItem, null);
  19495. idName != null && keyMap_1.set(idOrNameItem, true);
  19496. }
  19497. });
  19498. return filter(cmpts, function (cmpt) {
  19499. return cmpt && keyMap_1.get(cmpt[attr]);
  19500. });
  19501. } else {
  19502. var idName_1 = convertOptionIdName(idOrName, null);
  19503. return filter(cmpts, function (cmpt) {
  19504. return cmpt && idName_1 != null && cmpt[attr] === idName_1;
  19505. });
  19506. }
  19507. }
  19508. function filterBySubType(components, condition) {
  19509. // Using hasOwnProperty for restrict. Consider
  19510. // subType is undefined in user payload.
  19511. return condition.hasOwnProperty('subType') ? filter(components, function (cmpt) {
  19512. return cmpt && cmpt.subType === condition.subType;
  19513. }) : components;
  19514. }
  19515. function normalizeSetOptionInput(opts) {
  19516. var replaceMergeMainTypeMap = createHashMap();
  19517. opts && each(normalizeToArray(opts.replaceMerge), function (mainType) {
  19518. if ("development" !== 'production') {
  19519. assert(ComponentModel.hasClass(mainType), '"' + mainType + '" is not valid component main type in "replaceMerge"');
  19520. }
  19521. replaceMergeMainTypeMap.set(mainType, true);
  19522. });
  19523. return {
  19524. replaceMergeMainTypeMap: replaceMergeMainTypeMap
  19525. };
  19526. }
  19527. mixin(GlobalModel, PaletteMixin);
  19528. var availableMethods = ['getDom', 'getZr', 'getWidth', 'getHeight', 'getDevicePixelRatio', 'dispatchAction', 'isSSR', 'isDisposed', 'on', 'off', 'getDataURL', 'getConnectedDataURL',
  19529. // 'getModel',
  19530. 'getOption',
  19531. // 'getViewOfComponentModel',
  19532. // 'getViewOfSeriesModel',
  19533. 'getId', 'updateLabelLayout'];
  19534. var ExtensionAPI = /** @class */function () {
  19535. function ExtensionAPI(ecInstance) {
  19536. each(availableMethods, function (methodName) {
  19537. this[methodName] = bind(ecInstance[methodName], ecInstance);
  19538. }, this);
  19539. }
  19540. return ExtensionAPI;
  19541. }();
  19542. var QUERY_REG = /^(min|max)?(.+)$/;
  19543. // Key: mainType
  19544. // type FakeComponentsMap = HashMap<(MappingExistingItem & { subType: string })[]>;
  19545. /**
  19546. * TERM EXPLANATIONS:
  19547. * See `ECOption` and `ECUnitOption` in `src/util/types.ts`.
  19548. */
  19549. var OptionManager = /** @class */function () {
  19550. // timeline.notMerge is not supported in ec3. Firstly there is rearly
  19551. // case that notMerge is needed. Secondly supporting 'notMerge' requires
  19552. // rawOption cloned and backuped when timeline changed, which does no
  19553. // good to performance. What's more, that both timeline and setOption
  19554. // method supply 'notMerge' brings complex and some problems.
  19555. // Consider this case:
  19556. // (step1) chart.setOption({timeline: {notMerge: false}, ...}, false);
  19557. // (step2) chart.setOption({timeline: {notMerge: true}, ...}, false);
  19558. function OptionManager(api) {
  19559. this._timelineOptions = [];
  19560. this._mediaList = [];
  19561. /**
  19562. * -1, means default.
  19563. * empty means no media.
  19564. */
  19565. this._currentMediaIndices = [];
  19566. this._api = api;
  19567. }
  19568. OptionManager.prototype.setOption = function (rawOption, optionPreprocessorFuncs, opt) {
  19569. if (rawOption) {
  19570. // That set dat primitive is dangerous if user reuse the data when setOption again.
  19571. each(normalizeToArray(rawOption.series), function (series) {
  19572. series && series.data && isTypedArray(series.data) && setAsPrimitive(series.data);
  19573. });
  19574. each(normalizeToArray(rawOption.dataset), function (dataset) {
  19575. dataset && dataset.source && isTypedArray(dataset.source) && setAsPrimitive(dataset.source);
  19576. });
  19577. }
  19578. // Caution: some series modify option data, if do not clone,
  19579. // it should ensure that the repeat modify correctly
  19580. // (create a new object when modify itself).
  19581. rawOption = clone(rawOption);
  19582. // FIXME
  19583. // If some property is set in timeline options or media option but
  19584. // not set in baseOption, a warning should be given.
  19585. var optionBackup = this._optionBackup;
  19586. var newParsedOption = parseRawOption(rawOption, optionPreprocessorFuncs, !optionBackup);
  19587. this._newBaseOption = newParsedOption.baseOption;
  19588. // For setOption at second time (using merge mode);
  19589. if (optionBackup) {
  19590. // FIXME
  19591. // the restore merge solution is essentially incorrect.
  19592. // the mapping can not be 100% consistent with ecModel, which probably brings
  19593. // potential bug!
  19594. // The first merge is delayed, because in most cases, users do not call `setOption` twice.
  19595. // let fakeCmptsMap = this._fakeCmptsMap;
  19596. // if (!fakeCmptsMap) {
  19597. // fakeCmptsMap = this._fakeCmptsMap = createHashMap();
  19598. // mergeToBackupOption(fakeCmptsMap, null, optionBackup.baseOption, null);
  19599. // }
  19600. // mergeToBackupOption(
  19601. // fakeCmptsMap, optionBackup.baseOption, newParsedOption.baseOption, opt
  19602. // );
  19603. // For simplicity, timeline options and media options do not support merge,
  19604. // that is, if you `setOption` twice and both has timeline options, the latter
  19605. // timeline options will not be merged to the former, but just substitute them.
  19606. if (newParsedOption.timelineOptions.length) {
  19607. optionBackup.timelineOptions = newParsedOption.timelineOptions;
  19608. }
  19609. if (newParsedOption.mediaList.length) {
  19610. optionBackup.mediaList = newParsedOption.mediaList;
  19611. }
  19612. if (newParsedOption.mediaDefault) {
  19613. optionBackup.mediaDefault = newParsedOption.mediaDefault;
  19614. }
  19615. } else {
  19616. this._optionBackup = newParsedOption;
  19617. }
  19618. };
  19619. OptionManager.prototype.mountOption = function (isRecreate) {
  19620. var optionBackup = this._optionBackup;
  19621. this._timelineOptions = optionBackup.timelineOptions;
  19622. this._mediaList = optionBackup.mediaList;
  19623. this._mediaDefault = optionBackup.mediaDefault;
  19624. this._currentMediaIndices = [];
  19625. return clone(isRecreate
  19626. // this._optionBackup.baseOption, which is created at the first `setOption`
  19627. // called, and is merged into every new option by inner method `mergeToBackupOption`
  19628. // each time `setOption` called, can be only used in `isRecreate`, because
  19629. // its reliability is under suspicion. In other cases option merge is
  19630. // performed by `model.mergeOption`.
  19631. ? optionBackup.baseOption : this._newBaseOption);
  19632. };
  19633. OptionManager.prototype.getTimelineOption = function (ecModel) {
  19634. var option;
  19635. var timelineOptions = this._timelineOptions;
  19636. if (timelineOptions.length) {
  19637. // getTimelineOption can only be called after ecModel inited,
  19638. // so we can get currentIndex from timelineModel.
  19639. var timelineModel = ecModel.getComponent('timeline');
  19640. if (timelineModel) {
  19641. option = clone(
  19642. // FIXME:TS as TimelineModel or quivlant interface
  19643. timelineOptions[timelineModel.getCurrentIndex()]);
  19644. }
  19645. }
  19646. return option;
  19647. };
  19648. OptionManager.prototype.getMediaOption = function (ecModel) {
  19649. var ecWidth = this._api.getWidth();
  19650. var ecHeight = this._api.getHeight();
  19651. var mediaList = this._mediaList;
  19652. var mediaDefault = this._mediaDefault;
  19653. var indices = [];
  19654. var result = [];
  19655. // No media defined.
  19656. if (!mediaList.length && !mediaDefault) {
  19657. return result;
  19658. }
  19659. // Multi media may be applied, the latter defined media has higher priority.
  19660. for (var i = 0, len = mediaList.length; i < len; i++) {
  19661. if (applyMediaQuery(mediaList[i].query, ecWidth, ecHeight)) {
  19662. indices.push(i);
  19663. }
  19664. }
  19665. // FIXME
  19666. // Whether mediaDefault should force users to provide? Otherwise
  19667. // the change by media query can not be recorvered.
  19668. if (!indices.length && mediaDefault) {
  19669. indices = [-1];
  19670. }
  19671. if (indices.length && !indicesEquals(indices, this._currentMediaIndices)) {
  19672. result = map(indices, function (index) {
  19673. return clone(index === -1 ? mediaDefault.option : mediaList[index].option);
  19674. });
  19675. }
  19676. // Otherwise return nothing.
  19677. this._currentMediaIndices = indices;
  19678. return result;
  19679. };
  19680. return OptionManager;
  19681. }();
  19682. /**
  19683. * [RAW_OPTION_PATTERNS]
  19684. * (Note: "series: []" represents all other props in `ECUnitOption`)
  19685. *
  19686. * (1) No prop "baseOption" declared:
  19687. * Root option is used as "baseOption" (except prop "options" and "media").
  19688. * ```js
  19689. * option = {
  19690. * series: [],
  19691. * timeline: {},
  19692. * options: [],
  19693. * };
  19694. * option = {
  19695. * series: [],
  19696. * media: {},
  19697. * };
  19698. * option = {
  19699. * series: [],
  19700. * timeline: {},
  19701. * options: [],
  19702. * media: {},
  19703. * }
  19704. * ```
  19705. *
  19706. * (2) Prop "baseOption" declared:
  19707. * If "baseOption" declared, `ECUnitOption` props can only be declared
  19708. * inside "baseOption" except prop "timeline" (compat ec2).
  19709. * ```js
  19710. * option = {
  19711. * baseOption: {
  19712. * timeline: {},
  19713. * series: [],
  19714. * },
  19715. * options: []
  19716. * };
  19717. * option = {
  19718. * baseOption: {
  19719. * series: [],
  19720. * },
  19721. * media: []
  19722. * };
  19723. * option = {
  19724. * baseOption: {
  19725. * timeline: {},
  19726. * series: [],
  19727. * },
  19728. * options: []
  19729. * media: []
  19730. * };
  19731. * option = {
  19732. * // ec3 compat ec2: allow (only) `timeline` declared
  19733. * // outside baseOption. Keep this setting for compat.
  19734. * timeline: {},
  19735. * baseOption: {
  19736. * series: [],
  19737. * },
  19738. * options: [],
  19739. * media: []
  19740. * };
  19741. * ```
  19742. */
  19743. function parseRawOption(
  19744. // `rawOption` May be modified
  19745. rawOption, optionPreprocessorFuncs, isNew) {
  19746. var mediaList = [];
  19747. var mediaDefault;
  19748. var baseOption;
  19749. var declaredBaseOption = rawOption.baseOption;
  19750. // Compatible with ec2, [RAW_OPTION_PATTERNS] above.
  19751. var timelineOnRoot = rawOption.timeline;
  19752. var timelineOptionsOnRoot = rawOption.options;
  19753. var mediaOnRoot = rawOption.media;
  19754. var hasMedia = !!rawOption.media;
  19755. var hasTimeline = !!(timelineOptionsOnRoot || timelineOnRoot || declaredBaseOption && declaredBaseOption.timeline);
  19756. if (declaredBaseOption) {
  19757. baseOption = declaredBaseOption;
  19758. // For merge option.
  19759. if (!baseOption.timeline) {
  19760. baseOption.timeline = timelineOnRoot;
  19761. }
  19762. }
  19763. // For convenience, enable to use the root option as the `baseOption`:
  19764. // `{ ...normalOptionProps, media: [{ ... }, { ... }] }`
  19765. else {
  19766. if (hasTimeline || hasMedia) {
  19767. rawOption.options = rawOption.media = null;
  19768. }
  19769. baseOption = rawOption;
  19770. }
  19771. if (hasMedia) {
  19772. if (isArray(mediaOnRoot)) {
  19773. each(mediaOnRoot, function (singleMedia) {
  19774. if ("development" !== 'production') {
  19775. // Real case of wrong config.
  19776. if (singleMedia && !singleMedia.option && isObject(singleMedia.query) && isObject(singleMedia.query.option)) {
  19777. error('Illegal media option. Must be like { media: [ { query: {}, option: {} } ] }');
  19778. }
  19779. }
  19780. if (singleMedia && singleMedia.option) {
  19781. if (singleMedia.query) {
  19782. mediaList.push(singleMedia);
  19783. } else if (!mediaDefault) {
  19784. // Use the first media default.
  19785. mediaDefault = singleMedia;
  19786. }
  19787. }
  19788. });
  19789. } else {
  19790. if ("development" !== 'production') {
  19791. // Real case of wrong config.
  19792. error('Illegal media option. Must be an array. Like { media: [ {...}, {...} ] }');
  19793. }
  19794. }
  19795. }
  19796. doPreprocess(baseOption);
  19797. each(timelineOptionsOnRoot, function (option) {
  19798. return doPreprocess(option);
  19799. });
  19800. each(mediaList, function (media) {
  19801. return doPreprocess(media.option);
  19802. });
  19803. function doPreprocess(option) {
  19804. each(optionPreprocessorFuncs, function (preProcess) {
  19805. preProcess(option, isNew);
  19806. });
  19807. }
  19808. return {
  19809. baseOption: baseOption,
  19810. timelineOptions: timelineOptionsOnRoot || [],
  19811. mediaDefault: mediaDefault,
  19812. mediaList: mediaList
  19813. };
  19814. }
  19815. /**
  19816. * @see <http://www.w3.org/TR/css3-mediaqueries/#media1>
  19817. * Support: width, height, aspectRatio
  19818. * Can use max or min as prefix.
  19819. */
  19820. function applyMediaQuery(query, ecWidth, ecHeight) {
  19821. var realMap = {
  19822. width: ecWidth,
  19823. height: ecHeight,
  19824. aspectratio: ecWidth / ecHeight // lower case for convenience.
  19825. };
  19826. var applicable = true;
  19827. each(query, function (value, attr) {
  19828. var matched = attr.match(QUERY_REG);
  19829. if (!matched || !matched[1] || !matched[2]) {
  19830. return;
  19831. }
  19832. var operator = matched[1];
  19833. var realAttr = matched[2].toLowerCase();
  19834. if (!compare(realMap[realAttr], value, operator)) {
  19835. applicable = false;
  19836. }
  19837. });
  19838. return applicable;
  19839. }
  19840. function compare(real, expect, operator) {
  19841. if (operator === 'min') {
  19842. return real >= expect;
  19843. } else if (operator === 'max') {
  19844. return real <= expect;
  19845. } else {
  19846. // Equals
  19847. return real === expect;
  19848. }
  19849. }
  19850. function indicesEquals(indices1, indices2) {
  19851. // indices is always order by asc and has only finite number.
  19852. return indices1.join(',') === indices2.join(',');
  19853. }
  19854. var each$2 = each;
  19855. var isObject$1 = isObject;
  19856. var POSSIBLE_STYLES = ['areaStyle', 'lineStyle', 'nodeStyle', 'linkStyle', 'chordStyle', 'label', 'labelLine'];
  19857. function compatEC2ItemStyle(opt) {
  19858. var itemStyleOpt = opt && opt.itemStyle;
  19859. if (!itemStyleOpt) {
  19860. return;
  19861. }
  19862. for (var i = 0, len = POSSIBLE_STYLES.length; i < len; i++) {
  19863. var styleName = POSSIBLE_STYLES[i];
  19864. var normalItemStyleOpt = itemStyleOpt.normal;
  19865. var emphasisItemStyleOpt = itemStyleOpt.emphasis;
  19866. if (normalItemStyleOpt && normalItemStyleOpt[styleName]) {
  19867. if ("development" !== 'production') {
  19868. deprecateReplaceLog("itemStyle.normal." + styleName, styleName);
  19869. }
  19870. opt[styleName] = opt[styleName] || {};
  19871. if (!opt[styleName].normal) {
  19872. opt[styleName].normal = normalItemStyleOpt[styleName];
  19873. } else {
  19874. merge(opt[styleName].normal, normalItemStyleOpt[styleName]);
  19875. }
  19876. normalItemStyleOpt[styleName] = null;
  19877. }
  19878. if (emphasisItemStyleOpt && emphasisItemStyleOpt[styleName]) {
  19879. if ("development" !== 'production') {
  19880. deprecateReplaceLog("itemStyle.emphasis." + styleName, "emphasis." + styleName);
  19881. }
  19882. opt[styleName] = opt[styleName] || {};
  19883. if (!opt[styleName].emphasis) {
  19884. opt[styleName].emphasis = emphasisItemStyleOpt[styleName];
  19885. } else {
  19886. merge(opt[styleName].emphasis, emphasisItemStyleOpt[styleName]);
  19887. }
  19888. emphasisItemStyleOpt[styleName] = null;
  19889. }
  19890. }
  19891. }
  19892. function convertNormalEmphasis(opt, optType, useExtend) {
  19893. if (opt && opt[optType] && (opt[optType].normal || opt[optType].emphasis)) {
  19894. var normalOpt = opt[optType].normal;
  19895. var emphasisOpt = opt[optType].emphasis;
  19896. if (normalOpt) {
  19897. if ("development" !== 'production') {
  19898. // eslint-disable-next-line max-len
  19899. deprecateLog("'normal' hierarchy in " + optType + " has been removed since 4.0. All style properties are configured in " + optType + " directly now.");
  19900. }
  19901. // Timeline controlStyle has other properties besides normal and emphasis
  19902. if (useExtend) {
  19903. opt[optType].normal = opt[optType].emphasis = null;
  19904. defaults(opt[optType], normalOpt);
  19905. } else {
  19906. opt[optType] = normalOpt;
  19907. }
  19908. }
  19909. if (emphasisOpt) {
  19910. if ("development" !== 'production') {
  19911. deprecateLog(optType + ".emphasis has been changed to emphasis." + optType + " since 4.0");
  19912. }
  19913. opt.emphasis = opt.emphasis || {};
  19914. opt.emphasis[optType] = emphasisOpt;
  19915. // Also compat the case user mix the style and focus together in ec3 style
  19916. // for example: { itemStyle: { normal: {}, emphasis: {focus, shadowBlur} } }
  19917. if (emphasisOpt.focus) {
  19918. opt.emphasis.focus = emphasisOpt.focus;
  19919. }
  19920. if (emphasisOpt.blurScope) {
  19921. opt.emphasis.blurScope = emphasisOpt.blurScope;
  19922. }
  19923. }
  19924. }
  19925. }
  19926. function removeEC3NormalStatus(opt) {
  19927. convertNormalEmphasis(opt, 'itemStyle');
  19928. convertNormalEmphasis(opt, 'lineStyle');
  19929. convertNormalEmphasis(opt, 'areaStyle');
  19930. convertNormalEmphasis(opt, 'label');
  19931. convertNormalEmphasis(opt, 'labelLine');
  19932. // treemap
  19933. convertNormalEmphasis(opt, 'upperLabel');
  19934. // graph
  19935. convertNormalEmphasis(opt, 'edgeLabel');
  19936. }
  19937. function compatTextStyle(opt, propName) {
  19938. // Check whether is not object (string\null\undefined ...)
  19939. var labelOptSingle = isObject$1(opt) && opt[propName];
  19940. var textStyle = isObject$1(labelOptSingle) && labelOptSingle.textStyle;
  19941. if (textStyle) {
  19942. if ("development" !== 'production') {
  19943. // eslint-disable-next-line max-len
  19944. deprecateLog("textStyle hierarchy in " + propName + " has been removed since 4.0. All textStyle properties are configured in " + propName + " directly now.");
  19945. }
  19946. for (var i = 0, len = TEXT_STYLE_OPTIONS.length; i < len; i++) {
  19947. var textPropName = TEXT_STYLE_OPTIONS[i];
  19948. if (textStyle.hasOwnProperty(textPropName)) {
  19949. labelOptSingle[textPropName] = textStyle[textPropName];
  19950. }
  19951. }
  19952. }
  19953. }
  19954. function compatEC3CommonStyles(opt) {
  19955. if (opt) {
  19956. removeEC3NormalStatus(opt);
  19957. compatTextStyle(opt, 'label');
  19958. opt.emphasis && compatTextStyle(opt.emphasis, 'label');
  19959. }
  19960. }
  19961. function processSeries(seriesOpt) {
  19962. if (!isObject$1(seriesOpt)) {
  19963. return;
  19964. }
  19965. compatEC2ItemStyle(seriesOpt);
  19966. removeEC3NormalStatus(seriesOpt);
  19967. compatTextStyle(seriesOpt, 'label');
  19968. // treemap
  19969. compatTextStyle(seriesOpt, 'upperLabel');
  19970. // graph
  19971. compatTextStyle(seriesOpt, 'edgeLabel');
  19972. if (seriesOpt.emphasis) {
  19973. compatTextStyle(seriesOpt.emphasis, 'label');
  19974. // treemap
  19975. compatTextStyle(seriesOpt.emphasis, 'upperLabel');
  19976. // graph
  19977. compatTextStyle(seriesOpt.emphasis, 'edgeLabel');
  19978. }
  19979. var markPoint = seriesOpt.markPoint;
  19980. if (markPoint) {
  19981. compatEC2ItemStyle(markPoint);
  19982. compatEC3CommonStyles(markPoint);
  19983. }
  19984. var markLine = seriesOpt.markLine;
  19985. if (markLine) {
  19986. compatEC2ItemStyle(markLine);
  19987. compatEC3CommonStyles(markLine);
  19988. }
  19989. var markArea = seriesOpt.markArea;
  19990. if (markArea) {
  19991. compatEC3CommonStyles(markArea);
  19992. }
  19993. var data = seriesOpt.data;
  19994. // Break with ec3: if `setOption` again, there may be no `type` in option,
  19995. // then the backward compat based on option type will not be performed.
  19996. if (seriesOpt.type === 'graph') {
  19997. data = data || seriesOpt.nodes;
  19998. var edgeData = seriesOpt.links || seriesOpt.edges;
  19999. if (edgeData && !isTypedArray(edgeData)) {
  20000. for (var i = 0; i < edgeData.length; i++) {
  20001. compatEC3CommonStyles(edgeData[i]);
  20002. }
  20003. }
  20004. each(seriesOpt.categories, function (opt) {
  20005. removeEC3NormalStatus(opt);
  20006. });
  20007. }
  20008. if (data && !isTypedArray(data)) {
  20009. for (var i = 0; i < data.length; i++) {
  20010. compatEC3CommonStyles(data[i]);
  20011. }
  20012. }
  20013. // mark point data
  20014. markPoint = seriesOpt.markPoint;
  20015. if (markPoint && markPoint.data) {
  20016. var mpData = markPoint.data;
  20017. for (var i = 0; i < mpData.length; i++) {
  20018. compatEC3CommonStyles(mpData[i]);
  20019. }
  20020. }
  20021. // mark line data
  20022. markLine = seriesOpt.markLine;
  20023. if (markLine && markLine.data) {
  20024. var mlData = markLine.data;
  20025. for (var i = 0; i < mlData.length; i++) {
  20026. if (isArray(mlData[i])) {
  20027. compatEC3CommonStyles(mlData[i][0]);
  20028. compatEC3CommonStyles(mlData[i][1]);
  20029. } else {
  20030. compatEC3CommonStyles(mlData[i]);
  20031. }
  20032. }
  20033. }
  20034. // Series
  20035. if (seriesOpt.type === 'gauge') {
  20036. compatTextStyle(seriesOpt, 'axisLabel');
  20037. compatTextStyle(seriesOpt, 'title');
  20038. compatTextStyle(seriesOpt, 'detail');
  20039. } else if (seriesOpt.type === 'treemap') {
  20040. convertNormalEmphasis(seriesOpt.breadcrumb, 'itemStyle');
  20041. each(seriesOpt.levels, function (opt) {
  20042. removeEC3NormalStatus(opt);
  20043. });
  20044. } else if (seriesOpt.type === 'tree') {
  20045. removeEC3NormalStatus(seriesOpt.leaves);
  20046. }
  20047. // sunburst starts from ec4, so it does not need to compat levels.
  20048. }
  20049. function toArr(o) {
  20050. return isArray(o) ? o : o ? [o] : [];
  20051. }
  20052. function toObj(o) {
  20053. return (isArray(o) ? o[0] : o) || {};
  20054. }
  20055. function globalCompatStyle(option, isTheme) {
  20056. each$2(toArr(option.series), function (seriesOpt) {
  20057. isObject$1(seriesOpt) && processSeries(seriesOpt);
  20058. });
  20059. var axes = ['xAxis', 'yAxis', 'radiusAxis', 'angleAxis', 'singleAxis', 'parallelAxis', 'radar'];
  20060. isTheme && axes.push('valueAxis', 'categoryAxis', 'logAxis', 'timeAxis');
  20061. each$2(axes, function (axisName) {
  20062. each$2(toArr(option[axisName]), function (axisOpt) {
  20063. if (axisOpt) {
  20064. compatTextStyle(axisOpt, 'axisLabel');
  20065. compatTextStyle(axisOpt.axisPointer, 'label');
  20066. }
  20067. });
  20068. });
  20069. each$2(toArr(option.parallel), function (parallelOpt) {
  20070. var parallelAxisDefault = parallelOpt && parallelOpt.parallelAxisDefault;
  20071. compatTextStyle(parallelAxisDefault, 'axisLabel');
  20072. compatTextStyle(parallelAxisDefault && parallelAxisDefault.axisPointer, 'label');
  20073. });
  20074. each$2(toArr(option.calendar), function (calendarOpt) {
  20075. convertNormalEmphasis(calendarOpt, 'itemStyle');
  20076. compatTextStyle(calendarOpt, 'dayLabel');
  20077. compatTextStyle(calendarOpt, 'monthLabel');
  20078. compatTextStyle(calendarOpt, 'yearLabel');
  20079. });
  20080. // radar.name.textStyle
  20081. each$2(toArr(option.radar), function (radarOpt) {
  20082. compatTextStyle(radarOpt, 'name');
  20083. // Use axisName instead of name because component has name property
  20084. if (radarOpt.name && radarOpt.axisName == null) {
  20085. radarOpt.axisName = radarOpt.name;
  20086. delete radarOpt.name;
  20087. if ("development" !== 'production') {
  20088. deprecateLog('name property in radar component has been changed to axisName');
  20089. }
  20090. }
  20091. if (radarOpt.nameGap != null && radarOpt.axisNameGap == null) {
  20092. radarOpt.axisNameGap = radarOpt.nameGap;
  20093. delete radarOpt.nameGap;
  20094. if ("development" !== 'production') {
  20095. deprecateLog('nameGap property in radar component has been changed to axisNameGap');
  20096. }
  20097. }
  20098. if ("development" !== 'production') {
  20099. each$2(radarOpt.indicator, function (indicatorOpt) {
  20100. if (indicatorOpt.text) {
  20101. deprecateReplaceLog('text', 'name', 'radar.indicator');
  20102. }
  20103. });
  20104. }
  20105. });
  20106. each$2(toArr(option.geo), function (geoOpt) {
  20107. if (isObject$1(geoOpt)) {
  20108. compatEC3CommonStyles(geoOpt);
  20109. each$2(toArr(geoOpt.regions), function (regionObj) {
  20110. compatEC3CommonStyles(regionObj);
  20111. });
  20112. }
  20113. });
  20114. each$2(toArr(option.timeline), function (timelineOpt) {
  20115. compatEC3CommonStyles(timelineOpt);
  20116. convertNormalEmphasis(timelineOpt, 'label');
  20117. convertNormalEmphasis(timelineOpt, 'itemStyle');
  20118. convertNormalEmphasis(timelineOpt, 'controlStyle', true);
  20119. var data = timelineOpt.data;
  20120. isArray(data) && each(data, function (item) {
  20121. if (isObject(item)) {
  20122. convertNormalEmphasis(item, 'label');
  20123. convertNormalEmphasis(item, 'itemStyle');
  20124. }
  20125. });
  20126. });
  20127. each$2(toArr(option.toolbox), function (toolboxOpt) {
  20128. convertNormalEmphasis(toolboxOpt, 'iconStyle');
  20129. each$2(toolboxOpt.feature, function (featureOpt) {
  20130. convertNormalEmphasis(featureOpt, 'iconStyle');
  20131. });
  20132. });
  20133. compatTextStyle(toObj(option.axisPointer), 'label');
  20134. compatTextStyle(toObj(option.tooltip).axisPointer, 'label');
  20135. // Clean logs
  20136. // storedLogs = {};
  20137. }
  20138. function get(opt, path) {
  20139. var pathArr = path.split(',');
  20140. var obj = opt;
  20141. for (var i = 0; i < pathArr.length; i++) {
  20142. obj = obj && obj[pathArr[i]];
  20143. if (obj == null) {
  20144. break;
  20145. }
  20146. }
  20147. return obj;
  20148. }
  20149. function set$1(opt, path, val, overwrite) {
  20150. var pathArr = path.split(',');
  20151. var obj = opt;
  20152. var key;
  20153. var i = 0;
  20154. for (; i < pathArr.length - 1; i++) {
  20155. key = pathArr[i];
  20156. if (obj[key] == null) {
  20157. obj[key] = {};
  20158. }
  20159. obj = obj[key];
  20160. }
  20161. if (overwrite || obj[pathArr[i]] == null) {
  20162. obj[pathArr[i]] = val;
  20163. }
  20164. }
  20165. function compatLayoutProperties(option) {
  20166. option && each(LAYOUT_PROPERTIES, function (prop) {
  20167. if (prop[0] in option && !(prop[1] in option)) {
  20168. option[prop[1]] = option[prop[0]];
  20169. }
  20170. });
  20171. }
  20172. var LAYOUT_PROPERTIES = [['x', 'left'], ['y', 'top'], ['x2', 'right'], ['y2', 'bottom']];
  20173. var COMPATITABLE_COMPONENTS = ['grid', 'geo', 'parallel', 'legend', 'toolbox', 'title', 'visualMap', 'dataZoom', 'timeline'];
  20174. var BAR_ITEM_STYLE_MAP = [['borderRadius', 'barBorderRadius'], ['borderColor', 'barBorderColor'], ['borderWidth', 'barBorderWidth']];
  20175. function compatBarItemStyle(option) {
  20176. var itemStyle = option && option.itemStyle;
  20177. if (itemStyle) {
  20178. for (var i = 0; i < BAR_ITEM_STYLE_MAP.length; i++) {
  20179. var oldName = BAR_ITEM_STYLE_MAP[i][1];
  20180. var newName = BAR_ITEM_STYLE_MAP[i][0];
  20181. if (itemStyle[oldName] != null) {
  20182. itemStyle[newName] = itemStyle[oldName];
  20183. if ("development" !== 'production') {
  20184. deprecateReplaceLog(oldName, newName);
  20185. }
  20186. }
  20187. }
  20188. }
  20189. }
  20190. function compatPieLabel(option) {
  20191. if (!option) {
  20192. return;
  20193. }
  20194. if (option.alignTo === 'edge' && option.margin != null && option.edgeDistance == null) {
  20195. if ("development" !== 'production') {
  20196. deprecateReplaceLog('label.margin', 'label.edgeDistance', 'pie');
  20197. }
  20198. option.edgeDistance = option.margin;
  20199. }
  20200. }
  20201. function compatSunburstState(option) {
  20202. if (!option) {
  20203. return;
  20204. }
  20205. if (option.downplay && !option.blur) {
  20206. option.blur = option.downplay;
  20207. if ("development" !== 'production') {
  20208. deprecateReplaceLog('downplay', 'blur', 'sunburst');
  20209. }
  20210. }
  20211. }
  20212. function compatGraphFocus(option) {
  20213. if (!option) {
  20214. return;
  20215. }
  20216. if (option.focusNodeAdjacency != null) {
  20217. option.emphasis = option.emphasis || {};
  20218. if (option.emphasis.focus == null) {
  20219. if ("development" !== 'production') {
  20220. deprecateReplaceLog('focusNodeAdjacency', 'emphasis: { focus: \'adjacency\'}', 'graph/sankey');
  20221. }
  20222. option.emphasis.focus = 'adjacency';
  20223. }
  20224. }
  20225. }
  20226. function traverseTree(data, cb) {
  20227. if (data) {
  20228. for (var i = 0; i < data.length; i++) {
  20229. cb(data[i]);
  20230. data[i] && traverseTree(data[i].children, cb);
  20231. }
  20232. }
  20233. }
  20234. function globalBackwardCompat(option, isTheme) {
  20235. globalCompatStyle(option, isTheme);
  20236. // Make sure series array for model initialization.
  20237. option.series = normalizeToArray(option.series);
  20238. each(option.series, function (seriesOpt) {
  20239. if (!isObject(seriesOpt)) {
  20240. return;
  20241. }
  20242. var seriesType = seriesOpt.type;
  20243. if (seriesType === 'line') {
  20244. if (seriesOpt.clipOverflow != null) {
  20245. seriesOpt.clip = seriesOpt.clipOverflow;
  20246. if ("development" !== 'production') {
  20247. deprecateReplaceLog('clipOverflow', 'clip', 'line');
  20248. }
  20249. }
  20250. } else if (seriesType === 'pie' || seriesType === 'gauge') {
  20251. if (seriesOpt.clockWise != null) {
  20252. seriesOpt.clockwise = seriesOpt.clockWise;
  20253. if ("development" !== 'production') {
  20254. deprecateReplaceLog('clockWise', 'clockwise');
  20255. }
  20256. }
  20257. compatPieLabel(seriesOpt.label);
  20258. var data = seriesOpt.data;
  20259. if (data && !isTypedArray(data)) {
  20260. for (var i = 0; i < data.length; i++) {
  20261. compatPieLabel(data[i]);
  20262. }
  20263. }
  20264. if (seriesOpt.hoverOffset != null) {
  20265. seriesOpt.emphasis = seriesOpt.emphasis || {};
  20266. if (seriesOpt.emphasis.scaleSize = null) {
  20267. if ("development" !== 'production') {
  20268. deprecateReplaceLog('hoverOffset', 'emphasis.scaleSize');
  20269. }
  20270. seriesOpt.emphasis.scaleSize = seriesOpt.hoverOffset;
  20271. }
  20272. }
  20273. } else if (seriesType === 'gauge') {
  20274. var pointerColor = get(seriesOpt, 'pointer.color');
  20275. pointerColor != null && set$1(seriesOpt, 'itemStyle.color', pointerColor);
  20276. } else if (seriesType === 'bar') {
  20277. compatBarItemStyle(seriesOpt);
  20278. compatBarItemStyle(seriesOpt.backgroundStyle);
  20279. compatBarItemStyle(seriesOpt.emphasis);
  20280. var data = seriesOpt.data;
  20281. if (data && !isTypedArray(data)) {
  20282. for (var i = 0; i < data.length; i++) {
  20283. if (typeof data[i] === 'object') {
  20284. compatBarItemStyle(data[i]);
  20285. compatBarItemStyle(data[i] && data[i].emphasis);
  20286. }
  20287. }
  20288. }
  20289. } else if (seriesType === 'sunburst') {
  20290. var highlightPolicy = seriesOpt.highlightPolicy;
  20291. if (highlightPolicy) {
  20292. seriesOpt.emphasis = seriesOpt.emphasis || {};
  20293. if (!seriesOpt.emphasis.focus) {
  20294. seriesOpt.emphasis.focus = highlightPolicy;
  20295. if ("development" !== 'production') {
  20296. deprecateReplaceLog('highlightPolicy', 'emphasis.focus', 'sunburst');
  20297. }
  20298. }
  20299. }
  20300. compatSunburstState(seriesOpt);
  20301. traverseTree(seriesOpt.data, compatSunburstState);
  20302. } else if (seriesType === 'graph' || seriesType === 'sankey') {
  20303. compatGraphFocus(seriesOpt);
  20304. // TODO nodes, edges?
  20305. } else if (seriesType === 'map') {
  20306. if (seriesOpt.mapType && !seriesOpt.map) {
  20307. if ("development" !== 'production') {
  20308. deprecateReplaceLog('mapType', 'map', 'map');
  20309. }
  20310. seriesOpt.map = seriesOpt.mapType;
  20311. }
  20312. if (seriesOpt.mapLocation) {
  20313. if ("development" !== 'production') {
  20314. deprecateLog('`mapLocation` is not used anymore.');
  20315. }
  20316. defaults(seriesOpt, seriesOpt.mapLocation);
  20317. }
  20318. }
  20319. if (seriesOpt.hoverAnimation != null) {
  20320. seriesOpt.emphasis = seriesOpt.emphasis || {};
  20321. if (seriesOpt.emphasis && seriesOpt.emphasis.scale == null) {
  20322. if ("development" !== 'production') {
  20323. deprecateReplaceLog('hoverAnimation', 'emphasis.scale');
  20324. }
  20325. seriesOpt.emphasis.scale = seriesOpt.hoverAnimation;
  20326. }
  20327. }
  20328. compatLayoutProperties(seriesOpt);
  20329. });
  20330. // dataRange has changed to visualMap
  20331. if (option.dataRange) {
  20332. option.visualMap = option.dataRange;
  20333. }
  20334. each(COMPATITABLE_COMPONENTS, function (componentName) {
  20335. var options = option[componentName];
  20336. if (options) {
  20337. if (!isArray(options)) {
  20338. options = [options];
  20339. }
  20340. each(options, function (option) {
  20341. compatLayoutProperties(option);
  20342. });
  20343. }
  20344. });
  20345. }
  20346. // (1) [Caution]: the logic is correct based on the premises:
  20347. // data processing stage is blocked in stream.
  20348. // See <module:echarts/stream/Scheduler#performDataProcessorTasks>
  20349. // (2) Only register once when import repeatedly.
  20350. // Should be executed after series is filtered and before stack calculation.
  20351. function dataStack(ecModel) {
  20352. var stackInfoMap = createHashMap();
  20353. ecModel.eachSeries(function (seriesModel) {
  20354. var stack = seriesModel.get('stack');
  20355. // Compatible: when `stack` is set as '', do not stack.
  20356. if (stack) {
  20357. var stackInfoList = stackInfoMap.get(stack) || stackInfoMap.set(stack, []);
  20358. var data = seriesModel.getData();
  20359. var stackInfo = {
  20360. // Used for calculate axis extent automatically.
  20361. // TODO: Type getCalculationInfo return more specific type?
  20362. stackResultDimension: data.getCalculationInfo('stackResultDimension'),
  20363. stackedOverDimension: data.getCalculationInfo('stackedOverDimension'),
  20364. stackedDimension: data.getCalculationInfo('stackedDimension'),
  20365. stackedByDimension: data.getCalculationInfo('stackedByDimension'),
  20366. isStackedByIndex: data.getCalculationInfo('isStackedByIndex'),
  20367. data: data,
  20368. seriesModel: seriesModel
  20369. };
  20370. // If stacked on axis that do not support data stack.
  20371. if (!stackInfo.stackedDimension || !(stackInfo.isStackedByIndex || stackInfo.stackedByDimension)) {
  20372. return;
  20373. }
  20374. stackInfoList.push(stackInfo);
  20375. }
  20376. });
  20377. // Process each stack group
  20378. stackInfoMap.each(function (stackInfoList) {
  20379. if (stackInfoList.length === 0) {
  20380. return;
  20381. }
  20382. // Check if stack order needs to be reversed
  20383. var firstSeries = stackInfoList[0].seriesModel;
  20384. var stackOrder = firstSeries.get('stackOrder') || 'seriesAsc';
  20385. if (stackOrder === 'seriesDesc') {
  20386. stackInfoList.reverse();
  20387. }
  20388. // Set stackedOnSeries for each series in the final order
  20389. each(stackInfoList, function (stackInfo, index) {
  20390. stackInfo.data.setCalculationInfo('stackedOnSeries', index > 0 ? stackInfoList[index - 1].seriesModel : null);
  20391. });
  20392. // Calculate stack values
  20393. calculateStack(stackInfoList);
  20394. });
  20395. }
  20396. function calculateStack(stackInfoList) {
  20397. each(stackInfoList, function (targetStackInfo, idxInStack) {
  20398. var resultVal = [];
  20399. var resultNaN = [NaN, NaN];
  20400. var dims = [targetStackInfo.stackResultDimension, targetStackInfo.stackedOverDimension];
  20401. var targetData = targetStackInfo.data;
  20402. var isStackedByIndex = targetStackInfo.isStackedByIndex;
  20403. var stackStrategy = targetStackInfo.seriesModel.get('stackStrategy') || 'samesign';
  20404. // Should not write on raw data, because stack series model list changes
  20405. // depending on legend selection.
  20406. targetData.modify(dims, function (v0, v1, dataIndex) {
  20407. var sum = targetData.get(targetStackInfo.stackedDimension, dataIndex);
  20408. // Consider `connectNulls` of line area, if value is NaN, stackedOver
  20409. // should also be NaN, to draw a appropriate belt area.
  20410. if (isNaN(sum)) {
  20411. return resultNaN;
  20412. }
  20413. var byValue;
  20414. var stackedDataRawIndex;
  20415. if (isStackedByIndex) {
  20416. stackedDataRawIndex = targetData.getRawIndex(dataIndex);
  20417. } else {
  20418. byValue = targetData.get(targetStackInfo.stackedByDimension, dataIndex);
  20419. }
  20420. // If stackOver is NaN, chart view will render point on value start.
  20421. var stackedOver = NaN;
  20422. for (var j = idxInStack - 1; j >= 0; j--) {
  20423. var stackInfo = stackInfoList[j];
  20424. // Has been optimized by inverted indices on `stackedByDimension`.
  20425. if (!isStackedByIndex) {
  20426. stackedDataRawIndex = stackInfo.data.rawIndexOf(stackInfo.stackedByDimension, byValue);
  20427. }
  20428. if (stackedDataRawIndex >= 0) {
  20429. var val = stackInfo.data.getByRawIndex(stackInfo.stackResultDimension, stackedDataRawIndex);
  20430. // Considering positive stack, negative stack and empty data
  20431. if (stackStrategy === 'all' // single stack group
  20432. || stackStrategy === 'positive' && val > 0 || stackStrategy === 'negative' && val < 0 || stackStrategy === 'samesign' && sum >= 0 && val > 0 // All positive stack
  20433. || stackStrategy === 'samesign' && sum <= 0 && val < 0 // All negative stack
  20434. ) {
  20435. // The sum has to be very small to be affected by the
  20436. // floating arithmetic problem. An incorrect result will probably
  20437. // cause axis min/max to be filtered incorrectly.
  20438. sum = addSafe(sum, val);
  20439. stackedOver = val;
  20440. break;
  20441. }
  20442. }
  20443. }
  20444. resultVal[0] = sum;
  20445. resultVal[1] = stackedOver;
  20446. return resultVal;
  20447. });
  20448. });
  20449. }
  20450. // @inner
  20451. var SourceImpl = /** @class */function () {
  20452. function SourceImpl(fields) {
  20453. this.data = fields.data || (fields.sourceFormat === SOURCE_FORMAT_KEYED_COLUMNS ? {} : []);
  20454. this.sourceFormat = fields.sourceFormat || SOURCE_FORMAT_UNKNOWN;
  20455. // Visit config
  20456. this.seriesLayoutBy = fields.seriesLayoutBy || SERIES_LAYOUT_BY_COLUMN;
  20457. this.startIndex = fields.startIndex || 0;
  20458. this.dimensionsDetectedCount = fields.dimensionsDetectedCount;
  20459. this.metaRawOption = fields.metaRawOption;
  20460. var dimensionsDefine = this.dimensionsDefine = fields.dimensionsDefine;
  20461. if (dimensionsDefine) {
  20462. for (var i = 0; i < dimensionsDefine.length; i++) {
  20463. var dim = dimensionsDefine[i];
  20464. if (dim.type == null) {
  20465. if (guessOrdinal(this, i) === BE_ORDINAL.Must) {
  20466. dim.type = 'ordinal';
  20467. }
  20468. }
  20469. }
  20470. }
  20471. }
  20472. return SourceImpl;
  20473. }();
  20474. function isSourceInstance(val) {
  20475. return val instanceof SourceImpl;
  20476. }
  20477. /**
  20478. * Create a source from option.
  20479. * NOTE: Created source is immutable. Don't change any properties in it.
  20480. */
  20481. function createSource(sourceData, thisMetaRawOption,
  20482. // can be null. If not provided, auto detect it from `sourceData`.
  20483. sourceFormat) {
  20484. sourceFormat = sourceFormat || detectSourceFormat(sourceData);
  20485. var seriesLayoutBy = thisMetaRawOption.seriesLayoutBy;
  20486. var determined = determineSourceDimensions(sourceData, sourceFormat, seriesLayoutBy, thisMetaRawOption.sourceHeader, thisMetaRawOption.dimensions);
  20487. var source = new SourceImpl({
  20488. data: sourceData,
  20489. sourceFormat: sourceFormat,
  20490. seriesLayoutBy: seriesLayoutBy,
  20491. dimensionsDefine: determined.dimensionsDefine,
  20492. startIndex: determined.startIndex,
  20493. dimensionsDetectedCount: determined.dimensionsDetectedCount,
  20494. metaRawOption: clone(thisMetaRawOption)
  20495. });
  20496. return source;
  20497. }
  20498. /**
  20499. * Wrap original series data for some compatibility cases.
  20500. */
  20501. function createSourceFromSeriesDataOption(data) {
  20502. return new SourceImpl({
  20503. data: data,
  20504. sourceFormat: isTypedArray(data) ? SOURCE_FORMAT_TYPED_ARRAY : SOURCE_FORMAT_ORIGINAL
  20505. });
  20506. }
  20507. /**
  20508. * Clone source but excludes source data.
  20509. */
  20510. function cloneSourceShallow(source) {
  20511. return new SourceImpl({
  20512. data: source.data,
  20513. sourceFormat: source.sourceFormat,
  20514. seriesLayoutBy: source.seriesLayoutBy,
  20515. dimensionsDefine: clone(source.dimensionsDefine),
  20516. startIndex: source.startIndex,
  20517. dimensionsDetectedCount: source.dimensionsDetectedCount
  20518. });
  20519. }
  20520. /**
  20521. * Note: An empty array will be detected as `SOURCE_FORMAT_ARRAY_ROWS`.
  20522. */
  20523. function detectSourceFormat(data) {
  20524. var sourceFormat = SOURCE_FORMAT_UNKNOWN;
  20525. if (isTypedArray(data)) {
  20526. sourceFormat = SOURCE_FORMAT_TYPED_ARRAY;
  20527. } else if (isArray(data)) {
  20528. // FIXME Whether tolerate null in top level array?
  20529. if (data.length === 0) {
  20530. sourceFormat = SOURCE_FORMAT_ARRAY_ROWS;
  20531. }
  20532. for (var i = 0, len = data.length; i < len; i++) {
  20533. var item = data[i];
  20534. if (item == null) {
  20535. continue;
  20536. } else if (isArray(item) || isTypedArray(item)) {
  20537. sourceFormat = SOURCE_FORMAT_ARRAY_ROWS;
  20538. break;
  20539. } else if (isObject(item)) {
  20540. sourceFormat = SOURCE_FORMAT_OBJECT_ROWS;
  20541. break;
  20542. }
  20543. }
  20544. } else if (isObject(data)) {
  20545. for (var key in data) {
  20546. if (hasOwn(data, key) && isArrayLike(data[key])) {
  20547. sourceFormat = SOURCE_FORMAT_KEYED_COLUMNS;
  20548. break;
  20549. }
  20550. }
  20551. }
  20552. return sourceFormat;
  20553. }
  20554. /**
  20555. * Determine the source definitions from data standalone dimensions definitions
  20556. * are not specified.
  20557. */
  20558. function determineSourceDimensions(data, sourceFormat, seriesLayoutBy, sourceHeader,
  20559. // standalone raw dimensions definition, like:
  20560. // {
  20561. // dimensions: ['aa', 'bb', { name: 'cc', type: 'time' }]
  20562. // }
  20563. // in `dataset` or `series`
  20564. dimensionsDefine) {
  20565. var dimensionsDetectedCount;
  20566. var startIndex;
  20567. // PENDING: Could data be null/undefined here?
  20568. // currently, if `dataset.source` not specified, error thrown.
  20569. // if `series.data` not specified, nothing rendered without error thrown.
  20570. // Should test these cases.
  20571. if (!data) {
  20572. return {
  20573. dimensionsDefine: normalizeDimensionsOption(dimensionsDefine),
  20574. startIndex: startIndex,
  20575. dimensionsDetectedCount: dimensionsDetectedCount
  20576. };
  20577. }
  20578. if (sourceFormat === SOURCE_FORMAT_ARRAY_ROWS) {
  20579. var dataArrayRows = data;
  20580. // Rule: Most of the first line are string: it is header.
  20581. // Caution: consider a line with 5 string and 1 number,
  20582. // it still can not be sure it is a head, because the
  20583. // 5 string may be 5 values of category columns.
  20584. if (sourceHeader === 'auto' || sourceHeader == null) {
  20585. arrayRowsTravelFirst(function (val) {
  20586. // '-' is regarded as null/undefined.
  20587. if (val != null && val !== '-') {
  20588. if (isString(val)) {
  20589. startIndex == null && (startIndex = 1);
  20590. } else {
  20591. startIndex = 0;
  20592. }
  20593. }
  20594. // 10 is an experience number, avoid long loop.
  20595. }, seriesLayoutBy, dataArrayRows, 10);
  20596. } else {
  20597. startIndex = isNumber(sourceHeader) ? sourceHeader : sourceHeader ? 1 : 0;
  20598. }
  20599. if (!dimensionsDefine && startIndex === 1) {
  20600. dimensionsDefine = [];
  20601. arrayRowsTravelFirst(function (val, index) {
  20602. dimensionsDefine[index] = val != null ? val + '' : '';
  20603. }, seriesLayoutBy, dataArrayRows, Infinity);
  20604. }
  20605. dimensionsDetectedCount = dimensionsDefine ? dimensionsDefine.length : seriesLayoutBy === SERIES_LAYOUT_BY_ROW ? dataArrayRows.length : dataArrayRows[0] ? dataArrayRows[0].length : null;
  20606. } else if (sourceFormat === SOURCE_FORMAT_OBJECT_ROWS) {
  20607. if (!dimensionsDefine) {
  20608. dimensionsDefine = objectRowsCollectDimensions(data);
  20609. }
  20610. } else if (sourceFormat === SOURCE_FORMAT_KEYED_COLUMNS) {
  20611. if (!dimensionsDefine) {
  20612. dimensionsDefine = [];
  20613. each(data, function (colArr, key) {
  20614. dimensionsDefine.push(key);
  20615. });
  20616. }
  20617. } else if (sourceFormat === SOURCE_FORMAT_ORIGINAL) {
  20618. var value0 = getDataItemValue(data[0]);
  20619. dimensionsDetectedCount = isArray(value0) && value0.length || 1;
  20620. } else if (sourceFormat === SOURCE_FORMAT_TYPED_ARRAY) {
  20621. if ("development" !== 'production') {
  20622. assert(!!dimensionsDefine, 'dimensions must be given if data is TypedArray.');
  20623. }
  20624. }
  20625. return {
  20626. startIndex: startIndex,
  20627. dimensionsDefine: normalizeDimensionsOption(dimensionsDefine),
  20628. dimensionsDetectedCount: dimensionsDetectedCount
  20629. };
  20630. }
  20631. function objectRowsCollectDimensions(data) {
  20632. var firstIndex = 0;
  20633. var obj;
  20634. while (firstIndex < data.length && !(obj = data[firstIndex++])) {} // jshint ignore: line
  20635. if (obj) {
  20636. return keys(obj);
  20637. }
  20638. }
  20639. // Consider dimensions defined like ['A', 'price', 'B', 'price', 'C', 'price'],
  20640. // which is reasonable. But dimension name is duplicated.
  20641. // Returns undefined or an array contains only object without null/undefined or string.
  20642. function normalizeDimensionsOption(dimensionsDefine) {
  20643. if (!dimensionsDefine) {
  20644. // The meaning of null/undefined is different from empty array.
  20645. return;
  20646. }
  20647. var nameMap = createHashMap();
  20648. return map(dimensionsDefine, function (rawItem, index) {
  20649. rawItem = isObject(rawItem) ? rawItem : {
  20650. name: rawItem
  20651. };
  20652. // Other fields will be discarded.
  20653. var item = {
  20654. name: rawItem.name,
  20655. displayName: rawItem.displayName,
  20656. type: rawItem.type
  20657. };
  20658. // User can set null in dimensions.
  20659. // We don't auto specify name, otherwise a given name may
  20660. // cause it to be referred unexpectedly.
  20661. if (item.name == null) {
  20662. return item;
  20663. }
  20664. // Also consider number form like 2012.
  20665. item.name += '';
  20666. // User may also specify displayName.
  20667. // displayName will always exists except user not
  20668. // specified or dim name is not specified or detected.
  20669. // (A auto generated dim name will not be used as
  20670. // displayName).
  20671. if (item.displayName == null) {
  20672. item.displayName = item.name;
  20673. }
  20674. var exist = nameMap.get(item.name);
  20675. if (!exist) {
  20676. nameMap.set(item.name, {
  20677. count: 1
  20678. });
  20679. } else {
  20680. item.name += '-' + exist.count++;
  20681. }
  20682. return item;
  20683. });
  20684. }
  20685. function arrayRowsTravelFirst(cb, seriesLayoutBy, data, maxLoop) {
  20686. if (seriesLayoutBy === SERIES_LAYOUT_BY_ROW) {
  20687. for (var i = 0; i < data.length && i < maxLoop; i++) {
  20688. cb(data[i] ? data[i][0] : null, i);
  20689. }
  20690. } else {
  20691. var value0 = data[0] || [];
  20692. for (var i = 0; i < value0.length && i < maxLoop; i++) {
  20693. cb(value0[i], i);
  20694. }
  20695. }
  20696. }
  20697. function shouldRetrieveDataByName(source) {
  20698. var sourceFormat = source.sourceFormat;
  20699. return sourceFormat === SOURCE_FORMAT_OBJECT_ROWS || sourceFormat === SOURCE_FORMAT_KEYED_COLUMNS;
  20700. }
  20701. /*
  20702. * Licensed to the Apache Software Foundation (ASF) under one
  20703. * or more contributor license agreements. See the NOTICE file
  20704. * distributed with this work for additional information
  20705. * regarding copyright ownership. The ASF licenses this file
  20706. * to you under the Apache License, Version 2.0 (the
  20707. * "License"); you may not use this file except in compliance
  20708. * with the License. You may obtain a copy of the License at
  20709. *
  20710. * http://www.apache.org/licenses/LICENSE-2.0
  20711. *
  20712. * Unless required by applicable law or agreed to in writing,
  20713. * software distributed under the License is distributed on an
  20714. * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
  20715. * KIND, either express or implied. See the License for the
  20716. * specific language governing permissions and limitations
  20717. * under the License.
  20718. */
  20719. /**
  20720. * AUTO-GENERATED FILE. DO NOT MODIFY.
  20721. */
  20722. /*
  20723. * Licensed to the Apache Software Foundation (ASF) under one
  20724. * or more contributor license agreements. See the NOTICE file
  20725. * distributed with this work for additional information
  20726. * regarding copyright ownership. The ASF licenses this file
  20727. * to you under the Apache License, Version 2.0 (the
  20728. * "License"); you may not use this file except in compliance
  20729. * with the License. You may obtain a copy of the License at
  20730. *
  20731. * http://www.apache.org/licenses/LICENSE-2.0
  20732. *
  20733. * Unless required by applicable law or agreed to in writing,
  20734. * software distributed under the License is distributed on an
  20735. * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
  20736. * KIND, either express or implied. See the License for the
  20737. * specific language governing permissions and limitations
  20738. * under the License.
  20739. */
  20740. var _a, _b, _c, _d;
  20741. var providerMethods;
  20742. var mountMethods;
  20743. /**
  20744. * If normal array used, mutable chunk size is supported.
  20745. * If typed array used, chunk size must be fixed.
  20746. */
  20747. var DefaultDataProvider = /** @class */function () {
  20748. function DefaultDataProvider(sourceParam, dimSize) {
  20749. // let source: Source;
  20750. var source = !isSourceInstance(sourceParam) ? createSourceFromSeriesDataOption(sourceParam) : sourceParam;
  20751. // declare source is Source;
  20752. this._source = source;
  20753. var data = this._data = source.data;
  20754. var sourceFormat = source.sourceFormat;
  20755. var seriesLayoutBy = source.seriesLayoutBy;
  20756. // Typed array. TODO IE10+?
  20757. if (sourceFormat === SOURCE_FORMAT_TYPED_ARRAY) {
  20758. if ("development" !== 'production') {
  20759. if (dimSize == null) {
  20760. throw new Error('Typed array data must specify dimension size');
  20761. }
  20762. }
  20763. this._offset = 0;
  20764. this._dimSize = dimSize;
  20765. this._data = data;
  20766. }
  20767. if ("development" !== 'production') {
  20768. var validator = rawSourceDataValidatorMap[getMethodMapKey(sourceFormat, seriesLayoutBy)];
  20769. validator && validator(data, source.dimensionsDefine);
  20770. }
  20771. mountMethods(this, data, source);
  20772. }
  20773. DefaultDataProvider.prototype.getSource = function () {
  20774. return this._source;
  20775. };
  20776. DefaultDataProvider.prototype.count = function () {
  20777. return 0;
  20778. };
  20779. DefaultDataProvider.prototype.getItem = function (idx, out) {
  20780. return;
  20781. };
  20782. DefaultDataProvider.prototype.appendData = function (newData) {};
  20783. DefaultDataProvider.prototype.clean = function () {};
  20784. DefaultDataProvider.protoInitialize = function () {
  20785. // PENDING: To avoid potential incompat (e.g., prototype
  20786. // is visited somewhere), still init them on prototype.
  20787. var proto = DefaultDataProvider.prototype;
  20788. proto.pure = false;
  20789. proto.persistent = true;
  20790. }();
  20791. DefaultDataProvider.internalField = function () {
  20792. var _a;
  20793. mountMethods = function (provider, data, source) {
  20794. var sourceFormat = source.sourceFormat;
  20795. var seriesLayoutBy = source.seriesLayoutBy;
  20796. var startIndex = source.startIndex;
  20797. var dimsDef = source.dimensionsDefine;
  20798. var methods = providerMethods[getMethodMapKey(sourceFormat, seriesLayoutBy)];
  20799. if ("development" !== 'production') {
  20800. assert(methods, 'Invalide sourceFormat: ' + sourceFormat);
  20801. }
  20802. extend(provider, methods);
  20803. if (sourceFormat === SOURCE_FORMAT_TYPED_ARRAY) {
  20804. provider.getItem = getItemForTypedArray;
  20805. provider.count = countForTypedArray;
  20806. provider.fillStorage = fillStorageForTypedArray;
  20807. } else {
  20808. var rawItemGetter = getRawSourceItemGetter(sourceFormat, seriesLayoutBy);
  20809. provider.getItem = bind(rawItemGetter, null, data, startIndex, dimsDef);
  20810. var rawCounter = getRawSourceDataCounter(sourceFormat, seriesLayoutBy);
  20811. provider.count = bind(rawCounter, null, data, startIndex, dimsDef);
  20812. }
  20813. };
  20814. var getItemForTypedArray = function (idx, out) {
  20815. idx = idx - this._offset;
  20816. out = out || [];
  20817. var data = this._data;
  20818. var dimSize = this._dimSize;
  20819. var offset = dimSize * idx;
  20820. for (var i = 0; i < dimSize; i++) {
  20821. out[i] = data[offset + i];
  20822. }
  20823. return out;
  20824. };
  20825. var fillStorageForTypedArray = function (start, end, storage, extent) {
  20826. var data = this._data;
  20827. var dimSize = this._dimSize;
  20828. for (var dim = 0; dim < dimSize; dim++) {
  20829. var dimExtent = extent[dim];
  20830. var min = dimExtent[0] == null ? Infinity : dimExtent[0];
  20831. var max = dimExtent[1] == null ? -Infinity : dimExtent[1];
  20832. var count = end - start;
  20833. var arr = storage[dim];
  20834. for (var i = 0; i < count; i++) {
  20835. // appendData with TypedArray will always do replace in provider.
  20836. var val = data[i * dimSize + dim];
  20837. arr[start + i] = val;
  20838. val < min && (min = val);
  20839. val > max && (max = val);
  20840. }
  20841. dimExtent[0] = min;
  20842. dimExtent[1] = max;
  20843. }
  20844. };
  20845. var countForTypedArray = function () {
  20846. return this._data ? this._data.length / this._dimSize : 0;
  20847. };
  20848. providerMethods = (_a = {}, _a[SOURCE_FORMAT_ARRAY_ROWS + '_' + SERIES_LAYOUT_BY_COLUMN] = {
  20849. pure: true,
  20850. appendData: appendDataSimply
  20851. }, _a[SOURCE_FORMAT_ARRAY_ROWS + '_' + SERIES_LAYOUT_BY_ROW] = {
  20852. pure: true,
  20853. appendData: function () {
  20854. throw new Error('Do not support appendData when set seriesLayoutBy: "row".');
  20855. }
  20856. }, _a[SOURCE_FORMAT_OBJECT_ROWS] = {
  20857. pure: true,
  20858. appendData: appendDataSimply
  20859. }, _a[SOURCE_FORMAT_KEYED_COLUMNS] = {
  20860. pure: true,
  20861. appendData: function (newData) {
  20862. var data = this._data;
  20863. each(newData, function (newCol, key) {
  20864. var oldCol = data[key] || (data[key] = []);
  20865. for (var i = 0; i < (newCol || []).length; i++) {
  20866. oldCol.push(newCol[i]);
  20867. }
  20868. });
  20869. }
  20870. }, _a[SOURCE_FORMAT_ORIGINAL] = {
  20871. appendData: appendDataSimply
  20872. }, _a[SOURCE_FORMAT_TYPED_ARRAY] = {
  20873. persistent: false,
  20874. pure: true,
  20875. appendData: function (newData) {
  20876. if ("development" !== 'production') {
  20877. assert(isTypedArray(newData), 'Added data must be TypedArray if data in initialization is TypedArray');
  20878. }
  20879. this._data = newData;
  20880. },
  20881. // Clean self if data is already used.
  20882. clean: function () {
  20883. // PENDING
  20884. this._offset += this.count();
  20885. this._data = null;
  20886. }
  20887. }, _a);
  20888. function appendDataSimply(newData) {
  20889. for (var i = 0; i < newData.length; i++) {
  20890. this._data.push(newData[i]);
  20891. }
  20892. }
  20893. }();
  20894. return DefaultDataProvider;
  20895. }();
  20896. var validateSimply = function (rawData) {
  20897. if (!isArray(rawData)) {
  20898. error('series.data or dataset.source must be an array.');
  20899. }
  20900. };
  20901. /**
  20902. * Only run in dev mode - hint users for debug.
  20903. */
  20904. var rawSourceDataValidatorMap = (_a = {}, _a[SOURCE_FORMAT_ARRAY_ROWS + '_' + SERIES_LAYOUT_BY_COLUMN] = validateSimply, _a[SOURCE_FORMAT_ARRAY_ROWS + '_' + SERIES_LAYOUT_BY_ROW] = validateSimply, _a[SOURCE_FORMAT_OBJECT_ROWS] = validateSimply, _a[SOURCE_FORMAT_KEYED_COLUMNS] = function (rawData, dimsDef) {
  20905. for (var i = 0; i < dimsDef.length; i++) {
  20906. var dimName = dimsDef[i].name;
  20907. if (dimName == null) {
  20908. error('dimension name must not be null/undefined.');
  20909. }
  20910. }
  20911. }, _a[SOURCE_FORMAT_ORIGINAL] = validateSimply, _a);
  20912. var getItemSimply = function (rawData, startIndex, dimsDef, idx) {
  20913. return rawData[idx];
  20914. };
  20915. var rawSourceItemGetterMap = (_b = {}, _b[SOURCE_FORMAT_ARRAY_ROWS + '_' + SERIES_LAYOUT_BY_COLUMN] = function (rawData, startIndex, dimsDef, idx) {
  20916. return rawData[idx + startIndex];
  20917. }, _b[SOURCE_FORMAT_ARRAY_ROWS + '_' + SERIES_LAYOUT_BY_ROW] = function (rawData, startIndex, dimsDef, idx, out) {
  20918. idx += startIndex;
  20919. var item = out || [];
  20920. var data = rawData;
  20921. for (var i = 0; i < data.length; i++) {
  20922. var row = data[i];
  20923. item[i] = row ? row[idx] : null;
  20924. }
  20925. return item;
  20926. }, _b[SOURCE_FORMAT_OBJECT_ROWS] = getItemSimply, _b[SOURCE_FORMAT_KEYED_COLUMNS] = function (rawData, startIndex, dimsDef, idx, out) {
  20927. var item = out || [];
  20928. for (var i = 0; i < dimsDef.length; i++) {
  20929. var dimName = dimsDef[i].name;
  20930. var col = dimName != null ? rawData[dimName] : null;
  20931. item[i] = col ? col[idx] : null;
  20932. }
  20933. return item;
  20934. }, _b[SOURCE_FORMAT_ORIGINAL] = getItemSimply, _b);
  20935. function getRawSourceItemGetter(sourceFormat, seriesLayoutBy) {
  20936. var method = rawSourceItemGetterMap[getMethodMapKey(sourceFormat, seriesLayoutBy)];
  20937. if ("development" !== 'production') {
  20938. assert(method, 'Do not support get item on "' + sourceFormat + '", "' + seriesLayoutBy + '".');
  20939. }
  20940. return method;
  20941. }
  20942. var countSimply = function (rawData, startIndex, dimsDef) {
  20943. return rawData.length;
  20944. };
  20945. var rawSourceDataCounterMap = (_c = {}, _c[SOURCE_FORMAT_ARRAY_ROWS + '_' + SERIES_LAYOUT_BY_COLUMN] = function (rawData, startIndex, dimsDef) {
  20946. return Math.max(0, rawData.length - startIndex);
  20947. }, _c[SOURCE_FORMAT_ARRAY_ROWS + '_' + SERIES_LAYOUT_BY_ROW] = function (rawData, startIndex, dimsDef) {
  20948. var row = rawData[0];
  20949. return row ? Math.max(0, row.length - startIndex) : 0;
  20950. }, _c[SOURCE_FORMAT_OBJECT_ROWS] = countSimply, _c[SOURCE_FORMAT_KEYED_COLUMNS] = function (rawData, startIndex, dimsDef) {
  20951. var dimName = dimsDef[0].name;
  20952. var col = dimName != null ? rawData[dimName] : null;
  20953. return col ? col.length : 0;
  20954. }, _c[SOURCE_FORMAT_ORIGINAL] = countSimply, _c);
  20955. function getRawSourceDataCounter(sourceFormat, seriesLayoutBy) {
  20956. var method = rawSourceDataCounterMap[getMethodMapKey(sourceFormat, seriesLayoutBy)];
  20957. if ("development" !== 'production') {
  20958. assert(method, 'Do not support count on "' + sourceFormat + '", "' + seriesLayoutBy + '".');
  20959. }
  20960. return method;
  20961. }
  20962. var getRawValueSimply = function (dataItem, dimIndex, property) {
  20963. return dataItem[dimIndex];
  20964. };
  20965. var rawSourceValueGetterMap = (_d = {}, _d[SOURCE_FORMAT_ARRAY_ROWS] = getRawValueSimply, _d[SOURCE_FORMAT_OBJECT_ROWS] = function (dataItem, dimIndex, property) {
  20966. return dataItem[property];
  20967. }, _d[SOURCE_FORMAT_KEYED_COLUMNS] = getRawValueSimply, _d[SOURCE_FORMAT_ORIGINAL] = function (dataItem, dimIndex, property) {
  20968. // FIXME: In some case (markpoint in geo (geo-map.html)),
  20969. // dataItem is {coord: [...]}
  20970. var value = getDataItemValue(dataItem);
  20971. return !(value instanceof Array) ? value : value[dimIndex];
  20972. }, _d[SOURCE_FORMAT_TYPED_ARRAY] = getRawValueSimply, _d);
  20973. function getRawSourceValueGetter(sourceFormat) {
  20974. var method = rawSourceValueGetterMap[sourceFormat];
  20975. if ("development" !== 'production') {
  20976. assert(method, 'Do not support get value on "' + sourceFormat + '".');
  20977. }
  20978. return method;
  20979. }
  20980. function getMethodMapKey(sourceFormat, seriesLayoutBy) {
  20981. return sourceFormat === SOURCE_FORMAT_ARRAY_ROWS ? sourceFormat + '_' + seriesLayoutBy : sourceFormat;
  20982. }
  20983. // ??? FIXME can these logic be more neat: getRawValue, getRawDataItem,
  20984. // Consider persistent.
  20985. // Caution: why use raw value to display on label or tooltip?
  20986. // A reason is to avoid format. For example time value we do not know
  20987. // how to format is expected. More over, if stack is used, calculated
  20988. // value may be 0.91000000001, which have brings trouble to display.
  20989. // TODO: consider how to treat null/undefined/NaN when display?
  20990. function retrieveRawValue(data, dataIndex,
  20991. // If dimIndex is null/undefined, return OptionDataItem.
  20992. // Otherwise, return OptionDataValue.
  20993. dim) {
  20994. if (!data) {
  20995. return;
  20996. }
  20997. // Consider data may be not persistent.
  20998. var dataItem = data.getRawDataItem(dataIndex);
  20999. if (dataItem == null) {
  21000. return;
  21001. }
  21002. var store = data.getStore();
  21003. var sourceFormat = store.getSource().sourceFormat;
  21004. if (dim != null) {
  21005. var dimIndex = data.getDimensionIndex(dim);
  21006. var property = store.getDimensionProperty(dimIndex);
  21007. return getRawSourceValueGetter(sourceFormat)(dataItem, dimIndex, property);
  21008. } else {
  21009. var result = dataItem;
  21010. if (sourceFormat === SOURCE_FORMAT_ORIGINAL) {
  21011. result = getDataItemValue(dataItem);
  21012. }
  21013. return result;
  21014. }
  21015. }
  21016. var DIMENSION_LABEL_REG = /\{@(.+?)\}/g;
  21017. var DataFormatMixin = /** @class */function () {
  21018. function DataFormatMixin() {}
  21019. /**
  21020. * Get params for formatter
  21021. */
  21022. DataFormatMixin.prototype.getDataParams = function (dataIndex, dataType) {
  21023. var data = this.getData(dataType);
  21024. var rawValue = this.getRawValue(dataIndex, dataType);
  21025. var rawDataIndex = data.getRawIndex(dataIndex);
  21026. var name = data.getName(dataIndex);
  21027. var itemOpt = data.getRawDataItem(dataIndex);
  21028. var style = data.getItemVisual(dataIndex, 'style');
  21029. var color = style && style[data.getItemVisual(dataIndex, 'drawType') || 'fill'];
  21030. var borderColor = style && style.stroke;
  21031. var mainType = this.mainType;
  21032. var isSeries = mainType === 'series';
  21033. var userOutput = data.userOutput && data.userOutput.get();
  21034. return {
  21035. componentType: mainType,
  21036. componentSubType: this.subType,
  21037. componentIndex: this.componentIndex,
  21038. seriesType: isSeries ? this.subType : null,
  21039. seriesIndex: this.seriesIndex,
  21040. seriesId: isSeries ? this.id : null,
  21041. seriesName: isSeries ? this.name : null,
  21042. name: name,
  21043. dataIndex: rawDataIndex,
  21044. data: itemOpt,
  21045. dataType: dataType,
  21046. value: rawValue,
  21047. color: color,
  21048. borderColor: borderColor,
  21049. dimensionNames: userOutput ? userOutput.fullDimensions : null,
  21050. encode: userOutput ? userOutput.encode : null,
  21051. // Param name list for mapping `a`, `b`, `c`, `d`, `e`
  21052. $vars: ['seriesName', 'name', 'value']
  21053. };
  21054. };
  21055. /**
  21056. * Format label
  21057. * @param dataIndex
  21058. * @param status 'normal' by default
  21059. * @param dataType
  21060. * @param labelDimIndex Only used in some chart that
  21061. * use formatter in different dimensions, like radar.
  21062. * @param formatter Formatter given outside.
  21063. * @return return null/undefined if no formatter
  21064. */
  21065. DataFormatMixin.prototype.getFormattedLabel = function (dataIndex, status, dataType, labelDimIndex, formatter, extendParams) {
  21066. status = status || 'normal';
  21067. var data = this.getData(dataType);
  21068. var params = this.getDataParams(dataIndex, dataType);
  21069. if (extendParams) {
  21070. params.value = extendParams.interpolatedValue;
  21071. }
  21072. if (labelDimIndex != null && isArray(params.value)) {
  21073. params.value = params.value[labelDimIndex];
  21074. }
  21075. if (!formatter) {
  21076. var itemModel = data.getItemModel(dataIndex);
  21077. // @ts-ignore
  21078. formatter = itemModel.get(status === 'normal' ? ['label', 'formatter'] : [status, 'label', 'formatter']);
  21079. }
  21080. if (isFunction(formatter)) {
  21081. params.status = status;
  21082. params.dimensionIndex = labelDimIndex;
  21083. return formatter(params);
  21084. } else if (isString(formatter)) {
  21085. var str = formatTpl(formatter, params);
  21086. // Support 'aaa{@[3]}bbb{@product}ccc'.
  21087. // Do not support '}' in dim name util have to.
  21088. return str.replace(DIMENSION_LABEL_REG, function (origin, dimStr) {
  21089. var len = dimStr.length;
  21090. var dimLoose = dimStr;
  21091. if (dimLoose.charAt(0) === '[' && dimLoose.charAt(len - 1) === ']') {
  21092. dimLoose = +dimLoose.slice(1, len - 1); // Also support: '[]' => 0
  21093. if ("development" !== 'production') {
  21094. if (isNaN(dimLoose)) {
  21095. error("Invalide label formatter: @" + dimStr + ", only support @[0], @[1], @[2], ...");
  21096. }
  21097. }
  21098. }
  21099. var val = retrieveRawValue(data, dataIndex, dimLoose);
  21100. if (extendParams && isArray(extendParams.interpolatedValue)) {
  21101. var dimIndex = data.getDimensionIndex(dimLoose);
  21102. if (dimIndex >= 0) {
  21103. val = extendParams.interpolatedValue[dimIndex];
  21104. }
  21105. }
  21106. return val != null ? val + '' : '';
  21107. });
  21108. }
  21109. };
  21110. /**
  21111. * Get raw value in option
  21112. */
  21113. DataFormatMixin.prototype.getRawValue = function (idx, dataType) {
  21114. return retrieveRawValue(this.getData(dataType), idx);
  21115. };
  21116. /**
  21117. * Should be implemented.
  21118. * @param {number} dataIndex
  21119. * @param {boolean} [multipleSeries=false]
  21120. * @param {string} [dataType]
  21121. */
  21122. DataFormatMixin.prototype.formatTooltip = function (dataIndex, multipleSeries, dataType) {
  21123. // Empty function
  21124. return;
  21125. };
  21126. return DataFormatMixin;
  21127. }();
  21128. // PENDING: previously we accept this type when calling `formatTooltip`,
  21129. // but guess little chance has been used outside. Do we need to backward
  21130. // compat it?
  21131. // type TooltipFormatResultLegacyObject = {
  21132. // // `html` means the markup language text, either in 'html' or 'richText'.
  21133. // // The name `html` is not appropriate because in 'richText' it is not a HTML
  21134. // // string. But still support it for backward compatibility.
  21135. // html: string;
  21136. // markers: Dictionary<ColorString>;
  21137. // };
  21138. /**
  21139. * For backward compat, normalize the return from `formatTooltip`.
  21140. */
  21141. function normalizeTooltipFormatResult(result) {
  21142. var markupText;
  21143. // let markers: Dictionary<ColorString>;
  21144. var markupFragment;
  21145. if (isObject(result)) {
  21146. if (result.type) {
  21147. markupFragment = result;
  21148. } else {
  21149. if ("development" !== 'production') {
  21150. console.warn('The return type of `formatTooltip` is not supported: ' + makePrintable(result));
  21151. }
  21152. }
  21153. // else {
  21154. // markupText = (result as TooltipFormatResultLegacyObject).html;
  21155. // markers = (result as TooltipFormatResultLegacyObject).markers;
  21156. // if (markersExisting) {
  21157. // markers = zrUtil.merge(markersExisting, markers);
  21158. // }
  21159. // }
  21160. } else {
  21161. markupText = result;
  21162. }
  21163. return {
  21164. text: markupText,
  21165. // markers: markers || markersExisting,
  21166. frag: markupFragment
  21167. };
  21168. }
  21169. /**
  21170. * @param {Object} define
  21171. * @return See the return of `createTask`.
  21172. */
  21173. function createTask(define) {
  21174. return new Task(define);
  21175. }
  21176. var Task = /** @class */function () {
  21177. function Task(define) {
  21178. define = define || {};
  21179. this._reset = define.reset;
  21180. this._plan = define.plan;
  21181. this._count = define.count;
  21182. this._onDirty = define.onDirty;
  21183. this._dirty = true;
  21184. }
  21185. /**
  21186. * @param step Specified step.
  21187. * @param skip Skip customer perform call.
  21188. * @param modBy Sampling window size.
  21189. * @param modDataCount Sampling count.
  21190. * @return whether unfinished.
  21191. */
  21192. Task.prototype.perform = function (performArgs) {
  21193. var upTask = this._upstream;
  21194. var skip = performArgs && performArgs.skip;
  21195. // TODO some refactor.
  21196. // Pull data. Must pull data each time, because context.data
  21197. // may be updated by Series.setData.
  21198. if (this._dirty && upTask) {
  21199. var context = this.context;
  21200. context.data = context.outputData = upTask.context.outputData;
  21201. }
  21202. if (this.__pipeline) {
  21203. this.__pipeline.currentTask = this;
  21204. }
  21205. var planResult;
  21206. if (this._plan && !skip) {
  21207. planResult = this._plan(this.context);
  21208. }
  21209. // Support sharding by mod, which changes the render sequence and makes the rendered graphic
  21210. // elements uniformed distributed when progress, especially when moving or zooming.
  21211. var lastModBy = normalizeModBy(this._modBy);
  21212. var lastModDataCount = this._modDataCount || 0;
  21213. var modBy = normalizeModBy(performArgs && performArgs.modBy);
  21214. var modDataCount = performArgs && performArgs.modDataCount || 0;
  21215. if (lastModBy !== modBy || lastModDataCount !== modDataCount) {
  21216. planResult = 'reset';
  21217. }
  21218. function normalizeModBy(val) {
  21219. !(val >= 1) && (val = 1); // jshint ignore:line
  21220. return val;
  21221. }
  21222. var forceFirstProgress;
  21223. if (this._dirty || planResult === 'reset') {
  21224. this._dirty = false;
  21225. forceFirstProgress = this._doReset(skip);
  21226. }
  21227. this._modBy = modBy;
  21228. this._modDataCount = modDataCount;
  21229. var step = performArgs && performArgs.step;
  21230. if (upTask) {
  21231. if ("development" !== 'production') {
  21232. assert(upTask._outputDueEnd != null);
  21233. }
  21234. this._dueEnd = upTask._outputDueEnd;
  21235. }
  21236. // DataTask or overallTask
  21237. else {
  21238. if ("development" !== 'production') {
  21239. assert(!this._progress || this._count);
  21240. }
  21241. this._dueEnd = this._count ? this._count(this.context) : Infinity;
  21242. }
  21243. // Note: Stubs, that its host overall task let it has progress, has progress.
  21244. // If no progress, pass index from upstream to downstream each time plan called.
  21245. if (this._progress) {
  21246. var start = this._dueIndex;
  21247. var end = Math.min(step != null ? this._dueIndex + step : Infinity, this._dueEnd);
  21248. if (!skip && (forceFirstProgress || start < end)) {
  21249. var progress = this._progress;
  21250. if (isArray(progress)) {
  21251. for (var i = 0; i < progress.length; i++) {
  21252. this._doProgress(progress[i], start, end, modBy, modDataCount);
  21253. }
  21254. } else {
  21255. this._doProgress(progress, start, end, modBy, modDataCount);
  21256. }
  21257. }
  21258. this._dueIndex = end;
  21259. // If no `outputDueEnd`, assume that output data and
  21260. // input data is the same, so use `dueIndex` as `outputDueEnd`.
  21261. var outputDueEnd = this._settedOutputEnd != null ? this._settedOutputEnd : end;
  21262. if ("development" !== 'production') {
  21263. // ??? Can not rollback.
  21264. assert(outputDueEnd >= this._outputDueEnd);
  21265. }
  21266. this._outputDueEnd = outputDueEnd;
  21267. } else {
  21268. // (1) Some overall task has no progress.
  21269. // (2) Stubs, that its host overall task do not let it has progress, has no progress.
  21270. // This should always be performed so it can be passed to downstream.
  21271. this._dueIndex = this._outputDueEnd = this._settedOutputEnd != null ? this._settedOutputEnd : this._dueEnd;
  21272. }
  21273. return this.unfinished();
  21274. };
  21275. Task.prototype.dirty = function () {
  21276. this._dirty = true;
  21277. this._onDirty && this._onDirty(this.context);
  21278. };
  21279. Task.prototype._doProgress = function (progress, start, end, modBy, modDataCount) {
  21280. iterator.reset(start, end, modBy, modDataCount);
  21281. this._callingProgress = progress;
  21282. this._callingProgress({
  21283. start: start,
  21284. end: end,
  21285. count: end - start,
  21286. next: iterator.next
  21287. }, this.context);
  21288. };
  21289. Task.prototype._doReset = function (skip) {
  21290. this._dueIndex = this._outputDueEnd = this._dueEnd = 0;
  21291. this._settedOutputEnd = null;
  21292. var progress;
  21293. var forceFirstProgress;
  21294. if (!skip && this._reset) {
  21295. progress = this._reset(this.context);
  21296. if (progress && progress.progress) {
  21297. forceFirstProgress = progress.forceFirstProgress;
  21298. progress = progress.progress;
  21299. }
  21300. // To simplify no progress checking, array must has item.
  21301. if (isArray(progress) && !progress.length) {
  21302. progress = null;
  21303. }
  21304. }
  21305. this._progress = progress;
  21306. this._modBy = this._modDataCount = null;
  21307. var downstream = this._downstream;
  21308. downstream && downstream.dirty();
  21309. return forceFirstProgress;
  21310. };
  21311. Task.prototype.unfinished = function () {
  21312. return this._progress && this._dueIndex < this._dueEnd;
  21313. };
  21314. /**
  21315. * @param downTask The downstream task.
  21316. * @return The downstream task.
  21317. */
  21318. Task.prototype.pipe = function (downTask) {
  21319. if ("development" !== 'production') {
  21320. assert(downTask && !downTask._disposed && downTask !== this);
  21321. }
  21322. // If already downstream, do not dirty downTask.
  21323. if (this._downstream !== downTask || this._dirty) {
  21324. this._downstream = downTask;
  21325. downTask._upstream = this;
  21326. downTask.dirty();
  21327. }
  21328. };
  21329. Task.prototype.dispose = function () {
  21330. if (this._disposed) {
  21331. return;
  21332. }
  21333. this._upstream && (this._upstream._downstream = null);
  21334. this._downstream && (this._downstream._upstream = null);
  21335. this._dirty = false;
  21336. this._disposed = true;
  21337. };
  21338. Task.prototype.getUpstream = function () {
  21339. return this._upstream;
  21340. };
  21341. Task.prototype.getDownstream = function () {
  21342. return this._downstream;
  21343. };
  21344. Task.prototype.setOutputEnd = function (end) {
  21345. // This only happens in dataTask, dataZoom, map, currently.
  21346. // where dataZoom do not set end each time, but only set
  21347. // when reset. So we should record the set end, in case
  21348. // that the stub of dataZoom perform again and earse the
  21349. // set end by upstream.
  21350. this._outputDueEnd = this._settedOutputEnd = end;
  21351. };
  21352. return Task;
  21353. }();
  21354. var iterator = function () {
  21355. var end;
  21356. var current;
  21357. var modBy;
  21358. var modDataCount;
  21359. var winCount;
  21360. var it = {
  21361. reset: function (s, e, sStep, sCount) {
  21362. current = s;
  21363. end = e;
  21364. modBy = sStep;
  21365. modDataCount = sCount;
  21366. winCount = Math.ceil(modDataCount / modBy);
  21367. it.next = modBy > 1 && modDataCount > 0 ? modNext : sequentialNext;
  21368. }
  21369. };
  21370. return it;
  21371. function sequentialNext() {
  21372. return current < end ? current++ : null;
  21373. }
  21374. function modNext() {
  21375. var dataIndex = current % winCount * modBy + Math.ceil(current / winCount);
  21376. var result = current >= end ? null : dataIndex < modDataCount ? dataIndex
  21377. // If modDataCount is smaller than data.count() (consider `appendData` case),
  21378. // Use normal linear rendering mode.
  21379. : current;
  21380. current++;
  21381. return result;
  21382. }
  21383. }();
  21384. // -----------------------------------------------------------------------------
  21385. // For stream debug (Should be commented out after used!)
  21386. // @usage: printTask(this, 'begin');
  21387. // @usage: printTask(this, null, {someExtraProp});
  21388. // @usage: Use `__idxInPipeline` as conditional breakpiont.
  21389. //
  21390. // window.printTask = function (task: any, prefix: string, extra: { [key: string]: unknown }): void {
  21391. // window.ecTaskUID == null && (window.ecTaskUID = 0);
  21392. // task.uidDebug == null && (task.uidDebug = `task_${window.ecTaskUID++}`);
  21393. // task.agent && task.agent.uidDebug == null && (task.agent.uidDebug = `task_${window.ecTaskUID++}`);
  21394. // let props = [];
  21395. // if (task.__pipeline) {
  21396. // let val = `${task.__idxInPipeline}/${task.__pipeline.tail.__idxInPipeline} ${task.agent ? '(stub)' : ''}`;
  21397. // props.push({text: '__idxInPipeline/total', value: val});
  21398. // } else {
  21399. // let stubCount = 0;
  21400. // task.agentStubMap.each(() => stubCount++);
  21401. // props.push({text: 'idx', value: `overall (stubs: ${stubCount})`});
  21402. // }
  21403. // props.push({text: 'uid', value: task.uidDebug});
  21404. // if (task.__pipeline) {
  21405. // props.push({text: 'pipelineId', value: task.__pipeline.id});
  21406. // task.agent && props.push(
  21407. // {text: 'stubFor', value: task.agent.uidDebug}
  21408. // );
  21409. // }
  21410. // props.push(
  21411. // {text: 'dirty', value: task._dirty},
  21412. // {text: 'dueIndex', value: task._dueIndex},
  21413. // {text: 'dueEnd', value: task._dueEnd},
  21414. // {text: 'outputDueEnd', value: task._outputDueEnd}
  21415. // );
  21416. // if (extra) {
  21417. // Object.keys(extra).forEach(key => {
  21418. // props.push({text: key, value: extra[key]});
  21419. // });
  21420. // }
  21421. // let args = ['color: blue'];
  21422. // let msg = `%c[${prefix || 'T'}] %c` + props.map(item => (
  21423. // args.push('color: green', 'color: red'),
  21424. // `${item.text}: %c${item.value}`
  21425. // )).join('%c, ');
  21426. // console.log.apply(console, [msg].concat(args));
  21427. // // console.log(this);
  21428. // };
  21429. // window.printPipeline = function (task: any, prefix: string) {
  21430. // const pipeline = task.__pipeline;
  21431. // let currTask = pipeline.head;
  21432. // while (currTask) {
  21433. // window.printTask(currTask, prefix);
  21434. // currTask = currTask._downstream;
  21435. // }
  21436. // };
  21437. // window.showChain = function (chainHeadTask) {
  21438. // var chain = [];
  21439. // var task = chainHeadTask;
  21440. // while (task) {
  21441. // chain.push({
  21442. // task: task,
  21443. // up: task._upstream,
  21444. // down: task._downstream,
  21445. // idxInPipeline: task.__idxInPipeline
  21446. // });
  21447. // task = task._downstream;
  21448. // }
  21449. // return chain;
  21450. // };
  21451. // window.findTaskInChain = function (task, chainHeadTask) {
  21452. // let chain = window.showChain(chainHeadTask);
  21453. // let result = [];
  21454. // for (let i = 0; i < chain.length; i++) {
  21455. // let chainItem = chain[i];
  21456. // if (chainItem.task === task) {
  21457. // result.push(i);
  21458. // }
  21459. // }
  21460. // return result;
  21461. // };
  21462. // window.printChainAEachInChainB = function (chainHeadTaskA, chainHeadTaskB) {
  21463. // let chainA = window.showChain(chainHeadTaskA);
  21464. // for (let i = 0; i < chainA.length; i++) {
  21465. // console.log('chainAIdx:', i, 'inChainB:', window.findTaskInChain(chainA[i].task, chainHeadTaskB));
  21466. // }
  21467. // };
  21468. /**
  21469. * Convert raw the value in to inner value in List.
  21470. *
  21471. * [Performance sensitive]
  21472. *
  21473. * [Caution]: this is the key logic of user value parser.
  21474. * For backward compatibility, do not modify it until you have to!
  21475. */
  21476. function parseDataValue(value,
  21477. // For high performance, do not omit the second param.
  21478. opt) {
  21479. // Performance sensitive.
  21480. var dimType = opt && opt.type;
  21481. if (dimType === 'ordinal') {
  21482. // If given value is a category string
  21483. return value;
  21484. }
  21485. if (dimType === 'time'
  21486. // spead up when using timestamp
  21487. && !isNumber(value) && value != null && value !== '-') {
  21488. value = +parseDate(value);
  21489. }
  21490. // dimType defaults 'number'.
  21491. // If dimType is not ordinal and value is null or undefined or NaN or '-',
  21492. // parse to NaN.
  21493. // number-like string (like ' 123 ') can be converted to a number.
  21494. // where null/undefined or other string will be converted to NaN.
  21495. return value == null || value === '' ? NaN
  21496. // If string (like '-'), using '+' parse to NaN
  21497. // If object, also parse to NaN
  21498. : Number(value);
  21499. }
  21500. var valueParserMap = createHashMap({
  21501. 'number': function (val) {
  21502. // Do not use `numericToNumber` here. We have `numericToNumber` by default.
  21503. // Here the number parser can have loose rule:
  21504. // enable to cut suffix: "120px" => 120, "14%" => 14.
  21505. return parseFloat(val);
  21506. },
  21507. 'time': function (val) {
  21508. // return timestamp.
  21509. return +parseDate(val);
  21510. },
  21511. 'trim': function (val) {
  21512. return isString(val) ? trim(val) : val;
  21513. }
  21514. });
  21515. function getRawValueParser(type) {
  21516. return valueParserMap.get(type);
  21517. }
  21518. var ORDER_COMPARISON_OP_MAP = {
  21519. lt: function (lval, rval) {
  21520. return lval < rval;
  21521. },
  21522. lte: function (lval, rval) {
  21523. return lval <= rval;
  21524. },
  21525. gt: function (lval, rval) {
  21526. return lval > rval;
  21527. },
  21528. gte: function (lval, rval) {
  21529. return lval >= rval;
  21530. }
  21531. };
  21532. var FilterOrderComparator = /** @class */function () {
  21533. function FilterOrderComparator(op, rval) {
  21534. if (!isNumber(rval)) {
  21535. var errMsg = '';
  21536. if ("development" !== 'production') {
  21537. errMsg = 'rvalue of "<", ">", "<=", ">=" can only be number in filter.';
  21538. }
  21539. throwError(errMsg);
  21540. }
  21541. this._opFn = ORDER_COMPARISON_OP_MAP[op];
  21542. this._rvalFloat = numericToNumber(rval);
  21543. }
  21544. // Performance sensitive.
  21545. FilterOrderComparator.prototype.evaluate = function (lval) {
  21546. // Most cases is 'number', and typeof maybe 10 times faseter than parseFloat.
  21547. return isNumber(lval) ? this._opFn(lval, this._rvalFloat) : this._opFn(numericToNumber(lval), this._rvalFloat);
  21548. };
  21549. return FilterOrderComparator;
  21550. }();
  21551. var SortOrderComparator = /** @class */function () {
  21552. /**
  21553. * @param order by default: 'asc'
  21554. * @param incomparable by default: Always on the tail.
  21555. * That is, if 'asc' => 'max', if 'desc' => 'min'
  21556. * See the definition of "incomparable" in [SORT_COMPARISON_RULE].
  21557. */
  21558. function SortOrderComparator(order, incomparable) {
  21559. var isDesc = order === 'desc';
  21560. this._resultLT = isDesc ? 1 : -1;
  21561. if (incomparable == null) {
  21562. incomparable = isDesc ? 'min' : 'max';
  21563. }
  21564. this._incomparable = incomparable === 'min' ? -Infinity : Infinity;
  21565. }
  21566. // See [SORT_COMPARISON_RULE].
  21567. // Performance sensitive.
  21568. SortOrderComparator.prototype.evaluate = function (lval, rval) {
  21569. // Most cases is 'number', and typeof maybe 10 times faseter than parseFloat.
  21570. var lvalFloat = isNumber(lval) ? lval : numericToNumber(lval);
  21571. var rvalFloat = isNumber(rval) ? rval : numericToNumber(rval);
  21572. var lvalNotNumeric = isNaN(lvalFloat);
  21573. var rvalNotNumeric = isNaN(rvalFloat);
  21574. if (lvalNotNumeric) {
  21575. lvalFloat = this._incomparable;
  21576. }
  21577. if (rvalNotNumeric) {
  21578. rvalFloat = this._incomparable;
  21579. }
  21580. if (lvalNotNumeric && rvalNotNumeric) {
  21581. var lvalIsStr = isString(lval);
  21582. var rvalIsStr = isString(rval);
  21583. if (lvalIsStr) {
  21584. lvalFloat = rvalIsStr ? lval : 0;
  21585. }
  21586. if (rvalIsStr) {
  21587. rvalFloat = lvalIsStr ? rval : 0;
  21588. }
  21589. }
  21590. return lvalFloat < rvalFloat ? this._resultLT : lvalFloat > rvalFloat ? -this._resultLT : 0;
  21591. };
  21592. return SortOrderComparator;
  21593. }();
  21594. var FilterEqualityComparator = /** @class */function () {
  21595. function FilterEqualityComparator(isEq, rval) {
  21596. this._rval = rval;
  21597. this._isEQ = isEq;
  21598. this._rvalTypeof = typeof rval;
  21599. this._rvalFloat = numericToNumber(rval);
  21600. }
  21601. // Performance sensitive.
  21602. FilterEqualityComparator.prototype.evaluate = function (lval) {
  21603. var eqResult = lval === this._rval;
  21604. if (!eqResult) {
  21605. var lvalTypeof = typeof lval;
  21606. if (lvalTypeof !== this._rvalTypeof && (lvalTypeof === 'number' || this._rvalTypeof === 'number')) {
  21607. eqResult = numericToNumber(lval) === this._rvalFloat;
  21608. }
  21609. }
  21610. return this._isEQ ? eqResult : !eqResult;
  21611. };
  21612. return FilterEqualityComparator;
  21613. }();
  21614. /**
  21615. * [FILTER_COMPARISON_RULE]
  21616. * `lt`|`lte`|`gt`|`gte`:
  21617. * + rval must be a number. And lval will be converted to number (`numericToNumber`) to compare.
  21618. * `eq`:
  21619. * + If same type, compare with `===`.
  21620. * + If there is one number, convert to number (`numericToNumber`) to compare.
  21621. * + Else return `false`.
  21622. * `ne`:
  21623. * + Not `eq`.
  21624. *
  21625. *
  21626. * [SORT_COMPARISON_RULE]
  21627. * All the values are grouped into three categories:
  21628. * + "numeric" (number and numeric string)
  21629. * + "non-numeric-string" (string that excluding numeric string)
  21630. * + "others"
  21631. * "numeric" vs "numeric": values are ordered by number order.
  21632. * "non-numeric-string" vs "non-numeric-string": values are ordered by ES spec (#sec-abstract-relational-comparison).
  21633. * "others" vs "others": do not change order (always return 0).
  21634. * "numeric" vs "non-numeric-string": "non-numeric-string" is treated as "incomparable".
  21635. * "number" vs "others": "others" is treated as "incomparable".
  21636. * "non-numeric-string" vs "others": "others" is treated as "incomparable".
  21637. * "incomparable" will be seen as -Infinity or Infinity (depends on the settings).
  21638. * MEMO:
  21639. * Non-numeric string sort makes sense when we need to put the items with the same tag together.
  21640. * But if we support string sort, we still need to avoid the misleading like `'2' > '12'`,
  21641. * So we treat "numeric-string" sorted by number order rather than string comparison.
  21642. *
  21643. *
  21644. * [CHECK_LIST_OF_THE_RULE_DESIGN]
  21645. * + Do not support string comparison until required. And also need to
  21646. * avoid the misleading of "2" > "12".
  21647. * + Should avoid the misleading case:
  21648. * `" 22 " gte "22"` is `true` but `" 22 " eq "22"` is `false`.
  21649. * + JS bad case should be avoided: null <= 0, [] <= 0, ' ' <= 0, ...
  21650. * + Only "numeric" can be converted to comparable number, otherwise converted to NaN.
  21651. * See `util/number.ts#numericToNumber`.
  21652. *
  21653. * @return If `op` is not `RelationalOperator`, return null;
  21654. */
  21655. function createFilterComparator(op, rval) {
  21656. return op === 'eq' || op === 'ne' ? new FilterEqualityComparator(op === 'eq', rval) : hasOwn(ORDER_COMPARISON_OP_MAP, op) ? new FilterOrderComparator(op, rval) : null;
  21657. }
  21658. /**
  21659. * TODO: disable writable.
  21660. * This structure will be exposed to users.
  21661. */
  21662. var ExternalSource = /** @class */function () {
  21663. function ExternalSource() {}
  21664. ExternalSource.prototype.getRawData = function () {
  21665. // Only built-in transform available.
  21666. throw new Error('not supported');
  21667. };
  21668. ExternalSource.prototype.getRawDataItem = function (dataIndex) {
  21669. // Only built-in transform available.
  21670. throw new Error('not supported');
  21671. };
  21672. ExternalSource.prototype.cloneRawData = function () {
  21673. return;
  21674. };
  21675. /**
  21676. * @return If dimension not found, return null/undefined.
  21677. */
  21678. ExternalSource.prototype.getDimensionInfo = function (dim) {
  21679. return;
  21680. };
  21681. /**
  21682. * dimensions defined if and only if either:
  21683. * (a) dataset.dimensions are declared.
  21684. * (b) dataset data include dimensions definitions in data (detected or via specified `sourceHeader`).
  21685. * If dimensions are defined, `dimensionInfoAll` is corresponding to
  21686. * the defined dimensions.
  21687. * Otherwise, `dimensionInfoAll` is determined by data columns.
  21688. * @return Always return an array (even empty array).
  21689. */
  21690. ExternalSource.prototype.cloneAllDimensionInfo = function () {
  21691. return;
  21692. };
  21693. ExternalSource.prototype.count = function () {
  21694. return;
  21695. };
  21696. /**
  21697. * Only support by dimension index.
  21698. * No need to support by dimension name in transform function,
  21699. * because transform function is not case-specific, no need to use name literally.
  21700. */
  21701. ExternalSource.prototype.retrieveValue = function (dataIndex, dimIndex) {
  21702. return;
  21703. };
  21704. ExternalSource.prototype.retrieveValueFromItem = function (dataItem, dimIndex) {
  21705. return;
  21706. };
  21707. ExternalSource.prototype.convertValue = function (rawVal, dimInfo) {
  21708. return parseDataValue(rawVal, dimInfo);
  21709. };
  21710. return ExternalSource;
  21711. }();
  21712. function createExternalSource(internalSource, externalTransform) {
  21713. var extSource = new ExternalSource();
  21714. var data = internalSource.data;
  21715. var sourceFormat = extSource.sourceFormat = internalSource.sourceFormat;
  21716. var sourceHeaderCount = internalSource.startIndex;
  21717. var errMsg = '';
  21718. if (internalSource.seriesLayoutBy !== SERIES_LAYOUT_BY_COLUMN) {
  21719. // For the logic simplicity in transformer, only 'culumn' is
  21720. // supported in data transform. Otherwise, the `dimensionsDefine`
  21721. // might be detected by 'row', which probably confuses users.
  21722. if ("development" !== 'production') {
  21723. errMsg = '`seriesLayoutBy` of upstream dataset can only be "column" in data transform.';
  21724. }
  21725. throwError(errMsg);
  21726. }
  21727. // [MEMO]
  21728. // Create a new dimensions structure for exposing.
  21729. // Do not expose all dimension info to users directly.
  21730. // Because the dimension is probably auto detected from data and not might reliable.
  21731. // Should not lead the transformers to think that is reliable and return it.
  21732. // See [DIMENSION_INHERIT_RULE] in `sourceManager.ts`.
  21733. var dimensions = [];
  21734. var dimsByName = {};
  21735. var dimsDef = internalSource.dimensionsDefine;
  21736. if (dimsDef) {
  21737. each(dimsDef, function (dimDef, idx) {
  21738. var name = dimDef.name;
  21739. var dimDefExt = {
  21740. index: idx,
  21741. name: name,
  21742. displayName: dimDef.displayName
  21743. };
  21744. dimensions.push(dimDefExt);
  21745. // Users probably do not specify dimension name. For simplicity, data transform
  21746. // does not generate dimension name.
  21747. if (name != null) {
  21748. // Dimension name should not be duplicated.
  21749. // For simplicity, data transform forbids name duplication, do not generate
  21750. // new name like module `completeDimensions.ts` did, but just tell users.
  21751. var errMsg_1 = '';
  21752. if (hasOwn(dimsByName, name)) {
  21753. if ("development" !== 'production') {
  21754. errMsg_1 = 'dimension name "' + name + '" duplicated.';
  21755. }
  21756. throwError(errMsg_1);
  21757. }
  21758. dimsByName[name] = dimDefExt;
  21759. }
  21760. });
  21761. }
  21762. // If dimension definitions are not defined and can not be detected.
  21763. // e.g., pure data `[[11, 22], ...]`.
  21764. else {
  21765. for (var i = 0; i < internalSource.dimensionsDetectedCount || 0; i++) {
  21766. // Do not generete name or anything others. The consequence process in
  21767. // `transform` or `series` probably have there own name generation strategry.
  21768. dimensions.push({
  21769. index: i
  21770. });
  21771. }
  21772. }
  21773. // Implement public methods:
  21774. var rawItemGetter = getRawSourceItemGetter(sourceFormat, SERIES_LAYOUT_BY_COLUMN);
  21775. if (externalTransform.__isBuiltIn) {
  21776. extSource.getRawDataItem = function (dataIndex) {
  21777. return rawItemGetter(data, sourceHeaderCount, dimensions, dataIndex);
  21778. };
  21779. extSource.getRawData = bind(getRawData, null, internalSource);
  21780. }
  21781. extSource.cloneRawData = bind(cloneRawData, null, internalSource);
  21782. var rawCounter = getRawSourceDataCounter(sourceFormat, SERIES_LAYOUT_BY_COLUMN);
  21783. extSource.count = bind(rawCounter, null, data, sourceHeaderCount, dimensions);
  21784. var rawValueGetter = getRawSourceValueGetter(sourceFormat);
  21785. extSource.retrieveValue = function (dataIndex, dimIndex) {
  21786. var rawItem = rawItemGetter(data, sourceHeaderCount, dimensions, dataIndex);
  21787. return retrieveValueFromItem(rawItem, dimIndex);
  21788. };
  21789. var retrieveValueFromItem = extSource.retrieveValueFromItem = function (dataItem, dimIndex) {
  21790. if (dataItem == null) {
  21791. return;
  21792. }
  21793. var dimDef = dimensions[dimIndex];
  21794. // When `dimIndex` is `null`, `rawValueGetter` return the whole item.
  21795. if (dimDef) {
  21796. return rawValueGetter(dataItem, dimIndex, dimDef.name);
  21797. }
  21798. };
  21799. extSource.getDimensionInfo = bind(getDimensionInfo, null, dimensions, dimsByName);
  21800. extSource.cloneAllDimensionInfo = bind(cloneAllDimensionInfo, null, dimensions);
  21801. return extSource;
  21802. }
  21803. function getRawData(upstream) {
  21804. var sourceFormat = upstream.sourceFormat;
  21805. if (!isSupportedSourceFormat(sourceFormat)) {
  21806. var errMsg = '';
  21807. if ("development" !== 'production') {
  21808. errMsg = '`getRawData` is not supported in source format ' + sourceFormat;
  21809. }
  21810. throwError(errMsg);
  21811. }
  21812. return upstream.data;
  21813. }
  21814. function cloneRawData(upstream) {
  21815. var sourceFormat = upstream.sourceFormat;
  21816. var data = upstream.data;
  21817. if (!isSupportedSourceFormat(sourceFormat)) {
  21818. var errMsg = '';
  21819. if ("development" !== 'production') {
  21820. errMsg = '`cloneRawData` is not supported in source format ' + sourceFormat;
  21821. }
  21822. throwError(errMsg);
  21823. }
  21824. if (sourceFormat === SOURCE_FORMAT_ARRAY_ROWS) {
  21825. var result = [];
  21826. for (var i = 0, len = data.length; i < len; i++) {
  21827. // Not strictly clone for performance
  21828. result.push(data[i].slice());
  21829. }
  21830. return result;
  21831. } else if (sourceFormat === SOURCE_FORMAT_OBJECT_ROWS) {
  21832. var result = [];
  21833. for (var i = 0, len = data.length; i < len; i++) {
  21834. // Not strictly clone for performance
  21835. result.push(extend({}, data[i]));
  21836. }
  21837. return result;
  21838. }
  21839. }
  21840. function getDimensionInfo(dimensions, dimsByName, dim) {
  21841. if (dim == null) {
  21842. return;
  21843. }
  21844. // Keep the same logic as `List::getDimension` did.
  21845. if (isNumber(dim)
  21846. // If being a number-like string but not being defined a dimension name.
  21847. || !isNaN(dim) && !hasOwn(dimsByName, dim)) {
  21848. return dimensions[dim];
  21849. } else if (hasOwn(dimsByName, dim)) {
  21850. return dimsByName[dim];
  21851. }
  21852. }
  21853. function cloneAllDimensionInfo(dimensions) {
  21854. return clone(dimensions);
  21855. }
  21856. var externalTransformMap = createHashMap();
  21857. function registerExternalTransform(externalTransform) {
  21858. externalTransform = clone(externalTransform);
  21859. var type = externalTransform.type;
  21860. var errMsg = '';
  21861. if (!type) {
  21862. if ("development" !== 'production') {
  21863. errMsg = 'Must have a `type` when `registerTransform`.';
  21864. }
  21865. throwError(errMsg);
  21866. }
  21867. var typeParsed = type.split(':');
  21868. if (typeParsed.length !== 2) {
  21869. if ("development" !== 'production') {
  21870. errMsg = 'Name must include namespace like "ns:regression".';
  21871. }
  21872. throwError(errMsg);
  21873. }
  21874. // Namespace 'echarts:xxx' is official namespace, where the transforms should
  21875. // be called directly via 'xxx' rather than 'echarts:xxx'.
  21876. var isBuiltIn = false;
  21877. if (typeParsed[0] === 'echarts') {
  21878. type = typeParsed[1];
  21879. isBuiltIn = true;
  21880. }
  21881. externalTransform.__isBuiltIn = isBuiltIn;
  21882. externalTransformMap.set(type, externalTransform);
  21883. }
  21884. function applyDataTransform(rawTransOption, sourceList, infoForPrint) {
  21885. var pipedTransOption = normalizeToArray(rawTransOption);
  21886. var pipeLen = pipedTransOption.length;
  21887. var errMsg = '';
  21888. if (!pipeLen) {
  21889. if ("development" !== 'production') {
  21890. errMsg = 'If `transform` declared, it should at least contain one transform.';
  21891. }
  21892. throwError(errMsg);
  21893. }
  21894. for (var i = 0, len = pipeLen; i < len; i++) {
  21895. var transOption = pipedTransOption[i];
  21896. sourceList = applySingleDataTransform(transOption, sourceList, infoForPrint, pipeLen === 1 ? null : i);
  21897. // piped transform only support single input, except the fist one.
  21898. // piped transform only support single output, except the last one.
  21899. if (i !== len - 1) {
  21900. sourceList.length = Math.max(sourceList.length, 1);
  21901. }
  21902. }
  21903. return sourceList;
  21904. }
  21905. function applySingleDataTransform(transOption, upSourceList, infoForPrint,
  21906. // If `pipeIndex` is null/undefined, no piped transform.
  21907. pipeIndex) {
  21908. var errMsg = '';
  21909. if (!upSourceList.length) {
  21910. if ("development" !== 'production') {
  21911. errMsg = 'Must have at least one upstream dataset.';
  21912. }
  21913. throwError(errMsg);
  21914. }
  21915. if (!isObject(transOption)) {
  21916. if ("development" !== 'production') {
  21917. errMsg = 'transform declaration must be an object rather than ' + typeof transOption + '.';
  21918. }
  21919. throwError(errMsg);
  21920. }
  21921. var transType = transOption.type;
  21922. var externalTransform = externalTransformMap.get(transType);
  21923. if (!externalTransform) {
  21924. if ("development" !== 'production') {
  21925. errMsg = 'Can not find transform on type "' + transType + '".';
  21926. }
  21927. throwError(errMsg);
  21928. }
  21929. // Prepare source
  21930. var extUpSourceList = map(upSourceList, function (upSource) {
  21931. return createExternalSource(upSource, externalTransform);
  21932. });
  21933. var resultList = normalizeToArray(externalTransform.transform({
  21934. upstream: extUpSourceList[0],
  21935. upstreamList: extUpSourceList,
  21936. config: clone(transOption.config)
  21937. }));
  21938. if ("development" !== 'production') {
  21939. if (transOption.print) {
  21940. var printStrArr = map(resultList, function (extSource) {
  21941. var pipeIndexStr = pipeIndex != null ? ' === pipe index: ' + pipeIndex : '';
  21942. return ['=== dataset index: ' + infoForPrint.datasetIndex + pipeIndexStr + ' ===', '- transform result data:', makePrintable(extSource.data), '- transform result dimensions:', makePrintable(extSource.dimensions)].join('\n');
  21943. }).join('\n');
  21944. log(printStrArr);
  21945. }
  21946. }
  21947. return map(resultList, function (result, resultIndex) {
  21948. var errMsg = '';
  21949. if (!isObject(result)) {
  21950. if ("development" !== 'production') {
  21951. errMsg = 'A transform should not return some empty results.';
  21952. }
  21953. throwError(errMsg);
  21954. }
  21955. if (!result.data) {
  21956. if ("development" !== 'production') {
  21957. errMsg = 'Transform result data should be not be null or undefined';
  21958. }
  21959. throwError(errMsg);
  21960. }
  21961. var sourceFormat = detectSourceFormat(result.data);
  21962. if (!isSupportedSourceFormat(sourceFormat)) {
  21963. if ("development" !== 'production') {
  21964. errMsg = 'Transform result data should be array rows or object rows.';
  21965. }
  21966. throwError(errMsg);
  21967. }
  21968. var resultMetaRawOption;
  21969. var firstUpSource = upSourceList[0];
  21970. /**
  21971. * Intuitively, the end users known the content of the original `dataset.source`,
  21972. * calucating the transform result in mind.
  21973. * Suppose the original `dataset.source` is:
  21974. * ```js
  21975. * [
  21976. * ['product', '2012', '2013', '2014', '2015'],
  21977. * ['AAA', 41.1, 30.4, 65.1, 53.3],
  21978. * ['BBB', 86.5, 92.1, 85.7, 83.1],
  21979. * ['CCC', 24.1, 67.2, 79.5, 86.4]
  21980. * ]
  21981. * ```
  21982. * The dimension info have to be detected from the source data.
  21983. * Some of the transformers (like filter, sort) will follow the dimension info
  21984. * of upstream, while others use new dimensions (like aggregate).
  21985. * Transformer can output a field `dimensions` to define the its own output dimensions.
  21986. * We also allow transformers to ignore the output `dimensions` field, and
  21987. * inherit the upstream dimensions definition. It can reduce the burden of handling
  21988. * dimensions in transformers.
  21989. *
  21990. * See also [DIMENSION_INHERIT_RULE] in `sourceManager.ts`.
  21991. */
  21992. if (firstUpSource && resultIndex === 0
  21993. // If transformer returns `dimensions`, it means that the transformer has different
  21994. // dimensions definitions. We do not inherit anything from upstream.
  21995. && !result.dimensions) {
  21996. var startIndex = firstUpSource.startIndex;
  21997. // We copy the header of upstream to the result, because:
  21998. // (1) The returned data always does not contain header line and can not be used
  21999. // as dimension-detection. In this case we can not use "detected dimensions" of
  22000. // upstream directly, because it might be detected based on different `seriesLayoutBy`.
  22001. // (2) We should support that the series read the upstream source in `seriesLayoutBy: 'row'`.
  22002. // So the original detected header should be add to the result, otherwise they can not be read.
  22003. if (startIndex) {
  22004. result.data = firstUpSource.data.slice(0, startIndex).concat(result.data);
  22005. }
  22006. resultMetaRawOption = {
  22007. seriesLayoutBy: SERIES_LAYOUT_BY_COLUMN,
  22008. sourceHeader: startIndex,
  22009. dimensions: firstUpSource.metaRawOption.dimensions
  22010. };
  22011. } else {
  22012. resultMetaRawOption = {
  22013. seriesLayoutBy: SERIES_LAYOUT_BY_COLUMN,
  22014. sourceHeader: 0,
  22015. dimensions: result.dimensions
  22016. };
  22017. }
  22018. return createSource(result.data, resultMetaRawOption, null);
  22019. });
  22020. }
  22021. function isSupportedSourceFormat(sourceFormat) {
  22022. return sourceFormat === SOURCE_FORMAT_ARRAY_ROWS || sourceFormat === SOURCE_FORMAT_OBJECT_ROWS;
  22023. }
  22024. var UNDEFINED = 'undefined';
  22025. /* global Float64Array, Int32Array, Uint32Array, Uint16Array */
  22026. // Caution: MUST not use `new CtorUint32Array(arr, 0, len)`, because the Ctor of array is
  22027. // different from the Ctor of typed array.
  22028. var CtorUint32Array = typeof Uint32Array === UNDEFINED ? Array : Uint32Array;
  22029. var CtorUint16Array = typeof Uint16Array === UNDEFINED ? Array : Uint16Array;
  22030. var CtorInt32Array = typeof Int32Array === UNDEFINED ? Array : Int32Array;
  22031. var CtorFloat64Array = typeof Float64Array === UNDEFINED ? Array : Float64Array;
  22032. /**
  22033. * Multi dimensional data store
  22034. */
  22035. var dataCtors = {
  22036. 'float': CtorFloat64Array,
  22037. 'int': CtorInt32Array,
  22038. // Ordinal data type can be string or int
  22039. 'ordinal': Array,
  22040. 'number': Array,
  22041. 'time': CtorFloat64Array
  22042. };
  22043. var defaultDimValueGetters;
  22044. function getIndicesCtor(rawCount) {
  22045. // The possible max value in this._indicies is always this._rawCount despite of filtering.
  22046. return rawCount > 65535 ? CtorUint32Array : CtorUint16Array;
  22047. }
  22048. function getInitialExtent() {
  22049. return [Infinity, -Infinity];
  22050. }
  22051. function cloneChunk(originalChunk) {
  22052. var Ctor = originalChunk.constructor;
  22053. // Only shallow clone is enough when Array.
  22054. return Ctor === Array ? originalChunk.slice() : new Ctor(originalChunk);
  22055. }
  22056. function prepareStore(store, dimIdx, dimType, end, append) {
  22057. var DataCtor = dataCtors[dimType || 'float'];
  22058. if (append) {
  22059. var oldStore = store[dimIdx];
  22060. var oldLen = oldStore && oldStore.length;
  22061. if (!(oldLen === end)) {
  22062. var newStore = new DataCtor(end);
  22063. // The cost of the copy is probably inconsiderable
  22064. // within the initial chunkSize.
  22065. for (var j = 0; j < oldLen; j++) {
  22066. newStore[j] = oldStore[j];
  22067. }
  22068. store[dimIdx] = newStore;
  22069. }
  22070. } else {
  22071. store[dimIdx] = new DataCtor(end);
  22072. }
  22073. }
  22074. /**
  22075. * Basically, DataStore API keep immutable.
  22076. */
  22077. var DataStore = /** @class */function () {
  22078. function DataStore() {
  22079. this._chunks = [];
  22080. // It will not be calculated until needed.
  22081. this._rawExtent = [];
  22082. this._extent = [];
  22083. this._count = 0;
  22084. this._rawCount = 0;
  22085. this._calcDimNameToIdx = createHashMap();
  22086. }
  22087. /**
  22088. * Initialize from data
  22089. */
  22090. DataStore.prototype.initData = function (provider, inputDimensions, dimValueGetter) {
  22091. if ("development" !== 'production') {
  22092. assert(isFunction(provider.getItem) && isFunction(provider.count), 'Invalid data provider.');
  22093. }
  22094. this._provider = provider;
  22095. // Clear
  22096. this._chunks = [];
  22097. this._indices = null;
  22098. this.getRawIndex = this._getRawIdxIdentity;
  22099. var source = provider.getSource();
  22100. var defaultGetter = this.defaultDimValueGetter = defaultDimValueGetters[source.sourceFormat];
  22101. // Default dim value getter
  22102. this._dimValueGetter = dimValueGetter || defaultGetter;
  22103. // Reset raw extent.
  22104. this._rawExtent = [];
  22105. var willRetrieveDataByName = shouldRetrieveDataByName(source);
  22106. this._dimensions = map(inputDimensions, function (dim) {
  22107. if ("development" !== 'production') {
  22108. if (willRetrieveDataByName) {
  22109. assert(dim.property != null);
  22110. }
  22111. }
  22112. return {
  22113. // Only pick these two props. Not leak other properties like orderMeta.
  22114. type: dim.type,
  22115. property: dim.property
  22116. };
  22117. });
  22118. this._initDataFromProvider(0, provider.count());
  22119. };
  22120. DataStore.prototype.getProvider = function () {
  22121. return this._provider;
  22122. };
  22123. /**
  22124. * Caution: even when a `source` instance owned by a series, the created data store
  22125. * may still be shared by different sereis (the source hash does not use all `source`
  22126. * props, see `sourceManager`). In this case, the `source` props that are not used in
  22127. * hash (like `source.dimensionDefine`) probably only belongs to a certain series and
  22128. * thus should not be fetch here.
  22129. */
  22130. DataStore.prototype.getSource = function () {
  22131. return this._provider.getSource();
  22132. };
  22133. /**
  22134. * @caution Only used in dataStack.
  22135. */
  22136. DataStore.prototype.ensureCalculationDimension = function (dimName, type) {
  22137. var calcDimNameToIdx = this._calcDimNameToIdx;
  22138. var dimensions = this._dimensions;
  22139. var calcDimIdx = calcDimNameToIdx.get(dimName);
  22140. if (calcDimIdx != null) {
  22141. if (dimensions[calcDimIdx].type === type) {
  22142. return calcDimIdx;
  22143. }
  22144. } else {
  22145. calcDimIdx = dimensions.length;
  22146. }
  22147. dimensions[calcDimIdx] = {
  22148. type: type
  22149. };
  22150. calcDimNameToIdx.set(dimName, calcDimIdx);
  22151. this._chunks[calcDimIdx] = new dataCtors[type || 'float'](this._rawCount);
  22152. this._rawExtent[calcDimIdx] = getInitialExtent();
  22153. return calcDimIdx;
  22154. };
  22155. DataStore.prototype.collectOrdinalMeta = function (dimIdx, ordinalMeta) {
  22156. var chunk = this._chunks[dimIdx];
  22157. var dim = this._dimensions[dimIdx];
  22158. var rawExtents = this._rawExtent;
  22159. var offset = dim.ordinalOffset || 0;
  22160. var len = chunk.length;
  22161. if (offset === 0) {
  22162. // We need to reset the rawExtent if collect is from start.
  22163. // Because this dimension may be guessed as number and calcuating a wrong extent.
  22164. rawExtents[dimIdx] = getInitialExtent();
  22165. }
  22166. var dimRawExtent = rawExtents[dimIdx];
  22167. // Parse from previous data offset. len may be changed after appendData
  22168. for (var i = offset; i < len; i++) {
  22169. var val = chunk[i] = ordinalMeta.parseAndCollect(chunk[i]);
  22170. if (!isNaN(val)) {
  22171. dimRawExtent[0] = Math.min(val, dimRawExtent[0]);
  22172. dimRawExtent[1] = Math.max(val, dimRawExtent[1]);
  22173. }
  22174. }
  22175. dim.ordinalMeta = ordinalMeta;
  22176. dim.ordinalOffset = len;
  22177. dim.type = 'ordinal'; // Force to be ordinal
  22178. };
  22179. DataStore.prototype.getOrdinalMeta = function (dimIdx) {
  22180. var dimInfo = this._dimensions[dimIdx];
  22181. var ordinalMeta = dimInfo.ordinalMeta;
  22182. return ordinalMeta;
  22183. };
  22184. DataStore.prototype.getDimensionProperty = function (dimIndex) {
  22185. var item = this._dimensions[dimIndex];
  22186. return item && item.property;
  22187. };
  22188. /**
  22189. * Caution: Can be only called on raw data (before `this._indices` created).
  22190. */
  22191. DataStore.prototype.appendData = function (data) {
  22192. if ("development" !== 'production') {
  22193. assert(!this._indices, 'appendData can only be called on raw data.');
  22194. }
  22195. var provider = this._provider;
  22196. var start = this.count();
  22197. provider.appendData(data);
  22198. var end = provider.count();
  22199. if (!provider.persistent) {
  22200. end += start;
  22201. }
  22202. if (start < end) {
  22203. this._initDataFromProvider(start, end, true);
  22204. }
  22205. return [start, end];
  22206. };
  22207. DataStore.prototype.appendValues = function (values, minFillLen) {
  22208. var chunks = this._chunks;
  22209. var dimensions = this._dimensions;
  22210. var dimLen = dimensions.length;
  22211. var rawExtent = this._rawExtent;
  22212. var start = this.count();
  22213. var end = start + Math.max(values.length, minFillLen || 0);
  22214. for (var i = 0; i < dimLen; i++) {
  22215. var dim = dimensions[i];
  22216. prepareStore(chunks, i, dim.type, end, true);
  22217. }
  22218. var emptyDataItem = [];
  22219. for (var idx = start; idx < end; idx++) {
  22220. var sourceIdx = idx - start;
  22221. // Store the data by dimensions
  22222. for (var dimIdx = 0; dimIdx < dimLen; dimIdx++) {
  22223. var dim = dimensions[dimIdx];
  22224. var val = defaultDimValueGetters.arrayRows.call(this, values[sourceIdx] || emptyDataItem, dim.property, sourceIdx, dimIdx);
  22225. chunks[dimIdx][idx] = val;
  22226. var dimRawExtent = rawExtent[dimIdx];
  22227. val < dimRawExtent[0] && (dimRawExtent[0] = val);
  22228. val > dimRawExtent[1] && (dimRawExtent[1] = val);
  22229. }
  22230. }
  22231. this._rawCount = this._count = end;
  22232. return {
  22233. start: start,
  22234. end: end
  22235. };
  22236. };
  22237. DataStore.prototype._initDataFromProvider = function (start, end, append) {
  22238. var provider = this._provider;
  22239. var chunks = this._chunks;
  22240. var dimensions = this._dimensions;
  22241. var dimLen = dimensions.length;
  22242. var rawExtent = this._rawExtent;
  22243. var dimNames = map(dimensions, function (dim) {
  22244. return dim.property;
  22245. });
  22246. for (var i = 0; i < dimLen; i++) {
  22247. var dim = dimensions[i];
  22248. if (!rawExtent[i]) {
  22249. rawExtent[i] = getInitialExtent();
  22250. }
  22251. prepareStore(chunks, i, dim.type, end, append);
  22252. }
  22253. if (provider.fillStorage) {
  22254. provider.fillStorage(start, end, chunks, rawExtent);
  22255. } else {
  22256. var dataItem = [];
  22257. for (var idx = start; idx < end; idx++) {
  22258. // NOTICE: Try not to write things into dataItem
  22259. dataItem = provider.getItem(idx, dataItem);
  22260. // Each data item is value
  22261. // [1, 2]
  22262. // 2
  22263. // Bar chart, line chart which uses category axis
  22264. // only gives the 'y' value. 'x' value is the indices of category
  22265. // Use a tempValue to normalize the value to be a (x, y) value
  22266. // Store the data by dimensions
  22267. for (var dimIdx = 0; dimIdx < dimLen; dimIdx++) {
  22268. var dimStorage = chunks[dimIdx];
  22269. // PENDING NULL is empty or zero
  22270. var val = this._dimValueGetter(dataItem, dimNames[dimIdx], idx, dimIdx);
  22271. dimStorage[idx] = val;
  22272. var dimRawExtent = rawExtent[dimIdx];
  22273. val < dimRawExtent[0] && (dimRawExtent[0] = val);
  22274. val > dimRawExtent[1] && (dimRawExtent[1] = val);
  22275. }
  22276. }
  22277. }
  22278. if (!provider.persistent && provider.clean) {
  22279. // Clean unused data if data source is typed array.
  22280. provider.clean();
  22281. }
  22282. this._rawCount = this._count = end;
  22283. // Reset data extent
  22284. this._extent = [];
  22285. };
  22286. DataStore.prototype.count = function () {
  22287. return this._count;
  22288. };
  22289. /**
  22290. * Get value. Return NaN if idx is out of range.
  22291. */
  22292. DataStore.prototype.get = function (dim, idx) {
  22293. if (!(idx >= 0 && idx < this._count)) {
  22294. return NaN;
  22295. }
  22296. var dimStore = this._chunks[dim];
  22297. return dimStore ? dimStore[this.getRawIndex(idx)] : NaN;
  22298. };
  22299. DataStore.prototype.getValues = function (dimensions, idx) {
  22300. var values = [];
  22301. var dimArr = [];
  22302. if (idx == null) {
  22303. idx = dimensions;
  22304. // TODO get all from store?
  22305. dimensions = [];
  22306. // All dimensions
  22307. for (var i = 0; i < this._dimensions.length; i++) {
  22308. dimArr.push(i);
  22309. }
  22310. } else {
  22311. dimArr = dimensions;
  22312. }
  22313. for (var i = 0, len = dimArr.length; i < len; i++) {
  22314. values.push(this.get(dimArr[i], idx));
  22315. }
  22316. return values;
  22317. };
  22318. /**
  22319. * @param dim concrete dim
  22320. */
  22321. DataStore.prototype.getByRawIndex = function (dim, rawIdx) {
  22322. if (!(rawIdx >= 0 && rawIdx < this._rawCount)) {
  22323. return NaN;
  22324. }
  22325. var dimStore = this._chunks[dim];
  22326. return dimStore ? dimStore[rawIdx] : NaN;
  22327. };
  22328. /**
  22329. * Get sum of data in one dimension
  22330. */
  22331. DataStore.prototype.getSum = function (dim) {
  22332. var dimData = this._chunks[dim];
  22333. var sum = 0;
  22334. if (dimData) {
  22335. for (var i = 0, len = this.count(); i < len; i++) {
  22336. var value = this.get(dim, i);
  22337. if (!isNaN(value)) {
  22338. sum += value;
  22339. }
  22340. }
  22341. }
  22342. return sum;
  22343. };
  22344. /**
  22345. * Get median of data in one dimension
  22346. */
  22347. DataStore.prototype.getMedian = function (dim) {
  22348. var dimDataArray = [];
  22349. // map all data of one dimension
  22350. this.each([dim], function (val) {
  22351. if (!isNaN(val)) {
  22352. dimDataArray.push(val);
  22353. }
  22354. });
  22355. // TODO
  22356. // Use quick select?
  22357. var sortedDimDataArray = dimDataArray.sort(function (a, b) {
  22358. return a - b;
  22359. });
  22360. var len = this.count();
  22361. // calculate median
  22362. return len === 0 ? 0 : len % 2 === 1 ? sortedDimDataArray[(len - 1) / 2] : (sortedDimDataArray[len / 2] + sortedDimDataArray[len / 2 - 1]) / 2;
  22363. };
  22364. /**
  22365. * Retrieve the index with given raw data index.
  22366. */
  22367. DataStore.prototype.indexOfRawIndex = function (rawIndex) {
  22368. if (rawIndex >= this._rawCount || rawIndex < 0) {
  22369. return -1;
  22370. }
  22371. if (!this._indices) {
  22372. return rawIndex;
  22373. }
  22374. // Indices are ascending
  22375. var indices = this._indices;
  22376. // If rawIndex === dataIndex
  22377. var rawDataIndex = indices[rawIndex];
  22378. if (rawDataIndex != null && rawDataIndex < this._count && rawDataIndex === rawIndex) {
  22379. return rawIndex;
  22380. }
  22381. var left = 0;
  22382. var right = this._count - 1;
  22383. while (left <= right) {
  22384. var mid = (left + right) / 2 | 0;
  22385. if (indices[mid] < rawIndex) {
  22386. left = mid + 1;
  22387. } else if (indices[mid] > rawIndex) {
  22388. right = mid - 1;
  22389. } else {
  22390. return mid;
  22391. }
  22392. }
  22393. return -1;
  22394. };
  22395. DataStore.prototype.getIndices = function () {
  22396. var newIndices;
  22397. var indices = this._indices;
  22398. if (indices) {
  22399. var Ctor = indices.constructor;
  22400. var thisCount = this._count;
  22401. // `new Array(a, b, c)` is different from `new Uint32Array(a, b, c)`.
  22402. if (Ctor === Array) {
  22403. newIndices = new Ctor(thisCount);
  22404. for (var i = 0; i < thisCount; i++) {
  22405. newIndices[i] = indices[i];
  22406. }
  22407. } else {
  22408. newIndices = new Ctor(indices.buffer, 0, thisCount);
  22409. }
  22410. } else {
  22411. var Ctor = getIndicesCtor(this._rawCount);
  22412. newIndices = new Ctor(this.count());
  22413. for (var i = 0; i < newIndices.length; i++) {
  22414. newIndices[i] = i;
  22415. }
  22416. }
  22417. return newIndices;
  22418. };
  22419. /**
  22420. * Data filter.
  22421. */
  22422. DataStore.prototype.filter = function (dims, cb) {
  22423. if (!this._count) {
  22424. return this;
  22425. }
  22426. var newStore = this.clone();
  22427. var count = newStore.count();
  22428. var Ctor = getIndicesCtor(newStore._rawCount);
  22429. var newIndices = new Ctor(count);
  22430. var value = [];
  22431. var dimSize = dims.length;
  22432. var offset = 0;
  22433. var dim0 = dims[0];
  22434. var chunks = newStore._chunks;
  22435. for (var i = 0; i < count; i++) {
  22436. var keep = void 0;
  22437. var rawIdx = newStore.getRawIndex(i);
  22438. // Simple optimization
  22439. if (dimSize === 0) {
  22440. keep = cb(i);
  22441. } else if (dimSize === 1) {
  22442. var val = chunks[dim0][rawIdx];
  22443. keep = cb(val, i);
  22444. } else {
  22445. var k = 0;
  22446. for (; k < dimSize; k++) {
  22447. value[k] = chunks[dims[k]][rawIdx];
  22448. }
  22449. value[k] = i;
  22450. keep = cb.apply(null, value);
  22451. }
  22452. if (keep) {
  22453. newIndices[offset++] = rawIdx;
  22454. }
  22455. }
  22456. // Set indices after filtered.
  22457. if (offset < count) {
  22458. newStore._indices = newIndices;
  22459. }
  22460. newStore._count = offset;
  22461. // Reset data extent
  22462. newStore._extent = [];
  22463. newStore._updateGetRawIdx();
  22464. return newStore;
  22465. };
  22466. /**
  22467. * Select data in range. (For optimization of filter)
  22468. * (Manually inline code, support 5 million data filtering in data zoom.)
  22469. */
  22470. DataStore.prototype.selectRange = function (range) {
  22471. var newStore = this.clone();
  22472. var len = newStore._count;
  22473. if (!len) {
  22474. return this;
  22475. }
  22476. var dims = keys(range);
  22477. var dimSize = dims.length;
  22478. if (!dimSize) {
  22479. return this;
  22480. }
  22481. var originalCount = newStore.count();
  22482. var Ctor = getIndicesCtor(newStore._rawCount);
  22483. var newIndices = new Ctor(originalCount);
  22484. var offset = 0;
  22485. var dim0 = dims[0];
  22486. var min = range[dim0][0];
  22487. var max = range[dim0][1];
  22488. var storeArr = newStore._chunks;
  22489. var quickFinished = false;
  22490. if (!newStore._indices) {
  22491. // Extreme optimization for common case. About 2x faster in chrome.
  22492. var idx = 0;
  22493. if (dimSize === 1) {
  22494. var dimStorage = storeArr[dims[0]];
  22495. for (var i = 0; i < len; i++) {
  22496. var val = dimStorage[i];
  22497. // NaN will not be filtered. Consider the case, in line chart, empty
  22498. // value indicates the line should be broken. But for the case like
  22499. // scatter plot, a data item with empty value will not be rendered,
  22500. // but the axis extent may be effected if some other dim of the data
  22501. // item has value. Fortunately it is not a significant negative effect.
  22502. if (val >= min && val <= max || isNaN(val)) {
  22503. newIndices[offset++] = idx;
  22504. }
  22505. idx++;
  22506. }
  22507. quickFinished = true;
  22508. } else if (dimSize === 2) {
  22509. var dimStorage = storeArr[dims[0]];
  22510. var dimStorage2 = storeArr[dims[1]];
  22511. var min2 = range[dims[1]][0];
  22512. var max2 = range[dims[1]][1];
  22513. for (var i = 0; i < len; i++) {
  22514. var val = dimStorage[i];
  22515. var val2 = dimStorage2[i];
  22516. // Do not filter NaN, see comment above.
  22517. if ((val >= min && val <= max || isNaN(val)) && (val2 >= min2 && val2 <= max2 || isNaN(val2))) {
  22518. newIndices[offset++] = idx;
  22519. }
  22520. idx++;
  22521. }
  22522. quickFinished = true;
  22523. }
  22524. }
  22525. if (!quickFinished) {
  22526. if (dimSize === 1) {
  22527. for (var i = 0; i < originalCount; i++) {
  22528. var rawIndex = newStore.getRawIndex(i);
  22529. var val = storeArr[dims[0]][rawIndex];
  22530. // Do not filter NaN, see comment above.
  22531. if (val >= min && val <= max || isNaN(val)) {
  22532. newIndices[offset++] = rawIndex;
  22533. }
  22534. }
  22535. } else {
  22536. for (var i = 0; i < originalCount; i++) {
  22537. var keep = true;
  22538. var rawIndex = newStore.getRawIndex(i);
  22539. for (var k = 0; k < dimSize; k++) {
  22540. var dimk = dims[k];
  22541. var val = storeArr[dimk][rawIndex];
  22542. // Do not filter NaN, see comment above.
  22543. if (val < range[dimk][0] || val > range[dimk][1]) {
  22544. keep = false;
  22545. }
  22546. }
  22547. if (keep) {
  22548. newIndices[offset++] = newStore.getRawIndex(i);
  22549. }
  22550. }
  22551. }
  22552. }
  22553. // Set indices after filtered.
  22554. if (offset < originalCount) {
  22555. newStore._indices = newIndices;
  22556. }
  22557. newStore._count = offset;
  22558. // Reset data extent
  22559. newStore._extent = [];
  22560. newStore._updateGetRawIdx();
  22561. return newStore;
  22562. };
  22563. // /**
  22564. // * Data mapping to a plain array
  22565. // */
  22566. // mapArray(dims: DimensionIndex[], cb: MapArrayCb): any[] {
  22567. // const result: any[] = [];
  22568. // this.each(dims, function () {
  22569. // result.push(cb && (cb as MapArrayCb).apply(null, arguments));
  22570. // });
  22571. // return result;
  22572. // }
  22573. /**
  22574. * Data mapping to a new List with given dimensions
  22575. */
  22576. DataStore.prototype.map = function (dims, cb) {
  22577. // TODO only clone picked chunks.
  22578. var target = this.clone(dims);
  22579. this._updateDims(target, dims, cb);
  22580. return target;
  22581. };
  22582. /**
  22583. * @caution Danger!! Only used in dataStack.
  22584. */
  22585. DataStore.prototype.modify = function (dims, cb) {
  22586. this._updateDims(this, dims, cb);
  22587. };
  22588. DataStore.prototype._updateDims = function (target, dims, cb) {
  22589. var targetChunks = target._chunks;
  22590. var tmpRetValue = [];
  22591. var dimSize = dims.length;
  22592. var dataCount = target.count();
  22593. var values = [];
  22594. var rawExtent = target._rawExtent;
  22595. for (var i = 0; i < dims.length; i++) {
  22596. rawExtent[dims[i]] = getInitialExtent();
  22597. }
  22598. for (var dataIndex = 0; dataIndex < dataCount; dataIndex++) {
  22599. var rawIndex = target.getRawIndex(dataIndex);
  22600. for (var k = 0; k < dimSize; k++) {
  22601. values[k] = targetChunks[dims[k]][rawIndex];
  22602. }
  22603. values[dimSize] = dataIndex;
  22604. var retValue = cb && cb.apply(null, values);
  22605. if (retValue != null) {
  22606. // a number or string (in oridinal dimension)?
  22607. if (typeof retValue !== 'object') {
  22608. tmpRetValue[0] = retValue;
  22609. retValue = tmpRetValue;
  22610. }
  22611. for (var i = 0; i < retValue.length; i++) {
  22612. var dim = dims[i];
  22613. var val = retValue[i];
  22614. var rawExtentOnDim = rawExtent[dim];
  22615. var dimStore = targetChunks[dim];
  22616. if (dimStore) {
  22617. dimStore[rawIndex] = val;
  22618. }
  22619. if (val < rawExtentOnDim[0]) {
  22620. rawExtentOnDim[0] = val;
  22621. }
  22622. if (val > rawExtentOnDim[1]) {
  22623. rawExtentOnDim[1] = val;
  22624. }
  22625. }
  22626. }
  22627. }
  22628. };
  22629. /**
  22630. * Large data down sampling using largest-triangle-three-buckets
  22631. * @param {string} valueDimension
  22632. * @param {number} targetCount
  22633. */
  22634. DataStore.prototype.lttbDownSample = function (valueDimension, rate) {
  22635. var target = this.clone([valueDimension], true);
  22636. var targetStorage = target._chunks;
  22637. var dimStore = targetStorage[valueDimension];
  22638. var len = this.count();
  22639. var sampledIndex = 0;
  22640. var frameSize = Math.floor(1 / rate);
  22641. var currentRawIndex = this.getRawIndex(0);
  22642. var maxArea;
  22643. var area;
  22644. var nextRawIndex;
  22645. var newIndices = new (getIndicesCtor(this._rawCount))(Math.min((Math.ceil(len / frameSize) + 2) * 2, len));
  22646. // First frame use the first data.
  22647. newIndices[sampledIndex++] = currentRawIndex;
  22648. for (var i = 1; i < len - 1; i += frameSize) {
  22649. var nextFrameStart = Math.min(i + frameSize, len - 1);
  22650. var nextFrameEnd = Math.min(i + frameSize * 2, len);
  22651. var avgX = (nextFrameEnd + nextFrameStart) / 2;
  22652. var avgY = 0;
  22653. for (var idx = nextFrameStart; idx < nextFrameEnd; idx++) {
  22654. var rawIndex = this.getRawIndex(idx);
  22655. var y = dimStore[rawIndex];
  22656. if (isNaN(y)) {
  22657. continue;
  22658. }
  22659. avgY += y;
  22660. }
  22661. avgY /= nextFrameEnd - nextFrameStart;
  22662. var frameStart = i;
  22663. var frameEnd = Math.min(i + frameSize, len);
  22664. var pointAX = i - 1;
  22665. var pointAY = dimStore[currentRawIndex];
  22666. maxArea = -1;
  22667. nextRawIndex = frameStart;
  22668. var firstNaNIndex = -1;
  22669. var countNaN = 0;
  22670. // Find a point from current frame that construct a triangle with largest area with previous selected point
  22671. // And the average of next frame.
  22672. for (var idx = frameStart; idx < frameEnd; idx++) {
  22673. var rawIndex = this.getRawIndex(idx);
  22674. var y = dimStore[rawIndex];
  22675. if (isNaN(y)) {
  22676. countNaN++;
  22677. if (firstNaNIndex < 0) {
  22678. firstNaNIndex = rawIndex;
  22679. }
  22680. continue;
  22681. }
  22682. // Calculate triangle area over three buckets
  22683. area = Math.abs((pointAX - avgX) * (y - pointAY) - (pointAX - idx) * (avgY - pointAY));
  22684. if (area > maxArea) {
  22685. maxArea = area;
  22686. nextRawIndex = rawIndex; // Next a is this b
  22687. }
  22688. }
  22689. if (countNaN > 0 && countNaN < frameEnd - frameStart) {
  22690. // Append first NaN point in every bucket.
  22691. // It is necessary to ensure the correct order of indices.
  22692. newIndices[sampledIndex++] = Math.min(firstNaNIndex, nextRawIndex);
  22693. nextRawIndex = Math.max(firstNaNIndex, nextRawIndex);
  22694. }
  22695. newIndices[sampledIndex++] = nextRawIndex;
  22696. currentRawIndex = nextRawIndex; // This a is the next a (chosen b)
  22697. }
  22698. // First frame use the last data.
  22699. newIndices[sampledIndex++] = this.getRawIndex(len - 1);
  22700. target._count = sampledIndex;
  22701. target._indices = newIndices;
  22702. target.getRawIndex = this._getRawIdx;
  22703. return target;
  22704. };
  22705. /**
  22706. * Large data down sampling using min-max
  22707. * @param {string} valueDimension
  22708. * @param {number} rate
  22709. */
  22710. DataStore.prototype.minmaxDownSample = function (valueDimension, rate) {
  22711. var target = this.clone([valueDimension], true);
  22712. var targetStorage = target._chunks;
  22713. var frameSize = Math.floor(1 / rate);
  22714. var dimStore = targetStorage[valueDimension];
  22715. var len = this.count();
  22716. // Each frame results in 2 data points, one for min and one for max
  22717. var newIndices = new (getIndicesCtor(this._rawCount))(Math.ceil(len / frameSize) * 2);
  22718. var offset = 0;
  22719. for (var i = 0; i < len; i += frameSize) {
  22720. var minIndex = i;
  22721. var minValue = dimStore[this.getRawIndex(minIndex)];
  22722. var maxIndex = i;
  22723. var maxValue = dimStore[this.getRawIndex(maxIndex)];
  22724. var thisFrameSize = frameSize;
  22725. // Handle final smaller frame
  22726. if (i + frameSize > len) {
  22727. thisFrameSize = len - i;
  22728. }
  22729. // Determine min and max within the current frame
  22730. for (var k = 0; k < thisFrameSize; k++) {
  22731. var rawIndex = this.getRawIndex(i + k);
  22732. var value = dimStore[rawIndex];
  22733. if (value < minValue) {
  22734. minValue = value;
  22735. minIndex = i + k;
  22736. }
  22737. if (value > maxValue) {
  22738. maxValue = value;
  22739. maxIndex = i + k;
  22740. }
  22741. }
  22742. var rawMinIndex = this.getRawIndex(minIndex);
  22743. var rawMaxIndex = this.getRawIndex(maxIndex);
  22744. // Set the order of the min and max values, based on their ordering in the frame
  22745. if (minIndex < maxIndex) {
  22746. newIndices[offset++] = rawMinIndex;
  22747. newIndices[offset++] = rawMaxIndex;
  22748. } else {
  22749. newIndices[offset++] = rawMaxIndex;
  22750. newIndices[offset++] = rawMinIndex;
  22751. }
  22752. }
  22753. target._count = offset;
  22754. target._indices = newIndices;
  22755. target._updateGetRawIdx();
  22756. return target;
  22757. };
  22758. /**
  22759. * Large data down sampling on given dimension
  22760. * @param sampleIndex Sample index for name and id
  22761. */
  22762. DataStore.prototype.downSample = function (dimension, rate, sampleValue, sampleIndex) {
  22763. var target = this.clone([dimension], true);
  22764. var targetStorage = target._chunks;
  22765. var frameValues = [];
  22766. var frameSize = Math.floor(1 / rate);
  22767. var dimStore = targetStorage[dimension];
  22768. var len = this.count();
  22769. var rawExtentOnDim = target._rawExtent[dimension] = getInitialExtent();
  22770. var newIndices = new (getIndicesCtor(this._rawCount))(Math.ceil(len / frameSize));
  22771. var offset = 0;
  22772. for (var i = 0; i < len; i += frameSize) {
  22773. // Last frame
  22774. if (frameSize > len - i) {
  22775. frameSize = len - i;
  22776. frameValues.length = frameSize;
  22777. }
  22778. for (var k = 0; k < frameSize; k++) {
  22779. var dataIdx = this.getRawIndex(i + k);
  22780. frameValues[k] = dimStore[dataIdx];
  22781. }
  22782. var value = sampleValue(frameValues);
  22783. var sampleFrameIdx = this.getRawIndex(Math.min(i + sampleIndex(frameValues, value) || 0, len - 1));
  22784. // Only write value on the filtered data
  22785. dimStore[sampleFrameIdx] = value;
  22786. if (value < rawExtentOnDim[0]) {
  22787. rawExtentOnDim[0] = value;
  22788. }
  22789. if (value > rawExtentOnDim[1]) {
  22790. rawExtentOnDim[1] = value;
  22791. }
  22792. newIndices[offset++] = sampleFrameIdx;
  22793. }
  22794. target._count = offset;
  22795. target._indices = newIndices;
  22796. target._updateGetRawIdx();
  22797. return target;
  22798. };
  22799. /**
  22800. * Data iteration
  22801. * @param ctx default this
  22802. * @example
  22803. * list.each('x', function (x, idx) {});
  22804. * list.each(['x', 'y'], function (x, y, idx) {});
  22805. * list.each(function (idx) {})
  22806. */
  22807. DataStore.prototype.each = function (dims, cb) {
  22808. if (!this._count) {
  22809. return;
  22810. }
  22811. var dimSize = dims.length;
  22812. var chunks = this._chunks;
  22813. for (var i = 0, len = this.count(); i < len; i++) {
  22814. var rawIdx = this.getRawIndex(i);
  22815. // Simple optimization
  22816. switch (dimSize) {
  22817. case 0:
  22818. cb(i);
  22819. break;
  22820. case 1:
  22821. cb(chunks[dims[0]][rawIdx], i);
  22822. break;
  22823. case 2:
  22824. cb(chunks[dims[0]][rawIdx], chunks[dims[1]][rawIdx], i);
  22825. break;
  22826. default:
  22827. var k = 0;
  22828. var value = [];
  22829. for (; k < dimSize; k++) {
  22830. value[k] = chunks[dims[k]][rawIdx];
  22831. }
  22832. // Index
  22833. value[k] = i;
  22834. cb.apply(null, value);
  22835. }
  22836. }
  22837. };
  22838. /**
  22839. * Get extent of data in one dimension
  22840. */
  22841. DataStore.prototype.getDataExtent = function (dim) {
  22842. // Make sure use concrete dim as cache name.
  22843. var dimData = this._chunks[dim];
  22844. var initialExtent = getInitialExtent();
  22845. if (!dimData) {
  22846. return initialExtent;
  22847. }
  22848. // Make more strict checkings to ensure hitting cache.
  22849. var currEnd = this.count();
  22850. // Consider the most cases when using data zoom, `getDataExtent`
  22851. // happened before filtering. We cache raw extent, which is not
  22852. // necessary to be cleared and recalculated when restore data.
  22853. var useRaw = !this._indices;
  22854. var dimExtent;
  22855. if (useRaw) {
  22856. return this._rawExtent[dim].slice();
  22857. }
  22858. dimExtent = this._extent[dim];
  22859. if (dimExtent) {
  22860. return dimExtent.slice();
  22861. }
  22862. dimExtent = initialExtent;
  22863. var min = dimExtent[0];
  22864. var max = dimExtent[1];
  22865. for (var i = 0; i < currEnd; i++) {
  22866. var rawIdx = this.getRawIndex(i);
  22867. var value = dimData[rawIdx];
  22868. value < min && (min = value);
  22869. value > max && (max = value);
  22870. }
  22871. dimExtent = [min, max];
  22872. this._extent[dim] = dimExtent;
  22873. return dimExtent;
  22874. };
  22875. /**
  22876. * Get raw data item
  22877. */
  22878. DataStore.prototype.getRawDataItem = function (idx) {
  22879. var rawIdx = this.getRawIndex(idx);
  22880. if (!this._provider.persistent) {
  22881. var val = [];
  22882. var chunks = this._chunks;
  22883. for (var i = 0; i < chunks.length; i++) {
  22884. val.push(chunks[i][rawIdx]);
  22885. }
  22886. return val;
  22887. } else {
  22888. return this._provider.getItem(rawIdx);
  22889. }
  22890. };
  22891. /**
  22892. * Clone shallow.
  22893. *
  22894. * @param clonedDims Determine which dims to clone. Will share the data if not specified.
  22895. */
  22896. DataStore.prototype.clone = function (clonedDims, ignoreIndices) {
  22897. var target = new DataStore();
  22898. var chunks = this._chunks;
  22899. var clonedDimsMap = clonedDims && reduce(clonedDims, function (obj, dimIdx) {
  22900. obj[dimIdx] = true;
  22901. return obj;
  22902. }, {});
  22903. if (clonedDimsMap) {
  22904. for (var i = 0; i < chunks.length; i++) {
  22905. // Not clone if dim is not picked.
  22906. target._chunks[i] = !clonedDimsMap[i] ? chunks[i] : cloneChunk(chunks[i]);
  22907. }
  22908. } else {
  22909. target._chunks = chunks;
  22910. }
  22911. this._copyCommonProps(target);
  22912. if (!ignoreIndices) {
  22913. target._indices = this._cloneIndices();
  22914. }
  22915. target._updateGetRawIdx();
  22916. return target;
  22917. };
  22918. DataStore.prototype._copyCommonProps = function (target) {
  22919. target._count = this._count;
  22920. target._rawCount = this._rawCount;
  22921. target._provider = this._provider;
  22922. target._dimensions = this._dimensions;
  22923. target._extent = clone(this._extent);
  22924. target._rawExtent = clone(this._rawExtent);
  22925. };
  22926. DataStore.prototype._cloneIndices = function () {
  22927. if (this._indices) {
  22928. var Ctor = this._indices.constructor;
  22929. var indices = void 0;
  22930. if (Ctor === Array) {
  22931. var thisCount = this._indices.length;
  22932. indices = new Ctor(thisCount);
  22933. for (var i = 0; i < thisCount; i++) {
  22934. indices[i] = this._indices[i];
  22935. }
  22936. } else {
  22937. indices = new Ctor(this._indices);
  22938. }
  22939. return indices;
  22940. }
  22941. return null;
  22942. };
  22943. DataStore.prototype._getRawIdxIdentity = function (idx) {
  22944. return idx;
  22945. };
  22946. DataStore.prototype._getRawIdx = function (idx) {
  22947. if (idx < this._count && idx >= 0) {
  22948. return this._indices[idx];
  22949. }
  22950. return -1;
  22951. };
  22952. DataStore.prototype._updateGetRawIdx = function () {
  22953. this.getRawIndex = this._indices ? this._getRawIdx : this._getRawIdxIdentity;
  22954. };
  22955. DataStore.internalField = function () {
  22956. function getDimValueSimply(dataItem, property, dataIndex, dimIndex) {
  22957. return parseDataValue(dataItem[dimIndex], this._dimensions[dimIndex]);
  22958. }
  22959. defaultDimValueGetters = {
  22960. arrayRows: getDimValueSimply,
  22961. objectRows: function (dataItem, property, dataIndex, dimIndex) {
  22962. return parseDataValue(dataItem[property], this._dimensions[dimIndex]);
  22963. },
  22964. keyedColumns: getDimValueSimply,
  22965. original: function (dataItem, property, dataIndex, dimIndex) {
  22966. // Performance sensitive, do not use modelUtil.getDataItemValue.
  22967. // If dataItem is an plain object with no value field, the let `value`
  22968. // will be assigned with the object, but it will be tread correctly
  22969. // in the `convertValue`.
  22970. var value = dataItem && (dataItem.value == null ? dataItem : dataItem.value);
  22971. return parseDataValue(value instanceof Array ? value[dimIndex]
  22972. // If value is a single number or something else not array.
  22973. : value, this._dimensions[dimIndex]);
  22974. },
  22975. typedArray: function (dataItem, property, dataIndex, dimIndex) {
  22976. return dataItem[dimIndex];
  22977. }
  22978. };
  22979. }();
  22980. return DataStore;
  22981. }();
  22982. /**
  22983. * [REQUIREMENT_MEMO]:
  22984. * (0) `metaRawOption` means `dimensions`/`sourceHeader`/`seriesLayoutBy` in raw option.
  22985. * (1) Keep support the feature: `metaRawOption` can be specified both on `series` and
  22986. * `root-dataset`. Them on `series` has higher priority.
  22987. * (2) Do not support to set `metaRawOption` on a `non-root-dataset`, because it might
  22988. * confuse users: whether those props indicate how to visit the upstream source or visit
  22989. * the transform result source, and some transforms has nothing to do with these props,
  22990. * and some transforms might have multiple upstream.
  22991. * (3) Transforms should specify `metaRawOption` in each output, just like they can be
  22992. * declared in `root-dataset`.
  22993. * (4) At present only support visit source in `SERIES_LAYOUT_BY_COLUMN` in transforms.
  22994. * That is for reducing complexity in transforms.
  22995. * PENDING: Whether to provide transposition transform?
  22996. *
  22997. * [IMPLEMENTAION_MEMO]:
  22998. * "sourceVisitConfig" are calculated from `metaRawOption` and `data`.
  22999. * They will not be calculated until `source` is about to be visited (to prevent from
  23000. * duplicate calcuation). `source` is visited only in series and input to transforms.
  23001. *
  23002. * [DIMENSION_INHERIT_RULE]:
  23003. * By default the dimensions are inherited from ancestors, unless a transform return
  23004. * a new dimensions definition.
  23005. * Consider the case:
  23006. * ```js
  23007. * dataset: [{
  23008. * source: [ ['Product', 'Sales', 'Prise'], ['Cookies', 321, 44.21], ...]
  23009. * }, {
  23010. * transform: { type: 'filter', ... }
  23011. * }]
  23012. * dataset: [{
  23013. * dimension: ['Product', 'Sales', 'Prise'],
  23014. * source: [ ['Cookies', 321, 44.21], ...]
  23015. * }, {
  23016. * transform: { type: 'filter', ... }
  23017. * }]
  23018. * ```
  23019. * The two types of option should have the same behavior after transform.
  23020. *
  23021. *
  23022. * [SCENARIO]:
  23023. * (1) Provide source data directly:
  23024. * ```js
  23025. * series: {
  23026. * encode: {...},
  23027. * dimensions: [...]
  23028. * seriesLayoutBy: 'row',
  23029. * data: [[...]]
  23030. * }
  23031. * ```
  23032. * (2) Series refer to dataset.
  23033. * ```js
  23034. * series: [{
  23035. * encode: {...}
  23036. * // Ignore datasetIndex means `datasetIndex: 0`
  23037. * // and the dimensions defination in dataset is used
  23038. * }, {
  23039. * encode: {...},
  23040. * seriesLayoutBy: 'column',
  23041. * datasetIndex: 1
  23042. * }]
  23043. * ```
  23044. * (3) dataset transform
  23045. * ```js
  23046. * dataset: [{
  23047. * source: [...]
  23048. * }, {
  23049. * source: [...]
  23050. * }, {
  23051. * // By default from 0.
  23052. * transform: { type: 'filter', config: {...} }
  23053. * }, {
  23054. * // Piped.
  23055. * transform: [
  23056. * { type: 'filter', config: {...} },
  23057. * { type: 'sort', config: {...} }
  23058. * ]
  23059. * }, {
  23060. * id: 'regressionData',
  23061. * fromDatasetIndex: 1,
  23062. * // Third-party transform
  23063. * transform: { type: 'ecStat:regression', config: {...} }
  23064. * }, {
  23065. * // retrieve the extra result.
  23066. * id: 'regressionFormula',
  23067. * fromDatasetId: 'regressionData',
  23068. * fromTransformResult: 1
  23069. * }]
  23070. * ```
  23071. */
  23072. var SourceManager = /** @class */function () {
  23073. function SourceManager(sourceHost) {
  23074. // Cached source. Do not repeat calculating if not dirty.
  23075. this._sourceList = [];
  23076. this._storeList = [];
  23077. // version sign of each upstream source manager.
  23078. this._upstreamSignList = [];
  23079. this._versionSignBase = 0;
  23080. this._dirty = true;
  23081. this._sourceHost = sourceHost;
  23082. }
  23083. /**
  23084. * Mark dirty.
  23085. */
  23086. SourceManager.prototype.dirty = function () {
  23087. this._setLocalSource([], []);
  23088. this._storeList = [];
  23089. this._dirty = true;
  23090. };
  23091. SourceManager.prototype._setLocalSource = function (sourceList, upstreamSignList) {
  23092. this._sourceList = sourceList;
  23093. this._upstreamSignList = upstreamSignList;
  23094. this._versionSignBase++;
  23095. if (this._versionSignBase > 9e10) {
  23096. this._versionSignBase = 0;
  23097. }
  23098. };
  23099. /**
  23100. * For detecting whether the upstream source is dirty, so that
  23101. * the local cached source (in `_sourceList`) should be discarded.
  23102. */
  23103. SourceManager.prototype._getVersionSign = function () {
  23104. return this._sourceHost.uid + '_' + this._versionSignBase;
  23105. };
  23106. /**
  23107. * Always return a source instance. Otherwise throw error.
  23108. */
  23109. SourceManager.prototype.prepareSource = function () {
  23110. // For the case that call `setOption` multiple time but no data changed,
  23111. // cache the result source to prevent from repeating transform.
  23112. if (this._isDirty()) {
  23113. this._createSource();
  23114. this._dirty = false;
  23115. }
  23116. };
  23117. SourceManager.prototype._createSource = function () {
  23118. this._setLocalSource([], []);
  23119. var sourceHost = this._sourceHost;
  23120. var upSourceMgrList = this._getUpstreamSourceManagers();
  23121. var hasUpstream = !!upSourceMgrList.length;
  23122. var resultSourceList;
  23123. var upstreamSignList;
  23124. if (isSeries(sourceHost)) {
  23125. var seriesModel = sourceHost;
  23126. var data = void 0;
  23127. var sourceFormat = void 0;
  23128. var upSource = void 0;
  23129. // Has upstream dataset
  23130. if (hasUpstream) {
  23131. var upSourceMgr = upSourceMgrList[0];
  23132. upSourceMgr.prepareSource();
  23133. upSource = upSourceMgr.getSource();
  23134. data = upSource.data;
  23135. sourceFormat = upSource.sourceFormat;
  23136. upstreamSignList = [upSourceMgr._getVersionSign()];
  23137. }
  23138. // Series data is from own.
  23139. else {
  23140. data = seriesModel.get('data', true);
  23141. sourceFormat = isTypedArray(data) ? SOURCE_FORMAT_TYPED_ARRAY : SOURCE_FORMAT_ORIGINAL;
  23142. upstreamSignList = [];
  23143. }
  23144. // See [REQUIREMENT_MEMO], merge settings on series and parent dataset if it is root.
  23145. var newMetaRawOption = this._getSourceMetaRawOption() || {};
  23146. var upMetaRawOption = upSource && upSource.metaRawOption || {};
  23147. var seriesLayoutBy = retrieve2(newMetaRawOption.seriesLayoutBy, upMetaRawOption.seriesLayoutBy) || null;
  23148. var sourceHeader = retrieve2(newMetaRawOption.sourceHeader, upMetaRawOption.sourceHeader);
  23149. // Note here we should not use `upSource.dimensionsDefine`. Consider the case:
  23150. // `upSource.dimensionsDefine` is detected by `seriesLayoutBy: 'column'`,
  23151. // but series need `seriesLayoutBy: 'row'`.
  23152. var dimensions = retrieve2(newMetaRawOption.dimensions, upMetaRawOption.dimensions);
  23153. // We share source with dataset as much as possible
  23154. // to avoid extra memory cost of high dimensional data.
  23155. var needsCreateSource = seriesLayoutBy !== upMetaRawOption.seriesLayoutBy || !!sourceHeader !== !!upMetaRawOption.sourceHeader || dimensions;
  23156. resultSourceList = needsCreateSource ? [createSource(data, {
  23157. seriesLayoutBy: seriesLayoutBy,
  23158. sourceHeader: sourceHeader,
  23159. dimensions: dimensions
  23160. }, sourceFormat)] : [];
  23161. } else {
  23162. var datasetModel = sourceHost;
  23163. // Has upstream dataset.
  23164. if (hasUpstream) {
  23165. var result = this._applyTransform(upSourceMgrList);
  23166. resultSourceList = result.sourceList;
  23167. upstreamSignList = result.upstreamSignList;
  23168. }
  23169. // Is root dataset.
  23170. else {
  23171. var sourceData = datasetModel.get('source', true);
  23172. resultSourceList = [createSource(sourceData, this._getSourceMetaRawOption(), null)];
  23173. upstreamSignList = [];
  23174. }
  23175. }
  23176. if ("development" !== 'production') {
  23177. assert(resultSourceList && upstreamSignList);
  23178. }
  23179. this._setLocalSource(resultSourceList, upstreamSignList);
  23180. };
  23181. SourceManager.prototype._applyTransform = function (upMgrList) {
  23182. var datasetModel = this._sourceHost;
  23183. var transformOption = datasetModel.get('transform', true);
  23184. var fromTransformResult = datasetModel.get('fromTransformResult', true);
  23185. if ("development" !== 'production') {
  23186. assert(fromTransformResult != null || transformOption != null);
  23187. }
  23188. if (fromTransformResult != null) {
  23189. var errMsg = '';
  23190. if (upMgrList.length !== 1) {
  23191. if ("development" !== 'production') {
  23192. errMsg = 'When using `fromTransformResult`, there should be only one upstream dataset';
  23193. }
  23194. doThrow(errMsg);
  23195. }
  23196. }
  23197. var sourceList;
  23198. var upSourceList = [];
  23199. var upstreamSignList = [];
  23200. each(upMgrList, function (upMgr) {
  23201. upMgr.prepareSource();
  23202. var upSource = upMgr.getSource(fromTransformResult || 0);
  23203. var errMsg = '';
  23204. if (fromTransformResult != null && !upSource) {
  23205. if ("development" !== 'production') {
  23206. errMsg = 'Can not retrieve result by `fromTransformResult`: ' + fromTransformResult;
  23207. }
  23208. doThrow(errMsg);
  23209. }
  23210. upSourceList.push(upSource);
  23211. upstreamSignList.push(upMgr._getVersionSign());
  23212. });
  23213. if (transformOption) {
  23214. sourceList = applyDataTransform(transformOption, upSourceList, {
  23215. datasetIndex: datasetModel.componentIndex
  23216. });
  23217. } else if (fromTransformResult != null) {
  23218. sourceList = [cloneSourceShallow(upSourceList[0])];
  23219. }
  23220. return {
  23221. sourceList: sourceList,
  23222. upstreamSignList: upstreamSignList
  23223. };
  23224. };
  23225. SourceManager.prototype._isDirty = function () {
  23226. if (this._dirty) {
  23227. return true;
  23228. }
  23229. // All sourceList is from the some upstream.
  23230. var upSourceMgrList = this._getUpstreamSourceManagers();
  23231. for (var i = 0; i < upSourceMgrList.length; i++) {
  23232. var upSrcMgr = upSourceMgrList[i];
  23233. if (
  23234. // Consider the case that there is ancestor diry, call it recursively.
  23235. // The performance is probably not an issue because usually the chain is not long.
  23236. upSrcMgr._isDirty() || this._upstreamSignList[i] !== upSrcMgr._getVersionSign()) {
  23237. return true;
  23238. }
  23239. }
  23240. };
  23241. /**
  23242. * @param sourceIndex By default 0, means "main source".
  23243. * In most cases there is only one source.
  23244. */
  23245. SourceManager.prototype.getSource = function (sourceIndex) {
  23246. sourceIndex = sourceIndex || 0;
  23247. var source = this._sourceList[sourceIndex];
  23248. if (!source) {
  23249. // Series may share source instance with dataset.
  23250. var upSourceMgrList = this._getUpstreamSourceManagers();
  23251. return upSourceMgrList[0] && upSourceMgrList[0].getSource(sourceIndex);
  23252. }
  23253. return source;
  23254. };
  23255. /**
  23256. *
  23257. * Get a data store which can be shared across series.
  23258. * Only available for series.
  23259. *
  23260. * @param seriesDimRequest Dimensions that are generated in series.
  23261. * Should have been sorted by `storeDimIndex` asc.
  23262. */
  23263. SourceManager.prototype.getSharedDataStore = function (seriesDimRequest) {
  23264. if ("development" !== 'production') {
  23265. assert(isSeries(this._sourceHost), 'Can only call getDataStore on series source manager.');
  23266. }
  23267. var schema = seriesDimRequest.makeStoreSchema();
  23268. return this._innerGetDataStore(schema.dimensions, seriesDimRequest.source, schema.hash);
  23269. };
  23270. SourceManager.prototype._innerGetDataStore = function (storeDims, seriesSource, sourceReadKey) {
  23271. // TODO Can use other sourceIndex?
  23272. var sourceIndex = 0;
  23273. var storeList = this._storeList;
  23274. var cachedStoreMap = storeList[sourceIndex];
  23275. if (!cachedStoreMap) {
  23276. cachedStoreMap = storeList[sourceIndex] = {};
  23277. }
  23278. var cachedStore = cachedStoreMap[sourceReadKey];
  23279. if (!cachedStore) {
  23280. var upSourceMgr = this._getUpstreamSourceManagers()[0];
  23281. if (isSeries(this._sourceHost) && upSourceMgr) {
  23282. cachedStore = upSourceMgr._innerGetDataStore(storeDims, seriesSource, sourceReadKey);
  23283. } else {
  23284. cachedStore = new DataStore();
  23285. // Always create store from source of series.
  23286. cachedStore.initData(new DefaultDataProvider(seriesSource, storeDims.length), storeDims);
  23287. }
  23288. cachedStoreMap[sourceReadKey] = cachedStore;
  23289. }
  23290. return cachedStore;
  23291. };
  23292. /**
  23293. * PENDING: Is it fast enough?
  23294. * If no upstream, return empty array.
  23295. */
  23296. SourceManager.prototype._getUpstreamSourceManagers = function () {
  23297. // Always get the relationship from the raw option.
  23298. // Do not cache the link of the dependency graph, so that
  23299. // there is no need to update them when change happens.
  23300. var sourceHost = this._sourceHost;
  23301. if (isSeries(sourceHost)) {
  23302. var datasetModel = querySeriesUpstreamDatasetModel(sourceHost);
  23303. return !datasetModel ? [] : [datasetModel.getSourceManager()];
  23304. } else {
  23305. return map(queryDatasetUpstreamDatasetModels(sourceHost), function (datasetModel) {
  23306. return datasetModel.getSourceManager();
  23307. });
  23308. }
  23309. };
  23310. SourceManager.prototype._getSourceMetaRawOption = function () {
  23311. var sourceHost = this._sourceHost;
  23312. var seriesLayoutBy;
  23313. var sourceHeader;
  23314. var dimensions;
  23315. if (isSeries(sourceHost)) {
  23316. seriesLayoutBy = sourceHost.get('seriesLayoutBy', true);
  23317. sourceHeader = sourceHost.get('sourceHeader', true);
  23318. dimensions = sourceHost.get('dimensions', true);
  23319. }
  23320. // See [REQUIREMENT_MEMO], `non-root-dataset` do not support them.
  23321. else if (!this._getUpstreamSourceManagers().length) {
  23322. var model = sourceHost;
  23323. seriesLayoutBy = model.get('seriesLayoutBy', true);
  23324. sourceHeader = model.get('sourceHeader', true);
  23325. dimensions = model.get('dimensions', true);
  23326. }
  23327. return {
  23328. seriesLayoutBy: seriesLayoutBy,
  23329. sourceHeader: sourceHeader,
  23330. dimensions: dimensions
  23331. };
  23332. };
  23333. return SourceManager;
  23334. }();
  23335. // Call this method after `super.init` and `super.mergeOption` to
  23336. // disable the transform merge, but do not disable transform clone from rawOption.
  23337. function disableTransformOptionMerge(datasetModel) {
  23338. var transformOption = datasetModel.option.transform;
  23339. transformOption && setAsPrimitive(datasetModel.option.transform);
  23340. }
  23341. function isSeries(sourceHost) {
  23342. // Avoid circular dependency with Series.ts
  23343. return sourceHost.mainType === 'series';
  23344. }
  23345. function doThrow(errMsg) {
  23346. throw new Error(errMsg);
  23347. }
  23348. var TOOLTIP_LINE_HEIGHT_CSS = 'line-height:1';
  23349. function getTooltipLineHeight(textStyle) {
  23350. var lineHeight = textStyle.lineHeight;
  23351. if (lineHeight == null) {
  23352. return TOOLTIP_LINE_HEIGHT_CSS;
  23353. } else {
  23354. return "line-height:" + encodeHTML(lineHeight + '') + "px";
  23355. }
  23356. }
  23357. // TODO: more textStyle option
  23358. function getTooltipTextStyle(textStyle, renderMode) {
  23359. var nameFontColor = textStyle.color || tokens.color.tertiary;
  23360. var nameFontSize = textStyle.fontSize || 12;
  23361. var nameFontWeight = textStyle.fontWeight || '400';
  23362. var valueFontColor = textStyle.color || tokens.color.secondary;
  23363. var valueFontSize = textStyle.fontSize || 14;
  23364. var valueFontWeight = textStyle.fontWeight || '900';
  23365. if (renderMode === 'html') {
  23366. // `textStyle` is probably from user input, should be encoded to reduce security risk.
  23367. return {
  23368. // eslint-disable-next-line max-len
  23369. nameStyle: "font-size:" + encodeHTML(nameFontSize + '') + "px;color:" + encodeHTML(nameFontColor) + ";font-weight:" + encodeHTML(nameFontWeight + ''),
  23370. // eslint-disable-next-line max-len
  23371. valueStyle: "font-size:" + encodeHTML(valueFontSize + '') + "px;color:" + encodeHTML(valueFontColor) + ";font-weight:" + encodeHTML(valueFontWeight + '')
  23372. };
  23373. } else {
  23374. return {
  23375. nameStyle: {
  23376. fontSize: nameFontSize,
  23377. fill: nameFontColor,
  23378. fontWeight: nameFontWeight
  23379. },
  23380. valueStyle: {
  23381. fontSize: valueFontSize,
  23382. fill: valueFontColor,
  23383. fontWeight: valueFontWeight
  23384. }
  23385. };
  23386. }
  23387. }
  23388. // See `TooltipMarkupLayoutIntent['innerGapLevel']`.
  23389. // (value from UI design)
  23390. var HTML_GAPS = [0, 10, 20, 30];
  23391. var RICH_TEXT_GAPS = ['', '\n', '\n\n', '\n\n\n'];
  23392. // eslint-disable-next-line max-len
  23393. function createTooltipMarkup(type, option) {
  23394. option.type = type;
  23395. return option;
  23396. }
  23397. function isSectionFragment(frag) {
  23398. return frag.type === 'section';
  23399. }
  23400. function getBuilder(frag) {
  23401. return isSectionFragment(frag) ? buildSection : buildNameValue;
  23402. }
  23403. function getBlockGapLevel(frag) {
  23404. if (isSectionFragment(frag)) {
  23405. var gapLevel_1 = 0;
  23406. var subBlockLen = frag.blocks.length;
  23407. var hasInnerGap_1 = subBlockLen > 1 || subBlockLen > 0 && !frag.noHeader;
  23408. each(frag.blocks, function (subBlock) {
  23409. var subGapLevel = getBlockGapLevel(subBlock);
  23410. // If the some of the sub-blocks have some gaps (like 10px) inside, this block
  23411. // should use a larger gap (like 20px) to distinguish those sub-blocks.
  23412. if (subGapLevel >= gapLevel_1) {
  23413. gapLevel_1 = subGapLevel + +(hasInnerGap_1 && (
  23414. // 0 always can not be readable gap level.
  23415. !subGapLevel
  23416. // If no header, always keep the sub gap level. Otherwise
  23417. // look weird in case `multipleSeries`.
  23418. || isSectionFragment(subBlock) && !subBlock.noHeader));
  23419. }
  23420. });
  23421. return gapLevel_1;
  23422. }
  23423. return 0;
  23424. }
  23425. function buildSection(ctx, fragment, topMarginForOuterGap, toolTipTextStyle) {
  23426. var noHeader = fragment.noHeader;
  23427. var gaps = getGap(getBlockGapLevel(fragment));
  23428. var subMarkupTextList = [];
  23429. var subBlocks = fragment.blocks || [];
  23430. assert(!subBlocks || isArray(subBlocks));
  23431. subBlocks = subBlocks || [];
  23432. var orderMode = ctx.orderMode;
  23433. if (fragment.sortBlocks && orderMode) {
  23434. subBlocks = subBlocks.slice();
  23435. var orderMap = {
  23436. valueAsc: 'asc',
  23437. valueDesc: 'desc'
  23438. };
  23439. if (hasOwn(orderMap, orderMode)) {
  23440. var comparator_1 = new SortOrderComparator(orderMap[orderMode], null);
  23441. subBlocks.sort(function (a, b) {
  23442. return comparator_1.evaluate(a.sortParam, b.sortParam);
  23443. });
  23444. }
  23445. // FIXME 'seriesDesc' necessary?
  23446. else if (orderMode === 'seriesDesc') {
  23447. subBlocks.reverse();
  23448. }
  23449. }
  23450. each(subBlocks, function (subBlock, idx) {
  23451. var valueFormatter = fragment.valueFormatter;
  23452. var subMarkupText = getBuilder(subBlock)(
  23453. // Inherit valueFormatter
  23454. valueFormatter ? extend(extend({}, ctx), {
  23455. valueFormatter: valueFormatter
  23456. }) : ctx, subBlock, idx > 0 ? gaps.html : 0, toolTipTextStyle);
  23457. subMarkupText != null && subMarkupTextList.push(subMarkupText);
  23458. });
  23459. var subMarkupText = ctx.renderMode === 'richText' ? subMarkupTextList.join(gaps.richText) : wrapBlockHTML(toolTipTextStyle, subMarkupTextList.join(''), noHeader ? topMarginForOuterGap : gaps.html);
  23460. if (noHeader) {
  23461. return subMarkupText;
  23462. }
  23463. var displayableHeader = makeValueReadable(fragment.header, 'ordinal', ctx.useUTC);
  23464. var nameStyle = getTooltipTextStyle(toolTipTextStyle, ctx.renderMode).nameStyle;
  23465. var tooltipLineHeight = getTooltipLineHeight(toolTipTextStyle);
  23466. if (ctx.renderMode === 'richText') {
  23467. return wrapInlineNameRichText(ctx, displayableHeader, nameStyle) + gaps.richText + subMarkupText;
  23468. } else {
  23469. return wrapBlockHTML(toolTipTextStyle, "<div style=\"" + nameStyle + ";" + tooltipLineHeight + ";\">" + encodeHTML(displayableHeader) + '</div>' + subMarkupText, topMarginForOuterGap);
  23470. }
  23471. }
  23472. function buildNameValue(ctx, fragment, topMarginForOuterGap, toolTipTextStyle) {
  23473. var renderMode = ctx.renderMode;
  23474. var noName = fragment.noName;
  23475. var noValue = fragment.noValue;
  23476. var noMarker = !fragment.markerType;
  23477. var name = fragment.name;
  23478. var useUTC = ctx.useUTC;
  23479. var valueFormatter = fragment.valueFormatter || ctx.valueFormatter || function (value) {
  23480. value = isArray(value) ? value : [value];
  23481. return map(value, function (val, idx) {
  23482. return makeValueReadable(val, isArray(valueTypeOption) ? valueTypeOption[idx] : valueTypeOption, useUTC);
  23483. });
  23484. };
  23485. if (noName && noValue) {
  23486. return;
  23487. }
  23488. var markerStr = noMarker ? '' : ctx.markupStyleCreator.makeTooltipMarker(fragment.markerType, fragment.markerColor || tokens.color.secondary, renderMode);
  23489. var readableName = noName ? '' : makeValueReadable(name, 'ordinal', useUTC);
  23490. var valueTypeOption = fragment.valueType;
  23491. var readableValueList = noValue ? [] : valueFormatter(fragment.value, fragment.dataIndex);
  23492. var valueAlignRight = !noMarker || !noName;
  23493. // It little weird if only value next to marker but far from marker.
  23494. var valueCloseToMarker = !noMarker && noName;
  23495. var _a = getTooltipTextStyle(toolTipTextStyle, renderMode),
  23496. nameStyle = _a.nameStyle,
  23497. valueStyle = _a.valueStyle;
  23498. return renderMode === 'richText' ? (noMarker ? '' : markerStr) + (noName ? '' : wrapInlineNameRichText(ctx, readableName, nameStyle))
  23499. // Value has commas inside, so use ' ' as delimiter for multiple values.
  23500. + (noValue ? '' : wrapInlineValueRichText(ctx, readableValueList, valueAlignRight, valueCloseToMarker, valueStyle)) : wrapBlockHTML(toolTipTextStyle, (noMarker ? '' : markerStr) + (noName ? '' : wrapInlineNameHTML(readableName, !noMarker, nameStyle)) + (noValue ? '' : wrapInlineValueHTML(readableValueList, valueAlignRight, valueCloseToMarker, valueStyle)), topMarginForOuterGap);
  23501. }
  23502. /**
  23503. * @return markupText. null/undefined means no content.
  23504. */
  23505. function buildTooltipMarkup(fragment, markupStyleCreator, renderMode, orderMode, useUTC, toolTipTextStyle) {
  23506. if (!fragment) {
  23507. return;
  23508. }
  23509. var builder = getBuilder(fragment);
  23510. var ctx = {
  23511. useUTC: useUTC,
  23512. renderMode: renderMode,
  23513. orderMode: orderMode,
  23514. markupStyleCreator: markupStyleCreator,
  23515. valueFormatter: fragment.valueFormatter
  23516. };
  23517. return builder(ctx, fragment, 0, toolTipTextStyle);
  23518. }
  23519. function getGap(gapLevel) {
  23520. return {
  23521. html: HTML_GAPS[gapLevel],
  23522. richText: RICH_TEXT_GAPS[gapLevel]
  23523. };
  23524. }
  23525. function wrapBlockHTML(textStyle, encodedContent, topGap) {
  23526. var clearfix = '<div style="clear:both"></div>';
  23527. var marginCSS = "margin: " + topGap + "px 0 0";
  23528. var tooltipLineHeight = getTooltipLineHeight(textStyle);
  23529. return "<div style=\"" + marginCSS + ";" + tooltipLineHeight + ";\">" + encodedContent + clearfix + '</div>';
  23530. }
  23531. function wrapInlineNameHTML(name, leftHasMarker, style) {
  23532. var marginCss = leftHasMarker ? 'margin-left:2px' : '';
  23533. return "<span style=\"" + style + ";" + marginCss + "\">" + encodeHTML(name) + '</span>';
  23534. }
  23535. function wrapInlineValueHTML(valueList, alignRight, valueCloseToMarker, style) {
  23536. // Do not too close to marker, considering there are multiple values separated by spaces.
  23537. var paddingStr = valueCloseToMarker ? '10px' : '20px';
  23538. var alignCSS = alignRight ? "float:right;margin-left:" + paddingStr : '';
  23539. valueList = isArray(valueList) ? valueList : [valueList];
  23540. return "<span style=\"" + alignCSS + ";" + style + "\">"
  23541. // Value has commas inside, so use ' ' as delimiter for multiple values.
  23542. + map(valueList, function (value) {
  23543. return encodeHTML(value);
  23544. }).join('&nbsp;&nbsp;') + '</span>';
  23545. }
  23546. function wrapInlineNameRichText(ctx, name, style) {
  23547. return ctx.markupStyleCreator.wrapRichTextStyle(name, style);
  23548. }
  23549. function wrapInlineValueRichText(ctx, values, alignRight, valueCloseToMarker, style) {
  23550. var styles = [style];
  23551. var paddingLeft = valueCloseToMarker ? 10 : 20;
  23552. alignRight && styles.push({
  23553. padding: [0, 0, 0, paddingLeft],
  23554. align: 'right'
  23555. });
  23556. // Value has commas inside, so use ' ' as delimiter for multiple values.
  23557. return ctx.markupStyleCreator.wrapRichTextStyle(isArray(values) ? values.join(' ') : values, styles);
  23558. }
  23559. function retrieveVisualColorForTooltipMarker(series, dataIndex) {
  23560. var style = series.getData().getItemVisual(dataIndex, 'style');
  23561. var color = style[series.visualDrawType];
  23562. return convertToColorString(color);
  23563. }
  23564. function getPaddingFromTooltipModel(model, renderMode) {
  23565. var padding = model.get('padding');
  23566. return padding != null ? padding
  23567. // We give slightly different to look pretty.
  23568. : renderMode === 'richText' ? [8, 10] : 10;
  23569. }
  23570. /**
  23571. * The major feature is generate styles for `renderMode: 'richText'`.
  23572. * But it also serves `renderMode: 'html'` to provide
  23573. * "renderMode-independent" API.
  23574. */
  23575. var TooltipMarkupStyleCreator = /** @class */function () {
  23576. function TooltipMarkupStyleCreator() {
  23577. this.richTextStyles = {};
  23578. // Notice that "generate a style name" usually happens repeatedly when mouse is moving and
  23579. // a tooltip is displayed. So we put the `_nextStyleNameId` as a member of each creator
  23580. // rather than static shared by all creators (which will cause it increase to fast).
  23581. this._nextStyleNameId = getRandomIdBase();
  23582. }
  23583. TooltipMarkupStyleCreator.prototype._generateStyleName = function () {
  23584. return '__EC_aUTo_' + this._nextStyleNameId++;
  23585. };
  23586. TooltipMarkupStyleCreator.prototype.makeTooltipMarker = function (markerType, colorStr, renderMode) {
  23587. var markerId = renderMode === 'richText' ? this._generateStyleName() : null;
  23588. var marker = getTooltipMarker({
  23589. color: colorStr,
  23590. type: markerType,
  23591. renderMode: renderMode,
  23592. markerId: markerId
  23593. });
  23594. if (isString(marker)) {
  23595. return marker;
  23596. } else {
  23597. if ("development" !== 'production') {
  23598. assert(markerId);
  23599. }
  23600. this.richTextStyles[markerId] = marker.style;
  23601. return marker.content;
  23602. }
  23603. };
  23604. /**
  23605. * @usage
  23606. * ```ts
  23607. * const styledText = markupStyleCreator.wrapRichTextStyle([
  23608. * // The styles will be auto merged.
  23609. * {
  23610. * fontSize: 12,
  23611. * color: 'blue'
  23612. * },
  23613. * {
  23614. * padding: 20
  23615. * }
  23616. * ]);
  23617. * ```
  23618. */
  23619. TooltipMarkupStyleCreator.prototype.wrapRichTextStyle = function (text, styles) {
  23620. var finalStl = {};
  23621. if (isArray(styles)) {
  23622. each(styles, function (stl) {
  23623. return extend(finalStl, stl);
  23624. });
  23625. } else {
  23626. extend(finalStl, styles);
  23627. }
  23628. var styleName = this._generateStyleName();
  23629. this.richTextStyles[styleName] = finalStl;
  23630. return "{" + styleName + "|" + text + "}";
  23631. };
  23632. return TooltipMarkupStyleCreator;
  23633. }();
  23634. function defaultSeriesFormatTooltip(opt) {
  23635. var series = opt.series;
  23636. var dataIndex = opt.dataIndex;
  23637. var multipleSeries = opt.multipleSeries;
  23638. var data = series.getData();
  23639. var tooltipDims = data.mapDimensionsAll('defaultedTooltip');
  23640. var tooltipDimLen = tooltipDims.length;
  23641. var value = series.getRawValue(dataIndex);
  23642. var isValueArr = isArray(value);
  23643. var markerColor = retrieveVisualColorForTooltipMarker(series, dataIndex);
  23644. // Complicated rule for pretty tooltip.
  23645. var inlineValue;
  23646. var inlineValueType;
  23647. var subBlocks;
  23648. var sortParam;
  23649. if (tooltipDimLen > 1 || isValueArr && !tooltipDimLen) {
  23650. var formatArrResult = formatTooltipArrayValue(value, series, dataIndex, tooltipDims, markerColor);
  23651. inlineValue = formatArrResult.inlineValues;
  23652. inlineValueType = formatArrResult.inlineValueTypes;
  23653. subBlocks = formatArrResult.blocks;
  23654. // Only support tooltip sort by the first inline value. It's enough in most cases.
  23655. sortParam = formatArrResult.inlineValues[0];
  23656. } else if (tooltipDimLen) {
  23657. var dimInfo = data.getDimensionInfo(tooltipDims[0]);
  23658. sortParam = inlineValue = retrieveRawValue(data, dataIndex, tooltipDims[0]);
  23659. inlineValueType = dimInfo.type;
  23660. } else {
  23661. sortParam = inlineValue = isValueArr ? value[0] : value;
  23662. }
  23663. // Do not show generated series name. It might not be readable.
  23664. var seriesNameSpecified = isNameSpecified(series);
  23665. var seriesName = seriesNameSpecified && series.name || '';
  23666. var itemName = data.getName(dataIndex);
  23667. var inlineName = multipleSeries ? seriesName : itemName;
  23668. return createTooltipMarkup('section', {
  23669. header: seriesName,
  23670. // When series name is not specified, do not show a header line with only '-'.
  23671. // This case always happens in tooltip.trigger: 'item'.
  23672. noHeader: multipleSeries || !seriesNameSpecified,
  23673. sortParam: sortParam,
  23674. blocks: [createTooltipMarkup('nameValue', {
  23675. markerType: 'item',
  23676. markerColor: markerColor,
  23677. // Do not mix display seriesName and itemName in one tooltip,
  23678. // which might confuses users.
  23679. name: inlineName,
  23680. // name dimension might be auto assigned, where the name might
  23681. // be not readable. So we check trim here.
  23682. noName: !trim(inlineName),
  23683. value: inlineValue,
  23684. valueType: inlineValueType,
  23685. dataIndex: dataIndex
  23686. })].concat(subBlocks || [])
  23687. });
  23688. }
  23689. function formatTooltipArrayValue(value, series, dataIndex, tooltipDims, colorStr) {
  23690. // check: category-no-encode-has-axis-data in dataset.html
  23691. var data = series.getData();
  23692. var isValueMultipleLine = reduce(value, function (isValueMultipleLine, val, idx) {
  23693. var dimItem = data.getDimensionInfo(idx);
  23694. return isValueMultipleLine = isValueMultipleLine || dimItem && dimItem.tooltip !== false && dimItem.displayName != null;
  23695. }, false);
  23696. var inlineValues = [];
  23697. var inlineValueTypes = [];
  23698. var blocks = [];
  23699. tooltipDims.length ? each(tooltipDims, function (dim) {
  23700. setEachItem(retrieveRawValue(data, dataIndex, dim), dim);
  23701. })
  23702. // By default, all dims is used on tooltip.
  23703. : each(value, setEachItem);
  23704. function setEachItem(val, dim) {
  23705. var dimInfo = data.getDimensionInfo(dim);
  23706. // If `dimInfo.tooltip` is not set, show tooltip.
  23707. if (!dimInfo || dimInfo.otherDims.tooltip === false) {
  23708. return;
  23709. }
  23710. if (isValueMultipleLine) {
  23711. blocks.push(createTooltipMarkup('nameValue', {
  23712. markerType: 'subItem',
  23713. markerColor: colorStr,
  23714. name: dimInfo.displayName,
  23715. value: val,
  23716. valueType: dimInfo.type
  23717. }));
  23718. } else {
  23719. inlineValues.push(val);
  23720. inlineValueTypes.push(dimInfo.type);
  23721. }
  23722. }
  23723. return {
  23724. inlineValues: inlineValues,
  23725. inlineValueTypes: inlineValueTypes,
  23726. blocks: blocks
  23727. };
  23728. }
  23729. var inner$1 = makeInner();
  23730. function getSelectionKey(data, dataIndex) {
  23731. return data.getName(dataIndex) || data.getId(dataIndex);
  23732. }
  23733. var SERIES_UNIVERSAL_TRANSITION_PROP = '__universalTransitionEnabled';
  23734. var SeriesModel = /** @class */function (_super) {
  23735. __extends(SeriesModel, _super);
  23736. function SeriesModel() {
  23737. // [Caution]: Because this class or desecendants can be used as `XXX.extend(subProto)`,
  23738. // the class members must not be initialized in constructor or declaration place.
  23739. // Otherwise there is bad case:
  23740. // class A {xxx = 1;}
  23741. // enableClassExtend(A);
  23742. // class B extends A {}
  23743. // var C = B.extend({xxx: 5});
  23744. // var c = new C();
  23745. // console.log(c.xxx); // expect 5 but always 1.
  23746. var _this = _super !== null && _super.apply(this, arguments) || this;
  23747. // ---------------------------------------
  23748. // Props about data selection
  23749. // ---------------------------------------
  23750. _this._selectedDataIndicesMap = {};
  23751. return _this;
  23752. }
  23753. SeriesModel.prototype.init = function (option, parentModel, ecModel) {
  23754. this.seriesIndex = this.componentIndex;
  23755. this.dataTask = createTask({
  23756. count: dataTaskCount,
  23757. reset: dataTaskReset
  23758. });
  23759. this.dataTask.context = {
  23760. model: this
  23761. };
  23762. this.mergeDefaultAndTheme(option, ecModel);
  23763. var sourceManager = inner$1(this).sourceManager = new SourceManager(this);
  23764. sourceManager.prepareSource();
  23765. var data = this.getInitialData(option, ecModel);
  23766. wrapData(data, this);
  23767. this.dataTask.context.data = data;
  23768. if ("development" !== 'production') {
  23769. assert(data, 'getInitialData returned invalid data.');
  23770. }
  23771. inner$1(this).dataBeforeProcessed = data;
  23772. // If we reverse the order (make data firstly, and then make
  23773. // dataBeforeProcessed by cloneShallow), cloneShallow will
  23774. // cause data.graph.data !== data when using
  23775. // module:echarts/data/Graph or module:echarts/data/Tree.
  23776. // See module:echarts/data/helper/linkSeriesData
  23777. // Theoretically, it is unreasonable to call `seriesModel.getData()` in the model
  23778. // init or merge stage, because the data can be restored. So we do not `restoreData`
  23779. // and `setData` here, which forbids calling `seriesModel.getData()` in this stage.
  23780. // Call `seriesModel.getRawData()` instead.
  23781. // this.restoreData();
  23782. autoSeriesName(this);
  23783. this._initSelectedMapFromData(data);
  23784. };
  23785. /**
  23786. * Util for merge default and theme to option
  23787. */
  23788. SeriesModel.prototype.mergeDefaultAndTheme = function (option, ecModel) {
  23789. var layoutMode = fetchLayoutMode(this);
  23790. var inputPositionParams = layoutMode ? getLayoutParams(option) : {};
  23791. // Backward compat: using subType on theme.
  23792. // But if name duplicate between series subType
  23793. // (for example: parallel) add component mainType,
  23794. // add suffix 'Series'.
  23795. var themeSubType = this.subType;
  23796. if (ComponentModel.hasClass(themeSubType)) {
  23797. themeSubType += 'Series';
  23798. }
  23799. merge(option, ecModel.getTheme().get(this.subType));
  23800. merge(option, this.getDefaultOption());
  23801. // Default label emphasis `show`
  23802. defaultEmphasis(option, 'label', ['show']);
  23803. this.fillDataTextStyle(option.data);
  23804. if (layoutMode) {
  23805. mergeLayoutParam(option, inputPositionParams, layoutMode);
  23806. }
  23807. };
  23808. SeriesModel.prototype.mergeOption = function (newSeriesOption, ecModel) {
  23809. // this.settingTask.dirty();
  23810. newSeriesOption = merge(this.option, newSeriesOption, true);
  23811. this.fillDataTextStyle(newSeriesOption.data);
  23812. var layoutMode = fetchLayoutMode(this);
  23813. if (layoutMode) {
  23814. mergeLayoutParam(this.option, newSeriesOption, layoutMode);
  23815. }
  23816. var sourceManager = inner$1(this).sourceManager;
  23817. sourceManager.dirty();
  23818. sourceManager.prepareSource();
  23819. var data = this.getInitialData(newSeriesOption, ecModel);
  23820. wrapData(data, this);
  23821. this.dataTask.dirty();
  23822. this.dataTask.context.data = data;
  23823. inner$1(this).dataBeforeProcessed = data;
  23824. autoSeriesName(this);
  23825. this._initSelectedMapFromData(data);
  23826. };
  23827. SeriesModel.prototype.fillDataTextStyle = function (data) {
  23828. // Default data label emphasis `show`
  23829. // FIXME Tree structure data ?
  23830. // FIXME Performance ?
  23831. if (data && !isTypedArray(data)) {
  23832. var props = ['show'];
  23833. for (var i = 0; i < data.length; i++) {
  23834. if (data[i] && data[i].label) {
  23835. defaultEmphasis(data[i], 'label', props);
  23836. }
  23837. }
  23838. }
  23839. };
  23840. /**
  23841. * Init a data structure from data related option in series
  23842. * Must be overridden.
  23843. */
  23844. SeriesModel.prototype.getInitialData = function (option, ecModel) {
  23845. return;
  23846. };
  23847. /**
  23848. * Append data to list
  23849. */
  23850. SeriesModel.prototype.appendData = function (params) {
  23851. // FIXME ???
  23852. // (1) If data from dataset, forbidden append.
  23853. // (2) support append data of dataset.
  23854. var data = this.getRawData();
  23855. data.appendData(params.data);
  23856. };
  23857. /**
  23858. * Consider some method like `filter`, `map` need make new data,
  23859. * We should make sure that `seriesModel.getData()` get correct
  23860. * data in the stream procedure. So we fetch data from upstream
  23861. * each time `task.perform` called.
  23862. */
  23863. SeriesModel.prototype.getData = function (dataType) {
  23864. var task = getCurrentTask(this);
  23865. if (task) {
  23866. var data = task.context.data;
  23867. return dataType == null || !data.getLinkedData ? data : data.getLinkedData(dataType);
  23868. } else {
  23869. // When series is not alive (that may happen when click toolbox
  23870. // restore or setOption with not merge mode), series data may
  23871. // be still need to judge animation or something when graphic
  23872. // elements want to know whether fade out.
  23873. return inner$1(this).data;
  23874. }
  23875. };
  23876. SeriesModel.prototype.getAllData = function () {
  23877. var mainData = this.getData();
  23878. return mainData && mainData.getLinkedDataAll ? mainData.getLinkedDataAll() : [{
  23879. data: mainData
  23880. }];
  23881. };
  23882. SeriesModel.prototype.setData = function (data) {
  23883. var task = getCurrentTask(this);
  23884. if (task) {
  23885. var context = task.context;
  23886. // Consider case: filter, data sample.
  23887. // FIXME:TS never used, so comment it
  23888. // if (context.data !== data && task.modifyOutputEnd) {
  23889. // task.setOutputEnd(data.count());
  23890. // }
  23891. context.outputData = data;
  23892. // Caution: setData should update context.data,
  23893. // Because getData may be called multiply in a
  23894. // single stage and expect to get the data just
  23895. // set. (For example, AxisProxy, x y both call
  23896. // getData and setDate sequentially).
  23897. // So the context.data should be fetched from
  23898. // upstream each time when a stage starts to be
  23899. // performed.
  23900. if (task !== this.dataTask) {
  23901. context.data = data;
  23902. }
  23903. }
  23904. inner$1(this).data = data;
  23905. };
  23906. SeriesModel.prototype.getEncode = function () {
  23907. var encode = this.get('encode', true);
  23908. if (encode) {
  23909. return createHashMap(encode);
  23910. }
  23911. };
  23912. SeriesModel.prototype.getSourceManager = function () {
  23913. return inner$1(this).sourceManager;
  23914. };
  23915. SeriesModel.prototype.getSource = function () {
  23916. return this.getSourceManager().getSource();
  23917. };
  23918. /**
  23919. * Get data before processed
  23920. */
  23921. SeriesModel.prototype.getRawData = function () {
  23922. return inner$1(this).dataBeforeProcessed;
  23923. };
  23924. SeriesModel.prototype.getColorBy = function () {
  23925. var colorBy = this.get('colorBy');
  23926. return colorBy || 'series';
  23927. };
  23928. SeriesModel.prototype.isColorBySeries = function () {
  23929. return this.getColorBy() === 'series';
  23930. };
  23931. /**
  23932. * Get base axis if has coordinate system and has axis.
  23933. * By default use coordSys.getBaseAxis();
  23934. * Can be overridden for some chart.
  23935. * @return {type} description
  23936. */
  23937. SeriesModel.prototype.getBaseAxis = function () {
  23938. var coordSys = this.coordinateSystem;
  23939. // @ts-ignore
  23940. return coordSys && coordSys.getBaseAxis && coordSys.getBaseAxis();
  23941. };
  23942. /**
  23943. * Retrieve the index of nearest value in the view coordinate.
  23944. * Data position is compared with each axis's dataToCoord.
  23945. *
  23946. * @param axisDim axis dimension
  23947. * @param dim data dimension
  23948. * @param value
  23949. * @param [maxDistance=Infinity] The maximum distance in view coordinate space
  23950. * @return If and only if multiple indices has
  23951. * the same value, they are put to the result.
  23952. */
  23953. SeriesModel.prototype.indicesOfNearest = function (axisDim, dim, value, maxDistance) {
  23954. var data = this.getData();
  23955. var coordSys = this.coordinateSystem;
  23956. var axis = coordSys && coordSys.getAxis(axisDim);
  23957. if (!coordSys || !axis) {
  23958. return [];
  23959. }
  23960. var targetCoord = axis.dataToCoord(value);
  23961. if (maxDistance == null) {
  23962. maxDistance = Infinity;
  23963. }
  23964. var nearestIndices = [];
  23965. var minDist = Infinity;
  23966. var minDiff = -1;
  23967. var nearestIndicesLen = 0;
  23968. data.each(dim, function (dimValue, idx) {
  23969. var dataCoord = axis.dataToCoord(dimValue);
  23970. var diff = targetCoord - dataCoord;
  23971. var dist = Math.abs(diff);
  23972. if (dist <= maxDistance) {
  23973. // When the `value` is at the middle of `this.get(dim, i)` and `this.get(dim, i+1)`,
  23974. // we'd better not push both of them to `nearestIndices`, otherwise it is easy to
  23975. // get more than one item in `nearestIndices` (more specifically, in `tooltip`).
  23976. // So we choose the one that `diff >= 0` in this case.
  23977. // But if `this.get(dim, i)` and `this.get(dim, j)` get the same value, both of them
  23978. // should be push to `nearestIndices`.
  23979. if (dist < minDist || dist === minDist && diff >= 0 && minDiff < 0) {
  23980. minDist = dist;
  23981. minDiff = diff;
  23982. nearestIndicesLen = 0;
  23983. }
  23984. if (diff === minDiff) {
  23985. nearestIndices[nearestIndicesLen++] = idx;
  23986. }
  23987. }
  23988. });
  23989. nearestIndices.length = nearestIndicesLen;
  23990. return nearestIndices;
  23991. };
  23992. /**
  23993. * Default tooltip formatter
  23994. *
  23995. * @param dataIndex
  23996. * @param multipleSeries
  23997. * @param dataType
  23998. * @param renderMode valid values: 'html'(by default) and 'richText'.
  23999. * 'html' is used for rendering tooltip in extra DOM form, and the result
  24000. * string is used as DOM HTML content.
  24001. * 'richText' is used for rendering tooltip in rich text form, for those where
  24002. * DOM operation is not supported.
  24003. * @return formatted tooltip with `html` and `markers`
  24004. * Notice: The override method can also return string
  24005. */
  24006. SeriesModel.prototype.formatTooltip = function (dataIndex, multipleSeries, dataType) {
  24007. return defaultSeriesFormatTooltip({
  24008. series: this,
  24009. dataIndex: dataIndex,
  24010. multipleSeries: multipleSeries
  24011. });
  24012. };
  24013. SeriesModel.prototype.isAnimationEnabled = function () {
  24014. var ecModel = this.ecModel;
  24015. // Disable animation if using echarts in node but not give ssr flag.
  24016. // In ssr mode, renderToString will generate svg with css animation.
  24017. if (env.node && !(ecModel && ecModel.ssr)) {
  24018. return false;
  24019. }
  24020. var animationEnabled = this.getShallow('animation');
  24021. if (animationEnabled) {
  24022. if (this.getData().count() > this.getShallow('animationThreshold')) {
  24023. animationEnabled = false;
  24024. }
  24025. }
  24026. return !!animationEnabled;
  24027. };
  24028. SeriesModel.prototype.restoreData = function () {
  24029. this.dataTask.dirty();
  24030. };
  24031. SeriesModel.prototype.getColorFromPalette = function (name, scope, requestColorNum) {
  24032. var ecModel = this.ecModel;
  24033. // PENDING
  24034. var color = PaletteMixin.prototype.getColorFromPalette.call(this, name, scope, requestColorNum);
  24035. if (!color) {
  24036. color = ecModel.getColorFromPalette(name, scope, requestColorNum);
  24037. }
  24038. return color;
  24039. };
  24040. /**
  24041. * Use `data.mapDimensionsAll(coordDim)` instead.
  24042. * @deprecated
  24043. */
  24044. SeriesModel.prototype.coordDimToDataDim = function (coordDim) {
  24045. return this.getRawData().mapDimensionsAll(coordDim);
  24046. };
  24047. /**
  24048. * Get progressive rendering count each step
  24049. */
  24050. SeriesModel.prototype.getProgressive = function () {
  24051. return this.get('progressive');
  24052. };
  24053. /**
  24054. * Get progressive rendering count each step
  24055. */
  24056. SeriesModel.prototype.getProgressiveThreshold = function () {
  24057. return this.get('progressiveThreshold');
  24058. };
  24059. // PENGING If selectedMode is null ?
  24060. SeriesModel.prototype.select = function (innerDataIndices, dataType) {
  24061. this._innerSelect(this.getData(dataType), innerDataIndices);
  24062. };
  24063. SeriesModel.prototype.unselect = function (innerDataIndices, dataType) {
  24064. var selectedMap = this.option.selectedMap;
  24065. if (!selectedMap) {
  24066. return;
  24067. }
  24068. var selectedMode = this.option.selectedMode;
  24069. var data = this.getData(dataType);
  24070. if (selectedMode === 'series' || selectedMap === 'all') {
  24071. this.option.selectedMap = {};
  24072. this._selectedDataIndicesMap = {};
  24073. return;
  24074. }
  24075. for (var i = 0; i < innerDataIndices.length; i++) {
  24076. var dataIndex = innerDataIndices[i];
  24077. var nameOrId = getSelectionKey(data, dataIndex);
  24078. selectedMap[nameOrId] = false;
  24079. this._selectedDataIndicesMap[nameOrId] = -1;
  24080. }
  24081. };
  24082. SeriesModel.prototype.toggleSelect = function (innerDataIndices, dataType) {
  24083. var tmpArr = [];
  24084. for (var i = 0; i < innerDataIndices.length; i++) {
  24085. tmpArr[0] = innerDataIndices[i];
  24086. this.isSelected(innerDataIndices[i], dataType) ? this.unselect(tmpArr, dataType) : this.select(tmpArr, dataType);
  24087. }
  24088. };
  24089. SeriesModel.prototype.getSelectedDataIndices = function () {
  24090. if (this.option.selectedMap === 'all') {
  24091. return [].slice.call(this.getData().getIndices());
  24092. }
  24093. var selectedDataIndicesMap = this._selectedDataIndicesMap;
  24094. var nameOrIds = keys(selectedDataIndicesMap);
  24095. var dataIndices = [];
  24096. for (var i = 0; i < nameOrIds.length; i++) {
  24097. var dataIndex = selectedDataIndicesMap[nameOrIds[i]];
  24098. if (dataIndex >= 0) {
  24099. dataIndices.push(dataIndex);
  24100. }
  24101. }
  24102. return dataIndices;
  24103. };
  24104. SeriesModel.prototype.isSelected = function (dataIndex, dataType) {
  24105. var selectedMap = this.option.selectedMap;
  24106. if (!selectedMap) {
  24107. return false;
  24108. }
  24109. var data = this.getData(dataType);
  24110. return (selectedMap === 'all' || selectedMap[getSelectionKey(data, dataIndex)]) && !data.getItemModel(dataIndex).get(['select', 'disabled']);
  24111. };
  24112. SeriesModel.prototype.isUniversalTransitionEnabled = function () {
  24113. if (this[SERIES_UNIVERSAL_TRANSITION_PROP]) {
  24114. return true;
  24115. }
  24116. var universalTransitionOpt = this.option.universalTransition;
  24117. // Quick reject
  24118. if (!universalTransitionOpt) {
  24119. return false;
  24120. }
  24121. if (universalTransitionOpt === true) {
  24122. return true;
  24123. }
  24124. // Can be simply 'universalTransition: true'
  24125. return universalTransitionOpt && universalTransitionOpt.enabled;
  24126. };
  24127. SeriesModel.prototype._innerSelect = function (data, innerDataIndices) {
  24128. var _a, _b;
  24129. var option = this.option;
  24130. var selectedMode = option.selectedMode;
  24131. var len = innerDataIndices.length;
  24132. if (!selectedMode || !len) {
  24133. return;
  24134. }
  24135. if (selectedMode === 'series') {
  24136. option.selectedMap = 'all';
  24137. } else if (selectedMode === 'multiple') {
  24138. if (!isObject(option.selectedMap)) {
  24139. option.selectedMap = {};
  24140. }
  24141. var selectedMap = option.selectedMap;
  24142. for (var i = 0; i < len; i++) {
  24143. var dataIndex = innerDataIndices[i];
  24144. // TODO different types of data share same object.
  24145. var nameOrId = getSelectionKey(data, dataIndex);
  24146. selectedMap[nameOrId] = true;
  24147. this._selectedDataIndicesMap[nameOrId] = data.getRawIndex(dataIndex);
  24148. }
  24149. } else if (selectedMode === 'single' || selectedMode === true) {
  24150. var lastDataIndex = innerDataIndices[len - 1];
  24151. var nameOrId = getSelectionKey(data, lastDataIndex);
  24152. option.selectedMap = (_a = {}, _a[nameOrId] = true, _a);
  24153. this._selectedDataIndicesMap = (_b = {}, _b[nameOrId] = data.getRawIndex(lastDataIndex), _b);
  24154. }
  24155. };
  24156. SeriesModel.prototype._initSelectedMapFromData = function (data) {
  24157. // Ignore select info in data if selectedMap exists.
  24158. // NOTE It's only for legacy usage. edge data is not supported.
  24159. if (this.option.selectedMap) {
  24160. return;
  24161. }
  24162. var dataIndices = [];
  24163. if (data.hasItemOption) {
  24164. data.each(function (idx) {
  24165. var rawItem = data.getRawDataItem(idx);
  24166. if (rawItem && rawItem.selected) {
  24167. dataIndices.push(idx);
  24168. }
  24169. });
  24170. }
  24171. if (dataIndices.length > 0) {
  24172. this._innerSelect(data, dataIndices);
  24173. }
  24174. };
  24175. // /**
  24176. // * @see {module:echarts/stream/Scheduler}
  24177. // */
  24178. // abstract pipeTask: null
  24179. SeriesModel.registerClass = function (clz) {
  24180. return ComponentModel.registerClass(clz);
  24181. };
  24182. SeriesModel.protoInitialize = function () {
  24183. var proto = SeriesModel.prototype;
  24184. proto.type = 'series.__base__';
  24185. proto.seriesIndex = 0;
  24186. proto.ignoreStyleOnData = false;
  24187. proto.hasSymbolVisual = false;
  24188. proto.defaultSymbol = 'circle';
  24189. // Make sure the values can be accessed!
  24190. proto.visualStyleAccessPath = 'itemStyle';
  24191. proto.visualDrawType = 'fill';
  24192. }();
  24193. return SeriesModel;
  24194. }(ComponentModel);
  24195. mixin(SeriesModel, DataFormatMixin);
  24196. mixin(SeriesModel, PaletteMixin);
  24197. mountExtend(SeriesModel, ComponentModel);
  24198. /**
  24199. * MUST be called after `prepareSource` called
  24200. * Here we need to make auto series, especially for auto legend. But we
  24201. * do not modify series.name in option to avoid side effects.
  24202. */
  24203. function autoSeriesName(seriesModel) {
  24204. // User specified name has higher priority, otherwise it may cause
  24205. // series can not be queried unexpectedly.
  24206. var name = seriesModel.name;
  24207. if (!isNameSpecified(seriesModel)) {
  24208. seriesModel.name = getSeriesAutoName(seriesModel) || name;
  24209. }
  24210. }
  24211. function getSeriesAutoName(seriesModel) {
  24212. var data = seriesModel.getRawData();
  24213. var dataDims = data.mapDimensionsAll('seriesName');
  24214. var nameArr = [];
  24215. each(dataDims, function (dataDim) {
  24216. var dimInfo = data.getDimensionInfo(dataDim);
  24217. dimInfo.displayName && nameArr.push(dimInfo.displayName);
  24218. });
  24219. return nameArr.join(' ');
  24220. }
  24221. function dataTaskCount(context) {
  24222. return context.model.getRawData().count();
  24223. }
  24224. function dataTaskReset(context) {
  24225. var seriesModel = context.model;
  24226. seriesModel.setData(seriesModel.getRawData().cloneShallow());
  24227. return dataTaskProgress;
  24228. }
  24229. function dataTaskProgress(param, context) {
  24230. // Avoid repeat cloneShallow when data just created in reset.
  24231. if (context.outputData && param.end > context.outputData.count()) {
  24232. context.model.getRawData().cloneShallow(context.outputData);
  24233. }
  24234. }
  24235. // TODO refactor
  24236. function wrapData(data, seriesModel) {
  24237. each(concatArray(data.CHANGABLE_METHODS, data.DOWNSAMPLE_METHODS), function (methodName) {
  24238. data.wrapMethod(methodName, curry(onDataChange, seriesModel));
  24239. });
  24240. }
  24241. function onDataChange(seriesModel, newList) {
  24242. var task = getCurrentTask(seriesModel);
  24243. if (task) {
  24244. // Consider case: filter, selectRange
  24245. task.setOutputEnd((newList || this).count());
  24246. }
  24247. return newList;
  24248. }
  24249. function getCurrentTask(seriesModel) {
  24250. var scheduler = (seriesModel.ecModel || {}).scheduler;
  24251. var pipeline = scheduler && scheduler.getPipeline(seriesModel.uid);
  24252. if (pipeline) {
  24253. // When pipline finished, the currrentTask keep the last
  24254. // task (renderTask).
  24255. var task = pipeline.currentTask;
  24256. if (task) {
  24257. var agentStubMap = task.agentStubMap;
  24258. if (agentStubMap) {
  24259. task = agentStubMap.get(seriesModel.uid);
  24260. }
  24261. }
  24262. return task;
  24263. }
  24264. }
  24265. var ComponentView = /** @class */function () {
  24266. function ComponentView() {
  24267. this.group = new Group();
  24268. this.uid = getUID('viewComponent');
  24269. }
  24270. ComponentView.prototype.init = function (ecModel, api) {};
  24271. ComponentView.prototype.render = function (model, ecModel, api, payload) {};
  24272. ComponentView.prototype.dispose = function (ecModel, api) {};
  24273. ComponentView.prototype.updateView = function (model, ecModel, api, payload) {
  24274. // Do nothing;
  24275. };
  24276. ComponentView.prototype.updateLayout = function (model, ecModel, api, payload) {
  24277. // Do nothing;
  24278. };
  24279. ComponentView.prototype.updateVisual = function (model, ecModel, api, payload) {
  24280. // Do nothing;
  24281. };
  24282. /**
  24283. * Hook for toggle blur target series.
  24284. * Can be used in marker for blur or leave blur the markers
  24285. */
  24286. ComponentView.prototype.toggleBlurSeries = function (seriesModels, isBlur, ecModel) {
  24287. // Do nothing;
  24288. };
  24289. /**
  24290. * Traverse the new rendered elements.
  24291. *
  24292. * It will traverse the new added element in progressive rendering.
  24293. * And traverse all in normal rendering.
  24294. */
  24295. ComponentView.prototype.eachRendered = function (cb) {
  24296. var group = this.group;
  24297. if (group) {
  24298. group.traverse(cb);
  24299. }
  24300. };
  24301. return ComponentView;
  24302. }();
  24303. enableClassExtend(ComponentView);
  24304. enableClassManagement(ComponentView);
  24305. /**
  24306. * @return {string} If large mode changed, return string 'reset';
  24307. */
  24308. function createRenderPlanner() {
  24309. var inner = makeInner();
  24310. return function (seriesModel) {
  24311. var fields = inner(seriesModel);
  24312. var pipelineContext = seriesModel.pipelineContext;
  24313. var originalLarge = !!fields.large;
  24314. var originalProgressive = !!fields.progressiveRender;
  24315. // FIXME: if the planner works on a filtered series, `pipelineContext` does not
  24316. // exists. See #11611 . Probably we need to modify this structure, see the comment
  24317. // on `performRawSeries` in `Schedular.js`.
  24318. var large = fields.large = !!(pipelineContext && pipelineContext.large);
  24319. var progressive = fields.progressiveRender = !!(pipelineContext && pipelineContext.progressiveRender);
  24320. return !!(originalLarge !== large || originalProgressive !== progressive) && 'reset';
  24321. };
  24322. }
  24323. var inner$2 = makeInner();
  24324. var renderPlanner = createRenderPlanner();
  24325. var ChartView = /** @class */function () {
  24326. function ChartView() {
  24327. this.group = new Group();
  24328. this.uid = getUID('viewChart');
  24329. this.renderTask = createTask({
  24330. plan: renderTaskPlan,
  24331. reset: renderTaskReset
  24332. });
  24333. this.renderTask.context = {
  24334. view: this
  24335. };
  24336. }
  24337. ChartView.prototype.init = function (ecModel, api) {};
  24338. ChartView.prototype.render = function (seriesModel, ecModel, api, payload) {
  24339. if ("development" !== 'production') {
  24340. throw new Error('render method must been implemented');
  24341. }
  24342. };
  24343. /**
  24344. * Highlight series or specified data item.
  24345. */
  24346. ChartView.prototype.highlight = function (seriesModel, ecModel, api, payload) {
  24347. var data = seriesModel.getData(payload && payload.dataType);
  24348. if (!data) {
  24349. if ("development" !== 'production') {
  24350. error("Unknown dataType " + payload.dataType);
  24351. }
  24352. return;
  24353. }
  24354. toggleHighlight(data, payload, 'emphasis');
  24355. };
  24356. /**
  24357. * Downplay series or specified data item.
  24358. */
  24359. ChartView.prototype.downplay = function (seriesModel, ecModel, api, payload) {
  24360. var data = seriesModel.getData(payload && payload.dataType);
  24361. if (!data) {
  24362. if ("development" !== 'production') {
  24363. error("Unknown dataType " + payload.dataType);
  24364. }
  24365. return;
  24366. }
  24367. toggleHighlight(data, payload, 'normal');
  24368. };
  24369. /**
  24370. * Remove self.
  24371. */
  24372. ChartView.prototype.remove = function (ecModel, api) {
  24373. this.group.removeAll();
  24374. };
  24375. /**
  24376. * Dispose self.
  24377. */
  24378. ChartView.prototype.dispose = function (ecModel, api) {};
  24379. ChartView.prototype.updateView = function (seriesModel, ecModel, api, payload) {
  24380. this.render(seriesModel, ecModel, api, payload);
  24381. };
  24382. // FIXME never used?
  24383. ChartView.prototype.updateLayout = function (seriesModel, ecModel, api, payload) {
  24384. this.render(seriesModel, ecModel, api, payload);
  24385. };
  24386. // FIXME never used?
  24387. ChartView.prototype.updateVisual = function (seriesModel, ecModel, api, payload) {
  24388. this.render(seriesModel, ecModel, api, payload);
  24389. };
  24390. /**
  24391. * Traverse the new rendered elements.
  24392. *
  24393. * It will traverse the new added element in progressive rendering.
  24394. * And traverse all in normal rendering.
  24395. */
  24396. ChartView.prototype.eachRendered = function (cb) {
  24397. traverseElements(this.group, cb);
  24398. };
  24399. ChartView.markUpdateMethod = function (payload, methodName) {
  24400. inner$2(payload).updateMethod = methodName;
  24401. };
  24402. ChartView.protoInitialize = function () {
  24403. var proto = ChartView.prototype;
  24404. proto.type = 'chart';
  24405. }();
  24406. return ChartView;
  24407. }();
  24408. /**
  24409. * Set state of single element
  24410. */
  24411. function elSetState(el, state, highlightDigit) {
  24412. if (el && isHighDownDispatcher(el)) {
  24413. (state === 'emphasis' ? enterEmphasis : leaveEmphasis)(el, highlightDigit);
  24414. }
  24415. }
  24416. function toggleHighlight(data, payload, state) {
  24417. var dataIndex = queryDataIndex(data, payload);
  24418. var highlightDigit = payload && payload.highlightKey != null ? getHighlightDigit(payload.highlightKey) : null;
  24419. if (dataIndex != null) {
  24420. each(normalizeToArray(dataIndex), function (dataIdx) {
  24421. elSetState(data.getItemGraphicEl(dataIdx), state, highlightDigit);
  24422. });
  24423. } else {
  24424. data.eachItemGraphicEl(function (el) {
  24425. elSetState(el, state, highlightDigit);
  24426. });
  24427. }
  24428. }
  24429. enableClassExtend(ChartView, ['dispose']);
  24430. enableClassManagement(ChartView);
  24431. function renderTaskPlan(context) {
  24432. return renderPlanner(context.model);
  24433. }
  24434. function renderTaskReset(context) {
  24435. var seriesModel = context.model;
  24436. var ecModel = context.ecModel;
  24437. var api = context.api;
  24438. var payload = context.payload;
  24439. // FIXME: remove updateView updateVisual
  24440. var progressiveRender = seriesModel.pipelineContext.progressiveRender;
  24441. var view = context.view;
  24442. var updateMethod = payload && inner$2(payload).updateMethod;
  24443. var methodName = progressiveRender ? 'incrementalPrepareRender' : updateMethod && view[updateMethod] ? updateMethod
  24444. // `appendData` is also supported when data amount
  24445. // is less than progressive threshold.
  24446. : 'render';
  24447. if (methodName !== 'render') {
  24448. view[methodName](seriesModel, ecModel, api, payload);
  24449. }
  24450. return progressMethodMap[methodName];
  24451. }
  24452. var progressMethodMap = {
  24453. incrementalPrepareRender: {
  24454. progress: function (params, context) {
  24455. context.view.incrementalRender(params, context.model, context.ecModel, context.api, context.payload);
  24456. }
  24457. },
  24458. render: {
  24459. // Put view.render in `progress` to support appendData. But in this case
  24460. // view.render should not be called in reset, otherwise it will be called
  24461. // twise. Use `forceFirstProgress` to make sure that view.render is called
  24462. // in any cases.
  24463. forceFirstProgress: true,
  24464. progress: function (params, context) {
  24465. context.view.render(context.model, context.ecModel, context.api, context.payload);
  24466. }
  24467. }
  24468. };
  24469. /*
  24470. * Licensed to the Apache Software Foundation (ASF) under one
  24471. * or more contributor license agreements. See the NOTICE file
  24472. * distributed with this work for additional information
  24473. * regarding copyright ownership. The ASF licenses this file
  24474. * to you under the Apache License, Version 2.0 (the
  24475. * "License"); you may not use this file except in compliance
  24476. * with the License. You may obtain a copy of the License at
  24477. *
  24478. * http://www.apache.org/licenses/LICENSE-2.0
  24479. *
  24480. * Unless required by applicable law or agreed to in writing,
  24481. * software distributed under the License is distributed on an
  24482. * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
  24483. * KIND, either express or implied. See the License for the
  24484. * specific language governing permissions and limitations
  24485. * under the License.
  24486. */
  24487. /**
  24488. * AUTO-GENERATED FILE. DO NOT MODIFY.
  24489. */
  24490. /*
  24491. * Licensed to the Apache Software Foundation (ASF) under one
  24492. * or more contributor license agreements. See the NOTICE file
  24493. * distributed with this work for additional information
  24494. * regarding copyright ownership. The ASF licenses this file
  24495. * to you under the Apache License, Version 2.0 (the
  24496. * "License"); you may not use this file except in compliance
  24497. * with the License. You may obtain a copy of the License at
  24498. *
  24499. * http://www.apache.org/licenses/LICENSE-2.0
  24500. *
  24501. * Unless required by applicable law or agreed to in writing,
  24502. * software distributed under the License is distributed on an
  24503. * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
  24504. * KIND, either express or implied. See the License for the
  24505. * specific language governing permissions and limitations
  24506. * under the License.
  24507. */
  24508. var ORIGIN_METHOD = '\0__throttleOriginMethod';
  24509. var RATE = '\0__throttleRate';
  24510. var THROTTLE_TYPE = '\0__throttleType';
  24511. /**
  24512. * @public
  24513. * @param {(Function)} fn
  24514. * @param {number} [delay=0] Unit: ms.
  24515. * @param {boolean} [debounce=false]
  24516. * true: If call interval less than `delay`, only the last call works.
  24517. * false: If call interval less than `delay, call works on fixed rate.
  24518. * @return {(Function)} throttled fn.
  24519. */
  24520. function throttle(fn, delay, debounce) {
  24521. var currCall;
  24522. var lastCall = 0;
  24523. var lastExec = 0;
  24524. var timer = null;
  24525. var diff;
  24526. var scope;
  24527. var args;
  24528. var debounceNextCall;
  24529. delay = delay || 0;
  24530. function exec() {
  24531. lastExec = new Date().getTime();
  24532. timer = null;
  24533. fn.apply(scope, args || []);
  24534. }
  24535. var cb = function () {
  24536. var cbArgs = [];
  24537. for (var _i = 0; _i < arguments.length; _i++) {
  24538. cbArgs[_i] = arguments[_i];
  24539. }
  24540. currCall = new Date().getTime();
  24541. scope = this;
  24542. args = cbArgs;
  24543. var thisDelay = debounceNextCall || delay;
  24544. var thisDebounce = debounceNextCall || debounce;
  24545. debounceNextCall = null;
  24546. diff = currCall - (thisDebounce ? lastCall : lastExec) - thisDelay;
  24547. clearTimeout(timer);
  24548. // Here we should make sure that: the `exec` SHOULD NOT be called later
  24549. // than a new call of `cb`, that is, preserving the command order. Consider
  24550. // calculating "scale rate" when roaming as an example. When a call of `cb`
  24551. // happens, either the `exec` is called dierectly, or the call is delayed.
  24552. // But the delayed call should never be later than next call of `cb`. Under
  24553. // this assurance, we can simply update view state each time `dispatchAction`
  24554. // triggered by user roaming, but not need to add extra code to avoid the
  24555. // state being "rolled-back".
  24556. if (thisDebounce) {
  24557. timer = setTimeout(exec, thisDelay);
  24558. } else {
  24559. if (diff >= 0) {
  24560. exec();
  24561. } else {
  24562. timer = setTimeout(exec, -diff);
  24563. }
  24564. }
  24565. lastCall = currCall;
  24566. };
  24567. /**
  24568. * Clear throttle.
  24569. * @public
  24570. */
  24571. cb.clear = function () {
  24572. if (timer) {
  24573. clearTimeout(timer);
  24574. timer = null;
  24575. }
  24576. };
  24577. /**
  24578. * Enable debounce once.
  24579. */
  24580. cb.debounceNextCall = function (debounceDelay) {
  24581. debounceNextCall = debounceDelay;
  24582. };
  24583. return cb;
  24584. }
  24585. /**
  24586. * Create throttle method or update throttle rate.
  24587. *
  24588. * @example
  24589. * ComponentView.prototype.render = function () {
  24590. * ...
  24591. * throttle.createOrUpdate(
  24592. * this,
  24593. * '_dispatchAction',
  24594. * this.model.get('throttle'),
  24595. * 'fixRate'
  24596. * );
  24597. * };
  24598. * ComponentView.prototype.remove = function () {
  24599. * throttle.clear(this, '_dispatchAction');
  24600. * };
  24601. * ComponentView.prototype.dispose = function () {
  24602. * throttle.clear(this, '_dispatchAction');
  24603. * };
  24604. *
  24605. */
  24606. function createOrUpdate(obj, fnAttr, rate, throttleType) {
  24607. var fn = obj[fnAttr];
  24608. if (!fn) {
  24609. return;
  24610. }
  24611. var originFn = fn[ORIGIN_METHOD] || fn;
  24612. var lastThrottleType = fn[THROTTLE_TYPE];
  24613. var lastRate = fn[RATE];
  24614. if (lastRate !== rate || lastThrottleType !== throttleType) {
  24615. if (rate == null || !throttleType) {
  24616. return obj[fnAttr] = originFn;
  24617. }
  24618. fn = obj[fnAttr] = throttle(originFn, rate, throttleType === 'debounce');
  24619. fn[ORIGIN_METHOD] = originFn;
  24620. fn[THROTTLE_TYPE] = throttleType;
  24621. fn[RATE] = rate;
  24622. }
  24623. return fn;
  24624. }
  24625. /**
  24626. * Clear throttle. Example see throttle.createOrUpdate.
  24627. */
  24628. function clear(obj, fnAttr) {
  24629. var fn = obj[fnAttr];
  24630. if (fn && fn[ORIGIN_METHOD]) {
  24631. // Clear throttle
  24632. fn.clear && fn.clear();
  24633. obj[fnAttr] = fn[ORIGIN_METHOD];
  24634. }
  24635. }
  24636. var inner$3 = makeInner();
  24637. var defaultStyleMappers = {
  24638. itemStyle: makeStyleMapper(ITEM_STYLE_KEY_MAP, true),
  24639. lineStyle: makeStyleMapper(LINE_STYLE_KEY_MAP, true)
  24640. };
  24641. var defaultColorKey = {
  24642. lineStyle: 'stroke',
  24643. itemStyle: 'fill'
  24644. };
  24645. function getStyleMapper(seriesModel, stylePath) {
  24646. var styleMapper = seriesModel.visualStyleMapper || defaultStyleMappers[stylePath];
  24647. if (!styleMapper) {
  24648. console.warn("Unknown style type '" + stylePath + "'.");
  24649. return defaultStyleMappers.itemStyle;
  24650. }
  24651. return styleMapper;
  24652. }
  24653. function getDefaultColorKey(seriesModel, stylePath) {
  24654. // return defaultColorKey[stylePath] ||
  24655. var colorKey = seriesModel.visualDrawType || defaultColorKey[stylePath];
  24656. if (!colorKey) {
  24657. console.warn("Unknown style type '" + stylePath + "'.");
  24658. return 'fill';
  24659. }
  24660. return colorKey;
  24661. }
  24662. var seriesStyleTask = {
  24663. createOnAllSeries: true,
  24664. performRawSeries: true,
  24665. reset: function (seriesModel, ecModel) {
  24666. var data = seriesModel.getData();
  24667. var stylePath = seriesModel.visualStyleAccessPath || 'itemStyle';
  24668. // Set in itemStyle
  24669. var styleModel = seriesModel.getModel(stylePath);
  24670. var getStyle = getStyleMapper(seriesModel, stylePath);
  24671. var globalStyle = getStyle(styleModel);
  24672. var decalOption = styleModel.getShallow('decal');
  24673. if (decalOption) {
  24674. data.setVisual('decal', decalOption);
  24675. decalOption.dirty = true;
  24676. }
  24677. // TODO
  24678. var colorKey = getDefaultColorKey(seriesModel, stylePath);
  24679. var color = globalStyle[colorKey];
  24680. // TODO style callback
  24681. var colorCallback = isFunction(color) ? color : null;
  24682. var hasAutoColor = globalStyle.fill === 'auto' || globalStyle.stroke === 'auto';
  24683. // Get from color palette by default.
  24684. if (!globalStyle[colorKey] || colorCallback || hasAutoColor) {
  24685. // Note: If some series has color specified (e.g., by itemStyle.color), we DO NOT
  24686. // make it effect palette. Because some scenarios users need to make some series
  24687. // transparent or as background, which should better not effect the palette.
  24688. var colorPalette = seriesModel.getColorFromPalette(
  24689. // TODO series count changed.
  24690. seriesModel.name, null, ecModel.getSeriesCount());
  24691. if (!globalStyle[colorKey]) {
  24692. globalStyle[colorKey] = colorPalette;
  24693. data.setVisual('colorFromPalette', true);
  24694. }
  24695. globalStyle.fill = globalStyle.fill === 'auto' || isFunction(globalStyle.fill) ? colorPalette : globalStyle.fill;
  24696. globalStyle.stroke = globalStyle.stroke === 'auto' || isFunction(globalStyle.stroke) ? colorPalette : globalStyle.stroke;
  24697. }
  24698. data.setVisual('style', globalStyle);
  24699. data.setVisual('drawType', colorKey);
  24700. // Only visible series has each data be visual encoded
  24701. if (!ecModel.isSeriesFiltered(seriesModel) && colorCallback) {
  24702. data.setVisual('colorFromPalette', false);
  24703. return {
  24704. dataEach: function (data, idx) {
  24705. var dataParams = seriesModel.getDataParams(idx);
  24706. var itemStyle = extend({}, globalStyle);
  24707. itemStyle[colorKey] = colorCallback(dataParams);
  24708. data.setItemVisual(idx, 'style', itemStyle);
  24709. }
  24710. };
  24711. }
  24712. }
  24713. };
  24714. var sharedModel = new Model();
  24715. var dataStyleTask = {
  24716. createOnAllSeries: true,
  24717. performRawSeries: true,
  24718. reset: function (seriesModel, ecModel) {
  24719. if (seriesModel.ignoreStyleOnData || ecModel.isSeriesFiltered(seriesModel)) {
  24720. return;
  24721. }
  24722. var data = seriesModel.getData();
  24723. var stylePath = seriesModel.visualStyleAccessPath || 'itemStyle';
  24724. // Set in itemStyle
  24725. var getStyle = getStyleMapper(seriesModel, stylePath);
  24726. var colorKey = data.getVisual('drawType');
  24727. return {
  24728. dataEach: data.hasItemOption ? function (data, idx) {
  24729. // Not use getItemModel for performance considuration
  24730. var rawItem = data.getRawDataItem(idx);
  24731. if (rawItem && rawItem[stylePath]) {
  24732. sharedModel.option = rawItem[stylePath];
  24733. var style = getStyle(sharedModel);
  24734. var existsStyle = data.ensureUniqueItemVisual(idx, 'style');
  24735. extend(existsStyle, style);
  24736. if (sharedModel.option.decal) {
  24737. data.setItemVisual(idx, 'decal', sharedModel.option.decal);
  24738. sharedModel.option.decal.dirty = true;
  24739. }
  24740. if (colorKey in style) {
  24741. data.setItemVisual(idx, 'colorFromPalette', false);
  24742. }
  24743. }
  24744. } : null
  24745. };
  24746. }
  24747. };
  24748. // Pick color from palette for the data which has not been set with color yet.
  24749. // Note: do not support stream rendering. No such cases yet.
  24750. var dataColorPaletteTask = {
  24751. performRawSeries: true,
  24752. overallReset: function (ecModel) {
  24753. // Each type of series uses one scope.
  24754. // Pie and funnel are using different scopes.
  24755. var paletteScopeGroupByType = createHashMap();
  24756. ecModel.eachSeries(function (seriesModel) {
  24757. var colorBy = seriesModel.getColorBy();
  24758. if (seriesModel.isColorBySeries()) {
  24759. return;
  24760. }
  24761. var key = seriesModel.type + '-' + colorBy;
  24762. var colorScope = paletteScopeGroupByType.get(key);
  24763. if (!colorScope) {
  24764. colorScope = {};
  24765. paletteScopeGroupByType.set(key, colorScope);
  24766. }
  24767. inner$3(seriesModel).scope = colorScope;
  24768. });
  24769. ecModel.eachSeries(function (seriesModel) {
  24770. if (seriesModel.isColorBySeries() || ecModel.isSeriesFiltered(seriesModel)) {
  24771. return;
  24772. }
  24773. var dataAll = seriesModel.getRawData();
  24774. var idxMap = {};
  24775. var data = seriesModel.getData();
  24776. var colorScope = inner$3(seriesModel).scope;
  24777. var stylePath = seriesModel.visualStyleAccessPath || 'itemStyle';
  24778. var colorKey = getDefaultColorKey(seriesModel, stylePath);
  24779. data.each(function (idx) {
  24780. var rawIdx = data.getRawIndex(idx);
  24781. idxMap[rawIdx] = idx;
  24782. });
  24783. // Iterate on data before filtered. To make sure color from palette can be
  24784. // Consistent when toggling legend.
  24785. dataAll.each(function (rawIdx) {
  24786. var idx = idxMap[rawIdx];
  24787. var fromPalette = data.getItemVisual(idx, 'colorFromPalette');
  24788. // Get color from palette for each data only when the color is inherited from series color, which is
  24789. // also picked from color palette. So following situation is not in the case:
  24790. // 1. series.itemStyle.color is set
  24791. // 2. color is encoded by visualMap
  24792. if (fromPalette) {
  24793. var itemStyle = data.ensureUniqueItemVisual(idx, 'style');
  24794. var name_1 = dataAll.getName(rawIdx) || rawIdx + '';
  24795. var dataCount = dataAll.count();
  24796. itemStyle[colorKey] = seriesModel.getColorFromPalette(name_1, colorScope, dataCount);
  24797. }
  24798. });
  24799. });
  24800. }
  24801. };
  24802. var PI$3 = Math.PI;
  24803. /**
  24804. * @param {module:echarts/ExtensionAPI} api
  24805. * @param {Object} [opts]
  24806. * @param {string} [opts.text]
  24807. * @param {string} [opts.color]
  24808. * @param {string} [opts.textColor]
  24809. * @return {module:zrender/Element}
  24810. */
  24811. function defaultLoading(api, opts) {
  24812. opts = opts || {};
  24813. defaults(opts, {
  24814. text: 'loading',
  24815. textColor: tokens.color.primary,
  24816. fontSize: 12,
  24817. fontWeight: 'normal',
  24818. fontStyle: 'normal',
  24819. fontFamily: 'sans-serif',
  24820. maskColor: 'rgba(255,255,255,0.8)',
  24821. showSpinner: true,
  24822. color: tokens.color.theme[0],
  24823. spinnerRadius: 10,
  24824. lineWidth: 5,
  24825. zlevel: 0
  24826. });
  24827. var group = new Group();
  24828. var mask = new Rect({
  24829. style: {
  24830. fill: opts.maskColor
  24831. },
  24832. zlevel: opts.zlevel,
  24833. z: 10000
  24834. });
  24835. group.add(mask);
  24836. var textContent = new ZRText({
  24837. style: {
  24838. text: opts.text,
  24839. fill: opts.textColor,
  24840. fontSize: opts.fontSize,
  24841. fontWeight: opts.fontWeight,
  24842. fontStyle: opts.fontStyle,
  24843. fontFamily: opts.fontFamily
  24844. },
  24845. zlevel: opts.zlevel,
  24846. z: 10001
  24847. });
  24848. var labelRect = new Rect({
  24849. style: {
  24850. fill: 'none'
  24851. },
  24852. textContent: textContent,
  24853. textConfig: {
  24854. position: 'right',
  24855. distance: 10
  24856. },
  24857. zlevel: opts.zlevel,
  24858. z: 10001
  24859. });
  24860. group.add(labelRect);
  24861. var arc;
  24862. if (opts.showSpinner) {
  24863. arc = new Arc({
  24864. shape: {
  24865. startAngle: -PI$3 / 2,
  24866. endAngle: -PI$3 / 2 + 0.1,
  24867. r: opts.spinnerRadius
  24868. },
  24869. style: {
  24870. stroke: opts.color,
  24871. lineCap: 'round',
  24872. lineWidth: opts.lineWidth
  24873. },
  24874. zlevel: opts.zlevel,
  24875. z: 10001
  24876. });
  24877. arc.animateShape(true).when(1000, {
  24878. endAngle: PI$3 * 3 / 2
  24879. }).start('circularInOut');
  24880. arc.animateShape(true).when(1000, {
  24881. startAngle: PI$3 * 3 / 2
  24882. }).delay(300).start('circularInOut');
  24883. group.add(arc);
  24884. }
  24885. // Inject resize
  24886. group.resize = function () {
  24887. var textWidth = textContent.getBoundingRect().width;
  24888. var r = opts.showSpinner ? opts.spinnerRadius : 0;
  24889. // cx = (containerWidth - arcDiameter - textDistance - textWidth) / 2
  24890. // textDistance needs to be calculated when both animation and text exist
  24891. var cx = (api.getWidth() - r * 2 - (opts.showSpinner && textWidth ? 10 : 0) - textWidth) / 2 - (opts.showSpinner && textWidth ? 0 : 5 + textWidth / 2)
  24892. // only show the text
  24893. + (opts.showSpinner ? 0 : textWidth / 2)
  24894. // only show the spinner
  24895. + (textWidth ? 0 : r);
  24896. var cy = api.getHeight() / 2;
  24897. opts.showSpinner && arc.setShape({
  24898. cx: cx,
  24899. cy: cy
  24900. });
  24901. labelRect.setShape({
  24902. x: cx - r,
  24903. y: cy - r,
  24904. width: r * 2,
  24905. height: r * 2
  24906. });
  24907. mask.setShape({
  24908. x: 0,
  24909. y: 0,
  24910. width: api.getWidth(),
  24911. height: api.getHeight()
  24912. });
  24913. };
  24914. group.resize();
  24915. return group;
  24916. }
  24917. var Scheduler = /** @class */function () {
  24918. function Scheduler(ecInstance, api, dataProcessorHandlers, visualHandlers) {
  24919. // key: handlerUID
  24920. this._stageTaskMap = createHashMap();
  24921. this.ecInstance = ecInstance;
  24922. this.api = api;
  24923. // Fix current processors in case that in some rear cases that
  24924. // processors might be registered after echarts instance created.
  24925. // Register processors incrementally for a echarts instance is
  24926. // not supported by this stream architecture.
  24927. dataProcessorHandlers = this._dataProcessorHandlers = dataProcessorHandlers.slice();
  24928. visualHandlers = this._visualHandlers = visualHandlers.slice();
  24929. this._allHandlers = dataProcessorHandlers.concat(visualHandlers);
  24930. }
  24931. Scheduler.prototype.restoreData = function (ecModel, payload) {
  24932. // TODO: Only restore needed series and components, but not all components.
  24933. // Currently `restoreData` of all of the series and component will be called.
  24934. // But some independent components like `title`, `legend`, `graphic`, `toolbox`,
  24935. // `tooltip`, `axisPointer`, etc, do not need series refresh when `setOption`,
  24936. // and some components like coordinate system, axes, dataZoom, visualMap only
  24937. // need their target series refresh.
  24938. // (1) If we are implementing this feature some day, we should consider these cases:
  24939. // if a data processor depends on a component (e.g., dataZoomProcessor depends
  24940. // on the settings of `dataZoom`), it should be re-performed if the component
  24941. // is modified by `setOption`.
  24942. // (2) If a processor depends on sevral series, speicified by its `getTargetSeries`,
  24943. // it should be re-performed when the result array of `getTargetSeries` changed.
  24944. // We use `dependencies` to cover these issues.
  24945. // (3) How to update target series when coordinate system related components modified.
  24946. // TODO: simply the dirty mechanism? Check whether only the case here can set tasks dirty,
  24947. // and this case all of the tasks will be set as dirty.
  24948. ecModel.restoreData(payload);
  24949. // Theoretically an overall task not only depends on each of its target series, but also
  24950. // depends on all of the series.
  24951. // The overall task is not in pipeline, and `ecModel.restoreData` only set pipeline tasks
  24952. // dirty. If `getTargetSeries` of an overall task returns nothing, we should also ensure
  24953. // that the overall task is set as dirty and to be performed, otherwise it probably cause
  24954. // state chaos. So we have to set dirty of all of the overall tasks manually, otherwise it
  24955. // probably cause state chaos (consider `dataZoomProcessor`).
  24956. this._stageTaskMap.each(function (taskRecord) {
  24957. var overallTask = taskRecord.overallTask;
  24958. overallTask && overallTask.dirty();
  24959. });
  24960. };
  24961. // If seriesModel provided, incremental threshold is check by series data.
  24962. Scheduler.prototype.getPerformArgs = function (task, isBlock) {
  24963. // For overall task
  24964. if (!task.__pipeline) {
  24965. return;
  24966. }
  24967. var pipeline = this._pipelineMap.get(task.__pipeline.id);
  24968. var pCtx = pipeline.context;
  24969. var incremental = !isBlock && pipeline.progressiveEnabled && (!pCtx || pCtx.progressiveRender) && task.__idxInPipeline > pipeline.blockIndex;
  24970. var step = incremental ? pipeline.step : null;
  24971. var modDataCount = pCtx && pCtx.modDataCount;
  24972. var modBy = modDataCount != null ? Math.ceil(modDataCount / step) : null;
  24973. return {
  24974. step: step,
  24975. modBy: modBy,
  24976. modDataCount: modDataCount
  24977. };
  24978. };
  24979. Scheduler.prototype.getPipeline = function (pipelineId) {
  24980. return this._pipelineMap.get(pipelineId);
  24981. };
  24982. /**
  24983. * Current, progressive rendering starts from visual and layout.
  24984. * Always detect render mode in the same stage, avoiding that incorrect
  24985. * detection caused by data filtering.
  24986. * Caution:
  24987. * `updateStreamModes` use `seriesModel.getData()`.
  24988. */
  24989. Scheduler.prototype.updateStreamModes = function (seriesModel, view) {
  24990. var pipeline = this._pipelineMap.get(seriesModel.uid);
  24991. var data = seriesModel.getData();
  24992. var dataLen = data.count();
  24993. // `progressiveRender` means that can render progressively in each
  24994. // animation frame. Note that some types of series do not provide
  24995. // `view.incrementalPrepareRender` but support `chart.appendData`. We
  24996. // use the term `incremental` but not `progressive` to describe the
  24997. // case that `chart.appendData`.
  24998. var progressiveRender = pipeline.progressiveEnabled && view.incrementalPrepareRender && dataLen >= pipeline.threshold;
  24999. var large = seriesModel.get('large') && dataLen >= seriesModel.get('largeThreshold');
  25000. // TODO: modDataCount should not updated if `appendData`, otherwise cause whole repaint.
  25001. // see `test/candlestick-large3.html`
  25002. var modDataCount = seriesModel.get('progressiveChunkMode') === 'mod' ? dataLen : null;
  25003. seriesModel.pipelineContext = pipeline.context = {
  25004. progressiveRender: progressiveRender,
  25005. modDataCount: modDataCount,
  25006. large: large
  25007. };
  25008. };
  25009. Scheduler.prototype.restorePipelines = function (ecModel) {
  25010. var scheduler = this;
  25011. var pipelineMap = scheduler._pipelineMap = createHashMap();
  25012. ecModel.eachSeries(function (seriesModel) {
  25013. var progressive = seriesModel.getProgressive();
  25014. var pipelineId = seriesModel.uid;
  25015. pipelineMap.set(pipelineId, {
  25016. id: pipelineId,
  25017. head: null,
  25018. tail: null,
  25019. threshold: seriesModel.getProgressiveThreshold(),
  25020. progressiveEnabled: progressive && !(seriesModel.preventIncremental && seriesModel.preventIncremental()),
  25021. blockIndex: -1,
  25022. step: Math.round(progressive || 700),
  25023. count: 0
  25024. });
  25025. scheduler._pipe(seriesModel, seriesModel.dataTask);
  25026. });
  25027. };
  25028. Scheduler.prototype.prepareStageTasks = function () {
  25029. var stageTaskMap = this._stageTaskMap;
  25030. var ecModel = this.api.getModel();
  25031. var api = this.api;
  25032. each(this._allHandlers, function (handler) {
  25033. var record = stageTaskMap.get(handler.uid) || stageTaskMap.set(handler.uid, {});
  25034. var errMsg = '';
  25035. if ("development" !== 'production') {
  25036. // Currently do not need to support to sepecify them both.
  25037. errMsg = '"reset" and "overallReset" must not be both specified.';
  25038. }
  25039. assert(!(handler.reset && handler.overallReset), errMsg);
  25040. handler.reset && this._createSeriesStageTask(handler, record, ecModel, api);
  25041. handler.overallReset && this._createOverallStageTask(handler, record, ecModel, api);
  25042. }, this);
  25043. };
  25044. Scheduler.prototype.prepareView = function (view, model, ecModel, api) {
  25045. var renderTask = view.renderTask;
  25046. var context = renderTask.context;
  25047. context.model = model;
  25048. context.ecModel = ecModel;
  25049. context.api = api;
  25050. renderTask.__block = !view.incrementalPrepareRender;
  25051. this._pipe(model, renderTask);
  25052. };
  25053. Scheduler.prototype.performDataProcessorTasks = function (ecModel, payload) {
  25054. // If we do not use `block` here, it should be considered when to update modes.
  25055. this._performStageTasks(this._dataProcessorHandlers, ecModel, payload, {
  25056. block: true
  25057. });
  25058. };
  25059. Scheduler.prototype.performVisualTasks = function (ecModel, payload, opt) {
  25060. this._performStageTasks(this._visualHandlers, ecModel, payload, opt);
  25061. };
  25062. Scheduler.prototype._performStageTasks = function (stageHandlers, ecModel, payload, opt) {
  25063. opt = opt || {};
  25064. var unfinished = false;
  25065. var scheduler = this;
  25066. each(stageHandlers, function (stageHandler, idx) {
  25067. if (opt.visualType && opt.visualType !== stageHandler.visualType) {
  25068. return;
  25069. }
  25070. var stageHandlerRecord = scheduler._stageTaskMap.get(stageHandler.uid);
  25071. var seriesTaskMap = stageHandlerRecord.seriesTaskMap;
  25072. var overallTask = stageHandlerRecord.overallTask;
  25073. if (overallTask) {
  25074. var overallNeedDirty_1;
  25075. var agentStubMap = overallTask.agentStubMap;
  25076. agentStubMap.each(function (stub) {
  25077. if (needSetDirty(opt, stub)) {
  25078. stub.dirty();
  25079. overallNeedDirty_1 = true;
  25080. }
  25081. });
  25082. overallNeedDirty_1 && overallTask.dirty();
  25083. scheduler.updatePayload(overallTask, payload);
  25084. var performArgs_1 = scheduler.getPerformArgs(overallTask, opt.block);
  25085. // Execute stubs firstly, which may set the overall task dirty,
  25086. // then execute the overall task. And stub will call seriesModel.setData,
  25087. // which ensures that in the overallTask seriesModel.getData() will not
  25088. // return incorrect data.
  25089. agentStubMap.each(function (stub) {
  25090. stub.perform(performArgs_1);
  25091. });
  25092. if (overallTask.perform(performArgs_1)) {
  25093. unfinished = true;
  25094. }
  25095. } else if (seriesTaskMap) {
  25096. seriesTaskMap.each(function (task, pipelineId) {
  25097. if (needSetDirty(opt, task)) {
  25098. task.dirty();
  25099. }
  25100. var performArgs = scheduler.getPerformArgs(task, opt.block);
  25101. // FIXME
  25102. // if intending to declare `performRawSeries` in handlers, only
  25103. // stream-independent (specifically, data item independent) operations can be
  25104. // performed. Because if a series is filtered, most of the tasks will not
  25105. // be performed. A stream-dependent operation probably cause wrong biz logic.
  25106. // Perhaps we should not provide a separate callback for this case instead
  25107. // of providing the config `performRawSeries`. The stream-dependent operations
  25108. // and stream-independent operations should better not be mixed.
  25109. performArgs.skip = !stageHandler.performRawSeries && ecModel.isSeriesFiltered(task.context.model);
  25110. scheduler.updatePayload(task, payload);
  25111. if (task.perform(performArgs)) {
  25112. unfinished = true;
  25113. }
  25114. });
  25115. }
  25116. });
  25117. function needSetDirty(opt, task) {
  25118. return opt.setDirty && (!opt.dirtyMap || opt.dirtyMap.get(task.__pipeline.id));
  25119. }
  25120. this.unfinished = unfinished || this.unfinished;
  25121. };
  25122. Scheduler.prototype.performSeriesTasks = function (ecModel) {
  25123. var unfinished;
  25124. ecModel.eachSeries(function (seriesModel) {
  25125. // Progress to the end for dataInit and dataRestore.
  25126. unfinished = seriesModel.dataTask.perform() || unfinished;
  25127. });
  25128. this.unfinished = unfinished || this.unfinished;
  25129. };
  25130. Scheduler.prototype.plan = function () {
  25131. // Travel pipelines, check block.
  25132. this._pipelineMap.each(function (pipeline) {
  25133. var task = pipeline.tail;
  25134. do {
  25135. if (task.__block) {
  25136. pipeline.blockIndex = task.__idxInPipeline;
  25137. break;
  25138. }
  25139. task = task.getUpstream();
  25140. } while (task);
  25141. });
  25142. };
  25143. Scheduler.prototype.updatePayload = function (task, payload) {
  25144. payload !== 'remain' && (task.context.payload = payload);
  25145. };
  25146. Scheduler.prototype._createSeriesStageTask = function (stageHandler, stageHandlerRecord, ecModel, api) {
  25147. var scheduler = this;
  25148. var oldSeriesTaskMap = stageHandlerRecord.seriesTaskMap;
  25149. // The count of stages are totally about only several dozen, so
  25150. // do not need to reuse the map.
  25151. var newSeriesTaskMap = stageHandlerRecord.seriesTaskMap = createHashMap();
  25152. var seriesType = stageHandler.seriesType;
  25153. var getTargetSeries = stageHandler.getTargetSeries;
  25154. // If a stageHandler should cover all series, `createOnAllSeries` should be declared mandatorily,
  25155. // to avoid some typo or abuse. Otherwise if an extension do not specify a `seriesType`,
  25156. // it works but it may cause other irrelevant charts blocked.
  25157. if (stageHandler.createOnAllSeries) {
  25158. ecModel.eachRawSeries(create);
  25159. } else if (seriesType) {
  25160. ecModel.eachRawSeriesByType(seriesType, create);
  25161. } else if (getTargetSeries) {
  25162. getTargetSeries(ecModel, api).each(create);
  25163. }
  25164. function create(seriesModel) {
  25165. var pipelineId = seriesModel.uid;
  25166. // Init tasks for each seriesModel only once.
  25167. // Reuse original task instance.
  25168. var task = newSeriesTaskMap.set(pipelineId, oldSeriesTaskMap && oldSeriesTaskMap.get(pipelineId) || createTask({
  25169. plan: seriesTaskPlan,
  25170. reset: seriesTaskReset,
  25171. count: seriesTaskCount
  25172. }));
  25173. task.context = {
  25174. model: seriesModel,
  25175. ecModel: ecModel,
  25176. api: api,
  25177. // PENDING: `useClearVisual` not used?
  25178. useClearVisual: stageHandler.isVisual && !stageHandler.isLayout,
  25179. plan: stageHandler.plan,
  25180. reset: stageHandler.reset,
  25181. scheduler: scheduler
  25182. };
  25183. scheduler._pipe(seriesModel, task);
  25184. }
  25185. };
  25186. Scheduler.prototype._createOverallStageTask = function (stageHandler, stageHandlerRecord, ecModel, api) {
  25187. var scheduler = this;
  25188. var overallTask = stageHandlerRecord.overallTask = stageHandlerRecord.overallTask
  25189. // For overall task, the function only be called on reset stage.
  25190. || createTask({
  25191. reset: overallTaskReset
  25192. });
  25193. overallTask.context = {
  25194. ecModel: ecModel,
  25195. api: api,
  25196. overallReset: stageHandler.overallReset,
  25197. scheduler: scheduler
  25198. };
  25199. var oldAgentStubMap = overallTask.agentStubMap;
  25200. // The count of stages are totally about only several dozen, so
  25201. // do not need to reuse the map.
  25202. var newAgentStubMap = overallTask.agentStubMap = createHashMap();
  25203. var seriesType = stageHandler.seriesType;
  25204. var getTargetSeries = stageHandler.getTargetSeries;
  25205. var overallProgress = true;
  25206. var shouldOverallTaskDirty = false;
  25207. // FIXME:TS never used, so comment it
  25208. // let modifyOutputEnd = stageHandler.modifyOutputEnd;
  25209. // An overall task with seriesType detected or has `getTargetSeries`, we add
  25210. // stub in each pipelines, it will set the overall task dirty when the pipeline
  25211. // progress. Moreover, to avoid call the overall task each frame (too frequent),
  25212. // we set the pipeline block.
  25213. var errMsg = '';
  25214. if ("development" !== 'production') {
  25215. errMsg = '"createOnAllSeries" is not supported for "overallReset", ' + 'because it will block all streams.';
  25216. }
  25217. assert(!stageHandler.createOnAllSeries, errMsg);
  25218. if (seriesType) {
  25219. ecModel.eachRawSeriesByType(seriesType, createStub);
  25220. } else if (getTargetSeries) {
  25221. getTargetSeries(ecModel, api).each(createStub);
  25222. }
  25223. // Otherwise, (usually it is legacy case), the overall task will only be
  25224. // executed when upstream is dirty. Otherwise the progressive rendering of all
  25225. // pipelines will be disabled unexpectedly. But it still needs stubs to receive
  25226. // dirty info from upstream.
  25227. else {
  25228. overallProgress = false;
  25229. each(ecModel.getSeries(), createStub);
  25230. }
  25231. function createStub(seriesModel) {
  25232. var pipelineId = seriesModel.uid;
  25233. var stub = newAgentStubMap.set(pipelineId, oldAgentStubMap && oldAgentStubMap.get(pipelineId) || (
  25234. // When the result of `getTargetSeries` changed, the overallTask
  25235. // should be set as dirty and re-performed.
  25236. shouldOverallTaskDirty = true, createTask({
  25237. reset: stubReset,
  25238. onDirty: stubOnDirty
  25239. })));
  25240. stub.context = {
  25241. model: seriesModel,
  25242. overallProgress: overallProgress
  25243. // FIXME:TS never used, so comment it
  25244. // modifyOutputEnd: modifyOutputEnd
  25245. };
  25246. stub.agent = overallTask;
  25247. stub.__block = overallProgress;
  25248. scheduler._pipe(seriesModel, stub);
  25249. }
  25250. if (shouldOverallTaskDirty) {
  25251. overallTask.dirty();
  25252. }
  25253. };
  25254. Scheduler.prototype._pipe = function (seriesModel, task) {
  25255. var pipelineId = seriesModel.uid;
  25256. var pipeline = this._pipelineMap.get(pipelineId);
  25257. !pipeline.head && (pipeline.head = task);
  25258. pipeline.tail && pipeline.tail.pipe(task);
  25259. pipeline.tail = task;
  25260. task.__idxInPipeline = pipeline.count++;
  25261. task.__pipeline = pipeline;
  25262. };
  25263. Scheduler.wrapStageHandler = function (stageHandler, visualType) {
  25264. if (isFunction(stageHandler)) {
  25265. stageHandler = {
  25266. overallReset: stageHandler,
  25267. seriesType: detectSeriseType(stageHandler)
  25268. };
  25269. }
  25270. stageHandler.uid = getUID('stageHandler');
  25271. visualType && (stageHandler.visualType = visualType);
  25272. return stageHandler;
  25273. };
  25274. return Scheduler;
  25275. }();
  25276. function overallTaskReset(context) {
  25277. context.overallReset(context.ecModel, context.api, context.payload);
  25278. }
  25279. function stubReset(context) {
  25280. return context.overallProgress && stubProgress;
  25281. }
  25282. function stubProgress() {
  25283. this.agent.dirty();
  25284. this.getDownstream().dirty();
  25285. }
  25286. function stubOnDirty() {
  25287. this.agent && this.agent.dirty();
  25288. }
  25289. function seriesTaskPlan(context) {
  25290. return context.plan ? context.plan(context.model, context.ecModel, context.api, context.payload) : null;
  25291. }
  25292. function seriesTaskReset(context) {
  25293. if (context.useClearVisual) {
  25294. context.data.clearAllVisual();
  25295. }
  25296. var resetDefines = context.resetDefines = normalizeToArray(context.reset(context.model, context.ecModel, context.api, context.payload));
  25297. return resetDefines.length > 1 ? map(resetDefines, function (v, idx) {
  25298. return makeSeriesTaskProgress(idx);
  25299. }) : singleSeriesTaskProgress;
  25300. }
  25301. var singleSeriesTaskProgress = makeSeriesTaskProgress(0);
  25302. function makeSeriesTaskProgress(resetDefineIdx) {
  25303. return function (params, context) {
  25304. var data = context.data;
  25305. var resetDefine = context.resetDefines[resetDefineIdx];
  25306. if (resetDefine && resetDefine.dataEach) {
  25307. for (var i = params.start; i < params.end; i++) {
  25308. resetDefine.dataEach(data, i);
  25309. }
  25310. } else if (resetDefine && resetDefine.progress) {
  25311. resetDefine.progress(params, data);
  25312. }
  25313. };
  25314. }
  25315. function seriesTaskCount(context) {
  25316. return context.data.count();
  25317. }
  25318. /**
  25319. * Only some legacy stage handlers (usually in echarts extensions) are pure function.
  25320. * To ensure that they can work normally, they should work in block mode, that is,
  25321. * they should not be started util the previous tasks finished. So they cause the
  25322. * progressive rendering disabled. We try to detect the series type, to narrow down
  25323. * the block range to only the series type they concern, but not all series.
  25324. */
  25325. function detectSeriseType(legacyFunc) {
  25326. seriesType = null;
  25327. try {
  25328. // Assume there is no async when calling `eachSeriesByType`.
  25329. legacyFunc(ecModelMock, apiMock);
  25330. } catch (e) {}
  25331. return seriesType;
  25332. }
  25333. var ecModelMock = {};
  25334. var apiMock = {};
  25335. var seriesType;
  25336. mockMethods(ecModelMock, GlobalModel);
  25337. mockMethods(apiMock, ExtensionAPI);
  25338. ecModelMock.eachSeriesByType = ecModelMock.eachRawSeriesByType = function (type) {
  25339. seriesType = type;
  25340. };
  25341. ecModelMock.eachComponent = function (cond) {
  25342. if (cond.mainType === 'series' && cond.subType) {
  25343. seriesType = cond.subType;
  25344. }
  25345. };
  25346. function mockMethods(target, Clz) {
  25347. /* eslint-disable */
  25348. for (var name_1 in Clz.prototype) {
  25349. // Do not use hasOwnProperty
  25350. target[name_1] = noop;
  25351. }
  25352. /* eslint-enable */
  25353. }
  25354. var color$2 = tokens.darkColor;
  25355. var backgroundColor = color$2.background;
  25356. var axisCommon = function () {
  25357. return {
  25358. axisLine: {
  25359. lineStyle: {
  25360. color: color$2.axisLine
  25361. }
  25362. },
  25363. splitLine: {
  25364. lineStyle: {
  25365. color: color$2.axisSplitLine
  25366. }
  25367. },
  25368. splitArea: {
  25369. areaStyle: {
  25370. color: [color$2.backgroundTint, color$2.backgroundTransparent]
  25371. }
  25372. },
  25373. minorSplitLine: {
  25374. lineStyle: {
  25375. color: color$2.axisMinorSplitLine
  25376. }
  25377. },
  25378. axisLabel: {
  25379. color: color$2.axisLabel
  25380. },
  25381. axisName: {}
  25382. };
  25383. };
  25384. var matrixAxis = {
  25385. label: {
  25386. color: color$2.secondary
  25387. },
  25388. itemStyle: {
  25389. borderColor: color$2.borderTint
  25390. },
  25391. dividerLineStyle: {
  25392. color: color$2.border
  25393. }
  25394. };
  25395. var theme = {
  25396. darkMode: true,
  25397. color: color$2.theme,
  25398. backgroundColor: backgroundColor,
  25399. axisPointer: {
  25400. lineStyle: {
  25401. color: color$2.border
  25402. },
  25403. crossStyle: {
  25404. color: color$2.borderShade
  25405. },
  25406. label: {
  25407. color: color$2.tertiary
  25408. }
  25409. },
  25410. legend: {
  25411. textStyle: {
  25412. color: color$2.secondary
  25413. },
  25414. pageTextStyle: {
  25415. color: color$2.tertiary
  25416. }
  25417. },
  25418. textStyle: {
  25419. color: color$2.secondary
  25420. },
  25421. title: {
  25422. textStyle: {
  25423. color: color$2.primary
  25424. },
  25425. subtextStyle: {
  25426. color: color$2.quaternary
  25427. }
  25428. },
  25429. toolbox: {
  25430. iconStyle: {
  25431. borderColor: color$2.accent50
  25432. }
  25433. },
  25434. tooltip: {
  25435. backgroundColor: color$2.neutral20,
  25436. defaultBorderColor: color$2.border,
  25437. textStyle: {
  25438. color: color$2.tertiary
  25439. }
  25440. },
  25441. dataZoom: {
  25442. borderColor: color$2.accent10,
  25443. textStyle: {
  25444. color: color$2.tertiary
  25445. },
  25446. brushStyle: {
  25447. color: color$2.backgroundTint
  25448. },
  25449. handleStyle: {
  25450. color: color$2.neutral00,
  25451. borderColor: color$2.accent20
  25452. },
  25453. moveHandleStyle: {
  25454. color: color$2.accent40
  25455. },
  25456. emphasis: {
  25457. handleStyle: {
  25458. borderColor: color$2.accent50
  25459. }
  25460. },
  25461. dataBackground: {
  25462. lineStyle: {
  25463. color: color$2.accent30
  25464. },
  25465. areaStyle: {
  25466. color: color$2.accent20
  25467. }
  25468. },
  25469. selectedDataBackground: {
  25470. lineStyle: {
  25471. color: color$2.accent50
  25472. },
  25473. areaStyle: {
  25474. color: color$2.accent30
  25475. }
  25476. }
  25477. },
  25478. visualMap: {
  25479. textStyle: {
  25480. color: color$2.secondary
  25481. },
  25482. handleStyle: {
  25483. borderColor: color$2.neutral30
  25484. }
  25485. },
  25486. timeline: {
  25487. lineStyle: {
  25488. color: color$2.accent10
  25489. },
  25490. label: {
  25491. color: color$2.tertiary
  25492. },
  25493. controlStyle: {
  25494. color: color$2.accent30,
  25495. borderColor: color$2.accent30
  25496. }
  25497. },
  25498. calendar: {
  25499. itemStyle: {
  25500. color: color$2.neutral00,
  25501. borderColor: color$2.neutral20
  25502. },
  25503. dayLabel: {
  25504. color: color$2.tertiary
  25505. },
  25506. monthLabel: {
  25507. color: color$2.secondary
  25508. },
  25509. yearLabel: {
  25510. color: color$2.secondary
  25511. }
  25512. },
  25513. matrix: {
  25514. x: matrixAxis,
  25515. y: matrixAxis,
  25516. backgroundColor: {
  25517. borderColor: color$2.axisLine
  25518. },
  25519. body: {
  25520. itemStyle: {
  25521. borderColor: color$2.borderTint
  25522. }
  25523. }
  25524. },
  25525. timeAxis: axisCommon(),
  25526. logAxis: axisCommon(),
  25527. valueAxis: axisCommon(),
  25528. categoryAxis: axisCommon(),
  25529. line: {
  25530. symbol: 'circle'
  25531. },
  25532. graph: {
  25533. color: color$2.theme
  25534. },
  25535. gauge: {
  25536. title: {
  25537. color: color$2.secondary
  25538. },
  25539. axisLine: {
  25540. lineStyle: {
  25541. color: [[1, color$2.neutral05]]
  25542. }
  25543. },
  25544. axisLabel: {
  25545. color: color$2.axisLabel
  25546. },
  25547. detail: {
  25548. color: color$2.primary
  25549. }
  25550. },
  25551. candlestick: {
  25552. itemStyle: {
  25553. color: '#f64e56',
  25554. color0: '#54ea92',
  25555. borderColor: '#f64e56',
  25556. borderColor0: '#54ea92'
  25557. // borderColor: '#ca2824',
  25558. // borderColor0: '#09a443'
  25559. }
  25560. },
  25561. funnel: {
  25562. itemStyle: {
  25563. borderColor: color$2.background
  25564. }
  25565. },
  25566. radar: function () {
  25567. var radar = axisCommon();
  25568. radar.axisName = {
  25569. color: color$2.axisLabel
  25570. };
  25571. radar.axisLine.lineStyle.color = color$2.neutral20;
  25572. return radar;
  25573. }(),
  25574. treemap: {
  25575. breadcrumb: {
  25576. itemStyle: {
  25577. color: color$2.neutral20,
  25578. textStyle: {
  25579. color: color$2.secondary
  25580. }
  25581. },
  25582. emphasis: {
  25583. itemStyle: {
  25584. color: color$2.neutral30
  25585. }
  25586. }
  25587. }
  25588. },
  25589. sunburst: {
  25590. itemStyle: {
  25591. borderColor: color$2.background
  25592. }
  25593. },
  25594. map: {
  25595. itemStyle: {
  25596. borderColor: color$2.border,
  25597. areaColor: color$2.neutral10
  25598. },
  25599. label: {
  25600. color: color$2.tertiary
  25601. },
  25602. emphasis: {
  25603. label: {
  25604. color: color$2.primary
  25605. },
  25606. itemStyle: {
  25607. areaColor: color$2.highlight
  25608. }
  25609. },
  25610. select: {
  25611. label: {
  25612. color: color$2.primary
  25613. },
  25614. itemStyle: {
  25615. areaColor: color$2.highlight
  25616. }
  25617. }
  25618. },
  25619. geo: {
  25620. itemStyle: {
  25621. borderColor: color$2.border,
  25622. areaColor: color$2.neutral10
  25623. },
  25624. emphasis: {
  25625. label: {
  25626. color: color$2.primary
  25627. },
  25628. itemStyle: {
  25629. areaColor: color$2.highlight
  25630. }
  25631. },
  25632. select: {
  25633. label: {
  25634. color: color$2.primary
  25635. },
  25636. itemStyle: {
  25637. color: color$2.highlight
  25638. }
  25639. }
  25640. }
  25641. };
  25642. theme.categoryAxis.splitLine.show = false;
  25643. /**
  25644. * Usage of query:
  25645. * `chart.on('click', query, handler);`
  25646. * The `query` can be:
  25647. * + The component type query string, only `mainType` or `mainType.subType`,
  25648. * like: 'xAxis', 'series', 'xAxis.category' or 'series.line'.
  25649. * + The component query object, like:
  25650. * `{seriesIndex: 2}`, `{seriesName: 'xx'}`, `{seriesId: 'some'}`,
  25651. * `{xAxisIndex: 2}`, `{xAxisName: 'xx'}`, `{xAxisId: 'some'}`.
  25652. * + The data query object, like:
  25653. * `{dataIndex: 123}`, `{dataType: 'link'}`, `{name: 'some'}`.
  25654. * + The other query object (cmponent customized query), like:
  25655. * `{element: 'some'}` (only available in custom series).
  25656. *
  25657. * Caveat: If a prop in the `query` object is `null/undefined`, it is the
  25658. * same as there is no such prop in the `query` object.
  25659. */
  25660. var ECEventProcessor = /** @class */function () {
  25661. function ECEventProcessor() {}
  25662. ECEventProcessor.prototype.normalizeQuery = function (query) {
  25663. var cptQuery = {};
  25664. var dataQuery = {};
  25665. var otherQuery = {};
  25666. // `query` is `mainType` or `mainType.subType` of component.
  25667. if (isString(query)) {
  25668. var condCptType = parseClassType(query);
  25669. // `.main` and `.sub` may be ''.
  25670. cptQuery.mainType = condCptType.main || null;
  25671. cptQuery.subType = condCptType.sub || null;
  25672. }
  25673. // `query` is an object, convert to {mainType, index, name, id}.
  25674. else {
  25675. // `xxxIndex`, `xxxName`, `xxxId`, `name`, `dataIndex`, `dataType` is reserved,
  25676. // can not be used in `compomentModel.filterForExposedEvent`.
  25677. var suffixes_1 = ['Index', 'Name', 'Id'];
  25678. var dataKeys_1 = {
  25679. name: 1,
  25680. dataIndex: 1,
  25681. dataType: 1
  25682. };
  25683. each(query, function (val, key) {
  25684. var reserved = false;
  25685. for (var i = 0; i < suffixes_1.length; i++) {
  25686. var propSuffix = suffixes_1[i];
  25687. var suffixPos = key.lastIndexOf(propSuffix);
  25688. if (suffixPos > 0 && suffixPos === key.length - propSuffix.length) {
  25689. var mainType = key.slice(0, suffixPos);
  25690. // Consider `dataIndex`.
  25691. if (mainType !== 'data') {
  25692. cptQuery.mainType = mainType;
  25693. cptQuery[propSuffix.toLowerCase()] = val;
  25694. reserved = true;
  25695. }
  25696. }
  25697. }
  25698. if (dataKeys_1.hasOwnProperty(key)) {
  25699. dataQuery[key] = val;
  25700. reserved = true;
  25701. }
  25702. if (!reserved) {
  25703. otherQuery[key] = val;
  25704. }
  25705. });
  25706. }
  25707. return {
  25708. cptQuery: cptQuery,
  25709. dataQuery: dataQuery,
  25710. otherQuery: otherQuery
  25711. };
  25712. };
  25713. ECEventProcessor.prototype.filter = function (eventType, query) {
  25714. // They should be assigned before each trigger call.
  25715. var eventInfo = this.eventInfo;
  25716. if (!eventInfo) {
  25717. return true;
  25718. }
  25719. var targetEl = eventInfo.targetEl;
  25720. var packedEvent = eventInfo.packedEvent;
  25721. var model = eventInfo.model;
  25722. var view = eventInfo.view;
  25723. // For event like 'globalout'.
  25724. if (!model || !view) {
  25725. return true;
  25726. }
  25727. var cptQuery = query.cptQuery;
  25728. var dataQuery = query.dataQuery;
  25729. return check(cptQuery, model, 'mainType') && check(cptQuery, model, 'subType') && check(cptQuery, model, 'index', 'componentIndex') && check(cptQuery, model, 'name') && check(cptQuery, model, 'id') && check(dataQuery, packedEvent, 'name') && check(dataQuery, packedEvent, 'dataIndex') && check(dataQuery, packedEvent, 'dataType') && (!view.filterForExposedEvent || view.filterForExposedEvent(eventType, query.otherQuery, targetEl, packedEvent));
  25730. function check(query, host, prop, propOnHost) {
  25731. return query[prop] == null || host[propOnHost || prop] === query[prop];
  25732. }
  25733. };
  25734. ECEventProcessor.prototype.afterTrigger = function () {
  25735. // Make sure the eventInfo won't be used in next trigger.
  25736. this.eventInfo = null;
  25737. };
  25738. return ECEventProcessor;
  25739. }();
  25740. var SYMBOL_PROPS_WITH_CB = ['symbol', 'symbolSize', 'symbolRotate', 'symbolOffset'];
  25741. var SYMBOL_PROPS = SYMBOL_PROPS_WITH_CB.concat(['symbolKeepAspect']);
  25742. // Encoding visual for all series include which is filtered for legend drawing
  25743. var seriesSymbolTask = {
  25744. createOnAllSeries: true,
  25745. // For legend.
  25746. performRawSeries: true,
  25747. reset: function (seriesModel, ecModel) {
  25748. var data = seriesModel.getData();
  25749. if (seriesModel.legendIcon) {
  25750. data.setVisual('legendIcon', seriesModel.legendIcon);
  25751. }
  25752. if (!seriesModel.hasSymbolVisual) {
  25753. return;
  25754. }
  25755. var symbolOptions = {};
  25756. var symbolOptionsCb = {};
  25757. var hasCallback = false;
  25758. for (var i = 0; i < SYMBOL_PROPS_WITH_CB.length; i++) {
  25759. var symbolPropName = SYMBOL_PROPS_WITH_CB[i];
  25760. var val = seriesModel.get(symbolPropName);
  25761. if (isFunction(val)) {
  25762. hasCallback = true;
  25763. symbolOptionsCb[symbolPropName] = val;
  25764. } else {
  25765. symbolOptions[symbolPropName] = val;
  25766. }
  25767. }
  25768. symbolOptions.symbol = symbolOptions.symbol || seriesModel.defaultSymbol;
  25769. data.setVisual(extend({
  25770. legendIcon: seriesModel.legendIcon || symbolOptions.symbol,
  25771. symbolKeepAspect: seriesModel.get('symbolKeepAspect')
  25772. }, symbolOptions));
  25773. // Only visible series has each data be visual encoded
  25774. if (ecModel.isSeriesFiltered(seriesModel)) {
  25775. return;
  25776. }
  25777. var symbolPropsCb = keys(symbolOptionsCb);
  25778. function dataEach(data, idx) {
  25779. var rawValue = seriesModel.getRawValue(idx);
  25780. var params = seriesModel.getDataParams(idx);
  25781. for (var i = 0; i < symbolPropsCb.length; i++) {
  25782. var symbolPropName = symbolPropsCb[i];
  25783. data.setItemVisual(idx, symbolPropName, symbolOptionsCb[symbolPropName](rawValue, params));
  25784. }
  25785. }
  25786. return {
  25787. dataEach: hasCallback ? dataEach : null
  25788. };
  25789. }
  25790. };
  25791. var dataSymbolTask = {
  25792. createOnAllSeries: true,
  25793. // For legend.
  25794. performRawSeries: true,
  25795. reset: function (seriesModel, ecModel) {
  25796. if (!seriesModel.hasSymbolVisual) {
  25797. return;
  25798. }
  25799. // Only visible series has each data be visual encoded
  25800. if (ecModel.isSeriesFiltered(seriesModel)) {
  25801. return;
  25802. }
  25803. var data = seriesModel.getData();
  25804. function dataEach(data, idx) {
  25805. var itemModel = data.getItemModel(idx);
  25806. for (var i = 0; i < SYMBOL_PROPS.length; i++) {
  25807. var symbolPropName = SYMBOL_PROPS[i];
  25808. var val = itemModel.getShallow(symbolPropName, true);
  25809. if (val != null) {
  25810. data.setItemVisual(idx, symbolPropName, val);
  25811. }
  25812. }
  25813. }
  25814. return {
  25815. dataEach: data.hasItemOption ? dataEach : null
  25816. };
  25817. }
  25818. };
  25819. /*
  25820. * Licensed to the Apache Software Foundation (ASF) under one
  25821. * or more contributor license agreements. See the NOTICE file
  25822. * distributed with this work for additional information
  25823. * regarding copyright ownership. The ASF licenses this file
  25824. * to you under the Apache License, Version 2.0 (the
  25825. * "License"); you may not use this file except in compliance
  25826. * with the License. You may obtain a copy of the License at
  25827. *
  25828. * http://www.apache.org/licenses/LICENSE-2.0
  25829. *
  25830. * Unless required by applicable law or agreed to in writing,
  25831. * software distributed under the License is distributed on an
  25832. * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
  25833. * KIND, either express or implied. See the License for the
  25834. * specific language governing permissions and limitations
  25835. * under the License.
  25836. */
  25837. /**
  25838. * AUTO-GENERATED FILE. DO NOT MODIFY.
  25839. */
  25840. /*
  25841. * Licensed to the Apache Software Foundation (ASF) under one
  25842. * or more contributor license agreements. See the NOTICE file
  25843. * distributed with this work for additional information
  25844. * regarding copyright ownership. The ASF licenses this file
  25845. * to you under the Apache License, Version 2.0 (the
  25846. * "License"); you may not use this file except in compliance
  25847. * with the License. You may obtain a copy of the License at
  25848. *
  25849. * http://www.apache.org/licenses/LICENSE-2.0
  25850. *
  25851. * Unless required by applicable law or agreed to in writing,
  25852. * software distributed under the License is distributed on an
  25853. * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
  25854. * KIND, either express or implied. See the License for the
  25855. * specific language governing permissions and limitations
  25856. * under the License.
  25857. */
  25858. function getItemVisualFromData(data, dataIndex, key) {
  25859. switch (key) {
  25860. case 'color':
  25861. var style = data.getItemVisual(dataIndex, 'style');
  25862. return style[data.getVisual('drawType')];
  25863. case 'opacity':
  25864. return data.getItemVisual(dataIndex, 'style').opacity;
  25865. case 'symbol':
  25866. case 'symbolSize':
  25867. case 'liftZ':
  25868. return data.getItemVisual(dataIndex, key);
  25869. default:
  25870. if ("development" !== 'production') {
  25871. console.warn("Unknown visual type " + key);
  25872. }
  25873. }
  25874. }
  25875. function getVisualFromData(data, key) {
  25876. switch (key) {
  25877. case 'color':
  25878. var style = data.getVisual('style');
  25879. return style[data.getVisual('drawType')];
  25880. case 'opacity':
  25881. return data.getVisual('style').opacity;
  25882. case 'symbol':
  25883. case 'symbolSize':
  25884. case 'liftZ':
  25885. return data.getVisual(key);
  25886. default:
  25887. if ("development" !== 'production') {
  25888. console.warn("Unknown visual type " + key);
  25889. }
  25890. }
  25891. }
  25892. function setItemVisualFromData(data, dataIndex, key, value) {
  25893. switch (key) {
  25894. case 'color':
  25895. // Make sure not sharing style object.
  25896. var style = data.ensureUniqueItemVisual(dataIndex, 'style');
  25897. style[data.getVisual('drawType')] = value;
  25898. // Mark the color has been changed, not from palette anymore
  25899. data.setItemVisual(dataIndex, 'colorFromPalette', false);
  25900. break;
  25901. case 'opacity':
  25902. data.ensureUniqueItemVisual(dataIndex, 'style').opacity = value;
  25903. break;
  25904. case 'symbol':
  25905. case 'symbolSize':
  25906. case 'liftZ':
  25907. data.setItemVisual(dataIndex, key, value);
  25908. break;
  25909. default:
  25910. if ("development" !== 'production') {
  25911. console.warn("Unknown visual type " + key);
  25912. }
  25913. }
  25914. }
  25915. // Legacy data selection action.
  25916. // Includes: pieSelect, pieUnSelect, pieToggleSelect, mapSelect, mapUnSelect, mapToggleSelect
  25917. function createLegacyDataSelectAction(seriesType, ecRegisterAction) {
  25918. function getSeriesIndices(ecModel, payload) {
  25919. var seriesIndices = [];
  25920. ecModel.eachComponent({
  25921. mainType: 'series',
  25922. subType: seriesType,
  25923. query: payload
  25924. }, function (seriesModel) {
  25925. seriesIndices.push(seriesModel.seriesIndex);
  25926. });
  25927. return seriesIndices;
  25928. }
  25929. each([[seriesType + 'ToggleSelect', 'toggleSelect'], [seriesType + 'Select', 'select'], [seriesType + 'UnSelect', 'unselect']], function (eventsMap) {
  25930. ecRegisterAction(eventsMap[0], function (payload, ecModel, api) {
  25931. payload = extend({}, payload);
  25932. if ("development" !== 'production') {
  25933. deprecateReplaceLog(payload.type, eventsMap[1]);
  25934. }
  25935. api.dispatchAction(extend(payload, {
  25936. type: eventsMap[1],
  25937. seriesIndex: getSeriesIndices(ecModel, payload)
  25938. }));
  25939. });
  25940. });
  25941. }
  25942. function handleSeriesLegacySelectEvents(type, eventPostfix, ecIns, ecModel, payload) {
  25943. var legacyEventName = type + eventPostfix;
  25944. if (!ecIns.isSilent(legacyEventName)) {
  25945. if ("development" !== 'production') {
  25946. deprecateLog("event " + legacyEventName + " is deprecated.");
  25947. }
  25948. ecModel.eachComponent({
  25949. mainType: 'series',
  25950. subType: 'pie'
  25951. }, function (seriesModel) {
  25952. var seriesIndex = seriesModel.seriesIndex;
  25953. var selectedMap = seriesModel.option.selectedMap;
  25954. var selected = payload.selected;
  25955. for (var i = 0; i < selected.length; i++) {
  25956. if (selected[i].seriesIndex === seriesIndex) {
  25957. var data = seriesModel.getData();
  25958. var dataIndex = queryDataIndex(data, payload.fromActionPayload);
  25959. ecIns.trigger(legacyEventName, {
  25960. type: legacyEventName,
  25961. seriesId: seriesModel.id,
  25962. name: isArray(dataIndex) ? data.getName(dataIndex[0]) : data.getName(dataIndex),
  25963. selected: isString(selectedMap) ? selectedMap : extend({}, selectedMap)
  25964. });
  25965. }
  25966. }
  25967. });
  25968. }
  25969. }
  25970. function handleLegacySelectEvents(messageCenter, ecIns, api) {
  25971. messageCenter.on('selectchanged', function (params) {
  25972. var ecModel = api.getModel();
  25973. if (params.isFromClick) {
  25974. handleSeriesLegacySelectEvents('map', 'selectchanged', ecIns, ecModel, params);
  25975. handleSeriesLegacySelectEvents('pie', 'selectchanged', ecIns, ecModel, params);
  25976. } else if (params.fromAction === 'select') {
  25977. handleSeriesLegacySelectEvents('map', 'selected', ecIns, ecModel, params);
  25978. handleSeriesLegacySelectEvents('pie', 'selected', ecIns, ecModel, params);
  25979. } else if (params.fromAction === 'unselect') {
  25980. handleSeriesLegacySelectEvents('map', 'unselected', ecIns, ecModel, params);
  25981. handleSeriesLegacySelectEvents('pie', 'unselected', ecIns, ecModel, params);
  25982. }
  25983. });
  25984. }
  25985. /*
  25986. * Licensed to the Apache Software Foundation (ASF) under one
  25987. * or more contributor license agreements. See the NOTICE file
  25988. * distributed with this work for additional information
  25989. * regarding copyright ownership. The ASF licenses this file
  25990. * to you under the Apache License, Version 2.0 (the
  25991. * "License"); you may not use this file except in compliance
  25992. * with the License. You may obtain a copy of the License at
  25993. *
  25994. * http://www.apache.org/licenses/LICENSE-2.0
  25995. *
  25996. * Unless required by applicable law or agreed to in writing,
  25997. * software distributed under the License is distributed on an
  25998. * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
  25999. * KIND, either express or implied. See the License for the
  26000. * specific language governing permissions and limitations
  26001. * under the License.
  26002. */
  26003. /**
  26004. * AUTO-GENERATED FILE. DO NOT MODIFY.
  26005. */
  26006. /*
  26007. * Licensed to the Apache Software Foundation (ASF) under one
  26008. * or more contributor license agreements. See the NOTICE file
  26009. * distributed with this work for additional information
  26010. * regarding copyright ownership. The ASF licenses this file
  26011. * to you under the Apache License, Version 2.0 (the
  26012. * "License"); you may not use this file except in compliance
  26013. * with the License. You may obtain a copy of the License at
  26014. *
  26015. * http://www.apache.org/licenses/LICENSE-2.0
  26016. *
  26017. * Unless required by applicable law or agreed to in writing,
  26018. * software distributed under the License is distributed on an
  26019. * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
  26020. * KIND, either express or implied. See the License for the
  26021. * specific language governing permissions and limitations
  26022. * under the License.
  26023. */
  26024. function findEventDispatcher(target, det, returnFirstMatch) {
  26025. var found;
  26026. while (target) {
  26027. if (det(target)) {
  26028. found = target;
  26029. if (returnFirstMatch) {
  26030. break;
  26031. }
  26032. }
  26033. target = target.__hostTarget || target.parent;
  26034. }
  26035. return found;
  26036. }
  26037. var wmUniqueIndex = Math.round(Math.random() * 9);
  26038. var supportDefineProperty = typeof Object.defineProperty === 'function';
  26039. var WeakMap = (function () {
  26040. function WeakMap() {
  26041. this._id = '__ec_inner_' + wmUniqueIndex++;
  26042. }
  26043. WeakMap.prototype.get = function (key) {
  26044. return this._guard(key)[this._id];
  26045. };
  26046. WeakMap.prototype.set = function (key, value) {
  26047. var target = this._guard(key);
  26048. if (supportDefineProperty) {
  26049. Object.defineProperty(target, this._id, {
  26050. value: value,
  26051. enumerable: false,
  26052. configurable: true
  26053. });
  26054. }
  26055. else {
  26056. target[this._id] = value;
  26057. }
  26058. return this;
  26059. };
  26060. WeakMap.prototype["delete"] = function (key) {
  26061. if (this.has(key)) {
  26062. delete this._guard(key)[this._id];
  26063. return true;
  26064. }
  26065. return false;
  26066. };
  26067. WeakMap.prototype.has = function (key) {
  26068. return !!this._guard(key)[this._id];
  26069. };
  26070. WeakMap.prototype._guard = function (key) {
  26071. if (key !== Object(key)) {
  26072. throw TypeError('Value of WeakMap is not a non-null object.');
  26073. }
  26074. return key;
  26075. };
  26076. return WeakMap;
  26077. }());
  26078. /**
  26079. * Triangle shape
  26080. * @inner
  26081. */
  26082. var Triangle = Path.extend({
  26083. type: 'triangle',
  26084. shape: {
  26085. cx: 0,
  26086. cy: 0,
  26087. width: 0,
  26088. height: 0
  26089. },
  26090. buildPath: function (path, shape) {
  26091. var cx = shape.cx;
  26092. var cy = shape.cy;
  26093. var width = shape.width / 2;
  26094. var height = shape.height / 2;
  26095. path.moveTo(cx, cy - height);
  26096. path.lineTo(cx + width, cy + height);
  26097. path.lineTo(cx - width, cy + height);
  26098. path.closePath();
  26099. }
  26100. });
  26101. /**
  26102. * Diamond shape
  26103. * @inner
  26104. */
  26105. var Diamond = Path.extend({
  26106. type: 'diamond',
  26107. shape: {
  26108. cx: 0,
  26109. cy: 0,
  26110. width: 0,
  26111. height: 0
  26112. },
  26113. buildPath: function (path, shape) {
  26114. var cx = shape.cx;
  26115. var cy = shape.cy;
  26116. var width = shape.width / 2;
  26117. var height = shape.height / 2;
  26118. path.moveTo(cx, cy - height);
  26119. path.lineTo(cx + width, cy);
  26120. path.lineTo(cx, cy + height);
  26121. path.lineTo(cx - width, cy);
  26122. path.closePath();
  26123. }
  26124. });
  26125. /**
  26126. * Pin shape
  26127. * @inner
  26128. */
  26129. var Pin = Path.extend({
  26130. type: 'pin',
  26131. shape: {
  26132. // x, y on the cusp
  26133. x: 0,
  26134. y: 0,
  26135. width: 0,
  26136. height: 0
  26137. },
  26138. buildPath: function (path, shape) {
  26139. var x = shape.x;
  26140. var y = shape.y;
  26141. var w = shape.width / 5 * 3;
  26142. // Height must be larger than width
  26143. var h = Math.max(w, shape.height);
  26144. var r = w / 2;
  26145. // Dist on y with tangent point and circle center
  26146. var dy = r * r / (h - r);
  26147. var cy = y - h + r + dy;
  26148. var angle = Math.asin(dy / r);
  26149. // Dist on x with tangent point and circle center
  26150. var dx = Math.cos(angle) * r;
  26151. var tanX = Math.sin(angle);
  26152. var tanY = Math.cos(angle);
  26153. var cpLen = r * 0.6;
  26154. var cpLen2 = r * 0.7;
  26155. path.moveTo(x - dx, cy + dy);
  26156. path.arc(x, cy, r, Math.PI - angle, Math.PI * 2 + angle);
  26157. path.bezierCurveTo(x + dx - tanX * cpLen, cy + dy + tanY * cpLen, x, y - cpLen2, x, y);
  26158. path.bezierCurveTo(x, y - cpLen2, x - dx + tanX * cpLen, cy + dy + tanY * cpLen, x - dx, cy + dy);
  26159. path.closePath();
  26160. }
  26161. });
  26162. /**
  26163. * Arrow shape
  26164. * @inner
  26165. */
  26166. var Arrow = Path.extend({
  26167. type: 'arrow',
  26168. shape: {
  26169. x: 0,
  26170. y: 0,
  26171. width: 0,
  26172. height: 0
  26173. },
  26174. buildPath: function (ctx, shape) {
  26175. var height = shape.height;
  26176. var width = shape.width;
  26177. var x = shape.x;
  26178. var y = shape.y;
  26179. var dx = width / 3 * 2;
  26180. ctx.moveTo(x, y);
  26181. ctx.lineTo(x + dx, y + height);
  26182. ctx.lineTo(x, y + height / 4 * 3);
  26183. ctx.lineTo(x - dx, y + height);
  26184. ctx.lineTo(x, y);
  26185. ctx.closePath();
  26186. }
  26187. });
  26188. /**
  26189. * Map of path constructors
  26190. */
  26191. // TODO Use function to build symbol path.
  26192. var symbolCtors = {
  26193. line: Line,
  26194. rect: Rect,
  26195. roundRect: Rect,
  26196. square: Rect,
  26197. circle: Circle,
  26198. diamond: Diamond,
  26199. pin: Pin,
  26200. arrow: Arrow,
  26201. triangle: Triangle
  26202. };
  26203. var symbolShapeMakers = {
  26204. line: function (x, y, w, h, shape) {
  26205. shape.x1 = x;
  26206. shape.y1 = y + h / 2;
  26207. shape.x2 = x + w;
  26208. shape.y2 = y + h / 2;
  26209. },
  26210. rect: function (x, y, w, h, shape) {
  26211. shape.x = x;
  26212. shape.y = y;
  26213. shape.width = w;
  26214. shape.height = h;
  26215. },
  26216. roundRect: function (x, y, w, h, shape) {
  26217. shape.x = x;
  26218. shape.y = y;
  26219. shape.width = w;
  26220. shape.height = h;
  26221. shape.r = Math.min(w, h) / 4;
  26222. },
  26223. square: function (x, y, w, h, shape) {
  26224. var size = Math.min(w, h);
  26225. shape.x = x;
  26226. shape.y = y;
  26227. shape.width = size;
  26228. shape.height = size;
  26229. },
  26230. circle: function (x, y, w, h, shape) {
  26231. // Put circle in the center of square
  26232. shape.cx = x + w / 2;
  26233. shape.cy = y + h / 2;
  26234. shape.r = Math.min(w, h) / 2;
  26235. },
  26236. diamond: function (x, y, w, h, shape) {
  26237. shape.cx = x + w / 2;
  26238. shape.cy = y + h / 2;
  26239. shape.width = w;
  26240. shape.height = h;
  26241. },
  26242. pin: function (x, y, w, h, shape) {
  26243. shape.x = x + w / 2;
  26244. shape.y = y + h / 2;
  26245. shape.width = w;
  26246. shape.height = h;
  26247. },
  26248. arrow: function (x, y, w, h, shape) {
  26249. shape.x = x + w / 2;
  26250. shape.y = y + h / 2;
  26251. shape.width = w;
  26252. shape.height = h;
  26253. },
  26254. triangle: function (x, y, w, h, shape) {
  26255. shape.cx = x + w / 2;
  26256. shape.cy = y + h / 2;
  26257. shape.width = w;
  26258. shape.height = h;
  26259. }
  26260. };
  26261. var symbolBuildProxies = {};
  26262. each(symbolCtors, function (Ctor, name) {
  26263. symbolBuildProxies[name] = new Ctor();
  26264. });
  26265. var SymbolClz = Path.extend({
  26266. type: 'symbol',
  26267. shape: {
  26268. symbolType: '',
  26269. x: 0,
  26270. y: 0,
  26271. width: 0,
  26272. height: 0
  26273. },
  26274. calculateTextPosition: function (out, config, rect) {
  26275. var res = calculateTextPosition(out, config, rect);
  26276. var shape = this.shape;
  26277. if (shape && shape.symbolType === 'pin' && config.position === 'inside') {
  26278. res.y = rect.y + rect.height * 0.4;
  26279. }
  26280. return res;
  26281. },
  26282. buildPath: function (ctx, shape, inBundle) {
  26283. var symbolType = shape.symbolType;
  26284. if (symbolType !== 'none') {
  26285. var proxySymbol = symbolBuildProxies[symbolType];
  26286. if (!proxySymbol) {
  26287. // Default rect
  26288. symbolType = 'rect';
  26289. proxySymbol = symbolBuildProxies[symbolType];
  26290. }
  26291. symbolShapeMakers[symbolType](shape.x, shape.y, shape.width, shape.height, proxySymbol.shape);
  26292. proxySymbol.buildPath(ctx, proxySymbol.shape, inBundle);
  26293. }
  26294. }
  26295. });
  26296. // Provide setColor helper method to avoid determine if set the fill or stroke outside
  26297. function symbolPathSetColor(color, innerColor) {
  26298. if (this.type !== 'image') {
  26299. var symbolStyle = this.style;
  26300. if (this.__isEmptyBrush) {
  26301. symbolStyle.stroke = color;
  26302. symbolStyle.fill = innerColor || tokens.color.neutral00;
  26303. // TODO Same width with lineStyle in LineView
  26304. symbolStyle.lineWidth = 2;
  26305. } else if (this.shape.symbolType === 'line') {
  26306. symbolStyle.stroke = color;
  26307. } else {
  26308. symbolStyle.fill = color;
  26309. }
  26310. this.markRedraw();
  26311. }
  26312. }
  26313. /**
  26314. * Create a symbol element with given symbol configuration: shape, x, y, width, height, color
  26315. */
  26316. function createSymbol(symbolType, x, y, w, h, color,
  26317. // whether to keep the ratio of w/h,
  26318. keepAspect) {
  26319. // TODO Support image object, DynamicImage.
  26320. var isEmpty = symbolType.indexOf('empty') === 0;
  26321. if (isEmpty) {
  26322. symbolType = symbolType.substr(5, 1).toLowerCase() + symbolType.substr(6);
  26323. }
  26324. var symbolPath;
  26325. if (symbolType.indexOf('image://') === 0) {
  26326. symbolPath = makeImage(symbolType.slice(8), new BoundingRect(x, y, w, h), keepAspect ? 'center' : 'cover');
  26327. } else if (symbolType.indexOf('path://') === 0) {
  26328. symbolPath = makePath(symbolType.slice(7), {}, new BoundingRect(x, y, w, h), keepAspect ? 'center' : 'cover');
  26329. } else {
  26330. symbolPath = new SymbolClz({
  26331. shape: {
  26332. symbolType: symbolType,
  26333. x: x,
  26334. y: y,
  26335. width: w,
  26336. height: h
  26337. }
  26338. });
  26339. }
  26340. symbolPath.__isEmptyBrush = isEmpty;
  26341. // TODO Should deprecate setColor
  26342. symbolPath.setColor = symbolPathSetColor;
  26343. if (color) {
  26344. symbolPath.setColor(color);
  26345. }
  26346. return symbolPath;
  26347. }
  26348. function normalizeSymbolSize(symbolSize) {
  26349. if (!isArray(symbolSize)) {
  26350. symbolSize = [+symbolSize, +symbolSize];
  26351. }
  26352. return [symbolSize[0] || 0, symbolSize[1] || 0];
  26353. }
  26354. function normalizeSymbolOffset(symbolOffset, symbolSize) {
  26355. if (symbolOffset == null) {
  26356. return;
  26357. }
  26358. if (!isArray(symbolOffset)) {
  26359. symbolOffset = [symbolOffset, symbolOffset];
  26360. }
  26361. return [parsePercent$1(symbolOffset[0], symbolSize[0]) || 0, parsePercent$1(retrieve2(symbolOffset[1], symbolOffset[0]), symbolSize[1]) || 0];
  26362. }
  26363. function isSafeNum(num) {
  26364. return isFinite(num);
  26365. }
  26366. function createLinearGradient(ctx, obj, rect) {
  26367. var x = obj.x == null ? 0 : obj.x;
  26368. var x2 = obj.x2 == null ? 1 : obj.x2;
  26369. var y = obj.y == null ? 0 : obj.y;
  26370. var y2 = obj.y2 == null ? 0 : obj.y2;
  26371. if (!obj.global) {
  26372. x = x * rect.width + rect.x;
  26373. x2 = x2 * rect.width + rect.x;
  26374. y = y * rect.height + rect.y;
  26375. y2 = y2 * rect.height + rect.y;
  26376. }
  26377. x = isSafeNum(x) ? x : 0;
  26378. x2 = isSafeNum(x2) ? x2 : 1;
  26379. y = isSafeNum(y) ? y : 0;
  26380. y2 = isSafeNum(y2) ? y2 : 0;
  26381. var canvasGradient = ctx.createLinearGradient(x, y, x2, y2);
  26382. return canvasGradient;
  26383. }
  26384. function createRadialGradient(ctx, obj, rect) {
  26385. var width = rect.width;
  26386. var height = rect.height;
  26387. var min = Math.min(width, height);
  26388. var x = obj.x == null ? 0.5 : obj.x;
  26389. var y = obj.y == null ? 0.5 : obj.y;
  26390. var r = obj.r == null ? 0.5 : obj.r;
  26391. if (!obj.global) {
  26392. x = x * width + rect.x;
  26393. y = y * height + rect.y;
  26394. r = r * min;
  26395. }
  26396. x = isSafeNum(x) ? x : 0.5;
  26397. y = isSafeNum(y) ? y : 0.5;
  26398. r = r >= 0 && isSafeNum(r) ? r : 0.5;
  26399. var canvasGradient = ctx.createRadialGradient(x, y, 0, x, y, r);
  26400. return canvasGradient;
  26401. }
  26402. function getCanvasGradient(ctx, obj, rect) {
  26403. var canvasGradient = obj.type === 'radial'
  26404. ? createRadialGradient(ctx, obj, rect)
  26405. : createLinearGradient(ctx, obj, rect);
  26406. var colorStops = obj.colorStops;
  26407. for (var i = 0; i < colorStops.length; i++) {
  26408. canvasGradient.addColorStop(colorStops[i].offset, colorStops[i].color);
  26409. }
  26410. return canvasGradient;
  26411. }
  26412. function isClipPathChanged(clipPaths, prevClipPaths) {
  26413. if (clipPaths === prevClipPaths || (!clipPaths && !prevClipPaths)) {
  26414. return false;
  26415. }
  26416. if (!clipPaths || !prevClipPaths || (clipPaths.length !== prevClipPaths.length)) {
  26417. return true;
  26418. }
  26419. for (var i = 0; i < clipPaths.length; i++) {
  26420. if (clipPaths[i] !== prevClipPaths[i]) {
  26421. return true;
  26422. }
  26423. }
  26424. return false;
  26425. }
  26426. function parseInt10(val) {
  26427. return parseInt(val, 10);
  26428. }
  26429. function getSize(root, whIdx, opts) {
  26430. var wh = ['width', 'height'][whIdx];
  26431. var cwh = ['clientWidth', 'clientHeight'][whIdx];
  26432. var plt = ['paddingLeft', 'paddingTop'][whIdx];
  26433. var prb = ['paddingRight', 'paddingBottom'][whIdx];
  26434. if (opts[wh] != null && opts[wh] !== 'auto') {
  26435. return parseFloat(opts[wh]);
  26436. }
  26437. var stl = document.defaultView.getComputedStyle(root);
  26438. return ((root[cwh] || parseInt10(stl[wh]) || parseInt10(root.style[wh]))
  26439. - (parseInt10(stl[plt]) || 0)
  26440. - (parseInt10(stl[prb]) || 0)) | 0;
  26441. }
  26442. function normalizeLineDash(lineType, lineWidth) {
  26443. if (!lineType || lineType === 'solid' || !(lineWidth > 0)) {
  26444. return null;
  26445. }
  26446. return lineType === 'dashed'
  26447. ? [4 * lineWidth, 2 * lineWidth]
  26448. : lineType === 'dotted'
  26449. ? [lineWidth]
  26450. : isNumber(lineType)
  26451. ? [lineType] : isArray(lineType) ? lineType : null;
  26452. }
  26453. function getLineDash(el) {
  26454. var style = el.style;
  26455. var lineDash = style.lineDash && style.lineWidth > 0 && normalizeLineDash(style.lineDash, style.lineWidth);
  26456. var lineDashOffset = style.lineDashOffset;
  26457. if (lineDash) {
  26458. var lineScale_1 = (style.strokeNoScale && el.getLineScale) ? el.getLineScale() : 1;
  26459. if (lineScale_1 && lineScale_1 !== 1) {
  26460. lineDash = map(lineDash, function (rawVal) {
  26461. return rawVal / lineScale_1;
  26462. });
  26463. lineDashOffset /= lineScale_1;
  26464. }
  26465. }
  26466. return [lineDash, lineDashOffset];
  26467. }
  26468. var pathProxyForDraw = new PathProxy(true);
  26469. function styleHasStroke(style) {
  26470. var stroke = style.stroke;
  26471. return !(stroke == null || stroke === 'none' || !(style.lineWidth > 0));
  26472. }
  26473. function isValidStrokeFillStyle(strokeOrFill) {
  26474. return typeof strokeOrFill === 'string' && strokeOrFill !== 'none';
  26475. }
  26476. function styleHasFill(style) {
  26477. var fill = style.fill;
  26478. return fill != null && fill !== 'none';
  26479. }
  26480. function doFillPath(ctx, style) {
  26481. if (style.fillOpacity != null && style.fillOpacity !== 1) {
  26482. var originalGlobalAlpha = ctx.globalAlpha;
  26483. ctx.globalAlpha = style.fillOpacity * style.opacity;
  26484. ctx.fill();
  26485. ctx.globalAlpha = originalGlobalAlpha;
  26486. }
  26487. else {
  26488. ctx.fill();
  26489. }
  26490. }
  26491. function doStrokePath(ctx, style) {
  26492. if (style.strokeOpacity != null && style.strokeOpacity !== 1) {
  26493. var originalGlobalAlpha = ctx.globalAlpha;
  26494. ctx.globalAlpha = style.strokeOpacity * style.opacity;
  26495. ctx.stroke();
  26496. ctx.globalAlpha = originalGlobalAlpha;
  26497. }
  26498. else {
  26499. ctx.stroke();
  26500. }
  26501. }
  26502. function createCanvasPattern(ctx, pattern, el) {
  26503. var image = createOrUpdateImage(pattern.image, pattern.__image, el);
  26504. if (isImageReady(image)) {
  26505. var canvasPattern = ctx.createPattern(image, pattern.repeat || 'repeat');
  26506. if (typeof DOMMatrix === 'function'
  26507. && canvasPattern
  26508. && canvasPattern.setTransform) {
  26509. var matrix = new DOMMatrix();
  26510. matrix.translateSelf((pattern.x || 0), (pattern.y || 0));
  26511. matrix.rotateSelf(0, 0, (pattern.rotation || 0) * RADIAN_TO_DEGREE);
  26512. matrix.scaleSelf((pattern.scaleX || 1), (pattern.scaleY || 1));
  26513. canvasPattern.setTransform(matrix);
  26514. }
  26515. return canvasPattern;
  26516. }
  26517. }
  26518. function brushPath(ctx, el, style, inBatch) {
  26519. var _a;
  26520. var hasStroke = styleHasStroke(style);
  26521. var hasFill = styleHasFill(style);
  26522. var strokePercent = style.strokePercent;
  26523. var strokePart = strokePercent < 1;
  26524. var firstDraw = !el.path;
  26525. if ((!el.silent || strokePart) && firstDraw) {
  26526. el.createPathProxy();
  26527. }
  26528. var path = el.path || pathProxyForDraw;
  26529. var dirtyFlag = el.__dirty;
  26530. if (!inBatch) {
  26531. var fill = style.fill;
  26532. var stroke = style.stroke;
  26533. var hasFillGradient = hasFill && !!fill.colorStops;
  26534. var hasStrokeGradient = hasStroke && !!stroke.colorStops;
  26535. var hasFillPattern = hasFill && !!fill.image;
  26536. var hasStrokePattern = hasStroke && !!stroke.image;
  26537. var fillGradient = void 0;
  26538. var strokeGradient = void 0;
  26539. var fillPattern = void 0;
  26540. var strokePattern = void 0;
  26541. var rect = void 0;
  26542. if (hasFillGradient || hasStrokeGradient) {
  26543. rect = el.getBoundingRect();
  26544. }
  26545. if (hasFillGradient) {
  26546. fillGradient = dirtyFlag
  26547. ? getCanvasGradient(ctx, fill, rect)
  26548. : el.__canvasFillGradient;
  26549. el.__canvasFillGradient = fillGradient;
  26550. }
  26551. if (hasStrokeGradient) {
  26552. strokeGradient = dirtyFlag
  26553. ? getCanvasGradient(ctx, stroke, rect)
  26554. : el.__canvasStrokeGradient;
  26555. el.__canvasStrokeGradient = strokeGradient;
  26556. }
  26557. if (hasFillPattern) {
  26558. fillPattern = (dirtyFlag || !el.__canvasFillPattern)
  26559. ? createCanvasPattern(ctx, fill, el)
  26560. : el.__canvasFillPattern;
  26561. el.__canvasFillPattern = fillPattern;
  26562. }
  26563. if (hasStrokePattern) {
  26564. strokePattern = (dirtyFlag || !el.__canvasStrokePattern)
  26565. ? createCanvasPattern(ctx, stroke, el)
  26566. : el.__canvasStrokePattern;
  26567. el.__canvasStrokePattern = strokePattern;
  26568. }
  26569. if (hasFillGradient) {
  26570. ctx.fillStyle = fillGradient;
  26571. }
  26572. else if (hasFillPattern) {
  26573. if (fillPattern) {
  26574. ctx.fillStyle = fillPattern;
  26575. }
  26576. else {
  26577. hasFill = false;
  26578. }
  26579. }
  26580. if (hasStrokeGradient) {
  26581. ctx.strokeStyle = strokeGradient;
  26582. }
  26583. else if (hasStrokePattern) {
  26584. if (strokePattern) {
  26585. ctx.strokeStyle = strokePattern;
  26586. }
  26587. else {
  26588. hasStroke = false;
  26589. }
  26590. }
  26591. }
  26592. var scale = el.getGlobalScale();
  26593. path.setScale(scale[0], scale[1], el.segmentIgnoreThreshold);
  26594. var lineDash;
  26595. var lineDashOffset;
  26596. if (ctx.setLineDash && style.lineDash) {
  26597. _a = getLineDash(el), lineDash = _a[0], lineDashOffset = _a[1];
  26598. }
  26599. var needsRebuild = true;
  26600. if (firstDraw || (dirtyFlag & SHAPE_CHANGED_BIT)) {
  26601. path.setDPR(ctx.dpr);
  26602. if (strokePart) {
  26603. path.setContext(null);
  26604. }
  26605. else {
  26606. path.setContext(ctx);
  26607. needsRebuild = false;
  26608. }
  26609. path.reset();
  26610. el.buildPath(path, el.shape, inBatch);
  26611. path.toStatic();
  26612. el.pathUpdated();
  26613. }
  26614. if (needsRebuild) {
  26615. path.rebuildPath(ctx, strokePart ? strokePercent : 1);
  26616. }
  26617. if (lineDash) {
  26618. ctx.setLineDash(lineDash);
  26619. ctx.lineDashOffset = lineDashOffset;
  26620. }
  26621. if (!inBatch) {
  26622. if (style.strokeFirst) {
  26623. if (hasStroke) {
  26624. doStrokePath(ctx, style);
  26625. }
  26626. if (hasFill) {
  26627. doFillPath(ctx, style);
  26628. }
  26629. }
  26630. else {
  26631. if (hasFill) {
  26632. doFillPath(ctx, style);
  26633. }
  26634. if (hasStroke) {
  26635. doStrokePath(ctx, style);
  26636. }
  26637. }
  26638. }
  26639. if (lineDash) {
  26640. ctx.setLineDash([]);
  26641. }
  26642. }
  26643. function brushImage(ctx, el, style) {
  26644. var image = el.__image = createOrUpdateImage(style.image, el.__image, el, el.onload);
  26645. if (!image || !isImageReady(image)) {
  26646. return;
  26647. }
  26648. var x = style.x || 0;
  26649. var y = style.y || 0;
  26650. var width = el.getWidth();
  26651. var height = el.getHeight();
  26652. var aspect = image.width / image.height;
  26653. if (width == null && height != null) {
  26654. width = height * aspect;
  26655. }
  26656. else if (height == null && width != null) {
  26657. height = width / aspect;
  26658. }
  26659. else if (width == null && height == null) {
  26660. width = image.width;
  26661. height = image.height;
  26662. }
  26663. if (style.sWidth && style.sHeight) {
  26664. var sx = style.sx || 0;
  26665. var sy = style.sy || 0;
  26666. ctx.drawImage(image, sx, sy, style.sWidth, style.sHeight, x, y, width, height);
  26667. }
  26668. else if (style.sx && style.sy) {
  26669. var sx = style.sx;
  26670. var sy = style.sy;
  26671. var sWidth = width - sx;
  26672. var sHeight = height - sy;
  26673. ctx.drawImage(image, sx, sy, sWidth, sHeight, x, y, width, height);
  26674. }
  26675. else {
  26676. ctx.drawImage(image, x, y, width, height);
  26677. }
  26678. }
  26679. function brushText(ctx, el, style) {
  26680. var _a;
  26681. var text = style.text;
  26682. text != null && (text += '');
  26683. if (text) {
  26684. ctx.font = style.font || DEFAULT_FONT;
  26685. ctx.textAlign = style.textAlign;
  26686. ctx.textBaseline = style.textBaseline;
  26687. var lineDash = void 0;
  26688. var lineDashOffset = void 0;
  26689. if (ctx.setLineDash && style.lineDash) {
  26690. _a = getLineDash(el), lineDash = _a[0], lineDashOffset = _a[1];
  26691. }
  26692. if (lineDash) {
  26693. ctx.setLineDash(lineDash);
  26694. ctx.lineDashOffset = lineDashOffset;
  26695. }
  26696. if (style.strokeFirst) {
  26697. if (styleHasStroke(style)) {
  26698. ctx.strokeText(text, style.x, style.y);
  26699. }
  26700. if (styleHasFill(style)) {
  26701. ctx.fillText(text, style.x, style.y);
  26702. }
  26703. }
  26704. else {
  26705. if (styleHasFill(style)) {
  26706. ctx.fillText(text, style.x, style.y);
  26707. }
  26708. if (styleHasStroke(style)) {
  26709. ctx.strokeText(text, style.x, style.y);
  26710. }
  26711. }
  26712. if (lineDash) {
  26713. ctx.setLineDash([]);
  26714. }
  26715. }
  26716. }
  26717. var SHADOW_NUMBER_PROPS = ['shadowBlur', 'shadowOffsetX', 'shadowOffsetY'];
  26718. var STROKE_PROPS = [
  26719. ['lineCap', 'butt'], ['lineJoin', 'miter'], ['miterLimit', 10]
  26720. ];
  26721. function bindCommonProps(ctx, style, prevStyle, forceSetAll, scope) {
  26722. var styleChanged = false;
  26723. if (!forceSetAll) {
  26724. prevStyle = prevStyle || {};
  26725. if (style === prevStyle) {
  26726. return false;
  26727. }
  26728. }
  26729. if (forceSetAll || style.opacity !== prevStyle.opacity) {
  26730. flushPathDrawn(ctx, scope);
  26731. styleChanged = true;
  26732. var opacity = Math.max(Math.min(style.opacity, 1), 0);
  26733. ctx.globalAlpha = isNaN(opacity) ? DEFAULT_COMMON_STYLE.opacity : opacity;
  26734. }
  26735. if (forceSetAll || style.blend !== prevStyle.blend) {
  26736. if (!styleChanged) {
  26737. flushPathDrawn(ctx, scope);
  26738. styleChanged = true;
  26739. }
  26740. ctx.globalCompositeOperation = style.blend || DEFAULT_COMMON_STYLE.blend;
  26741. }
  26742. for (var i = 0; i < SHADOW_NUMBER_PROPS.length; i++) {
  26743. var propName = SHADOW_NUMBER_PROPS[i];
  26744. if (forceSetAll || style[propName] !== prevStyle[propName]) {
  26745. if (!styleChanged) {
  26746. flushPathDrawn(ctx, scope);
  26747. styleChanged = true;
  26748. }
  26749. ctx[propName] = ctx.dpr * (style[propName] || 0);
  26750. }
  26751. }
  26752. if (forceSetAll || style.shadowColor !== prevStyle.shadowColor) {
  26753. if (!styleChanged) {
  26754. flushPathDrawn(ctx, scope);
  26755. styleChanged = true;
  26756. }
  26757. ctx.shadowColor = style.shadowColor || DEFAULT_COMMON_STYLE.shadowColor;
  26758. }
  26759. return styleChanged;
  26760. }
  26761. function bindPathAndTextCommonStyle(ctx, el, prevEl, forceSetAll, scope) {
  26762. var style = getStyle(el, scope.inHover);
  26763. var prevStyle = forceSetAll
  26764. ? null
  26765. : (prevEl && getStyle(prevEl, scope.inHover) || {});
  26766. if (style === prevStyle) {
  26767. return false;
  26768. }
  26769. var styleChanged = bindCommonProps(ctx, style, prevStyle, forceSetAll, scope);
  26770. if (forceSetAll || style.fill !== prevStyle.fill) {
  26771. if (!styleChanged) {
  26772. flushPathDrawn(ctx, scope);
  26773. styleChanged = true;
  26774. }
  26775. isValidStrokeFillStyle(style.fill) && (ctx.fillStyle = style.fill);
  26776. }
  26777. if (forceSetAll || style.stroke !== prevStyle.stroke) {
  26778. if (!styleChanged) {
  26779. flushPathDrawn(ctx, scope);
  26780. styleChanged = true;
  26781. }
  26782. isValidStrokeFillStyle(style.stroke) && (ctx.strokeStyle = style.stroke);
  26783. }
  26784. if (forceSetAll || style.opacity !== prevStyle.opacity) {
  26785. if (!styleChanged) {
  26786. flushPathDrawn(ctx, scope);
  26787. styleChanged = true;
  26788. }
  26789. ctx.globalAlpha = style.opacity == null ? 1 : style.opacity;
  26790. }
  26791. if (el.hasStroke()) {
  26792. var lineWidth = style.lineWidth;
  26793. var newLineWidth = lineWidth / ((style.strokeNoScale && el.getLineScale) ? el.getLineScale() : 1);
  26794. if (ctx.lineWidth !== newLineWidth) {
  26795. if (!styleChanged) {
  26796. flushPathDrawn(ctx, scope);
  26797. styleChanged = true;
  26798. }
  26799. ctx.lineWidth = newLineWidth;
  26800. }
  26801. }
  26802. for (var i = 0; i < STROKE_PROPS.length; i++) {
  26803. var prop = STROKE_PROPS[i];
  26804. var propName = prop[0];
  26805. if (forceSetAll || style[propName] !== prevStyle[propName]) {
  26806. if (!styleChanged) {
  26807. flushPathDrawn(ctx, scope);
  26808. styleChanged = true;
  26809. }
  26810. ctx[propName] = style[propName] || prop[1];
  26811. }
  26812. }
  26813. return styleChanged;
  26814. }
  26815. function bindImageStyle(ctx, el, prevEl, forceSetAll, scope) {
  26816. return bindCommonProps(ctx, getStyle(el, scope.inHover), prevEl && getStyle(prevEl, scope.inHover), forceSetAll, scope);
  26817. }
  26818. function setContextTransform(ctx, el) {
  26819. var m = el.transform;
  26820. var dpr = ctx.dpr || 1;
  26821. if (m) {
  26822. ctx.setTransform(dpr * m[0], dpr * m[1], dpr * m[2], dpr * m[3], dpr * m[4], dpr * m[5]);
  26823. }
  26824. else {
  26825. ctx.setTransform(dpr, 0, 0, dpr, 0, 0);
  26826. }
  26827. }
  26828. function updateClipStatus(clipPaths, ctx, scope) {
  26829. var allClipped = false;
  26830. for (var i = 0; i < clipPaths.length; i++) {
  26831. var clipPath = clipPaths[i];
  26832. allClipped = allClipped || clipPath.isZeroArea();
  26833. setContextTransform(ctx, clipPath);
  26834. ctx.beginPath();
  26835. clipPath.buildPath(ctx, clipPath.shape);
  26836. ctx.clip();
  26837. }
  26838. scope.allClipped = allClipped;
  26839. }
  26840. function isTransformChanged(m0, m1) {
  26841. if (m0 && m1) {
  26842. return m0[0] !== m1[0]
  26843. || m0[1] !== m1[1]
  26844. || m0[2] !== m1[2]
  26845. || m0[3] !== m1[3]
  26846. || m0[4] !== m1[4]
  26847. || m0[5] !== m1[5];
  26848. }
  26849. else if (!m0 && !m1) {
  26850. return false;
  26851. }
  26852. return true;
  26853. }
  26854. var DRAW_TYPE_PATH = 1;
  26855. var DRAW_TYPE_IMAGE = 2;
  26856. var DRAW_TYPE_TEXT = 3;
  26857. var DRAW_TYPE_INCREMENTAL = 4;
  26858. function canPathBatch(style) {
  26859. var hasFill = styleHasFill(style);
  26860. var hasStroke = styleHasStroke(style);
  26861. return !(style.lineDash
  26862. || !(+hasFill ^ +hasStroke)
  26863. || (hasFill && typeof style.fill !== 'string')
  26864. || (hasStroke && typeof style.stroke !== 'string')
  26865. || style.strokePercent < 1
  26866. || style.strokeOpacity < 1
  26867. || style.fillOpacity < 1);
  26868. }
  26869. function flushPathDrawn(ctx, scope) {
  26870. scope.batchFill && ctx.fill();
  26871. scope.batchStroke && ctx.stroke();
  26872. scope.batchFill = '';
  26873. scope.batchStroke = '';
  26874. }
  26875. function getStyle(el, inHover) {
  26876. return inHover ? (el.__hoverStyle || el.style) : el.style;
  26877. }
  26878. function brushSingle(ctx, el) {
  26879. brush(ctx, el, { inHover: false, viewWidth: 0, viewHeight: 0 }, true);
  26880. }
  26881. function brush(ctx, el, scope, isLast) {
  26882. var m = el.transform;
  26883. if (!el.shouldBePainted(scope.viewWidth, scope.viewHeight, false, false)) {
  26884. el.__dirty &= ~REDRAW_BIT;
  26885. el.__isRendered = false;
  26886. return;
  26887. }
  26888. var clipPaths = el.__clipPaths;
  26889. var prevElClipPaths = scope.prevElClipPaths;
  26890. var forceSetTransform = false;
  26891. var forceSetStyle = false;
  26892. if (!prevElClipPaths || isClipPathChanged(clipPaths, prevElClipPaths)) {
  26893. if (prevElClipPaths && prevElClipPaths.length) {
  26894. flushPathDrawn(ctx, scope);
  26895. ctx.restore();
  26896. forceSetStyle = forceSetTransform = true;
  26897. scope.prevElClipPaths = null;
  26898. scope.allClipped = false;
  26899. scope.prevEl = null;
  26900. }
  26901. if (clipPaths && clipPaths.length) {
  26902. flushPathDrawn(ctx, scope);
  26903. ctx.save();
  26904. updateClipStatus(clipPaths, ctx, scope);
  26905. forceSetTransform = true;
  26906. }
  26907. scope.prevElClipPaths = clipPaths;
  26908. }
  26909. if (scope.allClipped) {
  26910. el.__isRendered = false;
  26911. return;
  26912. }
  26913. el.beforeBrush && el.beforeBrush();
  26914. el.innerBeforeBrush();
  26915. var prevEl = scope.prevEl;
  26916. if (!prevEl) {
  26917. forceSetStyle = forceSetTransform = true;
  26918. }
  26919. var canBatchPath = el instanceof Path
  26920. && el.autoBatch
  26921. && canPathBatch(el.style);
  26922. if (forceSetTransform || isTransformChanged(m, prevEl.transform)) {
  26923. flushPathDrawn(ctx, scope);
  26924. setContextTransform(ctx, el);
  26925. }
  26926. else if (!canBatchPath) {
  26927. flushPathDrawn(ctx, scope);
  26928. }
  26929. var style = getStyle(el, scope.inHover);
  26930. if (el instanceof Path) {
  26931. if (scope.lastDrawType !== DRAW_TYPE_PATH) {
  26932. forceSetStyle = true;
  26933. scope.lastDrawType = DRAW_TYPE_PATH;
  26934. }
  26935. bindPathAndTextCommonStyle(ctx, el, prevEl, forceSetStyle, scope);
  26936. if (!canBatchPath || (!scope.batchFill && !scope.batchStroke)) {
  26937. ctx.beginPath();
  26938. }
  26939. brushPath(ctx, el, style, canBatchPath);
  26940. if (canBatchPath) {
  26941. scope.batchFill = style.fill || '';
  26942. scope.batchStroke = style.stroke || '';
  26943. }
  26944. }
  26945. else {
  26946. if (el instanceof TSpan) {
  26947. if (scope.lastDrawType !== DRAW_TYPE_TEXT) {
  26948. forceSetStyle = true;
  26949. scope.lastDrawType = DRAW_TYPE_TEXT;
  26950. }
  26951. bindPathAndTextCommonStyle(ctx, el, prevEl, forceSetStyle, scope);
  26952. brushText(ctx, el, style);
  26953. }
  26954. else if (el instanceof ZRImage) {
  26955. if (scope.lastDrawType !== DRAW_TYPE_IMAGE) {
  26956. forceSetStyle = true;
  26957. scope.lastDrawType = DRAW_TYPE_IMAGE;
  26958. }
  26959. bindImageStyle(ctx, el, prevEl, forceSetStyle, scope);
  26960. brushImage(ctx, el, style);
  26961. }
  26962. else if (el.getTemporalDisplayables) {
  26963. if (scope.lastDrawType !== DRAW_TYPE_INCREMENTAL) {
  26964. forceSetStyle = true;
  26965. scope.lastDrawType = DRAW_TYPE_INCREMENTAL;
  26966. }
  26967. brushIncremental(ctx, el, scope);
  26968. }
  26969. }
  26970. if (canBatchPath && isLast) {
  26971. flushPathDrawn(ctx, scope);
  26972. }
  26973. el.innerAfterBrush();
  26974. el.afterBrush && el.afterBrush();
  26975. scope.prevEl = el;
  26976. el.__dirty = 0;
  26977. el.__isRendered = true;
  26978. }
  26979. function brushIncremental(ctx, el, scope) {
  26980. var displayables = el.getDisplayables();
  26981. var temporalDisplayables = el.getTemporalDisplayables();
  26982. ctx.save();
  26983. var innerScope = {
  26984. prevElClipPaths: null,
  26985. prevEl: null,
  26986. allClipped: false,
  26987. viewWidth: scope.viewWidth,
  26988. viewHeight: scope.viewHeight,
  26989. inHover: scope.inHover
  26990. };
  26991. var i;
  26992. var len;
  26993. for (i = el.getCursor(), len = displayables.length; i < len; i++) {
  26994. var displayable = displayables[i];
  26995. displayable.beforeBrush && displayable.beforeBrush();
  26996. displayable.innerBeforeBrush();
  26997. brush(ctx, displayable, innerScope, i === len - 1);
  26998. displayable.innerAfterBrush();
  26999. displayable.afterBrush && displayable.afterBrush();
  27000. innerScope.prevEl = displayable;
  27001. }
  27002. for (var i_1 = 0, len_1 = temporalDisplayables.length; i_1 < len_1; i_1++) {
  27003. var displayable = temporalDisplayables[i_1];
  27004. displayable.beforeBrush && displayable.beforeBrush();
  27005. displayable.innerBeforeBrush();
  27006. brush(ctx, displayable, innerScope, i_1 === len_1 - 1);
  27007. displayable.innerAfterBrush();
  27008. displayable.afterBrush && displayable.afterBrush();
  27009. innerScope.prevEl = displayable;
  27010. }
  27011. el.clearTemporalDisplayables();
  27012. el.notClear = true;
  27013. ctx.restore();
  27014. }
  27015. var decalMap = new WeakMap();
  27016. var decalCache = new LRU(100);
  27017. var decalKeys = ['symbol', 'symbolSize', 'symbolKeepAspect', 'color', 'backgroundColor', 'dashArrayX', 'dashArrayY', 'maxTileWidth', 'maxTileHeight'];
  27018. /**
  27019. * Create or update pattern image from decal options
  27020. *
  27021. * @param {InnerDecalObject | 'none'} decalObject decal options, 'none' if no decal
  27022. * @return {Pattern} pattern with generated image, null if no decal
  27023. */
  27024. function createOrUpdatePatternFromDecal(decalObject, api) {
  27025. if (decalObject === 'none') {
  27026. return null;
  27027. }
  27028. var dpr = api.getDevicePixelRatio();
  27029. var zr = api.getZr();
  27030. var isSVG = zr.painter.type === 'svg';
  27031. if (decalObject.dirty) {
  27032. decalMap["delete"](decalObject);
  27033. }
  27034. var oldPattern = decalMap.get(decalObject);
  27035. if (oldPattern) {
  27036. return oldPattern;
  27037. }
  27038. var decalOpt = defaults(decalObject, {
  27039. symbol: 'rect',
  27040. symbolSize: 1,
  27041. symbolKeepAspect: true,
  27042. color: 'rgba(0, 0, 0, 0.2)',
  27043. backgroundColor: null,
  27044. dashArrayX: 5,
  27045. dashArrayY: 5,
  27046. rotation: 0,
  27047. maxTileWidth: 512,
  27048. maxTileHeight: 512
  27049. });
  27050. if (decalOpt.backgroundColor === 'none') {
  27051. decalOpt.backgroundColor = null;
  27052. }
  27053. var pattern = {
  27054. repeat: 'repeat'
  27055. };
  27056. setPatternnSource(pattern);
  27057. pattern.rotation = decalOpt.rotation;
  27058. pattern.scaleX = pattern.scaleY = isSVG ? 1 : 1 / dpr;
  27059. decalMap.set(decalObject, pattern);
  27060. decalObject.dirty = false;
  27061. return pattern;
  27062. function setPatternnSource(pattern) {
  27063. var keys = [dpr];
  27064. var isValidKey = true;
  27065. for (var i = 0; i < decalKeys.length; ++i) {
  27066. var value = decalOpt[decalKeys[i]];
  27067. if (value != null && !isArray(value) && !isString(value) && !isNumber(value) && typeof value !== 'boolean') {
  27068. isValidKey = false;
  27069. break;
  27070. }
  27071. keys.push(value);
  27072. }
  27073. var cacheKey;
  27074. if (isValidKey) {
  27075. cacheKey = keys.join(',') + (isSVG ? '-svg' : '');
  27076. var cache = decalCache.get(cacheKey);
  27077. if (cache) {
  27078. isSVG ? pattern.svgElement = cache : pattern.image = cache;
  27079. }
  27080. }
  27081. var dashArrayX = normalizeDashArrayX(decalOpt.dashArrayX);
  27082. var dashArrayY = normalizeDashArrayY(decalOpt.dashArrayY);
  27083. var symbolArray = normalizeSymbolArray(decalOpt.symbol);
  27084. var lineBlockLengthsX = getLineBlockLengthX(dashArrayX);
  27085. var lineBlockLengthY = getLineBlockLengthY(dashArrayY);
  27086. var canvas = !isSVG && platformApi.createCanvas();
  27087. var svgRoot = isSVG && {
  27088. tag: 'g',
  27089. attrs: {},
  27090. key: 'dcl',
  27091. children: []
  27092. };
  27093. var pSize = getPatternSize();
  27094. var ctx;
  27095. if (canvas) {
  27096. canvas.width = pSize.width * dpr;
  27097. canvas.height = pSize.height * dpr;
  27098. ctx = canvas.getContext('2d');
  27099. }
  27100. brushDecal();
  27101. if (isValidKey) {
  27102. decalCache.put(cacheKey, canvas || svgRoot);
  27103. }
  27104. pattern.image = canvas;
  27105. pattern.svgElement = svgRoot;
  27106. pattern.svgWidth = pSize.width;
  27107. pattern.svgHeight = pSize.height;
  27108. /**
  27109. * Get minimum length that can make a repeatable pattern.
  27110. *
  27111. * @return {Object} pattern width and height
  27112. */
  27113. function getPatternSize() {
  27114. /**
  27115. * For example, if dash is [[3, 2], [2, 1]] for X, it looks like
  27116. * |--- --- --- --- --- ...
  27117. * |-- -- -- -- -- -- -- -- ...
  27118. * |--- --- --- --- --- ...
  27119. * |-- -- -- -- -- -- -- -- ...
  27120. * So the minimum length of X is 15,
  27121. * which is the least common multiple of `3 + 2` and `2 + 1`
  27122. * |--- --- --- |--- --- ...
  27123. * |-- -- -- -- -- |-- -- -- ...
  27124. */
  27125. var width = 1;
  27126. for (var i = 0, xlen = lineBlockLengthsX.length; i < xlen; ++i) {
  27127. width = getLeastCommonMultiple(width, lineBlockLengthsX[i]);
  27128. }
  27129. var symbolRepeats = 1;
  27130. for (var i = 0, xlen = symbolArray.length; i < xlen; ++i) {
  27131. symbolRepeats = getLeastCommonMultiple(symbolRepeats, symbolArray[i].length);
  27132. }
  27133. width *= symbolRepeats;
  27134. var height = lineBlockLengthY * lineBlockLengthsX.length * symbolArray.length;
  27135. if ("development" !== 'production') {
  27136. var warn = function (attrName) {
  27137. /* eslint-disable-next-line */
  27138. console.warn("Calculated decal size is greater than " + attrName + " due to decal option settings so " + attrName + " is used for the decal size. Please consider changing the decal option to make a smaller decal or set " + attrName + " to be larger to avoid incontinuity.");
  27139. };
  27140. if (width > decalOpt.maxTileWidth) {
  27141. warn('maxTileWidth');
  27142. }
  27143. if (height > decalOpt.maxTileHeight) {
  27144. warn('maxTileHeight');
  27145. }
  27146. }
  27147. return {
  27148. width: Math.max(1, Math.min(width, decalOpt.maxTileWidth)),
  27149. height: Math.max(1, Math.min(height, decalOpt.maxTileHeight))
  27150. };
  27151. }
  27152. function brushDecal() {
  27153. if (ctx) {
  27154. ctx.clearRect(0, 0, canvas.width, canvas.height);
  27155. if (decalOpt.backgroundColor) {
  27156. ctx.fillStyle = decalOpt.backgroundColor;
  27157. ctx.fillRect(0, 0, canvas.width, canvas.height);
  27158. }
  27159. }
  27160. var ySum = 0;
  27161. for (var i = 0; i < dashArrayY.length; ++i) {
  27162. ySum += dashArrayY[i];
  27163. }
  27164. if (ySum <= 0) {
  27165. // dashArrayY is 0, draw nothing
  27166. return;
  27167. }
  27168. var y = -lineBlockLengthY;
  27169. var yId = 0;
  27170. var yIdTotal = 0;
  27171. var xId0 = 0;
  27172. while (y < pSize.height) {
  27173. if (yId % 2 === 0) {
  27174. var symbolYId = yIdTotal / 2 % symbolArray.length;
  27175. var x = 0;
  27176. var xId1 = 0;
  27177. var xId1Total = 0;
  27178. while (x < pSize.width * 2) {
  27179. var xSum = 0;
  27180. for (var i = 0; i < dashArrayX[xId0].length; ++i) {
  27181. xSum += dashArrayX[xId0][i];
  27182. }
  27183. if (xSum <= 0) {
  27184. // Skip empty line
  27185. break;
  27186. }
  27187. // E.g., [15, 5, 20, 5] draws only for 15 and 20
  27188. if (xId1 % 2 === 0) {
  27189. var size = (1 - decalOpt.symbolSize) * 0.5;
  27190. var left = x + dashArrayX[xId0][xId1] * size;
  27191. var top_1 = y + dashArrayY[yId] * size;
  27192. var width = dashArrayX[xId0][xId1] * decalOpt.symbolSize;
  27193. var height = dashArrayY[yId] * decalOpt.symbolSize;
  27194. var symbolXId = xId1Total / 2 % symbolArray[symbolYId].length;
  27195. brushSymbol(left, top_1, width, height, symbolArray[symbolYId][symbolXId]);
  27196. }
  27197. x += dashArrayX[xId0][xId1];
  27198. ++xId1Total;
  27199. ++xId1;
  27200. if (xId1 === dashArrayX[xId0].length) {
  27201. xId1 = 0;
  27202. }
  27203. }
  27204. ++xId0;
  27205. if (xId0 === dashArrayX.length) {
  27206. xId0 = 0;
  27207. }
  27208. }
  27209. y += dashArrayY[yId];
  27210. ++yIdTotal;
  27211. ++yId;
  27212. if (yId === dashArrayY.length) {
  27213. yId = 0;
  27214. }
  27215. }
  27216. function brushSymbol(x, y, width, height, symbolType) {
  27217. var scale = isSVG ? 1 : dpr;
  27218. var symbol = createSymbol(symbolType, x * scale, y * scale, width * scale, height * scale, decalOpt.color, decalOpt.symbolKeepAspect);
  27219. if (isSVG) {
  27220. var symbolVNode = zr.painter.renderOneToVNode(symbol);
  27221. if (symbolVNode) {
  27222. svgRoot.children.push(symbolVNode);
  27223. }
  27224. } else {
  27225. // Paint to canvas for all other renderers.
  27226. brushSingle(ctx, symbol);
  27227. }
  27228. }
  27229. }
  27230. }
  27231. }
  27232. /**
  27233. * Convert symbol array into normalized array
  27234. *
  27235. * @param {string | (string | string[])[]} symbol symbol input
  27236. * @return {string[][]} normolized symbol array
  27237. */
  27238. function normalizeSymbolArray(symbol) {
  27239. if (!symbol || symbol.length === 0) {
  27240. return [['rect']];
  27241. }
  27242. if (isString(symbol)) {
  27243. return [[symbol]];
  27244. }
  27245. var isAllString = true;
  27246. for (var i = 0; i < symbol.length; ++i) {
  27247. if (!isString(symbol[i])) {
  27248. isAllString = false;
  27249. break;
  27250. }
  27251. }
  27252. if (isAllString) {
  27253. return normalizeSymbolArray([symbol]);
  27254. }
  27255. var result = [];
  27256. for (var i = 0; i < symbol.length; ++i) {
  27257. if (isString(symbol[i])) {
  27258. result.push([symbol[i]]);
  27259. } else {
  27260. result.push(symbol[i]);
  27261. }
  27262. }
  27263. return result;
  27264. }
  27265. /**
  27266. * Convert dash input into dashArray
  27267. *
  27268. * @param {DecalDashArrayX} dash dash input
  27269. * @return {number[][]} normolized dash array
  27270. */
  27271. function normalizeDashArrayX(dash) {
  27272. if (!dash || dash.length === 0) {
  27273. return [[0, 0]];
  27274. }
  27275. if (isNumber(dash)) {
  27276. var dashValue = Math.ceil(dash);
  27277. return [[dashValue, dashValue]];
  27278. }
  27279. /**
  27280. * [20, 5] should be normalized into [[20, 5]],
  27281. * while [20, [5, 10]] should be normalized into [[20, 20], [5, 10]]
  27282. */
  27283. var isAllNumber = true;
  27284. for (var i = 0; i < dash.length; ++i) {
  27285. if (!isNumber(dash[i])) {
  27286. isAllNumber = false;
  27287. break;
  27288. }
  27289. }
  27290. if (isAllNumber) {
  27291. return normalizeDashArrayX([dash]);
  27292. }
  27293. var result = [];
  27294. for (var i = 0; i < dash.length; ++i) {
  27295. if (isNumber(dash[i])) {
  27296. var dashValue = Math.ceil(dash[i]);
  27297. result.push([dashValue, dashValue]);
  27298. } else {
  27299. var dashValue = map(dash[i], function (n) {
  27300. return Math.ceil(n);
  27301. });
  27302. if (dashValue.length % 2 === 1) {
  27303. // [4, 2, 1] means |---- - -- |---- - -- |
  27304. // so normalize it to be [4, 2, 1, 4, 2, 1]
  27305. result.push(dashValue.concat(dashValue));
  27306. } else {
  27307. result.push(dashValue);
  27308. }
  27309. }
  27310. }
  27311. return result;
  27312. }
  27313. /**
  27314. * Convert dash input into dashArray
  27315. *
  27316. * @param {DecalDashArrayY} dash dash input
  27317. * @return {number[]} normolized dash array
  27318. */
  27319. function normalizeDashArrayY(dash) {
  27320. if (!dash || typeof dash === 'object' && dash.length === 0) {
  27321. return [0, 0];
  27322. }
  27323. if (isNumber(dash)) {
  27324. var dashValue_1 = Math.ceil(dash);
  27325. return [dashValue_1, dashValue_1];
  27326. }
  27327. var dashValue = map(dash, function (n) {
  27328. return Math.ceil(n);
  27329. });
  27330. return dash.length % 2 ? dashValue.concat(dashValue) : dashValue;
  27331. }
  27332. /**
  27333. * Get block length of each line. A block is the length of dash line and space.
  27334. * For example, a line with [4, 1] has a dash line of 4 and a space of 1 after
  27335. * that, so the block length of this line is 5.
  27336. *
  27337. * @param {number[][]} dash dash array of X or Y
  27338. * @return {number[]} block length of each line
  27339. */
  27340. function getLineBlockLengthX(dash) {
  27341. return map(dash, function (line) {
  27342. return getLineBlockLengthY(line);
  27343. });
  27344. }
  27345. function getLineBlockLengthY(dash) {
  27346. var blockLength = 0;
  27347. for (var i = 0; i < dash.length; ++i) {
  27348. blockLength += dash[i];
  27349. }
  27350. if (dash.length % 2 === 1) {
  27351. // [4, 2, 1] means |---- - -- |---- - -- |
  27352. // So total length is (4 + 2 + 1) * 2
  27353. return blockLength * 2;
  27354. }
  27355. return blockLength;
  27356. }
  27357. function decalVisual(ecModel, api) {
  27358. ecModel.eachRawSeries(function (seriesModel) {
  27359. if (ecModel.isSeriesFiltered(seriesModel)) {
  27360. return;
  27361. }
  27362. var data = seriesModel.getData();
  27363. if (data.hasItemVisual()) {
  27364. data.each(function (idx) {
  27365. var decal = data.getItemVisual(idx, 'decal');
  27366. if (decal) {
  27367. var itemStyle = data.ensureUniqueItemVisual(idx, 'style');
  27368. itemStyle.decal = createOrUpdatePatternFromDecal(decal, api);
  27369. }
  27370. });
  27371. }
  27372. var decal = data.getVisual('decal');
  27373. if (decal) {
  27374. var style = data.getVisual('style');
  27375. style.decal = createOrUpdatePatternFromDecal(decal, api);
  27376. }
  27377. });
  27378. }
  27379. var lifecycle = new Eventful();
  27380. // Implementation of exported APIs. For example registerMap, getMap.
  27381. // The implementations will be registered when installing the component.
  27382. // Avoid these code being bundled to the core module.
  27383. var implsStore = {};
  27384. // TODO Type
  27385. function registerImpl(name, impl) {
  27386. if ("development" !== 'production') {
  27387. if (implsStore[name]) {
  27388. error("Already has an implementation of " + name + ".");
  27389. }
  27390. }
  27391. implsStore[name] = impl;
  27392. }
  27393. function getImpl(name) {
  27394. if ("development" !== 'production') {
  27395. if (!implsStore[name]) {
  27396. error("Implementation of " + name + " doesn't exists.");
  27397. }
  27398. }
  27399. return implsStore[name];
  27400. }
  27401. /*
  27402. * Licensed to the Apache Software Foundation (ASF) under one
  27403. * or more contributor license agreements. See the NOTICE file
  27404. * distributed with this work for additional information
  27405. * regarding copyright ownership. The ASF licenses this file
  27406. * to you under the Apache License, Version 2.0 (the
  27407. * "License"); you may not use this file except in compliance
  27408. * with the License. You may obtain a copy of the License at
  27409. *
  27410. * http://www.apache.org/licenses/LICENSE-2.0
  27411. *
  27412. * Unless required by applicable law or agreed to in writing,
  27413. * software distributed under the License is distributed on an
  27414. * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
  27415. * KIND, either express or implied. See the License for the
  27416. * specific language governing permissions and limitations
  27417. * under the License.
  27418. */
  27419. /**
  27420. * AUTO-GENERATED FILE. DO NOT MODIFY.
  27421. */
  27422. /*
  27423. * Licensed to the Apache Software Foundation (ASF) under one
  27424. * or more contributor license agreements. See the NOTICE file
  27425. * distributed with this work for additional information
  27426. * regarding copyright ownership. The ASF licenses this file
  27427. * to you under the Apache License, Version 2.0 (the
  27428. * "License"); you may not use this file except in compliance
  27429. * with the License. You may obtain a copy of the License at
  27430. *
  27431. * http://www.apache.org/licenses/LICENSE-2.0
  27432. *
  27433. * Unless required by applicable law or agreed to in writing,
  27434. * software distributed under the License is distributed on an
  27435. * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
  27436. * KIND, either express or implied. See the License for the
  27437. * specific language governing permissions and limitations
  27438. * under the License.
  27439. */
  27440. var customRenderers = {};
  27441. function registerCustomSeries(type, renderItem) {
  27442. customRenderers[type] = renderItem;
  27443. }
  27444. function getCustomSeries(type) {
  27445. return customRenderers[type];
  27446. }
  27447. var version$1 = '6.0.0';
  27448. var dependencies = {
  27449. zrender: '6.0.0'
  27450. };
  27451. var TEST_FRAME_REMAIN_TIME = 1;
  27452. var PRIORITY_PROCESSOR_SERIES_FILTER = 800;
  27453. // Some data processors depends on the stack result dimension (to calculate data extent).
  27454. // So data stack stage should be in front of data processing stage.
  27455. var PRIORITY_PROCESSOR_DATASTACK = 900;
  27456. // "Data filter" will block the stream, so it should be
  27457. // put at the beginning of data processing.
  27458. var PRIORITY_PROCESSOR_FILTER = 1000;
  27459. var PRIORITY_PROCESSOR_DEFAULT = 2000;
  27460. var PRIORITY_PROCESSOR_STATISTIC = 5000;
  27461. var PRIORITY_VISUAL_LAYOUT = 1000;
  27462. var PRIORITY_VISUAL_PROGRESSIVE_LAYOUT = 1100;
  27463. var PRIORITY_VISUAL_GLOBAL = 2000;
  27464. var PRIORITY_VISUAL_CHART = 3000;
  27465. var PRIORITY_VISUAL_COMPONENT = 4000;
  27466. // Visual property in data. Greater than `PRIORITY_VISUAL_COMPONENT` to enable to
  27467. // overwrite the viusal result of component (like `visualMap`)
  27468. // using data item specific setting (like itemStyle.xxx on data item)
  27469. var PRIORITY_VISUAL_CHART_DATA_CUSTOM = 4500;
  27470. // Greater than `PRIORITY_VISUAL_CHART_DATA_CUSTOM` to enable to layout based on
  27471. // visual result like `symbolSize`.
  27472. var PRIORITY_VISUAL_POST_CHART_LAYOUT = 4600;
  27473. var PRIORITY_VISUAL_BRUSH = 5000;
  27474. var PRIORITY_VISUAL_ARIA = 6000;
  27475. var PRIORITY_VISUAL_DECAL = 7000;
  27476. var PRIORITY = {
  27477. PROCESSOR: {
  27478. FILTER: PRIORITY_PROCESSOR_FILTER,
  27479. SERIES_FILTER: PRIORITY_PROCESSOR_SERIES_FILTER,
  27480. STATISTIC: PRIORITY_PROCESSOR_STATISTIC
  27481. },
  27482. VISUAL: {
  27483. LAYOUT: PRIORITY_VISUAL_LAYOUT,
  27484. PROGRESSIVE_LAYOUT: PRIORITY_VISUAL_PROGRESSIVE_LAYOUT,
  27485. GLOBAL: PRIORITY_VISUAL_GLOBAL,
  27486. CHART: PRIORITY_VISUAL_CHART,
  27487. POST_CHART_LAYOUT: PRIORITY_VISUAL_POST_CHART_LAYOUT,
  27488. COMPONENT: PRIORITY_VISUAL_COMPONENT,
  27489. BRUSH: PRIORITY_VISUAL_BRUSH,
  27490. CHART_ITEM: PRIORITY_VISUAL_CHART_DATA_CUSTOM,
  27491. ARIA: PRIORITY_VISUAL_ARIA,
  27492. DECAL: PRIORITY_VISUAL_DECAL
  27493. }
  27494. };
  27495. // Main process have three entries: `setOption`, `dispatchAction` and `resize`,
  27496. // where they must not be invoked nestedly, except the only case: invoke
  27497. // dispatchAction with updateMethod "none" in main process.
  27498. // This flag is used to carry out this rule.
  27499. // All events will be triggered out side main process (i.e. when !this[IN_MAIN_PROCESS]).
  27500. var IN_MAIN_PROCESS_KEY = '__flagInMainProcess';
  27501. // Useful for detecting outdated rendering results in scenarios that these issues are involved:
  27502. // - Use shortcut (such as, updateTransform, or no update) to start a main process.
  27503. // - Asynchronously update rendered view (e.g., graph force layout).
  27504. // - Multiple ChartView/ComponentView render to one group cooperatively.
  27505. var MAIN_PROCESS_VERSION_KEY = '__mainProcessVersion';
  27506. var PENDING_UPDATE = '__pendingUpdate';
  27507. var STATUS_NEEDS_UPDATE_KEY = '__needsUpdateStatus';
  27508. var ACTION_REG = /^[a-zA-Z0-9_]+$/;
  27509. var CONNECT_STATUS_KEY = '__connectUpdateStatus';
  27510. var CONNECT_STATUS_PENDING = 0;
  27511. var CONNECT_STATUS_UPDATING = 1;
  27512. var CONNECT_STATUS_UPDATED = 2;
  27513. function createRegisterEventWithLowercaseECharts(method) {
  27514. return function () {
  27515. var args = [];
  27516. for (var _i = 0; _i < arguments.length; _i++) {
  27517. args[_i] = arguments[_i];
  27518. }
  27519. if (this.isDisposed()) {
  27520. disposedWarning(this.id);
  27521. return;
  27522. }
  27523. return toLowercaseNameAndCallEventful(this, method, args);
  27524. };
  27525. }
  27526. function createRegisterEventWithLowercaseMessageCenter(method) {
  27527. return function () {
  27528. var args = [];
  27529. for (var _i = 0; _i < arguments.length; _i++) {
  27530. args[_i] = arguments[_i];
  27531. }
  27532. return toLowercaseNameAndCallEventful(this, method, args);
  27533. };
  27534. }
  27535. function toLowercaseNameAndCallEventful(host, method, args) {
  27536. // `args[0]` is event name. Event name is all lowercase.
  27537. args[0] = args[0] && args[0].toLowerCase();
  27538. return Eventful.prototype[method].apply(host, args);
  27539. }
  27540. var MessageCenter = /** @class */function (_super) {
  27541. __extends(MessageCenter, _super);
  27542. function MessageCenter() {
  27543. return _super !== null && _super.apply(this, arguments) || this;
  27544. }
  27545. return MessageCenter;
  27546. }(Eventful);
  27547. var messageCenterProto = MessageCenter.prototype;
  27548. messageCenterProto.on = createRegisterEventWithLowercaseMessageCenter('on');
  27549. messageCenterProto.off = createRegisterEventWithLowercaseMessageCenter('off');
  27550. // ---------------------------------------
  27551. // Internal method names for class ECharts
  27552. // ---------------------------------------
  27553. var prepare;
  27554. var prepareView;
  27555. var updateDirectly;
  27556. var updateMethods;
  27557. var doConvertPixel;
  27558. var updateStreamModes;
  27559. var doDispatchAction;
  27560. var flushPendingActions;
  27561. var triggerUpdatedEvent;
  27562. var bindRenderedEvent;
  27563. var bindMouseEvent;
  27564. var render;
  27565. var renderComponents;
  27566. var renderSeries;
  27567. var createExtensionAPI;
  27568. var enableConnect;
  27569. var markStatusToUpdate;
  27570. var applyChangedStates;
  27571. var updateMainProcessVersion;
  27572. var ECharts = /** @class */function (_super) {
  27573. __extends(ECharts, _super);
  27574. function ECharts(dom,
  27575. // Theme name or themeOption.
  27576. theme, opts) {
  27577. var _this = _super.call(this, new ECEventProcessor()) || this;
  27578. _this._chartsViews = [];
  27579. _this._chartsMap = {};
  27580. _this._componentsViews = [];
  27581. _this._componentsMap = {};
  27582. // Can't dispatch action during rendering procedure
  27583. _this._pendingActions = [];
  27584. opts = opts || {};
  27585. _this._dom = dom;
  27586. var defaultRenderer = 'canvas';
  27587. var defaultCoarsePointer = 'auto';
  27588. var defaultUseDirtyRect = false;
  27589. _this[MAIN_PROCESS_VERSION_KEY] = 1;
  27590. if ("development" !== 'production') {
  27591. var root = /* eslint-disable-next-line */
  27592. env.hasGlobalWindow ? window : global;
  27593. if (root) {
  27594. defaultRenderer = retrieve2(root.__ECHARTS__DEFAULT__RENDERER__, defaultRenderer);
  27595. defaultCoarsePointer = retrieve2(root.__ECHARTS__DEFAULT__COARSE_POINTER, defaultCoarsePointer);
  27596. defaultUseDirtyRect = retrieve2(root.__ECHARTS__DEFAULT__USE_DIRTY_RECT__, defaultUseDirtyRect);
  27597. }
  27598. }
  27599. if (opts.ssr) {
  27600. registerSSRDataGetter(function (el) {
  27601. var ecData = getECData(el);
  27602. var dataIndex = ecData.dataIndex;
  27603. if (dataIndex == null) {
  27604. return;
  27605. }
  27606. var hashMap = createHashMap();
  27607. hashMap.set('series_index', ecData.seriesIndex);
  27608. hashMap.set('data_index', dataIndex);
  27609. ecData.ssrType && hashMap.set('ssr_type', ecData.ssrType);
  27610. return hashMap;
  27611. });
  27612. }
  27613. var zr = _this._zr = init(dom, {
  27614. renderer: opts.renderer || defaultRenderer,
  27615. devicePixelRatio: opts.devicePixelRatio,
  27616. width: opts.width,
  27617. height: opts.height,
  27618. ssr: opts.ssr,
  27619. useDirtyRect: retrieve2(opts.useDirtyRect, defaultUseDirtyRect),
  27620. useCoarsePointer: retrieve2(opts.useCoarsePointer, defaultCoarsePointer),
  27621. pointerSize: opts.pointerSize
  27622. });
  27623. _this._ssr = opts.ssr;
  27624. // Expect 60 fps.
  27625. _this._throttledZrFlush = throttle(bind(zr.flush, zr), 17);
  27626. _this._updateTheme(theme);
  27627. _this._locale = createLocaleObject(opts.locale || SYSTEM_LANG);
  27628. _this._coordSysMgr = new CoordinateSystemManager();
  27629. var api = _this._api = createExtensionAPI(_this);
  27630. // Sort on demand
  27631. function prioritySortFunc(a, b) {
  27632. return a.__prio - b.__prio;
  27633. }
  27634. sort(visualFuncs, prioritySortFunc);
  27635. sort(dataProcessorFuncs, prioritySortFunc);
  27636. _this._scheduler = new Scheduler(_this, api, dataProcessorFuncs, visualFuncs);
  27637. _this._messageCenter = new MessageCenter();
  27638. // Init mouse events
  27639. _this._initEvents();
  27640. // In case some people write `window.onresize = chart.resize`
  27641. _this.resize = bind(_this.resize, _this);
  27642. zr.animation.on('frame', _this._onframe, _this);
  27643. bindRenderedEvent(zr, _this);
  27644. bindMouseEvent(zr, _this);
  27645. // ECharts instance can be used as value.
  27646. setAsPrimitive(_this);
  27647. return _this;
  27648. }
  27649. ECharts.prototype._onframe = function () {
  27650. if (this._disposed) {
  27651. return;
  27652. }
  27653. applyChangedStates(this);
  27654. var scheduler = this._scheduler;
  27655. // Lazy update
  27656. if (this[PENDING_UPDATE]) {
  27657. var silent = this[PENDING_UPDATE].silent;
  27658. this[IN_MAIN_PROCESS_KEY] = true;
  27659. updateMainProcessVersion(this);
  27660. try {
  27661. prepare(this);
  27662. updateMethods.update.call(this, null, this[PENDING_UPDATE].updateParams);
  27663. } catch (e) {
  27664. this[IN_MAIN_PROCESS_KEY] = false;
  27665. this[PENDING_UPDATE] = null;
  27666. throw e;
  27667. }
  27668. // At present, in each frame, zrender performs:
  27669. // (1) animation step forward.
  27670. // (2) trigger('frame') (where this `_onframe` is called)
  27671. // (3) zrender flush (render).
  27672. // If we do nothing here, since we use `setToFinal: true`, the step (3) above
  27673. // will render the final state of the elements before the real animation started.
  27674. this._zr.flush();
  27675. this[IN_MAIN_PROCESS_KEY] = false;
  27676. this[PENDING_UPDATE] = null;
  27677. flushPendingActions.call(this, silent);
  27678. triggerUpdatedEvent.call(this, silent);
  27679. }
  27680. // Avoid do both lazy update and progress in one frame.
  27681. else if (scheduler.unfinished) {
  27682. // Stream progress.
  27683. var remainTime = TEST_FRAME_REMAIN_TIME;
  27684. var ecModel = this._model;
  27685. var api = this._api;
  27686. scheduler.unfinished = false;
  27687. do {
  27688. var startTime = +new Date();
  27689. scheduler.performSeriesTasks(ecModel);
  27690. // Currently dataProcessorFuncs do not check threshold.
  27691. scheduler.performDataProcessorTasks(ecModel);
  27692. updateStreamModes(this, ecModel);
  27693. // Do not update coordinate system here. Because that coord system update in
  27694. // each frame is not a good user experience. So we follow the rule that
  27695. // the extent of the coordinate system is determined in the first frame (the
  27696. // frame is executed immediately after task reset.
  27697. // this._coordSysMgr.update(ecModel, api);
  27698. // console.log('--- ec frame visual ---', remainTime);
  27699. scheduler.performVisualTasks(ecModel);
  27700. renderSeries(this, this._model, api, 'remain', {});
  27701. remainTime -= +new Date() - startTime;
  27702. } while (remainTime > 0 && scheduler.unfinished);
  27703. // Call flush explicitly for trigger finished event.
  27704. if (!scheduler.unfinished) {
  27705. this._zr.flush();
  27706. }
  27707. // Else, zr flushing be ensue within the same frame,
  27708. // because zr flushing is after onframe event.
  27709. }
  27710. };
  27711. ECharts.prototype.getDom = function () {
  27712. return this._dom;
  27713. };
  27714. ECharts.prototype.getId = function () {
  27715. return this.id;
  27716. };
  27717. ECharts.prototype.getZr = function () {
  27718. return this._zr;
  27719. };
  27720. ECharts.prototype.isSSR = function () {
  27721. return this._ssr;
  27722. };
  27723. /* eslint-disable-next-line */
  27724. ECharts.prototype.setOption = function (option, notMerge, lazyUpdate) {
  27725. if (this[IN_MAIN_PROCESS_KEY]) {
  27726. if ("development" !== 'production') {
  27727. error('`setOption` should not be called during main process.');
  27728. }
  27729. return;
  27730. }
  27731. if (this._disposed) {
  27732. disposedWarning(this.id);
  27733. return;
  27734. }
  27735. var silent;
  27736. var replaceMerge;
  27737. var transitionOpt;
  27738. if (isObject(notMerge)) {
  27739. lazyUpdate = notMerge.lazyUpdate;
  27740. silent = notMerge.silent;
  27741. replaceMerge = notMerge.replaceMerge;
  27742. transitionOpt = notMerge.transition;
  27743. notMerge = notMerge.notMerge;
  27744. }
  27745. this[IN_MAIN_PROCESS_KEY] = true;
  27746. updateMainProcessVersion(this);
  27747. if (!this._model || notMerge) {
  27748. var optionManager = new OptionManager(this._api);
  27749. var theme = this._theme;
  27750. var ecModel = this._model = new GlobalModel();
  27751. ecModel.scheduler = this._scheduler;
  27752. ecModel.ssr = this._ssr;
  27753. ecModel.init(null, null, null, theme, this._locale, optionManager);
  27754. }
  27755. this._model.setOption(option, {
  27756. replaceMerge: replaceMerge
  27757. }, optionPreprocessorFuncs);
  27758. var updateParams = {
  27759. seriesTransition: transitionOpt,
  27760. optionChanged: true
  27761. };
  27762. if (lazyUpdate) {
  27763. this[PENDING_UPDATE] = {
  27764. silent: silent,
  27765. updateParams: updateParams
  27766. };
  27767. this[IN_MAIN_PROCESS_KEY] = false;
  27768. // `setOption(option, {lazyMode: true})` may be called when zrender has been slept.
  27769. // It should wake it up to make sure zrender start to render at the next frame.
  27770. this.getZr().wakeUp();
  27771. } else {
  27772. try {
  27773. prepare(this);
  27774. updateMethods.update.call(this, null, updateParams);
  27775. } catch (e) {
  27776. this[PENDING_UPDATE] = null;
  27777. this[IN_MAIN_PROCESS_KEY] = false;
  27778. throw e;
  27779. }
  27780. // Ensure zr refresh sychronously, and then pixel in canvas can be
  27781. // fetched after `setOption`.
  27782. if (!this._ssr) {
  27783. // not use flush when using ssr mode.
  27784. this._zr.flush();
  27785. }
  27786. this[PENDING_UPDATE] = null;
  27787. this[IN_MAIN_PROCESS_KEY] = false;
  27788. flushPendingActions.call(this, silent);
  27789. triggerUpdatedEvent.call(this, silent);
  27790. }
  27791. };
  27792. /**
  27793. * Update theme with name or theme option and repaint the chart.
  27794. * @param theme Theme name or theme option.
  27795. * @param opts Optional settings
  27796. */
  27797. ECharts.prototype.setTheme = function (theme, opts) {
  27798. if (this[IN_MAIN_PROCESS_KEY]) {
  27799. if ("development" !== 'production') {
  27800. error('`setTheme` should not be called during main process.');
  27801. }
  27802. return;
  27803. }
  27804. if (this._disposed) {
  27805. disposedWarning(this.id);
  27806. return;
  27807. }
  27808. var ecModel = this._model;
  27809. if (!ecModel) {
  27810. return;
  27811. }
  27812. var silent = opts && opts.silent;
  27813. var updateParams = null;
  27814. if (this[PENDING_UPDATE]) {
  27815. if (silent == null) {
  27816. silent = this[PENDING_UPDATE].silent;
  27817. }
  27818. updateParams = this[PENDING_UPDATE].updateParams;
  27819. this[PENDING_UPDATE] = null;
  27820. }
  27821. this[IN_MAIN_PROCESS_KEY] = true;
  27822. updateMainProcessVersion(this);
  27823. try {
  27824. this._updateTheme(theme);
  27825. ecModel.setTheme(this._theme);
  27826. prepare(this);
  27827. updateMethods.update.call(this, {
  27828. type: 'setTheme'
  27829. }, updateParams);
  27830. } catch (e) {
  27831. this[IN_MAIN_PROCESS_KEY] = false;
  27832. throw e;
  27833. }
  27834. this[IN_MAIN_PROCESS_KEY] = false;
  27835. flushPendingActions.call(this, silent);
  27836. triggerUpdatedEvent.call(this, silent);
  27837. };
  27838. ECharts.prototype._updateTheme = function (theme) {
  27839. if (isString(theme)) {
  27840. theme = themeStorage[theme];
  27841. }
  27842. if (theme) {
  27843. theme = clone(theme);
  27844. theme && globalBackwardCompat(theme, true);
  27845. this._theme = theme;
  27846. }
  27847. };
  27848. // We don't want developers to use getModel directly.
  27849. ECharts.prototype.getModel = function () {
  27850. return this._model;
  27851. };
  27852. ECharts.prototype.getOption = function () {
  27853. return this._model && this._model.getOption();
  27854. };
  27855. ECharts.prototype.getWidth = function () {
  27856. return this._zr.getWidth();
  27857. };
  27858. ECharts.prototype.getHeight = function () {
  27859. return this._zr.getHeight();
  27860. };
  27861. ECharts.prototype.getDevicePixelRatio = function () {
  27862. return this._zr.painter.dpr
  27863. /* eslint-disable-next-line */ || env.hasGlobalWindow && window.devicePixelRatio || 1;
  27864. };
  27865. /**
  27866. * Get canvas which has all thing rendered
  27867. * @deprecated Use renderToCanvas instead.
  27868. */
  27869. ECharts.prototype.getRenderedCanvas = function (opts) {
  27870. if ("development" !== 'production') {
  27871. deprecateReplaceLog('getRenderedCanvas', 'renderToCanvas');
  27872. }
  27873. return this.renderToCanvas(opts);
  27874. };
  27875. ECharts.prototype.renderToCanvas = function (opts) {
  27876. opts = opts || {};
  27877. var painter = this._zr.painter;
  27878. if ("development" !== 'production') {
  27879. if (painter.type !== 'canvas') {
  27880. throw new Error('renderToCanvas can only be used in the canvas renderer.');
  27881. }
  27882. }
  27883. return painter.getRenderedCanvas({
  27884. backgroundColor: opts.backgroundColor || this._model.get('backgroundColor'),
  27885. pixelRatio: opts.pixelRatio || this.getDevicePixelRatio()
  27886. });
  27887. };
  27888. ECharts.prototype.renderToSVGString = function (opts) {
  27889. opts = opts || {};
  27890. var painter = this._zr.painter;
  27891. if ("development" !== 'production') {
  27892. if (painter.type !== 'svg') {
  27893. throw new Error('renderToSVGString can only be used in the svg renderer.');
  27894. }
  27895. }
  27896. return painter.renderToString({
  27897. useViewBox: opts.useViewBox
  27898. });
  27899. };
  27900. /**
  27901. * Get svg data url
  27902. */
  27903. ECharts.prototype.getSvgDataURL = function () {
  27904. var zr = this._zr;
  27905. var list = zr.storage.getDisplayList();
  27906. // Stop animations
  27907. each(list, function (el) {
  27908. el.stopAnimation(null, true);
  27909. });
  27910. return zr.painter.toDataURL();
  27911. };
  27912. ECharts.prototype.getDataURL = function (opts) {
  27913. if (this._disposed) {
  27914. disposedWarning(this.id);
  27915. return;
  27916. }
  27917. opts = opts || {};
  27918. var excludeComponents = opts.excludeComponents;
  27919. var ecModel = this._model;
  27920. var excludesComponentViews = [];
  27921. var self = this;
  27922. each(excludeComponents, function (componentType) {
  27923. ecModel.eachComponent({
  27924. mainType: componentType
  27925. }, function (component) {
  27926. var view = self._componentsMap[component.__viewId];
  27927. if (!view.group.ignore) {
  27928. excludesComponentViews.push(view);
  27929. view.group.ignore = true;
  27930. }
  27931. });
  27932. });
  27933. var url = this._zr.painter.getType() === 'svg' ? this.getSvgDataURL() : this.renderToCanvas(opts).toDataURL('image/' + (opts && opts.type || 'png'));
  27934. each(excludesComponentViews, function (view) {
  27935. view.group.ignore = false;
  27936. });
  27937. return url;
  27938. };
  27939. ECharts.prototype.getConnectedDataURL = function (opts) {
  27940. if (this._disposed) {
  27941. disposedWarning(this.id);
  27942. return;
  27943. }
  27944. var isSvg = opts.type === 'svg';
  27945. var groupId = this.group;
  27946. var mathMin = Math.min;
  27947. var mathMax = Math.max;
  27948. var MAX_NUMBER = Infinity;
  27949. if (connectedGroups[groupId]) {
  27950. var left_1 = MAX_NUMBER;
  27951. var top_1 = MAX_NUMBER;
  27952. var right_1 = -MAX_NUMBER;
  27953. var bottom_1 = -MAX_NUMBER;
  27954. var canvasList_1 = [];
  27955. var dpr_1 = opts && opts.pixelRatio || this.getDevicePixelRatio();
  27956. each(instances$1, function (chart, id) {
  27957. if (chart.group === groupId) {
  27958. var canvas = isSvg ? chart.getZr().painter.getSvgDom().innerHTML : chart.renderToCanvas(clone(opts));
  27959. var boundingRect = chart.getDom().getBoundingClientRect();
  27960. left_1 = mathMin(boundingRect.left, left_1);
  27961. top_1 = mathMin(boundingRect.top, top_1);
  27962. right_1 = mathMax(boundingRect.right, right_1);
  27963. bottom_1 = mathMax(boundingRect.bottom, bottom_1);
  27964. canvasList_1.push({
  27965. dom: canvas,
  27966. left: boundingRect.left,
  27967. top: boundingRect.top
  27968. });
  27969. }
  27970. });
  27971. left_1 *= dpr_1;
  27972. top_1 *= dpr_1;
  27973. right_1 *= dpr_1;
  27974. bottom_1 *= dpr_1;
  27975. var width = right_1 - left_1;
  27976. var height = bottom_1 - top_1;
  27977. var targetCanvas = platformApi.createCanvas();
  27978. var zr_1 = init(targetCanvas, {
  27979. renderer: isSvg ? 'svg' : 'canvas'
  27980. });
  27981. zr_1.resize({
  27982. width: width,
  27983. height: height
  27984. });
  27985. if (isSvg) {
  27986. var content_1 = '';
  27987. each(canvasList_1, function (item) {
  27988. var x = item.left - left_1;
  27989. var y = item.top - top_1;
  27990. content_1 += '<g transform="translate(' + x + ',' + y + ')">' + item.dom + '</g>';
  27991. });
  27992. zr_1.painter.getSvgRoot().innerHTML = content_1;
  27993. if (opts.connectedBackgroundColor) {
  27994. zr_1.painter.setBackgroundColor(opts.connectedBackgroundColor);
  27995. }
  27996. zr_1.refreshImmediately();
  27997. return zr_1.painter.toDataURL();
  27998. } else {
  27999. // Background between the charts
  28000. if (opts.connectedBackgroundColor) {
  28001. zr_1.add(new Rect({
  28002. shape: {
  28003. x: 0,
  28004. y: 0,
  28005. width: width,
  28006. height: height
  28007. },
  28008. style: {
  28009. fill: opts.connectedBackgroundColor
  28010. }
  28011. }));
  28012. }
  28013. each(canvasList_1, function (item) {
  28014. var img = new ZRImage({
  28015. style: {
  28016. x: item.left * dpr_1 - left_1,
  28017. y: item.top * dpr_1 - top_1,
  28018. image: item.dom
  28019. }
  28020. });
  28021. zr_1.add(img);
  28022. });
  28023. zr_1.refreshImmediately();
  28024. return targetCanvas.toDataURL('image/' + (opts && opts.type || 'png'));
  28025. }
  28026. } else {
  28027. return this.getDataURL(opts);
  28028. }
  28029. };
  28030. ECharts.prototype.convertToPixel = function (finder, value, opt) {
  28031. return doConvertPixel(this, 'convertToPixel', finder, value, opt);
  28032. };
  28033. /**
  28034. * Convert from logical coordinate system to pixel coordinate system.
  28035. * See CoordinateSystem#convertToPixel.
  28036. *
  28037. * @see CoordinateSystem['dataToLayout'] for parameters and return.
  28038. * @see CoordinateSystemDataCoord
  28039. */
  28040. ECharts.prototype.convertToLayout = function (finder, value, opt) {
  28041. return doConvertPixel(this, 'convertToLayout', finder, value, opt);
  28042. };
  28043. // The above are signatures from before v6, thus they should be preserved for backward compat.
  28044. ECharts.prototype.convertFromPixel = function (finder, value, opt) {
  28045. return doConvertPixel(this, 'convertFromPixel', finder, value, opt);
  28046. };
  28047. /**
  28048. * Is the specified coordinate systems or components contain the given pixel point.
  28049. * @param {Array|number} value
  28050. * @return {boolean} result
  28051. */
  28052. ECharts.prototype.containPixel = function (finder, value) {
  28053. if (this._disposed) {
  28054. disposedWarning(this.id);
  28055. return;
  28056. }
  28057. var ecModel = this._model;
  28058. var result;
  28059. var findResult = parseFinder(ecModel, finder);
  28060. each(findResult, function (models, key) {
  28061. key.indexOf('Models') >= 0 && each(models, function (model) {
  28062. var coordSys = model.coordinateSystem;
  28063. if (coordSys && coordSys.containPoint) {
  28064. result = result || !!coordSys.containPoint(value);
  28065. } else if (key === 'seriesModels') {
  28066. var view = this._chartsMap[model.__viewId];
  28067. if (view && view.containPoint) {
  28068. result = result || view.containPoint(value, model);
  28069. } else {
  28070. if ("development" !== 'production') {
  28071. warn(key + ': ' + (view ? 'The found component do not support containPoint.' : 'No view mapping to the found component.'));
  28072. }
  28073. }
  28074. } else {
  28075. if ("development" !== 'production') {
  28076. warn(key + ': containPoint is not supported');
  28077. }
  28078. }
  28079. }, this);
  28080. }, this);
  28081. return !!result;
  28082. };
  28083. /**
  28084. * Get visual from series or data.
  28085. * @param finder
  28086. * If string, e.g., 'series', means {seriesIndex: 0}.
  28087. * If Object, could contain some of these properties below:
  28088. * {
  28089. * seriesIndex / seriesId / seriesName,
  28090. * dataIndex / dataIndexInside
  28091. * }
  28092. * If dataIndex is not specified, series visual will be fetched,
  28093. * but not data item visual.
  28094. * If all of seriesIndex, seriesId, seriesName are not specified,
  28095. * visual will be fetched from first series.
  28096. * @param visualType 'color', 'symbol', 'symbolSize'
  28097. */
  28098. ECharts.prototype.getVisual = function (finder, visualType) {
  28099. var ecModel = this._model;
  28100. var parsedFinder = parseFinder(ecModel, finder, {
  28101. defaultMainType: 'series'
  28102. });
  28103. var seriesModel = parsedFinder.seriesModel;
  28104. if ("development" !== 'production') {
  28105. if (!seriesModel) {
  28106. warn('There is no specified series model');
  28107. }
  28108. }
  28109. var data = seriesModel.getData();
  28110. var dataIndexInside = parsedFinder.hasOwnProperty('dataIndexInside') ? parsedFinder.dataIndexInside : parsedFinder.hasOwnProperty('dataIndex') ? data.indexOfRawIndex(parsedFinder.dataIndex) : null;
  28111. return dataIndexInside != null ? getItemVisualFromData(data, dataIndexInside, visualType) : getVisualFromData(data, visualType);
  28112. };
  28113. /**
  28114. * Get view of corresponding component model
  28115. */
  28116. ECharts.prototype.getViewOfComponentModel = function (componentModel) {
  28117. return this._componentsMap[componentModel.__viewId];
  28118. };
  28119. /**
  28120. * Get view of corresponding series model
  28121. */
  28122. ECharts.prototype.getViewOfSeriesModel = function (seriesModel) {
  28123. return this._chartsMap[seriesModel.__viewId];
  28124. };
  28125. ECharts.prototype._initEvents = function () {
  28126. var _this = this;
  28127. each(MOUSE_EVENT_NAMES, function (eveName) {
  28128. var handler = function (e) {
  28129. var ecModel = _this.getModel();
  28130. var el = e.target;
  28131. var params;
  28132. var isGlobalOut = eveName === 'globalout';
  28133. // no e.target when 'globalout'.
  28134. if (isGlobalOut) {
  28135. params = {};
  28136. } else {
  28137. el && findEventDispatcher(el, function (parent) {
  28138. var ecData = getECData(parent);
  28139. if (ecData && ecData.dataIndex != null) {
  28140. var dataModel = ecData.dataModel || ecModel.getSeriesByIndex(ecData.seriesIndex);
  28141. params = dataModel && dataModel.getDataParams(ecData.dataIndex, ecData.dataType, el) || {};
  28142. return true;
  28143. }
  28144. // If element has custom eventData of components
  28145. else if (ecData.eventData) {
  28146. params = extend({}, ecData.eventData);
  28147. return true;
  28148. }
  28149. }, true);
  28150. }
  28151. // Contract: if params prepared in mouse event,
  28152. // these properties must be specified:
  28153. // {
  28154. // componentType: string (component main type)
  28155. // componentIndex: number
  28156. // }
  28157. // Otherwise event query can not work.
  28158. if (params) {
  28159. var componentType = params.componentType;
  28160. var componentIndex = params.componentIndex;
  28161. // Special handling for historic reason: when trigger by
  28162. // markLine/markPoint/markArea, the componentType is
  28163. // 'markLine'/'markPoint'/'markArea', but we should better
  28164. // enable them to be queried by seriesIndex, since their
  28165. // option is set in each series.
  28166. if (componentType === 'markLine' || componentType === 'markPoint' || componentType === 'markArea') {
  28167. componentType = 'series';
  28168. componentIndex = params.seriesIndex;
  28169. }
  28170. var model = componentType && componentIndex != null && ecModel.getComponent(componentType, componentIndex);
  28171. var view = model && _this[model.mainType === 'series' ? '_chartsMap' : '_componentsMap'][model.__viewId];
  28172. if ("development" !== 'production') {
  28173. // `event.componentType` and `event[componentTpype + 'Index']` must not
  28174. // be missed, otherwise there is no way to distinguish source component.
  28175. // See `dataFormat.getDataParams`.
  28176. if (!isGlobalOut && !(model && view)) {
  28177. warn('model or view can not be found by params');
  28178. }
  28179. }
  28180. params.event = e;
  28181. params.type = eveName;
  28182. _this._$eventProcessor.eventInfo = {
  28183. targetEl: el,
  28184. packedEvent: params,
  28185. model: model,
  28186. view: view
  28187. };
  28188. _this.trigger(eveName, params);
  28189. }
  28190. };
  28191. // Consider that some component (like tooltip, brush, ...)
  28192. // register zr event handler, but user event handler might
  28193. // do anything, such as call `setOption` or `dispatchAction`,
  28194. // which probably update any of the content and probably
  28195. // cause problem if it is called previous other inner handlers.
  28196. handler.zrEventfulCallAtLast = true;
  28197. _this._zr.on(eveName, handler, _this);
  28198. });
  28199. var messageCenter = this._messageCenter;
  28200. each(publicEventTypeMap, function (_, eventType) {
  28201. messageCenter.on(eventType, function (event) {
  28202. _this.trigger(eventType, event);
  28203. });
  28204. });
  28205. handleLegacySelectEvents(messageCenter, this, this._api);
  28206. };
  28207. ECharts.prototype.isDisposed = function () {
  28208. return this._disposed;
  28209. };
  28210. ECharts.prototype.clear = function () {
  28211. if (this._disposed) {
  28212. disposedWarning(this.id);
  28213. return;
  28214. }
  28215. this.setOption({
  28216. series: []
  28217. }, true);
  28218. };
  28219. ECharts.prototype.dispose = function () {
  28220. if (this._disposed) {
  28221. disposedWarning(this.id);
  28222. return;
  28223. }
  28224. this._disposed = true;
  28225. var dom = this.getDom();
  28226. if (dom) {
  28227. setAttribute(this.getDom(), DOM_ATTRIBUTE_KEY, '');
  28228. }
  28229. var chart = this;
  28230. var api = chart._api;
  28231. var ecModel = chart._model;
  28232. each(chart._componentsViews, function (component) {
  28233. component.dispose(ecModel, api);
  28234. });
  28235. each(chart._chartsViews, function (chart) {
  28236. chart.dispose(ecModel, api);
  28237. });
  28238. // Dispose after all views disposed
  28239. chart._zr.dispose();
  28240. // Set properties to null.
  28241. // To reduce the memory cost in case the top code still holds this instance unexpectedly.
  28242. chart._dom = chart._model = chart._chartsMap = chart._componentsMap = chart._chartsViews = chart._componentsViews = chart._scheduler = chart._api = chart._zr = chart._throttledZrFlush = chart._theme = chart._coordSysMgr = chart._messageCenter = null;
  28243. delete instances$1[chart.id];
  28244. };
  28245. /**
  28246. * Resize the chart
  28247. */
  28248. ECharts.prototype.resize = function (opts) {
  28249. if (this[IN_MAIN_PROCESS_KEY]) {
  28250. if ("development" !== 'production') {
  28251. error('`resize` should not be called during main process.');
  28252. }
  28253. return;
  28254. }
  28255. if (this._disposed) {
  28256. disposedWarning(this.id);
  28257. return;
  28258. }
  28259. this._zr.resize(opts);
  28260. var ecModel = this._model;
  28261. // Resize loading effect
  28262. this._loadingFX && this._loadingFX.resize();
  28263. if (!ecModel) {
  28264. return;
  28265. }
  28266. var needPrepare = ecModel.resetOption('media');
  28267. var silent = opts && opts.silent;
  28268. // There is some real cases that:
  28269. // chart.setOption(option, { lazyUpdate: true });
  28270. // chart.resize();
  28271. if (this[PENDING_UPDATE]) {
  28272. if (silent == null) {
  28273. silent = this[PENDING_UPDATE].silent;
  28274. }
  28275. needPrepare = true;
  28276. this[PENDING_UPDATE] = null;
  28277. }
  28278. this[IN_MAIN_PROCESS_KEY] = true;
  28279. updateMainProcessVersion(this);
  28280. try {
  28281. needPrepare && prepare(this);
  28282. updateMethods.update.call(this, {
  28283. type: 'resize',
  28284. animation: extend({
  28285. // Disable animation
  28286. duration: 0
  28287. }, opts && opts.animation)
  28288. });
  28289. } catch (e) {
  28290. this[IN_MAIN_PROCESS_KEY] = false;
  28291. throw e;
  28292. }
  28293. this[IN_MAIN_PROCESS_KEY] = false;
  28294. flushPendingActions.call(this, silent);
  28295. triggerUpdatedEvent.call(this, silent);
  28296. };
  28297. ECharts.prototype.showLoading = function (name, cfg) {
  28298. if (this._disposed) {
  28299. disposedWarning(this.id);
  28300. return;
  28301. }
  28302. if (isObject(name)) {
  28303. cfg = name;
  28304. name = '';
  28305. }
  28306. name = name || 'default';
  28307. this.hideLoading();
  28308. if (!loadingEffects[name]) {
  28309. if ("development" !== 'production') {
  28310. warn('Loading effects ' + name + ' not exists.');
  28311. }
  28312. return;
  28313. }
  28314. var el = loadingEffects[name](this._api, cfg);
  28315. var zr = this._zr;
  28316. this._loadingFX = el;
  28317. zr.add(el);
  28318. };
  28319. /**
  28320. * Hide loading effect
  28321. */
  28322. ECharts.prototype.hideLoading = function () {
  28323. if (this._disposed) {
  28324. disposedWarning(this.id);
  28325. return;
  28326. }
  28327. this._loadingFX && this._zr.remove(this._loadingFX);
  28328. this._loadingFX = null;
  28329. };
  28330. ECharts.prototype.makeActionFromEvent = function (eventObj) {
  28331. var payload = extend({}, eventObj);
  28332. payload.type = connectionEventRevertMap[eventObj.type];
  28333. return payload;
  28334. };
  28335. /**
  28336. * @param opt If pass boolean, means opt.silent
  28337. * @param opt.silent Default `false`. Whether trigger events.
  28338. * @param opt.flush Default `undefined`.
  28339. * true: Flush immediately, and then pixel in canvas can be fetched
  28340. * immediately. Caution: it might affect performance.
  28341. * false: Not flush.
  28342. * undefined: Auto decide whether perform flush.
  28343. */
  28344. ECharts.prototype.dispatchAction = function (payload, opt) {
  28345. if (this._disposed) {
  28346. disposedWarning(this.id);
  28347. return;
  28348. }
  28349. if (!isObject(opt)) {
  28350. opt = {
  28351. silent: !!opt
  28352. };
  28353. }
  28354. if (!actions[payload.type]) {
  28355. return;
  28356. }
  28357. // Avoid dispatch action before setOption. Especially in `connect`.
  28358. if (!this._model) {
  28359. return;
  28360. }
  28361. // May dispatchAction in rendering procedure
  28362. if (this[IN_MAIN_PROCESS_KEY]) {
  28363. this._pendingActions.push(payload);
  28364. return;
  28365. }
  28366. var silent = opt.silent;
  28367. doDispatchAction.call(this, payload, silent);
  28368. var flush = opt.flush;
  28369. if (flush) {
  28370. this._zr.flush();
  28371. } else if (flush !== false && env.browser.weChat) {
  28372. // In WeChat embedded browser, `requestAnimationFrame` and `setInterval`
  28373. // hang when sliding page (on touch event), which cause that zr does not
  28374. // refresh until user interaction finished, which is not expected.
  28375. // But `dispatchAction` may be called too frequently when pan on touch
  28376. // screen, which impacts performance if do not throttle them.
  28377. this._throttledZrFlush();
  28378. }
  28379. flushPendingActions.call(this, silent);
  28380. triggerUpdatedEvent.call(this, silent);
  28381. };
  28382. ECharts.prototype.updateLabelLayout = function () {
  28383. lifecycle.trigger('series:layoutlabels', this._model, this._api, {
  28384. // Not adding series labels.
  28385. // TODO
  28386. updatedSeries: []
  28387. });
  28388. };
  28389. ECharts.prototype.appendData = function (params) {
  28390. if (this._disposed) {
  28391. disposedWarning(this.id);
  28392. return;
  28393. }
  28394. var seriesIndex = params.seriesIndex;
  28395. var ecModel = this.getModel();
  28396. var seriesModel = ecModel.getSeriesByIndex(seriesIndex);
  28397. if ("development" !== 'production') {
  28398. assert(params.data && seriesModel);
  28399. }
  28400. seriesModel.appendData(params);
  28401. // Note: `appendData` does not support that update extent of coordinate
  28402. // system, util some scenario require that. In the expected usage of
  28403. // `appendData`, the initial extent of coordinate system should better
  28404. // be fixed by axis `min`/`max` setting or initial data, otherwise if
  28405. // the extent changed while `appendData`, the location of the painted
  28406. // graphic elements have to be changed, which make the usage of
  28407. // `appendData` meaningless.
  28408. this._scheduler.unfinished = true;
  28409. this.getZr().wakeUp();
  28410. };
  28411. // A work around for no `internal` modifier in ts yet but
  28412. // need to strictly hide private methods to JS users.
  28413. ECharts.internalField = function () {
  28414. prepare = function (ecIns) {
  28415. var scheduler = ecIns._scheduler;
  28416. scheduler.restorePipelines(ecIns._model);
  28417. scheduler.prepareStageTasks();
  28418. prepareView(ecIns, true);
  28419. prepareView(ecIns, false);
  28420. scheduler.plan();
  28421. };
  28422. /**
  28423. * Prepare view instances of charts and components
  28424. */
  28425. prepareView = function (ecIns, isComponent) {
  28426. var ecModel = ecIns._model;
  28427. var scheduler = ecIns._scheduler;
  28428. var viewList = isComponent ? ecIns._componentsViews : ecIns._chartsViews;
  28429. var viewMap = isComponent ? ecIns._componentsMap : ecIns._chartsMap;
  28430. var zr = ecIns._zr;
  28431. var api = ecIns._api;
  28432. for (var i = 0; i < viewList.length; i++) {
  28433. viewList[i].__alive = false;
  28434. }
  28435. isComponent ? ecModel.eachComponent(function (componentType, model) {
  28436. componentType !== 'series' && doPrepare(model);
  28437. }) : ecModel.eachSeries(doPrepare);
  28438. function doPrepare(model) {
  28439. // By default view will be reused if possible for the case that `setOption` with "notMerge"
  28440. // mode and need to enable transition animation. (Usually, when they have the same id, or
  28441. // especially no id but have the same type & name & index. See the `model.id` generation
  28442. // rule in `makeIdAndName` and `viewId` generation rule here).
  28443. // But in `replaceMerge` mode, this feature should be able to disabled when it is clear that
  28444. // the new model has nothing to do with the old model.
  28445. var requireNewView = model.__requireNewView;
  28446. // This command should not work twice.
  28447. model.__requireNewView = false;
  28448. // Consider: id same and type changed.
  28449. var viewId = '_ec_' + model.id + '_' + model.type;
  28450. var view = !requireNewView && viewMap[viewId];
  28451. if (!view) {
  28452. var classType = parseClassType(model.type);
  28453. var Clazz = isComponent ? ComponentView.getClass(classType.main, classType.sub) :
  28454. // FIXME:TS
  28455. // (ChartView as ChartViewConstructor).getClass('series', classType.sub)
  28456. // For backward compat, still support a chart type declared as only subType
  28457. // like "liquidfill", but recommend "series.liquidfill"
  28458. // But need a base class to make a type series.
  28459. ChartView.getClass(classType.sub);
  28460. if ("development" !== 'production') {
  28461. assert(Clazz, classType.sub + ' does not exist.');
  28462. }
  28463. view = new Clazz();
  28464. view.init(ecModel, api);
  28465. viewMap[viewId] = view;
  28466. viewList.push(view);
  28467. zr.add(view.group);
  28468. }
  28469. model.__viewId = view.__id = viewId;
  28470. view.__alive = true;
  28471. view.__model = model;
  28472. view.group.__ecComponentInfo = {
  28473. mainType: model.mainType,
  28474. index: model.componentIndex
  28475. };
  28476. !isComponent && scheduler.prepareView(view, model, ecModel, api);
  28477. }
  28478. for (var i = 0; i < viewList.length;) {
  28479. var view = viewList[i];
  28480. if (!view.__alive) {
  28481. !isComponent && view.renderTask.dispose();
  28482. zr.remove(view.group);
  28483. view.dispose(ecModel, api);
  28484. viewList.splice(i, 1);
  28485. if (viewMap[view.__id] === view) {
  28486. delete viewMap[view.__id];
  28487. }
  28488. view.__id = view.group.__ecComponentInfo = null;
  28489. } else {
  28490. i++;
  28491. }
  28492. }
  28493. };
  28494. updateDirectly = function (ecIns, method, payload, mainType, subType) {
  28495. var ecModel = ecIns._model;
  28496. ecModel.setUpdatePayload(payload);
  28497. // broadcast
  28498. if (!mainType) {
  28499. // FIXME
  28500. // Chart will not be update directly here, except set dirty.
  28501. // But there is no such scenario now.
  28502. each([].concat(ecIns._componentsViews).concat(ecIns._chartsViews), callView);
  28503. return;
  28504. }
  28505. var query = {};
  28506. query[mainType + 'Id'] = payload[mainType + 'Id'];
  28507. query[mainType + 'Index'] = payload[mainType + 'Index'];
  28508. query[mainType + 'Name'] = payload[mainType + 'Name'];
  28509. var condition = {
  28510. mainType: mainType,
  28511. query: query
  28512. };
  28513. subType && (condition.subType = subType); // subType may be '' by parseClassType;
  28514. var excludeSeriesId = payload.excludeSeriesId;
  28515. var excludeSeriesIdMap;
  28516. if (excludeSeriesId != null) {
  28517. excludeSeriesIdMap = createHashMap();
  28518. each(normalizeToArray(excludeSeriesId), function (id) {
  28519. var modelId = convertOptionIdName(id, null);
  28520. if (modelId != null) {
  28521. excludeSeriesIdMap.set(modelId, true);
  28522. }
  28523. });
  28524. }
  28525. // If dispatchAction before setOption, do nothing.
  28526. ecModel && ecModel.eachComponent(condition, function (model) {
  28527. var isExcluded = excludeSeriesIdMap && excludeSeriesIdMap.get(model.id) != null;
  28528. if (isExcluded) {
  28529. return;
  28530. }
  28531. if (isHighDownPayload(payload)) {
  28532. if (model instanceof SeriesModel) {
  28533. if (payload.type === HIGHLIGHT_ACTION_TYPE && !payload.notBlur && !model.get(['emphasis', 'disabled'])) {
  28534. blurSeriesFromHighlightPayload(model, payload, ecIns._api);
  28535. }
  28536. } else {
  28537. var _a = findComponentHighDownDispatchers(model.mainType, model.componentIndex, payload.name, ecIns._api),
  28538. focusSelf = _a.focusSelf,
  28539. dispatchers = _a.dispatchers;
  28540. if (payload.type === HIGHLIGHT_ACTION_TYPE && focusSelf && !payload.notBlur) {
  28541. blurComponent(model.mainType, model.componentIndex, ecIns._api);
  28542. }
  28543. // PENDING:
  28544. // Whether to put this "enter emphasis" code in `ComponentView`,
  28545. // which will be the same as `ChartView` but might be not necessary
  28546. // and will be far from this logic.
  28547. if (dispatchers) {
  28548. each(dispatchers, function (dispatcher) {
  28549. payload.type === HIGHLIGHT_ACTION_TYPE ? enterEmphasis(dispatcher) : leaveEmphasis(dispatcher);
  28550. });
  28551. }
  28552. }
  28553. } else if (isSelectChangePayload(payload)) {
  28554. // TODO geo
  28555. if (model instanceof SeriesModel) {
  28556. toggleSelectionFromPayload(model, payload, ecIns._api);
  28557. updateSeriesElementSelection(model);
  28558. markStatusToUpdate(ecIns);
  28559. }
  28560. }
  28561. }, ecIns);
  28562. ecModel && ecModel.eachComponent(condition, function (model) {
  28563. var isExcluded = excludeSeriesIdMap && excludeSeriesIdMap.get(model.id) != null;
  28564. if (isExcluded) {
  28565. return;
  28566. }
  28567. callView(ecIns[mainType === 'series' ? '_chartsMap' : '_componentsMap'][model.__viewId]);
  28568. }, ecIns);
  28569. function callView(view) {
  28570. view && view.__alive && view[method] && view[method](view.__model, ecModel, ecIns._api, payload);
  28571. }
  28572. };
  28573. updateMethods = {
  28574. prepareAndUpdate: function (payload) {
  28575. prepare(this);
  28576. updateMethods.update.call(this, payload, payload && {
  28577. // Needs to mark option changed if newOption is given.
  28578. // It's from MagicType.
  28579. // TODO If use a separate flag optionChanged in payload?
  28580. optionChanged: payload.newOption != null
  28581. });
  28582. },
  28583. update: function (payload, updateParams) {
  28584. var ecModel = this._model;
  28585. var api = this._api;
  28586. var zr = this._zr;
  28587. var coordSysMgr = this._coordSysMgr;
  28588. var scheduler = this._scheduler;
  28589. // update before setOption
  28590. if (!ecModel) {
  28591. return;
  28592. }
  28593. ecModel.setUpdatePayload(payload);
  28594. scheduler.restoreData(ecModel, payload);
  28595. scheduler.performSeriesTasks(ecModel);
  28596. // TODO
  28597. // Save total ecModel here for undo/redo (after restoring data and before processing data).
  28598. // Undo (restoration of total ecModel) can be carried out in 'action' or outside API call.
  28599. // Create new coordinate system each update
  28600. // In LineView may save the old coordinate system and use it to get the original point.
  28601. coordSysMgr.create(ecModel, api);
  28602. scheduler.performDataProcessorTasks(ecModel, payload);
  28603. // Current stream render is not supported in data process. So we can update
  28604. // stream modes after data processing, where the filtered data is used to
  28605. // determine whether to use progressive rendering.
  28606. updateStreamModes(this, ecModel);
  28607. // We update stream modes before coordinate system updated, then the modes info
  28608. // can be fetched when coord sys updating (consider the barGrid extent fix). But
  28609. // the drawback is the full coord info can not be fetched. Fortunately this full
  28610. // coord is not required in stream mode updater currently.
  28611. coordSysMgr.update(ecModel, api);
  28612. clearColorPalette(ecModel);
  28613. scheduler.performVisualTasks(ecModel, payload);
  28614. // Set background and dark mode before rendering, because they affect auto-color-determination
  28615. // in zrender Text, and consequently affect the bounding rect if stroke is added.
  28616. var backgroundColor = ecModel.get('backgroundColor') || 'transparent';
  28617. zr.setBackgroundColor(backgroundColor);
  28618. // Force set dark mode.
  28619. var darkMode = ecModel.get('darkMode');
  28620. if (darkMode != null && darkMode !== 'auto') {
  28621. zr.setDarkMode(darkMode);
  28622. }
  28623. render(this, ecModel, api, payload, updateParams);
  28624. lifecycle.trigger('afterupdate', ecModel, api);
  28625. },
  28626. updateTransform: function (payload) {
  28627. var _this = this;
  28628. var ecModel = this._model;
  28629. var api = this._api;
  28630. // update before setOption
  28631. if (!ecModel) {
  28632. return;
  28633. }
  28634. ecModel.setUpdatePayload(payload);
  28635. // ChartView.markUpdateMethod(payload, 'updateTransform');
  28636. var componentDirtyList = [];
  28637. ecModel.eachComponent(function (componentType, componentModel) {
  28638. if (componentType === 'series') {
  28639. return;
  28640. }
  28641. var componentView = _this.getViewOfComponentModel(componentModel);
  28642. if (componentView && componentView.__alive) {
  28643. if (componentView.updateTransform) {
  28644. var result = componentView.updateTransform(componentModel, ecModel, api, payload);
  28645. result && result.update && componentDirtyList.push(componentView);
  28646. } else {
  28647. componentDirtyList.push(componentView);
  28648. }
  28649. }
  28650. });
  28651. var seriesDirtyMap = createHashMap();
  28652. ecModel.eachSeries(function (seriesModel) {
  28653. var chartView = _this._chartsMap[seriesModel.__viewId];
  28654. if (chartView.updateTransform) {
  28655. var result = chartView.updateTransform(seriesModel, ecModel, api, payload);
  28656. result && result.update && seriesDirtyMap.set(seriesModel.uid, 1);
  28657. } else {
  28658. seriesDirtyMap.set(seriesModel.uid, 1);
  28659. }
  28660. });
  28661. clearColorPalette(ecModel);
  28662. // Keep pipe to the exist pipeline because it depends on the render task of the full pipeline.
  28663. // this._scheduler.performVisualTasks(ecModel, payload, 'layout', true);
  28664. this._scheduler.performVisualTasks(ecModel, payload, {
  28665. setDirty: true,
  28666. dirtyMap: seriesDirtyMap
  28667. });
  28668. // Currently, not call render of components. Geo render cost a lot.
  28669. // renderComponents(ecIns, ecModel, api, payload, componentDirtyList);
  28670. renderSeries(this, ecModel, api, payload, {}, seriesDirtyMap);
  28671. lifecycle.trigger('afterupdate', ecModel, api);
  28672. },
  28673. updateView: function (payload) {
  28674. var ecModel = this._model;
  28675. // update before setOption
  28676. if (!ecModel) {
  28677. return;
  28678. }
  28679. ecModel.setUpdatePayload(payload);
  28680. ChartView.markUpdateMethod(payload, 'updateView');
  28681. clearColorPalette(ecModel);
  28682. // Keep pipe to the exist pipeline because it depends on the render task of the full pipeline.
  28683. this._scheduler.performVisualTasks(ecModel, payload, {
  28684. setDirty: true
  28685. });
  28686. render(this, ecModel, this._api, payload, {});
  28687. lifecycle.trigger('afterupdate', ecModel, this._api);
  28688. },
  28689. updateVisual: function (payload) {
  28690. // updateMethods.update.call(this, payload);
  28691. var _this = this;
  28692. var ecModel = this._model;
  28693. // update before setOption
  28694. if (!ecModel) {
  28695. return;
  28696. }
  28697. ecModel.setUpdatePayload(payload);
  28698. // clear all visual
  28699. ecModel.eachSeries(function (seriesModel) {
  28700. seriesModel.getData().clearAllVisual();
  28701. });
  28702. // Perform visual
  28703. ChartView.markUpdateMethod(payload, 'updateVisual');
  28704. clearColorPalette(ecModel);
  28705. // Keep pipe to the exist pipeline because it depends on the render task of the full pipeline.
  28706. this._scheduler.performVisualTasks(ecModel, payload, {
  28707. visualType: 'visual',
  28708. setDirty: true
  28709. });
  28710. ecModel.eachComponent(function (componentType, componentModel) {
  28711. if (componentType !== 'series') {
  28712. var componentView = _this.getViewOfComponentModel(componentModel);
  28713. componentView && componentView.__alive && componentView.updateVisual(componentModel, ecModel, _this._api, payload);
  28714. }
  28715. });
  28716. ecModel.eachSeries(function (seriesModel) {
  28717. var chartView = _this._chartsMap[seriesModel.__viewId];
  28718. chartView.updateVisual(seriesModel, ecModel, _this._api, payload);
  28719. });
  28720. lifecycle.trigger('afterupdate', ecModel, this._api);
  28721. },
  28722. updateLayout: function (payload) {
  28723. updateMethods.update.call(this, payload);
  28724. }
  28725. };
  28726. function doConvertPixelImpl(ecIns, methodName, finder, value, opt) {
  28727. if (ecIns._disposed) {
  28728. disposedWarning(ecIns.id);
  28729. return;
  28730. }
  28731. var ecModel = ecIns._model;
  28732. var coordSysList = ecIns._coordSysMgr.getCoordinateSystems();
  28733. var result;
  28734. var parsedFinder = parseFinder(ecModel, finder);
  28735. for (var i = 0; i < coordSysList.length; i++) {
  28736. var coordSys = coordSysList[i];
  28737. if (coordSys[methodName] && (result = coordSys[methodName](ecModel, parsedFinder, value, opt)) != null) {
  28738. return result;
  28739. }
  28740. }
  28741. if ("development" !== 'production') {
  28742. warn('No coordinate system that supports ' + methodName + ' found by the given finder.');
  28743. }
  28744. }
  28745. doConvertPixel = doConvertPixelImpl;
  28746. updateStreamModes = function (ecIns, ecModel) {
  28747. var chartsMap = ecIns._chartsMap;
  28748. var scheduler = ecIns._scheduler;
  28749. ecModel.eachSeries(function (seriesModel) {
  28750. scheduler.updateStreamModes(seriesModel, chartsMap[seriesModel.__viewId]);
  28751. });
  28752. };
  28753. doDispatchAction = function (payload, silent) {
  28754. var _this = this;
  28755. var ecModel = this.getModel();
  28756. var payloadType = payload.type;
  28757. var escapeConnect = payload.escapeConnect;
  28758. var actionInfo = actions[payloadType];
  28759. var cptTypeTmp = (actionInfo.update || 'update').split(':');
  28760. var updateMethod = cptTypeTmp.pop();
  28761. var cptType = cptTypeTmp[0] != null && parseClassType(cptTypeTmp[0]);
  28762. this[IN_MAIN_PROCESS_KEY] = true;
  28763. updateMainProcessVersion(this);
  28764. var payloads = [payload];
  28765. var batched = false;
  28766. // Batch action
  28767. if (payload.batch) {
  28768. batched = true;
  28769. payloads = map(payload.batch, function (item) {
  28770. item = defaults(extend({}, item), payload);
  28771. item.batch = null;
  28772. return item;
  28773. });
  28774. }
  28775. var eventObjBatch = [];
  28776. var eventObj;
  28777. var actionResultBatch = [];
  28778. var nonRefinedEventType = actionInfo.nonRefinedEventType;
  28779. var isSelectChange = isSelectChangePayload(payload);
  28780. var isHighDown = isHighDownPayload(payload);
  28781. // Only leave blur once if there are multiple batches.
  28782. if (isHighDown) {
  28783. allLeaveBlur(this._api);
  28784. }
  28785. each(payloads, function (batchItem) {
  28786. // Action can specify the event by return it.
  28787. var actionResult = actionInfo.action(batchItem, ecModel, _this._api);
  28788. if (actionInfo.refineEvent) {
  28789. actionResultBatch.push(actionResult);
  28790. } else {
  28791. eventObj = actionResult;
  28792. }
  28793. eventObj = eventObj || extend({}, batchItem);
  28794. eventObj.type = nonRefinedEventType;
  28795. eventObjBatch.push(eventObj);
  28796. // light update does not perform data process, layout and visual.
  28797. if (isHighDown) {
  28798. var _a = preParseFinder(payload),
  28799. queryOptionMap = _a.queryOptionMap,
  28800. mainTypeSpecified = _a.mainTypeSpecified;
  28801. var componentMainType = mainTypeSpecified ? queryOptionMap.keys()[0] : 'series';
  28802. updateDirectly(_this, updateMethod, batchItem, componentMainType);
  28803. markStatusToUpdate(_this);
  28804. } else if (isSelectChange) {
  28805. // At present `dispatchAction({ type: 'select', ... })` is not supported on components.
  28806. // geo still use 'geoselect'.
  28807. updateDirectly(_this, updateMethod, batchItem, 'series');
  28808. markStatusToUpdate(_this);
  28809. } else if (cptType) {
  28810. updateDirectly(_this, updateMethod, batchItem, cptType.main, cptType.sub);
  28811. }
  28812. });
  28813. if (updateMethod !== 'none' && !isHighDown && !isSelectChange && !cptType) {
  28814. try {
  28815. // Still dirty
  28816. if (this[PENDING_UPDATE]) {
  28817. prepare(this);
  28818. updateMethods.update.call(this, payload);
  28819. this[PENDING_UPDATE] = null;
  28820. } else {
  28821. updateMethods[updateMethod].call(this, payload);
  28822. }
  28823. } catch (e) {
  28824. this[IN_MAIN_PROCESS_KEY] = false;
  28825. throw e;
  28826. }
  28827. }
  28828. // Follow the rule of action batch
  28829. if (batched) {
  28830. eventObj = {
  28831. type: nonRefinedEventType,
  28832. escapeConnect: escapeConnect,
  28833. batch: eventObjBatch
  28834. };
  28835. } else {
  28836. eventObj = eventObjBatch[0];
  28837. }
  28838. this[IN_MAIN_PROCESS_KEY] = false;
  28839. if (!silent) {
  28840. var refinedEvent = void 0;
  28841. if (actionInfo.refineEvent) {
  28842. var eventContent = actionInfo.refineEvent(actionResultBatch, payload, ecModel, this._api).eventContent;
  28843. assert(isObject(eventContent));
  28844. refinedEvent = defaults({
  28845. type: actionInfo.refinedEventType
  28846. }, eventContent);
  28847. refinedEvent.fromAction = payload.type;
  28848. refinedEvent.fromActionPayload = payload;
  28849. refinedEvent.escapeConnect = true;
  28850. }
  28851. var messageCenter = this._messageCenter;
  28852. // - If `refineEvent` created a `refinedEvent`, `eventObj` (replicated from the original payload)
  28853. // is still needed to be triggered for the feature `connect`. But it will not be triggered to
  28854. // users in this case.
  28855. // - If no `refineEvent` used, `eventObj` will be triggered for both `connect` and users.
  28856. messageCenter.trigger(eventObj.type, eventObj);
  28857. if (refinedEvent) {
  28858. messageCenter.trigger(refinedEvent.type, refinedEvent);
  28859. }
  28860. }
  28861. };
  28862. flushPendingActions = function (silent) {
  28863. var pendingActions = this._pendingActions;
  28864. while (pendingActions.length) {
  28865. var payload = pendingActions.shift();
  28866. doDispatchAction.call(this, payload, silent);
  28867. }
  28868. };
  28869. triggerUpdatedEvent = function (silent) {
  28870. !silent && this.trigger('updated');
  28871. };
  28872. /**
  28873. * Event `rendered` is triggered when zr
  28874. * rendered. It is useful for realtime
  28875. * snapshot (reflect animation).
  28876. *
  28877. * Event `finished` is triggered when:
  28878. * (1) zrender rendering finished.
  28879. * (2) initial animation finished.
  28880. * (3) progressive rendering finished.
  28881. * (4) no pending action.
  28882. * (5) no delayed setOption needs to be processed.
  28883. */
  28884. bindRenderedEvent = function (zr, ecIns) {
  28885. zr.on('rendered', function (params) {
  28886. ecIns.trigger('rendered', params);
  28887. // The `finished` event should not be triggered repeatedly,
  28888. // so it should only be triggered when rendering indeed happens
  28889. // in zrender. (Consider the case that dipatchAction is keep
  28890. // triggering when mouse move).
  28891. if (
  28892. // Although zr is dirty if initial animation is not finished
  28893. // and this checking is called on frame, we also check
  28894. // animation finished for robustness.
  28895. zr.animation.isFinished() && !ecIns[PENDING_UPDATE] && !ecIns._scheduler.unfinished && !ecIns._pendingActions.length) {
  28896. ecIns.trigger('finished');
  28897. }
  28898. });
  28899. };
  28900. bindMouseEvent = function (zr, ecIns) {
  28901. zr.on('mouseover', function (e) {
  28902. var el = e.target;
  28903. var dispatcher = findEventDispatcher(el, isHighDownDispatcher);
  28904. if (dispatcher) {
  28905. handleGlobalMouseOverForHighDown(dispatcher, e, ecIns._api);
  28906. markStatusToUpdate(ecIns);
  28907. }
  28908. }).on('mouseout', function (e) {
  28909. var el = e.target;
  28910. var dispatcher = findEventDispatcher(el, isHighDownDispatcher);
  28911. if (dispatcher) {
  28912. handleGlobalMouseOutForHighDown(dispatcher, e, ecIns._api);
  28913. markStatusToUpdate(ecIns);
  28914. }
  28915. }).on('click', function (e) {
  28916. var el = e.target;
  28917. var dispatcher = findEventDispatcher(el, function (target) {
  28918. return getECData(target).dataIndex != null;
  28919. }, true);
  28920. if (dispatcher) {
  28921. var actionType = dispatcher.selected ? 'unselect' : 'select';
  28922. var ecData = getECData(dispatcher);
  28923. ecIns._api.dispatchAction({
  28924. type: actionType,
  28925. dataType: ecData.dataType,
  28926. dataIndexInside: ecData.dataIndex,
  28927. seriesIndex: ecData.seriesIndex,
  28928. isFromClick: true
  28929. });
  28930. }
  28931. });
  28932. };
  28933. function clearColorPalette(ecModel) {
  28934. ecModel.clearColorPalette();
  28935. ecModel.eachSeries(function (seriesModel) {
  28936. seriesModel.clearColorPalette();
  28937. });
  28938. }
  28939. // Allocate zlevels for series and components
  28940. function allocateZlevels(ecModel) {
  28941. var componentZLevels = [];
  28942. var seriesZLevels = [];
  28943. var hasSeparateZLevel = false;
  28944. ecModel.eachComponent(function (componentType, componentModel) {
  28945. var zlevel = componentModel.get('zlevel') || 0;
  28946. var z = componentModel.get('z') || 0;
  28947. var zlevelKey = componentModel.getZLevelKey();
  28948. hasSeparateZLevel = hasSeparateZLevel || !!zlevelKey;
  28949. (componentType === 'series' ? seriesZLevels : componentZLevels).push({
  28950. zlevel: zlevel,
  28951. z: z,
  28952. idx: componentModel.componentIndex,
  28953. type: componentType,
  28954. key: zlevelKey
  28955. });
  28956. });
  28957. if (hasSeparateZLevel) {
  28958. // Series after component
  28959. var zLevels = componentZLevels.concat(seriesZLevels);
  28960. var lastSeriesZLevel_1;
  28961. var lastSeriesKey_1;
  28962. sort(zLevels, function (a, b) {
  28963. if (a.zlevel === b.zlevel) {
  28964. return a.z - b.z;
  28965. }
  28966. return a.zlevel - b.zlevel;
  28967. });
  28968. each(zLevels, function (item) {
  28969. var componentModel = ecModel.getComponent(item.type, item.idx);
  28970. var zlevel = item.zlevel;
  28971. var key = item.key;
  28972. if (lastSeriesZLevel_1 != null) {
  28973. zlevel = Math.max(lastSeriesZLevel_1, zlevel);
  28974. }
  28975. if (key) {
  28976. if (zlevel === lastSeriesZLevel_1 && key !== lastSeriesKey_1) {
  28977. zlevel++;
  28978. }
  28979. lastSeriesKey_1 = key;
  28980. } else if (lastSeriesKey_1) {
  28981. if (zlevel === lastSeriesZLevel_1) {
  28982. zlevel++;
  28983. }
  28984. lastSeriesKey_1 = '';
  28985. }
  28986. lastSeriesZLevel_1 = zlevel;
  28987. componentModel.setZLevel(zlevel);
  28988. });
  28989. }
  28990. }
  28991. render = function (ecIns, ecModel, api, payload, updateParams) {
  28992. allocateZlevels(ecModel);
  28993. renderComponents(ecIns, ecModel, api, payload, updateParams);
  28994. each(ecIns._chartsViews, function (chart) {
  28995. chart.__alive = false;
  28996. });
  28997. renderSeries(ecIns, ecModel, api, payload, updateParams);
  28998. // Remove groups of unrendered charts
  28999. each(ecIns._chartsViews, function (chart) {
  29000. if (!chart.__alive) {
  29001. chart.remove(ecModel, api);
  29002. }
  29003. });
  29004. };
  29005. renderComponents = function (ecIns, ecModel, api, payload, updateParams, dirtyList) {
  29006. each(dirtyList || ecIns._componentsViews, function (componentView) {
  29007. var componentModel = componentView.__model;
  29008. clearStates(componentModel, componentView);
  29009. componentView.render(componentModel, ecModel, api, payload);
  29010. updateZ(componentModel, componentView);
  29011. updateStates(componentModel, componentView);
  29012. });
  29013. };
  29014. /**
  29015. * Render each chart and component
  29016. */
  29017. renderSeries = function (ecIns, ecModel, api, payload, updateParams, dirtyMap) {
  29018. // Render all charts
  29019. var scheduler = ecIns._scheduler;
  29020. updateParams = extend(updateParams || {}, {
  29021. updatedSeries: ecModel.getSeries()
  29022. });
  29023. // TODO progressive?
  29024. lifecycle.trigger('series:beforeupdate', ecModel, api, updateParams);
  29025. var unfinished = false;
  29026. ecModel.eachSeries(function (seriesModel) {
  29027. var chartView = ecIns._chartsMap[seriesModel.__viewId];
  29028. chartView.__alive = true;
  29029. var renderTask = chartView.renderTask;
  29030. scheduler.updatePayload(renderTask, payload);
  29031. // TODO states on marker.
  29032. clearStates(seriesModel, chartView);
  29033. if (dirtyMap && dirtyMap.get(seriesModel.uid)) {
  29034. renderTask.dirty();
  29035. }
  29036. if (renderTask.perform(scheduler.getPerformArgs(renderTask))) {
  29037. unfinished = true;
  29038. }
  29039. chartView.group.silent = !!seriesModel.get('silent');
  29040. // Should not call markRedraw on group, because it will disable zrender
  29041. // incremental render (always render from the __startIndex each frame)
  29042. // chartView.group.markRedraw();
  29043. updateBlend(seriesModel, chartView);
  29044. updateSeriesElementSelection(seriesModel);
  29045. });
  29046. scheduler.unfinished = unfinished || scheduler.unfinished;
  29047. lifecycle.trigger('series:layoutlabels', ecModel, api, updateParams);
  29048. // transition after label is layouted.
  29049. lifecycle.trigger('series:transition', ecModel, api, updateParams);
  29050. ecModel.eachSeries(function (seriesModel) {
  29051. var chartView = ecIns._chartsMap[seriesModel.__viewId];
  29052. // Update Z after labels updated. Before applying states.
  29053. updateZ(seriesModel, chartView);
  29054. // NOTE: Update states after label is updated.
  29055. // label should be in normal status when layouting.
  29056. updateStates(seriesModel, chartView);
  29057. });
  29058. // If use hover layer
  29059. updateHoverLayerStatus(ecIns, ecModel);
  29060. lifecycle.trigger('series:afterupdate', ecModel, api, updateParams);
  29061. };
  29062. markStatusToUpdate = function (ecIns) {
  29063. ecIns[STATUS_NEEDS_UPDATE_KEY] = true;
  29064. // Wake up zrender if it's sleep. Let it update states in the next frame.
  29065. ecIns.getZr().wakeUp();
  29066. };
  29067. updateMainProcessVersion = function (ecIns) {
  29068. ecIns[MAIN_PROCESS_VERSION_KEY] = (ecIns[MAIN_PROCESS_VERSION_KEY] + 1) % 1000;
  29069. };
  29070. applyChangedStates = function (ecIns) {
  29071. if (!ecIns[STATUS_NEEDS_UPDATE_KEY]) {
  29072. return;
  29073. }
  29074. ecIns.getZr().storage.traverse(function (el) {
  29075. // Not applied on removed elements, it may still in fading.
  29076. if (isElementRemoved(el)) {
  29077. return;
  29078. }
  29079. applyElementStates(el);
  29080. });
  29081. ecIns[STATUS_NEEDS_UPDATE_KEY] = false;
  29082. };
  29083. function applyElementStates(el) {
  29084. var newStates = [];
  29085. var oldStates = el.currentStates;
  29086. // Keep other states.
  29087. for (var i = 0; i < oldStates.length; i++) {
  29088. var stateName = oldStates[i];
  29089. if (!(stateName === 'emphasis' || stateName === 'blur' || stateName === 'select')) {
  29090. newStates.push(stateName);
  29091. }
  29092. }
  29093. // Only use states when it's exists.
  29094. if (el.selected && el.states.select) {
  29095. newStates.push('select');
  29096. }
  29097. if (el.hoverState === HOVER_STATE_EMPHASIS && el.states.emphasis) {
  29098. newStates.push('emphasis');
  29099. } else if (el.hoverState === HOVER_STATE_BLUR && el.states.blur) {
  29100. newStates.push('blur');
  29101. }
  29102. el.useStates(newStates);
  29103. }
  29104. function updateHoverLayerStatus(ecIns, ecModel) {
  29105. var zr = ecIns._zr;
  29106. var storage = zr.storage;
  29107. var elCount = 0;
  29108. storage.traverse(function (el) {
  29109. if (!el.isGroup) {
  29110. elCount++;
  29111. }
  29112. });
  29113. if (elCount > ecModel.get('hoverLayerThreshold') && !env.node && !env.worker) {
  29114. ecModel.eachSeries(function (seriesModel) {
  29115. if (seriesModel.preventUsingHoverLayer) {
  29116. return;
  29117. }
  29118. var chartView = ecIns._chartsMap[seriesModel.__viewId];
  29119. if (chartView.__alive) {
  29120. chartView.eachRendered(function (el) {
  29121. if (el.states.emphasis) {
  29122. el.states.emphasis.hoverLayer = true;
  29123. }
  29124. });
  29125. }
  29126. });
  29127. }
  29128. }
  29129. /**
  29130. * Update chart and blend.
  29131. */
  29132. function updateBlend(seriesModel, chartView) {
  29133. var blendMode = seriesModel.get('blendMode') || null;
  29134. chartView.eachRendered(function (el) {
  29135. // FIXME marker and other components
  29136. if (!el.isGroup) {
  29137. // DON'T mark the element dirty. In case element is incremental and don't want to rerender.
  29138. el.style.blend = blendMode;
  29139. }
  29140. });
  29141. }
  29142. function updateZ(model, view) {
  29143. if (model.preventAutoZ) {
  29144. return;
  29145. }
  29146. var zInfo = retrieveZInfo(model);
  29147. // Set z and zlevel
  29148. view.eachRendered(function (el) {
  29149. traverseUpdateZ(el, zInfo.z, zInfo.zlevel);
  29150. // Don't traverse the children because it has been traversed in _updateZ.
  29151. return true;
  29152. });
  29153. }
  29154. // Clear states without animation.
  29155. // TODO States on component.
  29156. function clearStates(model, view) {
  29157. view.eachRendered(function (el) {
  29158. // Not applied on removed elements, it may still in fading.
  29159. if (isElementRemoved(el)) {
  29160. return;
  29161. }
  29162. var textContent = el.getTextContent();
  29163. var textGuide = el.getTextGuideLine();
  29164. if (el.stateTransition) {
  29165. el.stateTransition = null;
  29166. }
  29167. if (textContent && textContent.stateTransition) {
  29168. textContent.stateTransition = null;
  29169. }
  29170. if (textGuide && textGuide.stateTransition) {
  29171. textGuide.stateTransition = null;
  29172. }
  29173. // TODO If el is incremental.
  29174. if (el.hasState()) {
  29175. el.prevStates = el.currentStates;
  29176. el.clearStates();
  29177. } else if (el.prevStates) {
  29178. el.prevStates = null;
  29179. }
  29180. });
  29181. }
  29182. function updateStates(model, view) {
  29183. var stateAnimationModel = model.getModel('stateAnimation');
  29184. var enableAnimation = model.isAnimationEnabled();
  29185. var duration = stateAnimationModel.get('duration');
  29186. var stateTransition = duration > 0 ? {
  29187. duration: duration,
  29188. delay: stateAnimationModel.get('delay'),
  29189. easing: stateAnimationModel.get('easing')
  29190. // additive: stateAnimationModel.get('additive')
  29191. } : null;
  29192. view.eachRendered(function (el) {
  29193. if (el.states && el.states.emphasis) {
  29194. // Not applied on removed elements, it may still in fading.
  29195. if (isElementRemoved(el)) {
  29196. return;
  29197. }
  29198. if (el instanceof Path) {
  29199. savePathStates(el);
  29200. }
  29201. // Only updated on changed element. In case element is incremental and don't want to rerender.
  29202. // TODO, a more proper way?
  29203. if (el.__dirty) {
  29204. var prevStates = el.prevStates;
  29205. // Restore states without animation
  29206. if (prevStates) {
  29207. el.useStates(prevStates);
  29208. }
  29209. }
  29210. // Update state transition and enable animation again.
  29211. if (enableAnimation) {
  29212. el.stateTransition = stateTransition;
  29213. var textContent = el.getTextContent();
  29214. var textGuide = el.getTextGuideLine();
  29215. // TODO Is it necessary to animate label?
  29216. if (textContent) {
  29217. textContent.stateTransition = stateTransition;
  29218. }
  29219. if (textGuide) {
  29220. textGuide.stateTransition = stateTransition;
  29221. }
  29222. }
  29223. // Use highlighted and selected flag to toggle states.
  29224. if (el.__dirty) {
  29225. applyElementStates(el);
  29226. }
  29227. }
  29228. });
  29229. }
  29230. createExtensionAPI = function (ecIns) {
  29231. return new (/** @class */function (_super) {
  29232. __extends(class_1, _super);
  29233. function class_1() {
  29234. return _super !== null && _super.apply(this, arguments) || this;
  29235. }
  29236. class_1.prototype.getCoordinateSystems = function () {
  29237. return ecIns._coordSysMgr.getCoordinateSystems();
  29238. };
  29239. class_1.prototype.getComponentByElement = function (el) {
  29240. while (el) {
  29241. var modelInfo = el.__ecComponentInfo;
  29242. if (modelInfo != null) {
  29243. return ecIns._model.getComponent(modelInfo.mainType, modelInfo.index);
  29244. }
  29245. el = el.parent;
  29246. }
  29247. };
  29248. class_1.prototype.enterEmphasis = function (el, highlightDigit) {
  29249. enterEmphasis(el, highlightDigit);
  29250. markStatusToUpdate(ecIns);
  29251. };
  29252. class_1.prototype.leaveEmphasis = function (el, highlightDigit) {
  29253. leaveEmphasis(el, highlightDigit);
  29254. markStatusToUpdate(ecIns);
  29255. };
  29256. class_1.prototype.enterBlur = function (el) {
  29257. enterBlur(el);
  29258. markStatusToUpdate(ecIns);
  29259. };
  29260. class_1.prototype.leaveBlur = function (el) {
  29261. leaveBlur(el);
  29262. markStatusToUpdate(ecIns);
  29263. };
  29264. class_1.prototype.enterSelect = function (el) {
  29265. enterSelect(el);
  29266. markStatusToUpdate(ecIns);
  29267. };
  29268. class_1.prototype.leaveSelect = function (el) {
  29269. leaveSelect(el);
  29270. markStatusToUpdate(ecIns);
  29271. };
  29272. class_1.prototype.getModel = function () {
  29273. return ecIns.getModel();
  29274. };
  29275. class_1.prototype.getViewOfComponentModel = function (componentModel) {
  29276. return ecIns.getViewOfComponentModel(componentModel);
  29277. };
  29278. class_1.prototype.getViewOfSeriesModel = function (seriesModel) {
  29279. return ecIns.getViewOfSeriesModel(seriesModel);
  29280. };
  29281. class_1.prototype.getMainProcessVersion = function () {
  29282. return ecIns[MAIN_PROCESS_VERSION_KEY];
  29283. };
  29284. return class_1;
  29285. }(ExtensionAPI))(ecIns);
  29286. };
  29287. enableConnect = function (chart) {
  29288. function updateConnectedChartsStatus(charts, status) {
  29289. for (var i = 0; i < charts.length; i++) {
  29290. var otherChart = charts[i];
  29291. otherChart[CONNECT_STATUS_KEY] = status;
  29292. }
  29293. }
  29294. each(connectionEventRevertMap, function (_, eventType) {
  29295. chart._messageCenter.on(eventType, function (event) {
  29296. if (connectedGroups[chart.group] && chart[CONNECT_STATUS_KEY] !== CONNECT_STATUS_PENDING) {
  29297. if (event && event.escapeConnect) {
  29298. return;
  29299. }
  29300. var action_1 = chart.makeActionFromEvent(event);
  29301. var otherCharts_1 = [];
  29302. each(instances$1, function (otherChart) {
  29303. if (otherChart !== chart && otherChart.group === chart.group) {
  29304. otherCharts_1.push(otherChart);
  29305. }
  29306. });
  29307. updateConnectedChartsStatus(otherCharts_1, CONNECT_STATUS_PENDING);
  29308. each(otherCharts_1, function (otherChart) {
  29309. if (otherChart[CONNECT_STATUS_KEY] !== CONNECT_STATUS_UPDATING) {
  29310. otherChart.dispatchAction(action_1);
  29311. }
  29312. });
  29313. updateConnectedChartsStatus(otherCharts_1, CONNECT_STATUS_UPDATED);
  29314. }
  29315. });
  29316. });
  29317. };
  29318. }();
  29319. return ECharts;
  29320. }(Eventful);
  29321. var echartsProto = ECharts.prototype;
  29322. echartsProto.on = createRegisterEventWithLowercaseECharts('on');
  29323. echartsProto.off = createRegisterEventWithLowercaseECharts('off');
  29324. /**
  29325. * @deprecated
  29326. */
  29327. // @ts-ignore
  29328. echartsProto.one = function (eventName, cb, ctx) {
  29329. var self = this;
  29330. deprecateLog('ECharts#one is deprecated.');
  29331. function wrapped() {
  29332. var args2 = [];
  29333. for (var _i = 0; _i < arguments.length; _i++) {
  29334. args2[_i] = arguments[_i];
  29335. }
  29336. cb && cb.apply && cb.apply(this, args2);
  29337. // @ts-ignore
  29338. self.off(eventName, wrapped);
  29339. }
  29340. // @ts-ignore
  29341. this.on.call(this, eventName, wrapped, ctx);
  29342. };
  29343. var MOUSE_EVENT_NAMES = ['click', 'dblclick', 'mouseover', 'mouseout', 'mousemove', 'mousedown', 'mouseup', 'globalout', 'contextmenu'];
  29344. function disposedWarning(id) {
  29345. if ("development" !== 'production') {
  29346. warn('Instance ' + id + ' has been disposed');
  29347. }
  29348. }
  29349. var actions = {};
  29350. /**
  29351. * Map event type to action type for reproducing action from event for `connect`.
  29352. */
  29353. var connectionEventRevertMap = {};
  29354. /**
  29355. * To remove duplication.
  29356. */
  29357. var publicEventTypeMap = {};
  29358. var dataProcessorFuncs = [];
  29359. var optionPreprocessorFuncs = [];
  29360. var visualFuncs = [];
  29361. var themeStorage = {};
  29362. var loadingEffects = {};
  29363. var instances$1 = {};
  29364. var connectedGroups = {};
  29365. var idBase = +new Date() - 0;
  29366. var groupIdBase = +new Date() - 0;
  29367. var DOM_ATTRIBUTE_KEY = '_echarts_instance_';
  29368. /**
  29369. * @param opts.devicePixelRatio Use window.devicePixelRatio by default
  29370. * @param opts.renderer Can choose 'canvas' or 'svg' to render the chart.
  29371. * @param opts.width Use clientWidth of the input `dom` by default.
  29372. * Can be 'auto' (the same as null/undefined)
  29373. * @param opts.height Use clientHeight of the input `dom` by default.
  29374. * Can be 'auto' (the same as null/undefined)
  29375. * @param opts.locale Specify the locale.
  29376. * @param opts.useDirtyRect Enable dirty rectangle rendering or not.
  29377. */
  29378. function init$1(dom, theme, opts) {
  29379. var isClient = !(opts && opts.ssr);
  29380. if (isClient) {
  29381. if ("development" !== 'production') {
  29382. if (!dom) {
  29383. throw new Error('Initialize failed: invalid dom.');
  29384. }
  29385. }
  29386. var existInstance = getInstanceByDom(dom);
  29387. if (existInstance) {
  29388. if ("development" !== 'production') {
  29389. warn('There is a chart instance already initialized on the dom.');
  29390. }
  29391. return existInstance;
  29392. }
  29393. if ("development" !== 'production') {
  29394. if (isDom(dom) && dom.nodeName.toUpperCase() !== 'CANVAS' && (!dom.clientWidth && (!opts || opts.width == null) || !dom.clientHeight && (!opts || opts.height == null))) {
  29395. warn('Can\'t get DOM width or height. Please check ' + 'dom.clientWidth and dom.clientHeight. They should not be 0.' + 'For example, you may need to call this in the callback ' + 'of window.onload.');
  29396. }
  29397. }
  29398. }
  29399. var chart = new ECharts(dom, theme, opts);
  29400. chart.id = 'ec_' + idBase++;
  29401. instances$1[chart.id] = chart;
  29402. isClient && setAttribute(dom, DOM_ATTRIBUTE_KEY, chart.id);
  29403. enableConnect(chart);
  29404. lifecycle.trigger('afterinit', chart);
  29405. return chart;
  29406. }
  29407. /**
  29408. * @usage
  29409. * (A)
  29410. * ```js
  29411. * let chart1 = echarts.init(dom1);
  29412. * let chart2 = echarts.init(dom2);
  29413. * chart1.group = 'xxx';
  29414. * chart2.group = 'xxx';
  29415. * echarts.connect('xxx');
  29416. * ```
  29417. * (B)
  29418. * ```js
  29419. * let chart1 = echarts.init(dom1);
  29420. * let chart2 = echarts.init(dom2);
  29421. * echarts.connect('xxx', [chart1, chart2]);
  29422. * ```
  29423. */
  29424. function connect(groupId) {
  29425. // Is array of charts
  29426. if (isArray(groupId)) {
  29427. var charts = groupId;
  29428. groupId = null;
  29429. // If any chart has group
  29430. each(charts, function (chart) {
  29431. if (chart.group != null) {
  29432. groupId = chart.group;
  29433. }
  29434. });
  29435. groupId = groupId || 'g_' + groupIdBase++;
  29436. each(charts, function (chart) {
  29437. chart.group = groupId;
  29438. });
  29439. }
  29440. connectedGroups[groupId] = true;
  29441. return groupId;
  29442. }
  29443. function disconnect(groupId) {
  29444. connectedGroups[groupId] = false;
  29445. }
  29446. /**
  29447. * Alias and backward compatibility
  29448. * @deprecated
  29449. */
  29450. var disConnect = disconnect;
  29451. /**
  29452. * Dispose a chart instance
  29453. */
  29454. function dispose$1(chart) {
  29455. if (isString(chart)) {
  29456. chart = instances$1[chart];
  29457. } else if (!(chart instanceof ECharts)) {
  29458. // Try to treat as dom
  29459. chart = getInstanceByDom(chart);
  29460. }
  29461. if (chart instanceof ECharts && !chart.isDisposed()) {
  29462. chart.dispose();
  29463. }
  29464. }
  29465. function getInstanceByDom(dom) {
  29466. return instances$1[getAttribute(dom, DOM_ATTRIBUTE_KEY)];
  29467. }
  29468. function getInstanceById(key) {
  29469. return instances$1[key];
  29470. }
  29471. /**
  29472. * Register theme
  29473. */
  29474. function registerTheme(name, theme) {
  29475. themeStorage[name] = theme;
  29476. }
  29477. /**
  29478. * Register option preprocessor
  29479. */
  29480. function registerPreprocessor(preprocessorFunc) {
  29481. if (indexOf(optionPreprocessorFuncs, preprocessorFunc) < 0) {
  29482. optionPreprocessorFuncs.push(preprocessorFunc);
  29483. }
  29484. }
  29485. function registerProcessor(priority, processor) {
  29486. normalizeRegister(dataProcessorFuncs, priority, processor, PRIORITY_PROCESSOR_DEFAULT);
  29487. }
  29488. /**
  29489. * Register postIniter
  29490. * @param {Function} postInitFunc
  29491. */
  29492. function registerPostInit(postInitFunc) {
  29493. registerUpdateLifecycle('afterinit', postInitFunc);
  29494. }
  29495. /**
  29496. * Register postUpdater
  29497. * @param {Function} postUpdateFunc
  29498. */
  29499. function registerPostUpdate(postUpdateFunc) {
  29500. registerUpdateLifecycle('afterupdate', postUpdateFunc);
  29501. }
  29502. function registerUpdateLifecycle(name, cb) {
  29503. lifecycle.on(name, cb);
  29504. }
  29505. function registerAction(arg0, arg1, action) {
  29506. var actionType;
  29507. var publicEventType;
  29508. var refineEvent;
  29509. var update;
  29510. var publishNonRefinedEvent;
  29511. if (isFunction(arg1)) {
  29512. action = arg1;
  29513. arg1 = '';
  29514. }
  29515. if (isObject(arg0)) {
  29516. actionType = arg0.type;
  29517. publicEventType = arg0.event;
  29518. update = arg0.update;
  29519. publishNonRefinedEvent = arg0.publishNonRefinedEvent;
  29520. if (!action) {
  29521. action = arg0.action;
  29522. }
  29523. refineEvent = arg0.refineEvent;
  29524. } else {
  29525. actionType = arg0;
  29526. publicEventType = arg1;
  29527. }
  29528. function createEventType(actionOrEventType) {
  29529. // Event type should be all lowercase
  29530. return actionOrEventType.toLowerCase();
  29531. }
  29532. publicEventType = createEventType(publicEventType || actionType);
  29533. // See comments on {ActionInfo} for the reason.
  29534. var nonRefinedEventType = refineEvent ? createEventType(actionType) : publicEventType;
  29535. // Support calling `registerAction` multiple times with the same action
  29536. // type; subsequent calls have no effect.
  29537. if (actions[actionType]) {
  29538. return;
  29539. }
  29540. // Validate action type and event name.
  29541. assert(ACTION_REG.test(actionType) && ACTION_REG.test(publicEventType));
  29542. if (refineEvent) {
  29543. // An event replicated from the action will be triggered internally for `connect` in this case.
  29544. assert(publicEventType !== actionType);
  29545. }
  29546. actions[actionType] = {
  29547. actionType: actionType,
  29548. refinedEventType: publicEventType,
  29549. nonRefinedEventType: nonRefinedEventType,
  29550. update: update,
  29551. action: action,
  29552. refineEvent: refineEvent
  29553. };
  29554. publicEventTypeMap[publicEventType] = 1;
  29555. if (refineEvent && publishNonRefinedEvent) {
  29556. publicEventTypeMap[nonRefinedEventType] = 1;
  29557. }
  29558. if ("development" !== 'production' && connectionEventRevertMap[nonRefinedEventType]) {
  29559. error(nonRefinedEventType + " must not be shared; use \"refineEvent\" if you intend to share an event name.");
  29560. }
  29561. connectionEventRevertMap[nonRefinedEventType] = actionType;
  29562. }
  29563. function registerCoordinateSystem(type, coordSysCreator) {
  29564. CoordinateSystemManager.register(type, coordSysCreator);
  29565. }
  29566. /**
  29567. * Get dimensions of specified coordinate system.
  29568. * @param {string} type
  29569. * @return {Array.<string|Object>}
  29570. */
  29571. function getCoordinateSystemDimensions(type) {
  29572. var coordSysCreator = CoordinateSystemManager.get(type);
  29573. if (coordSysCreator) {
  29574. return coordSysCreator.getDimensionsInfo ? coordSysCreator.getDimensionsInfo() : coordSysCreator.dimensions.slice();
  29575. }
  29576. }
  29577. function registerCustomSeries$1(seriesType, renderItem) {
  29578. registerCustomSeries(seriesType, renderItem);
  29579. }
  29580. function registerLayout(priority, layoutTask) {
  29581. normalizeRegister(visualFuncs, priority, layoutTask, PRIORITY_VISUAL_LAYOUT, 'layout');
  29582. }
  29583. function registerVisual(priority, visualTask) {
  29584. normalizeRegister(visualFuncs, priority, visualTask, PRIORITY_VISUAL_CHART, 'visual');
  29585. }
  29586. var registeredTasks = [];
  29587. function normalizeRegister(targetList, priority, fn, defaultPriority, visualType) {
  29588. if (isFunction(priority) || isObject(priority)) {
  29589. fn = priority;
  29590. priority = defaultPriority;
  29591. }
  29592. if ("development" !== 'production') {
  29593. if (isNaN(priority) || priority == null) {
  29594. throw new Error('Illegal priority');
  29595. }
  29596. // Check duplicate
  29597. each(targetList, function (wrap) {
  29598. assert(wrap.__raw !== fn);
  29599. });
  29600. }
  29601. // Already registered
  29602. if (indexOf(registeredTasks, fn) >= 0) {
  29603. return;
  29604. }
  29605. registeredTasks.push(fn);
  29606. var stageHandler = Scheduler.wrapStageHandler(fn, visualType);
  29607. stageHandler.__prio = priority;
  29608. stageHandler.__raw = fn;
  29609. targetList.push(stageHandler);
  29610. }
  29611. function registerLoading(name, loadingFx) {
  29612. loadingEffects[name] = loadingFx;
  29613. }
  29614. /**
  29615. * ZRender need a canvas context to do measureText.
  29616. * But in node environment canvas may be created by node-canvas.
  29617. * So we need to specify how to create a canvas instead of using document.createElement('canvas')
  29618. *
  29619. *
  29620. * @deprecated use setPlatformAPI({ createCanvas }) instead.
  29621. *
  29622. * @example
  29623. * let Canvas = require('canvas');
  29624. * let echarts = require('echarts');
  29625. * echarts.setCanvasCreator(function () {
  29626. * // Small size is enough.
  29627. * return new Canvas(32, 32);
  29628. * });
  29629. */
  29630. function setCanvasCreator(creator) {
  29631. if ("development" !== 'production') {
  29632. deprecateLog('setCanvasCreator is deprecated. Use setPlatformAPI({ createCanvas }) instead.');
  29633. }
  29634. setPlatformAPI({
  29635. createCanvas: creator
  29636. });
  29637. }
  29638. /**
  29639. * The parameters and usage: see `geoSourceManager.registerMap`.
  29640. * Compatible with previous `echarts.registerMap`.
  29641. */
  29642. function registerMap(mapName, geoJson, specialAreas) {
  29643. var registerMap = getImpl('registerMap');
  29644. registerMap && registerMap(mapName, geoJson, specialAreas);
  29645. }
  29646. function getMap(mapName) {
  29647. var getMap = getImpl('getMap');
  29648. return getMap && getMap(mapName);
  29649. }
  29650. var registerTransform = registerExternalTransform;
  29651. /**
  29652. * Globa dispatchAction to a specified chart instance.
  29653. */
  29654. // export function dispatchAction(payload: { chartId: string } & Payload, opt?: Parameters<ECharts['dispatchAction']>[1]) {
  29655. // if (!payload || !payload.chartId) {
  29656. // // Must have chartId to find chart
  29657. // return;
  29658. // }
  29659. // const chart = instances[payload.chartId];
  29660. // if (chart) {
  29661. // chart.dispatchAction(payload, opt);
  29662. // }
  29663. // }
  29664. // Builtin global visual
  29665. registerVisual(PRIORITY_VISUAL_GLOBAL, seriesStyleTask);
  29666. registerVisual(PRIORITY_VISUAL_CHART_DATA_CUSTOM, dataStyleTask);
  29667. registerVisual(PRIORITY_VISUAL_CHART_DATA_CUSTOM, dataColorPaletteTask);
  29668. registerVisual(PRIORITY_VISUAL_GLOBAL, seriesSymbolTask);
  29669. registerVisual(PRIORITY_VISUAL_CHART_DATA_CUSTOM, dataSymbolTask);
  29670. registerVisual(PRIORITY_VISUAL_DECAL, decalVisual);
  29671. registerPreprocessor(globalBackwardCompat);
  29672. registerProcessor(PRIORITY_PROCESSOR_DATASTACK, dataStack);
  29673. registerLoading('default', defaultLoading);
  29674. // Default actions
  29675. registerAction({
  29676. type: HIGHLIGHT_ACTION_TYPE,
  29677. event: HIGHLIGHT_ACTION_TYPE,
  29678. update: HIGHLIGHT_ACTION_TYPE
  29679. }, noop);
  29680. registerAction({
  29681. type: DOWNPLAY_ACTION_TYPE,
  29682. event: DOWNPLAY_ACTION_TYPE,
  29683. update: DOWNPLAY_ACTION_TYPE
  29684. }, noop);
  29685. registerAction({
  29686. type: SELECT_ACTION_TYPE,
  29687. event: SELECT_CHANGED_EVENT_TYPE,
  29688. update: SELECT_ACTION_TYPE,
  29689. action: noop,
  29690. refineEvent: makeSelectChangedEvent,
  29691. publishNonRefinedEvent: true
  29692. });
  29693. registerAction({
  29694. type: UNSELECT_ACTION_TYPE,
  29695. event: SELECT_CHANGED_EVENT_TYPE,
  29696. update: UNSELECT_ACTION_TYPE,
  29697. action: noop,
  29698. refineEvent: makeSelectChangedEvent,
  29699. publishNonRefinedEvent: true
  29700. });
  29701. registerAction({
  29702. type: TOGGLE_SELECT_ACTION_TYPE,
  29703. event: SELECT_CHANGED_EVENT_TYPE,
  29704. update: TOGGLE_SELECT_ACTION_TYPE,
  29705. action: noop,
  29706. refineEvent: makeSelectChangedEvent,
  29707. publishNonRefinedEvent: true
  29708. });
  29709. function makeSelectChangedEvent(actionResultBatch, payload, ecModel, api) {
  29710. return {
  29711. eventContent: {
  29712. selected: getAllSelectedIndices(ecModel),
  29713. isFromClick: payload.isFromClick || false
  29714. }
  29715. };
  29716. }
  29717. // Default theme, so that we can use `chart.setTheme('default')` to revert to
  29718. // the default theme after changing to other themes.
  29719. registerTheme('default', {});
  29720. registerTheme('dark', theme);
  29721. // For backward compatibility, where the namespace `dataTool` will
  29722. // be mounted on `echarts` is the extension `dataTool` is imported.
  29723. var dataTool = {};
  29724. var extensions = [];
  29725. var extensionRegisters = {
  29726. registerPreprocessor: registerPreprocessor,
  29727. registerProcessor: registerProcessor,
  29728. registerPostInit: registerPostInit,
  29729. registerPostUpdate: registerPostUpdate,
  29730. registerUpdateLifecycle: registerUpdateLifecycle,
  29731. registerAction: registerAction,
  29732. registerCoordinateSystem: registerCoordinateSystem,
  29733. registerLayout: registerLayout,
  29734. registerVisual: registerVisual,
  29735. registerTransform: registerTransform,
  29736. registerLoading: registerLoading,
  29737. registerMap: registerMap,
  29738. registerImpl: registerImpl,
  29739. PRIORITY: PRIORITY,
  29740. ComponentModel: ComponentModel,
  29741. ComponentView: ComponentView,
  29742. SeriesModel: SeriesModel,
  29743. ChartView: ChartView,
  29744. // TODO Use ComponentModel and SeriesModel instead of Constructor
  29745. registerComponentModel: function (ComponentModelClass) {
  29746. ComponentModel.registerClass(ComponentModelClass);
  29747. },
  29748. registerComponentView: function (ComponentViewClass) {
  29749. ComponentView.registerClass(ComponentViewClass);
  29750. },
  29751. registerSeriesModel: function (SeriesModelClass) {
  29752. SeriesModel.registerClass(SeriesModelClass);
  29753. },
  29754. registerChartView: function (ChartViewClass) {
  29755. ChartView.registerClass(ChartViewClass);
  29756. },
  29757. registerCustomSeries: function (seriesType, renderItem) {
  29758. registerCustomSeries(seriesType, renderItem);
  29759. },
  29760. registerSubTypeDefaulter: function (componentType, defaulter) {
  29761. ComponentModel.registerSubTypeDefaulter(componentType, defaulter);
  29762. },
  29763. registerPainter: function (painterType, PainterCtor) {
  29764. registerPainter(painterType, PainterCtor);
  29765. }
  29766. };
  29767. function use(ext) {
  29768. if (isArray(ext)) {
  29769. // use([ChartLine, ChartBar]);
  29770. each(ext, function (singleExt) {
  29771. use(singleExt);
  29772. });
  29773. return;
  29774. }
  29775. if (indexOf(extensions, ext) >= 0) {
  29776. return;
  29777. }
  29778. extensions.push(ext);
  29779. if (isFunction(ext)) {
  29780. ext = {
  29781. install: ext
  29782. };
  29783. }
  29784. ext.install(extensionRegisters);
  29785. }
  29786. /*
  29787. * Licensed to the Apache Software Foundation (ASF) under one
  29788. * or more contributor license agreements. See the NOTICE file
  29789. * distributed with this work for additional information
  29790. * regarding copyright ownership. The ASF licenses this file
  29791. * to you under the Apache License, Version 2.0 (the
  29792. * "License"); you may not use this file except in compliance
  29793. * with the License. You may obtain a copy of the License at
  29794. *
  29795. * http://www.apache.org/licenses/LICENSE-2.0
  29796. *
  29797. * Unless required by applicable law or agreed to in writing,
  29798. * software distributed under the License is distributed on an
  29799. * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
  29800. * KIND, either express or implied. See the License for the
  29801. * specific language governing permissions and limitations
  29802. * under the License.
  29803. */
  29804. /**
  29805. * AUTO-GENERATED FILE. DO NOT MODIFY.
  29806. */
  29807. /*
  29808. * Licensed to the Apache Software Foundation (ASF) under one
  29809. * or more contributor license agreements. See the NOTICE file
  29810. * distributed with this work for additional information
  29811. * regarding copyright ownership. The ASF licenses this file
  29812. * to you under the Apache License, Version 2.0 (the
  29813. * "License"); you may not use this file except in compliance
  29814. * with the License. You may obtain a copy of the License at
  29815. *
  29816. * http://www.apache.org/licenses/LICENSE-2.0
  29817. *
  29818. * Unless required by applicable law or agreed to in writing,
  29819. * software distributed under the License is distributed on an
  29820. * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
  29821. * KIND, either express or implied. See the License for the
  29822. * specific language governing permissions and limitations
  29823. * under the License.
  29824. */
  29825. function dataIndexMapValueLength(valNumOrArrLengthMoreThan2) {
  29826. return valNumOrArrLengthMoreThan2 == null ? 0 : valNumOrArrLengthMoreThan2.length || 1;
  29827. }
  29828. function defaultKeyGetter(item) {
  29829. return item;
  29830. }
  29831. var DataDiffer = /** @class */function () {
  29832. /**
  29833. * @param context Can be visited by this.context in callback.
  29834. */
  29835. function DataDiffer(oldArr, newArr, oldKeyGetter, newKeyGetter, context,
  29836. // By default: 'oneToOne'.
  29837. diffMode) {
  29838. this._old = oldArr;
  29839. this._new = newArr;
  29840. this._oldKeyGetter = oldKeyGetter || defaultKeyGetter;
  29841. this._newKeyGetter = newKeyGetter || defaultKeyGetter;
  29842. // Visible in callback via `this.context`;
  29843. this.context = context;
  29844. this._diffModeMultiple = diffMode === 'multiple';
  29845. }
  29846. /**
  29847. * Callback function when add a data
  29848. */
  29849. DataDiffer.prototype.add = function (func) {
  29850. this._add = func;
  29851. return this;
  29852. };
  29853. /**
  29854. * Callback function when update a data
  29855. */
  29856. DataDiffer.prototype.update = function (func) {
  29857. this._update = func;
  29858. return this;
  29859. };
  29860. /**
  29861. * Callback function when update a data and only work in `cbMode: 'byKey'`.
  29862. */
  29863. DataDiffer.prototype.updateManyToOne = function (func) {
  29864. this._updateManyToOne = func;
  29865. return this;
  29866. };
  29867. /**
  29868. * Callback function when update a data and only work in `cbMode: 'byKey'`.
  29869. */
  29870. DataDiffer.prototype.updateOneToMany = function (func) {
  29871. this._updateOneToMany = func;
  29872. return this;
  29873. };
  29874. /**
  29875. * Callback function when update a data and only work in `cbMode: 'byKey'`.
  29876. */
  29877. DataDiffer.prototype.updateManyToMany = function (func) {
  29878. this._updateManyToMany = func;
  29879. return this;
  29880. };
  29881. /**
  29882. * Callback function when remove a data
  29883. */
  29884. DataDiffer.prototype.remove = function (func) {
  29885. this._remove = func;
  29886. return this;
  29887. };
  29888. DataDiffer.prototype.execute = function () {
  29889. this[this._diffModeMultiple ? '_executeMultiple' : '_executeOneToOne']();
  29890. };
  29891. DataDiffer.prototype._executeOneToOne = function () {
  29892. var oldArr = this._old;
  29893. var newArr = this._new;
  29894. var newDataIndexMap = {};
  29895. var oldDataKeyArr = new Array(oldArr.length);
  29896. var newDataKeyArr = new Array(newArr.length);
  29897. this._initIndexMap(oldArr, null, oldDataKeyArr, '_oldKeyGetter');
  29898. this._initIndexMap(newArr, newDataIndexMap, newDataKeyArr, '_newKeyGetter');
  29899. for (var i = 0; i < oldArr.length; i++) {
  29900. var oldKey = oldDataKeyArr[i];
  29901. var newIdxMapVal = newDataIndexMap[oldKey];
  29902. var newIdxMapValLen = dataIndexMapValueLength(newIdxMapVal);
  29903. // idx can never be empty array here. see 'set null' logic below.
  29904. if (newIdxMapValLen > 1) {
  29905. // Consider there is duplicate key (for example, use dataItem.name as key).
  29906. // We should make sure every item in newArr and oldArr can be visited.
  29907. var newIdx = newIdxMapVal.shift();
  29908. if (newIdxMapVal.length === 1) {
  29909. newDataIndexMap[oldKey] = newIdxMapVal[0];
  29910. }
  29911. this._update && this._update(newIdx, i);
  29912. } else if (newIdxMapValLen === 1) {
  29913. newDataIndexMap[oldKey] = null;
  29914. this._update && this._update(newIdxMapVal, i);
  29915. } else {
  29916. this._remove && this._remove(i);
  29917. }
  29918. }
  29919. this._performRestAdd(newDataKeyArr, newDataIndexMap);
  29920. };
  29921. /**
  29922. * For example, consider the case:
  29923. * oldData: [o0, o1, o2, o3, o4, o5, o6, o7],
  29924. * newData: [n0, n1, n2, n3, n4, n5, n6, n7, n8],
  29925. * Where:
  29926. * o0, o1, n0 has key 'a' (many to one)
  29927. * o5, n4, n5, n6 has key 'b' (one to many)
  29928. * o2, n1 has key 'c' (one to one)
  29929. * n2, n3 has key 'd' (add)
  29930. * o3, o4 has key 'e' (remove)
  29931. * o6, o7, n7, n8 has key 'f' (many to many, treated as add and remove)
  29932. * Then:
  29933. * (The order of the following directives are not ensured.)
  29934. * this._updateManyToOne(n0, [o0, o1]);
  29935. * this._updateOneToMany([n4, n5, n6], o5);
  29936. * this._update(n1, o2);
  29937. * this._remove(o3);
  29938. * this._remove(o4);
  29939. * this._remove(o6);
  29940. * this._remove(o7);
  29941. * this._add(n2);
  29942. * this._add(n3);
  29943. * this._add(n7);
  29944. * this._add(n8);
  29945. */
  29946. DataDiffer.prototype._executeMultiple = function () {
  29947. var oldArr = this._old;
  29948. var newArr = this._new;
  29949. var oldDataIndexMap = {};
  29950. var newDataIndexMap = {};
  29951. var oldDataKeyArr = [];
  29952. var newDataKeyArr = [];
  29953. this._initIndexMap(oldArr, oldDataIndexMap, oldDataKeyArr, '_oldKeyGetter');
  29954. this._initIndexMap(newArr, newDataIndexMap, newDataKeyArr, '_newKeyGetter');
  29955. for (var i = 0; i < oldDataKeyArr.length; i++) {
  29956. var oldKey = oldDataKeyArr[i];
  29957. var oldIdxMapVal = oldDataIndexMap[oldKey];
  29958. var newIdxMapVal = newDataIndexMap[oldKey];
  29959. var oldIdxMapValLen = dataIndexMapValueLength(oldIdxMapVal);
  29960. var newIdxMapValLen = dataIndexMapValueLength(newIdxMapVal);
  29961. if (oldIdxMapValLen > 1 && newIdxMapValLen === 1) {
  29962. this._updateManyToOne && this._updateManyToOne(newIdxMapVal, oldIdxMapVal);
  29963. newDataIndexMap[oldKey] = null;
  29964. } else if (oldIdxMapValLen === 1 && newIdxMapValLen > 1) {
  29965. this._updateOneToMany && this._updateOneToMany(newIdxMapVal, oldIdxMapVal);
  29966. newDataIndexMap[oldKey] = null;
  29967. } else if (oldIdxMapValLen === 1 && newIdxMapValLen === 1) {
  29968. this._update && this._update(newIdxMapVal, oldIdxMapVal);
  29969. newDataIndexMap[oldKey] = null;
  29970. } else if (oldIdxMapValLen > 1 && newIdxMapValLen > 1) {
  29971. this._updateManyToMany && this._updateManyToMany(newIdxMapVal, oldIdxMapVal);
  29972. newDataIndexMap[oldKey] = null;
  29973. } else if (oldIdxMapValLen > 1) {
  29974. for (var i_1 = 0; i_1 < oldIdxMapValLen; i_1++) {
  29975. this._remove && this._remove(oldIdxMapVal[i_1]);
  29976. }
  29977. } else {
  29978. this._remove && this._remove(oldIdxMapVal);
  29979. }
  29980. }
  29981. this._performRestAdd(newDataKeyArr, newDataIndexMap);
  29982. };
  29983. DataDiffer.prototype._performRestAdd = function (newDataKeyArr, newDataIndexMap) {
  29984. for (var i = 0; i < newDataKeyArr.length; i++) {
  29985. var newKey = newDataKeyArr[i];
  29986. var newIdxMapVal = newDataIndexMap[newKey];
  29987. var idxMapValLen = dataIndexMapValueLength(newIdxMapVal);
  29988. if (idxMapValLen > 1) {
  29989. for (var j = 0; j < idxMapValLen; j++) {
  29990. this._add && this._add(newIdxMapVal[j]);
  29991. }
  29992. } else if (idxMapValLen === 1) {
  29993. this._add && this._add(newIdxMapVal);
  29994. }
  29995. // Support both `newDataKeyArr` are duplication removed or not removed.
  29996. newDataIndexMap[newKey] = null;
  29997. }
  29998. };
  29999. DataDiffer.prototype._initIndexMap = function (arr,
  30000. // Can be null.
  30001. map,
  30002. // In 'byKey', the output `keyArr` is duplication removed.
  30003. // In 'byIndex', the output `keyArr` is not duplication removed and
  30004. // its indices are accurately corresponding to `arr`.
  30005. keyArr, keyGetterName) {
  30006. var cbModeMultiple = this._diffModeMultiple;
  30007. for (var i = 0; i < arr.length; i++) {
  30008. // Add prefix to avoid conflict with Object.prototype.
  30009. var key = '_ec_' + this[keyGetterName](arr[i], i);
  30010. if (!cbModeMultiple) {
  30011. keyArr[i] = key;
  30012. }
  30013. if (!map) {
  30014. continue;
  30015. }
  30016. var idxMapVal = map[key];
  30017. var idxMapValLen = dataIndexMapValueLength(idxMapVal);
  30018. if (idxMapValLen === 0) {
  30019. // Simple optimize: in most cases, one index has one key,
  30020. // do not need array.
  30021. map[key] = i;
  30022. if (cbModeMultiple) {
  30023. keyArr.push(key);
  30024. }
  30025. } else if (idxMapValLen === 1) {
  30026. map[key] = [idxMapVal, i];
  30027. } else {
  30028. idxMapVal.push(i);
  30029. }
  30030. }
  30031. };
  30032. return DataDiffer;
  30033. }();
  30034. var DimensionUserOuput = /** @class */function () {
  30035. function DimensionUserOuput(encode, dimRequest) {
  30036. this._encode = encode;
  30037. this._schema = dimRequest;
  30038. }
  30039. DimensionUserOuput.prototype.get = function () {
  30040. return {
  30041. // Do not generate full dimension name until fist used.
  30042. fullDimensions: this._getFullDimensionNames(),
  30043. encode: this._encode
  30044. };
  30045. };
  30046. /**
  30047. * Get all data store dimension names.
  30048. * Theoretically a series data store is defined both by series and used dataset (if any).
  30049. * If some dimensions are omitted for performance reason in `this.dimensions`,
  30050. * the dimension name may not be auto-generated if user does not specify a dimension name.
  30051. * In this case, the dimension name is `null`/`undefined`.
  30052. */
  30053. DimensionUserOuput.prototype._getFullDimensionNames = function () {
  30054. if (!this._cachedDimNames) {
  30055. this._cachedDimNames = this._schema ? this._schema.makeOutputDimensionNames() : [];
  30056. }
  30057. return this._cachedDimNames;
  30058. };
  30059. return DimensionUserOuput;
  30060. }();
  30061. function summarizeDimensions(data, schema) {
  30062. var summary = {};
  30063. var encode = summary.encode = {};
  30064. var notExtraCoordDimMap = createHashMap();
  30065. var defaultedLabel = [];
  30066. var defaultedTooltip = [];
  30067. var userOutputEncode = {};
  30068. each(data.dimensions, function (dimName) {
  30069. var dimItem = data.getDimensionInfo(dimName);
  30070. var coordDim = dimItem.coordDim;
  30071. if (coordDim) {
  30072. if ("development" !== 'production') {
  30073. assert(VISUAL_DIMENSIONS.get(coordDim) == null);
  30074. }
  30075. var coordDimIndex = dimItem.coordDimIndex;
  30076. getOrCreateEncodeArr(encode, coordDim)[coordDimIndex] = dimName;
  30077. if (!dimItem.isExtraCoord) {
  30078. notExtraCoordDimMap.set(coordDim, 1);
  30079. // Use the last coord dim (and label friendly) as default label,
  30080. // because when dataset is used, it is hard to guess which dimension
  30081. // can be value dimension. If both show x, y on label is not look good,
  30082. // and conventionally y axis is focused more.
  30083. if (mayLabelDimType(dimItem.type)) {
  30084. defaultedLabel[0] = dimName;
  30085. }
  30086. // User output encode do not contain generated coords.
  30087. // And it only has index. User can use index to retrieve value from the raw item array.
  30088. getOrCreateEncodeArr(userOutputEncode, coordDim)[coordDimIndex] = data.getDimensionIndex(dimItem.name);
  30089. }
  30090. if (dimItem.defaultTooltip) {
  30091. defaultedTooltip.push(dimName);
  30092. }
  30093. }
  30094. VISUAL_DIMENSIONS.each(function (v, otherDim) {
  30095. var encodeArr = getOrCreateEncodeArr(encode, otherDim);
  30096. var dimIndex = dimItem.otherDims[otherDim];
  30097. if (dimIndex != null && dimIndex !== false) {
  30098. encodeArr[dimIndex] = dimItem.name;
  30099. }
  30100. });
  30101. });
  30102. var dataDimsOnCoord = [];
  30103. var encodeFirstDimNotExtra = {};
  30104. notExtraCoordDimMap.each(function (v, coordDim) {
  30105. var dimArr = encode[coordDim];
  30106. encodeFirstDimNotExtra[coordDim] = dimArr[0];
  30107. // Not necessary to remove duplicate, because a data
  30108. // dim canot on more than one coordDim.
  30109. dataDimsOnCoord = dataDimsOnCoord.concat(dimArr);
  30110. });
  30111. summary.dataDimsOnCoord = dataDimsOnCoord;
  30112. summary.dataDimIndicesOnCoord = map(dataDimsOnCoord, function (dimName) {
  30113. return data.getDimensionInfo(dimName).storeDimIndex;
  30114. });
  30115. summary.encodeFirstDimNotExtra = encodeFirstDimNotExtra;
  30116. var encodeLabel = encode.label;
  30117. // FIXME `encode.label` is not recommended, because formatter cannot be set
  30118. // in this way. Use label.formatter instead. Maybe remove this approach someday.
  30119. if (encodeLabel && encodeLabel.length) {
  30120. defaultedLabel = encodeLabel.slice();
  30121. }
  30122. var encodeTooltip = encode.tooltip;
  30123. if (encodeTooltip && encodeTooltip.length) {
  30124. defaultedTooltip = encodeTooltip.slice();
  30125. } else if (!defaultedTooltip.length) {
  30126. defaultedTooltip = defaultedLabel.slice();
  30127. }
  30128. encode.defaultedLabel = defaultedLabel;
  30129. encode.defaultedTooltip = defaultedTooltip;
  30130. summary.userOutput = new DimensionUserOuput(userOutputEncode, schema);
  30131. return summary;
  30132. }
  30133. function getOrCreateEncodeArr(encode, dim) {
  30134. if (!encode.hasOwnProperty(dim)) {
  30135. encode[dim] = [];
  30136. }
  30137. return encode[dim];
  30138. }
  30139. // FIXME:TS should be type `AxisType`
  30140. function getDimensionTypeByAxis(axisType) {
  30141. return axisType === 'category' ? 'ordinal' : axisType === 'time' ? 'time' : 'float';
  30142. }
  30143. function mayLabelDimType(dimType) {
  30144. // In most cases, ordinal and time do not suitable for label.
  30145. // Ordinal info can be displayed on axis. Time is too long.
  30146. return !(dimType === 'ordinal' || dimType === 'time');
  30147. }
  30148. // function findTheLastDimMayLabel(data) {
  30149. // // Get last value dim
  30150. // let dimensions = data.dimensions.slice();
  30151. // let valueType;
  30152. // let valueDim;
  30153. // while (dimensions.length && (
  30154. // valueDim = dimensions.pop(),
  30155. // valueType = data.getDimensionInfo(valueDim).type,
  30156. // valueType === 'ordinal' || valueType === 'time'
  30157. // )) {} // jshint ignore:line
  30158. // return valueDim;
  30159. // }
  30160. var SeriesDimensionDefine = /** @class */function () {
  30161. /**
  30162. * @param opt All of the fields will be shallow copied.
  30163. */
  30164. function SeriesDimensionDefine(opt) {
  30165. /**
  30166. * The format of `otherDims` is:
  30167. * ```js
  30168. * {
  30169. * tooltip?: number
  30170. * label?: number
  30171. * itemName?: number
  30172. * seriesName?: number
  30173. * }
  30174. * ```
  30175. *
  30176. * A `series.encode` can specified these fields:
  30177. * ```js
  30178. * encode: {
  30179. * // "3, 1, 5" is the index of data dimension.
  30180. * tooltip: [3, 1, 5],
  30181. * label: [0, 3],
  30182. * ...
  30183. * }
  30184. * ```
  30185. * `otherDims` is the parse result of the `series.encode` above, like:
  30186. * ```js
  30187. * // Suppose the index of this data dimension is `3`.
  30188. * this.otherDims = {
  30189. * // `3` is at the index `0` of the `encode.tooltip`
  30190. * tooltip: 0,
  30191. * // `3` is at the index `1` of the `encode.label`
  30192. * label: 1
  30193. * };
  30194. * ```
  30195. *
  30196. * This prop should never be `null`/`undefined` after initialized.
  30197. */
  30198. this.otherDims = {};
  30199. if (opt != null) {
  30200. extend(this, opt);
  30201. }
  30202. }
  30203. return SeriesDimensionDefine;
  30204. }();
  30205. var inner$4 = makeInner();
  30206. var dimTypeShort = {
  30207. float: 'f',
  30208. int: 'i',
  30209. ordinal: 'o',
  30210. number: 'n',
  30211. time: 't'
  30212. };
  30213. /**
  30214. * Represents the dimension requirement of a series.
  30215. *
  30216. * NOTICE:
  30217. * When there are too many dimensions in dataset and many series, only the used dimensions
  30218. * (i.e., used by coord sys and declared in `series.encode`) are add to `dimensionDefineList`.
  30219. * But users may query data by other unused dimension names.
  30220. * In this case, users can only query data if and only if they have defined dimension names
  30221. * via ec option, so we provide `getDimensionIndexFromSource`, which only query them from
  30222. * `source` dimensions.
  30223. */
  30224. var SeriesDataSchema = /** @class */function () {
  30225. function SeriesDataSchema(opt) {
  30226. this.dimensions = opt.dimensions;
  30227. this._dimOmitted = opt.dimensionOmitted;
  30228. this.source = opt.source;
  30229. this._fullDimCount = opt.fullDimensionCount;
  30230. this._updateDimOmitted(opt.dimensionOmitted);
  30231. }
  30232. SeriesDataSchema.prototype.isDimensionOmitted = function () {
  30233. return this._dimOmitted;
  30234. };
  30235. SeriesDataSchema.prototype._updateDimOmitted = function (dimensionOmitted) {
  30236. this._dimOmitted = dimensionOmitted;
  30237. if (!dimensionOmitted) {
  30238. return;
  30239. }
  30240. if (!this._dimNameMap) {
  30241. this._dimNameMap = ensureSourceDimNameMap(this.source);
  30242. }
  30243. };
  30244. /**
  30245. * @caution Can only be used when `dimensionOmitted: true`.
  30246. *
  30247. * Get index by user defined dimension name (i.e., not internal generate name).
  30248. * That is, get index from `dimensionsDefine`.
  30249. * If no `dimensionsDefine`, or no name get, return -1.
  30250. */
  30251. SeriesDataSchema.prototype.getSourceDimensionIndex = function (dimName) {
  30252. return retrieve2(this._dimNameMap.get(dimName), -1);
  30253. };
  30254. /**
  30255. * @caution Can only be used when `dimensionOmitted: true`.
  30256. *
  30257. * Notice: may return `null`/`undefined` if user not specify dimension names.
  30258. */
  30259. SeriesDataSchema.prototype.getSourceDimension = function (dimIndex) {
  30260. var dimensionsDefine = this.source.dimensionsDefine;
  30261. if (dimensionsDefine) {
  30262. return dimensionsDefine[dimIndex];
  30263. }
  30264. };
  30265. SeriesDataSchema.prototype.makeStoreSchema = function () {
  30266. var dimCount = this._fullDimCount;
  30267. var willRetrieveDataByName = shouldRetrieveDataByName(this.source);
  30268. var makeHashStrict = !shouldOmitUnusedDimensions(dimCount);
  30269. // If source don't have dimensions or series don't omit unsed dimensions.
  30270. // Generate from seriesDimList directly
  30271. var dimHash = '';
  30272. var dims = [];
  30273. for (var fullDimIdx = 0, seriesDimIdx = 0; fullDimIdx < dimCount; fullDimIdx++) {
  30274. var property = void 0;
  30275. var type = void 0;
  30276. var ordinalMeta = void 0;
  30277. var seriesDimDef = this.dimensions[seriesDimIdx];
  30278. // The list has been sorted by `storeDimIndex` asc.
  30279. if (seriesDimDef && seriesDimDef.storeDimIndex === fullDimIdx) {
  30280. property = willRetrieveDataByName ? seriesDimDef.name : null;
  30281. type = seriesDimDef.type;
  30282. ordinalMeta = seriesDimDef.ordinalMeta;
  30283. seriesDimIdx++;
  30284. } else {
  30285. var sourceDimDef = this.getSourceDimension(fullDimIdx);
  30286. if (sourceDimDef) {
  30287. property = willRetrieveDataByName ? sourceDimDef.name : null;
  30288. type = sourceDimDef.type;
  30289. }
  30290. }
  30291. dims.push({
  30292. property: property,
  30293. type: type,
  30294. ordinalMeta: ordinalMeta
  30295. });
  30296. // If retrieving data by index,
  30297. // use <index, type, ordinalMeta> to determine whether data can be shared.
  30298. // (Because in this case there might be no dimension name defined in dataset, but indices always exists).
  30299. // (Indices are always 0, 1, 2, ..., so we can ignore them to shorten the hash).
  30300. // Otherwise if retrieving data by property name (like `data: [{aa: 123, bb: 765}, ...]`),
  30301. // use <property, type, ordinalMeta> in hash.
  30302. if (willRetrieveDataByName && property != null
  30303. // For data stack, we have make sure each series has its own dim on this store.
  30304. // So we do not add property to hash to make sure they can share this store.
  30305. && (!seriesDimDef || !seriesDimDef.isCalculationCoord)) {
  30306. dimHash += makeHashStrict
  30307. // Use escape character '`' in case that property name contains '$'.
  30308. ? property.replace(/\`/g, '`1').replace(/\$/g, '`2')
  30309. // For better performance, when there are large dimensions, tolerant this defects that hardly meet.
  30310. : property;
  30311. }
  30312. dimHash += '$';
  30313. dimHash += dimTypeShort[type] || 'f';
  30314. if (ordinalMeta) {
  30315. dimHash += ordinalMeta.uid;
  30316. }
  30317. dimHash += '$';
  30318. }
  30319. // Source from endpoint(usually series) will be read differently
  30320. // when seriesLayoutBy or startIndex(which is affected by sourceHeader) are different.
  30321. // So we use this three props as key.
  30322. var source = this.source;
  30323. var hash = [source.seriesLayoutBy, source.startIndex, dimHash].join('$$');
  30324. return {
  30325. dimensions: dims,
  30326. hash: hash
  30327. };
  30328. };
  30329. SeriesDataSchema.prototype.makeOutputDimensionNames = function () {
  30330. var result = [];
  30331. for (var fullDimIdx = 0, seriesDimIdx = 0; fullDimIdx < this._fullDimCount; fullDimIdx++) {
  30332. var name_1 = void 0;
  30333. var seriesDimDef = this.dimensions[seriesDimIdx];
  30334. // The list has been sorted by `storeDimIndex` asc.
  30335. if (seriesDimDef && seriesDimDef.storeDimIndex === fullDimIdx) {
  30336. if (!seriesDimDef.isCalculationCoord) {
  30337. name_1 = seriesDimDef.name;
  30338. }
  30339. seriesDimIdx++;
  30340. } else {
  30341. var sourceDimDef = this.getSourceDimension(fullDimIdx);
  30342. if (sourceDimDef) {
  30343. name_1 = sourceDimDef.name;
  30344. }
  30345. }
  30346. result.push(name_1);
  30347. }
  30348. return result;
  30349. };
  30350. SeriesDataSchema.prototype.appendCalculationDimension = function (dimDef) {
  30351. this.dimensions.push(dimDef);
  30352. dimDef.isCalculationCoord = true;
  30353. this._fullDimCount++;
  30354. // If append dimension on a data store, consider the store
  30355. // might be shared by different series, series dimensions not
  30356. // really map to store dimensions.
  30357. this._updateDimOmitted(true);
  30358. };
  30359. return SeriesDataSchema;
  30360. }();
  30361. function isSeriesDataSchema(schema) {
  30362. return schema instanceof SeriesDataSchema;
  30363. }
  30364. function createDimNameMap(dimsDef) {
  30365. var dataDimNameMap = createHashMap();
  30366. for (var i = 0; i < (dimsDef || []).length; i++) {
  30367. var dimDefItemRaw = dimsDef[i];
  30368. var userDimName = isObject(dimDefItemRaw) ? dimDefItemRaw.name : dimDefItemRaw;
  30369. if (userDimName != null && dataDimNameMap.get(userDimName) == null) {
  30370. dataDimNameMap.set(userDimName, i);
  30371. }
  30372. }
  30373. return dataDimNameMap;
  30374. }
  30375. function ensureSourceDimNameMap(source) {
  30376. var innerSource = inner$4(source);
  30377. return innerSource.dimNameMap || (innerSource.dimNameMap = createDimNameMap(source.dimensionsDefine));
  30378. }
  30379. function shouldOmitUnusedDimensions(dimCount) {
  30380. return dimCount > 30;
  30381. }
  30382. var isObject$2 = isObject;
  30383. var map$1 = map;
  30384. var CtorInt32Array$1 = typeof Int32Array === 'undefined' ? Array : Int32Array;
  30385. // Use prefix to avoid index to be the same as otherIdList[idx],
  30386. // which will cause weird update animation.
  30387. var ID_PREFIX = 'e\0\0';
  30388. var INDEX_NOT_FOUND = -1;
  30389. // type SeriesDimensionIndex = DimensionIndex;
  30390. var TRANSFERABLE_PROPERTIES = ['hasItemOption', '_nameList', '_idList', '_invertedIndicesMap', '_dimSummary', 'userOutput', '_rawData', '_dimValueGetter', '_nameDimIdx', '_idDimIdx', '_nameRepeatCount'];
  30391. var CLONE_PROPERTIES = ['_approximateExtent'];
  30392. // -----------------------------
  30393. // Internal method declarations:
  30394. // -----------------------------
  30395. var prepareInvertedIndex;
  30396. var getId;
  30397. var getIdNameFromStore;
  30398. var normalizeDimensions;
  30399. var transferProperties;
  30400. var cloneListForMapAndSample;
  30401. var makeIdFromName;
  30402. var SeriesData = /** @class */function () {
  30403. /**
  30404. * @param dimensionsInput.dimensions
  30405. * For example, ['someDimName', {name: 'someDimName', type: 'someDimType'}, ...].
  30406. * Dimensions should be concrete names like x, y, z, lng, lat, angle, radius
  30407. */
  30408. function SeriesData(dimensionsInput, hostModel) {
  30409. this.type = 'list';
  30410. this._dimOmitted = false;
  30411. this._nameList = [];
  30412. this._idList = [];
  30413. // Models of data option is stored sparse for optimizing memory cost
  30414. // Never used yet (not used yet).
  30415. // private _optionModels: Model[] = [];
  30416. // Global visual properties after visual coding
  30417. this._visual = {};
  30418. // Global layout properties.
  30419. this._layout = {};
  30420. // Item visual properties after visual coding
  30421. this._itemVisuals = [];
  30422. // Item layout properties after layout
  30423. this._itemLayouts = [];
  30424. // Graphic elements
  30425. this._graphicEls = [];
  30426. // key: dim, value: extent
  30427. this._approximateExtent = {};
  30428. this._calculationInfo = {};
  30429. // Having detected that there is data item is non primitive type
  30430. // (in type `OptionDataItemObject`).
  30431. // Like `data: [ { value: xx, itemStyle: {...} }, ...]`
  30432. // At present it only happen in `SOURCE_FORMAT_ORIGINAL`.
  30433. this.hasItemOption = false;
  30434. // Methods that create a new list based on this list should be listed here.
  30435. // Notice that those method should `RETURN` the new list.
  30436. this.TRANSFERABLE_METHODS = ['cloneShallow', 'downSample', 'minmaxDownSample', 'lttbDownSample', 'map'];
  30437. // Methods that change indices of this list should be listed here.
  30438. this.CHANGABLE_METHODS = ['filterSelf', 'selectRange'];
  30439. this.DOWNSAMPLE_METHODS = ['downSample', 'minmaxDownSample', 'lttbDownSample'];
  30440. var dimensions;
  30441. var assignStoreDimIdx = false;
  30442. if (isSeriesDataSchema(dimensionsInput)) {
  30443. dimensions = dimensionsInput.dimensions;
  30444. this._dimOmitted = dimensionsInput.isDimensionOmitted();
  30445. this._schema = dimensionsInput;
  30446. } else {
  30447. assignStoreDimIdx = true;
  30448. dimensions = dimensionsInput;
  30449. }
  30450. dimensions = dimensions || ['x', 'y'];
  30451. var dimensionInfos = {};
  30452. var dimensionNames = [];
  30453. var invertedIndicesMap = {};
  30454. var needsHasOwn = false;
  30455. var emptyObj = {};
  30456. for (var i = 0; i < dimensions.length; i++) {
  30457. // Use the original dimensions[i], where other flag props may exists.
  30458. var dimInfoInput = dimensions[i];
  30459. var dimensionInfo = isString(dimInfoInput) ? new SeriesDimensionDefine({
  30460. name: dimInfoInput
  30461. }) : !(dimInfoInput instanceof SeriesDimensionDefine) ? new SeriesDimensionDefine(dimInfoInput) : dimInfoInput;
  30462. var dimensionName = dimensionInfo.name;
  30463. dimensionInfo.type = dimensionInfo.type || 'float';
  30464. if (!dimensionInfo.coordDim) {
  30465. dimensionInfo.coordDim = dimensionName;
  30466. dimensionInfo.coordDimIndex = 0;
  30467. }
  30468. var otherDims = dimensionInfo.otherDims = dimensionInfo.otherDims || {};
  30469. dimensionNames.push(dimensionName);
  30470. dimensionInfos[dimensionName] = dimensionInfo;
  30471. if (emptyObj[dimensionName] != null) {
  30472. needsHasOwn = true;
  30473. }
  30474. if (dimensionInfo.createInvertedIndices) {
  30475. invertedIndicesMap[dimensionName] = [];
  30476. }
  30477. var dimIdx = i;
  30478. if (isNumber(dimensionInfo.storeDimIndex)) {
  30479. dimIdx = dimensionInfo.storeDimIndex;
  30480. }
  30481. if (otherDims.itemName === 0) {
  30482. this._nameDimIdx = dimIdx;
  30483. }
  30484. if (otherDims.itemId === 0) {
  30485. this._idDimIdx = dimIdx;
  30486. }
  30487. if ("development" !== 'production') {
  30488. assert(assignStoreDimIdx || dimensionInfo.storeDimIndex >= 0);
  30489. }
  30490. if (assignStoreDimIdx) {
  30491. dimensionInfo.storeDimIndex = i;
  30492. }
  30493. }
  30494. this.dimensions = dimensionNames;
  30495. this._dimInfos = dimensionInfos;
  30496. this._initGetDimensionInfo(needsHasOwn);
  30497. this.hostModel = hostModel;
  30498. this._invertedIndicesMap = invertedIndicesMap;
  30499. if (this._dimOmitted) {
  30500. var dimIdxToName_1 = this._dimIdxToName = createHashMap();
  30501. each(dimensionNames, function (dimName) {
  30502. dimIdxToName_1.set(dimensionInfos[dimName].storeDimIndex, dimName);
  30503. });
  30504. }
  30505. }
  30506. /**
  30507. *
  30508. * Get concrete dimension name by dimension name or dimension index.
  30509. * If input a dimension name, do not validate whether the dimension name exits.
  30510. *
  30511. * @caution
  30512. * @param dim Must make sure the dimension is `SeriesDimensionLoose`.
  30513. * Because only those dimensions will have auto-generated dimension names if not
  30514. * have a user-specified name, and other dimensions will get a return of null/undefined.
  30515. *
  30516. * @notice Because of this reason, should better use `getDimensionIndex` instead, for examples:
  30517. * ```js
  30518. * const val = data.getStore().get(data.getDimensionIndex(dim), dataIdx);
  30519. * ```
  30520. *
  30521. * @return Concrete dim name.
  30522. */
  30523. SeriesData.prototype.getDimension = function (dim) {
  30524. var dimIdx = this._recognizeDimIndex(dim);
  30525. if (dimIdx == null) {
  30526. return dim;
  30527. }
  30528. dimIdx = dim;
  30529. if (!this._dimOmitted) {
  30530. return this.dimensions[dimIdx];
  30531. }
  30532. // Retrieve from series dimension definition because it probably contains
  30533. // generated dimension name (like 'x', 'y').
  30534. var dimName = this._dimIdxToName.get(dimIdx);
  30535. if (dimName != null) {
  30536. return dimName;
  30537. }
  30538. var sourceDimDef = this._schema.getSourceDimension(dimIdx);
  30539. if (sourceDimDef) {
  30540. return sourceDimDef.name;
  30541. }
  30542. };
  30543. /**
  30544. * Get dimension index in data store. Return -1 if not found.
  30545. * Can be used to index value from getRawValue.
  30546. */
  30547. SeriesData.prototype.getDimensionIndex = function (dim) {
  30548. var dimIdx = this._recognizeDimIndex(dim);
  30549. if (dimIdx != null) {
  30550. return dimIdx;
  30551. }
  30552. if (dim == null) {
  30553. return -1;
  30554. }
  30555. var dimInfo = this._getDimInfo(dim);
  30556. return dimInfo ? dimInfo.storeDimIndex : this._dimOmitted ? this._schema.getSourceDimensionIndex(dim) : -1;
  30557. };
  30558. /**
  30559. * The meanings of the input parameter `dim`:
  30560. *
  30561. * + If dim is a number (e.g., `1`), it means the index of the dimension.
  30562. * For example, `getDimension(0)` will return 'x' or 'lng' or 'radius'.
  30563. * + If dim is a number-like string (e.g., `"1"`):
  30564. * + If there is the same concrete dim name defined in `series.dimensions` or `dataset.dimensions`,
  30565. * it means that concrete name.
  30566. * + If not, it will be converted to a number, which means the index of the dimension.
  30567. * (why? because of the backward compatibility. We have been tolerating number-like string in
  30568. * dimension setting, although now it seems that it is not a good idea.)
  30569. * For example, `visualMap[i].dimension: "1"` is the same meaning as `visualMap[i].dimension: 1`,
  30570. * if no dimension name is defined as `"1"`.
  30571. * + If dim is a not-number-like string, it means the concrete dim name.
  30572. * For example, it can be be default name `"x"`, `"y"`, `"z"`, `"lng"`, `"lat"`, `"angle"`, `"radius"`,
  30573. * or customized in `dimensions` property of option like `"age"`.
  30574. *
  30575. * @return recognized `DimensionIndex`. Otherwise return null/undefined (means that dim is `DimensionName`).
  30576. */
  30577. SeriesData.prototype._recognizeDimIndex = function (dim) {
  30578. if (isNumber(dim)
  30579. // If being a number-like string but not being defined as a dimension name.
  30580. || dim != null && !isNaN(dim) && !this._getDimInfo(dim) && (!this._dimOmitted || this._schema.getSourceDimensionIndex(dim) < 0)) {
  30581. return +dim;
  30582. }
  30583. };
  30584. SeriesData.prototype._getStoreDimIndex = function (dim) {
  30585. var dimIdx = this.getDimensionIndex(dim);
  30586. if ("development" !== 'production') {
  30587. if (dimIdx == null) {
  30588. throw new Error('Unknown dimension ' + dim);
  30589. }
  30590. }
  30591. return dimIdx;
  30592. };
  30593. /**
  30594. * Get type and calculation info of particular dimension
  30595. * @param dim
  30596. * Dimension can be concrete names like x, y, z, lng, lat, angle, radius
  30597. * Or a ordinal number. For example getDimensionInfo(0) will return 'x' or 'lng' or 'radius'
  30598. */
  30599. SeriesData.prototype.getDimensionInfo = function (dim) {
  30600. // Do not clone, because there may be categories in dimInfo.
  30601. return this._getDimInfo(this.getDimension(dim));
  30602. };
  30603. SeriesData.prototype._initGetDimensionInfo = function (needsHasOwn) {
  30604. var dimensionInfos = this._dimInfos;
  30605. this._getDimInfo = needsHasOwn ? function (dimName) {
  30606. return dimensionInfos.hasOwnProperty(dimName) ? dimensionInfos[dimName] : undefined;
  30607. } : function (dimName) {
  30608. return dimensionInfos[dimName];
  30609. };
  30610. };
  30611. /**
  30612. * concrete dimension name list on coord.
  30613. */
  30614. SeriesData.prototype.getDimensionsOnCoord = function () {
  30615. return this._dimSummary.dataDimsOnCoord.slice();
  30616. };
  30617. SeriesData.prototype.mapDimension = function (coordDim, idx) {
  30618. var dimensionsSummary = this._dimSummary;
  30619. if (idx == null) {
  30620. return dimensionsSummary.encodeFirstDimNotExtra[coordDim];
  30621. }
  30622. var dims = dimensionsSummary.encode[coordDim];
  30623. return dims ? dims[idx] : null;
  30624. };
  30625. SeriesData.prototype.mapDimensionsAll = function (coordDim) {
  30626. var dimensionsSummary = this._dimSummary;
  30627. var dims = dimensionsSummary.encode[coordDim];
  30628. return (dims || []).slice();
  30629. };
  30630. SeriesData.prototype.getStore = function () {
  30631. return this._store;
  30632. };
  30633. /**
  30634. * Initialize from data
  30635. * @param data source or data or data store.
  30636. * @param nameList The name of a datum is used on data diff and
  30637. * default label/tooltip.
  30638. * A name can be specified in encode.itemName,
  30639. * or dataItem.name (only for series option data),
  30640. * or provided in nameList from outside.
  30641. */
  30642. SeriesData.prototype.initData = function (data, nameList, dimValueGetter) {
  30643. var _this = this;
  30644. var store;
  30645. if (data instanceof DataStore) {
  30646. store = data;
  30647. }
  30648. if (!store) {
  30649. var dimensions = this.dimensions;
  30650. var provider = isSourceInstance(data) || isArrayLike(data) ? new DefaultDataProvider(data, dimensions.length) : data;
  30651. store = new DataStore();
  30652. var dimensionInfos = map$1(dimensions, function (dimName) {
  30653. return {
  30654. type: _this._dimInfos[dimName].type,
  30655. property: dimName
  30656. };
  30657. });
  30658. store.initData(provider, dimensionInfos, dimValueGetter);
  30659. }
  30660. this._store = store;
  30661. // Reset
  30662. this._nameList = (nameList || []).slice();
  30663. this._idList = [];
  30664. this._nameRepeatCount = {};
  30665. this._doInit(0, store.count());
  30666. // Cache summary info for fast visit. See "dimensionHelper".
  30667. // Needs to be initialized after store is prepared.
  30668. this._dimSummary = summarizeDimensions(this, this._schema);
  30669. this.userOutput = this._dimSummary.userOutput;
  30670. };
  30671. /**
  30672. * Caution: Can be only called on raw data (before `this._indices` created).
  30673. */
  30674. SeriesData.prototype.appendData = function (data) {
  30675. var range = this._store.appendData(data);
  30676. this._doInit(range[0], range[1]);
  30677. };
  30678. /**
  30679. * Caution: Can be only called on raw data (before `this._indices` created).
  30680. * This method does not modify `rawData` (`dataProvider`), but only
  30681. * add values to store.
  30682. *
  30683. * The final count will be increased by `Math.max(values.length, names.length)`.
  30684. *
  30685. * @param values That is the SourceType: 'arrayRows', like
  30686. * [
  30687. * [12, 33, 44],
  30688. * [NaN, 43, 1],
  30689. * ['-', 'asdf', 0]
  30690. * ]
  30691. * Each item is exactly corresponding to a dimension.
  30692. */
  30693. SeriesData.prototype.appendValues = function (values, names) {
  30694. var _a = this._store.appendValues(values, names && names.length),
  30695. start = _a.start,
  30696. end = _a.end;
  30697. var shouldMakeIdFromName = this._shouldMakeIdFromName();
  30698. this._updateOrdinalMeta();
  30699. if (names) {
  30700. for (var idx = start; idx < end; idx++) {
  30701. var sourceIdx = idx - start;
  30702. this._nameList[idx] = names[sourceIdx];
  30703. if (shouldMakeIdFromName) {
  30704. makeIdFromName(this, idx);
  30705. }
  30706. }
  30707. }
  30708. };
  30709. SeriesData.prototype._updateOrdinalMeta = function () {
  30710. var store = this._store;
  30711. var dimensions = this.dimensions;
  30712. for (var i = 0; i < dimensions.length; i++) {
  30713. var dimInfo = this._dimInfos[dimensions[i]];
  30714. if (dimInfo.ordinalMeta) {
  30715. store.collectOrdinalMeta(dimInfo.storeDimIndex, dimInfo.ordinalMeta);
  30716. }
  30717. }
  30718. };
  30719. SeriesData.prototype._shouldMakeIdFromName = function () {
  30720. var provider = this._store.getProvider();
  30721. return this._idDimIdx == null && provider.getSource().sourceFormat !== SOURCE_FORMAT_TYPED_ARRAY && !provider.fillStorage;
  30722. };
  30723. SeriesData.prototype._doInit = function (start, end) {
  30724. if (start >= end) {
  30725. return;
  30726. }
  30727. var store = this._store;
  30728. var provider = store.getProvider();
  30729. this._updateOrdinalMeta();
  30730. var nameList = this._nameList;
  30731. var idList = this._idList;
  30732. var sourceFormat = provider.getSource().sourceFormat;
  30733. var isFormatOriginal = sourceFormat === SOURCE_FORMAT_ORIGINAL;
  30734. // Each data item is value
  30735. // [1, 2]
  30736. // 2
  30737. // Bar chart, line chart which uses category axis
  30738. // only gives the 'y' value. 'x' value is the indices of category
  30739. // Use a tempValue to normalize the value to be a (x, y) value
  30740. // If dataItem is {name: ...} or {id: ...}, it has highest priority.
  30741. // This kind of ids and names are always stored `_nameList` and `_idList`.
  30742. if (isFormatOriginal && !provider.pure) {
  30743. var sharedDataItem = [];
  30744. for (var idx = start; idx < end; idx++) {
  30745. // NOTICE: Try not to write things into dataItem
  30746. var dataItem = provider.getItem(idx, sharedDataItem);
  30747. if (!this.hasItemOption && isDataItemOption(dataItem)) {
  30748. this.hasItemOption = true;
  30749. }
  30750. if (dataItem) {
  30751. var itemName = dataItem.name;
  30752. if (nameList[idx] == null && itemName != null) {
  30753. nameList[idx] = convertOptionIdName(itemName, null);
  30754. }
  30755. var itemId = dataItem.id;
  30756. if (idList[idx] == null && itemId != null) {
  30757. idList[idx] = convertOptionIdName(itemId, null);
  30758. }
  30759. }
  30760. }
  30761. }
  30762. if (this._shouldMakeIdFromName()) {
  30763. for (var idx = start; idx < end; idx++) {
  30764. makeIdFromName(this, idx);
  30765. }
  30766. }
  30767. prepareInvertedIndex(this);
  30768. };
  30769. /**
  30770. * PENDING: In fact currently this function is only used to short-circuit
  30771. * the calling of `scale.unionExtentFromData` when data have been filtered by modules
  30772. * like "dataZoom". `scale.unionExtentFromData` is used to calculate data extent for series on
  30773. * an axis, but if a "axis related data filter module" is used, the extent of the axis have
  30774. * been fixed and no need to calling `scale.unionExtentFromData` actually.
  30775. * But if we add "custom data filter" in future, which is not "axis related", this method may
  30776. * be still needed.
  30777. *
  30778. * Optimize for the scenario that data is filtered by a given extent.
  30779. * Consider that if data amount is more than hundreds of thousand,
  30780. * extent calculation will cost more than 10ms and the cache will
  30781. * be erased because of the filtering.
  30782. */
  30783. SeriesData.prototype.getApproximateExtent = function (dim) {
  30784. return this._approximateExtent[dim] || this._store.getDataExtent(this._getStoreDimIndex(dim));
  30785. };
  30786. /**
  30787. * Calculate extent on a filtered data might be time consuming.
  30788. * Approximate extent is only used for: calculate extent of filtered data outside.
  30789. */
  30790. SeriesData.prototype.setApproximateExtent = function (extent, dim) {
  30791. dim = this.getDimension(dim);
  30792. this._approximateExtent[dim] = extent.slice();
  30793. };
  30794. SeriesData.prototype.getCalculationInfo = function (key) {
  30795. return this._calculationInfo[key];
  30796. };
  30797. SeriesData.prototype.setCalculationInfo = function (key, value) {
  30798. isObject$2(key) ? extend(this._calculationInfo, key) : this._calculationInfo[key] = value;
  30799. };
  30800. /**
  30801. * @return Never be null/undefined. `number` will be converted to string. Because:
  30802. * In most cases, name is used in display, where returning a string is more convenient.
  30803. * In other cases, name is used in query (see `indexOfName`), where we can keep the
  30804. * rule that name `2` equals to name `'2'`.
  30805. */
  30806. SeriesData.prototype.getName = function (idx) {
  30807. var rawIndex = this.getRawIndex(idx);
  30808. var name = this._nameList[rawIndex];
  30809. if (name == null && this._nameDimIdx != null) {
  30810. name = getIdNameFromStore(this, this._nameDimIdx, rawIndex);
  30811. }
  30812. if (name == null) {
  30813. name = '';
  30814. }
  30815. return name;
  30816. };
  30817. SeriesData.prototype._getCategory = function (dimIdx, idx) {
  30818. var ordinal = this._store.get(dimIdx, idx);
  30819. var ordinalMeta = this._store.getOrdinalMeta(dimIdx);
  30820. if (ordinalMeta) {
  30821. return ordinalMeta.categories[ordinal];
  30822. }
  30823. return ordinal;
  30824. };
  30825. /**
  30826. * @return Never null/undefined. `number` will be converted to string. Because:
  30827. * In all cases having encountered at present, id is used in making diff comparison, which
  30828. * are usually based on hash map. We can keep the rule that the internal id are always string
  30829. * (treat `2` is the same as `'2'`) to make the related logic simple.
  30830. */
  30831. SeriesData.prototype.getId = function (idx) {
  30832. return getId(this, this.getRawIndex(idx));
  30833. };
  30834. SeriesData.prototype.count = function () {
  30835. return this._store.count();
  30836. };
  30837. /**
  30838. * Get value. Return NaN if idx is out of range.
  30839. *
  30840. * @notice Should better to use `data.getStore().get(dimIndex, dataIdx)` instead.
  30841. */
  30842. SeriesData.prototype.get = function (dim, idx) {
  30843. var store = this._store;
  30844. var dimInfo = this._dimInfos[dim];
  30845. if (dimInfo) {
  30846. return store.get(dimInfo.storeDimIndex, idx);
  30847. }
  30848. };
  30849. /**
  30850. * @notice Should better to use `data.getStore().getByRawIndex(dimIndex, dataIdx)` instead.
  30851. */
  30852. SeriesData.prototype.getByRawIndex = function (dim, rawIdx) {
  30853. var store = this._store;
  30854. var dimInfo = this._dimInfos[dim];
  30855. if (dimInfo) {
  30856. return store.getByRawIndex(dimInfo.storeDimIndex, rawIdx);
  30857. }
  30858. };
  30859. SeriesData.prototype.getIndices = function () {
  30860. return this._store.getIndices();
  30861. };
  30862. SeriesData.prototype.getDataExtent = function (dim) {
  30863. return this._store.getDataExtent(this._getStoreDimIndex(dim));
  30864. };
  30865. SeriesData.prototype.getSum = function (dim) {
  30866. return this._store.getSum(this._getStoreDimIndex(dim));
  30867. };
  30868. SeriesData.prototype.getMedian = function (dim) {
  30869. return this._store.getMedian(this._getStoreDimIndex(dim));
  30870. };
  30871. SeriesData.prototype.getValues = function (dimensions, idx) {
  30872. var _this = this;
  30873. var store = this._store;
  30874. return isArray(dimensions) ? store.getValues(map$1(dimensions, function (dim) {
  30875. return _this._getStoreDimIndex(dim);
  30876. }), idx) : store.getValues(dimensions);
  30877. };
  30878. /**
  30879. * If value is NaN. Including '-'
  30880. * Only check the coord dimensions.
  30881. */
  30882. SeriesData.prototype.hasValue = function (idx) {
  30883. var dataDimIndicesOnCoord = this._dimSummary.dataDimIndicesOnCoord;
  30884. for (var i = 0, len = dataDimIndicesOnCoord.length; i < len; i++) {
  30885. // Ordinal type originally can be string or number.
  30886. // But when an ordinal type is used on coord, it can
  30887. // not be string but only number. So we can also use isNaN.
  30888. if (isNaN(this._store.get(dataDimIndicesOnCoord[i], idx))) {
  30889. return false;
  30890. }
  30891. }
  30892. return true;
  30893. };
  30894. /**
  30895. * Retrieve the index with given name
  30896. */
  30897. SeriesData.prototype.indexOfName = function (name) {
  30898. for (var i = 0, len = this._store.count(); i < len; i++) {
  30899. if (this.getName(i) === name) {
  30900. return i;
  30901. }
  30902. }
  30903. return -1;
  30904. };
  30905. SeriesData.prototype.getRawIndex = function (idx) {
  30906. return this._store.getRawIndex(idx);
  30907. };
  30908. SeriesData.prototype.indexOfRawIndex = function (rawIndex) {
  30909. return this._store.indexOfRawIndex(rawIndex);
  30910. };
  30911. /**
  30912. * Only support the dimension which inverted index created.
  30913. * Do not support other cases until required.
  30914. * @param dim concrete dim
  30915. * @param value ordinal index
  30916. * @return rawIndex
  30917. */
  30918. SeriesData.prototype.rawIndexOf = function (dim, value) {
  30919. var invertedIndices = dim && this._invertedIndicesMap[dim];
  30920. if ("development" !== 'production') {
  30921. if (!invertedIndices) {
  30922. throw new Error('Do not supported yet');
  30923. }
  30924. }
  30925. var rawIndex = invertedIndices && invertedIndices[value];
  30926. if (rawIndex == null || isNaN(rawIndex)) {
  30927. return INDEX_NOT_FOUND;
  30928. }
  30929. return rawIndex;
  30930. };
  30931. SeriesData.prototype.each = function (dims, cb, ctx) {
  30932. if (isFunction(dims)) {
  30933. ctx = cb;
  30934. cb = dims;
  30935. dims = [];
  30936. }
  30937. // ctxCompat just for compat echarts3
  30938. var fCtx = ctx || this;
  30939. var dimIndices = map$1(normalizeDimensions(dims), this._getStoreDimIndex, this);
  30940. this._store.each(dimIndices, fCtx ? bind(cb, fCtx) : cb);
  30941. };
  30942. SeriesData.prototype.filterSelf = function (dims, cb, ctx) {
  30943. if (isFunction(dims)) {
  30944. ctx = cb;
  30945. cb = dims;
  30946. dims = [];
  30947. }
  30948. // ctxCompat just for compat echarts3
  30949. var fCtx = ctx || this;
  30950. var dimIndices = map$1(normalizeDimensions(dims), this._getStoreDimIndex, this);
  30951. this._store = this._store.filter(dimIndices, fCtx ? bind(cb, fCtx) : cb);
  30952. return this;
  30953. };
  30954. /**
  30955. * Select data in range. (For optimization of filter)
  30956. * (Manually inline code, support 5 million data filtering in data zoom.)
  30957. */
  30958. SeriesData.prototype.selectRange = function (range) {
  30959. var _this = this;
  30960. var innerRange = {};
  30961. var dims = keys(range);
  30962. each(dims, function (dim) {
  30963. var dimIdx = _this._getStoreDimIndex(dim);
  30964. innerRange[dimIdx] = range[dim];
  30965. });
  30966. this._store = this._store.selectRange(innerRange);
  30967. return this;
  30968. };
  30969. /* eslint-enable max-len */
  30970. SeriesData.prototype.mapArray = function (dims, cb, ctx) {
  30971. if (isFunction(dims)) {
  30972. ctx = cb;
  30973. cb = dims;
  30974. dims = [];
  30975. }
  30976. // ctxCompat just for compat echarts3
  30977. ctx = ctx || this;
  30978. var result = [];
  30979. this.each(dims, function () {
  30980. result.push(cb && cb.apply(this, arguments));
  30981. }, ctx);
  30982. return result;
  30983. };
  30984. SeriesData.prototype.map = function (dims, cb, ctx, ctxCompat) {
  30985. // ctxCompat just for compat echarts3
  30986. var fCtx = ctx || ctxCompat || this;
  30987. var dimIndices = map$1(normalizeDimensions(dims), this._getStoreDimIndex, this);
  30988. var list = cloneListForMapAndSample(this);
  30989. list._store = this._store.map(dimIndices, fCtx ? bind(cb, fCtx) : cb);
  30990. return list;
  30991. };
  30992. SeriesData.prototype.modify = function (dims, cb, ctx, ctxCompat) {
  30993. var _this = this;
  30994. // ctxCompat just for compat echarts3
  30995. var fCtx = ctx || ctxCompat || this;
  30996. if ("development" !== 'production') {
  30997. each(normalizeDimensions(dims), function (dim) {
  30998. var dimInfo = _this.getDimensionInfo(dim);
  30999. if (!dimInfo.isCalculationCoord) {
  31000. console.error('Danger: only stack dimension can be modified');
  31001. }
  31002. });
  31003. }
  31004. var dimIndices = map$1(normalizeDimensions(dims), this._getStoreDimIndex, this);
  31005. // If do shallow clone here, if there are too many stacked series,
  31006. // it still cost lots of memory, because `_store.dimensions` are not shared.
  31007. // We should consider there probably be shallow clone happen in each series
  31008. // in consequent filter/map.
  31009. this._store.modify(dimIndices, fCtx ? bind(cb, fCtx) : cb);
  31010. };
  31011. /**
  31012. * Large data down sampling on given dimension
  31013. * @param sampleIndex Sample index for name and id
  31014. */
  31015. SeriesData.prototype.downSample = function (dimension, rate, sampleValue, sampleIndex) {
  31016. var list = cloneListForMapAndSample(this);
  31017. list._store = this._store.downSample(this._getStoreDimIndex(dimension), rate, sampleValue, sampleIndex);
  31018. return list;
  31019. };
  31020. /**
  31021. * Large data down sampling using min-max
  31022. * @param {string} valueDimension
  31023. * @param {number} rate
  31024. */
  31025. SeriesData.prototype.minmaxDownSample = function (valueDimension, rate) {
  31026. var list = cloneListForMapAndSample(this);
  31027. list._store = this._store.minmaxDownSample(this._getStoreDimIndex(valueDimension), rate);
  31028. return list;
  31029. };
  31030. /**
  31031. * Large data down sampling using largest-triangle-three-buckets
  31032. * @param {string} valueDimension
  31033. * @param {number} targetCount
  31034. */
  31035. SeriesData.prototype.lttbDownSample = function (valueDimension, rate) {
  31036. var list = cloneListForMapAndSample(this);
  31037. list._store = this._store.lttbDownSample(this._getStoreDimIndex(valueDimension), rate);
  31038. return list;
  31039. };
  31040. SeriesData.prototype.getRawDataItem = function (idx) {
  31041. return this._store.getRawDataItem(idx);
  31042. };
  31043. /**
  31044. * Get model of one data item.
  31045. */
  31046. // TODO: Type of data item
  31047. SeriesData.prototype.getItemModel = function (idx) {
  31048. var hostModel = this.hostModel;
  31049. var dataItem = this.getRawDataItem(idx);
  31050. return new Model(dataItem, hostModel, hostModel && hostModel.ecModel);
  31051. };
  31052. /**
  31053. * Create a data differ
  31054. */
  31055. SeriesData.prototype.diff = function (otherList) {
  31056. var thisList = this;
  31057. return new DataDiffer(otherList ? otherList.getStore().getIndices() : [], this.getStore().getIndices(), function (idx) {
  31058. return getId(otherList, idx);
  31059. }, function (idx) {
  31060. return getId(thisList, idx);
  31061. });
  31062. };
  31063. /**
  31064. * Get visual property.
  31065. */
  31066. SeriesData.prototype.getVisual = function (key) {
  31067. var visual = this._visual;
  31068. return visual && visual[key];
  31069. };
  31070. SeriesData.prototype.setVisual = function (kvObj, val) {
  31071. this._visual = this._visual || {};
  31072. if (isObject$2(kvObj)) {
  31073. extend(this._visual, kvObj);
  31074. } else {
  31075. this._visual[kvObj] = val;
  31076. }
  31077. };
  31078. /**
  31079. * Get visual property of single data item
  31080. */
  31081. // eslint-disable-next-line
  31082. SeriesData.prototype.getItemVisual = function (idx, key) {
  31083. var itemVisual = this._itemVisuals[idx];
  31084. var val = itemVisual && itemVisual[key];
  31085. if (val == null) {
  31086. // Use global visual property
  31087. return this.getVisual(key);
  31088. }
  31089. return val;
  31090. };
  31091. /**
  31092. * If exists visual property of single data item
  31093. */
  31094. SeriesData.prototype.hasItemVisual = function () {
  31095. return this._itemVisuals.length > 0;
  31096. };
  31097. /**
  31098. * Make sure itemVisual property is unique
  31099. */
  31100. // TODO: use key to save visual to reduce memory.
  31101. SeriesData.prototype.ensureUniqueItemVisual = function (idx, key) {
  31102. var itemVisuals = this._itemVisuals;
  31103. var itemVisual = itemVisuals[idx];
  31104. if (!itemVisual) {
  31105. itemVisual = itemVisuals[idx] = {};
  31106. }
  31107. var val = itemVisual[key];
  31108. if (val == null) {
  31109. val = this.getVisual(key);
  31110. // TODO Performance?
  31111. if (isArray(val)) {
  31112. val = val.slice();
  31113. } else if (isObject$2(val)) {
  31114. val = extend({}, val);
  31115. }
  31116. itemVisual[key] = val;
  31117. }
  31118. return val;
  31119. };
  31120. // eslint-disable-next-line
  31121. SeriesData.prototype.setItemVisual = function (idx, key, value) {
  31122. var itemVisual = this._itemVisuals[idx] || {};
  31123. this._itemVisuals[idx] = itemVisual;
  31124. if (isObject$2(key)) {
  31125. extend(itemVisual, key);
  31126. } else {
  31127. itemVisual[key] = value;
  31128. }
  31129. };
  31130. /**
  31131. * Clear itemVisuals and list visual.
  31132. */
  31133. SeriesData.prototype.clearAllVisual = function () {
  31134. this._visual = {};
  31135. this._itemVisuals = [];
  31136. };
  31137. SeriesData.prototype.setLayout = function (key, val) {
  31138. isObject$2(key) ? extend(this._layout, key) : this._layout[key] = val;
  31139. };
  31140. /**
  31141. * Get layout property.
  31142. */
  31143. SeriesData.prototype.getLayout = function (key) {
  31144. return this._layout[key];
  31145. };
  31146. /**
  31147. * Get layout of single data item
  31148. */
  31149. SeriesData.prototype.getItemLayout = function (idx) {
  31150. return this._itemLayouts[idx];
  31151. };
  31152. /**
  31153. * Set layout of single data item
  31154. */
  31155. SeriesData.prototype.setItemLayout = function (idx, layout, merge) {
  31156. this._itemLayouts[idx] = merge ? extend(this._itemLayouts[idx] || {}, layout) : layout;
  31157. };
  31158. /**
  31159. * Clear all layout of single data item
  31160. */
  31161. SeriesData.prototype.clearItemLayouts = function () {
  31162. this._itemLayouts.length = 0;
  31163. };
  31164. /**
  31165. * Set graphic element relative to data. It can be set as null
  31166. */
  31167. SeriesData.prototype.setItemGraphicEl = function (idx, el) {
  31168. var seriesIndex = this.hostModel && this.hostModel.seriesIndex;
  31169. setCommonECData(seriesIndex, this.dataType, idx, el);
  31170. this._graphicEls[idx] = el;
  31171. };
  31172. SeriesData.prototype.getItemGraphicEl = function (idx) {
  31173. return this._graphicEls[idx];
  31174. };
  31175. SeriesData.prototype.eachItemGraphicEl = function (cb, context) {
  31176. each(this._graphicEls, function (el, idx) {
  31177. if (el) {
  31178. cb && cb.call(context, el, idx);
  31179. }
  31180. });
  31181. };
  31182. /**
  31183. * Shallow clone a new list except visual and layout properties, and graph elements.
  31184. * New list only change the indices.
  31185. */
  31186. SeriesData.prototype.cloneShallow = function (list) {
  31187. if (!list) {
  31188. list = new SeriesData(this._schema ? this._schema : map$1(this.dimensions, this._getDimInfo, this), this.hostModel);
  31189. }
  31190. transferProperties(list, this);
  31191. list._store = this._store;
  31192. return list;
  31193. };
  31194. /**
  31195. * Wrap some method to add more feature
  31196. */
  31197. SeriesData.prototype.wrapMethod = function (methodName, injectFunction) {
  31198. var originalMethod = this[methodName];
  31199. if (!isFunction(originalMethod)) {
  31200. return;
  31201. }
  31202. this.__wrappedMethods = this.__wrappedMethods || [];
  31203. this.__wrappedMethods.push(methodName);
  31204. this[methodName] = function () {
  31205. var res = originalMethod.apply(this, arguments);
  31206. return injectFunction.apply(this, [res].concat(slice(arguments)));
  31207. };
  31208. };
  31209. // ----------------------------------------------------------
  31210. // A work around for internal method visiting private member.
  31211. // ----------------------------------------------------------
  31212. SeriesData.internalField = function () {
  31213. prepareInvertedIndex = function (data) {
  31214. var invertedIndicesMap = data._invertedIndicesMap;
  31215. each(invertedIndicesMap, function (invertedIndices, dim) {
  31216. var dimInfo = data._dimInfos[dim];
  31217. // Currently, only dimensions that has ordinalMeta can create inverted indices.
  31218. var ordinalMeta = dimInfo.ordinalMeta;
  31219. var store = data._store;
  31220. if (ordinalMeta) {
  31221. invertedIndices = invertedIndicesMap[dim] = new CtorInt32Array$1(ordinalMeta.categories.length);
  31222. // The default value of TypedArray is 0. To avoid miss
  31223. // mapping to 0, we should set it as INDEX_NOT_FOUND.
  31224. for (var i = 0; i < invertedIndices.length; i++) {
  31225. invertedIndices[i] = INDEX_NOT_FOUND;
  31226. }
  31227. for (var i = 0; i < store.count(); i++) {
  31228. // Only support the case that all values are distinct.
  31229. invertedIndices[store.get(dimInfo.storeDimIndex, i)] = i;
  31230. }
  31231. }
  31232. });
  31233. };
  31234. getIdNameFromStore = function (data, dimIdx, idx) {
  31235. return convertOptionIdName(data._getCategory(dimIdx, idx), null);
  31236. };
  31237. /**
  31238. * @see the comment of `List['getId']`.
  31239. */
  31240. getId = function (data, rawIndex) {
  31241. var id = data._idList[rawIndex];
  31242. if (id == null && data._idDimIdx != null) {
  31243. id = getIdNameFromStore(data, data._idDimIdx, rawIndex);
  31244. }
  31245. if (id == null) {
  31246. id = ID_PREFIX + rawIndex;
  31247. }
  31248. return id;
  31249. };
  31250. normalizeDimensions = function (dimensions) {
  31251. if (!isArray(dimensions)) {
  31252. dimensions = dimensions != null ? [dimensions] : [];
  31253. }
  31254. return dimensions;
  31255. };
  31256. /**
  31257. * Data in excludeDimensions is copied, otherwise transferred.
  31258. */
  31259. cloneListForMapAndSample = function (original) {
  31260. var list = new SeriesData(original._schema ? original._schema : map$1(original.dimensions, original._getDimInfo, original), original.hostModel);
  31261. // FIXME If needs stackedOn, value may already been stacked
  31262. transferProperties(list, original);
  31263. return list;
  31264. };
  31265. transferProperties = function (target, source) {
  31266. each(TRANSFERABLE_PROPERTIES.concat(source.__wrappedMethods || []), function (propName) {
  31267. if (source.hasOwnProperty(propName)) {
  31268. target[propName] = source[propName];
  31269. }
  31270. });
  31271. target.__wrappedMethods = source.__wrappedMethods;
  31272. each(CLONE_PROPERTIES, function (propName) {
  31273. target[propName] = clone(source[propName]);
  31274. });
  31275. target._calculationInfo = extend({}, source._calculationInfo);
  31276. };
  31277. makeIdFromName = function (data, idx) {
  31278. var nameList = data._nameList;
  31279. var idList = data._idList;
  31280. var nameDimIdx = data._nameDimIdx;
  31281. var idDimIdx = data._idDimIdx;
  31282. var name = nameList[idx];
  31283. var id = idList[idx];
  31284. if (name == null && nameDimIdx != null) {
  31285. nameList[idx] = name = getIdNameFromStore(data, nameDimIdx, idx);
  31286. }
  31287. if (id == null && idDimIdx != null) {
  31288. idList[idx] = id = getIdNameFromStore(data, idDimIdx, idx);
  31289. }
  31290. if (id == null && name != null) {
  31291. var nameRepeatCount = data._nameRepeatCount;
  31292. var nmCnt = nameRepeatCount[name] = (nameRepeatCount[name] || 0) + 1;
  31293. id = name;
  31294. if (nmCnt > 1) {
  31295. id += '__ec__' + nmCnt;
  31296. }
  31297. idList[idx] = id;
  31298. }
  31299. };
  31300. }();
  31301. return SeriesData;
  31302. }();
  31303. /**
  31304. * For outside usage compat (like echarts-gl are using it).
  31305. */
  31306. function createDimensions(source, opt) {
  31307. return prepareSeriesDataSchema(source, opt).dimensions;
  31308. }
  31309. /**
  31310. * This method builds the relationship between:
  31311. * + "what the coord sys or series requires (see `coordDimensions`)",
  31312. * + "what the user defines (in `encode` and `dimensions`, see `opt.dimensionsDefine` and `opt.encodeDefine`)"
  31313. * + "what the data source provids (see `source`)".
  31314. *
  31315. * Some guess strategy will be adapted if user does not define something.
  31316. * If no 'value' dimension specified, the first no-named dimension will be
  31317. * named as 'value'.
  31318. *
  31319. * @return The results are always sorted by `storeDimIndex` asc.
  31320. */
  31321. function prepareSeriesDataSchema(
  31322. // TODO: TYPE completeDimensions type
  31323. source, opt) {
  31324. if (!isSourceInstance(source)) {
  31325. source = createSourceFromSeriesDataOption(source);
  31326. }
  31327. opt = opt || {};
  31328. var sysDims = opt.coordDimensions || [];
  31329. var dimsDef = opt.dimensionsDefine || source.dimensionsDefine || [];
  31330. var coordDimNameMap = createHashMap();
  31331. var resultList = [];
  31332. var dimCount = getDimCount(source, sysDims, dimsDef, opt.dimensionsCount);
  31333. // Try to ignore unused dimensions if sharing a high dimension datastore
  31334. // 30 is an experience value.
  31335. var omitUnusedDimensions = opt.canOmitUnusedDimensions && shouldOmitUnusedDimensions(dimCount);
  31336. var isUsingSourceDimensionsDef = dimsDef === source.dimensionsDefine;
  31337. var dataDimNameMap = isUsingSourceDimensionsDef ? ensureSourceDimNameMap(source) : createDimNameMap(dimsDef);
  31338. var encodeDef = opt.encodeDefine;
  31339. if (!encodeDef && opt.encodeDefaulter) {
  31340. encodeDef = opt.encodeDefaulter(source, dimCount);
  31341. }
  31342. var encodeDefMap = createHashMap(encodeDef);
  31343. var indicesMap = new CtorInt32Array(dimCount);
  31344. for (var i = 0; i < indicesMap.length; i++) {
  31345. indicesMap[i] = -1;
  31346. }
  31347. function getResultItem(dimIdx) {
  31348. var idx = indicesMap[dimIdx];
  31349. if (idx < 0) {
  31350. var dimDefItemRaw = dimsDef[dimIdx];
  31351. var dimDefItem = isObject(dimDefItemRaw) ? dimDefItemRaw : {
  31352. name: dimDefItemRaw
  31353. };
  31354. var resultItem = new SeriesDimensionDefine();
  31355. var userDimName = dimDefItem.name;
  31356. if (userDimName != null && dataDimNameMap.get(userDimName) != null) {
  31357. // Only if `series.dimensions` is defined in option
  31358. // displayName, will be set, and dimension will be displayed vertically in
  31359. // tooltip by default.
  31360. resultItem.name = resultItem.displayName = userDimName;
  31361. }
  31362. dimDefItem.type != null && (resultItem.type = dimDefItem.type);
  31363. dimDefItem.displayName != null && (resultItem.displayName = dimDefItem.displayName);
  31364. var newIdx = resultList.length;
  31365. indicesMap[dimIdx] = newIdx;
  31366. resultItem.storeDimIndex = dimIdx;
  31367. resultList.push(resultItem);
  31368. return resultItem;
  31369. }
  31370. return resultList[idx];
  31371. }
  31372. if (!omitUnusedDimensions) {
  31373. for (var i = 0; i < dimCount; i++) {
  31374. getResultItem(i);
  31375. }
  31376. }
  31377. // Set `coordDim` and `coordDimIndex` by `encodeDefMap` and normalize `encodeDefMap`.
  31378. encodeDefMap.each(function (dataDimsRaw, coordDim) {
  31379. var dataDims = normalizeToArray(dataDimsRaw).slice();
  31380. // Note: It is allowed that `dataDims.length` is `0`, e.g., options is
  31381. // `{encode: {x: -1, y: 1}}`. Should not filter anything in
  31382. // this case.
  31383. if (dataDims.length === 1 && !isString(dataDims[0]) && dataDims[0] < 0) {
  31384. encodeDefMap.set(coordDim, false);
  31385. return;
  31386. }
  31387. var validDataDims = encodeDefMap.set(coordDim, []);
  31388. each(dataDims, function (resultDimIdxOrName, idx) {
  31389. // The input resultDimIdx can be dim name or index.
  31390. var resultDimIdx = isString(resultDimIdxOrName) ? dataDimNameMap.get(resultDimIdxOrName) : resultDimIdxOrName;
  31391. if (resultDimIdx != null && resultDimIdx < dimCount) {
  31392. validDataDims[idx] = resultDimIdx;
  31393. applyDim(getResultItem(resultDimIdx), coordDim, idx);
  31394. }
  31395. });
  31396. });
  31397. // Apply templates and default order from `sysDims`.
  31398. var availDimIdx = 0;
  31399. each(sysDims, function (sysDimItemRaw) {
  31400. var coordDim;
  31401. var sysDimItemDimsDef;
  31402. var sysDimItemOtherDims;
  31403. var sysDimItem;
  31404. if (isString(sysDimItemRaw)) {
  31405. coordDim = sysDimItemRaw;
  31406. sysDimItem = {};
  31407. } else {
  31408. sysDimItem = sysDimItemRaw;
  31409. coordDim = sysDimItem.name;
  31410. var ordinalMeta = sysDimItem.ordinalMeta;
  31411. sysDimItem.ordinalMeta = null;
  31412. sysDimItem = extend({}, sysDimItem);
  31413. sysDimItem.ordinalMeta = ordinalMeta;
  31414. // `coordDimIndex` should not be set directly.
  31415. sysDimItemDimsDef = sysDimItem.dimsDef;
  31416. sysDimItemOtherDims = sysDimItem.otherDims;
  31417. sysDimItem.name = sysDimItem.coordDim = sysDimItem.coordDimIndex = sysDimItem.dimsDef = sysDimItem.otherDims = null;
  31418. }
  31419. var dataDims = encodeDefMap.get(coordDim);
  31420. // negative resultDimIdx means no need to mapping.
  31421. if (dataDims === false) {
  31422. return;
  31423. }
  31424. dataDims = normalizeToArray(dataDims);
  31425. // dimensions provides default dim sequences.
  31426. if (!dataDims.length) {
  31427. for (var i = 0; i < (sysDimItemDimsDef && sysDimItemDimsDef.length || 1); i++) {
  31428. while (availDimIdx < dimCount && getResultItem(availDimIdx).coordDim != null) {
  31429. availDimIdx++;
  31430. }
  31431. availDimIdx < dimCount && dataDims.push(availDimIdx++);
  31432. }
  31433. }
  31434. // Apply templates.
  31435. each(dataDims, function (resultDimIdx, coordDimIndex) {
  31436. var resultItem = getResultItem(resultDimIdx);
  31437. // Coordinate system has a higher priority on dim type than source.
  31438. if (isUsingSourceDimensionsDef && sysDimItem.type != null) {
  31439. resultItem.type = sysDimItem.type;
  31440. }
  31441. applyDim(defaults(resultItem, sysDimItem), coordDim, coordDimIndex);
  31442. if (resultItem.name == null && sysDimItemDimsDef) {
  31443. var sysDimItemDimsDefItem = sysDimItemDimsDef[coordDimIndex];
  31444. !isObject(sysDimItemDimsDefItem) && (sysDimItemDimsDefItem = {
  31445. name: sysDimItemDimsDefItem
  31446. });
  31447. resultItem.name = resultItem.displayName = sysDimItemDimsDefItem.name;
  31448. resultItem.defaultTooltip = sysDimItemDimsDefItem.defaultTooltip;
  31449. }
  31450. // FIXME refactor, currently only used in case: {otherDims: {tooltip: false}}
  31451. sysDimItemOtherDims && defaults(resultItem.otherDims, sysDimItemOtherDims);
  31452. });
  31453. });
  31454. function applyDim(resultItem, coordDim, coordDimIndex) {
  31455. if (VISUAL_DIMENSIONS.get(coordDim) != null) {
  31456. resultItem.otherDims[coordDim] = coordDimIndex;
  31457. } else {
  31458. resultItem.coordDim = coordDim;
  31459. resultItem.coordDimIndex = coordDimIndex;
  31460. coordDimNameMap.set(coordDim, true);
  31461. }
  31462. }
  31463. // Make sure the first extra dim is 'value'.
  31464. var generateCoord = opt.generateCoord;
  31465. var generateCoordCount = opt.generateCoordCount;
  31466. var fromZero = generateCoordCount != null;
  31467. generateCoordCount = generateCoord ? generateCoordCount || 1 : 0;
  31468. var extra = generateCoord || 'value';
  31469. function ifNoNameFillWithCoordName(resultItem) {
  31470. if (resultItem.name == null) {
  31471. // Duplication will be removed in the next step.
  31472. resultItem.name = resultItem.coordDim;
  31473. }
  31474. }
  31475. // Set dim `name` and other `coordDim` and other props.
  31476. if (!omitUnusedDimensions) {
  31477. for (var resultDimIdx = 0; resultDimIdx < dimCount; resultDimIdx++) {
  31478. var resultItem = getResultItem(resultDimIdx);
  31479. var coordDim = resultItem.coordDim;
  31480. if (coordDim == null) {
  31481. // TODO no need to generate coordDim for isExtraCoord?
  31482. resultItem.coordDim = genCoordDimName(extra, coordDimNameMap, fromZero);
  31483. resultItem.coordDimIndex = 0;
  31484. // Series specified generateCoord is using out.
  31485. if (!generateCoord || generateCoordCount <= 0) {
  31486. resultItem.isExtraCoord = true;
  31487. }
  31488. generateCoordCount--;
  31489. }
  31490. ifNoNameFillWithCoordName(resultItem);
  31491. if (resultItem.type == null && (guessOrdinal(source, resultDimIdx) === BE_ORDINAL.Must
  31492. // Consider the case:
  31493. // {
  31494. // dataset: {source: [
  31495. // ['2001', 123],
  31496. // ['2002', 456],
  31497. // ...
  31498. // ['The others', 987],
  31499. // ]},
  31500. // series: {type: 'pie'}
  31501. // }
  31502. // The first column should better be treated as a "ordinal" although it
  31503. // might not be detected as an "ordinal" by `guessOrdinal`.
  31504. || resultItem.isExtraCoord && (resultItem.otherDims.itemName != null || resultItem.otherDims.seriesName != null))) {
  31505. resultItem.type = 'ordinal';
  31506. }
  31507. }
  31508. } else {
  31509. each(resultList, function (resultItem) {
  31510. // PENDING: guessOrdinal or let user specify type: 'ordinal' manually?
  31511. ifNoNameFillWithCoordName(resultItem);
  31512. });
  31513. // Sort dimensions: there are some rule that use the last dim as label,
  31514. // and for some latter travel process easier.
  31515. resultList.sort(function (item0, item1) {
  31516. return item0.storeDimIndex - item1.storeDimIndex;
  31517. });
  31518. }
  31519. removeDuplication(resultList);
  31520. return new SeriesDataSchema({
  31521. source: source,
  31522. dimensions: resultList,
  31523. fullDimensionCount: dimCount,
  31524. dimensionOmitted: omitUnusedDimensions
  31525. });
  31526. }
  31527. function removeDuplication(result) {
  31528. var duplicationMap = createHashMap();
  31529. for (var i = 0; i < result.length; i++) {
  31530. var dim = result[i];
  31531. var dimOriginalName = dim.name;
  31532. var count = duplicationMap.get(dimOriginalName) || 0;
  31533. if (count > 0) {
  31534. // Starts from 0.
  31535. dim.name = dimOriginalName + (count - 1);
  31536. }
  31537. count++;
  31538. duplicationMap.set(dimOriginalName, count);
  31539. }
  31540. }
  31541. // ??? TODO
  31542. // Originally detect dimCount by data[0]. Should we
  31543. // optimize it to only by sysDims and dimensions and encode.
  31544. // So only necessary dims will be initialized.
  31545. // But
  31546. // (1) custom series should be considered. where other dims
  31547. // may be visited.
  31548. // (2) sometimes user need to calculate bubble size or use visualMap
  31549. // on other dimensions besides coordSys needed.
  31550. // So, dims that is not used by system, should be shared in data store?
  31551. function getDimCount(source, sysDims, dimsDef, optDimCount) {
  31552. // Note that the result dimCount should not small than columns count
  31553. // of data, otherwise `dataDimNameMap` checking will be incorrect.
  31554. var dimCount = Math.max(source.dimensionsDetectedCount || 1, sysDims.length, dimsDef.length, optDimCount || 0);
  31555. each(sysDims, function (sysDimItem) {
  31556. var sysDimItemDimsDef;
  31557. if (isObject(sysDimItem) && (sysDimItemDimsDef = sysDimItem.dimsDef)) {
  31558. dimCount = Math.max(dimCount, sysDimItemDimsDef.length);
  31559. }
  31560. });
  31561. return dimCount;
  31562. }
  31563. function genCoordDimName(name, map, fromZero) {
  31564. if (fromZero || map.hasKey(name)) {
  31565. var i = 0;
  31566. while (map.hasKey(name + i)) {
  31567. i++;
  31568. }
  31569. name += i;
  31570. }
  31571. map.set(name, true);
  31572. return name;
  31573. }
  31574. /**
  31575. * @class
  31576. * For example:
  31577. * {
  31578. * coordSysName: 'cartesian2d',
  31579. * coordSysDims: ['x', 'y', ...],
  31580. * axisMap: HashMap({
  31581. * x: xAxisModel,
  31582. * y: yAxisModel
  31583. * }),
  31584. * categoryAxisMap: HashMap({
  31585. * x: xAxisModel,
  31586. * y: undefined
  31587. * }),
  31588. * // The index of the first category axis in `coordSysDims`.
  31589. * // `null/undefined` means no category axis exists.
  31590. * firstCategoryDimIndex: 1,
  31591. * // To replace user specified encode.
  31592. * }
  31593. */
  31594. var CoordSysInfo = /** @class */function () {
  31595. function CoordSysInfo(coordSysName) {
  31596. this.coordSysDims = [];
  31597. this.axisMap = createHashMap();
  31598. this.categoryAxisMap = createHashMap();
  31599. this.coordSysName = coordSysName;
  31600. }
  31601. return CoordSysInfo;
  31602. }();
  31603. function getCoordSysInfoBySeries(seriesModel) {
  31604. var coordSysName = seriesModel.get('coordinateSystem');
  31605. var result = new CoordSysInfo(coordSysName);
  31606. var fetch = fetchers[coordSysName];
  31607. if (fetch) {
  31608. fetch(seriesModel, result, result.axisMap, result.categoryAxisMap);
  31609. return result;
  31610. }
  31611. }
  31612. // TODO: refactor them to static member of each coord sys, rather than hard code here.
  31613. var fetchers = {
  31614. cartesian2d: function (seriesModel, result, axisMap, categoryAxisMap) {
  31615. var xAxisModel = seriesModel.getReferringComponents('xAxis', SINGLE_REFERRING).models[0];
  31616. var yAxisModel = seriesModel.getReferringComponents('yAxis', SINGLE_REFERRING).models[0];
  31617. if ("development" !== 'production') {
  31618. if (!xAxisModel) {
  31619. throw new Error('xAxis "' + retrieve(seriesModel.get('xAxisIndex'), seriesModel.get('xAxisId'), 0) + '" not found');
  31620. }
  31621. if (!yAxisModel) {
  31622. throw new Error('yAxis "' + retrieve(seriesModel.get('xAxisIndex'), seriesModel.get('yAxisId'), 0) + '" not found');
  31623. }
  31624. }
  31625. result.coordSysDims = ['x', 'y'];
  31626. axisMap.set('x', xAxisModel);
  31627. axisMap.set('y', yAxisModel);
  31628. if (isCategory(xAxisModel)) {
  31629. categoryAxisMap.set('x', xAxisModel);
  31630. result.firstCategoryDimIndex = 0;
  31631. }
  31632. if (isCategory(yAxisModel)) {
  31633. categoryAxisMap.set('y', yAxisModel);
  31634. result.firstCategoryDimIndex == null && (result.firstCategoryDimIndex = 1);
  31635. }
  31636. },
  31637. singleAxis: function (seriesModel, result, axisMap, categoryAxisMap) {
  31638. var singleAxisModel = seriesModel.getReferringComponents('singleAxis', SINGLE_REFERRING).models[0];
  31639. if ("development" !== 'production') {
  31640. if (!singleAxisModel) {
  31641. throw new Error('singleAxis should be specified.');
  31642. }
  31643. }
  31644. result.coordSysDims = ['single'];
  31645. axisMap.set('single', singleAxisModel);
  31646. if (isCategory(singleAxisModel)) {
  31647. categoryAxisMap.set('single', singleAxisModel);
  31648. result.firstCategoryDimIndex = 0;
  31649. }
  31650. },
  31651. polar: function (seriesModel, result, axisMap, categoryAxisMap) {
  31652. var polarModel = seriesModel.getReferringComponents('polar', SINGLE_REFERRING).models[0];
  31653. var radiusAxisModel = polarModel.findAxisModel('radiusAxis');
  31654. var angleAxisModel = polarModel.findAxisModel('angleAxis');
  31655. if ("development" !== 'production') {
  31656. if (!angleAxisModel) {
  31657. throw new Error('angleAxis option not found');
  31658. }
  31659. if (!radiusAxisModel) {
  31660. throw new Error('radiusAxis option not found');
  31661. }
  31662. }
  31663. result.coordSysDims = ['radius', 'angle'];
  31664. axisMap.set('radius', radiusAxisModel);
  31665. axisMap.set('angle', angleAxisModel);
  31666. if (isCategory(radiusAxisModel)) {
  31667. categoryAxisMap.set('radius', radiusAxisModel);
  31668. result.firstCategoryDimIndex = 0;
  31669. }
  31670. if (isCategory(angleAxisModel)) {
  31671. categoryAxisMap.set('angle', angleAxisModel);
  31672. result.firstCategoryDimIndex == null && (result.firstCategoryDimIndex = 1);
  31673. }
  31674. },
  31675. geo: function (seriesModel, result, axisMap, categoryAxisMap) {
  31676. result.coordSysDims = ['lng', 'lat'];
  31677. },
  31678. parallel: function (seriesModel, result, axisMap, categoryAxisMap) {
  31679. var ecModel = seriesModel.ecModel;
  31680. var parallelModel = ecModel.getComponent('parallel', seriesModel.get('parallelIndex'));
  31681. var coordSysDims = result.coordSysDims = parallelModel.dimensions.slice();
  31682. each(parallelModel.parallelAxisIndex, function (axisIndex, index) {
  31683. var axisModel = ecModel.getComponent('parallelAxis', axisIndex);
  31684. var axisDim = coordSysDims[index];
  31685. axisMap.set(axisDim, axisModel);
  31686. if (isCategory(axisModel)) {
  31687. categoryAxisMap.set(axisDim, axisModel);
  31688. if (result.firstCategoryDimIndex == null) {
  31689. result.firstCategoryDimIndex = index;
  31690. }
  31691. }
  31692. });
  31693. },
  31694. matrix: function (seriesModel, result, axisMap, categoryAxisMap) {
  31695. var matrixModel = seriesModel.getReferringComponents('matrix', SINGLE_REFERRING).models[0];
  31696. if ("development" !== 'production') {
  31697. if (!matrixModel) {
  31698. throw new Error('matrix coordinate system should be specified.');
  31699. }
  31700. }
  31701. result.coordSysDims = ['x', 'y'];
  31702. var xModel = matrixModel.getDimensionModel('x');
  31703. var yModel = matrixModel.getDimensionModel('y');
  31704. axisMap.set('x', xModel);
  31705. axisMap.set('y', yModel);
  31706. categoryAxisMap.set('x', xModel);
  31707. categoryAxisMap.set('y', yModel);
  31708. }
  31709. };
  31710. function isCategory(axisModel) {
  31711. return axisModel.get('type') === 'category';
  31712. }
  31713. /**
  31714. * Note that it is too complicated to support 3d stack by value
  31715. * (have to create two-dimension inverted index), so in 3d case
  31716. * we just support that stacked by index.
  31717. *
  31718. * @param seriesModel
  31719. * @param dimensionsInput The same as the input of <module:echarts/data/SeriesData>.
  31720. * The input will be modified.
  31721. * @param opt
  31722. * @param opt.stackedCoordDimension Specify a coord dimension if needed.
  31723. * @param opt.byIndex=false
  31724. * @return calculationInfo
  31725. * {
  31726. * stackedDimension: string
  31727. * stackedByDimension: string
  31728. * isStackedByIndex: boolean
  31729. * stackedOverDimension: string
  31730. * stackResultDimension: string
  31731. * }
  31732. */
  31733. function enableDataStack(seriesModel, dimensionsInput, opt) {
  31734. opt = opt || {};
  31735. var byIndex = opt.byIndex;
  31736. var stackedCoordDimension = opt.stackedCoordDimension;
  31737. var dimensionDefineList;
  31738. var schema;
  31739. var store;
  31740. if (isLegacyDimensionsInput(dimensionsInput)) {
  31741. dimensionDefineList = dimensionsInput;
  31742. } else {
  31743. schema = dimensionsInput.schema;
  31744. dimensionDefineList = schema.dimensions;
  31745. store = dimensionsInput.store;
  31746. }
  31747. // Compatibal: when `stack` is set as '', do not stack.
  31748. var mayStack = !!(seriesModel && seriesModel.get('stack'));
  31749. var stackedByDimInfo;
  31750. var stackedDimInfo;
  31751. var stackResultDimension;
  31752. var stackedOverDimension;
  31753. each(dimensionDefineList, function (dimensionInfo, index) {
  31754. if (isString(dimensionInfo)) {
  31755. dimensionDefineList[index] = dimensionInfo = {
  31756. name: dimensionInfo
  31757. };
  31758. }
  31759. if (mayStack && !dimensionInfo.isExtraCoord) {
  31760. // Find the first ordinal dimension as the stackedByDimInfo.
  31761. if (!byIndex && !stackedByDimInfo && dimensionInfo.ordinalMeta) {
  31762. stackedByDimInfo = dimensionInfo;
  31763. }
  31764. // Find the first stackable dimension as the stackedDimInfo.
  31765. if (!stackedDimInfo && dimensionInfo.type !== 'ordinal' && dimensionInfo.type !== 'time' && (!stackedCoordDimension || stackedCoordDimension === dimensionInfo.coordDim)) {
  31766. stackedDimInfo = dimensionInfo;
  31767. }
  31768. }
  31769. });
  31770. if (stackedDimInfo && !byIndex && !stackedByDimInfo) {
  31771. // Compatible with previous design, value axis (time axis) only stack by index.
  31772. // It may make sense if the user provides elaborately constructed data.
  31773. byIndex = true;
  31774. }
  31775. // Add stack dimension, they can be both calculated by coordinate system in `unionExtent`.
  31776. // That put stack logic in List is for using conveniently in echarts extensions, but it
  31777. // might not be a good way.
  31778. if (stackedDimInfo) {
  31779. // Use a weird name that not duplicated with other names.
  31780. // Also need to use seriesModel.id as postfix because different
  31781. // series may share same data store. The stack dimension needs to be distinguished.
  31782. stackResultDimension = '__\0ecstackresult_' + seriesModel.id;
  31783. stackedOverDimension = '__\0ecstackedover_' + seriesModel.id;
  31784. // Create inverted index to fast query index by value.
  31785. if (stackedByDimInfo) {
  31786. stackedByDimInfo.createInvertedIndices = true;
  31787. }
  31788. var stackedDimCoordDim_1 = stackedDimInfo.coordDim;
  31789. var stackedDimType = stackedDimInfo.type;
  31790. var stackedDimCoordIndex_1 = 0;
  31791. each(dimensionDefineList, function (dimensionInfo) {
  31792. if (dimensionInfo.coordDim === stackedDimCoordDim_1) {
  31793. stackedDimCoordIndex_1++;
  31794. }
  31795. });
  31796. var stackedOverDimensionDefine = {
  31797. name: stackResultDimension,
  31798. coordDim: stackedDimCoordDim_1,
  31799. coordDimIndex: stackedDimCoordIndex_1,
  31800. type: stackedDimType,
  31801. isExtraCoord: true,
  31802. isCalculationCoord: true,
  31803. storeDimIndex: dimensionDefineList.length
  31804. };
  31805. var stackResultDimensionDefine = {
  31806. name: stackedOverDimension,
  31807. // This dimension contains stack base (generally, 0), so do not set it as
  31808. // `stackedDimCoordDim` to avoid extent calculation, consider log scale.
  31809. coordDim: stackedOverDimension,
  31810. coordDimIndex: stackedDimCoordIndex_1 + 1,
  31811. type: stackedDimType,
  31812. isExtraCoord: true,
  31813. isCalculationCoord: true,
  31814. storeDimIndex: dimensionDefineList.length + 1
  31815. };
  31816. if (schema) {
  31817. if (store) {
  31818. stackedOverDimensionDefine.storeDimIndex = store.ensureCalculationDimension(stackedOverDimension, stackedDimType);
  31819. stackResultDimensionDefine.storeDimIndex = store.ensureCalculationDimension(stackResultDimension, stackedDimType);
  31820. }
  31821. schema.appendCalculationDimension(stackedOverDimensionDefine);
  31822. schema.appendCalculationDimension(stackResultDimensionDefine);
  31823. } else {
  31824. dimensionDefineList.push(stackedOverDimensionDefine);
  31825. dimensionDefineList.push(stackResultDimensionDefine);
  31826. }
  31827. }
  31828. return {
  31829. stackedDimension: stackedDimInfo && stackedDimInfo.name,
  31830. stackedByDimension: stackedByDimInfo && stackedByDimInfo.name,
  31831. isStackedByIndex: byIndex,
  31832. stackedOverDimension: stackedOverDimension,
  31833. stackResultDimension: stackResultDimension
  31834. };
  31835. }
  31836. function isLegacyDimensionsInput(dimensionsInput) {
  31837. return !isSeriesDataSchema(dimensionsInput.schema);
  31838. }
  31839. function isDimensionStacked(data, stackedDim) {
  31840. // Each single series only maps to one pair of axis. So we do not need to
  31841. // check stackByDim, whatever stacked by a dimension or stacked by index.
  31842. return !!stackedDim && stackedDim === data.getCalculationInfo('stackedDimension');
  31843. }
  31844. function getStackedDimension(data, targetDim) {
  31845. return isDimensionStacked(data, targetDim) ? data.getCalculationInfo('stackResultDimension') : targetDim;
  31846. }
  31847. function getCoordSysDimDefs(seriesModel, coordSysInfo) {
  31848. var coordSysName = seriesModel.get('coordinateSystem');
  31849. var registeredCoordSys = CoordinateSystemManager.get(coordSysName);
  31850. var coordSysDimDefs;
  31851. if (coordSysInfo && coordSysInfo.coordSysDims) {
  31852. coordSysDimDefs = map(coordSysInfo.coordSysDims, function (dim) {
  31853. var dimInfo = {
  31854. name: dim
  31855. };
  31856. var axisModel = coordSysInfo.axisMap.get(dim);
  31857. if (axisModel) {
  31858. var axisType = axisModel.get('type');
  31859. dimInfo.type = getDimensionTypeByAxis(axisType);
  31860. }
  31861. return dimInfo;
  31862. });
  31863. }
  31864. if (!coordSysDimDefs) {
  31865. // Get dimensions from registered coordinate system
  31866. coordSysDimDefs = registeredCoordSys && (registeredCoordSys.getDimensionsInfo ? registeredCoordSys.getDimensionsInfo() : registeredCoordSys.dimensions.slice()) || ['x', 'y'];
  31867. }
  31868. return coordSysDimDefs;
  31869. }
  31870. function injectOrdinalMeta(dimInfoList, createInvertedIndices, coordSysInfo) {
  31871. var firstCategoryDimIndex;
  31872. var hasNameEncode;
  31873. coordSysInfo && each(dimInfoList, function (dimInfo, dimIndex) {
  31874. var coordDim = dimInfo.coordDim;
  31875. var categoryAxisModel = coordSysInfo.categoryAxisMap.get(coordDim);
  31876. if (categoryAxisModel) {
  31877. if (firstCategoryDimIndex == null) {
  31878. firstCategoryDimIndex = dimIndex;
  31879. }
  31880. dimInfo.ordinalMeta = categoryAxisModel.getOrdinalMeta();
  31881. if (createInvertedIndices) {
  31882. dimInfo.createInvertedIndices = true;
  31883. }
  31884. }
  31885. if (dimInfo.otherDims.itemName != null) {
  31886. hasNameEncode = true;
  31887. }
  31888. });
  31889. if (!hasNameEncode && firstCategoryDimIndex != null) {
  31890. dimInfoList[firstCategoryDimIndex].otherDims.itemName = 0;
  31891. }
  31892. return firstCategoryDimIndex;
  31893. }
  31894. /**
  31895. * Caution: there are side effects to `sourceManager` in this method.
  31896. * Should better only be called in `Series['getInitialData']`.
  31897. */
  31898. function createSeriesData(sourceRaw, seriesModel, opt) {
  31899. opt = opt || {};
  31900. var sourceManager = seriesModel.getSourceManager();
  31901. var source;
  31902. var isOriginalSource = false;
  31903. if (sourceRaw) {
  31904. isOriginalSource = true;
  31905. source = createSourceFromSeriesDataOption(sourceRaw);
  31906. } else {
  31907. source = sourceManager.getSource();
  31908. // Is series.data. not dataset.
  31909. isOriginalSource = source.sourceFormat === SOURCE_FORMAT_ORIGINAL;
  31910. }
  31911. var coordSysInfo = getCoordSysInfoBySeries(seriesModel);
  31912. var coordSysDimDefs = getCoordSysDimDefs(seriesModel, coordSysInfo);
  31913. var useEncodeDefaulter = opt.useEncodeDefaulter;
  31914. var encodeDefaulter = isFunction(useEncodeDefaulter) ? useEncodeDefaulter : useEncodeDefaulter ? curry(makeSeriesEncodeForAxisCoordSys, coordSysDimDefs, seriesModel) : null;
  31915. var createDimensionOptions = {
  31916. coordDimensions: coordSysDimDefs,
  31917. generateCoord: opt.generateCoord,
  31918. encodeDefine: seriesModel.getEncode(),
  31919. encodeDefaulter: encodeDefaulter,
  31920. canOmitUnusedDimensions: !isOriginalSource
  31921. };
  31922. var schema = prepareSeriesDataSchema(source, createDimensionOptions);
  31923. var firstCategoryDimIndex = injectOrdinalMeta(schema.dimensions, opt.createInvertedIndices, coordSysInfo);
  31924. var store = !isOriginalSource ? sourceManager.getSharedDataStore(schema) : null;
  31925. var stackCalculationInfo = enableDataStack(seriesModel, {
  31926. schema: schema,
  31927. store: store
  31928. });
  31929. var data = new SeriesData(schema, seriesModel);
  31930. data.setCalculationInfo(stackCalculationInfo);
  31931. var dimValueGetter = firstCategoryDimIndex != null && isNeedCompleteOrdinalData(source)
  31932. /**
  31933. * This serves this case:
  31934. * var echarts_option = {
  31935. * xAxis: { data: ['a', 'b', 'c'] },
  31936. * yAxis: {}
  31937. * series: { data: [555, 666, 777] }
  31938. * };
  31939. * The `series.data` is completed to:
  31940. * [[0, 555], [1, 666], [2, 777]]
  31941. */ ? function (itemOpt, dimName, dataIndex, dimIndex) {
  31942. // Use dataIndex as ordinal value in categoryAxis
  31943. return dimIndex === firstCategoryDimIndex ? dataIndex : this.defaultDimValueGetter(itemOpt, dimName, dataIndex, dimIndex);
  31944. } : null;
  31945. data.hasItemOption = false;
  31946. data.initData(
  31947. // Try to reuse the data store in sourceManager if using dataset.
  31948. isOriginalSource ? source : store, null, dimValueGetter);
  31949. return data;
  31950. }
  31951. function isNeedCompleteOrdinalData(source) {
  31952. if (source.sourceFormat === SOURCE_FORMAT_ORIGINAL) {
  31953. var sampleItem = firstDataNotNull(source.data || []);
  31954. return !isArray(getDataItemValue(sampleItem));
  31955. }
  31956. }
  31957. function firstDataNotNull(arr) {
  31958. var i = 0;
  31959. while (i < arr.length && arr[i] == null) {
  31960. i++;
  31961. }
  31962. return arr[i];
  31963. }
  31964. function isValueNice(val) {
  31965. var exp10 = Math.pow(10, quantityExponent(Math.abs(val)));
  31966. var f = Math.abs(val / exp10);
  31967. return f === 0 || f === 1 || f === 2 || f === 3 || f === 5;
  31968. }
  31969. function isIntervalOrLogScale(scale) {
  31970. return scale.type === 'interval' || scale.type === 'log';
  31971. }
  31972. /**
  31973. * @param extent Both extent[0] and extent[1] should be valid number.
  31974. * Should be extent[0] < extent[1].
  31975. * @param splitNumber splitNumber should be >= 1.
  31976. */
  31977. function intervalScaleNiceTicks(extent, spanWithBreaks, splitNumber, minInterval, maxInterval) {
  31978. var result = {};
  31979. var interval = result.interval = nice(spanWithBreaks / splitNumber, true);
  31980. if (minInterval != null && interval < minInterval) {
  31981. interval = result.interval = minInterval;
  31982. }
  31983. if (maxInterval != null && interval > maxInterval) {
  31984. interval = result.interval = maxInterval;
  31985. }
  31986. // Tow more digital for tick.
  31987. var precision = result.intervalPrecision = getIntervalPrecision(interval);
  31988. // Niced extent inside original extent
  31989. var niceTickExtent = result.niceTickExtent = [round(Math.ceil(extent[0] / interval) * interval, precision), round(Math.floor(extent[1] / interval) * interval, precision)];
  31990. fixExtent(niceTickExtent, extent);
  31991. return result;
  31992. }
  31993. function increaseInterval(interval) {
  31994. var exp10 = Math.pow(10, quantityExponent(interval));
  31995. // Increase interval
  31996. var f = interval / exp10;
  31997. if (!f) {
  31998. f = 1;
  31999. } else if (f === 2) {
  32000. f = 3;
  32001. } else if (f === 3) {
  32002. f = 5;
  32003. } else {
  32004. // f is 1 or 5
  32005. f *= 2;
  32006. }
  32007. return round(f * exp10);
  32008. }
  32009. /**
  32010. * @return interval precision
  32011. */
  32012. function getIntervalPrecision(interval) {
  32013. // Tow more digital for tick.
  32014. return getPrecision(interval) + 2;
  32015. }
  32016. function clamp(niceTickExtent, idx, extent) {
  32017. niceTickExtent[idx] = Math.max(Math.min(niceTickExtent[idx], extent[1]), extent[0]);
  32018. }
  32019. // In some cases (e.g., splitNumber is 1), niceTickExtent may be out of extent.
  32020. function fixExtent(niceTickExtent, extent) {
  32021. !isFinite(niceTickExtent[0]) && (niceTickExtent[0] = extent[0]);
  32022. !isFinite(niceTickExtent[1]) && (niceTickExtent[1] = extent[1]);
  32023. clamp(niceTickExtent, 0, extent);
  32024. clamp(niceTickExtent, 1, extent);
  32025. if (niceTickExtent[0] > niceTickExtent[1]) {
  32026. niceTickExtent[0] = niceTickExtent[1];
  32027. }
  32028. }
  32029. function contain$1(val, extent) {
  32030. return val >= extent[0] && val <= extent[1];
  32031. }
  32032. var ScaleCalculator = /** @class */function () {
  32033. function ScaleCalculator() {
  32034. this.normalize = normalize$1;
  32035. this.scale = scale$2;
  32036. }
  32037. ScaleCalculator.prototype.updateMethods = function (brkCtx) {
  32038. if (brkCtx.hasBreaks()) {
  32039. this.normalize = bind(brkCtx.normalize, brkCtx);
  32040. this.scale = bind(brkCtx.scale, brkCtx);
  32041. } else {
  32042. this.normalize = normalize$1;
  32043. this.scale = scale$2;
  32044. }
  32045. };
  32046. return ScaleCalculator;
  32047. }();
  32048. function normalize$1(val, extent) {
  32049. if (extent[1] === extent[0]) {
  32050. return 0.5;
  32051. }
  32052. return (val - extent[0]) / (extent[1] - extent[0]);
  32053. }
  32054. function scale$2(val, extent) {
  32055. return val * (extent[1] - extent[0]) + extent[0];
  32056. }
  32057. function logTransform(base, extent, noClampNegative) {
  32058. var loggedBase = Math.log(base);
  32059. return [
  32060. // log(negative) is NaN, so safe guard here.
  32061. // PENDING: But even getting a -Infinity still does not make sense in extent.
  32062. // Just keep it as is, getting a NaN to make some previous cases works by coincidence.
  32063. Math.log(noClampNegative ? extent[0] : Math.max(0, extent[0])) / loggedBase, Math.log(noClampNegative ? extent[1] : Math.max(0, extent[1])) / loggedBase];
  32064. }
  32065. var Scale = /** @class */function () {
  32066. function Scale(setting) {
  32067. this._calculator = new ScaleCalculator();
  32068. this._setting = setting || {};
  32069. this._extent = [Infinity, -Infinity];
  32070. var scaleBreakHelper = getScaleBreakHelper();
  32071. if (scaleBreakHelper) {
  32072. this._brkCtx = scaleBreakHelper.createScaleBreakContext();
  32073. this._brkCtx.update(this._extent);
  32074. }
  32075. }
  32076. Scale.prototype.getSetting = function (name) {
  32077. return this._setting[name];
  32078. };
  32079. /**
  32080. * [CAVEAT]: It should not be overridden!
  32081. */
  32082. Scale.prototype._innerUnionExtent = function (other) {
  32083. var extent = this._extent;
  32084. // Considered that number could be NaN and should not write into the extent.
  32085. this._innerSetExtent(other[0] < extent[0] ? other[0] : extent[0], other[1] > extent[1] ? other[1] : extent[1]);
  32086. };
  32087. /**
  32088. * Set extent from data
  32089. */
  32090. Scale.prototype.unionExtentFromData = function (data, dim) {
  32091. this._innerUnionExtent(data.getApproximateExtent(dim));
  32092. };
  32093. /**
  32094. * Get a new slice of extent.
  32095. * Extent is always in increase order.
  32096. */
  32097. Scale.prototype.getExtent = function () {
  32098. return this._extent.slice();
  32099. };
  32100. Scale.prototype.setExtent = function (start, end) {
  32101. this._innerSetExtent(start, end);
  32102. };
  32103. /**
  32104. * [CAVEAT]: It should not be overridden!
  32105. */
  32106. Scale.prototype._innerSetExtent = function (start, end) {
  32107. var thisExtent = this._extent;
  32108. if (!isNaN(start)) {
  32109. thisExtent[0] = start;
  32110. }
  32111. if (!isNaN(end)) {
  32112. thisExtent[1] = end;
  32113. }
  32114. this._brkCtx && this._brkCtx.update(thisExtent);
  32115. };
  32116. /**
  32117. * Prerequisite: Scale#parse is ready.
  32118. */
  32119. Scale.prototype.setBreaksFromOption = function (breakOptionList) {
  32120. var scaleBreakHelper = getScaleBreakHelper();
  32121. if (scaleBreakHelper) {
  32122. this._innerSetBreak(scaleBreakHelper.parseAxisBreakOption(breakOptionList, bind(this.parse, this)));
  32123. }
  32124. };
  32125. /**
  32126. * [CAVEAT]: It should not be overridden!
  32127. */
  32128. Scale.prototype._innerSetBreak = function (parsed) {
  32129. if (this._brkCtx) {
  32130. this._brkCtx.setBreaks(parsed);
  32131. this._calculator.updateMethods(this._brkCtx);
  32132. this._brkCtx.update(this._extent);
  32133. }
  32134. };
  32135. /**
  32136. * [CAVEAT]: It should not be overridden!
  32137. */
  32138. Scale.prototype._innerGetBreaks = function () {
  32139. return this._brkCtx ? this._brkCtx.breaks : [];
  32140. };
  32141. /**
  32142. * Do not expose the internal `_breaks` unless necessary.
  32143. */
  32144. Scale.prototype.hasBreaks = function () {
  32145. return this._brkCtx ? this._brkCtx.hasBreaks() : false;
  32146. };
  32147. Scale.prototype._getExtentSpanWithBreaks = function () {
  32148. return this._brkCtx && this._brkCtx.hasBreaks() ? this._brkCtx.getExtentSpan() : this._extent[1] - this._extent[0];
  32149. };
  32150. /**
  32151. * If value is in extent range
  32152. */
  32153. Scale.prototype.isInExtentRange = function (value) {
  32154. return this._extent[0] <= value && this._extent[1] >= value;
  32155. };
  32156. /**
  32157. * When axis extent depends on data and no data exists,
  32158. * axis ticks should not be drawn, which is named 'blank'.
  32159. */
  32160. Scale.prototype.isBlank = function () {
  32161. return this._isBlank;
  32162. };
  32163. /**
  32164. * When axis extent depends on data and no data exists,
  32165. * axis ticks should not be drawn, which is named 'blank'.
  32166. */
  32167. Scale.prototype.setBlank = function (isBlank) {
  32168. this._isBlank = isBlank;
  32169. };
  32170. return Scale;
  32171. }();
  32172. enableClassManagement(Scale);
  32173. var uidBase = 0;
  32174. var OrdinalMeta = /** @class */function () {
  32175. /**
  32176. * PENDING - Regarding forcibly converting to string:
  32177. * In the early days, the underlying hash map impl used JS plain object and converted the key to
  32178. * string; later in https://github.com/ecomfe/zrender/pull/966 it was changed to a JS Map (in supported
  32179. * platforms), which does not require string keys. But consider any input that `scale/Ordinal['parse']`
  32180. * is involved, a number input represents an `OrdinalNumber` (i.e., an index), and affect the query
  32181. * behavior:
  32182. * - If forcbily converting to string:
  32183. * pros: users can use numeric string (such as, '123') to query the raw data (123), tho it's probably
  32184. * still confusing.
  32185. * cons: NaN/null/undefined in data will be equals to 'NaN'/'null'/'undefined', if simply using
  32186. * `val + ''` to convert them, like currently `getName` does.
  32187. * - Otherwise:
  32188. * pros: see NaN/null/undefined case above.
  32189. * cons: users cannot query the raw data (123) any more.
  32190. * There are two inconsistent behaviors in the current impl:
  32191. * - Force conversion is applied on the case `xAxis{data: ['aaa', 'bbb', ...]}`,
  32192. * but no conversion applied to the case `xAxis{data: [{value: 'aaa'}, ...]}` and
  32193. * the case `dataset: {source: [['aaa', 123], ['bbb', 234], ...]}`.
  32194. * - behaves differently according to whether JS Map is supported (the polyfill is simply using JS
  32195. * plain object) (tho it seems rare platform that do not support it).
  32196. * Since there's no sufficient good solution to offset cost of the breaking change, we preserve the
  32197. * current behavior, until real issues is reported.
  32198. */
  32199. function OrdinalMeta(opt) {
  32200. this.categories = opt.categories || [];
  32201. this._needCollect = opt.needCollect;
  32202. this._deduplication = opt.deduplication;
  32203. this.uid = ++uidBase;
  32204. this._onCollect = opt.onCollect;
  32205. }
  32206. OrdinalMeta.createByAxisModel = function (axisModel) {
  32207. var option = axisModel.option;
  32208. var data = option.data;
  32209. var categories = data && map(data, getName);
  32210. return new OrdinalMeta({
  32211. categories: categories,
  32212. needCollect: !categories,
  32213. // deduplication is default in axis.
  32214. deduplication: option.dedplication !== false
  32215. });
  32216. };
  32217. OrdinalMeta.prototype.getOrdinal = function (category) {
  32218. return this._getOrCreateMap().get(category);
  32219. };
  32220. /**
  32221. * @return The ordinal. If not found, return NaN.
  32222. */
  32223. OrdinalMeta.prototype.parseAndCollect = function (category) {
  32224. var index;
  32225. var needCollect = this._needCollect;
  32226. // The value of category dim can be the index of the given category set.
  32227. // This feature is only supported when !needCollect, because we should
  32228. // consider a common case: a value is 2017, which is a number but is
  32229. // expected to be tread as a category. This case usually happen in dataset,
  32230. // where it happent to be no need of the index feature.
  32231. if (!isString(category) && !needCollect) {
  32232. return category;
  32233. }
  32234. // Optimize for the scenario:
  32235. // category is ['2012-01-01', '2012-01-02', ...], where the input
  32236. // data has been ensured not duplicate and is large data.
  32237. // Notice, if a dataset dimension provide categroies, usually echarts
  32238. // should remove duplication except user tell echarts dont do that
  32239. // (set axis.deduplication = false), because echarts do not know whether
  32240. // the values in the category dimension has duplication (consider the
  32241. // parallel-aqi example)
  32242. if (needCollect && !this._deduplication) {
  32243. index = this.categories.length;
  32244. this.categories[index] = category;
  32245. this._onCollect && this._onCollect(category, index);
  32246. return index;
  32247. }
  32248. var map = this._getOrCreateMap();
  32249. index = map.get(category);
  32250. if (index == null) {
  32251. if (needCollect) {
  32252. index = this.categories.length;
  32253. this.categories[index] = category;
  32254. map.set(category, index);
  32255. this._onCollect && this._onCollect(category, index);
  32256. } else {
  32257. index = NaN;
  32258. }
  32259. }
  32260. return index;
  32261. };
  32262. // Consider big data, do not create map until needed.
  32263. OrdinalMeta.prototype._getOrCreateMap = function () {
  32264. return this._map || (this._map = createHashMap(this.categories));
  32265. };
  32266. return OrdinalMeta;
  32267. }();
  32268. function getName(obj) {
  32269. if (isObject(obj) && obj.value != null) {
  32270. return obj.value;
  32271. } else {
  32272. return obj + '';
  32273. }
  32274. }
  32275. var OrdinalScale = /** @class */function (_super) {
  32276. __extends(OrdinalScale, _super);
  32277. function OrdinalScale(setting) {
  32278. var _this = _super.call(this, setting) || this;
  32279. _this.type = 'ordinal';
  32280. var ordinalMeta = _this.getSetting('ordinalMeta');
  32281. // Caution: Should not use instanceof, consider ec-extensions using
  32282. // import approach to get OrdinalMeta class.
  32283. if (!ordinalMeta) {
  32284. ordinalMeta = new OrdinalMeta({});
  32285. }
  32286. if (isArray(ordinalMeta)) {
  32287. ordinalMeta = new OrdinalMeta({
  32288. categories: map(ordinalMeta, function (item) {
  32289. return isObject(item) ? item.value : item;
  32290. })
  32291. });
  32292. }
  32293. _this._ordinalMeta = ordinalMeta;
  32294. _this._extent = _this.getSetting('extent') || [0, ordinalMeta.categories.length - 1];
  32295. return _this;
  32296. }
  32297. OrdinalScale.prototype.parse = function (val) {
  32298. // Caution: Math.round(null) will return `0` rather than `NaN`
  32299. if (val == null) {
  32300. return NaN;
  32301. }
  32302. return isString(val) ? this._ordinalMeta.getOrdinal(val)
  32303. // val might be float.
  32304. : Math.round(val);
  32305. };
  32306. OrdinalScale.prototype.contain = function (val) {
  32307. return contain$1(val, this._extent) && val >= 0 && val < this._ordinalMeta.categories.length;
  32308. };
  32309. /**
  32310. * Normalize given rank or name to linear [0, 1]
  32311. * @param val raw ordinal number.
  32312. * @return normalized value in [0, 1].
  32313. */
  32314. OrdinalScale.prototype.normalize = function (val) {
  32315. val = this._getTickNumber(val);
  32316. return this._calculator.normalize(val, this._extent);
  32317. };
  32318. /**
  32319. * @param val normalized value in [0, 1].
  32320. * @return raw ordinal number.
  32321. */
  32322. OrdinalScale.prototype.scale = function (val) {
  32323. val = Math.round(this._calculator.scale(val, this._extent));
  32324. return this.getRawOrdinalNumber(val);
  32325. };
  32326. OrdinalScale.prototype.getTicks = function () {
  32327. var ticks = [];
  32328. var extent = this._extent;
  32329. var rank = extent[0];
  32330. while (rank <= extent[1]) {
  32331. ticks.push({
  32332. value: rank
  32333. });
  32334. rank++;
  32335. }
  32336. return ticks;
  32337. };
  32338. OrdinalScale.prototype.getMinorTicks = function (splitNumber) {
  32339. // Not support.
  32340. return;
  32341. };
  32342. /**
  32343. * @see `Ordinal['_ordinalNumbersByTick']`
  32344. */
  32345. OrdinalScale.prototype.setSortInfo = function (info) {
  32346. if (info == null) {
  32347. this._ordinalNumbersByTick = this._ticksByOrdinalNumber = null;
  32348. return;
  32349. }
  32350. var infoOrdinalNumbers = info.ordinalNumbers;
  32351. var ordinalsByTick = this._ordinalNumbersByTick = [];
  32352. var ticksByOrdinal = this._ticksByOrdinalNumber = [];
  32353. // Unnecessary support negative tick in `realtimeSort`.
  32354. var tickNum = 0;
  32355. var allCategoryLen = this._ordinalMeta.categories.length;
  32356. for (var len = Math.min(allCategoryLen, infoOrdinalNumbers.length); tickNum < len; ++tickNum) {
  32357. var ordinalNumber = infoOrdinalNumbers[tickNum];
  32358. ordinalsByTick[tickNum] = ordinalNumber;
  32359. ticksByOrdinal[ordinalNumber] = tickNum;
  32360. }
  32361. // Handle that `series.data` only covers part of the `axis.category.data`.
  32362. var unusedOrdinal = 0;
  32363. for (; tickNum < allCategoryLen; ++tickNum) {
  32364. while (ticksByOrdinal[unusedOrdinal] != null) {
  32365. unusedOrdinal++;
  32366. }
  32367. ordinalsByTick.push(unusedOrdinal);
  32368. ticksByOrdinal[unusedOrdinal] = tickNum;
  32369. }
  32370. };
  32371. OrdinalScale.prototype._getTickNumber = function (ordinal) {
  32372. var ticksByOrdinalNumber = this._ticksByOrdinalNumber;
  32373. // also support ordinal out of range of `ordinalMeta.categories.length`,
  32374. // where ordinal numbers are used as tick value directly.
  32375. return ticksByOrdinalNumber && ordinal >= 0 && ordinal < ticksByOrdinalNumber.length ? ticksByOrdinalNumber[ordinal] : ordinal;
  32376. };
  32377. /**
  32378. * @usage
  32379. * ```js
  32380. * const ordinalNumber = ordinalScale.getRawOrdinalNumber(tickVal);
  32381. *
  32382. * // case0
  32383. * const rawOrdinalValue = axisModel.getCategories()[ordinalNumber];
  32384. * // case1
  32385. * const rawOrdinalValue = this._ordinalMeta.categories[ordinalNumber];
  32386. * // case2
  32387. * const coord = axis.dataToCoord(ordinalNumber);
  32388. * ```
  32389. *
  32390. * @param {OrdinalNumber} tickNumber index of display
  32391. */
  32392. OrdinalScale.prototype.getRawOrdinalNumber = function (tickNumber) {
  32393. var ordinalNumbersByTick = this._ordinalNumbersByTick;
  32394. // tickNumber may be out of range, e.g., when axis max is larger than `ordinalMeta.categories.length`.,
  32395. // where ordinal numbers are used as tick value directly.
  32396. return ordinalNumbersByTick && tickNumber >= 0 && tickNumber < ordinalNumbersByTick.length ? ordinalNumbersByTick[tickNumber] : tickNumber;
  32397. };
  32398. /**
  32399. * Get item on tick
  32400. */
  32401. OrdinalScale.prototype.getLabel = function (tick) {
  32402. if (!this.isBlank()) {
  32403. var ordinalNumber = this.getRawOrdinalNumber(tick.value);
  32404. var cateogry = this._ordinalMeta.categories[ordinalNumber];
  32405. // Note that if no data, ordinalMeta.categories is an empty array.
  32406. // Return empty if it's not exist.
  32407. return cateogry == null ? '' : cateogry + '';
  32408. }
  32409. };
  32410. OrdinalScale.prototype.count = function () {
  32411. return this._extent[1] - this._extent[0] + 1;
  32412. };
  32413. /**
  32414. * @override
  32415. * If value is in extent range
  32416. */
  32417. OrdinalScale.prototype.isInExtentRange = function (value) {
  32418. value = this._getTickNumber(value);
  32419. return this._extent[0] <= value && this._extent[1] >= value;
  32420. };
  32421. OrdinalScale.prototype.getOrdinalMeta = function () {
  32422. return this._ordinalMeta;
  32423. };
  32424. OrdinalScale.prototype.calcNiceTicks = function () {};
  32425. OrdinalScale.prototype.calcNiceExtent = function () {};
  32426. OrdinalScale.type = 'ordinal';
  32427. return OrdinalScale;
  32428. }(Scale);
  32429. Scale.registerClass(OrdinalScale);
  32430. var roundNumber = round;
  32431. var IntervalScale = /** @class */function (_super) {
  32432. __extends(IntervalScale, _super);
  32433. function IntervalScale() {
  32434. var _this = _super !== null && _super.apply(this, arguments) || this;
  32435. _this.type = 'interval';
  32436. // Step is calculated in adjustExtent.
  32437. _this._interval = 0;
  32438. _this._intervalPrecision = 2;
  32439. return _this;
  32440. }
  32441. IntervalScale.prototype.parse = function (val) {
  32442. // `Scale#parse` (and its overrids) are typically applied at the axis values input
  32443. // in echarts option. e.g., `axis.min/max`, `dataZoom.min/max`, etc.
  32444. // but `series.data` is not included, which uses `dataValueHelper.ts`#`parseDataValue`.
  32445. // `Scale#parse` originally introduced in fb8c813215098b9d2458966229bb95c510883d5e
  32446. // at 2016 for dataZoom start/end settings (See `parseAxisModelMinMax`).
  32447. //
  32448. // Historically `scale/Interval.ts` returns the input value directly. But numeric
  32449. // values (such as a number-like string '123') effectively passed through here and
  32450. // were involved in calculations, which was error-prone and inconsistent with the
  32451. // declared TS return type. Previously such issues are fixed separately in different
  32452. // places case by case (such as #2475).
  32453. //
  32454. // Now, we perform actual parse to ensure its `number` type here. The parsing rule
  32455. // follows the series data parsing rule (`dataValueHelper.ts`#`parseDataValue`)
  32456. // and maintains compatibility as much as possible (thus a more strict parsing
  32457. // `number.ts`#`numericToNumber` is not used here.)
  32458. //
  32459. // FIXME: `ScaleDataValue` also need to be modified to include numeric string type,
  32460. // since it effectively does.
  32461. return val == null || val === '' ? NaN
  32462. // If string (like '-'), using '+' parse to NaN
  32463. // If object, also parse to NaN
  32464. : Number(val);
  32465. };
  32466. IntervalScale.prototype.contain = function (val) {
  32467. return contain$1(val, this._extent);
  32468. };
  32469. IntervalScale.prototype.normalize = function (val) {
  32470. return this._calculator.normalize(val, this._extent);
  32471. };
  32472. IntervalScale.prototype.scale = function (val) {
  32473. return this._calculator.scale(val, this._extent);
  32474. };
  32475. IntervalScale.prototype.getInterval = function () {
  32476. return this._interval;
  32477. };
  32478. IntervalScale.prototype.setInterval = function (interval) {
  32479. this._interval = interval;
  32480. // Dropped auto calculated niceExtent and use user-set extent.
  32481. // We assume user wants to set both interval, min, max to get a better result.
  32482. this._niceExtent = this._extent.slice();
  32483. this._intervalPrecision = getIntervalPrecision(interval);
  32484. };
  32485. /**
  32486. * @override
  32487. */
  32488. IntervalScale.prototype.getTicks = function (opt) {
  32489. opt = opt || {};
  32490. var interval = this._interval;
  32491. var extent = this._extent;
  32492. var niceTickExtent = this._niceExtent;
  32493. var intervalPrecision = this._intervalPrecision;
  32494. var scaleBreakHelper = getScaleBreakHelper();
  32495. var ticks = [];
  32496. // If interval is 0, return [];
  32497. if (!interval) {
  32498. return ticks;
  32499. }
  32500. if (opt.breakTicks === 'only_break' && scaleBreakHelper) {
  32501. scaleBreakHelper.addBreaksToTicks(ticks, this._brkCtx.breaks, this._extent);
  32502. return ticks;
  32503. }
  32504. // Consider this case: using dataZoom toolbox, zoom and zoom.
  32505. var safeLimit = 10000;
  32506. if (extent[0] < niceTickExtent[0]) {
  32507. if (opt.expandToNicedExtent) {
  32508. ticks.push({
  32509. value: roundNumber(niceTickExtent[0] - interval, intervalPrecision)
  32510. });
  32511. } else {
  32512. ticks.push({
  32513. value: extent[0]
  32514. });
  32515. }
  32516. }
  32517. var estimateNiceMultiple = function (tickVal, targetTick) {
  32518. return Math.round((targetTick - tickVal) / interval);
  32519. };
  32520. var tick = niceTickExtent[0];
  32521. while (tick <= niceTickExtent[1]) {
  32522. ticks.push({
  32523. value: tick
  32524. });
  32525. // Avoid rounding error
  32526. tick = roundNumber(tick + interval, intervalPrecision);
  32527. if (this._brkCtx) {
  32528. var moreMultiple = this._brkCtx.calcNiceTickMultiple(tick, estimateNiceMultiple);
  32529. if (moreMultiple >= 0) {
  32530. tick = roundNumber(tick + moreMultiple * interval, intervalPrecision);
  32531. }
  32532. }
  32533. if (ticks.length > 0 && tick === ticks[ticks.length - 1].value) {
  32534. // Consider out of safe float point, e.g.,
  32535. // -3711126.9907707 + 2e-10 === -3711126.9907707
  32536. break;
  32537. }
  32538. if (ticks.length > safeLimit) {
  32539. return [];
  32540. }
  32541. }
  32542. // Consider this case: the last item of ticks is smaller
  32543. // than niceTickExtent[1] and niceTickExtent[1] === extent[1].
  32544. var lastNiceTick = ticks.length ? ticks[ticks.length - 1].value : niceTickExtent[1];
  32545. if (extent[1] > lastNiceTick) {
  32546. if (opt.expandToNicedExtent) {
  32547. ticks.push({
  32548. value: roundNumber(lastNiceTick + interval, intervalPrecision)
  32549. });
  32550. } else {
  32551. ticks.push({
  32552. value: extent[1]
  32553. });
  32554. }
  32555. }
  32556. if (scaleBreakHelper) {
  32557. scaleBreakHelper.pruneTicksByBreak(opt.pruneByBreak, ticks, this._brkCtx.breaks, function (item) {
  32558. return item.value;
  32559. }, this._interval, this._extent);
  32560. }
  32561. if (opt.breakTicks !== 'none' && scaleBreakHelper) {
  32562. scaleBreakHelper.addBreaksToTicks(ticks, this._brkCtx.breaks, this._extent);
  32563. }
  32564. return ticks;
  32565. };
  32566. IntervalScale.prototype.getMinorTicks = function (splitNumber) {
  32567. var ticks = this.getTicks({
  32568. expandToNicedExtent: true
  32569. });
  32570. // NOTE: In log-scale, do not support minor ticks when breaks exist.
  32571. // because currently log-scale minor ticks is calculated based on raw values
  32572. // rather than log-transformed value, due to an odd effect when breaks exist.
  32573. var minorTicks = [];
  32574. var extent = this.getExtent();
  32575. for (var i = 1; i < ticks.length; i++) {
  32576. var nextTick = ticks[i];
  32577. var prevTick = ticks[i - 1];
  32578. if (prevTick["break"] || nextTick["break"]) {
  32579. // Do not build minor ticks to the adjacent ticks to breaks ticks,
  32580. // since the interval might be irregular.
  32581. continue;
  32582. }
  32583. var count = 0;
  32584. var minorTicksGroup = [];
  32585. var interval = nextTick.value - prevTick.value;
  32586. var minorInterval = interval / splitNumber;
  32587. var minorIntervalPrecision = getIntervalPrecision(minorInterval);
  32588. while (count < splitNumber - 1) {
  32589. var minorTick = roundNumber(prevTick.value + (count + 1) * minorInterval, minorIntervalPrecision);
  32590. // For the first and last interval. The count may be less than splitNumber.
  32591. if (minorTick > extent[0] && minorTick < extent[1]) {
  32592. minorTicksGroup.push(minorTick);
  32593. }
  32594. count++;
  32595. }
  32596. var scaleBreakHelper = getScaleBreakHelper();
  32597. scaleBreakHelper && scaleBreakHelper.pruneTicksByBreak('auto', minorTicksGroup, this._getNonTransBreaks(), function (value) {
  32598. return value;
  32599. }, this._interval, extent);
  32600. minorTicks.push(minorTicksGroup);
  32601. }
  32602. return minorTicks;
  32603. };
  32604. IntervalScale.prototype._getNonTransBreaks = function () {
  32605. return this._brkCtx ? this._brkCtx.breaks : [];
  32606. };
  32607. /**
  32608. * @param opt.precision If 'auto', use nice presision.
  32609. * @param opt.pad returns 1.50 but not 1.5 if precision is 2.
  32610. */
  32611. IntervalScale.prototype.getLabel = function (data, opt) {
  32612. if (data == null) {
  32613. return '';
  32614. }
  32615. var precision = opt && opt.precision;
  32616. if (precision == null) {
  32617. precision = getPrecision(data.value) || 0;
  32618. } else if (precision === 'auto') {
  32619. // Should be more precise then tick.
  32620. precision = this._intervalPrecision;
  32621. }
  32622. // (1) If `precision` is set, 12.005 should be display as '12.00500'.
  32623. // (2) Use roundNumber (toFixed) to avoid scientific notation like '3.5e-7'.
  32624. var dataNum = roundNumber(data.value, precision, true);
  32625. return addCommas(dataNum);
  32626. };
  32627. /**
  32628. * FIXME: refactor - disallow override, use composition instead.
  32629. *
  32630. * The override of `calcNiceTicks` should ensure these members are provided:
  32631. * this._intervalPrecision
  32632. * this._interval
  32633. *
  32634. * @param splitNumber By default `5`.
  32635. */
  32636. IntervalScale.prototype.calcNiceTicks = function (splitNumber, minInterval, maxInterval) {
  32637. splitNumber = splitNumber || 5;
  32638. var extent = this._extent.slice();
  32639. var span = this._getExtentSpanWithBreaks();
  32640. if (!isFinite(span)) {
  32641. return;
  32642. }
  32643. // User may set axis min 0 and data are all negative
  32644. // FIXME If it needs to reverse ?
  32645. if (span < 0) {
  32646. span = -span;
  32647. extent.reverse();
  32648. this._innerSetExtent(extent[0], extent[1]);
  32649. extent = this._extent.slice();
  32650. }
  32651. var result = intervalScaleNiceTicks(extent, span, splitNumber, minInterval, maxInterval);
  32652. this._intervalPrecision = result.intervalPrecision;
  32653. this._interval = result.interval;
  32654. this._niceExtent = result.niceTickExtent;
  32655. };
  32656. IntervalScale.prototype.calcNiceExtent = function (opt) {
  32657. var extent = this._extent.slice();
  32658. // If extent start and end are same, expand them
  32659. if (extent[0] === extent[1]) {
  32660. if (extent[0] !== 0) {
  32661. // Expand extent
  32662. // Note that extents can be both negative. See #13154
  32663. var expandSize = Math.abs(extent[0]);
  32664. // In the fowllowing case
  32665. // Axis has been fixed max 100
  32666. // Plus data are all 100 and axis extent are [100, 100].
  32667. // Extend to the both side will cause expanded max is larger than fixed max.
  32668. // So only expand to the smaller side.
  32669. if (!opt.fixMax) {
  32670. extent[1] += expandSize / 2;
  32671. extent[0] -= expandSize / 2;
  32672. } else {
  32673. extent[0] -= expandSize / 2;
  32674. }
  32675. } else {
  32676. extent[1] = 1;
  32677. }
  32678. }
  32679. var span = extent[1] - extent[0];
  32680. // If there are no data and extent are [Infinity, -Infinity]
  32681. if (!isFinite(span)) {
  32682. extent[0] = 0;
  32683. extent[1] = 1;
  32684. }
  32685. this._innerSetExtent(extent[0], extent[1]);
  32686. extent = this._extent.slice();
  32687. this.calcNiceTicks(opt.splitNumber, opt.minInterval, opt.maxInterval);
  32688. var interval = this._interval;
  32689. var intervalPrecition = this._intervalPrecision;
  32690. if (!opt.fixMin) {
  32691. extent[0] = roundNumber(Math.floor(extent[0] / interval) * interval, intervalPrecition);
  32692. }
  32693. if (!opt.fixMax) {
  32694. extent[1] = roundNumber(Math.ceil(extent[1] / interval) * interval, intervalPrecition);
  32695. }
  32696. this._innerSetExtent(extent[0], extent[1]);
  32697. };
  32698. IntervalScale.prototype.setNiceExtent = function (min, max) {
  32699. this._niceExtent = [min, max];
  32700. };
  32701. IntervalScale.type = 'interval';
  32702. return IntervalScale;
  32703. }(Scale);
  32704. Scale.registerClass(IntervalScale);
  32705. /* global Float32Array */
  32706. var supportFloat32Array = typeof Float32Array !== 'undefined';
  32707. var Float32ArrayCtor = !supportFloat32Array ? Array : Float32Array;
  32708. function createFloat32Array(arg) {
  32709. if (isArray(arg)) {
  32710. // Return self directly if don't support TypedArray.
  32711. return supportFloat32Array ? new Float32Array(arg) : arg;
  32712. }
  32713. // Else is number
  32714. return new Float32ArrayCtor(arg);
  32715. }
  32716. var STACK_PREFIX = '__ec_stack_';
  32717. function getSeriesStackId(seriesModel) {
  32718. return seriesModel.get('stack') || STACK_PREFIX + seriesModel.seriesIndex;
  32719. }
  32720. function getAxisKey(axis) {
  32721. return axis.dim + axis.index;
  32722. }
  32723. /**
  32724. * @return {Object} {width, offset, offsetCenter} If axis.type is not 'category', return undefined.
  32725. */
  32726. function getLayoutOnAxis(opt) {
  32727. var params = [];
  32728. var baseAxis = opt.axis;
  32729. var axisKey = 'axis0';
  32730. if (baseAxis.type !== 'category') {
  32731. return;
  32732. }
  32733. var bandWidth = baseAxis.getBandWidth();
  32734. for (var i = 0; i < opt.count || 0; i++) {
  32735. params.push(defaults({
  32736. bandWidth: bandWidth,
  32737. axisKey: axisKey,
  32738. stackId: STACK_PREFIX + i
  32739. }, opt));
  32740. }
  32741. var widthAndOffsets = doCalBarWidthAndOffset(params);
  32742. var result = [];
  32743. for (var i = 0; i < opt.count; i++) {
  32744. var item = widthAndOffsets[axisKey][STACK_PREFIX + i];
  32745. item.offsetCenter = item.offset + item.width / 2;
  32746. result.push(item);
  32747. }
  32748. return result;
  32749. }
  32750. function prepareLayoutBarSeries(seriesType, ecModel) {
  32751. var seriesModels = [];
  32752. ecModel.eachSeriesByType(seriesType, function (seriesModel) {
  32753. // Check series coordinate, do layout for cartesian2d only
  32754. if (isOnCartesian(seriesModel)) {
  32755. seriesModels.push(seriesModel);
  32756. }
  32757. });
  32758. return seriesModels;
  32759. }
  32760. /**
  32761. * Map from (baseAxis.dim + '_' + baseAxis.index) to min gap of two adjacent
  32762. * values.
  32763. * This works for time axes, value axes, and log axes.
  32764. * For a single time axis, return value is in the form like
  32765. * {'x_0': [1000000]}.
  32766. * The value of 1000000 is in milliseconds.
  32767. */
  32768. function getValueAxesMinGaps(barSeries) {
  32769. /**
  32770. * Map from axis.index to values.
  32771. * For a single time axis, axisValues is in the form like
  32772. * {'x_0': [1495555200000, 1495641600000, 1495728000000]}.
  32773. * Items in axisValues[x], e.g. 1495555200000, are time values of all
  32774. * series.
  32775. */
  32776. var axisValues = {};
  32777. each(barSeries, function (seriesModel) {
  32778. var cartesian = seriesModel.coordinateSystem;
  32779. var baseAxis = cartesian.getBaseAxis();
  32780. if (baseAxis.type !== 'time' && baseAxis.type !== 'value') {
  32781. return;
  32782. }
  32783. var data = seriesModel.getData();
  32784. var key = baseAxis.dim + '_' + baseAxis.index;
  32785. var dimIdx = data.getDimensionIndex(data.mapDimension(baseAxis.dim));
  32786. var store = data.getStore();
  32787. for (var i = 0, cnt = store.count(); i < cnt; ++i) {
  32788. var value = store.get(dimIdx, i);
  32789. if (!axisValues[key]) {
  32790. // No previous data for the axis
  32791. axisValues[key] = [value];
  32792. } else {
  32793. // No value in previous series
  32794. axisValues[key].push(value);
  32795. }
  32796. // Ignore duplicated time values in the same axis
  32797. }
  32798. });
  32799. var axisMinGaps = {};
  32800. for (var key in axisValues) {
  32801. if (axisValues.hasOwnProperty(key)) {
  32802. var valuesInAxis = axisValues[key];
  32803. if (valuesInAxis) {
  32804. // Sort axis values into ascending order to calculate gaps
  32805. valuesInAxis.sort(function (a, b) {
  32806. return a - b;
  32807. });
  32808. var min = null;
  32809. for (var j = 1; j < valuesInAxis.length; ++j) {
  32810. var delta = valuesInAxis[j] - valuesInAxis[j - 1];
  32811. if (delta > 0) {
  32812. // Ignore 0 delta because they are of the same axis value
  32813. min = min === null ? delta : Math.min(min, delta);
  32814. }
  32815. }
  32816. // Set to null if only have one data
  32817. axisMinGaps[key] = min;
  32818. }
  32819. }
  32820. }
  32821. return axisMinGaps;
  32822. }
  32823. function makeColumnLayout(barSeries) {
  32824. var axisMinGaps = getValueAxesMinGaps(barSeries);
  32825. var seriesInfoList = [];
  32826. each(barSeries, function (seriesModel) {
  32827. var cartesian = seriesModel.coordinateSystem;
  32828. var baseAxis = cartesian.getBaseAxis();
  32829. var axisExtent = baseAxis.getExtent();
  32830. var bandWidth;
  32831. if (baseAxis.type === 'category') {
  32832. bandWidth = baseAxis.getBandWidth();
  32833. } else if (baseAxis.type === 'value' || baseAxis.type === 'time') {
  32834. var key = baseAxis.dim + '_' + baseAxis.index;
  32835. var minGap = axisMinGaps[key];
  32836. var extentSpan = Math.abs(axisExtent[1] - axisExtent[0]);
  32837. var scale = baseAxis.scale.getExtent();
  32838. var scaleSpan = Math.abs(scale[1] - scale[0]);
  32839. bandWidth = minGap ? extentSpan / scaleSpan * minGap : extentSpan; // When there is only one data value
  32840. } else {
  32841. var data = seriesModel.getData();
  32842. bandWidth = Math.abs(axisExtent[1] - axisExtent[0]) / data.count();
  32843. }
  32844. var barWidth = parsePercent$1(seriesModel.get('barWidth'), bandWidth);
  32845. var barMaxWidth = parsePercent$1(seriesModel.get('barMaxWidth'), bandWidth);
  32846. var barMinWidth = parsePercent$1(
  32847. // barMinWidth by default is 0.5 / 1 in cartesian. Because in value axis,
  32848. // the auto-calculated bar width might be less than 0.5 / 1.
  32849. seriesModel.get('barMinWidth') || (isInLargeMode(seriesModel) ? 0.5 : 1), bandWidth);
  32850. var barGap = seriesModel.get('barGap');
  32851. var barCategoryGap = seriesModel.get('barCategoryGap');
  32852. var defaultBarGap = seriesModel.get('defaultBarGap');
  32853. seriesInfoList.push({
  32854. bandWidth: bandWidth,
  32855. barWidth: barWidth,
  32856. barMaxWidth: barMaxWidth,
  32857. barMinWidth: barMinWidth,
  32858. barGap: barGap,
  32859. barCategoryGap: barCategoryGap,
  32860. defaultBarGap: defaultBarGap,
  32861. axisKey: getAxisKey(baseAxis),
  32862. stackId: getSeriesStackId(seriesModel)
  32863. });
  32864. });
  32865. return doCalBarWidthAndOffset(seriesInfoList);
  32866. }
  32867. function doCalBarWidthAndOffset(seriesInfoList) {
  32868. // Columns info on each category axis. Key is cartesian name
  32869. var columnsMap = {};
  32870. each(seriesInfoList, function (seriesInfo, idx) {
  32871. var axisKey = seriesInfo.axisKey;
  32872. var bandWidth = seriesInfo.bandWidth;
  32873. var columnsOnAxis = columnsMap[axisKey] || {
  32874. bandWidth: bandWidth,
  32875. remainedWidth: bandWidth,
  32876. autoWidthCount: 0,
  32877. categoryGap: null,
  32878. gap: seriesInfo.defaultBarGap || 0,
  32879. stacks: {}
  32880. };
  32881. var stacks = columnsOnAxis.stacks;
  32882. columnsMap[axisKey] = columnsOnAxis;
  32883. var stackId = seriesInfo.stackId;
  32884. if (!stacks[stackId]) {
  32885. columnsOnAxis.autoWidthCount++;
  32886. }
  32887. stacks[stackId] = stacks[stackId] || {
  32888. width: 0,
  32889. maxWidth: 0
  32890. };
  32891. // Caution: In a single coordinate system, these barGrid attributes
  32892. // will be shared by series. Consider that they have default values,
  32893. // only the attributes set on the last series will work.
  32894. // Do not change this fact unless there will be a break change.
  32895. var barWidth = seriesInfo.barWidth;
  32896. if (barWidth && !stacks[stackId].width) {
  32897. // See #6312, do not restrict width.
  32898. stacks[stackId].width = barWidth;
  32899. barWidth = Math.min(columnsOnAxis.remainedWidth, barWidth);
  32900. columnsOnAxis.remainedWidth -= barWidth;
  32901. }
  32902. var barMaxWidth = seriesInfo.barMaxWidth;
  32903. barMaxWidth && (stacks[stackId].maxWidth = barMaxWidth);
  32904. var barMinWidth = seriesInfo.barMinWidth;
  32905. barMinWidth && (stacks[stackId].minWidth = barMinWidth);
  32906. var barGap = seriesInfo.barGap;
  32907. barGap != null && (columnsOnAxis.gap = barGap);
  32908. var barCategoryGap = seriesInfo.barCategoryGap;
  32909. barCategoryGap != null && (columnsOnAxis.categoryGap = barCategoryGap);
  32910. });
  32911. var result = {};
  32912. each(columnsMap, function (columnsOnAxis, coordSysName) {
  32913. result[coordSysName] = {};
  32914. var stacks = columnsOnAxis.stacks;
  32915. var bandWidth = columnsOnAxis.bandWidth;
  32916. var categoryGapPercent = columnsOnAxis.categoryGap;
  32917. if (categoryGapPercent == null) {
  32918. var columnCount = keys(stacks).length;
  32919. // More columns in one group
  32920. // the spaces between group is smaller. Or the column will be too thin.
  32921. categoryGapPercent = Math.max(35 - columnCount * 4, 15) + '%';
  32922. }
  32923. var categoryGap = parsePercent$1(categoryGapPercent, bandWidth);
  32924. var barGapPercent = parsePercent$1(columnsOnAxis.gap, 1);
  32925. var remainedWidth = columnsOnAxis.remainedWidth;
  32926. var autoWidthCount = columnsOnAxis.autoWidthCount;
  32927. var autoWidth = (remainedWidth - categoryGap) / (autoWidthCount + (autoWidthCount - 1) * barGapPercent);
  32928. autoWidth = Math.max(autoWidth, 0);
  32929. // Find if any auto calculated bar exceeded maxBarWidth
  32930. each(stacks, function (column) {
  32931. var maxWidth = column.maxWidth;
  32932. var minWidth = column.minWidth;
  32933. if (!column.width) {
  32934. var finalWidth = autoWidth;
  32935. if (maxWidth && maxWidth < finalWidth) {
  32936. finalWidth = Math.min(maxWidth, remainedWidth);
  32937. }
  32938. // `minWidth` has higher priority. `minWidth` decide that whether the
  32939. // bar is able to be visible. So `minWidth` should not be restricted
  32940. // by `maxWidth` or `remainedWidth` (which is from `bandWidth`). In
  32941. // the extreme cases for `value` axis, bars are allowed to overlap
  32942. // with each other if `minWidth` specified.
  32943. if (minWidth && minWidth > finalWidth) {
  32944. finalWidth = minWidth;
  32945. }
  32946. if (finalWidth !== autoWidth) {
  32947. column.width = finalWidth;
  32948. remainedWidth -= finalWidth + barGapPercent * finalWidth;
  32949. autoWidthCount--;
  32950. }
  32951. } else {
  32952. // `barMinWidth/barMaxWidth` has higher priority than `barWidth`, as
  32953. // CSS does. Because barWidth can be a percent value, where
  32954. // `barMaxWidth` can be used to restrict the final width.
  32955. var finalWidth = column.width;
  32956. if (maxWidth) {
  32957. finalWidth = Math.min(finalWidth, maxWidth);
  32958. }
  32959. // `minWidth` has higher priority, as described above
  32960. if (minWidth) {
  32961. finalWidth = Math.max(finalWidth, minWidth);
  32962. }
  32963. column.width = finalWidth;
  32964. remainedWidth -= finalWidth + barGapPercent * finalWidth;
  32965. autoWidthCount--;
  32966. }
  32967. });
  32968. // Recalculate width again
  32969. autoWidth = (remainedWidth - categoryGap) / (autoWidthCount + (autoWidthCount - 1) * barGapPercent);
  32970. autoWidth = Math.max(autoWidth, 0);
  32971. var widthSum = 0;
  32972. var lastColumn;
  32973. each(stacks, function (column, idx) {
  32974. if (!column.width) {
  32975. column.width = autoWidth;
  32976. }
  32977. lastColumn = column;
  32978. widthSum += column.width * (1 + barGapPercent);
  32979. });
  32980. if (lastColumn) {
  32981. widthSum -= lastColumn.width * barGapPercent;
  32982. }
  32983. var offset = -widthSum / 2;
  32984. each(stacks, function (column, stackId) {
  32985. result[coordSysName][stackId] = result[coordSysName][stackId] || {
  32986. bandWidth: bandWidth,
  32987. offset: offset,
  32988. width: column.width
  32989. };
  32990. offset += column.width * (1 + barGapPercent);
  32991. });
  32992. });
  32993. return result;
  32994. }
  32995. function retrieveColumnLayout(barWidthAndOffset, axis, seriesModel) {
  32996. if (barWidthAndOffset && axis) {
  32997. var result = barWidthAndOffset[getAxisKey(axis)];
  32998. if (result != null && seriesModel != null) {
  32999. return result[getSeriesStackId(seriesModel)];
  33000. }
  33001. return result;
  33002. }
  33003. }
  33004. function layout(seriesType, ecModel) {
  33005. var seriesModels = prepareLayoutBarSeries(seriesType, ecModel);
  33006. var barWidthAndOffset = makeColumnLayout(seriesModels);
  33007. each(seriesModels, function (seriesModel) {
  33008. var data = seriesModel.getData();
  33009. var cartesian = seriesModel.coordinateSystem;
  33010. var baseAxis = cartesian.getBaseAxis();
  33011. var stackId = getSeriesStackId(seriesModel);
  33012. var columnLayoutInfo = barWidthAndOffset[getAxisKey(baseAxis)][stackId];
  33013. var columnOffset = columnLayoutInfo.offset;
  33014. var columnWidth = columnLayoutInfo.width;
  33015. data.setLayout({
  33016. bandWidth: columnLayoutInfo.bandWidth,
  33017. offset: columnOffset,
  33018. size: columnWidth
  33019. });
  33020. });
  33021. }
  33022. // TODO: Do not support stack in large mode yet.
  33023. function createProgressiveLayout(seriesType) {
  33024. return {
  33025. seriesType: seriesType,
  33026. plan: createRenderPlanner(),
  33027. reset: function (seriesModel) {
  33028. if (!isOnCartesian(seriesModel)) {
  33029. return;
  33030. }
  33031. var data = seriesModel.getData();
  33032. var cartesian = seriesModel.coordinateSystem;
  33033. var baseAxis = cartesian.getBaseAxis();
  33034. var valueAxis = cartesian.getOtherAxis(baseAxis);
  33035. var valueDimIdx = data.getDimensionIndex(data.mapDimension(valueAxis.dim));
  33036. var baseDimIdx = data.getDimensionIndex(data.mapDimension(baseAxis.dim));
  33037. var drawBackground = seriesModel.get('showBackground', true);
  33038. var valueDim = data.mapDimension(valueAxis.dim);
  33039. var stackResultDim = data.getCalculationInfo('stackResultDimension');
  33040. var stacked = isDimensionStacked(data, valueDim) && !!data.getCalculationInfo('stackedOnSeries');
  33041. var isValueAxisH = valueAxis.isHorizontal();
  33042. var valueAxisStart = getValueAxisStart(baseAxis, valueAxis);
  33043. var isLarge = isInLargeMode(seriesModel);
  33044. var barMinHeight = seriesModel.get('barMinHeight') || 0;
  33045. var stackedDimIdx = stackResultDim && data.getDimensionIndex(stackResultDim);
  33046. // Layout info.
  33047. var columnWidth = data.getLayout('size');
  33048. var columnOffset = data.getLayout('offset');
  33049. return {
  33050. progress: function (params, data) {
  33051. var count = params.count;
  33052. var largePoints = isLarge && createFloat32Array(count * 3);
  33053. var largeBackgroundPoints = isLarge && drawBackground && createFloat32Array(count * 3);
  33054. var largeDataIndices = isLarge && createFloat32Array(count);
  33055. var coordLayout = cartesian.master.getRect();
  33056. var bgSize = isValueAxisH ? coordLayout.width : coordLayout.height;
  33057. var dataIndex;
  33058. var store = data.getStore();
  33059. var idxOffset = 0;
  33060. while ((dataIndex = params.next()) != null) {
  33061. var value = store.get(stacked ? stackedDimIdx : valueDimIdx, dataIndex);
  33062. var baseValue = store.get(baseDimIdx, dataIndex);
  33063. var baseCoord = valueAxisStart;
  33064. var stackStartValue = void 0;
  33065. // Because of the barMinHeight, we can not use the value in
  33066. // stackResultDimension directly.
  33067. if (stacked) {
  33068. stackStartValue = +value - store.get(valueDimIdx, dataIndex);
  33069. }
  33070. var x = void 0;
  33071. var y = void 0;
  33072. var width = void 0;
  33073. var height = void 0;
  33074. if (isValueAxisH) {
  33075. var coord = cartesian.dataToPoint([value, baseValue]);
  33076. if (stacked) {
  33077. var startCoord = cartesian.dataToPoint([stackStartValue, baseValue]);
  33078. baseCoord = startCoord[0];
  33079. }
  33080. x = baseCoord;
  33081. y = coord[1] + columnOffset;
  33082. width = coord[0] - baseCoord;
  33083. height = columnWidth;
  33084. if (Math.abs(width) < barMinHeight) {
  33085. width = (width < 0 ? -1 : 1) * barMinHeight;
  33086. }
  33087. } else {
  33088. var coord = cartesian.dataToPoint([baseValue, value]);
  33089. if (stacked) {
  33090. var startCoord = cartesian.dataToPoint([baseValue, stackStartValue]);
  33091. baseCoord = startCoord[1];
  33092. }
  33093. x = coord[0] + columnOffset;
  33094. y = baseCoord;
  33095. width = columnWidth;
  33096. height = coord[1] - baseCoord;
  33097. if (Math.abs(height) < barMinHeight) {
  33098. // Include zero to has a positive bar
  33099. height = (height <= 0 ? -1 : 1) * barMinHeight;
  33100. }
  33101. }
  33102. if (!isLarge) {
  33103. data.setItemLayout(dataIndex, {
  33104. x: x,
  33105. y: y,
  33106. width: width,
  33107. height: height
  33108. });
  33109. } else {
  33110. largePoints[idxOffset] = x;
  33111. largePoints[idxOffset + 1] = y;
  33112. largePoints[idxOffset + 2] = isValueAxisH ? width : height;
  33113. if (largeBackgroundPoints) {
  33114. largeBackgroundPoints[idxOffset] = isValueAxisH ? coordLayout.x : x;
  33115. largeBackgroundPoints[idxOffset + 1] = isValueAxisH ? y : coordLayout.y;
  33116. largeBackgroundPoints[idxOffset + 2] = bgSize;
  33117. }
  33118. largeDataIndices[dataIndex] = dataIndex;
  33119. }
  33120. idxOffset += 3;
  33121. }
  33122. if (isLarge) {
  33123. data.setLayout({
  33124. largePoints: largePoints,
  33125. largeDataIndices: largeDataIndices,
  33126. largeBackgroundPoints: largeBackgroundPoints,
  33127. valueAxisHorizontal: isValueAxisH
  33128. });
  33129. }
  33130. }
  33131. };
  33132. }
  33133. };
  33134. }
  33135. function isOnCartesian(seriesModel) {
  33136. return seriesModel.coordinateSystem && seriesModel.coordinateSystem.type === 'cartesian2d';
  33137. }
  33138. function isInLargeMode(seriesModel) {
  33139. return seriesModel.pipelineContext && seriesModel.pipelineContext.large;
  33140. }
  33141. // See cases in `test/bar-start.html` and `#7412`, `#8747`.
  33142. function getValueAxisStart(baseAxis, valueAxis) {
  33143. var startValue = valueAxis.model.get('startValue');
  33144. if (!startValue) {
  33145. startValue = 0;
  33146. }
  33147. return valueAxis.toGlobalCoord(valueAxis.dataToCoord(valueAxis.type === 'log' ? startValue > 0 ? startValue : 1 : startValue));
  33148. }
  33149. // FIXME 公用?
  33150. var bisect = function (a, x, lo, hi) {
  33151. while (lo < hi) {
  33152. var mid = lo + hi >>> 1;
  33153. if (a[mid][1] < x) {
  33154. lo = mid + 1;
  33155. } else {
  33156. hi = mid;
  33157. }
  33158. }
  33159. return lo;
  33160. };
  33161. var TimeScale = /** @class */function (_super) {
  33162. __extends(TimeScale, _super);
  33163. function TimeScale(settings) {
  33164. var _this = _super.call(this, settings) || this;
  33165. _this.type = 'time';
  33166. return _this;
  33167. }
  33168. /**
  33169. * Get label is mainly for other components like dataZoom, tooltip.
  33170. */
  33171. TimeScale.prototype.getLabel = function (tick) {
  33172. var useUTC = this.getSetting('useUTC');
  33173. return format(tick.value, fullLeveledFormatter[getDefaultFormatPrecisionOfInterval(getPrimaryTimeUnit(this._minLevelUnit))] || fullLeveledFormatter.second, useUTC, this.getSetting('locale'));
  33174. };
  33175. TimeScale.prototype.getFormattedLabel = function (tick, idx, labelFormatter) {
  33176. var isUTC = this.getSetting('useUTC');
  33177. var lang = this.getSetting('locale');
  33178. return leveledFormat(tick, idx, labelFormatter, lang, isUTC);
  33179. };
  33180. /**
  33181. * @override
  33182. */
  33183. TimeScale.prototype.getTicks = function (opt) {
  33184. opt = opt || {};
  33185. var interval = this._interval;
  33186. var extent = this._extent;
  33187. var scaleBreakHelper = getScaleBreakHelper();
  33188. var ticks = [];
  33189. // If interval is 0, return [];
  33190. if (!interval) {
  33191. return ticks;
  33192. }
  33193. var useUTC = this.getSetting('useUTC');
  33194. if (scaleBreakHelper && opt.breakTicks === 'only_break') {
  33195. getScaleBreakHelper().addBreaksToTicks(ticks, this._brkCtx.breaks, this._extent);
  33196. return ticks;
  33197. }
  33198. var extent0Unit = getUnitFromValue(extent[1], useUTC);
  33199. ticks.push({
  33200. value: extent[0],
  33201. time: {
  33202. level: 0,
  33203. upperTimeUnit: extent0Unit,
  33204. lowerTimeUnit: extent0Unit
  33205. }
  33206. });
  33207. var innerTicks = getIntervalTicks(this._minLevelUnit, this._approxInterval, useUTC, extent, this._getExtentSpanWithBreaks(), this._brkCtx);
  33208. ticks = ticks.concat(innerTicks);
  33209. var extent1Unit = getUnitFromValue(extent[1], useUTC);
  33210. ticks.push({
  33211. value: extent[1],
  33212. time: {
  33213. level: 0,
  33214. upperTimeUnit: extent1Unit,
  33215. lowerTimeUnit: extent1Unit
  33216. }
  33217. });
  33218. var isUTC = this.getSetting('useUTC');
  33219. var upperUnitIndex = primaryTimeUnits.length - 1;
  33220. var maxLevel = 0;
  33221. each(ticks, function (tick) {
  33222. upperUnitIndex = Math.min(upperUnitIndex, indexOf(primaryTimeUnits, tick.time.upperTimeUnit));
  33223. maxLevel = Math.max(maxLevel, tick.time.level);
  33224. });
  33225. if (scaleBreakHelper) {
  33226. getScaleBreakHelper().pruneTicksByBreak(opt.pruneByBreak, ticks, this._brkCtx.breaks, function (item) {
  33227. return item.value;
  33228. }, this._approxInterval, this._extent);
  33229. }
  33230. if (scaleBreakHelper && opt.breakTicks !== 'none') {
  33231. getScaleBreakHelper().addBreaksToTicks(ticks, this._brkCtx.breaks, this._extent, function (trimmedBrk) {
  33232. // @see `parseTimeAxisLabelFormatterDictionary`.
  33233. var lowerBrkUnitIndex = Math.max(indexOf(primaryTimeUnits, getUnitFromValue(trimmedBrk.vmin, isUTC)), indexOf(primaryTimeUnits, getUnitFromValue(trimmedBrk.vmax, isUTC)));
  33234. var upperBrkUnitIndex = 0;
  33235. for (var unitIdx = 0; unitIdx < primaryTimeUnits.length; unitIdx++) {
  33236. if (!isPrimaryUnitValueAndGreaterSame(primaryTimeUnits[unitIdx], trimmedBrk.vmin, trimmedBrk.vmax, isUTC)) {
  33237. upperBrkUnitIndex = unitIdx;
  33238. break;
  33239. }
  33240. }
  33241. var upperIdx = Math.min(upperBrkUnitIndex, upperUnitIndex);
  33242. var lowerIdx = Math.max(upperIdx, lowerBrkUnitIndex);
  33243. return {
  33244. level: maxLevel,
  33245. lowerTimeUnit: primaryTimeUnits[lowerIdx],
  33246. upperTimeUnit: primaryTimeUnits[upperIdx]
  33247. };
  33248. });
  33249. }
  33250. return ticks;
  33251. };
  33252. TimeScale.prototype.calcNiceExtent = function (opt) {
  33253. var extent = this.getExtent();
  33254. // If extent start and end are same, expand them
  33255. if (extent[0] === extent[1]) {
  33256. // Expand extent
  33257. extent[0] -= ONE_DAY;
  33258. extent[1] += ONE_DAY;
  33259. }
  33260. // If there are no data and extent are [Infinity, -Infinity]
  33261. if (extent[1] === -Infinity && extent[0] === Infinity) {
  33262. var d = new Date();
  33263. extent[1] = +new Date(d.getFullYear(), d.getMonth(), d.getDate());
  33264. extent[0] = extent[1] - ONE_DAY;
  33265. }
  33266. this._innerSetExtent(extent[0], extent[1]);
  33267. this.calcNiceTicks(opt.splitNumber, opt.minInterval, opt.maxInterval);
  33268. };
  33269. TimeScale.prototype.calcNiceTicks = function (approxTickNum, minInterval, maxInterval) {
  33270. approxTickNum = approxTickNum || 10;
  33271. var span = this._getExtentSpanWithBreaks();
  33272. this._approxInterval = span / approxTickNum;
  33273. if (minInterval != null && this._approxInterval < minInterval) {
  33274. this._approxInterval = minInterval;
  33275. }
  33276. if (maxInterval != null && this._approxInterval > maxInterval) {
  33277. this._approxInterval = maxInterval;
  33278. }
  33279. var scaleIntervalsLen = scaleIntervals.length;
  33280. var idx = Math.min(bisect(scaleIntervals, this._approxInterval, 0, scaleIntervalsLen), scaleIntervalsLen - 1);
  33281. // Interval that can be used to calculate ticks
  33282. this._interval = scaleIntervals[idx][1];
  33283. this._intervalPrecision = getIntervalPrecision(this._interval);
  33284. // Min level used when picking ticks from top down.
  33285. // We check one more level to avoid the ticks are to sparse in some case.
  33286. this._minLevelUnit = scaleIntervals[Math.max(idx - 1, 0)][0];
  33287. };
  33288. TimeScale.prototype.parse = function (val) {
  33289. // val might be float.
  33290. return isNumber(val) ? val : +parseDate(val);
  33291. };
  33292. TimeScale.prototype.contain = function (val) {
  33293. return contain$1(val, this._extent);
  33294. };
  33295. TimeScale.prototype.normalize = function (val) {
  33296. return this._calculator.normalize(val, this._extent);
  33297. };
  33298. TimeScale.prototype.scale = function (val) {
  33299. return this._calculator.scale(val, this._extent);
  33300. };
  33301. TimeScale.type = 'time';
  33302. return TimeScale;
  33303. }(IntervalScale);
  33304. /**
  33305. * This implementation was originally copied from "d3.js"
  33306. * <https://github.com/d3/d3/blob/b516d77fb8566b576088e73410437494717ada26/src/time/scale.js>
  33307. * with some modifications made for this program.
  33308. * See the license statement at the head of this file.
  33309. */
  33310. var scaleIntervals = [
  33311. // Format interval
  33312. ['second', ONE_SECOND], ['minute', ONE_MINUTE], ['hour', ONE_HOUR], ['quarter-day', ONE_HOUR * 6], ['half-day', ONE_HOUR * 12], ['day', ONE_DAY * 1.2], ['half-week', ONE_DAY * 3.5], ['week', ONE_DAY * 7], ['month', ONE_DAY * 31], ['quarter', ONE_DAY * 95], ['half-year', ONE_YEAR / 2], ['year', ONE_YEAR] // 1Y
  33313. ];
  33314. function isPrimaryUnitValueAndGreaterSame(unit, valueA, valueB, isUTC) {
  33315. return roundTime(new Date(valueA), unit, isUTC).getTime() === roundTime(new Date(valueB), unit, isUTC).getTime();
  33316. }
  33317. // function isUnitValueSame(
  33318. // unit: PrimaryTimeUnit,
  33319. // valueA: number,
  33320. // valueB: number,
  33321. // isUTC: boolean
  33322. // ): boolean {
  33323. // const dateA = numberUtil.parseDate(valueA) as any;
  33324. // const dateB = numberUtil.parseDate(valueB) as any;
  33325. // const isSame = (unit: PrimaryTimeUnit) => {
  33326. // return getUnitValue(dateA, unit, isUTC)
  33327. // === getUnitValue(dateB, unit, isUTC);
  33328. // };
  33329. // const isSameYear = () => isSame('year');
  33330. // // const isSameHalfYear = () => isSameYear() && isSame('half-year');
  33331. // // const isSameQuater = () => isSameYear() && isSame('quarter');
  33332. // const isSameMonth = () => isSameYear() && isSame('month');
  33333. // const isSameDay = () => isSameMonth() && isSame('day');
  33334. // // const isSameHalfDay = () => isSameDay() && isSame('half-day');
  33335. // const isSameHour = () => isSameDay() && isSame('hour');
  33336. // const isSameMinute = () => isSameHour() && isSame('minute');
  33337. // const isSameSecond = () => isSameMinute() && isSame('second');
  33338. // const isSameMilliSecond = () => isSameSecond() && isSame('millisecond');
  33339. // switch (unit) {
  33340. // case 'year':
  33341. // return isSameYear();
  33342. // case 'month':
  33343. // return isSameMonth();
  33344. // case 'day':
  33345. // return isSameDay();
  33346. // case 'hour':
  33347. // return isSameHour();
  33348. // case 'minute':
  33349. // return isSameMinute();
  33350. // case 'second':
  33351. // return isSameSecond();
  33352. // case 'millisecond':
  33353. // return isSameMilliSecond();
  33354. // }
  33355. // }
  33356. // const primaryUnitGetters = {
  33357. // year: fullYearGetterName(),
  33358. // month: monthGetterName(),
  33359. // day: dateGetterName(),
  33360. // hour: hoursGetterName(),
  33361. // minute: minutesGetterName(),
  33362. // second: secondsGetterName(),
  33363. // millisecond: millisecondsGetterName()
  33364. // };
  33365. // const primaryUnitUTCGetters = {
  33366. // year: fullYearGetterName(true),
  33367. // month: monthGetterName(true),
  33368. // day: dateGetterName(true),
  33369. // hour: hoursGetterName(true),
  33370. // minute: minutesGetterName(true),
  33371. // second: secondsGetterName(true),
  33372. // millisecond: millisecondsGetterName(true)
  33373. // };
  33374. // function moveTick(date: Date, unitName: TimeUnit, step: number, isUTC: boolean) {
  33375. // step = step || 1;
  33376. // switch (getPrimaryTimeUnit(unitName)) {
  33377. // case 'year':
  33378. // date[fullYearSetterName(isUTC)](date[fullYearGetterName(isUTC)]() + step);
  33379. // break;
  33380. // case 'month':
  33381. // date[monthSetterName(isUTC)](date[monthGetterName(isUTC)]() + step);
  33382. // break;
  33383. // case 'day':
  33384. // date[dateSetterName(isUTC)](date[dateGetterName(isUTC)]() + step);
  33385. // break;
  33386. // case 'hour':
  33387. // date[hoursSetterName(isUTC)](date[hoursGetterName(isUTC)]() + step);
  33388. // break;
  33389. // case 'minute':
  33390. // date[minutesSetterName(isUTC)](date[minutesGetterName(isUTC)]() + step);
  33391. // break;
  33392. // case 'second':
  33393. // date[secondsSetterName(isUTC)](date[secondsGetterName(isUTC)]() + step);
  33394. // break;
  33395. // case 'millisecond':
  33396. // date[millisecondsSetterName(isUTC)](date[millisecondsGetterName(isUTC)]() + step);
  33397. // break;
  33398. // }
  33399. // return date.getTime();
  33400. // }
  33401. // const DATE_INTERVALS = [[8, 7.5], [4, 3.5], [2, 1.5]];
  33402. // const MONTH_INTERVALS = [[6, 5.5], [3, 2.5], [2, 1.5]];
  33403. // const MINUTES_SECONDS_INTERVALS = [[30, 30], [20, 20], [15, 15], [10, 10], [5, 5], [2, 2]];
  33404. function getDateInterval(approxInterval, daysInMonth) {
  33405. approxInterval /= ONE_DAY;
  33406. return approxInterval > 16 ? 16
  33407. // Math.floor(daysInMonth / 2) + 1 // In this case we only want one tick between two months.
  33408. : approxInterval > 7.5 ? 7 // TODO week 7 or day 8?
  33409. : approxInterval > 3.5 ? 4 : approxInterval > 1.5 ? 2 : 1;
  33410. }
  33411. function getMonthInterval(approxInterval) {
  33412. var APPROX_ONE_MONTH = 30 * ONE_DAY;
  33413. approxInterval /= APPROX_ONE_MONTH;
  33414. return approxInterval > 6 ? 6 : approxInterval > 3 ? 3 : approxInterval > 2 ? 2 : 1;
  33415. }
  33416. function getHourInterval(approxInterval) {
  33417. approxInterval /= ONE_HOUR;
  33418. return approxInterval > 12 ? 12 : approxInterval > 6 ? 6 : approxInterval > 3.5 ? 4 : approxInterval > 2 ? 2 : 1;
  33419. }
  33420. function getMinutesAndSecondsInterval(approxInterval, isMinutes) {
  33421. approxInterval /= isMinutes ? ONE_MINUTE : ONE_SECOND;
  33422. return approxInterval > 30 ? 30 : approxInterval > 20 ? 20 : approxInterval > 15 ? 15 : approxInterval > 10 ? 10 : approxInterval > 5 ? 5 : approxInterval > 2 ? 2 : 1;
  33423. }
  33424. function getMillisecondsInterval(approxInterval) {
  33425. return nice(approxInterval, true);
  33426. }
  33427. // e.g., if the input unit is 'day', start calculate ticks from the first day of
  33428. // that month to make ticks "nice".
  33429. function getFirstTimestampOfUnit(timestamp, unitName, isUTC) {
  33430. var upperUnitIdx = Math.max(0, indexOf(primaryTimeUnits, unitName) - 1);
  33431. return roundTime(new Date(timestamp), primaryTimeUnits[upperUnitIdx], isUTC).getTime();
  33432. }
  33433. function createEstimateNiceMultiple(setMethodName, dateMethodInterval) {
  33434. var tmpDate = new Date(0);
  33435. tmpDate[setMethodName](1);
  33436. var tmpTime = tmpDate.getTime();
  33437. tmpDate[setMethodName](1 + dateMethodInterval);
  33438. var approxTimeInterval = tmpDate.getTime() - tmpTime;
  33439. return function (tickVal, targetValue) {
  33440. // Only in month that accurate result can not get by division of
  33441. // timestamp interval, but no need accurate here.
  33442. return Math.max(0, Math.round((targetValue - tickVal) / approxTimeInterval));
  33443. };
  33444. }
  33445. function getIntervalTicks(bottomUnitName, approxInterval, isUTC, extent, extentSpanWithBreaks, brkCtx) {
  33446. var safeLimit = 10000;
  33447. var unitNames = timeUnits;
  33448. var iter = 0;
  33449. function addTicksInSpan(interval, minTimestamp, maxTimestamp, getMethodName, setMethodName, isDate, out) {
  33450. var estimateNiceMultiple = createEstimateNiceMultiple(setMethodName, interval);
  33451. var dateTime = minTimestamp;
  33452. var date = new Date(dateTime);
  33453. // if (isDate) {
  33454. // d -= 1; // Starts with 0; PENDING
  33455. // }
  33456. while (dateTime < maxTimestamp && dateTime <= extent[1]) {
  33457. out.push({
  33458. value: dateTime
  33459. });
  33460. if (iter++ > safeLimit) {
  33461. if ("development" !== 'production') {
  33462. warn('Exceed safe limit in time scale.');
  33463. }
  33464. break;
  33465. }
  33466. date[setMethodName](date[getMethodName]() + interval);
  33467. dateTime = date.getTime();
  33468. if (brkCtx) {
  33469. var moreMultiple = brkCtx.calcNiceTickMultiple(dateTime, estimateNiceMultiple);
  33470. if (moreMultiple > 0) {
  33471. date[setMethodName](date[getMethodName]() + moreMultiple * interval);
  33472. dateTime = date.getTime();
  33473. }
  33474. }
  33475. }
  33476. // This extra tick is for calcuating ticks of next level. Will not been added to the final result
  33477. out.push({
  33478. value: dateTime,
  33479. notAdd: true
  33480. });
  33481. }
  33482. function addLevelTicks(unitName, lastLevelTicks, levelTicks) {
  33483. var newAddedTicks = [];
  33484. var isFirstLevel = !lastLevelTicks.length;
  33485. if (isPrimaryUnitValueAndGreaterSame(getPrimaryTimeUnit(unitName), extent[0], extent[1], isUTC)) {
  33486. return;
  33487. }
  33488. if (isFirstLevel) {
  33489. lastLevelTicks = [{
  33490. value: getFirstTimestampOfUnit(extent[0], unitName, isUTC)
  33491. }, {
  33492. value: extent[1]
  33493. }];
  33494. }
  33495. for (var i = 0; i < lastLevelTicks.length - 1; i++) {
  33496. var startTick = lastLevelTicks[i].value;
  33497. var endTick = lastLevelTicks[i + 1].value;
  33498. if (startTick === endTick) {
  33499. continue;
  33500. }
  33501. var interval = void 0;
  33502. var getterName = void 0;
  33503. var setterName = void 0;
  33504. var isDate = false;
  33505. switch (unitName) {
  33506. case 'year':
  33507. interval = Math.max(1, Math.round(approxInterval / ONE_DAY / 365));
  33508. getterName = fullYearGetterName(isUTC);
  33509. setterName = fullYearSetterName(isUTC);
  33510. break;
  33511. case 'half-year':
  33512. case 'quarter':
  33513. case 'month':
  33514. interval = getMonthInterval(approxInterval);
  33515. getterName = monthGetterName(isUTC);
  33516. setterName = monthSetterName(isUTC);
  33517. break;
  33518. case 'week': // PENDING If week is added. Ignore day.
  33519. case 'half-week':
  33520. case 'day':
  33521. interval = getDateInterval(approxInterval); // Use 32 days and let interval been 16
  33522. getterName = dateGetterName(isUTC);
  33523. setterName = dateSetterName(isUTC);
  33524. isDate = true;
  33525. break;
  33526. case 'half-day':
  33527. case 'quarter-day':
  33528. case 'hour':
  33529. interval = getHourInterval(approxInterval);
  33530. getterName = hoursGetterName(isUTC);
  33531. setterName = hoursSetterName(isUTC);
  33532. break;
  33533. case 'minute':
  33534. interval = getMinutesAndSecondsInterval(approxInterval, true);
  33535. getterName = minutesGetterName(isUTC);
  33536. setterName = minutesSetterName(isUTC);
  33537. break;
  33538. case 'second':
  33539. interval = getMinutesAndSecondsInterval(approxInterval, false);
  33540. getterName = secondsGetterName(isUTC);
  33541. setterName = secondsSetterName(isUTC);
  33542. break;
  33543. case 'millisecond':
  33544. interval = getMillisecondsInterval(approxInterval);
  33545. getterName = millisecondsGetterName(isUTC);
  33546. setterName = millisecondsSetterName(isUTC);
  33547. break;
  33548. }
  33549. // Notice: This expansion by `getFirstTimestampOfUnit` may cause too many ticks and
  33550. // iteration. e.g., when three levels of ticks is displayed, which can be caused by
  33551. // data zoom and axis breaks. Thus trim them here.
  33552. if (endTick >= extent[0] && startTick <= extent[1]) {
  33553. addTicksInSpan(interval, startTick, endTick, getterName, setterName, isDate, newAddedTicks);
  33554. }
  33555. if (unitName === 'year' && levelTicks.length > 1 && i === 0) {
  33556. // Add nearest years to the left extent.
  33557. levelTicks.unshift({
  33558. value: levelTicks[0].value - interval
  33559. });
  33560. }
  33561. }
  33562. for (var i = 0; i < newAddedTicks.length; i++) {
  33563. levelTicks.push(newAddedTicks[i]);
  33564. }
  33565. }
  33566. var levelsTicks = [];
  33567. var currentLevelTicks = [];
  33568. var tickCount = 0;
  33569. var lastLevelTickCount = 0;
  33570. for (var i = 0; i < unitNames.length; ++i) {
  33571. var primaryTimeUnit = getPrimaryTimeUnit(unitNames[i]);
  33572. if (!isPrimaryTimeUnit(unitNames[i])) {
  33573. // TODO
  33574. continue;
  33575. }
  33576. addLevelTicks(unitNames[i], levelsTicks[levelsTicks.length - 1] || [], currentLevelTicks);
  33577. var nextPrimaryTimeUnit = unitNames[i + 1] ? getPrimaryTimeUnit(unitNames[i + 1]) : null;
  33578. if (primaryTimeUnit !== nextPrimaryTimeUnit) {
  33579. if (currentLevelTicks.length) {
  33580. lastLevelTickCount = tickCount;
  33581. // Remove the duplicate so the tick count can be precisely.
  33582. currentLevelTicks.sort(function (a, b) {
  33583. return a.value - b.value;
  33584. });
  33585. var levelTicksRemoveDuplicated = [];
  33586. for (var i_1 = 0; i_1 < currentLevelTicks.length; ++i_1) {
  33587. var tickValue = currentLevelTicks[i_1].value;
  33588. if (i_1 === 0 || currentLevelTicks[i_1 - 1].value !== tickValue) {
  33589. levelTicksRemoveDuplicated.push(currentLevelTicks[i_1]);
  33590. if (tickValue >= extent[0] && tickValue <= extent[1]) {
  33591. tickCount++;
  33592. }
  33593. }
  33594. }
  33595. var targetTickNum = extentSpanWithBreaks / approxInterval;
  33596. // Added too much in this level and not too less in last level
  33597. if (tickCount > targetTickNum * 1.5 && lastLevelTickCount > targetTickNum / 1.5) {
  33598. break;
  33599. }
  33600. // Only treat primary time unit as one level.
  33601. levelsTicks.push(levelTicksRemoveDuplicated);
  33602. if (tickCount > targetTickNum || bottomUnitName === unitNames[i]) {
  33603. break;
  33604. }
  33605. }
  33606. // Reset if next unitName is primary
  33607. currentLevelTicks = [];
  33608. }
  33609. }
  33610. var levelsTicksInExtent = filter(map(levelsTicks, function (levelTicks) {
  33611. return filter(levelTicks, function (tick) {
  33612. return tick.value >= extent[0] && tick.value <= extent[1] && !tick.notAdd;
  33613. });
  33614. }), function (levelTicks) {
  33615. return levelTicks.length > 0;
  33616. });
  33617. var ticks = [];
  33618. var maxLevel = levelsTicksInExtent.length - 1;
  33619. for (var i = 0; i < levelsTicksInExtent.length; ++i) {
  33620. var levelTicks = levelsTicksInExtent[i];
  33621. for (var k = 0; k < levelTicks.length; ++k) {
  33622. var unit = getUnitFromValue(levelTicks[k].value, isUTC);
  33623. ticks.push({
  33624. value: levelTicks[k].value,
  33625. time: {
  33626. level: maxLevel - i,
  33627. upperTimeUnit: unit,
  33628. lowerTimeUnit: unit
  33629. }
  33630. });
  33631. }
  33632. }
  33633. ticks.sort(function (a, b) {
  33634. return a.value - b.value;
  33635. });
  33636. // Remove duplicates
  33637. var result = [];
  33638. for (var i = 0; i < ticks.length; ++i) {
  33639. if (i === 0 || ticks[i].value !== ticks[i - 1].value) {
  33640. result.push(ticks[i]);
  33641. }
  33642. }
  33643. return result;
  33644. }
  33645. Scale.registerClass(TimeScale);
  33646. var fixRound = round;
  33647. var mathFloor = Math.floor;
  33648. var mathCeil = Math.ceil;
  33649. var mathPow$1 = Math.pow;
  33650. var mathLog = Math.log;
  33651. var LogScale = /** @class */function (_super) {
  33652. __extends(LogScale, _super);
  33653. function LogScale() {
  33654. var _this = _super !== null && _super.apply(this, arguments) || this;
  33655. _this.type = 'log';
  33656. _this.base = 10;
  33657. _this._originalScale = new IntervalScale();
  33658. return _this;
  33659. }
  33660. /**
  33661. * @param Whether expand the ticks to niced extent.
  33662. */
  33663. LogScale.prototype.getTicks = function (opt) {
  33664. opt = opt || {};
  33665. var extent = this._extent.slice();
  33666. var originalExtent = this._originalScale.getExtent();
  33667. var ticks = _super.prototype.getTicks.call(this, opt);
  33668. var base = this.base;
  33669. var originalBreaks = this._originalScale._innerGetBreaks();
  33670. var scaleBreakHelper = getScaleBreakHelper();
  33671. return map(ticks, function (tick) {
  33672. var val = tick.value;
  33673. var roundingCriterion = null;
  33674. var powVal = mathPow$1(base, val);
  33675. // Fix #4158
  33676. if (val === extent[0] && this._fixMin) {
  33677. roundingCriterion = originalExtent[0];
  33678. } else if (val === extent[1] && this._fixMax) {
  33679. roundingCriterion = originalExtent[1];
  33680. }
  33681. var vBreak;
  33682. if (scaleBreakHelper) {
  33683. var transformed = scaleBreakHelper.getTicksLogTransformBreak(tick, base, originalBreaks, fixRoundingError);
  33684. vBreak = transformed.vBreak;
  33685. if (roundingCriterion == null) {
  33686. roundingCriterion = transformed.brkRoundingCriterion;
  33687. }
  33688. }
  33689. if (roundingCriterion != null) {
  33690. powVal = fixRoundingError(powVal, roundingCriterion);
  33691. }
  33692. return {
  33693. value: powVal,
  33694. "break": vBreak
  33695. };
  33696. }, this);
  33697. };
  33698. LogScale.prototype._getNonTransBreaks = function () {
  33699. return this._originalScale._innerGetBreaks();
  33700. };
  33701. LogScale.prototype.setExtent = function (start, end) {
  33702. this._originalScale.setExtent(start, end);
  33703. var loggedExtent = logTransform(this.base, [start, end]);
  33704. _super.prototype.setExtent.call(this, loggedExtent[0], loggedExtent[1]);
  33705. };
  33706. /**
  33707. * @return {number} end
  33708. */
  33709. LogScale.prototype.getExtent = function () {
  33710. var base = this.base;
  33711. var extent = _super.prototype.getExtent.call(this);
  33712. extent[0] = mathPow$1(base, extent[0]);
  33713. extent[1] = mathPow$1(base, extent[1]);
  33714. // Fix #4158
  33715. var originalExtent = this._originalScale.getExtent();
  33716. this._fixMin && (extent[0] = fixRoundingError(extent[0], originalExtent[0]));
  33717. this._fixMax && (extent[1] = fixRoundingError(extent[1], originalExtent[1]));
  33718. return extent;
  33719. };
  33720. LogScale.prototype.unionExtentFromData = function (data, dim) {
  33721. this._originalScale.unionExtentFromData(data, dim);
  33722. var loggedOther = logTransform(this.base, data.getApproximateExtent(dim), true);
  33723. this._innerUnionExtent(loggedOther);
  33724. };
  33725. /**
  33726. * Update interval and extent of intervals for nice ticks
  33727. * @param approxTickNum default 10 Given approx tick number
  33728. */
  33729. LogScale.prototype.calcNiceTicks = function (approxTickNum) {
  33730. approxTickNum = approxTickNum || 10;
  33731. var extent = this._extent.slice();
  33732. var span = this._getExtentSpanWithBreaks();
  33733. if (!isFinite(span) || span <= 0) {
  33734. return;
  33735. }
  33736. var interval = quantity(span);
  33737. var err = approxTickNum / span * interval;
  33738. // Filter ticks to get closer to the desired count.
  33739. if (err <= 0.5) {
  33740. interval *= 10;
  33741. }
  33742. // Interval should be integer
  33743. while (!isNaN(interval) && Math.abs(interval) < 1 && Math.abs(interval) > 0) {
  33744. interval *= 10;
  33745. }
  33746. var niceExtent = [fixRound(mathCeil(extent[0] / interval) * interval), fixRound(mathFloor(extent[1] / interval) * interval)];
  33747. this._interval = interval;
  33748. this._intervalPrecision = getIntervalPrecision(interval);
  33749. this._niceExtent = niceExtent;
  33750. };
  33751. LogScale.prototype.calcNiceExtent = function (opt) {
  33752. _super.prototype.calcNiceExtent.call(this, opt);
  33753. this._fixMin = opt.fixMin;
  33754. this._fixMax = opt.fixMax;
  33755. };
  33756. LogScale.prototype.contain = function (val) {
  33757. val = mathLog(val) / mathLog(this.base);
  33758. return _super.prototype.contain.call(this, val);
  33759. };
  33760. LogScale.prototype.normalize = function (val) {
  33761. val = mathLog(val) / mathLog(this.base);
  33762. return _super.prototype.normalize.call(this, val);
  33763. };
  33764. LogScale.prototype.scale = function (val) {
  33765. val = _super.prototype.scale.call(this, val);
  33766. return mathPow$1(this.base, val);
  33767. };
  33768. LogScale.prototype.setBreaksFromOption = function (breakOptionList) {
  33769. var scaleBreakHelper = getScaleBreakHelper();
  33770. if (!scaleBreakHelper) {
  33771. return;
  33772. }
  33773. var _a = scaleBreakHelper.logarithmicParseBreaksFromOption(breakOptionList, this.base, bind(this.parse, this)),
  33774. parsedOriginal = _a.parsedOriginal,
  33775. parsedLogged = _a.parsedLogged;
  33776. this._originalScale._innerSetBreak(parsedOriginal);
  33777. this._innerSetBreak(parsedLogged);
  33778. };
  33779. LogScale.type = 'log';
  33780. return LogScale;
  33781. }(IntervalScale);
  33782. function fixRoundingError(val, originalVal) {
  33783. return fixRound(val, getPrecision(originalVal));
  33784. }
  33785. Scale.registerClass(LogScale);
  33786. var ScaleRawExtentInfo = /** @class */function () {
  33787. function ScaleRawExtentInfo(scale, model,
  33788. // Usually: data extent from all series on this axis.
  33789. originalExtent) {
  33790. this._prepareParams(scale, model, originalExtent);
  33791. }
  33792. /**
  33793. * Parameters depending on outside (like model, user callback)
  33794. * are prepared and fixed here.
  33795. */
  33796. ScaleRawExtentInfo.prototype._prepareParams = function (scale, model,
  33797. // Usually: data extent from all series on this axis.
  33798. dataExtent) {
  33799. if (dataExtent[1] < dataExtent[0]) {
  33800. dataExtent = [NaN, NaN];
  33801. }
  33802. this._dataMin = dataExtent[0];
  33803. this._dataMax = dataExtent[1];
  33804. var isOrdinal = this._isOrdinal = scale.type === 'ordinal';
  33805. this._needCrossZero = scale.type === 'interval' && model.getNeedCrossZero && model.getNeedCrossZero();
  33806. var axisMinValue = model.get('min', true);
  33807. if (axisMinValue == null) {
  33808. axisMinValue = model.get('startValue', true);
  33809. }
  33810. var modelMinRaw = this._modelMinRaw = axisMinValue;
  33811. if (isFunction(modelMinRaw)) {
  33812. // This callback always provides users the full data extent (before data is filtered).
  33813. this._modelMinNum = parseAxisModelMinMax(scale, modelMinRaw({
  33814. min: dataExtent[0],
  33815. max: dataExtent[1]
  33816. }));
  33817. } else if (modelMinRaw !== 'dataMin') {
  33818. this._modelMinNum = parseAxisModelMinMax(scale, modelMinRaw);
  33819. }
  33820. var modelMaxRaw = this._modelMaxRaw = model.get('max', true);
  33821. if (isFunction(modelMaxRaw)) {
  33822. // This callback always provides users the full data extent (before data is filtered).
  33823. this._modelMaxNum = parseAxisModelMinMax(scale, modelMaxRaw({
  33824. min: dataExtent[0],
  33825. max: dataExtent[1]
  33826. }));
  33827. } else if (modelMaxRaw !== 'dataMax') {
  33828. this._modelMaxNum = parseAxisModelMinMax(scale, modelMaxRaw);
  33829. }
  33830. if (isOrdinal) {
  33831. // FIXME: there is a flaw here: if there is no "block" data processor like `dataZoom`,
  33832. // and progressive rendering is using, here the category result might just only contain
  33833. // the processed chunk rather than the entire result.
  33834. this._axisDataLen = model.getCategories().length;
  33835. } else {
  33836. var boundaryGap = model.get('boundaryGap');
  33837. var boundaryGapArr = isArray(boundaryGap) ? boundaryGap : [boundaryGap || 0, boundaryGap || 0];
  33838. if (typeof boundaryGapArr[0] === 'boolean' || typeof boundaryGapArr[1] === 'boolean') {
  33839. if ("development" !== 'production') {
  33840. console.warn('Boolean type for boundaryGap is only ' + 'allowed for ordinal axis. Please use string in ' + 'percentage instead, e.g., "20%". Currently, ' + 'boundaryGap is set to be 0.');
  33841. }
  33842. this._boundaryGapInner = [0, 0];
  33843. } else {
  33844. this._boundaryGapInner = [parsePercent(boundaryGapArr[0], 1), parsePercent(boundaryGapArr[1], 1)];
  33845. }
  33846. }
  33847. };
  33848. /**
  33849. * Calculate extent by prepared parameters.
  33850. * This method has no external dependency and can be called duplicatedly,
  33851. * getting the same result.
  33852. * If parameters changed, should call this method to recalcuate.
  33853. */
  33854. ScaleRawExtentInfo.prototype.calculate = function () {
  33855. // Notice: When min/max is not set (that is, when there are null/undefined,
  33856. // which is the most common case), these cases should be ensured:
  33857. // (1) For 'ordinal', show all axis.data.
  33858. // (2) For others:
  33859. // + `boundaryGap` is applied (if min/max set, boundaryGap is
  33860. // disabled).
  33861. // + If `needCrossZero`, min/max should be zero, otherwise, min/max should
  33862. // be the result that originalExtent enlarged by boundaryGap.
  33863. // (3) If no data, it should be ensured that `scale.setBlank` is set.
  33864. var isOrdinal = this._isOrdinal;
  33865. var dataMin = this._dataMin;
  33866. var dataMax = this._dataMax;
  33867. var axisDataLen = this._axisDataLen;
  33868. var boundaryGapInner = this._boundaryGapInner;
  33869. var span = !isOrdinal ? dataMax - dataMin || Math.abs(dataMin) : null;
  33870. // Currently if a `'value'` axis model min is specified as 'dataMin'/'dataMax',
  33871. // `boundaryGap` will not be used. It's the different from specifying as `null`/`undefined`.
  33872. var min = this._modelMinRaw === 'dataMin' ? dataMin : this._modelMinNum;
  33873. var max = this._modelMaxRaw === 'dataMax' ? dataMax : this._modelMaxNum;
  33874. // If `_modelMinNum`/`_modelMaxNum` is `null`/`undefined`, should not be fixed.
  33875. var minFixed = min != null;
  33876. var maxFixed = max != null;
  33877. if (min == null) {
  33878. min = isOrdinal ? axisDataLen ? 0 : NaN : dataMin - boundaryGapInner[0] * span;
  33879. }
  33880. if (max == null) {
  33881. max = isOrdinal ? axisDataLen ? axisDataLen - 1 : NaN : dataMax + boundaryGapInner[1] * span;
  33882. }
  33883. (min == null || !isFinite(min)) && (min = NaN);
  33884. (max == null || !isFinite(max)) && (max = NaN);
  33885. var isBlank = eqNaN(min) || eqNaN(max) || isOrdinal && !axisDataLen;
  33886. // If data extent modified, need to recalculated to ensure cross zero.
  33887. if (this._needCrossZero) {
  33888. // Axis is over zero and min is not set
  33889. if (min > 0 && max > 0 && !minFixed) {
  33890. min = 0;
  33891. // minFixed = true;
  33892. }
  33893. // Axis is under zero and max is not set
  33894. if (min < 0 && max < 0 && !maxFixed) {
  33895. max = 0;
  33896. // maxFixed = true;
  33897. }
  33898. // PENDING:
  33899. // When `needCrossZero` and all data is positive/negative, should it be ensured
  33900. // that the results processed by boundaryGap are positive/negative?
  33901. // If so, here `minFixed`/`maxFixed` need to be set.
  33902. }
  33903. var determinedMin = this._determinedMin;
  33904. var determinedMax = this._determinedMax;
  33905. if (determinedMin != null) {
  33906. min = determinedMin;
  33907. minFixed = true;
  33908. }
  33909. if (determinedMax != null) {
  33910. max = determinedMax;
  33911. maxFixed = true;
  33912. }
  33913. // Ensure min/max be finite number or NaN here. (not to be null/undefined)
  33914. // `NaN` means min/max axis is blank.
  33915. return {
  33916. min: min,
  33917. max: max,
  33918. minFixed: minFixed,
  33919. maxFixed: maxFixed,
  33920. isBlank: isBlank
  33921. };
  33922. };
  33923. ScaleRawExtentInfo.prototype.modifyDataMinMax = function (minMaxName, val) {
  33924. if ("development" !== 'production') {
  33925. assert(!this.frozen);
  33926. }
  33927. this[DATA_MIN_MAX_ATTR[minMaxName]] = val;
  33928. };
  33929. ScaleRawExtentInfo.prototype.setDeterminedMinMax = function (minMaxName, val) {
  33930. var attr = DETERMINED_MIN_MAX_ATTR[minMaxName];
  33931. if ("development" !== 'production') {
  33932. assert(!this.frozen
  33933. // Earse them usually means logic flaw.
  33934. && this[attr] == null);
  33935. }
  33936. this[attr] = val;
  33937. };
  33938. ScaleRawExtentInfo.prototype.freeze = function () {
  33939. // @ts-ignore
  33940. this.frozen = true;
  33941. };
  33942. return ScaleRawExtentInfo;
  33943. }();
  33944. var DETERMINED_MIN_MAX_ATTR = {
  33945. min: '_determinedMin',
  33946. max: '_determinedMax'
  33947. };
  33948. var DATA_MIN_MAX_ATTR = {
  33949. min: '_dataMin',
  33950. max: '_dataMax'
  33951. };
  33952. /**
  33953. * Get scale min max and related info only depends on model settings.
  33954. * This method can be called after coordinate system created.
  33955. * For example, in data processing stage.
  33956. *
  33957. * Scale extent info probably be required multiple times during a workflow.
  33958. * For example:
  33959. * (1) `dataZoom` depends it to get the axis extent in "100%" state.
  33960. * (2) `processor/extentCalculator` depends it to make sure whether axis extent is specified.
  33961. * (3) `coordSys.update` use it to finally decide the scale extent.
  33962. * But the callback of `min`/`max` should not be called multiple times.
  33963. * The code below should not be implemented repeatedly either.
  33964. * So we cache the result in the scale instance, which will be recreated at the beginning
  33965. * of the workflow (because `scale` instance will be recreated each round of the workflow).
  33966. */
  33967. function ensureScaleRawExtentInfo(scale, model,
  33968. // Usually: data extent from all series on this axis.
  33969. originalExtent) {
  33970. // Do not permit to recreate.
  33971. var rawExtentInfo = scale.rawExtentInfo;
  33972. if (rawExtentInfo) {
  33973. return rawExtentInfo;
  33974. }
  33975. rawExtentInfo = new ScaleRawExtentInfo(scale, model, originalExtent);
  33976. // @ts-ignore
  33977. scale.rawExtentInfo = rawExtentInfo;
  33978. return rawExtentInfo;
  33979. }
  33980. function parseAxisModelMinMax(scale, minMax) {
  33981. return minMax == null ? null : eqNaN(minMax) ? NaN : scale.parse(minMax);
  33982. }
  33983. /**
  33984. * Get axis scale extent before niced.
  33985. * Item of returned array can only be number (including Infinity and NaN).
  33986. *
  33987. * Caution:
  33988. * Precondition of calling this method:
  33989. * The scale extent has been initialized using series data extent via
  33990. * `scale.setExtent` or `scale.unionExtentFromData`;
  33991. */
  33992. function getScaleExtent(scale, model) {
  33993. var scaleType = scale.type;
  33994. var rawExtentResult = ensureScaleRawExtentInfo(scale, model, scale.getExtent()).calculate();
  33995. scale.setBlank(rawExtentResult.isBlank);
  33996. var min = rawExtentResult.min;
  33997. var max = rawExtentResult.max;
  33998. // If bars are placed on a base axis of type time or interval account for axis boundary overflow and current axis
  33999. // is base axis
  34000. // FIXME
  34001. // (1) Consider support value axis, where below zero and axis `onZero` should be handled properly.
  34002. // (2) Refactor the logic with `barGrid`. Is it not need to `makeBarWidthAndOffsetInfo` twice with different extent?
  34003. // Should not depend on series type `bar`?
  34004. // (3) Fix that might overlap when using dataZoom.
  34005. // (4) Consider other chart types using `barGrid`?
  34006. // See #6728, #4862, `test/bar-overflow-time-plot.html`
  34007. var ecModel = model.ecModel;
  34008. if (ecModel && scaleType === 'time' /* || scaleType === 'interval' */) {
  34009. var barSeriesModels = prepareLayoutBarSeries('bar', ecModel);
  34010. var isBaseAxisAndHasBarSeries_1 = false;
  34011. each(barSeriesModels, function (seriesModel) {
  34012. isBaseAxisAndHasBarSeries_1 = isBaseAxisAndHasBarSeries_1 || seriesModel.getBaseAxis() === model.axis;
  34013. });
  34014. if (isBaseAxisAndHasBarSeries_1) {
  34015. // Calculate placement of bars on axis. TODO should be decoupled
  34016. // with barLayout
  34017. var barWidthAndOffset = makeColumnLayout(barSeriesModels);
  34018. // Adjust axis min and max to account for overflow
  34019. var adjustedScale = adjustScaleForOverflow(min, max, model, barWidthAndOffset);
  34020. min = adjustedScale.min;
  34021. max = adjustedScale.max;
  34022. }
  34023. }
  34024. return {
  34025. extent: [min, max],
  34026. // "fix" means "fixed", the value should not be
  34027. // changed in the subsequent steps.
  34028. fixMin: rawExtentResult.minFixed,
  34029. fixMax: rawExtentResult.maxFixed
  34030. };
  34031. }
  34032. function adjustScaleForOverflow(min, max, model,
  34033. // Only support cartesian coord yet.
  34034. barWidthAndOffset) {
  34035. // Get Axis Length
  34036. var axisExtent = model.axis.getExtent();
  34037. var axisLength = Math.abs(axisExtent[1] - axisExtent[0]);
  34038. // Get bars on current base axis and calculate min and max overflow
  34039. var barsOnCurrentAxis = retrieveColumnLayout(barWidthAndOffset, model.axis);
  34040. if (barsOnCurrentAxis === undefined) {
  34041. return {
  34042. min: min,
  34043. max: max
  34044. };
  34045. }
  34046. var minOverflow = Infinity;
  34047. each(barsOnCurrentAxis, function (item) {
  34048. minOverflow = Math.min(item.offset, minOverflow);
  34049. });
  34050. var maxOverflow = -Infinity;
  34051. each(barsOnCurrentAxis, function (item) {
  34052. maxOverflow = Math.max(item.offset + item.width, maxOverflow);
  34053. });
  34054. minOverflow = Math.abs(minOverflow);
  34055. maxOverflow = Math.abs(maxOverflow);
  34056. var totalOverFlow = minOverflow + maxOverflow;
  34057. // Calculate required buffer based on old range and overflow
  34058. var oldRange = max - min;
  34059. var oldRangePercentOfNew = 1 - (minOverflow + maxOverflow) / axisLength;
  34060. var overflowBuffer = oldRange / oldRangePercentOfNew - oldRange;
  34061. max += overflowBuffer * (maxOverflow / totalOverFlow);
  34062. min -= overflowBuffer * (minOverflow / totalOverFlow);
  34063. return {
  34064. min: min,
  34065. max: max
  34066. };
  34067. }
  34068. // Precondition of calling this method:
  34069. // The scale extent has been initialized using series data extent via
  34070. // `scale.setExtent` or `scale.unionExtentFromData`;
  34071. function niceScaleExtent(scale, inModel) {
  34072. var model = inModel;
  34073. var extentInfo = getScaleExtent(scale, model);
  34074. var extent = extentInfo.extent;
  34075. var splitNumber = model.get('splitNumber');
  34076. if (scale instanceof LogScale) {
  34077. scale.base = model.get('logBase');
  34078. }
  34079. var scaleType = scale.type;
  34080. var interval = model.get('interval');
  34081. var isIntervalOrTime = scaleType === 'interval' || scaleType === 'time';
  34082. scale.setBreaksFromOption(retrieveAxisBreaksOption(model));
  34083. scale.setExtent(extent[0], extent[1]);
  34084. scale.calcNiceExtent({
  34085. splitNumber: splitNumber,
  34086. fixMin: extentInfo.fixMin,
  34087. fixMax: extentInfo.fixMax,
  34088. minInterval: isIntervalOrTime ? model.get('minInterval') : null,
  34089. maxInterval: isIntervalOrTime ? model.get('maxInterval') : null
  34090. });
  34091. // If some one specified the min, max. And the default calculated interval
  34092. // is not good enough. He can specify the interval. It is often appeared
  34093. // in angle axis with angle 0 - 360. Interval calculated in interval scale is hard
  34094. // to be 60.
  34095. // FIXME
  34096. if (interval != null) {
  34097. scale.setInterval && scale.setInterval(interval);
  34098. }
  34099. }
  34100. /**
  34101. * @param axisType Default retrieve from model.type
  34102. */
  34103. function createScaleByModel(model, axisType) {
  34104. axisType = axisType || model.get('type');
  34105. if (axisType) {
  34106. switch (axisType) {
  34107. // Buildin scale
  34108. case 'category':
  34109. return new OrdinalScale({
  34110. ordinalMeta: model.getOrdinalMeta ? model.getOrdinalMeta() : model.getCategories(),
  34111. extent: [Infinity, -Infinity]
  34112. });
  34113. case 'time':
  34114. return new TimeScale({
  34115. locale: model.ecModel.getLocaleModel(),
  34116. useUTC: model.ecModel.get('useUTC')
  34117. });
  34118. default:
  34119. // case 'value'/'interval', 'log', or others.
  34120. return new (Scale.getClass(axisType) || IntervalScale)();
  34121. }
  34122. }
  34123. }
  34124. /**
  34125. * Check if the axis cross 0
  34126. */
  34127. function ifAxisCrossZero(axis) {
  34128. var dataExtent = axis.scale.getExtent();
  34129. var min = dataExtent[0];
  34130. var max = dataExtent[1];
  34131. return !(min > 0 && max > 0 || min < 0 && max < 0);
  34132. }
  34133. /**
  34134. * @param axis
  34135. * @return Label formatter function.
  34136. * param: {number} tickValue,
  34137. * param: {number} idx, the index in all ticks.
  34138. * If category axis, this param is not required.
  34139. * return: {string} label string.
  34140. */
  34141. function makeLabelFormatter(axis) {
  34142. var labelFormatter = axis.getLabelModel().get('formatter');
  34143. if (axis.type === 'time') {
  34144. var parsed_1 = parseTimeAxisLabelFormatter(labelFormatter);
  34145. return function (tick, idx) {
  34146. return axis.scale.getFormattedLabel(tick, idx, parsed_1);
  34147. };
  34148. } else if (isString(labelFormatter)) {
  34149. return function (tick) {
  34150. // For category axis, get raw value; for numeric axis,
  34151. // get formatted label like '1,333,444'.
  34152. var label = axis.scale.getLabel(tick);
  34153. var text = labelFormatter.replace('{value}', label != null ? label : '');
  34154. return text;
  34155. };
  34156. } else if (isFunction(labelFormatter)) {
  34157. if (axis.type === 'category') {
  34158. return function (tick, idx) {
  34159. // The original intention of `idx` is "the index of the tick in all ticks".
  34160. // But the previous implementation of category axis do not consider the
  34161. // `axisLabel.interval`, which cause that, for example, the `interval` is
  34162. // `1`, then the ticks "name5", "name7", "name9" are displayed, where the
  34163. // corresponding `idx` are `0`, `2`, `4`, but not `0`, `1`, `2`. So we keep
  34164. // the definition here for back compatibility.
  34165. return labelFormatter(getAxisRawValue(axis, tick), tick.value - axis.scale.getExtent()[0], null // Using `null` just for backward compat.
  34166. );
  34167. };
  34168. }
  34169. var scaleBreakHelper_1 = getScaleBreakHelper();
  34170. return function (tick, idx) {
  34171. // Using `null` just for backward compat. It's been found that in the `test/axis-customTicks.html`,
  34172. // there is a formatter `function (value, index, revers = true) { ... }`. Although the third param
  34173. // `revers` is incorrect and always `null`, changing it might introduce a breaking change.
  34174. var extra = null;
  34175. if (scaleBreakHelper_1) {
  34176. extra = scaleBreakHelper_1.makeAxisLabelFormatterParamBreak(extra, tick["break"]);
  34177. }
  34178. return labelFormatter(getAxisRawValue(axis, tick), idx, extra);
  34179. };
  34180. } else {
  34181. return function (tick) {
  34182. return axis.scale.getLabel(tick);
  34183. };
  34184. }
  34185. }
  34186. function getAxisRawValue(axis, tick) {
  34187. // In category axis with data zoom, tick is not the original
  34188. // index of axis.data. So tick should not be exposed to user
  34189. // in category axis.
  34190. return axis.type === 'category' ? axis.scale.getLabel(tick) : tick.value;
  34191. }
  34192. /**
  34193. * @param model axisLabelModel or axisTickModel
  34194. * @return {number|String} Can be null|'auto'|number|function
  34195. */
  34196. function getOptionCategoryInterval(model) {
  34197. var interval = model.get('interval');
  34198. return interval == null ? 'auto' : interval;
  34199. }
  34200. /**
  34201. * Set `categoryInterval` as 0 implicitly indicates that
  34202. * show all labels regardless of overlap.
  34203. * @param {Object} axis axisModel.axis
  34204. */
  34205. function shouldShowAllLabels(axis) {
  34206. return axis.type === 'category' && getOptionCategoryInterval(axis.getLabelModel()) === 0;
  34207. }
  34208. function getDataDimensionsOnAxis(data, axisDim) {
  34209. // Remove duplicated dat dimensions caused by `getStackedDimension`.
  34210. var dataDimMap = {};
  34211. // Currently `mapDimensionsAll` will contain stack result dimension ('__\0ecstackresult').
  34212. // PENDING: is it reasonable? Do we need to remove the original dim from "coord dim" since
  34213. // there has been stacked result dim?
  34214. each(data.mapDimensionsAll(axisDim), function (dataDim) {
  34215. // For example, the extent of the original dimension
  34216. // is [0.1, 0.5], the extent of the `stackResultDimension`
  34217. // is [7, 9], the final extent should NOT include [0.1, 0.5],
  34218. // because there is no graphic corresponding to [0.1, 0.5].
  34219. // See the case in `test/area-stack.html` `main1`, where area line
  34220. // stack needs `yAxis` not start from 0.
  34221. dataDimMap[getStackedDimension(data, dataDim)] = true;
  34222. });
  34223. return keys(dataDimMap);
  34224. }
  34225. function unionAxisExtentFromData(dataExtent, data, axisDim) {
  34226. if (data) {
  34227. each(getDataDimensionsOnAxis(data, axisDim), function (dim) {
  34228. var seriesExtent = data.getApproximateExtent(dim);
  34229. seriesExtent[0] < dataExtent[0] && (dataExtent[0] = seriesExtent[0]);
  34230. seriesExtent[1] > dataExtent[1] && (dataExtent[1] = seriesExtent[1]);
  34231. });
  34232. }
  34233. }
  34234. function isNameLocationCenter(nameLocation) {
  34235. return nameLocation === 'middle' || nameLocation === 'center';
  34236. }
  34237. function shouldAxisShow(axisModel) {
  34238. return axisModel.getShallow('show');
  34239. }
  34240. function retrieveAxisBreaksOption(model) {
  34241. var option = model.get('breaks', true);
  34242. if (option != null) {
  34243. if (!getScaleBreakHelper()) {
  34244. if ("development" !== 'production') {
  34245. error('Must `import {AxisBreak} from "echarts/features.js"; use(AxisBreak);` first if using breaks option.');
  34246. }
  34247. return undefined;
  34248. }
  34249. if (!isSupportAxisBreak(model.axis)) {
  34250. if ("development" !== 'production') {
  34251. error("Axis '" + model.axis.dim + "'-'" + model.axis.type + "' does not support break.");
  34252. }
  34253. return undefined;
  34254. }
  34255. return option;
  34256. }
  34257. }
  34258. function isSupportAxisBreak(axis) {
  34259. // The polar radius axis can also support break feasibly. Do not do it until the requirements are met.
  34260. return (axis.dim === 'x' || axis.dim === 'y' || axis.dim === 'z' || axis.dim === 'single') && axis.type !== 'category';
  34261. }
  34262. /*
  34263. * Licensed to the Apache Software Foundation (ASF) under one
  34264. * or more contributor license agreements. See the NOTICE file
  34265. * distributed with this work for additional information
  34266. * regarding copyright ownership. The ASF licenses this file
  34267. * to you under the Apache License, Version 2.0 (the
  34268. * "License"); you may not use this file except in compliance
  34269. * with the License. You may obtain a copy of the License at
  34270. *
  34271. * http://www.apache.org/licenses/LICENSE-2.0
  34272. *
  34273. * Unless required by applicable law or agreed to in writing,
  34274. * software distributed under the License is distributed on an
  34275. * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
  34276. * KIND, either express or implied. See the License for the
  34277. * specific language governing permissions and limitations
  34278. * under the License.
  34279. */
  34280. /**
  34281. * AUTO-GENERATED FILE. DO NOT MODIFY.
  34282. */
  34283. /*
  34284. * Licensed to the Apache Software Foundation (ASF) under one
  34285. * or more contributor license agreements. See the NOTICE file
  34286. * distributed with this work for additional information
  34287. * regarding copyright ownership. The ASF licenses this file
  34288. * to you under the Apache License, Version 2.0 (the
  34289. * "License"); you may not use this file except in compliance
  34290. * with the License. You may obtain a copy of the License at
  34291. *
  34292. * http://www.apache.org/licenses/LICENSE-2.0
  34293. *
  34294. * Unless required by applicable law or agreed to in writing,
  34295. * software distributed under the License is distributed on an
  34296. * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
  34297. * KIND, either express or implied. See the License for the
  34298. * specific language governing permissions and limitations
  34299. * under the License.
  34300. */
  34301. // eslint-disable-next-line @typescript-eslint/no-unused-vars
  34302. var AxisModelCommonMixin = /** @class */function () {
  34303. function AxisModelCommonMixin() {}
  34304. AxisModelCommonMixin.prototype.getNeedCrossZero = function () {
  34305. var option = this.option;
  34306. return !option.scale;
  34307. };
  34308. /**
  34309. * Should be implemented by each axis model if necessary.
  34310. * @return coordinate system model
  34311. */
  34312. AxisModelCommonMixin.prototype.getCoordSysModel = function () {
  34313. return;
  34314. };
  34315. return AxisModelCommonMixin;
  34316. }();
  34317. /**
  34318. * Create a multi dimension List structure from seriesModel.
  34319. */
  34320. function createList(seriesModel) {
  34321. return createSeriesData(null, seriesModel);
  34322. }
  34323. var dataStack$1 = {
  34324. isDimensionStacked: isDimensionStacked,
  34325. enableDataStack: enableDataStack,
  34326. getStackedDimension: getStackedDimension
  34327. };
  34328. /**
  34329. * Create scale
  34330. * @param {Array.<number>} dataExtent
  34331. * @param {Object|module:echarts/Model} option If `optoin.type`
  34332. * is secified, it can only be `'value'` currently.
  34333. */
  34334. function createScale(dataExtent, option) {
  34335. var axisModel = option;
  34336. if (!(option instanceof Model)) {
  34337. axisModel = new Model(option);
  34338. // FIXME
  34339. // Currently AxisModelCommonMixin has nothing to do with the
  34340. // the requirements of `axisHelper.createScaleByModel`. For
  34341. // example the methods `getCategories` and `getOrdinalMeta`
  34342. // are required for `'category'` axis, and ecModel is required
  34343. // for `'time'` axis. But occasionally echarts-gl happened
  34344. // to only use `'value'` axis.
  34345. // zrUtil.mixin(axisModel, AxisModelCommonMixin);
  34346. }
  34347. var scale = createScaleByModel(axisModel);
  34348. scale.setExtent(dataExtent[0], dataExtent[1]);
  34349. niceScaleExtent(scale, axisModel);
  34350. return scale;
  34351. }
  34352. /**
  34353. * Mixin common methods to axis model,
  34354. *
  34355. * Include methods
  34356. * `getFormattedLabels() => Array.<string>`
  34357. * `getCategories() => Array.<string>`
  34358. * `getMin(origin: boolean) => number`
  34359. * `getMax(origin: boolean) => number`
  34360. * `getNeedCrossZero() => boolean`
  34361. */
  34362. function mixinAxisModelCommonMethods(Model) {
  34363. mixin(Model, AxisModelCommonMixin);
  34364. }
  34365. function createTextStyle$1(textStyleModel, opts) {
  34366. opts = opts || {};
  34367. return createTextStyle(textStyleModel, null, null, opts.state !== 'normal');
  34368. }
  34369. var helper = /*#__PURE__*/Object.freeze({
  34370. __proto__: null,
  34371. createList: createList,
  34372. getLayoutRect: getLayoutRect,
  34373. dataStack: dataStack$1,
  34374. createScale: createScale,
  34375. mixinAxisModelCommonMethods: mixinAxisModelCommonMethods,
  34376. getECData: getECData,
  34377. createTextStyle: createTextStyle$1,
  34378. createDimensions: createDimensions,
  34379. createSymbol: createSymbol,
  34380. enableHoverEmphasis: enableHoverEmphasis
  34381. });
  34382. var EPSILON$5 = 1e-8;
  34383. function isAroundEqual$1(a, b) {
  34384. return Math.abs(a - b) < EPSILON$5;
  34385. }
  34386. function contain$2(points, x, y) {
  34387. var w = 0;
  34388. var p = points[0];
  34389. if (!p) {
  34390. return false;
  34391. }
  34392. for (var i = 1; i < points.length; i++) {
  34393. var p2 = points[i];
  34394. w += windingLine(p[0], p[1], p2[0], p2[1], x, y);
  34395. p = p2;
  34396. }
  34397. var p0 = points[0];
  34398. if (!isAroundEqual$1(p[0], p0[0]) || !isAroundEqual$1(p[1], p0[1])) {
  34399. w += windingLine(p[0], p[1], p0[0], p0[1], x, y);
  34400. }
  34401. return w !== 0;
  34402. }
  34403. var TMP_TRANSFORM = [];
  34404. function transformPoints(points, transform) {
  34405. for (var p = 0; p < points.length; p++) {
  34406. applyTransform(points[p], points[p], transform);
  34407. }
  34408. }
  34409. function updateBBoxFromPoints(points, min$1, max$1, projection) {
  34410. for (var i = 0; i < points.length; i++) {
  34411. var p = points[i];
  34412. if (projection) {
  34413. // projection may return null point.
  34414. p = projection.project(p);
  34415. }
  34416. if (p && isFinite(p[0]) && isFinite(p[1])) {
  34417. min(min$1, min$1, p);
  34418. max(max$1, max$1, p);
  34419. }
  34420. }
  34421. }
  34422. function centroid(points) {
  34423. var signedArea = 0;
  34424. var cx = 0;
  34425. var cy = 0;
  34426. var len = points.length;
  34427. var x0 = points[len - 1][0];
  34428. var y0 = points[len - 1][1];
  34429. // Polygon should been closed.
  34430. for (var i = 0; i < len; i++) {
  34431. var x1 = points[i][0];
  34432. var y1 = points[i][1];
  34433. var a = x0 * y1 - x1 * y0;
  34434. signedArea += a;
  34435. cx += (x0 + x1) * a;
  34436. cy += (y0 + y1) * a;
  34437. x0 = x1;
  34438. y0 = y1;
  34439. }
  34440. return signedArea ? [cx / signedArea / 3, cy / signedArea / 3, signedArea] : [points[0][0] || 0, points[0][1] || 0];
  34441. }
  34442. var Region = /** @class */function () {
  34443. function Region(name) {
  34444. this.name = name;
  34445. }
  34446. Region.prototype.setCenter = function (center) {
  34447. this._center = center;
  34448. };
  34449. /**
  34450. * Get center point in data unit. That is,
  34451. * for GeoJSONRegion, the unit is lat/lng,
  34452. * for GeoSVGRegion, the unit is SVG local coord.
  34453. */
  34454. Region.prototype.getCenter = function () {
  34455. var center = this._center;
  34456. if (!center) {
  34457. // In most cases there are no need to calculate this center.
  34458. // So calculate only when called.
  34459. center = this._center = this.calcCenter();
  34460. }
  34461. return center;
  34462. };
  34463. return Region;
  34464. }();
  34465. var GeoJSONPolygonGeometry = /** @class */function () {
  34466. function GeoJSONPolygonGeometry(exterior, interiors) {
  34467. this.type = 'polygon';
  34468. this.exterior = exterior;
  34469. this.interiors = interiors;
  34470. }
  34471. return GeoJSONPolygonGeometry;
  34472. }();
  34473. var GeoJSONLineStringGeometry = /** @class */function () {
  34474. function GeoJSONLineStringGeometry(points) {
  34475. this.type = 'linestring';
  34476. this.points = points;
  34477. }
  34478. return GeoJSONLineStringGeometry;
  34479. }();
  34480. var GeoJSONRegion = /** @class */function (_super) {
  34481. __extends(GeoJSONRegion, _super);
  34482. function GeoJSONRegion(name, geometries, cp) {
  34483. var _this = _super.call(this, name) || this;
  34484. _this.type = 'geoJSON';
  34485. _this.geometries = geometries;
  34486. _this._center = cp && [cp[0], cp[1]];
  34487. return _this;
  34488. }
  34489. GeoJSONRegion.prototype.calcCenter = function () {
  34490. var geometries = this.geometries;
  34491. var largestGeo;
  34492. var largestGeoSize = 0;
  34493. for (var i = 0; i < geometries.length; i++) {
  34494. var geo = geometries[i];
  34495. var exterior = geo.exterior;
  34496. // Simple trick to use points count instead of polygon area as region size.
  34497. // Ignore linestring
  34498. var size = exterior && exterior.length;
  34499. if (size > largestGeoSize) {
  34500. largestGeo = geo;
  34501. largestGeoSize = size;
  34502. }
  34503. }
  34504. if (largestGeo) {
  34505. return centroid(largestGeo.exterior);
  34506. }
  34507. // from bounding rect by default.
  34508. var rect = this.getBoundingRect();
  34509. return [rect.x + rect.width / 2, rect.y + rect.height / 2];
  34510. };
  34511. GeoJSONRegion.prototype.getBoundingRect = function (projection) {
  34512. var rect = this._rect;
  34513. // Always recalculate if using projection.
  34514. if (rect && !projection) {
  34515. return rect;
  34516. }
  34517. var min = [Infinity, Infinity];
  34518. var max = [-Infinity, -Infinity];
  34519. var geometries = this.geometries;
  34520. each(geometries, function (geo) {
  34521. if (geo.type === 'polygon') {
  34522. // Doesn't consider hole
  34523. updateBBoxFromPoints(geo.exterior, min, max, projection);
  34524. } else {
  34525. each(geo.points, function (points) {
  34526. updateBBoxFromPoints(points, min, max, projection);
  34527. });
  34528. }
  34529. });
  34530. // Normalie invalid bounding.
  34531. if (!(isFinite(min[0]) && isFinite(min[1]) && isFinite(max[0]) && isFinite(max[1]))) {
  34532. min[0] = min[1] = max[0] = max[1] = 0;
  34533. }
  34534. rect = new BoundingRect(min[0], min[1], max[0] - min[0], max[1] - min[1]);
  34535. if (!projection) {
  34536. this._rect = rect;
  34537. }
  34538. return rect;
  34539. };
  34540. GeoJSONRegion.prototype.contain = function (coord) {
  34541. var rect = this.getBoundingRect();
  34542. var geometries = this.geometries;
  34543. if (!rect.contain(coord[0], coord[1])) {
  34544. return false;
  34545. }
  34546. loopGeo: for (var i = 0, len = geometries.length; i < len; i++) {
  34547. var geo = geometries[i];
  34548. // Only support polygon.
  34549. if (geo.type !== 'polygon') {
  34550. continue;
  34551. }
  34552. var exterior = geo.exterior;
  34553. var interiors = geo.interiors;
  34554. if (contain$2(exterior, coord[0], coord[1])) {
  34555. // Not in the region if point is in the hole.
  34556. for (var k = 0; k < (interiors ? interiors.length : 0); k++) {
  34557. if (contain$2(interiors[k], coord[0], coord[1])) {
  34558. continue loopGeo;
  34559. }
  34560. }
  34561. return true;
  34562. }
  34563. }
  34564. return false;
  34565. };
  34566. /**
  34567. * Transform the raw coords to target bounding.
  34568. * @param x
  34569. * @param y
  34570. * @param width
  34571. * @param height
  34572. */
  34573. GeoJSONRegion.prototype.transformTo = function (x, y, width, height) {
  34574. var rect = this.getBoundingRect();
  34575. var aspect = rect.width / rect.height;
  34576. if (!width) {
  34577. width = aspect * height;
  34578. } else if (!height) {
  34579. height = width / aspect;
  34580. }
  34581. var target = new BoundingRect(x, y, width, height);
  34582. var transform = rect.calculateTransform(target);
  34583. var geometries = this.geometries;
  34584. for (var i = 0; i < geometries.length; i++) {
  34585. var geo = geometries[i];
  34586. if (geo.type === 'polygon') {
  34587. transformPoints(geo.exterior, transform);
  34588. each(geo.interiors, function (interior) {
  34589. transformPoints(interior, transform);
  34590. });
  34591. } else {
  34592. each(geo.points, function (points) {
  34593. transformPoints(points, transform);
  34594. });
  34595. }
  34596. }
  34597. rect = this._rect;
  34598. rect.copy(target);
  34599. // Update center
  34600. this._center = [rect.x + rect.width / 2, rect.y + rect.height / 2];
  34601. };
  34602. GeoJSONRegion.prototype.cloneShallow = function (name) {
  34603. name == null && (name = this.name);
  34604. var newRegion = new GeoJSONRegion(name, this.geometries, this._center);
  34605. newRegion._rect = this._rect;
  34606. newRegion.transformTo = null; // Simply avoid to be called.
  34607. return newRegion;
  34608. };
  34609. return GeoJSONRegion;
  34610. }(Region);
  34611. var GeoSVGRegion = /** @class */function (_super) {
  34612. __extends(GeoSVGRegion, _super);
  34613. function GeoSVGRegion(name, elOnlyForCalculate) {
  34614. var _this = _super.call(this, name) || this;
  34615. _this.type = 'geoSVG';
  34616. _this._elOnlyForCalculate = elOnlyForCalculate;
  34617. return _this;
  34618. }
  34619. GeoSVGRegion.prototype.calcCenter = function () {
  34620. var el = this._elOnlyForCalculate;
  34621. var rect = el.getBoundingRect();
  34622. var center = [rect.x + rect.width / 2, rect.y + rect.height / 2];
  34623. var mat = identity(TMP_TRANSFORM);
  34624. var target = el;
  34625. while (target && !target.isGeoSVGGraphicRoot) {
  34626. mul$1(mat, target.getLocalTransform(), mat);
  34627. target = target.parent;
  34628. }
  34629. invert(mat, mat);
  34630. applyTransform(center, center, mat);
  34631. return center;
  34632. };
  34633. return GeoSVGRegion;
  34634. }(Region);
  34635. function decode(json) {
  34636. if (!json.UTF8Encoding) {
  34637. return json;
  34638. }
  34639. var jsonCompressed = json;
  34640. var encodeScale = jsonCompressed.UTF8Scale;
  34641. if (encodeScale == null) {
  34642. encodeScale = 1024;
  34643. }
  34644. var features = jsonCompressed.features;
  34645. each(features, function (feature) {
  34646. var geometry = feature.geometry;
  34647. var encodeOffsets = geometry.encodeOffsets;
  34648. var coordinates = geometry.coordinates;
  34649. // Geometry may be appeded manually in the script after json loaded.
  34650. // In this case this geometry is usually not encoded.
  34651. if (!encodeOffsets) {
  34652. return;
  34653. }
  34654. switch (geometry.type) {
  34655. case 'LineString':
  34656. geometry.coordinates = decodeRing(coordinates, encodeOffsets, encodeScale);
  34657. break;
  34658. case 'Polygon':
  34659. decodeRings(coordinates, encodeOffsets, encodeScale);
  34660. break;
  34661. case 'MultiLineString':
  34662. decodeRings(coordinates, encodeOffsets, encodeScale);
  34663. break;
  34664. case 'MultiPolygon':
  34665. each(coordinates, function (rings, idx) {
  34666. return decodeRings(rings, encodeOffsets[idx], encodeScale);
  34667. });
  34668. }
  34669. });
  34670. // Has been decoded
  34671. jsonCompressed.UTF8Encoding = false;
  34672. return jsonCompressed;
  34673. }
  34674. function decodeRings(rings, encodeOffsets, encodeScale) {
  34675. for (var c = 0; c < rings.length; c++) {
  34676. rings[c] = decodeRing(rings[c], encodeOffsets[c], encodeScale);
  34677. }
  34678. }
  34679. function decodeRing(coordinate, encodeOffsets, encodeScale) {
  34680. var result = [];
  34681. var prevX = encodeOffsets[0];
  34682. var prevY = encodeOffsets[1];
  34683. for (var i = 0; i < coordinate.length; i += 2) {
  34684. var x = coordinate.charCodeAt(i) - 64;
  34685. var y = coordinate.charCodeAt(i + 1) - 64;
  34686. // ZigZag decoding
  34687. x = x >> 1 ^ -(x & 1);
  34688. y = y >> 1 ^ -(y & 1);
  34689. // Delta deocding
  34690. x += prevX;
  34691. y += prevY;
  34692. prevX = x;
  34693. prevY = y;
  34694. // Dequantize
  34695. result.push([x / encodeScale, y / encodeScale]);
  34696. }
  34697. return result;
  34698. }
  34699. function parseGeoJSON(geoJson, nameProperty) {
  34700. geoJson = decode(geoJson);
  34701. return map(filter(geoJson.features, function (featureObj) {
  34702. // Output of mapshaper may have geometry null
  34703. return featureObj.geometry && featureObj.properties && featureObj.geometry.coordinates.length > 0;
  34704. }), function (featureObj) {
  34705. var properties = featureObj.properties;
  34706. var geo = featureObj.geometry;
  34707. var geometries = [];
  34708. switch (geo.type) {
  34709. case 'Polygon':
  34710. var coordinates = geo.coordinates;
  34711. // According to the GeoJSON specification.
  34712. // First must be exterior, and the rest are all interior(holes).
  34713. geometries.push(new GeoJSONPolygonGeometry(coordinates[0], coordinates.slice(1)));
  34714. break;
  34715. case 'MultiPolygon':
  34716. each(geo.coordinates, function (item) {
  34717. if (item[0]) {
  34718. geometries.push(new GeoJSONPolygonGeometry(item[0], item.slice(1)));
  34719. }
  34720. });
  34721. break;
  34722. case 'LineString':
  34723. geometries.push(new GeoJSONLineStringGeometry([geo.coordinates]));
  34724. break;
  34725. case 'MultiLineString':
  34726. geometries.push(new GeoJSONLineStringGeometry(geo.coordinates));
  34727. }
  34728. var region = new GeoJSONRegion(properties[nameProperty || 'name'], geometries, properties.cp);
  34729. region.properties = properties;
  34730. return region;
  34731. });
  34732. }
  34733. var number = /*#__PURE__*/Object.freeze({
  34734. __proto__: null,
  34735. linearMap: linearMap,
  34736. round: round,
  34737. asc: asc,
  34738. getPrecision: getPrecision,
  34739. getPrecisionSafe: getPrecisionSafe,
  34740. getPixelPrecision: getPixelPrecision,
  34741. getPercentWithPrecision: getPercentWithPrecision,
  34742. parsePercent: parsePercent$1,
  34743. MAX_SAFE_INTEGER: MAX_SAFE_INTEGER,
  34744. remRadian: remRadian,
  34745. isRadianAroundZero: isRadianAroundZero,
  34746. parseDate: parseDate,
  34747. quantity: quantity,
  34748. quantityExponent: quantityExponent,
  34749. nice: nice,
  34750. quantile: quantile,
  34751. reformIntervals: reformIntervals,
  34752. isNumeric: isNumeric,
  34753. numericToNumber: numericToNumber
  34754. });
  34755. var time = /*#__PURE__*/Object.freeze({
  34756. __proto__: null,
  34757. parse: parseDate,
  34758. format: format,
  34759. roundTime: roundTime
  34760. });
  34761. var graphic$1 = /*#__PURE__*/Object.freeze({
  34762. __proto__: null,
  34763. extendShape: extendShape,
  34764. extendPath: extendPath,
  34765. makePath: makePath,
  34766. makeImage: makeImage,
  34767. mergePath: mergePath$1,
  34768. resizePath: resizePath,
  34769. createIcon: createIcon,
  34770. updateProps: updateProps,
  34771. initProps: initProps,
  34772. getTransform: getTransform,
  34773. clipPointsByRect: clipPointsByRect,
  34774. clipRectByRect: clipRectByRect,
  34775. registerShape: registerShape,
  34776. getShapeClass: getShapeClass,
  34777. Group: Group,
  34778. Image: ZRImage,
  34779. Text: ZRText,
  34780. Circle: Circle,
  34781. Ellipse: Ellipse,
  34782. Sector: Sector,
  34783. Ring: Ring,
  34784. Polygon: Polygon,
  34785. Polyline: Polyline,
  34786. Rect: Rect,
  34787. Line: Line,
  34788. BezierCurve: BezierCurve,
  34789. Arc: Arc,
  34790. IncrementalDisplayable: IncrementalDisplayable,
  34791. CompoundPath: CompoundPath,
  34792. LinearGradient: LinearGradient,
  34793. RadialGradient: RadialGradient,
  34794. BoundingRect: BoundingRect
  34795. });
  34796. var format$1 = /*#__PURE__*/Object.freeze({
  34797. __proto__: null,
  34798. addCommas: addCommas,
  34799. toCamelCase: toCamelCase,
  34800. normalizeCssArray: normalizeCssArray$1,
  34801. encodeHTML: encodeHTML,
  34802. formatTpl: formatTpl,
  34803. getTooltipMarker: getTooltipMarker,
  34804. formatTime: formatTime,
  34805. capitalFirst: capitalFirst,
  34806. truncateText: truncateText,
  34807. getTextRect: getTextRect
  34808. });
  34809. var util$1 = /*#__PURE__*/Object.freeze({
  34810. __proto__: null,
  34811. map: map,
  34812. each: each,
  34813. indexOf: indexOf,
  34814. inherits: inherits,
  34815. reduce: reduce,
  34816. filter: filter,
  34817. bind: bind,
  34818. curry: curry,
  34819. isArray: isArray,
  34820. isString: isString,
  34821. isObject: isObject,
  34822. isFunction: isFunction,
  34823. extend: extend,
  34824. defaults: defaults,
  34825. clone: clone,
  34826. merge: merge
  34827. });
  34828. var modelInner = makeInner();
  34829. var axisInner = makeInner();
  34830. var AxisTickLabelComputingKind = {
  34831. estimate: 1,
  34832. determine: 2
  34833. };
  34834. function createAxisLabelsComputingContext(kind) {
  34835. return {
  34836. out: {
  34837. noPxChangeTryDetermine: []
  34838. },
  34839. kind: kind
  34840. };
  34841. }
  34842. function tickValuesToNumbers(axis, values) {
  34843. var nums = map(values, function (val) {
  34844. return axis.scale.parse(val);
  34845. });
  34846. if (axis.type === 'time' && nums.length > 0) {
  34847. // Time axis needs duplicate first/last tick (see TimeScale.getTicks())
  34848. // The first and last tick/label don't get drawn
  34849. nums.sort();
  34850. nums.unshift(nums[0]);
  34851. nums.push(nums[nums.length - 1]);
  34852. }
  34853. return nums;
  34854. }
  34855. function createAxisLabels(axis, ctx) {
  34856. var custom = axis.getLabelModel().get('customValues');
  34857. if (custom) {
  34858. var labelFormatter_1 = makeLabelFormatter(axis);
  34859. var extent_1 = axis.scale.getExtent();
  34860. var tickNumbers = tickValuesToNumbers(axis, custom);
  34861. var ticks = filter(tickNumbers, function (val) {
  34862. return val >= extent_1[0] && val <= extent_1[1];
  34863. });
  34864. return {
  34865. labels: map(ticks, function (numval) {
  34866. var tick = {
  34867. value: numval
  34868. };
  34869. return {
  34870. formattedLabel: labelFormatter_1(tick),
  34871. rawLabel: axis.scale.getLabel(tick),
  34872. tickValue: numval,
  34873. time: undefined,
  34874. "break": undefined
  34875. };
  34876. })
  34877. };
  34878. }
  34879. // Only ordinal scale support tick interval
  34880. return axis.type === 'category' ? makeCategoryLabels(axis, ctx) : makeRealNumberLabels(axis);
  34881. }
  34882. /**
  34883. * @param tickModel For example, can be axisTick, splitLine, splitArea.
  34884. */
  34885. function createAxisTicks(axis, tickModel, opt) {
  34886. var custom = axis.getTickModel().get('customValues');
  34887. if (custom) {
  34888. var extent_2 = axis.scale.getExtent();
  34889. var tickNumbers = tickValuesToNumbers(axis, custom);
  34890. return {
  34891. ticks: filter(tickNumbers, function (val) {
  34892. return val >= extent_2[0] && val <= extent_2[1];
  34893. })
  34894. };
  34895. }
  34896. // Only ordinal scale support tick interval
  34897. return axis.type === 'category' ? makeCategoryTicks(axis, tickModel) : {
  34898. ticks: map(axis.scale.getTicks(opt), function (tick) {
  34899. return tick.value;
  34900. })
  34901. };
  34902. }
  34903. function makeCategoryLabels(axis, ctx) {
  34904. var labelModel = axis.getLabelModel();
  34905. var result = makeCategoryLabelsActually(axis, labelModel, ctx);
  34906. return !labelModel.get('show') || axis.scale.isBlank() ? {
  34907. labels: []
  34908. } : result;
  34909. }
  34910. function makeCategoryLabelsActually(axis, labelModel, ctx) {
  34911. var labelsCache = ensureCategoryLabelCache(axis);
  34912. var optionLabelInterval = getOptionCategoryInterval(labelModel);
  34913. var isEstimate = ctx.kind === AxisTickLabelComputingKind.estimate;
  34914. // In AxisTickLabelComputingKind.estimate, the result likely varies during a single
  34915. // pass of ec main process,due to the change of axisExtent, and will not be shared with
  34916. // splitLine. Therefore no cache is used.
  34917. if (!isEstimate) {
  34918. // PENDING: check necessary?
  34919. var result_1 = axisCacheGet(labelsCache, optionLabelInterval);
  34920. if (result_1) {
  34921. return result_1;
  34922. }
  34923. }
  34924. var labels;
  34925. var numericLabelInterval;
  34926. if (isFunction(optionLabelInterval)) {
  34927. labels = makeLabelsByCustomizedCategoryInterval(axis, optionLabelInterval);
  34928. } else {
  34929. numericLabelInterval = optionLabelInterval === 'auto' ? makeAutoCategoryInterval(axis, ctx) : optionLabelInterval;
  34930. labels = makeLabelsByNumericCategoryInterval(axis, numericLabelInterval);
  34931. }
  34932. var result = {
  34933. labels: labels,
  34934. labelCategoryInterval: numericLabelInterval
  34935. };
  34936. if (!isEstimate) {
  34937. axisCacheSet(labelsCache, optionLabelInterval, result);
  34938. } else {
  34939. ctx.out.noPxChangeTryDetermine.push(function () {
  34940. axisCacheSet(labelsCache, optionLabelInterval, result);
  34941. return true;
  34942. });
  34943. }
  34944. return result;
  34945. }
  34946. function makeCategoryTicks(axis, tickModel) {
  34947. var ticksCache = ensureCategoryTickCache(axis);
  34948. var optionTickInterval = getOptionCategoryInterval(tickModel);
  34949. var result = axisCacheGet(ticksCache, optionTickInterval);
  34950. if (result) {
  34951. return result;
  34952. }
  34953. var ticks;
  34954. var tickCategoryInterval;
  34955. // Optimize for the case that large category data and no label displayed,
  34956. // we should not return all ticks.
  34957. if (!tickModel.get('show') || axis.scale.isBlank()) {
  34958. ticks = [];
  34959. }
  34960. if (isFunction(optionTickInterval)) {
  34961. ticks = makeLabelsByCustomizedCategoryInterval(axis, optionTickInterval, true);
  34962. }
  34963. // Always use label interval by default despite label show. Consider this
  34964. // scenario, Use multiple grid with the xAxis sync, and only one xAxis shows
  34965. // labels. `splitLine` and `axisTick` should be consistent in this case.
  34966. else if (optionTickInterval === 'auto') {
  34967. var labelsResult = makeCategoryLabelsActually(axis, axis.getLabelModel(), createAxisLabelsComputingContext(AxisTickLabelComputingKind.determine));
  34968. tickCategoryInterval = labelsResult.labelCategoryInterval;
  34969. ticks = map(labelsResult.labels, function (labelItem) {
  34970. return labelItem.tickValue;
  34971. });
  34972. } else {
  34973. tickCategoryInterval = optionTickInterval;
  34974. ticks = makeLabelsByNumericCategoryInterval(axis, tickCategoryInterval, true);
  34975. }
  34976. // Cache to avoid calling interval function repeatedly.
  34977. return axisCacheSet(ticksCache, optionTickInterval, {
  34978. ticks: ticks,
  34979. tickCategoryInterval: tickCategoryInterval
  34980. });
  34981. }
  34982. function makeRealNumberLabels(axis) {
  34983. var ticks = axis.scale.getTicks();
  34984. var labelFormatter = makeLabelFormatter(axis);
  34985. return {
  34986. labels: map(ticks, function (tick, idx) {
  34987. return {
  34988. formattedLabel: labelFormatter(tick, idx),
  34989. rawLabel: axis.scale.getLabel(tick),
  34990. tickValue: tick.value,
  34991. time: tick.time,
  34992. "break": tick["break"]
  34993. };
  34994. })
  34995. };
  34996. }
  34997. // Large category data calculation is performance sensitive, and ticks and label probably will
  34998. // be fetched multiple times (e.g. shared by splitLine and axisTick). So we cache the result.
  34999. // axis is created each time during a ec process, so we do not need to clear cache.
  35000. var ensureCategoryTickCache = initAxisCacheMethod('axisTick');
  35001. var ensureCategoryLabelCache = initAxisCacheMethod('axisLabel');
  35002. /**
  35003. * PENDING: refactor to JS Map? Because key can be a function or more complicated object, and
  35004. * cache size always is small, and currently no JS Map object key polyfill, we use a simple
  35005. * array cache instead of plain object hash.
  35006. */
  35007. function initAxisCacheMethod(prop) {
  35008. return function ensureCache(axis) {
  35009. return axisInner(axis)[prop] || (axisInner(axis)[prop] = {
  35010. list: []
  35011. });
  35012. };
  35013. }
  35014. function axisCacheGet(cache, key) {
  35015. for (var i = 0; i < cache.list.length; i++) {
  35016. if (cache.list[i].key === key) {
  35017. return cache.list[i].value;
  35018. }
  35019. }
  35020. }
  35021. function axisCacheSet(cache, key, value) {
  35022. cache.list.push({
  35023. key: key,
  35024. value: value
  35025. });
  35026. return value;
  35027. }
  35028. function makeAutoCategoryInterval(axis, ctx) {
  35029. if (ctx.kind === AxisTickLabelComputingKind.estimate) {
  35030. // Currently axisTick is not involved in estimate kind, and the result likely varies during a
  35031. // single pass of ec main process, due to the change of axisExtent. Therefore no cache is used.
  35032. var result_2 = axis.calculateCategoryInterval(ctx);
  35033. ctx.out.noPxChangeTryDetermine.push(function () {
  35034. axisInner(axis).autoInterval = result_2;
  35035. return true;
  35036. });
  35037. return result_2;
  35038. }
  35039. // Both tick and label uses this result, cacah it to avoid recompute.
  35040. var result = axisInner(axis).autoInterval;
  35041. return result != null ? result : axisInner(axis).autoInterval = axis.calculateCategoryInterval(ctx);
  35042. }
  35043. /**
  35044. * Calculate interval for category axis ticks and labels.
  35045. * Use a stretegy to try to avoid overlapping.
  35046. * To get precise result, at least one of `getRotate` and `isHorizontal`
  35047. * should be implemented in axis.
  35048. */
  35049. function calculateCategoryInterval(axis, ctx) {
  35050. var kind = ctx.kind;
  35051. var params = fetchAutoCategoryIntervalCalculationParams(axis);
  35052. var labelFormatter = makeLabelFormatter(axis);
  35053. var rotation = (params.axisRotate - params.labelRotate) / 180 * Math.PI;
  35054. var ordinalScale = axis.scale;
  35055. var ordinalExtent = ordinalScale.getExtent();
  35056. // Providing this method is for optimization:
  35057. // avoid generating a long array by `getTicks`
  35058. // in large category data case.
  35059. var tickCount = ordinalScale.count();
  35060. if (ordinalExtent[1] - ordinalExtent[0] < 1) {
  35061. return 0;
  35062. }
  35063. var step = 1;
  35064. // Simple optimization. Arbitrary value.
  35065. var maxCount = 40;
  35066. if (tickCount > maxCount) {
  35067. step = Math.max(1, Math.floor(tickCount / maxCount));
  35068. }
  35069. var tickValue = ordinalExtent[0];
  35070. var unitSpan = axis.dataToCoord(tickValue + 1) - axis.dataToCoord(tickValue);
  35071. var unitW = Math.abs(unitSpan * Math.cos(rotation));
  35072. var unitH = Math.abs(unitSpan * Math.sin(rotation));
  35073. var maxW = 0;
  35074. var maxH = 0;
  35075. // Caution: Performance sensitive for large category data.
  35076. // Consider dataZoom, we should make appropriate step to avoid O(n) loop.
  35077. for (; tickValue <= ordinalExtent[1]; tickValue += step) {
  35078. var width = 0;
  35079. var height = 0;
  35080. // Not precise, do not consider align and vertical align
  35081. // and each distance from axis line yet.
  35082. var rect = getBoundingRect(labelFormatter({
  35083. value: tickValue
  35084. }), params.font, 'center', 'top');
  35085. // Magic number
  35086. width = rect.width * 1.3;
  35087. height = rect.height * 1.3;
  35088. // Min size, void long loop.
  35089. maxW = Math.max(maxW, width, 7);
  35090. maxH = Math.max(maxH, height, 7);
  35091. }
  35092. var dw = maxW / unitW;
  35093. var dh = maxH / unitH;
  35094. // 0/0 is NaN, 1/0 is Infinity.
  35095. isNaN(dw) && (dw = Infinity);
  35096. isNaN(dh) && (dh = Infinity);
  35097. var interval = Math.max(0, Math.floor(Math.min(dw, dh)));
  35098. if (kind === AxisTickLabelComputingKind.estimate) {
  35099. // In estimate kind, the inteval likely varies, thus do not erase the cache.
  35100. ctx.out.noPxChangeTryDetermine.push(bind(calculateCategoryIntervalTryDetermine, null, axis, interval, tickCount));
  35101. return interval;
  35102. }
  35103. var lastInterval = calculateCategoryIntervalDealCache(axis, interval, tickCount);
  35104. return lastInterval != null ? lastInterval : interval;
  35105. }
  35106. function calculateCategoryIntervalTryDetermine(axis, interval, tickCount) {
  35107. return calculateCategoryIntervalDealCache(axis, interval, tickCount) == null;
  35108. }
  35109. // Return the lastInterval if need to use it, otherwise return NullUndefined and save cache.
  35110. function calculateCategoryIntervalDealCache(axis, interval, tickCount) {
  35111. var cache = modelInner(axis.model);
  35112. var axisExtent = axis.getExtent();
  35113. var lastAutoInterval = cache.lastAutoInterval;
  35114. var lastTickCount = cache.lastTickCount;
  35115. // Use cache to keep interval stable while moving zoom window,
  35116. // otherwise the calculated interval might jitter when the zoom
  35117. // window size is close to the interval-changing size.
  35118. // For example, if all of the axis labels are `a, b, c, d, e, f, g`.
  35119. // The jitter will cause that sometimes the displayed labels are
  35120. // `a, d, g` (interval: 2) sometimes `a, c, e`(interval: 1).
  35121. if (lastAutoInterval != null && lastTickCount != null && Math.abs(lastAutoInterval - interval) <= 1 && Math.abs(lastTickCount - tickCount) <= 1
  35122. // Always choose the bigger one, otherwise the critical
  35123. // point is not the same when zooming in or zooming out.
  35124. && lastAutoInterval > interval
  35125. // If the axis change is caused by chart resize, the cache should not
  35126. // be used. Otherwise some hidden labels might not be shown again.
  35127. && cache.axisExtent0 === axisExtent[0] && cache.axisExtent1 === axisExtent[1]) {
  35128. return lastAutoInterval;
  35129. }
  35130. // Only update cache if cache not used, otherwise the
  35131. // changing of interval is too insensitive.
  35132. else {
  35133. cache.lastTickCount = tickCount;
  35134. cache.lastAutoInterval = interval;
  35135. cache.axisExtent0 = axisExtent[0];
  35136. cache.axisExtent1 = axisExtent[1];
  35137. }
  35138. }
  35139. function fetchAutoCategoryIntervalCalculationParams(axis) {
  35140. var labelModel = axis.getLabelModel();
  35141. return {
  35142. axisRotate: axis.getRotate ? axis.getRotate() : axis.isHorizontal && !axis.isHorizontal() ? 90 : 0,
  35143. labelRotate: labelModel.get('rotate') || 0,
  35144. font: labelModel.getFont()
  35145. };
  35146. }
  35147. function makeLabelsByNumericCategoryInterval(axis, categoryInterval, onlyTick) {
  35148. var labelFormatter = makeLabelFormatter(axis);
  35149. var ordinalScale = axis.scale;
  35150. var ordinalExtent = ordinalScale.getExtent();
  35151. var labelModel = axis.getLabelModel();
  35152. var result = [];
  35153. // TODO: axisType: ordinalTime, pick the tick from each month/day/year/...
  35154. var step = Math.max((categoryInterval || 0) + 1, 1);
  35155. var startTick = ordinalExtent[0];
  35156. var tickCount = ordinalScale.count();
  35157. // Calculate start tick based on zero if possible to keep label consistent
  35158. // while zooming and moving while interval > 0. Otherwise the selection
  35159. // of displayable ticks and symbols probably keep changing.
  35160. // 3 is empirical value.
  35161. if (startTick !== 0 && step > 1 && tickCount / step > 2) {
  35162. startTick = Math.round(Math.ceil(startTick / step) * step);
  35163. }
  35164. // (1) Only add min max label here but leave overlap checking
  35165. // to render stage, which also ensure the returned list
  35166. // suitable for splitLine and splitArea rendering.
  35167. // (2) Scales except category always contain min max label so
  35168. // do not need to perform this process.
  35169. var showAllLabel = shouldShowAllLabels(axis);
  35170. var includeMinLabel = labelModel.get('showMinLabel') || showAllLabel;
  35171. var includeMaxLabel = labelModel.get('showMaxLabel') || showAllLabel;
  35172. if (includeMinLabel && startTick !== ordinalExtent[0]) {
  35173. addItem(ordinalExtent[0]);
  35174. }
  35175. // Optimize: avoid generating large array by `ordinalScale.getTicks()`.
  35176. var tickValue = startTick;
  35177. for (; tickValue <= ordinalExtent[1]; tickValue += step) {
  35178. addItem(tickValue);
  35179. }
  35180. if (includeMaxLabel && tickValue - step !== ordinalExtent[1]) {
  35181. addItem(ordinalExtent[1]);
  35182. }
  35183. function addItem(tickValue) {
  35184. var tickObj = {
  35185. value: tickValue
  35186. };
  35187. result.push(onlyTick ? tickValue : {
  35188. formattedLabel: labelFormatter(tickObj),
  35189. rawLabel: ordinalScale.getLabel(tickObj),
  35190. tickValue: tickValue,
  35191. time: undefined,
  35192. "break": undefined
  35193. });
  35194. }
  35195. return result;
  35196. }
  35197. function makeLabelsByCustomizedCategoryInterval(axis, categoryInterval, onlyTick) {
  35198. var ordinalScale = axis.scale;
  35199. var labelFormatter = makeLabelFormatter(axis);
  35200. var result = [];
  35201. each(ordinalScale.getTicks(), function (tick) {
  35202. var rawLabel = ordinalScale.getLabel(tick);
  35203. var tickValue = tick.value;
  35204. if (categoryInterval(tick.value, rawLabel)) {
  35205. result.push(onlyTick ? tickValue : {
  35206. formattedLabel: labelFormatter(tick),
  35207. rawLabel: rawLabel,
  35208. tickValue: tickValue,
  35209. time: undefined,
  35210. "break": undefined
  35211. });
  35212. }
  35213. });
  35214. return result;
  35215. }
  35216. var NORMALIZED_EXTENT = [0, 1];
  35217. /**
  35218. * Base class of Axis.
  35219. *
  35220. * Lifetime: recreate for each main process.
  35221. * [NOTICE]: Some caches is stored on the axis instance (see `axisTickLabelBuilder.ts`)
  35222. * which is based on this lifetime.
  35223. */
  35224. var Axis = /** @class */function () {
  35225. function Axis(dim, scale, extent) {
  35226. this.onBand = false;
  35227. // Make sure that `extent[0] > extent[1]` only if `inverse: true`.
  35228. // `inverse` can be inferred by `extent` unless `extent[0] === extent[1]`.
  35229. this.inverse = false;
  35230. this.dim = dim;
  35231. this.scale = scale;
  35232. this._extent = extent || [0, 0];
  35233. }
  35234. /**
  35235. * If axis extent contain given coord
  35236. */
  35237. Axis.prototype.contain = function (coord) {
  35238. var extent = this._extent;
  35239. var min = Math.min(extent[0], extent[1]);
  35240. var max = Math.max(extent[0], extent[1]);
  35241. return coord >= min && coord <= max;
  35242. };
  35243. /**
  35244. * If axis extent contain given data
  35245. */
  35246. Axis.prototype.containData = function (data) {
  35247. return this.scale.contain(this.scale.parse(data));
  35248. };
  35249. /**
  35250. * Get coord extent.
  35251. */
  35252. Axis.prototype.getExtent = function () {
  35253. return this._extent.slice();
  35254. };
  35255. /**
  35256. * Get precision used for formatting
  35257. */
  35258. Axis.prototype.getPixelPrecision = function (dataExtent) {
  35259. return getPixelPrecision(dataExtent || this.scale.getExtent(), this._extent);
  35260. };
  35261. /**
  35262. * Set coord extent
  35263. */
  35264. Axis.prototype.setExtent = function (start, end) {
  35265. var extent = this._extent;
  35266. extent[0] = start;
  35267. extent[1] = end;
  35268. };
  35269. /**
  35270. * Convert data to coord. Data is the rank if it has an ordinal scale
  35271. */
  35272. Axis.prototype.dataToCoord = function (data, clamp) {
  35273. var extent = this._extent;
  35274. var scale = this.scale;
  35275. data = scale.normalize(scale.parse(data));
  35276. if (this.onBand && scale.type === 'ordinal') {
  35277. extent = extent.slice();
  35278. fixExtentWithBands(extent, scale.count());
  35279. }
  35280. return linearMap(data, NORMALIZED_EXTENT, extent, clamp);
  35281. };
  35282. /**
  35283. * Convert coord to data. Data is the rank if it has an ordinal scale
  35284. */
  35285. Axis.prototype.coordToData = function (coord, clamp) {
  35286. var extent = this._extent;
  35287. var scale = this.scale;
  35288. if (this.onBand && scale.type === 'ordinal') {
  35289. extent = extent.slice();
  35290. fixExtentWithBands(extent, scale.count());
  35291. }
  35292. var t = linearMap(coord, extent, NORMALIZED_EXTENT, clamp);
  35293. return this.scale.scale(t);
  35294. };
  35295. /**
  35296. * Convert pixel point to data in axis
  35297. */
  35298. Axis.prototype.pointToData = function (point, clamp) {
  35299. // Should be implemented in derived class if necessary.
  35300. return;
  35301. };
  35302. /**
  35303. * Different from `zrUtil.map(axis.getTicks(), axis.dataToCoord, axis)`,
  35304. * `axis.getTicksCoords` considers `onBand`, which is used by
  35305. * `boundaryGap:true` of category axis and splitLine and splitArea.
  35306. * @param opt.tickModel default: axis.model.getModel('axisTick')
  35307. * @param opt.clamp If `true`, the first and the last
  35308. * tick must be at the axis end points. Otherwise, clip ticks
  35309. * that outside the axis extent.
  35310. */
  35311. Axis.prototype.getTicksCoords = function (opt) {
  35312. opt = opt || {};
  35313. var tickModel = opt.tickModel || this.getTickModel();
  35314. var result = createAxisTicks(this, tickModel, {
  35315. breakTicks: opt.breakTicks,
  35316. pruneByBreak: opt.pruneByBreak
  35317. });
  35318. var ticks = result.ticks;
  35319. var ticksCoords = map(ticks, function (tickVal) {
  35320. return {
  35321. coord: this.dataToCoord(this.scale.type === 'ordinal' ? this.scale.getRawOrdinalNumber(tickVal) : tickVal),
  35322. tickValue: tickVal
  35323. };
  35324. }, this);
  35325. var alignWithLabel = tickModel.get('alignWithLabel');
  35326. fixOnBandTicksCoords(this, ticksCoords, alignWithLabel, opt.clamp);
  35327. return ticksCoords;
  35328. };
  35329. Axis.prototype.getMinorTicksCoords = function () {
  35330. if (this.scale.type === 'ordinal') {
  35331. // Category axis doesn't support minor ticks
  35332. return [];
  35333. }
  35334. var minorTickModel = this.model.getModel('minorTick');
  35335. var splitNumber = minorTickModel.get('splitNumber');
  35336. // Protection.
  35337. if (!(splitNumber > 0 && splitNumber < 100)) {
  35338. splitNumber = 5;
  35339. }
  35340. var minorTicks = this.scale.getMinorTicks(splitNumber);
  35341. var minorTicksCoords = map(minorTicks, function (minorTicksGroup) {
  35342. return map(minorTicksGroup, function (minorTick) {
  35343. return {
  35344. coord: this.dataToCoord(minorTick),
  35345. tickValue: minorTick
  35346. };
  35347. }, this);
  35348. }, this);
  35349. return minorTicksCoords;
  35350. };
  35351. Axis.prototype.getViewLabels = function (ctx) {
  35352. ctx = ctx || createAxisLabelsComputingContext(AxisTickLabelComputingKind.determine);
  35353. return createAxisLabels(this, ctx).labels;
  35354. };
  35355. Axis.prototype.getLabelModel = function () {
  35356. return this.model.getModel('axisLabel');
  35357. };
  35358. /**
  35359. * Notice here we only get the default tick model. For splitLine
  35360. * or splitArea, we should pass the splitLineModel or splitAreaModel
  35361. * manually when calling `getTicksCoords`.
  35362. * In GL, this method may be overridden to:
  35363. * `axisModel.getModel('axisTick', grid3DModel.getModel('axisTick'));`
  35364. */
  35365. Axis.prototype.getTickModel = function () {
  35366. return this.model.getModel('axisTick');
  35367. };
  35368. /**
  35369. * Get width of band
  35370. */
  35371. Axis.prototype.getBandWidth = function () {
  35372. var axisExtent = this._extent;
  35373. var dataExtent = this.scale.getExtent();
  35374. var len = dataExtent[1] - dataExtent[0] + (this.onBand ? 1 : 0);
  35375. // Fix #2728, avoid NaN when only one data.
  35376. len === 0 && (len = 1);
  35377. var size = Math.abs(axisExtent[1] - axisExtent[0]);
  35378. return Math.abs(size) / len;
  35379. };
  35380. /**
  35381. * Only be called in category axis.
  35382. * Can be overridden, consider other axes like in 3D.
  35383. * @return Auto interval for cateogry axis tick and label
  35384. */
  35385. Axis.prototype.calculateCategoryInterval = function (ctx) {
  35386. ctx = ctx || createAxisLabelsComputingContext(AxisTickLabelComputingKind.determine);
  35387. return calculateCategoryInterval(this, ctx);
  35388. };
  35389. return Axis;
  35390. }();
  35391. function fixExtentWithBands(extent, nTick) {
  35392. var size = extent[1] - extent[0];
  35393. var len = nTick;
  35394. var margin = size / len / 2;
  35395. extent[0] += margin;
  35396. extent[1] -= margin;
  35397. }
  35398. // If axis has labels [1, 2, 3, 4]. Bands on the axis are
  35399. // |---1---|---2---|---3---|---4---|.
  35400. // So the displayed ticks and splitLine/splitArea should between
  35401. // each data item, otherwise cause misleading (e.g., split tow bars
  35402. // of a single data item when there are two bar series).
  35403. // Also consider if tickCategoryInterval > 0 and onBand, ticks and
  35404. // splitLine/spliteArea should layout appropriately corresponding
  35405. // to displayed labels. (So we should not use `getBandWidth` in this
  35406. // case).
  35407. function fixOnBandTicksCoords(axis, ticksCoords, alignWithLabel, clamp) {
  35408. var ticksLen = ticksCoords.length;
  35409. if (!axis.onBand || alignWithLabel || !ticksLen) {
  35410. return;
  35411. }
  35412. var axisExtent = axis.getExtent();
  35413. var last;
  35414. var diffSize;
  35415. if (ticksLen === 1) {
  35416. ticksCoords[0].coord = axisExtent[0];
  35417. ticksCoords[0].onBand = true;
  35418. last = ticksCoords[1] = {
  35419. coord: axisExtent[1],
  35420. tickValue: ticksCoords[0].tickValue,
  35421. onBand: true
  35422. };
  35423. } else {
  35424. var crossLen = ticksCoords[ticksLen - 1].tickValue - ticksCoords[0].tickValue;
  35425. var shift_1 = (ticksCoords[ticksLen - 1].coord - ticksCoords[0].coord) / crossLen;
  35426. each(ticksCoords, function (ticksItem) {
  35427. ticksItem.coord -= shift_1 / 2;
  35428. ticksItem.onBand = true;
  35429. });
  35430. var dataExtent = axis.scale.getExtent();
  35431. diffSize = 1 + dataExtent[1] - ticksCoords[ticksLen - 1].tickValue;
  35432. last = {
  35433. coord: ticksCoords[ticksLen - 1].coord + shift_1 * diffSize,
  35434. tickValue: dataExtent[1] + 1,
  35435. onBand: true
  35436. };
  35437. ticksCoords.push(last);
  35438. }
  35439. var inverse = axisExtent[0] > axisExtent[1];
  35440. // Handling clamp.
  35441. if (littleThan(ticksCoords[0].coord, axisExtent[0])) {
  35442. clamp ? ticksCoords[0].coord = axisExtent[0] : ticksCoords.shift();
  35443. }
  35444. if (clamp && littleThan(axisExtent[0], ticksCoords[0].coord)) {
  35445. ticksCoords.unshift({
  35446. coord: axisExtent[0],
  35447. onBand: true
  35448. });
  35449. }
  35450. if (littleThan(axisExtent[1], last.coord)) {
  35451. clamp ? last.coord = axisExtent[1] : ticksCoords.pop();
  35452. }
  35453. if (clamp && littleThan(last.coord, axisExtent[1])) {
  35454. ticksCoords.push({
  35455. coord: axisExtent[1],
  35456. onBand: true
  35457. });
  35458. }
  35459. function littleThan(a, b) {
  35460. // Avoid rounding error cause calculated tick coord different with extent.
  35461. // It may cause an extra unnecessary tick added.
  35462. a = round(a);
  35463. b = round(b);
  35464. return inverse ? a > b : a < b;
  35465. }
  35466. }
  35467. // --------------------- Deprecated Extension Methods ---------------------
  35468. // Should use `ComponentModel.extend` or `class XXXX extend ComponentModel` to create class.
  35469. // Then use `registerComponentModel` in `install` parameter when `use` this extension. For example:
  35470. // class Bar3DModel extends ComponentModel {}
  35471. // export function install(registers) { registers.registerComponentModel(Bar3DModel); }
  35472. // echarts.use(install);
  35473. function extendComponentModel(proto) {
  35474. var Model = ComponentModel.extend(proto);
  35475. ComponentModel.registerClass(Model);
  35476. return Model;
  35477. }
  35478. function extendComponentView(proto) {
  35479. var View = ComponentView.extend(proto);
  35480. ComponentView.registerClass(View);
  35481. return View;
  35482. }
  35483. function extendSeriesModel(proto) {
  35484. var Model = SeriesModel.extend(proto);
  35485. SeriesModel.registerClass(Model);
  35486. return Model;
  35487. }
  35488. function extendChartView(proto) {
  35489. var View = ChartView.extend(proto);
  35490. ChartView.registerClass(View);
  35491. return View;
  35492. }
  35493. var PI2$6 = Math.PI * 2;
  35494. var CMD$3 = PathProxy.CMD;
  35495. var DEFAULT_SEARCH_SPACE = ['top', 'right', 'bottom', 'left'];
  35496. function getCandidateAnchor(pos, distance, rect, outPt, outDir) {
  35497. var width = rect.width;
  35498. var height = rect.height;
  35499. switch (pos) {
  35500. case 'top':
  35501. outPt.set(rect.x + width / 2, rect.y - distance);
  35502. outDir.set(0, -1);
  35503. break;
  35504. case 'bottom':
  35505. outPt.set(rect.x + width / 2, rect.y + height + distance);
  35506. outDir.set(0, 1);
  35507. break;
  35508. case 'left':
  35509. outPt.set(rect.x - distance, rect.y + height / 2);
  35510. outDir.set(-1, 0);
  35511. break;
  35512. case 'right':
  35513. outPt.set(rect.x + width + distance, rect.y + height / 2);
  35514. outDir.set(1, 0);
  35515. break;
  35516. }
  35517. }
  35518. function projectPointToArc(cx, cy, r, startAngle, endAngle, anticlockwise, x, y, out) {
  35519. x -= cx;
  35520. y -= cy;
  35521. var d = Math.sqrt(x * x + y * y);
  35522. x /= d;
  35523. y /= d;
  35524. // Intersect point.
  35525. var ox = x * r + cx;
  35526. var oy = y * r + cy;
  35527. if (Math.abs(startAngle - endAngle) % PI2$6 < 1e-4) {
  35528. // Is a circle
  35529. out[0] = ox;
  35530. out[1] = oy;
  35531. return d - r;
  35532. }
  35533. if (anticlockwise) {
  35534. var tmp = startAngle;
  35535. startAngle = normalizeRadian(endAngle);
  35536. endAngle = normalizeRadian(tmp);
  35537. } else {
  35538. startAngle = normalizeRadian(startAngle);
  35539. endAngle = normalizeRadian(endAngle);
  35540. }
  35541. if (startAngle > endAngle) {
  35542. endAngle += PI2$6;
  35543. }
  35544. var angle = Math.atan2(y, x);
  35545. if (angle < 0) {
  35546. angle += PI2$6;
  35547. }
  35548. if (angle >= startAngle && angle <= endAngle || angle + PI2$6 >= startAngle && angle + PI2$6 <= endAngle) {
  35549. // Project point is on the arc.
  35550. out[0] = ox;
  35551. out[1] = oy;
  35552. return d - r;
  35553. }
  35554. var x1 = r * Math.cos(startAngle) + cx;
  35555. var y1 = r * Math.sin(startAngle) + cy;
  35556. var x2 = r * Math.cos(endAngle) + cx;
  35557. var y2 = r * Math.sin(endAngle) + cy;
  35558. var d1 = (x1 - x) * (x1 - x) + (y1 - y) * (y1 - y);
  35559. var d2 = (x2 - x) * (x2 - x) + (y2 - y) * (y2 - y);
  35560. if (d1 < d2) {
  35561. out[0] = x1;
  35562. out[1] = y1;
  35563. return Math.sqrt(d1);
  35564. } else {
  35565. out[0] = x2;
  35566. out[1] = y2;
  35567. return Math.sqrt(d2);
  35568. }
  35569. }
  35570. function projectPointToLine(x1, y1, x2, y2, x, y, out, limitToEnds) {
  35571. var dx = x - x1;
  35572. var dy = y - y1;
  35573. var dx1 = x2 - x1;
  35574. var dy1 = y2 - y1;
  35575. var lineLen = Math.sqrt(dx1 * dx1 + dy1 * dy1);
  35576. dx1 /= lineLen;
  35577. dy1 /= lineLen;
  35578. // dot product
  35579. var projectedLen = dx * dx1 + dy * dy1;
  35580. var t = projectedLen / lineLen;
  35581. if (limitToEnds) {
  35582. t = Math.min(Math.max(t, 0), 1);
  35583. }
  35584. t *= lineLen;
  35585. var ox = out[0] = x1 + t * dx1;
  35586. var oy = out[1] = y1 + t * dy1;
  35587. return Math.sqrt((ox - x) * (ox - x) + (oy - y) * (oy - y));
  35588. }
  35589. function projectPointToRect(x1, y1, width, height, x, y, out) {
  35590. if (width < 0) {
  35591. x1 = x1 + width;
  35592. width = -width;
  35593. }
  35594. if (height < 0) {
  35595. y1 = y1 + height;
  35596. height = -height;
  35597. }
  35598. var x2 = x1 + width;
  35599. var y2 = y1 + height;
  35600. var ox = out[0] = Math.min(Math.max(x, x1), x2);
  35601. var oy = out[1] = Math.min(Math.max(y, y1), y2);
  35602. return Math.sqrt((ox - x) * (ox - x) + (oy - y) * (oy - y));
  35603. }
  35604. var tmpPt = [];
  35605. function nearestPointOnRect(pt, rect, out) {
  35606. var dist = projectPointToRect(rect.x, rect.y, rect.width, rect.height, pt.x, pt.y, tmpPt);
  35607. out.set(tmpPt[0], tmpPt[1]);
  35608. return dist;
  35609. }
  35610. /**
  35611. * Calculate min distance corresponding point.
  35612. * This method won't evaluate if point is in the path.
  35613. */
  35614. function nearestPointOnPath(pt, path, out) {
  35615. var xi = 0;
  35616. var yi = 0;
  35617. var x0 = 0;
  35618. var y0 = 0;
  35619. var x1;
  35620. var y1;
  35621. var minDist = Infinity;
  35622. var data = path.data;
  35623. var x = pt.x;
  35624. var y = pt.y;
  35625. for (var i = 0; i < data.length;) {
  35626. var cmd = data[i++];
  35627. if (i === 1) {
  35628. xi = data[i];
  35629. yi = data[i + 1];
  35630. x0 = xi;
  35631. y0 = yi;
  35632. }
  35633. var d = minDist;
  35634. switch (cmd) {
  35635. case CMD$3.M:
  35636. // moveTo 命令重新创建一个新的 subpath, 并且更新新的起点
  35637. // 在 closePath 的时候使用
  35638. x0 = data[i++];
  35639. y0 = data[i++];
  35640. xi = x0;
  35641. yi = y0;
  35642. break;
  35643. case CMD$3.L:
  35644. d = projectPointToLine(xi, yi, data[i], data[i + 1], x, y, tmpPt, true);
  35645. xi = data[i++];
  35646. yi = data[i++];
  35647. break;
  35648. case CMD$3.C:
  35649. d = cubicProjectPoint(xi, yi, data[i++], data[i++], data[i++], data[i++], data[i], data[i + 1], x, y, tmpPt);
  35650. xi = data[i++];
  35651. yi = data[i++];
  35652. break;
  35653. case CMD$3.Q:
  35654. d = quadraticProjectPoint(xi, yi, data[i++], data[i++], data[i], data[i + 1], x, y, tmpPt);
  35655. xi = data[i++];
  35656. yi = data[i++];
  35657. break;
  35658. case CMD$3.A:
  35659. // TODO Arc 判断的开销比较大
  35660. var cx = data[i++];
  35661. var cy = data[i++];
  35662. var rx = data[i++];
  35663. var ry = data[i++];
  35664. var theta = data[i++];
  35665. var dTheta = data[i++];
  35666. // TODO Arc 旋转
  35667. i += 1;
  35668. var anticlockwise = !!(1 - data[i++]);
  35669. x1 = Math.cos(theta) * rx + cx;
  35670. y1 = Math.sin(theta) * ry + cy;
  35671. // 不是直接使用 arc 命令
  35672. if (i <= 1) {
  35673. // 第一个命令起点还未定义
  35674. x0 = x1;
  35675. y0 = y1;
  35676. }
  35677. // zr 使用scale来模拟椭圆, 这里也对x做一定的缩放
  35678. var _x = (x - cx) * ry / rx + cx;
  35679. d = projectPointToArc(cx, cy, ry, theta, theta + dTheta, anticlockwise, _x, y, tmpPt);
  35680. xi = Math.cos(theta + dTheta) * rx + cx;
  35681. yi = Math.sin(theta + dTheta) * ry + cy;
  35682. break;
  35683. case CMD$3.R:
  35684. x0 = xi = data[i++];
  35685. y0 = yi = data[i++];
  35686. var width = data[i++];
  35687. var height = data[i++];
  35688. d = projectPointToRect(x0, y0, width, height, x, y, tmpPt);
  35689. break;
  35690. case CMD$3.Z:
  35691. d = projectPointToLine(xi, yi, x0, y0, x, y, tmpPt, true);
  35692. xi = x0;
  35693. yi = y0;
  35694. break;
  35695. }
  35696. if (d < minDist) {
  35697. minDist = d;
  35698. out.set(tmpPt[0], tmpPt[1]);
  35699. }
  35700. }
  35701. return minDist;
  35702. }
  35703. // Temporal variable for intermediate usage.
  35704. var pt0 = new Point();
  35705. var pt1 = new Point();
  35706. var pt2 = new Point();
  35707. var dir = new Point();
  35708. var dir2 = new Point();
  35709. /**
  35710. * Calculate a proper guide line based on the label position and graphic element definition
  35711. * @param label
  35712. * @param labelRect
  35713. * @param target
  35714. * @param targetRect
  35715. */
  35716. function updateLabelLinePoints(target, labelLineModel) {
  35717. if (!target) {
  35718. return;
  35719. }
  35720. var labelLine = target.getTextGuideLine();
  35721. var label = target.getTextContent();
  35722. // Needs to create text guide in each charts.
  35723. if (!(label && labelLine)) {
  35724. return;
  35725. }
  35726. var labelGuideConfig = target.textGuideLineConfig || {};
  35727. var points = [[0, 0], [0, 0], [0, 0]];
  35728. var searchSpace = labelGuideConfig.candidates || DEFAULT_SEARCH_SPACE;
  35729. var labelRect = label.getBoundingRect().clone();
  35730. labelRect.applyTransform(label.getComputedTransform());
  35731. var minDist = Infinity;
  35732. var anchorPoint = labelGuideConfig.anchor;
  35733. var targetTransform = target.getComputedTransform();
  35734. var targetInversedTransform = targetTransform && invert([], targetTransform);
  35735. var len = labelLineModel.get('length2') || 0;
  35736. if (anchorPoint) {
  35737. pt2.copy(anchorPoint);
  35738. }
  35739. for (var i = 0; i < searchSpace.length; i++) {
  35740. var candidate = searchSpace[i];
  35741. getCandidateAnchor(candidate, 0, labelRect, pt0, dir);
  35742. Point.scaleAndAdd(pt1, pt0, dir, len);
  35743. // Transform to target coord space.
  35744. pt1.transform(targetInversedTransform);
  35745. // Note: getBoundingRect will ensure the `path` being created.
  35746. var boundingRect = target.getBoundingRect();
  35747. var dist = anchorPoint ? anchorPoint.distance(pt1) : target instanceof Path ? nearestPointOnPath(pt1, target.path, pt2) : nearestPointOnRect(pt1, boundingRect, pt2);
  35748. // TODO pt2 is in the path
  35749. if (dist < minDist) {
  35750. minDist = dist;
  35751. // Transform back to global space.
  35752. pt1.transform(targetTransform);
  35753. pt2.transform(targetTransform);
  35754. pt2.toArray(points[0]);
  35755. pt1.toArray(points[1]);
  35756. pt0.toArray(points[2]);
  35757. }
  35758. }
  35759. limitTurnAngle(points, labelLineModel.get('minTurnAngle'));
  35760. labelLine.setShape({
  35761. points: points
  35762. });
  35763. }
  35764. // Temporal variable for the limitTurnAngle function
  35765. var tmpArr = [];
  35766. var tmpProjPoint = new Point();
  35767. /**
  35768. * Reduce the line segment attached to the label to limit the turn angle between two segments.
  35769. * @param linePoints
  35770. * @param minTurnAngle Radian of minimum turn angle. 0 - 180
  35771. */
  35772. function limitTurnAngle(linePoints, minTurnAngle) {
  35773. if (!(minTurnAngle <= 180 && minTurnAngle > 0)) {
  35774. return;
  35775. }
  35776. minTurnAngle = minTurnAngle / 180 * Math.PI;
  35777. // The line points can be
  35778. // /pt1----pt2 (label)
  35779. // /
  35780. // pt0/
  35781. pt0.fromArray(linePoints[0]);
  35782. pt1.fromArray(linePoints[1]);
  35783. pt2.fromArray(linePoints[2]);
  35784. Point.sub(dir, pt0, pt1);
  35785. Point.sub(dir2, pt2, pt1);
  35786. var len1 = dir.len();
  35787. var len2 = dir2.len();
  35788. if (len1 < 1e-3 || len2 < 1e-3) {
  35789. return;
  35790. }
  35791. dir.scale(1 / len1);
  35792. dir2.scale(1 / len2);
  35793. var angleCos = dir.dot(dir2);
  35794. var minTurnAngleCos = Math.cos(minTurnAngle);
  35795. if (minTurnAngleCos < angleCos) {
  35796. // Smaller than minTurnAngle
  35797. // Calculate project point of pt0 on pt1-pt2
  35798. var d = projectPointToLine(pt1.x, pt1.y, pt2.x, pt2.y, pt0.x, pt0.y, tmpArr, false);
  35799. tmpProjPoint.fromArray(tmpArr);
  35800. // Calculate new projected length with limited minTurnAngle and get the new connect point
  35801. tmpProjPoint.scaleAndAdd(dir2, d / Math.tan(Math.PI - minTurnAngle));
  35802. // Limit the new calculated connect point between pt1 and pt2.
  35803. var t = pt2.x !== pt1.x ? (tmpProjPoint.x - pt1.x) / (pt2.x - pt1.x) : (tmpProjPoint.y - pt1.y) / (pt2.y - pt1.y);
  35804. if (isNaN(t)) {
  35805. return;
  35806. }
  35807. if (t < 0) {
  35808. Point.copy(tmpProjPoint, pt1);
  35809. } else if (t > 1) {
  35810. Point.copy(tmpProjPoint, pt2);
  35811. }
  35812. tmpProjPoint.toArray(linePoints[1]);
  35813. }
  35814. }
  35815. /**
  35816. * Limit the angle of line and the surface
  35817. * @param maxSurfaceAngle Radian of minimum turn angle. 0 - 180. 0 is same direction to normal. 180 is opposite
  35818. */
  35819. function limitSurfaceAngle(linePoints, surfaceNormal, maxSurfaceAngle) {
  35820. if (!(maxSurfaceAngle <= 180 && maxSurfaceAngle > 0)) {
  35821. return;
  35822. }
  35823. maxSurfaceAngle = maxSurfaceAngle / 180 * Math.PI;
  35824. pt0.fromArray(linePoints[0]);
  35825. pt1.fromArray(linePoints[1]);
  35826. pt2.fromArray(linePoints[2]);
  35827. Point.sub(dir, pt1, pt0);
  35828. Point.sub(dir2, pt2, pt1);
  35829. var len1 = dir.len();
  35830. var len2 = dir2.len();
  35831. if (len1 < 1e-3 || len2 < 1e-3) {
  35832. return;
  35833. }
  35834. dir.scale(1 / len1);
  35835. dir2.scale(1 / len2);
  35836. var angleCos = dir.dot(surfaceNormal);
  35837. var maxSurfaceAngleCos = Math.cos(maxSurfaceAngle);
  35838. if (angleCos < maxSurfaceAngleCos) {
  35839. // Calculate project point of pt0 on pt1-pt2
  35840. var d = projectPointToLine(pt1.x, pt1.y, pt2.x, pt2.y, pt0.x, pt0.y, tmpArr, false);
  35841. tmpProjPoint.fromArray(tmpArr);
  35842. var HALF_PI = Math.PI / 2;
  35843. var angle2 = Math.acos(dir2.dot(surfaceNormal));
  35844. var newAngle = HALF_PI + angle2 - maxSurfaceAngle;
  35845. if (newAngle >= HALF_PI) {
  35846. // parallel
  35847. Point.copy(tmpProjPoint, pt2);
  35848. } else {
  35849. // Calculate new projected length with limited minTurnAngle and get the new connect point
  35850. tmpProjPoint.scaleAndAdd(dir2, d / Math.tan(Math.PI / 2 - newAngle));
  35851. // Limit the new calculated connect point between pt1 and pt2.
  35852. var t = pt2.x !== pt1.x ? (tmpProjPoint.x - pt1.x) / (pt2.x - pt1.x) : (tmpProjPoint.y - pt1.y) / (pt2.y - pt1.y);
  35853. if (isNaN(t)) {
  35854. return;
  35855. }
  35856. if (t < 0) {
  35857. Point.copy(tmpProjPoint, pt1);
  35858. } else if (t > 1) {
  35859. Point.copy(tmpProjPoint, pt2);
  35860. }
  35861. }
  35862. tmpProjPoint.toArray(linePoints[1]);
  35863. }
  35864. }
  35865. function setLabelLineState(labelLine, ignore, stateName, stateModel) {
  35866. var isNormal = stateName === 'normal';
  35867. var stateObj = isNormal ? labelLine : labelLine.ensureState(stateName);
  35868. // Make sure display.
  35869. stateObj.ignore = ignore;
  35870. // Set smooth
  35871. var smooth = stateModel.get('smooth');
  35872. if (smooth && smooth === true) {
  35873. smooth = 0.3;
  35874. }
  35875. stateObj.shape = stateObj.shape || {};
  35876. if (smooth > 0) {
  35877. stateObj.shape.smooth = smooth;
  35878. }
  35879. var styleObj = stateModel.getModel('lineStyle').getLineStyle();
  35880. isNormal ? labelLine.useStyle(styleObj) : stateObj.style = styleObj;
  35881. }
  35882. function buildLabelLinePath(path, shape) {
  35883. var smooth = shape.smooth;
  35884. var points = shape.points;
  35885. if (!points) {
  35886. return;
  35887. }
  35888. path.moveTo(points[0][0], points[0][1]);
  35889. if (smooth > 0 && points.length >= 3) {
  35890. var len1 = dist(points[0], points[1]);
  35891. var len2 = dist(points[1], points[2]);
  35892. if (!len1 || !len2) {
  35893. path.lineTo(points[1][0], points[1][1]);
  35894. path.lineTo(points[2][0], points[2][1]);
  35895. return;
  35896. }
  35897. var moveLen = Math.min(len1, len2) * smooth;
  35898. var midPoint0 = lerp([], points[1], points[0], moveLen / len1);
  35899. var midPoint2 = lerp([], points[1], points[2], moveLen / len2);
  35900. var midPoint1 = lerp([], midPoint0, midPoint2, 0.5);
  35901. path.bezierCurveTo(midPoint0[0], midPoint0[1], midPoint0[0], midPoint0[1], midPoint1[0], midPoint1[1]);
  35902. path.bezierCurveTo(midPoint2[0], midPoint2[1], midPoint2[0], midPoint2[1], points[2][0], points[2][1]);
  35903. } else {
  35904. for (var i = 1; i < points.length; i++) {
  35905. path.lineTo(points[i][0], points[i][1]);
  35906. }
  35907. }
  35908. }
  35909. /**
  35910. * Create a label line if necessary and set it's style.
  35911. */
  35912. function setLabelLineStyle(targetEl, statesModels, defaultStyle) {
  35913. var labelLine = targetEl.getTextGuideLine();
  35914. var label = targetEl.getTextContent();
  35915. if (!label) {
  35916. // Not show label line if there is no label.
  35917. if (labelLine) {
  35918. targetEl.removeTextGuideLine();
  35919. }
  35920. return;
  35921. }
  35922. var normalModel = statesModels.normal;
  35923. var showNormal = normalModel.get('show');
  35924. var labelIgnoreNormal = label.ignore;
  35925. for (var i = 0; i < DISPLAY_STATES.length; i++) {
  35926. var stateName = DISPLAY_STATES[i];
  35927. var stateModel = statesModels[stateName];
  35928. var isNormal = stateName === 'normal';
  35929. if (stateModel) {
  35930. var stateShow = stateModel.get('show');
  35931. var isLabelIgnored = isNormal ? labelIgnoreNormal : retrieve2(label.states[stateName] && label.states[stateName].ignore, labelIgnoreNormal);
  35932. if (isLabelIgnored // Not show when label is not shown in this state.
  35933. || !retrieve2(stateShow, showNormal) // Use normal state by default if not set.
  35934. ) {
  35935. var stateObj = isNormal ? labelLine : labelLine && labelLine.states[stateName];
  35936. if (stateObj) {
  35937. stateObj.ignore = true;
  35938. }
  35939. if (!!labelLine) {
  35940. setLabelLineState(labelLine, true, stateName, stateModel);
  35941. }
  35942. continue;
  35943. }
  35944. // Create labelLine if not exists
  35945. if (!labelLine) {
  35946. labelLine = new Polyline();
  35947. targetEl.setTextGuideLine(labelLine);
  35948. // Reset state of normal because it's new created.
  35949. // NOTE: NORMAL should always been the first!
  35950. if (!isNormal && (labelIgnoreNormal || !showNormal)) {
  35951. setLabelLineState(labelLine, true, 'normal', statesModels.normal);
  35952. }
  35953. // Use same state proxy.
  35954. if (targetEl.stateProxy) {
  35955. labelLine.stateProxy = targetEl.stateProxy;
  35956. }
  35957. }
  35958. setLabelLineState(labelLine, false, stateName, stateModel);
  35959. }
  35960. }
  35961. if (labelLine) {
  35962. defaults(labelLine.style, defaultStyle);
  35963. // Not fill.
  35964. labelLine.style.fill = null;
  35965. var showAbove = normalModel.get('showAbove');
  35966. var labelLineConfig = targetEl.textGuideLineConfig = targetEl.textGuideLineConfig || {};
  35967. labelLineConfig.showAbove = showAbove || false;
  35968. // Custom the buildPath.
  35969. labelLine.buildPath = buildLabelLinePath;
  35970. }
  35971. }
  35972. function getLabelLineStatesModels(itemModel, labelLineName) {
  35973. labelLineName = labelLineName || 'labelLine';
  35974. var statesModels = {
  35975. normal: itemModel.getModel(labelLineName)
  35976. };
  35977. for (var i = 0; i < SPECIAL_STATES.length; i++) {
  35978. var stateName = SPECIAL_STATES[i];
  35979. statesModels[stateName] = itemModel.getModel([stateName, labelLineName]);
  35980. }
  35981. return statesModels;
  35982. }
  35983. var LABEL_LAYOUT_BASE_PROPS = ['label', 'labelLine', 'layoutOption', 'priority', 'defaultAttr', 'marginForce', 'minMarginForce', 'marginDefault', 'suggestIgnore'];
  35984. var LABEL_LAYOUT_DIRTY_BIT_OTHERS = 1;
  35985. var LABEL_LAYOUT_DIRTY_BIT_OBB = 2;
  35986. var LABEL_LAYOUT_DIRTY_ALL = LABEL_LAYOUT_DIRTY_BIT_OTHERS | LABEL_LAYOUT_DIRTY_BIT_OBB;
  35987. function setLabelLayoutDirty(labelGeometry, dirtyOrClear, dirtyBits) {
  35988. dirtyBits = dirtyBits || LABEL_LAYOUT_DIRTY_ALL;
  35989. dirtyOrClear ? labelGeometry.dirty |= dirtyBits : labelGeometry.dirty &= ~dirtyBits;
  35990. }
  35991. function isLabelLayoutDirty(labelGeometry, dirtyBits) {
  35992. dirtyBits = dirtyBits || LABEL_LAYOUT_DIRTY_ALL;
  35993. return labelGeometry.dirty == null || !!(labelGeometry.dirty & dirtyBits);
  35994. }
  35995. /**
  35996. * [CAUTION]
  35997. * - No auto dirty propagation mechanism yet. If the transform of the raw label or any of its ancestors is
  35998. * changed, must sync the changes to the props of `LabelGeometry` by:
  35999. * either explicitly call:
  36000. * `setLabelLayoutDirty(labelLayout, true); ensureLabelLayoutWithGeometry(labelLayout);`
  36001. * or call (if only translation is performed):
  36002. * `labelLayoutApplyTranslation(labelLayout);`
  36003. * - `label.ignore` is not necessarily falsy, and not considered in computing `LabelGeometry`,
  36004. * since it might be modified by some overlap resolving handling.
  36005. * - To duplicate or make a variation:
  36006. * use `newLabelLayoutWithGeometry`.
  36007. *
  36008. * The result can also be the input of this method.
  36009. * @return `NullUndefined` if and only if `labelLayout` is `NullUndefined`.
  36010. */
  36011. function ensureLabelLayoutWithGeometry(labelLayout) {
  36012. if (!labelLayout) {
  36013. return;
  36014. }
  36015. if (isLabelLayoutDirty(labelLayout)) {
  36016. computeLabelGeometry(labelLayout, labelLayout.label, labelLayout);
  36017. }
  36018. return labelLayout;
  36019. }
  36020. /**
  36021. * The props in `out` will be filled if existing, or created.
  36022. */
  36023. function computeLabelGeometry(out, label, opt) {
  36024. // [CAUTION] These props may be modified directly for performance consideration,
  36025. // therefore, do not output the internal data structure of zrender Element.
  36026. var rawTransform = label.getComputedTransform();
  36027. out.transform = ensureCopyTransform(out.transform, rawTransform);
  36028. // NOTE: should call `getBoundingRect` after `getComputedTransform`, or may get an inaccurate bounding rect.
  36029. // The reason is that `getComputedTransform` calls `__host.updateInnerText()` internally, which updates the label
  36030. // by `textConfig` mounted on the host.
  36031. // PENDING: add a dirty bit for that in zrender?
  36032. var outLocalRect = out.localRect = ensureCopyRect(out.localRect, label.getBoundingRect());
  36033. var labelStyleExt = label.style;
  36034. var margin = labelStyleExt.margin;
  36035. var marginForce = opt && opt.marginForce;
  36036. var minMarginForce = opt && opt.minMarginForce;
  36037. var marginDefault = opt && opt.marginDefault;
  36038. var marginType = labelStyleExt.__marginType;
  36039. if (marginType == null && marginDefault) {
  36040. margin = marginDefault;
  36041. marginType = LabelMarginType.textMargin;
  36042. }
  36043. // `textMargin` and `minMargin` can not exist both.
  36044. for (var i = 0; i < 4; i++) {
  36045. _tmpLabelMargin[i] = marginType === LabelMarginType.minMargin && minMarginForce && minMarginForce[i] != null ? minMarginForce[i] : marginForce && marginForce[i] != null ? marginForce[i] : margin ? margin[i] : 0;
  36046. }
  36047. if (marginType === LabelMarginType.textMargin) {
  36048. expandOrShrinkRect(outLocalRect, _tmpLabelMargin, false, false);
  36049. }
  36050. var outGlobalRect = out.rect = ensureCopyRect(out.rect, outLocalRect);
  36051. if (rawTransform) {
  36052. outGlobalRect.applyTransform(rawTransform);
  36053. }
  36054. // Notice: label.style.margin is actually `minMargin / 2`, handled by `setTextStyleCommon`.
  36055. if (marginType === LabelMarginType.minMargin) {
  36056. expandOrShrinkRect(outGlobalRect, _tmpLabelMargin, false, false);
  36057. }
  36058. out.axisAligned = isBoundingRectAxisAligned(rawTransform);
  36059. (out.label = out.label || {}).ignore = label.ignore;
  36060. setLabelLayoutDirty(out, false);
  36061. setLabelLayoutDirty(out, true, LABEL_LAYOUT_DIRTY_BIT_OBB);
  36062. // Do not remove `obb` (if existing) for reuse, just reset the dirty bit.
  36063. return out;
  36064. }
  36065. var _tmpLabelMargin = [0, 0, 0, 0];
  36066. /**
  36067. * The props in `out` will be filled if existing, or created.
  36068. */
  36069. function computeLabelGeometry2(out, rawLocalRect, rawTransform) {
  36070. out.transform = ensureCopyTransform(out.transform, rawTransform);
  36071. out.localRect = ensureCopyRect(out.localRect, rawLocalRect);
  36072. out.rect = ensureCopyRect(out.rect, rawLocalRect);
  36073. if (rawTransform) {
  36074. out.rect.applyTransform(rawTransform);
  36075. }
  36076. out.axisAligned = isBoundingRectAxisAligned(rawTransform);
  36077. out.obb = undefined; // Reset to undefined, will be created by `ensureOBB` when using.
  36078. (out.label = out.label || {}).ignore = false;
  36079. return out;
  36080. }
  36081. /**
  36082. * This is a shortcut of
  36083. * ```js
  36084. * labelLayout.label.x = newX;
  36085. * labelLayout.label.y = newY;
  36086. * setLabelLayoutDirty(labelLayout, true);
  36087. * ensureLabelLayoutWithGeometry(labelLayout);
  36088. * ```
  36089. * and provide better performance in this common case.
  36090. */
  36091. function labelLayoutApplyTranslation(labelLayout, offset) {
  36092. if (!labelLayout) {
  36093. return;
  36094. }
  36095. labelLayout.label.x += offset.x;
  36096. labelLayout.label.y += offset.y;
  36097. labelLayout.label.markRedraw();
  36098. var transform = labelLayout.transform;
  36099. if (transform) {
  36100. transform[4] += offset.x;
  36101. transform[5] += offset.y;
  36102. }
  36103. var globalRect = labelLayout.rect;
  36104. if (globalRect) {
  36105. globalRect.x += offset.x;
  36106. globalRect.y += offset.y;
  36107. }
  36108. var obb = labelLayout.obb;
  36109. if (obb) {
  36110. obb.fromBoundingRect(labelLayout.localRect, transform);
  36111. }
  36112. }
  36113. /**
  36114. * To duplicate or make a variation of a label layout.
  36115. * Copy the only relevant properties to avoid the conflict or wrongly reuse of the props of `LabelLayoutWithGeometry`.
  36116. */
  36117. function newLabelLayoutWithGeometry(newBaseWithDefaults, source) {
  36118. for (var i = 0; i < LABEL_LAYOUT_BASE_PROPS.length; i++) {
  36119. var prop = LABEL_LAYOUT_BASE_PROPS[i];
  36120. if (newBaseWithDefaults[prop] == null) {
  36121. newBaseWithDefaults[prop] = source[prop];
  36122. }
  36123. }
  36124. return ensureLabelLayoutWithGeometry(newBaseWithDefaults);
  36125. }
  36126. /**
  36127. * Create obb if no one, can cache it.
  36128. */
  36129. function ensureOBB(labelGeometry) {
  36130. var obb = labelGeometry.obb;
  36131. if (!obb || isLabelLayoutDirty(labelGeometry, LABEL_LAYOUT_DIRTY_BIT_OBB)) {
  36132. labelGeometry.obb = obb = obb || new OrientedBoundingRect();
  36133. obb.fromBoundingRect(labelGeometry.localRect, labelGeometry.transform);
  36134. setLabelLayoutDirty(labelGeometry, false, LABEL_LAYOUT_DIRTY_BIT_OBB);
  36135. }
  36136. return obb;
  36137. }
  36138. /**
  36139. * Adjust labels on x/y direction to avoid overlap.
  36140. *
  36141. * PENDING: the current implementation is based on the global bounding rect rather than the local rect,
  36142. * which may be not preferable in some edge cases when the label has rotation, but works for most cases,
  36143. * since rotation is unnecessary when there is sufficient space, while squeezing is applied regardless
  36144. * of overlapping when there is no enough space.
  36145. *
  36146. * NOTICE:
  36147. * - The input `list` and its content will be modified (sort, label.x/y, rect).
  36148. * - The caller should sync the modifications to the other parts by
  36149. * `setLabelLayoutDirty` and `ensureLabelLayoutWithGeometry` if needed.
  36150. *
  36151. * @return adjusted
  36152. */
  36153. function shiftLayoutOnXY(list, xyDimIdx,
  36154. // 0 for x, 1 for y
  36155. minBound,
  36156. // for x, leftBound; for y, topBound
  36157. maxBound,
  36158. // for x, rightBound; for y, bottomBound
  36159. // If average the shifts on all labels and add them to 0
  36160. // TODO: Not sure if should enable it.
  36161. // Pros: The angle of lines will distribute more equally
  36162. // Cons: In some layout. It may not what user wanted. like in pie. the label of last sector is usually changed unexpectedly.
  36163. balanceShift) {
  36164. var len = list.length;
  36165. var xyDim = XY$1[xyDimIdx];
  36166. var sizeDim = WH$1[xyDimIdx];
  36167. if (len < 2) {
  36168. return false;
  36169. }
  36170. list.sort(function (a, b) {
  36171. return a.rect[xyDim] - b.rect[xyDim];
  36172. });
  36173. var lastPos = 0;
  36174. var delta;
  36175. var adjusted = false;
  36176. // const shifts = [];
  36177. var totalShifts = 0;
  36178. for (var i = 0; i < len; i++) {
  36179. var item = list[i];
  36180. var rect = item.rect;
  36181. delta = rect[xyDim] - lastPos;
  36182. if (delta < 0) {
  36183. // shiftForward(i, len, -delta);
  36184. rect[xyDim] -= delta;
  36185. item.label[xyDim] -= delta;
  36186. adjusted = true;
  36187. }
  36188. var shift = Math.max(-delta, 0);
  36189. // shifts.push(shift);
  36190. totalShifts += shift;
  36191. lastPos = rect[xyDim] + rect[sizeDim];
  36192. }
  36193. if (totalShifts > 0 && balanceShift) {
  36194. // Shift back to make the distribution more equally.
  36195. shiftList(-totalShifts / len, 0, len);
  36196. }
  36197. // TODO bleedMargin?
  36198. var first = list[0];
  36199. var last = list[len - 1];
  36200. var minGap;
  36201. var maxGap;
  36202. updateMinMaxGap();
  36203. // If ends exceed two bounds, squeeze at most 80%, then take the gap of two bounds.
  36204. minGap < 0 && squeezeGaps(-minGap, 0.8);
  36205. maxGap < 0 && squeezeGaps(maxGap, 0.8);
  36206. updateMinMaxGap();
  36207. takeBoundsGap(minGap, maxGap, 1);
  36208. takeBoundsGap(maxGap, minGap, -1);
  36209. // Handle bailout when there is not enough space.
  36210. updateMinMaxGap();
  36211. if (minGap < 0) {
  36212. squeezeWhenBailout(-minGap);
  36213. }
  36214. if (maxGap < 0) {
  36215. squeezeWhenBailout(maxGap);
  36216. }
  36217. function updateMinMaxGap() {
  36218. minGap = first.rect[xyDim] - minBound;
  36219. maxGap = maxBound - last.rect[xyDim] - last.rect[sizeDim];
  36220. }
  36221. function takeBoundsGap(gapThisBound, gapOtherBound, moveDir) {
  36222. if (gapThisBound < 0) {
  36223. // Move from other gap if can.
  36224. var moveFromMaxGap = Math.min(gapOtherBound, -gapThisBound);
  36225. if (moveFromMaxGap > 0) {
  36226. shiftList(moveFromMaxGap * moveDir, 0, len);
  36227. var remained = moveFromMaxGap + gapThisBound;
  36228. if (remained < 0) {
  36229. squeezeGaps(-remained * moveDir, 1);
  36230. }
  36231. } else {
  36232. squeezeGaps(-gapThisBound * moveDir, 1);
  36233. }
  36234. }
  36235. }
  36236. function shiftList(delta, start, end) {
  36237. if (delta !== 0) {
  36238. adjusted = true;
  36239. }
  36240. for (var i = start; i < end; i++) {
  36241. var item = list[i];
  36242. var rect = item.rect;
  36243. rect[xyDim] += delta;
  36244. item.label[xyDim] += delta;
  36245. }
  36246. }
  36247. // Squeeze gaps if the labels exceed margin.
  36248. function squeezeGaps(delta, maxSqeezePercent) {
  36249. var gaps = [];
  36250. var totalGaps = 0;
  36251. for (var i = 1; i < len; i++) {
  36252. var prevItemRect = list[i - 1].rect;
  36253. var gap = Math.max(list[i].rect[xyDim] - prevItemRect[xyDim] - prevItemRect[sizeDim], 0);
  36254. gaps.push(gap);
  36255. totalGaps += gap;
  36256. }
  36257. if (!totalGaps) {
  36258. return;
  36259. }
  36260. var squeezePercent = Math.min(Math.abs(delta) / totalGaps, maxSqeezePercent);
  36261. if (delta > 0) {
  36262. for (var i = 0; i < len - 1; i++) {
  36263. // Distribute the shift delta to all gaps.
  36264. var movement = gaps[i] * squeezePercent;
  36265. // Forward
  36266. shiftList(movement, 0, i + 1);
  36267. }
  36268. } else {
  36269. // Backward
  36270. for (var i = len - 1; i > 0; i--) {
  36271. // Distribute the shift delta to all gaps.
  36272. var movement = gaps[i - 1] * squeezePercent;
  36273. shiftList(-movement, i, len);
  36274. }
  36275. }
  36276. }
  36277. /**
  36278. * Squeeze to allow overlap if there is no more space available.
  36279. * Let other overlapping strategy like hideOverlap do the job instead of keep exceeding the bounds.
  36280. */
  36281. function squeezeWhenBailout(delta) {
  36282. var dir = delta < 0 ? -1 : 1;
  36283. delta = Math.abs(delta);
  36284. var moveForEachLabel = Math.ceil(delta / (len - 1));
  36285. for (var i = 0; i < len - 1; i++) {
  36286. if (dir > 0) {
  36287. // Forward
  36288. shiftList(moveForEachLabel, 0, i + 1);
  36289. } else {
  36290. // Backward
  36291. shiftList(-moveForEachLabel, len - i - 1, len);
  36292. }
  36293. delta -= moveForEachLabel;
  36294. if (delta <= 0) {
  36295. return;
  36296. }
  36297. }
  36298. }
  36299. return adjusted;
  36300. }
  36301. /**
  36302. * @see `SavedLabelAttr` in `LabelManager.ts`
  36303. * @see `hideOverlap`
  36304. */
  36305. function restoreIgnore(labelList) {
  36306. for (var i = 0; i < labelList.length; i++) {
  36307. var labelItem = labelList[i];
  36308. var defaultAttr = labelItem.defaultAttr;
  36309. var labelLine = labelItem.labelLine;
  36310. labelItem.label.attr('ignore', defaultAttr.ignore);
  36311. labelLine && labelLine.attr('ignore', defaultAttr.labelGuideIgnore);
  36312. }
  36313. }
  36314. /**
  36315. * [NOTICE - restore]:
  36316. * 'series:layoutlabels' may be triggered during some shortcut passes, such as zooming in series.graph/geo
  36317. * (`updateLabelLayout`), where the modified `Element` props should be restorable from `defaultAttr`.
  36318. * @see `SavedLabelAttr` in `LabelManager.ts`
  36319. * `restoreIgnore` can be called to perform the restore, if needed.
  36320. *
  36321. * [NOTICE - state]:
  36322. * Regarding Element's states, this method is only designed for the normal state.
  36323. * PENDING: although currently this method is effectively called in other states in `updateLabelLayout` case,
  36324. * the bad case is not noticeable in the zooming scenario.
  36325. */
  36326. function hideOverlap(labelList) {
  36327. var displayedLabels = [];
  36328. // TODO, render overflow visible first, put in the displayedLabels.
  36329. labelList.sort(function (a, b) {
  36330. return (b.suggestIgnore ? 1 : 0) - (a.suggestIgnore ? 1 : 0) || b.priority - a.priority;
  36331. });
  36332. function hideEl(el) {
  36333. if (!el.ignore) {
  36334. // Show on emphasis.
  36335. var emphasisState = el.ensureState('emphasis');
  36336. if (emphasisState.ignore == null) {
  36337. emphasisState.ignore = false;
  36338. }
  36339. }
  36340. el.ignore = true;
  36341. }
  36342. for (var i = 0; i < labelList.length; i++) {
  36343. var labelItem = ensureLabelLayoutWithGeometry(labelList[i]);
  36344. // The current `el.ignore` is involved, since some previous overlap
  36345. // resolving strategies may have set `el.ignore` to true.
  36346. if (labelItem.label.ignore) {
  36347. continue;
  36348. }
  36349. var label = labelItem.label;
  36350. var labelLine = labelItem.labelLine;
  36351. // NOTICE: even when the with/height of globalRect of a label is 0, the label line should
  36352. // still be displayed, since we should follow the concept of "truncation", meaning that
  36353. // something exists even if it cannot be fully displayed. A visible label line is necessary
  36354. // to allow users to get a tooltip with label info on hover.
  36355. var overlapped = false;
  36356. for (var j = 0; j < displayedLabels.length; j++) {
  36357. if (labelIntersect(labelItem, displayedLabels[j], null, {
  36358. touchThreshold: 0.05
  36359. })) {
  36360. overlapped = true;
  36361. break;
  36362. }
  36363. }
  36364. // TODO Callback to determine if this overlap should be handled?
  36365. if (overlapped) {
  36366. hideEl(label);
  36367. labelLine && hideEl(labelLine);
  36368. } else {
  36369. displayedLabels.push(labelItem);
  36370. }
  36371. }
  36372. }
  36373. /**
  36374. * Enable fast check for performance; use obb if inevitable.
  36375. * If `mtv` is used, `targetLayoutInfo` can be moved based on the values filled into `mtv`.
  36376. *
  36377. * This method is based only on the current `Element` states (regardless of other states).
  36378. * Typically this method (and the entire layout process) is performed in normal state.
  36379. */
  36380. function labelIntersect(baseLayoutInfo, targetLayoutInfo, mtv, intersectOpt) {
  36381. if (!baseLayoutInfo || !targetLayoutInfo) {
  36382. return false;
  36383. }
  36384. if (baseLayoutInfo.label && baseLayoutInfo.label.ignore || targetLayoutInfo.label && targetLayoutInfo.label.ignore) {
  36385. return false;
  36386. }
  36387. // Fast rejection.
  36388. if (!baseLayoutInfo.rect.intersect(targetLayoutInfo.rect, mtv, intersectOpt)) {
  36389. return false;
  36390. }
  36391. if (baseLayoutInfo.axisAligned && targetLayoutInfo.axisAligned) {
  36392. return true; // obb is the same as the normal bounding rect.
  36393. }
  36394. return ensureOBB(baseLayoutInfo).intersect(ensureOBB(targetLayoutInfo), mtv, intersectOpt);
  36395. }
  36396. function cloneArr(points) {
  36397. if (points) {
  36398. var newPoints = [];
  36399. for (var i = 0; i < points.length; i++) {
  36400. newPoints.push(points[i].slice());
  36401. }
  36402. return newPoints;
  36403. }
  36404. }
  36405. function prepareLayoutCallbackParams(labelItem, hostEl) {
  36406. var label = labelItem.label;
  36407. var labelLine = hostEl && hostEl.getTextGuideLine();
  36408. return {
  36409. dataIndex: labelItem.dataIndex,
  36410. dataType: labelItem.dataType,
  36411. seriesIndex: labelItem.seriesModel.seriesIndex,
  36412. text: labelItem.label.style.text,
  36413. rect: labelItem.hostRect,
  36414. labelRect: labelItem.rect,
  36415. // x: labelAttr.x,
  36416. // y: labelAttr.y,
  36417. align: label.style.align,
  36418. verticalAlign: label.style.verticalAlign,
  36419. labelLinePoints: cloneArr(labelLine && labelLine.shape.points)
  36420. };
  36421. }
  36422. var LABEL_OPTION_TO_STYLE_KEYS = ['align', 'verticalAlign', 'width', 'height', 'fontSize'];
  36423. var dummyTransformable = new Transformable();
  36424. var labelLayoutInnerStore = makeInner();
  36425. var labelLineAnimationStore = makeInner();
  36426. function extendWithKeys(target, source, keys) {
  36427. for (var i = 0; i < keys.length; i++) {
  36428. var key = keys[i];
  36429. if (source[key] != null) {
  36430. target[key] = source[key];
  36431. }
  36432. }
  36433. }
  36434. var LABEL_LAYOUT_PROPS = ['x', 'y', 'rotation'];
  36435. var LabelManager = /** @class */function () {
  36436. function LabelManager() {
  36437. this._labelList = [];
  36438. this._chartViewList = [];
  36439. }
  36440. LabelManager.prototype.clearLabels = function () {
  36441. this._labelList = [];
  36442. this._chartViewList = [];
  36443. };
  36444. /**
  36445. * Add label to manager
  36446. */
  36447. LabelManager.prototype._addLabel = function (dataIndex, dataType, seriesModel, label, layoutOptionOrCb) {
  36448. var labelStyle = label.style;
  36449. var hostEl = label.__hostTarget;
  36450. var textConfig = hostEl.textConfig || {};
  36451. // TODO: If label is in other state.
  36452. var labelTransform = label.getComputedTransform();
  36453. var labelRect = label.getBoundingRect().plain();
  36454. BoundingRect.applyTransform(labelRect, labelRect, labelTransform);
  36455. if (labelTransform) {
  36456. dummyTransformable.setLocalTransform(labelTransform);
  36457. } else {
  36458. // Identity transform.
  36459. dummyTransformable.x = dummyTransformable.y = dummyTransformable.rotation = dummyTransformable.originX = dummyTransformable.originY = 0;
  36460. dummyTransformable.scaleX = dummyTransformable.scaleY = 1;
  36461. }
  36462. dummyTransformable.rotation = normalizeRadian(dummyTransformable.rotation);
  36463. var host = label.__hostTarget;
  36464. var hostRect;
  36465. if (host) {
  36466. hostRect = host.getBoundingRect().plain();
  36467. var transform = host.getComputedTransform();
  36468. BoundingRect.applyTransform(hostRect, hostRect, transform);
  36469. }
  36470. var labelGuide = hostRect && host.getTextGuideLine();
  36471. this._labelList.push({
  36472. label: label,
  36473. labelLine: labelGuide,
  36474. seriesModel: seriesModel,
  36475. dataIndex: dataIndex,
  36476. dataType: dataType,
  36477. layoutOptionOrCb: layoutOptionOrCb,
  36478. layoutOption: null,
  36479. rect: labelRect,
  36480. hostRect: hostRect,
  36481. // Label with lower priority will be hidden when overlapped
  36482. // Use rect size as default priority
  36483. priority: hostRect ? hostRect.width * hostRect.height : 0,
  36484. // Save default label attributes.
  36485. // For restore if developers want get back to default value in callback.
  36486. defaultAttr: {
  36487. ignore: label.ignore,
  36488. labelGuideIgnore: labelGuide && labelGuide.ignore,
  36489. x: dummyTransformable.x,
  36490. y: dummyTransformable.y,
  36491. scaleX: dummyTransformable.scaleX,
  36492. scaleY: dummyTransformable.scaleY,
  36493. rotation: dummyTransformable.rotation,
  36494. style: {
  36495. x: labelStyle.x,
  36496. y: labelStyle.y,
  36497. align: labelStyle.align,
  36498. verticalAlign: labelStyle.verticalAlign,
  36499. width: labelStyle.width,
  36500. height: labelStyle.height,
  36501. fontSize: labelStyle.fontSize
  36502. },
  36503. cursor: label.cursor,
  36504. attachedPos: textConfig.position,
  36505. attachedRot: textConfig.rotation
  36506. }
  36507. });
  36508. };
  36509. LabelManager.prototype.addLabelsOfSeries = function (chartView) {
  36510. var _this = this;
  36511. this._chartViewList.push(chartView);
  36512. var seriesModel = chartView.__model;
  36513. var layoutOption = seriesModel.get('labelLayout');
  36514. /**
  36515. * Ignore layouting if it's not specified anything.
  36516. */
  36517. if (!(isFunction(layoutOption) || keys(layoutOption).length)) {
  36518. return;
  36519. }
  36520. chartView.group.traverse(function (child) {
  36521. if (child.ignore) {
  36522. return true; // Stop traverse descendants.
  36523. }
  36524. // Only support label being hosted on graphic elements.
  36525. var textEl = child.getTextContent();
  36526. var ecData = getECData(child);
  36527. // Can only attach the text on the element with dataIndex
  36528. if (textEl && !textEl.disableLabelLayout) {
  36529. _this._addLabel(ecData.dataIndex, ecData.dataType, seriesModel, textEl, layoutOption);
  36530. }
  36531. });
  36532. };
  36533. LabelManager.prototype.updateLayoutConfig = function (api) {
  36534. var width = api.getWidth();
  36535. var height = api.getHeight();
  36536. function createDragHandler(el, labelLineModel) {
  36537. return function () {
  36538. updateLabelLinePoints(el, labelLineModel);
  36539. };
  36540. }
  36541. for (var i = 0; i < this._labelList.length; i++) {
  36542. var labelItem = this._labelList[i];
  36543. var label = labelItem.label;
  36544. var hostEl = label.__hostTarget;
  36545. var defaultLabelAttr = labelItem.defaultAttr;
  36546. var layoutOption = void 0;
  36547. // TODO A global layout option?
  36548. if (isFunction(labelItem.layoutOptionOrCb)) {
  36549. layoutOption = labelItem.layoutOptionOrCb(prepareLayoutCallbackParams(labelItem, hostEl));
  36550. } else {
  36551. layoutOption = labelItem.layoutOptionOrCb;
  36552. }
  36553. layoutOption = layoutOption || {};
  36554. labelItem.layoutOption = layoutOption;
  36555. var degreeToRadian = Math.PI / 180;
  36556. // TODO hostEl should always exists.
  36557. // Or label should not have parent because the x, y is all in global space.
  36558. if (hostEl) {
  36559. hostEl.setTextConfig({
  36560. // Force to set local false.
  36561. local: false,
  36562. // Ignore position and rotation config on the host el if x or y is changed.
  36563. position: layoutOption.x != null || layoutOption.y != null ? null : defaultLabelAttr.attachedPos,
  36564. // Ignore rotation config on the host el if rotation is changed.
  36565. rotation: layoutOption.rotate != null ? layoutOption.rotate * degreeToRadian : defaultLabelAttr.attachedRot,
  36566. offset: [layoutOption.dx || 0, layoutOption.dy || 0]
  36567. });
  36568. }
  36569. var needsUpdateLabelLine = false;
  36570. if (layoutOption.x != null) {
  36571. // TODO width of chart view.
  36572. label.x = parsePercent$1(layoutOption.x, width);
  36573. label.setStyle('x', 0); // Ignore movement in style. TODO: origin.
  36574. needsUpdateLabelLine = true;
  36575. } else {
  36576. label.x = defaultLabelAttr.x;
  36577. label.setStyle('x', defaultLabelAttr.style.x);
  36578. }
  36579. if (layoutOption.y != null) {
  36580. // TODO height of chart view.
  36581. label.y = parsePercent$1(layoutOption.y, height);
  36582. label.setStyle('y', 0); // Ignore movement in style.
  36583. needsUpdateLabelLine = true;
  36584. } else {
  36585. label.y = defaultLabelAttr.y;
  36586. label.setStyle('y', defaultLabelAttr.style.y);
  36587. }
  36588. if (layoutOption.labelLinePoints) {
  36589. var guideLine = hostEl.getTextGuideLine();
  36590. if (guideLine) {
  36591. guideLine.setShape({
  36592. points: layoutOption.labelLinePoints
  36593. });
  36594. // Not update
  36595. needsUpdateLabelLine = false;
  36596. }
  36597. }
  36598. var labelLayoutStore = labelLayoutInnerStore(label);
  36599. labelLayoutStore.needsUpdateLabelLine = needsUpdateLabelLine;
  36600. label.rotation = layoutOption.rotate != null ? layoutOption.rotate * degreeToRadian : defaultLabelAttr.rotation;
  36601. label.scaleX = defaultLabelAttr.scaleX;
  36602. label.scaleY = defaultLabelAttr.scaleY;
  36603. for (var k = 0; k < LABEL_OPTION_TO_STYLE_KEYS.length; k++) {
  36604. var key = LABEL_OPTION_TO_STYLE_KEYS[k];
  36605. label.setStyle(key, layoutOption[key] != null ? layoutOption[key] : defaultLabelAttr.style[key]);
  36606. }
  36607. if (layoutOption.draggable) {
  36608. label.draggable = true;
  36609. label.cursor = 'move';
  36610. if (hostEl) {
  36611. var hostModel = labelItem.seriesModel;
  36612. if (labelItem.dataIndex != null) {
  36613. var data = labelItem.seriesModel.getData(labelItem.dataType);
  36614. hostModel = data.getItemModel(labelItem.dataIndex);
  36615. }
  36616. label.on('drag', createDragHandler(hostEl, hostModel.getModel('labelLine')));
  36617. }
  36618. } else {
  36619. // TODO Other drag functions?
  36620. label.off('drag');
  36621. label.cursor = defaultLabelAttr.cursor;
  36622. }
  36623. }
  36624. };
  36625. LabelManager.prototype.layout = function (api) {
  36626. var width = api.getWidth();
  36627. var height = api.getHeight();
  36628. var labelList = [];
  36629. each(this._labelList, function (inputItem) {
  36630. if (!inputItem.defaultAttr.ignore) {
  36631. labelList.push(newLabelLayoutWithGeometry({}, inputItem));
  36632. }
  36633. });
  36634. var labelsNeedsAdjustOnX = filter(labelList, function (item) {
  36635. return item.layoutOption.moveOverlap === 'shiftX';
  36636. });
  36637. var labelsNeedsAdjustOnY = filter(labelList, function (item) {
  36638. return item.layoutOption.moveOverlap === 'shiftY';
  36639. });
  36640. shiftLayoutOnXY(labelsNeedsAdjustOnX, 0, 0, width);
  36641. shiftLayoutOnXY(labelsNeedsAdjustOnY, 1, 0, height);
  36642. var labelsNeedsHideOverlap = filter(labelList, function (item) {
  36643. return item.layoutOption.hideOverlap;
  36644. });
  36645. restoreIgnore(labelsNeedsHideOverlap);
  36646. hideOverlap(labelsNeedsHideOverlap);
  36647. };
  36648. /**
  36649. * Process all labels. Not only labels with layoutOption.
  36650. */
  36651. LabelManager.prototype.processLabelsOverall = function () {
  36652. var _this = this;
  36653. each(this._chartViewList, function (chartView) {
  36654. var seriesModel = chartView.__model;
  36655. var ignoreLabelLineUpdate = chartView.ignoreLabelLineUpdate;
  36656. var animationEnabled = seriesModel.isAnimationEnabled();
  36657. chartView.group.traverse(function (child) {
  36658. if (child.ignore && !child.forceLabelAnimation) {
  36659. return true; // Stop traverse descendants.
  36660. }
  36661. var needsUpdateLabelLine = !ignoreLabelLineUpdate;
  36662. var label = child.getTextContent();
  36663. if (!needsUpdateLabelLine && label) {
  36664. needsUpdateLabelLine = labelLayoutInnerStore(label).needsUpdateLabelLine;
  36665. }
  36666. if (needsUpdateLabelLine) {
  36667. _this._updateLabelLine(child, seriesModel);
  36668. }
  36669. if (animationEnabled) {
  36670. _this._animateLabels(child, seriesModel);
  36671. }
  36672. });
  36673. });
  36674. };
  36675. LabelManager.prototype._updateLabelLine = function (el, seriesModel) {
  36676. // Only support label being hosted on graphic elements.
  36677. var textEl = el.getTextContent();
  36678. // Update label line style.
  36679. var ecData = getECData(el);
  36680. var dataIndex = ecData.dataIndex;
  36681. // Only support labelLine on the labels represent data.
  36682. if (textEl && dataIndex != null) {
  36683. var data = seriesModel.getData(ecData.dataType);
  36684. var itemModel = data.getItemModel(dataIndex);
  36685. var defaultStyle = {};
  36686. var visualStyle = data.getItemVisual(dataIndex, 'style');
  36687. if (visualStyle) {
  36688. var visualType = data.getVisual('drawType');
  36689. // Default to be same with main color
  36690. defaultStyle.stroke = visualStyle[visualType];
  36691. }
  36692. var labelLineModel = itemModel.getModel('labelLine');
  36693. setLabelLineStyle(el, getLabelLineStatesModels(itemModel), defaultStyle);
  36694. updateLabelLinePoints(el, labelLineModel);
  36695. }
  36696. };
  36697. LabelManager.prototype._animateLabels = function (el, seriesModel) {
  36698. var textEl = el.getTextContent();
  36699. var guideLine = el.getTextGuideLine();
  36700. // Animate
  36701. if (textEl
  36702. // `forceLabelAnimation` has the highest priority
  36703. && (el.forceLabelAnimation || !textEl.ignore && !textEl.invisible && !el.disableLabelAnimation && !isElementRemoved(el))) {
  36704. var layoutStore = labelLayoutInnerStore(textEl);
  36705. var oldLayout = layoutStore.oldLayout;
  36706. var ecData = getECData(el);
  36707. var dataIndex = ecData.dataIndex;
  36708. var newProps = {
  36709. x: textEl.x,
  36710. y: textEl.y,
  36711. rotation: textEl.rotation
  36712. };
  36713. var data = seriesModel.getData(ecData.dataType);
  36714. if (!oldLayout) {
  36715. textEl.attr(newProps);
  36716. // Disable fade in animation if value animation is enabled.
  36717. if (!labelInner(textEl).valueAnimation) {
  36718. var oldOpacity = retrieve2(textEl.style.opacity, 1);
  36719. // Fade in animation
  36720. textEl.style.opacity = 0;
  36721. initProps(textEl, {
  36722. style: {
  36723. opacity: oldOpacity
  36724. }
  36725. }, seriesModel, dataIndex);
  36726. }
  36727. } else {
  36728. textEl.attr(oldLayout);
  36729. // Make sure the animation from is in the right status.
  36730. var prevStates = el.prevStates;
  36731. if (prevStates) {
  36732. if (indexOf(prevStates, 'select') >= 0) {
  36733. textEl.attr(layoutStore.oldLayoutSelect);
  36734. }
  36735. if (indexOf(prevStates, 'emphasis') >= 0) {
  36736. textEl.attr(layoutStore.oldLayoutEmphasis);
  36737. }
  36738. }
  36739. updateProps(textEl, newProps, seriesModel, dataIndex);
  36740. }
  36741. layoutStore.oldLayout = newProps;
  36742. if (textEl.states.select) {
  36743. var layoutSelect = layoutStore.oldLayoutSelect = {};
  36744. extendWithKeys(layoutSelect, newProps, LABEL_LAYOUT_PROPS);
  36745. extendWithKeys(layoutSelect, textEl.states.select, LABEL_LAYOUT_PROPS);
  36746. }
  36747. if (textEl.states.emphasis) {
  36748. var layoutEmphasis = layoutStore.oldLayoutEmphasis = {};
  36749. extendWithKeys(layoutEmphasis, newProps, LABEL_LAYOUT_PROPS);
  36750. extendWithKeys(layoutEmphasis, textEl.states.emphasis, LABEL_LAYOUT_PROPS);
  36751. }
  36752. animateLabelValue(textEl, dataIndex, data, seriesModel, seriesModel);
  36753. }
  36754. if (guideLine && !guideLine.ignore && !guideLine.invisible) {
  36755. var layoutStore = labelLineAnimationStore(guideLine);
  36756. var oldLayout = layoutStore.oldLayout;
  36757. var newLayout = {
  36758. points: guideLine.shape.points
  36759. };
  36760. if (!oldLayout) {
  36761. guideLine.setShape(newLayout);
  36762. guideLine.style.strokePercent = 0;
  36763. initProps(guideLine, {
  36764. style: {
  36765. strokePercent: 1
  36766. }
  36767. }, seriesModel);
  36768. } else {
  36769. guideLine.attr({
  36770. shape: oldLayout
  36771. });
  36772. updateProps(guideLine, {
  36773. shape: newLayout
  36774. }, seriesModel);
  36775. }
  36776. layoutStore.oldLayout = newLayout;
  36777. }
  36778. };
  36779. return LabelManager;
  36780. }();
  36781. var getLabelManager = makeInner();
  36782. function installLabelLayout(registers) {
  36783. registers.registerUpdateLifecycle('series:beforeupdate', function (ecModel, api, params) {
  36784. // TODO api provide an namespace that can save stuff per instance
  36785. var labelManager = getLabelManager(api).labelManager;
  36786. if (!labelManager) {
  36787. labelManager = getLabelManager(api).labelManager = new LabelManager();
  36788. }
  36789. labelManager.clearLabels();
  36790. });
  36791. registers.registerUpdateLifecycle('series:layoutlabels', function (ecModel, api, params) {
  36792. var labelManager = getLabelManager(api).labelManager;
  36793. params.updatedSeries.forEach(function (series) {
  36794. labelManager.addLabelsOfSeries(api.getViewOfSeriesModel(series));
  36795. });
  36796. labelManager.updateLayoutConfig(api);
  36797. labelManager.layout(api);
  36798. labelManager.processLabelsOverall();
  36799. });
  36800. }
  36801. var mathSin$4 = Math.sin;
  36802. var mathCos$4 = Math.cos;
  36803. var PI$4 = Math.PI;
  36804. var PI2$7 = Math.PI * 2;
  36805. var degree = 180 / PI$4;
  36806. var SVGPathRebuilder = (function () {
  36807. function SVGPathRebuilder() {
  36808. }
  36809. SVGPathRebuilder.prototype.reset = function (precision) {
  36810. this._start = true;
  36811. this._d = [];
  36812. this._str = '';
  36813. this._p = Math.pow(10, precision || 4);
  36814. };
  36815. SVGPathRebuilder.prototype.moveTo = function (x, y) {
  36816. this._add('M', x, y);
  36817. };
  36818. SVGPathRebuilder.prototype.lineTo = function (x, y) {
  36819. this._add('L', x, y);
  36820. };
  36821. SVGPathRebuilder.prototype.bezierCurveTo = function (x, y, x2, y2, x3, y3) {
  36822. this._add('C', x, y, x2, y2, x3, y3);
  36823. };
  36824. SVGPathRebuilder.prototype.quadraticCurveTo = function (x, y, x2, y2) {
  36825. this._add('Q', x, y, x2, y2);
  36826. };
  36827. SVGPathRebuilder.prototype.arc = function (cx, cy, r, startAngle, endAngle, anticlockwise) {
  36828. this.ellipse(cx, cy, r, r, 0, startAngle, endAngle, anticlockwise);
  36829. };
  36830. SVGPathRebuilder.prototype.ellipse = function (cx, cy, rx, ry, psi, startAngle, endAngle, anticlockwise) {
  36831. var dTheta = endAngle - startAngle;
  36832. var clockwise = !anticlockwise;
  36833. var dThetaPositive = Math.abs(dTheta);
  36834. var isCircle = isAroundZero$1(dThetaPositive - PI2$7)
  36835. || (clockwise ? dTheta >= PI2$7 : -dTheta >= PI2$7);
  36836. var unifiedTheta = dTheta > 0 ? dTheta % PI2$7 : (dTheta % PI2$7 + PI2$7);
  36837. var large = false;
  36838. if (isCircle) {
  36839. large = true;
  36840. }
  36841. else if (isAroundZero$1(dThetaPositive)) {
  36842. large = false;
  36843. }
  36844. else {
  36845. large = (unifiedTheta >= PI$4) === !!clockwise;
  36846. }
  36847. var x0 = cx + rx * mathCos$4(startAngle);
  36848. var y0 = cy + ry * mathSin$4(startAngle);
  36849. if (this._start) {
  36850. this._add('M', x0, y0);
  36851. }
  36852. var xRot = Math.round(psi * degree);
  36853. if (isCircle) {
  36854. var p = 1 / this._p;
  36855. var dTheta_1 = (clockwise ? 1 : -1) * (PI2$7 - p);
  36856. this._add('A', rx, ry, xRot, 1, +clockwise, cx + rx * mathCos$4(startAngle + dTheta_1), cy + ry * mathSin$4(startAngle + dTheta_1));
  36857. if (p > 1e-2) {
  36858. this._add('A', rx, ry, xRot, 0, +clockwise, x0, y0);
  36859. }
  36860. }
  36861. else {
  36862. var x = cx + rx * mathCos$4(endAngle);
  36863. var y = cy + ry * mathSin$4(endAngle);
  36864. this._add('A', rx, ry, xRot, +large, +clockwise, x, y);
  36865. }
  36866. };
  36867. SVGPathRebuilder.prototype.rect = function (x, y, w, h) {
  36868. this._add('M', x, y);
  36869. this._add('l', w, 0);
  36870. this._add('l', 0, h);
  36871. this._add('l', -w, 0);
  36872. this._add('Z');
  36873. };
  36874. SVGPathRebuilder.prototype.closePath = function () {
  36875. if (this._d.length > 0) {
  36876. this._add('Z');
  36877. }
  36878. };
  36879. SVGPathRebuilder.prototype._add = function (cmd, a, b, c, d, e, f, g, h) {
  36880. var vals = [];
  36881. var p = this._p;
  36882. for (var i = 1; i < arguments.length; i++) {
  36883. var val = arguments[i];
  36884. if (isNaN(val)) {
  36885. this._invalid = true;
  36886. return;
  36887. }
  36888. vals.push(Math.round(val * p) / p);
  36889. }
  36890. this._d.push(cmd + vals.join(' '));
  36891. this._start = cmd === 'Z';
  36892. };
  36893. SVGPathRebuilder.prototype.generateStr = function () {
  36894. this._str = this._invalid ? '' : this._d.join('');
  36895. this._d = [];
  36896. };
  36897. SVGPathRebuilder.prototype.getStr = function () {
  36898. return this._str;
  36899. };
  36900. return SVGPathRebuilder;
  36901. }());
  36902. var NONE = 'none';
  36903. var mathRound$1 = Math.round;
  36904. function pathHasFill(style) {
  36905. var fill = style.fill;
  36906. return fill != null && fill !== NONE;
  36907. }
  36908. function pathHasStroke(style) {
  36909. var stroke = style.stroke;
  36910. return stroke != null && stroke !== NONE;
  36911. }
  36912. var strokeProps = ['lineCap', 'miterLimit', 'lineJoin'];
  36913. var svgStrokeProps = map(strokeProps, function (prop) { return "stroke-" + prop.toLowerCase(); });
  36914. function mapStyleToAttrs(updateAttr, style, el, forceUpdate) {
  36915. var opacity = style.opacity == null ? 1 : style.opacity;
  36916. if (el instanceof ZRImage) {
  36917. updateAttr('opacity', opacity);
  36918. return;
  36919. }
  36920. if (pathHasFill(style)) {
  36921. var fill = normalizeColor(style.fill);
  36922. updateAttr('fill', fill.color);
  36923. var fillOpacity = style.fillOpacity != null
  36924. ? style.fillOpacity * fill.opacity * opacity
  36925. : fill.opacity * opacity;
  36926. if (forceUpdate || fillOpacity < 1) {
  36927. updateAttr('fill-opacity', fillOpacity);
  36928. }
  36929. }
  36930. else {
  36931. updateAttr('fill', NONE);
  36932. }
  36933. if (pathHasStroke(style)) {
  36934. var stroke = normalizeColor(style.stroke);
  36935. updateAttr('stroke', stroke.color);
  36936. var strokeScale = style.strokeNoScale
  36937. ? el.getLineScale()
  36938. : 1;
  36939. var strokeWidth = (strokeScale ? (style.lineWidth || 0) / strokeScale : 0);
  36940. var strokeOpacity = style.strokeOpacity != null
  36941. ? style.strokeOpacity * stroke.opacity * opacity
  36942. : stroke.opacity * opacity;
  36943. var strokeFirst = style.strokeFirst;
  36944. if (forceUpdate || strokeWidth !== 1) {
  36945. updateAttr('stroke-width', strokeWidth);
  36946. }
  36947. if (forceUpdate || strokeFirst) {
  36948. updateAttr('paint-order', strokeFirst ? 'stroke' : 'fill');
  36949. }
  36950. if (forceUpdate || strokeOpacity < 1) {
  36951. updateAttr('stroke-opacity', strokeOpacity);
  36952. }
  36953. if (style.lineDash) {
  36954. var _a = getLineDash(el), lineDash = _a[0], lineDashOffset = _a[1];
  36955. if (lineDash) {
  36956. lineDashOffset = mathRound$1(lineDashOffset || 0);
  36957. updateAttr('stroke-dasharray', lineDash.join(','));
  36958. if (lineDashOffset || forceUpdate) {
  36959. updateAttr('stroke-dashoffset', lineDashOffset);
  36960. }
  36961. }
  36962. }
  36963. else if (forceUpdate) {
  36964. updateAttr('stroke-dasharray', NONE);
  36965. }
  36966. for (var i = 0; i < strokeProps.length; i++) {
  36967. var propName = strokeProps[i];
  36968. if (forceUpdate || style[propName] !== DEFAULT_PATH_STYLE[propName]) {
  36969. var val = style[propName] || DEFAULT_PATH_STYLE[propName];
  36970. val && updateAttr(svgStrokeProps[i], val);
  36971. }
  36972. }
  36973. }
  36974. else if (forceUpdate) {
  36975. updateAttr('stroke', NONE);
  36976. }
  36977. }
  36978. var SVGNS = 'http://www.w3.org/2000/svg';
  36979. var XLINKNS = 'http://www.w3.org/1999/xlink';
  36980. var XMLNS = 'http://www.w3.org/2000/xmlns/';
  36981. var XML_NAMESPACE = 'http://www.w3.org/XML/1998/namespace';
  36982. var META_DATA_PREFIX = 'ecmeta_';
  36983. function createElement(name) {
  36984. return document.createElementNS(SVGNS, name);
  36985. }
  36986. function createVNode(tag, key, attrs, children, text) {
  36987. return {
  36988. tag: tag,
  36989. attrs: attrs || {},
  36990. children: children,
  36991. text: text,
  36992. key: key
  36993. };
  36994. }
  36995. function createElementOpen(name, attrs) {
  36996. var attrsStr = [];
  36997. if (attrs) {
  36998. for (var key in attrs) {
  36999. var val = attrs[key];
  37000. var part = key;
  37001. if (val === false) {
  37002. continue;
  37003. }
  37004. else if (val !== true && val != null) {
  37005. part += "=\"" + val + "\"";
  37006. }
  37007. attrsStr.push(part);
  37008. }
  37009. }
  37010. return "<" + name + " " + attrsStr.join(' ') + ">";
  37011. }
  37012. function createElementClose(name) {
  37013. return "</" + name + ">";
  37014. }
  37015. function vNodeToString(el, opts) {
  37016. opts = opts || {};
  37017. var S = opts.newline ? '\n' : '';
  37018. function convertElToString(el) {
  37019. var children = el.children, tag = el.tag, attrs = el.attrs, text = el.text;
  37020. return createElementOpen(tag, attrs)
  37021. + (tag !== 'style' ? encodeHTML(text) : text || '')
  37022. + (children ? "" + S + map(children, function (child) { return convertElToString(child); }).join(S) + S : '')
  37023. + createElementClose(tag);
  37024. }
  37025. return convertElToString(el);
  37026. }
  37027. function getCssString(selectorNodes, animationNodes, opts) {
  37028. opts = opts || {};
  37029. var S = opts.newline ? '\n' : '';
  37030. var bracketBegin = " {" + S;
  37031. var bracketEnd = S + "}";
  37032. var selectors = map(keys(selectorNodes), function (className) {
  37033. return className + bracketBegin + map(keys(selectorNodes[className]), function (attrName) {
  37034. return attrName + ":" + selectorNodes[className][attrName] + ";";
  37035. }).join(S) + bracketEnd;
  37036. }).join(S);
  37037. var animations = map(keys(animationNodes), function (animationName) {
  37038. return "@keyframes " + animationName + bracketBegin + map(keys(animationNodes[animationName]), function (percent) {
  37039. return percent + bracketBegin + map(keys(animationNodes[animationName][percent]), function (attrName) {
  37040. var val = animationNodes[animationName][percent][attrName];
  37041. if (attrName === 'd') {
  37042. val = "path(\"" + val + "\")";
  37043. }
  37044. return attrName + ":" + val + ";";
  37045. }).join(S) + bracketEnd;
  37046. }).join(S) + bracketEnd;
  37047. }).join(S);
  37048. if (!selectors && !animations) {
  37049. return '';
  37050. }
  37051. return ['<![CDATA[', selectors, animations, ']]>'].join(S);
  37052. }
  37053. function createBrushScope(zrId) {
  37054. return {
  37055. zrId: zrId,
  37056. shadowCache: {},
  37057. patternCache: {},
  37058. gradientCache: {},
  37059. clipPathCache: {},
  37060. defs: {},
  37061. cssNodes: {},
  37062. cssAnims: {},
  37063. cssStyleCache: {},
  37064. cssAnimIdx: 0,
  37065. shadowIdx: 0,
  37066. gradientIdx: 0,
  37067. patternIdx: 0,
  37068. clipPathIdx: 0
  37069. };
  37070. }
  37071. function createSVGVNode(width, height, children, useViewBox) {
  37072. return createVNode('svg', 'root', {
  37073. 'width': width,
  37074. 'height': height,
  37075. 'xmlns': SVGNS,
  37076. 'xmlns:xlink': XLINKNS,
  37077. 'version': '1.1',
  37078. 'baseProfile': 'full',
  37079. 'viewBox': useViewBox ? "0 0 " + width + " " + height : false
  37080. }, children);
  37081. }
  37082. var cssClassIdx = 0;
  37083. function getClassId() {
  37084. return cssClassIdx++;
  37085. }
  37086. var EASING_MAP = {
  37087. cubicIn: '0.32,0,0.67,0',
  37088. cubicOut: '0.33,1,0.68,1',
  37089. cubicInOut: '0.65,0,0.35,1',
  37090. quadraticIn: '0.11,0,0.5,0',
  37091. quadraticOut: '0.5,1,0.89,1',
  37092. quadraticInOut: '0.45,0,0.55,1',
  37093. quarticIn: '0.5,0,0.75,0',
  37094. quarticOut: '0.25,1,0.5,1',
  37095. quarticInOut: '0.76,0,0.24,1',
  37096. quinticIn: '0.64,0,0.78,0',
  37097. quinticOut: '0.22,1,0.36,1',
  37098. quinticInOut: '0.83,0,0.17,1',
  37099. sinusoidalIn: '0.12,0,0.39,0',
  37100. sinusoidalOut: '0.61,1,0.88,1',
  37101. sinusoidalInOut: '0.37,0,0.63,1',
  37102. exponentialIn: '0.7,0,0.84,0',
  37103. exponentialOut: '0.16,1,0.3,1',
  37104. exponentialInOut: '0.87,0,0.13,1',
  37105. circularIn: '0.55,0,1,0.45',
  37106. circularOut: '0,0.55,0.45,1',
  37107. circularInOut: '0.85,0,0.15,1'
  37108. };
  37109. var transformOriginKey = 'transform-origin';
  37110. function buildPathString(el, kfShape, path) {
  37111. var shape = extend({}, el.shape);
  37112. extend(shape, kfShape);
  37113. el.buildPath(path, shape);
  37114. var svgPathBuilder = new SVGPathRebuilder();
  37115. svgPathBuilder.reset(getPathPrecision(el));
  37116. path.rebuildPath(svgPathBuilder, 1);
  37117. svgPathBuilder.generateStr();
  37118. return svgPathBuilder.getStr();
  37119. }
  37120. function setTransformOrigin(target, transform) {
  37121. var originX = transform.originX, originY = transform.originY;
  37122. if (originX || originY) {
  37123. target[transformOriginKey] = originX + "px " + originY + "px";
  37124. }
  37125. }
  37126. var ANIMATE_STYLE_MAP = {
  37127. fill: 'fill',
  37128. opacity: 'opacity',
  37129. lineWidth: 'stroke-width',
  37130. lineDashOffset: 'stroke-dashoffset'
  37131. };
  37132. function addAnimation(cssAnim, scope) {
  37133. var animationName = scope.zrId + '-ani-' + scope.cssAnimIdx++;
  37134. scope.cssAnims[animationName] = cssAnim;
  37135. return animationName;
  37136. }
  37137. function createCompoundPathCSSAnimation(el, attrs, scope) {
  37138. var paths = el.shape.paths;
  37139. var composedAnim = {};
  37140. var cssAnimationCfg;
  37141. var cssAnimationName;
  37142. each(paths, function (path) {
  37143. var subScope = createBrushScope(scope.zrId);
  37144. subScope.animation = true;
  37145. createCSSAnimation(path, {}, subScope, true);
  37146. var cssAnims = subScope.cssAnims;
  37147. var cssNodes = subScope.cssNodes;
  37148. var animNames = keys(cssAnims);
  37149. var len = animNames.length;
  37150. if (!len) {
  37151. return;
  37152. }
  37153. cssAnimationName = animNames[len - 1];
  37154. var lastAnim = cssAnims[cssAnimationName];
  37155. for (var percent in lastAnim) {
  37156. var kf = lastAnim[percent];
  37157. composedAnim[percent] = composedAnim[percent] || { d: '' };
  37158. composedAnim[percent].d += kf.d || '';
  37159. }
  37160. for (var className in cssNodes) {
  37161. var val = cssNodes[className].animation;
  37162. if (val.indexOf(cssAnimationName) >= 0) {
  37163. cssAnimationCfg = val;
  37164. }
  37165. }
  37166. });
  37167. if (!cssAnimationCfg) {
  37168. return;
  37169. }
  37170. attrs.d = false;
  37171. var animationName = addAnimation(composedAnim, scope);
  37172. return cssAnimationCfg.replace(cssAnimationName, animationName);
  37173. }
  37174. function getEasingFunc(easing) {
  37175. return isString(easing)
  37176. ? EASING_MAP[easing]
  37177. ? "cubic-bezier(" + EASING_MAP[easing] + ")"
  37178. : createCubicEasingFunc(easing) ? easing : ''
  37179. : '';
  37180. }
  37181. function createCSSAnimation(el, attrs, scope, onlyShape) {
  37182. var animators = el.animators;
  37183. var len = animators.length;
  37184. var cssAnimations = [];
  37185. if (el instanceof CompoundPath) {
  37186. var animationCfg = createCompoundPathCSSAnimation(el, attrs, scope);
  37187. if (animationCfg) {
  37188. cssAnimations.push(animationCfg);
  37189. }
  37190. else if (!len) {
  37191. return;
  37192. }
  37193. }
  37194. else if (!len) {
  37195. return;
  37196. }
  37197. var groupAnimators = {};
  37198. for (var i = 0; i < len; i++) {
  37199. var animator = animators[i];
  37200. var cfgArr = [animator.getMaxTime() / 1000 + 's'];
  37201. var easing = getEasingFunc(animator.getClip().easing);
  37202. var delay = animator.getDelay();
  37203. if (easing) {
  37204. cfgArr.push(easing);
  37205. }
  37206. else {
  37207. cfgArr.push('linear');
  37208. }
  37209. if (delay) {
  37210. cfgArr.push(delay / 1000 + 's');
  37211. }
  37212. if (animator.getLoop()) {
  37213. cfgArr.push('infinite');
  37214. }
  37215. var cfg = cfgArr.join(' ');
  37216. groupAnimators[cfg] = groupAnimators[cfg] || [cfg, []];
  37217. groupAnimators[cfg][1].push(animator);
  37218. }
  37219. function createSingleCSSAnimation(groupAnimator) {
  37220. var animators = groupAnimator[1];
  37221. var len = animators.length;
  37222. var transformKfs = {};
  37223. var shapeKfs = {};
  37224. var finalKfs = {};
  37225. var animationTimingFunctionAttrName = 'animation-timing-function';
  37226. function saveAnimatorTrackToCssKfs(animator, cssKfs, toCssAttrName) {
  37227. var tracks = animator.getTracks();
  37228. var maxTime = animator.getMaxTime();
  37229. for (var k = 0; k < tracks.length; k++) {
  37230. var track = tracks[k];
  37231. if (track.needsAnimate()) {
  37232. var kfs = track.keyframes;
  37233. var attrName = track.propName;
  37234. toCssAttrName && (attrName = toCssAttrName(attrName));
  37235. if (attrName) {
  37236. for (var i = 0; i < kfs.length; i++) {
  37237. var kf = kfs[i];
  37238. var percent = Math.round(kf.time / maxTime * 100) + '%';
  37239. var kfEasing = getEasingFunc(kf.easing);
  37240. var rawValue = kf.rawValue;
  37241. if (isString(rawValue) || isNumber(rawValue)) {
  37242. cssKfs[percent] = cssKfs[percent] || {};
  37243. cssKfs[percent][attrName] = kf.rawValue;
  37244. if (kfEasing) {
  37245. cssKfs[percent][animationTimingFunctionAttrName] = kfEasing;
  37246. }
  37247. }
  37248. }
  37249. }
  37250. }
  37251. }
  37252. }
  37253. for (var i = 0; i < len; i++) {
  37254. var animator = animators[i];
  37255. var targetProp = animator.targetName;
  37256. if (!targetProp) {
  37257. !onlyShape && saveAnimatorTrackToCssKfs(animator, transformKfs);
  37258. }
  37259. else if (targetProp === 'shape') {
  37260. saveAnimatorTrackToCssKfs(animator, shapeKfs);
  37261. }
  37262. }
  37263. for (var percent in transformKfs) {
  37264. var transform = {};
  37265. copyTransform(transform, el);
  37266. extend(transform, transformKfs[percent]);
  37267. var str = getSRTTransformString(transform);
  37268. var timingFunction = transformKfs[percent][animationTimingFunctionAttrName];
  37269. finalKfs[percent] = str ? {
  37270. transform: str
  37271. } : {};
  37272. setTransformOrigin(finalKfs[percent], transform);
  37273. if (timingFunction) {
  37274. finalKfs[percent][animationTimingFunctionAttrName] = timingFunction;
  37275. }
  37276. }
  37277. var path;
  37278. var canAnimateShape = true;
  37279. for (var percent in shapeKfs) {
  37280. finalKfs[percent] = finalKfs[percent] || {};
  37281. var isFirst = !path;
  37282. var timingFunction = shapeKfs[percent][animationTimingFunctionAttrName];
  37283. if (isFirst) {
  37284. path = new PathProxy();
  37285. }
  37286. var len_1 = path.len();
  37287. path.reset();
  37288. finalKfs[percent].d = buildPathString(el, shapeKfs[percent], path);
  37289. var newLen = path.len();
  37290. if (!isFirst && len_1 !== newLen) {
  37291. canAnimateShape = false;
  37292. break;
  37293. }
  37294. if (timingFunction) {
  37295. finalKfs[percent][animationTimingFunctionAttrName] = timingFunction;
  37296. }
  37297. }
  37298. if (!canAnimateShape) {
  37299. for (var percent in finalKfs) {
  37300. delete finalKfs[percent].d;
  37301. }
  37302. }
  37303. if (!onlyShape) {
  37304. for (var i = 0; i < len; i++) {
  37305. var animator = animators[i];
  37306. var targetProp = animator.targetName;
  37307. if (targetProp === 'style') {
  37308. saveAnimatorTrackToCssKfs(animator, finalKfs, function (propName) { return ANIMATE_STYLE_MAP[propName]; });
  37309. }
  37310. }
  37311. }
  37312. var percents = keys(finalKfs);
  37313. var allTransformOriginSame = true;
  37314. var transformOrigin;
  37315. for (var i = 1; i < percents.length; i++) {
  37316. var p0 = percents[i - 1];
  37317. var p1 = percents[i];
  37318. if (finalKfs[p0][transformOriginKey] !== finalKfs[p1][transformOriginKey]) {
  37319. allTransformOriginSame = false;
  37320. break;
  37321. }
  37322. transformOrigin = finalKfs[p0][transformOriginKey];
  37323. }
  37324. if (allTransformOriginSame && transformOrigin) {
  37325. for (var percent in finalKfs) {
  37326. if (finalKfs[percent][transformOriginKey]) {
  37327. delete finalKfs[percent][transformOriginKey];
  37328. }
  37329. }
  37330. attrs[transformOriginKey] = transformOrigin;
  37331. }
  37332. if (filter(percents, function (percent) { return keys(finalKfs[percent]).length > 0; }).length) {
  37333. var animationName = addAnimation(finalKfs, scope);
  37334. return animationName + " " + groupAnimator[0] + " both";
  37335. }
  37336. }
  37337. for (var key in groupAnimators) {
  37338. var animationCfg = createSingleCSSAnimation(groupAnimators[key]);
  37339. if (animationCfg) {
  37340. cssAnimations.push(animationCfg);
  37341. }
  37342. }
  37343. if (cssAnimations.length) {
  37344. var className = scope.zrId + '-cls-' + getClassId();
  37345. scope.cssNodes['.' + className] = {
  37346. animation: cssAnimations.join(',')
  37347. };
  37348. attrs["class"] = className;
  37349. }
  37350. }
  37351. function createCSSEmphasis(el, attrs, scope) {
  37352. if (!el.ignore) {
  37353. if (el.isSilent()) {
  37354. var style = {
  37355. 'pointer-events': 'none'
  37356. };
  37357. setClassAttribute(style, attrs, scope, true);
  37358. }
  37359. else {
  37360. var emphasisStyle = el.states.emphasis && el.states.emphasis.style
  37361. ? el.states.emphasis.style
  37362. : {};
  37363. var fill = emphasisStyle.fill;
  37364. if (!fill) {
  37365. var normalFill = el.style && el.style.fill;
  37366. var selectFill = el.states.select
  37367. && el.states.select.style
  37368. && el.states.select.style.fill;
  37369. var fromFill = el.currentStates.indexOf('select') >= 0
  37370. ? (selectFill || normalFill)
  37371. : normalFill;
  37372. if (fromFill) {
  37373. fill = liftColor(fromFill);
  37374. }
  37375. }
  37376. var lineWidth = emphasisStyle.lineWidth;
  37377. if (lineWidth) {
  37378. var scaleX = (!emphasisStyle.strokeNoScale && el.transform)
  37379. ? el.transform[0]
  37380. : 1;
  37381. lineWidth = lineWidth / scaleX;
  37382. }
  37383. var style = {
  37384. cursor: 'pointer'
  37385. };
  37386. if (fill) {
  37387. style.fill = fill;
  37388. }
  37389. if (emphasisStyle.stroke) {
  37390. style.stroke = emphasisStyle.stroke;
  37391. }
  37392. if (lineWidth) {
  37393. style['stroke-width'] = lineWidth;
  37394. }
  37395. setClassAttribute(style, attrs, scope, true);
  37396. }
  37397. }
  37398. }
  37399. function setClassAttribute(style, attrs, scope, withHover) {
  37400. var styleKey = JSON.stringify(style);
  37401. var className = scope.cssStyleCache[styleKey];
  37402. if (!className) {
  37403. className = scope.zrId + '-cls-' + getClassId();
  37404. scope.cssStyleCache[styleKey] = className;
  37405. scope.cssNodes['.' + className + (withHover ? ':hover' : '')] = style;
  37406. }
  37407. attrs["class"] = attrs["class"] ? (attrs["class"] + ' ' + className) : className;
  37408. }
  37409. var round$2 = Math.round;
  37410. function isImageLike$1(val) {
  37411. return val && isString(val.src);
  37412. }
  37413. function isCanvasLike(val) {
  37414. return val && isFunction(val.toDataURL);
  37415. }
  37416. function setStyleAttrs(attrs, style, el, scope) {
  37417. mapStyleToAttrs(function (key, val) {
  37418. var isFillStroke = key === 'fill' || key === 'stroke';
  37419. if (isFillStroke && isGradient(val)) {
  37420. setGradient(style, attrs, key, scope);
  37421. }
  37422. else if (isFillStroke && isPattern(val)) {
  37423. setPattern(el, attrs, key, scope);
  37424. }
  37425. else {
  37426. attrs[key] = val;
  37427. }
  37428. if (isFillStroke && scope.ssr && val === 'none') {
  37429. attrs['pointer-events'] = 'visible';
  37430. }
  37431. }, style, el, false);
  37432. setShadow(el, attrs, scope);
  37433. }
  37434. function setMetaData(attrs, el) {
  37435. var metaData = getElementSSRData(el);
  37436. if (metaData) {
  37437. metaData.each(function (val, key) {
  37438. val != null && (attrs[(META_DATA_PREFIX + key).toLowerCase()] = val + '');
  37439. });
  37440. if (el.isSilent()) {
  37441. attrs[META_DATA_PREFIX + 'silent'] = 'true';
  37442. }
  37443. }
  37444. }
  37445. function noRotateScale(m) {
  37446. return isAroundZero$1(m[0] - 1)
  37447. && isAroundZero$1(m[1])
  37448. && isAroundZero$1(m[2])
  37449. && isAroundZero$1(m[3] - 1);
  37450. }
  37451. function noTranslate(m) {
  37452. return isAroundZero$1(m[4]) && isAroundZero$1(m[5]);
  37453. }
  37454. function setTransform(attrs, m, compress) {
  37455. if (m && !(noTranslate(m) && noRotateScale(m))) {
  37456. var mul = compress ? 10 : 1e4;
  37457. attrs.transform = noRotateScale(m)
  37458. ? "translate(" + round$2(m[4] * mul) / mul + " " + round$2(m[5] * mul) / mul + ")" : getMatrixStr(m);
  37459. }
  37460. }
  37461. function convertPolyShape(shape, attrs, mul) {
  37462. var points = shape.points;
  37463. var strArr = [];
  37464. for (var i = 0; i < points.length; i++) {
  37465. strArr.push(round$2(points[i][0] * mul) / mul);
  37466. strArr.push(round$2(points[i][1] * mul) / mul);
  37467. }
  37468. attrs.points = strArr.join(' ');
  37469. }
  37470. function validatePolyShape(shape) {
  37471. return !shape.smooth;
  37472. }
  37473. function createAttrsConvert(desc) {
  37474. var normalizedDesc = map(desc, function (item) {
  37475. return (typeof item === 'string' ? [item, item] : item);
  37476. });
  37477. return function (shape, attrs, mul) {
  37478. for (var i = 0; i < normalizedDesc.length; i++) {
  37479. var item = normalizedDesc[i];
  37480. var val = shape[item[0]];
  37481. if (val != null) {
  37482. attrs[item[1]] = round$2(val * mul) / mul;
  37483. }
  37484. }
  37485. };
  37486. }
  37487. var builtinShapesDef = {
  37488. circle: [createAttrsConvert(['cx', 'cy', 'r'])],
  37489. polyline: [convertPolyShape, validatePolyShape],
  37490. polygon: [convertPolyShape, validatePolyShape]
  37491. };
  37492. function hasShapeAnimation(el) {
  37493. var animators = el.animators;
  37494. for (var i = 0; i < animators.length; i++) {
  37495. if (animators[i].targetName === 'shape') {
  37496. return true;
  37497. }
  37498. }
  37499. return false;
  37500. }
  37501. function brushSVGPath(el, scope) {
  37502. var style = el.style;
  37503. var shape = el.shape;
  37504. var builtinShpDef = builtinShapesDef[el.type];
  37505. var attrs = {};
  37506. var needsAnimate = scope.animation;
  37507. var svgElType = 'path';
  37508. var strokePercent = el.style.strokePercent;
  37509. var precision = (scope.compress && getPathPrecision(el)) || 4;
  37510. if (builtinShpDef
  37511. && !scope.willUpdate
  37512. && !(builtinShpDef[1] && !builtinShpDef[1](shape))
  37513. && !(needsAnimate && hasShapeAnimation(el))
  37514. && !(strokePercent < 1)) {
  37515. svgElType = el.type;
  37516. var mul = Math.pow(10, precision);
  37517. builtinShpDef[0](shape, attrs, mul);
  37518. }
  37519. else {
  37520. var needBuildPath = !el.path || el.shapeChanged();
  37521. if (!el.path) {
  37522. el.createPathProxy();
  37523. }
  37524. var path = el.path;
  37525. if (needBuildPath) {
  37526. path.beginPath();
  37527. el.buildPath(path, el.shape);
  37528. el.pathUpdated();
  37529. }
  37530. var pathVersion = path.getVersion();
  37531. var elExt = el;
  37532. var svgPathBuilder = elExt.__svgPathBuilder;
  37533. if (elExt.__svgPathVersion !== pathVersion
  37534. || !svgPathBuilder
  37535. || strokePercent !== elExt.__svgPathStrokePercent) {
  37536. if (!svgPathBuilder) {
  37537. svgPathBuilder = elExt.__svgPathBuilder = new SVGPathRebuilder();
  37538. }
  37539. svgPathBuilder.reset(precision);
  37540. path.rebuildPath(svgPathBuilder, strokePercent);
  37541. svgPathBuilder.generateStr();
  37542. elExt.__svgPathVersion = pathVersion;
  37543. elExt.__svgPathStrokePercent = strokePercent;
  37544. }
  37545. attrs.d = svgPathBuilder.getStr();
  37546. }
  37547. setTransform(attrs, el.transform);
  37548. setStyleAttrs(attrs, style, el, scope);
  37549. setMetaData(attrs, el);
  37550. scope.animation && createCSSAnimation(el, attrs, scope);
  37551. scope.emphasis && createCSSEmphasis(el, attrs, scope);
  37552. return createVNode(svgElType, el.id + '', attrs);
  37553. }
  37554. function brushSVGImage(el, scope) {
  37555. var style = el.style;
  37556. var image = style.image;
  37557. if (image && !isString(image)) {
  37558. if (isImageLike$1(image)) {
  37559. image = image.src;
  37560. }
  37561. else if (isCanvasLike(image)) {
  37562. image = image.toDataURL();
  37563. }
  37564. }
  37565. if (!image) {
  37566. return;
  37567. }
  37568. var x = style.x || 0;
  37569. var y = style.y || 0;
  37570. var dw = style.width;
  37571. var dh = style.height;
  37572. var attrs = {
  37573. href: image,
  37574. width: dw,
  37575. height: dh
  37576. };
  37577. if (x) {
  37578. attrs.x = x;
  37579. }
  37580. if (y) {
  37581. attrs.y = y;
  37582. }
  37583. setTransform(attrs, el.transform);
  37584. setStyleAttrs(attrs, style, el, scope);
  37585. setMetaData(attrs, el);
  37586. scope.animation && createCSSAnimation(el, attrs, scope);
  37587. return createVNode('image', el.id + '', attrs);
  37588. }
  37589. function brushSVGTSpan(el, scope) {
  37590. var style = el.style;
  37591. var text = style.text;
  37592. text != null && (text += '');
  37593. if (!text || isNaN(style.x) || isNaN(style.y)) {
  37594. return;
  37595. }
  37596. var font = style.font || DEFAULT_FONT;
  37597. var x = style.x || 0;
  37598. var y = adjustTextY(style.y || 0, getLineHeight(font), style.textBaseline);
  37599. var textAlign = TEXT_ALIGN_TO_ANCHOR[style.textAlign]
  37600. || style.textAlign;
  37601. var attrs = {
  37602. 'dominant-baseline': 'central',
  37603. 'text-anchor': textAlign
  37604. };
  37605. if (hasSeparateFont(style)) {
  37606. var separatedFontStr = '';
  37607. var fontStyle = style.fontStyle;
  37608. var fontSize = parseFontSize(style.fontSize);
  37609. if (!parseFloat(fontSize)) {
  37610. return;
  37611. }
  37612. var fontFamily = style.fontFamily || DEFAULT_FONT_FAMILY;
  37613. var fontWeight = style.fontWeight;
  37614. separatedFontStr += "font-size:" + fontSize + ";font-family:" + fontFamily + ";";
  37615. if (fontStyle && fontStyle !== 'normal') {
  37616. separatedFontStr += "font-style:" + fontStyle + ";";
  37617. }
  37618. if (fontWeight && fontWeight !== 'normal') {
  37619. separatedFontStr += "font-weight:" + fontWeight + ";";
  37620. }
  37621. attrs.style = separatedFontStr;
  37622. }
  37623. else {
  37624. attrs.style = "font: " + font;
  37625. }
  37626. if (text.match(/\s/)) {
  37627. attrs['xml:space'] = 'preserve';
  37628. }
  37629. if (x) {
  37630. attrs.x = x;
  37631. }
  37632. if (y) {
  37633. attrs.y = y;
  37634. }
  37635. setTransform(attrs, el.transform);
  37636. setStyleAttrs(attrs, style, el, scope);
  37637. setMetaData(attrs, el);
  37638. scope.animation && createCSSAnimation(el, attrs, scope);
  37639. return createVNode('text', el.id + '', attrs, undefined, text);
  37640. }
  37641. function brush$1(el, scope) {
  37642. if (el instanceof Path) {
  37643. return brushSVGPath(el, scope);
  37644. }
  37645. else if (el instanceof ZRImage) {
  37646. return brushSVGImage(el, scope);
  37647. }
  37648. else if (el instanceof TSpan) {
  37649. return brushSVGTSpan(el, scope);
  37650. }
  37651. }
  37652. function setShadow(el, attrs, scope) {
  37653. var style = el.style;
  37654. if (hasShadow(style)) {
  37655. var shadowKey = getShadowKey(el);
  37656. var shadowCache = scope.shadowCache;
  37657. var shadowId = shadowCache[shadowKey];
  37658. if (!shadowId) {
  37659. var globalScale = el.getGlobalScale();
  37660. var scaleX = globalScale[0];
  37661. var scaleY = globalScale[1];
  37662. if (!scaleX || !scaleY) {
  37663. return;
  37664. }
  37665. var offsetX = style.shadowOffsetX || 0;
  37666. var offsetY = style.shadowOffsetY || 0;
  37667. var blur_1 = style.shadowBlur;
  37668. var _a = normalizeColor(style.shadowColor), opacity = _a.opacity, color = _a.color;
  37669. var stdDx = blur_1 / 2 / scaleX;
  37670. var stdDy = blur_1 / 2 / scaleY;
  37671. var stdDeviation = stdDx + ' ' + stdDy;
  37672. shadowId = scope.zrId + '-s' + scope.shadowIdx++;
  37673. scope.defs[shadowId] = createVNode('filter', shadowId, {
  37674. 'id': shadowId,
  37675. 'x': '-100%',
  37676. 'y': '-100%',
  37677. 'width': '300%',
  37678. 'height': '300%'
  37679. }, [
  37680. createVNode('feDropShadow', '', {
  37681. 'dx': offsetX / scaleX,
  37682. 'dy': offsetY / scaleY,
  37683. 'stdDeviation': stdDeviation,
  37684. 'flood-color': color,
  37685. 'flood-opacity': opacity
  37686. })
  37687. ]);
  37688. shadowCache[shadowKey] = shadowId;
  37689. }
  37690. attrs.filter = getIdURL(shadowId);
  37691. }
  37692. }
  37693. function setGradient(style, attrs, target, scope) {
  37694. var val = style[target];
  37695. var gradientTag;
  37696. var gradientAttrs = {
  37697. 'gradientUnits': val.global
  37698. ? 'userSpaceOnUse'
  37699. : 'objectBoundingBox'
  37700. };
  37701. if (isLinearGradient(val)) {
  37702. gradientTag = 'linearGradient';
  37703. gradientAttrs.x1 = val.x;
  37704. gradientAttrs.y1 = val.y;
  37705. gradientAttrs.x2 = val.x2;
  37706. gradientAttrs.y2 = val.y2;
  37707. }
  37708. else if (isRadialGradient(val)) {
  37709. gradientTag = 'radialGradient';
  37710. gradientAttrs.cx = retrieve2(val.x, 0.5);
  37711. gradientAttrs.cy = retrieve2(val.y, 0.5);
  37712. gradientAttrs.r = retrieve2(val.r, 0.5);
  37713. }
  37714. else {
  37715. if ("development" !== 'production') {
  37716. logError('Illegal gradient type.');
  37717. }
  37718. return;
  37719. }
  37720. var colors = val.colorStops;
  37721. var colorStops = [];
  37722. for (var i = 0, len = colors.length; i < len; ++i) {
  37723. var offset = round4(colors[i].offset) * 100 + '%';
  37724. var stopColor = colors[i].color;
  37725. var _a = normalizeColor(stopColor), color = _a.color, opacity = _a.opacity;
  37726. var stopsAttrs = {
  37727. 'offset': offset
  37728. };
  37729. stopsAttrs['stop-color'] = color;
  37730. if (opacity < 1) {
  37731. stopsAttrs['stop-opacity'] = opacity;
  37732. }
  37733. colorStops.push(createVNode('stop', i + '', stopsAttrs));
  37734. }
  37735. var gradientVNode = createVNode(gradientTag, '', gradientAttrs, colorStops);
  37736. var gradientKey = vNodeToString(gradientVNode);
  37737. var gradientCache = scope.gradientCache;
  37738. var gradientId = gradientCache[gradientKey];
  37739. if (!gradientId) {
  37740. gradientId = scope.zrId + '-g' + scope.gradientIdx++;
  37741. gradientCache[gradientKey] = gradientId;
  37742. gradientAttrs.id = gradientId;
  37743. scope.defs[gradientId] = createVNode(gradientTag, gradientId, gradientAttrs, colorStops);
  37744. }
  37745. attrs[target] = getIdURL(gradientId);
  37746. }
  37747. function setPattern(el, attrs, target, scope) {
  37748. var val = el.style[target];
  37749. var boundingRect = el.getBoundingRect();
  37750. var patternAttrs = {};
  37751. var repeat = val.repeat;
  37752. var noRepeat = repeat === 'no-repeat';
  37753. var repeatX = repeat === 'repeat-x';
  37754. var repeatY = repeat === 'repeat-y';
  37755. var child;
  37756. if (isImagePattern(val)) {
  37757. var imageWidth_1 = val.imageWidth;
  37758. var imageHeight_1 = val.imageHeight;
  37759. var imageSrc = void 0;
  37760. var patternImage = val.image;
  37761. if (isString(patternImage)) {
  37762. imageSrc = patternImage;
  37763. }
  37764. else if (isImageLike$1(patternImage)) {
  37765. imageSrc = patternImage.src;
  37766. }
  37767. else if (isCanvasLike(patternImage)) {
  37768. imageSrc = patternImage.toDataURL();
  37769. }
  37770. if (typeof Image === 'undefined') {
  37771. var errMsg = 'Image width/height must been given explictly in svg-ssr renderer.';
  37772. assert(imageWidth_1, errMsg);
  37773. assert(imageHeight_1, errMsg);
  37774. }
  37775. else if (imageWidth_1 == null || imageHeight_1 == null) {
  37776. var setSizeToVNode_1 = function (vNode, img) {
  37777. if (vNode) {
  37778. var svgEl = vNode.elm;
  37779. var width = imageWidth_1 || img.width;
  37780. var height = imageHeight_1 || img.height;
  37781. if (vNode.tag === 'pattern') {
  37782. if (repeatX) {
  37783. height = 1;
  37784. width /= boundingRect.width;
  37785. }
  37786. else if (repeatY) {
  37787. width = 1;
  37788. height /= boundingRect.height;
  37789. }
  37790. }
  37791. vNode.attrs.width = width;
  37792. vNode.attrs.height = height;
  37793. if (svgEl) {
  37794. svgEl.setAttribute('width', width);
  37795. svgEl.setAttribute('height', height);
  37796. }
  37797. }
  37798. };
  37799. var createdImage = createOrUpdateImage(imageSrc, null, el, function (img) {
  37800. noRepeat || setSizeToVNode_1(patternVNode, img);
  37801. setSizeToVNode_1(child, img);
  37802. });
  37803. if (createdImage && createdImage.width && createdImage.height) {
  37804. imageWidth_1 = imageWidth_1 || createdImage.width;
  37805. imageHeight_1 = imageHeight_1 || createdImage.height;
  37806. }
  37807. }
  37808. child = createVNode('image', 'img', {
  37809. href: imageSrc,
  37810. width: imageWidth_1,
  37811. height: imageHeight_1
  37812. });
  37813. patternAttrs.width = imageWidth_1;
  37814. patternAttrs.height = imageHeight_1;
  37815. }
  37816. else if (val.svgElement) {
  37817. child = clone(val.svgElement);
  37818. patternAttrs.width = val.svgWidth;
  37819. patternAttrs.height = val.svgHeight;
  37820. }
  37821. if (!child) {
  37822. return;
  37823. }
  37824. var patternWidth;
  37825. var patternHeight;
  37826. if (noRepeat) {
  37827. patternWidth = patternHeight = 1;
  37828. }
  37829. else if (repeatX) {
  37830. patternHeight = 1;
  37831. patternWidth = patternAttrs.width / boundingRect.width;
  37832. }
  37833. else if (repeatY) {
  37834. patternWidth = 1;
  37835. patternHeight = patternAttrs.height / boundingRect.height;
  37836. }
  37837. else {
  37838. patternAttrs.patternUnits = 'userSpaceOnUse';
  37839. }
  37840. if (patternWidth != null && !isNaN(patternWidth)) {
  37841. patternAttrs.width = patternWidth;
  37842. }
  37843. if (patternHeight != null && !isNaN(patternHeight)) {
  37844. patternAttrs.height = patternHeight;
  37845. }
  37846. var patternTransform = getSRTTransformString(val);
  37847. patternTransform && (patternAttrs.patternTransform = patternTransform);
  37848. var patternVNode = createVNode('pattern', '', patternAttrs, [child]);
  37849. var patternKey = vNodeToString(patternVNode);
  37850. var patternCache = scope.patternCache;
  37851. var patternId = patternCache[patternKey];
  37852. if (!patternId) {
  37853. patternId = scope.zrId + '-p' + scope.patternIdx++;
  37854. patternCache[patternKey] = patternId;
  37855. patternAttrs.id = patternId;
  37856. patternVNode = scope.defs[patternId] = createVNode('pattern', patternId, patternAttrs, [child]);
  37857. }
  37858. attrs[target] = getIdURL(patternId);
  37859. }
  37860. function setClipPath(clipPath, attrs, scope) {
  37861. var clipPathCache = scope.clipPathCache, defs = scope.defs;
  37862. var clipPathId = clipPathCache[clipPath.id];
  37863. if (!clipPathId) {
  37864. clipPathId = scope.zrId + '-c' + scope.clipPathIdx++;
  37865. var clipPathAttrs = {
  37866. id: clipPathId
  37867. };
  37868. clipPathCache[clipPath.id] = clipPathId;
  37869. defs[clipPathId] = createVNode('clipPath', clipPathId, clipPathAttrs, [brushSVGPath(clipPath, scope)]);
  37870. }
  37871. attrs['clip-path'] = getIdURL(clipPathId);
  37872. }
  37873. function createTextNode(text) {
  37874. return document.createTextNode(text);
  37875. }
  37876. function insertBefore(parentNode, newNode, referenceNode) {
  37877. parentNode.insertBefore(newNode, referenceNode);
  37878. }
  37879. function removeChild(node, child) {
  37880. node.removeChild(child);
  37881. }
  37882. function appendChild(node, child) {
  37883. node.appendChild(child);
  37884. }
  37885. function parentNode(node) {
  37886. return node.parentNode;
  37887. }
  37888. function nextSibling(node) {
  37889. return node.nextSibling;
  37890. }
  37891. function setTextContent(node, text) {
  37892. node.textContent = text;
  37893. }
  37894. var colonChar = 58;
  37895. var xChar = 120;
  37896. var emptyNode = createVNode('', '');
  37897. function isUndef(s) {
  37898. return s === undefined;
  37899. }
  37900. function isDef(s) {
  37901. return s !== undefined;
  37902. }
  37903. function createKeyToOldIdx(children, beginIdx, endIdx) {
  37904. var map = {};
  37905. for (var i = beginIdx; i <= endIdx; ++i) {
  37906. var key = children[i].key;
  37907. if (key !== undefined) {
  37908. if ("development" !== 'production') {
  37909. if (map[key] != null) {
  37910. console.error("Duplicate key " + key);
  37911. }
  37912. }
  37913. map[key] = i;
  37914. }
  37915. }
  37916. return map;
  37917. }
  37918. function sameVnode(vnode1, vnode2) {
  37919. var isSameKey = vnode1.key === vnode2.key;
  37920. var isSameTag = vnode1.tag === vnode2.tag;
  37921. return isSameTag && isSameKey;
  37922. }
  37923. function createElm(vnode) {
  37924. var i;
  37925. var children = vnode.children;
  37926. var tag = vnode.tag;
  37927. if (isDef(tag)) {
  37928. var elm = (vnode.elm = createElement(tag));
  37929. updateAttrs(emptyNode, vnode);
  37930. if (isArray(children)) {
  37931. for (i = 0; i < children.length; ++i) {
  37932. var ch = children[i];
  37933. if (ch != null) {
  37934. appendChild(elm, createElm(ch));
  37935. }
  37936. }
  37937. }
  37938. else if (isDef(vnode.text) && !isObject(vnode.text)) {
  37939. appendChild(elm, createTextNode(vnode.text));
  37940. }
  37941. }
  37942. else {
  37943. vnode.elm = createTextNode(vnode.text);
  37944. }
  37945. return vnode.elm;
  37946. }
  37947. function addVnodes(parentElm, before, vnodes, startIdx, endIdx) {
  37948. for (; startIdx <= endIdx; ++startIdx) {
  37949. var ch = vnodes[startIdx];
  37950. if (ch != null) {
  37951. insertBefore(parentElm, createElm(ch), before);
  37952. }
  37953. }
  37954. }
  37955. function removeVnodes(parentElm, vnodes, startIdx, endIdx) {
  37956. for (; startIdx <= endIdx; ++startIdx) {
  37957. var ch = vnodes[startIdx];
  37958. if (ch != null) {
  37959. if (isDef(ch.tag)) {
  37960. var parent_1 = parentNode(ch.elm);
  37961. removeChild(parent_1, ch.elm);
  37962. }
  37963. else {
  37964. removeChild(parentElm, ch.elm);
  37965. }
  37966. }
  37967. }
  37968. }
  37969. function updateAttrs(oldVnode, vnode) {
  37970. var key;
  37971. var elm = vnode.elm;
  37972. var oldAttrs = oldVnode && oldVnode.attrs || {};
  37973. var attrs = vnode.attrs || {};
  37974. if (oldAttrs === attrs) {
  37975. return;
  37976. }
  37977. for (key in attrs) {
  37978. var cur = attrs[key];
  37979. var old = oldAttrs[key];
  37980. if (old !== cur) {
  37981. if (cur === true) {
  37982. elm.setAttribute(key, '');
  37983. }
  37984. else if (cur === false) {
  37985. elm.removeAttribute(key);
  37986. }
  37987. else {
  37988. if (key === 'style') {
  37989. elm.style.cssText = cur;
  37990. }
  37991. else if (key.charCodeAt(0) !== xChar) {
  37992. elm.setAttribute(key, cur);
  37993. }
  37994. else if (key === 'xmlns:xlink' || key === 'xmlns') {
  37995. elm.setAttributeNS(XMLNS, key, cur);
  37996. }
  37997. else if (key.charCodeAt(3) === colonChar) {
  37998. elm.setAttributeNS(XML_NAMESPACE, key, cur);
  37999. }
  38000. else if (key.charCodeAt(5) === colonChar) {
  38001. elm.setAttributeNS(XLINKNS, key, cur);
  38002. }
  38003. else {
  38004. elm.setAttribute(key, cur);
  38005. }
  38006. }
  38007. }
  38008. }
  38009. for (key in oldAttrs) {
  38010. if (!(key in attrs)) {
  38011. elm.removeAttribute(key);
  38012. }
  38013. }
  38014. }
  38015. function updateChildren(parentElm, oldCh, newCh) {
  38016. var oldStartIdx = 0;
  38017. var newStartIdx = 0;
  38018. var oldEndIdx = oldCh.length - 1;
  38019. var oldStartVnode = oldCh[0];
  38020. var oldEndVnode = oldCh[oldEndIdx];
  38021. var newEndIdx = newCh.length - 1;
  38022. var newStartVnode = newCh[0];
  38023. var newEndVnode = newCh[newEndIdx];
  38024. var oldKeyToIdx;
  38025. var idxInOld;
  38026. var elmToMove;
  38027. var before;
  38028. while (oldStartIdx <= oldEndIdx && newStartIdx <= newEndIdx) {
  38029. if (oldStartVnode == null) {
  38030. oldStartVnode = oldCh[++oldStartIdx];
  38031. }
  38032. else if (oldEndVnode == null) {
  38033. oldEndVnode = oldCh[--oldEndIdx];
  38034. }
  38035. else if (newStartVnode == null) {
  38036. newStartVnode = newCh[++newStartIdx];
  38037. }
  38038. else if (newEndVnode == null) {
  38039. newEndVnode = newCh[--newEndIdx];
  38040. }
  38041. else if (sameVnode(oldStartVnode, newStartVnode)) {
  38042. patchVnode(oldStartVnode, newStartVnode);
  38043. oldStartVnode = oldCh[++oldStartIdx];
  38044. newStartVnode = newCh[++newStartIdx];
  38045. }
  38046. else if (sameVnode(oldEndVnode, newEndVnode)) {
  38047. patchVnode(oldEndVnode, newEndVnode);
  38048. oldEndVnode = oldCh[--oldEndIdx];
  38049. newEndVnode = newCh[--newEndIdx];
  38050. }
  38051. else if (sameVnode(oldStartVnode, newEndVnode)) {
  38052. patchVnode(oldStartVnode, newEndVnode);
  38053. insertBefore(parentElm, oldStartVnode.elm, nextSibling(oldEndVnode.elm));
  38054. oldStartVnode = oldCh[++oldStartIdx];
  38055. newEndVnode = newCh[--newEndIdx];
  38056. }
  38057. else if (sameVnode(oldEndVnode, newStartVnode)) {
  38058. patchVnode(oldEndVnode, newStartVnode);
  38059. insertBefore(parentElm, oldEndVnode.elm, oldStartVnode.elm);
  38060. oldEndVnode = oldCh[--oldEndIdx];
  38061. newStartVnode = newCh[++newStartIdx];
  38062. }
  38063. else {
  38064. if (isUndef(oldKeyToIdx)) {
  38065. oldKeyToIdx = createKeyToOldIdx(oldCh, oldStartIdx, oldEndIdx);
  38066. }
  38067. idxInOld = oldKeyToIdx[newStartVnode.key];
  38068. if (isUndef(idxInOld)) {
  38069. insertBefore(parentElm, createElm(newStartVnode), oldStartVnode.elm);
  38070. }
  38071. else {
  38072. elmToMove = oldCh[idxInOld];
  38073. if (elmToMove.tag !== newStartVnode.tag) {
  38074. insertBefore(parentElm, createElm(newStartVnode), oldStartVnode.elm);
  38075. }
  38076. else {
  38077. patchVnode(elmToMove, newStartVnode);
  38078. oldCh[idxInOld] = undefined;
  38079. insertBefore(parentElm, elmToMove.elm, oldStartVnode.elm);
  38080. }
  38081. }
  38082. newStartVnode = newCh[++newStartIdx];
  38083. }
  38084. }
  38085. if (oldStartIdx <= oldEndIdx || newStartIdx <= newEndIdx) {
  38086. if (oldStartIdx > oldEndIdx) {
  38087. before = newCh[newEndIdx + 1] == null ? null : newCh[newEndIdx + 1].elm;
  38088. addVnodes(parentElm, before, newCh, newStartIdx, newEndIdx);
  38089. }
  38090. else {
  38091. removeVnodes(parentElm, oldCh, oldStartIdx, oldEndIdx);
  38092. }
  38093. }
  38094. }
  38095. function patchVnode(oldVnode, vnode) {
  38096. var elm = (vnode.elm = oldVnode.elm);
  38097. var oldCh = oldVnode.children;
  38098. var ch = vnode.children;
  38099. if (oldVnode === vnode) {
  38100. return;
  38101. }
  38102. updateAttrs(oldVnode, vnode);
  38103. if (isUndef(vnode.text)) {
  38104. if (isDef(oldCh) && isDef(ch)) {
  38105. if (oldCh !== ch) {
  38106. updateChildren(elm, oldCh, ch);
  38107. }
  38108. }
  38109. else if (isDef(ch)) {
  38110. if (isDef(oldVnode.text)) {
  38111. setTextContent(elm, '');
  38112. }
  38113. addVnodes(elm, null, ch, 0, ch.length - 1);
  38114. }
  38115. else if (isDef(oldCh)) {
  38116. removeVnodes(elm, oldCh, 0, oldCh.length - 1);
  38117. }
  38118. else if (isDef(oldVnode.text)) {
  38119. setTextContent(elm, '');
  38120. }
  38121. }
  38122. else if (oldVnode.text !== vnode.text) {
  38123. if (isDef(oldCh)) {
  38124. removeVnodes(elm, oldCh, 0, oldCh.length - 1);
  38125. }
  38126. setTextContent(elm, vnode.text);
  38127. }
  38128. }
  38129. function patch(oldVnode, vnode) {
  38130. if (sameVnode(oldVnode, vnode)) {
  38131. patchVnode(oldVnode, vnode);
  38132. }
  38133. else {
  38134. var elm = oldVnode.elm;
  38135. var parent_2 = parentNode(elm);
  38136. createElm(vnode);
  38137. if (parent_2 !== null) {
  38138. insertBefore(parent_2, vnode.elm, nextSibling(elm));
  38139. removeVnodes(parent_2, [oldVnode], 0, 0);
  38140. }
  38141. }
  38142. return vnode;
  38143. }
  38144. var svgId = 0;
  38145. var SVGPainter = (function () {
  38146. function SVGPainter(root, storage, opts) {
  38147. this.type = 'svg';
  38148. this.refreshHover = createMethodNotSupport('refreshHover');
  38149. this.configLayer = createMethodNotSupport('configLayer');
  38150. this.storage = storage;
  38151. this._opts = opts = extend({}, opts);
  38152. this.root = root;
  38153. this._id = 'zr' + svgId++;
  38154. this._oldVNode = createSVGVNode(opts.width, opts.height);
  38155. if (root && !opts.ssr) {
  38156. var viewport = this._viewport = document.createElement('div');
  38157. viewport.style.cssText = 'position:relative;overflow:hidden';
  38158. var svgDom = this._svgDom = this._oldVNode.elm = createElement('svg');
  38159. updateAttrs(null, this._oldVNode);
  38160. viewport.appendChild(svgDom);
  38161. root.appendChild(viewport);
  38162. }
  38163. this.resize(opts.width, opts.height);
  38164. }
  38165. SVGPainter.prototype.getType = function () {
  38166. return this.type;
  38167. };
  38168. SVGPainter.prototype.getViewportRoot = function () {
  38169. return this._viewport;
  38170. };
  38171. SVGPainter.prototype.getViewportRootOffset = function () {
  38172. var viewportRoot = this.getViewportRoot();
  38173. if (viewportRoot) {
  38174. return {
  38175. offsetLeft: viewportRoot.offsetLeft || 0,
  38176. offsetTop: viewportRoot.offsetTop || 0
  38177. };
  38178. }
  38179. };
  38180. SVGPainter.prototype.getSvgDom = function () {
  38181. return this._svgDom;
  38182. };
  38183. SVGPainter.prototype.refresh = function () {
  38184. if (this.root) {
  38185. var vnode = this.renderToVNode({
  38186. willUpdate: true
  38187. });
  38188. vnode.attrs.style = 'position:absolute;left:0;top:0;user-select:none';
  38189. patch(this._oldVNode, vnode);
  38190. this._oldVNode = vnode;
  38191. }
  38192. };
  38193. SVGPainter.prototype.renderOneToVNode = function (el) {
  38194. return brush$1(el, createBrushScope(this._id));
  38195. };
  38196. SVGPainter.prototype.renderToVNode = function (opts) {
  38197. opts = opts || {};
  38198. var list = this.storage.getDisplayList(true);
  38199. var width = this._width;
  38200. var height = this._height;
  38201. var scope = createBrushScope(this._id);
  38202. scope.animation = opts.animation;
  38203. scope.willUpdate = opts.willUpdate;
  38204. scope.compress = opts.compress;
  38205. scope.emphasis = opts.emphasis;
  38206. scope.ssr = this._opts.ssr;
  38207. var children = [];
  38208. var bgVNode = this._bgVNode = createBackgroundVNode(width, height, this._backgroundColor, scope);
  38209. bgVNode && children.push(bgVNode);
  38210. var mainVNode = !opts.compress
  38211. ? (this._mainVNode = createVNode('g', 'main', {}, [])) : null;
  38212. this._paintList(list, scope, mainVNode ? mainVNode.children : children);
  38213. mainVNode && children.push(mainVNode);
  38214. var defs = map(keys(scope.defs), function (id) { return scope.defs[id]; });
  38215. if (defs.length) {
  38216. children.push(createVNode('defs', 'defs', {}, defs));
  38217. }
  38218. if (opts.animation) {
  38219. var animationCssStr = getCssString(scope.cssNodes, scope.cssAnims, { newline: true });
  38220. if (animationCssStr) {
  38221. var styleNode = createVNode('style', 'stl', {}, [], animationCssStr);
  38222. children.push(styleNode);
  38223. }
  38224. }
  38225. return createSVGVNode(width, height, children, opts.useViewBox);
  38226. };
  38227. SVGPainter.prototype.renderToString = function (opts) {
  38228. opts = opts || {};
  38229. return vNodeToString(this.renderToVNode({
  38230. animation: retrieve2(opts.cssAnimation, true),
  38231. emphasis: retrieve2(opts.cssEmphasis, true),
  38232. willUpdate: false,
  38233. compress: true,
  38234. useViewBox: retrieve2(opts.useViewBox, true)
  38235. }), { newline: true });
  38236. };
  38237. SVGPainter.prototype.setBackgroundColor = function (backgroundColor) {
  38238. this._backgroundColor = backgroundColor;
  38239. };
  38240. SVGPainter.prototype.getSvgRoot = function () {
  38241. return this._mainVNode && this._mainVNode.elm;
  38242. };
  38243. SVGPainter.prototype._paintList = function (list, scope, out) {
  38244. var listLen = list.length;
  38245. var clipPathsGroupsStack = [];
  38246. var clipPathsGroupsStackDepth = 0;
  38247. var currentClipPathGroup;
  38248. var prevClipPaths;
  38249. var clipGroupNodeIdx = 0;
  38250. for (var i = 0; i < listLen; i++) {
  38251. var displayable = list[i];
  38252. if (!displayable.invisible) {
  38253. var clipPaths = displayable.__clipPaths;
  38254. var len = clipPaths && clipPaths.length || 0;
  38255. var prevLen = prevClipPaths && prevClipPaths.length || 0;
  38256. var lca = void 0;
  38257. for (lca = Math.max(len - 1, prevLen - 1); lca >= 0; lca--) {
  38258. if (clipPaths && prevClipPaths
  38259. && clipPaths[lca] === prevClipPaths[lca]) {
  38260. break;
  38261. }
  38262. }
  38263. for (var i_1 = prevLen - 1; i_1 > lca; i_1--) {
  38264. clipPathsGroupsStackDepth--;
  38265. currentClipPathGroup = clipPathsGroupsStack[clipPathsGroupsStackDepth - 1];
  38266. }
  38267. for (var i_2 = lca + 1; i_2 < len; i_2++) {
  38268. var groupAttrs = {};
  38269. setClipPath(clipPaths[i_2], groupAttrs, scope);
  38270. var g = createVNode('g', 'clip-g-' + clipGroupNodeIdx++, groupAttrs, []);
  38271. (currentClipPathGroup ? currentClipPathGroup.children : out).push(g);
  38272. clipPathsGroupsStack[clipPathsGroupsStackDepth++] = g;
  38273. currentClipPathGroup = g;
  38274. }
  38275. prevClipPaths = clipPaths;
  38276. var ret = brush$1(displayable, scope);
  38277. if (ret) {
  38278. (currentClipPathGroup ? currentClipPathGroup.children : out).push(ret);
  38279. }
  38280. }
  38281. }
  38282. };
  38283. SVGPainter.prototype.resize = function (width, height) {
  38284. var opts = this._opts;
  38285. var root = this.root;
  38286. var viewport = this._viewport;
  38287. width != null && (opts.width = width);
  38288. height != null && (opts.height = height);
  38289. if (root && viewport) {
  38290. viewport.style.display = 'none';
  38291. width = getSize(root, 0, opts);
  38292. height = getSize(root, 1, opts);
  38293. viewport.style.display = '';
  38294. }
  38295. if (this._width !== width || this._height !== height) {
  38296. this._width = width;
  38297. this._height = height;
  38298. if (viewport) {
  38299. var viewportStyle = viewport.style;
  38300. viewportStyle.width = width + 'px';
  38301. viewportStyle.height = height + 'px';
  38302. }
  38303. if (!isPattern(this._backgroundColor)) {
  38304. var svgDom = this._svgDom;
  38305. if (svgDom) {
  38306. svgDom.setAttribute('width', width);
  38307. svgDom.setAttribute('height', height);
  38308. }
  38309. var bgEl = this._bgVNode && this._bgVNode.elm;
  38310. if (bgEl) {
  38311. bgEl.setAttribute('width', width);
  38312. bgEl.setAttribute('height', height);
  38313. }
  38314. }
  38315. else {
  38316. this.refresh();
  38317. }
  38318. }
  38319. };
  38320. SVGPainter.prototype.getWidth = function () {
  38321. return this._width;
  38322. };
  38323. SVGPainter.prototype.getHeight = function () {
  38324. return this._height;
  38325. };
  38326. SVGPainter.prototype.dispose = function () {
  38327. if (this.root) {
  38328. this.root.innerHTML = '';
  38329. }
  38330. this._svgDom =
  38331. this._viewport =
  38332. this.storage =
  38333. this._oldVNode =
  38334. this._bgVNode =
  38335. this._mainVNode = null;
  38336. };
  38337. SVGPainter.prototype.clear = function () {
  38338. if (this._svgDom) {
  38339. this._svgDom.innerHTML = null;
  38340. }
  38341. this._oldVNode = null;
  38342. };
  38343. SVGPainter.prototype.toDataURL = function (base64) {
  38344. var str = this.renderToString();
  38345. var prefix = 'data:image/svg+xml;';
  38346. if (base64) {
  38347. str = encodeBase64(str);
  38348. return str && prefix + 'base64,' + str;
  38349. }
  38350. return prefix + 'charset=UTF-8,' + encodeURIComponent(str);
  38351. };
  38352. return SVGPainter;
  38353. }());
  38354. function createMethodNotSupport(method) {
  38355. return function () {
  38356. if ("development" !== 'production') {
  38357. logError('In SVG mode painter not support method "' + method + '"');
  38358. }
  38359. };
  38360. }
  38361. function createBackgroundVNode(width, height, backgroundColor, scope) {
  38362. var bgVNode;
  38363. if (backgroundColor && backgroundColor !== 'none') {
  38364. bgVNode = createVNode('rect', 'bg', {
  38365. width: width,
  38366. height: height,
  38367. x: '0',
  38368. y: '0'
  38369. });
  38370. if (isGradient(backgroundColor)) {
  38371. setGradient({ fill: backgroundColor }, bgVNode.attrs, 'fill', scope);
  38372. }
  38373. else if (isPattern(backgroundColor)) {
  38374. setPattern({
  38375. style: {
  38376. fill: backgroundColor
  38377. },
  38378. dirty: noop,
  38379. getBoundingRect: function () { return ({ width: width, height: height }); }
  38380. }, bgVNode.attrs, 'fill', scope);
  38381. }
  38382. else {
  38383. var _a = normalizeColor(backgroundColor), color = _a.color, opacity = _a.opacity;
  38384. bgVNode.attrs.fill = color;
  38385. opacity < 1 && (bgVNode.attrs['fill-opacity'] = opacity);
  38386. }
  38387. }
  38388. return bgVNode;
  38389. }
  38390. function install(registers) {
  38391. registers.registerPainter('svg', SVGPainter);
  38392. }
  38393. function createDom(id, painter, dpr) {
  38394. var newDom = platformApi.createCanvas();
  38395. var width = painter.getWidth();
  38396. var height = painter.getHeight();
  38397. var newDomStyle = newDom.style;
  38398. if (newDomStyle) {
  38399. newDomStyle.position = 'absolute';
  38400. newDomStyle.left = '0';
  38401. newDomStyle.top = '0';
  38402. newDomStyle.width = width + 'px';
  38403. newDomStyle.height = height + 'px';
  38404. newDom.setAttribute('data-zr-dom-id', id);
  38405. }
  38406. newDom.width = width * dpr;
  38407. newDom.height = height * dpr;
  38408. return newDom;
  38409. }
  38410. var Layer = (function (_super) {
  38411. __extends(Layer, _super);
  38412. function Layer(id, painter, dpr) {
  38413. var _this = _super.call(this) || this;
  38414. _this.motionBlur = false;
  38415. _this.lastFrameAlpha = 0.7;
  38416. _this.dpr = 1;
  38417. _this.virtual = false;
  38418. _this.config = {};
  38419. _this.incremental = false;
  38420. _this.zlevel = 0;
  38421. _this.maxRepaintRectCount = 5;
  38422. _this.__dirty = true;
  38423. _this.__firstTimePaint = true;
  38424. _this.__used = false;
  38425. _this.__drawIndex = 0;
  38426. _this.__startIndex = 0;
  38427. _this.__endIndex = 0;
  38428. _this.__prevStartIndex = null;
  38429. _this.__prevEndIndex = null;
  38430. var dom;
  38431. dpr = dpr || devicePixelRatio;
  38432. if (typeof id === 'string') {
  38433. dom = createDom(id, painter, dpr);
  38434. }
  38435. else if (isObject(id)) {
  38436. dom = id;
  38437. id = dom.id;
  38438. }
  38439. _this.id = id;
  38440. _this.dom = dom;
  38441. var domStyle = dom.style;
  38442. if (domStyle) {
  38443. disableUserSelect(dom);
  38444. dom.onselectstart = function () { return false; };
  38445. domStyle.padding = '0';
  38446. domStyle.margin = '0';
  38447. domStyle.borderWidth = '0';
  38448. }
  38449. _this.painter = painter;
  38450. _this.dpr = dpr;
  38451. return _this;
  38452. }
  38453. Layer.prototype.getElementCount = function () {
  38454. return this.__endIndex - this.__startIndex;
  38455. };
  38456. Layer.prototype.afterBrush = function () {
  38457. this.__prevStartIndex = this.__startIndex;
  38458. this.__prevEndIndex = this.__endIndex;
  38459. };
  38460. Layer.prototype.initContext = function () {
  38461. this.ctx = this.dom.getContext('2d');
  38462. this.ctx.dpr = this.dpr;
  38463. };
  38464. Layer.prototype.setUnpainted = function () {
  38465. this.__firstTimePaint = true;
  38466. };
  38467. Layer.prototype.createBackBuffer = function () {
  38468. var dpr = this.dpr;
  38469. this.domBack = createDom('back-' + this.id, this.painter, dpr);
  38470. this.ctxBack = this.domBack.getContext('2d');
  38471. if (dpr !== 1) {
  38472. this.ctxBack.scale(dpr, dpr);
  38473. }
  38474. };
  38475. Layer.prototype.createRepaintRects = function (displayList, prevList, viewWidth, viewHeight) {
  38476. if (this.__firstTimePaint) {
  38477. this.__firstTimePaint = false;
  38478. return null;
  38479. }
  38480. var mergedRepaintRects = [];
  38481. var maxRepaintRectCount = this.maxRepaintRectCount;
  38482. var full = false;
  38483. var pendingRect = new BoundingRect(0, 0, 0, 0);
  38484. function addRectToMergePool(rect) {
  38485. if (!rect.isFinite() || rect.isZero()) {
  38486. return;
  38487. }
  38488. if (mergedRepaintRects.length === 0) {
  38489. var boundingRect = new BoundingRect(0, 0, 0, 0);
  38490. boundingRect.copy(rect);
  38491. mergedRepaintRects.push(boundingRect);
  38492. }
  38493. else {
  38494. var isMerged = false;
  38495. var minDeltaArea = Infinity;
  38496. var bestRectToMergeIdx = 0;
  38497. for (var i = 0; i < mergedRepaintRects.length; ++i) {
  38498. var mergedRect = mergedRepaintRects[i];
  38499. if (mergedRect.intersect(rect)) {
  38500. var pendingRect_1 = new BoundingRect(0, 0, 0, 0);
  38501. pendingRect_1.copy(mergedRect);
  38502. pendingRect_1.union(rect);
  38503. mergedRepaintRects[i] = pendingRect_1;
  38504. isMerged = true;
  38505. break;
  38506. }
  38507. else if (full) {
  38508. pendingRect.copy(rect);
  38509. pendingRect.union(mergedRect);
  38510. var aArea = rect.width * rect.height;
  38511. var bArea = mergedRect.width * mergedRect.height;
  38512. var pendingArea = pendingRect.width * pendingRect.height;
  38513. var deltaArea = pendingArea - aArea - bArea;
  38514. if (deltaArea < minDeltaArea) {
  38515. minDeltaArea = deltaArea;
  38516. bestRectToMergeIdx = i;
  38517. }
  38518. }
  38519. }
  38520. if (full) {
  38521. mergedRepaintRects[bestRectToMergeIdx].union(rect);
  38522. isMerged = true;
  38523. }
  38524. if (!isMerged) {
  38525. var boundingRect = new BoundingRect(0, 0, 0, 0);
  38526. boundingRect.copy(rect);
  38527. mergedRepaintRects.push(boundingRect);
  38528. }
  38529. if (!full) {
  38530. full = mergedRepaintRects.length >= maxRepaintRectCount;
  38531. }
  38532. }
  38533. }
  38534. for (var i = this.__startIndex; i < this.__endIndex; ++i) {
  38535. var el = displayList[i];
  38536. if (el) {
  38537. var shouldPaint = el.shouldBePainted(viewWidth, viewHeight, true, true);
  38538. var prevRect = el.__isRendered && ((el.__dirty & REDRAW_BIT) || !shouldPaint)
  38539. ? el.getPrevPaintRect()
  38540. : null;
  38541. if (prevRect) {
  38542. addRectToMergePool(prevRect);
  38543. }
  38544. var curRect = shouldPaint && ((el.__dirty & REDRAW_BIT) || !el.__isRendered)
  38545. ? el.getPaintRect()
  38546. : null;
  38547. if (curRect) {
  38548. addRectToMergePool(curRect);
  38549. }
  38550. }
  38551. }
  38552. for (var i = this.__prevStartIndex; i < this.__prevEndIndex; ++i) {
  38553. var el = prevList[i];
  38554. var shouldPaint = el && el.shouldBePainted(viewWidth, viewHeight, true, true);
  38555. if (el && (!shouldPaint || !el.__zr) && el.__isRendered) {
  38556. var prevRect = el.getPrevPaintRect();
  38557. if (prevRect) {
  38558. addRectToMergePool(prevRect);
  38559. }
  38560. }
  38561. }
  38562. var hasIntersections;
  38563. do {
  38564. hasIntersections = false;
  38565. for (var i = 0; i < mergedRepaintRects.length;) {
  38566. if (mergedRepaintRects[i].isZero()) {
  38567. mergedRepaintRects.splice(i, 1);
  38568. continue;
  38569. }
  38570. for (var j = i + 1; j < mergedRepaintRects.length;) {
  38571. if (mergedRepaintRects[i].intersect(mergedRepaintRects[j])) {
  38572. hasIntersections = true;
  38573. mergedRepaintRects[i].union(mergedRepaintRects[j]);
  38574. mergedRepaintRects.splice(j, 1);
  38575. }
  38576. else {
  38577. j++;
  38578. }
  38579. }
  38580. i++;
  38581. }
  38582. } while (hasIntersections);
  38583. this._paintRects = mergedRepaintRects;
  38584. return mergedRepaintRects;
  38585. };
  38586. Layer.prototype.debugGetPaintRects = function () {
  38587. return (this._paintRects || []).slice();
  38588. };
  38589. Layer.prototype.resize = function (width, height) {
  38590. var dpr = this.dpr;
  38591. var dom = this.dom;
  38592. var domStyle = dom.style;
  38593. var domBack = this.domBack;
  38594. if (domStyle) {
  38595. domStyle.width = width + 'px';
  38596. domStyle.height = height + 'px';
  38597. }
  38598. dom.width = width * dpr;
  38599. dom.height = height * dpr;
  38600. if (domBack) {
  38601. domBack.width = width * dpr;
  38602. domBack.height = height * dpr;
  38603. if (dpr !== 1) {
  38604. this.ctxBack.scale(dpr, dpr);
  38605. }
  38606. }
  38607. };
  38608. Layer.prototype.clear = function (clearAll, clearColor, repaintRects) {
  38609. var dom = this.dom;
  38610. var ctx = this.ctx;
  38611. var width = dom.width;
  38612. var height = dom.height;
  38613. clearColor = clearColor || this.clearColor;
  38614. var haveMotionBLur = this.motionBlur && !clearAll;
  38615. var lastFrameAlpha = this.lastFrameAlpha;
  38616. var dpr = this.dpr;
  38617. var self = this;
  38618. if (haveMotionBLur) {
  38619. if (!this.domBack) {
  38620. this.createBackBuffer();
  38621. }
  38622. this.ctxBack.globalCompositeOperation = 'copy';
  38623. this.ctxBack.drawImage(dom, 0, 0, width / dpr, height / dpr);
  38624. }
  38625. var domBack = this.domBack;
  38626. function doClear(x, y, width, height) {
  38627. ctx.clearRect(x, y, width, height);
  38628. if (clearColor && clearColor !== 'transparent') {
  38629. var clearColorGradientOrPattern = void 0;
  38630. if (isGradientObject(clearColor)) {
  38631. var shouldCache = clearColor.global || (clearColor.__width === width
  38632. && clearColor.__height === height);
  38633. clearColorGradientOrPattern = shouldCache
  38634. && clearColor.__canvasGradient
  38635. || getCanvasGradient(ctx, clearColor, {
  38636. x: 0,
  38637. y: 0,
  38638. width: width,
  38639. height: height
  38640. });
  38641. clearColor.__canvasGradient = clearColorGradientOrPattern;
  38642. clearColor.__width = width;
  38643. clearColor.__height = height;
  38644. }
  38645. else if (isImagePatternObject(clearColor)) {
  38646. clearColor.scaleX = clearColor.scaleX || dpr;
  38647. clearColor.scaleY = clearColor.scaleY || dpr;
  38648. clearColorGradientOrPattern = createCanvasPattern(ctx, clearColor, {
  38649. dirty: function () {
  38650. self.setUnpainted();
  38651. self.painter.refresh();
  38652. }
  38653. });
  38654. }
  38655. ctx.save();
  38656. ctx.fillStyle = clearColorGradientOrPattern || clearColor;
  38657. ctx.fillRect(x, y, width, height);
  38658. ctx.restore();
  38659. }
  38660. if (haveMotionBLur) {
  38661. ctx.save();
  38662. ctx.globalAlpha = lastFrameAlpha;
  38663. ctx.drawImage(domBack, x, y, width, height);
  38664. ctx.restore();
  38665. }
  38666. }
  38667. if (!repaintRects || haveMotionBLur) {
  38668. doClear(0, 0, width, height);
  38669. }
  38670. else if (repaintRects.length) {
  38671. each(repaintRects, function (rect) {
  38672. doClear(rect.x * dpr, rect.y * dpr, rect.width * dpr, rect.height * dpr);
  38673. });
  38674. }
  38675. };
  38676. return Layer;
  38677. }(Eventful));
  38678. var HOVER_LAYER_ZLEVEL = 1e5;
  38679. var CANVAS_ZLEVEL = 314159;
  38680. var EL_AFTER_INCREMENTAL_INC = 0.01;
  38681. var INCREMENTAL_INC = 0.001;
  38682. function isLayerValid(layer) {
  38683. if (!layer) {
  38684. return false;
  38685. }
  38686. if (layer.__builtin__) {
  38687. return true;
  38688. }
  38689. if (typeof (layer.resize) !== 'function'
  38690. || typeof (layer.refresh) !== 'function') {
  38691. return false;
  38692. }
  38693. return true;
  38694. }
  38695. function createRoot(width, height) {
  38696. var domRoot = document.createElement('div');
  38697. domRoot.style.cssText = [
  38698. 'position:relative',
  38699. 'width:' + width + 'px',
  38700. 'height:' + height + 'px',
  38701. 'padding:0',
  38702. 'margin:0',
  38703. 'border-width:0'
  38704. ].join(';') + ';';
  38705. return domRoot;
  38706. }
  38707. var CanvasPainter = (function () {
  38708. function CanvasPainter(root, storage, opts, id) {
  38709. this.type = 'canvas';
  38710. this._zlevelList = [];
  38711. this._prevDisplayList = [];
  38712. this._layers = {};
  38713. this._layerConfig = {};
  38714. this._needsManuallyCompositing = false;
  38715. this.type = 'canvas';
  38716. var singleCanvas = !root.nodeName
  38717. || root.nodeName.toUpperCase() === 'CANVAS';
  38718. this._opts = opts = extend({}, opts || {});
  38719. this.dpr = opts.devicePixelRatio || devicePixelRatio;
  38720. this._singleCanvas = singleCanvas;
  38721. this.root = root;
  38722. var rootStyle = root.style;
  38723. if (rootStyle) {
  38724. disableUserSelect(root);
  38725. root.innerHTML = '';
  38726. }
  38727. this.storage = storage;
  38728. var zlevelList = this._zlevelList;
  38729. this._prevDisplayList = [];
  38730. var layers = this._layers;
  38731. if (!singleCanvas) {
  38732. this._width = getSize(root, 0, opts);
  38733. this._height = getSize(root, 1, opts);
  38734. var domRoot = this._domRoot = createRoot(this._width, this._height);
  38735. root.appendChild(domRoot);
  38736. }
  38737. else {
  38738. var rootCanvas = root;
  38739. var width = rootCanvas.width;
  38740. var height = rootCanvas.height;
  38741. if (opts.width != null) {
  38742. width = opts.width;
  38743. }
  38744. if (opts.height != null) {
  38745. height = opts.height;
  38746. }
  38747. this.dpr = opts.devicePixelRatio || 1;
  38748. rootCanvas.width = width * this.dpr;
  38749. rootCanvas.height = height * this.dpr;
  38750. this._width = width;
  38751. this._height = height;
  38752. var mainLayer = new Layer(rootCanvas, this, this.dpr);
  38753. mainLayer.__builtin__ = true;
  38754. mainLayer.initContext();
  38755. layers[CANVAS_ZLEVEL] = mainLayer;
  38756. mainLayer.zlevel = CANVAS_ZLEVEL;
  38757. zlevelList.push(CANVAS_ZLEVEL);
  38758. this._domRoot = root;
  38759. }
  38760. }
  38761. CanvasPainter.prototype.getType = function () {
  38762. return 'canvas';
  38763. };
  38764. CanvasPainter.prototype.isSingleCanvas = function () {
  38765. return this._singleCanvas;
  38766. };
  38767. CanvasPainter.prototype.getViewportRoot = function () {
  38768. return this._domRoot;
  38769. };
  38770. CanvasPainter.prototype.getViewportRootOffset = function () {
  38771. var viewportRoot = this.getViewportRoot();
  38772. if (viewportRoot) {
  38773. return {
  38774. offsetLeft: viewportRoot.offsetLeft || 0,
  38775. offsetTop: viewportRoot.offsetTop || 0
  38776. };
  38777. }
  38778. };
  38779. CanvasPainter.prototype.refresh = function (paintAll) {
  38780. var list = this.storage.getDisplayList(true);
  38781. var prevList = this._prevDisplayList;
  38782. var zlevelList = this._zlevelList;
  38783. this._redrawId = Math.random();
  38784. this._paintList(list, prevList, paintAll, this._redrawId);
  38785. for (var i = 0; i < zlevelList.length; i++) {
  38786. var z = zlevelList[i];
  38787. var layer = this._layers[z];
  38788. if (!layer.__builtin__ && layer.refresh) {
  38789. var clearColor = i === 0 ? this._backgroundColor : null;
  38790. layer.refresh(clearColor);
  38791. }
  38792. }
  38793. if (this._opts.useDirtyRect) {
  38794. this._prevDisplayList = list.slice();
  38795. }
  38796. return this;
  38797. };
  38798. CanvasPainter.prototype.refreshHover = function () {
  38799. this._paintHoverList(this.storage.getDisplayList(false));
  38800. };
  38801. CanvasPainter.prototype._paintHoverList = function (list) {
  38802. var len = list.length;
  38803. var hoverLayer = this._hoverlayer;
  38804. hoverLayer && hoverLayer.clear();
  38805. if (!len) {
  38806. return;
  38807. }
  38808. var scope = {
  38809. inHover: true,
  38810. viewWidth: this._width,
  38811. viewHeight: this._height
  38812. };
  38813. var ctx;
  38814. for (var i = 0; i < len; i++) {
  38815. var el = list[i];
  38816. if (el.__inHover) {
  38817. if (!hoverLayer) {
  38818. hoverLayer = this._hoverlayer = this.getLayer(HOVER_LAYER_ZLEVEL);
  38819. }
  38820. if (!ctx) {
  38821. ctx = hoverLayer.ctx;
  38822. ctx.save();
  38823. }
  38824. brush(ctx, el, scope, i === len - 1);
  38825. }
  38826. }
  38827. if (ctx) {
  38828. ctx.restore();
  38829. }
  38830. };
  38831. CanvasPainter.prototype.getHoverLayer = function () {
  38832. return this.getLayer(HOVER_LAYER_ZLEVEL);
  38833. };
  38834. CanvasPainter.prototype.paintOne = function (ctx, el) {
  38835. brushSingle(ctx, el);
  38836. };
  38837. CanvasPainter.prototype._paintList = function (list, prevList, paintAll, redrawId) {
  38838. if (this._redrawId !== redrawId) {
  38839. return;
  38840. }
  38841. paintAll = paintAll || false;
  38842. this._updateLayerStatus(list);
  38843. var _a = this._doPaintList(list, prevList, paintAll), finished = _a.finished, needsRefreshHover = _a.needsRefreshHover;
  38844. if (this._needsManuallyCompositing) {
  38845. this._compositeManually();
  38846. }
  38847. if (needsRefreshHover) {
  38848. this._paintHoverList(list);
  38849. }
  38850. if (!finished) {
  38851. var self_1 = this;
  38852. requestAnimationFrame$1(function () {
  38853. self_1._paintList(list, prevList, paintAll, redrawId);
  38854. });
  38855. }
  38856. else {
  38857. this.eachLayer(function (layer) {
  38858. layer.afterBrush && layer.afterBrush();
  38859. });
  38860. }
  38861. };
  38862. CanvasPainter.prototype._compositeManually = function () {
  38863. var ctx = this.getLayer(CANVAS_ZLEVEL).ctx;
  38864. var width = this._domRoot.width;
  38865. var height = this._domRoot.height;
  38866. ctx.clearRect(0, 0, width, height);
  38867. this.eachBuiltinLayer(function (layer) {
  38868. if (layer.virtual) {
  38869. ctx.drawImage(layer.dom, 0, 0, width, height);
  38870. }
  38871. });
  38872. };
  38873. CanvasPainter.prototype._doPaintList = function (list, prevList, paintAll) {
  38874. var _this = this;
  38875. var layerList = [];
  38876. var useDirtyRect = this._opts.useDirtyRect;
  38877. for (var zi = 0; zi < this._zlevelList.length; zi++) {
  38878. var zlevel = this._zlevelList[zi];
  38879. var layer = this._layers[zlevel];
  38880. if (layer.__builtin__
  38881. && layer !== this._hoverlayer
  38882. && (layer.__dirty || paintAll)) {
  38883. layerList.push(layer);
  38884. }
  38885. }
  38886. var finished = true;
  38887. var needsRefreshHover = false;
  38888. var _loop_1 = function (k) {
  38889. var layer = layerList[k];
  38890. var ctx = layer.ctx;
  38891. var repaintRects = useDirtyRect
  38892. && layer.createRepaintRects(list, prevList, this_1._width, this_1._height);
  38893. var start = paintAll ? layer.__startIndex : layer.__drawIndex;
  38894. var useTimer = !paintAll && layer.incremental && Date.now;
  38895. var startTime = useTimer && Date.now();
  38896. var clearColor = layer.zlevel === this_1._zlevelList[0]
  38897. ? this_1._backgroundColor : null;
  38898. if (layer.__startIndex === layer.__endIndex) {
  38899. layer.clear(false, clearColor, repaintRects);
  38900. }
  38901. else if (start === layer.__startIndex) {
  38902. var firstEl = list[start];
  38903. if (!firstEl.incremental || !firstEl.notClear || paintAll) {
  38904. layer.clear(false, clearColor, repaintRects);
  38905. }
  38906. }
  38907. if (start === -1) {
  38908. console.error('For some unknown reason. drawIndex is -1');
  38909. start = layer.__startIndex;
  38910. }
  38911. var i;
  38912. var repaint = function (repaintRect) {
  38913. var scope = {
  38914. inHover: false,
  38915. allClipped: false,
  38916. prevEl: null,
  38917. viewWidth: _this._width,
  38918. viewHeight: _this._height
  38919. };
  38920. for (i = start; i < layer.__endIndex; i++) {
  38921. var el = list[i];
  38922. if (el.__inHover) {
  38923. needsRefreshHover = true;
  38924. }
  38925. _this._doPaintEl(el, layer, useDirtyRect, repaintRect, scope, i === layer.__endIndex - 1);
  38926. if (useTimer) {
  38927. var dTime = Date.now() - startTime;
  38928. if (dTime > 15) {
  38929. break;
  38930. }
  38931. }
  38932. }
  38933. if (scope.prevElClipPaths) {
  38934. ctx.restore();
  38935. }
  38936. };
  38937. if (repaintRects) {
  38938. if (repaintRects.length === 0) {
  38939. i = layer.__endIndex;
  38940. }
  38941. else {
  38942. var dpr = this_1.dpr;
  38943. for (var r = 0; r < repaintRects.length; ++r) {
  38944. var rect = repaintRects[r];
  38945. ctx.save();
  38946. ctx.beginPath();
  38947. ctx.rect(rect.x * dpr, rect.y * dpr, rect.width * dpr, rect.height * dpr);
  38948. ctx.clip();
  38949. repaint(rect);
  38950. ctx.restore();
  38951. }
  38952. }
  38953. }
  38954. else {
  38955. ctx.save();
  38956. repaint();
  38957. ctx.restore();
  38958. }
  38959. layer.__drawIndex = i;
  38960. if (layer.__drawIndex < layer.__endIndex) {
  38961. finished = false;
  38962. }
  38963. };
  38964. var this_1 = this;
  38965. for (var k = 0; k < layerList.length; k++) {
  38966. _loop_1(k);
  38967. }
  38968. if (env.wxa) {
  38969. each(this._layers, function (layer) {
  38970. if (layer && layer.ctx && layer.ctx.draw) {
  38971. layer.ctx.draw();
  38972. }
  38973. });
  38974. }
  38975. return {
  38976. finished: finished,
  38977. needsRefreshHover: needsRefreshHover
  38978. };
  38979. };
  38980. CanvasPainter.prototype._doPaintEl = function (el, currentLayer, useDirtyRect, repaintRect, scope, isLast) {
  38981. var ctx = currentLayer.ctx;
  38982. if (useDirtyRect) {
  38983. var paintRect = el.getPaintRect();
  38984. if (!repaintRect || paintRect && paintRect.intersect(repaintRect)) {
  38985. brush(ctx, el, scope, isLast);
  38986. el.setPrevPaintRect(paintRect);
  38987. }
  38988. }
  38989. else {
  38990. brush(ctx, el, scope, isLast);
  38991. }
  38992. };
  38993. CanvasPainter.prototype.getLayer = function (zlevel, virtual) {
  38994. if (this._singleCanvas && !this._needsManuallyCompositing) {
  38995. zlevel = CANVAS_ZLEVEL;
  38996. }
  38997. var layer = this._layers[zlevel];
  38998. if (!layer) {
  38999. layer = new Layer('zr_' + zlevel, this, this.dpr);
  39000. layer.zlevel = zlevel;
  39001. layer.__builtin__ = true;
  39002. if (this._layerConfig[zlevel]) {
  39003. merge(layer, this._layerConfig[zlevel], true);
  39004. }
  39005. else if (this._layerConfig[zlevel - EL_AFTER_INCREMENTAL_INC]) {
  39006. merge(layer, this._layerConfig[zlevel - EL_AFTER_INCREMENTAL_INC], true);
  39007. }
  39008. if (virtual) {
  39009. layer.virtual = virtual;
  39010. }
  39011. this.insertLayer(zlevel, layer);
  39012. layer.initContext();
  39013. }
  39014. return layer;
  39015. };
  39016. CanvasPainter.prototype.insertLayer = function (zlevel, layer) {
  39017. var layersMap = this._layers;
  39018. var zlevelList = this._zlevelList;
  39019. var len = zlevelList.length;
  39020. var domRoot = this._domRoot;
  39021. var prevLayer = null;
  39022. var i = -1;
  39023. if (layersMap[zlevel]) {
  39024. if ("development" !== 'production') {
  39025. logError('ZLevel ' + zlevel + ' has been used already');
  39026. }
  39027. return;
  39028. }
  39029. if (!isLayerValid(layer)) {
  39030. if ("development" !== 'production') {
  39031. logError('Layer of zlevel ' + zlevel + ' is not valid');
  39032. }
  39033. return;
  39034. }
  39035. if (len > 0 && zlevel > zlevelList[0]) {
  39036. for (i = 0; i < len - 1; i++) {
  39037. if (zlevelList[i] < zlevel
  39038. && zlevelList[i + 1] > zlevel) {
  39039. break;
  39040. }
  39041. }
  39042. prevLayer = layersMap[zlevelList[i]];
  39043. }
  39044. zlevelList.splice(i + 1, 0, zlevel);
  39045. layersMap[zlevel] = layer;
  39046. if (!layer.virtual) {
  39047. if (prevLayer) {
  39048. var prevDom = prevLayer.dom;
  39049. if (prevDom.nextSibling) {
  39050. domRoot.insertBefore(layer.dom, prevDom.nextSibling);
  39051. }
  39052. else {
  39053. domRoot.appendChild(layer.dom);
  39054. }
  39055. }
  39056. else {
  39057. if (domRoot.firstChild) {
  39058. domRoot.insertBefore(layer.dom, domRoot.firstChild);
  39059. }
  39060. else {
  39061. domRoot.appendChild(layer.dom);
  39062. }
  39063. }
  39064. }
  39065. layer.painter || (layer.painter = this);
  39066. };
  39067. CanvasPainter.prototype.eachLayer = function (cb, context) {
  39068. var zlevelList = this._zlevelList;
  39069. for (var i = 0; i < zlevelList.length; i++) {
  39070. var z = zlevelList[i];
  39071. cb.call(context, this._layers[z], z);
  39072. }
  39073. };
  39074. CanvasPainter.prototype.eachBuiltinLayer = function (cb, context) {
  39075. var zlevelList = this._zlevelList;
  39076. for (var i = 0; i < zlevelList.length; i++) {
  39077. var z = zlevelList[i];
  39078. var layer = this._layers[z];
  39079. if (layer.__builtin__) {
  39080. cb.call(context, layer, z);
  39081. }
  39082. }
  39083. };
  39084. CanvasPainter.prototype.eachOtherLayer = function (cb, context) {
  39085. var zlevelList = this._zlevelList;
  39086. for (var i = 0; i < zlevelList.length; i++) {
  39087. var z = zlevelList[i];
  39088. var layer = this._layers[z];
  39089. if (!layer.__builtin__) {
  39090. cb.call(context, layer, z);
  39091. }
  39092. }
  39093. };
  39094. CanvasPainter.prototype.getLayers = function () {
  39095. return this._layers;
  39096. };
  39097. CanvasPainter.prototype._updateLayerStatus = function (list) {
  39098. this.eachBuiltinLayer(function (layer, z) {
  39099. layer.__dirty = layer.__used = false;
  39100. });
  39101. function updatePrevLayer(idx) {
  39102. if (prevLayer) {
  39103. if (prevLayer.__endIndex !== idx) {
  39104. prevLayer.__dirty = true;
  39105. }
  39106. prevLayer.__endIndex = idx;
  39107. }
  39108. }
  39109. if (this._singleCanvas) {
  39110. for (var i_1 = 1; i_1 < list.length; i_1++) {
  39111. var el = list[i_1];
  39112. if (el.zlevel !== list[i_1 - 1].zlevel || el.incremental) {
  39113. this._needsManuallyCompositing = true;
  39114. break;
  39115. }
  39116. }
  39117. }
  39118. var prevLayer = null;
  39119. var incrementalLayerCount = 0;
  39120. var prevZlevel;
  39121. var i;
  39122. for (i = 0; i < list.length; i++) {
  39123. var el = list[i];
  39124. var zlevel = el.zlevel;
  39125. var layer = void 0;
  39126. if (prevZlevel !== zlevel) {
  39127. prevZlevel = zlevel;
  39128. incrementalLayerCount = 0;
  39129. }
  39130. if (el.incremental) {
  39131. layer = this.getLayer(zlevel + INCREMENTAL_INC, this._needsManuallyCompositing);
  39132. layer.incremental = true;
  39133. incrementalLayerCount = 1;
  39134. }
  39135. else {
  39136. layer = this.getLayer(zlevel + (incrementalLayerCount > 0 ? EL_AFTER_INCREMENTAL_INC : 0), this._needsManuallyCompositing);
  39137. }
  39138. if (!layer.__builtin__) {
  39139. logError('ZLevel ' + zlevel + ' has been used by unkown layer ' + layer.id);
  39140. }
  39141. if (layer !== prevLayer) {
  39142. layer.__used = true;
  39143. if (layer.__startIndex !== i) {
  39144. layer.__dirty = true;
  39145. }
  39146. layer.__startIndex = i;
  39147. if (!layer.incremental) {
  39148. layer.__drawIndex = i;
  39149. }
  39150. else {
  39151. layer.__drawIndex = -1;
  39152. }
  39153. updatePrevLayer(i);
  39154. prevLayer = layer;
  39155. }
  39156. if ((el.__dirty & REDRAW_BIT) && !el.__inHover) {
  39157. layer.__dirty = true;
  39158. if (layer.incremental && layer.__drawIndex < 0) {
  39159. layer.__drawIndex = i;
  39160. }
  39161. }
  39162. }
  39163. updatePrevLayer(i);
  39164. this.eachBuiltinLayer(function (layer, z) {
  39165. if (!layer.__used && layer.getElementCount() > 0) {
  39166. layer.__dirty = true;
  39167. layer.__startIndex = layer.__endIndex = layer.__drawIndex = 0;
  39168. }
  39169. if (layer.__dirty && layer.__drawIndex < 0) {
  39170. layer.__drawIndex = layer.__startIndex;
  39171. }
  39172. });
  39173. };
  39174. CanvasPainter.prototype.clear = function () {
  39175. this.eachBuiltinLayer(this._clearLayer);
  39176. return this;
  39177. };
  39178. CanvasPainter.prototype._clearLayer = function (layer) {
  39179. layer.clear();
  39180. };
  39181. CanvasPainter.prototype.setBackgroundColor = function (backgroundColor) {
  39182. this._backgroundColor = backgroundColor;
  39183. each(this._layers, function (layer) {
  39184. layer.setUnpainted();
  39185. });
  39186. };
  39187. CanvasPainter.prototype.configLayer = function (zlevel, config) {
  39188. if (config) {
  39189. var layerConfig = this._layerConfig;
  39190. if (!layerConfig[zlevel]) {
  39191. layerConfig[zlevel] = config;
  39192. }
  39193. else {
  39194. merge(layerConfig[zlevel], config, true);
  39195. }
  39196. for (var i = 0; i < this._zlevelList.length; i++) {
  39197. var _zlevel = this._zlevelList[i];
  39198. if (_zlevel === zlevel || _zlevel === zlevel + EL_AFTER_INCREMENTAL_INC) {
  39199. var layer = this._layers[_zlevel];
  39200. merge(layer, layerConfig[zlevel], true);
  39201. }
  39202. }
  39203. }
  39204. };
  39205. CanvasPainter.prototype.delLayer = function (zlevel) {
  39206. var layers = this._layers;
  39207. var zlevelList = this._zlevelList;
  39208. var layer = layers[zlevel];
  39209. if (!layer) {
  39210. return;
  39211. }
  39212. layer.dom.parentNode.removeChild(layer.dom);
  39213. delete layers[zlevel];
  39214. zlevelList.splice(indexOf(zlevelList, zlevel), 1);
  39215. };
  39216. CanvasPainter.prototype.resize = function (width, height) {
  39217. if (!this._domRoot.style) {
  39218. if (width == null || height == null) {
  39219. return;
  39220. }
  39221. this._width = width;
  39222. this._height = height;
  39223. this.getLayer(CANVAS_ZLEVEL).resize(width, height);
  39224. }
  39225. else {
  39226. var domRoot = this._domRoot;
  39227. domRoot.style.display = 'none';
  39228. var opts = this._opts;
  39229. var root = this.root;
  39230. width != null && (opts.width = width);
  39231. height != null && (opts.height = height);
  39232. width = getSize(root, 0, opts);
  39233. height = getSize(root, 1, opts);
  39234. domRoot.style.display = '';
  39235. if (this._width !== width || height !== this._height) {
  39236. domRoot.style.width = width + 'px';
  39237. domRoot.style.height = height + 'px';
  39238. for (var id in this._layers) {
  39239. if (this._layers.hasOwnProperty(id)) {
  39240. this._layers[id].resize(width, height);
  39241. }
  39242. }
  39243. this.refresh(true);
  39244. }
  39245. this._width = width;
  39246. this._height = height;
  39247. }
  39248. return this;
  39249. };
  39250. CanvasPainter.prototype.clearLayer = function (zlevel) {
  39251. var layer = this._layers[zlevel];
  39252. if (layer) {
  39253. layer.clear();
  39254. }
  39255. };
  39256. CanvasPainter.prototype.dispose = function () {
  39257. this.root.innerHTML = '';
  39258. this.root =
  39259. this.storage =
  39260. this._domRoot =
  39261. this._layers = null;
  39262. };
  39263. CanvasPainter.prototype.getRenderedCanvas = function (opts) {
  39264. opts = opts || {};
  39265. if (this._singleCanvas && !this._compositeManually) {
  39266. return this._layers[CANVAS_ZLEVEL].dom;
  39267. }
  39268. var imageLayer = new Layer('image', this, opts.pixelRatio || this.dpr);
  39269. imageLayer.initContext();
  39270. imageLayer.clear(false, opts.backgroundColor || this._backgroundColor);
  39271. var ctx = imageLayer.ctx;
  39272. if (opts.pixelRatio <= this.dpr) {
  39273. this.refresh();
  39274. var width_1 = imageLayer.dom.width;
  39275. var height_1 = imageLayer.dom.height;
  39276. this.eachLayer(function (layer) {
  39277. if (layer.__builtin__) {
  39278. ctx.drawImage(layer.dom, 0, 0, width_1, height_1);
  39279. }
  39280. else if (layer.renderToCanvas) {
  39281. ctx.save();
  39282. layer.renderToCanvas(ctx);
  39283. ctx.restore();
  39284. }
  39285. });
  39286. }
  39287. else {
  39288. var scope = {
  39289. inHover: false,
  39290. viewWidth: this._width,
  39291. viewHeight: this._height
  39292. };
  39293. var displayList = this.storage.getDisplayList(true);
  39294. for (var i = 0, len = displayList.length; i < len; i++) {
  39295. var el = displayList[i];
  39296. brush(ctx, el, scope, i === len - 1);
  39297. }
  39298. }
  39299. return imageLayer.dom;
  39300. };
  39301. CanvasPainter.prototype.getWidth = function () {
  39302. return this._width;
  39303. };
  39304. CanvasPainter.prototype.getHeight = function () {
  39305. return this._height;
  39306. };
  39307. return CanvasPainter;
  39308. }());
  39309. function install$1(registers) {
  39310. registers.registerPainter('canvas', CanvasPainter);
  39311. }
  39312. var LineSeriesModel = /** @class */function (_super) {
  39313. __extends(LineSeriesModel, _super);
  39314. function LineSeriesModel() {
  39315. var _this = _super !== null && _super.apply(this, arguments) || this;
  39316. _this.type = LineSeriesModel.type;
  39317. _this.hasSymbolVisual = true;
  39318. return _this;
  39319. }
  39320. LineSeriesModel.prototype.getInitialData = function (option) {
  39321. if ("development" !== 'production') {
  39322. var coordSys = option.coordinateSystem;
  39323. if (coordSys !== 'polar' && coordSys !== 'cartesian2d') {
  39324. throw new Error('Line not support coordinateSystem besides cartesian and polar');
  39325. }
  39326. }
  39327. return createSeriesData(null, this, {
  39328. useEncodeDefaulter: true
  39329. });
  39330. };
  39331. LineSeriesModel.prototype.getLegendIcon = function (opt) {
  39332. var group = new Group();
  39333. var line = createSymbol('line', 0, opt.itemHeight / 2, opt.itemWidth, 0, opt.lineStyle.stroke, false);
  39334. group.add(line);
  39335. line.setStyle(opt.lineStyle);
  39336. var visualType = this.getData().getVisual('symbol');
  39337. var visualRotate = this.getData().getVisual('symbolRotate');
  39338. var symbolType = visualType === 'none' ? 'circle' : visualType;
  39339. // Symbol size is 80% when there is a line
  39340. var size = opt.itemHeight * 0.8;
  39341. var symbol = createSymbol(symbolType, (opt.itemWidth - size) / 2, (opt.itemHeight - size) / 2, size, size, opt.itemStyle.fill);
  39342. group.add(symbol);
  39343. symbol.setStyle(opt.itemStyle);
  39344. var symbolRotate = opt.iconRotate === 'inherit' ? visualRotate : opt.iconRotate || 0;
  39345. symbol.rotation = symbolRotate * Math.PI / 180;
  39346. symbol.setOrigin([opt.itemWidth / 2, opt.itemHeight / 2]);
  39347. if (symbolType.indexOf('empty') > -1) {
  39348. symbol.style.stroke = symbol.style.fill;
  39349. symbol.style.fill = tokens.color.neutral00;
  39350. symbol.style.lineWidth = 2;
  39351. }
  39352. return group;
  39353. };
  39354. LineSeriesModel.type = 'series.line';
  39355. LineSeriesModel.dependencies = ['grid', 'polar'];
  39356. LineSeriesModel.defaultOption = {
  39357. // zlevel: 0,
  39358. z: 3,
  39359. coordinateSystem: 'cartesian2d',
  39360. legendHoverLink: true,
  39361. clip: true,
  39362. label: {
  39363. position: 'top'
  39364. },
  39365. // itemStyle: {
  39366. // },
  39367. endLabel: {
  39368. show: false,
  39369. valueAnimation: true,
  39370. distance: 8
  39371. },
  39372. lineStyle: {
  39373. width: 2,
  39374. type: 'solid'
  39375. },
  39376. emphasis: {
  39377. scale: true
  39378. },
  39379. // areaStyle: {
  39380. // origin of areaStyle. Valid values:
  39381. // `'auto'/null/undefined`: from axisLine to data
  39382. // `'start'`: from min to data
  39383. // `'end'`: from data to max
  39384. // origin: 'auto'
  39385. // },
  39386. // false, 'start', 'end', 'middle'
  39387. step: false,
  39388. // Disabled if step is true
  39389. smooth: false,
  39390. smoothMonotone: null,
  39391. symbol: 'emptyCircle',
  39392. symbolSize: 6,
  39393. symbolRotate: null,
  39394. showSymbol: true,
  39395. // `false`: follow the label interval strategy.
  39396. // `true`: show all symbols.
  39397. // `'auto'`: If possible, show all symbols, otherwise
  39398. // follow the label interval strategy.
  39399. showAllSymbol: 'auto',
  39400. // Whether to connect break point.
  39401. connectNulls: false,
  39402. // Sampling for large data. Can be: 'average', 'max', 'min', 'sum', 'lttb'.
  39403. sampling: 'none',
  39404. animationEasing: 'linear',
  39405. // Disable progressive
  39406. progressive: 0,
  39407. hoverLayerThreshold: Infinity,
  39408. universalTransition: {
  39409. divideShape: 'clone'
  39410. },
  39411. triggerLineEvent: false
  39412. };
  39413. return LineSeriesModel;
  39414. }(SeriesModel);
  39415. /**
  39416. * @return label string. Not null/undefined
  39417. */
  39418. function getDefaultLabel(data, dataIndex) {
  39419. var labelDims = data.mapDimensionsAll('defaultedLabel');
  39420. var len = labelDims.length;
  39421. // Simple optimization (in lots of cases, label dims length is 1)
  39422. if (len === 1) {
  39423. var rawVal = retrieveRawValue(data, dataIndex, labelDims[0]);
  39424. return rawVal != null ? rawVal + '' : null;
  39425. } else if (len) {
  39426. var vals = [];
  39427. for (var i = 0; i < labelDims.length; i++) {
  39428. vals.push(retrieveRawValue(data, dataIndex, labelDims[i]));
  39429. }
  39430. return vals.join(' ');
  39431. }
  39432. }
  39433. function getDefaultInterpolatedLabel(data, interpolatedValue) {
  39434. var labelDims = data.mapDimensionsAll('defaultedLabel');
  39435. if (!isArray(interpolatedValue)) {
  39436. return interpolatedValue + '';
  39437. }
  39438. var vals = [];
  39439. for (var i = 0; i < labelDims.length; i++) {
  39440. var dimIndex = data.getDimensionIndex(labelDims[i]);
  39441. if (dimIndex >= 0) {
  39442. vals.push(interpolatedValue[dimIndex]);
  39443. }
  39444. }
  39445. return vals.join(' ');
  39446. }
  39447. var Symbol = /** @class */function (_super) {
  39448. __extends(Symbol, _super);
  39449. function Symbol(data, idx, seriesScope, opts) {
  39450. var _this = _super.call(this) || this;
  39451. _this.updateData(data, idx, seriesScope, opts);
  39452. return _this;
  39453. }
  39454. Symbol.prototype._createSymbol = function (symbolType, data, idx, symbolSize, z2, keepAspect) {
  39455. // Remove paths created before
  39456. this.removeAll();
  39457. // let symbolPath = createSymbol(
  39458. // symbolType, -0.5, -0.5, 1, 1, color
  39459. // );
  39460. // If width/height are set too small (e.g., set to 1) on ios10
  39461. // and macOS Sierra, a circle stroke become a rect, no matter what
  39462. // the scale is set. So we set width/height as 2. See #4150.
  39463. var symbolPath = createSymbol(symbolType, -1, -1, 2, 2, null, keepAspect);
  39464. symbolPath.attr({
  39465. z2: retrieve2(z2, 100),
  39466. culling: true,
  39467. scaleX: symbolSize[0] / 2,
  39468. scaleY: symbolSize[1] / 2
  39469. });
  39470. // Rewrite drift method
  39471. symbolPath.drift = driftSymbol;
  39472. this._symbolType = symbolType;
  39473. this.add(symbolPath);
  39474. };
  39475. /**
  39476. * Stop animation
  39477. * @param {boolean} toLastFrame
  39478. */
  39479. Symbol.prototype.stopSymbolAnimation = function (toLastFrame) {
  39480. this.childAt(0).stopAnimation(null, toLastFrame);
  39481. };
  39482. Symbol.prototype.getSymbolType = function () {
  39483. return this._symbolType;
  39484. };
  39485. /**
  39486. * FIXME:
  39487. * Caution: This method breaks the encapsulation of this module,
  39488. * but it indeed brings convenience. So do not use the method
  39489. * unless you detailedly know all the implements of `Symbol`,
  39490. * especially animation.
  39491. *
  39492. * Get symbol path element.
  39493. */
  39494. Symbol.prototype.getSymbolPath = function () {
  39495. return this.childAt(0);
  39496. };
  39497. /**
  39498. * Highlight symbol
  39499. */
  39500. Symbol.prototype.highlight = function () {
  39501. enterEmphasis(this.childAt(0));
  39502. };
  39503. /**
  39504. * Downplay symbol
  39505. */
  39506. Symbol.prototype.downplay = function () {
  39507. leaveEmphasis(this.childAt(0));
  39508. };
  39509. /**
  39510. * @param {number} zlevel
  39511. * @param {number} z
  39512. */
  39513. Symbol.prototype.setZ = function (zlevel, z) {
  39514. var symbolPath = this.childAt(0);
  39515. symbolPath.zlevel = zlevel;
  39516. symbolPath.z = z;
  39517. };
  39518. Symbol.prototype.setDraggable = function (draggable, hasCursorOption) {
  39519. var symbolPath = this.childAt(0);
  39520. symbolPath.draggable = draggable;
  39521. symbolPath.cursor = !hasCursorOption && draggable ? 'move' : symbolPath.cursor;
  39522. };
  39523. /**
  39524. * Update symbol properties
  39525. */
  39526. Symbol.prototype.updateData = function (data, idx, seriesScope, opts) {
  39527. this.silent = false;
  39528. var symbolType = data.getItemVisual(idx, 'symbol') || 'circle';
  39529. var seriesModel = data.hostModel;
  39530. var symbolSize = Symbol.getSymbolSize(data, idx);
  39531. var z2 = Symbol.getSymbolZ2(data, idx);
  39532. var isInit = symbolType !== this._symbolType;
  39533. var disableAnimation = opts && opts.disableAnimation;
  39534. if (isInit) {
  39535. var keepAspect = data.getItemVisual(idx, 'symbolKeepAspect');
  39536. this._createSymbol(symbolType, data, idx, symbolSize, z2, keepAspect);
  39537. } else {
  39538. var symbolPath = this.childAt(0);
  39539. symbolPath.silent = false;
  39540. var target = {
  39541. scaleX: symbolSize[0] / 2,
  39542. scaleY: symbolSize[1] / 2
  39543. };
  39544. disableAnimation ? symbolPath.attr(target) : updateProps(symbolPath, target, seriesModel, idx);
  39545. saveOldStyle(symbolPath);
  39546. }
  39547. this._updateCommon(data, idx, symbolSize, seriesScope, opts);
  39548. if (isInit) {
  39549. var symbolPath = this.childAt(0);
  39550. if (!disableAnimation) {
  39551. var target = {
  39552. scaleX: this._sizeX,
  39553. scaleY: this._sizeY,
  39554. style: {
  39555. // Always fadeIn. Because it has fadeOut animation when symbol is removed..
  39556. opacity: symbolPath.style.opacity
  39557. }
  39558. };
  39559. symbolPath.scaleX = symbolPath.scaleY = 0;
  39560. symbolPath.style.opacity = 0;
  39561. initProps(symbolPath, target, seriesModel, idx);
  39562. }
  39563. }
  39564. if (disableAnimation) {
  39565. // Must stop leave transition manually if don't call initProps or updateProps.
  39566. this.childAt(0).stopAnimation('leave');
  39567. }
  39568. };
  39569. Symbol.prototype._updateCommon = function (data, idx, symbolSize, seriesScope, opts) {
  39570. var symbolPath = this.childAt(0);
  39571. var seriesModel = data.hostModel;
  39572. var emphasisItemStyle;
  39573. var blurItemStyle;
  39574. var selectItemStyle;
  39575. var focus;
  39576. var blurScope;
  39577. var emphasisDisabled;
  39578. var labelStatesModels;
  39579. var hoverScale;
  39580. var cursorStyle;
  39581. if (seriesScope) {
  39582. emphasisItemStyle = seriesScope.emphasisItemStyle;
  39583. blurItemStyle = seriesScope.blurItemStyle;
  39584. selectItemStyle = seriesScope.selectItemStyle;
  39585. focus = seriesScope.focus;
  39586. blurScope = seriesScope.blurScope;
  39587. labelStatesModels = seriesScope.labelStatesModels;
  39588. hoverScale = seriesScope.hoverScale;
  39589. cursorStyle = seriesScope.cursorStyle;
  39590. emphasisDisabled = seriesScope.emphasisDisabled;
  39591. }
  39592. if (!seriesScope || data.hasItemOption) {
  39593. var itemModel = seriesScope && seriesScope.itemModel ? seriesScope.itemModel : data.getItemModel(idx);
  39594. var emphasisModel = itemModel.getModel('emphasis');
  39595. emphasisItemStyle = emphasisModel.getModel('itemStyle').getItemStyle();
  39596. selectItemStyle = itemModel.getModel(['select', 'itemStyle']).getItemStyle();
  39597. blurItemStyle = itemModel.getModel(['blur', 'itemStyle']).getItemStyle();
  39598. focus = emphasisModel.get('focus');
  39599. blurScope = emphasisModel.get('blurScope');
  39600. emphasisDisabled = emphasisModel.get('disabled');
  39601. labelStatesModels = getLabelStatesModels(itemModel);
  39602. hoverScale = emphasisModel.getShallow('scale');
  39603. cursorStyle = itemModel.getShallow('cursor');
  39604. }
  39605. var symbolRotate = data.getItemVisual(idx, 'symbolRotate');
  39606. symbolPath.attr('rotation', (symbolRotate || 0) * Math.PI / 180 || 0);
  39607. var symbolOffset = normalizeSymbolOffset(data.getItemVisual(idx, 'symbolOffset'), symbolSize);
  39608. if (symbolOffset) {
  39609. symbolPath.x = symbolOffset[0];
  39610. symbolPath.y = symbolOffset[1];
  39611. }
  39612. cursorStyle && symbolPath.attr('cursor', cursorStyle);
  39613. var symbolStyle = data.getItemVisual(idx, 'style');
  39614. var visualColor = symbolStyle.fill;
  39615. if (symbolPath instanceof ZRImage) {
  39616. var pathStyle = symbolPath.style;
  39617. symbolPath.useStyle(extend({
  39618. // TODO other properties like x, y ?
  39619. image: pathStyle.image,
  39620. x: pathStyle.x,
  39621. y: pathStyle.y,
  39622. width: pathStyle.width,
  39623. height: pathStyle.height
  39624. }, symbolStyle));
  39625. } else {
  39626. if (symbolPath.__isEmptyBrush) {
  39627. // fill and stroke will be swapped if it's empty.
  39628. // So we cloned a new style to avoid it affecting the original style in visual storage.
  39629. // TODO Better implementation. No empty logic!
  39630. symbolPath.useStyle(extend({}, symbolStyle));
  39631. } else {
  39632. symbolPath.useStyle(symbolStyle);
  39633. }
  39634. // Disable decal because symbol scale will been applied on the decal.
  39635. symbolPath.style.decal = null;
  39636. symbolPath.setColor(visualColor, opts && opts.symbolInnerColor);
  39637. symbolPath.style.strokeNoScale = true;
  39638. }
  39639. var liftZ = data.getItemVisual(idx, 'liftZ');
  39640. var z2Origin = this._z2;
  39641. if (liftZ != null) {
  39642. if (z2Origin == null) {
  39643. this._z2 = symbolPath.z2;
  39644. symbolPath.z2 += liftZ;
  39645. }
  39646. } else if (z2Origin != null) {
  39647. symbolPath.z2 = z2Origin;
  39648. this._z2 = null;
  39649. }
  39650. var useNameLabel = opts && opts.useNameLabel;
  39651. setLabelStyle(symbolPath, labelStatesModels, {
  39652. labelFetcher: seriesModel,
  39653. labelDataIndex: idx,
  39654. defaultText: getLabelDefaultText,
  39655. inheritColor: visualColor,
  39656. defaultOpacity: symbolStyle.opacity
  39657. });
  39658. // Do not execute util needed.
  39659. function getLabelDefaultText(idx) {
  39660. return useNameLabel ? data.getName(idx) : getDefaultLabel(data, idx);
  39661. }
  39662. this._sizeX = symbolSize[0] / 2;
  39663. this._sizeY = symbolSize[1] / 2;
  39664. var emphasisState = symbolPath.ensureState('emphasis');
  39665. emphasisState.style = emphasisItemStyle;
  39666. symbolPath.ensureState('select').style = selectItemStyle;
  39667. symbolPath.ensureState('blur').style = blurItemStyle;
  39668. // null / undefined / true means to use default strategy.
  39669. // 0 / false / negative number / NaN / Infinity means no scale.
  39670. var scaleRatio = hoverScale == null || hoverScale === true ? Math.max(1.1, 3 / this._sizeY)
  39671. // PENDING: restrict hoverScale > 1? It seems unreasonable to scale down
  39672. : isFinite(hoverScale) && hoverScale > 0 ? +hoverScale : 1;
  39673. // always set scale to allow resetting
  39674. emphasisState.scaleX = this._sizeX * scaleRatio;
  39675. emphasisState.scaleY = this._sizeY * scaleRatio;
  39676. this.setSymbolScale(1);
  39677. toggleHoverEmphasis(this, focus, blurScope, emphasisDisabled);
  39678. };
  39679. Symbol.prototype.setSymbolScale = function (scale) {
  39680. this.scaleX = this.scaleY = scale;
  39681. };
  39682. Symbol.prototype.fadeOut = function (cb, seriesModel, opt) {
  39683. var symbolPath = this.childAt(0);
  39684. var dataIndex = getECData(this).dataIndex;
  39685. var animationOpt = opt && opt.animation;
  39686. // Avoid mistaken hover when fading out
  39687. this.silent = symbolPath.silent = true;
  39688. // Not show text when animating
  39689. if (opt && opt.fadeLabel) {
  39690. var textContent = symbolPath.getTextContent();
  39691. if (textContent) {
  39692. removeElement(textContent, {
  39693. style: {
  39694. opacity: 0
  39695. }
  39696. }, seriesModel, {
  39697. dataIndex: dataIndex,
  39698. removeOpt: animationOpt,
  39699. cb: function () {
  39700. symbolPath.removeTextContent();
  39701. }
  39702. });
  39703. }
  39704. } else {
  39705. symbolPath.removeTextContent();
  39706. }
  39707. removeElement(symbolPath, {
  39708. style: {
  39709. opacity: 0
  39710. },
  39711. scaleX: 0,
  39712. scaleY: 0
  39713. }, seriesModel, {
  39714. dataIndex: dataIndex,
  39715. cb: cb,
  39716. removeOpt: animationOpt
  39717. });
  39718. };
  39719. Symbol.getSymbolSize = function (data, idx) {
  39720. return normalizeSymbolSize(data.getItemVisual(idx, 'symbolSize'));
  39721. };
  39722. Symbol.getSymbolZ2 = function (data, idx) {
  39723. return data.getItemVisual(idx, 'z2');
  39724. };
  39725. return Symbol;
  39726. }(Group);
  39727. function driftSymbol(dx, dy) {
  39728. this.parent.drift(dx, dy);
  39729. }
  39730. function symbolNeedsDraw(data, point, idx, opt) {
  39731. return point && !isNaN(point[0]) && !isNaN(point[1]) && !(opt.isIgnore && opt.isIgnore(idx))
  39732. // We do not set clipShape on group, because it will cut part of
  39733. // the symbol element shape. We use the same clip shape here as
  39734. // the line clip.
  39735. && !(opt.clipShape && !opt.clipShape.contain(point[0], point[1])) && data.getItemVisual(idx, 'symbol') !== 'none';
  39736. }
  39737. function normalizeUpdateOpt(opt) {
  39738. if (opt != null && !isObject(opt)) {
  39739. opt = {
  39740. isIgnore: opt
  39741. };
  39742. }
  39743. return opt || {};
  39744. }
  39745. function makeSeriesScope(data) {
  39746. var seriesModel = data.hostModel;
  39747. var emphasisModel = seriesModel.getModel('emphasis');
  39748. return {
  39749. emphasisItemStyle: emphasisModel.getModel('itemStyle').getItemStyle(),
  39750. blurItemStyle: seriesModel.getModel(['blur', 'itemStyle']).getItemStyle(),
  39751. selectItemStyle: seriesModel.getModel(['select', 'itemStyle']).getItemStyle(),
  39752. focus: emphasisModel.get('focus'),
  39753. blurScope: emphasisModel.get('blurScope'),
  39754. emphasisDisabled: emphasisModel.get('disabled'),
  39755. hoverScale: emphasisModel.get('scale'),
  39756. labelStatesModels: getLabelStatesModels(seriesModel),
  39757. cursorStyle: seriesModel.get('cursor')
  39758. };
  39759. }
  39760. var SymbolDraw = /** @class */function () {
  39761. function SymbolDraw(SymbolCtor) {
  39762. this.group = new Group();
  39763. this._SymbolCtor = SymbolCtor || Symbol;
  39764. }
  39765. /**
  39766. * Update symbols draw by new data
  39767. */
  39768. SymbolDraw.prototype.updateData = function (data, opt) {
  39769. // Remove progressive els.
  39770. this._progressiveEls = null;
  39771. opt = normalizeUpdateOpt(opt);
  39772. var group = this.group;
  39773. var seriesModel = data.hostModel;
  39774. var oldData = this._data;
  39775. var SymbolCtor = this._SymbolCtor;
  39776. var disableAnimation = opt.disableAnimation;
  39777. var seriesScope = makeSeriesScope(data);
  39778. var symbolUpdateOpt = {
  39779. disableAnimation: disableAnimation
  39780. };
  39781. var getSymbolPoint = opt.getSymbolPoint || function (idx) {
  39782. return data.getItemLayout(idx);
  39783. };
  39784. // There is no oldLineData only when first rendering or switching from
  39785. // stream mode to normal mode, where previous elements should be removed.
  39786. if (!oldData) {
  39787. group.removeAll();
  39788. }
  39789. data.diff(oldData).add(function (newIdx) {
  39790. var point = getSymbolPoint(newIdx);
  39791. if (symbolNeedsDraw(data, point, newIdx, opt)) {
  39792. var symbolEl = new SymbolCtor(data, newIdx, seriesScope, symbolUpdateOpt);
  39793. symbolEl.setPosition(point);
  39794. data.setItemGraphicEl(newIdx, symbolEl);
  39795. group.add(symbolEl);
  39796. }
  39797. }).update(function (newIdx, oldIdx) {
  39798. var symbolEl = oldData.getItemGraphicEl(oldIdx);
  39799. var point = getSymbolPoint(newIdx);
  39800. if (!symbolNeedsDraw(data, point, newIdx, opt)) {
  39801. group.remove(symbolEl);
  39802. return;
  39803. }
  39804. var newSymbolType = data.getItemVisual(newIdx, 'symbol') || 'circle';
  39805. var oldSymbolType = symbolEl && symbolEl.getSymbolType && symbolEl.getSymbolType();
  39806. if (!symbolEl
  39807. // Create a new if symbol type changed.
  39808. || oldSymbolType && oldSymbolType !== newSymbolType) {
  39809. group.remove(symbolEl);
  39810. symbolEl = new SymbolCtor(data, newIdx, seriesScope, symbolUpdateOpt);
  39811. symbolEl.setPosition(point);
  39812. } else {
  39813. symbolEl.updateData(data, newIdx, seriesScope, symbolUpdateOpt);
  39814. var target = {
  39815. x: point[0],
  39816. y: point[1]
  39817. };
  39818. disableAnimation ? symbolEl.attr(target) : updateProps(symbolEl, target, seriesModel);
  39819. }
  39820. // Add back
  39821. group.add(symbolEl);
  39822. data.setItemGraphicEl(newIdx, symbolEl);
  39823. }).remove(function (oldIdx) {
  39824. var el = oldData.getItemGraphicEl(oldIdx);
  39825. el && el.fadeOut(function () {
  39826. group.remove(el);
  39827. }, seriesModel);
  39828. }).execute();
  39829. this._getSymbolPoint = getSymbolPoint;
  39830. this._data = data;
  39831. };
  39832. SymbolDraw.prototype.updateLayout = function () {
  39833. var _this = this;
  39834. var data = this._data;
  39835. if (data) {
  39836. // Not use animation
  39837. data.eachItemGraphicEl(function (el, idx) {
  39838. var point = _this._getSymbolPoint(idx);
  39839. el.setPosition(point);
  39840. el.markRedraw();
  39841. });
  39842. }
  39843. };
  39844. SymbolDraw.prototype.incrementalPrepareUpdate = function (data) {
  39845. this._seriesScope = makeSeriesScope(data);
  39846. this._data = null;
  39847. this.group.removeAll();
  39848. };
  39849. /**
  39850. * Update symbols draw by new data
  39851. */
  39852. SymbolDraw.prototype.incrementalUpdate = function (taskParams, data, opt) {
  39853. // Clear
  39854. this._progressiveEls = [];
  39855. opt = normalizeUpdateOpt(opt);
  39856. function updateIncrementalAndHover(el) {
  39857. if (!el.isGroup) {
  39858. el.incremental = true;
  39859. el.ensureState('emphasis').hoverLayer = true;
  39860. }
  39861. }
  39862. for (var idx = taskParams.start; idx < taskParams.end; idx++) {
  39863. var point = data.getItemLayout(idx);
  39864. if (symbolNeedsDraw(data, point, idx, opt)) {
  39865. var el = new this._SymbolCtor(data, idx, this._seriesScope);
  39866. el.traverse(updateIncrementalAndHover);
  39867. el.setPosition(point);
  39868. this.group.add(el);
  39869. data.setItemGraphicEl(idx, el);
  39870. this._progressiveEls.push(el);
  39871. }
  39872. }
  39873. };
  39874. SymbolDraw.prototype.eachRendered = function (cb) {
  39875. traverseElements(this._progressiveEls || this.group, cb);
  39876. };
  39877. SymbolDraw.prototype.remove = function (enableAnimation) {
  39878. var group = this.group;
  39879. var data = this._data;
  39880. // Incremental model do not have this._data.
  39881. if (data && enableAnimation) {
  39882. data.eachItemGraphicEl(function (el) {
  39883. el.fadeOut(function () {
  39884. group.remove(el);
  39885. }, data.hostModel);
  39886. });
  39887. } else {
  39888. group.removeAll();
  39889. }
  39890. };
  39891. return SymbolDraw;
  39892. }();
  39893. function prepareDataCoordInfo(coordSys, data, valueOrigin) {
  39894. var baseAxis = coordSys.getBaseAxis();
  39895. var valueAxis = coordSys.getOtherAxis(baseAxis);
  39896. var valueStart = getValueStart(valueAxis, valueOrigin);
  39897. var baseAxisDim = baseAxis.dim;
  39898. var valueAxisDim = valueAxis.dim;
  39899. var valueDim = data.mapDimension(valueAxisDim);
  39900. var baseDim = data.mapDimension(baseAxisDim);
  39901. var baseDataOffset = valueAxisDim === 'x' || valueAxisDim === 'radius' ? 1 : 0;
  39902. var dims = map(coordSys.dimensions, function (coordDim) {
  39903. return data.mapDimension(coordDim);
  39904. });
  39905. var stacked = false;
  39906. var stackResultDim = data.getCalculationInfo('stackResultDimension');
  39907. if (isDimensionStacked(data, dims[0] /* , dims[1] */)) {
  39908. // jshint ignore:line
  39909. stacked = true;
  39910. dims[0] = stackResultDim;
  39911. }
  39912. if (isDimensionStacked(data, dims[1] /* , dims[0] */)) {
  39913. // jshint ignore:line
  39914. stacked = true;
  39915. dims[1] = stackResultDim;
  39916. }
  39917. return {
  39918. dataDimsForPoint: dims,
  39919. valueStart: valueStart,
  39920. valueAxisDim: valueAxisDim,
  39921. baseAxisDim: baseAxisDim,
  39922. stacked: !!stacked,
  39923. valueDim: valueDim,
  39924. baseDim: baseDim,
  39925. baseDataOffset: baseDataOffset,
  39926. stackedOverDimension: data.getCalculationInfo('stackedOverDimension')
  39927. };
  39928. }
  39929. function getValueStart(valueAxis, valueOrigin) {
  39930. var valueStart = 0;
  39931. var extent = valueAxis.scale.getExtent();
  39932. if (valueOrigin === 'start') {
  39933. valueStart = extent[0];
  39934. } else if (valueOrigin === 'end') {
  39935. valueStart = extent[1];
  39936. }
  39937. // If origin is specified as a number, use it as
  39938. // valueStart directly
  39939. else if (isNumber(valueOrigin) && !isNaN(valueOrigin)) {
  39940. valueStart = valueOrigin;
  39941. }
  39942. // auto
  39943. else {
  39944. // Both positive
  39945. if (extent[0] > 0) {
  39946. valueStart = extent[0];
  39947. }
  39948. // Both negative
  39949. else if (extent[1] < 0) {
  39950. valueStart = extent[1];
  39951. }
  39952. // If is one positive, and one negative, onZero shall be true
  39953. }
  39954. return valueStart;
  39955. }
  39956. function getStackedOnPoint(dataCoordInfo, coordSys, data, idx) {
  39957. var value = NaN;
  39958. if (dataCoordInfo.stacked) {
  39959. value = data.get(data.getCalculationInfo('stackedOverDimension'), idx);
  39960. }
  39961. if (isNaN(value)) {
  39962. value = dataCoordInfo.valueStart;
  39963. }
  39964. var baseDataOffset = dataCoordInfo.baseDataOffset;
  39965. var stackedData = [];
  39966. stackedData[baseDataOffset] = data.get(dataCoordInfo.baseDim, idx);
  39967. stackedData[1 - baseDataOffset] = value;
  39968. return coordSys.dataToPoint(stackedData);
  39969. }
  39970. function diffData(oldData, newData) {
  39971. var diffResult = [];
  39972. newData.diff(oldData).add(function (idx) {
  39973. diffResult.push({
  39974. cmd: '+',
  39975. idx: idx
  39976. });
  39977. }).update(function (newIdx, oldIdx) {
  39978. diffResult.push({
  39979. cmd: '=',
  39980. idx: oldIdx,
  39981. idx1: newIdx
  39982. });
  39983. }).remove(function (idx) {
  39984. diffResult.push({
  39985. cmd: '-',
  39986. idx: idx
  39987. });
  39988. }).execute();
  39989. return diffResult;
  39990. }
  39991. function lineAnimationDiff(oldData, newData, oldStackedOnPoints, newStackedOnPoints, oldCoordSys, newCoordSys, oldValueOrigin, newValueOrigin) {
  39992. var diff = diffData(oldData, newData);
  39993. // let newIdList = newData.mapArray(newData.getId);
  39994. // let oldIdList = oldData.mapArray(oldData.getId);
  39995. // convertToIntId(newIdList, oldIdList);
  39996. // // FIXME One data ?
  39997. // diff = arrayDiff(oldIdList, newIdList);
  39998. var currPoints = [];
  39999. var nextPoints = [];
  40000. // Points for stacking base line
  40001. var currStackedPoints = [];
  40002. var nextStackedPoints = [];
  40003. var status = [];
  40004. var sortedIndices = [];
  40005. var rawIndices = [];
  40006. var newDataOldCoordInfo = prepareDataCoordInfo(oldCoordSys, newData, oldValueOrigin);
  40007. // const oldDataNewCoordInfo = prepareDataCoordInfo(newCoordSys, oldData, newValueOrigin);
  40008. var oldPoints = oldData.getLayout('points') || [];
  40009. var newPoints = newData.getLayout('points') || [];
  40010. for (var i = 0; i < diff.length; i++) {
  40011. var diffItem = diff[i];
  40012. var pointAdded = true;
  40013. var oldIdx2 = void 0;
  40014. var newIdx2 = void 0;
  40015. // FIXME, animation is not so perfect when dataZoom window moves fast
  40016. // Which is in case remvoing or add more than one data in the tail or head
  40017. switch (diffItem.cmd) {
  40018. case '=':
  40019. oldIdx2 = diffItem.idx * 2;
  40020. newIdx2 = diffItem.idx1 * 2;
  40021. var currentX = oldPoints[oldIdx2];
  40022. var currentY = oldPoints[oldIdx2 + 1];
  40023. var nextX = newPoints[newIdx2];
  40024. var nextY = newPoints[newIdx2 + 1];
  40025. // If previous data is NaN, use next point directly
  40026. if (isNaN(currentX) || isNaN(currentY)) {
  40027. currentX = nextX;
  40028. currentY = nextY;
  40029. }
  40030. currPoints.push(currentX, currentY);
  40031. nextPoints.push(nextX, nextY);
  40032. currStackedPoints.push(oldStackedOnPoints[oldIdx2], oldStackedOnPoints[oldIdx2 + 1]);
  40033. nextStackedPoints.push(newStackedOnPoints[newIdx2], newStackedOnPoints[newIdx2 + 1]);
  40034. rawIndices.push(newData.getRawIndex(diffItem.idx1));
  40035. break;
  40036. case '+':
  40037. var newIdx = diffItem.idx;
  40038. var newDataDimsForPoint = newDataOldCoordInfo.dataDimsForPoint;
  40039. var oldPt = oldCoordSys.dataToPoint([newData.get(newDataDimsForPoint[0], newIdx), newData.get(newDataDimsForPoint[1], newIdx)]);
  40040. newIdx2 = newIdx * 2;
  40041. currPoints.push(oldPt[0], oldPt[1]);
  40042. nextPoints.push(newPoints[newIdx2], newPoints[newIdx2 + 1]);
  40043. var stackedOnPoint = getStackedOnPoint(newDataOldCoordInfo, oldCoordSys, newData, newIdx);
  40044. currStackedPoints.push(stackedOnPoint[0], stackedOnPoint[1]);
  40045. nextStackedPoints.push(newStackedOnPoints[newIdx2], newStackedOnPoints[newIdx2 + 1]);
  40046. rawIndices.push(newData.getRawIndex(newIdx));
  40047. break;
  40048. case '-':
  40049. pointAdded = false;
  40050. }
  40051. // Original indices
  40052. if (pointAdded) {
  40053. status.push(diffItem);
  40054. sortedIndices.push(sortedIndices.length);
  40055. }
  40056. }
  40057. // Diff result may be crossed if all items are changed
  40058. // Sort by data index
  40059. sortedIndices.sort(function (a, b) {
  40060. return rawIndices[a] - rawIndices[b];
  40061. });
  40062. var len = currPoints.length;
  40063. var sortedCurrPoints = createFloat32Array(len);
  40064. var sortedNextPoints = createFloat32Array(len);
  40065. var sortedCurrStackedPoints = createFloat32Array(len);
  40066. var sortedNextStackedPoints = createFloat32Array(len);
  40067. var sortedStatus = [];
  40068. for (var i = 0; i < sortedIndices.length; i++) {
  40069. var idx = sortedIndices[i];
  40070. var i2 = i * 2;
  40071. var idx2 = idx * 2;
  40072. sortedCurrPoints[i2] = currPoints[idx2];
  40073. sortedCurrPoints[i2 + 1] = currPoints[idx2 + 1];
  40074. sortedNextPoints[i2] = nextPoints[idx2];
  40075. sortedNextPoints[i2 + 1] = nextPoints[idx2 + 1];
  40076. sortedCurrStackedPoints[i2] = currStackedPoints[idx2];
  40077. sortedCurrStackedPoints[i2 + 1] = currStackedPoints[idx2 + 1];
  40078. sortedNextStackedPoints[i2] = nextStackedPoints[idx2];
  40079. sortedNextStackedPoints[i2 + 1] = nextStackedPoints[idx2 + 1];
  40080. sortedStatus[i] = status[idx];
  40081. }
  40082. return {
  40083. current: sortedCurrPoints,
  40084. next: sortedNextPoints,
  40085. stackedOnCurrent: sortedCurrStackedPoints,
  40086. stackedOnNext: sortedNextStackedPoints,
  40087. status: sortedStatus
  40088. };
  40089. }
  40090. var mathMin$6 = Math.min;
  40091. var mathMax$6 = Math.max;
  40092. function isPointNull(x, y) {
  40093. return isNaN(x) || isNaN(y);
  40094. }
  40095. /**
  40096. * Draw smoothed line in non-monotone, in may cause undesired curve in extreme
  40097. * situations. This should be used when points are non-monotone neither in x or
  40098. * y dimension.
  40099. */
  40100. function drawSegment(ctx, points, start, segLen, allLen, dir, smooth, smoothMonotone, connectNulls) {
  40101. var prevX;
  40102. var prevY;
  40103. var cpx0;
  40104. var cpy0;
  40105. var cpx1;
  40106. var cpy1;
  40107. var idx = start;
  40108. var k = 0;
  40109. for (; k < segLen; k++) {
  40110. var x = points[idx * 2];
  40111. var y = points[idx * 2 + 1];
  40112. if (idx >= allLen || idx < 0) {
  40113. break;
  40114. }
  40115. if (isPointNull(x, y)) {
  40116. if (connectNulls) {
  40117. idx += dir;
  40118. continue;
  40119. }
  40120. break;
  40121. }
  40122. if (idx === start) {
  40123. ctx[dir > 0 ? 'moveTo' : 'lineTo'](x, y);
  40124. cpx0 = x;
  40125. cpy0 = y;
  40126. } else {
  40127. var dx = x - prevX;
  40128. var dy = y - prevY;
  40129. // Ignore tiny segment.
  40130. if (dx * dx + dy * dy < 0.5) {
  40131. idx += dir;
  40132. continue;
  40133. }
  40134. if (smooth > 0) {
  40135. var nextIdx = idx + dir;
  40136. var nextX = points[nextIdx * 2];
  40137. var nextY = points[nextIdx * 2 + 1];
  40138. // Ignore duplicate point
  40139. while (nextX === x && nextY === y && k < segLen) {
  40140. k++;
  40141. nextIdx += dir;
  40142. idx += dir;
  40143. nextX = points[nextIdx * 2];
  40144. nextY = points[nextIdx * 2 + 1];
  40145. x = points[idx * 2];
  40146. y = points[idx * 2 + 1];
  40147. dx = x - prevX;
  40148. dy = y - prevY;
  40149. }
  40150. var tmpK = k + 1;
  40151. if (connectNulls) {
  40152. // Find next point not null
  40153. while (isPointNull(nextX, nextY) && tmpK < segLen) {
  40154. tmpK++;
  40155. nextIdx += dir;
  40156. nextX = points[nextIdx * 2];
  40157. nextY = points[nextIdx * 2 + 1];
  40158. }
  40159. }
  40160. var ratioNextSeg = 0.5;
  40161. var vx = 0;
  40162. var vy = 0;
  40163. var nextCpx0 = void 0;
  40164. var nextCpy0 = void 0;
  40165. // Is last point
  40166. if (tmpK >= segLen || isPointNull(nextX, nextY)) {
  40167. cpx1 = x;
  40168. cpy1 = y;
  40169. } else {
  40170. vx = nextX - prevX;
  40171. vy = nextY - prevY;
  40172. var dx0 = x - prevX;
  40173. var dx1 = nextX - x;
  40174. var dy0 = y - prevY;
  40175. var dy1 = nextY - y;
  40176. var lenPrevSeg = void 0;
  40177. var lenNextSeg = void 0;
  40178. if (smoothMonotone === 'x') {
  40179. lenPrevSeg = Math.abs(dx0);
  40180. lenNextSeg = Math.abs(dx1);
  40181. var dir_1 = vx > 0 ? 1 : -1;
  40182. cpx1 = x - dir_1 * lenPrevSeg * smooth;
  40183. cpy1 = y;
  40184. nextCpx0 = x + dir_1 * lenNextSeg * smooth;
  40185. nextCpy0 = y;
  40186. } else if (smoothMonotone === 'y') {
  40187. lenPrevSeg = Math.abs(dy0);
  40188. lenNextSeg = Math.abs(dy1);
  40189. var dir_2 = vy > 0 ? 1 : -1;
  40190. cpx1 = x;
  40191. cpy1 = y - dir_2 * lenPrevSeg * smooth;
  40192. nextCpx0 = x;
  40193. nextCpy0 = y + dir_2 * lenNextSeg * smooth;
  40194. } else {
  40195. lenPrevSeg = Math.sqrt(dx0 * dx0 + dy0 * dy0);
  40196. lenNextSeg = Math.sqrt(dx1 * dx1 + dy1 * dy1);
  40197. // Use ratio of seg length
  40198. ratioNextSeg = lenNextSeg / (lenNextSeg + lenPrevSeg);
  40199. cpx1 = x - vx * smooth * (1 - ratioNextSeg);
  40200. cpy1 = y - vy * smooth * (1 - ratioNextSeg);
  40201. // cp0 of next segment
  40202. nextCpx0 = x + vx * smooth * ratioNextSeg;
  40203. nextCpy0 = y + vy * smooth * ratioNextSeg;
  40204. // Smooth constraint between point and next point.
  40205. // Avoid exceeding extreme after smoothing.
  40206. nextCpx0 = mathMin$6(nextCpx0, mathMax$6(nextX, x));
  40207. nextCpy0 = mathMin$6(nextCpy0, mathMax$6(nextY, y));
  40208. nextCpx0 = mathMax$6(nextCpx0, mathMin$6(nextX, x));
  40209. nextCpy0 = mathMax$6(nextCpy0, mathMin$6(nextY, y));
  40210. // Reclaculate cp1 based on the adjusted cp0 of next seg.
  40211. vx = nextCpx0 - x;
  40212. vy = nextCpy0 - y;
  40213. cpx1 = x - vx * lenPrevSeg / lenNextSeg;
  40214. cpy1 = y - vy * lenPrevSeg / lenNextSeg;
  40215. // Smooth constraint between point and prev point.
  40216. // Avoid exceeding extreme after smoothing.
  40217. cpx1 = mathMin$6(cpx1, mathMax$6(prevX, x));
  40218. cpy1 = mathMin$6(cpy1, mathMax$6(prevY, y));
  40219. cpx1 = mathMax$6(cpx1, mathMin$6(prevX, x));
  40220. cpy1 = mathMax$6(cpy1, mathMin$6(prevY, y));
  40221. // Adjust next cp0 again.
  40222. vx = x - cpx1;
  40223. vy = y - cpy1;
  40224. nextCpx0 = x + vx * lenNextSeg / lenPrevSeg;
  40225. nextCpy0 = y + vy * lenNextSeg / lenPrevSeg;
  40226. }
  40227. }
  40228. ctx.bezierCurveTo(cpx0, cpy0, cpx1, cpy1, x, y);
  40229. cpx0 = nextCpx0;
  40230. cpy0 = nextCpy0;
  40231. } else {
  40232. ctx.lineTo(x, y);
  40233. }
  40234. }
  40235. prevX = x;
  40236. prevY = y;
  40237. idx += dir;
  40238. }
  40239. return k;
  40240. }
  40241. var ECPolylineShape = /** @class */function () {
  40242. function ECPolylineShape() {
  40243. this.smooth = 0;
  40244. this.smoothConstraint = true;
  40245. }
  40246. return ECPolylineShape;
  40247. }();
  40248. var ECPolyline = /** @class */function (_super) {
  40249. __extends(ECPolyline, _super);
  40250. function ECPolyline(opts) {
  40251. var _this = _super.call(this, opts) || this;
  40252. _this.type = 'ec-polyline';
  40253. return _this;
  40254. }
  40255. ECPolyline.prototype.getDefaultStyle = function () {
  40256. return {
  40257. stroke: tokens.color.neutral99,
  40258. fill: null
  40259. };
  40260. };
  40261. ECPolyline.prototype.getDefaultShape = function () {
  40262. return new ECPolylineShape();
  40263. };
  40264. ECPolyline.prototype.buildPath = function (ctx, shape) {
  40265. var points = shape.points;
  40266. var i = 0;
  40267. var len = points.length / 2;
  40268. // const result = getBoundingBox(points, shape.smoothConstraint);
  40269. if (shape.connectNulls) {
  40270. // Must remove first and last null values avoid draw error in polygon
  40271. for (; len > 0; len--) {
  40272. if (!isPointNull(points[len * 2 - 2], points[len * 2 - 1])) {
  40273. break;
  40274. }
  40275. }
  40276. for (; i < len; i++) {
  40277. if (!isPointNull(points[i * 2], points[i * 2 + 1])) {
  40278. break;
  40279. }
  40280. }
  40281. }
  40282. while (i < len) {
  40283. i += drawSegment(ctx, points, i, len, len, 1, shape.smooth, shape.smoothMonotone, shape.connectNulls) + 1;
  40284. }
  40285. };
  40286. ECPolyline.prototype.getPointOn = function (xOrY, dim) {
  40287. if (!this.path) {
  40288. this.createPathProxy();
  40289. this.buildPath(this.path, this.shape);
  40290. }
  40291. var path = this.path;
  40292. var data = path.data;
  40293. var CMD = PathProxy.CMD;
  40294. var x0;
  40295. var y0;
  40296. var isDimX = dim === 'x';
  40297. var roots = [];
  40298. for (var i = 0; i < data.length;) {
  40299. var cmd = data[i++];
  40300. var x = void 0;
  40301. var y = void 0;
  40302. var x2 = void 0;
  40303. var y2 = void 0;
  40304. var x3 = void 0;
  40305. var y3 = void 0;
  40306. var t = void 0;
  40307. switch (cmd) {
  40308. case CMD.M:
  40309. x0 = data[i++];
  40310. y0 = data[i++];
  40311. break;
  40312. case CMD.L:
  40313. x = data[i++];
  40314. y = data[i++];
  40315. t = isDimX ? (xOrY - x0) / (x - x0) : (xOrY - y0) / (y - y0);
  40316. if (t <= 1 && t >= 0) {
  40317. var val = isDimX ? (y - y0) * t + y0 : (x - x0) * t + x0;
  40318. return isDimX ? [xOrY, val] : [val, xOrY];
  40319. }
  40320. x0 = x;
  40321. y0 = y;
  40322. break;
  40323. case CMD.C:
  40324. x = data[i++];
  40325. y = data[i++];
  40326. x2 = data[i++];
  40327. y2 = data[i++];
  40328. x3 = data[i++];
  40329. y3 = data[i++];
  40330. var nRoot = isDimX ? cubicRootAt(x0, x, x2, x3, xOrY, roots) : cubicRootAt(y0, y, y2, y3, xOrY, roots);
  40331. if (nRoot > 0) {
  40332. for (var i_1 = 0; i_1 < nRoot; i_1++) {
  40333. var t_1 = roots[i_1];
  40334. if (t_1 <= 1 && t_1 >= 0) {
  40335. var val = isDimX ? cubicAt(y0, y, y2, y3, t_1) : cubicAt(x0, x, x2, x3, t_1);
  40336. return isDimX ? [xOrY, val] : [val, xOrY];
  40337. }
  40338. }
  40339. }
  40340. x0 = x3;
  40341. y0 = y3;
  40342. break;
  40343. }
  40344. }
  40345. };
  40346. return ECPolyline;
  40347. }(Path);
  40348. var ECPolygonShape = /** @class */function (_super) {
  40349. __extends(ECPolygonShape, _super);
  40350. function ECPolygonShape() {
  40351. return _super !== null && _super.apply(this, arguments) || this;
  40352. }
  40353. return ECPolygonShape;
  40354. }(ECPolylineShape);
  40355. var ECPolygon = /** @class */function (_super) {
  40356. __extends(ECPolygon, _super);
  40357. function ECPolygon(opts) {
  40358. var _this = _super.call(this, opts) || this;
  40359. _this.type = 'ec-polygon';
  40360. return _this;
  40361. }
  40362. ECPolygon.prototype.getDefaultShape = function () {
  40363. return new ECPolygonShape();
  40364. };
  40365. ECPolygon.prototype.buildPath = function (ctx, shape) {
  40366. var points = shape.points;
  40367. var stackedOnPoints = shape.stackedOnPoints;
  40368. var i = 0;
  40369. var len = points.length / 2;
  40370. var smoothMonotone = shape.smoothMonotone;
  40371. if (shape.connectNulls) {
  40372. // Must remove first and last null values avoid draw error in polygon
  40373. for (; len > 0; len--) {
  40374. if (!isPointNull(points[len * 2 - 2], points[len * 2 - 1])) {
  40375. break;
  40376. }
  40377. }
  40378. for (; i < len; i++) {
  40379. if (!isPointNull(points[i * 2], points[i * 2 + 1])) {
  40380. break;
  40381. }
  40382. }
  40383. }
  40384. while (i < len) {
  40385. var k = drawSegment(ctx, points, i, len, len, 1, shape.smooth, smoothMonotone, shape.connectNulls);
  40386. drawSegment(ctx, stackedOnPoints, i + k - 1, k, len, -1, shape.stackedOnSmooth, smoothMonotone, shape.connectNulls);
  40387. i += k + 1;
  40388. ctx.closePath();
  40389. }
  40390. };
  40391. return ECPolygon;
  40392. }(Path);
  40393. function createGridClipPath(cartesian, hasAnimation, seriesModel, done, during) {
  40394. var rect = cartesian.getArea();
  40395. var x = rect.x;
  40396. var y = rect.y;
  40397. var width = rect.width;
  40398. var height = rect.height;
  40399. var lineWidth = seriesModel.get(['lineStyle', 'width']) || 0;
  40400. // Expand the clip path a bit to avoid the border is clipped and looks thinner
  40401. x -= lineWidth / 2;
  40402. y -= lineWidth / 2;
  40403. width += lineWidth;
  40404. height += lineWidth;
  40405. // fix: https://github.com/apache/incubator-echarts/issues/11369
  40406. width = Math.ceil(width);
  40407. if (x !== Math.floor(x)) {
  40408. x = Math.floor(x);
  40409. // if no extra 1px on `width`, it will still be clipped since `x` is floored
  40410. width++;
  40411. }
  40412. var clipPath = new Rect({
  40413. shape: {
  40414. x: x,
  40415. y: y,
  40416. width: width,
  40417. height: height
  40418. }
  40419. });
  40420. if (hasAnimation) {
  40421. var baseAxis = cartesian.getBaseAxis();
  40422. var isHorizontal = baseAxis.isHorizontal();
  40423. var isAxisInversed = baseAxis.inverse;
  40424. if (isHorizontal) {
  40425. if (isAxisInversed) {
  40426. clipPath.shape.x += width;
  40427. }
  40428. clipPath.shape.width = 0;
  40429. } else {
  40430. if (!isAxisInversed) {
  40431. clipPath.shape.y += height;
  40432. }
  40433. clipPath.shape.height = 0;
  40434. }
  40435. var duringCb = isFunction(during) ? function (percent) {
  40436. during(percent, clipPath);
  40437. } : null;
  40438. initProps(clipPath, {
  40439. shape: {
  40440. width: width,
  40441. height: height,
  40442. x: x,
  40443. y: y
  40444. }
  40445. }, seriesModel, null, done, duringCb);
  40446. }
  40447. return clipPath;
  40448. }
  40449. function createPolarClipPath(polar, hasAnimation, seriesModel) {
  40450. var sectorArea = polar.getArea();
  40451. // Avoid float number rounding error for symbol on the edge of axis extent.
  40452. var r0 = round(sectorArea.r0, 1);
  40453. var r = round(sectorArea.r, 1);
  40454. var clipPath = new Sector({
  40455. shape: {
  40456. cx: round(polar.cx, 1),
  40457. cy: round(polar.cy, 1),
  40458. r0: r0,
  40459. r: r,
  40460. startAngle: sectorArea.startAngle,
  40461. endAngle: sectorArea.endAngle,
  40462. clockwise: sectorArea.clockwise
  40463. }
  40464. });
  40465. if (hasAnimation) {
  40466. var isRadial = polar.getBaseAxis().dim === 'angle';
  40467. if (isRadial) {
  40468. clipPath.shape.endAngle = sectorArea.startAngle;
  40469. } else {
  40470. clipPath.shape.r = r0;
  40471. }
  40472. initProps(clipPath, {
  40473. shape: {
  40474. endAngle: sectorArea.endAngle,
  40475. r: r
  40476. }
  40477. }, seriesModel);
  40478. }
  40479. return clipPath;
  40480. }
  40481. function createClipPath(coordSys, hasAnimation, seriesModel, done, during) {
  40482. if (!coordSys) {
  40483. return null;
  40484. } else if (coordSys.type === 'polar') {
  40485. return createPolarClipPath(coordSys, hasAnimation, seriesModel);
  40486. } else if (coordSys.type === 'cartesian2d') {
  40487. return createGridClipPath(coordSys, hasAnimation, seriesModel, done, during);
  40488. }
  40489. return null;
  40490. }
  40491. /*
  40492. * Licensed to the Apache Software Foundation (ASF) under one
  40493. * or more contributor license agreements. See the NOTICE file
  40494. * distributed with this work for additional information
  40495. * regarding copyright ownership. The ASF licenses this file
  40496. * to you under the Apache License, Version 2.0 (the
  40497. * "License"); you may not use this file except in compliance
  40498. * with the License. You may obtain a copy of the License at
  40499. *
  40500. * http://www.apache.org/licenses/LICENSE-2.0
  40501. *
  40502. * Unless required by applicable law or agreed to in writing,
  40503. * software distributed under the License is distributed on an
  40504. * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
  40505. * KIND, either express or implied. See the License for the
  40506. * specific language governing permissions and limitations
  40507. * under the License.
  40508. */
  40509. /**
  40510. * AUTO-GENERATED FILE. DO NOT MODIFY.
  40511. */
  40512. /*
  40513. * Licensed to the Apache Software Foundation (ASF) under one
  40514. * or more contributor license agreements. See the NOTICE file
  40515. * distributed with this work for additional information
  40516. * regarding copyright ownership. The ASF licenses this file
  40517. * to you under the Apache License, Version 2.0 (the
  40518. * "License"); you may not use this file except in compliance
  40519. * with the License. You may obtain a copy of the License at
  40520. *
  40521. * http://www.apache.org/licenses/LICENSE-2.0
  40522. *
  40523. * Unless required by applicable law or agreed to in writing,
  40524. * software distributed under the License is distributed on an
  40525. * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
  40526. * KIND, either express or implied. See the License for the
  40527. * specific language governing permissions and limitations
  40528. * under the License.
  40529. */
  40530. function isCoordinateSystemType(coordSys, type) {
  40531. return coordSys.type === type;
  40532. }
  40533. function isPointsSame(points1, points2) {
  40534. if (points1.length !== points2.length) {
  40535. return;
  40536. }
  40537. for (var i = 0; i < points1.length; i++) {
  40538. if (points1[i] !== points2[i]) {
  40539. return;
  40540. }
  40541. }
  40542. return true;
  40543. }
  40544. function bboxFromPoints(points) {
  40545. var minX = Infinity;
  40546. var minY = Infinity;
  40547. var maxX = -Infinity;
  40548. var maxY = -Infinity;
  40549. for (var i = 0; i < points.length;) {
  40550. var x = points[i++];
  40551. var y = points[i++];
  40552. if (!isNaN(x)) {
  40553. minX = Math.min(x, minX);
  40554. maxX = Math.max(x, maxX);
  40555. }
  40556. if (!isNaN(y)) {
  40557. minY = Math.min(y, minY);
  40558. maxY = Math.max(y, maxY);
  40559. }
  40560. }
  40561. return [[minX, minY], [maxX, maxY]];
  40562. }
  40563. function getBoundingDiff(points1, points2) {
  40564. var _a = bboxFromPoints(points1),
  40565. min1 = _a[0],
  40566. max1 = _a[1];
  40567. var _b = bboxFromPoints(points2),
  40568. min2 = _b[0],
  40569. max2 = _b[1];
  40570. // Get a max value from each corner of two boundings.
  40571. return Math.max(Math.abs(min1[0] - min2[0]), Math.abs(min1[1] - min2[1]), Math.abs(max1[0] - max2[0]), Math.abs(max1[1] - max2[1]));
  40572. }
  40573. function getSmooth(smooth) {
  40574. return isNumber(smooth) ? smooth : smooth ? 0.5 : 0;
  40575. }
  40576. function getStackedOnPoints(coordSys, data, dataCoordInfo) {
  40577. if (!dataCoordInfo.valueDim) {
  40578. return [];
  40579. }
  40580. var len = data.count();
  40581. var points = createFloat32Array(len * 2);
  40582. for (var idx = 0; idx < len; idx++) {
  40583. var pt = getStackedOnPoint(dataCoordInfo, coordSys, data, idx);
  40584. points[idx * 2] = pt[0];
  40585. points[idx * 2 + 1] = pt[1];
  40586. }
  40587. return points;
  40588. }
  40589. /**
  40590. * Filter the null data and extend data for step considering `stepTurnAt`
  40591. *
  40592. * @param points data to convert, that may containing null
  40593. * @param basePoints base data to reference, used only for areaStyle points
  40594. * @param coordSys coordinate system
  40595. * @param stepTurnAt 'start' | 'end' | 'middle' | true
  40596. * @param connectNulls whether to connect nulls
  40597. * @returns converted point positions
  40598. */
  40599. function turnPointsIntoStep(points, basePoints, coordSys, stepTurnAt, connectNulls) {
  40600. var baseAxis = coordSys.getBaseAxis();
  40601. var baseIndex = baseAxis.dim === 'x' || baseAxis.dim === 'radius' ? 0 : 1;
  40602. var stepPoints = [];
  40603. var i = 0;
  40604. var stepPt = [];
  40605. var pt = [];
  40606. var nextPt = [];
  40607. var filteredPoints = [];
  40608. if (connectNulls) {
  40609. for (i = 0; i < points.length; i += 2) {
  40610. /**
  40611. * For areaStyle of stepped lines, `stackedOnPoints` should be
  40612. * filtered the same as `points` so that the base axis values
  40613. * should stay the same as the lines above. See #20021
  40614. */
  40615. var reference = basePoints || points;
  40616. if (!isNaN(reference[i]) && !isNaN(reference[i + 1])) {
  40617. filteredPoints.push(points[i], points[i + 1]);
  40618. }
  40619. }
  40620. points = filteredPoints;
  40621. }
  40622. for (i = 0; i < points.length - 2; i += 2) {
  40623. nextPt[0] = points[i + 2];
  40624. nextPt[1] = points[i + 3];
  40625. pt[0] = points[i];
  40626. pt[1] = points[i + 1];
  40627. stepPoints.push(pt[0], pt[1]);
  40628. switch (stepTurnAt) {
  40629. case 'end':
  40630. stepPt[baseIndex] = nextPt[baseIndex];
  40631. stepPt[1 - baseIndex] = pt[1 - baseIndex];
  40632. stepPoints.push(stepPt[0], stepPt[1]);
  40633. break;
  40634. case 'middle':
  40635. var middle = (pt[baseIndex] + nextPt[baseIndex]) / 2;
  40636. var stepPt2 = [];
  40637. stepPt[baseIndex] = stepPt2[baseIndex] = middle;
  40638. stepPt[1 - baseIndex] = pt[1 - baseIndex];
  40639. stepPt2[1 - baseIndex] = nextPt[1 - baseIndex];
  40640. stepPoints.push(stepPt[0], stepPt[1]);
  40641. stepPoints.push(stepPt2[0], stepPt2[1]);
  40642. break;
  40643. default:
  40644. // default is start
  40645. stepPt[baseIndex] = pt[baseIndex];
  40646. stepPt[1 - baseIndex] = nextPt[1 - baseIndex];
  40647. stepPoints.push(stepPt[0], stepPt[1]);
  40648. }
  40649. }
  40650. // Last points
  40651. stepPoints.push(points[i++], points[i++]);
  40652. return stepPoints;
  40653. }
  40654. /**
  40655. * Clip color stops to edge. Avoid creating too large gradients.
  40656. * Which may lead to blurry when GPU acceleration is enabled. See #15680
  40657. *
  40658. * The stops has been sorted from small to large.
  40659. */
  40660. function clipColorStops(colorStops, maxSize) {
  40661. var newColorStops = [];
  40662. var len = colorStops.length;
  40663. // coord will always < 0 in prevOutOfRangeColorStop.
  40664. var prevOutOfRangeColorStop;
  40665. var prevInRangeColorStop;
  40666. function lerpStop(stop0, stop1, clippedCoord) {
  40667. var coord0 = stop0.coord;
  40668. var p = (clippedCoord - coord0) / (stop1.coord - coord0);
  40669. var color = lerp$1(p, [stop0.color, stop1.color]);
  40670. return {
  40671. coord: clippedCoord,
  40672. color: color
  40673. };
  40674. }
  40675. for (var i = 0; i < len; i++) {
  40676. var stop_1 = colorStops[i];
  40677. var coord = stop_1.coord;
  40678. if (coord < 0) {
  40679. prevOutOfRangeColorStop = stop_1;
  40680. } else if (coord > maxSize) {
  40681. if (prevInRangeColorStop) {
  40682. newColorStops.push(lerpStop(prevInRangeColorStop, stop_1, maxSize));
  40683. } else if (prevOutOfRangeColorStop) {
  40684. // If there are two stops and coord range is between these two stops
  40685. newColorStops.push(lerpStop(prevOutOfRangeColorStop, stop_1, 0), lerpStop(prevOutOfRangeColorStop, stop_1, maxSize));
  40686. }
  40687. // All following stop will be out of range. So just ignore them.
  40688. break;
  40689. } else {
  40690. if (prevOutOfRangeColorStop) {
  40691. newColorStops.push(lerpStop(prevOutOfRangeColorStop, stop_1, 0));
  40692. // Reset
  40693. prevOutOfRangeColorStop = null;
  40694. }
  40695. newColorStops.push(stop_1);
  40696. prevInRangeColorStop = stop_1;
  40697. }
  40698. }
  40699. return newColorStops;
  40700. }
  40701. function getVisualGradient(data, coordSys, api) {
  40702. var visualMetaList = data.getVisual('visualMeta');
  40703. if (!visualMetaList || !visualMetaList.length || !data.count()) {
  40704. // When data.count() is 0, gradient range can not be calculated.
  40705. return;
  40706. }
  40707. if (coordSys.type !== 'cartesian2d') {
  40708. if ("development" !== 'production') {
  40709. console.warn('Visual map on line style is only supported on cartesian2d.');
  40710. }
  40711. return;
  40712. }
  40713. var coordDim;
  40714. var visualMeta;
  40715. for (var i = visualMetaList.length - 1; i >= 0; i--) {
  40716. var dimInfo = data.getDimensionInfo(visualMetaList[i].dimension);
  40717. coordDim = dimInfo && dimInfo.coordDim;
  40718. // Can only be x or y
  40719. if (coordDim === 'x' || coordDim === 'y') {
  40720. visualMeta = visualMetaList[i];
  40721. break;
  40722. }
  40723. }
  40724. if (!visualMeta) {
  40725. if ("development" !== 'production') {
  40726. console.warn('Visual map on line style only support x or y dimension.');
  40727. }
  40728. return;
  40729. }
  40730. // If the area to be rendered is bigger than area defined by LinearGradient,
  40731. // the canvas spec prescribes that the color of the first stop and the last
  40732. // stop should be used. But if two stops are added at offset 0, in effect
  40733. // browsers use the color of the second stop to render area outside
  40734. // LinearGradient. So we can only infinitesimally extend area defined in
  40735. // LinearGradient to render `outerColors`.
  40736. var axis = coordSys.getAxis(coordDim);
  40737. // dataToCoord mapping may not be linear, but must be monotonic.
  40738. var colorStops = map(visualMeta.stops, function (stop) {
  40739. // offset will be calculated later.
  40740. return {
  40741. coord: axis.toGlobalCoord(axis.dataToCoord(stop.value)),
  40742. color: stop.color
  40743. };
  40744. });
  40745. var stopLen = colorStops.length;
  40746. var outerColors = visualMeta.outerColors.slice();
  40747. if (stopLen && colorStops[0].coord > colorStops[stopLen - 1].coord) {
  40748. colorStops.reverse();
  40749. outerColors.reverse();
  40750. }
  40751. var colorStopsInRange = clipColorStops(colorStops, coordDim === 'x' ? api.getWidth() : api.getHeight());
  40752. var inRangeStopLen = colorStopsInRange.length;
  40753. if (!inRangeStopLen && stopLen) {
  40754. // All stops are out of range. All will be the same color.
  40755. return colorStops[0].coord < 0 ? outerColors[1] ? outerColors[1] : colorStops[stopLen - 1].color : outerColors[0] ? outerColors[0] : colorStops[0].color;
  40756. }
  40757. var tinyExtent = 10; // Arbitrary value: 10px
  40758. var minCoord = colorStopsInRange[0].coord - tinyExtent;
  40759. var maxCoord = colorStopsInRange[inRangeStopLen - 1].coord + tinyExtent;
  40760. var coordSpan = maxCoord - minCoord;
  40761. if (coordSpan < 1e-3) {
  40762. return 'transparent';
  40763. }
  40764. each(colorStopsInRange, function (stop) {
  40765. stop.offset = (stop.coord - minCoord) / coordSpan;
  40766. });
  40767. colorStopsInRange.push({
  40768. // NOTE: inRangeStopLen may still be 0 if stoplen is zero.
  40769. offset: inRangeStopLen ? colorStopsInRange[inRangeStopLen - 1].offset : 0.5,
  40770. color: outerColors[1] || 'transparent'
  40771. });
  40772. colorStopsInRange.unshift({
  40773. offset: inRangeStopLen ? colorStopsInRange[0].offset : 0.5,
  40774. color: outerColors[0] || 'transparent'
  40775. });
  40776. var gradient = new LinearGradient(0, 0, 0, 0, colorStopsInRange, true);
  40777. gradient[coordDim] = minCoord;
  40778. gradient[coordDim + '2'] = maxCoord;
  40779. return gradient;
  40780. }
  40781. function getIsIgnoreFunc(seriesModel, data, coordSys) {
  40782. var showAllSymbol = seriesModel.get('showAllSymbol');
  40783. var isAuto = showAllSymbol === 'auto';
  40784. if (showAllSymbol && !isAuto) {
  40785. return;
  40786. }
  40787. var categoryAxis = coordSys.getAxesByScale('ordinal')[0];
  40788. if (!categoryAxis) {
  40789. return;
  40790. }
  40791. // Note that category label interval strategy might bring some weird effect
  40792. // in some scenario: users may wonder why some of the symbols are not
  40793. // displayed. So we show all symbols as possible as we can.
  40794. if (isAuto
  40795. // Simplify the logic, do not determine label overlap here.
  40796. && canShowAllSymbolForCategory(categoryAxis, data)) {
  40797. return;
  40798. }
  40799. // Otherwise follow the label interval strategy on category axis.
  40800. var categoryDataDim = data.mapDimension(categoryAxis.dim);
  40801. var labelMap = {};
  40802. each(categoryAxis.getViewLabels(), function (labelItem) {
  40803. var ordinalNumber = categoryAxis.scale.getRawOrdinalNumber(labelItem.tickValue);
  40804. labelMap[ordinalNumber] = 1;
  40805. });
  40806. return function (dataIndex) {
  40807. return !labelMap.hasOwnProperty(data.get(categoryDataDim, dataIndex));
  40808. };
  40809. }
  40810. function canShowAllSymbolForCategory(categoryAxis, data) {
  40811. // In most cases, line is monotonous on category axis, and the label size
  40812. // is close with each other. So we check the symbol size and some of the
  40813. // label size alone with the category axis to estimate whether all symbol
  40814. // can be shown without overlap.
  40815. var axisExtent = categoryAxis.getExtent();
  40816. var availSize = Math.abs(axisExtent[1] - axisExtent[0]) / categoryAxis.scale.count();
  40817. isNaN(availSize) && (availSize = 0); // 0/0 is NaN.
  40818. // Sampling some points, max 5.
  40819. var dataLen = data.count();
  40820. var step = Math.max(1, Math.round(dataLen / 5));
  40821. for (var dataIndex = 0; dataIndex < dataLen; dataIndex += step) {
  40822. if (Symbol.getSymbolSize(data, dataIndex
  40823. // Only for cartesian, where `isHorizontal` exists.
  40824. )[categoryAxis.isHorizontal() ? 1 : 0]
  40825. // Empirical number
  40826. * 1.5 > availSize) {
  40827. return false;
  40828. }
  40829. }
  40830. return true;
  40831. }
  40832. function isPointNull$1(x, y) {
  40833. return isNaN(x) || isNaN(y);
  40834. }
  40835. function getLastIndexNotNull(points) {
  40836. var len = points.length / 2;
  40837. for (; len > 0; len--) {
  40838. if (!isPointNull$1(points[len * 2 - 2], points[len * 2 - 1])) {
  40839. break;
  40840. }
  40841. }
  40842. return len - 1;
  40843. }
  40844. function getPointAtIndex(points, idx) {
  40845. return [points[idx * 2], points[idx * 2 + 1]];
  40846. }
  40847. function getIndexRange(points, xOrY, dim) {
  40848. var len = points.length / 2;
  40849. var dimIdx = dim === 'x' ? 0 : 1;
  40850. var a;
  40851. var b;
  40852. var prevIndex = 0;
  40853. var nextIndex = -1;
  40854. for (var i = 0; i < len; i++) {
  40855. b = points[i * 2 + dimIdx];
  40856. if (isNaN(b) || isNaN(points[i * 2 + 1 - dimIdx])) {
  40857. continue;
  40858. }
  40859. if (i === 0) {
  40860. a = b;
  40861. continue;
  40862. }
  40863. if (a <= xOrY && b >= xOrY || a >= xOrY && b <= xOrY) {
  40864. nextIndex = i;
  40865. break;
  40866. }
  40867. prevIndex = i;
  40868. a = b;
  40869. }
  40870. return {
  40871. range: [prevIndex, nextIndex],
  40872. t: (xOrY - a) / (b - a)
  40873. };
  40874. }
  40875. function anyStateShowEndLabel(seriesModel) {
  40876. if (seriesModel.get(['endLabel', 'show'])) {
  40877. return true;
  40878. }
  40879. for (var i = 0; i < SPECIAL_STATES.length; i++) {
  40880. if (seriesModel.get([SPECIAL_STATES[i], 'endLabel', 'show'])) {
  40881. return true;
  40882. }
  40883. }
  40884. return false;
  40885. }
  40886. function createLineClipPath(lineView, coordSys, hasAnimation, seriesModel) {
  40887. if (isCoordinateSystemType(coordSys, 'cartesian2d')) {
  40888. var endLabelModel_1 = seriesModel.getModel('endLabel');
  40889. var valueAnimation_1 = endLabelModel_1.get('valueAnimation');
  40890. var data_1 = seriesModel.getData();
  40891. var labelAnimationRecord_1 = {
  40892. lastFrameIndex: 0
  40893. };
  40894. var during = anyStateShowEndLabel(seriesModel) ? function (percent, clipRect) {
  40895. lineView._endLabelOnDuring(percent, clipRect, data_1, labelAnimationRecord_1, valueAnimation_1, endLabelModel_1, coordSys);
  40896. } : null;
  40897. var isHorizontal = coordSys.getBaseAxis().isHorizontal();
  40898. var clipPath = createGridClipPath(coordSys, hasAnimation, seriesModel, function () {
  40899. var endLabel = lineView._endLabel;
  40900. if (endLabel && hasAnimation) {
  40901. if (labelAnimationRecord_1.originalX != null) {
  40902. endLabel.attr({
  40903. x: labelAnimationRecord_1.originalX,
  40904. y: labelAnimationRecord_1.originalY
  40905. });
  40906. }
  40907. }
  40908. }, during);
  40909. // Expand clip shape to avoid clipping when line value exceeds axis
  40910. if (!seriesModel.get('clip', true)) {
  40911. var rectShape = clipPath.shape;
  40912. var expandSize = Math.max(rectShape.width, rectShape.height);
  40913. if (isHorizontal) {
  40914. rectShape.y -= expandSize;
  40915. rectShape.height += expandSize * 2;
  40916. } else {
  40917. rectShape.x -= expandSize;
  40918. rectShape.width += expandSize * 2;
  40919. }
  40920. }
  40921. // Set to the final frame. To make sure label layout is right.
  40922. if (during) {
  40923. during(1, clipPath);
  40924. }
  40925. return clipPath;
  40926. } else {
  40927. if ("development" !== 'production') {
  40928. if (seriesModel.get(['endLabel', 'show'])) {
  40929. console.warn('endLabel is not supported for lines in polar systems.');
  40930. }
  40931. }
  40932. return createPolarClipPath(coordSys, hasAnimation, seriesModel);
  40933. }
  40934. }
  40935. function getEndLabelStateSpecified(endLabelModel, coordSys) {
  40936. var baseAxis = coordSys.getBaseAxis();
  40937. var isHorizontal = baseAxis.isHorizontal();
  40938. var isBaseInversed = baseAxis.inverse;
  40939. var align = isHorizontal ? isBaseInversed ? 'right' : 'left' : 'center';
  40940. var verticalAlign = isHorizontal ? 'middle' : isBaseInversed ? 'top' : 'bottom';
  40941. return {
  40942. normal: {
  40943. align: endLabelModel.get('align') || align,
  40944. verticalAlign: endLabelModel.get('verticalAlign') || verticalAlign
  40945. }
  40946. };
  40947. }
  40948. var LineView = /** @class */function (_super) {
  40949. __extends(LineView, _super);
  40950. function LineView() {
  40951. return _super !== null && _super.apply(this, arguments) || this;
  40952. }
  40953. LineView.prototype.init = function () {
  40954. var lineGroup = new Group();
  40955. var symbolDraw = new SymbolDraw();
  40956. this.group.add(symbolDraw.group);
  40957. this._symbolDraw = symbolDraw;
  40958. this._lineGroup = lineGroup;
  40959. this._changePolyState = bind(this._changePolyState, this);
  40960. };
  40961. LineView.prototype.render = function (seriesModel, ecModel, api) {
  40962. var coordSys = seriesModel.coordinateSystem;
  40963. var group = this.group;
  40964. var data = seriesModel.getData();
  40965. var lineStyleModel = seriesModel.getModel('lineStyle');
  40966. var areaStyleModel = seriesModel.getModel('areaStyle');
  40967. var points = data.getLayout('points') || [];
  40968. var isCoordSysPolar = coordSys.type === 'polar';
  40969. var prevCoordSys = this._coordSys;
  40970. var symbolDraw = this._symbolDraw;
  40971. var polyline = this._polyline;
  40972. var polygon = this._polygon;
  40973. var lineGroup = this._lineGroup;
  40974. var hasAnimation = !ecModel.ssr && seriesModel.get('animation');
  40975. var isAreaChart = !areaStyleModel.isEmpty();
  40976. var valueOrigin = areaStyleModel.get('origin');
  40977. var dataCoordInfo = prepareDataCoordInfo(coordSys, data, valueOrigin);
  40978. var stackedOnPoints = isAreaChart && getStackedOnPoints(coordSys, data, dataCoordInfo);
  40979. var showSymbol = seriesModel.get('showSymbol');
  40980. var connectNulls = seriesModel.get('connectNulls');
  40981. var isIgnoreFunc = showSymbol && !isCoordSysPolar && getIsIgnoreFunc(seriesModel, data, coordSys);
  40982. // Remove temporary symbols
  40983. var oldData = this._data;
  40984. oldData && oldData.eachItemGraphicEl(function (el, idx) {
  40985. if (el.__temp) {
  40986. group.remove(el);
  40987. oldData.setItemGraphicEl(idx, null);
  40988. }
  40989. });
  40990. // Remove previous created symbols if showSymbol changed to false
  40991. if (!showSymbol) {
  40992. symbolDraw.remove();
  40993. }
  40994. group.add(lineGroup);
  40995. // FIXME step not support polar
  40996. var step = !isCoordSysPolar ? seriesModel.get('step') : false;
  40997. var clipShapeForSymbol;
  40998. if (coordSys && coordSys.getArea && seriesModel.get('clip', true)) {
  40999. clipShapeForSymbol = coordSys.getArea();
  41000. // Avoid float number rounding error for symbol on the edge of axis extent.
  41001. // See #7913 and `test/dataZoom-clip.html`.
  41002. if (clipShapeForSymbol.width != null) {
  41003. clipShapeForSymbol.x -= 0.1;
  41004. clipShapeForSymbol.y -= 0.1;
  41005. clipShapeForSymbol.width += 0.2;
  41006. clipShapeForSymbol.height += 0.2;
  41007. } else if (clipShapeForSymbol.r0) {
  41008. clipShapeForSymbol.r0 -= 0.5;
  41009. clipShapeForSymbol.r += 0.5;
  41010. }
  41011. }
  41012. this._clipShapeForSymbol = clipShapeForSymbol;
  41013. var visualColor = getVisualGradient(data, coordSys, api) || data.getVisual('style')[data.getVisual('drawType')];
  41014. // Initialization animation or coordinate system changed
  41015. if (!(polyline && prevCoordSys.type === coordSys.type && step === this._step)) {
  41016. showSymbol && symbolDraw.updateData(data, {
  41017. isIgnore: isIgnoreFunc,
  41018. clipShape: clipShapeForSymbol,
  41019. disableAnimation: true,
  41020. getSymbolPoint: function (idx) {
  41021. return [points[idx * 2], points[idx * 2 + 1]];
  41022. }
  41023. });
  41024. hasAnimation && this._initSymbolLabelAnimation(data, coordSys, clipShapeForSymbol);
  41025. if (step) {
  41026. if (stackedOnPoints) {
  41027. stackedOnPoints = turnPointsIntoStep(stackedOnPoints, points, coordSys, step, connectNulls);
  41028. }
  41029. // TODO If stacked series is not step
  41030. points = turnPointsIntoStep(points, null, coordSys, step, connectNulls);
  41031. }
  41032. polyline = this._newPolyline(points);
  41033. if (isAreaChart) {
  41034. polygon = this._newPolygon(points, stackedOnPoints);
  41035. } // If areaStyle is removed
  41036. else if (polygon) {
  41037. lineGroup.remove(polygon);
  41038. polygon = this._polygon = null;
  41039. }
  41040. // NOTE: Must update _endLabel before setClipPath.
  41041. if (!isCoordSysPolar) {
  41042. this._initOrUpdateEndLabel(seriesModel, coordSys, convertToColorString(visualColor));
  41043. }
  41044. lineGroup.setClipPath(createLineClipPath(this, coordSys, true, seriesModel));
  41045. } else {
  41046. if (isAreaChart && !polygon) {
  41047. // If areaStyle is added
  41048. polygon = this._newPolygon(points, stackedOnPoints);
  41049. } else if (polygon && !isAreaChart) {
  41050. // If areaStyle is removed
  41051. lineGroup.remove(polygon);
  41052. polygon = this._polygon = null;
  41053. }
  41054. // NOTE: Must update _endLabel before setClipPath.
  41055. if (!isCoordSysPolar) {
  41056. this._initOrUpdateEndLabel(seriesModel, coordSys, convertToColorString(visualColor));
  41057. }
  41058. // Update clipPath
  41059. var oldClipPath = lineGroup.getClipPath();
  41060. if (oldClipPath) {
  41061. var newClipPath = createLineClipPath(this, coordSys, false, seriesModel);
  41062. initProps(oldClipPath, {
  41063. shape: newClipPath.shape
  41064. }, seriesModel);
  41065. } else {
  41066. lineGroup.setClipPath(createLineClipPath(this, coordSys, true, seriesModel));
  41067. }
  41068. // Always update, or it is wrong in the case turning on legend
  41069. // because points are not changed.
  41070. showSymbol && symbolDraw.updateData(data, {
  41071. isIgnore: isIgnoreFunc,
  41072. clipShape: clipShapeForSymbol,
  41073. disableAnimation: true,
  41074. getSymbolPoint: function (idx) {
  41075. return [points[idx * 2], points[idx * 2 + 1]];
  41076. }
  41077. });
  41078. // In the case data zoom triggered refreshing frequently
  41079. // Data may not change if line has a category axis. So it should animate nothing.
  41080. if (!isPointsSame(this._stackedOnPoints, stackedOnPoints) || !isPointsSame(this._points, points)) {
  41081. if (hasAnimation) {
  41082. this._doUpdateAnimation(data, stackedOnPoints, coordSys, api, step, valueOrigin, connectNulls);
  41083. } else {
  41084. // Not do it in update with animation
  41085. if (step) {
  41086. if (stackedOnPoints) {
  41087. stackedOnPoints = turnPointsIntoStep(stackedOnPoints, points, coordSys, step, connectNulls);
  41088. }
  41089. // TODO If stacked series is not step
  41090. points = turnPointsIntoStep(points, null, coordSys, step, connectNulls);
  41091. }
  41092. polyline.setShape({
  41093. points: points
  41094. });
  41095. polygon && polygon.setShape({
  41096. points: points,
  41097. stackedOnPoints: stackedOnPoints
  41098. });
  41099. }
  41100. }
  41101. }
  41102. var emphasisModel = seriesModel.getModel('emphasis');
  41103. var focus = emphasisModel.get('focus');
  41104. var blurScope = emphasisModel.get('blurScope');
  41105. var emphasisDisabled = emphasisModel.get('disabled');
  41106. polyline.useStyle(defaults(
  41107. // Use color in lineStyle first
  41108. lineStyleModel.getLineStyle(), {
  41109. fill: 'none',
  41110. stroke: visualColor,
  41111. lineJoin: 'bevel'
  41112. }));
  41113. setStatesStylesFromModel(polyline, seriesModel, 'lineStyle');
  41114. if (polyline.style.lineWidth > 0 && seriesModel.get(['emphasis', 'lineStyle', 'width']) === 'bolder') {
  41115. var emphasisLineStyle = polyline.getState('emphasis').style;
  41116. emphasisLineStyle.lineWidth = +polyline.style.lineWidth + 1;
  41117. }
  41118. // Needs seriesIndex for focus
  41119. getECData(polyline).seriesIndex = seriesModel.seriesIndex;
  41120. toggleHoverEmphasis(polyline, focus, blurScope, emphasisDisabled);
  41121. var smooth = getSmooth(seriesModel.get('smooth'));
  41122. var smoothMonotone = seriesModel.get('smoothMonotone');
  41123. polyline.setShape({
  41124. smooth: smooth,
  41125. smoothMonotone: smoothMonotone,
  41126. connectNulls: connectNulls
  41127. });
  41128. if (polygon) {
  41129. var stackedOnSeries = data.getCalculationInfo('stackedOnSeries');
  41130. var stackedOnSmooth = 0;
  41131. polygon.useStyle(defaults(areaStyleModel.getAreaStyle(), {
  41132. fill: visualColor,
  41133. opacity: 0.7,
  41134. lineJoin: 'bevel',
  41135. decal: data.getVisual('style').decal
  41136. }));
  41137. if (stackedOnSeries) {
  41138. stackedOnSmooth = getSmooth(stackedOnSeries.get('smooth'));
  41139. }
  41140. polygon.setShape({
  41141. smooth: smooth,
  41142. stackedOnSmooth: stackedOnSmooth,
  41143. smoothMonotone: smoothMonotone,
  41144. connectNulls: connectNulls
  41145. });
  41146. setStatesStylesFromModel(polygon, seriesModel, 'areaStyle');
  41147. // Needs seriesIndex for focus
  41148. getECData(polygon).seriesIndex = seriesModel.seriesIndex;
  41149. toggleHoverEmphasis(polygon, focus, blurScope, emphasisDisabled);
  41150. }
  41151. var changePolyState = this._changePolyState;
  41152. data.eachItemGraphicEl(function (el) {
  41153. // Switch polyline / polygon state if element changed its state.
  41154. el && (el.onHoverStateChange = changePolyState);
  41155. });
  41156. this._polyline.onHoverStateChange = changePolyState;
  41157. this._data = data;
  41158. // Save the coordinate system for transition animation when data changed
  41159. this._coordSys = coordSys;
  41160. this._stackedOnPoints = stackedOnPoints;
  41161. this._points = points;
  41162. this._step = step;
  41163. this._valueOrigin = valueOrigin;
  41164. if (seriesModel.get('triggerLineEvent')) {
  41165. this.packEventData(seriesModel, polyline);
  41166. polygon && this.packEventData(seriesModel, polygon);
  41167. }
  41168. };
  41169. LineView.prototype.packEventData = function (seriesModel, el) {
  41170. getECData(el).eventData = {
  41171. componentType: 'series',
  41172. componentSubType: 'line',
  41173. componentIndex: seriesModel.componentIndex,
  41174. seriesIndex: seriesModel.seriesIndex,
  41175. seriesName: seriesModel.name,
  41176. seriesType: 'line'
  41177. };
  41178. };
  41179. LineView.prototype.highlight = function (seriesModel, ecModel, api, payload) {
  41180. var data = seriesModel.getData();
  41181. var dataIndex = queryDataIndex(data, payload);
  41182. this._changePolyState('emphasis');
  41183. if (!(dataIndex instanceof Array) && dataIndex != null && dataIndex >= 0) {
  41184. var points = data.getLayout('points');
  41185. var symbol = data.getItemGraphicEl(dataIndex);
  41186. if (!symbol) {
  41187. // Create a temporary symbol if it is not exists
  41188. var x = points[dataIndex * 2];
  41189. var y = points[dataIndex * 2 + 1];
  41190. if (isNaN(x) || isNaN(y)) {
  41191. // Null data
  41192. return;
  41193. }
  41194. // fix #11360: shouldn't draw symbol outside clipShapeForSymbol
  41195. if (this._clipShapeForSymbol && !this._clipShapeForSymbol.contain(x, y)) {
  41196. return;
  41197. }
  41198. var zlevel = seriesModel.get('zlevel') || 0;
  41199. var z = seriesModel.get('z') || 0;
  41200. symbol = new Symbol(data, dataIndex);
  41201. symbol.x = x;
  41202. symbol.y = y;
  41203. symbol.setZ(zlevel, z);
  41204. // ensure label text of the temporary symbol is in front of line and area polygon
  41205. var symbolLabel = symbol.getSymbolPath().getTextContent();
  41206. if (symbolLabel) {
  41207. symbolLabel.zlevel = zlevel;
  41208. symbolLabel.z = z;
  41209. symbolLabel.z2 = this._polyline.z2 + 1;
  41210. }
  41211. symbol.__temp = true;
  41212. data.setItemGraphicEl(dataIndex, symbol);
  41213. // Stop scale animation
  41214. symbol.stopSymbolAnimation(true);
  41215. this.group.add(symbol);
  41216. }
  41217. symbol.highlight();
  41218. } else {
  41219. // Highlight whole series
  41220. ChartView.prototype.highlight.call(this, seriesModel, ecModel, api, payload);
  41221. }
  41222. };
  41223. LineView.prototype.downplay = function (seriesModel, ecModel, api, payload) {
  41224. var data = seriesModel.getData();
  41225. var dataIndex = queryDataIndex(data, payload);
  41226. this._changePolyState('normal');
  41227. if (dataIndex != null && dataIndex >= 0) {
  41228. var symbol = data.getItemGraphicEl(dataIndex);
  41229. if (symbol) {
  41230. if (symbol.__temp) {
  41231. data.setItemGraphicEl(dataIndex, null);
  41232. this.group.remove(symbol);
  41233. } else {
  41234. symbol.downplay();
  41235. }
  41236. }
  41237. } else {
  41238. // FIXME
  41239. // can not downplay completely.
  41240. // Downplay whole series
  41241. ChartView.prototype.downplay.call(this, seriesModel, ecModel, api, payload);
  41242. }
  41243. };
  41244. LineView.prototype._changePolyState = function (toState) {
  41245. var polygon = this._polygon;
  41246. setStatesFlag(this._polyline, toState);
  41247. polygon && setStatesFlag(polygon, toState);
  41248. };
  41249. LineView.prototype._newPolyline = function (points) {
  41250. var polyline = this._polyline;
  41251. // Remove previous created polyline
  41252. if (polyline) {
  41253. this._lineGroup.remove(polyline);
  41254. }
  41255. polyline = new ECPolyline({
  41256. shape: {
  41257. points: points
  41258. },
  41259. segmentIgnoreThreshold: 2,
  41260. z2: 10
  41261. });
  41262. this._lineGroup.add(polyline);
  41263. this._polyline = polyline;
  41264. return polyline;
  41265. };
  41266. LineView.prototype._newPolygon = function (points, stackedOnPoints) {
  41267. var polygon = this._polygon;
  41268. // Remove previous created polygon
  41269. if (polygon) {
  41270. this._lineGroup.remove(polygon);
  41271. }
  41272. polygon = new ECPolygon({
  41273. shape: {
  41274. points: points,
  41275. stackedOnPoints: stackedOnPoints
  41276. },
  41277. segmentIgnoreThreshold: 2
  41278. });
  41279. this._lineGroup.add(polygon);
  41280. this._polygon = polygon;
  41281. return polygon;
  41282. };
  41283. LineView.prototype._initSymbolLabelAnimation = function (data, coordSys, clipShape) {
  41284. var isHorizontalOrRadial;
  41285. var isCoordSysPolar;
  41286. var baseAxis = coordSys.getBaseAxis();
  41287. var isAxisInverse = baseAxis.inverse;
  41288. if (coordSys.type === 'cartesian2d') {
  41289. isHorizontalOrRadial = baseAxis.isHorizontal();
  41290. isCoordSysPolar = false;
  41291. } else if (coordSys.type === 'polar') {
  41292. isHorizontalOrRadial = baseAxis.dim === 'angle';
  41293. isCoordSysPolar = true;
  41294. }
  41295. var seriesModel = data.hostModel;
  41296. var seriesDuration = seriesModel.get('animationDuration');
  41297. if (isFunction(seriesDuration)) {
  41298. seriesDuration = seriesDuration(null);
  41299. }
  41300. var seriesDelay = seriesModel.get('animationDelay') || 0;
  41301. var seriesDelayValue = isFunction(seriesDelay) ? seriesDelay(null) : seriesDelay;
  41302. data.eachItemGraphicEl(function (symbol, idx) {
  41303. var el = symbol;
  41304. if (el) {
  41305. var point = [symbol.x, symbol.y];
  41306. var start = void 0;
  41307. var end = void 0;
  41308. var current = void 0;
  41309. if (clipShape) {
  41310. if (isCoordSysPolar) {
  41311. var polarClip = clipShape;
  41312. var coord = coordSys.pointToCoord(point);
  41313. if (isHorizontalOrRadial) {
  41314. start = polarClip.startAngle;
  41315. end = polarClip.endAngle;
  41316. current = -coord[1] / 180 * Math.PI;
  41317. } else {
  41318. start = polarClip.r0;
  41319. end = polarClip.r;
  41320. current = coord[0];
  41321. }
  41322. } else {
  41323. var gridClip = clipShape;
  41324. if (isHorizontalOrRadial) {
  41325. start = gridClip.x;
  41326. end = gridClip.x + gridClip.width;
  41327. current = symbol.x;
  41328. } else {
  41329. start = gridClip.y + gridClip.height;
  41330. end = gridClip.y;
  41331. current = symbol.y;
  41332. }
  41333. }
  41334. }
  41335. var ratio = end === start ? 0 : (current - start) / (end - start);
  41336. if (isAxisInverse) {
  41337. ratio = 1 - ratio;
  41338. }
  41339. var delay = isFunction(seriesDelay) ? seriesDelay(idx) : seriesDuration * ratio + seriesDelayValue;
  41340. var symbolPath = el.getSymbolPath();
  41341. var text = symbolPath.getTextContent();
  41342. el.attr({
  41343. scaleX: 0,
  41344. scaleY: 0
  41345. });
  41346. el.animateTo({
  41347. scaleX: 1,
  41348. scaleY: 1
  41349. }, {
  41350. duration: 200,
  41351. setToFinal: true,
  41352. delay: delay
  41353. });
  41354. if (text) {
  41355. text.animateFrom({
  41356. style: {
  41357. opacity: 0
  41358. }
  41359. }, {
  41360. duration: 300,
  41361. delay: delay
  41362. });
  41363. }
  41364. symbolPath.disableLabelAnimation = true;
  41365. }
  41366. });
  41367. };
  41368. LineView.prototype._initOrUpdateEndLabel = function (seriesModel, coordSys, inheritColor) {
  41369. var endLabelModel = seriesModel.getModel('endLabel');
  41370. if (anyStateShowEndLabel(seriesModel)) {
  41371. var data_2 = seriesModel.getData();
  41372. var polyline = this._polyline;
  41373. // series may be filtered.
  41374. var points = data_2.getLayout('points');
  41375. if (!points) {
  41376. polyline.removeTextContent();
  41377. this._endLabel = null;
  41378. return;
  41379. }
  41380. var endLabel = this._endLabel;
  41381. if (!endLabel) {
  41382. endLabel = this._endLabel = new ZRText({
  41383. z2: 200 // should be higher than item symbol
  41384. });
  41385. endLabel.ignoreClip = true;
  41386. polyline.setTextContent(this._endLabel);
  41387. polyline.disableLabelAnimation = true;
  41388. }
  41389. // Find last non-NaN data to display data
  41390. var dataIndex = getLastIndexNotNull(points);
  41391. if (dataIndex >= 0) {
  41392. setLabelStyle(polyline, getLabelStatesModels(seriesModel, 'endLabel'), {
  41393. inheritColor: inheritColor,
  41394. labelFetcher: seriesModel,
  41395. labelDataIndex: dataIndex,
  41396. defaultText: function (dataIndex, opt, interpolatedValue) {
  41397. return interpolatedValue != null ? getDefaultInterpolatedLabel(data_2, interpolatedValue) : getDefaultLabel(data_2, dataIndex);
  41398. },
  41399. enableTextSetter: true
  41400. }, getEndLabelStateSpecified(endLabelModel, coordSys));
  41401. polyline.textConfig.position = null;
  41402. }
  41403. } else if (this._endLabel) {
  41404. this._polyline.removeTextContent();
  41405. this._endLabel = null;
  41406. }
  41407. };
  41408. LineView.prototype._endLabelOnDuring = function (percent, clipRect, data, animationRecord, valueAnimation, endLabelModel, coordSys) {
  41409. var endLabel = this._endLabel;
  41410. var polyline = this._polyline;
  41411. if (endLabel) {
  41412. // NOTE: Don't remove percent < 1. percent === 1 means the first frame during render.
  41413. // The label is not prepared at this time.
  41414. if (percent < 1 && animationRecord.originalX == null) {
  41415. animationRecord.originalX = endLabel.x;
  41416. animationRecord.originalY = endLabel.y;
  41417. }
  41418. var points = data.getLayout('points');
  41419. var seriesModel = data.hostModel;
  41420. var connectNulls = seriesModel.get('connectNulls');
  41421. var precision = endLabelModel.get('precision');
  41422. var distance = endLabelModel.get('distance') || 0;
  41423. var baseAxis = coordSys.getBaseAxis();
  41424. var isHorizontal = baseAxis.isHorizontal();
  41425. var isBaseInversed = baseAxis.inverse;
  41426. var clipShape = clipRect.shape;
  41427. var xOrY = isBaseInversed ? isHorizontal ? clipShape.x : clipShape.y + clipShape.height : isHorizontal ? clipShape.x + clipShape.width : clipShape.y;
  41428. var distanceX = (isHorizontal ? distance : 0) * (isBaseInversed ? -1 : 1);
  41429. var distanceY = (isHorizontal ? 0 : -distance) * (isBaseInversed ? -1 : 1);
  41430. var dim = isHorizontal ? 'x' : 'y';
  41431. var dataIndexRange = getIndexRange(points, xOrY, dim);
  41432. var indices = dataIndexRange.range;
  41433. var diff = indices[1] - indices[0];
  41434. var value = void 0;
  41435. if (diff >= 1) {
  41436. // diff > 1 && connectNulls, which is on the null data.
  41437. if (diff > 1 && !connectNulls) {
  41438. var pt = getPointAtIndex(points, indices[0]);
  41439. endLabel.attr({
  41440. x: pt[0] + distanceX,
  41441. y: pt[1] + distanceY
  41442. });
  41443. valueAnimation && (value = seriesModel.getRawValue(indices[0]));
  41444. } else {
  41445. var pt = polyline.getPointOn(xOrY, dim);
  41446. pt && endLabel.attr({
  41447. x: pt[0] + distanceX,
  41448. y: pt[1] + distanceY
  41449. });
  41450. var startValue = seriesModel.getRawValue(indices[0]);
  41451. var endValue = seriesModel.getRawValue(indices[1]);
  41452. valueAnimation && (value = interpolateRawValues(data, precision, startValue, endValue, dataIndexRange.t));
  41453. }
  41454. animationRecord.lastFrameIndex = indices[0];
  41455. } else {
  41456. // If diff <= 0, which is the range is not found(Include NaN)
  41457. // Choose the first point or last point.
  41458. var idx = percent === 1 || animationRecord.lastFrameIndex > 0 ? indices[0] : 0;
  41459. var pt = getPointAtIndex(points, idx);
  41460. valueAnimation && (value = seriesModel.getRawValue(idx));
  41461. endLabel.attr({
  41462. x: pt[0] + distanceX,
  41463. y: pt[1] + distanceY
  41464. });
  41465. }
  41466. if (valueAnimation) {
  41467. var inner = labelInner(endLabel);
  41468. if (typeof inner.setLabelText === 'function') {
  41469. inner.setLabelText(value);
  41470. }
  41471. }
  41472. }
  41473. };
  41474. /**
  41475. * @private
  41476. */
  41477. // FIXME Two value axis
  41478. LineView.prototype._doUpdateAnimation = function (data, stackedOnPoints, coordSys, api, step, valueOrigin, connectNulls) {
  41479. var polyline = this._polyline;
  41480. var polygon = this._polygon;
  41481. var seriesModel = data.hostModel;
  41482. var diff = lineAnimationDiff(this._data, data, this._stackedOnPoints, stackedOnPoints, this._coordSys, coordSys, this._valueOrigin);
  41483. var current = diff.current;
  41484. var stackedOnCurrent = diff.stackedOnCurrent;
  41485. var next = diff.next;
  41486. var stackedOnNext = diff.stackedOnNext;
  41487. if (step) {
  41488. // TODO If stacked series is not step
  41489. stackedOnCurrent = turnPointsIntoStep(diff.stackedOnCurrent, diff.current, coordSys, step, connectNulls);
  41490. current = turnPointsIntoStep(diff.current, null, coordSys, step, connectNulls);
  41491. stackedOnNext = turnPointsIntoStep(diff.stackedOnNext, diff.next, coordSys, step, connectNulls);
  41492. next = turnPointsIntoStep(diff.next, null, coordSys, step, connectNulls);
  41493. }
  41494. // Don't apply animation if diff is large.
  41495. // For better result and avoid memory explosion problems like
  41496. // https://github.com/apache/incubator-echarts/issues/12229
  41497. if (getBoundingDiff(current, next) > 3000 || polygon && getBoundingDiff(stackedOnCurrent, stackedOnNext) > 3000) {
  41498. polyline.stopAnimation();
  41499. polyline.setShape({
  41500. points: next
  41501. });
  41502. if (polygon) {
  41503. polygon.stopAnimation();
  41504. polygon.setShape({
  41505. points: next,
  41506. stackedOnPoints: stackedOnNext
  41507. });
  41508. }
  41509. return;
  41510. }
  41511. polyline.shape.__points = diff.current;
  41512. polyline.shape.points = current;
  41513. var target = {
  41514. shape: {
  41515. points: next
  41516. }
  41517. };
  41518. // Also animate the original points.
  41519. // If points reference is changed when turning into step line.
  41520. if (diff.current !== current) {
  41521. target.shape.__points = diff.next;
  41522. }
  41523. // Stop previous animation.
  41524. polyline.stopAnimation();
  41525. updateProps(polyline, target, seriesModel);
  41526. if (polygon) {
  41527. polygon.setShape({
  41528. // Reuse the points with polyline.
  41529. points: current,
  41530. stackedOnPoints: stackedOnCurrent
  41531. });
  41532. polygon.stopAnimation();
  41533. updateProps(polygon, {
  41534. shape: {
  41535. stackedOnPoints: stackedOnNext
  41536. }
  41537. }, seriesModel);
  41538. // If use attr directly in updateProps.
  41539. if (polyline.shape.points !== polygon.shape.points) {
  41540. polygon.shape.points = polyline.shape.points;
  41541. }
  41542. }
  41543. var updatedDataInfo = [];
  41544. var diffStatus = diff.status;
  41545. for (var i = 0; i < diffStatus.length; i++) {
  41546. var cmd = diffStatus[i].cmd;
  41547. if (cmd === '=') {
  41548. var el = data.getItemGraphicEl(diffStatus[i].idx1);
  41549. if (el) {
  41550. updatedDataInfo.push({
  41551. el: el,
  41552. ptIdx: i // Index of points
  41553. });
  41554. }
  41555. }
  41556. }
  41557. if (polyline.animators && polyline.animators.length) {
  41558. polyline.animators[0].during(function () {
  41559. polygon && polygon.dirtyShape();
  41560. var points = polyline.shape.__points;
  41561. for (var i = 0; i < updatedDataInfo.length; i++) {
  41562. var el = updatedDataInfo[i].el;
  41563. var offset = updatedDataInfo[i].ptIdx * 2;
  41564. el.x = points[offset];
  41565. el.y = points[offset + 1];
  41566. el.markRedraw();
  41567. }
  41568. });
  41569. }
  41570. };
  41571. LineView.prototype.remove = function (ecModel) {
  41572. var group = this.group;
  41573. var oldData = this._data;
  41574. this._lineGroup.removeAll();
  41575. this._symbolDraw.remove(true);
  41576. // Remove temporary created elements when highlighting
  41577. oldData && oldData.eachItemGraphicEl(function (el, idx) {
  41578. if (el.__temp) {
  41579. group.remove(el);
  41580. oldData.setItemGraphicEl(idx, null);
  41581. }
  41582. });
  41583. this._polyline = this._polygon = this._coordSys = this._points = this._stackedOnPoints = this._endLabel = this._data = null;
  41584. };
  41585. LineView.type = 'line';
  41586. return LineView;
  41587. }(ChartView);
  41588. function pointsLayout(seriesType, forceStoreInTypedArray) {
  41589. return {
  41590. seriesType: seriesType,
  41591. plan: createRenderPlanner(),
  41592. reset: function (seriesModel) {
  41593. var data = seriesModel.getData();
  41594. var coordSys = seriesModel.coordinateSystem;
  41595. var pipelineContext = seriesModel.pipelineContext;
  41596. var useTypedArray = forceStoreInTypedArray || pipelineContext.large;
  41597. if (!coordSys) {
  41598. return;
  41599. }
  41600. var dims = map(coordSys.dimensions, function (dim) {
  41601. return data.mapDimension(dim);
  41602. }).slice(0, 2);
  41603. var dimLen = dims.length;
  41604. var stackResultDim = data.getCalculationInfo('stackResultDimension');
  41605. if (isDimensionStacked(data, dims[0])) {
  41606. dims[0] = stackResultDim;
  41607. }
  41608. if (isDimensionStacked(data, dims[1])) {
  41609. dims[1] = stackResultDim;
  41610. }
  41611. var store = data.getStore();
  41612. var dimIdx0 = data.getDimensionIndex(dims[0]);
  41613. var dimIdx1 = data.getDimensionIndex(dims[1]);
  41614. return dimLen && {
  41615. progress: function (params, data) {
  41616. var segCount = params.end - params.start;
  41617. var points = useTypedArray && createFloat32Array(segCount * dimLen);
  41618. var tmpIn = [];
  41619. var tmpOut = [];
  41620. for (var i = params.start, offset = 0; i < params.end; i++) {
  41621. var point = void 0;
  41622. if (dimLen === 1) {
  41623. var x = store.get(dimIdx0, i);
  41624. // NOTE: Make sure the second parameter is null to use default strategy.
  41625. point = coordSys.dataToPoint(x, null, tmpOut);
  41626. } else {
  41627. tmpIn[0] = store.get(dimIdx0, i);
  41628. tmpIn[1] = store.get(dimIdx1, i);
  41629. // Let coordinate system to handle the NaN data.
  41630. point = coordSys.dataToPoint(tmpIn, null, tmpOut);
  41631. }
  41632. if (useTypedArray) {
  41633. points[offset++] = point[0];
  41634. points[offset++] = point[1];
  41635. } else {
  41636. data.setItemLayout(i, point.slice());
  41637. }
  41638. }
  41639. useTypedArray && data.setLayout('points', points);
  41640. }
  41641. };
  41642. }
  41643. };
  41644. }
  41645. var samplers = {
  41646. average: function (frame) {
  41647. var sum = 0;
  41648. var count = 0;
  41649. for (var i = 0; i < frame.length; i++) {
  41650. if (!isNaN(frame[i])) {
  41651. sum += frame[i];
  41652. count++;
  41653. }
  41654. }
  41655. // Return NaN if count is 0
  41656. return count === 0 ? NaN : sum / count;
  41657. },
  41658. sum: function (frame) {
  41659. var sum = 0;
  41660. for (var i = 0; i < frame.length; i++) {
  41661. // Ignore NaN
  41662. sum += frame[i] || 0;
  41663. }
  41664. return sum;
  41665. },
  41666. max: function (frame) {
  41667. var max = -Infinity;
  41668. for (var i = 0; i < frame.length; i++) {
  41669. frame[i] > max && (max = frame[i]);
  41670. }
  41671. // NaN will cause illegal axis extent.
  41672. return isFinite(max) ? max : NaN;
  41673. },
  41674. min: function (frame) {
  41675. var min = Infinity;
  41676. for (var i = 0; i < frame.length; i++) {
  41677. frame[i] < min && (min = frame[i]);
  41678. }
  41679. // NaN will cause illegal axis extent.
  41680. return isFinite(min) ? min : NaN;
  41681. },
  41682. // TODO
  41683. // Median
  41684. nearest: function (frame) {
  41685. return frame[0];
  41686. }
  41687. };
  41688. var indexSampler = function (frame) {
  41689. return Math.round(frame.length / 2);
  41690. };
  41691. function dataSample(seriesType) {
  41692. return {
  41693. seriesType: seriesType,
  41694. // FIXME:TS never used, so comment it
  41695. // modifyOutputEnd: true,
  41696. reset: function (seriesModel, ecModel, api) {
  41697. var data = seriesModel.getData();
  41698. var sampling = seriesModel.get('sampling');
  41699. var coordSys = seriesModel.coordinateSystem;
  41700. var count = data.count();
  41701. // Only cartesian2d support down sampling. Disable it when there is few data.
  41702. if (count > 10 && coordSys.type === 'cartesian2d' && sampling) {
  41703. var baseAxis = coordSys.getBaseAxis();
  41704. var valueAxis = coordSys.getOtherAxis(baseAxis);
  41705. var extent = baseAxis.getExtent();
  41706. var dpr = api.getDevicePixelRatio();
  41707. // Coordinste system has been resized
  41708. var size = Math.abs(extent[1] - extent[0]) * (dpr || 1);
  41709. var rate = Math.round(count / size);
  41710. if (isFinite(rate) && rate > 1) {
  41711. if (sampling === 'lttb') {
  41712. seriesModel.setData(data.lttbDownSample(data.mapDimension(valueAxis.dim), 1 / rate));
  41713. } else if (sampling === 'minmax') {
  41714. seriesModel.setData(data.minmaxDownSample(data.mapDimension(valueAxis.dim), 1 / rate));
  41715. }
  41716. var sampler = void 0;
  41717. if (isString(sampling)) {
  41718. sampler = samplers[sampling];
  41719. } else if (isFunction(sampling)) {
  41720. sampler = sampling;
  41721. }
  41722. if (sampler) {
  41723. // Only support sample the first dim mapped from value axis.
  41724. seriesModel.setData(data.downSample(data.mapDimension(valueAxis.dim), 1 / rate, sampler, indexSampler));
  41725. }
  41726. }
  41727. }
  41728. }
  41729. };
  41730. }
  41731. function install$2(registers) {
  41732. registers.registerChartView(LineView);
  41733. registers.registerSeriesModel(LineSeriesModel);
  41734. registers.registerLayout(pointsLayout('line', true));
  41735. registers.registerVisual({
  41736. seriesType: 'line',
  41737. reset: function (seriesModel) {
  41738. var data = seriesModel.getData();
  41739. // Visual coding for legend
  41740. var lineStyle = seriesModel.getModel('lineStyle').getLineStyle();
  41741. if (lineStyle && !lineStyle.stroke) {
  41742. // Fill in visual should be palette color if
  41743. // has color callback
  41744. lineStyle.stroke = data.getVisual('style').fill;
  41745. }
  41746. data.setVisual('legendLineStyle', lineStyle);
  41747. }
  41748. });
  41749. // Down sample after filter
  41750. registers.registerProcessor(registers.PRIORITY.PROCESSOR.STATISTIC, dataSample('line'));
  41751. }
  41752. var BaseBarSeriesModel = /** @class */function (_super) {
  41753. __extends(BaseBarSeriesModel, _super);
  41754. function BaseBarSeriesModel() {
  41755. var _this = _super !== null && _super.apply(this, arguments) || this;
  41756. _this.type = BaseBarSeriesModel.type;
  41757. return _this;
  41758. }
  41759. BaseBarSeriesModel.prototype.getInitialData = function (option, ecModel) {
  41760. return createSeriesData(null, this, {
  41761. useEncodeDefaulter: true
  41762. });
  41763. };
  41764. BaseBarSeriesModel.prototype.getMarkerPosition = function (value, dims, startingAtTick) {
  41765. var coordSys = this.coordinateSystem;
  41766. if (coordSys && coordSys.clampData) {
  41767. // PENDING if clamp ?
  41768. var clampData_1 = coordSys.clampData(value);
  41769. var pt_1 = coordSys.dataToPoint(clampData_1);
  41770. if (startingAtTick) {
  41771. each(coordSys.getAxes(), function (axis, idx) {
  41772. // If axis type is category, use tick coords instead
  41773. if (axis.type === 'category' && dims != null) {
  41774. var tickCoords = axis.getTicksCoords();
  41775. var alignTicksWithLabel = axis.getTickModel().get('alignWithLabel');
  41776. var targetTickId = clampData_1[idx];
  41777. // The index of rightmost tick of markArea is 1 larger than x1/y1 index
  41778. var isEnd = dims[idx] === 'x1' || dims[idx] === 'y1';
  41779. if (isEnd && !alignTicksWithLabel) {
  41780. targetTickId += 1;
  41781. }
  41782. // The only contains one tick, tickCoords is
  41783. // like [{coord: 0, tickValue: 0}, {coord: 0}]
  41784. // to the length should always be larger than 1
  41785. if (tickCoords.length < 2) {
  41786. return;
  41787. } else if (tickCoords.length === 2) {
  41788. // The left value and right value of the axis are
  41789. // the same. coord is 0 in both items. Use the max
  41790. // value of the axis as the coord
  41791. pt_1[idx] = axis.toGlobalCoord(axis.getExtent()[isEnd ? 1 : 0]);
  41792. return;
  41793. }
  41794. var leftCoord = void 0;
  41795. var coord = void 0;
  41796. var stepTickValue = 1;
  41797. for (var i = 0; i < tickCoords.length; i++) {
  41798. var tickCoord = tickCoords[i].coord;
  41799. // The last item of tickCoords doesn't contain
  41800. // tickValue
  41801. var tickValue = i === tickCoords.length - 1 ? tickCoords[i - 1].tickValue + stepTickValue : tickCoords[i].tickValue;
  41802. if (tickValue === targetTickId) {
  41803. coord = tickCoord;
  41804. break;
  41805. } else if (tickValue < targetTickId) {
  41806. leftCoord = tickCoord;
  41807. } else if (leftCoord != null && tickValue > targetTickId) {
  41808. coord = (tickCoord + leftCoord) / 2;
  41809. break;
  41810. }
  41811. if (i === 1) {
  41812. // Here we assume the step of category axes is
  41813. // the same
  41814. stepTickValue = tickValue - tickCoords[0].tickValue;
  41815. }
  41816. }
  41817. if (coord == null) {
  41818. if (!leftCoord) {
  41819. // targetTickId is smaller than all tick ids in the
  41820. // visible area, use the leftmost tick coord
  41821. coord = tickCoords[0].coord;
  41822. } else if (leftCoord) {
  41823. // targetTickId is larger than all tick ids in the
  41824. // visible area, use the rightmost tick coord
  41825. coord = tickCoords[tickCoords.length - 1].coord;
  41826. }
  41827. }
  41828. pt_1[idx] = axis.toGlobalCoord(coord);
  41829. }
  41830. });
  41831. } else {
  41832. var data = this.getData();
  41833. var offset = data.getLayout('offset');
  41834. var size = data.getLayout('size');
  41835. var offsetIndex = coordSys.getBaseAxis().isHorizontal() ? 0 : 1;
  41836. pt_1[offsetIndex] += offset + size / 2;
  41837. }
  41838. return pt_1;
  41839. }
  41840. return [NaN, NaN];
  41841. };
  41842. BaseBarSeriesModel.type = 'series.__base_bar__';
  41843. BaseBarSeriesModel.defaultOption = {
  41844. // zlevel: 0,
  41845. z: 2,
  41846. coordinateSystem: 'cartesian2d',
  41847. legendHoverLink: true,
  41848. // stack: null
  41849. // Cartesian coordinate system
  41850. // xAxisIndex: 0,
  41851. // yAxisIndex: 0,
  41852. barMinHeight: 0,
  41853. barMinAngle: 0,
  41854. // cursor: null,
  41855. large: false,
  41856. largeThreshold: 400,
  41857. progressive: 3e3,
  41858. progressiveChunkMode: 'mod',
  41859. defaultBarGap: '10%'
  41860. };
  41861. return BaseBarSeriesModel;
  41862. }(SeriesModel);
  41863. SeriesModel.registerClass(BaseBarSeriesModel);
  41864. var BarSeriesModel = /** @class */function (_super) {
  41865. __extends(BarSeriesModel, _super);
  41866. function BarSeriesModel() {
  41867. var _this = _super !== null && _super.apply(this, arguments) || this;
  41868. _this.type = BarSeriesModel.type;
  41869. return _this;
  41870. }
  41871. BarSeriesModel.prototype.getInitialData = function () {
  41872. return createSeriesData(null, this, {
  41873. useEncodeDefaulter: true,
  41874. createInvertedIndices: !!this.get('realtimeSort', true) || null
  41875. });
  41876. };
  41877. /**
  41878. * @override
  41879. */
  41880. BarSeriesModel.prototype.getProgressive = function () {
  41881. // Do not support progressive in normal mode.
  41882. return this.get('large') ? this.get('progressive') : false;
  41883. };
  41884. /**
  41885. * @override
  41886. */
  41887. BarSeriesModel.prototype.getProgressiveThreshold = function () {
  41888. // Do not support progressive in normal mode.
  41889. var progressiveThreshold = this.get('progressiveThreshold');
  41890. var largeThreshold = this.get('largeThreshold');
  41891. if (largeThreshold > progressiveThreshold) {
  41892. progressiveThreshold = largeThreshold;
  41893. }
  41894. return progressiveThreshold;
  41895. };
  41896. BarSeriesModel.prototype.brushSelector = function (dataIndex, data, selectors) {
  41897. return selectors.rect(data.getItemLayout(dataIndex));
  41898. };
  41899. BarSeriesModel.type = 'series.bar';
  41900. BarSeriesModel.dependencies = ['grid', 'polar'];
  41901. BarSeriesModel.defaultOption = inheritDefaultOption(BaseBarSeriesModel.defaultOption, {
  41902. // If clipped
  41903. // Only available on cartesian2d
  41904. clip: true,
  41905. roundCap: false,
  41906. showBackground: false,
  41907. backgroundStyle: {
  41908. color: 'rgba(180, 180, 180, 0.2)',
  41909. borderColor: null,
  41910. borderWidth: 0,
  41911. borderType: 'solid',
  41912. borderRadius: 0,
  41913. shadowBlur: 0,
  41914. shadowColor: null,
  41915. shadowOffsetX: 0,
  41916. shadowOffsetY: 0,
  41917. opacity: 1
  41918. },
  41919. select: {
  41920. itemStyle: {
  41921. borderColor: tokens.color.primary,
  41922. borderWidth: 2
  41923. }
  41924. },
  41925. realtimeSort: false
  41926. });
  41927. return BarSeriesModel;
  41928. }(BaseBarSeriesModel);
  41929. /**
  41930. * Sausage: similar to sector, but have half circle on both sides
  41931. */
  41932. var SausageShape = /** @class */function () {
  41933. function SausageShape() {
  41934. this.cx = 0;
  41935. this.cy = 0;
  41936. this.r0 = 0;
  41937. this.r = 0;
  41938. this.startAngle = 0;
  41939. this.endAngle = Math.PI * 2;
  41940. this.clockwise = true;
  41941. }
  41942. return SausageShape;
  41943. }();
  41944. var SausagePath = /** @class */function (_super) {
  41945. __extends(SausagePath, _super);
  41946. function SausagePath(opts) {
  41947. var _this = _super.call(this, opts) || this;
  41948. _this.type = 'sausage';
  41949. return _this;
  41950. }
  41951. SausagePath.prototype.getDefaultShape = function () {
  41952. return new SausageShape();
  41953. };
  41954. SausagePath.prototype.buildPath = function (ctx, shape) {
  41955. var cx = shape.cx;
  41956. var cy = shape.cy;
  41957. var r0 = Math.max(shape.r0 || 0, 0);
  41958. var r = Math.max(shape.r, 0);
  41959. var dr = (r - r0) * 0.5;
  41960. var rCenter = r0 + dr;
  41961. var startAngle = shape.startAngle;
  41962. var endAngle = shape.endAngle;
  41963. var clockwise = shape.clockwise;
  41964. var PI2 = Math.PI * 2;
  41965. var lessThanCircle = clockwise ? endAngle - startAngle < PI2 : startAngle - endAngle < PI2;
  41966. if (!lessThanCircle) {
  41967. // Normalize angles
  41968. startAngle = endAngle - (clockwise ? PI2 : -PI2);
  41969. }
  41970. var unitStartX = Math.cos(startAngle);
  41971. var unitStartY = Math.sin(startAngle);
  41972. var unitEndX = Math.cos(endAngle);
  41973. var unitEndY = Math.sin(endAngle);
  41974. if (lessThanCircle) {
  41975. ctx.moveTo(unitStartX * r0 + cx, unitStartY * r0 + cy);
  41976. ctx.arc(unitStartX * rCenter + cx, unitStartY * rCenter + cy, dr, -Math.PI + startAngle, startAngle, !clockwise);
  41977. } else {
  41978. ctx.moveTo(unitStartX * r + cx, unitStartY * r + cy);
  41979. }
  41980. ctx.arc(cx, cy, r, startAngle, endAngle, !clockwise);
  41981. ctx.arc(unitEndX * rCenter + cx, unitEndY * rCenter + cy, dr, endAngle - Math.PI * 2, endAngle - Math.PI, !clockwise);
  41982. if (r0 !== 0) {
  41983. ctx.arc(cx, cy, r0, endAngle, startAngle, clockwise);
  41984. }
  41985. // ctx.closePath();
  41986. };
  41987. return SausagePath;
  41988. }(Path);
  41989. function createSectorCalculateTextPosition(positionMapping, opts) {
  41990. opts = opts || {};
  41991. var isRoundCap = opts.isRoundCap;
  41992. return function (out, opts, boundingRect) {
  41993. var textPosition = opts.position;
  41994. if (!textPosition || textPosition instanceof Array) {
  41995. return calculateTextPosition(out, opts, boundingRect);
  41996. }
  41997. var mappedSectorPosition = positionMapping(textPosition);
  41998. var distance = opts.distance != null ? opts.distance : 5;
  41999. var sector = this.shape;
  42000. var cx = sector.cx;
  42001. var cy = sector.cy;
  42002. var r = sector.r;
  42003. var r0 = sector.r0;
  42004. var middleR = (r + r0) / 2;
  42005. var startAngle = sector.startAngle;
  42006. var endAngle = sector.endAngle;
  42007. var middleAngle = (startAngle + endAngle) / 2;
  42008. var extraDist = isRoundCap ? Math.abs(r - r0) / 2 : 0;
  42009. var mathCos = Math.cos;
  42010. var mathSin = Math.sin;
  42011. // base position: top-left
  42012. var x = cx + r * mathCos(startAngle);
  42013. var y = cy + r * mathSin(startAngle);
  42014. var textAlign = 'left';
  42015. var textVerticalAlign = 'top';
  42016. switch (mappedSectorPosition) {
  42017. case 'startArc':
  42018. x = cx + (r0 - distance) * mathCos(middleAngle);
  42019. y = cy + (r0 - distance) * mathSin(middleAngle);
  42020. textAlign = 'center';
  42021. textVerticalAlign = 'top';
  42022. break;
  42023. case 'insideStartArc':
  42024. x = cx + (r0 + distance) * mathCos(middleAngle);
  42025. y = cy + (r0 + distance) * mathSin(middleAngle);
  42026. textAlign = 'center';
  42027. textVerticalAlign = 'bottom';
  42028. break;
  42029. case 'startAngle':
  42030. x = cx + middleR * mathCos(startAngle) + adjustAngleDistanceX(startAngle, distance + extraDist, false);
  42031. y = cy + middleR * mathSin(startAngle) + adjustAngleDistanceY(startAngle, distance + extraDist, false);
  42032. textAlign = 'right';
  42033. textVerticalAlign = 'middle';
  42034. break;
  42035. case 'insideStartAngle':
  42036. x = cx + middleR * mathCos(startAngle) + adjustAngleDistanceX(startAngle, -distance + extraDist, false);
  42037. y = cy + middleR * mathSin(startAngle) + adjustAngleDistanceY(startAngle, -distance + extraDist, false);
  42038. textAlign = 'left';
  42039. textVerticalAlign = 'middle';
  42040. break;
  42041. case 'middle':
  42042. x = cx + middleR * mathCos(middleAngle);
  42043. y = cy + middleR * mathSin(middleAngle);
  42044. textAlign = 'center';
  42045. textVerticalAlign = 'middle';
  42046. break;
  42047. case 'endArc':
  42048. x = cx + (r + distance) * mathCos(middleAngle);
  42049. y = cy + (r + distance) * mathSin(middleAngle);
  42050. textAlign = 'center';
  42051. textVerticalAlign = 'bottom';
  42052. break;
  42053. case 'insideEndArc':
  42054. x = cx + (r - distance) * mathCos(middleAngle);
  42055. y = cy + (r - distance) * mathSin(middleAngle);
  42056. textAlign = 'center';
  42057. textVerticalAlign = 'top';
  42058. break;
  42059. case 'endAngle':
  42060. x = cx + middleR * mathCos(endAngle) + adjustAngleDistanceX(endAngle, distance + extraDist, true);
  42061. y = cy + middleR * mathSin(endAngle) + adjustAngleDistanceY(endAngle, distance + extraDist, true);
  42062. textAlign = 'left';
  42063. textVerticalAlign = 'middle';
  42064. break;
  42065. case 'insideEndAngle':
  42066. x = cx + middleR * mathCos(endAngle) + adjustAngleDistanceX(endAngle, -distance + extraDist, true);
  42067. y = cy + middleR * mathSin(endAngle) + adjustAngleDistanceY(endAngle, -distance + extraDist, true);
  42068. textAlign = 'right';
  42069. textVerticalAlign = 'middle';
  42070. break;
  42071. default:
  42072. return calculateTextPosition(out, opts, boundingRect);
  42073. }
  42074. out = out || {};
  42075. out.x = x;
  42076. out.y = y;
  42077. out.align = textAlign;
  42078. out.verticalAlign = textVerticalAlign;
  42079. return out;
  42080. };
  42081. }
  42082. function setSectorTextRotation(sector, textPosition, positionMapping, rotateType) {
  42083. if (isNumber(rotateType)) {
  42084. // user-set rotation
  42085. sector.setTextConfig({
  42086. rotation: rotateType
  42087. });
  42088. return;
  42089. } else if (isArray(textPosition)) {
  42090. // user-set position, use 0 as auto rotation
  42091. sector.setTextConfig({
  42092. rotation: 0
  42093. });
  42094. return;
  42095. }
  42096. var shape = sector.shape;
  42097. var startAngle = shape.clockwise ? shape.startAngle : shape.endAngle;
  42098. var endAngle = shape.clockwise ? shape.endAngle : shape.startAngle;
  42099. var middleAngle = (startAngle + endAngle) / 2;
  42100. var anchorAngle;
  42101. var mappedSectorPosition = positionMapping(textPosition);
  42102. switch (mappedSectorPosition) {
  42103. case 'startArc':
  42104. case 'insideStartArc':
  42105. case 'middle':
  42106. case 'insideEndArc':
  42107. case 'endArc':
  42108. anchorAngle = middleAngle;
  42109. break;
  42110. case 'startAngle':
  42111. case 'insideStartAngle':
  42112. anchorAngle = startAngle;
  42113. break;
  42114. case 'endAngle':
  42115. case 'insideEndAngle':
  42116. anchorAngle = endAngle;
  42117. break;
  42118. default:
  42119. sector.setTextConfig({
  42120. rotation: 0
  42121. });
  42122. return;
  42123. }
  42124. var rotate = Math.PI * 1.5 - anchorAngle;
  42125. /**
  42126. * TODO: labels with rotate > Math.PI / 2 should be rotate another
  42127. * half round flipped to increase readability. However, only middle
  42128. * position supports this for now, because in other positions, the
  42129. * anchor point is not at the center of the text, so the positions
  42130. * after rotating is not as expected.
  42131. */
  42132. if (mappedSectorPosition === 'middle' && rotate > Math.PI / 2 && rotate < Math.PI * 1.5) {
  42133. rotate -= Math.PI;
  42134. }
  42135. sector.setTextConfig({
  42136. rotation: rotate
  42137. });
  42138. }
  42139. function adjustAngleDistanceX(angle, distance, isEnd) {
  42140. return distance * Math.sin(angle) * (isEnd ? -1 : 1);
  42141. }
  42142. function adjustAngleDistanceY(angle, distance, isEnd) {
  42143. return distance * Math.cos(angle) * (isEnd ? 1 : -1);
  42144. }
  42145. function getSectorCornerRadius(model, shape, zeroIfNull) {
  42146. var cornerRadius = model.get('borderRadius');
  42147. if (cornerRadius == null) {
  42148. return zeroIfNull ? {
  42149. cornerRadius: 0
  42150. } : null;
  42151. }
  42152. if (!isArray(cornerRadius)) {
  42153. cornerRadius = [cornerRadius, cornerRadius, cornerRadius, cornerRadius];
  42154. }
  42155. var dr = Math.abs(shape.r || 0 - shape.r0 || 0);
  42156. return {
  42157. cornerRadius: map(cornerRadius, function (cr) {
  42158. return parsePercent(cr, dr);
  42159. })
  42160. };
  42161. }
  42162. var mathMax$7 = Math.max;
  42163. var mathMin$7 = Math.min;
  42164. function getClipArea(coord, data) {
  42165. var coordSysClipArea = coord.getArea && coord.getArea();
  42166. if (isCoordinateSystemType(coord, 'cartesian2d')) {
  42167. var baseAxis = coord.getBaseAxis();
  42168. // When boundaryGap is false or using time axis. bar may exceed the grid.
  42169. // We should not clip this part.
  42170. // See test/bar2.html
  42171. if (baseAxis.type !== 'category' || !baseAxis.onBand) {
  42172. var expandWidth = data.getLayout('bandWidth');
  42173. if (baseAxis.isHorizontal()) {
  42174. coordSysClipArea.x -= expandWidth;
  42175. coordSysClipArea.width += expandWidth * 2;
  42176. } else {
  42177. coordSysClipArea.y -= expandWidth;
  42178. coordSysClipArea.height += expandWidth * 2;
  42179. }
  42180. }
  42181. }
  42182. return coordSysClipArea;
  42183. }
  42184. var BarView = /** @class */function (_super) {
  42185. __extends(BarView, _super);
  42186. function BarView() {
  42187. var _this = _super.call(this) || this;
  42188. _this.type = BarView.type;
  42189. _this._isFirstFrame = true;
  42190. return _this;
  42191. }
  42192. BarView.prototype.render = function (seriesModel, ecModel, api, payload) {
  42193. this._model = seriesModel;
  42194. this._removeOnRenderedListener(api);
  42195. this._updateDrawMode(seriesModel);
  42196. var coordinateSystemType = seriesModel.get('coordinateSystem');
  42197. if (coordinateSystemType === 'cartesian2d' || coordinateSystemType === 'polar') {
  42198. // Clear previously rendered progressive elements.
  42199. this._progressiveEls = null;
  42200. this._isLargeDraw ? this._renderLarge(seriesModel, ecModel, api) : this._renderNormal(seriesModel, ecModel, api, payload);
  42201. } else if ("development" !== 'production') {
  42202. warn('Only cartesian2d and polar supported for bar.');
  42203. }
  42204. };
  42205. BarView.prototype.incrementalPrepareRender = function (seriesModel) {
  42206. this._clear();
  42207. this._updateDrawMode(seriesModel);
  42208. // incremental also need to clip, otherwise might be overlow.
  42209. // But must not set clip in each frame, otherwise all of the children will be marked redraw.
  42210. this._updateLargeClip(seriesModel);
  42211. };
  42212. BarView.prototype.incrementalRender = function (params, seriesModel) {
  42213. // Reset
  42214. this._progressiveEls = [];
  42215. // Do not support progressive in normal mode.
  42216. this._incrementalRenderLarge(params, seriesModel);
  42217. };
  42218. BarView.prototype.eachRendered = function (cb) {
  42219. traverseElements(this._progressiveEls || this.group, cb);
  42220. };
  42221. BarView.prototype._updateDrawMode = function (seriesModel) {
  42222. var isLargeDraw = seriesModel.pipelineContext.large;
  42223. if (this._isLargeDraw == null || isLargeDraw !== this._isLargeDraw) {
  42224. this._isLargeDraw = isLargeDraw;
  42225. this._clear();
  42226. }
  42227. };
  42228. BarView.prototype._renderNormal = function (seriesModel, ecModel, api, payload) {
  42229. var group = this.group;
  42230. var data = seriesModel.getData();
  42231. var oldData = this._data;
  42232. var coord = seriesModel.coordinateSystem;
  42233. var baseAxis = coord.getBaseAxis();
  42234. var isHorizontalOrRadial;
  42235. if (coord.type === 'cartesian2d') {
  42236. isHorizontalOrRadial = baseAxis.isHorizontal();
  42237. } else if (coord.type === 'polar') {
  42238. isHorizontalOrRadial = baseAxis.dim === 'angle';
  42239. }
  42240. var animationModel = seriesModel.isAnimationEnabled() ? seriesModel : null;
  42241. var realtimeSortCfg = shouldRealtimeSort(seriesModel, coord);
  42242. if (realtimeSortCfg) {
  42243. this._enableRealtimeSort(realtimeSortCfg, data, api);
  42244. }
  42245. var needsClip = seriesModel.get('clip', true) || realtimeSortCfg;
  42246. var coordSysClipArea = getClipArea(coord, data);
  42247. // If there is clipPath created in large mode. Remove it.
  42248. group.removeClipPath();
  42249. // We don't use clipPath in normal mode because we needs a perfect animation
  42250. // And don't want the label are clipped.
  42251. var roundCap = seriesModel.get('roundCap', true);
  42252. var drawBackground = seriesModel.get('showBackground', true);
  42253. var backgroundModel = seriesModel.getModel('backgroundStyle');
  42254. var barBorderRadius = backgroundModel.get('borderRadius') || 0;
  42255. var bgEls = [];
  42256. var oldBgEls = this._backgroundEls;
  42257. var isInitSort = payload && payload.isInitSort;
  42258. var isChangeOrder = payload && payload.type === 'changeAxisOrder';
  42259. function createBackground(dataIndex) {
  42260. var bgLayout = getLayout[coord.type](data, dataIndex);
  42261. if (!bgLayout) {
  42262. return null;
  42263. }
  42264. var bgEl = createBackgroundEl(coord, isHorizontalOrRadial, bgLayout);
  42265. bgEl.useStyle(backgroundModel.getItemStyle());
  42266. // Only cartesian2d support borderRadius.
  42267. if (coord.type === 'cartesian2d') {
  42268. bgEl.setShape('r', barBorderRadius);
  42269. } else {
  42270. bgEl.setShape('cornerRadius', barBorderRadius);
  42271. }
  42272. bgEls[dataIndex] = bgEl;
  42273. return bgEl;
  42274. }
  42275. data.diff(oldData).add(function (dataIndex) {
  42276. var itemModel = data.getItemModel(dataIndex);
  42277. var layout = getLayout[coord.type](data, dataIndex, itemModel);
  42278. if (!layout) {
  42279. return;
  42280. }
  42281. if (drawBackground) {
  42282. createBackground(dataIndex);
  42283. }
  42284. // If dataZoom in filteMode: 'empty', the baseValue can be set as NaN in "axisProxy".
  42285. if (!data.hasValue(dataIndex) || !isValidLayout[coord.type](layout)) {
  42286. return;
  42287. }
  42288. var isClipped = false;
  42289. if (needsClip) {
  42290. // Clip will modify the layout params.
  42291. // And return a boolean to determine if the shape are fully clipped.
  42292. isClipped = clip[coord.type](coordSysClipArea, layout);
  42293. }
  42294. var el = elementCreator[coord.type](seriesModel, data, dataIndex, layout, isHorizontalOrRadial, animationModel, baseAxis.model, false, roundCap);
  42295. if (realtimeSortCfg) {
  42296. /**
  42297. * Force label animation because even if the element is
  42298. * ignored because it's clipped, it may not be clipped after
  42299. * changing order. Then, if not using forceLabelAnimation,
  42300. * the label animation was never started, in which case,
  42301. * the label will be the final value and doesn't have label
  42302. * animation.
  42303. */
  42304. el.forceLabelAnimation = true;
  42305. }
  42306. updateStyle(el, data, dataIndex, itemModel, layout, seriesModel, isHorizontalOrRadial, coord.type === 'polar');
  42307. if (isInitSort) {
  42308. el.attr({
  42309. shape: layout
  42310. });
  42311. } else if (realtimeSortCfg) {
  42312. updateRealtimeAnimation(realtimeSortCfg, animationModel, el, layout, dataIndex, isHorizontalOrRadial, false, false);
  42313. } else {
  42314. initProps(el, {
  42315. shape: layout
  42316. }, seriesModel, dataIndex);
  42317. }
  42318. data.setItemGraphicEl(dataIndex, el);
  42319. group.add(el);
  42320. el.ignore = isClipped;
  42321. }).update(function (newIndex, oldIndex) {
  42322. var itemModel = data.getItemModel(newIndex);
  42323. var layout = getLayout[coord.type](data, newIndex, itemModel);
  42324. if (!layout) {
  42325. return;
  42326. }
  42327. if (drawBackground) {
  42328. var bgEl = void 0;
  42329. if (oldBgEls.length === 0) {
  42330. bgEl = createBackground(oldIndex);
  42331. } else {
  42332. bgEl = oldBgEls[oldIndex];
  42333. bgEl.useStyle(backgroundModel.getItemStyle());
  42334. // Only cartesian2d support borderRadius.
  42335. if (coord.type === 'cartesian2d') {
  42336. bgEl.setShape('r', barBorderRadius);
  42337. } else {
  42338. bgEl.setShape('cornerRadius', barBorderRadius);
  42339. }
  42340. bgEls[newIndex] = bgEl;
  42341. }
  42342. var bgLayout = getLayout[coord.type](data, newIndex);
  42343. var shape = createBackgroundShape(isHorizontalOrRadial, bgLayout, coord);
  42344. updateProps(bgEl, {
  42345. shape: shape
  42346. }, animationModel, newIndex);
  42347. }
  42348. var el = oldData.getItemGraphicEl(oldIndex);
  42349. if (!data.hasValue(newIndex) || !isValidLayout[coord.type](layout)) {
  42350. group.remove(el);
  42351. return;
  42352. }
  42353. var isClipped = false;
  42354. if (needsClip) {
  42355. isClipped = clip[coord.type](coordSysClipArea, layout);
  42356. if (isClipped) {
  42357. group.remove(el);
  42358. }
  42359. }
  42360. var roundCapChanged = el && (el.type === 'sector' && roundCap || el.type === 'sausage' && !roundCap);
  42361. if (roundCapChanged) {
  42362. // roundCap changed, there is no way to use animation from a `sector` to a `sausage` shape,
  42363. // so remove the old one and create a new shape
  42364. el && removeElementWithFadeOut(el, seriesModel, oldIndex);
  42365. el = null;
  42366. }
  42367. if (!el) {
  42368. el = elementCreator[coord.type](seriesModel, data, newIndex, layout, isHorizontalOrRadial, animationModel, baseAxis.model, true, roundCap);
  42369. } else {
  42370. saveOldStyle(el);
  42371. }
  42372. if (realtimeSortCfg) {
  42373. el.forceLabelAnimation = true;
  42374. }
  42375. if (isChangeOrder) {
  42376. var textEl = el.getTextContent();
  42377. if (textEl) {
  42378. var labelInnerStore = labelInner(textEl);
  42379. if (labelInnerStore.prevValue != null) {
  42380. /**
  42381. * Set preValue to be value so that no new label
  42382. * should be started, otherwise, it will take a full
  42383. * `animationDurationUpdate` time to finish the
  42384. * animation, which is not expected.
  42385. */
  42386. labelInnerStore.prevValue = labelInnerStore.value;
  42387. }
  42388. }
  42389. }
  42390. // Not change anything if only order changed.
  42391. // Especially not change label.
  42392. else {
  42393. updateStyle(el, data, newIndex, itemModel, layout, seriesModel, isHorizontalOrRadial, coord.type === 'polar');
  42394. }
  42395. if (isInitSort) {
  42396. el.attr({
  42397. shape: layout
  42398. });
  42399. } else if (realtimeSortCfg) {
  42400. updateRealtimeAnimation(realtimeSortCfg, animationModel, el, layout, newIndex, isHorizontalOrRadial, true, isChangeOrder);
  42401. } else {
  42402. updateProps(el, {
  42403. shape: layout
  42404. }, seriesModel, newIndex, null);
  42405. }
  42406. data.setItemGraphicEl(newIndex, el);
  42407. el.ignore = isClipped;
  42408. group.add(el);
  42409. }).remove(function (dataIndex) {
  42410. var el = oldData.getItemGraphicEl(dataIndex);
  42411. el && removeElementWithFadeOut(el, seriesModel, dataIndex);
  42412. }).execute();
  42413. var bgGroup = this._backgroundGroup || (this._backgroundGroup = new Group());
  42414. bgGroup.removeAll();
  42415. for (var i = 0; i < bgEls.length; ++i) {
  42416. bgGroup.add(bgEls[i]);
  42417. }
  42418. group.add(bgGroup);
  42419. this._backgroundEls = bgEls;
  42420. this._data = data;
  42421. };
  42422. BarView.prototype._renderLarge = function (seriesModel, ecModel, api) {
  42423. this._clear();
  42424. createLarge(seriesModel, this.group);
  42425. this._updateLargeClip(seriesModel);
  42426. };
  42427. BarView.prototype._incrementalRenderLarge = function (params, seriesModel) {
  42428. this._removeBackground();
  42429. createLarge(seriesModel, this.group, this._progressiveEls, true);
  42430. };
  42431. BarView.prototype._updateLargeClip = function (seriesModel) {
  42432. // Use clipPath in large mode.
  42433. var clipPath = seriesModel.get('clip', true) && createClipPath(seriesModel.coordinateSystem, false, seriesModel);
  42434. var group = this.group;
  42435. if (clipPath) {
  42436. group.setClipPath(clipPath);
  42437. } else {
  42438. group.removeClipPath();
  42439. }
  42440. };
  42441. BarView.prototype._enableRealtimeSort = function (realtimeSortCfg, data, api) {
  42442. var _this = this;
  42443. // If no data in the first frame, wait for data to initSort
  42444. if (!data.count()) {
  42445. return;
  42446. }
  42447. var baseAxis = realtimeSortCfg.baseAxis;
  42448. if (this._isFirstFrame) {
  42449. this._dispatchInitSort(data, realtimeSortCfg, api);
  42450. this._isFirstFrame = false;
  42451. } else {
  42452. var orderMapping_1 = function (idx) {
  42453. var el = data.getItemGraphicEl(idx);
  42454. var shape = el && el.shape;
  42455. return shape &&
  42456. // The result should be consistent with the initial sort by data value.
  42457. // Do not support the case that both positive and negative exist.
  42458. Math.abs(baseAxis.isHorizontal() ? shape.height : shape.width)
  42459. // If data is NaN, shape.xxx may be NaN, so use || 0 here in case
  42460. || 0;
  42461. };
  42462. this._onRendered = function () {
  42463. _this._updateSortWithinSameData(data, orderMapping_1, baseAxis, api);
  42464. };
  42465. api.getZr().on('rendered', this._onRendered);
  42466. }
  42467. };
  42468. BarView.prototype._dataSort = function (data, baseAxis, orderMapping) {
  42469. var info = [];
  42470. data.each(data.mapDimension(baseAxis.dim), function (ordinalNumber, dataIdx) {
  42471. var mappedValue = orderMapping(dataIdx);
  42472. mappedValue = mappedValue == null ? NaN : mappedValue;
  42473. info.push({
  42474. dataIndex: dataIdx,
  42475. mappedValue: mappedValue,
  42476. ordinalNumber: ordinalNumber
  42477. });
  42478. });
  42479. info.sort(function (a, b) {
  42480. // If NaN, it will be treated as min val.
  42481. return b.mappedValue - a.mappedValue;
  42482. });
  42483. return {
  42484. ordinalNumbers: map(info, function (item) {
  42485. return item.ordinalNumber;
  42486. })
  42487. };
  42488. };
  42489. BarView.prototype._isOrderChangedWithinSameData = function (data, orderMapping, baseAxis) {
  42490. var scale = baseAxis.scale;
  42491. var ordinalDataDim = data.mapDimension(baseAxis.dim);
  42492. var lastValue = Number.MAX_VALUE;
  42493. for (var tickNum = 0, len = scale.getOrdinalMeta().categories.length; tickNum < len; ++tickNum) {
  42494. var rawIdx = data.rawIndexOf(ordinalDataDim, scale.getRawOrdinalNumber(tickNum));
  42495. var value = rawIdx < 0
  42496. // If some tick have no bar, the tick will be treated as min.
  42497. ? Number.MIN_VALUE
  42498. // PENDING: if dataZoom on baseAxis exits, is it a performance issue?
  42499. : orderMapping(data.indexOfRawIndex(rawIdx));
  42500. if (value > lastValue) {
  42501. return true;
  42502. }
  42503. lastValue = value;
  42504. }
  42505. return false;
  42506. };
  42507. /*
  42508. * Consider the case when A and B changed order, whose representing
  42509. * bars are both out of sight, we don't wish to trigger reorder action
  42510. * as long as the order in the view doesn't change.
  42511. */
  42512. BarView.prototype._isOrderDifferentInView = function (orderInfo, baseAxis) {
  42513. var scale = baseAxis.scale;
  42514. var extent = scale.getExtent();
  42515. var tickNum = Math.max(0, extent[0]);
  42516. var tickMax = Math.min(extent[1], scale.getOrdinalMeta().categories.length - 1);
  42517. for (; tickNum <= tickMax; ++tickNum) {
  42518. if (orderInfo.ordinalNumbers[tickNum] !== scale.getRawOrdinalNumber(tickNum)) {
  42519. return true;
  42520. }
  42521. }
  42522. };
  42523. BarView.prototype._updateSortWithinSameData = function (data, orderMapping, baseAxis, api) {
  42524. if (!this._isOrderChangedWithinSameData(data, orderMapping, baseAxis)) {
  42525. return;
  42526. }
  42527. var sortInfo = this._dataSort(data, baseAxis, orderMapping);
  42528. if (this._isOrderDifferentInView(sortInfo, baseAxis)) {
  42529. this._removeOnRenderedListener(api);
  42530. api.dispatchAction({
  42531. type: 'changeAxisOrder',
  42532. componentType: baseAxis.dim + 'Axis',
  42533. axisId: baseAxis.index,
  42534. sortInfo: sortInfo
  42535. });
  42536. }
  42537. };
  42538. BarView.prototype._dispatchInitSort = function (data, realtimeSortCfg, api) {
  42539. var baseAxis = realtimeSortCfg.baseAxis;
  42540. var sortResult = this._dataSort(data, baseAxis, function (dataIdx) {
  42541. return data.get(data.mapDimension(realtimeSortCfg.otherAxis.dim), dataIdx);
  42542. });
  42543. api.dispatchAction({
  42544. type: 'changeAxisOrder',
  42545. componentType: baseAxis.dim + 'Axis',
  42546. isInitSort: true,
  42547. axisId: baseAxis.index,
  42548. sortInfo: sortResult
  42549. });
  42550. };
  42551. BarView.prototype.remove = function (ecModel, api) {
  42552. this._clear(this._model);
  42553. this._removeOnRenderedListener(api);
  42554. };
  42555. BarView.prototype.dispose = function (ecModel, api) {
  42556. this._removeOnRenderedListener(api);
  42557. };
  42558. BarView.prototype._removeOnRenderedListener = function (api) {
  42559. if (this._onRendered) {
  42560. api.getZr().off('rendered', this._onRendered);
  42561. this._onRendered = null;
  42562. }
  42563. };
  42564. BarView.prototype._clear = function (model) {
  42565. var group = this.group;
  42566. var data = this._data;
  42567. if (model && model.isAnimationEnabled() && data && !this._isLargeDraw) {
  42568. this._removeBackground();
  42569. this._backgroundEls = [];
  42570. data.eachItemGraphicEl(function (el) {
  42571. removeElementWithFadeOut(el, model, getECData(el).dataIndex);
  42572. });
  42573. } else {
  42574. group.removeAll();
  42575. }
  42576. this._data = null;
  42577. this._isFirstFrame = true;
  42578. };
  42579. BarView.prototype._removeBackground = function () {
  42580. this.group.remove(this._backgroundGroup);
  42581. this._backgroundGroup = null;
  42582. };
  42583. BarView.type = 'bar';
  42584. return BarView;
  42585. }(ChartView);
  42586. var clip = {
  42587. cartesian2d: function (coordSysBoundingRect, layout) {
  42588. var signWidth = layout.width < 0 ? -1 : 1;
  42589. var signHeight = layout.height < 0 ? -1 : 1;
  42590. // Needs positive width and height
  42591. if (signWidth < 0) {
  42592. layout.x += layout.width;
  42593. layout.width = -layout.width;
  42594. }
  42595. if (signHeight < 0) {
  42596. layout.y += layout.height;
  42597. layout.height = -layout.height;
  42598. }
  42599. var coordSysX2 = coordSysBoundingRect.x + coordSysBoundingRect.width;
  42600. var coordSysY2 = coordSysBoundingRect.y + coordSysBoundingRect.height;
  42601. var x = mathMax$7(layout.x, coordSysBoundingRect.x);
  42602. var x2 = mathMin$7(layout.x + layout.width, coordSysX2);
  42603. var y = mathMax$7(layout.y, coordSysBoundingRect.y);
  42604. var y2 = mathMin$7(layout.y + layout.height, coordSysY2);
  42605. var xClipped = x2 < x;
  42606. var yClipped = y2 < y;
  42607. // When xClipped or yClipped, the element will be marked as `ignore`.
  42608. // But we should also place the element at the edge of the coord sys bounding rect.
  42609. // Because if data changed and the bar shows again, its transition animation
  42610. // will begin at this place.
  42611. layout.x = xClipped && x > coordSysX2 ? x2 : x;
  42612. layout.y = yClipped && y > coordSysY2 ? y2 : y;
  42613. layout.width = xClipped ? 0 : x2 - x;
  42614. layout.height = yClipped ? 0 : y2 - y;
  42615. // Reverse back
  42616. if (signWidth < 0) {
  42617. layout.x += layout.width;
  42618. layout.width = -layout.width;
  42619. }
  42620. if (signHeight < 0) {
  42621. layout.y += layout.height;
  42622. layout.height = -layout.height;
  42623. }
  42624. return xClipped || yClipped;
  42625. },
  42626. polar: function (coordSysClipArea, layout) {
  42627. var signR = layout.r0 <= layout.r ? 1 : -1;
  42628. // Make sure r is larger than r0
  42629. if (signR < 0) {
  42630. var tmp = layout.r;
  42631. layout.r = layout.r0;
  42632. layout.r0 = tmp;
  42633. }
  42634. var r = mathMin$7(layout.r, coordSysClipArea.r);
  42635. var r0 = mathMax$7(layout.r0, coordSysClipArea.r0);
  42636. layout.r = r;
  42637. layout.r0 = r0;
  42638. var clipped = r - r0 < 0;
  42639. // Reverse back
  42640. if (signR < 0) {
  42641. var tmp = layout.r;
  42642. layout.r = layout.r0;
  42643. layout.r0 = tmp;
  42644. }
  42645. return clipped;
  42646. }
  42647. };
  42648. var elementCreator = {
  42649. cartesian2d: function (seriesModel, data, newIndex, layout, isHorizontal, animationModel, axisModel, isUpdate, roundCap) {
  42650. var rect = new Rect({
  42651. shape: extend({}, layout),
  42652. z2: 1
  42653. });
  42654. rect.__dataIndex = newIndex;
  42655. rect.name = 'item';
  42656. if (animationModel) {
  42657. var rectShape = rect.shape;
  42658. var animateProperty = isHorizontal ? 'height' : 'width';
  42659. rectShape[animateProperty] = 0;
  42660. }
  42661. return rect;
  42662. },
  42663. polar: function (seriesModel, data, newIndex, layout, isRadial, animationModel, axisModel, isUpdate, roundCap) {
  42664. var ShapeClass = !isRadial && roundCap ? SausagePath : Sector;
  42665. var sector = new ShapeClass({
  42666. shape: layout,
  42667. z2: 1
  42668. });
  42669. sector.name = 'item';
  42670. var positionMap = createPolarPositionMapping(isRadial);
  42671. sector.calculateTextPosition = createSectorCalculateTextPosition(positionMap, {
  42672. isRoundCap: ShapeClass === SausagePath
  42673. });
  42674. // Animation
  42675. if (animationModel) {
  42676. var sectorShape = sector.shape;
  42677. var animateProperty = isRadial ? 'r' : 'endAngle';
  42678. var animateTarget = {};
  42679. sectorShape[animateProperty] = isRadial ? layout.r0 : layout.startAngle;
  42680. animateTarget[animateProperty] = layout[animateProperty];
  42681. (isUpdate ? updateProps : initProps)(sector, {
  42682. shape: animateTarget
  42683. // __value: typeof dataValue === 'string' ? parseInt(dataValue, 10) : dataValue
  42684. }, animationModel);
  42685. }
  42686. return sector;
  42687. }
  42688. };
  42689. function shouldRealtimeSort(seriesModel, coordSys) {
  42690. var realtimeSortOption = seriesModel.get('realtimeSort', true);
  42691. var baseAxis = coordSys.getBaseAxis();
  42692. if ("development" !== 'production') {
  42693. if (realtimeSortOption) {
  42694. if (baseAxis.type !== 'category') {
  42695. warn('`realtimeSort` will not work because this bar series is not based on a category axis.');
  42696. }
  42697. if (coordSys.type !== 'cartesian2d') {
  42698. warn('`realtimeSort` will not work because this bar series is not on cartesian2d.');
  42699. }
  42700. }
  42701. }
  42702. if (realtimeSortOption && baseAxis.type === 'category' && coordSys.type === 'cartesian2d') {
  42703. return {
  42704. baseAxis: baseAxis,
  42705. otherAxis: coordSys.getOtherAxis(baseAxis)
  42706. };
  42707. }
  42708. }
  42709. function updateRealtimeAnimation(realtimeSortCfg, seriesAnimationModel, el, layout, newIndex, isHorizontal, isUpdate, isChangeOrder) {
  42710. var seriesTarget;
  42711. var axisTarget;
  42712. if (isHorizontal) {
  42713. axisTarget = {
  42714. x: layout.x,
  42715. width: layout.width
  42716. };
  42717. seriesTarget = {
  42718. y: layout.y,
  42719. height: layout.height
  42720. };
  42721. } else {
  42722. axisTarget = {
  42723. y: layout.y,
  42724. height: layout.height
  42725. };
  42726. seriesTarget = {
  42727. x: layout.x,
  42728. width: layout.width
  42729. };
  42730. }
  42731. if (!isChangeOrder) {
  42732. // Keep the original growth animation if only axis order changed.
  42733. // Not start a new animation.
  42734. (isUpdate ? updateProps : initProps)(el, {
  42735. shape: seriesTarget
  42736. }, seriesAnimationModel, newIndex, null);
  42737. }
  42738. var axisAnimationModel = seriesAnimationModel ? realtimeSortCfg.baseAxis.model : null;
  42739. (isUpdate ? updateProps : initProps)(el, {
  42740. shape: axisTarget
  42741. }, axisAnimationModel, newIndex);
  42742. }
  42743. function checkPropertiesNotValid(obj, props) {
  42744. for (var i = 0; i < props.length; i++) {
  42745. if (!isFinite(obj[props[i]])) {
  42746. return true;
  42747. }
  42748. }
  42749. return false;
  42750. }
  42751. var rectPropties = ['x', 'y', 'width', 'height'];
  42752. var polarPropties = ['cx', 'cy', 'r', 'startAngle', 'endAngle'];
  42753. var isValidLayout = {
  42754. cartesian2d: function (layout) {
  42755. return !checkPropertiesNotValid(layout, rectPropties);
  42756. },
  42757. polar: function (layout) {
  42758. return !checkPropertiesNotValid(layout, polarPropties);
  42759. }
  42760. };
  42761. var getLayout = {
  42762. // itemModel is only used to get borderWidth, which is not needed
  42763. // when calculating bar background layout.
  42764. cartesian2d: function (data, dataIndex, itemModel) {
  42765. var layout = data.getItemLayout(dataIndex);
  42766. if (!layout) {
  42767. return null;
  42768. }
  42769. var fixedLineWidth = itemModel ? getLineWidth(itemModel, layout) : 0;
  42770. // fix layout with lineWidth
  42771. var signX = layout.width > 0 ? 1 : -1;
  42772. var signY = layout.height > 0 ? 1 : -1;
  42773. return {
  42774. x: layout.x + signX * fixedLineWidth / 2,
  42775. y: layout.y + signY * fixedLineWidth / 2,
  42776. width: layout.width - signX * fixedLineWidth,
  42777. height: layout.height - signY * fixedLineWidth
  42778. };
  42779. },
  42780. polar: function (data, dataIndex, itemModel) {
  42781. var layout = data.getItemLayout(dataIndex);
  42782. return {
  42783. cx: layout.cx,
  42784. cy: layout.cy,
  42785. r0: layout.r0,
  42786. r: layout.r,
  42787. startAngle: layout.startAngle,
  42788. endAngle: layout.endAngle,
  42789. clockwise: layout.clockwise
  42790. };
  42791. }
  42792. };
  42793. function isZeroOnPolar(layout) {
  42794. return layout.startAngle != null && layout.endAngle != null && layout.startAngle === layout.endAngle;
  42795. }
  42796. function createPolarPositionMapping(isRadial) {
  42797. return function (isRadial) {
  42798. var arcOrAngle = isRadial ? 'Arc' : 'Angle';
  42799. return function (position) {
  42800. switch (position) {
  42801. case 'start':
  42802. case 'insideStart':
  42803. case 'end':
  42804. case 'insideEnd':
  42805. return position + arcOrAngle;
  42806. default:
  42807. return position;
  42808. }
  42809. };
  42810. }(isRadial);
  42811. }
  42812. function updateStyle(el, data, dataIndex, itemModel, layout, seriesModel, isHorizontalOrRadial, isPolar) {
  42813. var style = data.getItemVisual(dataIndex, 'style');
  42814. if (!isPolar) {
  42815. var borderRadius = itemModel.get(['itemStyle', 'borderRadius']) || 0;
  42816. el.setShape('r', borderRadius);
  42817. } else if (!seriesModel.get('roundCap')) {
  42818. var sectorShape = el.shape;
  42819. var cornerRadius = getSectorCornerRadius(itemModel.getModel('itemStyle'), sectorShape, true);
  42820. extend(sectorShape, cornerRadius);
  42821. el.setShape(sectorShape);
  42822. }
  42823. el.useStyle(style);
  42824. var cursorStyle = itemModel.getShallow('cursor');
  42825. cursorStyle && el.attr('cursor', cursorStyle);
  42826. var labelPositionOutside = isPolar ? isHorizontalOrRadial ? layout.r >= layout.r0 ? 'endArc' : 'startArc' : layout.endAngle >= layout.startAngle ? 'endAngle' : 'startAngle' : isHorizontalOrRadial ? layout.height >= 0 ? 'bottom' : 'top' : layout.width >= 0 ? 'right' : 'left';
  42827. var labelStatesModels = getLabelStatesModels(itemModel);
  42828. setLabelStyle(el, labelStatesModels, {
  42829. labelFetcher: seriesModel,
  42830. labelDataIndex: dataIndex,
  42831. defaultText: getDefaultLabel(seriesModel.getData(), dataIndex),
  42832. inheritColor: style.fill,
  42833. defaultOpacity: style.opacity,
  42834. defaultOutsidePosition: labelPositionOutside
  42835. });
  42836. var label = el.getTextContent();
  42837. if (isPolar && label) {
  42838. var position = itemModel.get(['label', 'position']);
  42839. el.textConfig.inside = position === 'middle' ? true : null;
  42840. setSectorTextRotation(el, position === 'outside' ? labelPositionOutside : position, createPolarPositionMapping(isHorizontalOrRadial), itemModel.get(['label', 'rotate']));
  42841. }
  42842. setLabelValueAnimation(label, labelStatesModels, seriesModel.getRawValue(dataIndex), function (value) {
  42843. return getDefaultInterpolatedLabel(data, value);
  42844. });
  42845. var emphasisModel = itemModel.getModel(['emphasis']);
  42846. toggleHoverEmphasis(el, emphasisModel.get('focus'), emphasisModel.get('blurScope'), emphasisModel.get('disabled'));
  42847. setStatesStylesFromModel(el, itemModel);
  42848. if (isZeroOnPolar(layout)) {
  42849. el.style.fill = 'none';
  42850. el.style.stroke = 'none';
  42851. each(el.states, function (state) {
  42852. if (state.style) {
  42853. state.style.fill = state.style.stroke = 'none';
  42854. }
  42855. });
  42856. }
  42857. }
  42858. // In case width or height are too small.
  42859. function getLineWidth(itemModel, rawLayout) {
  42860. // Has no border.
  42861. var borderColor = itemModel.get(['itemStyle', 'borderColor']);
  42862. if (!borderColor || borderColor === 'none') {
  42863. return 0;
  42864. }
  42865. var lineWidth = itemModel.get(['itemStyle', 'borderWidth']) || 0;
  42866. // width or height may be NaN for empty data
  42867. var width = isNaN(rawLayout.width) ? Number.MAX_VALUE : Math.abs(rawLayout.width);
  42868. var height = isNaN(rawLayout.height) ? Number.MAX_VALUE : Math.abs(rawLayout.height);
  42869. return Math.min(lineWidth, width, height);
  42870. }
  42871. var LagePathShape = /** @class */function () {
  42872. function LagePathShape() {}
  42873. return LagePathShape;
  42874. }();
  42875. var LargePath = /** @class */function (_super) {
  42876. __extends(LargePath, _super);
  42877. function LargePath(opts) {
  42878. var _this = _super.call(this, opts) || this;
  42879. _this.type = 'largeBar';
  42880. return _this;
  42881. }
  42882. LargePath.prototype.getDefaultShape = function () {
  42883. return new LagePathShape();
  42884. };
  42885. LargePath.prototype.buildPath = function (ctx, shape) {
  42886. // Drawing lines is more efficient than drawing
  42887. // a whole line or drawing rects.
  42888. var points = shape.points;
  42889. var baseDimIdx = this.baseDimIdx;
  42890. var valueDimIdx = 1 - this.baseDimIdx;
  42891. var startPoint = [];
  42892. var size = [];
  42893. var barWidth = this.barWidth;
  42894. for (var i = 0; i < points.length; i += 3) {
  42895. size[baseDimIdx] = barWidth;
  42896. size[valueDimIdx] = points[i + 2];
  42897. startPoint[baseDimIdx] = points[i + baseDimIdx];
  42898. startPoint[valueDimIdx] = points[i + valueDimIdx];
  42899. ctx.rect(startPoint[0], startPoint[1], size[0], size[1]);
  42900. }
  42901. };
  42902. return LargePath;
  42903. }(Path);
  42904. function createLarge(seriesModel, group, progressiveEls, incremental) {
  42905. // TODO support polar
  42906. var data = seriesModel.getData();
  42907. var baseDimIdx = data.getLayout('valueAxisHorizontal') ? 1 : 0;
  42908. var largeDataIndices = data.getLayout('largeDataIndices');
  42909. var barWidth = data.getLayout('size');
  42910. var backgroundModel = seriesModel.getModel('backgroundStyle');
  42911. var bgPoints = data.getLayout('largeBackgroundPoints');
  42912. if (bgPoints) {
  42913. var bgEl = new LargePath({
  42914. shape: {
  42915. points: bgPoints
  42916. },
  42917. incremental: !!incremental,
  42918. silent: true,
  42919. z2: 0
  42920. });
  42921. bgEl.baseDimIdx = baseDimIdx;
  42922. bgEl.largeDataIndices = largeDataIndices;
  42923. bgEl.barWidth = barWidth;
  42924. bgEl.useStyle(backgroundModel.getItemStyle());
  42925. group.add(bgEl);
  42926. progressiveEls && progressiveEls.push(bgEl);
  42927. }
  42928. var el = new LargePath({
  42929. shape: {
  42930. points: data.getLayout('largePoints')
  42931. },
  42932. incremental: !!incremental,
  42933. ignoreCoarsePointer: true,
  42934. z2: 1
  42935. });
  42936. el.baseDimIdx = baseDimIdx;
  42937. el.largeDataIndices = largeDataIndices;
  42938. el.barWidth = barWidth;
  42939. group.add(el);
  42940. el.useStyle(data.getVisual('style'));
  42941. // Stroke is rendered first to avoid overlapping with fill
  42942. el.style.stroke = null;
  42943. // Enable tooltip and user mouse/touch event handlers.
  42944. getECData(el).seriesIndex = seriesModel.seriesIndex;
  42945. if (!seriesModel.get('silent')) {
  42946. el.on('mousedown', largePathUpdateDataIndex);
  42947. el.on('mousemove', largePathUpdateDataIndex);
  42948. }
  42949. progressiveEls && progressiveEls.push(el);
  42950. }
  42951. // Use throttle to avoid frequently traverse to find dataIndex.
  42952. var largePathUpdateDataIndex = throttle(function (event) {
  42953. var largePath = this;
  42954. var dataIndex = largePathFindDataIndex(largePath, event.offsetX, event.offsetY);
  42955. getECData(largePath).dataIndex = dataIndex >= 0 ? dataIndex : null;
  42956. }, 30, false);
  42957. function largePathFindDataIndex(largePath, x, y) {
  42958. var baseDimIdx = largePath.baseDimIdx;
  42959. var valueDimIdx = 1 - baseDimIdx;
  42960. var points = largePath.shape.points;
  42961. var largeDataIndices = largePath.largeDataIndices;
  42962. var startPoint = [];
  42963. var size = [];
  42964. var barWidth = largePath.barWidth;
  42965. for (var i = 0, len = points.length / 3; i < len; i++) {
  42966. var ii = i * 3;
  42967. size[baseDimIdx] = barWidth;
  42968. size[valueDimIdx] = points[ii + 2];
  42969. startPoint[baseDimIdx] = points[ii + baseDimIdx];
  42970. startPoint[valueDimIdx] = points[ii + valueDimIdx];
  42971. if (size[valueDimIdx] < 0) {
  42972. startPoint[valueDimIdx] += size[valueDimIdx];
  42973. size[valueDimIdx] = -size[valueDimIdx];
  42974. }
  42975. if (x >= startPoint[0] && x <= startPoint[0] + size[0] && y >= startPoint[1] && y <= startPoint[1] + size[1]) {
  42976. return largeDataIndices[i];
  42977. }
  42978. }
  42979. return -1;
  42980. }
  42981. function createBackgroundShape(isHorizontalOrRadial, layout, coord) {
  42982. if (isCoordinateSystemType(coord, 'cartesian2d')) {
  42983. var rectShape = layout;
  42984. var coordLayout = coord.getArea();
  42985. return {
  42986. x: isHorizontalOrRadial ? rectShape.x : coordLayout.x,
  42987. y: isHorizontalOrRadial ? coordLayout.y : rectShape.y,
  42988. width: isHorizontalOrRadial ? rectShape.width : coordLayout.width,
  42989. height: isHorizontalOrRadial ? coordLayout.height : rectShape.height
  42990. };
  42991. } else {
  42992. var coordLayout = coord.getArea();
  42993. var sectorShape = layout;
  42994. return {
  42995. cx: coordLayout.cx,
  42996. cy: coordLayout.cy,
  42997. r0: isHorizontalOrRadial ? coordLayout.r0 : sectorShape.r0,
  42998. r: isHorizontalOrRadial ? coordLayout.r : sectorShape.r,
  42999. startAngle: isHorizontalOrRadial ? sectorShape.startAngle : 0,
  43000. endAngle: isHorizontalOrRadial ? sectorShape.endAngle : Math.PI * 2
  43001. };
  43002. }
  43003. }
  43004. function createBackgroundEl(coord, isHorizontalOrRadial, layout) {
  43005. var ElementClz = coord.type === 'polar' ? Sector : Rect;
  43006. return new ElementClz({
  43007. shape: createBackgroundShape(isHorizontalOrRadial, layout, coord),
  43008. silent: true,
  43009. z2: 0
  43010. });
  43011. }
  43012. function install$3(registers) {
  43013. registers.registerChartView(BarView);
  43014. registers.registerSeriesModel(BarSeriesModel);
  43015. registers.registerLayout(registers.PRIORITY.VISUAL.LAYOUT, curry(layout, 'bar'));
  43016. // Do layout after other overall layout, which can prepare some information.
  43017. registers.registerLayout(registers.PRIORITY.VISUAL.PROGRESSIVE_LAYOUT, createProgressiveLayout('bar'));
  43018. // Down sample after filter
  43019. registers.registerProcessor(registers.PRIORITY.PROCESSOR.STATISTIC, dataSample('bar'));
  43020. /**
  43021. * @payload
  43022. * @property {string} [componentType=series]
  43023. * @property {number} [dx]
  43024. * @property {number} [dy]
  43025. * @property {number} [zoom]
  43026. * @property {number} [originX]
  43027. * @property {number} [originY]
  43028. */
  43029. registers.registerAction({
  43030. type: 'changeAxisOrder',
  43031. event: 'changeAxisOrder',
  43032. update: 'update'
  43033. }, function (payload, ecModel) {
  43034. var componentType = payload.componentType || 'series';
  43035. ecModel.eachComponent({
  43036. mainType: componentType,
  43037. query: payload
  43038. }, function (componentModel) {
  43039. if (payload.sortInfo) {
  43040. componentModel.axis.setCategorySortInfo(payload.sortInfo);
  43041. }
  43042. });
  43043. });
  43044. }
  43045. var PI2$8 = Math.PI * 2;
  43046. var RADIAN = Math.PI / 180;
  43047. function pieLayout(seriesType, ecModel, api) {
  43048. ecModel.eachSeriesByType(seriesType, function (seriesModel) {
  43049. var data = seriesModel.getData();
  43050. var valueDim = data.mapDimension('value');
  43051. var _a = getCircleLayout(seriesModel, api),
  43052. cx = _a.cx,
  43053. cy = _a.cy,
  43054. r = _a.r,
  43055. r0 = _a.r0,
  43056. viewRect = _a.viewRect;
  43057. var startAngle = -seriesModel.get('startAngle') * RADIAN;
  43058. var endAngle = seriesModel.get('endAngle');
  43059. var padAngle = seriesModel.get('padAngle') * RADIAN;
  43060. endAngle = endAngle === 'auto' ? startAngle - PI2$8 : -endAngle * RADIAN;
  43061. var minAngle = seriesModel.get('minAngle') * RADIAN;
  43062. var minAndPadAngle = minAngle + padAngle;
  43063. var validDataCount = 0;
  43064. data.each(valueDim, function (value) {
  43065. !isNaN(value) && validDataCount++;
  43066. });
  43067. var sum = data.getSum(valueDim);
  43068. // Sum may be 0
  43069. var unitRadian = Math.PI / (sum || validDataCount) * 2;
  43070. var clockwise = seriesModel.get('clockwise');
  43071. var roseType = seriesModel.get('roseType');
  43072. var stillShowZeroSum = seriesModel.get('stillShowZeroSum');
  43073. // [0...max]
  43074. var extent = data.getDataExtent(valueDim);
  43075. extent[0] = 0;
  43076. var dir = clockwise ? 1 : -1;
  43077. var angles = [startAngle, endAngle];
  43078. var halfPadAngle = dir * padAngle / 2;
  43079. normalizeArcAngles(angles, !clockwise);
  43080. startAngle = angles[0], endAngle = angles[1];
  43081. var layoutData = getSeriesLayoutData(seriesModel);
  43082. layoutData.startAngle = startAngle;
  43083. layoutData.endAngle = endAngle;
  43084. layoutData.clockwise = clockwise;
  43085. layoutData.cx = cx;
  43086. layoutData.cy = cy;
  43087. layoutData.r = r;
  43088. layoutData.r0 = r0;
  43089. var angleRange = Math.abs(endAngle - startAngle);
  43090. // In the case some sector angle is smaller than minAngle
  43091. var restAngle = angleRange;
  43092. var valueSumLargerThanMinAngle = 0;
  43093. var currentAngle = startAngle;
  43094. // Requird by `pieLabelLayout`.
  43095. data.setLayout({
  43096. viewRect: viewRect,
  43097. r: r
  43098. });
  43099. data.each(valueDim, function (value, idx) {
  43100. var angle;
  43101. if (isNaN(value)) {
  43102. data.setItemLayout(idx, {
  43103. angle: NaN,
  43104. startAngle: NaN,
  43105. endAngle: NaN,
  43106. clockwise: clockwise,
  43107. cx: cx,
  43108. cy: cy,
  43109. r0: r0,
  43110. r: roseType ? NaN : r
  43111. });
  43112. return;
  43113. }
  43114. // FIXME 兼容 2.0 但是 roseType 是 area 的时候才是这样?
  43115. if (roseType !== 'area') {
  43116. angle = sum === 0 && stillShowZeroSum ? unitRadian : value * unitRadian;
  43117. } else {
  43118. angle = angleRange / validDataCount;
  43119. }
  43120. if (angle < minAndPadAngle) {
  43121. angle = minAndPadAngle;
  43122. restAngle -= minAndPadAngle;
  43123. } else {
  43124. valueSumLargerThanMinAngle += value;
  43125. }
  43126. var endAngle = currentAngle + dir * angle;
  43127. // calculate display angle
  43128. var actualStartAngle = 0;
  43129. var actualEndAngle = 0;
  43130. if (padAngle > angle) {
  43131. actualStartAngle = currentAngle + dir * angle / 2;
  43132. actualEndAngle = actualStartAngle;
  43133. } else {
  43134. actualStartAngle = currentAngle + halfPadAngle;
  43135. actualEndAngle = endAngle - halfPadAngle;
  43136. }
  43137. data.setItemLayout(idx, {
  43138. angle: angle,
  43139. startAngle: actualStartAngle,
  43140. endAngle: actualEndAngle,
  43141. clockwise: clockwise,
  43142. cx: cx,
  43143. cy: cy,
  43144. r0: r0,
  43145. r: roseType ? linearMap(value, extent, [r0, r]) : r
  43146. });
  43147. currentAngle = endAngle;
  43148. });
  43149. // Some sector is constrained by minAngle and padAngle
  43150. // Rest sectors needs recalculate angle
  43151. if (restAngle < PI2$8 && validDataCount) {
  43152. // Average the angle if rest angle is not enough after all angles is
  43153. // Constrained by minAngle and padAngle
  43154. if (restAngle <= 1e-3) {
  43155. var angle_1 = angleRange / validDataCount;
  43156. data.each(valueDim, function (value, idx) {
  43157. if (!isNaN(value)) {
  43158. var layout = data.getItemLayout(idx);
  43159. layout.angle = angle_1;
  43160. var actualStartAngle = 0;
  43161. var actualEndAngle = 0;
  43162. if (angle_1 < padAngle) {
  43163. actualStartAngle = startAngle + dir * (idx + 1 / 2) * angle_1;
  43164. actualEndAngle = actualStartAngle;
  43165. } else {
  43166. actualStartAngle = startAngle + dir * idx * angle_1 + halfPadAngle;
  43167. actualEndAngle = startAngle + dir * (idx + 1) * angle_1 - halfPadAngle;
  43168. }
  43169. layout.startAngle = actualStartAngle;
  43170. layout.endAngle = actualEndAngle;
  43171. }
  43172. });
  43173. } else {
  43174. unitRadian = restAngle / valueSumLargerThanMinAngle;
  43175. currentAngle = startAngle;
  43176. data.each(valueDim, function (value, idx) {
  43177. if (!isNaN(value)) {
  43178. var layout = data.getItemLayout(idx);
  43179. var angle = layout.angle === minAndPadAngle ? minAndPadAngle : value * unitRadian;
  43180. var actualStartAngle = 0;
  43181. var actualEndAngle = 0;
  43182. if (angle < padAngle) {
  43183. actualStartAngle = currentAngle + dir * angle / 2;
  43184. actualEndAngle = actualStartAngle;
  43185. } else {
  43186. actualStartAngle = currentAngle + halfPadAngle;
  43187. actualEndAngle = currentAngle + dir * angle - halfPadAngle;
  43188. }
  43189. layout.startAngle = actualStartAngle;
  43190. layout.endAngle = actualEndAngle;
  43191. currentAngle += dir * angle;
  43192. }
  43193. });
  43194. }
  43195. }
  43196. });
  43197. }
  43198. var getSeriesLayoutData = makeInner();
  43199. /*
  43200. * Licensed to the Apache Software Foundation (ASF) under one
  43201. * or more contributor license agreements. See the NOTICE file
  43202. * distributed with this work for additional information
  43203. * regarding copyright ownership. The ASF licenses this file
  43204. * to you under the Apache License, Version 2.0 (the
  43205. * "License"); you may not use this file except in compliance
  43206. * with the License. You may obtain a copy of the License at
  43207. *
  43208. * http://www.apache.org/licenses/LICENSE-2.0
  43209. *
  43210. * Unless required by applicable law or agreed to in writing,
  43211. * software distributed under the License is distributed on an
  43212. * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
  43213. * KIND, either express or implied. See the License for the
  43214. * specific language governing permissions and limitations
  43215. * under the License.
  43216. */
  43217. /**
  43218. * AUTO-GENERATED FILE. DO NOT MODIFY.
  43219. */
  43220. /*
  43221. * Licensed to the Apache Software Foundation (ASF) under one
  43222. * or more contributor license agreements. See the NOTICE file
  43223. * distributed with this work for additional information
  43224. * regarding copyright ownership. The ASF licenses this file
  43225. * to you under the Apache License, Version 2.0 (the
  43226. * "License"); you may not use this file except in compliance
  43227. * with the License. You may obtain a copy of the License at
  43228. *
  43229. * http://www.apache.org/licenses/LICENSE-2.0
  43230. *
  43231. * Unless required by applicable law or agreed to in writing,
  43232. * software distributed under the License is distributed on an
  43233. * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
  43234. * KIND, either express or implied. See the License for the
  43235. * specific language governing permissions and limitations
  43236. * under the License.
  43237. */
  43238. function dataFilter(seriesType) {
  43239. return {
  43240. seriesType: seriesType,
  43241. reset: function (seriesModel, ecModel) {
  43242. var legendModels = ecModel.findComponents({
  43243. mainType: 'legend'
  43244. });
  43245. if (!legendModels || !legendModels.length) {
  43246. return;
  43247. }
  43248. var data = seriesModel.getData();
  43249. data.filterSelf(function (idx) {
  43250. var name = data.getName(idx);
  43251. // If in any legend component the status is not selected.
  43252. for (var i = 0; i < legendModels.length; i++) {
  43253. // @ts-ignore FIXME: LegendModel
  43254. if (!legendModels[i].isSelected(name)) {
  43255. return false;
  43256. }
  43257. }
  43258. return true;
  43259. });
  43260. }
  43261. };
  43262. }
  43263. var RADIAN$1 = Math.PI / 180;
  43264. function adjustSingleSide(list, cx, cy, r, dir, viewWidth, viewHeight, viewLeft, viewTop, farthestX) {
  43265. if (list.length < 2) {
  43266. return;
  43267. }
  43268. function recalculateXOnSemiToAlignOnEllipseCurve(semi) {
  43269. var rB = semi.rB;
  43270. var rB2 = rB * rB;
  43271. for (var i = 0; i < semi.list.length; i++) {
  43272. var item = semi.list[i];
  43273. var dy = Math.abs(item.label.y - cy);
  43274. // horizontal r is always same with original r because x is not changed.
  43275. var rA = r + item.len;
  43276. var rA2 = rA * rA;
  43277. // Use ellipse implicit function to calculate x
  43278. var dx = Math.sqrt(Math.abs((1 - dy * dy / rB2) * rA2));
  43279. var newX = cx + (dx + item.len2) * dir;
  43280. var deltaX = newX - item.label.x;
  43281. var newTargetWidth = item.targetTextWidth - deltaX * dir;
  43282. // text x is changed, so need to recalculate width.
  43283. constrainTextWidth(item, newTargetWidth, true);
  43284. item.label.x = newX;
  43285. }
  43286. }
  43287. // Adjust X based on the shifted y. Make tight labels aligned on an ellipse curve.
  43288. function recalculateX(items) {
  43289. // Extremes of
  43290. var topSemi = {
  43291. list: [],
  43292. maxY: 0
  43293. };
  43294. var bottomSemi = {
  43295. list: [],
  43296. maxY: 0
  43297. };
  43298. for (var i = 0; i < items.length; i++) {
  43299. if (items[i].labelAlignTo !== 'none') {
  43300. continue;
  43301. }
  43302. var item = items[i];
  43303. var semi = item.label.y > cy ? bottomSemi : topSemi;
  43304. var dy = Math.abs(item.label.y - cy);
  43305. if (dy >= semi.maxY) {
  43306. var dx = item.label.x - cx - item.len2 * dir;
  43307. // horizontal r is always same with original r because x is not changed.
  43308. var rA = r + item.len;
  43309. // Canculate rB based on the topest / bottemest label.
  43310. var rB = Math.abs(dx) < rA ? Math.sqrt(dy * dy / (1 - dx * dx / rA / rA)) : rA;
  43311. semi.rB = rB;
  43312. semi.maxY = dy;
  43313. }
  43314. semi.list.push(item);
  43315. }
  43316. recalculateXOnSemiToAlignOnEllipseCurve(topSemi);
  43317. recalculateXOnSemiToAlignOnEllipseCurve(bottomSemi);
  43318. }
  43319. var len = list.length;
  43320. for (var i = 0; i < len; i++) {
  43321. if (list[i].position === 'outer' && list[i].labelAlignTo === 'labelLine') {
  43322. var dx = list[i].label.x - farthestX;
  43323. list[i].linePoints[1][0] += dx;
  43324. list[i].label.x = farthestX;
  43325. }
  43326. }
  43327. if (shiftLayoutOnXY(list, 1, viewTop, viewTop + viewHeight)) {
  43328. recalculateX(list);
  43329. }
  43330. }
  43331. function avoidOverlap(labelLayoutList, cx, cy, r, viewWidth, viewHeight, viewLeft, viewTop) {
  43332. var leftList = [];
  43333. var rightList = [];
  43334. var leftmostX = Number.MAX_VALUE;
  43335. var rightmostX = -Number.MAX_VALUE;
  43336. for (var i = 0; i < labelLayoutList.length; i++) {
  43337. var label = labelLayoutList[i].label;
  43338. if (isPositionCenter(labelLayoutList[i])) {
  43339. continue;
  43340. }
  43341. if (label.x < cx) {
  43342. leftmostX = Math.min(leftmostX, label.x);
  43343. leftList.push(labelLayoutList[i]);
  43344. } else {
  43345. rightmostX = Math.max(rightmostX, label.x);
  43346. rightList.push(labelLayoutList[i]);
  43347. }
  43348. }
  43349. for (var i = 0; i < labelLayoutList.length; i++) {
  43350. var layout = labelLayoutList[i];
  43351. if (!isPositionCenter(layout) && layout.linePoints) {
  43352. if (layout.labelStyleWidth != null) {
  43353. continue;
  43354. }
  43355. var label = layout.label;
  43356. var linePoints = layout.linePoints;
  43357. var targetTextWidth = void 0;
  43358. if (layout.labelAlignTo === 'edge') {
  43359. if (label.x < cx) {
  43360. targetTextWidth = linePoints[2][0] - layout.labelDistance - viewLeft - layout.edgeDistance;
  43361. } else {
  43362. targetTextWidth = viewLeft + viewWidth - layout.edgeDistance - linePoints[2][0] - layout.labelDistance;
  43363. }
  43364. } else if (layout.labelAlignTo === 'labelLine') {
  43365. if (label.x < cx) {
  43366. targetTextWidth = leftmostX - viewLeft - layout.bleedMargin;
  43367. } else {
  43368. targetTextWidth = viewLeft + viewWidth - rightmostX - layout.bleedMargin;
  43369. }
  43370. } else {
  43371. if (label.x < cx) {
  43372. targetTextWidth = label.x - viewLeft - layout.bleedMargin;
  43373. } else {
  43374. targetTextWidth = viewLeft + viewWidth - label.x - layout.bleedMargin;
  43375. }
  43376. }
  43377. layout.targetTextWidth = targetTextWidth;
  43378. constrainTextWidth(layout, targetTextWidth, false);
  43379. }
  43380. }
  43381. adjustSingleSide(rightList, cx, cy, r, 1, viewWidth, viewHeight, viewLeft, viewTop, rightmostX);
  43382. adjustSingleSide(leftList, cx, cy, r, -1, viewWidth, viewHeight, viewLeft, viewTop, leftmostX);
  43383. for (var i = 0; i < labelLayoutList.length; i++) {
  43384. var layout = labelLayoutList[i];
  43385. if (!isPositionCenter(layout) && layout.linePoints) {
  43386. var label = layout.label;
  43387. var linePoints = layout.linePoints;
  43388. var isAlignToEdge = layout.labelAlignTo === 'edge';
  43389. var padding = label.style.padding;
  43390. var paddingH = padding ? padding[1] + padding[3] : 0;
  43391. // textRect.width already contains paddingH if bgColor is set
  43392. var extraPaddingH = label.style.backgroundColor ? 0 : paddingH;
  43393. var realTextWidth = layout.rect.width + extraPaddingH;
  43394. var dist = linePoints[1][0] - linePoints[2][0];
  43395. if (isAlignToEdge) {
  43396. if (label.x < cx) {
  43397. linePoints[2][0] = viewLeft + layout.edgeDistance + realTextWidth + layout.labelDistance;
  43398. } else {
  43399. linePoints[2][0] = viewLeft + viewWidth - layout.edgeDistance - realTextWidth - layout.labelDistance;
  43400. }
  43401. } else {
  43402. if (label.x < cx) {
  43403. linePoints[2][0] = label.x + layout.labelDistance;
  43404. } else {
  43405. linePoints[2][0] = label.x - layout.labelDistance;
  43406. }
  43407. linePoints[1][0] = linePoints[2][0] + dist;
  43408. }
  43409. linePoints[1][1] = linePoints[2][1] = label.y;
  43410. }
  43411. }
  43412. }
  43413. /**
  43414. * Set max width of each label, and then wrap each label to the max width.
  43415. *
  43416. * @param layout label layout
  43417. * @param availableWidth max width for the label to display
  43418. * @param forceRecalculate recaculate the text layout even if the current width
  43419. * is smaller than `availableWidth`. This is useful when the text was previously
  43420. * wrapped by calling `constrainTextWidth` but now `availableWidth` changed, in
  43421. * which case, previous wrapping should be redo.
  43422. */
  43423. function constrainTextWidth(layout, availableWidth, forceRecalculate) {
  43424. if (layout.labelStyleWidth != null) {
  43425. // User-defined style.width has the highest priority.
  43426. return;
  43427. }
  43428. var label = layout.label;
  43429. var style = label.style;
  43430. var textRect = layout.rect;
  43431. var bgColor = style.backgroundColor;
  43432. var padding = style.padding;
  43433. var paddingH = padding ? padding[1] + padding[3] : 0;
  43434. var overflow = style.overflow;
  43435. // textRect.width already contains paddingH if bgColor is set
  43436. var oldOuterWidth = textRect.width + (bgColor ? 0 : paddingH);
  43437. if (availableWidth < oldOuterWidth || forceRecalculate) {
  43438. if (overflow && overflow.match('break')) {
  43439. // Temporarily set background to be null to calculate
  43440. // the bounding box without background.
  43441. label.setStyle('backgroundColor', null);
  43442. // Set constraining width
  43443. label.setStyle('width', availableWidth - paddingH);
  43444. // This is the real bounding box of the text without padding.
  43445. var innerRect = label.getBoundingRect();
  43446. label.setStyle('width', Math.ceil(innerRect.width));
  43447. label.setStyle('backgroundColor', bgColor);
  43448. } else {
  43449. var availableInnerWidth = availableWidth - paddingH;
  43450. var newWidth = availableWidth < oldOuterWidth
  43451. // Current text is too wide, use `availableWidth` as max width.
  43452. ? availableInnerWidth :
  43453. // Current available width is enough, but the text may have
  43454. // already been wrapped with a smaller available width.
  43455. forceRecalculate ? availableInnerWidth > layout.unconstrainedWidth
  43456. // Current available is larger than text width,
  43457. // so don't constrain width (otherwise it may have
  43458. // empty space in the background).
  43459. ? null
  43460. // Current available is smaller than text width, so
  43461. // use the current available width as constraining
  43462. // width.
  43463. : availableInnerWidth
  43464. // Current available width is enough, so no need to
  43465. // constrain.
  43466. : null;
  43467. label.setStyle('width', newWidth);
  43468. }
  43469. computeLabelGlobalRect(textRect, label);
  43470. }
  43471. }
  43472. function computeLabelGlobalRect(out, label) {
  43473. _tmpLabelGeometry.rect = out;
  43474. computeLabelGeometry(_tmpLabelGeometry, label, _computeLabelGeometryOpt);
  43475. }
  43476. var _computeLabelGeometryOpt = {
  43477. minMarginForce: [null, 0, null, 0],
  43478. marginDefault: [1, 0, 1, 0]
  43479. };
  43480. var _tmpLabelGeometry = {};
  43481. function isPositionCenter(sectorShape) {
  43482. // Not change x for center label
  43483. return sectorShape.position === 'center';
  43484. }
  43485. function pieLabelLayout(seriesModel) {
  43486. var data = seriesModel.getData();
  43487. var labelLayoutList = [];
  43488. var cx;
  43489. var cy;
  43490. var hasLabelRotate = false;
  43491. var minShowLabelRadian = (seriesModel.get('minShowLabelAngle') || 0) * RADIAN$1;
  43492. var viewRect = data.getLayout('viewRect');
  43493. var r = data.getLayout('r');
  43494. var viewWidth = viewRect.width;
  43495. var viewLeft = viewRect.x;
  43496. var viewTop = viewRect.y;
  43497. var viewHeight = viewRect.height;
  43498. function setNotShow(el) {
  43499. el.ignore = true;
  43500. }
  43501. function isLabelShown(label) {
  43502. if (!label.ignore) {
  43503. return true;
  43504. }
  43505. for (var key in label.states) {
  43506. if (label.states[key].ignore === false) {
  43507. return true;
  43508. }
  43509. }
  43510. return false;
  43511. }
  43512. data.each(function (idx) {
  43513. var sector = data.getItemGraphicEl(idx);
  43514. var sectorShape = sector.shape;
  43515. var label = sector.getTextContent();
  43516. var labelLine = sector.getTextGuideLine();
  43517. var itemModel = data.getItemModel(idx);
  43518. var labelModel = itemModel.getModel('label');
  43519. // Use position in normal or emphasis
  43520. var labelPosition = labelModel.get('position') || itemModel.get(['emphasis', 'label', 'position']);
  43521. var labelDistance = labelModel.get('distanceToLabelLine');
  43522. var labelAlignTo = labelModel.get('alignTo');
  43523. var edgeDistance = parsePercent$1(labelModel.get('edgeDistance'), viewWidth);
  43524. var bleedMargin = labelModel.get('bleedMargin');
  43525. if (bleedMargin == null) {
  43526. // An arbitrary strategy for small viewRect - especial pie is layout in calendar or matrix coord sys.
  43527. bleedMargin = Math.min(viewWidth, viewHeight) > 200 ? 10 : 2;
  43528. }
  43529. var labelLineModel = itemModel.getModel('labelLine');
  43530. var labelLineLen = labelLineModel.get('length');
  43531. labelLineLen = parsePercent$1(labelLineLen, viewWidth);
  43532. var labelLineLen2 = labelLineModel.get('length2');
  43533. labelLineLen2 = parsePercent$1(labelLineLen2, viewWidth);
  43534. if (Math.abs(sectorShape.endAngle - sectorShape.startAngle) < minShowLabelRadian) {
  43535. each(label.states, setNotShow);
  43536. label.ignore = true;
  43537. if (labelLine) {
  43538. each(labelLine.states, setNotShow);
  43539. labelLine.ignore = true;
  43540. }
  43541. return;
  43542. }
  43543. if (!isLabelShown(label)) {
  43544. return;
  43545. }
  43546. var midAngle = (sectorShape.startAngle + sectorShape.endAngle) / 2;
  43547. var nx = Math.cos(midAngle);
  43548. var ny = Math.sin(midAngle);
  43549. var textX;
  43550. var textY;
  43551. var linePoints;
  43552. var textAlign;
  43553. cx = sectorShape.cx;
  43554. cy = sectorShape.cy;
  43555. var isLabelInside = labelPosition === 'inside' || labelPosition === 'inner';
  43556. if (labelPosition === 'center') {
  43557. textX = sectorShape.cx;
  43558. textY = sectorShape.cy;
  43559. textAlign = 'center';
  43560. } else {
  43561. var x1 = (isLabelInside ? (sectorShape.r + sectorShape.r0) / 2 * nx : sectorShape.r * nx) + cx;
  43562. var y1 = (isLabelInside ? (sectorShape.r + sectorShape.r0) / 2 * ny : sectorShape.r * ny) + cy;
  43563. textX = x1 + nx * 3;
  43564. textY = y1 + ny * 3;
  43565. if (!isLabelInside) {
  43566. // For roseType
  43567. var x2 = x1 + nx * (labelLineLen + r - sectorShape.r);
  43568. var y2 = y1 + ny * (labelLineLen + r - sectorShape.r);
  43569. var x3 = x2 + (nx < 0 ? -1 : 1) * labelLineLen2;
  43570. var y3 = y2;
  43571. if (labelAlignTo === 'edge') {
  43572. // Adjust textX because text align of edge is opposite
  43573. textX = nx < 0 ? viewLeft + edgeDistance : viewLeft + viewWidth - edgeDistance;
  43574. } else {
  43575. textX = x3 + (nx < 0 ? -labelDistance : labelDistance);
  43576. }
  43577. textY = y3;
  43578. linePoints = [[x1, y1], [x2, y2], [x3, y3]];
  43579. }
  43580. textAlign = isLabelInside ? 'center' : labelAlignTo === 'edge' ? nx > 0 ? 'right' : 'left' : nx > 0 ? 'left' : 'right';
  43581. }
  43582. var PI = Math.PI;
  43583. var labelRotate = 0;
  43584. var rotate = labelModel.get('rotate');
  43585. if (isNumber(rotate)) {
  43586. labelRotate = rotate * (PI / 180);
  43587. } else if (labelPosition === 'center') {
  43588. labelRotate = 0;
  43589. } else if (rotate === 'radial' || rotate === true) {
  43590. var radialAngle = nx < 0 ? -midAngle + PI : -midAngle;
  43591. labelRotate = radialAngle;
  43592. } else if (rotate === 'tangential' && labelPosition !== 'outside' && labelPosition !== 'outer') {
  43593. var rad = Math.atan2(nx, ny);
  43594. if (rad < 0) {
  43595. rad = PI * 2 + rad;
  43596. }
  43597. var isDown = ny > 0;
  43598. if (isDown) {
  43599. rad = PI + rad;
  43600. }
  43601. labelRotate = rad - PI;
  43602. }
  43603. hasLabelRotate = !!labelRotate;
  43604. label.x = textX;
  43605. label.y = textY;
  43606. label.rotation = labelRotate;
  43607. label.setStyle({
  43608. verticalAlign: 'middle'
  43609. });
  43610. // Not sectorShape the inside label
  43611. if (!isLabelInside) {
  43612. var textRect = new BoundingRect(0, 0, 0, 0);
  43613. computeLabelGlobalRect(textRect, label);
  43614. labelLayoutList.push({
  43615. label: label,
  43616. labelLine: labelLine,
  43617. position: labelPosition,
  43618. len: labelLineLen,
  43619. len2: labelLineLen2,
  43620. minTurnAngle: labelLineModel.get('minTurnAngle'),
  43621. maxSurfaceAngle: labelLineModel.get('maxSurfaceAngle'),
  43622. surfaceNormal: new Point(nx, ny),
  43623. linePoints: linePoints,
  43624. textAlign: textAlign,
  43625. labelDistance: labelDistance,
  43626. labelAlignTo: labelAlignTo,
  43627. edgeDistance: edgeDistance,
  43628. bleedMargin: bleedMargin,
  43629. rect: textRect,
  43630. unconstrainedWidth: textRect.width,
  43631. labelStyleWidth: label.style.width
  43632. });
  43633. } else {
  43634. label.setStyle({
  43635. align: textAlign
  43636. });
  43637. var selectState = label.states.select;
  43638. if (selectState) {
  43639. selectState.x += label.x;
  43640. selectState.y += label.y;
  43641. }
  43642. }
  43643. sector.setTextConfig({
  43644. inside: isLabelInside
  43645. });
  43646. });
  43647. if (!hasLabelRotate && seriesModel.get('avoidLabelOverlap')) {
  43648. avoidOverlap(labelLayoutList, cx, cy, r, viewWidth, viewHeight, viewLeft, viewTop);
  43649. }
  43650. for (var i = 0; i < labelLayoutList.length; i++) {
  43651. var layout = labelLayoutList[i];
  43652. var label = layout.label;
  43653. var labelLine = layout.labelLine;
  43654. var notShowLabel = isNaN(label.x) || isNaN(label.y);
  43655. if (label) {
  43656. label.setStyle({
  43657. align: layout.textAlign
  43658. });
  43659. if (notShowLabel) {
  43660. each(label.states, setNotShow);
  43661. label.ignore = true;
  43662. }
  43663. var selectState = label.states.select;
  43664. if (selectState) {
  43665. selectState.x += label.x;
  43666. selectState.y += label.y;
  43667. }
  43668. }
  43669. if (labelLine) {
  43670. var linePoints = layout.linePoints;
  43671. if (notShowLabel || !linePoints) {
  43672. each(labelLine.states, setNotShow);
  43673. labelLine.ignore = true;
  43674. } else {
  43675. limitTurnAngle(linePoints, layout.minTurnAngle);
  43676. limitSurfaceAngle(linePoints, layout.surfaceNormal, layout.maxSurfaceAngle);
  43677. labelLine.setShape({
  43678. points: linePoints
  43679. });
  43680. // Set the anchor to the midpoint of sector
  43681. label.__hostTarget.textGuideLineConfig = {
  43682. anchor: new Point(linePoints[0][0], linePoints[0][1])
  43683. };
  43684. }
  43685. }
  43686. }
  43687. }
  43688. /**
  43689. * Piece of pie including Sector, Label, LabelLine
  43690. */
  43691. var PiePiece = /** @class */function (_super) {
  43692. __extends(PiePiece, _super);
  43693. function PiePiece(data, idx, startAngle) {
  43694. var _this = _super.call(this) || this;
  43695. _this.z2 = 2;
  43696. var text = new ZRText();
  43697. _this.setTextContent(text);
  43698. _this.updateData(data, idx, startAngle, true);
  43699. return _this;
  43700. }
  43701. PiePiece.prototype.updateData = function (data, idx, startAngle, firstCreate) {
  43702. var sector = this;
  43703. var seriesModel = data.hostModel;
  43704. var itemModel = data.getItemModel(idx);
  43705. var emphasisModel = itemModel.getModel('emphasis');
  43706. var layout = data.getItemLayout(idx);
  43707. // cornerRadius & innerCornerRadius doesn't exist in the item layout. Use `0` if null value is specified.
  43708. // see `setItemLayout` in `pieLayout.ts`.
  43709. var sectorShape = extend(getSectorCornerRadius(itemModel.getModel('itemStyle'), layout, true), layout);
  43710. // Ignore NaN data.
  43711. if (isNaN(sectorShape.startAngle)) {
  43712. // Use NaN shape to avoid drawing shape.
  43713. sector.setShape(sectorShape);
  43714. return;
  43715. }
  43716. if (firstCreate) {
  43717. sector.setShape(sectorShape);
  43718. var animationType = seriesModel.getShallow('animationType');
  43719. if (seriesModel.ecModel.ssr) {
  43720. // Use scale animation in SSR mode(opacity?)
  43721. // Because CSS SVG animation doesn't support very customized shape animation.
  43722. initProps(sector, {
  43723. scaleX: 0,
  43724. scaleY: 0
  43725. }, seriesModel, {
  43726. dataIndex: idx,
  43727. isFrom: true
  43728. });
  43729. sector.originX = sectorShape.cx;
  43730. sector.originY = sectorShape.cy;
  43731. } else if (animationType === 'scale') {
  43732. sector.shape.r = layout.r0;
  43733. initProps(sector, {
  43734. shape: {
  43735. r: layout.r
  43736. }
  43737. }, seriesModel, idx);
  43738. }
  43739. // Expansion
  43740. else {
  43741. if (startAngle != null) {
  43742. sector.setShape({
  43743. startAngle: startAngle,
  43744. endAngle: startAngle
  43745. });
  43746. initProps(sector, {
  43747. shape: {
  43748. startAngle: layout.startAngle,
  43749. endAngle: layout.endAngle
  43750. }
  43751. }, seriesModel, idx);
  43752. } else {
  43753. sector.shape.endAngle = layout.startAngle;
  43754. updateProps(sector, {
  43755. shape: {
  43756. endAngle: layout.endAngle
  43757. }
  43758. }, seriesModel, idx);
  43759. }
  43760. }
  43761. } else {
  43762. saveOldStyle(sector);
  43763. // Transition animation from the old shape
  43764. updateProps(sector, {
  43765. shape: sectorShape
  43766. }, seriesModel, idx);
  43767. }
  43768. sector.useStyle(data.getItemVisual(idx, 'style'));
  43769. setStatesStylesFromModel(sector, itemModel);
  43770. var midAngle = (layout.startAngle + layout.endAngle) / 2;
  43771. var offset = seriesModel.get('selectedOffset');
  43772. var dx = Math.cos(midAngle) * offset;
  43773. var dy = Math.sin(midAngle) * offset;
  43774. var cursorStyle = itemModel.getShallow('cursor');
  43775. cursorStyle && sector.attr('cursor', cursorStyle);
  43776. this._updateLabel(seriesModel, data, idx);
  43777. sector.ensureState('emphasis').shape = extend({
  43778. r: layout.r + (emphasisModel.get('scale') ? emphasisModel.get('scaleSize') || 0 : 0)
  43779. }, getSectorCornerRadius(emphasisModel.getModel('itemStyle'), layout));
  43780. extend(sector.ensureState('select'), {
  43781. x: dx,
  43782. y: dy,
  43783. shape: getSectorCornerRadius(itemModel.getModel(['select', 'itemStyle']), layout)
  43784. });
  43785. extend(sector.ensureState('blur'), {
  43786. shape: getSectorCornerRadius(itemModel.getModel(['blur', 'itemStyle']), layout)
  43787. });
  43788. var labelLine = sector.getTextGuideLine();
  43789. var labelText = sector.getTextContent();
  43790. labelLine && extend(labelLine.ensureState('select'), {
  43791. x: dx,
  43792. y: dy
  43793. });
  43794. // TODO: needs dx, dy in zrender?
  43795. extend(labelText.ensureState('select'), {
  43796. x: dx,
  43797. y: dy
  43798. });
  43799. toggleHoverEmphasis(this, emphasisModel.get('focus'), emphasisModel.get('blurScope'), emphasisModel.get('disabled'));
  43800. };
  43801. PiePiece.prototype._updateLabel = function (seriesModel, data, idx) {
  43802. var sector = this;
  43803. var itemModel = data.getItemModel(idx);
  43804. var labelLineModel = itemModel.getModel('labelLine');
  43805. var style = data.getItemVisual(idx, 'style');
  43806. var visualColor = style && style.fill;
  43807. var visualOpacity = style && style.opacity;
  43808. setLabelStyle(sector, getLabelStatesModels(itemModel), {
  43809. labelFetcher: data.hostModel,
  43810. labelDataIndex: idx,
  43811. inheritColor: visualColor,
  43812. defaultOpacity: visualOpacity,
  43813. defaultText: seriesModel.getFormattedLabel(idx, 'normal') || data.getName(idx)
  43814. });
  43815. var labelText = sector.getTextContent();
  43816. // Set textConfig on sector.
  43817. sector.setTextConfig({
  43818. // reset position, rotation
  43819. position: null,
  43820. rotation: null
  43821. });
  43822. // Make sure update style on labelText after setLabelStyle.
  43823. // Because setLabelStyle will replace a new style on it.
  43824. labelText.attr({
  43825. z2: 10
  43826. });
  43827. var labelPosition = itemModel.get(['label', 'position']);
  43828. if (labelPosition !== 'outside' && labelPosition !== 'outer') {
  43829. sector.removeTextGuideLine();
  43830. } else {
  43831. var polyline = this.getTextGuideLine();
  43832. if (!polyline) {
  43833. polyline = new Polyline();
  43834. this.setTextGuideLine(polyline);
  43835. }
  43836. // Default use item visual color
  43837. setLabelLineStyle(this, getLabelLineStatesModels(itemModel), {
  43838. stroke: visualColor,
  43839. opacity: retrieve3(labelLineModel.get(['lineStyle', 'opacity']), visualOpacity, 1)
  43840. });
  43841. }
  43842. };
  43843. return PiePiece;
  43844. }(Sector);
  43845. // Pie view
  43846. var PieView = /** @class */function (_super) {
  43847. __extends(PieView, _super);
  43848. function PieView() {
  43849. var _this = _super !== null && _super.apply(this, arguments) || this;
  43850. _this.ignoreLabelLineUpdate = true;
  43851. return _this;
  43852. }
  43853. PieView.prototype.render = function (seriesModel, ecModel, api, payload) {
  43854. var data = seriesModel.getData();
  43855. var oldData = this._data;
  43856. var group = this.group;
  43857. var startAngle;
  43858. // First render
  43859. if (!oldData && data.count() > 0) {
  43860. var shape = data.getItemLayout(0);
  43861. for (var s = 1; isNaN(shape && shape.startAngle) && s < data.count(); ++s) {
  43862. shape = data.getItemLayout(s);
  43863. }
  43864. if (shape) {
  43865. startAngle = shape.startAngle;
  43866. }
  43867. }
  43868. // remove empty-circle if it exists
  43869. if (this._emptyCircleSector) {
  43870. group.remove(this._emptyCircleSector);
  43871. }
  43872. // when all data are filtered, show lightgray empty circle
  43873. if (data.count() === 0 && seriesModel.get('showEmptyCircle')) {
  43874. var layoutData = getSeriesLayoutData(seriesModel);
  43875. var sector = new Sector({
  43876. shape: clone(layoutData)
  43877. });
  43878. sector.useStyle(seriesModel.getModel('emptyCircleStyle').getItemStyle());
  43879. this._emptyCircleSector = sector;
  43880. group.add(sector);
  43881. }
  43882. data.diff(oldData).add(function (idx) {
  43883. var piePiece = new PiePiece(data, idx, startAngle);
  43884. data.setItemGraphicEl(idx, piePiece);
  43885. group.add(piePiece);
  43886. }).update(function (newIdx, oldIdx) {
  43887. var piePiece = oldData.getItemGraphicEl(oldIdx);
  43888. piePiece.updateData(data, newIdx, startAngle);
  43889. piePiece.off('click');
  43890. group.add(piePiece);
  43891. data.setItemGraphicEl(newIdx, piePiece);
  43892. }).remove(function (idx) {
  43893. var piePiece = oldData.getItemGraphicEl(idx);
  43894. removeElementWithFadeOut(piePiece, seriesModel, idx);
  43895. }).execute();
  43896. pieLabelLayout(seriesModel);
  43897. // Always use initial animation.
  43898. if (seriesModel.get('animationTypeUpdate') !== 'expansion') {
  43899. this._data = data;
  43900. }
  43901. };
  43902. PieView.prototype.dispose = function () {};
  43903. PieView.prototype.containPoint = function (point, seriesModel) {
  43904. var data = seriesModel.getData();
  43905. var itemLayout = data.getItemLayout(0);
  43906. if (itemLayout) {
  43907. var dx = point[0] - itemLayout.cx;
  43908. var dy = point[1] - itemLayout.cy;
  43909. var radius = Math.sqrt(dx * dx + dy * dy);
  43910. return radius <= itemLayout.r && radius >= itemLayout.r0;
  43911. }
  43912. };
  43913. PieView.type = 'pie';
  43914. return PieView;
  43915. }(ChartView);
  43916. /**
  43917. * [Usage]:
  43918. * (1)
  43919. * createListSimply(seriesModel, ['value']);
  43920. * (2)
  43921. * createListSimply(seriesModel, {
  43922. * coordDimensions: ['value'],
  43923. * dimensionsCount: 5
  43924. * });
  43925. */
  43926. function createSeriesDataSimply(seriesModel, opt, nameList) {
  43927. opt = isArray(opt) && {
  43928. coordDimensions: opt
  43929. } || extend({
  43930. encodeDefine: seriesModel.getEncode()
  43931. }, opt);
  43932. var source = seriesModel.getSource();
  43933. var dimensions = prepareSeriesDataSchema(source, opt).dimensions;
  43934. var list = new SeriesData(dimensions, seriesModel);
  43935. list.initData(source, nameList);
  43936. return list;
  43937. }
  43938. /*
  43939. * Licensed to the Apache Software Foundation (ASF) under one
  43940. * or more contributor license agreements. See the NOTICE file
  43941. * distributed with this work for additional information
  43942. * regarding copyright ownership. The ASF licenses this file
  43943. * to you under the Apache License, Version 2.0 (the
  43944. * "License"); you may not use this file except in compliance
  43945. * with the License. You may obtain a copy of the License at
  43946. *
  43947. * http://www.apache.org/licenses/LICENSE-2.0
  43948. *
  43949. * Unless required by applicable law or agreed to in writing,
  43950. * software distributed under the License is distributed on an
  43951. * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
  43952. * KIND, either express or implied. See the License for the
  43953. * specific language governing permissions and limitations
  43954. * under the License.
  43955. */
  43956. /**
  43957. * AUTO-GENERATED FILE. DO NOT MODIFY.
  43958. */
  43959. /*
  43960. * Licensed to the Apache Software Foundation (ASF) under one
  43961. * or more contributor license agreements. See the NOTICE file
  43962. * distributed with this work for additional information
  43963. * regarding copyright ownership. The ASF licenses this file
  43964. * to you under the Apache License, Version 2.0 (the
  43965. * "License"); you may not use this file except in compliance
  43966. * with the License. You may obtain a copy of the License at
  43967. *
  43968. * http://www.apache.org/licenses/LICENSE-2.0
  43969. *
  43970. * Unless required by applicable law or agreed to in writing,
  43971. * software distributed under the License is distributed on an
  43972. * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
  43973. * KIND, either express or implied. See the License for the
  43974. * specific language governing permissions and limitations
  43975. * under the License.
  43976. */
  43977. /**
  43978. * LegendVisualProvider is an bridge that pick encoded color from data and
  43979. * provide to the legend component.
  43980. */
  43981. var LegendVisualProvider = /** @class */function () {
  43982. function LegendVisualProvider(
  43983. // Function to get data after filtered. It stores all the encoding info
  43984. getDataWithEncodedVisual,
  43985. // Function to get raw data before filtered.
  43986. getRawData) {
  43987. this._getDataWithEncodedVisual = getDataWithEncodedVisual;
  43988. this._getRawData = getRawData;
  43989. }
  43990. LegendVisualProvider.prototype.getAllNames = function () {
  43991. var rawData = this._getRawData();
  43992. // We find the name from the raw data. In case it's filtered by the legend component.
  43993. // Normally, the name can be found in rawData, but can't be found in filtered data will display as gray.
  43994. return rawData.mapArray(rawData.getName);
  43995. };
  43996. LegendVisualProvider.prototype.containName = function (name) {
  43997. var rawData = this._getRawData();
  43998. return rawData.indexOfName(name) >= 0;
  43999. };
  44000. LegendVisualProvider.prototype.indexOfName = function (name) {
  44001. // Only get data when necessary.
  44002. // Because LegendVisualProvider constructor may be new in the stage that data is not prepared yet.
  44003. // Invoking Series#getData immediately will throw an error.
  44004. var dataWithEncodedVisual = this._getDataWithEncodedVisual();
  44005. return dataWithEncodedVisual.indexOfName(name);
  44006. };
  44007. LegendVisualProvider.prototype.getItemVisual = function (dataIndex, key) {
  44008. // Get encoded visual properties from final filtered data.
  44009. var dataWithEncodedVisual = this._getDataWithEncodedVisual();
  44010. return dataWithEncodedVisual.getItemVisual(dataIndex, key);
  44011. };
  44012. return LegendVisualProvider;
  44013. }();
  44014. var innerData = makeInner();
  44015. var PieSeriesModel = /** @class */function (_super) {
  44016. __extends(PieSeriesModel, _super);
  44017. function PieSeriesModel() {
  44018. return _super !== null && _super.apply(this, arguments) || this;
  44019. }
  44020. /**
  44021. * @overwrite
  44022. */
  44023. PieSeriesModel.prototype.init = function (option) {
  44024. _super.prototype.init.apply(this, arguments);
  44025. // Enable legend selection for each data item
  44026. // Use a function instead of direct access because data reference may changed
  44027. this.legendVisualProvider = new LegendVisualProvider(bind(this.getData, this), bind(this.getRawData, this));
  44028. this._defaultLabelLine(option);
  44029. };
  44030. /**
  44031. * @overwrite
  44032. */
  44033. PieSeriesModel.prototype.mergeOption = function () {
  44034. _super.prototype.mergeOption.apply(this, arguments);
  44035. };
  44036. /**
  44037. * @overwrite
  44038. */
  44039. PieSeriesModel.prototype.getInitialData = function () {
  44040. return createSeriesDataSimply(this, {
  44041. coordDimensions: ['value'],
  44042. encodeDefaulter: curry(makeSeriesEncodeForNameBased, this)
  44043. });
  44044. };
  44045. /**
  44046. * @overwrite
  44047. */
  44048. PieSeriesModel.prototype.getDataParams = function (dataIndex) {
  44049. var data = this.getData();
  44050. // update seats when data is changed
  44051. var dataInner = innerData(data);
  44052. var seats = dataInner.seats;
  44053. if (!seats) {
  44054. var valueList_1 = [];
  44055. data.each(data.mapDimension('value'), function (value) {
  44056. valueList_1.push(value);
  44057. });
  44058. seats = dataInner.seats = getPercentSeats(valueList_1, data.hostModel.get('percentPrecision'));
  44059. }
  44060. var params = _super.prototype.getDataParams.call(this, dataIndex);
  44061. // seats may be empty when sum is 0
  44062. params.percent = seats[dataIndex] || 0;
  44063. params.$vars.push('percent');
  44064. return params;
  44065. };
  44066. PieSeriesModel.prototype._defaultLabelLine = function (option) {
  44067. // Extend labelLine emphasis
  44068. defaultEmphasis(option, 'labelLine', ['show']);
  44069. var labelLineNormalOpt = option.labelLine;
  44070. var labelLineEmphasisOpt = option.emphasis.labelLine;
  44071. // Not show label line if `label.normal.show = false`
  44072. labelLineNormalOpt.show = labelLineNormalOpt.show && option.label.show;
  44073. labelLineEmphasisOpt.show = labelLineEmphasisOpt.show && option.emphasis.label.show;
  44074. };
  44075. PieSeriesModel.type = 'series.pie';
  44076. PieSeriesModel.defaultOption = {
  44077. // zlevel: 0,
  44078. z: 2,
  44079. legendHoverLink: true,
  44080. colorBy: 'data',
  44081. // 默认全局居中
  44082. center: ['50%', '50%'],
  44083. radius: [0, '50%'],
  44084. // 默认顺时针
  44085. clockwise: true,
  44086. startAngle: 90,
  44087. endAngle: 'auto',
  44088. padAngle: 0,
  44089. // 最小角度改为0
  44090. minAngle: 0,
  44091. // If the angle of a sector less than `minShowLabelAngle`,
  44092. // the label will not be displayed.
  44093. minShowLabelAngle: 0,
  44094. // 选中时扇区偏移量
  44095. selectedOffset: 10,
  44096. // 选择模式,默认关闭,可选single,multiple
  44097. // selectedMode: false,
  44098. // 南丁格尔玫瑰图模式,'radius'(半径) | 'area'(面积)
  44099. // roseType: null,
  44100. percentPrecision: 2,
  44101. // If still show when all data zero.
  44102. stillShowZeroSum: true,
  44103. // cursor: null,
  44104. coordinateSystemUsage: 'box',
  44105. left: 0,
  44106. top: 0,
  44107. right: 0,
  44108. bottom: 0,
  44109. width: null,
  44110. height: null,
  44111. label: {
  44112. // color: 'inherit',
  44113. // If rotate around circle
  44114. rotate: 0,
  44115. show: true,
  44116. overflow: 'truncate',
  44117. // 'outer', 'inside', 'center'
  44118. position: 'outer',
  44119. // 'none', 'labelLine', 'edge'. Works only when position is 'outer'
  44120. alignTo: 'none',
  44121. // Closest distance between label and chart edge.
  44122. // Works only position is 'outer' and alignTo is 'edge'.
  44123. edgeDistance: '25%',
  44124. // Works only position is 'outer' and alignTo is not 'edge'.
  44125. // The default `bleedMargin` is auto determined according to view rect size.
  44126. // bleedMargin: 10,
  44127. // Distance between text and label line.
  44128. distanceToLabelLine: 5
  44129. // formatter: 标签文本格式器,同 tooltip.formatter,不支持异步回调
  44130. // 默认使用全局文本样式,详见 textStyle
  44131. // distance: 当position为inner时有效,为label位置到圆心的距离与圆半径(环状图为内外半径和)的比例系数
  44132. },
  44133. // Enabled when label.normal.position is 'outer'
  44134. labelLine: {
  44135. show: true,
  44136. // 引导线两段中的第一段长度
  44137. length: 15,
  44138. // 引导线两段中的第二段长度
  44139. length2: 30,
  44140. smooth: false,
  44141. minTurnAngle: 90,
  44142. maxSurfaceAngle: 90,
  44143. lineStyle: {
  44144. // color: 各异,
  44145. width: 1,
  44146. type: 'solid'
  44147. }
  44148. },
  44149. itemStyle: {
  44150. borderWidth: 1,
  44151. borderJoin: 'round'
  44152. },
  44153. showEmptyCircle: true,
  44154. emptyCircleStyle: {
  44155. color: 'lightgray',
  44156. opacity: 1
  44157. },
  44158. labelLayout: {
  44159. // Hide the overlapped label.
  44160. hideOverlap: true
  44161. },
  44162. emphasis: {
  44163. scale: true,
  44164. scaleSize: 5
  44165. },
  44166. // If use strategy to avoid label overlapping
  44167. avoidLabelOverlap: true,
  44168. // Animation type. Valid values: expansion, scale
  44169. animationType: 'expansion',
  44170. animationDuration: 1000,
  44171. // Animation type when update. Valid values: transition, expansion
  44172. animationTypeUpdate: 'transition',
  44173. animationEasingUpdate: 'cubicInOut',
  44174. animationDurationUpdate: 500,
  44175. animationEasing: 'cubicInOut'
  44176. };
  44177. return PieSeriesModel;
  44178. }(SeriesModel);
  44179. registerLayOutOnCoordSysUsage({
  44180. fullType: PieSeriesModel.type,
  44181. getCoord2: function (model) {
  44182. // Not able to validate `center` type here.
  44183. // But percentage center, such as '12%', is not allowed in this case.
  44184. return model.getShallow('center');
  44185. }
  44186. });
  44187. function negativeDataFilter(seriesType) {
  44188. return {
  44189. seriesType: seriesType,
  44190. reset: function (seriesModel, ecModel) {
  44191. var data = seriesModel.getData();
  44192. data.filterSelf(function (idx) {
  44193. // handle negative value condition
  44194. var valueDim = data.mapDimension('value');
  44195. var curValue = data.get(valueDim, idx);
  44196. if (isNumber(curValue) && !isNaN(curValue) && curValue < 0) {
  44197. return false;
  44198. }
  44199. return true;
  44200. });
  44201. }
  44202. };
  44203. }
  44204. function install$4(registers) {
  44205. registers.registerChartView(PieView);
  44206. registers.registerSeriesModel(PieSeriesModel);
  44207. createLegacyDataSelectAction('pie', registers.registerAction);
  44208. registers.registerLayout(curry(pieLayout, 'pie'));
  44209. registers.registerProcessor(dataFilter('pie'));
  44210. registers.registerProcessor(negativeDataFilter('pie'));
  44211. }
  44212. var ScatterSeriesModel = /** @class */function (_super) {
  44213. __extends(ScatterSeriesModel, _super);
  44214. function ScatterSeriesModel() {
  44215. var _this = _super !== null && _super.apply(this, arguments) || this;
  44216. _this.type = ScatterSeriesModel.type;
  44217. _this.hasSymbolVisual = true;
  44218. return _this;
  44219. }
  44220. ScatterSeriesModel.prototype.getInitialData = function (option, ecModel) {
  44221. return createSeriesData(null, this, {
  44222. useEncodeDefaulter: true
  44223. });
  44224. };
  44225. ScatterSeriesModel.prototype.getProgressive = function () {
  44226. var progressive = this.option.progressive;
  44227. if (progressive == null) {
  44228. // PENDING
  44229. return this.option.large ? 5e3 : this.get('progressive');
  44230. }
  44231. return progressive;
  44232. };
  44233. ScatterSeriesModel.prototype.getProgressiveThreshold = function () {
  44234. var progressiveThreshold = this.option.progressiveThreshold;
  44235. if (progressiveThreshold == null) {
  44236. // PENDING
  44237. return this.option.large ? 1e4 : this.get('progressiveThreshold');
  44238. }
  44239. return progressiveThreshold;
  44240. };
  44241. ScatterSeriesModel.prototype.brushSelector = function (dataIndex, data, selectors) {
  44242. return selectors.point(data.getItemLayout(dataIndex));
  44243. };
  44244. ScatterSeriesModel.prototype.getZLevelKey = function () {
  44245. // Each progressive series has individual key.
  44246. return this.getData().count() > this.getProgressiveThreshold() ? this.id : '';
  44247. };
  44248. ScatterSeriesModel.type = 'series.scatter';
  44249. ScatterSeriesModel.dependencies = ['grid', 'polar', 'geo', 'singleAxis', 'calendar', 'matrix'];
  44250. ScatterSeriesModel.defaultOption = {
  44251. coordinateSystem: 'cartesian2d',
  44252. // zlevel: 0,
  44253. z: 2,
  44254. legendHoverLink: true,
  44255. symbolSize: 10,
  44256. // symbolRotate: null, // 图形旋转控制
  44257. large: false,
  44258. // Available when large is true
  44259. largeThreshold: 2000,
  44260. // cursor: null,
  44261. itemStyle: {
  44262. opacity: 0.8
  44263. // color: 各异
  44264. },
  44265. emphasis: {
  44266. scale: true
  44267. },
  44268. // If clip the overflow graphics
  44269. // Works on cartesian / polar series
  44270. clip: true,
  44271. select: {
  44272. itemStyle: {
  44273. borderColor: tokens.color.primary
  44274. }
  44275. },
  44276. universalTransition: {
  44277. divideShape: 'clone'
  44278. }
  44279. // progressive: null
  44280. };
  44281. return ScatterSeriesModel;
  44282. }(SeriesModel);
  44283. var BOOST_SIZE_THRESHOLD = 4;
  44284. var LargeSymbolPathShape = /** @class */function () {
  44285. function LargeSymbolPathShape() {}
  44286. return LargeSymbolPathShape;
  44287. }();
  44288. var LargeSymbolPath = /** @class */function (_super) {
  44289. __extends(LargeSymbolPath, _super);
  44290. function LargeSymbolPath(opts) {
  44291. var _this = _super.call(this, opts) || this;
  44292. _this._off = 0;
  44293. _this.hoverDataIdx = -1;
  44294. return _this;
  44295. }
  44296. LargeSymbolPath.prototype.getDefaultShape = function () {
  44297. return new LargeSymbolPathShape();
  44298. };
  44299. LargeSymbolPath.prototype.reset = function () {
  44300. this.notClear = false;
  44301. this._off = 0;
  44302. };
  44303. LargeSymbolPath.prototype.buildPath = function (path, shape) {
  44304. var points = shape.points;
  44305. var size = shape.size;
  44306. var symbolProxy = this.symbolProxy;
  44307. var symbolProxyShape = symbolProxy.shape;
  44308. var ctx = path.getContext ? path.getContext() : path;
  44309. var canBoost = ctx && size[0] < BOOST_SIZE_THRESHOLD;
  44310. var softClipShape = this.softClipShape;
  44311. var i;
  44312. // Do draw in afterBrush.
  44313. if (canBoost) {
  44314. this._ctx = ctx;
  44315. return;
  44316. }
  44317. this._ctx = null;
  44318. for (i = this._off; i < points.length;) {
  44319. var x = points[i++];
  44320. var y = points[i++];
  44321. if (isNaN(x) || isNaN(y)) {
  44322. continue;
  44323. }
  44324. if (softClipShape && !softClipShape.contain(x, y)) {
  44325. continue;
  44326. }
  44327. symbolProxyShape.x = x - size[0] / 2;
  44328. symbolProxyShape.y = y - size[1] / 2;
  44329. symbolProxyShape.width = size[0];
  44330. symbolProxyShape.height = size[1];
  44331. symbolProxy.buildPath(path, symbolProxyShape, true);
  44332. }
  44333. if (this.incremental) {
  44334. this._off = i;
  44335. this.notClear = true;
  44336. }
  44337. };
  44338. LargeSymbolPath.prototype.afterBrush = function () {
  44339. var shape = this.shape;
  44340. var points = shape.points;
  44341. var size = shape.size;
  44342. var ctx = this._ctx;
  44343. var softClipShape = this.softClipShape;
  44344. var i;
  44345. if (!ctx) {
  44346. return;
  44347. }
  44348. // PENDING If style or other canvas status changed?
  44349. for (i = this._off; i < points.length;) {
  44350. var x = points[i++];
  44351. var y = points[i++];
  44352. if (isNaN(x) || isNaN(y)) {
  44353. continue;
  44354. }
  44355. if (softClipShape && !softClipShape.contain(x, y)) {
  44356. continue;
  44357. }
  44358. // fillRect is faster than building a rect path and draw.
  44359. // And it support light globalCompositeOperation.
  44360. ctx.fillRect(x - size[0] / 2, y - size[1] / 2, size[0], size[1]);
  44361. }
  44362. if (this.incremental) {
  44363. this._off = i;
  44364. this.notClear = true;
  44365. }
  44366. };
  44367. LargeSymbolPath.prototype.findDataIndex = function (x, y) {
  44368. // TODO ???
  44369. // Consider transform
  44370. var shape = this.shape;
  44371. var points = shape.points;
  44372. var size = shape.size;
  44373. var w = Math.max(size[0], 4);
  44374. var h = Math.max(size[1], 4);
  44375. // Not consider transform
  44376. // Treat each element as a rect
  44377. // top down traverse
  44378. for (var idx = points.length / 2 - 1; idx >= 0; idx--) {
  44379. var i = idx * 2;
  44380. var x0 = points[i] - w / 2;
  44381. var y0 = points[i + 1] - h / 2;
  44382. if (x >= x0 && y >= y0 && x <= x0 + w && y <= y0 + h) {
  44383. return idx;
  44384. }
  44385. }
  44386. return -1;
  44387. };
  44388. LargeSymbolPath.prototype.contain = function (x, y) {
  44389. var localPos = this.transformCoordToLocal(x, y);
  44390. var rect = this.getBoundingRect();
  44391. x = localPos[0];
  44392. y = localPos[1];
  44393. if (rect.contain(x, y)) {
  44394. // Cache found data index.
  44395. var dataIdx = this.hoverDataIdx = this.findDataIndex(x, y);
  44396. return dataIdx >= 0;
  44397. }
  44398. this.hoverDataIdx = -1;
  44399. return false;
  44400. };
  44401. LargeSymbolPath.prototype.getBoundingRect = function () {
  44402. // Ignore stroke for large symbol draw.
  44403. var rect = this._rect;
  44404. if (!rect) {
  44405. var shape = this.shape;
  44406. var points = shape.points;
  44407. var size = shape.size;
  44408. var w = size[0];
  44409. var h = size[1];
  44410. var minX = Infinity;
  44411. var minY = Infinity;
  44412. var maxX = -Infinity;
  44413. var maxY = -Infinity;
  44414. for (var i = 0; i < points.length;) {
  44415. var x = points[i++];
  44416. var y = points[i++];
  44417. minX = Math.min(x, minX);
  44418. maxX = Math.max(x, maxX);
  44419. minY = Math.min(y, minY);
  44420. maxY = Math.max(y, maxY);
  44421. }
  44422. rect = this._rect = new BoundingRect(minX - w / 2, minY - h / 2, maxX - minX + w, maxY - minY + h);
  44423. }
  44424. return rect;
  44425. };
  44426. return LargeSymbolPath;
  44427. }(Path);
  44428. var LargeSymbolDraw = /** @class */function () {
  44429. function LargeSymbolDraw() {
  44430. this.group = new Group();
  44431. }
  44432. /**
  44433. * Update symbols draw by new data
  44434. */
  44435. LargeSymbolDraw.prototype.updateData = function (data, opt) {
  44436. this._clear();
  44437. var symbolEl = this._create();
  44438. symbolEl.setShape({
  44439. points: data.getLayout('points')
  44440. });
  44441. this._setCommon(symbolEl, data, opt);
  44442. };
  44443. LargeSymbolDraw.prototype.updateLayout = function (data) {
  44444. var points = data.getLayout('points');
  44445. this.group.eachChild(function (child) {
  44446. if (child.startIndex != null) {
  44447. var len = (child.endIndex - child.startIndex) * 2;
  44448. var byteOffset = child.startIndex * 4 * 2;
  44449. points = new Float32Array(points.buffer, byteOffset, len);
  44450. }
  44451. child.setShape('points', points);
  44452. // Reset draw cursor.
  44453. child.reset();
  44454. });
  44455. };
  44456. LargeSymbolDraw.prototype.incrementalPrepareUpdate = function (data) {
  44457. this._clear();
  44458. };
  44459. LargeSymbolDraw.prototype.incrementalUpdate = function (taskParams, data, opt) {
  44460. var lastAdded = this._newAdded[0];
  44461. var points = data.getLayout('points');
  44462. var oldPoints = lastAdded && lastAdded.shape.points;
  44463. // Merging the exists. Each element has 1e4 points.
  44464. // Consider the performance balance between too much elements and too much points in one shape(may affect hover optimization)
  44465. if (oldPoints && oldPoints.length < 2e4) {
  44466. var oldLen = oldPoints.length;
  44467. var newPoints = new Float32Array(oldLen + points.length);
  44468. // Concat two array
  44469. newPoints.set(oldPoints);
  44470. newPoints.set(points, oldLen);
  44471. // Update endIndex
  44472. lastAdded.endIndex = taskParams.end;
  44473. lastAdded.setShape({
  44474. points: newPoints
  44475. });
  44476. } else {
  44477. // Clear
  44478. this._newAdded = [];
  44479. var symbolEl = this._create();
  44480. symbolEl.startIndex = taskParams.start;
  44481. symbolEl.endIndex = taskParams.end;
  44482. symbolEl.incremental = true;
  44483. symbolEl.setShape({
  44484. points: points
  44485. });
  44486. this._setCommon(symbolEl, data, opt);
  44487. }
  44488. };
  44489. LargeSymbolDraw.prototype.eachRendered = function (cb) {
  44490. this._newAdded[0] && cb(this._newAdded[0]);
  44491. };
  44492. LargeSymbolDraw.prototype._create = function () {
  44493. var symbolEl = new LargeSymbolPath({
  44494. cursor: 'default'
  44495. });
  44496. symbolEl.ignoreCoarsePointer = true;
  44497. this.group.add(symbolEl);
  44498. this._newAdded.push(symbolEl);
  44499. return symbolEl;
  44500. };
  44501. LargeSymbolDraw.prototype._setCommon = function (symbolEl, data, opt) {
  44502. var hostModel = data.hostModel;
  44503. opt = opt || {};
  44504. var size = data.getVisual('symbolSize');
  44505. symbolEl.setShape('size', size instanceof Array ? size : [size, size]);
  44506. symbolEl.softClipShape = opt.clipShape || null;
  44507. // Create symbolProxy to build path for each data
  44508. symbolEl.symbolProxy = createSymbol(data.getVisual('symbol'), 0, 0, 0, 0);
  44509. // Use symbolProxy setColor method
  44510. symbolEl.setColor = symbolEl.symbolProxy.setColor;
  44511. var extrudeShadow = symbolEl.shape.size[0] < BOOST_SIZE_THRESHOLD;
  44512. symbolEl.useStyle(
  44513. // Draw shadow when doing fillRect is extremely slow.
  44514. hostModel.getModel('itemStyle').getItemStyle(extrudeShadow ? ['color', 'shadowBlur', 'shadowColor'] : ['color']));
  44515. var globalStyle = data.getVisual('style');
  44516. var visualColor = globalStyle && globalStyle.fill;
  44517. if (visualColor) {
  44518. symbolEl.setColor(visualColor);
  44519. }
  44520. var ecData = getECData(symbolEl);
  44521. // Enable tooltip
  44522. // PENDING May have performance issue when path is extremely large
  44523. ecData.seriesIndex = hostModel.seriesIndex;
  44524. symbolEl.on('mousemove', function (e) {
  44525. ecData.dataIndex = null;
  44526. var dataIndex = symbolEl.hoverDataIdx;
  44527. if (dataIndex >= 0) {
  44528. // Provide dataIndex for tooltip
  44529. ecData.dataIndex = dataIndex + (symbolEl.startIndex || 0);
  44530. }
  44531. });
  44532. };
  44533. LargeSymbolDraw.prototype.remove = function () {
  44534. this._clear();
  44535. };
  44536. LargeSymbolDraw.prototype._clear = function () {
  44537. this._newAdded = [];
  44538. this.group.removeAll();
  44539. };
  44540. return LargeSymbolDraw;
  44541. }();
  44542. var ScatterView = /** @class */function (_super) {
  44543. __extends(ScatterView, _super);
  44544. function ScatterView() {
  44545. var _this = _super !== null && _super.apply(this, arguments) || this;
  44546. _this.type = ScatterView.type;
  44547. return _this;
  44548. }
  44549. ScatterView.prototype.render = function (seriesModel, ecModel, api) {
  44550. var data = seriesModel.getData();
  44551. var symbolDraw = this._updateSymbolDraw(data, seriesModel);
  44552. symbolDraw.updateData(data, {
  44553. // TODO
  44554. // If this parameter should be a shape or a bounding volume
  44555. // shape will be more general.
  44556. // But bounding volume like bounding rect will be much faster in the contain calculation
  44557. clipShape: this._getClipShape(seriesModel)
  44558. });
  44559. this._finished = true;
  44560. };
  44561. ScatterView.prototype.incrementalPrepareRender = function (seriesModel, ecModel, api) {
  44562. var data = seriesModel.getData();
  44563. var symbolDraw = this._updateSymbolDraw(data, seriesModel);
  44564. symbolDraw.incrementalPrepareUpdate(data);
  44565. this._finished = false;
  44566. };
  44567. ScatterView.prototype.incrementalRender = function (taskParams, seriesModel, ecModel) {
  44568. this._symbolDraw.incrementalUpdate(taskParams, seriesModel.getData(), {
  44569. clipShape: this._getClipShape(seriesModel)
  44570. });
  44571. this._finished = taskParams.end === seriesModel.getData().count();
  44572. };
  44573. ScatterView.prototype.updateTransform = function (seriesModel, ecModel, api) {
  44574. var data = seriesModel.getData();
  44575. // Must mark group dirty and make sure the incremental layer will be cleared
  44576. // PENDING
  44577. this.group.dirty();
  44578. if (!this._finished || data.count() > 1e4) {
  44579. return {
  44580. update: true
  44581. };
  44582. } else {
  44583. var res = pointsLayout('').reset(seriesModel, ecModel, api);
  44584. if (res.progress) {
  44585. res.progress({
  44586. start: 0,
  44587. end: data.count(),
  44588. count: data.count()
  44589. }, data);
  44590. }
  44591. this._symbolDraw.updateLayout(data);
  44592. }
  44593. };
  44594. ScatterView.prototype.eachRendered = function (cb) {
  44595. this._symbolDraw && this._symbolDraw.eachRendered(cb);
  44596. };
  44597. ScatterView.prototype._getClipShape = function (seriesModel) {
  44598. if (!seriesModel.get('clip', true)) {
  44599. return;
  44600. }
  44601. var coordSys = seriesModel.coordinateSystem;
  44602. // PENDING make `0.1` configurable, for example, `clipTolerance`?
  44603. return coordSys && coordSys.getArea && coordSys.getArea(.1);
  44604. };
  44605. ScatterView.prototype._updateSymbolDraw = function (data, seriesModel) {
  44606. var symbolDraw = this._symbolDraw;
  44607. var pipelineContext = seriesModel.pipelineContext;
  44608. var isLargeDraw = pipelineContext.large;
  44609. if (!symbolDraw || isLargeDraw !== this._isLargeDraw) {
  44610. symbolDraw && symbolDraw.remove();
  44611. symbolDraw = this._symbolDraw = isLargeDraw ? new LargeSymbolDraw() : new SymbolDraw();
  44612. this._isLargeDraw = isLargeDraw;
  44613. this.group.removeAll();
  44614. }
  44615. this.group.add(symbolDraw.group);
  44616. return symbolDraw;
  44617. };
  44618. ScatterView.prototype.remove = function (ecModel, api) {
  44619. this._symbolDraw && this._symbolDraw.remove(true);
  44620. this._symbolDraw = null;
  44621. };
  44622. ScatterView.prototype.dispose = function () {};
  44623. ScatterView.type = 'scatter';
  44624. return ScatterView;
  44625. }(ChartView);
  44626. // For backward compatibility, do not use a margin. Although the labels might touch the edge of
  44627. // the canvas, the chart canvas probably does not have an border or a different background color within a page.
  44628. var OUTER_BOUNDS_DEFAULT = {
  44629. left: 0,
  44630. right: 0,
  44631. top: 0,
  44632. bottom: 0
  44633. };
  44634. var OUTER_BOUNDS_CLAMP_DEFAULT = ['25%', '25%'];
  44635. var GridModel = /** @class */function (_super) {
  44636. __extends(GridModel, _super);
  44637. function GridModel() {
  44638. return _super !== null && _super.apply(this, arguments) || this;
  44639. }
  44640. GridModel.prototype.mergeDefaultAndTheme = function (option, ecModel) {
  44641. var outerBoundsCp = getLayoutParams(option.outerBounds);
  44642. _super.prototype.mergeDefaultAndTheme.apply(this, arguments);
  44643. if (outerBoundsCp && option.outerBounds) {
  44644. mergeLayoutParam(option.outerBounds, outerBoundsCp);
  44645. }
  44646. };
  44647. GridModel.prototype.mergeOption = function (newOption, ecModel) {
  44648. _super.prototype.mergeOption.apply(this, arguments);
  44649. if (this.option.outerBounds && newOption.outerBounds) {
  44650. mergeLayoutParam(this.option.outerBounds, newOption.outerBounds);
  44651. }
  44652. };
  44653. GridModel.type = 'grid';
  44654. GridModel.dependencies = ['xAxis', 'yAxis'];
  44655. GridModel.layoutMode = 'box';
  44656. GridModel.defaultOption = {
  44657. show: false,
  44658. // zlevel: 0,
  44659. z: 0,
  44660. left: '15%',
  44661. top: 65,
  44662. right: '10%',
  44663. bottom: 80,
  44664. // If grid size contain label
  44665. containLabel: false,
  44666. outerBoundsMode: 'auto',
  44667. outerBounds: OUTER_BOUNDS_DEFAULT,
  44668. outerBoundsContain: 'all',
  44669. outerBoundsClampWidth: OUTER_BOUNDS_CLAMP_DEFAULT[0],
  44670. outerBoundsClampHeight: OUTER_BOUNDS_CLAMP_DEFAULT[1],
  44671. // width: {totalWidth} - left - right,
  44672. // height: {totalHeight} - top - bottom,
  44673. backgroundColor: tokens.color.transparent,
  44674. borderWidth: 1,
  44675. borderColor: tokens.color.neutral30
  44676. };
  44677. return GridModel;
  44678. }(ComponentModel);
  44679. var CartesianAxisModel = /** @class */function (_super) {
  44680. __extends(CartesianAxisModel, _super);
  44681. function CartesianAxisModel() {
  44682. return _super !== null && _super.apply(this, arguments) || this;
  44683. }
  44684. CartesianAxisModel.prototype.getCoordSysModel = function () {
  44685. return this.getReferringComponents('grid', SINGLE_REFERRING).models[0];
  44686. };
  44687. CartesianAxisModel.type = 'cartesian2dAxis';
  44688. return CartesianAxisModel;
  44689. }(ComponentModel);
  44690. mixin(CartesianAxisModel, AxisModelCommonMixin);
  44691. var defaultOption = {
  44692. show: true,
  44693. // zlevel: 0,
  44694. z: 0,
  44695. // Inverse the axis.
  44696. inverse: false,
  44697. // Axis name displayed.
  44698. name: '',
  44699. // 'start' | 'middle' | 'end'
  44700. nameLocation: 'end',
  44701. // By degree. By default auto rotate by nameLocation.
  44702. nameRotate: null,
  44703. nameTruncate: {
  44704. maxWidth: null,
  44705. ellipsis: '...',
  44706. placeholder: '.'
  44707. },
  44708. // Use global text style by default.
  44709. nameTextStyle: {
  44710. // textMargin: never, // The default value will be specified based on `nameLocation`.
  44711. },
  44712. // The gap between axisName and axisLine.
  44713. nameGap: 15,
  44714. // Default `false` to support tooltip.
  44715. silent: false,
  44716. // Default `false` to avoid legacy user event listener fail.
  44717. triggerEvent: false,
  44718. tooltip: {
  44719. show: false
  44720. },
  44721. axisPointer: {},
  44722. axisLine: {
  44723. show: true,
  44724. onZero: true,
  44725. onZeroAxisIndex: null,
  44726. lineStyle: {
  44727. color: tokens.color.axisLine,
  44728. width: 1,
  44729. type: 'solid'
  44730. },
  44731. // The arrow at both ends the the axis.
  44732. symbol: ['none', 'none'],
  44733. symbolSize: [10, 15],
  44734. breakLine: true
  44735. },
  44736. axisTick: {
  44737. show: true,
  44738. // Whether axisTick is inside the grid or outside the grid.
  44739. inside: false,
  44740. // The length of axisTick.
  44741. length: 5,
  44742. lineStyle: {
  44743. width: 1
  44744. }
  44745. },
  44746. axisLabel: {
  44747. show: true,
  44748. // Whether axisLabel is inside the grid or outside the grid.
  44749. inside: false,
  44750. rotate: 0,
  44751. // true | false | null/undefined (auto)
  44752. showMinLabel: null,
  44753. // true | false | null/undefined (auto)
  44754. showMaxLabel: null,
  44755. margin: 8,
  44756. // formatter: null,
  44757. fontSize: 12,
  44758. color: tokens.color.axisLabel,
  44759. // In scenarios like axis labels, when labels text's progression direction matches the label
  44760. // layout direction (e.g., when all letters are in a single line), extra start/end margin is
  44761. // needed to prevent the text from appearing visually joined. In the other case, when lables
  44762. // are stacked (e.g., having rotation or horizontal labels on yAxis), the layout needs to be
  44763. // compact, so NO extra top/bottom margin should be applied.
  44764. textMargin: [0, 3]
  44765. },
  44766. splitLine: {
  44767. show: true,
  44768. showMinLine: true,
  44769. showMaxLine: true,
  44770. lineStyle: {
  44771. color: tokens.color.axisSplitLine,
  44772. width: 1,
  44773. type: 'solid'
  44774. }
  44775. },
  44776. splitArea: {
  44777. show: false,
  44778. areaStyle: {
  44779. color: [tokens.color.backgroundTint, tokens.color.backgroundTransparent]
  44780. }
  44781. },
  44782. breakArea: {
  44783. show: true,
  44784. itemStyle: {
  44785. color: tokens.color.neutral00,
  44786. // Break border color should be darker than the splitLine
  44787. // because it has opacity and should be more prominent
  44788. borderColor: tokens.color.border,
  44789. borderWidth: 1,
  44790. borderType: [3, 3],
  44791. opacity: 0.6
  44792. },
  44793. zigzagAmplitude: 4,
  44794. zigzagMinSpan: 4,
  44795. zigzagMaxSpan: 20,
  44796. zigzagZ: 100,
  44797. expandOnClick: true
  44798. },
  44799. breakLabelLayout: {
  44800. moveOverlap: 'auto'
  44801. }
  44802. };
  44803. var categoryAxis = merge({
  44804. // The gap at both ends of the axis. For categoryAxis, boolean.
  44805. boundaryGap: true,
  44806. // Set false to faster category collection.
  44807. deduplication: null,
  44808. jitter: 0,
  44809. jitterOverlap: true,
  44810. jitterMargin: 2,
  44811. // splitArea: {
  44812. // show: false
  44813. // },
  44814. splitLine: {
  44815. show: false
  44816. },
  44817. axisTick: {
  44818. // If tick is align with label when boundaryGap is true
  44819. alignWithLabel: false,
  44820. interval: 'auto',
  44821. show: 'auto'
  44822. },
  44823. axisLabel: {
  44824. interval: 'auto'
  44825. }
  44826. }, defaultOption);
  44827. var valueAxis = merge({
  44828. boundaryGap: [0, 0],
  44829. axisLine: {
  44830. // Not shown when other axis is categoryAxis in cartesian
  44831. show: 'auto'
  44832. },
  44833. axisTick: {
  44834. // Not shown when other axis is categoryAxis in cartesian
  44835. show: 'auto'
  44836. },
  44837. // TODO
  44838. // min/max: [30, datamin, 60] or [20, datamin] or [datamin, 60]
  44839. splitNumber: 5,
  44840. minorTick: {
  44841. // Minor tick, not available for cateogry axis.
  44842. show: false,
  44843. // Split number of minor ticks. The value should be in range of (0, 100)
  44844. splitNumber: 5,
  44845. // Length of minor tick
  44846. length: 3,
  44847. // Line style
  44848. lineStyle: {
  44849. // Default to be same with axisTick
  44850. }
  44851. },
  44852. minorSplitLine: {
  44853. show: false,
  44854. lineStyle: {
  44855. color: tokens.color.axisMinorSplitLine,
  44856. width: 1
  44857. }
  44858. }
  44859. }, defaultOption);
  44860. var timeAxis = merge({
  44861. splitNumber: 6,
  44862. axisLabel: {
  44863. // To eliminate labels that are not nice
  44864. showMinLabel: false,
  44865. showMaxLabel: false,
  44866. rich: {
  44867. primary: {
  44868. fontWeight: 'bold'
  44869. }
  44870. }
  44871. },
  44872. splitLine: {
  44873. show: false
  44874. }
  44875. }, valueAxis);
  44876. var logAxis = defaults({
  44877. logBase: 10
  44878. }, valueAxis);
  44879. var axisDefault = {
  44880. category: categoryAxis,
  44881. value: valueAxis,
  44882. time: timeAxis,
  44883. log: logAxis
  44884. };
  44885. /*
  44886. * Licensed to the Apache Software Foundation (ASF) under one
  44887. * or more contributor license agreements. See the NOTICE file
  44888. * distributed with this work for additional information
  44889. * regarding copyright ownership. The ASF licenses this file
  44890. * to you under the Apache License, Version 2.0 (the
  44891. * "License"); you may not use this file except in compliance
  44892. * with the License. You may obtain a copy of the License at
  44893. *
  44894. * http://www.apache.org/licenses/LICENSE-2.0
  44895. *
  44896. * Unless required by applicable law or agreed to in writing,
  44897. * software distributed under the License is distributed on an
  44898. * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
  44899. * KIND, either express or implied. See the License for the
  44900. * specific language governing permissions and limitations
  44901. * under the License.
  44902. */
  44903. /**
  44904. * AUTO-GENERATED FILE. DO NOT MODIFY.
  44905. */
  44906. /*
  44907. * Licensed to the Apache Software Foundation (ASF) under one
  44908. * or more contributor license agreements. See the NOTICE file
  44909. * distributed with this work for additional information
  44910. * regarding copyright ownership. The ASF licenses this file
  44911. * to you under the Apache License, Version 2.0 (the
  44912. * "License"); you may not use this file except in compliance
  44913. * with the License. You may obtain a copy of the License at
  44914. *
  44915. * http://www.apache.org/licenses/LICENSE-2.0
  44916. *
  44917. * Unless required by applicable law or agreed to in writing,
  44918. * software distributed under the License is distributed on an
  44919. * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
  44920. * KIND, either express or implied. See the License for the
  44921. * specific language governing permissions and limitations
  44922. * under the License.
  44923. */
  44924. var AXIS_TYPES = {
  44925. value: 1,
  44926. category: 1,
  44927. time: 1,
  44928. log: 1
  44929. };
  44930. /*
  44931. * Licensed to the Apache Software Foundation (ASF) under one
  44932. * or more contributor license agreements. See the NOTICE file
  44933. * distributed with this work for additional information
  44934. * regarding copyright ownership. The ASF licenses this file
  44935. * to you under the Apache License, Version 2.0 (the
  44936. * "License"); you may not use this file except in compliance
  44937. * with the License. You may obtain a copy of the License at
  44938. *
  44939. * http://www.apache.org/licenses/LICENSE-2.0
  44940. *
  44941. * Unless required by applicable law or agreed to in writing,
  44942. * software distributed under the License is distributed on an
  44943. * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
  44944. * KIND, either express or implied. See the License for the
  44945. * specific language governing permissions and limitations
  44946. * under the License.
  44947. */
  44948. /**
  44949. * AUTO-GENERATED FILE. DO NOT MODIFY.
  44950. */
  44951. /*
  44952. * Licensed to the Apache Software Foundation (ASF) under one
  44953. * or more contributor license agreements. See the NOTICE file
  44954. * distributed with this work for additional information
  44955. * regarding copyright ownership. The ASF licenses this file
  44956. * to you under the Apache License, Version 2.0 (the
  44957. * "License"); you may not use this file except in compliance
  44958. * with the License. You may obtain a copy of the License at
  44959. *
  44960. * http://www.apache.org/licenses/LICENSE-2.0
  44961. *
  44962. * Unless required by applicable law or agreed to in writing,
  44963. * software distributed under the License is distributed on an
  44964. * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
  44965. * KIND, either express or implied. See the License for the
  44966. * specific language governing permissions and limitations
  44967. * under the License.
  44968. */
  44969. var _impl$1 = null;
  44970. function registerAxisBreakHelperImpl(impl) {
  44971. if (!_impl$1) {
  44972. _impl$1 = impl;
  44973. }
  44974. }
  44975. function getAxisBreakHelper() {
  44976. return _impl$1;
  44977. }
  44978. /**
  44979. * Generate sub axis model class
  44980. * @param axisName 'x' 'y' 'radius' 'angle' 'parallel' ...
  44981. */
  44982. function axisModelCreator(registers, axisName, BaseAxisModelClass, extraDefaultOption) {
  44983. each(AXIS_TYPES, function (v, axisType) {
  44984. var defaultOption = merge(merge({}, axisDefault[axisType], true), extraDefaultOption, true);
  44985. var AxisModel = /** @class */function (_super) {
  44986. __extends(AxisModel, _super);
  44987. function AxisModel() {
  44988. var _this = _super !== null && _super.apply(this, arguments) || this;
  44989. _this.type = axisName + 'Axis.' + axisType;
  44990. return _this;
  44991. }
  44992. AxisModel.prototype.mergeDefaultAndTheme = function (option, ecModel) {
  44993. var layoutMode = fetchLayoutMode(this);
  44994. var inputPositionParams = layoutMode ? getLayoutParams(option) : {};
  44995. var themeModel = ecModel.getTheme();
  44996. merge(option, themeModel.get(axisType + 'Axis'));
  44997. merge(option, this.getDefaultOption());
  44998. option.type = getAxisType(option);
  44999. if (layoutMode) {
  45000. mergeLayoutParam(option, inputPositionParams, layoutMode);
  45001. }
  45002. };
  45003. AxisModel.prototype.optionUpdated = function () {
  45004. var thisOption = this.option;
  45005. if (thisOption.type === 'category') {
  45006. this.__ordinalMeta = OrdinalMeta.createByAxisModel(this);
  45007. }
  45008. };
  45009. /**
  45010. * Should not be called before all of 'getInitailData' finished.
  45011. * Because categories are collected during initializing data.
  45012. */
  45013. AxisModel.prototype.getCategories = function (rawData) {
  45014. var option = this.option;
  45015. // FIXME
  45016. // warning if called before all of 'getInitailData' finished.
  45017. if (option.type === 'category') {
  45018. if (rawData) {
  45019. return option.data;
  45020. }
  45021. return this.__ordinalMeta.categories;
  45022. }
  45023. };
  45024. AxisModel.prototype.getOrdinalMeta = function () {
  45025. return this.__ordinalMeta;
  45026. };
  45027. AxisModel.prototype.updateAxisBreaks = function (payload) {
  45028. var axisBreakHelper = getAxisBreakHelper();
  45029. return axisBreakHelper ? axisBreakHelper.updateModelAxisBreak(this, payload) : {
  45030. breaks: []
  45031. };
  45032. };
  45033. AxisModel.type = axisName + 'Axis.' + axisType;
  45034. AxisModel.defaultOption = defaultOption;
  45035. return AxisModel;
  45036. }(BaseAxisModelClass);
  45037. registers.registerComponentModel(AxisModel);
  45038. });
  45039. registers.registerSubTypeDefaulter(axisName + 'Axis', getAxisType);
  45040. }
  45041. function getAxisType(option) {
  45042. // Default axis with data is category axis
  45043. return option.type || (option.data ? 'category' : 'value');
  45044. }
  45045. var Cartesian = /** @class */function () {
  45046. function Cartesian(name) {
  45047. this.type = 'cartesian';
  45048. this._dimList = [];
  45049. this._axes = {};
  45050. this.name = name || '';
  45051. }
  45052. Cartesian.prototype.getAxis = function (dim) {
  45053. return this._axes[dim];
  45054. };
  45055. Cartesian.prototype.getAxes = function () {
  45056. return map(this._dimList, function (dim) {
  45057. return this._axes[dim];
  45058. }, this);
  45059. };
  45060. Cartesian.prototype.getAxesByScale = function (scaleType) {
  45061. scaleType = scaleType.toLowerCase();
  45062. return filter(this.getAxes(), function (axis) {
  45063. return axis.scale.type === scaleType;
  45064. });
  45065. };
  45066. Cartesian.prototype.addAxis = function (axis) {
  45067. var dim = axis.dim;
  45068. this._axes[dim] = axis;
  45069. this._dimList.push(dim);
  45070. };
  45071. return Cartesian;
  45072. }();
  45073. var cartesian2DDimensions = ['x', 'y'];
  45074. function canCalculateAffineTransform(scale) {
  45075. return (scale.type === 'interval' || scale.type === 'time') && !scale.hasBreaks();
  45076. }
  45077. var Cartesian2D = /** @class */function (_super) {
  45078. __extends(Cartesian2D, _super);
  45079. function Cartesian2D() {
  45080. var _this = _super !== null && _super.apply(this, arguments) || this;
  45081. _this.type = 'cartesian2d';
  45082. _this.dimensions = cartesian2DDimensions;
  45083. return _this;
  45084. }
  45085. /**
  45086. * Calculate an affine transform matrix if two axes are time or value.
  45087. * It's mainly for accelartion on the large time series data.
  45088. */
  45089. Cartesian2D.prototype.calcAffineTransform = function () {
  45090. this._transform = this._invTransform = null;
  45091. var xAxisScale = this.getAxis('x').scale;
  45092. var yAxisScale = this.getAxis('y').scale;
  45093. if (!canCalculateAffineTransform(xAxisScale) || !canCalculateAffineTransform(yAxisScale)) {
  45094. return;
  45095. }
  45096. var xScaleExtent = xAxisScale.getExtent();
  45097. var yScaleExtent = yAxisScale.getExtent();
  45098. var start = this.dataToPoint([xScaleExtent[0], yScaleExtent[0]]);
  45099. var end = this.dataToPoint([xScaleExtent[1], yScaleExtent[1]]);
  45100. var xScaleSpan = xScaleExtent[1] - xScaleExtent[0];
  45101. var yScaleSpan = yScaleExtent[1] - yScaleExtent[0];
  45102. if (!xScaleSpan || !yScaleSpan) {
  45103. return;
  45104. }
  45105. // Accelerate data to point calculation on the special large time series data.
  45106. var scaleX = (end[0] - start[0]) / xScaleSpan;
  45107. var scaleY = (end[1] - start[1]) / yScaleSpan;
  45108. var translateX = start[0] - xScaleExtent[0] * scaleX;
  45109. var translateY = start[1] - yScaleExtent[0] * scaleY;
  45110. var m = this._transform = [scaleX, 0, 0, scaleY, translateX, translateY];
  45111. this._invTransform = invert([], m);
  45112. };
  45113. /**
  45114. * Base axis will be used on stacking.
  45115. */
  45116. Cartesian2D.prototype.getBaseAxis = function () {
  45117. return this.getAxesByScale('ordinal')[0] || this.getAxesByScale('time')[0] || this.getAxis('x');
  45118. };
  45119. Cartesian2D.prototype.containPoint = function (point) {
  45120. var axisX = this.getAxis('x');
  45121. var axisY = this.getAxis('y');
  45122. return axisX.contain(axisX.toLocalCoord(point[0])) && axisY.contain(axisY.toLocalCoord(point[1]));
  45123. };
  45124. Cartesian2D.prototype.containData = function (data) {
  45125. return this.getAxis('x').containData(data[0]) && this.getAxis('y').containData(data[1]);
  45126. };
  45127. Cartesian2D.prototype.containZone = function (data1, data2) {
  45128. var zoneDiag1 = this.dataToPoint(data1);
  45129. var zoneDiag2 = this.dataToPoint(data2);
  45130. var area = this.getArea();
  45131. var zone = new BoundingRect(zoneDiag1[0], zoneDiag1[1], zoneDiag2[0] - zoneDiag1[0], zoneDiag2[1] - zoneDiag1[1]);
  45132. return area.intersect(zone);
  45133. };
  45134. Cartesian2D.prototype.dataToPoint = function (data, clamp, out) {
  45135. out = out || [];
  45136. var xVal = data[0];
  45137. var yVal = data[1];
  45138. // [CAVEAT]: Do not add time consuming operation within and before fast path.
  45139. // Fast path.
  45140. if (this._transform
  45141. // It's supported that if data is like `[Inifity, 123]`, where only Y pixel calculated.
  45142. && xVal != null && isFinite(xVal) && yVal != null && isFinite(yVal)) {
  45143. return applyTransform(out, data, this._transform);
  45144. }
  45145. var xAxis = this.getAxis('x');
  45146. var yAxis = this.getAxis('y');
  45147. out[0] = xAxis.toGlobalCoord(xAxis.dataToCoord(xVal, clamp));
  45148. out[1] = yAxis.toGlobalCoord(yAxis.dataToCoord(yVal, clamp));
  45149. return out;
  45150. };
  45151. Cartesian2D.prototype.clampData = function (data, out) {
  45152. var xScale = this.getAxis('x').scale;
  45153. var yScale = this.getAxis('y').scale;
  45154. var xAxisExtent = xScale.getExtent();
  45155. var yAxisExtent = yScale.getExtent();
  45156. var x = xScale.parse(data[0]);
  45157. var y = yScale.parse(data[1]);
  45158. out = out || [];
  45159. out[0] = Math.min(Math.max(Math.min(xAxisExtent[0], xAxisExtent[1]), x), Math.max(xAxisExtent[0], xAxisExtent[1]));
  45160. out[1] = Math.min(Math.max(Math.min(yAxisExtent[0], yAxisExtent[1]), y), Math.max(yAxisExtent[0], yAxisExtent[1]));
  45161. return out;
  45162. };
  45163. Cartesian2D.prototype.pointToData = function (point, clamp, out) {
  45164. out = out || [];
  45165. if (this._invTransform) {
  45166. return applyTransform(out, point, this._invTransform);
  45167. }
  45168. var xAxis = this.getAxis('x');
  45169. var yAxis = this.getAxis('y');
  45170. out[0] = xAxis.coordToData(xAxis.toLocalCoord(point[0]), clamp);
  45171. out[1] = yAxis.coordToData(yAxis.toLocalCoord(point[1]), clamp);
  45172. return out;
  45173. };
  45174. Cartesian2D.prototype.getOtherAxis = function (axis) {
  45175. return this.getAxis(axis.dim === 'x' ? 'y' : 'x');
  45176. };
  45177. /**
  45178. * Get rect area of cartesian.
  45179. * Area will have a contain function to determine if a point is in the coordinate system.
  45180. */
  45181. Cartesian2D.prototype.getArea = function (tolerance) {
  45182. tolerance = tolerance || 0;
  45183. var xExtent = this.getAxis('x').getGlobalExtent();
  45184. var yExtent = this.getAxis('y').getGlobalExtent();
  45185. var x = Math.min(xExtent[0], xExtent[1]) - tolerance;
  45186. var y = Math.min(yExtent[0], yExtent[1]) - tolerance;
  45187. var width = Math.max(xExtent[0], xExtent[1]) - x + tolerance;
  45188. var height = Math.max(yExtent[0], yExtent[1]) - y + tolerance;
  45189. return new BoundingRect(x, y, width, height);
  45190. };
  45191. return Cartesian2D;
  45192. }(Cartesian);
  45193. var Axis2D = /** @class */function (_super) {
  45194. __extends(Axis2D, _super);
  45195. function Axis2D(dim, scale, coordExtent, axisType, position) {
  45196. var _this = _super.call(this, dim, scale, coordExtent) || this;
  45197. /**
  45198. * Index of axis, can be used as key
  45199. * Injected outside.
  45200. */
  45201. _this.index = 0;
  45202. _this.type = axisType || 'value';
  45203. _this.position = position || 'bottom';
  45204. return _this;
  45205. }
  45206. Axis2D.prototype.isHorizontal = function () {
  45207. var position = this.position;
  45208. return position === 'top' || position === 'bottom';
  45209. };
  45210. /**
  45211. * Each item cooresponds to this.getExtent(), which
  45212. * means globalExtent[0] may greater than globalExtent[1],
  45213. * unless `asc` is input.
  45214. *
  45215. * @param {boolean} [asc]
  45216. * @return {Array.<number>}
  45217. */
  45218. Axis2D.prototype.getGlobalExtent = function (asc) {
  45219. var ret = this.getExtent();
  45220. ret[0] = this.toGlobalCoord(ret[0]);
  45221. ret[1] = this.toGlobalCoord(ret[1]);
  45222. asc && ret[0] > ret[1] && ret.reverse();
  45223. return ret;
  45224. };
  45225. Axis2D.prototype.pointToData = function (point, clamp) {
  45226. return this.coordToData(this.toLocalCoord(point[this.dim === 'x' ? 0 : 1]), clamp);
  45227. };
  45228. /**
  45229. * Set ordinalSortInfo
  45230. * @param info new OrdinalSortInfo
  45231. */
  45232. Axis2D.prototype.setCategorySortInfo = function (info) {
  45233. if (this.type !== 'category') {
  45234. return false;
  45235. }
  45236. this.model.option.categorySortInfo = info;
  45237. this.scale.setSortInfo(info);
  45238. };
  45239. return Axis2D;
  45240. }(Axis);
  45241. var AXIS_BREAK_EXPAND_ACTION_TYPE = 'expandAxisBreak';
  45242. var AXIS_BREAK_COLLAPSE_ACTION_TYPE = 'collapseAxisBreak';
  45243. var AXIS_BREAK_TOGGLE_ACTION_TYPE = 'toggleAxisBreak';
  45244. var AXIS_BREAK_CHANGED_EVENT_TYPE = 'axisbreakchanged';
  45245. var expandAxisBreakActionInfo = {
  45246. type: AXIS_BREAK_EXPAND_ACTION_TYPE,
  45247. event: AXIS_BREAK_CHANGED_EVENT_TYPE,
  45248. update: 'update',
  45249. refineEvent: refineAxisBreakChangeEvent
  45250. };
  45251. var collapseAxisBreakActionInfo = {
  45252. type: AXIS_BREAK_COLLAPSE_ACTION_TYPE,
  45253. event: AXIS_BREAK_CHANGED_EVENT_TYPE,
  45254. update: 'update',
  45255. refineEvent: refineAxisBreakChangeEvent
  45256. };
  45257. var toggleAxisBreakActionInfo = {
  45258. type: AXIS_BREAK_TOGGLE_ACTION_TYPE,
  45259. event: AXIS_BREAK_CHANGED_EVENT_TYPE,
  45260. update: 'update',
  45261. refineEvent: refineAxisBreakChangeEvent
  45262. };
  45263. function refineAxisBreakChangeEvent(actionResultBatch, payload, ecModel, api) {
  45264. var breaks = [];
  45265. each(actionResultBatch, function (actionResult) {
  45266. breaks = breaks.concat(actionResult.eventBreaks);
  45267. });
  45268. return {
  45269. eventContent: {
  45270. breaks: breaks
  45271. }
  45272. };
  45273. }
  45274. function registerAction$1(registers) {
  45275. registers.registerAction(expandAxisBreakActionInfo, actionHandler);
  45276. registers.registerAction(collapseAxisBreakActionInfo, actionHandler);
  45277. registers.registerAction(toggleAxisBreakActionInfo, actionHandler);
  45278. function actionHandler(payload, ecModel) {
  45279. var eventBreaks = [];
  45280. var finderResult = parseFinder(ecModel, payload);
  45281. function dealUpdate(modelProp, indexProp) {
  45282. each(finderResult[modelProp], function (axisModel) {
  45283. var result = axisModel.updateAxisBreaks(payload);
  45284. each(result.breaks, function (item) {
  45285. var _a;
  45286. eventBreaks.push(defaults((_a = {}, _a[indexProp] = axisModel.componentIndex, _a), item));
  45287. });
  45288. });
  45289. }
  45290. dealUpdate('xAxisModels', 'xAxisIndex');
  45291. dealUpdate('yAxisModels', 'yAxisIndex');
  45292. dealUpdate('singleAxisModels', 'singleAxisIndex');
  45293. return {
  45294. eventBreaks: eventBreaks
  45295. };
  45296. }
  45297. }
  45298. var PI$5 = Math.PI;
  45299. var DEFAULT_CENTER_NAME_MARGIN_LEVELS = [[1, 2, 1, 2], [5, 3, 5, 3], [8, 3, 8, 3]];
  45300. var DEFAULT_ENDS_NAME_MARGIN_LEVELS = [[0, 1, 0, 1], [0, 3, 0, 3], [0, 3, 0, 3]];
  45301. var getLabelInner = makeInner();
  45302. var getTickInner = makeInner();
  45303. /**
  45304. * A context shared by difference axisBuilder instances.
  45305. * For cross-axes overlap resolving.
  45306. *
  45307. * Lifecycle constraint: should not over a pass of ec main process.
  45308. * If model is changed, the context must be disposed.
  45309. *
  45310. * @see AxisBuilderLocalContext
  45311. */
  45312. var AxisBuilderSharedContext = /** @class */function () {
  45313. function AxisBuilderSharedContext(resolveAxisNameOverlap) {
  45314. /**
  45315. * [CAUTION] Do not modify this data structure outside this class.
  45316. */
  45317. this.recordMap = {};
  45318. this.resolveAxisNameOverlap = resolveAxisNameOverlap;
  45319. }
  45320. AxisBuilderSharedContext.prototype.ensureRecord = function (axisModel) {
  45321. var dim = axisModel.axis.dim;
  45322. var idx = axisModel.componentIndex;
  45323. var recordMap = this.recordMap;
  45324. var records = recordMap[dim] || (recordMap[dim] = []);
  45325. return records[idx] || (records[idx] = {
  45326. ready: {}
  45327. });
  45328. };
  45329. return AxisBuilderSharedContext;
  45330. }();
  45331. /**
  45332. * [CAUTION]
  45333. * 1. The call of this function must be after axisLabel overlap handlings
  45334. * (such as `hideOverlap`, `fixMinMaxLabelShow`) and after transform calculating.
  45335. * 2. Can be called multiple times and should be idempotent.
  45336. */
  45337. function resetOverlapRecordToShared(cfg, shared, axisModel, labelLayoutList) {
  45338. var axis = axisModel.axis;
  45339. var record = shared.ensureRecord(axisModel);
  45340. var labelInfoList = [];
  45341. var stOccupiedRect;
  45342. var useStOccupiedRect = hasAxisName(cfg.axisName) && isNameLocationCenter(cfg.nameLocation);
  45343. each(labelLayoutList, function (layout) {
  45344. var layoutInfo = ensureLabelLayoutWithGeometry(layout);
  45345. if (!layoutInfo || layoutInfo.label.ignore) {
  45346. return;
  45347. }
  45348. labelInfoList.push(layoutInfo);
  45349. var transGroup = record.transGroup;
  45350. if (useStOccupiedRect) {
  45351. // Transform to "standard axis" for creating stOccupiedRect (the label rects union).
  45352. transGroup.transform ? invert(_stTransTmp, transGroup.transform) : identity(_stTransTmp);
  45353. if (layoutInfo.transform) {
  45354. mul$1(_stTransTmp, _stTransTmp, layoutInfo.transform);
  45355. }
  45356. BoundingRect.copy(_stLabelRectTmp, layoutInfo.localRect);
  45357. _stLabelRectTmp.applyTransform(_stTransTmp);
  45358. stOccupiedRect ? stOccupiedRect.union(_stLabelRectTmp) : BoundingRect.copy(stOccupiedRect = new BoundingRect(0, 0, 0, 0), _stLabelRectTmp);
  45359. }
  45360. });
  45361. var sortByDim = Math.abs(record.dirVec.x) > 0.1 ? 'x' : 'y';
  45362. var sortByValue = record.transGroup[sortByDim];
  45363. labelInfoList.sort(function (info1, info2) {
  45364. return Math.abs(info1.label[sortByDim] - sortByValue) - Math.abs(info2.label[sortByDim] - sortByValue);
  45365. });
  45366. if (useStOccupiedRect && stOccupiedRect) {
  45367. var extent = axis.getExtent();
  45368. var axisLineX = Math.min(extent[0], extent[1]);
  45369. var axisLineWidth = Math.max(extent[0], extent[1]) - axisLineX;
  45370. // If `nameLocation` is 'middle', enlarge axis labels boundingRect to axisLine to avoid bad
  45371. // case like that axis name is placed in the gap between axis labels and axis line.
  45372. // If only one label exists, the entire band should be occupied for
  45373. // visual consistency, so extent it to [0, canvas width].
  45374. stOccupiedRect.union(new BoundingRect(axisLineX, 0, axisLineWidth, 1));
  45375. }
  45376. record.stOccupiedRect = stOccupiedRect;
  45377. record.labelInfoList = labelInfoList;
  45378. }
  45379. var _stTransTmp = create$1();
  45380. var _stLabelRectTmp = new BoundingRect(0, 0, 0, 0);
  45381. /**
  45382. * The default resolver does not involve other axes within the same coordinate system.
  45383. */
  45384. var resolveAxisNameOverlapDefault = function (cfg, ctx, axisModel, nameLayoutInfo, nameMoveDirVec, thisRecord) {
  45385. if (isNameLocationCenter(cfg.nameLocation)) {
  45386. var stOccupiedRect = thisRecord.stOccupiedRect;
  45387. if (stOccupiedRect) {
  45388. moveIfOverlap(computeLabelGeometry2({}, stOccupiedRect, thisRecord.transGroup.transform), nameLayoutInfo, nameMoveDirVec);
  45389. }
  45390. } else {
  45391. moveIfOverlapByLinearLabels(thisRecord.labelInfoList, thisRecord.dirVec, nameLayoutInfo, nameMoveDirVec);
  45392. }
  45393. };
  45394. // [NOTICE] not consider ignore.
  45395. function moveIfOverlap(basedLayoutInfo, movableLayoutInfo, moveDirVec) {
  45396. var mtv = new Point();
  45397. if (labelIntersect(basedLayoutInfo, movableLayoutInfo, mtv, {
  45398. direction: Math.atan2(moveDirVec.y, moveDirVec.x),
  45399. bidirectional: false,
  45400. touchThreshold: 0.05
  45401. })) {
  45402. labelLayoutApplyTranslation(movableLayoutInfo, mtv);
  45403. }
  45404. }
  45405. function moveIfOverlapByLinearLabels(baseLayoutInfoList, baseDirVec, movableLayoutInfo, moveDirVec) {
  45406. // Detect and move from far to close.
  45407. var sameDir = Point.dot(moveDirVec, baseDirVec) >= 0;
  45408. for (var idx = 0, len = baseLayoutInfoList.length; idx < len; idx++) {
  45409. var labelInfo = baseLayoutInfoList[sameDir ? idx : len - 1 - idx];
  45410. if (!labelInfo.label.ignore) {
  45411. moveIfOverlap(labelInfo, movableLayoutInfo, moveDirVec);
  45412. }
  45413. }
  45414. }
  45415. /**
  45416. * @caution
  45417. * - Ensure it is called after the data processing stage finished.
  45418. * - It might be called before `CahrtView#render`, sush as called at `CoordinateSystem#update`,
  45419. * thus ensure the result the same whenever it is called.
  45420. *
  45421. * A builder for a straight-line axis.
  45422. *
  45423. * A final axis is translated and rotated from a "standard axis".
  45424. * So opt.position and opt.rotation is required.
  45425. *
  45426. * A "standard axis" is the axis [0,0]-->[abs(axisExtent[1]-axisExtent[0]),0]
  45427. * for example: [0,0]-->[50,0]
  45428. */
  45429. var AxisBuilder = /** @class */function () {
  45430. /**
  45431. * [CAUTION]: axisModel.axis.extent/scale must be ready to use.
  45432. */
  45433. function AxisBuilder(axisModel, api, opt, shared) {
  45434. this.group = new Group();
  45435. this._axisModel = axisModel;
  45436. this._api = api;
  45437. this._local = {};
  45438. this._shared = shared || new AxisBuilderSharedContext(resolveAxisNameOverlapDefault);
  45439. this._resetCfgDetermined(opt);
  45440. }
  45441. /**
  45442. * Regarding axis label related configurations, only the change of label.x/y is supported; other
  45443. * changes are not necessary and not performant. To be specific, only `axis.position`
  45444. * (and consequently `labelOffset`) and `axis.extent` can be changed, and assume everything in
  45445. * `axisModel` are not changed.
  45446. * Axis line related configurations can be changed since this method can only be called
  45447. * before they are created.
  45448. */
  45449. AxisBuilder.prototype.updateCfg = function (opt) {
  45450. if ("development" !== 'production') {
  45451. var ready = this._shared.ensureRecord(this._axisModel).ready;
  45452. // After that, changing cfg is not supported; avoid unnecessary complexity.
  45453. assert(!ready.axisLine && !ready.axisTickLabelDetermine);
  45454. // Have to be called again if cfg changed.
  45455. ready.axisName = ready.axisTickLabelEstimate = false;
  45456. }
  45457. var raw = this._cfg.raw;
  45458. raw.position = opt.position;
  45459. raw.labelOffset = opt.labelOffset;
  45460. this._resetCfgDetermined(raw);
  45461. };
  45462. /**
  45463. * [CAUTION] For debug usage. Never change it outside!
  45464. */
  45465. AxisBuilder.prototype.__getRawCfg = function () {
  45466. return this._cfg.raw;
  45467. };
  45468. AxisBuilder.prototype._resetCfgDetermined = function (raw) {
  45469. var axisModel = this._axisModel;
  45470. // FIXME:
  45471. // Currently there is no uniformed way to set default values if an option
  45472. // is specified null/undefined by user (intentionally or unintentionally),
  45473. // e.g. null/undefined is not a illegal value for `nameLocation`.
  45474. // Try to use `getDefaultOption` to address it. But radar has no `getDefaultOption`.
  45475. var axisModelDefaultOption = axisModel.getDefaultOption ? axisModel.getDefaultOption() : {};
  45476. // Default value
  45477. var axisName = retrieve2(raw.axisName, axisModel.get('name'));
  45478. var nameMoveOverlapOption = axisModel.get('nameMoveOverlap');
  45479. if (nameMoveOverlapOption == null || nameMoveOverlapOption === 'auto') {
  45480. nameMoveOverlapOption = retrieve2(raw.defaultNameMoveOverlap, true);
  45481. }
  45482. var cfg = {
  45483. raw: raw,
  45484. position: raw.position,
  45485. rotation: raw.rotation,
  45486. nameDirection: retrieve2(raw.nameDirection, 1),
  45487. tickDirection: retrieve2(raw.tickDirection, 1),
  45488. labelDirection: retrieve2(raw.labelDirection, 1),
  45489. labelOffset: retrieve2(raw.labelOffset, 0),
  45490. silent: retrieve2(raw.silent, true),
  45491. axisName: axisName,
  45492. nameLocation: retrieve3(axisModel.get('nameLocation'), axisModelDefaultOption.nameLocation, 'end'),
  45493. shouldNameMoveOverlap: hasAxisName(axisName) && nameMoveOverlapOption,
  45494. optionHideOverlap: axisModel.get(['axisLabel', 'hideOverlap']),
  45495. showMinorTicks: axisModel.get(['minorTick', 'show'])
  45496. };
  45497. if ("development" !== 'production') {
  45498. assert(cfg.position != null);
  45499. assert(cfg.rotation != null);
  45500. }
  45501. this._cfg = cfg;
  45502. // FIXME Not use a separate text group?
  45503. var transformGroup = new Group({
  45504. x: cfg.position[0],
  45505. y: cfg.position[1],
  45506. rotation: cfg.rotation
  45507. });
  45508. transformGroup.updateTransform();
  45509. this._transformGroup = transformGroup;
  45510. var record = this._shared.ensureRecord(axisModel);
  45511. record.transGroup = this._transformGroup;
  45512. record.dirVec = new Point(Math.cos(-cfg.rotation), Math.sin(-cfg.rotation));
  45513. };
  45514. AxisBuilder.prototype.build = function (axisPartNameMap, extraParams) {
  45515. var _this = this;
  45516. if (!axisPartNameMap) {
  45517. axisPartNameMap = {
  45518. axisLine: true,
  45519. axisTickLabelEstimate: false,
  45520. axisTickLabelDetermine: true,
  45521. axisName: true
  45522. };
  45523. }
  45524. each(AXIS_BUILDER_AXIS_PART_NAMES, function (partName) {
  45525. if (axisPartNameMap[partName]) {
  45526. builders[partName](_this._cfg, _this._local, _this._shared, _this._axisModel, _this.group, _this._transformGroup, _this._api, extraParams || {});
  45527. }
  45528. });
  45529. return this;
  45530. };
  45531. /**
  45532. * Currently only get text align/verticalAlign by rotation.
  45533. * NO `position` is involved, otherwise it have to be performed for each `updateAxisLabelChangableProps`.
  45534. */
  45535. AxisBuilder.innerTextLayout = function (axisRotation, textRotation, direction) {
  45536. var rotationDiff = remRadian(textRotation - axisRotation);
  45537. var textAlign;
  45538. var textVerticalAlign;
  45539. if (isRadianAroundZero(rotationDiff)) {
  45540. // Label is parallel with axis line.
  45541. textVerticalAlign = direction > 0 ? 'top' : 'bottom';
  45542. textAlign = 'center';
  45543. } else if (isRadianAroundZero(rotationDiff - PI$5)) {
  45544. // Label is inverse parallel with axis line.
  45545. textVerticalAlign = direction > 0 ? 'bottom' : 'top';
  45546. textAlign = 'center';
  45547. } else {
  45548. textVerticalAlign = 'middle';
  45549. if (rotationDiff > 0 && rotationDiff < PI$5) {
  45550. textAlign = direction > 0 ? 'right' : 'left';
  45551. } else {
  45552. textAlign = direction > 0 ? 'left' : 'right';
  45553. }
  45554. }
  45555. return {
  45556. rotation: rotationDiff,
  45557. textAlign: textAlign,
  45558. textVerticalAlign: textVerticalAlign
  45559. };
  45560. };
  45561. AxisBuilder.makeAxisEventDataBase = function (axisModel) {
  45562. var eventData = {
  45563. componentType: axisModel.mainType,
  45564. componentIndex: axisModel.componentIndex
  45565. };
  45566. eventData[axisModel.mainType + 'Index'] = axisModel.componentIndex;
  45567. return eventData;
  45568. };
  45569. AxisBuilder.isLabelSilent = function (axisModel) {
  45570. var tooltipOpt = axisModel.get('tooltip');
  45571. return axisModel.get('silent')
  45572. // Consider mouse cursor, add these restrictions.
  45573. || !(axisModel.get('triggerEvent') || tooltipOpt && tooltipOpt.show);
  45574. };
  45575. return AxisBuilder;
  45576. }();
  45577. // Sorted by dependency order.
  45578. var AXIS_BUILDER_AXIS_PART_NAMES = ['axisLine', 'axisTickLabelEstimate', 'axisTickLabelDetermine', 'axisName'];
  45579. var builders = {
  45580. axisLine: function (cfg, local, shared, axisModel, group, transformGroup, api) {
  45581. if ("development" !== 'production') {
  45582. var ready = shared.ensureRecord(axisModel).ready;
  45583. assert(!ready.axisLine);
  45584. ready.axisLine = true;
  45585. }
  45586. var shown = axisModel.get(['axisLine', 'show']);
  45587. if (shown === 'auto') {
  45588. shown = true;
  45589. if (cfg.raw.axisLineAutoShow != null) {
  45590. shown = !!cfg.raw.axisLineAutoShow;
  45591. }
  45592. }
  45593. if (!shown) {
  45594. return;
  45595. }
  45596. var extent = axisModel.axis.getExtent();
  45597. var matrix = transformGroup.transform;
  45598. var pt1 = [extent[0], 0];
  45599. var pt2 = [extent[1], 0];
  45600. var inverse = pt1[0] > pt2[0];
  45601. if (matrix) {
  45602. applyTransform(pt1, pt1, matrix);
  45603. applyTransform(pt2, pt2, matrix);
  45604. }
  45605. var lineStyle = extend({
  45606. lineCap: 'round'
  45607. }, axisModel.getModel(['axisLine', 'lineStyle']).getLineStyle());
  45608. var pathBaseProp = {
  45609. strokeContainThreshold: cfg.raw.strokeContainThreshold || 5,
  45610. silent: true,
  45611. z2: 1,
  45612. style: lineStyle
  45613. };
  45614. if (axisModel.get(['axisLine', 'breakLine']) && axisModel.axis.scale.hasBreaks()) {
  45615. getAxisBreakHelper().buildAxisBreakLine(axisModel, group, transformGroup, pathBaseProp);
  45616. } else {
  45617. var line = new Line(extend({
  45618. shape: {
  45619. x1: pt1[0],
  45620. y1: pt1[1],
  45621. x2: pt2[0],
  45622. y2: pt2[1]
  45623. }
  45624. }, pathBaseProp));
  45625. subPixelOptimizeLine$1(line.shape, line.style.lineWidth);
  45626. line.anid = 'line';
  45627. group.add(line);
  45628. }
  45629. var arrows = axisModel.get(['axisLine', 'symbol']);
  45630. if (arrows != null) {
  45631. var arrowSize = axisModel.get(['axisLine', 'symbolSize']);
  45632. if (isString(arrows)) {
  45633. // Use the same arrow for start and end point
  45634. arrows = [arrows, arrows];
  45635. }
  45636. if (isString(arrowSize) || isNumber(arrowSize)) {
  45637. // Use the same size for width and height
  45638. arrowSize = [arrowSize, arrowSize];
  45639. }
  45640. var arrowOffset = normalizeSymbolOffset(axisModel.get(['axisLine', 'symbolOffset']) || 0, arrowSize);
  45641. var symbolWidth_1 = arrowSize[0];
  45642. var symbolHeight_1 = arrowSize[1];
  45643. each([{
  45644. rotate: cfg.rotation + Math.PI / 2,
  45645. offset: arrowOffset[0],
  45646. r: 0
  45647. }, {
  45648. rotate: cfg.rotation - Math.PI / 2,
  45649. offset: arrowOffset[1],
  45650. r: Math.sqrt((pt1[0] - pt2[0]) * (pt1[0] - pt2[0]) + (pt1[1] - pt2[1]) * (pt1[1] - pt2[1]))
  45651. }], function (point, index) {
  45652. if (arrows[index] !== 'none' && arrows[index] != null) {
  45653. var symbol = createSymbol(arrows[index], -symbolWidth_1 / 2, -symbolHeight_1 / 2, symbolWidth_1, symbolHeight_1, lineStyle.stroke, true);
  45654. // Calculate arrow position with offset
  45655. var r = point.r + point.offset;
  45656. var pt = inverse ? pt2 : pt1;
  45657. symbol.attr({
  45658. rotation: point.rotate,
  45659. x: pt[0] + r * Math.cos(cfg.rotation),
  45660. y: pt[1] - r * Math.sin(cfg.rotation),
  45661. silent: true,
  45662. z2: 11
  45663. });
  45664. group.add(symbol);
  45665. }
  45666. });
  45667. }
  45668. },
  45669. /**
  45670. * [CAUTION] This method can be called multiple times, following the change due to `resetCfg` called
  45671. * in size measurement. Thus this method should be idempotent, and should be performant.
  45672. */
  45673. axisTickLabelEstimate: function (cfg, local, shared, axisModel, group, transformGroup, api, extraParams) {
  45674. if ("development" !== 'production') {
  45675. var ready = shared.ensureRecord(axisModel).ready;
  45676. assert(!ready.axisTickLabelDetermine);
  45677. ready.axisTickLabelEstimate = true;
  45678. }
  45679. var needCallLayout = dealLastTickLabelResultReusable(local, group, extraParams);
  45680. if (needCallLayout) {
  45681. layOutAxisTickLabel(cfg, local, shared, axisModel, group, transformGroup, api, AxisTickLabelComputingKind.estimate);
  45682. }
  45683. },
  45684. /**
  45685. * Finish axis tick label build.
  45686. * Can be only called once.
  45687. */
  45688. axisTickLabelDetermine: function (cfg, local, shared, axisModel, group, transformGroup, api, extraParams) {
  45689. if ("development" !== 'production') {
  45690. var ready = shared.ensureRecord(axisModel).ready;
  45691. ready.axisTickLabelDetermine = true;
  45692. }
  45693. var needCallLayout = dealLastTickLabelResultReusable(local, group, extraParams);
  45694. if (needCallLayout) {
  45695. layOutAxisTickLabel(cfg, local, shared, axisModel, group, transformGroup, api, AxisTickLabelComputingKind.determine);
  45696. }
  45697. var ticksEls = buildAxisMajorTicks(cfg, group, transformGroup, axisModel);
  45698. syncLabelIgnoreToMajorTicks(cfg, local.labelLayoutList, ticksEls);
  45699. buildAxisMinorTicks(cfg, group, transformGroup, axisModel, cfg.tickDirection);
  45700. },
  45701. /**
  45702. * [CAUTION] This method can be called multiple times, following the change due to `resetCfg` called
  45703. * in size measurement. Thus this method should be idempotent, and should be performant.
  45704. */
  45705. axisName: function (cfg, local, shared, axisModel, group, transformGroup, api, extraParams) {
  45706. var sharedRecord = shared.ensureRecord(axisModel);
  45707. if ("development" !== 'production') {
  45708. var ready = sharedRecord.ready;
  45709. assert(ready.axisTickLabelEstimate || ready.axisTickLabelDetermine);
  45710. ready.axisName = true;
  45711. }
  45712. // Remove the existing name result created in estimation phase.
  45713. if (local.nameEl) {
  45714. group.remove(local.nameEl);
  45715. local.nameEl = sharedRecord.nameLayout = sharedRecord.nameLocation = null;
  45716. }
  45717. var name = cfg.axisName;
  45718. if (!hasAxisName(name)) {
  45719. return;
  45720. }
  45721. var nameLocation = cfg.nameLocation;
  45722. var nameDirection = cfg.nameDirection;
  45723. var textStyleModel = axisModel.getModel('nameTextStyle');
  45724. var gap = axisModel.get('nameGap') || 0;
  45725. var extent = axisModel.axis.getExtent();
  45726. var gapStartEndSignal = axisModel.axis.inverse ? -1 : 1;
  45727. var pos = new Point(0, 0);
  45728. var nameMoveDirVec = new Point(0, 0);
  45729. if (nameLocation === 'start') {
  45730. pos.x = extent[0] - gapStartEndSignal * gap;
  45731. nameMoveDirVec.x = -gapStartEndSignal;
  45732. } else if (nameLocation === 'end') {
  45733. pos.x = extent[1] + gapStartEndSignal * gap;
  45734. nameMoveDirVec.x = gapStartEndSignal;
  45735. } else {
  45736. // 'middle' or 'center'
  45737. pos.x = (extent[0] + extent[1]) / 2;
  45738. pos.y = cfg.labelOffset + nameDirection * gap;
  45739. nameMoveDirVec.y = nameDirection;
  45740. }
  45741. var mt = create$1();
  45742. nameMoveDirVec.transform(rotate(mt, mt, cfg.rotation));
  45743. var nameRotation = axisModel.get('nameRotate');
  45744. if (nameRotation != null) {
  45745. nameRotation = nameRotation * PI$5 / 180; // To radian.
  45746. }
  45747. var labelLayout;
  45748. var axisNameAvailableWidth;
  45749. if (isNameLocationCenter(nameLocation)) {
  45750. labelLayout = AxisBuilder.innerTextLayout(cfg.rotation, nameRotation != null ? nameRotation : cfg.rotation,
  45751. // Adapt to axis.
  45752. nameDirection);
  45753. } else {
  45754. labelLayout = endTextLayout(cfg.rotation, nameLocation, nameRotation || 0, extent);
  45755. axisNameAvailableWidth = cfg.raw.axisNameAvailableWidth;
  45756. if (axisNameAvailableWidth != null) {
  45757. axisNameAvailableWidth = Math.abs(axisNameAvailableWidth / Math.sin(labelLayout.rotation));
  45758. !isFinite(axisNameAvailableWidth) && (axisNameAvailableWidth = null);
  45759. }
  45760. }
  45761. var textFont = textStyleModel.getFont();
  45762. var truncateOpt = axisModel.get('nameTruncate', true) || {};
  45763. var ellipsis = truncateOpt.ellipsis;
  45764. var maxWidth = retrieve(cfg.raw.nameTruncateMaxWidth, truncateOpt.maxWidth, axisNameAvailableWidth);
  45765. var nameMarginLevel = extraParams.nameMarginLevel || 0;
  45766. var textEl = new ZRText({
  45767. x: pos.x,
  45768. y: pos.y,
  45769. rotation: labelLayout.rotation,
  45770. silent: AxisBuilder.isLabelSilent(axisModel),
  45771. style: createTextStyle(textStyleModel, {
  45772. text: name,
  45773. font: textFont,
  45774. overflow: 'truncate',
  45775. width: maxWidth,
  45776. ellipsis: ellipsis,
  45777. fill: textStyleModel.getTextColor() || axisModel.get(['axisLine', 'lineStyle', 'color']),
  45778. align: textStyleModel.get('align') || labelLayout.textAlign,
  45779. verticalAlign: textStyleModel.get('verticalAlign') || labelLayout.textVerticalAlign
  45780. }),
  45781. z2: 1
  45782. });
  45783. setTooltipConfig({
  45784. el: textEl,
  45785. componentModel: axisModel,
  45786. itemName: name
  45787. });
  45788. textEl.__fullText = name;
  45789. // Id for animation
  45790. textEl.anid = 'name';
  45791. if (axisModel.get('triggerEvent')) {
  45792. var eventData = AxisBuilder.makeAxisEventDataBase(axisModel);
  45793. eventData.targetType = 'axisName';
  45794. eventData.name = name;
  45795. getECData(textEl).eventData = eventData;
  45796. }
  45797. transformGroup.add(textEl);
  45798. textEl.updateTransform();
  45799. local.nameEl = textEl;
  45800. var nameLayout = sharedRecord.nameLayout = ensureLabelLayoutWithGeometry({
  45801. label: textEl,
  45802. priority: textEl.z2,
  45803. defaultAttr: {
  45804. ignore: textEl.ignore
  45805. },
  45806. marginDefault: isNameLocationCenter(nameLocation)
  45807. // Make axis name visually far from axis labels.
  45808. // (but not too aggressive, consider multiple small charts)
  45809. ? DEFAULT_CENTER_NAME_MARGIN_LEVELS[nameMarginLevel]
  45810. // top/button margin is set to `0` to inserted the xAxis name into the indention
  45811. // above the axis labels to save space. (see example below.)
  45812. : DEFAULT_ENDS_NAME_MARGIN_LEVELS[nameMarginLevel]
  45813. });
  45814. sharedRecord.nameLocation = nameLocation;
  45815. group.add(textEl);
  45816. textEl.decomposeTransform();
  45817. if (cfg.shouldNameMoveOverlap && nameLayout) {
  45818. var record = shared.ensureRecord(axisModel);
  45819. if ("development" !== 'production') {
  45820. assert(record.labelInfoList);
  45821. }
  45822. shared.resolveAxisNameOverlap(cfg, shared, axisModel, nameLayout, nameMoveDirVec, record);
  45823. }
  45824. }
  45825. };
  45826. function layOutAxisTickLabel(cfg, local, shared, axisModel, group, transformGroup, api, kind) {
  45827. if (!axisLabelBuildResultExists(local)) {
  45828. buildAxisLabel(cfg, local, group, kind, axisModel, api);
  45829. }
  45830. var labelLayoutList = local.labelLayoutList;
  45831. updateAxisLabelChangableProps(cfg, axisModel, labelLayoutList, transformGroup);
  45832. adjustBreakLabels(axisModel, cfg.rotation, labelLayoutList);
  45833. var optionHideOverlap = cfg.optionHideOverlap;
  45834. fixMinMaxLabelShow(axisModel, labelLayoutList, optionHideOverlap);
  45835. if (optionHideOverlap) {
  45836. // This bit fixes the label overlap issue for the time chart.
  45837. // See https://github.com/apache/echarts/issues/14266 for more.
  45838. hideOverlap(
  45839. // Filter the already ignored labels by the previous overlap resolving methods.
  45840. filter(labelLayoutList, function (layout) {
  45841. return layout && !layout.label.ignore;
  45842. }));
  45843. }
  45844. // Always call it even this axis has no name, since it serves in overlapping detection
  45845. // and grid outerBounds on other axis.
  45846. resetOverlapRecordToShared(cfg, shared, axisModel, labelLayoutList);
  45847. }
  45848. function endTextLayout(rotation, textPosition, textRotate, extent) {
  45849. var rotationDiff = remRadian(textRotate - rotation);
  45850. var textAlign;
  45851. var textVerticalAlign;
  45852. var inverse = extent[0] > extent[1];
  45853. var onLeft = textPosition === 'start' && !inverse || textPosition !== 'start' && inverse;
  45854. if (isRadianAroundZero(rotationDiff - PI$5 / 2)) {
  45855. textVerticalAlign = onLeft ? 'bottom' : 'top';
  45856. textAlign = 'center';
  45857. } else if (isRadianAroundZero(rotationDiff - PI$5 * 1.5)) {
  45858. textVerticalAlign = onLeft ? 'top' : 'bottom';
  45859. textAlign = 'center';
  45860. } else {
  45861. textVerticalAlign = 'middle';
  45862. if (rotationDiff < PI$5 * 1.5 && rotationDiff > PI$5 / 2) {
  45863. textAlign = onLeft ? 'left' : 'right';
  45864. } else {
  45865. textAlign = onLeft ? 'right' : 'left';
  45866. }
  45867. }
  45868. return {
  45869. rotation: rotationDiff,
  45870. textAlign: textAlign,
  45871. textVerticalAlign: textVerticalAlign
  45872. };
  45873. }
  45874. /**
  45875. * Assume `labelLayoutList` has no `label.ignore: true`.
  45876. * Assume `labelLayoutList` have been sorted by value ascending order.
  45877. */
  45878. function fixMinMaxLabelShow(axisModel, labelLayoutList, optionHideOverlap) {
  45879. if (shouldShowAllLabels(axisModel.axis)) {
  45880. return;
  45881. }
  45882. // FIXME
  45883. // Have not consider onBand yet, where tick els is more than label els.
  45884. // Assert no ignore in labels.
  45885. function deal(showMinMaxLabel, outmostLabelIdx, innerLabelIdx) {
  45886. var outmostLabelLayout = ensureLabelLayoutWithGeometry(labelLayoutList[outmostLabelIdx]);
  45887. var innerLabelLayout = ensureLabelLayoutWithGeometry(labelLayoutList[innerLabelIdx]);
  45888. if (!outmostLabelLayout || !innerLabelLayout) {
  45889. return;
  45890. }
  45891. if (showMinMaxLabel === false || outmostLabelLayout.suggestIgnore) {
  45892. ignoreEl(outmostLabelLayout.label);
  45893. return;
  45894. }
  45895. if (innerLabelLayout.suggestIgnore) {
  45896. ignoreEl(innerLabelLayout.label);
  45897. return;
  45898. }
  45899. // PENDING: Originally we thought `optionHideOverlap === false` means do not hide anything,
  45900. // since currently the bounding rect of text might not accurate enough and might slightly bigger,
  45901. // which causes false positive. But `optionHideOverlap: null/undfined` is falsy and likely
  45902. // be treated as false.
  45903. // In most fonts the glyph does not reach the boundary of the bounding rect.
  45904. // This is needed to avoid too aggressive to hide two elements that meet at the edge
  45905. // due to compact layout by the same bounding rect or OBB.
  45906. var touchThreshold = 0.1;
  45907. // This treatment is for backward compatibility. And `!optionHideOverlap` implies that
  45908. // the user accepts the visual touch between adjacent labels, thus "hide min/max label"
  45909. // should be conservative, since the space might be sufficient in this case.
  45910. if (!optionHideOverlap) {
  45911. var marginForce = [0, 0, 0, 0];
  45912. // Make a copy to apply `ignoreMargin`.
  45913. outmostLabelLayout = newLabelLayoutWithGeometry({
  45914. marginForce: marginForce
  45915. }, outmostLabelLayout);
  45916. innerLabelLayout = newLabelLayoutWithGeometry({
  45917. marginForce: marginForce
  45918. }, innerLabelLayout);
  45919. }
  45920. if (labelIntersect(outmostLabelLayout, innerLabelLayout, null, {
  45921. touchThreshold: touchThreshold
  45922. })) {
  45923. if (showMinMaxLabel) {
  45924. ignoreEl(innerLabelLayout.label);
  45925. } else {
  45926. ignoreEl(outmostLabelLayout.label);
  45927. }
  45928. }
  45929. }
  45930. // If min or max are user set, we need to check
  45931. // If the tick on min(max) are overlap on their neighbour tick
  45932. // If they are overlapped, we need to hide the min(max) tick label
  45933. var showMinLabel = axisModel.get(['axisLabel', 'showMinLabel']);
  45934. var showMaxLabel = axisModel.get(['axisLabel', 'showMaxLabel']);
  45935. var labelsLen = labelLayoutList.length;
  45936. deal(showMinLabel, 0, 1);
  45937. deal(showMaxLabel, labelsLen - 1, labelsLen - 2);
  45938. }
  45939. // PENDING: Is it necessary to display a tick while the corresponding label is ignored?
  45940. function syncLabelIgnoreToMajorTicks(cfg, labelLayoutList, tickEls) {
  45941. if (cfg.showMinorTicks) {
  45942. // It probably unreaasonable to hide major ticks when show minor ticks.
  45943. return;
  45944. }
  45945. each(labelLayoutList, function (labelLayout) {
  45946. if (labelLayout && labelLayout.label.ignore) {
  45947. for (var idx = 0; idx < tickEls.length; idx++) {
  45948. var tickEl = tickEls[idx];
  45949. // Assume small array, linear search is fine for performance.
  45950. // PENDING: measure?
  45951. var tickInner = getTickInner(tickEl);
  45952. var labelInner = getLabelInner(labelLayout.label);
  45953. if (tickInner.tickValue != null && !tickInner.onBand && tickInner.tickValue === labelInner.tickValue) {
  45954. ignoreEl(tickEl);
  45955. return;
  45956. }
  45957. }
  45958. }
  45959. });
  45960. }
  45961. function ignoreEl(el) {
  45962. el && (el.ignore = true);
  45963. }
  45964. function createTicks(ticksCoords, tickTransform, tickEndCoord, tickLineStyle, anidPrefix) {
  45965. var tickEls = [];
  45966. var pt1 = [];
  45967. var pt2 = [];
  45968. for (var i = 0; i < ticksCoords.length; i++) {
  45969. var tickCoord = ticksCoords[i].coord;
  45970. pt1[0] = tickCoord;
  45971. pt1[1] = 0;
  45972. pt2[0] = tickCoord;
  45973. pt2[1] = tickEndCoord;
  45974. if (tickTransform) {
  45975. applyTransform(pt1, pt1, tickTransform);
  45976. applyTransform(pt2, pt2, tickTransform);
  45977. }
  45978. // Tick line, Not use group transform to have better line draw
  45979. var tickEl = new Line({
  45980. shape: {
  45981. x1: pt1[0],
  45982. y1: pt1[1],
  45983. x2: pt2[0],
  45984. y2: pt2[1]
  45985. },
  45986. style: tickLineStyle,
  45987. z2: 2,
  45988. autoBatch: true,
  45989. silent: true
  45990. });
  45991. subPixelOptimizeLine$1(tickEl.shape, tickEl.style.lineWidth);
  45992. tickEl.anid = anidPrefix + '_' + ticksCoords[i].tickValue;
  45993. tickEls.push(tickEl);
  45994. var inner = getTickInner(tickEl);
  45995. inner.onBand = !!ticksCoords[i].onBand;
  45996. inner.tickValue = ticksCoords[i].tickValue;
  45997. }
  45998. return tickEls;
  45999. }
  46000. function buildAxisMajorTicks(cfg, group, transformGroup, axisModel) {
  46001. var axis = axisModel.axis;
  46002. var tickModel = axisModel.getModel('axisTick');
  46003. var shown = tickModel.get('show');
  46004. if (shown === 'auto') {
  46005. shown = true;
  46006. if (cfg.raw.axisTickAutoShow != null) {
  46007. shown = !!cfg.raw.axisTickAutoShow;
  46008. }
  46009. }
  46010. if (!shown || axis.scale.isBlank()) {
  46011. return [];
  46012. }
  46013. var lineStyleModel = tickModel.getModel('lineStyle');
  46014. var tickEndCoord = cfg.tickDirection * tickModel.get('length');
  46015. var ticksCoords = axis.getTicksCoords();
  46016. var ticksEls = createTicks(ticksCoords, transformGroup.transform, tickEndCoord, defaults(lineStyleModel.getLineStyle(), {
  46017. stroke: axisModel.get(['axisLine', 'lineStyle', 'color'])
  46018. }), 'ticks');
  46019. for (var i = 0; i < ticksEls.length; i++) {
  46020. group.add(ticksEls[i]);
  46021. }
  46022. return ticksEls;
  46023. }
  46024. function buildAxisMinorTicks(cfg, group, transformGroup, axisModel, tickDirection) {
  46025. var axis = axisModel.axis;
  46026. var minorTickModel = axisModel.getModel('minorTick');
  46027. if (!cfg.showMinorTicks || axis.scale.isBlank()) {
  46028. return;
  46029. }
  46030. var minorTicksCoords = axis.getMinorTicksCoords();
  46031. if (!minorTicksCoords.length) {
  46032. return;
  46033. }
  46034. var lineStyleModel = minorTickModel.getModel('lineStyle');
  46035. var tickEndCoord = tickDirection * minorTickModel.get('length');
  46036. var minorTickLineStyle = defaults(lineStyleModel.getLineStyle(), defaults(axisModel.getModel('axisTick').getLineStyle(), {
  46037. stroke: axisModel.get(['axisLine', 'lineStyle', 'color'])
  46038. }));
  46039. for (var i = 0; i < minorTicksCoords.length; i++) {
  46040. var minorTicksEls = createTicks(minorTicksCoords[i], transformGroup.transform, tickEndCoord, minorTickLineStyle, 'minorticks_' + i);
  46041. for (var k = 0; k < minorTicksEls.length; k++) {
  46042. group.add(minorTicksEls[k]);
  46043. }
  46044. }
  46045. }
  46046. // Return whether need to call `layOutAxisTickLabel` again.
  46047. function dealLastTickLabelResultReusable(local, group, extraParams) {
  46048. if (axisLabelBuildResultExists(local)) {
  46049. var axisLabelsCreationContext = local.axisLabelsCreationContext;
  46050. if ("development" !== 'production') {
  46051. assert(local.labelGroup && axisLabelsCreationContext);
  46052. }
  46053. var noPxChangeTryDetermine = axisLabelsCreationContext.out.noPxChangeTryDetermine;
  46054. if (extraParams.noPxChange) {
  46055. var canDetermine = true;
  46056. for (var idx = 0; idx < noPxChangeTryDetermine.length; idx++) {
  46057. canDetermine = canDetermine && noPxChangeTryDetermine[idx]();
  46058. }
  46059. if (canDetermine) {
  46060. return false;
  46061. }
  46062. }
  46063. if (noPxChangeTryDetermine.length) {
  46064. // Remove the result of `buildAxisLabel`
  46065. group.remove(local.labelGroup);
  46066. axisLabelBuildResultSet(local, null, null, null);
  46067. }
  46068. }
  46069. return true;
  46070. }
  46071. function buildAxisLabel(cfg, local, group, kind, axisModel, api) {
  46072. var axis = axisModel.axis;
  46073. var show = retrieve(cfg.raw.axisLabelShow, axisModel.get(['axisLabel', 'show']));
  46074. var labelGroup = new Group();
  46075. group.add(labelGroup);
  46076. var axisLabelCreationCtx = createAxisLabelsComputingContext(kind);
  46077. if (!show || axis.scale.isBlank()) {
  46078. axisLabelBuildResultSet(local, [], labelGroup, axisLabelCreationCtx);
  46079. return;
  46080. }
  46081. var labelModel = axisModel.getModel('axisLabel');
  46082. var labels = axis.getViewLabels(axisLabelCreationCtx);
  46083. // Special label rotate.
  46084. var labelRotation = (retrieve(cfg.raw.labelRotate, labelModel.get('rotate')) || 0) * PI$5 / 180;
  46085. var labelLayout = AxisBuilder.innerTextLayout(cfg.rotation, labelRotation, cfg.labelDirection);
  46086. var rawCategoryData = axisModel.getCategories && axisModel.getCategories(true);
  46087. var labelEls = [];
  46088. var triggerEvent = axisModel.get('triggerEvent');
  46089. var z2Min = Infinity;
  46090. var z2Max = -Infinity;
  46091. each(labels, function (labelItem, index) {
  46092. var _a;
  46093. var tickValue = axis.scale.type === 'ordinal' ? axis.scale.getRawOrdinalNumber(labelItem.tickValue) : labelItem.tickValue;
  46094. var formattedLabel = labelItem.formattedLabel;
  46095. var rawLabel = labelItem.rawLabel;
  46096. var itemLabelModel = labelModel;
  46097. if (rawCategoryData && rawCategoryData[tickValue]) {
  46098. var rawCategoryItem = rawCategoryData[tickValue];
  46099. if (isObject(rawCategoryItem) && rawCategoryItem.textStyle) {
  46100. itemLabelModel = new Model(rawCategoryItem.textStyle, labelModel, axisModel.ecModel);
  46101. }
  46102. }
  46103. var textColor = itemLabelModel.getTextColor() || axisModel.get(['axisLine', 'lineStyle', 'color']);
  46104. var align = itemLabelModel.getShallow('align', true) || labelLayout.textAlign;
  46105. var alignMin = retrieve2(itemLabelModel.getShallow('alignMinLabel', true), align);
  46106. var alignMax = retrieve2(itemLabelModel.getShallow('alignMaxLabel', true), align);
  46107. var verticalAlign = itemLabelModel.getShallow('verticalAlign', true) || itemLabelModel.getShallow('baseline', true) || labelLayout.textVerticalAlign;
  46108. var verticalAlignMin = retrieve2(itemLabelModel.getShallow('verticalAlignMinLabel', true), verticalAlign);
  46109. var verticalAlignMax = retrieve2(itemLabelModel.getShallow('verticalAlignMaxLabel', true), verticalAlign);
  46110. var z2 = 10 + (((_a = labelItem.time) === null || _a === void 0 ? void 0 : _a.level) || 0);
  46111. z2Min = Math.min(z2Min, z2);
  46112. z2Max = Math.max(z2Max, z2);
  46113. var textEl = new ZRText({
  46114. // --- transform props start ---
  46115. // All of the transform props MUST not be set here, but should be set in
  46116. // `updateAxisLabelChangableProps`, because they may change in estimation,
  46117. // and need to calculate based on global coord sys by `decomposeTransform`.
  46118. x: 0,
  46119. y: 0,
  46120. rotation: 0,
  46121. // --- transform props end ---
  46122. silent: AxisBuilder.isLabelSilent(axisModel),
  46123. z2: z2,
  46124. style: createTextStyle(itemLabelModel, {
  46125. text: formattedLabel,
  46126. align: index === 0 ? alignMin : index === labels.length - 1 ? alignMax : align,
  46127. verticalAlign: index === 0 ? verticalAlignMin : index === labels.length - 1 ? verticalAlignMax : verticalAlign,
  46128. fill: isFunction(textColor) ? textColor(
  46129. // (1) In category axis with data zoom, tick is not the original
  46130. // index of axis.data. So tick should not be exposed to user
  46131. // in category axis.
  46132. // (2) Compatible with previous version, which always use formatted label as
  46133. // input. But in interval scale the formatted label is like '223,445', which
  46134. // maked user replace ','. So we modify it to return original val but remain
  46135. // it as 'string' to avoid error in replacing.
  46136. axis.type === 'category' ? rawLabel : axis.type === 'value' ? tickValue + '' : tickValue, index) : textColor
  46137. })
  46138. });
  46139. textEl.anid = 'label_' + tickValue;
  46140. var inner = getLabelInner(textEl);
  46141. inner["break"] = labelItem["break"];
  46142. inner.tickValue = tickValue;
  46143. inner.layoutRotation = labelLayout.rotation;
  46144. setTooltipConfig({
  46145. el: textEl,
  46146. componentModel: axisModel,
  46147. itemName: formattedLabel,
  46148. formatterParamsExtra: {
  46149. isTruncated: function () {
  46150. return textEl.isTruncated;
  46151. },
  46152. value: rawLabel,
  46153. tickIndex: index
  46154. }
  46155. });
  46156. // Pack data for mouse event
  46157. if (triggerEvent) {
  46158. var eventData = AxisBuilder.makeAxisEventDataBase(axisModel);
  46159. eventData.targetType = 'axisLabel';
  46160. eventData.value = rawLabel;
  46161. eventData.tickIndex = index;
  46162. if (labelItem["break"]) {
  46163. eventData["break"] = {
  46164. // type: labelItem.break.type,
  46165. start: labelItem["break"].parsedBreak.vmin,
  46166. end: labelItem["break"].parsedBreak.vmax
  46167. };
  46168. }
  46169. if (axis.type === 'category') {
  46170. eventData.dataIndex = tickValue;
  46171. }
  46172. getECData(textEl).eventData = eventData;
  46173. if (labelItem["break"]) {
  46174. addBreakEventHandler(axisModel, api, textEl, labelItem["break"]);
  46175. }
  46176. }
  46177. labelEls.push(textEl);
  46178. labelGroup.add(textEl);
  46179. });
  46180. var labelLayoutList = map(labelEls, function (label) {
  46181. return {
  46182. label: label,
  46183. priority: getLabelInner(label)["break"] ? label.z2 + (z2Max - z2Min + 1) // Make break labels be highest priority.
  46184. : label.z2,
  46185. defaultAttr: {
  46186. ignore: label.ignore
  46187. }
  46188. };
  46189. });
  46190. axisLabelBuildResultSet(local, labelLayoutList, labelGroup, axisLabelCreationCtx);
  46191. }
  46192. // Indicate that `layOutAxisTickLabel` has been called.
  46193. function axisLabelBuildResultExists(local) {
  46194. return !!local.labelLayoutList;
  46195. }
  46196. function axisLabelBuildResultSet(local, labelLayoutList, labelGroup, axisLabelsCreationContext) {
  46197. // Ensure the same lifetime.
  46198. local.labelLayoutList = labelLayoutList;
  46199. local.labelGroup = labelGroup;
  46200. local.axisLabelsCreationContext = axisLabelsCreationContext;
  46201. }
  46202. function updateAxisLabelChangableProps(cfg, axisModel, labelLayoutList, transformGroup) {
  46203. var labelMargin = axisModel.get(['axisLabel', 'margin']);
  46204. each(labelLayoutList, function (layout, idx) {
  46205. var geometry = ensureLabelLayoutWithGeometry(layout);
  46206. if (!geometry) {
  46207. return;
  46208. }
  46209. var labelEl = geometry.label;
  46210. var inner = getLabelInner(labelEl);
  46211. // See the comment in `suggestIgnore`.
  46212. geometry.suggestIgnore = labelEl.ignore;
  46213. // Currently no `ignore:true` is set in `buildAxisLabel`
  46214. // But `ignore:true` may be set subsequently for overlap handling, thus reset it here.
  46215. labelEl.ignore = false;
  46216. copyTransform(_tmpLayoutEl, _tmpLayoutElReset);
  46217. _tmpLayoutEl.x = axisModel.axis.dataToCoord(inner.tickValue);
  46218. _tmpLayoutEl.y = cfg.labelOffset + cfg.labelDirection * labelMargin;
  46219. _tmpLayoutEl.rotation = inner.layoutRotation;
  46220. transformGroup.add(_tmpLayoutEl);
  46221. _tmpLayoutEl.updateTransform();
  46222. transformGroup.remove(_tmpLayoutEl);
  46223. _tmpLayoutEl.decomposeTransform();
  46224. copyTransform(labelEl, _tmpLayoutEl);
  46225. labelEl.markRedraw();
  46226. setLabelLayoutDirty(geometry, true);
  46227. ensureLabelLayoutWithGeometry(geometry);
  46228. });
  46229. }
  46230. var _tmpLayoutEl = new Rect();
  46231. var _tmpLayoutElReset = new Rect();
  46232. function hasAxisName(axisName) {
  46233. return !!axisName;
  46234. }
  46235. function addBreakEventHandler(axisModel, api, textEl, visualBreak) {
  46236. textEl.on('click', function (params) {
  46237. var payload = {
  46238. type: AXIS_BREAK_EXPAND_ACTION_TYPE,
  46239. breaks: [{
  46240. start: visualBreak.parsedBreak.breakOption.start,
  46241. end: visualBreak.parsedBreak.breakOption.end
  46242. }]
  46243. };
  46244. payload[axisModel.axis.dim + "AxisIndex"] = axisModel.componentIndex;
  46245. api.dispatchAction(payload);
  46246. });
  46247. }
  46248. function adjustBreakLabels(axisModel, axisRotation, labelLayoutList) {
  46249. var scaleBreakHelper = getScaleBreakHelper();
  46250. if (!scaleBreakHelper) {
  46251. return;
  46252. }
  46253. var breakLabelIndexPairs = scaleBreakHelper.retrieveAxisBreakPairs(labelLayoutList, function (layoutInfo) {
  46254. return layoutInfo && getLabelInner(layoutInfo.label)["break"];
  46255. }, true);
  46256. var moveOverlap = axisModel.get(['breakLabelLayout', 'moveOverlap'], true);
  46257. if (moveOverlap === true || moveOverlap === 'auto') {
  46258. each(breakLabelIndexPairs, function (idxPair) {
  46259. getAxisBreakHelper().adjustBreakLabelPair(axisModel.axis.inverse, axisRotation, [ensureLabelLayoutWithGeometry(labelLayoutList[idxPair[0]]), ensureLabelLayoutWithGeometry(labelLayoutList[idxPair[1]])]);
  46260. });
  46261. }
  46262. }
  46263. /**
  46264. * [__CAUTION__]
  46265. * MUST guarantee: if only the input `rect` and `axis.extent` changed,
  46266. * only `layout.position` changes.
  46267. * This character is replied on `grid.contain` calculation in `AxisBuilder`.
  46268. * @see updateCartesianAxisViewCommonPartBuilder
  46269. *
  46270. * Can only be called after coordinate system creation stage.
  46271. * (Can be called before coordinate system update stage).
  46272. */
  46273. function layout$1(rect, axisModel, opt) {
  46274. opt = opt || {};
  46275. var axis = axisModel.axis;
  46276. var layout = {};
  46277. var otherAxisOnZeroOf = axis.getAxesOnZeroOf()[0];
  46278. var rawAxisPosition = axis.position;
  46279. var axisPosition = otherAxisOnZeroOf ? 'onZero' : rawAxisPosition;
  46280. var axisDim = axis.dim;
  46281. var rectBound = [rect.x, rect.x + rect.width, rect.y, rect.y + rect.height];
  46282. var idx = {
  46283. left: 0,
  46284. right: 1,
  46285. top: 0,
  46286. bottom: 1,
  46287. onZero: 2
  46288. };
  46289. var axisOffset = axisModel.get('offset') || 0;
  46290. var posBound = axisDim === 'x' ? [rectBound[2] - axisOffset, rectBound[3] + axisOffset] : [rectBound[0] - axisOffset, rectBound[1] + axisOffset];
  46291. if (otherAxisOnZeroOf) {
  46292. var onZeroCoord = otherAxisOnZeroOf.toGlobalCoord(otherAxisOnZeroOf.dataToCoord(0));
  46293. posBound[idx.onZero] = Math.max(Math.min(onZeroCoord, posBound[1]), posBound[0]);
  46294. }
  46295. // Axis position
  46296. layout.position = [axisDim === 'y' ? posBound[idx[axisPosition]] : rectBound[0], axisDim === 'x' ? posBound[idx[axisPosition]] : rectBound[3]];
  46297. // Axis rotation
  46298. layout.rotation = Math.PI / 2 * (axisDim === 'x' ? 0 : 1);
  46299. // Tick and label direction, x y is axisDim
  46300. var dirMap = {
  46301. top: -1,
  46302. bottom: 1,
  46303. left: -1,
  46304. right: 1
  46305. };
  46306. layout.labelDirection = layout.tickDirection = layout.nameDirection = dirMap[rawAxisPosition];
  46307. layout.labelOffset = otherAxisOnZeroOf ? posBound[idx[rawAxisPosition]] - posBound[idx.onZero] : 0;
  46308. if (axisModel.get(['axisTick', 'inside'])) {
  46309. layout.tickDirection = -layout.tickDirection;
  46310. }
  46311. if (retrieve(opt.labelInside, axisModel.get(['axisLabel', 'inside']))) {
  46312. layout.labelDirection = -layout.labelDirection;
  46313. }
  46314. // Special label rotation
  46315. var labelRotate = axisModel.get(['axisLabel', 'rotate']);
  46316. layout.labelRotate = axisPosition === 'top' ? -labelRotate : labelRotate;
  46317. // Over splitLine and splitArea
  46318. layout.z2 = 1;
  46319. return layout;
  46320. }
  46321. /**
  46322. * Note: If pie (or other similar series) use cartesian2d, here
  46323. * option `seriesModel.get('coordinateSystem') === 'cartesian2d'`
  46324. * and `seriesModel.coordinateSystem !== cartesian2dCoordSysInstance`
  46325. * and `seriesModel.boxCoordinateSystem === cartesian2dCoordSysInstance`,
  46326. * the logic below is probably wrong, therefore skip it temporarily.
  46327. */
  46328. function isCartesian2DInjectedAsDataCoordSys(seriesModel) {
  46329. return seriesModel.coordinateSystem && seriesModel.coordinateSystem.type === 'cartesian2d';
  46330. }
  46331. function findAxisModels(seriesModel) {
  46332. var axisModelMap = {
  46333. xAxisModel: null,
  46334. yAxisModel: null
  46335. };
  46336. each(axisModelMap, function (v, key) {
  46337. var axisType = key.replace(/Model$/, '');
  46338. var axisModel = seriesModel.getReferringComponents(axisType, SINGLE_REFERRING).models[0];
  46339. if ("development" !== 'production') {
  46340. if (!axisModel) {
  46341. throw new Error(axisType + ' "' + retrieve3(seriesModel.get(axisType + 'Index'), seriesModel.get(axisType + 'Id'), 0) + '" not found');
  46342. }
  46343. }
  46344. axisModelMap[key] = axisModel;
  46345. });
  46346. return axisModelMap;
  46347. }
  46348. function createCartesianAxisViewCommonPartBuilder(gridRect, cartesians, axisModel, api, ctx, defaultNameMoveOverlap) {
  46349. var layoutResult = layout$1(gridRect, axisModel);
  46350. var axisLineAutoShow = false;
  46351. var axisTickAutoShow = false;
  46352. // Not show axisTick or axisLine if other axis is category / time
  46353. for (var i = 0; i < cartesians.length; i++) {
  46354. if (isIntervalOrLogScale(cartesians[i].getOtherAxis(axisModel.axis).scale)) {
  46355. // Still show axis tick or axisLine if other axis is value / log
  46356. axisLineAutoShow = axisTickAutoShow = true;
  46357. if (axisModel.axis.type === 'category' && axisModel.axis.onBand) {
  46358. axisTickAutoShow = false;
  46359. }
  46360. }
  46361. }
  46362. layoutResult.axisLineAutoShow = axisLineAutoShow;
  46363. layoutResult.axisTickAutoShow = axisTickAutoShow;
  46364. layoutResult.defaultNameMoveOverlap = defaultNameMoveOverlap;
  46365. return new AxisBuilder(axisModel, api, layoutResult, ctx);
  46366. }
  46367. function updateCartesianAxisViewCommonPartBuilder(axisBuilder, gridRect, axisModel) {
  46368. var newRaw = layout$1(gridRect, axisModel);
  46369. if ("development" !== 'production') {
  46370. var oldRaw_1 = axisBuilder.__getRawCfg();
  46371. each(keys(newRaw), function (prop) {
  46372. if (prop !== 'position' && prop !== 'labelOffset') {
  46373. assert(newRaw[prop] === oldRaw_1[prop]);
  46374. }
  46375. });
  46376. }
  46377. axisBuilder.updateCfg(newRaw);
  46378. }
  46379. function alignScaleTicks(scale, axisModel, alignToScale) {
  46380. var _a;
  46381. var intervalScaleProto = IntervalScale.prototype;
  46382. // NOTE: There is a precondition for log scale here:
  46383. // In log scale we store _interval and _extent of exponent value.
  46384. // So if we use the method of InternalScale to set/get these data.
  46385. // It process the exponent value, which is linear and what we want here.
  46386. var alignToTicks = intervalScaleProto.getTicks.call(alignToScale);
  46387. var alignToNicedTicks = intervalScaleProto.getTicks.call(alignToScale, {
  46388. expandToNicedExtent: true
  46389. });
  46390. var alignToSplitNumber = alignToTicks.length - 1;
  46391. var alignToInterval = intervalScaleProto.getInterval.call(alignToScale);
  46392. var scaleExtent = getScaleExtent(scale, axisModel);
  46393. var rawExtent = scaleExtent.extent;
  46394. var isMinFixed = scaleExtent.fixMin;
  46395. var isMaxFixed = scaleExtent.fixMax;
  46396. if (scale.type === 'log') {
  46397. rawExtent = logTransform(scale.base, rawExtent, true);
  46398. }
  46399. scale.setBreaksFromOption(retrieveAxisBreaksOption(axisModel));
  46400. scale.setExtent(rawExtent[0], rawExtent[1]);
  46401. scale.calcNiceExtent({
  46402. splitNumber: alignToSplitNumber,
  46403. fixMin: isMinFixed,
  46404. fixMax: isMaxFixed
  46405. });
  46406. var extent = intervalScaleProto.getExtent.call(scale);
  46407. // Need to update the rawExtent.
  46408. // Because value in rawExtent may be not parsed. e.g. 'dataMin', 'dataMax'
  46409. if (isMinFixed) {
  46410. rawExtent[0] = extent[0];
  46411. }
  46412. if (isMaxFixed) {
  46413. rawExtent[1] = extent[1];
  46414. }
  46415. var interval = intervalScaleProto.getInterval.call(scale);
  46416. var min = rawExtent[0];
  46417. var max = rawExtent[1];
  46418. if (isMinFixed && isMaxFixed) {
  46419. // User set min, max, divide to get new interval
  46420. interval = (max - min) / alignToSplitNumber;
  46421. } else if (isMinFixed) {
  46422. max = rawExtent[0] + interval * alignToSplitNumber;
  46423. // User set min, expand extent on the other side
  46424. while (max < rawExtent[1] && isFinite(max) && isFinite(rawExtent[1])) {
  46425. interval = increaseInterval(interval);
  46426. max = rawExtent[0] + interval * alignToSplitNumber;
  46427. }
  46428. } else if (isMaxFixed) {
  46429. // User set max, expand extent on the other side
  46430. min = rawExtent[1] - interval * alignToSplitNumber;
  46431. while (min > rawExtent[0] && isFinite(min) && isFinite(rawExtent[0])) {
  46432. interval = increaseInterval(interval);
  46433. min = rawExtent[1] - interval * alignToSplitNumber;
  46434. }
  46435. } else {
  46436. var nicedSplitNumber = scale.getTicks().length - 1;
  46437. if (nicedSplitNumber > alignToSplitNumber) {
  46438. interval = increaseInterval(interval);
  46439. }
  46440. var range = interval * alignToSplitNumber;
  46441. max = Math.ceil(rawExtent[1] / interval) * interval;
  46442. min = round(max - range);
  46443. // Not change the result that crossing zero.
  46444. if (min < 0 && rawExtent[0] >= 0) {
  46445. min = 0;
  46446. max = round(range);
  46447. } else if (max > 0 && rawExtent[1] <= 0) {
  46448. max = 0;
  46449. min = -round(range);
  46450. }
  46451. }
  46452. // Adjust min, max based on the extent of alignTo. When min or max is set in alignTo scale
  46453. var t0 = (alignToTicks[0].value - alignToNicedTicks[0].value) / alignToInterval;
  46454. var t1 = (alignToTicks[alignToSplitNumber].value - alignToNicedTicks[alignToSplitNumber].value) / alignToInterval;
  46455. // NOTE: Must in setExtent -> setInterval -> setNiceExtent order.
  46456. intervalScaleProto.setExtent.call(scale, min + interval * t0, max + interval * t1);
  46457. intervalScaleProto.setInterval.call(scale, interval);
  46458. if (t0 || t1) {
  46459. intervalScaleProto.setNiceExtent.call(scale, min + interval, max - interval);
  46460. }
  46461. if ("development" !== 'production') {
  46462. var ticks = intervalScaleProto.getTicks.call(scale);
  46463. if (ticks[1] && (!isValueNice(interval) || getPrecisionSafe(ticks[1].value) > getPrecisionSafe(interval))) {
  46464. warn("The ticks may be not readable when set min: " + axisModel.get('min') + ", max: " + axisModel.get('max') + (" and alignTicks: true. (" + ((_a = axisModel.axis) === null || _a === void 0 ? void 0 : _a.dim) + "AxisIndex: " + axisModel.componentIndex + ")"), true);
  46465. }
  46466. }
  46467. }
  46468. // margin is [top, right, bottom, left]
  46469. var XY_TO_MARGIN_IDX = [[3, 1], [0, 2] // xyIdx 1 => 'y'
  46470. ];
  46471. var Grid = /** @class */function () {
  46472. function Grid(gridModel, ecModel, api) {
  46473. // FIXME:TS where used (different from registered type 'cartesian2d')?
  46474. this.type = 'grid';
  46475. this._coordsMap = {};
  46476. this._coordsList = [];
  46477. this._axesMap = {};
  46478. this._axesList = [];
  46479. this.axisPointerEnabled = true;
  46480. this.dimensions = cartesian2DDimensions;
  46481. this._initCartesian(gridModel, ecModel, api);
  46482. this.model = gridModel;
  46483. }
  46484. Grid.prototype.getRect = function () {
  46485. return this._rect;
  46486. };
  46487. Grid.prototype.update = function (ecModel, api) {
  46488. var axesMap = this._axesMap;
  46489. this._updateScale(ecModel, this.model);
  46490. function updateAxisTicks(axes) {
  46491. var alignTo;
  46492. // Axis is added in order of axisIndex.
  46493. var axesIndices = keys(axes);
  46494. var len = axesIndices.length;
  46495. if (!len) {
  46496. return;
  46497. }
  46498. var axisNeedsAlign = [];
  46499. // Process once and calculate the ticks for those don't use alignTicks.
  46500. for (var i = len - 1; i >= 0; i--) {
  46501. var idx = +axesIndices[i]; // Convert to number.
  46502. var axis = axes[idx];
  46503. var model = axis.model;
  46504. var scale = axis.scale;
  46505. if (
  46506. // Only value and log axis without interval support alignTicks.
  46507. isIntervalOrLogScale(scale) && model.get('alignTicks') && model.get('interval') == null) {
  46508. axisNeedsAlign.push(axis);
  46509. } else {
  46510. niceScaleExtent(scale, model);
  46511. if (isIntervalOrLogScale(scale)) {
  46512. // Can only align to interval or log axis.
  46513. alignTo = axis;
  46514. }
  46515. }
  46516. }
  46517. // All axes has set alignTicks. Pick the first one.
  46518. // PENDING. Should we find the axis that both set interval, min, max and align to this one?
  46519. if (axisNeedsAlign.length) {
  46520. if (!alignTo) {
  46521. alignTo = axisNeedsAlign.pop();
  46522. niceScaleExtent(alignTo.scale, alignTo.model);
  46523. }
  46524. each(axisNeedsAlign, function (axis) {
  46525. alignScaleTicks(axis.scale, axis.model, alignTo.scale);
  46526. });
  46527. }
  46528. }
  46529. updateAxisTicks(axesMap.x);
  46530. updateAxisTicks(axesMap.y);
  46531. // Key: axisDim_axisIndex, value: boolean, whether onZero target.
  46532. var onZeroRecords = {};
  46533. each(axesMap.x, function (xAxis) {
  46534. fixAxisOnZero(axesMap, 'y', xAxis, onZeroRecords);
  46535. });
  46536. each(axesMap.y, function (yAxis) {
  46537. fixAxisOnZero(axesMap, 'x', yAxis, onZeroRecords);
  46538. });
  46539. // Resize again if containLabel is enabled
  46540. // FIXME It may cause getting wrong grid size in data processing stage
  46541. this.resize(this.model, api);
  46542. };
  46543. /**
  46544. * Resize the grid.
  46545. *
  46546. * [NOTE]
  46547. * If both "grid.containLabel/grid.contain" and pixel-required-data-processing (such as, "dataSampling")
  46548. * exist, circular dependency occurs in logic.
  46549. * The final compromised sequence is:
  46550. * 1. Calculate "axis.extent" (pixel extent) and AffineTransform based on only "grid layout options".
  46551. * Not accurate if "grid.containLabel/grid.contain" is required, but it is a compromise to avoid
  46552. * circular dependency.
  46553. * 2. Perform "series data processing" (where "dataSampling" requires "axis.extent").
  46554. * 3. Calculate "scale.extent" (data extent) based on "processed series data".
  46555. * 4. Modify "axis.extent" for "grid.containLabel/grid.contain":
  46556. * 4.1. Calculate "axis labels" based on "scale.extent".
  46557. * 4.2. Modify "axis.extent" by the bounding rects of "axis labels and names".
  46558. */
  46559. Grid.prototype.resize = function (gridModel, api, beforeDataProcessing) {
  46560. var layoutRef = createBoxLayoutReference(gridModel, api);
  46561. var gridRect = this._rect = getLayoutRect(gridModel.getBoxLayoutParams(), layoutRef.refContainer);
  46562. // PENDING: whether to support that if the input `coord` is out of the base coord sys,
  46563. // do not render anything. At present, the behavior is undefined.
  46564. var axesMap = this._axesMap;
  46565. var coordsList = this._coordsList;
  46566. var optionContainLabel = gridModel.get('containLabel'); // No `.get(, true)` for backward compat.
  46567. updateAllAxisExtentTransByGridRect(axesMap, gridRect);
  46568. if (!beforeDataProcessing) {
  46569. var axisBuilderSharedCtx = createAxisBiulders(gridRect, coordsList, axesMap, optionContainLabel, api);
  46570. var noPxChange = void 0;
  46571. if (optionContainLabel) {
  46572. if (legacyLayOutGridByContainLabel) {
  46573. // console.time('legacyLayOutGridByContainLabel');
  46574. legacyLayOutGridByContainLabel(this._axesList, gridRect);
  46575. updateAllAxisExtentTransByGridRect(axesMap, gridRect);
  46576. // console.timeEnd('legacyLayOutGridByContainLabel');
  46577. } else {
  46578. if ("development" !== 'production') {
  46579. log('Specified `grid.containLabel` but no `use(LegacyGridContainLabel)`;' + 'use `grid.outerBounds` instead.', true);
  46580. }
  46581. noPxChange = layOutGridByOuterBounds(gridRect.clone(), 'axisLabel', null, gridRect, axesMap, axisBuilderSharedCtx, layoutRef);
  46582. }
  46583. } else {
  46584. var _a = prepareOuterBounds(gridModel, gridRect, layoutRef),
  46585. outerBoundsRect = _a.outerBoundsRect,
  46586. parsedOuterBoundsContain = _a.parsedOuterBoundsContain,
  46587. outerBoundsClamp = _a.outerBoundsClamp;
  46588. if (outerBoundsRect) {
  46589. // console.time('layOutGridByOuterBounds');
  46590. noPxChange = layOutGridByOuterBounds(outerBoundsRect, parsedOuterBoundsContain, outerBoundsClamp, gridRect, axesMap, axisBuilderSharedCtx, layoutRef);
  46591. // console.timeEnd('layOutGridByOuterBounds');
  46592. }
  46593. }
  46594. // console.time('buildAxesView_determine');
  46595. createOrUpdateAxesView(gridRect, axesMap, AxisTickLabelComputingKind.determine, null, noPxChange, layoutRef);
  46596. // console.timeEnd('buildAxesView_determine');
  46597. } // End of beforeDataProcessing
  46598. each(this._coordsList, function (coord) {
  46599. // Calculate affine matrix to accelerate the data to point transform.
  46600. // If all the axes scales are time or value.
  46601. coord.calcAffineTransform();
  46602. });
  46603. };
  46604. Grid.prototype.getAxis = function (dim, axisIndex) {
  46605. var axesMapOnDim = this._axesMap[dim];
  46606. if (axesMapOnDim != null) {
  46607. return axesMapOnDim[axisIndex || 0];
  46608. }
  46609. };
  46610. Grid.prototype.getAxes = function () {
  46611. return this._axesList.slice();
  46612. };
  46613. Grid.prototype.getCartesian = function (xAxisIndex, yAxisIndex) {
  46614. if (xAxisIndex != null && yAxisIndex != null) {
  46615. var key = 'x' + xAxisIndex + 'y' + yAxisIndex;
  46616. return this._coordsMap[key];
  46617. }
  46618. if (isObject(xAxisIndex)) {
  46619. yAxisIndex = xAxisIndex.yAxisIndex;
  46620. xAxisIndex = xAxisIndex.xAxisIndex;
  46621. }
  46622. for (var i = 0, coordList = this._coordsList; i < coordList.length; i++) {
  46623. if (coordList[i].getAxis('x').index === xAxisIndex || coordList[i].getAxis('y').index === yAxisIndex) {
  46624. return coordList[i];
  46625. }
  46626. }
  46627. };
  46628. Grid.prototype.getCartesians = function () {
  46629. return this._coordsList.slice();
  46630. };
  46631. /**
  46632. * @implements
  46633. */
  46634. Grid.prototype.convertToPixel = function (ecModel, finder, value) {
  46635. var target = this._findConvertTarget(finder);
  46636. return target.cartesian ? target.cartesian.dataToPoint(value) : target.axis ? target.axis.toGlobalCoord(target.axis.dataToCoord(value)) : null;
  46637. };
  46638. /**
  46639. * @implements
  46640. */
  46641. Grid.prototype.convertFromPixel = function (ecModel, finder, value) {
  46642. var target = this._findConvertTarget(finder);
  46643. return target.cartesian ? target.cartesian.pointToData(value) : target.axis ? target.axis.coordToData(target.axis.toLocalCoord(value)) : null;
  46644. };
  46645. Grid.prototype._findConvertTarget = function (finder) {
  46646. var seriesModel = finder.seriesModel;
  46647. var xAxisModel = finder.xAxisModel || seriesModel && seriesModel.getReferringComponents('xAxis', SINGLE_REFERRING).models[0];
  46648. var yAxisModel = finder.yAxisModel || seriesModel && seriesModel.getReferringComponents('yAxis', SINGLE_REFERRING).models[0];
  46649. var gridModel = finder.gridModel;
  46650. var coordsList = this._coordsList;
  46651. var cartesian;
  46652. var axis;
  46653. if (seriesModel) {
  46654. cartesian = seriesModel.coordinateSystem;
  46655. indexOf(coordsList, cartesian) < 0 && (cartesian = null);
  46656. } else if (xAxisModel && yAxisModel) {
  46657. cartesian = this.getCartesian(xAxisModel.componentIndex, yAxisModel.componentIndex);
  46658. } else if (xAxisModel) {
  46659. axis = this.getAxis('x', xAxisModel.componentIndex);
  46660. } else if (yAxisModel) {
  46661. axis = this.getAxis('y', yAxisModel.componentIndex);
  46662. }
  46663. // Lowest priority.
  46664. else if (gridModel) {
  46665. var grid = gridModel.coordinateSystem;
  46666. if (grid === this) {
  46667. cartesian = this._coordsList[0];
  46668. }
  46669. }
  46670. return {
  46671. cartesian: cartesian,
  46672. axis: axis
  46673. };
  46674. };
  46675. /**
  46676. * @implements
  46677. */
  46678. Grid.prototype.containPoint = function (point) {
  46679. var coord = this._coordsList[0];
  46680. if (coord) {
  46681. return coord.containPoint(point);
  46682. }
  46683. };
  46684. /**
  46685. * Initialize cartesian coordinate systems
  46686. */
  46687. Grid.prototype._initCartesian = function (gridModel, ecModel, api) {
  46688. var _this = this;
  46689. var grid = this;
  46690. var axisPositionUsed = {
  46691. left: false,
  46692. right: false,
  46693. top: false,
  46694. bottom: false
  46695. };
  46696. var axesMap = {
  46697. x: {},
  46698. y: {}
  46699. };
  46700. var axesCount = {
  46701. x: 0,
  46702. y: 0
  46703. };
  46704. // Create axis
  46705. ecModel.eachComponent('xAxis', createAxisCreator('x'), this);
  46706. ecModel.eachComponent('yAxis', createAxisCreator('y'), this);
  46707. if (!axesCount.x || !axesCount.y) {
  46708. // Roll back when there no either x or y axis
  46709. this._axesMap = {};
  46710. this._axesList = [];
  46711. return;
  46712. }
  46713. this._axesMap = axesMap;
  46714. // Create cartesian2d
  46715. each(axesMap.x, function (xAxis, xAxisIndex) {
  46716. each(axesMap.y, function (yAxis, yAxisIndex) {
  46717. var key = 'x' + xAxisIndex + 'y' + yAxisIndex;
  46718. var cartesian = new Cartesian2D(key);
  46719. cartesian.master = _this;
  46720. cartesian.model = gridModel;
  46721. _this._coordsMap[key] = cartesian;
  46722. _this._coordsList.push(cartesian);
  46723. cartesian.addAxis(xAxis);
  46724. cartesian.addAxis(yAxis);
  46725. });
  46726. });
  46727. function createAxisCreator(dimName) {
  46728. return function (axisModel, idx) {
  46729. if (!isAxisUsedInTheGrid(axisModel, gridModel)) {
  46730. return;
  46731. }
  46732. var axisPosition = axisModel.get('position');
  46733. if (dimName === 'x') {
  46734. // Fix position
  46735. if (axisPosition !== 'top' && axisPosition !== 'bottom') {
  46736. // Default bottom of X
  46737. axisPosition = axisPositionUsed.bottom ? 'top' : 'bottom';
  46738. }
  46739. } else {
  46740. // Fix position
  46741. if (axisPosition !== 'left' && axisPosition !== 'right') {
  46742. // Default left of Y
  46743. axisPosition = axisPositionUsed.left ? 'right' : 'left';
  46744. }
  46745. }
  46746. axisPositionUsed[axisPosition] = true;
  46747. var axis = new Axis2D(dimName, createScaleByModel(axisModel), [0, 0], axisModel.get('type'), axisPosition);
  46748. var isCategory = axis.type === 'category';
  46749. axis.onBand = isCategory && axisModel.get('boundaryGap');
  46750. axis.inverse = axisModel.get('inverse');
  46751. // Inject axis into axisModel
  46752. axisModel.axis = axis;
  46753. // Inject axisModel into axis
  46754. axis.model = axisModel;
  46755. // Inject grid info axis
  46756. axis.grid = grid;
  46757. // Index of axis, can be used as key
  46758. axis.index = idx;
  46759. grid._axesList.push(axis);
  46760. axesMap[dimName][idx] = axis;
  46761. axesCount[dimName]++;
  46762. };
  46763. }
  46764. };
  46765. /**
  46766. * Update cartesian properties from series.
  46767. */
  46768. Grid.prototype._updateScale = function (ecModel, gridModel) {
  46769. // Reset scale
  46770. each(this._axesList, function (axis) {
  46771. axis.scale.setExtent(Infinity, -Infinity);
  46772. if (axis.type === 'category') {
  46773. var categorySortInfo = axis.model.get('categorySortInfo');
  46774. axis.scale.setSortInfo(categorySortInfo);
  46775. }
  46776. });
  46777. ecModel.eachSeries(function (seriesModel) {
  46778. // If pie (or other similar series) use cartesian2d, the unionExtent logic below is
  46779. // wrong, therefore skip it temporarily. See also in `defaultAxisExtentFromData.ts`.
  46780. // TODO: support union extent in this case.
  46781. if (isCartesian2DInjectedAsDataCoordSys(seriesModel)) {
  46782. var axesModelMap = findAxisModels(seriesModel);
  46783. var xAxisModel = axesModelMap.xAxisModel;
  46784. var yAxisModel = axesModelMap.yAxisModel;
  46785. if (!isAxisUsedInTheGrid(xAxisModel, gridModel) || !isAxisUsedInTheGrid(yAxisModel, gridModel)) {
  46786. return;
  46787. }
  46788. var cartesian = this.getCartesian(xAxisModel.componentIndex, yAxisModel.componentIndex);
  46789. var data = seriesModel.getData();
  46790. var xAxis = cartesian.getAxis('x');
  46791. var yAxis = cartesian.getAxis('y');
  46792. unionExtent(data, xAxis);
  46793. unionExtent(data, yAxis);
  46794. }
  46795. }, this);
  46796. function unionExtent(data, axis) {
  46797. each(getDataDimensionsOnAxis(data, axis.dim), function (dim) {
  46798. axis.scale.unionExtentFromData(data, dim);
  46799. });
  46800. }
  46801. };
  46802. /**
  46803. * @param dim 'x' or 'y' or 'auto' or null/undefined
  46804. */
  46805. Grid.prototype.getTooltipAxes = function (dim) {
  46806. var baseAxes = [];
  46807. var otherAxes = [];
  46808. each(this.getCartesians(), function (cartesian) {
  46809. var baseAxis = dim != null && dim !== 'auto' ? cartesian.getAxis(dim) : cartesian.getBaseAxis();
  46810. var otherAxis = cartesian.getOtherAxis(baseAxis);
  46811. indexOf(baseAxes, baseAxis) < 0 && baseAxes.push(baseAxis);
  46812. indexOf(otherAxes, otherAxis) < 0 && otherAxes.push(otherAxis);
  46813. });
  46814. return {
  46815. baseAxes: baseAxes,
  46816. otherAxes: otherAxes
  46817. };
  46818. };
  46819. Grid.create = function (ecModel, api) {
  46820. var grids = [];
  46821. ecModel.eachComponent('grid', function (gridModel, idx) {
  46822. var grid = new Grid(gridModel, ecModel, api);
  46823. grid.name = 'grid_' + idx;
  46824. // dataSampling requires axis extent, so resize
  46825. // should be performed in create stage.
  46826. grid.resize(gridModel, api, true);
  46827. gridModel.coordinateSystem = grid;
  46828. grids.push(grid);
  46829. });
  46830. // Inject the coordinateSystems into seriesModel
  46831. ecModel.eachSeries(function (seriesModel) {
  46832. injectCoordSysByOption({
  46833. targetModel: seriesModel,
  46834. coordSysType: 'cartesian2d',
  46835. coordSysProvider: coordSysProvider
  46836. });
  46837. function coordSysProvider() {
  46838. var axesModelMap = findAxisModels(seriesModel);
  46839. var xAxisModel = axesModelMap.xAxisModel;
  46840. var yAxisModel = axesModelMap.yAxisModel;
  46841. var gridModel = xAxisModel.getCoordSysModel();
  46842. if ("development" !== 'production') {
  46843. if (!gridModel) {
  46844. throw new Error('Grid "' + retrieve3(xAxisModel.get('gridIndex'), xAxisModel.get('gridId'), 0) + '" not found');
  46845. }
  46846. if (xAxisModel.getCoordSysModel() !== yAxisModel.getCoordSysModel()) {
  46847. throw new Error('xAxis and yAxis must use the same grid');
  46848. }
  46849. }
  46850. var grid = gridModel.coordinateSystem;
  46851. return grid.getCartesian(xAxisModel.componentIndex, yAxisModel.componentIndex);
  46852. }
  46853. });
  46854. return grids;
  46855. };
  46856. // For deciding which dimensions to use when creating list data
  46857. Grid.dimensions = cartesian2DDimensions;
  46858. return Grid;
  46859. }();
  46860. /**
  46861. * Check if the axis is used in the specified grid.
  46862. */
  46863. function isAxisUsedInTheGrid(axisModel, gridModel) {
  46864. return axisModel.getCoordSysModel() === gridModel;
  46865. }
  46866. function fixAxisOnZero(axesMap, otherAxisDim, axis,
  46867. // Key: see `getOnZeroRecordKey`
  46868. onZeroRecords) {
  46869. axis.getAxesOnZeroOf = function () {
  46870. // TODO: onZero of multiple axes.
  46871. return otherAxisOnZeroOf ? [otherAxisOnZeroOf] : [];
  46872. };
  46873. // onZero can not be enabled in these two situations:
  46874. // 1. When any other axis is a category axis.
  46875. // 2. When no axis is cross 0 point.
  46876. var otherAxes = axesMap[otherAxisDim];
  46877. var otherAxisOnZeroOf;
  46878. var axisModel = axis.model;
  46879. var onZero = axisModel.get(['axisLine', 'onZero']);
  46880. var onZeroAxisIndex = axisModel.get(['axisLine', 'onZeroAxisIndex']);
  46881. if (!onZero) {
  46882. return;
  46883. }
  46884. // If target axis is specified.
  46885. if (onZeroAxisIndex != null) {
  46886. if (canOnZeroToAxis(otherAxes[onZeroAxisIndex])) {
  46887. otherAxisOnZeroOf = otherAxes[onZeroAxisIndex];
  46888. }
  46889. } else {
  46890. // Find the first available other axis.
  46891. for (var idx in otherAxes) {
  46892. if (otherAxes.hasOwnProperty(idx) && canOnZeroToAxis(otherAxes[idx])
  46893. // Consider that two Y axes on one value axis,
  46894. // if both onZero, the two Y axes overlap.
  46895. && !onZeroRecords[getOnZeroRecordKey(otherAxes[idx])]) {
  46896. otherAxisOnZeroOf = otherAxes[idx];
  46897. break;
  46898. }
  46899. }
  46900. }
  46901. if (otherAxisOnZeroOf) {
  46902. onZeroRecords[getOnZeroRecordKey(otherAxisOnZeroOf)] = true;
  46903. }
  46904. function getOnZeroRecordKey(axis) {
  46905. return axis.dim + '_' + axis.index;
  46906. }
  46907. }
  46908. function canOnZeroToAxis(axis) {
  46909. return axis && axis.type !== 'category' && axis.type !== 'time' && ifAxisCrossZero(axis);
  46910. }
  46911. function updateAxisTransform(axis, coordBase) {
  46912. var axisExtent = axis.getExtent();
  46913. var axisExtentSum = axisExtent[0] + axisExtent[1];
  46914. // Fast transform
  46915. axis.toGlobalCoord = axis.dim === 'x' ? function (coord) {
  46916. return coord + coordBase;
  46917. } : function (coord) {
  46918. return axisExtentSum - coord + coordBase;
  46919. };
  46920. axis.toLocalCoord = axis.dim === 'x' ? function (coord) {
  46921. return coord - coordBase;
  46922. } : function (coord) {
  46923. return axisExtentSum - coord + coordBase;
  46924. };
  46925. }
  46926. function updateAllAxisExtentTransByGridRect(axesMap, gridRect) {
  46927. each(axesMap.x, function (axis) {
  46928. return updateAxisExtentTransByGridRect(axis, gridRect.x, gridRect.width);
  46929. });
  46930. each(axesMap.y, function (axis) {
  46931. return updateAxisExtentTransByGridRect(axis, gridRect.y, gridRect.height);
  46932. });
  46933. }
  46934. function updateAxisExtentTransByGridRect(axis, gridXY, gridWH) {
  46935. var extent = [0, gridWH];
  46936. var idx = axis.inverse ? 1 : 0;
  46937. axis.setExtent(extent[idx], extent[1 - idx]);
  46938. updateAxisTransform(axis, gridXY);
  46939. }
  46940. var legacyLayOutGridByContainLabel;
  46941. function registerLegacyGridContainLabelImpl(impl) {
  46942. legacyLayOutGridByContainLabel = impl;
  46943. }
  46944. // Return noPxChange.
  46945. function layOutGridByOuterBounds(outerBoundsRect, outerBoundsContain, outerBoundsClamp, gridRect, axesMap, axisBuilderSharedCtx, layoutRef) {
  46946. if ("development" !== 'production') {
  46947. assert(outerBoundsContain === 'all' || outerBoundsContain === 'axisLabel');
  46948. }
  46949. // Assume `updateAllAxisExtentTransByGridRect` has been performed once before this call.
  46950. // [NOTE]:
  46951. // - The bounding rect of the axis elements might be sensitve to variations in `axis.extent` due to strategies
  46952. // like hideOverlap/moveOverlap. @see the comment in `LabelLayoutBase['suggestIgnore']`.
  46953. // - The final `gridRect` might be slightly smaller than the ideally expected result if labels are giant and
  46954. // get hidden due to overlapping. More iterations could improve precision, but not performant. We consider
  46955. // the current result acceptable, since no alignment among charts can be guaranteed when using this feature.
  46956. createOrUpdateAxesView(gridRect, axesMap, AxisTickLabelComputingKind.estimate, outerBoundsContain, false, layoutRef);
  46957. var margin = [0, 0, 0, 0];
  46958. fillLabelNameOverflowOnOneDimension(0);
  46959. fillLabelNameOverflowOnOneDimension(1);
  46960. // If axis is blank, no label can be used to detect overflow.
  46961. // gridRect itself should not overflow.
  46962. fillMarginOnOneDimension(gridRect, 0, NaN);
  46963. fillMarginOnOneDimension(gridRect, 1, NaN);
  46964. var noPxChange = find(margin, function (item) {
  46965. return item > 0;
  46966. }) == null;
  46967. expandOrShrinkRect(gridRect, margin, true, true, outerBoundsClamp);
  46968. updateAllAxisExtentTransByGridRect(axesMap, gridRect);
  46969. return noPxChange;
  46970. function fillLabelNameOverflowOnOneDimension(xyIdx) {
  46971. each(axesMap[XY$1[xyIdx]], function (axis) {
  46972. if (!shouldAxisShow(axis.model)) {
  46973. return;
  46974. }
  46975. // FIXME: zr Group.union may wrongly union (0, 0, 0, 0) and not performant.
  46976. // unionRect.union(axis.axisBuilder.group.getBoundingRect());
  46977. // If ussing Group.getBoundingRect to calculate shrink space, it is not strictly accurate when
  46978. // the outermost label is ignored and the secondary label is very long and contribute to the
  46979. // union extension:
  46980. // -|---|---|---|
  46981. // 1,000,000,000
  46982. // Therefore we calculate them one by one.
  46983. // Also considered axis may be blank or no labels.
  46984. var sharedRecord = axisBuilderSharedCtx.ensureRecord(axis.model);
  46985. var labelInfoList = sharedRecord.labelInfoList;
  46986. if (labelInfoList) {
  46987. for (var idx = 0; idx < labelInfoList.length; idx++) {
  46988. var labelInfo = labelInfoList[idx];
  46989. var proportion = axis.scale.normalize(getLabelInner(labelInfo.label).tickValue);
  46990. proportion = xyIdx === 1 ? 1 - proportion : proportion;
  46991. // xAxis use proportion on x, yAxis use proprotion on y, otherwise not.
  46992. fillMarginOnOneDimension(labelInfo.rect, xyIdx, proportion);
  46993. fillMarginOnOneDimension(labelInfo.rect, 1 - xyIdx, NaN);
  46994. }
  46995. }
  46996. var nameLayout = sharedRecord.nameLayout;
  46997. if (nameLayout) {
  46998. var proportion = isNameLocationCenter(sharedRecord.nameLocation) ? 0.5 : NaN;
  46999. fillMarginOnOneDimension(nameLayout.rect, xyIdx, proportion);
  47000. fillMarginOnOneDimension(nameLayout.rect, 1 - xyIdx, NaN);
  47001. }
  47002. });
  47003. }
  47004. function fillMarginOnOneDimension(itemRect, xyIdx, proportion // NaN mean no use proportion
  47005. ) {
  47006. var overflow1 = outerBoundsRect[XY$1[xyIdx]] - itemRect[XY$1[xyIdx]];
  47007. var overflow2 = itemRect[WH$1[xyIdx]] + itemRect[XY$1[xyIdx]] - (outerBoundsRect[WH$1[xyIdx]] + outerBoundsRect[XY$1[xyIdx]]);
  47008. overflow1 = applyProportion(overflow1, 1 - proportion);
  47009. overflow2 = applyProportion(overflow2, proportion);
  47010. var minIdx = XY_TO_MARGIN_IDX[xyIdx][0];
  47011. var maxIdx = XY_TO_MARGIN_IDX[xyIdx][1];
  47012. margin[minIdx] = mathMax$1(margin[minIdx], overflow1);
  47013. margin[maxIdx] = mathMax$1(margin[maxIdx], overflow2);
  47014. }
  47015. function applyProportion(overflow, proportion) {
  47016. // proportion is not likely to near zero. If so, give up shrink
  47017. if (overflow > 0 && !eqNaN(proportion) && proportion > 1e-4) {
  47018. overflow /= proportion;
  47019. }
  47020. return overflow;
  47021. }
  47022. }
  47023. function createAxisBiulders(gridRect, cartesians, axesMap, optionContainLabel, api) {
  47024. var axisBuilderSharedCtx = new AxisBuilderSharedContext(resolveAxisNameOverlapForGrid);
  47025. each(axesMap, function (axisList) {
  47026. return each(axisList, function (axis) {
  47027. if (shouldAxisShow(axis.model)) {
  47028. // See `AxisBaseOptionCommon['nameMoveOverlap']`.
  47029. var defaultNameMoveOverlap = !optionContainLabel;
  47030. axis.axisBuilder = createCartesianAxisViewCommonPartBuilder(gridRect, cartesians, axis.model, api, axisBuilderSharedCtx, defaultNameMoveOverlap);
  47031. }
  47032. });
  47033. });
  47034. return axisBuilderSharedCtx;
  47035. }
  47036. /**
  47037. * Promote the axis-elements-building from "view render" stage to "coordinate system resize" stage.
  47038. * This is aimed to resovle overlap across multiple axes, since currently it's hard to reconcile
  47039. * multiple axes in "view render" stage.
  47040. *
  47041. * [CAUTION] But this promotion assumes that the subsequent "visual mapping" stage does not affect
  47042. * this axis-elements-building; otherwise we have to refactor it again.
  47043. */
  47044. function createOrUpdateAxesView(gridRect, axesMap, kind, outerBoundsContain, noPxChange, layoutRef) {
  47045. var isDetermine = kind === AxisTickLabelComputingKind.determine;
  47046. each(axesMap, function (axisList) {
  47047. return each(axisList, function (axis) {
  47048. if (shouldAxisShow(axis.model)) {
  47049. updateCartesianAxisViewCommonPartBuilder(axis.axisBuilder, gridRect, axis.model);
  47050. axis.axisBuilder.build(isDetermine ? {
  47051. axisTickLabelDetermine: true
  47052. } : {
  47053. axisTickLabelEstimate: true
  47054. }, {
  47055. noPxChange: noPxChange
  47056. });
  47057. }
  47058. });
  47059. });
  47060. var nameMarginLevelMap = {
  47061. x: 0,
  47062. y: 0
  47063. };
  47064. calcNameMarginLevel(0);
  47065. calcNameMarginLevel(1);
  47066. function calcNameMarginLevel(xyIdx) {
  47067. nameMarginLevelMap[XY$1[1 - xyIdx]] = gridRect[WH$1[xyIdx]] <= layoutRef.refContainer[WH$1[xyIdx]] * 0.5 ? 0 : 1 - xyIdx === 1 ? 2 : 1;
  47068. }
  47069. each(axesMap, function (axisList, xy) {
  47070. return each(axisList, function (axis) {
  47071. if (shouldAxisShow(axis.model)) {
  47072. if (outerBoundsContain === 'all' || isDetermine) {
  47073. // To resolve overlap, `axisName` layout depends on `axisTickLabel` layout result
  47074. // (all of the axes of the same `grid`; consider multiple x or y axes).
  47075. axis.axisBuilder.build({
  47076. axisName: true
  47077. }, {
  47078. nameMarginLevel: nameMarginLevelMap[xy]
  47079. });
  47080. }
  47081. if (isDetermine) {
  47082. axis.axisBuilder.build({
  47083. axisLine: true
  47084. });
  47085. }
  47086. }
  47087. });
  47088. });
  47089. }
  47090. function prepareOuterBounds(gridModel, rawRridRect, layoutRef) {
  47091. var outerBoundsRect;
  47092. var optionOuterBoundsMode = gridModel.get('outerBoundsMode', true);
  47093. if (optionOuterBoundsMode === 'same') {
  47094. outerBoundsRect = rawRridRect.clone();
  47095. } else if (optionOuterBoundsMode == null || optionOuterBoundsMode === 'auto') {
  47096. outerBoundsRect = getLayoutRect(gridModel.get('outerBounds', true) || OUTER_BOUNDS_DEFAULT, layoutRef.refContainer);
  47097. } else if (optionOuterBoundsMode !== 'none') {
  47098. if ("development" !== 'production') {
  47099. error("Invalid grid[" + gridModel.componentIndex + "].outerBoundsMode.");
  47100. }
  47101. }
  47102. var optionOuterBoundsContain = gridModel.get('outerBoundsContain', true);
  47103. var parsedOuterBoundsContain;
  47104. if (optionOuterBoundsContain == null || optionOuterBoundsContain === 'auto') {
  47105. parsedOuterBoundsContain = 'all';
  47106. } else if (indexOf(['all', 'axisLabel'], optionOuterBoundsContain) < 0) {
  47107. if ("development" !== 'production') {
  47108. error("Invalid grid[" + gridModel.componentIndex + "].outerBoundsContain.");
  47109. }
  47110. parsedOuterBoundsContain = 'all';
  47111. } else {
  47112. parsedOuterBoundsContain = optionOuterBoundsContain;
  47113. }
  47114. var outerBoundsClamp = [parsePositionSizeOption(retrieve2(gridModel.get('outerBoundsClampWidth', true), OUTER_BOUNDS_CLAMP_DEFAULT[0]), rawRridRect.width), parsePositionSizeOption(retrieve2(gridModel.get('outerBoundsClampHeight', true), OUTER_BOUNDS_CLAMP_DEFAULT[1]), rawRridRect.height)];
  47115. return {
  47116. outerBoundsRect: outerBoundsRect,
  47117. parsedOuterBoundsContain: parsedOuterBoundsContain,
  47118. outerBoundsClamp: outerBoundsClamp
  47119. };
  47120. }
  47121. var resolveAxisNameOverlapForGrid = function (cfg, ctx, axisModel, nameLayoutInfo, nameMoveDirVec, thisRecord) {
  47122. var perpendicularDim = axisModel.axis.dim === 'x' ? 'y' : 'x';
  47123. resolveAxisNameOverlapDefault(cfg, ctx, axisModel, nameLayoutInfo, nameMoveDirVec, thisRecord);
  47124. // If nameLocation 'center', and there are multiple axes parallel to this axis, do not adjust by
  47125. // other axes, because the axis name should be close to its axis line as much as possible even
  47126. // if overlapping; otherwise it might cause misleading.
  47127. // If nameLocation 'center', do not adjust by perpendicular axes, since they are not likely to overlap.
  47128. // If nameLocation 'start'/'end', move name within the same direction to escape overlap with the
  47129. // perpendicular axes.
  47130. if (!isNameLocationCenter(cfg.nameLocation)) {
  47131. each(ctx.recordMap[perpendicularDim], function (perpenRecord) {
  47132. // perpendicular axis may be no name.
  47133. if (perpenRecord && perpenRecord.labelInfoList && perpenRecord.dirVec) {
  47134. moveIfOverlapByLinearLabels(perpenRecord.labelInfoList, perpenRecord.dirVec, nameLayoutInfo, nameMoveDirVec);
  47135. }
  47136. });
  47137. }
  47138. };
  47139. // Build axisPointerModel, mergin tooltip.axisPointer model for each axis.
  47140. // allAxesInfo should be updated when setOption performed.
  47141. function collect(ecModel, api) {
  47142. var result = {
  47143. /**
  47144. * key: makeKey(axis.model)
  47145. * value: {
  47146. * axis,
  47147. * coordSys,
  47148. * axisPointerModel,
  47149. * triggerTooltip,
  47150. * triggerEmphasis,
  47151. * involveSeries,
  47152. * snap,
  47153. * seriesModels,
  47154. * seriesDataCount
  47155. * }
  47156. */
  47157. axesInfo: {},
  47158. seriesInvolved: false,
  47159. /**
  47160. * key: makeKey(coordSys.model)
  47161. * value: Object: key makeKey(axis.model), value: axisInfo
  47162. */
  47163. coordSysAxesInfo: {},
  47164. coordSysMap: {}
  47165. };
  47166. collectAxesInfo(result, ecModel, api);
  47167. // Check seriesInvolved for performance, in case too many series in some chart.
  47168. result.seriesInvolved && collectSeriesInfo(result, ecModel);
  47169. return result;
  47170. }
  47171. function collectAxesInfo(result, ecModel, api) {
  47172. var globalTooltipModel = ecModel.getComponent('tooltip');
  47173. var globalAxisPointerModel = ecModel.getComponent('axisPointer');
  47174. // links can only be set on global.
  47175. var linksOption = globalAxisPointerModel.get('link', true) || [];
  47176. var linkGroups = [];
  47177. // Collect axes info.
  47178. each(api.getCoordinateSystems(), function (coordSys) {
  47179. // Some coordinate system do not support axes, like geo.
  47180. if (!coordSys.axisPointerEnabled) {
  47181. return;
  47182. }
  47183. var coordSysKey = makeKey(coordSys.model);
  47184. var axesInfoInCoordSys = result.coordSysAxesInfo[coordSysKey] = {};
  47185. result.coordSysMap[coordSysKey] = coordSys;
  47186. // Set tooltip (like 'cross') is a convenient way to show axisPointer
  47187. // for user. So we enable setting tooltip on coordSys model.
  47188. var coordSysModel = coordSys.model;
  47189. var baseTooltipModel = coordSysModel.getModel('tooltip', globalTooltipModel);
  47190. each(coordSys.getAxes(), curry(saveTooltipAxisInfo, false, null));
  47191. // If axis tooltip used, choose tooltip axis for each coordSys.
  47192. // Notice this case: coordSys is `grid` but not `cartesian2D` here.
  47193. if (coordSys.getTooltipAxes && globalTooltipModel
  47194. // If tooltip.showContent is set as false, tooltip will not
  47195. // show but axisPointer will show as normal.
  47196. && baseTooltipModel.get('show')) {
  47197. // Compatible with previous logic. But series.tooltip.trigger: 'axis'
  47198. // or series.data[n].tooltip.trigger: 'axis' are not support any more.
  47199. var triggerAxis = baseTooltipModel.get('trigger') === 'axis';
  47200. var cross = baseTooltipModel.get(['axisPointer', 'type']) === 'cross';
  47201. var tooltipAxes = coordSys.getTooltipAxes(baseTooltipModel.get(['axisPointer', 'axis']));
  47202. if (triggerAxis || cross) {
  47203. each(tooltipAxes.baseAxes, curry(saveTooltipAxisInfo, cross ? 'cross' : true, triggerAxis));
  47204. }
  47205. if (cross) {
  47206. each(tooltipAxes.otherAxes, curry(saveTooltipAxisInfo, 'cross', false));
  47207. }
  47208. }
  47209. // fromTooltip: true | false | 'cross'
  47210. // triggerTooltip: true | false | null
  47211. function saveTooltipAxisInfo(fromTooltip, triggerTooltip, axis) {
  47212. var axisPointerModel = axis.model.getModel('axisPointer', globalAxisPointerModel);
  47213. var axisPointerShow = axisPointerModel.get('show');
  47214. if (!axisPointerShow || axisPointerShow === 'auto' && !fromTooltip && !isHandleTrigger(axisPointerModel)) {
  47215. return;
  47216. }
  47217. if (triggerTooltip == null) {
  47218. triggerTooltip = axisPointerModel.get('triggerTooltip');
  47219. }
  47220. axisPointerModel = fromTooltip ? makeAxisPointerModel(axis, baseTooltipModel, globalAxisPointerModel, ecModel, fromTooltip, triggerTooltip) : axisPointerModel;
  47221. var snap = axisPointerModel.get('snap');
  47222. var triggerEmphasis = axisPointerModel.get('triggerEmphasis');
  47223. var axisKey = makeKey(axis.model);
  47224. var involveSeries = triggerTooltip || snap || axis.type === 'category';
  47225. // If result.axesInfo[key] exist, override it (tooltip has higher priority).
  47226. var axisInfo = result.axesInfo[axisKey] = {
  47227. key: axisKey,
  47228. axis: axis,
  47229. coordSys: coordSys,
  47230. axisPointerModel: axisPointerModel,
  47231. triggerTooltip: triggerTooltip,
  47232. triggerEmphasis: triggerEmphasis,
  47233. involveSeries: involveSeries,
  47234. snap: snap,
  47235. useHandle: isHandleTrigger(axisPointerModel),
  47236. seriesModels: [],
  47237. linkGroup: null
  47238. };
  47239. axesInfoInCoordSys[axisKey] = axisInfo;
  47240. result.seriesInvolved = result.seriesInvolved || involveSeries;
  47241. var groupIndex = getLinkGroupIndex(linksOption, axis);
  47242. if (groupIndex != null) {
  47243. var linkGroup = linkGroups[groupIndex] || (linkGroups[groupIndex] = {
  47244. axesInfo: {}
  47245. });
  47246. linkGroup.axesInfo[axisKey] = axisInfo;
  47247. linkGroup.mapper = linksOption[groupIndex].mapper;
  47248. axisInfo.linkGroup = linkGroup;
  47249. }
  47250. }
  47251. });
  47252. }
  47253. function makeAxisPointerModel(axis, baseTooltipModel, globalAxisPointerModel, ecModel, fromTooltip, triggerTooltip) {
  47254. var tooltipAxisPointerModel = baseTooltipModel.getModel('axisPointer');
  47255. var fields = ['type', 'snap', 'lineStyle', 'shadowStyle', 'label', 'animation', 'animationDurationUpdate', 'animationEasingUpdate', 'z'];
  47256. var volatileOption = {};
  47257. each(fields, function (field) {
  47258. volatileOption[field] = clone(tooltipAxisPointerModel.get(field));
  47259. });
  47260. // category axis do not auto snap, otherwise some tick that do not
  47261. // has value can not be hovered. value/time/log axis default snap if
  47262. // triggered from tooltip and trigger tooltip.
  47263. volatileOption.snap = axis.type !== 'category' && !!triggerTooltip;
  47264. // Compatible with previous behavior, tooltip axis does not show label by default.
  47265. // Only these properties can be overridden from tooltip to axisPointer.
  47266. if (tooltipAxisPointerModel.get('type') === 'cross') {
  47267. volatileOption.type = 'line';
  47268. }
  47269. var labelOption = volatileOption.label || (volatileOption.label = {});
  47270. // Follow the convention, do not show label when triggered by tooltip by default.
  47271. labelOption.show == null && (labelOption.show = false);
  47272. if (fromTooltip === 'cross') {
  47273. // When 'cross', both axes show labels.
  47274. var tooltipAxisPointerLabelShow = tooltipAxisPointerModel.get(['label', 'show']);
  47275. labelOption.show = tooltipAxisPointerLabelShow != null ? tooltipAxisPointerLabelShow : true;
  47276. // If triggerTooltip, this is a base axis, which should better not use cross style
  47277. // (cross style is dashed by default)
  47278. if (!triggerTooltip) {
  47279. var crossStyle = volatileOption.lineStyle = tooltipAxisPointerModel.get('crossStyle');
  47280. crossStyle && defaults(labelOption, crossStyle.textStyle);
  47281. }
  47282. }
  47283. return axis.model.getModel('axisPointer', new Model(volatileOption, globalAxisPointerModel, ecModel));
  47284. }
  47285. function collectSeriesInfo(result, ecModel) {
  47286. // Prepare data for axis trigger
  47287. ecModel.eachSeries(function (seriesModel) {
  47288. // Notice this case: this coordSys is `cartesian2D` but not `grid`.
  47289. var coordSys = seriesModel.coordinateSystem;
  47290. var seriesTooltipTrigger = seriesModel.get(['tooltip', 'trigger'], true);
  47291. var seriesTooltipShow = seriesModel.get(['tooltip', 'show'], true);
  47292. if (!coordSys || !coordSys.model // PENDING: radar do not have a model.
  47293. || seriesTooltipTrigger === 'none' || seriesTooltipTrigger === false || seriesTooltipTrigger === 'item' || seriesTooltipShow === false || seriesModel.get(['axisPointer', 'show'], true) === false) {
  47294. return;
  47295. }
  47296. each(result.coordSysAxesInfo[makeKey(coordSys.model)], function (axisInfo) {
  47297. var axis = axisInfo.axis;
  47298. if (coordSys.getAxis(axis.dim) === axis) {
  47299. axisInfo.seriesModels.push(seriesModel);
  47300. axisInfo.seriesDataCount == null && (axisInfo.seriesDataCount = 0);
  47301. axisInfo.seriesDataCount += seriesModel.getData().count();
  47302. }
  47303. });
  47304. });
  47305. }
  47306. /**
  47307. * For example:
  47308. * {
  47309. * axisPointer: {
  47310. * links: [{
  47311. * xAxisIndex: [2, 4],
  47312. * yAxisIndex: 'all'
  47313. * }, {
  47314. * xAxisId: ['a5', 'a7'],
  47315. * xAxisName: 'xxx'
  47316. * }]
  47317. * }
  47318. * }
  47319. */
  47320. function getLinkGroupIndex(linksOption, axis) {
  47321. var axisModel = axis.model;
  47322. var dim = axis.dim;
  47323. for (var i = 0; i < linksOption.length; i++) {
  47324. var linkOption = linksOption[i] || {};
  47325. if (checkPropInLink(linkOption[dim + 'AxisId'], axisModel.id) || checkPropInLink(linkOption[dim + 'AxisIndex'], axisModel.componentIndex) || checkPropInLink(linkOption[dim + 'AxisName'], axisModel.name)) {
  47326. return i;
  47327. }
  47328. }
  47329. }
  47330. function checkPropInLink(linkPropValue, axisPropValue) {
  47331. return linkPropValue === 'all' || isArray(linkPropValue) && indexOf(linkPropValue, axisPropValue) >= 0 || linkPropValue === axisPropValue;
  47332. }
  47333. function fixValue(axisModel) {
  47334. var axisInfo = getAxisInfo(axisModel);
  47335. if (!axisInfo) {
  47336. return;
  47337. }
  47338. var axisPointerModel = axisInfo.axisPointerModel;
  47339. var scale = axisInfo.axis.scale;
  47340. var option = axisPointerModel.option;
  47341. var status = axisPointerModel.get('status');
  47342. var value = axisPointerModel.get('value');
  47343. // Parse init value for category and time axis.
  47344. if (value != null) {
  47345. value = scale.parse(value);
  47346. }
  47347. var useHandle = isHandleTrigger(axisPointerModel);
  47348. // If `handle` used, `axisPointer` will always be displayed, so value
  47349. // and status should be initialized.
  47350. if (status == null) {
  47351. option.status = useHandle ? 'show' : 'hide';
  47352. }
  47353. var extent = scale.getExtent().slice();
  47354. extent[0] > extent[1] && extent.reverse();
  47355. if (
  47356. // Pick a value on axis when initializing.
  47357. value == null
  47358. // If both `handle` and `dataZoom` are used, value may be out of axis extent,
  47359. // where we should re-pick a value to keep `handle` displaying normally.
  47360. || value > extent[1]) {
  47361. // Make handle displayed on the end of the axis when init, which looks better.
  47362. value = extent[1];
  47363. }
  47364. if (value < extent[0]) {
  47365. value = extent[0];
  47366. }
  47367. option.value = value;
  47368. if (useHandle) {
  47369. option.status = axisInfo.axis.scale.isBlank() ? 'hide' : 'show';
  47370. }
  47371. }
  47372. function getAxisInfo(axisModel) {
  47373. var coordSysAxesInfo = (axisModel.ecModel.getComponent('axisPointer') || {}).coordSysAxesInfo;
  47374. return coordSysAxesInfo && coordSysAxesInfo.axesInfo[makeKey(axisModel)];
  47375. }
  47376. function getAxisPointerModel(axisModel) {
  47377. var axisInfo = getAxisInfo(axisModel);
  47378. return axisInfo && axisInfo.axisPointerModel;
  47379. }
  47380. function isHandleTrigger(axisPointerModel) {
  47381. return !!axisPointerModel.get(['handle', 'show']);
  47382. }
  47383. /**
  47384. * @param {module:echarts/model/Model} model
  47385. * @return {string} unique key
  47386. */
  47387. function makeKey(model) {
  47388. return model.type + '||' + model.id;
  47389. }
  47390. var axisPointerClazz = {};
  47391. /**
  47392. * Base class of AxisView.
  47393. */
  47394. var AxisView = /** @class */function (_super) {
  47395. __extends(AxisView, _super);
  47396. function AxisView() {
  47397. var _this = _super !== null && _super.apply(this, arguments) || this;
  47398. _this.type = AxisView.type;
  47399. return _this;
  47400. }
  47401. /**
  47402. * @override
  47403. */
  47404. AxisView.prototype.render = function (axisModel, ecModel, api, payload) {
  47405. // FIXME
  47406. // This process should proformed after coordinate systems updated
  47407. // (axis scale updated), and should be performed each time update.
  47408. // So put it here temporarily, although it is not appropriate to
  47409. // put a model-writing procedure in `view`.
  47410. this.axisPointerClass && fixValue(axisModel);
  47411. _super.prototype.render.apply(this, arguments);
  47412. this._doUpdateAxisPointerClass(axisModel, api, true);
  47413. };
  47414. /**
  47415. * Action handler.
  47416. */
  47417. AxisView.prototype.updateAxisPointer = function (axisModel, ecModel, api, payload) {
  47418. this._doUpdateAxisPointerClass(axisModel, api, false);
  47419. };
  47420. /**
  47421. * @override
  47422. */
  47423. AxisView.prototype.remove = function (ecModel, api) {
  47424. var axisPointer = this._axisPointer;
  47425. axisPointer && axisPointer.remove(api);
  47426. };
  47427. /**
  47428. * @override
  47429. */
  47430. AxisView.prototype.dispose = function (ecModel, api) {
  47431. this._disposeAxisPointer(api);
  47432. _super.prototype.dispose.apply(this, arguments);
  47433. };
  47434. AxisView.prototype._doUpdateAxisPointerClass = function (axisModel, api, forceRender) {
  47435. var Clazz = AxisView.getAxisPointerClass(this.axisPointerClass);
  47436. if (!Clazz) {
  47437. return;
  47438. }
  47439. var axisPointerModel = getAxisPointerModel(axisModel);
  47440. axisPointerModel ? (this._axisPointer || (this._axisPointer = new Clazz())).render(axisModel, axisPointerModel, api, forceRender) : this._disposeAxisPointer(api);
  47441. };
  47442. AxisView.prototype._disposeAxisPointer = function (api) {
  47443. this._axisPointer && this._axisPointer.dispose(api);
  47444. this._axisPointer = null;
  47445. };
  47446. AxisView.registerAxisPointerClass = function (type, clazz) {
  47447. if ("development" !== 'production') {
  47448. if (axisPointerClazz[type]) {
  47449. throw new Error('axisPointer ' + type + ' exists');
  47450. }
  47451. }
  47452. axisPointerClazz[type] = clazz;
  47453. };
  47454. AxisView.getAxisPointerClass = function (type) {
  47455. return type && axisPointerClazz[type];
  47456. };
  47457. AxisView.type = 'axis';
  47458. return AxisView;
  47459. }(ComponentView);
  47460. var inner$5 = makeInner();
  47461. function rectCoordAxisBuildSplitArea(axisView, axisGroup, axisModel, gridModel) {
  47462. var axis = axisModel.axis;
  47463. if (axis.scale.isBlank()) {
  47464. return;
  47465. }
  47466. // TODO: TYPE
  47467. var splitAreaModel = axisModel.getModel('splitArea');
  47468. var areaStyleModel = splitAreaModel.getModel('areaStyle');
  47469. var areaColors = areaStyleModel.get('color');
  47470. var gridRect = gridModel.coordinateSystem.getRect();
  47471. var ticksCoords = axis.getTicksCoords({
  47472. tickModel: splitAreaModel,
  47473. clamp: true,
  47474. breakTicks: 'none',
  47475. pruneByBreak: 'preserve_extent_bound'
  47476. });
  47477. if (!ticksCoords.length) {
  47478. return;
  47479. }
  47480. // For Making appropriate splitArea animation, the color and anid
  47481. // should be corresponding to previous one if possible.
  47482. var areaColorsLen = areaColors.length;
  47483. var lastSplitAreaColors = inner$5(axisView).splitAreaColors;
  47484. var newSplitAreaColors = createHashMap();
  47485. var colorIndex = 0;
  47486. if (lastSplitAreaColors) {
  47487. for (var i = 0; i < ticksCoords.length; i++) {
  47488. var cIndex = lastSplitAreaColors.get(ticksCoords[i].tickValue);
  47489. if (cIndex != null) {
  47490. colorIndex = (cIndex + (areaColorsLen - 1) * i) % areaColorsLen;
  47491. break;
  47492. }
  47493. }
  47494. }
  47495. var prev = axis.toGlobalCoord(ticksCoords[0].coord);
  47496. var areaStyle = areaStyleModel.getAreaStyle();
  47497. areaColors = isArray(areaColors) ? areaColors : [areaColors];
  47498. for (var i = 1; i < ticksCoords.length; i++) {
  47499. var tickCoord = axis.toGlobalCoord(ticksCoords[i].coord);
  47500. var x = void 0;
  47501. var y = void 0;
  47502. var width = void 0;
  47503. var height = void 0;
  47504. if (axis.isHorizontal()) {
  47505. x = prev;
  47506. y = gridRect.y;
  47507. width = tickCoord - x;
  47508. height = gridRect.height;
  47509. prev = x + width;
  47510. } else {
  47511. x = gridRect.x;
  47512. y = prev;
  47513. width = gridRect.width;
  47514. height = tickCoord - y;
  47515. prev = y + height;
  47516. }
  47517. var tickValue = ticksCoords[i - 1].tickValue;
  47518. tickValue != null && newSplitAreaColors.set(tickValue, colorIndex);
  47519. axisGroup.add(new Rect({
  47520. anid: tickValue != null ? 'area_' + tickValue : null,
  47521. shape: {
  47522. x: x,
  47523. y: y,
  47524. width: width,
  47525. height: height
  47526. },
  47527. style: defaults({
  47528. fill: areaColors[colorIndex]
  47529. }, areaStyle),
  47530. autoBatch: true,
  47531. silent: true
  47532. }));
  47533. colorIndex = (colorIndex + 1) % areaColorsLen;
  47534. }
  47535. inner$5(axisView).splitAreaColors = newSplitAreaColors;
  47536. }
  47537. function rectCoordAxisHandleRemove(axisView) {
  47538. inner$5(axisView).splitAreaColors = null;
  47539. }
  47540. var selfBuilderAttrs = ['splitArea', 'splitLine', 'minorSplitLine', 'breakArea'];
  47541. var CartesianAxisView = /** @class */function (_super) {
  47542. __extends(CartesianAxisView, _super);
  47543. function CartesianAxisView() {
  47544. var _this = _super !== null && _super.apply(this, arguments) || this;
  47545. _this.type = CartesianAxisView.type;
  47546. _this.axisPointerClass = 'CartesianAxisPointer';
  47547. return _this;
  47548. }
  47549. /**
  47550. * @override
  47551. */
  47552. CartesianAxisView.prototype.render = function (axisModel, ecModel, api, payload) {
  47553. this.group.removeAll();
  47554. var oldAxisGroup = this._axisGroup;
  47555. this._axisGroup = new Group();
  47556. this.group.add(this._axisGroup);
  47557. if (!shouldAxisShow(axisModel)) {
  47558. return;
  47559. }
  47560. this._axisGroup.add(axisModel.axis.axisBuilder.group);
  47561. each(selfBuilderAttrs, function (name) {
  47562. if (axisModel.get([name, 'show'])) {
  47563. axisElementBuilders[name](this, this._axisGroup, axisModel, axisModel.getCoordSysModel(), api);
  47564. }
  47565. }, this);
  47566. // THIS is a special case for bar racing chart.
  47567. // Update the axis label from the natural initial layout to
  47568. // sorted layout should has no animation.
  47569. var isInitialSortFromBarRacing = payload && payload.type === 'changeAxisOrder' && payload.isInitSort;
  47570. if (!isInitialSortFromBarRacing) {
  47571. groupTransition(oldAxisGroup, this._axisGroup, axisModel);
  47572. }
  47573. _super.prototype.render.call(this, axisModel, ecModel, api, payload);
  47574. };
  47575. CartesianAxisView.prototype.remove = function () {
  47576. rectCoordAxisHandleRemove(this);
  47577. };
  47578. CartesianAxisView.type = 'cartesianAxis';
  47579. return CartesianAxisView;
  47580. }(AxisView);
  47581. var axisElementBuilders = {
  47582. splitLine: function (axisView, axisGroup, axisModel, gridModel, api) {
  47583. var axis = axisModel.axis;
  47584. if (axis.scale.isBlank()) {
  47585. return;
  47586. }
  47587. var splitLineModel = axisModel.getModel('splitLine');
  47588. var lineStyleModel = splitLineModel.getModel('lineStyle');
  47589. var lineColors = lineStyleModel.get('color');
  47590. var showMinLine = splitLineModel.get('showMinLine') !== false;
  47591. var showMaxLine = splitLineModel.get('showMaxLine') !== false;
  47592. lineColors = isArray(lineColors) ? lineColors : [lineColors];
  47593. var gridRect = gridModel.coordinateSystem.getRect();
  47594. var isHorizontal = axis.isHorizontal();
  47595. var lineCount = 0;
  47596. var ticksCoords = axis.getTicksCoords({
  47597. tickModel: splitLineModel,
  47598. breakTicks: 'none',
  47599. pruneByBreak: 'preserve_extent_bound'
  47600. });
  47601. var p1 = [];
  47602. var p2 = [];
  47603. var lineStyle = lineStyleModel.getLineStyle();
  47604. for (var i = 0; i < ticksCoords.length; i++) {
  47605. var tickCoord = axis.toGlobalCoord(ticksCoords[i].coord);
  47606. if (i === 0 && !showMinLine || i === ticksCoords.length - 1 && !showMaxLine) {
  47607. continue;
  47608. }
  47609. var tickValue = ticksCoords[i].tickValue;
  47610. if (isHorizontal) {
  47611. p1[0] = tickCoord;
  47612. p1[1] = gridRect.y;
  47613. p2[0] = tickCoord;
  47614. p2[1] = gridRect.y + gridRect.height;
  47615. } else {
  47616. p1[0] = gridRect.x;
  47617. p1[1] = tickCoord;
  47618. p2[0] = gridRect.x + gridRect.width;
  47619. p2[1] = tickCoord;
  47620. }
  47621. var colorIndex = lineCount++ % lineColors.length;
  47622. var line = new Line({
  47623. anid: tickValue != null ? 'line_' + tickValue : null,
  47624. autoBatch: true,
  47625. shape: {
  47626. x1: p1[0],
  47627. y1: p1[1],
  47628. x2: p2[0],
  47629. y2: p2[1]
  47630. },
  47631. style: defaults({
  47632. stroke: lineColors[colorIndex]
  47633. }, lineStyle),
  47634. silent: true
  47635. });
  47636. subPixelOptimizeLine$1(line.shape, lineStyle.lineWidth);
  47637. axisGroup.add(line);
  47638. }
  47639. },
  47640. minorSplitLine: function (axisView, axisGroup, axisModel, gridModel, api) {
  47641. var axis = axisModel.axis;
  47642. var minorSplitLineModel = axisModel.getModel('minorSplitLine');
  47643. var lineStyleModel = minorSplitLineModel.getModel('lineStyle');
  47644. var gridRect = gridModel.coordinateSystem.getRect();
  47645. var isHorizontal = axis.isHorizontal();
  47646. var minorTicksCoords = axis.getMinorTicksCoords();
  47647. if (!minorTicksCoords.length) {
  47648. return;
  47649. }
  47650. var p1 = [];
  47651. var p2 = [];
  47652. var lineStyle = lineStyleModel.getLineStyle();
  47653. for (var i = 0; i < minorTicksCoords.length; i++) {
  47654. for (var k = 0; k < minorTicksCoords[i].length; k++) {
  47655. var tickCoord = axis.toGlobalCoord(minorTicksCoords[i][k].coord);
  47656. if (isHorizontal) {
  47657. p1[0] = tickCoord;
  47658. p1[1] = gridRect.y;
  47659. p2[0] = tickCoord;
  47660. p2[1] = gridRect.y + gridRect.height;
  47661. } else {
  47662. p1[0] = gridRect.x;
  47663. p1[1] = tickCoord;
  47664. p2[0] = gridRect.x + gridRect.width;
  47665. p2[1] = tickCoord;
  47666. }
  47667. var line = new Line({
  47668. anid: 'minor_line_' + minorTicksCoords[i][k].tickValue,
  47669. autoBatch: true,
  47670. shape: {
  47671. x1: p1[0],
  47672. y1: p1[1],
  47673. x2: p2[0],
  47674. y2: p2[1]
  47675. },
  47676. style: lineStyle,
  47677. silent: true
  47678. });
  47679. subPixelOptimizeLine$1(line.shape, lineStyle.lineWidth);
  47680. axisGroup.add(line);
  47681. }
  47682. }
  47683. },
  47684. splitArea: function (axisView, axisGroup, axisModel, gridModel, api) {
  47685. rectCoordAxisBuildSplitArea(axisView, axisGroup, axisModel, gridModel);
  47686. },
  47687. breakArea: function (axisView, axisGroup, axisModel, gridModel, api) {
  47688. var axisBreakHelper = getAxisBreakHelper();
  47689. var scale = axisModel.axis.scale;
  47690. if (axisBreakHelper && scale.type !== 'ordinal') {
  47691. axisBreakHelper.rectCoordBuildBreakAxis(axisGroup, axisView, axisModel, gridModel.coordinateSystem.getRect(), api);
  47692. }
  47693. }
  47694. };
  47695. var CartesianXAxisView = /** @class */function (_super) {
  47696. __extends(CartesianXAxisView, _super);
  47697. function CartesianXAxisView() {
  47698. var _this = _super !== null && _super.apply(this, arguments) || this;
  47699. _this.type = CartesianXAxisView.type;
  47700. return _this;
  47701. }
  47702. CartesianXAxisView.type = 'xAxis';
  47703. return CartesianXAxisView;
  47704. }(CartesianAxisView);
  47705. var CartesianYAxisView = /** @class */function (_super) {
  47706. __extends(CartesianYAxisView, _super);
  47707. function CartesianYAxisView() {
  47708. var _this = _super !== null && _super.apply(this, arguments) || this;
  47709. _this.type = CartesianXAxisView.type;
  47710. return _this;
  47711. }
  47712. CartesianYAxisView.type = 'yAxis';
  47713. return CartesianYAxisView;
  47714. }(CartesianAxisView);
  47715. // Grid view
  47716. var GridView = /** @class */function (_super) {
  47717. __extends(GridView, _super);
  47718. function GridView() {
  47719. var _this = _super !== null && _super.apply(this, arguments) || this;
  47720. _this.type = 'grid';
  47721. return _this;
  47722. }
  47723. GridView.prototype.render = function (gridModel, ecModel) {
  47724. this.group.removeAll();
  47725. if (gridModel.get('show')) {
  47726. this.group.add(new Rect({
  47727. shape: gridModel.coordinateSystem.getRect(),
  47728. style: defaults({
  47729. fill: gridModel.get('backgroundColor')
  47730. }, gridModel.getItemStyle()),
  47731. silent: true,
  47732. z2: -1
  47733. }));
  47734. }
  47735. };
  47736. GridView.type = 'grid';
  47737. return GridView;
  47738. }(ComponentView);
  47739. var extraOption = {
  47740. // gridIndex: 0,
  47741. // gridId: '',
  47742. offset: 0
  47743. };
  47744. function install$5(registers) {
  47745. registers.registerComponentView(GridView);
  47746. registers.registerComponentModel(GridModel);
  47747. registers.registerCoordinateSystem('cartesian2d', Grid);
  47748. axisModelCreator(registers, 'x', CartesianAxisModel, extraOption);
  47749. axisModelCreator(registers, 'y', CartesianAxisModel, extraOption);
  47750. registers.registerComponentView(CartesianXAxisView);
  47751. registers.registerComponentView(CartesianYAxisView);
  47752. registers.registerPreprocessor(function (option) {
  47753. // Only create grid when need
  47754. if (option.xAxis && option.yAxis && !option.grid) {
  47755. option.grid = {};
  47756. }
  47757. });
  47758. }
  47759. function needFixJitter(seriesModel, axis) {
  47760. var coordinateSystem = seriesModel.coordinateSystem;
  47761. var coordType = coordinateSystem && coordinateSystem.type;
  47762. var baseAxis = coordinateSystem && coordinateSystem.getBaseAxis && coordinateSystem.getBaseAxis();
  47763. var scaleType = baseAxis && baseAxis.scale && baseAxis.scale.type;
  47764. var seriesValid = coordType === 'cartesian2d' && scaleType === 'ordinal' || coordType === 'single';
  47765. var axisValid = axis.model.get('jitter') > 0;
  47766. return seriesValid && axisValid;
  47767. }
  47768. var inner$6 = makeInner();
  47769. /**
  47770. * Fix jitter for overlapping data points.
  47771. *
  47772. * @param fixedAxis The axis whose coord doesn't change with jitter.
  47773. * @param fixedCoord The coord of fixedAxis.
  47774. * @param floatCoord The coord of the other axis, which should be changed with jittering.
  47775. * @param radius The radius of the data point, considering the symbol is a circle.
  47776. * @returns updated floatCoord.
  47777. */
  47778. function fixJitter(fixedAxis, fixedCoord, floatCoord, radius) {
  47779. if (fixedAxis instanceof Axis2D) {
  47780. var scaleType = fixedAxis.scale.type;
  47781. if (scaleType !== 'category' && scaleType !== 'ordinal') {
  47782. return floatCoord;
  47783. }
  47784. }
  47785. var axisModel = fixedAxis.model;
  47786. var jitter = axisModel.get('jitter');
  47787. var jitterOverlap = axisModel.get('jitterOverlap');
  47788. var jitterMargin = axisModel.get('jitterMargin') || 0;
  47789. // Get band width to limit jitter range
  47790. var bandWidth = fixedAxis.scale.type === 'ordinal' ? fixedAxis.getBandWidth() : null;
  47791. if (jitter > 0) {
  47792. if (jitterOverlap) {
  47793. return fixJitterIgnoreOverlaps(floatCoord, jitter, bandWidth, radius);
  47794. } else {
  47795. return fixJitterAvoidOverlaps(fixedAxis, fixedCoord, floatCoord, radius, jitter, jitterMargin);
  47796. }
  47797. }
  47798. return floatCoord;
  47799. }
  47800. function fixJitterIgnoreOverlaps(floatCoord, jitter, bandWidth, radius) {
  47801. // Don't clamp single axis
  47802. if (bandWidth === null) {
  47803. return floatCoord + (Math.random() - 0.5) * jitter;
  47804. }
  47805. var maxJitter = bandWidth - radius * 2;
  47806. var actualJitter = Math.min(Math.max(0, jitter), maxJitter);
  47807. return floatCoord + (Math.random() - 0.5) * actualJitter;
  47808. }
  47809. function fixJitterAvoidOverlaps(fixedAxis, fixedCoord, floatCoord, radius, jitter, margin) {
  47810. var store = inner$6(fixedAxis);
  47811. if (!store.items) {
  47812. store.items = [];
  47813. }
  47814. var items = store.items;
  47815. // Try both positive and negative directions, choose the one with smaller movement
  47816. var overlapA = placeJitterOnDirection(items, fixedCoord, floatCoord, radius, jitter, margin, 1);
  47817. var overlapB = placeJitterOnDirection(items, fixedCoord, floatCoord, radius, jitter, margin, -1);
  47818. var minFloat = Math.abs(overlapA - floatCoord) < Math.abs(overlapB - floatCoord) ? overlapA : overlapB;
  47819. // Clamp only category axis
  47820. var bandWidth = fixedAxis.scale.type === 'ordinal' ? fixedAxis.getBandWidth() : null;
  47821. var distance = Math.abs(minFloat - floatCoord);
  47822. if (distance > jitter / 2 || bandWidth && distance > bandWidth / 2 - radius) {
  47823. // If the new item is moved too far, then give up.
  47824. // Fall back to random jitter.
  47825. return fixJitterIgnoreOverlaps(floatCoord, jitter, bandWidth, radius);
  47826. }
  47827. // Add new point to array
  47828. items.push({
  47829. fixedCoord: fixedCoord,
  47830. floatCoord: minFloat,
  47831. r: radius
  47832. });
  47833. return minFloat;
  47834. }
  47835. function placeJitterOnDirection(items, fixedCoord, floatCoord, radius, jitter, margin, direction) {
  47836. var y = floatCoord;
  47837. // Check all existing items for overlap and find the maximum adjustment needed
  47838. for (var i = 0; i < items.length; i++) {
  47839. var item = items[i];
  47840. var dx = fixedCoord - item.fixedCoord;
  47841. var dy = y - item.floatCoord;
  47842. var d2 = dx * dx + dy * dy;
  47843. var r = radius + item.r + margin;
  47844. if (d2 < r * r) {
  47845. // Has overlap, calculate required adjustment
  47846. var requiredY = item.floatCoord + Math.sqrt(r * r - dx * dx) * direction;
  47847. // Check if this adjustment would move too far
  47848. if (Math.abs(requiredY - floatCoord) > jitter / 2) {
  47849. return Number.MAX_VALUE; // Give up
  47850. }
  47851. // Update y only when it's larger to the center
  47852. if (direction === 1 && requiredY > y || direction === -1 && requiredY < y) {
  47853. y = requiredY;
  47854. // Loop from the start again
  47855. i = -1; // Reset index to recheck all items
  47856. continue; // Recalculate with the new y position
  47857. }
  47858. }
  47859. }
  47860. return y;
  47861. }
  47862. function jitterLayout(ecModel) {
  47863. ecModel.eachSeriesByType('scatter', function (seriesModel) {
  47864. var coordSys = seriesModel.coordinateSystem;
  47865. if (coordSys && (coordSys.type === 'cartesian2d' || coordSys.type === 'single')) {
  47866. var baseAxis_1 = coordSys.getBaseAxis ? coordSys.getBaseAxis() : null;
  47867. var hasJitter = baseAxis_1 && needFixJitter(seriesModel, baseAxis_1);
  47868. if (hasJitter) {
  47869. var data_1 = seriesModel.getData();
  47870. data_1.each(function (idx) {
  47871. var dim = baseAxis_1.dim;
  47872. var orient = baseAxis_1.orient;
  47873. var isSingleY = orient === 'horizontal' && baseAxis_1.type !== 'category' || orient === 'vertical' && baseAxis_1.type === 'category';
  47874. var layout = data_1.getItemLayout(idx);
  47875. var rawSize = data_1.getItemVisual(idx, 'symbolSize');
  47876. var size = rawSize instanceof Array ? (rawSize[1] + rawSize[0]) / 2 : rawSize;
  47877. if (dim === 'y' || dim === 'single' && isSingleY) {
  47878. // x is fixed, and y is floating
  47879. var jittered = fixJitter(baseAxis_1, layout[0], layout[1], size / 2);
  47880. data_1.setItemLayout(idx, [layout[0], jittered]);
  47881. } else if (dim === 'x' || dim === 'single' && !isSingleY) {
  47882. // y is fixed, and x is floating
  47883. var jittered = fixJitter(baseAxis_1, layout[1], layout[0], size / 2);
  47884. data_1.setItemLayout(idx, [jittered, layout[1]]);
  47885. }
  47886. });
  47887. }
  47888. }
  47889. });
  47890. }
  47891. function install$6(registers) {
  47892. // In case developer forget to include grid component
  47893. use(install$5);
  47894. registers.registerSeriesModel(ScatterSeriesModel);
  47895. registers.registerChartView(ScatterView);
  47896. registers.registerLayout(pointsLayout('scatter'));
  47897. }
  47898. function installScatterJitter(registers) {
  47899. registers.registerLayout(registers.PRIORITY.VISUAL.POST_CHART_LAYOUT, jitterLayout);
  47900. }
  47901. function radarLayout(ecModel) {
  47902. ecModel.eachSeriesByType('radar', function (seriesModel) {
  47903. var data = seriesModel.getData();
  47904. var points = [];
  47905. var coordSys = seriesModel.coordinateSystem;
  47906. if (!coordSys) {
  47907. return;
  47908. }
  47909. var axes = coordSys.getIndicatorAxes();
  47910. each(axes, function (axis, axisIndex) {
  47911. data.each(data.mapDimension(axes[axisIndex].dim), function (val, dataIndex) {
  47912. points[dataIndex] = points[dataIndex] || [];
  47913. var point = coordSys.dataToPoint(val, axisIndex);
  47914. points[dataIndex][axisIndex] = isValidPoint(point) ? point : getValueMissingPoint(coordSys);
  47915. });
  47916. });
  47917. // Close polygon
  47918. data.each(function (idx) {
  47919. // TODO
  47920. // Is it appropriate to connect to the next data when some data is missing?
  47921. // Or, should trade it like `connectNull` in line chart?
  47922. var firstPoint = find(points[idx], function (point) {
  47923. return isValidPoint(point);
  47924. }) || getValueMissingPoint(coordSys);
  47925. // Copy the first actual point to the end of the array
  47926. points[idx].push(firstPoint.slice());
  47927. data.setItemLayout(idx, points[idx]);
  47928. });
  47929. });
  47930. }
  47931. function isValidPoint(point) {
  47932. return !isNaN(point[0]) && !isNaN(point[1]);
  47933. }
  47934. function getValueMissingPoint(coordSys) {
  47935. // It is error-prone to input [NaN, NaN] into polygon, polygon.
  47936. // (probably cause problem when refreshing or animating)
  47937. return [coordSys.cx, coordSys.cy];
  47938. }
  47939. function radarBackwardCompat(option) {
  47940. var polarOptArr = option.polar;
  47941. if (polarOptArr) {
  47942. if (!isArray(polarOptArr)) {
  47943. polarOptArr = [polarOptArr];
  47944. }
  47945. var polarNotRadar_1 = [];
  47946. each(polarOptArr, function (polarOpt, idx) {
  47947. if (polarOpt.indicator) {
  47948. if (polarOpt.type && !polarOpt.shape) {
  47949. polarOpt.shape = polarOpt.type;
  47950. }
  47951. option.radar = option.radar || [];
  47952. if (!isArray(option.radar)) {
  47953. option.radar = [option.radar];
  47954. }
  47955. option.radar.push(polarOpt);
  47956. } else {
  47957. polarNotRadar_1.push(polarOpt);
  47958. }
  47959. });
  47960. option.polar = polarNotRadar_1;
  47961. }
  47962. each(option.series, function (seriesOpt) {
  47963. if (seriesOpt && seriesOpt.type === 'radar' && seriesOpt.polarIndex) {
  47964. seriesOpt.radarIndex = seriesOpt.polarIndex;
  47965. }
  47966. });
  47967. }
  47968. var RadarView = /** @class */function (_super) {
  47969. __extends(RadarView, _super);
  47970. function RadarView() {
  47971. var _this = _super !== null && _super.apply(this, arguments) || this;
  47972. _this.type = RadarView.type;
  47973. return _this;
  47974. }
  47975. RadarView.prototype.render = function (seriesModel, ecModel, api) {
  47976. var polar = seriesModel.coordinateSystem;
  47977. var group = this.group;
  47978. var data = seriesModel.getData();
  47979. var oldData = this._data;
  47980. function createSymbol$1(data, idx) {
  47981. var symbolType = data.getItemVisual(idx, 'symbol') || 'circle';
  47982. if (symbolType === 'none') {
  47983. return;
  47984. }
  47985. var symbolSize = normalizeSymbolSize(data.getItemVisual(idx, 'symbolSize'));
  47986. var symbolPath = createSymbol(symbolType, -1, -1, 2, 2);
  47987. var symbolRotate = data.getItemVisual(idx, 'symbolRotate') || 0;
  47988. symbolPath.attr({
  47989. style: {
  47990. strokeNoScale: true
  47991. },
  47992. z2: 100,
  47993. scaleX: symbolSize[0] / 2,
  47994. scaleY: symbolSize[1] / 2,
  47995. rotation: symbolRotate * Math.PI / 180 || 0
  47996. });
  47997. return symbolPath;
  47998. }
  47999. function updateSymbols(oldPoints, newPoints, symbolGroup, data, idx, isInit) {
  48000. // Simply rerender all
  48001. symbolGroup.removeAll();
  48002. for (var i = 0; i < newPoints.length - 1; i++) {
  48003. var symbolPath = createSymbol$1(data, idx);
  48004. if (symbolPath) {
  48005. symbolPath.__dimIdx = i;
  48006. if (oldPoints[i]) {
  48007. symbolPath.setPosition(oldPoints[i]);
  48008. graphic[isInit ? 'initProps' : 'updateProps'](symbolPath, {
  48009. x: newPoints[i][0],
  48010. y: newPoints[i][1]
  48011. }, seriesModel, idx);
  48012. } else {
  48013. symbolPath.setPosition(newPoints[i]);
  48014. }
  48015. symbolGroup.add(symbolPath);
  48016. }
  48017. }
  48018. }
  48019. function getInitialPoints(points) {
  48020. return map(points, function (pt) {
  48021. return [polar.cx, polar.cy];
  48022. });
  48023. }
  48024. data.diff(oldData).add(function (idx) {
  48025. var points = data.getItemLayout(idx);
  48026. if (!points) {
  48027. return;
  48028. }
  48029. var polygon = new Polygon();
  48030. var polyline = new Polyline();
  48031. var target = {
  48032. shape: {
  48033. points: points
  48034. }
  48035. };
  48036. polygon.shape.points = getInitialPoints(points);
  48037. polyline.shape.points = getInitialPoints(points);
  48038. initProps(polygon, target, seriesModel, idx);
  48039. initProps(polyline, target, seriesModel, idx);
  48040. var itemGroup = new Group();
  48041. var symbolGroup = new Group();
  48042. itemGroup.add(polyline);
  48043. itemGroup.add(polygon);
  48044. itemGroup.add(symbolGroup);
  48045. updateSymbols(polyline.shape.points, points, symbolGroup, data, idx, true);
  48046. data.setItemGraphicEl(idx, itemGroup);
  48047. }).update(function (newIdx, oldIdx) {
  48048. var itemGroup = oldData.getItemGraphicEl(oldIdx);
  48049. var polyline = itemGroup.childAt(0);
  48050. var polygon = itemGroup.childAt(1);
  48051. var symbolGroup = itemGroup.childAt(2);
  48052. var target = {
  48053. shape: {
  48054. points: data.getItemLayout(newIdx)
  48055. }
  48056. };
  48057. if (!target.shape.points) {
  48058. return;
  48059. }
  48060. updateSymbols(polyline.shape.points, target.shape.points, symbolGroup, data, newIdx, false);
  48061. saveOldStyle(polygon);
  48062. saveOldStyle(polyline);
  48063. updateProps(polyline, target, seriesModel);
  48064. updateProps(polygon, target, seriesModel);
  48065. data.setItemGraphicEl(newIdx, itemGroup);
  48066. }).remove(function (idx) {
  48067. group.remove(oldData.getItemGraphicEl(idx));
  48068. }).execute();
  48069. data.eachItemGraphicEl(function (itemGroup, idx) {
  48070. var itemModel = data.getItemModel(idx);
  48071. var polyline = itemGroup.childAt(0);
  48072. var polygon = itemGroup.childAt(1);
  48073. var symbolGroup = itemGroup.childAt(2);
  48074. // Radar uses the visual encoded from itemStyle.
  48075. var itemStyle = data.getItemVisual(idx, 'style');
  48076. var color = itemStyle.fill;
  48077. group.add(itemGroup);
  48078. polyline.useStyle(defaults(itemModel.getModel('lineStyle').getLineStyle(), {
  48079. fill: 'none',
  48080. stroke: color
  48081. }));
  48082. setStatesStylesFromModel(polyline, itemModel, 'lineStyle');
  48083. setStatesStylesFromModel(polygon, itemModel, 'areaStyle');
  48084. var areaStyleModel = itemModel.getModel('areaStyle');
  48085. var polygonIgnore = areaStyleModel.isEmpty() && areaStyleModel.parentModel.isEmpty();
  48086. polygon.ignore = polygonIgnore;
  48087. each(['emphasis', 'select', 'blur'], function (stateName) {
  48088. var stateModel = itemModel.getModel([stateName, 'areaStyle']);
  48089. var stateIgnore = stateModel.isEmpty() && stateModel.parentModel.isEmpty();
  48090. // Won't be ignore if normal state is not ignore.
  48091. polygon.ensureState(stateName).ignore = stateIgnore && polygonIgnore;
  48092. var lineStyle = itemModel.getModel([stateName, 'lineStyle']).getLineStyle();
  48093. polyline.ensureState(stateName).style = lineStyle;
  48094. var areaStyle = stateModel.getAreaStyle();
  48095. polygon.ensureState(stateName).style = areaStyle;
  48096. var itemStateStyle = itemModel.getModel([stateName, 'itemStyle']).getItemStyle();
  48097. symbolGroup.eachChild(function (symbolPath) {
  48098. symbolPath.ensureState(stateName).style = clone(itemStateStyle);
  48099. });
  48100. });
  48101. polygon.useStyle(defaults(itemModel.getModel('areaStyle').getAreaStyle(), {
  48102. fill: color,
  48103. opacity: 0.7,
  48104. decal: itemStyle.decal
  48105. }));
  48106. var emphasisModel = itemModel.getModel('emphasis');
  48107. symbolGroup.eachChild(function (symbolPath) {
  48108. if (symbolPath instanceof ZRImage) {
  48109. var pathStyle = symbolPath.style;
  48110. symbolPath.useStyle(extend({
  48111. // TODO other properties like x, y ?
  48112. image: pathStyle.image,
  48113. x: pathStyle.x,
  48114. y: pathStyle.y,
  48115. width: pathStyle.width,
  48116. height: pathStyle.height
  48117. }, itemStyle));
  48118. } else {
  48119. symbolPath.useStyle(itemStyle);
  48120. symbolPath.setColor(color);
  48121. symbolPath.style.strokeNoScale = true;
  48122. }
  48123. var defaultText = data.getStore().get(data.getDimensionIndex(symbolPath.__dimIdx), idx);
  48124. (defaultText == null || isNaN(defaultText)) && (defaultText = '');
  48125. setLabelStyle(symbolPath, getLabelStatesModels(itemModel), {
  48126. labelFetcher: data.hostModel,
  48127. labelDataIndex: idx,
  48128. labelDimIndex: symbolPath.__dimIdx,
  48129. defaultText: defaultText,
  48130. inheritColor: color,
  48131. defaultOpacity: itemStyle.opacity
  48132. });
  48133. });
  48134. toggleHoverEmphasis(itemGroup, emphasisModel.get('focus'), emphasisModel.get('blurScope'), emphasisModel.get('disabled'));
  48135. });
  48136. this._data = data;
  48137. };
  48138. RadarView.prototype.remove = function () {
  48139. this.group.removeAll();
  48140. this._data = null;
  48141. };
  48142. RadarView.type = 'radar';
  48143. return RadarView;
  48144. }(ChartView);
  48145. var RadarSeriesModel = /** @class */function (_super) {
  48146. __extends(RadarSeriesModel, _super);
  48147. function RadarSeriesModel() {
  48148. var _this = _super !== null && _super.apply(this, arguments) || this;
  48149. _this.type = RadarSeriesModel.type;
  48150. _this.hasSymbolVisual = true;
  48151. return _this;
  48152. }
  48153. // Overwrite
  48154. RadarSeriesModel.prototype.init = function (option) {
  48155. _super.prototype.init.apply(this, arguments);
  48156. // Enable legend selection for each data item
  48157. // Use a function instead of direct access because data reference may changed
  48158. this.legendVisualProvider = new LegendVisualProvider(bind(this.getData, this), bind(this.getRawData, this));
  48159. };
  48160. RadarSeriesModel.prototype.getInitialData = function (option, ecModel) {
  48161. return createSeriesDataSimply(this, {
  48162. generateCoord: 'indicator_',
  48163. generateCoordCount: Infinity
  48164. });
  48165. };
  48166. RadarSeriesModel.prototype.formatTooltip = function (dataIndex, multipleSeries, dataType) {
  48167. var data = this.getData();
  48168. var coordSys = this.coordinateSystem;
  48169. var indicatorAxes = coordSys.getIndicatorAxes();
  48170. var name = this.getData().getName(dataIndex);
  48171. var nameToDisplay = name === '' ? this.name : name;
  48172. var markerColor = retrieveVisualColorForTooltipMarker(this, dataIndex);
  48173. return createTooltipMarkup('section', {
  48174. header: nameToDisplay,
  48175. sortBlocks: true,
  48176. blocks: map(indicatorAxes, function (axis) {
  48177. var val = data.get(data.mapDimension(axis.dim), dataIndex);
  48178. return createTooltipMarkup('nameValue', {
  48179. markerType: 'subItem',
  48180. markerColor: markerColor,
  48181. name: axis.name,
  48182. value: val,
  48183. sortParam: val
  48184. });
  48185. })
  48186. });
  48187. };
  48188. RadarSeriesModel.prototype.getTooltipPosition = function (dataIndex) {
  48189. if (dataIndex != null) {
  48190. var data_1 = this.getData();
  48191. var coordSys = this.coordinateSystem;
  48192. var values = data_1.getValues(map(coordSys.dimensions, function (dim) {
  48193. return data_1.mapDimension(dim);
  48194. }), dataIndex);
  48195. for (var i = 0, len = values.length; i < len; i++) {
  48196. if (!isNaN(values[i])) {
  48197. var indicatorAxes = coordSys.getIndicatorAxes();
  48198. return coordSys.coordToPoint(indicatorAxes[i].dataToCoord(values[i]), i);
  48199. }
  48200. }
  48201. }
  48202. };
  48203. RadarSeriesModel.type = 'series.radar';
  48204. RadarSeriesModel.dependencies = ['radar'];
  48205. RadarSeriesModel.defaultOption = {
  48206. // zlevel: 0,
  48207. z: 2,
  48208. colorBy: 'data',
  48209. coordinateSystem: 'radar',
  48210. legendHoverLink: true,
  48211. radarIndex: 0,
  48212. lineStyle: {
  48213. width: 2,
  48214. type: 'solid',
  48215. join: 'round'
  48216. },
  48217. label: {
  48218. position: 'top'
  48219. },
  48220. // areaStyle: {
  48221. // },
  48222. // itemStyle: {}
  48223. symbolSize: 8
  48224. // symbolRotate: null
  48225. };
  48226. return RadarSeriesModel;
  48227. }(SeriesModel);
  48228. var valueAxisDefault = axisDefault.value;
  48229. function defaultsShow(opt, show) {
  48230. return defaults({
  48231. show: show
  48232. }, opt);
  48233. }
  48234. var RadarModel = /** @class */function (_super) {
  48235. __extends(RadarModel, _super);
  48236. function RadarModel() {
  48237. var _this = _super !== null && _super.apply(this, arguments) || this;
  48238. _this.type = RadarModel.type;
  48239. return _this;
  48240. }
  48241. RadarModel.prototype.optionUpdated = function () {
  48242. var boundaryGap = this.get('boundaryGap');
  48243. var splitNumber = this.get('splitNumber');
  48244. var scale = this.get('scale');
  48245. var axisLine = this.get('axisLine');
  48246. var axisTick = this.get('axisTick');
  48247. // let axisType = this.get('axisType');
  48248. var axisLabel = this.get('axisLabel');
  48249. var nameTextStyle = this.get('axisName');
  48250. var showName = this.get(['axisName', 'show']);
  48251. var nameFormatter = this.get(['axisName', 'formatter']);
  48252. var nameGap = this.get('axisNameGap');
  48253. var triggerEvent = this.get('triggerEvent');
  48254. var indicatorModels = map(this.get('indicator') || [], function (indicatorOpt) {
  48255. // PENDING
  48256. if (indicatorOpt.max != null && indicatorOpt.max > 0 && !indicatorOpt.min) {
  48257. indicatorOpt.min = 0;
  48258. } else if (indicatorOpt.min != null && indicatorOpt.min < 0 && !indicatorOpt.max) {
  48259. indicatorOpt.max = 0;
  48260. }
  48261. var iNameTextStyle = nameTextStyle;
  48262. if (indicatorOpt.color != null) {
  48263. iNameTextStyle = defaults({
  48264. color: indicatorOpt.color
  48265. }, nameTextStyle);
  48266. }
  48267. // Use same configuration
  48268. var innerIndicatorOpt = merge(clone(indicatorOpt), {
  48269. boundaryGap: boundaryGap,
  48270. splitNumber: splitNumber,
  48271. scale: scale,
  48272. axisLine: axisLine,
  48273. axisTick: axisTick,
  48274. // axisType: axisType,
  48275. axisLabel: axisLabel,
  48276. // Compatible with 2 and use text
  48277. name: indicatorOpt.text,
  48278. showName: showName,
  48279. nameLocation: 'end',
  48280. nameGap: nameGap,
  48281. // min: 0,
  48282. nameTextStyle: iNameTextStyle,
  48283. triggerEvent: triggerEvent
  48284. }, false);
  48285. if (isString(nameFormatter)) {
  48286. var indName = innerIndicatorOpt.name;
  48287. innerIndicatorOpt.name = nameFormatter.replace('{value}', indName != null ? indName : '');
  48288. } else if (isFunction(nameFormatter)) {
  48289. innerIndicatorOpt.name = nameFormatter(innerIndicatorOpt.name, innerIndicatorOpt);
  48290. }
  48291. var model = new Model(innerIndicatorOpt, null, this.ecModel);
  48292. mixin(model, AxisModelCommonMixin.prototype);
  48293. // For triggerEvent.
  48294. model.mainType = 'radar';
  48295. model.componentIndex = this.componentIndex;
  48296. return model;
  48297. }, this);
  48298. this._indicatorModels = indicatorModels;
  48299. };
  48300. RadarModel.prototype.getIndicatorModels = function () {
  48301. return this._indicatorModels;
  48302. };
  48303. RadarModel.type = 'radar';
  48304. RadarModel.defaultOption = {
  48305. // zlevel: 0,
  48306. z: 0,
  48307. center: ['50%', '50%'],
  48308. radius: '50%',
  48309. startAngle: 90,
  48310. axisName: {
  48311. show: true,
  48312. color: tokens.color.axisLabel
  48313. // formatter: null
  48314. // textStyle: {}
  48315. },
  48316. boundaryGap: [0, 0],
  48317. splitNumber: 5,
  48318. axisNameGap: 15,
  48319. scale: false,
  48320. // Polygon or circle
  48321. shape: 'polygon',
  48322. axisLine: merge({
  48323. lineStyle: {
  48324. color: tokens.color.neutral20
  48325. }
  48326. }, valueAxisDefault.axisLine),
  48327. axisLabel: defaultsShow(valueAxisDefault.axisLabel, false),
  48328. axisTick: defaultsShow(valueAxisDefault.axisTick, false),
  48329. // axisType: 'value',
  48330. splitLine: defaultsShow(valueAxisDefault.splitLine, true),
  48331. splitArea: defaultsShow(valueAxisDefault.splitArea, true),
  48332. // {text, min, max}
  48333. indicator: []
  48334. };
  48335. return RadarModel;
  48336. }(ComponentModel);
  48337. var RadarView$1 = /** @class */function (_super) {
  48338. __extends(RadarView, _super);
  48339. function RadarView() {
  48340. var _this = _super !== null && _super.apply(this, arguments) || this;
  48341. _this.type = RadarView.type;
  48342. return _this;
  48343. }
  48344. RadarView.prototype.render = function (radarModel, ecModel, api) {
  48345. var group = this.group;
  48346. group.removeAll();
  48347. this._buildAxes(radarModel, api);
  48348. this._buildSplitLineAndArea(radarModel);
  48349. };
  48350. RadarView.prototype._buildAxes = function (radarModel, api) {
  48351. var radar = radarModel.coordinateSystem;
  48352. var indicatorAxes = radar.getIndicatorAxes();
  48353. var axisBuilders = map(indicatorAxes, function (indicatorAxis) {
  48354. var axisName = indicatorAxis.model.get('showName') ? indicatorAxis.name : ''; // hide name
  48355. var axisBuilder = new AxisBuilder(indicatorAxis.model, api, {
  48356. axisName: axisName,
  48357. position: [radar.cx, radar.cy],
  48358. rotation: indicatorAxis.angle,
  48359. labelDirection: -1,
  48360. tickDirection: -1,
  48361. nameDirection: 1
  48362. });
  48363. return axisBuilder;
  48364. });
  48365. each(axisBuilders, function (axisBuilder) {
  48366. axisBuilder.build();
  48367. this.group.add(axisBuilder.group);
  48368. }, this);
  48369. };
  48370. RadarView.prototype._buildSplitLineAndArea = function (radarModel) {
  48371. var radar = radarModel.coordinateSystem;
  48372. var indicatorAxes = radar.getIndicatorAxes();
  48373. if (!indicatorAxes.length) {
  48374. return;
  48375. }
  48376. var shape = radarModel.get('shape');
  48377. var splitLineModel = radarModel.getModel('splitLine');
  48378. var splitAreaModel = radarModel.getModel('splitArea');
  48379. var lineStyleModel = splitLineModel.getModel('lineStyle');
  48380. var areaStyleModel = splitAreaModel.getModel('areaStyle');
  48381. var showSplitLine = splitLineModel.get('show');
  48382. var showSplitArea = splitAreaModel.get('show');
  48383. var splitLineColors = lineStyleModel.get('color');
  48384. var splitAreaColors = areaStyleModel.get('color');
  48385. var splitLineColorsArr = isArray(splitLineColors) ? splitLineColors : [splitLineColors];
  48386. var splitAreaColorsArr = isArray(splitAreaColors) ? splitAreaColors : [splitAreaColors];
  48387. var splitLines = [];
  48388. var splitAreas = [];
  48389. function getColorIndex(areaOrLine, areaOrLineColorList, idx) {
  48390. var colorIndex = idx % areaOrLineColorList.length;
  48391. areaOrLine[colorIndex] = areaOrLine[colorIndex] || [];
  48392. return colorIndex;
  48393. }
  48394. if (shape === 'circle') {
  48395. var ticksRadius = indicatorAxes[0].getTicksCoords();
  48396. var cx = radar.cx;
  48397. var cy = radar.cy;
  48398. for (var i = 0; i < ticksRadius.length; i++) {
  48399. if (showSplitLine) {
  48400. var colorIndex = getColorIndex(splitLines, splitLineColorsArr, i);
  48401. splitLines[colorIndex].push(new Circle({
  48402. shape: {
  48403. cx: cx,
  48404. cy: cy,
  48405. r: ticksRadius[i].coord
  48406. }
  48407. }));
  48408. }
  48409. if (showSplitArea && i < ticksRadius.length - 1) {
  48410. var colorIndex = getColorIndex(splitAreas, splitAreaColorsArr, i);
  48411. splitAreas[colorIndex].push(new Ring({
  48412. shape: {
  48413. cx: cx,
  48414. cy: cy,
  48415. r0: ticksRadius[i].coord,
  48416. r: ticksRadius[i + 1].coord
  48417. }
  48418. }));
  48419. }
  48420. }
  48421. }
  48422. // Polyyon
  48423. else {
  48424. var realSplitNumber_1;
  48425. var axesTicksPoints = map(indicatorAxes, function (indicatorAxis, idx) {
  48426. var ticksCoords = indicatorAxis.getTicksCoords();
  48427. realSplitNumber_1 = realSplitNumber_1 == null ? ticksCoords.length - 1 : Math.min(ticksCoords.length - 1, realSplitNumber_1);
  48428. return map(ticksCoords, function (tickCoord) {
  48429. return radar.coordToPoint(tickCoord.coord, idx);
  48430. });
  48431. });
  48432. var prevPoints = [];
  48433. for (var i = 0; i <= realSplitNumber_1; i++) {
  48434. var points = [];
  48435. for (var j = 0; j < indicatorAxes.length; j++) {
  48436. points.push(axesTicksPoints[j][i]);
  48437. }
  48438. // Close
  48439. if (points[0]) {
  48440. points.push(points[0].slice());
  48441. } else {
  48442. if ("development" !== 'production') {
  48443. console.error('Can\'t draw value axis ' + i);
  48444. }
  48445. }
  48446. if (showSplitLine) {
  48447. var colorIndex = getColorIndex(splitLines, splitLineColorsArr, i);
  48448. splitLines[colorIndex].push(new Polyline({
  48449. shape: {
  48450. points: points
  48451. }
  48452. }));
  48453. }
  48454. if (showSplitArea && prevPoints) {
  48455. var colorIndex = getColorIndex(splitAreas, splitAreaColorsArr, i - 1);
  48456. splitAreas[colorIndex].push(new Polygon({
  48457. shape: {
  48458. points: points.concat(prevPoints)
  48459. }
  48460. }));
  48461. }
  48462. prevPoints = points.slice().reverse();
  48463. }
  48464. }
  48465. var lineStyle = lineStyleModel.getLineStyle();
  48466. var areaStyle = areaStyleModel.getAreaStyle();
  48467. // Add splitArea before splitLine
  48468. each(splitAreas, function (splitAreas, idx) {
  48469. this.group.add(mergePath$1(splitAreas, {
  48470. style: defaults({
  48471. stroke: 'none',
  48472. fill: splitAreaColorsArr[idx % splitAreaColorsArr.length]
  48473. }, areaStyle),
  48474. silent: true
  48475. }));
  48476. }, this);
  48477. each(splitLines, function (splitLines, idx) {
  48478. this.group.add(mergePath$1(splitLines, {
  48479. style: defaults({
  48480. fill: 'none',
  48481. stroke: splitLineColorsArr[idx % splitLineColorsArr.length]
  48482. }, lineStyle),
  48483. silent: true
  48484. }));
  48485. }, this);
  48486. };
  48487. RadarView.type = 'radar';
  48488. return RadarView;
  48489. }(ComponentView);
  48490. var IndicatorAxis = /** @class */function (_super) {
  48491. __extends(IndicatorAxis, _super);
  48492. function IndicatorAxis(dim, scale, radiusExtent) {
  48493. var _this = _super.call(this, dim, scale, radiusExtent) || this;
  48494. _this.type = 'value';
  48495. _this.angle = 0;
  48496. _this.name = '';
  48497. return _this;
  48498. }
  48499. return IndicatorAxis;
  48500. }(Axis);
  48501. var Radar = /** @class */function () {
  48502. function Radar(radarModel, ecModel, api) {
  48503. /**
  48504. *
  48505. * Radar dimensions
  48506. */
  48507. this.dimensions = [];
  48508. this._model = radarModel;
  48509. this._indicatorAxes = map(radarModel.getIndicatorModels(), function (indicatorModel, idx) {
  48510. var dim = 'indicator_' + idx;
  48511. var indicatorAxis = new IndicatorAxis(dim, new IntervalScale()
  48512. // (indicatorModel.get('axisType') === 'log') ? new LogScale() : new IntervalScale()
  48513. );
  48514. indicatorAxis.name = indicatorModel.get('name');
  48515. // Inject model and axis
  48516. indicatorAxis.model = indicatorModel;
  48517. indicatorModel.axis = indicatorAxis;
  48518. this.dimensions.push(dim);
  48519. return indicatorAxis;
  48520. }, this);
  48521. this.resize(radarModel, api);
  48522. }
  48523. Radar.prototype.getIndicatorAxes = function () {
  48524. return this._indicatorAxes;
  48525. };
  48526. Radar.prototype.dataToPoint = function (value, indicatorIndex) {
  48527. var indicatorAxis = this._indicatorAxes[indicatorIndex];
  48528. return this.coordToPoint(indicatorAxis.dataToCoord(value), indicatorIndex);
  48529. };
  48530. // TODO: API should be coordToPoint([coord, indicatorIndex])
  48531. Radar.prototype.coordToPoint = function (coord, indicatorIndex) {
  48532. var indicatorAxis = this._indicatorAxes[indicatorIndex];
  48533. var angle = indicatorAxis.angle;
  48534. var x = this.cx + coord * Math.cos(angle);
  48535. var y = this.cy - coord * Math.sin(angle);
  48536. return [x, y];
  48537. };
  48538. Radar.prototype.pointToData = function (pt) {
  48539. var dx = pt[0] - this.cx;
  48540. var dy = pt[1] - this.cy;
  48541. var radius = Math.sqrt(dx * dx + dy * dy);
  48542. dx /= radius;
  48543. dy /= radius;
  48544. var radian = Math.atan2(-dy, dx);
  48545. // Find the closest angle
  48546. // FIXME index can calculated directly
  48547. var minRadianDiff = Infinity;
  48548. var closestAxis;
  48549. var closestAxisIdx = -1;
  48550. for (var i = 0; i < this._indicatorAxes.length; i++) {
  48551. var indicatorAxis = this._indicatorAxes[i];
  48552. var diff = Math.abs(radian - indicatorAxis.angle);
  48553. if (diff < minRadianDiff) {
  48554. closestAxis = indicatorAxis;
  48555. closestAxisIdx = i;
  48556. minRadianDiff = diff;
  48557. }
  48558. }
  48559. return [closestAxisIdx, +(closestAxis && closestAxis.coordToData(radius))];
  48560. };
  48561. Radar.prototype.resize = function (radarModel, api) {
  48562. var refContainer = createBoxLayoutReference(radarModel, api).refContainer;
  48563. var center = radarModel.get('center');
  48564. var viewSize = Math.min(refContainer.width, refContainer.height) / 2;
  48565. this.cx = parsePercent$1(center[0], refContainer.width) + refContainer.x;
  48566. this.cy = parsePercent$1(center[1], refContainer.height) + refContainer.y;
  48567. this.startAngle = radarModel.get('startAngle') * Math.PI / 180;
  48568. // radius may be single value like `20`, `'80%'`, or array like `[10, '80%']`
  48569. var radius = radarModel.get('radius');
  48570. if (isString(radius) || isNumber(radius)) {
  48571. radius = [0, radius];
  48572. }
  48573. this.r0 = parsePercent$1(radius[0], viewSize);
  48574. this.r = parsePercent$1(radius[1], viewSize);
  48575. each(this._indicatorAxes, function (indicatorAxis, idx) {
  48576. indicatorAxis.setExtent(this.r0, this.r);
  48577. var angle = this.startAngle + idx * Math.PI * 2 / this._indicatorAxes.length;
  48578. // Normalize to [-PI, PI]
  48579. angle = Math.atan2(Math.sin(angle), Math.cos(angle));
  48580. indicatorAxis.angle = angle;
  48581. }, this);
  48582. };
  48583. Radar.prototype.update = function (ecModel, api) {
  48584. var indicatorAxes = this._indicatorAxes;
  48585. var radarModel = this._model;
  48586. each(indicatorAxes, function (indicatorAxis) {
  48587. indicatorAxis.scale.setExtent(Infinity, -Infinity);
  48588. });
  48589. ecModel.eachSeriesByType('radar', function (radarSeries, idx) {
  48590. if (radarSeries.get('coordinateSystem') !== 'radar'
  48591. // @ts-ignore
  48592. || ecModel.getComponent('radar', radarSeries.get('radarIndex')) !== radarModel) {
  48593. return;
  48594. }
  48595. var data = radarSeries.getData();
  48596. each(indicatorAxes, function (indicatorAxis) {
  48597. indicatorAxis.scale.unionExtentFromData(data, data.mapDimension(indicatorAxis.dim));
  48598. });
  48599. }, this);
  48600. var splitNumber = radarModel.get('splitNumber');
  48601. var dummyScale = new IntervalScale();
  48602. dummyScale.setExtent(0, splitNumber);
  48603. dummyScale.setInterval(1);
  48604. // Force all the axis fixing the maxSplitNumber.
  48605. each(indicatorAxes, function (indicatorAxis, idx) {
  48606. alignScaleTicks(indicatorAxis.scale, indicatorAxis.model, dummyScale);
  48607. });
  48608. };
  48609. Radar.prototype.convertToPixel = function (ecModel, finder, value) {
  48610. console.warn('Not implemented.');
  48611. return null;
  48612. };
  48613. Radar.prototype.convertFromPixel = function (ecModel, finder, pixel) {
  48614. console.warn('Not implemented.');
  48615. return null;
  48616. };
  48617. Radar.prototype.containPoint = function (point) {
  48618. console.warn('Not implemented.');
  48619. return false;
  48620. };
  48621. Radar.create = function (ecModel, api) {
  48622. var radarList = [];
  48623. ecModel.eachComponent('radar', function (radarModel) {
  48624. var radar = new Radar(radarModel, ecModel, api);
  48625. radarList.push(radar);
  48626. radarModel.coordinateSystem = radar;
  48627. });
  48628. ecModel.eachSeriesByType('radar', function (radarSeries) {
  48629. if (radarSeries.get('coordinateSystem') === 'radar') {
  48630. // Inject coordinate system
  48631. // @ts-ignore
  48632. radarSeries.coordinateSystem = radarList[radarSeries.get('radarIndex') || 0];
  48633. }
  48634. });
  48635. return radarList;
  48636. };
  48637. /**
  48638. * Radar dimensions is based on the data
  48639. */
  48640. Radar.dimensions = [];
  48641. return Radar;
  48642. }();
  48643. function install$7(registers) {
  48644. registers.registerCoordinateSystem('radar', Radar);
  48645. registers.registerComponentModel(RadarModel);
  48646. registers.registerComponentView(RadarView$1);
  48647. registers.registerVisual({
  48648. seriesType: 'radar',
  48649. reset: function (seriesModel) {
  48650. var data = seriesModel.getData();
  48651. // itemVisual symbol is for selected data
  48652. data.each(function (idx) {
  48653. data.setItemVisual(idx, 'legendIcon', 'roundRect');
  48654. });
  48655. // visual is for unselected data
  48656. data.setVisual('legendIcon', 'roundRect');
  48657. }
  48658. });
  48659. }
  48660. function install$8(registers) {
  48661. use(install$7);
  48662. registers.registerChartView(RadarView);
  48663. registers.registerSeriesModel(RadarSeriesModel);
  48664. registers.registerLayout(radarLayout);
  48665. registers.registerProcessor(dataFilter('radar'));
  48666. registers.registerPreprocessor(radarBackwardCompat);
  48667. }
  48668. var inner$7 = makeInner();
  48669. function take(zr, resourceKey, userKey) {
  48670. inner$7(zr)[resourceKey] = userKey;
  48671. }
  48672. function release(zr, resourceKey, userKey) {
  48673. var store = inner$7(zr);
  48674. var uKey = store[resourceKey];
  48675. if (uKey === userKey) {
  48676. store[resourceKey] = null;
  48677. }
  48678. }
  48679. function isTaken(zr, resourceKey) {
  48680. return !!inner$7(zr)[resourceKey];
  48681. }
  48682. /**
  48683. * payload: {
  48684. * type: 'takeGlobalCursor',
  48685. * key: 'dataZoomSelect', or 'brush', or ...,
  48686. * If no userKey, release global cursor.
  48687. * }
  48688. */
  48689. // TODO: SELF REGISTERED.
  48690. registerAction({
  48691. type: 'takeGlobalCursor',
  48692. event: 'globalCursorTaken',
  48693. update: 'update'
  48694. }, noop);
  48695. var IRRELEVANT_EXCLUDES = {
  48696. 'axisPointer': 1,
  48697. 'tooltip': 1,
  48698. 'brush': 1
  48699. };
  48700. /**
  48701. * Used on roam/brush triggering determination.
  48702. * This is to avoid that: mouse clicking on an elements that is over geo or graph,
  48703. * but roam is triggered unexpectedly.
  48704. */
  48705. function onIrrelevantElement(e, api, targetComponent) {
  48706. var eventElComponent = api.getComponentByElement(e.topTarget);
  48707. if (!eventElComponent || eventElComponent === targetComponent || IRRELEVANT_EXCLUDES.hasOwnProperty(eventElComponent.mainType)) {
  48708. return false;
  48709. }
  48710. // At present the `true` return is conservative. That is, the caller, such as a RoamController,
  48711. // is more likely to get a `false` return and start a roam behavior, becuase even if the
  48712. // `model.coordinateSystem` does not exist, the `e.topTarget` may be also a relevant element,
  48713. // such as axis split line/area or series elements, where roam should be available. Otherwise,
  48714. // if a dataZoom-served cartesian is full of series elements, the dataZoom-roaming can hardly
  48715. // be triggered.
  48716. var eventElCoordSys = eventElComponent.coordinateSystem;
  48717. // If eventElComponent is axisModel, it works only if it is injected with coordinateSystem.
  48718. if (!eventElCoordSys || eventElCoordSys.model === targetComponent) {
  48719. return false;
  48720. }
  48721. // e.g., if a cartesian is covered by a graph, the graph has a higher presedence in roam.
  48722. // A potential bad case is that RoamController does not prevent the cartesian from handling zr
  48723. // event, such as click and hovering, but it's fine so far.
  48724. // Aslo be conservative, if equals, return false.
  48725. var eventElCmptZInfo = retrieveZInfo(eventElComponent);
  48726. var targetCmptZInfo = retrieveZInfo(targetComponent);
  48727. if ((eventElCmptZInfo.zlevel - targetCmptZInfo.zlevel || eventElCmptZInfo.z - targetCmptZInfo.z) <= 0) {
  48728. return false;
  48729. }
  48730. return true;
  48731. }
  48732. /**
  48733. * An manager of zoom and pan(darg) hehavior.
  48734. * But it is not responsible for updating the view, since view updates vary and can
  48735. * not be handled in a uniform way.
  48736. *
  48737. * Note: regarding view updates:
  48738. * - Transformabe views typically use `coord/View` (e.g., geo and series.graph roaming).
  48739. * Some commonly used view update logic has been organized into `roamHelper.ts`.
  48740. * - Non-transformable views handle updates themselves, possibly involving re-layout,
  48741. * (e.g., treemap).
  48742. * - Some scenarios do not require transformation (e.g., dataZoom roaming for cartesian,
  48743. * brush component).
  48744. */
  48745. var RoamController = /** @class */function (_super) {
  48746. __extends(RoamController, _super);
  48747. function RoamController(zr) {
  48748. var _this = _super.call(this) || this;
  48749. _this._zr = zr;
  48750. // Avoid two roamController bind the same handler
  48751. var mousedownHandler = bind(_this._mousedownHandler, _this);
  48752. var mousemoveHandler = bind(_this._mousemoveHandler, _this);
  48753. var mouseupHandler = bind(_this._mouseupHandler, _this);
  48754. var mousewheelHandler = bind(_this._mousewheelHandler, _this);
  48755. var pinchHandler = bind(_this._pinchHandler, _this);
  48756. /**
  48757. * Notice:
  48758. * - only enable needed types. For example, if 'zoom'
  48759. * is not needed, 'zoom' should not be enabled, otherwise
  48760. * default mousewheel behaviour (scroll page) will be disabled.
  48761. * - This method is idempotent.
  48762. */
  48763. _this.enable = function (controlType, rawOpt) {
  48764. var zInfo = rawOpt.zInfo;
  48765. var _a = retrieveZInfo(zInfo.component),
  48766. z = _a.z,
  48767. zlevel = _a.zlevel;
  48768. var zInfoParsed = {
  48769. component: zInfo.component,
  48770. z: z,
  48771. zlevel: zlevel,
  48772. // By default roam controller is the lowest z2 comparing to other elememts in a component.
  48773. z2: retrieve2(zInfo.z2, -Infinity)
  48774. };
  48775. var triggerInfo = extend({}, rawOpt.triggerInfo);
  48776. this._opt = defaults(extend({}, rawOpt), {
  48777. zoomOnMouseWheel: true,
  48778. moveOnMouseMove: true,
  48779. // By default, wheel do not trigger move.
  48780. moveOnMouseWheel: false,
  48781. preventDefaultMouseMove: true,
  48782. zInfoParsed: zInfoParsed,
  48783. triggerInfo: triggerInfo
  48784. });
  48785. if (controlType == null) {
  48786. controlType = true;
  48787. }
  48788. // A handy optimization for repeatedly calling `enable` during roaming.
  48789. // Assert `disable` is only affected by `controlType`.
  48790. if (!this._enabled || this._controlType !== controlType) {
  48791. this._enabled = true;
  48792. // Disable previous first
  48793. this.disable();
  48794. if (controlType === true || controlType === 'move' || controlType === 'pan') {
  48795. addRoamZrListener(zr, 'mousedown', mousedownHandler, zInfoParsed);
  48796. addRoamZrListener(zr, 'mousemove', mousemoveHandler, zInfoParsed);
  48797. addRoamZrListener(zr, 'mouseup', mouseupHandler, zInfoParsed);
  48798. }
  48799. if (controlType === true || controlType === 'scale' || controlType === 'zoom') {
  48800. addRoamZrListener(zr, 'mousewheel', mousewheelHandler, zInfoParsed);
  48801. addRoamZrListener(zr, 'pinch', pinchHandler, zInfoParsed);
  48802. }
  48803. }
  48804. };
  48805. _this.disable = function () {
  48806. this._enabled = false;
  48807. removeRoamZrListener(zr, 'mousedown', mousedownHandler);
  48808. removeRoamZrListener(zr, 'mousemove', mousemoveHandler);
  48809. removeRoamZrListener(zr, 'mouseup', mouseupHandler);
  48810. removeRoamZrListener(zr, 'mousewheel', mousewheelHandler);
  48811. removeRoamZrListener(zr, 'pinch', pinchHandler);
  48812. };
  48813. return _this;
  48814. }
  48815. RoamController.prototype.isDragging = function () {
  48816. return this._dragging;
  48817. };
  48818. RoamController.prototype.isPinching = function () {
  48819. return this._pinching;
  48820. };
  48821. RoamController.prototype._checkPointer = function (e, x, y) {
  48822. var opt = this._opt;
  48823. var zInfoParsed = opt.zInfoParsed;
  48824. if (onIrrelevantElement(e, opt.api, zInfoParsed.component)) {
  48825. return false;
  48826. }
  48827. var triggerInfo = opt.triggerInfo;
  48828. var roamTrigger = triggerInfo.roamTrigger;
  48829. var inArea = false;
  48830. if (roamTrigger === 'global') {
  48831. inArea = true;
  48832. }
  48833. if (!inArea) {
  48834. inArea = triggerInfo.isInSelf(e, x, y);
  48835. }
  48836. if (inArea && triggerInfo.isInClip && !triggerInfo.isInClip(e, x, y)) {
  48837. inArea = false;
  48838. }
  48839. return inArea;
  48840. };
  48841. RoamController.prototype._decideCursorStyle = function (e, x, y, forReverse) {
  48842. // If this cursor style decision is not strictly consistent with zrender,
  48843. // it's fine - zr will set the cursor on the next mousemove.
  48844. // This `grab` cursor style should take the lowest precedence. If the hovring element already
  48845. // have a cursor, zrender will set it to be non-'default' before entering this handler.
  48846. // (note, e.target is never silent, e.topTarget can be silent be irrelevant.)
  48847. var target = e.target;
  48848. if (!target && this._checkPointer(e, x, y)) {
  48849. // To indicate users that this area is draggable, otherwise users probably cannot kwown
  48850. // that when hovering out of the shape but still inside the bounding rect.
  48851. return 'grab';
  48852. }
  48853. if (forReverse) {
  48854. return target && target.cursor || 'default';
  48855. }
  48856. };
  48857. RoamController.prototype.dispose = function () {
  48858. this.disable();
  48859. };
  48860. RoamController.prototype._mousedownHandler = function (e) {
  48861. if (isMiddleOrRightButtonOnMouseUpDown(e) || eventConsumed(e)) {
  48862. return;
  48863. }
  48864. var el = e.target;
  48865. while (el) {
  48866. if (el.draggable) {
  48867. return;
  48868. }
  48869. // check if host is draggable
  48870. el = el.__hostTarget || el.parent;
  48871. }
  48872. var x = e.offsetX;
  48873. var y = e.offsetY;
  48874. // To determine dragging start, only by checking on mosedown, but not mousemove.
  48875. // Mouse can be out of target when mouse moving.
  48876. if (this._checkPointer(e, x, y)) {
  48877. this._x = x;
  48878. this._y = y;
  48879. this._dragging = true;
  48880. }
  48881. };
  48882. RoamController.prototype._mousemoveHandler = function (e) {
  48883. var zr = this._zr;
  48884. if (e.gestureEvent === 'pinch' || isTaken(zr, 'globalPan') || eventConsumed(e)) {
  48885. return;
  48886. }
  48887. var x = e.offsetX;
  48888. var y = e.offsetY;
  48889. if (!this._dragging || !isAvailableBehavior('moveOnMouseMove', e, this._opt)) {
  48890. var cursorStyle = this._decideCursorStyle(e, x, y, false);
  48891. if (cursorStyle) {
  48892. zr.setCursorStyle(cursorStyle);
  48893. }
  48894. return;
  48895. }
  48896. zr.setCursorStyle('grabbing');
  48897. var oldX = this._x;
  48898. var oldY = this._y;
  48899. var dx = x - oldX;
  48900. var dy = y - oldY;
  48901. this._x = x;
  48902. this._y = y;
  48903. if (this._opt.preventDefaultMouseMove) {
  48904. stop(e.event);
  48905. }
  48906. e.__ecRoamConsumed = true;
  48907. trigger(this, 'pan', 'moveOnMouseMove', e, {
  48908. dx: dx,
  48909. dy: dy,
  48910. oldX: oldX,
  48911. oldY: oldY,
  48912. newX: x,
  48913. newY: y,
  48914. isAvailableBehavior: null
  48915. });
  48916. };
  48917. RoamController.prototype._mouseupHandler = function (e) {
  48918. if (eventConsumed(e)) {
  48919. return;
  48920. }
  48921. var zr = this._zr;
  48922. if (!isMiddleOrRightButtonOnMouseUpDown(e)) {
  48923. this._dragging = false;
  48924. var cursorStyle = this._decideCursorStyle(e, e.offsetX, e.offsetY, true);
  48925. if (cursorStyle) {
  48926. zr.setCursorStyle(cursorStyle);
  48927. }
  48928. }
  48929. };
  48930. RoamController.prototype._mousewheelHandler = function (e) {
  48931. if (eventConsumed(e)) {
  48932. return;
  48933. }
  48934. var shouldZoom = isAvailableBehavior('zoomOnMouseWheel', e, this._opt);
  48935. var shouldMove = isAvailableBehavior('moveOnMouseWheel', e, this._opt);
  48936. var wheelDelta = e.wheelDelta;
  48937. var absWheelDeltaDelta = Math.abs(wheelDelta);
  48938. var originX = e.offsetX;
  48939. var originY = e.offsetY;
  48940. // wheelDelta maybe -0 in chrome mac.
  48941. if (wheelDelta === 0 || !shouldZoom && !shouldMove) {
  48942. return;
  48943. }
  48944. // If both `shouldZoom` and `shouldMove` is true, trigger
  48945. // their event both, and the final behavior is determined
  48946. // by event listener themselves.
  48947. if (shouldZoom) {
  48948. // Convenience:
  48949. // Mac and VM Windows on Mac: scroll up: zoom out.
  48950. // Windows: scroll up: zoom in.
  48951. // FIXME: Should do more test in different environment.
  48952. // wheelDelta is too complicated in difference nvironment
  48953. // (https://developer.mozilla.org/en-US/docs/Web/Events/mousewheel),
  48954. // although it has been normallized by zrender.
  48955. // wheelDelta of mouse wheel is bigger than touch pad.
  48956. var factor = absWheelDeltaDelta > 3 ? 1.4 : absWheelDeltaDelta > 1 ? 1.2 : 1.1;
  48957. var scale = wheelDelta > 0 ? factor : 1 / factor;
  48958. this._checkTriggerMoveZoom(this, 'zoom', 'zoomOnMouseWheel', e, {
  48959. scale: scale,
  48960. originX: originX,
  48961. originY: originY,
  48962. isAvailableBehavior: null
  48963. });
  48964. }
  48965. if (shouldMove) {
  48966. // FIXME: Should do more test in different environment.
  48967. var absDelta = Math.abs(wheelDelta);
  48968. // wheelDelta of mouse wheel is bigger than touch pad.
  48969. var scrollDelta = (wheelDelta > 0 ? 1 : -1) * (absDelta > 3 ? 0.4 : absDelta > 1 ? 0.15 : 0.05);
  48970. this._checkTriggerMoveZoom(this, 'scrollMove', 'moveOnMouseWheel', e, {
  48971. scrollDelta: scrollDelta,
  48972. originX: originX,
  48973. originY: originY,
  48974. isAvailableBehavior: null
  48975. });
  48976. }
  48977. };
  48978. RoamController.prototype._pinchHandler = function (e) {
  48979. if (isTaken(this._zr, 'globalPan') || eventConsumed(e)) {
  48980. return;
  48981. }
  48982. var scale = e.pinchScale > 1 ? 1.1 : 1 / 1.1;
  48983. this._checkTriggerMoveZoom(this, 'zoom', null, e, {
  48984. scale: scale,
  48985. originX: e.pinchX,
  48986. originY: e.pinchY,
  48987. isAvailableBehavior: null
  48988. });
  48989. };
  48990. RoamController.prototype._checkTriggerMoveZoom = function (controller, eventName, behaviorToCheck, e, contollerEvent) {
  48991. if (controller._checkPointer(e, contollerEvent.originX, contollerEvent.originY)) {
  48992. // When mouse is out of roamController rect,
  48993. // default befavoius should not be be disabled, otherwise
  48994. // page sliding is disabled, contrary to expectation.
  48995. stop(e.event);
  48996. e.__ecRoamConsumed = true;
  48997. trigger(controller, eventName, behaviorToCheck, e, contollerEvent);
  48998. }
  48999. };
  49000. return RoamController;
  49001. }(Eventful);
  49002. function eventConsumed(e) {
  49003. return e.__ecRoamConsumed;
  49004. }
  49005. var innerZrStore = makeInner();
  49006. function ensureZrStore(zr) {
  49007. var store = innerZrStore(zr);
  49008. store.roam = store.roam || {};
  49009. store.uniform = store.uniform || {};
  49010. return store;
  49011. }
  49012. /**
  49013. * Listeners are sorted by z2/z/zlevel in descending order.
  49014. * This decides the precedence between different roam controllers if they are overlapped.
  49015. *
  49016. * [MEMO]: It's not easy to perfectly reconcile the conflicts caused by overlap.
  49017. * - Consider cases:
  49018. * - Multiple roam controllers overlapped.
  49019. * - Usually only the topmost can trigger roam.
  49020. * - Roam controllers overlap with other zr elements:
  49021. * - zr elements are relevant or irrelevent to the host of the roam controller. e.g., axis split line
  49022. * or series elements is relevant to a cartesian and should trigger roam.
  49023. * - zr elements is above or below the roam controller host, which affects the precedence of interaction.
  49024. * - zr elements may not silent only for triggering tooltip by hovering, which is available to roam;
  49025. * or may not silent for click, where roam is not preferable.
  49026. * - Approach - `addRoamZrListener+pointerChecker+onIrrelevantElement` (currently used):
  49027. * - Resolve the precedence between different roam controllers
  49028. * - But cannot prevent the handling on other zr elements that under the roam controller in z-order.
  49029. * - Approach - "use an invisible zr elements to receive the zr events to trigger roam":
  49030. * - More complicated in impl.
  49031. * - May cause bad cases where zr event cannot be receive due to other non-silient zr elements covering it.
  49032. */
  49033. function addRoamZrListener(zr, eventType, listener, zInfoParsed) {
  49034. var store = ensureZrStore(zr);
  49035. var roam = store.roam;
  49036. var listenerList = roam[eventType] = roam[eventType] || [];
  49037. var idx = 0;
  49038. for (; idx < listenerList.length; idx++) {
  49039. var currZInfo = listenerList[idx].zInfoParsed;
  49040. if ((currZInfo.zlevel - zInfoParsed.zlevel || currZInfo.z - zInfoParsed.z || currZInfo.z2 - zInfoParsed.z2
  49041. // If all equals, the latter added one has a higher precedence.
  49042. ) <= 0) {
  49043. break;
  49044. }
  49045. }
  49046. listenerList.splice(idx, 0, {
  49047. listener: listener,
  49048. zInfoParsed: zInfoParsed
  49049. });
  49050. ensureUniformListener(zr, eventType);
  49051. }
  49052. function removeRoamZrListener(zr, eventType, listener) {
  49053. var store = ensureZrStore(zr);
  49054. var listenerList = store.roam[eventType] || [];
  49055. for (var idx = 0; idx < listenerList.length; idx++) {
  49056. if (listenerList[idx].listener === listener) {
  49057. listenerList.splice(idx, 1);
  49058. if (!listenerList.length) {
  49059. removeUniformListener(zr, eventType);
  49060. }
  49061. return;
  49062. }
  49063. }
  49064. }
  49065. function ensureUniformListener(zr, eventType) {
  49066. var store = ensureZrStore(zr);
  49067. if (!store.uniform[eventType]) {
  49068. zr.on(eventType, store.uniform[eventType] = function (event) {
  49069. var listenerList = store.roam[eventType];
  49070. if (listenerList) {
  49071. for (var i = 0; i < listenerList.length; i++) {
  49072. listenerList[i].listener(event);
  49073. }
  49074. }
  49075. });
  49076. }
  49077. }
  49078. function removeUniformListener(zr, eventType) {
  49079. var store = ensureZrStore(zr);
  49080. var uniform = store.uniform;
  49081. if (uniform[eventType]) {
  49082. zr.off(eventType, uniform[eventType]);
  49083. uniform[eventType] = null;
  49084. }
  49085. }
  49086. function trigger(controller, eventName, behaviorToCheck, e, contollerEvent) {
  49087. // Also provide behavior checker for event listener, for some case that
  49088. // multiple components share one listener.
  49089. contollerEvent.isAvailableBehavior = bind(isAvailableBehavior, null, behaviorToCheck, e);
  49090. // TODO should not have type issue.
  49091. controller.trigger(eventName, contollerEvent);
  49092. }
  49093. // settings: {
  49094. // zoomOnMouseWheel
  49095. // moveOnMouseMove
  49096. // moveOnMouseWheel
  49097. // }
  49098. // The value can be: true / false / 'shift' / 'ctrl' / 'alt'.
  49099. function isAvailableBehavior(behaviorToCheck, e, settings) {
  49100. var setting = settings[behaviorToCheck];
  49101. return !behaviorToCheck || setting && (!isString(setting) || e.event[setting + 'Key']);
  49102. }
  49103. /**
  49104. * [CAVEAT] `updateViewOnPan` and `updateViewOnZoom` modifies the group transform directly,
  49105. * but the 'center' and 'zoom' in echarts option and 'View' coordinate system are not updated yet,
  49106. * which must be performed later in 'xxxRoam' action by calling `updateCenterAndZoom`.
  49107. * @see {updateCenterAndZoomInAction}
  49108. */
  49109. function updateViewOnPan(controllerHost, dx, dy) {
  49110. var target = controllerHost.target;
  49111. target.x += dx;
  49112. target.y += dy;
  49113. target.dirty();
  49114. }
  49115. function updateViewOnZoom(controllerHost, zoomDelta, zoomX, zoomY) {
  49116. var target = controllerHost.target;
  49117. var zoomLimit = controllerHost.zoomLimit;
  49118. var newZoom = controllerHost.zoom = controllerHost.zoom || 1;
  49119. newZoom *= zoomDelta;
  49120. newZoom = clampByZoomLimit(newZoom, zoomLimit);
  49121. var zoomScale = newZoom / controllerHost.zoom;
  49122. controllerHost.zoom = newZoom;
  49123. zoomTransformableByOrigin(target, zoomX, zoomY, zoomScale);
  49124. target.dirty();
  49125. }
  49126. /**
  49127. * A abstraction for some similar impl in roaming.
  49128. */
  49129. function updateController(seriesModel, api, pointerCheckerEl, controller, controllerHost, clipRect) {
  49130. var tmpRect = new BoundingRect(0, 0, 0, 0);
  49131. controller.enable(seriesModel.get('roam'), {
  49132. api: api,
  49133. zInfo: {
  49134. component: seriesModel
  49135. },
  49136. triggerInfo: {
  49137. roamTrigger: seriesModel.get('roamTrigger'),
  49138. isInSelf: function (e, x, y) {
  49139. tmpRect.copy(pointerCheckerEl.getBoundingRect());
  49140. tmpRect.applyTransform(pointerCheckerEl.getComputedTransform());
  49141. return tmpRect.contain(x, y);
  49142. },
  49143. isInClip: function (e, x, y) {
  49144. return !clipRect || clipRect.contain(x, y);
  49145. }
  49146. }
  49147. });
  49148. controllerHost.zoomLimit = seriesModel.get('scaleLimit');
  49149. var coordinate = seriesModel.coordinateSystem;
  49150. controllerHost.zoom = coordinate ? coordinate.getZoom() : 1;
  49151. var type = seriesModel.subType + 'Roam';
  49152. controller.off('pan').off('zoom').on('pan', function (e) {
  49153. updateViewOnPan(controllerHost, e.dx, e.dy);
  49154. api.dispatchAction({
  49155. seriesId: seriesModel.id,
  49156. type: type,
  49157. dx: e.dx,
  49158. dy: e.dy
  49159. });
  49160. }).on('zoom', function (e) {
  49161. /**
  49162. * FIXME: should do nothing except `api.dispatchAction` here, the other logic
  49163. * should be performed in the action handler and `updateTransform`; otherwise,
  49164. * they are inconsistent if user triggers this action explicitly.
  49165. */
  49166. updateViewOnZoom(controllerHost, e.scale, e.originX, e.originY);
  49167. api.dispatchAction({
  49168. seriesId: seriesModel.id,
  49169. type: type,
  49170. zoom: e.scale,
  49171. originX: e.originX,
  49172. originY: e.originY
  49173. });
  49174. // Only update label layout on zoom
  49175. api.updateLabelLayout();
  49176. });
  49177. }
  49178. function getCenterCoord(view, point) {
  49179. // Use projected coord as center because it's linear.
  49180. return view.pointToProjected ? view.pointToProjected(point) : view.pointToData(point);
  49181. }
  49182. /**
  49183. * Should be called only in action handler.
  49184. * @see {updateViewOnPan|updateViewOnZoom}
  49185. */
  49186. function updateCenterAndZoomInAction(view, payload, zoomLimit) {
  49187. var previousZoom = view.getZoom();
  49188. var center = view.getCenter();
  49189. var deltaZoom = payload.zoom;
  49190. var point = view.projectedToPoint ? view.projectedToPoint(center) : view.dataToPoint(center);
  49191. if (payload.dx != null && payload.dy != null) {
  49192. point[0] -= payload.dx;
  49193. point[1] -= payload.dy;
  49194. view.setCenter(getCenterCoord(view, point));
  49195. }
  49196. if (deltaZoom != null) {
  49197. deltaZoom = clampByZoomLimit(previousZoom * deltaZoom, zoomLimit) / previousZoom;
  49198. zoomTransformableByOrigin(view, payload.originX, payload.originY, deltaZoom);
  49199. view.updateTransform();
  49200. // [NOTICE] Tricky: `getCetnerCoord` uses `this.invTransform` modified by the `updateTransform` above.
  49201. view.setCenter(getCenterCoord(view, point));
  49202. view.setZoom(deltaZoom * previousZoom);
  49203. }
  49204. return {
  49205. center: view.getCenter(),
  49206. zoom: view.getZoom()
  49207. };
  49208. }
  49209. function zoomTransformableByOrigin(target, originX, originY, deltaZoom) {
  49210. // Keep the mouse center when scaling.
  49211. target.x -= (originX - target.x) * (deltaZoom - 1);
  49212. target.y -= (originY - target.y) * (deltaZoom - 1);
  49213. target.scaleX *= deltaZoom;
  49214. target.scaleY *= deltaZoom;
  49215. }
  49216. function clampByZoomLimit(zoom, zoomLimit) {
  49217. if (zoomLimit) {
  49218. var zoomMin = zoomLimit.min || 0;
  49219. var zoomMax = zoomLimit.max || Infinity;
  49220. zoom = Math.max(Math.min(zoomMax, zoom), zoomMin);
  49221. }
  49222. return zoom;
  49223. }
  49224. function parseXML(svg) {
  49225. if (isString(svg)) {
  49226. var parser = new DOMParser();
  49227. svg = parser.parseFromString(svg, 'text/xml');
  49228. }
  49229. var svgNode = svg;
  49230. if (svgNode.nodeType === 9) {
  49231. svgNode = svgNode.firstChild;
  49232. }
  49233. while (svgNode.nodeName.toLowerCase() !== 'svg' || svgNode.nodeType !== 1) {
  49234. svgNode = svgNode.nextSibling;
  49235. }
  49236. return svgNode;
  49237. }
  49238. var nodeParsers;
  49239. var INHERITABLE_STYLE_ATTRIBUTES_MAP = {
  49240. 'fill': 'fill',
  49241. 'stroke': 'stroke',
  49242. 'stroke-width': 'lineWidth',
  49243. 'opacity': 'opacity',
  49244. 'fill-opacity': 'fillOpacity',
  49245. 'stroke-opacity': 'strokeOpacity',
  49246. 'stroke-dasharray': 'lineDash',
  49247. 'stroke-dashoffset': 'lineDashOffset',
  49248. 'stroke-linecap': 'lineCap',
  49249. 'stroke-linejoin': 'lineJoin',
  49250. 'stroke-miterlimit': 'miterLimit',
  49251. 'font-family': 'fontFamily',
  49252. 'font-size': 'fontSize',
  49253. 'font-style': 'fontStyle',
  49254. 'font-weight': 'fontWeight',
  49255. 'text-anchor': 'textAlign',
  49256. 'visibility': 'visibility',
  49257. 'display': 'display'
  49258. };
  49259. var INHERITABLE_STYLE_ATTRIBUTES_MAP_KEYS = keys(INHERITABLE_STYLE_ATTRIBUTES_MAP);
  49260. var SELF_STYLE_ATTRIBUTES_MAP = {
  49261. 'alignment-baseline': 'textBaseline',
  49262. 'stop-color': 'stopColor'
  49263. };
  49264. var SELF_STYLE_ATTRIBUTES_MAP_KEYS = keys(SELF_STYLE_ATTRIBUTES_MAP);
  49265. var SVGParser = (function () {
  49266. function SVGParser() {
  49267. this._defs = {};
  49268. this._root = null;
  49269. }
  49270. SVGParser.prototype.parse = function (xml, opt) {
  49271. opt = opt || {};
  49272. var svg = parseXML(xml);
  49273. if ("development" !== 'production') {
  49274. if (!svg) {
  49275. throw new Error('Illegal svg');
  49276. }
  49277. }
  49278. this._defsUsePending = [];
  49279. var root = new Group();
  49280. this._root = root;
  49281. var named = [];
  49282. var viewBox = svg.getAttribute('viewBox') || '';
  49283. var width = parseFloat((svg.getAttribute('width') || opt.width));
  49284. var height = parseFloat((svg.getAttribute('height') || opt.height));
  49285. isNaN(width) && (width = null);
  49286. isNaN(height) && (height = null);
  49287. parseAttributes(svg, root, null, true, false);
  49288. var child = svg.firstChild;
  49289. while (child) {
  49290. this._parseNode(child, root, named, null, false, false);
  49291. child = child.nextSibling;
  49292. }
  49293. applyDefs(this._defs, this._defsUsePending);
  49294. this._defsUsePending = [];
  49295. var viewBoxRect;
  49296. var viewBoxTransform;
  49297. if (viewBox) {
  49298. var viewBoxArr = splitNumberSequence(viewBox);
  49299. if (viewBoxArr.length >= 4) {
  49300. viewBoxRect = {
  49301. x: parseFloat((viewBoxArr[0] || 0)),
  49302. y: parseFloat((viewBoxArr[1] || 0)),
  49303. width: parseFloat(viewBoxArr[2]),
  49304. height: parseFloat(viewBoxArr[3])
  49305. };
  49306. }
  49307. }
  49308. if (viewBoxRect && width != null && height != null) {
  49309. viewBoxTransform = makeViewBoxTransform(viewBoxRect, { x: 0, y: 0, width: width, height: height });
  49310. if (!opt.ignoreViewBox) {
  49311. var elRoot = root;
  49312. root = new Group();
  49313. root.add(elRoot);
  49314. elRoot.scaleX = elRoot.scaleY = viewBoxTransform.scale;
  49315. elRoot.x = viewBoxTransform.x;
  49316. elRoot.y = viewBoxTransform.y;
  49317. }
  49318. }
  49319. if (!opt.ignoreRootClip && width != null && height != null) {
  49320. root.setClipPath(new Rect({
  49321. shape: { x: 0, y: 0, width: width, height: height }
  49322. }));
  49323. }
  49324. return {
  49325. root: root,
  49326. width: width,
  49327. height: height,
  49328. viewBoxRect: viewBoxRect,
  49329. viewBoxTransform: viewBoxTransform,
  49330. named: named
  49331. };
  49332. };
  49333. SVGParser.prototype._parseNode = function (xmlNode, parentGroup, named, namedFrom, isInDefs, isInText) {
  49334. var nodeName = xmlNode.nodeName.toLowerCase();
  49335. var el;
  49336. var namedFromForSub = namedFrom;
  49337. if (nodeName === 'defs') {
  49338. isInDefs = true;
  49339. }
  49340. if (nodeName === 'text') {
  49341. isInText = true;
  49342. }
  49343. if (nodeName === 'defs' || nodeName === 'switch') {
  49344. el = parentGroup;
  49345. }
  49346. else {
  49347. if (!isInDefs) {
  49348. var parser_1 = nodeParsers[nodeName];
  49349. if (parser_1 && hasOwn(nodeParsers, nodeName)) {
  49350. el = parser_1.call(this, xmlNode, parentGroup);
  49351. var nameAttr = xmlNode.getAttribute('name');
  49352. if (nameAttr) {
  49353. var newNamed = {
  49354. name: nameAttr,
  49355. namedFrom: null,
  49356. svgNodeTagLower: nodeName,
  49357. el: el
  49358. };
  49359. named.push(newNamed);
  49360. if (nodeName === 'g') {
  49361. namedFromForSub = newNamed;
  49362. }
  49363. }
  49364. else if (namedFrom) {
  49365. named.push({
  49366. name: namedFrom.name,
  49367. namedFrom: namedFrom,
  49368. svgNodeTagLower: nodeName,
  49369. el: el
  49370. });
  49371. }
  49372. parentGroup.add(el);
  49373. }
  49374. }
  49375. var parser = paintServerParsers[nodeName];
  49376. if (parser && hasOwn(paintServerParsers, nodeName)) {
  49377. var def = parser.call(this, xmlNode);
  49378. var id = xmlNode.getAttribute('id');
  49379. if (id) {
  49380. this._defs[id] = def;
  49381. }
  49382. }
  49383. }
  49384. if (el && el.isGroup) {
  49385. var child = xmlNode.firstChild;
  49386. while (child) {
  49387. if (child.nodeType === 1) {
  49388. this._parseNode(child, el, named, namedFromForSub, isInDefs, isInText);
  49389. }
  49390. else if (child.nodeType === 3 && isInText) {
  49391. this._parseText(child, el);
  49392. }
  49393. child = child.nextSibling;
  49394. }
  49395. }
  49396. };
  49397. SVGParser.prototype._parseText = function (xmlNode, parentGroup) {
  49398. var text = new TSpan({
  49399. style: {
  49400. text: xmlNode.textContent
  49401. },
  49402. silent: true,
  49403. x: this._textX || 0,
  49404. y: this._textY || 0
  49405. });
  49406. inheritStyle(parentGroup, text);
  49407. parseAttributes(xmlNode, text, this._defsUsePending, false, false);
  49408. applyTextAlignment(text, parentGroup);
  49409. var textStyle = text.style;
  49410. var fontSize = textStyle.fontSize;
  49411. if (fontSize && fontSize < 9) {
  49412. textStyle.fontSize = 9;
  49413. text.scaleX *= fontSize / 9;
  49414. text.scaleY *= fontSize / 9;
  49415. }
  49416. var font = (textStyle.fontSize || textStyle.fontFamily) && [
  49417. textStyle.fontStyle,
  49418. textStyle.fontWeight,
  49419. (textStyle.fontSize || 12) + 'px',
  49420. textStyle.fontFamily || 'sans-serif'
  49421. ].join(' ');
  49422. textStyle.font = font;
  49423. var rect = text.getBoundingRect();
  49424. this._textX += rect.width;
  49425. parentGroup.add(text);
  49426. return text;
  49427. };
  49428. SVGParser.internalField = (function () {
  49429. nodeParsers = {
  49430. 'g': function (xmlNode, parentGroup) {
  49431. var g = new Group();
  49432. inheritStyle(parentGroup, g);
  49433. parseAttributes(xmlNode, g, this._defsUsePending, false, false);
  49434. return g;
  49435. },
  49436. 'rect': function (xmlNode, parentGroup) {
  49437. var rect = new Rect();
  49438. inheritStyle(parentGroup, rect);
  49439. parseAttributes(xmlNode, rect, this._defsUsePending, false, false);
  49440. rect.setShape({
  49441. x: parseFloat(xmlNode.getAttribute('x') || '0'),
  49442. y: parseFloat(xmlNode.getAttribute('y') || '0'),
  49443. width: parseFloat(xmlNode.getAttribute('width') || '0'),
  49444. height: parseFloat(xmlNode.getAttribute('height') || '0')
  49445. });
  49446. rect.silent = true;
  49447. return rect;
  49448. },
  49449. 'circle': function (xmlNode, parentGroup) {
  49450. var circle = new Circle();
  49451. inheritStyle(parentGroup, circle);
  49452. parseAttributes(xmlNode, circle, this._defsUsePending, false, false);
  49453. circle.setShape({
  49454. cx: parseFloat(xmlNode.getAttribute('cx') || '0'),
  49455. cy: parseFloat(xmlNode.getAttribute('cy') || '0'),
  49456. r: parseFloat(xmlNode.getAttribute('r') || '0')
  49457. });
  49458. circle.silent = true;
  49459. return circle;
  49460. },
  49461. 'line': function (xmlNode, parentGroup) {
  49462. var line = new Line();
  49463. inheritStyle(parentGroup, line);
  49464. parseAttributes(xmlNode, line, this._defsUsePending, false, false);
  49465. line.setShape({
  49466. x1: parseFloat(xmlNode.getAttribute('x1') || '0'),
  49467. y1: parseFloat(xmlNode.getAttribute('y1') || '0'),
  49468. x2: parseFloat(xmlNode.getAttribute('x2') || '0'),
  49469. y2: parseFloat(xmlNode.getAttribute('y2') || '0')
  49470. });
  49471. line.silent = true;
  49472. return line;
  49473. },
  49474. 'ellipse': function (xmlNode, parentGroup) {
  49475. var ellipse = new Ellipse();
  49476. inheritStyle(parentGroup, ellipse);
  49477. parseAttributes(xmlNode, ellipse, this._defsUsePending, false, false);
  49478. ellipse.setShape({
  49479. cx: parseFloat(xmlNode.getAttribute('cx') || '0'),
  49480. cy: parseFloat(xmlNode.getAttribute('cy') || '0'),
  49481. rx: parseFloat(xmlNode.getAttribute('rx') || '0'),
  49482. ry: parseFloat(xmlNode.getAttribute('ry') || '0')
  49483. });
  49484. ellipse.silent = true;
  49485. return ellipse;
  49486. },
  49487. 'polygon': function (xmlNode, parentGroup) {
  49488. var pointsStr = xmlNode.getAttribute('points');
  49489. var pointsArr;
  49490. if (pointsStr) {
  49491. pointsArr = parsePoints(pointsStr);
  49492. }
  49493. var polygon = new Polygon({
  49494. shape: {
  49495. points: pointsArr || []
  49496. },
  49497. silent: true
  49498. });
  49499. inheritStyle(parentGroup, polygon);
  49500. parseAttributes(xmlNode, polygon, this._defsUsePending, false, false);
  49501. return polygon;
  49502. },
  49503. 'polyline': function (xmlNode, parentGroup) {
  49504. var pointsStr = xmlNode.getAttribute('points');
  49505. var pointsArr;
  49506. if (pointsStr) {
  49507. pointsArr = parsePoints(pointsStr);
  49508. }
  49509. var polyline = new Polyline({
  49510. shape: {
  49511. points: pointsArr || []
  49512. },
  49513. silent: true
  49514. });
  49515. inheritStyle(parentGroup, polyline);
  49516. parseAttributes(xmlNode, polyline, this._defsUsePending, false, false);
  49517. return polyline;
  49518. },
  49519. 'image': function (xmlNode, parentGroup) {
  49520. var img = new ZRImage();
  49521. inheritStyle(parentGroup, img);
  49522. parseAttributes(xmlNode, img, this._defsUsePending, false, false);
  49523. img.setStyle({
  49524. image: xmlNode.getAttribute('xlink:href') || xmlNode.getAttribute('href'),
  49525. x: +xmlNode.getAttribute('x'),
  49526. y: +xmlNode.getAttribute('y'),
  49527. width: +xmlNode.getAttribute('width'),
  49528. height: +xmlNode.getAttribute('height')
  49529. });
  49530. img.silent = true;
  49531. return img;
  49532. },
  49533. 'text': function (xmlNode, parentGroup) {
  49534. var x = xmlNode.getAttribute('x') || '0';
  49535. var y = xmlNode.getAttribute('y') || '0';
  49536. var dx = xmlNode.getAttribute('dx') || '0';
  49537. var dy = xmlNode.getAttribute('dy') || '0';
  49538. this._textX = parseFloat(x) + parseFloat(dx);
  49539. this._textY = parseFloat(y) + parseFloat(dy);
  49540. var g = new Group();
  49541. inheritStyle(parentGroup, g);
  49542. parseAttributes(xmlNode, g, this._defsUsePending, false, true);
  49543. return g;
  49544. },
  49545. 'tspan': function (xmlNode, parentGroup) {
  49546. var x = xmlNode.getAttribute('x');
  49547. var y = xmlNode.getAttribute('y');
  49548. if (x != null) {
  49549. this._textX = parseFloat(x);
  49550. }
  49551. if (y != null) {
  49552. this._textY = parseFloat(y);
  49553. }
  49554. var dx = xmlNode.getAttribute('dx') || '0';
  49555. var dy = xmlNode.getAttribute('dy') || '0';
  49556. var g = new Group();
  49557. inheritStyle(parentGroup, g);
  49558. parseAttributes(xmlNode, g, this._defsUsePending, false, true);
  49559. this._textX += parseFloat(dx);
  49560. this._textY += parseFloat(dy);
  49561. return g;
  49562. },
  49563. 'path': function (xmlNode, parentGroup) {
  49564. var d = xmlNode.getAttribute('d') || '';
  49565. var path = createFromString(d);
  49566. inheritStyle(parentGroup, path);
  49567. parseAttributes(xmlNode, path, this._defsUsePending, false, false);
  49568. path.silent = true;
  49569. return path;
  49570. }
  49571. };
  49572. })();
  49573. return SVGParser;
  49574. }());
  49575. var paintServerParsers = {
  49576. 'lineargradient': function (xmlNode) {
  49577. var x1 = parseInt(xmlNode.getAttribute('x1') || '0', 10);
  49578. var y1 = parseInt(xmlNode.getAttribute('y1') || '0', 10);
  49579. var x2 = parseInt(xmlNode.getAttribute('x2') || '10', 10);
  49580. var y2 = parseInt(xmlNode.getAttribute('y2') || '0', 10);
  49581. var gradient = new LinearGradient(x1, y1, x2, y2);
  49582. parsePaintServerUnit(xmlNode, gradient);
  49583. parseGradientColorStops(xmlNode, gradient);
  49584. return gradient;
  49585. },
  49586. 'radialgradient': function (xmlNode) {
  49587. var cx = parseInt(xmlNode.getAttribute('cx') || '0', 10);
  49588. var cy = parseInt(xmlNode.getAttribute('cy') || '0', 10);
  49589. var r = parseInt(xmlNode.getAttribute('r') || '0', 10);
  49590. var gradient = new RadialGradient(cx, cy, r);
  49591. parsePaintServerUnit(xmlNode, gradient);
  49592. parseGradientColorStops(xmlNode, gradient);
  49593. return gradient;
  49594. }
  49595. };
  49596. function parsePaintServerUnit(xmlNode, gradient) {
  49597. var gradientUnits = xmlNode.getAttribute('gradientUnits');
  49598. if (gradientUnits === 'userSpaceOnUse') {
  49599. gradient.global = true;
  49600. }
  49601. }
  49602. function parseGradientColorStops(xmlNode, gradient) {
  49603. var stop = xmlNode.firstChild;
  49604. while (stop) {
  49605. if (stop.nodeType === 1
  49606. && stop.nodeName.toLocaleLowerCase() === 'stop') {
  49607. var offsetStr = stop.getAttribute('offset');
  49608. var offset = void 0;
  49609. if (offsetStr && offsetStr.indexOf('%') > 0) {
  49610. offset = parseInt(offsetStr, 10) / 100;
  49611. }
  49612. else if (offsetStr) {
  49613. offset = parseFloat(offsetStr);
  49614. }
  49615. else {
  49616. offset = 0;
  49617. }
  49618. var styleVals = {};
  49619. parseInlineStyle(stop, styleVals, styleVals);
  49620. var stopColor = styleVals.stopColor
  49621. || stop.getAttribute('stop-color')
  49622. || '#000000';
  49623. var stopOpacity = styleVals.stopOpacity
  49624. || stop.getAttribute('stop-opacity');
  49625. if (stopOpacity) {
  49626. var rgba = parse(stopColor);
  49627. var stopColorOpacity = rgba && rgba[3];
  49628. if (stopColorOpacity) {
  49629. rgba[3] *= parseCssFloat(stopOpacity);
  49630. stopColor = stringify(rgba, 'rgba');
  49631. }
  49632. }
  49633. gradient.colorStops.push({
  49634. offset: offset,
  49635. color: stopColor
  49636. });
  49637. }
  49638. stop = stop.nextSibling;
  49639. }
  49640. }
  49641. function inheritStyle(parent, child) {
  49642. if (parent && parent.__inheritedStyle) {
  49643. if (!child.__inheritedStyle) {
  49644. child.__inheritedStyle = {};
  49645. }
  49646. defaults(child.__inheritedStyle, parent.__inheritedStyle);
  49647. }
  49648. }
  49649. function parsePoints(pointsString) {
  49650. var list = splitNumberSequence(pointsString);
  49651. var points = [];
  49652. for (var i = 0; i < list.length; i += 2) {
  49653. var x = parseFloat(list[i]);
  49654. var y = parseFloat(list[i + 1]);
  49655. points.push([x, y]);
  49656. }
  49657. return points;
  49658. }
  49659. function parseAttributes(xmlNode, el, defsUsePending, onlyInlineStyle, isTextGroup) {
  49660. var disp = el;
  49661. var inheritedStyle = disp.__inheritedStyle = disp.__inheritedStyle || {};
  49662. var selfStyle = {};
  49663. if (xmlNode.nodeType === 1) {
  49664. parseTransformAttribute(xmlNode, el);
  49665. parseInlineStyle(xmlNode, inheritedStyle, selfStyle);
  49666. if (!onlyInlineStyle) {
  49667. parseAttributeStyle(xmlNode, inheritedStyle, selfStyle);
  49668. }
  49669. }
  49670. disp.style = disp.style || {};
  49671. if (inheritedStyle.fill != null) {
  49672. disp.style.fill = getFillStrokeStyle(disp, 'fill', inheritedStyle.fill, defsUsePending);
  49673. }
  49674. if (inheritedStyle.stroke != null) {
  49675. disp.style.stroke = getFillStrokeStyle(disp, 'stroke', inheritedStyle.stroke, defsUsePending);
  49676. }
  49677. each([
  49678. 'lineWidth', 'opacity', 'fillOpacity', 'strokeOpacity', 'miterLimit', 'fontSize'
  49679. ], function (propName) {
  49680. if (inheritedStyle[propName] != null) {
  49681. disp.style[propName] = parseFloat(inheritedStyle[propName]);
  49682. }
  49683. });
  49684. each([
  49685. 'lineDashOffset', 'lineCap', 'lineJoin', 'fontWeight', 'fontFamily', 'fontStyle', 'textAlign'
  49686. ], function (propName) {
  49687. if (inheritedStyle[propName] != null) {
  49688. disp.style[propName] = inheritedStyle[propName];
  49689. }
  49690. });
  49691. if (isTextGroup) {
  49692. disp.__selfStyle = selfStyle;
  49693. }
  49694. if (inheritedStyle.lineDash) {
  49695. disp.style.lineDash = map(splitNumberSequence(inheritedStyle.lineDash), function (str) {
  49696. return parseFloat(str);
  49697. });
  49698. }
  49699. if (inheritedStyle.visibility === 'hidden' || inheritedStyle.visibility === 'collapse') {
  49700. disp.invisible = true;
  49701. }
  49702. if (inheritedStyle.display === 'none') {
  49703. disp.ignore = true;
  49704. }
  49705. }
  49706. function applyTextAlignment(text, parentGroup) {
  49707. var parentSelfStyle = parentGroup.__selfStyle;
  49708. if (parentSelfStyle) {
  49709. var textBaseline = parentSelfStyle.textBaseline;
  49710. var zrTextBaseline = textBaseline;
  49711. if (!textBaseline || textBaseline === 'auto') {
  49712. zrTextBaseline = 'alphabetic';
  49713. }
  49714. else if (textBaseline === 'baseline') {
  49715. zrTextBaseline = 'alphabetic';
  49716. }
  49717. else if (textBaseline === 'before-edge' || textBaseline === 'text-before-edge') {
  49718. zrTextBaseline = 'top';
  49719. }
  49720. else if (textBaseline === 'after-edge' || textBaseline === 'text-after-edge') {
  49721. zrTextBaseline = 'bottom';
  49722. }
  49723. else if (textBaseline === 'central' || textBaseline === 'mathematical') {
  49724. zrTextBaseline = 'middle';
  49725. }
  49726. text.style.textBaseline = zrTextBaseline;
  49727. }
  49728. var parentInheritedStyle = parentGroup.__inheritedStyle;
  49729. if (parentInheritedStyle) {
  49730. var textAlign = parentInheritedStyle.textAlign;
  49731. var zrTextAlign = textAlign;
  49732. if (textAlign) {
  49733. if (textAlign === 'middle') {
  49734. zrTextAlign = 'center';
  49735. }
  49736. text.style.textAlign = zrTextAlign;
  49737. }
  49738. }
  49739. }
  49740. var urlRegex = /^url\(\s*#(.*?)\)/;
  49741. function getFillStrokeStyle(el, method, str, defsUsePending) {
  49742. var urlMatch = str && str.match(urlRegex);
  49743. if (urlMatch) {
  49744. var url = trim(urlMatch[1]);
  49745. defsUsePending.push([el, method, url]);
  49746. return;
  49747. }
  49748. if (str === 'none') {
  49749. str = null;
  49750. }
  49751. return str;
  49752. }
  49753. function applyDefs(defs, defsUsePending) {
  49754. for (var i = 0; i < defsUsePending.length; i++) {
  49755. var item = defsUsePending[i];
  49756. item[0].style[item[1]] = defs[item[2]];
  49757. }
  49758. }
  49759. var numberReg$1 = /-?([0-9]*\.)?[0-9]+([eE]-?[0-9]+)?/g;
  49760. function splitNumberSequence(rawStr) {
  49761. return rawStr.match(numberReg$1) || [];
  49762. }
  49763. var transformRegex = /(translate|scale|rotate|skewX|skewY|matrix)\(([\-\s0-9\.eE,]*)\)/g;
  49764. var DEGREE_TO_ANGLE = Math.PI / 180;
  49765. function parseTransformAttribute(xmlNode, node) {
  49766. var transform = xmlNode.getAttribute('transform');
  49767. if (transform) {
  49768. transform = transform.replace(/,/g, ' ');
  49769. var transformOps_1 = [];
  49770. var mt = null;
  49771. transform.replace(transformRegex, function (str, type, value) {
  49772. transformOps_1.push(type, value);
  49773. return '';
  49774. });
  49775. for (var i = transformOps_1.length - 1; i > 0; i -= 2) {
  49776. var value = transformOps_1[i];
  49777. var type = transformOps_1[i - 1];
  49778. var valueArr = splitNumberSequence(value);
  49779. mt = mt || create$1();
  49780. switch (type) {
  49781. case 'translate':
  49782. translate(mt, mt, [parseFloat(valueArr[0]), parseFloat(valueArr[1] || '0')]);
  49783. break;
  49784. case 'scale':
  49785. scale$1(mt, mt, [parseFloat(valueArr[0]), parseFloat(valueArr[1] || valueArr[0])]);
  49786. break;
  49787. case 'rotate':
  49788. rotate(mt, mt, -parseFloat(valueArr[0]) * DEGREE_TO_ANGLE, [
  49789. parseFloat(valueArr[1] || '0'),
  49790. parseFloat(valueArr[2] || '0')
  49791. ]);
  49792. break;
  49793. case 'skewX':
  49794. var sx = Math.tan(parseFloat(valueArr[0]) * DEGREE_TO_ANGLE);
  49795. mul$1(mt, [1, 0, sx, 1, 0, 0], mt);
  49796. break;
  49797. case 'skewY':
  49798. var sy = Math.tan(parseFloat(valueArr[0]) * DEGREE_TO_ANGLE);
  49799. mul$1(mt, [1, sy, 0, 1, 0, 0], mt);
  49800. break;
  49801. case 'matrix':
  49802. mt[0] = parseFloat(valueArr[0]);
  49803. mt[1] = parseFloat(valueArr[1]);
  49804. mt[2] = parseFloat(valueArr[2]);
  49805. mt[3] = parseFloat(valueArr[3]);
  49806. mt[4] = parseFloat(valueArr[4]);
  49807. mt[5] = parseFloat(valueArr[5]);
  49808. break;
  49809. }
  49810. }
  49811. node.setLocalTransform(mt);
  49812. }
  49813. }
  49814. var styleRegex = /([^\s:;]+)\s*:\s*([^:;]+)/g;
  49815. function parseInlineStyle(xmlNode, inheritableStyleResult, selfStyleResult) {
  49816. var style = xmlNode.getAttribute('style');
  49817. if (!style) {
  49818. return;
  49819. }
  49820. styleRegex.lastIndex = 0;
  49821. var styleRegResult;
  49822. while ((styleRegResult = styleRegex.exec(style)) != null) {
  49823. var svgStlAttr = styleRegResult[1];
  49824. var zrInheritableStlAttr = hasOwn(INHERITABLE_STYLE_ATTRIBUTES_MAP, svgStlAttr)
  49825. ? INHERITABLE_STYLE_ATTRIBUTES_MAP[svgStlAttr]
  49826. : null;
  49827. if (zrInheritableStlAttr) {
  49828. inheritableStyleResult[zrInheritableStlAttr] = styleRegResult[2];
  49829. }
  49830. var zrSelfStlAttr = hasOwn(SELF_STYLE_ATTRIBUTES_MAP, svgStlAttr)
  49831. ? SELF_STYLE_ATTRIBUTES_MAP[svgStlAttr]
  49832. : null;
  49833. if (zrSelfStlAttr) {
  49834. selfStyleResult[zrSelfStlAttr] = styleRegResult[2];
  49835. }
  49836. }
  49837. }
  49838. function parseAttributeStyle(xmlNode, inheritableStyleResult, selfStyleResult) {
  49839. for (var i = 0; i < INHERITABLE_STYLE_ATTRIBUTES_MAP_KEYS.length; i++) {
  49840. var svgAttrName = INHERITABLE_STYLE_ATTRIBUTES_MAP_KEYS[i];
  49841. var attrValue = xmlNode.getAttribute(svgAttrName);
  49842. if (attrValue != null) {
  49843. inheritableStyleResult[INHERITABLE_STYLE_ATTRIBUTES_MAP[svgAttrName]] = attrValue;
  49844. }
  49845. }
  49846. for (var i = 0; i < SELF_STYLE_ATTRIBUTES_MAP_KEYS.length; i++) {
  49847. var svgAttrName = SELF_STYLE_ATTRIBUTES_MAP_KEYS[i];
  49848. var attrValue = xmlNode.getAttribute(svgAttrName);
  49849. if (attrValue != null) {
  49850. selfStyleResult[SELF_STYLE_ATTRIBUTES_MAP[svgAttrName]] = attrValue;
  49851. }
  49852. }
  49853. }
  49854. function makeViewBoxTransform(viewBoxRect, boundingRect) {
  49855. var scaleX = boundingRect.width / viewBoxRect.width;
  49856. var scaleY = boundingRect.height / viewBoxRect.height;
  49857. var scale = Math.min(scaleX, scaleY);
  49858. return {
  49859. scale: scale,
  49860. x: -(viewBoxRect.x + viewBoxRect.width / 2) * scale + (boundingRect.x + boundingRect.width / 2),
  49861. y: -(viewBoxRect.y + viewBoxRect.height / 2) * scale + (boundingRect.y + boundingRect.height / 2)
  49862. };
  49863. }
  49864. function parseSVG(xml, opt) {
  49865. var parser = new SVGParser();
  49866. return parser.parse(xml, opt);
  49867. }
  49868. /**
  49869. * "region available" means that: enable users to set attribute `name="xxx"` on those tags
  49870. * to make it be a region.
  49871. * 1. region styles and its label styles can be defined in echarts opton:
  49872. * ```js
  49873. * geo: {
  49874. * regions: [{
  49875. * name: 'xxx',
  49876. * itemStyle: { ... },
  49877. * label: { ... }
  49878. * }, {
  49879. * ...
  49880. * },
  49881. * ...]
  49882. * };
  49883. * ```
  49884. * 2. name can be duplicated in different SVG tag. All of the tags with the same name share
  49885. * a region option. For exampel if there are two <path> representing two lung lobes. They have
  49886. * no common parents but both of them need to display label "lung" inside.
  49887. */
  49888. var REGION_AVAILABLE_SVG_TAG_MAP = createHashMap(['rect', 'circle', 'line', 'ellipse', 'polygon', 'polyline', 'path',
  49889. // <text> <tspan> are also enabled because some SVG might paint text itself,
  49890. // but still need to trigger events or tooltip.
  49891. 'text', 'tspan',
  49892. // <g> is also enabled because this case: if multiple tags share one name
  49893. // and need label displayed, every tags will display the name, which is not
  49894. // expected. So we can put them into a <g name="xxx">. Thereby only one label
  49895. // displayed and located based on the bounding rect of the <g>.
  49896. 'g']);
  49897. var GeoSVGResource = /** @class */function () {
  49898. function GeoSVGResource(mapName, svg) {
  49899. this.type = 'geoSVG';
  49900. // All used graphics. key: hostKey, value: root
  49901. this._usedGraphicMap = createHashMap();
  49902. // All unused graphics.
  49903. this._freedGraphics = [];
  49904. this._mapName = mapName;
  49905. // Only perform parse to XML object here, which might be time
  49906. // consiming for large SVG.
  49907. // Although convert XML to zrender element is also time consiming,
  49908. // if we do it here, the clone of zrender elements has to be
  49909. // required. So we do it once for each geo instance, util real
  49910. // performance issues call for optimizing it.
  49911. this._parsedXML = parseXML(svg);
  49912. }
  49913. GeoSVGResource.prototype.load = function /* nameMap: NameMap */
  49914. () {
  49915. // In the "load" stage, graphic need to be built to
  49916. // get boundingRect for geo coordinate system.
  49917. var firstGraphic = this._firstGraphic;
  49918. // Create the return data structure only when first graphic created.
  49919. // Because they will be used in geo coordinate system update stage,
  49920. // and `regions` will be mounted at `geo` coordinate system,
  49921. // in which there is no "view" info, so that it should better not to
  49922. // make references to graphic elements.
  49923. if (!firstGraphic) {
  49924. firstGraphic = this._firstGraphic = this._buildGraphic(this._parsedXML);
  49925. this._freedGraphics.push(firstGraphic);
  49926. this._boundingRect = this._firstGraphic.boundingRect.clone();
  49927. // PENDING: `nameMap` will not be supported until some real requirement come.
  49928. // if (nameMap) {
  49929. // named = applyNameMap(named, nameMap);
  49930. // }
  49931. var _a = createRegions(firstGraphic.named),
  49932. regions = _a.regions,
  49933. regionsMap = _a.regionsMap;
  49934. this._regions = regions;
  49935. this._regionsMap = regionsMap;
  49936. }
  49937. return {
  49938. boundingRect: this._boundingRect,
  49939. regions: this._regions,
  49940. regionsMap: this._regionsMap
  49941. };
  49942. };
  49943. GeoSVGResource.prototype._buildGraphic = function (svgXML) {
  49944. var result;
  49945. var rootFromParse;
  49946. try {
  49947. result = svgXML && parseSVG(svgXML, {
  49948. ignoreViewBox: true,
  49949. ignoreRootClip: true
  49950. }) || {};
  49951. rootFromParse = result.root;
  49952. assert(rootFromParse != null);
  49953. } catch (e) {
  49954. throw new Error('Invalid svg format\n' + e.message);
  49955. }
  49956. // Note: we keep the covenant that the root has no transform. So always add an extra root.
  49957. var root = new Group();
  49958. root.add(rootFromParse);
  49959. root.isGeoSVGGraphicRoot = true;
  49960. // [THE_RULE_OF_VIEWPORT_AND_VIEWBOX]
  49961. //
  49962. // Consider: `<svg width="..." height="..." viewBox="...">`
  49963. // - the `width/height` we call it `svgWidth/svgHeight` for short.
  49964. // - `(0, 0, svgWidth, svgHeight)` defines the viewport of the SVG, or say,
  49965. // "viewport boundingRect", or `boundingRect` for short.
  49966. // - `viewBox` defines the transform from the real content ot the viewport.
  49967. // `viewBox` has the same unit as the content of SVG.
  49968. // If `viewBox` exists, a transform is defined, so the unit of `svgWidth/svgHeight` become
  49969. // different from the content of SVG. Otherwise, they are the same.
  49970. //
  49971. // If both `svgWidth/svgHeight/viewBox` are specified in a SVG file, the transform rule will be:
  49972. // 0. `boundingRect` is `(0, 0, svgWidth, svgHeight)`. Set it to Geo['_rect'] (View['_rect']).
  49973. // 1. Make a transform from `viewBox` to `boundingRect`.
  49974. // Note: only support `preserveAspectRatio 'xMidYMid'` here. That is, this transform will preserve
  49975. // the aspect ratio.
  49976. // 2. Make a transform from boundingRect to Geo['_viewRect'] (View['_viewRect'])
  49977. // (`Geo`/`View` will do this job).
  49978. // Note: this transform might not preserve aspect radio, which depending on how users specify
  49979. // viewRect in echarts option (e.g., `geo.left/top/width/height` will not preserve aspect ratio,
  49980. // but `geo.layoutCenter/layoutSize` will preserve aspect ratio).
  49981. //
  49982. // If `svgWidth/svgHeight` not specified, we use `viewBox` as the `boundingRect` to make the SVG
  49983. // layout look good.
  49984. //
  49985. // If neither `svgWidth/svgHeight` nor `viewBox` are not specified, we calculate the boundingRect
  49986. // of the SVG content and use them to make SVG layout look good.
  49987. var svgWidth = result.width;
  49988. var svgHeight = result.height;
  49989. var viewBoxRect = result.viewBoxRect;
  49990. var boundingRect = this._boundingRect;
  49991. if (!boundingRect) {
  49992. var bRectX = void 0;
  49993. var bRectY = void 0;
  49994. var bRectWidth = void 0;
  49995. var bRectHeight = void 0;
  49996. if (svgWidth != null) {
  49997. bRectX = 0;
  49998. bRectWidth = svgWidth;
  49999. } else if (viewBoxRect) {
  50000. bRectX = viewBoxRect.x;
  50001. bRectWidth = viewBoxRect.width;
  50002. }
  50003. if (svgHeight != null) {
  50004. bRectY = 0;
  50005. bRectHeight = svgHeight;
  50006. } else if (viewBoxRect) {
  50007. bRectY = viewBoxRect.y;
  50008. bRectHeight = viewBoxRect.height;
  50009. }
  50010. // If both viewBox and svgWidth/svgHeight not specified,
  50011. // we have to determine how to layout those element to make them look good.
  50012. if (bRectX == null || bRectY == null) {
  50013. var calculatedBoundingRect = rootFromParse.getBoundingRect();
  50014. if (bRectX == null) {
  50015. bRectX = calculatedBoundingRect.x;
  50016. bRectWidth = calculatedBoundingRect.width;
  50017. }
  50018. if (bRectY == null) {
  50019. bRectY = calculatedBoundingRect.y;
  50020. bRectHeight = calculatedBoundingRect.height;
  50021. }
  50022. }
  50023. boundingRect = this._boundingRect = new BoundingRect(bRectX, bRectY, bRectWidth, bRectHeight);
  50024. }
  50025. if (viewBoxRect) {
  50026. var viewBoxTransform = makeViewBoxTransform(viewBoxRect, boundingRect);
  50027. // Only support `preserveAspectRatio 'xMidYMid'`
  50028. rootFromParse.scaleX = rootFromParse.scaleY = viewBoxTransform.scale;
  50029. rootFromParse.x = viewBoxTransform.x;
  50030. rootFromParse.y = viewBoxTransform.y;
  50031. }
  50032. // SVG needs to clip based on `viewBox`. And some SVG files really rely on this feature.
  50033. // They do not strictly confine all of the content inside a display rect, but deliberately
  50034. // use a `viewBox` to define a displayable rect.
  50035. // PENDING:
  50036. // The drawback of the `setClipPath` here is: the region label (genereted by echarts) near the
  50037. // edge might also be clipped, because region labels are put as `textContent` of the SVG path.
  50038. root.setClipPath(new Rect({
  50039. shape: boundingRect.plain()
  50040. }));
  50041. var named = [];
  50042. each(result.named, function (namedItem) {
  50043. if (REGION_AVAILABLE_SVG_TAG_MAP.get(namedItem.svgNodeTagLower) != null) {
  50044. named.push(namedItem);
  50045. setSilent(namedItem.el);
  50046. }
  50047. });
  50048. return {
  50049. root: root,
  50050. boundingRect: boundingRect,
  50051. named: named
  50052. };
  50053. };
  50054. /**
  50055. * Consider:
  50056. * (1) One graphic element can not be shared by different `geoView` running simultaneously.
  50057. * Notice, also need to consider multiple echarts instances share a `mapRecord`.
  50058. * (2) Converting SVG to graphic elements is time consuming.
  50059. * (3) In the current architecture, `load` should be called frequently to get boundingRect,
  50060. * and it is called without view info.
  50061. * So we maintain graphic elements in this module, and enables `view` to use/return these
  50062. * graphics from/to the pool with it's uid.
  50063. */
  50064. GeoSVGResource.prototype.useGraphic = function (hostKey /* , nameMap: NameMap */) {
  50065. var usedRootMap = this._usedGraphicMap;
  50066. var svgGraphic = usedRootMap.get(hostKey);
  50067. if (svgGraphic) {
  50068. return svgGraphic;
  50069. }
  50070. svgGraphic = this._freedGraphics.pop()
  50071. // use the first boundingRect to avoid duplicated boundingRect calculation.
  50072. || this._buildGraphic(this._parsedXML);
  50073. usedRootMap.set(hostKey, svgGraphic);
  50074. // PENDING: `nameMap` will not be supported until some real requirement come.
  50075. // `nameMap` can only be obtained from echarts option.
  50076. // The original `named` must not be modified.
  50077. // if (nameMap) {
  50078. // svgGraphic = extend({}, svgGraphic);
  50079. // svgGraphic.named = applyNameMap(svgGraphic.named, nameMap);
  50080. // }
  50081. return svgGraphic;
  50082. };
  50083. GeoSVGResource.prototype.freeGraphic = function (hostKey) {
  50084. var usedRootMap = this._usedGraphicMap;
  50085. var svgGraphic = usedRootMap.get(hostKey);
  50086. if (svgGraphic) {
  50087. usedRootMap.removeKey(hostKey);
  50088. this._freedGraphics.push(svgGraphic);
  50089. }
  50090. };
  50091. return GeoSVGResource;
  50092. }();
  50093. function setSilent(el) {
  50094. // Only named element has silent: false, other elements should
  50095. // act as background and has no user interaction.
  50096. el.silent = false;
  50097. // text|tspan will be converted to group.
  50098. if (el.isGroup) {
  50099. el.traverse(function (child) {
  50100. child.silent = false;
  50101. });
  50102. }
  50103. }
  50104. function createRegions(named) {
  50105. var regions = [];
  50106. var regionsMap = createHashMap();
  50107. // Create resions only for the first graphic.
  50108. each(named, function (namedItem) {
  50109. // Region has feature to calculate center for tooltip or other features.
  50110. // If there is a <g name="xxx">, the center should be the center of the
  50111. // bounding rect of the g.
  50112. if (namedItem.namedFrom != null) {
  50113. return;
  50114. }
  50115. var region = new GeoSVGRegion(namedItem.name, namedItem.el);
  50116. // PENDING: if `nameMap` supported, this region can not be mounted on
  50117. // `this`, but can only be created each time `load()` called.
  50118. regions.push(region);
  50119. // PENDING: if multiple tag named with the same name, only one will be
  50120. // found by `_regionsMap`. `_regionsMap` is used to find a coordinate
  50121. // by name. We use `region.getCenter()` as the coordinate.
  50122. regionsMap.set(namedItem.name, region);
  50123. });
  50124. return {
  50125. regions: regions,
  50126. regionsMap: regionsMap
  50127. };
  50128. }
  50129. // PENDING: `nameMap` will not be supported until some real requirement come.
  50130. // /**
  50131. // * Use the alias in geoNameMap.
  50132. // * The input `named` must not be modified.
  50133. // */
  50134. // function applyNameMap(
  50135. // named: GeoSVGGraphicRecord['named'],
  50136. // nameMap: NameMap
  50137. // ): GeoSVGGraphicRecord['named'] {
  50138. // const result = [] as GeoSVGGraphicRecord['named'];
  50139. // for (let i = 0; i < named.length; i++) {
  50140. // let regionGraphic = named[i];
  50141. // const name = regionGraphic.name;
  50142. // if (nameMap && nameMap.hasOwnProperty(name)) {
  50143. // regionGraphic = extend({}, regionGraphic);
  50144. // regionGraphic.name = name;
  50145. // }
  50146. // result.push(regionGraphic);
  50147. // }
  50148. // return result;
  50149. // }
  50150. var geoCoord = [126, 25];
  50151. var nanhaiName = '南海诸岛';
  50152. var points$1 = [[[0, 3.5], [7, 11.2], [15, 11.9], [30, 7], [42, 0.7], [52, 0.7], [56, 7.7], [59, 0.7], [64, 0.7], [64, 0], [5, 0], [0, 3.5]], [[13, 16.1], [19, 14.7], [16, 21.7], [11, 23.1], [13, 16.1]], [[12, 32.2], [14, 38.5], [15, 38.5], [13, 32.2], [12, 32.2]], [[16, 47.6], [12, 53.2], [13, 53.2], [18, 47.6], [16, 47.6]], [[6, 64.4], [8, 70], [9, 70], [8, 64.4], [6, 64.4]], [[23, 82.6], [29, 79.8], [30, 79.8], [25, 82.6], [23, 82.6]], [[37, 70.7], [43, 62.3], [44, 62.3], [39, 70.7], [37, 70.7]], [[48, 51.1], [51, 45.5], [53, 45.5], [50, 51.1], [48, 51.1]], [[51, 35], [51, 28.7], [53, 28.7], [53, 35], [51, 35]], [[52, 22.4], [55, 17.5], [56, 17.5], [53, 22.4], [52, 22.4]], [[58, 12.6], [62, 7], [63, 7], [60, 12.6], [58, 12.6]], [[0, 3.5], [0, 93.1], [64, 93.1], [64, 0], [63, 0], [63, 92.4], [1, 92.4], [1, 3.5], [0, 3.5]]];
  50153. for (var i = 0; i < points$1.length; i++) {
  50154. for (var k = 0; k < points$1[i].length; k++) {
  50155. points$1[i][k][0] /= 10.5;
  50156. points$1[i][k][1] /= -10.5 / 0.75;
  50157. points$1[i][k][0] += geoCoord[0];
  50158. points$1[i][k][1] += geoCoord[1];
  50159. }
  50160. }
  50161. function fixNanhai(mapType, regions) {
  50162. if (mapType === 'china') {
  50163. for (var i = 0; i < regions.length; i++) {
  50164. // Already exists.
  50165. if (regions[i].name === nanhaiName) {
  50166. return;
  50167. }
  50168. }
  50169. regions.push(new GeoJSONRegion(nanhaiName, map(points$1, function (exterior) {
  50170. return {
  50171. type: 'polygon',
  50172. exterior: exterior
  50173. };
  50174. }), geoCoord));
  50175. }
  50176. }
  50177. /*
  50178. * Licensed to the Apache Software Foundation (ASF) under one
  50179. * or more contributor license agreements. See the NOTICE file
  50180. * distributed with this work for additional information
  50181. * regarding copyright ownership. The ASF licenses this file
  50182. * to you under the Apache License, Version 2.0 (the
  50183. * "License"); you may not use this file except in compliance
  50184. * with the License. You may obtain a copy of the License at
  50185. *
  50186. * http://www.apache.org/licenses/LICENSE-2.0
  50187. *
  50188. * Unless required by applicable law or agreed to in writing,
  50189. * software distributed under the License is distributed on an
  50190. * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
  50191. * KIND, either express or implied. See the License for the
  50192. * specific language governing permissions and limitations
  50193. * under the License.
  50194. */
  50195. /**
  50196. * AUTO-GENERATED FILE. DO NOT MODIFY.
  50197. */
  50198. /*
  50199. * Licensed to the Apache Software Foundation (ASF) under one
  50200. * or more contributor license agreements. See the NOTICE file
  50201. * distributed with this work for additional information
  50202. * regarding copyright ownership. The ASF licenses this file
  50203. * to you under the Apache License, Version 2.0 (the
  50204. * "License"); you may not use this file except in compliance
  50205. * with the License. You may obtain a copy of the License at
  50206. *
  50207. * http://www.apache.org/licenses/LICENSE-2.0
  50208. *
  50209. * Unless required by applicable law or agreed to in writing,
  50210. * software distributed under the License is distributed on an
  50211. * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
  50212. * KIND, either express or implied. See the License for the
  50213. * specific language governing permissions and limitations
  50214. * under the License.
  50215. */
  50216. var coordsOffsetMap = {
  50217. '南海诸岛': [32, 80],
  50218. // 全国
  50219. '广东': [0, -10],
  50220. '香港': [10, 5],
  50221. '澳门': [-10, 10],
  50222. // '北京': [-10, 0],
  50223. '天津': [5, 5]
  50224. };
  50225. function fixTextCoords(mapType, region) {
  50226. if (mapType === 'china') {
  50227. var coordFix = coordsOffsetMap[region.name];
  50228. if (coordFix) {
  50229. var cp = region.getCenter();
  50230. cp[0] += coordFix[0] / 10.5;
  50231. cp[1] += -coordFix[1] / (10.5 / 0.75);
  50232. region.setCenter(cp);
  50233. }
  50234. }
  50235. }
  50236. /*
  50237. * Licensed to the Apache Software Foundation (ASF) under one
  50238. * or more contributor license agreements. See the NOTICE file
  50239. * distributed with this work for additional information
  50240. * regarding copyright ownership. The ASF licenses this file
  50241. * to you under the Apache License, Version 2.0 (the
  50242. * "License"); you may not use this file except in compliance
  50243. * with the License. You may obtain a copy of the License at
  50244. *
  50245. * http://www.apache.org/licenses/LICENSE-2.0
  50246. *
  50247. * Unless required by applicable law or agreed to in writing,
  50248. * software distributed under the License is distributed on an
  50249. * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
  50250. * KIND, either express or implied. See the License for the
  50251. * specific language governing permissions and limitations
  50252. * under the License.
  50253. */
  50254. /**
  50255. * AUTO-GENERATED FILE. DO NOT MODIFY.
  50256. */
  50257. /*
  50258. * Licensed to the Apache Software Foundation (ASF) under one
  50259. * or more contributor license agreements. See the NOTICE file
  50260. * distributed with this work for additional information
  50261. * regarding copyright ownership. The ASF licenses this file
  50262. * to you under the Apache License, Version 2.0 (the
  50263. * "License"); you may not use this file except in compliance
  50264. * with the License. You may obtain a copy of the License at
  50265. *
  50266. * http://www.apache.org/licenses/LICENSE-2.0
  50267. *
  50268. * Unless required by applicable law or agreed to in writing,
  50269. * software distributed under the License is distributed on an
  50270. * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
  50271. * KIND, either express or implied. See the License for the
  50272. * specific language governing permissions and limitations
  50273. * under the License.
  50274. */
  50275. // Fix for 钓鱼岛
  50276. // let Region = require('../Region');
  50277. // let zrUtil = require('zrender/lib/core/util');
  50278. // let geoCoord = [126, 25];
  50279. var points$2 = [[[123.45165252685547, 25.73527164402261], [123.49731445312499, 25.73527164402261], [123.49731445312499, 25.750734064600884], [123.45165252685547, 25.750734064600884], [123.45165252685547, 25.73527164402261]]];
  50280. function fixDiaoyuIsland(mapType, region) {
  50281. if (mapType === 'china' && region.name === '台湾') {
  50282. region.geometries.push({
  50283. type: 'polygon',
  50284. exterior: points$2[0]
  50285. });
  50286. }
  50287. }
  50288. var DEFAULT_NAME_PROPERTY = 'name';
  50289. var GeoJSONResource = /** @class */function () {
  50290. function GeoJSONResource(mapName, geoJSON, specialAreas) {
  50291. this.type = 'geoJSON';
  50292. this._parsedMap = createHashMap();
  50293. this._mapName = mapName;
  50294. this._specialAreas = specialAreas;
  50295. // PENDING: delay the parse to the first usage to rapid up the FMP?
  50296. this._geoJSON = parseInput(geoJSON);
  50297. }
  50298. /**
  50299. * @param nameMap can be null/undefined
  50300. * @param nameProperty can be null/undefined
  50301. */
  50302. GeoJSONResource.prototype.load = function (nameMap, nameProperty) {
  50303. nameProperty = nameProperty || DEFAULT_NAME_PROPERTY;
  50304. var parsed = this._parsedMap.get(nameProperty);
  50305. if (!parsed) {
  50306. var rawRegions = this._parseToRegions(nameProperty);
  50307. parsed = this._parsedMap.set(nameProperty, {
  50308. regions: rawRegions,
  50309. boundingRect: calculateBoundingRect(rawRegions)
  50310. });
  50311. }
  50312. var regionsMap = createHashMap();
  50313. var finalRegions = [];
  50314. each(parsed.regions, function (region) {
  50315. var regionName = region.name;
  50316. // Try use the alias in geoNameMap
  50317. if (nameMap && hasOwn(nameMap, regionName)) {
  50318. region = region.cloneShallow(regionName = nameMap[regionName]);
  50319. }
  50320. finalRegions.push(region);
  50321. regionsMap.set(regionName, region);
  50322. });
  50323. return {
  50324. regions: finalRegions,
  50325. boundingRect: parsed.boundingRect || new BoundingRect(0, 0, 0, 0),
  50326. regionsMap: regionsMap
  50327. };
  50328. };
  50329. GeoJSONResource.prototype._parseToRegions = function (nameProperty) {
  50330. var mapName = this._mapName;
  50331. var geoJSON = this._geoJSON;
  50332. var rawRegions;
  50333. // https://jsperf.com/try-catch-performance-overhead
  50334. try {
  50335. rawRegions = geoJSON ? parseGeoJSON(geoJSON, nameProperty) : [];
  50336. } catch (e) {
  50337. throw new Error('Invalid geoJson format\n' + e.message);
  50338. }
  50339. fixNanhai(mapName, rawRegions);
  50340. each(rawRegions, function (region) {
  50341. var regionName = region.name;
  50342. fixTextCoords(mapName, region);
  50343. fixDiaoyuIsland(mapName, region);
  50344. // Some area like Alaska in USA map needs to be tansformed
  50345. // to look better
  50346. var specialArea = this._specialAreas && this._specialAreas[regionName];
  50347. if (specialArea) {
  50348. region.transformTo(specialArea.left, specialArea.top, specialArea.width, specialArea.height);
  50349. }
  50350. }, this);
  50351. return rawRegions;
  50352. };
  50353. /**
  50354. * Only for exporting to users.
  50355. * **MUST NOT** used internally.
  50356. */
  50357. GeoJSONResource.prototype.getMapForUser = function () {
  50358. return {
  50359. // For backward compatibility, use geoJson
  50360. // PENDING: it has been returning them without clone.
  50361. // do we need to avoid outsite modification?
  50362. geoJson: this._geoJSON,
  50363. geoJSON: this._geoJSON,
  50364. specialAreas: this._specialAreas
  50365. };
  50366. };
  50367. return GeoJSONResource;
  50368. }();
  50369. function calculateBoundingRect(regions) {
  50370. var rect;
  50371. for (var i = 0; i < regions.length; i++) {
  50372. var regionRect = regions[i].getBoundingRect();
  50373. rect = rect || regionRect.clone();
  50374. rect.union(regionRect);
  50375. }
  50376. return rect;
  50377. }
  50378. function parseInput(source) {
  50379. return !isString(source) ? source : typeof JSON !== 'undefined' && JSON.parse ? JSON.parse(source) : new Function('return (' + source + ');')();
  50380. }
  50381. var storage = createHashMap();
  50382. var geoSourceManager = {
  50383. /**
  50384. * Compatible with previous `echarts.registerMap`.
  50385. *
  50386. * @usage
  50387. * ```js
  50388. *
  50389. * echarts.registerMap('USA', geoJson, specialAreas);
  50390. *
  50391. * echarts.registerMap('USA', {
  50392. * geoJson: geoJson,
  50393. * specialAreas: {...}
  50394. * });
  50395. * echarts.registerMap('USA', {
  50396. * geoJSON: geoJson,
  50397. * specialAreas: {...}
  50398. * });
  50399. *
  50400. * echarts.registerMap('airport', {
  50401. * svg: svg
  50402. * }
  50403. * ```
  50404. *
  50405. * Note:
  50406. * Do not support that register multiple geoJSON or SVG
  50407. * one map name. Because different geoJSON and SVG have
  50408. * different unit. It's not easy to make sure how those
  50409. * units are mapping/normalize.
  50410. * If intending to use multiple geoJSON or SVG, we can
  50411. * use multiple geo coordinate system.
  50412. */
  50413. registerMap: function (mapName, rawDef, rawSpecialAreas) {
  50414. if (rawDef.svg) {
  50415. var resource = new GeoSVGResource(mapName, rawDef.svg);
  50416. storage.set(mapName, resource);
  50417. } else {
  50418. // Recommend:
  50419. // echarts.registerMap('eu', { geoJSON: xxx, specialAreas: xxx });
  50420. // Backward compatibility:
  50421. // echarts.registerMap('eu', geoJSON, specialAreas);
  50422. // echarts.registerMap('eu', { geoJson: xxx, specialAreas: xxx });
  50423. var geoJSON = rawDef.geoJson || rawDef.geoJSON;
  50424. if (geoJSON && !rawDef.features) {
  50425. rawSpecialAreas = rawDef.specialAreas;
  50426. } else {
  50427. geoJSON = rawDef;
  50428. }
  50429. var resource = new GeoJSONResource(mapName, geoJSON, rawSpecialAreas);
  50430. storage.set(mapName, resource);
  50431. }
  50432. },
  50433. getGeoResource: function (mapName) {
  50434. return storage.get(mapName);
  50435. },
  50436. /**
  50437. * Only for exporting to users.
  50438. * **MUST NOT** used internally.
  50439. */
  50440. getMapForUser: function (mapName) {
  50441. var resource = storage.get(mapName);
  50442. // Do not support return SVG until some real requirement come.
  50443. return resource && resource.type === 'geoJSON' && resource.getMapForUser();
  50444. },
  50445. load: function (mapName, nameMap, nameProperty) {
  50446. var resource = storage.get(mapName);
  50447. if (!resource) {
  50448. if ("development" !== 'production') {
  50449. console.error('Map ' + mapName + ' not exists. The GeoJSON of the map must be provided.');
  50450. }
  50451. return;
  50452. }
  50453. return resource.load(nameMap, nameProperty);
  50454. }
  50455. };
  50456. /**
  50457. * Only these tags enable use `itemStyle` if they are named in SVG.
  50458. * Other tags like <text> <tspan> <image> might not suitable for `itemStyle`.
  50459. * They will not be considered to be styled until some requirements come.
  50460. */
  50461. var OPTION_STYLE_ENABLED_TAGS = ['rect', 'circle', 'line', 'ellipse', 'polygon', 'polyline', 'path'];
  50462. var OPTION_STYLE_ENABLED_TAG_MAP = createHashMap(OPTION_STYLE_ENABLED_TAGS);
  50463. var STATE_TRIGGER_TAG_MAP = createHashMap(OPTION_STYLE_ENABLED_TAGS.concat(['g']));
  50464. var LABEL_HOST_MAP = createHashMap(OPTION_STYLE_ENABLED_TAGS.concat(['g']));
  50465. var mapLabelRaw = makeInner();
  50466. function getFixedItemStyle(model) {
  50467. var itemStyle = model.getItemStyle();
  50468. var areaColor = model.get('areaColor');
  50469. // If user want the color not to be changed when hover,
  50470. // they should both set areaColor and color to be null.
  50471. if (areaColor != null) {
  50472. itemStyle.fill = areaColor;
  50473. }
  50474. return itemStyle;
  50475. }
  50476. // Only stroke can be used for line.
  50477. // Using fill in style if stroke not exits.
  50478. // TODO Not sure yet. Perhaps a separate `lineStyle`?
  50479. function fixLineStyle(styleHost) {
  50480. var style = styleHost.style;
  50481. if (style) {
  50482. style.stroke = style.stroke || style.fill;
  50483. style.fill = null;
  50484. }
  50485. }
  50486. var MapDraw = /** @class */function () {
  50487. function MapDraw(api) {
  50488. var group = this.group = new Group();
  50489. var transformGroup = this._transformGroup = new Group();
  50490. group.add(transformGroup);
  50491. this.uid = getUID('ec_map_draw');
  50492. this._controller = new RoamController(api.getZr());
  50493. this._controllerHost = {
  50494. target: transformGroup
  50495. };
  50496. transformGroup.add(this._regionsGroup = new Group());
  50497. transformGroup.add(this._svgGroup = new Group());
  50498. }
  50499. MapDraw.prototype.draw = function (mapOrGeoModel, ecModel, api, fromView, payload) {
  50500. var isGeo = mapOrGeoModel.mainType === 'geo';
  50501. // Map series has data. GEO model that controlled by map series
  50502. // will be assigned with map data. Other GEO model has no data.
  50503. var data = mapOrGeoModel.getData && mapOrGeoModel.getData();
  50504. isGeo && ecModel.eachComponent({
  50505. mainType: 'series',
  50506. subType: 'map'
  50507. }, function (mapSeries) {
  50508. if (!data && mapSeries.getHostGeoModel() === mapOrGeoModel) {
  50509. data = mapSeries.getData();
  50510. }
  50511. });
  50512. var geo = mapOrGeoModel.coordinateSystem;
  50513. var regionsGroup = this._regionsGroup;
  50514. var transformGroup = this._transformGroup;
  50515. var transformInfo = geo.getTransformInfo();
  50516. var transformInfoRaw = transformInfo.raw;
  50517. var transformInfoRoam = transformInfo.roam;
  50518. // No animation when first draw or in action
  50519. var isFirstDraw = !regionsGroup.childAt(0) || payload;
  50520. var clip = mapOrGeoModel.getShallow('clip', true);
  50521. var clipRect;
  50522. if (clip) {
  50523. clipRect = geo.getViewRect().clone();
  50524. this.group.setClipPath(new Rect({
  50525. shape: clipRect.clone()
  50526. }));
  50527. } else {
  50528. this.group.removeClipPath();
  50529. }
  50530. if (isFirstDraw) {
  50531. transformGroup.x = transformInfoRoam.x;
  50532. transformGroup.y = transformInfoRoam.y;
  50533. transformGroup.scaleX = transformInfoRoam.scaleX;
  50534. transformGroup.scaleY = transformInfoRoam.scaleY;
  50535. transformGroup.dirty();
  50536. } else {
  50537. updateProps(transformGroup, transformInfoRoam, mapOrGeoModel);
  50538. }
  50539. var isVisualEncodedByVisualMap = data && data.getVisual('visualMeta') && data.getVisual('visualMeta').length > 0;
  50540. var viewBuildCtx = {
  50541. api: api,
  50542. geo: geo,
  50543. mapOrGeoModel: mapOrGeoModel,
  50544. data: data,
  50545. isVisualEncodedByVisualMap: isVisualEncodedByVisualMap,
  50546. isGeo: isGeo,
  50547. transformInfoRaw: transformInfoRaw
  50548. };
  50549. if (geo.resourceType === 'geoJSON') {
  50550. this._buildGeoJSON(viewBuildCtx);
  50551. } else if (geo.resourceType === 'geoSVG') {
  50552. this._buildSVG(viewBuildCtx);
  50553. }
  50554. this._updateController(mapOrGeoModel, clipRect, ecModel, api);
  50555. this._updateMapSelectHandler(mapOrGeoModel, regionsGroup, api, fromView);
  50556. };
  50557. MapDraw.prototype._buildGeoJSON = function (viewBuildCtx) {
  50558. var regionsGroupByName = this._regionsGroupByName = createHashMap();
  50559. var regionsInfoByName = createHashMap();
  50560. var regionsGroup = this._regionsGroup;
  50561. var transformInfoRaw = viewBuildCtx.transformInfoRaw;
  50562. var mapOrGeoModel = viewBuildCtx.mapOrGeoModel;
  50563. var data = viewBuildCtx.data;
  50564. var projection = viewBuildCtx.geo.projection;
  50565. var projectionStream = projection && projection.stream;
  50566. function transformPoint(point, project) {
  50567. if (project) {
  50568. // projection may return null point.
  50569. point = project(point);
  50570. }
  50571. return point && [point[0] * transformInfoRaw.scaleX + transformInfoRaw.x, point[1] * transformInfoRaw.scaleY + transformInfoRaw.y];
  50572. }
  50573. function transformPolygonPoints(inPoints) {
  50574. var outPoints = [];
  50575. // If projectionStream is provided. Use it instead of single point project.
  50576. var project = !projectionStream && projection && projection.project;
  50577. for (var i = 0; i < inPoints.length; ++i) {
  50578. var newPt = transformPoint(inPoints[i], project);
  50579. newPt && outPoints.push(newPt);
  50580. }
  50581. return outPoints;
  50582. }
  50583. function getPolyShape(points) {
  50584. return {
  50585. shape: {
  50586. points: transformPolygonPoints(points)
  50587. }
  50588. };
  50589. }
  50590. regionsGroup.removeAll();
  50591. // Only when the resource is GeoJSON, there is `geo.regions`.
  50592. each(viewBuildCtx.geo.regions, function (region) {
  50593. var regionName = region.name;
  50594. // Consider in GeoJson properties.name may be duplicated, for example,
  50595. // there is multiple region named "United Kindom" or "France" (so many
  50596. // colonies). And it is not appropriate to merge them in geo, which
  50597. // will make them share the same label and bring trouble in label
  50598. // location calculation.
  50599. var regionGroup = regionsGroupByName.get(regionName);
  50600. var _a = regionsInfoByName.get(regionName) || {},
  50601. dataIdx = _a.dataIdx,
  50602. regionModel = _a.regionModel;
  50603. if (!regionGroup) {
  50604. regionGroup = regionsGroupByName.set(regionName, new Group());
  50605. regionsGroup.add(regionGroup);
  50606. dataIdx = data ? data.indexOfName(regionName) : null;
  50607. regionModel = viewBuildCtx.isGeo ? mapOrGeoModel.getRegionModel(regionName) : data ? data.getItemModel(dataIdx) : null;
  50608. var silent = regionModel.get('silent', true);
  50609. silent != null && (regionGroup.silent = silent);
  50610. regionsInfoByName.set(regionName, {
  50611. dataIdx: dataIdx,
  50612. regionModel: regionModel
  50613. });
  50614. }
  50615. var polygonSubpaths = [];
  50616. var polylineSubpaths = [];
  50617. each(region.geometries, function (geometry) {
  50618. // Polygon and MultiPolygon
  50619. if (geometry.type === 'polygon') {
  50620. var polys = [geometry.exterior].concat(geometry.interiors || []);
  50621. if (projectionStream) {
  50622. polys = projectPolys(polys, projectionStream);
  50623. }
  50624. each(polys, function (poly) {
  50625. polygonSubpaths.push(new Polygon(getPolyShape(poly)));
  50626. });
  50627. }
  50628. // LineString and MultiLineString
  50629. else {
  50630. var points = geometry.points;
  50631. if (projectionStream) {
  50632. points = projectPolys(points, projectionStream, true);
  50633. }
  50634. each(points, function (points) {
  50635. polylineSubpaths.push(new Polyline(getPolyShape(points)));
  50636. });
  50637. }
  50638. });
  50639. var centerPt = transformPoint(region.getCenter(), projection && projection.project);
  50640. function createCompoundPath(subpaths, isLine) {
  50641. if (!subpaths.length) {
  50642. return;
  50643. }
  50644. var compoundPath = new CompoundPath({
  50645. culling: true,
  50646. segmentIgnoreThreshold: 1,
  50647. shape: {
  50648. paths: subpaths
  50649. }
  50650. });
  50651. regionGroup.add(compoundPath);
  50652. applyOptionStyleForRegion(viewBuildCtx, compoundPath, dataIdx, regionModel);
  50653. resetLabelForRegion(viewBuildCtx, compoundPath, regionName, regionModel, mapOrGeoModel, dataIdx, centerPt);
  50654. if (isLine) {
  50655. fixLineStyle(compoundPath);
  50656. each(compoundPath.states, fixLineStyle);
  50657. }
  50658. }
  50659. createCompoundPath(polygonSubpaths);
  50660. createCompoundPath(polylineSubpaths, true);
  50661. });
  50662. // Ensure children have been added to `regionGroup` before calling them.
  50663. regionsGroupByName.each(function (regionGroup, regionName) {
  50664. var _a = regionsInfoByName.get(regionName),
  50665. dataIdx = _a.dataIdx,
  50666. regionModel = _a.regionModel;
  50667. resetEventTriggerForRegion(viewBuildCtx, regionGroup, regionName, regionModel, mapOrGeoModel, dataIdx);
  50668. resetTooltipForRegion(viewBuildCtx, regionGroup, regionName, regionModel, mapOrGeoModel);
  50669. resetStateTriggerForRegion(viewBuildCtx, regionGroup, regionName, regionModel, mapOrGeoModel);
  50670. }, this);
  50671. };
  50672. MapDraw.prototype._buildSVG = function (viewBuildCtx) {
  50673. var mapName = viewBuildCtx.geo.map;
  50674. var transformInfoRaw = viewBuildCtx.transformInfoRaw;
  50675. this._svgGroup.x = transformInfoRaw.x;
  50676. this._svgGroup.y = transformInfoRaw.y;
  50677. this._svgGroup.scaleX = transformInfoRaw.scaleX;
  50678. this._svgGroup.scaleY = transformInfoRaw.scaleY;
  50679. if (this._svgResourceChanged(mapName)) {
  50680. this._freeSVG();
  50681. this._useSVG(mapName);
  50682. }
  50683. var svgDispatcherMap = this._svgDispatcherMap = createHashMap();
  50684. var focusSelf = false;
  50685. each(this._svgGraphicRecord.named, function (namedItem) {
  50686. // Note that we also allow different elements have the same name.
  50687. // For example, a glyph of a city and the label of the city have
  50688. // the same name and their tooltip info can be defined in a single
  50689. // region option.
  50690. var regionName = namedItem.name;
  50691. var mapOrGeoModel = viewBuildCtx.mapOrGeoModel;
  50692. var data = viewBuildCtx.data;
  50693. var svgNodeTagLower = namedItem.svgNodeTagLower;
  50694. var el = namedItem.el;
  50695. var dataIdx = data ? data.indexOfName(regionName) : null;
  50696. var regionModel = mapOrGeoModel.getRegionModel(regionName);
  50697. if (OPTION_STYLE_ENABLED_TAG_MAP.get(svgNodeTagLower) != null && el instanceof Displayable) {
  50698. applyOptionStyleForRegion(viewBuildCtx, el, dataIdx, regionModel);
  50699. }
  50700. if (el instanceof Displayable) {
  50701. el.culling = true;
  50702. }
  50703. var silent = regionModel.get('silent', true);
  50704. silent != null && (el.silent = silent);
  50705. // We do not know how the SVG like so we'd better not to change z2.
  50706. // Otherwise it might bring some unexpected result. For example,
  50707. // an area hovered that make some inner city can not be clicked.
  50708. el.z2EmphasisLift = 0;
  50709. // If self named:
  50710. if (!namedItem.namedFrom) {
  50711. // label should batter to be displayed based on the center of <g>
  50712. // if it is named rather than displayed on each child.
  50713. if (LABEL_HOST_MAP.get(svgNodeTagLower) != null) {
  50714. resetLabelForRegion(viewBuildCtx, el, regionName, regionModel, mapOrGeoModel, dataIdx, null);
  50715. }
  50716. resetEventTriggerForRegion(viewBuildCtx, el, regionName, regionModel, mapOrGeoModel, dataIdx);
  50717. resetTooltipForRegion(viewBuildCtx, el, regionName, regionModel, mapOrGeoModel);
  50718. if (STATE_TRIGGER_TAG_MAP.get(svgNodeTagLower) != null) {
  50719. var focus_1 = resetStateTriggerForRegion(viewBuildCtx, el, regionName, regionModel, mapOrGeoModel);
  50720. if (focus_1 === 'self') {
  50721. focusSelf = true;
  50722. }
  50723. var els = svgDispatcherMap.get(regionName) || svgDispatcherMap.set(regionName, []);
  50724. els.push(el);
  50725. }
  50726. }
  50727. }, this);
  50728. this._enableBlurEntireSVG(focusSelf, viewBuildCtx);
  50729. };
  50730. MapDraw.prototype._enableBlurEntireSVG = function (focusSelf, viewBuildCtx) {
  50731. // It's a little complicated to support blurring the entire geoSVG in series-map.
  50732. // So do not support it until some requirements come.
  50733. // At present, in series-map, only regions can be blurred.
  50734. if (focusSelf && viewBuildCtx.isGeo) {
  50735. var blurStyle = viewBuildCtx.mapOrGeoModel.getModel(['blur', 'itemStyle']).getItemStyle();
  50736. // Only support `opacity` here. Because not sure that other props are suitable for
  50737. // all of the elements generated by SVG (especially for Text/TSpan/Image/... ).
  50738. var opacity_1 = blurStyle.opacity;
  50739. this._svgGraphicRecord.root.traverse(function (el) {
  50740. if (!el.isGroup) {
  50741. // PENDING: clear those settings to SVG elements when `_freeSVG`.
  50742. // (Currently it happen not to be needed.)
  50743. setDefaultStateProxy(el);
  50744. var style = el.ensureState('blur').style || {};
  50745. // Do not overwrite the region style that already set from region option.
  50746. if (style.opacity == null && opacity_1 != null) {
  50747. style.opacity = opacity_1;
  50748. }
  50749. // If `ensureState('blur').style = {}`, there will be default opacity.
  50750. // Enable `stateTransition` (animation).
  50751. el.ensureState('emphasis');
  50752. }
  50753. });
  50754. }
  50755. };
  50756. MapDraw.prototype.remove = function () {
  50757. this._regionsGroup.removeAll();
  50758. this._regionsGroupByName = null;
  50759. this._svgGroup.removeAll();
  50760. this._freeSVG();
  50761. this._controller.dispose();
  50762. this._controllerHost = null;
  50763. };
  50764. MapDraw.prototype.findHighDownDispatchers = function (name, geoModel) {
  50765. if (name == null) {
  50766. return [];
  50767. }
  50768. var geo = geoModel.coordinateSystem;
  50769. if (geo.resourceType === 'geoJSON') {
  50770. var regionsGroupByName = this._regionsGroupByName;
  50771. if (regionsGroupByName) {
  50772. var regionGroup = regionsGroupByName.get(name);
  50773. return regionGroup ? [regionGroup] : [];
  50774. }
  50775. } else if (geo.resourceType === 'geoSVG') {
  50776. return this._svgDispatcherMap && this._svgDispatcherMap.get(name) || [];
  50777. }
  50778. };
  50779. MapDraw.prototype._svgResourceChanged = function (mapName) {
  50780. return this._svgMapName !== mapName;
  50781. };
  50782. MapDraw.prototype._useSVG = function (mapName) {
  50783. var resource = geoSourceManager.getGeoResource(mapName);
  50784. if (resource && resource.type === 'geoSVG') {
  50785. var svgGraphic = resource.useGraphic(this.uid);
  50786. this._svgGroup.add(svgGraphic.root);
  50787. this._svgGraphicRecord = svgGraphic;
  50788. this._svgMapName = mapName;
  50789. }
  50790. };
  50791. MapDraw.prototype._freeSVG = function () {
  50792. var mapName = this._svgMapName;
  50793. if (mapName == null) {
  50794. return;
  50795. }
  50796. var resource = geoSourceManager.getGeoResource(mapName);
  50797. if (resource && resource.type === 'geoSVG') {
  50798. resource.freeGraphic(this.uid);
  50799. }
  50800. this._svgGraphicRecord = null;
  50801. this._svgDispatcherMap = null;
  50802. this._svgGroup.removeAll();
  50803. this._svgMapName = null;
  50804. };
  50805. MapDraw.prototype._updateController = function (mapOrGeoModel, clipRect, ecModel, api) {
  50806. var geo = mapOrGeoModel.coordinateSystem;
  50807. var controller = this._controller;
  50808. var controllerHost = this._controllerHost;
  50809. controllerHost.zoomLimit = mapOrGeoModel.get('scaleLimit');
  50810. controllerHost.zoom = geo.getZoom();
  50811. // roamType is will be set default true if it is null
  50812. controller.enable(mapOrGeoModel.get('roam') || false, {
  50813. api: api,
  50814. zInfo: {
  50815. component: mapOrGeoModel
  50816. },
  50817. triggerInfo: {
  50818. roamTrigger: mapOrGeoModel.get('roamTrigger'),
  50819. isInSelf: function (e, x, y) {
  50820. return geo.containPoint([x, y]);
  50821. },
  50822. isInClip: function (e, x, y) {
  50823. return !clipRect || clipRect.contain(x, y);
  50824. }
  50825. }
  50826. });
  50827. var mainType = mapOrGeoModel.mainType;
  50828. function makeActionBase() {
  50829. var action = {
  50830. type: 'geoRoam',
  50831. componentType: mainType
  50832. };
  50833. action[mainType + 'Id'] = mapOrGeoModel.id;
  50834. return action;
  50835. }
  50836. controller.off('pan').on('pan', function (e) {
  50837. this._mouseDownFlag = false;
  50838. updateViewOnPan(controllerHost, e.dx, e.dy);
  50839. api.dispatchAction(extend(makeActionBase(), {
  50840. dx: e.dx,
  50841. dy: e.dy,
  50842. animation: {
  50843. duration: 0
  50844. }
  50845. }));
  50846. }, this);
  50847. controller.off('zoom').on('zoom', function (e) {
  50848. this._mouseDownFlag = false;
  50849. updateViewOnZoom(controllerHost, e.scale, e.originX, e.originY);
  50850. api.dispatchAction(extend(makeActionBase(), {
  50851. totalZoom: controllerHost.zoom,
  50852. zoom: e.scale,
  50853. originX: e.originX,
  50854. originY: e.originY,
  50855. animation: {
  50856. duration: 0
  50857. }
  50858. }));
  50859. }, this);
  50860. };
  50861. /**
  50862. * FIXME: this is a temporarily workaround.
  50863. * When `geoRoam` the elements need to be reset in `MapView['render']`, because the props like
  50864. * `ignore` might have been modified by `LabelManager`, and `LabelManager#addLabelsOfSeries`
  50865. * will subsequently cache `defaultAttr` like `ignore`. If do not do this reset, the modified
  50866. * props will have no chance to be restored.
  50867. * Note: This reset should be after `clearStates` in `renderSeries` because `useStates` in
  50868. * `renderSeries` will cache the modified `ignore` to `el._normalState`.
  50869. * TODO:
  50870. * Use clone/immutable in `LabelManager`?
  50871. */
  50872. MapDraw.prototype.resetForLabelLayout = function () {
  50873. this.group.traverse(function (el) {
  50874. var label = el.getTextContent();
  50875. if (label) {
  50876. label.ignore = mapLabelRaw(label).ignore;
  50877. }
  50878. });
  50879. };
  50880. MapDraw.prototype._updateMapSelectHandler = function (mapOrGeoModel, regionsGroup, api, fromView) {
  50881. var mapDraw = this;
  50882. regionsGroup.off('mousedown');
  50883. regionsGroup.off('click');
  50884. // @ts-ignore FIXME:TS resolve type conflict
  50885. if (mapOrGeoModel.get('selectedMode')) {
  50886. regionsGroup.on('mousedown', function () {
  50887. mapDraw._mouseDownFlag = true;
  50888. });
  50889. regionsGroup.on('click', function (e) {
  50890. if (!mapDraw._mouseDownFlag) {
  50891. return;
  50892. }
  50893. mapDraw._mouseDownFlag = false;
  50894. });
  50895. }
  50896. };
  50897. return MapDraw;
  50898. }();
  50899. function applyOptionStyleForRegion(viewBuildCtx, el, dataIndex, regionModel) {
  50900. // All of the path are using `itemStyle`, because
  50901. // (1) Some SVG also use fill on polyline (The different between
  50902. // polyline and polygon is "open" or "close" but not fill or not).
  50903. // (2) For the common props like opacity, if some use itemStyle
  50904. // and some use `lineStyle`, it might confuse users.
  50905. // (3) Most SVG use <path>, where can not detect whether to draw a "line"
  50906. // or a filled shape, so use `itemStyle` for <path>.
  50907. var normalStyleModel = regionModel.getModel('itemStyle');
  50908. var emphasisStyleModel = regionModel.getModel(['emphasis', 'itemStyle']);
  50909. var blurStyleModel = regionModel.getModel(['blur', 'itemStyle']);
  50910. var selectStyleModel = regionModel.getModel(['select', 'itemStyle']);
  50911. // NOTE: DON'T use 'style' in visual when drawing map.
  50912. // This component is used for drawing underlying map for both geo component and map series.
  50913. var normalStyle = getFixedItemStyle(normalStyleModel);
  50914. var emphasisStyle = getFixedItemStyle(emphasisStyleModel);
  50915. var selectStyle = getFixedItemStyle(selectStyleModel);
  50916. var blurStyle = getFixedItemStyle(blurStyleModel);
  50917. // Update the itemStyle if has data visual
  50918. var data = viewBuildCtx.data;
  50919. if (data) {
  50920. // Only visual color of each item will be used. It can be encoded by visualMap
  50921. // But visual color of series is used in symbol drawing
  50922. // Visual color for each series is for the symbol draw
  50923. var style = data.getItemVisual(dataIndex, 'style');
  50924. var decal = data.getItemVisual(dataIndex, 'decal');
  50925. if (viewBuildCtx.isVisualEncodedByVisualMap && style.fill) {
  50926. normalStyle.fill = style.fill;
  50927. }
  50928. if (decal) {
  50929. normalStyle.decal = createOrUpdatePatternFromDecal(decal, viewBuildCtx.api);
  50930. }
  50931. }
  50932. // SVG text, tspan and image can be named but not supporeted
  50933. // to be styled by region option yet.
  50934. el.setStyle(normalStyle);
  50935. el.style.strokeNoScale = true;
  50936. el.ensureState('emphasis').style = emphasisStyle;
  50937. el.ensureState('select').style = selectStyle;
  50938. el.ensureState('blur').style = blurStyle;
  50939. // Enable blur
  50940. setDefaultStateProxy(el);
  50941. }
  50942. function resetLabelForRegion(viewBuildCtx, el, regionName, regionModel, mapOrGeoModel,
  50943. // Exist only if `viewBuildCtx.data` exists.
  50944. dataIdx,
  50945. // If labelXY not provided, use `textConfig.position: 'inside'`
  50946. labelXY) {
  50947. var data = viewBuildCtx.data;
  50948. var isGeo = viewBuildCtx.isGeo;
  50949. var isDataNaN = data && isNaN(data.get(data.mapDimension('value'), dataIdx));
  50950. var itemLayout = data && data.getItemLayout(dataIdx);
  50951. // In the following cases label will be drawn
  50952. // 1. In map series and data value is NaN
  50953. // 2. In geo component
  50954. // 3. Region has no series legendIcon, which will be add a showLabel flag in mapSymbolLayout
  50955. if (isGeo || isDataNaN || itemLayout && itemLayout.showLabel) {
  50956. var query = !isGeo ? dataIdx : regionName;
  50957. var labelFetcher = void 0;
  50958. // Consider dataIdx not found.
  50959. if (!data || dataIdx >= 0) {
  50960. labelFetcher = mapOrGeoModel;
  50961. }
  50962. var specifiedTextOpt = labelXY ? {
  50963. normal: {
  50964. align: 'center',
  50965. verticalAlign: 'middle'
  50966. }
  50967. } : null;
  50968. // Caveat: must be called after `setDefaultStateProxy(el);` called.
  50969. // because textContent will be assign with `el.stateProxy` inside.
  50970. setLabelStyle(el, getLabelStatesModels(regionModel), {
  50971. labelFetcher: labelFetcher,
  50972. labelDataIndex: query,
  50973. defaultText: regionName
  50974. }, specifiedTextOpt);
  50975. var textEl = el.getTextContent();
  50976. if (textEl) {
  50977. mapLabelRaw(textEl).ignore = textEl.ignore;
  50978. if (el.textConfig && labelXY) {
  50979. // Compute a relative offset based on the el bounding rect.
  50980. var rect = el.getBoundingRect().clone();
  50981. // Need to make sure the percent position base on the same rect in normal and
  50982. // emphasis state. Otherwise if using boundingRect of el, but the emphasis state
  50983. // has borderWidth (even 0.5px), the text position will be changed obviously
  50984. // if the position is very big like ['1234%', '1345%'].
  50985. el.textConfig.layoutRect = rect;
  50986. el.textConfig.position = [(labelXY[0] - rect.x) / rect.width * 100 + '%', (labelXY[1] - rect.y) / rect.height * 100 + '%'];
  50987. }
  50988. }
  50989. // PENDING:
  50990. // If labelLayout is enabled (test/label-layout.html), el.dataIndex should be specified.
  50991. // But el.dataIndex is also used to determine whether user event should be triggered,
  50992. // where el.seriesIndex or el.dataModel must be specified. At present for a single el
  50993. // there is not case that "only label layout enabled but user event disabled", so here
  50994. // we depends `resetEventTriggerForRegion` to do the job of setting `el.dataIndex`.
  50995. el.disableLabelAnimation = true;
  50996. } else {
  50997. el.removeTextContent();
  50998. el.removeTextConfig();
  50999. el.disableLabelAnimation = null;
  51000. }
  51001. }
  51002. function resetEventTriggerForRegion(viewBuildCtx, eventTrigger, regionName, regionModel, mapOrGeoModel,
  51003. // Exist only if `viewBuildCtx.data` exists.
  51004. dataIdx) {
  51005. // setItemGraphicEl, setHoverStyle after all polygons and labels
  51006. // are added to the regionGroup
  51007. if (viewBuildCtx.data) {
  51008. // FIXME: when series-map use a SVG map, and there are duplicated name specified
  51009. // on different SVG elements, after `data.setItemGraphicEl(...)`:
  51010. // (1) all of them will be mounted with `dataIndex`, `seriesIndex`, so that tooltip
  51011. // can be triggered only mouse hover. That's correct.
  51012. // (2) only the last element will be kept in `data`, so that if trigger tooltip
  51013. // by `dispatchAction`, only the last one can be found and triggered. That might be
  51014. // not correct. We will fix it in future if anyone demanding that.
  51015. viewBuildCtx.data.setItemGraphicEl(dataIdx, eventTrigger);
  51016. }
  51017. // series-map will not trigger "geoselectchange" no matter it is
  51018. // based on a declared geo component. Because series-map will
  51019. // trigger "selectchange". If it trigger both the two events,
  51020. // If users call `chart.dispatchAction({type: 'toggleSelect'})`,
  51021. // it not easy to also fire event "geoselectchanged".
  51022. else {
  51023. // Package custom mouse event for geo component
  51024. getECData(eventTrigger).eventData = {
  51025. componentType: 'geo',
  51026. componentIndex: mapOrGeoModel.componentIndex,
  51027. geoIndex: mapOrGeoModel.componentIndex,
  51028. name: regionName,
  51029. region: regionModel && regionModel.option || {}
  51030. };
  51031. }
  51032. }
  51033. function resetTooltipForRegion(viewBuildCtx, el, regionName, regionModel, mapOrGeoModel) {
  51034. if (!viewBuildCtx.data) {
  51035. setTooltipConfig({
  51036. el: el,
  51037. componentModel: mapOrGeoModel,
  51038. itemName: regionName,
  51039. // @ts-ignore FIXME:TS fix the "compatible with each other"?
  51040. itemTooltipOption: regionModel.get('tooltip')
  51041. });
  51042. }
  51043. }
  51044. function resetStateTriggerForRegion(viewBuildCtx, el, regionName, regionModel, mapOrGeoModel) {
  51045. // @ts-ignore FIXME:TS fix the "compatible with each other"?
  51046. el.highDownSilentOnTouch = !!mapOrGeoModel.get('selectedMode');
  51047. // @ts-ignore FIXME:TS fix the "compatible with each other"?
  51048. var emphasisModel = regionModel.getModel('emphasis');
  51049. var focus = emphasisModel.get('focus');
  51050. toggleHoverEmphasis(el, focus, emphasisModel.get('blurScope'), emphasisModel.get('disabled'));
  51051. if (viewBuildCtx.isGeo) {
  51052. enableComponentHighDownFeatures(el, mapOrGeoModel, regionName);
  51053. }
  51054. return focus;
  51055. }
  51056. function projectPolys(rings,
  51057. // Polygons include exterior and interiors. Or polylines.
  51058. createStream, isLine) {
  51059. var polygons = [];
  51060. var curPoly;
  51061. function startPolygon() {
  51062. curPoly = [];
  51063. }
  51064. function endPolygon() {
  51065. if (curPoly.length) {
  51066. polygons.push(curPoly);
  51067. curPoly = [];
  51068. }
  51069. }
  51070. var stream = createStream({
  51071. polygonStart: startPolygon,
  51072. polygonEnd: endPolygon,
  51073. lineStart: startPolygon,
  51074. lineEnd: endPolygon,
  51075. point: function (x, y) {
  51076. // May have NaN values from stream.
  51077. if (isFinite(x) && isFinite(y)) {
  51078. curPoly.push([x, y]);
  51079. }
  51080. },
  51081. sphere: function () {}
  51082. });
  51083. !isLine && stream.polygonStart();
  51084. each(rings, function (ring) {
  51085. stream.lineStart();
  51086. for (var i = 0; i < ring.length; i++) {
  51087. stream.point(ring[i][0], ring[i][1]);
  51088. }
  51089. stream.lineEnd();
  51090. });
  51091. !isLine && stream.polygonEnd();
  51092. return polygons;
  51093. }
  51094. // @ts-ignore FIXME:TS fix the "compatible with each other"?
  51095. var MapView = /** @class */function (_super) {
  51096. __extends(MapView, _super);
  51097. function MapView() {
  51098. var _this = _super !== null && _super.apply(this, arguments) || this;
  51099. _this.type = MapView.type;
  51100. return _this;
  51101. }
  51102. MapView.prototype.render = function (mapModel, ecModel, api, payload) {
  51103. // Not render if it is an toggleSelect action from self
  51104. if (payload && payload.type === 'mapToggleSelect' && payload.from === this.uid) {
  51105. return;
  51106. }
  51107. var group = this.group;
  51108. group.removeAll();
  51109. if (mapModel.getHostGeoModel()) {
  51110. return;
  51111. }
  51112. if (this._mapDraw && payload && payload.type === 'geoRoam') {
  51113. this._mapDraw.resetForLabelLayout();
  51114. }
  51115. // Not update map if it is an roam action from self
  51116. if (!(payload && payload.type === 'geoRoam' && payload.componentType === 'series' && payload.seriesId === mapModel.id)) {
  51117. if (mapModel.needsDrawMap) {
  51118. var mapDraw = this._mapDraw || new MapDraw(api);
  51119. group.add(mapDraw.group);
  51120. mapDraw.draw(mapModel, ecModel, api, this, payload);
  51121. this._mapDraw = mapDraw;
  51122. } else {
  51123. // Remove drawn map
  51124. this._mapDraw && this._mapDraw.remove();
  51125. this._mapDraw = null;
  51126. }
  51127. } else {
  51128. var mapDraw = this._mapDraw;
  51129. mapDraw && group.add(mapDraw.group);
  51130. }
  51131. mapModel.get('showLegendSymbol') && ecModel.getComponent('legend') && this._renderSymbols(mapModel, ecModel, api);
  51132. };
  51133. MapView.prototype.remove = function () {
  51134. this._mapDraw && this._mapDraw.remove();
  51135. this._mapDraw = null;
  51136. this.group.removeAll();
  51137. };
  51138. MapView.prototype.dispose = function () {
  51139. this._mapDraw && this._mapDraw.remove();
  51140. this._mapDraw = null;
  51141. };
  51142. MapView.prototype._renderSymbols = function (mapModel, ecModel, api) {
  51143. var originalData = mapModel.originalData;
  51144. var group = this.group;
  51145. originalData.each(originalData.mapDimension('value'), function (value, originalDataIndex) {
  51146. if (isNaN(value)) {
  51147. return;
  51148. }
  51149. var layout = originalData.getItemLayout(originalDataIndex);
  51150. if (!layout || !layout.point) {
  51151. // Not exists in map
  51152. return;
  51153. }
  51154. var point = layout.point;
  51155. var offset = layout.offset;
  51156. var circle = new Circle({
  51157. style: {
  51158. // Because the special of map draw.
  51159. // Which needs statistic of multiple series and draw on one map.
  51160. // And each series also need a symbol with legend color
  51161. //
  51162. // Layout and visual are put one the different data
  51163. // TODO
  51164. fill: mapModel.getData().getVisual('style').fill
  51165. },
  51166. shape: {
  51167. cx: point[0] + offset * 9,
  51168. cy: point[1],
  51169. r: 3
  51170. },
  51171. silent: true,
  51172. // Do not overlap the first series, on which labels are displayed.
  51173. z2: 8 + (!offset ? Z2_EMPHASIS_LIFT + 1 : 0)
  51174. });
  51175. // Only the series that has the first value on the same region is in charge of rendering the label.
  51176. // But consider the case:
  51177. // series: [
  51178. // {id: 'X', type: 'map', map: 'm', {data: [{name: 'A', value: 11}, {name: 'B', {value: 22}]},
  51179. // {id: 'Y', type: 'map', map: 'm', {data: [{name: 'A', value: 21}, {name: 'C', {value: 33}]}
  51180. // ]
  51181. // The offset `0` of item `A` is at series `X`, but of item `C` is at series `Y`.
  51182. // For backward compatibility, we follow the rule that render label `A` by the
  51183. // settings on series `X` but render label `C` by the settings on series `Y`.
  51184. if (!offset) {
  51185. var fullData = mapModel.mainSeries.getData();
  51186. var name_1 = originalData.getName(originalDataIndex);
  51187. var fullIndex_1 = fullData.indexOfName(name_1);
  51188. var itemModel = originalData.getItemModel(originalDataIndex);
  51189. var labelModel = itemModel.getModel('label');
  51190. var regionGroup = fullData.getItemGraphicEl(fullIndex_1);
  51191. // `getFormattedLabel` needs to use `getData` inside. Here
  51192. // `mapModel.getData()` is shallow cloned from `mainSeries.getData()`.
  51193. // FIXME
  51194. // If this is not the `mainSeries`, the item model (like label formatter)
  51195. // set on original data item will never get. But it has been working
  51196. // like that from the beginning, and this scenario is rarely encountered.
  51197. // So it won't be fixed until we have to.
  51198. setLabelStyle(circle, getLabelStatesModels(itemModel), {
  51199. labelFetcher: {
  51200. getFormattedLabel: function (idx, state) {
  51201. return mapModel.getFormattedLabel(fullIndex_1, state);
  51202. }
  51203. },
  51204. defaultText: name_1
  51205. });
  51206. circle.disableLabelAnimation = true;
  51207. if (!labelModel.get('position')) {
  51208. circle.setTextConfig({
  51209. position: 'bottom'
  51210. });
  51211. }
  51212. regionGroup.onHoverStateChange = function (toState) {
  51213. setStatesFlag(circle, toState);
  51214. };
  51215. }
  51216. group.add(circle);
  51217. });
  51218. };
  51219. MapView.type = 'map';
  51220. return MapView;
  51221. }(ChartView);
  51222. var MapSeries = /** @class */function (_super) {
  51223. __extends(MapSeries, _super);
  51224. function MapSeries() {
  51225. var _this = _super !== null && _super.apply(this, arguments) || this;
  51226. _this.type = MapSeries.type;
  51227. // Only first map series of same mapType will drawMap.
  51228. _this.needsDrawMap = false;
  51229. // Group of all map series with same mapType
  51230. _this.seriesGroup = [];
  51231. _this.getTooltipPosition = function (dataIndex) {
  51232. if (dataIndex != null) {
  51233. var name_1 = this.getData().getName(dataIndex);
  51234. var geo = this.coordinateSystem;
  51235. var region = geo.getRegion(name_1);
  51236. return region && geo.dataToPoint(region.getCenter());
  51237. }
  51238. };
  51239. return _this;
  51240. }
  51241. MapSeries.prototype.getInitialData = function (option) {
  51242. var data = createSeriesDataSimply(this, {
  51243. coordDimensions: ['value'],
  51244. encodeDefaulter: curry(makeSeriesEncodeForNameBased, this)
  51245. });
  51246. var dataNameIndexMap = createHashMap();
  51247. var toAppendItems = [];
  51248. for (var i = 0, len = data.count(); i < len; i++) {
  51249. var name_2 = data.getName(i);
  51250. dataNameIndexMap.set(name_2, i);
  51251. }
  51252. var geoSource = geoSourceManager.load(this.getMapType(), this.option.nameMap, this.option.nameProperty);
  51253. each(geoSource.regions, function (region) {
  51254. var name = region.name;
  51255. var dataNameIdx = dataNameIndexMap.get(name);
  51256. // apply specified echarts style in GeoJSON data
  51257. var specifiedGeoJSONRegionStyle = region.properties && region.properties.echartsStyle;
  51258. var dataItem;
  51259. if (dataNameIdx == null) {
  51260. dataItem = {
  51261. name: name
  51262. };
  51263. toAppendItems.push(dataItem);
  51264. } else {
  51265. dataItem = data.getRawDataItem(dataNameIdx);
  51266. }
  51267. specifiedGeoJSONRegionStyle && merge(dataItem, specifiedGeoJSONRegionStyle);
  51268. });
  51269. // Complete data with missing regions. The consequent processes (like visual
  51270. // map and render) can not be performed without a "full data". For example,
  51271. // find `dataIndex` by name.
  51272. data.appendData(toAppendItems);
  51273. return data;
  51274. };
  51275. /**
  51276. * If no host geo model, return null, which means using a
  51277. * inner exclusive geo model.
  51278. */
  51279. MapSeries.prototype.getHostGeoModel = function () {
  51280. if (decideCoordSysUsageKind(this).kind === CoordinateSystemUsageKind.boxCoordSys) {
  51281. // Always use an internal geo if specify a boxCoordSys.
  51282. // Notice that currently we do not support laying out a geo based on
  51283. // another geo, but preserve the possibility.
  51284. return;
  51285. }
  51286. return this.getReferringComponents('geo', {
  51287. useDefault: false,
  51288. enableAll: false,
  51289. enableNone: false
  51290. }).models[0];
  51291. };
  51292. MapSeries.prototype.getMapType = function () {
  51293. return (this.getHostGeoModel() || this).option.map;
  51294. };
  51295. // _fillOption(option, mapName) {
  51296. // Shallow clone
  51297. // option = zrUtil.extend({}, option);
  51298. // option.data = geoCreator.getFilledRegions(option.data, mapName, option.nameMap);
  51299. // return option;
  51300. // }
  51301. MapSeries.prototype.getRawValue = function (dataIndex) {
  51302. // Use value stored in data instead because it is calculated from multiple series
  51303. // FIXME Provide all value of multiple series ?
  51304. var data = this.getData();
  51305. return data.get(data.mapDimension('value'), dataIndex);
  51306. };
  51307. /**
  51308. * Get model of region
  51309. */
  51310. MapSeries.prototype.getRegionModel = function (regionName) {
  51311. var data = this.getData();
  51312. return data.getItemModel(data.indexOfName(regionName));
  51313. };
  51314. /**
  51315. * Map tooltip formatter
  51316. */
  51317. MapSeries.prototype.formatTooltip = function (dataIndex, multipleSeries, dataType) {
  51318. // FIXME orignalData and data is a bit confusing
  51319. var data = this.getData();
  51320. var value = this.getRawValue(dataIndex);
  51321. var name = data.getName(dataIndex);
  51322. var seriesGroup = this.seriesGroup;
  51323. var seriesNames = [];
  51324. for (var i = 0; i < seriesGroup.length; i++) {
  51325. var otherIndex = seriesGroup[i].originalData.indexOfName(name);
  51326. var valueDim = data.mapDimension('value');
  51327. if (!isNaN(seriesGroup[i].originalData.get(valueDim, otherIndex))) {
  51328. seriesNames.push(seriesGroup[i].name);
  51329. }
  51330. }
  51331. return createTooltipMarkup('section', {
  51332. header: seriesNames.join(', '),
  51333. noHeader: !seriesNames.length,
  51334. blocks: [createTooltipMarkup('nameValue', {
  51335. name: name,
  51336. value: value
  51337. })]
  51338. });
  51339. };
  51340. MapSeries.prototype.setZoom = function (zoom) {
  51341. this.option.zoom = zoom;
  51342. };
  51343. MapSeries.prototype.setCenter = function (center) {
  51344. this.option.center = center;
  51345. };
  51346. MapSeries.prototype.getLegendIcon = function (opt) {
  51347. var iconType = opt.icon || 'roundRect';
  51348. var icon = createSymbol(iconType, 0, 0, opt.itemWidth, opt.itemHeight, opt.itemStyle.fill);
  51349. icon.setStyle(opt.itemStyle);
  51350. // Map do not use itemStyle.borderWidth as border width
  51351. icon.style.stroke = 'none';
  51352. // No rotation because no series visual symbol for map
  51353. if (iconType.indexOf('empty') > -1) {
  51354. icon.style.stroke = icon.style.fill;
  51355. icon.style.fill = tokens.color.neutral00;
  51356. icon.style.lineWidth = 2;
  51357. }
  51358. return icon;
  51359. };
  51360. MapSeries.type = 'series.map';
  51361. MapSeries.dependencies = ['geo'];
  51362. MapSeries.layoutMode = 'box';
  51363. MapSeries.defaultOption = {
  51364. // 一级层叠
  51365. // zlevel: 0,
  51366. // 二级层叠
  51367. z: 2,
  51368. coordinateSystem: 'geo',
  51369. // map should be explicitly specified since ec3.
  51370. map: '',
  51371. // If `geoIndex` is not specified, a exclusive geo will be
  51372. // created. Otherwise use the specified geo component, and
  51373. // `map` and `mapType` are ignored.
  51374. // geoIndex: 0,
  51375. // 'center' | 'left' | 'right' | 'x%' | {number}
  51376. left: 'center',
  51377. // 'center' | 'top' | 'bottom' | 'x%' | {number}
  51378. top: 'center',
  51379. // right
  51380. // bottom
  51381. // width:
  51382. // height
  51383. // Aspect is width / height. Inited to be geoJson bbox aspect
  51384. // This parameter is used for scale this aspect
  51385. // Default value:
  51386. // for geoSVG source: 1,
  51387. // for geoJSON source: 0.75.
  51388. aspectScale: null,
  51389. // Layout with center and size
  51390. // If you want to put map in a fixed size box with right aspect ratio
  51391. // This two properties may be more convenient.
  51392. // layoutCenter: [50%, 50%]
  51393. // layoutSize: 100
  51394. showLegendSymbol: true,
  51395. // Define left-top, right-bottom coords to control view
  51396. // For example, [ [180, 90], [-180, -90] ],
  51397. // higher priority than center and zoom
  51398. boundingCoords: null,
  51399. // Default on center of map
  51400. center: null,
  51401. zoom: 1,
  51402. scaleLimit: null,
  51403. selectedMode: true,
  51404. label: {
  51405. show: false,
  51406. color: tokens.color.tertiary
  51407. },
  51408. // scaleLimit: null,
  51409. itemStyle: {
  51410. borderWidth: 0.5,
  51411. borderColor: tokens.color.border,
  51412. areaColor: tokens.color.background
  51413. },
  51414. emphasis: {
  51415. label: {
  51416. show: true,
  51417. color: tokens.color.primary
  51418. },
  51419. itemStyle: {
  51420. areaColor: tokens.color.highlight
  51421. }
  51422. },
  51423. select: {
  51424. label: {
  51425. show: true,
  51426. color: tokens.color.primary
  51427. },
  51428. itemStyle: {
  51429. color: tokens.color.highlight
  51430. }
  51431. },
  51432. nameProperty: 'name'
  51433. };
  51434. return MapSeries;
  51435. }(SeriesModel);
  51436. // FIXME 公用?
  51437. function dataStatistics(datas, statisticType) {
  51438. var dataNameMap = {};
  51439. each(datas, function (data) {
  51440. data.each(data.mapDimension('value'), function (value, idx) {
  51441. // Add prefix to avoid conflict with Object.prototype.
  51442. var mapKey = 'ec-' + data.getName(idx);
  51443. dataNameMap[mapKey] = dataNameMap[mapKey] || [];
  51444. if (!isNaN(value)) {
  51445. dataNameMap[mapKey].push(value);
  51446. }
  51447. });
  51448. });
  51449. return datas[0].map(datas[0].mapDimension('value'), function (value, idx) {
  51450. var mapKey = 'ec-' + datas[0].getName(idx);
  51451. var sum = 0;
  51452. var min = Infinity;
  51453. var max = -Infinity;
  51454. var len = dataNameMap[mapKey].length;
  51455. for (var i = 0; i < len; i++) {
  51456. min = Math.min(min, dataNameMap[mapKey][i]);
  51457. max = Math.max(max, dataNameMap[mapKey][i]);
  51458. sum += dataNameMap[mapKey][i];
  51459. }
  51460. var result;
  51461. if (statisticType === 'min') {
  51462. result = min;
  51463. } else if (statisticType === 'max') {
  51464. result = max;
  51465. } else if (statisticType === 'average') {
  51466. result = sum / len;
  51467. } else {
  51468. result = sum;
  51469. }
  51470. return len === 0 ? NaN : result;
  51471. });
  51472. }
  51473. function mapDataStatistic(ecModel) {
  51474. var seriesGroups = {};
  51475. ecModel.eachSeriesByType('map', function (seriesModel) {
  51476. var hostGeoModel = seriesModel.getHostGeoModel();
  51477. var key = hostGeoModel ? 'o' + hostGeoModel.id : 'i' + seriesModel.getMapType();
  51478. (seriesGroups[key] = seriesGroups[key] || []).push(seriesModel);
  51479. });
  51480. each(seriesGroups, function (seriesList, key) {
  51481. var data = dataStatistics(map(seriesList, function (seriesModel) {
  51482. return seriesModel.getData();
  51483. }), seriesList[0].get('mapValueCalculation'));
  51484. for (var i = 0; i < seriesList.length; i++) {
  51485. seriesList[i].originalData = seriesList[i].getData();
  51486. }
  51487. // FIXME Put where?
  51488. for (var i = 0; i < seriesList.length; i++) {
  51489. seriesList[i].seriesGroup = seriesList;
  51490. seriesList[i].needsDrawMap = i === 0 && !seriesList[i].getHostGeoModel();
  51491. seriesList[i].setData(data.cloneShallow());
  51492. seriesList[i].mainSeries = seriesList[0];
  51493. }
  51494. });
  51495. }
  51496. function mapSymbolLayout(ecModel) {
  51497. var processedMapType = {};
  51498. ecModel.eachSeriesByType('map', function (mapSeries) {
  51499. var mapType = mapSeries.getMapType();
  51500. if (mapSeries.getHostGeoModel() || processedMapType[mapType]) {
  51501. return;
  51502. }
  51503. var mapSymbolOffsets = {};
  51504. each(mapSeries.seriesGroup, function (subMapSeries) {
  51505. var geo = subMapSeries.coordinateSystem;
  51506. var data = subMapSeries.originalData;
  51507. if (subMapSeries.get('showLegendSymbol') && ecModel.getComponent('legend')) {
  51508. data.each(data.mapDimension('value'), function (value, idx) {
  51509. var name = data.getName(idx);
  51510. var region = geo.getRegion(name);
  51511. // If input series.data is [11, 22, '-'/null/undefined, 44],
  51512. // it will be filled with NaN: [11, 22, NaN, 44] and NaN will
  51513. // not be drawn. So here must validate if value is NaN.
  51514. if (!region || isNaN(value)) {
  51515. return;
  51516. }
  51517. var offset = mapSymbolOffsets[name] || 0;
  51518. var point = geo.dataToPoint(region.getCenter());
  51519. mapSymbolOffsets[name] = offset + 1;
  51520. data.setItemLayout(idx, {
  51521. point: point,
  51522. offset: offset
  51523. });
  51524. });
  51525. }
  51526. });
  51527. // Show label of those region not has legendIcon (which is offset 0)
  51528. var data = mapSeries.getData();
  51529. data.each(function (idx) {
  51530. var name = data.getName(idx);
  51531. var layout = data.getItemLayout(idx) || {};
  51532. layout.showLabel = !mapSymbolOffsets[name];
  51533. data.setItemLayout(idx, layout);
  51534. });
  51535. processedMapType[mapType] = true;
  51536. });
  51537. }
  51538. var v2ApplyTransform = applyTransform;
  51539. var View = /** @class */function (_super) {
  51540. __extends(View, _super);
  51541. function View(name, opt) {
  51542. var _this = _super.call(this) || this;
  51543. _this.type = 'view';
  51544. _this.dimensions = ['x', 'y'];
  51545. /**
  51546. * Represents the transform brought by roam/zoom.
  51547. * If `View['_viewRect']` applies roam transform,
  51548. * we can get the final displayed rect.
  51549. */
  51550. _this._roamTransformable = new Transformable();
  51551. /**
  51552. * Represents the transform from `View['_rect']` to `View['_viewRect']`.
  51553. */
  51554. _this._rawTransformable = new Transformable();
  51555. _this.name = name;
  51556. _this._opt = opt;
  51557. return _this;
  51558. }
  51559. View.prototype.setBoundingRect = function (x, y, width, height) {
  51560. this._rect = new BoundingRect(x, y, width, height);
  51561. this._updateCenterAndZoom();
  51562. return this._rect;
  51563. };
  51564. View.prototype.getBoundingRect = function () {
  51565. return this._rect;
  51566. };
  51567. /**
  51568. * If no need to transform `View['_rect']` to `View['_viewRect']`, the calling of
  51569. * `setViewRect` can be omitted.
  51570. */
  51571. View.prototype.setViewRect = function (x, y, width, height) {
  51572. this._transformTo(x, y, width, height);
  51573. this._viewRect = new BoundingRect(x, y, width, height);
  51574. };
  51575. /**
  51576. * Transformed to particular position and size
  51577. */
  51578. View.prototype._transformTo = function (x, y, width, height) {
  51579. var rect = this.getBoundingRect();
  51580. var rawTransform = this._rawTransformable;
  51581. rawTransform.transform = rect.calculateTransform(new BoundingRect(x, y, width, height));
  51582. var rawParent = rawTransform.parent;
  51583. rawTransform.parent = null;
  51584. rawTransform.decomposeTransform();
  51585. rawTransform.parent = rawParent;
  51586. this._updateTransform();
  51587. };
  51588. /**
  51589. * [NOTICE]
  51590. * The definition of this center has always been irrelevant to some other series center like
  51591. * 'series-pie.center' - this center is a point on the same coord sys as `View['_rect'].x/y`,
  51592. * rather than canvas viewport, and the unit is not necessarily pixel (e.g., in geo case).
  51593. * @see {View['_center']} for details.
  51594. */
  51595. View.prototype.setCenter = function (centerCoord) {
  51596. // #16904 introcuded percentage string here, such as '33%'. But it was based on canvas
  51597. // width/height, which is not reasonable - the unit may incorrect, and it is unpredictable if
  51598. // the `View['_rect']` is not calculated based on the current canvas rect. Therefore the percentage
  51599. // value is changed to based on `View['_rect'].width/height` since v6. Under this definition, users
  51600. // can use '0%' to map the top-left of `View['_rect']` to the center of `View['_viewRect']`.
  51601. var opt = this._opt;
  51602. if (opt && opt.api && opt.ecModel && opt.ecModel.getShallow('legacyViewCoordSysCenterBase') && centerCoord) {
  51603. centerCoord = [parsePercent$1(centerCoord[0], opt.api.getWidth()), parsePercent$1(centerCoord[1], opt.api.getWidth())];
  51604. }
  51605. this._centerOption = clone(centerCoord);
  51606. this._updateCenterAndZoom();
  51607. };
  51608. View.prototype.setZoom = function (zoom) {
  51609. this._zoom = clampByZoomLimit(zoom || 1, this.zoomLimit);
  51610. this._updateCenterAndZoom();
  51611. };
  51612. /**
  51613. * Get default center without roam
  51614. */
  51615. View.prototype.getDefaultCenter = function () {
  51616. // Rect before any transform
  51617. var rawRect = this.getBoundingRect();
  51618. var cx = rawRect.x + rawRect.width / 2;
  51619. var cy = rawRect.y + rawRect.height / 2;
  51620. return [cx, cy];
  51621. };
  51622. View.prototype.getCenter = function () {
  51623. return this._center || this.getDefaultCenter();
  51624. };
  51625. View.prototype.getZoom = function () {
  51626. return this._zoom || 1;
  51627. };
  51628. View.prototype.getRoamTransform = function () {
  51629. return this._roamTransformable.getLocalTransform();
  51630. };
  51631. /**
  51632. * Ensure this method is idempotent, since it should be called when
  51633. * every relevant prop (e.g. _centerOption/_zoom/_rect/_viewRect) changed.
  51634. */
  51635. View.prototype._updateCenterAndZoom = function () {
  51636. var centerOption = this._centerOption;
  51637. var rect = this._rect;
  51638. if (centerOption && rect) {
  51639. this._center = [parsePercent$1(centerOption[0], rect.width, rect.x), parsePercent$1(centerOption[1], rect.height, rect.y)];
  51640. }
  51641. // Must update after view transform updated
  51642. var rawTransformMatrix = this._rawTransformable.getLocalTransform();
  51643. var roamTransform = this._roamTransformable;
  51644. var defaultCenter = this.getDefaultCenter();
  51645. var center = this.getCenter();
  51646. var zoom = this.getZoom();
  51647. center = applyTransform([], center, rawTransformMatrix);
  51648. defaultCenter = applyTransform([], defaultCenter, rawTransformMatrix);
  51649. roamTransform.originX = center[0];
  51650. roamTransform.originY = center[1];
  51651. roamTransform.x = defaultCenter[0] - center[0];
  51652. roamTransform.y = defaultCenter[1] - center[1];
  51653. roamTransform.scaleX = roamTransform.scaleY = zoom;
  51654. this._updateTransform();
  51655. };
  51656. /**
  51657. * Update transform props on `this` based on the current
  51658. * `this._roamTransformable` and `this._rawTransformable`.
  51659. */
  51660. View.prototype._updateTransform = function () {
  51661. var roamTransformable = this._roamTransformable;
  51662. var rawTransformable = this._rawTransformable;
  51663. rawTransformable.parent = roamTransformable;
  51664. roamTransformable.updateTransform();
  51665. rawTransformable.updateTransform();
  51666. copy$1(this.transform || (this.transform = []), rawTransformable.transform || create$1());
  51667. this._rawTransform = rawTransformable.getLocalTransform();
  51668. this.invTransform = this.invTransform || [];
  51669. invert(this.invTransform, this.transform);
  51670. this.decomposeTransform();
  51671. };
  51672. View.prototype.getTransformInfo = function () {
  51673. var rawTransformable = this._rawTransformable;
  51674. var roamTransformable = this._roamTransformable;
  51675. // Because roamTransformabel has `originX/originY` modified,
  51676. // but the caller of `getTransformInfo` can not handle `originX/originY`,
  51677. // so need to recalculate them.
  51678. var dummyTransformable = new Transformable();
  51679. dummyTransformable.transform = roamTransformable.transform;
  51680. dummyTransformable.decomposeTransform();
  51681. return {
  51682. roam: {
  51683. x: dummyTransformable.x,
  51684. y: dummyTransformable.y,
  51685. scaleX: dummyTransformable.scaleX,
  51686. scaleY: dummyTransformable.scaleY
  51687. },
  51688. raw: {
  51689. x: rawTransformable.x,
  51690. y: rawTransformable.y,
  51691. scaleX: rawTransformable.scaleX,
  51692. scaleY: rawTransformable.scaleY
  51693. }
  51694. };
  51695. };
  51696. View.prototype.getViewRect = function () {
  51697. return this._viewRect;
  51698. };
  51699. /**
  51700. * Get view rect after roam transform
  51701. */
  51702. View.prototype.getViewRectAfterRoam = function () {
  51703. var rect = this.getBoundingRect().clone();
  51704. rect.applyTransform(this.transform);
  51705. return rect;
  51706. };
  51707. /**
  51708. * Convert a single (lon, lat) data item to (x, y) point.
  51709. */
  51710. View.prototype.dataToPoint = function (data, noRoam, out) {
  51711. var transform = noRoam ? this._rawTransform : this.transform;
  51712. out = out || [];
  51713. return transform ? v2ApplyTransform(out, data, transform) : copy(out, data);
  51714. };
  51715. /**
  51716. * Convert a (x, y) point to (lon, lat) data
  51717. */
  51718. View.prototype.pointToData = function (point, reserved, out) {
  51719. out = out || [];
  51720. var invTransform = this.invTransform;
  51721. return invTransform ? v2ApplyTransform(out, point, invTransform) : (out[0] = point[0], out[1] = point[1], out);
  51722. };
  51723. View.prototype.convertToPixel = function (ecModel, finder, value) {
  51724. var coordSys = getCoordSys(finder);
  51725. return coordSys === this ? coordSys.dataToPoint(value) : null;
  51726. };
  51727. View.prototype.convertFromPixel = function (ecModel, finder, pixel) {
  51728. var coordSys = getCoordSys(finder);
  51729. return coordSys === this ? coordSys.pointToData(pixel) : null;
  51730. };
  51731. /**
  51732. * @implements
  51733. */
  51734. View.prototype.containPoint = function (point) {
  51735. return this.getViewRectAfterRoam().contain(point[0], point[1]);
  51736. };
  51737. View.dimensions = ['x', 'y'];
  51738. return View;
  51739. }(Transformable);
  51740. function getCoordSys(finder) {
  51741. var seriesModel = finder.seriesModel;
  51742. return seriesModel ? seriesModel.coordinateSystem : null; // e.g., graph.
  51743. }
  51744. var GEO_DEFAULT_PARAMS = {
  51745. 'geoJSON': {
  51746. aspectScale: 0.75,
  51747. invertLongitute: true
  51748. },
  51749. 'geoSVG': {
  51750. aspectScale: 1,
  51751. invertLongitute: false
  51752. }
  51753. };
  51754. var geo2DDimensions = ['lng', 'lat'];
  51755. var Geo = /** @class */function (_super) {
  51756. __extends(Geo, _super);
  51757. function Geo(name, map, opt) {
  51758. var _this = _super.call(this, name, {
  51759. api: opt.api,
  51760. ecModel: opt.ecModel
  51761. }) || this;
  51762. _this.dimensions = geo2DDimensions;
  51763. _this.type = 'geo';
  51764. // Only store specified name coord via `addGeoCoord`.
  51765. _this._nameCoordMap = createHashMap();
  51766. _this.map = map;
  51767. var projection = opt.projection;
  51768. var source = geoSourceManager.load(map, opt.nameMap, opt.nameProperty);
  51769. var resource = geoSourceManager.getGeoResource(map);
  51770. var resourceType = _this.resourceType = resource ? resource.type : null;
  51771. var regions = _this.regions = source.regions;
  51772. var defaultParams = GEO_DEFAULT_PARAMS[resource.type];
  51773. _this._regionsMap = source.regionsMap;
  51774. _this.regions = source.regions;
  51775. if ("development" !== 'production' && projection) {
  51776. // Do some check
  51777. if (resourceType === 'geoSVG') {
  51778. if ("development" !== 'production') {
  51779. warn("Map " + map + " with SVG source can't use projection. Only GeoJSON source supports projection.");
  51780. }
  51781. projection = null;
  51782. }
  51783. if (!(projection.project && projection.unproject)) {
  51784. if ("development" !== 'production') {
  51785. warn('project and unproject must be both provided in the projeciton.');
  51786. }
  51787. projection = null;
  51788. }
  51789. }
  51790. _this.projection = projection;
  51791. var boundingRect;
  51792. if (projection) {
  51793. // Can't reuse the raw bounding rect
  51794. for (var i = 0; i < regions.length; i++) {
  51795. var regionRect = regions[i].getBoundingRect(projection);
  51796. boundingRect = boundingRect || regionRect.clone();
  51797. boundingRect.union(regionRect);
  51798. }
  51799. } else {
  51800. boundingRect = source.boundingRect;
  51801. }
  51802. _this.setBoundingRect(boundingRect.x, boundingRect.y, boundingRect.width, boundingRect.height);
  51803. // aspectScale and invertLongitute actually is the parameters default raw projection.
  51804. // So we ignore them if projection is given.
  51805. // Ignore default aspect scale if projection exits.
  51806. _this.aspectScale = projection ? 1 : retrieve2(opt.aspectScale, defaultParams.aspectScale);
  51807. // Not invert longitude if projection exits.
  51808. _this._invertLongitute = projection ? false : defaultParams.invertLongitute;
  51809. return _this;
  51810. }
  51811. Geo.prototype._transformTo = function (x, y, width, height) {
  51812. var rect = this.getBoundingRect();
  51813. var invertLongitute = this._invertLongitute;
  51814. rect = rect.clone();
  51815. if (invertLongitute) {
  51816. // Longitude is inverted.
  51817. rect.y = -rect.y - rect.height;
  51818. }
  51819. var rawTransformable = this._rawTransformable;
  51820. rawTransformable.transform = rect.calculateTransform(new BoundingRect(x, y, width, height));
  51821. var rawParent = rawTransformable.parent;
  51822. rawTransformable.parent = null;
  51823. rawTransformable.decomposeTransform();
  51824. rawTransformable.parent = rawParent;
  51825. if (invertLongitute) {
  51826. rawTransformable.scaleY = -rawTransformable.scaleY;
  51827. }
  51828. this._updateTransform();
  51829. };
  51830. Geo.prototype.getRegion = function (name) {
  51831. return this._regionsMap.get(name);
  51832. };
  51833. Geo.prototype.getRegionByCoord = function (coord) {
  51834. var regions = this.regions;
  51835. for (var i = 0; i < regions.length; i++) {
  51836. var region = regions[i];
  51837. if (region.type === 'geoJSON' && region.contain(coord)) {
  51838. return regions[i];
  51839. }
  51840. }
  51841. };
  51842. /**
  51843. * Add geoCoord for indexing by name
  51844. */
  51845. Geo.prototype.addGeoCoord = function (name, geoCoord) {
  51846. this._nameCoordMap.set(name, geoCoord);
  51847. };
  51848. /**
  51849. * Get geoCoord by name
  51850. */
  51851. Geo.prototype.getGeoCoord = function (name) {
  51852. var region = this._regionsMap.get(name);
  51853. // Calculate center only on demand.
  51854. return this._nameCoordMap.get(name) || region && region.getCenter();
  51855. };
  51856. Geo.prototype.dataToPoint = function (data, noRoam, out) {
  51857. if (isString(data)) {
  51858. // Map area name to geoCoord
  51859. data = this.getGeoCoord(data);
  51860. }
  51861. if (data) {
  51862. var projection = this.projection;
  51863. if (projection) {
  51864. // projection may return null point.
  51865. data = projection.project(data);
  51866. }
  51867. return data && this.projectedToPoint(data, noRoam, out);
  51868. }
  51869. };
  51870. Geo.prototype.pointToData = function (point, reserved, out) {
  51871. var projection = this.projection;
  51872. if (projection) {
  51873. // projection may return null point.
  51874. point = projection.unproject(point);
  51875. }
  51876. // FIXME: if no `point`, should return [NaN, NaN], rather than undefined.
  51877. // null/undefined has special meaning in `convertFromPixel`.
  51878. return point && this.pointToProjected(point, out);
  51879. };
  51880. /**
  51881. * Point to projected data. Same with pointToData when projection is used.
  51882. */
  51883. Geo.prototype.pointToProjected = function (point, out) {
  51884. return _super.prototype.pointToData.call(this, point, 0, out);
  51885. };
  51886. Geo.prototype.projectedToPoint = function (projected, noRoam, out) {
  51887. return _super.prototype.dataToPoint.call(this, projected, noRoam, out);
  51888. };
  51889. Geo.prototype.convertToPixel = function (ecModel, finder, value) {
  51890. var coordSys = getCoordSys$1(finder);
  51891. return coordSys === this ? coordSys.dataToPoint(value) : null;
  51892. };
  51893. Geo.prototype.convertFromPixel = function (ecModel, finder, pixel) {
  51894. var coordSys = getCoordSys$1(finder);
  51895. return coordSys === this ? coordSys.pointToData(pixel) : null;
  51896. };
  51897. return Geo;
  51898. }(View);
  51899. mixin(Geo, View);
  51900. function getCoordSys$1(finder) {
  51901. var geoModel = finder.geoModel;
  51902. var seriesModel = finder.seriesModel;
  51903. return geoModel ? geoModel.coordinateSystem : seriesModel ? seriesModel.coordinateSystem // For map series.
  51904. || (seriesModel.getReferringComponents('geo', SINGLE_REFERRING).models[0] || {}).coordinateSystem : null;
  51905. }
  51906. /**
  51907. * Resize method bound to the geo
  51908. */
  51909. function resizeGeo(geoModel, api) {
  51910. var boundingCoords = geoModel.get('boundingCoords');
  51911. if (boundingCoords != null) {
  51912. var leftTop_1 = boundingCoords[0];
  51913. var rightBottom_1 = boundingCoords[1];
  51914. if (!(isFinite(leftTop_1[0]) && isFinite(leftTop_1[1]) && isFinite(rightBottom_1[0]) && isFinite(rightBottom_1[1]))) {
  51915. if ("development" !== 'production') {
  51916. console.error('Invalid boundingCoords');
  51917. }
  51918. } else {
  51919. // Sample around the lng/lat rect and use projection to calculate actual bounding rect.
  51920. var projection_1 = this.projection;
  51921. if (projection_1) {
  51922. var xMin = leftTop_1[0];
  51923. var yMin = leftTop_1[1];
  51924. var xMax = rightBottom_1[0];
  51925. var yMax = rightBottom_1[1];
  51926. leftTop_1 = [Infinity, Infinity];
  51927. rightBottom_1 = [-Infinity, -Infinity];
  51928. // TODO better way?
  51929. var sampleLine = function (x0, y0, x1, y1) {
  51930. var dx = x1 - x0;
  51931. var dy = y1 - y0;
  51932. for (var i = 0; i <= 100; i++) {
  51933. var p = i / 100;
  51934. var pt = projection_1.project([x0 + dx * p, y0 + dy * p]);
  51935. min(leftTop_1, leftTop_1, pt);
  51936. max(rightBottom_1, rightBottom_1, pt);
  51937. }
  51938. };
  51939. // Top
  51940. sampleLine(xMin, yMin, xMax, yMin);
  51941. // Right
  51942. sampleLine(xMax, yMin, xMax, yMax);
  51943. // Bottom
  51944. sampleLine(xMax, yMax, xMin, yMax);
  51945. // Left
  51946. sampleLine(xMin, yMax, xMax, yMin);
  51947. }
  51948. this.setBoundingRect(leftTop_1[0], leftTop_1[1], rightBottom_1[0] - leftTop_1[0], rightBottom_1[1] - leftTop_1[1]);
  51949. }
  51950. }
  51951. var rect = this.getBoundingRect();
  51952. var centerOption = geoModel.get('layoutCenter');
  51953. var sizeOption = geoModel.get('layoutSize');
  51954. // Laying out geo on `dataCoordSys`, such as cartesian, works theoretically but not supported yet.
  51955. // Therefore here we only handle cases that laying out on `boxCoordSys`, such as matrix/calendar.
  51956. var refContainer = createBoxLayoutReference(geoModel, api).refContainer;
  51957. var aspect = rect.width / rect.height * this.aspectScale;
  51958. var useCenterAndSize = false;
  51959. var center;
  51960. var size;
  51961. if (centerOption && sizeOption) {
  51962. center = [parsePercent$1(centerOption[0], refContainer.width) + refContainer.x, parsePercent$1(centerOption[1], refContainer.height) + refContainer.y];
  51963. size = parsePercent$1(sizeOption, Math.min(refContainer.width, refContainer.height));
  51964. if (!isNaN(center[0]) && !isNaN(center[1]) && !isNaN(size)) {
  51965. useCenterAndSize = true;
  51966. } else {
  51967. if ("development" !== 'production') {
  51968. console.warn('Given layoutCenter or layoutSize data are invalid. Use left/top/width/height instead.');
  51969. }
  51970. }
  51971. }
  51972. var viewRect;
  51973. if (useCenterAndSize) {
  51974. viewRect = {};
  51975. if (aspect > 1) {
  51976. // Width is same with size
  51977. viewRect.width = size;
  51978. viewRect.height = size / aspect;
  51979. } else {
  51980. viewRect.height = size;
  51981. viewRect.width = size * aspect;
  51982. }
  51983. viewRect.y = center[1] - viewRect.height / 2;
  51984. viewRect.x = center[0] - viewRect.width / 2;
  51985. } else {
  51986. // Use left/top/width/height
  51987. var boxLayoutOption = geoModel.getBoxLayoutParams();
  51988. boxLayoutOption.aspect = aspect;
  51989. viewRect = getLayoutRect(boxLayoutOption, refContainer);
  51990. viewRect = applyPreserveAspect(geoModel, viewRect, aspect);
  51991. }
  51992. this.setViewRect(viewRect.x, viewRect.y, viewRect.width, viewRect.height);
  51993. this.setCenter(geoModel.get('center'));
  51994. this.setZoom(geoModel.get('zoom'));
  51995. }
  51996. // Back compat for ECharts2, where the coord map is set on map series:
  51997. // {type: 'map', geoCoord: {'cityA': [116.46,39.92], 'cityA': [119.12,24.61]}},
  51998. function setGeoCoords(geo, model) {
  51999. each(model.get('geoCoord'), function (geoCoord, name) {
  52000. geo.addGeoCoord(name, geoCoord);
  52001. });
  52002. }
  52003. var GeoCreator = /** @class */function () {
  52004. function GeoCreator() {
  52005. // For deciding which dimensions to use when creating list data
  52006. this.dimensions = geo2DDimensions;
  52007. }
  52008. GeoCreator.prototype.create = function (ecModel, api) {
  52009. var geoList = [];
  52010. function getCommonGeoProperties(model) {
  52011. return {
  52012. nameProperty: model.get('nameProperty'),
  52013. aspectScale: model.get('aspectScale'),
  52014. projection: model.get('projection')
  52015. };
  52016. }
  52017. // FIXME Create each time may be slow
  52018. ecModel.eachComponent('geo', function (geoModel, idx) {
  52019. var mapName = geoModel.get('map');
  52020. var geo = new Geo(mapName + idx, mapName, extend({
  52021. nameMap: geoModel.get('nameMap'),
  52022. api: api,
  52023. ecModel: ecModel
  52024. }, getCommonGeoProperties(geoModel)));
  52025. geo.zoomLimit = geoModel.get('scaleLimit');
  52026. geoList.push(geo);
  52027. // setGeoCoords(geo, geoModel);
  52028. geoModel.coordinateSystem = geo;
  52029. geo.model = geoModel;
  52030. // Inject resize method
  52031. geo.resize = resizeGeo;
  52032. geo.resize(geoModel, api);
  52033. });
  52034. ecModel.eachSeries(function (seriesModel) {
  52035. injectCoordSysByOption({
  52036. targetModel: seriesModel,
  52037. coordSysType: 'geo',
  52038. coordSysProvider: function () {
  52039. var geoModel = seriesModel.subType === 'map' ? seriesModel.getHostGeoModel() : seriesModel.getReferringComponents('geo', SINGLE_REFERRING).models[0];
  52040. return geoModel && geoModel.coordinateSystem;
  52041. },
  52042. allowNotFound: true
  52043. });
  52044. });
  52045. // If has map series
  52046. var mapModelGroupBySeries = {};
  52047. ecModel.eachSeriesByType('map', function (seriesModel) {
  52048. if (!seriesModel.getHostGeoModel()) {
  52049. var mapType = seriesModel.getMapType();
  52050. mapModelGroupBySeries[mapType] = mapModelGroupBySeries[mapType] || [];
  52051. mapModelGroupBySeries[mapType].push(seriesModel);
  52052. }
  52053. });
  52054. each(mapModelGroupBySeries, function (mapSeries, mapType) {
  52055. var nameMapList = map(mapSeries, function (singleMapSeries) {
  52056. return singleMapSeries.get('nameMap');
  52057. });
  52058. var geo = new Geo(mapType, mapType, extend({
  52059. nameMap: mergeAll(nameMapList),
  52060. api: api,
  52061. ecModel: ecModel
  52062. }, getCommonGeoProperties(mapSeries[0])));
  52063. geo.zoomLimit = retrieve.apply(null, map(mapSeries, function (singleMapSeries) {
  52064. return singleMapSeries.get('scaleLimit');
  52065. }));
  52066. geoList.push(geo);
  52067. // Inject resize method
  52068. geo.resize = resizeGeo;
  52069. geo.resize(mapSeries[0], api);
  52070. each(mapSeries, function (singleMapSeries) {
  52071. singleMapSeries.coordinateSystem = geo;
  52072. setGeoCoords(geo, singleMapSeries);
  52073. });
  52074. });
  52075. return geoList;
  52076. };
  52077. /**
  52078. * Fill given regions array
  52079. */
  52080. GeoCreator.prototype.getFilledRegions = function (originRegionArr, mapName, nameMap, nameProperty) {
  52081. // Not use the original
  52082. var regionsArr = (originRegionArr || []).slice();
  52083. var dataNameMap = createHashMap();
  52084. for (var i = 0; i < regionsArr.length; i++) {
  52085. dataNameMap.set(regionsArr[i].name, regionsArr[i]);
  52086. }
  52087. var source = geoSourceManager.load(mapName, nameMap, nameProperty);
  52088. each(source.regions, function (region) {
  52089. var name = region.name;
  52090. var regionOption = dataNameMap.get(name);
  52091. // apply specified echarts style in GeoJSON data
  52092. var specifiedGeoJSONRegionStyle = region.properties && region.properties.echartsStyle;
  52093. if (!regionOption) {
  52094. regionOption = {
  52095. name: name
  52096. };
  52097. regionsArr.push(regionOption);
  52098. }
  52099. specifiedGeoJSONRegionStyle && merge(regionOption, specifiedGeoJSONRegionStyle);
  52100. });
  52101. return regionsArr;
  52102. };
  52103. return GeoCreator;
  52104. }();
  52105. var geoCreator = new GeoCreator();
  52106. var GeoModel = /** @class */function (_super) {
  52107. __extends(GeoModel, _super);
  52108. function GeoModel() {
  52109. var _this = _super !== null && _super.apply(this, arguments) || this;
  52110. _this.type = GeoModel.type;
  52111. return _this;
  52112. }
  52113. GeoModel.prototype.init = function (option, parentModel, ecModel) {
  52114. this.mergeDefaultAndTheme(option, ecModel);
  52115. var source = geoSourceManager.getGeoResource(option.map);
  52116. if (source && source.type === 'geoJSON') {
  52117. var itemStyle = option.itemStyle = option.itemStyle || {};
  52118. if (!('color' in itemStyle)) {
  52119. itemStyle.color = option.defaultItemStyleColor || tokens.color.backgroundTint;
  52120. }
  52121. }
  52122. // Default label emphasis `show`
  52123. defaultEmphasis(option, 'label', ['show']);
  52124. };
  52125. GeoModel.prototype.optionUpdated = function () {
  52126. var _this = this;
  52127. var option = this.option;
  52128. option.regions = geoCreator.getFilledRegions(option.regions, option.map, option.nameMap, option.nameProperty);
  52129. var selectedMap = {};
  52130. this._optionModelMap = reduce(option.regions || [], function (optionModelMap, regionOpt) {
  52131. var regionName = regionOpt.name;
  52132. if (regionName) {
  52133. optionModelMap.set(regionName, new Model(regionOpt, _this, _this.ecModel));
  52134. if (regionOpt.selected) {
  52135. selectedMap[regionName] = true;
  52136. }
  52137. }
  52138. return optionModelMap;
  52139. }, createHashMap());
  52140. if (!option.selectedMap) {
  52141. option.selectedMap = selectedMap;
  52142. }
  52143. };
  52144. /**
  52145. * Get model of region.
  52146. */
  52147. GeoModel.prototype.getRegionModel = function (name) {
  52148. return this._optionModelMap.get(name) || new Model(null, this, this.ecModel);
  52149. };
  52150. /**
  52151. * Format label
  52152. * @param name Region name
  52153. */
  52154. GeoModel.prototype.getFormattedLabel = function (name, status) {
  52155. var regionModel = this.getRegionModel(name);
  52156. var formatter = status === 'normal' ? regionModel.get(['label', 'formatter']) : regionModel.get(['emphasis', 'label', 'formatter']);
  52157. var params = {
  52158. name: name
  52159. };
  52160. if (isFunction(formatter)) {
  52161. params.status = status;
  52162. return formatter(params);
  52163. } else if (isString(formatter)) {
  52164. return formatter.replace('{a}', name != null ? name : '');
  52165. }
  52166. };
  52167. GeoModel.prototype.setZoom = function (zoom) {
  52168. this.option.zoom = zoom;
  52169. };
  52170. GeoModel.prototype.setCenter = function (center) {
  52171. this.option.center = center;
  52172. };
  52173. // PENGING If selectedMode is null ?
  52174. GeoModel.prototype.select = function (name) {
  52175. var option = this.option;
  52176. var selectedMode = option.selectedMode;
  52177. if (!selectedMode) {
  52178. return;
  52179. }
  52180. if (selectedMode !== 'multiple') {
  52181. option.selectedMap = null;
  52182. }
  52183. var selectedMap = option.selectedMap || (option.selectedMap = {});
  52184. selectedMap[name] = true;
  52185. };
  52186. GeoModel.prototype.unSelect = function (name) {
  52187. var selectedMap = this.option.selectedMap;
  52188. if (selectedMap) {
  52189. selectedMap[name] = false;
  52190. }
  52191. };
  52192. GeoModel.prototype.toggleSelected = function (name) {
  52193. this[this.isSelected(name) ? 'unSelect' : 'select'](name);
  52194. };
  52195. GeoModel.prototype.isSelected = function (name) {
  52196. var selectedMap = this.option.selectedMap;
  52197. return !!(selectedMap && selectedMap[name]);
  52198. };
  52199. GeoModel.type = 'geo';
  52200. GeoModel.layoutMode = 'box';
  52201. GeoModel.defaultOption = {
  52202. // zlevel: 0,
  52203. z: 0,
  52204. show: true,
  52205. left: 'center',
  52206. top: 'center',
  52207. // Default value:
  52208. // for geoSVG source: 1,
  52209. // for geoJSON source: 0.75.
  52210. aspectScale: null,
  52211. // /// Layout with center and size
  52212. // If you want to put map in a fixed size box with right aspect ratio
  52213. // This two properties may be more convenient
  52214. // layoutCenter: [50%, 50%]
  52215. // layoutSize: 100
  52216. silent: false,
  52217. // Map type
  52218. map: '',
  52219. // Define left-top, right-bottom coords to control view
  52220. // For example, [ [180, 90], [-180, -90] ]
  52221. boundingCoords: null,
  52222. // Default on center of map
  52223. center: null,
  52224. zoom: 1,
  52225. scaleLimit: null,
  52226. // selectedMode: false
  52227. label: {
  52228. show: false,
  52229. color: tokens.color.tertiary
  52230. },
  52231. itemStyle: {
  52232. borderWidth: 0.5,
  52233. borderColor: tokens.color.border
  52234. },
  52235. emphasis: {
  52236. label: {
  52237. show: true,
  52238. color: tokens.color.primary
  52239. },
  52240. itemStyle: {
  52241. color: tokens.color.highlight
  52242. }
  52243. },
  52244. select: {
  52245. label: {
  52246. show: true,
  52247. color: tokens.color.primary
  52248. },
  52249. itemStyle: {
  52250. color: tokens.color.highlight
  52251. }
  52252. },
  52253. regions: []
  52254. // tooltip: {
  52255. // show: false
  52256. // }
  52257. };
  52258. return GeoModel;
  52259. }(ComponentModel);
  52260. var GeoView = /** @class */function (_super) {
  52261. __extends(GeoView, _super);
  52262. function GeoView() {
  52263. var _this = _super !== null && _super.apply(this, arguments) || this;
  52264. _this.type = GeoView.type;
  52265. _this.focusBlurEnabled = true;
  52266. return _this;
  52267. }
  52268. GeoView.prototype.init = function (ecModel, api) {
  52269. this._api = api;
  52270. };
  52271. GeoView.prototype.render = function (geoModel, ecModel, api, payload) {
  52272. this._model = geoModel;
  52273. if (!geoModel.get('show')) {
  52274. this._mapDraw && this._mapDraw.remove();
  52275. this._mapDraw = null;
  52276. return;
  52277. }
  52278. if (!this._mapDraw) {
  52279. this._mapDraw = new MapDraw(api);
  52280. }
  52281. var mapDraw = this._mapDraw;
  52282. mapDraw.draw(geoModel, ecModel, api, this, payload);
  52283. mapDraw.group.on('click', this._handleRegionClick, this);
  52284. mapDraw.group.silent = geoModel.get('silent');
  52285. this.group.add(mapDraw.group);
  52286. this.updateSelectStatus(geoModel, ecModel, api);
  52287. };
  52288. GeoView.prototype._handleRegionClick = function (e) {
  52289. var eventData;
  52290. findEventDispatcher(e.target, function (current) {
  52291. return (eventData = getECData(current).eventData) != null;
  52292. }, true);
  52293. if (eventData) {
  52294. this._api.dispatchAction({
  52295. type: 'geoToggleSelect',
  52296. geoId: this._model.id,
  52297. name: eventData.name
  52298. });
  52299. }
  52300. };
  52301. GeoView.prototype.updateSelectStatus = function (model, ecModel, api) {
  52302. var _this = this;
  52303. this._mapDraw.group.traverse(function (node) {
  52304. var eventData = getECData(node).eventData;
  52305. if (eventData) {
  52306. _this._model.isSelected(eventData.name) ? api.enterSelect(node) : api.leaveSelect(node);
  52307. // No need to traverse children.
  52308. return true;
  52309. }
  52310. });
  52311. };
  52312. GeoView.prototype.findHighDownDispatchers = function (name) {
  52313. return this._mapDraw && this._mapDraw.findHighDownDispatchers(name, this._model);
  52314. };
  52315. GeoView.prototype.dispose = function () {
  52316. this._mapDraw && this._mapDraw.remove();
  52317. };
  52318. GeoView.type = 'geo';
  52319. return GeoView;
  52320. }(ComponentView);
  52321. function registerMap$1(mapName, geoJson, specialAreas) {
  52322. geoSourceManager.registerMap(mapName, geoJson, specialAreas);
  52323. }
  52324. function install$9(registers) {
  52325. registers.registerCoordinateSystem('geo', geoCreator);
  52326. registers.registerComponentModel(GeoModel);
  52327. registers.registerComponentView(GeoView);
  52328. registers.registerImpl('registerMap', registerMap$1);
  52329. registers.registerImpl('getMap', function (mapName) {
  52330. return geoSourceManager.getMapForUser(mapName);
  52331. });
  52332. function makeAction(method, actionInfo) {
  52333. actionInfo.update = 'geo:updateSelectStatus';
  52334. registers.registerAction(actionInfo, function (payload, ecModel) {
  52335. var selected = {};
  52336. var allSelected = [];
  52337. ecModel.eachComponent({
  52338. mainType: 'geo',
  52339. query: payload
  52340. }, function (geoModel) {
  52341. geoModel[method](payload.name);
  52342. var geo = geoModel.coordinateSystem;
  52343. each(geo.regions, function (region) {
  52344. selected[region.name] = geoModel.isSelected(region.name) || false;
  52345. });
  52346. // Notice: there might be duplicated name in different regions.
  52347. var names = [];
  52348. each(selected, function (v, name) {
  52349. selected[name] && names.push(name);
  52350. });
  52351. allSelected.push({
  52352. geoIndex: geoModel.componentIndex,
  52353. // Use singular, the same naming convention as the event `selectchanged`.
  52354. name: names
  52355. });
  52356. });
  52357. return {
  52358. selected: selected,
  52359. allSelected: allSelected,
  52360. name: payload.name
  52361. };
  52362. });
  52363. }
  52364. makeAction('toggleSelected', {
  52365. type: 'geoToggleSelect',
  52366. event: 'geoselectchanged'
  52367. });
  52368. makeAction('select', {
  52369. type: 'geoSelect',
  52370. event: 'geoselected'
  52371. });
  52372. makeAction('unSelect', {
  52373. type: 'geoUnSelect',
  52374. event: 'geounselected'
  52375. });
  52376. /**
  52377. * @payload
  52378. * @property {string} [componentType=series]
  52379. * @property {number} [dx]
  52380. * @property {number} [dy]
  52381. * @property {number} [zoom]
  52382. * @property {number} [originX]
  52383. * @property {number} [originY]
  52384. */
  52385. registers.registerAction({
  52386. type: 'geoRoam',
  52387. event: 'geoRoam',
  52388. update: 'updateTransform'
  52389. }, function (payload, ecModel, api) {
  52390. var componentType = payload.componentType;
  52391. if (!componentType) {
  52392. // backward compat, but `payload.componentType` is deprecated.
  52393. if (payload.geoId != null) {
  52394. componentType = 'geo';
  52395. } else if (payload.seriesId != null) {
  52396. componentType = 'series';
  52397. }
  52398. }
  52399. if (!componentType) {
  52400. componentType = 'series';
  52401. }
  52402. // FIXME: payload.geoId/payload.seriesId should be required, but historically
  52403. // it is not mandatory, causing that all of the geo or series can be queried below,
  52404. // which is not reasonable.
  52405. ecModel.eachComponent({
  52406. mainType: componentType,
  52407. query: payload
  52408. }, function (componentModel) {
  52409. var geo = componentModel.coordinateSystem;
  52410. if (geo.type !== 'geo') {
  52411. return;
  52412. }
  52413. var res = updateCenterAndZoomInAction(geo, payload, componentModel.get('scaleLimit'));
  52414. componentModel.setCenter && componentModel.setCenter(res.center);
  52415. componentModel.setZoom && componentModel.setZoom(res.zoom);
  52416. // All map series with same `map` use the same geo coordinate system
  52417. // So the center and zoom must be in sync. Include the series not selected by legend
  52418. if (componentType === 'series') {
  52419. each(componentModel.seriesGroup, function (seriesModel) {
  52420. seriesModel.setCenter(res.center);
  52421. seriesModel.setZoom(res.zoom);
  52422. });
  52423. }
  52424. });
  52425. });
  52426. }
  52427. function install$a(registers) {
  52428. use(install$9);
  52429. registers.registerChartView(MapView);
  52430. registers.registerSeriesModel(MapSeries);
  52431. registers.registerLayout(mapSymbolLayout);
  52432. registers.registerProcessor(registers.PRIORITY.PROCESSOR.STATISTIC, mapDataStatistic);
  52433. createLegacyDataSelectAction('map', registers.registerAction);
  52434. }
  52435. /*
  52436. * Licensed to the Apache Software Foundation (ASF) under one
  52437. * or more contributor license agreements. See the NOTICE file
  52438. * distributed with this work for additional information
  52439. * regarding copyright ownership. The ASF licenses this file
  52440. * to you under the Apache License, Version 2.0 (the
  52441. * "License"); you may not use this file except in compliance
  52442. * with the License. You may obtain a copy of the License at
  52443. *
  52444. * http://www.apache.org/licenses/LICENSE-2.0
  52445. *
  52446. * Unless required by applicable law or agreed to in writing,
  52447. * software distributed under the License is distributed on an
  52448. * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
  52449. * KIND, either express or implied. See the License for the
  52450. * specific language governing permissions and limitations
  52451. * under the License.
  52452. */
  52453. /**
  52454. * AUTO-GENERATED FILE. DO NOT MODIFY.
  52455. */
  52456. /*
  52457. * Licensed to the Apache Software Foundation (ASF) under one
  52458. * or more contributor license agreements. See the NOTICE file
  52459. * distributed with this work for additional information
  52460. * regarding copyright ownership. The ASF licenses this file
  52461. * to you under the Apache License, Version 2.0 (the
  52462. * "License"); you may not use this file except in compliance
  52463. * with the License. You may obtain a copy of the License at
  52464. *
  52465. * http://www.apache.org/licenses/LICENSE-2.0
  52466. *
  52467. * Unless required by applicable law or agreed to in writing,
  52468. * software distributed under the License is distributed on an
  52469. * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
  52470. * KIND, either express or implied. See the License for the
  52471. * specific language governing permissions and limitations
  52472. * under the License.
  52473. */
  52474. /**
  52475. * Initialize all computational message for following algorithm.
  52476. */
  52477. function init$2(inRoot) {
  52478. var root = inRoot;
  52479. root.hierNode = {
  52480. defaultAncestor: null,
  52481. ancestor: root,
  52482. prelim: 0,
  52483. modifier: 0,
  52484. change: 0,
  52485. shift: 0,
  52486. i: 0,
  52487. thread: null
  52488. };
  52489. var nodes = [root];
  52490. var node;
  52491. var children;
  52492. while (node = nodes.pop()) {
  52493. // jshint ignore:line
  52494. children = node.children;
  52495. if (node.isExpand && children.length) {
  52496. var n = children.length;
  52497. for (var i = n - 1; i >= 0; i--) {
  52498. var child = children[i];
  52499. child.hierNode = {
  52500. defaultAncestor: null,
  52501. ancestor: child,
  52502. prelim: 0,
  52503. modifier: 0,
  52504. change: 0,
  52505. shift: 0,
  52506. i: i,
  52507. thread: null
  52508. };
  52509. nodes.push(child);
  52510. }
  52511. }
  52512. }
  52513. }
  52514. /**
  52515. * The implementation of this function was originally copied from "d3.js"
  52516. * <https://github.com/d3/d3-hierarchy/blob/4c1f038f2725d6eae2e49b61d01456400694bac4/src/tree.js>
  52517. * with some modifications made for this program.
  52518. * See the license statement at the head of this file.
  52519. *
  52520. * Computes a preliminary x coordinate for node. Before that, this function is
  52521. * applied recursively to the children of node, as well as the function
  52522. * apportion(). After spacing out the children by calling executeShifts(), the
  52523. * node is placed to the midpoint of its outermost children.
  52524. */
  52525. function firstWalk(node, separation) {
  52526. var children = node.isExpand ? node.children : [];
  52527. var siblings = node.parentNode.children;
  52528. var subtreeW = node.hierNode.i ? siblings[node.hierNode.i - 1] : null;
  52529. if (children.length) {
  52530. executeShifts(node);
  52531. var midPoint = (children[0].hierNode.prelim + children[children.length - 1].hierNode.prelim) / 2;
  52532. if (subtreeW) {
  52533. node.hierNode.prelim = subtreeW.hierNode.prelim + separation(node, subtreeW);
  52534. node.hierNode.modifier = node.hierNode.prelim - midPoint;
  52535. } else {
  52536. node.hierNode.prelim = midPoint;
  52537. }
  52538. } else if (subtreeW) {
  52539. node.hierNode.prelim = subtreeW.hierNode.prelim + separation(node, subtreeW);
  52540. }
  52541. node.parentNode.hierNode.defaultAncestor = apportion(node, subtreeW, node.parentNode.hierNode.defaultAncestor || siblings[0], separation);
  52542. }
  52543. /**
  52544. * The implementation of this function was originally copied from "d3.js"
  52545. * <https://github.com/d3/d3-hierarchy/blob/4c1f038f2725d6eae2e49b61d01456400694bac4/src/tree.js>
  52546. * with some modifications made for this program.
  52547. * See the license statement at the head of this file.
  52548. *
  52549. * Computes all real x-coordinates by summing up the modifiers recursively.
  52550. */
  52551. function secondWalk(node) {
  52552. var nodeX = node.hierNode.prelim + node.parentNode.hierNode.modifier;
  52553. node.setLayout({
  52554. x: nodeX
  52555. }, true);
  52556. node.hierNode.modifier += node.parentNode.hierNode.modifier;
  52557. }
  52558. function separation(cb) {
  52559. return arguments.length ? cb : defaultSeparation;
  52560. }
  52561. /**
  52562. * Transform the common coordinate to radial coordinate.
  52563. */
  52564. function radialCoordinate(rad, r) {
  52565. rad -= Math.PI / 2;
  52566. return {
  52567. x: r * Math.cos(rad),
  52568. y: r * Math.sin(rad)
  52569. };
  52570. }
  52571. /**
  52572. * All other shifts, applied to the smaller subtrees between w- and w+, are
  52573. * performed by this function.
  52574. *
  52575. * The implementation of this function was originally copied from "d3.js"
  52576. * <https://github.com/d3/d3-hierarchy/blob/4c1f038f2725d6eae2e49b61d01456400694bac4/src/tree.js>
  52577. * with some modifications made for this program.
  52578. * See the license statement at the head of this file.
  52579. */
  52580. function executeShifts(node) {
  52581. var children = node.children;
  52582. var n = children.length;
  52583. var shift = 0;
  52584. var change = 0;
  52585. while (--n >= 0) {
  52586. var child = children[n];
  52587. child.hierNode.prelim += shift;
  52588. child.hierNode.modifier += shift;
  52589. change += child.hierNode.change;
  52590. shift += child.hierNode.shift + change;
  52591. }
  52592. }
  52593. /**
  52594. * The implementation of this function was originally copied from "d3.js"
  52595. * <https://github.com/d3/d3-hierarchy/blob/4c1f038f2725d6eae2e49b61d01456400694bac4/src/tree.js>
  52596. * with some modifications made for this program.
  52597. * See the license statement at the head of this file.
  52598. *
  52599. * The core of the algorithm. Here, a new subtree is combined with the
  52600. * previous subtrees. Threads are used to traverse the inside and outside
  52601. * contours of the left and right subtree up to the highest common level.
  52602. * Whenever two nodes of the inside contours conflict, we compute the left
  52603. * one of the greatest uncommon ancestors using the function nextAncestor()
  52604. * and call moveSubtree() to shift the subtree and prepare the shifts of
  52605. * smaller subtrees. Finally, we add a new thread (if necessary).
  52606. */
  52607. function apportion(subtreeV, subtreeW, ancestor, separation) {
  52608. if (subtreeW) {
  52609. var nodeOutRight = subtreeV;
  52610. var nodeInRight = subtreeV;
  52611. var nodeOutLeft = nodeInRight.parentNode.children[0];
  52612. var nodeInLeft = subtreeW;
  52613. var sumOutRight = nodeOutRight.hierNode.modifier;
  52614. var sumInRight = nodeInRight.hierNode.modifier;
  52615. var sumOutLeft = nodeOutLeft.hierNode.modifier;
  52616. var sumInLeft = nodeInLeft.hierNode.modifier;
  52617. while (nodeInLeft = nextRight(nodeInLeft), nodeInRight = nextLeft(nodeInRight), nodeInLeft && nodeInRight) {
  52618. nodeOutRight = nextRight(nodeOutRight);
  52619. nodeOutLeft = nextLeft(nodeOutLeft);
  52620. nodeOutRight.hierNode.ancestor = subtreeV;
  52621. var shift = nodeInLeft.hierNode.prelim + sumInLeft - nodeInRight.hierNode.prelim - sumInRight + separation(nodeInLeft, nodeInRight);
  52622. if (shift > 0) {
  52623. moveSubtree(nextAncestor(nodeInLeft, subtreeV, ancestor), subtreeV, shift);
  52624. sumInRight += shift;
  52625. sumOutRight += shift;
  52626. }
  52627. sumInLeft += nodeInLeft.hierNode.modifier;
  52628. sumInRight += nodeInRight.hierNode.modifier;
  52629. sumOutRight += nodeOutRight.hierNode.modifier;
  52630. sumOutLeft += nodeOutLeft.hierNode.modifier;
  52631. }
  52632. if (nodeInLeft && !nextRight(nodeOutRight)) {
  52633. nodeOutRight.hierNode.thread = nodeInLeft;
  52634. nodeOutRight.hierNode.modifier += sumInLeft - sumOutRight;
  52635. }
  52636. if (nodeInRight && !nextLeft(nodeOutLeft)) {
  52637. nodeOutLeft.hierNode.thread = nodeInRight;
  52638. nodeOutLeft.hierNode.modifier += sumInRight - sumOutLeft;
  52639. ancestor = subtreeV;
  52640. }
  52641. }
  52642. return ancestor;
  52643. }
  52644. /**
  52645. * This function is used to traverse the right contour of a subtree.
  52646. * It returns the rightmost child of node or the thread of node. The function
  52647. * returns null if and only if node is on the highest depth of its subtree.
  52648. */
  52649. function nextRight(node) {
  52650. var children = node.children;
  52651. return children.length && node.isExpand ? children[children.length - 1] : node.hierNode.thread;
  52652. }
  52653. /**
  52654. * This function is used to traverse the left contour of a subtree (or a subforest).
  52655. * It returns the leftmost child of node or the thread of node. The function
  52656. * returns null if and only if node is on the highest depth of its subtree.
  52657. */
  52658. function nextLeft(node) {
  52659. var children = node.children;
  52660. return children.length && node.isExpand ? children[0] : node.hierNode.thread;
  52661. }
  52662. /**
  52663. * If nodeInLeft’s ancestor is a sibling of node, returns nodeInLeft’s ancestor.
  52664. * Otherwise, returns the specified ancestor.
  52665. */
  52666. function nextAncestor(nodeInLeft, node, ancestor) {
  52667. return nodeInLeft.hierNode.ancestor.parentNode === node.parentNode ? nodeInLeft.hierNode.ancestor : ancestor;
  52668. }
  52669. /**
  52670. * The implementation of this function was originally copied from "d3.js"
  52671. * <https://github.com/d3/d3-hierarchy/blob/4c1f038f2725d6eae2e49b61d01456400694bac4/src/tree.js>
  52672. * with some modifications made for this program.
  52673. * See the license statement at the head of this file.
  52674. *
  52675. * Shifts the current subtree rooted at wr.
  52676. * This is done by increasing prelim(w+) and modifier(w+) by shift.
  52677. */
  52678. function moveSubtree(wl, wr, shift) {
  52679. var change = shift / (wr.hierNode.i - wl.hierNode.i);
  52680. wr.hierNode.change -= change;
  52681. wr.hierNode.shift += shift;
  52682. wr.hierNode.modifier += shift;
  52683. wr.hierNode.prelim += shift;
  52684. wl.hierNode.change += change;
  52685. }
  52686. /**
  52687. * The implementation of this function was originally copied from "d3.js"
  52688. * <https://github.com/d3/d3-hierarchy/blob/4c1f038f2725d6eae2e49b61d01456400694bac4/src/tree.js>
  52689. * with some modifications made for this program.
  52690. * See the license statement at the head of this file.
  52691. */
  52692. function defaultSeparation(node1, node2) {
  52693. return node1.parentNode === node2.parentNode ? 1 : 2;
  52694. }
  52695. var TreeEdgeShape = /** @class */function () {
  52696. function TreeEdgeShape() {
  52697. this.parentPoint = [];
  52698. this.childPoints = [];
  52699. }
  52700. return TreeEdgeShape;
  52701. }();
  52702. var TreePath = /** @class */function (_super) {
  52703. __extends(TreePath, _super);
  52704. function TreePath(opts) {
  52705. return _super.call(this, opts) || this;
  52706. }
  52707. TreePath.prototype.getDefaultStyle = function () {
  52708. return {
  52709. stroke: tokens.color.neutral99,
  52710. fill: null
  52711. };
  52712. };
  52713. TreePath.prototype.getDefaultShape = function () {
  52714. return new TreeEdgeShape();
  52715. };
  52716. TreePath.prototype.buildPath = function (ctx, shape) {
  52717. var childPoints = shape.childPoints;
  52718. var childLen = childPoints.length;
  52719. var parentPoint = shape.parentPoint;
  52720. var firstChildPos = childPoints[0];
  52721. var lastChildPos = childPoints[childLen - 1];
  52722. if (childLen === 1) {
  52723. ctx.moveTo(parentPoint[0], parentPoint[1]);
  52724. ctx.lineTo(firstChildPos[0], firstChildPos[1]);
  52725. return;
  52726. }
  52727. var orient = shape.orient;
  52728. var forkDim = orient === 'TB' || orient === 'BT' ? 0 : 1;
  52729. var otherDim = 1 - forkDim;
  52730. var forkPosition = parsePercent$1(shape.forkPosition, 1);
  52731. var tmpPoint = [];
  52732. tmpPoint[forkDim] = parentPoint[forkDim];
  52733. tmpPoint[otherDim] = parentPoint[otherDim] + (lastChildPos[otherDim] - parentPoint[otherDim]) * forkPosition;
  52734. ctx.moveTo(parentPoint[0], parentPoint[1]);
  52735. ctx.lineTo(tmpPoint[0], tmpPoint[1]);
  52736. ctx.moveTo(firstChildPos[0], firstChildPos[1]);
  52737. tmpPoint[forkDim] = firstChildPos[forkDim];
  52738. ctx.lineTo(tmpPoint[0], tmpPoint[1]);
  52739. tmpPoint[forkDim] = lastChildPos[forkDim];
  52740. ctx.lineTo(tmpPoint[0], tmpPoint[1]);
  52741. ctx.lineTo(lastChildPos[0], lastChildPos[1]);
  52742. for (var i = 1; i < childLen - 1; i++) {
  52743. var point = childPoints[i];
  52744. ctx.moveTo(point[0], point[1]);
  52745. tmpPoint[forkDim] = point[forkDim];
  52746. ctx.lineTo(tmpPoint[0], tmpPoint[1]);
  52747. }
  52748. };
  52749. return TreePath;
  52750. }(Path);
  52751. var TreeView = /** @class */function (_super) {
  52752. __extends(TreeView, _super);
  52753. function TreeView() {
  52754. var _this = _super !== null && _super.apply(this, arguments) || this;
  52755. _this.type = TreeView.type;
  52756. _this._mainGroup = new Group();
  52757. return _this;
  52758. }
  52759. TreeView.prototype.init = function (ecModel, api) {
  52760. this._controller = new RoamController(api.getZr());
  52761. this._controllerHost = {
  52762. target: this.group
  52763. };
  52764. this.group.add(this._mainGroup);
  52765. };
  52766. TreeView.prototype.render = function (seriesModel, ecModel, api) {
  52767. var data = seriesModel.getData();
  52768. var layoutInfo = seriesModel.layoutInfo;
  52769. var group = this._mainGroup;
  52770. var layout = seriesModel.get('layout');
  52771. if (layout === 'radial') {
  52772. group.x = layoutInfo.x + layoutInfo.width / 2;
  52773. group.y = layoutInfo.y + layoutInfo.height / 2;
  52774. } else {
  52775. group.x = layoutInfo.x;
  52776. group.y = layoutInfo.y;
  52777. }
  52778. this._updateViewCoordSys(seriesModel, api);
  52779. this._updateController(seriesModel, null, ecModel, api);
  52780. var oldData = this._data;
  52781. data.diff(oldData).add(function (newIdx) {
  52782. if (symbolNeedsDraw$1(data, newIdx)) {
  52783. // Create node and edge
  52784. updateNode(data, newIdx, null, group, seriesModel);
  52785. }
  52786. }).update(function (newIdx, oldIdx) {
  52787. var symbolEl = oldData.getItemGraphicEl(oldIdx);
  52788. if (!symbolNeedsDraw$1(data, newIdx)) {
  52789. symbolEl && removeNode(oldData, oldIdx, symbolEl, group, seriesModel);
  52790. return;
  52791. }
  52792. // Update node and edge
  52793. updateNode(data, newIdx, symbolEl, group, seriesModel);
  52794. }).remove(function (oldIdx) {
  52795. var symbolEl = oldData.getItemGraphicEl(oldIdx);
  52796. // When remove a collapsed node of subtree, since the collapsed
  52797. // node haven't been initialized with a symbol element,
  52798. // you can't found it's symbol element through index.
  52799. // so if we want to remove the symbol element we should insure
  52800. // that the symbol element is not null.
  52801. if (symbolEl) {
  52802. removeNode(oldData, oldIdx, symbolEl, group, seriesModel);
  52803. }
  52804. }).execute();
  52805. this._nodeScaleRatio = seriesModel.get('nodeScaleRatio');
  52806. this._updateNodeAndLinkScale(seriesModel);
  52807. if (seriesModel.get('expandAndCollapse') === true) {
  52808. data.eachItemGraphicEl(function (el, dataIndex) {
  52809. el.off('click').on('click', function () {
  52810. api.dispatchAction({
  52811. type: 'treeExpandAndCollapse',
  52812. seriesId: seriesModel.id,
  52813. dataIndex: dataIndex
  52814. });
  52815. });
  52816. });
  52817. }
  52818. this._data = data;
  52819. };
  52820. TreeView.prototype._updateViewCoordSys = function (seriesModel, api) {
  52821. var data = seriesModel.getData();
  52822. var points = [];
  52823. data.each(function (idx) {
  52824. var layout = data.getItemLayout(idx);
  52825. if (layout && !isNaN(layout.x) && !isNaN(layout.y)) {
  52826. points.push([+layout.x, +layout.y]);
  52827. }
  52828. });
  52829. var min = [];
  52830. var max = [];
  52831. fromPoints(points, min, max);
  52832. // If don't Store min max when collapse the root node after roam,
  52833. // the root node will disappear.
  52834. var oldMin = this._min;
  52835. var oldMax = this._max;
  52836. // If width or height is 0
  52837. if (max[0] - min[0] === 0) {
  52838. min[0] = oldMin ? oldMin[0] : min[0] - 1;
  52839. max[0] = oldMax ? oldMax[0] : max[0] + 1;
  52840. }
  52841. if (max[1] - min[1] === 0) {
  52842. min[1] = oldMin ? oldMin[1] : min[1] - 1;
  52843. max[1] = oldMax ? oldMax[1] : max[1] + 1;
  52844. }
  52845. var viewCoordSys = seriesModel.coordinateSystem = new View(null, {
  52846. api: api,
  52847. ecModel: seriesModel.ecModel
  52848. });
  52849. viewCoordSys.zoomLimit = seriesModel.get('scaleLimit');
  52850. viewCoordSys.setBoundingRect(min[0], min[1], max[0] - min[0], max[1] - min[1]);
  52851. viewCoordSys.setCenter(seriesModel.get('center'));
  52852. viewCoordSys.setZoom(seriesModel.get('zoom'));
  52853. // Here we use viewCoordSys just for computing the 'position' and 'scale' of the group,
  52854. // and 'treeRoam' action.
  52855. this.group.attr({
  52856. x: viewCoordSys.x,
  52857. y: viewCoordSys.y,
  52858. scaleX: viewCoordSys.scaleX,
  52859. scaleY: viewCoordSys.scaleY
  52860. });
  52861. this._min = min;
  52862. this._max = max;
  52863. };
  52864. TreeView.prototype._updateController = function (seriesModel, clipRect, ecModel, api) {
  52865. var _this = this;
  52866. updateController(seriesModel, api, this.group, this._controller, this._controllerHost, clipRect);
  52867. this._controller.on('zoom', function (e) {
  52868. _this._updateNodeAndLinkScale(seriesModel);
  52869. });
  52870. };
  52871. TreeView.prototype._updateNodeAndLinkScale = function (seriesModel) {
  52872. var data = seriesModel.getData();
  52873. var nodeScale = this._getNodeGlobalScale(seriesModel);
  52874. data.eachItemGraphicEl(function (el, idx) {
  52875. el.setSymbolScale(nodeScale);
  52876. });
  52877. };
  52878. TreeView.prototype._getNodeGlobalScale = function (seriesModel) {
  52879. var coordSys = seriesModel.coordinateSystem;
  52880. if (coordSys.type !== 'view') {
  52881. return 1;
  52882. }
  52883. var nodeScaleRatio = this._nodeScaleRatio;
  52884. var groupZoom = coordSys.scaleX || 1;
  52885. // Scale node when zoom changes
  52886. var roamZoom = coordSys.getZoom();
  52887. var nodeScale = (roamZoom - 1) * nodeScaleRatio + 1;
  52888. return nodeScale / groupZoom;
  52889. };
  52890. TreeView.prototype.dispose = function () {
  52891. this._controller && this._controller.dispose();
  52892. this._controllerHost = null;
  52893. };
  52894. TreeView.prototype.remove = function () {
  52895. this._mainGroup.removeAll();
  52896. this._data = null;
  52897. };
  52898. TreeView.type = 'tree';
  52899. return TreeView;
  52900. }(ChartView);
  52901. function symbolNeedsDraw$1(data, dataIndex) {
  52902. var layout = data.getItemLayout(dataIndex);
  52903. return layout && !isNaN(layout.x) && !isNaN(layout.y);
  52904. }
  52905. function updateNode(data, dataIndex, symbolEl, group, seriesModel) {
  52906. var isInit = !symbolEl;
  52907. var node = data.tree.getNodeByDataIndex(dataIndex);
  52908. var itemModel = node.getModel();
  52909. var visualColor = node.getVisual('style').fill;
  52910. var symbolInnerColor = node.isExpand === false && node.children.length !== 0 ? visualColor : tokens.color.neutral00;
  52911. var virtualRoot = data.tree.root;
  52912. var source = node.parentNode === virtualRoot ? node : node.parentNode || node;
  52913. var sourceSymbolEl = data.getItemGraphicEl(source.dataIndex);
  52914. var sourceLayout = source.getLayout();
  52915. var sourceOldLayout = sourceSymbolEl ? {
  52916. x: sourceSymbolEl.__oldX,
  52917. y: sourceSymbolEl.__oldY,
  52918. rawX: sourceSymbolEl.__radialOldRawX,
  52919. rawY: sourceSymbolEl.__radialOldRawY
  52920. } : sourceLayout;
  52921. var targetLayout = node.getLayout();
  52922. if (isInit) {
  52923. symbolEl = new Symbol(data, dataIndex, null, {
  52924. symbolInnerColor: symbolInnerColor,
  52925. useNameLabel: true
  52926. });
  52927. symbolEl.x = sourceOldLayout.x;
  52928. symbolEl.y = sourceOldLayout.y;
  52929. } else {
  52930. symbolEl.updateData(data, dataIndex, null, {
  52931. symbolInnerColor: symbolInnerColor,
  52932. useNameLabel: true
  52933. });
  52934. }
  52935. symbolEl.__radialOldRawX = symbolEl.__radialRawX;
  52936. symbolEl.__radialOldRawY = symbolEl.__radialRawY;
  52937. symbolEl.__radialRawX = targetLayout.rawX;
  52938. symbolEl.__radialRawY = targetLayout.rawY;
  52939. group.add(symbolEl);
  52940. data.setItemGraphicEl(dataIndex, symbolEl);
  52941. symbolEl.__oldX = symbolEl.x;
  52942. symbolEl.__oldY = symbolEl.y;
  52943. updateProps(symbolEl, {
  52944. x: targetLayout.x,
  52945. y: targetLayout.y
  52946. }, seriesModel);
  52947. var symbolPath = symbolEl.getSymbolPath();
  52948. if (seriesModel.get('layout') === 'radial') {
  52949. var realRoot = virtualRoot.children[0];
  52950. var rootLayout = realRoot.getLayout();
  52951. var length_1 = realRoot.children.length;
  52952. var rad = void 0;
  52953. var isLeft = void 0;
  52954. if (targetLayout.x === rootLayout.x && node.isExpand === true && realRoot.children.length) {
  52955. var center = {
  52956. x: (realRoot.children[0].getLayout().x + realRoot.children[length_1 - 1].getLayout().x) / 2,
  52957. y: (realRoot.children[0].getLayout().y + realRoot.children[length_1 - 1].getLayout().y) / 2
  52958. };
  52959. rad = Math.atan2(center.y - rootLayout.y, center.x - rootLayout.x);
  52960. if (rad < 0) {
  52961. rad = Math.PI * 2 + rad;
  52962. }
  52963. isLeft = center.x < rootLayout.x;
  52964. if (isLeft) {
  52965. rad = rad - Math.PI;
  52966. }
  52967. } else {
  52968. rad = Math.atan2(targetLayout.y - rootLayout.y, targetLayout.x - rootLayout.x);
  52969. if (rad < 0) {
  52970. rad = Math.PI * 2 + rad;
  52971. }
  52972. if (node.children.length === 0 || node.children.length !== 0 && node.isExpand === false) {
  52973. isLeft = targetLayout.x < rootLayout.x;
  52974. if (isLeft) {
  52975. rad = rad - Math.PI;
  52976. }
  52977. } else {
  52978. isLeft = targetLayout.x > rootLayout.x;
  52979. if (!isLeft) {
  52980. rad = rad - Math.PI;
  52981. }
  52982. }
  52983. }
  52984. var textPosition = isLeft ? 'left' : 'right';
  52985. var normalLabelModel = itemModel.getModel('label');
  52986. var rotate = normalLabelModel.get('rotate');
  52987. var labelRotateRadian = rotate * (Math.PI / 180);
  52988. var textContent = symbolPath.getTextContent();
  52989. if (textContent) {
  52990. symbolPath.setTextConfig({
  52991. position: normalLabelModel.get('position') || textPosition,
  52992. rotation: rotate == null ? -rad : labelRotateRadian,
  52993. origin: 'center'
  52994. });
  52995. textContent.setStyle('verticalAlign', 'middle');
  52996. }
  52997. }
  52998. // Handle status
  52999. var focus = itemModel.get(['emphasis', 'focus']);
  53000. var focusDataIndices = focus === 'relative' ? concatArray(node.getAncestorsIndices(), node.getDescendantIndices()) : focus === 'ancestor' ? node.getAncestorsIndices() : focus === 'descendant' ? node.getDescendantIndices() : null;
  53001. if (focusDataIndices) {
  53002. // Modify the focus to data indices.
  53003. getECData(symbolEl).focus = focusDataIndices;
  53004. }
  53005. drawEdge(seriesModel, node, virtualRoot, symbolEl, sourceOldLayout, sourceLayout, targetLayout, group);
  53006. if (symbolEl.__edge) {
  53007. symbolEl.onHoverStateChange = function (toState) {
  53008. if (toState !== 'blur') {
  53009. // NOTE: Ensure the parent elements will been blurred firstly.
  53010. // According to the return of getAncestorsIndices and getDescendantIndices
  53011. // TODO: A bit tricky.
  53012. var parentEl = node.parentNode && data.getItemGraphicEl(node.parentNode.dataIndex);
  53013. if (!(parentEl && parentEl.hoverState === HOVER_STATE_BLUR)) {
  53014. setStatesFlag(symbolEl.__edge, toState);
  53015. }
  53016. }
  53017. };
  53018. }
  53019. }
  53020. function drawEdge(seriesModel, node, virtualRoot, symbolEl, sourceOldLayout, sourceLayout, targetLayout, group) {
  53021. var itemModel = node.getModel();
  53022. var edgeShape = seriesModel.get('edgeShape');
  53023. var layout = seriesModel.get('layout');
  53024. var orient = seriesModel.getOrient();
  53025. var curvature = seriesModel.get(['lineStyle', 'curveness']);
  53026. var edgeForkPosition = seriesModel.get('edgeForkPosition');
  53027. var lineStyle = itemModel.getModel('lineStyle').getLineStyle();
  53028. var edge = symbolEl.__edge;
  53029. // curve edge from node -> parent
  53030. // polyline edge from node -> children
  53031. if (edgeShape === 'curve') {
  53032. if (node.parentNode && node.parentNode !== virtualRoot) {
  53033. if (!edge) {
  53034. edge = symbolEl.__edge = new BezierCurve({
  53035. shape: getEdgeShape(layout, orient, curvature, sourceOldLayout, sourceOldLayout)
  53036. });
  53037. }
  53038. updateProps(edge, {
  53039. shape: getEdgeShape(layout, orient, curvature, sourceLayout, targetLayout)
  53040. }, seriesModel);
  53041. }
  53042. } else if (edgeShape === 'polyline') {
  53043. if (layout === 'orthogonal') {
  53044. if (node !== virtualRoot && node.children && node.children.length !== 0 && node.isExpand === true) {
  53045. var children = node.children;
  53046. var childPoints = [];
  53047. for (var i = 0; i < children.length; i++) {
  53048. var childLayout = children[i].getLayout();
  53049. childPoints.push([childLayout.x, childLayout.y]);
  53050. }
  53051. if (!edge) {
  53052. edge = symbolEl.__edge = new TreePath({
  53053. shape: {
  53054. parentPoint: [targetLayout.x, targetLayout.y],
  53055. childPoints: [[targetLayout.x, targetLayout.y]],
  53056. orient: orient,
  53057. forkPosition: edgeForkPosition
  53058. }
  53059. });
  53060. }
  53061. updateProps(edge, {
  53062. shape: {
  53063. parentPoint: [targetLayout.x, targetLayout.y],
  53064. childPoints: childPoints
  53065. }
  53066. }, seriesModel);
  53067. }
  53068. } else {
  53069. if ("development" !== 'production') {
  53070. throw new Error('The polyline edgeShape can only be used in orthogonal layout');
  53071. }
  53072. }
  53073. }
  53074. // show all edge when edgeShape is 'curve', filter node `isExpand` is false when edgeShape is 'polyline'
  53075. if (edge && !(edgeShape === 'polyline' && !node.isExpand)) {
  53076. edge.useStyle(defaults({
  53077. strokeNoScale: true,
  53078. fill: null
  53079. }, lineStyle));
  53080. setStatesStylesFromModel(edge, itemModel, 'lineStyle');
  53081. setDefaultStateProxy(edge);
  53082. group.add(edge);
  53083. }
  53084. }
  53085. function removeNodeEdge(node, data, group, seriesModel, removeAnimationOpt) {
  53086. var virtualRoot = data.tree.root;
  53087. var _a = getSourceNode(virtualRoot, node),
  53088. source = _a.source,
  53089. sourceLayout = _a.sourceLayout;
  53090. var symbolEl = data.getItemGraphicEl(node.dataIndex);
  53091. if (!symbolEl) {
  53092. return;
  53093. }
  53094. var sourceSymbolEl = data.getItemGraphicEl(source.dataIndex);
  53095. var sourceEdge = sourceSymbolEl.__edge;
  53096. // 1. when expand the sub tree, delete the children node should delete the edge of
  53097. // the source at the same time. because the polyline edge shape is only owned by the source.
  53098. // 2.when the node is the only children of the source, delete the node should delete the edge of
  53099. // the source at the same time. the same reason as above.
  53100. var edge = symbolEl.__edge || (source.isExpand === false || source.children.length === 1 ? sourceEdge : undefined);
  53101. var edgeShape = seriesModel.get('edgeShape');
  53102. var layoutOpt = seriesModel.get('layout');
  53103. var orient = seriesModel.get('orient');
  53104. var curvature = seriesModel.get(['lineStyle', 'curveness']);
  53105. if (edge) {
  53106. if (edgeShape === 'curve') {
  53107. removeElement(edge, {
  53108. shape: getEdgeShape(layoutOpt, orient, curvature, sourceLayout, sourceLayout),
  53109. style: {
  53110. opacity: 0
  53111. }
  53112. }, seriesModel, {
  53113. cb: function () {
  53114. group.remove(edge);
  53115. },
  53116. removeOpt: removeAnimationOpt
  53117. });
  53118. } else if (edgeShape === 'polyline' && seriesModel.get('layout') === 'orthogonal') {
  53119. removeElement(edge, {
  53120. shape: {
  53121. parentPoint: [sourceLayout.x, sourceLayout.y],
  53122. childPoints: [[sourceLayout.x, sourceLayout.y]]
  53123. },
  53124. style: {
  53125. opacity: 0
  53126. }
  53127. }, seriesModel, {
  53128. cb: function () {
  53129. group.remove(edge);
  53130. },
  53131. removeOpt: removeAnimationOpt
  53132. });
  53133. }
  53134. }
  53135. }
  53136. function getSourceNode(virtualRoot, node) {
  53137. var source = node.parentNode === virtualRoot ? node : node.parentNode || node;
  53138. var sourceLayout;
  53139. while (sourceLayout = source.getLayout(), sourceLayout == null) {
  53140. source = source.parentNode === virtualRoot ? source : source.parentNode || source;
  53141. }
  53142. return {
  53143. source: source,
  53144. sourceLayout: sourceLayout
  53145. };
  53146. }
  53147. function removeNode(data, dataIndex, symbolEl, group, seriesModel) {
  53148. var node = data.tree.getNodeByDataIndex(dataIndex);
  53149. var virtualRoot = data.tree.root;
  53150. var sourceLayout = getSourceNode(virtualRoot, node).sourceLayout;
  53151. // Use same duration and easing with update to have more consistent animation.
  53152. var removeAnimationOpt = {
  53153. duration: seriesModel.get('animationDurationUpdate'),
  53154. easing: seriesModel.get('animationEasingUpdate')
  53155. };
  53156. removeElement(symbolEl, {
  53157. x: sourceLayout.x + 1,
  53158. y: sourceLayout.y + 1
  53159. }, seriesModel, {
  53160. cb: function () {
  53161. group.remove(symbolEl);
  53162. data.setItemGraphicEl(dataIndex, null);
  53163. },
  53164. removeOpt: removeAnimationOpt
  53165. });
  53166. symbolEl.fadeOut(null, data.hostModel, {
  53167. fadeLabel: true,
  53168. animation: removeAnimationOpt
  53169. });
  53170. // remove edge as parent node
  53171. node.children.forEach(function (childNode) {
  53172. removeNodeEdge(childNode, data, group, seriesModel, removeAnimationOpt);
  53173. });
  53174. // remove edge as child node
  53175. removeNodeEdge(node, data, group, seriesModel, removeAnimationOpt);
  53176. }
  53177. function getEdgeShape(layoutOpt, orient, curvature, sourceLayout, targetLayout) {
  53178. var cpx1;
  53179. var cpy1;
  53180. var cpx2;
  53181. var cpy2;
  53182. var x1;
  53183. var x2;
  53184. var y1;
  53185. var y2;
  53186. if (layoutOpt === 'radial') {
  53187. x1 = sourceLayout.rawX;
  53188. y1 = sourceLayout.rawY;
  53189. x2 = targetLayout.rawX;
  53190. y2 = targetLayout.rawY;
  53191. var radialCoor1 = radialCoordinate(x1, y1);
  53192. var radialCoor2 = radialCoordinate(x1, y1 + (y2 - y1) * curvature);
  53193. var radialCoor3 = radialCoordinate(x2, y2 + (y1 - y2) * curvature);
  53194. var radialCoor4 = radialCoordinate(x2, y2);
  53195. return {
  53196. x1: radialCoor1.x || 0,
  53197. y1: radialCoor1.y || 0,
  53198. x2: radialCoor4.x || 0,
  53199. y2: radialCoor4.y || 0,
  53200. cpx1: radialCoor2.x || 0,
  53201. cpy1: radialCoor2.y || 0,
  53202. cpx2: radialCoor3.x || 0,
  53203. cpy2: radialCoor3.y || 0
  53204. };
  53205. } else {
  53206. x1 = sourceLayout.x;
  53207. y1 = sourceLayout.y;
  53208. x2 = targetLayout.x;
  53209. y2 = targetLayout.y;
  53210. if (orient === 'LR' || orient === 'RL') {
  53211. cpx1 = x1 + (x2 - x1) * curvature;
  53212. cpy1 = y1;
  53213. cpx2 = x2 + (x1 - x2) * curvature;
  53214. cpy2 = y2;
  53215. }
  53216. if (orient === 'TB' || orient === 'BT') {
  53217. cpx1 = x1;
  53218. cpy1 = y1 + (y2 - y1) * curvature;
  53219. cpx2 = x2;
  53220. cpy2 = y2 + (y1 - y2) * curvature;
  53221. }
  53222. }
  53223. return {
  53224. x1: x1,
  53225. y1: y1,
  53226. x2: x2,
  53227. y2: y2,
  53228. cpx1: cpx1,
  53229. cpy1: cpy1,
  53230. cpx2: cpx2,
  53231. cpy2: cpy2
  53232. };
  53233. }
  53234. var inner$8 = makeInner();
  53235. function linkSeriesData(opt) {
  53236. var mainData = opt.mainData;
  53237. var datas = opt.datas;
  53238. if (!datas) {
  53239. datas = {
  53240. main: mainData
  53241. };
  53242. opt.datasAttr = {
  53243. main: 'data'
  53244. };
  53245. }
  53246. opt.datas = opt.mainData = null;
  53247. linkAll(mainData, datas, opt);
  53248. // Porxy data original methods.
  53249. each(datas, function (data) {
  53250. each(mainData.TRANSFERABLE_METHODS, function (methodName) {
  53251. data.wrapMethod(methodName, curry(transferInjection, opt));
  53252. });
  53253. });
  53254. // Beyond transfer, additional features should be added to `cloneShallow`.
  53255. mainData.wrapMethod('cloneShallow', curry(cloneShallowInjection, opt));
  53256. // Only mainData trigger change, because struct.update may trigger
  53257. // another changable methods, which may bring about dead lock.
  53258. each(mainData.CHANGABLE_METHODS, function (methodName) {
  53259. mainData.wrapMethod(methodName, curry(changeInjection, opt));
  53260. });
  53261. // Make sure datas contains mainData.
  53262. assert(datas[mainData.dataType] === mainData);
  53263. }
  53264. function transferInjection(opt, res) {
  53265. if (isMainData(this)) {
  53266. // Transfer datas to new main data.
  53267. var datas = extend({}, inner$8(this).datas);
  53268. datas[this.dataType] = res;
  53269. linkAll(res, datas, opt);
  53270. } else {
  53271. // Modify the reference in main data to point newData.
  53272. linkSingle(res, this.dataType, inner$8(this).mainData, opt);
  53273. }
  53274. return res;
  53275. }
  53276. function changeInjection(opt, res) {
  53277. opt.struct && opt.struct.update();
  53278. return res;
  53279. }
  53280. function cloneShallowInjection(opt, res) {
  53281. // cloneShallow, which brings about some fragilities, may be inappropriate
  53282. // to be exposed as an API. So for implementation simplicity we can make
  53283. // the restriction that cloneShallow of not-mainData should not be invoked
  53284. // outside, but only be invoked here.
  53285. each(inner$8(res).datas, function (data, dataType) {
  53286. data !== res && linkSingle(data.cloneShallow(), dataType, res, opt);
  53287. });
  53288. return res;
  53289. }
  53290. /**
  53291. * Supplement method to List.
  53292. *
  53293. * @public
  53294. * @param [dataType] If not specified, return mainData.
  53295. */
  53296. function getLinkedData(dataType) {
  53297. var mainData = inner$8(this).mainData;
  53298. return dataType == null || mainData == null ? mainData : inner$8(mainData).datas[dataType];
  53299. }
  53300. /**
  53301. * Get list of all linked data
  53302. */
  53303. function getLinkedDataAll() {
  53304. var mainData = inner$8(this).mainData;
  53305. return mainData == null ? [{
  53306. data: mainData
  53307. }] : map(keys(inner$8(mainData).datas), function (type) {
  53308. return {
  53309. type: type,
  53310. data: inner$8(mainData).datas[type]
  53311. };
  53312. });
  53313. }
  53314. function isMainData(data) {
  53315. return inner$8(data).mainData === data;
  53316. }
  53317. function linkAll(mainData, datas, opt) {
  53318. inner$8(mainData).datas = {};
  53319. each(datas, function (data, dataType) {
  53320. linkSingle(data, dataType, mainData, opt);
  53321. });
  53322. }
  53323. function linkSingle(data, dataType, mainData, opt) {
  53324. inner$8(mainData).datas[dataType] = data;
  53325. inner$8(data).mainData = mainData;
  53326. data.dataType = dataType;
  53327. if (opt.struct) {
  53328. data[opt.structAttr] = opt.struct;
  53329. opt.struct[opt.datasAttr[dataType]] = data;
  53330. }
  53331. // Supplement method.
  53332. data.getLinkedData = getLinkedData;
  53333. data.getLinkedDataAll = getLinkedDataAll;
  53334. }
  53335. var TreeNode = /** @class */function () {
  53336. function TreeNode(name, hostTree) {
  53337. this.depth = 0;
  53338. this.height = 0;
  53339. /**
  53340. * Reference to list item.
  53341. * Do not persistent dataIndex outside,
  53342. * besause it may be changed by list.
  53343. * If dataIndex -1,
  53344. * this node is logical deleted (filtered) in list.
  53345. */
  53346. this.dataIndex = -1;
  53347. this.children = [];
  53348. this.viewChildren = [];
  53349. this.isExpand = false;
  53350. this.name = name || '';
  53351. this.hostTree = hostTree;
  53352. }
  53353. /**
  53354. * The node is removed.
  53355. */
  53356. TreeNode.prototype.isRemoved = function () {
  53357. return this.dataIndex < 0;
  53358. };
  53359. TreeNode.prototype.eachNode = function (options, cb, context) {
  53360. if (isFunction(options)) {
  53361. context = cb;
  53362. cb = options;
  53363. options = null;
  53364. }
  53365. options = options || {};
  53366. if (isString(options)) {
  53367. options = {
  53368. order: options
  53369. };
  53370. }
  53371. var order = options.order || 'preorder';
  53372. var children = this[options.attr || 'children'];
  53373. var suppressVisitSub;
  53374. order === 'preorder' && (suppressVisitSub = cb.call(context, this));
  53375. for (var i = 0; !suppressVisitSub && i < children.length; i++) {
  53376. children[i].eachNode(options, cb, context);
  53377. }
  53378. order === 'postorder' && cb.call(context, this);
  53379. };
  53380. /**
  53381. * Update depth and height of this subtree.
  53382. */
  53383. TreeNode.prototype.updateDepthAndHeight = function (depth) {
  53384. var height = 0;
  53385. this.depth = depth;
  53386. for (var i = 0; i < this.children.length; i++) {
  53387. var child = this.children[i];
  53388. child.updateDepthAndHeight(depth + 1);
  53389. if (child.height > height) {
  53390. height = child.height;
  53391. }
  53392. }
  53393. this.height = height + 1;
  53394. };
  53395. TreeNode.prototype.getNodeById = function (id) {
  53396. if (this.getId() === id) {
  53397. return this;
  53398. }
  53399. for (var i = 0, children = this.children, len = children.length; i < len; i++) {
  53400. var res = children[i].getNodeById(id);
  53401. if (res) {
  53402. return res;
  53403. }
  53404. }
  53405. };
  53406. TreeNode.prototype.contains = function (node) {
  53407. if (node === this) {
  53408. return true;
  53409. }
  53410. for (var i = 0, children = this.children, len = children.length; i < len; i++) {
  53411. var res = children[i].contains(node);
  53412. if (res) {
  53413. return res;
  53414. }
  53415. }
  53416. };
  53417. /**
  53418. * @param includeSelf Default false.
  53419. * @return order: [root, child, grandchild, ...]
  53420. */
  53421. TreeNode.prototype.getAncestors = function (includeSelf) {
  53422. var ancestors = [];
  53423. var node = includeSelf ? this : this.parentNode;
  53424. while (node) {
  53425. ancestors.push(node);
  53426. node = node.parentNode;
  53427. }
  53428. ancestors.reverse();
  53429. return ancestors;
  53430. };
  53431. TreeNode.prototype.getAncestorsIndices = function () {
  53432. var indices = [];
  53433. var currNode = this;
  53434. while (currNode) {
  53435. indices.push(currNode.dataIndex);
  53436. currNode = currNode.parentNode;
  53437. }
  53438. indices.reverse();
  53439. return indices;
  53440. };
  53441. TreeNode.prototype.getDescendantIndices = function () {
  53442. var indices = [];
  53443. this.eachNode(function (childNode) {
  53444. indices.push(childNode.dataIndex);
  53445. });
  53446. return indices;
  53447. };
  53448. TreeNode.prototype.getValue = function (dimension) {
  53449. var data = this.hostTree.data;
  53450. return data.getStore().get(data.getDimensionIndex(dimension || 'value'), this.dataIndex);
  53451. };
  53452. TreeNode.prototype.setLayout = function (layout, merge) {
  53453. this.dataIndex >= 0 && this.hostTree.data.setItemLayout(this.dataIndex, layout, merge);
  53454. };
  53455. /**
  53456. * @return {Object} layout
  53457. */
  53458. TreeNode.prototype.getLayout = function () {
  53459. return this.hostTree.data.getItemLayout(this.dataIndex);
  53460. };
  53461. // @depcrecated
  53462. // getModel<T = unknown, S extends keyof T = keyof T>(path: S): Model<T[S]>
  53463. // eslint-disable-next-line @typescript-eslint/no-unused-vars
  53464. TreeNode.prototype.getModel = function (path) {
  53465. if (this.dataIndex < 0) {
  53466. return;
  53467. }
  53468. var hostTree = this.hostTree;
  53469. var itemModel = hostTree.data.getItemModel(this.dataIndex);
  53470. return itemModel.getModel(path);
  53471. };
  53472. // TODO: TYPE More specific model
  53473. TreeNode.prototype.getLevelModel = function () {
  53474. return (this.hostTree.levelModels || [])[this.depth];
  53475. };
  53476. TreeNode.prototype.setVisual = function (key, value) {
  53477. this.dataIndex >= 0 && this.hostTree.data.setItemVisual(this.dataIndex, key, value);
  53478. };
  53479. /**
  53480. * Get item visual
  53481. * FIXME: make return type better
  53482. */
  53483. TreeNode.prototype.getVisual = function (key) {
  53484. return this.hostTree.data.getItemVisual(this.dataIndex, key);
  53485. };
  53486. TreeNode.prototype.getRawIndex = function () {
  53487. return this.hostTree.data.getRawIndex(this.dataIndex);
  53488. };
  53489. TreeNode.prototype.getId = function () {
  53490. return this.hostTree.data.getId(this.dataIndex);
  53491. };
  53492. /**
  53493. * index in parent's children
  53494. */
  53495. TreeNode.prototype.getChildIndex = function () {
  53496. if (this.parentNode) {
  53497. var children = this.parentNode.children;
  53498. for (var i = 0; i < children.length; ++i) {
  53499. if (children[i] === this) {
  53500. return i;
  53501. }
  53502. }
  53503. return -1;
  53504. }
  53505. return -1;
  53506. };
  53507. /**
  53508. * if this is an ancestor of another node
  53509. *
  53510. * @param node another node
  53511. * @return if is ancestor
  53512. */
  53513. TreeNode.prototype.isAncestorOf = function (node) {
  53514. var parent = node.parentNode;
  53515. while (parent) {
  53516. if (parent === this) {
  53517. return true;
  53518. }
  53519. parent = parent.parentNode;
  53520. }
  53521. return false;
  53522. };
  53523. /**
  53524. * if this is an descendant of another node
  53525. *
  53526. * @param node another node
  53527. * @return if is descendant
  53528. */
  53529. TreeNode.prototype.isDescendantOf = function (node) {
  53530. return node !== this && node.isAncestorOf(this);
  53531. };
  53532. return TreeNode;
  53533. }();
  53534. var Tree = /** @class */function () {
  53535. function Tree(hostModel) {
  53536. this.type = 'tree';
  53537. this._nodes = [];
  53538. this.hostModel = hostModel;
  53539. }
  53540. Tree.prototype.eachNode = function (options, cb, context) {
  53541. this.root.eachNode(options, cb, context);
  53542. };
  53543. Tree.prototype.getNodeByDataIndex = function (dataIndex) {
  53544. var rawIndex = this.data.getRawIndex(dataIndex);
  53545. return this._nodes[rawIndex];
  53546. };
  53547. Tree.prototype.getNodeById = function (name) {
  53548. return this.root.getNodeById(name);
  53549. };
  53550. /**
  53551. * Update item available by list,
  53552. * when list has been performed options like 'filterSelf' or 'map'.
  53553. */
  53554. Tree.prototype.update = function () {
  53555. var data = this.data;
  53556. var nodes = this._nodes;
  53557. for (var i = 0, len = nodes.length; i < len; i++) {
  53558. nodes[i].dataIndex = -1;
  53559. }
  53560. for (var i = 0, len = data.count(); i < len; i++) {
  53561. nodes[data.getRawIndex(i)].dataIndex = i;
  53562. }
  53563. };
  53564. /**
  53565. * Clear all layouts
  53566. */
  53567. Tree.prototype.clearLayouts = function () {
  53568. this.data.clearItemLayouts();
  53569. };
  53570. /**
  53571. * data node format:
  53572. * {
  53573. * name: ...
  53574. * value: ...
  53575. * children: [
  53576. * {
  53577. * name: ...
  53578. * value: ...
  53579. * children: ...
  53580. * },
  53581. * ...
  53582. * ]
  53583. * }
  53584. */
  53585. Tree.createTree = function (dataRoot, hostModel, beforeLink) {
  53586. var tree = new Tree(hostModel);
  53587. var listData = [];
  53588. var dimMax = 1;
  53589. buildHierarchy(dataRoot);
  53590. function buildHierarchy(dataNode, parentNode) {
  53591. var value = dataNode.value;
  53592. dimMax = Math.max(dimMax, isArray(value) ? value.length : 1);
  53593. listData.push(dataNode);
  53594. var node = new TreeNode(convertOptionIdName(dataNode.name, ''), tree);
  53595. parentNode ? addChild(node, parentNode) : tree.root = node;
  53596. tree._nodes.push(node);
  53597. var children = dataNode.children;
  53598. if (children) {
  53599. for (var i = 0; i < children.length; i++) {
  53600. buildHierarchy(children[i], node);
  53601. }
  53602. }
  53603. }
  53604. tree.root.updateDepthAndHeight(0);
  53605. var dimensions = prepareSeriesDataSchema(listData, {
  53606. coordDimensions: ['value'],
  53607. dimensionsCount: dimMax
  53608. }).dimensions;
  53609. var list = new SeriesData(dimensions, hostModel);
  53610. list.initData(listData);
  53611. beforeLink && beforeLink(list);
  53612. linkSeriesData({
  53613. mainData: list,
  53614. struct: tree,
  53615. structAttr: 'tree'
  53616. });
  53617. tree.update();
  53618. return tree;
  53619. };
  53620. return Tree;
  53621. }();
  53622. /**
  53623. * It is needed to consider the mess of 'list', 'hostModel' when creating a TreeNote,
  53624. * so this function is not ready and not necessary to be public.
  53625. */
  53626. function addChild(child, node) {
  53627. var children = node.children;
  53628. if (child.parentNode === node) {
  53629. return;
  53630. }
  53631. children.push(child);
  53632. child.parentNode = node;
  53633. }
  53634. function retrieveTargetInfo(payload, validPayloadTypes, seriesModel) {
  53635. if (payload && indexOf(validPayloadTypes, payload.type) >= 0) {
  53636. var root = seriesModel.getData().tree.root;
  53637. var targetNode = payload.targetNode;
  53638. if (isString(targetNode)) {
  53639. targetNode = root.getNodeById(targetNode);
  53640. }
  53641. if (targetNode && root.contains(targetNode)) {
  53642. return {
  53643. node: targetNode
  53644. };
  53645. }
  53646. var targetNodeId = payload.targetNodeId;
  53647. if (targetNodeId != null && (targetNode = root.getNodeById(targetNodeId))) {
  53648. return {
  53649. node: targetNode
  53650. };
  53651. }
  53652. }
  53653. }
  53654. // Not includes the given node at the last item.
  53655. function getPathToRoot(node) {
  53656. var path = [];
  53657. while (node) {
  53658. node = node.parentNode;
  53659. node && path.push(node);
  53660. }
  53661. return path.reverse();
  53662. }
  53663. function aboveViewRoot(viewRoot, node) {
  53664. var viewPath = getPathToRoot(viewRoot);
  53665. return indexOf(viewPath, node) >= 0;
  53666. }
  53667. // From root to the input node (the input node will be included).
  53668. function wrapTreePathInfo(node, seriesModel) {
  53669. var treePathInfo = [];
  53670. while (node) {
  53671. var nodeDataIndex = node.dataIndex;
  53672. treePathInfo.push({
  53673. name: node.name,
  53674. dataIndex: nodeDataIndex,
  53675. value: seriesModel.getRawValue(nodeDataIndex)
  53676. });
  53677. node = node.parentNode;
  53678. }
  53679. treePathInfo.reverse();
  53680. return treePathInfo;
  53681. }
  53682. var TreeSeriesModel = /** @class */function (_super) {
  53683. __extends(TreeSeriesModel, _super);
  53684. function TreeSeriesModel() {
  53685. var _this = _super !== null && _super.apply(this, arguments) || this;
  53686. _this.hasSymbolVisual = true;
  53687. // Do it self.
  53688. _this.ignoreStyleOnData = true;
  53689. return _this;
  53690. }
  53691. /**
  53692. * Init a tree data structure from data in option series
  53693. */
  53694. TreeSeriesModel.prototype.getInitialData = function (option) {
  53695. // create a virtual root
  53696. var root = {
  53697. name: option.name,
  53698. children: option.data
  53699. };
  53700. var leaves = option.leaves || {};
  53701. var leavesModel = new Model(leaves, this, this.ecModel);
  53702. var tree = Tree.createTree(root, this, beforeLink);
  53703. function beforeLink(nodeData) {
  53704. nodeData.wrapMethod('getItemModel', function (model, idx) {
  53705. var node = tree.getNodeByDataIndex(idx);
  53706. if (!(node && node.children.length && node.isExpand)) {
  53707. model.parentModel = leavesModel;
  53708. }
  53709. return model;
  53710. });
  53711. }
  53712. var treeDepth = 0;
  53713. tree.eachNode('preorder', function (node) {
  53714. if (node.depth > treeDepth) {
  53715. treeDepth = node.depth;
  53716. }
  53717. });
  53718. var expandAndCollapse = option.expandAndCollapse;
  53719. var expandTreeDepth = expandAndCollapse && option.initialTreeDepth >= 0 ? option.initialTreeDepth : treeDepth;
  53720. tree.root.eachNode('preorder', function (node) {
  53721. var item = node.hostTree.data.getRawDataItem(node.dataIndex);
  53722. // Add item.collapsed != null, because users can collapse node original in the series.data.
  53723. node.isExpand = item && item.collapsed != null ? !item.collapsed : node.depth <= expandTreeDepth;
  53724. });
  53725. return tree.data;
  53726. };
  53727. /**
  53728. * Make the configuration 'orient' backward compatibly, with 'horizontal = LR', 'vertical = TB'.
  53729. * @returns {string} orient
  53730. */
  53731. TreeSeriesModel.prototype.getOrient = function () {
  53732. var orient = this.get('orient');
  53733. if (orient === 'horizontal') {
  53734. orient = 'LR';
  53735. } else if (orient === 'vertical') {
  53736. orient = 'TB';
  53737. }
  53738. return orient;
  53739. };
  53740. TreeSeriesModel.prototype.setZoom = function (zoom) {
  53741. this.option.zoom = zoom;
  53742. };
  53743. TreeSeriesModel.prototype.setCenter = function (center) {
  53744. this.option.center = center;
  53745. };
  53746. TreeSeriesModel.prototype.formatTooltip = function (dataIndex, multipleSeries, dataType) {
  53747. var tree = this.getData().tree;
  53748. var realRoot = tree.root.children[0];
  53749. var node = tree.getNodeByDataIndex(dataIndex);
  53750. var value = node.getValue();
  53751. var name = node.name;
  53752. while (node && node !== realRoot) {
  53753. name = node.parentNode.name + '.' + name;
  53754. node = node.parentNode;
  53755. }
  53756. return createTooltipMarkup('nameValue', {
  53757. name: name,
  53758. value: value,
  53759. noValue: isNaN(value) || value == null
  53760. });
  53761. };
  53762. // Add tree path to tooltip param
  53763. TreeSeriesModel.prototype.getDataParams = function (dataIndex) {
  53764. var params = _super.prototype.getDataParams.apply(this, arguments);
  53765. var node = this.getData().tree.getNodeByDataIndex(dataIndex);
  53766. params.treeAncestors = wrapTreePathInfo(node, this);
  53767. params.collapsed = !node.isExpand;
  53768. return params;
  53769. };
  53770. TreeSeriesModel.type = 'series.tree';
  53771. // can support the position parameters 'left', 'top','right','bottom', 'width',
  53772. // 'height' in the setOption() with 'merge' mode normal.
  53773. TreeSeriesModel.layoutMode = 'box';
  53774. TreeSeriesModel.defaultOption = {
  53775. // zlevel: 0,
  53776. z: 2,
  53777. // `coordinateSystem` can be declared as 'matrix', 'calendar',
  53778. // which provides box layout container.
  53779. coordinateSystemUsage: 'box',
  53780. // the position of the whole view
  53781. left: '12%',
  53782. top: '12%',
  53783. right: '12%',
  53784. bottom: '12%',
  53785. // the layout of the tree, two value can be selected, 'orthogonal' or 'radial'
  53786. layout: 'orthogonal',
  53787. // value can be 'polyline'
  53788. edgeShape: 'curve',
  53789. edgeForkPosition: '50%',
  53790. // true | false | 'move' | 'scale', see module:component/helper/RoamController.
  53791. roam: false,
  53792. roamTrigger: 'global',
  53793. // Symbol size scale ratio in roam
  53794. nodeScaleRatio: 0.4,
  53795. // Default on center of graph
  53796. center: null,
  53797. zoom: 1,
  53798. orient: 'LR',
  53799. symbol: 'emptyCircle',
  53800. symbolSize: 7,
  53801. expandAndCollapse: true,
  53802. initialTreeDepth: 2,
  53803. lineStyle: {
  53804. color: tokens.color.borderTint,
  53805. width: 1.5,
  53806. curveness: 0.5
  53807. },
  53808. itemStyle: {
  53809. color: 'lightsteelblue',
  53810. // borderColor: '#c23531',
  53811. borderWidth: 1.5
  53812. },
  53813. label: {
  53814. show: true
  53815. },
  53816. animationEasing: 'linear',
  53817. animationDuration: 700,
  53818. animationDurationUpdate: 500
  53819. };
  53820. return TreeSeriesModel;
  53821. }(SeriesModel);
  53822. /*
  53823. * Licensed to the Apache Software Foundation (ASF) under one
  53824. * or more contributor license agreements. See the NOTICE file
  53825. * distributed with this work for additional information
  53826. * regarding copyright ownership. The ASF licenses this file
  53827. * to you under the Apache License, Version 2.0 (the
  53828. * "License"); you may not use this file except in compliance
  53829. * with the License. You may obtain a copy of the License at
  53830. *
  53831. * http://www.apache.org/licenses/LICENSE-2.0
  53832. *
  53833. * Unless required by applicable law or agreed to in writing,
  53834. * software distributed under the License is distributed on an
  53835. * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
  53836. * KIND, either express or implied. See the License for the
  53837. * specific language governing permissions and limitations
  53838. * under the License.
  53839. */
  53840. /**
  53841. * AUTO-GENERATED FILE. DO NOT MODIFY.
  53842. */
  53843. /*
  53844. * Licensed to the Apache Software Foundation (ASF) under one
  53845. * or more contributor license agreements. See the NOTICE file
  53846. * distributed with this work for additional information
  53847. * regarding copyright ownership. The ASF licenses this file
  53848. * to you under the Apache License, Version 2.0 (the
  53849. * "License"); you may not use this file except in compliance
  53850. * with the License. You may obtain a copy of the License at
  53851. *
  53852. * http://www.apache.org/licenses/LICENSE-2.0
  53853. *
  53854. * Unless required by applicable law or agreed to in writing,
  53855. * software distributed under the License is distributed on an
  53856. * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
  53857. * KIND, either express or implied. See the License for the
  53858. * specific language governing permissions and limitations
  53859. * under the License.
  53860. */
  53861. /**
  53862. * Traverse the tree from bottom to top and do something
  53863. */
  53864. function eachAfter(root, callback, separation) {
  53865. var nodes = [root];
  53866. var next = [];
  53867. var node;
  53868. while (node = nodes.pop()) {
  53869. // jshint ignore:line
  53870. next.push(node);
  53871. if (node.isExpand) {
  53872. var children = node.children;
  53873. if (children.length) {
  53874. for (var i = 0; i < children.length; i++) {
  53875. nodes.push(children[i]);
  53876. }
  53877. }
  53878. }
  53879. }
  53880. while (node = next.pop()) {
  53881. // jshint ignore:line
  53882. callback(node, separation);
  53883. }
  53884. }
  53885. /**
  53886. * Traverse the tree from top to bottom and do something
  53887. */
  53888. function eachBefore(root, callback) {
  53889. var nodes = [root];
  53890. var node;
  53891. while (node = nodes.pop()) {
  53892. // jshint ignore:line
  53893. callback(node);
  53894. if (node.isExpand) {
  53895. var children = node.children;
  53896. if (children.length) {
  53897. for (var i = children.length - 1; i >= 0; i--) {
  53898. nodes.push(children[i]);
  53899. }
  53900. }
  53901. }
  53902. }
  53903. }
  53904. function treeLayout(ecModel, api) {
  53905. ecModel.eachSeriesByType('tree', function (seriesModel) {
  53906. commonLayout(seriesModel, api);
  53907. });
  53908. }
  53909. function commonLayout(seriesModel, api) {
  53910. var refContainer = createBoxLayoutReference(seriesModel, api).refContainer;
  53911. var layoutInfo = getLayoutRect(seriesModel.getBoxLayoutParams(), refContainer);
  53912. seriesModel.layoutInfo = layoutInfo;
  53913. var layout = seriesModel.get('layout');
  53914. var width = 0;
  53915. var height = 0;
  53916. var separation$1 = null;
  53917. if (layout === 'radial') {
  53918. width = 2 * Math.PI;
  53919. height = Math.min(layoutInfo.height, layoutInfo.width) / 2;
  53920. separation$1 = separation(function (node1, node2) {
  53921. return (node1.parentNode === node2.parentNode ? 1 : 2) / node1.depth;
  53922. });
  53923. } else {
  53924. width = layoutInfo.width;
  53925. height = layoutInfo.height;
  53926. separation$1 = separation();
  53927. }
  53928. var virtualRoot = seriesModel.getData().tree.root;
  53929. var realRoot = virtualRoot.children[0];
  53930. if (realRoot) {
  53931. init$2(virtualRoot);
  53932. eachAfter(realRoot, firstWalk, separation$1);
  53933. virtualRoot.hierNode.modifier = -realRoot.hierNode.prelim;
  53934. eachBefore(realRoot, secondWalk);
  53935. var left_1 = realRoot;
  53936. var right_1 = realRoot;
  53937. var bottom_1 = realRoot;
  53938. eachBefore(realRoot, function (node) {
  53939. var x = node.getLayout().x;
  53940. if (x < left_1.getLayout().x) {
  53941. left_1 = node;
  53942. }
  53943. if (x > right_1.getLayout().x) {
  53944. right_1 = node;
  53945. }
  53946. if (node.depth > bottom_1.depth) {
  53947. bottom_1 = node;
  53948. }
  53949. });
  53950. var delta = left_1 === right_1 ? 1 : separation$1(left_1, right_1) / 2;
  53951. var tx_1 = delta - left_1.getLayout().x;
  53952. var kx_1 = 0;
  53953. var ky_1 = 0;
  53954. var coorX_1 = 0;
  53955. var coorY_1 = 0;
  53956. if (layout === 'radial') {
  53957. kx_1 = width / (right_1.getLayout().x + delta + tx_1);
  53958. // here we use (node.depth - 1), bucause the real root's depth is 1
  53959. ky_1 = height / (bottom_1.depth - 1 || 1);
  53960. eachBefore(realRoot, function (node) {
  53961. coorX_1 = (node.getLayout().x + tx_1) * kx_1;
  53962. coorY_1 = (node.depth - 1) * ky_1;
  53963. var finalCoor = radialCoordinate(coorX_1, coorY_1);
  53964. node.setLayout({
  53965. x: finalCoor.x,
  53966. y: finalCoor.y,
  53967. rawX: coorX_1,
  53968. rawY: coorY_1
  53969. }, true);
  53970. });
  53971. } else {
  53972. var orient_1 = seriesModel.getOrient();
  53973. if (orient_1 === 'RL' || orient_1 === 'LR') {
  53974. ky_1 = height / (right_1.getLayout().x + delta + tx_1);
  53975. kx_1 = width / (bottom_1.depth - 1 || 1);
  53976. eachBefore(realRoot, function (node) {
  53977. coorY_1 = (node.getLayout().x + tx_1) * ky_1;
  53978. coorX_1 = orient_1 === 'LR' ? (node.depth - 1) * kx_1 : width - (node.depth - 1) * kx_1;
  53979. node.setLayout({
  53980. x: coorX_1,
  53981. y: coorY_1
  53982. }, true);
  53983. });
  53984. } else if (orient_1 === 'TB' || orient_1 === 'BT') {
  53985. kx_1 = width / (right_1.getLayout().x + delta + tx_1);
  53986. ky_1 = height / (bottom_1.depth - 1 || 1);
  53987. eachBefore(realRoot, function (node) {
  53988. coorX_1 = (node.getLayout().x + tx_1) * kx_1;
  53989. coorY_1 = orient_1 === 'TB' ? (node.depth - 1) * ky_1 : height - (node.depth - 1) * ky_1;
  53990. node.setLayout({
  53991. x: coorX_1,
  53992. y: coorY_1
  53993. }, true);
  53994. });
  53995. }
  53996. }
  53997. }
  53998. }
  53999. function treeVisual(ecModel) {
  54000. ecModel.eachSeriesByType('tree', function (seriesModel) {
  54001. var data = seriesModel.getData();
  54002. var tree = data.tree;
  54003. tree.eachNode(function (node) {
  54004. var model = node.getModel();
  54005. // TODO Optimize
  54006. var style = model.getModel('itemStyle').getItemStyle();
  54007. var existsStyle = data.ensureUniqueItemVisual(node.dataIndex, 'style');
  54008. extend(existsStyle, style);
  54009. });
  54010. });
  54011. }
  54012. function installTreeAction(registers) {
  54013. registers.registerAction({
  54014. type: 'treeExpandAndCollapse',
  54015. event: 'treeExpandAndCollapse',
  54016. update: 'update'
  54017. }, function (payload, ecModel) {
  54018. ecModel.eachComponent({
  54019. mainType: 'series',
  54020. subType: 'tree',
  54021. query: payload
  54022. }, function (seriesModel) {
  54023. var dataIndex = payload.dataIndex;
  54024. var tree = seriesModel.getData().tree;
  54025. var node = tree.getNodeByDataIndex(dataIndex);
  54026. node.isExpand = !node.isExpand;
  54027. });
  54028. });
  54029. registers.registerAction({
  54030. type: 'treeRoam',
  54031. event: 'treeRoam',
  54032. // Here we set 'none' instead of 'update', because roam action
  54033. // just need to update the transform matrix without having to recalculate
  54034. // the layout. So don't need to go through the whole update process, such
  54035. // as 'dataPrcocess', 'coordSystemUpdate', 'layout' and so on.
  54036. update: 'none'
  54037. }, function (payload, ecModel, api) {
  54038. ecModel.eachComponent({
  54039. mainType: 'series',
  54040. subType: 'tree',
  54041. query: payload
  54042. }, function (seriesModel) {
  54043. var coordSys = seriesModel.coordinateSystem;
  54044. var res = updateCenterAndZoomInAction(coordSys, payload, seriesModel.get('scaleLimit'));
  54045. seriesModel.setCenter(res.center);
  54046. seriesModel.setZoom(res.zoom);
  54047. });
  54048. });
  54049. }
  54050. function install$b(registers) {
  54051. registers.registerChartView(TreeView);
  54052. registers.registerSeriesModel(TreeSeriesModel);
  54053. registers.registerLayout(treeLayout);
  54054. registers.registerVisual(treeVisual);
  54055. installTreeAction(registers);
  54056. }
  54057. var actionTypes = ['treemapZoomToNode', 'treemapRender', 'treemapMove'];
  54058. function installTreemapAction(registers) {
  54059. for (var i = 0; i < actionTypes.length; i++) {
  54060. registers.registerAction({
  54061. type: actionTypes[i],
  54062. update: 'updateView'
  54063. }, noop);
  54064. }
  54065. registers.registerAction({
  54066. type: 'treemapRootToNode',
  54067. update: 'updateView'
  54068. }, function (payload, ecModel) {
  54069. ecModel.eachComponent({
  54070. mainType: 'series',
  54071. subType: 'treemap',
  54072. query: payload
  54073. }, handleRootToNode);
  54074. function handleRootToNode(model, index) {
  54075. var types = ['treemapZoomToNode', 'treemapRootToNode'];
  54076. var targetInfo = retrieveTargetInfo(payload, types, model);
  54077. if (targetInfo) {
  54078. var originViewRoot = model.getViewRoot();
  54079. if (originViewRoot) {
  54080. payload.direction = aboveViewRoot(originViewRoot, targetInfo.node) ? 'rollUp' : 'drillDown';
  54081. }
  54082. model.resetViewRoot(targetInfo.node);
  54083. }
  54084. }
  54085. });
  54086. }
  54087. function enableAriaDecalForTree(seriesModel) {
  54088. var data = seriesModel.getData();
  54089. var tree = data.tree;
  54090. var decalPaletteScope = {};
  54091. tree.eachNode(function (node) {
  54092. // Use decal of level 1 node
  54093. var current = node;
  54094. while (current && current.depth > 1) {
  54095. current = current.parentNode;
  54096. }
  54097. var decal = getDecalFromPalette(seriesModel.ecModel, current.name || current.dataIndex + '', decalPaletteScope);
  54098. node.setVisual('decal', decal);
  54099. });
  54100. }
  54101. var TreemapSeriesModel = /** @class */function (_super) {
  54102. __extends(TreemapSeriesModel, _super);
  54103. function TreemapSeriesModel() {
  54104. var _this = _super !== null && _super.apply(this, arguments) || this;
  54105. _this.type = TreemapSeriesModel.type;
  54106. _this.preventUsingHoverLayer = true;
  54107. return _this;
  54108. }
  54109. /**
  54110. * @override
  54111. */
  54112. TreemapSeriesModel.prototype.getInitialData = function (option, ecModel) {
  54113. // Create a virtual root.
  54114. var root = {
  54115. name: option.name,
  54116. children: option.data
  54117. };
  54118. completeTreeValue(root);
  54119. var levels = option.levels || [];
  54120. // Used in "visual priority" in `treemapVisual.js`.
  54121. // This way is a little tricky, must satisfy the precondition:
  54122. // 1. There is no `treeNode.getModel('itemStyle.xxx')` used.
  54123. // 2. The `Model.prototype.getModel()` will not use any clone-like way.
  54124. var designatedVisualItemStyle = this.designatedVisualItemStyle = {};
  54125. var designatedVisualModel = new Model({
  54126. itemStyle: designatedVisualItemStyle
  54127. }, this, ecModel);
  54128. levels = option.levels = setDefault(levels, ecModel);
  54129. var levelModels = map(levels || [], function (levelDefine) {
  54130. return new Model(levelDefine, designatedVisualModel, ecModel);
  54131. }, this);
  54132. // Make sure always a new tree is created when setOption,
  54133. // in TreemapView, we check whether oldTree === newTree
  54134. // to choose mappings approach among old shapes and new shapes.
  54135. var tree = Tree.createTree(root, this, beforeLink);
  54136. function beforeLink(nodeData) {
  54137. nodeData.wrapMethod('getItemModel', function (model, idx) {
  54138. var node = tree.getNodeByDataIndex(idx);
  54139. var levelModel = node ? levelModels[node.depth] : null;
  54140. // If no levelModel, we also need `designatedVisualModel`.
  54141. model.parentModel = levelModel || designatedVisualModel;
  54142. return model;
  54143. });
  54144. }
  54145. return tree.data;
  54146. };
  54147. TreemapSeriesModel.prototype.optionUpdated = function () {
  54148. this.resetViewRoot();
  54149. };
  54150. /**
  54151. * @override
  54152. * @param {number} dataIndex
  54153. * @param {boolean} [mutipleSeries=false]
  54154. */
  54155. TreemapSeriesModel.prototype.formatTooltip = function (dataIndex, multipleSeries, dataType) {
  54156. var data = this.getData();
  54157. var value = this.getRawValue(dataIndex);
  54158. var name = data.getName(dataIndex);
  54159. return createTooltipMarkup('nameValue', {
  54160. name: name,
  54161. value: value
  54162. });
  54163. };
  54164. /**
  54165. * Add tree path to tooltip param
  54166. *
  54167. * @override
  54168. * @param {number} dataIndex
  54169. * @return {Object}
  54170. */
  54171. TreemapSeriesModel.prototype.getDataParams = function (dataIndex) {
  54172. var params = _super.prototype.getDataParams.apply(this, arguments);
  54173. var node = this.getData().tree.getNodeByDataIndex(dataIndex);
  54174. params.treeAncestors = wrapTreePathInfo(node, this);
  54175. // compatitable the previous code.
  54176. params.treePathInfo = params.treeAncestors;
  54177. return params;
  54178. };
  54179. /**
  54180. * @public
  54181. * @param {Object} layoutInfo {
  54182. * x: containerGroup x
  54183. * y: containerGroup y
  54184. * width: containerGroup width
  54185. * height: containerGroup height
  54186. * }
  54187. */
  54188. TreemapSeriesModel.prototype.setLayoutInfo = function (layoutInfo) {
  54189. /**
  54190. * @readOnly
  54191. * @type {Object}
  54192. */
  54193. this.layoutInfo = this.layoutInfo || {};
  54194. extend(this.layoutInfo, layoutInfo);
  54195. };
  54196. /**
  54197. * @param {string} id
  54198. * @return {number} index
  54199. */
  54200. TreemapSeriesModel.prototype.mapIdToIndex = function (id) {
  54201. // A feature is implemented:
  54202. // index is monotone increasing with the sequence of
  54203. // input id at the first time.
  54204. // This feature can make sure that each data item and its
  54205. // mapped color have the same index between data list and
  54206. // color list at the beginning, which is useful for user
  54207. // to adjust data-color mapping.
  54208. /**
  54209. * @private
  54210. * @type {Object}
  54211. */
  54212. var idIndexMap = this._idIndexMap;
  54213. if (!idIndexMap) {
  54214. idIndexMap = this._idIndexMap = createHashMap();
  54215. /**
  54216. * @private
  54217. * @type {number}
  54218. */
  54219. this._idIndexMapCount = 0;
  54220. }
  54221. var index = idIndexMap.get(id);
  54222. if (index == null) {
  54223. idIndexMap.set(id, index = this._idIndexMapCount++);
  54224. }
  54225. return index;
  54226. };
  54227. TreemapSeriesModel.prototype.getViewRoot = function () {
  54228. return this._viewRoot;
  54229. };
  54230. TreemapSeriesModel.prototype.resetViewRoot = function (viewRoot) {
  54231. viewRoot ? this._viewRoot = viewRoot : viewRoot = this._viewRoot;
  54232. var root = this.getRawData().tree.root;
  54233. if (!viewRoot || viewRoot !== root && !root.contains(viewRoot)) {
  54234. this._viewRoot = root;
  54235. }
  54236. };
  54237. TreemapSeriesModel.prototype.enableAriaDecal = function () {
  54238. enableAriaDecalForTree(this);
  54239. };
  54240. TreemapSeriesModel.type = 'series.treemap';
  54241. TreemapSeriesModel.layoutMode = 'box';
  54242. TreemapSeriesModel.defaultOption = {
  54243. // Disable progressive rendering
  54244. progressive: 0,
  54245. // size: ['80%', '80%'], // deprecated, compatible with ec2.
  54246. // `coordinateSystem` can be declared as 'matrix', 'calendar',
  54247. // which provides box layout container.
  54248. coordinateSystemUsage: 'box',
  54249. left: tokens.size.l,
  54250. top: tokens.size.xxxl,
  54251. right: tokens.size.l,
  54252. bottom: tokens.size.xxxl,
  54253. sort: true,
  54254. clipWindow: 'origin',
  54255. squareRatio: 0.5 * (1 + Math.sqrt(5)),
  54256. leafDepth: null,
  54257. drillDownIcon: '▶',
  54258. // to align specialized icon. ▷▶❒❐▼✚
  54259. zoomToNodeRatio: 0.32 * 0.32,
  54260. scaleLimit: {
  54261. max: 5,
  54262. min: 0.2
  54263. },
  54264. roam: true,
  54265. roamTrigger: 'global',
  54266. nodeClick: 'zoomToNode',
  54267. animation: true,
  54268. animationDurationUpdate: 900,
  54269. animationEasing: 'quinticInOut',
  54270. breadcrumb: {
  54271. show: true,
  54272. height: 22,
  54273. left: 'center',
  54274. bottom: tokens.size.m,
  54275. // right
  54276. // bottom
  54277. emptyItemWidth: 25,
  54278. itemStyle: {
  54279. color: tokens.color.backgroundShade,
  54280. textStyle: {
  54281. color: tokens.color.secondary
  54282. }
  54283. },
  54284. emphasis: {
  54285. itemStyle: {
  54286. color: tokens.color.background
  54287. }
  54288. }
  54289. },
  54290. label: {
  54291. show: true,
  54292. // Do not use textDistance, for ellipsis rect just the same as treemap node rect.
  54293. distance: 0,
  54294. padding: 5,
  54295. position: 'inside',
  54296. // formatter: null,
  54297. color: tokens.color.neutral00,
  54298. overflow: 'truncate'
  54299. // align
  54300. // verticalAlign
  54301. },
  54302. upperLabel: {
  54303. show: false,
  54304. position: [0, '50%'],
  54305. height: 20,
  54306. // formatter: null,
  54307. // color: '#fff',
  54308. overflow: 'truncate',
  54309. // align: null,
  54310. verticalAlign: 'middle'
  54311. },
  54312. itemStyle: {
  54313. color: null,
  54314. colorAlpha: null,
  54315. colorSaturation: null,
  54316. borderWidth: 0,
  54317. gapWidth: 0,
  54318. borderColor: tokens.color.neutral00,
  54319. borderColorSaturation: null // If specified, borderColor will be ineffective, and the
  54320. // border color is evaluated by color of current node and
  54321. // borderColorSaturation.
  54322. },
  54323. emphasis: {
  54324. upperLabel: {
  54325. show: true,
  54326. position: [0, '50%'],
  54327. overflow: 'truncate',
  54328. verticalAlign: 'middle'
  54329. }
  54330. },
  54331. visualDimension: 0,
  54332. visualMin: null,
  54333. visualMax: null,
  54334. color: [],
  54335. // level[n].color (if necessary).
  54336. // + Specify color list of each level. level[0].color would be global
  54337. // color list if not specified. (see method `setDefault`).
  54338. // + But set as a empty array to forbid fetch color from global palette
  54339. // when using nodeModel.get('color'), otherwise nodes on deep level
  54340. // will always has color palette set and are not able to inherit color
  54341. // from parent node.
  54342. // + TreemapSeries.color can not be set as 'none', otherwise effect
  54343. // legend color fetching (see seriesColor.js).
  54344. colorAlpha: null,
  54345. colorSaturation: null,
  54346. colorMappingBy: 'index',
  54347. visibleMin: 10,
  54348. // be rendered. Only works when sort is 'asc' or 'desc'.
  54349. childrenVisibleMin: null,
  54350. // grandchildren will not show.
  54351. // Why grandchildren? If not grandchildren but children,
  54352. // some siblings show children and some not,
  54353. // the appearance may be mess and not consistent,
  54354. levels: [] // Each item: {
  54355. // visibleMin, itemStyle, visualDimension, label
  54356. // }
  54357. };
  54358. return TreemapSeriesModel;
  54359. }(SeriesModel);
  54360. /**
  54361. * @param {Object} dataNode
  54362. */
  54363. function completeTreeValue(dataNode) {
  54364. // Postorder travel tree.
  54365. // If value of none-leaf node is not set,
  54366. // calculate it by suming up the value of all children.
  54367. var sum = 0;
  54368. each(dataNode.children, function (child) {
  54369. completeTreeValue(child);
  54370. var childValue = child.value;
  54371. isArray(childValue) && (childValue = childValue[0]);
  54372. sum += childValue;
  54373. });
  54374. var thisValue = dataNode.value;
  54375. if (isArray(thisValue)) {
  54376. thisValue = thisValue[0];
  54377. }
  54378. if (thisValue == null || isNaN(thisValue)) {
  54379. thisValue = sum;
  54380. }
  54381. // Value should not less than 0.
  54382. if (thisValue < 0) {
  54383. thisValue = 0;
  54384. }
  54385. isArray(dataNode.value) ? dataNode.value[0] = thisValue : dataNode.value = thisValue;
  54386. }
  54387. /**
  54388. * set default to level configuration
  54389. */
  54390. function setDefault(levels, ecModel) {
  54391. var globalColorList = normalizeToArray(ecModel.get('color'));
  54392. var globalDecalList = normalizeToArray(ecModel.get(['aria', 'decal', 'decals']));
  54393. if (!globalColorList) {
  54394. return;
  54395. }
  54396. levels = levels || [];
  54397. var hasColorDefine;
  54398. var hasDecalDefine;
  54399. each(levels, function (levelDefine) {
  54400. var model = new Model(levelDefine);
  54401. var modelColor = model.get('color');
  54402. var modelDecal = model.get('decal');
  54403. if (model.get(['itemStyle', 'color']) || modelColor && modelColor !== 'none') {
  54404. hasColorDefine = true;
  54405. }
  54406. if (model.get(['itemStyle', 'decal']) || modelDecal && modelDecal !== 'none') {
  54407. hasDecalDefine = true;
  54408. }
  54409. });
  54410. var level0 = levels[0] || (levels[0] = {});
  54411. if (!hasColorDefine) {
  54412. level0.color = globalColorList.slice();
  54413. }
  54414. if (!hasDecalDefine && globalDecalList) {
  54415. level0.decal = globalDecalList.slice();
  54416. }
  54417. return levels;
  54418. }
  54419. var TEXT_PADDING = 8;
  54420. var ITEM_GAP = 8;
  54421. var ARRAY_LENGTH = 5;
  54422. var Breadcrumb = /** @class */function () {
  54423. function Breadcrumb(containerGroup) {
  54424. this.group = new Group();
  54425. containerGroup.add(this.group);
  54426. }
  54427. Breadcrumb.prototype.render = function (seriesModel, api, targetNode, onSelect) {
  54428. var model = seriesModel.getModel('breadcrumb');
  54429. var thisGroup = this.group;
  54430. thisGroup.removeAll();
  54431. if (!model.get('show') || !targetNode) {
  54432. return;
  54433. }
  54434. var normalStyleModel = model.getModel('itemStyle');
  54435. var emphasisModel = model.getModel('emphasis');
  54436. var textStyleModel = normalStyleModel.getModel('textStyle');
  54437. var emphasisTextStyleModel = emphasisModel.getModel(['itemStyle', 'textStyle']);
  54438. var refContainer = createBoxLayoutReference(seriesModel, api).refContainer;
  54439. var boxLayoutParams = {
  54440. left: model.get('left'),
  54441. right: model.get('right'),
  54442. top: model.get('top'),
  54443. bottom: model.get('bottom')
  54444. };
  54445. var layoutParam = {
  54446. emptyItemWidth: model.get('emptyItemWidth'),
  54447. totalWidth: 0,
  54448. renderList: []
  54449. };
  54450. var availableSize = getLayoutRect(boxLayoutParams, refContainer);
  54451. this._prepare(targetNode, layoutParam, textStyleModel);
  54452. this._renderContent(seriesModel, layoutParam, availableSize, normalStyleModel, emphasisModel, textStyleModel, emphasisTextStyleModel, onSelect);
  54453. positionElement(thisGroup, boxLayoutParams, refContainer);
  54454. };
  54455. /**
  54456. * Prepare render list and total width
  54457. * @private
  54458. */
  54459. Breadcrumb.prototype._prepare = function (targetNode, layoutParam, textStyleModel) {
  54460. for (var node = targetNode; node; node = node.parentNode) {
  54461. var text = convertOptionIdName(node.getModel().get('name'), '');
  54462. var textRect = textStyleModel.getTextRect(text);
  54463. var itemWidth = Math.max(textRect.width + TEXT_PADDING * 2, layoutParam.emptyItemWidth);
  54464. layoutParam.totalWidth += itemWidth + ITEM_GAP;
  54465. layoutParam.renderList.push({
  54466. node: node,
  54467. text: text,
  54468. width: itemWidth
  54469. });
  54470. }
  54471. };
  54472. /**
  54473. * @private
  54474. */
  54475. Breadcrumb.prototype._renderContent = function (seriesModel, layoutParam, availableSize, normalStyleModel, emphasisModel, textStyleModel, emphasisTextStyleModel, onSelect) {
  54476. // Start rendering.
  54477. var lastX = 0;
  54478. var emptyItemWidth = layoutParam.emptyItemWidth;
  54479. var height = seriesModel.get(['breadcrumb', 'height']);
  54480. var totalWidth = layoutParam.totalWidth;
  54481. var renderList = layoutParam.renderList;
  54482. var emphasisItemStyle = emphasisModel.getModel('itemStyle').getItemStyle();
  54483. for (var i = renderList.length - 1; i >= 0; i--) {
  54484. var item = renderList[i];
  54485. var itemNode = item.node;
  54486. var itemWidth = item.width;
  54487. var text = item.text;
  54488. // Hdie text and shorten width if necessary.
  54489. if (totalWidth > availableSize.width) {
  54490. totalWidth -= itemWidth - emptyItemWidth;
  54491. itemWidth = emptyItemWidth;
  54492. text = null;
  54493. }
  54494. var el = new Polygon({
  54495. shape: {
  54496. points: makeItemPoints(lastX, 0, itemWidth, height, i === renderList.length - 1, i === 0)
  54497. },
  54498. style: defaults(normalStyleModel.getItemStyle(), {
  54499. lineJoin: 'bevel'
  54500. }),
  54501. textContent: new ZRText({
  54502. style: createTextStyle(textStyleModel, {
  54503. text: text
  54504. })
  54505. }),
  54506. textConfig: {
  54507. position: 'inside'
  54508. },
  54509. z2: Z2_EMPHASIS_LIFT * 1e4,
  54510. onclick: curry(onSelect, itemNode)
  54511. });
  54512. el.disableLabelAnimation = true;
  54513. el.getTextContent().ensureState('emphasis').style = createTextStyle(emphasisTextStyleModel, {
  54514. text: text
  54515. });
  54516. el.ensureState('emphasis').style = emphasisItemStyle;
  54517. toggleHoverEmphasis(el, emphasisModel.get('focus'), emphasisModel.get('blurScope'), emphasisModel.get('disabled'));
  54518. this.group.add(el);
  54519. packEventData(el, seriesModel, itemNode);
  54520. lastX += itemWidth + ITEM_GAP;
  54521. }
  54522. };
  54523. Breadcrumb.prototype.remove = function () {
  54524. this.group.removeAll();
  54525. };
  54526. return Breadcrumb;
  54527. }();
  54528. function makeItemPoints(x, y, itemWidth, itemHeight, head, tail) {
  54529. var points = [[head ? x : x - ARRAY_LENGTH, y], [x + itemWidth, y], [x + itemWidth, y + itemHeight], [head ? x : x - ARRAY_LENGTH, y + itemHeight]];
  54530. !tail && points.splice(2, 0, [x + itemWidth + ARRAY_LENGTH, y + itemHeight / 2]);
  54531. !head && points.push([x, y + itemHeight / 2]);
  54532. return points;
  54533. }
  54534. // Package custom mouse event.
  54535. function packEventData(el, seriesModel, itemNode) {
  54536. getECData(el).eventData = {
  54537. componentType: 'series',
  54538. componentSubType: 'treemap',
  54539. componentIndex: seriesModel.componentIndex,
  54540. seriesIndex: seriesModel.seriesIndex,
  54541. seriesName: seriesModel.name,
  54542. seriesType: 'treemap',
  54543. selfType: 'breadcrumb',
  54544. nodeData: {
  54545. dataIndex: itemNode && itemNode.dataIndex,
  54546. name: itemNode && itemNode.name
  54547. },
  54548. treePathInfo: itemNode && wrapTreePathInfo(itemNode, seriesModel)
  54549. };
  54550. }
  54551. /*
  54552. * Licensed to the Apache Software Foundation (ASF) under one
  54553. * or more contributor license agreements. See the NOTICE file
  54554. * distributed with this work for additional information
  54555. * regarding copyright ownership. The ASF licenses this file
  54556. * to you under the Apache License, Version 2.0 (the
  54557. * "License"); you may not use this file except in compliance
  54558. * with the License. You may obtain a copy of the License at
  54559. *
  54560. * http://www.apache.org/licenses/LICENSE-2.0
  54561. *
  54562. * Unless required by applicable law or agreed to in writing,
  54563. * software distributed under the License is distributed on an
  54564. * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
  54565. * KIND, either express or implied. See the License for the
  54566. * specific language governing permissions and limitations
  54567. * under the License.
  54568. */
  54569. /**
  54570. * AUTO-GENERATED FILE. DO NOT MODIFY.
  54571. */
  54572. /*
  54573. * Licensed to the Apache Software Foundation (ASF) under one
  54574. * or more contributor license agreements. See the NOTICE file
  54575. * distributed with this work for additional information
  54576. * regarding copyright ownership. The ASF licenses this file
  54577. * to you under the Apache License, Version 2.0 (the
  54578. * "License"); you may not use this file except in compliance
  54579. * with the License. You may obtain a copy of the License at
  54580. *
  54581. * http://www.apache.org/licenses/LICENSE-2.0
  54582. *
  54583. * Unless required by applicable law or agreed to in writing,
  54584. * software distributed under the License is distributed on an
  54585. * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
  54586. * KIND, either express or implied. See the License for the
  54587. * specific language governing permissions and limitations
  54588. * under the License.
  54589. */
  54590. /**
  54591. * Animate multiple elements with a single done-callback.
  54592. *
  54593. * @example
  54594. * animation
  54595. * .createWrap()
  54596. * .add(el1, {x: 10, y: 10})
  54597. * .add(el2, {shape: {width: 500}, style: {fill: 'red'}}, 400)
  54598. * .done(function () { // done })
  54599. * .start('cubicOut');
  54600. */
  54601. var AnimationWrap = /** @class */function () {
  54602. function AnimationWrap() {
  54603. this._storage = [];
  54604. this._elExistsMap = {};
  54605. }
  54606. /**
  54607. * Caution: a el can only be added once, otherwise 'done'
  54608. * might not be called. This method checks this (by el.id),
  54609. * suppresses adding and returns false when existing el found.
  54610. *
  54611. * @return Whether adding succeeded.
  54612. */
  54613. AnimationWrap.prototype.add = function (el, target, duration, delay, easing) {
  54614. if (this._elExistsMap[el.id]) {
  54615. return false;
  54616. }
  54617. this._elExistsMap[el.id] = true;
  54618. this._storage.push({
  54619. el: el,
  54620. target: target,
  54621. duration: duration,
  54622. delay: delay,
  54623. easing: easing
  54624. });
  54625. return true;
  54626. };
  54627. /**
  54628. * Only execute when animation done/aborted.
  54629. */
  54630. AnimationWrap.prototype.finished = function (callback) {
  54631. this._finishedCallback = callback;
  54632. return this;
  54633. };
  54634. /**
  54635. * Will stop exist animation firstly.
  54636. */
  54637. AnimationWrap.prototype.start = function () {
  54638. var _this = this;
  54639. var count = this._storage.length;
  54640. var checkTerminate = function () {
  54641. count--;
  54642. if (count <= 0) {
  54643. // Guard.
  54644. _this._storage.length = 0;
  54645. _this._elExistsMap = {};
  54646. _this._finishedCallback && _this._finishedCallback();
  54647. }
  54648. };
  54649. for (var i = 0, len = this._storage.length; i < len; i++) {
  54650. var item = this._storage[i];
  54651. item.el.animateTo(item.target, {
  54652. duration: item.duration,
  54653. delay: item.delay,
  54654. easing: item.easing,
  54655. setToFinal: true,
  54656. done: checkTerminate,
  54657. aborted: checkTerminate
  54658. });
  54659. }
  54660. return this;
  54661. };
  54662. return AnimationWrap;
  54663. }();
  54664. function createWrap() {
  54665. return new AnimationWrap();
  54666. }
  54667. var Group$1 = Group;
  54668. var Rect$1 = Rect;
  54669. var DRAG_THRESHOLD = 3;
  54670. var PATH_LABEL_NOAMAL = 'label';
  54671. var PATH_UPPERLABEL_NORMAL = 'upperLabel';
  54672. // Should larger than emphasis states lift z
  54673. var Z2_BASE = Z2_EMPHASIS_LIFT * 10; // Should bigger than every z2.
  54674. var Z2_BG = Z2_EMPHASIS_LIFT * 2;
  54675. var Z2_CONTENT = Z2_EMPHASIS_LIFT * 3;
  54676. var getStateItemStyle = makeStyleMapper([['fill', 'color'],
  54677. // `borderColor` and `borderWidth` has been occupied,
  54678. // so use `stroke` to indicate the stroke of the rect.
  54679. ['stroke', 'strokeColor'], ['lineWidth', 'strokeWidth'], ['shadowBlur'], ['shadowOffsetX'], ['shadowOffsetY'], ['shadowColor']
  54680. // Option decal is in `DecalObject` but style.decal is in `PatternObject`.
  54681. // So do not transfer decal directly.
  54682. ]);
  54683. var getItemStyleNormal = function (model) {
  54684. // Normal style props should include emphasis style props.
  54685. var itemStyle = getStateItemStyle(model);
  54686. // Clear styles set by emphasis.
  54687. itemStyle.stroke = itemStyle.fill = itemStyle.lineWidth = null;
  54688. return itemStyle;
  54689. };
  54690. var inner$9 = makeInner();
  54691. var TreemapView = /** @class */function (_super) {
  54692. __extends(TreemapView, _super);
  54693. function TreemapView() {
  54694. var _this = _super !== null && _super.apply(this, arguments) || this;
  54695. _this.type = TreemapView.type;
  54696. _this._state = 'ready';
  54697. _this._storage = createStorage();
  54698. return _this;
  54699. }
  54700. /**
  54701. * @override
  54702. */
  54703. TreemapView.prototype.render = function (seriesModel, ecModel, api, payload) {
  54704. var models = ecModel.findComponents({
  54705. mainType: 'series',
  54706. subType: 'treemap',
  54707. query: payload
  54708. });
  54709. if (indexOf(models, seriesModel) < 0) {
  54710. return;
  54711. }
  54712. this.seriesModel = seriesModel;
  54713. this.api = api;
  54714. this.ecModel = ecModel;
  54715. var types = ['treemapZoomToNode', 'treemapRootToNode'];
  54716. var targetInfo = retrieveTargetInfo(payload, types, seriesModel);
  54717. var payloadType = payload && payload.type;
  54718. var layoutInfo = seriesModel.layoutInfo;
  54719. var isInit = !this._oldTree;
  54720. var thisStorage = this._storage;
  54721. // Mark new root when action is treemapRootToNode.
  54722. var reRoot = payloadType === 'treemapRootToNode' && targetInfo && thisStorage ? {
  54723. rootNodeGroup: thisStorage.nodeGroup[targetInfo.node.getRawIndex()],
  54724. direction: payload.direction
  54725. } : null;
  54726. var containerGroup = this._giveContainerGroup(layoutInfo);
  54727. var hasAnimation = seriesModel.get('animation');
  54728. var renderResult = this._doRender(containerGroup, seriesModel, reRoot);
  54729. hasAnimation && !isInit && (!payloadType || payloadType === 'treemapZoomToNode' || payloadType === 'treemapRootToNode') ? this._doAnimation(containerGroup, renderResult, seriesModel, reRoot) : renderResult.renderFinally();
  54730. this._resetController(api);
  54731. this._renderBreadcrumb(seriesModel, api, targetInfo);
  54732. };
  54733. TreemapView.prototype._giveContainerGroup = function (layoutInfo) {
  54734. var containerGroup = this._containerGroup;
  54735. if (!containerGroup) {
  54736. // FIXME
  54737. // 加一层containerGroup是为了clip,但是现在clip功能并没有实现。
  54738. containerGroup = this._containerGroup = new Group$1();
  54739. this._initEvents(containerGroup);
  54740. this.group.add(containerGroup);
  54741. }
  54742. containerGroup.x = layoutInfo.x;
  54743. containerGroup.y = layoutInfo.y;
  54744. return containerGroup;
  54745. };
  54746. TreemapView.prototype._doRender = function (containerGroup, seriesModel, reRoot) {
  54747. var thisTree = seriesModel.getData().tree;
  54748. var oldTree = this._oldTree;
  54749. // Clear last shape records.
  54750. var lastsForAnimation = createStorage();
  54751. var thisStorage = createStorage();
  54752. var oldStorage = this._storage;
  54753. var willInvisibleEls = [];
  54754. function doRenderNode(thisNode, oldNode, parentGroup, depth) {
  54755. return renderNode(seriesModel, thisStorage, oldStorage, reRoot, lastsForAnimation, willInvisibleEls, thisNode, oldNode, parentGroup, depth);
  54756. }
  54757. // Notice: When thisTree and oldTree are the same tree (see list.cloneShallow),
  54758. // the oldTree is actually losted, so we cannot find all of the old graphic
  54759. // elements from tree. So we use this strategy: make element storage, move
  54760. // from old storage to new storage, clear old storage.
  54761. dualTravel(thisTree.root ? [thisTree.root] : [], oldTree && oldTree.root ? [oldTree.root] : [], containerGroup, thisTree === oldTree || !oldTree, 0);
  54762. // Process all removing.
  54763. var willDeleteEls = clearStorage(oldStorage);
  54764. this._oldTree = thisTree;
  54765. this._storage = thisStorage;
  54766. if (this._controllerHost) {
  54767. var _oldRootLayout = this.seriesModel.layoutInfo;
  54768. var rootLayout = thisTree.root.getLayout();
  54769. if (rootLayout.width === _oldRootLayout.width && rootLayout.height === _oldRootLayout.height) {
  54770. this._controllerHost.zoom = 1;
  54771. }
  54772. }
  54773. return {
  54774. lastsForAnimation: lastsForAnimation,
  54775. willDeleteEls: willDeleteEls,
  54776. renderFinally: renderFinally
  54777. };
  54778. function dualTravel(thisViewChildren, oldViewChildren, parentGroup, sameTree, depth) {
  54779. // When 'render' is triggered by action,
  54780. // 'this' and 'old' may be the same tree,
  54781. // we use rawIndex in that case.
  54782. if (sameTree) {
  54783. oldViewChildren = thisViewChildren;
  54784. each(thisViewChildren, function (child, index) {
  54785. !child.isRemoved() && processNode(index, index);
  54786. });
  54787. }
  54788. // Diff hierarchically (diff only in each subtree, but not whole).
  54789. // because, consistency of view is important.
  54790. else {
  54791. new DataDiffer(oldViewChildren, thisViewChildren, getKey, getKey).add(processNode).update(processNode).remove(curry(processNode, null)).execute();
  54792. }
  54793. function getKey(node) {
  54794. // Identify by name or raw index.
  54795. return node.getId();
  54796. }
  54797. function processNode(newIndex, oldIndex) {
  54798. var thisNode = newIndex != null ? thisViewChildren[newIndex] : null;
  54799. var oldNode = oldIndex != null ? oldViewChildren[oldIndex] : null;
  54800. var group = doRenderNode(thisNode, oldNode, parentGroup, depth);
  54801. group && dualTravel(thisNode && thisNode.viewChildren || [], oldNode && oldNode.viewChildren || [], group, sameTree, depth + 1);
  54802. }
  54803. }
  54804. function clearStorage(storage) {
  54805. var willDeleteEls = createStorage();
  54806. storage && each(storage, function (store, storageName) {
  54807. var delEls = willDeleteEls[storageName];
  54808. each(store, function (el) {
  54809. el && (delEls.push(el), inner$9(el).willDelete = true);
  54810. });
  54811. });
  54812. return willDeleteEls;
  54813. }
  54814. function renderFinally() {
  54815. each(willDeleteEls, function (els) {
  54816. each(els, function (el) {
  54817. el.parent && el.parent.remove(el);
  54818. });
  54819. });
  54820. each(willInvisibleEls, function (el) {
  54821. el.invisible = true;
  54822. // Setting invisible is for optimizing, so no need to set dirty,
  54823. // just mark as invisible.
  54824. el.dirty();
  54825. });
  54826. }
  54827. };
  54828. TreemapView.prototype._doAnimation = function (containerGroup, renderResult, seriesModel, reRoot) {
  54829. var durationOption = seriesModel.get('animationDurationUpdate');
  54830. var easingOption = seriesModel.get('animationEasing');
  54831. // TODO: do not support function until necessary.
  54832. var duration = (isFunction(durationOption) ? 0 : durationOption) || 0;
  54833. var easing = (isFunction(easingOption) ? null : easingOption) || 'cubicOut';
  54834. var animationWrap = createWrap();
  54835. // Make delete animations.
  54836. each(renderResult.willDeleteEls, function (store, storageName) {
  54837. each(store, function (el, rawIndex) {
  54838. if (el.invisible) {
  54839. return;
  54840. }
  54841. var parent = el.parent; // Always has parent, and parent is nodeGroup.
  54842. var target;
  54843. var innerStore = inner$9(parent);
  54844. if (reRoot && reRoot.direction === 'drillDown') {
  54845. target = parent === reRoot.rootNodeGroup
  54846. // This is the content element of view root.
  54847. // Only `content` will enter this branch, because
  54848. // `background` and `nodeGroup` will not be deleted.
  54849. ? {
  54850. shape: {
  54851. x: 0,
  54852. y: 0,
  54853. width: innerStore.nodeWidth,
  54854. height: innerStore.nodeHeight
  54855. },
  54856. style: {
  54857. opacity: 0
  54858. }
  54859. }
  54860. // Others.
  54861. : {
  54862. style: {
  54863. opacity: 0
  54864. }
  54865. };
  54866. } else {
  54867. var targetX = 0;
  54868. var targetY = 0;
  54869. if (!innerStore.willDelete) {
  54870. // Let node animate to right-bottom corner, cooperating with fadeout,
  54871. // which is appropriate for user understanding.
  54872. // Divided by 2 for reRoot rolling up effect.
  54873. targetX = innerStore.nodeWidth / 2;
  54874. targetY = innerStore.nodeHeight / 2;
  54875. }
  54876. target = storageName === 'nodeGroup' ? {
  54877. x: targetX,
  54878. y: targetY,
  54879. style: {
  54880. opacity: 0
  54881. }
  54882. } : {
  54883. shape: {
  54884. x: targetX,
  54885. y: targetY,
  54886. width: 0,
  54887. height: 0
  54888. },
  54889. style: {
  54890. opacity: 0
  54891. }
  54892. };
  54893. }
  54894. // TODO: do not support delay until necessary.
  54895. target && animationWrap.add(el, target, duration, 0, easing);
  54896. });
  54897. });
  54898. // Make other animations
  54899. each(this._storage, function (store, storageName) {
  54900. each(store, function (el, rawIndex) {
  54901. var last = renderResult.lastsForAnimation[storageName][rawIndex];
  54902. var target = {};
  54903. if (!last) {
  54904. return;
  54905. }
  54906. if (el instanceof Group) {
  54907. if (last.oldX != null) {
  54908. target.x = el.x;
  54909. target.y = el.y;
  54910. el.x = last.oldX;
  54911. el.y = last.oldY;
  54912. }
  54913. } else {
  54914. if (last.oldShape) {
  54915. target.shape = extend({}, el.shape);
  54916. el.setShape(last.oldShape);
  54917. }
  54918. if (last.fadein) {
  54919. el.setStyle('opacity', 0);
  54920. target.style = {
  54921. opacity: 1
  54922. };
  54923. }
  54924. // When animation is stopped for succedent animation starting,
  54925. // el.style.opacity might not be 1
  54926. else if (el.style.opacity !== 1) {
  54927. target.style = {
  54928. opacity: 1
  54929. };
  54930. }
  54931. }
  54932. animationWrap.add(el, target, duration, 0, easing);
  54933. });
  54934. }, this);
  54935. this._state = 'animating';
  54936. animationWrap.finished(bind(function () {
  54937. this._state = 'ready';
  54938. renderResult.renderFinally();
  54939. }, this)).start();
  54940. };
  54941. TreemapView.prototype._resetController = function (api) {
  54942. var _this = this;
  54943. var controller = this._controller;
  54944. var controllerHost = this._controllerHost;
  54945. if (!controllerHost) {
  54946. this._controllerHost = {
  54947. target: this.group
  54948. };
  54949. controllerHost = this._controllerHost;
  54950. }
  54951. var seriesModel = this.seriesModel;
  54952. // Init controller.
  54953. if (!controller) {
  54954. controller = this._controller = new RoamController(api.getZr());
  54955. controller.on('pan', bind(this._onPan, this));
  54956. controller.on('zoom', bind(this._onZoom, this));
  54957. }
  54958. controller.enable(seriesModel.get('roam'), {
  54959. api: api,
  54960. zInfo: {
  54961. component: seriesModel
  54962. },
  54963. triggerInfo: {
  54964. roamTrigger: seriesModel.get('roamTrigger'),
  54965. isInSelf: function (e, x, y) {
  54966. var containerGroup = _this._containerGroup;
  54967. return containerGroup
  54968. // Currently only x, y exist in tranform.
  54969. ? containerGroup.getBoundingRect().contain(x - containerGroup.x, y - containerGroup.y) : false;
  54970. }
  54971. }
  54972. });
  54973. controllerHost.zoomLimit = seriesModel.get('scaleLimit');
  54974. controllerHost.zoom = seriesModel.get('zoom');
  54975. };
  54976. TreemapView.prototype._clearController = function () {
  54977. var controller = this._controller;
  54978. this._controllerHost = null;
  54979. if (controller) {
  54980. controller.dispose();
  54981. controller = null;
  54982. }
  54983. };
  54984. TreemapView.prototype._onPan = function (e) {
  54985. if (this._state !== 'animating' && (Math.abs(e.dx) > DRAG_THRESHOLD || Math.abs(e.dy) > DRAG_THRESHOLD)) {
  54986. // These param must not be cached.
  54987. var root = this.seriesModel.getData().tree.root;
  54988. if (!root) {
  54989. return;
  54990. }
  54991. var rootLayout = root.getLayout();
  54992. if (!rootLayout) {
  54993. return;
  54994. }
  54995. this.api.dispatchAction({
  54996. type: 'treemapMove',
  54997. from: this.uid,
  54998. seriesId: this.seriesModel.id,
  54999. rootRect: {
  55000. x: rootLayout.x + e.dx,
  55001. y: rootLayout.y + e.dy,
  55002. width: rootLayout.width,
  55003. height: rootLayout.height
  55004. }
  55005. });
  55006. }
  55007. };
  55008. TreemapView.prototype._onZoom = function (e) {
  55009. var mouseX = e.originX;
  55010. var mouseY = e.originY;
  55011. var zoomDelta = e.scale;
  55012. if (this._state !== 'animating') {
  55013. // These param must not be cached.
  55014. var root = this.seriesModel.getData().tree.root;
  55015. if (!root) {
  55016. return;
  55017. }
  55018. var rootLayout = root.getLayout();
  55019. if (!rootLayout) {
  55020. return;
  55021. }
  55022. var rect = new BoundingRect(rootLayout.x, rootLayout.y, rootLayout.width, rootLayout.height);
  55023. // scaleLimit
  55024. var zoomLimit = null;
  55025. var _controllerHost = this._controllerHost;
  55026. zoomLimit = _controllerHost.zoomLimit;
  55027. var newZoom = _controllerHost.zoom = _controllerHost.zoom || 1;
  55028. newZoom *= zoomDelta;
  55029. if (zoomLimit) {
  55030. var zoomMin = zoomLimit.min || 0;
  55031. var zoomMax = zoomLimit.max || Infinity;
  55032. newZoom = Math.max(Math.min(zoomMax, newZoom), zoomMin);
  55033. }
  55034. var zoomScale = newZoom / _controllerHost.zoom;
  55035. _controllerHost.zoom = newZoom;
  55036. var layoutInfo = this.seriesModel.layoutInfo;
  55037. // Transform mouse coord from global to containerGroup.
  55038. mouseX -= layoutInfo.x;
  55039. mouseY -= layoutInfo.y;
  55040. // Scale root bounding rect.
  55041. var m = create$1();
  55042. translate(m, m, [-mouseX, -mouseY]);
  55043. scale$1(m, m, [zoomScale, zoomScale]);
  55044. translate(m, m, [mouseX, mouseY]);
  55045. rect.applyTransform(m);
  55046. this.api.dispatchAction({
  55047. type: 'treemapRender',
  55048. from: this.uid,
  55049. seriesId: this.seriesModel.id,
  55050. rootRect: {
  55051. x: rect.x,
  55052. y: rect.y,
  55053. width: rect.width,
  55054. height: rect.height
  55055. }
  55056. });
  55057. }
  55058. };
  55059. TreemapView.prototype._initEvents = function (containerGroup) {
  55060. var _this = this;
  55061. containerGroup.on('click', function (e) {
  55062. if (_this._state !== 'ready') {
  55063. return;
  55064. }
  55065. var nodeClick = _this.seriesModel.get('nodeClick', true);
  55066. if (!nodeClick) {
  55067. return;
  55068. }
  55069. var targetInfo = _this.findTarget(e.offsetX, e.offsetY);
  55070. if (!targetInfo) {
  55071. return;
  55072. }
  55073. var node = targetInfo.node;
  55074. if (node.getLayout().isLeafRoot) {
  55075. _this._rootToNode(targetInfo);
  55076. } else {
  55077. if (nodeClick === 'zoomToNode') {
  55078. _this._zoomToNode(targetInfo);
  55079. } else if (nodeClick === 'link') {
  55080. var itemModel = node.hostTree.data.getItemModel(node.dataIndex);
  55081. var link = itemModel.get('link', true);
  55082. var linkTarget = itemModel.get('target', true) || 'blank';
  55083. link && windowOpen(link, linkTarget);
  55084. }
  55085. }
  55086. }, this);
  55087. };
  55088. TreemapView.prototype._renderBreadcrumb = function (seriesModel, api, targetInfo) {
  55089. var _this = this;
  55090. if (!targetInfo) {
  55091. targetInfo = seriesModel.get('leafDepth', true) != null ? {
  55092. node: seriesModel.getViewRoot()
  55093. }
  55094. // FIXME
  55095. // better way?
  55096. // Find breadcrumb tail on center of containerGroup.
  55097. : this.findTarget(api.getWidth() / 2, api.getHeight() / 2);
  55098. if (!targetInfo) {
  55099. targetInfo = {
  55100. node: seriesModel.getData().tree.root
  55101. };
  55102. }
  55103. }
  55104. (this._breadcrumb || (this._breadcrumb = new Breadcrumb(this.group))).render(seriesModel, api, targetInfo.node, function (node) {
  55105. if (_this._state !== 'animating') {
  55106. aboveViewRoot(seriesModel.getViewRoot(), node) ? _this._rootToNode({
  55107. node: node
  55108. }) : _this._zoomToNode({
  55109. node: node
  55110. });
  55111. }
  55112. });
  55113. };
  55114. /**
  55115. * @override
  55116. */
  55117. TreemapView.prototype.remove = function () {
  55118. this._clearController();
  55119. this._containerGroup && this._containerGroup.removeAll();
  55120. this._storage = createStorage();
  55121. this._state = 'ready';
  55122. this._breadcrumb && this._breadcrumb.remove();
  55123. };
  55124. TreemapView.prototype.dispose = function () {
  55125. this._clearController();
  55126. };
  55127. TreemapView.prototype._zoomToNode = function (targetInfo) {
  55128. this.api.dispatchAction({
  55129. type: 'treemapZoomToNode',
  55130. from: this.uid,
  55131. seriesId: this.seriesModel.id,
  55132. targetNode: targetInfo.node
  55133. });
  55134. };
  55135. TreemapView.prototype._rootToNode = function (targetInfo) {
  55136. this.api.dispatchAction({
  55137. type: 'treemapRootToNode',
  55138. from: this.uid,
  55139. seriesId: this.seriesModel.id,
  55140. targetNode: targetInfo.node
  55141. });
  55142. };
  55143. /**
  55144. * @param x Global coord x.
  55145. * @param y Global coord y.
  55146. * @return info If not found, return undefined;
  55147. * @return info.node Target node.
  55148. * @return info.offsetX x refer to target node.
  55149. * @return info.offsetY y refer to target node.
  55150. */
  55151. TreemapView.prototype.findTarget = function (x, y) {
  55152. var targetInfo;
  55153. var viewRoot = this.seriesModel.getViewRoot();
  55154. viewRoot.eachNode({
  55155. attr: 'viewChildren',
  55156. order: 'preorder'
  55157. }, function (node) {
  55158. var bgEl = this._storage.background[node.getRawIndex()];
  55159. // If invisible, there might be no element.
  55160. if (bgEl) {
  55161. var point = bgEl.transformCoordToLocal(x, y);
  55162. var shape = bgEl.shape;
  55163. // For performance consideration, don't use 'getBoundingRect'.
  55164. if (shape.x <= point[0] && point[0] <= shape.x + shape.width && shape.y <= point[1] && point[1] <= shape.y + shape.height) {
  55165. targetInfo = {
  55166. node: node,
  55167. offsetX: point[0],
  55168. offsetY: point[1]
  55169. };
  55170. } else {
  55171. return false; // Suppress visit subtree.
  55172. }
  55173. }
  55174. }, this);
  55175. return targetInfo;
  55176. };
  55177. TreemapView.type = 'treemap';
  55178. return TreemapView;
  55179. }(ChartView);
  55180. function createStorage() {
  55181. return {
  55182. nodeGroup: [],
  55183. background: [],
  55184. content: []
  55185. };
  55186. }
  55187. /**
  55188. * @return Return undefined means do not travel further.
  55189. */
  55190. function renderNode(seriesModel, thisStorage, oldStorage, reRoot, lastsForAnimation, willInvisibleEls, thisNode, oldNode, parentGroup, depth) {
  55191. // Whether under viewRoot.
  55192. if (!thisNode) {
  55193. // Deleting nodes will be performed finally. This method just find
  55194. // element from old storage, or create new element, set them to new
  55195. // storage, and set styles.
  55196. return;
  55197. }
  55198. // -------------------------------------------------------------------
  55199. // Start of closure variables available in "Procedures in renderNode".
  55200. var thisLayout = thisNode.getLayout();
  55201. var data = seriesModel.getData();
  55202. var nodeModel = thisNode.getModel();
  55203. // Only for enabling highlight/downplay. Clear firstly.
  55204. // Because some node will not be rendered.
  55205. data.setItemGraphicEl(thisNode.dataIndex, null);
  55206. if (!thisLayout || !thisLayout.isInView) {
  55207. return;
  55208. }
  55209. var thisWidth = thisLayout.width;
  55210. var thisHeight = thisLayout.height;
  55211. var borderWidth = thisLayout.borderWidth;
  55212. var thisInvisible = thisLayout.invisible;
  55213. var thisRawIndex = thisNode.getRawIndex();
  55214. var oldRawIndex = oldNode && oldNode.getRawIndex();
  55215. var thisViewChildren = thisNode.viewChildren;
  55216. var upperHeight = thisLayout.upperHeight;
  55217. var isParent = thisViewChildren && thisViewChildren.length;
  55218. var itemStyleNormalModel = nodeModel.getModel('itemStyle');
  55219. var itemStyleEmphasisModel = nodeModel.getModel(['emphasis', 'itemStyle']);
  55220. var itemStyleBlurModel = nodeModel.getModel(['blur', 'itemStyle']);
  55221. var itemStyleSelectModel = nodeModel.getModel(['select', 'itemStyle']);
  55222. var borderRadius = itemStyleNormalModel.get('borderRadius') || 0;
  55223. // End of closure ariables available in "Procedures in renderNode".
  55224. // -----------------------------------------------------------------
  55225. // Node group
  55226. var group = giveGraphic('nodeGroup', Group$1);
  55227. if (!group) {
  55228. return;
  55229. }
  55230. parentGroup.add(group);
  55231. // x,y are not set when el is above view root.
  55232. group.x = thisLayout.x || 0;
  55233. group.y = thisLayout.y || 0;
  55234. group.markRedraw();
  55235. inner$9(group).nodeWidth = thisWidth;
  55236. inner$9(group).nodeHeight = thisHeight;
  55237. if (thisLayout.isAboveViewRoot) {
  55238. return group;
  55239. }
  55240. // Background
  55241. var bg = giveGraphic('background', Rect$1, depth, Z2_BG);
  55242. bg && renderBackground(group, bg, isParent && thisLayout.upperLabelHeight);
  55243. var emphasisModel = nodeModel.getModel('emphasis');
  55244. var focus = emphasisModel.get('focus');
  55245. var blurScope = emphasisModel.get('blurScope');
  55246. var isDisabled = emphasisModel.get('disabled');
  55247. var focusOrIndices = focus === 'ancestor' ? thisNode.getAncestorsIndices() : focus === 'descendant' ? thisNode.getDescendantIndices() : focus;
  55248. // No children, render content.
  55249. if (isParent) {
  55250. // Because of the implementation about "traverse" in graphic hover style, we
  55251. // can not set hover listener on the "group" of non-leaf node. Otherwise the
  55252. // hover event from the descendents will be listenered.
  55253. if (isHighDownDispatcher(group)) {
  55254. setAsHighDownDispatcher(group, false);
  55255. }
  55256. if (bg) {
  55257. setAsHighDownDispatcher(bg, !isDisabled);
  55258. // Only for enabling highlight/downplay.
  55259. data.setItemGraphicEl(thisNode.dataIndex, bg);
  55260. enableHoverFocus(bg, focusOrIndices, blurScope);
  55261. }
  55262. } else {
  55263. var content = giveGraphic('content', Rect$1, depth, Z2_CONTENT);
  55264. content && renderContent(group, content);
  55265. bg.disableMorphing = true;
  55266. if (bg && isHighDownDispatcher(bg)) {
  55267. setAsHighDownDispatcher(bg, false);
  55268. }
  55269. setAsHighDownDispatcher(group, !isDisabled);
  55270. // Only for enabling highlight/downplay.
  55271. data.setItemGraphicEl(thisNode.dataIndex, group);
  55272. var cursorStyle = nodeModel.getShallow('cursor');
  55273. cursorStyle && content.attr('cursor', cursorStyle);
  55274. enableHoverFocus(group, focusOrIndices, blurScope);
  55275. }
  55276. return group;
  55277. // ----------------------------
  55278. // | Procedures in renderNode |
  55279. // ----------------------------
  55280. function renderBackground(group, bg, useUpperLabel) {
  55281. var ecData = getECData(bg);
  55282. // For tooltip.
  55283. ecData.dataIndex = thisNode.dataIndex;
  55284. ecData.seriesIndex = seriesModel.seriesIndex;
  55285. bg.setShape({
  55286. x: 0,
  55287. y: 0,
  55288. width: thisWidth,
  55289. height: thisHeight,
  55290. r: borderRadius
  55291. });
  55292. if (thisInvisible) {
  55293. // If invisible, do not set visual, otherwise the element will
  55294. // change immediately before animation. We think it is OK to
  55295. // remain its origin color when moving out of the view window.
  55296. processInvisible(bg);
  55297. } else {
  55298. bg.invisible = false;
  55299. var style = thisNode.getVisual('style');
  55300. var visualBorderColor = style.stroke;
  55301. var normalStyle = getItemStyleNormal(itemStyleNormalModel);
  55302. normalStyle.fill = visualBorderColor;
  55303. var emphasisStyle = getStateItemStyle(itemStyleEmphasisModel);
  55304. emphasisStyle.fill = itemStyleEmphasisModel.get('borderColor');
  55305. var blurStyle = getStateItemStyle(itemStyleBlurModel);
  55306. blurStyle.fill = itemStyleBlurModel.get('borderColor');
  55307. var selectStyle = getStateItemStyle(itemStyleSelectModel);
  55308. selectStyle.fill = itemStyleSelectModel.get('borderColor');
  55309. if (useUpperLabel) {
  55310. var upperLabelWidth = thisWidth - 2 * borderWidth;
  55311. prepareText(
  55312. // PENDING: convert ZRColor to ColorString for text.
  55313. bg, visualBorderColor, style.opacity, {
  55314. x: borderWidth,
  55315. y: 0,
  55316. width: upperLabelWidth,
  55317. height: upperHeight
  55318. });
  55319. }
  55320. // For old bg.
  55321. else {
  55322. bg.removeTextContent();
  55323. }
  55324. bg.setStyle(normalStyle);
  55325. bg.ensureState('emphasis').style = emphasisStyle;
  55326. bg.ensureState('blur').style = blurStyle;
  55327. bg.ensureState('select').style = selectStyle;
  55328. setDefaultStateProxy(bg);
  55329. }
  55330. group.add(bg);
  55331. }
  55332. function renderContent(group, content) {
  55333. var ecData = getECData(content);
  55334. // For tooltip.
  55335. ecData.dataIndex = thisNode.dataIndex;
  55336. ecData.seriesIndex = seriesModel.seriesIndex;
  55337. var contentWidth = Math.max(thisWidth - 2 * borderWidth, 0);
  55338. var contentHeight = Math.max(thisHeight - 2 * borderWidth, 0);
  55339. content.culling = true;
  55340. content.setShape({
  55341. x: borderWidth,
  55342. y: borderWidth,
  55343. width: contentWidth,
  55344. height: contentHeight,
  55345. r: borderRadius
  55346. });
  55347. if (thisInvisible) {
  55348. // If invisible, do not set visual, otherwise the element will
  55349. // change immediately before animation. We think it is OK to
  55350. // remain its origin color when moving out of the view window.
  55351. processInvisible(content);
  55352. } else {
  55353. content.invisible = false;
  55354. var nodeStyle = thisNode.getVisual('style');
  55355. var visualColor = nodeStyle.fill;
  55356. var normalStyle = getItemStyleNormal(itemStyleNormalModel);
  55357. normalStyle.fill = visualColor;
  55358. normalStyle.decal = nodeStyle.decal;
  55359. var emphasisStyle = getStateItemStyle(itemStyleEmphasisModel);
  55360. var blurStyle = getStateItemStyle(itemStyleBlurModel);
  55361. var selectStyle = getStateItemStyle(itemStyleSelectModel);
  55362. // PENDING: convert ZRColor to ColorString for text.
  55363. prepareText(content, visualColor, nodeStyle.opacity, null);
  55364. content.setStyle(normalStyle);
  55365. content.ensureState('emphasis').style = emphasisStyle;
  55366. content.ensureState('blur').style = blurStyle;
  55367. content.ensureState('select').style = selectStyle;
  55368. setDefaultStateProxy(content);
  55369. }
  55370. group.add(content);
  55371. }
  55372. function processInvisible(element) {
  55373. // Delay invisible setting utill animation finished,
  55374. // avoid element vanish suddenly before animation.
  55375. !element.invisible && willInvisibleEls.push(element);
  55376. }
  55377. function prepareText(rectEl, visualColor, visualOpacity,
  55378. // Can be null/undefined
  55379. upperLabelRect) {
  55380. var normalLabelModel = nodeModel.getModel(upperLabelRect ? PATH_UPPERLABEL_NORMAL : PATH_LABEL_NOAMAL);
  55381. var defaultText = convertOptionIdName(nodeModel.get('name'), null);
  55382. var isShow = normalLabelModel.getShallow('show');
  55383. setLabelStyle(rectEl, getLabelStatesModels(nodeModel, upperLabelRect ? PATH_UPPERLABEL_NORMAL : PATH_LABEL_NOAMAL), {
  55384. defaultText: isShow ? defaultText : null,
  55385. inheritColor: visualColor,
  55386. defaultOpacity: visualOpacity,
  55387. labelFetcher: seriesModel,
  55388. labelDataIndex: thisNode.dataIndex
  55389. });
  55390. var textEl = rectEl.getTextContent();
  55391. if (!textEl) {
  55392. return;
  55393. }
  55394. var textStyle = textEl.style;
  55395. var textPadding = normalizeCssArray(textStyle.padding || 0);
  55396. if (upperLabelRect) {
  55397. rectEl.setTextConfig({
  55398. layoutRect: upperLabelRect
  55399. });
  55400. textEl.disableLabelLayout = true;
  55401. }
  55402. textEl.beforeUpdate = function () {
  55403. var width = Math.max((upperLabelRect ? upperLabelRect.width : rectEl.shape.width) - textPadding[1] - textPadding[3], 0);
  55404. var height = Math.max((upperLabelRect ? upperLabelRect.height : rectEl.shape.height) - textPadding[0] - textPadding[2], 0);
  55405. if (textStyle.width !== width || textStyle.height !== height) {
  55406. textEl.setStyle({
  55407. width: width,
  55408. height: height
  55409. });
  55410. }
  55411. };
  55412. textStyle.truncateMinChar = 2;
  55413. textStyle.lineOverflow = 'truncate';
  55414. addDrillDownIcon(textStyle, upperLabelRect, thisLayout);
  55415. var textEmphasisState = textEl.getState('emphasis');
  55416. addDrillDownIcon(textEmphasisState ? textEmphasisState.style : null, upperLabelRect, thisLayout);
  55417. }
  55418. function addDrillDownIcon(style, upperLabelRect, thisLayout) {
  55419. var text = style ? style.text : null;
  55420. if (!upperLabelRect && thisLayout.isLeafRoot && text != null) {
  55421. var iconChar = seriesModel.get('drillDownIcon', true);
  55422. style.text = iconChar ? iconChar + ' ' + text : text;
  55423. }
  55424. }
  55425. function giveGraphic(storageName, Ctor, depth, z) {
  55426. var element = oldRawIndex != null && oldStorage[storageName][oldRawIndex];
  55427. var lasts = lastsForAnimation[storageName];
  55428. if (element) {
  55429. // Remove from oldStorage
  55430. oldStorage[storageName][oldRawIndex] = null;
  55431. prepareAnimationWhenHasOld(lasts, element);
  55432. }
  55433. // If invisible and no old element, do not create new element (for optimizing).
  55434. else if (!thisInvisible) {
  55435. element = new Ctor();
  55436. if (element instanceof Displayable) {
  55437. element.z2 = calculateZ2(depth, z);
  55438. }
  55439. prepareAnimationWhenNoOld(lasts, element);
  55440. }
  55441. // Set to thisStorage
  55442. return thisStorage[storageName][thisRawIndex] = element;
  55443. }
  55444. function prepareAnimationWhenHasOld(lasts, element) {
  55445. var lastCfg = lasts[thisRawIndex] = {};
  55446. if (element instanceof Group$1) {
  55447. lastCfg.oldX = element.x;
  55448. lastCfg.oldY = element.y;
  55449. } else {
  55450. lastCfg.oldShape = extend({}, element.shape);
  55451. }
  55452. }
  55453. // If a element is new, we need to find the animation start point carefully,
  55454. // otherwise it will looks strange when 'zoomToNode'.
  55455. function prepareAnimationWhenNoOld(lasts, element) {
  55456. var lastCfg = lasts[thisRawIndex] = {};
  55457. var parentNode = thisNode.parentNode;
  55458. var isGroup = element instanceof Group;
  55459. if (parentNode && (!reRoot || reRoot.direction === 'drillDown')) {
  55460. var parentOldX = 0;
  55461. var parentOldY = 0;
  55462. // New nodes appear from right-bottom corner in 'zoomToNode' animation.
  55463. // For convenience, get old bounding rect from background.
  55464. var parentOldBg = lastsForAnimation.background[parentNode.getRawIndex()];
  55465. if (!reRoot && parentOldBg && parentOldBg.oldShape) {
  55466. parentOldX = parentOldBg.oldShape.width;
  55467. parentOldY = parentOldBg.oldShape.height;
  55468. }
  55469. // When no parent old shape found, its parent is new too,
  55470. // so we can just use {x:0, y:0}.
  55471. if (isGroup) {
  55472. lastCfg.oldX = 0;
  55473. lastCfg.oldY = parentOldY;
  55474. } else {
  55475. lastCfg.oldShape = {
  55476. x: parentOldX,
  55477. y: parentOldY,
  55478. width: 0,
  55479. height: 0
  55480. };
  55481. }
  55482. }
  55483. // Fade in, user can be aware that these nodes are new.
  55484. lastCfg.fadein = !isGroup;
  55485. }
  55486. }
  55487. // We cannot set all background with the same z, because the behaviour of
  55488. // drill down and roll up differ background creation sequence from tree
  55489. // hierarchy sequence, which cause lower background elements to overlap
  55490. // upper ones. So we calculate z based on depth.
  55491. // Moreover, we try to shrink down z interval to [0, 1] to avoid that
  55492. // treemap with large z overlaps other components.
  55493. function calculateZ2(depth, z2InLevel) {
  55494. return depth * Z2_BASE + z2InLevel;
  55495. }
  55496. var each$3 = each;
  55497. var isObject$3 = isObject;
  55498. var CATEGORY_DEFAULT_VISUAL_INDEX = -1;
  55499. var VisualMapping = /** @class */function () {
  55500. function VisualMapping(option) {
  55501. var mappingMethod = option.mappingMethod;
  55502. var visualType = option.type;
  55503. var thisOption = this.option = clone(option);
  55504. this.type = visualType;
  55505. this.mappingMethod = mappingMethod;
  55506. this._normalizeData = normalizers[mappingMethod];
  55507. var visualHandler = VisualMapping.visualHandlers[visualType];
  55508. this.applyVisual = visualHandler.applyVisual;
  55509. this.getColorMapper = visualHandler.getColorMapper;
  55510. this._normalizedToVisual = visualHandler._normalizedToVisual[mappingMethod];
  55511. if (mappingMethod === 'piecewise') {
  55512. normalizeVisualRange(thisOption);
  55513. preprocessForPiecewise(thisOption);
  55514. } else if (mappingMethod === 'category') {
  55515. thisOption.categories ? preprocessForSpecifiedCategory(thisOption)
  55516. // categories is ordinal when thisOption.categories not specified,
  55517. // which need no more preprocess except normalize visual.
  55518. : normalizeVisualRange(thisOption, true);
  55519. } else {
  55520. // mappingMethod === 'linear' or 'fixed'
  55521. assert(mappingMethod !== 'linear' || thisOption.dataExtent);
  55522. normalizeVisualRange(thisOption);
  55523. }
  55524. }
  55525. VisualMapping.prototype.mapValueToVisual = function (value) {
  55526. var normalized = this._normalizeData(value);
  55527. return this._normalizedToVisual(normalized, value);
  55528. };
  55529. VisualMapping.prototype.getNormalizer = function () {
  55530. return bind(this._normalizeData, this);
  55531. };
  55532. /**
  55533. * List available visual types.
  55534. *
  55535. * @public
  55536. * @return {Array.<string>}
  55537. */
  55538. VisualMapping.listVisualTypes = function () {
  55539. return keys(VisualMapping.visualHandlers);
  55540. };
  55541. // /**
  55542. // * @public
  55543. // */
  55544. // static addVisualHandler(name, handler) {
  55545. // visualHandlers[name] = handler;
  55546. // }
  55547. /**
  55548. * @public
  55549. */
  55550. VisualMapping.isValidType = function (visualType) {
  55551. return VisualMapping.visualHandlers.hasOwnProperty(visualType);
  55552. };
  55553. /**
  55554. * Convenient method.
  55555. * Visual can be Object or Array or primary type.
  55556. */
  55557. VisualMapping.eachVisual = function (visual, callback, context) {
  55558. if (isObject(visual)) {
  55559. each(visual, callback, context);
  55560. } else {
  55561. callback.call(context, visual);
  55562. }
  55563. };
  55564. VisualMapping.mapVisual = function (visual, callback, context) {
  55565. var isPrimary;
  55566. var newVisual = isArray(visual) ? [] : isObject(visual) ? {} : (isPrimary = true, null);
  55567. VisualMapping.eachVisual(visual, function (v, key) {
  55568. var newVal = callback.call(context, v, key);
  55569. isPrimary ? newVisual = newVal : newVisual[key] = newVal;
  55570. });
  55571. return newVisual;
  55572. };
  55573. /**
  55574. * Retrieve visual properties from given object.
  55575. */
  55576. VisualMapping.retrieveVisuals = function (obj) {
  55577. var ret = {};
  55578. var hasVisual;
  55579. obj && each$3(VisualMapping.visualHandlers, function (h, visualType) {
  55580. if (obj.hasOwnProperty(visualType)) {
  55581. ret[visualType] = obj[visualType];
  55582. hasVisual = true;
  55583. }
  55584. });
  55585. return hasVisual ? ret : null;
  55586. };
  55587. /**
  55588. * Give order to visual types, considering colorSaturation, colorAlpha depends on color.
  55589. *
  55590. * @public
  55591. * @param {(Object|Array)} visualTypes If Object, like: {color: ..., colorSaturation: ...}
  55592. * IF Array, like: ['color', 'symbol', 'colorSaturation']
  55593. * @return {Array.<string>} Sorted visual types.
  55594. */
  55595. VisualMapping.prepareVisualTypes = function (visualTypes) {
  55596. if (isArray(visualTypes)) {
  55597. visualTypes = visualTypes.slice();
  55598. } else if (isObject$3(visualTypes)) {
  55599. var types_1 = [];
  55600. each$3(visualTypes, function (item, type) {
  55601. types_1.push(type);
  55602. });
  55603. visualTypes = types_1;
  55604. } else {
  55605. return [];
  55606. }
  55607. visualTypes.sort(function (type1, type2) {
  55608. // color should be front of colorSaturation, colorAlpha, ...
  55609. // symbol and symbolSize do not matter.
  55610. return type2 === 'color' && type1 !== 'color' && type1.indexOf('color') === 0 ? 1 : -1;
  55611. });
  55612. return visualTypes;
  55613. };
  55614. /**
  55615. * 'color', 'colorSaturation', 'colorAlpha', ... are depends on 'color'.
  55616. * Other visuals are only depends on themself.
  55617. */
  55618. VisualMapping.dependsOn = function (visualType1, visualType2) {
  55619. return visualType2 === 'color' ? !!(visualType1 && visualType1.indexOf(visualType2) === 0) : visualType1 === visualType2;
  55620. };
  55621. /**
  55622. * @param value
  55623. * @param pieceList [{value: ..., interval: [min, max]}, ...]
  55624. * Always from small to big.
  55625. * @param findClosestWhenOutside Default to be false
  55626. * @return index
  55627. */
  55628. VisualMapping.findPieceIndex = function (value, pieceList, findClosestWhenOutside) {
  55629. var possibleI;
  55630. var abs = Infinity;
  55631. // value has the higher priority.
  55632. for (var i = 0, len = pieceList.length; i < len; i++) {
  55633. var pieceValue = pieceList[i].value;
  55634. if (pieceValue != null) {
  55635. if (pieceValue === value
  55636. // FIXME
  55637. // It is supposed to compare value according to value type of dimension,
  55638. // but currently value type can exactly be string or number.
  55639. // Compromise for numeric-like string (like '12'), especially
  55640. // in the case that visualMap.categories is ['22', '33'].
  55641. || isString(pieceValue) && pieceValue === value + '') {
  55642. return i;
  55643. }
  55644. findClosestWhenOutside && updatePossible(pieceValue, i);
  55645. }
  55646. }
  55647. for (var i = 0, len = pieceList.length; i < len; i++) {
  55648. var piece = pieceList[i];
  55649. var interval = piece.interval;
  55650. var close_1 = piece.close;
  55651. if (interval) {
  55652. if (interval[0] === -Infinity) {
  55653. if (littleThan(close_1[1], value, interval[1])) {
  55654. return i;
  55655. }
  55656. } else if (interval[1] === Infinity) {
  55657. if (littleThan(close_1[0], interval[0], value)) {
  55658. return i;
  55659. }
  55660. } else if (littleThan(close_1[0], interval[0], value) && littleThan(close_1[1], value, interval[1])) {
  55661. return i;
  55662. }
  55663. findClosestWhenOutside && updatePossible(interval[0], i);
  55664. findClosestWhenOutside && updatePossible(interval[1], i);
  55665. }
  55666. }
  55667. if (findClosestWhenOutside) {
  55668. return value === Infinity ? pieceList.length - 1 : value === -Infinity ? 0 : possibleI;
  55669. }
  55670. function updatePossible(val, index) {
  55671. var newAbs = Math.abs(val - value);
  55672. if (newAbs < abs) {
  55673. abs = newAbs;
  55674. possibleI = index;
  55675. }
  55676. }
  55677. };
  55678. VisualMapping.visualHandlers = {
  55679. color: {
  55680. applyVisual: makeApplyVisual('color'),
  55681. getColorMapper: function () {
  55682. var thisOption = this.option;
  55683. return bind(thisOption.mappingMethod === 'category' ? function (value, isNormalized) {
  55684. !isNormalized && (value = this._normalizeData(value));
  55685. return doMapCategory.call(this, value);
  55686. } : function (value, isNormalized, out) {
  55687. // If output rgb array
  55688. // which will be much faster and useful in pixel manipulation
  55689. var returnRGBArray = !!out;
  55690. !isNormalized && (value = this._normalizeData(value));
  55691. out = fastLerp(value, thisOption.parsedVisual, out);
  55692. return returnRGBArray ? out : stringify(out, 'rgba');
  55693. }, this);
  55694. },
  55695. _normalizedToVisual: {
  55696. linear: function (normalized) {
  55697. return stringify(fastLerp(normalized, this.option.parsedVisual), 'rgba');
  55698. },
  55699. category: doMapCategory,
  55700. piecewise: function (normalized, value) {
  55701. var result = getSpecifiedVisual.call(this, value);
  55702. if (result == null) {
  55703. result = stringify(fastLerp(normalized, this.option.parsedVisual), 'rgba');
  55704. }
  55705. return result;
  55706. },
  55707. fixed: doMapFixed
  55708. }
  55709. },
  55710. colorHue: makePartialColorVisualHandler(function (color$1, value) {
  55711. return modifyHSL(color$1, value);
  55712. }),
  55713. colorSaturation: makePartialColorVisualHandler(function (color$1, value) {
  55714. return modifyHSL(color$1, null, value);
  55715. }),
  55716. colorLightness: makePartialColorVisualHandler(function (color$1, value) {
  55717. return modifyHSL(color$1, null, null, value);
  55718. }),
  55719. colorAlpha: makePartialColorVisualHandler(function (color$1, value) {
  55720. return modifyAlpha(color$1, value);
  55721. }),
  55722. decal: {
  55723. applyVisual: makeApplyVisual('decal'),
  55724. _normalizedToVisual: {
  55725. linear: null,
  55726. category: doMapCategory,
  55727. piecewise: null,
  55728. fixed: null
  55729. }
  55730. },
  55731. opacity: {
  55732. applyVisual: makeApplyVisual('opacity'),
  55733. _normalizedToVisual: createNormalizedToNumericVisual([0, 1])
  55734. },
  55735. liftZ: {
  55736. applyVisual: makeApplyVisual('liftZ'),
  55737. _normalizedToVisual: {
  55738. linear: doMapFixed,
  55739. category: doMapFixed,
  55740. piecewise: doMapFixed,
  55741. fixed: doMapFixed
  55742. }
  55743. },
  55744. symbol: {
  55745. applyVisual: function (value, getter, setter) {
  55746. var symbolCfg = this.mapValueToVisual(value);
  55747. setter('symbol', symbolCfg);
  55748. },
  55749. _normalizedToVisual: {
  55750. linear: doMapToArray,
  55751. category: doMapCategory,
  55752. piecewise: function (normalized, value) {
  55753. var result = getSpecifiedVisual.call(this, value);
  55754. if (result == null) {
  55755. result = doMapToArray.call(this, normalized);
  55756. }
  55757. return result;
  55758. },
  55759. fixed: doMapFixed
  55760. }
  55761. },
  55762. symbolSize: {
  55763. applyVisual: makeApplyVisual('symbolSize'),
  55764. _normalizedToVisual: createNormalizedToNumericVisual([0, 1])
  55765. }
  55766. };
  55767. return VisualMapping;
  55768. }();
  55769. function preprocessForPiecewise(thisOption) {
  55770. var pieceList = thisOption.pieceList;
  55771. thisOption.hasSpecialVisual = false;
  55772. each(pieceList, function (piece, index) {
  55773. piece.originIndex = index;
  55774. // piece.visual is "result visual value" but not
  55775. // a visual range, so it does not need to be normalized.
  55776. if (piece.visual != null) {
  55777. thisOption.hasSpecialVisual = true;
  55778. }
  55779. });
  55780. }
  55781. function preprocessForSpecifiedCategory(thisOption) {
  55782. // Hash categories.
  55783. var categories = thisOption.categories;
  55784. var categoryMap = thisOption.categoryMap = {};
  55785. var visual = thisOption.visual;
  55786. each$3(categories, function (cate, index) {
  55787. categoryMap[cate] = index;
  55788. });
  55789. // Process visual map input.
  55790. if (!isArray(visual)) {
  55791. var visualArr_1 = [];
  55792. if (isObject(visual)) {
  55793. each$3(visual, function (v, cate) {
  55794. var index = categoryMap[cate];
  55795. visualArr_1[index != null ? index : CATEGORY_DEFAULT_VISUAL_INDEX] = v;
  55796. });
  55797. } else {
  55798. // Is primary type, represents default visual.
  55799. visualArr_1[CATEGORY_DEFAULT_VISUAL_INDEX] = visual;
  55800. }
  55801. visual = setVisualToOption(thisOption, visualArr_1);
  55802. }
  55803. // Remove categories that has no visual,
  55804. // then we can mapping them to CATEGORY_DEFAULT_VISUAL_INDEX.
  55805. for (var i = categories.length - 1; i >= 0; i--) {
  55806. if (visual[i] == null) {
  55807. delete categoryMap[categories[i]];
  55808. categories.pop();
  55809. }
  55810. }
  55811. }
  55812. function normalizeVisualRange(thisOption, isCategory) {
  55813. var visual = thisOption.visual;
  55814. var visualArr = [];
  55815. if (isObject(visual)) {
  55816. each$3(visual, function (v) {
  55817. visualArr.push(v);
  55818. });
  55819. } else if (visual != null) {
  55820. visualArr.push(visual);
  55821. }
  55822. var doNotNeedPair = {
  55823. color: 1,
  55824. symbol: 1
  55825. };
  55826. if (!isCategory && visualArr.length === 1 && !doNotNeedPair.hasOwnProperty(thisOption.type)) {
  55827. // Do not care visualArr.length === 0, which is illegal.
  55828. visualArr[1] = visualArr[0];
  55829. }
  55830. setVisualToOption(thisOption, visualArr);
  55831. }
  55832. function makePartialColorVisualHandler(applyValue) {
  55833. return {
  55834. applyVisual: function (value, getter, setter) {
  55835. // Only used in HSL
  55836. var colorChannel = this.mapValueToVisual(value);
  55837. // Must not be array value
  55838. setter('color', applyValue(getter('color'), colorChannel));
  55839. },
  55840. _normalizedToVisual: createNormalizedToNumericVisual([0, 1])
  55841. };
  55842. }
  55843. function doMapToArray(normalized) {
  55844. var visual = this.option.visual;
  55845. return visual[Math.round(linearMap(normalized, [0, 1], [0, visual.length - 1], true))] || {}; // TODO {}?
  55846. }
  55847. function makeApplyVisual(visualType) {
  55848. return function (value, getter, setter) {
  55849. setter(visualType, this.mapValueToVisual(value));
  55850. };
  55851. }
  55852. function doMapCategory(normalized) {
  55853. var visual = this.option.visual;
  55854. return visual[this.option.loop && normalized !== CATEGORY_DEFAULT_VISUAL_INDEX ? normalized % visual.length : normalized];
  55855. }
  55856. function doMapFixed() {
  55857. // visual will be convert to array.
  55858. return this.option.visual[0];
  55859. }
  55860. /**
  55861. * Create mapped to numeric visual
  55862. */
  55863. function createNormalizedToNumericVisual(sourceExtent) {
  55864. return {
  55865. linear: function (normalized) {
  55866. return linearMap(normalized, sourceExtent, this.option.visual, true);
  55867. },
  55868. category: doMapCategory,
  55869. piecewise: function (normalized, value) {
  55870. var result = getSpecifiedVisual.call(this, value);
  55871. if (result == null) {
  55872. result = linearMap(normalized, sourceExtent, this.option.visual, true);
  55873. }
  55874. return result;
  55875. },
  55876. fixed: doMapFixed
  55877. };
  55878. }
  55879. function getSpecifiedVisual(value) {
  55880. var thisOption = this.option;
  55881. var pieceList = thisOption.pieceList;
  55882. if (thisOption.hasSpecialVisual) {
  55883. var pieceIndex = VisualMapping.findPieceIndex(value, pieceList);
  55884. var piece = pieceList[pieceIndex];
  55885. if (piece && piece.visual) {
  55886. return piece.visual[this.type];
  55887. }
  55888. }
  55889. }
  55890. function setVisualToOption(thisOption, visualArr) {
  55891. thisOption.visual = visualArr;
  55892. if (thisOption.type === 'color') {
  55893. thisOption.parsedVisual = map(visualArr, function (item) {
  55894. var color$1 = parse(item);
  55895. if (!color$1 && "development" !== 'production') {
  55896. warn("'" + item + "' is an illegal color, fallback to '#000000'", true);
  55897. }
  55898. return color$1 || [0, 0, 0, 1];
  55899. });
  55900. }
  55901. return visualArr;
  55902. }
  55903. /**
  55904. * Normalizers by mapping methods.
  55905. */
  55906. var normalizers = {
  55907. linear: function (value) {
  55908. return linearMap(value, this.option.dataExtent, [0, 1], true);
  55909. },
  55910. piecewise: function (value) {
  55911. var pieceList = this.option.pieceList;
  55912. var pieceIndex = VisualMapping.findPieceIndex(value, pieceList, true);
  55913. if (pieceIndex != null) {
  55914. return linearMap(pieceIndex, [0, pieceList.length - 1], [0, 1], true);
  55915. }
  55916. },
  55917. category: function (value) {
  55918. var index = this.option.categories ? this.option.categoryMap[value] : value; // ordinal value
  55919. return index == null ? CATEGORY_DEFAULT_VISUAL_INDEX : index;
  55920. },
  55921. fixed: noop
  55922. };
  55923. function littleThan(close, a, b) {
  55924. return close ? a <= b : a < b;
  55925. }
  55926. var ITEM_STYLE_NORMAL = 'itemStyle';
  55927. var inner$a = makeInner();
  55928. var treemapVisual = {
  55929. seriesType: 'treemap',
  55930. reset: function (seriesModel) {
  55931. var tree = seriesModel.getData().tree;
  55932. var root = tree.root;
  55933. if (root.isRemoved()) {
  55934. return;
  55935. }
  55936. travelTree(root,
  55937. // Visual should calculate from tree root but not view root.
  55938. {}, seriesModel.getViewRoot().getAncestors(), seriesModel);
  55939. }
  55940. };
  55941. function travelTree(node, designatedVisual, viewRootAncestors, seriesModel) {
  55942. var nodeModel = node.getModel();
  55943. var nodeLayout = node.getLayout();
  55944. var data = node.hostTree.data;
  55945. // Optimize
  55946. if (!nodeLayout || nodeLayout.invisible || !nodeLayout.isInView) {
  55947. return;
  55948. }
  55949. var nodeItemStyleModel = nodeModel.getModel(ITEM_STYLE_NORMAL);
  55950. var visuals = buildVisuals(nodeItemStyleModel, designatedVisual, seriesModel);
  55951. var existsStyle = data.ensureUniqueItemVisual(node.dataIndex, 'style');
  55952. // calculate border color
  55953. var borderColor = nodeItemStyleModel.get('borderColor');
  55954. var borderColorSaturation = nodeItemStyleModel.get('borderColorSaturation');
  55955. var thisNodeColor;
  55956. if (borderColorSaturation != null) {
  55957. // For performance, do not always execute 'calculateColor'.
  55958. thisNodeColor = calculateColor(visuals);
  55959. borderColor = calculateBorderColor(borderColorSaturation, thisNodeColor);
  55960. }
  55961. existsStyle.stroke = borderColor;
  55962. var viewChildren = node.viewChildren;
  55963. if (!viewChildren || !viewChildren.length) {
  55964. thisNodeColor = calculateColor(visuals);
  55965. // Apply visual to this node.
  55966. existsStyle.fill = thisNodeColor;
  55967. } else {
  55968. var mapping_1 = buildVisualMapping(node, nodeModel, nodeLayout, nodeItemStyleModel, visuals, viewChildren);
  55969. // Designate visual to children.
  55970. each(viewChildren, function (child, index) {
  55971. // If higher than viewRoot, only ancestors of viewRoot is needed to visit.
  55972. if (child.depth >= viewRootAncestors.length || child === viewRootAncestors[child.depth]) {
  55973. var childVisual = mapVisual(nodeModel, visuals, child, index, mapping_1, seriesModel);
  55974. travelTree(child, childVisual, viewRootAncestors, seriesModel);
  55975. }
  55976. });
  55977. }
  55978. }
  55979. function buildVisuals(nodeItemStyleModel, designatedVisual, seriesModel) {
  55980. var visuals = extend({}, designatedVisual);
  55981. var designatedVisualItemStyle = seriesModel.designatedVisualItemStyle;
  55982. each(['color', 'colorAlpha', 'colorSaturation'], function (visualName) {
  55983. // Priority: thisNode > thisLevel > parentNodeDesignated > seriesModel
  55984. designatedVisualItemStyle[visualName] = designatedVisual[visualName];
  55985. var val = nodeItemStyleModel.get(visualName);
  55986. designatedVisualItemStyle[visualName] = null;
  55987. val != null && (visuals[visualName] = val);
  55988. });
  55989. return visuals;
  55990. }
  55991. function calculateColor(visuals) {
  55992. var color = getValueVisualDefine(visuals, 'color');
  55993. if (color) {
  55994. var colorAlpha = getValueVisualDefine(visuals, 'colorAlpha');
  55995. var colorSaturation = getValueVisualDefine(visuals, 'colorSaturation');
  55996. if (colorSaturation) {
  55997. color = modifyHSL(color, null, null, colorSaturation);
  55998. }
  55999. if (colorAlpha) {
  56000. color = modifyAlpha(color, colorAlpha);
  56001. }
  56002. return color;
  56003. }
  56004. }
  56005. function calculateBorderColor(borderColorSaturation, thisNodeColor) {
  56006. return thisNodeColor != null
  56007. // Can only be string
  56008. ? modifyHSL(thisNodeColor, null, null, borderColorSaturation) : null;
  56009. }
  56010. function getValueVisualDefine(visuals, name) {
  56011. var value = visuals[name];
  56012. if (value != null && value !== 'none') {
  56013. return value;
  56014. }
  56015. }
  56016. function buildVisualMapping(node, nodeModel, nodeLayout, nodeItemStyleModel, visuals, viewChildren) {
  56017. if (!viewChildren || !viewChildren.length) {
  56018. return;
  56019. }
  56020. var rangeVisual = getRangeVisual(nodeModel, 'color') || visuals.color != null && visuals.color !== 'none' && (getRangeVisual(nodeModel, 'colorAlpha') || getRangeVisual(nodeModel, 'colorSaturation'));
  56021. if (!rangeVisual) {
  56022. return;
  56023. }
  56024. var visualMin = nodeModel.get('visualMin');
  56025. var visualMax = nodeModel.get('visualMax');
  56026. var dataExtent = nodeLayout.dataExtent.slice();
  56027. visualMin != null && visualMin < dataExtent[0] && (dataExtent[0] = visualMin);
  56028. visualMax != null && visualMax > dataExtent[1] && (dataExtent[1] = visualMax);
  56029. var colorMappingBy = nodeModel.get('colorMappingBy');
  56030. var opt = {
  56031. type: rangeVisual.name,
  56032. dataExtent: dataExtent,
  56033. visual: rangeVisual.range
  56034. };
  56035. if (opt.type === 'color' && (colorMappingBy === 'index' || colorMappingBy === 'id')) {
  56036. opt.mappingMethod = 'category';
  56037. opt.loop = true;
  56038. // categories is ordinal, so do not set opt.categories.
  56039. } else {
  56040. opt.mappingMethod = 'linear';
  56041. }
  56042. var mapping = new VisualMapping(opt);
  56043. inner$a(mapping).drColorMappingBy = colorMappingBy;
  56044. return mapping;
  56045. }
  56046. // Notice: If we don't have the attribute 'colorRange', but only use
  56047. // attribute 'color' to represent both concepts of 'colorRange' and 'color',
  56048. // (It means 'colorRange' when 'color' is Array, means 'color' when not array),
  56049. // this problem will be encountered:
  56050. // If a level-1 node doesn't have children, and its siblings have children,
  56051. // and colorRange is set on level-1, then the node cannot be colored.
  56052. // So we separate 'colorRange' and 'color' to different attributes.
  56053. function getRangeVisual(nodeModel, name) {
  56054. // 'colorRange', 'colorARange', 'colorSRange'.
  56055. // If not exists on this node, fetch from levels and series.
  56056. var range = nodeModel.get(name);
  56057. return isArray(range) && range.length ? {
  56058. name: name,
  56059. range: range
  56060. } : null;
  56061. }
  56062. function mapVisual(nodeModel, visuals, child, index, mapping, seriesModel) {
  56063. var childVisuals = extend({}, visuals);
  56064. if (mapping) {
  56065. // Only support color, colorAlpha, colorSaturation.
  56066. var mappingType = mapping.type;
  56067. var colorMappingBy = mappingType === 'color' && inner$a(mapping).drColorMappingBy;
  56068. var value = colorMappingBy === 'index' ? index : colorMappingBy === 'id' ? seriesModel.mapIdToIndex(child.getId()) : child.getValue(nodeModel.get('visualDimension'));
  56069. childVisuals[mappingType] = mapping.mapValueToVisual(value);
  56070. }
  56071. return childVisuals;
  56072. }
  56073. var mathMax$8 = Math.max;
  56074. var mathMin$8 = Math.min;
  56075. var retrieveValue = retrieve;
  56076. var each$4 = each;
  56077. var PATH_BORDER_WIDTH = ['itemStyle', 'borderWidth'];
  56078. var PATH_GAP_WIDTH = ['itemStyle', 'gapWidth'];
  56079. var PATH_UPPER_LABEL_SHOW = ['upperLabel', 'show'];
  56080. var PATH_UPPER_LABEL_HEIGHT = ['upperLabel', 'height'];
  56081. /**
  56082. * @public
  56083. */
  56084. var treemapLayout = {
  56085. seriesType: 'treemap',
  56086. reset: function (seriesModel, ecModel, api, payload) {
  56087. // Layout result in each node:
  56088. // {x, y, width, height, area, borderWidth}
  56089. var seriesOption = seriesModel.option;
  56090. var refContainer = createBoxLayoutReference(seriesModel, api).refContainer;
  56091. var layoutInfo = getLayoutRect(seriesModel.getBoxLayoutParams(), refContainer);
  56092. var size = seriesOption.size || []; // Compatible with ec2.
  56093. var containerWidth = parsePercent$1(retrieveValue(layoutInfo.width, size[0]), refContainer.width);
  56094. var containerHeight = parsePercent$1(retrieveValue(layoutInfo.height, size[1]), refContainer.height);
  56095. // Fetch payload info.
  56096. var payloadType = payload && payload.type;
  56097. var types = ['treemapZoomToNode', 'treemapRootToNode'];
  56098. var targetInfo = retrieveTargetInfo(payload, types, seriesModel);
  56099. var rootRect = payloadType === 'treemapRender' || payloadType === 'treemapMove' ? payload.rootRect : null;
  56100. var viewRoot = seriesModel.getViewRoot();
  56101. var viewAbovePath = getPathToRoot(viewRoot);
  56102. if (payloadType !== 'treemapMove') {
  56103. var rootSize = payloadType === 'treemapZoomToNode' ? estimateRootSize(seriesModel, targetInfo, viewRoot, containerWidth, containerHeight) : rootRect ? [rootRect.width, rootRect.height] : [containerWidth, containerHeight];
  56104. var sort_1 = seriesOption.sort;
  56105. if (sort_1 && sort_1 !== 'asc' && sort_1 !== 'desc') {
  56106. // Default to be desc order.
  56107. sort_1 = 'desc';
  56108. }
  56109. var options = {
  56110. squareRatio: seriesOption.squareRatio,
  56111. sort: sort_1,
  56112. leafDepth: seriesOption.leafDepth
  56113. };
  56114. // layout should be cleared because using updateView but not update.
  56115. viewRoot.hostTree.clearLayouts();
  56116. // TODO
  56117. // optimize: if out of view clip, do not layout.
  56118. // But take care that if do not render node out of view clip,
  56119. // how to calculate start po
  56120. var viewRootLayout_1 = {
  56121. x: 0,
  56122. y: 0,
  56123. width: rootSize[0],
  56124. height: rootSize[1],
  56125. area: rootSize[0] * rootSize[1]
  56126. };
  56127. viewRoot.setLayout(viewRootLayout_1);
  56128. squarify(viewRoot, options, false, 0);
  56129. // Supplement layout.
  56130. viewRootLayout_1 = viewRoot.getLayout();
  56131. each$4(viewAbovePath, function (node, index) {
  56132. var childValue = (viewAbovePath[index + 1] || viewRoot).getValue();
  56133. node.setLayout(extend({
  56134. dataExtent: [childValue, childValue],
  56135. borderWidth: 0,
  56136. upperHeight: 0
  56137. }, viewRootLayout_1));
  56138. });
  56139. }
  56140. var treeRoot = seriesModel.getData().tree.root;
  56141. treeRoot.setLayout(calculateRootPosition(layoutInfo, rootRect, targetInfo), true);
  56142. seriesModel.setLayoutInfo(layoutInfo);
  56143. // FIXME: narrow down pruning boungding rect.
  56144. // Currently ec width/height is used becuases clip is not supported.
  56145. prunning(treeRoot,
  56146. // Transform to base element coordinate system.
  56147. new BoundingRect(-layoutInfo.x, -layoutInfo.y, api.getWidth(), api.getHeight()), viewAbovePath, viewRoot, 0);
  56148. }
  56149. };
  56150. /**
  56151. * Layout treemap with squarify algorithm.
  56152. * The original presentation of this algorithm
  56153. * was made by Mark Bruls, Kees Huizing, and Jarke J. van Wijk
  56154. * <https://graphics.ethz.ch/teaching/scivis_common/Literature/squarifiedTreeMaps.pdf>.
  56155. * The implementation of this algorithm was originally copied from "d3.js"
  56156. * <https://github.com/d3/d3/blob/9cc9a875e636a1dcf36cc1e07bdf77e1ad6e2c74/src/layout/treemap.js>
  56157. * with some modifications made for this program.
  56158. * See the license statement at the head of this file.
  56159. *
  56160. * @protected
  56161. * @param {module:echarts/data/Tree~TreeNode} node
  56162. * @param {Object} options
  56163. * @param {string} options.sort 'asc' or 'desc'
  56164. * @param {number} options.squareRatio
  56165. * @param {boolean} hideChildren
  56166. * @param {number} depth
  56167. */
  56168. function squarify(node, options, hideChildren, depth) {
  56169. var width;
  56170. var height;
  56171. if (node.isRemoved()) {
  56172. return;
  56173. }
  56174. var thisLayout = node.getLayout();
  56175. width = thisLayout.width;
  56176. height = thisLayout.height;
  56177. // Considering border and gap
  56178. var nodeModel = node.getModel();
  56179. var borderWidth = nodeModel.get(PATH_BORDER_WIDTH);
  56180. var halfGapWidth = nodeModel.get(PATH_GAP_WIDTH) / 2;
  56181. var upperLabelHeight = getUpperLabelHeight(nodeModel);
  56182. var upperHeight = Math.max(borderWidth, upperLabelHeight);
  56183. var layoutOffset = borderWidth - halfGapWidth;
  56184. var layoutOffsetUpper = upperHeight - halfGapWidth;
  56185. node.setLayout({
  56186. borderWidth: borderWidth,
  56187. upperHeight: upperHeight,
  56188. upperLabelHeight: upperLabelHeight
  56189. }, true);
  56190. width = mathMax$8(width - 2 * layoutOffset, 0);
  56191. height = mathMax$8(height - layoutOffset - layoutOffsetUpper, 0);
  56192. var totalArea = width * height;
  56193. var viewChildren = initChildren(node, nodeModel, totalArea, options, hideChildren, depth);
  56194. if (!viewChildren.length) {
  56195. return;
  56196. }
  56197. var rect = {
  56198. x: layoutOffset,
  56199. y: layoutOffsetUpper,
  56200. width: width,
  56201. height: height
  56202. };
  56203. var rowFixedLength = mathMin$8(width, height);
  56204. var best = Infinity; // the best row score so far
  56205. var row = [];
  56206. row.area = 0;
  56207. for (var i = 0, len = viewChildren.length; i < len;) {
  56208. var child = viewChildren[i];
  56209. row.push(child);
  56210. row.area += child.getLayout().area;
  56211. var score = worst(row, rowFixedLength, options.squareRatio);
  56212. // continue with this orientation
  56213. if (score <= best) {
  56214. i++;
  56215. best = score;
  56216. }
  56217. // abort, and try a different orientation
  56218. else {
  56219. row.area -= row.pop().getLayout().area;
  56220. position(row, rowFixedLength, rect, halfGapWidth, false);
  56221. rowFixedLength = mathMin$8(rect.width, rect.height);
  56222. row.length = row.area = 0;
  56223. best = Infinity;
  56224. }
  56225. }
  56226. if (row.length) {
  56227. position(row, rowFixedLength, rect, halfGapWidth, true);
  56228. }
  56229. if (!hideChildren) {
  56230. var childrenVisibleMin = nodeModel.get('childrenVisibleMin');
  56231. if (childrenVisibleMin != null && totalArea < childrenVisibleMin) {
  56232. hideChildren = true;
  56233. }
  56234. }
  56235. for (var i = 0, len = viewChildren.length; i < len; i++) {
  56236. squarify(viewChildren[i], options, hideChildren, depth + 1);
  56237. }
  56238. }
  56239. /**
  56240. * Set area to each child, and calculate data extent for visual coding.
  56241. */
  56242. function initChildren(node, nodeModel, totalArea, options, hideChildren, depth) {
  56243. var viewChildren = node.children || [];
  56244. var orderBy = options.sort;
  56245. orderBy !== 'asc' && orderBy !== 'desc' && (orderBy = null);
  56246. var overLeafDepth = options.leafDepth != null && options.leafDepth <= depth;
  56247. // leafDepth has higher priority.
  56248. if (hideChildren && !overLeafDepth) {
  56249. return node.viewChildren = [];
  56250. }
  56251. // Sort children, order by desc.
  56252. viewChildren = filter(viewChildren, function (child) {
  56253. return !child.isRemoved();
  56254. });
  56255. sort$1(viewChildren, orderBy);
  56256. var info = statistic(nodeModel, viewChildren, orderBy);
  56257. if (info.sum === 0) {
  56258. return node.viewChildren = [];
  56259. }
  56260. info.sum = filterByThreshold(nodeModel, totalArea, info.sum, orderBy, viewChildren);
  56261. if (info.sum === 0) {
  56262. return node.viewChildren = [];
  56263. }
  56264. // Set area to each child.
  56265. for (var i = 0, len = viewChildren.length; i < len; i++) {
  56266. var area = viewChildren[i].getValue() / info.sum * totalArea;
  56267. // Do not use setLayout({...}, true), because it is needed to clear last layout.
  56268. viewChildren[i].setLayout({
  56269. area: area
  56270. });
  56271. }
  56272. if (overLeafDepth) {
  56273. viewChildren.length && node.setLayout({
  56274. isLeafRoot: true
  56275. }, true);
  56276. viewChildren.length = 0;
  56277. }
  56278. node.viewChildren = viewChildren;
  56279. node.setLayout({
  56280. dataExtent: info.dataExtent
  56281. }, true);
  56282. return viewChildren;
  56283. }
  56284. /**
  56285. * Consider 'visibleMin'. Modify viewChildren and get new sum.
  56286. */
  56287. function filterByThreshold(nodeModel, totalArea, sum, orderBy, orderedChildren) {
  56288. // visibleMin is not supported yet when no option.sort.
  56289. if (!orderBy) {
  56290. return sum;
  56291. }
  56292. var visibleMin = nodeModel.get('visibleMin');
  56293. var len = orderedChildren.length;
  56294. var deletePoint = len;
  56295. // Always travel from little value to big value.
  56296. for (var i = len - 1; i >= 0; i--) {
  56297. var value = orderedChildren[orderBy === 'asc' ? len - i - 1 : i].getValue();
  56298. if (value / sum * totalArea < visibleMin) {
  56299. deletePoint = i;
  56300. sum -= value;
  56301. }
  56302. }
  56303. orderBy === 'asc' ? orderedChildren.splice(0, len - deletePoint) : orderedChildren.splice(deletePoint, len - deletePoint);
  56304. return sum;
  56305. }
  56306. /**
  56307. * Sort
  56308. */
  56309. function sort$1(viewChildren, orderBy) {
  56310. if (orderBy) {
  56311. viewChildren.sort(function (a, b) {
  56312. var diff = orderBy === 'asc' ? a.getValue() - b.getValue() : b.getValue() - a.getValue();
  56313. return diff === 0 ? orderBy === 'asc' ? a.dataIndex - b.dataIndex : b.dataIndex - a.dataIndex : diff;
  56314. });
  56315. }
  56316. return viewChildren;
  56317. }
  56318. /**
  56319. * Statistic
  56320. */
  56321. function statistic(nodeModel, children, orderBy) {
  56322. // Calculate sum.
  56323. var sum = 0;
  56324. for (var i = 0, len = children.length; i < len; i++) {
  56325. sum += children[i].getValue();
  56326. }
  56327. // Statistic data extent for latter visual coding.
  56328. // Notice: data extent should be calculate based on raw children
  56329. // but not filtered view children, otherwise visual mapping will not
  56330. // be stable when zoom (where children is filtered by visibleMin).
  56331. var dimension = nodeModel.get('visualDimension');
  56332. var dataExtent;
  56333. // The same as area dimension.
  56334. if (!children || !children.length) {
  56335. dataExtent = [NaN, NaN];
  56336. } else if (dimension === 'value' && orderBy) {
  56337. dataExtent = [children[children.length - 1].getValue(), children[0].getValue()];
  56338. orderBy === 'asc' && dataExtent.reverse();
  56339. }
  56340. // Other dimension.
  56341. else {
  56342. dataExtent = [Infinity, -Infinity];
  56343. each$4(children, function (child) {
  56344. var value = child.getValue(dimension);
  56345. value < dataExtent[0] && (dataExtent[0] = value);
  56346. value > dataExtent[1] && (dataExtent[1] = value);
  56347. });
  56348. }
  56349. return {
  56350. sum: sum,
  56351. dataExtent: dataExtent
  56352. };
  56353. }
  56354. /**
  56355. * Computes the score for the specified row,
  56356. * as the worst aspect ratio.
  56357. */
  56358. function worst(row, rowFixedLength, ratio) {
  56359. var areaMax = 0;
  56360. var areaMin = Infinity;
  56361. for (var i = 0, area = void 0, len = row.length; i < len; i++) {
  56362. area = row[i].getLayout().area;
  56363. if (area) {
  56364. area < areaMin && (areaMin = area);
  56365. area > areaMax && (areaMax = area);
  56366. }
  56367. }
  56368. var squareArea = row.area * row.area;
  56369. var f = rowFixedLength * rowFixedLength * ratio;
  56370. return squareArea ? mathMax$8(f * areaMax / squareArea, squareArea / (f * areaMin)) : Infinity;
  56371. }
  56372. /**
  56373. * Positions the specified row of nodes. Modifies `rect`.
  56374. */
  56375. function position(row, rowFixedLength, rect, halfGapWidth, flush) {
  56376. // When rowFixedLength === rect.width,
  56377. // it is horizontal subdivision,
  56378. // rowFixedLength is the width of the subdivision,
  56379. // rowOtherLength is the height of the subdivision,
  56380. // and nodes will be positioned from left to right.
  56381. // wh[idx0WhenH] means: when horizontal,
  56382. // wh[idx0WhenH] => wh[0] => 'width'.
  56383. // xy[idx1WhenH] => xy[1] => 'y'.
  56384. var idx0WhenH = rowFixedLength === rect.width ? 0 : 1;
  56385. var idx1WhenH = 1 - idx0WhenH;
  56386. var xy = ['x', 'y'];
  56387. var wh = ['width', 'height'];
  56388. var last = rect[xy[idx0WhenH]];
  56389. var rowOtherLength = rowFixedLength ? row.area / rowFixedLength : 0;
  56390. if (flush || rowOtherLength > rect[wh[idx1WhenH]]) {
  56391. rowOtherLength = rect[wh[idx1WhenH]]; // over+underflow
  56392. }
  56393. for (var i = 0, rowLen = row.length; i < rowLen; i++) {
  56394. var node = row[i];
  56395. var nodeLayout = {};
  56396. var step = rowOtherLength ? node.getLayout().area / rowOtherLength : 0;
  56397. var wh1 = nodeLayout[wh[idx1WhenH]] = mathMax$8(rowOtherLength - 2 * halfGapWidth, 0);
  56398. // We use Math.max/min to avoid negative width/height when considering gap width.
  56399. var remain = rect[xy[idx0WhenH]] + rect[wh[idx0WhenH]] - last;
  56400. var modWH = i === rowLen - 1 || remain < step ? remain : step;
  56401. var wh0 = nodeLayout[wh[idx0WhenH]] = mathMax$8(modWH - 2 * halfGapWidth, 0);
  56402. nodeLayout[xy[idx1WhenH]] = rect[xy[idx1WhenH]] + mathMin$8(halfGapWidth, wh1 / 2);
  56403. nodeLayout[xy[idx0WhenH]] = last + mathMin$8(halfGapWidth, wh0 / 2);
  56404. last += modWH;
  56405. node.setLayout(nodeLayout, true);
  56406. }
  56407. rect[xy[idx1WhenH]] += rowOtherLength;
  56408. rect[wh[idx1WhenH]] -= rowOtherLength;
  56409. }
  56410. // Return [containerWidth, containerHeight] as default.
  56411. function estimateRootSize(seriesModel, targetInfo, viewRoot, containerWidth, containerHeight) {
  56412. // If targetInfo.node exists, we zoom to the node,
  56413. // so estimate whole width and height by target node.
  56414. var currNode = (targetInfo || {}).node;
  56415. var defaultSize = [containerWidth, containerHeight];
  56416. if (!currNode || currNode === viewRoot) {
  56417. return defaultSize;
  56418. }
  56419. var parent;
  56420. var viewArea = containerWidth * containerHeight;
  56421. var area = viewArea * seriesModel.option.zoomToNodeRatio;
  56422. while (parent = currNode.parentNode) {
  56423. // jshint ignore:line
  56424. var sum = 0;
  56425. var siblings = parent.children;
  56426. for (var i = 0, len = siblings.length; i < len; i++) {
  56427. sum += siblings[i].getValue();
  56428. }
  56429. var currNodeValue = currNode.getValue();
  56430. if (currNodeValue === 0) {
  56431. return defaultSize;
  56432. }
  56433. area *= sum / currNodeValue;
  56434. // Considering border, suppose aspect ratio is 1.
  56435. var parentModel = parent.getModel();
  56436. var borderWidth = parentModel.get(PATH_BORDER_WIDTH);
  56437. var upperHeight = Math.max(borderWidth, getUpperLabelHeight(parentModel));
  56438. area += 4 * borderWidth * borderWidth + (3 * borderWidth + upperHeight) * Math.pow(area, 0.5);
  56439. area > MAX_SAFE_INTEGER && (area = MAX_SAFE_INTEGER);
  56440. currNode = parent;
  56441. }
  56442. area < viewArea && (area = viewArea);
  56443. var scale = Math.pow(area / viewArea, 0.5);
  56444. return [containerWidth * scale, containerHeight * scale];
  56445. }
  56446. // Root position based on coord of containerGroup
  56447. function calculateRootPosition(layoutInfo, rootRect, targetInfo) {
  56448. if (rootRect) {
  56449. return {
  56450. x: rootRect.x,
  56451. y: rootRect.y
  56452. };
  56453. }
  56454. var defaultPosition = {
  56455. x: 0,
  56456. y: 0
  56457. };
  56458. if (!targetInfo) {
  56459. return defaultPosition;
  56460. }
  56461. // If targetInfo is fetched by 'retrieveTargetInfo',
  56462. // old tree and new tree are the same tree,
  56463. // so the node still exists and we can visit it.
  56464. var targetNode = targetInfo.node;
  56465. var layout = targetNode.getLayout();
  56466. if (!layout) {
  56467. return defaultPosition;
  56468. }
  56469. // Transform coord from local to container.
  56470. var targetCenter = [layout.width / 2, layout.height / 2];
  56471. var node = targetNode;
  56472. while (node) {
  56473. var nodeLayout = node.getLayout();
  56474. targetCenter[0] += nodeLayout.x;
  56475. targetCenter[1] += nodeLayout.y;
  56476. node = node.parentNode;
  56477. }
  56478. return {
  56479. x: layoutInfo.width / 2 - targetCenter[0],
  56480. y: layoutInfo.height / 2 - targetCenter[1]
  56481. };
  56482. }
  56483. // Mark nodes visible for prunning when visual coding and rendering.
  56484. // Prunning depends on layout and root position, so we have to do it after layout.
  56485. function prunning(node, clipRect, viewAbovePath, viewRoot, depth) {
  56486. var nodeLayout = node.getLayout();
  56487. var nodeInViewAbovePath = viewAbovePath[depth];
  56488. var isAboveViewRoot = nodeInViewAbovePath && nodeInViewAbovePath === node;
  56489. if (nodeInViewAbovePath && !isAboveViewRoot || depth === viewAbovePath.length && node !== viewRoot) {
  56490. return;
  56491. }
  56492. node.setLayout({
  56493. // isInView means: viewRoot sub tree + viewAbovePath
  56494. isInView: true,
  56495. // invisible only means: outside view clip so that the node can not
  56496. // see but still layout for animation preparation but not render.
  56497. invisible: !isAboveViewRoot && !clipRect.intersect(nodeLayout),
  56498. isAboveViewRoot: isAboveViewRoot
  56499. }, true);
  56500. // Transform to child coordinate.
  56501. var childClipRect = new BoundingRect(clipRect.x - nodeLayout.x, clipRect.y - nodeLayout.y, clipRect.width, clipRect.height);
  56502. each$4(node.viewChildren || [], function (child) {
  56503. prunning(child, childClipRect, viewAbovePath, viewRoot, depth + 1);
  56504. });
  56505. }
  56506. function getUpperLabelHeight(model) {
  56507. return model.get(PATH_UPPER_LABEL_SHOW) ? model.get(PATH_UPPER_LABEL_HEIGHT) : 0;
  56508. }
  56509. function install$c(registers) {
  56510. registers.registerSeriesModel(TreemapSeriesModel);
  56511. registers.registerChartView(TreemapView);
  56512. registers.registerVisual(treemapVisual);
  56513. registers.registerLayout(treemapLayout);
  56514. installTreemapAction(registers);
  56515. }
  56516. function categoryFilter(ecModel) {
  56517. var legendModels = ecModel.findComponents({
  56518. mainType: 'legend'
  56519. });
  56520. if (!legendModels || !legendModels.length) {
  56521. return;
  56522. }
  56523. ecModel.eachSeriesByType('graph', function (graphSeries) {
  56524. var categoriesData = graphSeries.getCategoriesData();
  56525. var graph = graphSeries.getGraph();
  56526. var data = graph.data;
  56527. var categoryNames = categoriesData.mapArray(categoriesData.getName);
  56528. data.filterSelf(function (idx) {
  56529. var model = data.getItemModel(idx);
  56530. var category = model.getShallow('category');
  56531. if (category != null) {
  56532. if (isNumber(category)) {
  56533. category = categoryNames[category];
  56534. }
  56535. // If in any legend component the status is not selected.
  56536. for (var i = 0; i < legendModels.length; i++) {
  56537. if (!legendModels[i].isSelected(category)) {
  56538. return false;
  56539. }
  56540. }
  56541. }
  56542. return true;
  56543. });
  56544. });
  56545. }
  56546. function categoryVisual(ecModel) {
  56547. var paletteScope = {};
  56548. ecModel.eachSeriesByType('graph', function (seriesModel) {
  56549. var categoriesData = seriesModel.getCategoriesData();
  56550. var data = seriesModel.getData();
  56551. var categoryNameIdxMap = {};
  56552. categoriesData.each(function (idx) {
  56553. var name = categoriesData.getName(idx);
  56554. // Add prefix to avoid conflict with Object.prototype.
  56555. categoryNameIdxMap['ec-' + name] = idx;
  56556. var itemModel = categoriesData.getItemModel(idx);
  56557. var style = itemModel.getModel('itemStyle').getItemStyle();
  56558. if (!style.fill) {
  56559. // Get color from palette.
  56560. style.fill = seriesModel.getColorFromPalette(name, paletteScope);
  56561. }
  56562. categoriesData.setItemVisual(idx, 'style', style);
  56563. var symbolVisualList = ['symbol', 'symbolSize', 'symbolKeepAspect'];
  56564. for (var i = 0; i < symbolVisualList.length; i++) {
  56565. var symbolVisual = itemModel.getShallow(symbolVisualList[i], true);
  56566. if (symbolVisual != null) {
  56567. categoriesData.setItemVisual(idx, symbolVisualList[i], symbolVisual);
  56568. }
  56569. }
  56570. });
  56571. // Assign category color to visual
  56572. if (categoriesData.count()) {
  56573. data.each(function (idx) {
  56574. var model = data.getItemModel(idx);
  56575. var categoryIdx = model.getShallow('category');
  56576. if (categoryIdx != null) {
  56577. if (isString(categoryIdx)) {
  56578. categoryIdx = categoryNameIdxMap['ec-' + categoryIdx];
  56579. }
  56580. var categoryStyle = categoriesData.getItemVisual(categoryIdx, 'style');
  56581. var style = data.ensureUniqueItemVisual(idx, 'style');
  56582. extend(style, categoryStyle);
  56583. var visualList = ['symbol', 'symbolSize', 'symbolKeepAspect'];
  56584. for (var i = 0; i < visualList.length; i++) {
  56585. data.setItemVisual(idx, visualList[i], categoriesData.getItemVisual(categoryIdx, visualList[i]));
  56586. }
  56587. }
  56588. });
  56589. }
  56590. });
  56591. }
  56592. function normalize$2(a) {
  56593. if (!(a instanceof Array)) {
  56594. a = [a, a];
  56595. }
  56596. return a;
  56597. }
  56598. function graphEdgeVisual(ecModel) {
  56599. ecModel.eachSeriesByType('graph', function (seriesModel) {
  56600. var graph = seriesModel.getGraph();
  56601. var edgeData = seriesModel.getEdgeData();
  56602. var symbolType = normalize$2(seriesModel.get('edgeSymbol'));
  56603. var symbolSize = normalize$2(seriesModel.get('edgeSymbolSize'));
  56604. // const colorQuery = ['lineStyle', 'color'] as const;
  56605. // const opacityQuery = ['lineStyle', 'opacity'] as const;
  56606. edgeData.setVisual('fromSymbol', symbolType && symbolType[0]);
  56607. edgeData.setVisual('toSymbol', symbolType && symbolType[1]);
  56608. edgeData.setVisual('fromSymbolSize', symbolSize && symbolSize[0]);
  56609. edgeData.setVisual('toSymbolSize', symbolSize && symbolSize[1]);
  56610. edgeData.setVisual('style', seriesModel.getModel('lineStyle').getLineStyle());
  56611. edgeData.each(function (idx) {
  56612. var itemModel = edgeData.getItemModel(idx);
  56613. var edge = graph.getEdgeByIndex(idx);
  56614. var symbolType = normalize$2(itemModel.getShallow('symbol', true));
  56615. var symbolSize = normalize$2(itemModel.getShallow('symbolSize', true));
  56616. // Edge visual must after node visual
  56617. var style = itemModel.getModel('lineStyle').getLineStyle();
  56618. var existsStyle = edgeData.ensureUniqueItemVisual(idx, 'style');
  56619. extend(existsStyle, style);
  56620. switch (existsStyle.stroke) {
  56621. case 'source':
  56622. {
  56623. var nodeStyle = edge.node1.getVisual('style');
  56624. existsStyle.stroke = nodeStyle && nodeStyle.fill;
  56625. break;
  56626. }
  56627. case 'target':
  56628. {
  56629. var nodeStyle = edge.node2.getVisual('style');
  56630. existsStyle.stroke = nodeStyle && nodeStyle.fill;
  56631. break;
  56632. }
  56633. }
  56634. symbolType[0] && edge.setVisual('fromSymbol', symbolType[0]);
  56635. symbolType[1] && edge.setVisual('toSymbol', symbolType[1]);
  56636. symbolSize[0] && edge.setVisual('fromSymbolSize', symbolSize[0]);
  56637. symbolSize[1] && edge.setVisual('toSymbolSize', symbolSize[1]);
  56638. });
  56639. });
  56640. }
  56641. var KEY_DELIMITER = '-->';
  56642. /**
  56643. * params handler
  56644. * @param {module:echarts/model/SeriesModel} seriesModel
  56645. * @returns {*}
  56646. */
  56647. var getAutoCurvenessParams = function (seriesModel) {
  56648. return seriesModel.get('autoCurveness') || null;
  56649. };
  56650. /**
  56651. * Generate a list of edge curvatures, 20 is the default
  56652. * @param {module:echarts/model/SeriesModel} seriesModel
  56653. * @param {number} appendLength
  56654. * @return 20 => [0, -0.2, 0.2, -0.4, 0.4, -0.6, 0.6, -0.8, 0.8, -1, 1, -1.2, 1.2, -1.4, 1.4, -1.6, 1.6, -1.8, 1.8, -2]
  56655. */
  56656. var createCurveness = function (seriesModel, appendLength) {
  56657. var autoCurvenessParmas = getAutoCurvenessParams(seriesModel);
  56658. var length = 20;
  56659. var curvenessList = [];
  56660. // handler the function set
  56661. if (isNumber(autoCurvenessParmas)) {
  56662. length = autoCurvenessParmas;
  56663. } else if (isArray(autoCurvenessParmas)) {
  56664. seriesModel.__curvenessList = autoCurvenessParmas;
  56665. return;
  56666. }
  56667. // append length
  56668. if (appendLength > length) {
  56669. length = appendLength;
  56670. }
  56671. // make sure the length is even
  56672. var len = length % 2 ? length + 2 : length + 3;
  56673. curvenessList = [];
  56674. for (var i = 0; i < len; i++) {
  56675. curvenessList.push((i % 2 ? i + 1 : i) / 10 * (i % 2 ? -1 : 1));
  56676. }
  56677. seriesModel.__curvenessList = curvenessList;
  56678. };
  56679. /**
  56680. * Create different cache key data in the positive and negative directions, in order to set the curvature later
  56681. * @param {number|string|module:echarts/data/Graph.Node} n1
  56682. * @param {number|string|module:echarts/data/Graph.Node} n2
  56683. * @param {module:echarts/model/SeriesModel} seriesModel
  56684. * @returns {string} key
  56685. */
  56686. var getKeyOfEdges = function (n1, n2, seriesModel) {
  56687. var source = [n1.id, n1.dataIndex].join('.');
  56688. var target = [n2.id, n2.dataIndex].join('.');
  56689. return [seriesModel.uid, source, target].join(KEY_DELIMITER);
  56690. };
  56691. /**
  56692. * get opposite key
  56693. * @param {string} key
  56694. * @returns {string}
  56695. */
  56696. var getOppositeKey = function (key) {
  56697. var keys = key.split(KEY_DELIMITER);
  56698. return [keys[0], keys[2], keys[1]].join(KEY_DELIMITER);
  56699. };
  56700. /**
  56701. * get edgeMap with key
  56702. * @param edge
  56703. * @param {module:echarts/model/SeriesModel} seriesModel
  56704. */
  56705. var getEdgeFromMap = function (edge, seriesModel) {
  56706. var key = getKeyOfEdges(edge.node1, edge.node2, seriesModel);
  56707. return seriesModel.__edgeMap[key];
  56708. };
  56709. /**
  56710. * calculate all cases total length
  56711. * @param edge
  56712. * @param seriesModel
  56713. * @returns {number}
  56714. */
  56715. var getTotalLengthBetweenNodes = function (edge, seriesModel) {
  56716. var len = getEdgeMapLengthWithKey(getKeyOfEdges(edge.node1, edge.node2, seriesModel), seriesModel);
  56717. var lenV = getEdgeMapLengthWithKey(getKeyOfEdges(edge.node2, edge.node1, seriesModel), seriesModel);
  56718. return len + lenV;
  56719. };
  56720. /**
  56721. *
  56722. * @param key
  56723. */
  56724. var getEdgeMapLengthWithKey = function (key, seriesModel) {
  56725. var edgeMap = seriesModel.__edgeMap;
  56726. return edgeMap[key] ? edgeMap[key].length : 0;
  56727. };
  56728. /**
  56729. * Count the number of edges between the same two points, used to obtain the curvature table and the parity of the edge
  56730. * @see /graph/GraphSeries.js@getInitialData
  56731. * @param {module:echarts/model/SeriesModel} seriesModel
  56732. */
  56733. function initCurvenessList(seriesModel) {
  56734. if (!getAutoCurvenessParams(seriesModel)) {
  56735. return;
  56736. }
  56737. seriesModel.__curvenessList = [];
  56738. seriesModel.__edgeMap = {};
  56739. // calc the array of curveness List
  56740. createCurveness(seriesModel);
  56741. }
  56742. /**
  56743. * set edgeMap with key
  56744. * @param {number|string|module:echarts/data/Graph.Node} n1
  56745. * @param {number|string|module:echarts/data/Graph.Node} n2
  56746. * @param {module:echarts/model/SeriesModel} seriesModel
  56747. * @param {number} index
  56748. */
  56749. function createEdgeMapForCurveness(n1, n2, seriesModel, index) {
  56750. if (!getAutoCurvenessParams(seriesModel)) {
  56751. return;
  56752. }
  56753. var key = getKeyOfEdges(n1, n2, seriesModel);
  56754. var edgeMap = seriesModel.__edgeMap;
  56755. var oppositeEdges = edgeMap[getOppositeKey(key)];
  56756. // set direction
  56757. if (edgeMap[key] && !oppositeEdges) {
  56758. edgeMap[key].isForward = true;
  56759. } else if (oppositeEdges && edgeMap[key]) {
  56760. oppositeEdges.isForward = true;
  56761. edgeMap[key].isForward = false;
  56762. }
  56763. edgeMap[key] = edgeMap[key] || [];
  56764. edgeMap[key].push(index);
  56765. }
  56766. /**
  56767. * get curvature for edge
  56768. * @param edge
  56769. * @param {module:echarts/model/SeriesModel} seriesModel
  56770. * @param index
  56771. */
  56772. function getCurvenessForEdge(edge, seriesModel, index, needReverse) {
  56773. var autoCurvenessParams = getAutoCurvenessParams(seriesModel);
  56774. var isArrayParam = isArray(autoCurvenessParams);
  56775. if (!autoCurvenessParams) {
  56776. return null;
  56777. }
  56778. var edgeArray = getEdgeFromMap(edge, seriesModel);
  56779. if (!edgeArray) {
  56780. return null;
  56781. }
  56782. var edgeIndex = -1;
  56783. for (var i = 0; i < edgeArray.length; i++) {
  56784. if (edgeArray[i] === index) {
  56785. edgeIndex = i;
  56786. break;
  56787. }
  56788. }
  56789. // if totalLen is Longer createCurveness
  56790. var totalLen = getTotalLengthBetweenNodes(edge, seriesModel);
  56791. createCurveness(seriesModel, totalLen);
  56792. edge.lineStyle = edge.lineStyle || {};
  56793. // if is opposite edge, must set curvenss to opposite number
  56794. var curKey = getKeyOfEdges(edge.node1, edge.node2, seriesModel);
  56795. var curvenessList = seriesModel.__curvenessList;
  56796. // if pass array no need parity
  56797. var parityCorrection = isArrayParam ? 0 : totalLen % 2 ? 0 : 1;
  56798. if (!edgeArray.isForward) {
  56799. // the opposite edge show outside
  56800. var oppositeKey = getOppositeKey(curKey);
  56801. var len = getEdgeMapLengthWithKey(oppositeKey, seriesModel);
  56802. var resValue = curvenessList[edgeIndex + len + parityCorrection];
  56803. // isNeedReverse, simple, force type need reverse the curveness in the junction of the forword and the opposite
  56804. if (needReverse) {
  56805. // set as array may make the parity handle with the len of opposite
  56806. if (isArrayParam) {
  56807. if (autoCurvenessParams && autoCurvenessParams[0] === 0) {
  56808. return (len + parityCorrection) % 2 ? resValue : -resValue;
  56809. } else {
  56810. return ((len % 2 ? 0 : 1) + parityCorrection) % 2 ? resValue : -resValue;
  56811. }
  56812. } else {
  56813. return (len + parityCorrection) % 2 ? resValue : -resValue;
  56814. }
  56815. } else {
  56816. return curvenessList[edgeIndex + len + parityCorrection];
  56817. }
  56818. } else {
  56819. return curvenessList[parityCorrection + edgeIndex];
  56820. }
  56821. }
  56822. function simpleLayout(seriesModel) {
  56823. var coordSys = seriesModel.coordinateSystem;
  56824. if (coordSys && coordSys.type !== 'view') {
  56825. return;
  56826. }
  56827. var graph = seriesModel.getGraph();
  56828. graph.eachNode(function (node) {
  56829. var model = node.getModel();
  56830. node.setLayout([+model.get('x'), +model.get('y')]);
  56831. });
  56832. simpleLayoutEdge(graph, seriesModel);
  56833. }
  56834. function simpleLayoutEdge(graph, seriesModel) {
  56835. graph.eachEdge(function (edge, index) {
  56836. var curveness = retrieve3(edge.getModel().get(['lineStyle', 'curveness']), -getCurvenessForEdge(edge, seriesModel, index, true), 0);
  56837. var p1 = clone$1(edge.node1.getLayout());
  56838. var p2 = clone$1(edge.node2.getLayout());
  56839. var points = [p1, p2];
  56840. if (+curveness) {
  56841. points.push([(p1[0] + p2[0]) / 2 - (p1[1] - p2[1]) * curveness, (p1[1] + p2[1]) / 2 - (p2[0] - p1[0]) * curveness]);
  56842. }
  56843. edge.setLayout(points);
  56844. });
  56845. }
  56846. function graphSimpleLayout(ecModel, api) {
  56847. ecModel.eachSeriesByType('graph', function (seriesModel) {
  56848. var layout = seriesModel.get('layout');
  56849. var coordSys = seriesModel.coordinateSystem;
  56850. if (coordSys && coordSys.type !== 'view') {
  56851. var data_1 = seriesModel.getData();
  56852. var dimensions_1 = [];
  56853. each(coordSys.dimensions, function (coordDim) {
  56854. dimensions_1 = dimensions_1.concat(data_1.mapDimensionsAll(coordDim));
  56855. });
  56856. for (var dataIndex = 0; dataIndex < data_1.count(); dataIndex++) {
  56857. var value = [];
  56858. var hasValue = false;
  56859. for (var i = 0; i < dimensions_1.length; i++) {
  56860. var val = data_1.get(dimensions_1[i], dataIndex);
  56861. if (!isNaN(val)) {
  56862. hasValue = true;
  56863. }
  56864. value.push(val);
  56865. }
  56866. if (hasValue) {
  56867. data_1.setItemLayout(dataIndex, coordSys.dataToPoint(value));
  56868. } else {
  56869. // Also {Array.<number>}, not undefined to avoid if...else... statement
  56870. data_1.setItemLayout(dataIndex, [NaN, NaN]);
  56871. }
  56872. }
  56873. simpleLayoutEdge(data_1.graph, seriesModel);
  56874. } else if (!layout || layout === 'none') {
  56875. simpleLayout(seriesModel);
  56876. }
  56877. });
  56878. }
  56879. /*
  56880. * Licensed to the Apache Software Foundation (ASF) under one
  56881. * or more contributor license agreements. See the NOTICE file
  56882. * distributed with this work for additional information
  56883. * regarding copyright ownership. The ASF licenses this file
  56884. * to you under the Apache License, Version 2.0 (the
  56885. * "License"); you may not use this file except in compliance
  56886. * with the License. You may obtain a copy of the License at
  56887. *
  56888. * http://www.apache.org/licenses/LICENSE-2.0
  56889. *
  56890. * Unless required by applicable law or agreed to in writing,
  56891. * software distributed under the License is distributed on an
  56892. * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
  56893. * KIND, either express or implied. See the License for the
  56894. * specific language governing permissions and limitations
  56895. * under the License.
  56896. */
  56897. /**
  56898. * AUTO-GENERATED FILE. DO NOT MODIFY.
  56899. */
  56900. /*
  56901. * Licensed to the Apache Software Foundation (ASF) under one
  56902. * or more contributor license agreements. See the NOTICE file
  56903. * distributed with this work for additional information
  56904. * regarding copyright ownership. The ASF licenses this file
  56905. * to you under the Apache License, Version 2.0 (the
  56906. * "License"); you may not use this file except in compliance
  56907. * with the License. You may obtain a copy of the License at
  56908. *
  56909. * http://www.apache.org/licenses/LICENSE-2.0
  56910. *
  56911. * Unless required by applicable law or agreed to in writing,
  56912. * software distributed under the License is distributed on an
  56913. * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
  56914. * KIND, either express or implied. See the License for the
  56915. * specific language governing permissions and limitations
  56916. * under the License.
  56917. */
  56918. function getNodeGlobalScale(seriesModel) {
  56919. var coordSys = seriesModel.coordinateSystem;
  56920. if (coordSys.type !== 'view') {
  56921. return 1;
  56922. }
  56923. var nodeScaleRatio = seriesModel.option.nodeScaleRatio;
  56924. var groupZoom = coordSys.scaleX;
  56925. // Scale node when zoom changes
  56926. var roamZoom = coordSys.getZoom();
  56927. var nodeScale = (roamZoom - 1) * nodeScaleRatio + 1;
  56928. return nodeScale / groupZoom;
  56929. }
  56930. function getSymbolSize(node) {
  56931. var symbolSize = node.getVisual('symbolSize');
  56932. if (symbolSize instanceof Array) {
  56933. symbolSize = (symbolSize[0] + symbolSize[1]) / 2;
  56934. }
  56935. return +symbolSize;
  56936. }
  56937. var PI$6 = Math.PI;
  56938. var _symbolRadiansHalf = [];
  56939. /**
  56940. * `basedOn` can be:
  56941. * 'value':
  56942. * This layout is not accurate and have same bad case. For example,
  56943. * if the min value is very smaller than the max value, the nodes
  56944. * with the min value probably overlap even though there is enough
  56945. * space to layout them. So we only use this approach in the as the
  56946. * init layout of the force layout.
  56947. * FIXME
  56948. * Probably we do not need this method any more but use
  56949. * `basedOn: 'symbolSize'` in force layout if
  56950. * delay its init operations to GraphView.
  56951. * 'symbolSize':
  56952. * This approach work only if all of the symbol size calculated.
  56953. * That is, the progressive rendering is not applied to graph.
  56954. * FIXME
  56955. * If progressive rendering is applied to graph some day,
  56956. * probably we have to use `basedOn: 'value'`.
  56957. */
  56958. function circularLayout(seriesModel, basedOn, draggingNode, pointer) {
  56959. var coordSys = seriesModel.coordinateSystem;
  56960. if (coordSys && coordSys.type !== 'view') {
  56961. return;
  56962. }
  56963. var rect = coordSys.getBoundingRect();
  56964. var nodeData = seriesModel.getData();
  56965. var graph = nodeData.graph;
  56966. var cx = rect.width / 2 + rect.x;
  56967. var cy = rect.height / 2 + rect.y;
  56968. var r = Math.min(rect.width, rect.height) / 2;
  56969. var count = nodeData.count();
  56970. nodeData.setLayout({
  56971. cx: cx,
  56972. cy: cy
  56973. });
  56974. if (!count) {
  56975. return;
  56976. }
  56977. if (draggingNode) {
  56978. var _a = coordSys.pointToData(pointer),
  56979. tempX = _a[0],
  56980. tempY = _a[1];
  56981. var v = [tempX - cx, tempY - cy];
  56982. normalize(v, v);
  56983. scale(v, v, r);
  56984. draggingNode.setLayout([cx + v[0], cy + v[1]], true);
  56985. var circularRotateLabel = seriesModel.get(['circular', 'rotateLabel']);
  56986. rotateNodeLabel(draggingNode, circularRotateLabel, cx, cy);
  56987. }
  56988. _layoutNodesBasedOn[basedOn](seriesModel, graph, nodeData, r, cx, cy, count);
  56989. graph.eachEdge(function (edge, index) {
  56990. var curveness = retrieve3(edge.getModel().get(['lineStyle', 'curveness']), getCurvenessForEdge(edge, seriesModel, index), 0);
  56991. var p1 = clone$1(edge.node1.getLayout());
  56992. var p2 = clone$1(edge.node2.getLayout());
  56993. var cp1;
  56994. var x12 = (p1[0] + p2[0]) / 2;
  56995. var y12 = (p1[1] + p2[1]) / 2;
  56996. if (+curveness) {
  56997. curveness *= 3;
  56998. cp1 = [cx * curveness + x12 * (1 - curveness), cy * curveness + y12 * (1 - curveness)];
  56999. }
  57000. edge.setLayout([p1, p2, cp1]);
  57001. });
  57002. }
  57003. var _layoutNodesBasedOn = {
  57004. value: function (seriesModel, graph, nodeData, r, cx, cy, count) {
  57005. var angle = 0;
  57006. var sum = nodeData.getSum('value');
  57007. var unitAngle = Math.PI * 2 / (sum || count);
  57008. graph.eachNode(function (node) {
  57009. var value = node.getValue('value');
  57010. var radianHalf = unitAngle * (sum ? value : 1) / 2;
  57011. angle += radianHalf;
  57012. node.setLayout([r * Math.cos(angle) + cx, r * Math.sin(angle) + cy]);
  57013. angle += radianHalf;
  57014. });
  57015. },
  57016. symbolSize: function (seriesModel, graph, nodeData, r, cx, cy, count) {
  57017. var sumRadian = 0;
  57018. _symbolRadiansHalf.length = count;
  57019. var nodeScale = getNodeGlobalScale(seriesModel);
  57020. graph.eachNode(function (node) {
  57021. var symbolSize = getSymbolSize(node);
  57022. // Normally this case will not happen, but we still add
  57023. // some the defensive code (2px is an arbitrary value).
  57024. isNaN(symbolSize) && (symbolSize = 2);
  57025. symbolSize < 0 && (symbolSize = 0);
  57026. symbolSize *= nodeScale;
  57027. var symbolRadianHalf = Math.asin(symbolSize / 2 / r);
  57028. // when `symbolSize / 2` is bigger than `r`.
  57029. isNaN(symbolRadianHalf) && (symbolRadianHalf = PI$6 / 2);
  57030. _symbolRadiansHalf[node.dataIndex] = symbolRadianHalf;
  57031. sumRadian += symbolRadianHalf * 2;
  57032. });
  57033. var halfRemainRadian = (2 * PI$6 - sumRadian) / count / 2;
  57034. var angle = 0;
  57035. graph.eachNode(function (node) {
  57036. var radianHalf = halfRemainRadian + _symbolRadiansHalf[node.dataIndex];
  57037. angle += radianHalf;
  57038. // init circular layout for
  57039. // 1. layout undefined node
  57040. // 2. not fixed node
  57041. (!node.getLayout() || !node.getLayout().fixed) && node.setLayout([r * Math.cos(angle) + cx, r * Math.sin(angle) + cy]);
  57042. angle += radianHalf;
  57043. });
  57044. }
  57045. };
  57046. function rotateNodeLabel(node, circularRotateLabel, cx, cy) {
  57047. var el = node.getGraphicEl();
  57048. // need to check if el exists. '-' value may not create node element.
  57049. if (!el) {
  57050. return;
  57051. }
  57052. var nodeModel = node.getModel();
  57053. var labelRotate = nodeModel.get(['label', 'rotate']) || 0;
  57054. var symbolPath = el.getSymbolPath();
  57055. if (circularRotateLabel) {
  57056. var pos = node.getLayout();
  57057. var rad = Math.atan2(pos[1] - cy, pos[0] - cx);
  57058. if (rad < 0) {
  57059. rad = Math.PI * 2 + rad;
  57060. }
  57061. var isLeft = pos[0] < cx;
  57062. if (isLeft) {
  57063. rad = rad - Math.PI;
  57064. }
  57065. var textPosition = isLeft ? 'left' : 'right';
  57066. symbolPath.setTextConfig({
  57067. rotation: -rad,
  57068. position: textPosition,
  57069. origin: 'center'
  57070. });
  57071. var emphasisState = symbolPath.ensureState('emphasis');
  57072. extend(emphasisState.textConfig || (emphasisState.textConfig = {}), {
  57073. position: textPosition
  57074. });
  57075. } else {
  57076. symbolPath.setTextConfig({
  57077. rotation: labelRotate *= Math.PI / 180
  57078. });
  57079. }
  57080. }
  57081. function graphCircularLayout(ecModel) {
  57082. ecModel.eachSeriesByType('graph', function (seriesModel) {
  57083. if (seriesModel.get('layout') === 'circular') {
  57084. circularLayout(seriesModel, 'symbolSize');
  57085. }
  57086. });
  57087. }
  57088. var scaleAndAdd$1 = scaleAndAdd;
  57089. // function adjacentNode(n, e) {
  57090. // return e.n1 === n ? e.n2 : e.n1;
  57091. // }
  57092. function forceLayout(inNodes, inEdges, opts) {
  57093. var nodes = inNodes;
  57094. var edges = inEdges;
  57095. var rect = opts.rect;
  57096. var width = rect.width;
  57097. var height = rect.height;
  57098. var center = [rect.x + width / 2, rect.y + height / 2];
  57099. // let scale = opts.scale || 1;
  57100. var gravity = opts.gravity == null ? 0.1 : opts.gravity;
  57101. // for (let i = 0; i < edges.length; i++) {
  57102. // let e = edges[i];
  57103. // let n1 = e.n1;
  57104. // let n2 = e.n2;
  57105. // n1.edges = n1.edges || [];
  57106. // n2.edges = n2.edges || [];
  57107. // n1.edges.push(e);
  57108. // n2.edges.push(e);
  57109. // }
  57110. // Init position
  57111. for (var i = 0; i < nodes.length; i++) {
  57112. var n = nodes[i];
  57113. if (!n.p) {
  57114. n.p = create(width * (Math.random() - 0.5) + center[0], height * (Math.random() - 0.5) + center[1]);
  57115. }
  57116. n.pp = clone$1(n.p);
  57117. n.edges = null;
  57118. }
  57119. // Formula in 'Graph Drawing by Force-directed Placement'
  57120. // let k = scale * Math.sqrt(width * height / nodes.length);
  57121. // let k2 = k * k;
  57122. var initialFriction = opts.friction == null ? 0.6 : opts.friction;
  57123. var friction = initialFriction;
  57124. var beforeStepCallback;
  57125. var afterStepCallback;
  57126. return {
  57127. warmUp: function () {
  57128. friction = initialFriction * 0.8;
  57129. },
  57130. setFixed: function (idx) {
  57131. nodes[idx].fixed = true;
  57132. },
  57133. setUnfixed: function (idx) {
  57134. nodes[idx].fixed = false;
  57135. },
  57136. /**
  57137. * Before step hook
  57138. */
  57139. beforeStep: function (cb) {
  57140. beforeStepCallback = cb;
  57141. },
  57142. /**
  57143. * After step hook
  57144. */
  57145. afterStep: function (cb) {
  57146. afterStepCallback = cb;
  57147. },
  57148. /**
  57149. * Some formulas were originally copied from "d3.js"
  57150. * https://github.com/d3/d3/blob/b516d77fb8566b576088e73410437494717ada26/src/layout/force.js
  57151. * with some modifications made for this project.
  57152. * See the license statement at the head of this file.
  57153. */
  57154. step: function (cb) {
  57155. beforeStepCallback && beforeStepCallback(nodes, edges);
  57156. var v12 = [];
  57157. var nLen = nodes.length;
  57158. for (var i = 0; i < edges.length; i++) {
  57159. var e = edges[i];
  57160. if (e.ignoreForceLayout) {
  57161. continue;
  57162. }
  57163. var n1 = e.n1;
  57164. var n2 = e.n2;
  57165. sub(v12, n2.p, n1.p);
  57166. var d = len(v12) - e.d;
  57167. var w = n2.w / (n1.w + n2.w);
  57168. if (isNaN(w)) {
  57169. w = 0;
  57170. }
  57171. normalize(v12, v12);
  57172. !n1.fixed && scaleAndAdd$1(n1.p, n1.p, v12, w * d * friction);
  57173. !n2.fixed && scaleAndAdd$1(n2.p, n2.p, v12, -(1 - w) * d * friction);
  57174. }
  57175. // Gravity
  57176. for (var i = 0; i < nLen; i++) {
  57177. var n = nodes[i];
  57178. if (!n.fixed) {
  57179. sub(v12, center, n.p);
  57180. // let d = vec2.len(v12);
  57181. // vec2.scale(v12, v12, 1 / d);
  57182. // let gravityFactor = gravity;
  57183. scaleAndAdd$1(n.p, n.p, v12, gravity * friction);
  57184. }
  57185. }
  57186. // Repulsive
  57187. // PENDING
  57188. for (var i = 0; i < nLen; i++) {
  57189. var n1 = nodes[i];
  57190. for (var j = i + 1; j < nLen; j++) {
  57191. var n2 = nodes[j];
  57192. sub(v12, n2.p, n1.p);
  57193. var d = len(v12);
  57194. if (d === 0) {
  57195. // Random repulse
  57196. set(v12, Math.random() - 0.5, Math.random() - 0.5);
  57197. d = 1;
  57198. }
  57199. var repFact = (n1.rep + n2.rep) / d / d;
  57200. !n1.fixed && scaleAndAdd$1(n1.pp, n1.pp, v12, repFact);
  57201. !n2.fixed && scaleAndAdd$1(n2.pp, n2.pp, v12, -repFact);
  57202. }
  57203. }
  57204. var v = [];
  57205. for (var i = 0; i < nLen; i++) {
  57206. var n = nodes[i];
  57207. if (!n.fixed) {
  57208. sub(v, n.p, n.pp);
  57209. scaleAndAdd$1(n.p, n.p, v, friction);
  57210. copy(n.pp, n.p);
  57211. }
  57212. }
  57213. friction = friction * 0.992;
  57214. var finished = friction < 0.01;
  57215. afterStepCallback && afterStepCallback(nodes, edges, finished);
  57216. cb && cb(finished);
  57217. }
  57218. };
  57219. }
  57220. function graphForceLayout(ecModel) {
  57221. ecModel.eachSeriesByType('graph', function (graphSeries) {
  57222. var coordSys = graphSeries.coordinateSystem;
  57223. if (coordSys && coordSys.type !== 'view') {
  57224. return;
  57225. }
  57226. if (graphSeries.get('layout') === 'force') {
  57227. var preservedPoints_1 = graphSeries.preservedPoints || {};
  57228. var graph_1 = graphSeries.getGraph();
  57229. var nodeData_1 = graph_1.data;
  57230. var edgeData = graph_1.edgeData;
  57231. var forceModel = graphSeries.getModel('force');
  57232. var initLayout = forceModel.get('initLayout');
  57233. if (graphSeries.preservedPoints) {
  57234. nodeData_1.each(function (idx) {
  57235. var id = nodeData_1.getId(idx);
  57236. nodeData_1.setItemLayout(idx, preservedPoints_1[id] || [NaN, NaN]);
  57237. });
  57238. } else if (!initLayout || initLayout === 'none') {
  57239. simpleLayout(graphSeries);
  57240. } else if (initLayout === 'circular') {
  57241. circularLayout(graphSeries, 'value');
  57242. }
  57243. var nodeDataExtent_1 = nodeData_1.getDataExtent('value');
  57244. var edgeDataExtent_1 = edgeData.getDataExtent('value');
  57245. // let edgeDataExtent = edgeData.getDataExtent('value');
  57246. var repulsion = forceModel.get('repulsion');
  57247. var edgeLength = forceModel.get('edgeLength');
  57248. var repulsionArr_1 = isArray(repulsion) ? repulsion : [repulsion, repulsion];
  57249. var edgeLengthArr_1 = isArray(edgeLength) ? edgeLength : [edgeLength, edgeLength];
  57250. // Larger value has smaller length
  57251. edgeLengthArr_1 = [edgeLengthArr_1[1], edgeLengthArr_1[0]];
  57252. var nodes_1 = nodeData_1.mapArray('value', function (value, idx) {
  57253. var point = nodeData_1.getItemLayout(idx);
  57254. var rep = linearMap(value, nodeDataExtent_1, repulsionArr_1);
  57255. if (isNaN(rep)) {
  57256. rep = (repulsionArr_1[0] + repulsionArr_1[1]) / 2;
  57257. }
  57258. return {
  57259. w: rep,
  57260. rep: rep,
  57261. fixed: nodeData_1.getItemModel(idx).get('fixed'),
  57262. p: !point || isNaN(point[0]) || isNaN(point[1]) ? null : point
  57263. };
  57264. });
  57265. var edges = edgeData.mapArray('value', function (value, idx) {
  57266. var edge = graph_1.getEdgeByIndex(idx);
  57267. var d = linearMap(value, edgeDataExtent_1, edgeLengthArr_1);
  57268. if (isNaN(d)) {
  57269. d = (edgeLengthArr_1[0] + edgeLengthArr_1[1]) / 2;
  57270. }
  57271. var edgeModel = edge.getModel();
  57272. var curveness = retrieve3(edge.getModel().get(['lineStyle', 'curveness']), -getCurvenessForEdge(edge, graphSeries, idx, true), 0);
  57273. return {
  57274. n1: nodes_1[edge.node1.dataIndex],
  57275. n2: nodes_1[edge.node2.dataIndex],
  57276. d: d,
  57277. curveness: curveness,
  57278. ignoreForceLayout: edgeModel.get('ignoreForceLayout')
  57279. };
  57280. });
  57281. // let coordSys = graphSeries.coordinateSystem;
  57282. var rect = coordSys.getBoundingRect();
  57283. var forceInstance = forceLayout(nodes_1, edges, {
  57284. rect: rect,
  57285. gravity: forceModel.get('gravity'),
  57286. friction: forceModel.get('friction')
  57287. });
  57288. forceInstance.beforeStep(function (nodes, edges) {
  57289. for (var i = 0, l = nodes.length; i < l; i++) {
  57290. if (nodes[i].fixed) {
  57291. // Write back to layout instance
  57292. copy(nodes[i].p, graph_1.getNodeByIndex(i).getLayout());
  57293. }
  57294. }
  57295. });
  57296. forceInstance.afterStep(function (nodes, edges, stopped) {
  57297. for (var i = 0, l = nodes.length; i < l; i++) {
  57298. if (!nodes[i].fixed) {
  57299. graph_1.getNodeByIndex(i).setLayout(nodes[i].p);
  57300. }
  57301. preservedPoints_1[nodeData_1.getId(i)] = nodes[i].p;
  57302. }
  57303. for (var i = 0, l = edges.length; i < l; i++) {
  57304. var e = edges[i];
  57305. var edge = graph_1.getEdgeByIndex(i);
  57306. var p1 = e.n1.p;
  57307. var p2 = e.n2.p;
  57308. var points = edge.getLayout();
  57309. points = points ? points.slice() : [];
  57310. points[0] = points[0] || [];
  57311. points[1] = points[1] || [];
  57312. copy(points[0], p1);
  57313. copy(points[1], p2);
  57314. if (+e.curveness) {
  57315. points[2] = [(p1[0] + p2[0]) / 2 - (p1[1] - p2[1]) * e.curveness, (p1[1] + p2[1]) / 2 - (p2[0] - p1[0]) * e.curveness];
  57316. }
  57317. edge.setLayout(points);
  57318. }
  57319. });
  57320. graphSeries.forceLayout = forceInstance;
  57321. graphSeries.preservedPoints = preservedPoints_1;
  57322. // Step to get the layout
  57323. forceInstance.step();
  57324. } else {
  57325. // Remove prev injected forceLayout instance
  57326. graphSeries.forceLayout = null;
  57327. }
  57328. });
  57329. }
  57330. function getViewRect(seriesModel, api, aspect) {
  57331. var layoutRef = createBoxLayoutReference(seriesModel, api);
  57332. var option = extend(seriesModel.getBoxLayoutParams(), {
  57333. aspect: aspect
  57334. });
  57335. var viewRect = getLayoutRect(option, layoutRef.refContainer);
  57336. return applyPreserveAspect(seriesModel, viewRect, aspect);
  57337. }
  57338. function createViewCoordSys(ecModel, api) {
  57339. var viewList = [];
  57340. ecModel.eachSeriesByType('graph', function (seriesModel) {
  57341. injectCoordSysByOption({
  57342. targetModel: seriesModel,
  57343. coordSysType: 'view',
  57344. coordSysProvider: createViewCoordSys,
  57345. isDefaultDataCoordSys: true
  57346. });
  57347. function createViewCoordSys() {
  57348. var data = seriesModel.getData();
  57349. var positions = data.mapArray(function (idx) {
  57350. var itemModel = data.getItemModel(idx);
  57351. return [+itemModel.get('x'), +itemModel.get('y')];
  57352. });
  57353. var min = [];
  57354. var max = [];
  57355. fromPoints(positions, min, max);
  57356. // If width or height is 0
  57357. if (max[0] - min[0] === 0) {
  57358. max[0] += 1;
  57359. min[0] -= 1;
  57360. }
  57361. if (max[1] - min[1] === 0) {
  57362. max[1] += 1;
  57363. min[1] -= 1;
  57364. }
  57365. var aspect = (max[0] - min[0]) / (max[1] - min[1]);
  57366. // FIXME If get view rect after data processed?
  57367. var viewRect = getViewRect(seriesModel, api, aspect);
  57368. // Position may be NaN, use view rect instead
  57369. if (isNaN(aspect)) {
  57370. min = [viewRect.x, viewRect.y];
  57371. max = [viewRect.x + viewRect.width, viewRect.y + viewRect.height];
  57372. }
  57373. var bbWidth = max[0] - min[0];
  57374. var bbHeight = max[1] - min[1];
  57375. var viewCoordSys = new View(null, {
  57376. api: api,
  57377. ecModel: ecModel
  57378. });
  57379. viewCoordSys.zoomLimit = seriesModel.get('scaleLimit');
  57380. viewCoordSys.setBoundingRect(min[0], min[1], bbWidth, bbHeight);
  57381. viewCoordSys.setViewRect(viewRect.x, viewRect.y, viewRect.width, viewRect.height);
  57382. // Update roam info
  57383. viewCoordSys.setCenter(seriesModel.get('center'));
  57384. viewCoordSys.setZoom(seriesModel.get('zoom'));
  57385. viewList.push(viewCoordSys);
  57386. return viewCoordSys;
  57387. }
  57388. });
  57389. return viewList;
  57390. }
  57391. var straightLineProto = Line.prototype;
  57392. var bezierCurveProto = BezierCurve.prototype;
  57393. var StraightLineShape = /** @class */function () {
  57394. function StraightLineShape() {
  57395. // Start point
  57396. this.x1 = 0;
  57397. this.y1 = 0;
  57398. // End point
  57399. this.x2 = 0;
  57400. this.y2 = 0;
  57401. this.percent = 1;
  57402. }
  57403. return StraightLineShape;
  57404. }();
  57405. var CurveShape = /** @class */function (_super) {
  57406. __extends(CurveShape, _super);
  57407. function CurveShape() {
  57408. return _super !== null && _super.apply(this, arguments) || this;
  57409. }
  57410. return CurveShape;
  57411. }(StraightLineShape);
  57412. function isStraightLine(shape) {
  57413. return isNaN(+shape.cpx1) || isNaN(+shape.cpy1);
  57414. }
  57415. var ECLinePath = /** @class */function (_super) {
  57416. __extends(ECLinePath, _super);
  57417. function ECLinePath(opts) {
  57418. var _this = _super.call(this, opts) || this;
  57419. _this.type = 'ec-line';
  57420. return _this;
  57421. }
  57422. ECLinePath.prototype.getDefaultStyle = function () {
  57423. return {
  57424. stroke: tokens.color.neutral99,
  57425. fill: null
  57426. };
  57427. };
  57428. ECLinePath.prototype.getDefaultShape = function () {
  57429. return new StraightLineShape();
  57430. };
  57431. ECLinePath.prototype.buildPath = function (ctx, shape) {
  57432. if (isStraightLine(shape)) {
  57433. straightLineProto.buildPath.call(this, ctx, shape);
  57434. } else {
  57435. bezierCurveProto.buildPath.call(this, ctx, shape);
  57436. }
  57437. };
  57438. ECLinePath.prototype.pointAt = function (t) {
  57439. if (isStraightLine(this.shape)) {
  57440. return straightLineProto.pointAt.call(this, t);
  57441. } else {
  57442. return bezierCurveProto.pointAt.call(this, t);
  57443. }
  57444. };
  57445. ECLinePath.prototype.tangentAt = function (t) {
  57446. var shape = this.shape;
  57447. var p = isStraightLine(shape) ? [shape.x2 - shape.x1, shape.y2 - shape.y1] : bezierCurveProto.tangentAt.call(this, t);
  57448. return normalize(p, p);
  57449. };
  57450. return ECLinePath;
  57451. }(Path);
  57452. var SYMBOL_CATEGORIES = ['fromSymbol', 'toSymbol'];
  57453. function makeSymbolTypeKey(symbolCategory) {
  57454. return '_' + symbolCategory + 'Type';
  57455. }
  57456. function makeSymbolTypeValue(name, lineData, idx) {
  57457. var symbolType = lineData.getItemVisual(idx, name);
  57458. if (!symbolType || symbolType === 'none') {
  57459. return symbolType;
  57460. }
  57461. var symbolSize = lineData.getItemVisual(idx, name + 'Size');
  57462. var symbolRotate = lineData.getItemVisual(idx, name + 'Rotate');
  57463. var symbolOffset = lineData.getItemVisual(idx, name + 'Offset');
  57464. var symbolKeepAspect = lineData.getItemVisual(idx, name + 'KeepAspect');
  57465. var symbolSizeArr = normalizeSymbolSize(symbolSize);
  57466. var symbolOffsetArr = normalizeSymbolOffset(symbolOffset || 0, symbolSizeArr);
  57467. return symbolType + symbolSizeArr + symbolOffsetArr + (symbolRotate || '') + (symbolKeepAspect || '');
  57468. }
  57469. /**
  57470. * @inner
  57471. */
  57472. function createSymbol$1(name, lineData, idx) {
  57473. var symbolType = lineData.getItemVisual(idx, name);
  57474. if (!symbolType || symbolType === 'none') {
  57475. return;
  57476. }
  57477. var symbolSize = lineData.getItemVisual(idx, name + 'Size');
  57478. var symbolRotate = lineData.getItemVisual(idx, name + 'Rotate');
  57479. var symbolOffset = lineData.getItemVisual(idx, name + 'Offset');
  57480. var symbolKeepAspect = lineData.getItemVisual(idx, name + 'KeepAspect');
  57481. var symbolSizeArr = normalizeSymbolSize(symbolSize);
  57482. var symbolOffsetArr = normalizeSymbolOffset(symbolOffset || 0, symbolSizeArr);
  57483. var symbolPath = createSymbol(symbolType, -symbolSizeArr[0] / 2 + symbolOffsetArr[0], -symbolSizeArr[1] / 2 + symbolOffsetArr[1], symbolSizeArr[0], symbolSizeArr[1], null, symbolKeepAspect);
  57484. symbolPath.__specifiedRotation = symbolRotate == null || isNaN(symbolRotate) ? void 0 : +symbolRotate * Math.PI / 180 || 0;
  57485. symbolPath.name = name;
  57486. return symbolPath;
  57487. }
  57488. function createLine(points) {
  57489. var line = new ECLinePath({
  57490. name: 'line',
  57491. subPixelOptimize: true
  57492. });
  57493. setLinePoints(line.shape, points);
  57494. return line;
  57495. }
  57496. function setLinePoints(targetShape, points) {
  57497. targetShape.x1 = points[0][0];
  57498. targetShape.y1 = points[0][1];
  57499. targetShape.x2 = points[1][0];
  57500. targetShape.y2 = points[1][1];
  57501. targetShape.percent = 1;
  57502. var cp1 = points[2];
  57503. if (cp1) {
  57504. targetShape.cpx1 = cp1[0];
  57505. targetShape.cpy1 = cp1[1];
  57506. } else {
  57507. targetShape.cpx1 = NaN;
  57508. targetShape.cpy1 = NaN;
  57509. }
  57510. }
  57511. var Line$1 = /** @class */function (_super) {
  57512. __extends(Line, _super);
  57513. function Line(lineData, idx, seriesScope) {
  57514. var _this = _super.call(this) || this;
  57515. _this._createLine(lineData, idx, seriesScope);
  57516. return _this;
  57517. }
  57518. Line.prototype._createLine = function (lineData, idx, seriesScope) {
  57519. var seriesModel = lineData.hostModel;
  57520. var linePoints = lineData.getItemLayout(idx);
  57521. var z2 = lineData.getItemVisual(idx, 'z2');
  57522. var line = createLine(linePoints);
  57523. line.shape.percent = 0;
  57524. initProps(line, {
  57525. z2: retrieve2(z2, 0),
  57526. shape: {
  57527. percent: 1
  57528. }
  57529. }, seriesModel, idx);
  57530. this.add(line);
  57531. each(SYMBOL_CATEGORIES, function (symbolCategory) {
  57532. var symbol = createSymbol$1(symbolCategory, lineData, idx);
  57533. // symbols must added after line to make sure
  57534. // it will be updated after line#update.
  57535. // Or symbol position and rotation update in line#beforeUpdate will be one frame slow
  57536. this.add(symbol);
  57537. this[makeSymbolTypeKey(symbolCategory)] = makeSymbolTypeValue(symbolCategory, lineData, idx);
  57538. }, this);
  57539. this._updateCommonStl(lineData, idx, seriesScope);
  57540. };
  57541. // TODO More strict on the List type in parameters?
  57542. Line.prototype.updateData = function (lineData, idx, seriesScope) {
  57543. var seriesModel = lineData.hostModel;
  57544. var line = this.childOfName('line');
  57545. var linePoints = lineData.getItemLayout(idx);
  57546. var target = {
  57547. shape: {}
  57548. };
  57549. setLinePoints(target.shape, linePoints);
  57550. updateProps(line, target, seriesModel, idx);
  57551. each(SYMBOL_CATEGORIES, function (symbolCategory) {
  57552. var symbolType = makeSymbolTypeValue(symbolCategory, lineData, idx);
  57553. var key = makeSymbolTypeKey(symbolCategory);
  57554. // Symbol changed
  57555. if (this[key] !== symbolType) {
  57556. this.remove(this.childOfName(symbolCategory));
  57557. var symbol = createSymbol$1(symbolCategory, lineData, idx);
  57558. this.add(symbol);
  57559. }
  57560. this[key] = symbolType;
  57561. }, this);
  57562. this._updateCommonStl(lineData, idx, seriesScope);
  57563. };
  57564. Line.prototype.getLinePath = function () {
  57565. return this.childAt(0);
  57566. };
  57567. Line.prototype._updateCommonStl = function (lineData, idx, seriesScope) {
  57568. var seriesModel = lineData.hostModel;
  57569. var line = this.childOfName('line');
  57570. var emphasisLineStyle = seriesScope && seriesScope.emphasisLineStyle;
  57571. var blurLineStyle = seriesScope && seriesScope.blurLineStyle;
  57572. var selectLineStyle = seriesScope && seriesScope.selectLineStyle;
  57573. var labelStatesModels = seriesScope && seriesScope.labelStatesModels;
  57574. var emphasisDisabled = seriesScope && seriesScope.emphasisDisabled;
  57575. var focus = seriesScope && seriesScope.focus;
  57576. var blurScope = seriesScope && seriesScope.blurScope;
  57577. // Optimization for large dataset
  57578. if (!seriesScope || lineData.hasItemOption) {
  57579. var itemModel = lineData.getItemModel(idx);
  57580. var emphasisModel = itemModel.getModel('emphasis');
  57581. emphasisLineStyle = emphasisModel.getModel('lineStyle').getLineStyle();
  57582. blurLineStyle = itemModel.getModel(['blur', 'lineStyle']).getLineStyle();
  57583. selectLineStyle = itemModel.getModel(['select', 'lineStyle']).getLineStyle();
  57584. emphasisDisabled = emphasisModel.get('disabled');
  57585. focus = emphasisModel.get('focus');
  57586. blurScope = emphasisModel.get('blurScope');
  57587. labelStatesModels = getLabelStatesModels(itemModel);
  57588. }
  57589. var lineStyle = lineData.getItemVisual(idx, 'style');
  57590. var visualColor = lineStyle.stroke;
  57591. line.useStyle(lineStyle);
  57592. line.style.fill = null;
  57593. line.style.strokeNoScale = true;
  57594. line.ensureState('emphasis').style = emphasisLineStyle;
  57595. line.ensureState('blur').style = blurLineStyle;
  57596. line.ensureState('select').style = selectLineStyle;
  57597. // Update symbol
  57598. each(SYMBOL_CATEGORIES, function (symbolCategory) {
  57599. var symbol = this.childOfName(symbolCategory);
  57600. if (symbol) {
  57601. // Share opacity and color with line.
  57602. symbol.setColor(visualColor);
  57603. symbol.style.opacity = lineStyle.opacity;
  57604. for (var i = 0; i < SPECIAL_STATES.length; i++) {
  57605. var stateName = SPECIAL_STATES[i];
  57606. var lineState = line.getState(stateName);
  57607. if (lineState) {
  57608. var lineStateStyle = lineState.style || {};
  57609. var state = symbol.ensureState(stateName);
  57610. var stateStyle = state.style || (state.style = {});
  57611. if (lineStateStyle.stroke != null) {
  57612. stateStyle[symbol.__isEmptyBrush ? 'stroke' : 'fill'] = lineStateStyle.stroke;
  57613. }
  57614. if (lineStateStyle.opacity != null) {
  57615. stateStyle.opacity = lineStateStyle.opacity;
  57616. }
  57617. }
  57618. }
  57619. symbol.markRedraw();
  57620. }
  57621. }, this);
  57622. var rawVal = seriesModel.getRawValue(idx);
  57623. setLabelStyle(this, labelStatesModels, {
  57624. labelDataIndex: idx,
  57625. labelFetcher: {
  57626. getFormattedLabel: function (dataIndex, stateName) {
  57627. return seriesModel.getFormattedLabel(dataIndex, stateName, lineData.dataType);
  57628. }
  57629. },
  57630. inheritColor: visualColor || tokens.color.neutral99,
  57631. defaultOpacity: lineStyle.opacity,
  57632. defaultText: (rawVal == null ? lineData.getName(idx) : isFinite(rawVal) ? round(rawVal) : rawVal) + ''
  57633. });
  57634. var label = this.getTextContent();
  57635. // Always set `textStyle` even if `normalStyle.text` is null, because default
  57636. // values have to be set on `normalStyle`.
  57637. if (label) {
  57638. var labelNormalModel = labelStatesModels.normal;
  57639. label.__align = label.style.align;
  57640. label.__verticalAlign = label.style.verticalAlign;
  57641. // 'start', 'middle', 'end'
  57642. label.__position = labelNormalModel.get('position') || 'middle';
  57643. var distance = labelNormalModel.get('distance');
  57644. if (!isArray(distance)) {
  57645. distance = [distance, distance];
  57646. }
  57647. label.__labelDistance = distance;
  57648. }
  57649. this.setTextConfig({
  57650. position: null,
  57651. local: true,
  57652. inside: false // Can't be inside for stroke element.
  57653. });
  57654. toggleHoverEmphasis(this, focus, blurScope, emphasisDisabled);
  57655. };
  57656. Line.prototype.highlight = function () {
  57657. enterEmphasis(this);
  57658. };
  57659. Line.prototype.downplay = function () {
  57660. leaveEmphasis(this);
  57661. };
  57662. Line.prototype.updateLayout = function (lineData, idx) {
  57663. this.setLinePoints(lineData.getItemLayout(idx));
  57664. };
  57665. Line.prototype.setLinePoints = function (points) {
  57666. var linePath = this.childOfName('line');
  57667. setLinePoints(linePath.shape, points);
  57668. linePath.dirty();
  57669. };
  57670. Line.prototype.beforeUpdate = function () {
  57671. var lineGroup = this;
  57672. var symbolFrom = lineGroup.childOfName('fromSymbol');
  57673. var symbolTo = lineGroup.childOfName('toSymbol');
  57674. var label = lineGroup.getTextContent();
  57675. // Quick reject
  57676. if (!symbolFrom && !symbolTo && (!label || label.ignore)) {
  57677. return;
  57678. }
  57679. var invScale = 1;
  57680. var parentNode = this.parent;
  57681. while (parentNode) {
  57682. if (parentNode.scaleX) {
  57683. invScale /= parentNode.scaleX;
  57684. }
  57685. parentNode = parentNode.parent;
  57686. }
  57687. var line = lineGroup.childOfName('line');
  57688. // If line not changed
  57689. // FIXME Parent scale changed
  57690. if (!this.__dirty && !line.__dirty) {
  57691. return;
  57692. }
  57693. var percent = line.shape.percent;
  57694. var fromPos = line.pointAt(0);
  57695. var toPos = line.pointAt(percent);
  57696. var d = sub([], toPos, fromPos);
  57697. normalize(d, d);
  57698. function setSymbolRotation(symbol, percent) {
  57699. // Fix #12388
  57700. // when symbol is set to be 'arrow' in markLine,
  57701. // symbolRotate value will be ignored, and compulsively use tangent angle.
  57702. // rotate by default if symbol rotation is not specified
  57703. var specifiedRotation = symbol.__specifiedRotation;
  57704. if (specifiedRotation == null) {
  57705. var tangent = line.tangentAt(percent);
  57706. symbol.attr('rotation', (percent === 1 ? -1 : 1) * Math.PI / 2 - Math.atan2(tangent[1], tangent[0]));
  57707. } else {
  57708. symbol.attr('rotation', specifiedRotation);
  57709. }
  57710. }
  57711. if (symbolFrom) {
  57712. symbolFrom.setPosition(fromPos);
  57713. setSymbolRotation(symbolFrom, 0);
  57714. symbolFrom.scaleX = symbolFrom.scaleY = invScale * percent;
  57715. symbolFrom.markRedraw();
  57716. }
  57717. if (symbolTo) {
  57718. symbolTo.setPosition(toPos);
  57719. setSymbolRotation(symbolTo, 1);
  57720. symbolTo.scaleX = symbolTo.scaleY = invScale * percent;
  57721. symbolTo.markRedraw();
  57722. }
  57723. if (label && !label.ignore) {
  57724. label.x = label.y = 0;
  57725. label.originX = label.originY = 0;
  57726. var textAlign = void 0;
  57727. var textVerticalAlign = void 0;
  57728. var distance = label.__labelDistance;
  57729. var distanceX = distance[0] * invScale;
  57730. var distanceY = distance[1] * invScale;
  57731. var halfPercent = percent / 2;
  57732. var tangent = line.tangentAt(halfPercent);
  57733. var n = [tangent[1], -tangent[0]];
  57734. var cp = line.pointAt(halfPercent);
  57735. if (n[1] > 0) {
  57736. n[0] = -n[0];
  57737. n[1] = -n[1];
  57738. }
  57739. var dir = tangent[0] < 0 ? -1 : 1;
  57740. if (label.__position !== 'start' && label.__position !== 'end') {
  57741. var rotation = -Math.atan2(tangent[1], tangent[0]);
  57742. if (toPos[0] < fromPos[0]) {
  57743. rotation = Math.PI + rotation;
  57744. }
  57745. label.rotation = rotation;
  57746. }
  57747. var dy = void 0;
  57748. switch (label.__position) {
  57749. case 'insideStartTop':
  57750. case 'insideMiddleTop':
  57751. case 'insideEndTop':
  57752. case 'middle':
  57753. dy = -distanceY;
  57754. textVerticalAlign = 'bottom';
  57755. break;
  57756. case 'insideStartBottom':
  57757. case 'insideMiddleBottom':
  57758. case 'insideEndBottom':
  57759. dy = distanceY;
  57760. textVerticalAlign = 'top';
  57761. break;
  57762. default:
  57763. dy = 0;
  57764. textVerticalAlign = 'middle';
  57765. }
  57766. switch (label.__position) {
  57767. case 'end':
  57768. label.x = d[0] * distanceX + toPos[0];
  57769. label.y = d[1] * distanceY + toPos[1];
  57770. textAlign = d[0] > 0.8 ? 'left' : d[0] < -0.8 ? 'right' : 'center';
  57771. textVerticalAlign = d[1] > 0.8 ? 'top' : d[1] < -0.8 ? 'bottom' : 'middle';
  57772. break;
  57773. case 'start':
  57774. label.x = -d[0] * distanceX + fromPos[0];
  57775. label.y = -d[1] * distanceY + fromPos[1];
  57776. textAlign = d[0] > 0.8 ? 'right' : d[0] < -0.8 ? 'left' : 'center';
  57777. textVerticalAlign = d[1] > 0.8 ? 'bottom' : d[1] < -0.8 ? 'top' : 'middle';
  57778. break;
  57779. case 'insideStartTop':
  57780. case 'insideStart':
  57781. case 'insideStartBottom':
  57782. label.x = distanceX * dir + fromPos[0];
  57783. label.y = fromPos[1] + dy;
  57784. textAlign = tangent[0] < 0 ? 'right' : 'left';
  57785. label.originX = -distanceX * dir;
  57786. label.originY = -dy;
  57787. break;
  57788. case 'insideMiddleTop':
  57789. case 'insideMiddle':
  57790. case 'insideMiddleBottom':
  57791. case 'middle':
  57792. label.x = cp[0];
  57793. label.y = cp[1] + dy;
  57794. textAlign = 'center';
  57795. label.originY = -dy;
  57796. break;
  57797. case 'insideEndTop':
  57798. case 'insideEnd':
  57799. case 'insideEndBottom':
  57800. label.x = -distanceX * dir + toPos[0];
  57801. label.y = toPos[1] + dy;
  57802. textAlign = tangent[0] >= 0 ? 'right' : 'left';
  57803. label.originX = distanceX * dir;
  57804. label.originY = -dy;
  57805. break;
  57806. }
  57807. label.scaleX = label.scaleY = invScale;
  57808. label.setStyle({
  57809. // Use the user specified text align and baseline first
  57810. verticalAlign: label.__verticalAlign || textVerticalAlign,
  57811. align: label.__align || textAlign
  57812. });
  57813. }
  57814. };
  57815. return Line;
  57816. }(Group);
  57817. var LineDraw = /** @class */function () {
  57818. function LineDraw(LineCtor) {
  57819. this.group = new Group();
  57820. this._LineCtor = LineCtor || Line$1;
  57821. }
  57822. LineDraw.prototype.updateData = function (lineData) {
  57823. var _this = this;
  57824. // Remove progressive els.
  57825. this._progressiveEls = null;
  57826. var lineDraw = this;
  57827. var group = lineDraw.group;
  57828. var oldLineData = lineDraw._lineData;
  57829. lineDraw._lineData = lineData;
  57830. // There is no oldLineData only when first rendering or switching from
  57831. // stream mode to normal mode, where previous elements should be removed.
  57832. if (!oldLineData) {
  57833. group.removeAll();
  57834. }
  57835. var seriesScope = makeSeriesScope$1(lineData);
  57836. lineData.diff(oldLineData).add(function (idx) {
  57837. _this._doAdd(lineData, idx, seriesScope);
  57838. }).update(function (newIdx, oldIdx) {
  57839. _this._doUpdate(oldLineData, lineData, oldIdx, newIdx, seriesScope);
  57840. }).remove(function (idx) {
  57841. group.remove(oldLineData.getItemGraphicEl(idx));
  57842. }).execute();
  57843. };
  57844. LineDraw.prototype.updateLayout = function () {
  57845. var lineData = this._lineData;
  57846. // Do not support update layout in incremental mode.
  57847. if (!lineData) {
  57848. return;
  57849. }
  57850. lineData.eachItemGraphicEl(function (el, idx) {
  57851. el.updateLayout(lineData, idx);
  57852. }, this);
  57853. };
  57854. LineDraw.prototype.incrementalPrepareUpdate = function (lineData) {
  57855. this._seriesScope = makeSeriesScope$1(lineData);
  57856. this._lineData = null;
  57857. this.group.removeAll();
  57858. };
  57859. LineDraw.prototype.incrementalUpdate = function (taskParams, lineData) {
  57860. this._progressiveEls = [];
  57861. function updateIncrementalAndHover(el) {
  57862. if (!el.isGroup && !isEffectObject(el)) {
  57863. el.incremental = true;
  57864. el.ensureState('emphasis').hoverLayer = true;
  57865. }
  57866. }
  57867. for (var idx = taskParams.start; idx < taskParams.end; idx++) {
  57868. var itemLayout = lineData.getItemLayout(idx);
  57869. if (lineNeedsDraw(itemLayout)) {
  57870. var el = new this._LineCtor(lineData, idx, this._seriesScope);
  57871. el.traverse(updateIncrementalAndHover);
  57872. this.group.add(el);
  57873. lineData.setItemGraphicEl(idx, el);
  57874. this._progressiveEls.push(el);
  57875. }
  57876. }
  57877. };
  57878. LineDraw.prototype.remove = function () {
  57879. this.group.removeAll();
  57880. };
  57881. LineDraw.prototype.eachRendered = function (cb) {
  57882. traverseElements(this._progressiveEls || this.group, cb);
  57883. };
  57884. LineDraw.prototype._doAdd = function (lineData, idx, seriesScope) {
  57885. var itemLayout = lineData.getItemLayout(idx);
  57886. if (!lineNeedsDraw(itemLayout)) {
  57887. return;
  57888. }
  57889. var el = new this._LineCtor(lineData, idx, seriesScope);
  57890. lineData.setItemGraphicEl(idx, el);
  57891. this.group.add(el);
  57892. };
  57893. LineDraw.prototype._doUpdate = function (oldLineData, newLineData, oldIdx, newIdx, seriesScope) {
  57894. var itemEl = oldLineData.getItemGraphicEl(oldIdx);
  57895. if (!lineNeedsDraw(newLineData.getItemLayout(newIdx))) {
  57896. this.group.remove(itemEl);
  57897. return;
  57898. }
  57899. if (!itemEl) {
  57900. itemEl = new this._LineCtor(newLineData, newIdx, seriesScope);
  57901. } else {
  57902. itemEl.updateData(newLineData, newIdx, seriesScope);
  57903. }
  57904. newLineData.setItemGraphicEl(newIdx, itemEl);
  57905. this.group.add(itemEl);
  57906. };
  57907. return LineDraw;
  57908. }();
  57909. function isEffectObject(el) {
  57910. return el.animators && el.animators.length > 0;
  57911. }
  57912. function makeSeriesScope$1(lineData) {
  57913. var hostModel = lineData.hostModel;
  57914. var emphasisModel = hostModel.getModel('emphasis');
  57915. return {
  57916. lineStyle: hostModel.getModel('lineStyle').getLineStyle(),
  57917. emphasisLineStyle: emphasisModel.getModel(['lineStyle']).getLineStyle(),
  57918. blurLineStyle: hostModel.getModel(['blur', 'lineStyle']).getLineStyle(),
  57919. selectLineStyle: hostModel.getModel(['select', 'lineStyle']).getLineStyle(),
  57920. emphasisDisabled: emphasisModel.get('disabled'),
  57921. blurScope: emphasisModel.get('blurScope'),
  57922. focus: emphasisModel.get('focus'),
  57923. labelStatesModels: getLabelStatesModels(hostModel)
  57924. };
  57925. }
  57926. function isPointNaN(pt) {
  57927. return isNaN(pt[0]) || isNaN(pt[1]);
  57928. }
  57929. function lineNeedsDraw(pts) {
  57930. return pts && !isPointNaN(pts[0]) && !isPointNaN(pts[1]);
  57931. }
  57932. var v1 = [];
  57933. var v2 = [];
  57934. var v3 = [];
  57935. var quadraticAt$1 = quadraticAt;
  57936. var v2DistSquare = distSquare;
  57937. var mathAbs$5 = Math.abs;
  57938. function intersectCurveCircle(curvePoints, center, radius) {
  57939. var p0 = curvePoints[0];
  57940. var p1 = curvePoints[1];
  57941. var p2 = curvePoints[2];
  57942. var d = Infinity;
  57943. var t;
  57944. var radiusSquare = radius * radius;
  57945. var interval = 0.1;
  57946. for (var _t = 0.1; _t <= 0.9; _t += 0.1) {
  57947. v1[0] = quadraticAt$1(p0[0], p1[0], p2[0], _t);
  57948. v1[1] = quadraticAt$1(p0[1], p1[1], p2[1], _t);
  57949. var diff = mathAbs$5(v2DistSquare(v1, center) - radiusSquare);
  57950. if (diff < d) {
  57951. d = diff;
  57952. t = _t;
  57953. }
  57954. }
  57955. // Assume the segment is monotone,Find root through Bisection method
  57956. // At most 32 iteration
  57957. for (var i = 0; i < 32; i++) {
  57958. // let prev = t - interval;
  57959. var next = t + interval;
  57960. // v1[0] = quadraticAt(p0[0], p1[0], p2[0], prev);
  57961. // v1[1] = quadraticAt(p0[1], p1[1], p2[1], prev);
  57962. v2[0] = quadraticAt$1(p0[0], p1[0], p2[0], t);
  57963. v2[1] = quadraticAt$1(p0[1], p1[1], p2[1], t);
  57964. v3[0] = quadraticAt$1(p0[0], p1[0], p2[0], next);
  57965. v3[1] = quadraticAt$1(p0[1], p1[1], p2[1], next);
  57966. var diff = v2DistSquare(v2, center) - radiusSquare;
  57967. if (mathAbs$5(diff) < 1e-2) {
  57968. break;
  57969. }
  57970. // let prevDiff = v2DistSquare(v1, center) - radiusSquare;
  57971. var nextDiff = v2DistSquare(v3, center) - radiusSquare;
  57972. interval /= 2;
  57973. if (diff < 0) {
  57974. if (nextDiff >= 0) {
  57975. t = t + interval;
  57976. } else {
  57977. t = t - interval;
  57978. }
  57979. } else {
  57980. if (nextDiff >= 0) {
  57981. t = t - interval;
  57982. } else {
  57983. t = t + interval;
  57984. }
  57985. }
  57986. }
  57987. return t;
  57988. }
  57989. // Adjust edge to avoid
  57990. function adjustEdge(graph, scale) {
  57991. var tmp0 = [];
  57992. var quadraticSubdivide$1 = quadraticSubdivide;
  57993. var pts = [[], [], []];
  57994. var pts2 = [[], []];
  57995. var v = [];
  57996. scale /= 2;
  57997. graph.eachEdge(function (edge, idx) {
  57998. var linePoints = edge.getLayout();
  57999. var fromSymbol = edge.getVisual('fromSymbol');
  58000. var toSymbol = edge.getVisual('toSymbol');
  58001. if (!linePoints.__original) {
  58002. linePoints.__original = [clone$1(linePoints[0]), clone$1(linePoints[1])];
  58003. if (linePoints[2]) {
  58004. linePoints.__original.push(clone$1(linePoints[2]));
  58005. }
  58006. }
  58007. var originalPoints = linePoints.__original;
  58008. // Quadratic curve
  58009. if (linePoints[2] != null) {
  58010. copy(pts[0], originalPoints[0]);
  58011. copy(pts[1], originalPoints[2]);
  58012. copy(pts[2], originalPoints[1]);
  58013. if (fromSymbol && fromSymbol !== 'none') {
  58014. var symbolSize = getSymbolSize(edge.node1);
  58015. var t = intersectCurveCircle(pts, originalPoints[0], symbolSize * scale);
  58016. // Subdivide and get the second
  58017. quadraticSubdivide$1(pts[0][0], pts[1][0], pts[2][0], t, tmp0);
  58018. pts[0][0] = tmp0[3];
  58019. pts[1][0] = tmp0[4];
  58020. quadraticSubdivide$1(pts[0][1], pts[1][1], pts[2][1], t, tmp0);
  58021. pts[0][1] = tmp0[3];
  58022. pts[1][1] = tmp0[4];
  58023. }
  58024. if (toSymbol && toSymbol !== 'none') {
  58025. var symbolSize = getSymbolSize(edge.node2);
  58026. var t = intersectCurveCircle(pts, originalPoints[1], symbolSize * scale);
  58027. // Subdivide and get the first
  58028. quadraticSubdivide$1(pts[0][0], pts[1][0], pts[2][0], t, tmp0);
  58029. pts[1][0] = tmp0[1];
  58030. pts[2][0] = tmp0[2];
  58031. quadraticSubdivide$1(pts[0][1], pts[1][1], pts[2][1], t, tmp0);
  58032. pts[1][1] = tmp0[1];
  58033. pts[2][1] = tmp0[2];
  58034. }
  58035. // Copy back to layout
  58036. copy(linePoints[0], pts[0]);
  58037. copy(linePoints[1], pts[2]);
  58038. copy(linePoints[2], pts[1]);
  58039. }
  58040. // Line
  58041. else {
  58042. copy(pts2[0], originalPoints[0]);
  58043. copy(pts2[1], originalPoints[1]);
  58044. sub(v, pts2[1], pts2[0]);
  58045. normalize(v, v);
  58046. if (fromSymbol && fromSymbol !== 'none') {
  58047. var symbolSize = getSymbolSize(edge.node1);
  58048. scaleAndAdd(pts2[0], pts2[0], v, symbolSize * scale);
  58049. }
  58050. if (toSymbol && toSymbol !== 'none') {
  58051. var symbolSize = getSymbolSize(edge.node2);
  58052. scaleAndAdd(pts2[1], pts2[1], v, -symbolSize * scale);
  58053. }
  58054. copy(linePoints[0], pts2[0]);
  58055. copy(linePoints[1], pts2[1]);
  58056. }
  58057. });
  58058. }
  58059. /**
  58060. * @caveat Do not import other `src/component/thumbnail/*` files.
  58061. * This file should be decoupled from them for sake of the size consideration.
  58062. */
  58063. /**
  58064. * FIXME: This is a temporary implmentation. May need refactor to decouple
  58065. * the direct call from series.graph to thumbnail.
  58066. */
  58067. var inner$b = makeInner();
  58068. function getThumbnailBridge(model) {
  58069. if (model) {
  58070. return inner$b(model).bridge;
  58071. }
  58072. }
  58073. function injectThumbnailBridge(model, thumbnailBridge) {
  58074. if (model) {
  58075. inner$b(model).bridge = thumbnailBridge;
  58076. }
  58077. }
  58078. function isViewCoordSys(coordSys) {
  58079. return coordSys.type === 'view';
  58080. }
  58081. var GraphView = /** @class */function (_super) {
  58082. __extends(GraphView, _super);
  58083. function GraphView() {
  58084. var _this = _super !== null && _super.apply(this, arguments) || this;
  58085. _this.type = GraphView.type;
  58086. return _this;
  58087. }
  58088. GraphView.prototype.init = function (ecModel, api) {
  58089. var symbolDraw = new SymbolDraw();
  58090. var lineDraw = new LineDraw();
  58091. var group = this.group;
  58092. var mainGroup = new Group();
  58093. this._controller = new RoamController(api.getZr());
  58094. this._controllerHost = {
  58095. target: mainGroup
  58096. };
  58097. mainGroup.add(symbolDraw.group);
  58098. mainGroup.add(lineDraw.group);
  58099. group.add(mainGroup);
  58100. this._symbolDraw = symbolDraw;
  58101. this._lineDraw = lineDraw;
  58102. this._mainGroup = mainGroup;
  58103. this._firstRender = true;
  58104. };
  58105. GraphView.prototype.render = function (seriesModel, ecModel, api) {
  58106. var _this = this;
  58107. var coordSys = seriesModel.coordinateSystem;
  58108. var isForceLayout = false;
  58109. this._model = seriesModel;
  58110. this._api = api;
  58111. this._active = true;
  58112. var thumbnailInfo = this._getThumbnailInfo();
  58113. if (thumbnailInfo) {
  58114. thumbnailInfo.bridge.reset(api);
  58115. }
  58116. var symbolDraw = this._symbolDraw;
  58117. var lineDraw = this._lineDraw;
  58118. if (isViewCoordSys(coordSys)) {
  58119. var groupNewProp = {
  58120. x: coordSys.x,
  58121. y: coordSys.y,
  58122. scaleX: coordSys.scaleX,
  58123. scaleY: coordSys.scaleY
  58124. };
  58125. if (this._firstRender) {
  58126. this._mainGroup.attr(groupNewProp);
  58127. } else {
  58128. updateProps(this._mainGroup, groupNewProp, seriesModel);
  58129. }
  58130. }
  58131. // Fix edge contact point with node
  58132. adjustEdge(seriesModel.getGraph(), getNodeGlobalScale(seriesModel));
  58133. var data = seriesModel.getData();
  58134. symbolDraw.updateData(data);
  58135. var edgeData = seriesModel.getEdgeData();
  58136. // TODO: TYPE
  58137. lineDraw.updateData(edgeData);
  58138. this._updateNodeAndLinkScale();
  58139. this._updateController(null, seriesModel, api);
  58140. clearTimeout(this._layoutTimeout);
  58141. var forceLayout = seriesModel.forceLayout;
  58142. var layoutAnimation = seriesModel.get(['force', 'layoutAnimation']);
  58143. if (forceLayout) {
  58144. isForceLayout = true;
  58145. this._startForceLayoutIteration(forceLayout, api, layoutAnimation);
  58146. }
  58147. var layout = seriesModel.get('layout');
  58148. data.graph.eachNode(function (node) {
  58149. var idx = node.dataIndex;
  58150. var el = node.getGraphicEl();
  58151. var itemModel = node.getModel();
  58152. if (!el) {
  58153. return;
  58154. }
  58155. // Update draggable
  58156. el.off('drag').off('dragend');
  58157. var draggable = itemModel.get('draggable');
  58158. if (draggable) {
  58159. el.on('drag', function (e) {
  58160. switch (layout) {
  58161. case 'force':
  58162. forceLayout.warmUp();
  58163. !_this._layouting && _this._startForceLayoutIteration(forceLayout, api, layoutAnimation);
  58164. forceLayout.setFixed(idx);
  58165. // Write position back to layout
  58166. data.setItemLayout(idx, [el.x, el.y]);
  58167. break;
  58168. case 'circular':
  58169. data.setItemLayout(idx, [el.x, el.y]);
  58170. // mark node fixed
  58171. node.setLayout({
  58172. fixed: true
  58173. }, true);
  58174. // recalculate circular layout
  58175. circularLayout(seriesModel, 'symbolSize', node, [e.offsetX, e.offsetY]);
  58176. _this.updateLayout(seriesModel);
  58177. break;
  58178. case 'none':
  58179. default:
  58180. data.setItemLayout(idx, [el.x, el.y]);
  58181. // update edge
  58182. simpleLayoutEdge(seriesModel.getGraph(), seriesModel);
  58183. _this.updateLayout(seriesModel);
  58184. break;
  58185. }
  58186. }).on('dragend', function () {
  58187. if (forceLayout) {
  58188. forceLayout.setUnfixed(idx);
  58189. }
  58190. });
  58191. }
  58192. el.setDraggable(draggable, !!itemModel.get('cursor'));
  58193. var focus = itemModel.get(['emphasis', 'focus']);
  58194. if (focus === 'adjacency') {
  58195. getECData(el).focus = node.getAdjacentDataIndices();
  58196. }
  58197. });
  58198. data.graph.eachEdge(function (edge) {
  58199. var el = edge.getGraphicEl();
  58200. var focus = edge.getModel().get(['emphasis', 'focus']);
  58201. if (!el) {
  58202. return;
  58203. }
  58204. if (focus === 'adjacency') {
  58205. getECData(el).focus = {
  58206. edge: [edge.dataIndex],
  58207. node: [edge.node1.dataIndex, edge.node2.dataIndex]
  58208. };
  58209. }
  58210. });
  58211. var circularRotateLabel = seriesModel.get('layout') === 'circular' && seriesModel.get(['circular', 'rotateLabel']);
  58212. var cx = data.getLayout('cx');
  58213. var cy = data.getLayout('cy');
  58214. data.graph.eachNode(function (node) {
  58215. rotateNodeLabel(node, circularRotateLabel, cx, cy);
  58216. });
  58217. this._firstRender = false;
  58218. // Force layout will render thumbnail when layout is finished.
  58219. if (!isForceLayout) {
  58220. this._renderThumbnail(seriesModel, api, this._symbolDraw, this._lineDraw);
  58221. }
  58222. };
  58223. GraphView.prototype.dispose = function () {
  58224. this.remove();
  58225. this._controller && this._controller.dispose();
  58226. this._controllerHost = null;
  58227. };
  58228. GraphView.prototype._startForceLayoutIteration = function (forceLayout, api, layoutAnimation) {
  58229. var self = this;
  58230. var firstRendered = false;
  58231. (function step() {
  58232. forceLayout.step(function (stopped) {
  58233. self.updateLayout(self._model);
  58234. if (stopped || !firstRendered) {
  58235. firstRendered = true;
  58236. self._renderThumbnail(self._model, api, self._symbolDraw, self._lineDraw);
  58237. }
  58238. (self._layouting = !stopped) && (layoutAnimation ? self._layoutTimeout = setTimeout(step, 16) : step());
  58239. });
  58240. })();
  58241. };
  58242. GraphView.prototype._updateController = function (clipRect, seriesModel, api) {
  58243. var controller = this._controller;
  58244. var controllerHost = this._controllerHost;
  58245. var coordSys = seriesModel.coordinateSystem;
  58246. if (!isViewCoordSys(coordSys)) {
  58247. controller.disable();
  58248. return;
  58249. }
  58250. controller.enable(seriesModel.get('roam'), {
  58251. api: api,
  58252. zInfo: {
  58253. component: seriesModel
  58254. },
  58255. triggerInfo: {
  58256. roamTrigger: seriesModel.get('roamTrigger'),
  58257. isInSelf: function (e, x, y) {
  58258. return coordSys.containPoint([x, y]);
  58259. },
  58260. isInClip: function (e, x, y) {
  58261. return !clipRect || clipRect.contain(x, y);
  58262. }
  58263. }
  58264. });
  58265. controllerHost.zoomLimit = seriesModel.get('scaleLimit');
  58266. controllerHost.zoom = coordSys.getZoom();
  58267. controller.off('pan').off('zoom').on('pan', function (e) {
  58268. api.dispatchAction({
  58269. seriesId: seriesModel.id,
  58270. type: 'graphRoam',
  58271. dx: e.dx,
  58272. dy: e.dy
  58273. });
  58274. }).on('zoom', function (e) {
  58275. api.dispatchAction({
  58276. seriesId: seriesModel.id,
  58277. type: 'graphRoam',
  58278. zoom: e.scale,
  58279. originX: e.originX,
  58280. originY: e.originY
  58281. });
  58282. });
  58283. };
  58284. /**
  58285. * A performance shortcut - called by action handler to update the view directly
  58286. * without any data/visual processing (which are assumed to be unchanged), while
  58287. * ensuring consistent behavior between internal and external action triggers.
  58288. */
  58289. GraphView.prototype.updateViewOnPan = function (seriesModel, api, params) {
  58290. if (!this._active) {
  58291. return;
  58292. }
  58293. updateViewOnPan(this._controllerHost, params.dx, params.dy);
  58294. this._updateThumbnailWindow();
  58295. };
  58296. /**
  58297. * A performance shortcut - called by action handler to update the view directly
  58298. * without any data/visual processing (which are assumed to be unchanged), while
  58299. * ensuring consistent behavior between internal and external action triggers.
  58300. */
  58301. GraphView.prototype.updateViewOnZoom = function (seriesModel, api, params) {
  58302. if (!this._active) {
  58303. return;
  58304. }
  58305. updateViewOnZoom(this._controllerHost, params.zoom, params.originX, params.originY);
  58306. this._updateNodeAndLinkScale();
  58307. adjustEdge(seriesModel.getGraph(), getNodeGlobalScale(seriesModel));
  58308. this._lineDraw.updateLayout();
  58309. // Only update label layout on zoom
  58310. api.updateLabelLayout();
  58311. this._updateThumbnailWindow();
  58312. };
  58313. GraphView.prototype._updateNodeAndLinkScale = function () {
  58314. var seriesModel = this._model;
  58315. var data = seriesModel.getData();
  58316. var nodeScale = getNodeGlobalScale(seriesModel);
  58317. data.eachItemGraphicEl(function (el, idx) {
  58318. el && el.setSymbolScale(nodeScale);
  58319. });
  58320. };
  58321. GraphView.prototype.updateLayout = function (seriesModel) {
  58322. if (!this._active) {
  58323. return;
  58324. }
  58325. adjustEdge(seriesModel.getGraph(), getNodeGlobalScale(seriesModel));
  58326. this._symbolDraw.updateLayout();
  58327. this._lineDraw.updateLayout();
  58328. };
  58329. GraphView.prototype.remove = function () {
  58330. this._active = false;
  58331. clearTimeout(this._layoutTimeout);
  58332. this._layouting = false;
  58333. this._layoutTimeout = null;
  58334. this._symbolDraw && this._symbolDraw.remove();
  58335. this._lineDraw && this._lineDraw.remove();
  58336. this._controller && this._controller.disable();
  58337. };
  58338. /**
  58339. * Get thumbnail data structure only if supported.
  58340. */
  58341. GraphView.prototype._getThumbnailInfo = function () {
  58342. var model = this._model;
  58343. var coordSys = model.coordinateSystem;
  58344. if (coordSys.type !== 'view') {
  58345. return;
  58346. }
  58347. var bridge = getThumbnailBridge(model);
  58348. if (!bridge) {
  58349. return;
  58350. }
  58351. return {
  58352. bridge: bridge,
  58353. coordSys: coordSys
  58354. };
  58355. };
  58356. GraphView.prototype._updateThumbnailWindow = function () {
  58357. var info = this._getThumbnailInfo();
  58358. if (info) {
  58359. info.bridge.updateWindow(info.coordSys.transform, this._api);
  58360. }
  58361. };
  58362. GraphView.prototype._renderThumbnail = function (seriesModel, api, symbolDraw, lineDraw) {
  58363. var info = this._getThumbnailInfo();
  58364. if (!info) {
  58365. return;
  58366. }
  58367. var bridgeGroup = new Group();
  58368. var symbolNodes = symbolDraw.group.children();
  58369. var lineNodes = lineDraw.group.children();
  58370. var lineGroup = new Group();
  58371. var symbolGroup = new Group();
  58372. bridgeGroup.add(symbolGroup);
  58373. bridgeGroup.add(lineGroup);
  58374. // TODO: reuse elemenents for performance in large graph?
  58375. for (var i = 0; i < symbolNodes.length; i++) {
  58376. var node = symbolNodes[i];
  58377. var sub = node.children()[0];
  58378. var x = node.x;
  58379. var y = node.y;
  58380. var subShape = clone(sub.shape);
  58381. var shape = extend(subShape, {
  58382. width: sub.scaleX,
  58383. height: sub.scaleY,
  58384. x: x - sub.scaleX / 2,
  58385. y: y - sub.scaleY / 2
  58386. });
  58387. var style = clone(sub.style);
  58388. var subThumbnail = new sub.constructor({
  58389. shape: shape,
  58390. style: style,
  58391. z2: 151
  58392. });
  58393. symbolGroup.add(subThumbnail);
  58394. }
  58395. for (var i = 0; i < lineNodes.length; i++) {
  58396. var node = lineNodes[i];
  58397. var line = node.children()[0];
  58398. var style = clone(line.style);
  58399. var shape = clone(line.shape);
  58400. var lineThumbnail = new ECLinePath({
  58401. style: style,
  58402. shape: shape,
  58403. z2: 151
  58404. });
  58405. lineGroup.add(lineThumbnail);
  58406. }
  58407. info.bridge.renderContent({
  58408. api: api,
  58409. roamType: seriesModel.get('roam'),
  58410. viewportRect: null,
  58411. group: bridgeGroup,
  58412. targetTrans: info.coordSys.transform
  58413. });
  58414. };
  58415. GraphView.type = 'graph';
  58416. return GraphView;
  58417. }(ChartView);
  58418. // id may be function name of Object, add a prefix to avoid this problem.
  58419. function generateNodeKey(id) {
  58420. return '_EC_' + id;
  58421. }
  58422. var Graph = /** @class */function () {
  58423. function Graph(directed) {
  58424. this.type = 'graph';
  58425. this.nodes = [];
  58426. this.edges = [];
  58427. this._nodesMap = {};
  58428. /**
  58429. * @type {Object.<string, module:echarts/data/Graph.Edge>}
  58430. * @private
  58431. */
  58432. this._edgesMap = {};
  58433. this._directed = directed || false;
  58434. }
  58435. /**
  58436. * If is directed graph
  58437. */
  58438. Graph.prototype.isDirected = function () {
  58439. return this._directed;
  58440. };
  58441. /**
  58442. * Add a new node
  58443. */
  58444. Graph.prototype.addNode = function (id, dataIndex) {
  58445. id = id == null ? '' + dataIndex : '' + id;
  58446. var nodesMap = this._nodesMap;
  58447. if (nodesMap[generateNodeKey(id)]) {
  58448. if ("development" !== 'production') {
  58449. console.error('Graph nodes have duplicate name or id');
  58450. }
  58451. return;
  58452. }
  58453. var node = new GraphNode(id, dataIndex);
  58454. node.hostGraph = this;
  58455. this.nodes.push(node);
  58456. nodesMap[generateNodeKey(id)] = node;
  58457. return node;
  58458. };
  58459. /**
  58460. * Get node by data index
  58461. */
  58462. Graph.prototype.getNodeByIndex = function (dataIndex) {
  58463. var rawIdx = this.data.getRawIndex(dataIndex);
  58464. return this.nodes[rawIdx];
  58465. };
  58466. /**
  58467. * Get node by id
  58468. */
  58469. Graph.prototype.getNodeById = function (id) {
  58470. return this._nodesMap[generateNodeKey(id)];
  58471. };
  58472. /**
  58473. * Add a new edge
  58474. */
  58475. Graph.prototype.addEdge = function (n1, n2, dataIndex) {
  58476. var nodesMap = this._nodesMap;
  58477. var edgesMap = this._edgesMap;
  58478. // PENDING
  58479. if (isNumber(n1)) {
  58480. n1 = this.nodes[n1];
  58481. }
  58482. if (isNumber(n2)) {
  58483. n2 = this.nodes[n2];
  58484. }
  58485. if (!(n1 instanceof GraphNode)) {
  58486. n1 = nodesMap[generateNodeKey(n1)];
  58487. }
  58488. if (!(n2 instanceof GraphNode)) {
  58489. n2 = nodesMap[generateNodeKey(n2)];
  58490. }
  58491. if (!n1 || !n2) {
  58492. return;
  58493. }
  58494. var key = n1.id + '-' + n2.id;
  58495. var edge = new GraphEdge(n1, n2, dataIndex);
  58496. edge.hostGraph = this;
  58497. if (this._directed) {
  58498. n1.outEdges.push(edge);
  58499. n2.inEdges.push(edge);
  58500. }
  58501. n1.edges.push(edge);
  58502. if (n1 !== n2) {
  58503. n2.edges.push(edge);
  58504. }
  58505. this.edges.push(edge);
  58506. edgesMap[key] = edge;
  58507. return edge;
  58508. };
  58509. /**
  58510. * Get edge by data index
  58511. */
  58512. Graph.prototype.getEdgeByIndex = function (dataIndex) {
  58513. var rawIdx = this.edgeData.getRawIndex(dataIndex);
  58514. return this.edges[rawIdx];
  58515. };
  58516. /**
  58517. * Get edge by two linked nodes
  58518. */
  58519. Graph.prototype.getEdge = function (n1, n2) {
  58520. if (n1 instanceof GraphNode) {
  58521. n1 = n1.id;
  58522. }
  58523. if (n2 instanceof GraphNode) {
  58524. n2 = n2.id;
  58525. }
  58526. var edgesMap = this._edgesMap;
  58527. if (this._directed) {
  58528. return edgesMap[n1 + '-' + n2];
  58529. } else {
  58530. return edgesMap[n1 + '-' + n2] || edgesMap[n2 + '-' + n1];
  58531. }
  58532. };
  58533. /**
  58534. * Iterate all nodes
  58535. */
  58536. Graph.prototype.eachNode = function (cb, context) {
  58537. var nodes = this.nodes;
  58538. var len = nodes.length;
  58539. for (var i = 0; i < len; i++) {
  58540. if (nodes[i].dataIndex >= 0) {
  58541. cb.call(context, nodes[i], i);
  58542. }
  58543. }
  58544. };
  58545. /**
  58546. * Iterate all edges
  58547. */
  58548. Graph.prototype.eachEdge = function (cb, context) {
  58549. var edges = this.edges;
  58550. var len = edges.length;
  58551. for (var i = 0; i < len; i++) {
  58552. if (edges[i].dataIndex >= 0 && edges[i].node1.dataIndex >= 0 && edges[i].node2.dataIndex >= 0) {
  58553. cb.call(context, edges[i], i);
  58554. }
  58555. }
  58556. };
  58557. /**
  58558. * Breadth first traverse
  58559. * Return true to stop traversing
  58560. */
  58561. Graph.prototype.breadthFirstTraverse = function (cb, startNode, direction, context) {
  58562. if (!(startNode instanceof GraphNode)) {
  58563. startNode = this._nodesMap[generateNodeKey(startNode)];
  58564. }
  58565. if (!startNode) {
  58566. return;
  58567. }
  58568. var edgeType = direction === 'out' ? 'outEdges' : direction === 'in' ? 'inEdges' : 'edges';
  58569. for (var i = 0; i < this.nodes.length; i++) {
  58570. this.nodes[i].__visited = false;
  58571. }
  58572. if (cb.call(context, startNode, null)) {
  58573. return;
  58574. }
  58575. var queue = [startNode];
  58576. while (queue.length) {
  58577. var currentNode = queue.shift();
  58578. var edges = currentNode[edgeType];
  58579. for (var i = 0; i < edges.length; i++) {
  58580. var e = edges[i];
  58581. var otherNode = e.node1 === currentNode ? e.node2 : e.node1;
  58582. if (!otherNode.__visited) {
  58583. if (cb.call(context, otherNode, currentNode)) {
  58584. // Stop traversing
  58585. return;
  58586. }
  58587. queue.push(otherNode);
  58588. otherNode.__visited = true;
  58589. }
  58590. }
  58591. }
  58592. };
  58593. // TODO
  58594. // depthFirstTraverse(
  58595. // cb, startNode, direction, context
  58596. // ) {
  58597. // };
  58598. // Filter update
  58599. Graph.prototype.update = function () {
  58600. var data = this.data;
  58601. var edgeData = this.edgeData;
  58602. var nodes = this.nodes;
  58603. var edges = this.edges;
  58604. for (var i = 0, len = nodes.length; i < len; i++) {
  58605. nodes[i].dataIndex = -1;
  58606. }
  58607. for (var i = 0, len = data.count(); i < len; i++) {
  58608. nodes[data.getRawIndex(i)].dataIndex = i;
  58609. }
  58610. edgeData.filterSelf(function (idx) {
  58611. var edge = edges[edgeData.getRawIndex(idx)];
  58612. return edge.node1.dataIndex >= 0 && edge.node2.dataIndex >= 0;
  58613. });
  58614. // Update edge
  58615. for (var i = 0, len = edges.length; i < len; i++) {
  58616. edges[i].dataIndex = -1;
  58617. }
  58618. for (var i = 0, len = edgeData.count(); i < len; i++) {
  58619. edges[edgeData.getRawIndex(i)].dataIndex = i;
  58620. }
  58621. };
  58622. /**
  58623. * @return {module:echarts/data/Graph}
  58624. */
  58625. Graph.prototype.clone = function () {
  58626. var graph = new Graph(this._directed);
  58627. var nodes = this.nodes;
  58628. var edges = this.edges;
  58629. for (var i = 0; i < nodes.length; i++) {
  58630. graph.addNode(nodes[i].id, nodes[i].dataIndex);
  58631. }
  58632. for (var i = 0; i < edges.length; i++) {
  58633. var e = edges[i];
  58634. graph.addEdge(e.node1.id, e.node2.id, e.dataIndex);
  58635. }
  58636. return graph;
  58637. };
  58638. return Graph;
  58639. }();
  58640. var GraphNode = /** @class */function () {
  58641. function GraphNode(id, dataIndex) {
  58642. this.inEdges = [];
  58643. this.outEdges = [];
  58644. this.edges = [];
  58645. this.dataIndex = -1;
  58646. this.id = id == null ? '' : id;
  58647. this.dataIndex = dataIndex == null ? -1 : dataIndex;
  58648. }
  58649. /**
  58650. * @return {number}
  58651. */
  58652. GraphNode.prototype.degree = function () {
  58653. return this.edges.length;
  58654. };
  58655. /**
  58656. * @return {number}
  58657. */
  58658. GraphNode.prototype.inDegree = function () {
  58659. return this.inEdges.length;
  58660. };
  58661. /**
  58662. * @return {number}
  58663. */
  58664. GraphNode.prototype.outDegree = function () {
  58665. return this.outEdges.length;
  58666. };
  58667. GraphNode.prototype.getModel = function (path) {
  58668. if (this.dataIndex < 0) {
  58669. return;
  58670. }
  58671. var graph = this.hostGraph;
  58672. var itemModel = graph.data.getItemModel(this.dataIndex);
  58673. return itemModel.getModel(path);
  58674. };
  58675. GraphNode.prototype.getAdjacentDataIndices = function () {
  58676. var dataIndices = {
  58677. edge: [],
  58678. node: []
  58679. };
  58680. for (var i = 0; i < this.edges.length; i++) {
  58681. var adjacentEdge = this.edges[i];
  58682. if (adjacentEdge.dataIndex < 0) {
  58683. continue;
  58684. }
  58685. dataIndices.edge.push(adjacentEdge.dataIndex);
  58686. dataIndices.node.push(adjacentEdge.node1.dataIndex, adjacentEdge.node2.dataIndex);
  58687. }
  58688. return dataIndices;
  58689. };
  58690. GraphNode.prototype.getTrajectoryDataIndices = function () {
  58691. var connectedEdgesMap = createHashMap();
  58692. var connectedNodesMap = createHashMap();
  58693. for (var i = 0, len = this.edges.length; i < len; i++) {
  58694. var adjacentEdge = this.edges[i];
  58695. if (adjacentEdge.dataIndex < 0) {
  58696. continue;
  58697. }
  58698. connectedEdgesMap.set(adjacentEdge.dataIndex, true);
  58699. var sourceNodesQueue = [adjacentEdge.node1];
  58700. var targetNodesQueue = [adjacentEdge.node2];
  58701. var nodeIteratorIndex = 0;
  58702. while (nodeIteratorIndex < sourceNodesQueue.length) {
  58703. var sourceNode = sourceNodesQueue[nodeIteratorIndex];
  58704. nodeIteratorIndex++;
  58705. connectedNodesMap.set(sourceNode.dataIndex, true);
  58706. var sourceNodeInEdges = sourceNode.inEdges;
  58707. for (var j = 0, len_1 = sourceNodeInEdges.length, inEdge = void 0, inEdgeDataIndex = void 0; j < len_1; j++) {
  58708. inEdge = sourceNodeInEdges[j];
  58709. inEdgeDataIndex = inEdge.dataIndex;
  58710. if (inEdgeDataIndex >= 0 && !connectedEdgesMap.hasKey(inEdgeDataIndex)) {
  58711. connectedEdgesMap.set(inEdgeDataIndex, true);
  58712. sourceNodesQueue.push(inEdge.node1);
  58713. }
  58714. }
  58715. }
  58716. nodeIteratorIndex = 0;
  58717. while (nodeIteratorIndex < targetNodesQueue.length) {
  58718. var targetNode = targetNodesQueue[nodeIteratorIndex];
  58719. nodeIteratorIndex++;
  58720. connectedNodesMap.set(targetNode.dataIndex, true);
  58721. var targetNodeOutEdges = targetNode.outEdges;
  58722. for (var j = 0, len_2 = targetNodeOutEdges.length, outEdge = void 0, outEdgeDataIndex = void 0; j < len_2; j++) {
  58723. outEdge = targetNodeOutEdges[j];
  58724. outEdgeDataIndex = outEdge.dataIndex;
  58725. if (outEdgeDataIndex >= 0 && !connectedEdgesMap.hasKey(outEdgeDataIndex)) {
  58726. connectedEdgesMap.set(outEdgeDataIndex, true);
  58727. targetNodesQueue.push(outEdge.node2);
  58728. }
  58729. }
  58730. }
  58731. }
  58732. return {
  58733. edge: connectedEdgesMap.keys(),
  58734. node: connectedNodesMap.keys()
  58735. };
  58736. };
  58737. return GraphNode;
  58738. }();
  58739. var GraphEdge = /** @class */function () {
  58740. function GraphEdge(n1, n2, dataIndex) {
  58741. this.dataIndex = -1;
  58742. this.node1 = n1;
  58743. this.node2 = n2;
  58744. this.dataIndex = dataIndex == null ? -1 : dataIndex;
  58745. }
  58746. // eslint-disable-next-line @typescript-eslint/no-unused-vars
  58747. GraphEdge.prototype.getModel = function (path) {
  58748. if (this.dataIndex < 0) {
  58749. return;
  58750. }
  58751. var graph = this.hostGraph;
  58752. var itemModel = graph.edgeData.getItemModel(this.dataIndex);
  58753. return itemModel.getModel(path);
  58754. };
  58755. GraphEdge.prototype.getAdjacentDataIndices = function () {
  58756. return {
  58757. edge: [this.dataIndex],
  58758. node: [this.node1.dataIndex, this.node2.dataIndex]
  58759. };
  58760. };
  58761. GraphEdge.prototype.getTrajectoryDataIndices = function () {
  58762. var connectedEdgesMap = createHashMap();
  58763. var connectedNodesMap = createHashMap();
  58764. connectedEdgesMap.set(this.dataIndex, true);
  58765. var sourceNodes = [this.node1];
  58766. var targetNodes = [this.node2];
  58767. var nodeIteratorIndex = 0;
  58768. while (nodeIteratorIndex < sourceNodes.length) {
  58769. var sourceNode = sourceNodes[nodeIteratorIndex];
  58770. nodeIteratorIndex++;
  58771. connectedNodesMap.set(sourceNode.dataIndex, true);
  58772. var sourceNodeInEdges = sourceNode.inEdges;
  58773. for (var j = 0, len = sourceNodeInEdges.length, inEdge = void 0, inEdgeDataIndex = void 0; j < len; j++) {
  58774. inEdge = sourceNode.inEdges[j];
  58775. inEdgeDataIndex = inEdge.dataIndex;
  58776. if (inEdgeDataIndex >= 0 && !connectedEdgesMap.hasKey(inEdgeDataIndex)) {
  58777. connectedEdgesMap.set(inEdgeDataIndex, true);
  58778. sourceNodes.push(inEdge.node1);
  58779. }
  58780. }
  58781. }
  58782. nodeIteratorIndex = 0;
  58783. while (nodeIteratorIndex < targetNodes.length) {
  58784. var targetNode = targetNodes[nodeIteratorIndex];
  58785. nodeIteratorIndex++;
  58786. connectedNodesMap.set(targetNode.dataIndex, true);
  58787. var targetNodeOutEdges = targetNode.outEdges;
  58788. for (var j = 0, len = targetNodeOutEdges.length, outEdge = void 0, outEdgeDataIndex = void 0; j < len; j++) {
  58789. outEdge = targetNode.outEdges[j];
  58790. outEdgeDataIndex = outEdge.dataIndex;
  58791. if (outEdgeDataIndex >= 0 && !connectedEdgesMap.hasKey(outEdgeDataIndex)) {
  58792. connectedEdgesMap.set(outEdgeDataIndex, true);
  58793. targetNodes.push(outEdge.node2);
  58794. }
  58795. }
  58796. }
  58797. return {
  58798. edge: connectedEdgesMap.keys(),
  58799. node: connectedNodesMap.keys()
  58800. };
  58801. };
  58802. return GraphEdge;
  58803. }();
  58804. function createGraphDataProxyMixin(hostName, dataName) {
  58805. return {
  58806. /**
  58807. * @param Default 'value'. can be 'a', 'b', 'c', 'd', 'e'.
  58808. */
  58809. getValue: function (dimension) {
  58810. var data = this[hostName][dataName];
  58811. return data.getStore().get(data.getDimensionIndex(dimension || 'value'), this.dataIndex);
  58812. },
  58813. // TODO: TYPE stricter type.
  58814. setVisual: function (key, value) {
  58815. this.dataIndex >= 0 && this[hostName][dataName].setItemVisual(this.dataIndex, key, value);
  58816. },
  58817. getVisual: function (key) {
  58818. return this[hostName][dataName].getItemVisual(this.dataIndex, key);
  58819. },
  58820. setLayout: function (layout, merge) {
  58821. this.dataIndex >= 0 && this[hostName][dataName].setItemLayout(this.dataIndex, layout, merge);
  58822. },
  58823. getLayout: function () {
  58824. return this[hostName][dataName].getItemLayout(this.dataIndex);
  58825. },
  58826. getGraphicEl: function () {
  58827. return this[hostName][dataName].getItemGraphicEl(this.dataIndex);
  58828. },
  58829. getRawIndex: function () {
  58830. return this[hostName][dataName].getRawIndex(this.dataIndex);
  58831. }
  58832. };
  58833. }
  58834. mixin(GraphNode, createGraphDataProxyMixin('hostGraph', 'data'));
  58835. mixin(GraphEdge, createGraphDataProxyMixin('hostGraph', 'edgeData'));
  58836. function createGraphFromNodeEdge(nodes, edges, seriesModel, directed, beforeLink) {
  58837. // ??? TODO
  58838. // support dataset?
  58839. var graph = new Graph(directed);
  58840. for (var i = 0; i < nodes.length; i++) {
  58841. graph.addNode(retrieve(
  58842. // Id, name, dataIndex
  58843. nodes[i].id, nodes[i].name, i), i);
  58844. }
  58845. var linkNameList = [];
  58846. var validEdges = [];
  58847. var linkCount = 0;
  58848. for (var i = 0; i < edges.length; i++) {
  58849. var link = edges[i];
  58850. var source = link.source;
  58851. var target = link.target;
  58852. // addEdge may fail when source or target not exists
  58853. if (graph.addEdge(source, target, linkCount)) {
  58854. validEdges.push(link);
  58855. linkNameList.push(retrieve(convertOptionIdName(link.id, null), source + ' > ' + target));
  58856. linkCount++;
  58857. }
  58858. }
  58859. var coordSys = seriesModel.get('coordinateSystem');
  58860. var nodeData;
  58861. if (coordSys === 'cartesian2d' || coordSys === 'polar' || coordSys === 'matrix') {
  58862. nodeData = createSeriesData(nodes, seriesModel);
  58863. } else {
  58864. var coordSysCtor = CoordinateSystemManager.get(coordSys);
  58865. var coordDimensions = coordSysCtor ? coordSysCtor.dimensions || [] : [];
  58866. // FIXME: Some geo do not need `value` dimenson, whereas `calendar` needs
  58867. // `value` dimension, but graph need `value` dimension. It's better to
  58868. // uniform this behavior.
  58869. if (indexOf(coordDimensions, 'value') < 0) {
  58870. coordDimensions.concat(['value']);
  58871. }
  58872. var dimensions = prepareSeriesDataSchema(nodes, {
  58873. coordDimensions: coordDimensions,
  58874. encodeDefine: seriesModel.getEncode()
  58875. }).dimensions;
  58876. nodeData = new SeriesData(dimensions, seriesModel);
  58877. nodeData.initData(nodes);
  58878. }
  58879. var edgeData = new SeriesData(['value'], seriesModel);
  58880. edgeData.initData(validEdges, linkNameList);
  58881. beforeLink && beforeLink(nodeData, edgeData);
  58882. linkSeriesData({
  58883. mainData: nodeData,
  58884. struct: graph,
  58885. structAttr: 'graph',
  58886. datas: {
  58887. node: nodeData,
  58888. edge: edgeData
  58889. },
  58890. datasAttr: {
  58891. node: 'data',
  58892. edge: 'edgeData'
  58893. }
  58894. });
  58895. // Update dataIndex of nodes and edges because invalid edge may be removed
  58896. graph.update();
  58897. return graph;
  58898. }
  58899. var GraphSeriesModel = /** @class */function (_super) {
  58900. __extends(GraphSeriesModel, _super);
  58901. function GraphSeriesModel() {
  58902. var _this = _super !== null && _super.apply(this, arguments) || this;
  58903. _this.type = GraphSeriesModel.type;
  58904. _this.hasSymbolVisual = true;
  58905. return _this;
  58906. }
  58907. GraphSeriesModel.prototype.init = function (option) {
  58908. _super.prototype.init.apply(this, arguments);
  58909. var self = this;
  58910. function getCategoriesData() {
  58911. return self._categoriesData;
  58912. }
  58913. // Provide data for legend select
  58914. this.legendVisualProvider = new LegendVisualProvider(getCategoriesData, getCategoriesData);
  58915. this.fillDataTextStyle(option.edges || option.links);
  58916. this._updateCategoriesData();
  58917. };
  58918. GraphSeriesModel.prototype.mergeOption = function (option) {
  58919. _super.prototype.mergeOption.apply(this, arguments);
  58920. this.fillDataTextStyle(option.edges || option.links);
  58921. this._updateCategoriesData();
  58922. };
  58923. GraphSeriesModel.prototype.mergeDefaultAndTheme = function (option) {
  58924. _super.prototype.mergeDefaultAndTheme.apply(this, arguments);
  58925. defaultEmphasis(option, 'edgeLabel', ['show']);
  58926. };
  58927. GraphSeriesModel.prototype.getInitialData = function (option, ecModel) {
  58928. var edges = option.edges || option.links || [];
  58929. var nodes = option.data || option.nodes || [];
  58930. var self = this;
  58931. if (nodes && edges) {
  58932. // auto curveness
  58933. initCurvenessList(this);
  58934. var graph = createGraphFromNodeEdge(nodes, edges, this, true, beforeLink);
  58935. each(graph.edges, function (edge) {
  58936. createEdgeMapForCurveness(edge.node1, edge.node2, this, edge.dataIndex);
  58937. }, this);
  58938. return graph.data;
  58939. }
  58940. function beforeLink(nodeData, edgeData) {
  58941. // Overwrite nodeData.getItemModel to
  58942. nodeData.wrapMethod('getItemModel', function (model) {
  58943. var categoriesModels = self._categoriesModels;
  58944. var categoryIdx = model.getShallow('category');
  58945. var categoryModel = categoriesModels[categoryIdx];
  58946. if (categoryModel) {
  58947. categoryModel.parentModel = model.parentModel;
  58948. model.parentModel = categoryModel;
  58949. }
  58950. return model;
  58951. });
  58952. // TODO Inherit resolveParentPath by default in Model#getModel?
  58953. var oldGetModel = Model.prototype.getModel;
  58954. function newGetModel(path, parentModel) {
  58955. var model = oldGetModel.call(this, path, parentModel);
  58956. model.resolveParentPath = resolveParentPath;
  58957. return model;
  58958. }
  58959. edgeData.wrapMethod('getItemModel', function (model) {
  58960. model.resolveParentPath = resolveParentPath;
  58961. model.getModel = newGetModel;
  58962. return model;
  58963. });
  58964. function resolveParentPath(pathArr) {
  58965. if (pathArr && (pathArr[0] === 'label' || pathArr[1] === 'label')) {
  58966. var newPathArr = pathArr.slice();
  58967. if (pathArr[0] === 'label') {
  58968. newPathArr[0] = 'edgeLabel';
  58969. } else if (pathArr[1] === 'label') {
  58970. newPathArr[1] = 'edgeLabel';
  58971. }
  58972. return newPathArr;
  58973. }
  58974. return pathArr;
  58975. }
  58976. }
  58977. };
  58978. GraphSeriesModel.prototype.getGraph = function () {
  58979. return this.getData().graph;
  58980. };
  58981. GraphSeriesModel.prototype.getEdgeData = function () {
  58982. return this.getGraph().edgeData;
  58983. };
  58984. GraphSeriesModel.prototype.getCategoriesData = function () {
  58985. return this._categoriesData;
  58986. };
  58987. GraphSeriesModel.prototype.formatTooltip = function (dataIndex, multipleSeries, dataType) {
  58988. if (dataType === 'edge') {
  58989. var nodeData = this.getData();
  58990. var params = this.getDataParams(dataIndex, dataType);
  58991. var edge = nodeData.graph.getEdgeByIndex(dataIndex);
  58992. var sourceName = nodeData.getName(edge.node1.dataIndex);
  58993. var targetName = nodeData.getName(edge.node2.dataIndex);
  58994. var nameArr = [];
  58995. sourceName != null && nameArr.push(sourceName);
  58996. targetName != null && nameArr.push(targetName);
  58997. return createTooltipMarkup('nameValue', {
  58998. name: nameArr.join(' > '),
  58999. value: params.value,
  59000. noValue: params.value == null
  59001. });
  59002. }
  59003. // dataType === 'node' or empty
  59004. var nodeMarkup = defaultSeriesFormatTooltip({
  59005. series: this,
  59006. dataIndex: dataIndex,
  59007. multipleSeries: multipleSeries
  59008. });
  59009. return nodeMarkup;
  59010. };
  59011. GraphSeriesModel.prototype._updateCategoriesData = function () {
  59012. var categories = map(this.option.categories || [], function (category) {
  59013. // Data must has value
  59014. return category.value != null ? category : extend({
  59015. value: 0
  59016. }, category);
  59017. });
  59018. var categoriesData = new SeriesData(['value'], this);
  59019. categoriesData.initData(categories);
  59020. this._categoriesData = categoriesData;
  59021. this._categoriesModels = categoriesData.mapArray(function (idx) {
  59022. return categoriesData.getItemModel(idx);
  59023. });
  59024. };
  59025. GraphSeriesModel.prototype.setZoom = function (zoom) {
  59026. this.option.zoom = zoom;
  59027. };
  59028. GraphSeriesModel.prototype.setCenter = function (center) {
  59029. this.option.center = center;
  59030. };
  59031. GraphSeriesModel.prototype.isAnimationEnabled = function () {
  59032. return _super.prototype.isAnimationEnabled.call(this)
  59033. // Not enable animation when do force layout
  59034. && !(this.get('layout') === 'force' && this.get(['force', 'layoutAnimation']));
  59035. };
  59036. GraphSeriesModel.type = 'series.graph';
  59037. GraphSeriesModel.dependencies = ['grid', 'polar', 'geo', 'singleAxis', 'calendar'];
  59038. GraphSeriesModel.defaultOption = {
  59039. // zlevel: 0,
  59040. z: 2,
  59041. coordinateSystem: 'view',
  59042. // Default option for all coordinate systems
  59043. // xAxisIndex: 0,
  59044. // yAxisIndex: 0,
  59045. // polarIndex: 0,
  59046. // geoIndex: 0,
  59047. legendHoverLink: true,
  59048. layout: null,
  59049. // Configuration of circular layout
  59050. circular: {
  59051. rotateLabel: false
  59052. },
  59053. // Configuration of force directed layout
  59054. force: {
  59055. initLayout: null,
  59056. // Node repulsion. Can be an array to represent range.
  59057. repulsion: [0, 50],
  59058. gravity: 0.1,
  59059. // Initial friction
  59060. friction: 0.6,
  59061. // Edge length. Can be an array to represent range.
  59062. edgeLength: 30,
  59063. layoutAnimation: true
  59064. },
  59065. left: 'center',
  59066. top: 'center',
  59067. // right: null,
  59068. // bottom: null,
  59069. // width: '80%',
  59070. // height: '80%',
  59071. symbol: 'circle',
  59072. symbolSize: 10,
  59073. edgeSymbol: ['none', 'none'],
  59074. edgeSymbolSize: 10,
  59075. edgeLabel: {
  59076. position: 'middle',
  59077. distance: 5
  59078. },
  59079. draggable: false,
  59080. roam: false,
  59081. // Default on center of graph
  59082. center: null,
  59083. zoom: 1,
  59084. // Symbol size scale ratio in roam
  59085. nodeScaleRatio: 0.6,
  59086. // cursor: null,
  59087. // categories: [],
  59088. // data: []
  59089. // Or
  59090. // nodes: []
  59091. //
  59092. // links: []
  59093. // Or
  59094. // edges: []
  59095. label: {
  59096. show: false,
  59097. formatter: '{b}'
  59098. },
  59099. itemStyle: {},
  59100. lineStyle: {
  59101. // Don't use tokens.color.border because of the opacity
  59102. color: tokens.color.neutral50,
  59103. width: 1,
  59104. opacity: 0.5
  59105. },
  59106. emphasis: {
  59107. scale: true,
  59108. label: {
  59109. show: true
  59110. }
  59111. },
  59112. select: {
  59113. itemStyle: {
  59114. borderColor: tokens.color.primary
  59115. }
  59116. }
  59117. };
  59118. return GraphSeriesModel;
  59119. }(SeriesModel);
  59120. function install$d(registers) {
  59121. registers.registerChartView(GraphView);
  59122. registers.registerSeriesModel(GraphSeriesModel);
  59123. registers.registerProcessor(categoryFilter);
  59124. registers.registerVisual(categoryVisual);
  59125. registers.registerVisual(graphEdgeVisual);
  59126. registers.registerLayout(graphSimpleLayout);
  59127. registers.registerLayout(registers.PRIORITY.VISUAL.POST_CHART_LAYOUT, graphCircularLayout);
  59128. registers.registerLayout(graphForceLayout);
  59129. registers.registerCoordinateSystem('graphView', {
  59130. dimensions: View.dimensions,
  59131. create: createViewCoordSys
  59132. });
  59133. // Register legacy focus actions
  59134. registers.registerAction({
  59135. type: 'focusNodeAdjacency',
  59136. event: 'focusNodeAdjacency',
  59137. update: 'series:focusNodeAdjacency'
  59138. }, noop);
  59139. registers.registerAction({
  59140. type: 'unfocusNodeAdjacency',
  59141. event: 'unfocusNodeAdjacency',
  59142. update: 'series:unfocusNodeAdjacency'
  59143. }, noop);
  59144. // Register roam action.
  59145. registers.registerAction({
  59146. type: 'graphRoam',
  59147. event: 'graphRoam',
  59148. update: 'none'
  59149. }, function (payload, ecModel, api) {
  59150. ecModel.eachComponent({
  59151. mainType: 'series',
  59152. query: payload
  59153. }, function (seriesModel) {
  59154. var graphView = api.getViewOfSeriesModel(seriesModel);
  59155. if (graphView) {
  59156. if (payload.dx != null && payload.dy != null) {
  59157. graphView.updateViewOnPan(seriesModel, api, payload);
  59158. }
  59159. if (payload.zoom != null && payload.originX != null && payload.originY != null) {
  59160. graphView.updateViewOnZoom(seriesModel, api, payload);
  59161. }
  59162. }
  59163. var coordSys = seriesModel.coordinateSystem;
  59164. var res = updateCenterAndZoomInAction(coordSys, payload, seriesModel.get('scaleLimit'));
  59165. seriesModel.setCenter && seriesModel.setCenter(res.center);
  59166. seriesModel.setZoom && seriesModel.setZoom(res.zoom);
  59167. });
  59168. });
  59169. }
  59170. var ChordPiece = /** @class */function (_super) {
  59171. __extends(ChordPiece, _super);
  59172. function ChordPiece(data, idx, startAngle) {
  59173. var _this = _super.call(this) || this;
  59174. getECData(_this).dataType = 'node';
  59175. _this.z2 = 2;
  59176. var text = new ZRText();
  59177. _this.setTextContent(text);
  59178. _this.updateData(data, idx, startAngle, true);
  59179. return _this;
  59180. }
  59181. ChordPiece.prototype.updateData = function (data, idx, startAngle, firstCreate) {
  59182. var sector = this;
  59183. var node = data.graph.getNodeByIndex(idx);
  59184. var seriesModel = data.hostModel;
  59185. var itemModel = node.getModel();
  59186. var emphasisModel = itemModel.getModel('emphasis');
  59187. // layout position is the center of the sector
  59188. var layout = data.getItemLayout(idx);
  59189. var shape = extend(getSectorCornerRadius(itemModel.getModel('itemStyle'), layout, true), layout);
  59190. var el = this;
  59191. // Ignore NaN data.
  59192. if (isNaN(shape.startAngle)) {
  59193. // Use NaN shape to avoid drawing shape.
  59194. el.setShape(shape);
  59195. return;
  59196. }
  59197. if (firstCreate) {
  59198. el.setShape(shape);
  59199. } else {
  59200. updateProps(el, {
  59201. shape: shape
  59202. }, seriesModel, idx);
  59203. }
  59204. var sectorShape = extend(getSectorCornerRadius(itemModel.getModel('itemStyle'), layout, true), layout);
  59205. sector.setShape(sectorShape);
  59206. sector.useStyle(data.getItemVisual(idx, 'style'));
  59207. setStatesStylesFromModel(sector, itemModel);
  59208. this._updateLabel(seriesModel, itemModel, node);
  59209. data.setItemGraphicEl(idx, el);
  59210. setStatesStylesFromModel(el, itemModel, 'itemStyle');
  59211. // Add focus/blur states handling
  59212. var focus = emphasisModel.get('focus');
  59213. toggleHoverEmphasis(this, focus === 'adjacency' ? node.getAdjacentDataIndices() : focus, emphasisModel.get('blurScope'), emphasisModel.get('disabled'));
  59214. };
  59215. ChordPiece.prototype._updateLabel = function (seriesModel, itemModel, node) {
  59216. var label = this.getTextContent();
  59217. var layout = node.getLayout();
  59218. var midAngle = (layout.startAngle + layout.endAngle) / 2;
  59219. var dx = Math.cos(midAngle);
  59220. var dy = Math.sin(midAngle);
  59221. var normalLabelModel = itemModel.getModel('label');
  59222. label.ignore = !normalLabelModel.get('show');
  59223. // Set label style
  59224. var labelStateModels = getLabelStatesModels(itemModel);
  59225. var style = node.getVisual('style');
  59226. setLabelStyle(label, labelStateModels, {
  59227. labelFetcher: {
  59228. getFormattedLabel: function (dataIndex, stateName, dataType, labelDimIndex, formatter, extendParams) {
  59229. return seriesModel.getFormattedLabel(dataIndex, stateName, 'node', labelDimIndex,
  59230. // ensure edgeLabel formatter is provided
  59231. // to prevent the inheritance from `label.formatter` of the series
  59232. retrieve3(formatter, labelStateModels.normal && labelStateModels.normal.get('formatter'), itemModel.get('name')), extendParams);
  59233. }
  59234. },
  59235. labelDataIndex: node.dataIndex,
  59236. defaultText: node.dataIndex + '',
  59237. inheritColor: style.fill,
  59238. defaultOpacity: style.opacity,
  59239. defaultOutsidePosition: 'startArc'
  59240. });
  59241. // Set label position
  59242. var labelPosition = normalLabelModel.get('position') || 'outside';
  59243. var labelPadding = normalLabelModel.get('distance') || 0;
  59244. var r;
  59245. if (labelPosition === 'outside') {
  59246. r = layout.r + labelPadding;
  59247. } else {
  59248. r = (layout.r + layout.r0) / 2;
  59249. }
  59250. this.textConfig = {
  59251. inside: labelPosition !== 'outside'
  59252. };
  59253. var align = labelPosition !== 'outside' ? normalLabelModel.get('align') || 'center' : dx > 0 ? 'left' : 'right';
  59254. var verticalAlign = labelPosition !== 'outside' ? normalLabelModel.get('verticalAlign') || 'middle' : dy > 0 ? 'top' : 'bottom';
  59255. label.attr({
  59256. x: dx * r + layout.cx,
  59257. y: dy * r + layout.cy,
  59258. rotation: 0,
  59259. style: {
  59260. align: align,
  59261. verticalAlign: verticalAlign
  59262. }
  59263. });
  59264. };
  59265. return ChordPiece;
  59266. }(Sector);
  59267. var ChordEdge = /** @class */function (_super) {
  59268. __extends(ChordEdge, _super);
  59269. function ChordEdge(nodeData, edgeData, edgeIdx, startAngle) {
  59270. var _this = _super.call(this) || this;
  59271. getECData(_this).dataType = 'edge';
  59272. _this.updateData(nodeData, edgeData, edgeIdx, startAngle, true);
  59273. return _this;
  59274. }
  59275. ChordEdge.prototype.buildPath = function (ctx, shape) {
  59276. // Start from n11
  59277. ctx.moveTo(shape.s1[0], shape.s1[1]);
  59278. var ratio = 0.7;
  59279. var clockwise = shape.clockwise;
  59280. // Draw the arc from n11 to n12
  59281. ctx.arc(shape.cx, shape.cy, shape.r, shape.sStartAngle, shape.sEndAngle, !clockwise);
  59282. // Bezier curve to cp1 and then to n21
  59283. ctx.bezierCurveTo((shape.cx - shape.s2[0]) * ratio + shape.s2[0], (shape.cy - shape.s2[1]) * ratio + shape.s2[1], (shape.cx - shape.t1[0]) * ratio + shape.t1[0], (shape.cy - shape.t1[1]) * ratio + shape.t1[1], shape.t1[0], shape.t1[1]);
  59284. // Draw the arc from n21 to n22
  59285. ctx.arc(shape.cx, shape.cy, shape.r, shape.tStartAngle, shape.tEndAngle, !clockwise);
  59286. // Bezier curve back to cp2 and then to n11
  59287. ctx.bezierCurveTo((shape.cx - shape.t2[0]) * ratio + shape.t2[0], (shape.cy - shape.t2[1]) * ratio + shape.t2[1], (shape.cx - shape.s1[0]) * ratio + shape.s1[0], (shape.cy - shape.s1[1]) * ratio + shape.s1[1], shape.s1[0], shape.s1[1]);
  59288. ctx.closePath();
  59289. };
  59290. ChordEdge.prototype.updateData = function (nodeData, edgeData, edgeIdx, startAngle, firstCreate) {
  59291. var seriesModel = nodeData.hostModel;
  59292. var edge = edgeData.graph.getEdgeByIndex(edgeIdx);
  59293. var layout = edge.getLayout();
  59294. var itemModel = edge.node1.getModel();
  59295. var edgeModel = edgeData.getItemModel(edge.dataIndex);
  59296. var lineStyle = edgeModel.getModel('lineStyle');
  59297. var emphasisModel = edgeModel.getModel('emphasis');
  59298. var focus = emphasisModel.get('focus');
  59299. var shape = extend(getSectorCornerRadius(itemModel.getModel('itemStyle'), layout, true), layout);
  59300. var el = this;
  59301. // Ignore NaN data.
  59302. if (isNaN(shape.sStartAngle) || isNaN(shape.tStartAngle)) {
  59303. // Use NaN shape to avoid drawing shape.
  59304. el.setShape(shape);
  59305. return;
  59306. }
  59307. if (firstCreate) {
  59308. el.setShape(shape);
  59309. applyEdgeFill(el, edge, nodeData, lineStyle);
  59310. } else {
  59311. saveOldStyle(el);
  59312. applyEdgeFill(el, edge, nodeData, lineStyle);
  59313. updateProps(el, {
  59314. shape: shape
  59315. }, seriesModel, edgeIdx);
  59316. }
  59317. toggleHoverEmphasis(this, focus === 'adjacency' ? edge.getAdjacentDataIndices() : focus, emphasisModel.get('blurScope'), emphasisModel.get('disabled'));
  59318. setStatesStylesFromModel(el, edgeModel, 'lineStyle');
  59319. edgeData.setItemGraphicEl(edge.dataIndex, el);
  59320. };
  59321. return ChordEdge;
  59322. }(Path);
  59323. function applyEdgeFill(edgeShape, edge, nodeData, lineStyleModel) {
  59324. var node1 = edge.node1;
  59325. var node2 = edge.node2;
  59326. var edgeStyle = edgeShape.style;
  59327. edgeShape.setStyle(lineStyleModel.getLineStyle());
  59328. var color = lineStyleModel.get('color');
  59329. switch (color) {
  59330. case 'source':
  59331. // TODO: use visual and node1.getVisual('color');
  59332. edgeStyle.fill = nodeData.getItemVisual(node1.dataIndex, 'style').fill;
  59333. edgeStyle.decal = node1.getVisual('style').decal;
  59334. break;
  59335. case 'target':
  59336. edgeStyle.fill = nodeData.getItemVisual(node2.dataIndex, 'style').fill;
  59337. edgeStyle.decal = node2.getVisual('style').decal;
  59338. break;
  59339. case 'gradient':
  59340. var sourceColor = nodeData.getItemVisual(node1.dataIndex, 'style').fill;
  59341. var targetColor = nodeData.getItemVisual(node2.dataIndex, 'style').fill;
  59342. if (isString(sourceColor) && isString(targetColor)) {
  59343. // Gradient direction is perpendicular to the mid-angles
  59344. // of source and target nodes.
  59345. var shape = edgeShape.shape;
  59346. var sMidX = (shape.s1[0] + shape.s2[0]) / 2;
  59347. var sMidY = (shape.s1[1] + shape.s2[1]) / 2;
  59348. var tMidX = (shape.t1[0] + shape.t2[0]) / 2;
  59349. var tMidY = (shape.t1[1] + shape.t2[1]) / 2;
  59350. edgeStyle.fill = new LinearGradient(sMidX, sMidY, tMidX, tMidY, [{
  59351. offset: 0,
  59352. color: sourceColor
  59353. }, {
  59354. offset: 1,
  59355. color: targetColor
  59356. }], true);
  59357. }
  59358. break;
  59359. }
  59360. }
  59361. var RADIAN$2 = Math.PI / 180;
  59362. var ChordView = /** @class */function (_super) {
  59363. __extends(ChordView, _super);
  59364. function ChordView() {
  59365. var _this = _super !== null && _super.apply(this, arguments) || this;
  59366. _this.type = ChordView.type;
  59367. return _this;
  59368. }
  59369. ChordView.prototype.init = function (ecModel, api) {};
  59370. ChordView.prototype.render = function (seriesModel, ecModel, api) {
  59371. var data = seriesModel.getData();
  59372. var oldData = this._data;
  59373. var group = this.group;
  59374. var startAngle = -seriesModel.get('startAngle') * RADIAN$2;
  59375. data.diff(oldData).add(function (newIdx) {
  59376. /* Consider the case when there are only two nodes A and B,
  59377. * and there is a link between A and B.
  59378. * At first, they are both disselected from legend. And then
  59379. * when A is selected, A will go into `add` method. But since
  59380. * there are no edges to be displayed, A should not be added.
  59381. * So we should only add A when layout is defined.
  59382. */
  59383. var layout = data.getItemLayout(newIdx);
  59384. if (layout) {
  59385. var el = new ChordPiece(data, newIdx, startAngle);
  59386. getECData(el).dataIndex = newIdx;
  59387. group.add(el);
  59388. }
  59389. }).update(function (newIdx, oldIdx) {
  59390. var el = oldData.getItemGraphicEl(oldIdx);
  59391. var layout = data.getItemLayout(newIdx);
  59392. /* Consider the case when there are only two nodes A and B,
  59393. * and there is a link between A and B.
  59394. * and when A is disselected from legend, there should be
  59395. * nothing to display. But in the `data.diff` method, B will go
  59396. * into `update` method and having no layout.
  59397. * In this case, we need to remove B.
  59398. */
  59399. if (!layout) {
  59400. el && removeElementWithFadeOut(el, seriesModel, oldIdx);
  59401. return;
  59402. }
  59403. if (!el) {
  59404. el = new ChordPiece(data, newIdx, startAngle);
  59405. } else {
  59406. el.updateData(data, newIdx, startAngle);
  59407. }
  59408. group.add(el);
  59409. }).remove(function (oldIdx) {
  59410. var el = oldData.getItemGraphicEl(oldIdx);
  59411. el && removeElementWithFadeOut(el, seriesModel, oldIdx);
  59412. }).execute();
  59413. if (!oldData) {
  59414. var center = seriesModel.get('center');
  59415. this.group.scaleX = 0.01;
  59416. this.group.scaleY = 0.01;
  59417. this.group.originX = parsePercent$1(center[0], api.getWidth());
  59418. this.group.originY = parsePercent$1(center[1], api.getHeight());
  59419. initProps(this.group, {
  59420. scaleX: 1,
  59421. scaleY: 1
  59422. }, seriesModel);
  59423. }
  59424. this._data = data;
  59425. this.renderEdges(seriesModel, startAngle);
  59426. };
  59427. ChordView.prototype.renderEdges = function (seriesModel, startAngle) {
  59428. var nodeData = seriesModel.getData();
  59429. var edgeData = seriesModel.getEdgeData();
  59430. var oldData = this._edgeData;
  59431. var group = this.group;
  59432. edgeData.diff(oldData).add(function (newIdx) {
  59433. var el = new ChordEdge(nodeData, edgeData, newIdx, startAngle);
  59434. getECData(el).dataIndex = newIdx;
  59435. group.add(el);
  59436. }).update(function (newIdx, oldIdx) {
  59437. var el = oldData.getItemGraphicEl(oldIdx);
  59438. el.updateData(nodeData, edgeData, newIdx, startAngle);
  59439. group.add(el);
  59440. }).remove(function (oldIdx) {
  59441. var el = oldData.getItemGraphicEl(oldIdx);
  59442. el && removeElementWithFadeOut(el, seriesModel, oldIdx);
  59443. }).execute();
  59444. this._edgeData = edgeData;
  59445. };
  59446. ChordView.prototype.dispose = function () {};
  59447. ChordView.type = 'chord';
  59448. return ChordView;
  59449. }(ChartView);
  59450. var ChordSeriesModel = /** @class */function (_super) {
  59451. __extends(ChordSeriesModel, _super);
  59452. function ChordSeriesModel() {
  59453. var _this = _super !== null && _super.apply(this, arguments) || this;
  59454. _this.type = ChordSeriesModel.type;
  59455. return _this;
  59456. }
  59457. ChordSeriesModel.prototype.init = function (option) {
  59458. _super.prototype.init.apply(this, arguments);
  59459. this.fillDataTextStyle(option.edges || option.links);
  59460. // Enable legend selection for each data item
  59461. this.legendVisualProvider = new LegendVisualProvider(bind(this.getData, this), bind(this.getRawData, this));
  59462. };
  59463. ChordSeriesModel.prototype.mergeOption = function (option) {
  59464. _super.prototype.mergeOption.apply(this, arguments);
  59465. this.fillDataTextStyle(option.edges || option.links);
  59466. };
  59467. ChordSeriesModel.prototype.getInitialData = function (option, ecModel) {
  59468. var edges = option.edges || option.links || [];
  59469. var nodes = option.data || option.nodes || [];
  59470. if (nodes && edges) {
  59471. var graph = createGraphFromNodeEdge(nodes, edges, this, true, beforeLink);
  59472. return graph.data;
  59473. }
  59474. function beforeLink(nodeData, edgeData) {
  59475. // TODO Inherit resolveParentPath by default in Model#getModel?
  59476. var oldGetModel = Model.prototype.getModel;
  59477. function newGetModel(path, parentModel) {
  59478. var model = oldGetModel.call(this, path, parentModel);
  59479. model.resolveParentPath = resolveParentPath;
  59480. return model;
  59481. }
  59482. edgeData.wrapMethod('getItemModel', function (model) {
  59483. model.resolveParentPath = resolveParentPath;
  59484. model.getModel = newGetModel;
  59485. return model;
  59486. });
  59487. function resolveParentPath(pathArr) {
  59488. if (pathArr && (pathArr[0] === 'label' || pathArr[1] === 'label')) {
  59489. var newPathArr = pathArr.slice();
  59490. if (pathArr[0] === 'label') {
  59491. newPathArr[0] = 'edgeLabel';
  59492. } else if (pathArr[1] === 'label') {
  59493. newPathArr[1] = 'edgeLabel';
  59494. }
  59495. return newPathArr;
  59496. }
  59497. return pathArr;
  59498. }
  59499. }
  59500. };
  59501. ChordSeriesModel.prototype.getGraph = function () {
  59502. return this.getData().graph;
  59503. };
  59504. ChordSeriesModel.prototype.getEdgeData = function () {
  59505. return this.getGraph().edgeData;
  59506. };
  59507. ChordSeriesModel.prototype.formatTooltip = function (dataIndex, multipleSeries, dataType) {
  59508. var params = this.getDataParams(dataIndex, dataType);
  59509. if (dataType === 'edge') {
  59510. var nodeData = this.getData();
  59511. var edge = nodeData.graph.getEdgeByIndex(dataIndex);
  59512. var sourceName = nodeData.getName(edge.node1.dataIndex);
  59513. var targetName = nodeData.getName(edge.node2.dataIndex);
  59514. var nameArr = [];
  59515. sourceName != null && nameArr.push(sourceName);
  59516. targetName != null && nameArr.push(targetName);
  59517. return createTooltipMarkup('nameValue', {
  59518. name: nameArr.join(' > '),
  59519. value: params.value,
  59520. noValue: params.value == null
  59521. });
  59522. }
  59523. // dataType === 'node' or empty
  59524. return createTooltipMarkup('nameValue', {
  59525. name: params.name,
  59526. value: params.value,
  59527. noValue: params.value == null
  59528. });
  59529. };
  59530. ChordSeriesModel.prototype.getDataParams = function (dataIndex, dataType) {
  59531. var params = _super.prototype.getDataParams.call(this, dataIndex, dataType);
  59532. if (dataType === 'node') {
  59533. var nodeData = this.getData();
  59534. var node = this.getGraph().getNodeByIndex(dataIndex);
  59535. // Set name if not already set
  59536. if (params.name == null) {
  59537. params.name = nodeData.getName(dataIndex);
  59538. }
  59539. // Set value if not already set
  59540. if (params.value == null) {
  59541. var nodeValue = node.getLayout().value;
  59542. params.value = nodeValue;
  59543. }
  59544. }
  59545. return params;
  59546. };
  59547. ChordSeriesModel.type = 'series.chord';
  59548. ChordSeriesModel.defaultOption = {
  59549. // zlevel: 0,
  59550. z: 2,
  59551. coordinateSystem: 'none',
  59552. legendHoverLink: true,
  59553. colorBy: 'data',
  59554. left: 0,
  59555. top: 0,
  59556. right: 0,
  59557. bottom: 0,
  59558. width: null,
  59559. height: null,
  59560. center: ['50%', '50%'],
  59561. radius: ['70%', '80%'],
  59562. clockwise: true,
  59563. startAngle: 90,
  59564. endAngle: 'auto',
  59565. minAngle: 0,
  59566. padAngle: 3,
  59567. itemStyle: {
  59568. borderRadius: [0, 0, 5, 5]
  59569. },
  59570. lineStyle: {
  59571. width: 0,
  59572. color: 'source',
  59573. opacity: 0.2
  59574. },
  59575. label: {
  59576. show: true,
  59577. position: 'outside',
  59578. distance: 5
  59579. },
  59580. emphasis: {
  59581. focus: 'adjacency',
  59582. lineStyle: {
  59583. opacity: 0.5
  59584. }
  59585. }
  59586. };
  59587. return ChordSeriesModel;
  59588. }(SeriesModel);
  59589. var RADIAN$3 = Math.PI / 180;
  59590. function chordCircularLayout(ecModel, api) {
  59591. ecModel.eachSeriesByType('chord', function (seriesModel) {
  59592. chordLayout(seriesModel, api);
  59593. });
  59594. }
  59595. function chordLayout(seriesModel, api) {
  59596. var nodeData = seriesModel.getData();
  59597. var nodeGraph = nodeData.graph;
  59598. var edgeData = seriesModel.getEdgeData();
  59599. var edgeCount = edgeData.count();
  59600. if (!edgeCount) {
  59601. return;
  59602. }
  59603. var _a = getCircleLayout(seriesModel, api),
  59604. cx = _a.cx,
  59605. cy = _a.cy,
  59606. r = _a.r,
  59607. r0 = _a.r0;
  59608. var padAngle = Math.max((seriesModel.get('padAngle') || 0) * RADIAN$3, 0);
  59609. var minAngle = Math.max((seriesModel.get('minAngle') || 0) * RADIAN$3, 0);
  59610. var startAngle = -seriesModel.get('startAngle') * RADIAN$3;
  59611. var endAngle = startAngle + Math.PI * 2;
  59612. var clockwise = seriesModel.get('clockwise');
  59613. var dir = clockwise ? 1 : -1;
  59614. // Normalize angles
  59615. var angles = [startAngle, endAngle];
  59616. normalizeArcAngles(angles, !clockwise);
  59617. var normalizedStartAngle = angles[0],
  59618. normalizedEndAngle = angles[1];
  59619. var totalAngle = normalizedEndAngle - normalizedStartAngle;
  59620. var allZero = nodeData.getSum('value') === 0 && edgeData.getSum('value') === 0;
  59621. // Sum of each node's edge values
  59622. var nodeValues = [];
  59623. var renderedNodeCount = 0;
  59624. nodeGraph.eachEdge(function (edge) {
  59625. // All links use the same value 1 when allZero is true
  59626. var value = allZero ? 1 : edge.getValue('value');
  59627. if (allZero && (value > 0 || minAngle)) {
  59628. // When allZero is true, angle is in direct proportion to number
  59629. // of links both in and out of the node.
  59630. renderedNodeCount += 2;
  59631. }
  59632. var node1Index = edge.node1.dataIndex;
  59633. var node2Index = edge.node2.dataIndex;
  59634. nodeValues[node1Index] = (nodeValues[node1Index] || 0) + value;
  59635. nodeValues[node2Index] = (nodeValues[node2Index] || 0) + value;
  59636. });
  59637. // Update nodeValues with data.value if exists
  59638. var nodeValueSum = 0;
  59639. nodeGraph.eachNode(function (node) {
  59640. var dataValue = node.getValue('value');
  59641. if (!isNaN(dataValue)) {
  59642. nodeValues[node.dataIndex] = Math.max(dataValue, nodeValues[node.dataIndex] || 0);
  59643. }
  59644. if (!allZero && (nodeValues[node.dataIndex] > 0 || minAngle)) {
  59645. // When allZero is false, angle is in direct proportion to node's
  59646. // value
  59647. renderedNodeCount++;
  59648. }
  59649. nodeValueSum += nodeValues[node.dataIndex] || 0;
  59650. });
  59651. if (renderedNodeCount === 0 || nodeValueSum === 0) {
  59652. return;
  59653. }
  59654. if (padAngle * renderedNodeCount >= Math.abs(totalAngle)) {
  59655. // Not enough angle to render the pad, minAngle has higher priority, and padAngle takes the rest
  59656. padAngle = Math.max(0, (Math.abs(totalAngle) - minAngle * renderedNodeCount) / renderedNodeCount);
  59657. }
  59658. if ((padAngle + minAngle) * renderedNodeCount >= Math.abs(totalAngle)) {
  59659. // Not enough angle to render the minAngle, so ignore the minAngle
  59660. minAngle = (Math.abs(totalAngle) - padAngle * renderedNodeCount) / renderedNodeCount;
  59661. }
  59662. var unitAngle = (totalAngle - padAngle * renderedNodeCount * dir) / nodeValueSum;
  59663. var totalDeficit = 0; // sum of deficits of nodes with span < minAngle
  59664. var totalSurplus = 0; // sum of (spans - minAngle) of nodes with span > minAngle
  59665. var totalSurplusSpan = 0; // sum of spans of nodes with span > minAngle
  59666. nodeGraph.eachNode(function (node) {
  59667. var value = nodeValues[node.dataIndex] || 0;
  59668. var spanAngle = unitAngle * (nodeValueSum ? value : 1) * dir;
  59669. if (Math.abs(spanAngle) < minAngle) {
  59670. totalDeficit += minAngle - Math.abs(spanAngle);
  59671. } else {
  59672. totalSurplus += Math.abs(spanAngle) - minAngle;
  59673. totalSurplusSpan += Math.abs(spanAngle);
  59674. }
  59675. node.setLayout({
  59676. angle: spanAngle,
  59677. value: value
  59678. });
  59679. });
  59680. var surplusAsMuchAsPossible = false;
  59681. if (totalDeficit > totalSurplus) {
  59682. // Not enough angle to spread the nodes, scale all
  59683. var scale_1 = totalDeficit / totalSurplus;
  59684. nodeGraph.eachNode(function (node) {
  59685. var spanAngle = node.getLayout().angle;
  59686. if (Math.abs(spanAngle) >= minAngle) {
  59687. node.setLayout({
  59688. angle: spanAngle * scale_1,
  59689. ratio: scale_1
  59690. }, true);
  59691. } else {
  59692. node.setLayout({
  59693. angle: minAngle,
  59694. ratio: minAngle === 0 ? 1 : spanAngle / minAngle
  59695. }, true);
  59696. }
  59697. });
  59698. } else {
  59699. // For example, if totalDeficit is 60 degrees and totalSurplus is 70
  59700. // degrees but one of the sector can only reduced by 1 degree,
  59701. // if we decrease it with the ratio of value to other surplused nodes,
  59702. // it will have smaller angle than minAngle itself.
  59703. // So we need to borrow some angle from other nodes.
  59704. nodeGraph.eachNode(function (node) {
  59705. if (surplusAsMuchAsPossible) {
  59706. return;
  59707. }
  59708. var spanAngle = node.getLayout().angle;
  59709. var borrowRatio = Math.min(spanAngle / totalSurplusSpan, 1);
  59710. var borrowAngle = borrowRatio * totalDeficit;
  59711. if (spanAngle - borrowAngle < minAngle) {
  59712. // It will have less than minAngle after borrowing
  59713. surplusAsMuchAsPossible = true;
  59714. }
  59715. });
  59716. }
  59717. var restDeficit = totalDeficit;
  59718. nodeGraph.eachNode(function (node) {
  59719. if (restDeficit <= 0) {
  59720. return;
  59721. }
  59722. var spanAngle = node.getLayout().angle;
  59723. if (spanAngle > minAngle && minAngle > 0) {
  59724. var borrowRatio = surplusAsMuchAsPossible ? 1 : Math.min(spanAngle / totalSurplusSpan, 1);
  59725. var maxBorrowAngle = spanAngle - minAngle;
  59726. var borrowAngle = Math.min(maxBorrowAngle, Math.min(restDeficit, totalDeficit * borrowRatio));
  59727. restDeficit -= borrowAngle;
  59728. node.setLayout({
  59729. angle: spanAngle - borrowAngle,
  59730. ratio: (spanAngle - borrowAngle) / spanAngle
  59731. }, true);
  59732. } else if (minAngle > 0) {
  59733. node.setLayout({
  59734. angle: minAngle,
  59735. ratio: spanAngle === 0 ? 1 : minAngle / spanAngle
  59736. }, true);
  59737. }
  59738. });
  59739. var angle = normalizedStartAngle;
  59740. var edgeAccAngle = [];
  59741. nodeGraph.eachNode(function (node) {
  59742. var spanAngle = Math.max(node.getLayout().angle, minAngle);
  59743. node.setLayout({
  59744. cx: cx,
  59745. cy: cy,
  59746. r0: r0,
  59747. r: r,
  59748. startAngle: angle,
  59749. endAngle: angle + spanAngle * dir,
  59750. clockwise: clockwise
  59751. }, true);
  59752. edgeAccAngle[node.dataIndex] = angle;
  59753. angle += (spanAngle + padAngle) * dir;
  59754. });
  59755. nodeGraph.eachEdge(function (edge) {
  59756. var value = allZero ? 1 : edge.getValue('value');
  59757. var spanAngle = unitAngle * (nodeValueSum ? value : 1) * dir;
  59758. var node1Index = edge.node1.dataIndex;
  59759. var sStartAngle = edgeAccAngle[node1Index] || 0;
  59760. var sSpan = Math.abs((edge.node1.getLayout().ratio || 1) * spanAngle);
  59761. var sEndAngle = sStartAngle + sSpan * dir;
  59762. var s1 = [cx + r0 * Math.cos(sStartAngle), cy + r0 * Math.sin(sStartAngle)];
  59763. var s2 = [cx + r0 * Math.cos(sEndAngle), cy + r0 * Math.sin(sEndAngle)];
  59764. var node2Index = edge.node2.dataIndex;
  59765. var tStartAngle = edgeAccAngle[node2Index] || 0;
  59766. var tSpan = Math.abs((edge.node2.getLayout().ratio || 1) * spanAngle);
  59767. var tEndAngle = tStartAngle + tSpan * dir;
  59768. var t1 = [cx + r0 * Math.cos(tStartAngle), cy + r0 * Math.sin(tStartAngle)];
  59769. var t2 = [cx + r0 * Math.cos(tEndAngle), cy + r0 * Math.sin(tEndAngle)];
  59770. edge.setLayout({
  59771. s1: s1,
  59772. s2: s2,
  59773. sStartAngle: sStartAngle,
  59774. sEndAngle: sEndAngle,
  59775. t1: t1,
  59776. t2: t2,
  59777. tStartAngle: tStartAngle,
  59778. tEndAngle: tEndAngle,
  59779. cx: cx,
  59780. cy: cy,
  59781. r: r0,
  59782. value: value,
  59783. clockwise: clockwise
  59784. });
  59785. edgeAccAngle[node1Index] = sEndAngle;
  59786. edgeAccAngle[node2Index] = tEndAngle;
  59787. });
  59788. }
  59789. function install$e(registers) {
  59790. registers.registerChartView(ChordView);
  59791. registers.registerSeriesModel(ChordSeriesModel);
  59792. registers.registerLayout(registers.PRIORITY.VISUAL.POST_CHART_LAYOUT, chordCircularLayout);
  59793. // Add data filter processor
  59794. registers.registerProcessor(dataFilter('chord'));
  59795. }
  59796. var PointerShape = /** @class */function () {
  59797. function PointerShape() {
  59798. this.angle = 0;
  59799. this.width = 10;
  59800. this.r = 10;
  59801. this.x = 0;
  59802. this.y = 0;
  59803. }
  59804. return PointerShape;
  59805. }();
  59806. var PointerPath = /** @class */function (_super) {
  59807. __extends(PointerPath, _super);
  59808. function PointerPath(opts) {
  59809. var _this = _super.call(this, opts) || this;
  59810. _this.type = 'pointer';
  59811. return _this;
  59812. }
  59813. PointerPath.prototype.getDefaultShape = function () {
  59814. return new PointerShape();
  59815. };
  59816. PointerPath.prototype.buildPath = function (ctx, shape) {
  59817. var mathCos = Math.cos;
  59818. var mathSin = Math.sin;
  59819. var r = shape.r;
  59820. var width = shape.width;
  59821. var angle = shape.angle;
  59822. var x = shape.x - mathCos(angle) * width * (width >= r / 3 ? 1 : 2);
  59823. var y = shape.y - mathSin(angle) * width * (width >= r / 3 ? 1 : 2);
  59824. angle = shape.angle - Math.PI / 2;
  59825. ctx.moveTo(x, y);
  59826. ctx.lineTo(shape.x + mathCos(angle) * width, shape.y + mathSin(angle) * width);
  59827. ctx.lineTo(shape.x + mathCos(shape.angle) * r, shape.y + mathSin(shape.angle) * r);
  59828. ctx.lineTo(shape.x - mathCos(angle) * width, shape.y - mathSin(angle) * width);
  59829. ctx.lineTo(x, y);
  59830. };
  59831. return PointerPath;
  59832. }(Path);
  59833. function parsePosition(seriesModel, api) {
  59834. var center = seriesModel.get('center');
  59835. var width = api.getWidth();
  59836. var height = api.getHeight();
  59837. var size = Math.min(width, height);
  59838. var cx = parsePercent$1(center[0], api.getWidth());
  59839. var cy = parsePercent$1(center[1], api.getHeight());
  59840. var r = parsePercent$1(seriesModel.get('radius'), size / 2);
  59841. return {
  59842. cx: cx,
  59843. cy: cy,
  59844. r: r
  59845. };
  59846. }
  59847. function formatLabel(value, labelFormatter) {
  59848. var label = value == null ? '' : value + '';
  59849. if (labelFormatter) {
  59850. if (isString(labelFormatter)) {
  59851. label = labelFormatter.replace('{value}', label);
  59852. } else if (isFunction(labelFormatter)) {
  59853. label = labelFormatter(value);
  59854. }
  59855. }
  59856. return label;
  59857. }
  59858. var GaugeView = /** @class */function (_super) {
  59859. __extends(GaugeView, _super);
  59860. function GaugeView() {
  59861. var _this = _super !== null && _super.apply(this, arguments) || this;
  59862. _this.type = GaugeView.type;
  59863. return _this;
  59864. }
  59865. GaugeView.prototype.render = function (seriesModel, ecModel, api) {
  59866. this.group.removeAll();
  59867. var colorList = seriesModel.get(['axisLine', 'lineStyle', 'color']);
  59868. var posInfo = parsePosition(seriesModel, api);
  59869. this._renderMain(seriesModel, ecModel, api, colorList, posInfo);
  59870. this._data = seriesModel.getData();
  59871. };
  59872. GaugeView.prototype.dispose = function () {};
  59873. GaugeView.prototype._renderMain = function (seriesModel, ecModel, api, colorList, posInfo) {
  59874. var group = this.group;
  59875. var clockwise = seriesModel.get('clockwise');
  59876. var startAngle = -seriesModel.get('startAngle') / 180 * Math.PI;
  59877. var endAngle = -seriesModel.get('endAngle') / 180 * Math.PI;
  59878. var axisLineModel = seriesModel.getModel('axisLine');
  59879. var roundCap = axisLineModel.get('roundCap');
  59880. var MainPath = roundCap ? SausagePath : Sector;
  59881. var showAxis = axisLineModel.get('show');
  59882. var lineStyleModel = axisLineModel.getModel('lineStyle');
  59883. var axisLineWidth = lineStyleModel.get('width');
  59884. var angles = [startAngle, endAngle];
  59885. normalizeArcAngles(angles, !clockwise);
  59886. startAngle = angles[0];
  59887. endAngle = angles[1];
  59888. var angleRangeSpan = endAngle - startAngle;
  59889. var prevEndAngle = startAngle;
  59890. var sectors = [];
  59891. for (var i = 0; showAxis && i < colorList.length; i++) {
  59892. // Clamp
  59893. var percent = Math.min(Math.max(colorList[i][0], 0), 1);
  59894. endAngle = startAngle + angleRangeSpan * percent;
  59895. var sector = new MainPath({
  59896. shape: {
  59897. startAngle: prevEndAngle,
  59898. endAngle: endAngle,
  59899. cx: posInfo.cx,
  59900. cy: posInfo.cy,
  59901. clockwise: clockwise,
  59902. r0: posInfo.r - axisLineWidth,
  59903. r: posInfo.r
  59904. },
  59905. silent: true
  59906. });
  59907. sector.setStyle({
  59908. fill: colorList[i][1]
  59909. });
  59910. sector.setStyle(lineStyleModel.getLineStyle(
  59911. // Because we use sector to simulate arc
  59912. // so the properties for stroking are useless
  59913. ['color', 'width']));
  59914. sectors.push(sector);
  59915. prevEndAngle = endAngle;
  59916. }
  59917. sectors.reverse();
  59918. each(sectors, function (sector) {
  59919. return group.add(sector);
  59920. });
  59921. var getColor = function (percent) {
  59922. // Less than 0
  59923. if (percent <= 0) {
  59924. return colorList[0][1];
  59925. }
  59926. var i;
  59927. for (i = 0; i < colorList.length; i++) {
  59928. if (colorList[i][0] >= percent && (i === 0 ? 0 : colorList[i - 1][0]) < percent) {
  59929. return colorList[i][1];
  59930. }
  59931. }
  59932. // More than 1
  59933. return colorList[i - 1][1];
  59934. };
  59935. this._renderTicks(seriesModel, ecModel, api, getColor, posInfo, startAngle, endAngle, clockwise, axisLineWidth);
  59936. this._renderTitleAndDetail(seriesModel, ecModel, api, getColor, posInfo);
  59937. this._renderAnchor(seriesModel, posInfo);
  59938. this._renderPointer(seriesModel, ecModel, api, getColor, posInfo, startAngle, endAngle, clockwise, axisLineWidth);
  59939. };
  59940. GaugeView.prototype._renderTicks = function (seriesModel, ecModel, api, getColor, posInfo, startAngle, endAngle, clockwise, axisLineWidth) {
  59941. var group = this.group;
  59942. var cx = posInfo.cx;
  59943. var cy = posInfo.cy;
  59944. var r = posInfo.r;
  59945. var minVal = +seriesModel.get('min');
  59946. var maxVal = +seriesModel.get('max');
  59947. var splitLineModel = seriesModel.getModel('splitLine');
  59948. var tickModel = seriesModel.getModel('axisTick');
  59949. var labelModel = seriesModel.getModel('axisLabel');
  59950. var splitNumber = seriesModel.get('splitNumber');
  59951. var subSplitNumber = tickModel.get('splitNumber');
  59952. var splitLineLen = parsePercent$1(splitLineModel.get('length'), r);
  59953. var tickLen = parsePercent$1(tickModel.get('length'), r);
  59954. var angle = startAngle;
  59955. var step = (endAngle - startAngle) / splitNumber;
  59956. var subStep = step / subSplitNumber;
  59957. var splitLineStyle = splitLineModel.getModel('lineStyle').getLineStyle();
  59958. var tickLineStyle = tickModel.getModel('lineStyle').getLineStyle();
  59959. var splitLineDistance = splitLineModel.get('distance');
  59960. var unitX;
  59961. var unitY;
  59962. for (var i = 0; i <= splitNumber; i++) {
  59963. unitX = Math.cos(angle);
  59964. unitY = Math.sin(angle);
  59965. // Split line
  59966. if (splitLineModel.get('show')) {
  59967. var distance = splitLineDistance ? splitLineDistance + axisLineWidth : axisLineWidth;
  59968. var splitLine = new Line({
  59969. shape: {
  59970. x1: unitX * (r - distance) + cx,
  59971. y1: unitY * (r - distance) + cy,
  59972. x2: unitX * (r - splitLineLen - distance) + cx,
  59973. y2: unitY * (r - splitLineLen - distance) + cy
  59974. },
  59975. style: splitLineStyle,
  59976. silent: true
  59977. });
  59978. if (splitLineStyle.stroke === 'auto') {
  59979. splitLine.setStyle({
  59980. stroke: getColor(i / splitNumber)
  59981. });
  59982. }
  59983. group.add(splitLine);
  59984. }
  59985. // Label
  59986. if (labelModel.get('show')) {
  59987. var distance = labelModel.get('distance') + splitLineDistance;
  59988. var label = formatLabel(round(i / splitNumber * (maxVal - minVal) + minVal), labelModel.get('formatter'));
  59989. var autoColor = getColor(i / splitNumber);
  59990. var textStyleX = unitX * (r - splitLineLen - distance) + cx;
  59991. var textStyleY = unitY * (r - splitLineLen - distance) + cy;
  59992. var rotateType = labelModel.get('rotate');
  59993. var rotate = 0;
  59994. if (rotateType === 'radial') {
  59995. rotate = -angle + 2 * Math.PI;
  59996. if (rotate > Math.PI / 2) {
  59997. rotate += Math.PI;
  59998. }
  59999. } else if (rotateType === 'tangential') {
  60000. rotate = -angle - Math.PI / 2;
  60001. } else if (isNumber(rotateType)) {
  60002. rotate = rotateType * Math.PI / 180;
  60003. }
  60004. if (rotate === 0) {
  60005. group.add(new ZRText({
  60006. style: createTextStyle(labelModel, {
  60007. text: label,
  60008. x: textStyleX,
  60009. y: textStyleY,
  60010. verticalAlign: unitY < -0.8 ? 'top' : unitY > 0.8 ? 'bottom' : 'middle',
  60011. align: unitX < -0.4 ? 'left' : unitX > 0.4 ? 'right' : 'center'
  60012. }, {
  60013. inheritColor: autoColor
  60014. }),
  60015. silent: true
  60016. }));
  60017. } else {
  60018. group.add(new ZRText({
  60019. style: createTextStyle(labelModel, {
  60020. text: label,
  60021. x: textStyleX,
  60022. y: textStyleY,
  60023. verticalAlign: 'middle',
  60024. align: 'center'
  60025. }, {
  60026. inheritColor: autoColor
  60027. }),
  60028. silent: true,
  60029. originX: textStyleX,
  60030. originY: textStyleY,
  60031. rotation: rotate
  60032. }));
  60033. }
  60034. }
  60035. // Axis tick
  60036. if (tickModel.get('show') && i !== splitNumber) {
  60037. var distance = tickModel.get('distance');
  60038. distance = distance ? distance + axisLineWidth : axisLineWidth;
  60039. for (var j = 0; j <= subSplitNumber; j++) {
  60040. unitX = Math.cos(angle);
  60041. unitY = Math.sin(angle);
  60042. var tickLine = new Line({
  60043. shape: {
  60044. x1: unitX * (r - distance) + cx,
  60045. y1: unitY * (r - distance) + cy,
  60046. x2: unitX * (r - tickLen - distance) + cx,
  60047. y2: unitY * (r - tickLen - distance) + cy
  60048. },
  60049. silent: true,
  60050. style: tickLineStyle
  60051. });
  60052. if (tickLineStyle.stroke === 'auto') {
  60053. tickLine.setStyle({
  60054. stroke: getColor((i + j / subSplitNumber) / splitNumber)
  60055. });
  60056. }
  60057. group.add(tickLine);
  60058. angle += subStep;
  60059. }
  60060. angle -= subStep;
  60061. } else {
  60062. angle += step;
  60063. }
  60064. }
  60065. };
  60066. GaugeView.prototype._renderPointer = function (seriesModel, ecModel, api, getColor, posInfo, startAngle, endAngle, clockwise, axisLineWidth) {
  60067. var group = this.group;
  60068. var oldData = this._data;
  60069. var oldProgressData = this._progressEls;
  60070. var progressList = [];
  60071. var showPointer = seriesModel.get(['pointer', 'show']);
  60072. var progressModel = seriesModel.getModel('progress');
  60073. var showProgress = progressModel.get('show');
  60074. var data = seriesModel.getData();
  60075. var valueDim = data.mapDimension('value');
  60076. var minVal = +seriesModel.get('min');
  60077. var maxVal = +seriesModel.get('max');
  60078. var valueExtent = [minVal, maxVal];
  60079. var angleExtent = [startAngle, endAngle];
  60080. function createPointer(idx, angle) {
  60081. var itemModel = data.getItemModel(idx);
  60082. var pointerModel = itemModel.getModel('pointer');
  60083. var pointerWidth = parsePercent$1(pointerModel.get('width'), posInfo.r);
  60084. var pointerLength = parsePercent$1(pointerModel.get('length'), posInfo.r);
  60085. var pointerStr = seriesModel.get(['pointer', 'icon']);
  60086. var pointerOffset = pointerModel.get('offsetCenter');
  60087. var pointerOffsetX = parsePercent$1(pointerOffset[0], posInfo.r);
  60088. var pointerOffsetY = parsePercent$1(pointerOffset[1], posInfo.r);
  60089. var pointerKeepAspect = pointerModel.get('keepAspect');
  60090. var pointer;
  60091. // not exist icon type will be set 'rect'
  60092. if (pointerStr) {
  60093. pointer = createSymbol(pointerStr, pointerOffsetX - pointerWidth / 2, pointerOffsetY - pointerLength, pointerWidth, pointerLength, null, pointerKeepAspect);
  60094. } else {
  60095. pointer = new PointerPath({
  60096. shape: {
  60097. angle: -Math.PI / 2,
  60098. width: pointerWidth,
  60099. r: pointerLength,
  60100. x: pointerOffsetX,
  60101. y: pointerOffsetY
  60102. }
  60103. });
  60104. }
  60105. pointer.rotation = -(angle + Math.PI / 2);
  60106. pointer.x = posInfo.cx;
  60107. pointer.y = posInfo.cy;
  60108. return pointer;
  60109. }
  60110. function createProgress(idx, endAngle) {
  60111. var roundCap = progressModel.get('roundCap');
  60112. var ProgressPath = roundCap ? SausagePath : Sector;
  60113. var isOverlap = progressModel.get('overlap');
  60114. var progressWidth = isOverlap ? progressModel.get('width') : axisLineWidth / data.count();
  60115. var r0 = isOverlap ? posInfo.r - progressWidth : posInfo.r - (idx + 1) * progressWidth;
  60116. var r = isOverlap ? posInfo.r : posInfo.r - idx * progressWidth;
  60117. var progress = new ProgressPath({
  60118. shape: {
  60119. startAngle: startAngle,
  60120. endAngle: endAngle,
  60121. cx: posInfo.cx,
  60122. cy: posInfo.cy,
  60123. clockwise: clockwise,
  60124. r0: r0,
  60125. r: r
  60126. }
  60127. });
  60128. isOverlap && (progress.z2 = linearMap(data.get(valueDim, idx), [minVal, maxVal], [100, 0], true));
  60129. return progress;
  60130. }
  60131. if (showProgress || showPointer) {
  60132. data.diff(oldData).add(function (idx) {
  60133. var val = data.get(valueDim, idx);
  60134. if (showPointer) {
  60135. var pointer = createPointer(idx, startAngle);
  60136. // TODO hide pointer on NaN value?
  60137. initProps(pointer, {
  60138. rotation: -((isNaN(+val) ? angleExtent[0] : linearMap(val, valueExtent, angleExtent, true)) + Math.PI / 2)
  60139. }, seriesModel);
  60140. group.add(pointer);
  60141. data.setItemGraphicEl(idx, pointer);
  60142. }
  60143. if (showProgress) {
  60144. var progress = createProgress(idx, startAngle);
  60145. var isClip = progressModel.get('clip');
  60146. initProps(progress, {
  60147. shape: {
  60148. endAngle: linearMap(val, valueExtent, angleExtent, isClip)
  60149. }
  60150. }, seriesModel);
  60151. group.add(progress);
  60152. // Add data index and series index for indexing the data by element
  60153. // Useful in tooltip
  60154. setCommonECData(seriesModel.seriesIndex, data.dataType, idx, progress);
  60155. progressList[idx] = progress;
  60156. }
  60157. }).update(function (newIdx, oldIdx) {
  60158. var val = data.get(valueDim, newIdx);
  60159. if (showPointer) {
  60160. var previousPointer = oldData.getItemGraphicEl(oldIdx);
  60161. var previousRotate = previousPointer ? previousPointer.rotation : startAngle;
  60162. var pointer = createPointer(newIdx, previousRotate);
  60163. pointer.rotation = previousRotate;
  60164. updateProps(pointer, {
  60165. rotation: -((isNaN(+val) ? angleExtent[0] : linearMap(val, valueExtent, angleExtent, true)) + Math.PI / 2)
  60166. }, seriesModel);
  60167. group.add(pointer);
  60168. data.setItemGraphicEl(newIdx, pointer);
  60169. }
  60170. if (showProgress) {
  60171. var previousProgress = oldProgressData[oldIdx];
  60172. var previousEndAngle = previousProgress ? previousProgress.shape.endAngle : startAngle;
  60173. var progress = createProgress(newIdx, previousEndAngle);
  60174. var isClip = progressModel.get('clip');
  60175. updateProps(progress, {
  60176. shape: {
  60177. endAngle: linearMap(val, valueExtent, angleExtent, isClip)
  60178. }
  60179. }, seriesModel);
  60180. group.add(progress);
  60181. // Add data index and series index for indexing the data by element
  60182. // Useful in tooltip
  60183. setCommonECData(seriesModel.seriesIndex, data.dataType, newIdx, progress);
  60184. progressList[newIdx] = progress;
  60185. }
  60186. }).execute();
  60187. data.each(function (idx) {
  60188. var itemModel = data.getItemModel(idx);
  60189. var emphasisModel = itemModel.getModel('emphasis');
  60190. var focus = emphasisModel.get('focus');
  60191. var blurScope = emphasisModel.get('blurScope');
  60192. var emphasisDisabled = emphasisModel.get('disabled');
  60193. if (showPointer) {
  60194. var pointer = data.getItemGraphicEl(idx);
  60195. var symbolStyle = data.getItemVisual(idx, 'style');
  60196. var visualColor = symbolStyle.fill;
  60197. if (pointer instanceof ZRImage) {
  60198. var pathStyle = pointer.style;
  60199. pointer.useStyle(extend({
  60200. image: pathStyle.image,
  60201. x: pathStyle.x,
  60202. y: pathStyle.y,
  60203. width: pathStyle.width,
  60204. height: pathStyle.height
  60205. }, symbolStyle));
  60206. } else {
  60207. pointer.useStyle(symbolStyle);
  60208. pointer.type !== 'pointer' && pointer.setColor(visualColor);
  60209. }
  60210. pointer.setStyle(itemModel.getModel(['pointer', 'itemStyle']).getItemStyle());
  60211. if (pointer.style.fill === 'auto') {
  60212. pointer.setStyle('fill', getColor(linearMap(data.get(valueDim, idx), valueExtent, [0, 1], true)));
  60213. }
  60214. pointer.z2EmphasisLift = 0;
  60215. setStatesStylesFromModel(pointer, itemModel);
  60216. toggleHoverEmphasis(pointer, focus, blurScope, emphasisDisabled);
  60217. }
  60218. if (showProgress) {
  60219. var progress = progressList[idx];
  60220. progress.useStyle(data.getItemVisual(idx, 'style'));
  60221. progress.setStyle(itemModel.getModel(['progress', 'itemStyle']).getItemStyle());
  60222. progress.z2EmphasisLift = 0;
  60223. setStatesStylesFromModel(progress, itemModel);
  60224. toggleHoverEmphasis(progress, focus, blurScope, emphasisDisabled);
  60225. }
  60226. });
  60227. this._progressEls = progressList;
  60228. }
  60229. };
  60230. GaugeView.prototype._renderAnchor = function (seriesModel, posInfo) {
  60231. var anchorModel = seriesModel.getModel('anchor');
  60232. var showAnchor = anchorModel.get('show');
  60233. if (showAnchor) {
  60234. var anchorSize = anchorModel.get('size');
  60235. var anchorType = anchorModel.get('icon');
  60236. var offsetCenter = anchorModel.get('offsetCenter');
  60237. var anchorKeepAspect = anchorModel.get('keepAspect');
  60238. var anchor = createSymbol(anchorType, posInfo.cx - anchorSize / 2 + parsePercent$1(offsetCenter[0], posInfo.r), posInfo.cy - anchorSize / 2 + parsePercent$1(offsetCenter[1], posInfo.r), anchorSize, anchorSize, null, anchorKeepAspect);
  60239. anchor.z2 = anchorModel.get('showAbove') ? 1 : 0;
  60240. anchor.setStyle(anchorModel.getModel('itemStyle').getItemStyle());
  60241. this.group.add(anchor);
  60242. }
  60243. };
  60244. GaugeView.prototype._renderTitleAndDetail = function (seriesModel, ecModel, api, getColor, posInfo) {
  60245. var _this = this;
  60246. var data = seriesModel.getData();
  60247. var valueDim = data.mapDimension('value');
  60248. var minVal = +seriesModel.get('min');
  60249. var maxVal = +seriesModel.get('max');
  60250. var contentGroup = new Group();
  60251. var newTitleEls = [];
  60252. var newDetailEls = [];
  60253. var hasAnimation = seriesModel.isAnimationEnabled();
  60254. var showPointerAbove = seriesModel.get(['pointer', 'showAbove']);
  60255. data.diff(this._data).add(function (idx) {
  60256. newTitleEls[idx] = new ZRText({
  60257. silent: true
  60258. });
  60259. newDetailEls[idx] = new ZRText({
  60260. silent: true
  60261. });
  60262. }).update(function (idx, oldIdx) {
  60263. newTitleEls[idx] = _this._titleEls[oldIdx];
  60264. newDetailEls[idx] = _this._detailEls[oldIdx];
  60265. }).execute();
  60266. data.each(function (idx) {
  60267. var itemModel = data.getItemModel(idx);
  60268. var value = data.get(valueDim, idx);
  60269. var itemGroup = new Group();
  60270. var autoColor = getColor(linearMap(value, [minVal, maxVal], [0, 1], true));
  60271. var itemTitleModel = itemModel.getModel('title');
  60272. if (itemTitleModel.get('show')) {
  60273. var titleOffsetCenter = itemTitleModel.get('offsetCenter');
  60274. var titleX = posInfo.cx + parsePercent$1(titleOffsetCenter[0], posInfo.r);
  60275. var titleY = posInfo.cy + parsePercent$1(titleOffsetCenter[1], posInfo.r);
  60276. var labelEl = newTitleEls[idx];
  60277. labelEl.attr({
  60278. z2: showPointerAbove ? 0 : 2,
  60279. style: createTextStyle(itemTitleModel, {
  60280. x: titleX,
  60281. y: titleY,
  60282. text: data.getName(idx),
  60283. align: 'center',
  60284. verticalAlign: 'middle'
  60285. }, {
  60286. inheritColor: autoColor
  60287. })
  60288. });
  60289. itemGroup.add(labelEl);
  60290. }
  60291. var itemDetailModel = itemModel.getModel('detail');
  60292. if (itemDetailModel.get('show')) {
  60293. var detailOffsetCenter = itemDetailModel.get('offsetCenter');
  60294. var detailX = posInfo.cx + parsePercent$1(detailOffsetCenter[0], posInfo.r);
  60295. var detailY = posInfo.cy + parsePercent$1(detailOffsetCenter[1], posInfo.r);
  60296. var width = parsePercent$1(itemDetailModel.get('width'), posInfo.r);
  60297. var height = parsePercent$1(itemDetailModel.get('height'), posInfo.r);
  60298. var detailColor = seriesModel.get(['progress', 'show']) ? data.getItemVisual(idx, 'style').fill : autoColor;
  60299. var labelEl = newDetailEls[idx];
  60300. var formatter_1 = itemDetailModel.get('formatter');
  60301. labelEl.attr({
  60302. z2: showPointerAbove ? 0 : 2,
  60303. style: createTextStyle(itemDetailModel, {
  60304. x: detailX,
  60305. y: detailY,
  60306. text: formatLabel(value, formatter_1),
  60307. width: isNaN(width) ? null : width,
  60308. height: isNaN(height) ? null : height,
  60309. align: 'center',
  60310. verticalAlign: 'middle'
  60311. }, {
  60312. inheritColor: detailColor
  60313. })
  60314. });
  60315. setLabelValueAnimation(labelEl, {
  60316. normal: itemDetailModel
  60317. }, value, function (value) {
  60318. return formatLabel(value, formatter_1);
  60319. });
  60320. hasAnimation && animateLabelValue(labelEl, idx, data, seriesModel, {
  60321. getFormattedLabel: function (labelDataIndex, status, dataType, labelDimIndex, fmt, extendParams) {
  60322. return formatLabel(extendParams ? extendParams.interpolatedValue : value, formatter_1);
  60323. }
  60324. });
  60325. itemGroup.add(labelEl);
  60326. }
  60327. contentGroup.add(itemGroup);
  60328. });
  60329. this.group.add(contentGroup);
  60330. this._titleEls = newTitleEls;
  60331. this._detailEls = newDetailEls;
  60332. };
  60333. GaugeView.type = 'gauge';
  60334. return GaugeView;
  60335. }(ChartView);
  60336. var GaugeSeriesModel = /** @class */function (_super) {
  60337. __extends(GaugeSeriesModel, _super);
  60338. function GaugeSeriesModel() {
  60339. var _this = _super !== null && _super.apply(this, arguments) || this;
  60340. _this.type = GaugeSeriesModel.type;
  60341. _this.visualStyleAccessPath = 'itemStyle';
  60342. return _this;
  60343. }
  60344. GaugeSeriesModel.prototype.getInitialData = function (option, ecModel) {
  60345. return createSeriesDataSimply(this, ['value']);
  60346. };
  60347. GaugeSeriesModel.type = 'series.gauge';
  60348. GaugeSeriesModel.defaultOption = {
  60349. // zlevel: 0,
  60350. z: 2,
  60351. colorBy: 'data',
  60352. // 默认全局居中
  60353. center: ['50%', '50%'],
  60354. legendHoverLink: true,
  60355. radius: '75%',
  60356. startAngle: 225,
  60357. endAngle: -45,
  60358. clockwise: true,
  60359. // 最小值
  60360. min: 0,
  60361. // 最大值
  60362. max: 100,
  60363. // 分割段数,默认为10
  60364. splitNumber: 10,
  60365. // 坐标轴线
  60366. axisLine: {
  60367. // 默认显示,属性show控制显示与否
  60368. show: true,
  60369. roundCap: false,
  60370. lineStyle: {
  60371. color: [[1, tokens.color.neutral10]],
  60372. width: 10
  60373. }
  60374. },
  60375. // 坐标轴线
  60376. progress: {
  60377. // 默认显示,属性show控制显示与否
  60378. show: false,
  60379. overlap: true,
  60380. width: 10,
  60381. roundCap: false,
  60382. clip: true
  60383. },
  60384. // 分隔线
  60385. splitLine: {
  60386. // 默认显示,属性show控制显示与否
  60387. show: true,
  60388. // 属性length控制线长
  60389. length: 10,
  60390. distance: 10,
  60391. // 属性lineStyle(详见lineStyle)控制线条样式
  60392. lineStyle: {
  60393. color: tokens.color.axisTick,
  60394. width: 3,
  60395. type: 'solid'
  60396. }
  60397. },
  60398. // 坐标轴小标记
  60399. axisTick: {
  60400. // 属性show控制显示与否,默认不显示
  60401. show: true,
  60402. // 每份split细分多少段
  60403. splitNumber: 5,
  60404. // 属性length控制线长
  60405. length: 6,
  60406. distance: 10,
  60407. // 属性lineStyle控制线条样式
  60408. lineStyle: {
  60409. color: tokens.color.axisTickMinor,
  60410. width: 1,
  60411. type: 'solid'
  60412. }
  60413. },
  60414. axisLabel: {
  60415. show: true,
  60416. distance: 15,
  60417. // formatter: null,
  60418. color: tokens.color.axisLabel,
  60419. fontSize: 12,
  60420. rotate: 0
  60421. },
  60422. pointer: {
  60423. icon: null,
  60424. offsetCenter: [0, 0],
  60425. show: true,
  60426. showAbove: true,
  60427. length: '60%',
  60428. width: 6,
  60429. keepAspect: false
  60430. },
  60431. anchor: {
  60432. show: false,
  60433. showAbove: false,
  60434. size: 6,
  60435. icon: 'circle',
  60436. offsetCenter: [0, 0],
  60437. keepAspect: false,
  60438. itemStyle: {
  60439. color: tokens.color.neutral00,
  60440. borderWidth: 0,
  60441. borderColor: tokens.color.theme[0]
  60442. }
  60443. },
  60444. title: {
  60445. show: true,
  60446. // x, y,单位px
  60447. offsetCenter: [0, '20%'],
  60448. // 其余属性默认使用全局文本样式,详见TEXTSTYLE
  60449. color: tokens.color.secondary,
  60450. fontSize: 16,
  60451. valueAnimation: false
  60452. },
  60453. detail: {
  60454. show: true,
  60455. backgroundColor: tokens.color.transparent,
  60456. borderWidth: 0,
  60457. borderColor: tokens.color.neutral40,
  60458. width: 100,
  60459. height: null,
  60460. padding: [5, 10],
  60461. // x, y,单位px
  60462. offsetCenter: [0, '40%'],
  60463. // formatter: null,
  60464. // 其余属性默认使用全局文本样式,详见TEXTSTYLE
  60465. color: tokens.color.primary,
  60466. fontSize: 30,
  60467. fontWeight: 'bold',
  60468. lineHeight: 30,
  60469. valueAnimation: false
  60470. }
  60471. };
  60472. return GaugeSeriesModel;
  60473. }(SeriesModel);
  60474. function install$f(registers) {
  60475. registers.registerChartView(GaugeView);
  60476. registers.registerSeriesModel(GaugeSeriesModel);
  60477. }
  60478. var opacityAccessPath = ['itemStyle', 'opacity'];
  60479. /**
  60480. * Piece of pie including Sector, Label, LabelLine
  60481. */
  60482. var FunnelPiece = /** @class */function (_super) {
  60483. __extends(FunnelPiece, _super);
  60484. function FunnelPiece(data, idx) {
  60485. var _this = _super.call(this) || this;
  60486. var polygon = _this;
  60487. var labelLine = new Polyline();
  60488. var text = new ZRText();
  60489. polygon.setTextContent(text);
  60490. _this.setTextGuideLine(labelLine);
  60491. _this.updateData(data, idx, true);
  60492. return _this;
  60493. }
  60494. FunnelPiece.prototype.updateData = function (data, idx, firstCreate) {
  60495. var polygon = this;
  60496. var seriesModel = data.hostModel;
  60497. var itemModel = data.getItemModel(idx);
  60498. var layout = data.getItemLayout(idx);
  60499. var emphasisModel = itemModel.getModel('emphasis');
  60500. var opacity = itemModel.get(opacityAccessPath);
  60501. opacity = opacity == null ? 1 : opacity;
  60502. if (!firstCreate) {
  60503. saveOldStyle(polygon);
  60504. }
  60505. // Update common style
  60506. polygon.useStyle(data.getItemVisual(idx, 'style'));
  60507. polygon.style.lineJoin = 'round';
  60508. if (firstCreate) {
  60509. polygon.setShape({
  60510. points: layout.points
  60511. });
  60512. polygon.style.opacity = 0;
  60513. initProps(polygon, {
  60514. style: {
  60515. opacity: opacity
  60516. }
  60517. }, seriesModel, idx);
  60518. } else {
  60519. updateProps(polygon, {
  60520. style: {
  60521. opacity: opacity
  60522. },
  60523. shape: {
  60524. points: layout.points
  60525. }
  60526. }, seriesModel, idx);
  60527. }
  60528. setStatesStylesFromModel(polygon, itemModel);
  60529. this._updateLabel(data, idx);
  60530. toggleHoverEmphasis(this, emphasisModel.get('focus'), emphasisModel.get('blurScope'), emphasisModel.get('disabled'));
  60531. };
  60532. FunnelPiece.prototype._updateLabel = function (data, idx) {
  60533. var polygon = this;
  60534. var labelLine = this.getTextGuideLine();
  60535. var labelText = polygon.getTextContent();
  60536. var seriesModel = data.hostModel;
  60537. var itemModel = data.getItemModel(idx);
  60538. var layout = data.getItemLayout(idx);
  60539. var labelLayout = layout.label;
  60540. var style = data.getItemVisual(idx, 'style');
  60541. var visualColor = style.fill;
  60542. setLabelStyle(
  60543. // position will not be used in setLabelStyle
  60544. labelText, getLabelStatesModels(itemModel), {
  60545. labelFetcher: data.hostModel,
  60546. labelDataIndex: idx,
  60547. defaultOpacity: style.opacity,
  60548. defaultText: data.getName(idx)
  60549. }, {
  60550. normal: {
  60551. align: labelLayout.textAlign,
  60552. verticalAlign: labelLayout.verticalAlign
  60553. }
  60554. });
  60555. var labelModel = itemModel.getModel('label');
  60556. var labelColor = labelModel.get('color');
  60557. var overrideColor = labelColor === 'inherit' ? visualColor : null;
  60558. polygon.setTextConfig({
  60559. local: true,
  60560. inside: !!labelLayout.inside,
  60561. insideStroke: overrideColor,
  60562. outsideFill: overrideColor
  60563. });
  60564. var linePoints = labelLayout.linePoints;
  60565. labelLine.setShape({
  60566. points: linePoints
  60567. });
  60568. polygon.textGuideLineConfig = {
  60569. anchor: linePoints ? new Point(linePoints[0][0], linePoints[0][1]) : null
  60570. };
  60571. // Make sure update style on labelText after setLabelStyle.
  60572. // Because setLabelStyle will replace a new style on it.
  60573. updateProps(labelText, {
  60574. style: {
  60575. x: labelLayout.x,
  60576. y: labelLayout.y
  60577. }
  60578. }, seriesModel, idx);
  60579. labelText.attr({
  60580. rotation: labelLayout.rotation,
  60581. originX: labelLayout.x,
  60582. originY: labelLayout.y,
  60583. z2: 10
  60584. });
  60585. setLabelLineStyle(polygon, getLabelLineStatesModels(itemModel), {
  60586. // Default use item visual color
  60587. stroke: visualColor
  60588. });
  60589. };
  60590. return FunnelPiece;
  60591. }(Polygon);
  60592. var FunnelView = /** @class */function (_super) {
  60593. __extends(FunnelView, _super);
  60594. function FunnelView() {
  60595. var _this = _super !== null && _super.apply(this, arguments) || this;
  60596. _this.type = FunnelView.type;
  60597. _this.ignoreLabelLineUpdate = true;
  60598. return _this;
  60599. }
  60600. FunnelView.prototype.render = function (seriesModel, ecModel, api) {
  60601. var data = seriesModel.getData();
  60602. var oldData = this._data;
  60603. var group = this.group;
  60604. data.diff(oldData).add(function (idx) {
  60605. var funnelPiece = new FunnelPiece(data, idx);
  60606. data.setItemGraphicEl(idx, funnelPiece);
  60607. group.add(funnelPiece);
  60608. }).update(function (newIdx, oldIdx) {
  60609. var piece = oldData.getItemGraphicEl(oldIdx);
  60610. piece.updateData(data, newIdx);
  60611. group.add(piece);
  60612. data.setItemGraphicEl(newIdx, piece);
  60613. }).remove(function (idx) {
  60614. var piece = oldData.getItemGraphicEl(idx);
  60615. removeElementWithFadeOut(piece, seriesModel, idx);
  60616. }).execute();
  60617. this._data = data;
  60618. };
  60619. FunnelView.prototype.remove = function () {
  60620. this.group.removeAll();
  60621. this._data = null;
  60622. };
  60623. FunnelView.prototype.dispose = function () {};
  60624. FunnelView.type = 'funnel';
  60625. return FunnelView;
  60626. }(ChartView);
  60627. var FunnelSeriesModel = /** @class */function (_super) {
  60628. __extends(FunnelSeriesModel, _super);
  60629. function FunnelSeriesModel() {
  60630. var _this = _super !== null && _super.apply(this, arguments) || this;
  60631. _this.type = FunnelSeriesModel.type;
  60632. return _this;
  60633. }
  60634. FunnelSeriesModel.prototype.init = function (option) {
  60635. _super.prototype.init.apply(this, arguments);
  60636. // Enable legend selection for each data item
  60637. // Use a function instead of direct access because data reference may changed
  60638. this.legendVisualProvider = new LegendVisualProvider(bind(this.getData, this), bind(this.getRawData, this));
  60639. // Extend labelLine emphasis
  60640. this._defaultLabelLine(option);
  60641. };
  60642. FunnelSeriesModel.prototype.getInitialData = function (option, ecModel) {
  60643. return createSeriesDataSimply(this, {
  60644. coordDimensions: ['value'],
  60645. encodeDefaulter: curry(makeSeriesEncodeForNameBased, this)
  60646. });
  60647. };
  60648. FunnelSeriesModel.prototype._defaultLabelLine = function (option) {
  60649. // Extend labelLine emphasis
  60650. defaultEmphasis(option, 'labelLine', ['show']);
  60651. var labelLineNormalOpt = option.labelLine;
  60652. var labelLineEmphasisOpt = option.emphasis.labelLine;
  60653. // Not show label line if `label.normal.show = false`
  60654. labelLineNormalOpt.show = labelLineNormalOpt.show && option.label.show;
  60655. labelLineEmphasisOpt.show = labelLineEmphasisOpt.show && option.emphasis.label.show;
  60656. };
  60657. // Overwrite
  60658. FunnelSeriesModel.prototype.getDataParams = function (dataIndex) {
  60659. var data = this.getData();
  60660. var params = _super.prototype.getDataParams.call(this, dataIndex);
  60661. var valueDim = data.mapDimension('value');
  60662. var sum = data.getSum(valueDim);
  60663. // Percent is 0 if sum is 0
  60664. params.percent = !sum ? 0 : +(data.get(valueDim, dataIndex) / sum * 100).toFixed(2);
  60665. params.$vars.push('percent');
  60666. return params;
  60667. };
  60668. FunnelSeriesModel.type = 'series.funnel';
  60669. FunnelSeriesModel.defaultOption = {
  60670. coordinateSystemUsage: 'box',
  60671. // zlevel: 0, // 一级层叠
  60672. z: 2,
  60673. legendHoverLink: true,
  60674. colorBy: 'data',
  60675. left: 80,
  60676. top: 60,
  60677. right: 80,
  60678. bottom: 65,
  60679. // width: {totalWidth} - left - right,
  60680. // height: {totalHeight} - top - bottom,
  60681. // 默认取数据最小最大值
  60682. // min: 0,
  60683. // max: 100,
  60684. minSize: '0%',
  60685. maxSize: '100%',
  60686. sort: 'descending',
  60687. orient: 'vertical',
  60688. gap: 0,
  60689. funnelAlign: 'center',
  60690. label: {
  60691. show: true,
  60692. position: 'outer'
  60693. // formatter: 标签文本格式器,同Tooltip.formatter,不支持异步回调
  60694. },
  60695. labelLine: {
  60696. show: true,
  60697. length: 20,
  60698. lineStyle: {
  60699. // color: 各异,
  60700. width: 1
  60701. }
  60702. },
  60703. itemStyle: {
  60704. // color: 各异,
  60705. borderColor: tokens.color.neutral00,
  60706. borderWidth: 1
  60707. },
  60708. emphasis: {
  60709. label: {
  60710. show: true
  60711. }
  60712. },
  60713. select: {
  60714. itemStyle: {
  60715. borderColor: tokens.color.primary
  60716. }
  60717. }
  60718. };
  60719. return FunnelSeriesModel;
  60720. }(SeriesModel);
  60721. function getSortedIndices(data, sort) {
  60722. var valueDim = data.mapDimension('value');
  60723. var valueArr = data.mapArray(valueDim, function (val) {
  60724. return val;
  60725. });
  60726. var indices = [];
  60727. var isAscending = sort === 'ascending';
  60728. for (var i = 0, len = data.count(); i < len; i++) {
  60729. indices[i] = i;
  60730. }
  60731. // Add custom sortable function & none sortable opetion by "options.sort"
  60732. if (isFunction(sort)) {
  60733. indices.sort(sort);
  60734. } else if (sort !== 'none') {
  60735. indices.sort(function (a, b) {
  60736. return isAscending ? valueArr[a] - valueArr[b] : valueArr[b] - valueArr[a];
  60737. });
  60738. }
  60739. return indices;
  60740. }
  60741. function labelLayout(data) {
  60742. var seriesModel = data.hostModel;
  60743. var orient = seriesModel.get('orient');
  60744. data.each(function (idx) {
  60745. var itemModel = data.getItemModel(idx);
  60746. var labelModel = itemModel.getModel('label');
  60747. var labelPosition = labelModel.get('position');
  60748. var labelLineModel = itemModel.getModel('labelLine');
  60749. var layout = data.getItemLayout(idx);
  60750. var points = layout.points;
  60751. var isLabelInside = labelPosition === 'inner' || labelPosition === 'inside' || labelPosition === 'center' || labelPosition === 'insideLeft' || labelPosition === 'insideRight';
  60752. var textAlign;
  60753. var textX;
  60754. var textY;
  60755. var linePoints;
  60756. if (isLabelInside) {
  60757. if (labelPosition === 'insideLeft') {
  60758. textX = (points[0][0] + points[3][0]) / 2 + 5;
  60759. textY = (points[0][1] + points[3][1]) / 2;
  60760. textAlign = 'left';
  60761. } else if (labelPosition === 'insideRight') {
  60762. textX = (points[1][0] + points[2][0]) / 2 - 5;
  60763. textY = (points[1][1] + points[2][1]) / 2;
  60764. textAlign = 'right';
  60765. } else {
  60766. textX = (points[0][0] + points[1][0] + points[2][0] + points[3][0]) / 4;
  60767. textY = (points[0][1] + points[1][1] + points[2][1] + points[3][1]) / 4;
  60768. textAlign = 'center';
  60769. }
  60770. linePoints = [[textX, textY], [textX, textY]];
  60771. } else {
  60772. var x1 = void 0;
  60773. var y1 = void 0;
  60774. var x2 = void 0;
  60775. var y2 = void 0;
  60776. var labelLineLen = labelLineModel.get('length');
  60777. if ("development" !== 'production') {
  60778. if (orient === 'vertical' && ['top', 'bottom'].indexOf(labelPosition) > -1) {
  60779. labelPosition = 'left';
  60780. console.warn('Position error: Funnel chart on vertical orient dose not support top and bottom.');
  60781. }
  60782. if (orient === 'horizontal' && ['left', 'right'].indexOf(labelPosition) > -1) {
  60783. labelPosition = 'bottom';
  60784. console.warn('Position error: Funnel chart on horizontal orient dose not support left and right.');
  60785. }
  60786. }
  60787. if (labelPosition === 'left') {
  60788. // Left side
  60789. x1 = (points[3][0] + points[0][0]) / 2;
  60790. y1 = (points[3][1] + points[0][1]) / 2;
  60791. x2 = x1 - labelLineLen;
  60792. textX = x2 - 5;
  60793. textAlign = 'right';
  60794. } else if (labelPosition === 'right') {
  60795. // Right side
  60796. x1 = (points[1][0] + points[2][0]) / 2;
  60797. y1 = (points[1][1] + points[2][1]) / 2;
  60798. x2 = x1 + labelLineLen;
  60799. textX = x2 + 5;
  60800. textAlign = 'left';
  60801. } else if (labelPosition === 'top') {
  60802. // Top side
  60803. x1 = (points[3][0] + points[0][0]) / 2;
  60804. y1 = (points[3][1] + points[0][1]) / 2;
  60805. y2 = y1 - labelLineLen;
  60806. textY = y2 - 5;
  60807. textAlign = 'center';
  60808. } else if (labelPosition === 'bottom') {
  60809. // Bottom side
  60810. x1 = (points[1][0] + points[2][0]) / 2;
  60811. y1 = (points[1][1] + points[2][1]) / 2;
  60812. y2 = y1 + labelLineLen;
  60813. textY = y2 + 5;
  60814. textAlign = 'center';
  60815. } else if (labelPosition === 'rightTop') {
  60816. // RightTop side
  60817. x1 = orient === 'horizontal' ? points[3][0] : points[1][0];
  60818. y1 = orient === 'horizontal' ? points[3][1] : points[1][1];
  60819. if (orient === 'horizontal') {
  60820. y2 = y1 - labelLineLen;
  60821. textY = y2 - 5;
  60822. textAlign = 'center';
  60823. } else {
  60824. x2 = x1 + labelLineLen;
  60825. textX = x2 + 5;
  60826. textAlign = 'top';
  60827. }
  60828. } else if (labelPosition === 'rightBottom') {
  60829. // RightBottom side
  60830. x1 = points[2][0];
  60831. y1 = points[2][1];
  60832. if (orient === 'horizontal') {
  60833. y2 = y1 + labelLineLen;
  60834. textY = y2 + 5;
  60835. textAlign = 'center';
  60836. } else {
  60837. x2 = x1 + labelLineLen;
  60838. textX = x2 + 5;
  60839. textAlign = 'bottom';
  60840. }
  60841. } else if (labelPosition === 'leftTop') {
  60842. // LeftTop side
  60843. x1 = points[0][0];
  60844. y1 = orient === 'horizontal' ? points[0][1] : points[1][1];
  60845. if (orient === 'horizontal') {
  60846. y2 = y1 - labelLineLen;
  60847. textY = y2 - 5;
  60848. textAlign = 'center';
  60849. } else {
  60850. x2 = x1 - labelLineLen;
  60851. textX = x2 - 5;
  60852. textAlign = 'right';
  60853. }
  60854. } else if (labelPosition === 'leftBottom') {
  60855. // LeftBottom side
  60856. x1 = orient === 'horizontal' ? points[1][0] : points[3][0];
  60857. y1 = orient === 'horizontal' ? points[1][1] : points[2][1];
  60858. if (orient === 'horizontal') {
  60859. y2 = y1 + labelLineLen;
  60860. textY = y2 + 5;
  60861. textAlign = 'center';
  60862. } else {
  60863. x2 = x1 - labelLineLen;
  60864. textX = x2 - 5;
  60865. textAlign = 'right';
  60866. }
  60867. } else {
  60868. // Right side or Bottom side
  60869. x1 = (points[1][0] + points[2][0]) / 2;
  60870. y1 = (points[1][1] + points[2][1]) / 2;
  60871. if (orient === 'horizontal') {
  60872. y2 = y1 + labelLineLen;
  60873. textY = y2 + 5;
  60874. textAlign = 'center';
  60875. } else {
  60876. x2 = x1 + labelLineLen;
  60877. textX = x2 + 5;
  60878. textAlign = 'left';
  60879. }
  60880. }
  60881. if (orient === 'horizontal') {
  60882. x2 = x1;
  60883. textX = x2;
  60884. } else {
  60885. y2 = y1;
  60886. textY = y2;
  60887. }
  60888. linePoints = [[x1, y1], [x2, y2]];
  60889. }
  60890. layout.label = {
  60891. linePoints: linePoints,
  60892. x: textX,
  60893. y: textY,
  60894. verticalAlign: 'middle',
  60895. textAlign: textAlign,
  60896. inside: isLabelInside
  60897. };
  60898. });
  60899. }
  60900. function funnelLayout(ecModel, api) {
  60901. ecModel.eachSeriesByType('funnel', function (seriesModel) {
  60902. var data = seriesModel.getData();
  60903. var valueDim = data.mapDimension('value');
  60904. var sort = seriesModel.get('sort');
  60905. var layoutRef = createBoxLayoutReference(seriesModel, api);
  60906. var viewRect = getLayoutRect(seriesModel.getBoxLayoutParams(), layoutRef.refContainer);
  60907. var orient = seriesModel.get('orient');
  60908. var viewWidth = viewRect.width;
  60909. var viewHeight = viewRect.height;
  60910. var indices = getSortedIndices(data, sort);
  60911. var x = viewRect.x;
  60912. var y = viewRect.y;
  60913. var sizeExtent = orient === 'horizontal' ? [parsePercent$1(seriesModel.get('minSize'), viewHeight), parsePercent$1(seriesModel.get('maxSize'), viewHeight)] : [parsePercent$1(seriesModel.get('minSize'), viewWidth), parsePercent$1(seriesModel.get('maxSize'), viewWidth)];
  60914. var dataExtent = data.getDataExtent(valueDim);
  60915. var min = seriesModel.get('min');
  60916. var max = seriesModel.get('max');
  60917. if (min == null) {
  60918. min = Math.min(dataExtent[0], 0);
  60919. }
  60920. if (max == null) {
  60921. max = dataExtent[1];
  60922. }
  60923. var funnelAlign = seriesModel.get('funnelAlign');
  60924. var gap = seriesModel.get('gap');
  60925. var viewSize = orient === 'horizontal' ? viewWidth : viewHeight;
  60926. var itemSize = (viewSize - gap * (data.count() - 1)) / data.count();
  60927. var getLinePoints = function (idx, offset) {
  60928. // End point index is data.count() and we assign it 0
  60929. if (orient === 'horizontal') {
  60930. var val_1 = data.get(valueDim, idx) || 0;
  60931. var itemHeight = linearMap(val_1, [min, max], sizeExtent, true);
  60932. var y0 = void 0;
  60933. switch (funnelAlign) {
  60934. case 'top':
  60935. y0 = y;
  60936. break;
  60937. case 'center':
  60938. y0 = y + (viewHeight - itemHeight) / 2;
  60939. break;
  60940. case 'bottom':
  60941. y0 = y + (viewHeight - itemHeight);
  60942. break;
  60943. }
  60944. return [[offset, y0], [offset, y0 + itemHeight]];
  60945. }
  60946. var val = data.get(valueDim, idx) || 0;
  60947. var itemWidth = linearMap(val, [min, max], sizeExtent, true);
  60948. var x0;
  60949. switch (funnelAlign) {
  60950. case 'left':
  60951. x0 = x;
  60952. break;
  60953. case 'center':
  60954. x0 = x + (viewWidth - itemWidth) / 2;
  60955. break;
  60956. case 'right':
  60957. x0 = x + viewWidth - itemWidth;
  60958. break;
  60959. }
  60960. return [[x0, offset], [x0 + itemWidth, offset]];
  60961. };
  60962. if (sort === 'ascending') {
  60963. // From bottom to top
  60964. itemSize = -itemSize;
  60965. gap = -gap;
  60966. if (orient === 'horizontal') {
  60967. x += viewWidth;
  60968. } else {
  60969. y += viewHeight;
  60970. }
  60971. indices = indices.reverse();
  60972. }
  60973. for (var i = 0; i < indices.length; i++) {
  60974. var idx = indices[i];
  60975. var nextIdx = indices[i + 1];
  60976. var itemModel = data.getItemModel(idx);
  60977. if (orient === 'horizontal') {
  60978. var width = itemModel.get(['itemStyle', 'width']);
  60979. if (width == null) {
  60980. width = itemSize;
  60981. } else {
  60982. width = parsePercent$1(width, viewWidth);
  60983. if (sort === 'ascending') {
  60984. width = -width;
  60985. }
  60986. }
  60987. var start = getLinePoints(idx, x);
  60988. var end = getLinePoints(nextIdx, x + width);
  60989. x += width + gap;
  60990. data.setItemLayout(idx, {
  60991. points: start.concat(end.slice().reverse())
  60992. });
  60993. } else {
  60994. var height = itemModel.get(['itemStyle', 'height']);
  60995. if (height == null) {
  60996. height = itemSize;
  60997. } else {
  60998. height = parsePercent$1(height, viewHeight);
  60999. if (sort === 'ascending') {
  61000. height = -height;
  61001. }
  61002. }
  61003. var start = getLinePoints(idx, y);
  61004. var end = getLinePoints(nextIdx, y + height);
  61005. y += height + gap;
  61006. data.setItemLayout(idx, {
  61007. points: start.concat(end.slice().reverse())
  61008. });
  61009. }
  61010. }
  61011. labelLayout(data);
  61012. });
  61013. }
  61014. function install$g(registers) {
  61015. registers.registerChartView(FunnelView);
  61016. registers.registerSeriesModel(FunnelSeriesModel);
  61017. registers.registerLayout(funnelLayout);
  61018. registers.registerProcessor(dataFilter('funnel'));
  61019. }
  61020. var DEFAULT_SMOOTH = 0.3;
  61021. var ParallelView = /** @class */function (_super) {
  61022. __extends(ParallelView, _super);
  61023. function ParallelView() {
  61024. var _this = _super !== null && _super.apply(this, arguments) || this;
  61025. _this.type = ParallelView.type;
  61026. _this._dataGroup = new Group();
  61027. _this._initialized = false;
  61028. return _this;
  61029. }
  61030. ParallelView.prototype.init = function () {
  61031. this.group.add(this._dataGroup);
  61032. };
  61033. /**
  61034. * @override
  61035. */
  61036. ParallelView.prototype.render = function (seriesModel, ecModel, api, payload) {
  61037. // Clear previously rendered progressive elements.
  61038. this._progressiveEls = null;
  61039. var dataGroup = this._dataGroup;
  61040. var data = seriesModel.getData();
  61041. var oldData = this._data;
  61042. var coordSys = seriesModel.coordinateSystem;
  61043. var dimensions = coordSys.dimensions;
  61044. var seriesScope = makeSeriesScope$2(seriesModel);
  61045. data.diff(oldData).add(add).update(update).remove(remove).execute();
  61046. function add(newDataIndex) {
  61047. var line = addEl(data, dataGroup, newDataIndex, dimensions, coordSys);
  61048. updateElCommon(line, data, newDataIndex, seriesScope);
  61049. }
  61050. function update(newDataIndex, oldDataIndex) {
  61051. var line = oldData.getItemGraphicEl(oldDataIndex);
  61052. var points = createLinePoints(data, newDataIndex, dimensions, coordSys);
  61053. data.setItemGraphicEl(newDataIndex, line);
  61054. updateProps(line, {
  61055. shape: {
  61056. points: points
  61057. }
  61058. }, seriesModel, newDataIndex);
  61059. saveOldStyle(line);
  61060. updateElCommon(line, data, newDataIndex, seriesScope);
  61061. }
  61062. function remove(oldDataIndex) {
  61063. var line = oldData.getItemGraphicEl(oldDataIndex);
  61064. dataGroup.remove(line);
  61065. }
  61066. // First create
  61067. if (!this._initialized) {
  61068. this._initialized = true;
  61069. var clipPath = createGridClipShape(coordSys, seriesModel, function () {
  61070. // Callback will be invoked immediately if there is no animation
  61071. setTimeout(function () {
  61072. dataGroup.removeClipPath();
  61073. });
  61074. });
  61075. dataGroup.setClipPath(clipPath);
  61076. }
  61077. this._data = data;
  61078. };
  61079. ParallelView.prototype.incrementalPrepareRender = function (seriesModel, ecModel, api) {
  61080. this._initialized = true;
  61081. this._data = null;
  61082. this._dataGroup.removeAll();
  61083. };
  61084. ParallelView.prototype.incrementalRender = function (taskParams, seriesModel, ecModel) {
  61085. var data = seriesModel.getData();
  61086. var coordSys = seriesModel.coordinateSystem;
  61087. var dimensions = coordSys.dimensions;
  61088. var seriesScope = makeSeriesScope$2(seriesModel);
  61089. var progressiveEls = this._progressiveEls = [];
  61090. for (var dataIndex = taskParams.start; dataIndex < taskParams.end; dataIndex++) {
  61091. var line = addEl(data, this._dataGroup, dataIndex, dimensions, coordSys);
  61092. line.incremental = true;
  61093. updateElCommon(line, data, dataIndex, seriesScope);
  61094. progressiveEls.push(line);
  61095. }
  61096. };
  61097. ParallelView.prototype.remove = function () {
  61098. this._dataGroup && this._dataGroup.removeAll();
  61099. this._data = null;
  61100. };
  61101. ParallelView.type = 'parallel';
  61102. return ParallelView;
  61103. }(ChartView);
  61104. function createGridClipShape(coordSys, seriesModel, cb) {
  61105. var parallelModel = coordSys.model;
  61106. var rect = coordSys.getRect();
  61107. var rectEl = new Rect({
  61108. shape: {
  61109. x: rect.x,
  61110. y: rect.y,
  61111. width: rect.width,
  61112. height: rect.height
  61113. }
  61114. });
  61115. var dim = parallelModel.get('layout') === 'horizontal' ? 'width' : 'height';
  61116. rectEl.setShape(dim, 0);
  61117. initProps(rectEl, {
  61118. shape: {
  61119. width: rect.width,
  61120. height: rect.height
  61121. }
  61122. }, seriesModel, cb);
  61123. return rectEl;
  61124. }
  61125. function createLinePoints(data, dataIndex, dimensions, coordSys) {
  61126. var points = [];
  61127. for (var i = 0; i < dimensions.length; i++) {
  61128. var dimName = dimensions[i];
  61129. var value = data.get(data.mapDimension(dimName), dataIndex);
  61130. if (!isEmptyValue(value, coordSys.getAxis(dimName).type)) {
  61131. points.push(coordSys.dataToPoint(value, dimName));
  61132. }
  61133. }
  61134. return points;
  61135. }
  61136. function addEl(data, dataGroup, dataIndex, dimensions, coordSys) {
  61137. var points = createLinePoints(data, dataIndex, dimensions, coordSys);
  61138. var line = new Polyline({
  61139. shape: {
  61140. points: points
  61141. },
  61142. // silent: true,
  61143. z2: 10
  61144. });
  61145. dataGroup.add(line);
  61146. data.setItemGraphicEl(dataIndex, line);
  61147. return line;
  61148. }
  61149. function makeSeriesScope$2(seriesModel) {
  61150. var smooth = seriesModel.get('smooth', true);
  61151. smooth === true && (smooth = DEFAULT_SMOOTH);
  61152. smooth = numericToNumber(smooth);
  61153. eqNaN(smooth) && (smooth = 0);
  61154. return {
  61155. smooth: smooth
  61156. };
  61157. }
  61158. function updateElCommon(el, data, dataIndex, seriesScope) {
  61159. el.useStyle(data.getItemVisual(dataIndex, 'style'));
  61160. el.style.fill = null;
  61161. el.setShape('smooth', seriesScope.smooth);
  61162. var itemModel = data.getItemModel(dataIndex);
  61163. var emphasisModel = itemModel.getModel('emphasis');
  61164. setStatesStylesFromModel(el, itemModel, 'lineStyle');
  61165. toggleHoverEmphasis(el, emphasisModel.get('focus'), emphasisModel.get('blurScope'), emphasisModel.get('disabled'));
  61166. }
  61167. // function simpleDiff(oldData, newData, dimensions) {
  61168. // let oldLen;
  61169. // if (!oldData
  61170. // || !oldData.__plProgressive
  61171. // || (oldLen = oldData.count()) !== newData.count()
  61172. // ) {
  61173. // return true;
  61174. // }
  61175. // let dimLen = dimensions.length;
  61176. // for (let i = 0; i < oldLen; i++) {
  61177. // for (let j = 0; j < dimLen; j++) {
  61178. // if (oldData.get(dimensions[j], i) !== newData.get(dimensions[j], i)) {
  61179. // return true;
  61180. // }
  61181. // }
  61182. // }
  61183. // return false;
  61184. // }
  61185. // FIXME put in common util?
  61186. function isEmptyValue(val, axisType) {
  61187. return axisType === 'category' ? val == null : val == null || isNaN(val); // axisType === 'value'
  61188. }
  61189. var ParallelSeriesModel = /** @class */function (_super) {
  61190. __extends(ParallelSeriesModel, _super);
  61191. function ParallelSeriesModel() {
  61192. var _this = _super !== null && _super.apply(this, arguments) || this;
  61193. _this.type = ParallelSeriesModel.type;
  61194. _this.visualStyleAccessPath = 'lineStyle';
  61195. _this.visualDrawType = 'stroke';
  61196. return _this;
  61197. }
  61198. ParallelSeriesModel.prototype.getInitialData = function (option, ecModel) {
  61199. return createSeriesData(null, this, {
  61200. useEncodeDefaulter: bind(makeDefaultEncode, null, this)
  61201. });
  61202. };
  61203. /**
  61204. * User can get data raw indices on 'axisAreaSelected' event received.
  61205. *
  61206. * @return Raw indices
  61207. */
  61208. ParallelSeriesModel.prototype.getRawIndicesByActiveState = function (activeState) {
  61209. var coordSys = this.coordinateSystem;
  61210. var data = this.getData();
  61211. var indices = [];
  61212. coordSys.eachActiveState(data, function (theActiveState, dataIndex) {
  61213. if (activeState === theActiveState) {
  61214. indices.push(data.getRawIndex(dataIndex));
  61215. }
  61216. });
  61217. return indices;
  61218. };
  61219. ParallelSeriesModel.type = 'series.parallel';
  61220. ParallelSeriesModel.dependencies = ['parallel'];
  61221. ParallelSeriesModel.defaultOption = {
  61222. // zlevel: 0,
  61223. z: 2,
  61224. coordinateSystem: 'parallel',
  61225. parallelIndex: 0,
  61226. label: {
  61227. show: false
  61228. },
  61229. inactiveOpacity: 0.05,
  61230. activeOpacity: 1,
  61231. lineStyle: {
  61232. width: 1,
  61233. opacity: 0.45,
  61234. type: 'solid'
  61235. },
  61236. emphasis: {
  61237. label: {
  61238. show: false
  61239. }
  61240. },
  61241. progressive: 500,
  61242. smooth: false,
  61243. animationEasing: 'linear'
  61244. };
  61245. return ParallelSeriesModel;
  61246. }(SeriesModel);
  61247. function makeDefaultEncode(seriesModel) {
  61248. // The mapping of parallelAxis dimension to data dimension can
  61249. // be specified in parallelAxis.option.dim. For example, if
  61250. // parallelAxis.option.dim is 'dim3', it mapping to the third
  61251. // dimension of data. But `data.encode` has higher priority.
  61252. // Moreover, parallelModel.dimension should not be regarded as data
  61253. // dimensions. Consider dimensions = ['dim4', 'dim2', 'dim6'];
  61254. var parallelModel = seriesModel.ecModel.getComponent('parallel', seriesModel.get('parallelIndex'));
  61255. if (!parallelModel) {
  61256. return;
  61257. }
  61258. var encodeDefine = {};
  61259. each(parallelModel.dimensions, function (axisDim) {
  61260. var dataDimIndex = convertDimNameToNumber(axisDim);
  61261. encodeDefine[axisDim] = dataDimIndex;
  61262. });
  61263. return encodeDefine;
  61264. }
  61265. function convertDimNameToNumber(dimName) {
  61266. return +dimName.replace('dim', '');
  61267. }
  61268. /*
  61269. * Licensed to the Apache Software Foundation (ASF) under one
  61270. * or more contributor license agreements. See the NOTICE file
  61271. * distributed with this work for additional information
  61272. * regarding copyright ownership. The ASF licenses this file
  61273. * to you under the Apache License, Version 2.0 (the
  61274. * "License"); you may not use this file except in compliance
  61275. * with the License. You may obtain a copy of the License at
  61276. *
  61277. * http://www.apache.org/licenses/LICENSE-2.0
  61278. *
  61279. * Unless required by applicable law or agreed to in writing,
  61280. * software distributed under the License is distributed on an
  61281. * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
  61282. * KIND, either express or implied. See the License for the
  61283. * specific language governing permissions and limitations
  61284. * under the License.
  61285. */
  61286. /**
  61287. * AUTO-GENERATED FILE. DO NOT MODIFY.
  61288. */
  61289. /*
  61290. * Licensed to the Apache Software Foundation (ASF) under one
  61291. * or more contributor license agreements. See the NOTICE file
  61292. * distributed with this work for additional information
  61293. * regarding copyright ownership. The ASF licenses this file
  61294. * to you under the Apache License, Version 2.0 (the
  61295. * "License"); you may not use this file except in compliance
  61296. * with the License. You may obtain a copy of the License at
  61297. *
  61298. * http://www.apache.org/licenses/LICENSE-2.0
  61299. *
  61300. * Unless required by applicable law or agreed to in writing,
  61301. * software distributed under the License is distributed on an
  61302. * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
  61303. * KIND, either express or implied. See the License for the
  61304. * specific language governing permissions and limitations
  61305. * under the License.
  61306. */
  61307. var opacityAccessPath$1 = ['lineStyle', 'opacity'];
  61308. var parallelVisual = {
  61309. seriesType: 'parallel',
  61310. reset: function (seriesModel, ecModel) {
  61311. var coordSys = seriesModel.coordinateSystem;
  61312. var opacityMap = {
  61313. normal: seriesModel.get(['lineStyle', 'opacity']),
  61314. active: seriesModel.get('activeOpacity'),
  61315. inactive: seriesModel.get('inactiveOpacity')
  61316. };
  61317. return {
  61318. progress: function (params, data) {
  61319. coordSys.eachActiveState(data, function (activeState, dataIndex) {
  61320. var opacity = opacityMap[activeState];
  61321. if (activeState === 'normal' && data.hasItemOption) {
  61322. var itemOpacity = data.getItemModel(dataIndex).get(opacityAccessPath$1, true);
  61323. itemOpacity != null && (opacity = itemOpacity);
  61324. }
  61325. var existsStyle = data.ensureUniqueItemVisual(dataIndex, 'style');
  61326. existsStyle.opacity = opacity;
  61327. }, params.start, params.end);
  61328. }
  61329. };
  61330. }
  61331. };
  61332. function parallelPreprocessor(option) {
  61333. createParallelIfNeeded(option);
  61334. mergeAxisOptionFromParallel(option);
  61335. }
  61336. /**
  61337. * Create a parallel coordinate if not exists.
  61338. * @inner
  61339. */
  61340. function createParallelIfNeeded(option) {
  61341. if (option.parallel) {
  61342. return;
  61343. }
  61344. var hasParallelSeries = false;
  61345. each(option.series, function (seriesOpt) {
  61346. if (seriesOpt && seriesOpt.type === 'parallel') {
  61347. hasParallelSeries = true;
  61348. }
  61349. });
  61350. if (hasParallelSeries) {
  61351. option.parallel = [{}];
  61352. }
  61353. }
  61354. /**
  61355. * Merge aixs definition from parallel option (if exists) to axis option.
  61356. * @inner
  61357. */
  61358. function mergeAxisOptionFromParallel(option) {
  61359. var axes = normalizeToArray(option.parallelAxis);
  61360. each(axes, function (axisOption) {
  61361. if (!isObject(axisOption)) {
  61362. return;
  61363. }
  61364. var parallelIndex = axisOption.parallelIndex || 0;
  61365. var parallelOption = normalizeToArray(option.parallel)[parallelIndex];
  61366. if (parallelOption && parallelOption.parallelAxisDefault) {
  61367. merge(axisOption, parallelOption.parallelAxisDefault, false);
  61368. }
  61369. });
  61370. }
  61371. var CLICK_THRESHOLD = 5; // > 4
  61372. var ParallelView$1 = /** @class */function (_super) {
  61373. __extends(ParallelView, _super);
  61374. function ParallelView() {
  61375. var _this = _super !== null && _super.apply(this, arguments) || this;
  61376. _this.type = ParallelView.type;
  61377. return _this;
  61378. }
  61379. ParallelView.prototype.render = function (parallelModel, ecModel, api) {
  61380. this._model = parallelModel;
  61381. this._api = api;
  61382. if (!this._handlers) {
  61383. this._handlers = {};
  61384. each(handlers, function (handler, eventName) {
  61385. api.getZr().on(eventName, this._handlers[eventName] = bind(handler, this));
  61386. }, this);
  61387. }
  61388. createOrUpdate(this, '_throttledDispatchExpand', parallelModel.get('axisExpandRate'), 'fixRate');
  61389. };
  61390. ParallelView.prototype.dispose = function (ecModel, api) {
  61391. clear(this, '_throttledDispatchExpand');
  61392. each(this._handlers, function (handler, eventName) {
  61393. api.getZr().off(eventName, handler);
  61394. });
  61395. this._handlers = null;
  61396. };
  61397. /**
  61398. * @internal
  61399. * @param {Object} [opt] If null, cancel the last action triggering for debounce.
  61400. */
  61401. ParallelView.prototype._throttledDispatchExpand = function (opt) {
  61402. this._dispatchExpand(opt);
  61403. };
  61404. /**
  61405. * @internal
  61406. */
  61407. ParallelView.prototype._dispatchExpand = function (opt) {
  61408. opt && this._api.dispatchAction(extend({
  61409. type: 'parallelAxisExpand'
  61410. }, opt));
  61411. };
  61412. ParallelView.type = 'parallel';
  61413. return ParallelView;
  61414. }(ComponentView);
  61415. var handlers = {
  61416. mousedown: function (e) {
  61417. if (checkTrigger(this, 'click')) {
  61418. this._mouseDownPoint = [e.offsetX, e.offsetY];
  61419. }
  61420. },
  61421. mouseup: function (e) {
  61422. var mouseDownPoint = this._mouseDownPoint;
  61423. if (checkTrigger(this, 'click') && mouseDownPoint) {
  61424. var point = [e.offsetX, e.offsetY];
  61425. var dist = Math.pow(mouseDownPoint[0] - point[0], 2) + Math.pow(mouseDownPoint[1] - point[1], 2);
  61426. if (dist > CLICK_THRESHOLD) {
  61427. return;
  61428. }
  61429. var result = this._model.coordinateSystem.getSlidedAxisExpandWindow([e.offsetX, e.offsetY]);
  61430. result.behavior !== 'none' && this._dispatchExpand({
  61431. axisExpandWindow: result.axisExpandWindow
  61432. });
  61433. }
  61434. this._mouseDownPoint = null;
  61435. },
  61436. mousemove: function (e) {
  61437. // Should do nothing when brushing.
  61438. if (this._mouseDownPoint || !checkTrigger(this, 'mousemove')) {
  61439. return;
  61440. }
  61441. var model = this._model;
  61442. var result = model.coordinateSystem.getSlidedAxisExpandWindow([e.offsetX, e.offsetY]);
  61443. var behavior = result.behavior;
  61444. behavior === 'jump' && this._throttledDispatchExpand.debounceNextCall(model.get('axisExpandDebounce'));
  61445. this._throttledDispatchExpand(behavior === 'none' ? null // Cancel the last trigger, in case that mouse slide out of the area quickly.
  61446. : {
  61447. axisExpandWindow: result.axisExpandWindow,
  61448. // Jumping uses animation, and sliding suppresses animation.
  61449. animation: behavior === 'jump' ? null : {
  61450. duration: 0 // Disable animation.
  61451. }
  61452. });
  61453. }
  61454. };
  61455. function checkTrigger(view, triggerOn) {
  61456. var model = view._model;
  61457. return model.get('axisExpandable') && model.get('axisExpandTriggerOn') === triggerOn;
  61458. }
  61459. var ParallelModel = /** @class */function (_super) {
  61460. __extends(ParallelModel, _super);
  61461. function ParallelModel() {
  61462. var _this = _super !== null && _super.apply(this, arguments) || this;
  61463. _this.type = ParallelModel.type;
  61464. return _this;
  61465. }
  61466. ParallelModel.prototype.init = function () {
  61467. _super.prototype.init.apply(this, arguments);
  61468. this.mergeOption({});
  61469. };
  61470. ParallelModel.prototype.mergeOption = function (newOption) {
  61471. var thisOption = this.option;
  61472. newOption && merge(thisOption, newOption, true);
  61473. this._initDimensions();
  61474. };
  61475. /**
  61476. * Whether series or axis is in this coordinate system.
  61477. */
  61478. ParallelModel.prototype.contains = function (model, ecModel) {
  61479. var parallelIndex = model.get('parallelIndex');
  61480. return parallelIndex != null && ecModel.getComponent('parallel', parallelIndex) === this;
  61481. };
  61482. ParallelModel.prototype.setAxisExpand = function (opt) {
  61483. each(['axisExpandable', 'axisExpandCenter', 'axisExpandCount', 'axisExpandWidth', 'axisExpandWindow'], function (name) {
  61484. if (opt.hasOwnProperty(name)) {
  61485. // @ts-ignore FIXME: why "never" inferred in this.option[name]?
  61486. this.option[name] = opt[name];
  61487. }
  61488. }, this);
  61489. };
  61490. ParallelModel.prototype._initDimensions = function () {
  61491. var dimensions = this.dimensions = [];
  61492. var parallelAxisIndex = this.parallelAxisIndex = [];
  61493. var axisModels = filter(this.ecModel.queryComponents({
  61494. mainType: 'parallelAxis'
  61495. }), function (axisModel) {
  61496. // Can not use this.contains here, because
  61497. // initialization has not been completed yet.
  61498. return (axisModel.get('parallelIndex') || 0) === this.componentIndex;
  61499. }, this);
  61500. each(axisModels, function (axisModel) {
  61501. dimensions.push('dim' + axisModel.get('dim'));
  61502. parallelAxisIndex.push(axisModel.componentIndex);
  61503. });
  61504. };
  61505. ParallelModel.type = 'parallel';
  61506. ParallelModel.dependencies = ['parallelAxis'];
  61507. ParallelModel.layoutMode = 'box';
  61508. ParallelModel.defaultOption = {
  61509. // zlevel: 0,
  61510. z: 0,
  61511. left: 80,
  61512. top: 60,
  61513. right: 80,
  61514. bottom: 60,
  61515. // width: {totalWidth} - left - right,
  61516. // height: {totalHeight} - top - bottom,
  61517. layout: 'horizontal',
  61518. // FIXME
  61519. // naming?
  61520. axisExpandable: false,
  61521. axisExpandCenter: null,
  61522. axisExpandCount: 0,
  61523. axisExpandWidth: 50,
  61524. axisExpandRate: 17,
  61525. axisExpandDebounce: 50,
  61526. // [out, in, jumpTarget]. In percentage. If use [null, 0.05], null means full.
  61527. // Do not doc to user until necessary.
  61528. axisExpandSlideTriggerArea: [-0.15, 0.05, 0.4],
  61529. axisExpandTriggerOn: 'click',
  61530. parallelAxisDefault: null
  61531. };
  61532. return ParallelModel;
  61533. }(ComponentModel);
  61534. var ParallelAxis = /** @class */function (_super) {
  61535. __extends(ParallelAxis, _super);
  61536. function ParallelAxis(dim, scale, coordExtent, axisType, axisIndex) {
  61537. var _this = _super.call(this, dim, scale, coordExtent) || this;
  61538. _this.type = axisType || 'value';
  61539. _this.axisIndex = axisIndex;
  61540. return _this;
  61541. }
  61542. ParallelAxis.prototype.isHorizontal = function () {
  61543. return this.coordinateSystem.getModel().get('layout') !== 'horizontal';
  61544. };
  61545. return ParallelAxis;
  61546. }(Axis);
  61547. /*
  61548. * Licensed to the Apache Software Foundation (ASF) under one
  61549. * or more contributor license agreements. See the NOTICE file
  61550. * distributed with this work for additional information
  61551. * regarding copyright ownership. The ASF licenses this file
  61552. * to you under the Apache License, Version 2.0 (the
  61553. * "License"); you may not use this file except in compliance
  61554. * with the License. You may obtain a copy of the License at
  61555. *
  61556. * http://www.apache.org/licenses/LICENSE-2.0
  61557. *
  61558. * Unless required by applicable law or agreed to in writing,
  61559. * software distributed under the License is distributed on an
  61560. * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
  61561. * KIND, either express or implied. See the License for the
  61562. * specific language governing permissions and limitations
  61563. * under the License.
  61564. */
  61565. /**
  61566. * AUTO-GENERATED FILE. DO NOT MODIFY.
  61567. */
  61568. /*
  61569. * Licensed to the Apache Software Foundation (ASF) under one
  61570. * or more contributor license agreements. See the NOTICE file
  61571. * distributed with this work for additional information
  61572. * regarding copyright ownership. The ASF licenses this file
  61573. * to you under the Apache License, Version 2.0 (the
  61574. * "License"); you may not use this file except in compliance
  61575. * with the License. You may obtain a copy of the License at
  61576. *
  61577. * http://www.apache.org/licenses/LICENSE-2.0
  61578. *
  61579. * Unless required by applicable law or agreed to in writing,
  61580. * software distributed under the License is distributed on an
  61581. * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
  61582. * KIND, either express or implied. See the License for the
  61583. * specific language governing permissions and limitations
  61584. * under the License.
  61585. */
  61586. /**
  61587. * Calculate slider move result.
  61588. * Usage:
  61589. * (1) If both handle0 and handle1 are needed to be moved, set minSpan the same as
  61590. * maxSpan and the same as `Math.abs(handleEnd[1] - handleEnds[0])`.
  61591. * (2) If handle0 is forbidden to cross handle1, set minSpan as `0`.
  61592. *
  61593. * @param delta Move length.
  61594. * @param handleEnds handleEnds[0] can be bigger then handleEnds[1].
  61595. * handleEnds will be modified in this method.
  61596. * @param extent handleEnds is restricted by extent.
  61597. * extent[0] should less or equals than extent[1].
  61598. * @param handleIndex Can be 'all', means that both move the two handleEnds.
  61599. * @param minSpan The range of dataZoom can not be smaller than that.
  61600. * If not set, handle0 and cross handle1. If set as a non-negative
  61601. * number (including `0`), handles will push each other when reaching
  61602. * the minSpan.
  61603. * @param maxSpan The range of dataZoom can not be larger than that.
  61604. * @return The input handleEnds.
  61605. */
  61606. function sliderMove(delta, handleEnds, extent, handleIndex, minSpan, maxSpan) {
  61607. delta = delta || 0;
  61608. var extentSpan = extent[1] - extent[0];
  61609. // Notice maxSpan and minSpan can be null/undefined.
  61610. if (minSpan != null) {
  61611. minSpan = restrict(minSpan, [0, extentSpan]);
  61612. }
  61613. if (maxSpan != null) {
  61614. maxSpan = Math.max(maxSpan, minSpan != null ? minSpan : 0);
  61615. }
  61616. if (handleIndex === 'all') {
  61617. var handleSpan = Math.abs(handleEnds[1] - handleEnds[0]);
  61618. handleSpan = restrict(handleSpan, [0, extentSpan]);
  61619. minSpan = maxSpan = restrict(handleSpan, [minSpan, maxSpan]);
  61620. handleIndex = 0;
  61621. }
  61622. handleEnds[0] = restrict(handleEnds[0], extent);
  61623. handleEnds[1] = restrict(handleEnds[1], extent);
  61624. var originalDistSign = getSpanSign(handleEnds, handleIndex);
  61625. handleEnds[handleIndex] += delta;
  61626. // Restrict in extent.
  61627. var extentMinSpan = minSpan || 0;
  61628. var realExtent = extent.slice();
  61629. originalDistSign.sign < 0 ? realExtent[0] += extentMinSpan : realExtent[1] -= extentMinSpan;
  61630. handleEnds[handleIndex] = restrict(handleEnds[handleIndex], realExtent);
  61631. // Expand span.
  61632. var currDistSign;
  61633. currDistSign = getSpanSign(handleEnds, handleIndex);
  61634. if (minSpan != null && (currDistSign.sign !== originalDistSign.sign || currDistSign.span < minSpan)) {
  61635. // If minSpan exists, 'cross' is forbidden.
  61636. handleEnds[1 - handleIndex] = handleEnds[handleIndex] + originalDistSign.sign * minSpan;
  61637. }
  61638. // Shrink span.
  61639. currDistSign = getSpanSign(handleEnds, handleIndex);
  61640. if (maxSpan != null && currDistSign.span > maxSpan) {
  61641. handleEnds[1 - handleIndex] = handleEnds[handleIndex] + currDistSign.sign * maxSpan;
  61642. }
  61643. return handleEnds;
  61644. }
  61645. function getSpanSign(handleEnds, handleIndex) {
  61646. var dist = handleEnds[handleIndex] - handleEnds[1 - handleIndex];
  61647. // If `handleEnds[0] === handleEnds[1]`, always believe that handleEnd[0]
  61648. // is at left of handleEnds[1] for non-cross case.
  61649. return {
  61650. span: Math.abs(dist),
  61651. sign: dist > 0 ? -1 : dist < 0 ? 1 : handleIndex ? -1 : 1
  61652. };
  61653. }
  61654. function restrict(value, extend) {
  61655. return Math.min(extend[1] != null ? extend[1] : Infinity, Math.max(extend[0] != null ? extend[0] : -Infinity, value));
  61656. }
  61657. var each$5 = each;
  61658. var mathMin$9 = Math.min;
  61659. var mathMax$9 = Math.max;
  61660. var mathFloor$1 = Math.floor;
  61661. var mathCeil$1 = Math.ceil;
  61662. var round$3 = round;
  61663. var PI$7 = Math.PI;
  61664. var Parallel = /** @class */function () {
  61665. function Parallel(parallelModel, ecModel, api) {
  61666. this.type = 'parallel';
  61667. /**
  61668. * key: dimension
  61669. */
  61670. this._axesMap = createHashMap();
  61671. /**
  61672. * key: dimension
  61673. * value: {position: [], rotation, }
  61674. */
  61675. this._axesLayout = {};
  61676. this.dimensions = parallelModel.dimensions;
  61677. this._model = parallelModel;
  61678. this._init(parallelModel, ecModel, api);
  61679. }
  61680. Parallel.prototype._init = function (parallelModel, ecModel, api) {
  61681. var dimensions = parallelModel.dimensions;
  61682. var parallelAxisIndex = parallelModel.parallelAxisIndex;
  61683. each$5(dimensions, function (dim, idx) {
  61684. var axisIndex = parallelAxisIndex[idx];
  61685. var axisModel = ecModel.getComponent('parallelAxis', axisIndex);
  61686. var axis = this._axesMap.set(dim, new ParallelAxis(dim, createScaleByModel(axisModel), [0, 0], axisModel.get('type'), axisIndex));
  61687. var isCategory = axis.type === 'category';
  61688. axis.onBand = isCategory && axisModel.get('boundaryGap');
  61689. axis.inverse = axisModel.get('inverse');
  61690. // Injection
  61691. axisModel.axis = axis;
  61692. axis.model = axisModel;
  61693. axis.coordinateSystem = axisModel.coordinateSystem = this;
  61694. }, this);
  61695. };
  61696. /**
  61697. * Update axis scale after data processed
  61698. */
  61699. Parallel.prototype.update = function (ecModel, api) {
  61700. this._updateAxesFromSeries(this._model, ecModel);
  61701. };
  61702. Parallel.prototype.containPoint = function (point) {
  61703. var layoutInfo = this._makeLayoutInfo();
  61704. var axisBase = layoutInfo.axisBase;
  61705. var layoutBase = layoutInfo.layoutBase;
  61706. var pixelDimIndex = layoutInfo.pixelDimIndex;
  61707. var pAxis = point[1 - pixelDimIndex];
  61708. var pLayout = point[pixelDimIndex];
  61709. return pAxis >= axisBase && pAxis <= axisBase + layoutInfo.axisLength && pLayout >= layoutBase && pLayout <= layoutBase + layoutInfo.layoutLength;
  61710. };
  61711. Parallel.prototype.getModel = function () {
  61712. return this._model;
  61713. };
  61714. /**
  61715. * Update properties from series
  61716. */
  61717. Parallel.prototype._updateAxesFromSeries = function (parallelModel, ecModel) {
  61718. ecModel.eachSeries(function (seriesModel) {
  61719. if (!parallelModel.contains(seriesModel, ecModel)) {
  61720. return;
  61721. }
  61722. var data = seriesModel.getData();
  61723. each$5(this.dimensions, function (dim) {
  61724. var axis = this._axesMap.get(dim);
  61725. axis.scale.unionExtentFromData(data, data.mapDimension(dim));
  61726. niceScaleExtent(axis.scale, axis.model);
  61727. }, this);
  61728. }, this);
  61729. };
  61730. /**
  61731. * Resize the parallel coordinate system.
  61732. */
  61733. Parallel.prototype.resize = function (parallelModel, api) {
  61734. var refContainer = createBoxLayoutReference(parallelModel, api).refContainer;
  61735. this._rect = getLayoutRect(parallelModel.getBoxLayoutParams(), refContainer);
  61736. this._layoutAxes();
  61737. };
  61738. Parallel.prototype.getRect = function () {
  61739. return this._rect;
  61740. };
  61741. Parallel.prototype._makeLayoutInfo = function () {
  61742. var parallelModel = this._model;
  61743. var rect = this._rect;
  61744. var xy = ['x', 'y'];
  61745. var wh = ['width', 'height'];
  61746. var layout = parallelModel.get('layout');
  61747. var pixelDimIndex = layout === 'horizontal' ? 0 : 1;
  61748. var layoutLength = rect[wh[pixelDimIndex]];
  61749. var layoutExtent = [0, layoutLength];
  61750. var axisCount = this.dimensions.length;
  61751. var axisExpandWidth = restrict$1(parallelModel.get('axisExpandWidth'), layoutExtent);
  61752. var axisExpandCount = restrict$1(parallelModel.get('axisExpandCount') || 0, [0, axisCount]);
  61753. var axisExpandable = parallelModel.get('axisExpandable') && axisCount > 3 && axisCount > axisExpandCount && axisExpandCount > 1 && axisExpandWidth > 0 && layoutLength > 0;
  61754. // `axisExpandWindow` is According to the coordinates of [0, axisExpandLength],
  61755. // for sake of consider the case that axisCollapseWidth is 0 (when screen is narrow),
  61756. // where collapsed axes should be overlapped.
  61757. var axisExpandWindow = parallelModel.get('axisExpandWindow');
  61758. var winSize;
  61759. if (!axisExpandWindow) {
  61760. winSize = restrict$1(axisExpandWidth * (axisExpandCount - 1), layoutExtent);
  61761. var axisExpandCenter = parallelModel.get('axisExpandCenter') || mathFloor$1(axisCount / 2);
  61762. axisExpandWindow = [axisExpandWidth * axisExpandCenter - winSize / 2];
  61763. axisExpandWindow[1] = axisExpandWindow[0] + winSize;
  61764. } else {
  61765. winSize = restrict$1(axisExpandWindow[1] - axisExpandWindow[0], layoutExtent);
  61766. axisExpandWindow[1] = axisExpandWindow[0] + winSize;
  61767. }
  61768. var axisCollapseWidth = (layoutLength - winSize) / (axisCount - axisExpandCount);
  61769. // Avoid axisCollapseWidth is too small.
  61770. axisCollapseWidth < 3 && (axisCollapseWidth = 0);
  61771. // Find the first and last indices > ewin[0] and < ewin[1].
  61772. var winInnerIndices = [mathFloor$1(round$3(axisExpandWindow[0] / axisExpandWidth, 1)) + 1, mathCeil$1(round$3(axisExpandWindow[1] / axisExpandWidth, 1)) - 1];
  61773. // Pos in ec coordinates.
  61774. var axisExpandWindow0Pos = axisCollapseWidth / axisExpandWidth * axisExpandWindow[0];
  61775. return {
  61776. layout: layout,
  61777. pixelDimIndex: pixelDimIndex,
  61778. layoutBase: rect[xy[pixelDimIndex]],
  61779. layoutLength: layoutLength,
  61780. axisBase: rect[xy[1 - pixelDimIndex]],
  61781. axisLength: rect[wh[1 - pixelDimIndex]],
  61782. axisExpandable: axisExpandable,
  61783. axisExpandWidth: axisExpandWidth,
  61784. axisCollapseWidth: axisCollapseWidth,
  61785. axisExpandWindow: axisExpandWindow,
  61786. axisCount: axisCount,
  61787. winInnerIndices: winInnerIndices,
  61788. axisExpandWindow0Pos: axisExpandWindow0Pos
  61789. };
  61790. };
  61791. Parallel.prototype._layoutAxes = function () {
  61792. var rect = this._rect;
  61793. var axes = this._axesMap;
  61794. var dimensions = this.dimensions;
  61795. var layoutInfo = this._makeLayoutInfo();
  61796. var layout = layoutInfo.layout;
  61797. axes.each(function (axis) {
  61798. var axisExtent = [0, layoutInfo.axisLength];
  61799. var idx = axis.inverse ? 1 : 0;
  61800. axis.setExtent(axisExtent[idx], axisExtent[1 - idx]);
  61801. });
  61802. each$5(dimensions, function (dim, idx) {
  61803. var posInfo = (layoutInfo.axisExpandable ? layoutAxisWithExpand : layoutAxisWithoutExpand)(idx, layoutInfo);
  61804. var positionTable = {
  61805. horizontal: {
  61806. x: posInfo.position,
  61807. y: layoutInfo.axisLength
  61808. },
  61809. vertical: {
  61810. x: 0,
  61811. y: posInfo.position
  61812. }
  61813. };
  61814. var rotationTable = {
  61815. horizontal: PI$7 / 2,
  61816. vertical: 0
  61817. };
  61818. var position = [positionTable[layout].x + rect.x, positionTable[layout].y + rect.y];
  61819. var rotation = rotationTable[layout];
  61820. var transform = create$1();
  61821. rotate(transform, transform, rotation);
  61822. translate(transform, transform, position);
  61823. // TODO
  61824. // tick layout info
  61825. // TODO
  61826. // update dimensions info based on axis order.
  61827. this._axesLayout[dim] = {
  61828. position: position,
  61829. rotation: rotation,
  61830. transform: transform,
  61831. axisNameAvailableWidth: posInfo.axisNameAvailableWidth,
  61832. axisLabelShow: posInfo.axisLabelShow,
  61833. nameTruncateMaxWidth: posInfo.nameTruncateMaxWidth,
  61834. tickDirection: 1,
  61835. labelDirection: 1
  61836. };
  61837. }, this);
  61838. };
  61839. /**
  61840. * Get axis by dim.
  61841. */
  61842. Parallel.prototype.getAxis = function (dim) {
  61843. return this._axesMap.get(dim);
  61844. };
  61845. /**
  61846. * Convert a dim value of a single item of series data to Point.
  61847. */
  61848. Parallel.prototype.dataToPoint = function (value, dim) {
  61849. return this.axisCoordToPoint(this._axesMap.get(dim).dataToCoord(value), dim);
  61850. };
  61851. /**
  61852. * Travel data for one time, get activeState of each data item.
  61853. * @param start the start dataIndex that travel from.
  61854. * @param end the next dataIndex of the last dataIndex will be travel.
  61855. */
  61856. Parallel.prototype.eachActiveState = function (data, callback, start, end) {
  61857. start == null && (start = 0);
  61858. end == null && (end = data.count());
  61859. var axesMap = this._axesMap;
  61860. var dimensions = this.dimensions;
  61861. var dataDimensions = [];
  61862. var axisModels = [];
  61863. each(dimensions, function (axisDim) {
  61864. dataDimensions.push(data.mapDimension(axisDim));
  61865. axisModels.push(axesMap.get(axisDim).model);
  61866. });
  61867. var hasActiveSet = this.hasAxisBrushed();
  61868. for (var dataIndex = start; dataIndex < end; dataIndex++) {
  61869. var activeState = void 0;
  61870. if (!hasActiveSet) {
  61871. activeState = 'normal';
  61872. } else {
  61873. activeState = 'active';
  61874. var values = data.getValues(dataDimensions, dataIndex);
  61875. for (var j = 0, lenj = dimensions.length; j < lenj; j++) {
  61876. var state = axisModels[j].getActiveState(values[j]);
  61877. if (state === 'inactive') {
  61878. activeState = 'inactive';
  61879. break;
  61880. }
  61881. }
  61882. }
  61883. callback(activeState, dataIndex);
  61884. }
  61885. };
  61886. /**
  61887. * Whether has any activeSet.
  61888. */
  61889. Parallel.prototype.hasAxisBrushed = function () {
  61890. var dimensions = this.dimensions;
  61891. var axesMap = this._axesMap;
  61892. var hasActiveSet = false;
  61893. for (var j = 0, lenj = dimensions.length; j < lenj; j++) {
  61894. if (axesMap.get(dimensions[j]).model.getActiveState() !== 'normal') {
  61895. hasActiveSet = true;
  61896. }
  61897. }
  61898. return hasActiveSet;
  61899. };
  61900. /**
  61901. * Convert coords of each axis to Point.
  61902. * Return point. For example: [10, 20]
  61903. */
  61904. Parallel.prototype.axisCoordToPoint = function (coord, dim) {
  61905. var axisLayout = this._axesLayout[dim];
  61906. return applyTransform$1([coord, 0], axisLayout.transform);
  61907. };
  61908. /**
  61909. * Get axis layout.
  61910. */
  61911. Parallel.prototype.getAxisLayout = function (dim) {
  61912. return clone(this._axesLayout[dim]);
  61913. };
  61914. /**
  61915. * @return {Object} {axisExpandWindow, delta, behavior: 'jump' | 'slide' | 'none'}.
  61916. */
  61917. Parallel.prototype.getSlidedAxisExpandWindow = function (point) {
  61918. var layoutInfo = this._makeLayoutInfo();
  61919. var pixelDimIndex = layoutInfo.pixelDimIndex;
  61920. var axisExpandWindow = layoutInfo.axisExpandWindow.slice();
  61921. var winSize = axisExpandWindow[1] - axisExpandWindow[0];
  61922. var extent = [0, layoutInfo.axisExpandWidth * (layoutInfo.axisCount - 1)];
  61923. // Out of the area of coordinate system.
  61924. if (!this.containPoint(point)) {
  61925. return {
  61926. behavior: 'none',
  61927. axisExpandWindow: axisExpandWindow
  61928. };
  61929. }
  61930. // Convert the point from global to expand coordinates.
  61931. var pointCoord = point[pixelDimIndex] - layoutInfo.layoutBase - layoutInfo.axisExpandWindow0Pos;
  61932. // For dragging operation convenience, the window should not be
  61933. // slided when mouse is the center area of the window.
  61934. var delta;
  61935. var behavior = 'slide';
  61936. var axisCollapseWidth = layoutInfo.axisCollapseWidth;
  61937. var triggerArea = this._model.get('axisExpandSlideTriggerArea');
  61938. // But consider touch device, jump is necessary.
  61939. var useJump = triggerArea[0] != null;
  61940. if (axisCollapseWidth) {
  61941. if (useJump && axisCollapseWidth && pointCoord < winSize * triggerArea[0]) {
  61942. behavior = 'jump';
  61943. delta = pointCoord - winSize * triggerArea[2];
  61944. } else if (useJump && axisCollapseWidth && pointCoord > winSize * (1 - triggerArea[0])) {
  61945. behavior = 'jump';
  61946. delta = pointCoord - winSize * (1 - triggerArea[2]);
  61947. } else {
  61948. (delta = pointCoord - winSize * triggerArea[1]) >= 0 && (delta = pointCoord - winSize * (1 - triggerArea[1])) <= 0 && (delta = 0);
  61949. }
  61950. delta *= layoutInfo.axisExpandWidth / axisCollapseWidth;
  61951. delta ? sliderMove(delta, axisExpandWindow, extent, 'all')
  61952. // Avoid nonsense triger on mousemove.
  61953. : behavior = 'none';
  61954. }
  61955. // When screen is too narrow, make it visible and slidable, although it is hard to interact.
  61956. else {
  61957. var winSize2 = axisExpandWindow[1] - axisExpandWindow[0];
  61958. var pos = extent[1] * pointCoord / winSize2;
  61959. axisExpandWindow = [mathMax$9(0, pos - winSize2 / 2)];
  61960. axisExpandWindow[1] = mathMin$9(extent[1], axisExpandWindow[0] + winSize2);
  61961. axisExpandWindow[0] = axisExpandWindow[1] - winSize2;
  61962. }
  61963. return {
  61964. axisExpandWindow: axisExpandWindow,
  61965. behavior: behavior
  61966. };
  61967. };
  61968. return Parallel;
  61969. }();
  61970. function restrict$1(len, extent) {
  61971. return mathMin$9(mathMax$9(len, extent[0]), extent[1]);
  61972. }
  61973. function layoutAxisWithoutExpand(axisIndex, layoutInfo) {
  61974. var step = layoutInfo.layoutLength / (layoutInfo.axisCount - 1);
  61975. return {
  61976. position: step * axisIndex,
  61977. axisNameAvailableWidth: step,
  61978. axisLabelShow: true
  61979. };
  61980. }
  61981. function layoutAxisWithExpand(axisIndex, layoutInfo) {
  61982. var layoutLength = layoutInfo.layoutLength;
  61983. var axisExpandWidth = layoutInfo.axisExpandWidth;
  61984. var axisCount = layoutInfo.axisCount;
  61985. var axisCollapseWidth = layoutInfo.axisCollapseWidth;
  61986. var winInnerIndices = layoutInfo.winInnerIndices;
  61987. var position;
  61988. var axisNameAvailableWidth = axisCollapseWidth;
  61989. var axisLabelShow = false;
  61990. var nameTruncateMaxWidth;
  61991. if (axisIndex < winInnerIndices[0]) {
  61992. position = axisIndex * axisCollapseWidth;
  61993. nameTruncateMaxWidth = axisCollapseWidth;
  61994. } else if (axisIndex <= winInnerIndices[1]) {
  61995. position = layoutInfo.axisExpandWindow0Pos + axisIndex * axisExpandWidth - layoutInfo.axisExpandWindow[0];
  61996. axisNameAvailableWidth = axisExpandWidth;
  61997. axisLabelShow = true;
  61998. } else {
  61999. position = layoutLength - (axisCount - 1 - axisIndex) * axisCollapseWidth;
  62000. nameTruncateMaxWidth = axisCollapseWidth;
  62001. }
  62002. return {
  62003. position: position,
  62004. axisNameAvailableWidth: axisNameAvailableWidth,
  62005. axisLabelShow: axisLabelShow,
  62006. nameTruncateMaxWidth: nameTruncateMaxWidth
  62007. };
  62008. }
  62009. function createParallelCoordSys(ecModel, api) {
  62010. var coordSysList = [];
  62011. ecModel.eachComponent('parallel', function (parallelModel, idx) {
  62012. var coordSys = new Parallel(parallelModel, ecModel, api);
  62013. coordSys.name = 'parallel_' + idx;
  62014. coordSys.resize(parallelModel, api);
  62015. parallelModel.coordinateSystem = coordSys;
  62016. coordSys.model = parallelModel;
  62017. coordSysList.push(coordSys);
  62018. });
  62019. // Inject the coordinateSystems into seriesModel
  62020. ecModel.eachSeries(function (seriesModel) {
  62021. if (seriesModel.get('coordinateSystem') === 'parallel') {
  62022. var parallelModel = seriesModel.getReferringComponents('parallel', SINGLE_REFERRING).models[0];
  62023. seriesModel.coordinateSystem = parallelModel.coordinateSystem;
  62024. }
  62025. });
  62026. return coordSysList;
  62027. }
  62028. var parallelCoordSysCreator = {
  62029. create: createParallelCoordSys
  62030. };
  62031. var ParallelAxisModel = /** @class */function (_super) {
  62032. __extends(ParallelAxisModel, _super);
  62033. function ParallelAxisModel() {
  62034. var _this = _super !== null && _super.apply(this, arguments) || this;
  62035. _this.type = ParallelAxisModel.type;
  62036. /**
  62037. * @readOnly
  62038. */
  62039. _this.activeIntervals = [];
  62040. return _this;
  62041. }
  62042. ParallelAxisModel.prototype.getAreaSelectStyle = function () {
  62043. return makeStyleMapper([['fill', 'color'], ['lineWidth', 'borderWidth'], ['stroke', 'borderColor'], ['width', 'width'], ['opacity', 'opacity']
  62044. // Option decal is in `DecalObject` but style.decal is in `PatternObject`.
  62045. // So do not transfer decal directly.
  62046. ])(this.getModel('areaSelectStyle'));
  62047. };
  62048. /**
  62049. * The code of this feature is put on AxisModel but not ParallelAxis,
  62050. * because axisModel can be alive after echarts updating but instance of
  62051. * ParallelAxis having been disposed. this._activeInterval should be kept
  62052. * when action dispatched (i.e. legend click).
  62053. *
  62054. * @param intervals `interval.length === 0` means set all active.
  62055. */
  62056. ParallelAxisModel.prototype.setActiveIntervals = function (intervals) {
  62057. var activeIntervals = this.activeIntervals = clone(intervals);
  62058. // Normalize
  62059. if (activeIntervals) {
  62060. for (var i = activeIntervals.length - 1; i >= 0; i--) {
  62061. asc(activeIntervals[i]);
  62062. }
  62063. }
  62064. };
  62065. /**
  62066. * @param value When only attempting detect whether 'no activeIntervals set',
  62067. * `value` is not needed to be input.
  62068. */
  62069. ParallelAxisModel.prototype.getActiveState = function (value) {
  62070. var activeIntervals = this.activeIntervals;
  62071. if (!activeIntervals.length) {
  62072. return 'normal';
  62073. }
  62074. if (value == null || isNaN(+value)) {
  62075. return 'inactive';
  62076. }
  62077. // Simple optimization
  62078. if (activeIntervals.length === 1) {
  62079. var interval = activeIntervals[0];
  62080. if (interval[0] <= value && value <= interval[1]) {
  62081. return 'active';
  62082. }
  62083. } else {
  62084. for (var i = 0, len = activeIntervals.length; i < len; i++) {
  62085. if (activeIntervals[i][0] <= value && value <= activeIntervals[i][1]) {
  62086. return 'active';
  62087. }
  62088. }
  62089. }
  62090. return 'inactive';
  62091. };
  62092. return ParallelAxisModel;
  62093. }(ComponentModel);
  62094. mixin(ParallelAxisModel, AxisModelCommonMixin);
  62095. var BRUSH_PANEL_GLOBAL = true;
  62096. var mathMin$a = Math.min;
  62097. var mathMax$a = Math.max;
  62098. var mathPow$2 = Math.pow;
  62099. var COVER_Z = 10000;
  62100. var UNSELECT_THRESHOLD = 6;
  62101. var MIN_RESIZE_LINE_WIDTH = 6;
  62102. var MUTEX_RESOURCE_KEY = 'globalPan';
  62103. var DIRECTION_MAP = {
  62104. w: [0, 0],
  62105. e: [0, 1],
  62106. n: [1, 0],
  62107. s: [1, 1]
  62108. };
  62109. var CURSOR_MAP = {
  62110. w: 'ew',
  62111. e: 'ew',
  62112. n: 'ns',
  62113. s: 'ns',
  62114. ne: 'nesw',
  62115. sw: 'nesw',
  62116. nw: 'nwse',
  62117. se: 'nwse'
  62118. };
  62119. var DEFAULT_BRUSH_OPT = {
  62120. brushStyle: {
  62121. lineWidth: 2,
  62122. stroke: tokens.color.backgroundTint,
  62123. fill: tokens.color.borderTint
  62124. },
  62125. transformable: true,
  62126. brushMode: 'single',
  62127. removeOnClick: false
  62128. };
  62129. var baseUID = 0;
  62130. /**
  62131. * params:
  62132. * areas: Array.<Array>, coord relates to container group,
  62133. * If no container specified, to global.
  62134. * opt {
  62135. * isEnd: boolean,
  62136. * removeOnClick: boolean
  62137. * }
  62138. */
  62139. var BrushController = /** @class */function (_super) {
  62140. __extends(BrushController, _super);
  62141. function BrushController(zr) {
  62142. var _this = _super.call(this) || this;
  62143. /**
  62144. * @internal
  62145. */
  62146. _this._track = [];
  62147. /**
  62148. * @internal
  62149. */
  62150. _this._covers = [];
  62151. _this._handlers = {};
  62152. if ("development" !== 'production') {
  62153. assert(zr);
  62154. }
  62155. _this._zr = zr;
  62156. _this.group = new Group();
  62157. _this._uid = 'brushController_' + baseUID++;
  62158. each(pointerHandlers, function (handler, eventName) {
  62159. this._handlers[eventName] = bind(handler, this);
  62160. }, _this);
  62161. return _this;
  62162. }
  62163. /**
  62164. * If set to `false`, select disabled.
  62165. */
  62166. BrushController.prototype.enableBrush = function (brushOption) {
  62167. if ("development" !== 'production') {
  62168. assert(this._mounted);
  62169. }
  62170. this._brushType && this._doDisableBrush();
  62171. brushOption.brushType && this._doEnableBrush(brushOption);
  62172. return this;
  62173. };
  62174. BrushController.prototype._doEnableBrush = function (brushOption) {
  62175. var zr = this._zr;
  62176. // Consider roam, which takes globalPan too.
  62177. if (!this._enableGlobalPan) {
  62178. take(zr, MUTEX_RESOURCE_KEY, this._uid);
  62179. }
  62180. each(this._handlers, function (handler, eventName) {
  62181. zr.on(eventName, handler);
  62182. });
  62183. this._brushType = brushOption.brushType;
  62184. this._brushOption = merge(clone(DEFAULT_BRUSH_OPT), brushOption, true);
  62185. };
  62186. BrushController.prototype._doDisableBrush = function () {
  62187. var zr = this._zr;
  62188. release(zr, MUTEX_RESOURCE_KEY, this._uid);
  62189. each(this._handlers, function (handler, eventName) {
  62190. zr.off(eventName, handler);
  62191. });
  62192. this._brushType = this._brushOption = null;
  62193. };
  62194. /**
  62195. * @param panelOpts If not pass, it is global brush.
  62196. */
  62197. BrushController.prototype.setPanels = function (panelOpts) {
  62198. if (panelOpts && panelOpts.length) {
  62199. var panels_1 = this._panels = {};
  62200. each(panelOpts, function (panelOpts) {
  62201. panels_1[panelOpts.panelId] = clone(panelOpts);
  62202. });
  62203. } else {
  62204. this._panels = null;
  62205. }
  62206. return this;
  62207. };
  62208. BrushController.prototype.mount = function (opt) {
  62209. opt = opt || {};
  62210. if ("development" !== 'production') {
  62211. this._mounted = true; // should be at first.
  62212. }
  62213. this._enableGlobalPan = opt.enableGlobalPan;
  62214. var thisGroup = this.group;
  62215. this._zr.add(thisGroup);
  62216. thisGroup.attr({
  62217. x: opt.x || 0,
  62218. y: opt.y || 0,
  62219. rotation: opt.rotation || 0,
  62220. scaleX: opt.scaleX || 1,
  62221. scaleY: opt.scaleY || 1
  62222. });
  62223. this._transform = thisGroup.getLocalTransform();
  62224. return this;
  62225. };
  62226. // eachCover(cb, context): void {
  62227. // each(this._covers, cb, context);
  62228. // }
  62229. /**
  62230. * Update covers.
  62231. * @param coverConfigList
  62232. * If coverConfigList is null/undefined, all covers removed.
  62233. */
  62234. BrushController.prototype.updateCovers = function (coverConfigList) {
  62235. if ("development" !== 'production') {
  62236. assert(this._mounted);
  62237. }
  62238. coverConfigList = map(coverConfigList, function (coverConfig) {
  62239. return merge(clone(DEFAULT_BRUSH_OPT), coverConfig, true);
  62240. });
  62241. var tmpIdPrefix = '\0-brush-index-';
  62242. var oldCovers = this._covers;
  62243. var newCovers = this._covers = [];
  62244. var controller = this;
  62245. var creatingCover = this._creatingCover;
  62246. new DataDiffer(oldCovers, coverConfigList, oldGetKey, getKey).add(addOrUpdate).update(addOrUpdate).remove(remove).execute();
  62247. return this;
  62248. function getKey(brushOption, index) {
  62249. return (brushOption.id != null ? brushOption.id : tmpIdPrefix + index) + '-' + brushOption.brushType;
  62250. }
  62251. function oldGetKey(cover, index) {
  62252. return getKey(cover.__brushOption, index);
  62253. }
  62254. function addOrUpdate(newIndex, oldIndex) {
  62255. var newBrushInternal = coverConfigList[newIndex];
  62256. // Consider setOption in event listener of brushSelect,
  62257. // where updating cover when creating should be forbidden.
  62258. if (oldIndex != null && oldCovers[oldIndex] === creatingCover) {
  62259. newCovers[newIndex] = oldCovers[oldIndex];
  62260. } else {
  62261. var cover = newCovers[newIndex] = oldIndex != null ? (oldCovers[oldIndex].__brushOption = newBrushInternal, oldCovers[oldIndex]) : endCreating(controller, createCover(controller, newBrushInternal));
  62262. updateCoverAfterCreation(controller, cover);
  62263. }
  62264. }
  62265. function remove(oldIndex) {
  62266. if (oldCovers[oldIndex] !== creatingCover) {
  62267. controller.group.remove(oldCovers[oldIndex]);
  62268. }
  62269. }
  62270. };
  62271. BrushController.prototype.unmount = function () {
  62272. if ("development" !== 'production') {
  62273. if (!this._mounted) {
  62274. return;
  62275. }
  62276. }
  62277. this.enableBrush(false);
  62278. // container may 'removeAll' outside.
  62279. clearCovers(this);
  62280. this._zr.remove(this.group);
  62281. if ("development" !== 'production') {
  62282. this._mounted = false; // should be at last.
  62283. }
  62284. return this;
  62285. };
  62286. BrushController.prototype.dispose = function () {
  62287. this.unmount();
  62288. this.off();
  62289. };
  62290. return BrushController;
  62291. }(Eventful);
  62292. function createCover(controller, brushOption) {
  62293. var cover = coverRenderers[brushOption.brushType].createCover(controller, brushOption);
  62294. cover.__brushOption = brushOption;
  62295. updateZ(cover, brushOption);
  62296. controller.group.add(cover);
  62297. return cover;
  62298. }
  62299. function endCreating(controller, creatingCover) {
  62300. var coverRenderer = getCoverRenderer(creatingCover);
  62301. if (coverRenderer.endCreating) {
  62302. coverRenderer.endCreating(controller, creatingCover);
  62303. updateZ(creatingCover, creatingCover.__brushOption);
  62304. }
  62305. return creatingCover;
  62306. }
  62307. function updateCoverShape(controller, cover) {
  62308. var brushOption = cover.__brushOption;
  62309. getCoverRenderer(cover).updateCoverShape(controller, cover, brushOption.range, brushOption);
  62310. }
  62311. function updateZ(cover, brushOption) {
  62312. var z = brushOption.z;
  62313. z == null && (z = COVER_Z);
  62314. cover.traverse(function (el) {
  62315. el.z = z;
  62316. el.z2 = z; // Consider in given container.
  62317. });
  62318. }
  62319. function updateCoverAfterCreation(controller, cover) {
  62320. getCoverRenderer(cover).updateCommon(controller, cover);
  62321. updateCoverShape(controller, cover);
  62322. }
  62323. function getCoverRenderer(cover) {
  62324. return coverRenderers[cover.__brushOption.brushType];
  62325. }
  62326. // return target panel or `true` (means global panel)
  62327. function getPanelByPoint(controller, e, localCursorPoint) {
  62328. var panels = controller._panels;
  62329. if (!panels) {
  62330. return BRUSH_PANEL_GLOBAL; // Global panel
  62331. }
  62332. var panel;
  62333. var transform = controller._transform;
  62334. each(panels, function (pn) {
  62335. pn.isTargetByCursor(e, localCursorPoint, transform) && (panel = pn);
  62336. });
  62337. return panel;
  62338. }
  62339. // Return a panel or true
  62340. function getPanelByCover(controller, cover) {
  62341. var panels = controller._panels;
  62342. if (!panels) {
  62343. return BRUSH_PANEL_GLOBAL; // Global panel
  62344. }
  62345. var panelId = cover.__brushOption.panelId;
  62346. // User may give cover without coord sys info,
  62347. // which is then treated as global panel.
  62348. return panelId != null ? panels[panelId] : BRUSH_PANEL_GLOBAL;
  62349. }
  62350. function clearCovers(controller) {
  62351. var covers = controller._covers;
  62352. var originalLength = covers.length;
  62353. each(covers, function (cover) {
  62354. controller.group.remove(cover);
  62355. }, controller);
  62356. covers.length = 0;
  62357. return !!originalLength;
  62358. }
  62359. function trigger$1(controller, opt) {
  62360. var areas = map(controller._covers, function (cover) {
  62361. var brushOption = cover.__brushOption;
  62362. var range = clone(brushOption.range);
  62363. return {
  62364. brushType: brushOption.brushType,
  62365. panelId: brushOption.panelId,
  62366. range: range
  62367. };
  62368. });
  62369. controller.trigger('brush', {
  62370. areas: areas,
  62371. isEnd: !!opt.isEnd,
  62372. removeOnClick: !!opt.removeOnClick
  62373. });
  62374. }
  62375. function shouldShowCover(controller) {
  62376. var track = controller._track;
  62377. if (!track.length) {
  62378. return false;
  62379. }
  62380. var p2 = track[track.length - 1];
  62381. var p1 = track[0];
  62382. var dx = p2[0] - p1[0];
  62383. var dy = p2[1] - p1[1];
  62384. var dist = mathPow$2(dx * dx + dy * dy, 0.5);
  62385. return dist > UNSELECT_THRESHOLD;
  62386. }
  62387. function getTrackEnds(track) {
  62388. var tail = track.length - 1;
  62389. tail < 0 && (tail = 0);
  62390. return [track[0], track[tail]];
  62391. }
  62392. function createBaseRectCover(rectRangeConverter, controller, brushOption, edgeNameSequences) {
  62393. var cover = new Group();
  62394. cover.add(new Rect({
  62395. name: 'main',
  62396. style: makeStyle(brushOption),
  62397. silent: true,
  62398. draggable: true,
  62399. cursor: 'move',
  62400. drift: curry(driftRect, rectRangeConverter, controller, cover, ['n', 's', 'w', 'e']),
  62401. ondragend: curry(trigger$1, controller, {
  62402. isEnd: true
  62403. })
  62404. }));
  62405. each(edgeNameSequences, function (nameSequence) {
  62406. cover.add(new Rect({
  62407. name: nameSequence.join(''),
  62408. style: {
  62409. opacity: 0
  62410. },
  62411. draggable: true,
  62412. silent: true,
  62413. invisible: true,
  62414. drift: curry(driftRect, rectRangeConverter, controller, cover, nameSequence),
  62415. ondragend: curry(trigger$1, controller, {
  62416. isEnd: true
  62417. })
  62418. }));
  62419. });
  62420. return cover;
  62421. }
  62422. function updateBaseRect(controller, cover, localRange, brushOption) {
  62423. var lineWidth = brushOption.brushStyle.lineWidth || 0;
  62424. var handleSize = mathMax$a(lineWidth, MIN_RESIZE_LINE_WIDTH);
  62425. var x = localRange[0][0];
  62426. var y = localRange[1][0];
  62427. var xa = x - lineWidth / 2;
  62428. var ya = y - lineWidth / 2;
  62429. var x2 = localRange[0][1];
  62430. var y2 = localRange[1][1];
  62431. var x2a = x2 - handleSize + lineWidth / 2;
  62432. var y2a = y2 - handleSize + lineWidth / 2;
  62433. var width = x2 - x;
  62434. var height = y2 - y;
  62435. var widtha = width + lineWidth;
  62436. var heighta = height + lineWidth;
  62437. updateRectShape(controller, cover, 'main', x, y, width, height);
  62438. if (brushOption.transformable) {
  62439. updateRectShape(controller, cover, 'w', xa, ya, handleSize, heighta);
  62440. updateRectShape(controller, cover, 'e', x2a, ya, handleSize, heighta);
  62441. updateRectShape(controller, cover, 'n', xa, ya, widtha, handleSize);
  62442. updateRectShape(controller, cover, 's', xa, y2a, widtha, handleSize);
  62443. updateRectShape(controller, cover, 'nw', xa, ya, handleSize, handleSize);
  62444. updateRectShape(controller, cover, 'ne', x2a, ya, handleSize, handleSize);
  62445. updateRectShape(controller, cover, 'sw', xa, y2a, handleSize, handleSize);
  62446. updateRectShape(controller, cover, 'se', x2a, y2a, handleSize, handleSize);
  62447. }
  62448. }
  62449. function updateCommon(controller, cover) {
  62450. var brushOption = cover.__brushOption;
  62451. var transformable = brushOption.transformable;
  62452. var mainEl = cover.childAt(0);
  62453. mainEl.useStyle(makeStyle(brushOption));
  62454. mainEl.attr({
  62455. silent: !transformable,
  62456. cursor: transformable ? 'move' : 'default'
  62457. });
  62458. each([['w'], ['e'], ['n'], ['s'], ['s', 'e'], ['s', 'w'], ['n', 'e'], ['n', 'w']], function (nameSequence) {
  62459. var el = cover.childOfName(nameSequence.join(''));
  62460. var globalDir = nameSequence.length === 1 ? getGlobalDirection1(controller, nameSequence[0]) : getGlobalDirection2(controller, nameSequence);
  62461. el && el.attr({
  62462. silent: !transformable,
  62463. invisible: !transformable,
  62464. cursor: transformable ? CURSOR_MAP[globalDir] + '-resize' : null
  62465. });
  62466. });
  62467. }
  62468. function updateRectShape(controller, cover, name, x, y, w, h) {
  62469. var el = cover.childOfName(name);
  62470. el && el.setShape(pointsToRect(clipByPanel(controller, cover, [[x, y], [x + w, y + h]])));
  62471. }
  62472. function makeStyle(brushOption) {
  62473. return defaults({
  62474. strokeNoScale: true
  62475. }, brushOption.brushStyle);
  62476. }
  62477. function formatRectRange(x, y, x2, y2) {
  62478. var min = [mathMin$a(x, x2), mathMin$a(y, y2)];
  62479. var max = [mathMax$a(x, x2), mathMax$a(y, y2)];
  62480. return [[min[0], max[0]], [min[1], max[1]] // y range
  62481. ];
  62482. }
  62483. function getTransform$1(controller) {
  62484. return getTransform(controller.group);
  62485. }
  62486. function getGlobalDirection1(controller, localDirName) {
  62487. var map = {
  62488. w: 'left',
  62489. e: 'right',
  62490. n: 'top',
  62491. s: 'bottom'
  62492. };
  62493. var inverseMap = {
  62494. left: 'w',
  62495. right: 'e',
  62496. top: 'n',
  62497. bottom: 's'
  62498. };
  62499. var dir = transformDirection(map[localDirName], getTransform$1(controller));
  62500. return inverseMap[dir];
  62501. }
  62502. function getGlobalDirection2(controller, localDirNameSeq) {
  62503. var globalDir = [getGlobalDirection1(controller, localDirNameSeq[0]), getGlobalDirection1(controller, localDirNameSeq[1])];
  62504. (globalDir[0] === 'e' || globalDir[0] === 'w') && globalDir.reverse();
  62505. return globalDir.join('');
  62506. }
  62507. function driftRect(rectRangeConverter, controller, cover, dirNameSequence, dx, dy) {
  62508. var brushOption = cover.__brushOption;
  62509. var rectRange = rectRangeConverter.toRectRange(brushOption.range);
  62510. var localDelta = toLocalDelta(controller, dx, dy);
  62511. each(dirNameSequence, function (dirName) {
  62512. var ind = DIRECTION_MAP[dirName];
  62513. rectRange[ind[0]][ind[1]] += localDelta[ind[0]];
  62514. });
  62515. brushOption.range = rectRangeConverter.fromRectRange(formatRectRange(rectRange[0][0], rectRange[1][0], rectRange[0][1], rectRange[1][1]));
  62516. updateCoverAfterCreation(controller, cover);
  62517. trigger$1(controller, {
  62518. isEnd: false
  62519. });
  62520. }
  62521. function driftPolygon(controller, cover, dx, dy) {
  62522. var range = cover.__brushOption.range;
  62523. var localDelta = toLocalDelta(controller, dx, dy);
  62524. each(range, function (point) {
  62525. point[0] += localDelta[0];
  62526. point[1] += localDelta[1];
  62527. });
  62528. updateCoverAfterCreation(controller, cover);
  62529. trigger$1(controller, {
  62530. isEnd: false
  62531. });
  62532. }
  62533. function toLocalDelta(controller, dx, dy) {
  62534. var thisGroup = controller.group;
  62535. var localD = thisGroup.transformCoordToLocal(dx, dy);
  62536. var localZero = thisGroup.transformCoordToLocal(0, 0);
  62537. return [localD[0] - localZero[0], localD[1] - localZero[1]];
  62538. }
  62539. function clipByPanel(controller, cover, data) {
  62540. var panel = getPanelByCover(controller, cover);
  62541. return panel && panel !== BRUSH_PANEL_GLOBAL ? panel.clipPath(data, controller._transform) : clone(data);
  62542. }
  62543. function pointsToRect(points) {
  62544. var xmin = mathMin$a(points[0][0], points[1][0]);
  62545. var ymin = mathMin$a(points[0][1], points[1][1]);
  62546. var xmax = mathMax$a(points[0][0], points[1][0]);
  62547. var ymax = mathMax$a(points[0][1], points[1][1]);
  62548. return {
  62549. x: xmin,
  62550. y: ymin,
  62551. width: xmax - xmin,
  62552. height: ymax - ymin
  62553. };
  62554. }
  62555. function resetCursor(controller, e, localCursorPoint) {
  62556. if (
  62557. // Check active
  62558. !controller._brushType
  62559. // resetCursor should be always called when mouse is in zr area,
  62560. // but not called when mouse is out of zr area to avoid bad influence
  62561. // if `mousemove`, `mouseup` are triggered from `document` event.
  62562. || isOutsideZrArea(controller, e.offsetX, e.offsetY)) {
  62563. return;
  62564. }
  62565. var zr = controller._zr;
  62566. var covers = controller._covers;
  62567. var currPanel = getPanelByPoint(controller, e, localCursorPoint);
  62568. // Check whether in covers.
  62569. if (!controller._dragging) {
  62570. for (var i = 0; i < covers.length; i++) {
  62571. var brushOption = covers[i].__brushOption;
  62572. if (currPanel && (currPanel === BRUSH_PANEL_GLOBAL || brushOption.panelId === currPanel.panelId) && coverRenderers[brushOption.brushType].contain(covers[i], localCursorPoint[0], localCursorPoint[1])) {
  62573. // Use cursor style set on cover.
  62574. return;
  62575. }
  62576. }
  62577. }
  62578. currPanel && zr.setCursorStyle('crosshair');
  62579. }
  62580. function preventDefault(e) {
  62581. var rawE = e.event;
  62582. rawE.preventDefault && rawE.preventDefault();
  62583. }
  62584. function mainShapeContain(cover, x, y) {
  62585. return cover.childOfName('main').contain(x, y);
  62586. }
  62587. function updateCoverByMouse(controller, e, localCursorPoint, isEnd) {
  62588. var creatingCover = controller._creatingCover;
  62589. var panel = controller._creatingPanel;
  62590. var thisBrushOption = controller._brushOption;
  62591. var eventParams;
  62592. controller._track.push(localCursorPoint.slice());
  62593. if (shouldShowCover(controller) || creatingCover) {
  62594. if (panel && !creatingCover) {
  62595. thisBrushOption.brushMode === 'single' && clearCovers(controller);
  62596. var brushOption = clone(thisBrushOption);
  62597. brushOption.brushType = determineBrushType(brushOption.brushType, panel);
  62598. brushOption.panelId = panel === BRUSH_PANEL_GLOBAL ? null : panel.panelId;
  62599. creatingCover = controller._creatingCover = createCover(controller, brushOption);
  62600. controller._covers.push(creatingCover);
  62601. }
  62602. if (creatingCover) {
  62603. var coverRenderer = coverRenderers[determineBrushType(controller._brushType, panel)];
  62604. var coverBrushOption = creatingCover.__brushOption;
  62605. coverBrushOption.range = coverRenderer.getCreatingRange(clipByPanel(controller, creatingCover, controller._track));
  62606. if (isEnd) {
  62607. endCreating(controller, creatingCover);
  62608. coverRenderer.updateCommon(controller, creatingCover);
  62609. }
  62610. updateCoverShape(controller, creatingCover);
  62611. eventParams = {
  62612. isEnd: isEnd
  62613. };
  62614. }
  62615. } else if (isEnd && thisBrushOption.brushMode === 'single' && thisBrushOption.removeOnClick) {
  62616. // Help user to remove covers easily, only by a tiny drag, in 'single' mode.
  62617. // But a single click do not clear covers, because user may have casual
  62618. // clicks (for example, click on other component and do not expect covers
  62619. // disappear).
  62620. // Only some cover removed, trigger action, but not every click trigger action.
  62621. if (getPanelByPoint(controller, e, localCursorPoint) && clearCovers(controller)) {
  62622. eventParams = {
  62623. isEnd: isEnd,
  62624. removeOnClick: true
  62625. };
  62626. }
  62627. }
  62628. return eventParams;
  62629. }
  62630. function determineBrushType(brushType, panel) {
  62631. if (brushType === 'auto') {
  62632. if ("development" !== 'production') {
  62633. assert(panel && panel.defaultBrushType, 'MUST have defaultBrushType when brushType is "atuo"');
  62634. }
  62635. return panel.defaultBrushType;
  62636. }
  62637. return brushType;
  62638. }
  62639. var pointerHandlers = {
  62640. mousedown: function (e) {
  62641. if (this._dragging) {
  62642. // In case some browser do not support globalOut,
  62643. // and release mouse out side the browser.
  62644. handleDragEnd(this, e);
  62645. } else if (!e.target || !e.target.draggable) {
  62646. preventDefault(e);
  62647. var localCursorPoint = this.group.transformCoordToLocal(e.offsetX, e.offsetY);
  62648. this._creatingCover = null;
  62649. var panel = this._creatingPanel = getPanelByPoint(this, e, localCursorPoint);
  62650. if (panel) {
  62651. this._dragging = true;
  62652. this._track = [localCursorPoint.slice()];
  62653. }
  62654. }
  62655. },
  62656. mousemove: function (e) {
  62657. var x = e.offsetX;
  62658. var y = e.offsetY;
  62659. var localCursorPoint = this.group.transformCoordToLocal(x, y);
  62660. resetCursor(this, e, localCursorPoint);
  62661. if (this._dragging) {
  62662. preventDefault(e);
  62663. var eventParams = updateCoverByMouse(this, e, localCursorPoint, false);
  62664. eventParams && trigger$1(this, eventParams);
  62665. }
  62666. },
  62667. mouseup: function (e) {
  62668. handleDragEnd(this, e);
  62669. }
  62670. };
  62671. function handleDragEnd(controller, e) {
  62672. if (controller._dragging) {
  62673. preventDefault(e);
  62674. var x = e.offsetX;
  62675. var y = e.offsetY;
  62676. var localCursorPoint = controller.group.transformCoordToLocal(x, y);
  62677. var eventParams = updateCoverByMouse(controller, e, localCursorPoint, true);
  62678. controller._dragging = false;
  62679. controller._track = [];
  62680. controller._creatingCover = null;
  62681. // trigger event should be at final, after procedure will be nested.
  62682. eventParams && trigger$1(controller, eventParams);
  62683. }
  62684. }
  62685. function isOutsideZrArea(controller, x, y) {
  62686. var zr = controller._zr;
  62687. return x < 0 || x > zr.getWidth() || y < 0 || y > zr.getHeight();
  62688. }
  62689. /**
  62690. * key: brushType
  62691. */
  62692. var coverRenderers = {
  62693. lineX: getLineRenderer(0),
  62694. lineY: getLineRenderer(1),
  62695. rect: {
  62696. createCover: function (controller, brushOption) {
  62697. function returnInput(range) {
  62698. return range;
  62699. }
  62700. return createBaseRectCover({
  62701. toRectRange: returnInput,
  62702. fromRectRange: returnInput
  62703. }, controller, brushOption, [['w'], ['e'], ['n'], ['s'], ['s', 'e'], ['s', 'w'], ['n', 'e'], ['n', 'w']]);
  62704. },
  62705. getCreatingRange: function (localTrack) {
  62706. var ends = getTrackEnds(localTrack);
  62707. return formatRectRange(ends[1][0], ends[1][1], ends[0][0], ends[0][1]);
  62708. },
  62709. updateCoverShape: function (controller, cover, localRange, brushOption) {
  62710. updateBaseRect(controller, cover, localRange, brushOption);
  62711. },
  62712. updateCommon: updateCommon,
  62713. contain: mainShapeContain
  62714. },
  62715. polygon: {
  62716. createCover: function (controller, brushOption) {
  62717. var cover = new Group();
  62718. // Do not use graphic.Polygon because graphic.Polyline do not close the
  62719. // border of the shape when drawing, which is a better experience for user.
  62720. cover.add(new Polyline({
  62721. name: 'main',
  62722. style: makeStyle(brushOption),
  62723. silent: true
  62724. }));
  62725. return cover;
  62726. },
  62727. getCreatingRange: function (localTrack) {
  62728. return localTrack;
  62729. },
  62730. endCreating: function (controller, cover) {
  62731. cover.remove(cover.childAt(0));
  62732. // Use graphic.Polygon close the shape.
  62733. cover.add(new Polygon({
  62734. name: 'main',
  62735. draggable: true,
  62736. drift: curry(driftPolygon, controller, cover),
  62737. ondragend: curry(trigger$1, controller, {
  62738. isEnd: true
  62739. })
  62740. }));
  62741. },
  62742. updateCoverShape: function (controller, cover, localRange, brushOption) {
  62743. cover.childAt(0).setShape({
  62744. points: clipByPanel(controller, cover, localRange)
  62745. });
  62746. },
  62747. updateCommon: updateCommon,
  62748. contain: mainShapeContain
  62749. }
  62750. };
  62751. function getLineRenderer(xyIndex) {
  62752. return {
  62753. createCover: function (controller, brushOption) {
  62754. return createBaseRectCover({
  62755. toRectRange: function (range) {
  62756. var rectRange = [range, [0, 100]];
  62757. xyIndex && rectRange.reverse();
  62758. return rectRange;
  62759. },
  62760. fromRectRange: function (rectRange) {
  62761. return rectRange[xyIndex];
  62762. }
  62763. }, controller, brushOption, [[['w'], ['e']], [['n'], ['s']]][xyIndex]);
  62764. },
  62765. getCreatingRange: function (localTrack) {
  62766. var ends = getTrackEnds(localTrack);
  62767. var min = mathMin$a(ends[0][xyIndex], ends[1][xyIndex]);
  62768. var max = mathMax$a(ends[0][xyIndex], ends[1][xyIndex]);
  62769. return [min, max];
  62770. },
  62771. updateCoverShape: function (controller, cover, localRange, brushOption) {
  62772. var otherExtent;
  62773. // If brushWidth not specified, fit the panel.
  62774. var panel = getPanelByCover(controller, cover);
  62775. if (panel !== BRUSH_PANEL_GLOBAL && panel.getLinearBrushOtherExtent) {
  62776. otherExtent = panel.getLinearBrushOtherExtent(xyIndex);
  62777. } else {
  62778. var zr = controller._zr;
  62779. otherExtent = [0, [zr.getWidth(), zr.getHeight()][1 - xyIndex]];
  62780. }
  62781. var rectRange = [localRange, otherExtent];
  62782. xyIndex && rectRange.reverse();
  62783. updateBaseRect(controller, cover, rectRange, brushOption);
  62784. },
  62785. updateCommon: updateCommon,
  62786. contain: mainShapeContain
  62787. };
  62788. }
  62789. function makeRectPanelClipPath(rect) {
  62790. rect = normalizeRect(rect);
  62791. return function (localPoints) {
  62792. return clipPointsByRect(localPoints, rect);
  62793. };
  62794. }
  62795. function makeLinearBrushOtherExtent(rect, specifiedXYIndex) {
  62796. rect = normalizeRect(rect);
  62797. return function (xyIndex) {
  62798. var idx = specifiedXYIndex != null ? specifiedXYIndex : xyIndex;
  62799. var brushWidth = idx ? rect.width : rect.height;
  62800. var base = idx ? rect.x : rect.y;
  62801. return [base, base + (brushWidth || 0)];
  62802. };
  62803. }
  62804. function makeRectIsTargetByCursor(rect, api, targetModel) {
  62805. var boundingRect = normalizeRect(rect);
  62806. return function (e, localCursorPoint) {
  62807. return boundingRect.contain(localCursorPoint[0], localCursorPoint[1]) && !onIrrelevantElement(e, api, targetModel);
  62808. };
  62809. }
  62810. // Consider width/height is negative.
  62811. function normalizeRect(rect) {
  62812. return BoundingRect.create(rect);
  62813. }
  62814. var ParallelAxisView = /** @class */function (_super) {
  62815. __extends(ParallelAxisView, _super);
  62816. function ParallelAxisView() {
  62817. var _this = _super !== null && _super.apply(this, arguments) || this;
  62818. _this.type = ParallelAxisView.type;
  62819. return _this;
  62820. }
  62821. ParallelAxisView.prototype.init = function (ecModel, api) {
  62822. _super.prototype.init.apply(this, arguments);
  62823. (this._brushController = new BrushController(api.getZr())).on('brush', bind(this._onBrush, this));
  62824. };
  62825. ParallelAxisView.prototype.render = function (axisModel, ecModel, api, payload) {
  62826. if (fromAxisAreaSelect(axisModel, ecModel, payload)) {
  62827. return;
  62828. }
  62829. this.axisModel = axisModel;
  62830. this.api = api;
  62831. this.group.removeAll();
  62832. var oldAxisGroup = this._axisGroup;
  62833. this._axisGroup = new Group();
  62834. this.group.add(this._axisGroup);
  62835. if (!axisModel.get('show')) {
  62836. return;
  62837. }
  62838. var coordSysModel = getCoordSysModel(axisModel, ecModel);
  62839. var coordSys = coordSysModel.coordinateSystem;
  62840. var areaSelectStyle = axisModel.getAreaSelectStyle();
  62841. var areaWidth = areaSelectStyle.width;
  62842. var dim = axisModel.axis.dim;
  62843. var axisLayout = coordSys.getAxisLayout(dim);
  62844. var builderOpt = extend({
  62845. strokeContainThreshold: areaWidth
  62846. }, axisLayout);
  62847. var axisBuilder = new AxisBuilder(axisModel, api, builderOpt);
  62848. axisBuilder.build();
  62849. this._axisGroup.add(axisBuilder.group);
  62850. this._refreshBrushController(builderOpt, areaSelectStyle, axisModel, coordSysModel, areaWidth, api);
  62851. groupTransition(oldAxisGroup, this._axisGroup, axisModel);
  62852. };
  62853. // /**
  62854. // * @override
  62855. // */
  62856. // updateVisual(axisModel, ecModel, api, payload) {
  62857. // this._brushController && this._brushController
  62858. // .updateCovers(getCoverInfoList(axisModel));
  62859. // }
  62860. ParallelAxisView.prototype._refreshBrushController = function (builderOpt, areaSelectStyle, axisModel, coordSysModel, areaWidth, api) {
  62861. // After filtering, axis may change, select area needs to be update.
  62862. var extent = axisModel.axis.getExtent();
  62863. var extentLen = extent[1] - extent[0];
  62864. var extra = Math.min(30, Math.abs(extentLen) * 0.1); // Arbitrary value.
  62865. // width/height might be negative, which will be
  62866. // normalized in BoundingRect.
  62867. var rect = BoundingRect.create({
  62868. x: extent[0],
  62869. y: -areaWidth / 2,
  62870. width: extentLen,
  62871. height: areaWidth
  62872. });
  62873. rect.x -= extra;
  62874. rect.width += 2 * extra;
  62875. this._brushController.mount({
  62876. enableGlobalPan: true,
  62877. rotation: builderOpt.rotation,
  62878. x: builderOpt.position[0],
  62879. y: builderOpt.position[1]
  62880. }).setPanels([{
  62881. panelId: 'pl',
  62882. clipPath: makeRectPanelClipPath(rect),
  62883. isTargetByCursor: makeRectIsTargetByCursor(rect, api, coordSysModel),
  62884. getLinearBrushOtherExtent: makeLinearBrushOtherExtent(rect, 0)
  62885. }]).enableBrush({
  62886. brushType: 'lineX',
  62887. brushStyle: areaSelectStyle,
  62888. removeOnClick: true
  62889. }).updateCovers(getCoverInfoList(axisModel));
  62890. };
  62891. ParallelAxisView.prototype._onBrush = function (eventParam) {
  62892. var coverInfoList = eventParam.areas;
  62893. // Do not cache these object, because the mey be changed.
  62894. var axisModel = this.axisModel;
  62895. var axis = axisModel.axis;
  62896. var intervals = map(coverInfoList, function (coverInfo) {
  62897. return [axis.coordToData(coverInfo.range[0], true), axis.coordToData(coverInfo.range[1], true)];
  62898. });
  62899. // If realtime is true, action is not dispatched on drag end, because
  62900. // the drag end emits the same params with the last drag move event,
  62901. // and may have some delay when using touch pad.
  62902. if (!axisModel.option.realtime === eventParam.isEnd || eventParam.removeOnClick) {
  62903. // jshint ignore:line
  62904. this.api.dispatchAction({
  62905. type: 'axisAreaSelect',
  62906. parallelAxisId: axisModel.id,
  62907. intervals: intervals
  62908. });
  62909. }
  62910. };
  62911. ParallelAxisView.prototype.dispose = function () {
  62912. this._brushController.dispose();
  62913. };
  62914. ParallelAxisView.type = 'parallelAxis';
  62915. return ParallelAxisView;
  62916. }(ComponentView);
  62917. function fromAxisAreaSelect(axisModel, ecModel, payload) {
  62918. return payload && payload.type === 'axisAreaSelect' && ecModel.findComponents({
  62919. mainType: 'parallelAxis',
  62920. query: payload
  62921. })[0] === axisModel;
  62922. }
  62923. function getCoverInfoList(axisModel) {
  62924. var axis = axisModel.axis;
  62925. return map(axisModel.activeIntervals, function (interval) {
  62926. return {
  62927. brushType: 'lineX',
  62928. panelId: 'pl',
  62929. range: [axis.dataToCoord(interval[0], true), axis.dataToCoord(interval[1], true)]
  62930. };
  62931. });
  62932. }
  62933. function getCoordSysModel(axisModel, ecModel) {
  62934. return ecModel.getComponent('parallel', axisModel.get('parallelIndex'));
  62935. }
  62936. /*
  62937. * Licensed to the Apache Software Foundation (ASF) under one
  62938. * or more contributor license agreements. See the NOTICE file
  62939. * distributed with this work for additional information
  62940. * regarding copyright ownership. The ASF licenses this file
  62941. * to you under the Apache License, Version 2.0 (the
  62942. * "License"); you may not use this file except in compliance
  62943. * with the License. You may obtain a copy of the License at
  62944. *
  62945. * http://www.apache.org/licenses/LICENSE-2.0
  62946. *
  62947. * Unless required by applicable law or agreed to in writing,
  62948. * software distributed under the License is distributed on an
  62949. * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
  62950. * KIND, either express or implied. See the License for the
  62951. * specific language governing permissions and limitations
  62952. * under the License.
  62953. */
  62954. /**
  62955. * AUTO-GENERATED FILE. DO NOT MODIFY.
  62956. */
  62957. /*
  62958. * Licensed to the Apache Software Foundation (ASF) under one
  62959. * or more contributor license agreements. See the NOTICE file
  62960. * distributed with this work for additional information
  62961. * regarding copyright ownership. The ASF licenses this file
  62962. * to you under the Apache License, Version 2.0 (the
  62963. * "License"); you may not use this file except in compliance
  62964. * with the License. You may obtain a copy of the License at
  62965. *
  62966. * http://www.apache.org/licenses/LICENSE-2.0
  62967. *
  62968. * Unless required by applicable law or agreed to in writing,
  62969. * software distributed under the License is distributed on an
  62970. * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
  62971. * KIND, either express or implied. See the License for the
  62972. * specific language governing permissions and limitations
  62973. * under the License.
  62974. */
  62975. var actionInfo = {
  62976. type: 'axisAreaSelect',
  62977. event: 'axisAreaSelected'
  62978. // update: 'updateVisual'
  62979. };
  62980. function installParallelActions(registers) {
  62981. registers.registerAction(actionInfo, function (payload, ecModel) {
  62982. ecModel.eachComponent({
  62983. mainType: 'parallelAxis',
  62984. query: payload
  62985. }, function (parallelAxisModel) {
  62986. parallelAxisModel.axis.model.setActiveIntervals(payload.intervals);
  62987. });
  62988. });
  62989. /**
  62990. * @payload
  62991. */
  62992. registers.registerAction('parallelAxisExpand', function (payload, ecModel) {
  62993. ecModel.eachComponent({
  62994. mainType: 'parallel',
  62995. query: payload
  62996. }, function (parallelModel) {
  62997. parallelModel.setAxisExpand(payload);
  62998. });
  62999. });
  63000. }
  63001. var defaultAxisOption = {
  63002. type: 'value',
  63003. areaSelectStyle: {
  63004. width: 20,
  63005. borderWidth: 1,
  63006. borderColor: 'rgba(160,197,232)',
  63007. color: 'rgba(160,197,232)',
  63008. opacity: 0.3
  63009. },
  63010. realtime: true,
  63011. z: 10
  63012. };
  63013. function install$h(registers) {
  63014. registers.registerComponentView(ParallelView$1);
  63015. registers.registerComponentModel(ParallelModel);
  63016. registers.registerCoordinateSystem('parallel', parallelCoordSysCreator);
  63017. registers.registerPreprocessor(parallelPreprocessor);
  63018. registers.registerComponentModel(ParallelAxisModel);
  63019. registers.registerComponentView(ParallelAxisView);
  63020. axisModelCreator(registers, 'parallel', ParallelAxisModel, defaultAxisOption);
  63021. installParallelActions(registers);
  63022. }
  63023. function install$i(registers) {
  63024. use(install$h);
  63025. registers.registerChartView(ParallelView);
  63026. registers.registerSeriesModel(ParallelSeriesModel);
  63027. registers.registerVisual(registers.PRIORITY.VISUAL.BRUSH, parallelVisual);
  63028. }
  63029. var SankeyPathShape = /** @class */function () {
  63030. function SankeyPathShape() {
  63031. this.x1 = 0;
  63032. this.y1 = 0;
  63033. this.x2 = 0;
  63034. this.y2 = 0;
  63035. this.cpx1 = 0;
  63036. this.cpy1 = 0;
  63037. this.cpx2 = 0;
  63038. this.cpy2 = 0;
  63039. this.extent = 0;
  63040. }
  63041. return SankeyPathShape;
  63042. }();
  63043. var SankeyPath = /** @class */function (_super) {
  63044. __extends(SankeyPath, _super);
  63045. function SankeyPath(opts) {
  63046. return _super.call(this, opts) || this;
  63047. }
  63048. SankeyPath.prototype.getDefaultShape = function () {
  63049. return new SankeyPathShape();
  63050. };
  63051. SankeyPath.prototype.buildPath = function (ctx, shape) {
  63052. var extent = shape.extent;
  63053. ctx.moveTo(shape.x1, shape.y1);
  63054. ctx.bezierCurveTo(shape.cpx1, shape.cpy1, shape.cpx2, shape.cpy2, shape.x2, shape.y2);
  63055. if (shape.orient === 'vertical') {
  63056. ctx.lineTo(shape.x2 + extent, shape.y2);
  63057. ctx.bezierCurveTo(shape.cpx2 + extent, shape.cpy2, shape.cpx1 + extent, shape.cpy1, shape.x1 + extent, shape.y1);
  63058. } else {
  63059. ctx.lineTo(shape.x2, shape.y2 + extent);
  63060. ctx.bezierCurveTo(shape.cpx2, shape.cpy2 + extent, shape.cpx1, shape.cpy1 + extent, shape.x1, shape.y1 + extent);
  63061. }
  63062. ctx.closePath();
  63063. };
  63064. SankeyPath.prototype.highlight = function () {
  63065. enterEmphasis(this);
  63066. };
  63067. SankeyPath.prototype.downplay = function () {
  63068. leaveEmphasis(this);
  63069. };
  63070. return SankeyPath;
  63071. }(Path);
  63072. var SankeyView = /** @class */function (_super) {
  63073. __extends(SankeyView, _super);
  63074. function SankeyView() {
  63075. var _this = _super !== null && _super.apply(this, arguments) || this;
  63076. _this.type = SankeyView.type;
  63077. _this._mainGroup = new Group();
  63078. _this._focusAdjacencyDisabled = false;
  63079. return _this;
  63080. }
  63081. SankeyView.prototype.init = function (ecModel, api) {
  63082. this._controller = new RoamController(api.getZr());
  63083. this._controllerHost = {
  63084. target: this.group
  63085. };
  63086. this.group.add(this._mainGroup);
  63087. };
  63088. SankeyView.prototype.render = function (seriesModel, ecModel, api) {
  63089. var sankeyView = this;
  63090. var graph = seriesModel.getGraph();
  63091. var mainGroup = this._mainGroup;
  63092. var layoutInfo = seriesModel.layoutInfo;
  63093. // view width
  63094. var width = layoutInfo.width;
  63095. // view height
  63096. var height = layoutInfo.height;
  63097. var nodeData = seriesModel.getData();
  63098. var edgeData = seriesModel.getData('edge');
  63099. var orient = seriesModel.get('orient');
  63100. this._model = seriesModel;
  63101. mainGroup.removeAll();
  63102. mainGroup.x = layoutInfo.x;
  63103. mainGroup.y = layoutInfo.y;
  63104. this._updateViewCoordSys(seriesModel, api);
  63105. updateController(seriesModel, api, mainGroup, this._controller, this._controllerHost, null);
  63106. // generate a bezire Curve for each edge
  63107. graph.eachEdge(function (edge) {
  63108. var curve = new SankeyPath();
  63109. var ecData = getECData(curve);
  63110. ecData.dataIndex = edge.dataIndex;
  63111. ecData.seriesIndex = seriesModel.seriesIndex;
  63112. ecData.dataType = 'edge';
  63113. var edgeModel = edge.getModel();
  63114. var lineStyleModel = edgeModel.getModel('lineStyle');
  63115. var curvature = lineStyleModel.get('curveness');
  63116. var n1Layout = edge.node1.getLayout();
  63117. var node1Model = edge.node1.getModel();
  63118. var dragX1 = node1Model.get('localX');
  63119. var dragY1 = node1Model.get('localY');
  63120. var n2Layout = edge.node2.getLayout();
  63121. var node2Model = edge.node2.getModel();
  63122. var dragX2 = node2Model.get('localX');
  63123. var dragY2 = node2Model.get('localY');
  63124. var edgeLayout = edge.getLayout();
  63125. var x1;
  63126. var y1;
  63127. var x2;
  63128. var y2;
  63129. var cpx1;
  63130. var cpy1;
  63131. var cpx2;
  63132. var cpy2;
  63133. curve.shape.extent = Math.max(1, edgeLayout.dy);
  63134. curve.shape.orient = orient;
  63135. if (orient === 'vertical') {
  63136. x1 = (dragX1 != null ? dragX1 * width : n1Layout.x) + edgeLayout.sy;
  63137. y1 = (dragY1 != null ? dragY1 * height : n1Layout.y) + n1Layout.dy;
  63138. x2 = (dragX2 != null ? dragX2 * width : n2Layout.x) + edgeLayout.ty;
  63139. y2 = dragY2 != null ? dragY2 * height : n2Layout.y;
  63140. cpx1 = x1;
  63141. cpy1 = y1 * (1 - curvature) + y2 * curvature;
  63142. cpx2 = x2;
  63143. cpy2 = y1 * curvature + y2 * (1 - curvature);
  63144. } else {
  63145. x1 = (dragX1 != null ? dragX1 * width : n1Layout.x) + n1Layout.dx;
  63146. y1 = (dragY1 != null ? dragY1 * height : n1Layout.y) + edgeLayout.sy;
  63147. x2 = dragX2 != null ? dragX2 * width : n2Layout.x;
  63148. y2 = (dragY2 != null ? dragY2 * height : n2Layout.y) + edgeLayout.ty;
  63149. cpx1 = x1 * (1 - curvature) + x2 * curvature;
  63150. cpy1 = y1;
  63151. cpx2 = x1 * curvature + x2 * (1 - curvature);
  63152. cpy2 = y2;
  63153. }
  63154. curve.setShape({
  63155. x1: x1,
  63156. y1: y1,
  63157. x2: x2,
  63158. y2: y2,
  63159. cpx1: cpx1,
  63160. cpy1: cpy1,
  63161. cpx2: cpx2,
  63162. cpy2: cpy2
  63163. });
  63164. curve.useStyle(lineStyleModel.getItemStyle());
  63165. // Special color, use source node color or target node color
  63166. applyCurveStyle(curve.style, orient, edge);
  63167. var defaultEdgeLabelText = "" + edgeModel.get('value');
  63168. var edgeLabelStateModels = getLabelStatesModels(edgeModel, 'edgeLabel');
  63169. setLabelStyle(curve, edgeLabelStateModels, {
  63170. labelFetcher: {
  63171. getFormattedLabel: function (dataIndex, stateName, dataType, labelDimIndex, formatter, extendParams) {
  63172. return seriesModel.getFormattedLabel(dataIndex, stateName, 'edge', labelDimIndex,
  63173. // ensure edgeLabel formatter is provided
  63174. // to prevent the inheritance from `label.formatter` of the series
  63175. retrieve3(formatter, edgeLabelStateModels.normal && edgeLabelStateModels.normal.get('formatter'), defaultEdgeLabelText), extendParams);
  63176. }
  63177. },
  63178. labelDataIndex: edge.dataIndex,
  63179. defaultText: defaultEdgeLabelText
  63180. });
  63181. curve.setTextConfig({
  63182. position: 'inside'
  63183. });
  63184. var emphasisModel = edgeModel.getModel('emphasis');
  63185. setStatesStylesFromModel(curve, edgeModel, 'lineStyle', function (model) {
  63186. var style = model.getItemStyle();
  63187. applyCurveStyle(style, orient, edge);
  63188. return style;
  63189. });
  63190. mainGroup.add(curve);
  63191. edgeData.setItemGraphicEl(edge.dataIndex, curve);
  63192. var focus = emphasisModel.get('focus');
  63193. toggleHoverEmphasis(curve, focus === 'adjacency' ? edge.getAdjacentDataIndices() : focus === 'trajectory' ? edge.getTrajectoryDataIndices() : focus, emphasisModel.get('blurScope'), emphasisModel.get('disabled'));
  63194. });
  63195. // Generate a rect for each node
  63196. graph.eachNode(function (node) {
  63197. var layout = node.getLayout();
  63198. var itemModel = node.getModel();
  63199. var dragX = itemModel.get('localX');
  63200. var dragY = itemModel.get('localY');
  63201. var emphasisModel = itemModel.getModel('emphasis');
  63202. var borderRadius = itemModel.get(['itemStyle', 'borderRadius']) || 0;
  63203. var rect = new Rect({
  63204. shape: {
  63205. x: dragX != null ? dragX * width : layout.x,
  63206. y: dragY != null ? dragY * height : layout.y,
  63207. width: layout.dx,
  63208. height: layout.dy,
  63209. r: borderRadius
  63210. },
  63211. style: itemModel.getModel('itemStyle').getItemStyle(),
  63212. z2: 10
  63213. });
  63214. setLabelStyle(rect, getLabelStatesModels(itemModel), {
  63215. labelFetcher: {
  63216. getFormattedLabel: function (dataIndex, stateName) {
  63217. return seriesModel.getFormattedLabel(dataIndex, stateName, 'node');
  63218. }
  63219. },
  63220. labelDataIndex: node.dataIndex,
  63221. defaultText: node.id
  63222. });
  63223. rect.disableLabelAnimation = true;
  63224. rect.setStyle('fill', node.getVisual('color'));
  63225. rect.setStyle('decal', node.getVisual('style').decal);
  63226. setStatesStylesFromModel(rect, itemModel);
  63227. mainGroup.add(rect);
  63228. nodeData.setItemGraphicEl(node.dataIndex, rect);
  63229. getECData(rect).dataType = 'node';
  63230. var focus = emphasisModel.get('focus');
  63231. toggleHoverEmphasis(rect, focus === 'adjacency' ? node.getAdjacentDataIndices() : focus === 'trajectory' ? node.getTrajectoryDataIndices() : focus, emphasisModel.get('blurScope'), emphasisModel.get('disabled'));
  63232. });
  63233. nodeData.eachItemGraphicEl(function (el, dataIndex) {
  63234. var itemModel = nodeData.getItemModel(dataIndex);
  63235. if (itemModel.get('draggable')) {
  63236. el.drift = function (dx, dy) {
  63237. sankeyView._focusAdjacencyDisabled = true;
  63238. this.shape.x += dx;
  63239. this.shape.y += dy;
  63240. this.dirty();
  63241. api.dispatchAction({
  63242. type: 'dragNode',
  63243. seriesId: seriesModel.id,
  63244. dataIndex: nodeData.getRawIndex(dataIndex),
  63245. localX: this.shape.x / width,
  63246. localY: this.shape.y / height
  63247. });
  63248. };
  63249. el.ondragend = function () {
  63250. sankeyView._focusAdjacencyDisabled = false;
  63251. };
  63252. el.draggable = true;
  63253. el.cursor = 'move';
  63254. }
  63255. });
  63256. if (!this._data && seriesModel.isAnimationEnabled()) {
  63257. mainGroup.setClipPath(createGridClipShape$1(mainGroup.getBoundingRect(), seriesModel, function () {
  63258. mainGroup.removeClipPath();
  63259. }));
  63260. }
  63261. this._data = seriesModel.getData();
  63262. };
  63263. SankeyView.prototype.dispose = function () {
  63264. this._controller && this._controller.dispose();
  63265. this._controllerHost = null;
  63266. };
  63267. SankeyView.prototype._updateViewCoordSys = function (seriesModel, api) {
  63268. var layoutInfo = seriesModel.layoutInfo;
  63269. var width = layoutInfo.width;
  63270. var height = layoutInfo.height;
  63271. var viewCoordSys = seriesModel.coordinateSystem = new View(null, {
  63272. api: api,
  63273. ecModel: seriesModel.ecModel
  63274. });
  63275. viewCoordSys.zoomLimit = seriesModel.get('scaleLimit');
  63276. viewCoordSys.setBoundingRect(0, 0, width, height);
  63277. viewCoordSys.setCenter(seriesModel.get('center'));
  63278. viewCoordSys.setZoom(seriesModel.get('zoom'));
  63279. this._controllerHost.target.attr({
  63280. x: viewCoordSys.x,
  63281. y: viewCoordSys.y,
  63282. scaleX: viewCoordSys.scaleX,
  63283. scaleY: viewCoordSys.scaleY
  63284. });
  63285. };
  63286. SankeyView.type = 'sankey';
  63287. return SankeyView;
  63288. }(ChartView);
  63289. /**
  63290. * Special color, use source node color or target node color
  63291. * @param curveProps curve's style to parse
  63292. * @param orient direction
  63293. * @param edge current curve data
  63294. */
  63295. function applyCurveStyle(curveProps, orient, edge) {
  63296. switch (curveProps.fill) {
  63297. case 'source':
  63298. curveProps.fill = edge.node1.getVisual('color');
  63299. curveProps.decal = edge.node1.getVisual('style').decal;
  63300. break;
  63301. case 'target':
  63302. curveProps.fill = edge.node2.getVisual('color');
  63303. curveProps.decal = edge.node2.getVisual('style').decal;
  63304. break;
  63305. case 'gradient':
  63306. var sourceColor = edge.node1.getVisual('color');
  63307. var targetColor = edge.node2.getVisual('color');
  63308. if (isString(sourceColor) && isString(targetColor)) {
  63309. curveProps.fill = new LinearGradient(0, 0, +(orient === 'horizontal'), +(orient === 'vertical'), [{
  63310. color: sourceColor,
  63311. offset: 0
  63312. }, {
  63313. color: targetColor,
  63314. offset: 1
  63315. }]);
  63316. }
  63317. }
  63318. }
  63319. // Add animation to the view
  63320. function createGridClipShape$1(rect, seriesModel, cb) {
  63321. var rectEl = new Rect({
  63322. shape: {
  63323. x: rect.x - 10,
  63324. y: rect.y - 10,
  63325. width: 0,
  63326. height: rect.height + 20
  63327. }
  63328. });
  63329. initProps(rectEl, {
  63330. shape: {
  63331. width: rect.width + 20
  63332. }
  63333. }, seriesModel, cb);
  63334. return rectEl;
  63335. }
  63336. var SankeySeriesModel = /** @class */function (_super) {
  63337. __extends(SankeySeriesModel, _super);
  63338. function SankeySeriesModel() {
  63339. var _this = _super !== null && _super.apply(this, arguments) || this;
  63340. _this.type = SankeySeriesModel.type;
  63341. return _this;
  63342. }
  63343. /**
  63344. * Init a graph data structure from data in option series
  63345. */
  63346. SankeySeriesModel.prototype.getInitialData = function (option, ecModel) {
  63347. var links = option.edges || option.links || [];
  63348. var nodes = option.data || option.nodes || [];
  63349. var levels = option.levels || [];
  63350. this.levelModels = [];
  63351. var levelModels = this.levelModels;
  63352. for (var i = 0; i < levels.length; i++) {
  63353. if (levels[i].depth != null && levels[i].depth >= 0) {
  63354. levelModels[levels[i].depth] = new Model(levels[i], this, ecModel);
  63355. } else {
  63356. if ("development" !== 'production') {
  63357. throw new Error('levels[i].depth is mandatory and should be natural number');
  63358. }
  63359. }
  63360. }
  63361. var graph = createGraphFromNodeEdge(nodes, links, this, true, beforeLink);
  63362. return graph.data;
  63363. function beforeLink(nodeData, edgeData) {
  63364. nodeData.wrapMethod('getItemModel', function (model, idx) {
  63365. var seriesModel = model.parentModel;
  63366. var layout = seriesModel.getData().getItemLayout(idx);
  63367. if (layout) {
  63368. var nodeDepth = layout.depth;
  63369. var levelModel = seriesModel.levelModels[nodeDepth];
  63370. if (levelModel) {
  63371. model.parentModel = levelModel;
  63372. }
  63373. }
  63374. return model;
  63375. });
  63376. edgeData.wrapMethod('getItemModel', function (model, idx) {
  63377. var seriesModel = model.parentModel;
  63378. var edge = seriesModel.getGraph().getEdgeByIndex(idx);
  63379. var layout = edge.node1.getLayout();
  63380. if (layout) {
  63381. var depth = layout.depth;
  63382. var levelModel = seriesModel.levelModels[depth];
  63383. if (levelModel) {
  63384. model.parentModel = levelModel;
  63385. }
  63386. }
  63387. return model;
  63388. });
  63389. }
  63390. };
  63391. SankeySeriesModel.prototype.setNodePosition = function (dataIndex, localPosition) {
  63392. var nodes = this.option.data || this.option.nodes;
  63393. var dataItem = nodes[dataIndex];
  63394. dataItem.localX = localPosition[0];
  63395. dataItem.localY = localPosition[1];
  63396. };
  63397. SankeySeriesModel.prototype.setCenter = function (center) {
  63398. this.option.center = center;
  63399. };
  63400. SankeySeriesModel.prototype.setZoom = function (zoom) {
  63401. this.option.zoom = zoom;
  63402. };
  63403. /**
  63404. * Return the graphic data structure
  63405. *
  63406. * @return graphic data structure
  63407. */
  63408. SankeySeriesModel.prototype.getGraph = function () {
  63409. return this.getData().graph;
  63410. };
  63411. /**
  63412. * Get edge data of graphic data structure
  63413. *
  63414. * @return data structure of list
  63415. */
  63416. SankeySeriesModel.prototype.getEdgeData = function () {
  63417. return this.getGraph().edgeData;
  63418. };
  63419. SankeySeriesModel.prototype.formatTooltip = function (dataIndex, multipleSeries, dataType) {
  63420. function noValue(val) {
  63421. return isNaN(val) || val == null;
  63422. }
  63423. // dataType === 'node' or empty do not show tooltip by default
  63424. if (dataType === 'edge') {
  63425. var params = this.getDataParams(dataIndex, dataType);
  63426. var rawDataOpt = params.data;
  63427. var edgeValue = params.value;
  63428. var edgeName = rawDataOpt.source + ' -- ' + rawDataOpt.target;
  63429. return createTooltipMarkup('nameValue', {
  63430. name: edgeName,
  63431. value: edgeValue,
  63432. noValue: noValue(edgeValue)
  63433. });
  63434. }
  63435. // dataType === 'node'
  63436. else {
  63437. var node = this.getGraph().getNodeByIndex(dataIndex);
  63438. var value = node.getLayout().value;
  63439. var name_1 = this.getDataParams(dataIndex, dataType).data.name;
  63440. return createTooltipMarkup('nameValue', {
  63441. name: name_1 != null ? name_1 + '' : null,
  63442. value: value,
  63443. noValue: noValue(value)
  63444. });
  63445. }
  63446. };
  63447. SankeySeriesModel.prototype.optionUpdated = function () {};
  63448. // Override Series.getDataParams()
  63449. SankeySeriesModel.prototype.getDataParams = function (dataIndex, dataType) {
  63450. var params = _super.prototype.getDataParams.call(this, dataIndex, dataType);
  63451. if (params.value == null && dataType === 'node') {
  63452. var node = this.getGraph().getNodeByIndex(dataIndex);
  63453. var nodeValue = node.getLayout().value;
  63454. params.value = nodeValue;
  63455. }
  63456. return params;
  63457. };
  63458. SankeySeriesModel.type = 'series.sankey';
  63459. SankeySeriesModel.layoutMode = 'box';
  63460. SankeySeriesModel.defaultOption = {
  63461. // zlevel: 0,
  63462. z: 2,
  63463. // `coordinateSystem` can be declared as 'matrix', 'calendar',
  63464. // which provides box layout container.
  63465. coordinateSystemUsage: 'box',
  63466. left: '5%',
  63467. top: '5%',
  63468. right: '20%',
  63469. bottom: '5%',
  63470. orient: 'horizontal',
  63471. nodeWidth: 20,
  63472. nodeGap: 8,
  63473. draggable: true,
  63474. layoutIterations: 32,
  63475. // true | false | 'move' | 'scale', see module:component/helper/RoamController.
  63476. roam: false,
  63477. roamTrigger: 'global',
  63478. center: null,
  63479. zoom: 1,
  63480. label: {
  63481. show: true,
  63482. position: 'right',
  63483. fontSize: 12
  63484. },
  63485. edgeLabel: {
  63486. show: false,
  63487. fontSize: 12
  63488. },
  63489. levels: [],
  63490. nodeAlign: 'justify',
  63491. lineStyle: {
  63492. color: tokens.color.neutral50,
  63493. opacity: 0.2,
  63494. curveness: 0.5
  63495. },
  63496. emphasis: {
  63497. label: {
  63498. show: true
  63499. },
  63500. lineStyle: {
  63501. opacity: 0.5
  63502. }
  63503. },
  63504. select: {
  63505. itemStyle: {
  63506. borderColor: tokens.color.primary
  63507. }
  63508. },
  63509. animationEasing: 'linear',
  63510. animationDuration: 1000
  63511. };
  63512. return SankeySeriesModel;
  63513. }(SeriesModel);
  63514. function sankeyLayout(ecModel, api) {
  63515. ecModel.eachSeriesByType('sankey', function (seriesModel) {
  63516. var nodeWidth = seriesModel.get('nodeWidth');
  63517. var nodeGap = seriesModel.get('nodeGap');
  63518. var refContainer = createBoxLayoutReference(seriesModel, api).refContainer;
  63519. var layoutInfo = getLayoutRect(seriesModel.getBoxLayoutParams(), refContainer);
  63520. seriesModel.layoutInfo = layoutInfo;
  63521. var width = layoutInfo.width;
  63522. var height = layoutInfo.height;
  63523. var graph = seriesModel.getGraph();
  63524. var nodes = graph.nodes;
  63525. var edges = graph.edges;
  63526. computeNodeValues(nodes);
  63527. var filteredNodes = filter(nodes, function (node) {
  63528. return node.getLayout().value === 0;
  63529. });
  63530. var iterations = filteredNodes.length !== 0 ? 0 : seriesModel.get('layoutIterations');
  63531. var orient = seriesModel.get('orient');
  63532. var nodeAlign = seriesModel.get('nodeAlign');
  63533. layoutSankey(nodes, edges, nodeWidth, nodeGap, width, height, iterations, orient, nodeAlign);
  63534. });
  63535. }
  63536. function layoutSankey(nodes, edges, nodeWidth, nodeGap, width, height, iterations, orient, nodeAlign) {
  63537. computeNodeBreadths(nodes, edges, nodeWidth, width, height, orient, nodeAlign);
  63538. computeNodeDepths(nodes, edges, height, width, nodeGap, iterations, orient);
  63539. computeEdgeDepths(nodes, orient);
  63540. }
  63541. /**
  63542. * Compute the value of each node by summing the associated edge's value
  63543. */
  63544. function computeNodeValues(nodes) {
  63545. each(nodes, function (node) {
  63546. var value1 = sum(node.outEdges, getEdgeValue);
  63547. var value2 = sum(node.inEdges, getEdgeValue);
  63548. var nodeRawValue = node.getValue() || 0;
  63549. var value = Math.max(value1, value2, nodeRawValue);
  63550. node.setLayout({
  63551. value: value
  63552. }, true);
  63553. });
  63554. }
  63555. /**
  63556. * Compute the x-position for each node.
  63557. *
  63558. * Here we use Kahn algorithm to detect cycle when we traverse
  63559. * the node to computer the initial x position.
  63560. */
  63561. function computeNodeBreadths(nodes, edges, nodeWidth, width, height, orient, nodeAlign) {
  63562. // Used to mark whether the edge is deleted. if it is deleted,
  63563. // the value is 0, otherwise it is 1.
  63564. var remainEdges = [];
  63565. // Storage each node's indegree.
  63566. var indegreeArr = [];
  63567. // Used to storage the node with indegree is equal to 0.
  63568. var zeroIndegrees = [];
  63569. var nextTargetNode = [];
  63570. var x = 0;
  63571. // let kx = 0;
  63572. for (var i = 0; i < edges.length; i++) {
  63573. remainEdges[i] = 1;
  63574. }
  63575. for (var i = 0; i < nodes.length; i++) {
  63576. indegreeArr[i] = nodes[i].inEdges.length;
  63577. if (indegreeArr[i] === 0) {
  63578. zeroIndegrees.push(nodes[i]);
  63579. }
  63580. }
  63581. var maxNodeDepth = -1;
  63582. // Traversing nodes using topological sorting to calculate the
  63583. // horizontal(if orient === 'horizontal') or vertical(if orient === 'vertical')
  63584. // position of the nodes.
  63585. while (zeroIndegrees.length) {
  63586. for (var idx = 0; idx < zeroIndegrees.length; idx++) {
  63587. var node = zeroIndegrees[idx];
  63588. var item = node.hostGraph.data.getRawDataItem(node.dataIndex);
  63589. var isItemDepth = item.depth != null && item.depth >= 0;
  63590. if (isItemDepth && item.depth > maxNodeDepth) {
  63591. maxNodeDepth = item.depth;
  63592. }
  63593. node.setLayout({
  63594. depth: isItemDepth ? item.depth : x
  63595. }, true);
  63596. orient === 'vertical' ? node.setLayout({
  63597. dy: nodeWidth
  63598. }, true) : node.setLayout({
  63599. dx: nodeWidth
  63600. }, true);
  63601. for (var edgeIdx = 0; edgeIdx < node.outEdges.length; edgeIdx++) {
  63602. var edge = node.outEdges[edgeIdx];
  63603. var indexEdge = edges.indexOf(edge);
  63604. remainEdges[indexEdge] = 0;
  63605. var targetNode = edge.node2;
  63606. var nodeIndex = nodes.indexOf(targetNode);
  63607. if (--indegreeArr[nodeIndex] === 0 && nextTargetNode.indexOf(targetNode) < 0) {
  63608. nextTargetNode.push(targetNode);
  63609. }
  63610. }
  63611. }
  63612. ++x;
  63613. zeroIndegrees = nextTargetNode;
  63614. nextTargetNode = [];
  63615. }
  63616. for (var i = 0; i < remainEdges.length; i++) {
  63617. if (remainEdges[i] === 1) {
  63618. throw new Error('Sankey is a DAG, the original data has cycle!');
  63619. }
  63620. }
  63621. var maxDepth = maxNodeDepth > x - 1 ? maxNodeDepth : x - 1;
  63622. if (nodeAlign && nodeAlign !== 'left') {
  63623. adjustNodeWithNodeAlign(nodes, nodeAlign, orient, maxDepth);
  63624. }
  63625. var kx = orient === 'vertical' ? (height - nodeWidth) / maxDepth : (width - nodeWidth) / maxDepth;
  63626. scaleNodeBreadths(nodes, kx, orient);
  63627. }
  63628. function isNodeDepth(node) {
  63629. var item = node.hostGraph.data.getRawDataItem(node.dataIndex);
  63630. return item.depth != null && item.depth >= 0;
  63631. }
  63632. function adjustNodeWithNodeAlign(nodes, nodeAlign, orient, maxDepth) {
  63633. if (nodeAlign === 'right') {
  63634. var nextSourceNode = [];
  63635. var remainNodes = nodes;
  63636. var nodeHeight = 0;
  63637. while (remainNodes.length) {
  63638. for (var i = 0; i < remainNodes.length; i++) {
  63639. var node = remainNodes[i];
  63640. node.setLayout({
  63641. skNodeHeight: nodeHeight
  63642. }, true);
  63643. for (var j = 0; j < node.inEdges.length; j++) {
  63644. var edge = node.inEdges[j];
  63645. if (nextSourceNode.indexOf(edge.node1) < 0) {
  63646. nextSourceNode.push(edge.node1);
  63647. }
  63648. }
  63649. }
  63650. remainNodes = nextSourceNode;
  63651. nextSourceNode = [];
  63652. ++nodeHeight;
  63653. }
  63654. each(nodes, function (node) {
  63655. if (!isNodeDepth(node)) {
  63656. node.setLayout({
  63657. depth: Math.max(0, maxDepth - node.getLayout().skNodeHeight)
  63658. }, true);
  63659. }
  63660. });
  63661. } else if (nodeAlign === 'justify') {
  63662. moveSinksRight(nodes, maxDepth);
  63663. }
  63664. }
  63665. /**
  63666. * All the node without outEgdes are assigned maximum x-position and
  63667. * be aligned in the last column.
  63668. *
  63669. * @param nodes. node of sankey view.
  63670. * @param maxDepth. use to assign to node without outEdges as x-position.
  63671. */
  63672. function moveSinksRight(nodes, maxDepth) {
  63673. each(nodes, function (node) {
  63674. if (!isNodeDepth(node) && !node.outEdges.length) {
  63675. node.setLayout({
  63676. depth: maxDepth
  63677. }, true);
  63678. }
  63679. });
  63680. }
  63681. /**
  63682. * Scale node x-position to the width
  63683. *
  63684. * @param nodes node of sankey view
  63685. * @param kx multiple used to scale nodes
  63686. */
  63687. function scaleNodeBreadths(nodes, kx, orient) {
  63688. each(nodes, function (node) {
  63689. var nodeDepth = node.getLayout().depth * kx;
  63690. orient === 'vertical' ? node.setLayout({
  63691. y: nodeDepth
  63692. }, true) : node.setLayout({
  63693. x: nodeDepth
  63694. }, true);
  63695. });
  63696. }
  63697. /**
  63698. * Using Gauss-Seidel iterations method to compute the node depth(y-position)
  63699. *
  63700. * @param nodes node of sankey view
  63701. * @param edges edge of sankey view
  63702. * @param height the whole height of the area to draw the view
  63703. * @param nodeGap the vertical distance between two nodes
  63704. * in the same column.
  63705. * @param iterations the number of iterations for the algorithm
  63706. */
  63707. function computeNodeDepths(nodes, edges, height, width, nodeGap, iterations, orient) {
  63708. var nodesByBreadth = prepareNodesByBreadth(nodes, orient);
  63709. initializeNodeDepth(nodesByBreadth, edges, height, width, nodeGap, orient);
  63710. resolveCollisions(nodesByBreadth, nodeGap, height, width, orient);
  63711. for (var alpha = 1; iterations > 0; iterations--) {
  63712. // 0.99 is a experience parameter, ensure that each iterations of
  63713. // changes as small as possible.
  63714. alpha *= 0.99;
  63715. relaxRightToLeft(nodesByBreadth, alpha, orient);
  63716. resolveCollisions(nodesByBreadth, nodeGap, height, width, orient);
  63717. relaxLeftToRight(nodesByBreadth, alpha, orient);
  63718. resolveCollisions(nodesByBreadth, nodeGap, height, width, orient);
  63719. }
  63720. }
  63721. function prepareNodesByBreadth(nodes, orient) {
  63722. var nodesByBreadth = [];
  63723. var keyAttr = orient === 'vertical' ? 'y' : 'x';
  63724. var groupResult = groupData(nodes, function (node) {
  63725. return node.getLayout()[keyAttr];
  63726. });
  63727. groupResult.keys.sort(function (a, b) {
  63728. return a - b;
  63729. });
  63730. each(groupResult.keys, function (key) {
  63731. nodesByBreadth.push(groupResult.buckets.get(key));
  63732. });
  63733. return nodesByBreadth;
  63734. }
  63735. /**
  63736. * Compute the original y-position for each node
  63737. */
  63738. function initializeNodeDepth(nodesByBreadth, edges, height, width, nodeGap, orient) {
  63739. var minKy = Infinity;
  63740. each(nodesByBreadth, function (nodes) {
  63741. var n = nodes.length;
  63742. var sum = 0;
  63743. each(nodes, function (node) {
  63744. sum += node.getLayout().value;
  63745. });
  63746. var ky = orient === 'vertical' ? (width - (n - 1) * nodeGap) / sum : (height - (n - 1) * nodeGap) / sum;
  63747. if (ky < minKy) {
  63748. minKy = ky;
  63749. }
  63750. });
  63751. each(nodesByBreadth, function (nodes) {
  63752. each(nodes, function (node, i) {
  63753. var nodeDy = node.getLayout().value * minKy;
  63754. if (orient === 'vertical') {
  63755. node.setLayout({
  63756. x: i
  63757. }, true);
  63758. node.setLayout({
  63759. dx: nodeDy
  63760. }, true);
  63761. } else {
  63762. node.setLayout({
  63763. y: i
  63764. }, true);
  63765. node.setLayout({
  63766. dy: nodeDy
  63767. }, true);
  63768. }
  63769. });
  63770. });
  63771. each(edges, function (edge) {
  63772. var edgeDy = +edge.getValue() * minKy;
  63773. edge.setLayout({
  63774. dy: edgeDy
  63775. }, true);
  63776. });
  63777. }
  63778. /**
  63779. * Resolve the collision of initialized depth (y-position)
  63780. */
  63781. function resolveCollisions(nodesByBreadth, nodeGap, height, width, orient) {
  63782. var keyAttr = orient === 'vertical' ? 'x' : 'y';
  63783. each(nodesByBreadth, function (nodes) {
  63784. nodes.sort(function (a, b) {
  63785. return a.getLayout()[keyAttr] - b.getLayout()[keyAttr];
  63786. });
  63787. var nodeX;
  63788. var node;
  63789. var dy;
  63790. var y0 = 0;
  63791. var n = nodes.length;
  63792. var nodeDyAttr = orient === 'vertical' ? 'dx' : 'dy';
  63793. for (var i = 0; i < n; i++) {
  63794. node = nodes[i];
  63795. dy = y0 - node.getLayout()[keyAttr];
  63796. if (dy > 0) {
  63797. nodeX = node.getLayout()[keyAttr] + dy;
  63798. orient === 'vertical' ? node.setLayout({
  63799. x: nodeX
  63800. }, true) : node.setLayout({
  63801. y: nodeX
  63802. }, true);
  63803. }
  63804. y0 = node.getLayout()[keyAttr] + node.getLayout()[nodeDyAttr] + nodeGap;
  63805. }
  63806. var viewWidth = orient === 'vertical' ? width : height;
  63807. // If the bottommost node goes outside the bounds, push it back up
  63808. dy = y0 - nodeGap - viewWidth;
  63809. if (dy > 0) {
  63810. nodeX = node.getLayout()[keyAttr] - dy;
  63811. orient === 'vertical' ? node.setLayout({
  63812. x: nodeX
  63813. }, true) : node.setLayout({
  63814. y: nodeX
  63815. }, true);
  63816. y0 = nodeX;
  63817. for (var i = n - 2; i >= 0; --i) {
  63818. node = nodes[i];
  63819. dy = node.getLayout()[keyAttr] + node.getLayout()[nodeDyAttr] + nodeGap - y0;
  63820. if (dy > 0) {
  63821. nodeX = node.getLayout()[keyAttr] - dy;
  63822. orient === 'vertical' ? node.setLayout({
  63823. x: nodeX
  63824. }, true) : node.setLayout({
  63825. y: nodeX
  63826. }, true);
  63827. }
  63828. y0 = node.getLayout()[keyAttr];
  63829. }
  63830. }
  63831. });
  63832. }
  63833. /**
  63834. * Change the y-position of the nodes, except most the right side nodes
  63835. * @param nodesByBreadth
  63836. * @param alpha parameter used to adjust the nodes y-position
  63837. */
  63838. function relaxRightToLeft(nodesByBreadth, alpha, orient) {
  63839. each(nodesByBreadth.slice().reverse(), function (nodes) {
  63840. each(nodes, function (node) {
  63841. if (node.outEdges.length) {
  63842. var y = sum(node.outEdges, weightedTarget, orient) / sum(node.outEdges, getEdgeValue);
  63843. if (isNaN(y)) {
  63844. var len = node.outEdges.length;
  63845. y = len ? sum(node.outEdges, centerTarget, orient) / len : 0;
  63846. }
  63847. if (orient === 'vertical') {
  63848. var nodeX = node.getLayout().x + (y - center$1(node, orient)) * alpha;
  63849. node.setLayout({
  63850. x: nodeX
  63851. }, true);
  63852. } else {
  63853. var nodeY = node.getLayout().y + (y - center$1(node, orient)) * alpha;
  63854. node.setLayout({
  63855. y: nodeY
  63856. }, true);
  63857. }
  63858. }
  63859. });
  63860. });
  63861. }
  63862. function weightedTarget(edge, orient) {
  63863. return center$1(edge.node2, orient) * edge.getValue();
  63864. }
  63865. function centerTarget(edge, orient) {
  63866. return center$1(edge.node2, orient);
  63867. }
  63868. function weightedSource(edge, orient) {
  63869. return center$1(edge.node1, orient) * edge.getValue();
  63870. }
  63871. function centerSource(edge, orient) {
  63872. return center$1(edge.node1, orient);
  63873. }
  63874. function center$1(node, orient) {
  63875. return orient === 'vertical' ? node.getLayout().x + node.getLayout().dx / 2 : node.getLayout().y + node.getLayout().dy / 2;
  63876. }
  63877. function getEdgeValue(edge) {
  63878. return edge.getValue();
  63879. }
  63880. function sum(array, cb, orient) {
  63881. var sum = 0;
  63882. var len = array.length;
  63883. var i = -1;
  63884. while (++i < len) {
  63885. var value = +cb(array[i], orient);
  63886. if (!isNaN(value)) {
  63887. sum += value;
  63888. }
  63889. }
  63890. return sum;
  63891. }
  63892. /**
  63893. * Change the y-position of the nodes, except most the left side nodes
  63894. */
  63895. function relaxLeftToRight(nodesByBreadth, alpha, orient) {
  63896. each(nodesByBreadth, function (nodes) {
  63897. each(nodes, function (node) {
  63898. if (node.inEdges.length) {
  63899. var y = sum(node.inEdges, weightedSource, orient) / sum(node.inEdges, getEdgeValue);
  63900. if (isNaN(y)) {
  63901. var len = node.inEdges.length;
  63902. y = len ? sum(node.inEdges, centerSource, orient) / len : 0;
  63903. }
  63904. if (orient === 'vertical') {
  63905. var nodeX = node.getLayout().x + (y - center$1(node, orient)) * alpha;
  63906. node.setLayout({
  63907. x: nodeX
  63908. }, true);
  63909. } else {
  63910. var nodeY = node.getLayout().y + (y - center$1(node, orient)) * alpha;
  63911. node.setLayout({
  63912. y: nodeY
  63913. }, true);
  63914. }
  63915. }
  63916. });
  63917. });
  63918. }
  63919. /**
  63920. * Compute the depth(y-position) of each edge
  63921. */
  63922. function computeEdgeDepths(nodes, orient) {
  63923. var keyAttr = orient === 'vertical' ? 'x' : 'y';
  63924. each(nodes, function (node) {
  63925. node.outEdges.sort(function (a, b) {
  63926. return a.node2.getLayout()[keyAttr] - b.node2.getLayout()[keyAttr];
  63927. });
  63928. node.inEdges.sort(function (a, b) {
  63929. return a.node1.getLayout()[keyAttr] - b.node1.getLayout()[keyAttr];
  63930. });
  63931. });
  63932. each(nodes, function (node) {
  63933. var sy = 0;
  63934. var ty = 0;
  63935. each(node.outEdges, function (edge) {
  63936. edge.setLayout({
  63937. sy: sy
  63938. }, true);
  63939. sy += edge.getLayout().dy;
  63940. });
  63941. each(node.inEdges, function (edge) {
  63942. edge.setLayout({
  63943. ty: ty
  63944. }, true);
  63945. ty += edge.getLayout().dy;
  63946. });
  63947. });
  63948. }
  63949. function sankeyVisual(ecModel) {
  63950. ecModel.eachSeriesByType('sankey', function (seriesModel) {
  63951. var graph = seriesModel.getGraph();
  63952. var nodes = graph.nodes;
  63953. var edges = graph.edges;
  63954. if (nodes.length) {
  63955. var minValue_1 = Infinity;
  63956. var maxValue_1 = -Infinity;
  63957. each(nodes, function (node) {
  63958. var nodeValue = node.getLayout().value;
  63959. if (nodeValue < minValue_1) {
  63960. minValue_1 = nodeValue;
  63961. }
  63962. if (nodeValue > maxValue_1) {
  63963. maxValue_1 = nodeValue;
  63964. }
  63965. });
  63966. each(nodes, function (node) {
  63967. var mapping = new VisualMapping({
  63968. type: 'color',
  63969. mappingMethod: 'linear',
  63970. dataExtent: [minValue_1, maxValue_1],
  63971. visual: seriesModel.get('color')
  63972. });
  63973. var mapValueToColor = mapping.mapValueToVisual(node.getLayout().value);
  63974. var customColor = node.getModel().get(['itemStyle', 'color']);
  63975. if (customColor != null) {
  63976. node.setVisual('color', customColor);
  63977. node.setVisual('style', {
  63978. fill: customColor
  63979. });
  63980. } else {
  63981. node.setVisual('color', mapValueToColor);
  63982. node.setVisual('style', {
  63983. fill: mapValueToColor
  63984. });
  63985. }
  63986. });
  63987. }
  63988. if (edges.length) {
  63989. each(edges, function (edge) {
  63990. var edgeStyle = edge.getModel().get('lineStyle');
  63991. edge.setVisual('style', edgeStyle);
  63992. });
  63993. }
  63994. });
  63995. }
  63996. function install$j(registers) {
  63997. registers.registerChartView(SankeyView);
  63998. registers.registerSeriesModel(SankeySeriesModel);
  63999. registers.registerLayout(sankeyLayout);
  64000. registers.registerVisual(sankeyVisual);
  64001. registers.registerAction({
  64002. type: 'dragNode',
  64003. event: 'dragnode',
  64004. // here can only use 'update' now, other value is not support in echarts.
  64005. update: 'update'
  64006. }, function (payload, ecModel) {
  64007. ecModel.eachComponent({
  64008. mainType: 'series',
  64009. subType: 'sankey',
  64010. query: payload
  64011. }, function (seriesModel) {
  64012. seriesModel.setNodePosition(payload.dataIndex, [payload.localX, payload.localY]);
  64013. });
  64014. });
  64015. registers.registerAction({
  64016. type: 'sankeyRoam',
  64017. event: 'sankeyRoam',
  64018. update: 'none'
  64019. }, function (payload, ecModel, api) {
  64020. ecModel.eachComponent({
  64021. mainType: 'series',
  64022. subType: 'sankey',
  64023. query: payload
  64024. }, function (seriesModel) {
  64025. var coordSys = seriesModel.coordinateSystem;
  64026. var res = updateCenterAndZoomInAction(coordSys, payload, seriesModel.get('scaleLimit'));
  64027. seriesModel.setCenter(res.center);
  64028. seriesModel.setZoom(res.zoom);
  64029. });
  64030. });
  64031. }
  64032. var WhiskerBoxCommonMixin = /** @class */function () {
  64033. function WhiskerBoxCommonMixin() {}
  64034. /**
  64035. * @private
  64036. */
  64037. WhiskerBoxCommonMixin.prototype._hasEncodeRule = function (key) {
  64038. var encodeRules = this.getEncode();
  64039. return encodeRules && encodeRules.get(key) != null;
  64040. };
  64041. /**
  64042. * @override
  64043. */
  64044. WhiskerBoxCommonMixin.prototype.getInitialData = function (option, ecModel) {
  64045. // When both types of xAxis and yAxis are 'value', layout is
  64046. // needed to be specified by user. Otherwise, layout can be
  64047. // judged by which axis is category.
  64048. var ordinalMeta;
  64049. var xAxisModel = ecModel.getComponent('xAxis', this.get('xAxisIndex'));
  64050. var yAxisModel = ecModel.getComponent('yAxis', this.get('yAxisIndex'));
  64051. var xAxisType = xAxisModel.get('type');
  64052. var yAxisType = yAxisModel.get('type');
  64053. var addOrdinal;
  64054. // FIXME
  64055. // Consider time axis.
  64056. if (xAxisType === 'category') {
  64057. option.layout = 'horizontal';
  64058. ordinalMeta = xAxisModel.getOrdinalMeta();
  64059. addOrdinal = !this._hasEncodeRule('x');
  64060. } else if (yAxisType === 'category') {
  64061. option.layout = 'vertical';
  64062. ordinalMeta = yAxisModel.getOrdinalMeta();
  64063. addOrdinal = !this._hasEncodeRule('y');
  64064. } else {
  64065. option.layout = option.layout || 'horizontal';
  64066. }
  64067. var coordDims = ['x', 'y'];
  64068. var baseAxisDimIndex = option.layout === 'horizontal' ? 0 : 1;
  64069. var baseAxisDim = this._baseAxisDim = coordDims[baseAxisDimIndex];
  64070. var otherAxisDim = coordDims[1 - baseAxisDimIndex];
  64071. var axisModels = [xAxisModel, yAxisModel];
  64072. var baseAxisType = axisModels[baseAxisDimIndex].get('type');
  64073. var otherAxisType = axisModels[1 - baseAxisDimIndex].get('type');
  64074. var data = option.data;
  64075. // Clone a new data for next setOption({}) usage.
  64076. // Avoid modifying current data will affect further update.
  64077. if (data && addOrdinal) {
  64078. var newOptionData_1 = [];
  64079. each(data, function (item, index) {
  64080. var newItem;
  64081. if (isArray(item)) {
  64082. newItem = item.slice();
  64083. // Modify current using data.
  64084. item.unshift(index);
  64085. } else if (isArray(item.value)) {
  64086. newItem = extend({}, item);
  64087. newItem.value = newItem.value.slice();
  64088. // Modify current using data.
  64089. item.value.unshift(index);
  64090. } else {
  64091. newItem = item;
  64092. }
  64093. newOptionData_1.push(newItem);
  64094. });
  64095. option.data = newOptionData_1;
  64096. }
  64097. var defaultValueDimensions = this.defaultValueDimensions;
  64098. var coordDimensions = [{
  64099. name: baseAxisDim,
  64100. type: getDimensionTypeByAxis(baseAxisType),
  64101. ordinalMeta: ordinalMeta,
  64102. otherDims: {
  64103. tooltip: false,
  64104. itemName: 0
  64105. },
  64106. dimsDef: ['base']
  64107. }, {
  64108. name: otherAxisDim,
  64109. type: getDimensionTypeByAxis(otherAxisType),
  64110. dimsDef: defaultValueDimensions.slice()
  64111. }];
  64112. return createSeriesDataSimply(this, {
  64113. coordDimensions: coordDimensions,
  64114. dimensionsCount: defaultValueDimensions.length + 1,
  64115. encodeDefaulter: curry(makeSeriesEncodeForAxisCoordSys, coordDimensions, this)
  64116. });
  64117. };
  64118. /**
  64119. * If horizontal, base axis is x, otherwise y.
  64120. * @override
  64121. */
  64122. WhiskerBoxCommonMixin.prototype.getBaseAxis = function () {
  64123. var dim = this._baseAxisDim;
  64124. return this.ecModel.getComponent(dim + 'Axis', this.get(dim + 'AxisIndex')).axis;
  64125. };
  64126. return WhiskerBoxCommonMixin;
  64127. }();
  64128. var BoxplotSeriesModel = /** @class */function (_super) {
  64129. __extends(BoxplotSeriesModel, _super);
  64130. function BoxplotSeriesModel() {
  64131. var _this = _super !== null && _super.apply(this, arguments) || this;
  64132. _this.type = BoxplotSeriesModel.type;
  64133. // TODO
  64134. // box width represents group size, so dimension should have 'size'.
  64135. /**
  64136. * @see <https://en.wikipedia.org/wiki/Box_plot>
  64137. * The meanings of 'min' and 'max' depend on user,
  64138. * and echarts do not need to know it.
  64139. * @readOnly
  64140. */
  64141. _this.defaultValueDimensions = [{
  64142. name: 'min',
  64143. defaultTooltip: true
  64144. }, {
  64145. name: 'Q1',
  64146. defaultTooltip: true
  64147. }, {
  64148. name: 'median',
  64149. defaultTooltip: true
  64150. }, {
  64151. name: 'Q3',
  64152. defaultTooltip: true
  64153. }, {
  64154. name: 'max',
  64155. defaultTooltip: true
  64156. }];
  64157. _this.visualDrawType = 'stroke';
  64158. return _this;
  64159. }
  64160. BoxplotSeriesModel.type = 'series.boxplot';
  64161. BoxplotSeriesModel.dependencies = ['xAxis', 'yAxis', 'grid'];
  64162. BoxplotSeriesModel.defaultOption = {
  64163. // zlevel: 0,
  64164. z: 2,
  64165. coordinateSystem: 'cartesian2d',
  64166. legendHoverLink: true,
  64167. layout: null,
  64168. boxWidth: [7, 50],
  64169. itemStyle: {
  64170. color: tokens.color.neutral00,
  64171. borderWidth: 1
  64172. },
  64173. emphasis: {
  64174. scale: true,
  64175. itemStyle: {
  64176. borderWidth: 2,
  64177. shadowBlur: 5,
  64178. shadowOffsetX: 1,
  64179. shadowOffsetY: 1,
  64180. shadowColor: tokens.color.shadow
  64181. }
  64182. },
  64183. animationDuration: 800
  64184. };
  64185. return BoxplotSeriesModel;
  64186. }(SeriesModel);
  64187. mixin(BoxplotSeriesModel, WhiskerBoxCommonMixin, true);
  64188. var BoxplotView = /** @class */function (_super) {
  64189. __extends(BoxplotView, _super);
  64190. function BoxplotView() {
  64191. var _this = _super !== null && _super.apply(this, arguments) || this;
  64192. _this.type = BoxplotView.type;
  64193. return _this;
  64194. }
  64195. BoxplotView.prototype.render = function (seriesModel, ecModel, api) {
  64196. var data = seriesModel.getData();
  64197. var group = this.group;
  64198. var oldData = this._data;
  64199. // There is no old data only when first rendering or switching from
  64200. // stream mode to normal mode, where previous elements should be removed.
  64201. if (!this._data) {
  64202. group.removeAll();
  64203. }
  64204. var constDim = seriesModel.get('layout') === 'horizontal' ? 1 : 0;
  64205. data.diff(oldData).add(function (newIdx) {
  64206. if (data.hasValue(newIdx)) {
  64207. var itemLayout = data.getItemLayout(newIdx);
  64208. var symbolEl = createNormalBox(itemLayout, data, newIdx, constDim, true);
  64209. data.setItemGraphicEl(newIdx, symbolEl);
  64210. group.add(symbolEl);
  64211. }
  64212. }).update(function (newIdx, oldIdx) {
  64213. var symbolEl = oldData.getItemGraphicEl(oldIdx);
  64214. // Empty data
  64215. if (!data.hasValue(newIdx)) {
  64216. group.remove(symbolEl);
  64217. return;
  64218. }
  64219. var itemLayout = data.getItemLayout(newIdx);
  64220. if (!symbolEl) {
  64221. symbolEl = createNormalBox(itemLayout, data, newIdx, constDim);
  64222. } else {
  64223. saveOldStyle(symbolEl);
  64224. updateNormalBoxData(itemLayout, symbolEl, data, newIdx);
  64225. }
  64226. group.add(symbolEl);
  64227. data.setItemGraphicEl(newIdx, symbolEl);
  64228. }).remove(function (oldIdx) {
  64229. var el = oldData.getItemGraphicEl(oldIdx);
  64230. el && group.remove(el);
  64231. }).execute();
  64232. this._data = data;
  64233. };
  64234. BoxplotView.prototype.remove = function (ecModel) {
  64235. var group = this.group;
  64236. var data = this._data;
  64237. this._data = null;
  64238. data && data.eachItemGraphicEl(function (el) {
  64239. el && group.remove(el);
  64240. });
  64241. };
  64242. BoxplotView.type = 'boxplot';
  64243. return BoxplotView;
  64244. }(ChartView);
  64245. var BoxPathShape = /** @class */function () {
  64246. function BoxPathShape() {}
  64247. return BoxPathShape;
  64248. }();
  64249. var BoxPath = /** @class */function (_super) {
  64250. __extends(BoxPath, _super);
  64251. function BoxPath(opts) {
  64252. var _this = _super.call(this, opts) || this;
  64253. _this.type = 'boxplotBoxPath';
  64254. return _this;
  64255. }
  64256. BoxPath.prototype.getDefaultShape = function () {
  64257. return new BoxPathShape();
  64258. };
  64259. BoxPath.prototype.buildPath = function (ctx, shape) {
  64260. var ends = shape.points;
  64261. var i = 0;
  64262. ctx.moveTo(ends[i][0], ends[i][1]);
  64263. i++;
  64264. for (; i < 4; i++) {
  64265. ctx.lineTo(ends[i][0], ends[i][1]);
  64266. }
  64267. ctx.closePath();
  64268. for (; i < ends.length; i++) {
  64269. ctx.moveTo(ends[i][0], ends[i][1]);
  64270. i++;
  64271. ctx.lineTo(ends[i][0], ends[i][1]);
  64272. }
  64273. };
  64274. return BoxPath;
  64275. }(Path);
  64276. function createNormalBox(itemLayout, data, dataIndex, constDim, isInit) {
  64277. var ends = itemLayout.ends;
  64278. var el = new BoxPath({
  64279. shape: {
  64280. points: isInit ? transInit(ends, constDim, itemLayout) : ends
  64281. }
  64282. });
  64283. updateNormalBoxData(itemLayout, el, data, dataIndex, isInit);
  64284. return el;
  64285. }
  64286. function updateNormalBoxData(itemLayout, el, data, dataIndex, isInit) {
  64287. var seriesModel = data.hostModel;
  64288. var updateMethod = graphic[isInit ? 'initProps' : 'updateProps'];
  64289. updateMethod(el, {
  64290. shape: {
  64291. points: itemLayout.ends
  64292. }
  64293. }, seriesModel, dataIndex);
  64294. el.useStyle(data.getItemVisual(dataIndex, 'style'));
  64295. el.style.strokeNoScale = true;
  64296. el.z2 = 100;
  64297. var itemModel = data.getItemModel(dataIndex);
  64298. var emphasisModel = itemModel.getModel('emphasis');
  64299. setStatesStylesFromModel(el, itemModel);
  64300. toggleHoverEmphasis(el, emphasisModel.get('focus'), emphasisModel.get('blurScope'), emphasisModel.get('disabled'));
  64301. }
  64302. function transInit(points, dim, itemLayout) {
  64303. return map(points, function (point) {
  64304. point = point.slice();
  64305. point[dim] = itemLayout.initBaseline;
  64306. return point;
  64307. });
  64308. }
  64309. var each$6 = each;
  64310. function boxplotLayout(ecModel) {
  64311. var groupResult = groupSeriesByAxis(ecModel);
  64312. each$6(groupResult, function (groupItem) {
  64313. var seriesModels = groupItem.seriesModels;
  64314. if (!seriesModels.length) {
  64315. return;
  64316. }
  64317. calculateBase(groupItem);
  64318. each$6(seriesModels, function (seriesModel, idx) {
  64319. layoutSingleSeries(seriesModel, groupItem.boxOffsetList[idx], groupItem.boxWidthList[idx]);
  64320. });
  64321. });
  64322. }
  64323. /**
  64324. * Group series by axis.
  64325. */
  64326. function groupSeriesByAxis(ecModel) {
  64327. var result = [];
  64328. var axisList = [];
  64329. ecModel.eachSeriesByType('boxplot', function (seriesModel) {
  64330. var baseAxis = seriesModel.getBaseAxis();
  64331. var idx = indexOf(axisList, baseAxis);
  64332. if (idx < 0) {
  64333. idx = axisList.length;
  64334. axisList[idx] = baseAxis;
  64335. result[idx] = {
  64336. axis: baseAxis,
  64337. seriesModels: []
  64338. };
  64339. }
  64340. result[idx].seriesModels.push(seriesModel);
  64341. });
  64342. return result;
  64343. }
  64344. /**
  64345. * Calculate offset and box width for each series.
  64346. */
  64347. function calculateBase(groupItem) {
  64348. var baseAxis = groupItem.axis;
  64349. var seriesModels = groupItem.seriesModels;
  64350. var seriesCount = seriesModels.length;
  64351. var boxWidthList = groupItem.boxWidthList = [];
  64352. var boxOffsetList = groupItem.boxOffsetList = [];
  64353. var boundList = [];
  64354. var bandWidth;
  64355. if (baseAxis.type === 'category') {
  64356. bandWidth = baseAxis.getBandWidth();
  64357. } else {
  64358. var maxDataCount_1 = 0;
  64359. each$6(seriesModels, function (seriesModel) {
  64360. maxDataCount_1 = Math.max(maxDataCount_1, seriesModel.getData().count());
  64361. });
  64362. var extent = baseAxis.getExtent();
  64363. bandWidth = Math.abs(extent[1] - extent[0]) / maxDataCount_1;
  64364. }
  64365. each$6(seriesModels, function (seriesModel) {
  64366. var boxWidthBound = seriesModel.get('boxWidth');
  64367. if (!isArray(boxWidthBound)) {
  64368. boxWidthBound = [boxWidthBound, boxWidthBound];
  64369. }
  64370. boundList.push([parsePercent$1(boxWidthBound[0], bandWidth) || 0, parsePercent$1(boxWidthBound[1], bandWidth) || 0]);
  64371. });
  64372. var availableWidth = bandWidth * 0.8 - 2;
  64373. var boxGap = availableWidth / seriesCount * 0.3;
  64374. var boxWidth = (availableWidth - boxGap * (seriesCount - 1)) / seriesCount;
  64375. var base = boxWidth / 2 - availableWidth / 2;
  64376. each$6(seriesModels, function (seriesModel, idx) {
  64377. boxOffsetList.push(base);
  64378. base += boxGap + boxWidth;
  64379. boxWidthList.push(Math.min(Math.max(boxWidth, boundList[idx][0]), boundList[idx][1]));
  64380. });
  64381. }
  64382. /**
  64383. * Calculate points location for each series.
  64384. */
  64385. function layoutSingleSeries(seriesModel, offset, boxWidth) {
  64386. var coordSys = seriesModel.coordinateSystem;
  64387. var data = seriesModel.getData();
  64388. var halfWidth = boxWidth / 2;
  64389. var cDimIdx = seriesModel.get('layout') === 'horizontal' ? 0 : 1;
  64390. var vDimIdx = 1 - cDimIdx;
  64391. var coordDims = ['x', 'y'];
  64392. var cDim = data.mapDimension(coordDims[cDimIdx]);
  64393. var vDims = data.mapDimensionsAll(coordDims[vDimIdx]);
  64394. if (cDim == null || vDims.length < 5) {
  64395. return;
  64396. }
  64397. for (var dataIndex = 0; dataIndex < data.count(); dataIndex++) {
  64398. var axisDimVal = data.get(cDim, dataIndex);
  64399. var median = getPoint(axisDimVal, vDims[2], dataIndex);
  64400. var end1 = getPoint(axisDimVal, vDims[0], dataIndex);
  64401. var end2 = getPoint(axisDimVal, vDims[1], dataIndex);
  64402. var end4 = getPoint(axisDimVal, vDims[3], dataIndex);
  64403. var end5 = getPoint(axisDimVal, vDims[4], dataIndex);
  64404. var ends = [];
  64405. addBodyEnd(ends, end2, false);
  64406. addBodyEnd(ends, end4, true);
  64407. ends.push(end1, end2, end5, end4);
  64408. layEndLine(ends, end1);
  64409. layEndLine(ends, end5);
  64410. layEndLine(ends, median);
  64411. data.setItemLayout(dataIndex, {
  64412. initBaseline: median[vDimIdx],
  64413. ends: ends
  64414. });
  64415. }
  64416. function getPoint(axisDimVal, dim, dataIndex) {
  64417. var val = data.get(dim, dataIndex);
  64418. var p = [];
  64419. p[cDimIdx] = axisDimVal;
  64420. p[vDimIdx] = val;
  64421. var point;
  64422. if (isNaN(axisDimVal) || isNaN(val)) {
  64423. point = [NaN, NaN];
  64424. } else {
  64425. point = coordSys.dataToPoint(p);
  64426. point[cDimIdx] += offset;
  64427. }
  64428. return point;
  64429. }
  64430. function addBodyEnd(ends, point, start) {
  64431. var point1 = point.slice();
  64432. var point2 = point.slice();
  64433. point1[cDimIdx] += halfWidth;
  64434. point2[cDimIdx] -= halfWidth;
  64435. start ? ends.push(point1, point2) : ends.push(point2, point1);
  64436. }
  64437. function layEndLine(ends, endCenter) {
  64438. var from = endCenter.slice();
  64439. var to = endCenter.slice();
  64440. from[cDimIdx] -= halfWidth;
  64441. to[cDimIdx] += halfWidth;
  64442. ends.push(from, to);
  64443. }
  64444. }
  64445. /**
  64446. * See:
  64447. * <https://en.wikipedia.org/wiki/Box_plot#cite_note-frigge_hoaglin_iglewicz-2>
  64448. * <http://stat.ethz.ch/R-manual/R-devel/library/grDevices/html/boxplot.stats.html>
  64449. *
  64450. * Helper method for preparing data.
  64451. *
  64452. * @param rawData like
  64453. * [
  64454. * [12,232,443], (raw data set for the first box)
  64455. * [3843,5545,1232], (raw data set for the second box)
  64456. * ...
  64457. * ]
  64458. * @param opt.boundIQR=1.5 Data less than min bound is outlier.
  64459. * default 1.5, means Q1 - 1.5 * (Q3 - Q1).
  64460. * If 'none'/0 passed, min bound will not be used.
  64461. */
  64462. function prepareBoxplotData(rawData, opt) {
  64463. opt = opt || {};
  64464. var boxData = [];
  64465. var outliers = [];
  64466. var boundIQR = opt.boundIQR;
  64467. var useExtreme = boundIQR === 'none' || boundIQR === 0;
  64468. for (var i = 0; i < rawData.length; i++) {
  64469. var ascList = asc(rawData[i].slice());
  64470. var Q1 = quantile(ascList, 0.25);
  64471. var Q2 = quantile(ascList, 0.5);
  64472. var Q3 = quantile(ascList, 0.75);
  64473. var min = ascList[0];
  64474. var max = ascList[ascList.length - 1];
  64475. var bound = (boundIQR == null ? 1.5 : boundIQR) * (Q3 - Q1);
  64476. var low = useExtreme ? min : Math.max(min, Q1 - bound);
  64477. var high = useExtreme ? max : Math.min(max, Q3 + bound);
  64478. var itemNameFormatter = opt.itemNameFormatter;
  64479. var itemName = isFunction(itemNameFormatter) ? itemNameFormatter({
  64480. value: i
  64481. }) : isString(itemNameFormatter) ? itemNameFormatter.replace('{value}', i + '') : i + '';
  64482. boxData.push([itemName, low, Q1, Q2, Q3, high]);
  64483. for (var j = 0; j < ascList.length; j++) {
  64484. var dataItem = ascList[j];
  64485. if (dataItem < low || dataItem > high) {
  64486. var outlier = [itemName, dataItem];
  64487. outliers.push(outlier);
  64488. }
  64489. }
  64490. }
  64491. return {
  64492. boxData: boxData,
  64493. outliers: outliers
  64494. };
  64495. }
  64496. var boxplotTransform = {
  64497. type: 'echarts:boxplot',
  64498. transform: function transform(params) {
  64499. var upstream = params.upstream;
  64500. if (upstream.sourceFormat !== SOURCE_FORMAT_ARRAY_ROWS) {
  64501. var errMsg = '';
  64502. if ("development" !== 'production') {
  64503. errMsg = makePrintable('source data is not applicable for this boxplot transform. Expect number[][].');
  64504. }
  64505. throwError(errMsg);
  64506. }
  64507. var result = prepareBoxplotData(upstream.getRawData(), params.config);
  64508. return [{
  64509. dimensions: ['ItemName', 'Low', 'Q1', 'Q2', 'Q3', 'High'],
  64510. data: result.boxData
  64511. }, {
  64512. data: result.outliers
  64513. }];
  64514. }
  64515. };
  64516. function install$k(registers) {
  64517. registers.registerSeriesModel(BoxplotSeriesModel);
  64518. registers.registerChartView(BoxplotView);
  64519. registers.registerLayout(boxplotLayout);
  64520. registers.registerTransform(boxplotTransform);
  64521. }
  64522. var positiveBorderColorQuery = ['itemStyle', 'borderColor'];
  64523. var negativeBorderColorQuery = ['itemStyle', 'borderColor0'];
  64524. var dojiBorderColorQuery = ['itemStyle', 'borderColorDoji'];
  64525. var positiveColorQuery = ['itemStyle', 'color'];
  64526. var negativeColorQuery = ['itemStyle', 'color0'];
  64527. function getColor(sign, model) {
  64528. return model.get(sign > 0 ? positiveColorQuery : negativeColorQuery);
  64529. }
  64530. function getBorderColor(sign, model) {
  64531. return model.get(sign === 0 ? dojiBorderColorQuery : sign > 0 ? positiveBorderColorQuery : negativeBorderColorQuery);
  64532. }
  64533. var candlestickVisual = {
  64534. seriesType: 'candlestick',
  64535. plan: createRenderPlanner(),
  64536. // For legend.
  64537. performRawSeries: true,
  64538. reset: function (seriesModel, ecModel) {
  64539. // Only visible series has each data be visual encoded
  64540. if (ecModel.isSeriesFiltered(seriesModel)) {
  64541. return;
  64542. }
  64543. var isLargeRender = seriesModel.pipelineContext.large;
  64544. return !isLargeRender && {
  64545. progress: function (params, data) {
  64546. var dataIndex;
  64547. while ((dataIndex = params.next()) != null) {
  64548. var itemModel = data.getItemModel(dataIndex);
  64549. var sign = data.getItemLayout(dataIndex).sign;
  64550. var style = itemModel.getItemStyle();
  64551. style.fill = getColor(sign, itemModel);
  64552. style.stroke = getBorderColor(sign, itemModel) || style.fill;
  64553. var existsStyle = data.ensureUniqueItemVisual(dataIndex, 'style');
  64554. extend(existsStyle, style);
  64555. }
  64556. }
  64557. };
  64558. }
  64559. };
  64560. var SKIP_PROPS = ['color', 'borderColor'];
  64561. var CandlestickView = /** @class */function (_super) {
  64562. __extends(CandlestickView, _super);
  64563. function CandlestickView() {
  64564. var _this = _super !== null && _super.apply(this, arguments) || this;
  64565. _this.type = CandlestickView.type;
  64566. return _this;
  64567. }
  64568. CandlestickView.prototype.render = function (seriesModel, ecModel, api) {
  64569. // If there is clipPath created in large mode. Remove it.
  64570. this.group.removeClipPath();
  64571. // Clear previously rendered progressive elements.
  64572. this._progressiveEls = null;
  64573. this._updateDrawMode(seriesModel);
  64574. this._isLargeDraw ? this._renderLarge(seriesModel) : this._renderNormal(seriesModel);
  64575. };
  64576. CandlestickView.prototype.incrementalPrepareRender = function (seriesModel, ecModel, api) {
  64577. this._clear();
  64578. this._updateDrawMode(seriesModel);
  64579. };
  64580. CandlestickView.prototype.incrementalRender = function (params, seriesModel, ecModel, api) {
  64581. this._progressiveEls = [];
  64582. this._isLargeDraw ? this._incrementalRenderLarge(params, seriesModel) : this._incrementalRenderNormal(params, seriesModel);
  64583. };
  64584. CandlestickView.prototype.eachRendered = function (cb) {
  64585. traverseElements(this._progressiveEls || this.group, cb);
  64586. };
  64587. CandlestickView.prototype._updateDrawMode = function (seriesModel) {
  64588. var isLargeDraw = seriesModel.pipelineContext.large;
  64589. if (this._isLargeDraw == null || isLargeDraw !== this._isLargeDraw) {
  64590. this._isLargeDraw = isLargeDraw;
  64591. this._clear();
  64592. }
  64593. };
  64594. CandlestickView.prototype._renderNormal = function (seriesModel) {
  64595. var data = seriesModel.getData();
  64596. var oldData = this._data;
  64597. var group = this.group;
  64598. var isSimpleBox = data.getLayout('isSimpleBox');
  64599. var needsClip = seriesModel.get('clip', true);
  64600. var coord = seriesModel.coordinateSystem;
  64601. var clipArea = coord.getArea && coord.getArea();
  64602. // There is no old data only when first rendering or switching from
  64603. // stream mode to normal mode, where previous elements should be removed.
  64604. if (!this._data) {
  64605. group.removeAll();
  64606. }
  64607. data.diff(oldData).add(function (newIdx) {
  64608. if (data.hasValue(newIdx)) {
  64609. var itemLayout = data.getItemLayout(newIdx);
  64610. if (needsClip && isNormalBoxClipped(clipArea, itemLayout)) {
  64611. return;
  64612. }
  64613. var el = createNormalBox$1(itemLayout, newIdx, true);
  64614. initProps(el, {
  64615. shape: {
  64616. points: itemLayout.ends
  64617. }
  64618. }, seriesModel, newIdx);
  64619. setBoxCommon(el, data, newIdx, isSimpleBox);
  64620. group.add(el);
  64621. data.setItemGraphicEl(newIdx, el);
  64622. }
  64623. }).update(function (newIdx, oldIdx) {
  64624. var el = oldData.getItemGraphicEl(oldIdx);
  64625. // Empty data
  64626. if (!data.hasValue(newIdx)) {
  64627. group.remove(el);
  64628. return;
  64629. }
  64630. var itemLayout = data.getItemLayout(newIdx);
  64631. if (needsClip && isNormalBoxClipped(clipArea, itemLayout)) {
  64632. group.remove(el);
  64633. return;
  64634. }
  64635. if (!el) {
  64636. el = createNormalBox$1(itemLayout);
  64637. } else {
  64638. updateProps(el, {
  64639. shape: {
  64640. points: itemLayout.ends
  64641. }
  64642. }, seriesModel, newIdx);
  64643. saveOldStyle(el);
  64644. }
  64645. setBoxCommon(el, data, newIdx, isSimpleBox);
  64646. group.add(el);
  64647. data.setItemGraphicEl(newIdx, el);
  64648. }).remove(function (oldIdx) {
  64649. var el = oldData.getItemGraphicEl(oldIdx);
  64650. el && group.remove(el);
  64651. }).execute();
  64652. this._data = data;
  64653. };
  64654. CandlestickView.prototype._renderLarge = function (seriesModel) {
  64655. this._clear();
  64656. createLarge$1(seriesModel, this.group);
  64657. var clipPath = seriesModel.get('clip', true) ? createClipPath(seriesModel.coordinateSystem, false, seriesModel) : null;
  64658. if (clipPath) {
  64659. this.group.setClipPath(clipPath);
  64660. } else {
  64661. this.group.removeClipPath();
  64662. }
  64663. };
  64664. CandlestickView.prototype._incrementalRenderNormal = function (params, seriesModel) {
  64665. var data = seriesModel.getData();
  64666. var isSimpleBox = data.getLayout('isSimpleBox');
  64667. var dataIndex;
  64668. while ((dataIndex = params.next()) != null) {
  64669. var itemLayout = data.getItemLayout(dataIndex);
  64670. var el = createNormalBox$1(itemLayout);
  64671. setBoxCommon(el, data, dataIndex, isSimpleBox);
  64672. el.incremental = true;
  64673. this.group.add(el);
  64674. this._progressiveEls.push(el);
  64675. }
  64676. };
  64677. CandlestickView.prototype._incrementalRenderLarge = function (params, seriesModel) {
  64678. createLarge$1(seriesModel, this.group, this._progressiveEls, true);
  64679. };
  64680. CandlestickView.prototype.remove = function (ecModel) {
  64681. this._clear();
  64682. };
  64683. CandlestickView.prototype._clear = function () {
  64684. this.group.removeAll();
  64685. this._data = null;
  64686. };
  64687. CandlestickView.type = 'candlestick';
  64688. return CandlestickView;
  64689. }(ChartView);
  64690. var NormalBoxPathShape = /** @class */function () {
  64691. function NormalBoxPathShape() {}
  64692. return NormalBoxPathShape;
  64693. }();
  64694. var NormalBoxPath = /** @class */function (_super) {
  64695. __extends(NormalBoxPath, _super);
  64696. function NormalBoxPath(opts) {
  64697. var _this = _super.call(this, opts) || this;
  64698. _this.type = 'normalCandlestickBox';
  64699. return _this;
  64700. }
  64701. NormalBoxPath.prototype.getDefaultShape = function () {
  64702. return new NormalBoxPathShape();
  64703. };
  64704. NormalBoxPath.prototype.buildPath = function (ctx, shape) {
  64705. var ends = shape.points;
  64706. if (this.__simpleBox) {
  64707. ctx.moveTo(ends[4][0], ends[4][1]);
  64708. ctx.lineTo(ends[6][0], ends[6][1]);
  64709. } else {
  64710. ctx.moveTo(ends[0][0], ends[0][1]);
  64711. ctx.lineTo(ends[1][0], ends[1][1]);
  64712. ctx.lineTo(ends[2][0], ends[2][1]);
  64713. ctx.lineTo(ends[3][0], ends[3][1]);
  64714. ctx.closePath();
  64715. ctx.moveTo(ends[4][0], ends[4][1]);
  64716. ctx.lineTo(ends[5][0], ends[5][1]);
  64717. ctx.moveTo(ends[6][0], ends[6][1]);
  64718. ctx.lineTo(ends[7][0], ends[7][1]);
  64719. }
  64720. };
  64721. return NormalBoxPath;
  64722. }(Path);
  64723. function createNormalBox$1(itemLayout, dataIndex, isInit) {
  64724. var ends = itemLayout.ends;
  64725. return new NormalBoxPath({
  64726. shape: {
  64727. points: isInit ? transInit$1(ends, itemLayout) : ends
  64728. },
  64729. z2: 100
  64730. });
  64731. }
  64732. function isNormalBoxClipped(clipArea, itemLayout) {
  64733. var clipped = true;
  64734. for (var i = 0; i < itemLayout.ends.length; i++) {
  64735. // If any point are in the region.
  64736. if (clipArea.contain(itemLayout.ends[i][0], itemLayout.ends[i][1])) {
  64737. clipped = false;
  64738. break;
  64739. }
  64740. }
  64741. return clipped;
  64742. }
  64743. function setBoxCommon(el, data, dataIndex, isSimpleBox) {
  64744. var itemModel = data.getItemModel(dataIndex);
  64745. el.useStyle(data.getItemVisual(dataIndex, 'style'));
  64746. el.style.strokeNoScale = true;
  64747. el.__simpleBox = isSimpleBox;
  64748. setStatesStylesFromModel(el, itemModel);
  64749. var sign = data.getItemLayout(dataIndex).sign;
  64750. each(el.states, function (state, stateName) {
  64751. var stateModel = itemModel.getModel(stateName);
  64752. var color = getColor(sign, stateModel);
  64753. var borderColor = getBorderColor(sign, stateModel) || color;
  64754. var stateStyle = state.style || (state.style = {});
  64755. color && (stateStyle.fill = color);
  64756. borderColor && (stateStyle.stroke = borderColor);
  64757. });
  64758. var emphasisModel = itemModel.getModel('emphasis');
  64759. toggleHoverEmphasis(el, emphasisModel.get('focus'), emphasisModel.get('blurScope'), emphasisModel.get('disabled'));
  64760. }
  64761. function transInit$1(points, itemLayout) {
  64762. return map(points, function (point) {
  64763. point = point.slice();
  64764. point[1] = itemLayout.initBaseline;
  64765. return point;
  64766. });
  64767. }
  64768. var LargeBoxPathShape = /** @class */function () {
  64769. function LargeBoxPathShape() {}
  64770. return LargeBoxPathShape;
  64771. }();
  64772. var LargeBoxPath = /** @class */function (_super) {
  64773. __extends(LargeBoxPath, _super);
  64774. function LargeBoxPath(opts) {
  64775. var _this = _super.call(this, opts) || this;
  64776. _this.type = 'largeCandlestickBox';
  64777. return _this;
  64778. }
  64779. LargeBoxPath.prototype.getDefaultShape = function () {
  64780. return new LargeBoxPathShape();
  64781. };
  64782. LargeBoxPath.prototype.buildPath = function (ctx, shape) {
  64783. // Drawing lines is more efficient than drawing
  64784. // a whole line or drawing rects.
  64785. var points = shape.points;
  64786. for (var i = 0; i < points.length;) {
  64787. if (this.__sign === points[i++]) {
  64788. var x = points[i++];
  64789. ctx.moveTo(x, points[i++]);
  64790. ctx.lineTo(x, points[i++]);
  64791. } else {
  64792. i += 3;
  64793. }
  64794. }
  64795. };
  64796. return LargeBoxPath;
  64797. }(Path);
  64798. function createLarge$1(seriesModel, group, progressiveEls, incremental) {
  64799. var data = seriesModel.getData();
  64800. var largePoints = data.getLayout('largePoints');
  64801. var elP = new LargeBoxPath({
  64802. shape: {
  64803. points: largePoints
  64804. },
  64805. __sign: 1,
  64806. ignoreCoarsePointer: true
  64807. });
  64808. group.add(elP);
  64809. var elN = new LargeBoxPath({
  64810. shape: {
  64811. points: largePoints
  64812. },
  64813. __sign: -1,
  64814. ignoreCoarsePointer: true
  64815. });
  64816. group.add(elN);
  64817. var elDoji = new LargeBoxPath({
  64818. shape: {
  64819. points: largePoints
  64820. },
  64821. __sign: 0,
  64822. ignoreCoarsePointer: true
  64823. });
  64824. group.add(elDoji);
  64825. setLargeStyle(1, elP, seriesModel);
  64826. setLargeStyle(-1, elN, seriesModel);
  64827. setLargeStyle(0, elDoji, seriesModel);
  64828. if (incremental) {
  64829. elP.incremental = true;
  64830. elN.incremental = true;
  64831. }
  64832. if (progressiveEls) {
  64833. progressiveEls.push(elP, elN);
  64834. }
  64835. }
  64836. function setLargeStyle(sign, el, seriesModel, data) {
  64837. // TODO put in visual?
  64838. var borderColor = getBorderColor(sign, seriesModel)
  64839. // Use color for border color by default.
  64840. || getColor(sign, seriesModel);
  64841. // Color must be excluded.
  64842. // Because symbol provide setColor individually to set fill and stroke
  64843. var itemStyle = seriesModel.getModel('itemStyle').getItemStyle(SKIP_PROPS);
  64844. el.useStyle(itemStyle);
  64845. el.style.fill = null;
  64846. el.style.stroke = borderColor;
  64847. }
  64848. var CandlestickSeriesModel = /** @class */function (_super) {
  64849. __extends(CandlestickSeriesModel, _super);
  64850. function CandlestickSeriesModel() {
  64851. var _this = _super !== null && _super.apply(this, arguments) || this;
  64852. _this.type = CandlestickSeriesModel.type;
  64853. _this.defaultValueDimensions = [{
  64854. name: 'open',
  64855. defaultTooltip: true
  64856. }, {
  64857. name: 'close',
  64858. defaultTooltip: true
  64859. }, {
  64860. name: 'lowest',
  64861. defaultTooltip: true
  64862. }, {
  64863. name: 'highest',
  64864. defaultTooltip: true
  64865. }];
  64866. return _this;
  64867. }
  64868. /**
  64869. * Get dimension for shadow in dataZoom
  64870. * @return dimension name
  64871. */
  64872. CandlestickSeriesModel.prototype.getShadowDim = function () {
  64873. return 'open';
  64874. };
  64875. CandlestickSeriesModel.prototype.brushSelector = function (dataIndex, data, selectors) {
  64876. var itemLayout = data.getItemLayout(dataIndex);
  64877. return itemLayout && selectors.rect(itemLayout.brushRect);
  64878. };
  64879. CandlestickSeriesModel.type = 'series.candlestick';
  64880. CandlestickSeriesModel.dependencies = ['xAxis', 'yAxis', 'grid'];
  64881. CandlestickSeriesModel.defaultOption = {
  64882. // zlevel: 0,
  64883. z: 2,
  64884. coordinateSystem: 'cartesian2d',
  64885. legendHoverLink: true,
  64886. // xAxisIndex: 0,
  64887. // yAxisIndex: 0,
  64888. layout: null,
  64889. clip: true,
  64890. itemStyle: {
  64891. color: '#eb5454',
  64892. color0: '#47b262',
  64893. borderColor: '#eb5454',
  64894. borderColor0: '#47b262',
  64895. borderColorDoji: null,
  64896. // borderColor: '#d24040',
  64897. // borderColor0: '#398f4f',
  64898. borderWidth: 1
  64899. },
  64900. emphasis: {
  64901. itemStyle: {
  64902. borderWidth: 2
  64903. }
  64904. },
  64905. barMaxWidth: null,
  64906. barMinWidth: null,
  64907. barWidth: null,
  64908. large: true,
  64909. largeThreshold: 600,
  64910. progressive: 3e3,
  64911. progressiveThreshold: 1e4,
  64912. progressiveChunkMode: 'mod',
  64913. animationEasing: 'linear',
  64914. animationDuration: 300
  64915. };
  64916. return CandlestickSeriesModel;
  64917. }(SeriesModel);
  64918. mixin(CandlestickSeriesModel, WhiskerBoxCommonMixin, true);
  64919. function candlestickPreprocessor(option) {
  64920. if (!option || !isArray(option.series)) {
  64921. return;
  64922. }
  64923. // Translate 'k' to 'candlestick'.
  64924. each(option.series, function (seriesItem) {
  64925. if (isObject(seriesItem) && seriesItem.type === 'k') {
  64926. seriesItem.type = 'candlestick';
  64927. }
  64928. });
  64929. }
  64930. var candlestickLayout = {
  64931. seriesType: 'candlestick',
  64932. plan: createRenderPlanner(),
  64933. reset: function (seriesModel) {
  64934. var coordSys = seriesModel.coordinateSystem;
  64935. var data = seriesModel.getData();
  64936. var candleWidth = calculateCandleWidth(seriesModel, data);
  64937. var cDimIdx = 0;
  64938. var vDimIdx = 1;
  64939. var coordDims = ['x', 'y'];
  64940. var cDimI = data.getDimensionIndex(data.mapDimension(coordDims[cDimIdx]));
  64941. var vDimsI = map(data.mapDimensionsAll(coordDims[vDimIdx]), data.getDimensionIndex, data);
  64942. var openDimI = vDimsI[0];
  64943. var closeDimI = vDimsI[1];
  64944. var lowestDimI = vDimsI[2];
  64945. var highestDimI = vDimsI[3];
  64946. data.setLayout({
  64947. candleWidth: candleWidth,
  64948. // The value is experimented visually.
  64949. isSimpleBox: candleWidth <= 1.3
  64950. });
  64951. if (cDimI < 0 || vDimsI.length < 4) {
  64952. return;
  64953. }
  64954. return {
  64955. progress: seriesModel.pipelineContext.large ? largeProgress : normalProgress
  64956. };
  64957. function normalProgress(params, data) {
  64958. var dataIndex;
  64959. var store = data.getStore();
  64960. while ((dataIndex = params.next()) != null) {
  64961. var axisDimVal = store.get(cDimI, dataIndex);
  64962. var openVal = store.get(openDimI, dataIndex);
  64963. var closeVal = store.get(closeDimI, dataIndex);
  64964. var lowestVal = store.get(lowestDimI, dataIndex);
  64965. var highestVal = store.get(highestDimI, dataIndex);
  64966. var ocLow = Math.min(openVal, closeVal);
  64967. var ocHigh = Math.max(openVal, closeVal);
  64968. var ocLowPoint = getPoint(ocLow, axisDimVal);
  64969. var ocHighPoint = getPoint(ocHigh, axisDimVal);
  64970. var lowestPoint = getPoint(lowestVal, axisDimVal);
  64971. var highestPoint = getPoint(highestVal, axisDimVal);
  64972. var ends = [];
  64973. addBodyEnd(ends, ocHighPoint, 0);
  64974. addBodyEnd(ends, ocLowPoint, 1);
  64975. ends.push(subPixelOptimizePoint(highestPoint), subPixelOptimizePoint(ocHighPoint), subPixelOptimizePoint(lowestPoint), subPixelOptimizePoint(ocLowPoint));
  64976. var itemModel = data.getItemModel(dataIndex);
  64977. var hasDojiColor = !!itemModel.get(['itemStyle', 'borderColorDoji']);
  64978. data.setItemLayout(dataIndex, {
  64979. sign: getSign(store, dataIndex, openVal, closeVal, closeDimI, hasDojiColor),
  64980. initBaseline: openVal > closeVal ? ocHighPoint[vDimIdx] : ocLowPoint[vDimIdx],
  64981. ends: ends,
  64982. brushRect: makeBrushRect(lowestVal, highestVal, axisDimVal)
  64983. });
  64984. }
  64985. function getPoint(val, axisDimVal) {
  64986. var p = [];
  64987. p[cDimIdx] = axisDimVal;
  64988. p[vDimIdx] = val;
  64989. return isNaN(axisDimVal) || isNaN(val) ? [NaN, NaN] : coordSys.dataToPoint(p);
  64990. }
  64991. function addBodyEnd(ends, point, start) {
  64992. var point1 = point.slice();
  64993. var point2 = point.slice();
  64994. point1[cDimIdx] = subPixelOptimize$1(point1[cDimIdx] + candleWidth / 2, 1, false);
  64995. point2[cDimIdx] = subPixelOptimize$1(point2[cDimIdx] - candleWidth / 2, 1, true);
  64996. start ? ends.push(point1, point2) : ends.push(point2, point1);
  64997. }
  64998. function makeBrushRect(lowestVal, highestVal, axisDimVal) {
  64999. var pmin = getPoint(lowestVal, axisDimVal);
  65000. var pmax = getPoint(highestVal, axisDimVal);
  65001. pmin[cDimIdx] -= candleWidth / 2;
  65002. pmax[cDimIdx] -= candleWidth / 2;
  65003. return {
  65004. x: pmin[0],
  65005. y: pmin[1],
  65006. width: candleWidth ,
  65007. height: pmax[1] - pmin[1]
  65008. };
  65009. }
  65010. function subPixelOptimizePoint(point) {
  65011. point[cDimIdx] = subPixelOptimize$1(point[cDimIdx], 1);
  65012. return point;
  65013. }
  65014. }
  65015. function largeProgress(params, data) {
  65016. // Structure: [sign, x, yhigh, ylow, sign, x, yhigh, ylow, ...]
  65017. var points = createFloat32Array(params.count * 4);
  65018. var offset = 0;
  65019. var point;
  65020. var tmpIn = [];
  65021. var tmpOut = [];
  65022. var dataIndex;
  65023. var store = data.getStore();
  65024. var hasDojiColor = !!seriesModel.get(['itemStyle', 'borderColorDoji']);
  65025. while ((dataIndex = params.next()) != null) {
  65026. var axisDimVal = store.get(cDimI, dataIndex);
  65027. var openVal = store.get(openDimI, dataIndex);
  65028. var closeVal = store.get(closeDimI, dataIndex);
  65029. var lowestVal = store.get(lowestDimI, dataIndex);
  65030. var highestVal = store.get(highestDimI, dataIndex);
  65031. if (isNaN(axisDimVal) || isNaN(lowestVal) || isNaN(highestVal)) {
  65032. points[offset++] = NaN;
  65033. offset += 3;
  65034. continue;
  65035. }
  65036. points[offset++] = getSign(store, dataIndex, openVal, closeVal, closeDimI, hasDojiColor);
  65037. tmpIn[cDimIdx] = axisDimVal;
  65038. tmpIn[vDimIdx] = lowestVal;
  65039. point = coordSys.dataToPoint(tmpIn, null, tmpOut);
  65040. points[offset++] = point ? point[0] : NaN;
  65041. points[offset++] = point ? point[1] : NaN;
  65042. tmpIn[vDimIdx] = highestVal;
  65043. point = coordSys.dataToPoint(tmpIn, null, tmpOut);
  65044. points[offset++] = point ? point[1] : NaN;
  65045. }
  65046. data.setLayout('largePoints', points);
  65047. }
  65048. }
  65049. };
  65050. /**
  65051. * Get the sign of a single data.
  65052. *
  65053. * @returns 0 for doji with hasDojiColor: true,
  65054. * 1 for positive,
  65055. * -1 for negative.
  65056. */
  65057. function getSign(store, dataIndex, openVal, closeVal, closeDimI, hasDojiColor) {
  65058. var sign;
  65059. if (openVal > closeVal) {
  65060. sign = -1;
  65061. } else if (openVal < closeVal) {
  65062. sign = 1;
  65063. } else {
  65064. sign = hasDojiColor
  65065. // When doji color is set, use it instead of color/color0.
  65066. ? 0 : dataIndex > 0
  65067. // If close === open, compare with close of last record
  65068. ? store.get(closeDimI, dataIndex - 1) <= closeVal ? 1 : -1
  65069. // No record of previous, set to be positive
  65070. : 1;
  65071. }
  65072. return sign;
  65073. }
  65074. function calculateCandleWidth(seriesModel, data) {
  65075. var baseAxis = seriesModel.getBaseAxis();
  65076. var extent;
  65077. var bandWidth = baseAxis.type === 'category' ? baseAxis.getBandWidth() : (extent = baseAxis.getExtent(), Math.abs(extent[1] - extent[0]) / data.count());
  65078. var barMaxWidth = parsePercent$1(retrieve2(seriesModel.get('barMaxWidth'), bandWidth), bandWidth);
  65079. var barMinWidth = parsePercent$1(retrieve2(seriesModel.get('barMinWidth'), 1), bandWidth);
  65080. var barWidth = seriesModel.get('barWidth');
  65081. return barWidth != null ? parsePercent$1(barWidth, bandWidth)
  65082. // Put max outer to ensure bar visible in spite of overlap.
  65083. : Math.max(Math.min(bandWidth / 2, barMaxWidth), barMinWidth);
  65084. }
  65085. function install$l(registers) {
  65086. registers.registerChartView(CandlestickView);
  65087. registers.registerSeriesModel(CandlestickSeriesModel);
  65088. registers.registerPreprocessor(candlestickPreprocessor);
  65089. registers.registerVisual(candlestickVisual);
  65090. registers.registerLayout(candlestickLayout);
  65091. }
  65092. function updateRipplePath(rippleGroup, effectCfg) {
  65093. var color = effectCfg.rippleEffectColor || effectCfg.color;
  65094. rippleGroup.eachChild(function (ripplePath) {
  65095. ripplePath.attr({
  65096. z: effectCfg.z,
  65097. zlevel: effectCfg.zlevel,
  65098. style: {
  65099. stroke: effectCfg.brushType === 'stroke' ? color : null,
  65100. fill: effectCfg.brushType === 'fill' ? color : null
  65101. }
  65102. });
  65103. });
  65104. }
  65105. var EffectSymbol = /** @class */function (_super) {
  65106. __extends(EffectSymbol, _super);
  65107. function EffectSymbol(data, idx) {
  65108. var _this = _super.call(this) || this;
  65109. var symbol = new Symbol(data, idx);
  65110. var rippleGroup = new Group();
  65111. _this.add(symbol);
  65112. _this.add(rippleGroup);
  65113. _this.updateData(data, idx);
  65114. return _this;
  65115. }
  65116. EffectSymbol.prototype.stopEffectAnimation = function () {
  65117. this.childAt(1).removeAll();
  65118. };
  65119. EffectSymbol.prototype.startEffectAnimation = function (effectCfg) {
  65120. var symbolType = effectCfg.symbolType;
  65121. var color = effectCfg.color;
  65122. var rippleNumber = effectCfg.rippleNumber;
  65123. var rippleGroup = this.childAt(1);
  65124. for (var i = 0; i < rippleNumber; i++) {
  65125. // If width/height are set too small (e.g., set to 1) on ios10
  65126. // and macOS Sierra, a circle stroke become a rect, no matter what
  65127. // the scale is set. So we set width/height as 2. See #4136.
  65128. var ripplePath = createSymbol(symbolType, -1, -1, 2, 2, color);
  65129. ripplePath.attr({
  65130. style: {
  65131. strokeNoScale: true
  65132. },
  65133. z2: 99,
  65134. silent: true,
  65135. scaleX: 0.5,
  65136. scaleY: 0.5
  65137. });
  65138. var delay = -i / rippleNumber * effectCfg.period + effectCfg.effectOffset;
  65139. ripplePath.animate('', true).when(effectCfg.period, {
  65140. scaleX: effectCfg.rippleScale / 2,
  65141. scaleY: effectCfg.rippleScale / 2
  65142. }).delay(delay).start();
  65143. ripplePath.animateStyle(true).when(effectCfg.period, {
  65144. opacity: 0
  65145. }).delay(delay).start();
  65146. rippleGroup.add(ripplePath);
  65147. }
  65148. updateRipplePath(rippleGroup, effectCfg);
  65149. };
  65150. /**
  65151. * Update effect symbol
  65152. */
  65153. EffectSymbol.prototype.updateEffectAnimation = function (effectCfg) {
  65154. var oldEffectCfg = this._effectCfg;
  65155. var rippleGroup = this.childAt(1);
  65156. // Must reinitialize effect if following configuration changed
  65157. var DIFFICULT_PROPS = ['symbolType', 'period', 'rippleScale', 'rippleNumber'];
  65158. for (var i = 0; i < DIFFICULT_PROPS.length; i++) {
  65159. var propName = DIFFICULT_PROPS[i];
  65160. if (oldEffectCfg[propName] !== effectCfg[propName]) {
  65161. this.stopEffectAnimation();
  65162. this.startEffectAnimation(effectCfg);
  65163. return;
  65164. }
  65165. }
  65166. updateRipplePath(rippleGroup, effectCfg);
  65167. };
  65168. /**
  65169. * Highlight symbol
  65170. */
  65171. EffectSymbol.prototype.highlight = function () {
  65172. enterEmphasis(this);
  65173. };
  65174. /**
  65175. * Downplay symbol
  65176. */
  65177. EffectSymbol.prototype.downplay = function () {
  65178. leaveEmphasis(this);
  65179. };
  65180. EffectSymbol.prototype.getSymbolType = function () {
  65181. var symbol = this.childAt(0);
  65182. return symbol && symbol.getSymbolType();
  65183. };
  65184. /**
  65185. * Update symbol properties
  65186. */
  65187. EffectSymbol.prototype.updateData = function (data, idx) {
  65188. var _this = this;
  65189. var seriesModel = data.hostModel;
  65190. this.childAt(0).updateData(data, idx);
  65191. var rippleGroup = this.childAt(1);
  65192. var itemModel = data.getItemModel(idx);
  65193. var symbolType = data.getItemVisual(idx, 'symbol');
  65194. var symbolSize = normalizeSymbolSize(data.getItemVisual(idx, 'symbolSize'));
  65195. var symbolStyle = data.getItemVisual(idx, 'style');
  65196. var color = symbolStyle && symbolStyle.fill;
  65197. var emphasisModel = itemModel.getModel('emphasis');
  65198. rippleGroup.setScale(symbolSize);
  65199. rippleGroup.traverse(function (ripplePath) {
  65200. ripplePath.setStyle('fill', color);
  65201. });
  65202. var symbolOffset = normalizeSymbolOffset(data.getItemVisual(idx, 'symbolOffset'), symbolSize);
  65203. if (symbolOffset) {
  65204. rippleGroup.x = symbolOffset[0];
  65205. rippleGroup.y = symbolOffset[1];
  65206. }
  65207. var symbolRotate = data.getItemVisual(idx, 'symbolRotate');
  65208. rippleGroup.rotation = (symbolRotate || 0) * Math.PI / 180 || 0;
  65209. var effectCfg = {};
  65210. effectCfg.showEffectOn = seriesModel.get('showEffectOn');
  65211. effectCfg.rippleScale = itemModel.get(['rippleEffect', 'scale']);
  65212. effectCfg.brushType = itemModel.get(['rippleEffect', 'brushType']);
  65213. effectCfg.period = itemModel.get(['rippleEffect', 'period']) * 1000;
  65214. effectCfg.effectOffset = idx / data.count();
  65215. effectCfg.z = seriesModel.getShallow('z') || 0;
  65216. effectCfg.zlevel = seriesModel.getShallow('zlevel') || 0;
  65217. effectCfg.symbolType = symbolType;
  65218. effectCfg.color = color;
  65219. effectCfg.rippleEffectColor = itemModel.get(['rippleEffect', 'color']);
  65220. effectCfg.rippleNumber = itemModel.get(['rippleEffect', 'number']);
  65221. if (effectCfg.showEffectOn === 'render') {
  65222. this._effectCfg ? this.updateEffectAnimation(effectCfg) : this.startEffectAnimation(effectCfg);
  65223. this._effectCfg = effectCfg;
  65224. } else {
  65225. // Not keep old effect config
  65226. this._effectCfg = null;
  65227. this.stopEffectAnimation();
  65228. this.onHoverStateChange = function (toState) {
  65229. if (toState === 'emphasis') {
  65230. if (effectCfg.showEffectOn !== 'render') {
  65231. _this.startEffectAnimation(effectCfg);
  65232. }
  65233. } else if (toState === 'normal') {
  65234. if (effectCfg.showEffectOn !== 'render') {
  65235. _this.stopEffectAnimation();
  65236. }
  65237. }
  65238. };
  65239. }
  65240. this._effectCfg = effectCfg;
  65241. toggleHoverEmphasis(this, emphasisModel.get('focus'), emphasisModel.get('blurScope'), emphasisModel.get('disabled'));
  65242. };
  65243. EffectSymbol.prototype.fadeOut = function (cb) {
  65244. cb && cb();
  65245. };
  65246. return EffectSymbol;
  65247. }(Group);
  65248. var EffectScatterView = /** @class */function (_super) {
  65249. __extends(EffectScatterView, _super);
  65250. function EffectScatterView() {
  65251. var _this = _super !== null && _super.apply(this, arguments) || this;
  65252. _this.type = EffectScatterView.type;
  65253. return _this;
  65254. }
  65255. EffectScatterView.prototype.init = function () {
  65256. this._symbolDraw = new SymbolDraw(EffectSymbol);
  65257. };
  65258. EffectScatterView.prototype.render = function (seriesModel, ecModel, api) {
  65259. var data = seriesModel.getData();
  65260. var effectSymbolDraw = this._symbolDraw;
  65261. effectSymbolDraw.updateData(data, {
  65262. clipShape: this._getClipShape(seriesModel)
  65263. });
  65264. this.group.add(effectSymbolDraw.group);
  65265. };
  65266. EffectScatterView.prototype._getClipShape = function (seriesModel) {
  65267. var coordSys = seriesModel.coordinateSystem;
  65268. var clipArea = coordSys && coordSys.getArea && coordSys.getArea();
  65269. return seriesModel.get('clip', true) ? clipArea : null;
  65270. };
  65271. EffectScatterView.prototype.updateTransform = function (seriesModel, ecModel, api) {
  65272. var data = seriesModel.getData();
  65273. this.group.dirty();
  65274. var res = pointsLayout('').reset(seriesModel, ecModel, api);
  65275. if (res.progress) {
  65276. res.progress({
  65277. start: 0,
  65278. end: data.count(),
  65279. count: data.count()
  65280. }, data);
  65281. }
  65282. this._symbolDraw.updateLayout();
  65283. };
  65284. EffectScatterView.prototype._updateGroupTransform = function (seriesModel) {
  65285. var coordSys = seriesModel.coordinateSystem;
  65286. if (coordSys && coordSys.getRoamTransform) {
  65287. this.group.transform = clone$2(coordSys.getRoamTransform());
  65288. this.group.decomposeTransform();
  65289. }
  65290. };
  65291. EffectScatterView.prototype.remove = function (ecModel, api) {
  65292. this._symbolDraw && this._symbolDraw.remove(true);
  65293. };
  65294. EffectScatterView.type = 'effectScatter';
  65295. return EffectScatterView;
  65296. }(ChartView);
  65297. var EffectScatterSeriesModel = /** @class */function (_super) {
  65298. __extends(EffectScatterSeriesModel, _super);
  65299. function EffectScatterSeriesModel() {
  65300. var _this = _super !== null && _super.apply(this, arguments) || this;
  65301. _this.type = EffectScatterSeriesModel.type;
  65302. _this.hasSymbolVisual = true;
  65303. return _this;
  65304. }
  65305. EffectScatterSeriesModel.prototype.getInitialData = function (option, ecModel) {
  65306. return createSeriesData(null, this, {
  65307. useEncodeDefaulter: true
  65308. });
  65309. };
  65310. EffectScatterSeriesModel.prototype.brushSelector = function (dataIndex, data, selectors) {
  65311. return selectors.point(data.getItemLayout(dataIndex));
  65312. };
  65313. EffectScatterSeriesModel.type = 'series.effectScatter';
  65314. EffectScatterSeriesModel.dependencies = ['grid', 'polar'];
  65315. EffectScatterSeriesModel.defaultOption = {
  65316. coordinateSystem: 'cartesian2d',
  65317. // zlevel: 0,
  65318. z: 2,
  65319. legendHoverLink: true,
  65320. effectType: 'ripple',
  65321. progressive: 0,
  65322. // When to show the effect, option: 'render'|'emphasis'
  65323. showEffectOn: 'render',
  65324. clip: true,
  65325. // Ripple effect config
  65326. rippleEffect: {
  65327. period: 4,
  65328. // Scale of ripple
  65329. scale: 2.5,
  65330. // Brush type can be fill or stroke
  65331. brushType: 'fill',
  65332. // Ripple number
  65333. number: 3
  65334. },
  65335. universalTransition: {
  65336. divideShape: 'clone'
  65337. },
  65338. // Cartesian coordinate system
  65339. // xAxisIndex: 0,
  65340. // yAxisIndex: 0,
  65341. // Polar coordinate system
  65342. // polarIndex: 0,
  65343. // Geo coordinate system
  65344. // geoIndex: 0,
  65345. // symbol: null, // 图形类型
  65346. symbolSize: 10 // 图形大小,半宽(半径)参数,当图形为方向或菱形则总宽度为symbolSize * 2
  65347. // symbolRotate: null, // 图形旋转控制
  65348. // itemStyle: {
  65349. // opacity: 1
  65350. // }
  65351. };
  65352. return EffectScatterSeriesModel;
  65353. }(SeriesModel);
  65354. function install$m(registers) {
  65355. registers.registerChartView(EffectScatterView);
  65356. registers.registerSeriesModel(EffectScatterSeriesModel);
  65357. registers.registerLayout(pointsLayout('effectScatter'));
  65358. }
  65359. var EffectLine = /** @class */function (_super) {
  65360. __extends(EffectLine, _super);
  65361. function EffectLine(lineData, idx, seriesScope) {
  65362. var _this = _super.call(this) || this;
  65363. _this.add(_this.createLine(lineData, idx, seriesScope));
  65364. _this._updateEffectSymbol(lineData, idx);
  65365. return _this;
  65366. }
  65367. EffectLine.prototype.createLine = function (lineData, idx, seriesScope) {
  65368. return new Line$1(lineData, idx, seriesScope);
  65369. };
  65370. EffectLine.prototype._updateEffectSymbol = function (lineData, idx) {
  65371. var itemModel = lineData.getItemModel(idx);
  65372. var effectModel = itemModel.getModel('effect');
  65373. var size = effectModel.get('symbolSize');
  65374. var symbolType = effectModel.get('symbol');
  65375. if (!isArray(size)) {
  65376. size = [size, size];
  65377. }
  65378. var lineStyle = lineData.getItemVisual(idx, 'style');
  65379. var color = effectModel.get('color') || lineStyle && lineStyle.stroke;
  65380. var symbol = this.childAt(1);
  65381. if (this._symbolType !== symbolType) {
  65382. // Remove previous
  65383. this.remove(symbol);
  65384. symbol = createSymbol(symbolType, -0.5, -0.5, 1, 1, color);
  65385. symbol.z2 = 100;
  65386. symbol.culling = true;
  65387. this.add(symbol);
  65388. }
  65389. // Symbol may be removed if loop is false
  65390. if (!symbol) {
  65391. return;
  65392. }
  65393. // Shadow color is same with color in default
  65394. symbol.setStyle('shadowColor', color);
  65395. symbol.setStyle(effectModel.getItemStyle(['color']));
  65396. symbol.scaleX = size[0];
  65397. symbol.scaleY = size[1];
  65398. symbol.setColor(color);
  65399. this._symbolType = symbolType;
  65400. this._symbolScale = size;
  65401. this._updateEffectAnimation(lineData, effectModel, idx);
  65402. };
  65403. EffectLine.prototype._updateEffectAnimation = function (lineData, effectModel, idx) {
  65404. var symbol = this.childAt(1);
  65405. if (!symbol) {
  65406. return;
  65407. }
  65408. var points = lineData.getItemLayout(idx);
  65409. var period = effectModel.get('period') * 1000;
  65410. var loop = effectModel.get('loop');
  65411. var roundTrip = effectModel.get('roundTrip');
  65412. var constantSpeed = effectModel.get('constantSpeed');
  65413. var delayExpr = retrieve(effectModel.get('delay'), function (idx) {
  65414. return idx / lineData.count() * period / 3;
  65415. });
  65416. // Ignore when updating
  65417. symbol.ignore = true;
  65418. this._updateAnimationPoints(symbol, points);
  65419. if (constantSpeed > 0) {
  65420. period = this._getLineLength(symbol) / constantSpeed * 1000;
  65421. }
  65422. if (period !== this._period || loop !== this._loop || roundTrip !== this._roundTrip) {
  65423. symbol.stopAnimation();
  65424. var delayNum = void 0;
  65425. if (isFunction(delayExpr)) {
  65426. delayNum = delayExpr(idx);
  65427. } else {
  65428. delayNum = delayExpr;
  65429. }
  65430. if (symbol.__t > 0) {
  65431. delayNum = -period * symbol.__t;
  65432. }
  65433. this._animateSymbol(symbol, period, delayNum, loop, roundTrip);
  65434. }
  65435. this._period = period;
  65436. this._loop = loop;
  65437. this._roundTrip = roundTrip;
  65438. };
  65439. EffectLine.prototype._animateSymbol = function (symbol, period, delayNum, loop, roundTrip) {
  65440. if (period > 0) {
  65441. symbol.__t = 0;
  65442. var self_1 = this;
  65443. var animator = symbol.animate('', loop).when(roundTrip ? period * 2 : period, {
  65444. __t: roundTrip ? 2 : 1
  65445. }).delay(delayNum).during(function () {
  65446. self_1._updateSymbolPosition(symbol);
  65447. });
  65448. if (!loop) {
  65449. animator.done(function () {
  65450. self_1.remove(symbol);
  65451. });
  65452. }
  65453. animator.start();
  65454. }
  65455. };
  65456. EffectLine.prototype._getLineLength = function (symbol) {
  65457. // Not so accurate
  65458. return dist(symbol.__p1, symbol.__cp1) + dist(symbol.__cp1, symbol.__p2);
  65459. };
  65460. EffectLine.prototype._updateAnimationPoints = function (symbol, points) {
  65461. symbol.__p1 = points[0];
  65462. symbol.__p2 = points[1];
  65463. symbol.__cp1 = points[2] || [(points[0][0] + points[1][0]) / 2, (points[0][1] + points[1][1]) / 2];
  65464. };
  65465. EffectLine.prototype.updateData = function (lineData, idx, seriesScope) {
  65466. this.childAt(0).updateData(lineData, idx, seriesScope);
  65467. this._updateEffectSymbol(lineData, idx);
  65468. };
  65469. EffectLine.prototype._updateSymbolPosition = function (symbol) {
  65470. var p1 = symbol.__p1;
  65471. var p2 = symbol.__p2;
  65472. var cp1 = symbol.__cp1;
  65473. var t = symbol.__t < 1 ? symbol.__t : 2 - symbol.__t;
  65474. var pos = [symbol.x, symbol.y];
  65475. var lastPos = pos.slice();
  65476. var quadraticAt$1 = quadraticAt;
  65477. var quadraticDerivativeAt$1 = quadraticDerivativeAt;
  65478. pos[0] = quadraticAt$1(p1[0], cp1[0], p2[0], t);
  65479. pos[1] = quadraticAt$1(p1[1], cp1[1], p2[1], t);
  65480. // Tangent
  65481. var tx = symbol.__t < 1 ? quadraticDerivativeAt$1(p1[0], cp1[0], p2[0], t) : quadraticDerivativeAt$1(p2[0], cp1[0], p1[0], 1 - t);
  65482. var ty = symbol.__t < 1 ? quadraticDerivativeAt$1(p1[1], cp1[1], p2[1], t) : quadraticDerivativeAt$1(p2[1], cp1[1], p1[1], 1 - t);
  65483. symbol.rotation = -Math.atan2(ty, tx) - Math.PI / 2;
  65484. // enable continuity trail for 'line', 'rect', 'roundRect' symbolType
  65485. if (this._symbolType === 'line' || this._symbolType === 'rect' || this._symbolType === 'roundRect') {
  65486. if (symbol.__lastT !== undefined && symbol.__lastT < symbol.__t) {
  65487. symbol.scaleY = dist(lastPos, pos) * 1.05;
  65488. // make sure the last segment render within endPoint
  65489. if (t === 1) {
  65490. pos[0] = lastPos[0] + (pos[0] - lastPos[0]) / 2;
  65491. pos[1] = lastPos[1] + (pos[1] - lastPos[1]) / 2;
  65492. }
  65493. } else if (symbol.__lastT === 1) {
  65494. // After first loop, symbol.__t does NOT start with 0, so connect p1 to pos directly.
  65495. symbol.scaleY = 2 * dist(p1, pos);
  65496. } else {
  65497. symbol.scaleY = this._symbolScale[1];
  65498. }
  65499. }
  65500. symbol.__lastT = symbol.__t;
  65501. symbol.ignore = false;
  65502. symbol.x = pos[0];
  65503. symbol.y = pos[1];
  65504. };
  65505. EffectLine.prototype.updateLayout = function (lineData, idx) {
  65506. this.childAt(0).updateLayout(lineData, idx);
  65507. var effectModel = lineData.getItemModel(idx).getModel('effect');
  65508. this._updateEffectAnimation(lineData, effectModel, idx);
  65509. };
  65510. return EffectLine;
  65511. }(Group);
  65512. var Polyline$1 = /** @class */function (_super) {
  65513. __extends(Polyline$1, _super);
  65514. function Polyline$1(lineData, idx, seriesScope) {
  65515. var _this = _super.call(this) || this;
  65516. _this._createPolyline(lineData, idx, seriesScope);
  65517. return _this;
  65518. }
  65519. Polyline$1.prototype._createPolyline = function (lineData, idx, seriesScope) {
  65520. // let seriesModel = lineData.hostModel;
  65521. var points = lineData.getItemLayout(idx);
  65522. var line = new Polyline({
  65523. shape: {
  65524. points: points
  65525. }
  65526. });
  65527. this.add(line);
  65528. this._updateCommonStl(lineData, idx, seriesScope);
  65529. };
  65530. Polyline$1.prototype.updateData = function (lineData, idx, seriesScope) {
  65531. var seriesModel = lineData.hostModel;
  65532. var line = this.childAt(0);
  65533. var target = {
  65534. shape: {
  65535. points: lineData.getItemLayout(idx)
  65536. }
  65537. };
  65538. updateProps(line, target, seriesModel, idx);
  65539. this._updateCommonStl(lineData, idx, seriesScope);
  65540. };
  65541. Polyline$1.prototype._updateCommonStl = function (lineData, idx, seriesScope) {
  65542. var line = this.childAt(0);
  65543. var itemModel = lineData.getItemModel(idx);
  65544. var emphasisLineStyle = seriesScope && seriesScope.emphasisLineStyle;
  65545. var focus = seriesScope && seriesScope.focus;
  65546. var blurScope = seriesScope && seriesScope.blurScope;
  65547. var emphasisDisabled = seriesScope && seriesScope.emphasisDisabled;
  65548. if (!seriesScope || lineData.hasItemOption) {
  65549. var emphasisModel = itemModel.getModel('emphasis');
  65550. emphasisLineStyle = emphasisModel.getModel('lineStyle').getLineStyle();
  65551. emphasisDisabled = emphasisModel.get('disabled');
  65552. focus = emphasisModel.get('focus');
  65553. blurScope = emphasisModel.get('blurScope');
  65554. }
  65555. line.useStyle(lineData.getItemVisual(idx, 'style'));
  65556. line.style.fill = null;
  65557. line.style.strokeNoScale = true;
  65558. var lineEmphasisState = line.ensureState('emphasis');
  65559. lineEmphasisState.style = emphasisLineStyle;
  65560. toggleHoverEmphasis(this, focus, blurScope, emphasisDisabled);
  65561. };
  65562. Polyline$1.prototype.updateLayout = function (lineData, idx) {
  65563. var polyline = this.childAt(0);
  65564. polyline.setShape('points', lineData.getItemLayout(idx));
  65565. };
  65566. return Polyline$1;
  65567. }(Group);
  65568. var EffectPolyline = /** @class */function (_super) {
  65569. __extends(EffectPolyline, _super);
  65570. function EffectPolyline() {
  65571. var _this = _super !== null && _super.apply(this, arguments) || this;
  65572. _this._lastFrame = 0;
  65573. _this._lastFramePercent = 0;
  65574. return _this;
  65575. }
  65576. // Override
  65577. EffectPolyline.prototype.createLine = function (lineData, idx, seriesScope) {
  65578. return new Polyline$1(lineData, idx, seriesScope);
  65579. };
  65580. // Override
  65581. EffectPolyline.prototype._updateAnimationPoints = function (symbol, points) {
  65582. this._points = points;
  65583. var accLenArr = [0];
  65584. var len = 0;
  65585. for (var i = 1; i < points.length; i++) {
  65586. var p1 = points[i - 1];
  65587. var p2 = points[i];
  65588. len += dist(p1, p2);
  65589. accLenArr.push(len);
  65590. }
  65591. if (len === 0) {
  65592. this._length = 0;
  65593. return;
  65594. }
  65595. for (var i = 0; i < accLenArr.length; i++) {
  65596. accLenArr[i] /= len;
  65597. }
  65598. this._offsets = accLenArr;
  65599. this._length = len;
  65600. };
  65601. // Override
  65602. EffectPolyline.prototype._getLineLength = function () {
  65603. return this._length;
  65604. };
  65605. // Override
  65606. EffectPolyline.prototype._updateSymbolPosition = function (symbol) {
  65607. var t = symbol.__t < 1 ? symbol.__t : 2 - symbol.__t;
  65608. var points = this._points;
  65609. var offsets = this._offsets;
  65610. var len = points.length;
  65611. if (!offsets) {
  65612. // Has length 0
  65613. return;
  65614. }
  65615. var lastFrame = this._lastFrame;
  65616. var frame;
  65617. if (t < this._lastFramePercent) {
  65618. // Start from the next frame
  65619. // PENDING start from lastFrame ?
  65620. var start = Math.min(lastFrame + 1, len - 1);
  65621. for (frame = start; frame >= 0; frame--) {
  65622. if (offsets[frame] <= t) {
  65623. break;
  65624. }
  65625. }
  65626. // PENDING really need to do this ?
  65627. frame = Math.min(frame, len - 2);
  65628. } else {
  65629. for (frame = lastFrame; frame < len; frame++) {
  65630. if (offsets[frame] > t) {
  65631. break;
  65632. }
  65633. }
  65634. frame = Math.min(frame - 1, len - 2);
  65635. }
  65636. var p = (t - offsets[frame]) / (offsets[frame + 1] - offsets[frame]);
  65637. var p0 = points[frame];
  65638. var p1 = points[frame + 1];
  65639. symbol.x = p0[0] * (1 - p) + p * p1[0];
  65640. symbol.y = p0[1] * (1 - p) + p * p1[1];
  65641. var tx = symbol.__t < 1 ? p1[0] - p0[0] : p0[0] - p1[0];
  65642. var ty = symbol.__t < 1 ? p1[1] - p0[1] : p0[1] - p1[1];
  65643. symbol.rotation = -Math.atan2(ty, tx) - Math.PI / 2;
  65644. this._lastFrame = frame;
  65645. this._lastFramePercent = t;
  65646. symbol.ignore = false;
  65647. };
  65648. return EffectPolyline;
  65649. }(EffectLine);
  65650. var LargeLinesPathShape = /** @class */function () {
  65651. function LargeLinesPathShape() {
  65652. this.polyline = false;
  65653. this.curveness = 0;
  65654. this.segs = [];
  65655. }
  65656. return LargeLinesPathShape;
  65657. }();
  65658. var LargeLinesPath = /** @class */function (_super) {
  65659. __extends(LargeLinesPath, _super);
  65660. function LargeLinesPath(opts) {
  65661. var _this = _super.call(this, opts) || this;
  65662. _this._off = 0;
  65663. _this.hoverDataIdx = -1;
  65664. return _this;
  65665. }
  65666. LargeLinesPath.prototype.reset = function () {
  65667. this.notClear = false;
  65668. this._off = 0;
  65669. };
  65670. LargeLinesPath.prototype.getDefaultStyle = function () {
  65671. return {
  65672. stroke: tokens.color.neutral99,
  65673. fill: null
  65674. };
  65675. };
  65676. LargeLinesPath.prototype.getDefaultShape = function () {
  65677. return new LargeLinesPathShape();
  65678. };
  65679. LargeLinesPath.prototype.buildPath = function (ctx, shape) {
  65680. var segs = shape.segs;
  65681. var curveness = shape.curveness;
  65682. var i;
  65683. if (shape.polyline) {
  65684. for (i = this._off; i < segs.length;) {
  65685. var count = segs[i++];
  65686. if (count > 0) {
  65687. ctx.moveTo(segs[i++], segs[i++]);
  65688. for (var k = 1; k < count; k++) {
  65689. ctx.lineTo(segs[i++], segs[i++]);
  65690. }
  65691. }
  65692. }
  65693. } else {
  65694. for (i = this._off; i < segs.length;) {
  65695. var x0 = segs[i++];
  65696. var y0 = segs[i++];
  65697. var x1 = segs[i++];
  65698. var y1 = segs[i++];
  65699. ctx.moveTo(x0, y0);
  65700. if (curveness > 0) {
  65701. var x2 = (x0 + x1) / 2 - (y0 - y1) * curveness;
  65702. var y2 = (y0 + y1) / 2 - (x1 - x0) * curveness;
  65703. ctx.quadraticCurveTo(x2, y2, x1, y1);
  65704. } else {
  65705. ctx.lineTo(x1, y1);
  65706. }
  65707. }
  65708. }
  65709. if (this.incremental) {
  65710. this._off = i;
  65711. this.notClear = true;
  65712. }
  65713. };
  65714. LargeLinesPath.prototype.findDataIndex = function (x, y) {
  65715. var shape = this.shape;
  65716. var segs = shape.segs;
  65717. var curveness = shape.curveness;
  65718. var lineWidth = this.style.lineWidth;
  65719. if (shape.polyline) {
  65720. var dataIndex = 0;
  65721. for (var i = 0; i < segs.length;) {
  65722. var count = segs[i++];
  65723. if (count > 0) {
  65724. var x0 = segs[i++];
  65725. var y0 = segs[i++];
  65726. for (var k = 1; k < count; k++) {
  65727. var x1 = segs[i++];
  65728. var y1 = segs[i++];
  65729. if (containStroke(x0, y0, x1, y1, lineWidth, x, y)) {
  65730. return dataIndex;
  65731. }
  65732. }
  65733. }
  65734. dataIndex++;
  65735. }
  65736. } else {
  65737. var dataIndex = 0;
  65738. for (var i = 0; i < segs.length;) {
  65739. var x0 = segs[i++];
  65740. var y0 = segs[i++];
  65741. var x1 = segs[i++];
  65742. var y1 = segs[i++];
  65743. if (curveness > 0) {
  65744. var x2 = (x0 + x1) / 2 - (y0 - y1) * curveness;
  65745. var y2 = (y0 + y1) / 2 - (x1 - x0) * curveness;
  65746. if (containStroke$2(x0, y0, x2, y2, x1, y1, lineWidth, x, y)) {
  65747. return dataIndex;
  65748. }
  65749. } else {
  65750. if (containStroke(x0, y0, x1, y1, lineWidth, x, y)) {
  65751. return dataIndex;
  65752. }
  65753. }
  65754. dataIndex++;
  65755. }
  65756. }
  65757. return -1;
  65758. };
  65759. LargeLinesPath.prototype.contain = function (x, y) {
  65760. var localPos = this.transformCoordToLocal(x, y);
  65761. var rect = this.getBoundingRect();
  65762. x = localPos[0];
  65763. y = localPos[1];
  65764. if (rect.contain(x, y)) {
  65765. // Cache found data index.
  65766. var dataIdx = this.hoverDataIdx = this.findDataIndex(x, y);
  65767. return dataIdx >= 0;
  65768. }
  65769. this.hoverDataIdx = -1;
  65770. return false;
  65771. };
  65772. LargeLinesPath.prototype.getBoundingRect = function () {
  65773. // Ignore stroke for large symbol draw.
  65774. var rect = this._rect;
  65775. if (!rect) {
  65776. var shape = this.shape;
  65777. var points = shape.segs;
  65778. var minX = Infinity;
  65779. var minY = Infinity;
  65780. var maxX = -Infinity;
  65781. var maxY = -Infinity;
  65782. for (var i = 0; i < points.length;) {
  65783. var x = points[i++];
  65784. var y = points[i++];
  65785. minX = Math.min(x, minX);
  65786. maxX = Math.max(x, maxX);
  65787. minY = Math.min(y, minY);
  65788. maxY = Math.max(y, maxY);
  65789. }
  65790. rect = this._rect = new BoundingRect(minX, minY, maxX, maxY);
  65791. }
  65792. return rect;
  65793. };
  65794. return LargeLinesPath;
  65795. }(Path);
  65796. var LargeLineDraw = /** @class */function () {
  65797. function LargeLineDraw() {
  65798. this.group = new Group();
  65799. }
  65800. /**
  65801. * Update symbols draw by new data
  65802. */
  65803. LargeLineDraw.prototype.updateData = function (data) {
  65804. this._clear();
  65805. var lineEl = this._create();
  65806. lineEl.setShape({
  65807. segs: data.getLayout('linesPoints')
  65808. });
  65809. this._setCommon(lineEl, data);
  65810. };
  65811. /**
  65812. * @override
  65813. */
  65814. LargeLineDraw.prototype.incrementalPrepareUpdate = function (data) {
  65815. this.group.removeAll();
  65816. this._clear();
  65817. };
  65818. /**
  65819. * @override
  65820. */
  65821. LargeLineDraw.prototype.incrementalUpdate = function (taskParams, data) {
  65822. var lastAdded = this._newAdded[0];
  65823. var linePoints = data.getLayout('linesPoints');
  65824. var oldSegs = lastAdded && lastAdded.shape.segs;
  65825. // Merging the exists. Each element has 1e4 points.
  65826. // Consider the performance balance between too much elements and too much points in one shape(may affect hover optimization)
  65827. if (oldSegs && oldSegs.length < 2e4) {
  65828. var oldLen = oldSegs.length;
  65829. var newSegs = new Float32Array(oldLen + linePoints.length);
  65830. // Concat two array
  65831. newSegs.set(oldSegs);
  65832. newSegs.set(linePoints, oldLen);
  65833. lastAdded.setShape({
  65834. segs: newSegs
  65835. });
  65836. } else {
  65837. // Clear
  65838. this._newAdded = [];
  65839. var lineEl = this._create();
  65840. lineEl.incremental = true;
  65841. lineEl.setShape({
  65842. segs: linePoints
  65843. });
  65844. this._setCommon(lineEl, data);
  65845. lineEl.__startIndex = taskParams.start;
  65846. }
  65847. };
  65848. /**
  65849. * @override
  65850. */
  65851. LargeLineDraw.prototype.remove = function () {
  65852. this._clear();
  65853. };
  65854. LargeLineDraw.prototype.eachRendered = function (cb) {
  65855. this._newAdded[0] && cb(this._newAdded[0]);
  65856. };
  65857. LargeLineDraw.prototype._create = function () {
  65858. var lineEl = new LargeLinesPath({
  65859. cursor: 'default',
  65860. ignoreCoarsePointer: true
  65861. });
  65862. this._newAdded.push(lineEl);
  65863. this.group.add(lineEl);
  65864. return lineEl;
  65865. };
  65866. LargeLineDraw.prototype._setCommon = function (lineEl, data, isIncremental) {
  65867. var hostModel = data.hostModel;
  65868. lineEl.setShape({
  65869. polyline: hostModel.get('polyline'),
  65870. curveness: hostModel.get(['lineStyle', 'curveness'])
  65871. });
  65872. lineEl.useStyle(hostModel.getModel('lineStyle').getLineStyle());
  65873. lineEl.style.strokeNoScale = true;
  65874. var style = data.getVisual('style');
  65875. if (style && style.stroke) {
  65876. lineEl.setStyle('stroke', style.stroke);
  65877. }
  65878. lineEl.setStyle('fill', null);
  65879. var ecData = getECData(lineEl);
  65880. // Enable tooltip
  65881. // PENDING May have performance issue when path is extremely large
  65882. ecData.seriesIndex = hostModel.seriesIndex;
  65883. lineEl.on('mousemove', function (e) {
  65884. ecData.dataIndex = null;
  65885. var dataIndex = lineEl.hoverDataIdx;
  65886. if (dataIndex > 0) {
  65887. // Provide dataIndex for tooltip
  65888. ecData.dataIndex = dataIndex + lineEl.__startIndex;
  65889. }
  65890. });
  65891. };
  65892. LargeLineDraw.prototype._clear = function () {
  65893. this._newAdded = [];
  65894. this.group.removeAll();
  65895. };
  65896. return LargeLineDraw;
  65897. }();
  65898. var linesLayout = {
  65899. seriesType: 'lines',
  65900. plan: createRenderPlanner(),
  65901. reset: function (seriesModel) {
  65902. var coordSys = seriesModel.coordinateSystem;
  65903. if (!coordSys) {
  65904. if ("development" !== 'production') {
  65905. error('The lines series must have a coordinate system.');
  65906. }
  65907. return;
  65908. }
  65909. var isPolyline = seriesModel.get('polyline');
  65910. var isLarge = seriesModel.pipelineContext.large;
  65911. return {
  65912. progress: function (params, lineData) {
  65913. var lineCoords = [];
  65914. if (isLarge) {
  65915. var points = void 0;
  65916. var segCount = params.end - params.start;
  65917. if (isPolyline) {
  65918. var totalCoordsCount = 0;
  65919. for (var i = params.start; i < params.end; i++) {
  65920. totalCoordsCount += seriesModel.getLineCoordsCount(i);
  65921. }
  65922. points = new Float32Array(segCount + totalCoordsCount * 2);
  65923. } else {
  65924. points = new Float32Array(segCount * 4);
  65925. }
  65926. var offset = 0;
  65927. var pt = [];
  65928. for (var i = params.start; i < params.end; i++) {
  65929. var len = seriesModel.getLineCoords(i, lineCoords);
  65930. if (isPolyline) {
  65931. points[offset++] = len;
  65932. }
  65933. for (var k = 0; k < len; k++) {
  65934. pt = coordSys.dataToPoint(lineCoords[k], false, pt);
  65935. points[offset++] = pt[0];
  65936. points[offset++] = pt[1];
  65937. }
  65938. }
  65939. lineData.setLayout('linesPoints', points);
  65940. } else {
  65941. for (var i = params.start; i < params.end; i++) {
  65942. var itemModel = lineData.getItemModel(i);
  65943. var len = seriesModel.getLineCoords(i, lineCoords);
  65944. var pts = [];
  65945. if (isPolyline) {
  65946. for (var j = 0; j < len; j++) {
  65947. pts.push(coordSys.dataToPoint(lineCoords[j]));
  65948. }
  65949. } else {
  65950. pts[0] = coordSys.dataToPoint(lineCoords[0]);
  65951. pts[1] = coordSys.dataToPoint(lineCoords[1]);
  65952. var curveness = itemModel.get(['lineStyle', 'curveness']);
  65953. if (+curveness) {
  65954. pts[2] = [(pts[0][0] + pts[1][0]) / 2 - (pts[0][1] - pts[1][1]) * curveness, (pts[0][1] + pts[1][1]) / 2 - (pts[1][0] - pts[0][0]) * curveness];
  65955. }
  65956. }
  65957. lineData.setItemLayout(i, pts);
  65958. }
  65959. }
  65960. }
  65961. };
  65962. }
  65963. };
  65964. var LinesView = /** @class */function (_super) {
  65965. __extends(LinesView, _super);
  65966. function LinesView() {
  65967. var _this = _super !== null && _super.apply(this, arguments) || this;
  65968. _this.type = LinesView.type;
  65969. return _this;
  65970. }
  65971. LinesView.prototype.render = function (seriesModel, ecModel, api) {
  65972. var data = seriesModel.getData();
  65973. var lineDraw = this._updateLineDraw(data, seriesModel);
  65974. var zlevel = seriesModel.get('zlevel');
  65975. var trailLength = seriesModel.get(['effect', 'trailLength']);
  65976. var zr = api.getZr();
  65977. // Avoid the drag cause ghost shadow
  65978. // FIXME Better way ?
  65979. // SVG doesn't support
  65980. var isSvg = zr.painter.getType() === 'svg';
  65981. if (!isSvg) {
  65982. zr.painter.getLayer(zlevel).clear(true);
  65983. }
  65984. // Config layer with motion blur
  65985. if (this._lastZlevel != null && !isSvg) {
  65986. zr.configLayer(this._lastZlevel, {
  65987. motionBlur: false
  65988. });
  65989. }
  65990. if (this._showEffect(seriesModel) && trailLength > 0) {
  65991. if (!isSvg) {
  65992. zr.configLayer(zlevel, {
  65993. motionBlur: true,
  65994. lastFrameAlpha: Math.max(Math.min(trailLength / 10 + 0.9, 1), 0)
  65995. });
  65996. } else if ("development" !== 'production') {
  65997. console.warn('SVG render mode doesn\'t support lines with trail effect');
  65998. }
  65999. }
  66000. lineDraw.updateData(data);
  66001. var clipPath = seriesModel.get('clip', true) && createClipPath(seriesModel.coordinateSystem, false, seriesModel);
  66002. if (clipPath) {
  66003. this.group.setClipPath(clipPath);
  66004. } else {
  66005. this.group.removeClipPath();
  66006. }
  66007. this._lastZlevel = zlevel;
  66008. this._finished = true;
  66009. };
  66010. LinesView.prototype.incrementalPrepareRender = function (seriesModel, ecModel, api) {
  66011. var data = seriesModel.getData();
  66012. var lineDraw = this._updateLineDraw(data, seriesModel);
  66013. lineDraw.incrementalPrepareUpdate(data);
  66014. this._clearLayer(api);
  66015. this._finished = false;
  66016. };
  66017. LinesView.prototype.incrementalRender = function (taskParams, seriesModel, ecModel) {
  66018. this._lineDraw.incrementalUpdate(taskParams, seriesModel.getData());
  66019. this._finished = taskParams.end === seriesModel.getData().count();
  66020. };
  66021. LinesView.prototype.eachRendered = function (cb) {
  66022. this._lineDraw && this._lineDraw.eachRendered(cb);
  66023. };
  66024. LinesView.prototype.updateTransform = function (seriesModel, ecModel, api) {
  66025. var data = seriesModel.getData();
  66026. var pipelineContext = seriesModel.pipelineContext;
  66027. if (!this._finished || pipelineContext.large || pipelineContext.progressiveRender) {
  66028. // TODO Don't have to do update in large mode. Only do it when there are millions of data.
  66029. return {
  66030. update: true
  66031. };
  66032. } else {
  66033. // TODO Use same logic with ScatterView.
  66034. // Manually update layout
  66035. var res = linesLayout.reset(seriesModel, ecModel, api);
  66036. if (res.progress) {
  66037. res.progress({
  66038. start: 0,
  66039. end: data.count(),
  66040. count: data.count()
  66041. }, data);
  66042. }
  66043. // Not in large mode
  66044. this._lineDraw.updateLayout();
  66045. this._clearLayer(api);
  66046. }
  66047. };
  66048. LinesView.prototype._updateLineDraw = function (data, seriesModel) {
  66049. var lineDraw = this._lineDraw;
  66050. var hasEffect = this._showEffect(seriesModel);
  66051. var isPolyline = !!seriesModel.get('polyline');
  66052. var pipelineContext = seriesModel.pipelineContext;
  66053. var isLargeDraw = pipelineContext.large;
  66054. if ("development" !== 'production') {
  66055. if (hasEffect && isLargeDraw) {
  66056. console.warn('Large lines not support effect');
  66057. }
  66058. }
  66059. if (!lineDraw || hasEffect !== this._hasEffet || isPolyline !== this._isPolyline || isLargeDraw !== this._isLargeDraw) {
  66060. if (lineDraw) {
  66061. lineDraw.remove();
  66062. }
  66063. lineDraw = this._lineDraw = isLargeDraw ? new LargeLineDraw() : new LineDraw(isPolyline ? hasEffect ? EffectPolyline : Polyline$1 : hasEffect ? EffectLine : Line$1);
  66064. this._hasEffet = hasEffect;
  66065. this._isPolyline = isPolyline;
  66066. this._isLargeDraw = isLargeDraw;
  66067. }
  66068. this.group.add(lineDraw.group);
  66069. return lineDraw;
  66070. };
  66071. LinesView.prototype._showEffect = function (seriesModel) {
  66072. return !!seriesModel.get(['effect', 'show']);
  66073. };
  66074. LinesView.prototype._clearLayer = function (api) {
  66075. // Not use motion when dragging or zooming
  66076. var zr = api.getZr();
  66077. var isSvg = zr.painter.getType() === 'svg';
  66078. if (!isSvg && this._lastZlevel != null) {
  66079. zr.painter.getLayer(this._lastZlevel).clear(true);
  66080. }
  66081. };
  66082. LinesView.prototype.remove = function (ecModel, api) {
  66083. this._lineDraw && this._lineDraw.remove();
  66084. this._lineDraw = null;
  66085. // Clear motion when lineDraw is removed
  66086. this._clearLayer(api);
  66087. };
  66088. LinesView.prototype.dispose = function (ecModel, api) {
  66089. this.remove(ecModel, api);
  66090. };
  66091. LinesView.type = 'lines';
  66092. return LinesView;
  66093. }(ChartView);
  66094. var Uint32Arr = typeof Uint32Array === 'undefined' ? Array : Uint32Array;
  66095. var Float64Arr = typeof Float64Array === 'undefined' ? Array : Float64Array;
  66096. function compatEc2(seriesOpt) {
  66097. var data = seriesOpt.data;
  66098. if (data && data[0] && data[0][0] && data[0][0].coord) {
  66099. if ("development" !== 'production') {
  66100. console.warn('Lines data configuration has been changed to' + ' { coords:[[1,2],[2,3]] }');
  66101. }
  66102. seriesOpt.data = map(data, function (itemOpt) {
  66103. var coords = [itemOpt[0].coord, itemOpt[1].coord];
  66104. var target = {
  66105. coords: coords
  66106. };
  66107. if (itemOpt[0].name) {
  66108. target.fromName = itemOpt[0].name;
  66109. }
  66110. if (itemOpt[1].name) {
  66111. target.toName = itemOpt[1].name;
  66112. }
  66113. return mergeAll([target, itemOpt[0], itemOpt[1]]);
  66114. });
  66115. }
  66116. }
  66117. var LinesSeriesModel = /** @class */function (_super) {
  66118. __extends(LinesSeriesModel, _super);
  66119. function LinesSeriesModel() {
  66120. var _this = _super !== null && _super.apply(this, arguments) || this;
  66121. _this.type = LinesSeriesModel.type;
  66122. _this.visualStyleAccessPath = 'lineStyle';
  66123. _this.visualDrawType = 'stroke';
  66124. return _this;
  66125. }
  66126. LinesSeriesModel.prototype.init = function (option) {
  66127. // The input data may be null/undefined.
  66128. option.data = option.data || [];
  66129. // Not using preprocessor because mergeOption may not have series.type
  66130. compatEc2(option);
  66131. var result = this._processFlatCoordsArray(option.data);
  66132. this._flatCoords = result.flatCoords;
  66133. this._flatCoordsOffset = result.flatCoordsOffset;
  66134. if (result.flatCoords) {
  66135. option.data = new Float32Array(result.count);
  66136. }
  66137. _super.prototype.init.apply(this, arguments);
  66138. };
  66139. LinesSeriesModel.prototype.mergeOption = function (option) {
  66140. compatEc2(option);
  66141. if (option.data) {
  66142. // Only update when have option data to merge.
  66143. var result = this._processFlatCoordsArray(option.data);
  66144. this._flatCoords = result.flatCoords;
  66145. this._flatCoordsOffset = result.flatCoordsOffset;
  66146. if (result.flatCoords) {
  66147. option.data = new Float32Array(result.count);
  66148. }
  66149. }
  66150. _super.prototype.mergeOption.apply(this, arguments);
  66151. };
  66152. LinesSeriesModel.prototype.appendData = function (params) {
  66153. var result = this._processFlatCoordsArray(params.data);
  66154. if (result.flatCoords) {
  66155. if (!this._flatCoords) {
  66156. this._flatCoords = result.flatCoords;
  66157. this._flatCoordsOffset = result.flatCoordsOffset;
  66158. } else {
  66159. this._flatCoords = concatArray(this._flatCoords, result.flatCoords);
  66160. this._flatCoordsOffset = concatArray(this._flatCoordsOffset, result.flatCoordsOffset);
  66161. }
  66162. params.data = new Float32Array(result.count);
  66163. }
  66164. this.getRawData().appendData(params.data);
  66165. };
  66166. LinesSeriesModel.prototype._getCoordsFromItemModel = function (idx) {
  66167. var itemModel = this.getData().getItemModel(idx);
  66168. var coords = itemModel.option instanceof Array ? itemModel.option : itemModel.getShallow('coords');
  66169. if ("development" !== 'production') {
  66170. if (!(coords instanceof Array && coords.length > 0 && coords[0] instanceof Array)) {
  66171. throw new Error('Invalid coords ' + JSON.stringify(coords) + '. Lines must have 2d coords array in data item.');
  66172. }
  66173. }
  66174. return coords;
  66175. };
  66176. LinesSeriesModel.prototype.getLineCoordsCount = function (idx) {
  66177. if (this._flatCoordsOffset) {
  66178. return this._flatCoordsOffset[idx * 2 + 1];
  66179. } else {
  66180. return this._getCoordsFromItemModel(idx).length;
  66181. }
  66182. };
  66183. LinesSeriesModel.prototype.getLineCoords = function (idx, out) {
  66184. if (this._flatCoordsOffset) {
  66185. var offset = this._flatCoordsOffset[idx * 2];
  66186. var len = this._flatCoordsOffset[idx * 2 + 1];
  66187. for (var i = 0; i < len; i++) {
  66188. out[i] = out[i] || [];
  66189. out[i][0] = this._flatCoords[offset + i * 2];
  66190. out[i][1] = this._flatCoords[offset + i * 2 + 1];
  66191. }
  66192. return len;
  66193. } else {
  66194. var coords = this._getCoordsFromItemModel(idx);
  66195. for (var i = 0; i < coords.length; i++) {
  66196. out[i] = out[i] || [];
  66197. out[i][0] = coords[i][0];
  66198. out[i][1] = coords[i][1];
  66199. }
  66200. return coords.length;
  66201. }
  66202. };
  66203. LinesSeriesModel.prototype._processFlatCoordsArray = function (data) {
  66204. var startOffset = 0;
  66205. if (this._flatCoords) {
  66206. startOffset = this._flatCoords.length;
  66207. }
  66208. // Stored as a typed array. In format
  66209. // Points Count(2) | x | y | x | y | Points Count(3) | x | y | x | y | x | y |
  66210. if (isNumber(data[0])) {
  66211. var len = data.length;
  66212. // Store offset and len of each segment
  66213. var coordsOffsetAndLenStorage = new Uint32Arr(len);
  66214. var coordsStorage = new Float64Arr(len);
  66215. var coordsCursor = 0;
  66216. var offsetCursor = 0;
  66217. var dataCount = 0;
  66218. for (var i = 0; i < len;) {
  66219. dataCount++;
  66220. var count = data[i++];
  66221. // Offset
  66222. coordsOffsetAndLenStorage[offsetCursor++] = coordsCursor + startOffset;
  66223. // Len
  66224. coordsOffsetAndLenStorage[offsetCursor++] = count;
  66225. for (var k = 0; k < count; k++) {
  66226. var x = data[i++];
  66227. var y = data[i++];
  66228. coordsStorage[coordsCursor++] = x;
  66229. coordsStorage[coordsCursor++] = y;
  66230. if (i > len) {
  66231. if ("development" !== 'production') {
  66232. throw new Error('Invalid data format.');
  66233. }
  66234. }
  66235. }
  66236. }
  66237. return {
  66238. flatCoordsOffset: new Uint32Array(coordsOffsetAndLenStorage.buffer, 0, offsetCursor),
  66239. flatCoords: coordsStorage,
  66240. count: dataCount
  66241. };
  66242. }
  66243. return {
  66244. flatCoordsOffset: null,
  66245. flatCoords: null,
  66246. count: data.length
  66247. };
  66248. };
  66249. LinesSeriesModel.prototype.getInitialData = function (option, ecModel) {
  66250. if ("development" !== 'production') {
  66251. var CoordSys = CoordinateSystemManager.get(option.coordinateSystem);
  66252. if (!CoordSys) {
  66253. throw new Error('Unknown coordinate system ' + option.coordinateSystem);
  66254. }
  66255. }
  66256. var lineData = new SeriesData(['value'], this);
  66257. lineData.hasItemOption = false;
  66258. lineData.initData(option.data, [], function (dataItem, dimName, dataIndex, dimIndex) {
  66259. // dataItem is simply coords
  66260. if (dataItem instanceof Array) {
  66261. return NaN;
  66262. } else {
  66263. lineData.hasItemOption = true;
  66264. var value = dataItem.value;
  66265. if (value != null) {
  66266. return value instanceof Array ? value[dimIndex] : value;
  66267. }
  66268. }
  66269. });
  66270. return lineData;
  66271. };
  66272. LinesSeriesModel.prototype.formatTooltip = function (dataIndex, multipleSeries, dataType) {
  66273. var data = this.getData();
  66274. var itemModel = data.getItemModel(dataIndex);
  66275. var name = itemModel.get('name');
  66276. if (name) {
  66277. return name;
  66278. }
  66279. var fromName = itemModel.get('fromName');
  66280. var toName = itemModel.get('toName');
  66281. var nameArr = [];
  66282. fromName != null && nameArr.push(fromName);
  66283. toName != null && nameArr.push(toName);
  66284. return createTooltipMarkup('nameValue', {
  66285. name: nameArr.join(' > ')
  66286. });
  66287. };
  66288. LinesSeriesModel.prototype.preventIncremental = function () {
  66289. return !!this.get(['effect', 'show']);
  66290. };
  66291. LinesSeriesModel.prototype.getProgressive = function () {
  66292. var progressive = this.option.progressive;
  66293. if (progressive == null) {
  66294. return this.option.large ? 1e4 : this.get('progressive');
  66295. }
  66296. return progressive;
  66297. };
  66298. LinesSeriesModel.prototype.getProgressiveThreshold = function () {
  66299. var progressiveThreshold = this.option.progressiveThreshold;
  66300. if (progressiveThreshold == null) {
  66301. return this.option.large ? 2e4 : this.get('progressiveThreshold');
  66302. }
  66303. return progressiveThreshold;
  66304. };
  66305. LinesSeriesModel.prototype.getZLevelKey = function () {
  66306. var effectModel = this.getModel('effect');
  66307. var trailLength = effectModel.get('trailLength');
  66308. return this.getData().count() > this.getProgressiveThreshold()
  66309. // Each progressive series has individual key.
  66310. ? this.id : effectModel.get('show') && trailLength > 0 ? trailLength + '' : '';
  66311. };
  66312. LinesSeriesModel.type = 'series.lines';
  66313. LinesSeriesModel.dependencies = ['grid', 'polar', 'geo', 'calendar'];
  66314. LinesSeriesModel.defaultOption = {
  66315. coordinateSystem: 'geo',
  66316. // zlevel: 0,
  66317. z: 2,
  66318. legendHoverLink: true,
  66319. // Cartesian coordinate system
  66320. xAxisIndex: 0,
  66321. yAxisIndex: 0,
  66322. symbol: ['none', 'none'],
  66323. symbolSize: [10, 10],
  66324. // Geo coordinate system
  66325. geoIndex: 0,
  66326. effect: {
  66327. show: false,
  66328. period: 4,
  66329. constantSpeed: 0,
  66330. symbol: 'circle',
  66331. symbolSize: 3,
  66332. loop: true,
  66333. trailLength: 0.2
  66334. },
  66335. large: false,
  66336. // Available when large is true
  66337. largeThreshold: 2000,
  66338. polyline: false,
  66339. clip: true,
  66340. label: {
  66341. show: false,
  66342. position: 'end'
  66343. // distance: 5,
  66344. // formatter: 标签文本格式器,同Tooltip.formatter,不支持异步回调
  66345. },
  66346. lineStyle: {
  66347. opacity: 0.5
  66348. }
  66349. };
  66350. return LinesSeriesModel;
  66351. }(SeriesModel);
  66352. /*
  66353. * Licensed to the Apache Software Foundation (ASF) under one
  66354. * or more contributor license agreements. See the NOTICE file
  66355. * distributed with this work for additional information
  66356. * regarding copyright ownership. The ASF licenses this file
  66357. * to you under the Apache License, Version 2.0 (the
  66358. * "License"); you may not use this file except in compliance
  66359. * with the License. You may obtain a copy of the License at
  66360. *
  66361. * http://www.apache.org/licenses/LICENSE-2.0
  66362. *
  66363. * Unless required by applicable law or agreed to in writing,
  66364. * software distributed under the License is distributed on an
  66365. * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
  66366. * KIND, either express or implied. See the License for the
  66367. * specific language governing permissions and limitations
  66368. * under the License.
  66369. */
  66370. /**
  66371. * AUTO-GENERATED FILE. DO NOT MODIFY.
  66372. */
  66373. /*
  66374. * Licensed to the Apache Software Foundation (ASF) under one
  66375. * or more contributor license agreements. See the NOTICE file
  66376. * distributed with this work for additional information
  66377. * regarding copyright ownership. The ASF licenses this file
  66378. * to you under the Apache License, Version 2.0 (the
  66379. * "License"); you may not use this file except in compliance
  66380. * with the License. You may obtain a copy of the License at
  66381. *
  66382. * http://www.apache.org/licenses/LICENSE-2.0
  66383. *
  66384. * Unless required by applicable law or agreed to in writing,
  66385. * software distributed under the License is distributed on an
  66386. * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
  66387. * KIND, either express or implied. See the License for the
  66388. * specific language governing permissions and limitations
  66389. * under the License.
  66390. */
  66391. function normalize$3(a) {
  66392. if (!(a instanceof Array)) {
  66393. a = [a, a];
  66394. }
  66395. return a;
  66396. }
  66397. var linesVisual = {
  66398. seriesType: 'lines',
  66399. reset: function (seriesModel) {
  66400. var symbolType = normalize$3(seriesModel.get('symbol'));
  66401. var symbolSize = normalize$3(seriesModel.get('symbolSize'));
  66402. var data = seriesModel.getData();
  66403. data.setVisual('fromSymbol', symbolType && symbolType[0]);
  66404. data.setVisual('toSymbol', symbolType && symbolType[1]);
  66405. data.setVisual('fromSymbolSize', symbolSize && symbolSize[0]);
  66406. data.setVisual('toSymbolSize', symbolSize && symbolSize[1]);
  66407. function dataEach(data, idx) {
  66408. var itemModel = data.getItemModel(idx);
  66409. var symbolType = normalize$3(itemModel.getShallow('symbol', true));
  66410. var symbolSize = normalize$3(itemModel.getShallow('symbolSize', true));
  66411. symbolType[0] && data.setItemVisual(idx, 'fromSymbol', symbolType[0]);
  66412. symbolType[1] && data.setItemVisual(idx, 'toSymbol', symbolType[1]);
  66413. symbolSize[0] && data.setItemVisual(idx, 'fromSymbolSize', symbolSize[0]);
  66414. symbolSize[1] && data.setItemVisual(idx, 'toSymbolSize', symbolSize[1]);
  66415. }
  66416. return {
  66417. dataEach: data.hasItemOption ? dataEach : null
  66418. };
  66419. }
  66420. };
  66421. function install$n(registers) {
  66422. registers.registerChartView(LinesView);
  66423. registers.registerSeriesModel(LinesSeriesModel);
  66424. registers.registerLayout(linesLayout);
  66425. registers.registerVisual(linesVisual);
  66426. }
  66427. var GRADIENT_LEVELS = 256;
  66428. var HeatmapLayer = /** @class */function () {
  66429. function HeatmapLayer() {
  66430. this.blurSize = 30;
  66431. this.pointSize = 20;
  66432. this.maxOpacity = 1;
  66433. this.minOpacity = 0;
  66434. this._gradientPixels = {
  66435. inRange: null,
  66436. outOfRange: null
  66437. };
  66438. var canvas = platformApi.createCanvas();
  66439. this.canvas = canvas;
  66440. }
  66441. /**
  66442. * Renders Heatmap and returns the rendered canvas
  66443. * @param data array of data, each has x, y, value
  66444. * @param width canvas width
  66445. * @param height canvas height
  66446. */
  66447. HeatmapLayer.prototype.update = function (data, width, height, normalize, colorFunc, isInRange) {
  66448. var brush = this._getBrush();
  66449. var gradientInRange = this._getGradient(colorFunc, 'inRange');
  66450. var gradientOutOfRange = this._getGradient(colorFunc, 'outOfRange');
  66451. var r = this.pointSize + this.blurSize;
  66452. var canvas = this.canvas;
  66453. var ctx = canvas.getContext('2d');
  66454. var len = data.length;
  66455. canvas.width = width;
  66456. canvas.height = height;
  66457. for (var i = 0; i < len; ++i) {
  66458. var p = data[i];
  66459. var x = p[0];
  66460. var y = p[1];
  66461. var value = p[2];
  66462. // calculate alpha using value
  66463. var alpha = normalize(value);
  66464. // draw with the circle brush with alpha
  66465. ctx.globalAlpha = alpha;
  66466. ctx.drawImage(brush, x - r, y - r);
  66467. }
  66468. if (!canvas.width || !canvas.height) {
  66469. // Avoid "Uncaught DOMException: Failed to execute 'getImageData' on
  66470. // 'CanvasRenderingContext2D': The source height is 0."
  66471. return canvas;
  66472. }
  66473. // colorize the canvas using alpha value and set with gradient
  66474. var imageData = ctx.getImageData(0, 0, canvas.width, canvas.height);
  66475. var pixels = imageData.data;
  66476. var offset = 0;
  66477. var pixelLen = pixels.length;
  66478. var minOpacity = this.minOpacity;
  66479. var maxOpacity = this.maxOpacity;
  66480. var diffOpacity = maxOpacity - minOpacity;
  66481. while (offset < pixelLen) {
  66482. var alpha = pixels[offset + 3] / 256;
  66483. var gradientOffset = Math.floor(alpha * (GRADIENT_LEVELS - 1)) * 4;
  66484. // Simple optimize to ignore the empty data
  66485. if (alpha > 0) {
  66486. var gradient = isInRange(alpha) ? gradientInRange : gradientOutOfRange;
  66487. // Any alpha > 0 will be mapped to [minOpacity, maxOpacity]
  66488. alpha > 0 && (alpha = alpha * diffOpacity + minOpacity);
  66489. pixels[offset++] = gradient[gradientOffset];
  66490. pixels[offset++] = gradient[gradientOffset + 1];
  66491. pixels[offset++] = gradient[gradientOffset + 2];
  66492. pixels[offset++] = gradient[gradientOffset + 3] * alpha * 256;
  66493. } else {
  66494. offset += 4;
  66495. }
  66496. }
  66497. ctx.putImageData(imageData, 0, 0);
  66498. return canvas;
  66499. };
  66500. /**
  66501. * get canvas of a black circle brush used for canvas to draw later
  66502. */
  66503. HeatmapLayer.prototype._getBrush = function () {
  66504. var brushCanvas = this._brushCanvas || (this._brushCanvas = platformApi.createCanvas());
  66505. // set brush size
  66506. var r = this.pointSize + this.blurSize;
  66507. var d = r * 2;
  66508. brushCanvas.width = d;
  66509. brushCanvas.height = d;
  66510. var ctx = brushCanvas.getContext('2d');
  66511. ctx.clearRect(0, 0, d, d);
  66512. // in order to render shadow without the distinct circle,
  66513. // draw the distinct circle in an invisible place,
  66514. // and use shadowOffset to draw shadow in the center of the canvas
  66515. ctx.shadowOffsetX = d;
  66516. ctx.shadowBlur = this.blurSize;
  66517. // draw the shadow in black, and use alpha and shadow blur to generate
  66518. // color in color map
  66519. ctx.shadowColor = tokens.color.neutral99;
  66520. // draw circle in the left to the canvas
  66521. ctx.beginPath();
  66522. ctx.arc(-r, r, this.pointSize, 0, Math.PI * 2, true);
  66523. ctx.closePath();
  66524. ctx.fill();
  66525. return brushCanvas;
  66526. };
  66527. /**
  66528. * get gradient color map
  66529. * @private
  66530. */
  66531. HeatmapLayer.prototype._getGradient = function (colorFunc, state) {
  66532. var gradientPixels = this._gradientPixels;
  66533. var pixelsSingleState = gradientPixels[state] || (gradientPixels[state] = new Uint8ClampedArray(256 * 4));
  66534. var color = [0, 0, 0, 0];
  66535. var off = 0;
  66536. for (var i = 0; i < 256; i++) {
  66537. colorFunc[state](i / 255, true, color);
  66538. pixelsSingleState[off++] = color[0];
  66539. pixelsSingleState[off++] = color[1];
  66540. pixelsSingleState[off++] = color[2];
  66541. pixelsSingleState[off++] = color[3];
  66542. }
  66543. return pixelsSingleState;
  66544. };
  66545. return HeatmapLayer;
  66546. }();
  66547. function getIsInPiecewiseRange(dataExtent, pieceList, selected) {
  66548. var dataSpan = dataExtent[1] - dataExtent[0];
  66549. pieceList = map(pieceList, function (piece) {
  66550. return {
  66551. interval: [(piece.interval[0] - dataExtent[0]) / dataSpan, (piece.interval[1] - dataExtent[0]) / dataSpan]
  66552. };
  66553. });
  66554. var len = pieceList.length;
  66555. var lastIndex = 0;
  66556. return function (val) {
  66557. var i;
  66558. // Try to find in the location of the last found
  66559. for (i = lastIndex; i < len; i++) {
  66560. var interval = pieceList[i].interval;
  66561. if (interval[0] <= val && val <= interval[1]) {
  66562. lastIndex = i;
  66563. break;
  66564. }
  66565. }
  66566. if (i === len) {
  66567. // Not found, back interation
  66568. for (i = lastIndex - 1; i >= 0; i--) {
  66569. var interval = pieceList[i].interval;
  66570. if (interval[0] <= val && val <= interval[1]) {
  66571. lastIndex = i;
  66572. break;
  66573. }
  66574. }
  66575. }
  66576. return i >= 0 && i < len && selected[i];
  66577. };
  66578. }
  66579. function getIsInContinuousRange(dataExtent, range) {
  66580. var dataSpan = dataExtent[1] - dataExtent[0];
  66581. range = [(range[0] - dataExtent[0]) / dataSpan, (range[1] - dataExtent[0]) / dataSpan];
  66582. return function (val) {
  66583. return val >= range[0] && val <= range[1];
  66584. };
  66585. }
  66586. function isGeoCoordSys(coordSys) {
  66587. var dimensions = coordSys.dimensions;
  66588. // Not use coordSys.type === 'geo' because coordSys maybe extended
  66589. return dimensions[0] === 'lng' && dimensions[1] === 'lat';
  66590. }
  66591. var HeatmapView = /** @class */function (_super) {
  66592. __extends(HeatmapView, _super);
  66593. function HeatmapView() {
  66594. var _this = _super !== null && _super.apply(this, arguments) || this;
  66595. _this.type = HeatmapView.type;
  66596. return _this;
  66597. }
  66598. HeatmapView.prototype.render = function (seriesModel, ecModel, api) {
  66599. var visualMapOfThisSeries;
  66600. ecModel.eachComponent('visualMap', function (visualMap) {
  66601. visualMap.eachTargetSeries(function (targetSeries) {
  66602. if (targetSeries === seriesModel) {
  66603. visualMapOfThisSeries = visualMap;
  66604. }
  66605. });
  66606. });
  66607. if ("development" !== 'production') {
  66608. if (!visualMapOfThisSeries) {
  66609. throw new Error('Heatmap must use with visualMap');
  66610. }
  66611. }
  66612. // Clear previously rendered progressive elements.
  66613. this._progressiveEls = null;
  66614. this.group.removeAll();
  66615. var coordSys = seriesModel.coordinateSystem;
  66616. if (coordSys.type === 'cartesian2d' || coordSys.type === 'calendar' || coordSys.type === 'matrix') {
  66617. this._renderOnGridLike(seriesModel, api, 0, seriesModel.getData().count());
  66618. } else if (isGeoCoordSys(coordSys)) {
  66619. this._renderOnGeo(coordSys, seriesModel, visualMapOfThisSeries, api);
  66620. }
  66621. };
  66622. HeatmapView.prototype.incrementalPrepareRender = function (seriesModel, ecModel, api) {
  66623. this.group.removeAll();
  66624. };
  66625. HeatmapView.prototype.incrementalRender = function (params, seriesModel, ecModel, api) {
  66626. var coordSys = seriesModel.coordinateSystem;
  66627. if (coordSys) {
  66628. // geo does not support incremental rendering?
  66629. if (isGeoCoordSys(coordSys)) {
  66630. this.render(seriesModel, ecModel, api);
  66631. } else {
  66632. this._progressiveEls = [];
  66633. this._renderOnGridLike(seriesModel, api, params.start, params.end, true);
  66634. }
  66635. }
  66636. };
  66637. HeatmapView.prototype.eachRendered = function (cb) {
  66638. traverseElements(this._progressiveEls || this.group, cb);
  66639. };
  66640. HeatmapView.prototype._renderOnGridLike = function (seriesModel, api, start, end, incremental) {
  66641. var coordSys = seriesModel.coordinateSystem;
  66642. var isCartesian2d = isCoordinateSystemType(coordSys, 'cartesian2d');
  66643. var isMatrix = isCoordinateSystemType(coordSys, 'matrix');
  66644. var width;
  66645. var height;
  66646. var xAxisExtent;
  66647. var yAxisExtent;
  66648. if (isCartesian2d) {
  66649. var xAxis = coordSys.getAxis('x');
  66650. var yAxis = coordSys.getAxis('y');
  66651. if ("development" !== 'production') {
  66652. if (!(xAxis.type === 'category' && yAxis.type === 'category')) {
  66653. throw new Error('Heatmap on cartesian must have two category axes');
  66654. }
  66655. if (!(xAxis.onBand && yAxis.onBand)) {
  66656. throw new Error('Heatmap on cartesian must have two axes with boundaryGap true');
  66657. }
  66658. }
  66659. // add 0.5px to avoid the gaps
  66660. width = xAxis.getBandWidth() + .5;
  66661. height = yAxis.getBandWidth() + .5;
  66662. xAxisExtent = xAxis.scale.getExtent();
  66663. yAxisExtent = yAxis.scale.getExtent();
  66664. }
  66665. var group = this.group;
  66666. var data = seriesModel.getData();
  66667. var emphasisStyle = seriesModel.getModel(['emphasis', 'itemStyle']).getItemStyle();
  66668. var blurStyle = seriesModel.getModel(['blur', 'itemStyle']).getItemStyle();
  66669. var selectStyle = seriesModel.getModel(['select', 'itemStyle']).getItemStyle();
  66670. var borderRadius = seriesModel.get(['itemStyle', 'borderRadius']);
  66671. var labelStatesModels = getLabelStatesModels(seriesModel);
  66672. var emphasisModel = seriesModel.getModel('emphasis');
  66673. var focus = emphasisModel.get('focus');
  66674. var blurScope = emphasisModel.get('blurScope');
  66675. var emphasisDisabled = emphasisModel.get('disabled');
  66676. var dataDims = isCartesian2d || isMatrix ? [data.mapDimension('x'), data.mapDimension('y'), data.mapDimension('value')] : [data.mapDimension('time'), data.mapDimension('value')];
  66677. for (var idx = start; idx < end; idx++) {
  66678. var rect = void 0;
  66679. var style = data.getItemVisual(idx, 'style');
  66680. if (isCartesian2d) {
  66681. var dataDimX = data.get(dataDims[0], idx);
  66682. var dataDimY = data.get(dataDims[1], idx);
  66683. // Ignore empty data and out of extent data
  66684. if (isNaN(data.get(dataDims[2], idx)) || isNaN(dataDimX) || isNaN(dataDimY) || dataDimX < xAxisExtent[0] || dataDimX > xAxisExtent[1] || dataDimY < yAxisExtent[0] || dataDimY > yAxisExtent[1]) {
  66685. continue;
  66686. }
  66687. var point = coordSys.dataToPoint([dataDimX, dataDimY]);
  66688. rect = new Rect({
  66689. shape: {
  66690. x: point[0] - width / 2,
  66691. y: point[1] - height / 2,
  66692. width: width,
  66693. height: height
  66694. },
  66695. style: style
  66696. });
  66697. } else if (isMatrix) {
  66698. var shape = coordSys.dataToLayout([data.get(dataDims[0], idx), data.get(dataDims[1], idx)]).rect;
  66699. if (eqNaN(shape.x)) {
  66700. continue;
  66701. }
  66702. rect = new Rect({
  66703. z2: 1,
  66704. shape: shape,
  66705. style: style
  66706. });
  66707. } else {
  66708. // Calendar
  66709. // Ignore empty data
  66710. if (isNaN(data.get(dataDims[1], idx))) {
  66711. continue;
  66712. }
  66713. var layout = coordSys.dataToLayout([data.get(dataDims[0], idx)]);
  66714. var shape = layout.contentRect || layout.rect;
  66715. if (eqNaN(shape.x) || eqNaN(shape.y)) {
  66716. continue;
  66717. }
  66718. rect = new Rect({
  66719. z2: 1,
  66720. shape: shape,
  66721. style: style
  66722. });
  66723. }
  66724. // Optimization for large dataset
  66725. if (data.hasItemOption) {
  66726. var itemModel = data.getItemModel(idx);
  66727. var emphasisModel_1 = itemModel.getModel('emphasis');
  66728. emphasisStyle = emphasisModel_1.getModel('itemStyle').getItemStyle();
  66729. blurStyle = itemModel.getModel(['blur', 'itemStyle']).getItemStyle();
  66730. selectStyle = itemModel.getModel(['select', 'itemStyle']).getItemStyle();
  66731. // Each item value struct in the data would be firstly
  66732. // {
  66733. // itemStyle: { borderRadius: [30, 30] },
  66734. // value: [2022, 02, 22]
  66735. // }
  66736. borderRadius = itemModel.get(['itemStyle', 'borderRadius']);
  66737. focus = emphasisModel_1.get('focus');
  66738. blurScope = emphasisModel_1.get('blurScope');
  66739. emphasisDisabled = emphasisModel_1.get('disabled');
  66740. labelStatesModels = getLabelStatesModels(itemModel);
  66741. }
  66742. rect.shape.r = borderRadius;
  66743. var rawValue = seriesModel.getRawValue(idx);
  66744. var defaultText = '-';
  66745. if (rawValue && rawValue[2] != null) {
  66746. defaultText = rawValue[2] + '';
  66747. }
  66748. setLabelStyle(rect, labelStatesModels, {
  66749. labelFetcher: seriesModel,
  66750. labelDataIndex: idx,
  66751. defaultOpacity: style.opacity,
  66752. defaultText: defaultText
  66753. });
  66754. rect.ensureState('emphasis').style = emphasisStyle;
  66755. rect.ensureState('blur').style = blurStyle;
  66756. rect.ensureState('select').style = selectStyle;
  66757. toggleHoverEmphasis(rect, focus, blurScope, emphasisDisabled);
  66758. rect.incremental = incremental;
  66759. // PENDING
  66760. if (incremental) {
  66761. // Rect must use hover layer if it's incremental.
  66762. rect.states.emphasis.hoverLayer = true;
  66763. }
  66764. group.add(rect);
  66765. data.setItemGraphicEl(idx, rect);
  66766. if (this._progressiveEls) {
  66767. this._progressiveEls.push(rect);
  66768. }
  66769. }
  66770. };
  66771. HeatmapView.prototype._renderOnGeo = function (geo, seriesModel, visualMapModel, api) {
  66772. var inRangeVisuals = visualMapModel.targetVisuals.inRange;
  66773. var outOfRangeVisuals = visualMapModel.targetVisuals.outOfRange;
  66774. // if (!visualMapping) {
  66775. // throw new Error('Data range must have color visuals');
  66776. // }
  66777. var data = seriesModel.getData();
  66778. var hmLayer = this._hmLayer || this._hmLayer || new HeatmapLayer();
  66779. hmLayer.blurSize = seriesModel.get('blurSize');
  66780. hmLayer.pointSize = seriesModel.get('pointSize');
  66781. hmLayer.minOpacity = seriesModel.get('minOpacity');
  66782. hmLayer.maxOpacity = seriesModel.get('maxOpacity');
  66783. var rect = geo.getViewRect().clone();
  66784. var roamTransform = geo.getRoamTransform();
  66785. rect.applyTransform(roamTransform);
  66786. // Clamp on viewport
  66787. var x = Math.max(rect.x, 0);
  66788. var y = Math.max(rect.y, 0);
  66789. var x2 = Math.min(rect.width + rect.x, api.getWidth());
  66790. var y2 = Math.min(rect.height + rect.y, api.getHeight());
  66791. var width = x2 - x;
  66792. var height = y2 - y;
  66793. var dims = [data.mapDimension('lng'), data.mapDimension('lat'), data.mapDimension('value')];
  66794. var points = data.mapArray(dims, function (lng, lat, value) {
  66795. var pt = geo.dataToPoint([lng, lat]);
  66796. pt[0] -= x;
  66797. pt[1] -= y;
  66798. pt.push(value);
  66799. return pt;
  66800. });
  66801. var dataExtent = visualMapModel.getExtent();
  66802. var isInRange = visualMapModel.type === 'visualMap.continuous' ? getIsInContinuousRange(dataExtent, visualMapModel.option.range) : getIsInPiecewiseRange(dataExtent, visualMapModel.getPieceList(), visualMapModel.option.selected);
  66803. hmLayer.update(points, width, height, inRangeVisuals.color.getNormalizer(), {
  66804. inRange: inRangeVisuals.color.getColorMapper(),
  66805. outOfRange: outOfRangeVisuals.color.getColorMapper()
  66806. }, isInRange);
  66807. var img = new ZRImage({
  66808. style: {
  66809. width: width,
  66810. height: height,
  66811. x: x,
  66812. y: y,
  66813. image: hmLayer.canvas
  66814. },
  66815. silent: true
  66816. });
  66817. this.group.add(img);
  66818. };
  66819. HeatmapView.type = 'heatmap';
  66820. return HeatmapView;
  66821. }(ChartView);
  66822. var HeatmapSeriesModel = /** @class */function (_super) {
  66823. __extends(HeatmapSeriesModel, _super);
  66824. function HeatmapSeriesModel() {
  66825. var _this = _super !== null && _super.apply(this, arguments) || this;
  66826. _this.type = HeatmapSeriesModel.type;
  66827. return _this;
  66828. }
  66829. HeatmapSeriesModel.prototype.getInitialData = function (option, ecModel) {
  66830. return createSeriesData(null, this, {
  66831. generateCoord: 'value'
  66832. });
  66833. };
  66834. HeatmapSeriesModel.prototype.preventIncremental = function () {
  66835. var coordSysCreator = CoordinateSystemManager.get(this.get('coordinateSystem'));
  66836. if (coordSysCreator && coordSysCreator.dimensions) {
  66837. return coordSysCreator.dimensions[0] === 'lng' && coordSysCreator.dimensions[1] === 'lat';
  66838. }
  66839. };
  66840. HeatmapSeriesModel.type = 'series.heatmap';
  66841. HeatmapSeriesModel.dependencies = ['grid', 'geo', 'calendar', 'matrix'];
  66842. HeatmapSeriesModel.defaultOption = {
  66843. coordinateSystem: 'cartesian2d',
  66844. // zlevel: 0,
  66845. z: 2,
  66846. // Cartesian coordinate system
  66847. // xAxisIndex: 0,
  66848. // yAxisIndex: 0,
  66849. // Geo coordinate system
  66850. geoIndex: 0,
  66851. blurSize: 30,
  66852. pointSize: 20,
  66853. maxOpacity: 1,
  66854. minOpacity: 0,
  66855. select: {
  66856. itemStyle: {
  66857. borderColor: tokens.color.primary
  66858. }
  66859. }
  66860. };
  66861. return HeatmapSeriesModel;
  66862. }(SeriesModel);
  66863. function install$o(registers) {
  66864. registers.registerChartView(HeatmapView);
  66865. registers.registerSeriesModel(HeatmapSeriesModel);
  66866. }
  66867. var BAR_BORDER_WIDTH_QUERY = ['itemStyle', 'borderWidth'];
  66868. // index: +isHorizontal
  66869. var LAYOUT_ATTRS = [{
  66870. xy: 'x',
  66871. wh: 'width',
  66872. index: 0,
  66873. posDesc: ['left', 'right']
  66874. }, {
  66875. xy: 'y',
  66876. wh: 'height',
  66877. index: 1,
  66878. posDesc: ['top', 'bottom']
  66879. }];
  66880. var pathForLineWidth = new Circle();
  66881. var PictorialBarView = /** @class */function (_super) {
  66882. __extends(PictorialBarView, _super);
  66883. function PictorialBarView() {
  66884. var _this = _super !== null && _super.apply(this, arguments) || this;
  66885. _this.type = PictorialBarView.type;
  66886. return _this;
  66887. }
  66888. PictorialBarView.prototype.render = function (seriesModel, ecModel, api) {
  66889. var group = this.group;
  66890. var data = seriesModel.getData();
  66891. var oldData = this._data;
  66892. var cartesian = seriesModel.coordinateSystem;
  66893. var baseAxis = cartesian.getBaseAxis();
  66894. var isHorizontal = baseAxis.isHorizontal();
  66895. var coordSysRect = cartesian.master.getRect();
  66896. var opt = {
  66897. ecSize: {
  66898. width: api.getWidth(),
  66899. height: api.getHeight()
  66900. },
  66901. seriesModel: seriesModel,
  66902. coordSys: cartesian,
  66903. coordSysExtent: [[coordSysRect.x, coordSysRect.x + coordSysRect.width], [coordSysRect.y, coordSysRect.y + coordSysRect.height]],
  66904. isHorizontal: isHorizontal,
  66905. valueDim: LAYOUT_ATTRS[+isHorizontal],
  66906. categoryDim: LAYOUT_ATTRS[1 - +isHorizontal]
  66907. };
  66908. data.diff(oldData).add(function (dataIndex) {
  66909. if (!data.hasValue(dataIndex)) {
  66910. return;
  66911. }
  66912. var itemModel = getItemModel(data, dataIndex);
  66913. var symbolMeta = getSymbolMeta(data, dataIndex, itemModel, opt);
  66914. var bar = createBar(data, opt, symbolMeta);
  66915. data.setItemGraphicEl(dataIndex, bar);
  66916. group.add(bar);
  66917. updateCommon$1(bar, opt, symbolMeta);
  66918. }).update(function (newIndex, oldIndex) {
  66919. var bar = oldData.getItemGraphicEl(oldIndex);
  66920. if (!data.hasValue(newIndex)) {
  66921. group.remove(bar);
  66922. return;
  66923. }
  66924. var itemModel = getItemModel(data, newIndex);
  66925. var symbolMeta = getSymbolMeta(data, newIndex, itemModel, opt);
  66926. var pictorialShapeStr = getShapeStr(data, symbolMeta);
  66927. if (bar && pictorialShapeStr !== bar.__pictorialShapeStr) {
  66928. group.remove(bar);
  66929. data.setItemGraphicEl(newIndex, null);
  66930. bar = null;
  66931. }
  66932. if (bar) {
  66933. updateBar(bar, opt, symbolMeta);
  66934. } else {
  66935. bar = createBar(data, opt, symbolMeta, true);
  66936. }
  66937. data.setItemGraphicEl(newIndex, bar);
  66938. bar.__pictorialSymbolMeta = symbolMeta;
  66939. // Add back
  66940. group.add(bar);
  66941. updateCommon$1(bar, opt, symbolMeta);
  66942. }).remove(function (dataIndex) {
  66943. var bar = oldData.getItemGraphicEl(dataIndex);
  66944. bar && removeBar(oldData, dataIndex, bar.__pictorialSymbolMeta.animationModel, bar);
  66945. }).execute();
  66946. // Do clipping
  66947. var clipPath = seriesModel.get('clip', true) ? createClipPath(seriesModel.coordinateSystem, false, seriesModel) : null;
  66948. if (clipPath) {
  66949. group.setClipPath(clipPath);
  66950. } else {
  66951. group.removeClipPath();
  66952. }
  66953. this._data = data;
  66954. return this.group;
  66955. };
  66956. PictorialBarView.prototype.remove = function (ecModel, api) {
  66957. var group = this.group;
  66958. var data = this._data;
  66959. if (ecModel.get('animation')) {
  66960. if (data) {
  66961. data.eachItemGraphicEl(function (bar) {
  66962. removeBar(data, getECData(bar).dataIndex, ecModel, bar);
  66963. });
  66964. }
  66965. } else {
  66966. group.removeAll();
  66967. }
  66968. };
  66969. PictorialBarView.type = 'pictorialBar';
  66970. return PictorialBarView;
  66971. }(ChartView);
  66972. // Set or calculate default value about symbol, and calculate layout info.
  66973. function getSymbolMeta(data, dataIndex, itemModel, opt) {
  66974. var layout = data.getItemLayout(dataIndex);
  66975. var symbolRepeat = itemModel.get('symbolRepeat');
  66976. var symbolClip = itemModel.get('symbolClip');
  66977. var symbolPosition = itemModel.get('symbolPosition') || 'start';
  66978. var symbolRotate = itemModel.get('symbolRotate');
  66979. var rotation = (symbolRotate || 0) * Math.PI / 180 || 0;
  66980. var symbolPatternSize = itemModel.get('symbolPatternSize') || 2;
  66981. var isAnimationEnabled = itemModel.isAnimationEnabled();
  66982. var symbolMeta = {
  66983. dataIndex: dataIndex,
  66984. layout: layout,
  66985. itemModel: itemModel,
  66986. symbolType: data.getItemVisual(dataIndex, 'symbol') || 'circle',
  66987. style: data.getItemVisual(dataIndex, 'style'),
  66988. symbolClip: symbolClip,
  66989. symbolRepeat: symbolRepeat,
  66990. symbolRepeatDirection: itemModel.get('symbolRepeatDirection'),
  66991. symbolPatternSize: symbolPatternSize,
  66992. rotation: rotation,
  66993. animationModel: isAnimationEnabled ? itemModel : null,
  66994. hoverScale: isAnimationEnabled && itemModel.get(['emphasis', 'scale']),
  66995. z2: itemModel.getShallow('z', true) || 0
  66996. };
  66997. prepareBarLength(itemModel, symbolRepeat, layout, opt, symbolMeta);
  66998. prepareSymbolSize(data, dataIndex, layout, symbolRepeat, symbolClip, symbolMeta.boundingLength, symbolMeta.pxSign, symbolPatternSize, opt, symbolMeta);
  66999. prepareLineWidth(itemModel, symbolMeta.symbolScale, rotation, opt, symbolMeta);
  67000. var symbolSize = symbolMeta.symbolSize;
  67001. var symbolOffset = normalizeSymbolOffset(itemModel.get('symbolOffset'), symbolSize);
  67002. prepareLayoutInfo(itemModel, symbolSize, layout, symbolRepeat, symbolClip, symbolOffset, symbolPosition, symbolMeta.valueLineWidth, symbolMeta.boundingLength, symbolMeta.repeatCutLength, opt, symbolMeta);
  67003. return symbolMeta;
  67004. }
  67005. // bar length can be negative.
  67006. function prepareBarLength(itemModel, symbolRepeat, layout, opt, outputSymbolMeta) {
  67007. var valueDim = opt.valueDim;
  67008. var symbolBoundingData = itemModel.get('symbolBoundingData');
  67009. var valueAxis = opt.coordSys.getOtherAxis(opt.coordSys.getBaseAxis());
  67010. var zeroPx = valueAxis.toGlobalCoord(valueAxis.dataToCoord(0));
  67011. var pxSignIdx = 1 - +(layout[valueDim.wh] <= 0);
  67012. var boundingLength;
  67013. if (isArray(symbolBoundingData)) {
  67014. var symbolBoundingExtent = [convertToCoordOnAxis(valueAxis, symbolBoundingData[0]) - zeroPx, convertToCoordOnAxis(valueAxis, symbolBoundingData[1]) - zeroPx];
  67015. symbolBoundingExtent[1] < symbolBoundingExtent[0] && symbolBoundingExtent.reverse();
  67016. boundingLength = symbolBoundingExtent[pxSignIdx];
  67017. } else if (symbolBoundingData != null) {
  67018. boundingLength = convertToCoordOnAxis(valueAxis, symbolBoundingData) - zeroPx;
  67019. } else if (symbolRepeat) {
  67020. boundingLength = opt.coordSysExtent[valueDim.index][pxSignIdx] - zeroPx;
  67021. } else {
  67022. boundingLength = layout[valueDim.wh];
  67023. }
  67024. outputSymbolMeta.boundingLength = boundingLength;
  67025. if (symbolRepeat) {
  67026. outputSymbolMeta.repeatCutLength = layout[valueDim.wh];
  67027. }
  67028. // if 'pxSign' means sign of pixel, it can't be zero, or symbolScale will be zero
  67029. // and when borderWidth be settled, the actual linewidth will be NaN
  67030. var isXAxis = valueDim.xy === 'x';
  67031. var isInverse = valueAxis.inverse;
  67032. outputSymbolMeta.pxSign = isXAxis && !isInverse || !isXAxis && isInverse ? boundingLength >= 0 ? 1 : -1 : boundingLength > 0 ? 1 : -1;
  67033. }
  67034. function convertToCoordOnAxis(axis, value) {
  67035. return axis.toGlobalCoord(axis.dataToCoord(axis.scale.parse(value)));
  67036. }
  67037. // Support ['100%', '100%']
  67038. function prepareSymbolSize(data, dataIndex, layout, symbolRepeat, symbolClip, boundingLength, pxSign, symbolPatternSize, opt, outputSymbolMeta) {
  67039. var valueDim = opt.valueDim;
  67040. var categoryDim = opt.categoryDim;
  67041. var categorySize = Math.abs(layout[categoryDim.wh]);
  67042. var symbolSize = data.getItemVisual(dataIndex, 'symbolSize');
  67043. var parsedSymbolSize;
  67044. if (isArray(symbolSize)) {
  67045. parsedSymbolSize = symbolSize.slice();
  67046. } else {
  67047. if (symbolSize == null) {
  67048. // will parse to number below
  67049. parsedSymbolSize = ['100%', '100%'];
  67050. } else {
  67051. parsedSymbolSize = [symbolSize, symbolSize];
  67052. }
  67053. }
  67054. // Note: percentage symbolSize (like '100%') do not consider lineWidth, because it is
  67055. // to complicated to calculate real percent value if considering scaled lineWidth.
  67056. // So the actual size will bigger than layout size if lineWidth is bigger than zero,
  67057. // which can be tolerated in pictorial chart.
  67058. parsedSymbolSize[categoryDim.index] = parsePercent$1(parsedSymbolSize[categoryDim.index], categorySize);
  67059. parsedSymbolSize[valueDim.index] = parsePercent$1(parsedSymbolSize[valueDim.index], symbolRepeat ? categorySize : Math.abs(boundingLength));
  67060. outputSymbolMeta.symbolSize = parsedSymbolSize;
  67061. // If x or y is less than zero, show reversed shape.
  67062. var symbolScale = outputSymbolMeta.symbolScale = [parsedSymbolSize[0] / symbolPatternSize, parsedSymbolSize[1] / symbolPatternSize];
  67063. // Follow convention, 'right' and 'top' is the normal scale.
  67064. symbolScale[valueDim.index] *= (opt.isHorizontal ? -1 : 1) * pxSign;
  67065. }
  67066. function prepareLineWidth(itemModel, symbolScale, rotation, opt, outputSymbolMeta) {
  67067. // In symbols are drawn with scale, so do not need to care about the case that width
  67068. // or height are too small. But symbol use strokeNoScale, where acture lineWidth should
  67069. // be calculated.
  67070. var valueLineWidth = itemModel.get(BAR_BORDER_WIDTH_QUERY) || 0;
  67071. if (valueLineWidth) {
  67072. pathForLineWidth.attr({
  67073. scaleX: symbolScale[0],
  67074. scaleY: symbolScale[1],
  67075. rotation: rotation
  67076. });
  67077. pathForLineWidth.updateTransform();
  67078. valueLineWidth /= pathForLineWidth.getLineScale();
  67079. valueLineWidth *= symbolScale[opt.valueDim.index];
  67080. }
  67081. outputSymbolMeta.valueLineWidth = valueLineWidth || 0;
  67082. }
  67083. function prepareLayoutInfo(itemModel, symbolSize, layout, symbolRepeat, symbolClip, symbolOffset, symbolPosition, valueLineWidth, boundingLength, repeatCutLength, opt, outputSymbolMeta) {
  67084. var categoryDim = opt.categoryDim;
  67085. var valueDim = opt.valueDim;
  67086. var pxSign = outputSymbolMeta.pxSign;
  67087. var unitLength = Math.max(symbolSize[valueDim.index] + valueLineWidth, 0);
  67088. var pathLen = unitLength;
  67089. // Note: rotation will not effect the layout of symbols, because user may
  67090. // want symbols to rotate on its center, which should not be translated
  67091. // when rotating.
  67092. if (symbolRepeat) {
  67093. var absBoundingLength = Math.abs(boundingLength);
  67094. var symbolMargin = retrieve(itemModel.get('symbolMargin'), '15%') + '';
  67095. var hasEndGap = false;
  67096. if (symbolMargin.lastIndexOf('!') === symbolMargin.length - 1) {
  67097. hasEndGap = true;
  67098. symbolMargin = symbolMargin.slice(0, symbolMargin.length - 1);
  67099. }
  67100. var symbolMarginNumeric = parsePercent$1(symbolMargin, symbolSize[valueDim.index]);
  67101. var uLenWithMargin = Math.max(unitLength + symbolMarginNumeric * 2, 0);
  67102. // When symbol margin is less than 0, margin at both ends will be subtracted
  67103. // to ensure that all of the symbols will not be overflow the given area.
  67104. var endFix = hasEndGap ? 0 : symbolMarginNumeric * 2;
  67105. // Both final repeatTimes and final symbolMarginNumeric area calculated based on
  67106. // boundingLength.
  67107. var repeatSpecified = isNumeric(symbolRepeat);
  67108. var repeatTimes = repeatSpecified ? symbolRepeat : toIntTimes((absBoundingLength + endFix) / uLenWithMargin);
  67109. // Adjust calculate margin, to ensure each symbol is displayed
  67110. // entirely in the given layout area.
  67111. var mDiff = absBoundingLength - repeatTimes * unitLength;
  67112. symbolMarginNumeric = mDiff / 2 / (hasEndGap ? repeatTimes : Math.max(repeatTimes - 1, 1));
  67113. uLenWithMargin = unitLength + symbolMarginNumeric * 2;
  67114. endFix = hasEndGap ? 0 : symbolMarginNumeric * 2;
  67115. // Update repeatTimes when not all symbol will be shown.
  67116. if (!repeatSpecified && symbolRepeat !== 'fixed') {
  67117. repeatTimes = repeatCutLength ? toIntTimes((Math.abs(repeatCutLength) + endFix) / uLenWithMargin) : 0;
  67118. }
  67119. pathLen = repeatTimes * uLenWithMargin - endFix;
  67120. outputSymbolMeta.repeatTimes = repeatTimes;
  67121. outputSymbolMeta.symbolMargin = symbolMarginNumeric;
  67122. }
  67123. var sizeFix = pxSign * (pathLen / 2);
  67124. var pathPosition = outputSymbolMeta.pathPosition = [];
  67125. pathPosition[categoryDim.index] = layout[categoryDim.wh] / 2;
  67126. pathPosition[valueDim.index] = symbolPosition === 'start' ? sizeFix : symbolPosition === 'end' ? boundingLength - sizeFix : boundingLength / 2; // 'center'
  67127. if (symbolOffset) {
  67128. pathPosition[0] += symbolOffset[0];
  67129. pathPosition[1] += symbolOffset[1];
  67130. }
  67131. var bundlePosition = outputSymbolMeta.bundlePosition = [];
  67132. bundlePosition[categoryDim.index] = layout[categoryDim.xy];
  67133. bundlePosition[valueDim.index] = layout[valueDim.xy];
  67134. var barRectShape = outputSymbolMeta.barRectShape = extend({}, layout);
  67135. barRectShape[valueDim.wh] = pxSign * Math.max(Math.abs(layout[valueDim.wh]), Math.abs(pathPosition[valueDim.index] + sizeFix));
  67136. barRectShape[categoryDim.wh] = layout[categoryDim.wh];
  67137. var clipShape = outputSymbolMeta.clipShape = {};
  67138. // Consider that symbol may be overflow layout rect.
  67139. clipShape[categoryDim.xy] = -layout[categoryDim.xy];
  67140. clipShape[categoryDim.wh] = opt.ecSize[categoryDim.wh];
  67141. clipShape[valueDim.xy] = 0;
  67142. clipShape[valueDim.wh] = layout[valueDim.wh];
  67143. }
  67144. function createPath(symbolMeta) {
  67145. var symbolPatternSize = symbolMeta.symbolPatternSize;
  67146. var path = createSymbol(
  67147. // Consider texture img, make a big size.
  67148. symbolMeta.symbolType, -symbolPatternSize / 2, -symbolPatternSize / 2, symbolPatternSize, symbolPatternSize);
  67149. path.attr({
  67150. culling: true
  67151. });
  67152. path.type !== 'image' && path.setStyle({
  67153. strokeNoScale: true
  67154. });
  67155. return path;
  67156. }
  67157. function createOrUpdateRepeatSymbols(bar, opt, symbolMeta, isUpdate) {
  67158. var bundle = bar.__pictorialBundle;
  67159. var symbolSize = symbolMeta.symbolSize;
  67160. var valueLineWidth = symbolMeta.valueLineWidth;
  67161. var pathPosition = symbolMeta.pathPosition;
  67162. var valueDim = opt.valueDim;
  67163. var repeatTimes = symbolMeta.repeatTimes || 0;
  67164. var index = 0;
  67165. var unit = symbolSize[opt.valueDim.index] + valueLineWidth + symbolMeta.symbolMargin * 2;
  67166. eachPath(bar, function (path) {
  67167. path.__pictorialAnimationIndex = index;
  67168. path.__pictorialRepeatTimes = repeatTimes;
  67169. if (index < repeatTimes) {
  67170. updateAttr(path, null, makeTarget(index), symbolMeta, isUpdate);
  67171. } else {
  67172. updateAttr(path, null, {
  67173. scaleX: 0,
  67174. scaleY: 0
  67175. }, symbolMeta, isUpdate, function () {
  67176. bundle.remove(path);
  67177. });
  67178. }
  67179. // updateHoverAnimation(path, symbolMeta);
  67180. index++;
  67181. });
  67182. for (; index < repeatTimes; index++) {
  67183. var path = createPath(symbolMeta);
  67184. path.__pictorialAnimationIndex = index;
  67185. path.__pictorialRepeatTimes = repeatTimes;
  67186. bundle.add(path);
  67187. var target = makeTarget(index);
  67188. updateAttr(path, {
  67189. x: target.x,
  67190. y: target.y,
  67191. scaleX: 0,
  67192. scaleY: 0
  67193. }, {
  67194. scaleX: target.scaleX,
  67195. scaleY: target.scaleY,
  67196. rotation: target.rotation
  67197. }, symbolMeta, isUpdate);
  67198. }
  67199. function makeTarget(index) {
  67200. var position = pathPosition.slice();
  67201. // (start && pxSign > 0) || (end && pxSign < 0): i = repeatTimes - index
  67202. // Otherwise: i = index;
  67203. var pxSign = symbolMeta.pxSign;
  67204. var i = index;
  67205. if (symbolMeta.symbolRepeatDirection === 'start' ? pxSign > 0 : pxSign < 0) {
  67206. i = repeatTimes - 1 - index;
  67207. }
  67208. position[valueDim.index] = unit * (i - repeatTimes / 2 + 0.5) + pathPosition[valueDim.index];
  67209. return {
  67210. x: position[0],
  67211. y: position[1],
  67212. scaleX: symbolMeta.symbolScale[0],
  67213. scaleY: symbolMeta.symbolScale[1],
  67214. rotation: symbolMeta.rotation
  67215. };
  67216. }
  67217. }
  67218. function createOrUpdateSingleSymbol(bar, opt, symbolMeta, isUpdate) {
  67219. var bundle = bar.__pictorialBundle;
  67220. var mainPath = bar.__pictorialMainPath;
  67221. if (!mainPath) {
  67222. mainPath = bar.__pictorialMainPath = createPath(symbolMeta);
  67223. bundle.add(mainPath);
  67224. updateAttr(mainPath, {
  67225. x: symbolMeta.pathPosition[0],
  67226. y: symbolMeta.pathPosition[1],
  67227. scaleX: 0,
  67228. scaleY: 0,
  67229. rotation: symbolMeta.rotation
  67230. }, {
  67231. scaleX: symbolMeta.symbolScale[0],
  67232. scaleY: symbolMeta.symbolScale[1]
  67233. }, symbolMeta, isUpdate);
  67234. } else {
  67235. updateAttr(mainPath, null, {
  67236. x: symbolMeta.pathPosition[0],
  67237. y: symbolMeta.pathPosition[1],
  67238. scaleX: symbolMeta.symbolScale[0],
  67239. scaleY: symbolMeta.symbolScale[1],
  67240. rotation: symbolMeta.rotation
  67241. }, symbolMeta, isUpdate);
  67242. }
  67243. }
  67244. // bar rect is used for label.
  67245. function createOrUpdateBarRect(bar, symbolMeta, isUpdate) {
  67246. var rectShape = extend({}, symbolMeta.barRectShape);
  67247. var barRect = bar.__pictorialBarRect;
  67248. if (!barRect) {
  67249. barRect = bar.__pictorialBarRect = new Rect({
  67250. z2: 2,
  67251. shape: rectShape,
  67252. silent: true,
  67253. style: {
  67254. stroke: 'transparent',
  67255. fill: 'transparent',
  67256. lineWidth: 0
  67257. }
  67258. });
  67259. barRect.disableMorphing = true;
  67260. bar.add(barRect);
  67261. } else {
  67262. updateAttr(barRect, null, {
  67263. shape: rectShape
  67264. }, symbolMeta, isUpdate);
  67265. }
  67266. }
  67267. function createOrUpdateClip(bar, opt, symbolMeta, isUpdate) {
  67268. // If not clip, symbol will be remove and rebuilt.
  67269. if (symbolMeta.symbolClip) {
  67270. var clipPath = bar.__pictorialClipPath;
  67271. var clipShape = extend({}, symbolMeta.clipShape);
  67272. var valueDim = opt.valueDim;
  67273. var animationModel = symbolMeta.animationModel;
  67274. var dataIndex = symbolMeta.dataIndex;
  67275. if (clipPath) {
  67276. updateProps(clipPath, {
  67277. shape: clipShape
  67278. }, animationModel, dataIndex);
  67279. } else {
  67280. clipShape[valueDim.wh] = 0;
  67281. clipPath = new Rect({
  67282. shape: clipShape
  67283. });
  67284. bar.__pictorialBundle.setClipPath(clipPath);
  67285. bar.__pictorialClipPath = clipPath;
  67286. var target = {};
  67287. target[valueDim.wh] = symbolMeta.clipShape[valueDim.wh];
  67288. graphic[isUpdate ? 'updateProps' : 'initProps'](clipPath, {
  67289. shape: target
  67290. }, animationModel, dataIndex);
  67291. }
  67292. }
  67293. }
  67294. function getItemModel(data, dataIndex) {
  67295. var itemModel = data.getItemModel(dataIndex);
  67296. itemModel.getAnimationDelayParams = getAnimationDelayParams;
  67297. itemModel.isAnimationEnabled = isAnimationEnabled;
  67298. return itemModel;
  67299. }
  67300. function getAnimationDelayParams(path) {
  67301. // The order is the same as the z-order, see `symbolRepeatDiretion`.
  67302. return {
  67303. index: path.__pictorialAnimationIndex,
  67304. count: path.__pictorialRepeatTimes
  67305. };
  67306. }
  67307. function isAnimationEnabled() {
  67308. // `animation` prop can be set on itemModel in pictorial bar chart.
  67309. return this.parentModel.isAnimationEnabled() && !!this.getShallow('animation');
  67310. }
  67311. function createBar(data, opt, symbolMeta, isUpdate) {
  67312. // bar is the main element for each data.
  67313. var bar = new Group();
  67314. // bundle is used for location and clip.
  67315. var bundle = new Group();
  67316. bar.add(bundle);
  67317. bar.__pictorialBundle = bundle;
  67318. bundle.x = symbolMeta.bundlePosition[0];
  67319. bundle.y = symbolMeta.bundlePosition[1];
  67320. if (symbolMeta.symbolRepeat) {
  67321. createOrUpdateRepeatSymbols(bar, opt, symbolMeta);
  67322. } else {
  67323. createOrUpdateSingleSymbol(bar, opt, symbolMeta);
  67324. }
  67325. createOrUpdateBarRect(bar, symbolMeta, isUpdate);
  67326. createOrUpdateClip(bar, opt, symbolMeta, isUpdate);
  67327. bar.__pictorialShapeStr = getShapeStr(data, symbolMeta);
  67328. bar.__pictorialSymbolMeta = symbolMeta;
  67329. return bar;
  67330. }
  67331. function updateBar(bar, opt, symbolMeta) {
  67332. var animationModel = symbolMeta.animationModel;
  67333. var dataIndex = symbolMeta.dataIndex;
  67334. var bundle = bar.__pictorialBundle;
  67335. updateProps(bundle, {
  67336. x: symbolMeta.bundlePosition[0],
  67337. y: symbolMeta.bundlePosition[1]
  67338. }, animationModel, dataIndex);
  67339. if (symbolMeta.symbolRepeat) {
  67340. createOrUpdateRepeatSymbols(bar, opt, symbolMeta, true);
  67341. } else {
  67342. createOrUpdateSingleSymbol(bar, opt, symbolMeta, true);
  67343. }
  67344. createOrUpdateBarRect(bar, symbolMeta, true);
  67345. createOrUpdateClip(bar, opt, symbolMeta, true);
  67346. }
  67347. function removeBar(data, dataIndex, animationModel, bar) {
  67348. // Not show text when animating
  67349. var labelRect = bar.__pictorialBarRect;
  67350. labelRect && labelRect.removeTextContent();
  67351. var paths = [];
  67352. eachPath(bar, function (path) {
  67353. paths.push(path);
  67354. });
  67355. bar.__pictorialMainPath && paths.push(bar.__pictorialMainPath);
  67356. // I do not find proper remove animation for clip yet.
  67357. bar.__pictorialClipPath && (animationModel = null);
  67358. each(paths, function (path) {
  67359. removeElement(path, {
  67360. scaleX: 0,
  67361. scaleY: 0
  67362. }, animationModel, dataIndex, function () {
  67363. bar.parent && bar.parent.remove(bar);
  67364. });
  67365. });
  67366. data.setItemGraphicEl(dataIndex, null);
  67367. }
  67368. function getShapeStr(data, symbolMeta) {
  67369. return [data.getItemVisual(symbolMeta.dataIndex, 'symbol') || 'none', !!symbolMeta.symbolRepeat, !!symbolMeta.symbolClip].join(':');
  67370. }
  67371. function eachPath(bar, cb, context) {
  67372. // Do not use Group#eachChild, because it do not support remove.
  67373. each(bar.__pictorialBundle.children(), function (el) {
  67374. el !== bar.__pictorialBarRect && cb.call(context, el);
  67375. });
  67376. }
  67377. function updateAttr(el, immediateAttrs, animationAttrs, symbolMeta, isUpdate, cb) {
  67378. immediateAttrs && el.attr(immediateAttrs);
  67379. // when symbolCip used, only clip path has init animation, otherwise it would be weird effect.
  67380. if (symbolMeta.symbolClip && !isUpdate) {
  67381. animationAttrs && el.attr(animationAttrs);
  67382. } else {
  67383. animationAttrs && graphic[isUpdate ? 'updateProps' : 'initProps'](el, animationAttrs, symbolMeta.animationModel, symbolMeta.dataIndex, cb);
  67384. }
  67385. }
  67386. function updateCommon$1(bar, opt, symbolMeta) {
  67387. var dataIndex = symbolMeta.dataIndex;
  67388. var itemModel = symbolMeta.itemModel;
  67389. // Color must be excluded.
  67390. // Because symbol provide setColor individually to set fill and stroke
  67391. var emphasisModel = itemModel.getModel('emphasis');
  67392. var emphasisStyle = emphasisModel.getModel('itemStyle').getItemStyle();
  67393. var blurStyle = itemModel.getModel(['blur', 'itemStyle']).getItemStyle();
  67394. var selectStyle = itemModel.getModel(['select', 'itemStyle']).getItemStyle();
  67395. var cursorStyle = itemModel.getShallow('cursor');
  67396. var focus = emphasisModel.get('focus');
  67397. var blurScope = emphasisModel.get('blurScope');
  67398. var hoverScale = emphasisModel.get('scale');
  67399. eachPath(bar, function (path) {
  67400. if (path instanceof ZRImage) {
  67401. var pathStyle = path.style;
  67402. path.useStyle(extend({
  67403. // TODO other properties like dx, dy ?
  67404. image: pathStyle.image,
  67405. x: pathStyle.x,
  67406. y: pathStyle.y,
  67407. width: pathStyle.width,
  67408. height: pathStyle.height
  67409. }, symbolMeta.style));
  67410. } else {
  67411. path.useStyle(symbolMeta.style);
  67412. }
  67413. var emphasisState = path.ensureState('emphasis');
  67414. emphasisState.style = emphasisStyle;
  67415. if (hoverScale) {
  67416. // NOTE: Must after scale is set after updateAttr
  67417. emphasisState.scaleX = path.scaleX * 1.1;
  67418. emphasisState.scaleY = path.scaleY * 1.1;
  67419. }
  67420. path.ensureState('blur').style = blurStyle;
  67421. path.ensureState('select').style = selectStyle;
  67422. cursorStyle && (path.cursor = cursorStyle);
  67423. path.z2 = symbolMeta.z2;
  67424. });
  67425. var barPositionOutside = opt.valueDim.posDesc[+(symbolMeta.boundingLength > 0)];
  67426. var barRect = bar.__pictorialBarRect;
  67427. barRect.ignoreClip = true;
  67428. setLabelStyle(barRect, getLabelStatesModels(itemModel), {
  67429. labelFetcher: opt.seriesModel,
  67430. labelDataIndex: dataIndex,
  67431. defaultText: getDefaultLabel(opt.seriesModel.getData(), dataIndex),
  67432. inheritColor: symbolMeta.style.fill,
  67433. defaultOpacity: symbolMeta.style.opacity,
  67434. defaultOutsidePosition: barPositionOutside
  67435. });
  67436. toggleHoverEmphasis(bar, focus, blurScope, emphasisModel.get('disabled'));
  67437. }
  67438. function toIntTimes(times) {
  67439. var roundedTimes = Math.round(times);
  67440. // Escapse accurate error
  67441. return Math.abs(times - roundedTimes) < 1e-4 ? roundedTimes : Math.ceil(times);
  67442. }
  67443. var PictorialBarSeriesModel = /** @class */function (_super) {
  67444. __extends(PictorialBarSeriesModel, _super);
  67445. function PictorialBarSeriesModel() {
  67446. var _this = _super !== null && _super.apply(this, arguments) || this;
  67447. _this.type = PictorialBarSeriesModel.type;
  67448. _this.hasSymbolVisual = true;
  67449. _this.defaultSymbol = 'roundRect';
  67450. return _this;
  67451. }
  67452. PictorialBarSeriesModel.prototype.getInitialData = function (option) {
  67453. // Disable stack.
  67454. option.stack = null;
  67455. return _super.prototype.getInitialData.apply(this, arguments);
  67456. };
  67457. PictorialBarSeriesModel.type = 'series.pictorialBar';
  67458. PictorialBarSeriesModel.dependencies = ['grid'];
  67459. PictorialBarSeriesModel.defaultOption = inheritDefaultOption(BaseBarSeriesModel.defaultOption, {
  67460. symbol: 'circle',
  67461. symbolSize: null,
  67462. symbolRotate: null,
  67463. symbolPosition: null,
  67464. symbolOffset: null,
  67465. symbolMargin: null,
  67466. symbolRepeat: false,
  67467. symbolRepeatDirection: 'end',
  67468. symbolClip: false,
  67469. symbolBoundingData: null,
  67470. symbolPatternSize: 400,
  67471. barGap: '-100%',
  67472. // Pictorial bar do not clip by default because in many cases
  67473. // xAxis and yAxis are not displayed and it's expected not to clip
  67474. clip: false,
  67475. // z can be set in data item, which is z2 actually.
  67476. // Disable progressive
  67477. progressive: 0,
  67478. emphasis: {
  67479. // By default pictorialBar do not hover scale. Hover scale is not suitable
  67480. // for the case that both has foreground and background.
  67481. scale: false
  67482. },
  67483. select: {
  67484. itemStyle: {
  67485. borderColor: tokens.color.primary
  67486. }
  67487. }
  67488. });
  67489. return PictorialBarSeriesModel;
  67490. }(BaseBarSeriesModel);
  67491. function install$p(registers) {
  67492. registers.registerChartView(PictorialBarView);
  67493. registers.registerSeriesModel(PictorialBarSeriesModel);
  67494. registers.registerLayout(registers.PRIORITY.VISUAL.LAYOUT, curry(layout, 'pictorialBar'));
  67495. // Do layout after other overall layout, which can prepare some information.
  67496. registers.registerLayout(registers.PRIORITY.VISUAL.PROGRESSIVE_LAYOUT, createProgressiveLayout('pictorialBar'));
  67497. }
  67498. var ThemeRiverView = /** @class */function (_super) {
  67499. __extends(ThemeRiverView, _super);
  67500. function ThemeRiverView() {
  67501. var _this = _super !== null && _super.apply(this, arguments) || this;
  67502. _this.type = ThemeRiverView.type;
  67503. _this._layers = [];
  67504. return _this;
  67505. }
  67506. ThemeRiverView.prototype.render = function (seriesModel, ecModel, api) {
  67507. var data = seriesModel.getData();
  67508. var self = this;
  67509. var group = this.group;
  67510. var layersSeries = seriesModel.getLayerSeries();
  67511. var layoutInfo = data.getLayout('layoutInfo');
  67512. var rect = layoutInfo.rect;
  67513. var boundaryGap = layoutInfo.boundaryGap;
  67514. group.x = 0;
  67515. group.y = rect.y + boundaryGap[0];
  67516. function keyGetter(item) {
  67517. return item.name;
  67518. }
  67519. var dataDiffer = new DataDiffer(this._layersSeries || [], layersSeries, keyGetter, keyGetter);
  67520. var newLayersGroups = [];
  67521. dataDiffer.add(bind(process, this, 'add')).update(bind(process, this, 'update')).remove(bind(process, this, 'remove')).execute();
  67522. function process(status, idx, oldIdx) {
  67523. var oldLayersGroups = self._layers;
  67524. if (status === 'remove') {
  67525. group.remove(oldLayersGroups[idx]);
  67526. return;
  67527. }
  67528. var points0 = [];
  67529. var points1 = [];
  67530. var style;
  67531. var indices = layersSeries[idx].indices;
  67532. var j = 0;
  67533. for (; j < indices.length; j++) {
  67534. var layout = data.getItemLayout(indices[j]);
  67535. var x = layout.x;
  67536. var y0 = layout.y0;
  67537. var y = layout.y;
  67538. points0.push(x, y0);
  67539. points1.push(x, y0 + y);
  67540. style = data.getItemVisual(indices[j], 'style');
  67541. }
  67542. var polygon;
  67543. var textLayout = data.getItemLayout(indices[0]);
  67544. var labelModel = seriesModel.getModel('label');
  67545. var margin = labelModel.get('margin');
  67546. var emphasisModel = seriesModel.getModel('emphasis');
  67547. if (status === 'add') {
  67548. var layerGroup = newLayersGroups[idx] = new Group();
  67549. polygon = new ECPolygon({
  67550. shape: {
  67551. points: points0,
  67552. stackedOnPoints: points1,
  67553. smooth: 0.4,
  67554. stackedOnSmooth: 0.4,
  67555. smoothConstraint: false
  67556. },
  67557. z2: 0
  67558. });
  67559. layerGroup.add(polygon);
  67560. group.add(layerGroup);
  67561. if (seriesModel.isAnimationEnabled()) {
  67562. polygon.setClipPath(createGridClipShape$2(polygon.getBoundingRect(), seriesModel, function () {
  67563. polygon.removeClipPath();
  67564. }));
  67565. }
  67566. } else {
  67567. var layerGroup = oldLayersGroups[oldIdx];
  67568. polygon = layerGroup.childAt(0);
  67569. group.add(layerGroup);
  67570. newLayersGroups[idx] = layerGroup;
  67571. updateProps(polygon, {
  67572. shape: {
  67573. points: points0,
  67574. stackedOnPoints: points1
  67575. }
  67576. }, seriesModel);
  67577. saveOldStyle(polygon);
  67578. }
  67579. setLabelStyle(polygon, getLabelStatesModels(seriesModel), {
  67580. labelDataIndex: indices[j - 1],
  67581. defaultText: data.getName(indices[j - 1]),
  67582. inheritColor: style.fill
  67583. }, {
  67584. normal: {
  67585. verticalAlign: 'middle'
  67586. // align: 'right'
  67587. }
  67588. });
  67589. polygon.setTextConfig({
  67590. position: null,
  67591. local: true
  67592. });
  67593. var labelEl = polygon.getTextContent();
  67594. // TODO More label position options.
  67595. if (labelEl) {
  67596. labelEl.x = textLayout.x - margin;
  67597. labelEl.y = textLayout.y0 + textLayout.y / 2;
  67598. }
  67599. polygon.useStyle(style);
  67600. data.setItemGraphicEl(idx, polygon);
  67601. setStatesStylesFromModel(polygon, seriesModel);
  67602. toggleHoverEmphasis(polygon, emphasisModel.get('focus'), emphasisModel.get('blurScope'), emphasisModel.get('disabled'));
  67603. }
  67604. this._layersSeries = layersSeries;
  67605. this._layers = newLayersGroups;
  67606. };
  67607. ThemeRiverView.type = 'themeRiver';
  67608. return ThemeRiverView;
  67609. }(ChartView);
  67610. // add animation to the view
  67611. function createGridClipShape$2(rect, seriesModel, cb) {
  67612. var rectEl = new Rect({
  67613. shape: {
  67614. x: rect.x - 10,
  67615. y: rect.y - 10,
  67616. width: 0,
  67617. height: rect.height + 20
  67618. }
  67619. });
  67620. initProps(rectEl, {
  67621. shape: {
  67622. x: rect.x - 50,
  67623. width: rect.width + 100,
  67624. height: rect.height + 20
  67625. }
  67626. }, seriesModel, cb);
  67627. return rectEl;
  67628. }
  67629. var DATA_NAME_INDEX = 2;
  67630. var ThemeRiverSeriesModel = /** @class */function (_super) {
  67631. __extends(ThemeRiverSeriesModel, _super);
  67632. function ThemeRiverSeriesModel() {
  67633. var _this = _super !== null && _super.apply(this, arguments) || this;
  67634. _this.type = ThemeRiverSeriesModel.type;
  67635. return _this;
  67636. }
  67637. /**
  67638. * @override
  67639. */
  67640. ThemeRiverSeriesModel.prototype.init = function (option) {
  67641. // eslint-disable-next-line
  67642. _super.prototype.init.apply(this, arguments);
  67643. // Put this function here is for the sake of consistency of code style.
  67644. // Enable legend selection for each data item
  67645. // Use a function instead of direct access because data reference may changed
  67646. this.legendVisualProvider = new LegendVisualProvider(bind(this.getData, this), bind(this.getRawData, this));
  67647. };
  67648. /**
  67649. * If there is no value of a certain point in the time for some event,set it value to 0.
  67650. *
  67651. * @param {Array} data initial data in the option
  67652. * @return {Array}
  67653. */
  67654. ThemeRiverSeriesModel.prototype.fixData = function (data) {
  67655. var rawDataLength = data.length;
  67656. /**
  67657. * Make sure every layer data get the same keys.
  67658. * The value index tells which layer has visited.
  67659. * {
  67660. * 2014/01/01: -1
  67661. * }
  67662. */
  67663. var timeValueKeys = {};
  67664. // grouped data by name
  67665. var groupResult = groupData(data, function (item) {
  67666. if (!timeValueKeys.hasOwnProperty(item[0] + '')) {
  67667. timeValueKeys[item[0] + ''] = -1;
  67668. }
  67669. return item[2];
  67670. });
  67671. var layerData = [];
  67672. groupResult.buckets.each(function (items, key) {
  67673. layerData.push({
  67674. name: key,
  67675. dataList: items
  67676. });
  67677. });
  67678. var layerNum = layerData.length;
  67679. for (var k = 0; k < layerNum; ++k) {
  67680. var name_1 = layerData[k].name;
  67681. for (var j = 0; j < layerData[k].dataList.length; ++j) {
  67682. var timeValue = layerData[k].dataList[j][0] + '';
  67683. timeValueKeys[timeValue] = k;
  67684. }
  67685. for (var timeValue in timeValueKeys) {
  67686. if (timeValueKeys.hasOwnProperty(timeValue) && timeValueKeys[timeValue] !== k) {
  67687. timeValueKeys[timeValue] = k;
  67688. data[rawDataLength] = [timeValue, 0, name_1];
  67689. rawDataLength++;
  67690. }
  67691. }
  67692. }
  67693. return data;
  67694. };
  67695. /**
  67696. * @override
  67697. * @param option the initial option that user gave
  67698. * @param ecModel the model object for themeRiver option
  67699. */
  67700. ThemeRiverSeriesModel.prototype.getInitialData = function (option, ecModel) {
  67701. var singleAxisModel = this.getReferringComponents('singleAxis', SINGLE_REFERRING).models[0];
  67702. var axisType = singleAxisModel.get('type');
  67703. // filter the data item with the value of label is undefined
  67704. var filterData = filter(option.data, function (dataItem) {
  67705. return dataItem[2] !== undefined;
  67706. });
  67707. // ??? TODO design a stage to transfer data for themeRiver and lines?
  67708. var data = this.fixData(filterData || []);
  67709. var nameList = [];
  67710. var nameMap = this.nameMap = createHashMap();
  67711. var count = 0;
  67712. for (var i = 0; i < data.length; ++i) {
  67713. nameList.push(data[i][DATA_NAME_INDEX]);
  67714. if (!nameMap.get(data[i][DATA_NAME_INDEX])) {
  67715. nameMap.set(data[i][DATA_NAME_INDEX], count);
  67716. count++;
  67717. }
  67718. }
  67719. var dimensions = prepareSeriesDataSchema(data, {
  67720. coordDimensions: ['single'],
  67721. dimensionsDefine: [{
  67722. name: 'time',
  67723. type: getDimensionTypeByAxis(axisType)
  67724. }, {
  67725. name: 'value',
  67726. type: 'float'
  67727. }, {
  67728. name: 'name',
  67729. type: 'ordinal'
  67730. }],
  67731. encodeDefine: {
  67732. single: 0,
  67733. value: 1,
  67734. itemName: 2
  67735. }
  67736. }).dimensions;
  67737. var list = new SeriesData(dimensions, this);
  67738. list.initData(data);
  67739. return list;
  67740. };
  67741. /**
  67742. * The raw data is divided into multiple layers and each layer
  67743. * has same name.
  67744. */
  67745. ThemeRiverSeriesModel.prototype.getLayerSeries = function () {
  67746. var data = this.getData();
  67747. var lenCount = data.count();
  67748. var indexArr = [];
  67749. for (var i = 0; i < lenCount; ++i) {
  67750. indexArr[i] = i;
  67751. }
  67752. var timeDim = data.mapDimension('single');
  67753. // data group by name
  67754. var groupResult = groupData(indexArr, function (index) {
  67755. return data.get('name', index);
  67756. });
  67757. var layerSeries = [];
  67758. groupResult.buckets.each(function (items, key) {
  67759. items.sort(function (index1, index2) {
  67760. return data.get(timeDim, index1) - data.get(timeDim, index2);
  67761. });
  67762. layerSeries.push({
  67763. name: key,
  67764. indices: items
  67765. });
  67766. });
  67767. return layerSeries;
  67768. };
  67769. /**
  67770. * Get data indices for show tooltip content
  67771. */
  67772. ThemeRiverSeriesModel.prototype.getAxisTooltipData = function (dim, value, baseAxis) {
  67773. if (!isArray(dim)) {
  67774. dim = dim ? [dim] : [];
  67775. }
  67776. var data = this.getData();
  67777. var layerSeries = this.getLayerSeries();
  67778. var indices = [];
  67779. var layerNum = layerSeries.length;
  67780. var nestestValue;
  67781. for (var i = 0; i < layerNum; ++i) {
  67782. var minDist = Number.MAX_VALUE;
  67783. var nearestIdx = -1;
  67784. var pointNum = layerSeries[i].indices.length;
  67785. for (var j = 0; j < pointNum; ++j) {
  67786. var theValue = data.get(dim[0], layerSeries[i].indices[j]);
  67787. var dist = Math.abs(theValue - value);
  67788. if (dist <= minDist) {
  67789. nestestValue = theValue;
  67790. minDist = dist;
  67791. nearestIdx = layerSeries[i].indices[j];
  67792. }
  67793. }
  67794. indices.push(nearestIdx);
  67795. }
  67796. return {
  67797. dataIndices: indices,
  67798. nestestValue: nestestValue
  67799. };
  67800. };
  67801. ThemeRiverSeriesModel.prototype.formatTooltip = function (dataIndex, multipleSeries, dataType) {
  67802. var data = this.getData();
  67803. var name = data.getName(dataIndex);
  67804. var value = data.get(data.mapDimension('value'), dataIndex);
  67805. return createTooltipMarkup('nameValue', {
  67806. name: name,
  67807. value: value
  67808. });
  67809. };
  67810. ThemeRiverSeriesModel.type = 'series.themeRiver';
  67811. ThemeRiverSeriesModel.dependencies = ['singleAxis'];
  67812. ThemeRiverSeriesModel.defaultOption = {
  67813. // zlevel: 0,
  67814. z: 2,
  67815. colorBy: 'data',
  67816. coordinateSystem: 'singleAxis',
  67817. // gap in axis's orthogonal orientation
  67818. boundaryGap: ['10%', '10%'],
  67819. // legendHoverLink: true,
  67820. singleAxisIndex: 0,
  67821. animationEasing: 'linear',
  67822. label: {
  67823. margin: 4,
  67824. show: true,
  67825. position: 'left',
  67826. fontSize: 11
  67827. },
  67828. emphasis: {
  67829. label: {
  67830. show: true
  67831. }
  67832. }
  67833. };
  67834. return ThemeRiverSeriesModel;
  67835. }(SeriesModel);
  67836. function themeRiverLayout(ecModel, api) {
  67837. ecModel.eachSeriesByType('themeRiver', function (seriesModel) {
  67838. var data = seriesModel.getData();
  67839. var single = seriesModel.coordinateSystem;
  67840. var layoutInfo = {};
  67841. // use the axis boundingRect for view
  67842. var rect = single.getRect();
  67843. layoutInfo.rect = rect;
  67844. var boundaryGap = seriesModel.get('boundaryGap');
  67845. var axis = single.getAxis();
  67846. layoutInfo.boundaryGap = boundaryGap;
  67847. if (axis.orient === 'horizontal') {
  67848. boundaryGap[0] = parsePercent$1(boundaryGap[0], rect.height);
  67849. boundaryGap[1] = parsePercent$1(boundaryGap[1], rect.height);
  67850. var height = rect.height - boundaryGap[0] - boundaryGap[1];
  67851. doThemeRiverLayout(data, seriesModel, height);
  67852. } else {
  67853. boundaryGap[0] = parsePercent$1(boundaryGap[0], rect.width);
  67854. boundaryGap[1] = parsePercent$1(boundaryGap[1], rect.width);
  67855. var width = rect.width - boundaryGap[0] - boundaryGap[1];
  67856. doThemeRiverLayout(data, seriesModel, width);
  67857. }
  67858. data.setLayout('layoutInfo', layoutInfo);
  67859. });
  67860. }
  67861. /**
  67862. * The layout information about themeriver
  67863. *
  67864. * @param data data in the series
  67865. * @param seriesModel the model object of themeRiver series
  67866. * @param height value used to compute every series height
  67867. */
  67868. function doThemeRiverLayout(data, seriesModel, height) {
  67869. if (!data.count()) {
  67870. return;
  67871. }
  67872. var coordSys = seriesModel.coordinateSystem;
  67873. // the data in each layer are organized into a series.
  67874. var layerSeries = seriesModel.getLayerSeries();
  67875. // the points in each layer.
  67876. var timeDim = data.mapDimension('single');
  67877. var valueDim = data.mapDimension('value');
  67878. var layerPoints = map(layerSeries, function (singleLayer) {
  67879. return map(singleLayer.indices, function (idx) {
  67880. var pt = coordSys.dataToPoint(data.get(timeDim, idx));
  67881. pt[1] = data.get(valueDim, idx);
  67882. return pt;
  67883. });
  67884. });
  67885. var base = computeBaseline(layerPoints);
  67886. var baseLine = base.y0;
  67887. var ky = height / base.max;
  67888. // set layout information for each item.
  67889. var n = layerSeries.length;
  67890. var m = layerSeries[0].indices.length;
  67891. var baseY0;
  67892. for (var j = 0; j < m; ++j) {
  67893. baseY0 = baseLine[j] * ky;
  67894. data.setItemLayout(layerSeries[0].indices[j], {
  67895. layerIndex: 0,
  67896. x: layerPoints[0][j][0],
  67897. y0: baseY0,
  67898. y: layerPoints[0][j][1] * ky
  67899. });
  67900. for (var i = 1; i < n; ++i) {
  67901. baseY0 += layerPoints[i - 1][j][1] * ky;
  67902. data.setItemLayout(layerSeries[i].indices[j], {
  67903. layerIndex: i,
  67904. x: layerPoints[i][j][0],
  67905. y0: baseY0,
  67906. y: layerPoints[i][j][1] * ky
  67907. });
  67908. }
  67909. }
  67910. }
  67911. /**
  67912. * Compute the baseLine of the rawdata
  67913. * Inspired by Lee Byron's paper Stacked Graphs - Geometry & Aesthetics
  67914. *
  67915. * @param data the points in each layer
  67916. */
  67917. function computeBaseline(data) {
  67918. var layerNum = data.length;
  67919. var pointNum = data[0].length;
  67920. var sums = [];
  67921. var y0 = [];
  67922. var max = 0;
  67923. for (var i = 0; i < pointNum; ++i) {
  67924. var temp = 0;
  67925. for (var j = 0; j < layerNum; ++j) {
  67926. temp += data[j][i][1];
  67927. }
  67928. if (temp > max) {
  67929. max = temp;
  67930. }
  67931. sums.push(temp);
  67932. }
  67933. for (var k = 0; k < pointNum; ++k) {
  67934. y0[k] = (max - sums[k]) / 2;
  67935. }
  67936. max = 0;
  67937. for (var l = 0; l < pointNum; ++l) {
  67938. var sum = sums[l] + y0[l];
  67939. if (sum > max) {
  67940. max = sum;
  67941. }
  67942. }
  67943. return {
  67944. y0: y0,
  67945. max: max
  67946. };
  67947. }
  67948. function install$q(registers) {
  67949. registers.registerChartView(ThemeRiverView);
  67950. registers.registerSeriesModel(ThemeRiverSeriesModel);
  67951. registers.registerLayout(themeRiverLayout);
  67952. registers.registerProcessor(dataFilter('themeRiver'));
  67953. }
  67954. var DEFAULT_SECTOR_Z = 2;
  67955. var DEFAULT_TEXT_Z = 4;
  67956. /**
  67957. * Sunburstce of Sunburst including Sector, Label, LabelLine
  67958. */
  67959. var SunburstPiece = /** @class */function (_super) {
  67960. __extends(SunburstPiece, _super);
  67961. function SunburstPiece(node, seriesModel, ecModel, api) {
  67962. var _this = _super.call(this) || this;
  67963. _this.z2 = DEFAULT_SECTOR_Z;
  67964. _this.textConfig = {
  67965. inside: true
  67966. };
  67967. getECData(_this).seriesIndex = seriesModel.seriesIndex;
  67968. var text = new ZRText({
  67969. z2: DEFAULT_TEXT_Z,
  67970. silent: node.getModel().get(['label', 'silent'])
  67971. });
  67972. _this.setTextContent(text);
  67973. _this.updateData(true, node, seriesModel, ecModel, api);
  67974. return _this;
  67975. }
  67976. SunburstPiece.prototype.updateData = function (firstCreate, node,
  67977. // state: 'emphasis' | 'normal' | 'highlight' | 'downplay',
  67978. seriesModel, ecModel, api) {
  67979. this.node = node;
  67980. node.piece = this;
  67981. seriesModel = seriesModel || this._seriesModel;
  67982. ecModel = ecModel || this._ecModel;
  67983. var sector = this;
  67984. getECData(sector).dataIndex = node.dataIndex;
  67985. var itemModel = node.getModel();
  67986. var emphasisModel = itemModel.getModel('emphasis');
  67987. var layout = node.getLayout();
  67988. var sectorShape = extend({}, layout);
  67989. sectorShape.label = null;
  67990. var normalStyle = node.getVisual('style');
  67991. normalStyle.lineJoin = 'bevel';
  67992. var decal = node.getVisual('decal');
  67993. if (decal) {
  67994. normalStyle.decal = createOrUpdatePatternFromDecal(decal, api);
  67995. }
  67996. var cornerRadius = getSectorCornerRadius(itemModel.getModel('itemStyle'), sectorShape, true);
  67997. extend(sectorShape, cornerRadius);
  67998. each(SPECIAL_STATES, function (stateName) {
  67999. var state = sector.ensureState(stateName);
  68000. var itemStyleModel = itemModel.getModel([stateName, 'itemStyle']);
  68001. state.style = itemStyleModel.getItemStyle();
  68002. // border radius
  68003. var cornerRadius = getSectorCornerRadius(itemStyleModel, sectorShape);
  68004. if (cornerRadius) {
  68005. state.shape = cornerRadius;
  68006. }
  68007. });
  68008. if (firstCreate) {
  68009. sector.setShape(sectorShape);
  68010. sector.shape.r = layout.r0;
  68011. initProps(sector, {
  68012. shape: {
  68013. r: layout.r
  68014. }
  68015. }, seriesModel, node.dataIndex);
  68016. } else {
  68017. // Disable animation for gradient since no interpolation method
  68018. // is supported for gradient
  68019. updateProps(sector, {
  68020. shape: sectorShape
  68021. }, seriesModel);
  68022. saveOldStyle(sector);
  68023. }
  68024. sector.useStyle(normalStyle);
  68025. this._updateLabel(seriesModel);
  68026. var cursorStyle = itemModel.getShallow('cursor');
  68027. cursorStyle && sector.attr('cursor', cursorStyle);
  68028. this._seriesModel = seriesModel || this._seriesModel;
  68029. this._ecModel = ecModel || this._ecModel;
  68030. var focus = emphasisModel.get('focus');
  68031. var focusOrIndices = focus === 'relative' ? concatArray(node.getAncestorsIndices(), node.getDescendantIndices()) : focus === 'ancestor' ? node.getAncestorsIndices() : focus === 'descendant' ? node.getDescendantIndices() : focus;
  68032. toggleHoverEmphasis(this, focusOrIndices, emphasisModel.get('blurScope'), emphasisModel.get('disabled'));
  68033. };
  68034. SunburstPiece.prototype._updateLabel = function (seriesModel) {
  68035. var _this = this;
  68036. var itemModel = this.node.getModel();
  68037. var normalLabelModel = itemModel.getModel('label');
  68038. var layout = this.node.getLayout();
  68039. var angle = layout.endAngle - layout.startAngle;
  68040. var midAngle = (layout.startAngle + layout.endAngle) / 2;
  68041. var dx = Math.cos(midAngle);
  68042. var dy = Math.sin(midAngle);
  68043. var sector = this;
  68044. var label = sector.getTextContent();
  68045. var dataIndex = this.node.dataIndex;
  68046. var labelMinAngle = normalLabelModel.get('minAngle') / 180 * Math.PI;
  68047. var isNormalShown = normalLabelModel.get('show') && !(labelMinAngle != null && Math.abs(angle) < labelMinAngle);
  68048. label.ignore = !isNormalShown;
  68049. // TODO use setLabelStyle
  68050. each(DISPLAY_STATES, function (stateName) {
  68051. var labelStateModel = stateName === 'normal' ? itemModel.getModel('label') : itemModel.getModel([stateName, 'label']);
  68052. var isNormal = stateName === 'normal';
  68053. var state = isNormal ? label : label.ensureState(stateName);
  68054. var text = seriesModel.getFormattedLabel(dataIndex, stateName);
  68055. if (isNormal) {
  68056. text = text || _this.node.name;
  68057. }
  68058. state.style = createTextStyle(labelStateModel, {}, null, stateName !== 'normal', true);
  68059. if (text) {
  68060. state.style.text = text;
  68061. }
  68062. // Not displaying text when angle is too small
  68063. var isShown = labelStateModel.get('show');
  68064. if (isShown != null && !isNormal) {
  68065. state.ignore = !isShown;
  68066. }
  68067. var labelPosition = getLabelAttr(labelStateModel, 'position');
  68068. var sectorState = isNormal ? sector : sector.states[stateName];
  68069. var labelColor = sectorState.style.fill;
  68070. sectorState.textConfig = {
  68071. outsideFill: labelStateModel.get('color') === 'inherit' ? labelColor : null,
  68072. inside: labelPosition !== 'outside'
  68073. };
  68074. var r;
  68075. var labelPadding = getLabelAttr(labelStateModel, 'distance') || 0;
  68076. var textAlign = getLabelAttr(labelStateModel, 'align');
  68077. var rotateType = getLabelAttr(labelStateModel, 'rotate');
  68078. var flipStartAngle = Math.PI * 0.5;
  68079. var flipEndAngle = Math.PI * 1.5;
  68080. var midAngleNormal = normalizeRadian(rotateType === 'tangential' ? Math.PI / 2 - midAngle : midAngle);
  68081. // For text that is up-side down, rotate 180 degrees to make sure
  68082. // it's readable
  68083. var needsFlip = midAngleNormal > flipStartAngle && !isRadianAroundZero(midAngleNormal - flipStartAngle) && midAngleNormal < flipEndAngle;
  68084. if (labelPosition === 'outside') {
  68085. r = layout.r + labelPadding;
  68086. textAlign = needsFlip ? 'right' : 'left';
  68087. } else {
  68088. if (!textAlign || textAlign === 'center') {
  68089. // Put label in the center if it's a circle
  68090. if (angle === 2 * Math.PI && layout.r0 === 0) {
  68091. r = 0;
  68092. } else {
  68093. r = (layout.r + layout.r0) / 2;
  68094. }
  68095. textAlign = 'center';
  68096. } else if (textAlign === 'left') {
  68097. r = layout.r0 + labelPadding;
  68098. textAlign = needsFlip ? 'right' : 'left';
  68099. } else if (textAlign === 'right') {
  68100. r = layout.r - labelPadding;
  68101. textAlign = needsFlip ? 'left' : 'right';
  68102. }
  68103. }
  68104. state.style.align = textAlign;
  68105. state.style.verticalAlign = getLabelAttr(labelStateModel, 'verticalAlign') || 'middle';
  68106. state.x = r * dx + layout.cx;
  68107. state.y = r * dy + layout.cy;
  68108. var rotate = 0;
  68109. if (rotateType === 'radial') {
  68110. rotate = normalizeRadian(-midAngle) + (needsFlip ? Math.PI : 0);
  68111. } else if (rotateType === 'tangential') {
  68112. rotate = normalizeRadian(Math.PI / 2 - midAngle) + (needsFlip ? Math.PI : 0);
  68113. } else if (isNumber(rotateType)) {
  68114. rotate = rotateType * Math.PI / 180;
  68115. }
  68116. state.rotation = normalizeRadian(rotate);
  68117. });
  68118. function getLabelAttr(model, name) {
  68119. var stateAttr = model.get(name);
  68120. if (stateAttr == null) {
  68121. return normalLabelModel.get(name);
  68122. }
  68123. return stateAttr;
  68124. }
  68125. label.dirtyStyle();
  68126. };
  68127. return SunburstPiece;
  68128. }(Sector);
  68129. var ROOT_TO_NODE_ACTION = 'sunburstRootToNode';
  68130. var HIGHLIGHT_ACTION = 'sunburstHighlight';
  68131. var UNHIGHLIGHT_ACTION = 'sunburstUnhighlight';
  68132. function installSunburstAction(registers) {
  68133. registers.registerAction({
  68134. type: ROOT_TO_NODE_ACTION,
  68135. update: 'updateView'
  68136. }, function (payload, ecModel) {
  68137. ecModel.eachComponent({
  68138. mainType: 'series',
  68139. subType: 'sunburst',
  68140. query: payload
  68141. }, handleRootToNode);
  68142. function handleRootToNode(model, index) {
  68143. var targetInfo = retrieveTargetInfo(payload, [ROOT_TO_NODE_ACTION], model);
  68144. if (targetInfo) {
  68145. var originViewRoot = model.getViewRoot();
  68146. if (originViewRoot) {
  68147. payload.direction = aboveViewRoot(originViewRoot, targetInfo.node) ? 'rollUp' : 'drillDown';
  68148. }
  68149. model.resetViewRoot(targetInfo.node);
  68150. }
  68151. }
  68152. });
  68153. registers.registerAction({
  68154. type: HIGHLIGHT_ACTION,
  68155. update: 'none'
  68156. }, function (payload, ecModel, api) {
  68157. // Clone
  68158. payload = extend({}, payload);
  68159. ecModel.eachComponent({
  68160. mainType: 'series',
  68161. subType: 'sunburst',
  68162. query: payload
  68163. }, handleHighlight);
  68164. function handleHighlight(model) {
  68165. var targetInfo = retrieveTargetInfo(payload, [HIGHLIGHT_ACTION], model);
  68166. if (targetInfo) {
  68167. payload.dataIndex = targetInfo.node.dataIndex;
  68168. }
  68169. }
  68170. if ("development" !== 'production') {
  68171. deprecateReplaceLog('sunburstHighlight', 'highlight');
  68172. }
  68173. // Fast forward action
  68174. api.dispatchAction(extend(payload, {
  68175. type: 'highlight'
  68176. }));
  68177. });
  68178. registers.registerAction({
  68179. type: UNHIGHLIGHT_ACTION,
  68180. update: 'updateView'
  68181. }, function (payload, ecModel, api) {
  68182. payload = extend({}, payload);
  68183. if ("development" !== 'production') {
  68184. deprecateReplaceLog('sunburstUnhighlight', 'downplay');
  68185. }
  68186. api.dispatchAction(extend(payload, {
  68187. type: 'downplay'
  68188. }));
  68189. });
  68190. }
  68191. var SunburstView = /** @class */function (_super) {
  68192. __extends(SunburstView, _super);
  68193. function SunburstView() {
  68194. var _this = _super !== null && _super.apply(this, arguments) || this;
  68195. _this.type = SunburstView.type;
  68196. return _this;
  68197. }
  68198. SunburstView.prototype.render = function (seriesModel, ecModel, api,
  68199. // @ts-ignore
  68200. payload) {
  68201. var self = this;
  68202. this.seriesModel = seriesModel;
  68203. this.api = api;
  68204. this.ecModel = ecModel;
  68205. var data = seriesModel.getData();
  68206. var virtualRoot = data.tree.root;
  68207. var newRoot = seriesModel.getViewRoot();
  68208. var group = this.group;
  68209. var renderLabelForZeroData = seriesModel.get('renderLabelForZeroData');
  68210. var newChildren = [];
  68211. newRoot.eachNode(function (node) {
  68212. newChildren.push(node);
  68213. });
  68214. var oldChildren = this._oldChildren || [];
  68215. dualTravel(newChildren, oldChildren);
  68216. renderRollUp(virtualRoot, newRoot);
  68217. this._initEvents();
  68218. this._oldChildren = newChildren;
  68219. function dualTravel(newChildren, oldChildren) {
  68220. if (newChildren.length === 0 && oldChildren.length === 0) {
  68221. return;
  68222. }
  68223. new DataDiffer(oldChildren, newChildren, getKey, getKey).add(processNode).update(processNode).remove(curry(processNode, null)).execute();
  68224. function getKey(node) {
  68225. return node.getId();
  68226. }
  68227. function processNode(newIdx, oldIdx) {
  68228. var newNode = newIdx == null ? null : newChildren[newIdx];
  68229. var oldNode = oldIdx == null ? null : oldChildren[oldIdx];
  68230. doRenderNode(newNode, oldNode);
  68231. }
  68232. }
  68233. function doRenderNode(newNode, oldNode) {
  68234. if (!renderLabelForZeroData && newNode && !newNode.getValue()) {
  68235. // Not render data with value 0
  68236. newNode = null;
  68237. }
  68238. if (newNode !== virtualRoot && oldNode !== virtualRoot) {
  68239. if (oldNode && oldNode.piece) {
  68240. if (newNode) {
  68241. // Update
  68242. oldNode.piece.updateData(false, newNode, seriesModel, ecModel, api);
  68243. // For tooltip
  68244. data.setItemGraphicEl(newNode.dataIndex, oldNode.piece);
  68245. } else {
  68246. // Remove
  68247. removeNode(oldNode);
  68248. }
  68249. } else if (newNode) {
  68250. // Add
  68251. var piece = new SunburstPiece(newNode, seriesModel, ecModel, api);
  68252. group.add(piece);
  68253. // For tooltip
  68254. data.setItemGraphicEl(newNode.dataIndex, piece);
  68255. }
  68256. }
  68257. }
  68258. function removeNode(node) {
  68259. if (!node) {
  68260. return;
  68261. }
  68262. if (node.piece) {
  68263. group.remove(node.piece);
  68264. node.piece = null;
  68265. }
  68266. }
  68267. function renderRollUp(virtualRoot, viewRoot) {
  68268. if (viewRoot.depth > 0) {
  68269. // Render
  68270. if (self.virtualPiece) {
  68271. // Update
  68272. self.virtualPiece.updateData(false, virtualRoot, seriesModel, ecModel, api);
  68273. } else {
  68274. // Add
  68275. self.virtualPiece = new SunburstPiece(virtualRoot, seriesModel, ecModel, api);
  68276. group.add(self.virtualPiece);
  68277. }
  68278. // TODO event scope
  68279. viewRoot.piece.off('click');
  68280. self.virtualPiece.on('click', function (e) {
  68281. self._rootToNode(viewRoot.parentNode);
  68282. });
  68283. } else if (self.virtualPiece) {
  68284. // Remove
  68285. group.remove(self.virtualPiece);
  68286. self.virtualPiece = null;
  68287. }
  68288. }
  68289. };
  68290. /**
  68291. * @private
  68292. */
  68293. SunburstView.prototype._initEvents = function () {
  68294. var _this = this;
  68295. this.group.off('click');
  68296. this.group.on('click', function (e) {
  68297. var targetFound = false;
  68298. var viewRoot = _this.seriesModel.getViewRoot();
  68299. viewRoot.eachNode(function (node) {
  68300. if (!targetFound && node.piece && node.piece === e.target) {
  68301. var nodeClick = node.getModel().get('nodeClick');
  68302. if (nodeClick === 'rootToNode') {
  68303. _this._rootToNode(node);
  68304. } else if (nodeClick === 'link') {
  68305. var itemModel = node.getModel();
  68306. var link = itemModel.get('link');
  68307. if (link) {
  68308. var linkTarget = itemModel.get('target', true) || '_blank';
  68309. windowOpen(link, linkTarget);
  68310. }
  68311. }
  68312. targetFound = true;
  68313. }
  68314. });
  68315. });
  68316. };
  68317. /**
  68318. * @private
  68319. */
  68320. SunburstView.prototype._rootToNode = function (node) {
  68321. if (node !== this.seriesModel.getViewRoot()) {
  68322. this.api.dispatchAction({
  68323. type: ROOT_TO_NODE_ACTION,
  68324. from: this.uid,
  68325. seriesId: this.seriesModel.id,
  68326. targetNode: node
  68327. });
  68328. }
  68329. };
  68330. /**
  68331. * @implement
  68332. */
  68333. SunburstView.prototype.containPoint = function (point, seriesModel) {
  68334. var treeRoot = seriesModel.getData();
  68335. var itemLayout = treeRoot.getItemLayout(0);
  68336. if (itemLayout) {
  68337. var dx = point[0] - itemLayout.cx;
  68338. var dy = point[1] - itemLayout.cy;
  68339. var radius = Math.sqrt(dx * dx + dy * dy);
  68340. return radius <= itemLayout.r && radius >= itemLayout.r0;
  68341. }
  68342. };
  68343. SunburstView.type = 'sunburst';
  68344. return SunburstView;
  68345. }(ChartView);
  68346. var SunburstSeriesModel = /** @class */function (_super) {
  68347. __extends(SunburstSeriesModel, _super);
  68348. function SunburstSeriesModel() {
  68349. var _this = _super !== null && _super.apply(this, arguments) || this;
  68350. _this.type = SunburstSeriesModel.type;
  68351. _this.ignoreStyleOnData = true;
  68352. return _this;
  68353. }
  68354. SunburstSeriesModel.prototype.getInitialData = function (option, ecModel) {
  68355. // Create a virtual root.
  68356. var root = {
  68357. name: option.name,
  68358. children: option.data
  68359. };
  68360. completeTreeValue$1(root);
  68361. var levelModels = this._levelModels = map(option.levels || [], function (levelDefine) {
  68362. return new Model(levelDefine, this, ecModel);
  68363. }, this);
  68364. // Make sure always a new tree is created when setOption,
  68365. // in TreemapView, we check whether oldTree === newTree
  68366. // to choose mappings approach among old shapes and new shapes.
  68367. var tree = Tree.createTree(root, this, beforeLink);
  68368. function beforeLink(nodeData) {
  68369. nodeData.wrapMethod('getItemModel', function (model, idx) {
  68370. var node = tree.getNodeByDataIndex(idx);
  68371. var levelModel = levelModels[node.depth];
  68372. levelModel && (model.parentModel = levelModel);
  68373. return model;
  68374. });
  68375. }
  68376. return tree.data;
  68377. };
  68378. SunburstSeriesModel.prototype.optionUpdated = function () {
  68379. this.resetViewRoot();
  68380. };
  68381. /*
  68382. * @override
  68383. */
  68384. SunburstSeriesModel.prototype.getDataParams = function (dataIndex) {
  68385. var params = _super.prototype.getDataParams.apply(this, arguments);
  68386. var node = this.getData().tree.getNodeByDataIndex(dataIndex);
  68387. params.treePathInfo = wrapTreePathInfo(node, this);
  68388. return params;
  68389. };
  68390. SunburstSeriesModel.prototype.getLevelModel = function (node) {
  68391. return this._levelModels && this._levelModels[node.depth];
  68392. };
  68393. SunburstSeriesModel.prototype.getViewRoot = function () {
  68394. return this._viewRoot;
  68395. };
  68396. SunburstSeriesModel.prototype.resetViewRoot = function (viewRoot) {
  68397. viewRoot ? this._viewRoot = viewRoot : viewRoot = this._viewRoot;
  68398. var root = this.getRawData().tree.root;
  68399. if (!viewRoot || viewRoot !== root && !root.contains(viewRoot)) {
  68400. this._viewRoot = root;
  68401. }
  68402. };
  68403. SunburstSeriesModel.prototype.enableAriaDecal = function () {
  68404. enableAriaDecalForTree(this);
  68405. };
  68406. SunburstSeriesModel.type = 'series.sunburst';
  68407. SunburstSeriesModel.defaultOption = {
  68408. // zlevel: 0,
  68409. z: 2,
  68410. // 默认全局居中
  68411. center: ['50%', '50%'],
  68412. radius: [0, '75%'],
  68413. // 默认顺时针
  68414. clockwise: true,
  68415. startAngle: 90,
  68416. // 最小角度改为0
  68417. minAngle: 0,
  68418. // If still show when all data zero.
  68419. stillShowZeroSum: true,
  68420. // 'rootToNode', 'link', or false
  68421. nodeClick: 'rootToNode',
  68422. renderLabelForZeroData: false,
  68423. label: {
  68424. // could be: 'radial', 'tangential', or 'none'
  68425. rotate: 'radial',
  68426. show: true,
  68427. opacity: 1,
  68428. // 'left' is for inner side of inside, and 'right' is for outer
  68429. // side for inside
  68430. align: 'center',
  68431. position: 'inside',
  68432. distance: 5,
  68433. silent: true
  68434. },
  68435. itemStyle: {
  68436. borderWidth: 1,
  68437. borderColor: 'white',
  68438. borderType: 'solid',
  68439. shadowBlur: 0,
  68440. shadowColor: 'rgba(0, 0, 0, 0.2)',
  68441. shadowOffsetX: 0,
  68442. shadowOffsetY: 0,
  68443. opacity: 1
  68444. },
  68445. emphasis: {
  68446. focus: 'descendant'
  68447. },
  68448. blur: {
  68449. itemStyle: {
  68450. opacity: 0.2
  68451. },
  68452. label: {
  68453. opacity: 0.1
  68454. }
  68455. },
  68456. // Animation type can be expansion, scale.
  68457. animationType: 'expansion',
  68458. animationDuration: 1000,
  68459. animationDurationUpdate: 500,
  68460. data: [],
  68461. /**
  68462. * Sort order.
  68463. *
  68464. * Valid values: 'desc', 'asc', null, or callback function.
  68465. * 'desc' and 'asc' for descend and ascendant order;
  68466. * null for not sorting;
  68467. * example of callback function:
  68468. * function(nodeA, nodeB) {
  68469. * return nodeA.getValue() - nodeB.getValue();
  68470. * }
  68471. */
  68472. sort: 'desc'
  68473. };
  68474. return SunburstSeriesModel;
  68475. }(SeriesModel);
  68476. function completeTreeValue$1(dataNode) {
  68477. // Postorder travel tree.
  68478. // If value of none-leaf node is not set,
  68479. // calculate it by suming up the value of all children.
  68480. var sum = 0;
  68481. each(dataNode.children, function (child) {
  68482. completeTreeValue$1(child);
  68483. var childValue = child.value;
  68484. // TODO First value of array must be a number
  68485. isArray(childValue) && (childValue = childValue[0]);
  68486. sum += childValue;
  68487. });
  68488. var thisValue = dataNode.value;
  68489. if (isArray(thisValue)) {
  68490. thisValue = thisValue[0];
  68491. }
  68492. if (thisValue == null || isNaN(thisValue)) {
  68493. thisValue = sum;
  68494. }
  68495. // Value should not less than 0.
  68496. if (thisValue < 0) {
  68497. thisValue = 0;
  68498. }
  68499. isArray(dataNode.value) ? dataNode.value[0] = thisValue : dataNode.value = thisValue;
  68500. }
  68501. // let PI2 = Math.PI * 2;
  68502. var RADIAN$4 = Math.PI / 180;
  68503. function sunburstLayout(seriesType, ecModel, api) {
  68504. ecModel.eachSeriesByType(seriesType, function (seriesModel) {
  68505. var center = seriesModel.get('center');
  68506. var radius = seriesModel.get('radius');
  68507. if (!isArray(radius)) {
  68508. radius = [0, radius];
  68509. }
  68510. if (!isArray(center)) {
  68511. center = [center, center];
  68512. }
  68513. var width = api.getWidth();
  68514. var height = api.getHeight();
  68515. var size = Math.min(width, height);
  68516. var cx = parsePercent$1(center[0], width);
  68517. var cy = parsePercent$1(center[1], height);
  68518. var r0 = parsePercent$1(radius[0], size / 2);
  68519. var r = parsePercent$1(radius[1], size / 2);
  68520. var startAngle = -seriesModel.get('startAngle') * RADIAN$4;
  68521. var minAngle = seriesModel.get('minAngle') * RADIAN$4;
  68522. var virtualRoot = seriesModel.getData().tree.root;
  68523. var treeRoot = seriesModel.getViewRoot();
  68524. var rootDepth = treeRoot.depth;
  68525. var sort = seriesModel.get('sort');
  68526. if (sort != null) {
  68527. initChildren$1(treeRoot, sort);
  68528. }
  68529. var validDataCount = 0;
  68530. each(treeRoot.children, function (child) {
  68531. !isNaN(child.getValue()) && validDataCount++;
  68532. });
  68533. var sum = treeRoot.getValue();
  68534. // Sum may be 0
  68535. var unitRadian = Math.PI / (sum || validDataCount) * 2;
  68536. var renderRollupNode = treeRoot.depth > 0;
  68537. var levels = treeRoot.height - (renderRollupNode ? -1 : 1);
  68538. var rPerLevel = (r - r0) / (levels || 1);
  68539. var clockwise = seriesModel.get('clockwise');
  68540. var stillShowZeroSum = seriesModel.get('stillShowZeroSum');
  68541. // In the case some sector angle is smaller than minAngle
  68542. // let restAngle = PI2;
  68543. // let valueSumLargerThanMinAngle = 0;
  68544. var dir = clockwise ? 1 : -1;
  68545. /**
  68546. * Render a tree
  68547. * @return increased angle
  68548. */
  68549. var renderNode = function (node, startAngle) {
  68550. if (!node) {
  68551. return;
  68552. }
  68553. var endAngle = startAngle;
  68554. // Render self
  68555. if (node !== virtualRoot) {
  68556. // Tree node is virtual, so it doesn't need to be drawn
  68557. var value = node.getValue();
  68558. var angle = sum === 0 && stillShowZeroSum ? unitRadian : value * unitRadian;
  68559. if (angle < minAngle) {
  68560. angle = minAngle;
  68561. // restAngle -= minAngle;
  68562. }
  68563. // else {
  68564. // valueSumLargerThanMinAngle += value;
  68565. // }
  68566. endAngle = startAngle + dir * angle;
  68567. var depth = node.depth - rootDepth - (renderRollupNode ? -1 : 1);
  68568. var rStart = r0 + rPerLevel * depth;
  68569. var rEnd = r0 + rPerLevel * (depth + 1);
  68570. var levelModel = seriesModel.getLevelModel(node);
  68571. if (levelModel) {
  68572. var r0_1 = levelModel.get('r0', true);
  68573. var r_1 = levelModel.get('r', true);
  68574. var radius_1 = levelModel.get('radius', true);
  68575. if (radius_1 != null) {
  68576. r0_1 = radius_1[0];
  68577. r_1 = radius_1[1];
  68578. }
  68579. r0_1 != null && (rStart = parsePercent$1(r0_1, size / 2));
  68580. r_1 != null && (rEnd = parsePercent$1(r_1, size / 2));
  68581. }
  68582. node.setLayout({
  68583. angle: angle,
  68584. startAngle: startAngle,
  68585. endAngle: endAngle,
  68586. clockwise: clockwise,
  68587. cx: cx,
  68588. cy: cy,
  68589. r0: rStart,
  68590. r: rEnd
  68591. });
  68592. }
  68593. // Render children
  68594. if (node.children && node.children.length) {
  68595. // currentAngle = startAngle;
  68596. var siblingAngle_1 = 0;
  68597. each(node.children, function (node) {
  68598. siblingAngle_1 += renderNode(node, startAngle + siblingAngle_1);
  68599. });
  68600. }
  68601. return endAngle - startAngle;
  68602. };
  68603. // Virtual root node for roll up
  68604. if (renderRollupNode) {
  68605. var rStart = r0;
  68606. var rEnd = r0 + rPerLevel;
  68607. var angle = Math.PI * 2;
  68608. virtualRoot.setLayout({
  68609. angle: angle,
  68610. startAngle: startAngle,
  68611. endAngle: startAngle + angle,
  68612. clockwise: clockwise,
  68613. cx: cx,
  68614. cy: cy,
  68615. r0: rStart,
  68616. r: rEnd
  68617. });
  68618. }
  68619. renderNode(treeRoot, startAngle);
  68620. });
  68621. }
  68622. /**
  68623. * Init node children by order and update visual
  68624. */
  68625. function initChildren$1(node, sortOrder) {
  68626. var children = node.children || [];
  68627. node.children = sort$2(children, sortOrder);
  68628. // Init children recursively
  68629. if (children.length) {
  68630. each(node.children, function (child) {
  68631. initChildren$1(child, sortOrder);
  68632. });
  68633. }
  68634. }
  68635. /**
  68636. * Sort children nodes
  68637. *
  68638. * @param {TreeNode[]} children children of node to be sorted
  68639. * @param {string | function | null} sort sort method
  68640. * See SunburstSeries.js for details.
  68641. */
  68642. function sort$2(children, sortOrder) {
  68643. if (isFunction(sortOrder)) {
  68644. var sortTargets = map(children, function (child, idx) {
  68645. var value = child.getValue();
  68646. return {
  68647. params: {
  68648. depth: child.depth,
  68649. height: child.height,
  68650. dataIndex: child.dataIndex,
  68651. getValue: function () {
  68652. return value;
  68653. }
  68654. },
  68655. index: idx
  68656. };
  68657. });
  68658. sortTargets.sort(function (a, b) {
  68659. return sortOrder(a.params, b.params);
  68660. });
  68661. return map(sortTargets, function (target) {
  68662. return children[target.index];
  68663. });
  68664. } else {
  68665. var isAsc_1 = sortOrder === 'asc';
  68666. return children.sort(function (a, b) {
  68667. var diff = (a.getValue() - b.getValue()) * (isAsc_1 ? 1 : -1);
  68668. return diff === 0 ? (a.dataIndex - b.dataIndex) * (isAsc_1 ? -1 : 1) : diff;
  68669. });
  68670. }
  68671. }
  68672. function sunburstVisual(ecModel) {
  68673. var paletteScope = {};
  68674. // Default color strategy
  68675. function pickColor(node, seriesModel, treeHeight) {
  68676. if (node.depth === 0) {
  68677. // Don't use palette color for the root node, because it's displayed only when drilling down.
  68678. return tokens.color.neutral50;
  68679. }
  68680. // Choose color from palette based on the first level.
  68681. var current = node;
  68682. while (current && current.depth > 1) {
  68683. current = current.parentNode;
  68684. }
  68685. var color = seriesModel.getColorFromPalette(current.name || current.dataIndex + '', paletteScope);
  68686. if (node.depth > 1 && isString(color)) {
  68687. // Lighter on the deeper level.
  68688. color = lift(color, (node.depth - 1) / (treeHeight - 1) * 0.5);
  68689. }
  68690. return color;
  68691. }
  68692. ecModel.eachSeriesByType('sunburst', function (seriesModel) {
  68693. var data = seriesModel.getData();
  68694. var tree = data.tree;
  68695. tree.eachNode(function (node) {
  68696. var model = node.getModel();
  68697. var style = model.getModel('itemStyle').getItemStyle();
  68698. if (!style.fill) {
  68699. style.fill = pickColor(node, seriesModel, tree.root.height);
  68700. }
  68701. var existsStyle = data.ensureUniqueItemVisual(node.dataIndex, 'style');
  68702. extend(existsStyle, style);
  68703. });
  68704. });
  68705. }
  68706. function install$r(registers) {
  68707. registers.registerChartView(SunburstView);
  68708. registers.registerSeriesModel(SunburstSeriesModel);
  68709. registers.registerLayout(curry(sunburstLayout, 'sunburst'));
  68710. registers.registerProcessor(curry(dataFilter, 'sunburst'));
  68711. registers.registerVisual(sunburstVisual);
  68712. installSunburstAction(registers);
  68713. }
  68714. // Also compat with ec4, where
  68715. // `visual('color') visual('borderColor')` is supported.
  68716. var STYLE_VISUAL_TYPE = {
  68717. color: 'fill',
  68718. borderColor: 'stroke'
  68719. };
  68720. var NON_STYLE_VISUAL_PROPS = {
  68721. symbol: 1,
  68722. symbolSize: 1,
  68723. symbolKeepAspect: 1,
  68724. legendIcon: 1,
  68725. visualMeta: 1,
  68726. liftZ: 1,
  68727. decal: 1
  68728. };
  68729. var customInnerStore = makeInner();
  68730. var CustomSeriesModel = /** @class */function (_super) {
  68731. __extends(CustomSeriesModel, _super);
  68732. function CustomSeriesModel() {
  68733. var _this = _super !== null && _super.apply(this, arguments) || this;
  68734. _this.type = CustomSeriesModel.type;
  68735. return _this;
  68736. }
  68737. CustomSeriesModel.prototype.optionUpdated = function () {
  68738. this.currentZLevel = this.get('zlevel', true);
  68739. this.currentZ = this.get('z', true);
  68740. };
  68741. CustomSeriesModel.prototype.getInitialData = function (option, ecModel) {
  68742. return createSeriesData(null, this);
  68743. };
  68744. CustomSeriesModel.prototype.getDataParams = function (dataIndex, dataType, el) {
  68745. var params = _super.prototype.getDataParams.call(this, dataIndex, dataType);
  68746. el && (params.info = customInnerStore(el).info);
  68747. return params;
  68748. };
  68749. CustomSeriesModel.type = 'series.custom';
  68750. CustomSeriesModel.dependencies = ['grid', 'polar', 'geo', 'singleAxis', 'calendar', 'matrix'];
  68751. CustomSeriesModel.defaultOption = {
  68752. coordinateSystem: 'cartesian2d',
  68753. // zlevel: 0,
  68754. z: 2,
  68755. legendHoverLink: true,
  68756. // Custom series will not clip by default.
  68757. // Some case will use custom series to draw label
  68758. // For example https://echarts.apache.org/examples/en/editor.html?c=custom-gantt-flight
  68759. clip: false
  68760. // Cartesian coordinate system
  68761. // xAxisIndex: 0,
  68762. // yAxisIndex: 0,
  68763. // Polar coordinate system
  68764. // polarIndex: 0,
  68765. // Geo coordinate system
  68766. // geoIndex: 0,
  68767. };
  68768. return CustomSeriesModel;
  68769. }(SeriesModel);
  68770. function dataToCoordSize(dataSize, dataItem) {
  68771. // dataItem is necessary in log axis.
  68772. dataItem = dataItem || [0, 0];
  68773. return map(['x', 'y'], function (dim, dimIdx) {
  68774. var axis = this.getAxis(dim);
  68775. var val = dataItem[dimIdx];
  68776. var halfSize = dataSize[dimIdx] / 2;
  68777. return axis.type === 'category' ? axis.getBandWidth() : Math.abs(axis.dataToCoord(val - halfSize) - axis.dataToCoord(val + halfSize));
  68778. }, this);
  68779. }
  68780. function cartesianPrepareCustom(coordSys) {
  68781. var rect = coordSys.master.getRect();
  68782. return {
  68783. coordSys: {
  68784. // The name exposed to user is always 'cartesian2d' but not 'grid'.
  68785. type: 'cartesian2d',
  68786. x: rect.x,
  68787. y: rect.y,
  68788. width: rect.width,
  68789. height: rect.height
  68790. },
  68791. api: {
  68792. coord: function (data) {
  68793. // do not provide "out" param
  68794. return coordSys.dataToPoint(data);
  68795. },
  68796. size: bind(dataToCoordSize, coordSys)
  68797. }
  68798. };
  68799. }
  68800. function dataToCoordSize$1(dataSize, dataItem) {
  68801. dataItem = dataItem || [0, 0];
  68802. return map([0, 1], function (dimIdx) {
  68803. var val = dataItem[dimIdx];
  68804. var halfSize = dataSize[dimIdx] / 2;
  68805. var p1 = [];
  68806. var p2 = [];
  68807. p1[dimIdx] = val - halfSize;
  68808. p2[dimIdx] = val + halfSize;
  68809. p1[1 - dimIdx] = p2[1 - dimIdx] = dataItem[1 - dimIdx];
  68810. return Math.abs(this.dataToPoint(p1)[dimIdx] - this.dataToPoint(p2)[dimIdx]);
  68811. }, this);
  68812. }
  68813. function geoPrepareCustom(coordSys) {
  68814. var rect = coordSys.getBoundingRect();
  68815. return {
  68816. coordSys: {
  68817. type: 'geo',
  68818. x: rect.x,
  68819. y: rect.y,
  68820. width: rect.width,
  68821. height: rect.height,
  68822. zoom: coordSys.getZoom()
  68823. },
  68824. api: {
  68825. coord: function (data) {
  68826. // do not provide "out" and noRoam param,
  68827. // Compatible with this usage:
  68828. // echarts.util.map(item.points, api.coord)
  68829. return coordSys.dataToPoint(data);
  68830. },
  68831. size: bind(dataToCoordSize$1, coordSys)
  68832. }
  68833. };
  68834. }
  68835. function dataToCoordSize$2(dataSize, dataItem) {
  68836. // dataItem is necessary in log axis.
  68837. var axis = this.getAxis();
  68838. var val = dataItem instanceof Array ? dataItem[0] : dataItem;
  68839. var halfSize = (dataSize instanceof Array ? dataSize[0] : dataSize) / 2;
  68840. return axis.type === 'category' ? axis.getBandWidth() : Math.abs(axis.dataToCoord(val - halfSize) - axis.dataToCoord(val + halfSize));
  68841. }
  68842. function singlePrepareCustom(coordSys) {
  68843. var rect = coordSys.getRect();
  68844. return {
  68845. coordSys: {
  68846. type: 'singleAxis',
  68847. x: rect.x,
  68848. y: rect.y,
  68849. width: rect.width,
  68850. height: rect.height
  68851. },
  68852. api: {
  68853. coord: function (val) {
  68854. // do not provide "out" param
  68855. return coordSys.dataToPoint(val);
  68856. },
  68857. size: bind(dataToCoordSize$2, coordSys)
  68858. }
  68859. };
  68860. }
  68861. // import AngleAxis from './AngleAxis.js';
  68862. function dataToCoordSize$3(dataSize, dataItem) {
  68863. // dataItem is necessary in log axis.
  68864. dataItem = dataItem || [0, 0];
  68865. return map(['Radius', 'Angle'], function (dim, dimIdx) {
  68866. var getterName = 'get' + dim + 'Axis';
  68867. // TODO: TYPE Check Angle Axis
  68868. var axis = this[getterName]();
  68869. var val = dataItem[dimIdx];
  68870. var halfSize = dataSize[dimIdx] / 2;
  68871. var result = axis.type === 'category' ? axis.getBandWidth() : Math.abs(axis.dataToCoord(val - halfSize) - axis.dataToCoord(val + halfSize));
  68872. if (dim === 'Angle') {
  68873. result = result * Math.PI / 180;
  68874. }
  68875. return result;
  68876. }, this);
  68877. }
  68878. function polarPrepareCustom(coordSys) {
  68879. var radiusAxis = coordSys.getRadiusAxis();
  68880. var angleAxis = coordSys.getAngleAxis();
  68881. var radius = radiusAxis.getExtent();
  68882. radius[0] > radius[1] && radius.reverse();
  68883. return {
  68884. coordSys: {
  68885. type: 'polar',
  68886. cx: coordSys.cx,
  68887. cy: coordSys.cy,
  68888. r: radius[1],
  68889. r0: radius[0]
  68890. },
  68891. api: {
  68892. coord: function (data) {
  68893. var radius = radiusAxis.dataToRadius(data[0]);
  68894. var angle = angleAxis.dataToAngle(data[1]);
  68895. var coord = coordSys.coordToPoint([radius, angle]);
  68896. coord.push(radius, angle * Math.PI / 180);
  68897. return coord;
  68898. },
  68899. size: bind(dataToCoordSize$3, coordSys)
  68900. }
  68901. };
  68902. }
  68903. /*
  68904. * Licensed to the Apache Software Foundation (ASF) under one
  68905. * or more contributor license agreements. See the NOTICE file
  68906. * distributed with this work for additional information
  68907. * regarding copyright ownership. The ASF licenses this file
  68908. * to you under the Apache License, Version 2.0 (the
  68909. * "License"); you may not use this file except in compliance
  68910. * with the License. You may obtain a copy of the License at
  68911. *
  68912. * http://www.apache.org/licenses/LICENSE-2.0
  68913. *
  68914. * Unless required by applicable law or agreed to in writing,
  68915. * software distributed under the License is distributed on an
  68916. * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
  68917. * KIND, either express or implied. See the License for the
  68918. * specific language governing permissions and limitations
  68919. * under the License.
  68920. */
  68921. /**
  68922. * AUTO-GENERATED FILE. DO NOT MODIFY.
  68923. */
  68924. /*
  68925. * Licensed to the Apache Software Foundation (ASF) under one
  68926. * or more contributor license agreements. See the NOTICE file
  68927. * distributed with this work for additional information
  68928. * regarding copyright ownership. The ASF licenses this file
  68929. * to you under the Apache License, Version 2.0 (the
  68930. * "License"); you may not use this file except in compliance
  68931. * with the License. You may obtain a copy of the License at
  68932. *
  68933. * http://www.apache.org/licenses/LICENSE-2.0
  68934. *
  68935. * Unless required by applicable law or agreed to in writing,
  68936. * software distributed under the License is distributed on an
  68937. * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
  68938. * KIND, either express or implied. See the License for the
  68939. * specific language governing permissions and limitations
  68940. * under the License.
  68941. */
  68942. function calendarPrepareCustom(coordSys) {
  68943. var rect = coordSys.getRect();
  68944. var rangeInfo = coordSys.getRangeInfo();
  68945. return {
  68946. coordSys: {
  68947. type: 'calendar',
  68948. x: rect.x,
  68949. y: rect.y,
  68950. width: rect.width,
  68951. height: rect.height,
  68952. cellWidth: coordSys.getCellWidth(),
  68953. cellHeight: coordSys.getCellHeight(),
  68954. rangeInfo: {
  68955. start: rangeInfo.start,
  68956. end: rangeInfo.end,
  68957. weeks: rangeInfo.weeks,
  68958. dayCount: rangeInfo.allDay
  68959. }
  68960. },
  68961. api: {
  68962. coord: function (data, clamp) {
  68963. return coordSys.dataToPoint(data, clamp);
  68964. },
  68965. layout: function (data, clamp) {
  68966. return coordSys.dataToLayout(data, clamp);
  68967. }
  68968. }
  68969. };
  68970. }
  68971. /*
  68972. * Licensed to the Apache Software Foundation (ASF) under one
  68973. * or more contributor license agreements. See the NOTICE file
  68974. * distributed with this work for additional information
  68975. * regarding copyright ownership. The ASF licenses this file
  68976. * to you under the Apache License, Version 2.0 (the
  68977. * "License"); you may not use this file except in compliance
  68978. * with the License. You may obtain a copy of the License at
  68979. *
  68980. * http://www.apache.org/licenses/LICENSE-2.0
  68981. *
  68982. * Unless required by applicable law or agreed to in writing,
  68983. * software distributed under the License is distributed on an
  68984. * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
  68985. * KIND, either express or implied. See the License for the
  68986. * specific language governing permissions and limitations
  68987. * under the License.
  68988. */
  68989. /**
  68990. * AUTO-GENERATED FILE. DO NOT MODIFY.
  68991. */
  68992. /*
  68993. * Licensed to the Apache Software Foundation (ASF) under one
  68994. * or more contributor license agreements. See the NOTICE file
  68995. * distributed with this work for additional information
  68996. * regarding copyright ownership. The ASF licenses this file
  68997. * to you under the Apache License, Version 2.0 (the
  68998. * "License"); you may not use this file except in compliance
  68999. * with the License. You may obtain a copy of the License at
  69000. *
  69001. * http://www.apache.org/licenses/LICENSE-2.0
  69002. *
  69003. * Unless required by applicable law or agreed to in writing,
  69004. * software distributed under the License is distributed on an
  69005. * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
  69006. * KIND, either express or implied. See the License for the
  69007. * specific language governing permissions and limitations
  69008. * under the License.
  69009. */
  69010. function matrixPrepareCustom(coordSys) {
  69011. var rect = coordSys.getRect();
  69012. return {
  69013. coordSys: {
  69014. type: 'matrix',
  69015. x: rect.x,
  69016. y: rect.y,
  69017. width: rect.width,
  69018. height: rect.height
  69019. },
  69020. api: {
  69021. coord: function (data, opt) {
  69022. return coordSys.dataToPoint(data, opt);
  69023. },
  69024. layout: function (data, opt) {
  69025. return coordSys.dataToLayout(data, opt);
  69026. }
  69027. }
  69028. };
  69029. }
  69030. var deprecatedLogs = {};
  69031. /**
  69032. * Whether need to call `convertEC4CompatibleStyle`.
  69033. */
  69034. function isEC4CompatibleStyle(style, elType, hasOwnTextContentOption, hasOwnTextConfig) {
  69035. // Since echarts5, `RectText` is separated from its host element and style.text
  69036. // does not exist any more. The compat work brings some extra burden on performance.
  69037. // So we provide:
  69038. // `legacy: true` force make compat.
  69039. // `legacy: false`, force do not compat.
  69040. // `legacy` not set: auto detect whether legacy.
  69041. // But in this case we do not compat (difficult to detect and rare case):
  69042. // Because custom series and graphic component support "merge", users may firstly
  69043. // only set `textStrokeWidth` style or secondly only set `text`.
  69044. return style && (style.legacy || style.legacy !== false && !hasOwnTextContentOption && !hasOwnTextConfig && elType !== 'tspan'
  69045. // Difficult to detect whether legacy for a "text" el.
  69046. && (elType === 'text' || hasOwn(style, 'text')));
  69047. }
  69048. /**
  69049. * `EC4CompatibleStyle` is style that might be in echarts4 format or echarts5 format.
  69050. * @param hostStyle The properties might be modified.
  69051. * @return If be text el, `textContentStyle` and `textConfig` will not be returned.
  69052. * Otherwise a `textContentStyle` and `textConfig` will be created, whose props area
  69053. * retried from the `hostStyle`.
  69054. */
  69055. function convertFromEC4CompatibleStyle(hostStyle, elType, isNormal) {
  69056. var srcStyle = hostStyle;
  69057. var textConfig;
  69058. var textContent;
  69059. var textContentStyle;
  69060. if (elType === 'text') {
  69061. textContentStyle = srcStyle;
  69062. } else {
  69063. textContentStyle = {};
  69064. hasOwn(srcStyle, 'text') && (textContentStyle.text = srcStyle.text);
  69065. hasOwn(srcStyle, 'rich') && (textContentStyle.rich = srcStyle.rich);
  69066. hasOwn(srcStyle, 'textFill') && (textContentStyle.fill = srcStyle.textFill);
  69067. hasOwn(srcStyle, 'textStroke') && (textContentStyle.stroke = srcStyle.textStroke);
  69068. hasOwn(srcStyle, 'fontFamily') && (textContentStyle.fontFamily = srcStyle.fontFamily);
  69069. hasOwn(srcStyle, 'fontSize') && (textContentStyle.fontSize = srcStyle.fontSize);
  69070. hasOwn(srcStyle, 'fontStyle') && (textContentStyle.fontStyle = srcStyle.fontStyle);
  69071. hasOwn(srcStyle, 'fontWeight') && (textContentStyle.fontWeight = srcStyle.fontWeight);
  69072. textContent = {
  69073. type: 'text',
  69074. style: textContentStyle,
  69075. // ec4 does not support rectText trigger.
  69076. // And when text position is different in normal and emphasis
  69077. // => hover text trigger emphasis;
  69078. // => text position changed, leave mouse pointer immediately;
  69079. // That might cause incorrect state.
  69080. silent: true
  69081. };
  69082. textConfig = {};
  69083. var hasOwnPos = hasOwn(srcStyle, 'textPosition');
  69084. if (isNormal) {
  69085. textConfig.position = hasOwnPos ? srcStyle.textPosition : 'inside';
  69086. } else {
  69087. hasOwnPos && (textConfig.position = srcStyle.textPosition);
  69088. }
  69089. hasOwn(srcStyle, 'textPosition') && (textConfig.position = srcStyle.textPosition);
  69090. hasOwn(srcStyle, 'textOffset') && (textConfig.offset = srcStyle.textOffset);
  69091. hasOwn(srcStyle, 'textRotation') && (textConfig.rotation = srcStyle.textRotation);
  69092. hasOwn(srcStyle, 'textDistance') && (textConfig.distance = srcStyle.textDistance);
  69093. }
  69094. convertEC4CompatibleRichItem(textContentStyle, hostStyle);
  69095. each(textContentStyle.rich, function (richItem) {
  69096. convertEC4CompatibleRichItem(richItem, richItem);
  69097. });
  69098. return {
  69099. textConfig: textConfig,
  69100. textContent: textContent
  69101. };
  69102. }
  69103. /**
  69104. * The result will be set to `out`.
  69105. */
  69106. function convertEC4CompatibleRichItem(out, richItem) {
  69107. if (!richItem) {
  69108. return;
  69109. }
  69110. // (1) For simplicity, make textXXX properties (deprecated since ec5) has
  69111. // higher priority. For example, consider in ec4 `borderColor: 5, textBorderColor: 10`
  69112. // on a rect means `borderColor: 4` on the rect and `borderColor: 10` on an attached
  69113. // richText in ec5.
  69114. // (2) `out === richItem` if and only if `out` is text el or rich item.
  69115. // So we can overwrite existing props in `out` since textXXX has higher priority.
  69116. richItem.font = richItem.textFont || richItem.font;
  69117. hasOwn(richItem, 'textStrokeWidth') && (out.lineWidth = richItem.textStrokeWidth);
  69118. hasOwn(richItem, 'textAlign') && (out.align = richItem.textAlign);
  69119. hasOwn(richItem, 'textVerticalAlign') && (out.verticalAlign = richItem.textVerticalAlign);
  69120. hasOwn(richItem, 'textLineHeight') && (out.lineHeight = richItem.textLineHeight);
  69121. hasOwn(richItem, 'textWidth') && (out.width = richItem.textWidth);
  69122. hasOwn(richItem, 'textHeight') && (out.height = richItem.textHeight);
  69123. hasOwn(richItem, 'textBackgroundColor') && (out.backgroundColor = richItem.textBackgroundColor);
  69124. hasOwn(richItem, 'textPadding') && (out.padding = richItem.textPadding);
  69125. hasOwn(richItem, 'textBorderColor') && (out.borderColor = richItem.textBorderColor);
  69126. hasOwn(richItem, 'textBorderWidth') && (out.borderWidth = richItem.textBorderWidth);
  69127. hasOwn(richItem, 'textBorderRadius') && (out.borderRadius = richItem.textBorderRadius);
  69128. hasOwn(richItem, 'textBoxShadowColor') && (out.shadowColor = richItem.textBoxShadowColor);
  69129. hasOwn(richItem, 'textBoxShadowBlur') && (out.shadowBlur = richItem.textBoxShadowBlur);
  69130. hasOwn(richItem, 'textBoxShadowOffsetX') && (out.shadowOffsetX = richItem.textBoxShadowOffsetX);
  69131. hasOwn(richItem, 'textBoxShadowOffsetY') && (out.shadowOffsetY = richItem.textBoxShadowOffsetY);
  69132. }
  69133. /**
  69134. * Convert to pure echarts4 format style.
  69135. * `itemStyle` will be modified, added with ec4 style properties from
  69136. * `textStyle` and `textConfig`.
  69137. *
  69138. * [Caveat]: For simplicity, `insideRollback` in ec4 does not compat, where
  69139. * `styleEmphasis: {textFill: 'red'}` will remove the normal auto added stroke.
  69140. */
  69141. function convertToEC4StyleForCustomSerise(itemStl, txStl, txCfg) {
  69142. var out = itemStl;
  69143. // See `custom.ts`, a trick to set extra `textPosition` firstly.
  69144. out.textPosition = out.textPosition || txCfg.position || 'inside';
  69145. txCfg.offset != null && (out.textOffset = txCfg.offset);
  69146. txCfg.rotation != null && (out.textRotation = txCfg.rotation);
  69147. txCfg.distance != null && (out.textDistance = txCfg.distance);
  69148. var isInside = out.textPosition.indexOf('inside') >= 0;
  69149. var hostFill = itemStl.fill || tokens.color.neutral99;
  69150. convertToEC4RichItem(out, txStl);
  69151. var textFillNotSet = out.textFill == null;
  69152. if (isInside) {
  69153. if (textFillNotSet) {
  69154. out.textFill = txCfg.insideFill || tokens.color.neutral00;
  69155. !out.textStroke && txCfg.insideStroke && (out.textStroke = txCfg.insideStroke);
  69156. !out.textStroke && (out.textStroke = hostFill);
  69157. out.textStrokeWidth == null && (out.textStrokeWidth = 2);
  69158. }
  69159. } else {
  69160. if (textFillNotSet) {
  69161. out.textFill = itemStl.fill || txCfg.outsideFill || tokens.color.neutral00;
  69162. }
  69163. !out.textStroke && txCfg.outsideStroke && (out.textStroke = txCfg.outsideStroke);
  69164. }
  69165. out.text = txStl.text;
  69166. out.rich = txStl.rich;
  69167. each(txStl.rich, function (richItem) {
  69168. convertToEC4RichItem(richItem, richItem);
  69169. });
  69170. return out;
  69171. }
  69172. function convertToEC4RichItem(out, richItem) {
  69173. if (!richItem) {
  69174. return;
  69175. }
  69176. hasOwn(richItem, 'fill') && (out.textFill = richItem.fill);
  69177. hasOwn(richItem, 'stroke') && (out.textStroke = richItem.fill);
  69178. hasOwn(richItem, 'lineWidth') && (out.textStrokeWidth = richItem.lineWidth);
  69179. hasOwn(richItem, 'font') && (out.font = richItem.font);
  69180. hasOwn(richItem, 'fontStyle') && (out.fontStyle = richItem.fontStyle);
  69181. hasOwn(richItem, 'fontWeight') && (out.fontWeight = richItem.fontWeight);
  69182. hasOwn(richItem, 'fontSize') && (out.fontSize = richItem.fontSize);
  69183. hasOwn(richItem, 'fontFamily') && (out.fontFamily = richItem.fontFamily);
  69184. hasOwn(richItem, 'align') && (out.textAlign = richItem.align);
  69185. hasOwn(richItem, 'verticalAlign') && (out.textVerticalAlign = richItem.verticalAlign);
  69186. hasOwn(richItem, 'lineHeight') && (out.textLineHeight = richItem.lineHeight);
  69187. hasOwn(richItem, 'width') && (out.textWidth = richItem.width);
  69188. hasOwn(richItem, 'height') && (out.textHeight = richItem.height);
  69189. hasOwn(richItem, 'backgroundColor') && (out.textBackgroundColor = richItem.backgroundColor);
  69190. hasOwn(richItem, 'padding') && (out.textPadding = richItem.padding);
  69191. hasOwn(richItem, 'borderColor') && (out.textBorderColor = richItem.borderColor);
  69192. hasOwn(richItem, 'borderWidth') && (out.textBorderWidth = richItem.borderWidth);
  69193. hasOwn(richItem, 'borderRadius') && (out.textBorderRadius = richItem.borderRadius);
  69194. hasOwn(richItem, 'shadowColor') && (out.textBoxShadowColor = richItem.shadowColor);
  69195. hasOwn(richItem, 'shadowBlur') && (out.textBoxShadowBlur = richItem.shadowBlur);
  69196. hasOwn(richItem, 'shadowOffsetX') && (out.textBoxShadowOffsetX = richItem.shadowOffsetX);
  69197. hasOwn(richItem, 'shadowOffsetY') && (out.textBoxShadowOffsetY = richItem.shadowOffsetY);
  69198. hasOwn(richItem, 'textShadowColor') && (out.textShadowColor = richItem.textShadowColor);
  69199. hasOwn(richItem, 'textShadowBlur') && (out.textShadowBlur = richItem.textShadowBlur);
  69200. hasOwn(richItem, 'textShadowOffsetX') && (out.textShadowOffsetX = richItem.textShadowOffsetX);
  69201. hasOwn(richItem, 'textShadowOffsetY') && (out.textShadowOffsetY = richItem.textShadowOffsetY);
  69202. }
  69203. function warnDeprecated(deprecated, insteadApproach) {
  69204. if ("development" !== 'production') {
  69205. var key = deprecated + '^_^' + insteadApproach;
  69206. if (!deprecatedLogs[key]) {
  69207. console.warn("[ECharts] DEPRECATED: \"" + deprecated + "\" has been deprecated. " + insteadApproach);
  69208. deprecatedLogs[key] = true;
  69209. }
  69210. }
  69211. }
  69212. var LEGACY_TRANSFORM_PROPS_MAP = {
  69213. position: ['x', 'y'],
  69214. scale: ['scaleX', 'scaleY'],
  69215. origin: ['originX', 'originY']
  69216. };
  69217. var LEGACY_TRANSFORM_PROPS = keys(LEGACY_TRANSFORM_PROPS_MAP);
  69218. var TRANSFORM_PROPS_MAP = reduce(TRANSFORMABLE_PROPS, function (obj, key) {
  69219. obj[key] = 1;
  69220. return obj;
  69221. }, {});
  69222. var transformPropNamesStr = TRANSFORMABLE_PROPS.join(', ');
  69223. // '' means root
  69224. var ELEMENT_ANIMATABLE_PROPS = ['', 'style', 'shape', 'extra'];
  69225. var transitionInnerStore = makeInner();
  69226. function getElementAnimationConfig(animationType, el, elOption, parentModel, dataIndex) {
  69227. var animationProp = animationType + "Animation";
  69228. var config = getAnimationConfig(animationType, parentModel, dataIndex) || {};
  69229. var userDuring = transitionInnerStore(el).userDuring;
  69230. // Only set when duration is > 0 and it's need to be animated.
  69231. if (config.duration > 0) {
  69232. // For simplicity, if during not specified, the previous during will not work any more.
  69233. config.during = userDuring ? bind(duringCall, {
  69234. el: el,
  69235. userDuring: userDuring
  69236. }) : null;
  69237. config.setToFinal = true;
  69238. config.scope = animationType;
  69239. }
  69240. extend(config, elOption[animationProp]);
  69241. return config;
  69242. }
  69243. function applyUpdateTransition(el, elOption, animatableModel, opts) {
  69244. opts = opts || {};
  69245. var dataIndex = opts.dataIndex,
  69246. isInit = opts.isInit,
  69247. clearStyle = opts.clearStyle;
  69248. var hasAnimation = animatableModel.isAnimationEnabled();
  69249. // Save the meta info for further morphing. Like apply on the sub morphing elements.
  69250. var store = transitionInnerStore(el);
  69251. var styleOpt = elOption.style;
  69252. store.userDuring = elOption.during;
  69253. var transFromProps = {};
  69254. var propsToSet = {};
  69255. prepareTransformAllPropsFinal(el, elOption, propsToSet);
  69256. if (el.type === 'compound') {
  69257. /**
  69258. * We cannot directly clone shape for compoundPath,
  69259. * because it makes the path to be an object instead of a Path instance,
  69260. * and thus missing `buildPath` method.
  69261. */
  69262. var paths = el.shape.paths;
  69263. var optionPaths = elOption.shape.paths;
  69264. for (var i = 0; i < optionPaths.length; i++) {
  69265. var path = optionPaths[i];
  69266. prepareShapeOrExtraAllPropsFinal('shape', path, paths[i]);
  69267. }
  69268. } else {
  69269. prepareShapeOrExtraAllPropsFinal('shape', elOption, propsToSet);
  69270. prepareShapeOrExtraAllPropsFinal('extra', elOption, propsToSet);
  69271. }
  69272. if (!isInit && hasAnimation) {
  69273. prepareTransformTransitionFrom(el, elOption, transFromProps);
  69274. prepareShapeOrExtraTransitionFrom('shape', el, elOption, transFromProps);
  69275. prepareShapeOrExtraTransitionFrom('extra', el, elOption, transFromProps);
  69276. prepareStyleTransitionFrom(el, elOption, styleOpt, transFromProps);
  69277. }
  69278. propsToSet.style = styleOpt;
  69279. applyPropsDirectly(el, propsToSet, clearStyle);
  69280. applyMiscProps(el, elOption);
  69281. if (hasAnimation) {
  69282. if (isInit) {
  69283. var enterFromProps_1 = {};
  69284. each(ELEMENT_ANIMATABLE_PROPS, function (propName) {
  69285. var prop = propName ? elOption[propName] : elOption;
  69286. if (prop && prop.enterFrom) {
  69287. if (propName) {
  69288. enterFromProps_1[propName] = enterFromProps_1[propName] || {};
  69289. }
  69290. extend(propName ? enterFromProps_1[propName] : enterFromProps_1, prop.enterFrom);
  69291. }
  69292. });
  69293. var config = getElementAnimationConfig('enter', el, elOption, animatableModel, dataIndex);
  69294. if (config.duration > 0) {
  69295. el.animateFrom(enterFromProps_1, config);
  69296. }
  69297. } else {
  69298. applyPropsTransition(el, elOption, dataIndex || 0, animatableModel, transFromProps);
  69299. }
  69300. }
  69301. // Store leave to be used in leave transition.
  69302. updateLeaveTo(el, elOption);
  69303. styleOpt ? el.dirty() : el.markRedraw();
  69304. }
  69305. function updateLeaveTo(el, elOption) {
  69306. // Try merge to previous set leaveTo
  69307. var leaveToProps = transitionInnerStore(el).leaveToProps;
  69308. for (var i = 0; i < ELEMENT_ANIMATABLE_PROPS.length; i++) {
  69309. var propName = ELEMENT_ANIMATABLE_PROPS[i];
  69310. var prop = propName ? elOption[propName] : elOption;
  69311. if (prop && prop.leaveTo) {
  69312. if (!leaveToProps) {
  69313. leaveToProps = transitionInnerStore(el).leaveToProps = {};
  69314. }
  69315. if (propName) {
  69316. leaveToProps[propName] = leaveToProps[propName] || {};
  69317. }
  69318. extend(propName ? leaveToProps[propName] : leaveToProps, prop.leaveTo);
  69319. }
  69320. }
  69321. }
  69322. function applyLeaveTransition(el, elOption, animatableModel, onRemove) {
  69323. if (el) {
  69324. var parent_1 = el.parent;
  69325. var leaveToProps = transitionInnerStore(el).leaveToProps;
  69326. if (leaveToProps) {
  69327. // TODO TODO use leave after leaveAnimation in series is introduced
  69328. // TODO Data index?
  69329. var config = getElementAnimationConfig('update', el, elOption, animatableModel, 0);
  69330. config.done = function () {
  69331. parent_1 && parent_1.remove(el);
  69332. onRemove && onRemove();
  69333. };
  69334. el.animateTo(leaveToProps, config);
  69335. } else {
  69336. parent_1 && parent_1.remove(el);
  69337. onRemove && onRemove();
  69338. }
  69339. }
  69340. }
  69341. function isTransitionAll(transition) {
  69342. return transition === 'all';
  69343. }
  69344. function applyPropsDirectly(el,
  69345. // Can be null/undefined
  69346. allPropsFinal, clearStyle) {
  69347. var styleOpt = allPropsFinal.style;
  69348. if (!el.isGroup && styleOpt) {
  69349. if (clearStyle) {
  69350. el.useStyle({});
  69351. // When style object changed, how to trade the existing animation?
  69352. // It is probably complicated and not needed to cover all the cases.
  69353. // But still need consider the case:
  69354. // (1) When using init animation on `style.opacity`, and before the animation
  69355. // ended users triggers an update by mousewhel. At that time the init
  69356. // animation should better be continued rather than terminated.
  69357. // So after `useStyle` called, we should change the animation target manually
  69358. // to continue the effect of the init animation.
  69359. // (2) PENDING: If the previous animation targeted at a `val1`, and currently we need
  69360. // to update the value to `val2` and no animation declared, should be terminate
  69361. // the previous animation or just modify the target of the animation?
  69362. // Therotically That will happen not only on `style` but also on `shape` and
  69363. // `transfrom` props. But we haven't handle this case at present yet.
  69364. // (3) PENDING: Is it proper to visit `animators` and `targetName`?
  69365. var animators = el.animators;
  69366. for (var i = 0; i < animators.length; i++) {
  69367. var animator = animators[i];
  69368. // targetName is the "topKey".
  69369. if (animator.targetName === 'style') {
  69370. animator.changeTarget(el.style);
  69371. }
  69372. }
  69373. }
  69374. el.setStyle(styleOpt);
  69375. }
  69376. if (allPropsFinal) {
  69377. // Not set style here.
  69378. allPropsFinal.style = null;
  69379. // Set el to the final state firstly.
  69380. allPropsFinal && el.attr(allPropsFinal);
  69381. allPropsFinal.style = styleOpt;
  69382. }
  69383. }
  69384. function applyPropsTransition(el, elOption, dataIndex, model,
  69385. // Can be null/undefined
  69386. transFromProps) {
  69387. if (transFromProps) {
  69388. var config = getElementAnimationConfig('update', el, elOption, model, dataIndex);
  69389. if (config.duration > 0) {
  69390. el.animateFrom(transFromProps, config);
  69391. }
  69392. }
  69393. }
  69394. function applyMiscProps(el, elOption) {
  69395. // Merge by default.
  69396. hasOwn(elOption, 'silent') && (el.silent = elOption.silent);
  69397. hasOwn(elOption, 'ignore') && (el.ignore = elOption.ignore);
  69398. if (el instanceof Displayable) {
  69399. hasOwn(elOption, 'invisible') && (el.invisible = elOption.invisible);
  69400. }
  69401. if (el instanceof Path) {
  69402. hasOwn(elOption, 'autoBatch') && (el.autoBatch = elOption.autoBatch);
  69403. }
  69404. }
  69405. // Use it to avoid it be exposed to user.
  69406. var tmpDuringScope = {};
  69407. var transitionDuringAPI = {
  69408. // Usually other props do not need to be changed in animation during.
  69409. setTransform: function (key, val) {
  69410. if ("development" !== 'production') {
  69411. assert(hasOwn(TRANSFORM_PROPS_MAP, key), 'Only ' + transformPropNamesStr + ' available in `setTransform`.');
  69412. }
  69413. tmpDuringScope.el[key] = val;
  69414. return this;
  69415. },
  69416. getTransform: function (key) {
  69417. if ("development" !== 'production') {
  69418. assert(hasOwn(TRANSFORM_PROPS_MAP, key), 'Only ' + transformPropNamesStr + ' available in `getTransform`.');
  69419. }
  69420. return tmpDuringScope.el[key];
  69421. },
  69422. setShape: function (key, val) {
  69423. if ("development" !== 'production') {
  69424. assertNotReserved(key);
  69425. }
  69426. var el = tmpDuringScope.el;
  69427. var shape = el.shape || (el.shape = {});
  69428. shape[key] = val;
  69429. el.dirtyShape && el.dirtyShape();
  69430. return this;
  69431. },
  69432. getShape: function (key) {
  69433. if ("development" !== 'production') {
  69434. assertNotReserved(key);
  69435. }
  69436. var shape = tmpDuringScope.el.shape;
  69437. if (shape) {
  69438. return shape[key];
  69439. }
  69440. },
  69441. setStyle: function (key, val) {
  69442. if ("development" !== 'production') {
  69443. assertNotReserved(key);
  69444. }
  69445. var el = tmpDuringScope.el;
  69446. var style = el.style;
  69447. if (style) {
  69448. if ("development" !== 'production') {
  69449. if (eqNaN(val)) {
  69450. warn('style.' + key + ' must not be assigned with NaN.');
  69451. }
  69452. }
  69453. style[key] = val;
  69454. el.dirtyStyle && el.dirtyStyle();
  69455. }
  69456. return this;
  69457. },
  69458. getStyle: function (key) {
  69459. if ("development" !== 'production') {
  69460. assertNotReserved(key);
  69461. }
  69462. var style = tmpDuringScope.el.style;
  69463. if (style) {
  69464. return style[key];
  69465. }
  69466. },
  69467. setExtra: function (key, val) {
  69468. if ("development" !== 'production') {
  69469. assertNotReserved(key);
  69470. }
  69471. var extra = tmpDuringScope.el.extra || (tmpDuringScope.el.extra = {});
  69472. extra[key] = val;
  69473. return this;
  69474. },
  69475. getExtra: function (key) {
  69476. if ("development" !== 'production') {
  69477. assertNotReserved(key);
  69478. }
  69479. var extra = tmpDuringScope.el.extra;
  69480. if (extra) {
  69481. return extra[key];
  69482. }
  69483. }
  69484. };
  69485. function assertNotReserved(key) {
  69486. if ("development" !== 'production') {
  69487. if (key === 'transition' || key === 'enterFrom' || key === 'leaveTo') {
  69488. throw new Error('key must not be "' + key + '"');
  69489. }
  69490. }
  69491. }
  69492. function duringCall() {
  69493. // Do not provide "percent" until some requirements come.
  69494. // Because consider thies case:
  69495. // enterFrom: {x: 100, y: 30}, transition: 'x'.
  69496. // And enter duration is different from update duration.
  69497. // Thus it might be confused about the meaning of "percent" in during callback.
  69498. var scope = this;
  69499. var el = scope.el;
  69500. if (!el) {
  69501. return;
  69502. }
  69503. // If el is remove from zr by reason like legend, during still need to called,
  69504. // because el will be added back to zr and the prop value should not be incorrect.
  69505. var latestUserDuring = transitionInnerStore(el).userDuring;
  69506. var scopeUserDuring = scope.userDuring;
  69507. // Ensured a during is only called once in each animation frame.
  69508. // If a during is called multiple times in one frame, maybe some users' calculation logic
  69509. // might be wrong (not sure whether this usage exists).
  69510. // The case of a during might be called twice can be: by default there is a animator for
  69511. // 'x', 'y' when init. Before the init animation finished, call `setOption` to start
  69512. // another animators for 'style'/'shape'/'extra'.
  69513. if (latestUserDuring !== scopeUserDuring) {
  69514. // release
  69515. scope.el = scope.userDuring = null;
  69516. return;
  69517. }
  69518. tmpDuringScope.el = el;
  69519. // Give no `this` to user in "during" calling.
  69520. scopeUserDuring(transitionDuringAPI);
  69521. // FIXME: if in future meet the case that some prop will be both modified in `during` and `state`,
  69522. // consider the issue that the prop might be incorrect when return to "normal" state.
  69523. }
  69524. function prepareShapeOrExtraTransitionFrom(mainAttr, fromEl, elOption, transFromProps) {
  69525. var attrOpt = elOption[mainAttr];
  69526. if (!attrOpt) {
  69527. return;
  69528. }
  69529. var elPropsInAttr = fromEl[mainAttr];
  69530. var transFromPropsInAttr;
  69531. if (elPropsInAttr) {
  69532. var transition = elOption.transition;
  69533. var attrTransition = attrOpt.transition;
  69534. if (attrTransition) {
  69535. !transFromPropsInAttr && (transFromPropsInAttr = transFromProps[mainAttr] = {});
  69536. if (isTransitionAll(attrTransition)) {
  69537. extend(transFromPropsInAttr, elPropsInAttr);
  69538. } else {
  69539. var transitionKeys = normalizeToArray(attrTransition);
  69540. for (var i = 0; i < transitionKeys.length; i++) {
  69541. var key = transitionKeys[i];
  69542. var elVal = elPropsInAttr[key];
  69543. transFromPropsInAttr[key] = elVal;
  69544. }
  69545. }
  69546. } else if (isTransitionAll(transition) || indexOf(transition, mainAttr) >= 0) {
  69547. !transFromPropsInAttr && (transFromPropsInAttr = transFromProps[mainAttr] = {});
  69548. var elPropsInAttrKeys = keys(elPropsInAttr);
  69549. for (var i = 0; i < elPropsInAttrKeys.length; i++) {
  69550. var key = elPropsInAttrKeys[i];
  69551. var elVal = elPropsInAttr[key];
  69552. if (isNonStyleTransitionEnabled(attrOpt[key], elVal)) {
  69553. transFromPropsInAttr[key] = elVal;
  69554. }
  69555. }
  69556. }
  69557. }
  69558. }
  69559. function prepareShapeOrExtraAllPropsFinal(mainAttr, elOption, allProps) {
  69560. var attrOpt = elOption[mainAttr];
  69561. if (!attrOpt) {
  69562. return;
  69563. }
  69564. var allPropsInAttr = allProps[mainAttr] = {};
  69565. var keysInAttr = keys(attrOpt);
  69566. for (var i = 0; i < keysInAttr.length; i++) {
  69567. var key = keysInAttr[i];
  69568. // To avoid share one object with different element, and
  69569. // to avoid user modify the object inexpectedly, have to clone.
  69570. allPropsInAttr[key] = cloneValue(attrOpt[key]);
  69571. }
  69572. }
  69573. function prepareTransformTransitionFrom(el, elOption, transFromProps) {
  69574. var transition = elOption.transition;
  69575. var transitionKeys = isTransitionAll(transition) ? TRANSFORMABLE_PROPS : normalizeToArray(transition || []);
  69576. for (var i = 0; i < transitionKeys.length; i++) {
  69577. var key = transitionKeys[i];
  69578. if (key === 'style' || key === 'shape' || key === 'extra') {
  69579. continue;
  69580. }
  69581. var elVal = el[key];
  69582. if ("development" !== 'production') {
  69583. checkTransformPropRefer(key, 'el.transition');
  69584. }
  69585. // Do not clone, animator will perform that clone.
  69586. transFromProps[key] = elVal;
  69587. }
  69588. }
  69589. function prepareTransformAllPropsFinal(el, elOption, allProps) {
  69590. for (var i = 0; i < LEGACY_TRANSFORM_PROPS.length; i++) {
  69591. var legacyName = LEGACY_TRANSFORM_PROPS[i];
  69592. var xyName = LEGACY_TRANSFORM_PROPS_MAP[legacyName];
  69593. var legacyArr = elOption[legacyName];
  69594. if (legacyArr) {
  69595. allProps[xyName[0]] = legacyArr[0];
  69596. allProps[xyName[1]] = legacyArr[1];
  69597. }
  69598. }
  69599. for (var i = 0; i < TRANSFORMABLE_PROPS.length; i++) {
  69600. var key = TRANSFORMABLE_PROPS[i];
  69601. if (elOption[key] != null) {
  69602. allProps[key] = elOption[key];
  69603. }
  69604. }
  69605. }
  69606. function prepareStyleTransitionFrom(fromEl, elOption, styleOpt, transFromProps) {
  69607. if (!styleOpt) {
  69608. return;
  69609. }
  69610. var fromElStyle = fromEl.style;
  69611. var transFromStyleProps;
  69612. if (fromElStyle) {
  69613. var styleTransition = styleOpt.transition;
  69614. var elTransition = elOption.transition;
  69615. if (styleTransition && !isTransitionAll(styleTransition)) {
  69616. var transitionKeys = normalizeToArray(styleTransition);
  69617. !transFromStyleProps && (transFromStyleProps = transFromProps.style = {});
  69618. for (var i = 0; i < transitionKeys.length; i++) {
  69619. var key = transitionKeys[i];
  69620. var elVal = fromElStyle[key];
  69621. // Do not clone, see `checkNonStyleTansitionRefer`.
  69622. transFromStyleProps[key] = elVal;
  69623. }
  69624. } else if (fromEl.getAnimationStyleProps && (isTransitionAll(elTransition) || isTransitionAll(styleTransition) || indexOf(elTransition, 'style') >= 0)) {
  69625. var animationProps = fromEl.getAnimationStyleProps();
  69626. var animationStyleProps = animationProps ? animationProps.style : null;
  69627. if (animationStyleProps) {
  69628. !transFromStyleProps && (transFromStyleProps = transFromProps.style = {});
  69629. var styleKeys = keys(styleOpt);
  69630. for (var i = 0; i < styleKeys.length; i++) {
  69631. var key = styleKeys[i];
  69632. if (animationStyleProps[key]) {
  69633. var elVal = fromElStyle[key];
  69634. transFromStyleProps[key] = elVal;
  69635. }
  69636. }
  69637. }
  69638. }
  69639. }
  69640. }
  69641. function isNonStyleTransitionEnabled(optVal, elVal) {
  69642. // The same as `checkNonStyleTansitionRefer`.
  69643. return !isArrayLike(optVal) ? optVal != null && isFinite(optVal) : optVal !== elVal;
  69644. }
  69645. var checkTransformPropRefer;
  69646. if ("development" !== 'production') {
  69647. checkTransformPropRefer = function (key, usedIn) {
  69648. if (!hasOwn(TRANSFORM_PROPS_MAP, key)) {
  69649. warn('Prop `' + key + '` is not a permitted in `' + usedIn + '`. ' + 'Only `' + keys(TRANSFORM_PROPS_MAP).join('`, `') + '` are permitted.');
  69650. }
  69651. };
  69652. }
  69653. var getStateToRestore = makeInner();
  69654. var KEYFRAME_EXCLUDE_KEYS = ['percent', 'easing', 'shape', 'style', 'extra'];
  69655. /**
  69656. * Stop previous keyframe animation and restore the attributes.
  69657. * Avoid new keyframe animation starts with wrong internal state when the percent: 0 is not set.
  69658. */
  69659. function stopPreviousKeyframeAnimationAndRestore(el) {
  69660. // Stop previous keyframe animation.
  69661. el.stopAnimation('keyframe');
  69662. // Restore
  69663. el.attr(getStateToRestore(el));
  69664. }
  69665. function applyKeyframeAnimation(el, animationOpts, animatableModel) {
  69666. if (!animatableModel.isAnimationEnabled() || !animationOpts) {
  69667. return;
  69668. }
  69669. if (isArray(animationOpts)) {
  69670. each(animationOpts, function (singleAnimationOpts) {
  69671. applyKeyframeAnimation(el, singleAnimationOpts, animatableModel);
  69672. });
  69673. return;
  69674. }
  69675. var keyframes = animationOpts.keyframes;
  69676. var duration = animationOpts.duration;
  69677. if (animatableModel && duration == null) {
  69678. // Default to use duration of config.
  69679. // NOTE: animation config from payload will be ignored because they are mainly for transitions.
  69680. var config = getAnimationConfig('enter', animatableModel, 0);
  69681. duration = config && config.duration;
  69682. }
  69683. if (!keyframes || !duration) {
  69684. return;
  69685. }
  69686. var stateToRestore = getStateToRestore(el);
  69687. each(ELEMENT_ANIMATABLE_PROPS, function (targetPropName) {
  69688. if (targetPropName && !el[targetPropName]) {
  69689. return;
  69690. }
  69691. var animator;
  69692. var endFrameIsSet = false;
  69693. // Sort keyframes by percent.
  69694. keyframes.sort(function (a, b) {
  69695. return a.percent - b.percent;
  69696. });
  69697. each(keyframes, function (kf) {
  69698. // Stop current animation.
  69699. var animators = el.animators;
  69700. var kfValues = targetPropName ? kf[targetPropName] : kf;
  69701. if ("development" !== 'production') {
  69702. if (kf.percent >= 1) {
  69703. endFrameIsSet = true;
  69704. }
  69705. }
  69706. if (!kfValues) {
  69707. return;
  69708. }
  69709. var propKeys = keys(kfValues);
  69710. if (!targetPropName) {
  69711. // PENDING performance?
  69712. propKeys = filter(propKeys, function (key) {
  69713. return indexOf(KEYFRAME_EXCLUDE_KEYS, key) < 0;
  69714. });
  69715. }
  69716. if (!propKeys.length) {
  69717. return;
  69718. }
  69719. if (!animator) {
  69720. animator = el.animate(targetPropName, animationOpts.loop, true);
  69721. animator.scope = 'keyframe';
  69722. }
  69723. for (var i = 0; i < animators.length; i++) {
  69724. // Stop all other animation that is not keyframe.
  69725. if (animators[i] !== animator && animators[i].targetName === animator.targetName) {
  69726. animators[i].stopTracks(propKeys);
  69727. }
  69728. }
  69729. targetPropName && (stateToRestore[targetPropName] = stateToRestore[targetPropName] || {});
  69730. var savedTarget = targetPropName ? stateToRestore[targetPropName] : stateToRestore;
  69731. each(propKeys, function (key) {
  69732. // Save original value.
  69733. savedTarget[key] = ((targetPropName ? el[targetPropName] : el) || {})[key];
  69734. });
  69735. animator.whenWithKeys(duration * kf.percent, kfValues, propKeys, kf.easing);
  69736. });
  69737. if (!animator) {
  69738. return;
  69739. }
  69740. if ("development" !== 'production') {
  69741. if (!endFrameIsSet) {
  69742. warn('End frame with percent: 1 is missing in the keyframeAnimation.', true);
  69743. }
  69744. }
  69745. animator.delay(animationOpts.delay || 0).duration(duration).start(animationOpts.easing);
  69746. });
  69747. }
  69748. var EMPHASIS = 'emphasis';
  69749. var NORMAL = 'normal';
  69750. var BLUR = 'blur';
  69751. var SELECT = 'select';
  69752. var STATES = [NORMAL, EMPHASIS, BLUR, SELECT];
  69753. var PATH_ITEM_STYLE = {
  69754. normal: ['itemStyle'],
  69755. emphasis: [EMPHASIS, 'itemStyle'],
  69756. blur: [BLUR, 'itemStyle'],
  69757. select: [SELECT, 'itemStyle']
  69758. };
  69759. var PATH_LABEL = {
  69760. normal: ['label'],
  69761. emphasis: [EMPHASIS, 'label'],
  69762. blur: [BLUR, 'label'],
  69763. select: [SELECT, 'label']
  69764. };
  69765. var DEFAULT_TRANSITION = ['x', 'y'];
  69766. // Use prefix to avoid index to be the same as el.name,
  69767. // which will cause weird update animation.
  69768. var GROUP_DIFF_PREFIX = 'e\0\0';
  69769. var attachedTxInfoTmp = {
  69770. normal: {},
  69771. emphasis: {},
  69772. blur: {},
  69773. select: {}
  69774. };
  69775. /**
  69776. * FIXME: register rather than import directly, for size.
  69777. *
  69778. * To reduce total package size of each coordinate systems, the modules `prepareCustom`
  69779. * of each coordinate systems are not required by each coordinate systems directly, but
  69780. * required by the module `custom`.
  69781. *
  69782. * prepareInfoForCustomSeries {Function}: optional
  69783. * @return {Object} {coordSys: {...}, api: {
  69784. * coord: function (data, clamp) {}, // return point in global.
  69785. * size: function (dataSize, dataItem) {} // return size of each axis in coordSys.
  69786. * }}
  69787. */
  69788. var prepareCustoms = {
  69789. cartesian2d: cartesianPrepareCustom,
  69790. geo: geoPrepareCustom,
  69791. single: singlePrepareCustom,
  69792. polar: polarPrepareCustom,
  69793. calendar: calendarPrepareCustom,
  69794. matrix: matrixPrepareCustom
  69795. };
  69796. function isPath$1(el) {
  69797. return el instanceof Path;
  69798. }
  69799. function isDisplayable(el) {
  69800. return el instanceof Displayable;
  69801. }
  69802. function copyElement(sourceEl, targetEl) {
  69803. targetEl.copyTransform(sourceEl);
  69804. if (isDisplayable(targetEl) && isDisplayable(sourceEl)) {
  69805. targetEl.setStyle(sourceEl.style);
  69806. targetEl.z = sourceEl.z;
  69807. targetEl.z2 = sourceEl.z2;
  69808. targetEl.zlevel = sourceEl.zlevel;
  69809. targetEl.invisible = sourceEl.invisible;
  69810. targetEl.ignore = sourceEl.ignore;
  69811. if (isPath$1(targetEl) && isPath$1(sourceEl)) {
  69812. targetEl.setShape(sourceEl.shape);
  69813. }
  69814. }
  69815. }
  69816. var CustomChartView = /** @class */function (_super) {
  69817. __extends(CustomChartView, _super);
  69818. function CustomChartView() {
  69819. var _this = _super !== null && _super.apply(this, arguments) || this;
  69820. _this.type = CustomChartView.type;
  69821. return _this;
  69822. }
  69823. CustomChartView.prototype.render = function (customSeries, ecModel, api, payload) {
  69824. // Clear previously rendered progressive elements.
  69825. this._progressiveEls = null;
  69826. var oldData = this._data;
  69827. var data = customSeries.getData();
  69828. var group = this.group;
  69829. var renderItem = makeRenderItem(customSeries, data, ecModel, api);
  69830. if (!oldData) {
  69831. // Previous render is incremental render or first render.
  69832. // Needs remove the incremental rendered elements.
  69833. group.removeAll();
  69834. }
  69835. data.diff(oldData).add(function (newIdx) {
  69836. createOrUpdateItem(api, null, newIdx, renderItem(newIdx, payload), customSeries, group, data);
  69837. }).remove(function (oldIdx) {
  69838. var el = oldData.getItemGraphicEl(oldIdx);
  69839. el && applyLeaveTransition(el, customInnerStore(el).option, customSeries);
  69840. }).update(function (newIdx, oldIdx) {
  69841. var oldEl = oldData.getItemGraphicEl(oldIdx);
  69842. createOrUpdateItem(api, oldEl, newIdx, renderItem(newIdx, payload), customSeries, group, data);
  69843. }).execute();
  69844. // Do clipping
  69845. var clipPath = customSeries.get('clip', true) ? createClipPath(customSeries.coordinateSystem, false, customSeries) : null;
  69846. if (clipPath) {
  69847. group.setClipPath(clipPath);
  69848. } else {
  69849. group.removeClipPath();
  69850. }
  69851. this._data = data;
  69852. };
  69853. CustomChartView.prototype.incrementalPrepareRender = function (customSeries, ecModel, api) {
  69854. this.group.removeAll();
  69855. this._data = null;
  69856. };
  69857. CustomChartView.prototype.incrementalRender = function (params, customSeries, ecModel, api, payload) {
  69858. var data = customSeries.getData();
  69859. var renderItem = makeRenderItem(customSeries, data, ecModel, api);
  69860. var progressiveEls = this._progressiveEls = [];
  69861. function setIncrementalAndHoverLayer(el) {
  69862. if (!el.isGroup) {
  69863. el.incremental = true;
  69864. el.ensureState('emphasis').hoverLayer = true;
  69865. }
  69866. }
  69867. for (var idx = params.start; idx < params.end; idx++) {
  69868. var el = createOrUpdateItem(null, null, idx, renderItem(idx, payload), customSeries, this.group, data);
  69869. if (el) {
  69870. el.traverse(setIncrementalAndHoverLayer);
  69871. progressiveEls.push(el);
  69872. }
  69873. }
  69874. };
  69875. CustomChartView.prototype.eachRendered = function (cb) {
  69876. traverseElements(this._progressiveEls || this.group, cb);
  69877. };
  69878. CustomChartView.prototype.filterForExposedEvent = function (eventType, query, targetEl, packedEvent) {
  69879. var elementName = query.element;
  69880. if (elementName == null || targetEl.name === elementName) {
  69881. return true;
  69882. }
  69883. // Enable to give a name on a group made by `renderItem`, and listen
  69884. // events that are triggered by its descendents.
  69885. while ((targetEl = targetEl.__hostTarget || targetEl.parent) && targetEl !== this.group) {
  69886. if (targetEl.name === elementName) {
  69887. return true;
  69888. }
  69889. }
  69890. return false;
  69891. };
  69892. CustomChartView.type = 'custom';
  69893. return CustomChartView;
  69894. }(ChartView);
  69895. function createEl(elOption) {
  69896. var graphicType = elOption.type;
  69897. var el;
  69898. // Those graphic elements are not shapes. They should not be
  69899. // overwritten by users, so do them first.
  69900. if (graphicType === 'path') {
  69901. var shape = elOption.shape;
  69902. // Using pathRect brings convenience to users sacle svg path.
  69903. var pathRect = shape.width != null && shape.height != null ? {
  69904. x: shape.x || 0,
  69905. y: shape.y || 0,
  69906. width: shape.width,
  69907. height: shape.height
  69908. } : null;
  69909. var pathData = getPathData(shape);
  69910. // Path is also used for icon, so layout 'center' by default.
  69911. el = makePath(pathData, null, pathRect, shape.layout || 'center');
  69912. customInnerStore(el).customPathData = pathData;
  69913. } else if (graphicType === 'image') {
  69914. el = new ZRImage({});
  69915. customInnerStore(el).customImagePath = elOption.style.image;
  69916. } else if (graphicType === 'text') {
  69917. el = new ZRText({});
  69918. // customInnerStore(el).customText = (elOption.style as TextStyleProps).text;
  69919. } else if (graphicType === 'group') {
  69920. el = new Group();
  69921. } else if (graphicType === 'compoundPath') {
  69922. var shape = elOption.shape;
  69923. if (!shape || !shape.paths) {
  69924. var errMsg = '';
  69925. if ("development" !== 'production') {
  69926. errMsg = 'shape.paths must be specified in compoundPath';
  69927. }
  69928. throwError(errMsg);
  69929. }
  69930. var paths = map(shape.paths, function (path) {
  69931. if (path.type === 'path') {
  69932. return makePath(path.shape.pathData, path, null);
  69933. }
  69934. var Clz = getShapeClass(path.type);
  69935. if (!Clz) {
  69936. var errMsg = '';
  69937. if ("development" !== 'production') {
  69938. errMsg = 'graphic type "' + graphicType + '" can not be found.';
  69939. }
  69940. throwError(errMsg);
  69941. }
  69942. return new Clz();
  69943. });
  69944. el = new CompoundPath({
  69945. shape: {
  69946. paths: paths
  69947. }
  69948. });
  69949. } else {
  69950. var Clz = getShapeClass(graphicType);
  69951. if (!Clz) {
  69952. var errMsg = '';
  69953. if ("development" !== 'production') {
  69954. errMsg = 'graphic type "' + graphicType + '" can not be found.';
  69955. }
  69956. throwError(errMsg);
  69957. }
  69958. el = new Clz();
  69959. }
  69960. customInnerStore(el).customGraphicType = graphicType;
  69961. el.name = elOption.name;
  69962. // Compat ec4: the default z2 lift is 1. If changing the number,
  69963. // some cases probably be broken: hierarchy layout along z, like circle packing,
  69964. // where emphasis only intending to modify color/border rather than lift z2.
  69965. el.z2EmphasisLift = 1;
  69966. el.z2SelectLift = 1;
  69967. return el;
  69968. }
  69969. function updateElNormal(
  69970. // Can be null/undefined
  69971. api, el, dataIndex, elOption, attachedTxInfo, seriesModel, isInit) {
  69972. // Stop and restore before update any other attributes.
  69973. stopPreviousKeyframeAnimationAndRestore(el);
  69974. var txCfgOpt = attachedTxInfo && attachedTxInfo.normal.cfg;
  69975. if (txCfgOpt) {
  69976. // PENDING: whether use user object directly rather than clone?
  69977. // TODO:5.0 textConfig transition animation?
  69978. el.setTextConfig(txCfgOpt);
  69979. }
  69980. // Default transition ['x', 'y']
  69981. if (elOption && elOption.transition == null) {
  69982. elOption.transition = DEFAULT_TRANSITION;
  69983. }
  69984. // Do some normalization on style.
  69985. var styleOpt = elOption && elOption.style;
  69986. if (styleOpt) {
  69987. if (el.type === 'text') {
  69988. var textOptionStyle = styleOpt;
  69989. // Compatible with ec4: if `textFill` or `textStroke` exists use them.
  69990. hasOwn(textOptionStyle, 'textFill') && (textOptionStyle.fill = textOptionStyle.textFill);
  69991. hasOwn(textOptionStyle, 'textStroke') && (textOptionStyle.stroke = textOptionStyle.textStroke);
  69992. }
  69993. var decalPattern = void 0;
  69994. var decalObj = isPath$1(el) ? styleOpt.decal : null;
  69995. if (api && decalObj) {
  69996. decalObj.dirty = true;
  69997. decalPattern = createOrUpdatePatternFromDecal(decalObj, api);
  69998. }
  69999. // Always overwrite in case user specify this prop.
  70000. styleOpt.__decalPattern = decalPattern;
  70001. }
  70002. if (isDisplayable(el)) {
  70003. if (styleOpt) {
  70004. var decalPattern = styleOpt.__decalPattern;
  70005. if (decalPattern) {
  70006. styleOpt.decal = decalPattern;
  70007. }
  70008. }
  70009. }
  70010. applyUpdateTransition(el, elOption, seriesModel, {
  70011. dataIndex: dataIndex,
  70012. isInit: isInit,
  70013. clearStyle: true
  70014. });
  70015. applyKeyframeAnimation(el, elOption.keyframeAnimation, seriesModel);
  70016. }
  70017. function updateElOnState(state, el, elStateOpt, styleOpt, attachedTxInfo) {
  70018. var elDisplayable = el.isGroup ? null : el;
  70019. var txCfgOpt = attachedTxInfo && attachedTxInfo[state].cfg;
  70020. // PENDING:5.0 support customize scale change and transition animation?
  70021. if (elDisplayable) {
  70022. // By default support auto lift color when hover whether `emphasis` specified.
  70023. var stateObj = elDisplayable.ensureState(state);
  70024. if (styleOpt === false) {
  70025. var existingEmphasisState = elDisplayable.getState(state);
  70026. if (existingEmphasisState) {
  70027. existingEmphasisState.style = null;
  70028. }
  70029. } else {
  70030. // style is needed to enable default emphasis.
  70031. stateObj.style = styleOpt || null;
  70032. }
  70033. // If `elOption.styleEmphasis` or `elOption.emphasis.style` is `false`,
  70034. // remove hover style.
  70035. // If `elOption.textConfig` or `elOption.emphasis.textConfig` is null/undefined, it does not
  70036. // make sense. So for simplicity, we do not ditinguish `hasOwnProperty` and null/undefined.
  70037. if (txCfgOpt) {
  70038. stateObj.textConfig = txCfgOpt;
  70039. }
  70040. setDefaultStateProxy(elDisplayable);
  70041. }
  70042. }
  70043. function updateZ$1(el, elOption, seriesModel) {
  70044. // Group not support textContent and not support z yet.
  70045. if (el.isGroup) {
  70046. return;
  70047. }
  70048. var elDisplayable = el;
  70049. var currentZ = seriesModel.currentZ;
  70050. var currentZLevel = seriesModel.currentZLevel;
  70051. // Always erase.
  70052. elDisplayable.z = currentZ;
  70053. elDisplayable.zlevel = currentZLevel;
  70054. // z2 must not be null/undefined, otherwise sort error may occur.
  70055. var optZ2 = elOption.z2;
  70056. optZ2 != null && (elDisplayable.z2 = optZ2 || 0);
  70057. for (var i = 0; i < STATES.length; i++) {
  70058. updateZForEachState(elDisplayable, elOption, STATES[i]);
  70059. }
  70060. }
  70061. function updateZForEachState(elDisplayable, elOption, state) {
  70062. var isNormal = state === NORMAL;
  70063. var elStateOpt = isNormal ? elOption : retrieveStateOption(elOption, state);
  70064. var optZ2 = elStateOpt ? elStateOpt.z2 : null;
  70065. var stateObj;
  70066. if (optZ2 != null) {
  70067. // Do not `ensureState` until required.
  70068. stateObj = isNormal ? elDisplayable : elDisplayable.ensureState(state);
  70069. stateObj.z2 = optZ2 || 0;
  70070. }
  70071. }
  70072. function makeRenderItem(customSeries, data, ecModel, api) {
  70073. var renderItem = customSeries.get('renderItem');
  70074. if (typeof renderItem === 'string') {
  70075. // Find renderItem in registered custom series
  70076. var registeredRenderItem = getCustomSeries(renderItem);
  70077. if (registeredRenderItem) {
  70078. renderItem = registeredRenderItem;
  70079. } else if ("development" !== 'production') {
  70080. console.warn("Custom series renderItem '" + renderItem + "' not found.\n Call 'echarts.registerCustomSeries' to register it.");
  70081. }
  70082. }
  70083. var coordSys = customSeries.coordinateSystem;
  70084. var prepareResult = {};
  70085. if (coordSys) {
  70086. if ("development" !== 'production') {
  70087. assert(renderItem, 'series.render is required.');
  70088. assert(coordSys.prepareCustoms || prepareCustoms[coordSys.type], 'This coordSys does not support custom series.');
  70089. }
  70090. // `coordSys.prepareCustoms` is used for external coord sys like bmap.
  70091. prepareResult = coordSys.prepareCustoms ? coordSys.prepareCustoms(coordSys) : prepareCustoms[coordSys.type](coordSys);
  70092. }
  70093. var userAPI = defaults({
  70094. getWidth: api.getWidth,
  70095. getHeight: api.getHeight,
  70096. getZr: api.getZr,
  70097. getDevicePixelRatio: api.getDevicePixelRatio,
  70098. value: value,
  70099. style: style,
  70100. ordinalRawValue: ordinalRawValue,
  70101. styleEmphasis: styleEmphasis,
  70102. visual: visual,
  70103. barLayout: barLayout,
  70104. currentSeriesIndices: currentSeriesIndices,
  70105. font: font
  70106. }, prepareResult.api || {});
  70107. var userParams = {
  70108. // The life cycle of context: current round of rendering.
  70109. // The global life cycle is probably not necessary, because
  70110. // user can store global status by themselves.
  70111. context: {},
  70112. seriesId: customSeries.id,
  70113. seriesName: customSeries.name,
  70114. seriesIndex: customSeries.seriesIndex,
  70115. coordSys: prepareResult.coordSys,
  70116. dataInsideLength: data.count(),
  70117. encode: wrapEncodeDef(customSeries.getData()),
  70118. itemPayload: customSeries.get('itemPayload') || {}
  70119. };
  70120. // If someday intending to refactor them to a class, should consider do not
  70121. // break change: currently these attribute member are encapsulated in a closure
  70122. // so that do not need to force user to call these method with a scope.
  70123. // Do not support call `api` asynchronously without dataIndexInside input.
  70124. var currDataIndexInside;
  70125. var currItemModel;
  70126. var currItemStyleModels = {};
  70127. var currLabelModels = {};
  70128. var seriesItemStyleModels = {};
  70129. var seriesLabelModels = {};
  70130. for (var i = 0; i < STATES.length; i++) {
  70131. var stateName = STATES[i];
  70132. seriesItemStyleModels[stateName] = customSeries.getModel(PATH_ITEM_STYLE[stateName]);
  70133. seriesLabelModels[stateName] = customSeries.getModel(PATH_LABEL[stateName]);
  70134. }
  70135. function getItemModel(dataIndexInside) {
  70136. return dataIndexInside === currDataIndexInside ? currItemModel || (currItemModel = data.getItemModel(dataIndexInside)) : data.getItemModel(dataIndexInside);
  70137. }
  70138. function getItemStyleModel(dataIndexInside, state) {
  70139. return !data.hasItemOption ? seriesItemStyleModels[state] : dataIndexInside === currDataIndexInside ? currItemStyleModels[state] || (currItemStyleModels[state] = getItemModel(dataIndexInside).getModel(PATH_ITEM_STYLE[state])) : getItemModel(dataIndexInside).getModel(PATH_ITEM_STYLE[state]);
  70140. }
  70141. function getLabelModel(dataIndexInside, state) {
  70142. return !data.hasItemOption ? seriesLabelModels[state] : dataIndexInside === currDataIndexInside ? currLabelModels[state] || (currLabelModels[state] = getItemModel(dataIndexInside).getModel(PATH_LABEL[state])) : getItemModel(dataIndexInside).getModel(PATH_LABEL[state]);
  70143. }
  70144. return function (dataIndexInside, payload) {
  70145. currDataIndexInside = dataIndexInside;
  70146. currItemModel = null;
  70147. currItemStyleModels = {};
  70148. currLabelModels = {};
  70149. return renderItem && renderItem(defaults({
  70150. dataIndexInside: dataIndexInside,
  70151. dataIndex: data.getRawIndex(dataIndexInside),
  70152. // Can be used for optimization when zoom or roam.
  70153. actionType: payload ? payload.type : null
  70154. }, userParams), userAPI);
  70155. };
  70156. /**
  70157. * @public
  70158. * @param dim by default 0.
  70159. * @param dataIndexInside by default `currDataIndexInside`.
  70160. */
  70161. function value(dim, dataIndexInside) {
  70162. dataIndexInside == null && (dataIndexInside = currDataIndexInside);
  70163. return data.getStore().get(data.getDimensionIndex(dim || 0), dataIndexInside);
  70164. }
  70165. /**
  70166. * @public
  70167. * @param dim by default 0.
  70168. * @param dataIndexInside by default `currDataIndexInside`.
  70169. */
  70170. function ordinalRawValue(dim, dataIndexInside) {
  70171. dataIndexInside == null && (dataIndexInside = currDataIndexInside);
  70172. dim = dim || 0;
  70173. var dimInfo = data.getDimensionInfo(dim);
  70174. if (!dimInfo) {
  70175. var dimIndex = data.getDimensionIndex(dim);
  70176. return dimIndex >= 0 ? data.getStore().get(dimIndex, dataIndexInside) : undefined;
  70177. }
  70178. var val = data.get(dimInfo.name, dataIndexInside);
  70179. var ordinalMeta = dimInfo && dimInfo.ordinalMeta;
  70180. return ordinalMeta ? ordinalMeta.categories[val] : val;
  70181. }
  70182. /**
  70183. * @deprecated The original intention of `api.style` is enable to set itemStyle
  70184. * like other series. But it is not necessary and not easy to give a strict definition
  70185. * of what it returns. And since echarts5 it needs to be make compat work. So
  70186. * deprecates it since echarts5.
  70187. *
  70188. * By default, `visual` is applied to style (to support visualMap).
  70189. * `visual.color` is applied at `fill`. If user want apply visual.color on `stroke`,
  70190. * it can be implemented as:
  70191. * `api.style({stroke: api.visual('color'), fill: null})`;
  70192. *
  70193. * [Compat]: since ec5, RectText has been separated from its hosts el.
  70194. * so `api.style()` will only return the style from `itemStyle` but not handle `label`
  70195. * any more. But `series.label` config is never published in doc.
  70196. * We still compat it in `api.style()`. But not encourage to use it and will still not
  70197. * to pulish it to doc.
  70198. * @public
  70199. * @param dataIndexInside by default `currDataIndexInside`.
  70200. */
  70201. function style(userProps, dataIndexInside) {
  70202. if ("development" !== 'production') {
  70203. warnDeprecated('api.style', 'Please write literal style directly instead.');
  70204. }
  70205. dataIndexInside == null && (dataIndexInside = currDataIndexInside);
  70206. var style = data.getItemVisual(dataIndexInside, 'style');
  70207. var visualColor = style && style.fill;
  70208. var opacity = style && style.opacity;
  70209. var itemStyle = getItemStyleModel(dataIndexInside, NORMAL).getItemStyle();
  70210. visualColor != null && (itemStyle.fill = visualColor);
  70211. opacity != null && (itemStyle.opacity = opacity);
  70212. var opt = {
  70213. inheritColor: isString(visualColor) ? visualColor : tokens.color.neutral99
  70214. };
  70215. var labelModel = getLabelModel(dataIndexInside, NORMAL);
  70216. // Now that the feature of "auto adjust text fill/stroke" has been migrated to zrender
  70217. // since ec5, we should set `isAttached` as `false` here and make compat in
  70218. // `convertToEC4StyleForCustomSerise`.
  70219. var textStyle = createTextStyle(labelModel, null, opt, false, true);
  70220. textStyle.text = labelModel.getShallow('show') ? retrieve2(customSeries.getFormattedLabel(dataIndexInside, NORMAL), getDefaultLabel(data, dataIndexInside)) : null;
  70221. var textConfig = createTextConfig(labelModel, opt, false);
  70222. preFetchFromExtra(userProps, itemStyle);
  70223. itemStyle = convertToEC4StyleForCustomSerise(itemStyle, textStyle, textConfig);
  70224. userProps && applyUserPropsAfter(itemStyle, userProps);
  70225. itemStyle.legacy = true;
  70226. return itemStyle;
  70227. }
  70228. /**
  70229. * @deprecated The reason see `api.style()`
  70230. * @public
  70231. * @param dataIndexInside by default `currDataIndexInside`.
  70232. */
  70233. function styleEmphasis(userProps, dataIndexInside) {
  70234. if ("development" !== 'production') {
  70235. warnDeprecated('api.styleEmphasis', 'Please write literal style directly instead.');
  70236. }
  70237. dataIndexInside == null && (dataIndexInside = currDataIndexInside);
  70238. var itemStyle = getItemStyleModel(dataIndexInside, EMPHASIS).getItemStyle();
  70239. var labelModel = getLabelModel(dataIndexInside, EMPHASIS);
  70240. var textStyle = createTextStyle(labelModel, null, null, true, true);
  70241. textStyle.text = labelModel.getShallow('show') ? retrieve3(customSeries.getFormattedLabel(dataIndexInside, EMPHASIS), customSeries.getFormattedLabel(dataIndexInside, NORMAL), getDefaultLabel(data, dataIndexInside)) : null;
  70242. var textConfig = createTextConfig(labelModel, null, true);
  70243. preFetchFromExtra(userProps, itemStyle);
  70244. itemStyle = convertToEC4StyleForCustomSerise(itemStyle, textStyle, textConfig);
  70245. userProps && applyUserPropsAfter(itemStyle, userProps);
  70246. itemStyle.legacy = true;
  70247. return itemStyle;
  70248. }
  70249. function applyUserPropsAfter(itemStyle, extra) {
  70250. for (var key in extra) {
  70251. if (hasOwn(extra, key)) {
  70252. itemStyle[key] = extra[key];
  70253. }
  70254. }
  70255. }
  70256. function preFetchFromExtra(extra, itemStyle) {
  70257. // A trick to retrieve those props firstly, which are used to
  70258. // apply auto inside fill/stroke in `convertToEC4StyleForCustomSerise`.
  70259. // (It's not reasonable but only for a degree of compat)
  70260. if (extra) {
  70261. extra.textFill && (itemStyle.textFill = extra.textFill);
  70262. extra.textPosition && (itemStyle.textPosition = extra.textPosition);
  70263. }
  70264. }
  70265. /**
  70266. * @public
  70267. * @param dataIndexInside by default `currDataIndexInside`.
  70268. */
  70269. function visual(visualType, dataIndexInside) {
  70270. dataIndexInside == null && (dataIndexInside = currDataIndexInside);
  70271. if (hasOwn(STYLE_VISUAL_TYPE, visualType)) {
  70272. var style_1 = data.getItemVisual(dataIndexInside, 'style');
  70273. return style_1 ? style_1[STYLE_VISUAL_TYPE[visualType]] : null;
  70274. }
  70275. // Only support these visuals. Other visual might be inner tricky
  70276. // for performance (like `style`), do not expose to users.
  70277. if (hasOwn(NON_STYLE_VISUAL_PROPS, visualType)) {
  70278. return data.getItemVisual(dataIndexInside, visualType);
  70279. }
  70280. }
  70281. /**
  70282. * @public
  70283. * @return If not support, return undefined.
  70284. */
  70285. function barLayout(opt) {
  70286. if (coordSys.type === 'cartesian2d') {
  70287. var baseAxis = coordSys.getBaseAxis();
  70288. return getLayoutOnAxis(defaults({
  70289. axis: baseAxis
  70290. }, opt));
  70291. }
  70292. }
  70293. /**
  70294. * @public
  70295. */
  70296. function currentSeriesIndices() {
  70297. return ecModel.getCurrentSeriesIndices();
  70298. }
  70299. /**
  70300. * @public
  70301. * @return font string
  70302. */
  70303. function font(opt) {
  70304. return getFont(opt, ecModel);
  70305. }
  70306. }
  70307. function wrapEncodeDef(data) {
  70308. var encodeDef = {};
  70309. each(data.dimensions, function (dimName) {
  70310. var dimInfo = data.getDimensionInfo(dimName);
  70311. if (!dimInfo.isExtraCoord) {
  70312. var coordDim = dimInfo.coordDim;
  70313. var dataDims = encodeDef[coordDim] = encodeDef[coordDim] || [];
  70314. dataDims[dimInfo.coordDimIndex] = data.getDimensionIndex(dimName);
  70315. }
  70316. });
  70317. return encodeDef;
  70318. }
  70319. function createOrUpdateItem(api, existsEl, dataIndex, elOption, seriesModel, group, data) {
  70320. // [Rule]
  70321. // If `renderItem` returns `null`/`undefined`/`false`, remove the previous el if existing.
  70322. // (It seems that violate the "merge" principle, but most of users probably intuitively
  70323. // regard "return;" as "show nothing element whatever", so make a exception to meet the
  70324. // most cases.)
  70325. // The rule or "merge" see [STRATEGY_MERGE].
  70326. // If `elOption` is `null`/`undefined`/`false` (when `renderItem` returns nothing).
  70327. if (!elOption) {
  70328. group.remove(existsEl);
  70329. return;
  70330. }
  70331. var el = doCreateOrUpdateEl(api, existsEl, dataIndex, elOption, seriesModel, group);
  70332. el && data.setItemGraphicEl(dataIndex, el);
  70333. el && toggleHoverEmphasis(el, elOption.focus, elOption.blurScope, elOption.emphasisDisabled);
  70334. return el;
  70335. }
  70336. function doCreateOrUpdateEl(api, existsEl, dataIndex, elOption, seriesModel, group) {
  70337. if ("development" !== 'production') {
  70338. assert(elOption, 'should not have an null/undefined element setting');
  70339. }
  70340. var toBeReplacedIdx = -1;
  70341. var oldEl = existsEl;
  70342. if (existsEl && doesElNeedRecreate(existsEl, elOption, seriesModel)
  70343. // || (
  70344. // // PENDING: even in one-to-one mapping case, if el is marked as morph,
  70345. // // do not sure whether the el will be mapped to another el with different
  70346. // // hierarchy in Group tree. So always recreate el rather than reuse the el.
  70347. // morphHelper && morphHelper.isOneToOneFrom(el)
  70348. // )
  70349. ) {
  70350. // Should keep at the original index, otherwise "merge by index" will be incorrect.
  70351. toBeReplacedIdx = indexOf(group.childrenRef(), existsEl);
  70352. existsEl = null;
  70353. }
  70354. var isInit = !existsEl;
  70355. var el = existsEl;
  70356. if (!el) {
  70357. el = createEl(elOption);
  70358. if (oldEl) {
  70359. copyElement(oldEl, el);
  70360. }
  70361. } else {
  70362. // FIMXE:NEXT unified clearState?
  70363. // If in some case the performance issue arised, consider
  70364. // do not clearState but update cached normal state directly.
  70365. el.clearStates();
  70366. }
  70367. // Need to set morph: false explictly to disable automatically morphing.
  70368. if (elOption.morph === false) {
  70369. el.disableMorphing = true;
  70370. } else if (el.disableMorphing) {
  70371. el.disableMorphing = false;
  70372. }
  70373. if (elOption.tooltipDisabled) {
  70374. el.tooltipDisabled = true;
  70375. }
  70376. attachedTxInfoTmp.normal.cfg = attachedTxInfoTmp.normal.conOpt = attachedTxInfoTmp.emphasis.cfg = attachedTxInfoTmp.emphasis.conOpt = attachedTxInfoTmp.blur.cfg = attachedTxInfoTmp.blur.conOpt = attachedTxInfoTmp.select.cfg = attachedTxInfoTmp.select.conOpt = null;
  70377. attachedTxInfoTmp.isLegacy = false;
  70378. doCreateOrUpdateAttachedTx(el, dataIndex, elOption, seriesModel, isInit, attachedTxInfoTmp);
  70379. doCreateOrUpdateClipPath(el, dataIndex, elOption, seriesModel, isInit);
  70380. updateElNormal(api, el, dataIndex, elOption, attachedTxInfoTmp, seriesModel, isInit);
  70381. // `elOption.info` enables user to mount some info on
  70382. // elements and use them in event handlers.
  70383. // Update them only when user specified, otherwise, remain.
  70384. hasOwn(elOption, 'info') && (customInnerStore(el).info = elOption.info);
  70385. for (var i = 0; i < STATES.length; i++) {
  70386. var stateName = STATES[i];
  70387. if (stateName !== NORMAL) {
  70388. var otherStateOpt = retrieveStateOption(elOption, stateName);
  70389. var otherStyleOpt = retrieveStyleOptionOnState(elOption, otherStateOpt, stateName);
  70390. updateElOnState(stateName, el, otherStateOpt, otherStyleOpt, attachedTxInfoTmp);
  70391. }
  70392. }
  70393. updateZ$1(el, elOption, seriesModel);
  70394. if (elOption.type === 'group') {
  70395. mergeChildren(api, el, dataIndex, elOption, seriesModel);
  70396. }
  70397. if (toBeReplacedIdx >= 0) {
  70398. group.replaceAt(el, toBeReplacedIdx);
  70399. } else {
  70400. group.add(el);
  70401. }
  70402. return el;
  70403. }
  70404. // `el` must not be null/undefined.
  70405. function doesElNeedRecreate(el, elOption, seriesModel) {
  70406. var elInner = customInnerStore(el);
  70407. var elOptionType = elOption.type;
  70408. var elOptionShape = elOption.shape;
  70409. var elOptionStyle = elOption.style;
  70410. return (
  70411. // Always create new if universal transition is enabled.
  70412. // Because we do transition after render. It needs to know what old element is. Replacement will loose it.
  70413. seriesModel.isUniversalTransitionEnabled()
  70414. // If `elOptionType` is `null`, follow the merge principle.
  70415. || elOptionType != null && elOptionType !== elInner.customGraphicType || elOptionType === 'path' && hasOwnPathData(elOptionShape) && getPathData(elOptionShape) !== elInner.customPathData || elOptionType === 'image' && hasOwn(elOptionStyle, 'image') && elOptionStyle.image !== elInner.customImagePath
  70416. // // FIXME test and remove this restriction?
  70417. // || (elOptionType === 'text'
  70418. // && hasOwn(elOptionStyle, 'text')
  70419. // && (elOptionStyle as TextStyleProps).text !== elInner.customText
  70420. // )
  70421. );
  70422. }
  70423. function doCreateOrUpdateClipPath(el, dataIndex, elOption, seriesModel, isInit) {
  70424. // Based on the "merge" principle, if no clipPath provided,
  70425. // do nothing. The exists clip will be totally removed only if
  70426. // `el.clipPath` is `false`. Otherwise it will be merged/replaced.
  70427. var clipPathOpt = elOption.clipPath;
  70428. if (clipPathOpt === false) {
  70429. if (el && el.getClipPath()) {
  70430. el.removeClipPath();
  70431. }
  70432. } else if (clipPathOpt) {
  70433. var clipPath = el.getClipPath();
  70434. if (clipPath && doesElNeedRecreate(clipPath, clipPathOpt, seriesModel)) {
  70435. clipPath = null;
  70436. }
  70437. if (!clipPath) {
  70438. clipPath = createEl(clipPathOpt);
  70439. if ("development" !== 'production') {
  70440. assert(isPath$1(clipPath), 'Only any type of `path` can be used in `clipPath`, rather than ' + clipPath.type + '.');
  70441. }
  70442. el.setClipPath(clipPath);
  70443. }
  70444. updateElNormal(null, clipPath, dataIndex, clipPathOpt, null, seriesModel, isInit);
  70445. }
  70446. // If not define `clipPath` in option, do nothing unnecessary.
  70447. }
  70448. function doCreateOrUpdateAttachedTx(el, dataIndex, elOption, seriesModel, isInit, attachedTxInfo) {
  70449. // Group does not support textContent temporarily until necessary.
  70450. if (el.isGroup || el.type === 'compoundPath') {
  70451. return;
  70452. }
  70453. // Normal must be called before emphasis, for `isLegacy` detection.
  70454. processTxInfo(elOption, null, attachedTxInfo);
  70455. processTxInfo(elOption, EMPHASIS, attachedTxInfo);
  70456. // If `elOption.textConfig` or `elOption.textContent` is null/undefined, it does not make sense.
  70457. // So for simplicity, if "elOption hasOwnProperty of them but be null/undefined", we do not
  70458. // trade them as set to null to el.
  70459. // Especially:
  70460. // `elOption.textContent: false` means remove textContent.
  70461. // `elOption.textContent.emphasis.style: false` means remove the style from emphasis state.
  70462. var txConOptNormal = attachedTxInfo.normal.conOpt;
  70463. var txConOptEmphasis = attachedTxInfo.emphasis.conOpt;
  70464. var txConOptBlur = attachedTxInfo.blur.conOpt;
  70465. var txConOptSelect = attachedTxInfo.select.conOpt;
  70466. if (txConOptNormal != null || txConOptEmphasis != null || txConOptSelect != null || txConOptBlur != null) {
  70467. var textContent = el.getTextContent();
  70468. if (txConOptNormal === false) {
  70469. textContent && el.removeTextContent();
  70470. } else {
  70471. txConOptNormal = attachedTxInfo.normal.conOpt = txConOptNormal || {
  70472. type: 'text'
  70473. };
  70474. if (!textContent) {
  70475. textContent = createEl(txConOptNormal);
  70476. el.setTextContent(textContent);
  70477. } else {
  70478. // If in some case the performance issue arised, consider
  70479. // do not clearState but update cached normal state directly.
  70480. textContent.clearStates();
  70481. }
  70482. updateElNormal(null, textContent, dataIndex, txConOptNormal, null, seriesModel, isInit);
  70483. var txConStlOptNormal = txConOptNormal && txConOptNormal.style;
  70484. for (var i = 0; i < STATES.length; i++) {
  70485. var stateName = STATES[i];
  70486. if (stateName !== NORMAL) {
  70487. var txConOptOtherState = attachedTxInfo[stateName].conOpt;
  70488. updateElOnState(stateName, textContent, txConOptOtherState, retrieveStyleOptionOnState(txConOptNormal, txConOptOtherState, stateName), null);
  70489. }
  70490. }
  70491. txConStlOptNormal ? textContent.dirty() : textContent.markRedraw();
  70492. }
  70493. }
  70494. }
  70495. function processTxInfo(elOption, state, attachedTxInfo) {
  70496. var stateOpt = !state ? elOption : retrieveStateOption(elOption, state);
  70497. var styleOpt = !state ? elOption.style : retrieveStyleOptionOnState(elOption, stateOpt, EMPHASIS);
  70498. var elType = elOption.type;
  70499. var txCfg = stateOpt ? stateOpt.textConfig : null;
  70500. var txConOptNormal = elOption.textContent;
  70501. var txConOpt = !txConOptNormal ? null : !state ? txConOptNormal : retrieveStateOption(txConOptNormal, state);
  70502. if (styleOpt && (
  70503. // Because emphasis style has little info to detect legacy,
  70504. // if normal is legacy, emphasis is trade as legacy.
  70505. attachedTxInfo.isLegacy || isEC4CompatibleStyle(styleOpt, elType, !!txCfg, !!txConOpt))) {
  70506. attachedTxInfo.isLegacy = true;
  70507. var convertResult = convertFromEC4CompatibleStyle(styleOpt, elType, !state);
  70508. // Explicitly specified `textConfig` and `textContent` has higher priority than
  70509. // the ones generated by legacy style. Otherwise if users use them and `api.style`
  70510. // at the same time, they not both work and hardly to known why.
  70511. if (!txCfg && convertResult.textConfig) {
  70512. txCfg = convertResult.textConfig;
  70513. }
  70514. if (!txConOpt && convertResult.textContent) {
  70515. txConOpt = convertResult.textContent;
  70516. }
  70517. }
  70518. if (!state && txConOpt) {
  70519. var txConOptNormal_1 = txConOpt;
  70520. // `textContent: {type: 'text'}`, the "type" is easy to be missing. So we tolerate it.
  70521. !txConOptNormal_1.type && (txConOptNormal_1.type = 'text');
  70522. if ("development" !== 'production') {
  70523. // Do not tolerate incorrcet type for forward compat.
  70524. assert(txConOptNormal_1.type === 'text', 'textContent.type must be "text"');
  70525. }
  70526. }
  70527. var info = !state ? attachedTxInfo.normal : attachedTxInfo[state];
  70528. info.cfg = txCfg;
  70529. info.conOpt = txConOpt;
  70530. }
  70531. function retrieveStateOption(elOption, state) {
  70532. return !state ? elOption : elOption ? elOption[state] : null;
  70533. }
  70534. function retrieveStyleOptionOnState(stateOptionNormal, stateOption, state) {
  70535. var style = stateOption && stateOption.style;
  70536. if (style == null && state === EMPHASIS && stateOptionNormal) {
  70537. style = stateOptionNormal.styleEmphasis;
  70538. }
  70539. return style;
  70540. }
  70541. // Usage:
  70542. // (1) By default, `elOption.$mergeChildren` is `'byIndex'`, which indicates
  70543. // that the existing children will not be removed, and enables the feature
  70544. // that update some of the props of some of the children simply by construct
  70545. // the returned children of `renderItem` like:
  70546. // `var children = group.children = []; children[3] = {opacity: 0.5};`
  70547. // (2) If `elOption.$mergeChildren` is `'byName'`, add/update/remove children
  70548. // by child.name. But that might be lower performance.
  70549. // (3) If `elOption.$mergeChildren` is `false`, the existing children will be
  70550. // replaced totally.
  70551. // (4) If `!elOption.children`, following the "merge" principle, nothing will
  70552. // happen.
  70553. // (5) If `elOption.$mergeChildren` is not `false` neither `'byName'` and the
  70554. // `el` is a group, and if any of the new child is null, it means to remove
  70555. // the element at the same index, if exists. On the other hand, if the new
  70556. // child is and empty object `{}`, it means to keep the element not changed.
  70557. //
  70558. // For implementation simpleness, do not provide a direct way to remove single
  70559. // child (otherwise the total indices of the children array have to be modified).
  70560. // User can remove a single child by setting its `ignore` to `true`.
  70561. function mergeChildren(api, el, dataIndex, elOption, seriesModel) {
  70562. var newChildren = elOption.children;
  70563. var newLen = newChildren ? newChildren.length : 0;
  70564. var mergeChildren = elOption.$mergeChildren;
  70565. // `diffChildrenByName` has been deprecated.
  70566. var byName = mergeChildren === 'byName' || elOption.diffChildrenByName;
  70567. var notMerge = mergeChildren === false;
  70568. // For better performance on roam update, only enter if necessary.
  70569. if (!newLen && !byName && !notMerge) {
  70570. return;
  70571. }
  70572. if (byName) {
  70573. diffGroupChildren({
  70574. api: api,
  70575. oldChildren: el.children() || [],
  70576. newChildren: newChildren || [],
  70577. dataIndex: dataIndex,
  70578. seriesModel: seriesModel,
  70579. group: el
  70580. });
  70581. return;
  70582. }
  70583. notMerge && el.removeAll();
  70584. // Mapping children of a group simply by index, which
  70585. // might be better performance.
  70586. var index = 0;
  70587. for (; index < newLen; index++) {
  70588. var newChild = newChildren[index];
  70589. var oldChild = el.childAt(index);
  70590. if (newChild) {
  70591. if (newChild.ignore == null) {
  70592. // The old child is set to be ignored if null (see comments
  70593. // below). So we need to set ignore to be false back.
  70594. newChild.ignore = false;
  70595. }
  70596. doCreateOrUpdateEl(api, oldChild, dataIndex, newChild, seriesModel, el);
  70597. } else {
  70598. if ("development" !== 'production') {
  70599. assert(oldChild, 'renderItem should not return a group containing elements' + ' as null/undefined/{} if they do not exist before.');
  70600. }
  70601. // If the new element option is null, it means to remove the old
  70602. // element. But we cannot really remove the element from the group
  70603. // directly, because the element order may not be stable when this
  70604. // element is added back. So we set the element to be ignored.
  70605. oldChild.ignore = true;
  70606. }
  70607. }
  70608. for (var i = el.childCount() - 1; i >= index; i--) {
  70609. var child = el.childAt(i);
  70610. removeChildFromGroup(el, child, seriesModel);
  70611. }
  70612. }
  70613. function removeChildFromGroup(group, child, seriesModel) {
  70614. // Do not support leave elements that are not mentioned in the latest
  70615. // `renderItem` return. Otherwise users may not have a clear and simple
  70616. // concept that how to control all of the elements.
  70617. child && applyLeaveTransition(child, customInnerStore(group).option, seriesModel);
  70618. }
  70619. function diffGroupChildren(context) {
  70620. new DataDiffer(context.oldChildren, context.newChildren, getKey, getKey, context).add(processAddUpdate).update(processAddUpdate).remove(processRemove).execute();
  70621. }
  70622. function getKey(item, idx) {
  70623. var name = item && item.name;
  70624. return name != null ? name : GROUP_DIFF_PREFIX + idx;
  70625. }
  70626. function processAddUpdate(newIndex, oldIndex) {
  70627. var context = this.context;
  70628. var childOption = newIndex != null ? context.newChildren[newIndex] : null;
  70629. var child = oldIndex != null ? context.oldChildren[oldIndex] : null;
  70630. doCreateOrUpdateEl(context.api, child, context.dataIndex, childOption, context.seriesModel, context.group);
  70631. }
  70632. function processRemove(oldIndex) {
  70633. var context = this.context;
  70634. var child = context.oldChildren[oldIndex];
  70635. child && applyLeaveTransition(child, customInnerStore(child).option, context.seriesModel);
  70636. }
  70637. /**
  70638. * @return SVG Path data.
  70639. */
  70640. function getPathData(shape) {
  70641. // "d" follows the SVG convention.
  70642. return shape && (shape.pathData || shape.d);
  70643. }
  70644. function hasOwnPathData(shape) {
  70645. return shape && (hasOwn(shape, 'pathData') || hasOwn(shape, 'd'));
  70646. }
  70647. function install$s(registers) {
  70648. registers.registerChartView(CustomChartView);
  70649. registers.registerSeriesModel(CustomSeriesModel);
  70650. }
  70651. var inner$c = makeInner();
  70652. var clone$3 = clone;
  70653. var bind$1 = bind;
  70654. /**
  70655. * Base axis pointer class in 2D.
  70656. */
  70657. var BaseAxisPointer = /** @class */function () {
  70658. function BaseAxisPointer() {
  70659. this._dragging = false;
  70660. /**
  70661. * In px, arbitrary value. Do not set too small,
  70662. * no animation is ok for most cases.
  70663. */
  70664. this.animationThreshold = 15;
  70665. }
  70666. /**
  70667. * @implement
  70668. */
  70669. BaseAxisPointer.prototype.render = function (axisModel, axisPointerModel, api, forceRender) {
  70670. var value = axisPointerModel.get('value');
  70671. var status = axisPointerModel.get('status');
  70672. // Bind them to `this`, not in closure, otherwise they will not
  70673. // be replaced when user calling setOption in not merge mode.
  70674. this._axisModel = axisModel;
  70675. this._axisPointerModel = axisPointerModel;
  70676. this._api = api;
  70677. // Optimize: `render` will be called repeatedly during mouse move.
  70678. // So it is power consuming if performing `render` each time,
  70679. // especially on mobile device.
  70680. if (!forceRender && this._lastValue === value && this._lastStatus === status) {
  70681. return;
  70682. }
  70683. this._lastValue = value;
  70684. this._lastStatus = status;
  70685. var group = this._group;
  70686. var handle = this._handle;
  70687. if (!status || status === 'hide') {
  70688. // Do not clear here, for animation better.
  70689. group && group.hide();
  70690. handle && handle.hide();
  70691. return;
  70692. }
  70693. group && group.show();
  70694. handle && handle.show();
  70695. // Otherwise status is 'show'
  70696. var elOption = {};
  70697. this.makeElOption(elOption, value, axisModel, axisPointerModel, api);
  70698. // Enable change axis pointer type.
  70699. var graphicKey = elOption.graphicKey;
  70700. if (graphicKey !== this._lastGraphicKey) {
  70701. this.clear(api);
  70702. }
  70703. this._lastGraphicKey = graphicKey;
  70704. var moveAnimation = this._moveAnimation = this.determineAnimation(axisModel, axisPointerModel);
  70705. if (!group) {
  70706. group = this._group = new Group();
  70707. this.createPointerEl(group, elOption, axisModel, axisPointerModel);
  70708. this.createLabelEl(group, elOption, axisModel, axisPointerModel);
  70709. api.getZr().add(group);
  70710. } else {
  70711. var doUpdateProps = curry(updateProps$1, axisPointerModel, moveAnimation);
  70712. this.updatePointerEl(group, elOption, doUpdateProps);
  70713. this.updateLabelEl(group, elOption, doUpdateProps, axisPointerModel);
  70714. }
  70715. updateMandatoryProps(group, axisPointerModel, true);
  70716. this._renderHandle(value);
  70717. };
  70718. /**
  70719. * @implement
  70720. */
  70721. BaseAxisPointer.prototype.remove = function (api) {
  70722. this.clear(api);
  70723. };
  70724. /**
  70725. * @implement
  70726. */
  70727. BaseAxisPointer.prototype.dispose = function (api) {
  70728. this.clear(api);
  70729. };
  70730. /**
  70731. * @protected
  70732. */
  70733. BaseAxisPointer.prototype.determineAnimation = function (axisModel, axisPointerModel) {
  70734. var animation = axisPointerModel.get('animation');
  70735. var axis = axisModel.axis;
  70736. var isCategoryAxis = axis.type === 'category';
  70737. var useSnap = axisPointerModel.get('snap');
  70738. // Value axis without snap always do not snap.
  70739. if (!useSnap && !isCategoryAxis) {
  70740. return false;
  70741. }
  70742. if (animation === 'auto' || animation == null) {
  70743. var animationThreshold = this.animationThreshold;
  70744. if (isCategoryAxis && axis.getBandWidth() > animationThreshold) {
  70745. return true;
  70746. }
  70747. // It is important to auto animation when snap used. Consider if there is
  70748. // a dataZoom, animation will be disabled when too many points exist, while
  70749. // it will be enabled for better visual effect when little points exist.
  70750. if (useSnap) {
  70751. var seriesDataCount = getAxisInfo(axisModel).seriesDataCount;
  70752. var axisExtent = axis.getExtent();
  70753. // Approximate band width
  70754. return Math.abs(axisExtent[0] - axisExtent[1]) / seriesDataCount > animationThreshold;
  70755. }
  70756. return false;
  70757. }
  70758. return animation === true;
  70759. };
  70760. /**
  70761. * add {pointer, label, graphicKey} to elOption
  70762. * @protected
  70763. */
  70764. BaseAxisPointer.prototype.makeElOption = function (elOption, value, axisModel, axisPointerModel, api) {
  70765. // Should be implemenented by sub-class.
  70766. };
  70767. /**
  70768. * @protected
  70769. */
  70770. BaseAxisPointer.prototype.createPointerEl = function (group, elOption, axisModel, axisPointerModel) {
  70771. var pointerOption = elOption.pointer;
  70772. if (pointerOption) {
  70773. var pointerEl = inner$c(group).pointerEl = new graphic[pointerOption.type](clone$3(elOption.pointer));
  70774. group.add(pointerEl);
  70775. }
  70776. };
  70777. /**
  70778. * @protected
  70779. */
  70780. BaseAxisPointer.prototype.createLabelEl = function (group, elOption, axisModel, axisPointerModel) {
  70781. if (elOption.label) {
  70782. var labelEl = inner$c(group).labelEl = new ZRText(clone$3(elOption.label));
  70783. group.add(labelEl);
  70784. updateLabelShowHide(labelEl, axisPointerModel);
  70785. }
  70786. };
  70787. /**
  70788. * @protected
  70789. */
  70790. BaseAxisPointer.prototype.updatePointerEl = function (group, elOption, updateProps) {
  70791. var pointerEl = inner$c(group).pointerEl;
  70792. if (pointerEl && elOption.pointer) {
  70793. pointerEl.setStyle(elOption.pointer.style);
  70794. updateProps(pointerEl, {
  70795. shape: elOption.pointer.shape
  70796. });
  70797. }
  70798. };
  70799. /**
  70800. * @protected
  70801. */
  70802. BaseAxisPointer.prototype.updateLabelEl = function (group, elOption, updateProps, axisPointerModel) {
  70803. var labelEl = inner$c(group).labelEl;
  70804. if (labelEl) {
  70805. labelEl.setStyle(elOption.label.style);
  70806. updateProps(labelEl, {
  70807. // Consider text length change in vertical axis, animation should
  70808. // be used on shape, otherwise the effect will be weird.
  70809. // TODOTODO
  70810. // shape: elOption.label.shape,
  70811. x: elOption.label.x,
  70812. y: elOption.label.y
  70813. });
  70814. updateLabelShowHide(labelEl, axisPointerModel);
  70815. }
  70816. };
  70817. /**
  70818. * @private
  70819. */
  70820. BaseAxisPointer.prototype._renderHandle = function (value) {
  70821. if (this._dragging || !this.updateHandleTransform) {
  70822. return;
  70823. }
  70824. var axisPointerModel = this._axisPointerModel;
  70825. var zr = this._api.getZr();
  70826. var handle = this._handle;
  70827. var handleModel = axisPointerModel.getModel('handle');
  70828. var status = axisPointerModel.get('status');
  70829. if (!handleModel.get('show') || !status || status === 'hide') {
  70830. handle && zr.remove(handle);
  70831. this._handle = null;
  70832. return;
  70833. }
  70834. var isInit;
  70835. if (!this._handle) {
  70836. isInit = true;
  70837. handle = this._handle = createIcon(handleModel.get('icon'), {
  70838. cursor: 'move',
  70839. draggable: true,
  70840. onmousemove: function (e) {
  70841. // For mobile device, prevent screen slider on the button.
  70842. stop(e.event);
  70843. },
  70844. onmousedown: bind$1(this._onHandleDragMove, this, 0, 0),
  70845. drift: bind$1(this._onHandleDragMove, this),
  70846. ondragend: bind$1(this._onHandleDragEnd, this)
  70847. });
  70848. zr.add(handle);
  70849. }
  70850. updateMandatoryProps(handle, axisPointerModel, false);
  70851. // update style
  70852. handle.setStyle(handleModel.getItemStyle(null, ['color', 'borderColor', 'borderWidth', 'opacity', 'shadowColor', 'shadowBlur', 'shadowOffsetX', 'shadowOffsetY']));
  70853. // update position
  70854. var handleSize = handleModel.get('size');
  70855. if (!isArray(handleSize)) {
  70856. handleSize = [handleSize, handleSize];
  70857. }
  70858. handle.scaleX = handleSize[0] / 2;
  70859. handle.scaleY = handleSize[1] / 2;
  70860. createOrUpdate(this, '_doDispatchAxisPointer', handleModel.get('throttle') || 0, 'fixRate');
  70861. this._moveHandleToValue(value, isInit);
  70862. };
  70863. BaseAxisPointer.prototype._moveHandleToValue = function (value, isInit) {
  70864. updateProps$1(this._axisPointerModel, !isInit && this._moveAnimation, this._handle, getHandleTransProps(this.getHandleTransform(value, this._axisModel, this._axisPointerModel)));
  70865. };
  70866. BaseAxisPointer.prototype._onHandleDragMove = function (dx, dy) {
  70867. var handle = this._handle;
  70868. if (!handle) {
  70869. return;
  70870. }
  70871. this._dragging = true;
  70872. // Persistent for throttle.
  70873. var trans = this.updateHandleTransform(getHandleTransProps(handle), [dx, dy], this._axisModel, this._axisPointerModel);
  70874. this._payloadInfo = trans;
  70875. handle.stopAnimation();
  70876. handle.attr(getHandleTransProps(trans));
  70877. inner$c(handle).lastProp = null;
  70878. this._doDispatchAxisPointer();
  70879. };
  70880. /**
  70881. * Throttled method.
  70882. */
  70883. BaseAxisPointer.prototype._doDispatchAxisPointer = function () {
  70884. var handle = this._handle;
  70885. if (!handle) {
  70886. return;
  70887. }
  70888. var payloadInfo = this._payloadInfo;
  70889. var axisModel = this._axisModel;
  70890. this._api.dispatchAction({
  70891. type: 'updateAxisPointer',
  70892. x: payloadInfo.cursorPoint[0],
  70893. y: payloadInfo.cursorPoint[1],
  70894. tooltipOption: payloadInfo.tooltipOption,
  70895. axesInfo: [{
  70896. axisDim: axisModel.axis.dim,
  70897. axisIndex: axisModel.componentIndex
  70898. }]
  70899. });
  70900. };
  70901. BaseAxisPointer.prototype._onHandleDragEnd = function () {
  70902. this._dragging = false;
  70903. var handle = this._handle;
  70904. if (!handle) {
  70905. return;
  70906. }
  70907. var value = this._axisPointerModel.get('value');
  70908. // Consider snap or categroy axis, handle may be not consistent with
  70909. // axisPointer. So move handle to align the exact value position when
  70910. // drag ended.
  70911. this._moveHandleToValue(value);
  70912. // For the effect: tooltip will be shown when finger holding on handle
  70913. // button, and will be hidden after finger left handle button.
  70914. this._api.dispatchAction({
  70915. type: 'hideTip'
  70916. });
  70917. };
  70918. /**
  70919. * @private
  70920. */
  70921. BaseAxisPointer.prototype.clear = function (api) {
  70922. this._lastValue = null;
  70923. this._lastStatus = null;
  70924. var zr = api.getZr();
  70925. var group = this._group;
  70926. var handle = this._handle;
  70927. if (zr && group) {
  70928. this._lastGraphicKey = null;
  70929. group && zr.remove(group);
  70930. handle && zr.remove(handle);
  70931. this._group = null;
  70932. this._handle = null;
  70933. this._payloadInfo = null;
  70934. }
  70935. clear(this, '_doDispatchAxisPointer');
  70936. };
  70937. /**
  70938. * @protected
  70939. */
  70940. BaseAxisPointer.prototype.doClear = function () {
  70941. // Implemented by sub-class if necessary.
  70942. };
  70943. BaseAxisPointer.prototype.buildLabel = function (xy, wh, xDimIndex) {
  70944. xDimIndex = xDimIndex || 0;
  70945. return {
  70946. x: xy[xDimIndex],
  70947. y: xy[1 - xDimIndex],
  70948. width: wh[xDimIndex],
  70949. height: wh[1 - xDimIndex]
  70950. };
  70951. };
  70952. return BaseAxisPointer;
  70953. }();
  70954. function updateProps$1(animationModel, moveAnimation, el, props) {
  70955. // Animation optimize.
  70956. if (!propsEqual(inner$c(el).lastProp, props)) {
  70957. inner$c(el).lastProp = props;
  70958. moveAnimation ? updateProps(el, props, animationModel) : (el.stopAnimation(), el.attr(props));
  70959. }
  70960. }
  70961. function propsEqual(lastProps, newProps) {
  70962. if (isObject(lastProps) && isObject(newProps)) {
  70963. var equals_1 = true;
  70964. each(newProps, function (item, key) {
  70965. equals_1 = equals_1 && propsEqual(lastProps[key], item);
  70966. });
  70967. return !!equals_1;
  70968. } else {
  70969. return lastProps === newProps;
  70970. }
  70971. }
  70972. function updateLabelShowHide(labelEl, axisPointerModel) {
  70973. labelEl[axisPointerModel.get(['label', 'show']) ? 'show' : 'hide']();
  70974. }
  70975. function getHandleTransProps(trans) {
  70976. return {
  70977. x: trans.x || 0,
  70978. y: trans.y || 0,
  70979. rotation: trans.rotation || 0
  70980. };
  70981. }
  70982. function updateMandatoryProps(group, axisPointerModel, silent) {
  70983. var z = axisPointerModel.get('z');
  70984. var zlevel = axisPointerModel.get('zlevel');
  70985. group && group.traverse(function (el) {
  70986. if (el.type !== 'group') {
  70987. z != null && (el.z = z);
  70988. zlevel != null && (el.zlevel = zlevel);
  70989. el.silent = silent;
  70990. }
  70991. });
  70992. }
  70993. function buildElStyle(axisPointerModel) {
  70994. var axisPointerType = axisPointerModel.get('type');
  70995. var styleModel = axisPointerModel.getModel(axisPointerType + 'Style');
  70996. var style;
  70997. if (axisPointerType === 'line') {
  70998. style = styleModel.getLineStyle();
  70999. style.fill = null;
  71000. } else if (axisPointerType === 'shadow') {
  71001. style = styleModel.getAreaStyle();
  71002. style.stroke = null;
  71003. }
  71004. return style;
  71005. }
  71006. /**
  71007. * @param {Function} labelPos {align, verticalAlign, position}
  71008. */
  71009. function buildLabelElOption(elOption, axisModel, axisPointerModel, api, labelPos) {
  71010. var value = axisPointerModel.get('value');
  71011. var text = getValueLabel(value, axisModel.axis, axisModel.ecModel, axisPointerModel.get('seriesDataIndices'), {
  71012. precision: axisPointerModel.get(['label', 'precision']),
  71013. formatter: axisPointerModel.get(['label', 'formatter'])
  71014. });
  71015. var labelModel = axisPointerModel.getModel('label');
  71016. var paddings = normalizeCssArray$1(labelModel.get('padding') || 0);
  71017. var font = labelModel.getFont();
  71018. var textRect = getBoundingRect(text, font);
  71019. var position = labelPos.position;
  71020. var width = textRect.width + paddings[1] + paddings[3];
  71021. var height = textRect.height + paddings[0] + paddings[2];
  71022. // Adjust by align.
  71023. var align = labelPos.align;
  71024. align === 'right' && (position[0] -= width);
  71025. align === 'center' && (position[0] -= width / 2);
  71026. var verticalAlign = labelPos.verticalAlign;
  71027. verticalAlign === 'bottom' && (position[1] -= height);
  71028. verticalAlign === 'middle' && (position[1] -= height / 2);
  71029. // Not overflow ec container
  71030. confineInContainer(position, width, height, api);
  71031. var bgColor = labelModel.get('backgroundColor');
  71032. if (!bgColor || bgColor === 'auto') {
  71033. bgColor = axisModel.get(['axisLine', 'lineStyle', 'color']);
  71034. }
  71035. elOption.label = {
  71036. // shape: {x: 0, y: 0, width: width, height: height, r: labelModel.get('borderRadius')},
  71037. x: position[0],
  71038. y: position[1],
  71039. style: createTextStyle(labelModel, {
  71040. text: text,
  71041. font: font,
  71042. fill: labelModel.getTextColor(),
  71043. padding: paddings,
  71044. backgroundColor: bgColor
  71045. }),
  71046. // Label should be over axisPointer.
  71047. z2: 10
  71048. };
  71049. }
  71050. // Do not overflow ec container
  71051. function confineInContainer(position, width, height, api) {
  71052. var viewWidth = api.getWidth();
  71053. var viewHeight = api.getHeight();
  71054. position[0] = Math.min(position[0] + width, viewWidth) - width;
  71055. position[1] = Math.min(position[1] + height, viewHeight) - height;
  71056. position[0] = Math.max(position[0], 0);
  71057. position[1] = Math.max(position[1], 0);
  71058. }
  71059. function getValueLabel(value, axis, ecModel, seriesDataIndices, opt) {
  71060. value = axis.scale.parse(value);
  71061. var text = axis.scale.getLabel({
  71062. value: value
  71063. }, {
  71064. // If `precision` is set, width can be fixed (like '12.00500'), which
  71065. // helps to debounce when when moving label.
  71066. precision: opt.precision
  71067. });
  71068. var formatter = opt.formatter;
  71069. if (formatter) {
  71070. var params_1 = {
  71071. value: getAxisRawValue(axis, {
  71072. value: value
  71073. }),
  71074. axisDimension: axis.dim,
  71075. axisIndex: axis.index,
  71076. seriesData: []
  71077. };
  71078. each(seriesDataIndices, function (idxItem) {
  71079. var series = ecModel.getSeriesByIndex(idxItem.seriesIndex);
  71080. var dataIndex = idxItem.dataIndexInside;
  71081. var dataParams = series && series.getDataParams(dataIndex);
  71082. dataParams && params_1.seriesData.push(dataParams);
  71083. });
  71084. if (isString(formatter)) {
  71085. text = formatter.replace('{value}', text);
  71086. } else if (isFunction(formatter)) {
  71087. text = formatter(params_1);
  71088. }
  71089. }
  71090. return text;
  71091. }
  71092. function getTransformedPosition(axis, value, layoutInfo) {
  71093. var transform = create$1();
  71094. rotate(transform, transform, layoutInfo.rotation);
  71095. translate(transform, transform, layoutInfo.position);
  71096. return applyTransform$1([axis.dataToCoord(value), (layoutInfo.labelOffset || 0) + (layoutInfo.labelDirection || 1) * (layoutInfo.labelMargin || 0)], transform);
  71097. }
  71098. function buildCartesianSingleLabelElOption(value, elOption, layoutInfo, axisModel, axisPointerModel, api) {
  71099. var textLayout = AxisBuilder.innerTextLayout(layoutInfo.rotation, 0, layoutInfo.labelDirection);
  71100. layoutInfo.labelMargin = axisPointerModel.get(['label', 'margin']);
  71101. buildLabelElOption(elOption, axisModel, axisPointerModel, api, {
  71102. position: getTransformedPosition(axisModel.axis, value, layoutInfo),
  71103. align: textLayout.textAlign,
  71104. verticalAlign: textLayout.textVerticalAlign
  71105. });
  71106. }
  71107. function makeLineShape(p1, p2, xDimIndex) {
  71108. xDimIndex = xDimIndex || 0;
  71109. return {
  71110. x1: p1[xDimIndex],
  71111. y1: p1[1 - xDimIndex],
  71112. x2: p2[xDimIndex],
  71113. y2: p2[1 - xDimIndex]
  71114. };
  71115. }
  71116. function makeRectShape(xy, wh, xDimIndex) {
  71117. xDimIndex = xDimIndex || 0;
  71118. return {
  71119. x: xy[xDimIndex],
  71120. y: xy[1 - xDimIndex],
  71121. width: wh[xDimIndex],
  71122. height: wh[1 - xDimIndex]
  71123. };
  71124. }
  71125. function makeSectorShape(cx, cy, r0, r, startAngle, endAngle) {
  71126. return {
  71127. cx: cx,
  71128. cy: cy,
  71129. r0: r0,
  71130. r: r,
  71131. startAngle: startAngle,
  71132. endAngle: endAngle,
  71133. clockwise: true
  71134. };
  71135. }
  71136. var CartesianAxisPointer = /** @class */function (_super) {
  71137. __extends(CartesianAxisPointer, _super);
  71138. function CartesianAxisPointer() {
  71139. return _super !== null && _super.apply(this, arguments) || this;
  71140. }
  71141. /**
  71142. * @override
  71143. */
  71144. CartesianAxisPointer.prototype.makeElOption = function (elOption, value, axisModel, axisPointerModel, api) {
  71145. var axis = axisModel.axis;
  71146. var grid = axis.grid;
  71147. var axisPointerType = axisPointerModel.get('type');
  71148. var otherExtent = getCartesian(grid, axis).getOtherAxis(axis).getGlobalExtent();
  71149. var pixelValue = axis.toGlobalCoord(axis.dataToCoord(value, true));
  71150. if (axisPointerType && axisPointerType !== 'none') {
  71151. var elStyle = buildElStyle(axisPointerModel);
  71152. var pointerOption = pointerShapeBuilder[axisPointerType](axis, pixelValue, otherExtent);
  71153. pointerOption.style = elStyle;
  71154. elOption.graphicKey = pointerOption.type;
  71155. elOption.pointer = pointerOption;
  71156. }
  71157. var layoutInfo = layout$1(grid.getRect(), axisModel);
  71158. buildCartesianSingleLabelElOption(value, elOption, layoutInfo, axisModel, axisPointerModel, api);
  71159. };
  71160. /**
  71161. * @override
  71162. */
  71163. CartesianAxisPointer.prototype.getHandleTransform = function (value, axisModel, axisPointerModel) {
  71164. var layoutInfo = layout$1(axisModel.axis.grid.getRect(), axisModel, {
  71165. labelInside: false
  71166. });
  71167. layoutInfo.labelMargin = axisPointerModel.get(['handle', 'margin']);
  71168. var pos = getTransformedPosition(axisModel.axis, value, layoutInfo);
  71169. return {
  71170. x: pos[0],
  71171. y: pos[1],
  71172. rotation: layoutInfo.rotation + (layoutInfo.labelDirection < 0 ? Math.PI : 0)
  71173. };
  71174. };
  71175. /**
  71176. * @override
  71177. */
  71178. CartesianAxisPointer.prototype.updateHandleTransform = function (transform, delta, axisModel, axisPointerModel) {
  71179. var axis = axisModel.axis;
  71180. var grid = axis.grid;
  71181. var axisExtent = axis.getGlobalExtent(true);
  71182. var otherExtent = getCartesian(grid, axis).getOtherAxis(axis).getGlobalExtent();
  71183. var dimIndex = axis.dim === 'x' ? 0 : 1;
  71184. var currPosition = [transform.x, transform.y];
  71185. currPosition[dimIndex] += delta[dimIndex];
  71186. currPosition[dimIndex] = Math.min(axisExtent[1], currPosition[dimIndex]);
  71187. currPosition[dimIndex] = Math.max(axisExtent[0], currPosition[dimIndex]);
  71188. var cursorOtherValue = (otherExtent[1] + otherExtent[0]) / 2;
  71189. var cursorPoint = [cursorOtherValue, cursorOtherValue];
  71190. cursorPoint[dimIndex] = currPosition[dimIndex];
  71191. // Make tooltip do not overlap axisPointer and in the middle of the grid.
  71192. var tooltipOptions = [{
  71193. verticalAlign: 'middle'
  71194. }, {
  71195. align: 'center'
  71196. }];
  71197. return {
  71198. x: currPosition[0],
  71199. y: currPosition[1],
  71200. rotation: transform.rotation,
  71201. cursorPoint: cursorPoint,
  71202. tooltipOption: tooltipOptions[dimIndex]
  71203. };
  71204. };
  71205. return CartesianAxisPointer;
  71206. }(BaseAxisPointer);
  71207. function getCartesian(grid, axis) {
  71208. var opt = {};
  71209. opt[axis.dim + 'AxisIndex'] = axis.index;
  71210. return grid.getCartesian(opt);
  71211. }
  71212. var pointerShapeBuilder = {
  71213. line: function (axis, pixelValue, otherExtent) {
  71214. var targetShape = makeLineShape([pixelValue, otherExtent[0]], [pixelValue, otherExtent[1]], getAxisDimIndex(axis));
  71215. return {
  71216. type: 'Line',
  71217. subPixelOptimize: true,
  71218. shape: targetShape
  71219. };
  71220. },
  71221. shadow: function (axis, pixelValue, otherExtent) {
  71222. var bandWidth = Math.max(1, axis.getBandWidth());
  71223. var span = otherExtent[1] - otherExtent[0];
  71224. return {
  71225. type: 'Rect',
  71226. shape: makeRectShape([pixelValue - bandWidth / 2, otherExtent[0]], [bandWidth, span], getAxisDimIndex(axis))
  71227. };
  71228. }
  71229. };
  71230. function getAxisDimIndex(axis) {
  71231. return axis.dim === 'x' ? 0 : 1;
  71232. }
  71233. var AxisPointerModel = /** @class */function (_super) {
  71234. __extends(AxisPointerModel, _super);
  71235. function AxisPointerModel() {
  71236. var _this = _super !== null && _super.apply(this, arguments) || this;
  71237. _this.type = AxisPointerModel.type;
  71238. return _this;
  71239. }
  71240. AxisPointerModel.type = 'axisPointer';
  71241. AxisPointerModel.defaultOption = {
  71242. // 'auto' means that show when triggered by tooltip or handle.
  71243. show: 'auto',
  71244. // zlevel: 0,
  71245. z: 50,
  71246. type: 'line',
  71247. // axispointer triggered by tootip determine snap automatically,
  71248. // see `modelHelper`.
  71249. snap: false,
  71250. triggerTooltip: true,
  71251. triggerEmphasis: true,
  71252. value: null,
  71253. status: null,
  71254. link: [],
  71255. // Do not set 'auto' here, otherwise global animation: false
  71256. // will not effect at this axispointer.
  71257. animation: null,
  71258. animationDurationUpdate: 200,
  71259. lineStyle: {
  71260. color: tokens.color.border,
  71261. width: 1,
  71262. type: 'dashed'
  71263. },
  71264. shadowStyle: {
  71265. color: tokens.color.shadowTint
  71266. },
  71267. label: {
  71268. show: true,
  71269. formatter: null,
  71270. precision: 'auto',
  71271. margin: 3,
  71272. color: tokens.color.neutral00,
  71273. padding: [5, 7, 5, 7],
  71274. backgroundColor: tokens.color.accent60,
  71275. borderColor: null,
  71276. borderWidth: 0,
  71277. borderRadius: 3
  71278. },
  71279. handle: {
  71280. show: false,
  71281. // eslint-disable-next-line
  71282. icon: 'M10.7,11.9v-1.3H9.3v1.3c-4.9,0.3-8.8,4.4-8.8,9.4c0,5,3.9,9.1,8.8,9.4h1.3c4.9-0.3,8.8-4.4,8.8-9.4C19.5,16.3,15.6,12.2,10.7,11.9z M13.3,24.4H6.7v-1.2h6.6z M13.3,22H6.7v-1.2h6.6z M13.3,19.6H6.7v-1.2h6.6z',
  71283. size: 45,
  71284. // handle margin is from symbol center to axis, which is stable when circular move.
  71285. margin: 50,
  71286. // color: '#1b8bbd'
  71287. // color: '#2f4554'
  71288. color: tokens.color.accent40,
  71289. // For mobile performance
  71290. throttle: 40
  71291. }
  71292. };
  71293. return AxisPointerModel;
  71294. }(ComponentModel);
  71295. var inner$d = makeInner();
  71296. var each$7 = each;
  71297. /**
  71298. * @param {string} key
  71299. * @param {module:echarts/ExtensionAPI} api
  71300. * @param {Function} handler
  71301. * param: {string} currTrigger
  71302. * param: {Array.<number>} point
  71303. */
  71304. function register(key, api, handler) {
  71305. if (env.node) {
  71306. return;
  71307. }
  71308. var zr = api.getZr();
  71309. inner$d(zr).records || (inner$d(zr).records = {});
  71310. initGlobalListeners(zr, api);
  71311. var record = inner$d(zr).records[key] || (inner$d(zr).records[key] = {});
  71312. record.handler = handler;
  71313. }
  71314. function initGlobalListeners(zr, api) {
  71315. if (inner$d(zr).initialized) {
  71316. return;
  71317. }
  71318. inner$d(zr).initialized = true;
  71319. useHandler('click', curry(doEnter, 'click'));
  71320. useHandler('mousemove', curry(doEnter, 'mousemove'));
  71321. // useHandler('mouseout', onLeave);
  71322. useHandler('globalout', onLeave);
  71323. function useHandler(eventType, cb) {
  71324. zr.on(eventType, function (e) {
  71325. var dis = makeDispatchAction(api);
  71326. each$7(inner$d(zr).records, function (record) {
  71327. record && cb(record, e, dis.dispatchAction);
  71328. });
  71329. dispatchTooltipFinally(dis.pendings, api);
  71330. });
  71331. }
  71332. }
  71333. function dispatchTooltipFinally(pendings, api) {
  71334. var showLen = pendings.showTip.length;
  71335. var hideLen = pendings.hideTip.length;
  71336. var actuallyPayload;
  71337. if (showLen) {
  71338. actuallyPayload = pendings.showTip[showLen - 1];
  71339. } else if (hideLen) {
  71340. actuallyPayload = pendings.hideTip[hideLen - 1];
  71341. }
  71342. if (actuallyPayload) {
  71343. actuallyPayload.dispatchAction = null;
  71344. api.dispatchAction(actuallyPayload);
  71345. }
  71346. }
  71347. function onLeave(record, e, dispatchAction) {
  71348. record.handler('leave', null, dispatchAction);
  71349. }
  71350. function doEnter(currTrigger, record, e, dispatchAction) {
  71351. record.handler(currTrigger, e, dispatchAction);
  71352. }
  71353. function makeDispatchAction(api) {
  71354. var pendings = {
  71355. showTip: [],
  71356. hideTip: []
  71357. };
  71358. // FIXME
  71359. // better approach?
  71360. // 'showTip' and 'hideTip' can be triggered by axisPointer and tooltip,
  71361. // which may be conflict, (axisPointer call showTip but tooltip call hideTip);
  71362. // So we have to add "final stage" to merge those dispatched actions.
  71363. var dispatchAction = function (payload) {
  71364. var pendingList = pendings[payload.type];
  71365. if (pendingList) {
  71366. pendingList.push(payload);
  71367. } else {
  71368. payload.dispatchAction = dispatchAction;
  71369. api.dispatchAction(payload);
  71370. }
  71371. };
  71372. return {
  71373. dispatchAction: dispatchAction,
  71374. pendings: pendings
  71375. };
  71376. }
  71377. function unregister(key, api) {
  71378. if (env.node) {
  71379. return;
  71380. }
  71381. var zr = api.getZr();
  71382. var record = (inner$d(zr).records || {})[key];
  71383. if (record) {
  71384. inner$d(zr).records[key] = null;
  71385. }
  71386. }
  71387. var AxisPointerView = /** @class */function (_super) {
  71388. __extends(AxisPointerView, _super);
  71389. function AxisPointerView() {
  71390. var _this = _super !== null && _super.apply(this, arguments) || this;
  71391. _this.type = AxisPointerView.type;
  71392. return _this;
  71393. }
  71394. AxisPointerView.prototype.render = function (globalAxisPointerModel, ecModel, api) {
  71395. var globalTooltipModel = ecModel.getComponent('tooltip');
  71396. var triggerOn = globalAxisPointerModel.get('triggerOn') || globalTooltipModel && globalTooltipModel.get('triggerOn') || 'mousemove|click';
  71397. // Register global listener in AxisPointerView to enable
  71398. // AxisPointerView to be independent to Tooltip.
  71399. register('axisPointer', api, function (currTrigger, e, dispatchAction) {
  71400. // If 'none', it is not controlled by mouse totally.
  71401. if (triggerOn !== 'none' && (currTrigger === 'leave' || triggerOn.indexOf(currTrigger) >= 0)) {
  71402. dispatchAction({
  71403. type: 'updateAxisPointer',
  71404. currTrigger: currTrigger,
  71405. x: e && e.offsetX,
  71406. y: e && e.offsetY
  71407. });
  71408. }
  71409. });
  71410. };
  71411. AxisPointerView.prototype.remove = function (ecModel, api) {
  71412. unregister('axisPointer', api);
  71413. };
  71414. AxisPointerView.prototype.dispose = function (ecModel, api) {
  71415. unregister('axisPointer', api);
  71416. };
  71417. AxisPointerView.type = 'axisPointer';
  71418. return AxisPointerView;
  71419. }(ComponentView);
  71420. /**
  71421. * @param finder contains {seriesIndex, dataIndex, dataIndexInside}
  71422. * @param ecModel
  71423. * @return {point: [x, y], el: ...} point Will not be null.
  71424. */
  71425. function findPointFromSeries(finder, ecModel) {
  71426. var point = [];
  71427. var seriesIndex = finder.seriesIndex;
  71428. var seriesModel;
  71429. if (seriesIndex == null || !(seriesModel = ecModel.getSeriesByIndex(seriesIndex))) {
  71430. return {
  71431. point: []
  71432. };
  71433. }
  71434. var data = seriesModel.getData();
  71435. var dataIndex = queryDataIndex(data, finder);
  71436. if (dataIndex == null || dataIndex < 0 || isArray(dataIndex)) {
  71437. return {
  71438. point: []
  71439. };
  71440. }
  71441. var el = data.getItemGraphicEl(dataIndex);
  71442. var coordSys = seriesModel.coordinateSystem;
  71443. if (seriesModel.getTooltipPosition) {
  71444. point = seriesModel.getTooltipPosition(dataIndex) || [];
  71445. } else if (coordSys && coordSys.dataToPoint) {
  71446. if (finder.isStacked) {
  71447. var baseAxis = coordSys.getBaseAxis();
  71448. var valueAxis = coordSys.getOtherAxis(baseAxis);
  71449. var valueAxisDim = valueAxis.dim;
  71450. var baseAxisDim = baseAxis.dim;
  71451. var baseDataOffset = valueAxisDim === 'x' || valueAxisDim === 'radius' ? 1 : 0;
  71452. var baseDim = data.mapDimension(baseAxisDim);
  71453. var stackedData = [];
  71454. stackedData[baseDataOffset] = data.get(baseDim, dataIndex);
  71455. stackedData[1 - baseDataOffset] = data.get(data.getCalculationInfo('stackResultDimension'), dataIndex);
  71456. point = coordSys.dataToPoint(stackedData) || [];
  71457. } else {
  71458. point = coordSys.dataToPoint(data.getValues(map(coordSys.dimensions, function (dim) {
  71459. return data.mapDimension(dim);
  71460. }), dataIndex)) || [];
  71461. }
  71462. } else if (el) {
  71463. // Use graphic bounding rect
  71464. var rect = el.getBoundingRect().clone();
  71465. rect.applyTransform(el.transform);
  71466. point = [rect.x + rect.width / 2, rect.y + rect.height / 2];
  71467. }
  71468. return {
  71469. point: point,
  71470. el: el
  71471. };
  71472. }
  71473. var inner$e = makeInner();
  71474. /**
  71475. * Basic logic: check all axis, if they do not demand show/highlight,
  71476. * then hide/downplay them.
  71477. *
  71478. * @return content of event obj for echarts.connect.
  71479. */
  71480. function axisTrigger(payload, ecModel, api) {
  71481. var currTrigger = payload.currTrigger;
  71482. var point = [payload.x, payload.y];
  71483. var finder = payload;
  71484. var dispatchAction = payload.dispatchAction || bind(api.dispatchAction, api);
  71485. var coordSysAxesInfo = ecModel.getComponent('axisPointer').coordSysAxesInfo;
  71486. // Pending
  71487. // See #6121. But we are not able to reproduce it yet.
  71488. if (!coordSysAxesInfo) {
  71489. return;
  71490. }
  71491. if (illegalPoint(point)) {
  71492. // Used in the default behavior of `connection`: use the sample seriesIndex
  71493. // and dataIndex. And also used in the tooltipView trigger.
  71494. point = findPointFromSeries({
  71495. seriesIndex: finder.seriesIndex,
  71496. // Do not use dataIndexInside from other ec instance.
  71497. // FIXME: auto detect it?
  71498. dataIndex: finder.dataIndex
  71499. }, ecModel).point;
  71500. }
  71501. var isIllegalPoint = illegalPoint(point);
  71502. // Axis and value can be specified when calling dispatchAction({type: 'updateAxisPointer'}).
  71503. // Notice: In this case, it is difficult to get the `point` (which is necessary to show
  71504. // tooltip, so if point is not given, we just use the point found by sample seriesIndex
  71505. // and dataIndex.
  71506. var inputAxesInfo = finder.axesInfo;
  71507. var axesInfo = coordSysAxesInfo.axesInfo;
  71508. var shouldHide = currTrigger === 'leave' || illegalPoint(point);
  71509. var outputPayload = {};
  71510. var showValueMap = {};
  71511. var dataByCoordSys = {
  71512. list: [],
  71513. map: {}
  71514. };
  71515. var updaters = {
  71516. showPointer: curry(showPointer, showValueMap),
  71517. showTooltip: curry(showTooltip, dataByCoordSys)
  71518. };
  71519. // Process for triggered axes.
  71520. each(coordSysAxesInfo.coordSysMap, function (coordSys, coordSysKey) {
  71521. // If a point given, it must be contained by the coordinate system.
  71522. var coordSysContainsPoint = isIllegalPoint || coordSys.containPoint(point);
  71523. each(coordSysAxesInfo.coordSysAxesInfo[coordSysKey], function (axisInfo, key) {
  71524. var axis = axisInfo.axis;
  71525. var inputAxisInfo = findInputAxisInfo(inputAxesInfo, axisInfo);
  71526. // If no inputAxesInfo, no axis is restricted.
  71527. if (!shouldHide && coordSysContainsPoint && (!inputAxesInfo || inputAxisInfo)) {
  71528. var val = inputAxisInfo && inputAxisInfo.value;
  71529. if (val == null && !isIllegalPoint) {
  71530. val = axis.pointToData(point);
  71531. }
  71532. val != null && processOnAxis(axisInfo, val, updaters, false, outputPayload);
  71533. }
  71534. });
  71535. });
  71536. // Process for linked axes.
  71537. var linkTriggers = {};
  71538. each(axesInfo, function (tarAxisInfo, tarKey) {
  71539. var linkGroup = tarAxisInfo.linkGroup;
  71540. // If axis has been triggered in the previous stage, it should not be triggered by link.
  71541. if (linkGroup && !showValueMap[tarKey]) {
  71542. each(linkGroup.axesInfo, function (srcAxisInfo, srcKey) {
  71543. var srcValItem = showValueMap[srcKey];
  71544. // If srcValItem exist, source axis is triggered, so link to target axis.
  71545. if (srcAxisInfo !== tarAxisInfo && srcValItem) {
  71546. var val = srcValItem.value;
  71547. linkGroup.mapper && (val = tarAxisInfo.axis.scale.parse(linkGroup.mapper(val, makeMapperParam(srcAxisInfo), makeMapperParam(tarAxisInfo))));
  71548. linkTriggers[tarAxisInfo.key] = val;
  71549. }
  71550. });
  71551. }
  71552. });
  71553. each(linkTriggers, function (val, tarKey) {
  71554. processOnAxis(axesInfo[tarKey], val, updaters, true, outputPayload);
  71555. });
  71556. updateModelActually(showValueMap, axesInfo, outputPayload);
  71557. dispatchTooltipActually(dataByCoordSys, point, payload, dispatchAction);
  71558. dispatchHighDownActually(axesInfo, dispatchAction, api);
  71559. return outputPayload;
  71560. }
  71561. function processOnAxis(axisInfo, newValue, updaters, noSnap, outputFinder) {
  71562. var axis = axisInfo.axis;
  71563. if (axis.scale.isBlank() || !axis.containData(newValue)) {
  71564. return;
  71565. }
  71566. if (!axisInfo.involveSeries) {
  71567. updaters.showPointer(axisInfo, newValue);
  71568. return;
  71569. }
  71570. // Heavy calculation. So put it after axis.containData checking.
  71571. var payloadInfo = buildPayloadsBySeries(newValue, axisInfo);
  71572. var payloadBatch = payloadInfo.payloadBatch;
  71573. var snapToValue = payloadInfo.snapToValue;
  71574. // Fill content of event obj for echarts.connect.
  71575. // By default use the first involved series data as a sample to connect.
  71576. if (payloadBatch[0] && outputFinder.seriesIndex == null) {
  71577. extend(outputFinder, payloadBatch[0]);
  71578. }
  71579. // If no linkSource input, this process is for collecting link
  71580. // target, where snap should not be accepted.
  71581. if (!noSnap && axisInfo.snap) {
  71582. if (axis.containData(snapToValue) && snapToValue != null) {
  71583. newValue = snapToValue;
  71584. }
  71585. }
  71586. updaters.showPointer(axisInfo, newValue, payloadBatch);
  71587. // Tooltip should always be snapToValue, otherwise there will be
  71588. // incorrect "axis value ~ series value" mapping displayed in tooltip.
  71589. updaters.showTooltip(axisInfo, payloadInfo, snapToValue);
  71590. }
  71591. function buildPayloadsBySeries(value, axisInfo) {
  71592. var axis = axisInfo.axis;
  71593. var dim = axis.dim;
  71594. var snapToValue = value;
  71595. var payloadBatch = [];
  71596. var minDist = Number.MAX_VALUE;
  71597. var minDiff = -1;
  71598. each(axisInfo.seriesModels, function (series, idx) {
  71599. var dataDim = series.getData().mapDimensionsAll(dim);
  71600. var seriesNestestValue;
  71601. var dataIndices;
  71602. if (series.getAxisTooltipData) {
  71603. var result = series.getAxisTooltipData(dataDim, value, axis);
  71604. dataIndices = result.dataIndices;
  71605. seriesNestestValue = result.nestestValue;
  71606. } else {
  71607. dataIndices = series.indicesOfNearest(dim, dataDim[0], value,
  71608. // Add a threshold to avoid find the wrong dataIndex
  71609. // when data length is not same.
  71610. // false,
  71611. axis.type === 'category' ? 0.5 : null);
  71612. if (!dataIndices.length) {
  71613. return;
  71614. }
  71615. seriesNestestValue = series.getData().get(dataDim[0], dataIndices[0]);
  71616. }
  71617. if (seriesNestestValue == null || !isFinite(seriesNestestValue)) {
  71618. return;
  71619. }
  71620. var diff = value - seriesNestestValue;
  71621. var dist = Math.abs(diff);
  71622. // Consider category case
  71623. if (dist <= minDist) {
  71624. if (dist < minDist || diff >= 0 && minDiff < 0) {
  71625. minDist = dist;
  71626. minDiff = diff;
  71627. snapToValue = seriesNestestValue;
  71628. payloadBatch.length = 0;
  71629. }
  71630. each(dataIndices, function (dataIndex) {
  71631. payloadBatch.push({
  71632. seriesIndex: series.seriesIndex,
  71633. dataIndexInside: dataIndex,
  71634. dataIndex: series.getData().getRawIndex(dataIndex)
  71635. });
  71636. });
  71637. }
  71638. });
  71639. return {
  71640. payloadBatch: payloadBatch,
  71641. snapToValue: snapToValue
  71642. };
  71643. }
  71644. function showPointer(showValueMap, axisInfo, value, payloadBatch) {
  71645. showValueMap[axisInfo.key] = {
  71646. value: value,
  71647. payloadBatch: payloadBatch
  71648. };
  71649. }
  71650. function showTooltip(dataByCoordSys, axisInfo, payloadInfo, value) {
  71651. var payloadBatch = payloadInfo.payloadBatch;
  71652. var axis = axisInfo.axis;
  71653. var axisModel = axis.model;
  71654. var axisPointerModel = axisInfo.axisPointerModel;
  71655. // If no data, do not create anything in dataByCoordSys,
  71656. // whose length will be used to judge whether dispatch action.
  71657. if (!axisInfo.triggerTooltip || !payloadBatch.length) {
  71658. return;
  71659. }
  71660. var coordSysModel = axisInfo.coordSys.model;
  71661. var coordSysKey = makeKey(coordSysModel);
  71662. var coordSysItem = dataByCoordSys.map[coordSysKey];
  71663. if (!coordSysItem) {
  71664. coordSysItem = dataByCoordSys.map[coordSysKey] = {
  71665. coordSysId: coordSysModel.id,
  71666. coordSysIndex: coordSysModel.componentIndex,
  71667. coordSysType: coordSysModel.type,
  71668. coordSysMainType: coordSysModel.mainType,
  71669. dataByAxis: []
  71670. };
  71671. dataByCoordSys.list.push(coordSysItem);
  71672. }
  71673. coordSysItem.dataByAxis.push({
  71674. axisDim: axis.dim,
  71675. axisIndex: axisModel.componentIndex,
  71676. axisType: axisModel.type,
  71677. axisId: axisModel.id,
  71678. value: value,
  71679. // Caustion: viewHelper.getValueLabel is actually on "view stage", which
  71680. // depends that all models have been updated. So it should not be performed
  71681. // here. Considering axisPointerModel used here is volatile, which is hard
  71682. // to be retrieve in TooltipView, we prepare parameters here.
  71683. valueLabelOpt: {
  71684. precision: axisPointerModel.get(['label', 'precision']),
  71685. formatter: axisPointerModel.get(['label', 'formatter'])
  71686. },
  71687. seriesDataIndices: payloadBatch.slice()
  71688. });
  71689. }
  71690. function updateModelActually(showValueMap, axesInfo, outputPayload) {
  71691. var outputAxesInfo = outputPayload.axesInfo = [];
  71692. // Basic logic: If no 'show' required, 'hide' this axisPointer.
  71693. each(axesInfo, function (axisInfo, key) {
  71694. var option = axisInfo.axisPointerModel.option;
  71695. var valItem = showValueMap[key];
  71696. if (valItem) {
  71697. !axisInfo.useHandle && (option.status = 'show');
  71698. option.value = valItem.value;
  71699. // For label formatter param and highlight.
  71700. option.seriesDataIndices = (valItem.payloadBatch || []).slice();
  71701. }
  71702. // When always show (e.g., handle used), remain
  71703. // original value and status.
  71704. else {
  71705. // If hide, value still need to be set, consider
  71706. // click legend to toggle axis blank.
  71707. !axisInfo.useHandle && (option.status = 'hide');
  71708. }
  71709. // If status is 'hide', should be no info in payload.
  71710. option.status === 'show' && outputAxesInfo.push({
  71711. axisDim: axisInfo.axis.dim,
  71712. axisIndex: axisInfo.axis.model.componentIndex,
  71713. value: option.value
  71714. });
  71715. });
  71716. }
  71717. function dispatchTooltipActually(dataByCoordSys, point, payload, dispatchAction) {
  71718. // Basic logic: If no showTip required, hideTip will be dispatched.
  71719. if (illegalPoint(point) || !dataByCoordSys.list.length) {
  71720. dispatchAction({
  71721. type: 'hideTip'
  71722. });
  71723. return;
  71724. }
  71725. // In most case only one axis (or event one series is used). It is
  71726. // convenient to fetch payload.seriesIndex and payload.dataIndex
  71727. // directly. So put the first seriesIndex and dataIndex of the first
  71728. // axis on the payload.
  71729. var sampleItem = ((dataByCoordSys.list[0].dataByAxis[0] || {}).seriesDataIndices || [])[0] || {};
  71730. dispatchAction({
  71731. type: 'showTip',
  71732. escapeConnect: true,
  71733. x: point[0],
  71734. y: point[1],
  71735. tooltipOption: payload.tooltipOption,
  71736. position: payload.position,
  71737. dataIndexInside: sampleItem.dataIndexInside,
  71738. dataIndex: sampleItem.dataIndex,
  71739. seriesIndex: sampleItem.seriesIndex,
  71740. dataByCoordSys: dataByCoordSys.list
  71741. });
  71742. }
  71743. function dispatchHighDownActually(axesInfo, dispatchAction, api) {
  71744. // FIXME
  71745. // highlight status modification should be a stage of main process?
  71746. // (Consider confilct (e.g., legend and axisPointer) and setOption)
  71747. var zr = api.getZr();
  71748. var highDownKey = 'axisPointerLastHighlights';
  71749. var lastHighlights = inner$e(zr)[highDownKey] || {};
  71750. var newHighlights = inner$e(zr)[highDownKey] = {};
  71751. // Update highlight/downplay status according to axisPointer model.
  71752. // Build hash map and remove duplicate incidentally.
  71753. each(axesInfo, function (axisInfo, key) {
  71754. var option = axisInfo.axisPointerModel.option;
  71755. option.status === 'show' && axisInfo.triggerEmphasis && each(option.seriesDataIndices, function (batchItem) {
  71756. var key = batchItem.seriesIndex + ' | ' + batchItem.dataIndex;
  71757. newHighlights[key] = batchItem;
  71758. });
  71759. });
  71760. // Diff.
  71761. var toHighlight = [];
  71762. var toDownplay = [];
  71763. each(lastHighlights, function (batchItem, key) {
  71764. !newHighlights[key] && toDownplay.push(batchItem);
  71765. });
  71766. each(newHighlights, function (batchItem, key) {
  71767. !lastHighlights[key] && toHighlight.push(batchItem);
  71768. });
  71769. toDownplay.length && api.dispatchAction({
  71770. type: 'downplay',
  71771. escapeConnect: true,
  71772. // Not blur others when highlight in axisPointer.
  71773. notBlur: true,
  71774. batch: toDownplay
  71775. });
  71776. toHighlight.length && api.dispatchAction({
  71777. type: 'highlight',
  71778. escapeConnect: true,
  71779. // Not blur others when highlight in axisPointer.
  71780. notBlur: true,
  71781. batch: toHighlight
  71782. });
  71783. }
  71784. function findInputAxisInfo(inputAxesInfo, axisInfo) {
  71785. for (var i = 0; i < (inputAxesInfo || []).length; i++) {
  71786. var inputAxisInfo = inputAxesInfo[i];
  71787. if (axisInfo.axis.dim === inputAxisInfo.axisDim && axisInfo.axis.model.componentIndex === inputAxisInfo.axisIndex) {
  71788. return inputAxisInfo;
  71789. }
  71790. }
  71791. }
  71792. function makeMapperParam(axisInfo) {
  71793. var axisModel = axisInfo.axis.model;
  71794. var item = {};
  71795. var dim = item.axisDim = axisInfo.axis.dim;
  71796. item.axisIndex = item[dim + 'AxisIndex'] = axisModel.componentIndex;
  71797. item.axisName = item[dim + 'AxisName'] = axisModel.name;
  71798. item.axisId = item[dim + 'AxisId'] = axisModel.id;
  71799. return item;
  71800. }
  71801. function illegalPoint(point) {
  71802. return !point || point[0] == null || isNaN(point[0]) || point[1] == null || isNaN(point[1]);
  71803. }
  71804. function install$t(registers) {
  71805. // CartesianAxisPointer is not supposed to be required here. But consider
  71806. // echarts.simple.js and online build tooltip, which only require gridSimple,
  71807. // CartesianAxisPointer should be able to required somewhere.
  71808. AxisView.registerAxisPointerClass('CartesianAxisPointer', CartesianAxisPointer);
  71809. registers.registerComponentModel(AxisPointerModel);
  71810. registers.registerComponentView(AxisPointerView);
  71811. registers.registerPreprocessor(function (option) {
  71812. // Always has a global axisPointerModel for default setting.
  71813. if (option) {
  71814. (!option.axisPointer || option.axisPointer.length === 0) && (option.axisPointer = {});
  71815. var link = option.axisPointer.link;
  71816. // Normalize to array to avoid object mergin. But if link
  71817. // is not set, remain null/undefined, otherwise it will
  71818. // override existent link setting.
  71819. if (link && !isArray(link)) {
  71820. option.axisPointer.link = [link];
  71821. }
  71822. }
  71823. });
  71824. // This process should proformed after coordinate systems created
  71825. // and series data processed. So put it on statistic processing stage.
  71826. registers.registerProcessor(registers.PRIORITY.PROCESSOR.STATISTIC, function (ecModel, api) {
  71827. // Build axisPointerModel, mergin tooltip.axisPointer model for each axis.
  71828. // allAxesInfo should be updated when setOption performed.
  71829. ecModel.getComponent('axisPointer').coordSysAxesInfo = collect(ecModel, api);
  71830. });
  71831. // Broadcast to all views.
  71832. registers.registerAction({
  71833. type: 'updateAxisPointer',
  71834. event: 'updateAxisPointer',
  71835. update: ':updateAxisPointer'
  71836. }, axisTrigger);
  71837. }
  71838. function install$u(registers) {
  71839. use(install$5);
  71840. use(install$t);
  71841. }
  71842. var PolarAxisPointer = /** @class */function (_super) {
  71843. __extends(PolarAxisPointer, _super);
  71844. function PolarAxisPointer() {
  71845. return _super !== null && _super.apply(this, arguments) || this;
  71846. }
  71847. /**
  71848. * @override
  71849. */
  71850. PolarAxisPointer.prototype.makeElOption = function (elOption, value, axisModel, axisPointerModel, api) {
  71851. var axis = axisModel.axis;
  71852. if (axis.dim === 'angle') {
  71853. this.animationThreshold = Math.PI / 18;
  71854. }
  71855. var polar = axis.polar;
  71856. var otherAxis = polar.getOtherAxis(axis);
  71857. var otherExtent = otherAxis.getExtent();
  71858. var coordValue = axis.dataToCoord(value);
  71859. var axisPointerType = axisPointerModel.get('type');
  71860. if (axisPointerType && axisPointerType !== 'none') {
  71861. var elStyle = buildElStyle(axisPointerModel);
  71862. var pointerOption = pointerShapeBuilder$1[axisPointerType](axis, polar, coordValue, otherExtent);
  71863. pointerOption.style = elStyle;
  71864. elOption.graphicKey = pointerOption.type;
  71865. elOption.pointer = pointerOption;
  71866. }
  71867. var labelMargin = axisPointerModel.get(['label', 'margin']);
  71868. var labelPos = getLabelPosition(value, axisModel, axisPointerModel, polar, labelMargin);
  71869. buildLabelElOption(elOption, axisModel, axisPointerModel, api, labelPos);
  71870. };
  71871. return PolarAxisPointer;
  71872. }(BaseAxisPointer);
  71873. function getLabelPosition(value, axisModel, axisPointerModel, polar, labelMargin) {
  71874. var axis = axisModel.axis;
  71875. var coord = axis.dataToCoord(value);
  71876. var axisAngle = polar.getAngleAxis().getExtent()[0];
  71877. axisAngle = axisAngle / 180 * Math.PI;
  71878. var radiusExtent = polar.getRadiusAxis().getExtent();
  71879. var position;
  71880. var align;
  71881. var verticalAlign;
  71882. if (axis.dim === 'radius') {
  71883. var transform = create$1();
  71884. rotate(transform, transform, axisAngle);
  71885. translate(transform, transform, [polar.cx, polar.cy]);
  71886. position = applyTransform$1([coord, -labelMargin], transform);
  71887. var labelRotation = axisModel.getModel('axisLabel').get('rotate') || 0;
  71888. // @ts-ignore
  71889. var labelLayout = AxisBuilder.innerTextLayout(axisAngle, labelRotation * Math.PI / 180, -1);
  71890. align = labelLayout.textAlign;
  71891. verticalAlign = labelLayout.textVerticalAlign;
  71892. } else {
  71893. // angle axis
  71894. var r = radiusExtent[1];
  71895. position = polar.coordToPoint([r + labelMargin, coord]);
  71896. var cx = polar.cx;
  71897. var cy = polar.cy;
  71898. align = Math.abs(position[0] - cx) / r < 0.3 ? 'center' : position[0] > cx ? 'left' : 'right';
  71899. verticalAlign = Math.abs(position[1] - cy) / r < 0.3 ? 'middle' : position[1] > cy ? 'top' : 'bottom';
  71900. }
  71901. return {
  71902. position: position,
  71903. align: align,
  71904. verticalAlign: verticalAlign
  71905. };
  71906. }
  71907. var pointerShapeBuilder$1 = {
  71908. line: function (axis, polar, coordValue, otherExtent) {
  71909. return axis.dim === 'angle' ? {
  71910. type: 'Line',
  71911. shape: makeLineShape(polar.coordToPoint([otherExtent[0], coordValue]), polar.coordToPoint([otherExtent[1], coordValue]))
  71912. } : {
  71913. type: 'Circle',
  71914. shape: {
  71915. cx: polar.cx,
  71916. cy: polar.cy,
  71917. r: coordValue
  71918. }
  71919. };
  71920. },
  71921. shadow: function (axis, polar, coordValue, otherExtent) {
  71922. var bandWidth = Math.max(1, axis.getBandWidth());
  71923. var radian = Math.PI / 180;
  71924. return axis.dim === 'angle' ? {
  71925. type: 'Sector',
  71926. shape: makeSectorShape(polar.cx, polar.cy, otherExtent[0], otherExtent[1],
  71927. // In ECharts y is negative if angle is positive
  71928. (-coordValue - bandWidth / 2) * radian, (-coordValue + bandWidth / 2) * radian)
  71929. } : {
  71930. type: 'Sector',
  71931. shape: makeSectorShape(polar.cx, polar.cy, coordValue - bandWidth / 2, coordValue + bandWidth / 2, 0, Math.PI * 2)
  71932. };
  71933. }
  71934. };
  71935. var PolarModel = /** @class */function (_super) {
  71936. __extends(PolarModel, _super);
  71937. function PolarModel() {
  71938. var _this = _super !== null && _super.apply(this, arguments) || this;
  71939. _this.type = PolarModel.type;
  71940. return _this;
  71941. }
  71942. PolarModel.prototype.findAxisModel = function (axisType) {
  71943. var foundAxisModel;
  71944. var ecModel = this.ecModel;
  71945. ecModel.eachComponent(axisType, function (axisModel) {
  71946. if (axisModel.getCoordSysModel() === this) {
  71947. foundAxisModel = axisModel;
  71948. }
  71949. }, this);
  71950. return foundAxisModel;
  71951. };
  71952. PolarModel.type = 'polar';
  71953. PolarModel.dependencies = ['radiusAxis', 'angleAxis'];
  71954. PolarModel.defaultOption = {
  71955. // zlevel: 0,
  71956. z: 0,
  71957. center: ['50%', '50%'],
  71958. radius: '80%'
  71959. };
  71960. return PolarModel;
  71961. }(ComponentModel);
  71962. var PolarAxisModel = /** @class */function (_super) {
  71963. __extends(PolarAxisModel, _super);
  71964. function PolarAxisModel() {
  71965. return _super !== null && _super.apply(this, arguments) || this;
  71966. }
  71967. PolarAxisModel.prototype.getCoordSysModel = function () {
  71968. return this.getReferringComponents('polar', SINGLE_REFERRING).models[0];
  71969. };
  71970. PolarAxisModel.type = 'polarAxis';
  71971. return PolarAxisModel;
  71972. }(ComponentModel);
  71973. mixin(PolarAxisModel, AxisModelCommonMixin);
  71974. var AngleAxisModel = /** @class */function (_super) {
  71975. __extends(AngleAxisModel, _super);
  71976. function AngleAxisModel() {
  71977. var _this = _super !== null && _super.apply(this, arguments) || this;
  71978. _this.type = AngleAxisModel.type;
  71979. return _this;
  71980. }
  71981. AngleAxisModel.type = 'angleAxis';
  71982. return AngleAxisModel;
  71983. }(PolarAxisModel);
  71984. var RadiusAxisModel = /** @class */function (_super) {
  71985. __extends(RadiusAxisModel, _super);
  71986. function RadiusAxisModel() {
  71987. var _this = _super !== null && _super.apply(this, arguments) || this;
  71988. _this.type = RadiusAxisModel.type;
  71989. return _this;
  71990. }
  71991. RadiusAxisModel.type = 'radiusAxis';
  71992. return RadiusAxisModel;
  71993. }(PolarAxisModel);
  71994. var RadiusAxis = /** @class */function (_super) {
  71995. __extends(RadiusAxis, _super);
  71996. function RadiusAxis(scale, radiusExtent) {
  71997. return _super.call(this, 'radius', scale, radiusExtent) || this;
  71998. }
  71999. RadiusAxis.prototype.pointToData = function (point, clamp) {
  72000. return this.polar.pointToData(point, clamp)[this.dim === 'radius' ? 0 : 1];
  72001. };
  72002. return RadiusAxis;
  72003. }(Axis);
  72004. RadiusAxis.prototype.dataToRadius = Axis.prototype.dataToCoord;
  72005. RadiusAxis.prototype.radiusToData = Axis.prototype.coordToData;
  72006. var inner$f = makeInner();
  72007. var AngleAxis = /** @class */function (_super) {
  72008. __extends(AngleAxis, _super);
  72009. function AngleAxis(scale, angleExtent) {
  72010. return _super.call(this, 'angle', scale, angleExtent || [0, 360]) || this;
  72011. }
  72012. AngleAxis.prototype.pointToData = function (point, clamp) {
  72013. return this.polar.pointToData(point, clamp)[this.dim === 'radius' ? 0 : 1];
  72014. };
  72015. /**
  72016. * Only be called in category axis.
  72017. * Angle axis uses text height to decide interval
  72018. *
  72019. * @override
  72020. * @return {number} Auto interval for cateogry axis tick and label
  72021. */
  72022. AngleAxis.prototype.calculateCategoryInterval = function () {
  72023. var axis = this;
  72024. var labelModel = axis.getLabelModel();
  72025. var ordinalScale = axis.scale;
  72026. var ordinalExtent = ordinalScale.getExtent();
  72027. // Providing this method is for optimization:
  72028. // avoid generating a long array by `getTicks`
  72029. // in large category data case.
  72030. var tickCount = ordinalScale.count();
  72031. if (ordinalExtent[1] - ordinalExtent[0] < 1) {
  72032. return 0;
  72033. }
  72034. var tickValue = ordinalExtent[0];
  72035. var unitSpan = axis.dataToCoord(tickValue + 1) - axis.dataToCoord(tickValue);
  72036. var unitH = Math.abs(unitSpan);
  72037. // Not precise, just use height as text width
  72038. // and each distance from axis line yet.
  72039. var rect = getBoundingRect(tickValue == null ? '' : tickValue + '', labelModel.getFont(), 'center', 'top');
  72040. var maxH = Math.max(rect.height, 7);
  72041. var dh = maxH / unitH;
  72042. // 0/0 is NaN, 1/0 is Infinity.
  72043. isNaN(dh) && (dh = Infinity);
  72044. var interval = Math.max(0, Math.floor(dh));
  72045. var cache = inner$f(axis.model);
  72046. var lastAutoInterval = cache.lastAutoInterval;
  72047. var lastTickCount = cache.lastTickCount;
  72048. // Use cache to keep interval stable while moving zoom window,
  72049. // otherwise the calculated interval might jitter when the zoom
  72050. // window size is close to the interval-changing size.
  72051. if (lastAutoInterval != null && lastTickCount != null && Math.abs(lastAutoInterval - interval) <= 1 && Math.abs(lastTickCount - tickCount) <= 1
  72052. // Always choose the bigger one, otherwise the critical
  72053. // point is not the same when zooming in or zooming out.
  72054. && lastAutoInterval > interval) {
  72055. interval = lastAutoInterval;
  72056. }
  72057. // Only update cache if cache not used, otherwise the
  72058. // changing of interval is too insensitive.
  72059. else {
  72060. cache.lastTickCount = tickCount;
  72061. cache.lastAutoInterval = interval;
  72062. }
  72063. return interval;
  72064. };
  72065. return AngleAxis;
  72066. }(Axis);
  72067. AngleAxis.prototype.dataToAngle = Axis.prototype.dataToCoord;
  72068. AngleAxis.prototype.angleToData = Axis.prototype.coordToData;
  72069. var polarDimensions = ['radius', 'angle'];
  72070. var Polar = /** @class */function () {
  72071. function Polar(name) {
  72072. this.dimensions = polarDimensions;
  72073. this.type = 'polar';
  72074. /**
  72075. * x of polar center
  72076. */
  72077. this.cx = 0;
  72078. /**
  72079. * y of polar center
  72080. */
  72081. this.cy = 0;
  72082. this._radiusAxis = new RadiusAxis();
  72083. this._angleAxis = new AngleAxis();
  72084. this.axisPointerEnabled = true;
  72085. this.name = name || '';
  72086. this._radiusAxis.polar = this._angleAxis.polar = this;
  72087. }
  72088. /**
  72089. * If contain coord
  72090. */
  72091. Polar.prototype.containPoint = function (point) {
  72092. var coord = this.pointToCoord(point);
  72093. return this._radiusAxis.contain(coord[0]) && this._angleAxis.contain(coord[1]);
  72094. };
  72095. /**
  72096. * If contain data
  72097. */
  72098. Polar.prototype.containData = function (data) {
  72099. return this._radiusAxis.containData(data[0]) && this._angleAxis.containData(data[1]);
  72100. };
  72101. Polar.prototype.getAxis = function (dim) {
  72102. var key = '_' + dim + 'Axis';
  72103. return this[key];
  72104. };
  72105. Polar.prototype.getAxes = function () {
  72106. return [this._radiusAxis, this._angleAxis];
  72107. };
  72108. /**
  72109. * Get axes by type of scale
  72110. */
  72111. Polar.prototype.getAxesByScale = function (scaleType) {
  72112. var axes = [];
  72113. var angleAxis = this._angleAxis;
  72114. var radiusAxis = this._radiusAxis;
  72115. angleAxis.scale.type === scaleType && axes.push(angleAxis);
  72116. radiusAxis.scale.type === scaleType && axes.push(radiusAxis);
  72117. return axes;
  72118. };
  72119. Polar.prototype.getAngleAxis = function () {
  72120. return this._angleAxis;
  72121. };
  72122. Polar.prototype.getRadiusAxis = function () {
  72123. return this._radiusAxis;
  72124. };
  72125. Polar.prototype.getOtherAxis = function (axis) {
  72126. var angleAxis = this._angleAxis;
  72127. return axis === angleAxis ? this._radiusAxis : angleAxis;
  72128. };
  72129. /**
  72130. * Base axis will be used on stacking.
  72131. *
  72132. */
  72133. Polar.prototype.getBaseAxis = function () {
  72134. return this.getAxesByScale('ordinal')[0] || this.getAxesByScale('time')[0] || this.getAngleAxis();
  72135. };
  72136. Polar.prototype.getTooltipAxes = function (dim) {
  72137. var baseAxis = dim != null && dim !== 'auto' ? this.getAxis(dim) : this.getBaseAxis();
  72138. return {
  72139. baseAxes: [baseAxis],
  72140. otherAxes: [this.getOtherAxis(baseAxis)]
  72141. };
  72142. };
  72143. /**
  72144. * Convert a single data item to (x, y) point.
  72145. * Parameter data is an array which the first element is radius and the second is angle
  72146. */
  72147. Polar.prototype.dataToPoint = function (data, clamp, out) {
  72148. return this.coordToPoint([this._radiusAxis.dataToRadius(data[0], clamp), this._angleAxis.dataToAngle(data[1], clamp)], out);
  72149. };
  72150. /**
  72151. * Convert a (x, y) point to data
  72152. */
  72153. Polar.prototype.pointToData = function (point, clamp, out) {
  72154. out = out || [];
  72155. var coord = this.pointToCoord(point);
  72156. out[0] = this._radiusAxis.radiusToData(coord[0], clamp);
  72157. out[1] = this._angleAxis.angleToData(coord[1], clamp);
  72158. return out;
  72159. };
  72160. /**
  72161. * Convert a (x, y) point to (radius, angle) coord
  72162. */
  72163. Polar.prototype.pointToCoord = function (point) {
  72164. var dx = point[0] - this.cx;
  72165. var dy = point[1] - this.cy;
  72166. var angleAxis = this.getAngleAxis();
  72167. var extent = angleAxis.getExtent();
  72168. var minAngle = Math.min(extent[0], extent[1]);
  72169. var maxAngle = Math.max(extent[0], extent[1]);
  72170. // Fix fixed extent in polarCreator
  72171. // FIXME
  72172. angleAxis.inverse ? minAngle = maxAngle - 360 : maxAngle = minAngle + 360;
  72173. var radius = Math.sqrt(dx * dx + dy * dy);
  72174. dx /= radius;
  72175. dy /= radius;
  72176. var radian = Math.atan2(-dy, dx) / Math.PI * 180;
  72177. // move to angleExtent
  72178. var dir = radian < minAngle ? 1 : -1;
  72179. while (radian < minAngle || radian > maxAngle) {
  72180. radian += dir * 360;
  72181. }
  72182. return [radius, radian];
  72183. };
  72184. /**
  72185. * Convert a (radius, angle) coord to (x, y) point
  72186. */
  72187. Polar.prototype.coordToPoint = function (coord, out) {
  72188. out = out || [];
  72189. var radius = coord[0];
  72190. var radian = coord[1] / 180 * Math.PI;
  72191. out[0] = Math.cos(radian) * radius + this.cx;
  72192. // Inverse the y
  72193. out[1] = -Math.sin(radian) * radius + this.cy;
  72194. return out;
  72195. };
  72196. /**
  72197. * Get ring area of cartesian.
  72198. * Area will have a contain function to determine if a point is in the coordinate system.
  72199. */
  72200. Polar.prototype.getArea = function () {
  72201. var angleAxis = this.getAngleAxis();
  72202. var radiusAxis = this.getRadiusAxis();
  72203. var radiusExtent = radiusAxis.getExtent().slice();
  72204. radiusExtent[0] > radiusExtent[1] && radiusExtent.reverse();
  72205. var angleExtent = angleAxis.getExtent();
  72206. var RADIAN = Math.PI / 180;
  72207. var EPSILON = 1e-4;
  72208. return {
  72209. cx: this.cx,
  72210. cy: this.cy,
  72211. r0: radiusExtent[0],
  72212. r: radiusExtent[1],
  72213. startAngle: -angleExtent[0] * RADIAN,
  72214. endAngle: -angleExtent[1] * RADIAN,
  72215. clockwise: angleAxis.inverse,
  72216. contain: function (x, y) {
  72217. // It's a ring shape.
  72218. // Start angle and end angle don't matter
  72219. var dx = x - this.cx;
  72220. var dy = y - this.cy;
  72221. var d2 = dx * dx + dy * dy;
  72222. var r = this.r;
  72223. var r0 = this.r0;
  72224. // minus a tiny value 1e-4 in double side to avoid being clipped unexpectedly
  72225. // r == r0 contain nothing
  72226. return r !== r0 && d2 - EPSILON <= r * r && d2 + EPSILON >= r0 * r0;
  72227. },
  72228. // As the bounding box
  72229. x: this.cx - radiusExtent[1],
  72230. y: this.cy - radiusExtent[1],
  72231. width: radiusExtent[1] * 2,
  72232. height: radiusExtent[1] * 2
  72233. };
  72234. };
  72235. Polar.prototype.convertToPixel = function (ecModel, finder, value) {
  72236. var coordSys = getCoordSys$2(finder);
  72237. return coordSys === this ? this.dataToPoint(value) : null;
  72238. };
  72239. Polar.prototype.convertFromPixel = function (ecModel, finder, pixel) {
  72240. var coordSys = getCoordSys$2(finder);
  72241. return coordSys === this ? this.pointToData(pixel) : null;
  72242. };
  72243. return Polar;
  72244. }();
  72245. function getCoordSys$2(finder) {
  72246. var seriesModel = finder.seriesModel;
  72247. var polarModel = finder.polarModel;
  72248. return polarModel && polarModel.coordinateSystem || seriesModel && seriesModel.coordinateSystem;
  72249. }
  72250. /**
  72251. * Resize method bound to the polar
  72252. */
  72253. function resizePolar(polar, polarModel, api) {
  72254. var center = polarModel.get('center');
  72255. var refContainer = createBoxLayoutReference(polarModel, api).refContainer;
  72256. polar.cx = parsePercent$1(center[0], refContainer.width) + refContainer.x;
  72257. polar.cy = parsePercent$1(center[1], refContainer.height) + refContainer.y;
  72258. var radiusAxis = polar.getRadiusAxis();
  72259. var size = Math.min(refContainer.width, refContainer.height) / 2;
  72260. var radius = polarModel.get('radius');
  72261. if (radius == null) {
  72262. radius = [0, '100%'];
  72263. } else if (!isArray(radius)) {
  72264. // r0 = 0
  72265. radius = [0, radius];
  72266. }
  72267. var parsedRadius = [parsePercent$1(radius[0], size), parsePercent$1(radius[1], size)];
  72268. radiusAxis.inverse ? radiusAxis.setExtent(parsedRadius[1], parsedRadius[0]) : radiusAxis.setExtent(parsedRadius[0], parsedRadius[1]);
  72269. }
  72270. /**
  72271. * Update polar
  72272. */
  72273. function updatePolarScale(ecModel, api) {
  72274. var polar = this;
  72275. var angleAxis = polar.getAngleAxis();
  72276. var radiusAxis = polar.getRadiusAxis();
  72277. // Reset scale
  72278. angleAxis.scale.setExtent(Infinity, -Infinity);
  72279. radiusAxis.scale.setExtent(Infinity, -Infinity);
  72280. ecModel.eachSeries(function (seriesModel) {
  72281. if (seriesModel.coordinateSystem === polar) {
  72282. var data_1 = seriesModel.getData();
  72283. each(getDataDimensionsOnAxis(data_1, 'radius'), function (dim) {
  72284. radiusAxis.scale.unionExtentFromData(data_1, dim);
  72285. });
  72286. each(getDataDimensionsOnAxis(data_1, 'angle'), function (dim) {
  72287. angleAxis.scale.unionExtentFromData(data_1, dim);
  72288. });
  72289. }
  72290. });
  72291. niceScaleExtent(angleAxis.scale, angleAxis.model);
  72292. niceScaleExtent(radiusAxis.scale, radiusAxis.model);
  72293. // Fix extent of category angle axis
  72294. if (angleAxis.type === 'category' && !angleAxis.onBand) {
  72295. var extent = angleAxis.getExtent();
  72296. var diff = 360 / angleAxis.scale.count();
  72297. angleAxis.inverse ? extent[1] += diff : extent[1] -= diff;
  72298. angleAxis.setExtent(extent[0], extent[1]);
  72299. }
  72300. }
  72301. function isAngleAxisModel(axisModel) {
  72302. return axisModel.mainType === 'angleAxis';
  72303. }
  72304. /**
  72305. * Set common axis properties
  72306. */
  72307. function setAxis(axis, axisModel) {
  72308. var _a;
  72309. axis.type = axisModel.get('type');
  72310. axis.scale = createScaleByModel(axisModel);
  72311. axis.onBand = axisModel.get('boundaryGap') && axis.type === 'category';
  72312. axis.inverse = axisModel.get('inverse');
  72313. if (isAngleAxisModel(axisModel)) {
  72314. axis.inverse = axis.inverse !== axisModel.get('clockwise');
  72315. var startAngle = axisModel.get('startAngle');
  72316. var endAngle = (_a = axisModel.get('endAngle')) !== null && _a !== void 0 ? _a : startAngle + (axis.inverse ? -360 : 360);
  72317. axis.setExtent(startAngle, endAngle);
  72318. }
  72319. // Inject axis instance
  72320. axisModel.axis = axis;
  72321. axis.model = axisModel;
  72322. }
  72323. var polarCreator = {
  72324. dimensions: polarDimensions,
  72325. create: function (ecModel, api) {
  72326. var polarList = [];
  72327. ecModel.eachComponent('polar', function (polarModel, idx) {
  72328. var polar = new Polar(idx + '');
  72329. // Inject resize and update method
  72330. polar.update = updatePolarScale;
  72331. var radiusAxis = polar.getRadiusAxis();
  72332. var angleAxis = polar.getAngleAxis();
  72333. var radiusAxisModel = polarModel.findAxisModel('radiusAxis');
  72334. var angleAxisModel = polarModel.findAxisModel('angleAxis');
  72335. setAxis(radiusAxis, radiusAxisModel);
  72336. setAxis(angleAxis, angleAxisModel);
  72337. resizePolar(polar, polarModel, api);
  72338. polarList.push(polar);
  72339. polarModel.coordinateSystem = polar;
  72340. polar.model = polarModel;
  72341. });
  72342. // Inject coordinateSystem to series
  72343. ecModel.eachSeries(function (seriesModel) {
  72344. if (seriesModel.get('coordinateSystem') === 'polar') {
  72345. var polarModel = seriesModel.getReferringComponents('polar', SINGLE_REFERRING).models[0];
  72346. if ("development" !== 'production') {
  72347. if (!polarModel) {
  72348. throw new Error('Polar "' + retrieve(seriesModel.get('polarIndex'), seriesModel.get('polarId'), 0) + '" not found');
  72349. }
  72350. }
  72351. seriesModel.coordinateSystem = polarModel.coordinateSystem;
  72352. }
  72353. });
  72354. return polarList;
  72355. }
  72356. };
  72357. var elementList = ['axisLine', 'axisLabel', 'axisTick', 'minorTick', 'splitLine', 'minorSplitLine', 'splitArea'];
  72358. function getAxisLineShape(polar, rExtent, angle) {
  72359. rExtent[1] > rExtent[0] && (rExtent = rExtent.slice().reverse());
  72360. var start = polar.coordToPoint([rExtent[0], angle]);
  72361. var end = polar.coordToPoint([rExtent[1], angle]);
  72362. return {
  72363. x1: start[0],
  72364. y1: start[1],
  72365. x2: end[0],
  72366. y2: end[1]
  72367. };
  72368. }
  72369. function getRadiusIdx(polar) {
  72370. var radiusAxis = polar.getRadiusAxis();
  72371. return radiusAxis.inverse ? 0 : 1;
  72372. }
  72373. // Remove the last tick which will overlap the first tick
  72374. function fixAngleOverlap(list) {
  72375. var firstItem = list[0];
  72376. var lastItem = list[list.length - 1];
  72377. if (firstItem && lastItem && Math.abs(Math.abs(firstItem.coord - lastItem.coord) - 360) < 1e-4) {
  72378. list.pop();
  72379. }
  72380. }
  72381. var AngleAxisView = /** @class */function (_super) {
  72382. __extends(AngleAxisView, _super);
  72383. function AngleAxisView() {
  72384. var _this = _super !== null && _super.apply(this, arguments) || this;
  72385. _this.type = AngleAxisView.type;
  72386. _this.axisPointerClass = 'PolarAxisPointer';
  72387. return _this;
  72388. }
  72389. AngleAxisView.prototype.render = function (angleAxisModel, ecModel) {
  72390. this.group.removeAll();
  72391. if (!angleAxisModel.get('show')) {
  72392. return;
  72393. }
  72394. var angleAxis = angleAxisModel.axis;
  72395. var polar = angleAxis.polar;
  72396. var radiusExtent = polar.getRadiusAxis().getExtent();
  72397. var ticksAngles = angleAxis.getTicksCoords({
  72398. breakTicks: 'none'
  72399. });
  72400. var minorTickAngles = angleAxis.getMinorTicksCoords();
  72401. var labels = map(angleAxis.getViewLabels(), function (labelItem) {
  72402. labelItem = clone(labelItem);
  72403. var scale = angleAxis.scale;
  72404. var tickValue = scale.type === 'ordinal' ? scale.getRawOrdinalNumber(labelItem.tickValue) : labelItem.tickValue;
  72405. labelItem.coord = angleAxis.dataToCoord(tickValue);
  72406. return labelItem;
  72407. });
  72408. fixAngleOverlap(labels);
  72409. fixAngleOverlap(ticksAngles);
  72410. each(elementList, function (name) {
  72411. if (angleAxisModel.get([name, 'show']) && (!angleAxis.scale.isBlank() || name === 'axisLine')) {
  72412. angelAxisElementsBuilders[name](this.group, angleAxisModel, polar, ticksAngles, minorTickAngles, radiusExtent, labels);
  72413. }
  72414. }, this);
  72415. };
  72416. AngleAxisView.type = 'angleAxis';
  72417. return AngleAxisView;
  72418. }(AxisView);
  72419. var angelAxisElementsBuilders = {
  72420. axisLine: function (group, angleAxisModel, polar, ticksAngles, minorTickAngles, radiusExtent) {
  72421. var lineStyleModel = angleAxisModel.getModel(['axisLine', 'lineStyle']);
  72422. var angleAxis = polar.getAngleAxis();
  72423. var RADIAN = Math.PI / 180;
  72424. var angleExtent = angleAxis.getExtent();
  72425. // extent id of the axis radius (r0 and r)
  72426. var rId = getRadiusIdx(polar);
  72427. var r0Id = rId ? 0 : 1;
  72428. var shape;
  72429. var shapeType = Math.abs(angleExtent[1] - angleExtent[0]) === 360 ? 'Circle' : 'Arc';
  72430. if (radiusExtent[r0Id] === 0) {
  72431. shape = new graphic[shapeType]({
  72432. shape: {
  72433. cx: polar.cx,
  72434. cy: polar.cy,
  72435. r: radiusExtent[rId],
  72436. startAngle: -angleExtent[0] * RADIAN,
  72437. endAngle: -angleExtent[1] * RADIAN,
  72438. clockwise: angleAxis.inverse
  72439. },
  72440. style: lineStyleModel.getLineStyle(),
  72441. z2: 1,
  72442. silent: true
  72443. });
  72444. } else {
  72445. shape = new Ring({
  72446. shape: {
  72447. cx: polar.cx,
  72448. cy: polar.cy,
  72449. r: radiusExtent[rId],
  72450. r0: radiusExtent[r0Id]
  72451. },
  72452. style: lineStyleModel.getLineStyle(),
  72453. z2: 1,
  72454. silent: true
  72455. });
  72456. }
  72457. shape.style.fill = null;
  72458. group.add(shape);
  72459. },
  72460. axisTick: function (group, angleAxisModel, polar, ticksAngles, minorTickAngles, radiusExtent) {
  72461. var tickModel = angleAxisModel.getModel('axisTick');
  72462. var tickLen = (tickModel.get('inside') ? -1 : 1) * tickModel.get('length');
  72463. var radius = radiusExtent[getRadiusIdx(polar)];
  72464. var lines = map(ticksAngles, function (tickAngleItem) {
  72465. return new Line({
  72466. shape: getAxisLineShape(polar, [radius, radius + tickLen], tickAngleItem.coord)
  72467. });
  72468. });
  72469. group.add(mergePath$1(lines, {
  72470. style: defaults(tickModel.getModel('lineStyle').getLineStyle(), {
  72471. stroke: angleAxisModel.get(['axisLine', 'lineStyle', 'color'])
  72472. })
  72473. }));
  72474. },
  72475. minorTick: function (group, angleAxisModel, polar, tickAngles, minorTickAngles, radiusExtent) {
  72476. if (!minorTickAngles.length) {
  72477. return;
  72478. }
  72479. var tickModel = angleAxisModel.getModel('axisTick');
  72480. var minorTickModel = angleAxisModel.getModel('minorTick');
  72481. var tickLen = (tickModel.get('inside') ? -1 : 1) * minorTickModel.get('length');
  72482. var radius = radiusExtent[getRadiusIdx(polar)];
  72483. var lines = [];
  72484. for (var i = 0; i < minorTickAngles.length; i++) {
  72485. for (var k = 0; k < minorTickAngles[i].length; k++) {
  72486. lines.push(new Line({
  72487. shape: getAxisLineShape(polar, [radius, radius + tickLen], minorTickAngles[i][k].coord)
  72488. }));
  72489. }
  72490. }
  72491. group.add(mergePath$1(lines, {
  72492. style: defaults(minorTickModel.getModel('lineStyle').getLineStyle(), defaults(tickModel.getLineStyle(), {
  72493. stroke: angleAxisModel.get(['axisLine', 'lineStyle', 'color'])
  72494. }))
  72495. }));
  72496. },
  72497. axisLabel: function (group, angleAxisModel, polar, ticksAngles, minorTickAngles, radiusExtent, labels) {
  72498. var rawCategoryData = angleAxisModel.getCategories(true);
  72499. var commonLabelModel = angleAxisModel.getModel('axisLabel');
  72500. var labelMargin = commonLabelModel.get('margin');
  72501. var triggerEvent = angleAxisModel.get('triggerEvent');
  72502. // Use length of ticksAngles because it may remove the last tick to avoid overlapping
  72503. each(labels, function (labelItem, idx) {
  72504. var labelModel = commonLabelModel;
  72505. var tickValue = labelItem.tickValue;
  72506. var r = radiusExtent[getRadiusIdx(polar)];
  72507. var p = polar.coordToPoint([r + labelMargin, labelItem.coord]);
  72508. var cx = polar.cx;
  72509. var cy = polar.cy;
  72510. var labelTextAlign = Math.abs(p[0] - cx) / r < 0.3 ? 'center' : p[0] > cx ? 'left' : 'right';
  72511. var labelTextVerticalAlign = Math.abs(p[1] - cy) / r < 0.3 ? 'middle' : p[1] > cy ? 'top' : 'bottom';
  72512. if (rawCategoryData && rawCategoryData[tickValue]) {
  72513. var rawCategoryItem = rawCategoryData[tickValue];
  72514. if (isObject(rawCategoryItem) && rawCategoryItem.textStyle) {
  72515. labelModel = new Model(rawCategoryItem.textStyle, commonLabelModel, commonLabelModel.ecModel);
  72516. }
  72517. }
  72518. var textEl = new ZRText({
  72519. silent: AxisBuilder.isLabelSilent(angleAxisModel),
  72520. style: createTextStyle(labelModel, {
  72521. x: p[0],
  72522. y: p[1],
  72523. fill: labelModel.getTextColor() || angleAxisModel.get(['axisLine', 'lineStyle', 'color']),
  72524. text: labelItem.formattedLabel,
  72525. align: labelTextAlign,
  72526. verticalAlign: labelTextVerticalAlign
  72527. })
  72528. });
  72529. group.add(textEl);
  72530. setTooltipConfig({
  72531. el: textEl,
  72532. componentModel: angleAxisModel,
  72533. itemName: labelItem.formattedLabel,
  72534. formatterParamsExtra: {
  72535. isTruncated: function () {
  72536. return textEl.isTruncated;
  72537. },
  72538. value: labelItem.rawLabel,
  72539. tickIndex: idx
  72540. }
  72541. });
  72542. // Pack data for mouse event
  72543. if (triggerEvent) {
  72544. var eventData = AxisBuilder.makeAxisEventDataBase(angleAxisModel);
  72545. eventData.targetType = 'axisLabel';
  72546. eventData.value = labelItem.rawLabel;
  72547. getECData(textEl).eventData = eventData;
  72548. }
  72549. }, this);
  72550. },
  72551. splitLine: function (group, angleAxisModel, polar, ticksAngles, minorTickAngles, radiusExtent) {
  72552. var splitLineModel = angleAxisModel.getModel('splitLine');
  72553. var lineStyleModel = splitLineModel.getModel('lineStyle');
  72554. var lineColors = lineStyleModel.get('color');
  72555. var lineCount = 0;
  72556. lineColors = lineColors instanceof Array ? lineColors : [lineColors];
  72557. var splitLines = [];
  72558. for (var i = 0; i < ticksAngles.length; i++) {
  72559. var colorIndex = lineCount++ % lineColors.length;
  72560. splitLines[colorIndex] = splitLines[colorIndex] || [];
  72561. splitLines[colorIndex].push(new Line({
  72562. shape: getAxisLineShape(polar, radiusExtent, ticksAngles[i].coord)
  72563. }));
  72564. }
  72565. // Simple optimization
  72566. // Batching the lines if color are the same
  72567. for (var i = 0; i < splitLines.length; i++) {
  72568. group.add(mergePath$1(splitLines[i], {
  72569. style: defaults({
  72570. stroke: lineColors[i % lineColors.length]
  72571. }, lineStyleModel.getLineStyle()),
  72572. silent: true,
  72573. z: angleAxisModel.get('z')
  72574. }));
  72575. }
  72576. },
  72577. minorSplitLine: function (group, angleAxisModel, polar, ticksAngles, minorTickAngles, radiusExtent) {
  72578. if (!minorTickAngles.length) {
  72579. return;
  72580. }
  72581. var minorSplitLineModel = angleAxisModel.getModel('minorSplitLine');
  72582. var lineStyleModel = minorSplitLineModel.getModel('lineStyle');
  72583. var lines = [];
  72584. for (var i = 0; i < minorTickAngles.length; i++) {
  72585. for (var k = 0; k < minorTickAngles[i].length; k++) {
  72586. lines.push(new Line({
  72587. shape: getAxisLineShape(polar, radiusExtent, minorTickAngles[i][k].coord)
  72588. }));
  72589. }
  72590. }
  72591. group.add(mergePath$1(lines, {
  72592. style: lineStyleModel.getLineStyle(),
  72593. silent: true,
  72594. z: angleAxisModel.get('z')
  72595. }));
  72596. },
  72597. splitArea: function (group, angleAxisModel, polar, ticksAngles, minorTickAngles, radiusExtent) {
  72598. if (!ticksAngles.length) {
  72599. return;
  72600. }
  72601. var splitAreaModel = angleAxisModel.getModel('splitArea');
  72602. var areaStyleModel = splitAreaModel.getModel('areaStyle');
  72603. var areaColors = areaStyleModel.get('color');
  72604. var lineCount = 0;
  72605. areaColors = areaColors instanceof Array ? areaColors : [areaColors];
  72606. var splitAreas = [];
  72607. var RADIAN = Math.PI / 180;
  72608. var prevAngle = -ticksAngles[0].coord * RADIAN;
  72609. var r0 = Math.min(radiusExtent[0], radiusExtent[1]);
  72610. var r1 = Math.max(radiusExtent[0], radiusExtent[1]);
  72611. var clockwise = angleAxisModel.get('clockwise');
  72612. for (var i = 1, len = ticksAngles.length; i <= len; i++) {
  72613. var coord = i === len ? ticksAngles[0].coord : ticksAngles[i].coord;
  72614. var colorIndex = lineCount++ % areaColors.length;
  72615. splitAreas[colorIndex] = splitAreas[colorIndex] || [];
  72616. splitAreas[colorIndex].push(new Sector({
  72617. shape: {
  72618. cx: polar.cx,
  72619. cy: polar.cy,
  72620. r0: r0,
  72621. r: r1,
  72622. startAngle: prevAngle,
  72623. endAngle: -coord * RADIAN,
  72624. clockwise: clockwise
  72625. },
  72626. silent: true
  72627. }));
  72628. prevAngle = -coord * RADIAN;
  72629. }
  72630. // Simple optimization
  72631. // Batching the lines if color are the same
  72632. for (var i = 0; i < splitAreas.length; i++) {
  72633. group.add(mergePath$1(splitAreas[i], {
  72634. style: defaults({
  72635. fill: areaColors[i % areaColors.length]
  72636. }, areaStyleModel.getAreaStyle()),
  72637. silent: true
  72638. }));
  72639. }
  72640. }
  72641. };
  72642. var selfBuilderAttrs$1 = ['splitLine', 'splitArea', 'minorSplitLine'];
  72643. var RadiusAxisView = /** @class */function (_super) {
  72644. __extends(RadiusAxisView, _super);
  72645. function RadiusAxisView() {
  72646. var _this = _super !== null && _super.apply(this, arguments) || this;
  72647. _this.type = RadiusAxisView.type;
  72648. _this.axisPointerClass = 'PolarAxisPointer';
  72649. return _this;
  72650. }
  72651. RadiusAxisView.prototype.render = function (radiusAxisModel, ecModel, api) {
  72652. this.group.removeAll();
  72653. if (!radiusAxisModel.get('show')) {
  72654. return;
  72655. }
  72656. var oldAxisGroup = this._axisGroup;
  72657. var newAxisGroup = this._axisGroup = new Group();
  72658. this.group.add(newAxisGroup);
  72659. var radiusAxis = radiusAxisModel.axis;
  72660. var polar = radiusAxis.polar;
  72661. var angleAxis = polar.getAngleAxis();
  72662. var ticksCoords = radiusAxis.getTicksCoords();
  72663. var minorTicksCoords = radiusAxis.getMinorTicksCoords();
  72664. var axisAngle = angleAxis.getExtent()[0];
  72665. var radiusExtent = radiusAxis.getExtent();
  72666. var layout = layoutAxis(polar, radiusAxisModel, axisAngle);
  72667. var axisBuilder = new AxisBuilder(radiusAxisModel, api, layout);
  72668. axisBuilder.build();
  72669. newAxisGroup.add(axisBuilder.group);
  72670. groupTransition(oldAxisGroup, newAxisGroup, radiusAxisModel);
  72671. each(selfBuilderAttrs$1, function (name) {
  72672. if (radiusAxisModel.get([name, 'show']) && !radiusAxis.scale.isBlank()) {
  72673. axisElementBuilders$1[name](this.group, radiusAxisModel, polar, axisAngle, radiusExtent, ticksCoords, minorTicksCoords);
  72674. }
  72675. }, this);
  72676. };
  72677. RadiusAxisView.type = 'radiusAxis';
  72678. return RadiusAxisView;
  72679. }(AxisView);
  72680. var axisElementBuilders$1 = {
  72681. splitLine: function (group, radiusAxisModel, polar, axisAngle, radiusExtent, ticksCoords) {
  72682. var splitLineModel = radiusAxisModel.getModel('splitLine');
  72683. var lineStyleModel = splitLineModel.getModel('lineStyle');
  72684. var lineColors = lineStyleModel.get('color');
  72685. var lineCount = 0;
  72686. var angleAxis = polar.getAngleAxis();
  72687. var RADIAN = Math.PI / 180;
  72688. var angleExtent = angleAxis.getExtent();
  72689. var shapeType = Math.abs(angleExtent[1] - angleExtent[0]) === 360 ? 'Circle' : 'Arc';
  72690. lineColors = lineColors instanceof Array ? lineColors : [lineColors];
  72691. var splitLines = [];
  72692. for (var i = 0; i < ticksCoords.length; i++) {
  72693. var colorIndex = lineCount++ % lineColors.length;
  72694. splitLines[colorIndex] = splitLines[colorIndex] || [];
  72695. splitLines[colorIndex].push(new graphic[shapeType]({
  72696. shape: {
  72697. cx: polar.cx,
  72698. cy: polar.cy,
  72699. // ensure circle radius >= 0
  72700. r: Math.max(ticksCoords[i].coord, 0),
  72701. startAngle: -angleExtent[0] * RADIAN,
  72702. endAngle: -angleExtent[1] * RADIAN,
  72703. clockwise: angleAxis.inverse
  72704. }
  72705. }));
  72706. }
  72707. // Simple optimization
  72708. // Batching the lines if color are the same
  72709. for (var i = 0; i < splitLines.length; i++) {
  72710. group.add(mergePath$1(splitLines[i], {
  72711. style: defaults({
  72712. stroke: lineColors[i % lineColors.length],
  72713. fill: null
  72714. }, lineStyleModel.getLineStyle()),
  72715. silent: true
  72716. }));
  72717. }
  72718. },
  72719. minorSplitLine: function (group, radiusAxisModel, polar, axisAngle, radiusExtent, ticksCoords, minorTicksCoords) {
  72720. if (!minorTicksCoords.length) {
  72721. return;
  72722. }
  72723. var minorSplitLineModel = radiusAxisModel.getModel('minorSplitLine');
  72724. var lineStyleModel = minorSplitLineModel.getModel('lineStyle');
  72725. var lines = [];
  72726. for (var i = 0; i < minorTicksCoords.length; i++) {
  72727. for (var k = 0; k < minorTicksCoords[i].length; k++) {
  72728. lines.push(new Circle({
  72729. shape: {
  72730. cx: polar.cx,
  72731. cy: polar.cy,
  72732. r: minorTicksCoords[i][k].coord
  72733. }
  72734. }));
  72735. }
  72736. }
  72737. group.add(mergePath$1(lines, {
  72738. style: defaults({
  72739. fill: null
  72740. }, lineStyleModel.getLineStyle()),
  72741. silent: true
  72742. }));
  72743. },
  72744. splitArea: function (group, radiusAxisModel, polar, axisAngle, radiusExtent, ticksCoords) {
  72745. if (!ticksCoords.length) {
  72746. return;
  72747. }
  72748. var splitAreaModel = radiusAxisModel.getModel('splitArea');
  72749. var areaStyleModel = splitAreaModel.getModel('areaStyle');
  72750. var areaColors = areaStyleModel.get('color');
  72751. var lineCount = 0;
  72752. areaColors = areaColors instanceof Array ? areaColors : [areaColors];
  72753. var splitAreas = [];
  72754. var prevRadius = ticksCoords[0].coord;
  72755. for (var i = 1; i < ticksCoords.length; i++) {
  72756. var colorIndex = lineCount++ % areaColors.length;
  72757. splitAreas[colorIndex] = splitAreas[colorIndex] || [];
  72758. splitAreas[colorIndex].push(new Sector({
  72759. shape: {
  72760. cx: polar.cx,
  72761. cy: polar.cy,
  72762. r0: prevRadius,
  72763. r: ticksCoords[i].coord,
  72764. startAngle: 0,
  72765. endAngle: Math.PI * 2
  72766. },
  72767. silent: true
  72768. }));
  72769. prevRadius = ticksCoords[i].coord;
  72770. }
  72771. // Simple optimization
  72772. // Batching the lines if color are the same
  72773. for (var i = 0; i < splitAreas.length; i++) {
  72774. group.add(mergePath$1(splitAreas[i], {
  72775. style: defaults({
  72776. fill: areaColors[i % areaColors.length]
  72777. }, areaStyleModel.getAreaStyle()),
  72778. silent: true
  72779. }));
  72780. }
  72781. }
  72782. };
  72783. /**
  72784. * @inner
  72785. */
  72786. function layoutAxis(polar, radiusAxisModel, axisAngle) {
  72787. return {
  72788. position: [polar.cx, polar.cy],
  72789. rotation: axisAngle / 180 * Math.PI,
  72790. labelDirection: -1,
  72791. tickDirection: -1,
  72792. nameDirection: 1,
  72793. labelRotate: radiusAxisModel.getModel('axisLabel').get('rotate'),
  72794. // Over splitLine and splitArea
  72795. z2: 1
  72796. };
  72797. }
  72798. function getSeriesStackId$1(seriesModel) {
  72799. return seriesModel.get('stack') || '__ec_stack_' + seriesModel.seriesIndex;
  72800. }
  72801. function getAxisKey$1(polar, axis) {
  72802. return axis.dim + polar.model.componentIndex;
  72803. }
  72804. function barLayoutPolar(seriesType, ecModel, api) {
  72805. var lastStackCoords = {};
  72806. var barWidthAndOffset = calRadialBar(filter(ecModel.getSeriesByType(seriesType), function (seriesModel) {
  72807. return !ecModel.isSeriesFiltered(seriesModel) && seriesModel.coordinateSystem && seriesModel.coordinateSystem.type === 'polar';
  72808. }));
  72809. ecModel.eachSeriesByType(seriesType, function (seriesModel) {
  72810. // Check series coordinate, do layout for polar only
  72811. if (seriesModel.coordinateSystem.type !== 'polar') {
  72812. return;
  72813. }
  72814. var data = seriesModel.getData();
  72815. var polar = seriesModel.coordinateSystem;
  72816. var baseAxis = polar.getBaseAxis();
  72817. var axisKey = getAxisKey$1(polar, baseAxis);
  72818. var stackId = getSeriesStackId$1(seriesModel);
  72819. var columnLayoutInfo = barWidthAndOffset[axisKey][stackId];
  72820. var columnOffset = columnLayoutInfo.offset;
  72821. var columnWidth = columnLayoutInfo.width;
  72822. var valueAxis = polar.getOtherAxis(baseAxis);
  72823. var cx = seriesModel.coordinateSystem.cx;
  72824. var cy = seriesModel.coordinateSystem.cy;
  72825. var barMinHeight = seriesModel.get('barMinHeight') || 0;
  72826. var barMinAngle = seriesModel.get('barMinAngle') || 0;
  72827. lastStackCoords[stackId] = lastStackCoords[stackId] || [];
  72828. var valueDim = data.mapDimension(valueAxis.dim);
  72829. var baseDim = data.mapDimension(baseAxis.dim);
  72830. var stacked = isDimensionStacked(data, valueDim /* , baseDim */);
  72831. var clampLayout = baseAxis.dim !== 'radius' || !seriesModel.get('roundCap', true);
  72832. var valueAxisModel = valueAxis.model;
  72833. var startValue = valueAxisModel.get('startValue');
  72834. var valueAxisStart = valueAxis.dataToCoord(startValue || 0);
  72835. for (var idx = 0, len = data.count(); idx < len; idx++) {
  72836. var value = data.get(valueDim, idx);
  72837. var baseValue = data.get(baseDim, idx);
  72838. var sign = value >= 0 ? 'p' : 'n';
  72839. var baseCoord = valueAxisStart;
  72840. // Because of the barMinHeight, we can not use the value in
  72841. // stackResultDimension directly.
  72842. // Only ordinal axis can be stacked.
  72843. if (stacked) {
  72844. if (!lastStackCoords[stackId][baseValue]) {
  72845. lastStackCoords[stackId][baseValue] = {
  72846. p: valueAxisStart,
  72847. n: valueAxisStart // Negative stack
  72848. };
  72849. }
  72850. // Should also consider #4243
  72851. baseCoord = lastStackCoords[stackId][baseValue][sign];
  72852. }
  72853. var r0 = void 0;
  72854. var r = void 0;
  72855. var startAngle = void 0;
  72856. var endAngle = void 0;
  72857. // radial sector
  72858. if (valueAxis.dim === 'radius') {
  72859. var radiusSpan = valueAxis.dataToCoord(value) - valueAxisStart;
  72860. var angle = baseAxis.dataToCoord(baseValue);
  72861. if (Math.abs(radiusSpan) < barMinHeight) {
  72862. radiusSpan = (radiusSpan < 0 ? -1 : 1) * barMinHeight;
  72863. }
  72864. r0 = baseCoord;
  72865. r = baseCoord + radiusSpan;
  72866. startAngle = angle - columnOffset;
  72867. endAngle = startAngle - columnWidth;
  72868. stacked && (lastStackCoords[stackId][baseValue][sign] = r);
  72869. }
  72870. // tangential sector
  72871. else {
  72872. var angleSpan = valueAxis.dataToCoord(value, clampLayout) - valueAxisStart;
  72873. var radius = baseAxis.dataToCoord(baseValue);
  72874. if (Math.abs(angleSpan) < barMinAngle) {
  72875. angleSpan = (angleSpan < 0 ? -1 : 1) * barMinAngle;
  72876. }
  72877. r0 = radius + columnOffset;
  72878. r = r0 + columnWidth;
  72879. startAngle = baseCoord;
  72880. endAngle = baseCoord + angleSpan;
  72881. // if the previous stack is at the end of the ring,
  72882. // add a round to differentiate it from origin
  72883. // let extent = angleAxis.getExtent();
  72884. // let stackCoord = angle;
  72885. // if (stackCoord === extent[0] && value > 0) {
  72886. // stackCoord = extent[1];
  72887. // }
  72888. // else if (stackCoord === extent[1] && value < 0) {
  72889. // stackCoord = extent[0];
  72890. // }
  72891. stacked && (lastStackCoords[stackId][baseValue][sign] = endAngle);
  72892. }
  72893. data.setItemLayout(idx, {
  72894. cx: cx,
  72895. cy: cy,
  72896. r0: r0,
  72897. r: r,
  72898. // Consider that positive angle is anti-clockwise,
  72899. // while positive radian of sector is clockwise
  72900. startAngle: -startAngle * Math.PI / 180,
  72901. endAngle: -endAngle * Math.PI / 180,
  72902. /**
  72903. * Keep the same logic with bar in catesion: use end value to
  72904. * control direction. Notice that if clockwise is true (by
  72905. * default), the sector will always draw clockwisely, no matter
  72906. * whether endAngle is greater or less than startAngle.
  72907. */
  72908. clockwise: startAngle >= endAngle
  72909. });
  72910. }
  72911. });
  72912. }
  72913. /**
  72914. * Calculate bar width and offset for radial bar charts
  72915. */
  72916. function calRadialBar(barSeries) {
  72917. // Columns info on each category axis. Key is polar name
  72918. var columnsMap = {};
  72919. each(barSeries, function (seriesModel, idx) {
  72920. var data = seriesModel.getData();
  72921. var polar = seriesModel.coordinateSystem;
  72922. var baseAxis = polar.getBaseAxis();
  72923. var axisKey = getAxisKey$1(polar, baseAxis);
  72924. var axisExtent = baseAxis.getExtent();
  72925. var bandWidth = baseAxis.type === 'category' ? baseAxis.getBandWidth() : Math.abs(axisExtent[1] - axisExtent[0]) / data.count();
  72926. var columnsOnAxis = columnsMap[axisKey] || {
  72927. bandWidth: bandWidth,
  72928. remainedWidth: bandWidth,
  72929. autoWidthCount: 0,
  72930. categoryGap: '20%',
  72931. gap: '30%',
  72932. stacks: {}
  72933. };
  72934. var stacks = columnsOnAxis.stacks;
  72935. columnsMap[axisKey] = columnsOnAxis;
  72936. var stackId = getSeriesStackId$1(seriesModel);
  72937. if (!stacks[stackId]) {
  72938. columnsOnAxis.autoWidthCount++;
  72939. }
  72940. stacks[stackId] = stacks[stackId] || {
  72941. width: 0,
  72942. maxWidth: 0
  72943. };
  72944. var barWidth = parsePercent$1(seriesModel.get('barWidth'), bandWidth);
  72945. var barMaxWidth = parsePercent$1(seriesModel.get('barMaxWidth'), bandWidth);
  72946. var barGap = seriesModel.get('barGap');
  72947. var barCategoryGap = seriesModel.get('barCategoryGap');
  72948. if (barWidth && !stacks[stackId].width) {
  72949. barWidth = Math.min(columnsOnAxis.remainedWidth, barWidth);
  72950. stacks[stackId].width = barWidth;
  72951. columnsOnAxis.remainedWidth -= barWidth;
  72952. }
  72953. barMaxWidth && (stacks[stackId].maxWidth = barMaxWidth);
  72954. barGap != null && (columnsOnAxis.gap = barGap);
  72955. barCategoryGap != null && (columnsOnAxis.categoryGap = barCategoryGap);
  72956. });
  72957. var result = {};
  72958. each(columnsMap, function (columnsOnAxis, coordSysName) {
  72959. result[coordSysName] = {};
  72960. var stacks = columnsOnAxis.stacks;
  72961. var bandWidth = columnsOnAxis.bandWidth;
  72962. var categoryGap = parsePercent$1(columnsOnAxis.categoryGap, bandWidth);
  72963. var barGapPercent = parsePercent$1(columnsOnAxis.gap, 1);
  72964. var remainedWidth = columnsOnAxis.remainedWidth;
  72965. var autoWidthCount = columnsOnAxis.autoWidthCount;
  72966. var autoWidth = (remainedWidth - categoryGap) / (autoWidthCount + (autoWidthCount - 1) * barGapPercent);
  72967. autoWidth = Math.max(autoWidth, 0);
  72968. // Find if any auto calculated bar exceeded maxBarWidth
  72969. each(stacks, function (column, stack) {
  72970. var maxWidth = column.maxWidth;
  72971. if (maxWidth && maxWidth < autoWidth) {
  72972. maxWidth = Math.min(maxWidth, remainedWidth);
  72973. if (column.width) {
  72974. maxWidth = Math.min(maxWidth, column.width);
  72975. }
  72976. remainedWidth -= maxWidth;
  72977. column.width = maxWidth;
  72978. autoWidthCount--;
  72979. }
  72980. });
  72981. // Recalculate width again
  72982. autoWidth = (remainedWidth - categoryGap) / (autoWidthCount + (autoWidthCount - 1) * barGapPercent);
  72983. autoWidth = Math.max(autoWidth, 0);
  72984. var widthSum = 0;
  72985. var lastColumn;
  72986. each(stacks, function (column, idx) {
  72987. if (!column.width) {
  72988. column.width = autoWidth;
  72989. }
  72990. lastColumn = column;
  72991. widthSum += column.width * (1 + barGapPercent);
  72992. });
  72993. if (lastColumn) {
  72994. widthSum -= lastColumn.width * barGapPercent;
  72995. }
  72996. var offset = -widthSum / 2;
  72997. each(stacks, function (column, stackId) {
  72998. result[coordSysName][stackId] = result[coordSysName][stackId] || {
  72999. offset: offset,
  73000. width: column.width
  73001. };
  73002. offset += column.width * (1 + barGapPercent);
  73003. });
  73004. });
  73005. return result;
  73006. }
  73007. var angleAxisExtraOption = {
  73008. startAngle: 90,
  73009. clockwise: true,
  73010. splitNumber: 12,
  73011. axisLabel: {
  73012. rotate: 0
  73013. }
  73014. };
  73015. var radiusAxisExtraOption = {
  73016. splitNumber: 5
  73017. };
  73018. var PolarView = /** @class */function (_super) {
  73019. __extends(PolarView, _super);
  73020. function PolarView() {
  73021. var _this = _super !== null && _super.apply(this, arguments) || this;
  73022. _this.type = PolarView.type;
  73023. return _this;
  73024. }
  73025. PolarView.type = 'polar';
  73026. return PolarView;
  73027. }(ComponentView);
  73028. function install$v(registers) {
  73029. use(install$t);
  73030. AxisView.registerAxisPointerClass('PolarAxisPointer', PolarAxisPointer);
  73031. registers.registerCoordinateSystem('polar', polarCreator);
  73032. registers.registerComponentModel(PolarModel);
  73033. registers.registerComponentView(PolarView);
  73034. // Model and view for angleAxis and radiusAxis
  73035. axisModelCreator(registers, 'angle', AngleAxisModel, angleAxisExtraOption);
  73036. axisModelCreator(registers, 'radius', RadiusAxisModel, radiusAxisExtraOption);
  73037. registers.registerComponentView(AngleAxisView);
  73038. registers.registerComponentView(RadiusAxisView);
  73039. registers.registerLayout(curry(barLayoutPolar, 'bar'));
  73040. }
  73041. function layout$2(axisModel, opt) {
  73042. opt = opt || {};
  73043. var single = axisModel.coordinateSystem;
  73044. var axis = axisModel.axis;
  73045. var layout = {};
  73046. var axisPosition = axis.position;
  73047. var orient = axis.orient;
  73048. var rect = single.getRect();
  73049. var rectBound = [rect.x, rect.x + rect.width, rect.y, rect.y + rect.height];
  73050. var positionMap = {
  73051. horizontal: {
  73052. top: rectBound[2],
  73053. bottom: rectBound[3]
  73054. },
  73055. vertical: {
  73056. left: rectBound[0],
  73057. right: rectBound[1]
  73058. }
  73059. };
  73060. layout.position = [orient === 'vertical' ? positionMap.vertical[axisPosition] : rectBound[0], orient === 'horizontal' ? positionMap.horizontal[axisPosition] : rectBound[3]];
  73061. var r = {
  73062. horizontal: 0,
  73063. vertical: 1
  73064. };
  73065. layout.rotation = Math.PI / 2 * r[orient];
  73066. var directionMap = {
  73067. top: -1,
  73068. bottom: 1,
  73069. right: 1,
  73070. left: -1
  73071. };
  73072. layout.labelDirection = layout.tickDirection = layout.nameDirection = directionMap[axisPosition];
  73073. if (axisModel.get(['axisTick', 'inside'])) {
  73074. layout.tickDirection = -layout.tickDirection;
  73075. }
  73076. if (retrieve(opt.labelInside, axisModel.get(['axisLabel', 'inside']))) {
  73077. layout.labelDirection = -layout.labelDirection;
  73078. }
  73079. var labelRotate = axisModel.get(['axisLabel', 'rotate']);
  73080. layout.labelRotate = axisPosition === 'top' ? -labelRotate : labelRotate;
  73081. layout.z2 = 1;
  73082. return layout;
  73083. }
  73084. var selfBuilderAttrs$2 = ['splitArea', 'splitLine', 'breakArea'];
  73085. var SingleAxisView = /** @class */function (_super) {
  73086. __extends(SingleAxisView, _super);
  73087. function SingleAxisView() {
  73088. var _this = _super !== null && _super.apply(this, arguments) || this;
  73089. _this.type = SingleAxisView.type;
  73090. _this.axisPointerClass = 'SingleAxisPointer';
  73091. return _this;
  73092. }
  73093. SingleAxisView.prototype.render = function (axisModel, ecModel, api, payload) {
  73094. var group = this.group;
  73095. group.removeAll();
  73096. var oldAxisGroup = this._axisGroup;
  73097. this._axisGroup = new Group();
  73098. var layout = layout$2(axisModel);
  73099. var axisBuilder = new AxisBuilder(axisModel, api, layout);
  73100. axisBuilder.build();
  73101. group.add(this._axisGroup);
  73102. group.add(axisBuilder.group);
  73103. each(selfBuilderAttrs$2, function (name) {
  73104. if (axisModel.get([name, 'show'])) {
  73105. axisElementBuilders$2[name](this, this.group, this._axisGroup, axisModel, api);
  73106. }
  73107. }, this);
  73108. groupTransition(oldAxisGroup, this._axisGroup, axisModel);
  73109. _super.prototype.render.call(this, axisModel, ecModel, api, payload);
  73110. };
  73111. SingleAxisView.prototype.remove = function () {
  73112. rectCoordAxisHandleRemove(this);
  73113. };
  73114. SingleAxisView.type = 'singleAxis';
  73115. return SingleAxisView;
  73116. }(AxisView);
  73117. var axisElementBuilders$2 = {
  73118. splitLine: function (axisView, group, axisGroup, axisModel, api) {
  73119. var axis = axisModel.axis;
  73120. if (axis.scale.isBlank()) {
  73121. return;
  73122. }
  73123. var splitLineModel = axisModel.getModel('splitLine');
  73124. var lineStyleModel = splitLineModel.getModel('lineStyle');
  73125. var lineColors = lineStyleModel.get('color');
  73126. lineColors = lineColors instanceof Array ? lineColors : [lineColors];
  73127. var lineWidth = lineStyleModel.get('width');
  73128. var gridRect = axisModel.coordinateSystem.getRect();
  73129. var isHorizontal = axis.isHorizontal();
  73130. var splitLines = [];
  73131. var lineCount = 0;
  73132. var ticksCoords = axis.getTicksCoords({
  73133. tickModel: splitLineModel,
  73134. breakTicks: 'none',
  73135. pruneByBreak: 'preserve_extent_bound'
  73136. });
  73137. var p1 = [];
  73138. var p2 = [];
  73139. for (var i = 0; i < ticksCoords.length; ++i) {
  73140. var tickCoord = axis.toGlobalCoord(ticksCoords[i].coord);
  73141. if (isHorizontal) {
  73142. p1[0] = tickCoord;
  73143. p1[1] = gridRect.y;
  73144. p2[0] = tickCoord;
  73145. p2[1] = gridRect.y + gridRect.height;
  73146. } else {
  73147. p1[0] = gridRect.x;
  73148. p1[1] = tickCoord;
  73149. p2[0] = gridRect.x + gridRect.width;
  73150. p2[1] = tickCoord;
  73151. }
  73152. var line = new Line({
  73153. shape: {
  73154. x1: p1[0],
  73155. y1: p1[1],
  73156. x2: p2[0],
  73157. y2: p2[1]
  73158. },
  73159. silent: true
  73160. });
  73161. subPixelOptimizeLine$1(line.shape, lineWidth);
  73162. var colorIndex = lineCount++ % lineColors.length;
  73163. splitLines[colorIndex] = splitLines[colorIndex] || [];
  73164. splitLines[colorIndex].push(line);
  73165. }
  73166. var lineStyle = lineStyleModel.getLineStyle(['color']);
  73167. for (var i = 0; i < splitLines.length; ++i) {
  73168. group.add(mergePath$1(splitLines[i], {
  73169. style: defaults({
  73170. stroke: lineColors[i % lineColors.length]
  73171. }, lineStyle),
  73172. silent: true
  73173. }));
  73174. }
  73175. },
  73176. splitArea: function (axisView, group, axisGroup, axisModel, api) {
  73177. rectCoordAxisBuildSplitArea(axisView, axisGroup, axisModel, axisModel);
  73178. },
  73179. breakArea: function (axisView, group, axisGroup, axisModel, api) {
  73180. var axisBreakHelper = getAxisBreakHelper();
  73181. var scale = axisModel.axis.scale;
  73182. if (axisBreakHelper && scale.type !== 'ordinal') {
  73183. axisBreakHelper.rectCoordBuildBreakAxis(group, axisView, axisModel, axisModel.coordinateSystem.getRect(), api);
  73184. }
  73185. }
  73186. };
  73187. var SingleAxisModel = /** @class */function (_super) {
  73188. __extends(SingleAxisModel, _super);
  73189. function SingleAxisModel() {
  73190. var _this = _super !== null && _super.apply(this, arguments) || this;
  73191. _this.type = SingleAxisModel.type;
  73192. return _this;
  73193. }
  73194. SingleAxisModel.prototype.getCoordSysModel = function () {
  73195. return this;
  73196. };
  73197. SingleAxisModel.type = 'singleAxis';
  73198. SingleAxisModel.layoutMode = 'box';
  73199. SingleAxisModel.defaultOption = {
  73200. left: '5%',
  73201. top: '5%',
  73202. right: '5%',
  73203. bottom: '5%',
  73204. type: 'value',
  73205. position: 'bottom',
  73206. orient: 'horizontal',
  73207. axisLine: {
  73208. show: true,
  73209. lineStyle: {
  73210. width: 1,
  73211. type: 'solid'
  73212. }
  73213. },
  73214. // Single coordinate system and single axis is the,
  73215. // which is used as the parent tooltip model.
  73216. // same model, so we set default tooltip show as true.
  73217. tooltip: {
  73218. show: true
  73219. },
  73220. axisTick: {
  73221. show: true,
  73222. length: 6,
  73223. lineStyle: {
  73224. width: 1
  73225. }
  73226. },
  73227. axisLabel: {
  73228. show: true,
  73229. interval: 'auto'
  73230. },
  73231. splitLine: {
  73232. show: true,
  73233. lineStyle: {
  73234. type: 'dashed',
  73235. opacity: 0.2
  73236. }
  73237. },
  73238. jitter: 0,
  73239. jitterOverlap: true,
  73240. jitterMargin: 2
  73241. };
  73242. return SingleAxisModel;
  73243. }(ComponentModel);
  73244. mixin(SingleAxisModel, AxisModelCommonMixin.prototype);
  73245. var SingleAxis = /** @class */function (_super) {
  73246. __extends(SingleAxis, _super);
  73247. function SingleAxis(dim, scale, coordExtent, axisType, position) {
  73248. var _this = _super.call(this, dim, scale, coordExtent) || this;
  73249. _this.type = axisType || 'value';
  73250. _this.position = position || 'bottom';
  73251. return _this;
  73252. }
  73253. /**
  73254. * Judge the orient of the axis.
  73255. */
  73256. SingleAxis.prototype.isHorizontal = function () {
  73257. var position = this.position;
  73258. return position === 'top' || position === 'bottom';
  73259. };
  73260. SingleAxis.prototype.pointToData = function (point, clamp) {
  73261. return this.coordinateSystem.pointToData(point)[0];
  73262. };
  73263. return SingleAxis;
  73264. }(Axis);
  73265. var singleDimensions = ['single'];
  73266. /**
  73267. * Create a single coordinates system.
  73268. */
  73269. var Single = /** @class */function () {
  73270. function Single(axisModel, ecModel, api) {
  73271. this.type = 'single';
  73272. this.dimension = 'single';
  73273. /**
  73274. * Add it just for draw tooltip.
  73275. */
  73276. this.dimensions = singleDimensions;
  73277. this.axisPointerEnabled = true;
  73278. this.model = axisModel;
  73279. this._init(axisModel, ecModel, api);
  73280. }
  73281. /**
  73282. * Initialize single coordinate system.
  73283. */
  73284. Single.prototype._init = function (axisModel, ecModel, api) {
  73285. var dim = this.dimension;
  73286. var axis = new SingleAxis(dim, createScaleByModel(axisModel), [0, 0], axisModel.get('type'), axisModel.get('position'));
  73287. var isCategory = axis.type === 'category';
  73288. axis.onBand = isCategory && axisModel.get('boundaryGap');
  73289. axis.inverse = axisModel.get('inverse');
  73290. axis.orient = axisModel.get('orient');
  73291. axisModel.axis = axis;
  73292. axis.model = axisModel;
  73293. axis.coordinateSystem = this;
  73294. this._axis = axis;
  73295. };
  73296. /**
  73297. * Update axis scale after data processed
  73298. */
  73299. Single.prototype.update = function (ecModel, api) {
  73300. ecModel.eachSeries(function (seriesModel) {
  73301. if (seriesModel.coordinateSystem === this) {
  73302. var data_1 = seriesModel.getData();
  73303. each(data_1.mapDimensionsAll(this.dimension), function (dim) {
  73304. this._axis.scale.unionExtentFromData(data_1, dim);
  73305. }, this);
  73306. niceScaleExtent(this._axis.scale, this._axis.model);
  73307. }
  73308. }, this);
  73309. };
  73310. /**
  73311. * Resize the single coordinate system.
  73312. */
  73313. Single.prototype.resize = function (axisModel, api) {
  73314. var refContainer = createBoxLayoutReference(axisModel, api).refContainer;
  73315. this._rect = getLayoutRect(axisModel.getBoxLayoutParams(), refContainer);
  73316. this._adjustAxis();
  73317. };
  73318. Single.prototype.getRect = function () {
  73319. return this._rect;
  73320. };
  73321. Single.prototype._adjustAxis = function () {
  73322. var rect = this._rect;
  73323. var axis = this._axis;
  73324. var isHorizontal = axis.isHorizontal();
  73325. var extent = isHorizontal ? [0, rect.width] : [0, rect.height];
  73326. var idx = axis.inverse ? 1 : 0;
  73327. axis.setExtent(extent[idx], extent[1 - idx]);
  73328. this._updateAxisTransform(axis, isHorizontal ? rect.x : rect.y);
  73329. };
  73330. Single.prototype._updateAxisTransform = function (axis, coordBase) {
  73331. var axisExtent = axis.getExtent();
  73332. var extentSum = axisExtent[0] + axisExtent[1];
  73333. var isHorizontal = axis.isHorizontal();
  73334. axis.toGlobalCoord = isHorizontal ? function (coord) {
  73335. return coord + coordBase;
  73336. } : function (coord) {
  73337. return extentSum - coord + coordBase;
  73338. };
  73339. axis.toLocalCoord = isHorizontal ? function (coord) {
  73340. return coord - coordBase;
  73341. } : function (coord) {
  73342. return extentSum - coord + coordBase;
  73343. };
  73344. };
  73345. /**
  73346. * Get axis.
  73347. */
  73348. Single.prototype.getAxis = function () {
  73349. return this._axis;
  73350. };
  73351. /**
  73352. * Get axis, add it just for draw tooltip.
  73353. */
  73354. Single.prototype.getBaseAxis = function () {
  73355. return this._axis;
  73356. };
  73357. Single.prototype.getAxes = function () {
  73358. return [this._axis];
  73359. };
  73360. Single.prototype.getTooltipAxes = function () {
  73361. return {
  73362. baseAxes: [this.getAxis()],
  73363. // Empty otherAxes
  73364. otherAxes: []
  73365. };
  73366. };
  73367. /**
  73368. * If contain point.
  73369. */
  73370. Single.prototype.containPoint = function (point) {
  73371. var rect = this.getRect();
  73372. var axis = this.getAxis();
  73373. var orient = axis.orient;
  73374. if (orient === 'horizontal') {
  73375. return axis.contain(axis.toLocalCoord(point[0])) && point[1] >= rect.y && point[1] <= rect.y + rect.height;
  73376. } else {
  73377. return axis.contain(axis.toLocalCoord(point[1])) && point[0] >= rect.y && point[0] <= rect.y + rect.height;
  73378. }
  73379. };
  73380. Single.prototype.pointToData = function (point, reserved, out) {
  73381. out = out || [];
  73382. var axis = this.getAxis();
  73383. out[0] = axis.coordToData(axis.toLocalCoord(point[axis.orient === 'horizontal' ? 0 : 1]));
  73384. return out;
  73385. };
  73386. /**
  73387. * Convert the series data to concrete point.
  73388. * Can be [val] | val
  73389. */
  73390. Single.prototype.dataToPoint = function (val, reserved, out) {
  73391. var axis = this.getAxis();
  73392. var rect = this.getRect();
  73393. out = out || [];
  73394. var idx = axis.orient === 'horizontal' ? 0 : 1;
  73395. if (val instanceof Array) {
  73396. val = val[0];
  73397. }
  73398. out[idx] = axis.toGlobalCoord(axis.dataToCoord(+val));
  73399. out[1 - idx] = idx === 0 ? rect.y + rect.height / 2 : rect.x + rect.width / 2;
  73400. return out;
  73401. };
  73402. Single.prototype.convertToPixel = function (ecModel, finder, value) {
  73403. var coordSys = getCoordSys$3(finder);
  73404. return coordSys === this ? this.dataToPoint(value) : null;
  73405. };
  73406. Single.prototype.convertFromPixel = function (ecModel, finder, pixel) {
  73407. var coordSys = getCoordSys$3(finder);
  73408. return coordSys === this ? this.pointToData(pixel) : null;
  73409. };
  73410. return Single;
  73411. }();
  73412. function getCoordSys$3(finder) {
  73413. var seriesModel = finder.seriesModel;
  73414. var singleModel = finder.singleAxisModel;
  73415. return singleModel && singleModel.coordinateSystem || seriesModel && seriesModel.coordinateSystem;
  73416. }
  73417. /**
  73418. * Create single coordinate system and inject it into seriesModel.
  73419. */
  73420. function create$2(ecModel, api) {
  73421. var singles = [];
  73422. ecModel.eachComponent('singleAxis', function (axisModel, idx) {
  73423. var single = new Single(axisModel, ecModel, api);
  73424. single.name = 'single_' + idx;
  73425. single.resize(axisModel, api);
  73426. axisModel.coordinateSystem = single;
  73427. singles.push(single);
  73428. });
  73429. ecModel.eachSeries(function (seriesModel) {
  73430. if (seriesModel.get('coordinateSystem') === 'singleAxis') {
  73431. var singleAxisModel = seriesModel.getReferringComponents('singleAxis', SINGLE_REFERRING).models[0];
  73432. seriesModel.coordinateSystem = singleAxisModel && singleAxisModel.coordinateSystem;
  73433. }
  73434. });
  73435. return singles;
  73436. }
  73437. var singleCreator = {
  73438. create: create$2,
  73439. dimensions: singleDimensions
  73440. };
  73441. var XY$2 = ['x', 'y'];
  73442. var WH$2 = ['width', 'height'];
  73443. var SingleAxisPointer = /** @class */function (_super) {
  73444. __extends(SingleAxisPointer, _super);
  73445. function SingleAxisPointer() {
  73446. return _super !== null && _super.apply(this, arguments) || this;
  73447. }
  73448. /**
  73449. * @override
  73450. */
  73451. SingleAxisPointer.prototype.makeElOption = function (elOption, value, axisModel, axisPointerModel, api) {
  73452. var axis = axisModel.axis;
  73453. var coordSys = axis.coordinateSystem;
  73454. var otherExtent = getGlobalExtent(coordSys, 1 - getPointDimIndex(axis));
  73455. var pixelValue = coordSys.dataToPoint(value)[0];
  73456. var axisPointerType = axisPointerModel.get('type');
  73457. if (axisPointerType && axisPointerType !== 'none') {
  73458. var elStyle = buildElStyle(axisPointerModel);
  73459. var pointerOption = pointerShapeBuilder$2[axisPointerType](axis, pixelValue, otherExtent);
  73460. pointerOption.style = elStyle;
  73461. elOption.graphicKey = pointerOption.type;
  73462. elOption.pointer = pointerOption;
  73463. }
  73464. var layoutInfo = layout$2(axisModel);
  73465. buildCartesianSingleLabelElOption(value, elOption, layoutInfo, axisModel, axisPointerModel, api);
  73466. };
  73467. /**
  73468. * @override
  73469. */
  73470. SingleAxisPointer.prototype.getHandleTransform = function (value, axisModel, axisPointerModel) {
  73471. var layoutInfo = layout$2(axisModel, {
  73472. labelInside: false
  73473. });
  73474. layoutInfo.labelMargin = axisPointerModel.get(['handle', 'margin']);
  73475. var position = getTransformedPosition(axisModel.axis, value, layoutInfo);
  73476. return {
  73477. x: position[0],
  73478. y: position[1],
  73479. rotation: layoutInfo.rotation + (layoutInfo.labelDirection < 0 ? Math.PI : 0)
  73480. };
  73481. };
  73482. /**
  73483. * @override
  73484. */
  73485. SingleAxisPointer.prototype.updateHandleTransform = function (transform, delta, axisModel, axisPointerModel) {
  73486. var axis = axisModel.axis;
  73487. var coordSys = axis.coordinateSystem;
  73488. var dimIndex = getPointDimIndex(axis);
  73489. var axisExtent = getGlobalExtent(coordSys, dimIndex);
  73490. var currPosition = [transform.x, transform.y];
  73491. currPosition[dimIndex] += delta[dimIndex];
  73492. currPosition[dimIndex] = Math.min(axisExtent[1], currPosition[dimIndex]);
  73493. currPosition[dimIndex] = Math.max(axisExtent[0], currPosition[dimIndex]);
  73494. var otherExtent = getGlobalExtent(coordSys, 1 - dimIndex);
  73495. var cursorOtherValue = (otherExtent[1] + otherExtent[0]) / 2;
  73496. var cursorPoint = [cursorOtherValue, cursorOtherValue];
  73497. cursorPoint[dimIndex] = currPosition[dimIndex];
  73498. return {
  73499. x: currPosition[0],
  73500. y: currPosition[1],
  73501. rotation: transform.rotation,
  73502. cursorPoint: cursorPoint,
  73503. tooltipOption: {
  73504. verticalAlign: 'middle'
  73505. }
  73506. };
  73507. };
  73508. return SingleAxisPointer;
  73509. }(BaseAxisPointer);
  73510. var pointerShapeBuilder$2 = {
  73511. line: function (axis, pixelValue, otherExtent) {
  73512. var targetShape = makeLineShape([pixelValue, otherExtent[0]], [pixelValue, otherExtent[1]], getPointDimIndex(axis));
  73513. return {
  73514. type: 'Line',
  73515. subPixelOptimize: true,
  73516. shape: targetShape
  73517. };
  73518. },
  73519. shadow: function (axis, pixelValue, otherExtent) {
  73520. var bandWidth = axis.getBandWidth();
  73521. var span = otherExtent[1] - otherExtent[0];
  73522. return {
  73523. type: 'Rect',
  73524. shape: makeRectShape([pixelValue - bandWidth / 2, otherExtent[0]], [bandWidth, span], getPointDimIndex(axis))
  73525. };
  73526. }
  73527. };
  73528. function getPointDimIndex(axis) {
  73529. return axis.isHorizontal() ? 0 : 1;
  73530. }
  73531. function getGlobalExtent(coordSys, dimIndex) {
  73532. var rect = coordSys.getRect();
  73533. return [rect[XY$2[dimIndex]], rect[XY$2[dimIndex]] + rect[WH$2[dimIndex]]];
  73534. }
  73535. var SingleView = /** @class */function (_super) {
  73536. __extends(SingleView, _super);
  73537. function SingleView() {
  73538. var _this = _super !== null && _super.apply(this, arguments) || this;
  73539. _this.type = SingleView.type;
  73540. return _this;
  73541. }
  73542. SingleView.type = 'single';
  73543. return SingleView;
  73544. }(ComponentView);
  73545. function install$w(registers) {
  73546. use(install$t);
  73547. AxisView.registerAxisPointerClass('SingleAxisPointer', SingleAxisPointer);
  73548. registers.registerComponentView(SingleView);
  73549. // Axis
  73550. registers.registerComponentView(SingleAxisView);
  73551. registers.registerComponentModel(SingleAxisModel);
  73552. axisModelCreator(registers, 'single', SingleAxisModel, SingleAxisModel.defaultOption);
  73553. registers.registerCoordinateSystem('single', singleCreator);
  73554. }
  73555. var CalendarModel = /** @class */function (_super) {
  73556. __extends(CalendarModel, _super);
  73557. function CalendarModel() {
  73558. var _this = _super !== null && _super.apply(this, arguments) || this;
  73559. _this.type = CalendarModel.type;
  73560. return _this;
  73561. }
  73562. /**
  73563. * @override
  73564. */
  73565. CalendarModel.prototype.init = function (option, parentModel, ecModel) {
  73566. var inputPositionParams = getLayoutParams(option);
  73567. _super.prototype.init.apply(this, arguments);
  73568. mergeAndNormalizeLayoutParams(option, inputPositionParams);
  73569. };
  73570. /**
  73571. * @override
  73572. */
  73573. CalendarModel.prototype.mergeOption = function (option) {
  73574. _super.prototype.mergeOption.apply(this, arguments);
  73575. mergeAndNormalizeLayoutParams(this.option, option);
  73576. };
  73577. CalendarModel.prototype.getCellSize = function () {
  73578. // Has been normalized
  73579. return this.option.cellSize;
  73580. };
  73581. CalendarModel.type = 'calendar';
  73582. CalendarModel.layoutMode = 'box';
  73583. CalendarModel.defaultOption = {
  73584. // zlevel: 0,
  73585. // TODO: theoretically, the z of the calendar should be lower
  73586. // than series, but we don't want the series to be displayed
  73587. // on top of the borders like month split line. To align with
  73588. // the effect of previous versions, we set the z to 2 for now
  73589. // until better solution is found.
  73590. z: 2,
  73591. left: 80,
  73592. top: 60,
  73593. cellSize: 20,
  73594. // horizontal vertical
  73595. orient: 'horizontal',
  73596. // month separate line style
  73597. splitLine: {
  73598. show: true,
  73599. lineStyle: {
  73600. color: tokens.color.axisLine,
  73601. width: 1,
  73602. type: 'solid'
  73603. }
  73604. },
  73605. // rect style temporarily unused emphasis
  73606. itemStyle: {
  73607. color: tokens.color.neutral00,
  73608. borderWidth: 1,
  73609. borderColor: tokens.color.neutral10
  73610. },
  73611. // week text style
  73612. dayLabel: {
  73613. show: true,
  73614. firstDay: 0,
  73615. // start end
  73616. position: 'start',
  73617. margin: tokens.size.s,
  73618. color: tokens.color.secondary
  73619. },
  73620. // month text style
  73621. monthLabel: {
  73622. show: true,
  73623. // start end
  73624. position: 'start',
  73625. margin: tokens.size.s,
  73626. // center or left
  73627. align: 'center',
  73628. formatter: null,
  73629. color: tokens.color.secondary
  73630. },
  73631. // year text style
  73632. yearLabel: {
  73633. show: true,
  73634. // top bottom left right
  73635. position: null,
  73636. margin: tokens.size.xl,
  73637. formatter: null,
  73638. color: tokens.color.quaternary,
  73639. fontFamily: 'sans-serif',
  73640. fontWeight: 'bolder',
  73641. fontSize: 20
  73642. }
  73643. };
  73644. return CalendarModel;
  73645. }(ComponentModel);
  73646. function mergeAndNormalizeLayoutParams(target, raw) {
  73647. // Normalize cellSize
  73648. var cellSize = target.cellSize;
  73649. var cellSizeArr;
  73650. if (!isArray(cellSize)) {
  73651. cellSizeArr = target.cellSize = [cellSize, cellSize];
  73652. } else {
  73653. cellSizeArr = cellSize;
  73654. }
  73655. if (cellSizeArr.length === 1) {
  73656. cellSizeArr[1] = cellSizeArr[0];
  73657. }
  73658. var ignoreSize = map([0, 1], function (hvIdx) {
  73659. // If user have set `width` or both `left` and `right`, cellSizeArr
  73660. // will be automatically set to 'auto', otherwise the default
  73661. // setting of cellSizeArr will make `width` setting not work.
  73662. if (sizeCalculable(raw, hvIdx)) {
  73663. cellSizeArr[hvIdx] = 'auto';
  73664. }
  73665. return cellSizeArr[hvIdx] != null && cellSizeArr[hvIdx] !== 'auto';
  73666. });
  73667. mergeLayoutParam(target, raw, {
  73668. type: 'box',
  73669. ignoreSize: ignoreSize
  73670. });
  73671. }
  73672. var CalendarView = /** @class */function (_super) {
  73673. __extends(CalendarView, _super);
  73674. function CalendarView() {
  73675. var _this = _super !== null && _super.apply(this, arguments) || this;
  73676. _this.type = CalendarView.type;
  73677. return _this;
  73678. }
  73679. CalendarView.prototype.render = function (calendarModel, ecModel, api) {
  73680. var group = this.group;
  73681. group.removeAll();
  73682. var coordSys = calendarModel.coordinateSystem;
  73683. // range info
  73684. var rangeData = coordSys.getRangeInfo();
  73685. var orient = coordSys.getOrient();
  73686. // locale
  73687. var localeModel = ecModel.getLocaleModel();
  73688. this._renderDayRect(calendarModel, rangeData, group);
  73689. // _renderLines must be called prior to following function
  73690. this._renderLines(calendarModel, rangeData, orient, group);
  73691. this._renderYearText(calendarModel, rangeData, orient, group);
  73692. this._renderMonthText(calendarModel, localeModel, orient, group);
  73693. this._renderWeekText(calendarModel, localeModel, rangeData, orient, group);
  73694. };
  73695. // render day rect
  73696. CalendarView.prototype._renderDayRect = function (calendarModel, rangeData, group) {
  73697. var coordSys = calendarModel.coordinateSystem;
  73698. var itemRectStyleModel = calendarModel.getModel('itemStyle').getItemStyle();
  73699. var sw = coordSys.getCellWidth();
  73700. var sh = coordSys.getCellHeight();
  73701. for (var i = rangeData.start.time; i <= rangeData.end.time; i = coordSys.getNextNDay(i, 1).time) {
  73702. var point = coordSys.dataToCalendarLayout([i], false).tl;
  73703. // every rect
  73704. var rect = new Rect({
  73705. shape: {
  73706. x: point[0],
  73707. y: point[1],
  73708. width: sw,
  73709. height: sh
  73710. },
  73711. cursor: 'default',
  73712. style: itemRectStyleModel
  73713. });
  73714. group.add(rect);
  73715. }
  73716. };
  73717. // render separate line
  73718. CalendarView.prototype._renderLines = function (calendarModel, rangeData, orient, group) {
  73719. var self = this;
  73720. var coordSys = calendarModel.coordinateSystem;
  73721. var lineStyleModel = calendarModel.getModel(['splitLine', 'lineStyle']).getLineStyle();
  73722. var show = calendarModel.get(['splitLine', 'show']);
  73723. var lineWidth = lineStyleModel.lineWidth;
  73724. this._tlpoints = [];
  73725. this._blpoints = [];
  73726. this._firstDayOfMonth = [];
  73727. this._firstDayPoints = [];
  73728. var firstDay = rangeData.start;
  73729. for (var i = 0; firstDay.time <= rangeData.end.time; i++) {
  73730. addPoints(firstDay.formatedDate);
  73731. if (i === 0) {
  73732. firstDay = coordSys.getDateInfo(rangeData.start.y + '-' + rangeData.start.m);
  73733. }
  73734. var date = firstDay.date;
  73735. date.setMonth(date.getMonth() + 1);
  73736. firstDay = coordSys.getDateInfo(date);
  73737. }
  73738. addPoints(coordSys.getNextNDay(rangeData.end.time, 1).formatedDate);
  73739. function addPoints(date) {
  73740. self._firstDayOfMonth.push(coordSys.getDateInfo(date));
  73741. self._firstDayPoints.push(coordSys.dataToCalendarLayout([date], false).tl);
  73742. var points = self._getLinePointsOfOneWeek(calendarModel, date, orient);
  73743. self._tlpoints.push(points[0]);
  73744. self._blpoints.push(points[points.length - 1]);
  73745. show && self._drawSplitline(points, lineStyleModel, group);
  73746. }
  73747. // render top/left line
  73748. show && this._drawSplitline(self._getEdgesPoints(self._tlpoints, lineWidth, orient), lineStyleModel, group);
  73749. // render bottom/right line
  73750. show && this._drawSplitline(self._getEdgesPoints(self._blpoints, lineWidth, orient), lineStyleModel, group);
  73751. };
  73752. // get points at both ends
  73753. CalendarView.prototype._getEdgesPoints = function (points, lineWidth, orient) {
  73754. var rs = [points[0].slice(), points[points.length - 1].slice()];
  73755. var idx = orient === 'horizontal' ? 0 : 1;
  73756. // both ends of the line are extend half lineWidth
  73757. rs[0][idx] = rs[0][idx] - lineWidth / 2;
  73758. rs[1][idx] = rs[1][idx] + lineWidth / 2;
  73759. return rs;
  73760. };
  73761. // render split line
  73762. CalendarView.prototype._drawSplitline = function (points, lineStyle, group) {
  73763. var poyline = new Polyline({
  73764. z2: 20,
  73765. shape: {
  73766. points: points
  73767. },
  73768. style: lineStyle
  73769. });
  73770. group.add(poyline);
  73771. };
  73772. // render month line of one week points
  73773. CalendarView.prototype._getLinePointsOfOneWeek = function (calendarModel, date, orient) {
  73774. var coordSys = calendarModel.coordinateSystem;
  73775. var parsedDate = coordSys.getDateInfo(date);
  73776. var points = [];
  73777. for (var i = 0; i < 7; i++) {
  73778. var tmpD = coordSys.getNextNDay(parsedDate.time, i);
  73779. var point = coordSys.dataToCalendarLayout([tmpD.time], false);
  73780. points[2 * tmpD.day] = point.tl;
  73781. points[2 * tmpD.day + 1] = point[orient === 'horizontal' ? 'bl' : 'tr'];
  73782. }
  73783. return points;
  73784. };
  73785. CalendarView.prototype._formatterLabel = function (formatter, params) {
  73786. if (isString(formatter) && formatter) {
  73787. return formatTplSimple(formatter, params);
  73788. }
  73789. if (isFunction(formatter)) {
  73790. return formatter(params);
  73791. }
  73792. return params.nameMap;
  73793. };
  73794. CalendarView.prototype._yearTextPositionControl = function (textEl, point, orient, position, margin) {
  73795. var x = point[0];
  73796. var y = point[1];
  73797. var aligns = ['center', 'bottom'];
  73798. if (position === 'bottom') {
  73799. y += margin;
  73800. aligns = ['center', 'top'];
  73801. } else if (position === 'left') {
  73802. x -= margin;
  73803. } else if (position === 'right') {
  73804. x += margin;
  73805. aligns = ['center', 'top'];
  73806. } else {
  73807. // top
  73808. y -= margin;
  73809. }
  73810. var rotate = 0;
  73811. if (position === 'left' || position === 'right') {
  73812. rotate = Math.PI / 2;
  73813. }
  73814. return {
  73815. rotation: rotate,
  73816. x: x,
  73817. y: y,
  73818. style: {
  73819. align: aligns[0],
  73820. verticalAlign: aligns[1]
  73821. }
  73822. };
  73823. };
  73824. // render year
  73825. CalendarView.prototype._renderYearText = function (calendarModel, rangeData, orient, group) {
  73826. var yearLabel = calendarModel.getModel('yearLabel');
  73827. if (!yearLabel.get('show')) {
  73828. return;
  73829. }
  73830. var margin = yearLabel.get('margin');
  73831. var pos = yearLabel.get('position');
  73832. if (!pos) {
  73833. pos = orient !== 'horizontal' ? 'top' : 'left';
  73834. }
  73835. var points = [this._tlpoints[this._tlpoints.length - 1], this._blpoints[0]];
  73836. var xc = (points[0][0] + points[1][0]) / 2;
  73837. var yc = (points[0][1] + points[1][1]) / 2;
  73838. var idx = orient === 'horizontal' ? 0 : 1;
  73839. var posPoints = {
  73840. top: [xc, points[idx][1]],
  73841. bottom: [xc, points[1 - idx][1]],
  73842. left: [points[1 - idx][0], yc],
  73843. right: [points[idx][0], yc]
  73844. };
  73845. var name = rangeData.start.y;
  73846. if (+rangeData.end.y > +rangeData.start.y) {
  73847. name = name + '-' + rangeData.end.y;
  73848. }
  73849. var formatter = yearLabel.get('formatter');
  73850. var params = {
  73851. start: rangeData.start.y,
  73852. end: rangeData.end.y,
  73853. nameMap: name
  73854. };
  73855. var content = this._formatterLabel(formatter, params);
  73856. var yearText = new ZRText({
  73857. z2: 30,
  73858. style: createTextStyle(yearLabel, {
  73859. text: content
  73860. }),
  73861. silent: yearLabel.get('silent')
  73862. });
  73863. yearText.attr(this._yearTextPositionControl(yearText, posPoints[pos], orient, pos, margin));
  73864. group.add(yearText);
  73865. };
  73866. CalendarView.prototype._monthTextPositionControl = function (point, isCenter, orient, position, margin) {
  73867. var align = 'left';
  73868. var vAlign = 'top';
  73869. var x = point[0];
  73870. var y = point[1];
  73871. if (orient === 'horizontal') {
  73872. y = y + margin;
  73873. if (isCenter) {
  73874. align = 'center';
  73875. }
  73876. if (position === 'start') {
  73877. vAlign = 'bottom';
  73878. }
  73879. } else {
  73880. x = x + margin;
  73881. if (isCenter) {
  73882. vAlign = 'middle';
  73883. }
  73884. if (position === 'start') {
  73885. align = 'right';
  73886. }
  73887. }
  73888. return {
  73889. x: x,
  73890. y: y,
  73891. align: align,
  73892. verticalAlign: vAlign
  73893. };
  73894. };
  73895. // render month and year text
  73896. CalendarView.prototype._renderMonthText = function (calendarModel, localeModel, orient, group) {
  73897. var monthLabel = calendarModel.getModel('monthLabel');
  73898. if (!monthLabel.get('show')) {
  73899. return;
  73900. }
  73901. var nameMap = monthLabel.get('nameMap');
  73902. var margin = monthLabel.get('margin');
  73903. var pos = monthLabel.get('position');
  73904. var align = monthLabel.get('align');
  73905. var termPoints = [this._tlpoints, this._blpoints];
  73906. if (!nameMap || isString(nameMap)) {
  73907. if (nameMap) {
  73908. // case-sensitive
  73909. localeModel = getLocaleModel(nameMap) || localeModel;
  73910. }
  73911. // PENDING
  73912. // for ZH locale, original form is `一月` but current form is `1月`
  73913. nameMap = localeModel.get(['time', 'monthAbbr']) || [];
  73914. }
  73915. var idx = pos === 'start' ? 0 : 1;
  73916. var axis = orient === 'horizontal' ? 0 : 1;
  73917. margin = pos === 'start' ? -margin : margin;
  73918. var isCenter = align === 'center';
  73919. var labelSilent = monthLabel.get('silent');
  73920. for (var i = 0; i < termPoints[idx].length - 1; i++) {
  73921. var tmp = termPoints[idx][i].slice();
  73922. var firstDay = this._firstDayOfMonth[i];
  73923. if (isCenter) {
  73924. var firstDayPoints = this._firstDayPoints[i];
  73925. tmp[axis] = (firstDayPoints[axis] + termPoints[0][i + 1][axis]) / 2;
  73926. }
  73927. var formatter = monthLabel.get('formatter');
  73928. var name_1 = nameMap[+firstDay.m - 1];
  73929. var params = {
  73930. yyyy: firstDay.y,
  73931. yy: (firstDay.y + '').slice(2),
  73932. MM: firstDay.m,
  73933. M: +firstDay.m,
  73934. nameMap: name_1
  73935. };
  73936. var content = this._formatterLabel(formatter, params);
  73937. var monthText = new ZRText({
  73938. z2: 30,
  73939. style: extend(createTextStyle(monthLabel, {
  73940. text: content
  73941. }), this._monthTextPositionControl(tmp, isCenter, orient, pos, margin)),
  73942. silent: labelSilent
  73943. });
  73944. group.add(monthText);
  73945. }
  73946. };
  73947. CalendarView.prototype._weekTextPositionControl = function (point, orient, position, margin, cellSize) {
  73948. var align = 'center';
  73949. var vAlign = 'middle';
  73950. var x = point[0];
  73951. var y = point[1];
  73952. var isStart = position === 'start';
  73953. if (orient === 'horizontal') {
  73954. x = x + margin + (isStart ? 1 : -1) * cellSize[0] / 2;
  73955. align = isStart ? 'right' : 'left';
  73956. } else {
  73957. y = y + margin + (isStart ? 1 : -1) * cellSize[1] / 2;
  73958. vAlign = isStart ? 'bottom' : 'top';
  73959. }
  73960. return {
  73961. x: x,
  73962. y: y,
  73963. align: align,
  73964. verticalAlign: vAlign
  73965. };
  73966. };
  73967. // render weeks
  73968. CalendarView.prototype._renderWeekText = function (calendarModel, localeModel, rangeData, orient, group) {
  73969. var dayLabel = calendarModel.getModel('dayLabel');
  73970. if (!dayLabel.get('show')) {
  73971. return;
  73972. }
  73973. var coordSys = calendarModel.coordinateSystem;
  73974. var pos = dayLabel.get('position');
  73975. var nameMap = dayLabel.get('nameMap');
  73976. var margin = dayLabel.get('margin');
  73977. var firstDayOfWeek = coordSys.getFirstDayOfWeek();
  73978. if (!nameMap || isString(nameMap)) {
  73979. if (nameMap) {
  73980. // case-sensitive
  73981. localeModel = getLocaleModel(nameMap) || localeModel;
  73982. }
  73983. // Use the first letter of `dayOfWeekAbbr` if `dayOfWeekShort` doesn't exist in the locale file
  73984. var dayOfWeekShort = localeModel.get(['time', 'dayOfWeekShort']);
  73985. nameMap = dayOfWeekShort || map(localeModel.get(['time', 'dayOfWeekAbbr']), function (val) {
  73986. return val[0];
  73987. });
  73988. }
  73989. var start = coordSys.getNextNDay(rangeData.end.time, 7 - rangeData.lweek).time;
  73990. var cellSize = [coordSys.getCellWidth(), coordSys.getCellHeight()];
  73991. margin = parsePercent$1(margin, Math.min(cellSize[1], cellSize[0]));
  73992. if (pos === 'start') {
  73993. start = coordSys.getNextNDay(rangeData.start.time, -(7 + rangeData.fweek)).time;
  73994. margin = -margin;
  73995. }
  73996. var labelSilent = dayLabel.get('silent');
  73997. for (var i = 0; i < 7; i++) {
  73998. var tmpD = coordSys.getNextNDay(start, i);
  73999. var point = coordSys.dataToCalendarLayout([tmpD.time], false).center;
  74000. var day = i;
  74001. day = Math.abs((i + firstDayOfWeek) % 7);
  74002. var weekText = new ZRText({
  74003. z2: 30,
  74004. style: extend(createTextStyle(dayLabel, {
  74005. text: nameMap[day]
  74006. }), this._weekTextPositionControl(point, orient, pos, margin, cellSize)),
  74007. silent: labelSilent
  74008. });
  74009. group.add(weekText);
  74010. }
  74011. };
  74012. CalendarView.type = 'calendar';
  74013. return CalendarView;
  74014. }(ComponentView);
  74015. // (24*60*60*1000)
  74016. var PROXIMATE_ONE_DAY = 86400000;
  74017. var Calendar = /** @class */function () {
  74018. function Calendar(calendarModel, ecModel, api) {
  74019. this.type = 'calendar';
  74020. this.dimensions = Calendar.dimensions;
  74021. // Required in createListFromData
  74022. this.getDimensionsInfo = Calendar.getDimensionsInfo;
  74023. this._model = calendarModel;
  74024. this._update(ecModel, api);
  74025. }
  74026. Calendar.getDimensionsInfo = function () {
  74027. return [{
  74028. name: 'time',
  74029. type: 'time'
  74030. }, 'value'];
  74031. };
  74032. Calendar.prototype.getRangeInfo = function () {
  74033. return this._rangeInfo;
  74034. };
  74035. Calendar.prototype.getModel = function () {
  74036. return this._model;
  74037. };
  74038. Calendar.prototype.getRect = function () {
  74039. return this._rect;
  74040. };
  74041. Calendar.prototype.getCellWidth = function () {
  74042. return this._sw;
  74043. };
  74044. Calendar.prototype.getCellHeight = function () {
  74045. return this._sh;
  74046. };
  74047. Calendar.prototype.getOrient = function () {
  74048. return this._orient;
  74049. };
  74050. /**
  74051. * getFirstDayOfWeek
  74052. *
  74053. * @example
  74054. * 0 : start at Sunday
  74055. * 1 : start at Monday
  74056. *
  74057. * @return {number}
  74058. */
  74059. Calendar.prototype.getFirstDayOfWeek = function () {
  74060. return this._firstDayOfWeek;
  74061. };
  74062. /**
  74063. * get date info
  74064. * }
  74065. */
  74066. Calendar.prototype.getDateInfo = function (date) {
  74067. date = parseDate(date);
  74068. var y = date.getFullYear();
  74069. var m = date.getMonth() + 1;
  74070. var mStr = m < 10 ? '0' + m : '' + m;
  74071. var d = date.getDate();
  74072. var dStr = d < 10 ? '0' + d : '' + d;
  74073. var day = date.getDay();
  74074. day = Math.abs((day + 7 - this.getFirstDayOfWeek()) % 7);
  74075. return {
  74076. y: y + '',
  74077. m: mStr,
  74078. d: dStr,
  74079. day: day,
  74080. time: date.getTime(),
  74081. formatedDate: y + '-' + mStr + '-' + dStr,
  74082. date: date
  74083. };
  74084. };
  74085. Calendar.prototype.getNextNDay = function (date, n) {
  74086. n = n || 0;
  74087. if (n === 0) {
  74088. return this.getDateInfo(date);
  74089. }
  74090. date = new Date(this.getDateInfo(date).time);
  74091. date.setDate(date.getDate() + n);
  74092. return this.getDateInfo(date);
  74093. };
  74094. Calendar.prototype._update = function (ecModel, api) {
  74095. this._firstDayOfWeek = +this._model.getModel('dayLabel').get('firstDay');
  74096. this._orient = this._model.get('orient');
  74097. this._lineWidth = this._model.getModel('itemStyle').getItemStyle().lineWidth || 0;
  74098. this._rangeInfo = this._getRangeInfo(this._initRangeOption());
  74099. var weeks = this._rangeInfo.weeks || 1;
  74100. var whNames = ['width', 'height'];
  74101. var cellSize = this._model.getCellSize().slice();
  74102. var layoutParams = this._model.getBoxLayoutParams();
  74103. var cellNumbers = this._orient === 'horizontal' ? [weeks, 7] : [7, weeks];
  74104. each([0, 1], function (idx) {
  74105. if (cellSizeSpecified(cellSize, idx)) {
  74106. layoutParams[whNames[idx]] = cellSize[idx] * cellNumbers[idx];
  74107. }
  74108. });
  74109. var whGlobal = {
  74110. width: api.getWidth(),
  74111. height: api.getHeight()
  74112. };
  74113. var calendarRect = this._rect = getLayoutRect(layoutParams, whGlobal);
  74114. each([0, 1], function (idx) {
  74115. if (!cellSizeSpecified(cellSize, idx)) {
  74116. cellSize[idx] = calendarRect[whNames[idx]] / cellNumbers[idx];
  74117. }
  74118. });
  74119. function cellSizeSpecified(cellSize, idx) {
  74120. return cellSize[idx] != null && cellSize[idx] !== 'auto';
  74121. }
  74122. // Has been calculated out number.
  74123. this._sw = cellSize[0];
  74124. this._sh = cellSize[1];
  74125. };
  74126. /**
  74127. * Convert a time data(time, value) item to (x, y) point.
  74128. */
  74129. // TODO Clamp of calendar is not same with cartesian coordinate systems.
  74130. // It will return NaN if data exceeds.
  74131. Calendar.prototype.dataToPoint = function (data, clamp, out) {
  74132. out = out || [];
  74133. isArray(data) && (data = data[0]);
  74134. clamp == null && (clamp = true);
  74135. var dayInfo = this.getDateInfo(data);
  74136. var range = this._rangeInfo;
  74137. var date = dayInfo.formatedDate;
  74138. // if not in range return [NaN, NaN]
  74139. if (clamp && !(dayInfo.time >= range.start.time && dayInfo.time < range.end.time + PROXIMATE_ONE_DAY)) {
  74140. out[0] = out[1] = NaN;
  74141. return out;
  74142. }
  74143. var week = dayInfo.day;
  74144. var nthWeek = this._getRangeInfo([range.start.time, date]).nthWeek;
  74145. if (this._orient === 'vertical') {
  74146. out[0] = this._rect.x + week * this._sw + this._sw / 2;
  74147. out[1] = this._rect.y + nthWeek * this._sh + this._sh / 2;
  74148. } else {
  74149. out[0] = this._rect.x + nthWeek * this._sw + this._sw / 2;
  74150. out[1] = this._rect.y + week * this._sh + this._sh / 2;
  74151. }
  74152. return out;
  74153. };
  74154. /**
  74155. * Convert a (x, y) point to time data
  74156. */
  74157. Calendar.prototype.pointToData = function (point) {
  74158. var date = this.pointToDate(point);
  74159. return date && date.time;
  74160. };
  74161. Calendar.prototype.dataToLayout = function (data, clamp, out) {
  74162. out = out || {};
  74163. var rect = out.rect = out.rect || {};
  74164. var contentRect = out.contentRect = out.contentRect || {};
  74165. var point = this.dataToPoint(data, clamp);
  74166. rect.x = point[0] - this._sw / 2;
  74167. rect.y = point[1] - this._sh / 2;
  74168. rect.width = this._sw;
  74169. rect.height = this._sh;
  74170. BoundingRect.copy(contentRect, rect);
  74171. expandOrShrinkRect(contentRect, this._lineWidth / 2, true, true);
  74172. return out;
  74173. };
  74174. /**
  74175. * Convert a time date item to (x, y) four point.
  74176. */
  74177. Calendar.prototype.dataToCalendarLayout = function (data, clamp) {
  74178. var point = this.dataToPoint(data, clamp);
  74179. return {
  74180. center: point,
  74181. tl: [point[0] - this._sw / 2, point[1] - this._sh / 2],
  74182. tr: [point[0] + this._sw / 2, point[1] - this._sh / 2],
  74183. br: [point[0] + this._sw / 2, point[1] + this._sh / 2],
  74184. bl: [point[0] - this._sw / 2, point[1] + this._sh / 2]
  74185. };
  74186. };
  74187. /**
  74188. * Convert a (x, y) point to time date
  74189. *
  74190. * @param {Array} point point
  74191. * @return {Object} date
  74192. */
  74193. Calendar.prototype.pointToDate = function (point) {
  74194. var nthX = Math.floor((point[0] - this._rect.x) / this._sw) + 1;
  74195. var nthY = Math.floor((point[1] - this._rect.y) / this._sh) + 1;
  74196. var range = this._rangeInfo.range;
  74197. if (this._orient === 'vertical') {
  74198. return this._getDateByWeeksAndDay(nthY, nthX - 1, range);
  74199. }
  74200. return this._getDateByWeeksAndDay(nthX, nthY - 1, range);
  74201. };
  74202. Calendar.prototype.convertToPixel = function (ecModel, finder, value) {
  74203. var coordSys = getCoordSys$4(finder);
  74204. return coordSys === this ? coordSys.dataToPoint(value) : null;
  74205. };
  74206. Calendar.prototype.convertToLayout = function (ecModel, finder, value) {
  74207. var coordSys = getCoordSys$4(finder);
  74208. return coordSys === this ? coordSys.dataToLayout(value) : null;
  74209. };
  74210. Calendar.prototype.convertFromPixel = function (ecModel, finder, pixel) {
  74211. var coordSys = getCoordSys$4(finder);
  74212. return coordSys === this ? coordSys.pointToData(pixel) : null;
  74213. };
  74214. Calendar.prototype.containPoint = function (point) {
  74215. console.warn('Not implemented.');
  74216. return false;
  74217. };
  74218. /**
  74219. * initRange
  74220. * Normalize to an [start, end] array
  74221. */
  74222. Calendar.prototype._initRangeOption = function () {
  74223. var range = this._model.get('range');
  74224. var normalizedRange;
  74225. // Convert [1990] to 1990
  74226. if (isArray(range) && range.length === 1) {
  74227. range = range[0];
  74228. }
  74229. if (!isArray(range)) {
  74230. var rangeStr = range.toString();
  74231. // One year.
  74232. if (/^\d{4}$/.test(rangeStr)) {
  74233. normalizedRange = [rangeStr + '-01-01', rangeStr + '-12-31'];
  74234. }
  74235. // One month
  74236. if (/^\d{4}[\/|-]\d{1,2}$/.test(rangeStr)) {
  74237. var start = this.getDateInfo(rangeStr);
  74238. var firstDay = start.date;
  74239. firstDay.setMonth(firstDay.getMonth() + 1);
  74240. var end = this.getNextNDay(firstDay, -1);
  74241. normalizedRange = [start.formatedDate, end.formatedDate];
  74242. }
  74243. // One day
  74244. if (/^\d{4}[\/|-]\d{1,2}[\/|-]\d{1,2}$/.test(rangeStr)) {
  74245. normalizedRange = [rangeStr, rangeStr];
  74246. }
  74247. } else {
  74248. normalizedRange = range;
  74249. }
  74250. if (!normalizedRange) {
  74251. if ("development" !== 'production') {
  74252. logError('Invalid date range.');
  74253. }
  74254. // Not handling it.
  74255. return range;
  74256. }
  74257. var tmp = this._getRangeInfo(normalizedRange);
  74258. if (tmp.start.time > tmp.end.time) {
  74259. normalizedRange.reverse();
  74260. }
  74261. return normalizedRange;
  74262. };
  74263. /**
  74264. * range info
  74265. *
  74266. * @private
  74267. * @param {Array} range range ['2017-01-01', '2017-07-08']
  74268. * If range[0] > range[1], they will not be reversed.
  74269. * @return {Object} obj
  74270. */
  74271. Calendar.prototype._getRangeInfo = function (range) {
  74272. var parsedRange = [this.getDateInfo(range[0]), this.getDateInfo(range[1])];
  74273. var reversed;
  74274. if (parsedRange[0].time > parsedRange[1].time) {
  74275. reversed = true;
  74276. parsedRange.reverse();
  74277. }
  74278. var allDay = Math.floor(parsedRange[1].time / PROXIMATE_ONE_DAY) - Math.floor(parsedRange[0].time / PROXIMATE_ONE_DAY) + 1;
  74279. // Consider case1 (#11677 #10430):
  74280. // Set the system timezone as "UK", set the range to `['2016-07-01', '2016-12-31']`
  74281. // Consider case2:
  74282. // Firstly set system timezone as "Time Zone: America/Toronto",
  74283. // ```
  74284. // let first = new Date(1478412000000 - 3600 * 1000 * 2.5);
  74285. // let second = new Date(1478412000000);
  74286. // let allDays = Math.floor(second / ONE_DAY) - Math.floor(first / ONE_DAY) + 1;
  74287. // ```
  74288. // will get wrong result because of DST. So we should fix it.
  74289. var date = new Date(parsedRange[0].time);
  74290. var startDateNum = date.getDate();
  74291. var endDateNum = parsedRange[1].date.getDate();
  74292. date.setDate(startDateNum + allDay - 1);
  74293. // The bias can not over a month, so just compare date.
  74294. var dateNum = date.getDate();
  74295. if (dateNum !== endDateNum) {
  74296. var sign = date.getTime() - parsedRange[1].time > 0 ? 1 : -1;
  74297. while ((dateNum = date.getDate()) !== endDateNum && (date.getTime() - parsedRange[1].time) * sign > 0) {
  74298. allDay -= sign;
  74299. date.setDate(dateNum - sign);
  74300. }
  74301. }
  74302. var weeks = Math.floor((allDay + parsedRange[0].day + 6) / 7);
  74303. var nthWeek = reversed ? -weeks + 1 : weeks - 1;
  74304. reversed && parsedRange.reverse();
  74305. return {
  74306. range: [parsedRange[0].formatedDate, parsedRange[1].formatedDate],
  74307. start: parsedRange[0],
  74308. end: parsedRange[1],
  74309. allDay: allDay,
  74310. weeks: weeks,
  74311. // From 0.
  74312. nthWeek: nthWeek,
  74313. fweek: parsedRange[0].day,
  74314. lweek: parsedRange[1].day
  74315. };
  74316. };
  74317. /**
  74318. * get date by nthWeeks and week day in range
  74319. *
  74320. * @private
  74321. * @param {number} nthWeek the week
  74322. * @param {number} day the week day
  74323. * @param {Array} range [d1, d2]
  74324. * @return {Object}
  74325. */
  74326. Calendar.prototype._getDateByWeeksAndDay = function (nthWeek, day, range) {
  74327. var rangeInfo = this._getRangeInfo(range);
  74328. if (nthWeek > rangeInfo.weeks || nthWeek === 0 && day < rangeInfo.fweek || nthWeek === rangeInfo.weeks && day > rangeInfo.lweek) {
  74329. return null;
  74330. }
  74331. var nthDay = (nthWeek - 1) * 7 - rangeInfo.fweek + day;
  74332. var date = new Date(rangeInfo.start.time);
  74333. date.setDate(+rangeInfo.start.d + nthDay);
  74334. return this.getDateInfo(date);
  74335. };
  74336. Calendar.create = function (ecModel, api) {
  74337. var calendarList = [];
  74338. ecModel.eachComponent('calendar', function (calendarModel) {
  74339. var calendar = new Calendar(calendarModel, ecModel, api);
  74340. calendarList.push(calendar);
  74341. calendarModel.coordinateSystem = calendar;
  74342. });
  74343. // Inject coordinate system
  74344. ecModel.eachComponent(function (mainType, componentModel) {
  74345. injectCoordSysByOption({
  74346. targetModel: componentModel,
  74347. coordSysType: 'calendar',
  74348. coordSysProvider: simpleCoordSysInjectionProvider
  74349. });
  74350. });
  74351. return calendarList;
  74352. };
  74353. Calendar.dimensions = ['time', 'value'];
  74354. return Calendar;
  74355. }();
  74356. function getCoordSys$4(finder) {
  74357. var calendarModel = finder.calendarModel;
  74358. var seriesModel = finder.seriesModel;
  74359. var coordSys = calendarModel ? calendarModel.coordinateSystem : seriesModel ? seriesModel.coordinateSystem : null;
  74360. return coordSys;
  74361. }
  74362. function install$x(registers) {
  74363. registers.registerComponentModel(CalendarModel);
  74364. registers.registerComponentView(CalendarView);
  74365. registers.registerCoordinateSystem('calendar', Calendar);
  74366. }
  74367. var MatrixCellLayoutInfoType = {
  74368. level: 1,
  74369. leaf: 2,
  74370. nonLeaf: 3
  74371. };
  74372. /**
  74373. * @public Public to users in `chart.convertFromPixel`.
  74374. */
  74375. var MatrixClampOption = {
  74376. // No clamp, be falsy, equals to null/undefined. It means if the input part is
  74377. // null/undefined/NaN/outOfBoundary, the result part is NaN, rather than clamp to
  74378. // the boundary of the matrix.
  74379. none: 0,
  74380. // Clamp, where null/undefined/NaN/outOfBoundary can be used to cover the entire row/column.
  74381. all: 1,
  74382. body: 2,
  74383. corner: 3
  74384. };
  74385. /**
  74386. * For the x direction,
  74387. * - find dimension cell from `xMatrixDim`,
  74388. * - If `xDimCell` or `yDimCell` is not a leaf, return the non-leaf cell itself.
  74389. * - otherwise find level from `yMatrixDim`.
  74390. * - otherwise return `NullUndefined`.
  74391. *
  74392. * For the y direction, it's the opposite.
  74393. */
  74394. function coordDataToAllCellLevelLayout(coordValue, dims, thisDimIdx // 0 | 1
  74395. ) {
  74396. // Find in body.
  74397. var result = dims[XY$1[thisDimIdx]].getCell(coordValue);
  74398. // Find in corner or dimension area.
  74399. if (!result && isNumber(coordValue) && coordValue < 0) {
  74400. result = dims[XY$1[1 - thisDimIdx]].getUnitLayoutInfo(thisDimIdx, Math.round(coordValue));
  74401. }
  74402. return result;
  74403. }
  74404. function resetXYLocatorRange(out) {
  74405. var rg = out || [];
  74406. rg[0] = rg[0] || [];
  74407. rg[1] = rg[1] || [];
  74408. rg[0][0] = rg[0][1] = rg[1][0] = rg[1][1] = NaN;
  74409. return rg;
  74410. }
  74411. /**
  74412. * If illegal or out of boundary, set NaN to `locOut`. See `isXYLocatorRangeInvalidOnDim`.
  74413. * x dimension and y dimension are calculated separately.
  74414. */
  74415. function parseCoordRangeOption(locOut,
  74416. // If illegal input or can not find any target, save reason to it.
  74417. // Do nothing if `NullUndefined`.
  74418. reasonOut, data, dims, clamp) {
  74419. // x and y are supported to be handled separately - if one dimension is invalid
  74420. // (may be users do not need that), the other one should also be calculated.
  74421. parseCoordRangeOptionOnOneDim(locOut[0], reasonOut, clamp, data, dims, 0);
  74422. parseCoordRangeOptionOnOneDim(locOut[1], reasonOut, clamp, data, dims, 1);
  74423. }
  74424. function parseCoordRangeOptionOnOneDim(locDimOut, reasonOut, clamp, data, dims, dimIdx) {
  74425. locDimOut[0] = Infinity;
  74426. locDimOut[1] = -Infinity;
  74427. var dataOnDim = data[dimIdx];
  74428. var coordValArr = isArray(dataOnDim) ? dataOnDim : [dataOnDim];
  74429. var len = coordValArr.length;
  74430. var hasClamp = !!clamp;
  74431. if (len >= 1) {
  74432. parseCoordRangeOptionOnOneDimOnePart(locDimOut, reasonOut, coordValArr, hasClamp, dims, dimIdx, 0);
  74433. if (len > 1) {
  74434. // Users may intuitively input the coords like `[[x1, x2, x3], ...]`;
  74435. // consider the range as `[x1, x3]` in this case.
  74436. parseCoordRangeOptionOnOneDimOnePart(locDimOut, reasonOut, coordValArr, hasClamp, dims, dimIdx, len - 1);
  74437. }
  74438. } else {
  74439. if ("development" !== 'production') {
  74440. if (reasonOut) {
  74441. reasonOut.push('Should be like [["x1", "x2"], ["y1", "y2"]], or ["x1", "y1"], rather than empty.');
  74442. }
  74443. }
  74444. locDimOut[0] = locDimOut[1] = NaN;
  74445. }
  74446. if (hasClamp) {
  74447. // null/undefined/NaN or illegal data represents the entire row/column;
  74448. // Cover the entire locator regardless of body or corner, and confine it later.
  74449. var locLowerBound = -dims[XY$1[1 - dimIdx]].getLocatorCount(dimIdx);
  74450. var locUpperBound = dims[XY$1[dimIdx]].getLocatorCount(dimIdx) - 1;
  74451. if (clamp === MatrixClampOption.body) {
  74452. locLowerBound = mathMax$1(0, locLowerBound);
  74453. } else if (clamp === MatrixClampOption.corner) {
  74454. locUpperBound = mathMin$1(-1, locUpperBound);
  74455. }
  74456. if (locUpperBound < locLowerBound) {
  74457. // Also considered that both x and y has no cell.
  74458. locLowerBound = locUpperBound = NaN;
  74459. }
  74460. if (eqNaN(locDimOut[0])) {
  74461. locDimOut[0] = locLowerBound;
  74462. }
  74463. if (eqNaN(locDimOut[1])) {
  74464. locDimOut[1] = locUpperBound;
  74465. }
  74466. locDimOut[0] = mathMax$1(mathMin$1(locDimOut[0], locUpperBound), locLowerBound);
  74467. locDimOut[1] = mathMax$1(mathMin$1(locDimOut[1], locUpperBound), locLowerBound);
  74468. }
  74469. }
  74470. // The return val must be finite or NaN.
  74471. function parseCoordRangeOptionOnOneDimOnePart(locDimOut, reasonOut, coordValArr, hasClamp, dims, dimIdx, partIdx) {
  74472. var layout = coordDataToAllCellLevelLayout(coordValArr[partIdx], dims, dimIdx);
  74473. if (!layout) {
  74474. if ("development" !== 'production') {
  74475. if (!hasClamp && reasonOut) {
  74476. reasonOut.push("Can not find cell by coord[" + dimIdx + "][" + partIdx + "].");
  74477. }
  74478. }
  74479. locDimOut[0] = locDimOut[1] = NaN;
  74480. return;
  74481. }
  74482. var locatorA = layout.id[XY$1[dimIdx]];
  74483. var locatorB = locatorA;
  74484. var dimCell = cellLayoutInfoToDimCell(layout);
  74485. if (dimCell) {
  74486. // Handle non-leaf
  74487. locatorB += dimCell.span[XY$1[dimIdx]] - 1;
  74488. }
  74489. locDimOut[0] = mathMin$1(locDimOut[0], locatorA, locatorB);
  74490. locDimOut[1] = mathMax$1(locDimOut[1], locatorA, locatorB);
  74491. }
  74492. /**
  74493. * @param locatorRange Must be the return of `parseCoordRangeOption`,
  74494. * where if not NaN, it must be a valid locator.
  74495. */
  74496. function isXYLocatorRangeInvalidOnDim(locatorRange, dimIdx) {
  74497. return eqNaN(locatorRange[dimIdx][0]) || eqNaN(locatorRange[dimIdx][1]);
  74498. }
  74499. // `locatorRange` will be expanded (modified) if an intersection is encountered.
  74500. function resolveXYLocatorRangeByCellMerge(inOutLocatorRange,
  74501. // Item indices coorespond to mergeDefList (len: mergeDefListTravelLen).
  74502. // Indicating whether each item has be merged into the `locatorRange`
  74503. outMergedMarkList, mergeDefList, mergeDefListTravelLen) {
  74504. outMergedMarkList = outMergedMarkList || _tmpOutMergedMarkList;
  74505. for (var idx = 0; idx < mergeDefListTravelLen; idx++) {
  74506. outMergedMarkList[idx] = false;
  74507. }
  74508. // In most case, cell merging definition list length is smaller than the range extent,
  74509. // therefore, to detection intersection, travelling cell merging definition list is probably
  74510. // performant than traveling the four edges of the rect formed by the locator range.
  74511. while (true) {
  74512. var expanded = false;
  74513. for (var idx = 0; idx < mergeDefListTravelLen; idx++) {
  74514. var mergeDef = mergeDefList[idx];
  74515. if (!outMergedMarkList[idx] && mergeDef.cellMergeOwner && expandXYLocatorRangeIfIntersect(inOutLocatorRange, mergeDef.locatorRange)) {
  74516. outMergedMarkList[idx] = true;
  74517. expanded = true;
  74518. }
  74519. }
  74520. if (!expanded) {
  74521. break;
  74522. }
  74523. }
  74524. }
  74525. var _tmpOutMergedMarkList = [];
  74526. // Return whether intersect.
  74527. // `thisLocRange` will be expanded (modified) if an intersection is encountered.
  74528. function expandXYLocatorRangeIfIntersect(thisLocRange, otherLocRange) {
  74529. if (!locatorRangeIntersectOneDim(thisLocRange[0], otherLocRange[0]) || !locatorRangeIntersectOneDim(thisLocRange[1], otherLocRange[1])) {
  74530. return false;
  74531. }
  74532. thisLocRange[0][0] = mathMin$1(thisLocRange[0][0], otherLocRange[0][0]);
  74533. thisLocRange[0][1] = mathMax$1(thisLocRange[0][1], otherLocRange[0][1]);
  74534. thisLocRange[1][0] = mathMin$1(thisLocRange[1][0], otherLocRange[1][0]);
  74535. thisLocRange[1][1] = mathMax$1(thisLocRange[1][1], otherLocRange[1][1]);
  74536. return true;
  74537. }
  74538. // Notice: If containing NaN, not intersect.
  74539. function locatorRangeIntersectOneDim(locRange1OneDim, locRange2OneDim) {
  74540. return locRange1OneDim[1] >= locRange2OneDim[0] && locRange1OneDim[0] <= locRange2OneDim[1];
  74541. }
  74542. function fillIdSpanFromLocatorRange(owner, locatorRange) {
  74543. owner.id.set(locatorRange[0][0], locatorRange[1][0]);
  74544. owner.span.set(locatorRange[0][1] - owner.id.x + 1, locatorRange[1][1] - owner.id.y + 1);
  74545. }
  74546. function cloneXYLocatorRange(target, source) {
  74547. target[0][0] = source[0][0];
  74548. target[0][1] = source[0][1];
  74549. target[1][0] = source[1][0];
  74550. target[1][1] = source[1][1];
  74551. }
  74552. /**
  74553. * If illegal, the corresponding x/y/width/height is set to `NaN`.
  74554. * `x/width` or `y/height` is supported to be calculated separately,
  74555. * i.e., one side are NaN, the other side are normal.
  74556. * @param oneDimOut only write to `x/width` or `y/height`, depending on `dimIdx`.
  74557. */
  74558. function xyLocatorRangeToRectOneDim(oneDimOut, locRange, dims, dimIdx) {
  74559. var layoutMin = coordDataToAllCellLevelLayout(locRange[dimIdx][0], dims, dimIdx);
  74560. var layoutMax = coordDataToAllCellLevelLayout(locRange[dimIdx][1], dims, dimIdx);
  74561. oneDimOut[XY$1[dimIdx]] = oneDimOut[WH$1[dimIdx]] = NaN;
  74562. if (layoutMin && layoutMax) {
  74563. oneDimOut[XY$1[dimIdx]] = layoutMin.xy;
  74564. oneDimOut[WH$1[dimIdx]] = layoutMax.xy + layoutMax.wh - layoutMin.xy;
  74565. }
  74566. }
  74567. // No need currently, since `span` is not allowed to be defined directly by users.
  74568. // /**
  74569. // * If either span x or y is valid and > 1, return parsed span, otherwise return `NullUndefined`.
  74570. // */
  74571. // export function parseSpanOption(
  74572. // spanOptionHost: MatrixCellSpanOptionHost,
  74573. // dimCellPair: MatrixCellLayoutInfo[]
  74574. // ): Point | NullUndefined {
  74575. // const spanX = parseSpanOnDim(spanOptionHost.spanX, dimCellPair[0], 0);
  74576. // const spanY = parseSpanOnDim(spanOptionHost.spanY, dimCellPair[1], 1);
  74577. // if (!eqNaN(spanX) || !eqNaN(spanY)) {
  74578. // return new Point(spanX || 1, spanY || 1);
  74579. // }
  74580. // function parseSpanOnDim(spanOption: unknown, dimCell: MatrixCellLayoutInfo, dimIdx: number): number {
  74581. // if (!isNumber(spanOption)) {
  74582. // return NaN;
  74583. // }
  74584. // // Ensure positive integer (not NaN) to avoid dead loop.
  74585. // const span = mathMax(1, Math.round(spanOption || 1)) || 1;
  74586. // // Clamp, and consider may also be specified as `Infinity` to span the entire col/row.
  74587. // return mathMin(span, mathMax(1, dimCell.dim.getLocatorCount(dimIdx) - dimCell.id[XY[dimIdx]]));
  74588. // }
  74589. // }
  74590. /**
  74591. * @usage To get/set on dimension, use:
  74592. * `xyVal[XY[dim]] = val;` // set on this dimension.
  74593. * `xyVal[XY[1 - dim]] = val;` // set on the perpendicular dimension.
  74594. */
  74595. function setDimXYValue(out, dimIdx,
  74596. // 0 | 1
  74597. valueOnThisDim, valueOnOtherDim) {
  74598. out[XY$1[dimIdx]] = valueOnThisDim;
  74599. out[XY$1[1 - dimIdx]] = valueOnOtherDim;
  74600. return out;
  74601. }
  74602. /**
  74603. * Return NullUndefined if not dimension cell.
  74604. */
  74605. function cellLayoutInfoToDimCell(cellLayoutInfo) {
  74606. return cellLayoutInfo && (cellLayoutInfo.type === MatrixCellLayoutInfoType.leaf || cellLayoutInfo.type === MatrixCellLayoutInfoType.nonLeaf) ? cellLayoutInfo : null;
  74607. }
  74608. function createNaNRectLike() {
  74609. return {
  74610. x: NaN,
  74611. y: NaN,
  74612. width: NaN,
  74613. height: NaN
  74614. };
  74615. }
  74616. /**
  74617. * Lifetime: the same with `MatrixModel`, but different from `coord/Matrix`.
  74618. */
  74619. var MatrixDim = /** @class */function () {
  74620. function MatrixDim(dim, dimModel) {
  74621. // Under the current definition, every leave corresponds a unit cell,
  74622. // and leaves can serve as the locator of cells.
  74623. // Therefore make sure:
  74624. // - The first `_leavesCount` elements in `_cells` are leaves.
  74625. // - `_cells[leaf.id[XY[this.dimIdx]]]` is the leaf itself.
  74626. // - Leaves of each subtree are placed together, that is, the leaves of a dimCell are:
  74627. // `this._cells.slice(dimCell.firstLeafLocator, dimCell.span[XY[this.dimIdx]])`
  74628. this._cells = [];
  74629. // Can be visited by `_levels[cell.level]` or `_levels[cell.id[1 - dimIdx] + _levels.length]`.
  74630. // Items are never be null/undefined after initialized.
  74631. this._levels = [];
  74632. this.dim = dim;
  74633. this.dimIdx = dim === 'x' ? 0 : 1;
  74634. this._model = dimModel;
  74635. this._uniqueValueGen = createUniqueValueGenerator(dim);
  74636. var dimModelData = dimModel.get('data', true);
  74637. if (dimModelData != null && !isArray(dimModelData)) {
  74638. if ("development" !== 'production') {
  74639. error("Illegal echarts option - matrix." + this.dim + ".data must be an array if specified.");
  74640. }
  74641. dimModelData = [];
  74642. }
  74643. if (dimModelData) {
  74644. this._initByDimModelData(dimModelData);
  74645. } else {
  74646. this._initBySeriesData();
  74647. }
  74648. }
  74649. MatrixDim.prototype._initByDimModelData = function (dimModelData) {
  74650. var self = this;
  74651. var _cells = self._cells;
  74652. var _levels = self._levels;
  74653. var sameLocatorCellsLists = []; // Save for sorting.
  74654. var _cellCount = 0;
  74655. self._leavesCount = traverseInitCells(dimModelData, 0, 0);
  74656. postInitCells();
  74657. return;
  74658. function traverseInitCells(dimModelData, firstLeafLocator, level) {
  74659. var totalSpan = 0;
  74660. if (!dimModelData) {
  74661. return totalSpan;
  74662. }
  74663. each(dimModelData, function (option, optionIdx) {
  74664. var invalidOption = false;
  74665. var cellOption;
  74666. if (isString(option)) {
  74667. cellOption = {
  74668. value: option
  74669. };
  74670. } else if (isObject(option)) {
  74671. cellOption = option;
  74672. if (option.value != null && !isString(option.value)) {
  74673. invalidOption = true;
  74674. cellOption = {
  74675. value: null
  74676. };
  74677. }
  74678. } else {
  74679. cellOption = {
  74680. value: null
  74681. };
  74682. if (option != null) {
  74683. invalidOption = true;
  74684. }
  74685. }
  74686. if (invalidOption) {
  74687. if ("development" !== 'production') {
  74688. error("Illegal echarts option - matrix." + self.dim + ".data[" + optionIdx + "]" + ' must be `string | {value: string}`.');
  74689. }
  74690. }
  74691. var cell = {
  74692. type: MatrixCellLayoutInfoType.nonLeaf,
  74693. ordinal: NaN,
  74694. level: level,
  74695. firstLeafLocator: firstLeafLocator,
  74696. id: new Point(),
  74697. span: setDimXYValue(new Point(), self.dimIdx, 1, 1),
  74698. option: cellOption,
  74699. xy: NaN,
  74700. wh: NaN,
  74701. dim: self,
  74702. rect: createNaNRectLike()
  74703. };
  74704. _cellCount++;
  74705. (sameLocatorCellsLists[firstLeafLocator] || (sameLocatorCellsLists[firstLeafLocator] = [])).push(cell);
  74706. if (!_levels[level]) {
  74707. // Create a level only if at least one cell exists.
  74708. _levels[level] = {
  74709. type: MatrixCellLayoutInfoType.level,
  74710. xy: NaN,
  74711. wh: NaN,
  74712. option: null,
  74713. id: new Point(),
  74714. dim: self
  74715. };
  74716. }
  74717. var childrenSpan = traverseInitCells(cellOption.children, firstLeafLocator, level + 1);
  74718. var subSpan = Math.max(1, childrenSpan);
  74719. cell.span[XY$1[self.dimIdx]] = subSpan;
  74720. totalSpan += subSpan;
  74721. firstLeafLocator += subSpan;
  74722. });
  74723. return totalSpan;
  74724. }
  74725. function postInitCells() {
  74726. // Sort to make sure the leaves are at the beginning, so that
  74727. // they can be used as the locator of body cells.
  74728. var categories = [];
  74729. while (_cells.length < _cellCount) {
  74730. for (var locator = 0; locator < sameLocatorCellsLists.length; locator++) {
  74731. var cell = sameLocatorCellsLists[locator].pop();
  74732. if (cell) {
  74733. cell.ordinal = categories.length;
  74734. var val = cell.option.value;
  74735. categories.push(val);
  74736. _cells.push(cell);
  74737. self._uniqueValueGen.calcDupBase(val);
  74738. }
  74739. }
  74740. }
  74741. self._uniqueValueGen.ensureValueUnique(categories, _cells);
  74742. var ordinalMeta = self._ordinalMeta = new OrdinalMeta({
  74743. categories: categories,
  74744. needCollect: false,
  74745. deduplication: false
  74746. });
  74747. self._scale = new OrdinalScale({
  74748. ordinalMeta: ordinalMeta
  74749. });
  74750. for (var idx = 0; idx < self._leavesCount; idx++) {
  74751. var leaf = self._cells[idx];
  74752. leaf.type = MatrixCellLayoutInfoType.leaf;
  74753. // Handle the tree level variation: enlarge the span of the leaves to reach the body cells.
  74754. leaf.span[XY$1[1 - self.dimIdx]] = self._levels.length - leaf.level;
  74755. }
  74756. self._initCellsId();
  74757. self._initLevelIdOptions();
  74758. }
  74759. };
  74760. MatrixDim.prototype._initBySeriesData = function () {
  74761. var self = this;
  74762. self._leavesCount = 0;
  74763. self._levels = [{
  74764. type: MatrixCellLayoutInfoType.level,
  74765. xy: NaN,
  74766. wh: NaN,
  74767. option: null,
  74768. id: new Point(),
  74769. dim: self
  74770. }];
  74771. self._initLevelIdOptions();
  74772. var ordinalMeta = self._ordinalMeta = new OrdinalMeta({
  74773. needCollect: true,
  74774. deduplication: true,
  74775. onCollect: function (value, ordinalNumber) {
  74776. var cell = self._cells[ordinalNumber] = {
  74777. type: MatrixCellLayoutInfoType.leaf,
  74778. ordinal: ordinalNumber,
  74779. level: 0,
  74780. firstLeafLocator: ordinalNumber,
  74781. id: new Point(),
  74782. span: setDimXYValue(new Point(), self.dimIdx, 1, 1),
  74783. // Theoretically `value` is from `dataset` or `series.data`, so it may be any type.
  74784. // Do not restrict this case for user's convenience, and here simply convert it to
  74785. // string for display.
  74786. option: {
  74787. value: value + ''
  74788. },
  74789. xy: NaN,
  74790. wh: NaN,
  74791. dim: self,
  74792. rect: createNaNRectLike()
  74793. };
  74794. self._leavesCount++;
  74795. self._setCellId(cell);
  74796. }
  74797. });
  74798. self._scale = new OrdinalScale({
  74799. ordinalMeta: ordinalMeta
  74800. });
  74801. };
  74802. MatrixDim.prototype._setCellId = function (cell) {
  74803. var levelsLen = this._levels.length;
  74804. var dimIdx = this.dimIdx;
  74805. setDimXYValue(cell.id, dimIdx, cell.firstLeafLocator, cell.level - levelsLen);
  74806. };
  74807. MatrixDim.prototype._initCellsId = function () {
  74808. var levelsLen = this._levels.length;
  74809. var dimIdx = this.dimIdx;
  74810. each(this._cells, function (cell) {
  74811. setDimXYValue(cell.id, dimIdx, cell.firstLeafLocator, cell.level - levelsLen);
  74812. });
  74813. };
  74814. MatrixDim.prototype._initLevelIdOptions = function () {
  74815. var levelsLen = this._levels.length;
  74816. var dimIdx = this.dimIdx;
  74817. var levelOptionList = this._model.get('levels', true);
  74818. levelOptionList = isArray(levelOptionList) ? levelOptionList : [];
  74819. each(this._levels, function (levelCfg, level) {
  74820. setDimXYValue(levelCfg.id, dimIdx, 0, level - levelsLen);
  74821. levelCfg.option = levelOptionList[level];
  74822. });
  74823. };
  74824. MatrixDim.prototype.shouldShow = function () {
  74825. return !!this._model.getShallow('show', true);
  74826. };
  74827. /**
  74828. * Iterate leaves (they are layout units) if dimIdx === this.dimIdx.
  74829. * Iterate levels if dimIdx !== this.dimIdx.
  74830. */
  74831. MatrixDim.prototype.resetLayoutIterator = function (it, dimIdx, startLocator, count) {
  74832. it = it || new ListIterator();
  74833. if (dimIdx === this.dimIdx) {
  74834. var len = this._leavesCount;
  74835. var startIdx = startLocator != null ? Math.max(0, startLocator) : 0;
  74836. count = count != null ? Math.min(count, len) : len;
  74837. it.reset(this._cells, startIdx, startIdx + count);
  74838. } else {
  74839. var len = this._levels.length;
  74840. // Corner locator is from `-this._levels.length` to `-1`.
  74841. var startIdx = startLocator != null ? Math.max(0, startLocator + len) : 0;
  74842. count = count != null ? Math.min(count, len) : len;
  74843. it.reset(this._levels, startIdx, startIdx + count);
  74844. }
  74845. return it;
  74846. };
  74847. MatrixDim.prototype.resetCellIterator = function (it) {
  74848. return (it || new ListIterator()).reset(this._cells, 0);
  74849. };
  74850. MatrixDim.prototype.resetLevelIterator = function (it) {
  74851. return (it || new ListIterator()).reset(this._levels, 0);
  74852. };
  74853. MatrixDim.prototype.getLayout = function (outRect, dimIdx, locator) {
  74854. var layout = this.getUnitLayoutInfo(dimIdx, locator);
  74855. outRect[XY$1[dimIdx]] = layout ? layout.xy : NaN;
  74856. outRect[WH$1[dimIdx]] = layout ? layout.wh : NaN;
  74857. };
  74858. /**
  74859. * Get leaf cell or get level info.
  74860. * Should be able to return null/undefined if not found on x or y, thus input `dimIdx` is needed.
  74861. */
  74862. MatrixDim.prototype.getUnitLayoutInfo = function (dimIdx, locator) {
  74863. return dimIdx === this.dimIdx ? locator < this._leavesCount ? this._cells[locator] : undefined : this._levels[locator + this._levels.length];
  74864. };
  74865. /**
  74866. * Get dimension cell by data, including leaves and non-leaves.
  74867. */
  74868. MatrixDim.prototype.getCell = function (value) {
  74869. var ordinal = this._scale.parse(value);
  74870. return eqNaN(ordinal) ? undefined : this._cells[ordinal];
  74871. };
  74872. /**
  74873. * Get leaf count or get level count.
  74874. */
  74875. MatrixDim.prototype.getLocatorCount = function (dimIdx) {
  74876. return dimIdx === this.dimIdx ? this._leavesCount : this._levels.length;
  74877. };
  74878. MatrixDim.prototype.getOrdinalMeta = function () {
  74879. return this._ordinalMeta;
  74880. };
  74881. return MatrixDim;
  74882. }();
  74883. function createUniqueValueGenerator(dim) {
  74884. var dimUpper = dim.toUpperCase();
  74885. var defaultValReg = new RegExp("^" + dimUpper + "([0-9]+)$");
  74886. var dupBase = 0;
  74887. function calcDupBase(val) {
  74888. var matchResult;
  74889. if (val != null && (matchResult = val.match(defaultValReg))) {
  74890. dupBase = mathMax$1(dupBase, +matchResult[1] + 1);
  74891. }
  74892. }
  74893. function makeUniqueValue() {
  74894. return "" + dimUpper + dupBase++;
  74895. }
  74896. // Duplicated value is allowed, because the `matrix.x/y.data` can be a tree and it's reasonable
  74897. // that leaves in different subtrees has the same text. But only the first one is allowed to be
  74898. // queried by the text, and the other ones can only be queried by index.
  74899. // Additionally, `matrix.x/y.data: [null, null, ...]` is allowed.
  74900. function ensureValueUnique(categories, cells) {
  74901. // A simple way to deduplicate or handle illegal or not specified values to avoid unexpected behaviors.
  74902. // The tree structure should not be broken even if duplicated.
  74903. var cateMap = createHashMap();
  74904. for (var idx = 0; idx < categories.length; idx++) {
  74905. var value = categories[idx];
  74906. // value may be set to NullUndefined by users or if illegal.
  74907. if (value == null || cateMap.get(value) != null) {
  74908. // Still display the original option.value if duplicated, but loose the ability to query by text.
  74909. categories[idx] = value = makeUniqueValue();
  74910. cells[idx].option = defaults({
  74911. value: value
  74912. }, cells[idx].option);
  74913. }
  74914. cateMap.set(value, true);
  74915. }
  74916. }
  74917. return {
  74918. calcDupBase: calcDupBase,
  74919. ensureValueUnique: ensureValueUnique
  74920. };
  74921. }
  74922. /**
  74923. * Lifetime: the same with `MatrixModel`, but different from `coord/Matrix`.
  74924. */
  74925. var MatrixBodyCorner = /** @class */function () {
  74926. function MatrixBodyCorner(kind, bodyOrCornerModel, dims) {
  74927. this._model = bodyOrCornerModel;
  74928. this._dims = dims;
  74929. this._kind = kind;
  74930. this._cellMergeOwnerList = [];
  74931. }
  74932. /**
  74933. * Can not be called before series models initialization finished, since the ordinalMeta may
  74934. * use collect the values from `series.data` in series initialization.
  74935. */
  74936. MatrixBodyCorner.prototype._ensureCellMap = function () {
  74937. var self = this;
  74938. var _cellMap = self._cellMap;
  74939. if (!_cellMap) {
  74940. _cellMap = self._cellMap = createHashMap();
  74941. fillCellMap();
  74942. }
  74943. return _cellMap;
  74944. function fillCellMap() {
  74945. var parsedList = [];
  74946. var cellOptionList = self._model.getShallow('data');
  74947. if (cellOptionList && !isArray(cellOptionList)) {
  74948. if ("development" !== 'production') {
  74949. error("matrix." + cellOptionList + ".data must be an array if specified.");
  74950. }
  74951. cellOptionList = null;
  74952. }
  74953. each(cellOptionList, function (option, idx) {
  74954. if (!isObject(option) || !isArray(option.coord)) {
  74955. if ("development" !== 'production') {
  74956. error("Illegal matrix." + self._kind + ".data[" + idx + "], must be a {coord: [...], ...}");
  74957. }
  74958. return;
  74959. }
  74960. var locatorRange = resetXYLocatorRange([]);
  74961. var reasonArr = null;
  74962. if ("development" !== 'production') {
  74963. reasonArr = [];
  74964. }
  74965. parseCoordRangeOption(locatorRange, reasonArr, option.coord, self._dims, option.coordClamp ? MatrixClampOption[self._kind] : MatrixClampOption.none);
  74966. if (isXYLocatorRangeInvalidOnDim(locatorRange, 0) || isXYLocatorRangeInvalidOnDim(locatorRange, 1)) {
  74967. if ("development" !== 'production') {
  74968. error("Can not determine cells by option matrix." + self._kind + ".data[" + idx + "]: " + ("" + reasonArr.join(' ')));
  74969. }
  74970. return;
  74971. }
  74972. var cellMergeOwner = option && option.mergeCells;
  74973. var parsed = {
  74974. id: new Point(),
  74975. span: new Point(),
  74976. locatorRange: locatorRange,
  74977. option: option,
  74978. cellMergeOwner: cellMergeOwner
  74979. };
  74980. fillIdSpanFromLocatorRange(parsed, locatorRange);
  74981. // The order of the `parsedList` determines the precedence of the styles, if there
  74982. // are overlaps between ranges specified in different items. Preserve the original
  74983. // order of `matrix.body/corner/data` to make it predictable for users.
  74984. parsedList.push(parsed);
  74985. });
  74986. // Resolve cell merging intersection - union to a larger rect.
  74987. var mergedMarkList = [];
  74988. for (var parsedIdx = 0; parsedIdx < parsedList.length; parsedIdx++) {
  74989. var parsed = parsedList[parsedIdx];
  74990. if (!parsed.cellMergeOwner) {
  74991. continue;
  74992. }
  74993. var locatorRange = parsed.locatorRange;
  74994. resolveXYLocatorRangeByCellMerge(locatorRange, mergedMarkList, parsedList, parsedIdx);
  74995. for (var idx = 0; idx < parsedIdx; idx++) {
  74996. if (mergedMarkList[idx]) {
  74997. parsedList[idx].cellMergeOwner = false;
  74998. }
  74999. }
  75000. if (locatorRange[0][0] !== parsed.id.x || locatorRange[1][0] !== parsed.id.y) {
  75001. // The top-left cell of the unioned locatorRange is not this cell any more.
  75002. parsed.cellMergeOwner = false;
  75003. // Reconcile: simply use the last style and value option if multiple styles involved
  75004. // in a merged area, since there might be no commonly used merge strategy.
  75005. var newOption = extend({}, parsed.option);
  75006. newOption.coord = null;
  75007. var newParsed = {
  75008. id: new Point(),
  75009. span: new Point(),
  75010. locatorRange: locatorRange,
  75011. option: newOption,
  75012. cellMergeOwner: true
  75013. };
  75014. fillIdSpanFromLocatorRange(newParsed, locatorRange);
  75015. parsedList.push(newParsed);
  75016. }
  75017. }
  75018. // Assign options to cells.
  75019. each(parsedList, function (parsed) {
  75020. var topLeftCell = ensureBodyOrCornerCell(parsed.id.x, parsed.id.y);
  75021. if (parsed.cellMergeOwner) {
  75022. topLeftCell.cellMergeOwner = true;
  75023. topLeftCell.span = parsed.span;
  75024. topLeftCell.locatorRange = parsed.locatorRange;
  75025. topLeftCell.spanRect = createNaNRectLike();
  75026. self._cellMergeOwnerList.push(topLeftCell);
  75027. }
  75028. if (!parsed.cellMergeOwner && !parsed.option) {
  75029. return;
  75030. }
  75031. for (var yidx = 0; yidx < parsed.span.y; yidx++) {
  75032. for (var xidx = 0; xidx < parsed.span.x; xidx++) {
  75033. var cell = ensureBodyOrCornerCell(parsed.id.x + xidx, parsed.id.y + yidx);
  75034. // If multiple style options are defined on a cell, the later ones takes precedence.
  75035. cell.option = parsed.option;
  75036. if (parsed.cellMergeOwner) {
  75037. cell.inSpanOf = topLeftCell;
  75038. }
  75039. }
  75040. }
  75041. });
  75042. } // End of fillCellMap
  75043. function ensureBodyOrCornerCell(x, y) {
  75044. var key = makeCellMapKey(x, y);
  75045. var cell = _cellMap.get(key);
  75046. if (!cell) {
  75047. cell = _cellMap.set(key, {
  75048. id: new Point(x, y),
  75049. option: null,
  75050. inSpanOf: null,
  75051. span: null,
  75052. spanRect: null,
  75053. locatorRange: null,
  75054. cellMergeOwner: false
  75055. });
  75056. }
  75057. return cell;
  75058. }
  75059. };
  75060. /**
  75061. * Body cells or corner cell are not commonly defined specifically, especially in a large
  75062. * table, thus his is a sparse data structure - bodys or corner cells exist only if there
  75063. * are options specified to it (in `matrix.body.data` or `matrix.corner.data`);
  75064. * otherwise, return `NullUndefined`.
  75065. */
  75066. MatrixBodyCorner.prototype.getCell = function (xy) {
  75067. // Assert xy do not contain NaN
  75068. return this._ensureCellMap().get(makeCellMapKey(xy[0], xy[1]));
  75069. };
  75070. /**
  75071. * Only cell existing (has specific definition or props) will be travelled.
  75072. */
  75073. MatrixBodyCorner.prototype.travelExistingCells = function (cb) {
  75074. this._ensureCellMap().each(cb);
  75075. };
  75076. /**
  75077. * @param locatorRange Must be the return of `parseCoordRangeOption`.
  75078. */
  75079. MatrixBodyCorner.prototype.expandRangeByCellMerge = function (locatorRange) {
  75080. if (!isXYLocatorRangeInvalidOnDim(locatorRange, 0) && !isXYLocatorRangeInvalidOnDim(locatorRange, 1) && locatorRange[0][0] === locatorRange[0][1] && locatorRange[1][0] === locatorRange[1][1]) {
  75081. // If it locates to a single cell, use this quick path to avoid travelling.
  75082. // It is based on the fact that any cell is not contained by more than one cell merging rect.
  75083. _tmpERBCMLocator[0] = locatorRange[0][0];
  75084. _tmpERBCMLocator[1] = locatorRange[1][0];
  75085. var cell = this.getCell(_tmpERBCMLocator);
  75086. var inSpanOf = cell && cell.inSpanOf;
  75087. if (inSpanOf) {
  75088. cloneXYLocatorRange(locatorRange, inSpanOf.locatorRange);
  75089. return;
  75090. }
  75091. }
  75092. var list = this._cellMergeOwnerList;
  75093. resolveXYLocatorRangeByCellMerge(locatorRange, null, list, list.length);
  75094. };
  75095. return MatrixBodyCorner;
  75096. }();
  75097. var _tmpERBCMLocator = [];
  75098. function makeCellMapKey(x, y) {
  75099. return x + "|" + y;
  75100. }
  75101. var defaultLabelOption = {
  75102. show: true,
  75103. color: tokens.color.secondary,
  75104. // overflow: 'truncate',
  75105. overflow: 'break',
  75106. lineOverflow: 'truncate',
  75107. padding: [2, 3, 2, 3],
  75108. // Prefer to use `padding`, rather than distance.
  75109. distance: 0
  75110. };
  75111. function makeDefaultCellItemStyleOption(isCorner) {
  75112. return {
  75113. color: 'none',
  75114. borderWidth: 1,
  75115. borderColor: isCorner ? 'none' : tokens.color.borderTint
  75116. };
  75117. }
  75118. var defaultDimOption = {
  75119. show: true,
  75120. label: defaultLabelOption,
  75121. itemStyle: makeDefaultCellItemStyleOption(false),
  75122. silent: undefined,
  75123. dividerLineStyle: {
  75124. width: 1,
  75125. color: tokens.color.border
  75126. }
  75127. };
  75128. var defaultBodyOption = {
  75129. label: defaultLabelOption,
  75130. itemStyle: makeDefaultCellItemStyleOption(false),
  75131. silent: undefined
  75132. };
  75133. var defaultCornerOption = {
  75134. label: defaultLabelOption,
  75135. itemStyle: makeDefaultCellItemStyleOption(true),
  75136. silent: undefined
  75137. };
  75138. var defaultMatrixOption = {
  75139. // As a most basic coord sys, `z` should be lower than
  75140. // other series and coord sys, such as, grid.
  75141. z: -50,
  75142. left: '10%',
  75143. top: '10%',
  75144. right: '10%',
  75145. bottom: '10%',
  75146. x: defaultDimOption,
  75147. y: defaultDimOption,
  75148. body: defaultBodyOption,
  75149. corner: defaultCornerOption,
  75150. backgroundStyle: {
  75151. color: 'none',
  75152. borderColor: tokens.color.axisLine,
  75153. borderWidth: 1
  75154. }
  75155. };
  75156. var MatrixModel = /** @class */function (_super) {
  75157. __extends(MatrixModel, _super);
  75158. function MatrixModel() {
  75159. var _this = _super !== null && _super.apply(this, arguments) || this;
  75160. _this.type = MatrixModel.type;
  75161. return _this;
  75162. }
  75163. MatrixModel.prototype.optionUpdated = function () {
  75164. // Simply re-create all to follow model changes.
  75165. var dimModels = this._dimModels = {
  75166. // Do not use matrixModel as the parent model, for preventing from cascade-fetching options to it.
  75167. x: new MatrixDimensionModel(this.get('x', true) || {}),
  75168. y: new MatrixDimensionModel(this.get('y', true) || {})
  75169. };
  75170. dimModels.x.option.type = dimModels.y.option.type = 'category';
  75171. var xDim = dimModels.x.dim = new MatrixDim('x', dimModels.x);
  75172. var yDim = dimModels.y.dim = new MatrixDim('y', dimModels.y);
  75173. var dims = {
  75174. x: xDim,
  75175. y: yDim
  75176. };
  75177. this._body = new MatrixBodyCorner('body', new Model(this.getShallow('body')), dims);
  75178. this._corner = new MatrixBodyCorner('corner', new Model(this.getShallow('corner')), dims);
  75179. };
  75180. MatrixModel.prototype.getDimensionModel = function (dim) {
  75181. return this._dimModels[dim];
  75182. };
  75183. MatrixModel.prototype.getBody = function () {
  75184. return this._body;
  75185. };
  75186. MatrixModel.prototype.getCorner = function () {
  75187. return this._corner;
  75188. };
  75189. MatrixModel.type = 'matrix';
  75190. MatrixModel.layoutMode = 'box';
  75191. MatrixModel.defaultOption = defaultMatrixOption;
  75192. return MatrixModel;
  75193. }(ComponentModel);
  75194. var MatrixDimensionModel = /** @class */function (_super) {
  75195. __extends(MatrixDimensionModel, _super);
  75196. function MatrixDimensionModel() {
  75197. return _super !== null && _super.apply(this, arguments) || this;
  75198. }
  75199. MatrixDimensionModel.prototype.getOrdinalMeta = function () {
  75200. return this.dim.getOrdinalMeta();
  75201. };
  75202. return MatrixDimensionModel;
  75203. }(Model);
  75204. var round$4 = Math.round;
  75205. var Z2_BACKGROUND = 0;
  75206. var Z2_OUTER_BORDER = 99;
  75207. var Z2_BODY_CORNER_CELL_DEFAULT = {
  75208. normal: 25,
  75209. special: 100
  75210. };
  75211. var Z2_DIMENSION_CELL_DEFAULT = {
  75212. normal: 50,
  75213. special: 125
  75214. };
  75215. var MatrixView = /** @class */function (_super) {
  75216. __extends(MatrixView, _super);
  75217. function MatrixView() {
  75218. var _this = _super !== null && _super.apply(this, arguments) || this;
  75219. _this.type = MatrixView.type;
  75220. return _this;
  75221. }
  75222. MatrixView.prototype.render = function (matrixModel, ecModel) {
  75223. this.group.removeAll();
  75224. var group = this.group;
  75225. var coordSys = matrixModel.coordinateSystem;
  75226. var rect = coordSys.getRect();
  75227. var xDimModel = matrixModel.getDimensionModel('x');
  75228. var yDimModel = matrixModel.getDimensionModel('y');
  75229. var xDim = xDimModel.dim;
  75230. var yDim = yDimModel.dim;
  75231. // PENDING:
  75232. // reuse the existing text and rect elements for performance?
  75233. renderDimensionCells(group, matrixModel, ecModel);
  75234. createBodyAndCorner(group, matrixModel, xDim, yDim, ecModel);
  75235. var borderZ2Option = matrixModel.getShallow('borderZ2', true);
  75236. var outerBorderZ2 = retrieve2(borderZ2Option, Z2_OUTER_BORDER);
  75237. var dividerLineZ2 = outerBorderZ2 - 1;
  75238. // Outer border and overall background. Use separate elements because of z-order:
  75239. // The overall background should appear below any other elements.
  75240. // But in most cases, the outer border and the divider line should be above the normal cell borders -
  75241. // especially when cell borders have different colors. But users may highlight some specific cells by
  75242. // overstirking their border, in which case it should be above the outer border.
  75243. var bgStyle = matrixModel.getModel('backgroundStyle').getItemStyle(['borderWidth']);
  75244. bgStyle.lineWidth = 0;
  75245. var borderStyle = matrixModel.getModel('backgroundStyle').getItemStyle(['color', 'decal', 'shadowColor', 'shadowBlur', 'shadowOffsetX', 'shadowOffsetY']);
  75246. borderStyle.fill = 'none';
  75247. var bgRect = createMatrixRect(rect.clone(), bgStyle, Z2_BACKGROUND);
  75248. var borderRect = createMatrixRect(rect.clone(), borderStyle, outerBorderZ2);
  75249. bgRect.silent = true;
  75250. borderRect.silent = true;
  75251. group.add(bgRect);
  75252. group.add(borderRect);
  75253. // Header split line.
  75254. var xDimCell0 = xDim.getUnitLayoutInfo(0, 0);
  75255. var yDimCell0 = yDim.getUnitLayoutInfo(1, 0);
  75256. if (xDimCell0 && yDimCell0) {
  75257. if (xDim.shouldShow()) {
  75258. group.add(createMatrixLine({
  75259. x1: rect.x,
  75260. y1: yDimCell0.xy,
  75261. x2: rect.x + rect.width,
  75262. y2: yDimCell0.xy
  75263. }, xDimModel.getModel('dividerLineStyle').getLineStyle(), dividerLineZ2));
  75264. }
  75265. if (yDim.shouldShow()) {
  75266. group.add(createMatrixLine({
  75267. x1: xDimCell0.xy,
  75268. y1: rect.y,
  75269. x2: xDimCell0.xy,
  75270. y2: rect.y + rect.height
  75271. }, yDimModel.getModel('dividerLineStyle').getLineStyle(), dividerLineZ2));
  75272. }
  75273. }
  75274. };
  75275. MatrixView.type = 'matrix';
  75276. return MatrixView;
  75277. }(ComponentView);
  75278. function renderDimensionCells(group, matrixModel, ecModel) {
  75279. renderOnDimension(0);
  75280. renderOnDimension(1);
  75281. function renderOnDimension(dimIdx) {
  75282. var thisDimModel = matrixModel.getDimensionModel(XY$1[dimIdx]);
  75283. var thisDim = thisDimModel.dim;
  75284. if (!thisDim.shouldShow()) {
  75285. return;
  75286. }
  75287. var thisDimBgStyleModel = thisDimModel.getModel('itemStyle');
  75288. var thisDimLabelModel = thisDimModel.getModel('label');
  75289. var tooltipOption = matrixModel.getShallow('tooltip', true);
  75290. var xyLocator = [];
  75291. for (var it_1 = thisDim.resetCellIterator(); it_1.next();) {
  75292. var dimCell = it_1.item;
  75293. var shape = {};
  75294. BoundingRect.copy(shape, dimCell.rect);
  75295. set(xyLocator, dimCell.id.x, dimCell.id.y);
  75296. createMatrixCell(xyLocator, matrixModel, group, ecModel, dimCell.option, thisDimBgStyleModel, thisDimLabelModel, thisDimModel, shape, dimCell.option.value, Z2_DIMENSION_CELL_DEFAULT, tooltipOption);
  75297. }
  75298. }
  75299. }
  75300. function createBodyAndCorner(group, matrixModel, xDim, yDim, ecModel) {
  75301. createBodyOrCornerCells('body', matrixModel.getBody(), xDim, yDim);
  75302. if (xDim.shouldShow() && yDim.shouldShow()) {
  75303. createBodyOrCornerCells('corner', matrixModel.getCorner(), yDim, xDim);
  75304. }
  75305. function createBodyOrCornerCells(bodyCornerOptionRoot, bodyOrCorner, dimForCoordX,
  75306. // Can be `matrix.y` (transposed) for corners.
  75307. dimForCoordY) {
  75308. // Prevent inheriting from ancestor.
  75309. var parentCellModel = new Model(matrixModel.getShallow(bodyCornerOptionRoot, true));
  75310. var parentItemStyleModel = parentCellModel.getModel('itemStyle');
  75311. var parentLabelModel = parentCellModel.getModel('label');
  75312. var itx = new ListIterator();
  75313. var ity = new ListIterator();
  75314. var xyLocator = [];
  75315. var tooltipOption = matrixModel.getShallow('tooltip', true);
  75316. for (dimForCoordY.resetLayoutIterator(ity, 1); ity.next();) {
  75317. for (dimForCoordX.resetLayoutIterator(itx, 0); itx.next();) {
  75318. var xLayout = itx.item;
  75319. var yLayout = ity.item;
  75320. set(xyLocator, xLayout.id.x, yLayout.id.y);
  75321. var bodyCornerCell = bodyOrCorner.getCell(xyLocator);
  75322. // If in span of an other body or corner cell, never render it.
  75323. if (bodyCornerCell && bodyCornerCell.inSpanOf && bodyCornerCell.inSpanOf !== bodyCornerCell) {
  75324. continue;
  75325. }
  75326. var shape = {};
  75327. if (bodyCornerCell && bodyCornerCell.span) {
  75328. BoundingRect.copy(shape, bodyCornerCell.spanRect);
  75329. } else {
  75330. xLayout.dim.getLayout(shape, 0, xyLocator[0]);
  75331. yLayout.dim.getLayout(shape, 1, xyLocator[1]);
  75332. }
  75333. var bodyCornerCellOption = bodyCornerCell ? bodyCornerCell.option : null;
  75334. createMatrixCell(xyLocator, matrixModel, group, ecModel, bodyCornerCellOption, parentItemStyleModel, parentLabelModel, parentCellModel, shape, bodyCornerCellOption ? bodyCornerCellOption.value : null, Z2_BODY_CORNER_CELL_DEFAULT, tooltipOption);
  75335. }
  75336. }
  75337. } // End of createBodyOrCornerCells
  75338. }
  75339. function createMatrixCell(xyLocator, matrixModel, group, ecModel, cellOption, parentItemStyleModel, parentLabelModel, parentCellModel, shape, textValue, zrCellDefault, tooltipOption) {
  75340. var _a;
  75341. // Do not use getModel for handy performance optimization.
  75342. _tmpCellItemStyleModel.option = cellOption ? cellOption.itemStyle : null;
  75343. _tmpCellItemStyleModel.parentModel = parentItemStyleModel;
  75344. _tmpCellModel.option = cellOption;
  75345. _tmpCellModel.parentModel = parentCellModel;
  75346. // Use different z2 because special border may be defined in itemStyle.
  75347. var z2 = retrieve2(_tmpCellModel.getShallow('z2'), cellOption && cellOption.itemStyle ? zrCellDefault.special : zrCellDefault.normal);
  75348. var tooltipOptionShow = tooltipOption && tooltipOption.show;
  75349. var cellRect = createMatrixRect(shape, _tmpCellItemStyleModel.getItemStyle(), z2);
  75350. group.add(cellRect);
  75351. var cursorOption = _tmpCellModel.get('cursor');
  75352. if (cursorOption != null) {
  75353. cellRect.attr('cursor', cursorOption);
  75354. }
  75355. var cellText;
  75356. if (textValue != null) {
  75357. var text = textValue + '';
  75358. _tmpCellLabelModel.option = cellOption ? cellOption.label : null;
  75359. _tmpCellLabelModel.parentModel = parentLabelModel;
  75360. // This is to accept `option.textStyle` as the default.
  75361. _tmpCellLabelModel.ecModel = ecModel;
  75362. setLabelStyle(cellRect,
  75363. // Currently do not support other states (`emphasis`, `select`, `blur`)
  75364. {
  75365. normal: _tmpCellLabelModel
  75366. }, {
  75367. defaultText: text,
  75368. autoOverflowArea: true,
  75369. // By default based on boundingRect. But boundingRect contains borderWidth,
  75370. // and borderWidth is half outside the cell. Thus specific `layoutRect` explicitly.
  75371. layoutRect: clone(cellRect.shape)
  75372. });
  75373. cellText = cellRect.getTextContent();
  75374. if (cellText) {
  75375. cellText.z2 = z2 + 1;
  75376. var style = cellText.style;
  75377. if (style && style.overflow && style.overflow !== 'none' && style.lineOverflow) {
  75378. // `overflow: 'break'/'breakAll'/'truncate'` does not guarantee prevention of overflow
  75379. // when space is insufficient. Use a `clipPath` in such case.
  75380. var clipShape = {};
  75381. BoundingRect.copy(clipShape, shape);
  75382. // `lineWidth` is half outside half inside the bounding rect.
  75383. expandOrShrinkRect(clipShape, (((_a = cellRect.style) === null || _a === void 0 ? void 0 : _a.lineWidth) || 0) / 2, true, true);
  75384. cellRect.updateInnerText();
  75385. cellText.getLocalTransform(_tmpInnerTextTrans);
  75386. invert(_tmpInnerTextTrans, _tmpInnerTextTrans);
  75387. BoundingRect.applyTransform(clipShape, clipShape, _tmpInnerTextTrans);
  75388. cellText.setClipPath(new Rect({
  75389. shape: clipShape
  75390. }));
  75391. }
  75392. }
  75393. setTooltipConfig({
  75394. el: cellRect,
  75395. componentModel: matrixModel,
  75396. itemName: text,
  75397. itemTooltipOption: tooltipOption,
  75398. formatterParamsExtra: {
  75399. xyLocator: xyLocator.slice()
  75400. }
  75401. });
  75402. }
  75403. // Set silent
  75404. if (cellText) {
  75405. var labelSilent = _tmpCellLabelModel.get('silent');
  75406. // auto, tooltip of text cells need silient: false, but non-text cells
  75407. // do not need a special cursor in most cases.
  75408. if (labelSilent == null) {
  75409. labelSilent = !tooltipOptionShow;
  75410. }
  75411. cellText.silent = labelSilent;
  75412. cellText.ignoreHostSilent = true;
  75413. }
  75414. var rectSilent = _tmpCellModel.get('silent');
  75415. if (rectSilent == null) {
  75416. rectSilent =
  75417. // If no background color in cell, set `rect.silent: false` will cause that only
  75418. // the border response to mouse hovering, which is probably weird.
  75419. !cellRect.style || cellRect.style.fill === 'none' || !cellRect.style.fill;
  75420. }
  75421. cellRect.silent = rectSilent;
  75422. clearTmpModel(_tmpCellModel);
  75423. clearTmpModel(_tmpCellItemStyleModel);
  75424. clearTmpModel(_tmpCellLabelModel);
  75425. }
  75426. var _tmpCellModel = new Model();
  75427. var _tmpCellItemStyleModel = new Model();
  75428. var _tmpCellLabelModel = new Model();
  75429. var _tmpInnerTextTrans = [];
  75430. // FIXME: move all of the subpixel process to Matrix.ts resize, otherwise the result of
  75431. // `dataToLayout` is not consistent with this rendering, and the caller (like heatmap) can
  75432. // not precisely align with the matrix border.
  75433. function createMatrixRect(shape, style, z2) {
  75434. // Currently `subPixelOptimizeRect` can not be used here because it will break rect alignment.
  75435. // Optimize line and rect with the same direction.
  75436. var lineWidth = style.lineWidth;
  75437. if (lineWidth) {
  75438. var x2Original = shape.x + shape.width;
  75439. var y2Original = shape.y + shape.height;
  75440. shape.x = subPixelOptimize(shape.x, lineWidth, true);
  75441. shape.y = subPixelOptimize(shape.y, lineWidth, true);
  75442. shape.width = subPixelOptimize(x2Original, lineWidth, true) - shape.x;
  75443. shape.height = subPixelOptimize(y2Original, lineWidth, true) - shape.y;
  75444. }
  75445. return new Rect({
  75446. shape: shape,
  75447. style: style,
  75448. z2: z2
  75449. });
  75450. }
  75451. function createMatrixLine(shape, style, z2) {
  75452. var lineWidth = style.lineWidth;
  75453. if (lineWidth) {
  75454. if (round$4(shape.x1 * 2) === round$4(shape.x2 * 2)) {
  75455. shape.x1 = shape.x2 = subPixelOptimize(shape.x1, lineWidth, true);
  75456. }
  75457. if (round$4(shape.y1 * 2) === round$4(shape.y2 * 2)) {
  75458. shape.y1 = shape.y2 = subPixelOptimize(shape.y1, lineWidth, true);
  75459. }
  75460. }
  75461. return new Line({
  75462. shape: shape,
  75463. style: style,
  75464. silent: true,
  75465. z2: z2
  75466. });
  75467. }
  75468. var Matrix = /** @class */function () {
  75469. function Matrix(matrixModel, ecModel, api) {
  75470. this.dimensions = Matrix.dimensions;
  75471. this.type = 'matrix';
  75472. this._model = matrixModel;
  75473. var models = this._dimModels = {
  75474. x: matrixModel.getDimensionModel('x'),
  75475. y: matrixModel.getDimensionModel('y')
  75476. };
  75477. this._dims = {
  75478. x: models.x.dim,
  75479. y: models.y.dim
  75480. };
  75481. this._resize(matrixModel, api);
  75482. }
  75483. /**
  75484. * @see fetchers in `model/referHelper.ts`,
  75485. * which is used to parse data in ordinal way.
  75486. * In most series only 'x' and 'y' is required,
  75487. * but some series, such as heatmap, can specify value.
  75488. */
  75489. Matrix.getDimensionsInfo = function () {
  75490. return [{
  75491. name: 'x',
  75492. type: 'ordinal'
  75493. }, {
  75494. name: 'y',
  75495. type: 'ordinal'
  75496. }, {
  75497. name: 'value'
  75498. }];
  75499. };
  75500. Matrix.create = function (ecModel, api) {
  75501. var matrixList = [];
  75502. ecModel.eachComponent('matrix', function (matrixModel) {
  75503. var matrix = new Matrix(matrixModel, ecModel, api);
  75504. matrixList.push(matrix);
  75505. matrixModel.coordinateSystem = matrix;
  75506. });
  75507. // Inject coordinate system
  75508. // PENDING: optimize to not to travel all components?
  75509. // (collect relevant components in ecModel only when model update?)
  75510. ecModel.eachComponent(function (mainType, componentModel) {
  75511. injectCoordSysByOption({
  75512. targetModel: componentModel,
  75513. coordSysType: 'matrix',
  75514. coordSysProvider: simpleCoordSysInjectionProvider
  75515. });
  75516. });
  75517. return matrixList;
  75518. };
  75519. Matrix.prototype.getRect = function () {
  75520. return this._rect;
  75521. };
  75522. Matrix.prototype._resize = function (matrixModel, api) {
  75523. var dims = this._dims;
  75524. var dimModels = this._dimModels;
  75525. var rect = this._rect = getLayoutRect(matrixModel.getBoxLayoutParams(), {
  75526. width: api.getWidth(),
  75527. height: api.getHeight()
  75528. });
  75529. layOutUnitsOnDimension(dimModels, dims, rect, 0);
  75530. layOutUnitsOnDimension(dimModels, dims, rect, 1);
  75531. layOutDimCellsRestInfoByUnit(0, dims);
  75532. layOutDimCellsRestInfoByUnit(1, dims);
  75533. layOutBodyCornerCellMerge(this._model.getBody(), dims);
  75534. layOutBodyCornerCellMerge(this._model.getCorner(), dims);
  75535. };
  75536. /**
  75537. * @implement
  75538. * - The input is allowed to be `[NaN/null/undefined, xxx]`/`[xxx, NaN/null/undefined]`;
  75539. * the return is `[NaN, xxxresult]`/`[xxxresult, NaN]` or clamped boundary value if
  75540. * `clamp` passed. This is for the usage that only get coord on single x or y.
  75541. * - Alwasy return an numeric array, but never be null/undefined.
  75542. * If it can not be located or invalid, return `[NaN, NaN]`.
  75543. */
  75544. Matrix.prototype.dataToPoint = function (data, opt, out) {
  75545. out = out || [];
  75546. this.dataToLayout(data, opt, _dtpOutDataToLayout);
  75547. out[0] = _dtpOutDataToLayout.rect.x + _dtpOutDataToLayout.rect.width / 2;
  75548. out[1] = _dtpOutDataToLayout.rect.y + _dtpOutDataToLayout.rect.height / 2;
  75549. return out;
  75550. };
  75551. /**
  75552. * @implement
  75553. * - The input is allowed to be `[NaN/null/undefined, xxx]`/`[xxx, NaN/null/undefined]`;
  75554. * the return is `{x: NaN, width: NaN, y: xxxresulty, height: xxxresulth}`/
  75555. * `{y: NaN, height: NaN, x: xxxresultx, width: xxxresultw}` or clamped boundary value
  75556. * if `clamp` passed. This is for the usage that only get coord on single x or y.
  75557. * - The returned `out.rect` and `out.matrixXYLocatorRange` is always an object or an 2d-array,
  75558. * but never be null/undefined. If it cannot be located or invalid, `NaN` is in their
  75559. * corresponding number props.
  75560. * - Do not provide `out.contentRect`, because it's allowed to input non-leaf dimension x/y or
  75561. * a range of x/y, which determines a rect covering multiple cells (even not merged), in which
  75562. * case the padding and borderWidth can not be determined to make a contentRect. Therefore only
  75563. * return `out.rect` in any case for consistency. The caller is responsible for adding space to
  75564. * avoid covering cell borders, if necessary.
  75565. */
  75566. Matrix.prototype.dataToLayout = function (data, opt, out) {
  75567. var dims = this._dims;
  75568. out = out || {};
  75569. var outRect = out.rect = out.rect || {};
  75570. outRect.x = outRect.y = outRect.width = outRect.height = NaN;
  75571. var outLocRange = out.matrixXYLocatorRange = resetXYLocatorRange(out.matrixXYLocatorRange);
  75572. if (!isArray(data)) {
  75573. if ("development" !== 'production') {
  75574. error('Input data must be an array in `convertToLayout`, `convertToPixel`');
  75575. }
  75576. return out;
  75577. }
  75578. parseCoordRangeOption(outLocRange, null, data, dims, retrieve2(opt && opt.clamp, MatrixClampOption.none));
  75579. if (!opt || !opt.ignoreMergeCells) {
  75580. if (!opt || opt.clamp !== MatrixClampOption.corner) {
  75581. this._model.getBody().expandRangeByCellMerge(outLocRange);
  75582. }
  75583. if (!opt || opt.clamp !== MatrixClampOption.body) {
  75584. this._model.getCorner().expandRangeByCellMerge(outLocRange);
  75585. }
  75586. }
  75587. xyLocatorRangeToRectOneDim(outRect, outLocRange, dims, 0);
  75588. xyLocatorRangeToRectOneDim(outRect, outLocRange, dims, 1);
  75589. return out;
  75590. };
  75591. /**
  75592. * The returned locator pair can be the input of `dataToPoint` or `dataToLayout`.
  75593. *
  75594. * If point[0] is out of the matrix rect,
  75595. * the out[0] is NaN;
  75596. * else if it is on the right of top-left corner of body,
  75597. * the out[0] is the oridinal number (>= 0).
  75598. * else
  75599. * out[0] is the locator for corner or header (<= 0).
  75600. *
  75601. * The same rule goes for point[1] and out[1].
  75602. *
  75603. * But point[0] and point[1] are calculated separately, i.e.,
  75604. * the reuslt can be `[1, NaN]` or `[NaN, 1]` if only one dimension is out of boundary.
  75605. *
  75606. * @implement
  75607. */
  75608. Matrix.prototype.pointToData = function (point, opt, out) {
  75609. var dims = this._dims;
  75610. pointToDataOneDimPrepareCtx(_tmpCtxPointToData, 0, dims, point, opt && opt.clamp);
  75611. pointToDataOneDimPrepareCtx(_tmpCtxPointToData, 1, dims, point, opt && opt.clamp);
  75612. out = out || [];
  75613. out[0] = out[1] = NaN;
  75614. if (_tmpCtxPointToData.y === CtxPointToDataAreaType.inCorner && _tmpCtxPointToData.x === CtxPointToDataAreaType.inBody) {
  75615. pointToDataOnlyHeaderFillOut(_tmpCtxPointToData, out, 0, dims);
  75616. } else if (_tmpCtxPointToData.x === CtxPointToDataAreaType.inCorner && _tmpCtxPointToData.y === CtxPointToDataAreaType.inBody) {
  75617. pointToDataOnlyHeaderFillOut(_tmpCtxPointToData, out, 1, dims);
  75618. } else {
  75619. pointToDataBodyCornerFillOut(_tmpCtxPointToData, out, 0, dims);
  75620. pointToDataBodyCornerFillOut(_tmpCtxPointToData, out, 1, dims);
  75621. }
  75622. return out;
  75623. };
  75624. Matrix.prototype.convertToPixel = function (ecModel, finder, value, opt) {
  75625. var coordSys = getCoordSys$5(finder);
  75626. return coordSys === this ? coordSys.dataToPoint(value, opt) : undefined;
  75627. };
  75628. Matrix.prototype.convertToLayout = function (ecModel, finder, value, opt) {
  75629. var coordSys = getCoordSys$5(finder);
  75630. return coordSys === this ? coordSys.dataToLayout(value, opt) : undefined;
  75631. };
  75632. Matrix.prototype.convertFromPixel = function (ecModel, finder, pixel, opt) {
  75633. var coordSys = getCoordSys$5(finder);
  75634. return coordSys === this ? coordSys.pointToData(pixel, opt) : undefined;
  75635. };
  75636. Matrix.prototype.containPoint = function (point) {
  75637. return this._rect.contain(point[0], point[1]);
  75638. };
  75639. Matrix.dimensions = ['x', 'y', 'value'];
  75640. return Matrix;
  75641. }();
  75642. var _dtpOutDataToLayout = {
  75643. rect: createNaNRectLike()
  75644. };
  75645. var _ptdLevelIt = new ListIterator();
  75646. var _ptdDimCellIt = new ListIterator();
  75647. function layOutUnitsOnDimension(dimModels, dims, matrixRect, dimIdx) {
  75648. var otherDimIdx = 1 - dimIdx;
  75649. var thisDim = dims[XY$1[dimIdx]];
  75650. var otherDim = dims[XY$1[otherDimIdx]];
  75651. // Notice: If matrix.x/y.show is false, still lay out, to ensure the
  75652. // consistent return of `dataToLayout`.
  75653. var otherDimShow = otherDim.shouldShow();
  75654. // Reset
  75655. for (var it_1 = thisDim.resetCellIterator(); it_1.next();) {
  75656. it_1.item.wh = it_1.item.xy = NaN;
  75657. }
  75658. for (var it_2 = otherDim.resetLayoutIterator(null, dimIdx); it_2.next();) {
  75659. it_2.item.wh = it_2.item.xy = NaN;
  75660. }
  75661. // Set specified size from option.
  75662. var restSize = matrixRect[WH$1[dimIdx]];
  75663. var restCellsCount = thisDim.getLocatorCount(dimIdx) + otherDim.getLocatorCount(dimIdx);
  75664. var tmpLevelModel = new Model();
  75665. for (var it_3 = otherDim.resetLevelIterator(); it_3.next();) {
  75666. // Consider `matrix.x.levelSize` and `matrix.x.levels[i].levelSize`.
  75667. tmpLevelModel.option = it_3.item.option;
  75668. tmpLevelModel.parentModel = dimModels[XY$1[otherDimIdx]];
  75669. layOutSpecified(it_3.item, otherDimShow ? tmpLevelModel.get('levelSize') : 0);
  75670. }
  75671. var tmpCellModel = new Model();
  75672. for (var it_4 = thisDim.resetCellIterator(); it_4.next();) {
  75673. // Only leaf support size specification, to avoid unnecessary complexity.
  75674. if (it_4.item.type === MatrixCellLayoutInfoType.leaf) {
  75675. tmpCellModel.option = it_4.item.option;
  75676. tmpCellModel.parentModel = undefined;
  75677. layOutSpecified(it_4.item, tmpCellModel.get('size'));
  75678. }
  75679. }
  75680. function layOutSpecified(item, sizeOption) {
  75681. var size = parseSizeOption(sizeOption, dimIdx, matrixRect);
  75682. if (!eqNaN(size)) {
  75683. item.wh = confineSize(size, restSize);
  75684. restSize = confineSize(restSize - item.wh);
  75685. restCellsCount--;
  75686. }
  75687. }
  75688. // Set all sizes and positions to levels and leaf cells of which size is unspecified.
  75689. // Contents lay out based on matrix, rather than inverse; therefore do not support
  75690. // calculating size based on content, but allocate equally.
  75691. var computedCellWH = restCellsCount ? restSize / restCellsCount : 0;
  75692. // If all size specified, but some space remain (may also caused by matrix.x/y.show: false)
  75693. // do not align to the big most edge.
  75694. var notAlignToBigmost = !restCellsCount && restSize >= 1; // `1` for cumulative precision error.
  75695. var currXY = matrixRect[XY$1[dimIdx]];
  75696. var maxLocator = thisDim.getLocatorCount(dimIdx) - 1;
  75697. var it = new ListIterator();
  75698. // Lay out levels of the perpendicular dim.
  75699. for (otherDim.resetLayoutIterator(it, dimIdx); it.next();) {
  75700. layOutUnspecified(it.item);
  75701. }
  75702. for (thisDim.resetLayoutIterator(it, dimIdx); it.next();) {
  75703. layOutUnspecified(it.item);
  75704. }
  75705. function layOutUnspecified(item) {
  75706. if (eqNaN(item.wh)) {
  75707. item.wh = computedCellWH;
  75708. }
  75709. item.xy = currXY;
  75710. if (item.id[XY$1[dimIdx]] === maxLocator && !notAlignToBigmost) {
  75711. // Align to the rightmost border, consider cumulative precision error.
  75712. item.wh = matrixRect[XY$1[dimIdx]] + matrixRect[WH$1[dimIdx]] - item.xy;
  75713. }
  75714. currXY += item.wh;
  75715. }
  75716. }
  75717. function layOutDimCellsRestInfoByUnit(dimIdx, dims) {
  75718. // Finally save layout info based on the unit leaves and levels.
  75719. for (var it_5 = dims[XY$1[dimIdx]].resetCellIterator(); it_5.next();) {
  75720. var dimCell = it_5.item;
  75721. layOutRectOneDimBasedOnUnit(dimCell.rect, dimIdx, dimCell.id, dimCell.span, dims);
  75722. // Consider level varitation on tree leaves, should extend the size to touch matrix body
  75723. // to avoid weird appearance.
  75724. layOutRectOneDimBasedOnUnit(dimCell.rect, 1 - dimIdx, dimCell.id, dimCell.span, dims);
  75725. if (dimCell.type === MatrixCellLayoutInfoType.nonLeaf) {
  75726. // `xy` and `wh` need to be saved in non-leaf since it supports locating by non-leaf
  75727. // in `dataToPoint` or `dataToLayout`.
  75728. dimCell.xy = dimCell.rect[XY$1[dimIdx]];
  75729. dimCell.wh = dimCell.rect[WH$1[dimIdx]];
  75730. }
  75731. }
  75732. }
  75733. function layOutBodyCornerCellMerge(bodyOrCorner, dims) {
  75734. bodyOrCorner.travelExistingCells(function (cell) {
  75735. var computedSpan = cell.span;
  75736. if (computedSpan) {
  75737. var layoutRect = cell.spanRect;
  75738. var id = cell.id;
  75739. layOutRectOneDimBasedOnUnit(layoutRect, 0, id, computedSpan, dims);
  75740. layOutRectOneDimBasedOnUnit(layoutRect, 1, id, computedSpan, dims);
  75741. }
  75742. });
  75743. }
  75744. // Save to rect for rendering.
  75745. function layOutRectOneDimBasedOnUnit(outRect, dimIdx, id, span, dims) {
  75746. outRect[WH$1[dimIdx]] = 0;
  75747. var locator = id[XY$1[dimIdx]];
  75748. var dim = locator < 0 ? dims[XY$1[1 - dimIdx]] : dims[XY$1[dimIdx]];
  75749. var layoutUnit = dim.getUnitLayoutInfo(dimIdx, id[XY$1[dimIdx]]);
  75750. outRect[XY$1[dimIdx]] = layoutUnit.xy;
  75751. outRect[WH$1[dimIdx]] = layoutUnit.wh;
  75752. if (span[XY$1[dimIdx]] > 1) {
  75753. var layoutUnit2 = dim.getUnitLayoutInfo(dimIdx, id[XY$1[dimIdx]] + span[XY$1[dimIdx]] - 1);
  75754. // Be careful the cumulative error - cell must be aligned.
  75755. outRect[WH$1[dimIdx]] = layoutUnit2.xy + layoutUnit2.wh - layoutUnit.xy;
  75756. }
  75757. }
  75758. /**
  75759. * Return NaN if not defined or invalid.
  75760. */
  75761. function parseSizeOption(sizeOption, dimIdx, matrixRect) {
  75762. var sizeNum = parsePositionSizeOption(sizeOption, matrixRect[WH$1[dimIdx]]);
  75763. return confineSize(sizeNum, matrixRect[WH$1[dimIdx]]);
  75764. }
  75765. function confineSize(sizeNum, sizeLimit) {
  75766. return Math.max(Math.min(sizeNum, retrieve2(sizeLimit, Infinity)), 0);
  75767. }
  75768. function getCoordSys$5(finder) {
  75769. var matrixModel = finder.matrixModel;
  75770. var seriesModel = finder.seriesModel;
  75771. var coordSys = matrixModel ? matrixModel.coordinateSystem : seriesModel ? seriesModel.coordinateSystem : null;
  75772. return coordSys;
  75773. }
  75774. var CtxPointToDataAreaType = {
  75775. inBody: 1,
  75776. inCorner: 2,
  75777. outside: 3
  75778. };
  75779. // For handy performance optimization in pointToData.
  75780. var _tmpCtxPointToData = {
  75781. x: null,
  75782. y: null,
  75783. point: []
  75784. };
  75785. function pointToDataOneDimPrepareCtx(ctx, dimIdx, dims, point, clamp) {
  75786. var thisDim = dims[XY$1[dimIdx]];
  75787. var otherDim = dims[XY$1[1 - dimIdx]];
  75788. // Notice: considered cases: `matrix.x/y.show: false`, `matrix.x/y.data` is empty.
  75789. // In this cases the `layout.xy` is on the edge and `layout.wh` is `0`; they still can be
  75790. // use to calculate clampping.
  75791. var bodyMaxUnit = thisDim.getUnitLayoutInfo(dimIdx, thisDim.getLocatorCount(dimIdx) - 1);
  75792. var body0Unit = thisDim.getUnitLayoutInfo(dimIdx, 0);
  75793. var cornerMinUnit = otherDim.getUnitLayoutInfo(dimIdx, -otherDim.getLocatorCount(dimIdx));
  75794. var cornerMinus1Unit = otherDim.shouldShow() ? otherDim.getUnitLayoutInfo(dimIdx, -1) : null;
  75795. var coord = ctx.point[dimIdx] = point[dimIdx]; // Transfer the oridinal coord.
  75796. if (!body0Unit && !cornerMinus1Unit) {
  75797. ctx[XY$1[dimIdx]] = CtxPointToDataAreaType.outside;
  75798. return;
  75799. }
  75800. if (clamp === MatrixClampOption.body) {
  75801. if (body0Unit) {
  75802. ctx[XY$1[dimIdx]] = CtxPointToDataAreaType.inBody;
  75803. coord = mathMin$1(bodyMaxUnit.xy + bodyMaxUnit.wh, mathMax$1(body0Unit.xy, coord));
  75804. ctx.point[dimIdx] = coord;
  75805. } else {
  75806. // If clamp to body, the result must not be in header.
  75807. ctx[XY$1[dimIdx]] = CtxPointToDataAreaType.outside;
  75808. }
  75809. return;
  75810. } else if (clamp === MatrixClampOption.corner) {
  75811. if (cornerMinus1Unit) {
  75812. ctx[XY$1[dimIdx]] = CtxPointToDataAreaType.inCorner;
  75813. coord = mathMin$1(cornerMinus1Unit.xy + cornerMinus1Unit.wh, mathMax$1(cornerMinUnit.xy, coord));
  75814. ctx.point[dimIdx] = coord;
  75815. } else {
  75816. // If clamp to corner, the result must not be in body.
  75817. ctx[XY$1[dimIdx]] = CtxPointToDataAreaType.outside;
  75818. }
  75819. return;
  75820. }
  75821. var pxLoc0 = body0Unit ? body0Unit.xy : cornerMinus1Unit ? cornerMinus1Unit.xy + cornerMinus1Unit.wh : NaN;
  75822. var pxMin = cornerMinUnit ? cornerMinUnit.xy : pxLoc0;
  75823. var pxMax = bodyMaxUnit ? bodyMaxUnit.xy + bodyMaxUnit.wh : pxLoc0;
  75824. if (coord < pxMin) {
  75825. if (!clamp) {
  75826. // Quick pass for later calc, since mouse event on any place will enter this method if use `pointToData`.
  75827. ctx[XY$1[dimIdx]] = CtxPointToDataAreaType.outside;
  75828. return;
  75829. }
  75830. coord = pxMin;
  75831. } else if (coord > pxMax) {
  75832. if (!clamp) {
  75833. ctx[XY$1[dimIdx]] = CtxPointToDataAreaType.outside;
  75834. return;
  75835. }
  75836. coord = pxMax;
  75837. }
  75838. ctx.point[dimIdx] = coord; // Save the updated coord.
  75839. ctx[XY$1[dimIdx]] = pxLoc0 <= coord && coord <= pxMax ? CtxPointToDataAreaType.inBody : pxMin <= coord && coord <= pxLoc0 ? CtxPointToDataAreaType.inCorner : CtxPointToDataAreaType.outside;
  75840. // Every props in ctx must be set in every branch of this method.
  75841. }
  75842. // Assume partialOut has been set to NaN outside.
  75843. // This method may fill out[0] and out[1] in one call.
  75844. function pointToDataOnlyHeaderFillOut(ctx, partialOut, dimIdx, dims) {
  75845. var otherDimIdx = 1 - dimIdx;
  75846. if (ctx[XY$1[dimIdx]] === CtxPointToDataAreaType.outside) {
  75847. return;
  75848. }
  75849. for (dims[XY$1[dimIdx]].resetCellIterator(_ptdDimCellIt); _ptdDimCellIt.next();) {
  75850. var cell = _ptdDimCellIt.item;
  75851. if (isCoordInRect(ctx.point[dimIdx], cell.rect, dimIdx) && isCoordInRect(ctx.point[otherDimIdx], cell.rect, otherDimIdx)) {
  75852. // non-leaves are also allowed to be located.
  75853. // If the point is in x or y dimension cell area, should check both x and y coord to
  75854. // determine a cell; in this way a non-leaf cell can be determined.
  75855. partialOut[dimIdx] = cell.ordinal;
  75856. partialOut[otherDimIdx] = cell.id[XY$1[otherDimIdx]];
  75857. return;
  75858. }
  75859. }
  75860. }
  75861. // Assume partialOut has been set to NaN outside.
  75862. // This method may fill out[0] and out[1] in one call.
  75863. function pointToDataBodyCornerFillOut(ctx, partialOut, dimIdx, dims) {
  75864. if (ctx[XY$1[dimIdx]] === CtxPointToDataAreaType.outside) {
  75865. return;
  75866. }
  75867. var dim = ctx[XY$1[dimIdx]] === CtxPointToDataAreaType.inCorner ? dims[XY$1[1 - dimIdx]] : dims[XY$1[dimIdx]];
  75868. for (dim.resetLayoutIterator(_ptdLevelIt, dimIdx); _ptdLevelIt.next();) {
  75869. if (isCoordInLayoutInfo(ctx.point[dimIdx], _ptdLevelIt.item)) {
  75870. partialOut[dimIdx] = _ptdLevelIt.item.id[XY$1[dimIdx]];
  75871. return;
  75872. }
  75873. }
  75874. }
  75875. function isCoordInLayoutInfo(coord, cell) {
  75876. return cell.xy <= coord && coord <= cell.xy + cell.wh;
  75877. }
  75878. function isCoordInRect(coord, rect, dimIdx) {
  75879. return rect[XY$1[dimIdx]] <= coord && coord <= rect[XY$1[dimIdx]] + rect[WH$1[dimIdx]];
  75880. }
  75881. function install$y(registers) {
  75882. registers.registerComponentModel(MatrixModel);
  75883. registers.registerComponentView(MatrixView);
  75884. registers.registerCoordinateSystem('matrix', Matrix);
  75885. }
  75886. function setKeyInfoToNewElOption(resultItem, newElOption) {
  75887. var existElOption = resultItem.existing;
  75888. // Set id and type after id assigned.
  75889. newElOption.id = resultItem.keyInfo.id;
  75890. !newElOption.type && existElOption && (newElOption.type = existElOption.type);
  75891. // Set parent id if not specified
  75892. if (newElOption.parentId == null) {
  75893. var newElParentOption = newElOption.parentOption;
  75894. if (newElParentOption) {
  75895. newElOption.parentId = newElParentOption.id;
  75896. } else if (existElOption) {
  75897. newElOption.parentId = existElOption.parentId;
  75898. }
  75899. }
  75900. // Clear
  75901. newElOption.parentOption = null;
  75902. }
  75903. function isSetLoc(obj, props) {
  75904. var isSet;
  75905. each(props, function (prop) {
  75906. obj[prop] != null && obj[prop] !== 'auto' && (isSet = true);
  75907. });
  75908. return isSet;
  75909. }
  75910. function mergeNewElOptionToExist(existList, index, newElOption) {
  75911. // Update existing options, for `getOption` feature.
  75912. var newElOptCopy = extend({}, newElOption);
  75913. var existElOption = existList[index];
  75914. var $action = newElOption.$action || 'merge';
  75915. if ($action === 'merge') {
  75916. if (existElOption) {
  75917. if ("development" !== 'production') {
  75918. var newType = newElOption.type;
  75919. assert(!newType || existElOption.type === newType, 'Please set $action: "replace" to change `type`');
  75920. }
  75921. // We can ensure that newElOptCopy and existElOption are not
  75922. // the same object, so `merge` will not change newElOptCopy.
  75923. merge(existElOption, newElOptCopy, true);
  75924. // Rigid body, use ignoreSize.
  75925. mergeLayoutParam(existElOption, newElOptCopy, {
  75926. ignoreSize: true
  75927. });
  75928. // Will be used in render.
  75929. copyLayoutParams(newElOption, existElOption);
  75930. // Copy transition info to new option so it can be used in the transition.
  75931. // DO IT AFTER merge
  75932. copyTransitionInfo(newElOption, existElOption);
  75933. copyTransitionInfo(newElOption, existElOption, 'shape');
  75934. copyTransitionInfo(newElOption, existElOption, 'style');
  75935. copyTransitionInfo(newElOption, existElOption, 'extra');
  75936. // Copy clipPath
  75937. newElOption.clipPath = existElOption.clipPath;
  75938. } else {
  75939. existList[index] = newElOptCopy;
  75940. }
  75941. } else if ($action === 'replace') {
  75942. existList[index] = newElOptCopy;
  75943. } else if ($action === 'remove') {
  75944. // null will be cleaned later.
  75945. existElOption && (existList[index] = null);
  75946. }
  75947. }
  75948. var TRANSITION_PROPS_TO_COPY = ['transition', 'enterFrom', 'leaveTo'];
  75949. var ROOT_TRANSITION_PROPS_TO_COPY = TRANSITION_PROPS_TO_COPY.concat(['enterAnimation', 'updateAnimation', 'leaveAnimation']);
  75950. function copyTransitionInfo(target, source, targetProp) {
  75951. if (targetProp) {
  75952. if (!target[targetProp] && source[targetProp]) {
  75953. // TODO avoid creating this empty object when there is no transition configuration.
  75954. target[targetProp] = {};
  75955. }
  75956. target = target[targetProp];
  75957. source = source[targetProp];
  75958. }
  75959. if (!target || !source) {
  75960. return;
  75961. }
  75962. var props = targetProp ? TRANSITION_PROPS_TO_COPY : ROOT_TRANSITION_PROPS_TO_COPY;
  75963. for (var i = 0; i < props.length; i++) {
  75964. var prop = props[i];
  75965. if (target[prop] == null && source[prop] != null) {
  75966. target[prop] = source[prop];
  75967. }
  75968. }
  75969. }
  75970. function setLayoutInfoToExist(existItem, newElOption) {
  75971. if (!existItem) {
  75972. return;
  75973. }
  75974. existItem.hv = newElOption.hv = [
  75975. // Rigid body, don't care about `width`.
  75976. isSetLoc(newElOption, ['left', 'right']),
  75977. // Rigid body, don't care about `height`.
  75978. isSetLoc(newElOption, ['top', 'bottom'])];
  75979. // Give default group size. Otherwise layout error may occur.
  75980. if (existItem.type === 'group') {
  75981. var existingGroupOpt = existItem;
  75982. var newGroupOpt = newElOption;
  75983. existingGroupOpt.width == null && (existingGroupOpt.width = newGroupOpt.width = 0);
  75984. existingGroupOpt.height == null && (existingGroupOpt.height = newGroupOpt.height = 0);
  75985. }
  75986. }
  75987. var GraphicComponentModel = /** @class */function (_super) {
  75988. __extends(GraphicComponentModel, _super);
  75989. function GraphicComponentModel() {
  75990. var _this = _super !== null && _super.apply(this, arguments) || this;
  75991. _this.type = GraphicComponentModel.type;
  75992. _this.preventAutoZ = true;
  75993. return _this;
  75994. }
  75995. GraphicComponentModel.prototype.mergeOption = function (option, ecModel) {
  75996. // Prevent default merge to elements
  75997. var elements = this.option.elements;
  75998. this.option.elements = null;
  75999. _super.prototype.mergeOption.call(this, option, ecModel);
  76000. this.option.elements = elements;
  76001. };
  76002. GraphicComponentModel.prototype.optionUpdated = function (newOption, isInit) {
  76003. var thisOption = this.option;
  76004. var newList = (isInit ? thisOption : newOption).elements;
  76005. var existList = thisOption.elements = isInit ? [] : thisOption.elements;
  76006. var flattenedList = [];
  76007. this._flatten(newList, flattenedList, null);
  76008. var mappingResult = mappingToExists(existList, flattenedList, 'normalMerge');
  76009. // Clear elOptionsToUpdate
  76010. var elOptionsToUpdate = this._elOptionsToUpdate = [];
  76011. each(mappingResult, function (resultItem, index) {
  76012. var newElOption = resultItem.newOption;
  76013. if ("development" !== 'production') {
  76014. assert(isObject(newElOption) || resultItem.existing, 'Empty graphic option definition');
  76015. }
  76016. if (!newElOption) {
  76017. return;
  76018. }
  76019. elOptionsToUpdate.push(newElOption);
  76020. setKeyInfoToNewElOption(resultItem, newElOption);
  76021. mergeNewElOptionToExist(existList, index, newElOption);
  76022. setLayoutInfoToExist(existList[index], newElOption);
  76023. }, this);
  76024. // Clean
  76025. thisOption.elements = filter(existList, function (item) {
  76026. // $action should be volatile, otherwise option gotten from
  76027. // `getOption` will contain unexpected $action.
  76028. item && delete item.$action;
  76029. return item != null;
  76030. });
  76031. };
  76032. /**
  76033. * Convert
  76034. * [{
  76035. * type: 'group',
  76036. * id: 'xx',
  76037. * children: [{type: 'circle'}, {type: 'polygon'}]
  76038. * }]
  76039. * to
  76040. * [
  76041. * {type: 'group', id: 'xx'},
  76042. * {type: 'circle', parentId: 'xx'},
  76043. * {type: 'polygon', parentId: 'xx'}
  76044. * ]
  76045. */
  76046. GraphicComponentModel.prototype._flatten = function (optionList, result, parentOption) {
  76047. each(optionList, function (option) {
  76048. if (!option) {
  76049. return;
  76050. }
  76051. if (parentOption) {
  76052. option.parentOption = parentOption;
  76053. }
  76054. result.push(option);
  76055. var children = option.children;
  76056. // here we don't judge if option.type is `group`
  76057. // when new option doesn't provide `type`, it will cause that the children can't be updated.
  76058. if (children && children.length) {
  76059. this._flatten(children, result, option);
  76060. }
  76061. // Deleting for JSON output, and for not affecting group creation.
  76062. delete option.children;
  76063. }, this);
  76064. };
  76065. // FIXME
  76066. // Pass to view using payload? setOption has a payload?
  76067. GraphicComponentModel.prototype.useElOptionsToUpdate = function () {
  76068. var els = this._elOptionsToUpdate;
  76069. // Clear to avoid render duplicately when zooming.
  76070. this._elOptionsToUpdate = null;
  76071. return els;
  76072. };
  76073. GraphicComponentModel.type = 'graphic';
  76074. GraphicComponentModel.defaultOption = {
  76075. elements: []
  76076. // parentId: null
  76077. };
  76078. return GraphicComponentModel;
  76079. }(ComponentModel);
  76080. var nonShapeGraphicElements = {
  76081. // Reserved but not supported in graphic component.
  76082. path: null,
  76083. compoundPath: null,
  76084. // Supported in graphic component.
  76085. group: Group,
  76086. image: ZRImage,
  76087. text: ZRText
  76088. };
  76089. var inner$g = makeInner();
  76090. // ------------------------
  76091. // View
  76092. // ------------------------
  76093. var GraphicComponentView = /** @class */function (_super) {
  76094. __extends(GraphicComponentView, _super);
  76095. function GraphicComponentView() {
  76096. var _this = _super !== null && _super.apply(this, arguments) || this;
  76097. _this.type = GraphicComponentView.type;
  76098. return _this;
  76099. }
  76100. GraphicComponentView.prototype.init = function () {
  76101. this._elMap = createHashMap();
  76102. };
  76103. GraphicComponentView.prototype.render = function (graphicModel, ecModel, api) {
  76104. // Having leveraged between use cases and algorithm complexity, a very
  76105. // simple layout mechanism is used:
  76106. // The size(width/height) can be determined by itself or its parent (not
  76107. // implemented yet), but can not by its children. (Top-down travel)
  76108. // The location(x/y) can be determined by the bounding rect of itself
  76109. // (can including its descendants or not) and the size of its parent.
  76110. // (Bottom-up travel)
  76111. // When `chart.clear()` or `chart.setOption({...}, true)` with the same id,
  76112. // view will be reused.
  76113. if (graphicModel !== this._lastGraphicModel) {
  76114. this._clear();
  76115. }
  76116. this._lastGraphicModel = graphicModel;
  76117. this._updateElements(graphicModel);
  76118. this._relocate(graphicModel, api);
  76119. };
  76120. /**
  76121. * Update graphic elements.
  76122. */
  76123. GraphicComponentView.prototype._updateElements = function (graphicModel) {
  76124. var elOptionsToUpdate = graphicModel.useElOptionsToUpdate();
  76125. if (!elOptionsToUpdate) {
  76126. return;
  76127. }
  76128. var elMap = this._elMap;
  76129. var rootGroup = this.group;
  76130. var globalZ = graphicModel.get('z');
  76131. var globalZLevel = graphicModel.get('zlevel');
  76132. // Top-down tranverse to assign graphic settings to each elements.
  76133. each(elOptionsToUpdate, function (elOption) {
  76134. var id = convertOptionIdName(elOption.id, null);
  76135. var elExisting = id != null ? elMap.get(id) : null;
  76136. var parentId = convertOptionIdName(elOption.parentId, null);
  76137. var targetElParent = parentId != null ? elMap.get(parentId) : rootGroup;
  76138. var elType = elOption.type;
  76139. var elOptionStyle = elOption.style;
  76140. if (elType === 'text' && elOptionStyle) {
  76141. // In top/bottom mode, textVerticalAlign should not be used, which cause
  76142. // inaccurately locating.
  76143. if (elOption.hv && elOption.hv[1]) {
  76144. elOptionStyle.textVerticalAlign = elOptionStyle.textBaseline = elOptionStyle.verticalAlign = elOptionStyle.align = null;
  76145. }
  76146. }
  76147. var textContentOption = elOption.textContent;
  76148. var textConfig = elOption.textConfig;
  76149. if (elOptionStyle && isEC4CompatibleStyle(elOptionStyle, elType, !!textConfig, !!textContentOption)) {
  76150. var convertResult = convertFromEC4CompatibleStyle(elOptionStyle, elType, true);
  76151. if (!textConfig && convertResult.textConfig) {
  76152. textConfig = elOption.textConfig = convertResult.textConfig;
  76153. }
  76154. if (!textContentOption && convertResult.textContent) {
  76155. textContentOption = convertResult.textContent;
  76156. }
  76157. }
  76158. // Remove unnecessary props to avoid potential problems.
  76159. var elOptionCleaned = getCleanedElOption(elOption);
  76160. // For simple, do not support parent change, otherwise reorder is needed.
  76161. if ("development" !== 'production') {
  76162. elExisting && assert(targetElParent === elExisting.parent, 'Changing parent is not supported.');
  76163. }
  76164. var $action = elOption.$action || 'merge';
  76165. var isMerge = $action === 'merge';
  76166. var isReplace = $action === 'replace';
  76167. if (isMerge) {
  76168. var isInit = !elExisting;
  76169. var el_1 = elExisting;
  76170. if (isInit) {
  76171. el_1 = createEl$1(id, targetElParent, elOption.type, elMap);
  76172. } else {
  76173. el_1 && (inner$g(el_1).isNew = false);
  76174. // Stop and restore before update any other attributes.
  76175. stopPreviousKeyframeAnimationAndRestore(el_1);
  76176. }
  76177. if (el_1) {
  76178. applyUpdateTransition(el_1, elOptionCleaned, graphicModel, {
  76179. isInit: isInit
  76180. });
  76181. updateCommonAttrs(el_1, elOption, globalZ, globalZLevel);
  76182. }
  76183. } else if (isReplace) {
  76184. removeEl(elExisting, elOption, elMap, graphicModel);
  76185. var el_2 = createEl$1(id, targetElParent, elOption.type, elMap);
  76186. if (el_2) {
  76187. applyUpdateTransition(el_2, elOptionCleaned, graphicModel, {
  76188. isInit: true
  76189. });
  76190. updateCommonAttrs(el_2, elOption, globalZ, globalZLevel);
  76191. }
  76192. } else if ($action === 'remove') {
  76193. updateLeaveTo(elExisting, elOption);
  76194. removeEl(elExisting, elOption, elMap, graphicModel);
  76195. }
  76196. var el = elMap.get(id);
  76197. if (el && textContentOption) {
  76198. if (isMerge) {
  76199. var textContentExisting = el.getTextContent();
  76200. textContentExisting ? textContentExisting.attr(textContentOption) : el.setTextContent(new ZRText(textContentOption));
  76201. } else if (isReplace) {
  76202. el.setTextContent(new ZRText(textContentOption));
  76203. }
  76204. }
  76205. if (el) {
  76206. var clipPathOption = elOption.clipPath;
  76207. if (clipPathOption) {
  76208. var clipPathType = clipPathOption.type;
  76209. var clipPath = void 0;
  76210. var isInit = false;
  76211. if (isMerge) {
  76212. var oldClipPath = el.getClipPath();
  76213. isInit = !oldClipPath || inner$g(oldClipPath).type !== clipPathType;
  76214. clipPath = isInit ? newEl(clipPathType) : oldClipPath;
  76215. } else if (isReplace) {
  76216. isInit = true;
  76217. clipPath = newEl(clipPathType);
  76218. }
  76219. el.setClipPath(clipPath);
  76220. applyUpdateTransition(clipPath, clipPathOption, graphicModel, {
  76221. isInit: isInit
  76222. });
  76223. applyKeyframeAnimation(clipPath, clipPathOption.keyframeAnimation, graphicModel);
  76224. }
  76225. var elInner = inner$g(el);
  76226. el.setTextConfig(textConfig);
  76227. elInner.option = elOption;
  76228. setEventData(el, graphicModel, elOption);
  76229. setTooltipConfig({
  76230. el: el,
  76231. componentModel: graphicModel,
  76232. itemName: el.name,
  76233. itemTooltipOption: elOption.tooltip
  76234. });
  76235. applyKeyframeAnimation(el, elOption.keyframeAnimation, graphicModel);
  76236. }
  76237. });
  76238. };
  76239. /**
  76240. * Locate graphic elements.
  76241. */
  76242. GraphicComponentView.prototype._relocate = function (graphicModel, api) {
  76243. var elOptions = graphicModel.option.elements;
  76244. var rootGroup = this.group;
  76245. var elMap = this._elMap;
  76246. var apiWidth = api.getWidth();
  76247. var apiHeight = api.getHeight();
  76248. var xy = ['x', 'y'];
  76249. // Top-down to calculate percentage width/height of group
  76250. for (var i = 0; i < elOptions.length; i++) {
  76251. var elOption = elOptions[i];
  76252. var id = convertOptionIdName(elOption.id, null);
  76253. var el = id != null ? elMap.get(id) : null;
  76254. if (!el || !el.isGroup) {
  76255. continue;
  76256. }
  76257. var parentEl = el.parent;
  76258. var isParentRoot = parentEl === rootGroup;
  76259. // Like 'position:absolut' in css, default 0.
  76260. var elInner = inner$g(el);
  76261. var parentElInner = inner$g(parentEl);
  76262. elInner.width = parsePercent$1(elInner.option.width, isParentRoot ? apiWidth : parentElInner.width) || 0;
  76263. elInner.height = parsePercent$1(elInner.option.height, isParentRoot ? apiHeight : parentElInner.height) || 0;
  76264. }
  76265. // Bottom-up tranvese all elements (consider ec resize) to locate elements.
  76266. for (var i = elOptions.length - 1; i >= 0; i--) {
  76267. var elOption = elOptions[i];
  76268. var id = convertOptionIdName(elOption.id, null);
  76269. var el = id != null ? elMap.get(id) : null;
  76270. if (!el) {
  76271. continue;
  76272. }
  76273. var parentEl = el.parent;
  76274. var parentElInner = inner$g(parentEl);
  76275. var containerInfo = parentEl === rootGroup ? {
  76276. width: apiWidth,
  76277. height: apiHeight
  76278. } : {
  76279. width: parentElInner.width,
  76280. height: parentElInner.height
  76281. };
  76282. // PENDING
  76283. // Currently, when `bounding: 'all'`, the union bounding rect of the group
  76284. // does not include the rect of [0, 0, group.width, group.height], which
  76285. // is probably weird for users. Should we make a break change for it?
  76286. var layoutPos = {};
  76287. var layouted = positionElement(el, elOption, containerInfo, null, {
  76288. hv: elOption.hv,
  76289. boundingMode: elOption.bounding
  76290. }, layoutPos);
  76291. if (!inner$g(el).isNew && layouted) {
  76292. var transition = elOption.transition;
  76293. var animatePos = {};
  76294. for (var k = 0; k < xy.length; k++) {
  76295. var key = xy[k];
  76296. var val = layoutPos[key];
  76297. if (transition && (isTransitionAll(transition) || indexOf(transition, key) >= 0)) {
  76298. animatePos[key] = val;
  76299. } else {
  76300. el[key] = val;
  76301. }
  76302. }
  76303. updateProps(el, animatePos, graphicModel, 0);
  76304. } else {
  76305. el.attr(layoutPos);
  76306. }
  76307. }
  76308. };
  76309. /**
  76310. * Clear all elements.
  76311. */
  76312. GraphicComponentView.prototype._clear = function () {
  76313. var _this = this;
  76314. var elMap = this._elMap;
  76315. elMap.each(function (el) {
  76316. removeEl(el, inner$g(el).option, elMap, _this._lastGraphicModel);
  76317. });
  76318. this._elMap = createHashMap();
  76319. };
  76320. GraphicComponentView.prototype.dispose = function () {
  76321. this._clear();
  76322. };
  76323. GraphicComponentView.type = 'graphic';
  76324. return GraphicComponentView;
  76325. }(ComponentView);
  76326. function newEl(graphicType) {
  76327. if ("development" !== 'production') {
  76328. assert(graphicType, 'graphic type MUST be set');
  76329. }
  76330. var Clz = hasOwn(nonShapeGraphicElements, graphicType)
  76331. // Those graphic elements are not shapes. They should not be
  76332. // overwritten by users, so do them first.
  76333. ? nonShapeGraphicElements[graphicType] : getShapeClass(graphicType);
  76334. if ("development" !== 'production') {
  76335. assert(Clz, "graphic type " + graphicType + " can not be found");
  76336. }
  76337. var el = new Clz({});
  76338. inner$g(el).type = graphicType;
  76339. return el;
  76340. }
  76341. function createEl$1(id, targetElParent, graphicType, elMap) {
  76342. var el = newEl(graphicType);
  76343. targetElParent.add(el);
  76344. elMap.set(id, el);
  76345. inner$g(el).id = id;
  76346. inner$g(el).isNew = true;
  76347. return el;
  76348. }
  76349. function removeEl(elExisting, elOption, elMap, graphicModel) {
  76350. var existElParent = elExisting && elExisting.parent;
  76351. if (existElParent) {
  76352. elExisting.type === 'group' && elExisting.traverse(function (el) {
  76353. removeEl(el, elOption, elMap, graphicModel);
  76354. });
  76355. applyLeaveTransition(elExisting, elOption, graphicModel);
  76356. elMap.removeKey(inner$g(elExisting).id);
  76357. }
  76358. }
  76359. function updateCommonAttrs(el, elOption, defaultZ, defaultZlevel) {
  76360. if (!el.isGroup) {
  76361. each([['cursor', Displayable.prototype.cursor],
  76362. // We should not support configure z and zlevel in the element level.
  76363. // But seems we didn't limit it previously. So here still use it to avoid breaking.
  76364. ['zlevel', defaultZlevel || 0], ['z', defaultZ || 0],
  76365. // z2 must not be null/undefined, otherwise sort error may occur.
  76366. ['z2', 0]], function (item) {
  76367. var prop = item[0];
  76368. if (hasOwn(elOption, prop)) {
  76369. el[prop] = retrieve2(elOption[prop], item[1]);
  76370. } else if (el[prop] == null) {
  76371. el[prop] = item[1];
  76372. }
  76373. });
  76374. }
  76375. each(keys(elOption), function (key) {
  76376. // Assign event handlers.
  76377. // PENDING: should enumerate all event names or use pattern matching?
  76378. if (key.indexOf('on') === 0) {
  76379. var val = elOption[key];
  76380. el[key] = isFunction(val) ? val : null;
  76381. }
  76382. });
  76383. if (hasOwn(elOption, 'draggable')) {
  76384. el.draggable = elOption.draggable;
  76385. }
  76386. // Other attributes
  76387. elOption.name != null && (el.name = elOption.name);
  76388. elOption.id != null && (el.id = elOption.id);
  76389. }
  76390. // Remove unnecessary props to avoid potential problems.
  76391. function getCleanedElOption(elOption) {
  76392. elOption = extend({}, elOption);
  76393. each(['id', 'parentId', '$action', 'hv', 'bounding', 'textContent', 'clipPath'].concat(LOCATION_PARAMS), function (name) {
  76394. delete elOption[name];
  76395. });
  76396. return elOption;
  76397. }
  76398. function setEventData(el, graphicModel, elOption) {
  76399. var eventData = getECData(el).eventData;
  76400. // Simple optimize for large amount of elements that no need event.
  76401. if (!el.silent && !el.ignore && !eventData) {
  76402. eventData = getECData(el).eventData = {
  76403. componentType: 'graphic',
  76404. componentIndex: graphicModel.componentIndex,
  76405. name: el.name
  76406. };
  76407. }
  76408. // `elOption.info` enables user to mount some info on
  76409. // elements and use them in event handlers.
  76410. if (eventData) {
  76411. eventData.info = elOption.info;
  76412. }
  76413. }
  76414. function install$z(registers) {
  76415. registers.registerComponentModel(GraphicComponentModel);
  76416. registers.registerComponentView(GraphicComponentView);
  76417. registers.registerPreprocessor(function (option) {
  76418. var graphicOption = option.graphic;
  76419. // Convert
  76420. // {graphic: [{left: 10, type: 'circle'}, ...]}
  76421. // or
  76422. // {graphic: {left: 10, type: 'circle'}}
  76423. // to
  76424. // {graphic: [{elements: [{left: 10, type: 'circle'}, ...]}]}
  76425. if (isArray(graphicOption)) {
  76426. if (!graphicOption[0] || !graphicOption[0].elements) {
  76427. option.graphic = [{
  76428. elements: graphicOption
  76429. }];
  76430. } else {
  76431. // Only one graphic instance can be instantiated. (We don't
  76432. // want that too many views are created in echarts._viewMap.)
  76433. option.graphic = [option.graphic[0]];
  76434. }
  76435. } else if (graphicOption && !graphicOption.elements) {
  76436. option.graphic = [{
  76437. elements: [graphicOption]
  76438. }];
  76439. }
  76440. });
  76441. }
  76442. var DATA_ZOOM_AXIS_DIMENSIONS = ['x', 'y', 'radius', 'angle', 'single'];
  76443. // Supported coords.
  76444. // FIXME: polar has been broken (but rarely used).
  76445. var SERIES_COORDS = ['cartesian2d', 'polar', 'singleAxis'];
  76446. function isCoordSupported(seriesModel) {
  76447. var coordType = seriesModel.get('coordinateSystem');
  76448. return indexOf(SERIES_COORDS, coordType) >= 0;
  76449. }
  76450. function getAxisMainType(axisDim) {
  76451. if ("development" !== 'production') {
  76452. assert(axisDim);
  76453. }
  76454. return axisDim + 'Axis';
  76455. }
  76456. /**
  76457. * If two dataZoomModels has the same axis controlled, we say that they are 'linked'.
  76458. * This function finds all linked dataZoomModels start from the given payload.
  76459. */
  76460. function findEffectedDataZooms(ecModel, payload) {
  76461. // Key: `DataZoomAxisDimension`
  76462. var axisRecords = createHashMap();
  76463. var effectedModels = [];
  76464. // Key: uid of dataZoomModel
  76465. var effectedModelMap = createHashMap();
  76466. // Find the dataZooms specified by payload.
  76467. ecModel.eachComponent({
  76468. mainType: 'dataZoom',
  76469. query: payload
  76470. }, function (dataZoomModel) {
  76471. if (!effectedModelMap.get(dataZoomModel.uid)) {
  76472. addToEffected(dataZoomModel);
  76473. }
  76474. });
  76475. // Start from the given dataZoomModels, travel the graph to find
  76476. // all of the linked dataZoom models.
  76477. var foundNewLink;
  76478. do {
  76479. foundNewLink = false;
  76480. ecModel.eachComponent('dataZoom', processSingle);
  76481. } while (foundNewLink);
  76482. function processSingle(dataZoomModel) {
  76483. if (!effectedModelMap.get(dataZoomModel.uid) && isLinked(dataZoomModel)) {
  76484. addToEffected(dataZoomModel);
  76485. foundNewLink = true;
  76486. }
  76487. }
  76488. function addToEffected(dataZoom) {
  76489. effectedModelMap.set(dataZoom.uid, true);
  76490. effectedModels.push(dataZoom);
  76491. markAxisControlled(dataZoom);
  76492. }
  76493. function isLinked(dataZoomModel) {
  76494. var isLink = false;
  76495. dataZoomModel.eachTargetAxis(function (axisDim, axisIndex) {
  76496. var axisIdxArr = axisRecords.get(axisDim);
  76497. if (axisIdxArr && axisIdxArr[axisIndex]) {
  76498. isLink = true;
  76499. }
  76500. });
  76501. return isLink;
  76502. }
  76503. function markAxisControlled(dataZoomModel) {
  76504. dataZoomModel.eachTargetAxis(function (axisDim, axisIndex) {
  76505. (axisRecords.get(axisDim) || axisRecords.set(axisDim, []))[axisIndex] = true;
  76506. });
  76507. }
  76508. return effectedModels;
  76509. }
  76510. /**
  76511. * Find the first target coordinate system.
  76512. * Available after model built.
  76513. *
  76514. * @return Like {
  76515. * grid: [
  76516. * {model: coord0, axisModels: [axis1, axis3], coordIndex: 1},
  76517. * {model: coord1, axisModels: [axis0, axis2], coordIndex: 0},
  76518. * ...
  76519. * ], // cartesians must not be null/undefined.
  76520. * polar: [
  76521. * {model: coord0, axisModels: [axis4], coordIndex: 0},
  76522. * ...
  76523. * ], // polars must not be null/undefined.
  76524. * singleAxis: [
  76525. * {model: coord0, axisModels: [], coordIndex: 0}
  76526. * ]
  76527. * }
  76528. */
  76529. function collectReferCoordSysModelInfo(dataZoomModel) {
  76530. var ecModel = dataZoomModel.ecModel;
  76531. var coordSysInfoWrap = {
  76532. infoList: [],
  76533. infoMap: createHashMap()
  76534. };
  76535. dataZoomModel.eachTargetAxis(function (axisDim, axisIndex) {
  76536. var axisModel = ecModel.getComponent(getAxisMainType(axisDim), axisIndex);
  76537. if (!axisModel) {
  76538. return;
  76539. }
  76540. var coordSysModel = axisModel.getCoordSysModel();
  76541. if (!coordSysModel) {
  76542. return;
  76543. }
  76544. var coordSysUid = coordSysModel.uid;
  76545. var coordSysInfo = coordSysInfoWrap.infoMap.get(coordSysUid);
  76546. if (!coordSysInfo) {
  76547. coordSysInfo = {
  76548. model: coordSysModel,
  76549. axisModels: []
  76550. };
  76551. coordSysInfoWrap.infoList.push(coordSysInfo);
  76552. coordSysInfoWrap.infoMap.set(coordSysUid, coordSysInfo);
  76553. }
  76554. coordSysInfo.axisModels.push(axisModel);
  76555. });
  76556. return coordSysInfoWrap;
  76557. }
  76558. var DataZoomAxisInfo = /** @class */function () {
  76559. function DataZoomAxisInfo() {
  76560. this.indexList = [];
  76561. this.indexMap = [];
  76562. }
  76563. DataZoomAxisInfo.prototype.add = function (axisCmptIdx) {
  76564. // Remove duplication.
  76565. if (!this.indexMap[axisCmptIdx]) {
  76566. this.indexList.push(axisCmptIdx);
  76567. this.indexMap[axisCmptIdx] = true;
  76568. }
  76569. };
  76570. return DataZoomAxisInfo;
  76571. }();
  76572. var DataZoomModel = /** @class */function (_super) {
  76573. __extends(DataZoomModel, _super);
  76574. function DataZoomModel() {
  76575. var _this = _super !== null && _super.apply(this, arguments) || this;
  76576. _this.type = DataZoomModel.type;
  76577. _this._autoThrottle = true;
  76578. _this._noTarget = true;
  76579. /**
  76580. * It is `[rangeModeForMin, rangeModeForMax]`.
  76581. * The optional values for `rangeMode`:
  76582. * + `'value'` mode: the axis extent will always be determined by
  76583. * `dataZoom.startValue` and `dataZoom.endValue`, despite
  76584. * how data like and how `axis.min` and `axis.max` are.
  76585. * + `'percent'` mode: `100` represents 100% of the `[dMin, dMax]`,
  76586. * where `dMin` is `axis.min` if `axis.min` specified, otherwise `data.extent[0]`,
  76587. * and `dMax` is `axis.max` if `axis.max` specified, otherwise `data.extent[1]`.
  76588. * Axis extent will be determined by the result of the percent of `[dMin, dMax]`.
  76589. *
  76590. * For example, when users are using dynamic data (update data periodically via `setOption`),
  76591. * if in `'value`' mode, the window will be kept in a fixed value range despite how
  76592. * data are appended, while if in `'percent'` mode, whe window range will be changed alone with
  76593. * the appended data (suppose `axis.min` and `axis.max` are not specified).
  76594. */
  76595. _this._rangePropMode = ['percent', 'percent'];
  76596. return _this;
  76597. }
  76598. DataZoomModel.prototype.init = function (option, parentModel, ecModel) {
  76599. var inputRawOption = retrieveRawOption(option);
  76600. /**
  76601. * Suppose a "main process" start at the point that model prepared (that is,
  76602. * model initialized or merged or method called in `action`).
  76603. * We should keep the `main process` idempotent, that is, given a set of values
  76604. * on `option`, we get the same result.
  76605. *
  76606. * But sometimes, values on `option` will be updated for providing users
  76607. * a "final calculated value" (`dataZoomProcessor` will do that). Those value
  76608. * should not be the base/input of the `main process`.
  76609. *
  76610. * So in that case we should save and keep the input of the `main process`
  76611. * separately, called `settledOption`.
  76612. *
  76613. * For example, consider the case:
  76614. * (Step_1) brush zoom the grid by `toolbox.dataZoom`,
  76615. * where the original input `option.startValue`, `option.endValue` are earsed by
  76616. * calculated value.
  76617. * (Step)2) click the legend to hide and show a series,
  76618. * where the new range is calculated by the earsed `startValue` and `endValue`,
  76619. * which brings incorrect result.
  76620. */
  76621. this.settledOption = inputRawOption;
  76622. this.mergeDefaultAndTheme(option, ecModel);
  76623. this._doInit(inputRawOption);
  76624. };
  76625. DataZoomModel.prototype.mergeOption = function (newOption) {
  76626. var inputRawOption = retrieveRawOption(newOption);
  76627. // FIX #2591
  76628. merge(this.option, newOption, true);
  76629. merge(this.settledOption, inputRawOption, true);
  76630. this._doInit(inputRawOption);
  76631. };
  76632. DataZoomModel.prototype._doInit = function (inputRawOption) {
  76633. var thisOption = this.option;
  76634. this._setDefaultThrottle(inputRawOption);
  76635. this._updateRangeUse(inputRawOption);
  76636. var settledOption = this.settledOption;
  76637. each([['start', 'startValue'], ['end', 'endValue']], function (names, index) {
  76638. // start/end has higher priority over startValue/endValue if they
  76639. // both set, but we should make chart.setOption({endValue: 1000})
  76640. // effective, rather than chart.setOption({endValue: 1000, end: null}).
  76641. if (this._rangePropMode[index] === 'value') {
  76642. thisOption[names[0]] = settledOption[names[0]] = null;
  76643. }
  76644. // Otherwise do nothing and use the merge result.
  76645. }, this);
  76646. this._resetTarget();
  76647. };
  76648. DataZoomModel.prototype._resetTarget = function () {
  76649. var optionOrient = this.get('orient', true);
  76650. var targetAxisIndexMap = this._targetAxisInfoMap = createHashMap();
  76651. var hasAxisSpecified = this._fillSpecifiedTargetAxis(targetAxisIndexMap);
  76652. if (hasAxisSpecified) {
  76653. this._orient = optionOrient || this._makeAutoOrientByTargetAxis();
  76654. } else {
  76655. this._orient = optionOrient || 'horizontal';
  76656. this._fillAutoTargetAxisByOrient(targetAxisIndexMap, this._orient);
  76657. }
  76658. this._noTarget = true;
  76659. targetAxisIndexMap.each(function (axisInfo) {
  76660. if (axisInfo.indexList.length) {
  76661. this._noTarget = false;
  76662. }
  76663. }, this);
  76664. };
  76665. DataZoomModel.prototype._fillSpecifiedTargetAxis = function (targetAxisIndexMap) {
  76666. var hasAxisSpecified = false;
  76667. each(DATA_ZOOM_AXIS_DIMENSIONS, function (axisDim) {
  76668. var refering = this.getReferringComponents(getAxisMainType(axisDim), MULTIPLE_REFERRING);
  76669. // When user set axisIndex as a empty array, we think that user specify axisIndex
  76670. // but do not want use auto mode. Because empty array may be encountered when
  76671. // some error occurred.
  76672. if (!refering.specified) {
  76673. return;
  76674. }
  76675. hasAxisSpecified = true;
  76676. var axisInfo = new DataZoomAxisInfo();
  76677. each(refering.models, function (axisModel) {
  76678. axisInfo.add(axisModel.componentIndex);
  76679. });
  76680. targetAxisIndexMap.set(axisDim, axisInfo);
  76681. }, this);
  76682. return hasAxisSpecified;
  76683. };
  76684. DataZoomModel.prototype._fillAutoTargetAxisByOrient = function (targetAxisIndexMap, orient) {
  76685. var ecModel = this.ecModel;
  76686. var needAuto = true;
  76687. // Find axis that parallel to dataZoom as default.
  76688. if (needAuto) {
  76689. var axisDim = orient === 'vertical' ? 'y' : 'x';
  76690. var axisModels = ecModel.findComponents({
  76691. mainType: axisDim + 'Axis'
  76692. });
  76693. setParallelAxis(axisModels, axisDim);
  76694. }
  76695. // Find axis that parallel to dataZoom as default.
  76696. if (needAuto) {
  76697. var axisModels = ecModel.findComponents({
  76698. mainType: 'singleAxis',
  76699. filter: function (axisModel) {
  76700. return axisModel.get('orient', true) === orient;
  76701. }
  76702. });
  76703. setParallelAxis(axisModels, 'single');
  76704. }
  76705. function setParallelAxis(axisModels, axisDim) {
  76706. // At least use the first parallel axis as the target axis.
  76707. var axisModel = axisModels[0];
  76708. if (!axisModel) {
  76709. return;
  76710. }
  76711. var axisInfo = new DataZoomAxisInfo();
  76712. axisInfo.add(axisModel.componentIndex);
  76713. targetAxisIndexMap.set(axisDim, axisInfo);
  76714. needAuto = false;
  76715. // Find parallel axes in the same grid.
  76716. if (axisDim === 'x' || axisDim === 'y') {
  76717. var gridModel_1 = axisModel.getReferringComponents('grid', SINGLE_REFERRING).models[0];
  76718. gridModel_1 && each(axisModels, function (axModel) {
  76719. if (axisModel.componentIndex !== axModel.componentIndex && gridModel_1 === axModel.getReferringComponents('grid', SINGLE_REFERRING).models[0]) {
  76720. axisInfo.add(axModel.componentIndex);
  76721. }
  76722. });
  76723. }
  76724. }
  76725. if (needAuto) {
  76726. // If no parallel axis, find the first category axis as default. (Also consider polar).
  76727. each(DATA_ZOOM_AXIS_DIMENSIONS, function (axisDim) {
  76728. if (!needAuto) {
  76729. return;
  76730. }
  76731. var axisModels = ecModel.findComponents({
  76732. mainType: getAxisMainType(axisDim),
  76733. filter: function (axisModel) {
  76734. return axisModel.get('type', true) === 'category';
  76735. }
  76736. });
  76737. if (axisModels[0]) {
  76738. var axisInfo = new DataZoomAxisInfo();
  76739. axisInfo.add(axisModels[0].componentIndex);
  76740. targetAxisIndexMap.set(axisDim, axisInfo);
  76741. needAuto = false;
  76742. }
  76743. }, this);
  76744. }
  76745. };
  76746. DataZoomModel.prototype._makeAutoOrientByTargetAxis = function () {
  76747. var dim;
  76748. // Find the first axis
  76749. this.eachTargetAxis(function (axisDim) {
  76750. !dim && (dim = axisDim);
  76751. }, this);
  76752. return dim === 'y' ? 'vertical' : 'horizontal';
  76753. };
  76754. DataZoomModel.prototype._setDefaultThrottle = function (inputRawOption) {
  76755. // When first time user set throttle, auto throttle ends.
  76756. if (inputRawOption.hasOwnProperty('throttle')) {
  76757. this._autoThrottle = false;
  76758. }
  76759. if (this._autoThrottle) {
  76760. var globalOption = this.ecModel.option;
  76761. this.option.throttle = globalOption.animation && globalOption.animationDurationUpdate > 0 ? 100 : 20;
  76762. }
  76763. };
  76764. DataZoomModel.prototype._updateRangeUse = function (inputRawOption) {
  76765. var rangePropMode = this._rangePropMode;
  76766. var rangeModeInOption = this.get('rangeMode');
  76767. each([['start', 'startValue'], ['end', 'endValue']], function (names, index) {
  76768. var percentSpecified = inputRawOption[names[0]] != null;
  76769. var valueSpecified = inputRawOption[names[1]] != null;
  76770. if (percentSpecified && !valueSpecified) {
  76771. rangePropMode[index] = 'percent';
  76772. } else if (!percentSpecified && valueSpecified) {
  76773. rangePropMode[index] = 'value';
  76774. } else if (rangeModeInOption) {
  76775. rangePropMode[index] = rangeModeInOption[index];
  76776. } else if (percentSpecified) {
  76777. // percentSpecified && valueSpecified
  76778. rangePropMode[index] = 'percent';
  76779. }
  76780. // else remain its original setting.
  76781. });
  76782. };
  76783. DataZoomModel.prototype.noTarget = function () {
  76784. return this._noTarget;
  76785. };
  76786. DataZoomModel.prototype.getFirstTargetAxisModel = function () {
  76787. var firstAxisModel;
  76788. this.eachTargetAxis(function (axisDim, axisIndex) {
  76789. if (firstAxisModel == null) {
  76790. firstAxisModel = this.ecModel.getComponent(getAxisMainType(axisDim), axisIndex);
  76791. }
  76792. }, this);
  76793. return firstAxisModel;
  76794. };
  76795. /**
  76796. * @param {Function} callback param: axisModel, dimNames, axisIndex, dataZoomModel, ecModel
  76797. */
  76798. DataZoomModel.prototype.eachTargetAxis = function (callback, context) {
  76799. this._targetAxisInfoMap.each(function (axisInfo, axisDim) {
  76800. each(axisInfo.indexList, function (axisIndex) {
  76801. callback.call(context, axisDim, axisIndex);
  76802. });
  76803. });
  76804. };
  76805. /**
  76806. * @return If not found, return null/undefined.
  76807. */
  76808. DataZoomModel.prototype.getAxisProxy = function (axisDim, axisIndex) {
  76809. var axisModel = this.getAxisModel(axisDim, axisIndex);
  76810. if (axisModel) {
  76811. return axisModel.__dzAxisProxy;
  76812. }
  76813. };
  76814. /**
  76815. * @return If not found, return null/undefined.
  76816. */
  76817. DataZoomModel.prototype.getAxisModel = function (axisDim, axisIndex) {
  76818. if ("development" !== 'production') {
  76819. assert(axisDim && axisIndex != null);
  76820. }
  76821. var axisInfo = this._targetAxisInfoMap.get(axisDim);
  76822. if (axisInfo && axisInfo.indexMap[axisIndex]) {
  76823. return this.ecModel.getComponent(getAxisMainType(axisDim), axisIndex);
  76824. }
  76825. };
  76826. /**
  76827. * If not specified, set to undefined.
  76828. */
  76829. DataZoomModel.prototype.setRawRange = function (opt) {
  76830. var thisOption = this.option;
  76831. var settledOption = this.settledOption;
  76832. each([['start', 'startValue'], ['end', 'endValue']], function (names) {
  76833. // Consider the pair <start, startValue>:
  76834. // If one has value and the other one is `null/undefined`, we both set them
  76835. // to `settledOption`. This strategy enables the feature to clear the original
  76836. // value in `settledOption` to `null/undefined`.
  76837. // But if both of them are `null/undefined`, we do not set them to `settledOption`
  76838. // and keep `settledOption` with the original value. This strategy enables users to
  76839. // only set <end or endValue> but not set <start or startValue> when calling
  76840. // `dispatchAction`.
  76841. // The pair <end, endValue> is treated in the same way.
  76842. if (opt[names[0]] != null || opt[names[1]] != null) {
  76843. thisOption[names[0]] = settledOption[names[0]] = opt[names[0]];
  76844. thisOption[names[1]] = settledOption[names[1]] = opt[names[1]];
  76845. }
  76846. }, this);
  76847. this._updateRangeUse(opt);
  76848. };
  76849. DataZoomModel.prototype.setCalculatedRange = function (opt) {
  76850. var option = this.option;
  76851. each(['start', 'startValue', 'end', 'endValue'], function (name) {
  76852. option[name] = opt[name];
  76853. });
  76854. };
  76855. DataZoomModel.prototype.getPercentRange = function () {
  76856. var axisProxy = this.findRepresentativeAxisProxy();
  76857. if (axisProxy) {
  76858. return axisProxy.getDataPercentWindow();
  76859. }
  76860. };
  76861. /**
  76862. * For example, chart.getModel().getComponent('dataZoom').getValueRange('y', 0);
  76863. *
  76864. * @return [startValue, endValue] value can only be '-' or finite number.
  76865. */
  76866. DataZoomModel.prototype.getValueRange = function (axisDim, axisIndex) {
  76867. if (axisDim == null && axisIndex == null) {
  76868. var axisProxy = this.findRepresentativeAxisProxy();
  76869. if (axisProxy) {
  76870. return axisProxy.getDataValueWindow();
  76871. }
  76872. } else {
  76873. return this.getAxisProxy(axisDim, axisIndex).getDataValueWindow();
  76874. }
  76875. };
  76876. /**
  76877. * @param axisModel If axisModel given, find axisProxy
  76878. * corresponding to the axisModel
  76879. */
  76880. DataZoomModel.prototype.findRepresentativeAxisProxy = function (axisModel) {
  76881. if (axisModel) {
  76882. return axisModel.__dzAxisProxy;
  76883. }
  76884. // Find the first hosted axisProxy
  76885. var firstProxy;
  76886. var axisDimList = this._targetAxisInfoMap.keys();
  76887. for (var i = 0; i < axisDimList.length; i++) {
  76888. var axisDim = axisDimList[i];
  76889. var axisInfo = this._targetAxisInfoMap.get(axisDim);
  76890. for (var j = 0; j < axisInfo.indexList.length; j++) {
  76891. var proxy = this.getAxisProxy(axisDim, axisInfo.indexList[j]);
  76892. if (proxy.hostedBy(this)) {
  76893. return proxy;
  76894. }
  76895. if (!firstProxy) {
  76896. firstProxy = proxy;
  76897. }
  76898. }
  76899. }
  76900. // If no hosted proxy found, still need to return a proxy.
  76901. // This case always happens in toolbox dataZoom, where axes are all hosted by
  76902. // other dataZooms.
  76903. return firstProxy;
  76904. };
  76905. DataZoomModel.prototype.getRangePropMode = function () {
  76906. return this._rangePropMode.slice();
  76907. };
  76908. DataZoomModel.prototype.getOrient = function () {
  76909. if ("development" !== 'production') {
  76910. // Should not be called before initialized.
  76911. assert(this._orient);
  76912. }
  76913. return this._orient;
  76914. };
  76915. DataZoomModel.type = 'dataZoom';
  76916. DataZoomModel.dependencies = ['xAxis', 'yAxis', 'radiusAxis', 'angleAxis', 'singleAxis', 'series', 'toolbox'];
  76917. DataZoomModel.defaultOption = {
  76918. // zlevel: 0,
  76919. z: 4,
  76920. filterMode: 'filter',
  76921. start: 0,
  76922. end: 100
  76923. };
  76924. return DataZoomModel;
  76925. }(ComponentModel);
  76926. /**
  76927. * Retrieve those raw params from option, which will be cached separately,
  76928. * because they will be overwritten by normalized/calculated values in the main
  76929. * process.
  76930. */
  76931. function retrieveRawOption(option) {
  76932. var ret = {};
  76933. each(['start', 'end', 'startValue', 'endValue', 'throttle'], function (name) {
  76934. option.hasOwnProperty(name) && (ret[name] = option[name]);
  76935. });
  76936. return ret;
  76937. }
  76938. var SelectDataZoomModel = /** @class */function (_super) {
  76939. __extends(SelectDataZoomModel, _super);
  76940. function SelectDataZoomModel() {
  76941. var _this = _super !== null && _super.apply(this, arguments) || this;
  76942. _this.type = SelectDataZoomModel.type;
  76943. return _this;
  76944. }
  76945. SelectDataZoomModel.type = 'dataZoom.select';
  76946. return SelectDataZoomModel;
  76947. }(DataZoomModel);
  76948. var DataZoomView = /** @class */function (_super) {
  76949. __extends(DataZoomView, _super);
  76950. function DataZoomView() {
  76951. var _this = _super !== null && _super.apply(this, arguments) || this;
  76952. _this.type = DataZoomView.type;
  76953. return _this;
  76954. }
  76955. DataZoomView.prototype.render = function (dataZoomModel, ecModel, api, payload) {
  76956. this.dataZoomModel = dataZoomModel;
  76957. this.ecModel = ecModel;
  76958. this.api = api;
  76959. };
  76960. DataZoomView.type = 'dataZoom';
  76961. return DataZoomView;
  76962. }(ComponentView);
  76963. var SelectDataZoomView = /** @class */function (_super) {
  76964. __extends(SelectDataZoomView, _super);
  76965. function SelectDataZoomView() {
  76966. var _this = _super !== null && _super.apply(this, arguments) || this;
  76967. _this.type = SelectDataZoomView.type;
  76968. return _this;
  76969. }
  76970. SelectDataZoomView.type = 'dataZoom.select';
  76971. return SelectDataZoomView;
  76972. }(DataZoomView);
  76973. var each$8 = each;
  76974. var asc$1 = asc;
  76975. /**
  76976. * Operate single axis.
  76977. * One axis can only operated by one axis operator.
  76978. * Different dataZoomModels may be defined to operate the same axis.
  76979. * (i.e. 'inside' data zoom and 'slider' data zoom components)
  76980. * So dataZoomModels share one axisProxy in that case.
  76981. */
  76982. var AxisProxy = /** @class */function () {
  76983. function AxisProxy(dimName, axisIndex, dataZoomModel, ecModel) {
  76984. this._dimName = dimName;
  76985. this._axisIndex = axisIndex;
  76986. this.ecModel = ecModel;
  76987. this._dataZoomModel = dataZoomModel;
  76988. // /**
  76989. // * @readOnly
  76990. // * @private
  76991. // */
  76992. // this.hasSeriesStacked;
  76993. }
  76994. /**
  76995. * Whether the axisProxy is hosted by dataZoomModel.
  76996. */
  76997. AxisProxy.prototype.hostedBy = function (dataZoomModel) {
  76998. return this._dataZoomModel === dataZoomModel;
  76999. };
  77000. /**
  77001. * @return Value can only be NaN or finite value.
  77002. */
  77003. AxisProxy.prototype.getDataValueWindow = function () {
  77004. return this._valueWindow.slice();
  77005. };
  77006. /**
  77007. * @return {Array.<number>}
  77008. */
  77009. AxisProxy.prototype.getDataPercentWindow = function () {
  77010. return this._percentWindow.slice();
  77011. };
  77012. AxisProxy.prototype.getTargetSeriesModels = function () {
  77013. var seriesModels = [];
  77014. this.ecModel.eachSeries(function (seriesModel) {
  77015. if (isCoordSupported(seriesModel)) {
  77016. var axisMainType = getAxisMainType(this._dimName);
  77017. var axisModel = seriesModel.getReferringComponents(axisMainType, SINGLE_REFERRING).models[0];
  77018. if (axisModel && this._axisIndex === axisModel.componentIndex) {
  77019. seriesModels.push(seriesModel);
  77020. }
  77021. }
  77022. }, this);
  77023. return seriesModels;
  77024. };
  77025. AxisProxy.prototype.getAxisModel = function () {
  77026. return this.ecModel.getComponent(this._dimName + 'Axis', this._axisIndex);
  77027. };
  77028. AxisProxy.prototype.getMinMaxSpan = function () {
  77029. return clone(this._minMaxSpan);
  77030. };
  77031. /**
  77032. * Only calculate by given range and this._dataExtent, do not change anything.
  77033. */
  77034. AxisProxy.prototype.calculateDataWindow = function (opt) {
  77035. var dataExtent = this._dataExtent;
  77036. var axisModel = this.getAxisModel();
  77037. var scale = axisModel.axis.scale;
  77038. var rangePropMode = this._dataZoomModel.getRangePropMode();
  77039. var percentExtent = [0, 100];
  77040. var percentWindow = [];
  77041. var valueWindow = [];
  77042. var hasPropModeValue;
  77043. each$8(['start', 'end'], function (prop, idx) {
  77044. var boundPercent = opt[prop];
  77045. var boundValue = opt[prop + 'Value'];
  77046. // Notice: dataZoom is based either on `percentProp` ('start', 'end') or
  77047. // on `valueProp` ('startValue', 'endValue'). (They are based on the data extent
  77048. // but not min/max of axis, which will be calculated by data window then).
  77049. // The former one is suitable for cases that a dataZoom component controls multiple
  77050. // axes with different unit or extent, and the latter one is suitable for accurate
  77051. // zoom by pixel (e.g., in dataZoomSelect).
  77052. // we use `getRangePropMode()` to mark which prop is used. `rangePropMode` is updated
  77053. // only when setOption or dispatchAction, otherwise it remains its original value.
  77054. // (Why not only record `percentProp` and always map to `valueProp`? Because
  77055. // the map `valueProp` -> `percentProp` -> `valueProp` probably not the original
  77056. // `valueProp`. consider two axes constrolled by one dataZoom. They have different
  77057. // data extent. All of values that are overflow the `dataExtent` will be calculated
  77058. // to percent '100%').
  77059. if (rangePropMode[idx] === 'percent') {
  77060. boundPercent == null && (boundPercent = percentExtent[idx]);
  77061. // Use scale.parse to math round for category or time axis.
  77062. boundValue = scale.parse(linearMap(boundPercent, percentExtent, dataExtent));
  77063. } else {
  77064. hasPropModeValue = true;
  77065. boundValue = boundValue == null ? dataExtent[idx] : scale.parse(boundValue);
  77066. // Calculating `percent` from `value` may be not accurate, because
  77067. // This calculation can not be inversed, because all of values that
  77068. // are overflow the `dataExtent` will be calculated to percent '100%'
  77069. boundPercent = linearMap(boundValue, dataExtent, percentExtent);
  77070. }
  77071. // valueWindow[idx] = round(boundValue);
  77072. // percentWindow[idx] = round(boundPercent);
  77073. // fallback to extent start/end when parsed value or percent is invalid
  77074. valueWindow[idx] = boundValue == null || isNaN(boundValue) ? dataExtent[idx] : boundValue;
  77075. percentWindow[idx] = boundPercent == null || isNaN(boundPercent) ? percentExtent[idx] : boundPercent;
  77076. });
  77077. asc$1(valueWindow);
  77078. asc$1(percentWindow);
  77079. // The windows from user calling of `dispatchAction` might be out of the extent,
  77080. // or do not obey the `min/maxSpan`, `min/maxValueSpan`. But we don't restrict window
  77081. // by `zoomLock` here, because we see `zoomLock` just as a interaction constraint,
  77082. // where API is able to initialize/modify the window size even though `zoomLock`
  77083. // specified.
  77084. var spans = this._minMaxSpan;
  77085. hasPropModeValue ? restrictSet(valueWindow, percentWindow, dataExtent, percentExtent, false) : restrictSet(percentWindow, valueWindow, percentExtent, dataExtent, true);
  77086. function restrictSet(fromWindow, toWindow, fromExtent, toExtent, toValue) {
  77087. var suffix = toValue ? 'Span' : 'ValueSpan';
  77088. sliderMove(0, fromWindow, fromExtent, 'all', spans['min' + suffix], spans['max' + suffix]);
  77089. for (var i = 0; i < 2; i++) {
  77090. toWindow[i] = linearMap(fromWindow[i], fromExtent, toExtent, true);
  77091. toValue && (toWindow[i] = scale.parse(toWindow[i]));
  77092. }
  77093. }
  77094. return {
  77095. valueWindow: valueWindow,
  77096. percentWindow: percentWindow
  77097. };
  77098. };
  77099. /**
  77100. * Notice: reset should not be called before series.restoreData() is called,
  77101. * so it is recommended to be called in "process stage" but not "model init
  77102. * stage".
  77103. */
  77104. AxisProxy.prototype.reset = function (dataZoomModel) {
  77105. if (dataZoomModel !== this._dataZoomModel) {
  77106. return;
  77107. }
  77108. var targetSeries = this.getTargetSeriesModels();
  77109. // Culculate data window and data extent, and record them.
  77110. this._dataExtent = calculateDataExtent(this, this._dimName, targetSeries);
  77111. // `calculateDataWindow` uses min/maxSpan.
  77112. this._updateMinMaxSpan();
  77113. var dataWindow = this.calculateDataWindow(dataZoomModel.settledOption);
  77114. this._valueWindow = dataWindow.valueWindow;
  77115. this._percentWindow = dataWindow.percentWindow;
  77116. // Update axis setting then.
  77117. this._setAxisModel();
  77118. };
  77119. AxisProxy.prototype.filterData = function (dataZoomModel, api) {
  77120. if (dataZoomModel !== this._dataZoomModel) {
  77121. return;
  77122. }
  77123. var axisDim = this._dimName;
  77124. var seriesModels = this.getTargetSeriesModels();
  77125. var filterMode = dataZoomModel.get('filterMode');
  77126. var valueWindow = this._valueWindow;
  77127. if (filterMode === 'none') {
  77128. return;
  77129. }
  77130. // FIXME
  77131. // Toolbox may has dataZoom injected. And if there are stacked bar chart
  77132. // with NaN data, NaN will be filtered and stack will be wrong.
  77133. // So we need to force the mode to be set empty.
  77134. // In fect, it is not a big deal that do not support filterMode-'filter'
  77135. // when using toolbox#dataZoom, utill tooltip#dataZoom support "single axis
  77136. // selection" some day, which might need "adapt to data extent on the
  77137. // otherAxis", which is disabled by filterMode-'empty'.
  77138. // But currently, stack has been fixed to based on value but not index,
  77139. // so this is not an issue any more.
  77140. // let otherAxisModel = this.getOtherAxisModel();
  77141. // if (dataZoomModel.get('$fromToolbox')
  77142. // && otherAxisModel
  77143. // && otherAxisModel.hasSeriesStacked
  77144. // ) {
  77145. // filterMode = 'empty';
  77146. // }
  77147. // TODO
  77148. // filterMode 'weakFilter' and 'empty' is not optimized for huge data yet.
  77149. each$8(seriesModels, function (seriesModel) {
  77150. var seriesData = seriesModel.getData();
  77151. var dataDims = seriesData.mapDimensionsAll(axisDim);
  77152. if (!dataDims.length) {
  77153. return;
  77154. }
  77155. if (filterMode === 'weakFilter') {
  77156. var store_1 = seriesData.getStore();
  77157. var dataDimIndices_1 = map(dataDims, function (dim) {
  77158. return seriesData.getDimensionIndex(dim);
  77159. }, seriesData);
  77160. seriesData.filterSelf(function (dataIndex) {
  77161. var leftOut;
  77162. var rightOut;
  77163. var hasValue;
  77164. for (var i = 0; i < dataDims.length; i++) {
  77165. var value = store_1.get(dataDimIndices_1[i], dataIndex);
  77166. var thisHasValue = !isNaN(value);
  77167. var thisLeftOut = value < valueWindow[0];
  77168. var thisRightOut = value > valueWindow[1];
  77169. if (thisHasValue && !thisLeftOut && !thisRightOut) {
  77170. return true;
  77171. }
  77172. thisHasValue && (hasValue = true);
  77173. thisLeftOut && (leftOut = true);
  77174. thisRightOut && (rightOut = true);
  77175. }
  77176. // If both left out and right out, do not filter.
  77177. return hasValue && leftOut && rightOut;
  77178. });
  77179. } else {
  77180. each$8(dataDims, function (dim) {
  77181. if (filterMode === 'empty') {
  77182. seriesModel.setData(seriesData = seriesData.map(dim, function (value) {
  77183. return !isInWindow(value) ? NaN : value;
  77184. }));
  77185. } else {
  77186. var range = {};
  77187. range[dim] = valueWindow;
  77188. // console.time('select');
  77189. seriesData.selectRange(range);
  77190. // console.timeEnd('select');
  77191. }
  77192. });
  77193. }
  77194. each$8(dataDims, function (dim) {
  77195. seriesData.setApproximateExtent(valueWindow, dim);
  77196. });
  77197. });
  77198. function isInWindow(value) {
  77199. return value >= valueWindow[0] && value <= valueWindow[1];
  77200. }
  77201. };
  77202. AxisProxy.prototype._updateMinMaxSpan = function () {
  77203. var minMaxSpan = this._minMaxSpan = {};
  77204. var dataZoomModel = this._dataZoomModel;
  77205. var dataExtent = this._dataExtent;
  77206. each$8(['min', 'max'], function (minMax) {
  77207. var percentSpan = dataZoomModel.get(minMax + 'Span');
  77208. var valueSpan = dataZoomModel.get(minMax + 'ValueSpan');
  77209. valueSpan != null && (valueSpan = this.getAxisModel().axis.scale.parse(valueSpan));
  77210. // minValueSpan and maxValueSpan has higher priority than minSpan and maxSpan
  77211. if (valueSpan != null) {
  77212. percentSpan = linearMap(dataExtent[0] + valueSpan, dataExtent, [0, 100], true);
  77213. } else if (percentSpan != null) {
  77214. valueSpan = linearMap(percentSpan, [0, 100], dataExtent, true) - dataExtent[0];
  77215. }
  77216. minMaxSpan[minMax + 'Span'] = percentSpan;
  77217. minMaxSpan[minMax + 'ValueSpan'] = valueSpan;
  77218. }, this);
  77219. };
  77220. AxisProxy.prototype._setAxisModel = function () {
  77221. var axisModel = this.getAxisModel();
  77222. var percentWindow = this._percentWindow;
  77223. var valueWindow = this._valueWindow;
  77224. if (!percentWindow) {
  77225. return;
  77226. }
  77227. // [0, 500]: arbitrary value, guess axis extent.
  77228. var precision = getPixelPrecision(valueWindow, [0, 500]);
  77229. precision = Math.min(precision, 20);
  77230. // For value axis, if min/max/scale are not set, we just use the extent obtained
  77231. // by series data, which may be a little different from the extent calculated by
  77232. // `axisHelper.getScaleExtent`. But the different just affects the experience a
  77233. // little when zooming. So it will not be fixed until some users require it strongly.
  77234. var rawExtentInfo = axisModel.axis.scale.rawExtentInfo;
  77235. if (percentWindow[0] !== 0) {
  77236. rawExtentInfo.setDeterminedMinMax('min', +valueWindow[0].toFixed(precision));
  77237. }
  77238. if (percentWindow[1] !== 100) {
  77239. rawExtentInfo.setDeterminedMinMax('max', +valueWindow[1].toFixed(precision));
  77240. }
  77241. rawExtentInfo.freeze();
  77242. };
  77243. return AxisProxy;
  77244. }();
  77245. function calculateDataExtent(axisProxy, axisDim, seriesModels) {
  77246. var dataExtent = [Infinity, -Infinity];
  77247. each$8(seriesModels, function (seriesModel) {
  77248. unionAxisExtentFromData(dataExtent, seriesModel.getData(), axisDim);
  77249. });
  77250. // It is important to get "consistent" extent when more then one axes is
  77251. // controlled by a `dataZoom`, otherwise those axes will not be synchronized
  77252. // when zooming. But it is difficult to know what is "consistent", considering
  77253. // axes have different type or even different meanings (For example, two
  77254. // time axes are used to compare data of the same date in different years).
  77255. // So basically dataZoom just obtains extent by series.data (in category axis
  77256. // extent can be obtained from axis.data).
  77257. // Nevertheless, user can set min/max/scale on axes to make extent of axes
  77258. // consistent.
  77259. var axisModel = axisProxy.getAxisModel();
  77260. var rawExtentResult = ensureScaleRawExtentInfo(axisModel.axis.scale, axisModel, dataExtent).calculate();
  77261. return [rawExtentResult.min, rawExtentResult.max];
  77262. }
  77263. var dataZoomProcessor = {
  77264. // `dataZoomProcessor` will only be performed in needed series. Consider if
  77265. // there is a line series and a pie series, it is better not to update the
  77266. // line series if only pie series is needed to be updated.
  77267. getTargetSeries: function (ecModel) {
  77268. function eachAxisModel(cb) {
  77269. ecModel.eachComponent('dataZoom', function (dataZoomModel) {
  77270. dataZoomModel.eachTargetAxis(function (axisDim, axisIndex) {
  77271. var axisModel = ecModel.getComponent(getAxisMainType(axisDim), axisIndex);
  77272. cb(axisDim, axisIndex, axisModel, dataZoomModel);
  77273. });
  77274. });
  77275. }
  77276. // FIXME: it brings side-effect to `getTargetSeries`.
  77277. // Prepare axis proxies.
  77278. eachAxisModel(function (axisDim, axisIndex, axisModel, dataZoomModel) {
  77279. // dispose all last axis proxy, in case that some axis are deleted.
  77280. axisModel.__dzAxisProxy = null;
  77281. });
  77282. var proxyList = [];
  77283. eachAxisModel(function (axisDim, axisIndex, axisModel, dataZoomModel) {
  77284. // Different dataZooms may constrol the same axis. In that case,
  77285. // an axisProxy serves both of them.
  77286. if (!axisModel.__dzAxisProxy) {
  77287. // Use the first dataZoomModel as the main model of axisProxy.
  77288. axisModel.__dzAxisProxy = new AxisProxy(axisDim, axisIndex, dataZoomModel, ecModel);
  77289. proxyList.push(axisModel.__dzAxisProxy);
  77290. }
  77291. });
  77292. var seriesModelMap = createHashMap();
  77293. each(proxyList, function (axisProxy) {
  77294. each(axisProxy.getTargetSeriesModels(), function (seriesModel) {
  77295. seriesModelMap.set(seriesModel.uid, seriesModel);
  77296. });
  77297. });
  77298. return seriesModelMap;
  77299. },
  77300. // Consider appendData, where filter should be performed. Because data process is
  77301. // in block mode currently, it is not need to worry about that the overallProgress
  77302. // execute every frame.
  77303. overallReset: function (ecModel, api) {
  77304. ecModel.eachComponent('dataZoom', function (dataZoomModel) {
  77305. // We calculate window and reset axis here but not in model
  77306. // init stage and not after action dispatch handler, because
  77307. // reset should be called after seriesData.restoreData.
  77308. dataZoomModel.eachTargetAxis(function (axisDim, axisIndex) {
  77309. dataZoomModel.getAxisProxy(axisDim, axisIndex).reset(dataZoomModel);
  77310. });
  77311. // Caution: data zoom filtering is order sensitive when using
  77312. // percent range and no min/max/scale set on axis.
  77313. // For example, we have dataZoom definition:
  77314. // [
  77315. // {xAxisIndex: 0, start: 30, end: 70},
  77316. // {yAxisIndex: 0, start: 20, end: 80}
  77317. // ]
  77318. // In this case, [20, 80] of y-dataZoom should be based on data
  77319. // that have filtered by x-dataZoom using range of [30, 70],
  77320. // but should not be based on full raw data. Thus sliding
  77321. // x-dataZoom will change both ranges of xAxis and yAxis,
  77322. // while sliding y-dataZoom will only change the range of yAxis.
  77323. // So we should filter x-axis after reset x-axis immediately,
  77324. // and then reset y-axis and filter y-axis.
  77325. dataZoomModel.eachTargetAxis(function (axisDim, axisIndex) {
  77326. dataZoomModel.getAxisProxy(axisDim, axisIndex).filterData(dataZoomModel, api);
  77327. });
  77328. });
  77329. ecModel.eachComponent('dataZoom', function (dataZoomModel) {
  77330. // Fullfill all of the range props so that user
  77331. // is able to get them from chart.getOption().
  77332. var axisProxy = dataZoomModel.findRepresentativeAxisProxy();
  77333. if (axisProxy) {
  77334. var percentRange = axisProxy.getDataPercentWindow();
  77335. var valueRange = axisProxy.getDataValueWindow();
  77336. dataZoomModel.setCalculatedRange({
  77337. start: percentRange[0],
  77338. end: percentRange[1],
  77339. startValue: valueRange[0],
  77340. endValue: valueRange[1]
  77341. });
  77342. }
  77343. });
  77344. }
  77345. };
  77346. function installDataZoomAction(registers) {
  77347. registers.registerAction('dataZoom', function (payload, ecModel) {
  77348. var effectedModels = findEffectedDataZooms(ecModel, payload);
  77349. each(effectedModels, function (dataZoomModel) {
  77350. dataZoomModel.setRawRange({
  77351. start: payload.start,
  77352. end: payload.end,
  77353. startValue: payload.startValue,
  77354. endValue: payload.endValue
  77355. });
  77356. });
  77357. });
  77358. }
  77359. var installed = false;
  77360. function installCommon(registers) {
  77361. if (installed) {
  77362. return;
  77363. }
  77364. installed = true;
  77365. registers.registerProcessor(registers.PRIORITY.PROCESSOR.FILTER, dataZoomProcessor);
  77366. installDataZoomAction(registers);
  77367. registers.registerSubTypeDefaulter('dataZoom', function () {
  77368. // Default 'slider' when no type specified.
  77369. return 'slider';
  77370. });
  77371. }
  77372. function install$A(registers) {
  77373. registers.registerComponentModel(SelectDataZoomModel);
  77374. registers.registerComponentView(SelectDataZoomView);
  77375. installCommon(registers);
  77376. }
  77377. /*
  77378. * Licensed to the Apache Software Foundation (ASF) under one
  77379. * or more contributor license agreements. See the NOTICE file
  77380. * distributed with this work for additional information
  77381. * regarding copyright ownership. The ASF licenses this file
  77382. * to you under the Apache License, Version 2.0 (the
  77383. * "License"); you may not use this file except in compliance
  77384. * with the License. You may obtain a copy of the License at
  77385. *
  77386. * http://www.apache.org/licenses/LICENSE-2.0
  77387. *
  77388. * Unless required by applicable law or agreed to in writing,
  77389. * software distributed under the License is distributed on an
  77390. * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
  77391. * KIND, either express or implied. See the License for the
  77392. * specific language governing permissions and limitations
  77393. * under the License.
  77394. */
  77395. /**
  77396. * AUTO-GENERATED FILE. DO NOT MODIFY.
  77397. */
  77398. var ToolboxFeature = /** @class */function () {
  77399. function ToolboxFeature() {}
  77400. return ToolboxFeature;
  77401. }();
  77402. var features = {};
  77403. function registerFeature(name, ctor) {
  77404. features[name] = ctor;
  77405. }
  77406. function getFeature(name) {
  77407. return features[name];
  77408. }
  77409. var ToolboxModel = /** @class */function (_super) {
  77410. __extends(ToolboxModel, _super);
  77411. function ToolboxModel() {
  77412. var _this = _super !== null && _super.apply(this, arguments) || this;
  77413. _this.type = ToolboxModel.type;
  77414. return _this;
  77415. }
  77416. ToolboxModel.prototype.optionUpdated = function () {
  77417. _super.prototype.optionUpdated.apply(this, arguments);
  77418. var ecModel = this.ecModel;
  77419. each(this.option.feature, function (featureOpt, featureName) {
  77420. var Feature = getFeature(featureName);
  77421. if (Feature) {
  77422. if (Feature.getDefaultOption) {
  77423. Feature.defaultOption = Feature.getDefaultOption(ecModel);
  77424. }
  77425. merge(featureOpt, Feature.defaultOption);
  77426. }
  77427. });
  77428. };
  77429. ToolboxModel.type = 'toolbox';
  77430. ToolboxModel.layoutMode = {
  77431. type: 'box',
  77432. ignoreSize: true
  77433. };
  77434. ToolboxModel.defaultOption = {
  77435. show: true,
  77436. z: 6,
  77437. // zlevel: 0,
  77438. orient: 'horizontal',
  77439. left: 'right',
  77440. top: 'top',
  77441. // right
  77442. // bottom
  77443. backgroundColor: 'transparent',
  77444. borderColor: tokens.color.border,
  77445. borderRadius: 0,
  77446. borderWidth: 0,
  77447. padding: tokens.size.m,
  77448. itemSize: 15,
  77449. itemGap: tokens.size.s,
  77450. showTitle: true,
  77451. iconStyle: {
  77452. borderColor: tokens.color.accent50,
  77453. color: 'none'
  77454. },
  77455. emphasis: {
  77456. iconStyle: {
  77457. borderColor: tokens.color.accent50
  77458. }
  77459. },
  77460. // textStyle: {},
  77461. // feature
  77462. tooltip: {
  77463. show: false,
  77464. position: 'bottom'
  77465. }
  77466. };
  77467. return ToolboxModel;
  77468. }(ComponentModel);
  77469. function makeBackground(rect, componentModel) {
  77470. var padding = normalizeCssArray$1(componentModel.get('padding'));
  77471. var style = componentModel.getItemStyle(['color', 'opacity']);
  77472. style.fill = componentModel.get('backgroundColor');
  77473. var bgRect = new Rect({
  77474. shape: {
  77475. x: rect.x - padding[3],
  77476. y: rect.y - padding[0],
  77477. width: rect.width + padding[1] + padding[3],
  77478. height: rect.height + padding[0] + padding[2],
  77479. r: componentModel.get('borderRadius')
  77480. },
  77481. style: style,
  77482. silent: true,
  77483. z2: -1
  77484. });
  77485. // FIXME
  77486. // `subPixelOptimizeRect` may bring some gap between edge of viewpart
  77487. // and background rect when setting like `left: 0`, `top: 0`.
  77488. // graphic.subPixelOptimizeRect(rect);
  77489. return bgRect;
  77490. }
  77491. var ToolboxView = /** @class */function (_super) {
  77492. __extends(ToolboxView, _super);
  77493. function ToolboxView() {
  77494. return _super !== null && _super.apply(this, arguments) || this;
  77495. }
  77496. ToolboxView.prototype.render = function (toolboxModel, ecModel, api, payload) {
  77497. var group = this.group;
  77498. group.removeAll();
  77499. if (!toolboxModel.get('show')) {
  77500. return;
  77501. }
  77502. var itemSize = +toolboxModel.get('itemSize');
  77503. var isVertical = toolboxModel.get('orient') === 'vertical';
  77504. var featureOpts = toolboxModel.get('feature') || {};
  77505. var features = this._features || (this._features = {});
  77506. var featureNames = [];
  77507. each(featureOpts, function (opt, name) {
  77508. featureNames.push(name);
  77509. });
  77510. new DataDiffer(this._featureNames || [], featureNames).add(processFeature).update(processFeature).remove(curry(processFeature, null)).execute();
  77511. // Keep for diff.
  77512. this._featureNames = featureNames;
  77513. function processFeature(newIndex, oldIndex) {
  77514. var featureName = featureNames[newIndex];
  77515. var oldName = featureNames[oldIndex];
  77516. var featureOpt = featureOpts[featureName];
  77517. var featureModel = new Model(featureOpt, toolboxModel, toolboxModel.ecModel);
  77518. var feature;
  77519. // FIX#11236, merge feature title from MagicType newOption. TODO: consider seriesIndex ?
  77520. if (payload && payload.newTitle != null && payload.featureName === featureName) {
  77521. featureOpt.title = payload.newTitle;
  77522. }
  77523. if (featureName && !oldName) {
  77524. // Create
  77525. if (isUserFeatureName(featureName)) {
  77526. feature = {
  77527. onclick: featureModel.option.onclick,
  77528. featureName: featureName
  77529. };
  77530. } else {
  77531. var Feature = getFeature(featureName);
  77532. if (!Feature) {
  77533. return;
  77534. }
  77535. feature = new Feature();
  77536. }
  77537. features[featureName] = feature;
  77538. } else {
  77539. feature = features[oldName];
  77540. // If feature does not exist.
  77541. if (!feature) {
  77542. return;
  77543. }
  77544. }
  77545. feature.uid = getUID('toolbox-feature');
  77546. feature.model = featureModel;
  77547. feature.ecModel = ecModel;
  77548. feature.api = api;
  77549. var isToolboxFeature = feature instanceof ToolboxFeature;
  77550. if (!featureName && oldName) {
  77551. isToolboxFeature && feature.dispose && feature.dispose(ecModel, api);
  77552. return;
  77553. }
  77554. if (!featureModel.get('show') || isToolboxFeature && feature.unusable) {
  77555. isToolboxFeature && feature.remove && feature.remove(ecModel, api);
  77556. return;
  77557. }
  77558. createIconPaths(featureModel, feature, featureName);
  77559. featureModel.setIconStatus = function (iconName, status) {
  77560. var option = this.option;
  77561. var iconPaths = this.iconPaths;
  77562. option.iconStatus = option.iconStatus || {};
  77563. option.iconStatus[iconName] = status;
  77564. if (iconPaths[iconName]) {
  77565. (status === 'emphasis' ? enterEmphasis : leaveEmphasis)(iconPaths[iconName]);
  77566. }
  77567. };
  77568. if (feature instanceof ToolboxFeature) {
  77569. if (feature.render) {
  77570. feature.render(featureModel, ecModel, api, payload);
  77571. }
  77572. }
  77573. }
  77574. function createIconPaths(featureModel, feature, featureName) {
  77575. var iconStyleModel = featureModel.getModel('iconStyle');
  77576. var iconStyleEmphasisModel = featureModel.getModel(['emphasis', 'iconStyle']);
  77577. // If one feature has multiple icons, they are organized as
  77578. // {
  77579. // icon: {
  77580. // foo: '',
  77581. // bar: ''
  77582. // },
  77583. // title: {
  77584. // foo: '',
  77585. // bar: ''
  77586. // }
  77587. // }
  77588. var icons = feature instanceof ToolboxFeature && feature.getIcons ? feature.getIcons() : featureModel.get('icon');
  77589. var titles = featureModel.get('title') || {};
  77590. var iconsMap;
  77591. var titlesMap;
  77592. if (isString(icons)) {
  77593. iconsMap = {};
  77594. iconsMap[featureName] = icons;
  77595. } else {
  77596. iconsMap = icons;
  77597. }
  77598. if (isString(titles)) {
  77599. titlesMap = {};
  77600. titlesMap[featureName] = titles;
  77601. } else {
  77602. titlesMap = titles;
  77603. }
  77604. var iconPaths = featureModel.iconPaths = {};
  77605. each(iconsMap, function (iconStr, iconName) {
  77606. var path = createIcon(iconStr, {}, {
  77607. x: -itemSize / 2,
  77608. y: -itemSize / 2,
  77609. width: itemSize,
  77610. height: itemSize
  77611. }); // TODO handling image
  77612. path.setStyle(iconStyleModel.getItemStyle());
  77613. var pathEmphasisState = path.ensureState('emphasis');
  77614. pathEmphasisState.style = iconStyleEmphasisModel.getItemStyle();
  77615. // Text position calculation
  77616. // TODO: extract `textStyle` from `iconStyle` and use `createTextStyle`
  77617. var textContent = new ZRText({
  77618. style: {
  77619. text: titlesMap[iconName],
  77620. align: iconStyleEmphasisModel.get('textAlign'),
  77621. borderRadius: iconStyleEmphasisModel.get('textBorderRadius'),
  77622. padding: iconStyleEmphasisModel.get('textPadding'),
  77623. fill: null,
  77624. font: getFont({
  77625. fontStyle: iconStyleEmphasisModel.get('textFontStyle'),
  77626. fontFamily: iconStyleEmphasisModel.get('textFontFamily'),
  77627. fontSize: iconStyleEmphasisModel.get('textFontSize'),
  77628. fontWeight: iconStyleEmphasisModel.get('textFontWeight')
  77629. }, ecModel)
  77630. },
  77631. ignore: true
  77632. });
  77633. path.setTextContent(textContent);
  77634. setTooltipConfig({
  77635. el: path,
  77636. componentModel: toolboxModel,
  77637. itemName: iconName,
  77638. formatterParamsExtra: {
  77639. title: titlesMap[iconName]
  77640. }
  77641. });
  77642. path.__title = titlesMap[iconName];
  77643. path.on('mouseover', function () {
  77644. // Should not reuse above hoverStyle, which might be modified.
  77645. var hoverStyle = iconStyleEmphasisModel.getItemStyle();
  77646. var defaultTextPosition = isVertical ? toolboxModel.get('right') == null && toolboxModel.get('left') !== 'right' ? 'right' : 'left' : toolboxModel.get('bottom') == null && toolboxModel.get('top') !== 'bottom' ? 'bottom' : 'top';
  77647. textContent.setStyle({
  77648. fill: iconStyleEmphasisModel.get('textFill') || hoverStyle.fill || hoverStyle.stroke || tokens.color.neutral99,
  77649. backgroundColor: iconStyleEmphasisModel.get('textBackgroundColor')
  77650. });
  77651. path.setTextConfig({
  77652. position: iconStyleEmphasisModel.get('textPosition') || defaultTextPosition
  77653. });
  77654. textContent.ignore = !toolboxModel.get('showTitle');
  77655. // Use enterEmphasis and leaveEmphasis provide by ec.
  77656. // There are flags managed by the echarts.
  77657. api.enterEmphasis(this);
  77658. }).on('mouseout', function () {
  77659. if (featureModel.get(['iconStatus', iconName]) !== 'emphasis') {
  77660. api.leaveEmphasis(this);
  77661. }
  77662. textContent.hide();
  77663. });
  77664. (featureModel.get(['iconStatus', iconName]) === 'emphasis' ? enterEmphasis : leaveEmphasis)(path);
  77665. group.add(path);
  77666. path.on('click', bind(feature.onclick, feature, ecModel, api, iconName));
  77667. iconPaths[iconName] = path;
  77668. });
  77669. }
  77670. var refContainer = createBoxLayoutReference(toolboxModel, api).refContainer;
  77671. var boxLayoutParams = toolboxModel.getBoxLayoutParams();
  77672. var padding = toolboxModel.get('padding');
  77673. var viewRect = getLayoutRect(boxLayoutParams, refContainer, padding);
  77674. box(toolboxModel.get('orient'), group, toolboxModel.get('itemGap'), viewRect.width, viewRect.height);
  77675. positionElement(group, boxLayoutParams, refContainer, padding);
  77676. // Render background after group is layout
  77677. // FIXME
  77678. group.add(makeBackground(group.getBoundingRect(), toolboxModel));
  77679. // Adjust icon title positions to avoid them out of screen
  77680. isVertical || group.eachChild(function (icon) {
  77681. var titleText = icon.__title;
  77682. // const hoverStyle = icon.hoverStyle;
  77683. // TODO simplify code?
  77684. var emphasisState = icon.ensureState('emphasis');
  77685. var emphasisTextConfig = emphasisState.textConfig || (emphasisState.textConfig = {});
  77686. var textContent = icon.getTextContent();
  77687. var emphasisTextState = textContent && textContent.ensureState('emphasis');
  77688. // May be background element
  77689. if (emphasisTextState && !isFunction(emphasisTextState) && titleText) {
  77690. var emphasisTextStyle = emphasisTextState.style || (emphasisTextState.style = {});
  77691. var rect = getBoundingRect(titleText, ZRText.makeFont(emphasisTextStyle));
  77692. var offsetX = icon.x + group.x;
  77693. var offsetY = icon.y + group.y + itemSize;
  77694. var needPutOnTop = false;
  77695. if (offsetY + rect.height > api.getHeight()) {
  77696. emphasisTextConfig.position = 'top';
  77697. needPutOnTop = true;
  77698. }
  77699. var topOffset = needPutOnTop ? -5 - rect.height : itemSize + 10;
  77700. if (offsetX + rect.width / 2 > api.getWidth()) {
  77701. emphasisTextConfig.position = ['100%', topOffset];
  77702. emphasisTextStyle.align = 'right';
  77703. } else if (offsetX - rect.width / 2 < 0) {
  77704. emphasisTextConfig.position = [0, topOffset];
  77705. emphasisTextStyle.align = 'left';
  77706. }
  77707. }
  77708. });
  77709. };
  77710. ToolboxView.prototype.updateView = function (toolboxModel, ecModel, api, payload) {
  77711. each(this._features, function (feature) {
  77712. feature instanceof ToolboxFeature && feature.updateView && feature.updateView(feature.model, ecModel, api, payload);
  77713. });
  77714. };
  77715. // updateLayout(toolboxModel, ecModel, api, payload) {
  77716. // zrUtil.each(this._features, function (feature) {
  77717. // feature.updateLayout && feature.updateLayout(feature.model, ecModel, api, payload);
  77718. // });
  77719. // },
  77720. ToolboxView.prototype.remove = function (ecModel, api) {
  77721. each(this._features, function (feature) {
  77722. feature instanceof ToolboxFeature && feature.remove && feature.remove(ecModel, api);
  77723. });
  77724. this.group.removeAll();
  77725. };
  77726. ToolboxView.prototype.dispose = function (ecModel, api) {
  77727. each(this._features, function (feature) {
  77728. feature instanceof ToolboxFeature && feature.dispose && feature.dispose(ecModel, api);
  77729. });
  77730. };
  77731. ToolboxView.type = 'toolbox';
  77732. return ToolboxView;
  77733. }(ComponentView);
  77734. function isUserFeatureName(featureName) {
  77735. return featureName.indexOf('my') === 0;
  77736. }
  77737. var SaveAsImage = /** @class */function (_super) {
  77738. __extends(SaveAsImage, _super);
  77739. function SaveAsImage() {
  77740. return _super !== null && _super.apply(this, arguments) || this;
  77741. }
  77742. SaveAsImage.prototype.onclick = function (ecModel, api) {
  77743. var model = this.model;
  77744. var title = model.get('name') || ecModel.get('title.0.text') || 'echarts';
  77745. var isSvg = api.getZr().painter.getType() === 'svg';
  77746. var type = isSvg ? 'svg' : model.get('type', true) || 'png';
  77747. var url = api.getConnectedDataURL({
  77748. type: type,
  77749. backgroundColor: model.get('backgroundColor', true) || ecModel.get('backgroundColor') || tokens.color.neutral00,
  77750. connectedBackgroundColor: model.get('connectedBackgroundColor'),
  77751. excludeComponents: model.get('excludeComponents'),
  77752. pixelRatio: model.get('pixelRatio')
  77753. });
  77754. var browser = env.browser;
  77755. // Chrome, Firefox, New Edge
  77756. if (typeof MouseEvent === 'function' && (browser.newEdge || !browser.ie && !browser.edge)) {
  77757. var $a = document.createElement('a');
  77758. $a.download = title + '.' + type;
  77759. $a.target = '_blank';
  77760. $a.href = url;
  77761. var evt = new MouseEvent('click', {
  77762. // some micro front-end framework, window maybe is a Proxy
  77763. view: document.defaultView,
  77764. bubbles: true,
  77765. cancelable: false
  77766. });
  77767. $a.dispatchEvent(evt);
  77768. }
  77769. // IE or old Edge
  77770. else {
  77771. // @ts-ignore
  77772. if (window.navigator.msSaveOrOpenBlob || isSvg) {
  77773. var parts = url.split(',');
  77774. // data:[<mime type>][;charset=<charset>][;base64],<encoded data>
  77775. var base64Encoded = parts[0].indexOf('base64') > -1;
  77776. var bstr = isSvg
  77777. // should decode the svg data uri first
  77778. ? decodeURIComponent(parts[1]) : parts[1];
  77779. // only `atob` when the data uri is encoded with base64
  77780. // otherwise, like `svg` data uri exported by zrender,
  77781. // there will be an error, for it's not encoded with base64.
  77782. // (just a url-encoded string through `encodeURIComponent`)
  77783. base64Encoded && (bstr = window.atob(bstr));
  77784. var filename = title + '.' + type;
  77785. // @ts-ignore
  77786. if (window.navigator.msSaveOrOpenBlob) {
  77787. var n = bstr.length;
  77788. var u8arr = new Uint8Array(n);
  77789. while (n--) {
  77790. u8arr[n] = bstr.charCodeAt(n);
  77791. }
  77792. var blob = new Blob([u8arr]); // @ts-ignore
  77793. window.navigator.msSaveOrOpenBlob(blob, filename);
  77794. } else {
  77795. var frame = document.createElement('iframe');
  77796. document.body.appendChild(frame);
  77797. var cw = frame.contentWindow;
  77798. var doc = cw.document;
  77799. doc.open('image/svg+xml', 'replace');
  77800. doc.write(bstr);
  77801. doc.close();
  77802. cw.focus();
  77803. doc.execCommand('SaveAs', true, filename);
  77804. document.body.removeChild(frame);
  77805. }
  77806. } else {
  77807. var lang = model.get('lang');
  77808. var html = '' + '<body style="margin:0;">' + '<img src="' + url + '" style="max-width:100%;" title="' + (lang && lang[0] || '') + '" />' + '</body>';
  77809. var tab = window.open();
  77810. tab.document.write(html);
  77811. tab.document.title = title;
  77812. }
  77813. }
  77814. };
  77815. SaveAsImage.getDefaultOption = function (ecModel) {
  77816. var defaultOption = {
  77817. show: true,
  77818. icon: 'M4.7,22.9L29.3,45.5L54.7,23.4M4.6,43.6L4.6,58L53.8,58L53.8,43.6M29.2,45.1L29.2,0',
  77819. title: ecModel.getLocaleModel().get(['toolbox', 'saveAsImage', 'title']),
  77820. type: 'png',
  77821. // Default use option.backgroundColor
  77822. // backgroundColor: '#fff',
  77823. connectedBackgroundColor: tokens.color.neutral00,
  77824. name: '',
  77825. excludeComponents: ['toolbox'],
  77826. // use current pixel ratio of device by default
  77827. // pixelRatio: 1,
  77828. lang: ecModel.getLocaleModel().get(['toolbox', 'saveAsImage', 'lang'])
  77829. };
  77830. return defaultOption;
  77831. };
  77832. return SaveAsImage;
  77833. }(ToolboxFeature);
  77834. var INNER_STACK_KEYWORD = '__ec_magicType_stack__';
  77835. var radioTypes = [['line', 'bar'], ['stack']];
  77836. var MagicType = /** @class */function (_super) {
  77837. __extends(MagicType, _super);
  77838. function MagicType() {
  77839. return _super !== null && _super.apply(this, arguments) || this;
  77840. }
  77841. MagicType.prototype.getIcons = function () {
  77842. var model = this.model;
  77843. var availableIcons = model.get('icon');
  77844. var icons = {};
  77845. each(model.get('type'), function (type) {
  77846. if (availableIcons[type]) {
  77847. icons[type] = availableIcons[type];
  77848. }
  77849. });
  77850. return icons;
  77851. };
  77852. MagicType.getDefaultOption = function (ecModel) {
  77853. var defaultOption = {
  77854. show: true,
  77855. type: [],
  77856. // Icon group
  77857. icon: {
  77858. line: 'M4.1,28.9h7.1l9.3-22l7.4,38l9.7-19.7l3,12.8h14.9M4.1,58h51.4',
  77859. bar: 'M6.7,22.9h10V48h-10V22.9zM24.9,13h10v35h-10V13zM43.2,2h10v46h-10V2zM3.1,58h53.7',
  77860. // eslint-disable-next-line
  77861. stack: 'M8.2,38.4l-8.4,4.1l30.6,15.3L60,42.5l-8.1-4.1l-21.5,11L8.2,38.4z M51.9,30l-8.1,4.2l-13.4,6.9l-13.9-6.9L8.2,30l-8.4,4.2l8.4,4.2l22.2,11l21.5-11l8.1-4.2L51.9,30z M51.9,21.7l-8.1,4.2L35.7,30l-5.3,2.8L24.9,30l-8.4-4.1l-8.3-4.2l-8.4,4.2L8.2,30l8.3,4.2l13.9,6.9l13.4-6.9l8.1-4.2l8.1-4.1L51.9,21.7zM30.4,2.2L-0.2,17.5l8.4,4.1l8.3,4.2l8.4,4.2l5.5,2.7l5.3-2.7l8.1-4.2l8.1-4.2l8.1-4.1L30.4,2.2z' // jshint ignore:line
  77862. },
  77863. // `line`, `bar`, `stack`, `tiled`
  77864. title: ecModel.getLocaleModel().get(['toolbox', 'magicType', 'title']),
  77865. option: {},
  77866. seriesIndex: {}
  77867. };
  77868. return defaultOption;
  77869. };
  77870. MagicType.prototype.onclick = function (ecModel, api, type) {
  77871. var model = this.model;
  77872. var seriesIndex = model.get(['seriesIndex', type]);
  77873. // Not supported magicType
  77874. if (!seriesOptGenreator[type]) {
  77875. return;
  77876. }
  77877. var newOption = {
  77878. series: []
  77879. };
  77880. var generateNewSeriesTypes = function (seriesModel) {
  77881. var seriesType = seriesModel.subType;
  77882. var seriesId = seriesModel.id;
  77883. var newSeriesOpt = seriesOptGenreator[type](seriesType, seriesId, seriesModel, model);
  77884. if (newSeriesOpt) {
  77885. // PENDING If merge original option?
  77886. defaults(newSeriesOpt, seriesModel.option);
  77887. newOption.series.push(newSeriesOpt);
  77888. }
  77889. // Modify boundaryGap
  77890. var coordSys = seriesModel.coordinateSystem;
  77891. if (coordSys && coordSys.type === 'cartesian2d' && (type === 'line' || type === 'bar')) {
  77892. var categoryAxis = coordSys.getAxesByScale('ordinal')[0];
  77893. if (categoryAxis) {
  77894. var axisDim = categoryAxis.dim;
  77895. var axisType = axisDim + 'Axis';
  77896. var axisModel = seriesModel.getReferringComponents(axisType, SINGLE_REFERRING).models[0];
  77897. var axisIndex = axisModel.componentIndex;
  77898. newOption[axisType] = newOption[axisType] || [];
  77899. for (var i = 0; i <= axisIndex; i++) {
  77900. newOption[axisType][axisIndex] = newOption[axisType][axisIndex] || {};
  77901. }
  77902. newOption[axisType][axisIndex].boundaryGap = type === 'bar';
  77903. }
  77904. }
  77905. };
  77906. each(radioTypes, function (radio) {
  77907. if (indexOf(radio, type) >= 0) {
  77908. each(radio, function (item) {
  77909. model.setIconStatus(item, 'normal');
  77910. });
  77911. }
  77912. });
  77913. model.setIconStatus(type, 'emphasis');
  77914. ecModel.eachComponent({
  77915. mainType: 'series',
  77916. query: seriesIndex == null ? null : {
  77917. seriesIndex: seriesIndex
  77918. }
  77919. }, generateNewSeriesTypes);
  77920. var newTitle;
  77921. var currentType = type;
  77922. // Change title of stack
  77923. if (type === 'stack') {
  77924. // use titles in model instead of ecModel
  77925. // as stack and tiled appears in pair, just flip them
  77926. // no need of checking stack state
  77927. newTitle = merge({
  77928. stack: model.option.title.tiled,
  77929. tiled: model.option.title.stack
  77930. }, model.option.title);
  77931. if (model.get(['iconStatus', type]) !== 'emphasis') {
  77932. currentType = 'tiled';
  77933. }
  77934. }
  77935. api.dispatchAction({
  77936. type: 'changeMagicType',
  77937. currentType: currentType,
  77938. newOption: newOption,
  77939. newTitle: newTitle,
  77940. featureName: 'magicType'
  77941. });
  77942. };
  77943. return MagicType;
  77944. }(ToolboxFeature);
  77945. var seriesOptGenreator = {
  77946. 'line': function (seriesType, seriesId, seriesModel, model) {
  77947. if (seriesType === 'bar') {
  77948. return merge({
  77949. id: seriesId,
  77950. type: 'line',
  77951. // Preserve data related option
  77952. data: seriesModel.get('data'),
  77953. stack: seriesModel.get('stack'),
  77954. markPoint: seriesModel.get('markPoint'),
  77955. markLine: seriesModel.get('markLine')
  77956. }, model.get(['option', 'line']) || {}, true);
  77957. }
  77958. },
  77959. 'bar': function (seriesType, seriesId, seriesModel, model) {
  77960. if (seriesType === 'line') {
  77961. return merge({
  77962. id: seriesId,
  77963. type: 'bar',
  77964. // Preserve data related option
  77965. data: seriesModel.get('data'),
  77966. stack: seriesModel.get('stack'),
  77967. markPoint: seriesModel.get('markPoint'),
  77968. markLine: seriesModel.get('markLine')
  77969. }, model.get(['option', 'bar']) || {}, true);
  77970. }
  77971. },
  77972. 'stack': function (seriesType, seriesId, seriesModel, model) {
  77973. var isStack = seriesModel.get('stack') === INNER_STACK_KEYWORD;
  77974. if (seriesType === 'line' || seriesType === 'bar') {
  77975. model.setIconStatus('stack', isStack ? 'normal' : 'emphasis');
  77976. return merge({
  77977. id: seriesId,
  77978. stack: isStack ? '' : INNER_STACK_KEYWORD
  77979. }, model.get(['option', 'stack']) || {}, true);
  77980. }
  77981. }
  77982. };
  77983. // TODO: SELF REGISTERED.
  77984. registerAction({
  77985. type: 'changeMagicType',
  77986. event: 'magicTypeChanged',
  77987. update: 'prepareAndUpdate'
  77988. }, function (payload, ecModel) {
  77989. ecModel.mergeOption(payload.newOption);
  77990. });
  77991. /* global document */
  77992. var BLOCK_SPLITER = new Array(60).join('-');
  77993. var ITEM_SPLITER = '\t';
  77994. /**
  77995. * Group series into two types
  77996. * 1. on category axis, like line, bar
  77997. * 2. others, like scatter, pie
  77998. */
  77999. function groupSeries(ecModel) {
  78000. var seriesGroupByCategoryAxis = {};
  78001. var otherSeries = [];
  78002. var meta = [];
  78003. ecModel.eachRawSeries(function (seriesModel) {
  78004. var coordSys = seriesModel.coordinateSystem;
  78005. if (coordSys && (coordSys.type === 'cartesian2d' || coordSys.type === 'polar')) {
  78006. // TODO: TYPE Consider polar? Include polar may increase unecessary bundle size.
  78007. var baseAxis = coordSys.getBaseAxis();
  78008. if (baseAxis.type === 'category') {
  78009. var key = baseAxis.dim + '_' + baseAxis.index;
  78010. if (!seriesGroupByCategoryAxis[key]) {
  78011. seriesGroupByCategoryAxis[key] = {
  78012. categoryAxis: baseAxis,
  78013. valueAxis: coordSys.getOtherAxis(baseAxis),
  78014. series: []
  78015. };
  78016. meta.push({
  78017. axisDim: baseAxis.dim,
  78018. axisIndex: baseAxis.index
  78019. });
  78020. }
  78021. seriesGroupByCategoryAxis[key].series.push(seriesModel);
  78022. } else {
  78023. otherSeries.push(seriesModel);
  78024. }
  78025. } else {
  78026. otherSeries.push(seriesModel);
  78027. }
  78028. });
  78029. return {
  78030. seriesGroupByCategoryAxis: seriesGroupByCategoryAxis,
  78031. other: otherSeries,
  78032. meta: meta
  78033. };
  78034. }
  78035. /**
  78036. * Assemble content of series on cateogory axis
  78037. * @inner
  78038. */
  78039. function assembleSeriesWithCategoryAxis(groups) {
  78040. var tables = [];
  78041. each(groups, function (group, key) {
  78042. var categoryAxis = group.categoryAxis;
  78043. var valueAxis = group.valueAxis;
  78044. var valueAxisDim = valueAxis.dim;
  78045. var headers = [' '].concat(map(group.series, function (series) {
  78046. return series.name;
  78047. }));
  78048. // @ts-ignore TODO Polar
  78049. var columns = [categoryAxis.model.getCategories()];
  78050. each(group.series, function (series) {
  78051. var rawData = series.getRawData();
  78052. columns.push(series.getRawData().mapArray(rawData.mapDimension(valueAxisDim), function (val) {
  78053. return val;
  78054. }));
  78055. });
  78056. // Assemble table content
  78057. var lines = [headers.join(ITEM_SPLITER)];
  78058. for (var i = 0; i < columns[0].length; i++) {
  78059. var items = [];
  78060. for (var j = 0; j < columns.length; j++) {
  78061. items.push(columns[j][i]);
  78062. }
  78063. lines.push(items.join(ITEM_SPLITER));
  78064. }
  78065. tables.push(lines.join('\n'));
  78066. });
  78067. return tables.join('\n\n' + BLOCK_SPLITER + '\n\n');
  78068. }
  78069. /**
  78070. * Assemble content of other series
  78071. */
  78072. function assembleOtherSeries(series) {
  78073. return map(series, function (series) {
  78074. var data = series.getRawData();
  78075. var lines = [series.name];
  78076. var vals = [];
  78077. data.each(data.dimensions, function () {
  78078. var argLen = arguments.length;
  78079. var dataIndex = arguments[argLen - 1];
  78080. var name = data.getName(dataIndex);
  78081. for (var i = 0; i < argLen - 1; i++) {
  78082. vals[i] = arguments[i];
  78083. }
  78084. lines.push((name ? name + ITEM_SPLITER : '') + vals.join(ITEM_SPLITER));
  78085. });
  78086. return lines.join('\n');
  78087. }).join('\n\n' + BLOCK_SPLITER + '\n\n');
  78088. }
  78089. function getContentFromModel(ecModel) {
  78090. var result = groupSeries(ecModel);
  78091. return {
  78092. value: filter([assembleSeriesWithCategoryAxis(result.seriesGroupByCategoryAxis), assembleOtherSeries(result.other)], function (str) {
  78093. return !!str.replace(/[\n\t\s]/g, '');
  78094. }).join('\n\n' + BLOCK_SPLITER + '\n\n'),
  78095. meta: result.meta
  78096. };
  78097. }
  78098. function trim$1(str) {
  78099. return str.replace(/^\s\s*/, '').replace(/\s\s*$/, '');
  78100. }
  78101. /**
  78102. * If a block is tsv format
  78103. */
  78104. function isTSVFormat(block) {
  78105. // Simple method to find out if a block is tsv format
  78106. var firstLine = block.slice(0, block.indexOf('\n'));
  78107. if (firstLine.indexOf(ITEM_SPLITER) >= 0) {
  78108. return true;
  78109. }
  78110. }
  78111. var itemSplitRegex = new RegExp('[' + ITEM_SPLITER + ']+', 'g');
  78112. /**
  78113. * @param {string} tsv
  78114. * @return {Object}
  78115. */
  78116. function parseTSVContents(tsv) {
  78117. var tsvLines = tsv.split(/\n+/g);
  78118. var headers = trim$1(tsvLines.shift()).split(itemSplitRegex);
  78119. var categories = [];
  78120. var series = map(headers, function (header) {
  78121. return {
  78122. name: header,
  78123. data: []
  78124. };
  78125. });
  78126. for (var i = 0; i < tsvLines.length; i++) {
  78127. var items = trim$1(tsvLines[i]).split(itemSplitRegex);
  78128. categories.push(items.shift());
  78129. for (var j = 0; j < items.length; j++) {
  78130. series[j] && (series[j].data[i] = items[j]);
  78131. }
  78132. }
  78133. return {
  78134. series: series,
  78135. categories: categories
  78136. };
  78137. }
  78138. function parseListContents(str) {
  78139. var lines = str.split(/\n+/g);
  78140. var seriesName = trim$1(lines.shift());
  78141. var data = [];
  78142. for (var i = 0; i < lines.length; i++) {
  78143. // if line is empty, ignore it.
  78144. // there is a case that a user forgot to delete `\n`.
  78145. var line = trim$1(lines[i]);
  78146. if (!line) {
  78147. continue;
  78148. }
  78149. var items = line.split(itemSplitRegex);
  78150. var name_1 = '';
  78151. var value = void 0;
  78152. var hasName = false;
  78153. if (isNaN(items[0])) {
  78154. // First item is name
  78155. hasName = true;
  78156. name_1 = items[0];
  78157. items = items.slice(1);
  78158. data[i] = {
  78159. name: name_1,
  78160. value: []
  78161. };
  78162. value = data[i].value;
  78163. } else {
  78164. value = data[i] = [];
  78165. }
  78166. for (var j = 0; j < items.length; j++) {
  78167. value.push(+items[j]);
  78168. }
  78169. if (value.length === 1) {
  78170. hasName ? data[i].value = value[0] : data[i] = value[0];
  78171. }
  78172. }
  78173. return {
  78174. name: seriesName,
  78175. data: data
  78176. };
  78177. }
  78178. function parseContents(str, blockMetaList) {
  78179. var blocks = str.split(new RegExp('\n*' + BLOCK_SPLITER + '\n*', 'g'));
  78180. var newOption = {
  78181. series: []
  78182. };
  78183. each(blocks, function (block, idx) {
  78184. if (isTSVFormat(block)) {
  78185. var result = parseTSVContents(block);
  78186. var blockMeta = blockMetaList[idx];
  78187. var axisKey = blockMeta.axisDim + 'Axis';
  78188. if (blockMeta) {
  78189. newOption[axisKey] = newOption[axisKey] || [];
  78190. newOption[axisKey][blockMeta.axisIndex] = {
  78191. data: result.categories
  78192. };
  78193. newOption.series = newOption.series.concat(result.series);
  78194. }
  78195. } else {
  78196. var result = parseListContents(block);
  78197. newOption.series.push(result);
  78198. }
  78199. });
  78200. return newOption;
  78201. }
  78202. var DataView = /** @class */function (_super) {
  78203. __extends(DataView, _super);
  78204. function DataView() {
  78205. return _super !== null && _super.apply(this, arguments) || this;
  78206. }
  78207. DataView.prototype.onclick = function (ecModel, api) {
  78208. // FIXME: better way?
  78209. setTimeout(function () {
  78210. api.dispatchAction({
  78211. type: 'hideTip'
  78212. });
  78213. });
  78214. var container = api.getDom();
  78215. var model = this.model;
  78216. if (this._dom) {
  78217. container.removeChild(this._dom);
  78218. }
  78219. var root = document.createElement('div');
  78220. // use padding to avoid 5px whitespace
  78221. root.style.cssText = 'position:absolute;top:0;bottom:0;left:0;right:0;padding:5px';
  78222. root.style.backgroundColor = model.get('backgroundColor') || tokens.color.neutral00;
  78223. // Create elements
  78224. var header = document.createElement('h4');
  78225. var lang = model.get('lang') || [];
  78226. header.innerHTML = lang[0] || model.get('title');
  78227. header.style.cssText = 'margin:10px 20px';
  78228. header.style.color = model.get('textColor');
  78229. var viewMain = document.createElement('div');
  78230. var textarea = document.createElement('textarea');
  78231. viewMain.style.cssText = 'overflow:auto';
  78232. var optionToContent = model.get('optionToContent');
  78233. var contentToOption = model.get('contentToOption');
  78234. var result = getContentFromModel(ecModel);
  78235. if (isFunction(optionToContent)) {
  78236. var htmlOrDom = optionToContent(api.getOption());
  78237. if (isString(htmlOrDom)) {
  78238. viewMain.innerHTML = htmlOrDom;
  78239. } else if (isDom(htmlOrDom)) {
  78240. viewMain.appendChild(htmlOrDom);
  78241. }
  78242. } else {
  78243. // Use default textarea
  78244. textarea.readOnly = model.get('readOnly');
  78245. var style = textarea.style;
  78246. // eslint-disable-next-line max-len
  78247. style.cssText = 'display:block;width:100%;height:100%;font-family:monospace;font-size:14px;line-height:1.6rem;resize:none;box-sizing:border-box;outline:none';
  78248. style.color = model.get('textColor');
  78249. style.borderColor = model.get('textareaBorderColor');
  78250. style.backgroundColor = model.get('textareaColor');
  78251. textarea.value = result.value;
  78252. viewMain.appendChild(textarea);
  78253. }
  78254. var blockMetaList = result.meta;
  78255. var buttonContainer = document.createElement('div');
  78256. buttonContainer.style.cssText = 'position:absolute;bottom:5px;left:0;right:0';
  78257. // eslint-disable-next-line max-len
  78258. var buttonStyle = 'float:right;margin-right:20px;border:none;cursor:pointer;padding:2px 5px;font-size:12px;border-radius:3px';
  78259. var closeButton = document.createElement('div');
  78260. var refreshButton = document.createElement('div');
  78261. buttonStyle += ';background-color:' + model.get('buttonColor');
  78262. buttonStyle += ';color:' + model.get('buttonTextColor');
  78263. var self = this;
  78264. function close() {
  78265. container.removeChild(root);
  78266. self._dom = null;
  78267. }
  78268. addEventListener(closeButton, 'click', close);
  78269. addEventListener(refreshButton, 'click', function () {
  78270. if (contentToOption == null && optionToContent != null || contentToOption != null && optionToContent == null) {
  78271. if ("development" !== 'production') {
  78272. // eslint-disable-next-line
  78273. warn('It seems you have just provided one of `contentToOption` and `optionToContent` functions but missed the other one. Data change is ignored.');
  78274. }
  78275. close();
  78276. return;
  78277. }
  78278. var newOption;
  78279. try {
  78280. if (isFunction(contentToOption)) {
  78281. newOption = contentToOption(viewMain, api.getOption());
  78282. } else {
  78283. newOption = parseContents(textarea.value, blockMetaList);
  78284. }
  78285. } catch (e) {
  78286. close();
  78287. throw new Error('Data view format error ' + e);
  78288. }
  78289. if (newOption) {
  78290. api.dispatchAction({
  78291. type: 'changeDataView',
  78292. newOption: newOption
  78293. });
  78294. }
  78295. close();
  78296. });
  78297. closeButton.innerHTML = lang[1];
  78298. refreshButton.innerHTML = lang[2];
  78299. refreshButton.style.cssText = closeButton.style.cssText = buttonStyle;
  78300. !model.get('readOnly') && buttonContainer.appendChild(refreshButton);
  78301. buttonContainer.appendChild(closeButton);
  78302. root.appendChild(header);
  78303. root.appendChild(viewMain);
  78304. root.appendChild(buttonContainer);
  78305. viewMain.style.height = container.clientHeight - 80 + 'px';
  78306. container.appendChild(root);
  78307. this._dom = root;
  78308. };
  78309. DataView.prototype.remove = function (ecModel, api) {
  78310. this._dom && api.getDom().removeChild(this._dom);
  78311. };
  78312. DataView.prototype.dispose = function (ecModel, api) {
  78313. this.remove(ecModel, api);
  78314. };
  78315. DataView.getDefaultOption = function (ecModel) {
  78316. var defaultOption = {
  78317. show: true,
  78318. readOnly: false,
  78319. optionToContent: null,
  78320. contentToOption: null,
  78321. // eslint-disable-next-line
  78322. icon: 'M17.5,17.3H33 M17.5,17.3H33 M45.4,29.5h-28 M11.5,2v56H51V14.8L38.4,2H11.5z M38.4,2.2v12.7H51 M45.4,41.7h-28',
  78323. title: ecModel.getLocaleModel().get(['toolbox', 'dataView', 'title']),
  78324. lang: ecModel.getLocaleModel().get(['toolbox', 'dataView', 'lang']),
  78325. backgroundColor: tokens.color.background,
  78326. textColor: tokens.color.primary,
  78327. textareaColor: tokens.color.background,
  78328. textareaBorderColor: tokens.color.border,
  78329. buttonColor: tokens.color.accent50,
  78330. buttonTextColor: tokens.color.neutral00
  78331. };
  78332. return defaultOption;
  78333. };
  78334. return DataView;
  78335. }(ToolboxFeature);
  78336. /**
  78337. * @inner
  78338. */
  78339. function tryMergeDataOption(newData, originalData) {
  78340. return map(newData, function (newVal, idx) {
  78341. var original = originalData && originalData[idx];
  78342. if (isObject(original) && !isArray(original)) {
  78343. var newValIsObject = isObject(newVal) && !isArray(newVal);
  78344. if (!newValIsObject) {
  78345. newVal = {
  78346. value: newVal
  78347. };
  78348. }
  78349. // original data has name but new data has no name
  78350. var shouldDeleteName = original.name != null && newVal.name == null;
  78351. // Original data has option
  78352. newVal = defaults(newVal, original);
  78353. shouldDeleteName && delete newVal.name;
  78354. return newVal;
  78355. } else {
  78356. return newVal;
  78357. }
  78358. });
  78359. }
  78360. // TODO: SELF REGISTERED.
  78361. registerAction({
  78362. type: 'changeDataView',
  78363. event: 'dataViewChanged',
  78364. update: 'prepareAndUpdate'
  78365. }, function (payload, ecModel) {
  78366. var newSeriesOptList = [];
  78367. each(payload.newOption.series, function (seriesOpt) {
  78368. var seriesModel = ecModel.getSeriesByName(seriesOpt.name)[0];
  78369. if (!seriesModel) {
  78370. // New created series
  78371. // Geuss the series type
  78372. newSeriesOptList.push(extend({
  78373. // Default is scatter
  78374. type: 'scatter'
  78375. }, seriesOpt));
  78376. } else {
  78377. var originalData = seriesModel.get('data');
  78378. newSeriesOptList.push({
  78379. name: seriesOpt.name,
  78380. data: tryMergeDataOption(seriesOpt.data, originalData)
  78381. });
  78382. }
  78383. });
  78384. ecModel.mergeOption(defaults({
  78385. series: newSeriesOptList
  78386. }, payload.newOption));
  78387. });
  78388. var each$9 = each;
  78389. var inner$h = makeInner();
  78390. /**
  78391. * @param ecModel
  78392. * @param newSnapshot key is dataZoomId
  78393. */
  78394. function push(ecModel, newSnapshot) {
  78395. var storedSnapshots = getStoreSnapshots(ecModel);
  78396. // If previous dataZoom can not be found,
  78397. // complete an range with current range.
  78398. each$9(newSnapshot, function (batchItem, dataZoomId) {
  78399. var i = storedSnapshots.length - 1;
  78400. for (; i >= 0; i--) {
  78401. var snapshot = storedSnapshots[i];
  78402. if (snapshot[dataZoomId]) {
  78403. break;
  78404. }
  78405. }
  78406. if (i < 0) {
  78407. // No origin range set, create one by current range.
  78408. var dataZoomModel = ecModel.queryComponents({
  78409. mainType: 'dataZoom',
  78410. subType: 'select',
  78411. id: dataZoomId
  78412. })[0];
  78413. if (dataZoomModel) {
  78414. var percentRange = dataZoomModel.getPercentRange();
  78415. storedSnapshots[0][dataZoomId] = {
  78416. dataZoomId: dataZoomId,
  78417. start: percentRange[0],
  78418. end: percentRange[1]
  78419. };
  78420. }
  78421. }
  78422. });
  78423. storedSnapshots.push(newSnapshot);
  78424. }
  78425. function pop(ecModel) {
  78426. var storedSnapshots = getStoreSnapshots(ecModel);
  78427. var head = storedSnapshots[storedSnapshots.length - 1];
  78428. storedSnapshots.length > 1 && storedSnapshots.pop();
  78429. // Find top for all dataZoom.
  78430. var snapshot = {};
  78431. each$9(head, function (batchItem, dataZoomId) {
  78432. for (var i = storedSnapshots.length - 1; i >= 0; i--) {
  78433. batchItem = storedSnapshots[i][dataZoomId];
  78434. if (batchItem) {
  78435. snapshot[dataZoomId] = batchItem;
  78436. break;
  78437. }
  78438. }
  78439. });
  78440. return snapshot;
  78441. }
  78442. function clear$1(ecModel) {
  78443. inner$h(ecModel).snapshots = null;
  78444. }
  78445. function count(ecModel) {
  78446. return getStoreSnapshots(ecModel).length;
  78447. }
  78448. /**
  78449. * History length of each dataZoom may be different.
  78450. * this._history[0] is used to store origin range.
  78451. */
  78452. function getStoreSnapshots(ecModel) {
  78453. var store = inner$h(ecModel);
  78454. if (!store.snapshots) {
  78455. store.snapshots = [{}];
  78456. }
  78457. return store.snapshots;
  78458. }
  78459. var RestoreOption = /** @class */function (_super) {
  78460. __extends(RestoreOption, _super);
  78461. function RestoreOption() {
  78462. return _super !== null && _super.apply(this, arguments) || this;
  78463. }
  78464. RestoreOption.prototype.onclick = function (ecModel, api) {
  78465. clear$1(ecModel);
  78466. api.dispatchAction({
  78467. type: 'restore',
  78468. from: this.uid
  78469. });
  78470. };
  78471. RestoreOption.getDefaultOption = function (ecModel) {
  78472. var defaultOption = {
  78473. show: true,
  78474. // eslint-disable-next-line
  78475. icon: 'M3.8,33.4 M47,18.9h9.8V8.7 M56.3,20.1 C52.1,9,40.5,0.6,26.8,2.1C12.6,3.7,1.6,16.2,2.1,30.6 M13,41.1H3.1v10.2 M3.7,39.9c4.2,11.1,15.8,19.5,29.5,18 c14.2-1.6,25.2-14.1,24.7-28.5',
  78476. title: ecModel.getLocaleModel().get(['toolbox', 'restore', 'title'])
  78477. };
  78478. return defaultOption;
  78479. };
  78480. return RestoreOption;
  78481. }(ToolboxFeature);
  78482. // TODO: SELF REGISTERED.
  78483. registerAction({
  78484. type: 'restore',
  78485. event: 'restore',
  78486. update: 'prepareAndUpdate'
  78487. }, function (payload, ecModel) {
  78488. ecModel.resetOption('recreate');
  78489. });
  78490. // FIXME
  78491. // how to genarialize to more coordinate systems.
  78492. var INCLUDE_FINDER_MAIN_TYPES = ['grid', 'xAxis', 'yAxis', 'geo', 'graph', 'polar', 'radiusAxis', 'angleAxis', 'bmap'];
  78493. var BrushTargetManager = /** @class */function () {
  78494. /**
  78495. * @param finder contains Index/Id/Name of xAxis/yAxis/geo/grid
  78496. * Each can be {number|Array.<number>}. like: {xAxisIndex: [3, 4]}
  78497. * @param opt.include include coordinate system types.
  78498. */
  78499. function BrushTargetManager(finder, ecModel, opt) {
  78500. var _this = this;
  78501. this._targetInfoList = [];
  78502. var foundCpts = parseFinder$1(ecModel, finder);
  78503. each(targetInfoBuilders, function (builder, type) {
  78504. if (!opt || !opt.include || indexOf(opt.include, type) >= 0) {
  78505. builder(foundCpts, _this._targetInfoList);
  78506. }
  78507. });
  78508. }
  78509. BrushTargetManager.prototype.setOutputRanges = function (areas, ecModel) {
  78510. this.matchOutputRanges(areas, ecModel, function (area, coordRange, coordSys) {
  78511. (area.coordRanges || (area.coordRanges = [])).push(coordRange);
  78512. // area.coordRange is the first of area.coordRanges
  78513. if (!area.coordRange) {
  78514. area.coordRange = coordRange;
  78515. // In 'category' axis, coord to pixel is not reversible, so we can not
  78516. // rebuild range by coordRange accrately, which may bring trouble when
  78517. // brushing only one item. So we use __rangeOffset to rebuilding range
  78518. // by coordRange. And this it only used in brush component so it is no
  78519. // need to be adapted to coordRanges.
  78520. var result = coordConvert[area.brushType](0, coordSys, coordRange);
  78521. area.__rangeOffset = {
  78522. offset: diffProcessor[area.brushType](result.values, area.range, [1, 1]),
  78523. xyMinMax: result.xyMinMax
  78524. };
  78525. }
  78526. });
  78527. return areas;
  78528. };
  78529. BrushTargetManager.prototype.matchOutputRanges = function (areas, ecModel, cb) {
  78530. each(areas, function (area) {
  78531. var targetInfo = this.findTargetInfo(area, ecModel);
  78532. if (targetInfo && targetInfo !== true) {
  78533. each(targetInfo.coordSyses, function (coordSys) {
  78534. var result = coordConvert[area.brushType](1, coordSys, area.range, true);
  78535. cb(area, result.values, coordSys, ecModel);
  78536. });
  78537. }
  78538. }, this);
  78539. };
  78540. /**
  78541. * the `areas` is `BrushModel.areas`.
  78542. * Called in layout stage.
  78543. * convert `area.coordRange` to global range and set panelId to `area.range`.
  78544. */
  78545. BrushTargetManager.prototype.setInputRanges = function (areas, ecModel) {
  78546. each(areas, function (area) {
  78547. var targetInfo = this.findTargetInfo(area, ecModel);
  78548. if ("development" !== 'production') {
  78549. assert(!targetInfo || targetInfo === true || area.coordRange, 'coordRange must be specified when coord index specified.');
  78550. assert(!targetInfo || targetInfo !== true || area.range, 'range must be specified in global brush.');
  78551. }
  78552. area.range = area.range || [];
  78553. // convert coordRange to global range and set panelId.
  78554. if (targetInfo && targetInfo !== true) {
  78555. area.panelId = targetInfo.panelId;
  78556. // (1) area.range should always be calculate from coordRange but does
  78557. // not keep its original value, for the sake of the dataZoom scenario,
  78558. // where area.coordRange remains unchanged but area.range may be changed.
  78559. // (2) Only support converting one coordRange to pixel range in brush
  78560. // component. So do not consider `coordRanges`.
  78561. // (3) About __rangeOffset, see comment above.
  78562. var result = coordConvert[area.brushType](0, targetInfo.coordSys, area.coordRange);
  78563. var rangeOffset = area.__rangeOffset;
  78564. area.range = rangeOffset ? diffProcessor[area.brushType](result.values, rangeOffset.offset, getScales(result.xyMinMax, rangeOffset.xyMinMax)) : result.values;
  78565. }
  78566. }, this);
  78567. };
  78568. BrushTargetManager.prototype.makePanelOpts = function (api, getDefaultBrushType) {
  78569. return map(this._targetInfoList, function (targetInfo) {
  78570. var rect = targetInfo.getPanelRect();
  78571. return {
  78572. panelId: targetInfo.panelId,
  78573. defaultBrushType: getDefaultBrushType ? getDefaultBrushType(targetInfo) : null,
  78574. clipPath: makeRectPanelClipPath(rect),
  78575. isTargetByCursor: makeRectIsTargetByCursor(rect, api, targetInfo.coordSysModel),
  78576. getLinearBrushOtherExtent: makeLinearBrushOtherExtent(rect)
  78577. };
  78578. });
  78579. };
  78580. BrushTargetManager.prototype.controlSeries = function (area, seriesModel, ecModel) {
  78581. // Check whether area is bound in coord, and series do not belong to that coord.
  78582. // If do not do this check, some brush (like lineX) will controll all axes.
  78583. var targetInfo = this.findTargetInfo(area, ecModel);
  78584. return targetInfo === true || targetInfo && indexOf(targetInfo.coordSyses, seriesModel.coordinateSystem) >= 0;
  78585. };
  78586. /**
  78587. * If return Object, a coord found.
  78588. * If return true, global found.
  78589. * Otherwise nothing found.
  78590. */
  78591. BrushTargetManager.prototype.findTargetInfo = function (area, ecModel) {
  78592. var targetInfoList = this._targetInfoList;
  78593. var foundCpts = parseFinder$1(ecModel, area);
  78594. for (var i = 0; i < targetInfoList.length; i++) {
  78595. var targetInfo = targetInfoList[i];
  78596. var areaPanelId = area.panelId;
  78597. if (areaPanelId) {
  78598. if (targetInfo.panelId === areaPanelId) {
  78599. return targetInfo;
  78600. }
  78601. } else {
  78602. for (var j = 0; j < targetInfoMatchers.length; j++) {
  78603. if (targetInfoMatchers[j](foundCpts, targetInfo)) {
  78604. return targetInfo;
  78605. }
  78606. }
  78607. }
  78608. }
  78609. return true;
  78610. };
  78611. return BrushTargetManager;
  78612. }();
  78613. function formatMinMax(minMax) {
  78614. minMax[0] > minMax[1] && minMax.reverse();
  78615. return minMax;
  78616. }
  78617. function parseFinder$1(ecModel, finder) {
  78618. return parseFinder(ecModel, finder, {
  78619. includeMainTypes: INCLUDE_FINDER_MAIN_TYPES
  78620. });
  78621. }
  78622. var targetInfoBuilders = {
  78623. grid: function (foundCpts, targetInfoList) {
  78624. var xAxisModels = foundCpts.xAxisModels;
  78625. var yAxisModels = foundCpts.yAxisModels;
  78626. var gridModels = foundCpts.gridModels;
  78627. // Remove duplicated.
  78628. var gridModelMap = createHashMap();
  78629. var xAxesHas = {};
  78630. var yAxesHas = {};
  78631. if (!xAxisModels && !yAxisModels && !gridModels) {
  78632. return;
  78633. }
  78634. each(xAxisModels, function (axisModel) {
  78635. var gridModel = axisModel.axis.grid.model;
  78636. gridModelMap.set(gridModel.id, gridModel);
  78637. xAxesHas[gridModel.id] = true;
  78638. });
  78639. each(yAxisModels, function (axisModel) {
  78640. var gridModel = axisModel.axis.grid.model;
  78641. gridModelMap.set(gridModel.id, gridModel);
  78642. yAxesHas[gridModel.id] = true;
  78643. });
  78644. each(gridModels, function (gridModel) {
  78645. gridModelMap.set(gridModel.id, gridModel);
  78646. xAxesHas[gridModel.id] = true;
  78647. yAxesHas[gridModel.id] = true;
  78648. });
  78649. gridModelMap.each(function (gridModel) {
  78650. var grid = gridModel.coordinateSystem;
  78651. var cartesians = [];
  78652. each(grid.getCartesians(), function (cartesian, index) {
  78653. if (indexOf(xAxisModels, cartesian.getAxis('x').model) >= 0 || indexOf(yAxisModels, cartesian.getAxis('y').model) >= 0) {
  78654. cartesians.push(cartesian);
  78655. }
  78656. });
  78657. targetInfoList.push({
  78658. panelId: 'grid--' + gridModel.id,
  78659. gridModel: gridModel,
  78660. coordSysModel: gridModel,
  78661. // Use the first one as the representitive coordSys.
  78662. coordSys: cartesians[0],
  78663. coordSyses: cartesians,
  78664. getPanelRect: panelRectBuilders.grid,
  78665. xAxisDeclared: xAxesHas[gridModel.id],
  78666. yAxisDeclared: yAxesHas[gridModel.id]
  78667. });
  78668. });
  78669. },
  78670. geo: function (foundCpts, targetInfoList) {
  78671. each(foundCpts.geoModels, function (geoModel) {
  78672. var coordSys = geoModel.coordinateSystem;
  78673. targetInfoList.push({
  78674. panelId: 'geo--' + geoModel.id,
  78675. geoModel: geoModel,
  78676. coordSysModel: geoModel,
  78677. coordSys: coordSys,
  78678. coordSyses: [coordSys],
  78679. getPanelRect: panelRectBuilders.geo
  78680. });
  78681. });
  78682. }
  78683. };
  78684. var targetInfoMatchers = [
  78685. // grid
  78686. function (foundCpts, targetInfo) {
  78687. var xAxisModel = foundCpts.xAxisModel;
  78688. var yAxisModel = foundCpts.yAxisModel;
  78689. var gridModel = foundCpts.gridModel;
  78690. !gridModel && xAxisModel && (gridModel = xAxisModel.axis.grid.model);
  78691. !gridModel && yAxisModel && (gridModel = yAxisModel.axis.grid.model);
  78692. return gridModel && gridModel === targetInfo.gridModel;
  78693. },
  78694. // geo
  78695. function (foundCpts, targetInfo) {
  78696. var geoModel = foundCpts.geoModel;
  78697. return geoModel && geoModel === targetInfo.geoModel;
  78698. }];
  78699. var panelRectBuilders = {
  78700. grid: function () {
  78701. // grid is not Transformable.
  78702. return this.coordSys.master.getRect().clone();
  78703. },
  78704. geo: function () {
  78705. var coordSys = this.coordSys;
  78706. var rect = coordSys.getBoundingRect().clone();
  78707. // geo roam and zoom transform
  78708. rect.applyTransform(getTransform(coordSys));
  78709. return rect;
  78710. }
  78711. };
  78712. var coordConvert = {
  78713. lineX: curry(axisConvert, 0),
  78714. lineY: curry(axisConvert, 1),
  78715. rect: function (to, coordSys, rangeOrCoordRange, clamp) {
  78716. var xminymin = to ? coordSys.pointToData([rangeOrCoordRange[0][0], rangeOrCoordRange[1][0]], clamp) : coordSys.dataToPoint([rangeOrCoordRange[0][0], rangeOrCoordRange[1][0]], clamp);
  78717. var xmaxymax = to ? coordSys.pointToData([rangeOrCoordRange[0][1], rangeOrCoordRange[1][1]], clamp) : coordSys.dataToPoint([rangeOrCoordRange[0][1], rangeOrCoordRange[1][1]], clamp);
  78718. var values = [formatMinMax([xminymin[0], xmaxymax[0]]), formatMinMax([xminymin[1], xmaxymax[1]])];
  78719. return {
  78720. values: values,
  78721. xyMinMax: values
  78722. };
  78723. },
  78724. polygon: function (to, coordSys, rangeOrCoordRange, clamp) {
  78725. var xyMinMax = [[Infinity, -Infinity], [Infinity, -Infinity]];
  78726. var values = map(rangeOrCoordRange, function (item) {
  78727. var p = to ? coordSys.pointToData(item, clamp) : coordSys.dataToPoint(item, clamp);
  78728. xyMinMax[0][0] = Math.min(xyMinMax[0][0], p[0]);
  78729. xyMinMax[1][0] = Math.min(xyMinMax[1][0], p[1]);
  78730. xyMinMax[0][1] = Math.max(xyMinMax[0][1], p[0]);
  78731. xyMinMax[1][1] = Math.max(xyMinMax[1][1], p[1]);
  78732. return p;
  78733. });
  78734. return {
  78735. values: values,
  78736. xyMinMax: xyMinMax
  78737. };
  78738. }
  78739. };
  78740. function axisConvert(axisNameIndex, to, coordSys, rangeOrCoordRange) {
  78741. if ("development" !== 'production') {
  78742. assert(coordSys.type === 'cartesian2d', 'lineX/lineY brush is available only in cartesian2d.');
  78743. }
  78744. var axis = coordSys.getAxis(['x', 'y'][axisNameIndex]);
  78745. var values = formatMinMax(map([0, 1], function (i) {
  78746. return to ? axis.coordToData(axis.toLocalCoord(rangeOrCoordRange[i]), true) : axis.toGlobalCoord(axis.dataToCoord(rangeOrCoordRange[i]));
  78747. }));
  78748. var xyMinMax = [];
  78749. xyMinMax[axisNameIndex] = values;
  78750. xyMinMax[1 - axisNameIndex] = [NaN, NaN];
  78751. return {
  78752. values: values,
  78753. xyMinMax: xyMinMax
  78754. };
  78755. }
  78756. var diffProcessor = {
  78757. lineX: curry(axisDiffProcessor, 0),
  78758. lineY: curry(axisDiffProcessor, 1),
  78759. rect: function (values, refer, scales) {
  78760. return [[values[0][0] - scales[0] * refer[0][0], values[0][1] - scales[0] * refer[0][1]], [values[1][0] - scales[1] * refer[1][0], values[1][1] - scales[1] * refer[1][1]]];
  78761. },
  78762. polygon: function (values, refer, scales) {
  78763. return map(values, function (item, idx) {
  78764. return [item[0] - scales[0] * refer[idx][0], item[1] - scales[1] * refer[idx][1]];
  78765. });
  78766. }
  78767. };
  78768. function axisDiffProcessor(axisNameIndex, values, refer, scales) {
  78769. return [values[0] - scales[axisNameIndex] * refer[0], values[1] - scales[axisNameIndex] * refer[1]];
  78770. }
  78771. // We have to process scale caused by dataZoom manually,
  78772. // although it might be not accurate.
  78773. // Return [0~1, 0~1]
  78774. function getScales(xyMinMaxCurr, xyMinMaxOrigin) {
  78775. var sizeCurr = getSize$1(xyMinMaxCurr);
  78776. var sizeOrigin = getSize$1(xyMinMaxOrigin);
  78777. var scales = [sizeCurr[0] / sizeOrigin[0], sizeCurr[1] / sizeOrigin[1]];
  78778. isNaN(scales[0]) && (scales[0] = 1);
  78779. isNaN(scales[1]) && (scales[1] = 1);
  78780. return scales;
  78781. }
  78782. function getSize$1(xyMinMax) {
  78783. return xyMinMax ? [xyMinMax[0][1] - xyMinMax[0][0], xyMinMax[1][1] - xyMinMax[1][0]] : [NaN, NaN];
  78784. }
  78785. var each$a = each;
  78786. var DATA_ZOOM_ID_BASE = makeInternalComponentId('toolbox-dataZoom_');
  78787. var DataZoomFeature = /** @class */function (_super) {
  78788. __extends(DataZoomFeature, _super);
  78789. function DataZoomFeature() {
  78790. return _super !== null && _super.apply(this, arguments) || this;
  78791. }
  78792. DataZoomFeature.prototype.render = function (featureModel, ecModel, api, payload) {
  78793. if (!this._brushController) {
  78794. this._brushController = new BrushController(api.getZr());
  78795. this._brushController.on('brush', bind(this._onBrush, this)).mount();
  78796. }
  78797. updateZoomBtnStatus(featureModel, ecModel, this, payload, api);
  78798. updateBackBtnStatus(featureModel, ecModel);
  78799. };
  78800. DataZoomFeature.prototype.onclick = function (ecModel, api, type) {
  78801. handlers$1[type].call(this);
  78802. };
  78803. DataZoomFeature.prototype.remove = function (ecModel, api) {
  78804. this._brushController && this._brushController.unmount();
  78805. };
  78806. DataZoomFeature.prototype.dispose = function (ecModel, api) {
  78807. this._brushController && this._brushController.dispose();
  78808. };
  78809. DataZoomFeature.prototype._onBrush = function (eventParam) {
  78810. var areas = eventParam.areas;
  78811. if (!eventParam.isEnd || !areas.length) {
  78812. return;
  78813. }
  78814. var snapshot = {};
  78815. var ecModel = this.ecModel;
  78816. this._brushController.updateCovers([]); // remove cover
  78817. var brushTargetManager = new BrushTargetManager(makeAxisFinder(this.model), ecModel, {
  78818. include: ['grid']
  78819. });
  78820. brushTargetManager.matchOutputRanges(areas, ecModel, function (area, coordRange, coordSys) {
  78821. if (coordSys.type !== 'cartesian2d') {
  78822. return;
  78823. }
  78824. var brushType = area.brushType;
  78825. if (brushType === 'rect') {
  78826. setBatch('x', coordSys, coordRange[0]);
  78827. setBatch('y', coordSys, coordRange[1]);
  78828. } else {
  78829. setBatch({
  78830. lineX: 'x',
  78831. lineY: 'y'
  78832. }[brushType], coordSys, coordRange);
  78833. }
  78834. });
  78835. push(ecModel, snapshot);
  78836. this._dispatchZoomAction(snapshot);
  78837. function setBatch(dimName, coordSys, minMax) {
  78838. var axis = coordSys.getAxis(dimName);
  78839. var axisModel = axis.model;
  78840. var dataZoomModel = findDataZoom(dimName, axisModel, ecModel);
  78841. // Restrict range.
  78842. var minMaxSpan = dataZoomModel.findRepresentativeAxisProxy(axisModel).getMinMaxSpan();
  78843. if (minMaxSpan.minValueSpan != null || minMaxSpan.maxValueSpan != null) {
  78844. minMax = sliderMove(0, minMax.slice(), axis.scale.getExtent(), 0, minMaxSpan.minValueSpan, minMaxSpan.maxValueSpan);
  78845. }
  78846. dataZoomModel && (snapshot[dataZoomModel.id] = {
  78847. dataZoomId: dataZoomModel.id,
  78848. startValue: minMax[0],
  78849. endValue: minMax[1]
  78850. });
  78851. }
  78852. function findDataZoom(dimName, axisModel, ecModel) {
  78853. var found;
  78854. ecModel.eachComponent({
  78855. mainType: 'dataZoom',
  78856. subType: 'select'
  78857. }, function (dzModel) {
  78858. var has = dzModel.getAxisModel(dimName, axisModel.componentIndex);
  78859. has && (found = dzModel);
  78860. });
  78861. return found;
  78862. }
  78863. };
  78864. DataZoomFeature.prototype._dispatchZoomAction = function (snapshot) {
  78865. var batch = [];
  78866. // Convert from hash map to array.
  78867. each$a(snapshot, function (batchItem, dataZoomId) {
  78868. batch.push(clone(batchItem));
  78869. });
  78870. batch.length && this.api.dispatchAction({
  78871. type: 'dataZoom',
  78872. from: this.uid,
  78873. batch: batch
  78874. });
  78875. };
  78876. DataZoomFeature.getDefaultOption = function (ecModel) {
  78877. var defaultOption = {
  78878. show: true,
  78879. filterMode: 'filter',
  78880. // Icon group
  78881. icon: {
  78882. zoom: 'M0,13.5h26.9 M13.5,26.9V0 M32.1,13.5H58V58H13.5 V32.1',
  78883. back: 'M22,1.4L9.9,13.5l12.3,12.3 M10.3,13.5H54.9v44.6 H10.3v-26'
  78884. },
  78885. // `zoom`, `back`
  78886. title: ecModel.getLocaleModel().get(['toolbox', 'dataZoom', 'title']),
  78887. brushStyle: {
  78888. borderWidth: 0,
  78889. color: tokens.color.backgroundTint
  78890. }
  78891. };
  78892. return defaultOption;
  78893. };
  78894. return DataZoomFeature;
  78895. }(ToolboxFeature);
  78896. var handlers$1 = {
  78897. zoom: function () {
  78898. var nextActive = !this._isZoomActive;
  78899. this.api.dispatchAction({
  78900. type: 'takeGlobalCursor',
  78901. key: 'dataZoomSelect',
  78902. dataZoomSelectActive: nextActive
  78903. });
  78904. },
  78905. back: function () {
  78906. this._dispatchZoomAction(pop(this.ecModel));
  78907. }
  78908. };
  78909. function makeAxisFinder(dzFeatureModel) {
  78910. var setting = {
  78911. xAxisIndex: dzFeatureModel.get('xAxisIndex', true),
  78912. yAxisIndex: dzFeatureModel.get('yAxisIndex', true),
  78913. xAxisId: dzFeatureModel.get('xAxisId', true),
  78914. yAxisId: dzFeatureModel.get('yAxisId', true)
  78915. };
  78916. // If both `xAxisIndex` `xAxisId` not set, it means 'all'.
  78917. // If both `yAxisIndex` `yAxisId` not set, it means 'all'.
  78918. // Some old cases set like this below to close yAxis control but leave xAxis control:
  78919. // `{ feature: { dataZoom: { yAxisIndex: false } }`.
  78920. if (setting.xAxisIndex == null && setting.xAxisId == null) {
  78921. setting.xAxisIndex = 'all';
  78922. }
  78923. if (setting.yAxisIndex == null && setting.yAxisId == null) {
  78924. setting.yAxisIndex = 'all';
  78925. }
  78926. return setting;
  78927. }
  78928. function updateBackBtnStatus(featureModel, ecModel) {
  78929. featureModel.setIconStatus('back', count(ecModel) > 1 ? 'emphasis' : 'normal');
  78930. }
  78931. function updateZoomBtnStatus(featureModel, ecModel, view, payload, api) {
  78932. var zoomActive = view._isZoomActive;
  78933. if (payload && payload.type === 'takeGlobalCursor') {
  78934. zoomActive = payload.key === 'dataZoomSelect' ? payload.dataZoomSelectActive : false;
  78935. }
  78936. view._isZoomActive = zoomActive;
  78937. featureModel.setIconStatus('zoom', zoomActive ? 'emphasis' : 'normal');
  78938. var brushTargetManager = new BrushTargetManager(makeAxisFinder(featureModel), ecModel, {
  78939. include: ['grid']
  78940. });
  78941. var panels = brushTargetManager.makePanelOpts(api, function (targetInfo) {
  78942. return targetInfo.xAxisDeclared && !targetInfo.yAxisDeclared ? 'lineX' : !targetInfo.xAxisDeclared && targetInfo.yAxisDeclared ? 'lineY' : 'rect';
  78943. });
  78944. view._brushController.setPanels(panels).enableBrush(zoomActive && panels.length ? {
  78945. brushType: 'auto',
  78946. brushStyle: featureModel.getModel('brushStyle').getItemStyle()
  78947. } : false);
  78948. }
  78949. registerInternalOptionCreator('dataZoom', function (ecModel) {
  78950. var toolboxModel = ecModel.getComponent('toolbox', 0);
  78951. var featureDataZoomPath = ['feature', 'dataZoom'];
  78952. if (!toolboxModel || toolboxModel.get(featureDataZoomPath) == null) {
  78953. return;
  78954. }
  78955. var dzFeatureModel = toolboxModel.getModel(featureDataZoomPath);
  78956. var dzOptions = [];
  78957. var finder = makeAxisFinder(dzFeatureModel);
  78958. var finderResult = parseFinder(ecModel, finder);
  78959. each$a(finderResult.xAxisModels, function (axisModel) {
  78960. return buildInternalOptions(axisModel, 'xAxis', 'xAxisIndex');
  78961. });
  78962. each$a(finderResult.yAxisModels, function (axisModel) {
  78963. return buildInternalOptions(axisModel, 'yAxis', 'yAxisIndex');
  78964. });
  78965. function buildInternalOptions(axisModel, axisMainType, axisIndexPropName) {
  78966. var axisIndex = axisModel.componentIndex;
  78967. var newOpt = {
  78968. type: 'select',
  78969. $fromToolbox: true,
  78970. // Default to be filter
  78971. filterMode: dzFeatureModel.get('filterMode', true) || 'filter',
  78972. // Id for merge mapping.
  78973. id: DATA_ZOOM_ID_BASE + axisMainType + axisIndex
  78974. };
  78975. newOpt[axisIndexPropName] = axisIndex;
  78976. dzOptions.push(newOpt);
  78977. }
  78978. return dzOptions;
  78979. });
  78980. function install$B(registers) {
  78981. registers.registerComponentModel(ToolboxModel);
  78982. registers.registerComponentView(ToolboxView);
  78983. registerFeature('saveAsImage', SaveAsImage);
  78984. registerFeature('magicType', MagicType);
  78985. registerFeature('dataView', DataView);
  78986. registerFeature('dataZoom', DataZoomFeature);
  78987. registerFeature('restore', RestoreOption);
  78988. use(install$A);
  78989. }
  78990. var TooltipModel = /** @class */function (_super) {
  78991. __extends(TooltipModel, _super);
  78992. function TooltipModel() {
  78993. var _this = _super !== null && _super.apply(this, arguments) || this;
  78994. _this.type = TooltipModel.type;
  78995. return _this;
  78996. }
  78997. TooltipModel.type = 'tooltip';
  78998. TooltipModel.dependencies = ['axisPointer'];
  78999. TooltipModel.defaultOption = {
  79000. // zlevel: 0,
  79001. z: 60,
  79002. show: true,
  79003. // tooltip main content
  79004. showContent: true,
  79005. // 'trigger' only works on coordinate system.
  79006. // 'item' | 'axis' | 'none'
  79007. trigger: 'item',
  79008. // 'click' | 'mousemove' | 'none'
  79009. triggerOn: 'mousemove|click',
  79010. alwaysShowContent: false,
  79011. renderMode: 'auto',
  79012. // whether restraint content inside viewRect.
  79013. // If renderMode: 'richText', default true.
  79014. // If renderMode: 'html', defaults to `false` (for backward compat).
  79015. confine: null,
  79016. showDelay: 0,
  79017. hideDelay: 100,
  79018. // Animation transition time, unit is second
  79019. transitionDuration: 0.4,
  79020. displayTransition: true,
  79021. enterable: false,
  79022. backgroundColor: tokens.color.neutral00,
  79023. // box shadow
  79024. shadowBlur: 10,
  79025. shadowColor: 'rgba(0, 0, 0, .2)',
  79026. shadowOffsetX: 1,
  79027. shadowOffsetY: 2,
  79028. // tooltip border radius, unit is px, default is 4
  79029. borderRadius: 4,
  79030. // tooltip border width, unit is px, default is 0 (no border)
  79031. borderWidth: 1,
  79032. defaultBorderColor: tokens.color.border,
  79033. // Tooltip inside padding, default is 5 for all direction
  79034. // Array is allowed to set up, right, bottom, left, same with css
  79035. // The default value: See `tooltip/tooltipMarkup.ts#getPaddingFromTooltipModel`.
  79036. padding: null,
  79037. // Extra css text
  79038. extraCssText: '',
  79039. // axis indicator, trigger by axis
  79040. axisPointer: {
  79041. // default is line
  79042. // legal values: 'line' | 'shadow' | 'cross'
  79043. type: 'line',
  79044. // Valid when type is line, appoint tooltip line locate on which line. Optional
  79045. // legal values: 'x' | 'y' | 'angle' | 'radius' | 'auto'
  79046. // default is 'auto', chose the axis which type is category.
  79047. // for multiply y axis, cartesian coord chose x axis, polar chose angle axis
  79048. axis: 'auto',
  79049. animation: 'auto',
  79050. animationDurationUpdate: 200,
  79051. animationEasingUpdate: 'exponentialOut',
  79052. crossStyle: {
  79053. color: tokens.color.borderShade,
  79054. width: 1,
  79055. type: 'dashed',
  79056. // TODO formatter
  79057. textStyle: {}
  79058. }
  79059. // lineStyle and shadowStyle should not be specified here,
  79060. // otherwise it will always override those styles on option.axisPointer.
  79061. },
  79062. textStyle: {
  79063. color: tokens.color.tertiary,
  79064. fontSize: 14
  79065. }
  79066. };
  79067. return TooltipModel;
  79068. }(ComponentModel);
  79069. /* global document */
  79070. function shouldTooltipConfine(tooltipModel) {
  79071. var confineOption = tooltipModel.get('confine');
  79072. return confineOption != null ? !!confineOption
  79073. // In richText mode, the outside part can not be visible.
  79074. : tooltipModel.get('renderMode') === 'richText';
  79075. }
  79076. function testStyle(styleProps) {
  79077. if (!env.domSupported) {
  79078. return;
  79079. }
  79080. var style = document.documentElement.style;
  79081. for (var i = 0, len = styleProps.length; i < len; i++) {
  79082. if (styleProps[i] in style) {
  79083. return styleProps[i];
  79084. }
  79085. }
  79086. }
  79087. var TRANSFORM_VENDOR = testStyle(['transform', 'webkitTransform', 'OTransform', 'MozTransform', 'msTransform']);
  79088. var TRANSITION_VENDOR = testStyle(['webkitTransition', 'transition', 'OTransition', 'MozTransition', 'msTransition']);
  79089. function toCSSVendorPrefix(styleVendor, styleProp) {
  79090. if (!styleVendor) {
  79091. return styleProp;
  79092. }
  79093. styleProp = toCamelCase(styleProp, true);
  79094. var idx = styleVendor.indexOf(styleProp);
  79095. styleVendor = idx === -1 ? styleProp : "-" + styleVendor.slice(0, idx) + "-" + styleProp;
  79096. return styleVendor.toLowerCase();
  79097. }
  79098. function getComputedStyle(el, style) {
  79099. var stl = el.currentStyle || document.defaultView && document.defaultView.getComputedStyle(el);
  79100. return stl ? style ? stl[style] : stl : null;
  79101. }
  79102. /* global document, window */
  79103. var CSS_TRANSITION_VENDOR = toCSSVendorPrefix(TRANSITION_VENDOR, 'transition');
  79104. var CSS_TRANSFORM_VENDOR = toCSSVendorPrefix(TRANSFORM_VENDOR, 'transform');
  79105. // eslint-disable-next-line
  79106. var gCssText = "position:absolute;display:block;border-style:solid;white-space:nowrap;z-index:9999999;" + (env.transform3dSupported ? 'will-change:transform;' : '');
  79107. function mirrorPos(pos) {
  79108. pos = pos === 'left' ? 'right' : pos === 'right' ? 'left' : pos === 'top' ? 'bottom' : 'top';
  79109. return pos;
  79110. }
  79111. function assembleArrow(tooltipModel, borderColor, arrowPosition) {
  79112. if (!isString(arrowPosition) || arrowPosition === 'inside') {
  79113. return '';
  79114. }
  79115. var backgroundColor = tooltipModel.get('backgroundColor');
  79116. var borderWidth = tooltipModel.get('borderWidth');
  79117. borderColor = convertToColorString(borderColor);
  79118. var arrowPos = mirrorPos(arrowPosition);
  79119. var arrowSize = Math.max(Math.round(borderWidth) * 1.5, 6);
  79120. var positionStyle = '';
  79121. var transformStyle = CSS_TRANSFORM_VENDOR + ':';
  79122. var rotateDeg;
  79123. if (indexOf(['left', 'right'], arrowPos) > -1) {
  79124. positionStyle += 'top:50%';
  79125. transformStyle += "translateY(-50%) rotate(" + (rotateDeg = arrowPos === 'left' ? -225 : -45) + "deg)";
  79126. } else {
  79127. positionStyle += 'left:50%';
  79128. transformStyle += "translateX(-50%) rotate(" + (rotateDeg = arrowPos === 'top' ? 225 : 45) + "deg)";
  79129. }
  79130. var rotateRadian = rotateDeg * Math.PI / 180;
  79131. var arrowWH = arrowSize + borderWidth;
  79132. var rotatedWH = arrowWH * Math.abs(Math.cos(rotateRadian)) + arrowWH * Math.abs(Math.sin(rotateRadian));
  79133. var arrowOffset = Math.round(((rotatedWH - Math.SQRT2 * borderWidth) / 2 + Math.SQRT2 * borderWidth - (rotatedWH - arrowWH) / 2) * 100) / 100;
  79134. positionStyle += ";" + arrowPos + ":-" + arrowOffset + "px";
  79135. var borderStyle = borderColor + " solid " + borderWidth + "px;";
  79136. var styleCss = ["position:absolute;width:" + arrowSize + "px;height:" + arrowSize + "px;z-index:-1;", positionStyle + ";" + transformStyle + ";", "border-bottom:" + borderStyle, "border-right:" + borderStyle, "background-color:" + backgroundColor + ";"];
  79137. return "<div style=\"" + styleCss.join('') + "\"></div>";
  79138. }
  79139. function assembleTransition(duration, onlyFadeTransition, enableDisplayTransition) {
  79140. var transitionCurve = 'cubic-bezier(0.23,1,0.32,1)';
  79141. var transitionOption = '';
  79142. var transitionText = '';
  79143. if (enableDisplayTransition) {
  79144. transitionOption = " " + duration / 2 + "s " + transitionCurve;
  79145. transitionText = "opacity" + transitionOption + ",visibility" + transitionOption;
  79146. }
  79147. if (!onlyFadeTransition) {
  79148. transitionOption = " " + duration + "s " + transitionCurve;
  79149. transitionText += (transitionText.length ? ',' : '') + (env.transformSupported ? "" + CSS_TRANSFORM_VENDOR + transitionOption : ",left" + transitionOption + ",top" + transitionOption);
  79150. }
  79151. return CSS_TRANSITION_VENDOR + ':' + transitionText;
  79152. }
  79153. function assembleTransform(x, y, toString) {
  79154. // If using float on style, the final width of the dom might
  79155. // keep changing slightly while mouse move. So `toFixed(0)` them.
  79156. var x0 = x.toFixed(0) + 'px';
  79157. var y0 = y.toFixed(0) + 'px';
  79158. // not support transform, use `left` and `top` instead.
  79159. if (!env.transformSupported) {
  79160. return toString ? "top:" + y0 + ";left:" + x0 + ";" : [['top', y0], ['left', x0]];
  79161. }
  79162. // support transform
  79163. var is3d = env.transform3dSupported;
  79164. var translate = "translate" + (is3d ? '3d' : '') + "(" + x0 + "," + y0 + (is3d ? ',0' : '') + ")";
  79165. return toString ? 'top:0;left:0;' + CSS_TRANSFORM_VENDOR + ':' + translate + ';' : [['top', 0], ['left', 0], [TRANSFORM_VENDOR, translate]];
  79166. }
  79167. /**
  79168. * @param {Object} textStyle
  79169. * @return {string}
  79170. * @inner
  79171. */
  79172. function assembleFont(textStyleModel) {
  79173. var cssText = [];
  79174. var fontSize = textStyleModel.get('fontSize');
  79175. var color = textStyleModel.getTextColor();
  79176. color && cssText.push('color:' + color);
  79177. cssText.push('font:' + textStyleModel.getFont());
  79178. // @ts-ignore, leave it to the tooltip refactor.
  79179. var lineHeight = retrieve2(textStyleModel.get('lineHeight'), Math.round(fontSize * 3 / 2));
  79180. fontSize && cssText.push('line-height:' + lineHeight + 'px');
  79181. var shadowColor = textStyleModel.get('textShadowColor');
  79182. var shadowBlur = textStyleModel.get('textShadowBlur') || 0;
  79183. var shadowOffsetX = textStyleModel.get('textShadowOffsetX') || 0;
  79184. var shadowOffsetY = textStyleModel.get('textShadowOffsetY') || 0;
  79185. shadowColor && shadowBlur && cssText.push('text-shadow:' + shadowOffsetX + 'px ' + shadowOffsetY + 'px ' + shadowBlur + 'px ' + shadowColor);
  79186. each(['decoration', 'align'], function (name) {
  79187. var val = textStyleModel.get(name);
  79188. val && cssText.push('text-' + name + ':' + val);
  79189. });
  79190. return cssText.join(';');
  79191. }
  79192. function assembleCssText(tooltipModel, enableTransition, onlyFadeTransition, enableDisplayTransition) {
  79193. var cssText = [];
  79194. var transitionDuration = tooltipModel.get('transitionDuration');
  79195. var backgroundColor = tooltipModel.get('backgroundColor');
  79196. var shadowBlur = tooltipModel.get('shadowBlur');
  79197. var shadowColor = tooltipModel.get('shadowColor');
  79198. var shadowOffsetX = tooltipModel.get('shadowOffsetX');
  79199. var shadowOffsetY = tooltipModel.get('shadowOffsetY');
  79200. var textStyleModel = tooltipModel.getModel('textStyle');
  79201. var padding = getPaddingFromTooltipModel(tooltipModel, 'html');
  79202. var boxShadow = shadowOffsetX + "px " + shadowOffsetY + "px " + shadowBlur + "px " + shadowColor;
  79203. cssText.push('box-shadow:' + boxShadow);
  79204. // Animation transition. Do not animate when transitionDuration <= 0.
  79205. enableTransition && transitionDuration > 0 && cssText.push(assembleTransition(transitionDuration, onlyFadeTransition, enableDisplayTransition));
  79206. if (backgroundColor) {
  79207. cssText.push('background-color:' + backgroundColor);
  79208. }
  79209. // Border style
  79210. each(['width', 'color', 'radius'], function (name) {
  79211. var borderName = 'border-' + name;
  79212. var camelCase = toCamelCase(borderName);
  79213. var val = tooltipModel.get(camelCase);
  79214. val != null && cssText.push(borderName + ':' + val + (name === 'color' ? '' : 'px'));
  79215. });
  79216. // Text style
  79217. cssText.push(assembleFont(textStyleModel));
  79218. // Padding
  79219. if (padding != null) {
  79220. cssText.push('padding:' + normalizeCssArray$1(padding).join('px ') + 'px');
  79221. }
  79222. return cssText.join(';') + ';';
  79223. }
  79224. // If not able to make, do not modify the input `out`.
  79225. function makeStyleCoord(out, zr, container, zrX, zrY) {
  79226. var zrPainter = zr && zr.painter;
  79227. if (container) {
  79228. var zrViewportRoot = zrPainter && zrPainter.getViewportRoot();
  79229. if (zrViewportRoot) {
  79230. // Some APPs might use scale on body, so we support CSS transform here.
  79231. transformLocalCoord(out, zrViewportRoot, container, zrX, zrY);
  79232. }
  79233. } else {
  79234. out[0] = zrX;
  79235. out[1] = zrY;
  79236. // xy should be based on canvas root. But tooltipContent is
  79237. // the sibling of canvas root. So padding of ec container
  79238. // should be considered here.
  79239. var viewportRootOffset = zrPainter && zrPainter.getViewportRootOffset();
  79240. if (viewportRootOffset) {
  79241. out[0] += viewportRootOffset.offsetLeft;
  79242. out[1] += viewportRootOffset.offsetTop;
  79243. }
  79244. }
  79245. out[2] = out[0] / zr.getWidth();
  79246. out[3] = out[1] / zr.getHeight();
  79247. }
  79248. var TooltipHTMLContent = /** @class */function () {
  79249. function TooltipHTMLContent(api, opt) {
  79250. this._show = false;
  79251. this._styleCoord = [0, 0, 0, 0];
  79252. this._enterable = true;
  79253. this._alwaysShowContent = false;
  79254. this._firstShow = true;
  79255. this._longHide = true;
  79256. if (env.wxa) {
  79257. return null;
  79258. }
  79259. var el = document.createElement('div');
  79260. // TODO: TYPE
  79261. el.domBelongToZr = true;
  79262. this.el = el;
  79263. var zr = this._zr = api.getZr();
  79264. var appendTo = opt.appendTo;
  79265. var container = appendTo && (isString(appendTo) ? document.querySelector(appendTo) : isDom(appendTo) ? appendTo : isFunction(appendTo) && appendTo(api.getDom()));
  79266. makeStyleCoord(this._styleCoord, zr, container, api.getWidth() / 2, api.getHeight() / 2);
  79267. (container || api.getDom()).appendChild(el);
  79268. this._api = api;
  79269. this._container = container;
  79270. // FIXME
  79271. // Is it needed to trigger zr event manually if
  79272. // the browser do not support `pointer-events: none`.
  79273. var self = this;
  79274. el.onmouseenter = function () {
  79275. // clear the timeout in hideLater and keep showing tooltip
  79276. if (self._enterable) {
  79277. clearTimeout(self._hideTimeout);
  79278. self._show = true;
  79279. }
  79280. self._inContent = true;
  79281. };
  79282. el.onmousemove = function (e) {
  79283. e = e || window.event;
  79284. if (!self._enterable) {
  79285. // `pointer-events: none` is set to tooltip content div
  79286. // if `enterable` is set as `false`, and `el.onmousemove`
  79287. // can not be triggered. But in browser that do not
  79288. // support `pointer-events`, we need to do this:
  79289. // Try trigger zrender event to avoid mouse
  79290. // in and out shape too frequently
  79291. var handler = zr.handler;
  79292. var zrViewportRoot = zr.painter.getViewportRoot();
  79293. normalizeEvent(zrViewportRoot, e, true);
  79294. handler.dispatch('mousemove', e);
  79295. }
  79296. };
  79297. el.onmouseleave = function () {
  79298. // set `_inContent` to `false` before `hideLater`
  79299. self._inContent = false;
  79300. if (self._enterable) {
  79301. if (self._show) {
  79302. self.hideLater(self._hideDelay);
  79303. }
  79304. }
  79305. };
  79306. }
  79307. /**
  79308. * Update when tooltip is rendered
  79309. */
  79310. TooltipHTMLContent.prototype.update = function (tooltipModel) {
  79311. // FIXME
  79312. // Move this logic to ec main?
  79313. if (!this._container) {
  79314. var container = this._api.getDom();
  79315. var position = getComputedStyle(container, 'position');
  79316. var domStyle = container.style;
  79317. if (domStyle.position !== 'absolute' && position !== 'absolute') {
  79318. domStyle.position = 'relative';
  79319. }
  79320. }
  79321. // move tooltip if chart resized
  79322. var alwaysShowContent = tooltipModel.get('alwaysShowContent');
  79323. alwaysShowContent && this._moveIfResized();
  79324. // update alwaysShowContent
  79325. this._alwaysShowContent = alwaysShowContent;
  79326. this._enableDisplayTransition = tooltipModel.get('displayTransition') && tooltipModel.get('transitionDuration') > 0;
  79327. // update className
  79328. this.el.className = tooltipModel.get('className') || '';
  79329. // Hide the tooltip
  79330. // PENDING
  79331. // this.hide();
  79332. };
  79333. TooltipHTMLContent.prototype.show = function (tooltipModel, nearPointColor) {
  79334. clearTimeout(this._hideTimeout);
  79335. clearTimeout(this._longHideTimeout);
  79336. var el = this.el;
  79337. var style = el.style;
  79338. var styleCoord = this._styleCoord;
  79339. if (!el.innerHTML) {
  79340. style.display = 'none';
  79341. } else {
  79342. style.cssText = gCssText + assembleCssText(tooltipModel, !this._firstShow, this._longHide, this._enableDisplayTransition)
  79343. // initial transform
  79344. + assembleTransform(styleCoord[0], styleCoord[1], true) + ("border-color:" + convertToColorString(nearPointColor) + ";") + (tooltipModel.get('extraCssText') || '')
  79345. // If mouse occasionally move over the tooltip, a mouseout event will be
  79346. // triggered by canvas, and cause some unexpectable result like dragging
  79347. // stop, "unfocusAdjacency". Here `pointer-events: none` is used to solve
  79348. // it. Although it is not supported by IE8~IE10, fortunately it is a rare
  79349. // scenario.
  79350. + (";pointer-events:" + (this._enterable ? 'auto' : 'none'));
  79351. }
  79352. this._show = true;
  79353. this._firstShow = false;
  79354. this._longHide = false;
  79355. };
  79356. TooltipHTMLContent.prototype.setContent = function (content, markers, tooltipModel, borderColor, arrowPosition) {
  79357. var el = this.el;
  79358. if (content == null) {
  79359. el.innerHTML = '';
  79360. return;
  79361. }
  79362. var arrow = '';
  79363. if (isString(arrowPosition) && tooltipModel.get('trigger') === 'item' && !shouldTooltipConfine(tooltipModel)) {
  79364. arrow = assembleArrow(tooltipModel, borderColor, arrowPosition);
  79365. }
  79366. if (isString(content)) {
  79367. el.innerHTML = content + arrow;
  79368. } else if (content) {
  79369. // Clear previous
  79370. el.innerHTML = '';
  79371. if (!isArray(content)) {
  79372. content = [content];
  79373. }
  79374. for (var i = 0; i < content.length; i++) {
  79375. if (isDom(content[i]) && content[i].parentNode !== el) {
  79376. el.appendChild(content[i]);
  79377. }
  79378. }
  79379. // no arrow if empty
  79380. if (arrow && el.childNodes.length) {
  79381. // no need to create a new parent element, but it's not supported by IE 10 and older.
  79382. // const arrowEl = document.createRange().createContextualFragment(arrow);
  79383. var arrowEl = document.createElement('div');
  79384. arrowEl.innerHTML = arrow;
  79385. el.appendChild(arrowEl);
  79386. }
  79387. }
  79388. };
  79389. TooltipHTMLContent.prototype.setEnterable = function (enterable) {
  79390. this._enterable = enterable;
  79391. };
  79392. TooltipHTMLContent.prototype.getSize = function () {
  79393. var el = this.el;
  79394. return el ? [el.offsetWidth, el.offsetHeight] : [0, 0];
  79395. };
  79396. TooltipHTMLContent.prototype.moveTo = function (zrX, zrY) {
  79397. if (!this.el) {
  79398. return;
  79399. }
  79400. var styleCoord = this._styleCoord;
  79401. makeStyleCoord(styleCoord, this._zr, this._container, zrX, zrY);
  79402. if (styleCoord[0] != null && styleCoord[1] != null) {
  79403. var style_1 = this.el.style;
  79404. var transforms = assembleTransform(styleCoord[0], styleCoord[1]);
  79405. each(transforms, function (transform) {
  79406. style_1[transform[0]] = transform[1];
  79407. });
  79408. }
  79409. };
  79410. /**
  79411. * when `alwaysShowContent` is true,
  79412. * move the tooltip after chart resized
  79413. */
  79414. TooltipHTMLContent.prototype._moveIfResized = function () {
  79415. // The ratio of left to width
  79416. var ratioX = this._styleCoord[2];
  79417. // The ratio of top to height
  79418. var ratioY = this._styleCoord[3];
  79419. this.moveTo(ratioX * this._zr.getWidth(), ratioY * this._zr.getHeight());
  79420. };
  79421. TooltipHTMLContent.prototype.hide = function () {
  79422. var _this = this;
  79423. var style = this.el.style;
  79424. if (this._enableDisplayTransition) {
  79425. style.visibility = 'hidden';
  79426. style.opacity = '0';
  79427. } else {
  79428. style.display = 'none';
  79429. }
  79430. env.transform3dSupported && (style.willChange = '');
  79431. this._show = false;
  79432. this._longHideTimeout = setTimeout(function () {
  79433. return _this._longHide = true;
  79434. }, 500);
  79435. };
  79436. TooltipHTMLContent.prototype.hideLater = function (time) {
  79437. if (this._show && !(this._inContent && this._enterable) && !this._alwaysShowContent) {
  79438. if (time) {
  79439. this._hideDelay = time;
  79440. // Set show false to avoid invoke hideLater multiple times
  79441. this._show = false;
  79442. this._hideTimeout = setTimeout(bind(this.hide, this), time);
  79443. } else {
  79444. this.hide();
  79445. }
  79446. }
  79447. };
  79448. TooltipHTMLContent.prototype.isShow = function () {
  79449. return this._show;
  79450. };
  79451. TooltipHTMLContent.prototype.dispose = function () {
  79452. clearTimeout(this._hideTimeout);
  79453. clearTimeout(this._longHideTimeout);
  79454. var zr = this._zr;
  79455. transformLocalCoordClear(zr && zr.painter && zr.painter.getViewportRoot(), this._container);
  79456. var el = this.el;
  79457. if (el) {
  79458. el.onmouseenter = el.onmousemove = el.onmouseleave = null;
  79459. var parentNode = el.parentNode;
  79460. parentNode && parentNode.removeChild(el);
  79461. }
  79462. this.el = this._container = null;
  79463. };
  79464. return TooltipHTMLContent;
  79465. }();
  79466. var TooltipRichContent = /** @class */function () {
  79467. function TooltipRichContent(api) {
  79468. this._show = false;
  79469. this._styleCoord = [0, 0, 0, 0];
  79470. this._alwaysShowContent = false;
  79471. this._enterable = true;
  79472. this._zr = api.getZr();
  79473. makeStyleCoord$1(this._styleCoord, this._zr, api.getWidth() / 2, api.getHeight() / 2);
  79474. }
  79475. /**
  79476. * Update when tooltip is rendered
  79477. */
  79478. TooltipRichContent.prototype.update = function (tooltipModel) {
  79479. var alwaysShowContent = tooltipModel.get('alwaysShowContent');
  79480. alwaysShowContent && this._moveIfResized();
  79481. // update alwaysShowContent
  79482. this._alwaysShowContent = alwaysShowContent;
  79483. };
  79484. TooltipRichContent.prototype.show = function () {
  79485. if (this._hideTimeout) {
  79486. clearTimeout(this._hideTimeout);
  79487. }
  79488. this.el.show();
  79489. this._show = true;
  79490. };
  79491. /**
  79492. * Set tooltip content
  79493. */
  79494. TooltipRichContent.prototype.setContent = function (content, markupStyleCreator, tooltipModel, borderColor, arrowPosition) {
  79495. var _this = this;
  79496. if (isObject(content)) {
  79497. throwError("development" !== 'production' ? 'Passing DOM nodes as content is not supported in richText tooltip!' : '');
  79498. }
  79499. if (this.el) {
  79500. this._zr.remove(this.el);
  79501. }
  79502. var textStyleModel = tooltipModel.getModel('textStyle');
  79503. this.el = new ZRText({
  79504. style: {
  79505. rich: markupStyleCreator.richTextStyles,
  79506. text: content,
  79507. lineHeight: 22,
  79508. borderWidth: 1,
  79509. borderColor: borderColor,
  79510. textShadowColor: textStyleModel.get('textShadowColor'),
  79511. fill: tooltipModel.get(['textStyle', 'color']),
  79512. padding: getPaddingFromTooltipModel(tooltipModel, 'richText'),
  79513. verticalAlign: 'top',
  79514. align: 'left'
  79515. },
  79516. z: tooltipModel.get('z')
  79517. });
  79518. each(['backgroundColor', 'borderRadius', 'shadowColor', 'shadowBlur', 'shadowOffsetX', 'shadowOffsetY'], function (propName) {
  79519. _this.el.style[propName] = tooltipModel.get(propName);
  79520. });
  79521. each(['textShadowBlur', 'textShadowOffsetX', 'textShadowOffsetY'], function (propName) {
  79522. _this.el.style[propName] = textStyleModel.get(propName) || 0;
  79523. });
  79524. this._zr.add(this.el);
  79525. var self = this;
  79526. this.el.on('mouseover', function () {
  79527. // clear the timeout in hideLater and keep showing tooltip
  79528. if (self._enterable) {
  79529. clearTimeout(self._hideTimeout);
  79530. self._show = true;
  79531. }
  79532. self._inContent = true;
  79533. });
  79534. this.el.on('mouseout', function () {
  79535. if (self._enterable) {
  79536. if (self._show) {
  79537. self.hideLater(self._hideDelay);
  79538. }
  79539. }
  79540. self._inContent = false;
  79541. });
  79542. };
  79543. TooltipRichContent.prototype.setEnterable = function (enterable) {
  79544. this._enterable = enterable;
  79545. };
  79546. TooltipRichContent.prototype.getSize = function () {
  79547. var el = this.el;
  79548. var bounding = this.el.getBoundingRect();
  79549. // bounding rect does not include shadow. For renderMode richText,
  79550. // if overflow, it will be cut. So calculate them accurately.
  79551. var shadowOuterSize = calcShadowOuterSize(el.style);
  79552. return [bounding.width + shadowOuterSize.left + shadowOuterSize.right, bounding.height + shadowOuterSize.top + shadowOuterSize.bottom];
  79553. };
  79554. TooltipRichContent.prototype.moveTo = function (x, y) {
  79555. var el = this.el;
  79556. if (el) {
  79557. var styleCoord = this._styleCoord;
  79558. makeStyleCoord$1(styleCoord, this._zr, x, y);
  79559. x = styleCoord[0];
  79560. y = styleCoord[1];
  79561. var style = el.style;
  79562. var borderWidth = mathMaxWith0(style.borderWidth || 0);
  79563. var shadowOuterSize = calcShadowOuterSize(style);
  79564. // rich text x, y do not include border.
  79565. el.x = x + borderWidth + shadowOuterSize.left;
  79566. el.y = y + borderWidth + shadowOuterSize.top;
  79567. el.markRedraw();
  79568. }
  79569. };
  79570. /**
  79571. * when `alwaysShowContent` is true,
  79572. * move the tooltip after chart resized
  79573. */
  79574. TooltipRichContent.prototype._moveIfResized = function () {
  79575. // The ratio of left to width
  79576. var ratioX = this._styleCoord[2];
  79577. // The ratio of top to height
  79578. var ratioY = this._styleCoord[3];
  79579. this.moveTo(ratioX * this._zr.getWidth(), ratioY * this._zr.getHeight());
  79580. };
  79581. TooltipRichContent.prototype.hide = function () {
  79582. if (this.el) {
  79583. this.el.hide();
  79584. }
  79585. this._show = false;
  79586. };
  79587. TooltipRichContent.prototype.hideLater = function (time) {
  79588. if (this._show && !(this._inContent && this._enterable) && !this._alwaysShowContent) {
  79589. if (time) {
  79590. this._hideDelay = time;
  79591. // Set show false to avoid invoke hideLater multiple times
  79592. this._show = false;
  79593. this._hideTimeout = setTimeout(bind(this.hide, this), time);
  79594. } else {
  79595. this.hide();
  79596. }
  79597. }
  79598. };
  79599. TooltipRichContent.prototype.isShow = function () {
  79600. return this._show;
  79601. };
  79602. TooltipRichContent.prototype.dispose = function () {
  79603. this._zr.remove(this.el);
  79604. };
  79605. return TooltipRichContent;
  79606. }();
  79607. function mathMaxWith0(val) {
  79608. return Math.max(0, val);
  79609. }
  79610. function calcShadowOuterSize(style) {
  79611. var shadowBlur = mathMaxWith0(style.shadowBlur || 0);
  79612. var shadowOffsetX = mathMaxWith0(style.shadowOffsetX || 0);
  79613. var shadowOffsetY = mathMaxWith0(style.shadowOffsetY || 0);
  79614. return {
  79615. left: mathMaxWith0(shadowBlur - shadowOffsetX),
  79616. right: mathMaxWith0(shadowBlur + shadowOffsetX),
  79617. top: mathMaxWith0(shadowBlur - shadowOffsetY),
  79618. bottom: mathMaxWith0(shadowBlur + shadowOffsetY)
  79619. };
  79620. }
  79621. function makeStyleCoord$1(out, zr, zrX, zrY) {
  79622. out[0] = zrX;
  79623. out[1] = zrY;
  79624. out[2] = out[0] / zr.getWidth();
  79625. out[3] = out[1] / zr.getHeight();
  79626. }
  79627. var proxyRect = new Rect({
  79628. shape: {
  79629. x: -1,
  79630. y: -1,
  79631. width: 2,
  79632. height: 2
  79633. }
  79634. });
  79635. var TooltipView = /** @class */function (_super) {
  79636. __extends(TooltipView, _super);
  79637. function TooltipView() {
  79638. var _this = _super !== null && _super.apply(this, arguments) || this;
  79639. _this.type = TooltipView.type;
  79640. return _this;
  79641. }
  79642. TooltipView.prototype.init = function (ecModel, api) {
  79643. if (env.node || !api.getDom()) {
  79644. return;
  79645. }
  79646. var tooltipModel = ecModel.getComponent('tooltip');
  79647. var renderMode = this._renderMode = getTooltipRenderMode(tooltipModel.get('renderMode'));
  79648. this._tooltipContent = renderMode === 'richText' ? new TooltipRichContent(api) : new TooltipHTMLContent(api, {
  79649. appendTo: tooltipModel.get('appendToBody', true) ? 'body' : tooltipModel.get('appendTo', true)
  79650. });
  79651. };
  79652. TooltipView.prototype.render = function (tooltipModel, ecModel, api) {
  79653. if (env.node || !api.getDom()) {
  79654. return;
  79655. }
  79656. // Reset
  79657. this.group.removeAll();
  79658. this._tooltipModel = tooltipModel;
  79659. this._ecModel = ecModel;
  79660. this._api = api;
  79661. var tooltipContent = this._tooltipContent;
  79662. tooltipContent.update(tooltipModel);
  79663. tooltipContent.setEnterable(tooltipModel.get('enterable'));
  79664. this._initGlobalListener();
  79665. this._keepShow();
  79666. // PENDING
  79667. // `mousemove` event will be triggered very frequently when the mouse moves fast,
  79668. // which causes that the `updatePosition` function was also called frequently.
  79669. // In Chrome with devtools open and Firefox, tooltip looks laggy and shakes. See #14695 #16101
  79670. // To avoid frequent triggering,
  79671. // consider throttling it in 50ms when transition is enabled
  79672. if (this._renderMode !== 'richText' && tooltipModel.get('transitionDuration')) {
  79673. createOrUpdate(this, '_updatePosition', 50, 'fixRate');
  79674. } else {
  79675. clear(this, '_updatePosition');
  79676. }
  79677. };
  79678. TooltipView.prototype._initGlobalListener = function () {
  79679. var tooltipModel = this._tooltipModel;
  79680. var triggerOn = tooltipModel.get('triggerOn');
  79681. register('itemTooltip', this._api, bind(function (currTrigger, e, dispatchAction) {
  79682. // If 'none', it is not controlled by mouse totally.
  79683. if (triggerOn !== 'none') {
  79684. if (triggerOn.indexOf(currTrigger) >= 0) {
  79685. this._tryShow(e, dispatchAction);
  79686. } else if (currTrigger === 'leave') {
  79687. this._hide(dispatchAction);
  79688. }
  79689. }
  79690. }, this));
  79691. };
  79692. TooltipView.prototype._keepShow = function () {
  79693. var tooltipModel = this._tooltipModel;
  79694. var ecModel = this._ecModel;
  79695. var api = this._api;
  79696. var triggerOn = tooltipModel.get('triggerOn');
  79697. // Try to keep the tooltip show when refreshing
  79698. if (this._lastX != null && this._lastY != null
  79699. // When user is willing to control tooltip totally using API,
  79700. // self.manuallyShowTip({x, y}) might cause tooltip hide,
  79701. // which is not expected.
  79702. && triggerOn !== 'none' && triggerOn !== 'click') {
  79703. var self_1 = this;
  79704. clearTimeout(this._refreshUpdateTimeout);
  79705. this._refreshUpdateTimeout = setTimeout(function () {
  79706. // Show tip next tick after other charts are rendered
  79707. // In case highlight action has wrong result
  79708. // FIXME
  79709. !api.isDisposed() && self_1.manuallyShowTip(tooltipModel, ecModel, api, {
  79710. x: self_1._lastX,
  79711. y: self_1._lastY,
  79712. dataByCoordSys: self_1._lastDataByCoordSys
  79713. });
  79714. });
  79715. }
  79716. };
  79717. /**
  79718. * Show tip manually by
  79719. * dispatchAction({
  79720. * type: 'showTip',
  79721. * x: 10,
  79722. * y: 10
  79723. * });
  79724. * Or
  79725. * dispatchAction({
  79726. * type: 'showTip',
  79727. * seriesIndex: 0,
  79728. * dataIndex or dataIndexInside or name
  79729. * });
  79730. *
  79731. * TODO Batch
  79732. */
  79733. TooltipView.prototype.manuallyShowTip = function (tooltipModel, ecModel, api, payload) {
  79734. if (payload.from === this.uid || env.node || !api.getDom()) {
  79735. return;
  79736. }
  79737. var dispatchAction = makeDispatchAction$1(payload, api);
  79738. // Reset ticket
  79739. this._ticket = '';
  79740. // When triggered from axisPointer.
  79741. var dataByCoordSys = payload.dataByCoordSys;
  79742. var cmptRef = findComponentReference(payload, ecModel, api);
  79743. if (cmptRef) {
  79744. var rect = cmptRef.el.getBoundingRect().clone();
  79745. rect.applyTransform(cmptRef.el.transform);
  79746. this._tryShow({
  79747. offsetX: rect.x + rect.width / 2,
  79748. offsetY: rect.y + rect.height / 2,
  79749. target: cmptRef.el,
  79750. position: payload.position,
  79751. // When manully trigger, the mouse is not on the el, so we'd better to
  79752. // position tooltip on the bottom of the el and display arrow is possible.
  79753. positionDefault: 'bottom'
  79754. }, dispatchAction);
  79755. } else if (payload.tooltip && payload.x != null && payload.y != null) {
  79756. var el = proxyRect;
  79757. el.x = payload.x;
  79758. el.y = payload.y;
  79759. el.update();
  79760. getECData(el).tooltipConfig = {
  79761. name: null,
  79762. option: payload.tooltip
  79763. };
  79764. // Manually show tooltip while view is not using zrender elements.
  79765. this._tryShow({
  79766. offsetX: payload.x,
  79767. offsetY: payload.y,
  79768. target: el
  79769. }, dispatchAction);
  79770. } else if (dataByCoordSys) {
  79771. this._tryShow({
  79772. offsetX: payload.x,
  79773. offsetY: payload.y,
  79774. position: payload.position,
  79775. dataByCoordSys: dataByCoordSys,
  79776. tooltipOption: payload.tooltipOption
  79777. }, dispatchAction);
  79778. } else if (payload.seriesIndex != null) {
  79779. if (this._manuallyAxisShowTip(tooltipModel, ecModel, api, payload)) {
  79780. return;
  79781. }
  79782. var pointInfo = findPointFromSeries(payload, ecModel);
  79783. var cx = pointInfo.point[0];
  79784. var cy = pointInfo.point[1];
  79785. if (cx != null && cy != null) {
  79786. this._tryShow({
  79787. offsetX: cx,
  79788. offsetY: cy,
  79789. target: pointInfo.el,
  79790. position: payload.position,
  79791. // When manully trigger, the mouse is not on the el, so we'd better to
  79792. // position tooltip on the bottom of the el and display arrow is possible.
  79793. positionDefault: 'bottom'
  79794. }, dispatchAction);
  79795. }
  79796. } else if (payload.x != null && payload.y != null) {
  79797. // FIXME
  79798. // should wrap dispatchAction like `axisPointer/globalListener` ?
  79799. api.dispatchAction({
  79800. type: 'updateAxisPointer',
  79801. x: payload.x,
  79802. y: payload.y
  79803. });
  79804. this._tryShow({
  79805. offsetX: payload.x,
  79806. offsetY: payload.y,
  79807. position: payload.position,
  79808. target: api.getZr().findHover(payload.x, payload.y).target
  79809. }, dispatchAction);
  79810. }
  79811. };
  79812. TooltipView.prototype.manuallyHideTip = function (tooltipModel, ecModel, api, payload) {
  79813. var tooltipContent = this._tooltipContent;
  79814. if (this._tooltipModel) {
  79815. tooltipContent.hideLater(this._tooltipModel.get('hideDelay'));
  79816. }
  79817. this._lastX = this._lastY = this._lastDataByCoordSys = null;
  79818. if (payload.from !== this.uid) {
  79819. this._hide(makeDispatchAction$1(payload, api));
  79820. }
  79821. };
  79822. // Be compatible with previous design, that is, when tooltip.type is 'axis' and
  79823. // dispatchAction 'showTip' with seriesIndex and dataIndex will trigger axis pointer
  79824. // and tooltip.
  79825. TooltipView.prototype._manuallyAxisShowTip = function (tooltipModel, ecModel, api, payload) {
  79826. var seriesIndex = payload.seriesIndex;
  79827. var dataIndex = payload.dataIndex;
  79828. // @ts-ignore
  79829. var coordSysAxesInfo = ecModel.getComponent('axisPointer').coordSysAxesInfo;
  79830. if (seriesIndex == null || dataIndex == null || coordSysAxesInfo == null) {
  79831. return;
  79832. }
  79833. var seriesModel = ecModel.getSeriesByIndex(seriesIndex);
  79834. if (!seriesModel) {
  79835. return;
  79836. }
  79837. var data = seriesModel.getData();
  79838. var tooltipCascadedModel = buildTooltipModel([data.getItemModel(dataIndex), seriesModel, (seriesModel.coordinateSystem || {}).model], this._tooltipModel);
  79839. if (tooltipCascadedModel.get('trigger') !== 'axis') {
  79840. return;
  79841. }
  79842. api.dispatchAction({
  79843. type: 'updateAxisPointer',
  79844. seriesIndex: seriesIndex,
  79845. dataIndex: dataIndex,
  79846. position: payload.position
  79847. });
  79848. return true;
  79849. };
  79850. TooltipView.prototype._tryShow = function (e, dispatchAction) {
  79851. var el = e.target;
  79852. var tooltipModel = this._tooltipModel;
  79853. if (!tooltipModel) {
  79854. return;
  79855. }
  79856. // Save mouse x, mouse y. So we can try to keep showing the tip if chart is refreshed
  79857. this._lastX = e.offsetX;
  79858. this._lastY = e.offsetY;
  79859. var dataByCoordSys = e.dataByCoordSys;
  79860. if (dataByCoordSys && dataByCoordSys.length) {
  79861. this._showAxisTooltip(dataByCoordSys, e);
  79862. } else if (el) {
  79863. var ecData = getECData(el);
  79864. if (ecData.ssrType === 'legend') {
  79865. // Don't trigger tooltip for legend tooltip item
  79866. return;
  79867. }
  79868. this._lastDataByCoordSys = null;
  79869. var seriesDispatcher_1;
  79870. var cmptDispatcher_1;
  79871. findEventDispatcher(el, function (target) {
  79872. if (target.tooltipDisabled) {
  79873. seriesDispatcher_1 = cmptDispatcher_1 = null;
  79874. return true;
  79875. }
  79876. if (seriesDispatcher_1 || cmptDispatcher_1) {
  79877. return;
  79878. }
  79879. // Always show item tooltip if mouse is on the element with dataIndex
  79880. if (getECData(target).dataIndex != null) {
  79881. seriesDispatcher_1 = target;
  79882. }
  79883. // Tooltip provided directly. Like legend.
  79884. else if (getECData(target).tooltipConfig != null) {
  79885. cmptDispatcher_1 = target;
  79886. }
  79887. }, true);
  79888. if (seriesDispatcher_1) {
  79889. this._showSeriesItemTooltip(e, seriesDispatcher_1, dispatchAction);
  79890. } else if (cmptDispatcher_1) {
  79891. this._showComponentItemTooltip(e, cmptDispatcher_1, dispatchAction);
  79892. } else {
  79893. this._hide(dispatchAction);
  79894. }
  79895. } else {
  79896. this._lastDataByCoordSys = null;
  79897. this._hide(dispatchAction);
  79898. }
  79899. };
  79900. TooltipView.prototype._showOrMove = function (tooltipModel, cb) {
  79901. // showDelay is used in this case: tooltip.enterable is set
  79902. // as true. User intent to move mouse into tooltip and click
  79903. // something. `showDelay` makes it easier to enter the content
  79904. // but tooltip do not move immediately.
  79905. var delay = tooltipModel.get('showDelay');
  79906. cb = bind(cb, this);
  79907. clearTimeout(this._showTimout);
  79908. delay > 0 ? this._showTimout = setTimeout(cb, delay) : cb();
  79909. };
  79910. TooltipView.prototype._showAxisTooltip = function (dataByCoordSys, e) {
  79911. var ecModel = this._ecModel;
  79912. var globalTooltipModel = this._tooltipModel;
  79913. var point = [e.offsetX, e.offsetY];
  79914. var singleTooltipModel = buildTooltipModel([e.tooltipOption], globalTooltipModel);
  79915. var renderMode = this._renderMode;
  79916. var cbParamsList = [];
  79917. var articleMarkup = createTooltipMarkup('section', {
  79918. blocks: [],
  79919. noHeader: true
  79920. });
  79921. // Only for legacy: `Serise['formatTooltip']` returns a string.
  79922. var markupTextArrLegacy = [];
  79923. var markupStyleCreator = new TooltipMarkupStyleCreator();
  79924. each(dataByCoordSys, function (itemCoordSys) {
  79925. each(itemCoordSys.dataByAxis, function (axisItem) {
  79926. var axisModel = ecModel.getComponent(axisItem.axisDim + 'Axis', axisItem.axisIndex);
  79927. var axisValue = axisItem.value;
  79928. if (!axisModel || axisValue == null) {
  79929. return;
  79930. }
  79931. // FIXME: when using `tooltip.trigger: 'axis'`, the precision of the axis value displayed in tooltip
  79932. // should match the original series values rather than using the default stretegy in Interval.ts
  79933. // (getPrecision(interval) + 2); otherwise it may cuase confusion.
  79934. var axisValueLabel = getValueLabel(axisValue, axisModel.axis, ecModel, axisItem.seriesDataIndices, axisItem.valueLabelOpt);
  79935. var axisSectionMarkup = createTooltipMarkup('section', {
  79936. header: axisValueLabel,
  79937. noHeader: !trim(axisValueLabel),
  79938. sortBlocks: true,
  79939. blocks: []
  79940. });
  79941. articleMarkup.blocks.push(axisSectionMarkup);
  79942. each(axisItem.seriesDataIndices, function (idxItem) {
  79943. var series = ecModel.getSeriesByIndex(idxItem.seriesIndex);
  79944. var dataIndex = idxItem.dataIndexInside;
  79945. var cbParams = series.getDataParams(dataIndex);
  79946. // Can't find data.
  79947. if (cbParams.dataIndex < 0) {
  79948. return;
  79949. }
  79950. cbParams.axisDim = axisItem.axisDim;
  79951. cbParams.axisIndex = axisItem.axisIndex;
  79952. cbParams.axisType = axisItem.axisType;
  79953. cbParams.axisId = axisItem.axisId;
  79954. cbParams.axisValue = getAxisRawValue(axisModel.axis, {
  79955. value: axisValue
  79956. });
  79957. cbParams.axisValueLabel = axisValueLabel;
  79958. // Pre-create marker style for makers. Users can assemble richText
  79959. // text in `formatter` callback and use those markers style.
  79960. cbParams.marker = markupStyleCreator.makeTooltipMarker('item', convertToColorString(cbParams.color), renderMode);
  79961. var seriesTooltipResult = normalizeTooltipFormatResult(series.formatTooltip(dataIndex, true, null));
  79962. var frag = seriesTooltipResult.frag;
  79963. if (frag) {
  79964. var valueFormatter = buildTooltipModel([series], globalTooltipModel).get('valueFormatter');
  79965. axisSectionMarkup.blocks.push(valueFormatter ? extend({
  79966. valueFormatter: valueFormatter
  79967. }, frag) : frag);
  79968. }
  79969. if (seriesTooltipResult.text) {
  79970. markupTextArrLegacy.push(seriesTooltipResult.text);
  79971. }
  79972. cbParamsList.push(cbParams);
  79973. });
  79974. });
  79975. });
  79976. // In most cases, the second axis is displays upper on the first one.
  79977. // So we reverse it to look better.
  79978. articleMarkup.blocks.reverse();
  79979. markupTextArrLegacy.reverse();
  79980. var positionExpr = e.position;
  79981. var orderMode = singleTooltipModel.get('order');
  79982. var builtMarkupText = buildTooltipMarkup(articleMarkup, markupStyleCreator, renderMode, orderMode, ecModel.get('useUTC'), singleTooltipModel.get('textStyle'));
  79983. builtMarkupText && markupTextArrLegacy.unshift(builtMarkupText);
  79984. var blockBreak = renderMode === 'richText' ? '\n\n' : '<br/>';
  79985. var allMarkupText = markupTextArrLegacy.join(blockBreak);
  79986. this._showOrMove(singleTooltipModel, function () {
  79987. if (this._updateContentNotChangedOnAxis(dataByCoordSys, cbParamsList)) {
  79988. this._updatePosition(singleTooltipModel, positionExpr, point[0], point[1], this._tooltipContent, cbParamsList);
  79989. } else {
  79990. this._showTooltipContent(singleTooltipModel, allMarkupText, cbParamsList, Math.random() + '', point[0], point[1], positionExpr, null, markupStyleCreator);
  79991. }
  79992. });
  79993. // Do not trigger events here, because this branch only be entered
  79994. // from dispatchAction.
  79995. };
  79996. TooltipView.prototype._showSeriesItemTooltip = function (e, dispatcher, dispatchAction) {
  79997. var ecModel = this._ecModel;
  79998. var ecData = getECData(dispatcher);
  79999. // Use dataModel in element if possible
  80000. // Used when mouseover on a element like markPoint or edge
  80001. // In which case, the data is not main data in series.
  80002. var seriesIndex = ecData.seriesIndex;
  80003. var seriesModel = ecModel.getSeriesByIndex(seriesIndex);
  80004. // For example, graph link.
  80005. var dataModel = ecData.dataModel || seriesModel;
  80006. var dataIndex = ecData.dataIndex;
  80007. var dataType = ecData.dataType;
  80008. var data = dataModel.getData(dataType);
  80009. var renderMode = this._renderMode;
  80010. var positionDefault = e.positionDefault;
  80011. var tooltipModel = buildTooltipModel([data.getItemModel(dataIndex), dataModel, seriesModel && (seriesModel.coordinateSystem || {}).model], this._tooltipModel, positionDefault ? {
  80012. position: positionDefault
  80013. } : null);
  80014. var tooltipTrigger = tooltipModel.get('trigger');
  80015. if (tooltipTrigger != null && tooltipTrigger !== 'item') {
  80016. return;
  80017. }
  80018. var params = dataModel.getDataParams(dataIndex, dataType);
  80019. var markupStyleCreator = new TooltipMarkupStyleCreator();
  80020. // Pre-create marker style for makers. Users can assemble richText
  80021. // text in `formatter` callback and use those markers style.
  80022. params.marker = markupStyleCreator.makeTooltipMarker('item', convertToColorString(params.color), renderMode);
  80023. var seriesTooltipResult = normalizeTooltipFormatResult(dataModel.formatTooltip(dataIndex, false, dataType));
  80024. var orderMode = tooltipModel.get('order');
  80025. var valueFormatter = tooltipModel.get('valueFormatter');
  80026. var frag = seriesTooltipResult.frag;
  80027. var markupText = frag ? buildTooltipMarkup(valueFormatter ? extend({
  80028. valueFormatter: valueFormatter
  80029. }, frag) : frag, markupStyleCreator, renderMode, orderMode, ecModel.get('useUTC'), tooltipModel.get('textStyle')) : seriesTooltipResult.text;
  80030. var asyncTicket = 'item_' + dataModel.name + '_' + dataIndex;
  80031. this._showOrMove(tooltipModel, function () {
  80032. this._showTooltipContent(tooltipModel, markupText, params, asyncTicket, e.offsetX, e.offsetY, e.position, e.target, markupStyleCreator);
  80033. });
  80034. // FIXME
  80035. // duplicated showtip if manuallyShowTip is called from dispatchAction.
  80036. dispatchAction({
  80037. type: 'showTip',
  80038. dataIndexInside: dataIndex,
  80039. dataIndex: data.getRawIndex(dataIndex),
  80040. seriesIndex: seriesIndex,
  80041. from: this.uid
  80042. });
  80043. };
  80044. TooltipView.prototype._showComponentItemTooltip = function (e, el, dispatchAction) {
  80045. var isHTMLRenderMode = this._renderMode === 'html';
  80046. var ecData = getECData(el);
  80047. var tooltipConfig = ecData.tooltipConfig;
  80048. var tooltipOpt = tooltipConfig.option || {};
  80049. var encodeHTMLContent = tooltipOpt.encodeHTMLContent;
  80050. if (isString(tooltipOpt)) {
  80051. var content = tooltipOpt;
  80052. tooltipOpt = {
  80053. content: content,
  80054. // Fixed formatter
  80055. formatter: content
  80056. };
  80057. // when `tooltipConfig.option` is a string rather than an object,
  80058. // we can't know if the content needs to be encoded
  80059. // for the sake of security, encode it by default.
  80060. encodeHTMLContent = true;
  80061. }
  80062. if (encodeHTMLContent && isHTMLRenderMode && tooltipOpt.content) {
  80063. // clone might be unnecessary?
  80064. tooltipOpt = clone(tooltipOpt);
  80065. tooltipOpt.content = encodeHTML(tooltipOpt.content);
  80066. }
  80067. var tooltipModelCascade = [tooltipOpt];
  80068. var cmpt = this._ecModel.getComponent(ecData.componentMainType, ecData.componentIndex);
  80069. if (cmpt) {
  80070. tooltipModelCascade.push(cmpt);
  80071. }
  80072. // In most cases, component tooltip formatter has different params with series tooltip formatter,
  80073. // so that they cannot share the same formatter. Since the global tooltip formatter is used for series
  80074. // by convention, we do not use it as the default formatter for component.
  80075. tooltipModelCascade.push({
  80076. formatter: tooltipOpt.content
  80077. });
  80078. var positionDefault = e.positionDefault;
  80079. var subTooltipModel = buildTooltipModel(tooltipModelCascade, this._tooltipModel, positionDefault ? {
  80080. position: positionDefault
  80081. } : null);
  80082. var defaultHtml = subTooltipModel.get('content');
  80083. var asyncTicket = Math.random() + '';
  80084. // PENDING: this case do not support richText style yet.
  80085. var markupStyleCreator = new TooltipMarkupStyleCreator();
  80086. // Do not check whether `trigger` is 'none' here, because `trigger`
  80087. // only works on coordinate system. In fact, we have not found case
  80088. // that requires setting `trigger` nothing on component yet.
  80089. this._showOrMove(subTooltipModel, function () {
  80090. // Use formatterParams from element defined in component
  80091. // Avoid users modify it.
  80092. var formatterParams = clone(subTooltipModel.get('formatterParams') || {});
  80093. this._showTooltipContent(subTooltipModel, defaultHtml, formatterParams, asyncTicket, e.offsetX, e.offsetY, e.position, el, markupStyleCreator);
  80094. });
  80095. // If not dispatch showTip, tip may be hide triggered by axis.
  80096. dispatchAction({
  80097. type: 'showTip',
  80098. from: this.uid
  80099. });
  80100. };
  80101. TooltipView.prototype._showTooltipContent = function (
  80102. // Use Model<TooltipOption> insteadof TooltipModel because this model may be from series or other options.
  80103. // Instead of top level tooltip.
  80104. tooltipModel, defaultHtml, params, asyncTicket, x, y, positionExpr, el, markupStyleCreator) {
  80105. // Reset ticket
  80106. this._ticket = '';
  80107. if (!tooltipModel.get('showContent') || !tooltipModel.get('show')) {
  80108. return;
  80109. }
  80110. var tooltipContent = this._tooltipContent;
  80111. tooltipContent.setEnterable(tooltipModel.get('enterable'));
  80112. var formatter = tooltipModel.get('formatter');
  80113. positionExpr = positionExpr || tooltipModel.get('position');
  80114. var html = defaultHtml;
  80115. var nearPoint = this._getNearestPoint([x, y], params, tooltipModel.get('trigger'), tooltipModel.get('borderColor'), tooltipModel.get('defaultBorderColor', true));
  80116. var nearPointColor = nearPoint.color;
  80117. if (formatter) {
  80118. if (isString(formatter)) {
  80119. var useUTC = tooltipModel.ecModel.get('useUTC');
  80120. var params0 = isArray(params) ? params[0] : params;
  80121. var isTimeAxis = params0 && params0.axisType && params0.axisType.indexOf('time') >= 0;
  80122. html = formatter;
  80123. if (isTimeAxis) {
  80124. html = format(params0.axisValue, html, useUTC);
  80125. }
  80126. html = formatTpl(html, params, true);
  80127. } else if (isFunction(formatter)) {
  80128. var callback = bind(function (cbTicket, html) {
  80129. if (cbTicket === this._ticket) {
  80130. tooltipContent.setContent(html, markupStyleCreator, tooltipModel, nearPointColor, positionExpr);
  80131. this._updatePosition(tooltipModel, positionExpr, x, y, tooltipContent, params, el);
  80132. }
  80133. }, this);
  80134. this._ticket = asyncTicket;
  80135. html = formatter(params, asyncTicket, callback);
  80136. } else {
  80137. html = formatter;
  80138. }
  80139. }
  80140. tooltipContent.setContent(html, markupStyleCreator, tooltipModel, nearPointColor, positionExpr);
  80141. tooltipContent.show(tooltipModel, nearPointColor);
  80142. this._updatePosition(tooltipModel, positionExpr, x, y, tooltipContent, params, el);
  80143. };
  80144. TooltipView.prototype._getNearestPoint = function (point, tooltipDataParams, trigger, borderColor, defaultBorderColor) {
  80145. if (trigger === 'axis' || isArray(tooltipDataParams)) {
  80146. return {
  80147. color: borderColor || defaultBorderColor
  80148. };
  80149. }
  80150. if (!isArray(tooltipDataParams)) {
  80151. return {
  80152. color: borderColor || tooltipDataParams.color || tooltipDataParams.borderColor
  80153. };
  80154. }
  80155. };
  80156. TooltipView.prototype._updatePosition = function (tooltipModel, positionExpr, x,
  80157. // Mouse x
  80158. y,
  80159. // Mouse y
  80160. content, params, el) {
  80161. var viewWidth = this._api.getWidth();
  80162. var viewHeight = this._api.getHeight();
  80163. positionExpr = positionExpr || tooltipModel.get('position');
  80164. var contentSize = content.getSize();
  80165. var align = tooltipModel.get('align');
  80166. var vAlign = tooltipModel.get('verticalAlign');
  80167. var rect = el && el.getBoundingRect().clone();
  80168. el && rect.applyTransform(el.transform);
  80169. if (isFunction(positionExpr)) {
  80170. // Callback of position can be an array or a string specify the position
  80171. positionExpr = positionExpr([x, y], params, content.el, rect, {
  80172. viewSize: [viewWidth, viewHeight],
  80173. contentSize: contentSize.slice()
  80174. });
  80175. }
  80176. if (isArray(positionExpr)) {
  80177. x = parsePercent$1(positionExpr[0], viewWidth);
  80178. y = parsePercent$1(positionExpr[1], viewHeight);
  80179. } else if (isObject(positionExpr)) {
  80180. var boxLayoutPosition = positionExpr;
  80181. boxLayoutPosition.width = contentSize[0];
  80182. boxLayoutPosition.height = contentSize[1];
  80183. var layoutRect = getLayoutRect(boxLayoutPosition, {
  80184. width: viewWidth,
  80185. height: viewHeight
  80186. });
  80187. x = layoutRect.x;
  80188. y = layoutRect.y;
  80189. align = null;
  80190. // When positionExpr is left/top/right/bottom,
  80191. // align and verticalAlign will not work.
  80192. vAlign = null;
  80193. }
  80194. // Specify tooltip position by string 'top' 'bottom' 'left' 'right' around graphic element
  80195. else if (isString(positionExpr) && el) {
  80196. var pos = calcTooltipPosition(positionExpr, rect, contentSize, tooltipModel.get('borderWidth'));
  80197. x = pos[0];
  80198. y = pos[1];
  80199. } else {
  80200. var pos = refixTooltipPosition(x, y, content, viewWidth, viewHeight, align ? null : 20, vAlign ? null : 20);
  80201. x = pos[0];
  80202. y = pos[1];
  80203. }
  80204. align && (x -= isCenterAlign(align) ? contentSize[0] / 2 : align === 'right' ? contentSize[0] : 0);
  80205. vAlign && (y -= isCenterAlign(vAlign) ? contentSize[1] / 2 : vAlign === 'bottom' ? contentSize[1] : 0);
  80206. if (shouldTooltipConfine(tooltipModel)) {
  80207. var pos = confineTooltipPosition(x, y, content, viewWidth, viewHeight);
  80208. x = pos[0];
  80209. y = pos[1];
  80210. }
  80211. content.moveTo(x, y);
  80212. };
  80213. // FIXME
  80214. // Should we remove this but leave this to user?
  80215. TooltipView.prototype._updateContentNotChangedOnAxis = function (dataByCoordSys, cbParamsList) {
  80216. var lastCoordSys = this._lastDataByCoordSys;
  80217. var lastCbParamsList = this._cbParamsList;
  80218. var contentNotChanged = !!lastCoordSys && lastCoordSys.length === dataByCoordSys.length;
  80219. contentNotChanged && each(lastCoordSys, function (lastItemCoordSys, indexCoordSys) {
  80220. var lastDataByAxis = lastItemCoordSys.dataByAxis || [];
  80221. var thisItemCoordSys = dataByCoordSys[indexCoordSys] || {};
  80222. var thisDataByAxis = thisItemCoordSys.dataByAxis || [];
  80223. contentNotChanged = contentNotChanged && lastDataByAxis.length === thisDataByAxis.length;
  80224. contentNotChanged && each(lastDataByAxis, function (lastItem, indexAxis) {
  80225. var thisItem = thisDataByAxis[indexAxis] || {};
  80226. var lastIndices = lastItem.seriesDataIndices || [];
  80227. var newIndices = thisItem.seriesDataIndices || [];
  80228. contentNotChanged = contentNotChanged && lastItem.value === thisItem.value && lastItem.axisType === thisItem.axisType && lastItem.axisId === thisItem.axisId && lastIndices.length === newIndices.length;
  80229. contentNotChanged && each(lastIndices, function (lastIdxItem, j) {
  80230. var newIdxItem = newIndices[j];
  80231. contentNotChanged = contentNotChanged && lastIdxItem.seriesIndex === newIdxItem.seriesIndex && lastIdxItem.dataIndex === newIdxItem.dataIndex;
  80232. });
  80233. // check is cbParams data value changed
  80234. lastCbParamsList && each(lastItem.seriesDataIndices, function (idxItem) {
  80235. var seriesIdx = idxItem.seriesIndex;
  80236. var cbParams = cbParamsList[seriesIdx];
  80237. var lastCbParams = lastCbParamsList[seriesIdx];
  80238. if (cbParams && lastCbParams && lastCbParams.data !== cbParams.data) {
  80239. contentNotChanged = false;
  80240. }
  80241. });
  80242. });
  80243. });
  80244. this._lastDataByCoordSys = dataByCoordSys;
  80245. this._cbParamsList = cbParamsList;
  80246. return !!contentNotChanged;
  80247. };
  80248. TooltipView.prototype._hide = function (dispatchAction) {
  80249. // Do not directly hideLater here, because this behavior may be prevented
  80250. // in dispatchAction when showTip is dispatched.
  80251. // FIXME
  80252. // duplicated hideTip if manuallyHideTip is called from dispatchAction.
  80253. this._lastDataByCoordSys = null;
  80254. dispatchAction({
  80255. type: 'hideTip',
  80256. from: this.uid
  80257. });
  80258. };
  80259. TooltipView.prototype.dispose = function (ecModel, api) {
  80260. if (env.node || !api.getDom()) {
  80261. return;
  80262. }
  80263. clear(this, '_updatePosition');
  80264. this._tooltipContent.dispose();
  80265. unregister('itemTooltip', api);
  80266. };
  80267. TooltipView.type = 'tooltip';
  80268. return TooltipView;
  80269. }(ComponentView);
  80270. /**
  80271. * From top to bottom. (the last one should be globalTooltipModel);
  80272. */
  80273. function buildTooltipModel(modelCascade, globalTooltipModel, defaultTooltipOption) {
  80274. // Last is always tooltip model.
  80275. var ecModel = globalTooltipModel.ecModel;
  80276. var resultModel;
  80277. if (defaultTooltipOption) {
  80278. resultModel = new Model(defaultTooltipOption, ecModel, ecModel);
  80279. resultModel = new Model(globalTooltipModel.option, resultModel, ecModel);
  80280. } else {
  80281. resultModel = globalTooltipModel;
  80282. }
  80283. for (var i = modelCascade.length - 1; i >= 0; i--) {
  80284. var tooltipOpt = modelCascade[i];
  80285. if (tooltipOpt) {
  80286. if (tooltipOpt instanceof Model) {
  80287. tooltipOpt = tooltipOpt.get('tooltip', true);
  80288. }
  80289. // In each data item tooltip can be simply write:
  80290. // {
  80291. // value: 10,
  80292. // tooltip: 'Something you need to know'
  80293. // }
  80294. if (isString(tooltipOpt)) {
  80295. tooltipOpt = {
  80296. formatter: tooltipOpt
  80297. };
  80298. }
  80299. if (tooltipOpt) {
  80300. resultModel = new Model(tooltipOpt, resultModel, ecModel);
  80301. }
  80302. }
  80303. }
  80304. return resultModel;
  80305. }
  80306. function makeDispatchAction$1(payload, api) {
  80307. return payload.dispatchAction || bind(api.dispatchAction, api);
  80308. }
  80309. function refixTooltipPosition(x, y, content, viewWidth, viewHeight, gapH, gapV) {
  80310. var size = content.getSize();
  80311. var width = size[0];
  80312. var height = size[1];
  80313. if (gapH != null) {
  80314. // Add extra 2 pixels for this case:
  80315. // At present the "values" in default tooltip are using CSS `float: right`.
  80316. // When the right edge of the tooltip box is on the right side of the
  80317. // viewport, the `float` layout might push the "values" to the second line.
  80318. if (x + width + gapH + 2 > viewWidth) {
  80319. x -= width + gapH;
  80320. } else {
  80321. x += gapH;
  80322. }
  80323. }
  80324. if (gapV != null) {
  80325. if (y + height + gapV > viewHeight) {
  80326. y -= height + gapV;
  80327. } else {
  80328. y += gapV;
  80329. }
  80330. }
  80331. return [x, y];
  80332. }
  80333. function confineTooltipPosition(x, y, content, viewWidth, viewHeight) {
  80334. var size = content.getSize();
  80335. var width = size[0];
  80336. var height = size[1];
  80337. x = Math.min(x + width, viewWidth) - width;
  80338. y = Math.min(y + height, viewHeight) - height;
  80339. x = Math.max(x, 0);
  80340. y = Math.max(y, 0);
  80341. return [x, y];
  80342. }
  80343. function calcTooltipPosition(position, rect, contentSize, borderWidth) {
  80344. var domWidth = contentSize[0];
  80345. var domHeight = contentSize[1];
  80346. var offset = Math.ceil(Math.SQRT2 * borderWidth) + 8;
  80347. var x = 0;
  80348. var y = 0;
  80349. var rectWidth = rect.width;
  80350. var rectHeight = rect.height;
  80351. switch (position) {
  80352. case 'inside':
  80353. x = rect.x + rectWidth / 2 - domWidth / 2;
  80354. y = rect.y + rectHeight / 2 - domHeight / 2;
  80355. break;
  80356. case 'top':
  80357. x = rect.x + rectWidth / 2 - domWidth / 2;
  80358. y = rect.y - domHeight - offset;
  80359. break;
  80360. case 'bottom':
  80361. x = rect.x + rectWidth / 2 - domWidth / 2;
  80362. y = rect.y + rectHeight + offset;
  80363. break;
  80364. case 'left':
  80365. x = rect.x - domWidth - offset;
  80366. y = rect.y + rectHeight / 2 - domHeight / 2;
  80367. break;
  80368. case 'right':
  80369. x = rect.x + rectWidth + offset;
  80370. y = rect.y + rectHeight / 2 - domHeight / 2;
  80371. }
  80372. return [x, y];
  80373. }
  80374. function isCenterAlign(align) {
  80375. return align === 'center' || align === 'middle';
  80376. }
  80377. /**
  80378. * Find target component by payload like:
  80379. * ```js
  80380. * { legendId: 'some_id', name: 'xxx' }
  80381. * { toolboxIndex: 1, name: 'xxx' }
  80382. * { geoName: 'some_name', name: 'xxx' }
  80383. * ```
  80384. * PENDING: at present only
  80385. *
  80386. * If not found, return null/undefined.
  80387. */
  80388. function findComponentReference(payload, ecModel, api) {
  80389. var queryOptionMap = preParseFinder(payload).queryOptionMap;
  80390. var componentMainType = queryOptionMap.keys()[0];
  80391. if (!componentMainType || componentMainType === 'series') {
  80392. return;
  80393. }
  80394. var queryResult = queryReferringComponents(ecModel, componentMainType, queryOptionMap.get(componentMainType), {
  80395. useDefault: false,
  80396. enableAll: false,
  80397. enableNone: false
  80398. });
  80399. var model = queryResult.models[0];
  80400. if (!model) {
  80401. return;
  80402. }
  80403. var view = api.getViewOfComponentModel(model);
  80404. var el;
  80405. view.group.traverse(function (subEl) {
  80406. var tooltipConfig = getECData(subEl).tooltipConfig;
  80407. if (tooltipConfig && tooltipConfig.name === payload.name) {
  80408. el = subEl;
  80409. return true; // stop
  80410. }
  80411. });
  80412. if (el) {
  80413. return {
  80414. componentMainType: componentMainType,
  80415. componentIndex: model.componentIndex,
  80416. el: el
  80417. };
  80418. }
  80419. }
  80420. function install$C(registers) {
  80421. use(install$t);
  80422. registers.registerComponentModel(TooltipModel);
  80423. registers.registerComponentView(TooltipView);
  80424. /**
  80425. * @action
  80426. * @property {string} type
  80427. * @property {number} seriesIndex
  80428. * @property {number} dataIndex
  80429. * @property {number} [x]
  80430. * @property {number} [y]
  80431. */
  80432. registers.registerAction({
  80433. type: 'showTip',
  80434. event: 'showTip',
  80435. update: 'tooltip:manuallyShowTip'
  80436. }, noop);
  80437. registers.registerAction({
  80438. type: 'hideTip',
  80439. event: 'hideTip',
  80440. update: 'tooltip:manuallyHideTip'
  80441. }, noop);
  80442. }
  80443. var DEFAULT_TOOLBOX_BTNS = ['rect', 'polygon', 'keep', 'clear'];
  80444. function brushPreprocessor(option, isNew) {
  80445. var brushComponents = normalizeToArray(option ? option.brush : []);
  80446. if (!brushComponents.length) {
  80447. return;
  80448. }
  80449. var brushComponentSpecifiedBtns = [];
  80450. each(brushComponents, function (brushOpt) {
  80451. var tbs = brushOpt.hasOwnProperty('toolbox') ? brushOpt.toolbox : [];
  80452. if (tbs instanceof Array) {
  80453. brushComponentSpecifiedBtns = brushComponentSpecifiedBtns.concat(tbs);
  80454. }
  80455. });
  80456. var toolbox = option && option.toolbox;
  80457. if (isArray(toolbox)) {
  80458. toolbox = toolbox[0];
  80459. }
  80460. if (!toolbox) {
  80461. toolbox = {
  80462. feature: {}
  80463. };
  80464. option.toolbox = [toolbox];
  80465. }
  80466. var toolboxFeature = toolbox.feature || (toolbox.feature = {});
  80467. var toolboxBrush = toolboxFeature.brush || (toolboxFeature.brush = {});
  80468. var brushTypes = toolboxBrush.type || (toolboxBrush.type = []);
  80469. brushTypes.push.apply(brushTypes, brushComponentSpecifiedBtns);
  80470. removeDuplicate(brushTypes);
  80471. if (isNew && !brushTypes.length) {
  80472. brushTypes.push.apply(brushTypes, DEFAULT_TOOLBOX_BTNS);
  80473. }
  80474. }
  80475. function removeDuplicate(arr) {
  80476. var map = {};
  80477. each(arr, function (val) {
  80478. map[val] = 1;
  80479. });
  80480. arr.length = 0;
  80481. each(map, function (flag, val) {
  80482. arr.push(val);
  80483. });
  80484. }
  80485. var each$b = each;
  80486. function hasKeys(obj) {
  80487. if (obj) {
  80488. for (var name_1 in obj) {
  80489. if (obj.hasOwnProperty(name_1)) {
  80490. return true;
  80491. }
  80492. }
  80493. }
  80494. }
  80495. function createVisualMappings(option, stateList, supplementVisualOption) {
  80496. var visualMappings = {};
  80497. each$b(stateList, function (state) {
  80498. var mappings = visualMappings[state] = createMappings();
  80499. each$b(option[state], function (visualData, visualType) {
  80500. if (!VisualMapping.isValidType(visualType)) {
  80501. return;
  80502. }
  80503. var mappingOption = {
  80504. type: visualType,
  80505. visual: visualData
  80506. };
  80507. supplementVisualOption && supplementVisualOption(mappingOption, state);
  80508. mappings[visualType] = new VisualMapping(mappingOption);
  80509. // Prepare a alpha for opacity, for some case that opacity
  80510. // is not supported, such as rendering using gradient color.
  80511. if (visualType === 'opacity') {
  80512. mappingOption = clone(mappingOption);
  80513. mappingOption.type = 'colorAlpha';
  80514. mappings.__hidden.__alphaForOpacity = new VisualMapping(mappingOption);
  80515. }
  80516. });
  80517. });
  80518. return visualMappings;
  80519. function createMappings() {
  80520. var Creater = function () {};
  80521. // Make sure hidden fields will not be visited by
  80522. // object iteration (with hasOwnProperty checking).
  80523. Creater.prototype.__hidden = Creater.prototype;
  80524. var obj = new Creater();
  80525. return obj;
  80526. }
  80527. }
  80528. function replaceVisualOption(thisOption, newOption, keys) {
  80529. // Visual attributes merge is not supported, otherwise it
  80530. // brings overcomplicated merge logic. See #2853. So if
  80531. // newOption has anyone of these keys, all of these keys
  80532. // will be reset. Otherwise, all keys remain.
  80533. var has;
  80534. each(keys, function (key) {
  80535. if (newOption.hasOwnProperty(key) && hasKeys(newOption[key])) {
  80536. has = true;
  80537. }
  80538. });
  80539. has && each(keys, function (key) {
  80540. if (newOption.hasOwnProperty(key) && hasKeys(newOption[key])) {
  80541. thisOption[key] = clone(newOption[key]);
  80542. } else {
  80543. delete thisOption[key];
  80544. }
  80545. });
  80546. }
  80547. /**
  80548. * @param stateList
  80549. * @param visualMappings
  80550. * @param list
  80551. * @param getValueState param: valueOrIndex, return: state.
  80552. * @param scope Scope for getValueState
  80553. * @param dimension Concrete dimension, if used.
  80554. */
  80555. // ???! handle brush?
  80556. function applyVisual(stateList, visualMappings, data, getValueState, scope, dimension) {
  80557. var visualTypesMap = {};
  80558. each(stateList, function (state) {
  80559. var visualTypes = VisualMapping.prepareVisualTypes(visualMappings[state]);
  80560. visualTypesMap[state] = visualTypes;
  80561. });
  80562. var dataIndex;
  80563. function getVisual(key) {
  80564. return getItemVisualFromData(data, dataIndex, key);
  80565. }
  80566. function setVisual(key, value) {
  80567. setItemVisualFromData(data, dataIndex, key, value);
  80568. }
  80569. if (dimension == null) {
  80570. data.each(eachItem);
  80571. } else {
  80572. data.each([dimension], eachItem);
  80573. }
  80574. function eachItem(valueOrIndex, index) {
  80575. dataIndex = dimension == null ? valueOrIndex // First argument is index
  80576. : index;
  80577. var rawDataItem = data.getRawDataItem(dataIndex);
  80578. // Consider performance
  80579. // @ts-ignore
  80580. if (rawDataItem && rawDataItem.visualMap === false) {
  80581. return;
  80582. }
  80583. var valueState = getValueState.call(scope, valueOrIndex);
  80584. var mappings = visualMappings[valueState];
  80585. var visualTypes = visualTypesMap[valueState];
  80586. for (var i = 0, len = visualTypes.length; i < len; i++) {
  80587. var type = visualTypes[i];
  80588. mappings[type] && mappings[type].applyVisual(valueOrIndex, getVisual, setVisual);
  80589. }
  80590. }
  80591. }
  80592. /**
  80593. * @param data
  80594. * @param stateList
  80595. * @param visualMappings <state, Object.<visualType, module:echarts/visual/VisualMapping>>
  80596. * @param getValueState param: valueOrIndex, return: state.
  80597. * @param dim dimension or dimension index.
  80598. */
  80599. function incrementalApplyVisual(stateList, visualMappings, getValueState, dim) {
  80600. var visualTypesMap = {};
  80601. each(stateList, function (state) {
  80602. var visualTypes = VisualMapping.prepareVisualTypes(visualMappings[state]);
  80603. visualTypesMap[state] = visualTypes;
  80604. });
  80605. return {
  80606. progress: function progress(params, data) {
  80607. var dimIndex;
  80608. if (dim != null) {
  80609. dimIndex = data.getDimensionIndex(dim);
  80610. }
  80611. function getVisual(key) {
  80612. return getItemVisualFromData(data, dataIndex, key);
  80613. }
  80614. function setVisual(key, value) {
  80615. setItemVisualFromData(data, dataIndex, key, value);
  80616. }
  80617. var dataIndex;
  80618. var store = data.getStore();
  80619. while ((dataIndex = params.next()) != null) {
  80620. var rawDataItem = data.getRawDataItem(dataIndex);
  80621. // Consider performance
  80622. // @ts-ignore
  80623. if (rawDataItem && rawDataItem.visualMap === false) {
  80624. continue;
  80625. }
  80626. var value = dim != null ? store.get(dimIndex, dataIndex) : dataIndex;
  80627. var valueState = getValueState(value);
  80628. var mappings = visualMappings[valueState];
  80629. var visualTypes = visualTypesMap[valueState];
  80630. for (var i = 0, len = visualTypes.length; i < len; i++) {
  80631. var type = visualTypes[i];
  80632. mappings[type] && mappings[type].applyVisual(value, getVisual, setVisual);
  80633. }
  80634. }
  80635. }
  80636. };
  80637. }
  80638. function makeBrushCommonSelectorForSeries(area) {
  80639. var brushType = area.brushType;
  80640. // Do not use function binding or curry for performance.
  80641. var selectors = {
  80642. point: function (itemLayout) {
  80643. return selector[brushType].point(itemLayout, selectors, area);
  80644. },
  80645. rect: function (itemLayout) {
  80646. return selector[brushType].rect(itemLayout, selectors, area);
  80647. }
  80648. };
  80649. return selectors;
  80650. }
  80651. var selector = {
  80652. lineX: getLineSelectors(0),
  80653. lineY: getLineSelectors(1),
  80654. rect: {
  80655. point: function (itemLayout, selectors, area) {
  80656. return itemLayout && area.boundingRect.contain(itemLayout[0], itemLayout[1]);
  80657. },
  80658. rect: function (itemLayout, selectors, area) {
  80659. return itemLayout && area.boundingRect.intersect(itemLayout);
  80660. }
  80661. },
  80662. polygon: {
  80663. point: function (itemLayout, selectors, area) {
  80664. return itemLayout && area.boundingRect.contain(itemLayout[0], itemLayout[1]) && contain$2(area.range, itemLayout[0], itemLayout[1]);
  80665. },
  80666. rect: function (itemLayout, selectors, area) {
  80667. var points = area.range;
  80668. if (!itemLayout || points.length <= 1) {
  80669. return false;
  80670. }
  80671. var x = itemLayout.x;
  80672. var y = itemLayout.y;
  80673. var width = itemLayout.width;
  80674. var height = itemLayout.height;
  80675. var p = points[0];
  80676. if (contain$2(points, x, y) || contain$2(points, x + width, y) || contain$2(points, x, y + height) || contain$2(points, x + width, y + height) || BoundingRect.create(itemLayout).contain(p[0], p[1]) || linePolygonIntersect(x, y, x + width, y, points) || linePolygonIntersect(x, y, x, y + height, points) || linePolygonIntersect(x + width, y, x + width, y + height, points) || linePolygonIntersect(x, y + height, x + width, y + height, points)) {
  80677. return true;
  80678. }
  80679. }
  80680. }
  80681. };
  80682. function getLineSelectors(xyIndex) {
  80683. var xy = ['x', 'y'];
  80684. var wh = ['width', 'height'];
  80685. return {
  80686. point: function (itemLayout, selectors, area) {
  80687. if (itemLayout) {
  80688. var range = area.range;
  80689. var p = itemLayout[xyIndex];
  80690. return inLineRange(p, range);
  80691. }
  80692. },
  80693. rect: function (itemLayout, selectors, area) {
  80694. if (itemLayout) {
  80695. var range = area.range;
  80696. var layoutRange = [itemLayout[xy[xyIndex]], itemLayout[xy[xyIndex]] + itemLayout[wh[xyIndex]]];
  80697. layoutRange[1] < layoutRange[0] && layoutRange.reverse();
  80698. return inLineRange(layoutRange[0], range) || inLineRange(layoutRange[1], range) || inLineRange(range[0], layoutRange) || inLineRange(range[1], layoutRange);
  80699. }
  80700. }
  80701. };
  80702. }
  80703. function inLineRange(p, range) {
  80704. return range[0] <= p && p <= range[1];
  80705. }
  80706. var STATE_LIST = ['inBrush', 'outOfBrush'];
  80707. var DISPATCH_METHOD = '__ecBrushSelect';
  80708. var DISPATCH_FLAG = '__ecInBrushSelectEvent';
  80709. function layoutCovers(ecModel) {
  80710. ecModel.eachComponent({
  80711. mainType: 'brush'
  80712. }, function (brushModel) {
  80713. var brushTargetManager = brushModel.brushTargetManager = new BrushTargetManager(brushModel.option, ecModel);
  80714. brushTargetManager.setInputRanges(brushModel.areas, ecModel);
  80715. });
  80716. }
  80717. /**
  80718. * Register the visual encoding if this modules required.
  80719. */
  80720. function brushVisual(ecModel, api, payload) {
  80721. var brushSelected = [];
  80722. var throttleType;
  80723. var throttleDelay;
  80724. ecModel.eachComponent({
  80725. mainType: 'brush'
  80726. }, function (brushModel) {
  80727. payload && payload.type === 'takeGlobalCursor' && brushModel.setBrushOption(payload.key === 'brush' ? payload.brushOption : {
  80728. brushType: false
  80729. });
  80730. });
  80731. layoutCovers(ecModel);
  80732. ecModel.eachComponent({
  80733. mainType: 'brush'
  80734. }, function (brushModel, brushIndex) {
  80735. var thisBrushSelected = {
  80736. brushId: brushModel.id,
  80737. brushIndex: brushIndex,
  80738. brushName: brushModel.name,
  80739. areas: clone(brushModel.areas),
  80740. selected: []
  80741. };
  80742. // Every brush component exists in event params, convenient
  80743. // for user to find by index.
  80744. brushSelected.push(thisBrushSelected);
  80745. var brushOption = brushModel.option;
  80746. var brushLink = brushOption.brushLink;
  80747. var linkedSeriesMap = [];
  80748. var selectedDataIndexForLink = [];
  80749. var rangeInfoBySeries = [];
  80750. var hasBrushExists = false;
  80751. if (!brushIndex) {
  80752. // Only the first throttle setting works.
  80753. throttleType = brushOption.throttleType;
  80754. throttleDelay = brushOption.throttleDelay;
  80755. }
  80756. // Add boundingRect and selectors to range.
  80757. var areas = map(brushModel.areas, function (area) {
  80758. var builder = boundingRectBuilders[area.brushType];
  80759. var selectableArea = defaults({
  80760. boundingRect: builder ? builder(area) : void 0
  80761. }, area);
  80762. selectableArea.selectors = makeBrushCommonSelectorForSeries(selectableArea);
  80763. return selectableArea;
  80764. });
  80765. var visualMappings = createVisualMappings(brushModel.option, STATE_LIST, function (mappingOption) {
  80766. mappingOption.mappingMethod = 'fixed';
  80767. });
  80768. isArray(brushLink) && each(brushLink, function (seriesIndex) {
  80769. linkedSeriesMap[seriesIndex] = 1;
  80770. });
  80771. function linkOthers(seriesIndex) {
  80772. return brushLink === 'all' || !!linkedSeriesMap[seriesIndex];
  80773. }
  80774. // If no supported brush or no brush on the series,
  80775. // all visuals should be in original state.
  80776. function brushed(rangeInfoList) {
  80777. return !!rangeInfoList.length;
  80778. }
  80779. /**
  80780. * Logic for each series: (If the logic has to be modified one day, do it carefully!)
  80781. *
  80782. * ( brushed ┬ && ┬hasBrushExist ┬ && linkOthers ) => StepA: ┬record, ┬ StepB: ┬visualByRecord.
  80783. * !brushed┘ ├hasBrushExist ┤ └nothing,┘ ├visualByRecord.
  80784. * └!hasBrushExist┘ └nothing.
  80785. * ( !brushed && ┬hasBrushExist ┬ && linkOthers ) => StepA: nothing, StepB: ┬visualByRecord.
  80786. * └!hasBrushExist┘ └nothing.
  80787. * ( brushed ┬ && !linkOthers ) => StepA: nothing, StepB: ┬visualByCheck.
  80788. * !brushed┘ └nothing.
  80789. * ( !brushed && !linkOthers ) => StepA: nothing, StepB: nothing.
  80790. */
  80791. // Step A
  80792. ecModel.eachSeries(function (seriesModel, seriesIndex) {
  80793. var rangeInfoList = rangeInfoBySeries[seriesIndex] = [];
  80794. seriesModel.subType === 'parallel' ? stepAParallel(seriesModel, seriesIndex) : stepAOthers(seriesModel, seriesIndex, rangeInfoList);
  80795. });
  80796. function stepAParallel(seriesModel, seriesIndex) {
  80797. var coordSys = seriesModel.coordinateSystem;
  80798. hasBrushExists = hasBrushExists || coordSys.hasAxisBrushed();
  80799. linkOthers(seriesIndex) && coordSys.eachActiveState(seriesModel.getData(), function (activeState, dataIndex) {
  80800. activeState === 'active' && (selectedDataIndexForLink[dataIndex] = 1);
  80801. });
  80802. }
  80803. function stepAOthers(seriesModel, seriesIndex, rangeInfoList) {
  80804. if (!seriesModel.brushSelector || brushModelNotControll(brushModel, seriesIndex)) {
  80805. return;
  80806. }
  80807. each(areas, function (area) {
  80808. if (brushModel.brushTargetManager.controlSeries(area, seriesModel, ecModel)) {
  80809. rangeInfoList.push(area);
  80810. }
  80811. hasBrushExists = hasBrushExists || brushed(rangeInfoList);
  80812. });
  80813. if (linkOthers(seriesIndex) && brushed(rangeInfoList)) {
  80814. var data_1 = seriesModel.getData();
  80815. data_1.each(function (dataIndex) {
  80816. if (checkInRange(seriesModel, rangeInfoList, data_1, dataIndex)) {
  80817. selectedDataIndexForLink[dataIndex] = 1;
  80818. }
  80819. });
  80820. }
  80821. }
  80822. // Step B
  80823. ecModel.eachSeries(function (seriesModel, seriesIndex) {
  80824. var seriesBrushSelected = {
  80825. seriesId: seriesModel.id,
  80826. seriesIndex: seriesIndex,
  80827. seriesName: seriesModel.name,
  80828. dataIndex: []
  80829. };
  80830. // Every series exists in event params, convenient
  80831. // for user to find series by seriesIndex.
  80832. thisBrushSelected.selected.push(seriesBrushSelected);
  80833. var rangeInfoList = rangeInfoBySeries[seriesIndex];
  80834. var data = seriesModel.getData();
  80835. var getValueState = linkOthers(seriesIndex) ? function (dataIndex) {
  80836. return selectedDataIndexForLink[dataIndex] ? (seriesBrushSelected.dataIndex.push(data.getRawIndex(dataIndex)), 'inBrush') : 'outOfBrush';
  80837. } : function (dataIndex) {
  80838. return checkInRange(seriesModel, rangeInfoList, data, dataIndex) ? (seriesBrushSelected.dataIndex.push(data.getRawIndex(dataIndex)), 'inBrush') : 'outOfBrush';
  80839. };
  80840. // If no supported brush or no brush, all visuals are in original state.
  80841. (linkOthers(seriesIndex) ? hasBrushExists : brushed(rangeInfoList)) && applyVisual(STATE_LIST, visualMappings, data, getValueState);
  80842. });
  80843. });
  80844. dispatchAction(api, throttleType, throttleDelay, brushSelected, payload);
  80845. }
  80846. function dispatchAction(api, throttleType, throttleDelay, brushSelected, payload) {
  80847. // This event will not be triggered when `setOpion`, otherwise dead lock may
  80848. // triggered when do `setOption` in event listener, which we do not find
  80849. // satisfactory way to solve yet. Some considered resolutions:
  80850. // (a) Diff with prevoius selected data ant only trigger event when changed.
  80851. // But store previous data and diff precisely (i.e., not only by dataIndex, but
  80852. // also detect value changes in selected data) might bring complexity or fragility.
  80853. // (b) Use spectial param like `silent` to suppress event triggering.
  80854. // But such kind of volatile param may be weird in `setOption`.
  80855. if (!payload) {
  80856. return;
  80857. }
  80858. var zr = api.getZr();
  80859. if (zr[DISPATCH_FLAG]) {
  80860. return;
  80861. }
  80862. if (!zr[DISPATCH_METHOD]) {
  80863. zr[DISPATCH_METHOD] = doDispatch;
  80864. }
  80865. var fn = createOrUpdate(zr, DISPATCH_METHOD, throttleDelay, throttleType);
  80866. fn(api, brushSelected);
  80867. }
  80868. function doDispatch(api, brushSelected) {
  80869. if (!api.isDisposed()) {
  80870. var zr = api.getZr();
  80871. zr[DISPATCH_FLAG] = true;
  80872. api.dispatchAction({
  80873. type: 'brushSelect',
  80874. batch: brushSelected
  80875. });
  80876. zr[DISPATCH_FLAG] = false;
  80877. }
  80878. }
  80879. function checkInRange(seriesModel, rangeInfoList, data, dataIndex) {
  80880. for (var i = 0, len = rangeInfoList.length; i < len; i++) {
  80881. var area = rangeInfoList[i];
  80882. if (seriesModel.brushSelector(dataIndex, data, area.selectors, area)) {
  80883. return true;
  80884. }
  80885. }
  80886. }
  80887. function brushModelNotControll(brushModel, seriesIndex) {
  80888. var seriesIndices = brushModel.option.seriesIndex;
  80889. return seriesIndices != null && seriesIndices !== 'all' && (isArray(seriesIndices) ? indexOf(seriesIndices, seriesIndex) < 0 : seriesIndex !== seriesIndices);
  80890. }
  80891. var boundingRectBuilders = {
  80892. rect: function (area) {
  80893. return getBoundingRectFromMinMax(area.range);
  80894. },
  80895. polygon: function (area) {
  80896. var minMax;
  80897. var range = area.range;
  80898. for (var i = 0, len = range.length; i < len; i++) {
  80899. minMax = minMax || [[Infinity, -Infinity], [Infinity, -Infinity]];
  80900. var rg = range[i];
  80901. rg[0] < minMax[0][0] && (minMax[0][0] = rg[0]);
  80902. rg[0] > minMax[0][1] && (minMax[0][1] = rg[0]);
  80903. rg[1] < minMax[1][0] && (minMax[1][0] = rg[1]);
  80904. rg[1] > minMax[1][1] && (minMax[1][1] = rg[1]);
  80905. }
  80906. return minMax && getBoundingRectFromMinMax(minMax);
  80907. }
  80908. };
  80909. function getBoundingRectFromMinMax(minMax) {
  80910. return new BoundingRect(minMax[0][0], minMax[1][0], minMax[0][1] - minMax[0][0], minMax[1][1] - minMax[1][0]);
  80911. }
  80912. var BrushView = /** @class */function (_super) {
  80913. __extends(BrushView, _super);
  80914. function BrushView() {
  80915. var _this = _super !== null && _super.apply(this, arguments) || this;
  80916. _this.type = BrushView.type;
  80917. return _this;
  80918. }
  80919. BrushView.prototype.init = function (ecModel, api) {
  80920. this.ecModel = ecModel;
  80921. this.api = api;
  80922. this.model;
  80923. (this._brushController = new BrushController(api.getZr())).on('brush', bind(this._onBrush, this)).mount();
  80924. };
  80925. BrushView.prototype.render = function (brushModel, ecModel, api, payload) {
  80926. this.model = brushModel;
  80927. this._updateController(brushModel, ecModel, api, payload);
  80928. };
  80929. BrushView.prototype.updateTransform = function (brushModel, ecModel, api, payload) {
  80930. // PENDING: `updateTransform` is a little tricky, whose layout need
  80931. // to be calculate mandatorily and other stages will not be performed.
  80932. // Take care the correctness of the logic. See #11754 .
  80933. layoutCovers(ecModel);
  80934. this._updateController(brushModel, ecModel, api, payload);
  80935. };
  80936. BrushView.prototype.updateVisual = function (brushModel, ecModel, api, payload) {
  80937. this.updateTransform(brushModel, ecModel, api, payload);
  80938. };
  80939. BrushView.prototype.updateView = function (brushModel, ecModel, api, payload) {
  80940. this._updateController(brushModel, ecModel, api, payload);
  80941. };
  80942. BrushView.prototype._updateController = function (brushModel, ecModel, api, payload) {
  80943. // Do not update controller when drawing.
  80944. (!payload || payload.$from !== brushModel.id) && this._brushController.setPanels(brushModel.brushTargetManager.makePanelOpts(api)).enableBrush(brushModel.brushOption).updateCovers(brushModel.areas.slice());
  80945. };
  80946. // updateLayout: updateController,
  80947. // updateVisual: updateController,
  80948. BrushView.prototype.dispose = function () {
  80949. this._brushController.dispose();
  80950. };
  80951. BrushView.prototype._onBrush = function (eventParam) {
  80952. var modelId = this.model.id;
  80953. var areas = this.model.brushTargetManager.setOutputRanges(eventParam.areas, this.ecModel);
  80954. // Action is not dispatched on drag end, because the drag end
  80955. // emits the same params with the last drag move event, and
  80956. // may have some delay when using touch pad, which makes
  80957. // animation not smooth (when using debounce).
  80958. (!eventParam.isEnd || eventParam.removeOnClick) && this.api.dispatchAction({
  80959. type: 'brush',
  80960. brushId: modelId,
  80961. areas: clone(areas),
  80962. $from: modelId
  80963. });
  80964. eventParam.isEnd && this.api.dispatchAction({
  80965. type: 'brushEnd',
  80966. brushId: modelId,
  80967. areas: clone(areas),
  80968. $from: modelId
  80969. });
  80970. };
  80971. BrushView.type = 'brush';
  80972. return BrushView;
  80973. }(ComponentView);
  80974. var BrushModel = /** @class */function (_super) {
  80975. __extends(BrushModel, _super);
  80976. function BrushModel() {
  80977. var _this = _super !== null && _super.apply(this, arguments) || this;
  80978. _this.type = BrushModel.type;
  80979. /**
  80980. * @readOnly
  80981. */
  80982. _this.areas = [];
  80983. /**
  80984. * Current brush painting area settings.
  80985. * @readOnly
  80986. */
  80987. _this.brushOption = {};
  80988. return _this;
  80989. }
  80990. BrushModel.prototype.optionUpdated = function (newOption, isInit) {
  80991. var thisOption = this.option;
  80992. !isInit && replaceVisualOption(thisOption, newOption, ['inBrush', 'outOfBrush']);
  80993. var inBrush = thisOption.inBrush = thisOption.inBrush || {};
  80994. // Always give default visual, consider setOption at the second time.
  80995. thisOption.outOfBrush = thisOption.outOfBrush || {
  80996. color: this.option.defaultOutOfBrushColor
  80997. };
  80998. if (!inBrush.hasOwnProperty('liftZ')) {
  80999. // Bigger than the highlight z lift, otherwise it will
  81000. // be effected by the highlight z when brush.
  81001. inBrush.liftZ = 5;
  81002. }
  81003. };
  81004. /**
  81005. * If `areas` is null/undefined, range state remain.
  81006. */
  81007. BrushModel.prototype.setAreas = function (areas) {
  81008. if ("development" !== 'production') {
  81009. assert(isArray(areas));
  81010. each(areas, function (area) {
  81011. assert(area.brushType, 'Illegal areas');
  81012. });
  81013. }
  81014. // If areas is null/undefined, range state remain.
  81015. // This helps user to dispatchAction({type: 'brush'}) with no areas
  81016. // set but just want to get the current brush select info from a `brush` event.
  81017. if (!areas) {
  81018. return;
  81019. }
  81020. this.areas = map(areas, function (area) {
  81021. return generateBrushOption(this.option, area);
  81022. }, this);
  81023. };
  81024. /**
  81025. * Set the current painting brush option.
  81026. */
  81027. BrushModel.prototype.setBrushOption = function (brushOption) {
  81028. this.brushOption = generateBrushOption(this.option, brushOption);
  81029. this.brushType = this.brushOption.brushType;
  81030. };
  81031. BrushModel.type = 'brush';
  81032. BrushModel.dependencies = ['geo', 'grid', 'xAxis', 'yAxis', 'parallel', 'series'];
  81033. BrushModel.defaultOption = {
  81034. seriesIndex: 'all',
  81035. brushType: 'rect',
  81036. brushMode: 'single',
  81037. transformable: true,
  81038. brushStyle: {
  81039. borderWidth: 1,
  81040. color: tokens.color.backgroundTint,
  81041. borderColor: tokens.color.borderTint
  81042. },
  81043. throttleType: 'fixRate',
  81044. throttleDelay: 0,
  81045. removeOnClick: true,
  81046. z: 10000,
  81047. defaultOutOfBrushColor: tokens.color.disabled
  81048. };
  81049. return BrushModel;
  81050. }(ComponentModel);
  81051. function generateBrushOption(option, brushOption) {
  81052. return merge({
  81053. brushType: option.brushType,
  81054. brushMode: option.brushMode,
  81055. transformable: option.transformable,
  81056. brushStyle: new Model(option.brushStyle).getItemStyle(),
  81057. removeOnClick: option.removeOnClick,
  81058. z: option.z
  81059. }, brushOption, true);
  81060. }
  81061. var ICON_TYPES = ['rect', 'polygon', 'lineX', 'lineY', 'keep', 'clear'];
  81062. var BrushFeature = /** @class */function (_super) {
  81063. __extends(BrushFeature, _super);
  81064. function BrushFeature() {
  81065. return _super !== null && _super.apply(this, arguments) || this;
  81066. }
  81067. BrushFeature.prototype.render = function (featureModel, ecModel, api) {
  81068. var brushType;
  81069. var brushMode;
  81070. var isBrushed;
  81071. ecModel.eachComponent({
  81072. mainType: 'brush'
  81073. }, function (brushModel) {
  81074. brushType = brushModel.brushType;
  81075. brushMode = brushModel.brushOption.brushMode || 'single';
  81076. isBrushed = isBrushed || !!brushModel.areas.length;
  81077. });
  81078. this._brushType = brushType;
  81079. this._brushMode = brushMode;
  81080. each(featureModel.get('type', true), function (type) {
  81081. featureModel.setIconStatus(type, (type === 'keep' ? brushMode === 'multiple' : type === 'clear' ? isBrushed : type === brushType) ? 'emphasis' : 'normal');
  81082. });
  81083. };
  81084. BrushFeature.prototype.updateView = function (featureModel, ecModel, api) {
  81085. this.render(featureModel, ecModel, api);
  81086. };
  81087. BrushFeature.prototype.getIcons = function () {
  81088. var model = this.model;
  81089. var availableIcons = model.get('icon', true);
  81090. var icons = {};
  81091. each(model.get('type', true), function (type) {
  81092. if (availableIcons[type]) {
  81093. icons[type] = availableIcons[type];
  81094. }
  81095. });
  81096. return icons;
  81097. };
  81098. BrushFeature.prototype.onclick = function (ecModel, api, type) {
  81099. var brushType = this._brushType;
  81100. var brushMode = this._brushMode;
  81101. if (type === 'clear') {
  81102. // Trigger parallel action firstly
  81103. api.dispatchAction({
  81104. type: 'axisAreaSelect',
  81105. intervals: []
  81106. });
  81107. api.dispatchAction({
  81108. type: 'brush',
  81109. command: 'clear',
  81110. // Clear all areas of all brush components.
  81111. areas: []
  81112. });
  81113. } else {
  81114. api.dispatchAction({
  81115. type: 'takeGlobalCursor',
  81116. key: 'brush',
  81117. brushOption: {
  81118. brushType: type === 'keep' ? brushType : brushType === type ? false : type,
  81119. brushMode: type === 'keep' ? brushMode === 'multiple' ? 'single' : 'multiple' : brushMode
  81120. }
  81121. });
  81122. }
  81123. };
  81124. BrushFeature.getDefaultOption = function (ecModel) {
  81125. var defaultOption = {
  81126. show: true,
  81127. type: ICON_TYPES.slice(),
  81128. icon: {
  81129. /* eslint-disable */
  81130. rect: 'M7.3,34.7 M0.4,10V-0.2h9.8 M89.6,10V-0.2h-9.8 M0.4,60v10.2h9.8 M89.6,60v10.2h-9.8 M12.3,22.4V10.5h13.1 M33.6,10.5h7.8 M49.1,10.5h7.8 M77.5,22.4V10.5h-13 M12.3,31.1v8.2 M77.7,31.1v8.2 M12.3,47.6v11.9h13.1 M33.6,59.5h7.6 M49.1,59.5 h7.7 M77.5,47.6v11.9h-13',
  81131. polygon: 'M55.2,34.9c1.7,0,3.1,1.4,3.1,3.1s-1.4,3.1-3.1,3.1 s-3.1-1.4-3.1-3.1S53.5,34.9,55.2,34.9z M50.4,51c1.7,0,3.1,1.4,3.1,3.1c0,1.7-1.4,3.1-3.1,3.1c-1.7,0-3.1-1.4-3.1-3.1 C47.3,52.4,48.7,51,50.4,51z M55.6,37.1l1.5-7.8 M60.1,13.5l1.6-8.7l-7.8,4 M59,19l-1,5.3 M24,16.1l6.4,4.9l6.4-3.3 M48.5,11.6 l-5.9,3.1 M19.1,12.8L9.7,5.1l1.1,7.7 M13.4,29.8l1,7.3l6.6,1.6 M11.6,18.4l1,6.1 M32.8,41.9 M26.6,40.4 M27.3,40.2l6.1,1.6 M49.9,52.1l-5.6-7.6l-4.9-1.2',
  81132. lineX: 'M15.2,30 M19.7,15.6V1.9H29 M34.8,1.9H40.4 M55.3,15.6V1.9H45.9 M19.7,44.4V58.1H29 M34.8,58.1H40.4 M55.3,44.4 V58.1H45.9 M12.5,20.3l-9.4,9.6l9.6,9.8 M3.1,29.9h16.5 M62.5,20.3l9.4,9.6L62.3,39.7 M71.9,29.9H55.4',
  81133. lineY: 'M38.8,7.7 M52.7,12h13.2v9 M65.9,26.6V32 M52.7,46.3h13.2v-9 M24.9,12H11.8v9 M11.8,26.6V32 M24.9,46.3H11.8v-9 M48.2,5.1l-9.3-9l-9.4,9.2 M38.9-3.9V12 M48.2,53.3l-9.3,9l-9.4-9.2 M38.9,62.3V46.4',
  81134. keep: 'M4,10.5V1h10.3 M20.7,1h6.1 M33,1h6.1 M55.4,10.5V1H45.2 M4,17.3v6.6 M55.6,17.3v6.6 M4,30.5V40h10.3 M20.7,40 h6.1 M33,40h6.1 M55.4,30.5V40H45.2 M21,18.9h62.9v48.6H21V18.9z',
  81135. clear: 'M22,14.7l30.9,31 M52.9,14.7L22,45.7 M4.7,16.8V4.2h13.1 M26,4.2h7.8 M41.6,4.2h7.8 M70.3,16.8V4.2H57.2 M4.7,25.9v8.6 M70.3,25.9v8.6 M4.7,43.2v12.6h13.1 M26,55.8h7.8 M41.6,55.8h7.8 M70.3,43.2v12.6H57.2' // jshint ignore:line
  81136. /* eslint-enable */
  81137. },
  81138. // `rect`, `polygon`, `lineX`, `lineY`, `keep`, `clear`
  81139. title: ecModel.getLocaleModel().get(['toolbox', 'brush', 'title'])
  81140. };
  81141. return defaultOption;
  81142. };
  81143. return BrushFeature;
  81144. }(ToolboxFeature);
  81145. function install$D(registers) {
  81146. registers.registerComponentView(BrushView);
  81147. registers.registerComponentModel(BrushModel);
  81148. registers.registerPreprocessor(brushPreprocessor);
  81149. registers.registerVisual(registers.PRIORITY.VISUAL.BRUSH, brushVisual);
  81150. registers.registerAction({
  81151. type: 'brush',
  81152. event: 'brush',
  81153. update: 'updateVisual'
  81154. }, function (payload, ecModel) {
  81155. ecModel.eachComponent({
  81156. mainType: 'brush',
  81157. query: payload
  81158. }, function (brushModel) {
  81159. brushModel.setAreas(payload.areas);
  81160. });
  81161. });
  81162. /**
  81163. * payload: {
  81164. * brushComponents: [
  81165. * {
  81166. * brushId,
  81167. * brushIndex,
  81168. * brushName,
  81169. * series: [
  81170. * {
  81171. * seriesId,
  81172. * seriesIndex,
  81173. * seriesName,
  81174. * rawIndices: [21, 34, ...]
  81175. * },
  81176. * ...
  81177. * ]
  81178. * },
  81179. * ...
  81180. * ]
  81181. * }
  81182. */
  81183. registers.registerAction({
  81184. type: 'brushSelect',
  81185. event: 'brushSelected',
  81186. update: 'none'
  81187. }, noop);
  81188. registers.registerAction({
  81189. type: 'brushEnd',
  81190. event: 'brushEnd',
  81191. update: 'none'
  81192. }, noop);
  81193. registerFeature('brush', BrushFeature);
  81194. }
  81195. var TitleModel = /** @class */function (_super) {
  81196. __extends(TitleModel, _super);
  81197. function TitleModel() {
  81198. var _this = _super !== null && _super.apply(this, arguments) || this;
  81199. _this.type = TitleModel.type;
  81200. _this.layoutMode = {
  81201. type: 'box',
  81202. ignoreSize: true
  81203. };
  81204. return _this;
  81205. }
  81206. TitleModel.type = 'title';
  81207. TitleModel.defaultOption = {
  81208. // zlevel: 0,
  81209. z: 6,
  81210. show: true,
  81211. text: '',
  81212. target: 'blank',
  81213. subtext: '',
  81214. subtarget: 'blank',
  81215. left: 'center',
  81216. top: tokens.size.m,
  81217. backgroundColor: tokens.color.transparent,
  81218. borderColor: tokens.color.primary,
  81219. borderWidth: 0,
  81220. padding: 5,
  81221. itemGap: 10,
  81222. textStyle: {
  81223. fontSize: 18,
  81224. fontWeight: 'bold',
  81225. color: tokens.color.primary
  81226. },
  81227. subtextStyle: {
  81228. fontSize: 12,
  81229. color: tokens.color.quaternary
  81230. }
  81231. };
  81232. return TitleModel;
  81233. }(ComponentModel);
  81234. // View
  81235. var TitleView = /** @class */function (_super) {
  81236. __extends(TitleView, _super);
  81237. function TitleView() {
  81238. var _this = _super !== null && _super.apply(this, arguments) || this;
  81239. _this.type = TitleView.type;
  81240. return _this;
  81241. }
  81242. TitleView.prototype.render = function (titleModel, ecModel, api) {
  81243. this.group.removeAll();
  81244. if (!titleModel.get('show')) {
  81245. return;
  81246. }
  81247. var group = this.group;
  81248. var textStyleModel = titleModel.getModel('textStyle');
  81249. var subtextStyleModel = titleModel.getModel('subtextStyle');
  81250. var textAlign = titleModel.get('textAlign');
  81251. var textVerticalAlign = retrieve2(titleModel.get('textBaseline'), titleModel.get('textVerticalAlign'));
  81252. var textEl = new ZRText({
  81253. style: createTextStyle(textStyleModel, {
  81254. text: titleModel.get('text'),
  81255. fill: textStyleModel.getTextColor()
  81256. }, {
  81257. disableBox: true
  81258. }),
  81259. z2: 10
  81260. });
  81261. var textRect = textEl.getBoundingRect();
  81262. var subText = titleModel.get('subtext');
  81263. var subTextEl = new ZRText({
  81264. style: createTextStyle(subtextStyleModel, {
  81265. text: subText,
  81266. fill: subtextStyleModel.getTextColor(),
  81267. y: textRect.height + titleModel.get('itemGap'),
  81268. verticalAlign: 'top'
  81269. }, {
  81270. disableBox: true
  81271. }),
  81272. z2: 10
  81273. });
  81274. var link = titleModel.get('link');
  81275. var sublink = titleModel.get('sublink');
  81276. var triggerEvent = titleModel.get('triggerEvent', true);
  81277. textEl.silent = !link && !triggerEvent;
  81278. subTextEl.silent = !sublink && !triggerEvent;
  81279. if (link) {
  81280. textEl.on('click', function () {
  81281. windowOpen(link, '_' + titleModel.get('target'));
  81282. });
  81283. }
  81284. if (sublink) {
  81285. subTextEl.on('click', function () {
  81286. windowOpen(sublink, '_' + titleModel.get('subtarget'));
  81287. });
  81288. }
  81289. getECData(textEl).eventData = getECData(subTextEl).eventData = triggerEvent ? {
  81290. componentType: 'title',
  81291. componentIndex: titleModel.componentIndex
  81292. } : null;
  81293. group.add(textEl);
  81294. subText && group.add(subTextEl);
  81295. // If no subText, but add subTextEl, there will be an empty line.
  81296. var groupRect = group.getBoundingRect();
  81297. var layoutOption = titleModel.getBoxLayoutParams();
  81298. layoutOption.width = groupRect.width;
  81299. layoutOption.height = groupRect.height;
  81300. var layoutRef = createBoxLayoutReference(titleModel, api);
  81301. var layoutRect = getLayoutRect(layoutOption, layoutRef.refContainer, titleModel.get('padding'));
  81302. // Adjust text align based on position
  81303. if (!textAlign) {
  81304. // Align left if title is on the left. center and right is same
  81305. textAlign = titleModel.get('left') || titleModel.get('right');
  81306. // @ts-ignore
  81307. if (textAlign === 'middle') {
  81308. textAlign = 'center';
  81309. }
  81310. // Adjust layout by text align
  81311. if (textAlign === 'right') {
  81312. layoutRect.x += layoutRect.width;
  81313. } else if (textAlign === 'center') {
  81314. layoutRect.x += layoutRect.width / 2;
  81315. }
  81316. }
  81317. if (!textVerticalAlign) {
  81318. textVerticalAlign = titleModel.get('top') || titleModel.get('bottom');
  81319. // @ts-ignore
  81320. if (textVerticalAlign === 'center') {
  81321. textVerticalAlign = 'middle';
  81322. }
  81323. if (textVerticalAlign === 'bottom') {
  81324. layoutRect.y += layoutRect.height;
  81325. } else if (textVerticalAlign === 'middle') {
  81326. layoutRect.y += layoutRect.height / 2;
  81327. }
  81328. textVerticalAlign = textVerticalAlign || 'top';
  81329. }
  81330. group.x = layoutRect.x;
  81331. group.y = layoutRect.y;
  81332. group.markRedraw();
  81333. var alignStyle = {
  81334. align: textAlign,
  81335. verticalAlign: textVerticalAlign
  81336. };
  81337. textEl.setStyle(alignStyle);
  81338. subTextEl.setStyle(alignStyle);
  81339. // Render background
  81340. // Get groupRect again because textAlign has been changed
  81341. groupRect = group.getBoundingRect();
  81342. var padding = layoutRect.margin;
  81343. var style = titleModel.getItemStyle(['color', 'opacity']);
  81344. style.fill = titleModel.get('backgroundColor');
  81345. var rect = new Rect({
  81346. shape: {
  81347. x: groupRect.x - padding[3],
  81348. y: groupRect.y - padding[0],
  81349. width: groupRect.width + padding[1] + padding[3],
  81350. height: groupRect.height + padding[0] + padding[2],
  81351. r: titleModel.get('borderRadius')
  81352. },
  81353. style: style,
  81354. subPixelOptimize: true,
  81355. silent: true
  81356. });
  81357. group.add(rect);
  81358. };
  81359. TitleView.type = 'title';
  81360. return TitleView;
  81361. }(ComponentView);
  81362. function install$E(registers) {
  81363. registers.registerComponentModel(TitleModel);
  81364. registers.registerComponentView(TitleView);
  81365. }
  81366. var TimelineModel = /** @class */function (_super) {
  81367. __extends(TimelineModel, _super);
  81368. function TimelineModel() {
  81369. var _this = _super !== null && _super.apply(this, arguments) || this;
  81370. _this.type = TimelineModel.type;
  81371. _this.layoutMode = 'box';
  81372. return _this;
  81373. }
  81374. /**
  81375. * @override
  81376. */
  81377. TimelineModel.prototype.init = function (option, parentModel, ecModel) {
  81378. this.mergeDefaultAndTheme(option, ecModel);
  81379. this._initData();
  81380. };
  81381. /**
  81382. * @override
  81383. */
  81384. TimelineModel.prototype.mergeOption = function (option) {
  81385. _super.prototype.mergeOption.apply(this, arguments);
  81386. this._initData();
  81387. };
  81388. TimelineModel.prototype.setCurrentIndex = function (currentIndex) {
  81389. if (currentIndex == null) {
  81390. currentIndex = this.option.currentIndex;
  81391. }
  81392. var count = this._data.count();
  81393. if (this.option.loop) {
  81394. currentIndex = (currentIndex % count + count) % count;
  81395. } else {
  81396. currentIndex >= count && (currentIndex = count - 1);
  81397. currentIndex < 0 && (currentIndex = 0);
  81398. }
  81399. this.option.currentIndex = currentIndex;
  81400. };
  81401. /**
  81402. * @return {number} currentIndex
  81403. */
  81404. TimelineModel.prototype.getCurrentIndex = function () {
  81405. return this.option.currentIndex;
  81406. };
  81407. /**
  81408. * @return {boolean}
  81409. */
  81410. TimelineModel.prototype.isIndexMax = function () {
  81411. return this.getCurrentIndex() >= this._data.count() - 1;
  81412. };
  81413. /**
  81414. * @param {boolean} state true: play, false: stop
  81415. */
  81416. TimelineModel.prototype.setPlayState = function (state) {
  81417. this.option.autoPlay = !!state;
  81418. };
  81419. /**
  81420. * @return {boolean} true: play, false: stop
  81421. */
  81422. TimelineModel.prototype.getPlayState = function () {
  81423. return !!this.option.autoPlay;
  81424. };
  81425. /**
  81426. * @private
  81427. */
  81428. TimelineModel.prototype._initData = function () {
  81429. var thisOption = this.option;
  81430. var dataArr = thisOption.data || [];
  81431. var axisType = thisOption.axisType;
  81432. var names = this._names = [];
  81433. var processedDataArr;
  81434. if (axisType === 'category') {
  81435. processedDataArr = [];
  81436. each(dataArr, function (item, index) {
  81437. var value = convertOptionIdName(getDataItemValue(item), '');
  81438. var newItem;
  81439. if (isObject(item)) {
  81440. newItem = clone(item);
  81441. newItem.value = index;
  81442. } else {
  81443. newItem = index;
  81444. }
  81445. processedDataArr.push(newItem);
  81446. names.push(value);
  81447. });
  81448. } else {
  81449. processedDataArr = dataArr;
  81450. }
  81451. var dimType = {
  81452. category: 'ordinal',
  81453. time: 'time',
  81454. value: 'number'
  81455. }[axisType] || 'number';
  81456. var data = this._data = new SeriesData([{
  81457. name: 'value',
  81458. type: dimType
  81459. }], this);
  81460. data.initData(processedDataArr, names);
  81461. };
  81462. TimelineModel.prototype.getData = function () {
  81463. return this._data;
  81464. };
  81465. /**
  81466. * @public
  81467. * @return {Array.<string>} categoreis
  81468. */
  81469. TimelineModel.prototype.getCategories = function () {
  81470. if (this.get('axisType') === 'category') {
  81471. return this._names.slice();
  81472. }
  81473. };
  81474. TimelineModel.type = 'timeline';
  81475. /**
  81476. * @protected
  81477. */
  81478. TimelineModel.defaultOption = {
  81479. // zlevel: 0, // 一级层叠
  81480. z: 4,
  81481. show: true,
  81482. axisType: 'time',
  81483. realtime: true,
  81484. left: '20%',
  81485. top: null,
  81486. right: '20%',
  81487. bottom: 0,
  81488. width: null,
  81489. height: 40,
  81490. padding: tokens.size.m,
  81491. controlPosition: 'left',
  81492. autoPlay: false,
  81493. rewind: false,
  81494. loop: true,
  81495. playInterval: 2000,
  81496. currentIndex: 0,
  81497. itemStyle: {},
  81498. label: {
  81499. color: tokens.color.secondary
  81500. },
  81501. data: []
  81502. };
  81503. return TimelineModel;
  81504. }(ComponentModel);
  81505. var SliderTimelineModel = /** @class */function (_super) {
  81506. __extends(SliderTimelineModel, _super);
  81507. function SliderTimelineModel() {
  81508. var _this = _super !== null && _super.apply(this, arguments) || this;
  81509. _this.type = SliderTimelineModel.type;
  81510. return _this;
  81511. }
  81512. SliderTimelineModel.type = 'timeline.slider';
  81513. /**
  81514. * @protected
  81515. */
  81516. SliderTimelineModel.defaultOption = inheritDefaultOption(TimelineModel.defaultOption, {
  81517. backgroundColor: 'rgba(0,0,0,0)',
  81518. borderColor: tokens.color.border,
  81519. borderWidth: 0,
  81520. orient: 'horizontal',
  81521. inverse: false,
  81522. tooltip: {
  81523. trigger: 'item' // data item may also have tootip attr.
  81524. },
  81525. symbol: 'circle',
  81526. symbolSize: 12,
  81527. lineStyle: {
  81528. show: true,
  81529. width: 2,
  81530. color: tokens.color.accent10
  81531. },
  81532. label: {
  81533. position: 'auto',
  81534. // When using number, label position is not
  81535. // restricted by viewRect.
  81536. // positive: right/bottom, negative: left/top
  81537. show: true,
  81538. interval: 'auto',
  81539. rotate: 0,
  81540. // formatter: null,
  81541. // 其余属性默认使用全局文本样式,详见TEXTSTYLE
  81542. color: tokens.color.tertiary
  81543. },
  81544. itemStyle: {
  81545. color: tokens.color.accent20,
  81546. borderWidth: 0
  81547. },
  81548. checkpointStyle: {
  81549. symbol: 'circle',
  81550. symbolSize: 15,
  81551. color: tokens.color.accent50,
  81552. borderColor: tokens.color.accent50,
  81553. borderWidth: 0,
  81554. shadowBlur: 0,
  81555. shadowOffsetX: 0,
  81556. shadowOffsetY: 0,
  81557. shadowColor: 'rgba(0, 0, 0, 0)',
  81558. // borderColor: 'rgba(194,53,49, 0.5)',
  81559. animation: true,
  81560. animationDuration: 300,
  81561. animationEasing: 'quinticInOut'
  81562. },
  81563. controlStyle: {
  81564. show: true,
  81565. showPlayBtn: true,
  81566. showPrevBtn: true,
  81567. showNextBtn: true,
  81568. itemSize: 24,
  81569. itemGap: 12,
  81570. position: 'left',
  81571. playIcon: 'path://M15 0C23.2843 0 30 6.71573 30 15C30 23.2843 23.2843 30 15 30C6.71573 30 0 23.2843 0 15C0 6.71573 6.71573 0 15 0ZM15 3C8.37258 3 3 8.37258 3 15C3 21.6274 8.37258 27 15 27C21.6274 27 27 21.6274 27 15C27 8.37258 21.6274 3 15 3ZM11.5 10.6699C11.5 9.90014 12.3333 9.41887 13 9.80371L20.5 14.1338C21.1667 14.5187 21.1667 15.4813 20.5 15.8662L13 20.1963C12.3333 20.5811 11.5 20.0999 11.5 19.3301V10.6699Z',
  81572. stopIcon: 'path://M15 0C23.2843 0 30 6.71573 30 15C30 23.2843 23.2843 30 15 30C6.71573 30 0 23.2843 0 15C0 6.71573 6.71573 0 15 0ZM15 3C8.37258 3 3 8.37258 3 15C3 21.6274 8.37258 27 15 27C21.6274 27 27 21.6274 27 15C27 8.37258 21.6274 3 15 3ZM11.5 10C12.3284 10 13 10.6716 13 11.5V18.5C13 19.3284 12.3284 20 11.5 20C10.6716 20 10 19.3284 10 18.5V11.5C10 10.6716 10.6716 10 11.5 10ZM18.5 10C19.3284 10 20 10.6716 20 11.5V18.5C20 19.3284 19.3284 20 18.5 20C17.6716 20 17 19.3284 17 18.5V11.5C17 10.6716 17.6716 10 18.5 10Z',
  81573. // eslint-disable-next-line max-len
  81574. nextIcon: 'path://M0.838834 18.7383C0.253048 18.1525 0.253048 17.2028 0.838834 16.617L7.55635 9.89949L0.838834 3.18198C0.253048 2.59619 0.253048 1.64645 0.838834 1.06066C1.42462 0.474874 2.37437 0.474874 2.96015 1.06066L10.7383 8.83883L10.8412 8.95277C11.2897 9.50267 11.2897 10.2963 10.8412 10.8462L10.7383 10.9602L2.96015 18.7383C2.37437 19.3241 1.42462 19.3241 0.838834 18.7383Z',
  81575. // eslint-disable-next-line max-len
  81576. prevIcon: 'path://M10.9602 1.06066C11.5459 1.64645 11.5459 2.59619 10.9602 3.18198L4.24264 9.89949L10.9602 16.617C11.5459 17.2028 11.5459 18.1525 10.9602 18.7383C10.3744 19.3241 9.42462 19.3241 8.83883 18.7383L1.06066 10.9602L0.957771 10.8462C0.509245 10.2963 0.509245 9.50267 0.957771 8.95277L1.06066 8.83883L8.83883 1.06066C9.42462 0.474874 10.3744 0.474874 10.9602 1.06066Z',
  81577. prevBtnSize: 18,
  81578. nextBtnSize: 18,
  81579. color: tokens.color.accent50,
  81580. borderColor: tokens.color.accent50,
  81581. borderWidth: 0
  81582. },
  81583. emphasis: {
  81584. label: {
  81585. show: true,
  81586. // 其余属性默认使用全局文本样式,详见TEXTSTYLE
  81587. color: tokens.color.accent60
  81588. },
  81589. itemStyle: {
  81590. color: tokens.color.accent60,
  81591. borderColor: tokens.color.accent60
  81592. },
  81593. controlStyle: {
  81594. color: tokens.color.accent70,
  81595. borderColor: tokens.color.accent70
  81596. }
  81597. },
  81598. progress: {
  81599. lineStyle: {
  81600. color: tokens.color.accent30
  81601. },
  81602. itemStyle: {
  81603. color: tokens.color.accent40
  81604. }
  81605. },
  81606. data: []
  81607. });
  81608. return SliderTimelineModel;
  81609. }(TimelineModel);
  81610. mixin(SliderTimelineModel, DataFormatMixin.prototype);
  81611. var TimelineView = /** @class */function (_super) {
  81612. __extends(TimelineView, _super);
  81613. function TimelineView() {
  81614. var _this = _super !== null && _super.apply(this, arguments) || this;
  81615. _this.type = TimelineView.type;
  81616. return _this;
  81617. }
  81618. TimelineView.type = 'timeline';
  81619. return TimelineView;
  81620. }(ComponentView);
  81621. /**
  81622. * Extend axis 2d
  81623. */
  81624. var TimelineAxis = /** @class */function (_super) {
  81625. __extends(TimelineAxis, _super);
  81626. function TimelineAxis(dim, scale, coordExtent, axisType) {
  81627. var _this = _super.call(this, dim, scale, coordExtent) || this;
  81628. _this.type = axisType || 'value';
  81629. return _this;
  81630. }
  81631. /**
  81632. * @override
  81633. */
  81634. TimelineAxis.prototype.getLabelModel = function () {
  81635. // Force override
  81636. return this.model.getModel('label');
  81637. };
  81638. /**
  81639. * @override
  81640. */
  81641. TimelineAxis.prototype.isHorizontal = function () {
  81642. return this.model.get('orient') === 'horizontal';
  81643. };
  81644. return TimelineAxis;
  81645. }(Axis);
  81646. var PI$8 = Math.PI;
  81647. var labelDataIndexStore = makeInner();
  81648. var SliderTimelineView = /** @class */function (_super) {
  81649. __extends(SliderTimelineView, _super);
  81650. function SliderTimelineView() {
  81651. var _this = _super !== null && _super.apply(this, arguments) || this;
  81652. _this.type = SliderTimelineView.type;
  81653. return _this;
  81654. }
  81655. SliderTimelineView.prototype.init = function (ecModel, api) {
  81656. this.api = api;
  81657. };
  81658. /**
  81659. * @override
  81660. */
  81661. SliderTimelineView.prototype.render = function (timelineModel, ecModel, api) {
  81662. this.model = timelineModel;
  81663. this.api = api;
  81664. this.ecModel = ecModel;
  81665. this.group.removeAll();
  81666. if (timelineModel.get('show', true)) {
  81667. var layoutInfo_1 = this._layout(timelineModel, api);
  81668. var mainGroup_1 = this._createGroup('_mainGroup');
  81669. var labelGroup = this._createGroup('_labelGroup');
  81670. var axis_1 = this._axis = this._createAxis(layoutInfo_1, timelineModel);
  81671. timelineModel.formatTooltip = function (dataIndex) {
  81672. var name = axis_1.scale.getLabel({
  81673. value: dataIndex
  81674. });
  81675. return createTooltipMarkup('nameValue', {
  81676. noName: true,
  81677. value: name
  81678. });
  81679. };
  81680. each(['AxisLine', 'AxisTick', 'Control', 'CurrentPointer'], function (name) {
  81681. this['_render' + name](layoutInfo_1, mainGroup_1, axis_1, timelineModel);
  81682. }, this);
  81683. this._renderAxisLabel(layoutInfo_1, labelGroup, axis_1, timelineModel);
  81684. this._position(layoutInfo_1, timelineModel);
  81685. }
  81686. this._doPlayStop();
  81687. this._updateTicksStatus();
  81688. };
  81689. /**
  81690. * @override
  81691. */
  81692. SliderTimelineView.prototype.remove = function () {
  81693. this._clearTimer();
  81694. this.group.removeAll();
  81695. };
  81696. /**
  81697. * @override
  81698. */
  81699. SliderTimelineView.prototype.dispose = function () {
  81700. this._clearTimer();
  81701. };
  81702. SliderTimelineView.prototype._layout = function (timelineModel, api) {
  81703. var labelPosOpt = timelineModel.get(['label', 'position']);
  81704. var orient = timelineModel.get('orient');
  81705. var viewRect = getViewRect$1(timelineModel, api);
  81706. var parsedLabelPos;
  81707. // Auto label offset.
  81708. if (labelPosOpt == null || labelPosOpt === 'auto') {
  81709. parsedLabelPos = orient === 'horizontal' ? viewRect.y + viewRect.height / 2 < api.getHeight() / 2 ? '-' : '+' : viewRect.x + viewRect.width / 2 < api.getWidth() / 2 ? '+' : '-';
  81710. } else if (isString(labelPosOpt)) {
  81711. parsedLabelPos = {
  81712. horizontal: {
  81713. top: '-',
  81714. bottom: '+'
  81715. },
  81716. vertical: {
  81717. left: '-',
  81718. right: '+'
  81719. }
  81720. }[orient][labelPosOpt];
  81721. } else {
  81722. // is number
  81723. parsedLabelPos = labelPosOpt;
  81724. }
  81725. var labelAlignMap = {
  81726. horizontal: 'center',
  81727. vertical: parsedLabelPos >= 0 || parsedLabelPos === '+' ? 'left' : 'right'
  81728. };
  81729. var labelBaselineMap = {
  81730. horizontal: parsedLabelPos >= 0 || parsedLabelPos === '+' ? 'top' : 'bottom',
  81731. vertical: 'middle'
  81732. };
  81733. var rotationMap = {
  81734. horizontal: 0,
  81735. vertical: PI$8 / 2
  81736. };
  81737. // Position
  81738. var mainLength = orient === 'vertical' ? viewRect.height : viewRect.width;
  81739. var controlModel = timelineModel.getModel('controlStyle');
  81740. var showControl = controlModel.get('show', true);
  81741. var controlSize = showControl ? controlModel.get('itemSize') : 0;
  81742. var controlGap = showControl ? controlModel.get('itemGap') : 0;
  81743. var sizePlusGap = controlSize + controlGap;
  81744. // Special label rotate.
  81745. var labelRotation = timelineModel.get(['label', 'rotate']) || 0;
  81746. labelRotation = labelRotation * PI$8 / 180; // To radian.
  81747. var playPosition;
  81748. var prevBtnPosition;
  81749. var nextBtnPosition;
  81750. var controlPosition = controlModel.get('position', true);
  81751. var showPlayBtn = showControl && controlModel.get('showPlayBtn', true);
  81752. var showPrevBtn = showControl && controlModel.get('showPrevBtn', true);
  81753. var showNextBtn = showControl && controlModel.get('showNextBtn', true);
  81754. var xLeft = 0;
  81755. var xRight = mainLength;
  81756. // position[0] means left, position[1] means middle.
  81757. if (controlPosition === 'left' || controlPosition === 'bottom') {
  81758. showPlayBtn && (playPosition = [0, 0], xLeft += sizePlusGap);
  81759. showPrevBtn && (prevBtnPosition = [xLeft, 0], xLeft += sizePlusGap);
  81760. showNextBtn && (nextBtnPosition = [xRight - controlSize, 0], xRight -= sizePlusGap);
  81761. } else {
  81762. // 'top' 'right'
  81763. showPlayBtn && (playPosition = [xRight - controlSize, 0], xRight -= sizePlusGap);
  81764. showPrevBtn && (prevBtnPosition = [0, 0], xLeft += sizePlusGap);
  81765. showNextBtn && (nextBtnPosition = [xRight - controlSize, 0], xRight -= sizePlusGap);
  81766. }
  81767. var axisExtent = [xLeft, xRight];
  81768. if (timelineModel.get('inverse')) {
  81769. axisExtent.reverse();
  81770. }
  81771. return {
  81772. viewRect: viewRect,
  81773. mainLength: mainLength,
  81774. orient: orient,
  81775. rotation: rotationMap[orient],
  81776. labelRotation: labelRotation,
  81777. labelPosOpt: parsedLabelPos,
  81778. labelAlign: timelineModel.get(['label', 'align']) || labelAlignMap[orient],
  81779. labelBaseline: timelineModel.get(['label', 'verticalAlign']) || timelineModel.get(['label', 'baseline']) || labelBaselineMap[orient],
  81780. // Based on mainGroup.
  81781. playPosition: playPosition,
  81782. prevBtnPosition: prevBtnPosition,
  81783. nextBtnPosition: nextBtnPosition,
  81784. axisExtent: axisExtent,
  81785. controlSize: controlSize,
  81786. controlGap: controlGap
  81787. };
  81788. };
  81789. SliderTimelineView.prototype._position = function (layoutInfo, timelineModel) {
  81790. // Position is be called finally, because bounding rect is needed for
  81791. // adapt content to fill viewRect (auto adapt offset).
  81792. // Timeline may be not all in the viewRect when 'offset' is specified
  81793. // as a number, because it is more appropriate that label aligns at
  81794. // 'offset' but not the other edge defined by viewRect.
  81795. var mainGroup = this._mainGroup;
  81796. var labelGroup = this._labelGroup;
  81797. var viewRect = layoutInfo.viewRect;
  81798. if (layoutInfo.orient === 'vertical') {
  81799. // transform to horizontal, inverse rotate by left-top point.
  81800. var m = create$1();
  81801. var rotateOriginX = viewRect.x;
  81802. var rotateOriginY = viewRect.y + viewRect.height;
  81803. translate(m, m, [-rotateOriginX, -rotateOriginY]);
  81804. rotate(m, m, -PI$8 / 2);
  81805. translate(m, m, [rotateOriginX, rotateOriginY]);
  81806. viewRect = viewRect.clone();
  81807. viewRect.applyTransform(m);
  81808. }
  81809. var viewBound = getBound(viewRect);
  81810. var mainBound = getBound(mainGroup.getBoundingRect());
  81811. var labelBound = getBound(labelGroup.getBoundingRect());
  81812. var mainPosition = [mainGroup.x, mainGroup.y];
  81813. var labelsPosition = [labelGroup.x, labelGroup.y];
  81814. labelsPosition[0] = mainPosition[0] = viewBound[0][0];
  81815. var labelPosOpt = layoutInfo.labelPosOpt;
  81816. if (labelPosOpt == null || isString(labelPosOpt)) {
  81817. // '+' or '-'
  81818. var mainBoundIdx = labelPosOpt === '+' ? 0 : 1;
  81819. toBound(mainPosition, mainBound, viewBound, 1, mainBoundIdx);
  81820. toBound(labelsPosition, labelBound, viewBound, 1, 1 - mainBoundIdx);
  81821. } else {
  81822. var mainBoundIdx = labelPosOpt >= 0 ? 0 : 1;
  81823. toBound(mainPosition, mainBound, viewBound, 1, mainBoundIdx);
  81824. labelsPosition[1] = mainPosition[1] + labelPosOpt;
  81825. }
  81826. mainGroup.setPosition(mainPosition);
  81827. labelGroup.setPosition(labelsPosition);
  81828. mainGroup.rotation = labelGroup.rotation = layoutInfo.rotation;
  81829. setOrigin(mainGroup);
  81830. setOrigin(labelGroup);
  81831. function setOrigin(targetGroup) {
  81832. targetGroup.originX = viewBound[0][0] - targetGroup.x;
  81833. targetGroup.originY = viewBound[1][0] - targetGroup.y;
  81834. }
  81835. function getBound(rect) {
  81836. // [[xmin, xmax], [ymin, ymax]]
  81837. return [[rect.x, rect.x + rect.width], [rect.y, rect.y + rect.height]];
  81838. }
  81839. function toBound(fromPos, from, to, dimIdx, boundIdx) {
  81840. fromPos[dimIdx] += to[dimIdx][boundIdx] - from[dimIdx][boundIdx];
  81841. }
  81842. };
  81843. SliderTimelineView.prototype._createAxis = function (layoutInfo, timelineModel) {
  81844. var data = timelineModel.getData();
  81845. var axisType = timelineModel.get('axisType');
  81846. var scale = createScaleByModel$1(timelineModel, axisType);
  81847. // Customize scale. The `tickValue` is `dataIndex`.
  81848. scale.getTicks = function () {
  81849. return data.mapArray(['value'], function (value) {
  81850. return {
  81851. value: value
  81852. };
  81853. });
  81854. };
  81855. var dataExtent = data.getDataExtent('value');
  81856. scale.setExtent(dataExtent[0], dataExtent[1]);
  81857. scale.calcNiceTicks();
  81858. var axis = new TimelineAxis('value', scale, layoutInfo.axisExtent, axisType);
  81859. axis.model = timelineModel;
  81860. return axis;
  81861. };
  81862. SliderTimelineView.prototype._createGroup = function (key) {
  81863. var newGroup = this[key] = new Group();
  81864. this.group.add(newGroup);
  81865. return newGroup;
  81866. };
  81867. SliderTimelineView.prototype._renderAxisLine = function (layoutInfo, group, axis, timelineModel) {
  81868. var axisExtent = axis.getExtent();
  81869. if (!timelineModel.get(['lineStyle', 'show'])) {
  81870. return;
  81871. }
  81872. var line = new Line({
  81873. shape: {
  81874. x1: axisExtent[0],
  81875. y1: 0,
  81876. x2: axisExtent[1],
  81877. y2: 0
  81878. },
  81879. style: extend({
  81880. lineCap: 'round'
  81881. }, timelineModel.getModel('lineStyle').getLineStyle()),
  81882. silent: true,
  81883. z2: 1
  81884. });
  81885. group.add(line);
  81886. var progressLine = this._progressLine = new Line({
  81887. shape: {
  81888. x1: axisExtent[0],
  81889. x2: this._currentPointer ? this._currentPointer.x : axisExtent[0],
  81890. y1: 0,
  81891. y2: 0
  81892. },
  81893. style: defaults({
  81894. lineCap: 'round',
  81895. lineWidth: line.style.lineWidth
  81896. }, timelineModel.getModel(['progress', 'lineStyle']).getLineStyle()),
  81897. silent: true,
  81898. z2: 1
  81899. });
  81900. group.add(progressLine);
  81901. };
  81902. SliderTimelineView.prototype._renderAxisTick = function (layoutInfo, group, axis, timelineModel) {
  81903. var _this = this;
  81904. var data = timelineModel.getData();
  81905. // Show all ticks, despite ignoring strategy.
  81906. var ticks = axis.scale.getTicks();
  81907. this._tickSymbols = [];
  81908. // The value is dataIndex, see the customized scale.
  81909. each(ticks, function (tick) {
  81910. var tickCoord = axis.dataToCoord(tick.value);
  81911. var itemModel = data.getItemModel(tick.value);
  81912. var itemStyleModel = itemModel.getModel('itemStyle');
  81913. var hoverStyleModel = itemModel.getModel(['emphasis', 'itemStyle']);
  81914. var progressStyleModel = itemModel.getModel(['progress', 'itemStyle']);
  81915. var symbolOpt = {
  81916. x: tickCoord,
  81917. y: 0,
  81918. onclick: bind(_this._changeTimeline, _this, tick.value)
  81919. };
  81920. var el = giveSymbol(itemModel, itemStyleModel, group, symbolOpt);
  81921. el.ensureState('emphasis').style = hoverStyleModel.getItemStyle();
  81922. el.ensureState('progress').style = progressStyleModel.getItemStyle();
  81923. enableHoverEmphasis(el);
  81924. var ecData = getECData(el);
  81925. if (itemModel.get('tooltip')) {
  81926. ecData.dataIndex = tick.value;
  81927. ecData.dataModel = timelineModel;
  81928. } else {
  81929. ecData.dataIndex = ecData.dataModel = null;
  81930. }
  81931. _this._tickSymbols.push(el);
  81932. });
  81933. };
  81934. SliderTimelineView.prototype._renderAxisLabel = function (layoutInfo, group, axis, timelineModel) {
  81935. var _this = this;
  81936. var labelModel = axis.getLabelModel();
  81937. if (!labelModel.get('show')) {
  81938. return;
  81939. }
  81940. var data = timelineModel.getData();
  81941. var labels = axis.getViewLabels();
  81942. this._tickLabels = [];
  81943. each(labels, function (labelItem) {
  81944. // The tickValue is dataIndex, see the customized scale.
  81945. var dataIndex = labelItem.tickValue;
  81946. var itemModel = data.getItemModel(dataIndex);
  81947. var normalLabelModel = itemModel.getModel('label');
  81948. var hoverLabelModel = itemModel.getModel(['emphasis', 'label']);
  81949. var progressLabelModel = itemModel.getModel(['progress', 'label']);
  81950. var tickCoord = axis.dataToCoord(labelItem.tickValue);
  81951. var textEl = new ZRText({
  81952. x: tickCoord,
  81953. y: 0,
  81954. rotation: layoutInfo.labelRotation - layoutInfo.rotation,
  81955. onclick: bind(_this._changeTimeline, _this, dataIndex),
  81956. silent: false,
  81957. style: createTextStyle(normalLabelModel, {
  81958. text: labelItem.formattedLabel,
  81959. align: layoutInfo.labelAlign,
  81960. verticalAlign: layoutInfo.labelBaseline
  81961. })
  81962. });
  81963. textEl.ensureState('emphasis').style = createTextStyle(hoverLabelModel);
  81964. textEl.ensureState('progress').style = createTextStyle(progressLabelModel);
  81965. group.add(textEl);
  81966. enableHoverEmphasis(textEl);
  81967. labelDataIndexStore(textEl).dataIndex = dataIndex;
  81968. _this._tickLabels.push(textEl);
  81969. });
  81970. };
  81971. SliderTimelineView.prototype._renderControl = function (layoutInfo, group, axis, timelineModel) {
  81972. var controlSize = layoutInfo.controlSize;
  81973. var rotation = layoutInfo.rotation;
  81974. var itemStyle = timelineModel.getModel('controlStyle').getItemStyle();
  81975. var hoverStyle = timelineModel.getModel(['emphasis', 'controlStyle']).getItemStyle();
  81976. var playState = timelineModel.getPlayState();
  81977. var inverse = timelineModel.get('inverse', true);
  81978. makeBtn(layoutInfo.nextBtnPosition, 'next', bind(this._changeTimeline, this, inverse ? '-' : '+'));
  81979. makeBtn(layoutInfo.prevBtnPosition, 'prev', bind(this._changeTimeline, this, inverse ? '+' : '-'));
  81980. makeBtn(layoutInfo.playPosition, playState ? 'stop' : 'play', bind(this._handlePlayClick, this, !playState), true);
  81981. function makeBtn(position, iconName, onclick, willRotate) {
  81982. if (!position) {
  81983. return;
  81984. }
  81985. var iconSize = parsePercent(retrieve2(timelineModel.get(['controlStyle', iconName + 'BtnSize']), controlSize), controlSize);
  81986. var rect = [0, -iconSize / 2, iconSize, iconSize];
  81987. var btn = makeControlIcon(timelineModel, iconName + 'Icon', rect, {
  81988. x: position[0],
  81989. y: position[1],
  81990. originX: controlSize / 2,
  81991. originY: 0,
  81992. rotation: willRotate ? -rotation : 0,
  81993. rectHover: true,
  81994. style: itemStyle,
  81995. onclick: onclick
  81996. });
  81997. btn.ensureState('emphasis').style = hoverStyle;
  81998. group.add(btn);
  81999. enableHoverEmphasis(btn);
  82000. }
  82001. };
  82002. SliderTimelineView.prototype._renderCurrentPointer = function (layoutInfo, group, axis, timelineModel) {
  82003. var data = timelineModel.getData();
  82004. var currentIndex = timelineModel.getCurrentIndex();
  82005. var pointerModel = data.getItemModel(currentIndex).getModel('checkpointStyle');
  82006. var me = this;
  82007. var callback = {
  82008. onCreate: function (pointer) {
  82009. pointer.draggable = true;
  82010. pointer.drift = bind(me._handlePointerDrag, me);
  82011. pointer.ondragend = bind(me._handlePointerDragend, me);
  82012. pointerMoveTo(pointer, me._progressLine, currentIndex, axis, timelineModel, true);
  82013. },
  82014. onUpdate: function (pointer) {
  82015. pointerMoveTo(pointer, me._progressLine, currentIndex, axis, timelineModel);
  82016. }
  82017. };
  82018. // Reuse when exists, for animation and drag.
  82019. this._currentPointer = giveSymbol(pointerModel, pointerModel, this._mainGroup, {}, this._currentPointer, callback);
  82020. };
  82021. SliderTimelineView.prototype._handlePlayClick = function (nextState) {
  82022. this._clearTimer();
  82023. this.api.dispatchAction({
  82024. type: 'timelinePlayChange',
  82025. playState: nextState,
  82026. from: this.uid
  82027. });
  82028. };
  82029. SliderTimelineView.prototype._handlePointerDrag = function (dx, dy, e) {
  82030. this._clearTimer();
  82031. this._pointerChangeTimeline([e.offsetX, e.offsetY]);
  82032. };
  82033. SliderTimelineView.prototype._handlePointerDragend = function (e) {
  82034. this._pointerChangeTimeline([e.offsetX, e.offsetY], true);
  82035. };
  82036. SliderTimelineView.prototype._pointerChangeTimeline = function (mousePos, trigger) {
  82037. var toCoord = this._toAxisCoord(mousePos)[0];
  82038. var axis = this._axis;
  82039. var axisExtent = asc(axis.getExtent().slice());
  82040. toCoord > axisExtent[1] && (toCoord = axisExtent[1]);
  82041. toCoord < axisExtent[0] && (toCoord = axisExtent[0]);
  82042. this._currentPointer.x = toCoord;
  82043. this._currentPointer.markRedraw();
  82044. var progressLine = this._progressLine;
  82045. if (progressLine) {
  82046. progressLine.shape.x2 = toCoord;
  82047. progressLine.dirty();
  82048. }
  82049. var targetDataIndex = this._findNearestTick(toCoord);
  82050. var timelineModel = this.model;
  82051. if (trigger || targetDataIndex !== timelineModel.getCurrentIndex() && timelineModel.get('realtime')) {
  82052. this._changeTimeline(targetDataIndex);
  82053. }
  82054. };
  82055. SliderTimelineView.prototype._doPlayStop = function () {
  82056. var _this = this;
  82057. this._clearTimer();
  82058. if (this.model.getPlayState()) {
  82059. this._timer = setTimeout(function () {
  82060. // Do not cache
  82061. var timelineModel = _this.model;
  82062. _this._changeTimeline(timelineModel.getCurrentIndex() + (timelineModel.get('rewind', true) ? -1 : 1));
  82063. }, this.model.get('playInterval'));
  82064. }
  82065. };
  82066. SliderTimelineView.prototype._toAxisCoord = function (vertex) {
  82067. var trans = this._mainGroup.getLocalTransform();
  82068. return applyTransform$1(vertex, trans, true);
  82069. };
  82070. SliderTimelineView.prototype._findNearestTick = function (axisCoord) {
  82071. var data = this.model.getData();
  82072. var dist = Infinity;
  82073. var targetDataIndex;
  82074. var axis = this._axis;
  82075. data.each(['value'], function (value, dataIndex) {
  82076. var coord = axis.dataToCoord(value);
  82077. var d = Math.abs(coord - axisCoord);
  82078. if (d < dist) {
  82079. dist = d;
  82080. targetDataIndex = dataIndex;
  82081. }
  82082. });
  82083. return targetDataIndex;
  82084. };
  82085. SliderTimelineView.prototype._clearTimer = function () {
  82086. if (this._timer) {
  82087. clearTimeout(this._timer);
  82088. this._timer = null;
  82089. }
  82090. };
  82091. SliderTimelineView.prototype._changeTimeline = function (nextIndex) {
  82092. var currentIndex = this.model.getCurrentIndex();
  82093. if (nextIndex === '+') {
  82094. nextIndex = currentIndex + 1;
  82095. } else if (nextIndex === '-') {
  82096. nextIndex = currentIndex - 1;
  82097. }
  82098. this.api.dispatchAction({
  82099. type: 'timelineChange',
  82100. currentIndex: nextIndex,
  82101. from: this.uid
  82102. });
  82103. };
  82104. SliderTimelineView.prototype._updateTicksStatus = function () {
  82105. var currentIndex = this.model.getCurrentIndex();
  82106. var tickSymbols = this._tickSymbols;
  82107. var tickLabels = this._tickLabels;
  82108. if (tickSymbols) {
  82109. for (var i = 0; i < tickSymbols.length; i++) {
  82110. tickSymbols && tickSymbols[i] && tickSymbols[i].toggleState('progress', i < currentIndex);
  82111. }
  82112. }
  82113. if (tickLabels) {
  82114. for (var i = 0; i < tickLabels.length; i++) {
  82115. tickLabels && tickLabels[i] && tickLabels[i].toggleState('progress', labelDataIndexStore(tickLabels[i]).dataIndex <= currentIndex);
  82116. }
  82117. }
  82118. };
  82119. SliderTimelineView.type = 'timeline.slider';
  82120. return SliderTimelineView;
  82121. }(TimelineView);
  82122. function createScaleByModel$1(model, axisType) {
  82123. axisType = axisType || model.get('type');
  82124. if (axisType) {
  82125. switch (axisType) {
  82126. // Buildin scale
  82127. case 'category':
  82128. return new OrdinalScale({
  82129. ordinalMeta: model.getCategories(),
  82130. extent: [Infinity, -Infinity]
  82131. });
  82132. case 'time':
  82133. return new TimeScale({
  82134. locale: model.ecModel.getLocaleModel(),
  82135. useUTC: model.ecModel.get('useUTC')
  82136. });
  82137. default:
  82138. // default to be value
  82139. return new IntervalScale();
  82140. }
  82141. }
  82142. }
  82143. function getViewRect$1(model, api) {
  82144. return getLayoutRect(model.getBoxLayoutParams(), createBoxLayoutReference(model, api).refContainer, model.get('padding'));
  82145. }
  82146. function makeControlIcon(timelineModel, objPath, rect, opts) {
  82147. var style = opts.style;
  82148. var icon = createIcon(timelineModel.get(['controlStyle', objPath]), opts || {}, new BoundingRect(rect[0], rect[1], rect[2], rect[3]));
  82149. // TODO createIcon won't use style in opt.
  82150. if (style) {
  82151. icon.setStyle(style);
  82152. }
  82153. return icon;
  82154. }
  82155. /**
  82156. * Create symbol or update symbol
  82157. * opt: basic position and event handlers
  82158. */
  82159. function giveSymbol(hostModel, itemStyleModel, group, opt, symbol, callback) {
  82160. var color = itemStyleModel.get('color');
  82161. if (!symbol) {
  82162. var symbolType = hostModel.get('symbol');
  82163. symbol = createSymbol(symbolType, -1, -1, 2, 2, color);
  82164. symbol.setStyle('strokeNoScale', true);
  82165. group.add(symbol);
  82166. callback && callback.onCreate(symbol);
  82167. } else {
  82168. symbol.setColor(color);
  82169. group.add(symbol); // Group may be new, also need to add.
  82170. callback && callback.onUpdate(symbol);
  82171. }
  82172. // Style
  82173. var itemStyle = itemStyleModel.getItemStyle(['color']);
  82174. symbol.setStyle(itemStyle);
  82175. // Transform and events.
  82176. opt = merge({
  82177. rectHover: true,
  82178. z2: 100
  82179. }, opt, true);
  82180. var symbolSize = normalizeSymbolSize(hostModel.get('symbolSize'));
  82181. opt.scaleX = symbolSize[0] / 2;
  82182. opt.scaleY = symbolSize[1] / 2;
  82183. var symbolOffset = normalizeSymbolOffset(hostModel.get('symbolOffset'), symbolSize);
  82184. if (symbolOffset) {
  82185. opt.x = (opt.x || 0) + symbolOffset[0];
  82186. opt.y = (opt.y || 0) + symbolOffset[1];
  82187. }
  82188. var symbolRotate = hostModel.get('symbolRotate');
  82189. opt.rotation = (symbolRotate || 0) * Math.PI / 180 || 0;
  82190. symbol.attr(opt);
  82191. // FIXME
  82192. // (1) When symbol.style.strokeNoScale is true and updateTransform is not performed,
  82193. // getBoundingRect will return wrong result.
  82194. // (This is supposed to be resolved in zrender, but it is a little difficult to
  82195. // leverage performance and auto updateTransform)
  82196. // (2) All of ancesters of symbol do not scale, so we can just updateTransform symbol.
  82197. symbol.updateTransform();
  82198. return symbol;
  82199. }
  82200. function pointerMoveTo(pointer, progressLine, dataIndex, axis, timelineModel, noAnimation) {
  82201. if (pointer.dragging) {
  82202. return;
  82203. }
  82204. var pointerModel = timelineModel.getModel('checkpointStyle');
  82205. var toCoord = axis.dataToCoord(timelineModel.getData().get('value', dataIndex));
  82206. if (noAnimation || !pointerModel.get('animation', true)) {
  82207. pointer.attr({
  82208. x: toCoord,
  82209. y: 0
  82210. });
  82211. progressLine && progressLine.attr({
  82212. shape: {
  82213. x2: toCoord
  82214. }
  82215. });
  82216. } else {
  82217. var animationCfg = {
  82218. duration: pointerModel.get('animationDuration', true),
  82219. easing: pointerModel.get('animationEasing', true)
  82220. };
  82221. pointer.stopAnimation(null, true);
  82222. pointer.animateTo({
  82223. x: toCoord,
  82224. y: 0
  82225. }, animationCfg);
  82226. progressLine && progressLine.animateTo({
  82227. shape: {
  82228. x2: toCoord
  82229. }
  82230. }, animationCfg);
  82231. }
  82232. }
  82233. function installTimelineAction(registers) {
  82234. registers.registerAction({
  82235. type: 'timelineChange',
  82236. event: 'timelineChanged',
  82237. update: 'prepareAndUpdate'
  82238. }, function (payload, ecModel, api) {
  82239. var timelineModel = ecModel.getComponent('timeline');
  82240. if (timelineModel && payload.currentIndex != null) {
  82241. timelineModel.setCurrentIndex(payload.currentIndex);
  82242. if (!timelineModel.get('loop', true) && timelineModel.isIndexMax() && timelineModel.getPlayState()) {
  82243. timelineModel.setPlayState(false);
  82244. // The timeline has played to the end, trigger event
  82245. api.dispatchAction({
  82246. type: 'timelinePlayChange',
  82247. playState: false,
  82248. from: payload.from
  82249. });
  82250. }
  82251. }
  82252. // Set normalized currentIndex to payload.
  82253. ecModel.resetOption('timeline', {
  82254. replaceMerge: timelineModel.get('replaceMerge', true)
  82255. });
  82256. return defaults({
  82257. currentIndex: timelineModel.option.currentIndex
  82258. }, payload);
  82259. });
  82260. registers.registerAction({
  82261. type: 'timelinePlayChange',
  82262. event: 'timelinePlayChanged',
  82263. update: 'update'
  82264. }, function (payload, ecModel) {
  82265. var timelineModel = ecModel.getComponent('timeline');
  82266. if (timelineModel && payload.playState != null) {
  82267. timelineModel.setPlayState(payload.playState);
  82268. }
  82269. });
  82270. }
  82271. function timelinePreprocessor(option) {
  82272. var timelineOpt = option && option.timeline;
  82273. if (!isArray(timelineOpt)) {
  82274. timelineOpt = timelineOpt ? [timelineOpt] : [];
  82275. }
  82276. each(timelineOpt, function (opt) {
  82277. if (!opt) {
  82278. return;
  82279. }
  82280. compatibleEC2(opt);
  82281. });
  82282. }
  82283. function compatibleEC2(opt) {
  82284. var type = opt.type;
  82285. var ec2Types = {
  82286. 'number': 'value',
  82287. 'time': 'time'
  82288. };
  82289. // Compatible with ec2
  82290. if (ec2Types[type]) {
  82291. opt.axisType = ec2Types[type];
  82292. delete opt.type;
  82293. }
  82294. transferItem(opt);
  82295. if (has(opt, 'controlPosition')) {
  82296. var controlStyle = opt.controlStyle || (opt.controlStyle = {});
  82297. if (!has(controlStyle, 'position')) {
  82298. controlStyle.position = opt.controlPosition;
  82299. }
  82300. if (controlStyle.position === 'none' && !has(controlStyle, 'show')) {
  82301. controlStyle.show = false;
  82302. delete controlStyle.position;
  82303. }
  82304. delete opt.controlPosition;
  82305. }
  82306. each(opt.data || [], function (dataItem) {
  82307. if (isObject(dataItem) && !isArray(dataItem)) {
  82308. if (!has(dataItem, 'value') && has(dataItem, 'name')) {
  82309. // In ec2, using name as value.
  82310. dataItem.value = dataItem.name;
  82311. }
  82312. transferItem(dataItem);
  82313. }
  82314. });
  82315. }
  82316. function transferItem(opt) {
  82317. var itemStyle = opt.itemStyle || (opt.itemStyle = {});
  82318. var itemStyleEmphasis = itemStyle.emphasis || (itemStyle.emphasis = {});
  82319. // Transfer label out
  82320. var label = opt.label || opt.label || {};
  82321. var labelNormal = label.normal || (label.normal = {});
  82322. var excludeLabelAttr = {
  82323. normal: 1,
  82324. emphasis: 1
  82325. };
  82326. each(label, function (value, name) {
  82327. if (!excludeLabelAttr[name] && !has(labelNormal, name)) {
  82328. labelNormal[name] = value;
  82329. }
  82330. });
  82331. if (itemStyleEmphasis.label && !has(label, 'emphasis')) {
  82332. label.emphasis = itemStyleEmphasis.label;
  82333. delete itemStyleEmphasis.label;
  82334. }
  82335. }
  82336. function has(obj, attr) {
  82337. return obj.hasOwnProperty(attr);
  82338. }
  82339. function install$F(registers) {
  82340. registers.registerComponentModel(SliderTimelineModel);
  82341. registers.registerComponentView(SliderTimelineView);
  82342. registers.registerSubTypeDefaulter('timeline', function () {
  82343. // Only slider now.
  82344. return 'slider';
  82345. });
  82346. installTimelineAction(registers);
  82347. registers.registerPreprocessor(timelinePreprocessor);
  82348. }
  82349. function checkMarkerInSeries(seriesOpts, markerType) {
  82350. if (!seriesOpts) {
  82351. return false;
  82352. }
  82353. var seriesOptArr = isArray(seriesOpts) ? seriesOpts : [seriesOpts];
  82354. for (var idx = 0; idx < seriesOptArr.length; idx++) {
  82355. if (seriesOptArr[idx] && seriesOptArr[idx][markerType]) {
  82356. return true;
  82357. }
  82358. }
  82359. return false;
  82360. }
  82361. function fillLabel(opt) {
  82362. defaultEmphasis(opt, 'label', ['show']);
  82363. }
  82364. // { [componentType]: MarkerModel }
  82365. var inner$i = makeInner();
  82366. var MarkerModel = /** @class */function (_super) {
  82367. __extends(MarkerModel, _super);
  82368. function MarkerModel() {
  82369. var _this = _super !== null && _super.apply(this, arguments) || this;
  82370. _this.type = MarkerModel.type;
  82371. /**
  82372. * If marker model is created by self from series
  82373. */
  82374. _this.createdBySelf = false;
  82375. _this.preventAutoZ = true;
  82376. return _this;
  82377. }
  82378. /**
  82379. * @overrite
  82380. */
  82381. MarkerModel.prototype.init = function (option, parentModel, ecModel) {
  82382. if ("development" !== 'production') {
  82383. if (this.type === 'marker') {
  82384. throw new Error('Marker component is abstract component. Use markLine, markPoint, markArea instead.');
  82385. }
  82386. }
  82387. this.mergeDefaultAndTheme(option, ecModel);
  82388. this._mergeOption(option, ecModel, false, true);
  82389. };
  82390. MarkerModel.prototype.isAnimationEnabled = function () {
  82391. if (env.node) {
  82392. return false;
  82393. }
  82394. var hostSeries = this.__hostSeries;
  82395. return this.getShallow('animation') && hostSeries && hostSeries.isAnimationEnabled();
  82396. };
  82397. /**
  82398. * @overrite
  82399. */
  82400. MarkerModel.prototype.mergeOption = function (newOpt, ecModel) {
  82401. this._mergeOption(newOpt, ecModel, false, false);
  82402. };
  82403. MarkerModel.prototype._mergeOption = function (newOpt, ecModel, createdBySelf, isInit) {
  82404. var componentType = this.mainType;
  82405. if (!createdBySelf) {
  82406. ecModel.eachSeries(function (seriesModel) {
  82407. // mainType can be markPoint, markLine, markArea
  82408. var markerOpt = seriesModel.get(this.mainType, true);
  82409. var markerModel = inner$i(seriesModel)[componentType];
  82410. if (!markerOpt || !markerOpt.data) {
  82411. inner$i(seriesModel)[componentType] = null;
  82412. return;
  82413. }
  82414. if (!markerModel) {
  82415. if (isInit) {
  82416. // Default label emphasis `position` and `show`
  82417. fillLabel(markerOpt);
  82418. }
  82419. each(markerOpt.data, function (item) {
  82420. // FIXME Overwrite fillLabel method ?
  82421. if (item instanceof Array) {
  82422. fillLabel(item[0]);
  82423. fillLabel(item[1]);
  82424. } else {
  82425. fillLabel(item);
  82426. }
  82427. });
  82428. markerModel = this.createMarkerModelFromSeries(markerOpt, this, ecModel);
  82429. // markerModel = new ImplementedMarkerModel(
  82430. // markerOpt, this, ecModel
  82431. // );
  82432. extend(markerModel, {
  82433. mainType: this.mainType,
  82434. // Use the same series index and name
  82435. seriesIndex: seriesModel.seriesIndex,
  82436. name: seriesModel.name,
  82437. createdBySelf: true
  82438. });
  82439. markerModel.__hostSeries = seriesModel;
  82440. } else {
  82441. markerModel._mergeOption(markerOpt, ecModel, true);
  82442. }
  82443. inner$i(seriesModel)[componentType] = markerModel;
  82444. }, this);
  82445. }
  82446. };
  82447. MarkerModel.prototype.formatTooltip = function (dataIndex, multipleSeries, dataType) {
  82448. var data = this.getData();
  82449. var value = this.getRawValue(dataIndex);
  82450. var itemName = data.getName(dataIndex);
  82451. return createTooltipMarkup('section', {
  82452. header: this.name,
  82453. blocks: [createTooltipMarkup('nameValue', {
  82454. name: itemName,
  82455. value: value,
  82456. noName: !itemName,
  82457. noValue: value == null
  82458. })]
  82459. });
  82460. };
  82461. MarkerModel.prototype.getData = function () {
  82462. return this._data;
  82463. };
  82464. MarkerModel.prototype.setData = function (data) {
  82465. this._data = data;
  82466. };
  82467. MarkerModel.prototype.getDataParams = function (dataIndex, dataType) {
  82468. var params = DataFormatMixin.prototype.getDataParams.call(this, dataIndex, dataType);
  82469. var hostSeries = this.__hostSeries;
  82470. if (hostSeries) {
  82471. params.seriesId = hostSeries.id;
  82472. params.seriesName = hostSeries.name;
  82473. params.seriesType = hostSeries.subType;
  82474. }
  82475. return params;
  82476. };
  82477. MarkerModel.getMarkerModelFromSeries = function (seriesModel,
  82478. // Support three types of markers. Strict check.
  82479. componentType) {
  82480. return inner$i(seriesModel)[componentType];
  82481. };
  82482. MarkerModel.type = 'marker';
  82483. MarkerModel.dependencies = ['series', 'grid', 'polar', 'geo'];
  82484. return MarkerModel;
  82485. }(ComponentModel);
  82486. mixin(MarkerModel, DataFormatMixin.prototype);
  82487. var MarkPointModel = /** @class */function (_super) {
  82488. __extends(MarkPointModel, _super);
  82489. function MarkPointModel() {
  82490. var _this = _super !== null && _super.apply(this, arguments) || this;
  82491. _this.type = MarkPointModel.type;
  82492. return _this;
  82493. }
  82494. MarkPointModel.prototype.createMarkerModelFromSeries = function (markerOpt, masterMarkerModel, ecModel) {
  82495. return new MarkPointModel(markerOpt, masterMarkerModel, ecModel);
  82496. };
  82497. MarkPointModel.type = 'markPoint';
  82498. MarkPointModel.defaultOption = {
  82499. // zlevel: 0,
  82500. z: 5,
  82501. symbol: 'pin',
  82502. symbolSize: 50,
  82503. // symbolRotate: 0,
  82504. // symbolOffset: [0, 0]
  82505. tooltip: {
  82506. trigger: 'item'
  82507. },
  82508. label: {
  82509. show: true,
  82510. position: 'inside'
  82511. },
  82512. itemStyle: {
  82513. borderWidth: 2
  82514. },
  82515. emphasis: {
  82516. label: {
  82517. show: true
  82518. }
  82519. }
  82520. };
  82521. return MarkPointModel;
  82522. }(MarkerModel);
  82523. function hasXOrY(item) {
  82524. return !(isNaN(parseFloat(item.x)) && isNaN(parseFloat(item.y)));
  82525. }
  82526. function hasXAndY(item) {
  82527. return !isNaN(parseFloat(item.x)) && !isNaN(parseFloat(item.y));
  82528. }
  82529. function markerTypeCalculatorWithExtent(markerType, data, axisDim, otherDataDim, targetDataDim, otherCoordIndex, targetCoordIndex) {
  82530. var coordArr = [];
  82531. var stacked = isDimensionStacked(data, targetDataDim /* , otherDataDim */);
  82532. var calcDataDim = stacked ? data.getCalculationInfo('stackResultDimension') : targetDataDim;
  82533. var value = numCalculate(data, calcDataDim, markerType);
  82534. var seriesModel = data.hostModel;
  82535. var dataIndex = seriesModel.indicesOfNearest(axisDim, calcDataDim, value)[0];
  82536. coordArr[otherCoordIndex] = data.get(otherDataDim, dataIndex);
  82537. coordArr[targetCoordIndex] = data.get(calcDataDim, dataIndex);
  82538. var coordArrValue = data.get(targetDataDim, dataIndex);
  82539. // Make it simple, do not visit all stacked value to count precision.
  82540. var precision = getPrecision(data.get(targetDataDim, dataIndex));
  82541. precision = Math.min(precision, 20);
  82542. if (precision >= 0) {
  82543. coordArr[targetCoordIndex] = +coordArr[targetCoordIndex].toFixed(precision);
  82544. }
  82545. return [coordArr, coordArrValue];
  82546. }
  82547. // TODO Specified percent
  82548. var markerTypeCalculator = {
  82549. min: curry(markerTypeCalculatorWithExtent, 'min'),
  82550. max: curry(markerTypeCalculatorWithExtent, 'max'),
  82551. average: curry(markerTypeCalculatorWithExtent, 'average'),
  82552. median: curry(markerTypeCalculatorWithExtent, 'median')
  82553. };
  82554. /**
  82555. * Transform markPoint data item to format used in List by do the following
  82556. * 1. Calculate statistic like `max`, `min`, `average`
  82557. * 2. Convert `item.xAxis`, `item.yAxis` to `item.coord` array
  82558. */
  82559. function dataTransform(seriesModel, item) {
  82560. if (!item) {
  82561. return;
  82562. }
  82563. var data = seriesModel.getData();
  82564. var coordSys = seriesModel.coordinateSystem;
  82565. var dims = coordSys && coordSys.dimensions;
  82566. // 1. If not specify the position with pixel directly
  82567. // 2. If `coord` is not a data array. Which uses `xAxis`,
  82568. // `yAxis` to specify the coord on each dimension
  82569. // parseFloat first because item.x and item.y can be percent string like '20%'
  82570. if (!hasXAndY(item) && !isArray(item.coord) && isArray(dims)) {
  82571. var axisInfo = getAxisInfo$1(item, data, coordSys, seriesModel);
  82572. // Clone the option
  82573. // Transform the properties xAxis, yAxis, radiusAxis, angleAxis, geoCoord to value
  82574. item = clone(item);
  82575. if (item.type && markerTypeCalculator[item.type] && axisInfo.baseAxis && axisInfo.valueAxis) {
  82576. var otherCoordIndex = indexOf(dims, axisInfo.baseAxis.dim);
  82577. var targetCoordIndex = indexOf(dims, axisInfo.valueAxis.dim);
  82578. var coordInfo = markerTypeCalculator[item.type](data, axisInfo.valueAxis.dim, axisInfo.baseDataDim, axisInfo.valueDataDim, otherCoordIndex, targetCoordIndex);
  82579. item.coord = coordInfo[0];
  82580. // Force to use the value of calculated value.
  82581. // let item use the value without stack.
  82582. item.value = coordInfo[1];
  82583. } else {
  82584. // FIXME Only has one of xAxis and yAxis.
  82585. item.coord = [item.xAxis != null ? item.xAxis : item.radiusAxis, item.yAxis != null ? item.yAxis : item.angleAxis];
  82586. }
  82587. }
  82588. // x y is provided
  82589. if (item.coord == null || !isArray(dims)) {
  82590. item.coord = [];
  82591. var baseAxis = seriesModel.getBaseAxis();
  82592. if (baseAxis && item.type && markerTypeCalculator[item.type]) {
  82593. var otherAxis = coordSys.getOtherAxis(baseAxis);
  82594. if (otherAxis) {
  82595. item.value = numCalculate(data, data.mapDimension(otherAxis.dim), item.type);
  82596. }
  82597. }
  82598. } else {
  82599. // Each coord support max, min, average
  82600. var coord = item.coord;
  82601. for (var i = 0; i < 2; i++) {
  82602. if (markerTypeCalculator[coord[i]]) {
  82603. coord[i] = numCalculate(data, data.mapDimension(dims[i]), coord[i]);
  82604. }
  82605. }
  82606. }
  82607. return item;
  82608. }
  82609. function getAxisInfo$1(item, data, coordSys, seriesModel) {
  82610. var ret = {};
  82611. if (item.valueIndex != null || item.valueDim != null) {
  82612. ret.valueDataDim = item.valueIndex != null ? data.getDimension(item.valueIndex) : item.valueDim;
  82613. ret.valueAxis = coordSys.getAxis(dataDimToCoordDim(seriesModel, ret.valueDataDim));
  82614. ret.baseAxis = coordSys.getOtherAxis(ret.valueAxis);
  82615. ret.baseDataDim = data.mapDimension(ret.baseAxis.dim);
  82616. } else {
  82617. ret.baseAxis = seriesModel.getBaseAxis();
  82618. ret.valueAxis = coordSys.getOtherAxis(ret.baseAxis);
  82619. ret.baseDataDim = data.mapDimension(ret.baseAxis.dim);
  82620. ret.valueDataDim = data.mapDimension(ret.valueAxis.dim);
  82621. }
  82622. return ret;
  82623. }
  82624. function dataDimToCoordDim(seriesModel, dataDim) {
  82625. var dimItem = seriesModel.getData().getDimensionInfo(dataDim);
  82626. return dimItem && dimItem.coordDim;
  82627. }
  82628. /**
  82629. * Filter data which is out of coordinateSystem range
  82630. * [dataFilter description]
  82631. */
  82632. function dataFilter$1(
  82633. // Currently only polar and cartesian has containData.
  82634. coordSys, item) {
  82635. // Always return true if there is no coordSys
  82636. return coordSys && coordSys.containData && item.coord && !hasXOrY(item) ? coordSys.containData(item.coord) : true;
  82637. }
  82638. function zoneFilter(
  82639. // Currently only polar and cartesian has containData.
  82640. coordSys, item1, item2) {
  82641. // Always return true if there is no coordSys
  82642. return coordSys && coordSys.containZone && item1.coord && item2.coord && !hasXOrY(item1) && !hasXOrY(item2) ? coordSys.containZone(item1.coord, item2.coord) : true;
  82643. }
  82644. function createMarkerDimValueGetter(inCoordSys, dims) {
  82645. return inCoordSys ? function (item, dimName, dataIndex, dimIndex) {
  82646. var rawVal = dimIndex < 2
  82647. // x, y, radius, angle
  82648. ? item.coord && item.coord[dimIndex] : item.value;
  82649. return parseDataValue(rawVal, dims[dimIndex]);
  82650. } : function (item, dimName, dataIndex, dimIndex) {
  82651. return parseDataValue(item.value, dims[dimIndex]);
  82652. };
  82653. }
  82654. function numCalculate(data, valueDataDim, type) {
  82655. if (type === 'average') {
  82656. var sum_1 = 0;
  82657. var count_1 = 0;
  82658. data.each(valueDataDim, function (val, idx) {
  82659. if (!isNaN(val)) {
  82660. sum_1 += val;
  82661. count_1++;
  82662. }
  82663. });
  82664. return sum_1 / count_1;
  82665. } else if (type === 'median') {
  82666. return data.getMedian(valueDataDim);
  82667. } else {
  82668. // max & min
  82669. return data.getDataExtent(valueDataDim)[type === 'max' ? 1 : 0];
  82670. }
  82671. }
  82672. var inner$j = makeInner();
  82673. var MarkerView = /** @class */function (_super) {
  82674. __extends(MarkerView, _super);
  82675. function MarkerView() {
  82676. var _this = _super !== null && _super.apply(this, arguments) || this;
  82677. _this.type = MarkerView.type;
  82678. return _this;
  82679. }
  82680. MarkerView.prototype.init = function () {
  82681. this.markerGroupMap = createHashMap();
  82682. };
  82683. MarkerView.prototype.render = function (markerModel, ecModel, api) {
  82684. var _this = this;
  82685. var markerGroupMap = this.markerGroupMap;
  82686. markerGroupMap.each(function (item) {
  82687. inner$j(item).keep = false;
  82688. });
  82689. ecModel.eachSeries(function (seriesModel) {
  82690. var markerModel = MarkerModel.getMarkerModelFromSeries(seriesModel, _this.type);
  82691. markerModel && _this.renderSeries(seriesModel, markerModel, ecModel, api);
  82692. });
  82693. markerGroupMap.each(function (item) {
  82694. !inner$j(item).keep && _this.group.remove(item.group);
  82695. });
  82696. updateZ$2(ecModel, markerGroupMap, this.type);
  82697. };
  82698. MarkerView.prototype.markKeep = function (drawGroup) {
  82699. inner$j(drawGroup).keep = true;
  82700. };
  82701. MarkerView.prototype.toggleBlurSeries = function (seriesModelList, isBlur) {
  82702. var _this = this;
  82703. each(seriesModelList, function (seriesModel) {
  82704. var markerModel = MarkerModel.getMarkerModelFromSeries(seriesModel, _this.type);
  82705. if (markerModel) {
  82706. var data = markerModel.getData();
  82707. data.eachItemGraphicEl(function (el) {
  82708. if (el) {
  82709. isBlur ? enterBlur(el) : leaveBlur(el);
  82710. }
  82711. });
  82712. }
  82713. });
  82714. };
  82715. MarkerView.type = 'marker';
  82716. return MarkerView;
  82717. }(ComponentView);
  82718. function updateZ$2(ecModel, markerGroupMap, type) {
  82719. ecModel.eachSeries(function (seriesModel) {
  82720. var markerModel = MarkerModel.getMarkerModelFromSeries(seriesModel, type);
  82721. var markerDraw = markerGroupMap.get(seriesModel.id);
  82722. if (markerModel && markerDraw && markerDraw.group) {
  82723. var _a = retrieveZInfo(markerModel),
  82724. z = _a.z,
  82725. zlevel = _a.zlevel;
  82726. traverseUpdateZ(markerDraw.group, z, zlevel);
  82727. }
  82728. });
  82729. }
  82730. function updateMarkerLayout(mpData, seriesModel, api) {
  82731. var coordSys = seriesModel.coordinateSystem;
  82732. var apiWidth = api.getWidth();
  82733. var apiHeight = api.getHeight();
  82734. var coordRect = coordSys && coordSys.getArea && coordSys.getArea();
  82735. mpData.each(function (idx) {
  82736. var itemModel = mpData.getItemModel(idx);
  82737. var isRelativeToCoordinate = itemModel.get('relativeTo') === 'coordinate';
  82738. var width = isRelativeToCoordinate ? coordRect ? coordRect.width : 0 : apiWidth;
  82739. var height = isRelativeToCoordinate ? coordRect ? coordRect.height : 0 : apiHeight;
  82740. var left = isRelativeToCoordinate && coordRect ? coordRect.x : 0;
  82741. var top = isRelativeToCoordinate && coordRect ? coordRect.y : 0;
  82742. var point;
  82743. var xPx = parsePercent$1(itemModel.get('x'), width) + left;
  82744. var yPx = parsePercent$1(itemModel.get('y'), height) + top;
  82745. if (!isNaN(xPx) && !isNaN(yPx)) {
  82746. point = [xPx, yPx];
  82747. }
  82748. // Chart like bar may have there own marker positioning logic
  82749. else if (seriesModel.getMarkerPosition) {
  82750. // Use the getMarkerPosition
  82751. point = seriesModel.getMarkerPosition(mpData.getValues(mpData.dimensions, idx));
  82752. } else if (coordSys) {
  82753. var x = mpData.get(coordSys.dimensions[0], idx);
  82754. var y = mpData.get(coordSys.dimensions[1], idx);
  82755. point = coordSys.dataToPoint([x, y]);
  82756. }
  82757. // Use x, y if has any
  82758. if (!isNaN(xPx)) {
  82759. point[0] = xPx;
  82760. }
  82761. if (!isNaN(yPx)) {
  82762. point[1] = yPx;
  82763. }
  82764. mpData.setItemLayout(idx, point);
  82765. });
  82766. }
  82767. var MarkPointView = /** @class */function (_super) {
  82768. __extends(MarkPointView, _super);
  82769. function MarkPointView() {
  82770. var _this = _super !== null && _super.apply(this, arguments) || this;
  82771. _this.type = MarkPointView.type;
  82772. return _this;
  82773. }
  82774. MarkPointView.prototype.updateTransform = function (markPointModel, ecModel, api) {
  82775. ecModel.eachSeries(function (seriesModel) {
  82776. var mpModel = MarkerModel.getMarkerModelFromSeries(seriesModel, 'markPoint');
  82777. if (mpModel) {
  82778. updateMarkerLayout(mpModel.getData(), seriesModel, api);
  82779. this.markerGroupMap.get(seriesModel.id).updateLayout();
  82780. }
  82781. }, this);
  82782. };
  82783. MarkPointView.prototype.renderSeries = function (seriesModel, mpModel, ecModel, api) {
  82784. var coordSys = seriesModel.coordinateSystem;
  82785. var seriesId = seriesModel.id;
  82786. var seriesData = seriesModel.getData();
  82787. var symbolDrawMap = this.markerGroupMap;
  82788. var symbolDraw = symbolDrawMap.get(seriesId) || symbolDrawMap.set(seriesId, new SymbolDraw());
  82789. var mpData = createData(coordSys, seriesModel, mpModel);
  82790. // FIXME
  82791. mpModel.setData(mpData);
  82792. updateMarkerLayout(mpModel.getData(), seriesModel, api);
  82793. mpData.each(function (idx) {
  82794. var itemModel = mpData.getItemModel(idx);
  82795. var symbol = itemModel.getShallow('symbol');
  82796. var symbolSize = itemModel.getShallow('symbolSize');
  82797. var symbolRotate = itemModel.getShallow('symbolRotate');
  82798. var symbolOffset = itemModel.getShallow('symbolOffset');
  82799. var symbolKeepAspect = itemModel.getShallow('symbolKeepAspect');
  82800. // TODO: refactor needed: single data item should not support callback function
  82801. if (isFunction(symbol) || isFunction(symbolSize) || isFunction(symbolRotate) || isFunction(symbolOffset)) {
  82802. var rawIdx = mpModel.getRawValue(idx);
  82803. var dataParams = mpModel.getDataParams(idx);
  82804. if (isFunction(symbol)) {
  82805. symbol = symbol(rawIdx, dataParams);
  82806. }
  82807. if (isFunction(symbolSize)) {
  82808. // FIXME 这里不兼容 ECharts 2.x,2.x 貌似参数是整个数据?
  82809. symbolSize = symbolSize(rawIdx, dataParams);
  82810. }
  82811. if (isFunction(symbolRotate)) {
  82812. symbolRotate = symbolRotate(rawIdx, dataParams);
  82813. }
  82814. if (isFunction(symbolOffset)) {
  82815. symbolOffset = symbolOffset(rawIdx, dataParams);
  82816. }
  82817. }
  82818. var style = itemModel.getModel('itemStyle').getItemStyle();
  82819. var z2 = itemModel.get('z2');
  82820. var color = getVisualFromData(seriesData, 'color');
  82821. if (!style.fill) {
  82822. style.fill = color;
  82823. }
  82824. mpData.setItemVisual(idx, {
  82825. z2: retrieve2(z2, 0),
  82826. symbol: symbol,
  82827. symbolSize: symbolSize,
  82828. symbolRotate: symbolRotate,
  82829. symbolOffset: symbolOffset,
  82830. symbolKeepAspect: symbolKeepAspect,
  82831. style: style
  82832. });
  82833. });
  82834. // TODO Text are wrong
  82835. symbolDraw.updateData(mpData);
  82836. this.group.add(symbolDraw.group);
  82837. // Set host model for tooltip
  82838. // FIXME
  82839. mpData.eachItemGraphicEl(function (el) {
  82840. el.traverse(function (child) {
  82841. getECData(child).dataModel = mpModel;
  82842. });
  82843. });
  82844. this.markKeep(symbolDraw);
  82845. symbolDraw.group.silent = mpModel.get('silent') || seriesModel.get('silent');
  82846. };
  82847. MarkPointView.type = 'markPoint';
  82848. return MarkPointView;
  82849. }(MarkerView);
  82850. function createData(coordSys, seriesModel, mpModel) {
  82851. var coordDimsInfos;
  82852. if (coordSys) {
  82853. coordDimsInfos = map(coordSys && coordSys.dimensions, function (coordDim) {
  82854. var info = seriesModel.getData().getDimensionInfo(seriesModel.getData().mapDimension(coordDim)) || {};
  82855. // In map series data don't have lng and lat dimension. Fallback to same with coordSys
  82856. return extend(extend({}, info), {
  82857. name: coordDim,
  82858. // DON'T use ordinalMeta to parse and collect ordinal.
  82859. ordinalMeta: null
  82860. });
  82861. });
  82862. } else {
  82863. coordDimsInfos = [{
  82864. name: 'value',
  82865. type: 'float'
  82866. }];
  82867. }
  82868. var mpData = new SeriesData(coordDimsInfos, mpModel);
  82869. var dataOpt = map(mpModel.get('data'), curry(dataTransform, seriesModel));
  82870. if (coordSys) {
  82871. dataOpt = filter(dataOpt, curry(dataFilter$1, coordSys));
  82872. }
  82873. var dimValueGetter = createMarkerDimValueGetter(!!coordSys, coordDimsInfos);
  82874. mpData.initData(dataOpt, null, dimValueGetter);
  82875. return mpData;
  82876. }
  82877. function install$G(registers) {
  82878. registers.registerComponentModel(MarkPointModel);
  82879. registers.registerComponentView(MarkPointView);
  82880. registers.registerPreprocessor(function (opt) {
  82881. if (checkMarkerInSeries(opt.series, 'markPoint')) {
  82882. // Make sure markPoint component is enabled
  82883. opt.markPoint = opt.markPoint || {};
  82884. }
  82885. });
  82886. }
  82887. var MarkLineModel = /** @class */function (_super) {
  82888. __extends(MarkLineModel, _super);
  82889. function MarkLineModel() {
  82890. var _this = _super !== null && _super.apply(this, arguments) || this;
  82891. _this.type = MarkLineModel.type;
  82892. return _this;
  82893. }
  82894. MarkLineModel.prototype.createMarkerModelFromSeries = function (markerOpt, masterMarkerModel, ecModel) {
  82895. return new MarkLineModel(markerOpt, masterMarkerModel, ecModel);
  82896. };
  82897. MarkLineModel.type = 'markLine';
  82898. MarkLineModel.defaultOption = {
  82899. // zlevel: 0,
  82900. z: 5,
  82901. symbol: ['circle', 'arrow'],
  82902. symbolSize: [8, 16],
  82903. // symbolRotate: 0,
  82904. symbolOffset: 0,
  82905. precision: 2,
  82906. tooltip: {
  82907. trigger: 'item'
  82908. },
  82909. label: {
  82910. show: true,
  82911. position: 'end',
  82912. distance: 5
  82913. },
  82914. lineStyle: {
  82915. type: 'dashed'
  82916. },
  82917. emphasis: {
  82918. label: {
  82919. show: true
  82920. },
  82921. lineStyle: {
  82922. width: 3
  82923. }
  82924. },
  82925. animationEasing: 'linear'
  82926. };
  82927. return MarkLineModel;
  82928. }(MarkerModel);
  82929. var inner$k = makeInner();
  82930. var markLineTransform = function (seriesModel, coordSys, mlModel, item) {
  82931. var data = seriesModel.getData();
  82932. var itemArray;
  82933. if (!isArray(item)) {
  82934. // Special type markLine like 'min', 'max', 'average', 'median'
  82935. var mlType = item.type;
  82936. if (mlType === 'min' || mlType === 'max' || mlType === 'average' || mlType === 'median'
  82937. // In case
  82938. // data: [{
  82939. // yAxis: 10
  82940. // }]
  82941. || item.xAxis != null || item.yAxis != null) {
  82942. var valueAxis = void 0;
  82943. var value = void 0;
  82944. if (item.yAxis != null || item.xAxis != null) {
  82945. valueAxis = coordSys.getAxis(item.yAxis != null ? 'y' : 'x');
  82946. value = retrieve(item.yAxis, item.xAxis);
  82947. } else {
  82948. var axisInfo = getAxisInfo$1(item, data, coordSys, seriesModel);
  82949. valueAxis = axisInfo.valueAxis;
  82950. var valueDataDim = getStackedDimension(data, axisInfo.valueDataDim);
  82951. value = numCalculate(data, valueDataDim, mlType);
  82952. }
  82953. var valueIndex = valueAxis.dim === 'x' ? 0 : 1;
  82954. var baseIndex = 1 - valueIndex;
  82955. // Normized to 2d data with start and end point
  82956. var mlFrom = clone(item);
  82957. var mlTo = {
  82958. coord: []
  82959. };
  82960. mlFrom.type = null;
  82961. mlFrom.coord = [];
  82962. mlFrom.coord[baseIndex] = -Infinity;
  82963. mlTo.coord[baseIndex] = Infinity;
  82964. var precision = mlModel.get('precision');
  82965. if (precision >= 0 && isNumber(value)) {
  82966. value = +value.toFixed(Math.min(precision, 20));
  82967. }
  82968. mlFrom.coord[valueIndex] = mlTo.coord[valueIndex] = value;
  82969. itemArray = [mlFrom, mlTo, {
  82970. type: mlType,
  82971. valueIndex: item.valueIndex,
  82972. // Force to use the value of calculated value.
  82973. value: value
  82974. }];
  82975. } else {
  82976. // Invalid data
  82977. if ("development" !== 'production') {
  82978. logError('Invalid markLine data.');
  82979. }
  82980. itemArray = [];
  82981. }
  82982. } else {
  82983. itemArray = item;
  82984. }
  82985. var normalizedItem = [dataTransform(seriesModel, itemArray[0]), dataTransform(seriesModel, itemArray[1]), extend({}, itemArray[2])];
  82986. // Avoid line data type is extended by from(to) data type
  82987. normalizedItem[2].type = normalizedItem[2].type || null;
  82988. // Merge from option and to option into line option
  82989. merge(normalizedItem[2], normalizedItem[0]);
  82990. merge(normalizedItem[2], normalizedItem[1]);
  82991. return normalizedItem;
  82992. };
  82993. function isInfinity(val) {
  82994. return !isNaN(val) && !isFinite(val);
  82995. }
  82996. // If a markLine has one dim
  82997. function ifMarkLineHasOnlyDim(dimIndex, fromCoord, toCoord, coordSys) {
  82998. var otherDimIndex = 1 - dimIndex;
  82999. var dimName = coordSys.dimensions[dimIndex];
  83000. return isInfinity(fromCoord[otherDimIndex]) && isInfinity(toCoord[otherDimIndex]) && fromCoord[dimIndex] === toCoord[dimIndex] && coordSys.getAxis(dimName).containData(fromCoord[dimIndex]);
  83001. }
  83002. function markLineFilter(coordSys, item) {
  83003. if (coordSys.type === 'cartesian2d') {
  83004. var fromCoord = item[0].coord;
  83005. var toCoord = item[1].coord;
  83006. // In case
  83007. // {
  83008. // markLine: {
  83009. // data: [{ yAxis: 2 }]
  83010. // }
  83011. // }
  83012. if (fromCoord && toCoord && (ifMarkLineHasOnlyDim(1, fromCoord, toCoord, coordSys) || ifMarkLineHasOnlyDim(0, fromCoord, toCoord, coordSys))) {
  83013. return true;
  83014. }
  83015. }
  83016. return dataFilter$1(coordSys, item[0]) && dataFilter$1(coordSys, item[1]);
  83017. }
  83018. function updateSingleMarkerEndLayout(data, idx, isFrom, seriesModel, api) {
  83019. var coordSys = seriesModel.coordinateSystem;
  83020. var itemModel = data.getItemModel(idx);
  83021. var point;
  83022. var xPx = parsePercent$1(itemModel.get('x'), api.getWidth());
  83023. var yPx = parsePercent$1(itemModel.get('y'), api.getHeight());
  83024. if (!isNaN(xPx) && !isNaN(yPx)) {
  83025. point = [xPx, yPx];
  83026. } else {
  83027. // Chart like bar may have there own marker positioning logic
  83028. if (seriesModel.getMarkerPosition) {
  83029. // Use the getMarkerPosition
  83030. point = seriesModel.getMarkerPosition(data.getValues(data.dimensions, idx));
  83031. } else {
  83032. var dims = coordSys.dimensions;
  83033. var x = data.get(dims[0], idx);
  83034. var y = data.get(dims[1], idx);
  83035. point = coordSys.dataToPoint([x, y]);
  83036. }
  83037. // Expand line to the edge of grid if value on one axis is Inifnity
  83038. // In case
  83039. // markLine: {
  83040. // data: [{
  83041. // yAxis: 2
  83042. // // or
  83043. // type: 'average'
  83044. // }]
  83045. // }
  83046. if (isCoordinateSystemType(coordSys, 'cartesian2d')) {
  83047. // TODO: TYPE ts@4.1 may still infer it as Axis instead of Axis2D. Not sure if it's a bug
  83048. var xAxis = coordSys.getAxis('x');
  83049. var yAxis = coordSys.getAxis('y');
  83050. var dims = coordSys.dimensions;
  83051. if (isInfinity(data.get(dims[0], idx))) {
  83052. point[0] = xAxis.toGlobalCoord(xAxis.getExtent()[isFrom ? 0 : 1]);
  83053. } else if (isInfinity(data.get(dims[1], idx))) {
  83054. point[1] = yAxis.toGlobalCoord(yAxis.getExtent()[isFrom ? 0 : 1]);
  83055. }
  83056. }
  83057. // Use x, y if has any
  83058. if (!isNaN(xPx)) {
  83059. point[0] = xPx;
  83060. }
  83061. if (!isNaN(yPx)) {
  83062. point[1] = yPx;
  83063. }
  83064. }
  83065. data.setItemLayout(idx, point);
  83066. }
  83067. var MarkLineView = /** @class */function (_super) {
  83068. __extends(MarkLineView, _super);
  83069. function MarkLineView() {
  83070. var _this = _super !== null && _super.apply(this, arguments) || this;
  83071. _this.type = MarkLineView.type;
  83072. return _this;
  83073. }
  83074. MarkLineView.prototype.updateTransform = function (markLineModel, ecModel, api) {
  83075. ecModel.eachSeries(function (seriesModel) {
  83076. var mlModel = MarkerModel.getMarkerModelFromSeries(seriesModel, 'markLine');
  83077. if (mlModel) {
  83078. var mlData_1 = mlModel.getData();
  83079. var fromData_1 = inner$k(mlModel).from;
  83080. var toData_1 = inner$k(mlModel).to;
  83081. // Update visual and layout of from symbol and to symbol
  83082. fromData_1.each(function (idx) {
  83083. updateSingleMarkerEndLayout(fromData_1, idx, true, seriesModel, api);
  83084. updateSingleMarkerEndLayout(toData_1, idx, false, seriesModel, api);
  83085. });
  83086. // Update layout of line
  83087. mlData_1.each(function (idx) {
  83088. mlData_1.setItemLayout(idx, [fromData_1.getItemLayout(idx), toData_1.getItemLayout(idx)]);
  83089. });
  83090. this.markerGroupMap.get(seriesModel.id).updateLayout();
  83091. }
  83092. }, this);
  83093. };
  83094. MarkLineView.prototype.renderSeries = function (seriesModel, mlModel, ecModel, api) {
  83095. var coordSys = seriesModel.coordinateSystem;
  83096. var seriesId = seriesModel.id;
  83097. var seriesData = seriesModel.getData();
  83098. var lineDrawMap = this.markerGroupMap;
  83099. var lineDraw = lineDrawMap.get(seriesId) || lineDrawMap.set(seriesId, new LineDraw());
  83100. this.group.add(lineDraw.group);
  83101. var mlData = createList$1(coordSys, seriesModel, mlModel);
  83102. var fromData = mlData.from;
  83103. var toData = mlData.to;
  83104. var lineData = mlData.line;
  83105. inner$k(mlModel).from = fromData;
  83106. inner$k(mlModel).to = toData;
  83107. // Line data for tooltip and formatter
  83108. mlModel.setData(lineData);
  83109. // TODO
  83110. // Functionally, `symbolSize` & `symbolOffset` can also be 2D array now.
  83111. // But the related logic and type definition are not finished yet.
  83112. // Finish it if required
  83113. var symbolType = mlModel.get('symbol');
  83114. var symbolSize = mlModel.get('symbolSize');
  83115. var symbolRotate = mlModel.get('symbolRotate');
  83116. var symbolOffset = mlModel.get('symbolOffset');
  83117. // TODO: support callback function like markPoint
  83118. if (!isArray(symbolType)) {
  83119. symbolType = [symbolType, symbolType];
  83120. }
  83121. if (!isArray(symbolSize)) {
  83122. symbolSize = [symbolSize, symbolSize];
  83123. }
  83124. if (!isArray(symbolRotate)) {
  83125. symbolRotate = [symbolRotate, symbolRotate];
  83126. }
  83127. if (!isArray(symbolOffset)) {
  83128. symbolOffset = [symbolOffset, symbolOffset];
  83129. }
  83130. // Update visual and layout of from symbol and to symbol
  83131. mlData.from.each(function (idx) {
  83132. updateDataVisualAndLayout(fromData, idx, true);
  83133. updateDataVisualAndLayout(toData, idx, false);
  83134. });
  83135. // Update visual and layout of line
  83136. lineData.each(function (idx) {
  83137. var itemModel = lineData.getItemModel(idx);
  83138. var lineStyle = itemModel.getModel('lineStyle').getLineStyle();
  83139. // lineData.setItemVisual(idx, {
  83140. // color: lineColor || fromData.getItemVisual(idx, 'color')
  83141. // });
  83142. lineData.setItemLayout(idx, [fromData.getItemLayout(idx), toData.getItemLayout(idx)]);
  83143. var z2 = itemModel.get('z2');
  83144. if (lineStyle.stroke == null) {
  83145. lineStyle.stroke = fromData.getItemVisual(idx, 'style').fill;
  83146. }
  83147. lineData.setItemVisual(idx, {
  83148. z2: retrieve2(z2, 0),
  83149. fromSymbolKeepAspect: fromData.getItemVisual(idx, 'symbolKeepAspect'),
  83150. fromSymbolOffset: fromData.getItemVisual(idx, 'symbolOffset'),
  83151. fromSymbolRotate: fromData.getItemVisual(idx, 'symbolRotate'),
  83152. fromSymbolSize: fromData.getItemVisual(idx, 'symbolSize'),
  83153. fromSymbol: fromData.getItemVisual(idx, 'symbol'),
  83154. toSymbolKeepAspect: toData.getItemVisual(idx, 'symbolKeepAspect'),
  83155. toSymbolOffset: toData.getItemVisual(idx, 'symbolOffset'),
  83156. toSymbolRotate: toData.getItemVisual(idx, 'symbolRotate'),
  83157. toSymbolSize: toData.getItemVisual(idx, 'symbolSize'),
  83158. toSymbol: toData.getItemVisual(idx, 'symbol'),
  83159. style: lineStyle
  83160. });
  83161. });
  83162. lineDraw.updateData(lineData);
  83163. // Set host model for tooltip
  83164. // FIXME
  83165. mlData.line.eachItemGraphicEl(function (el) {
  83166. getECData(el).dataModel = mlModel;
  83167. el.traverse(function (child) {
  83168. getECData(child).dataModel = mlModel;
  83169. });
  83170. });
  83171. function updateDataVisualAndLayout(data, idx, isFrom) {
  83172. var itemModel = data.getItemModel(idx);
  83173. updateSingleMarkerEndLayout(data, idx, isFrom, seriesModel, api);
  83174. var style = itemModel.getModel('itemStyle').getItemStyle();
  83175. if (style.fill == null) {
  83176. style.fill = getVisualFromData(seriesData, 'color');
  83177. }
  83178. data.setItemVisual(idx, {
  83179. symbolKeepAspect: itemModel.get('symbolKeepAspect'),
  83180. // `0` should be considered as a valid value, so use `retrieve2` instead of `||`
  83181. symbolOffset: retrieve2(itemModel.get('symbolOffset', true), symbolOffset[isFrom ? 0 : 1]),
  83182. symbolRotate: retrieve2(itemModel.get('symbolRotate', true), symbolRotate[isFrom ? 0 : 1]),
  83183. // TODO: when 2d array is supported, it should ignore parent
  83184. symbolSize: retrieve2(itemModel.get('symbolSize'), symbolSize[isFrom ? 0 : 1]),
  83185. symbol: retrieve2(itemModel.get('symbol', true), symbolType[isFrom ? 0 : 1]),
  83186. style: style
  83187. });
  83188. }
  83189. this.markKeep(lineDraw);
  83190. lineDraw.group.silent = mlModel.get('silent') || seriesModel.get('silent');
  83191. };
  83192. MarkLineView.type = 'markLine';
  83193. return MarkLineView;
  83194. }(MarkerView);
  83195. function createList$1(coordSys, seriesModel, mlModel) {
  83196. var coordDimsInfos;
  83197. if (coordSys) {
  83198. coordDimsInfos = map(coordSys && coordSys.dimensions, function (coordDim) {
  83199. var info = seriesModel.getData().getDimensionInfo(seriesModel.getData().mapDimension(coordDim)) || {};
  83200. // In map series data don't have lng and lat dimension. Fallback to same with coordSys
  83201. return extend(extend({}, info), {
  83202. name: coordDim,
  83203. // DON'T use ordinalMeta to parse and collect ordinal.
  83204. ordinalMeta: null
  83205. });
  83206. });
  83207. } else {
  83208. coordDimsInfos = [{
  83209. name: 'value',
  83210. type: 'float'
  83211. }];
  83212. }
  83213. var fromData = new SeriesData(coordDimsInfos, mlModel);
  83214. var toData = new SeriesData(coordDimsInfos, mlModel);
  83215. // No dimensions
  83216. var lineData = new SeriesData([], mlModel);
  83217. var optData = map(mlModel.get('data'), curry(markLineTransform, seriesModel, coordSys, mlModel));
  83218. if (coordSys) {
  83219. optData = filter(optData, curry(markLineFilter, coordSys));
  83220. }
  83221. var dimValueGetter = createMarkerDimValueGetter(!!coordSys, coordDimsInfos);
  83222. fromData.initData(map(optData, function (item) {
  83223. return item[0];
  83224. }), null, dimValueGetter);
  83225. toData.initData(map(optData, function (item) {
  83226. return item[1];
  83227. }), null, dimValueGetter);
  83228. lineData.initData(map(optData, function (item) {
  83229. return item[2];
  83230. }));
  83231. lineData.hasItemOption = true;
  83232. return {
  83233. from: fromData,
  83234. to: toData,
  83235. line: lineData
  83236. };
  83237. }
  83238. function install$H(registers) {
  83239. registers.registerComponentModel(MarkLineModel);
  83240. registers.registerComponentView(MarkLineView);
  83241. registers.registerPreprocessor(function (opt) {
  83242. if (checkMarkerInSeries(opt.series, 'markLine')) {
  83243. // Make sure markLine component is enabled
  83244. opt.markLine = opt.markLine || {};
  83245. }
  83246. });
  83247. }
  83248. var MarkAreaModel = /** @class */function (_super) {
  83249. __extends(MarkAreaModel, _super);
  83250. function MarkAreaModel() {
  83251. var _this = _super !== null && _super.apply(this, arguments) || this;
  83252. _this.type = MarkAreaModel.type;
  83253. return _this;
  83254. }
  83255. MarkAreaModel.prototype.createMarkerModelFromSeries = function (markerOpt, masterMarkerModel, ecModel) {
  83256. return new MarkAreaModel(markerOpt, masterMarkerModel, ecModel);
  83257. };
  83258. MarkAreaModel.type = 'markArea';
  83259. MarkAreaModel.defaultOption = {
  83260. // zlevel: 0,
  83261. // PENDING
  83262. z: 1,
  83263. tooltip: {
  83264. trigger: 'item'
  83265. },
  83266. // markArea should fixed on the coordinate system
  83267. animation: false,
  83268. label: {
  83269. show: true,
  83270. position: 'top'
  83271. },
  83272. itemStyle: {
  83273. // color and borderColor default to use color from series
  83274. // color: 'auto'
  83275. // borderColor: 'auto'
  83276. borderWidth: 0
  83277. },
  83278. emphasis: {
  83279. label: {
  83280. show: true,
  83281. position: 'top'
  83282. }
  83283. }
  83284. };
  83285. return MarkAreaModel;
  83286. }(MarkerModel);
  83287. var inner$l = makeInner();
  83288. var markAreaTransform = function (seriesModel, coordSys, maModel, item) {
  83289. // item may be null
  83290. var item0 = item[0];
  83291. var item1 = item[1];
  83292. if (!item0 || !item1) {
  83293. return;
  83294. }
  83295. var lt = dataTransform(seriesModel, item0);
  83296. var rb = dataTransform(seriesModel, item1);
  83297. // FIXME make sure lt is less than rb
  83298. var ltCoord = lt.coord;
  83299. var rbCoord = rb.coord;
  83300. ltCoord[0] = retrieve(ltCoord[0], -Infinity);
  83301. ltCoord[1] = retrieve(ltCoord[1], -Infinity);
  83302. rbCoord[0] = retrieve(rbCoord[0], Infinity);
  83303. rbCoord[1] = retrieve(rbCoord[1], Infinity);
  83304. // Merge option into one
  83305. var result = mergeAll([{}, lt, rb]);
  83306. result.coord = [lt.coord, rb.coord];
  83307. result.x0 = lt.x;
  83308. result.y0 = lt.y;
  83309. result.x1 = rb.x;
  83310. result.y1 = rb.y;
  83311. return result;
  83312. };
  83313. function isInfinity$1(val) {
  83314. return !isNaN(val) && !isFinite(val);
  83315. }
  83316. // If a markArea has one dim
  83317. function ifMarkAreaHasOnlyDim(dimIndex, fromCoord, toCoord, coordSys) {
  83318. var otherDimIndex = 1 - dimIndex;
  83319. return isInfinity$1(fromCoord[otherDimIndex]) && isInfinity$1(toCoord[otherDimIndex]);
  83320. }
  83321. function markAreaFilter(coordSys, item) {
  83322. var fromCoord = item.coord[0];
  83323. var toCoord = item.coord[1];
  83324. var item0 = {
  83325. coord: fromCoord,
  83326. x: item.x0,
  83327. y: item.y0
  83328. };
  83329. var item1 = {
  83330. coord: toCoord,
  83331. x: item.x1,
  83332. y: item.y1
  83333. };
  83334. if (isCoordinateSystemType(coordSys, 'cartesian2d')) {
  83335. // In case
  83336. // {
  83337. // markArea: {
  83338. // data: [{ yAxis: 2 }]
  83339. // }
  83340. // }
  83341. if (fromCoord && toCoord && (ifMarkAreaHasOnlyDim(1, fromCoord, toCoord) || ifMarkAreaHasOnlyDim(0, fromCoord, toCoord))) {
  83342. return true;
  83343. }
  83344. // Directly returning true may also do the work,
  83345. // because markArea will not be shown automatically
  83346. // when it's not included in coordinate system.
  83347. // But filtering ahead can avoid keeping rendering markArea
  83348. // when there are too many of them.
  83349. return zoneFilter(coordSys, item0, item1);
  83350. }
  83351. return dataFilter$1(coordSys, item0) || dataFilter$1(coordSys, item1);
  83352. }
  83353. // dims can be ['x0', 'y0'], ['x1', 'y1'], ['x0', 'y1'], ['x1', 'y0']
  83354. function getSingleMarkerEndPoint(data, idx, dims, seriesModel, api) {
  83355. var coordSys = seriesModel.coordinateSystem;
  83356. var itemModel = data.getItemModel(idx);
  83357. var point;
  83358. var xPx = parsePercent$1(itemModel.get(dims[0]), api.getWidth());
  83359. var yPx = parsePercent$1(itemModel.get(dims[1]), api.getHeight());
  83360. if (!isNaN(xPx) && !isNaN(yPx)) {
  83361. point = [xPx, yPx];
  83362. } else {
  83363. // Chart like bar may have there own marker positioning logic
  83364. if (seriesModel.getMarkerPosition) {
  83365. // Consider the case that user input the right-bottom point first
  83366. // Pick the larger x and y as 'x1' and 'y1'
  83367. var pointValue0 = data.getValues(['x0', 'y0'], idx);
  83368. var pointValue1 = data.getValues(['x1', 'y1'], idx);
  83369. var clampPointValue0 = coordSys.clampData(pointValue0);
  83370. var clampPointValue1 = coordSys.clampData(pointValue1);
  83371. var pointValue = [];
  83372. if (dims[0] === 'x0') {
  83373. pointValue[0] = clampPointValue0[0] > clampPointValue1[0] ? pointValue1[0] : pointValue0[0];
  83374. } else {
  83375. pointValue[0] = clampPointValue0[0] > clampPointValue1[0] ? pointValue0[0] : pointValue1[0];
  83376. }
  83377. if (dims[1] === 'y0') {
  83378. pointValue[1] = clampPointValue0[1] > clampPointValue1[1] ? pointValue1[1] : pointValue0[1];
  83379. } else {
  83380. pointValue[1] = clampPointValue0[1] > clampPointValue1[1] ? pointValue0[1] : pointValue1[1];
  83381. }
  83382. // Use the getMarkerPosition
  83383. point = seriesModel.getMarkerPosition(pointValue, dims, true);
  83384. } else {
  83385. var x = data.get(dims[0], idx);
  83386. var y = data.get(dims[1], idx);
  83387. var pt = [x, y];
  83388. coordSys.clampData && coordSys.clampData(pt, pt);
  83389. point = coordSys.dataToPoint(pt, true);
  83390. }
  83391. if (isCoordinateSystemType(coordSys, 'cartesian2d')) {
  83392. // TODO: TYPE ts@4.1 may still infer it as Axis instead of Axis2D. Not sure if it's a bug
  83393. var xAxis = coordSys.getAxis('x');
  83394. var yAxis = coordSys.getAxis('y');
  83395. var x = data.get(dims[0], idx);
  83396. var y = data.get(dims[1], idx);
  83397. if (isInfinity$1(x)) {
  83398. point[0] = xAxis.toGlobalCoord(xAxis.getExtent()[dims[0] === 'x0' ? 0 : 1]);
  83399. } else if (isInfinity$1(y)) {
  83400. point[1] = yAxis.toGlobalCoord(yAxis.getExtent()[dims[1] === 'y0' ? 0 : 1]);
  83401. }
  83402. }
  83403. // Use x, y if has any
  83404. if (!isNaN(xPx)) {
  83405. point[0] = xPx;
  83406. }
  83407. if (!isNaN(yPx)) {
  83408. point[1] = yPx;
  83409. }
  83410. }
  83411. return point;
  83412. }
  83413. var dimPermutations = [['x0', 'y0'], ['x1', 'y0'], ['x1', 'y1'], ['x0', 'y1']];
  83414. var MarkAreaView = /** @class */function (_super) {
  83415. __extends(MarkAreaView, _super);
  83416. function MarkAreaView() {
  83417. var _this = _super !== null && _super.apply(this, arguments) || this;
  83418. _this.type = MarkAreaView.type;
  83419. return _this;
  83420. }
  83421. MarkAreaView.prototype.updateTransform = function (markAreaModel, ecModel, api) {
  83422. ecModel.eachSeries(function (seriesModel) {
  83423. var maModel = MarkerModel.getMarkerModelFromSeries(seriesModel, 'markArea');
  83424. if (maModel) {
  83425. var areaData_1 = maModel.getData();
  83426. areaData_1.each(function (idx) {
  83427. var points = map(dimPermutations, function (dim) {
  83428. return getSingleMarkerEndPoint(areaData_1, idx, dim, seriesModel, api);
  83429. });
  83430. // Layout
  83431. areaData_1.setItemLayout(idx, points);
  83432. var el = areaData_1.getItemGraphicEl(idx);
  83433. el.setShape('points', points);
  83434. });
  83435. }
  83436. }, this);
  83437. };
  83438. MarkAreaView.prototype.renderSeries = function (seriesModel, maModel, ecModel, api) {
  83439. var coordSys = seriesModel.coordinateSystem;
  83440. var seriesId = seriesModel.id;
  83441. var seriesData = seriesModel.getData();
  83442. var areaGroupMap = this.markerGroupMap;
  83443. var polygonGroup = areaGroupMap.get(seriesId) || areaGroupMap.set(seriesId, {
  83444. group: new Group()
  83445. });
  83446. this.group.add(polygonGroup.group);
  83447. this.markKeep(polygonGroup);
  83448. var areaData = createList$2(coordSys, seriesModel, maModel);
  83449. // Line data for tooltip and formatter
  83450. maModel.setData(areaData);
  83451. // Update visual and layout of line
  83452. areaData.each(function (idx) {
  83453. // Layout
  83454. var points = map(dimPermutations, function (dim) {
  83455. return getSingleMarkerEndPoint(areaData, idx, dim, seriesModel, api);
  83456. });
  83457. var xAxisScale = coordSys.getAxis('x').scale;
  83458. var yAxisScale = coordSys.getAxis('y').scale;
  83459. var xAxisExtent = xAxisScale.getExtent();
  83460. var yAxisExtent = yAxisScale.getExtent();
  83461. var xPointExtent = [xAxisScale.parse(areaData.get('x0', idx)), xAxisScale.parse(areaData.get('x1', idx))];
  83462. var yPointExtent = [yAxisScale.parse(areaData.get('y0', idx)), yAxisScale.parse(areaData.get('y1', idx))];
  83463. asc(xPointExtent);
  83464. asc(yPointExtent);
  83465. var overlapped = !(xAxisExtent[0] > xPointExtent[1] || xAxisExtent[1] < xPointExtent[0] || yAxisExtent[0] > yPointExtent[1] || yAxisExtent[1] < yPointExtent[0]);
  83466. // If none of the area is inside coordSys, allClipped is set to be true
  83467. // in layout so that label will not be displayed. See #12591
  83468. var allClipped = !overlapped;
  83469. areaData.setItemLayout(idx, {
  83470. points: points,
  83471. allClipped: allClipped
  83472. });
  83473. var itemModel = areaData.getItemModel(idx);
  83474. var style = itemModel.getModel('itemStyle').getItemStyle();
  83475. var z2 = itemModel.get('z2');
  83476. var color$1 = getVisualFromData(seriesData, 'color');
  83477. if (!style.fill) {
  83478. style.fill = color$1;
  83479. if (isString(style.fill)) {
  83480. style.fill = modifyAlpha(style.fill, 0.4);
  83481. }
  83482. }
  83483. if (!style.stroke) {
  83484. style.stroke = color$1;
  83485. }
  83486. // Visual
  83487. areaData.setItemVisual(idx, 'style', style);
  83488. areaData.setItemVisual(idx, 'z2', retrieve2(z2, 0));
  83489. });
  83490. areaData.diff(inner$l(polygonGroup).data).add(function (idx) {
  83491. var layout = areaData.getItemLayout(idx);
  83492. var z2 = areaData.getItemVisual(idx, 'z2');
  83493. if (!layout.allClipped) {
  83494. var polygon = new Polygon({
  83495. z2: retrieve2(z2, 0),
  83496. shape: {
  83497. points: layout.points
  83498. }
  83499. });
  83500. areaData.setItemGraphicEl(idx, polygon);
  83501. polygonGroup.group.add(polygon);
  83502. }
  83503. }).update(function (newIdx, oldIdx) {
  83504. var polygon = inner$l(polygonGroup).data.getItemGraphicEl(oldIdx);
  83505. var layout = areaData.getItemLayout(newIdx);
  83506. var z2 = areaData.getItemVisual(newIdx, 'z2');
  83507. if (!layout.allClipped) {
  83508. if (polygon) {
  83509. updateProps(polygon, {
  83510. z2: retrieve2(z2, 0),
  83511. shape: {
  83512. points: layout.points
  83513. }
  83514. }, maModel, newIdx);
  83515. } else {
  83516. polygon = new Polygon({
  83517. shape: {
  83518. points: layout.points
  83519. }
  83520. });
  83521. }
  83522. areaData.setItemGraphicEl(newIdx, polygon);
  83523. polygonGroup.group.add(polygon);
  83524. } else if (polygon) {
  83525. polygonGroup.group.remove(polygon);
  83526. }
  83527. }).remove(function (idx) {
  83528. var polygon = inner$l(polygonGroup).data.getItemGraphicEl(idx);
  83529. polygonGroup.group.remove(polygon);
  83530. }).execute();
  83531. areaData.eachItemGraphicEl(function (polygon, idx) {
  83532. var itemModel = areaData.getItemModel(idx);
  83533. var style = areaData.getItemVisual(idx, 'style');
  83534. polygon.useStyle(areaData.getItemVisual(idx, 'style'));
  83535. setLabelStyle(polygon, getLabelStatesModels(itemModel), {
  83536. labelFetcher: maModel,
  83537. labelDataIndex: idx,
  83538. defaultText: areaData.getName(idx) || '',
  83539. inheritColor: isString(style.fill) ? modifyAlpha(style.fill, 1) : tokens.color.neutral99
  83540. });
  83541. setStatesStylesFromModel(polygon, itemModel);
  83542. toggleHoverEmphasis(polygon, null, null, itemModel.get(['emphasis', 'disabled']));
  83543. getECData(polygon).dataModel = maModel;
  83544. });
  83545. inner$l(polygonGroup).data = areaData;
  83546. polygonGroup.group.silent = maModel.get('silent') || seriesModel.get('silent');
  83547. };
  83548. MarkAreaView.type = 'markArea';
  83549. return MarkAreaView;
  83550. }(MarkerView);
  83551. function createList$2(coordSys, seriesModel, maModel) {
  83552. var areaData;
  83553. var dataDims;
  83554. var dims = ['x0', 'y0', 'x1', 'y1'];
  83555. if (coordSys) {
  83556. var coordDimsInfos_1 = map(coordSys && coordSys.dimensions, function (coordDim) {
  83557. var data = seriesModel.getData();
  83558. var info = data.getDimensionInfo(data.mapDimension(coordDim)) || {};
  83559. // In map series data don't have lng and lat dimension. Fallback to same with coordSys
  83560. return extend(extend({}, info), {
  83561. name: coordDim,
  83562. // DON'T use ordinalMeta to parse and collect ordinal.
  83563. ordinalMeta: null
  83564. });
  83565. });
  83566. dataDims = map(dims, function (dim, idx) {
  83567. return {
  83568. name: dim,
  83569. type: coordDimsInfos_1[idx % 2].type
  83570. };
  83571. });
  83572. areaData = new SeriesData(dataDims, maModel);
  83573. } else {
  83574. dataDims = [{
  83575. name: 'value',
  83576. type: 'float'
  83577. }];
  83578. areaData = new SeriesData(dataDims, maModel);
  83579. }
  83580. var optData = map(maModel.get('data'), curry(markAreaTransform, seriesModel, coordSys, maModel));
  83581. if (coordSys) {
  83582. optData = filter(optData, curry(markAreaFilter, coordSys));
  83583. }
  83584. var dimValueGetter = coordSys ? function (item, dimName, dataIndex, dimIndex) {
  83585. // TODO should convert to ParsedValue?
  83586. var rawVal = item.coord[Math.floor(dimIndex / 2)][dimIndex % 2];
  83587. return parseDataValue(rawVal, dataDims[dimIndex]);
  83588. } : function (item, dimName, dataIndex, dimIndex) {
  83589. return parseDataValue(item.value, dataDims[dimIndex]);
  83590. };
  83591. areaData.initData(optData, null, dimValueGetter);
  83592. areaData.hasItemOption = true;
  83593. return areaData;
  83594. }
  83595. function install$I(registers) {
  83596. registers.registerComponentModel(MarkAreaModel);
  83597. registers.registerComponentView(MarkAreaView);
  83598. registers.registerPreprocessor(function (opt) {
  83599. if (checkMarkerInSeries(opt.series, 'markArea')) {
  83600. // Make sure markArea component is enabled
  83601. opt.markArea = opt.markArea || {};
  83602. }
  83603. });
  83604. }
  83605. var getDefaultSelectorOptions = function (ecModel, type) {
  83606. if (type === 'all') {
  83607. return {
  83608. type: 'all',
  83609. title: ecModel.getLocaleModel().get(['legend', 'selector', 'all'])
  83610. };
  83611. } else if (type === 'inverse') {
  83612. return {
  83613. type: 'inverse',
  83614. title: ecModel.getLocaleModel().get(['legend', 'selector', 'inverse'])
  83615. };
  83616. }
  83617. };
  83618. var LegendModel = /** @class */function (_super) {
  83619. __extends(LegendModel, _super);
  83620. function LegendModel() {
  83621. var _this = _super !== null && _super.apply(this, arguments) || this;
  83622. _this.type = LegendModel.type;
  83623. _this.layoutMode = {
  83624. type: 'box',
  83625. // legend.width/height are maxWidth/maxHeight actually,
  83626. // whereas real width/height is calculated by its content.
  83627. // (Setting {left: 10, right: 10} does not make sense).
  83628. // So consider the case:
  83629. // `setOption({legend: {left: 10});`
  83630. // then `setOption({legend: {right: 10});`
  83631. // The previous `left` should be cleared by setting `ignoreSize`.
  83632. ignoreSize: true
  83633. };
  83634. return _this;
  83635. }
  83636. LegendModel.prototype.init = function (option, parentModel, ecModel) {
  83637. this.mergeDefaultAndTheme(option, ecModel);
  83638. option.selected = option.selected || {};
  83639. this._updateSelector(option);
  83640. };
  83641. LegendModel.prototype.mergeOption = function (option, ecModel) {
  83642. _super.prototype.mergeOption.call(this, option, ecModel);
  83643. this._updateSelector(option);
  83644. };
  83645. LegendModel.prototype._updateSelector = function (option) {
  83646. var selector = option.selector;
  83647. var ecModel = this.ecModel;
  83648. if (selector === true) {
  83649. selector = option.selector = ['all', 'inverse'];
  83650. }
  83651. if (isArray(selector)) {
  83652. each(selector, function (item, index) {
  83653. isString(item) && (item = {
  83654. type: item
  83655. });
  83656. selector[index] = merge(item, getDefaultSelectorOptions(ecModel, item.type));
  83657. });
  83658. }
  83659. };
  83660. LegendModel.prototype.optionUpdated = function () {
  83661. this._updateData(this.ecModel);
  83662. var legendData = this._data;
  83663. // If selectedMode is single, try to select one
  83664. if (legendData[0] && this.get('selectedMode') === 'single') {
  83665. var hasSelected = false;
  83666. // If has any selected in option.selected
  83667. for (var i = 0; i < legendData.length; i++) {
  83668. var name_1 = legendData[i].get('name');
  83669. if (this.isSelected(name_1)) {
  83670. // Force to unselect others
  83671. this.select(name_1);
  83672. hasSelected = true;
  83673. break;
  83674. }
  83675. }
  83676. // Try select the first if selectedMode is single
  83677. !hasSelected && this.select(legendData[0].get('name'));
  83678. }
  83679. };
  83680. LegendModel.prototype._updateData = function (ecModel) {
  83681. var potentialData = [];
  83682. var availableNames = [];
  83683. ecModel.eachRawSeries(function (seriesModel) {
  83684. var seriesName = seriesModel.name;
  83685. availableNames.push(seriesName);
  83686. var isPotential;
  83687. if (seriesModel.legendVisualProvider) {
  83688. var provider = seriesModel.legendVisualProvider;
  83689. var names = provider.getAllNames();
  83690. if (!ecModel.isSeriesFiltered(seriesModel)) {
  83691. availableNames = availableNames.concat(names);
  83692. }
  83693. if (names.length) {
  83694. potentialData = potentialData.concat(names);
  83695. } else {
  83696. isPotential = true;
  83697. }
  83698. } else {
  83699. isPotential = true;
  83700. }
  83701. if (isPotential && isNameSpecified(seriesModel)) {
  83702. potentialData.push(seriesModel.name);
  83703. }
  83704. });
  83705. /**
  83706. * @type {Array.<string>}
  83707. * @private
  83708. */
  83709. this._availableNames = availableNames;
  83710. // If legend.data is not specified in option, use availableNames as data,
  83711. // which is convenient for user preparing option.
  83712. var rawData = this.get('data') || potentialData;
  83713. var legendNameMap = createHashMap();
  83714. var legendData = map(rawData, function (dataItem) {
  83715. // Can be string or number
  83716. if (isString(dataItem) || isNumber(dataItem)) {
  83717. dataItem = {
  83718. name: dataItem
  83719. };
  83720. }
  83721. if (legendNameMap.get(dataItem.name)) {
  83722. // remove legend name duplicate
  83723. return null;
  83724. }
  83725. legendNameMap.set(dataItem.name, true);
  83726. return new Model(dataItem, this, this.ecModel);
  83727. }, this);
  83728. /**
  83729. * @type {Array.<module:echarts/model/Model>}
  83730. * @private
  83731. */
  83732. this._data = filter(legendData, function (item) {
  83733. return !!item;
  83734. });
  83735. };
  83736. LegendModel.prototype.getData = function () {
  83737. return this._data;
  83738. };
  83739. LegendModel.prototype.select = function (name) {
  83740. var selected = this.option.selected;
  83741. var selectedMode = this.get('selectedMode');
  83742. if (selectedMode === 'single') {
  83743. var data = this._data;
  83744. each(data, function (dataItem) {
  83745. selected[dataItem.get('name')] = false;
  83746. });
  83747. }
  83748. selected[name] = true;
  83749. };
  83750. LegendModel.prototype.unSelect = function (name) {
  83751. if (this.get('selectedMode') !== 'single') {
  83752. this.option.selected[name] = false;
  83753. }
  83754. };
  83755. LegendModel.prototype.toggleSelected = function (name) {
  83756. var selected = this.option.selected;
  83757. // Default is true
  83758. if (!selected.hasOwnProperty(name)) {
  83759. selected[name] = true;
  83760. }
  83761. this[selected[name] ? 'unSelect' : 'select'](name);
  83762. };
  83763. LegendModel.prototype.allSelect = function () {
  83764. var data = this._data;
  83765. var selected = this.option.selected;
  83766. each(data, function (dataItem) {
  83767. selected[dataItem.get('name', true)] = true;
  83768. });
  83769. };
  83770. LegendModel.prototype.inverseSelect = function () {
  83771. var data = this._data;
  83772. var selected = this.option.selected;
  83773. each(data, function (dataItem) {
  83774. var name = dataItem.get('name', true);
  83775. // Initially, default value is true
  83776. if (!selected.hasOwnProperty(name)) {
  83777. selected[name] = true;
  83778. }
  83779. selected[name] = !selected[name];
  83780. });
  83781. };
  83782. LegendModel.prototype.isSelected = function (name) {
  83783. var selected = this.option.selected;
  83784. return !(selected.hasOwnProperty(name) && !selected[name]) && indexOf(this._availableNames, name) >= 0;
  83785. };
  83786. LegendModel.prototype.getOrient = function () {
  83787. return this.get('orient') === 'vertical' ? {
  83788. index: 1,
  83789. name: 'vertical'
  83790. } : {
  83791. index: 0,
  83792. name: 'horizontal'
  83793. };
  83794. };
  83795. LegendModel.type = 'legend.plain';
  83796. LegendModel.dependencies = ['series'];
  83797. LegendModel.defaultOption = {
  83798. // zlevel: 0,
  83799. z: 4,
  83800. show: true,
  83801. orient: 'horizontal',
  83802. left: 'center',
  83803. // right: 'center',
  83804. // top: 0,
  83805. bottom: tokens.size.m,
  83806. align: 'auto',
  83807. backgroundColor: tokens.color.transparent,
  83808. borderColor: tokens.color.border,
  83809. borderRadius: 0,
  83810. borderWidth: 0,
  83811. padding: 5,
  83812. itemGap: 8,
  83813. itemWidth: 25,
  83814. itemHeight: 14,
  83815. symbolRotate: 'inherit',
  83816. symbolKeepAspect: true,
  83817. inactiveColor: tokens.color.disabled,
  83818. inactiveBorderColor: tokens.color.disabled,
  83819. inactiveBorderWidth: 'auto',
  83820. itemStyle: {
  83821. color: 'inherit',
  83822. opacity: 'inherit',
  83823. borderColor: 'inherit',
  83824. borderWidth: 'auto',
  83825. borderCap: 'inherit',
  83826. borderJoin: 'inherit',
  83827. borderDashOffset: 'inherit',
  83828. borderMiterLimit: 'inherit'
  83829. },
  83830. lineStyle: {
  83831. width: 'auto',
  83832. color: 'inherit',
  83833. inactiveColor: tokens.color.disabled,
  83834. inactiveWidth: 2,
  83835. opacity: 'inherit',
  83836. type: 'inherit',
  83837. cap: 'inherit',
  83838. join: 'inherit',
  83839. dashOffset: 'inherit',
  83840. miterLimit: 'inherit'
  83841. },
  83842. textStyle: {
  83843. color: tokens.color.secondary
  83844. },
  83845. selectedMode: true,
  83846. selector: false,
  83847. selectorLabel: {
  83848. show: true,
  83849. borderRadius: 10,
  83850. padding: [3, 5, 3, 5],
  83851. fontSize: 12,
  83852. fontFamily: 'sans-serif',
  83853. color: tokens.color.tertiary,
  83854. borderWidth: 1,
  83855. borderColor: tokens.color.border
  83856. },
  83857. emphasis: {
  83858. selectorLabel: {
  83859. show: true,
  83860. color: tokens.color.quaternary
  83861. }
  83862. },
  83863. selectorPosition: 'auto',
  83864. selectorItemGap: 7,
  83865. selectorButtonGap: 10,
  83866. tooltip: {
  83867. show: false
  83868. },
  83869. triggerEvent: false
  83870. };
  83871. return LegendModel;
  83872. }(ComponentModel);
  83873. var curry$1 = curry;
  83874. var each$c = each;
  83875. var Group$2 = Group;
  83876. var LegendView = /** @class */function (_super) {
  83877. __extends(LegendView, _super);
  83878. function LegendView() {
  83879. var _this = _super !== null && _super.apply(this, arguments) || this;
  83880. _this.type = LegendView.type;
  83881. _this.newlineDisabled = false;
  83882. return _this;
  83883. }
  83884. LegendView.prototype.init = function () {
  83885. this.group.add(this._contentGroup = new Group$2());
  83886. this.group.add(this._selectorGroup = new Group$2());
  83887. this._isFirstRender = true;
  83888. };
  83889. /**
  83890. * @protected
  83891. */
  83892. LegendView.prototype.getContentGroup = function () {
  83893. return this._contentGroup;
  83894. };
  83895. /**
  83896. * @protected
  83897. */
  83898. LegendView.prototype.getSelectorGroup = function () {
  83899. return this._selectorGroup;
  83900. };
  83901. /**
  83902. * @override
  83903. */
  83904. LegendView.prototype.render = function (legendModel, ecModel, api) {
  83905. var isFirstRender = this._isFirstRender;
  83906. this._isFirstRender = false;
  83907. this.resetInner();
  83908. if (!legendModel.get('show', true)) {
  83909. return;
  83910. }
  83911. var itemAlign = legendModel.get('align');
  83912. var orient = legendModel.get('orient');
  83913. if (!itemAlign || itemAlign === 'auto') {
  83914. itemAlign = legendModel.get('left') === 'right' && orient === 'vertical' ? 'right' : 'left';
  83915. }
  83916. // selector has been normalized to an array in model
  83917. var selector = legendModel.get('selector', true);
  83918. var selectorPosition = legendModel.get('selectorPosition', true);
  83919. if (selector && (!selectorPosition || selectorPosition === 'auto')) {
  83920. selectorPosition = orient === 'horizontal' ? 'end' : 'start';
  83921. }
  83922. this.renderInner(itemAlign, legendModel, ecModel, api, selector, orient, selectorPosition);
  83923. // Perform layout.
  83924. var refContainer = createBoxLayoutReference(legendModel, api).refContainer;
  83925. var positionInfo = legendModel.getBoxLayoutParams();
  83926. var padding = legendModel.get('padding');
  83927. var maxSize = getLayoutRect(positionInfo, refContainer, padding);
  83928. var mainRect = this.layoutInner(legendModel, itemAlign, maxSize, isFirstRender, selector, selectorPosition);
  83929. // Place mainGroup, based on the calculated `mainRect`.
  83930. var layoutRect = getLayoutRect(defaults({
  83931. width: mainRect.width,
  83932. height: mainRect.height
  83933. }, positionInfo), refContainer, padding);
  83934. this.group.x = layoutRect.x - mainRect.x;
  83935. this.group.y = layoutRect.y - mainRect.y;
  83936. this.group.markRedraw();
  83937. // Render background after group is layout.
  83938. this.group.add(this._backgroundEl = makeBackground(mainRect,
  83939. // FXIME: most itemStyle options does not work in background because inherit is not handled yet.
  83940. legendModel));
  83941. };
  83942. LegendView.prototype.resetInner = function () {
  83943. this.getContentGroup().removeAll();
  83944. this._backgroundEl && this.group.remove(this._backgroundEl);
  83945. this.getSelectorGroup().removeAll();
  83946. };
  83947. LegendView.prototype.renderInner = function (itemAlign, legendModel, ecModel, api, selector, orient, selectorPosition) {
  83948. var contentGroup = this.getContentGroup();
  83949. var legendDrawnMap = createHashMap();
  83950. var selectMode = legendModel.get('selectedMode');
  83951. var triggerEvent = legendModel.get('triggerEvent');
  83952. var excludeSeriesId = [];
  83953. ecModel.eachRawSeries(function (seriesModel) {
  83954. !seriesModel.get('legendHoverLink') && excludeSeriesId.push(seriesModel.id);
  83955. });
  83956. each$c(legendModel.getData(), function (legendItemModel, dataIndex) {
  83957. var _this = this;
  83958. var name = legendItemModel.get('name');
  83959. // Use empty string or \n as a newline string
  83960. if (!this.newlineDisabled && (name === '' || name === '\n')) {
  83961. var g = new Group$2();
  83962. // @ts-ignore
  83963. g.newline = true;
  83964. contentGroup.add(g);
  83965. return;
  83966. }
  83967. // Representitive series.
  83968. var seriesModel = ecModel.getSeriesByName(name)[0];
  83969. if (legendDrawnMap.get(name)) {
  83970. // Have been drawn
  83971. return;
  83972. }
  83973. // Legend to control series.
  83974. if (seriesModel) {
  83975. var data = seriesModel.getData();
  83976. var lineVisualStyle = data.getVisual('legendLineStyle') || {};
  83977. var legendIcon = data.getVisual('legendIcon');
  83978. /**
  83979. * `data.getVisual('style')` may be the color from the register
  83980. * in series. For example, for line series,
  83981. */
  83982. var style = data.getVisual('style');
  83983. var itemGroup = this._createItem(seriesModel, name, dataIndex, legendItemModel, legendModel, itemAlign, lineVisualStyle, style, legendIcon, selectMode, api);
  83984. itemGroup.on('click', curry$1(dispatchSelectAction, name, null, api, excludeSeriesId)).on('mouseover', curry$1(dispatchHighlightAction, seriesModel.name, null, api, excludeSeriesId)).on('mouseout', curry$1(dispatchDownplayAction, seriesModel.name, null, api, excludeSeriesId));
  83985. if (ecModel.ssr) {
  83986. itemGroup.eachChild(function (child) {
  83987. var ecData = getECData(child);
  83988. ecData.seriesIndex = seriesModel.seriesIndex;
  83989. ecData.dataIndex = dataIndex;
  83990. ecData.ssrType = 'legend';
  83991. });
  83992. }
  83993. if (triggerEvent) {
  83994. itemGroup.eachChild(function (child) {
  83995. _this.packEventData(child, legendModel, seriesModel, dataIndex, name);
  83996. });
  83997. }
  83998. legendDrawnMap.set(name, true);
  83999. } else {
  84000. // Legend to control data. In pie and funnel.
  84001. ecModel.eachRawSeries(function (seriesModel) {
  84002. var _this = this;
  84003. // In case multiple series has same data name
  84004. if (legendDrawnMap.get(name)) {
  84005. return;
  84006. }
  84007. if (seriesModel.legendVisualProvider) {
  84008. var provider = seriesModel.legendVisualProvider;
  84009. if (!provider.containName(name)) {
  84010. return;
  84011. }
  84012. var idx = provider.indexOfName(name);
  84013. var style = provider.getItemVisual(idx, 'style');
  84014. var legendIcon = provider.getItemVisual(idx, 'legendIcon');
  84015. var colorArr = parse(style.fill);
  84016. // Color may be set to transparent in visualMap when data is out of range.
  84017. // Do not show nothing.
  84018. if (colorArr && colorArr[3] === 0) {
  84019. colorArr[3] = 0.2;
  84020. // TODO color is set to 0, 0, 0, 0. Should show correct RGBA
  84021. style = extend(extend({}, style), {
  84022. fill: stringify(colorArr, 'rgba')
  84023. });
  84024. }
  84025. var itemGroup = this._createItem(seriesModel, name, dataIndex, legendItemModel, legendModel, itemAlign, {}, style, legendIcon, selectMode, api);
  84026. // FIXME: consider different series has items with the same name.
  84027. itemGroup.on('click', curry$1(dispatchSelectAction, null, name, api, excludeSeriesId))
  84028. // Should not specify the series name, consider legend controls
  84029. // more than one pie series.
  84030. .on('mouseover', curry$1(dispatchHighlightAction, null, name, api, excludeSeriesId)).on('mouseout', curry$1(dispatchDownplayAction, null, name, api, excludeSeriesId));
  84031. if (ecModel.ssr) {
  84032. itemGroup.eachChild(function (child) {
  84033. var ecData = getECData(child);
  84034. ecData.seriesIndex = seriesModel.seriesIndex;
  84035. ecData.dataIndex = dataIndex;
  84036. ecData.ssrType = 'legend';
  84037. });
  84038. }
  84039. if (triggerEvent) {
  84040. itemGroup.eachChild(function (child) {
  84041. _this.packEventData(child, legendModel, seriesModel, dataIndex, name);
  84042. });
  84043. }
  84044. legendDrawnMap.set(name, true);
  84045. }
  84046. }, this);
  84047. }
  84048. if ("development" !== 'production') {
  84049. if (!legendDrawnMap.get(name)) {
  84050. console.warn(name + ' series not exists. Legend data should be same with series name or data name.');
  84051. }
  84052. }
  84053. }, this);
  84054. if (selector) {
  84055. this._createSelector(selector, legendModel, api, orient, selectorPosition);
  84056. }
  84057. };
  84058. LegendView.prototype.packEventData = function (el, legendModel, seriesModel, dataIndex, name) {
  84059. var eventData = {
  84060. componentType: 'legend',
  84061. componentIndex: legendModel.componentIndex,
  84062. dataIndex: dataIndex,
  84063. value: name,
  84064. seriesIndex: seriesModel.seriesIndex
  84065. };
  84066. getECData(el).eventData = eventData;
  84067. };
  84068. LegendView.prototype._createSelector = function (selector, legendModel, api, orient, selectorPosition) {
  84069. var selectorGroup = this.getSelectorGroup();
  84070. each$c(selector, function createSelectorButton(selectorItem) {
  84071. var type = selectorItem.type;
  84072. var labelText = new ZRText({
  84073. style: {
  84074. x: 0,
  84075. y: 0,
  84076. align: 'center',
  84077. verticalAlign: 'middle'
  84078. },
  84079. onclick: function () {
  84080. api.dispatchAction({
  84081. type: type === 'all' ? 'legendAllSelect' : 'legendInverseSelect',
  84082. legendId: legendModel.id
  84083. });
  84084. }
  84085. });
  84086. selectorGroup.add(labelText);
  84087. var labelModel = legendModel.getModel('selectorLabel');
  84088. var emphasisLabelModel = legendModel.getModel(['emphasis', 'selectorLabel']);
  84089. setLabelStyle(labelText, {
  84090. normal: labelModel,
  84091. emphasis: emphasisLabelModel
  84092. }, {
  84093. defaultText: selectorItem.title
  84094. });
  84095. enableHoverEmphasis(labelText);
  84096. });
  84097. };
  84098. LegendView.prototype._createItem = function (seriesModel, name, dataIndex, legendItemModel, legendModel, itemAlign, lineVisualStyle, itemVisualStyle, legendIcon, selectMode, api) {
  84099. var drawType = seriesModel.visualDrawType;
  84100. var itemWidth = legendModel.get('itemWidth');
  84101. var itemHeight = legendModel.get('itemHeight');
  84102. var isSelected = legendModel.isSelected(name);
  84103. var iconRotate = legendItemModel.get('symbolRotate');
  84104. var symbolKeepAspect = legendItemModel.get('symbolKeepAspect');
  84105. var legendIconType = legendItemModel.get('icon');
  84106. legendIcon = legendIconType || legendIcon || 'roundRect';
  84107. var style = getLegendStyle(legendIcon, legendItemModel, lineVisualStyle, itemVisualStyle, drawType, isSelected, api);
  84108. var itemGroup = new Group$2();
  84109. var textStyleModel = legendItemModel.getModel('textStyle');
  84110. if (isFunction(seriesModel.getLegendIcon) && (!legendIconType || legendIconType === 'inherit')) {
  84111. // Series has specific way to define legend icon
  84112. itemGroup.add(seriesModel.getLegendIcon({
  84113. itemWidth: itemWidth,
  84114. itemHeight: itemHeight,
  84115. icon: legendIcon,
  84116. iconRotate: iconRotate,
  84117. itemStyle: style.itemStyle,
  84118. lineStyle: style.lineStyle,
  84119. symbolKeepAspect: symbolKeepAspect
  84120. }));
  84121. } else {
  84122. // Use default legend icon policy for most series
  84123. var rotate = legendIconType === 'inherit' && seriesModel.getData().getVisual('symbol') ? iconRotate === 'inherit' ? seriesModel.getData().getVisual('symbolRotate') : iconRotate : 0; // No rotation for no icon
  84124. itemGroup.add(getDefaultLegendIcon({
  84125. itemWidth: itemWidth,
  84126. itemHeight: itemHeight,
  84127. icon: legendIcon,
  84128. iconRotate: rotate,
  84129. itemStyle: style.itemStyle,
  84130. lineStyle: style.lineStyle,
  84131. symbolKeepAspect: symbolKeepAspect
  84132. }));
  84133. }
  84134. var textX = itemAlign === 'left' ? itemWidth + 5 : -5;
  84135. var textAlign = itemAlign;
  84136. var formatter = legendModel.get('formatter');
  84137. var content = name;
  84138. if (isString(formatter) && formatter) {
  84139. content = formatter.replace('{name}', name != null ? name : '');
  84140. } else if (isFunction(formatter)) {
  84141. content = formatter(name);
  84142. }
  84143. var textColor = isSelected ? textStyleModel.getTextColor() : legendItemModel.get('inactiveColor');
  84144. itemGroup.add(new ZRText({
  84145. style: createTextStyle(textStyleModel, {
  84146. text: content,
  84147. x: textX,
  84148. y: itemHeight / 2,
  84149. fill: textColor,
  84150. align: textAlign,
  84151. verticalAlign: 'middle'
  84152. }, {
  84153. inheritColor: textColor
  84154. })
  84155. }));
  84156. // Add a invisible rect to increase the area of mouse hover
  84157. var hitRect = new Rect({
  84158. shape: itemGroup.getBoundingRect(),
  84159. style: {
  84160. // Cannot use 'invisible' because SVG SSR will miss the node
  84161. fill: 'transparent'
  84162. }
  84163. });
  84164. var tooltipModel = legendItemModel.getModel('tooltip');
  84165. if (tooltipModel.get('show')) {
  84166. setTooltipConfig({
  84167. el: hitRect,
  84168. componentModel: legendModel,
  84169. itemName: name,
  84170. itemTooltipOption: tooltipModel.option
  84171. });
  84172. }
  84173. itemGroup.add(hitRect);
  84174. itemGroup.eachChild(function (child) {
  84175. child.silent = true;
  84176. });
  84177. hitRect.silent = !selectMode;
  84178. this.getContentGroup().add(itemGroup);
  84179. enableHoverEmphasis(itemGroup);
  84180. // @ts-ignore
  84181. itemGroup.__legendDataIndex = dataIndex;
  84182. return itemGroup;
  84183. };
  84184. LegendView.prototype.layoutInner = function (legendModel, itemAlign, maxSize, isFirstRender, selector, selectorPosition) {
  84185. var contentGroup = this.getContentGroup();
  84186. var selectorGroup = this.getSelectorGroup();
  84187. // Place items in contentGroup.
  84188. box(legendModel.get('orient'), contentGroup, legendModel.get('itemGap'), maxSize.width, maxSize.height);
  84189. var contentRect = contentGroup.getBoundingRect();
  84190. var contentPos = [-contentRect.x, -contentRect.y];
  84191. selectorGroup.markRedraw();
  84192. contentGroup.markRedraw();
  84193. if (selector) {
  84194. // Place buttons in selectorGroup
  84195. box(
  84196. // Buttons in selectorGroup always layout horizontally
  84197. 'horizontal', selectorGroup, legendModel.get('selectorItemGap', true));
  84198. var selectorRect = selectorGroup.getBoundingRect();
  84199. var selectorPos = [-selectorRect.x, -selectorRect.y];
  84200. var selectorButtonGap = legendModel.get('selectorButtonGap', true);
  84201. var orientIdx = legendModel.getOrient().index;
  84202. var wh = orientIdx === 0 ? 'width' : 'height';
  84203. var hw = orientIdx === 0 ? 'height' : 'width';
  84204. var yx = orientIdx === 0 ? 'y' : 'x';
  84205. if (selectorPosition === 'end') {
  84206. selectorPos[orientIdx] += contentRect[wh] + selectorButtonGap;
  84207. } else {
  84208. contentPos[orientIdx] += selectorRect[wh] + selectorButtonGap;
  84209. }
  84210. // Always align selector to content as 'middle'
  84211. selectorPos[1 - orientIdx] += contentRect[hw] / 2 - selectorRect[hw] / 2;
  84212. selectorGroup.x = selectorPos[0];
  84213. selectorGroup.y = selectorPos[1];
  84214. contentGroup.x = contentPos[0];
  84215. contentGroup.y = contentPos[1];
  84216. var mainRect = {
  84217. x: 0,
  84218. y: 0
  84219. };
  84220. mainRect[wh] = contentRect[wh] + selectorButtonGap + selectorRect[wh];
  84221. mainRect[hw] = Math.max(contentRect[hw], selectorRect[hw]);
  84222. mainRect[yx] = Math.min(0, selectorRect[yx] + selectorPos[1 - orientIdx]);
  84223. return mainRect;
  84224. } else {
  84225. contentGroup.x = contentPos[0];
  84226. contentGroup.y = contentPos[1];
  84227. return this.group.getBoundingRect();
  84228. }
  84229. };
  84230. /**
  84231. * @protected
  84232. */
  84233. LegendView.prototype.remove = function () {
  84234. this.getContentGroup().removeAll();
  84235. this._isFirstRender = true;
  84236. };
  84237. LegendView.type = 'legend.plain';
  84238. return LegendView;
  84239. }(ComponentView);
  84240. function getLegendStyle(iconType, legendItemModel, lineVisualStyle, itemVisualStyle, drawType, isSelected, api) {
  84241. /**
  84242. * Use series style if is inherit;
  84243. * elsewise, use legend style
  84244. */
  84245. function handleCommonProps(style, visualStyle) {
  84246. // If lineStyle.width is 'auto', it is set to be 2 if series has border
  84247. if (style.lineWidth === 'auto') {
  84248. style.lineWidth = visualStyle.lineWidth > 0 ? 2 : 0;
  84249. }
  84250. each$c(style, function (propVal, propName) {
  84251. style[propName] === 'inherit' && (style[propName] = visualStyle[propName]);
  84252. });
  84253. }
  84254. // itemStyle
  84255. var itemStyleModel = legendItemModel.getModel('itemStyle');
  84256. var itemStyle = itemStyleModel.getItemStyle();
  84257. var iconBrushType = iconType.lastIndexOf('empty', 0) === 0 ? 'fill' : 'stroke';
  84258. var decalStyle = itemStyleModel.getShallow('decal');
  84259. itemStyle.decal = !decalStyle || decalStyle === 'inherit' ? itemVisualStyle.decal : createOrUpdatePatternFromDecal(decalStyle, api);
  84260. if (itemStyle.fill === 'inherit') {
  84261. /**
  84262. * Series with visualDrawType as 'stroke' should have
  84263. * series stroke as legend fill
  84264. */
  84265. itemStyle.fill = itemVisualStyle[drawType];
  84266. }
  84267. if (itemStyle.stroke === 'inherit') {
  84268. /**
  84269. * icon type with "emptyXXX" should use fill color
  84270. * in visual style
  84271. */
  84272. itemStyle.stroke = itemVisualStyle[iconBrushType];
  84273. }
  84274. if (itemStyle.opacity === 'inherit') {
  84275. /**
  84276. * Use lineStyle.opacity if drawType is stroke
  84277. */
  84278. itemStyle.opacity = (drawType === 'fill' ? itemVisualStyle : lineVisualStyle).opacity;
  84279. }
  84280. handleCommonProps(itemStyle, itemVisualStyle);
  84281. // lineStyle
  84282. var legendLineModel = legendItemModel.getModel('lineStyle');
  84283. var lineStyle = legendLineModel.getLineStyle();
  84284. handleCommonProps(lineStyle, lineVisualStyle);
  84285. // Fix auto color to real color
  84286. itemStyle.fill === 'auto' && (itemStyle.fill = itemVisualStyle.fill);
  84287. itemStyle.stroke === 'auto' && (itemStyle.stroke = itemVisualStyle.fill);
  84288. lineStyle.stroke === 'auto' && (lineStyle.stroke = itemVisualStyle.fill);
  84289. if (!isSelected) {
  84290. var borderWidth = legendItemModel.get('inactiveBorderWidth');
  84291. /**
  84292. * Since stroke is set to be inactiveBorderColor, it may occur that
  84293. * there is no border in series but border in legend, so we need to
  84294. * use border only when series has border if is set to be auto
  84295. */
  84296. var visualHasBorder = itemStyle[iconBrushType];
  84297. itemStyle.lineWidth = borderWidth === 'auto' ? itemVisualStyle.lineWidth > 0 && visualHasBorder ? 2 : 0 : itemStyle.lineWidth;
  84298. itemStyle.fill = legendItemModel.get('inactiveColor');
  84299. itemStyle.stroke = legendItemModel.get('inactiveBorderColor');
  84300. lineStyle.stroke = legendLineModel.get('inactiveColor');
  84301. lineStyle.lineWidth = legendLineModel.get('inactiveWidth');
  84302. }
  84303. return {
  84304. itemStyle: itemStyle,
  84305. lineStyle: lineStyle
  84306. };
  84307. }
  84308. function getDefaultLegendIcon(opt) {
  84309. var symboType = opt.icon || 'roundRect';
  84310. var icon = createSymbol(symboType, 0, 0, opt.itemWidth, opt.itemHeight, opt.itemStyle.fill, opt.symbolKeepAspect);
  84311. icon.setStyle(opt.itemStyle);
  84312. icon.rotation = (opt.iconRotate || 0) * Math.PI / 180;
  84313. icon.setOrigin([opt.itemWidth / 2, opt.itemHeight / 2]);
  84314. if (symboType.indexOf('empty') > -1) {
  84315. icon.style.stroke = icon.style.fill;
  84316. icon.style.fill = tokens.color.neutral00;
  84317. icon.style.lineWidth = 2;
  84318. }
  84319. return icon;
  84320. }
  84321. function dispatchSelectAction(seriesName, dataName, api, excludeSeriesId) {
  84322. // downplay before unselect
  84323. dispatchDownplayAction(seriesName, dataName, api, excludeSeriesId);
  84324. api.dispatchAction({
  84325. type: 'legendToggleSelect',
  84326. name: seriesName != null ? seriesName : dataName
  84327. });
  84328. // highlight after select
  84329. // TODO highlight immediately may cause animation loss.
  84330. dispatchHighlightAction(seriesName, dataName, api, excludeSeriesId);
  84331. }
  84332. function isUseHoverLayer(api) {
  84333. var list = api.getZr().storage.getDisplayList();
  84334. var emphasisState;
  84335. var i = 0;
  84336. var len = list.length;
  84337. while (i < len && !(emphasisState = list[i].states.emphasis)) {
  84338. i++;
  84339. }
  84340. return emphasisState && emphasisState.hoverLayer;
  84341. }
  84342. function dispatchHighlightAction(seriesName, dataName, api, excludeSeriesId) {
  84343. // If element hover will move to a hoverLayer.
  84344. if (!isUseHoverLayer(api)) {
  84345. api.dispatchAction({
  84346. type: 'highlight',
  84347. seriesName: seriesName,
  84348. name: dataName,
  84349. excludeSeriesId: excludeSeriesId
  84350. });
  84351. }
  84352. }
  84353. function dispatchDownplayAction(seriesName, dataName, api, excludeSeriesId) {
  84354. // If element hover will move to a hoverLayer.
  84355. if (!isUseHoverLayer(api)) {
  84356. api.dispatchAction({
  84357. type: 'downplay',
  84358. seriesName: seriesName,
  84359. name: dataName,
  84360. excludeSeriesId: excludeSeriesId
  84361. });
  84362. }
  84363. }
  84364. /*
  84365. * Licensed to the Apache Software Foundation (ASF) under one
  84366. * or more contributor license agreements. See the NOTICE file
  84367. * distributed with this work for additional information
  84368. * regarding copyright ownership. The ASF licenses this file
  84369. * to you under the Apache License, Version 2.0 (the
  84370. * "License"); you may not use this file except in compliance
  84371. * with the License. You may obtain a copy of the License at
  84372. *
  84373. * http://www.apache.org/licenses/LICENSE-2.0
  84374. *
  84375. * Unless required by applicable law or agreed to in writing,
  84376. * software distributed under the License is distributed on an
  84377. * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
  84378. * KIND, either express or implied. See the License for the
  84379. * specific language governing permissions and limitations
  84380. * under the License.
  84381. */
  84382. /**
  84383. * AUTO-GENERATED FILE. DO NOT MODIFY.
  84384. */
  84385. /*
  84386. * Licensed to the Apache Software Foundation (ASF) under one
  84387. * or more contributor license agreements. See the NOTICE file
  84388. * distributed with this work for additional information
  84389. * regarding copyright ownership. The ASF licenses this file
  84390. * to you under the Apache License, Version 2.0 (the
  84391. * "License"); you may not use this file except in compliance
  84392. * with the License. You may obtain a copy of the License at
  84393. *
  84394. * http://www.apache.org/licenses/LICENSE-2.0
  84395. *
  84396. * Unless required by applicable law or agreed to in writing,
  84397. * software distributed under the License is distributed on an
  84398. * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
  84399. * KIND, either express or implied. See the License for the
  84400. * specific language governing permissions and limitations
  84401. * under the License.
  84402. */
  84403. function legendFilter(ecModel) {
  84404. var legendModels = ecModel.findComponents({
  84405. mainType: 'legend'
  84406. });
  84407. if (legendModels && legendModels.length) {
  84408. ecModel.filterSeries(function (series) {
  84409. // If in any legend component the status is not selected.
  84410. // Because in legend series is assumed selected when it is not in the legend data.
  84411. for (var i = 0; i < legendModels.length; i++) {
  84412. if (!legendModels[i].isSelected(series.name)) {
  84413. return false;
  84414. }
  84415. }
  84416. return true;
  84417. });
  84418. }
  84419. }
  84420. function legendSelectActionHandler(methodName, payload, ecModel) {
  84421. var isAllSelect = methodName === 'allSelect' || methodName === 'inverseSelect';
  84422. var selectedMap = {};
  84423. var actionLegendIndices = [];
  84424. ecModel.eachComponent({
  84425. mainType: 'legend',
  84426. query: payload
  84427. }, function (legendModel) {
  84428. if (isAllSelect) {
  84429. legendModel[methodName]();
  84430. } else {
  84431. legendModel[methodName](payload.name);
  84432. }
  84433. makeSelectedMap(legendModel, selectedMap);
  84434. actionLegendIndices.push(legendModel.componentIndex);
  84435. });
  84436. var allSelectedMap = {};
  84437. // make selectedMap from all legend components
  84438. ecModel.eachComponent('legend', function (legendModel) {
  84439. each(selectedMap, function (isSelected, name) {
  84440. // Force other legend has same selected status
  84441. // Or the first is toggled to true and other are toggled to false
  84442. // In the case one legend has some item unSelected in option. And if other legend
  84443. // doesn't has the item, they will assume it is selected.
  84444. legendModel[isSelected ? 'select' : 'unSelect'](name);
  84445. });
  84446. makeSelectedMap(legendModel, allSelectedMap);
  84447. });
  84448. // Return the event explicitly
  84449. return isAllSelect ? {
  84450. selected: allSelectedMap,
  84451. // return legendIndex array to tell the developers which legends are allSelect / inverseSelect
  84452. legendIndex: actionLegendIndices
  84453. } : {
  84454. name: payload.name,
  84455. selected: allSelectedMap
  84456. };
  84457. }
  84458. function makeSelectedMap(legendModel, out) {
  84459. var selectedMap = out || {};
  84460. each(legendModel.getData(), function (model) {
  84461. var name = model.get('name');
  84462. // Wrap element
  84463. if (name === '\n' || name === '') {
  84464. return;
  84465. }
  84466. var isItemSelected = legendModel.isSelected(name);
  84467. if (hasOwn(selectedMap, name)) {
  84468. // Unselected if any legend is unselected
  84469. selectedMap[name] = selectedMap[name] && isItemSelected;
  84470. } else {
  84471. selectedMap[name] = isItemSelected;
  84472. }
  84473. });
  84474. return selectedMap;
  84475. }
  84476. function installLegendAction(registers) {
  84477. /**
  84478. * @event legendToggleSelect
  84479. * @type {Object}
  84480. * @property {string} type 'legendToggleSelect'
  84481. * @property {string} [from]
  84482. * @property {string} name Series name or data item name
  84483. */
  84484. registers.registerAction('legendToggleSelect', 'legendselectchanged', curry(legendSelectActionHandler, 'toggleSelected'));
  84485. registers.registerAction('legendAllSelect', 'legendselectall', curry(legendSelectActionHandler, 'allSelect'));
  84486. registers.registerAction('legendInverseSelect', 'legendinverseselect', curry(legendSelectActionHandler, 'inverseSelect'));
  84487. /**
  84488. * @event legendSelect
  84489. * @type {Object}
  84490. * @property {string} type 'legendSelect'
  84491. * @property {string} name Series name or data item name
  84492. */
  84493. registers.registerAction('legendSelect', 'legendselected', curry(legendSelectActionHandler, 'select'));
  84494. /**
  84495. * @event legendUnSelect
  84496. * @type {Object}
  84497. * @property {string} type 'legendUnSelect'
  84498. * @property {string} name Series name or data item name
  84499. */
  84500. registers.registerAction('legendUnSelect', 'legendunselected', curry(legendSelectActionHandler, 'unSelect'));
  84501. }
  84502. function install$J(registers) {
  84503. registers.registerComponentModel(LegendModel);
  84504. registers.registerComponentView(LegendView);
  84505. registers.registerProcessor(registers.PRIORITY.PROCESSOR.SERIES_FILTER, legendFilter);
  84506. registers.registerSubTypeDefaulter('legend', function () {
  84507. return 'plain';
  84508. });
  84509. installLegendAction(registers);
  84510. }
  84511. var ScrollableLegendModel = /** @class */function (_super) {
  84512. __extends(ScrollableLegendModel, _super);
  84513. function ScrollableLegendModel() {
  84514. var _this = _super !== null && _super.apply(this, arguments) || this;
  84515. _this.type = ScrollableLegendModel.type;
  84516. return _this;
  84517. }
  84518. /**
  84519. * @param {number} scrollDataIndex
  84520. */
  84521. ScrollableLegendModel.prototype.setScrollDataIndex = function (scrollDataIndex) {
  84522. this.option.scrollDataIndex = scrollDataIndex;
  84523. };
  84524. ScrollableLegendModel.prototype.init = function (option, parentModel, ecModel) {
  84525. var inputPositionParams = getLayoutParams(option);
  84526. _super.prototype.init.call(this, option, parentModel, ecModel);
  84527. mergeAndNormalizeLayoutParams$1(this, option, inputPositionParams);
  84528. };
  84529. /**
  84530. * @override
  84531. */
  84532. ScrollableLegendModel.prototype.mergeOption = function (option, ecModel) {
  84533. _super.prototype.mergeOption.call(this, option, ecModel);
  84534. mergeAndNormalizeLayoutParams$1(this, this.option, option);
  84535. };
  84536. ScrollableLegendModel.type = 'legend.scroll';
  84537. ScrollableLegendModel.defaultOption = inheritDefaultOption(LegendModel.defaultOption, {
  84538. scrollDataIndex: 0,
  84539. pageButtonItemGap: 5,
  84540. pageButtonGap: null,
  84541. pageButtonPosition: 'end',
  84542. pageFormatter: '{current}/{total}',
  84543. pageIcons: {
  84544. horizontal: ['M0,0L12,-10L12,10z', 'M0,0L-12,-10L-12,10z'],
  84545. vertical: ['M0,0L20,0L10,-20z', 'M0,0L20,0L10,20z']
  84546. },
  84547. pageIconColor: tokens.color.accent50,
  84548. pageIconInactiveColor: tokens.color.accent10,
  84549. pageIconSize: 15,
  84550. pageTextStyle: {
  84551. color: tokens.color.tertiary
  84552. },
  84553. animationDurationUpdate: 800
  84554. });
  84555. return ScrollableLegendModel;
  84556. }(LegendModel);
  84557. // Do not `ignoreSize` to enable setting {left: 10, right: 10}.
  84558. function mergeAndNormalizeLayoutParams$1(legendModel, target, raw) {
  84559. var orient = legendModel.getOrient();
  84560. var ignoreSize = [1, 1];
  84561. ignoreSize[orient.index] = 0;
  84562. mergeLayoutParam(target, raw, {
  84563. type: 'box',
  84564. ignoreSize: !!ignoreSize
  84565. });
  84566. }
  84567. var Group$3 = Group;
  84568. var WH$3 = ['width', 'height'];
  84569. var XY$3 = ['x', 'y'];
  84570. var ScrollableLegendView = /** @class */function (_super) {
  84571. __extends(ScrollableLegendView, _super);
  84572. function ScrollableLegendView() {
  84573. var _this = _super !== null && _super.apply(this, arguments) || this;
  84574. _this.type = ScrollableLegendView.type;
  84575. _this.newlineDisabled = true;
  84576. _this._currentIndex = 0;
  84577. return _this;
  84578. }
  84579. ScrollableLegendView.prototype.init = function () {
  84580. _super.prototype.init.call(this);
  84581. this.group.add(this._containerGroup = new Group$3());
  84582. this._containerGroup.add(this.getContentGroup());
  84583. this.group.add(this._controllerGroup = new Group$3());
  84584. };
  84585. /**
  84586. * @override
  84587. */
  84588. ScrollableLegendView.prototype.resetInner = function () {
  84589. _super.prototype.resetInner.call(this);
  84590. this._controllerGroup.removeAll();
  84591. this._containerGroup.removeClipPath();
  84592. this._containerGroup.__rectSize = null;
  84593. };
  84594. /**
  84595. * @override
  84596. */
  84597. ScrollableLegendView.prototype.renderInner = function (itemAlign, legendModel, ecModel, api, selector, orient, selectorPosition) {
  84598. var self = this;
  84599. // Render content items.
  84600. _super.prototype.renderInner.call(this, itemAlign, legendModel, ecModel, api, selector, orient, selectorPosition);
  84601. var controllerGroup = this._controllerGroup;
  84602. // FIXME: support be 'auto' adapt to size number text length,
  84603. // e.g., '3/12345' should not overlap with the control arrow button.
  84604. var pageIconSize = legendModel.get('pageIconSize', true);
  84605. var pageIconSizeArr = isArray(pageIconSize) ? pageIconSize : [pageIconSize, pageIconSize];
  84606. createPageButton('pagePrev', 0);
  84607. var pageTextStyleModel = legendModel.getModel('pageTextStyle');
  84608. controllerGroup.add(new ZRText({
  84609. name: 'pageText',
  84610. style: {
  84611. // Placeholder to calculate a proper layout.
  84612. text: 'xx/xx',
  84613. fill: pageTextStyleModel.getTextColor(),
  84614. font: pageTextStyleModel.getFont(),
  84615. verticalAlign: 'middle',
  84616. align: 'center'
  84617. },
  84618. silent: true
  84619. }));
  84620. createPageButton('pageNext', 1);
  84621. function createPageButton(name, iconIdx) {
  84622. var pageDataIndexName = name + 'DataIndex';
  84623. var icon = createIcon(legendModel.get('pageIcons', true)[legendModel.getOrient().name][iconIdx], {
  84624. // Buttons will be created in each render, so we do not need
  84625. // to worry about avoiding using legendModel kept in scope.
  84626. onclick: bind(self._pageGo, self, pageDataIndexName, legendModel, api)
  84627. }, {
  84628. x: -pageIconSizeArr[0] / 2,
  84629. y: -pageIconSizeArr[1] / 2,
  84630. width: pageIconSizeArr[0],
  84631. height: pageIconSizeArr[1]
  84632. });
  84633. icon.name = name;
  84634. controllerGroup.add(icon);
  84635. }
  84636. };
  84637. /**
  84638. * @override
  84639. */
  84640. ScrollableLegendView.prototype.layoutInner = function (legendModel, itemAlign, maxSize, isFirstRender, selector, selectorPosition) {
  84641. var selectorGroup = this.getSelectorGroup();
  84642. var orientIdx = legendModel.getOrient().index;
  84643. var wh = WH$3[orientIdx];
  84644. var xy = XY$3[orientIdx];
  84645. var hw = WH$3[1 - orientIdx];
  84646. var yx = XY$3[1 - orientIdx];
  84647. selector && box(
  84648. // Buttons in selectorGroup always layout horizontally
  84649. 'horizontal', selectorGroup, legendModel.get('selectorItemGap', true));
  84650. var selectorButtonGap = legendModel.get('selectorButtonGap', true);
  84651. var selectorRect = selectorGroup.getBoundingRect();
  84652. var selectorPos = [-selectorRect.x, -selectorRect.y];
  84653. var processMaxSize = clone(maxSize);
  84654. selector && (processMaxSize[wh] = maxSize[wh] - selectorRect[wh] - selectorButtonGap);
  84655. var mainRect = this._layoutContentAndController(legendModel, isFirstRender, processMaxSize, orientIdx, wh, hw, yx, xy);
  84656. if (selector) {
  84657. if (selectorPosition === 'end') {
  84658. selectorPos[orientIdx] += mainRect[wh] + selectorButtonGap;
  84659. } else {
  84660. var offset = selectorRect[wh] + selectorButtonGap;
  84661. selectorPos[orientIdx] -= offset;
  84662. mainRect[xy] -= offset;
  84663. }
  84664. mainRect[wh] += selectorRect[wh] + selectorButtonGap;
  84665. selectorPos[1 - orientIdx] += mainRect[yx] + mainRect[hw] / 2 - selectorRect[hw] / 2;
  84666. mainRect[hw] = Math.max(mainRect[hw], selectorRect[hw]);
  84667. mainRect[yx] = Math.min(mainRect[yx], selectorRect[yx] + selectorPos[1 - orientIdx]);
  84668. selectorGroup.x = selectorPos[0];
  84669. selectorGroup.y = selectorPos[1];
  84670. selectorGroup.markRedraw();
  84671. }
  84672. return mainRect;
  84673. };
  84674. ScrollableLegendView.prototype._layoutContentAndController = function (legendModel, isFirstRender, maxSize, orientIdx, wh, hw, yx, xy) {
  84675. var contentGroup = this.getContentGroup();
  84676. var containerGroup = this._containerGroup;
  84677. var controllerGroup = this._controllerGroup;
  84678. // Place items in contentGroup.
  84679. box(legendModel.get('orient'), contentGroup, legendModel.get('itemGap'), !orientIdx ? null : maxSize.width, orientIdx ? null : maxSize.height);
  84680. box(
  84681. // Buttons in controller are layout always horizontally.
  84682. 'horizontal', controllerGroup, legendModel.get('pageButtonItemGap', true));
  84683. var contentRect = contentGroup.getBoundingRect();
  84684. var controllerRect = controllerGroup.getBoundingRect();
  84685. var showController = this._showController = contentRect[wh] > maxSize[wh];
  84686. // In case that the inner elements of contentGroup layout do not based on [0, 0]
  84687. var contentPos = [-contentRect.x, -contentRect.y];
  84688. // Remain contentPos when scroll animation perfroming.
  84689. // If first rendering, `contentGroup.position` is [0, 0], which
  84690. // does not make sense and may cause unexepcted animation if adopted.
  84691. if (!isFirstRender) {
  84692. contentPos[orientIdx] = contentGroup[xy];
  84693. }
  84694. // Layout container group based on 0.
  84695. var containerPos = [0, 0];
  84696. var controllerPos = [-controllerRect.x, -controllerRect.y];
  84697. var pageButtonGap = retrieve2(legendModel.get('pageButtonGap', true), legendModel.get('itemGap', true));
  84698. // Place containerGroup and controllerGroup and contentGroup.
  84699. if (showController) {
  84700. var pageButtonPosition = legendModel.get('pageButtonPosition', true);
  84701. // controller is on the right / bottom.
  84702. if (pageButtonPosition === 'end') {
  84703. controllerPos[orientIdx] += maxSize[wh] - controllerRect[wh];
  84704. }
  84705. // controller is on the left / top.
  84706. else {
  84707. containerPos[orientIdx] += controllerRect[wh] + pageButtonGap;
  84708. }
  84709. }
  84710. // Always align controller to content as 'middle'.
  84711. controllerPos[1 - orientIdx] += contentRect[hw] / 2 - controllerRect[hw] / 2;
  84712. contentGroup.setPosition(contentPos);
  84713. containerGroup.setPosition(containerPos);
  84714. controllerGroup.setPosition(controllerPos);
  84715. // Calculate `mainRect` and set `clipPath`.
  84716. // mainRect should not be calculated by `this.group.getBoundingRect()`
  84717. // for sake of the overflow.
  84718. var mainRect = {
  84719. x: 0,
  84720. y: 0
  84721. };
  84722. // Consider content may be overflow (should be clipped).
  84723. mainRect[wh] = showController ? maxSize[wh] : contentRect[wh];
  84724. mainRect[hw] = Math.max(contentRect[hw], controllerRect[hw]);
  84725. // `containerRect[yx] + containerPos[1 - orientIdx]` is 0.
  84726. mainRect[yx] = Math.min(0, controllerRect[yx] + controllerPos[1 - orientIdx]);
  84727. containerGroup.__rectSize = maxSize[wh];
  84728. if (showController) {
  84729. var clipShape = {
  84730. x: 0,
  84731. y: 0
  84732. };
  84733. clipShape[wh] = Math.max(maxSize[wh] - controllerRect[wh] - pageButtonGap, 0);
  84734. clipShape[hw] = mainRect[hw];
  84735. containerGroup.setClipPath(new Rect({
  84736. shape: clipShape
  84737. }));
  84738. // Consider content may be larger than container, container rect
  84739. // can not be obtained from `containerGroup.getBoundingRect()`.
  84740. containerGroup.__rectSize = clipShape[wh];
  84741. } else {
  84742. // Do not remove or ignore controller. Keep them set as placeholders.
  84743. controllerGroup.eachChild(function (child) {
  84744. child.attr({
  84745. invisible: true,
  84746. silent: true
  84747. });
  84748. });
  84749. }
  84750. // Content translate animation.
  84751. var pageInfo = this._getPageInfo(legendModel);
  84752. pageInfo.pageIndex != null && updateProps(contentGroup, {
  84753. x: pageInfo.contentPosition[0],
  84754. y: pageInfo.contentPosition[1]
  84755. },
  84756. // When switch from "show controller" to "not show controller", view should be
  84757. // updated immediately without animation, otherwise causes weird effect.
  84758. showController ? legendModel : null);
  84759. this._updatePageInfoView(legendModel, pageInfo);
  84760. return mainRect;
  84761. };
  84762. ScrollableLegendView.prototype._pageGo = function (to, legendModel, api) {
  84763. var scrollDataIndex = this._getPageInfo(legendModel)[to];
  84764. scrollDataIndex != null && api.dispatchAction({
  84765. type: 'legendScroll',
  84766. scrollDataIndex: scrollDataIndex,
  84767. legendId: legendModel.id
  84768. });
  84769. };
  84770. ScrollableLegendView.prototype._updatePageInfoView = function (legendModel, pageInfo) {
  84771. var controllerGroup = this._controllerGroup;
  84772. each(['pagePrev', 'pageNext'], function (name) {
  84773. var key = name + 'DataIndex';
  84774. var canJump = pageInfo[key] != null;
  84775. var icon = controllerGroup.childOfName(name);
  84776. if (icon) {
  84777. icon.setStyle('fill', canJump ? legendModel.get('pageIconColor', true) : legendModel.get('pageIconInactiveColor', true));
  84778. icon.cursor = canJump ? 'pointer' : 'default';
  84779. }
  84780. });
  84781. var pageText = controllerGroup.childOfName('pageText');
  84782. var pageFormatter = legendModel.get('pageFormatter');
  84783. var pageIndex = pageInfo.pageIndex;
  84784. var current = pageIndex != null ? pageIndex + 1 : 0;
  84785. var total = pageInfo.pageCount;
  84786. pageText && pageFormatter && pageText.setStyle('text', isString(pageFormatter) ? pageFormatter.replace('{current}', current == null ? '' : current + '').replace('{total}', total == null ? '' : total + '') : pageFormatter({
  84787. current: current,
  84788. total: total
  84789. }));
  84790. };
  84791. /**
  84792. * contentPosition: Array.<number>, null when data item not found.
  84793. * pageIndex: number, null when data item not found.
  84794. * pageCount: number, always be a number, can be 0.
  84795. * pagePrevDataIndex: number, null when no previous page.
  84796. * pageNextDataIndex: number, null when no next page.
  84797. * }
  84798. */
  84799. ScrollableLegendView.prototype._getPageInfo = function (legendModel) {
  84800. var scrollDataIndex = legendModel.get('scrollDataIndex', true);
  84801. var contentGroup = this.getContentGroup();
  84802. var containerRectSize = this._containerGroup.__rectSize;
  84803. var orientIdx = legendModel.getOrient().index;
  84804. var wh = WH$3[orientIdx];
  84805. var xy = XY$3[orientIdx];
  84806. var targetItemIndex = this._findTargetItemIndex(scrollDataIndex);
  84807. var children = contentGroup.children();
  84808. var targetItem = children[targetItemIndex];
  84809. var itemCount = children.length;
  84810. var pCount = !itemCount ? 0 : 1;
  84811. var result = {
  84812. contentPosition: [contentGroup.x, contentGroup.y],
  84813. pageCount: pCount,
  84814. pageIndex: pCount - 1,
  84815. pagePrevDataIndex: null,
  84816. pageNextDataIndex: null
  84817. };
  84818. if (!targetItem) {
  84819. return result;
  84820. }
  84821. var targetItemInfo = getItemInfo(targetItem);
  84822. result.contentPosition[orientIdx] = -targetItemInfo.s;
  84823. // Strategy:
  84824. // (1) Always align based on the left/top most item.
  84825. // (2) It is user-friendly that the last item shown in the
  84826. // current window is shown at the begining of next window.
  84827. // Otherwise if half of the last item is cut by the window,
  84828. // it will have no chance to display entirely.
  84829. // (3) Consider that item size probably be different, we
  84830. // have calculate pageIndex by size rather than item index,
  84831. // and we can not get page index directly by division.
  84832. // (4) The window is to narrow to contain more than
  84833. // one item, we should make sure that the page can be fliped.
  84834. for (var i = targetItemIndex + 1, winStartItemInfo = targetItemInfo, winEndItemInfo = targetItemInfo, currItemInfo = null; i <= itemCount; ++i) {
  84835. currItemInfo = getItemInfo(children[i]);
  84836. if (
  84837. // Half of the last item is out of the window.
  84838. !currItemInfo && winEndItemInfo.e > winStartItemInfo.s + containerRectSize
  84839. // If the current item does not intersect with the window, the new page
  84840. // can be started at the current item or the last item.
  84841. || currItemInfo && !intersect(currItemInfo, winStartItemInfo.s)) {
  84842. if (winEndItemInfo.i > winStartItemInfo.i) {
  84843. winStartItemInfo = winEndItemInfo;
  84844. } else {
  84845. // e.g., when page size is smaller than item size.
  84846. winStartItemInfo = currItemInfo;
  84847. }
  84848. if (winStartItemInfo) {
  84849. if (result.pageNextDataIndex == null) {
  84850. result.pageNextDataIndex = winStartItemInfo.i;
  84851. }
  84852. ++result.pageCount;
  84853. }
  84854. }
  84855. winEndItemInfo = currItemInfo;
  84856. }
  84857. for (var i = targetItemIndex - 1, winStartItemInfo = targetItemInfo, winEndItemInfo = targetItemInfo, currItemInfo = null; i >= -1; --i) {
  84858. currItemInfo = getItemInfo(children[i]);
  84859. if (
  84860. // If the the end item does not intersect with the window started
  84861. // from the current item, a page can be settled.
  84862. (!currItemInfo || !intersect(winEndItemInfo, currItemInfo.s)
  84863. // e.g., when page size is smaller than item size.
  84864. ) && winStartItemInfo.i < winEndItemInfo.i) {
  84865. winEndItemInfo = winStartItemInfo;
  84866. if (result.pagePrevDataIndex == null) {
  84867. result.pagePrevDataIndex = winStartItemInfo.i;
  84868. }
  84869. ++result.pageCount;
  84870. ++result.pageIndex;
  84871. }
  84872. winStartItemInfo = currItemInfo;
  84873. }
  84874. return result;
  84875. function getItemInfo(el) {
  84876. if (el) {
  84877. var itemRect = el.getBoundingRect();
  84878. var start = itemRect[xy] + el[xy];
  84879. return {
  84880. s: start,
  84881. e: start + itemRect[wh],
  84882. i: el.__legendDataIndex
  84883. };
  84884. }
  84885. }
  84886. function intersect(itemInfo, winStart) {
  84887. return itemInfo.e >= winStart && itemInfo.s <= winStart + containerRectSize;
  84888. }
  84889. };
  84890. ScrollableLegendView.prototype._findTargetItemIndex = function (targetDataIndex) {
  84891. if (!this._showController) {
  84892. return 0;
  84893. }
  84894. var index;
  84895. var contentGroup = this.getContentGroup();
  84896. var defaultIndex;
  84897. contentGroup.eachChild(function (child, idx) {
  84898. var legendDataIdx = child.__legendDataIndex;
  84899. // FIXME
  84900. // If the given targetDataIndex (from model) is illegal,
  84901. // we use defaultIndex. But the index on the legend model and
  84902. // action payload is still illegal. That case will not be
  84903. // changed until some scenario requires.
  84904. if (defaultIndex == null && legendDataIdx != null) {
  84905. defaultIndex = idx;
  84906. }
  84907. if (legendDataIdx === targetDataIndex) {
  84908. index = idx;
  84909. }
  84910. });
  84911. return index != null ? index : defaultIndex;
  84912. };
  84913. ScrollableLegendView.type = 'legend.scroll';
  84914. return ScrollableLegendView;
  84915. }(LegendView);
  84916. /*
  84917. * Licensed to the Apache Software Foundation (ASF) under one
  84918. * or more contributor license agreements. See the NOTICE file
  84919. * distributed with this work for additional information
  84920. * regarding copyright ownership. The ASF licenses this file
  84921. * to you under the Apache License, Version 2.0 (the
  84922. * "License"); you may not use this file except in compliance
  84923. * with the License. You may obtain a copy of the License at
  84924. *
  84925. * http://www.apache.org/licenses/LICENSE-2.0
  84926. *
  84927. * Unless required by applicable law or agreed to in writing,
  84928. * software distributed under the License is distributed on an
  84929. * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
  84930. * KIND, either express or implied. See the License for the
  84931. * specific language governing permissions and limitations
  84932. * under the License.
  84933. */
  84934. /**
  84935. * AUTO-GENERATED FILE. DO NOT MODIFY.
  84936. */
  84937. /*
  84938. * Licensed to the Apache Software Foundation (ASF) under one
  84939. * or more contributor license agreements. See the NOTICE file
  84940. * distributed with this work for additional information
  84941. * regarding copyright ownership. The ASF licenses this file
  84942. * to you under the Apache License, Version 2.0 (the
  84943. * "License"); you may not use this file except in compliance
  84944. * with the License. You may obtain a copy of the License at
  84945. *
  84946. * http://www.apache.org/licenses/LICENSE-2.0
  84947. *
  84948. * Unless required by applicable law or agreed to in writing,
  84949. * software distributed under the License is distributed on an
  84950. * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
  84951. * KIND, either express or implied. See the License for the
  84952. * specific language governing permissions and limitations
  84953. * under the License.
  84954. */
  84955. function installScrollableLegendAction(registers) {
  84956. /**
  84957. * @event legendScroll
  84958. * @type {Object}
  84959. * @property {string} type 'legendScroll'
  84960. * @property {string} scrollDataIndex
  84961. */
  84962. registers.registerAction('legendScroll', 'legendscroll', function (payload, ecModel) {
  84963. var scrollDataIndex = payload.scrollDataIndex;
  84964. scrollDataIndex != null && ecModel.eachComponent({
  84965. mainType: 'legend',
  84966. subType: 'scroll',
  84967. query: payload
  84968. }, function (legendModel) {
  84969. legendModel.setScrollDataIndex(scrollDataIndex);
  84970. });
  84971. });
  84972. }
  84973. function install$K(registers) {
  84974. use(install$J);
  84975. registers.registerComponentModel(ScrollableLegendModel);
  84976. registers.registerComponentView(ScrollableLegendView);
  84977. installScrollableLegendAction(registers);
  84978. }
  84979. function install$L(registers) {
  84980. use(install$J);
  84981. use(install$K);
  84982. }
  84983. var InsideZoomModel = /** @class */function (_super) {
  84984. __extends(InsideZoomModel, _super);
  84985. function InsideZoomModel() {
  84986. var _this = _super !== null && _super.apply(this, arguments) || this;
  84987. _this.type = InsideZoomModel.type;
  84988. return _this;
  84989. }
  84990. InsideZoomModel.type = 'dataZoom.inside';
  84991. InsideZoomModel.defaultOption = inheritDefaultOption(DataZoomModel.defaultOption, {
  84992. disabled: false,
  84993. zoomLock: false,
  84994. zoomOnMouseWheel: true,
  84995. moveOnMouseMove: true,
  84996. moveOnMouseWheel: false,
  84997. preventDefaultMouseMove: true
  84998. });
  84999. return InsideZoomModel;
  85000. }(DataZoomModel);
  85001. var inner$m = makeInner();
  85002. function setViewInfoToCoordSysRecord(api, dataZoomModel, getRange) {
  85003. inner$m(api).coordSysRecordMap.each(function (coordSysRecord) {
  85004. var dzInfo = coordSysRecord.dataZoomInfoMap.get(dataZoomModel.uid);
  85005. if (dzInfo) {
  85006. dzInfo.getRange = getRange;
  85007. }
  85008. });
  85009. }
  85010. function disposeCoordSysRecordIfNeeded(api, dataZoomModel) {
  85011. var coordSysRecordMap = inner$m(api).coordSysRecordMap;
  85012. var coordSysKeyArr = coordSysRecordMap.keys();
  85013. for (var i = 0; i < coordSysKeyArr.length; i++) {
  85014. var coordSysKey = coordSysKeyArr[i];
  85015. var coordSysRecord = coordSysRecordMap.get(coordSysKey);
  85016. var dataZoomInfoMap = coordSysRecord.dataZoomInfoMap;
  85017. if (dataZoomInfoMap) {
  85018. var dzUid = dataZoomModel.uid;
  85019. var dzInfo = dataZoomInfoMap.get(dzUid);
  85020. if (dzInfo) {
  85021. dataZoomInfoMap.removeKey(dzUid);
  85022. if (!dataZoomInfoMap.keys().length) {
  85023. disposeCoordSysRecord(coordSysRecordMap, coordSysRecord);
  85024. }
  85025. }
  85026. }
  85027. }
  85028. }
  85029. function disposeCoordSysRecord(coordSysRecordMap, coordSysRecord) {
  85030. if (coordSysRecord) {
  85031. coordSysRecordMap.removeKey(coordSysRecord.model.uid);
  85032. var controller = coordSysRecord.controller;
  85033. controller && controller.dispose();
  85034. }
  85035. }
  85036. function createCoordSysRecord(api, coordSysModel) {
  85037. // These init props will never change after record created.
  85038. var coordSysRecord = {
  85039. model: coordSysModel,
  85040. containsPoint: curry(containsPoint, coordSysModel),
  85041. dispatchAction: curry(dispatchAction$1, api),
  85042. dataZoomInfoMap: null,
  85043. controller: null
  85044. };
  85045. // Must not do anything depends on coordSysRecord outside the event handler here,
  85046. // because coordSysRecord not completed yet.
  85047. var controller = coordSysRecord.controller = new RoamController(api.getZr());
  85048. each(['pan', 'zoom', 'scrollMove'], function (eventName) {
  85049. controller.on(eventName, function (event) {
  85050. var batch = [];
  85051. coordSysRecord.dataZoomInfoMap.each(function (dzInfo) {
  85052. // Check whether the behaviors (zoomOnMouseWheel, moveOnMouseMove,
  85053. // moveOnMouseWheel, ...) enabled.
  85054. if (!event.isAvailableBehavior(dzInfo.model.option)) {
  85055. return;
  85056. }
  85057. var method = (dzInfo.getRange || {})[eventName];
  85058. var range = method && method(dzInfo.dzReferCoordSysInfo, coordSysRecord.model.mainType, coordSysRecord.controller, event);
  85059. !dzInfo.model.get('disabled', true) && range && batch.push({
  85060. dataZoomId: dzInfo.model.id,
  85061. start: range[0],
  85062. end: range[1]
  85063. });
  85064. });
  85065. batch.length && coordSysRecord.dispatchAction(batch);
  85066. });
  85067. });
  85068. return coordSysRecord;
  85069. }
  85070. /**
  85071. * This action will be throttled.
  85072. */
  85073. function dispatchAction$1(api, batch) {
  85074. if (!api.isDisposed()) {
  85075. api.dispatchAction({
  85076. type: 'dataZoom',
  85077. animation: {
  85078. easing: 'cubicOut',
  85079. duration: 100
  85080. },
  85081. batch: batch
  85082. });
  85083. }
  85084. }
  85085. function containsPoint(coordSysModel, e, x, y) {
  85086. return coordSysModel.coordinateSystem.containPoint([x, y]);
  85087. }
  85088. /**
  85089. * Merge roamController settings when multiple dataZooms share one roamController.
  85090. */
  85091. function mergeControllerParams(dataZoomInfoMap, coordSysRecord, api) {
  85092. var controlType;
  85093. // DO NOT use reserved word (true, false, undefined) as key literally. Even if encapsulated
  85094. // as string, it is probably revert to reserved word by compress tool. See #7411.
  85095. var prefix = 'type_';
  85096. var typePriority = {
  85097. 'type_true': 2,
  85098. 'type_move': 1,
  85099. 'type_false': 0,
  85100. 'type_undefined': -1
  85101. };
  85102. var preventDefaultMouseMove = true;
  85103. dataZoomInfoMap.each(function (dataZoomInfo) {
  85104. var dataZoomModel = dataZoomInfo.model;
  85105. var oneType = dataZoomModel.get('disabled', true) ? false : dataZoomModel.get('zoomLock', true) ? 'move' : true;
  85106. if (typePriority[prefix + oneType] > typePriority[prefix + controlType]) {
  85107. controlType = oneType;
  85108. }
  85109. // Prevent default move event by default. If one false, do not prevent. Otherwise
  85110. // users may be confused why it does not work when multiple insideZooms exist.
  85111. preventDefaultMouseMove = preventDefaultMouseMove && dataZoomModel.get('preventDefaultMouseMove', true);
  85112. });
  85113. return {
  85114. controlType: controlType,
  85115. opt: {
  85116. // RoamController will enable all of these functionalities,
  85117. // and the final behavior is determined by its event listener
  85118. // provided by each inside zoom.
  85119. zoomOnMouseWheel: true,
  85120. moveOnMouseMove: true,
  85121. moveOnMouseWheel: true,
  85122. preventDefaultMouseMove: !!preventDefaultMouseMove,
  85123. api: api,
  85124. zInfo: {
  85125. component: coordSysRecord.model
  85126. },
  85127. triggerInfo: {
  85128. roamTrigger: null,
  85129. isInSelf: coordSysRecord.containsPoint
  85130. }
  85131. }
  85132. };
  85133. }
  85134. function installDataZoomRoamProcessor(registers) {
  85135. registers.registerProcessor(registers.PRIORITY.PROCESSOR.FILTER, function (ecModel, api) {
  85136. var apiInner = inner$m(api);
  85137. var coordSysRecordMap = apiInner.coordSysRecordMap || (apiInner.coordSysRecordMap = createHashMap());
  85138. coordSysRecordMap.each(function (coordSysRecord) {
  85139. // `coordSysRecordMap` always exists (because it holds the `roam controller`, which should
  85140. // better not re-create each time), but clear `dataZoomInfoMap` each round of the workflow.
  85141. coordSysRecord.dataZoomInfoMap = null;
  85142. });
  85143. ecModel.eachComponent({
  85144. mainType: 'dataZoom',
  85145. subType: 'inside'
  85146. }, function (dataZoomModel) {
  85147. var dzReferCoordSysWrap = collectReferCoordSysModelInfo(dataZoomModel);
  85148. each(dzReferCoordSysWrap.infoList, function (dzCoordSysInfo) {
  85149. var coordSysUid = dzCoordSysInfo.model.uid;
  85150. var coordSysRecord = coordSysRecordMap.get(coordSysUid) || coordSysRecordMap.set(coordSysUid, createCoordSysRecord(api, dzCoordSysInfo.model));
  85151. var dataZoomInfoMap = coordSysRecord.dataZoomInfoMap || (coordSysRecord.dataZoomInfoMap = createHashMap());
  85152. // Notice these props might be changed each time for a single dataZoomModel.
  85153. dataZoomInfoMap.set(dataZoomModel.uid, {
  85154. dzReferCoordSysInfo: dzCoordSysInfo,
  85155. model: dataZoomModel,
  85156. getRange: null
  85157. });
  85158. });
  85159. });
  85160. // (1) Merge dataZoom settings for each coord sys and set to the roam controller.
  85161. // (2) Clear coord sys if not refered by any dataZoom.
  85162. coordSysRecordMap.each(function (coordSysRecord) {
  85163. var controller = coordSysRecord.controller;
  85164. var firstDzInfo;
  85165. var dataZoomInfoMap = coordSysRecord.dataZoomInfoMap;
  85166. if (dataZoomInfoMap) {
  85167. var firstDzKey = dataZoomInfoMap.keys()[0];
  85168. if (firstDzKey != null) {
  85169. firstDzInfo = dataZoomInfoMap.get(firstDzKey);
  85170. }
  85171. }
  85172. if (!firstDzInfo) {
  85173. disposeCoordSysRecord(coordSysRecordMap, coordSysRecord);
  85174. return;
  85175. }
  85176. var controllerParams = mergeControllerParams(dataZoomInfoMap, coordSysRecord, api);
  85177. controller.enable(controllerParams.controlType, controllerParams.opt);
  85178. createOrUpdate(coordSysRecord, 'dispatchAction', firstDzInfo.model.get('throttle', true), 'fixRate');
  85179. });
  85180. });
  85181. }
  85182. var InsideZoomView = /** @class */function (_super) {
  85183. __extends(InsideZoomView, _super);
  85184. function InsideZoomView() {
  85185. var _this = _super !== null && _super.apply(this, arguments) || this;
  85186. _this.type = 'dataZoom.inside';
  85187. return _this;
  85188. }
  85189. InsideZoomView.prototype.render = function (dataZoomModel, ecModel, api) {
  85190. _super.prototype.render.apply(this, arguments);
  85191. if (dataZoomModel.noTarget()) {
  85192. this._clear();
  85193. return;
  85194. }
  85195. // Hence the `throttle` util ensures to preserve command order,
  85196. // here simply updating range all the time will not cause missing
  85197. // any of the the roam change.
  85198. this.range = dataZoomModel.getPercentRange();
  85199. // Reset controllers.
  85200. setViewInfoToCoordSysRecord(api, dataZoomModel, {
  85201. pan: bind(getRangeHandlers.pan, this),
  85202. zoom: bind(getRangeHandlers.zoom, this),
  85203. scrollMove: bind(getRangeHandlers.scrollMove, this)
  85204. });
  85205. };
  85206. InsideZoomView.prototype.dispose = function () {
  85207. this._clear();
  85208. _super.prototype.dispose.apply(this, arguments);
  85209. };
  85210. InsideZoomView.prototype._clear = function () {
  85211. disposeCoordSysRecordIfNeeded(this.api, this.dataZoomModel);
  85212. this.range = null;
  85213. };
  85214. InsideZoomView.type = 'dataZoom.inside';
  85215. return InsideZoomView;
  85216. }(DataZoomView);
  85217. var getRangeHandlers = {
  85218. zoom: function (coordSysInfo, coordSysMainType, controller, e) {
  85219. var lastRange = this.range;
  85220. var range = lastRange.slice();
  85221. // Calculate transform by the first axis.
  85222. var axisModel = coordSysInfo.axisModels[0];
  85223. if (!axisModel) {
  85224. return;
  85225. }
  85226. var directionInfo = getDirectionInfo[coordSysMainType](null, [e.originX, e.originY], axisModel, controller, coordSysInfo);
  85227. var percentPoint = (directionInfo.signal > 0 ? directionInfo.pixelStart + directionInfo.pixelLength - directionInfo.pixel : directionInfo.pixel - directionInfo.pixelStart) / directionInfo.pixelLength * (range[1] - range[0]) + range[0];
  85228. var scale = Math.max(1 / e.scale, 0);
  85229. range[0] = (range[0] - percentPoint) * scale + percentPoint;
  85230. range[1] = (range[1] - percentPoint) * scale + percentPoint;
  85231. // Restrict range.
  85232. var minMaxSpan = this.dataZoomModel.findRepresentativeAxisProxy().getMinMaxSpan();
  85233. sliderMove(0, range, [0, 100], 0, minMaxSpan.minSpan, minMaxSpan.maxSpan);
  85234. this.range = range;
  85235. if (lastRange[0] !== range[0] || lastRange[1] !== range[1]) {
  85236. return range;
  85237. }
  85238. },
  85239. pan: makeMover(function (range, axisModel, coordSysInfo, coordSysMainType, controller, e) {
  85240. var directionInfo = getDirectionInfo[coordSysMainType]([e.oldX, e.oldY], [e.newX, e.newY], axisModel, controller, coordSysInfo);
  85241. return directionInfo.signal * (range[1] - range[0]) * directionInfo.pixel / directionInfo.pixelLength;
  85242. }),
  85243. scrollMove: makeMover(function (range, axisModel, coordSysInfo, coordSysMainType, controller, e) {
  85244. var directionInfo = getDirectionInfo[coordSysMainType]([0, 0], [e.scrollDelta, e.scrollDelta], axisModel, controller, coordSysInfo);
  85245. return directionInfo.signal * (range[1] - range[0]) * e.scrollDelta;
  85246. })
  85247. };
  85248. function makeMover(getPercentDelta) {
  85249. return function (coordSysInfo, coordSysMainType, controller, e) {
  85250. var lastRange = this.range;
  85251. var range = lastRange.slice();
  85252. // Calculate transform by the first axis.
  85253. var axisModel = coordSysInfo.axisModels[0];
  85254. if (!axisModel) {
  85255. return;
  85256. }
  85257. var percentDelta = getPercentDelta(range, axisModel, coordSysInfo, coordSysMainType, controller, e);
  85258. sliderMove(percentDelta, range, [0, 100], 'all');
  85259. this.range = range;
  85260. if (lastRange[0] !== range[0] || lastRange[1] !== range[1]) {
  85261. return range;
  85262. }
  85263. };
  85264. }
  85265. var getDirectionInfo = {
  85266. grid: function (oldPoint, newPoint, axisModel, controller, coordSysInfo) {
  85267. var axis = axisModel.axis;
  85268. var ret = {};
  85269. var rect = coordSysInfo.model.coordinateSystem.getRect();
  85270. oldPoint = oldPoint || [0, 0];
  85271. if (axis.dim === 'x') {
  85272. ret.pixel = newPoint[0] - oldPoint[0];
  85273. ret.pixelLength = rect.width;
  85274. ret.pixelStart = rect.x;
  85275. ret.signal = axis.inverse ? 1 : -1;
  85276. } else {
  85277. // axis.dim === 'y'
  85278. ret.pixel = newPoint[1] - oldPoint[1];
  85279. ret.pixelLength = rect.height;
  85280. ret.pixelStart = rect.y;
  85281. ret.signal = axis.inverse ? -1 : 1;
  85282. }
  85283. return ret;
  85284. },
  85285. polar: function (oldPoint, newPoint, axisModel, controller, coordSysInfo) {
  85286. var axis = axisModel.axis;
  85287. var ret = {};
  85288. var polar = coordSysInfo.model.coordinateSystem;
  85289. var radiusExtent = polar.getRadiusAxis().getExtent();
  85290. var angleExtent = polar.getAngleAxis().getExtent();
  85291. oldPoint = oldPoint ? polar.pointToCoord(oldPoint) : [0, 0];
  85292. newPoint = polar.pointToCoord(newPoint);
  85293. if (axisModel.mainType === 'radiusAxis') {
  85294. ret.pixel = newPoint[0] - oldPoint[0];
  85295. // ret.pixelLength = Math.abs(radiusExtent[1] - radiusExtent[0]);
  85296. // ret.pixelStart = Math.min(radiusExtent[0], radiusExtent[1]);
  85297. ret.pixelLength = radiusExtent[1] - radiusExtent[0];
  85298. ret.pixelStart = radiusExtent[0];
  85299. ret.signal = axis.inverse ? 1 : -1;
  85300. } else {
  85301. // 'angleAxis'
  85302. ret.pixel = newPoint[1] - oldPoint[1];
  85303. // ret.pixelLength = Math.abs(angleExtent[1] - angleExtent[0]);
  85304. // ret.pixelStart = Math.min(angleExtent[0], angleExtent[1]);
  85305. ret.pixelLength = angleExtent[1] - angleExtent[0];
  85306. ret.pixelStart = angleExtent[0];
  85307. ret.signal = axis.inverse ? -1 : 1;
  85308. }
  85309. return ret;
  85310. },
  85311. singleAxis: function (oldPoint, newPoint, axisModel, controller, coordSysInfo) {
  85312. var axis = axisModel.axis;
  85313. var rect = coordSysInfo.model.coordinateSystem.getRect();
  85314. var ret = {};
  85315. oldPoint = oldPoint || [0, 0];
  85316. if (axis.orient === 'horizontal') {
  85317. ret.pixel = newPoint[0] - oldPoint[0];
  85318. ret.pixelLength = rect.width;
  85319. ret.pixelStart = rect.x;
  85320. ret.signal = axis.inverse ? 1 : -1;
  85321. } else {
  85322. // 'vertical'
  85323. ret.pixel = newPoint[1] - oldPoint[1];
  85324. ret.pixelLength = rect.height;
  85325. ret.pixelStart = rect.y;
  85326. ret.signal = axis.inverse ? -1 : 1;
  85327. }
  85328. return ret;
  85329. }
  85330. };
  85331. function install$M(registers) {
  85332. installCommon(registers);
  85333. registers.registerComponentModel(InsideZoomModel);
  85334. registers.registerComponentView(InsideZoomView);
  85335. installDataZoomRoamProcessor(registers);
  85336. }
  85337. var SliderZoomModel = /** @class */function (_super) {
  85338. __extends(SliderZoomModel, _super);
  85339. function SliderZoomModel() {
  85340. var _this = _super !== null && _super.apply(this, arguments) || this;
  85341. _this.type = SliderZoomModel.type;
  85342. return _this;
  85343. }
  85344. SliderZoomModel.type = 'dataZoom.slider';
  85345. SliderZoomModel.layoutMode = 'box';
  85346. SliderZoomModel.defaultOption = inheritDefaultOption(DataZoomModel.defaultOption, {
  85347. show: true,
  85348. // deault value can only be drived in view stage.
  85349. right: 'ph',
  85350. top: 'ph',
  85351. width: 'ph',
  85352. height: 'ph',
  85353. left: null,
  85354. bottom: null,
  85355. borderColor: tokens.color.accent10,
  85356. borderRadius: 0,
  85357. backgroundColor: tokens.color.transparent,
  85358. // dataBackgroundColor: '#ddd',
  85359. dataBackground: {
  85360. lineStyle: {
  85361. color: tokens.color.accent30,
  85362. width: 0.5
  85363. },
  85364. areaStyle: {
  85365. color: tokens.color.accent20,
  85366. opacity: 0.2
  85367. }
  85368. },
  85369. selectedDataBackground: {
  85370. lineStyle: {
  85371. color: tokens.color.accent40,
  85372. width: 0.5
  85373. },
  85374. areaStyle: {
  85375. color: tokens.color.accent20,
  85376. opacity: 0.3
  85377. }
  85378. },
  85379. // Color of selected window.
  85380. fillerColor: 'rgba(135,175,274,0.2)',
  85381. handleIcon: 'path://M-9.35,34.56V42m0-40V9.5m-2,0h4a2,2,0,0,1,2,2v21a2,2,0,0,1-2,2h-4a2,2,0,0,1-2-2v-21A2,2,0,0,1-11.35,9.5Z',
  85382. // Percent of the slider height
  85383. handleSize: '100%',
  85384. handleStyle: {
  85385. color: tokens.color.neutral00,
  85386. borderColor: tokens.color.accent20
  85387. },
  85388. moveHandleSize: 7,
  85389. moveHandleIcon: 'path://M-320.9-50L-320.9-50c18.1,0,27.1,9,27.1,27.1V85.7c0,18.1-9,27.1-27.1,27.1l0,0c-18.1,0-27.1-9-27.1-27.1V-22.9C-348-41-339-50-320.9-50z M-212.3-50L-212.3-50c18.1,0,27.1,9,27.1,27.1V85.7c0,18.1-9,27.1-27.1,27.1l0,0c-18.1,0-27.1-9-27.1-27.1V-22.9C-239.4-41-230.4-50-212.3-50z M-103.7-50L-103.7-50c18.1,0,27.1,9,27.1,27.1V85.7c0,18.1-9,27.1-27.1,27.1l0,0c-18.1,0-27.1-9-27.1-27.1V-22.9C-130.9-41-121.8-50-103.7-50z',
  85390. moveHandleStyle: {
  85391. color: tokens.color.accent40,
  85392. opacity: 0.5
  85393. },
  85394. showDetail: true,
  85395. showDataShadow: 'auto',
  85396. realtime: true,
  85397. zoomLock: false,
  85398. textStyle: {
  85399. color: tokens.color.tertiary
  85400. },
  85401. brushSelect: true,
  85402. brushStyle: {
  85403. color: tokens.color.accent30,
  85404. opacity: 0.3
  85405. },
  85406. emphasis: {
  85407. handleLabel: {
  85408. show: true
  85409. },
  85410. handleStyle: {
  85411. borderColor: tokens.color.accent40
  85412. },
  85413. moveHandleStyle: {
  85414. opacity: 0.8
  85415. }
  85416. },
  85417. defaultLocationEdgeGap: 15
  85418. });
  85419. return SliderZoomModel;
  85420. }(DataZoomModel);
  85421. var Rect$2 = Rect;
  85422. // Constants
  85423. var DEFAULT_FRAME_BORDER_WIDTH = 1;
  85424. var DEFAULT_FILLER_SIZE = 30;
  85425. var DEFAULT_MOVE_HANDLE_SIZE = 7;
  85426. var HORIZONTAL = 'horizontal';
  85427. var VERTICAL = 'vertical';
  85428. var LABEL_GAP = 5;
  85429. var SHOW_DATA_SHADOW_SERIES_TYPE = ['line', 'bar', 'candlestick', 'scatter'];
  85430. var REALTIME_ANIMATION_CONFIG = {
  85431. easing: 'cubicOut',
  85432. duration: 100,
  85433. delay: 0
  85434. };
  85435. var SliderZoomView = /** @class */function (_super) {
  85436. __extends(SliderZoomView, _super);
  85437. function SliderZoomView() {
  85438. var _this = _super !== null && _super.apply(this, arguments) || this;
  85439. _this.type = SliderZoomView.type;
  85440. _this._displayables = {};
  85441. return _this;
  85442. }
  85443. SliderZoomView.prototype.init = function (ecModel, api) {
  85444. this.api = api;
  85445. // A unique handler for each dataZoom component
  85446. this._onBrush = bind(this._onBrush, this);
  85447. this._onBrushEnd = bind(this._onBrushEnd, this);
  85448. };
  85449. SliderZoomView.prototype.render = function (dataZoomModel, ecModel, api, payload) {
  85450. _super.prototype.render.apply(this, arguments);
  85451. createOrUpdate(this, '_dispatchZoomAction', dataZoomModel.get('throttle'), 'fixRate');
  85452. this._orient = dataZoomModel.getOrient();
  85453. if (dataZoomModel.get('show') === false) {
  85454. this.group.removeAll();
  85455. return;
  85456. }
  85457. if (dataZoomModel.noTarget()) {
  85458. this._clear();
  85459. this.group.removeAll();
  85460. return;
  85461. }
  85462. // Notice: this._resetInterval() should not be executed when payload.type
  85463. // is 'dataZoom', origin this._range should be maintained, otherwise 'pan'
  85464. // or 'zoom' info will be missed because of 'throttle' of this.dispatchAction,
  85465. if (!payload || payload.type !== 'dataZoom' || payload.from !== this.uid) {
  85466. this._buildView();
  85467. }
  85468. this._updateView();
  85469. };
  85470. SliderZoomView.prototype.dispose = function () {
  85471. this._clear();
  85472. _super.prototype.dispose.apply(this, arguments);
  85473. };
  85474. SliderZoomView.prototype._clear = function () {
  85475. clear(this, '_dispatchZoomAction');
  85476. var zr = this.api.getZr();
  85477. zr.off('mousemove', this._onBrush);
  85478. zr.off('mouseup', this._onBrushEnd);
  85479. };
  85480. SliderZoomView.prototype._buildView = function () {
  85481. var thisGroup = this.group;
  85482. thisGroup.removeAll();
  85483. this._brushing = false;
  85484. this._displayables.brushRect = null;
  85485. this._resetLocation();
  85486. this._resetInterval();
  85487. var barGroup = this._displayables.sliderGroup = new Group();
  85488. this._renderBackground();
  85489. this._renderHandle();
  85490. this._renderDataShadow();
  85491. thisGroup.add(barGroup);
  85492. this._positionGroup();
  85493. };
  85494. SliderZoomView.prototype._resetLocation = function () {
  85495. var dataZoomModel = this.dataZoomModel;
  85496. var api = this.api;
  85497. var showMoveHandle = dataZoomModel.get('brushSelect');
  85498. var moveHandleSize = showMoveHandle ? DEFAULT_MOVE_HANDLE_SIZE : 0;
  85499. var refContainer = createBoxLayoutReference(dataZoomModel, api).refContainer;
  85500. // If some of x/y/width/height are not specified,
  85501. // auto-adapt according to target grid.
  85502. var coordRect = this._findCoordRect();
  85503. var edgeGap = dataZoomModel.get('defaultLocationEdgeGap', true) || 0;
  85504. // Default align by coordinate system rect.
  85505. var positionInfo = this._orient === HORIZONTAL ? {
  85506. // Why using 'right', because right should be used in vertical,
  85507. // and it is better to be consistent for dealing with position param merge.
  85508. right: refContainer.width - coordRect.x - coordRect.width,
  85509. top: refContainer.height - DEFAULT_FILLER_SIZE - edgeGap - moveHandleSize,
  85510. width: coordRect.width,
  85511. height: DEFAULT_FILLER_SIZE
  85512. } : {
  85513. right: edgeGap,
  85514. top: coordRect.y,
  85515. width: DEFAULT_FILLER_SIZE,
  85516. height: coordRect.height
  85517. };
  85518. // Do not write back to option and replace value 'ph', because
  85519. // the 'ph' value should be recalculated when resize.
  85520. var layoutParams = getLayoutParams(dataZoomModel.option);
  85521. // Replace the placeholder value.
  85522. each(['right', 'top', 'width', 'height'], function (name) {
  85523. if (layoutParams[name] === 'ph') {
  85524. layoutParams[name] = positionInfo[name];
  85525. }
  85526. });
  85527. var layoutRect = getLayoutRect(layoutParams, refContainer);
  85528. this._location = {
  85529. x: layoutRect.x,
  85530. y: layoutRect.y
  85531. };
  85532. this._size = [layoutRect.width, layoutRect.height];
  85533. this._orient === VERTICAL && this._size.reverse();
  85534. };
  85535. SliderZoomView.prototype._positionGroup = function () {
  85536. var thisGroup = this.group;
  85537. var location = this._location;
  85538. var orient = this._orient;
  85539. // Just use the first axis to determine mapping.
  85540. var targetAxisModel = this.dataZoomModel.getFirstTargetAxisModel();
  85541. var inverse = targetAxisModel && targetAxisModel.get('inverse');
  85542. var sliderGroup = this._displayables.sliderGroup;
  85543. var otherAxisInverse = (this._dataShadowInfo || {}).otherAxisInverse;
  85544. // Transform barGroup.
  85545. sliderGroup.attr(orient === HORIZONTAL && !inverse ? {
  85546. scaleY: otherAxisInverse ? 1 : -1,
  85547. scaleX: 1
  85548. } : orient === HORIZONTAL && inverse ? {
  85549. scaleY: otherAxisInverse ? 1 : -1,
  85550. scaleX: -1
  85551. } : orient === VERTICAL && !inverse ? {
  85552. scaleY: otherAxisInverse ? -1 : 1,
  85553. scaleX: 1,
  85554. rotation: Math.PI / 2
  85555. }
  85556. // Don't use Math.PI, considering shadow direction.
  85557. : {
  85558. scaleY: otherAxisInverse ? -1 : 1,
  85559. scaleX: -1,
  85560. rotation: Math.PI / 2
  85561. });
  85562. // Position barGroup
  85563. var rect = thisGroup.getBoundingRect([sliderGroup]);
  85564. thisGroup.x = location.x - rect.x;
  85565. thisGroup.y = location.y - rect.y;
  85566. thisGroup.markRedraw();
  85567. };
  85568. SliderZoomView.prototype._getViewExtent = function () {
  85569. return [0, this._size[0]];
  85570. };
  85571. SliderZoomView.prototype._renderBackground = function () {
  85572. var dataZoomModel = this.dataZoomModel;
  85573. var size = this._size;
  85574. var barGroup = this._displayables.sliderGroup;
  85575. var brushSelect = dataZoomModel.get('brushSelect');
  85576. barGroup.add(new Rect$2({
  85577. silent: true,
  85578. shape: {
  85579. x: 0,
  85580. y: 0,
  85581. width: size[0],
  85582. height: size[1]
  85583. },
  85584. style: {
  85585. fill: dataZoomModel.get('backgroundColor')
  85586. },
  85587. z2: -40
  85588. }));
  85589. // Click panel, over shadow, below handles.
  85590. var clickPanel = new Rect$2({
  85591. shape: {
  85592. x: 0,
  85593. y: 0,
  85594. width: size[0],
  85595. height: size[1]
  85596. },
  85597. style: {
  85598. fill: 'transparent'
  85599. },
  85600. z2: 0,
  85601. onclick: bind(this._onClickPanel, this)
  85602. });
  85603. var zr = this.api.getZr();
  85604. if (brushSelect) {
  85605. clickPanel.on('mousedown', this._onBrushStart, this);
  85606. clickPanel.cursor = 'crosshair';
  85607. zr.on('mousemove', this._onBrush);
  85608. zr.on('mouseup', this._onBrushEnd);
  85609. } else {
  85610. zr.off('mousemove', this._onBrush);
  85611. zr.off('mouseup', this._onBrushEnd);
  85612. }
  85613. barGroup.add(clickPanel);
  85614. };
  85615. SliderZoomView.prototype._renderDataShadow = function () {
  85616. var info = this._dataShadowInfo = this._prepareDataShadowInfo();
  85617. this._displayables.dataShadowSegs = [];
  85618. if (!info) {
  85619. return;
  85620. }
  85621. var size = this._size;
  85622. var oldSize = this._shadowSize || [];
  85623. var seriesModel = info.series;
  85624. var data = seriesModel.getRawData();
  85625. var candlestickDim = seriesModel.getShadowDim && seriesModel.getShadowDim();
  85626. var otherDim = candlestickDim && data.getDimensionInfo(candlestickDim) ? seriesModel.getShadowDim() // @see candlestick
  85627. : info.otherDim;
  85628. if (otherDim == null) {
  85629. return;
  85630. }
  85631. var polygonPts = this._shadowPolygonPts;
  85632. var polylinePts = this._shadowPolylinePts;
  85633. // Not re-render if data doesn't change.
  85634. if (data !== this._shadowData || otherDim !== this._shadowDim || size[0] !== oldSize[0] || size[1] !== oldSize[1]) {
  85635. var thisDataExtent_1 = data.getDataExtent(info.thisDim);
  85636. var otherDataExtent_1 = data.getDataExtent(otherDim);
  85637. // Nice extent.
  85638. var otherOffset = (otherDataExtent_1[1] - otherDataExtent_1[0]) * 0.3;
  85639. otherDataExtent_1 = [otherDataExtent_1[0] - otherOffset, otherDataExtent_1[1] + otherOffset];
  85640. var otherShadowExtent_1 = [0, size[1]];
  85641. var thisShadowExtent = [0, size[0]];
  85642. var areaPoints_1 = [[size[0], 0], [0, 0]];
  85643. var linePoints_1 = [];
  85644. var step_1 = thisShadowExtent[1] / Math.max(1, data.count() - 1);
  85645. var normalizationConstant_1 = size[0] / (thisDataExtent_1[1] - thisDataExtent_1[0]);
  85646. var isTimeAxis_1 = info.thisAxis.type === 'time';
  85647. var thisCoord_1 = -step_1;
  85648. // Optimize for large data shadow
  85649. var stride_1 = Math.round(data.count() / size[0]);
  85650. var lastIsEmpty_1;
  85651. data.each([info.thisDim, otherDim], function (thisValue, otherValue, index) {
  85652. if (stride_1 > 0 && index % stride_1) {
  85653. if (!isTimeAxis_1) {
  85654. thisCoord_1 += step_1;
  85655. }
  85656. return;
  85657. }
  85658. thisCoord_1 = isTimeAxis_1 ? (+thisValue - thisDataExtent_1[0]) * normalizationConstant_1 : thisCoord_1 + step_1;
  85659. // FIXME
  85660. // Should consider axis.min/axis.max when drawing dataShadow.
  85661. // FIXME
  85662. // 应该使用统一的空判断?还是在list里进行空判断?
  85663. var isEmpty = otherValue == null || isNaN(otherValue) || otherValue === '';
  85664. // See #4235.
  85665. var otherCoord = isEmpty ? 0 : linearMap(otherValue, otherDataExtent_1, otherShadowExtent_1, true);
  85666. // Attempt to draw data shadow precisely when there are empty value.
  85667. if (isEmpty && !lastIsEmpty_1 && index) {
  85668. areaPoints_1.push([areaPoints_1[areaPoints_1.length - 1][0], 0]);
  85669. linePoints_1.push([linePoints_1[linePoints_1.length - 1][0], 0]);
  85670. } else if (!isEmpty && lastIsEmpty_1) {
  85671. areaPoints_1.push([thisCoord_1, 0]);
  85672. linePoints_1.push([thisCoord_1, 0]);
  85673. }
  85674. if (!isEmpty) {
  85675. areaPoints_1.push([thisCoord_1, otherCoord]);
  85676. linePoints_1.push([thisCoord_1, otherCoord]);
  85677. }
  85678. lastIsEmpty_1 = isEmpty;
  85679. });
  85680. polygonPts = this._shadowPolygonPts = areaPoints_1;
  85681. polylinePts = this._shadowPolylinePts = linePoints_1;
  85682. }
  85683. this._shadowData = data;
  85684. this._shadowDim = otherDim;
  85685. this._shadowSize = [size[0], size[1]];
  85686. var dataZoomModel = this.dataZoomModel;
  85687. function createDataShadowGroup(isSelectedArea) {
  85688. var model = dataZoomModel.getModel(isSelectedArea ? 'selectedDataBackground' : 'dataBackground');
  85689. var group = new Group();
  85690. var polygon = new Polygon({
  85691. shape: {
  85692. points: polygonPts
  85693. },
  85694. segmentIgnoreThreshold: 1,
  85695. style: model.getModel('areaStyle').getAreaStyle(),
  85696. silent: true,
  85697. z2: -20
  85698. });
  85699. var polyline = new Polyline({
  85700. shape: {
  85701. points: polylinePts
  85702. },
  85703. segmentIgnoreThreshold: 1,
  85704. style: model.getModel('lineStyle').getLineStyle(),
  85705. silent: true,
  85706. z2: -19
  85707. });
  85708. group.add(polygon);
  85709. group.add(polyline);
  85710. return group;
  85711. }
  85712. // let dataBackgroundModel = dataZoomModel.getModel('dataBackground');
  85713. for (var i = 0; i < 3; i++) {
  85714. var group = createDataShadowGroup(i === 1);
  85715. this._displayables.sliderGroup.add(group);
  85716. this._displayables.dataShadowSegs.push(group);
  85717. }
  85718. };
  85719. SliderZoomView.prototype._prepareDataShadowInfo = function () {
  85720. var dataZoomModel = this.dataZoomModel;
  85721. var showDataShadow = dataZoomModel.get('showDataShadow');
  85722. if (showDataShadow === false) {
  85723. return;
  85724. }
  85725. // Find a representative series.
  85726. var result;
  85727. var ecModel = this.ecModel;
  85728. dataZoomModel.eachTargetAxis(function (axisDim, axisIndex) {
  85729. var seriesModels = dataZoomModel.getAxisProxy(axisDim, axisIndex).getTargetSeriesModels();
  85730. each(seriesModels, function (seriesModel) {
  85731. if (result) {
  85732. return;
  85733. }
  85734. if (showDataShadow !== true && indexOf(SHOW_DATA_SHADOW_SERIES_TYPE, seriesModel.get('type')) < 0) {
  85735. return;
  85736. }
  85737. var thisAxis = ecModel.getComponent(getAxisMainType(axisDim), axisIndex).axis;
  85738. var otherDim = getOtherDim(axisDim);
  85739. var otherAxisInverse;
  85740. var coordSys = seriesModel.coordinateSystem;
  85741. if (otherDim != null && coordSys.getOtherAxis) {
  85742. otherAxisInverse = coordSys.getOtherAxis(thisAxis).inverse;
  85743. }
  85744. otherDim = seriesModel.getData().mapDimension(otherDim);
  85745. var thisDim = seriesModel.getData().mapDimension(axisDim);
  85746. result = {
  85747. thisAxis: thisAxis,
  85748. series: seriesModel,
  85749. thisDim: thisDim,
  85750. otherDim: otherDim,
  85751. otherAxisInverse: otherAxisInverse
  85752. };
  85753. }, this);
  85754. }, this);
  85755. return result;
  85756. };
  85757. SliderZoomView.prototype._renderHandle = function () {
  85758. var thisGroup = this.group;
  85759. var displayables = this._displayables;
  85760. var handles = displayables.handles = [null, null];
  85761. var handleLabels = displayables.handleLabels = [null, null];
  85762. var sliderGroup = this._displayables.sliderGroup;
  85763. var size = this._size;
  85764. var dataZoomModel = this.dataZoomModel;
  85765. var api = this.api;
  85766. var borderRadius = dataZoomModel.get('borderRadius') || 0;
  85767. var brushSelect = dataZoomModel.get('brushSelect');
  85768. var filler = displayables.filler = new Rect$2({
  85769. silent: brushSelect,
  85770. style: {
  85771. fill: dataZoomModel.get('fillerColor')
  85772. },
  85773. textConfig: {
  85774. position: 'inside'
  85775. }
  85776. });
  85777. sliderGroup.add(filler);
  85778. // Frame border.
  85779. sliderGroup.add(new Rect$2({
  85780. silent: true,
  85781. subPixelOptimize: true,
  85782. shape: {
  85783. x: 0,
  85784. y: 0,
  85785. width: size[0],
  85786. height: size[1],
  85787. r: borderRadius
  85788. },
  85789. style: {
  85790. // deprecated option
  85791. stroke: dataZoomModel.get('dataBackgroundColor') || dataZoomModel.get('borderColor'),
  85792. lineWidth: DEFAULT_FRAME_BORDER_WIDTH,
  85793. fill: tokens.color.transparent
  85794. }
  85795. }));
  85796. // Left and right handle to resize
  85797. each([0, 1], function (handleIndex) {
  85798. var iconStr = dataZoomModel.get('handleIcon');
  85799. if (!symbolBuildProxies[iconStr] && iconStr.indexOf('path://') < 0 && iconStr.indexOf('image://') < 0) {
  85800. // Compatitable with the old icon parsers. Which can use a path string without path://
  85801. iconStr = 'path://' + iconStr;
  85802. if ("development" !== 'production') {
  85803. deprecateLog('handleIcon now needs \'path://\' prefix when using a path string');
  85804. }
  85805. }
  85806. var path = createSymbol(iconStr, -1, 0, 2, 2, null, true);
  85807. path.attr({
  85808. cursor: getCursor(this._orient),
  85809. draggable: true,
  85810. drift: bind(this._onDragMove, this, handleIndex),
  85811. ondragend: bind(this._onDragEnd, this),
  85812. onmouseover: bind(this._showDataInfo, this, true),
  85813. onmouseout: bind(this._showDataInfo, this, false),
  85814. z2: 5
  85815. });
  85816. var bRect = path.getBoundingRect();
  85817. var handleSize = dataZoomModel.get('handleSize');
  85818. this._handleHeight = parsePercent$1(handleSize, this._size[1]);
  85819. this._handleWidth = bRect.width / bRect.height * this._handleHeight;
  85820. path.setStyle(dataZoomModel.getModel('handleStyle').getItemStyle());
  85821. path.style.strokeNoScale = true;
  85822. path.rectHover = true;
  85823. path.ensureState('emphasis').style = dataZoomModel.getModel(['emphasis', 'handleStyle']).getItemStyle();
  85824. enableHoverEmphasis(path);
  85825. var handleColor = dataZoomModel.get('handleColor'); // deprecated option
  85826. // Compatitable with previous version
  85827. if (handleColor != null) {
  85828. path.style.fill = handleColor;
  85829. }
  85830. sliderGroup.add(handles[handleIndex] = path);
  85831. var textStyleModel = dataZoomModel.getModel('textStyle');
  85832. var handleLabel = dataZoomModel.get('handleLabel') || {};
  85833. var handleLabelShow = handleLabel.show || false;
  85834. thisGroup.add(handleLabels[handleIndex] = new ZRText({
  85835. silent: true,
  85836. invisible: !handleLabelShow,
  85837. style: createTextStyle(textStyleModel, {
  85838. x: 0,
  85839. y: 0,
  85840. text: '',
  85841. verticalAlign: 'middle',
  85842. align: 'center',
  85843. fill: textStyleModel.getTextColor(),
  85844. font: textStyleModel.getFont()
  85845. }),
  85846. z2: 10
  85847. }));
  85848. }, this);
  85849. // Handle to move. Only visible when brushSelect is set true.
  85850. var actualMoveZone = filler;
  85851. if (brushSelect) {
  85852. var moveHandleHeight = parsePercent$1(dataZoomModel.get('moveHandleSize'), size[1]);
  85853. var moveHandle_1 = displayables.moveHandle = new Rect({
  85854. style: dataZoomModel.getModel('moveHandleStyle').getItemStyle(),
  85855. silent: true,
  85856. shape: {
  85857. r: [0, 0, 2, 2],
  85858. y: size[1] - 0.5,
  85859. height: moveHandleHeight
  85860. }
  85861. });
  85862. var iconSize = moveHandleHeight * 0.8;
  85863. var moveHandleIcon = displayables.moveHandleIcon = createSymbol(dataZoomModel.get('moveHandleIcon'), -iconSize / 2, -iconSize / 2, iconSize, iconSize, tokens.color.neutral00, true);
  85864. moveHandleIcon.silent = true;
  85865. moveHandleIcon.y = size[1] + moveHandleHeight / 2 - 0.5;
  85866. moveHandle_1.ensureState('emphasis').style = dataZoomModel.getModel(['emphasis', 'moveHandleStyle']).getItemStyle();
  85867. var moveZoneExpandSize = Math.min(size[1] / 2, Math.max(moveHandleHeight, 10));
  85868. actualMoveZone = displayables.moveZone = new Rect({
  85869. invisible: true,
  85870. shape: {
  85871. y: size[1] - moveZoneExpandSize,
  85872. height: moveHandleHeight + moveZoneExpandSize
  85873. }
  85874. });
  85875. actualMoveZone.on('mouseover', function () {
  85876. api.enterEmphasis(moveHandle_1);
  85877. }).on('mouseout', function () {
  85878. api.leaveEmphasis(moveHandle_1);
  85879. });
  85880. sliderGroup.add(moveHandle_1);
  85881. sliderGroup.add(moveHandleIcon);
  85882. sliderGroup.add(actualMoveZone);
  85883. }
  85884. actualMoveZone.attr({
  85885. draggable: true,
  85886. cursor: 'default',
  85887. drift: bind(this._onDragMove, this, 'all'),
  85888. ondragstart: bind(this._showDataInfo, this, true),
  85889. ondragend: bind(this._onDragEnd, this),
  85890. onmouseover: bind(this._showDataInfo, this, true),
  85891. onmouseout: bind(this._showDataInfo, this, false)
  85892. });
  85893. };
  85894. SliderZoomView.prototype._resetInterval = function () {
  85895. var range = this._range = this.dataZoomModel.getPercentRange();
  85896. var viewExtent = this._getViewExtent();
  85897. this._handleEnds = [linearMap(range[0], [0, 100], viewExtent, true), linearMap(range[1], [0, 100], viewExtent, true)];
  85898. };
  85899. SliderZoomView.prototype._updateInterval = function (handleIndex, delta) {
  85900. var dataZoomModel = this.dataZoomModel;
  85901. var handleEnds = this._handleEnds;
  85902. var viewExtend = this._getViewExtent();
  85903. var minMaxSpan = dataZoomModel.findRepresentativeAxisProxy().getMinMaxSpan();
  85904. var percentExtent = [0, 100];
  85905. sliderMove(delta, handleEnds, viewExtend, dataZoomModel.get('zoomLock') ? 'all' : handleIndex, minMaxSpan.minSpan != null ? linearMap(minMaxSpan.minSpan, percentExtent, viewExtend, true) : null, minMaxSpan.maxSpan != null ? linearMap(minMaxSpan.maxSpan, percentExtent, viewExtend, true) : null);
  85906. var lastRange = this._range;
  85907. var range = this._range = asc([linearMap(handleEnds[0], viewExtend, percentExtent, true), linearMap(handleEnds[1], viewExtend, percentExtent, true)]);
  85908. return !lastRange || lastRange[0] !== range[0] || lastRange[1] !== range[1];
  85909. };
  85910. SliderZoomView.prototype._updateView = function (nonRealtime) {
  85911. var displaybles = this._displayables;
  85912. var handleEnds = this._handleEnds;
  85913. var handleInterval = asc(handleEnds.slice());
  85914. var size = this._size;
  85915. each([0, 1], function (handleIndex) {
  85916. // Handles
  85917. var handle = displaybles.handles[handleIndex];
  85918. var handleHeight = this._handleHeight;
  85919. handle.attr({
  85920. scaleX: handleHeight / 2,
  85921. scaleY: handleHeight / 2,
  85922. // This is a trick, by adding an extra tiny offset to let the default handle's end point align to the drag window.
  85923. // NOTE: It may affect some custom shapes a bit. But we prefer to have better result by default.
  85924. x: handleEnds[handleIndex] + (handleIndex ? -1 : 1),
  85925. y: size[1] / 2 - handleHeight / 2
  85926. });
  85927. }, this);
  85928. // Filler
  85929. displaybles.filler.setShape({
  85930. x: handleInterval[0],
  85931. y: 0,
  85932. width: handleInterval[1] - handleInterval[0],
  85933. height: size[1]
  85934. });
  85935. var viewExtent = {
  85936. x: handleInterval[0],
  85937. width: handleInterval[1] - handleInterval[0]
  85938. };
  85939. // Move handle
  85940. if (displaybles.moveHandle) {
  85941. displaybles.moveHandle.setShape(viewExtent);
  85942. displaybles.moveZone.setShape(viewExtent);
  85943. // Force update path on the invisible object
  85944. displaybles.moveZone.getBoundingRect();
  85945. displaybles.moveHandleIcon && displaybles.moveHandleIcon.attr('x', viewExtent.x + viewExtent.width / 2);
  85946. }
  85947. // update clip path of shadow.
  85948. var dataShadowSegs = displaybles.dataShadowSegs;
  85949. var segIntervals = [0, handleInterval[0], handleInterval[1], size[0]];
  85950. for (var i = 0; i < dataShadowSegs.length; i++) {
  85951. var segGroup = dataShadowSegs[i];
  85952. var clipPath = segGroup.getClipPath();
  85953. if (!clipPath) {
  85954. clipPath = new Rect();
  85955. segGroup.setClipPath(clipPath);
  85956. }
  85957. clipPath.setShape({
  85958. x: segIntervals[i],
  85959. y: 0,
  85960. width: segIntervals[i + 1] - segIntervals[i],
  85961. height: size[1]
  85962. });
  85963. }
  85964. this._updateDataInfo(nonRealtime);
  85965. };
  85966. SliderZoomView.prototype._updateDataInfo = function (nonRealtime) {
  85967. var dataZoomModel = this.dataZoomModel;
  85968. var displaybles = this._displayables;
  85969. var handleLabels = displaybles.handleLabels;
  85970. var orient = this._orient;
  85971. var labelTexts = ['', ''];
  85972. // FIXME
  85973. // date型,支持formatter,autoformatter(ec2 date.getAutoFormatter)
  85974. if (dataZoomModel.get('showDetail')) {
  85975. var axisProxy = dataZoomModel.findRepresentativeAxisProxy();
  85976. if (axisProxy) {
  85977. var axis = axisProxy.getAxisModel().axis;
  85978. var range = this._range;
  85979. var dataInterval = nonRealtime
  85980. // See #4434, data and axis are not processed and reset yet in non-realtime mode.
  85981. ? axisProxy.calculateDataWindow({
  85982. start: range[0],
  85983. end: range[1]
  85984. }).valueWindow : axisProxy.getDataValueWindow();
  85985. labelTexts = [this._formatLabel(dataInterval[0], axis), this._formatLabel(dataInterval[1], axis)];
  85986. }
  85987. }
  85988. var orderedHandleEnds = asc(this._handleEnds.slice());
  85989. setLabel.call(this, 0);
  85990. setLabel.call(this, 1);
  85991. function setLabel(handleIndex) {
  85992. // Label
  85993. // Text should not transform by barGroup.
  85994. // Ignore handlers transform
  85995. var barTransform = getTransform(displaybles.handles[handleIndex].parent, this.group);
  85996. var direction = transformDirection(handleIndex === 0 ? 'right' : 'left', barTransform);
  85997. var offset = this._handleWidth / 2 + LABEL_GAP;
  85998. var textPoint = applyTransform$1([orderedHandleEnds[handleIndex] + (handleIndex === 0 ? -offset : offset), this._size[1] / 2], barTransform);
  85999. handleLabels[handleIndex].setStyle({
  86000. x: textPoint[0],
  86001. y: textPoint[1],
  86002. verticalAlign: orient === HORIZONTAL ? 'middle' : direction,
  86003. align: orient === HORIZONTAL ? direction : 'center',
  86004. text: labelTexts[handleIndex]
  86005. });
  86006. }
  86007. };
  86008. SliderZoomView.prototype._formatLabel = function (value, axis) {
  86009. var dataZoomModel = this.dataZoomModel;
  86010. var labelFormatter = dataZoomModel.get('labelFormatter');
  86011. var labelPrecision = dataZoomModel.get('labelPrecision');
  86012. if (labelPrecision == null || labelPrecision === 'auto') {
  86013. labelPrecision = axis.getPixelPrecision();
  86014. }
  86015. var valueStr = value == null || isNaN(value) ? ''
  86016. // FIXME Glue code
  86017. : axis.type === 'category' || axis.type === 'time' ? axis.scale.getLabel({
  86018. value: Math.round(value)
  86019. })
  86020. // param of toFixed should less then 20.
  86021. : value.toFixed(Math.min(labelPrecision, 20));
  86022. return isFunction(labelFormatter) ? labelFormatter(value, valueStr) : isString(labelFormatter) ? labelFormatter.replace('{value}', valueStr) : valueStr;
  86023. };
  86024. /**
  86025. * @param isEmphasis true: show, false: hide
  86026. */
  86027. SliderZoomView.prototype._showDataInfo = function (isEmphasis) {
  86028. var handleLabel = this.dataZoomModel.get('handleLabel') || {};
  86029. var normalShow = handleLabel.show || false;
  86030. var emphasisHandleLabel = this.dataZoomModel.getModel(['emphasis', 'handleLabel']);
  86031. var emphasisShow = emphasisHandleLabel.get('show') || false;
  86032. // Dragging is considered as emphasis, unless emphasisShow is false
  86033. var toShow = isEmphasis || this._dragging ? emphasisShow : normalShow;
  86034. var displayables = this._displayables;
  86035. var handleLabels = displayables.handleLabels;
  86036. handleLabels[0].attr('invisible', !toShow);
  86037. handleLabels[1].attr('invisible', !toShow);
  86038. // Highlight move handle
  86039. displayables.moveHandle && this.api[toShow ? 'enterEmphasis' : 'leaveEmphasis'](displayables.moveHandle, 1);
  86040. };
  86041. SliderZoomView.prototype._onDragMove = function (handleIndex, dx, dy, event) {
  86042. this._dragging = true;
  86043. // For mobile device, prevent screen slider on the button.
  86044. stop(event.event);
  86045. // Transform dx, dy to bar coordination.
  86046. var barTransform = this._displayables.sliderGroup.getLocalTransform();
  86047. var vertex = applyTransform$1([dx, dy], barTransform, true);
  86048. var changed = this._updateInterval(handleIndex, vertex[0]);
  86049. var realtime = this.dataZoomModel.get('realtime');
  86050. this._updateView(!realtime);
  86051. // Avoid dispatch dataZoom repeatly but range not changed,
  86052. // which cause bad visual effect when progressive enabled.
  86053. changed && realtime && this._dispatchZoomAction(true);
  86054. };
  86055. SliderZoomView.prototype._onDragEnd = function () {
  86056. this._dragging = false;
  86057. this._showDataInfo(false);
  86058. // While in realtime mode and stream mode, dispatch action when
  86059. // drag end will cause the whole view rerender, which is unnecessary.
  86060. var realtime = this.dataZoomModel.get('realtime');
  86061. !realtime && this._dispatchZoomAction(false);
  86062. };
  86063. SliderZoomView.prototype._onClickPanel = function (e) {
  86064. var size = this._size;
  86065. var localPoint = this._displayables.sliderGroup.transformCoordToLocal(e.offsetX, e.offsetY);
  86066. if (localPoint[0] < 0 || localPoint[0] > size[0] || localPoint[1] < 0 || localPoint[1] > size[1]) {
  86067. return;
  86068. }
  86069. var handleEnds = this._handleEnds;
  86070. var center = (handleEnds[0] + handleEnds[1]) / 2;
  86071. var changed = this._updateInterval('all', localPoint[0] - center);
  86072. this._updateView();
  86073. changed && this._dispatchZoomAction(false);
  86074. };
  86075. SliderZoomView.prototype._onBrushStart = function (e) {
  86076. var x = e.offsetX;
  86077. var y = e.offsetY;
  86078. this._brushStart = new Point(x, y);
  86079. this._brushing = true;
  86080. this._brushStartTime = +new Date();
  86081. // this._updateBrushRect(x, y);
  86082. };
  86083. SliderZoomView.prototype._onBrushEnd = function (e) {
  86084. if (!this._brushing) {
  86085. return;
  86086. }
  86087. var brushRect = this._displayables.brushRect;
  86088. this._brushing = false;
  86089. if (!brushRect) {
  86090. return;
  86091. }
  86092. brushRect.attr('ignore', true);
  86093. var brushShape = brushRect.shape;
  86094. var brushEndTime = +new Date();
  86095. // console.log(brushEndTime - this._brushStartTime);
  86096. if (brushEndTime - this._brushStartTime < 200 && Math.abs(brushShape.width) < 5) {
  86097. // Will treat it as a click
  86098. return;
  86099. }
  86100. var viewExtend = this._getViewExtent();
  86101. var percentExtent = [0, 100];
  86102. var handleEnds = this._handleEnds = [brushShape.x, brushShape.x + brushShape.width];
  86103. var minMaxSpan = this.dataZoomModel.findRepresentativeAxisProxy().getMinMaxSpan();
  86104. // Restrict range.
  86105. sliderMove(0, handleEnds, viewExtend, 0, minMaxSpan.minSpan != null ? linearMap(minMaxSpan.minSpan, percentExtent, viewExtend, true) : null, minMaxSpan.maxSpan != null ? linearMap(minMaxSpan.maxSpan, percentExtent, viewExtend, true) : null);
  86106. this._range = asc([linearMap(handleEnds[0], viewExtend, percentExtent, true), linearMap(handleEnds[1], viewExtend, percentExtent, true)]);
  86107. this._updateView();
  86108. this._dispatchZoomAction(false);
  86109. };
  86110. SliderZoomView.prototype._onBrush = function (e) {
  86111. if (this._brushing) {
  86112. // For mobile device, prevent screen slider on the button.
  86113. stop(e.event);
  86114. this._updateBrushRect(e.offsetX, e.offsetY);
  86115. }
  86116. };
  86117. SliderZoomView.prototype._updateBrushRect = function (mouseX, mouseY) {
  86118. var displayables = this._displayables;
  86119. var dataZoomModel = this.dataZoomModel;
  86120. var brushRect = displayables.brushRect;
  86121. if (!brushRect) {
  86122. brushRect = displayables.brushRect = new Rect$2({
  86123. silent: true,
  86124. style: dataZoomModel.getModel('brushStyle').getItemStyle()
  86125. });
  86126. displayables.sliderGroup.add(brushRect);
  86127. }
  86128. brushRect.attr('ignore', false);
  86129. var brushStart = this._brushStart;
  86130. var sliderGroup = this._displayables.sliderGroup;
  86131. var endPoint = sliderGroup.transformCoordToLocal(mouseX, mouseY);
  86132. var startPoint = sliderGroup.transformCoordToLocal(brushStart.x, brushStart.y);
  86133. var size = this._size;
  86134. endPoint[0] = Math.max(Math.min(size[0], endPoint[0]), 0);
  86135. brushRect.setShape({
  86136. x: startPoint[0],
  86137. y: 0,
  86138. width: endPoint[0] - startPoint[0],
  86139. height: size[1]
  86140. });
  86141. };
  86142. /**
  86143. * This action will be throttled.
  86144. */
  86145. SliderZoomView.prototype._dispatchZoomAction = function (realtime) {
  86146. var range = this._range;
  86147. this.api.dispatchAction({
  86148. type: 'dataZoom',
  86149. from: this.uid,
  86150. dataZoomId: this.dataZoomModel.id,
  86151. animation: realtime ? REALTIME_ANIMATION_CONFIG : null,
  86152. start: range[0],
  86153. end: range[1]
  86154. });
  86155. };
  86156. SliderZoomView.prototype._findCoordRect = function () {
  86157. // Find the grid corresponding to the first axis referred by dataZoom.
  86158. var rect;
  86159. var coordSysInfoList = collectReferCoordSysModelInfo(this.dataZoomModel).infoList;
  86160. if (!rect && coordSysInfoList.length) {
  86161. var coordSys = coordSysInfoList[0].model.coordinateSystem;
  86162. rect = coordSys.getRect && coordSys.getRect();
  86163. }
  86164. if (!rect) {
  86165. var width = this.api.getWidth();
  86166. var height = this.api.getHeight();
  86167. rect = {
  86168. x: width * 0.2,
  86169. y: height * 0.2,
  86170. width: width * 0.6,
  86171. height: height * 0.6
  86172. };
  86173. }
  86174. return rect;
  86175. };
  86176. SliderZoomView.type = 'dataZoom.slider';
  86177. return SliderZoomView;
  86178. }(DataZoomView);
  86179. function getOtherDim(thisDim) {
  86180. // FIXME
  86181. // 这个逻辑和getOtherAxis里一致,但是写在这里是否不好
  86182. var map = {
  86183. x: 'y',
  86184. y: 'x',
  86185. radius: 'angle',
  86186. angle: 'radius'
  86187. };
  86188. return map[thisDim];
  86189. }
  86190. function getCursor(orient) {
  86191. return orient === 'vertical' ? 'ns-resize' : 'ew-resize';
  86192. }
  86193. function install$N(registers) {
  86194. registers.registerComponentModel(SliderZoomModel);
  86195. registers.registerComponentView(SliderZoomView);
  86196. installCommon(registers);
  86197. }
  86198. function install$O(registers) {
  86199. use(install$M);
  86200. use(install$N);
  86201. // Do not install './dataZoomSelect',
  86202. // since it only work for toolbox dataZoom.
  86203. }
  86204. var visualDefault = {
  86205. /**
  86206. * @public
  86207. */
  86208. get: function (visualType, key, isCategory) {
  86209. var value = clone((defaultOption$1[visualType] || {})[key]);
  86210. return isCategory ? isArray(value) ? value[value.length - 1] : value : value;
  86211. }
  86212. };
  86213. var defaultOption$1 = {
  86214. color: {
  86215. active: ['#006edd', '#e0ffff'],
  86216. inactive: [tokens.color.transparent]
  86217. },
  86218. colorHue: {
  86219. active: [0, 360],
  86220. inactive: [0, 0]
  86221. },
  86222. colorSaturation: {
  86223. active: [0.3, 1],
  86224. inactive: [0, 0]
  86225. },
  86226. colorLightness: {
  86227. active: [0.9, 0.5],
  86228. inactive: [0, 0]
  86229. },
  86230. colorAlpha: {
  86231. active: [0.3, 1],
  86232. inactive: [0, 0]
  86233. },
  86234. opacity: {
  86235. active: [0.3, 1],
  86236. inactive: [0, 0]
  86237. },
  86238. symbol: {
  86239. active: ['circle', 'roundRect', 'diamond'],
  86240. inactive: ['none']
  86241. },
  86242. symbolSize: {
  86243. active: [10, 50],
  86244. inactive: [0, 0]
  86245. }
  86246. };
  86247. var mapVisual$1 = VisualMapping.mapVisual;
  86248. var eachVisual = VisualMapping.eachVisual;
  86249. var isArray$1 = isArray;
  86250. var each$d = each;
  86251. var asc$2 = asc;
  86252. var linearMap$1 = linearMap;
  86253. var VisualMapModel = /** @class */function (_super) {
  86254. __extends(VisualMapModel, _super);
  86255. function VisualMapModel() {
  86256. var _this = _super !== null && _super.apply(this, arguments) || this;
  86257. _this.type = VisualMapModel.type;
  86258. _this.stateList = ['inRange', 'outOfRange'];
  86259. _this.replacableOptionKeys = ['inRange', 'outOfRange', 'target', 'controller', 'color'];
  86260. _this.layoutMode = {
  86261. type: 'box',
  86262. ignoreSize: true
  86263. };
  86264. /**
  86265. * [lowerBound, upperBound]
  86266. */
  86267. _this.dataBound = [-Infinity, Infinity];
  86268. _this.targetVisuals = {};
  86269. _this.controllerVisuals = {};
  86270. return _this;
  86271. }
  86272. VisualMapModel.prototype.init = function (option, parentModel, ecModel) {
  86273. this.mergeDefaultAndTheme(option, ecModel);
  86274. };
  86275. /**
  86276. * @protected
  86277. */
  86278. VisualMapModel.prototype.optionUpdated = function (newOption, isInit) {
  86279. var thisOption = this.option;
  86280. !isInit && replaceVisualOption(thisOption, newOption, this.replacableOptionKeys);
  86281. this.textStyleModel = this.getModel('textStyle');
  86282. this.resetItemSize();
  86283. this.completeVisualOption();
  86284. };
  86285. /**
  86286. * @protected
  86287. */
  86288. VisualMapModel.prototype.resetVisual = function (supplementVisualOption) {
  86289. var stateList = this.stateList;
  86290. supplementVisualOption = bind(supplementVisualOption, this);
  86291. this.controllerVisuals = createVisualMappings(this.option.controller, stateList, supplementVisualOption);
  86292. this.targetVisuals = createVisualMappings(this.option.target, stateList, supplementVisualOption);
  86293. };
  86294. /**
  86295. * @public
  86296. */
  86297. VisualMapModel.prototype.getItemSymbol = function () {
  86298. return null;
  86299. };
  86300. /**
  86301. * @return An array of series indices.
  86302. */
  86303. VisualMapModel.prototype.getTargetSeriesIndices = function () {
  86304. var optionSeriesId = this.option.seriesId;
  86305. var optionSeriesIndex = this.option.seriesIndex;
  86306. if (optionSeriesIndex == null && optionSeriesId == null) {
  86307. optionSeriesIndex = 'all';
  86308. }
  86309. var seriesModels = queryReferringComponents(this.ecModel, 'series', {
  86310. index: optionSeriesIndex,
  86311. id: optionSeriesId
  86312. }, {
  86313. useDefault: false,
  86314. enableAll: true,
  86315. enableNone: false
  86316. }).models;
  86317. return map(seriesModels, function (seriesModel) {
  86318. return seriesModel.componentIndex;
  86319. });
  86320. };
  86321. /**
  86322. * @public
  86323. */
  86324. VisualMapModel.prototype.eachTargetSeries = function (callback, context) {
  86325. each(this.getTargetSeriesIndices(), function (seriesIndex) {
  86326. var seriesModel = this.ecModel.getSeriesByIndex(seriesIndex);
  86327. if (seriesModel) {
  86328. callback.call(context, seriesModel);
  86329. }
  86330. }, this);
  86331. };
  86332. /**
  86333. * @pubilc
  86334. */
  86335. VisualMapModel.prototype.isTargetSeries = function (seriesModel) {
  86336. var is = false;
  86337. this.eachTargetSeries(function (model) {
  86338. model === seriesModel && (is = true);
  86339. });
  86340. return is;
  86341. };
  86342. /**
  86343. * @example
  86344. * this.formatValueText(someVal); // format single numeric value to text.
  86345. * this.formatValueText(someVal, true); // format single category value to text.
  86346. * this.formatValueText([min, max]); // format numeric min-max to text.
  86347. * this.formatValueText([this.dataBound[0], max]); // using data lower bound.
  86348. * this.formatValueText([min, this.dataBound[1]]); // using data upper bound.
  86349. *
  86350. * @param value Real value, or this.dataBound[0 or 1].
  86351. * @param isCategory Only available when value is number.
  86352. * @param edgeSymbols Open-close symbol when value is interval.
  86353. * @protected
  86354. */
  86355. VisualMapModel.prototype.formatValueText = function (value, isCategory, edgeSymbols) {
  86356. var option = this.option;
  86357. var precision = option.precision;
  86358. var dataBound = this.dataBound;
  86359. var formatter = option.formatter;
  86360. var isMinMax;
  86361. edgeSymbols = edgeSymbols || ['<', '>'];
  86362. if (isArray(value)) {
  86363. value = value.slice();
  86364. isMinMax = true;
  86365. }
  86366. var textValue = isCategory ? value // Value is string when isCategory
  86367. : isMinMax ? [toFixed(value[0]), toFixed(value[1])] : toFixed(value);
  86368. if (isString(formatter)) {
  86369. return formatter.replace('{value}', isMinMax ? textValue[0] : textValue).replace('{value2}', isMinMax ? textValue[1] : textValue);
  86370. } else if (isFunction(formatter)) {
  86371. return isMinMax ? formatter(value[0], value[1]) : formatter(value);
  86372. }
  86373. if (isMinMax) {
  86374. if (value[0] === dataBound[0]) {
  86375. return edgeSymbols[0] + ' ' + textValue[1];
  86376. } else if (value[1] === dataBound[1]) {
  86377. return edgeSymbols[1] + ' ' + textValue[0];
  86378. } else {
  86379. return textValue[0] + ' - ' + textValue[1];
  86380. }
  86381. } else {
  86382. // Format single value (includes category case).
  86383. return textValue;
  86384. }
  86385. function toFixed(val) {
  86386. return val === dataBound[0] ? 'min' : val === dataBound[1] ? 'max' : (+val).toFixed(Math.min(precision, 20));
  86387. }
  86388. };
  86389. /**
  86390. * @protected
  86391. */
  86392. VisualMapModel.prototype.resetExtent = function () {
  86393. var thisOption = this.option;
  86394. // Can not calculate data extent by data here.
  86395. // Because series and data may be modified in processing stage.
  86396. // So we do not support the feature "auto min/max".
  86397. var extent = asc$2([thisOption.min, thisOption.max]);
  86398. this._dataExtent = extent;
  86399. };
  86400. /**
  86401. * PENDING:
  86402. * delete this method if no outer usage.
  86403. *
  86404. * Return Concrete dimension. If null/undefined is returned, no dimension is used.
  86405. */
  86406. // getDataDimension(data: SeriesData) {
  86407. // const optDim = this.option.dimension;
  86408. // if (optDim != null) {
  86409. // return data.getDimension(optDim);
  86410. // }
  86411. // const dimNames = data.dimensions;
  86412. // for (let i = dimNames.length - 1; i >= 0; i--) {
  86413. // const dimName = dimNames[i];
  86414. // const dimInfo = data.getDimensionInfo(dimName);
  86415. // if (!dimInfo.isCalculationCoord) {
  86416. // return dimName;
  86417. // }
  86418. // }
  86419. // }
  86420. VisualMapModel.prototype.getDataDimensionIndex = function (data) {
  86421. var optDim = this.option.dimension;
  86422. if (optDim != null) {
  86423. return data.getDimensionIndex(optDim);
  86424. }
  86425. var dimNames = data.dimensions;
  86426. for (var i = dimNames.length - 1; i >= 0; i--) {
  86427. var dimName = dimNames[i];
  86428. var dimInfo = data.getDimensionInfo(dimName);
  86429. if (!dimInfo.isCalculationCoord) {
  86430. return dimInfo.storeDimIndex;
  86431. }
  86432. }
  86433. };
  86434. VisualMapModel.prototype.getExtent = function () {
  86435. return this._dataExtent.slice();
  86436. };
  86437. VisualMapModel.prototype.completeVisualOption = function () {
  86438. var ecModel = this.ecModel;
  86439. var thisOption = this.option;
  86440. var base = {
  86441. inRange: thisOption.inRange,
  86442. outOfRange: thisOption.outOfRange
  86443. };
  86444. var target = thisOption.target || (thisOption.target = {});
  86445. var controller = thisOption.controller || (thisOption.controller = {});
  86446. merge(target, base); // Do not override
  86447. merge(controller, base); // Do not override
  86448. var isCategory = this.isCategory();
  86449. completeSingle.call(this, target);
  86450. completeSingle.call(this, controller);
  86451. completeInactive.call(this, target, 'inRange', 'outOfRange');
  86452. // completeInactive.call(this, target, 'outOfRange', 'inRange');
  86453. completeController.call(this, controller);
  86454. function completeSingle(base) {
  86455. // Compatible with ec2 dataRange.color.
  86456. // The mapping order of dataRange.color is: [high value, ..., low value]
  86457. // whereas inRange.color and outOfRange.color is [low value, ..., high value]
  86458. // Notice: ec2 has no inverse.
  86459. if (isArray$1(thisOption.color)
  86460. // If there has been inRange: {symbol: ...}, adding color is a mistake.
  86461. // So adding color only when no inRange defined.
  86462. && !base.inRange) {
  86463. base.inRange = {
  86464. color: thisOption.color.slice().reverse()
  86465. };
  86466. }
  86467. // Compatible with previous logic, always give a default color, otherwise
  86468. // simple config with no inRange and outOfRange will not work.
  86469. // Originally we use visualMap.color as the default color, but setOption at
  86470. // the second time the default color will be erased. So we change to use
  86471. // constant DEFAULT_COLOR.
  86472. // If user do not want the default color, set inRange: {color: null}.
  86473. base.inRange = base.inRange || {
  86474. color: ecModel.get('gradientColor')
  86475. };
  86476. }
  86477. function completeInactive(base, stateExist, stateAbsent) {
  86478. var optExist = base[stateExist];
  86479. var optAbsent = base[stateAbsent];
  86480. if (optExist && !optAbsent) {
  86481. optAbsent = base[stateAbsent] = {};
  86482. each$d(optExist, function (visualData, visualType) {
  86483. if (!VisualMapping.isValidType(visualType)) {
  86484. return;
  86485. }
  86486. var defa = visualDefault.get(visualType, 'inactive', isCategory);
  86487. if (defa != null) {
  86488. optAbsent[visualType] = defa;
  86489. // Compatibable with ec2:
  86490. // Only inactive color to rgba(0,0,0,0) can not
  86491. // make label transparent, so use opacity also.
  86492. if (visualType === 'color' && !optAbsent.hasOwnProperty('opacity') && !optAbsent.hasOwnProperty('colorAlpha')) {
  86493. optAbsent.opacity = [0, 0];
  86494. }
  86495. }
  86496. });
  86497. }
  86498. }
  86499. function completeController(controller) {
  86500. var symbolExists = (controller.inRange || {}).symbol || (controller.outOfRange || {}).symbol;
  86501. var symbolSizeExists = (controller.inRange || {}).symbolSize || (controller.outOfRange || {}).symbolSize;
  86502. var inactiveColor = this.get('inactiveColor');
  86503. var itemSymbol = this.getItemSymbol();
  86504. var defaultSymbol = itemSymbol || 'roundRect';
  86505. each$d(this.stateList, function (state) {
  86506. var itemSize = this.itemSize;
  86507. var visuals = controller[state];
  86508. // Set inactive color for controller if no other color
  86509. // attr (like colorAlpha) specified.
  86510. if (!visuals) {
  86511. visuals = controller[state] = {
  86512. color: isCategory ? inactiveColor : [inactiveColor]
  86513. };
  86514. }
  86515. // Consistent symbol and symbolSize if not specified.
  86516. if (visuals.symbol == null) {
  86517. visuals.symbol = symbolExists && clone(symbolExists) || (isCategory ? defaultSymbol : [defaultSymbol]);
  86518. }
  86519. if (visuals.symbolSize == null) {
  86520. visuals.symbolSize = symbolSizeExists && clone(symbolSizeExists) || (isCategory ? itemSize[0] : [itemSize[0], itemSize[0]]);
  86521. }
  86522. // Filter none
  86523. visuals.symbol = mapVisual$1(visuals.symbol, function (symbol) {
  86524. return symbol === 'none' ? defaultSymbol : symbol;
  86525. });
  86526. // Normalize symbolSize
  86527. var symbolSize = visuals.symbolSize;
  86528. if (symbolSize != null) {
  86529. var max_1 = -Infinity;
  86530. // symbolSize can be object when categories defined.
  86531. eachVisual(symbolSize, function (value) {
  86532. value > max_1 && (max_1 = value);
  86533. });
  86534. visuals.symbolSize = mapVisual$1(symbolSize, function (value) {
  86535. return linearMap$1(value, [0, max_1], [0, itemSize[0]], true);
  86536. });
  86537. }
  86538. }, this);
  86539. }
  86540. };
  86541. VisualMapModel.prototype.resetItemSize = function () {
  86542. this.itemSize = [parseFloat(this.get('itemWidth')), parseFloat(this.get('itemHeight'))];
  86543. };
  86544. VisualMapModel.prototype.isCategory = function () {
  86545. return !!this.option.categories;
  86546. };
  86547. /**
  86548. * @public
  86549. * @abstract
  86550. */
  86551. VisualMapModel.prototype.setSelected = function (selected) {};
  86552. VisualMapModel.prototype.getSelected = function () {
  86553. return null;
  86554. };
  86555. /**
  86556. * @public
  86557. * @abstract
  86558. */
  86559. VisualMapModel.prototype.getValueState = function (value) {
  86560. return null;
  86561. };
  86562. /**
  86563. * FIXME
  86564. * Do not publish to thirt-part-dev temporarily
  86565. * util the interface is stable. (Should it return
  86566. * a function but not visual meta?)
  86567. *
  86568. * @pubilc
  86569. * @abstract
  86570. * @param getColorVisual
  86571. * params: value, valueState
  86572. * return: color
  86573. * @return {Object} visualMeta
  86574. * should includes {stops, outerColors}
  86575. * outerColor means [colorBeyondMinValue, colorBeyondMaxValue]
  86576. */
  86577. VisualMapModel.prototype.getVisualMeta = function (getColorVisual) {
  86578. return null;
  86579. };
  86580. VisualMapModel.type = 'visualMap';
  86581. VisualMapModel.dependencies = ['series'];
  86582. VisualMapModel.defaultOption = {
  86583. show: true,
  86584. // zlevel: 0,
  86585. z: 4,
  86586. // seriesIndex: 'all',
  86587. min: 0,
  86588. max: 200,
  86589. left: 0,
  86590. right: null,
  86591. top: null,
  86592. bottom: 0,
  86593. itemWidth: null,
  86594. itemHeight: null,
  86595. inverse: false,
  86596. orient: 'vertical',
  86597. backgroundColor: tokens.color.transparent,
  86598. borderColor: tokens.color.borderTint,
  86599. contentColor: tokens.color.theme[0],
  86600. inactiveColor: tokens.color.disabled,
  86601. borderWidth: 0,
  86602. padding: tokens.size.m,
  86603. // 接受数组分别设定上右下左边距,同css
  86604. textGap: 10,
  86605. precision: 0,
  86606. textStyle: {
  86607. color: tokens.color.secondary // 值域文字颜色
  86608. }
  86609. };
  86610. return VisualMapModel;
  86611. }(ComponentModel);
  86612. // Constant
  86613. var DEFAULT_BAR_BOUND = [20, 140];
  86614. var ContinuousModel = /** @class */function (_super) {
  86615. __extends(ContinuousModel, _super);
  86616. function ContinuousModel() {
  86617. var _this = _super !== null && _super.apply(this, arguments) || this;
  86618. _this.type = ContinuousModel.type;
  86619. return _this;
  86620. }
  86621. /**
  86622. * @override
  86623. */
  86624. ContinuousModel.prototype.optionUpdated = function (newOption, isInit) {
  86625. _super.prototype.optionUpdated.apply(this, arguments);
  86626. this.resetExtent();
  86627. this.resetVisual(function (mappingOption) {
  86628. mappingOption.mappingMethod = 'linear';
  86629. mappingOption.dataExtent = this.getExtent();
  86630. });
  86631. this._resetRange();
  86632. };
  86633. /**
  86634. * @protected
  86635. * @override
  86636. */
  86637. ContinuousModel.prototype.resetItemSize = function () {
  86638. _super.prototype.resetItemSize.apply(this, arguments);
  86639. var itemSize = this.itemSize;
  86640. (itemSize[0] == null || isNaN(itemSize[0])) && (itemSize[0] = DEFAULT_BAR_BOUND[0]);
  86641. (itemSize[1] == null || isNaN(itemSize[1])) && (itemSize[1] = DEFAULT_BAR_BOUND[1]);
  86642. };
  86643. /**
  86644. * @private
  86645. */
  86646. ContinuousModel.prototype._resetRange = function () {
  86647. var dataExtent = this.getExtent();
  86648. var range = this.option.range;
  86649. if (!range || range.auto) {
  86650. // `range` should always be array (so we don't use other
  86651. // value like 'auto') for user-friend. (consider getOption).
  86652. dataExtent.auto = 1;
  86653. this.option.range = dataExtent;
  86654. } else if (isArray(range)) {
  86655. if (range[0] > range[1]) {
  86656. range.reverse();
  86657. }
  86658. range[0] = Math.max(range[0], dataExtent[0]);
  86659. range[1] = Math.min(range[1], dataExtent[1]);
  86660. }
  86661. };
  86662. /**
  86663. * @protected
  86664. * @override
  86665. */
  86666. ContinuousModel.prototype.completeVisualOption = function () {
  86667. _super.prototype.completeVisualOption.apply(this, arguments);
  86668. each(this.stateList, function (state) {
  86669. var symbolSize = this.option.controller[state].symbolSize;
  86670. if (symbolSize && symbolSize[0] !== symbolSize[1]) {
  86671. symbolSize[0] = symbolSize[1] / 3; // For good looking.
  86672. }
  86673. }, this);
  86674. };
  86675. /**
  86676. * @override
  86677. */
  86678. ContinuousModel.prototype.setSelected = function (selected) {
  86679. this.option.range = selected.slice();
  86680. this._resetRange();
  86681. };
  86682. /**
  86683. * @public
  86684. */
  86685. ContinuousModel.prototype.getSelected = function () {
  86686. var dataExtent = this.getExtent();
  86687. var dataInterval = asc((this.get('range') || []).slice());
  86688. // Clamp
  86689. dataInterval[0] > dataExtent[1] && (dataInterval[0] = dataExtent[1]);
  86690. dataInterval[1] > dataExtent[1] && (dataInterval[1] = dataExtent[1]);
  86691. dataInterval[0] < dataExtent[0] && (dataInterval[0] = dataExtent[0]);
  86692. dataInterval[1] < dataExtent[0] && (dataInterval[1] = dataExtent[0]);
  86693. return dataInterval;
  86694. };
  86695. /**
  86696. * @override
  86697. */
  86698. ContinuousModel.prototype.getValueState = function (value) {
  86699. var range = this.option.range;
  86700. var dataExtent = this.getExtent();
  86701. var unboundedRange = retrieve2(this.option.unboundedRange, true);
  86702. return (unboundedRange && range[0] <= dataExtent[0] || range[0] <= value) && (unboundedRange && range[1] >= dataExtent[1] || value <= range[1]) ? 'inRange' : 'outOfRange';
  86703. };
  86704. ContinuousModel.prototype.findTargetDataIndices = function (range) {
  86705. var result = [];
  86706. this.eachTargetSeries(function (seriesModel) {
  86707. var dataIndices = [];
  86708. var data = seriesModel.getData();
  86709. data.each(this.getDataDimensionIndex(data), function (value, dataIndex) {
  86710. range[0] <= value && value <= range[1] && dataIndices.push(dataIndex);
  86711. }, this);
  86712. result.push({
  86713. seriesId: seriesModel.id,
  86714. dataIndex: dataIndices
  86715. });
  86716. }, this);
  86717. return result;
  86718. };
  86719. /**
  86720. * @implement
  86721. */
  86722. ContinuousModel.prototype.getVisualMeta = function (getColorVisual) {
  86723. var oVals = getColorStopValues(this, 'outOfRange', this.getExtent());
  86724. var iVals = getColorStopValues(this, 'inRange', this.option.range.slice());
  86725. var stops = [];
  86726. function setStop(value, valueState) {
  86727. stops.push({
  86728. value: value,
  86729. color: getColorVisual(value, valueState)
  86730. });
  86731. }
  86732. // Format to: outOfRange -- inRange -- outOfRange.
  86733. var iIdx = 0;
  86734. var oIdx = 0;
  86735. var iLen = iVals.length;
  86736. var oLen = oVals.length;
  86737. for (; oIdx < oLen && (!iVals.length || oVals[oIdx] <= iVals[0]); oIdx++) {
  86738. // If oVal[oIdx] === iVals[iIdx], oVal[oIdx] should be ignored.
  86739. if (oVals[oIdx] < iVals[iIdx]) {
  86740. setStop(oVals[oIdx], 'outOfRange');
  86741. }
  86742. }
  86743. for (var first = 1; iIdx < iLen; iIdx++, first = 0) {
  86744. // If range is full, value beyond min, max will be clamped.
  86745. // make a singularity
  86746. first && stops.length && setStop(iVals[iIdx], 'outOfRange');
  86747. setStop(iVals[iIdx], 'inRange');
  86748. }
  86749. for (var first = 1; oIdx < oLen; oIdx++) {
  86750. if (!iVals.length || iVals[iVals.length - 1] < oVals[oIdx]) {
  86751. // make a singularity
  86752. if (first) {
  86753. stops.length && setStop(stops[stops.length - 1].value, 'outOfRange');
  86754. first = 0;
  86755. }
  86756. setStop(oVals[oIdx], 'outOfRange');
  86757. }
  86758. }
  86759. var stopsLen = stops.length;
  86760. return {
  86761. stops: stops,
  86762. outerColors: [stopsLen ? stops[0].color : 'transparent', stopsLen ? stops[stopsLen - 1].color : 'transparent']
  86763. };
  86764. };
  86765. ContinuousModel.type = 'visualMap.continuous';
  86766. ContinuousModel.defaultOption = inheritDefaultOption(VisualMapModel.defaultOption, {
  86767. align: 'auto',
  86768. calculable: false,
  86769. hoverLink: true,
  86770. realtime: true,
  86771. handleIcon: 'path://M-11.39,9.77h0a3.5,3.5,0,0,1-3.5,3.5h-22a3.5,3.5,0,0,1-3.5-3.5h0a3.5,3.5,0,0,1,3.5-3.5h22A3.5,3.5,0,0,1-11.39,9.77Z',
  86772. handleSize: '120%',
  86773. handleStyle: {
  86774. borderColor: tokens.color.neutral00,
  86775. borderWidth: 1
  86776. },
  86777. indicatorIcon: 'circle',
  86778. indicatorSize: '50%',
  86779. indicatorStyle: {
  86780. borderColor: tokens.color.neutral00,
  86781. borderWidth: 2,
  86782. shadowBlur: 2,
  86783. shadowOffsetX: 1,
  86784. shadowOffsetY: 1,
  86785. shadowColor: tokens.color.shadow
  86786. }
  86787. // emphasis: {
  86788. // handleStyle: {
  86789. // shadowBlur: 3,
  86790. // shadowOffsetX: 1,
  86791. // shadowOffsetY: 1,
  86792. // shadowColor: tokens.color.shadow
  86793. // }
  86794. // }
  86795. });
  86796. return ContinuousModel;
  86797. }(VisualMapModel);
  86798. function getColorStopValues(visualMapModel, valueState, dataExtent) {
  86799. if (dataExtent[0] === dataExtent[1]) {
  86800. return dataExtent.slice();
  86801. }
  86802. // When using colorHue mapping, it is not linear color any more.
  86803. // Moreover, canvas gradient seems not to be accurate linear.
  86804. // FIXME
  86805. // Should be arbitrary value 100? or based on pixel size?
  86806. var count = 200;
  86807. var step = (dataExtent[1] - dataExtent[0]) / count;
  86808. var value = dataExtent[0];
  86809. var stopValues = [];
  86810. for (var i = 0; i <= count && value < dataExtent[1]; i++) {
  86811. stopValues.push(value);
  86812. value += step;
  86813. }
  86814. stopValues.push(dataExtent[1]);
  86815. return stopValues;
  86816. }
  86817. var VisualMapView = /** @class */function (_super) {
  86818. __extends(VisualMapView, _super);
  86819. function VisualMapView() {
  86820. var _this = _super !== null && _super.apply(this, arguments) || this;
  86821. _this.type = VisualMapView.type;
  86822. _this.autoPositionValues = {
  86823. left: 1,
  86824. right: 1,
  86825. top: 1,
  86826. bottom: 1
  86827. };
  86828. return _this;
  86829. }
  86830. VisualMapView.prototype.init = function (ecModel, api) {
  86831. this.ecModel = ecModel;
  86832. this.api = api;
  86833. };
  86834. /**
  86835. * @protected
  86836. */
  86837. VisualMapView.prototype.render = function (visualMapModel, ecModel, api, payload // TODO: TYPE
  86838. ) {
  86839. this.visualMapModel = visualMapModel;
  86840. if (visualMapModel.get('show') === false) {
  86841. this.group.removeAll();
  86842. return;
  86843. }
  86844. this.doRender(visualMapModel, ecModel, api, payload);
  86845. };
  86846. /**
  86847. * @protected
  86848. */
  86849. VisualMapView.prototype.renderBackground = function (group) {
  86850. var visualMapModel = this.visualMapModel;
  86851. var padding = normalizeCssArray$1(visualMapModel.get('padding') || 0);
  86852. var rect = group.getBoundingRect();
  86853. group.add(new Rect({
  86854. z2: -1,
  86855. silent: true,
  86856. shape: {
  86857. x: rect.x - padding[3],
  86858. y: rect.y - padding[0],
  86859. width: rect.width + padding[3] + padding[1],
  86860. height: rect.height + padding[0] + padding[2]
  86861. },
  86862. style: {
  86863. fill: visualMapModel.get('backgroundColor'),
  86864. stroke: visualMapModel.get('borderColor'),
  86865. lineWidth: visualMapModel.get('borderWidth')
  86866. }
  86867. }));
  86868. };
  86869. /**
  86870. * @protected
  86871. * @param targetValue can be Infinity or -Infinity
  86872. * @param visualCluster Only can be 'color' 'opacity' 'symbol' 'symbolSize'
  86873. * @param opts
  86874. * @param opts.forceState Specify state, instead of using getValueState method.
  86875. * @param opts.convertOpacityToAlpha For color gradient in controller widget.
  86876. * @return {*} Visual value.
  86877. */
  86878. VisualMapView.prototype.getControllerVisual = function (targetValue, visualCluster, opts) {
  86879. opts = opts || {};
  86880. var forceState = opts.forceState;
  86881. var visualMapModel = this.visualMapModel;
  86882. var visualObj = {};
  86883. // Default values.
  86884. if (visualCluster === 'color') {
  86885. var defaultColor = visualMapModel.get('contentColor');
  86886. visualObj.color = defaultColor;
  86887. }
  86888. function getter(key) {
  86889. return visualObj[key];
  86890. }
  86891. function setter(key, value) {
  86892. visualObj[key] = value;
  86893. }
  86894. var mappings = visualMapModel.controllerVisuals[forceState || visualMapModel.getValueState(targetValue)];
  86895. var visualTypes = VisualMapping.prepareVisualTypes(mappings);
  86896. each(visualTypes, function (type) {
  86897. var visualMapping = mappings[type];
  86898. if (opts.convertOpacityToAlpha && type === 'opacity') {
  86899. type = 'colorAlpha';
  86900. visualMapping = mappings.__alphaForOpacity;
  86901. }
  86902. if (VisualMapping.dependsOn(type, visualCluster)) {
  86903. visualMapping && visualMapping.applyVisual(targetValue, getter, setter);
  86904. }
  86905. });
  86906. return visualObj[visualCluster];
  86907. };
  86908. VisualMapView.prototype.positionGroup = function (group) {
  86909. var model = this.visualMapModel;
  86910. var api = this.api;
  86911. var refContainer = createBoxLayoutReference(model, api).refContainer;
  86912. positionElement(group, model.getBoxLayoutParams(), refContainer);
  86913. };
  86914. VisualMapView.prototype.doRender = function (visualMapModel, ecModel, api, payload) {};
  86915. VisualMapView.type = 'visualMap';
  86916. return VisualMapView;
  86917. }(ComponentView);
  86918. var paramsSet = [['left', 'right', 'width'], ['top', 'bottom', 'height']];
  86919. /**
  86920. * @param visualMapModel
  86921. * @param api
  86922. * @param itemSize always [short, long]
  86923. * @return {string} 'left' or 'right' or 'top' or 'bottom'
  86924. */
  86925. function getItemAlign(visualMapModel, api, itemSize) {
  86926. var modelOption = visualMapModel.option;
  86927. var itemAlign = modelOption.align;
  86928. if (itemAlign != null && itemAlign !== 'auto') {
  86929. return itemAlign;
  86930. }
  86931. // Auto decision align.
  86932. var ecSize = {
  86933. width: api.getWidth(),
  86934. height: api.getHeight()
  86935. };
  86936. var realIndex = modelOption.orient === 'horizontal' ? 1 : 0;
  86937. var reals = paramsSet[realIndex];
  86938. var fakeValue = [0, null, 10];
  86939. var layoutInput = {};
  86940. for (var i = 0; i < 3; i++) {
  86941. layoutInput[paramsSet[1 - realIndex][i]] = fakeValue[i];
  86942. layoutInput[reals[i]] = i === 2 ? itemSize[0] : modelOption[reals[i]];
  86943. }
  86944. var rParam = [['x', 'width', 3], ['y', 'height', 0]][realIndex];
  86945. var rect = getLayoutRect(layoutInput, ecSize, modelOption.padding);
  86946. return reals[(rect.margin[rParam[2]] || 0) + rect[rParam[0]] + rect[rParam[1]] * 0.5 < ecSize[rParam[1]] * 0.5 ? 0 : 1];
  86947. }
  86948. /**
  86949. * Prepare dataIndex for outside usage, where dataIndex means rawIndex, and
  86950. * dataIndexInside means filtered index.
  86951. */
  86952. // TODO: TYPE more specified payload types.
  86953. function makeHighDownBatch(batch, visualMapModel) {
  86954. each(batch || [], function (batchItem) {
  86955. if (batchItem.dataIndex != null) {
  86956. batchItem.dataIndexInside = batchItem.dataIndex;
  86957. batchItem.dataIndex = null;
  86958. }
  86959. batchItem.highlightKey = 'visualMap' + (visualMapModel ? visualMapModel.componentIndex : '');
  86960. });
  86961. return batch;
  86962. }
  86963. var linearMap$2 = linearMap;
  86964. var each$e = each;
  86965. var mathMin$b = Math.min;
  86966. var mathMax$b = Math.max;
  86967. // Arbitrary value
  86968. var HOVER_LINK_SIZE = 12;
  86969. var HOVER_LINK_OUT = 6;
  86970. // Notice:
  86971. // Any "interval" should be by the order of [low, high].
  86972. // "handle0" (handleIndex === 0) maps to
  86973. // low data value: this._dataInterval[0] and has low coord.
  86974. // "handle1" (handleIndex === 1) maps to
  86975. // high data value: this._dataInterval[1] and has high coord.
  86976. // The logic of transform is implemented in this._createBarGroup.
  86977. var ContinuousView = /** @class */function (_super) {
  86978. __extends(ContinuousView, _super);
  86979. function ContinuousView() {
  86980. var _this = _super !== null && _super.apply(this, arguments) || this;
  86981. _this.type = ContinuousView.type;
  86982. _this._shapes = {};
  86983. _this._dataInterval = [];
  86984. _this._handleEnds = [];
  86985. _this._hoverLinkDataIndices = [];
  86986. return _this;
  86987. }
  86988. ContinuousView.prototype.init = function (ecModel, api) {
  86989. _super.prototype.init.call(this, ecModel, api);
  86990. this._hoverLinkFromSeriesMouseOver = bind(this._hoverLinkFromSeriesMouseOver, this);
  86991. this._hideIndicator = bind(this._hideIndicator, this);
  86992. };
  86993. ContinuousView.prototype.doRender = function (visualMapModel, ecModel, api, payload) {
  86994. if (!payload || payload.type !== 'selectDataRange' || payload.from !== this.uid) {
  86995. this._buildView();
  86996. }
  86997. };
  86998. ContinuousView.prototype._buildView = function () {
  86999. this.group.removeAll();
  87000. var visualMapModel = this.visualMapModel;
  87001. var thisGroup = this.group;
  87002. this._orient = visualMapModel.get('orient');
  87003. this._useHandle = visualMapModel.get('calculable');
  87004. this._resetInterval();
  87005. this._renderBar(thisGroup);
  87006. var dataRangeText = visualMapModel.get('text');
  87007. this._renderEndsText(thisGroup, dataRangeText, 0);
  87008. this._renderEndsText(thisGroup, dataRangeText, 1);
  87009. // Do this for background size calculation.
  87010. this._updateView(true);
  87011. // After updating view, inner shapes is built completely,
  87012. // and then background can be rendered.
  87013. this.renderBackground(thisGroup);
  87014. // Real update view
  87015. this._updateView();
  87016. this._enableHoverLinkToSeries();
  87017. this._enableHoverLinkFromSeries();
  87018. this.positionGroup(thisGroup);
  87019. };
  87020. ContinuousView.prototype._renderEndsText = function (group, dataRangeText, endsIndex) {
  87021. if (!dataRangeText) {
  87022. return;
  87023. }
  87024. // Compatible with ec2, text[0] map to high value, text[1] map low value.
  87025. var text = dataRangeText[1 - endsIndex];
  87026. text = text != null ? text + '' : '';
  87027. var visualMapModel = this.visualMapModel;
  87028. var textGap = visualMapModel.get('textGap');
  87029. var itemSize = visualMapModel.itemSize;
  87030. var barGroup = this._shapes.mainGroup;
  87031. var position = this._applyTransform([itemSize[0] / 2, endsIndex === 0 ? -textGap : itemSize[1] + textGap], barGroup);
  87032. var align = this._applyTransform(endsIndex === 0 ? 'bottom' : 'top', barGroup);
  87033. var orient = this._orient;
  87034. var textStyleModel = this.visualMapModel.textStyleModel;
  87035. this.group.add(new ZRText({
  87036. style: createTextStyle(textStyleModel, {
  87037. x: position[0],
  87038. y: position[1],
  87039. verticalAlign: textStyleModel.get('verticalAlign') || (orient === 'horizontal' ? 'middle' : align),
  87040. align: textStyleModel.get('align') || (orient === 'horizontal' ? align : 'center'),
  87041. text: text
  87042. })
  87043. }));
  87044. };
  87045. ContinuousView.prototype._renderBar = function (targetGroup) {
  87046. var visualMapModel = this.visualMapModel;
  87047. var shapes = this._shapes;
  87048. var itemSize = visualMapModel.itemSize;
  87049. var orient = this._orient;
  87050. var useHandle = this._useHandle;
  87051. var itemAlign = getItemAlign(visualMapModel, this.api, itemSize);
  87052. var mainGroup = shapes.mainGroup = this._createBarGroup(itemAlign);
  87053. var gradientBarGroup = new Group();
  87054. mainGroup.add(gradientBarGroup);
  87055. // Bar
  87056. gradientBarGroup.add(shapes.outOfRange = createPolygon());
  87057. gradientBarGroup.add(shapes.inRange = createPolygon(null, useHandle ? getCursor$1(this._orient) : null, bind(this._dragHandle, this, 'all', false), bind(this._dragHandle, this, 'all', true)));
  87058. // A border radius clip.
  87059. gradientBarGroup.setClipPath(new Rect({
  87060. shape: {
  87061. x: 0,
  87062. y: 0,
  87063. width: itemSize[0],
  87064. height: itemSize[1],
  87065. r: 3
  87066. }
  87067. }));
  87068. var textRect = visualMapModel.textStyleModel.getTextRect('国');
  87069. var textSize = mathMax$b(textRect.width, textRect.height);
  87070. // Handle
  87071. if (useHandle) {
  87072. shapes.handleThumbs = [];
  87073. shapes.handleLabels = [];
  87074. shapes.handleLabelPoints = [];
  87075. this._createHandle(visualMapModel, mainGroup, 0, itemSize, textSize, orient);
  87076. this._createHandle(visualMapModel, mainGroup, 1, itemSize, textSize, orient);
  87077. }
  87078. this._createIndicator(visualMapModel, mainGroup, itemSize, textSize, orient);
  87079. targetGroup.add(mainGroup);
  87080. };
  87081. ContinuousView.prototype._createHandle = function (visualMapModel, mainGroup, handleIndex, itemSize, textSize, orient) {
  87082. var onDrift = bind(this._dragHandle, this, handleIndex, false);
  87083. var onDragEnd = bind(this._dragHandle, this, handleIndex, true);
  87084. var handleSize = parsePercent(visualMapModel.get('handleSize'), itemSize[0]);
  87085. var handleThumb = createSymbol(visualMapModel.get('handleIcon'), -handleSize / 2, -handleSize / 2, handleSize, handleSize, null, true);
  87086. var cursor = getCursor$1(this._orient);
  87087. handleThumb.attr({
  87088. cursor: cursor,
  87089. draggable: true,
  87090. drift: onDrift,
  87091. ondragend: onDragEnd,
  87092. onmousemove: function (e) {
  87093. stop(e.event);
  87094. }
  87095. });
  87096. handleThumb.x = itemSize[0] / 2;
  87097. handleThumb.useStyle(visualMapModel.getModel('handleStyle').getItemStyle());
  87098. handleThumb.setStyle({
  87099. strokeNoScale: true,
  87100. strokeFirst: true
  87101. });
  87102. handleThumb.style.lineWidth *= 2;
  87103. handleThumb.ensureState('emphasis').style = visualMapModel.getModel(['emphasis', 'handleStyle']).getItemStyle();
  87104. setAsHighDownDispatcher(handleThumb, true);
  87105. mainGroup.add(handleThumb);
  87106. // Text is always horizontal layout but should not be effected by
  87107. // transform (orient/inverse). So label is built separately but not
  87108. // use zrender/graphic/helper/RectText, and is located based on view
  87109. // group (according to handleLabelPoint) but not barGroup.
  87110. var textStyleModel = this.visualMapModel.textStyleModel;
  87111. var handleLabel = new ZRText({
  87112. cursor: cursor,
  87113. draggable: true,
  87114. drift: onDrift,
  87115. onmousemove: function (e) {
  87116. // For mobile device, prevent screen slider on the button.
  87117. stop(e.event);
  87118. },
  87119. ondragend: onDragEnd,
  87120. style: createTextStyle(textStyleModel, {
  87121. x: 0,
  87122. y: 0,
  87123. text: ''
  87124. })
  87125. });
  87126. handleLabel.ensureState('blur').style = {
  87127. opacity: 0.1
  87128. };
  87129. handleLabel.stateTransition = {
  87130. duration: 200
  87131. };
  87132. this.group.add(handleLabel);
  87133. var handleLabelPoint = [handleSize, 0];
  87134. var shapes = this._shapes;
  87135. shapes.handleThumbs[handleIndex] = handleThumb;
  87136. shapes.handleLabelPoints[handleIndex] = handleLabelPoint;
  87137. shapes.handleLabels[handleIndex] = handleLabel;
  87138. };
  87139. ContinuousView.prototype._createIndicator = function (visualMapModel, mainGroup, itemSize, textSize, orient) {
  87140. var scale = parsePercent(visualMapModel.get('indicatorSize'), itemSize[0]);
  87141. var indicator = createSymbol(visualMapModel.get('indicatorIcon'), -scale / 2, -scale / 2, scale, scale, null, true);
  87142. indicator.attr({
  87143. cursor: 'move',
  87144. invisible: true,
  87145. silent: true,
  87146. x: itemSize[0] / 2
  87147. });
  87148. var indicatorStyle = visualMapModel.getModel('indicatorStyle').getItemStyle();
  87149. if (indicator instanceof ZRImage) {
  87150. var pathStyle = indicator.style;
  87151. indicator.useStyle(extend({
  87152. // TODO other properties like x, y ?
  87153. image: pathStyle.image,
  87154. x: pathStyle.x,
  87155. y: pathStyle.y,
  87156. width: pathStyle.width,
  87157. height: pathStyle.height
  87158. }, indicatorStyle));
  87159. } else {
  87160. indicator.useStyle(indicatorStyle);
  87161. }
  87162. mainGroup.add(indicator);
  87163. var textStyleModel = this.visualMapModel.textStyleModel;
  87164. var indicatorLabel = new ZRText({
  87165. silent: true,
  87166. invisible: true,
  87167. style: createTextStyle(textStyleModel, {
  87168. x: 0,
  87169. y: 0,
  87170. text: ''
  87171. })
  87172. });
  87173. this.group.add(indicatorLabel);
  87174. var indicatorLabelPoint = [(orient === 'horizontal' ? textSize / 2 : HOVER_LINK_OUT) + itemSize[0] / 2, 0];
  87175. var shapes = this._shapes;
  87176. shapes.indicator = indicator;
  87177. shapes.indicatorLabel = indicatorLabel;
  87178. shapes.indicatorLabelPoint = indicatorLabelPoint;
  87179. this._firstShowIndicator = true;
  87180. };
  87181. ContinuousView.prototype._dragHandle = function (handleIndex, isEnd,
  87182. // dx is event from ondragend if isEnd is true. It's not used
  87183. dx, dy) {
  87184. if (!this._useHandle) {
  87185. return;
  87186. }
  87187. this._dragging = !isEnd;
  87188. if (!isEnd) {
  87189. // Transform dx, dy to bar coordination.
  87190. var vertex = this._applyTransform([dx, dy], this._shapes.mainGroup, true);
  87191. this._updateInterval(handleIndex, vertex[1]);
  87192. this._hideIndicator();
  87193. // Considering realtime, update view should be executed
  87194. // before dispatch action.
  87195. this._updateView();
  87196. }
  87197. // dragEnd do not dispatch action when realtime.
  87198. if (isEnd === !this.visualMapModel.get('realtime')) {
  87199. // jshint ignore:line
  87200. this.api.dispatchAction({
  87201. type: 'selectDataRange',
  87202. from: this.uid,
  87203. visualMapId: this.visualMapModel.id,
  87204. selected: this._dataInterval.slice()
  87205. });
  87206. }
  87207. if (isEnd) {
  87208. !this._hovering && this._clearHoverLinkToSeries();
  87209. } else if (useHoverLinkOnHandle(this.visualMapModel)) {
  87210. this._doHoverLinkToSeries(this._handleEnds[handleIndex], false);
  87211. }
  87212. };
  87213. ContinuousView.prototype._resetInterval = function () {
  87214. var visualMapModel = this.visualMapModel;
  87215. var dataInterval = this._dataInterval = visualMapModel.getSelected();
  87216. var dataExtent = visualMapModel.getExtent();
  87217. var sizeExtent = [0, visualMapModel.itemSize[1]];
  87218. this._handleEnds = [linearMap$2(dataInterval[0], dataExtent, sizeExtent, true), linearMap$2(dataInterval[1], dataExtent, sizeExtent, true)];
  87219. };
  87220. /**
  87221. * @private
  87222. * @param {(number|string)} handleIndex 0 or 1 or 'all'
  87223. * @param {number} dx
  87224. * @param {number} dy
  87225. */
  87226. ContinuousView.prototype._updateInterval = function (handleIndex, delta) {
  87227. delta = delta || 0;
  87228. var visualMapModel = this.visualMapModel;
  87229. var handleEnds = this._handleEnds;
  87230. var sizeExtent = [0, visualMapModel.itemSize[1]];
  87231. sliderMove(delta, handleEnds, sizeExtent, handleIndex,
  87232. // cross is forbidden
  87233. 0);
  87234. var dataExtent = visualMapModel.getExtent();
  87235. // Update data interval.
  87236. this._dataInterval = [linearMap$2(handleEnds[0], sizeExtent, dataExtent, true), linearMap$2(handleEnds[1], sizeExtent, dataExtent, true)];
  87237. };
  87238. ContinuousView.prototype._updateView = function (forSketch) {
  87239. var visualMapModel = this.visualMapModel;
  87240. var dataExtent = visualMapModel.getExtent();
  87241. var shapes = this._shapes;
  87242. var outOfRangeHandleEnds = [0, visualMapModel.itemSize[1]];
  87243. var inRangeHandleEnds = forSketch ? outOfRangeHandleEnds : this._handleEnds;
  87244. var visualInRange = this._createBarVisual(this._dataInterval, dataExtent, inRangeHandleEnds, 'inRange');
  87245. var visualOutOfRange = this._createBarVisual(dataExtent, dataExtent, outOfRangeHandleEnds, 'outOfRange');
  87246. shapes.inRange.setStyle({
  87247. fill: visualInRange.barColor
  87248. // opacity: visualInRange.opacity
  87249. }).setShape('points', visualInRange.barPoints);
  87250. shapes.outOfRange.setStyle({
  87251. fill: visualOutOfRange.barColor
  87252. // opacity: visualOutOfRange.opacity
  87253. }).setShape('points', visualOutOfRange.barPoints);
  87254. this._updateHandle(inRangeHandleEnds, visualInRange);
  87255. };
  87256. ContinuousView.prototype._createBarVisual = function (dataInterval, dataExtent, handleEnds, forceState) {
  87257. var opts = {
  87258. forceState: forceState,
  87259. convertOpacityToAlpha: true
  87260. };
  87261. var colorStops = this._makeColorGradient(dataInterval, opts);
  87262. var symbolSizes = [this.getControllerVisual(dataInterval[0], 'symbolSize', opts), this.getControllerVisual(dataInterval[1], 'symbolSize', opts)];
  87263. var barPoints = this._createBarPoints(handleEnds, symbolSizes);
  87264. return {
  87265. barColor: new LinearGradient(0, 0, 0, 1, colorStops),
  87266. barPoints: barPoints,
  87267. handlesColor: [colorStops[0].color, colorStops[colorStops.length - 1].color]
  87268. };
  87269. };
  87270. ContinuousView.prototype._makeColorGradient = function (dataInterval, opts) {
  87271. // Considering colorHue, which is not linear, so we have to sample
  87272. // to calculate gradient color stops, but not only calculate head
  87273. // and tail.
  87274. var sampleNumber = 100; // Arbitrary value.
  87275. var colorStops = [];
  87276. var step = (dataInterval[1] - dataInterval[0]) / sampleNumber;
  87277. colorStops.push({
  87278. color: this.getControllerVisual(dataInterval[0], 'color', opts),
  87279. offset: 0
  87280. });
  87281. for (var i = 1; i < sampleNumber; i++) {
  87282. var currValue = dataInterval[0] + step * i;
  87283. if (currValue > dataInterval[1]) {
  87284. break;
  87285. }
  87286. colorStops.push({
  87287. color: this.getControllerVisual(currValue, 'color', opts),
  87288. offset: i / sampleNumber
  87289. });
  87290. }
  87291. colorStops.push({
  87292. color: this.getControllerVisual(dataInterval[1], 'color', opts),
  87293. offset: 1
  87294. });
  87295. return colorStops;
  87296. };
  87297. ContinuousView.prototype._createBarPoints = function (handleEnds, symbolSizes) {
  87298. var itemSize = this.visualMapModel.itemSize;
  87299. return [[itemSize[0] - symbolSizes[0], handleEnds[0]], [itemSize[0], handleEnds[0]], [itemSize[0], handleEnds[1]], [itemSize[0] - symbolSizes[1], handleEnds[1]]];
  87300. };
  87301. ContinuousView.prototype._createBarGroup = function (itemAlign) {
  87302. var orient = this._orient;
  87303. var inverse = this.visualMapModel.get('inverse');
  87304. return new Group(orient === 'horizontal' && !inverse ? {
  87305. scaleX: itemAlign === 'bottom' ? 1 : -1,
  87306. rotation: Math.PI / 2
  87307. } : orient === 'horizontal' && inverse ? {
  87308. scaleX: itemAlign === 'bottom' ? -1 : 1,
  87309. rotation: -Math.PI / 2
  87310. } : orient === 'vertical' && !inverse ? {
  87311. scaleX: itemAlign === 'left' ? 1 : -1,
  87312. scaleY: -1
  87313. } : {
  87314. scaleX: itemAlign === 'left' ? 1 : -1
  87315. });
  87316. };
  87317. ContinuousView.prototype._updateHandle = function (handleEnds, visualInRange) {
  87318. if (!this._useHandle) {
  87319. return;
  87320. }
  87321. var shapes = this._shapes;
  87322. var visualMapModel = this.visualMapModel;
  87323. var handleThumbs = shapes.handleThumbs;
  87324. var handleLabels = shapes.handleLabels;
  87325. var itemSize = visualMapModel.itemSize;
  87326. var dataExtent = visualMapModel.getExtent();
  87327. var align = this._applyTransform('left', shapes.mainGroup);
  87328. each$e([0, 1], function (handleIndex) {
  87329. var handleThumb = handleThumbs[handleIndex];
  87330. handleThumb.setStyle('fill', visualInRange.handlesColor[handleIndex]);
  87331. handleThumb.y = handleEnds[handleIndex];
  87332. var val = linearMap$2(handleEnds[handleIndex], [0, itemSize[1]], dataExtent, true);
  87333. var symbolSize = this.getControllerVisual(val, 'symbolSize');
  87334. handleThumb.scaleX = handleThumb.scaleY = symbolSize / itemSize[0];
  87335. handleThumb.x = itemSize[0] - symbolSize / 2;
  87336. // Update handle label position.
  87337. var textPoint = applyTransform$1(shapes.handleLabelPoints[handleIndex], getTransform(handleThumb, this.group));
  87338. if (this._orient === 'horizontal') {
  87339. // If visualMap controls symbol size, an additional offset needs to be added to labels to avoid collision at minimum size.
  87340. // Offset reaches value of 0 at "maximum" position, so maximum position is not altered at all.
  87341. var minimumOffset = align === 'left' || align === 'top' ? (itemSize[0] - symbolSize) / 2 : (itemSize[0] - symbolSize) / -2;
  87342. textPoint[1] += minimumOffset;
  87343. }
  87344. handleLabels[handleIndex].setStyle({
  87345. x: textPoint[0],
  87346. y: textPoint[1],
  87347. text: visualMapModel.formatValueText(this._dataInterval[handleIndex]),
  87348. verticalAlign: 'middle',
  87349. align: this._orient === 'vertical' ? this._applyTransform('left', shapes.mainGroup) : 'center'
  87350. });
  87351. }, this);
  87352. };
  87353. ContinuousView.prototype._showIndicator = function (cursorValue, textValue, rangeSymbol, halfHoverLinkSize) {
  87354. var visualMapModel = this.visualMapModel;
  87355. var dataExtent = visualMapModel.getExtent();
  87356. var itemSize = visualMapModel.itemSize;
  87357. var sizeExtent = [0, itemSize[1]];
  87358. var shapes = this._shapes;
  87359. var indicator = shapes.indicator;
  87360. if (!indicator) {
  87361. return;
  87362. }
  87363. indicator.attr('invisible', false);
  87364. var opts = {
  87365. convertOpacityToAlpha: true
  87366. };
  87367. var color = this.getControllerVisual(cursorValue, 'color', opts);
  87368. var symbolSize = this.getControllerVisual(cursorValue, 'symbolSize');
  87369. var y = linearMap$2(cursorValue, dataExtent, sizeExtent, true);
  87370. var x = itemSize[0] - symbolSize / 2;
  87371. var oldIndicatorPos = {
  87372. x: indicator.x,
  87373. y: indicator.y
  87374. };
  87375. // Update handle label position.
  87376. indicator.y = y;
  87377. indicator.x = x;
  87378. var textPoint = applyTransform$1(shapes.indicatorLabelPoint, getTransform(indicator, this.group));
  87379. var indicatorLabel = shapes.indicatorLabel;
  87380. indicatorLabel.attr('invisible', false);
  87381. var align = this._applyTransform('left', shapes.mainGroup);
  87382. var orient = this._orient;
  87383. var isHorizontal = orient === 'horizontal';
  87384. indicatorLabel.setStyle({
  87385. text: (rangeSymbol ? rangeSymbol : '') + visualMapModel.formatValueText(textValue),
  87386. verticalAlign: isHorizontal ? align : 'middle',
  87387. align: isHorizontal ? 'center' : align
  87388. });
  87389. var indicatorNewProps = {
  87390. x: x,
  87391. y: y,
  87392. style: {
  87393. fill: color
  87394. }
  87395. };
  87396. var labelNewProps = {
  87397. style: {
  87398. x: textPoint[0],
  87399. y: textPoint[1]
  87400. }
  87401. };
  87402. if (visualMapModel.ecModel.isAnimationEnabled() && !this._firstShowIndicator) {
  87403. var animationCfg = {
  87404. duration: 100,
  87405. easing: 'cubicInOut',
  87406. additive: true
  87407. };
  87408. indicator.x = oldIndicatorPos.x;
  87409. indicator.y = oldIndicatorPos.y;
  87410. indicator.animateTo(indicatorNewProps, animationCfg);
  87411. indicatorLabel.animateTo(labelNewProps, animationCfg);
  87412. } else {
  87413. indicator.attr(indicatorNewProps);
  87414. indicatorLabel.attr(labelNewProps);
  87415. }
  87416. this._firstShowIndicator = false;
  87417. var handleLabels = this._shapes.handleLabels;
  87418. if (handleLabels) {
  87419. for (var i = 0; i < handleLabels.length; i++) {
  87420. // Fade out handle labels.
  87421. // NOTE: Must use api enter/leave on emphasis/blur/select state. Or the global states manager will change it.
  87422. this.api.enterBlur(handleLabels[i]);
  87423. }
  87424. }
  87425. };
  87426. ContinuousView.prototype._enableHoverLinkToSeries = function () {
  87427. var self = this;
  87428. this._shapes.mainGroup.on('mousemove', function (e) {
  87429. self._hovering = true;
  87430. if (!self._dragging) {
  87431. var itemSize = self.visualMapModel.itemSize;
  87432. var pos = self._applyTransform([e.offsetX, e.offsetY], self._shapes.mainGroup, true, true);
  87433. // For hover link show when hover handle, which might be
  87434. // below or upper than sizeExtent.
  87435. pos[1] = mathMin$b(mathMax$b(0, pos[1]), itemSize[1]);
  87436. self._doHoverLinkToSeries(pos[1], 0 <= pos[0] && pos[0] <= itemSize[0]);
  87437. }
  87438. }).on('mouseout', function () {
  87439. // When mouse is out of handle, hoverLink still need
  87440. // to be displayed when realtime is set as false.
  87441. self._hovering = false;
  87442. !self._dragging && self._clearHoverLinkToSeries();
  87443. });
  87444. };
  87445. ContinuousView.prototype._enableHoverLinkFromSeries = function () {
  87446. var zr = this.api.getZr();
  87447. if (this.visualMapModel.option.hoverLink) {
  87448. zr.on('mouseover', this._hoverLinkFromSeriesMouseOver, this);
  87449. zr.on('mouseout', this._hideIndicator, this);
  87450. } else {
  87451. this._clearHoverLinkFromSeries();
  87452. }
  87453. };
  87454. ContinuousView.prototype._doHoverLinkToSeries = function (cursorPos, hoverOnBar) {
  87455. var visualMapModel = this.visualMapModel;
  87456. var itemSize = visualMapModel.itemSize;
  87457. if (!visualMapModel.option.hoverLink) {
  87458. return;
  87459. }
  87460. var sizeExtent = [0, itemSize[1]];
  87461. var dataExtent = visualMapModel.getExtent();
  87462. // For hover link show when hover handle, which might be below or upper than sizeExtent.
  87463. cursorPos = mathMin$b(mathMax$b(sizeExtent[0], cursorPos), sizeExtent[1]);
  87464. var halfHoverLinkSize = getHalfHoverLinkSize(visualMapModel, dataExtent, sizeExtent);
  87465. var hoverRange = [cursorPos - halfHoverLinkSize, cursorPos + halfHoverLinkSize];
  87466. var cursorValue = linearMap$2(cursorPos, sizeExtent, dataExtent, true);
  87467. var valueRange = [linearMap$2(hoverRange[0], sizeExtent, dataExtent, true), linearMap$2(hoverRange[1], sizeExtent, dataExtent, true)];
  87468. // Consider data range is out of visualMap range, see test/visualMap-continuous.html,
  87469. // where china and india has very large population.
  87470. hoverRange[0] < sizeExtent[0] && (valueRange[0] = -Infinity);
  87471. hoverRange[1] > sizeExtent[1] && (valueRange[1] = Infinity);
  87472. // Do not show indicator when mouse is over handle,
  87473. // otherwise labels overlap, especially when dragging.
  87474. if (hoverOnBar) {
  87475. if (valueRange[0] === -Infinity) {
  87476. this._showIndicator(cursorValue, valueRange[1], '< ', halfHoverLinkSize);
  87477. } else if (valueRange[1] === Infinity) {
  87478. this._showIndicator(cursorValue, valueRange[0], '> ', halfHoverLinkSize);
  87479. } else {
  87480. this._showIndicator(cursorValue, cursorValue, '≈ ', halfHoverLinkSize);
  87481. }
  87482. }
  87483. // When realtime is set as false, handles, which are in barGroup,
  87484. // also trigger hoverLink, which help user to realize where they
  87485. // focus on when dragging. (see test/heatmap-large.html)
  87486. // When realtime is set as true, highlight will not show when hover
  87487. // handle, because the label on handle, which displays a exact value
  87488. // but not range, might mislead users.
  87489. var oldBatch = this._hoverLinkDataIndices;
  87490. var newBatch = [];
  87491. if (hoverOnBar || useHoverLinkOnHandle(visualMapModel)) {
  87492. newBatch = this._hoverLinkDataIndices = visualMapModel.findTargetDataIndices(valueRange);
  87493. }
  87494. var resultBatches = compressBatches(oldBatch, newBatch);
  87495. this._dispatchHighDown('downplay', makeHighDownBatch(resultBatches[0], visualMapModel));
  87496. this._dispatchHighDown('highlight', makeHighDownBatch(resultBatches[1], visualMapModel));
  87497. };
  87498. ContinuousView.prototype._hoverLinkFromSeriesMouseOver = function (e) {
  87499. var ecData;
  87500. findEventDispatcher(e.target, function (target) {
  87501. var currECData = getECData(target);
  87502. if (currECData.dataIndex != null) {
  87503. ecData = currECData;
  87504. return true;
  87505. }
  87506. }, true);
  87507. if (!ecData) {
  87508. return;
  87509. }
  87510. var dataModel = this.ecModel.getSeriesByIndex(ecData.seriesIndex);
  87511. var visualMapModel = this.visualMapModel;
  87512. if (!visualMapModel.isTargetSeries(dataModel)) {
  87513. return;
  87514. }
  87515. var data = dataModel.getData(ecData.dataType);
  87516. var value = data.getStore().get(visualMapModel.getDataDimensionIndex(data), ecData.dataIndex);
  87517. if (!isNaN(value)) {
  87518. this._showIndicator(value, value);
  87519. }
  87520. };
  87521. ContinuousView.prototype._hideIndicator = function () {
  87522. var shapes = this._shapes;
  87523. shapes.indicator && shapes.indicator.attr('invisible', true);
  87524. shapes.indicatorLabel && shapes.indicatorLabel.attr('invisible', true);
  87525. var handleLabels = this._shapes.handleLabels;
  87526. if (handleLabels) {
  87527. for (var i = 0; i < handleLabels.length; i++) {
  87528. // Fade out handle labels.
  87529. // NOTE: Must use api enter/leave on emphasis/blur/select state. Or the global states manager will change it.
  87530. this.api.leaveBlur(handleLabels[i]);
  87531. }
  87532. }
  87533. };
  87534. ContinuousView.prototype._clearHoverLinkToSeries = function () {
  87535. this._hideIndicator();
  87536. var indices = this._hoverLinkDataIndices;
  87537. this._dispatchHighDown('downplay', makeHighDownBatch(indices, this.visualMapModel));
  87538. indices.length = 0;
  87539. };
  87540. ContinuousView.prototype._clearHoverLinkFromSeries = function () {
  87541. this._hideIndicator();
  87542. var zr = this.api.getZr();
  87543. zr.off('mouseover', this._hoverLinkFromSeriesMouseOver);
  87544. zr.off('mouseout', this._hideIndicator);
  87545. };
  87546. ContinuousView.prototype._applyTransform = function (vertex, element, inverse, global) {
  87547. var transform = getTransform(element, global ? null : this.group);
  87548. return isArray(vertex) ? applyTransform$1(vertex, transform, inverse) : transformDirection(vertex, transform, inverse);
  87549. };
  87550. // TODO: TYPE more specified payload types.
  87551. ContinuousView.prototype._dispatchHighDown = function (type, batch) {
  87552. batch && batch.length && this.api.dispatchAction({
  87553. type: type,
  87554. batch: batch
  87555. });
  87556. };
  87557. /**
  87558. * @override
  87559. */
  87560. ContinuousView.prototype.dispose = function () {
  87561. this._clearHoverLinkFromSeries();
  87562. this._clearHoverLinkToSeries();
  87563. };
  87564. ContinuousView.type = 'visualMap.continuous';
  87565. return ContinuousView;
  87566. }(VisualMapView);
  87567. function createPolygon(points, cursor, onDrift, onDragEnd) {
  87568. return new Polygon({
  87569. shape: {
  87570. points: points
  87571. },
  87572. draggable: !!onDrift,
  87573. cursor: cursor,
  87574. drift: onDrift,
  87575. onmousemove: function (e) {
  87576. // For mobile device, prevent screen slider on the button.
  87577. stop(e.event);
  87578. },
  87579. ondragend: onDragEnd
  87580. });
  87581. }
  87582. function getHalfHoverLinkSize(visualMapModel, dataExtent, sizeExtent) {
  87583. var halfHoverLinkSize = HOVER_LINK_SIZE / 2;
  87584. var hoverLinkDataSize = visualMapModel.get('hoverLinkDataSize');
  87585. if (hoverLinkDataSize) {
  87586. halfHoverLinkSize = linearMap$2(hoverLinkDataSize, dataExtent, sizeExtent, true) / 2;
  87587. }
  87588. return halfHoverLinkSize;
  87589. }
  87590. function useHoverLinkOnHandle(visualMapModel) {
  87591. var hoverLinkOnHandle = visualMapModel.get('hoverLinkOnHandle');
  87592. return !!(hoverLinkOnHandle == null ? visualMapModel.get('realtime') : hoverLinkOnHandle);
  87593. }
  87594. function getCursor$1(orient) {
  87595. return orient === 'vertical' ? 'ns-resize' : 'ew-resize';
  87596. }
  87597. /*
  87598. * Licensed to the Apache Software Foundation (ASF) under one
  87599. * or more contributor license agreements. See the NOTICE file
  87600. * distributed with this work for additional information
  87601. * regarding copyright ownership. The ASF licenses this file
  87602. * to you under the Apache License, Version 2.0 (the
  87603. * "License"); you may not use this file except in compliance
  87604. * with the License. You may obtain a copy of the License at
  87605. *
  87606. * http://www.apache.org/licenses/LICENSE-2.0
  87607. *
  87608. * Unless required by applicable law or agreed to in writing,
  87609. * software distributed under the License is distributed on an
  87610. * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
  87611. * KIND, either express or implied. See the License for the
  87612. * specific language governing permissions and limitations
  87613. * under the License.
  87614. */
  87615. /**
  87616. * AUTO-GENERATED FILE. DO NOT MODIFY.
  87617. */
  87618. /*
  87619. * Licensed to the Apache Software Foundation (ASF) under one
  87620. * or more contributor license agreements. See the NOTICE file
  87621. * distributed with this work for additional information
  87622. * regarding copyright ownership. The ASF licenses this file
  87623. * to you under the Apache License, Version 2.0 (the
  87624. * "License"); you may not use this file except in compliance
  87625. * with the License. You may obtain a copy of the License at
  87626. *
  87627. * http://www.apache.org/licenses/LICENSE-2.0
  87628. *
  87629. * Unless required by applicable law or agreed to in writing,
  87630. * software distributed under the License is distributed on an
  87631. * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
  87632. * KIND, either express or implied. See the License for the
  87633. * specific language governing permissions and limitations
  87634. * under the License.
  87635. */
  87636. var visualMapActionInfo = {
  87637. type: 'selectDataRange',
  87638. event: 'dataRangeSelected',
  87639. // FIXME use updateView appears wrong
  87640. update: 'update'
  87641. };
  87642. var visualMapActionHander = function (payload, ecModel) {
  87643. ecModel.eachComponent({
  87644. mainType: 'visualMap',
  87645. query: payload
  87646. }, function (model) {
  87647. model.setSelected(payload.selected);
  87648. });
  87649. };
  87650. var visualMapEncodingHandlers = [{
  87651. createOnAllSeries: true,
  87652. reset: function (seriesModel, ecModel) {
  87653. var resetDefines = [];
  87654. ecModel.eachComponent('visualMap', function (visualMapModel) {
  87655. var pipelineContext = seriesModel.pipelineContext;
  87656. if (!visualMapModel.isTargetSeries(seriesModel) || pipelineContext && pipelineContext.large) {
  87657. return;
  87658. }
  87659. resetDefines.push(incrementalApplyVisual(visualMapModel.stateList, visualMapModel.targetVisuals, bind(visualMapModel.getValueState, visualMapModel), visualMapModel.getDataDimensionIndex(seriesModel.getData())));
  87660. });
  87661. return resetDefines;
  87662. }
  87663. },
  87664. // Only support color.
  87665. {
  87666. createOnAllSeries: true,
  87667. reset: function (seriesModel, ecModel) {
  87668. var data = seriesModel.getData();
  87669. var visualMetaList = [];
  87670. ecModel.eachComponent('visualMap', function (visualMapModel) {
  87671. if (visualMapModel.isTargetSeries(seriesModel)) {
  87672. var visualMeta = visualMapModel.getVisualMeta(bind(getColorVisual, null, seriesModel, visualMapModel)) || {
  87673. stops: [],
  87674. outerColors: []
  87675. };
  87676. var dimIdx = visualMapModel.getDataDimensionIndex(data);
  87677. if (dimIdx >= 0) {
  87678. // visualMeta.dimension should be dimension index, but not concrete dimension.
  87679. visualMeta.dimension = dimIdx;
  87680. visualMetaList.push(visualMeta);
  87681. }
  87682. }
  87683. });
  87684. // console.log(JSON.stringify(visualMetaList.map(a => a.stops)));
  87685. seriesModel.getData().setVisual('visualMeta', visualMetaList);
  87686. }
  87687. }];
  87688. // FIXME
  87689. // performance and export for heatmap?
  87690. // value can be Infinity or -Infinity
  87691. function getColorVisual(seriesModel, visualMapModel, value, valueState) {
  87692. var mappings = visualMapModel.targetVisuals[valueState];
  87693. var visualTypes = VisualMapping.prepareVisualTypes(mappings);
  87694. var resultVisual = {
  87695. color: getVisualFromData(seriesModel.getData(), 'color') // default color.
  87696. };
  87697. for (var i = 0, len = visualTypes.length; i < len; i++) {
  87698. var type = visualTypes[i];
  87699. var mapping = mappings[type === 'opacity' ? '__alphaForOpacity' : type];
  87700. mapping && mapping.applyVisual(value, getVisual, setVisual);
  87701. }
  87702. return resultVisual.color;
  87703. function getVisual(key) {
  87704. return resultVisual[key];
  87705. }
  87706. function setVisual(key, value) {
  87707. resultVisual[key] = value;
  87708. }
  87709. }
  87710. var each$f = each;
  87711. function visualMapPreprocessor(option) {
  87712. var visualMap = option && option.visualMap;
  87713. if (!isArray(visualMap)) {
  87714. visualMap = visualMap ? [visualMap] : [];
  87715. }
  87716. each$f(visualMap, function (opt) {
  87717. if (!opt) {
  87718. return;
  87719. }
  87720. // rename splitList to pieces
  87721. if (has$1(opt, 'splitList') && !has$1(opt, 'pieces')) {
  87722. opt.pieces = opt.splitList;
  87723. delete opt.splitList;
  87724. }
  87725. var pieces = opt.pieces;
  87726. if (pieces && isArray(pieces)) {
  87727. each$f(pieces, function (piece) {
  87728. if (isObject(piece)) {
  87729. if (has$1(piece, 'start') && !has$1(piece, 'min')) {
  87730. piece.min = piece.start;
  87731. }
  87732. if (has$1(piece, 'end') && !has$1(piece, 'max')) {
  87733. piece.max = piece.end;
  87734. }
  87735. }
  87736. });
  87737. }
  87738. });
  87739. }
  87740. function has$1(obj, name) {
  87741. return obj && obj.hasOwnProperty && obj.hasOwnProperty(name);
  87742. }
  87743. var installed$1 = false;
  87744. function installCommon$1(registers) {
  87745. if (installed$1) {
  87746. return;
  87747. }
  87748. installed$1 = true;
  87749. registers.registerSubTypeDefaulter('visualMap', function (option) {
  87750. // Compatible with ec2, when splitNumber === 0, continuous visualMap will be used.
  87751. return !option.categories && (!(option.pieces ? option.pieces.length > 0 : option.splitNumber > 0) || option.calculable) ? 'continuous' : 'piecewise';
  87752. });
  87753. registers.registerAction(visualMapActionInfo, visualMapActionHander);
  87754. each(visualMapEncodingHandlers, function (handler) {
  87755. registers.registerVisual(registers.PRIORITY.VISUAL.COMPONENT, handler);
  87756. });
  87757. registers.registerPreprocessor(visualMapPreprocessor);
  87758. }
  87759. function install$P(registers) {
  87760. registers.registerComponentModel(ContinuousModel);
  87761. registers.registerComponentView(ContinuousView);
  87762. installCommon$1(registers);
  87763. }
  87764. var PiecewiseModel = /** @class */function (_super) {
  87765. __extends(PiecewiseModel, _super);
  87766. function PiecewiseModel() {
  87767. var _this = _super !== null && _super.apply(this, arguments) || this;
  87768. _this.type = PiecewiseModel.type;
  87769. /**
  87770. * The order is always [low, ..., high].
  87771. * [{text: string, interval: Array.<number>}, ...]
  87772. */
  87773. _this._pieceList = [];
  87774. return _this;
  87775. }
  87776. PiecewiseModel.prototype.optionUpdated = function (newOption, isInit) {
  87777. _super.prototype.optionUpdated.apply(this, arguments);
  87778. this.resetExtent();
  87779. var mode = this._mode = this._determineMode();
  87780. this._pieceList = [];
  87781. resetMethods[this._mode].call(this, this._pieceList);
  87782. this._resetSelected(newOption, isInit);
  87783. var categories = this.option.categories;
  87784. this.resetVisual(function (mappingOption, state) {
  87785. if (mode === 'categories') {
  87786. mappingOption.mappingMethod = 'category';
  87787. mappingOption.categories = clone(categories);
  87788. } else {
  87789. mappingOption.dataExtent = this.getExtent();
  87790. mappingOption.mappingMethod = 'piecewise';
  87791. mappingOption.pieceList = map(this._pieceList, function (piece) {
  87792. piece = clone(piece);
  87793. if (state !== 'inRange') {
  87794. // FIXME
  87795. // outOfRange do not support special visual in pieces.
  87796. piece.visual = null;
  87797. }
  87798. return piece;
  87799. });
  87800. }
  87801. });
  87802. };
  87803. /**
  87804. * @protected
  87805. * @override
  87806. */
  87807. PiecewiseModel.prototype.completeVisualOption = function () {
  87808. // Consider this case:
  87809. // visualMap: {
  87810. // pieces: [{symbol: 'circle', lt: 0}, {symbol: 'rect', gte: 0}]
  87811. // }
  87812. // where no inRange/outOfRange set but only pieces. So we should make
  87813. // default inRange/outOfRange for this case, otherwise visuals that only
  87814. // appear in `pieces` will not be taken into account in visual encoding.
  87815. var option = this.option;
  87816. var visualTypesInPieces = {};
  87817. var visualTypes = VisualMapping.listVisualTypes();
  87818. var isCategory = this.isCategory();
  87819. each(option.pieces, function (piece) {
  87820. each(visualTypes, function (visualType) {
  87821. if (piece.hasOwnProperty(visualType)) {
  87822. visualTypesInPieces[visualType] = 1;
  87823. }
  87824. });
  87825. });
  87826. each(visualTypesInPieces, function (v, visualType) {
  87827. var exists = false;
  87828. each(this.stateList, function (state) {
  87829. exists = exists || has(option, state, visualType) || has(option.target, state, visualType);
  87830. }, this);
  87831. !exists && each(this.stateList, function (state) {
  87832. (option[state] || (option[state] = {}))[visualType] = visualDefault.get(visualType, state === 'inRange' ? 'active' : 'inactive', isCategory);
  87833. });
  87834. }, this);
  87835. function has(obj, state, visualType) {
  87836. return obj && obj[state] && obj[state].hasOwnProperty(visualType);
  87837. }
  87838. _super.prototype.completeVisualOption.apply(this, arguments);
  87839. };
  87840. PiecewiseModel.prototype._resetSelected = function (newOption, isInit) {
  87841. var thisOption = this.option;
  87842. var pieceList = this._pieceList;
  87843. // Selected do not merge but all override.
  87844. var selected = (isInit ? thisOption : newOption).selected || {};
  87845. thisOption.selected = selected;
  87846. // Consider 'not specified' means true.
  87847. each(pieceList, function (piece, index) {
  87848. var key = this.getSelectedMapKey(piece);
  87849. if (!selected.hasOwnProperty(key)) {
  87850. selected[key] = true;
  87851. }
  87852. }, this);
  87853. if (thisOption.selectedMode === 'single') {
  87854. // Ensure there is only one selected.
  87855. var hasSel_1 = false;
  87856. each(pieceList, function (piece, index) {
  87857. var key = this.getSelectedMapKey(piece);
  87858. if (selected[key]) {
  87859. hasSel_1 ? selected[key] = false : hasSel_1 = true;
  87860. }
  87861. }, this);
  87862. }
  87863. // thisOption.selectedMode === 'multiple', default: all selected.
  87864. };
  87865. /**
  87866. * @public
  87867. */
  87868. PiecewiseModel.prototype.getItemSymbol = function () {
  87869. return this.get('itemSymbol');
  87870. };
  87871. /**
  87872. * @public
  87873. */
  87874. PiecewiseModel.prototype.getSelectedMapKey = function (piece) {
  87875. return this._mode === 'categories' ? piece.value + '' : piece.index + '';
  87876. };
  87877. /**
  87878. * @public
  87879. */
  87880. PiecewiseModel.prototype.getPieceList = function () {
  87881. return this._pieceList;
  87882. };
  87883. /**
  87884. * @return {string}
  87885. */
  87886. PiecewiseModel.prototype._determineMode = function () {
  87887. var option = this.option;
  87888. return option.pieces && option.pieces.length > 0 ? 'pieces' : this.option.categories ? 'categories' : 'splitNumber';
  87889. };
  87890. /**
  87891. * @override
  87892. */
  87893. PiecewiseModel.prototype.setSelected = function (selected) {
  87894. this.option.selected = clone(selected);
  87895. };
  87896. /**
  87897. * @override
  87898. */
  87899. PiecewiseModel.prototype.getValueState = function (value) {
  87900. var index = VisualMapping.findPieceIndex(value, this._pieceList);
  87901. return index != null ? this.option.selected[this.getSelectedMapKey(this._pieceList[index])] ? 'inRange' : 'outOfRange' : 'outOfRange';
  87902. };
  87903. /**
  87904. * @public
  87905. * @param pieceIndex piece index in visualMapModel.getPieceList()
  87906. */
  87907. PiecewiseModel.prototype.findTargetDataIndices = function (pieceIndex) {
  87908. var result = [];
  87909. var pieceList = this._pieceList;
  87910. this.eachTargetSeries(function (seriesModel) {
  87911. var dataIndices = [];
  87912. var data = seriesModel.getData();
  87913. data.each(this.getDataDimensionIndex(data), function (value, dataIndex) {
  87914. // Should always base on model pieceList, because it is order sensitive.
  87915. var pIdx = VisualMapping.findPieceIndex(value, pieceList);
  87916. pIdx === pieceIndex && dataIndices.push(dataIndex);
  87917. }, this);
  87918. result.push({
  87919. seriesId: seriesModel.id,
  87920. dataIndex: dataIndices
  87921. });
  87922. }, this);
  87923. return result;
  87924. };
  87925. /**
  87926. * @private
  87927. * @param piece piece.value or piece.interval is required.
  87928. * @return Can be Infinity or -Infinity
  87929. */
  87930. PiecewiseModel.prototype.getRepresentValue = function (piece) {
  87931. var representValue;
  87932. if (this.isCategory()) {
  87933. representValue = piece.value;
  87934. } else {
  87935. if (piece.value != null) {
  87936. representValue = piece.value;
  87937. } else {
  87938. var pieceInterval = piece.interval || [];
  87939. representValue = pieceInterval[0] === -Infinity && pieceInterval[1] === Infinity ? 0 : (pieceInterval[0] + pieceInterval[1]) / 2;
  87940. }
  87941. }
  87942. return representValue;
  87943. };
  87944. PiecewiseModel.prototype.getVisualMeta = function (getColorVisual) {
  87945. // Do not support category. (category axis is ordinal, numerical)
  87946. if (this.isCategory()) {
  87947. return;
  87948. }
  87949. var stops = [];
  87950. var outerColors = ['', ''];
  87951. var visualMapModel = this;
  87952. function setStop(interval, valueState) {
  87953. var representValue = visualMapModel.getRepresentValue({
  87954. interval: interval
  87955. }); // Not category
  87956. if (!valueState) {
  87957. valueState = visualMapModel.getValueState(representValue);
  87958. }
  87959. var color = getColorVisual(representValue, valueState);
  87960. if (interval[0] === -Infinity) {
  87961. outerColors[0] = color;
  87962. } else if (interval[1] === Infinity) {
  87963. outerColors[1] = color;
  87964. } else {
  87965. stops.push({
  87966. value: interval[0],
  87967. color: color
  87968. }, {
  87969. value: interval[1],
  87970. color: color
  87971. });
  87972. }
  87973. }
  87974. // Suplement
  87975. var pieceList = this._pieceList.slice();
  87976. if (!pieceList.length) {
  87977. pieceList.push({
  87978. interval: [-Infinity, Infinity]
  87979. });
  87980. } else {
  87981. var edge = pieceList[0].interval[0];
  87982. edge !== -Infinity && pieceList.unshift({
  87983. interval: [-Infinity, edge]
  87984. });
  87985. edge = pieceList[pieceList.length - 1].interval[1];
  87986. edge !== Infinity && pieceList.push({
  87987. interval: [edge, Infinity]
  87988. });
  87989. }
  87990. var curr = -Infinity;
  87991. each(pieceList, function (piece) {
  87992. var interval = piece.interval;
  87993. if (interval) {
  87994. // Fulfill gap.
  87995. interval[0] > curr && setStop([curr, interval[0]], 'outOfRange');
  87996. setStop(interval.slice());
  87997. curr = interval[1];
  87998. }
  87999. }, this);
  88000. return {
  88001. stops: stops,
  88002. outerColors: outerColors
  88003. };
  88004. };
  88005. PiecewiseModel.type = 'visualMap.piecewise';
  88006. PiecewiseModel.defaultOption = inheritDefaultOption(VisualMapModel.defaultOption, {
  88007. selected: null,
  88008. minOpen: false,
  88009. maxOpen: false,
  88010. align: 'auto',
  88011. itemWidth: 20,
  88012. itemHeight: 14,
  88013. itemSymbol: 'roundRect',
  88014. pieces: null,
  88015. categories: null,
  88016. splitNumber: 5,
  88017. selectedMode: 'multiple',
  88018. itemGap: 10,
  88019. hoverLink: true // Enable hover highlight.
  88020. });
  88021. return PiecewiseModel;
  88022. }(VisualMapModel);
  88023. /**
  88024. * Key is this._mode
  88025. * @type {Object}
  88026. * @this {module:echarts/component/viusalMap/PiecewiseMode}
  88027. */
  88028. var resetMethods = {
  88029. splitNumber: function (outPieceList) {
  88030. var thisOption = this.option;
  88031. var precision = Math.min(thisOption.precision, 20);
  88032. var dataExtent = this.getExtent();
  88033. var splitNumber = thisOption.splitNumber;
  88034. splitNumber = Math.max(parseInt(splitNumber, 10), 1);
  88035. thisOption.splitNumber = splitNumber;
  88036. var splitStep = (dataExtent[1] - dataExtent[0]) / splitNumber;
  88037. // Precision auto-adaption
  88038. while (+splitStep.toFixed(precision) !== splitStep && precision < 5) {
  88039. precision++;
  88040. }
  88041. thisOption.precision = precision;
  88042. splitStep = +splitStep.toFixed(precision);
  88043. if (thisOption.minOpen) {
  88044. outPieceList.push({
  88045. interval: [-Infinity, dataExtent[0]],
  88046. close: [0, 0]
  88047. });
  88048. }
  88049. for (var index = 0, curr = dataExtent[0]; index < splitNumber; curr += splitStep, index++) {
  88050. var max = index === splitNumber - 1 ? dataExtent[1] : curr + splitStep;
  88051. outPieceList.push({
  88052. interval: [curr, max],
  88053. close: [1, 1]
  88054. });
  88055. }
  88056. if (thisOption.maxOpen) {
  88057. outPieceList.push({
  88058. interval: [dataExtent[1], Infinity],
  88059. close: [0, 0]
  88060. });
  88061. }
  88062. reformIntervals(outPieceList);
  88063. each(outPieceList, function (piece, index) {
  88064. piece.index = index;
  88065. piece.text = this.formatValueText(piece.interval);
  88066. }, this);
  88067. },
  88068. categories: function (outPieceList) {
  88069. var thisOption = this.option;
  88070. each(thisOption.categories, function (cate) {
  88071. // FIXME category模式也使用pieceList,但在visualMapping中不是使用pieceList。
  88072. // 是否改一致。
  88073. outPieceList.push({
  88074. text: this.formatValueText(cate, true),
  88075. value: cate
  88076. });
  88077. }, this);
  88078. // See "Order Rule".
  88079. normalizeReverse(thisOption, outPieceList);
  88080. },
  88081. pieces: function (outPieceList) {
  88082. var thisOption = this.option;
  88083. each(thisOption.pieces, function (pieceListItem, index) {
  88084. if (!isObject(pieceListItem)) {
  88085. pieceListItem = {
  88086. value: pieceListItem
  88087. };
  88088. }
  88089. var item = {
  88090. text: '',
  88091. index: index
  88092. };
  88093. if (pieceListItem.label != null) {
  88094. item.text = pieceListItem.label;
  88095. }
  88096. if (pieceListItem.hasOwnProperty('value')) {
  88097. var value = item.value = pieceListItem.value;
  88098. item.interval = [value, value];
  88099. item.close = [1, 1];
  88100. } else {
  88101. // `min` `max` is legacy option.
  88102. // `lt` `gt` `lte` `gte` is recommended.
  88103. var interval = item.interval = [];
  88104. var close_1 = item.close = [0, 0];
  88105. var closeList = [1, 0, 1];
  88106. var infinityList = [-Infinity, Infinity];
  88107. var useMinMax = [];
  88108. for (var lg = 0; lg < 2; lg++) {
  88109. var names = [['gte', 'gt', 'min'], ['lte', 'lt', 'max']][lg];
  88110. for (var i = 0; i < 3 && interval[lg] == null; i++) {
  88111. interval[lg] = pieceListItem[names[i]];
  88112. close_1[lg] = closeList[i];
  88113. useMinMax[lg] = i === 2;
  88114. }
  88115. interval[lg] == null && (interval[lg] = infinityList[lg]);
  88116. }
  88117. useMinMax[0] && interval[1] === Infinity && (close_1[0] = 0);
  88118. useMinMax[1] && interval[0] === -Infinity && (close_1[1] = 0);
  88119. if ("development" !== 'production') {
  88120. if (interval[0] > interval[1]) {
  88121. console.warn('Piece ' + index + 'is illegal: ' + interval + ' lower bound should not greater then uppper bound.');
  88122. }
  88123. }
  88124. if (interval[0] === interval[1] && close_1[0] && close_1[1]) {
  88125. // Consider: [{min: 5, max: 5, visual: {...}}, {min: 0, max: 5}],
  88126. // we use value to lift the priority when min === max
  88127. item.value = interval[0];
  88128. }
  88129. }
  88130. item.visual = VisualMapping.retrieveVisuals(pieceListItem);
  88131. outPieceList.push(item);
  88132. }, this);
  88133. // See "Order Rule".
  88134. normalizeReverse(thisOption, outPieceList);
  88135. // Only pieces
  88136. reformIntervals(outPieceList);
  88137. each(outPieceList, function (piece) {
  88138. var close = piece.close;
  88139. var edgeSymbols = [['<', '≤'][close[1]], ['>', '≥'][close[0]]];
  88140. piece.text = piece.text || this.formatValueText(piece.value != null ? piece.value : piece.interval, false, edgeSymbols);
  88141. }, this);
  88142. }
  88143. };
  88144. function normalizeReverse(thisOption, pieceList) {
  88145. var inverse = thisOption.inverse;
  88146. if (thisOption.orient === 'vertical' ? !inverse : inverse) {
  88147. pieceList.reverse();
  88148. }
  88149. }
  88150. var PiecewiseVisualMapView = /** @class */function (_super) {
  88151. __extends(PiecewiseVisualMapView, _super);
  88152. function PiecewiseVisualMapView() {
  88153. var _this = _super !== null && _super.apply(this, arguments) || this;
  88154. _this.type = PiecewiseVisualMapView.type;
  88155. return _this;
  88156. }
  88157. PiecewiseVisualMapView.prototype.doRender = function () {
  88158. var thisGroup = this.group;
  88159. thisGroup.removeAll();
  88160. var visualMapModel = this.visualMapModel;
  88161. var textGap = visualMapModel.get('textGap');
  88162. var textStyleModel = visualMapModel.textStyleModel;
  88163. var itemAlign = this._getItemAlign();
  88164. var itemSize = visualMapModel.itemSize;
  88165. var viewData = this._getViewData();
  88166. var endsText = viewData.endsText;
  88167. var showLabel = retrieve(visualMapModel.get('showLabel', true), !endsText);
  88168. var silent = !visualMapModel.get('selectedMode');
  88169. endsText && this._renderEndsText(thisGroup, endsText[0], itemSize, showLabel, itemAlign);
  88170. each(viewData.viewPieceList, function (item) {
  88171. var piece = item.piece;
  88172. var itemGroup = new Group();
  88173. itemGroup.onclick = bind(this._onItemClick, this, piece);
  88174. this._enableHoverLink(itemGroup, item.indexInModelPieceList);
  88175. // TODO Category
  88176. var representValue = visualMapModel.getRepresentValue(piece);
  88177. this._createItemSymbol(itemGroup, representValue, [0, 0, itemSize[0], itemSize[1]], silent);
  88178. if (showLabel) {
  88179. var visualState = this.visualMapModel.getValueState(representValue);
  88180. var align = textStyleModel.get('align') || itemAlign;
  88181. itemGroup.add(new ZRText({
  88182. style: createTextStyle(textStyleModel, {
  88183. x: align === 'right' ? -textGap : itemSize[0] + textGap,
  88184. y: itemSize[1] / 2,
  88185. text: piece.text,
  88186. verticalAlign: textStyleModel.get('verticalAlign') || 'middle',
  88187. align: align,
  88188. opacity: retrieve2(textStyleModel.get('opacity'), visualState === 'outOfRange' ? 0.5 : 1)
  88189. }),
  88190. silent: silent
  88191. }));
  88192. }
  88193. thisGroup.add(itemGroup);
  88194. }, this);
  88195. endsText && this._renderEndsText(thisGroup, endsText[1], itemSize, showLabel, itemAlign);
  88196. box(visualMapModel.get('orient'), thisGroup, visualMapModel.get('itemGap'));
  88197. this.renderBackground(thisGroup);
  88198. this.positionGroup(thisGroup);
  88199. };
  88200. PiecewiseVisualMapView.prototype._enableHoverLink = function (itemGroup, pieceIndex) {
  88201. var _this = this;
  88202. itemGroup.on('mouseover', function () {
  88203. return onHoverLink('highlight');
  88204. }).on('mouseout', function () {
  88205. return onHoverLink('downplay');
  88206. });
  88207. var onHoverLink = function (method) {
  88208. var visualMapModel = _this.visualMapModel;
  88209. // TODO: TYPE More detailed action types
  88210. visualMapModel.option.hoverLink && _this.api.dispatchAction({
  88211. type: method,
  88212. batch: makeHighDownBatch(visualMapModel.findTargetDataIndices(pieceIndex), visualMapModel)
  88213. });
  88214. };
  88215. };
  88216. PiecewiseVisualMapView.prototype._getItemAlign = function () {
  88217. var visualMapModel = this.visualMapModel;
  88218. var modelOption = visualMapModel.option;
  88219. if (modelOption.orient === 'vertical') {
  88220. return getItemAlign(visualMapModel, this.api, visualMapModel.itemSize);
  88221. } else {
  88222. // horizontal, most case left unless specifying right.
  88223. var align = modelOption.align;
  88224. if (!align || align === 'auto') {
  88225. align = 'left';
  88226. }
  88227. return align;
  88228. }
  88229. };
  88230. PiecewiseVisualMapView.prototype._renderEndsText = function (group, text, itemSize, showLabel, itemAlign) {
  88231. if (!text) {
  88232. return;
  88233. }
  88234. var itemGroup = new Group();
  88235. var textStyleModel = this.visualMapModel.textStyleModel;
  88236. itemGroup.add(new ZRText({
  88237. style: createTextStyle(textStyleModel, {
  88238. x: showLabel ? itemAlign === 'right' ? itemSize[0] : 0 : itemSize[0] / 2,
  88239. y: itemSize[1] / 2,
  88240. verticalAlign: 'middle',
  88241. align: showLabel ? itemAlign : 'center',
  88242. text: text
  88243. })
  88244. }));
  88245. group.add(itemGroup);
  88246. };
  88247. /**
  88248. * @private
  88249. * @return {Object} {peiceList, endsText} The order is the same as screen pixel order.
  88250. */
  88251. PiecewiseVisualMapView.prototype._getViewData = function () {
  88252. var visualMapModel = this.visualMapModel;
  88253. var viewPieceList = map(visualMapModel.getPieceList(), function (piece, index) {
  88254. return {
  88255. piece: piece,
  88256. indexInModelPieceList: index
  88257. };
  88258. });
  88259. var endsText = visualMapModel.get('text');
  88260. // Consider orient and inverse.
  88261. var orient = visualMapModel.get('orient');
  88262. var inverse = visualMapModel.get('inverse');
  88263. // Order of model pieceList is always [low, ..., high]
  88264. if (orient === 'horizontal' ? inverse : !inverse) {
  88265. viewPieceList.reverse();
  88266. }
  88267. // Origin order of endsText is [high, low]
  88268. else if (endsText) {
  88269. endsText = endsText.slice().reverse();
  88270. }
  88271. return {
  88272. viewPieceList: viewPieceList,
  88273. endsText: endsText
  88274. };
  88275. };
  88276. PiecewiseVisualMapView.prototype._createItemSymbol = function (group, representValue, shapeParam, silent) {
  88277. var itemSymbol = createSymbol(
  88278. // symbol will be string
  88279. this.getControllerVisual(representValue, 'symbol'), shapeParam[0], shapeParam[1], shapeParam[2], shapeParam[3],
  88280. // color will be string
  88281. this.getControllerVisual(representValue, 'color'));
  88282. itemSymbol.silent = silent;
  88283. group.add(itemSymbol);
  88284. };
  88285. PiecewiseVisualMapView.prototype._onItemClick = function (piece) {
  88286. var visualMapModel = this.visualMapModel;
  88287. var option = visualMapModel.option;
  88288. var selectedMode = option.selectedMode;
  88289. if (!selectedMode) {
  88290. return;
  88291. }
  88292. var selected = clone(option.selected);
  88293. var newKey = visualMapModel.getSelectedMapKey(piece);
  88294. if (selectedMode === 'single' || selectedMode === true) {
  88295. selected[newKey] = true;
  88296. each(selected, function (o, key) {
  88297. selected[key] = key === newKey;
  88298. });
  88299. } else {
  88300. selected[newKey] = !selected[newKey];
  88301. }
  88302. this.api.dispatchAction({
  88303. type: 'selectDataRange',
  88304. from: this.uid,
  88305. visualMapId: this.visualMapModel.id,
  88306. selected: selected
  88307. });
  88308. };
  88309. PiecewiseVisualMapView.type = 'visualMap.piecewise';
  88310. return PiecewiseVisualMapView;
  88311. }(VisualMapView);
  88312. function install$Q(registers) {
  88313. registers.registerComponentModel(PiecewiseModel);
  88314. registers.registerComponentView(PiecewiseVisualMapView);
  88315. installCommon$1(registers);
  88316. }
  88317. function install$R(registers) {
  88318. use(install$P);
  88319. use(install$Q);
  88320. // Do not install './dataZoomSelect',
  88321. // since it only work for toolbox dataZoom.
  88322. }
  88323. /**
  88324. * [CAVEAT]: the call order of `ThumbnailView['render']` and other
  88325. * `ChartView['render']/ComponentView['render']` is not guaranteed.
  88326. */
  88327. var ThumbnailBridgeImpl = /** @class */function () {
  88328. function ThumbnailBridgeImpl(thumbnailModel) {
  88329. this._thumbnailModel = thumbnailModel;
  88330. }
  88331. ThumbnailBridgeImpl.prototype.reset = function (api) {
  88332. this._renderVersion = api.getMainProcessVersion();
  88333. };
  88334. ThumbnailBridgeImpl.prototype.renderContent = function (opt) {
  88335. var thumbnailView = opt.api.getViewOfComponentModel(this._thumbnailModel);
  88336. if (!thumbnailView) {
  88337. return;
  88338. }
  88339. opt.group.silent = true;
  88340. thumbnailView.renderContent({
  88341. group: opt.group,
  88342. targetTrans: opt.targetTrans,
  88343. z2Range: calcZ2Range(opt.group),
  88344. roamType: opt.roamType,
  88345. viewportRect: opt.viewportRect,
  88346. renderVersion: this._renderVersion
  88347. });
  88348. };
  88349. ThumbnailBridgeImpl.prototype.updateWindow = function (targetTrans, api) {
  88350. var thumbnailView = api.getViewOfComponentModel(this._thumbnailModel);
  88351. if (!thumbnailView) {
  88352. return;
  88353. }
  88354. thumbnailView.updateWindow({
  88355. targetTrans: targetTrans,
  88356. renderVersion: this._renderVersion
  88357. });
  88358. };
  88359. return ThumbnailBridgeImpl;
  88360. }();
  88361. var ThumbnailModel = /** @class */function (_super) {
  88362. __extends(ThumbnailModel, _super);
  88363. function ThumbnailModel() {
  88364. var _this = _super !== null && _super.apply(this, arguments) || this;
  88365. _this.type = ThumbnailModel.type;
  88366. _this.preventAutoZ = true;
  88367. return _this;
  88368. }
  88369. ThumbnailModel.prototype.optionUpdated = function (newCptOption, isInit) {
  88370. this._updateBridge();
  88371. };
  88372. ThumbnailModel.prototype._updateBridge = function () {
  88373. var bridge = this._birdge = this._birdge || new ThumbnailBridgeImpl(this);
  88374. // Clear all, in case of option changed.
  88375. this._target = null;
  88376. this.ecModel.eachSeries(function (series) {
  88377. injectThumbnailBridge(series, null);
  88378. });
  88379. if (this.shouldShow()) {
  88380. var target = this.getTarget();
  88381. // If a component is targeted by more than one thumbnails, simply only the last one works.
  88382. injectThumbnailBridge(target.baseMapProvider, bridge);
  88383. }
  88384. };
  88385. ThumbnailModel.prototype.shouldShow = function () {
  88386. return this.getShallow('show', true);
  88387. };
  88388. ThumbnailModel.prototype.getBridge = function () {
  88389. return this._birdge;
  88390. };
  88391. ThumbnailModel.prototype.getTarget = function () {
  88392. if (this._target) {
  88393. return this._target;
  88394. }
  88395. // Find by `seriesId`/`seriesIndex`.
  88396. var series = this.getReferringComponents('series', {
  88397. useDefault: false,
  88398. enableAll: false,
  88399. enableNone: false
  88400. }).models[0];
  88401. if (series) {
  88402. if (series.subType !== 'graph') {
  88403. series = null;
  88404. if ("development" !== 'production') {
  88405. error("series." + series.subType + " is not supported in thumbnail.", true);
  88406. }
  88407. }
  88408. } else {
  88409. // If no xxxId and xxxIndex specified, find the first series.graph. If other components,
  88410. // such as geo, is supported in future, the default stretagy may be extended.
  88411. series = this.ecModel.queryComponents({
  88412. mainType: 'series',
  88413. subType: 'graph'
  88414. })[0];
  88415. }
  88416. this._target = {
  88417. baseMapProvider: series
  88418. };
  88419. return this._target;
  88420. };
  88421. ThumbnailModel.type = 'thumbnail';
  88422. ThumbnailModel.layoutMode = 'box';
  88423. // All the supported components should be added here.
  88424. ThumbnailModel.dependencies = ['series', 'geo'];
  88425. ThumbnailModel.defaultOption = {
  88426. show: true,
  88427. right: 1,
  88428. bottom: 1,
  88429. height: '25%',
  88430. width: '25%',
  88431. itemStyle: {
  88432. // Use echarts option.backgorundColor by default.
  88433. borderColor: tokens.color.border,
  88434. borderWidth: 2
  88435. },
  88436. windowStyle: {
  88437. borderWidth: 1,
  88438. color: tokens.color.neutral30,
  88439. borderColor: tokens.color.neutral40,
  88440. opacity: 0.3
  88441. },
  88442. z: 10
  88443. };
  88444. return ThumbnailModel;
  88445. }(ComponentModel);
  88446. var ThumbnailView = /** @class */function (_super) {
  88447. __extends(ThumbnailView, _super);
  88448. function ThumbnailView() {
  88449. var _this = _super !== null && _super.apply(this, arguments) || this;
  88450. _this.type = ThumbnailView.type;
  88451. return _this;
  88452. }
  88453. ThumbnailView.prototype.render = function (thumbnailModel, ecModel, api) {
  88454. this._api = api;
  88455. this._model = thumbnailModel;
  88456. if (!this._coordSys) {
  88457. this._coordSys = new View();
  88458. }
  88459. if (!this._isEnabled()) {
  88460. this._clear();
  88461. return;
  88462. }
  88463. this._renderVersion = api.getMainProcessVersion();
  88464. var group = this.group;
  88465. group.removeAll();
  88466. var itemStyleModel = thumbnailModel.getModel('itemStyle');
  88467. var itemStyle = itemStyleModel.getItemStyle();
  88468. if (itemStyle.fill == null) {
  88469. itemStyle.fill = ecModel.get('backgroundColor') || tokens.color.neutral00;
  88470. }
  88471. var refContainer = createBoxLayoutReference(thumbnailModel, api).refContainer;
  88472. var boxRect = getLayoutRect(getBoxLayoutParams(thumbnailModel, true), refContainer);
  88473. var boxBorderWidth = itemStyle.lineWidth || 0;
  88474. var contentRect = this._contentRect = expandOrShrinkRect(boxRect.clone(), boxBorderWidth / 2, true, true);
  88475. var contentGroup = new Group();
  88476. group.add(contentGroup);
  88477. contentGroup.setClipPath(new Rect({
  88478. shape: contentRect.plain()
  88479. }));
  88480. var targetGroup = this._targetGroup = new Group();
  88481. contentGroup.add(targetGroup);
  88482. // Draw border and background and shadow of thumbnail box.
  88483. var borderShape = boxRect.plain();
  88484. borderShape.r = itemStyleModel.getShallow('borderRadius', true);
  88485. group.add(this._bgRect = new Rect({
  88486. style: itemStyle,
  88487. shape: borderShape,
  88488. silent: false,
  88489. cursor: 'grab'
  88490. }));
  88491. var windowStyleModel = thumbnailModel.getModel('windowStyle');
  88492. var windowR = windowStyleModel.getShallow('borderRadius', true);
  88493. contentGroup.add(this._windowRect = new Rect({
  88494. shape: {
  88495. x: 0,
  88496. y: 0,
  88497. width: 0,
  88498. height: 0,
  88499. r: windowR
  88500. },
  88501. style: windowStyleModel.getItemStyle(),
  88502. silent: false,
  88503. cursor: 'grab'
  88504. }));
  88505. this._dealRenderContent();
  88506. this._dealUpdateWindow();
  88507. updateZ$3(thumbnailModel, this);
  88508. };
  88509. /**
  88510. * Can be called asynchronously directly.
  88511. * This method should be idempotent.
  88512. */
  88513. ThumbnailView.prototype.renderContent = function (bridgeRendered) {
  88514. this._bridgeRendered = bridgeRendered;
  88515. if (this._isEnabled()) {
  88516. this._dealRenderContent();
  88517. this._dealUpdateWindow();
  88518. updateZ$3(this._model, this);
  88519. }
  88520. };
  88521. ThumbnailView.prototype._dealRenderContent = function () {
  88522. var bridgeRendered = this._bridgeRendered;
  88523. if (!bridgeRendered || bridgeRendered.renderVersion !== this._renderVersion) {
  88524. return;
  88525. }
  88526. var targetGroup = this._targetGroup;
  88527. var coordSys = this._coordSys;
  88528. var contentRect = this._contentRect;
  88529. targetGroup.removeAll();
  88530. if (!bridgeRendered) {
  88531. return;
  88532. }
  88533. var bridgeGroup = bridgeRendered.group;
  88534. var bridgeRect = bridgeGroup.getBoundingRect();
  88535. targetGroup.add(bridgeGroup);
  88536. this._bgRect.z2 = bridgeRendered.z2Range.min - 10;
  88537. coordSys.setBoundingRect(bridgeRect.x, bridgeRect.y, bridgeRect.width, bridgeRect.height);
  88538. // Use `getLayoutRect` is just to find an approperiate rect in thumbnail.
  88539. var viewRect = getLayoutRect({
  88540. left: 'center',
  88541. top: 'center',
  88542. aspect: bridgeRect.width / bridgeRect.height
  88543. }, contentRect);
  88544. coordSys.setViewRect(viewRect.x, viewRect.y, viewRect.width, viewRect.height);
  88545. bridgeGroup.attr(coordSys.getTransformInfo().raw);
  88546. this._windowRect.z2 = bridgeRendered.z2Range.max + 10;
  88547. this._resetRoamController(bridgeRendered.roamType);
  88548. };
  88549. /**
  88550. * Can be called from action handler directly.
  88551. * This method should be idempotent.
  88552. */
  88553. ThumbnailView.prototype.updateWindow = function (param) {
  88554. var bridgeRendered = this._bridgeRendered;
  88555. if (bridgeRendered && bridgeRendered.renderVersion === param.renderVersion) {
  88556. bridgeRendered.targetTrans = param.targetTrans;
  88557. }
  88558. if (this._isEnabled()) {
  88559. this._dealUpdateWindow();
  88560. }
  88561. };
  88562. ThumbnailView.prototype._dealUpdateWindow = function () {
  88563. var bridgeRendered = this._bridgeRendered;
  88564. if (!bridgeRendered || bridgeRendered.renderVersion !== this._renderVersion) {
  88565. return;
  88566. }
  88567. var invTargetTrans = invert([], bridgeRendered.targetTrans);
  88568. var transTargetToThis = mul$1([], this._coordSys.transform, invTargetTrans);
  88569. this._transThisToTarget = invert([], transTargetToThis);
  88570. var viewportRect = bridgeRendered.viewportRect;
  88571. if (!viewportRect) {
  88572. viewportRect = new BoundingRect(0, 0, this._api.getWidth(), this._api.getHeight());
  88573. } else {
  88574. viewportRect = viewportRect.clone();
  88575. }
  88576. viewportRect.applyTransform(transTargetToThis);
  88577. var windowRect = this._windowRect;
  88578. var r = windowRect.shape.r;
  88579. windowRect.setShape(defaults({
  88580. r: r
  88581. }, viewportRect));
  88582. };
  88583. ThumbnailView.prototype._resetRoamController = function (roamType) {
  88584. var _this = this;
  88585. var api = this._api;
  88586. var roamController = this._roamController;
  88587. if (!roamController) {
  88588. roamController = this._roamController = new RoamController(api.getZr());
  88589. }
  88590. if (!roamType || !this._isEnabled()) {
  88591. roamController.disable();
  88592. return;
  88593. }
  88594. roamController.enable(roamType, {
  88595. api: api,
  88596. zInfo: {
  88597. component: this._model
  88598. },
  88599. triggerInfo: {
  88600. roamTrigger: null,
  88601. isInSelf: function (e, x, y) {
  88602. return _this._contentRect.contain(x, y);
  88603. }
  88604. }
  88605. });
  88606. roamController.off('pan').off('zoom').on('pan', bind(this._onPan, this)).on('zoom', bind(this._onZoom, this));
  88607. };
  88608. ThumbnailView.prototype._onPan = function (event) {
  88609. var trans = this._transThisToTarget;
  88610. if (!this._isEnabled() || !trans) {
  88611. return;
  88612. }
  88613. var oldOffset = applyTransform([], [event.oldX, event.oldY], trans);
  88614. var newOffset = applyTransform([], [event.oldX - event.dx, event.oldY - event.dy], trans);
  88615. this._api.dispatchAction(makeRoamPayload(this._model.getTarget().baseMapProvider, {
  88616. dx: newOffset[0] - oldOffset[0],
  88617. dy: newOffset[1] - oldOffset[1]
  88618. }));
  88619. };
  88620. ThumbnailView.prototype._onZoom = function (event) {
  88621. var trans = this._transThisToTarget;
  88622. if (!this._isEnabled() || !trans) {
  88623. return;
  88624. }
  88625. var offset = applyTransform([], [event.originX, event.originY], trans);
  88626. this._api.dispatchAction(makeRoamPayload(this._model.getTarget().baseMapProvider, {
  88627. zoom: 1 / event.scale,
  88628. originX: offset[0],
  88629. originY: offset[1]
  88630. }));
  88631. };
  88632. /**
  88633. * This method is also responsible for check enable in asynchronous situation,
  88634. * e.g., in event listeners that is supposed to be outdated but not be removed.
  88635. */
  88636. ThumbnailView.prototype._isEnabled = function () {
  88637. var thumbnailModel = this._model;
  88638. if (!thumbnailModel || !thumbnailModel.shouldShow()) {
  88639. return false;
  88640. }
  88641. var baseMapProvider = thumbnailModel.getTarget().baseMapProvider;
  88642. if (!baseMapProvider) {
  88643. return false;
  88644. }
  88645. return true;
  88646. };
  88647. ThumbnailView.prototype._clear = function () {
  88648. this.group.removeAll();
  88649. this._bridgeRendered = null;
  88650. if (this._roamController) {
  88651. this._roamController.disable();
  88652. }
  88653. };
  88654. ThumbnailView.prototype.remove = function () {
  88655. this._clear();
  88656. };
  88657. ThumbnailView.prototype.dispose = function () {
  88658. this._clear();
  88659. };
  88660. ThumbnailView.type = 'thumbnail';
  88661. return ThumbnailView;
  88662. }(ComponentView);
  88663. function makeRoamPayload(baseMapProvider, params) {
  88664. var type = baseMapProvider.mainType === 'series' ? baseMapProvider.subType + "Roam" // e.g. 'graphRoam'
  88665. : baseMapProvider.mainType + "Roam"; // e.g., 'geoRoam'
  88666. var payload = {
  88667. type: type
  88668. };
  88669. payload[baseMapProvider.mainType + "Id"] = baseMapProvider.id;
  88670. extend(payload, params);
  88671. return payload;
  88672. }
  88673. function updateZ$3(thumbnailModel, thumbnailView) {
  88674. var zInfo = retrieveZInfo(thumbnailModel);
  88675. traverseUpdateZ(thumbnailView.group, zInfo.z, zInfo.zlevel);
  88676. }
  88677. function install$S(registers) {
  88678. registers.registerComponentModel(ThumbnailModel);
  88679. registers.registerComponentView(ThumbnailView);
  88680. }
  88681. var DEFAULT_OPTION = {
  88682. label: {
  88683. enabled: true
  88684. },
  88685. decal: {
  88686. show: false
  88687. }
  88688. };
  88689. var inner$n = makeInner();
  88690. var decalPaletteScope = {};
  88691. function ariaVisual(ecModel, api) {
  88692. var ariaModel = ecModel.getModel('aria');
  88693. // See "area enabled" detection code in `GlobalModel.ts`.
  88694. if (!ariaModel.get('enabled')) {
  88695. return;
  88696. }
  88697. var defaultOption = clone(DEFAULT_OPTION);
  88698. merge(defaultOption.label, ecModel.getLocaleModel().get('aria'), false);
  88699. merge(ariaModel.option, defaultOption, false);
  88700. setDecal();
  88701. setLabel();
  88702. function setDecal() {
  88703. var decalModel = ariaModel.getModel('decal');
  88704. var useDecal = decalModel.get('show');
  88705. if (useDecal) {
  88706. // Each type of series use one scope.
  88707. // Pie and funnel are using different scopes.
  88708. var paletteScopeGroupByType_1 = createHashMap();
  88709. ecModel.eachSeries(function (seriesModel) {
  88710. if (seriesModel.isColorBySeries()) {
  88711. return;
  88712. }
  88713. var decalScope = paletteScopeGroupByType_1.get(seriesModel.type);
  88714. if (!decalScope) {
  88715. decalScope = {};
  88716. paletteScopeGroupByType_1.set(seriesModel.type, decalScope);
  88717. }
  88718. inner$n(seriesModel).scope = decalScope;
  88719. });
  88720. ecModel.eachRawSeries(function (seriesModel) {
  88721. if (ecModel.isSeriesFiltered(seriesModel)) {
  88722. return;
  88723. }
  88724. if (isFunction(seriesModel.enableAriaDecal)) {
  88725. // Let series define how to use decal palette on data
  88726. seriesModel.enableAriaDecal();
  88727. return;
  88728. }
  88729. var data = seriesModel.getData();
  88730. if (!seriesModel.isColorBySeries()) {
  88731. var dataAll_1 = seriesModel.getRawData();
  88732. var idxMap_1 = {};
  88733. var decalScope_1 = inner$n(seriesModel).scope;
  88734. data.each(function (idx) {
  88735. var rawIdx = data.getRawIndex(idx);
  88736. idxMap_1[rawIdx] = idx;
  88737. });
  88738. var dataCount_1 = dataAll_1.count();
  88739. dataAll_1.each(function (rawIdx) {
  88740. var idx = idxMap_1[rawIdx];
  88741. var name = dataAll_1.getName(rawIdx) || rawIdx + '';
  88742. var paletteDecal = getDecalFromPalette(seriesModel.ecModel, name, decalScope_1, dataCount_1);
  88743. var specifiedDecal = data.getItemVisual(idx, 'decal');
  88744. data.setItemVisual(idx, 'decal', mergeDecal(specifiedDecal, paletteDecal));
  88745. });
  88746. } else {
  88747. var paletteDecal = getDecalFromPalette(seriesModel.ecModel, seriesModel.name, decalPaletteScope, ecModel.getSeriesCount());
  88748. var specifiedDecal = data.getVisual('decal');
  88749. data.setVisual('decal', mergeDecal(specifiedDecal, paletteDecal));
  88750. }
  88751. function mergeDecal(specifiedDecal, paletteDecal) {
  88752. // Merge decal from palette to decal from itemStyle.
  88753. // User do not need to specify all of the decal props.
  88754. var resultDecal = specifiedDecal ? extend(extend({}, paletteDecal), specifiedDecal) : paletteDecal;
  88755. resultDecal.dirty = true;
  88756. return resultDecal;
  88757. }
  88758. });
  88759. }
  88760. }
  88761. function setLabel() {
  88762. var dom = api.getZr().dom;
  88763. // TODO: support for SSR
  88764. if (!dom) {
  88765. return;
  88766. }
  88767. var labelLocale = ecModel.getLocaleModel().get('aria');
  88768. var labelModel = ariaModel.getModel('label');
  88769. labelModel.option = defaults(labelModel.option, labelLocale);
  88770. if (!labelModel.get('enabled')) {
  88771. return;
  88772. }
  88773. dom.setAttribute('role', 'img');
  88774. if (labelModel.get('description')) {
  88775. dom.setAttribute('aria-label', labelModel.get('description'));
  88776. return;
  88777. }
  88778. var seriesCnt = ecModel.getSeriesCount();
  88779. var maxDataCnt = labelModel.get(['data', 'maxCount']) || 10;
  88780. var maxSeriesCnt = labelModel.get(['series', 'maxCount']) || 10;
  88781. var displaySeriesCnt = Math.min(seriesCnt, maxSeriesCnt);
  88782. var ariaLabel;
  88783. if (seriesCnt < 1) {
  88784. // No series, no aria label
  88785. return;
  88786. } else {
  88787. var title = getTitle();
  88788. if (title) {
  88789. var withTitle = labelModel.get(['general', 'withTitle']);
  88790. ariaLabel = replace(withTitle, {
  88791. title: title
  88792. });
  88793. } else {
  88794. ariaLabel = labelModel.get(['general', 'withoutTitle']);
  88795. }
  88796. var seriesLabels_1 = [];
  88797. var prefix = seriesCnt > 1 ? labelModel.get(['series', 'multiple', 'prefix']) : labelModel.get(['series', 'single', 'prefix']);
  88798. ariaLabel += replace(prefix, {
  88799. seriesCount: seriesCnt
  88800. });
  88801. ecModel.eachSeries(function (seriesModel, idx) {
  88802. if (idx < displaySeriesCnt) {
  88803. var seriesLabel = void 0;
  88804. var seriesName = seriesModel.get('name');
  88805. var withName = seriesName ? 'withName' : 'withoutName';
  88806. seriesLabel = seriesCnt > 1 ? labelModel.get(['series', 'multiple', withName]) : labelModel.get(['series', 'single', withName]);
  88807. seriesLabel = replace(seriesLabel, {
  88808. seriesId: seriesModel.seriesIndex,
  88809. seriesName: seriesModel.get('name'),
  88810. seriesType: getSeriesTypeName(seriesModel.subType)
  88811. });
  88812. var data = seriesModel.getData();
  88813. if (data.count() > maxDataCnt) {
  88814. // Show part of data
  88815. var partialLabel = labelModel.get(['data', 'partialData']);
  88816. seriesLabel += replace(partialLabel, {
  88817. displayCnt: maxDataCnt
  88818. });
  88819. } else {
  88820. seriesLabel += labelModel.get(['data', 'allData']);
  88821. }
  88822. var middleSeparator_1 = labelModel.get(['data', 'separator', 'middle']);
  88823. var endSeparator_1 = labelModel.get(['data', 'separator', 'end']);
  88824. var excludeDimensionId_1 = labelModel.get(['data', 'excludeDimensionId']);
  88825. var dataLabels = [];
  88826. for (var i = 0; i < data.count(); i++) {
  88827. if (i < maxDataCnt) {
  88828. var name_1 = data.getName(i);
  88829. var value = !excludeDimensionId_1 ? data.getValues(i) : filter(data.getValues(i), function (v, j) {
  88830. return indexOf(excludeDimensionId_1, j) === -1;
  88831. });
  88832. var dataLabel = labelModel.get(['data', name_1 ? 'withName' : 'withoutName']);
  88833. dataLabels.push(replace(dataLabel, {
  88834. name: name_1,
  88835. value: value.join(middleSeparator_1)
  88836. }));
  88837. }
  88838. }
  88839. seriesLabel += dataLabels.join(middleSeparator_1) + endSeparator_1;
  88840. seriesLabels_1.push(seriesLabel);
  88841. }
  88842. });
  88843. var separatorModel = labelModel.getModel(['series', 'multiple', 'separator']);
  88844. var middleSeparator = separatorModel.get('middle');
  88845. var endSeparator = separatorModel.get('end');
  88846. ariaLabel += seriesLabels_1.join(middleSeparator) + endSeparator;
  88847. dom.setAttribute('aria-label', ariaLabel);
  88848. }
  88849. }
  88850. function replace(str, keyValues) {
  88851. if (!isString(str)) {
  88852. return str;
  88853. }
  88854. var result = str;
  88855. each(keyValues, function (value, key) {
  88856. result = result.replace(new RegExp('\\{\\s*' + key + '\\s*\\}', 'g'), value);
  88857. });
  88858. return result;
  88859. }
  88860. function getTitle() {
  88861. var title = ecModel.get('title');
  88862. if (title && title.length) {
  88863. title = title[0];
  88864. }
  88865. return title && title.text;
  88866. }
  88867. function getSeriesTypeName(type) {
  88868. var typeNames = ecModel.getLocaleModel().get(['series', 'typeNames']);
  88869. return typeNames[type] || typeNames.chart;
  88870. }
  88871. }
  88872. function ariaPreprocessor(option) {
  88873. if (!option || !option.aria) {
  88874. return;
  88875. }
  88876. var aria = option.aria;
  88877. // aria.show is deprecated and should use aria.enabled instead
  88878. if (aria.show != null) {
  88879. aria.enabled = aria.show;
  88880. }
  88881. aria.label = aria.label || {};
  88882. // move description, general, series, data to be under aria.label
  88883. each(['description', 'general', 'series', 'data'], function (name) {
  88884. if (aria[name] != null) {
  88885. aria.label[name] = aria[name];
  88886. }
  88887. });
  88888. }
  88889. function install$T(registers) {
  88890. registers.registerPreprocessor(ariaPreprocessor);
  88891. registers.registerVisual(registers.PRIORITY.VISUAL.ARIA, ariaVisual);
  88892. }
  88893. var RELATIONAL_EXPRESSION_OP_ALIAS_MAP = {
  88894. value: 'eq',
  88895. // PENDING: not good for literal semantic?
  88896. '<': 'lt',
  88897. '<=': 'lte',
  88898. '>': 'gt',
  88899. '>=': 'gte',
  88900. '=': 'eq',
  88901. '!=': 'ne',
  88902. '<>': 'ne'
  88903. // Might be misleading for sake of the difference between '==' and '===',
  88904. // so don't support them.
  88905. // '==': 'eq',
  88906. // '===': 'seq',
  88907. // '!==': 'sne'
  88908. // PENDING: Whether support some common alias "ge", "le", "neq"?
  88909. // ge: 'gte',
  88910. // le: 'lte',
  88911. // neq: 'ne',
  88912. };
  88913. // type RelationalExpressionOpEvaluate = (tarVal: unknown, condVal: unknown) => boolean;
  88914. var RegExpEvaluator = /** @class */function () {
  88915. function RegExpEvaluator(rVal) {
  88916. // Support condVal: RegExp | string
  88917. var condValue = this._condVal = isString(rVal) ? new RegExp(rVal) : isRegExp(rVal) ? rVal : null;
  88918. if (condValue == null) {
  88919. var errMsg = '';
  88920. if ("development" !== 'production') {
  88921. errMsg = makePrintable('Illegal regexp', rVal, 'in');
  88922. }
  88923. throwError(errMsg);
  88924. }
  88925. }
  88926. RegExpEvaluator.prototype.evaluate = function (lVal) {
  88927. var type = typeof lVal;
  88928. return isString(type) ? this._condVal.test(lVal) : isNumber(type) ? this._condVal.test(lVal + '') : false;
  88929. };
  88930. return RegExpEvaluator;
  88931. }();
  88932. var ConstConditionInternal = /** @class */function () {
  88933. function ConstConditionInternal() {}
  88934. ConstConditionInternal.prototype.evaluate = function () {
  88935. return this.value;
  88936. };
  88937. return ConstConditionInternal;
  88938. }();
  88939. var AndConditionInternal = /** @class */function () {
  88940. function AndConditionInternal() {}
  88941. AndConditionInternal.prototype.evaluate = function () {
  88942. var children = this.children;
  88943. for (var i = 0; i < children.length; i++) {
  88944. if (!children[i].evaluate()) {
  88945. return false;
  88946. }
  88947. }
  88948. return true;
  88949. };
  88950. return AndConditionInternal;
  88951. }();
  88952. var OrConditionInternal = /** @class */function () {
  88953. function OrConditionInternal() {}
  88954. OrConditionInternal.prototype.evaluate = function () {
  88955. var children = this.children;
  88956. for (var i = 0; i < children.length; i++) {
  88957. if (children[i].evaluate()) {
  88958. return true;
  88959. }
  88960. }
  88961. return false;
  88962. };
  88963. return OrConditionInternal;
  88964. }();
  88965. var NotConditionInternal = /** @class */function () {
  88966. function NotConditionInternal() {}
  88967. NotConditionInternal.prototype.evaluate = function () {
  88968. return !this.child.evaluate();
  88969. };
  88970. return NotConditionInternal;
  88971. }();
  88972. var RelationalConditionInternal = /** @class */function () {
  88973. function RelationalConditionInternal() {}
  88974. RelationalConditionInternal.prototype.evaluate = function () {
  88975. var needParse = !!this.valueParser;
  88976. // Call getValue with no `this`.
  88977. var getValue = this.getValue;
  88978. var tarValRaw = getValue(this.valueGetterParam);
  88979. var tarValParsed = needParse ? this.valueParser(tarValRaw) : null;
  88980. // Relational cond follow "and" logic internally.
  88981. for (var i = 0; i < this.subCondList.length; i++) {
  88982. if (!this.subCondList[i].evaluate(needParse ? tarValParsed : tarValRaw)) {
  88983. return false;
  88984. }
  88985. }
  88986. return true;
  88987. };
  88988. return RelationalConditionInternal;
  88989. }();
  88990. function parseOption(exprOption, getters) {
  88991. if (exprOption === true || exprOption === false) {
  88992. var cond = new ConstConditionInternal();
  88993. cond.value = exprOption;
  88994. return cond;
  88995. }
  88996. var errMsg = '';
  88997. if (!isObjectNotArray(exprOption)) {
  88998. if ("development" !== 'production') {
  88999. errMsg = makePrintable('Illegal config. Expect a plain object but actually', exprOption);
  89000. }
  89001. throwError(errMsg);
  89002. }
  89003. if (exprOption.and) {
  89004. return parseAndOrOption('and', exprOption, getters);
  89005. } else if (exprOption.or) {
  89006. return parseAndOrOption('or', exprOption, getters);
  89007. } else if (exprOption.not) {
  89008. return parseNotOption(exprOption, getters);
  89009. }
  89010. return parseRelationalOption(exprOption, getters);
  89011. }
  89012. function parseAndOrOption(op, exprOption, getters) {
  89013. var subOptionArr = exprOption[op];
  89014. var errMsg = '';
  89015. if ("development" !== 'production') {
  89016. errMsg = makePrintable('"and"/"or" condition should only be `' + op + ': [...]` and must not be empty array.', 'Illegal condition:', exprOption);
  89017. }
  89018. if (!isArray(subOptionArr)) {
  89019. throwError(errMsg);
  89020. }
  89021. if (!subOptionArr.length) {
  89022. throwError(errMsg);
  89023. }
  89024. var cond = op === 'and' ? new AndConditionInternal() : new OrConditionInternal();
  89025. cond.children = map(subOptionArr, function (subOption) {
  89026. return parseOption(subOption, getters);
  89027. });
  89028. if (!cond.children.length) {
  89029. throwError(errMsg);
  89030. }
  89031. return cond;
  89032. }
  89033. function parseNotOption(exprOption, getters) {
  89034. var subOption = exprOption.not;
  89035. var errMsg = '';
  89036. if ("development" !== 'production') {
  89037. errMsg = makePrintable('"not" condition should only be `not: {}`.', 'Illegal condition:', exprOption);
  89038. }
  89039. if (!isObjectNotArray(subOption)) {
  89040. throwError(errMsg);
  89041. }
  89042. var cond = new NotConditionInternal();
  89043. cond.child = parseOption(subOption, getters);
  89044. if (!cond.child) {
  89045. throwError(errMsg);
  89046. }
  89047. return cond;
  89048. }
  89049. function parseRelationalOption(exprOption, getters) {
  89050. var errMsg = '';
  89051. var valueGetterParam = getters.prepareGetValue(exprOption);
  89052. var subCondList = [];
  89053. var exprKeys = keys(exprOption);
  89054. var parserName = exprOption.parser;
  89055. var valueParser = parserName ? getRawValueParser(parserName) : null;
  89056. for (var i = 0; i < exprKeys.length; i++) {
  89057. var keyRaw = exprKeys[i];
  89058. if (keyRaw === 'parser' || getters.valueGetterAttrMap.get(keyRaw)) {
  89059. continue;
  89060. }
  89061. var op = hasOwn(RELATIONAL_EXPRESSION_OP_ALIAS_MAP, keyRaw) ? RELATIONAL_EXPRESSION_OP_ALIAS_MAP[keyRaw] : keyRaw;
  89062. var condValueRaw = exprOption[keyRaw];
  89063. var condValueParsed = valueParser ? valueParser(condValueRaw) : condValueRaw;
  89064. var evaluator = createFilterComparator(op, condValueParsed) || op === 'reg' && new RegExpEvaluator(condValueParsed);
  89065. if (!evaluator) {
  89066. if ("development" !== 'production') {
  89067. errMsg = makePrintable('Illegal relational operation: "' + keyRaw + '" in condition:', exprOption);
  89068. }
  89069. throwError(errMsg);
  89070. }
  89071. subCondList.push(evaluator);
  89072. }
  89073. if (!subCondList.length) {
  89074. if ("development" !== 'production') {
  89075. errMsg = makePrintable('Relational condition must have at least one operator.', 'Illegal condition:', exprOption);
  89076. }
  89077. // No relational operator always disabled in case of dangers result.
  89078. throwError(errMsg);
  89079. }
  89080. var cond = new RelationalConditionInternal();
  89081. cond.valueGetterParam = valueGetterParam;
  89082. cond.valueParser = valueParser;
  89083. cond.getValue = getters.getValue;
  89084. cond.subCondList = subCondList;
  89085. return cond;
  89086. }
  89087. function isObjectNotArray(val) {
  89088. return isObject(val) && !isArrayLike(val);
  89089. }
  89090. var ConditionalExpressionParsed = /** @class */function () {
  89091. function ConditionalExpressionParsed(exprOption, getters) {
  89092. this._cond = parseOption(exprOption, getters);
  89093. }
  89094. ConditionalExpressionParsed.prototype.evaluate = function () {
  89095. return this._cond.evaluate();
  89096. };
  89097. return ConditionalExpressionParsed;
  89098. }();
  89099. function parseConditionalExpression(exprOption, getters) {
  89100. return new ConditionalExpressionParsed(exprOption, getters);
  89101. }
  89102. var filterTransform = {
  89103. type: 'echarts:filter',
  89104. // PENDING: enhance to filter by index rather than create new data
  89105. transform: function (params) {
  89106. // [Caveat] Fail-Fast:
  89107. // Do not return the whole dataset unless user config indicates it explicitly.
  89108. // For example, if no condition is specified by mistake, returning an empty result
  89109. // is better than returning the entire raw source for the user to find the mistake.
  89110. var upstream = params.upstream;
  89111. var rawItem;
  89112. var condition = parseConditionalExpression(params.config, {
  89113. valueGetterAttrMap: createHashMap({
  89114. dimension: true
  89115. }),
  89116. prepareGetValue: function (exprOption) {
  89117. var errMsg = '';
  89118. var dimLoose = exprOption.dimension;
  89119. if (!hasOwn(exprOption, 'dimension')) {
  89120. if ("development" !== 'production') {
  89121. errMsg = makePrintable('Relation condition must has prop "dimension" specified.', 'Illegal condition:', exprOption);
  89122. }
  89123. throwError(errMsg);
  89124. }
  89125. var dimInfo = upstream.getDimensionInfo(dimLoose);
  89126. if (!dimInfo) {
  89127. if ("development" !== 'production') {
  89128. errMsg = makePrintable('Can not find dimension info via: ' + dimLoose + '.\n', 'Existing dimensions: ', upstream.cloneAllDimensionInfo(), '.\n', 'Illegal condition:', exprOption, '.\n');
  89129. }
  89130. throwError(errMsg);
  89131. }
  89132. return {
  89133. dimIdx: dimInfo.index
  89134. };
  89135. },
  89136. getValue: function (param) {
  89137. return upstream.retrieveValueFromItem(rawItem, param.dimIdx);
  89138. }
  89139. });
  89140. var resultData = [];
  89141. for (var i = 0, len = upstream.count(); i < len; i++) {
  89142. rawItem = upstream.getRawDataItem(i);
  89143. if (condition.evaluate()) {
  89144. resultData.push(rawItem);
  89145. }
  89146. }
  89147. return {
  89148. data: resultData
  89149. };
  89150. }
  89151. };
  89152. var sampleLog = '';
  89153. if ("development" !== 'production') {
  89154. sampleLog = ['Valid config is like:', '{ dimension: "age", order: "asc" }', 'or [{ dimension: "age", order: "asc"], { dimension: "date", order: "desc" }]'].join(' ');
  89155. }
  89156. var sortTransform = {
  89157. type: 'echarts:sort',
  89158. transform: function (params) {
  89159. var upstream = params.upstream;
  89160. var config = params.config;
  89161. var errMsg = '';
  89162. // Normalize
  89163. // const orderExprList: OrderExpression[] = isArray(config[0])
  89164. // ? config as OrderExpression[]
  89165. // : [config as OrderExpression];
  89166. var orderExprList = normalizeToArray(config);
  89167. if (!orderExprList.length) {
  89168. if ("development" !== 'production') {
  89169. errMsg = 'Empty `config` in sort transform.';
  89170. }
  89171. throwError(errMsg);
  89172. }
  89173. var orderDefList = [];
  89174. each(orderExprList, function (orderExpr) {
  89175. var dimLoose = orderExpr.dimension;
  89176. var order = orderExpr.order;
  89177. var parserName = orderExpr.parser;
  89178. var incomparable = orderExpr.incomparable;
  89179. if (dimLoose == null) {
  89180. if ("development" !== 'production') {
  89181. errMsg = 'Sort transform config must has "dimension" specified.' + sampleLog;
  89182. }
  89183. throwError(errMsg);
  89184. }
  89185. if (order !== 'asc' && order !== 'desc') {
  89186. if ("development" !== 'production') {
  89187. errMsg = 'Sort transform config must has "order" specified.' + sampleLog;
  89188. }
  89189. throwError(errMsg);
  89190. }
  89191. if (incomparable && incomparable !== 'min' && incomparable !== 'max') {
  89192. var errMsg_1 = '';
  89193. if ("development" !== 'production') {
  89194. errMsg_1 = 'incomparable must be "min" or "max" rather than "' + incomparable + '".';
  89195. }
  89196. throwError(errMsg_1);
  89197. }
  89198. if (order !== 'asc' && order !== 'desc') {
  89199. var errMsg_2 = '';
  89200. if ("development" !== 'production') {
  89201. errMsg_2 = 'order must be "asc" or "desc" rather than "' + order + '".';
  89202. }
  89203. throwError(errMsg_2);
  89204. }
  89205. var dimInfo = upstream.getDimensionInfo(dimLoose);
  89206. if (!dimInfo) {
  89207. if ("development" !== 'production') {
  89208. errMsg = makePrintable('Can not find dimension info via: ' + dimLoose + '.\n', 'Existing dimensions: ', upstream.cloneAllDimensionInfo(), '.\n', 'Illegal config:', orderExpr, '.\n');
  89209. }
  89210. throwError(errMsg);
  89211. }
  89212. var parser = parserName ? getRawValueParser(parserName) : null;
  89213. if (parserName && !parser) {
  89214. if ("development" !== 'production') {
  89215. errMsg = makePrintable('Invalid parser name ' + parserName + '.\n', 'Illegal config:', orderExpr, '.\n');
  89216. }
  89217. throwError(errMsg);
  89218. }
  89219. orderDefList.push({
  89220. dimIdx: dimInfo.index,
  89221. parser: parser,
  89222. comparator: new SortOrderComparator(order, incomparable)
  89223. });
  89224. });
  89225. // TODO: support it?
  89226. var sourceFormat = upstream.sourceFormat;
  89227. if (sourceFormat !== SOURCE_FORMAT_ARRAY_ROWS && sourceFormat !== SOURCE_FORMAT_OBJECT_ROWS) {
  89228. if ("development" !== 'production') {
  89229. errMsg = 'sourceFormat "' + sourceFormat + '" is not supported yet';
  89230. }
  89231. throwError(errMsg);
  89232. }
  89233. // Other upstream format are all array.
  89234. var resultData = [];
  89235. for (var i = 0, len = upstream.count(); i < len; i++) {
  89236. resultData.push(upstream.getRawDataItem(i));
  89237. }
  89238. resultData.sort(function (item0, item1) {
  89239. for (var i = 0; i < orderDefList.length; i++) {
  89240. var orderDef = orderDefList[i];
  89241. var val0 = upstream.retrieveValueFromItem(item0, orderDef.dimIdx);
  89242. var val1 = upstream.retrieveValueFromItem(item1, orderDef.dimIdx);
  89243. if (orderDef.parser) {
  89244. val0 = orderDef.parser(val0);
  89245. val1 = orderDef.parser(val1);
  89246. }
  89247. var result = orderDef.comparator.evaluate(val0, val1);
  89248. if (result !== 0) {
  89249. return result;
  89250. }
  89251. }
  89252. return 0;
  89253. });
  89254. return {
  89255. data: resultData
  89256. };
  89257. }
  89258. };
  89259. function install$U(registers) {
  89260. registers.registerTransform(filterTransform);
  89261. registers.registerTransform(sortTransform);
  89262. }
  89263. var DatasetModel = /** @class */function (_super) {
  89264. __extends(DatasetModel, _super);
  89265. function DatasetModel() {
  89266. var _this = _super !== null && _super.apply(this, arguments) || this;
  89267. _this.type = 'dataset';
  89268. return _this;
  89269. }
  89270. DatasetModel.prototype.init = function (option, parentModel, ecModel) {
  89271. _super.prototype.init.call(this, option, parentModel, ecModel);
  89272. this._sourceManager = new SourceManager(this);
  89273. disableTransformOptionMerge(this);
  89274. };
  89275. DatasetModel.prototype.mergeOption = function (newOption, ecModel) {
  89276. _super.prototype.mergeOption.call(this, newOption, ecModel);
  89277. disableTransformOptionMerge(this);
  89278. };
  89279. DatasetModel.prototype.optionUpdated = function () {
  89280. this._sourceManager.dirty();
  89281. };
  89282. DatasetModel.prototype.getSourceManager = function () {
  89283. return this._sourceManager;
  89284. };
  89285. DatasetModel.type = 'dataset';
  89286. DatasetModel.defaultOption = {
  89287. seriesLayoutBy: SERIES_LAYOUT_BY_COLUMN
  89288. };
  89289. return DatasetModel;
  89290. }(ComponentModel);
  89291. var DatasetView = /** @class */function (_super) {
  89292. __extends(DatasetView, _super);
  89293. function DatasetView() {
  89294. var _this = _super !== null && _super.apply(this, arguments) || this;
  89295. _this.type = 'dataset';
  89296. return _this;
  89297. }
  89298. DatasetView.type = 'dataset';
  89299. return DatasetView;
  89300. }(ComponentView);
  89301. function install$V(registers) {
  89302. registers.registerComponentModel(DatasetModel);
  89303. registers.registerComponentView(DatasetView);
  89304. }
  89305. var CMD$4 = PathProxy.CMD;
  89306. function aroundEqual(a, b) {
  89307. return Math.abs(a - b) < 1e-5;
  89308. }
  89309. function pathToBezierCurves(path) {
  89310. var data = path.data;
  89311. var len = path.len();
  89312. var bezierArrayGroups = [];
  89313. var currentSubpath;
  89314. var xi = 0;
  89315. var yi = 0;
  89316. var x0 = 0;
  89317. var y0 = 0;
  89318. function createNewSubpath(x, y) {
  89319. if (currentSubpath && currentSubpath.length > 2) {
  89320. bezierArrayGroups.push(currentSubpath);
  89321. }
  89322. currentSubpath = [x, y];
  89323. }
  89324. function addLine(x0, y0, x1, y1) {
  89325. if (!(aroundEqual(x0, x1) && aroundEqual(y0, y1))) {
  89326. currentSubpath.push(x0, y0, x1, y1, x1, y1);
  89327. }
  89328. }
  89329. function addArc(startAngle, endAngle, cx, cy, rx, ry) {
  89330. var delta = Math.abs(endAngle - startAngle);
  89331. var len = Math.tan(delta / 4) * 4 / 3;
  89332. var dir = endAngle < startAngle ? -1 : 1;
  89333. var c1 = Math.cos(startAngle);
  89334. var s1 = Math.sin(startAngle);
  89335. var c2 = Math.cos(endAngle);
  89336. var s2 = Math.sin(endAngle);
  89337. var x1 = c1 * rx + cx;
  89338. var y1 = s1 * ry + cy;
  89339. var x4 = c2 * rx + cx;
  89340. var y4 = s2 * ry + cy;
  89341. var hx = rx * len * dir;
  89342. var hy = ry * len * dir;
  89343. currentSubpath.push(x1 - hx * s1, y1 + hy * c1, x4 + hx * s2, y4 - hy * c2, x4, y4);
  89344. }
  89345. var x1;
  89346. var y1;
  89347. var x2;
  89348. var y2;
  89349. for (var i = 0; i < len;) {
  89350. var cmd = data[i++];
  89351. var isFirst = i === 1;
  89352. if (isFirst) {
  89353. xi = data[i];
  89354. yi = data[i + 1];
  89355. x0 = xi;
  89356. y0 = yi;
  89357. if (cmd === CMD$4.L || cmd === CMD$4.C || cmd === CMD$4.Q) {
  89358. currentSubpath = [x0, y0];
  89359. }
  89360. }
  89361. switch (cmd) {
  89362. case CMD$4.M:
  89363. xi = x0 = data[i++];
  89364. yi = y0 = data[i++];
  89365. createNewSubpath(x0, y0);
  89366. break;
  89367. case CMD$4.L:
  89368. x1 = data[i++];
  89369. y1 = data[i++];
  89370. addLine(xi, yi, x1, y1);
  89371. xi = x1;
  89372. yi = y1;
  89373. break;
  89374. case CMD$4.C:
  89375. currentSubpath.push(data[i++], data[i++], data[i++], data[i++], xi = data[i++], yi = data[i++]);
  89376. break;
  89377. case CMD$4.Q:
  89378. x1 = data[i++];
  89379. y1 = data[i++];
  89380. x2 = data[i++];
  89381. y2 = data[i++];
  89382. currentSubpath.push(xi + 2 / 3 * (x1 - xi), yi + 2 / 3 * (y1 - yi), x2 + 2 / 3 * (x1 - x2), y2 + 2 / 3 * (y1 - y2), x2, y2);
  89383. xi = x2;
  89384. yi = y2;
  89385. break;
  89386. case CMD$4.A:
  89387. var cx = data[i++];
  89388. var cy = data[i++];
  89389. var rx = data[i++];
  89390. var ry = data[i++];
  89391. var startAngle = data[i++];
  89392. var endAngle = data[i++] + startAngle;
  89393. i += 1;
  89394. var anticlockwise = !data[i++];
  89395. x1 = Math.cos(startAngle) * rx + cx;
  89396. y1 = Math.sin(startAngle) * ry + cy;
  89397. if (isFirst) {
  89398. x0 = x1;
  89399. y0 = y1;
  89400. createNewSubpath(x0, y0);
  89401. }
  89402. else {
  89403. addLine(xi, yi, x1, y1);
  89404. }
  89405. xi = Math.cos(endAngle) * rx + cx;
  89406. yi = Math.sin(endAngle) * ry + cy;
  89407. var step = (anticlockwise ? -1 : 1) * Math.PI / 2;
  89408. for (var angle = startAngle; anticlockwise ? angle > endAngle : angle < endAngle; angle += step) {
  89409. var nextAngle = anticlockwise ? Math.max(angle + step, endAngle)
  89410. : Math.min(angle + step, endAngle);
  89411. addArc(angle, nextAngle, cx, cy, rx, ry);
  89412. }
  89413. break;
  89414. case CMD$4.R:
  89415. x0 = xi = data[i++];
  89416. y0 = yi = data[i++];
  89417. x1 = x0 + data[i++];
  89418. y1 = y0 + data[i++];
  89419. createNewSubpath(x1, y0);
  89420. addLine(x1, y0, x1, y1);
  89421. addLine(x1, y1, x0, y1);
  89422. addLine(x0, y1, x0, y0);
  89423. addLine(x0, y0, x1, y0);
  89424. break;
  89425. case CMD$4.Z:
  89426. currentSubpath && addLine(xi, yi, x0, y0);
  89427. xi = x0;
  89428. yi = y0;
  89429. break;
  89430. }
  89431. }
  89432. if (currentSubpath && currentSubpath.length > 2) {
  89433. bezierArrayGroups.push(currentSubpath);
  89434. }
  89435. return bezierArrayGroups;
  89436. }
  89437. function adpativeBezier(x0, y0, x1, y1, x2, y2, x3, y3, out, scale) {
  89438. if (aroundEqual(x0, x1) && aroundEqual(y0, y1) && aroundEqual(x2, x3) && aroundEqual(y2, y3)) {
  89439. out.push(x3, y3);
  89440. return;
  89441. }
  89442. var PIXEL_DISTANCE = 2 / scale;
  89443. var PIXEL_DISTANCE_SQR = PIXEL_DISTANCE * PIXEL_DISTANCE;
  89444. var dx = x3 - x0;
  89445. var dy = y3 - y0;
  89446. var d = Math.sqrt(dx * dx + dy * dy);
  89447. dx /= d;
  89448. dy /= d;
  89449. var dx1 = x1 - x0;
  89450. var dy1 = y1 - y0;
  89451. var dx2 = x2 - x3;
  89452. var dy2 = y2 - y3;
  89453. var cp1LenSqr = dx1 * dx1 + dy1 * dy1;
  89454. var cp2LenSqr = dx2 * dx2 + dy2 * dy2;
  89455. if (cp1LenSqr < PIXEL_DISTANCE_SQR && cp2LenSqr < PIXEL_DISTANCE_SQR) {
  89456. out.push(x3, y3);
  89457. return;
  89458. }
  89459. var projLen1 = dx * dx1 + dy * dy1;
  89460. var projLen2 = -dx * dx2 - dy * dy2;
  89461. var d1Sqr = cp1LenSqr - projLen1 * projLen1;
  89462. var d2Sqr = cp2LenSqr - projLen2 * projLen2;
  89463. if (d1Sqr < PIXEL_DISTANCE_SQR && projLen1 >= 0
  89464. && d2Sqr < PIXEL_DISTANCE_SQR && projLen2 >= 0) {
  89465. out.push(x3, y3);
  89466. return;
  89467. }
  89468. var tmpSegX = [];
  89469. var tmpSegY = [];
  89470. cubicSubdivide(x0, x1, x2, x3, 0.5, tmpSegX);
  89471. cubicSubdivide(y0, y1, y2, y3, 0.5, tmpSegY);
  89472. adpativeBezier(tmpSegX[0], tmpSegY[0], tmpSegX[1], tmpSegY[1], tmpSegX[2], tmpSegY[2], tmpSegX[3], tmpSegY[3], out, scale);
  89473. adpativeBezier(tmpSegX[4], tmpSegY[4], tmpSegX[5], tmpSegY[5], tmpSegX[6], tmpSegY[6], tmpSegX[7], tmpSegY[7], out, scale);
  89474. }
  89475. function pathToPolygons(path, scale) {
  89476. var bezierArrayGroups = pathToBezierCurves(path);
  89477. var polygons = [];
  89478. scale = scale || 1;
  89479. for (var i = 0; i < bezierArrayGroups.length; i++) {
  89480. var beziers = bezierArrayGroups[i];
  89481. var polygon = [];
  89482. var x0 = beziers[0];
  89483. var y0 = beziers[1];
  89484. polygon.push(x0, y0);
  89485. for (var k = 2; k < beziers.length;) {
  89486. var x1 = beziers[k++];
  89487. var y1 = beziers[k++];
  89488. var x2 = beziers[k++];
  89489. var y2 = beziers[k++];
  89490. var x3 = beziers[k++];
  89491. var y3 = beziers[k++];
  89492. adpativeBezier(x0, y0, x1, y1, x2, y2, x3, y3, polygon, scale);
  89493. x0 = x3;
  89494. y0 = y3;
  89495. }
  89496. polygons.push(polygon);
  89497. }
  89498. return polygons;
  89499. }
  89500. function getDividingGrids(dimSize, rowDim, count) {
  89501. var rowSize = dimSize[rowDim];
  89502. var columnSize = dimSize[1 - rowDim];
  89503. var ratio = Math.abs(rowSize / columnSize);
  89504. var rowCount = Math.ceil(Math.sqrt(ratio * count));
  89505. var columnCount = Math.floor(count / rowCount);
  89506. if (columnCount === 0) {
  89507. columnCount = 1;
  89508. rowCount = count;
  89509. }
  89510. var grids = [];
  89511. for (var i = 0; i < rowCount; i++) {
  89512. grids.push(columnCount);
  89513. }
  89514. var currentCount = rowCount * columnCount;
  89515. var remained = count - currentCount;
  89516. if (remained > 0) {
  89517. for (var i = 0; i < remained; i++) {
  89518. grids[i % rowCount] += 1;
  89519. }
  89520. }
  89521. return grids;
  89522. }
  89523. function divideSector(sectorShape, count, outShapes) {
  89524. var r0 = sectorShape.r0;
  89525. var r = sectorShape.r;
  89526. var startAngle = sectorShape.startAngle;
  89527. var endAngle = sectorShape.endAngle;
  89528. var angle = Math.abs(endAngle - startAngle);
  89529. var arcLen = angle * r;
  89530. var deltaR = r - r0;
  89531. var isAngleRow = arcLen > Math.abs(deltaR);
  89532. var grids = getDividingGrids([arcLen, deltaR], isAngleRow ? 0 : 1, count);
  89533. var rowSize = (isAngleRow ? angle : deltaR) / grids.length;
  89534. for (var row = 0; row < grids.length; row++) {
  89535. var columnSize = (isAngleRow ? deltaR : angle) / grids[row];
  89536. for (var column = 0; column < grids[row]; column++) {
  89537. var newShape = {};
  89538. if (isAngleRow) {
  89539. newShape.startAngle = startAngle + rowSize * row;
  89540. newShape.endAngle = startAngle + rowSize * (row + 1);
  89541. newShape.r0 = r0 + columnSize * column;
  89542. newShape.r = r0 + columnSize * (column + 1);
  89543. }
  89544. else {
  89545. newShape.startAngle = startAngle + columnSize * column;
  89546. newShape.endAngle = startAngle + columnSize * (column + 1);
  89547. newShape.r0 = r0 + rowSize * row;
  89548. newShape.r = r0 + rowSize * (row + 1);
  89549. }
  89550. newShape.clockwise = sectorShape.clockwise;
  89551. newShape.cx = sectorShape.cx;
  89552. newShape.cy = sectorShape.cy;
  89553. outShapes.push(newShape);
  89554. }
  89555. }
  89556. }
  89557. function divideRect(rectShape, count, outShapes) {
  89558. var width = rectShape.width;
  89559. var height = rectShape.height;
  89560. var isHorizontalRow = width > height;
  89561. var grids = getDividingGrids([width, height], isHorizontalRow ? 0 : 1, count);
  89562. var rowSizeDim = isHorizontalRow ? 'width' : 'height';
  89563. var columnSizeDim = isHorizontalRow ? 'height' : 'width';
  89564. var rowDim = isHorizontalRow ? 'x' : 'y';
  89565. var columnDim = isHorizontalRow ? 'y' : 'x';
  89566. var rowSize = rectShape[rowSizeDim] / grids.length;
  89567. for (var row = 0; row < grids.length; row++) {
  89568. var columnSize = rectShape[columnSizeDim] / grids[row];
  89569. for (var column = 0; column < grids[row]; column++) {
  89570. var newShape = {};
  89571. newShape[rowDim] = row * rowSize;
  89572. newShape[columnDim] = column * columnSize;
  89573. newShape[rowSizeDim] = rowSize;
  89574. newShape[columnSizeDim] = columnSize;
  89575. newShape.x += rectShape.x;
  89576. newShape.y += rectShape.y;
  89577. outShapes.push(newShape);
  89578. }
  89579. }
  89580. }
  89581. function crossProduct2d$1(x1, y1, x2, y2) {
  89582. return x1 * y2 - x2 * y1;
  89583. }
  89584. function lineLineIntersect$1(a1x, a1y, a2x, a2y, b1x, b1y, b2x, b2y) {
  89585. var mx = a2x - a1x;
  89586. var my = a2y - a1y;
  89587. var nx = b2x - b1x;
  89588. var ny = b2y - b1y;
  89589. var nmCrossProduct = crossProduct2d$1(nx, ny, mx, my);
  89590. if (Math.abs(nmCrossProduct) < 1e-6) {
  89591. return null;
  89592. }
  89593. var b1a1x = a1x - b1x;
  89594. var b1a1y = a1y - b1y;
  89595. var p = crossProduct2d$1(b1a1x, b1a1y, nx, ny) / nmCrossProduct;
  89596. if (p < 0 || p > 1) {
  89597. return null;
  89598. }
  89599. return new Point(p * mx + a1x, p * my + a1y);
  89600. }
  89601. function projPtOnLine(pt, lineA, lineB) {
  89602. var dir = new Point();
  89603. Point.sub(dir, lineB, lineA);
  89604. dir.normalize();
  89605. var dir2 = new Point();
  89606. Point.sub(dir2, pt, lineA);
  89607. var len = dir2.dot(dir);
  89608. return len;
  89609. }
  89610. function addToPoly(poly, pt) {
  89611. var last = poly[poly.length - 1];
  89612. if (last && last[0] === pt[0] && last[1] === pt[1]) {
  89613. return;
  89614. }
  89615. poly.push(pt);
  89616. }
  89617. function splitPolygonByLine(points, lineA, lineB) {
  89618. var len = points.length;
  89619. var intersections = [];
  89620. for (var i = 0; i < len; i++) {
  89621. var p0 = points[i];
  89622. var p1 = points[(i + 1) % len];
  89623. var intersectionPt = lineLineIntersect$1(p0[0], p0[1], p1[0], p1[1], lineA.x, lineA.y, lineB.x, lineB.y);
  89624. if (intersectionPt) {
  89625. intersections.push({
  89626. projPt: projPtOnLine(intersectionPt, lineA, lineB),
  89627. pt: intersectionPt,
  89628. idx: i
  89629. });
  89630. }
  89631. }
  89632. if (intersections.length < 2) {
  89633. return [{ points: points }, { points: points }];
  89634. }
  89635. intersections.sort(function (a, b) {
  89636. return a.projPt - b.projPt;
  89637. });
  89638. var splitPt0 = intersections[0];
  89639. var splitPt1 = intersections[intersections.length - 1];
  89640. if (splitPt1.idx < splitPt0.idx) {
  89641. var tmp = splitPt0;
  89642. splitPt0 = splitPt1;
  89643. splitPt1 = tmp;
  89644. }
  89645. var splitPt0Arr = [splitPt0.pt.x, splitPt0.pt.y];
  89646. var splitPt1Arr = [splitPt1.pt.x, splitPt1.pt.y];
  89647. var newPolyA = [splitPt0Arr];
  89648. var newPolyB = [splitPt1Arr];
  89649. for (var i = splitPt0.idx + 1; i <= splitPt1.idx; i++) {
  89650. addToPoly(newPolyA, points[i].slice());
  89651. }
  89652. addToPoly(newPolyA, splitPt1Arr);
  89653. addToPoly(newPolyA, splitPt0Arr);
  89654. for (var i = splitPt1.idx + 1; i <= splitPt0.idx + len; i++) {
  89655. addToPoly(newPolyB, points[i % len].slice());
  89656. }
  89657. addToPoly(newPolyB, splitPt0Arr);
  89658. addToPoly(newPolyB, splitPt1Arr);
  89659. return [{
  89660. points: newPolyA
  89661. }, {
  89662. points: newPolyB
  89663. }];
  89664. }
  89665. function binaryDividePolygon(polygonShape) {
  89666. var points = polygonShape.points;
  89667. var min = [];
  89668. var max = [];
  89669. fromPoints(points, min, max);
  89670. var boundingRect = new BoundingRect(min[0], min[1], max[0] - min[0], max[1] - min[1]);
  89671. var width = boundingRect.width;
  89672. var height = boundingRect.height;
  89673. var x = boundingRect.x;
  89674. var y = boundingRect.y;
  89675. var pt0 = new Point();
  89676. var pt1 = new Point();
  89677. if (width > height) {
  89678. pt0.x = pt1.x = x + width / 2;
  89679. pt0.y = y;
  89680. pt1.y = y + height;
  89681. }
  89682. else {
  89683. pt0.y = pt1.y = y + height / 2;
  89684. pt0.x = x;
  89685. pt1.x = x + width;
  89686. }
  89687. return splitPolygonByLine(points, pt0, pt1);
  89688. }
  89689. function binaryDivideRecursive(divider, shape, count, out) {
  89690. if (count === 1) {
  89691. out.push(shape);
  89692. }
  89693. else {
  89694. var mid = Math.floor(count / 2);
  89695. var sub = divider(shape);
  89696. binaryDivideRecursive(divider, sub[0], mid, out);
  89697. binaryDivideRecursive(divider, sub[1], count - mid, out);
  89698. }
  89699. return out;
  89700. }
  89701. function clone$4(path, count) {
  89702. var paths = [];
  89703. for (var i = 0; i < count; i++) {
  89704. paths.push(clonePath(path));
  89705. }
  89706. return paths;
  89707. }
  89708. function copyPathProps(source, target) {
  89709. target.setStyle(source.style);
  89710. target.z = source.z;
  89711. target.z2 = source.z2;
  89712. target.zlevel = source.zlevel;
  89713. }
  89714. function polygonConvert(points) {
  89715. var out = [];
  89716. for (var i = 0; i < points.length;) {
  89717. out.push([points[i++], points[i++]]);
  89718. }
  89719. return out;
  89720. }
  89721. function split(path, count) {
  89722. var outShapes = [];
  89723. var shape = path.shape;
  89724. var OutShapeCtor;
  89725. switch (path.type) {
  89726. case 'rect':
  89727. divideRect(shape, count, outShapes);
  89728. OutShapeCtor = Rect;
  89729. break;
  89730. case 'sector':
  89731. divideSector(shape, count, outShapes);
  89732. OutShapeCtor = Sector;
  89733. break;
  89734. case 'circle':
  89735. divideSector({
  89736. r0: 0, r: shape.r, startAngle: 0, endAngle: Math.PI * 2,
  89737. cx: shape.cx, cy: shape.cy
  89738. }, count, outShapes);
  89739. OutShapeCtor = Sector;
  89740. break;
  89741. default:
  89742. var m = path.getComputedTransform();
  89743. var scale = m ? Math.sqrt(Math.max(m[0] * m[0] + m[1] * m[1], m[2] * m[2] + m[3] * m[3])) : 1;
  89744. var polygons = map(pathToPolygons(path.getUpdatedPathProxy(), scale), function (poly) { return polygonConvert(poly); });
  89745. var polygonCount = polygons.length;
  89746. if (polygonCount === 0) {
  89747. binaryDivideRecursive(binaryDividePolygon, {
  89748. points: polygons[0]
  89749. }, count, outShapes);
  89750. }
  89751. else if (polygonCount === count) {
  89752. for (var i = 0; i < polygonCount; i++) {
  89753. outShapes.push({
  89754. points: polygons[i]
  89755. });
  89756. }
  89757. }
  89758. else {
  89759. var totalArea_1 = 0;
  89760. var items = map(polygons, function (poly) {
  89761. var min = [];
  89762. var max = [];
  89763. fromPoints(poly, min, max);
  89764. var area = (max[1] - min[1]) * (max[0] - min[0]);
  89765. totalArea_1 += area;
  89766. return { poly: poly, area: area };
  89767. });
  89768. items.sort(function (a, b) { return b.area - a.area; });
  89769. var left = count;
  89770. for (var i = 0; i < polygonCount; i++) {
  89771. var item = items[i];
  89772. if (left <= 0) {
  89773. break;
  89774. }
  89775. var selfCount = i === polygonCount - 1
  89776. ? left
  89777. : Math.ceil(item.area / totalArea_1 * count);
  89778. if (selfCount < 0) {
  89779. continue;
  89780. }
  89781. binaryDivideRecursive(binaryDividePolygon, {
  89782. points: item.poly
  89783. }, selfCount, outShapes);
  89784. left -= selfCount;
  89785. }
  89786. }
  89787. OutShapeCtor = Polygon;
  89788. break;
  89789. }
  89790. if (!OutShapeCtor) {
  89791. return clone$4(path, count);
  89792. }
  89793. var out = [];
  89794. for (var i = 0; i < outShapes.length; i++) {
  89795. var subPath = new OutShapeCtor();
  89796. subPath.setShape(outShapes[i]);
  89797. copyPathProps(path, subPath);
  89798. out.push(subPath);
  89799. }
  89800. return out;
  89801. }
  89802. function alignSubpath(subpath1, subpath2) {
  89803. var len1 = subpath1.length;
  89804. var len2 = subpath2.length;
  89805. if (len1 === len2) {
  89806. return [subpath1, subpath2];
  89807. }
  89808. var tmpSegX = [];
  89809. var tmpSegY = [];
  89810. var shorterPath = len1 < len2 ? subpath1 : subpath2;
  89811. var shorterLen = Math.min(len1, len2);
  89812. var diff = Math.abs(len2 - len1) / 6;
  89813. var shorterBezierCount = (shorterLen - 2) / 6;
  89814. var eachCurveSubDivCount = Math.ceil(diff / shorterBezierCount) + 1;
  89815. var newSubpath = [shorterPath[0], shorterPath[1]];
  89816. var remained = diff;
  89817. for (var i = 2; i < shorterLen;) {
  89818. var x0 = shorterPath[i - 2];
  89819. var y0 = shorterPath[i - 1];
  89820. var x1 = shorterPath[i++];
  89821. var y1 = shorterPath[i++];
  89822. var x2 = shorterPath[i++];
  89823. var y2 = shorterPath[i++];
  89824. var x3 = shorterPath[i++];
  89825. var y3 = shorterPath[i++];
  89826. if (remained <= 0) {
  89827. newSubpath.push(x1, y1, x2, y2, x3, y3);
  89828. continue;
  89829. }
  89830. var actualSubDivCount = Math.min(remained, eachCurveSubDivCount - 1) + 1;
  89831. for (var k = 1; k <= actualSubDivCount; k++) {
  89832. var p = k / actualSubDivCount;
  89833. cubicSubdivide(x0, x1, x2, x3, p, tmpSegX);
  89834. cubicSubdivide(y0, y1, y2, y3, p, tmpSegY);
  89835. x0 = tmpSegX[3];
  89836. y0 = tmpSegY[3];
  89837. newSubpath.push(tmpSegX[1], tmpSegY[1], tmpSegX[2], tmpSegY[2], x0, y0);
  89838. x1 = tmpSegX[5];
  89839. y1 = tmpSegY[5];
  89840. x2 = tmpSegX[6];
  89841. y2 = tmpSegY[6];
  89842. }
  89843. remained -= actualSubDivCount - 1;
  89844. }
  89845. return shorterPath === subpath1 ? [newSubpath, subpath2] : [subpath1, newSubpath];
  89846. }
  89847. function createSubpath(lastSubpathSubpath, otherSubpath) {
  89848. var len = lastSubpathSubpath.length;
  89849. var lastX = lastSubpathSubpath[len - 2];
  89850. var lastY = lastSubpathSubpath[len - 1];
  89851. var newSubpath = [];
  89852. for (var i = 0; i < otherSubpath.length;) {
  89853. newSubpath[i++] = lastX;
  89854. newSubpath[i++] = lastY;
  89855. }
  89856. return newSubpath;
  89857. }
  89858. function alignBezierCurves(array1, array2) {
  89859. var _a;
  89860. var lastSubpath1;
  89861. var lastSubpath2;
  89862. var newArray1 = [];
  89863. var newArray2 = [];
  89864. for (var i = 0; i < Math.max(array1.length, array2.length); i++) {
  89865. var subpath1 = array1[i];
  89866. var subpath2 = array2[i];
  89867. var newSubpath1 = void 0;
  89868. var newSubpath2 = void 0;
  89869. if (!subpath1) {
  89870. newSubpath1 = createSubpath(lastSubpath1 || subpath2, subpath2);
  89871. newSubpath2 = subpath2;
  89872. }
  89873. else if (!subpath2) {
  89874. newSubpath2 = createSubpath(lastSubpath2 || subpath1, subpath1);
  89875. newSubpath1 = subpath1;
  89876. }
  89877. else {
  89878. _a = alignSubpath(subpath1, subpath2), newSubpath1 = _a[0], newSubpath2 = _a[1];
  89879. lastSubpath1 = newSubpath1;
  89880. lastSubpath2 = newSubpath2;
  89881. }
  89882. newArray1.push(newSubpath1);
  89883. newArray2.push(newSubpath2);
  89884. }
  89885. return [newArray1, newArray2];
  89886. }
  89887. function centroid$1(array) {
  89888. var signedArea = 0;
  89889. var cx = 0;
  89890. var cy = 0;
  89891. var len = array.length;
  89892. for (var i = 0, j = len - 2; i < len; j = i, i += 2) {
  89893. var x0 = array[j];
  89894. var y0 = array[j + 1];
  89895. var x1 = array[i];
  89896. var y1 = array[i + 1];
  89897. var a = x0 * y1 - x1 * y0;
  89898. signedArea += a;
  89899. cx += (x0 + x1) * a;
  89900. cy += (y0 + y1) * a;
  89901. }
  89902. if (signedArea === 0) {
  89903. return [array[0] || 0, array[1] || 0];
  89904. }
  89905. return [cx / signedArea / 3, cy / signedArea / 3, signedArea];
  89906. }
  89907. function findBestRingOffset(fromSubBeziers, toSubBeziers, fromCp, toCp) {
  89908. var bezierCount = (fromSubBeziers.length - 2) / 6;
  89909. var bestScore = Infinity;
  89910. var bestOffset = 0;
  89911. var len = fromSubBeziers.length;
  89912. var len2 = len - 2;
  89913. for (var offset = 0; offset < bezierCount; offset++) {
  89914. var cursorOffset = offset * 6;
  89915. var score = 0;
  89916. for (var k = 0; k < len; k += 2) {
  89917. var idx = k === 0 ? cursorOffset : ((cursorOffset + k - 2) % len2 + 2);
  89918. var x0 = fromSubBeziers[idx] - fromCp[0];
  89919. var y0 = fromSubBeziers[idx + 1] - fromCp[1];
  89920. var x1 = toSubBeziers[k] - toCp[0];
  89921. var y1 = toSubBeziers[k + 1] - toCp[1];
  89922. var dx = x1 - x0;
  89923. var dy = y1 - y0;
  89924. score += dx * dx + dy * dy;
  89925. }
  89926. if (score < bestScore) {
  89927. bestScore = score;
  89928. bestOffset = offset;
  89929. }
  89930. }
  89931. return bestOffset;
  89932. }
  89933. function reverse(array) {
  89934. var newArr = [];
  89935. var len = array.length;
  89936. for (var i = 0; i < len; i += 2) {
  89937. newArr[i] = array[len - i - 2];
  89938. newArr[i + 1] = array[len - i - 1];
  89939. }
  89940. return newArr;
  89941. }
  89942. function findBestMorphingRotation(fromArr, toArr, searchAngleIteration, searchAngleRange) {
  89943. var result = [];
  89944. var fromNeedsReverse;
  89945. for (var i = 0; i < fromArr.length; i++) {
  89946. var fromSubpathBezier = fromArr[i];
  89947. var toSubpathBezier = toArr[i];
  89948. var fromCp = centroid$1(fromSubpathBezier);
  89949. var toCp = centroid$1(toSubpathBezier);
  89950. if (fromNeedsReverse == null) {
  89951. fromNeedsReverse = fromCp[2] < 0 !== toCp[2] < 0;
  89952. }
  89953. var newFromSubpathBezier = [];
  89954. var newToSubpathBezier = [];
  89955. var bestAngle = 0;
  89956. var bestScore = Infinity;
  89957. var tmpArr = [];
  89958. var len = fromSubpathBezier.length;
  89959. if (fromNeedsReverse) {
  89960. fromSubpathBezier = reverse(fromSubpathBezier);
  89961. }
  89962. var offset = findBestRingOffset(fromSubpathBezier, toSubpathBezier, fromCp, toCp) * 6;
  89963. var len2 = len - 2;
  89964. for (var k = 0; k < len2; k += 2) {
  89965. var idx = (offset + k) % len2 + 2;
  89966. newFromSubpathBezier[k + 2] = fromSubpathBezier[idx] - fromCp[0];
  89967. newFromSubpathBezier[k + 3] = fromSubpathBezier[idx + 1] - fromCp[1];
  89968. }
  89969. newFromSubpathBezier[0] = fromSubpathBezier[offset] - fromCp[0];
  89970. newFromSubpathBezier[1] = fromSubpathBezier[offset + 1] - fromCp[1];
  89971. if (searchAngleIteration > 0) {
  89972. var step = searchAngleRange / searchAngleIteration;
  89973. for (var angle = -searchAngleRange / 2; angle <= searchAngleRange / 2; angle += step) {
  89974. var sa = Math.sin(angle);
  89975. var ca = Math.cos(angle);
  89976. var score = 0;
  89977. for (var k = 0; k < fromSubpathBezier.length; k += 2) {
  89978. var x0 = newFromSubpathBezier[k];
  89979. var y0 = newFromSubpathBezier[k + 1];
  89980. var x1 = toSubpathBezier[k] - toCp[0];
  89981. var y1 = toSubpathBezier[k + 1] - toCp[1];
  89982. var newX1 = x1 * ca - y1 * sa;
  89983. var newY1 = x1 * sa + y1 * ca;
  89984. tmpArr[k] = newX1;
  89985. tmpArr[k + 1] = newY1;
  89986. var dx = newX1 - x0;
  89987. var dy = newY1 - y0;
  89988. score += dx * dx + dy * dy;
  89989. }
  89990. if (score < bestScore) {
  89991. bestScore = score;
  89992. bestAngle = angle;
  89993. for (var m = 0; m < tmpArr.length; m++) {
  89994. newToSubpathBezier[m] = tmpArr[m];
  89995. }
  89996. }
  89997. }
  89998. }
  89999. else {
  90000. for (var i_1 = 0; i_1 < len; i_1 += 2) {
  90001. newToSubpathBezier[i_1] = toSubpathBezier[i_1] - toCp[0];
  90002. newToSubpathBezier[i_1 + 1] = toSubpathBezier[i_1 + 1] - toCp[1];
  90003. }
  90004. }
  90005. result.push({
  90006. from: newFromSubpathBezier,
  90007. to: newToSubpathBezier,
  90008. fromCp: fromCp,
  90009. toCp: toCp,
  90010. rotation: -bestAngle
  90011. });
  90012. }
  90013. return result;
  90014. }
  90015. function isCombineMorphing(path) {
  90016. return path.__isCombineMorphing;
  90017. }
  90018. var SAVED_METHOD_PREFIX = '__mOriginal_';
  90019. function saveAndModifyMethod(obj, methodName, modifiers) {
  90020. var savedMethodName = SAVED_METHOD_PREFIX + methodName;
  90021. var originalMethod = obj[savedMethodName] || obj[methodName];
  90022. if (!obj[savedMethodName]) {
  90023. obj[savedMethodName] = obj[methodName];
  90024. }
  90025. var replace = modifiers.replace;
  90026. var after = modifiers.after;
  90027. var before = modifiers.before;
  90028. obj[methodName] = function () {
  90029. var args = arguments;
  90030. var res;
  90031. before && before.apply(this, args);
  90032. if (replace) {
  90033. res = replace.apply(this, args);
  90034. }
  90035. else {
  90036. res = originalMethod.apply(this, args);
  90037. }
  90038. after && after.apply(this, args);
  90039. return res;
  90040. };
  90041. }
  90042. function restoreMethod(obj, methodName) {
  90043. var savedMethodName = SAVED_METHOD_PREFIX + methodName;
  90044. if (obj[savedMethodName]) {
  90045. obj[methodName] = obj[savedMethodName];
  90046. obj[savedMethodName] = null;
  90047. }
  90048. }
  90049. function applyTransformOnBeziers(bezierCurves, mm) {
  90050. for (var i = 0; i < bezierCurves.length; i++) {
  90051. var subBeziers = bezierCurves[i];
  90052. for (var k = 0; k < subBeziers.length;) {
  90053. var x = subBeziers[k];
  90054. var y = subBeziers[k + 1];
  90055. subBeziers[k++] = mm[0] * x + mm[2] * y + mm[4];
  90056. subBeziers[k++] = mm[1] * x + mm[3] * y + mm[5];
  90057. }
  90058. }
  90059. }
  90060. function prepareMorphPath(fromPath, toPath) {
  90061. var fromPathProxy = fromPath.getUpdatedPathProxy();
  90062. var toPathProxy = toPath.getUpdatedPathProxy();
  90063. var _a = alignBezierCurves(pathToBezierCurves(fromPathProxy), pathToBezierCurves(toPathProxy)), fromBezierCurves = _a[0], toBezierCurves = _a[1];
  90064. var fromPathTransform = fromPath.getComputedTransform();
  90065. var toPathTransform = toPath.getComputedTransform();
  90066. function updateIdentityTransform() {
  90067. this.transform = null;
  90068. }
  90069. fromPathTransform && applyTransformOnBeziers(fromBezierCurves, fromPathTransform);
  90070. toPathTransform && applyTransformOnBeziers(toBezierCurves, toPathTransform);
  90071. saveAndModifyMethod(toPath, 'updateTransform', { replace: updateIdentityTransform });
  90072. toPath.transform = null;
  90073. var morphingData = findBestMorphingRotation(fromBezierCurves, toBezierCurves, 10, Math.PI);
  90074. var tmpArr = [];
  90075. saveAndModifyMethod(toPath, 'buildPath', { replace: function (path) {
  90076. var t = toPath.__morphT;
  90077. var onet = 1 - t;
  90078. var newCp = [];
  90079. for (var i = 0; i < morphingData.length; i++) {
  90080. var item = morphingData[i];
  90081. var from = item.from;
  90082. var to = item.to;
  90083. var angle = item.rotation * t;
  90084. var fromCp = item.fromCp;
  90085. var toCp = item.toCp;
  90086. var sa = Math.sin(angle);
  90087. var ca = Math.cos(angle);
  90088. lerp(newCp, fromCp, toCp, t);
  90089. for (var m = 0; m < from.length; m += 2) {
  90090. var x0_1 = from[m];
  90091. var y0_1 = from[m + 1];
  90092. var x1 = to[m];
  90093. var y1 = to[m + 1];
  90094. var x = x0_1 * onet + x1 * t;
  90095. var y = y0_1 * onet + y1 * t;
  90096. tmpArr[m] = (x * ca - y * sa) + newCp[0];
  90097. tmpArr[m + 1] = (x * sa + y * ca) + newCp[1];
  90098. }
  90099. var x0 = tmpArr[0];
  90100. var y0 = tmpArr[1];
  90101. path.moveTo(x0, y0);
  90102. for (var m = 2; m < from.length;) {
  90103. var x1 = tmpArr[m++];
  90104. var y1 = tmpArr[m++];
  90105. var x2 = tmpArr[m++];
  90106. var y2 = tmpArr[m++];
  90107. var x3 = tmpArr[m++];
  90108. var y3 = tmpArr[m++];
  90109. if (x0 === x1 && y0 === y1 && x2 === x3 && y2 === y3) {
  90110. path.lineTo(x3, y3);
  90111. }
  90112. else {
  90113. path.bezierCurveTo(x1, y1, x2, y2, x3, y3);
  90114. }
  90115. x0 = x3;
  90116. y0 = y3;
  90117. }
  90118. }
  90119. } });
  90120. }
  90121. function morphPath(fromPath, toPath, animationOpts) {
  90122. if (!fromPath || !toPath) {
  90123. return toPath;
  90124. }
  90125. var oldDone = animationOpts.done;
  90126. var oldDuring = animationOpts.during;
  90127. prepareMorphPath(fromPath, toPath);
  90128. toPath.__morphT = 0;
  90129. function restoreToPath() {
  90130. restoreMethod(toPath, 'buildPath');
  90131. restoreMethod(toPath, 'updateTransform');
  90132. toPath.__morphT = -1;
  90133. toPath.createPathProxy();
  90134. toPath.dirtyShape();
  90135. }
  90136. toPath.animateTo({
  90137. __morphT: 1
  90138. }, defaults({
  90139. during: function (p) {
  90140. toPath.dirtyShape();
  90141. oldDuring && oldDuring(p);
  90142. },
  90143. done: function () {
  90144. restoreToPath();
  90145. oldDone && oldDone();
  90146. }
  90147. }, animationOpts));
  90148. return toPath;
  90149. }
  90150. function hilbert(x, y, minX, minY, maxX, maxY) {
  90151. var bits = 16;
  90152. x = (maxX === minX) ? 0 : Math.round(32767 * (x - minX) / (maxX - minX));
  90153. y = (maxY === minY) ? 0 : Math.round(32767 * (y - minY) / (maxY - minY));
  90154. var d = 0;
  90155. var tmp;
  90156. for (var s = (1 << bits) / 2; s > 0; s /= 2) {
  90157. var rx = 0;
  90158. var ry = 0;
  90159. if ((x & s) > 0) {
  90160. rx = 1;
  90161. }
  90162. if ((y & s) > 0) {
  90163. ry = 1;
  90164. }
  90165. d += s * s * ((3 * rx) ^ ry);
  90166. if (ry === 0) {
  90167. if (rx === 1) {
  90168. x = s - 1 - x;
  90169. y = s - 1 - y;
  90170. }
  90171. tmp = x;
  90172. x = y;
  90173. y = tmp;
  90174. }
  90175. }
  90176. return d;
  90177. }
  90178. function sortPaths(pathList) {
  90179. var xMin = Infinity;
  90180. var yMin = Infinity;
  90181. var xMax = -Infinity;
  90182. var yMax = -Infinity;
  90183. var cps = map(pathList, function (path) {
  90184. var rect = path.getBoundingRect();
  90185. var m = path.getComputedTransform();
  90186. var x = rect.x + rect.width / 2 + (m ? m[4] : 0);
  90187. var y = rect.y + rect.height / 2 + (m ? m[5] : 0);
  90188. xMin = Math.min(x, xMin);
  90189. yMin = Math.min(y, yMin);
  90190. xMax = Math.max(x, xMax);
  90191. yMax = Math.max(y, yMax);
  90192. return [x, y];
  90193. });
  90194. var items = map(cps, function (cp, idx) {
  90195. return {
  90196. cp: cp,
  90197. z: hilbert(cp[0], cp[1], xMin, yMin, xMax, yMax),
  90198. path: pathList[idx]
  90199. };
  90200. });
  90201. return items.sort(function (a, b) { return a.z - b.z; }).map(function (item) { return item.path; });
  90202. }
  90203. function defaultDividePath(param) {
  90204. return split(param.path, param.count);
  90205. }
  90206. function createEmptyReturn() {
  90207. return {
  90208. fromIndividuals: [],
  90209. toIndividuals: [],
  90210. count: 0
  90211. };
  90212. }
  90213. function combineMorph(fromList, toPath, animationOpts) {
  90214. var fromPathList = [];
  90215. function addFromPath(fromList) {
  90216. for (var i = 0; i < fromList.length; i++) {
  90217. var from = fromList[i];
  90218. if (isCombineMorphing(from)) {
  90219. addFromPath(from.childrenRef());
  90220. }
  90221. else if (from instanceof Path) {
  90222. fromPathList.push(from);
  90223. }
  90224. }
  90225. }
  90226. addFromPath(fromList);
  90227. var separateCount = fromPathList.length;
  90228. if (!separateCount) {
  90229. return createEmptyReturn();
  90230. }
  90231. var dividePath = animationOpts.dividePath || defaultDividePath;
  90232. var toSubPathList = dividePath({
  90233. path: toPath, count: separateCount
  90234. });
  90235. if (toSubPathList.length !== separateCount) {
  90236. console.error('Invalid morphing: unmatched splitted path');
  90237. return createEmptyReturn();
  90238. }
  90239. fromPathList = sortPaths(fromPathList);
  90240. toSubPathList = sortPaths(toSubPathList);
  90241. var oldDone = animationOpts.done;
  90242. var oldDuring = animationOpts.during;
  90243. var individualDelay = animationOpts.individualDelay;
  90244. var identityTransform = new Transformable();
  90245. for (var i = 0; i < separateCount; i++) {
  90246. var from = fromPathList[i];
  90247. var to = toSubPathList[i];
  90248. to.parent = toPath;
  90249. to.copyTransform(identityTransform);
  90250. if (!individualDelay) {
  90251. prepareMorphPath(from, to);
  90252. }
  90253. }
  90254. toPath.__isCombineMorphing = true;
  90255. toPath.childrenRef = function () {
  90256. return toSubPathList;
  90257. };
  90258. function addToSubPathListToZr(zr) {
  90259. for (var i = 0; i < toSubPathList.length; i++) {
  90260. toSubPathList[i].addSelfToZr(zr);
  90261. }
  90262. }
  90263. saveAndModifyMethod(toPath, 'addSelfToZr', {
  90264. after: function (zr) {
  90265. addToSubPathListToZr(zr);
  90266. }
  90267. });
  90268. saveAndModifyMethod(toPath, 'removeSelfFromZr', {
  90269. after: function (zr) {
  90270. for (var i = 0; i < toSubPathList.length; i++) {
  90271. toSubPathList[i].removeSelfFromZr(zr);
  90272. }
  90273. }
  90274. });
  90275. function restoreToPath() {
  90276. toPath.__isCombineMorphing = false;
  90277. toPath.__morphT = -1;
  90278. toPath.childrenRef = null;
  90279. restoreMethod(toPath, 'addSelfToZr');
  90280. restoreMethod(toPath, 'removeSelfFromZr');
  90281. }
  90282. var toLen = toSubPathList.length;
  90283. if (individualDelay) {
  90284. var animating_1 = toLen;
  90285. var eachDone = function () {
  90286. animating_1--;
  90287. if (animating_1 === 0) {
  90288. restoreToPath();
  90289. oldDone && oldDone();
  90290. }
  90291. };
  90292. for (var i = 0; i < toLen; i++) {
  90293. var indivdualAnimationOpts = individualDelay ? defaults({
  90294. delay: (animationOpts.delay || 0) + individualDelay(i, toLen, fromPathList[i], toSubPathList[i]),
  90295. done: eachDone
  90296. }, animationOpts) : animationOpts;
  90297. morphPath(fromPathList[i], toSubPathList[i], indivdualAnimationOpts);
  90298. }
  90299. }
  90300. else {
  90301. toPath.__morphT = 0;
  90302. toPath.animateTo({
  90303. __morphT: 1
  90304. }, defaults({
  90305. during: function (p) {
  90306. for (var i = 0; i < toLen; i++) {
  90307. var child = toSubPathList[i];
  90308. child.__morphT = toPath.__morphT;
  90309. child.dirtyShape();
  90310. }
  90311. oldDuring && oldDuring(p);
  90312. },
  90313. done: function () {
  90314. restoreToPath();
  90315. for (var i = 0; i < fromList.length; i++) {
  90316. restoreMethod(fromList[i], 'updateTransform');
  90317. }
  90318. oldDone && oldDone();
  90319. }
  90320. }, animationOpts));
  90321. }
  90322. if (toPath.__zr) {
  90323. addToSubPathListToZr(toPath.__zr);
  90324. }
  90325. return {
  90326. fromIndividuals: fromPathList,
  90327. toIndividuals: toSubPathList,
  90328. count: toLen
  90329. };
  90330. }
  90331. function separateMorph(fromPath, toPathList, animationOpts) {
  90332. var toLen = toPathList.length;
  90333. var fromPathList = [];
  90334. var dividePath = animationOpts.dividePath || defaultDividePath;
  90335. function addFromPath(fromList) {
  90336. for (var i = 0; i < fromList.length; i++) {
  90337. var from = fromList[i];
  90338. if (isCombineMorphing(from)) {
  90339. addFromPath(from.childrenRef());
  90340. }
  90341. else if (from instanceof Path) {
  90342. fromPathList.push(from);
  90343. }
  90344. }
  90345. }
  90346. if (isCombineMorphing(fromPath)) {
  90347. addFromPath(fromPath.childrenRef());
  90348. var fromLen = fromPathList.length;
  90349. if (fromLen < toLen) {
  90350. var k = 0;
  90351. for (var i = fromLen; i < toLen; i++) {
  90352. fromPathList.push(clonePath(fromPathList[k++ % fromLen]));
  90353. }
  90354. }
  90355. fromPathList.length = toLen;
  90356. }
  90357. else {
  90358. fromPathList = dividePath({ path: fromPath, count: toLen });
  90359. var fromPathTransform = fromPath.getComputedTransform();
  90360. for (var i = 0; i < fromPathList.length; i++) {
  90361. fromPathList[i].setLocalTransform(fromPathTransform);
  90362. }
  90363. if (fromPathList.length !== toLen) {
  90364. console.error('Invalid morphing: unmatched splitted path');
  90365. return createEmptyReturn();
  90366. }
  90367. }
  90368. fromPathList = sortPaths(fromPathList);
  90369. toPathList = sortPaths(toPathList);
  90370. var individualDelay = animationOpts.individualDelay;
  90371. for (var i = 0; i < toLen; i++) {
  90372. var indivdualAnimationOpts = individualDelay ? defaults({
  90373. delay: (animationOpts.delay || 0) + individualDelay(i, toLen, fromPathList[i], toPathList[i])
  90374. }, animationOpts) : animationOpts;
  90375. morphPath(fromPathList[i], toPathList[i], indivdualAnimationOpts);
  90376. }
  90377. return {
  90378. fromIndividuals: fromPathList,
  90379. toIndividuals: toPathList,
  90380. count: toPathList.length
  90381. };
  90382. }
  90383. function isMultiple(elements) {
  90384. return isArray(elements[0]);
  90385. }
  90386. function prepareMorphBatches(one, many) {
  90387. var batches = [];
  90388. var batchCount = one.length;
  90389. for (var i = 0; i < batchCount; i++) {
  90390. batches.push({
  90391. one: one[i],
  90392. many: []
  90393. });
  90394. }
  90395. for (var i = 0; i < many.length; i++) {
  90396. var len = many[i].length;
  90397. var k = void 0;
  90398. for (k = 0; k < len; k++) {
  90399. batches[k % batchCount].many.push(many[i][k]);
  90400. }
  90401. }
  90402. var off = 0;
  90403. // If one has more paths than each one of many. average them.
  90404. for (var i = batchCount - 1; i >= 0; i--) {
  90405. if (!batches[i].many.length) {
  90406. var moveFrom = batches[off].many;
  90407. if (moveFrom.length <= 1) {
  90408. // Not enough
  90409. // Start from the first one.
  90410. if (off) {
  90411. off = 0;
  90412. } else {
  90413. return batches;
  90414. }
  90415. }
  90416. var len = moveFrom.length;
  90417. var mid = Math.ceil(len / 2);
  90418. batches[i].many = moveFrom.slice(mid, len);
  90419. batches[off].many = moveFrom.slice(0, mid);
  90420. off++;
  90421. }
  90422. }
  90423. return batches;
  90424. }
  90425. var pathDividers = {
  90426. clone: function (params) {
  90427. var ret = [];
  90428. // Fitting the alpha
  90429. var approxOpacity = 1 - Math.pow(1 - params.path.style.opacity, 1 / params.count);
  90430. for (var i = 0; i < params.count; i++) {
  90431. var cloned = clonePath(params.path);
  90432. cloned.setStyle('opacity', approxOpacity);
  90433. ret.push(cloned);
  90434. }
  90435. return ret;
  90436. },
  90437. // Use the default divider
  90438. split: null
  90439. };
  90440. function applyMorphAnimation(from, to, divideShape, seriesModel, dataIndex, animateOtherProps) {
  90441. if (!from.length || !to.length) {
  90442. return;
  90443. }
  90444. var updateAnimationCfg = getAnimationConfig('update', seriesModel, dataIndex);
  90445. if (!(updateAnimationCfg && updateAnimationCfg.duration > 0)) {
  90446. return;
  90447. }
  90448. var animationDelay = seriesModel.getModel('universalTransition').get('delay');
  90449. var animationCfg = Object.assign({
  90450. // Need to setToFinal so the further calculation based on the style can be correct.
  90451. // Like emphasis color.
  90452. setToFinal: true
  90453. }, updateAnimationCfg);
  90454. var many;
  90455. var one;
  90456. if (isMultiple(from)) {
  90457. // manyToOne
  90458. many = from;
  90459. one = to;
  90460. }
  90461. if (isMultiple(to)) {
  90462. // oneToMany
  90463. many = to;
  90464. one = from;
  90465. }
  90466. function morphOneBatch(batch, fromIsMany, animateIndex, animateCount, forceManyOne) {
  90467. var batchMany = batch.many;
  90468. var batchOne = batch.one;
  90469. if (batchMany.length === 1 && !forceManyOne) {
  90470. // Is one to one
  90471. var batchFrom = fromIsMany ? batchMany[0] : batchOne;
  90472. var batchTo = fromIsMany ? batchOne : batchMany[0];
  90473. if (isCombineMorphing(batchFrom)) {
  90474. // Keep doing combine animation.
  90475. morphOneBatch({
  90476. many: [batchFrom],
  90477. one: batchTo
  90478. }, true, animateIndex, animateCount, true);
  90479. } else {
  90480. var individualAnimationCfg = animationDelay ? defaults({
  90481. delay: animationDelay(animateIndex, animateCount)
  90482. }, animationCfg) : animationCfg;
  90483. morphPath(batchFrom, batchTo, individualAnimationCfg);
  90484. animateOtherProps(batchFrom, batchTo, batchFrom, batchTo, individualAnimationCfg);
  90485. }
  90486. } else {
  90487. var separateAnimationCfg = defaults({
  90488. dividePath: pathDividers[divideShape],
  90489. individualDelay: animationDelay && function (idx, count, fromPath, toPath) {
  90490. return animationDelay(idx + animateIndex, animateCount);
  90491. }
  90492. }, animationCfg);
  90493. var _a = fromIsMany ? combineMorph(batchMany, batchOne, separateAnimationCfg) : separateMorph(batchOne, batchMany, separateAnimationCfg),
  90494. fromIndividuals = _a.fromIndividuals,
  90495. toIndividuals = _a.toIndividuals;
  90496. var count = fromIndividuals.length;
  90497. for (var k = 0; k < count; k++) {
  90498. var individualAnimationCfg = animationDelay ? defaults({
  90499. delay: animationDelay(k, count)
  90500. }, animationCfg) : animationCfg;
  90501. animateOtherProps(fromIndividuals[k], toIndividuals[k], fromIsMany ? batchMany[k] : batch.one, fromIsMany ? batch.one : batchMany[k], individualAnimationCfg);
  90502. }
  90503. }
  90504. }
  90505. var fromIsMany = many ? many === from
  90506. // Is one to one. If the path number not match. also needs do merge and separate morphing.
  90507. : from.length > to.length;
  90508. var morphBatches = many ? prepareMorphBatches(one, many) : prepareMorphBatches(fromIsMany ? to : from, [fromIsMany ? from : to]);
  90509. var animateCount = 0;
  90510. for (var i = 0; i < morphBatches.length; i++) {
  90511. animateCount += morphBatches[i].many.length;
  90512. }
  90513. var animateIndex = 0;
  90514. for (var i = 0; i < morphBatches.length; i++) {
  90515. morphOneBatch(morphBatches[i], fromIsMany, animateIndex, animateCount);
  90516. animateIndex += morphBatches[i].many.length;
  90517. }
  90518. }
  90519. function getPathList(elements) {
  90520. if (!elements) {
  90521. return [];
  90522. }
  90523. if (isArray(elements)) {
  90524. var pathList_1 = [];
  90525. for (var i = 0; i < elements.length; i++) {
  90526. pathList_1.push(getPathList(elements[i]));
  90527. }
  90528. return pathList_1;
  90529. }
  90530. var pathList = [];
  90531. elements.traverse(function (el) {
  90532. if (el instanceof Path && !el.disableMorphing && !el.invisible && !el.ignore) {
  90533. pathList.push(el);
  90534. }
  90535. });
  90536. return pathList;
  90537. }
  90538. var DATA_COUNT_THRESHOLD = 1e4;
  90539. var TRANSITION_NONE = 0;
  90540. var TRANSITION_P2C = 1;
  90541. var TRANSITION_C2P = 2;
  90542. var getUniversalTransitionGlobalStore = makeInner();
  90543. function getDimension(data, visualDimension) {
  90544. var dimensions = data.dimensions;
  90545. for (var i = 0; i < dimensions.length; i++) {
  90546. var dimInfo = data.getDimensionInfo(dimensions[i]);
  90547. if (dimInfo && dimInfo.otherDims[visualDimension] === 0) {
  90548. return dimensions[i];
  90549. }
  90550. }
  90551. }
  90552. // get value by dimension. (only get value of itemGroupId or childGroupId, so convert it to string)
  90553. function getValueByDimension(data, dataIndex, dimension) {
  90554. var dimInfo = data.getDimensionInfo(dimension);
  90555. var dimOrdinalMeta = dimInfo && dimInfo.ordinalMeta;
  90556. if (dimInfo) {
  90557. var value = data.get(dimInfo.name, dataIndex);
  90558. if (dimOrdinalMeta) {
  90559. return dimOrdinalMeta.categories[value] || value + '';
  90560. }
  90561. return value + '';
  90562. }
  90563. }
  90564. function getGroupId(data, dataIndex, dataGroupId, isChild) {
  90565. // try to get groupId from encode
  90566. var visualDimension = isChild ? 'itemChildGroupId' : 'itemGroupId';
  90567. var groupIdDim = getDimension(data, visualDimension);
  90568. if (groupIdDim) {
  90569. var groupId = getValueByDimension(data, dataIndex, groupIdDim);
  90570. return groupId;
  90571. }
  90572. // try to get groupId from raw data item
  90573. var rawDataItem = data.getRawDataItem(dataIndex);
  90574. var property = isChild ? 'childGroupId' : 'groupId';
  90575. if (rawDataItem && rawDataItem[property]) {
  90576. return rawDataItem[property] + '';
  90577. }
  90578. // fallback
  90579. if (isChild) {
  90580. return;
  90581. }
  90582. // try to use series.dataGroupId as groupId, otherwise use dataItem's id as groupId
  90583. return dataGroupId || data.getId(dataIndex);
  90584. }
  90585. // flatten all data items from different serieses into one arrary
  90586. function flattenDataDiffItems(list) {
  90587. var items = [];
  90588. each(list, function (seriesInfo) {
  90589. var data = seriesInfo.data;
  90590. var dataGroupId = seriesInfo.dataGroupId;
  90591. if (data.count() > DATA_COUNT_THRESHOLD) {
  90592. if ("development" !== 'production') {
  90593. warn('Universal transition is disabled on large data > 10k.');
  90594. }
  90595. return;
  90596. }
  90597. var indices = data.getIndices();
  90598. for (var dataIndex = 0; dataIndex < indices.length; dataIndex++) {
  90599. items.push({
  90600. data: data,
  90601. groupId: getGroupId(data, dataIndex, dataGroupId, false),
  90602. childGroupId: getGroupId(data, dataIndex, dataGroupId, true),
  90603. divide: seriesInfo.divide,
  90604. dataIndex: dataIndex
  90605. });
  90606. }
  90607. });
  90608. return items;
  90609. }
  90610. function fadeInElement(newEl, newSeries, newIndex) {
  90611. newEl.traverse(function (el) {
  90612. if (el instanceof Path) {
  90613. // TODO use fade in animation for target element.
  90614. initProps(el, {
  90615. style: {
  90616. opacity: 0
  90617. }
  90618. }, newSeries, {
  90619. dataIndex: newIndex,
  90620. isFrom: true
  90621. });
  90622. }
  90623. });
  90624. }
  90625. function removeEl$1(el) {
  90626. if (el.parent) {
  90627. // Bake parent transform to element.
  90628. // So it can still have proper transform to transition after it's removed.
  90629. var computedTransform = el.getComputedTransform();
  90630. el.setLocalTransform(computedTransform);
  90631. el.parent.remove(el);
  90632. }
  90633. }
  90634. function stopAnimation(el) {
  90635. el.stopAnimation();
  90636. if (el.isGroup) {
  90637. el.traverse(function (child) {
  90638. child.stopAnimation();
  90639. });
  90640. }
  90641. }
  90642. function animateElementStyles(el, dataIndex, seriesModel) {
  90643. var animationConfig = getAnimationConfig('update', seriesModel, dataIndex);
  90644. animationConfig && el.traverse(function (child) {
  90645. if (child instanceof Displayable) {
  90646. var oldStyle = getOldStyle(child);
  90647. if (oldStyle) {
  90648. child.animateFrom({
  90649. style: oldStyle
  90650. }, animationConfig);
  90651. }
  90652. }
  90653. });
  90654. }
  90655. function isAllIdSame(oldDiffItems, newDiffItems) {
  90656. var len = oldDiffItems.length;
  90657. if (len !== newDiffItems.length) {
  90658. return false;
  90659. }
  90660. for (var i = 0; i < len; i++) {
  90661. var oldItem = oldDiffItems[i];
  90662. var newItem = newDiffItems[i];
  90663. if (oldItem.data.getId(oldItem.dataIndex) !== newItem.data.getId(newItem.dataIndex)) {
  90664. return false;
  90665. }
  90666. }
  90667. return true;
  90668. }
  90669. function transitionBetween(oldList, newList, api) {
  90670. var oldDiffItems = flattenDataDiffItems(oldList);
  90671. var newDiffItems = flattenDataDiffItems(newList);
  90672. function updateMorphingPathProps(from, to, rawFrom, rawTo, animationCfg) {
  90673. if (rawFrom || from) {
  90674. to.animateFrom({
  90675. style: rawFrom && rawFrom !== from
  90676. // dividingMethod like clone may override the style(opacity)
  90677. // So extend it to raw style.
  90678. ? extend(extend({}, rawFrom.style), from.style) : from.style
  90679. }, animationCfg);
  90680. }
  90681. }
  90682. var hasMorphAnimation = false;
  90683. /**
  90684. * With groupId and childGroupId, we can build parent-child relationships between dataItems.
  90685. * However, we should mind the parent-child "direction" between old and new options.
  90686. *
  90687. * For example, suppose we have two dataItems from two series.data:
  90688. *
  90689. * dataA: [ dataB: [
  90690. * { {
  90691. * value: 5, value: 3,
  90692. * groupId: 'creatures', groupId: 'animals',
  90693. * childGroupId: 'animals' childGroupId: 'dogs'
  90694. * }, },
  90695. * ... ...
  90696. * ] ]
  90697. *
  90698. * where dataA is belong to optionA and dataB is belong to optionB.
  90699. *
  90700. * When we `setOption(optionB)` from optionA, we choose childGroupId of dataItemA and groupId of
  90701. * dataItemB as keys so the two keys are matched (both are 'animals'), then universalTransition
  90702. * will work. This derection is "parent -> child".
  90703. *
  90704. * If we `setOption(optionA)` from optionB, we also choose groupId of dataItemB and childGroupId
  90705. * of dataItemA as keys and universalTransition will work. This derection is "child -> parent".
  90706. *
  90707. * If there is no childGroupId specified, which means no multiLevelDrillDown/Up is needed and no
  90708. * parent-child relationship exists. This direction is "none".
  90709. *
  90710. * So we need to know whether to use groupId or childGroupId as the key when we call the keyGetter
  90711. * functions. Thus, we need to decide the direction first.
  90712. *
  90713. * The rule is:
  90714. *
  90715. * if (all childGroupIds in oldDiffItems and all groupIds in newDiffItems have common value) {
  90716. * direction = 'parent -> child';
  90717. * } else if (all groupIds in oldDiffItems and all childGroupIds in newDiffItems have common value) {
  90718. * direction = 'child -> parent';
  90719. * } else {
  90720. * direction = 'none';
  90721. * }
  90722. */
  90723. var direction = TRANSITION_NONE;
  90724. // find all groupIds and childGroupIds from oldDiffItems
  90725. var oldGroupIds = createHashMap();
  90726. var oldChildGroupIds = createHashMap();
  90727. oldDiffItems.forEach(function (item) {
  90728. item.groupId && oldGroupIds.set(item.groupId, true);
  90729. item.childGroupId && oldChildGroupIds.set(item.childGroupId, true);
  90730. });
  90731. // traverse newDiffItems and decide the direction according to the rule
  90732. for (var i = 0; i < newDiffItems.length; i++) {
  90733. var newGroupId = newDiffItems[i].groupId;
  90734. if (oldChildGroupIds.get(newGroupId)) {
  90735. direction = TRANSITION_P2C;
  90736. break;
  90737. }
  90738. var newChildGroupId = newDiffItems[i].childGroupId;
  90739. if (newChildGroupId && oldGroupIds.get(newChildGroupId)) {
  90740. direction = TRANSITION_C2P;
  90741. break;
  90742. }
  90743. }
  90744. function createKeyGetter(isOld, onlyGetId) {
  90745. return function (diffItem) {
  90746. var data = diffItem.data;
  90747. var dataIndex = diffItem.dataIndex;
  90748. // TODO if specified dim
  90749. if (onlyGetId) {
  90750. return data.getId(dataIndex);
  90751. }
  90752. if (isOld) {
  90753. return direction === TRANSITION_P2C ? diffItem.childGroupId : diffItem.groupId;
  90754. } else {
  90755. return direction === TRANSITION_C2P ? diffItem.childGroupId : diffItem.groupId;
  90756. }
  90757. };
  90758. }
  90759. // Use id if it's very likely to be an one to one animation
  90760. // It's more robust than groupId
  90761. // TODO Check if key dimension is specified.
  90762. var useId = isAllIdSame(oldDiffItems, newDiffItems);
  90763. var isElementStillInChart = {};
  90764. if (!useId) {
  90765. // We may have different diff strategy with basicTransition if we use other dimension as key.
  90766. // If so, we can't simply check if oldEl is same with newEl. We need a map to check if oldEl is still being used in the new chart.
  90767. // We can't use the elements that already being morphed. Let it keep it's original basic transition.
  90768. for (var i = 0; i < newDiffItems.length; i++) {
  90769. var newItem = newDiffItems[i];
  90770. var el = newItem.data.getItemGraphicEl(newItem.dataIndex);
  90771. if (el) {
  90772. isElementStillInChart[el.id] = true;
  90773. }
  90774. }
  90775. }
  90776. function updateOneToOne(newIndex, oldIndex) {
  90777. var oldItem = oldDiffItems[oldIndex];
  90778. var newItem = newDiffItems[newIndex];
  90779. var newSeries = newItem.data.hostModel;
  90780. // TODO Mark this elements is morphed and don't morph them anymore
  90781. var oldEl = oldItem.data.getItemGraphicEl(oldItem.dataIndex);
  90782. var newEl = newItem.data.getItemGraphicEl(newItem.dataIndex);
  90783. // Can't handle same elements.
  90784. if (oldEl === newEl) {
  90785. newEl && animateElementStyles(newEl, newItem.dataIndex, newSeries);
  90786. return;
  90787. }
  90788. if (
  90789. // We can't use the elements that already being morphed
  90790. oldEl && isElementStillInChart[oldEl.id]) {
  90791. return;
  90792. }
  90793. if (newEl) {
  90794. // TODO: If keep animating the group in case
  90795. // some of the elements don't want to be morphed.
  90796. // TODO Label?
  90797. stopAnimation(newEl);
  90798. if (oldEl) {
  90799. stopAnimation(oldEl);
  90800. // If old element is doing leaving animation. stop it and remove it immediately.
  90801. removeEl$1(oldEl);
  90802. hasMorphAnimation = true;
  90803. applyMorphAnimation(getPathList(oldEl), getPathList(newEl), newItem.divide, newSeries, newIndex, updateMorphingPathProps);
  90804. } else {
  90805. fadeInElement(newEl, newSeries, newIndex);
  90806. }
  90807. }
  90808. // else keep oldEl leaving animation.
  90809. }
  90810. new DataDiffer(oldDiffItems, newDiffItems, createKeyGetter(true, useId), createKeyGetter(false, useId), null, 'multiple').update(updateOneToOne).updateManyToOne(function (newIndex, oldIndices) {
  90811. var newItem = newDiffItems[newIndex];
  90812. var newData = newItem.data;
  90813. var newSeries = newData.hostModel;
  90814. var newEl = newData.getItemGraphicEl(newItem.dataIndex);
  90815. var oldElsList = filter(map(oldIndices, function (idx) {
  90816. return oldDiffItems[idx].data.getItemGraphicEl(oldDiffItems[idx].dataIndex);
  90817. }), function (oldEl) {
  90818. return oldEl && oldEl !== newEl && !isElementStillInChart[oldEl.id];
  90819. });
  90820. if (newEl) {
  90821. stopAnimation(newEl);
  90822. if (oldElsList.length) {
  90823. // If old element is doing leaving animation. stop it and remove it immediately.
  90824. each(oldElsList, function (oldEl) {
  90825. stopAnimation(oldEl);
  90826. removeEl$1(oldEl);
  90827. });
  90828. hasMorphAnimation = true;
  90829. applyMorphAnimation(getPathList(oldElsList), getPathList(newEl), newItem.divide, newSeries, newIndex, updateMorphingPathProps);
  90830. } else {
  90831. fadeInElement(newEl, newSeries, newItem.dataIndex);
  90832. }
  90833. }
  90834. // else keep oldEl leaving animation.
  90835. }).updateOneToMany(function (newIndices, oldIndex) {
  90836. var oldItem = oldDiffItems[oldIndex];
  90837. var oldEl = oldItem.data.getItemGraphicEl(oldItem.dataIndex);
  90838. // We can't use the elements that already being morphed
  90839. if (oldEl && isElementStillInChart[oldEl.id]) {
  90840. return;
  90841. }
  90842. var newElsList = filter(map(newIndices, function (idx) {
  90843. return newDiffItems[idx].data.getItemGraphicEl(newDiffItems[idx].dataIndex);
  90844. }), function (el) {
  90845. return el && el !== oldEl;
  90846. });
  90847. var newSeris = newDiffItems[newIndices[0]].data.hostModel;
  90848. if (newElsList.length) {
  90849. each(newElsList, function (newEl) {
  90850. return stopAnimation(newEl);
  90851. });
  90852. if (oldEl) {
  90853. stopAnimation(oldEl);
  90854. // If old element is doing leaving animation. stop it and remove it immediately.
  90855. removeEl$1(oldEl);
  90856. hasMorphAnimation = true;
  90857. applyMorphAnimation(getPathList(oldEl), getPathList(newElsList), oldItem.divide,
  90858. // Use divide on old.
  90859. newSeris, newIndices[0], updateMorphingPathProps);
  90860. } else {
  90861. each(newElsList, function (newEl) {
  90862. return fadeInElement(newEl, newSeris, newIndices[0]);
  90863. });
  90864. }
  90865. }
  90866. // else keep oldEl leaving animation.
  90867. }).updateManyToMany(function (newIndices, oldIndices) {
  90868. // If two data are same and both have groupId.
  90869. // Normally they should be diff by id.
  90870. new DataDiffer(oldIndices, newIndices, function (rawIdx) {
  90871. return oldDiffItems[rawIdx].data.getId(oldDiffItems[rawIdx].dataIndex);
  90872. }, function (rawIdx) {
  90873. return newDiffItems[rawIdx].data.getId(newDiffItems[rawIdx].dataIndex);
  90874. }).update(function (newIndex, oldIndex) {
  90875. // Use the original index
  90876. updateOneToOne(newIndices[newIndex], oldIndices[oldIndex]);
  90877. }).execute();
  90878. }).execute();
  90879. if (hasMorphAnimation) {
  90880. each(newList, function (_a) {
  90881. var data = _a.data;
  90882. var seriesModel = data.hostModel;
  90883. var view = seriesModel && api.getViewOfSeriesModel(seriesModel);
  90884. var animationCfg = getAnimationConfig('update', seriesModel, 0); // use 0 index.
  90885. if (view && seriesModel.isAnimationEnabled() && animationCfg && animationCfg.duration > 0) {
  90886. view.group.traverse(function (el) {
  90887. if (el instanceof Path && !el.animators.length) {
  90888. // We can't accept there still exists element that has no animation
  90889. // if universalTransition is enabled
  90890. el.animateFrom({
  90891. style: {
  90892. opacity: 0
  90893. }
  90894. }, animationCfg);
  90895. }
  90896. });
  90897. }
  90898. });
  90899. }
  90900. }
  90901. function getSeriesTransitionKey(series) {
  90902. var seriesKey = series.getModel('universalTransition').get('seriesKey');
  90903. if (!seriesKey) {
  90904. // Use series id by default.
  90905. return series.id;
  90906. }
  90907. return seriesKey;
  90908. }
  90909. function convertArraySeriesKeyToString(seriesKey) {
  90910. if (isArray(seriesKey)) {
  90911. // Order independent.
  90912. return seriesKey.sort().join(',');
  90913. }
  90914. return seriesKey;
  90915. }
  90916. function getDivideShapeFromData(data) {
  90917. if (data.hostModel) {
  90918. return data.hostModel.getModel('universalTransition').get('divideShape');
  90919. }
  90920. }
  90921. function findTransitionSeriesBatches(globalStore, params) {
  90922. var updateBatches = createHashMap();
  90923. var oldDataMap = createHashMap();
  90924. // Map that only store key in array seriesKey.
  90925. // Which is used to query the old data when transition from one to multiple series.
  90926. var oldDataMapForSplit = createHashMap();
  90927. each(globalStore.oldSeries, function (series, idx) {
  90928. var oldDataGroupId = globalStore.oldDataGroupIds[idx];
  90929. var oldData = globalStore.oldData[idx];
  90930. var transitionKey = getSeriesTransitionKey(series);
  90931. var transitionKeyStr = convertArraySeriesKeyToString(transitionKey);
  90932. oldDataMap.set(transitionKeyStr, {
  90933. dataGroupId: oldDataGroupId,
  90934. data: oldData
  90935. });
  90936. if (isArray(transitionKey)) {
  90937. // Same key can't in different array seriesKey.
  90938. each(transitionKey, function (key) {
  90939. oldDataMapForSplit.set(key, {
  90940. key: transitionKeyStr,
  90941. dataGroupId: oldDataGroupId,
  90942. data: oldData
  90943. });
  90944. });
  90945. }
  90946. });
  90947. function checkTransitionSeriesKeyDuplicated(transitionKeyStr) {
  90948. if (updateBatches.get(transitionKeyStr)) {
  90949. warn("Duplicated seriesKey in universalTransition " + transitionKeyStr);
  90950. }
  90951. }
  90952. each(params.updatedSeries, function (series) {
  90953. if (series.isUniversalTransitionEnabled() && series.isAnimationEnabled()) {
  90954. var newDataGroupId = series.get('dataGroupId');
  90955. var newData = series.getData();
  90956. var transitionKey = getSeriesTransitionKey(series);
  90957. var transitionKeyStr = convertArraySeriesKeyToString(transitionKey);
  90958. // Only transition between series with same id.
  90959. var oldData = oldDataMap.get(transitionKeyStr);
  90960. // string transition key is the best match.
  90961. if (oldData) {
  90962. if ("development" !== 'production') {
  90963. checkTransitionSeriesKeyDuplicated(transitionKeyStr);
  90964. }
  90965. // TODO check if data is same?
  90966. updateBatches.set(transitionKeyStr, {
  90967. oldSeries: [{
  90968. dataGroupId: oldData.dataGroupId,
  90969. divide: getDivideShapeFromData(oldData.data),
  90970. data: oldData.data
  90971. }],
  90972. newSeries: [{
  90973. dataGroupId: newDataGroupId,
  90974. divide: getDivideShapeFromData(newData),
  90975. data: newData
  90976. }]
  90977. });
  90978. } else {
  90979. // Transition from multiple series.
  90980. // e.g. 'female', 'male' -> ['female', 'male']
  90981. if (isArray(transitionKey)) {
  90982. if ("development" !== 'production') {
  90983. checkTransitionSeriesKeyDuplicated(transitionKeyStr);
  90984. }
  90985. var oldSeries_1 = [];
  90986. each(transitionKey, function (key) {
  90987. var oldData = oldDataMap.get(key);
  90988. if (oldData.data) {
  90989. oldSeries_1.push({
  90990. dataGroupId: oldData.dataGroupId,
  90991. divide: getDivideShapeFromData(oldData.data),
  90992. data: oldData.data
  90993. });
  90994. }
  90995. });
  90996. if (oldSeries_1.length) {
  90997. updateBatches.set(transitionKeyStr, {
  90998. oldSeries: oldSeries_1,
  90999. newSeries: [{
  91000. dataGroupId: newDataGroupId,
  91001. data: newData,
  91002. divide: getDivideShapeFromData(newData)
  91003. }]
  91004. });
  91005. }
  91006. } else {
  91007. // Try transition to multiple series.
  91008. // e.g. ['female', 'male'] -> 'female', 'male'
  91009. var oldData_1 = oldDataMapForSplit.get(transitionKey);
  91010. if (oldData_1) {
  91011. var batch = updateBatches.get(oldData_1.key);
  91012. if (!batch) {
  91013. batch = {
  91014. oldSeries: [{
  91015. dataGroupId: oldData_1.dataGroupId,
  91016. data: oldData_1.data,
  91017. divide: getDivideShapeFromData(oldData_1.data)
  91018. }],
  91019. newSeries: []
  91020. };
  91021. updateBatches.set(oldData_1.key, batch);
  91022. }
  91023. batch.newSeries.push({
  91024. dataGroupId: newDataGroupId,
  91025. data: newData,
  91026. divide: getDivideShapeFromData(newData)
  91027. });
  91028. }
  91029. }
  91030. }
  91031. }
  91032. });
  91033. return updateBatches;
  91034. }
  91035. function querySeries(series, finder) {
  91036. for (var i = 0; i < series.length; i++) {
  91037. var found = finder.seriesIndex != null && finder.seriesIndex === series[i].seriesIndex || finder.seriesId != null && finder.seriesId === series[i].id;
  91038. if (found) {
  91039. return i;
  91040. }
  91041. }
  91042. }
  91043. function transitionSeriesFromOpt(transitionOpt, globalStore, params, api) {
  91044. var from = [];
  91045. var to = [];
  91046. each(normalizeToArray(transitionOpt.from), function (finder) {
  91047. var idx = querySeries(globalStore.oldSeries, finder);
  91048. if (idx >= 0) {
  91049. from.push({
  91050. dataGroupId: globalStore.oldDataGroupIds[idx],
  91051. data: globalStore.oldData[idx],
  91052. // TODO can specify divideShape in transition.
  91053. divide: getDivideShapeFromData(globalStore.oldData[idx]),
  91054. groupIdDim: finder.dimension
  91055. });
  91056. }
  91057. });
  91058. each(normalizeToArray(transitionOpt.to), function (finder) {
  91059. var idx = querySeries(params.updatedSeries, finder);
  91060. if (idx >= 0) {
  91061. var data = params.updatedSeries[idx].getData();
  91062. to.push({
  91063. dataGroupId: globalStore.oldDataGroupIds[idx],
  91064. data: data,
  91065. divide: getDivideShapeFromData(data),
  91066. groupIdDim: finder.dimension
  91067. });
  91068. }
  91069. });
  91070. if (from.length > 0 && to.length > 0) {
  91071. transitionBetween(from, to, api);
  91072. }
  91073. }
  91074. function installUniversalTransition(registers) {
  91075. registers.registerUpdateLifecycle('series:beforeupdate', function (ecMOdel, api, params) {
  91076. each(normalizeToArray(params.seriesTransition), function (transOpt) {
  91077. each(normalizeToArray(transOpt.to), function (finder) {
  91078. var series = params.updatedSeries;
  91079. for (var i = 0; i < series.length; i++) {
  91080. if (finder.seriesIndex != null && finder.seriesIndex === series[i].seriesIndex || finder.seriesId != null && finder.seriesId === series[i].id) {
  91081. series[i][SERIES_UNIVERSAL_TRANSITION_PROP] = true;
  91082. }
  91083. }
  91084. });
  91085. });
  91086. });
  91087. registers.registerUpdateLifecycle('series:transition', function (ecModel, api, params) {
  91088. // TODO api provide an namespace that can save stuff per instance
  91089. var globalStore = getUniversalTransitionGlobalStore(api);
  91090. // TODO multiple to multiple series.
  91091. if (globalStore.oldSeries && params.updatedSeries && params.optionChanged) {
  91092. // TODO transitionOpt was used in an old implementation and can be removed now
  91093. // Use give transition config if its' give;
  91094. var transitionOpt = params.seriesTransition;
  91095. if (transitionOpt) {
  91096. each(normalizeToArray(transitionOpt), function (opt) {
  91097. transitionSeriesFromOpt(opt, globalStore, params, api);
  91098. });
  91099. } else {
  91100. // Else guess from series based on transition series key.
  91101. var updateBatches_1 = findTransitionSeriesBatches(globalStore, params);
  91102. each(updateBatches_1.keys(), function (key) {
  91103. var batch = updateBatches_1.get(key);
  91104. transitionBetween(batch.oldSeries, batch.newSeries, api);
  91105. });
  91106. }
  91107. // Reset
  91108. each(params.updatedSeries, function (series) {
  91109. // Reset;
  91110. if (series[SERIES_UNIVERSAL_TRANSITION_PROP]) {
  91111. series[SERIES_UNIVERSAL_TRANSITION_PROP] = false;
  91112. }
  91113. });
  91114. }
  91115. // Save all series of current update. Not only the updated one.
  91116. var allSeries = ecModel.getSeries();
  91117. var savedSeries = globalStore.oldSeries = [];
  91118. var savedDataGroupIds = globalStore.oldDataGroupIds = [];
  91119. var savedData = globalStore.oldData = [];
  91120. for (var i = 0; i < allSeries.length; i++) {
  91121. var data = allSeries[i].getData();
  91122. // Only save the data that can have transition.
  91123. // Avoid large data costing too much extra memory
  91124. if (data.count() < DATA_COUNT_THRESHOLD) {
  91125. savedSeries.push(allSeries[i]);
  91126. savedDataGroupIds.push(allSeries[i].get('dataGroupId'));
  91127. savedData.push(data);
  91128. }
  91129. }
  91130. });
  91131. }
  91132. /**
  91133. * @caution
  91134. * Must not export anything except `installScaleBreakHelper`
  91135. */
  91136. var ScaleBreakContextImpl = /** @class */function () {
  91137. function ScaleBreakContextImpl() {
  91138. // [CAVEAT]: Should set only by `ScaleBreakContext#setBreaks`!
  91139. this.breaks = [];
  91140. // [CAVEAT]: Should update only by `ScaleBreakContext#update`!
  91141. // They are the values that scaleExtent[0] and scaleExtent[1] are mapped to a numeric axis
  91142. // that breaks are applied, primarily for optimization of `Scale#normalize`.
  91143. this._elapsedExtent = [Infinity, -Infinity];
  91144. }
  91145. ScaleBreakContextImpl.prototype.setBreaks = function (parsed) {
  91146. // @ts-ignore
  91147. this.breaks = parsed.breaks;
  91148. };
  91149. /**
  91150. * [CAVEAT]: Must be called immediately each time scale extent and breaks are updated!
  91151. */
  91152. ScaleBreakContextImpl.prototype.update = function (scaleExtent) {
  91153. updateAxisBreakGapReal(this, scaleExtent);
  91154. var elapsedExtent = this._elapsedExtent;
  91155. elapsedExtent[0] = this.elapse(scaleExtent[0]);
  91156. elapsedExtent[1] = this.elapse(scaleExtent[1]);
  91157. };
  91158. ScaleBreakContextImpl.prototype.hasBreaks = function () {
  91159. return !!this.breaks.length;
  91160. };
  91161. /**
  91162. * When iteratively generating ticks by nice interval, currently the `interval`, which is
  91163. * calculated by break-elapsed extent span, is probably very small comparing to the original
  91164. * extent, leading to a large number of iteration and tick generation, even over `safeLimit`.
  91165. * Thus stepping over breaks is necessary in that loop.
  91166. *
  91167. * "Nice" should be ensured on ticks when step over the breaks. Thus this method returns
  91168. * a integer multiple of the "nice tick interval".
  91169. *
  91170. * This method does little work; it is just for unifying and restricting the behavior.
  91171. */
  91172. ScaleBreakContextImpl.prototype.calcNiceTickMultiple = function (tickVal, estimateNiceMultiple) {
  91173. for (var idx = 0; idx < this.breaks.length; idx++) {
  91174. var brk = this.breaks[idx];
  91175. if (brk.vmin < tickVal && tickVal < brk.vmax) {
  91176. var multiple = estimateNiceMultiple(tickVal, brk.vmax);
  91177. if ("development" !== 'production') {
  91178. // If not, it may cause dead loop or not nice tick.
  91179. assert(multiple >= 0 && Math.round(multiple) === multiple);
  91180. }
  91181. return multiple;
  91182. }
  91183. }
  91184. return 0;
  91185. };
  91186. ScaleBreakContextImpl.prototype.getExtentSpan = function () {
  91187. return this._elapsedExtent[1] - this._elapsedExtent[0];
  91188. };
  91189. ScaleBreakContextImpl.prototype.normalize = function (val) {
  91190. var elapsedSpan = this._elapsedExtent[1] - this._elapsedExtent[0];
  91191. // The same logic as `Scale#normalize`.
  91192. if (elapsedSpan === 0) {
  91193. return 0.5;
  91194. }
  91195. return (this.elapse(val) - this._elapsedExtent[0]) / elapsedSpan;
  91196. };
  91197. ScaleBreakContextImpl.prototype.scale = function (val) {
  91198. return this.unelapse(val * (this._elapsedExtent[1] - this._elapsedExtent[0]) + this._elapsedExtent[0]);
  91199. };
  91200. /**
  91201. * Suppose:
  91202. * AXIS_BREAK_LAST_BREAK_END_BASE: 0
  91203. * AXIS_BREAK_ELAPSED_BASE: 0
  91204. * breaks: [
  91205. * {start: -400, end: -300, gap: 27},
  91206. * {start: -100, end: 100, gap: 10},
  91207. * {start: 200, end: 400, gap: 300},
  91208. * ]
  91209. * The mapping will be:
  91210. * | |
  91211. * 400 + -> + 237
  91212. * | | | | (gap: 300)
  91213. * 200 + -> + -63
  91214. * | |
  91215. * 100 + -> + -163
  91216. * | | | | (gap: 10)
  91217. * -100 + -> + -173
  91218. * | |
  91219. * -300 + -> + -373
  91220. * | | | | (gap: 27)
  91221. * -400 + -> + -400
  91222. * | |
  91223. * origianl elapsed
  91224. *
  91225. * Note:
  91226. * The mapping has nothing to do with "scale extent".
  91227. */
  91228. ScaleBreakContextImpl.prototype.elapse = function (val) {
  91229. // If the value is in the break, return the normalized value in the break
  91230. var elapsedVal = AXIS_BREAK_ELAPSED_BASE;
  91231. var lastBreakEnd = AXIS_BREAK_LAST_BREAK_END_BASE;
  91232. var stillOver = true;
  91233. for (var i = 0; i < this.breaks.length; i++) {
  91234. var brk = this.breaks[i];
  91235. if (val <= brk.vmax) {
  91236. if (val > brk.vmin) {
  91237. elapsedVal += brk.vmin - lastBreakEnd + (val - brk.vmin) / (brk.vmax - brk.vmin) * brk.gapReal;
  91238. } else {
  91239. elapsedVal += val - lastBreakEnd;
  91240. }
  91241. lastBreakEnd = brk.vmax;
  91242. stillOver = false;
  91243. break;
  91244. }
  91245. elapsedVal += brk.vmin - lastBreakEnd + brk.gapReal;
  91246. lastBreakEnd = brk.vmax;
  91247. }
  91248. if (stillOver) {
  91249. elapsedVal += val - lastBreakEnd;
  91250. }
  91251. return elapsedVal;
  91252. };
  91253. ScaleBreakContextImpl.prototype.unelapse = function (elapsedVal) {
  91254. var lastElapsedEnd = AXIS_BREAK_ELAPSED_BASE;
  91255. var lastBreakEnd = AXIS_BREAK_LAST_BREAK_END_BASE;
  91256. var stillOver = true;
  91257. var unelapsedVal = 0;
  91258. for (var i = 0; i < this.breaks.length; i++) {
  91259. var brk = this.breaks[i];
  91260. var elapsedStart = lastElapsedEnd + brk.vmin - lastBreakEnd;
  91261. var elapsedEnd = elapsedStart + brk.gapReal;
  91262. if (elapsedVal <= elapsedEnd) {
  91263. if (elapsedVal > elapsedStart) {
  91264. unelapsedVal = brk.vmin + (elapsedVal - elapsedStart) / (elapsedEnd - elapsedStart) * (brk.vmax - brk.vmin);
  91265. } else {
  91266. unelapsedVal = lastBreakEnd + elapsedVal - lastElapsedEnd;
  91267. }
  91268. lastBreakEnd = brk.vmax;
  91269. stillOver = false;
  91270. break;
  91271. }
  91272. lastElapsedEnd = elapsedEnd;
  91273. lastBreakEnd = brk.vmax;
  91274. }
  91275. if (stillOver) {
  91276. unelapsedVal = lastBreakEnd + elapsedVal - lastElapsedEnd;
  91277. }
  91278. return unelapsedVal;
  91279. };
  91280. return ScaleBreakContextImpl;
  91281. }();
  91282. function createScaleBreakContext() {
  91283. return new ScaleBreakContextImpl();
  91284. }
  91285. // Both can start with any finite value, and are not necessaryily equal. But they need to
  91286. // be the same in `axisBreakElapse` and `axisBreakUnelapse` respectively.
  91287. var AXIS_BREAK_ELAPSED_BASE = 0;
  91288. var AXIS_BREAK_LAST_BREAK_END_BASE = 0;
  91289. /**
  91290. * `gapReal` in brkCtx.breaks will be calculated.
  91291. */
  91292. function updateAxisBreakGapReal(brkCtx, scaleExtent) {
  91293. // Considered the effect:
  91294. // - Use dataZoom to move some of the breaks outside the extent.
  91295. // - Some scenarios that `series.clip: false`.
  91296. //
  91297. // How to calculate `prctBrksGapRealSum`:
  91298. // Based on the formula:
  91299. // xxx.span = brk.vmax - brk.vmin
  91300. // xxx.tpPrct.val / xxx.tpAbs.val means ParsedAxisBreak['gapParsed']['val']
  91301. // .S/.E means a break that is semi in scaleExtent[0] or scaleExtent[1]
  91302. // valP = (
  91303. // + (fullyInExtBrksSum.tpAbs.gapReal - fullyInExtBrksSum.tpAbs.span)
  91304. // + (semiInExtBrk.S.tpAbs.gapReal - semiInExtBrk.S.tpAbs.span) * semiInExtBrk.S.tpAbs.inExtFrac
  91305. // + (semiInExtBrk.E.tpAbs.gapReal - semiInExtBrk.E.tpAbs.span) * semiInExtBrk.E.tpAbs.inExtFrac
  91306. // )
  91307. // valQ = (
  91308. // - fullyInExtBrksSum.tpPrct.span
  91309. // - semiInExtBrk.S.tpPrct.span * semiInExtBrk.S.tpPrct.inExtFrac
  91310. // - semiInExtBrk.E.tpPrct.span * semiInExtBrk.E.tpPrct.inExtFrac
  91311. // )
  91312. // gapPrctSum = sum(xxx.tpPrct.val)
  91313. // gapPrctSum = prctBrksGapRealSum / (
  91314. // + (scaleExtent[1] - scaleExtent[0]) + valP + valQ
  91315. // + fullyInExtBrksSum.tpPrct.gapReal
  91316. // + semiInExtBrk.S.tpPrct.gapReal * semiInExtBrk.S.tpPrct.inExtFrac
  91317. // + semiInExtBrk.E.tpPrct.gapReal * semiInExtBrk.E.tpPrct.inExtFrac
  91318. // )
  91319. // Assume:
  91320. // xxx.tpPrct.gapReal = xxx.tpPrct.val / gapPrctSum * prctBrksGapRealSum
  91321. // (NOTE: This is not accurate when semi-in-extent break exist because its
  91322. // proportion is not linear, but this assumption approximately works.)
  91323. // Derived as follows:
  91324. // prctBrksGapRealSum = gapPrctSum * ( (scaleExtent[1] - scaleExtent[0]) + valP + valQ )
  91325. // / (1
  91326. // - fullyInExtBrksSum.tpPrct.val
  91327. // - semiInExtBrk.S.tpPrct.val * semiInExtBrk.S.tpPrct.inExtFrac
  91328. // - semiInExtBrk.E.tpPrct.val * semiInExtBrk.E.tpPrct.inExtFrac
  91329. // )
  91330. var gapPrctSum = 0;
  91331. var fullyInExtBrksSum = {
  91332. tpAbs: {
  91333. span: 0,
  91334. val: 0
  91335. },
  91336. tpPrct: {
  91337. span: 0,
  91338. val: 0
  91339. }
  91340. };
  91341. var init = function () {
  91342. return {
  91343. has: false,
  91344. span: NaN,
  91345. inExtFrac: NaN,
  91346. val: NaN
  91347. };
  91348. };
  91349. var semiInExtBrk = {
  91350. S: {
  91351. tpAbs: init(),
  91352. tpPrct: init()
  91353. },
  91354. E: {
  91355. tpAbs: init(),
  91356. tpPrct: init()
  91357. }
  91358. };
  91359. each(brkCtx.breaks, function (brk) {
  91360. var gapParsed = brk.gapParsed;
  91361. if (gapParsed.type === 'tpPrct') {
  91362. gapPrctSum += gapParsed.val;
  91363. }
  91364. var clampedBrk = clampBreakByExtent(brk, scaleExtent);
  91365. if (clampedBrk) {
  91366. var vminClamped = clampedBrk.vmin !== brk.vmin;
  91367. var vmaxClamped = clampedBrk.vmax !== brk.vmax;
  91368. var clampedSpan = clampedBrk.vmax - clampedBrk.vmin;
  91369. if (vminClamped && vmaxClamped) ; else if (vminClamped || vmaxClamped) {
  91370. var sOrE = vminClamped ? 'S' : 'E';
  91371. semiInExtBrk[sOrE][gapParsed.type].has = true;
  91372. semiInExtBrk[sOrE][gapParsed.type].span = clampedSpan;
  91373. semiInExtBrk[sOrE][gapParsed.type].inExtFrac = clampedSpan / (brk.vmax - brk.vmin);
  91374. semiInExtBrk[sOrE][gapParsed.type].val = gapParsed.val;
  91375. } else {
  91376. fullyInExtBrksSum[gapParsed.type].span += clampedSpan;
  91377. fullyInExtBrksSum[gapParsed.type].val += gapParsed.val;
  91378. }
  91379. }
  91380. });
  91381. var prctBrksGapRealSum = gapPrctSum * (0 + (scaleExtent[1] - scaleExtent[0]) + (fullyInExtBrksSum.tpAbs.val - fullyInExtBrksSum.tpAbs.span) + (semiInExtBrk.S.tpAbs.has ? (semiInExtBrk.S.tpAbs.val - semiInExtBrk.S.tpAbs.span) * semiInExtBrk.S.tpAbs.inExtFrac : 0) + (semiInExtBrk.E.tpAbs.has ? (semiInExtBrk.E.tpAbs.val - semiInExtBrk.E.tpAbs.span) * semiInExtBrk.E.tpAbs.inExtFrac : 0) - fullyInExtBrksSum.tpPrct.span - (semiInExtBrk.S.tpPrct.has ? semiInExtBrk.S.tpPrct.span * semiInExtBrk.S.tpPrct.inExtFrac : 0) - (semiInExtBrk.E.tpPrct.has ? semiInExtBrk.E.tpPrct.span * semiInExtBrk.E.tpPrct.inExtFrac : 0)) / (1 - fullyInExtBrksSum.tpPrct.val - (semiInExtBrk.S.tpPrct.has ? semiInExtBrk.S.tpPrct.val * semiInExtBrk.S.tpPrct.inExtFrac : 0) - (semiInExtBrk.E.tpPrct.has ? semiInExtBrk.E.tpPrct.val * semiInExtBrk.E.tpPrct.inExtFrac : 0));
  91382. each(brkCtx.breaks, function (brk) {
  91383. var gapParsed = brk.gapParsed;
  91384. if (gapParsed.type === 'tpPrct') {
  91385. brk.gapReal = gapPrctSum !== 0
  91386. // prctBrksGapRealSum is supposed to be non-negative but add a safe guard
  91387. ? Math.max(prctBrksGapRealSum, 0) * gapParsed.val / gapPrctSum : 0;
  91388. }
  91389. if (gapParsed.type === 'tpAbs') {
  91390. brk.gapReal = gapParsed.val;
  91391. }
  91392. if (brk.gapReal == null) {
  91393. brk.gapReal = 0;
  91394. }
  91395. });
  91396. }
  91397. function pruneTicksByBreak(pruneByBreak, ticks, breaks, getValue, interval, scaleExtent) {
  91398. if (pruneByBreak === 'no') {
  91399. return;
  91400. }
  91401. each(breaks, function (brk) {
  91402. // break.vmin/vmax that out of extent must not impact the visible of
  91403. // normal ticks and labels.
  91404. var clampedBrk = clampBreakByExtent(brk, scaleExtent);
  91405. if (!clampedBrk) {
  91406. return;
  91407. }
  91408. // Remove some normal ticks to avoid zigzag shapes overlapping with split lines
  91409. // and to avoid break labels overlapping with normal tick labels (thouth it can
  91410. // also be avoided by `axisLabel.hideOverlap`).
  91411. // It's OK to O(n^2) since the number of `ticks` are small.
  91412. for (var j = ticks.length - 1; j >= 0; j--) {
  91413. var tick = ticks[j];
  91414. var val = getValue(tick);
  91415. // 1. Ensure there is no ticks inside `break.vmin` and `break.vmax`.
  91416. // 2. Use an empirically gap value here. Theoritically `zigzagAmplitude` is
  91417. // supposed to be involved to provide better precision but it will brings
  91418. // more complexity. The empirically gap value is conservative because break
  91419. // labels and normal tick lables are prone to overlapping.
  91420. var gap = interval * 3 / 4;
  91421. if (val > clampedBrk.vmin - gap && val < clampedBrk.vmax + gap && (pruneByBreak !== 'preserve_extent_bound' || val !== scaleExtent[0] && val !== scaleExtent[1])) {
  91422. ticks.splice(j, 1);
  91423. }
  91424. }
  91425. });
  91426. }
  91427. function addBreaksToTicks(
  91428. // The input ticks should be in accending order.
  91429. ticks, breaks, scaleExtent,
  91430. // Keep the break ends at the same level to avoid an awkward appearance.
  91431. getTimeProps) {
  91432. each(breaks, function (brk) {
  91433. var clampedBrk = clampBreakByExtent(brk, scaleExtent);
  91434. if (!clampedBrk) {
  91435. return;
  91436. }
  91437. // - When neight `break.vmin` nor `break.vmax` is in scale extent,
  91438. // break label should not be displayed and we do not add them to the result.
  91439. // - When only one of `break.vmin` and `break.vmax` is inside the extent and the
  91440. // other is outsite, we comply with the extent and display only part of the breaks area,
  91441. // because the extent might be determined by user settings (such as `axis.min/max`)
  91442. ticks.push({
  91443. value: clampedBrk.vmin,
  91444. "break": {
  91445. type: 'vmin',
  91446. parsedBreak: clampedBrk
  91447. },
  91448. time: getTimeProps ? getTimeProps(clampedBrk) : undefined
  91449. });
  91450. // When gap is 0, start tick overlap with end tick, but we still count both of them. Break
  91451. // area shape can address that overlapping. `axisLabel` need draw both start and end separately,
  91452. // otherwise it brings complexity to the logic of label overlapping resolving (e.g., when label
  91453. // rotated), and introduces inconsistency to users in `axisLabel.formatter` between gap is 0 or not.
  91454. ticks.push({
  91455. value: clampedBrk.vmax,
  91456. "break": {
  91457. type: 'vmax',
  91458. parsedBreak: clampedBrk
  91459. },
  91460. time: getTimeProps ? getTimeProps(clampedBrk) : undefined
  91461. });
  91462. });
  91463. if (breaks.length) {
  91464. ticks.sort(function (a, b) {
  91465. return a.value - b.value;
  91466. });
  91467. }
  91468. }
  91469. /**
  91470. * If break and extent does not intersect, return null/undefined.
  91471. * If the intersection is only a point at scaleExtent[0] or scaleExtent[1], return null/undefined.
  91472. */
  91473. function clampBreakByExtent(brk, scaleExtent) {
  91474. var vmin = Math.max(brk.vmin, scaleExtent[0]);
  91475. var vmax = Math.min(brk.vmax, scaleExtent[1]);
  91476. return vmin < vmax || vmin === vmax && vmin > scaleExtent[0] && vmin < scaleExtent[1] ? {
  91477. vmin: vmin,
  91478. vmax: vmax,
  91479. breakOption: brk.breakOption,
  91480. gapParsed: brk.gapParsed,
  91481. gapReal: brk.gapReal
  91482. } : null;
  91483. }
  91484. function parseAxisBreakOption(
  91485. // raw user input breaks, retrieved from axis model.
  91486. breakOptionList, parse, opt) {
  91487. var parsedBreaks = [];
  91488. if (!breakOptionList) {
  91489. return {
  91490. breaks: parsedBreaks
  91491. };
  91492. }
  91493. function validatePercent(normalizedPercent, msg) {
  91494. if (normalizedPercent >= 0 && normalizedPercent < 1 - 1e-5) {
  91495. // Avoid division error.
  91496. return true;
  91497. }
  91498. if ("development" !== 'production') {
  91499. error(msg + " must be >= 0 and < 1, rather than " + normalizedPercent + " .");
  91500. }
  91501. return false;
  91502. }
  91503. each(breakOptionList, function (brkOption) {
  91504. if (!brkOption || brkOption.start == null || brkOption.end == null) {
  91505. if ("development" !== 'production') {
  91506. error('The input axis breaks start/end should not be empty.');
  91507. }
  91508. return;
  91509. }
  91510. if (brkOption.isExpanded) {
  91511. return;
  91512. }
  91513. var parsedBrk = {
  91514. breakOption: clone(brkOption),
  91515. vmin: parse(brkOption.start),
  91516. vmax: parse(brkOption.end),
  91517. gapParsed: {
  91518. type: 'tpAbs',
  91519. val: 0
  91520. },
  91521. gapReal: null
  91522. };
  91523. if (brkOption.gap != null) {
  91524. var isPrct = false;
  91525. if (isString(brkOption.gap)) {
  91526. var trimmedGap = trim(brkOption.gap);
  91527. if (trimmedGap.match(/%$/)) {
  91528. var normalizedPercent = parseFloat(trimmedGap) / 100;
  91529. if (!validatePercent(normalizedPercent, 'Percent gap')) {
  91530. normalizedPercent = 0;
  91531. }
  91532. parsedBrk.gapParsed.type = 'tpPrct';
  91533. parsedBrk.gapParsed.val = normalizedPercent;
  91534. isPrct = true;
  91535. }
  91536. }
  91537. if (!isPrct) {
  91538. var absolute = parse(brkOption.gap);
  91539. if (!isFinite(absolute) || absolute < 0) {
  91540. if ("development" !== 'production') {
  91541. error("Axis breaks gap must positive finite rather than (" + brkOption.gap + ").");
  91542. }
  91543. absolute = 0;
  91544. }
  91545. parsedBrk.gapParsed.type = 'tpAbs';
  91546. parsedBrk.gapParsed.val = absolute;
  91547. }
  91548. }
  91549. if (parsedBrk.vmin === parsedBrk.vmax) {
  91550. parsedBrk.gapParsed.type = 'tpAbs';
  91551. parsedBrk.gapParsed.val = 0;
  91552. }
  91553. if (opt && opt.noNegative) {
  91554. each(['vmin', 'vmax'], function (se) {
  91555. if (parsedBrk[se] < 0) {
  91556. if ("development" !== 'production') {
  91557. error("Axis break." + se + " must not be negative.");
  91558. }
  91559. parsedBrk[se] = 0;
  91560. }
  91561. });
  91562. }
  91563. // Ascending numerical order is the prerequisite of the calculation in Scale#normalize.
  91564. // User are allowed to input desending vmin/vmax for simplifying the usage.
  91565. if (parsedBrk.vmin > parsedBrk.vmax) {
  91566. var tmp = parsedBrk.vmax;
  91567. parsedBrk.vmax = parsedBrk.vmin;
  91568. parsedBrk.vmin = tmp;
  91569. }
  91570. parsedBreaks.push(parsedBrk);
  91571. });
  91572. // Ascending numerical order is the prerequisite of the calculation in Scale#normalize.
  91573. parsedBreaks.sort(function (item1, item2) {
  91574. return item1.vmin - item2.vmin;
  91575. });
  91576. // Make sure that the intervals in breaks are not overlap.
  91577. var lastEnd = -Infinity;
  91578. each(parsedBreaks, function (brk, idx) {
  91579. if (lastEnd > brk.vmin) {
  91580. if ("development" !== 'production') {
  91581. error('Axis breaks must not overlap.');
  91582. }
  91583. parsedBreaks[idx] = null;
  91584. }
  91585. lastEnd = brk.vmax;
  91586. });
  91587. return {
  91588. breaks: parsedBreaks.filter(function (brk) {
  91589. return !!brk;
  91590. })
  91591. };
  91592. }
  91593. function identifyAxisBreak(brk, identifier) {
  91594. return serializeAxisBreakIdentifier(identifier) === serializeAxisBreakIdentifier(brk);
  91595. }
  91596. function serializeAxisBreakIdentifier(identifier) {
  91597. // We use user input start/end to identify break. Considered cases like `start: new Date(xxx)`,
  91598. // Theoretically `Scale#parse` should be used here, but not used currently to reduce dependencies,
  91599. // since simply converting to string happens to be correct.
  91600. return identifier.start + '_\0_' + identifier.end;
  91601. }
  91602. /**
  91603. * - A break pair represents `[vmin, vmax]`,
  91604. * - Only both vmin and vmax item exist, they are counted as a pair.
  91605. */
  91606. function retrieveAxisBreakPairs(itemList, getVisualAxisBreak, returnIdx) {
  91607. var idxPairList = [];
  91608. each(itemList, function (el, idx) {
  91609. var vBreak = getVisualAxisBreak(el);
  91610. if (vBreak && vBreak.type === 'vmin') {
  91611. idxPairList.push([idx]);
  91612. }
  91613. });
  91614. each(itemList, function (el, idx) {
  91615. var vBreak = getVisualAxisBreak(el);
  91616. if (vBreak && vBreak.type === 'vmax') {
  91617. var idxPair = find(idxPairList,
  91618. // parsedBreak may be changed, can only use breakOption to match them.
  91619. function (pr) {
  91620. return identifyAxisBreak(getVisualAxisBreak(itemList[pr[0]]).parsedBreak.breakOption, vBreak.parsedBreak.breakOption);
  91621. });
  91622. idxPair && idxPair.push(idx);
  91623. }
  91624. });
  91625. var result = [];
  91626. each(idxPairList, function (idxPair) {
  91627. if (idxPair.length === 2) {
  91628. result.push(returnIdx ? idxPair : [itemList[idxPair[0]], itemList[idxPair[1]]]);
  91629. }
  91630. });
  91631. return result;
  91632. }
  91633. function getTicksLogTransformBreak(tick, logBase, logOriginalBreaks, fixRoundingError) {
  91634. var vBreak;
  91635. var brkRoundingCriterion;
  91636. if (tick["break"]) {
  91637. var brk = tick["break"].parsedBreak;
  91638. var originalBreak = find(logOriginalBreaks, function (brk) {
  91639. return identifyAxisBreak(brk.breakOption, tick["break"].parsedBreak.breakOption);
  91640. });
  91641. var vmin = fixRoundingError(Math.pow(logBase, brk.vmin), originalBreak.vmin);
  91642. var vmax = fixRoundingError(Math.pow(logBase, brk.vmax), originalBreak.vmax);
  91643. var gapParsed = {
  91644. type: brk.gapParsed.type,
  91645. val: brk.gapParsed.type === 'tpAbs' ? round(Math.pow(logBase, brk.vmin + brk.gapParsed.val)) - vmin : brk.gapParsed.val
  91646. };
  91647. vBreak = {
  91648. type: tick["break"].type,
  91649. parsedBreak: {
  91650. breakOption: brk.breakOption,
  91651. vmin: vmin,
  91652. vmax: vmax,
  91653. gapParsed: gapParsed,
  91654. gapReal: brk.gapReal
  91655. }
  91656. };
  91657. brkRoundingCriterion = originalBreak[tick["break"].type];
  91658. }
  91659. return {
  91660. brkRoundingCriterion: brkRoundingCriterion,
  91661. vBreak: vBreak
  91662. };
  91663. }
  91664. function logarithmicParseBreaksFromOption(breakOptionList, logBase, parse) {
  91665. var opt = {
  91666. noNegative: true
  91667. };
  91668. var parsedOriginal = parseAxisBreakOption(breakOptionList, parse, opt);
  91669. var parsedLogged = parseAxisBreakOption(breakOptionList, parse, opt);
  91670. var loggedBase = Math.log(logBase);
  91671. parsedLogged.breaks = map(parsedLogged.breaks, function (brk) {
  91672. var vmin = Math.log(brk.vmin) / loggedBase;
  91673. var vmax = Math.log(brk.vmax) / loggedBase;
  91674. var gapParsed = {
  91675. type: brk.gapParsed.type,
  91676. val: brk.gapParsed.type === 'tpAbs' ? Math.log(brk.vmin + brk.gapParsed.val) / loggedBase - vmin : brk.gapParsed.val
  91677. };
  91678. return {
  91679. vmin: vmin,
  91680. vmax: vmax,
  91681. gapParsed: gapParsed,
  91682. gapReal: brk.gapReal,
  91683. breakOption: brk.breakOption
  91684. };
  91685. });
  91686. return {
  91687. parsedOriginal: parsedOriginal,
  91688. parsedLogged: parsedLogged
  91689. };
  91690. }
  91691. var BREAK_MIN_MAX_TO_PARAM = {
  91692. vmin: 'start',
  91693. vmax: 'end'
  91694. };
  91695. function makeAxisLabelFormatterParamBreak(extraParam, vBreak) {
  91696. if (vBreak) {
  91697. extraParam = extraParam || {};
  91698. extraParam["break"] = {
  91699. type: BREAK_MIN_MAX_TO_PARAM[vBreak.type],
  91700. start: vBreak.parsedBreak.vmin,
  91701. end: vBreak.parsedBreak.vmax
  91702. };
  91703. }
  91704. return extraParam;
  91705. }
  91706. function installScaleBreakHelper() {
  91707. registerScaleBreakHelperImpl({
  91708. createScaleBreakContext: createScaleBreakContext,
  91709. pruneTicksByBreak: pruneTicksByBreak,
  91710. addBreaksToTicks: addBreaksToTicks,
  91711. parseAxisBreakOption: parseAxisBreakOption,
  91712. identifyAxisBreak: identifyAxisBreak,
  91713. serializeAxisBreakIdentifier: serializeAxisBreakIdentifier,
  91714. retrieveAxisBreakPairs: retrieveAxisBreakPairs,
  91715. getTicksLogTransformBreak: getTicksLogTransformBreak,
  91716. logarithmicParseBreaksFromOption: logarithmicParseBreaksFromOption,
  91717. makeAxisLabelFormatterParamBreak: makeAxisLabelFormatterParamBreak
  91718. });
  91719. }
  91720. /**
  91721. * @caution
  91722. * Must not export anything except `installAxisBreakHelper`
  91723. */
  91724. /**
  91725. * The zigzag shapes for axis breaks are generated according to some random
  91726. * factors. It should persist as much as possible to avoid constantly
  91727. * changing by every user operation.
  91728. */
  91729. var viewCache = makeInner();
  91730. function ensureVisualInCache(visualList, targetBreak) {
  91731. var visual = find(visualList, function (item) {
  91732. return getScaleBreakHelper().identifyAxisBreak(item.parsedBreak.breakOption, targetBreak.breakOption);
  91733. });
  91734. if (!visual) {
  91735. visualList.push(visual = {
  91736. zigzagRandomList: [],
  91737. parsedBreak: targetBreak,
  91738. shouldRemove: false
  91739. });
  91740. }
  91741. return visual;
  91742. }
  91743. function resetCacheVisualRemoveFlag(visualList) {
  91744. each(visualList, function (item) {
  91745. return item.shouldRemove = true;
  91746. });
  91747. }
  91748. function removeUnusedCacheVisual(visualList) {
  91749. for (var i = visualList.length - 1; i >= 0; i--) {
  91750. if (visualList[i].shouldRemove) {
  91751. visualList.splice(i, 1);
  91752. }
  91753. }
  91754. }
  91755. function rectCoordBuildBreakAxis(axisGroup, axisView, axisModel, coordSysRect, api) {
  91756. var axis = axisModel.axis;
  91757. if (axis.scale.isBlank() || !getScaleBreakHelper()) {
  91758. return;
  91759. }
  91760. var breakPairs = getScaleBreakHelper().retrieveAxisBreakPairs(axis.scale.getTicks({
  91761. breakTicks: 'only_break'
  91762. }), function (tick) {
  91763. return tick["break"];
  91764. }, false);
  91765. if (!breakPairs.length) {
  91766. return;
  91767. }
  91768. var breakAreaModel = axisModel.getModel('breakArea');
  91769. var zigzagAmplitude = breakAreaModel.get('zigzagAmplitude');
  91770. var zigzagMinSpan = breakAreaModel.get('zigzagMinSpan');
  91771. var zigzagMaxSpan = breakAreaModel.get('zigzagMaxSpan');
  91772. // Use arbitrary value to avoid dead loop if user gives inappropriate settings.
  91773. zigzagMinSpan = Math.max(2, zigzagMinSpan || 0);
  91774. zigzagMaxSpan = Math.max(zigzagMinSpan, zigzagMaxSpan || 0);
  91775. var expandOnClick = breakAreaModel.get('expandOnClick');
  91776. var zigzagZ = breakAreaModel.get('zigzagZ');
  91777. var itemStyleModel = breakAreaModel.getModel('itemStyle');
  91778. var itemStyle = itemStyleModel.getItemStyle();
  91779. var borderColor = itemStyle.stroke;
  91780. var borderWidth = itemStyle.lineWidth;
  91781. var borderType = itemStyle.lineDash;
  91782. var color = itemStyle.fill;
  91783. var group = new Group({
  91784. ignoreModelZ: true
  91785. });
  91786. var isAxisHorizontal = axis.isHorizontal();
  91787. var cachedVisualList = viewCache(axisView).visualList || (viewCache(axisView).visualList = []);
  91788. resetCacheVisualRemoveFlag(cachedVisualList);
  91789. var _loop_1 = function (i) {
  91790. var parsedBreak = breakPairs[i][0]["break"].parsedBreak;
  91791. // Even if brk.gap is 0, we should also draw the breakArea because
  91792. // border is sometimes required to be visible (as a line)
  91793. var coords = [];
  91794. coords[0] = axis.toGlobalCoord(axis.dataToCoord(parsedBreak.vmin, true));
  91795. coords[1] = axis.toGlobalCoord(axis.dataToCoord(parsedBreak.vmax, true));
  91796. if (coords[1] < coords[0]) {
  91797. coords.reverse();
  91798. }
  91799. var cachedVisual = ensureVisualInCache(cachedVisualList, parsedBreak);
  91800. cachedVisual.shouldRemove = false;
  91801. var breakGroup = new Group();
  91802. addZigzagShapes(cachedVisual.zigzagRandomList, breakGroup, coords[0], coords[1], isAxisHorizontal, parsedBreak);
  91803. if (expandOnClick) {
  91804. breakGroup.on('click', function () {
  91805. var payload = {
  91806. type: AXIS_BREAK_EXPAND_ACTION_TYPE,
  91807. breaks: [{
  91808. start: parsedBreak.breakOption.start,
  91809. end: parsedBreak.breakOption.end
  91810. }]
  91811. };
  91812. payload[axis.dim + "AxisIndex"] = axisModel.componentIndex;
  91813. api.dispatchAction(payload);
  91814. });
  91815. }
  91816. breakGroup.silent = !expandOnClick;
  91817. group.add(breakGroup);
  91818. };
  91819. for (var i = 0; i < breakPairs.length; i++) {
  91820. _loop_1(i);
  91821. }
  91822. axisGroup.add(group);
  91823. removeUnusedCacheVisual(cachedVisualList);
  91824. function addZigzagShapes(zigzagRandomList, breakGroup, startCoord, endCoord, isAxisHorizontal, trimmedBreak) {
  91825. var polylineStyle = {
  91826. stroke: borderColor,
  91827. lineWidth: borderWidth,
  91828. lineDash: borderType,
  91829. fill: 'none'
  91830. };
  91831. var dimBrk = isAxisHorizontal ? 0 : 1;
  91832. var dimZigzag = 1 - dimBrk;
  91833. var zigzagCoordMax = coordSysRect[XY$1[dimZigzag]] + coordSysRect[WH$1[dimZigzag]];
  91834. // Apply `subPixelOptimizeLine` for alignning with break ticks.
  91835. function subPixelOpt(brkCoord) {
  91836. var pBrk = [];
  91837. var dummyP = [];
  91838. pBrk[dimBrk] = dummyP[dimBrk] = brkCoord;
  91839. pBrk[dimZigzag] = coordSysRect[XY$1[dimZigzag]];
  91840. dummyP[dimZigzag] = zigzagCoordMax;
  91841. var dummyShape = {
  91842. x1: pBrk[0],
  91843. y1: pBrk[1],
  91844. x2: dummyP[0],
  91845. y2: dummyP[1]
  91846. };
  91847. subPixelOptimizeLine(dummyShape, dummyShape, {
  91848. lineWidth: 1
  91849. });
  91850. pBrk[0] = dummyShape.x1;
  91851. pBrk[1] = dummyShape.y1;
  91852. return pBrk[dimBrk];
  91853. }
  91854. startCoord = subPixelOpt(startCoord);
  91855. endCoord = subPixelOpt(endCoord);
  91856. var pointsA = [];
  91857. var pointsB = [];
  91858. var isSwap = true;
  91859. var current = coordSysRect[XY$1[dimZigzag]];
  91860. for (var idx = 0;; idx++) {
  91861. // Use `isFirstPoint` `isLastPoint` to ensure the intersections between zigzag
  91862. // and axis are precise, thus it can join its axis tick correctly.
  91863. var isFirstPoint = current === coordSysRect[XY$1[dimZigzag]];
  91864. var isLastPoint = current >= zigzagCoordMax;
  91865. if (isLastPoint) {
  91866. current = zigzagCoordMax;
  91867. }
  91868. var pA = [];
  91869. var pB = [];
  91870. pA[dimBrk] = startCoord;
  91871. pB[dimBrk] = endCoord;
  91872. if (!isFirstPoint && !isLastPoint) {
  91873. pA[dimBrk] += isSwap ? -zigzagAmplitude : zigzagAmplitude;
  91874. pB[dimBrk] -= !isSwap ? -zigzagAmplitude : zigzagAmplitude;
  91875. }
  91876. pA[dimZigzag] = current;
  91877. pB[dimZigzag] = current;
  91878. pointsA.push(pA);
  91879. pointsB.push(pB);
  91880. var randomVal = void 0;
  91881. if (idx < zigzagRandomList.length) {
  91882. randomVal = zigzagRandomList[idx];
  91883. } else {
  91884. randomVal = Math.random();
  91885. zigzagRandomList.push(randomVal);
  91886. }
  91887. current += randomVal * (zigzagMaxSpan - zigzagMinSpan) + zigzagMinSpan;
  91888. isSwap = !isSwap;
  91889. if (isLastPoint) {
  91890. break;
  91891. }
  91892. }
  91893. var anidSuffix = getScaleBreakHelper().serializeAxisBreakIdentifier(trimmedBreak.breakOption);
  91894. // Create two polylines and add them to the breakGroup
  91895. breakGroup.add(new Polyline({
  91896. anid: "break_a_" + anidSuffix,
  91897. shape: {
  91898. points: pointsA
  91899. },
  91900. style: polylineStyle,
  91901. z: zigzagZ
  91902. }));
  91903. /* Add the second polyline and a polygon only if the gap is not zero
  91904. * Otherwise if the polyline is with dashed line or being opaque,
  91905. * it may not be constant with breaks with non-zero gaps. */
  91906. if (trimmedBreak.gapReal !== 0) {
  91907. breakGroup.add(new Polyline({
  91908. anid: "break_b_" + anidSuffix,
  91909. shape: {
  91910. // Not reverse to keep the dash stable when dragging resizing.
  91911. points: pointsB
  91912. },
  91913. style: polylineStyle,
  91914. z: zigzagZ
  91915. }));
  91916. // Creating the polygon that fills the area between the polylines
  91917. // From end to start for polygon.
  91918. var pointsB2 = pointsB.slice();
  91919. pointsB2.reverse();
  91920. var polygonPoints = pointsA.concat(pointsB2);
  91921. breakGroup.add(new Polygon({
  91922. anid: "break_c_" + anidSuffix,
  91923. shape: {
  91924. points: polygonPoints
  91925. },
  91926. style: {
  91927. fill: color,
  91928. opacity: itemStyle.opacity
  91929. },
  91930. z: zigzagZ
  91931. }));
  91932. }
  91933. }
  91934. }
  91935. function buildAxisBreakLine(axisModel, group, transformGroup, pathBaseProp) {
  91936. var axis = axisModel.axis;
  91937. var transform = transformGroup.transform;
  91938. assert(pathBaseProp.style);
  91939. var extent = axis.getExtent();
  91940. if (axis.inverse) {
  91941. extent = extent.slice();
  91942. extent.reverse();
  91943. }
  91944. var breakPairs = getScaleBreakHelper().retrieveAxisBreakPairs(axis.scale.getTicks({
  91945. breakTicks: 'only_break'
  91946. }), function (tick) {
  91947. return tick["break"];
  91948. }, false);
  91949. var brkLayoutList = map(breakPairs, function (breakPair) {
  91950. var parsedBreak = breakPair[0]["break"].parsedBreak;
  91951. var coordPair = [axis.dataToCoord(parsedBreak.vmin, true), axis.dataToCoord(parsedBreak.vmax, true)];
  91952. coordPair[0] > coordPair[1] && coordPair.reverse();
  91953. return {
  91954. coordPair: coordPair,
  91955. brkId: getScaleBreakHelper().serializeAxisBreakIdentifier(parsedBreak.breakOption)
  91956. };
  91957. });
  91958. brkLayoutList.sort(function (layout1, layout2) {
  91959. return layout1.coordPair[0] - layout2.coordPair[0];
  91960. });
  91961. var ySegMin = extent[0];
  91962. var lastLayout = null;
  91963. for (var idx = 0; idx < brkLayoutList.length; idx++) {
  91964. var layout = brkLayoutList[idx];
  91965. var brkTirmmedMin = Math.max(layout.coordPair[0], extent[0]);
  91966. var brkTirmmedMax = Math.min(layout.coordPair[1], extent[1]);
  91967. if (ySegMin <= brkTirmmedMin) {
  91968. addSeg(ySegMin, brkTirmmedMin, lastLayout, layout);
  91969. }
  91970. ySegMin = brkTirmmedMax;
  91971. lastLayout = layout;
  91972. }
  91973. if (ySegMin <= extent[1]) {
  91974. addSeg(ySegMin, extent[1], lastLayout, null);
  91975. }
  91976. function addSeg(min, max, layout1, layout2) {
  91977. function trans(p1, p2) {
  91978. if (transform) {
  91979. applyTransform(p1, p1, transform);
  91980. applyTransform(p2, p2, transform);
  91981. }
  91982. }
  91983. function subPixelOptimizePP(p1, p2) {
  91984. var shape = {
  91985. x1: p1[0],
  91986. y1: p1[1],
  91987. x2: p2[0],
  91988. y2: p2[1]
  91989. };
  91990. subPixelOptimizeLine(shape, shape, pathBaseProp.style);
  91991. p1[0] = shape.x1;
  91992. p1[1] = shape.y1;
  91993. p2[0] = shape.x2;
  91994. p2[1] = shape.y2;
  91995. }
  91996. var lineP1 = [min, 0];
  91997. var lineP2 = [max, 0];
  91998. // dummy tick is used to align the line segment ends with axis ticks
  91999. // after `subPixelOptimizeLine` being applied.
  92000. var dummyTickEnd1 = [min, 5];
  92001. var dummyTickEnd2 = [max, 5];
  92002. trans(lineP1, dummyTickEnd1);
  92003. subPixelOptimizePP(lineP1, dummyTickEnd1);
  92004. trans(lineP2, dummyTickEnd2);
  92005. subPixelOptimizePP(lineP2, dummyTickEnd2);
  92006. // Apply it keeping the same as the normal axis line.
  92007. subPixelOptimizePP(lineP1, lineP2);
  92008. var seg = new Line(extend({
  92009. shape: {
  92010. x1: lineP1[0],
  92011. y1: lineP1[1],
  92012. x2: lineP2[0],
  92013. y2: lineP2[1]
  92014. }
  92015. }, pathBaseProp));
  92016. group.add(seg);
  92017. // Animation should be precise to be consistent with tick and split line animation.
  92018. seg.anid = "breakLine_" + (layout1 ? layout1.brkId : '\0') + "_\0_" + (layout2 ? layout2.brkId : '\0');
  92019. }
  92020. }
  92021. /**
  92022. * Resolve the overlap of a pair of labels.
  92023. *
  92024. * [CAUTION] Only label.x/y are allowed to change.
  92025. */
  92026. function adjustBreakLabelPair(axisInverse, axisRotation, layoutPair) {
  92027. if (find(layoutPair, function (item) {
  92028. return !item;
  92029. })) {
  92030. return;
  92031. }
  92032. var mtv = new Point();
  92033. if (!labelIntersect(layoutPair[0], layoutPair[1], mtv, {
  92034. // Assert `labelPair` is `[break_min, break_max]`.
  92035. // `axis.inverse: true` means a smaller scale value corresponds to a bigger value in axis.extent.
  92036. // The axisRotation indicates mtv direction of OBB intersecting.
  92037. direction: -(axisInverse ? axisRotation + Math.PI : axisRotation),
  92038. touchThreshold: 0,
  92039. // If need to resovle intersection align axis by moving labels according to MTV,
  92040. // the direction must not be opposite, otherwise cause misleading.
  92041. bidirectional: false
  92042. })) {
  92043. return;
  92044. }
  92045. // Rotate axis back to (1, 0) direction, to be a standard axis.
  92046. var axisStTrans = create$1();
  92047. rotate(axisStTrans, axisStTrans, -axisRotation);
  92048. var labelPairStTrans = map(layoutPair, function (layout) {
  92049. return layout.transform ? mul$1(create$1(), axisStTrans, layout.transform) : axisStTrans;
  92050. });
  92051. function isParallelToAxis(whIdx) {
  92052. // Assert label[0] and label[1] has the same rotation, so only use [0].
  92053. var localRect = layoutPair[0].localRect;
  92054. var labelVec0 = new Point(localRect[WH$1[whIdx]] * labelPairStTrans[0][0], localRect[WH$1[whIdx]] * labelPairStTrans[0][1]);
  92055. return Math.abs(labelVec0.y) < 1e-5;
  92056. }
  92057. // If overlapping, move pair[0] pair[1] apart a little. We need to calculate a ratio k to
  92058. // distribute mtv to pair[0] and pair[1]. This is to place the text gap as close as possible
  92059. // to the center of the break ticks, otherwise it might looks weird or misleading.
  92060. // - When labels' width/height are not parallel to axis (usually by rotation),
  92061. // we can simply treat the k as `0.5`.
  92062. var k = 0.5;
  92063. // - When labels' width/height are parallel to axis, the width/height need to be considered,
  92064. // since they may differ significantly. In this case we keep textAlign as 'center' rather
  92065. // than 'left'/'right', due to considerations of space utilization for wide break.gap.
  92066. // A sample case: break on xAxis(no inverse) is [200, 300000].
  92067. // We calculate k based on the formula below:
  92068. // Rotated axis and labels to the direction of (1, 0).
  92069. // uval = ( (pair[0].insidePt - mtv*k) + (pair[1].insidePt + mtv*(1-k)) ) / 2 - brkCenter
  92070. // 0 <= k <= 1
  92071. // |uval| should be as small as possible.
  92072. // Derived as follows:
  92073. // qval = (pair[0].insidePt + pair[1].insidePt + mtv) / 2 - brkCenter
  92074. // k = (qval - uval) / mtv
  92075. // min(qval, qval-mtv) <= uval <= max(qval, qval-mtv)
  92076. if (isParallelToAxis(0) || isParallelToAxis(1)) {
  92077. var rectSt = map(layoutPair, function (layout, idx) {
  92078. var rect = layout.localRect.clone();
  92079. rect.applyTransform(labelPairStTrans[idx]);
  92080. return rect;
  92081. });
  92082. var brkCenterSt = new Point();
  92083. brkCenterSt.copy(layoutPair[0].label).add(layoutPair[1].label).scale(0.5);
  92084. brkCenterSt.transform(axisStTrans);
  92085. var mtvSt = mtv.clone().transform(axisStTrans);
  92086. var insidePtSum = rectSt[0].x + rectSt[1].x + (mtvSt.x >= 0 ? rectSt[0].width : rectSt[1].width);
  92087. var qval = (insidePtSum + mtvSt.x) / 2 - brkCenterSt.x;
  92088. var uvalMin = Math.min(qval, qval - mtvSt.x);
  92089. var uvalMax = Math.max(qval, qval - mtvSt.x);
  92090. var uval = uvalMax < 0 ? uvalMax : uvalMin > 0 ? uvalMin : 0;
  92091. k = (qval - uval) / mtvSt.x;
  92092. }
  92093. var delta0 = new Point();
  92094. var delta1 = new Point();
  92095. Point.scale(delta0, mtv, -k);
  92096. Point.scale(delta1, mtv, 1 - k);
  92097. labelLayoutApplyTranslation(layoutPair[0], delta0);
  92098. labelLayoutApplyTranslation(layoutPair[1], delta1);
  92099. }
  92100. function updateModelAxisBreak(model, payload) {
  92101. var result = {
  92102. breaks: []
  92103. };
  92104. each(payload.breaks, function (inputBrk) {
  92105. if (!inputBrk) {
  92106. return;
  92107. }
  92108. var breakOption = find(model.get('breaks', true), function (brkOption) {
  92109. return getScaleBreakHelper().identifyAxisBreak(brkOption, inputBrk);
  92110. });
  92111. if (!breakOption) {
  92112. if ("development" !== 'production') {
  92113. warn("Can not find axis break by start: " + inputBrk.start + ", end: " + inputBrk.end);
  92114. }
  92115. return;
  92116. }
  92117. var actionType = payload.type;
  92118. var old = {
  92119. isExpanded: !!breakOption.isExpanded
  92120. };
  92121. breakOption.isExpanded = actionType === AXIS_BREAK_EXPAND_ACTION_TYPE ? true : actionType === AXIS_BREAK_COLLAPSE_ACTION_TYPE ? false : actionType === AXIS_BREAK_TOGGLE_ACTION_TYPE ? !breakOption.isExpanded : breakOption.isExpanded;
  92122. result.breaks.push({
  92123. start: breakOption.start,
  92124. end: breakOption.end,
  92125. isExpanded: !!breakOption.isExpanded,
  92126. old: old
  92127. });
  92128. });
  92129. return result;
  92130. }
  92131. function installAxisBreakHelper() {
  92132. registerAxisBreakHelperImpl({
  92133. adjustBreakLabelPair: adjustBreakLabelPair,
  92134. buildAxisBreakLine: buildAxisBreakLine,
  92135. rectCoordBuildBreakAxis: rectCoordBuildBreakAxis,
  92136. updateModelAxisBreak: updateModelAxisBreak
  92137. });
  92138. }
  92139. function installAxisBreak(registers) {
  92140. registerAction$1(registers);
  92141. installScaleBreakHelper();
  92142. installAxisBreakHelper();
  92143. }
  92144. /**
  92145. * [CAUTION] Never export methods other than `installLegacyGridContainLabel`.
  92146. */
  92147. function installLegacyGridContainLabel() {
  92148. registerLegacyGridContainLabelImpl(legacyLayOutGridByContained);
  92149. }
  92150. /**
  92151. * The input gridRect and axes will be modified.
  92152. */
  92153. function legacyLayOutGridByContained(axesList, gridRect) {
  92154. each(axesList, function (axis) {
  92155. if (!axis.model.get(['axisLabel', 'inside'])) {
  92156. var labelUnionRect = estimateLabelUnionRect(axis);
  92157. if (labelUnionRect) {
  92158. var dim = axis.isHorizontal() ? 'height' : 'width';
  92159. var margin = axis.model.get(['axisLabel', 'margin']);
  92160. gridRect[dim] -= labelUnionRect[dim] + margin;
  92161. if (axis.position === 'top') {
  92162. gridRect.y += labelUnionRect.height + margin;
  92163. } else if (axis.position === 'left') {
  92164. gridRect.x += labelUnionRect.width + margin;
  92165. }
  92166. }
  92167. }
  92168. });
  92169. }
  92170. /**
  92171. * @return Be null/undefined if no labels.
  92172. */
  92173. function estimateLabelUnionRect(axis) {
  92174. var axisModel = axis.model;
  92175. var scale = axis.scale;
  92176. if (!axisModel.get(['axisLabel', 'show']) || scale.isBlank()) {
  92177. return;
  92178. }
  92179. var realNumberScaleTicks;
  92180. var tickCount;
  92181. var categoryScaleExtent = scale.getExtent();
  92182. // Optimize for large category data, avoid call `getTicks()`.
  92183. if (scale instanceof OrdinalScale) {
  92184. tickCount = scale.count();
  92185. } else {
  92186. realNumberScaleTicks = scale.getTicks();
  92187. tickCount = realNumberScaleTicks.length;
  92188. }
  92189. var axisLabelModel = axis.getLabelModel();
  92190. var labelFormatter = makeLabelFormatter(axis);
  92191. var rect;
  92192. var step = 1;
  92193. // Simple optimization for large amount of category labels
  92194. if (tickCount > 40) {
  92195. step = Math.ceil(tickCount / 40);
  92196. }
  92197. for (var i = 0; i < tickCount; i += step) {
  92198. var tick = realNumberScaleTicks ? realNumberScaleTicks[i] : {
  92199. value: categoryScaleExtent[0] + i
  92200. };
  92201. var label = labelFormatter(tick, i);
  92202. var unrotatedSingleRect = axisLabelModel.getTextRect(label);
  92203. var singleRect = rotateTextRect(unrotatedSingleRect, axisLabelModel.get('rotate') || 0);
  92204. rect ? rect.union(singleRect) : rect = singleRect;
  92205. }
  92206. return rect;
  92207. function rotateTextRect(textRect, rotate) {
  92208. var rotateRadians = rotate * Math.PI / 180;
  92209. var beforeWidth = textRect.width;
  92210. var beforeHeight = textRect.height;
  92211. var afterWidth = beforeWidth * Math.abs(Math.cos(rotateRadians)) + Math.abs(beforeHeight * Math.sin(rotateRadians));
  92212. var afterHeight = beforeWidth * Math.abs(Math.sin(rotateRadians)) + Math.abs(beforeHeight * Math.cos(rotateRadians));
  92213. var rotatedRect = new BoundingRect(textRect.x, textRect.y, afterWidth, afterHeight);
  92214. return rotatedRect;
  92215. }
  92216. }
  92217. // -----------------
  92218. // Render engines
  92219. // -----------------
  92220. // Render via Canvas.
  92221. // echarts.init(dom, null, { renderer: 'canvas' })
  92222. use([install$1]);
  92223. // Render via SVG.
  92224. // echarts.init(dom, null, { renderer: 'svg' })
  92225. use([install]);
  92226. // ----------------
  92227. // Charts (series)
  92228. // ----------------
  92229. // All of the series types, for example:
  92230. // chart.setOption({
  92231. // series: [{
  92232. // type: 'line' // or 'bar', 'pie', ...
  92233. // }]
  92234. // });
  92235. use([install$2, install$3, install$4, install$6, install$8, install$a, install$b, install$c, install$d, install$e, install$f, install$g, install$i, install$j, install$k, install$l, install$m, install$n, install$o, install$p, install$q, install$r, install$s]);
  92236. // -------------------
  92237. // Coordinate systems
  92238. // -------------------
  92239. // All of the axis modules have been included in the
  92240. // coordinate system module below, do not need to
  92241. // make extra import.
  92242. // `cartesian` coordinate system. For some historical
  92243. // reasons, it is named as grid, for example:
  92244. // chart.setOption({
  92245. // grid: {...},
  92246. // xAxis: {...},
  92247. // yAxis: {...},
  92248. // series: [{...}]
  92249. // });
  92250. use(install$u);
  92251. // `polar` coordinate system, for example:
  92252. // chart.setOption({
  92253. // polar: {...},
  92254. // radiusAxis: {...},
  92255. // angleAxis: {...},
  92256. // series: [{
  92257. // coordinateSystem: 'polar'
  92258. // }]
  92259. // });
  92260. use(install$v);
  92261. // `geo` coordinate system, for example:
  92262. // chart.setOption({
  92263. // geo: {...},
  92264. // series: [{
  92265. // coordinateSystem: 'geo'
  92266. // }]
  92267. // });
  92268. use(install$9);
  92269. // `singleAxis` coordinate system (notice, it is a coordinate system
  92270. // with only one axis, work for chart like theme river), for example:
  92271. // chart.setOption({
  92272. // singleAxis: {...}
  92273. // series: [{type: 'themeRiver', ...}]
  92274. // });
  92275. use(install$w);
  92276. // `parallel` coordinate system, only work for parallel series, for example:
  92277. // chart.setOption({
  92278. // parallel: {...},
  92279. // parallelAxis: [{...}, ...],
  92280. // series: [{
  92281. // type: 'parallel'
  92282. // }]
  92283. // });
  92284. use(install$h);
  92285. // `calendar` coordinate system. for example,
  92286. // chart.setOption({
  92287. // calendar: {...},
  92288. // series: [{
  92289. // coordinateSystem: 'calendar'
  92290. // }]
  92291. // );
  92292. use(install$x);
  92293. // `matrix` coordinate system. for example,
  92294. // chart.setOption({
  92295. // matrix: {...},
  92296. // series: [{
  92297. // coordinateSystem: 'matrix'
  92298. // }]
  92299. // );
  92300. use(install$y);
  92301. // ------------------
  92302. // Other components
  92303. // ------------------
  92304. // `graphic` component, for example:
  92305. // chart.setOption({
  92306. // graphic: {...}
  92307. // });
  92308. use(install$z);
  92309. // `toolbox` component, for example:
  92310. // chart.setOption({
  92311. // toolbox: {...}
  92312. // });
  92313. use(install$B);
  92314. // `tooltip` component, for example:
  92315. // chart.setOption({
  92316. // tooltip: {...}
  92317. // });
  92318. use(install$C);
  92319. // `axisPointer` component, for example:
  92320. // chart.setOption({
  92321. // tooltip: {axisPointer: {...}, ...}
  92322. // });
  92323. // Or
  92324. // chart.setOption({
  92325. // axisPointer: {...}
  92326. // });
  92327. use(install$t);
  92328. // `brush` component, for example:
  92329. // chart.setOption({
  92330. // brush: {...}
  92331. // });
  92332. // Or
  92333. // chart.setOption({
  92334. // tooltip: {feature: {brush: {...}}
  92335. // })
  92336. use(install$D);
  92337. // `title` component, for example:
  92338. // chart.setOption({
  92339. // title: {...}
  92340. // });
  92341. use(install$E);
  92342. // `timeline` component, for example:
  92343. // chart.setOption({
  92344. // timeline: {...}
  92345. // });
  92346. use(install$F);
  92347. // `markPoint` component, for example:
  92348. // chart.setOption({
  92349. // series: [{markPoint: {...}}]
  92350. // });
  92351. use(install$G);
  92352. // `markLine` component, for example:
  92353. // chart.setOption({
  92354. // series: [{markLine: {...}}]
  92355. // });
  92356. use(install$H);
  92357. // `markArea` component, for example:
  92358. // chart.setOption({
  92359. // series: [{markArea: {...}}]
  92360. // });
  92361. use(install$I);
  92362. // `legend` component not scrollable. for example:
  92363. // chart.setOption({
  92364. // legend: {...}
  92365. // });
  92366. use(install$L);
  92367. // `dataZoom` component including both `dataZoomInside` and `dataZoomSlider`.
  92368. use(install$O);
  92369. // `dataZoom` component providing drag, pinch, wheel behaviors
  92370. // inside coordinate system, for example:
  92371. // chart.setOption({
  92372. // dataZoom: {type: 'inside'}
  92373. // });
  92374. use(install$M);
  92375. // `dataZoom` component providing a slider bar, for example:
  92376. // chart.setOption({
  92377. // dataZoom: {type: 'slider'}
  92378. // });
  92379. use(install$N);
  92380. // `visualMap` component including both `visualMapContinuous` and `visualMapPiecewise`.
  92381. use(install$R);
  92382. // `visualMap` component providing continuous bar, for example:
  92383. // chart.setOption({
  92384. // visualMap: {type: 'continuous'}
  92385. // });
  92386. use(install$P);
  92387. // `visualMap` component providing pieces bar, for example:
  92388. // chart.setOption({
  92389. // visualMap: {type: 'piecewise'}
  92390. // });
  92391. use(install$Q);
  92392. use(install$S);
  92393. // `aria` component providing aria, for example:
  92394. // chart.setOption({
  92395. // aria: {...}
  92396. // });
  92397. use(install$T);
  92398. // dataset transform
  92399. // chart.setOption({
  92400. // dataset: {
  92401. // transform: []
  92402. // }
  92403. // });
  92404. use(install$U);
  92405. use(install$V);
  92406. // universal transition
  92407. // chart.setOption({
  92408. // series: {
  92409. // universalTransition: { enabled: true }
  92410. // }
  92411. // })
  92412. use(installUniversalTransition);
  92413. // label layout
  92414. // chart.setOption({
  92415. // series: {
  92416. // labelLayout: { hideOverlap: true }
  92417. // }
  92418. // })
  92419. use(installLabelLayout);
  92420. use(installAxisBreak);
  92421. use(installLegacyGridContainLabel);
  92422. use(installScatterJitter);
  92423. export { Axis, ChartView, ComponentModel, ComponentView, SeriesData as List, Model, PRIORITY, SeriesModel, color, connect, dataTool, dependencies, disConnect, disconnect, dispose$1 as dispose, env, extendChartView, extendComponentModel, extendComponentView, extendSeriesModel, format$1 as format, getCoordinateSystemDimensions, getInstanceByDom, getInstanceById, getMap, graphic$1 as graphic, helper, init$1 as init, brushSingle as innerDrawElementOnCanvas, matrix, number, parseGeoJSON, parseGeoJSON as parseGeoJson, registerAction, registerCoordinateSystem, registerCustomSeries$1 as registerCustomSeries, registerLayout, registerLoading, registerLocale, registerMap, registerPostInit, registerPostUpdate, registerPreprocessor, registerProcessor, registerTheme, registerTransform, registerUpdateLifecycle, registerVisual, setCanvasCreator, setPlatformAPI, throttle, time, use, util$1 as util, vector, version$1 as version, util as zrUtil, zrender };
  92424. //# sourceMappingURL=echarts.esm.mjs.map