index.js 125 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092209320942095209620972098209921002101210221032104210521062107210821092110211121122113211421152116211721182119212021212122212321242125212621272128212921302131213221332134213521362137213821392140214121422143214421452146214721482149215021512152215321542155215621572158215921602161216221632164216521662167216821692170217121722173217421752176217721782179218021812182218321842185218621872188218921902191219221932194219521962197219821992200220122022203220422052206220722082209221022112212221322142215221622172218221922202221222222232224222522262227222822292230223122322233223422352236223722382239224022412242224322442245224622472248224922502251225222532254225522562257225822592260226122622263226422652266226722682269227022712272227322742275227622772278227922802281228222832284228522862287228822892290229122922293229422952296229722982299230023012302230323042305230623072308230923102311231223132314231523162317231823192320232123222323232423252326232723282329233023312332233323342335233623372338233923402341234223432344234523462347234823492350235123522353235423552356235723582359236023612362236323642365236623672368236923702371237223732374237523762377237823792380238123822383238423852386238723882389239023912392239323942395239623972398239924002401240224032404240524062407240824092410241124122413241424152416241724182419242024212422242324242425242624272428242924302431243224332434243524362437243824392440244124422443244424452446244724482449245024512452245324542455245624572458245924602461246224632464246524662467246824692470247124722473247424752476247724782479248024812482248324842485248624872488248924902491249224932494249524962497249824992500250125022503250425052506250725082509251025112512251325142515251625172518251925202521252225232524252525262527252825292530253125322533253425352536253725382539254025412542254325442545254625472548254925502551255225532554255525562557255825592560256125622563256425652566256725682569257025712572257325742575257625772578257925802581258225832584258525862587258825892590259125922593259425952596259725982599260026012602260326042605260626072608260926102611261226132614261526162617261826192620262126222623262426252626262726282629263026312632263326342635263626372638263926402641264226432644264526462647264826492650265126522653265426552656265726582659266026612662266326642665266626672668266926702671267226732674267526762677267826792680268126822683268426852686268726882689269026912692269326942695269626972698269927002701270227032704270527062707270827092710271127122713271427152716271727182719272027212722272327242725272627272728272927302731273227332734273527362737273827392740274127422743274427452746274727482749275027512752275327542755275627572758275927602761276227632764276527662767276827692770277127722773277427752776277727782779278027812782278327842785278627872788278927902791279227932794279527962797279827992800280128022803280428052806280728082809281028112812281328142815281628172818281928202821282228232824282528262827282828292830283128322833283428352836283728382839284028412842284328442845284628472848284928502851285228532854285528562857285828592860286128622863286428652866286728682869287028712872287328742875287628772878287928802881288228832884288528862887288828892890289128922893289428952896289728982899290029012902290329042905290629072908290929102911291229132914291529162917291829192920292129222923292429252926292729282929293029312932293329342935293629372938293929402941294229432944294529462947294829492950295129522953295429552956295729582959296029612962296329642965296629672968296929702971297229732974297529762977297829792980298129822983298429852986298729882989299029912992299329942995299629972998299930003001300230033004300530063007300830093010301130123013301430153016301730183019302030213022302330243025302630273028302930303031303230333034303530363037303830393040304130423043304430453046304730483049305030513052305330543055305630573058305930603061306230633064306530663067306830693070307130723073307430753076307730783079308030813082308330843085308630873088308930903091309230933094309530963097309830993100310131023103310431053106310731083109311031113112311331143115311631173118311931203121312231233124312531263127312831293130313131323133313431353136313731383139314031413142314331443145314631473148314931503151315231533154315531563157315831593160316131623163316431653166316731683169317031713172317331743175317631773178317931803181318231833184318531863187318831893190319131923193319431953196319731983199320032013202320332043205320632073208320932103211321232133214321532163217321832193220322132223223322432253226322732283229323032313232323332343235323632373238323932403241324232433244324532463247324832493250325132523253325432553256325732583259326032613262326332643265326632673268326932703271327232733274327532763277327832793280328132823283328432853286328732883289329032913292329332943295329632973298329933003301330233033304330533063307330833093310331133123313331433153316331733183319332033213322332333243325332633273328332933303331333233333334333533363337333833393340334133423343334433453346334733483349335033513352335333543355335633573358335933603361336233633364336533663367336833693370337133723373337433753376337733783379338033813382338333843385338633873388338933903391339233933394339533963397339833993400340134023403340434053406340734083409341034113412341334143415341634173418341934203421342234233424342534263427342834293430343134323433343434353436343734383439344034413442344334443445344634473448344934503451345234533454345534563457345834593460346134623463346434653466346734683469347034713472347334743475347634773478347934803481348234833484348534863487348834893490349134923493349434953496349734983499350035013502350335043505350635073508350935103511351235133514351535163517351835193520352135223523352435253526352735283529353035313532353335343535353635373538353935403541354235433544354535463547354835493550355135523553355435553556355735583559356035613562356335643565356635673568356935703571357235733574357535763577357835793580358135823583358435853586358735883589359035913592359335943595359635973598359936003601360236033604360536063607360836093610361136123613361436153616361736183619362036213622362336243625362636273628362936303631363236333634363536363637363836393640364136423643364436453646364736483649365036513652365336543655365636573658365936603661366236633664366536663667366836693670367136723673367436753676367736783679368036813682368336843685368636873688368936903691369236933694369536963697369836993700370137023703370437053706370737083709371037113712371337143715371637173718371937203721372237233724372537263727372837293730373137323733373437353736373737383739374037413742374337443745374637473748374937503751375237533754375537563757375837593760376137623763376437653766376737683769377037713772377337743775377637773778377937803781378237833784378537863787378837893790379137923793379437953796379737983799380038013802380338043805380638073808380938103811381238133814381538163817381838193820382138223823382438253826382738283829383038313832383338343835383638373838383938403841384238433844384538463847384838493850385138523853385438553856385738583859386038613862386338643865386638673868386938703871387238733874387538763877387838793880388138823883388438853886388738883889389038913892389338943895389638973898389939003901390239033904390539063907390839093910391139123913391439153916391739183919392039213922392339243925392639273928392939303931393239333934393539363937393839393940394139423943394439453946394739483949395039513952395339543955395639573958395939603961396239633964396539663967396839693970397139723973397439753976397739783979398039813982398339843985398639873988398939903991399239933994399539963997399839994000400140024003400440054006400740084009401040114012401340144015401640174018401940204021402240234024402540264027402840294030403140324033403440354036403740384039404040414042404340444045404640474048404940504051405240534054405540564057405840594060406140624063406440654066406740684069407040714072407340744075407640774078407940804081408240834084408540864087408840894090409140924093409440954096409740984099410041014102410341044105410641074108410941104111411241134114411541164117411841194120412141224123412441254126412741284129413041314132413341344135413641374138413941404141414241434144414541464147414841494150415141524153415441554156415741584159416041614162416341644165416641674168416941704171417241734174417541764177417841794180418141824183418441854186418741884189419041914192419341944195419641974198419942004201420242034204420542064207420842094210421142124213421442154216421742184219422042214222422342244225422642274228422942304231423242334234423542364237423842394240424142424243424442454246424742484249425042514252425342544255425642574258425942604261426242634264426542664267426842694270427142724273427442754276427742784279428042814282428342844285428642874288428942904291429242934294429542964297429842994300430143024303430443054306430743084309431043114312431343144315431643174318431943204321432243234324432543264327432843294330433143324333433443354336433743384339434043414342434343444345434643474348434943504351435243534354435543564357435843594360436143624363436443654366436743684369437043714372437343744375437643774378437943804381438243834384438543864387438843894390439143924393439443954396439743984399440044014402440344044405440644074408440944104411441244134414441544164417441844194420442144224423442444254426442744284429443044314432443344344435443644374438443944404441444244434444444544464447444844494450445144524453445444554456445744584459446044614462446344644465446644674468446944704471447244734474447544764477447844794480448144824483448444854486448744884489449044914492449344944495449644974498449945004501450245034504450545064507450845094510451145124513
  1. module.exports = (function() {
  2. var __MODS__ = {};
  3. var __DEFINE__ = function(modId, func, req) { var m = { exports: {}, _tempexports: {} }; __MODS__[modId] = { status: 0, func: func, req: req, m: m }; };
  4. var __REQUIRE__ = function(modId, source) { if(!__MODS__[modId]) return require(source); if(!__MODS__[modId].status) { var m = __MODS__[modId].m; m._exports = m._tempexports; var desp = Object.getOwnPropertyDescriptor(m, "exports"); if (desp && desp.configurable) Object.defineProperty(m, "exports", { set: function (val) { if(typeof val === "object" && val !== m._exports) { m._exports.__proto__ = val.__proto__; Object.keys(val).forEach(function (k) { m._exports[k] = val[k]; }); } m._tempexports = val }, get: function () { return m._tempexports; } }); __MODS__[modId].status = 1; __MODS__[modId].func(__MODS__[modId].req, m, m.exports); } return __MODS__[modId].m.exports; };
  5. var __REQUIRE_WILDCARD__ = function(obj) { if(obj && obj.__esModule) { return obj; } else { var newObj = {}; if(obj != null) { for(var k in obj) { if (Object.prototype.hasOwnProperty.call(obj, k)) newObj[k] = obj[k]; } } newObj.default = obj; return newObj; } };
  6. var __REQUIRE_DEFAULT__ = function(obj) { return obj && obj.__esModule ? obj.default : obj; };
  7. __DEFINE__(1663749502287, function(require, module, exports) {
  8. var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
  9. var _typeof = require("@babel/runtime/helpers/typeof");
  10. Object.defineProperty(exports, "__esModule", {
  11. value: true
  12. });
  13. exports.BBox = void 0;
  14. Object.defineProperty(exports, "Canvas", {
  15. enumerable: true,
  16. get: function get() {
  17. return _engine.Canvas;
  18. }
  19. });
  20. Object.defineProperty(exports, "Group", {
  21. enumerable: true,
  22. get: function get() {
  23. return _engine.Group;
  24. }
  25. });
  26. Object.defineProperty(exports, "Matrix", {
  27. enumerable: true,
  28. get: function get() {
  29. return _matrix.default;
  30. }
  31. });
  32. Object.defineProperty(exports, "Shape", {
  33. enumerable: true,
  34. get: function get() {
  35. return _engine.Shape;
  36. }
  37. });
  38. exports.Types = exports.Smooth = void 0;
  39. Object.defineProperty(exports, "Vector2", {
  40. enumerable: true,
  41. get: function get() {
  42. return _vector.default;
  43. }
  44. });
  45. exports.createCanvas = createCanvas;
  46. exports.getEngine = getEngine;
  47. exports.registerEngine = registerEngine;
  48. var _matrix = _interopRequireDefault(require("./util/matrix"));
  49. var _vector = _interopRequireDefault(require("./util/vector2"));
  50. var Smooth = _interopRequireWildcard(require("./util/smooth"));
  51. exports.Smooth = Smooth;
  52. var BBox = _interopRequireWildcard(require("./util/bbox"));
  53. exports.BBox = BBox;
  54. var _engine = require("./engine");
  55. var Types = _interopRequireWildcard(require("./types"));
  56. exports.Types = Types;
  57. function _getRequireWildcardCache(nodeInterop) { if (typeof WeakMap !== "function") return null; var cacheBabelInterop = new WeakMap(); var cacheNodeInterop = new WeakMap(); return (_getRequireWildcardCache = function _getRequireWildcardCache(nodeInterop) { return nodeInterop ? cacheNodeInterop : cacheBabelInterop; })(nodeInterop); }
  58. function _interopRequireWildcard(obj, nodeInterop) { if (!nodeInterop && obj && obj.__esModule) { return obj; } if (obj === null || _typeof(obj) !== "object" && typeof obj !== "function") { return { default: obj }; } var cache = _getRequireWildcardCache(nodeInterop); if (cache && cache.has(obj)) { return cache.get(obj); } var newObj = {}; var hasPropertyDescriptor = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var key in obj) { if (key !== "default" && Object.prototype.hasOwnProperty.call(obj, key)) { var desc = hasPropertyDescriptor ? Object.getOwnPropertyDescriptor(obj, key) : null; if (desc && (desc.get || desc.set)) { Object.defineProperty(newObj, key, desc); } else { newObj[key] = obj[key]; } } } newObj.default = obj; if (cache) { cache.set(obj, newObj); } return newObj; }
  59. var engines = {};
  60. function registerEngine(name, engine) {
  61. engines[name] = engine;
  62. }
  63. function getEngine(name) {
  64. var G = engines[name];
  65. if (G) {
  66. return G;
  67. }
  68. return {
  69. Canvas: _engine.Canvas,
  70. Group: _engine.Group,
  71. Shape: _engine.Shape
  72. };
  73. }
  74. function createCanvas(cfg) {
  75. var renderer = cfg.renderer;
  76. var G = getEngine(renderer);
  77. return new G.Canvas(cfg);
  78. }
  79. }, function(modId) {var map = {"./util/matrix":1663749502288,"./util/vector2":1663749502289,"./util/smooth":1663749502290,"./util/bbox":1663749502291,"./engine":1663749502292,"./types":1663749502319}; return __REQUIRE__(map[modId], modId); })
  80. __DEFINE__(1663749502288, function(require, module, exports) {
  81. Object.defineProperty(exports, "__esModule", {
  82. value: true
  83. });
  84. exports.default = void 0;
  85. var Matrix = {
  86. generateDefault: function generateDefault() {
  87. return [1, 0, 0, 1, 0, 0];
  88. },
  89. isChanged: function isChanged(m) {
  90. return m[0] !== 1 || m[1] !== 0 || m[2] !== 0 || m[3] !== 1 || m[4] !== 0 || m[5] !== 0;
  91. },
  92. multiply: function multiply(m1, m2) {
  93. var m11 = m1[0] * m2[0] + m1[2] * m2[1];
  94. var m12 = m1[1] * m2[0] + m1[3] * m2[1];
  95. var m21 = m1[0] * m2[2] + m1[2] * m2[3];
  96. var m22 = m1[1] * m2[2] + m1[3] * m2[3];
  97. var dx = m1[0] * m2[4] + m1[2] * m2[5] + m1[4];
  98. var dy = m1[1] * m2[4] + m1[3] * m2[5] + m1[5];
  99. return [m11, m12, m21, m22, dx, dy];
  100. },
  101. scale: function scale(out, m, v) {
  102. out[0] = m[0] * v[0];
  103. out[1] = m[1] * v[0];
  104. out[2] = m[2] * v[1];
  105. out[3] = m[3] * v[1];
  106. out[4] = m[4];
  107. out[5] = m[5];
  108. return out;
  109. },
  110. rotate: function rotate(out, m, radian) {
  111. var c = Math.cos(radian);
  112. var s = Math.sin(radian);
  113. var m11 = m[0] * c + m[2] * s;
  114. var m12 = m[1] * c + m[3] * s;
  115. var m21 = m[0] * -s + m[2] * c;
  116. var m22 = m[1] * -s + m[3] * c;
  117. out[0] = m11;
  118. out[1] = m12;
  119. out[2] = m21;
  120. out[3] = m22;
  121. out[4] = m[4];
  122. out[5] = m[5];
  123. return out;
  124. },
  125. translate: function translate(out, m, v) {
  126. out[0] = m[0];
  127. out[1] = m[1];
  128. out[2] = m[2];
  129. out[3] = m[3];
  130. out[4] = m[4] + m[0] * v[0] + m[2] * v[1];
  131. out[5] = m[5] + m[1] * v[0] + m[3] * v[1];
  132. return out;
  133. },
  134. transform: function transform(m, actions) {
  135. var out = [].concat(m);
  136. for (var i = 0, len = actions.length; i < len; i++) {
  137. var action = actions[i];
  138. switch (action[0]) {
  139. case 't':
  140. Matrix.translate(out, out, [action[1], action[2]]);
  141. break;
  142. case 's':
  143. Matrix.scale(out, out, [action[1], action[2]]);
  144. break;
  145. case 'r':
  146. Matrix.rotate(out, out, action[1]);
  147. break;
  148. default:
  149. break;
  150. }
  151. }
  152. return out;
  153. }
  154. };
  155. var _default = Matrix;
  156. exports.default = _default;
  157. }, function(modId) { var map = {}; return __REQUIRE__(map[modId], modId); })
  158. __DEFINE__(1663749502289, function(require, module, exports) {
  159. Object.defineProperty(exports, "__esModule", {
  160. value: true
  161. });
  162. exports.default = void 0;
  163. /**
  164. * 2 Dimensional Vector
  165. * @module vector2
  166. */
  167. var _default = {
  168. /**
  169. * Creates a new, empty vector2
  170. *
  171. * @return {vector2} a new 2D vector
  172. */
  173. create: function create() {
  174. return [0, 0];
  175. },
  176. /**
  177. * Calculates the length of a vector2
  178. *
  179. * @param {vector2} v vector to calculate length of
  180. * @return {Number} length of v
  181. */
  182. length: function length(v) {
  183. var x = v[0];
  184. var y = v[1];
  185. return Math.sqrt(x * x + y * y);
  186. },
  187. /**
  188. * Normalize a vector2
  189. *
  190. * @param {vector2} out the receiving vector
  191. * @param {vector2} v vector to normalize
  192. * @return {vector2} out
  193. */
  194. normalize: function normalize(out, v) {
  195. var len = this.length(v);
  196. if (len === 0) {
  197. out[0] = 0;
  198. out[1] = 0;
  199. } else {
  200. out[0] = v[0] / len;
  201. out[1] = v[1] / len;
  202. }
  203. return out;
  204. },
  205. /**
  206. * Adds two vector2's
  207. *
  208. * @param {vector2} out the receiving vector
  209. * @param {vector2} v1 the first operand
  210. * @param {vector2} v2 the second operand
  211. * @return {vector2} out
  212. */
  213. add: function add(out, v1, v2) {
  214. out[0] = v1[0] + v2[0];
  215. out[1] = v1[1] + v2[1];
  216. return out;
  217. },
  218. /**
  219. * Subtracts vector v2 from vector v1
  220. *
  221. * @param {vector2} out the receiving vector
  222. * @param {vector2} v1 the first operand
  223. * @param {vector2} v2 the second operand
  224. * @return {vector2} out
  225. */
  226. sub: function sub(out, v1, v2) {
  227. out[0] = v1[0] - v2[0];
  228. out[1] = v1[1] - v2[1];
  229. return out;
  230. },
  231. /**
  232. * Scales a vector2 by a scalar number
  233. *
  234. * @param {vector2} out the receiving vector
  235. * @param {vector2} v the vector to scale
  236. * @param {Number} s amount to scale the vector by
  237. * @return {vector2} out
  238. */
  239. scale: function scale(out, v, s) {
  240. out[0] = v[0] * s;
  241. out[1] = v[1] * s;
  242. return out;
  243. },
  244. /**
  245. * Calculates the dot product of two vector2's
  246. *
  247. * @param {vector2} v1 the first operand
  248. * @param {vector2} v2 the second operand
  249. * @return {Number} dot product of v1 and v2
  250. */
  251. dot: function dot(v1, v2) {
  252. return v1[0] * v2[0] + v1[1] * v2[1];
  253. },
  254. /**
  255. * Calculates the direction of two vector2's
  256. *
  257. * @param {vector2} v1 the first operand
  258. * @param {vector2} v2 the second operand
  259. * @return {Boolean} the direction of v1 and v2
  260. */
  261. direction: function direction(v1, v2) {
  262. return v1[0] * v2[1] - v2[0] * v1[1];
  263. },
  264. /**
  265. * Calculates the angle of two vector2's
  266. *
  267. * @param {vector2} v1 the first operand
  268. * @param {vector2} v2 the second operand
  269. * @return {Number} angle of v1 and v2
  270. */
  271. angle: function angle(v1, v2) {
  272. var theta = this.dot(v1, v2) / (this.length(v1) * this.length(v2));
  273. return Math.acos(theta);
  274. },
  275. /**
  276. * Calculates the angle of two vector2's with direction
  277. *
  278. * @param {vector2} v1 the first operand
  279. * @param {vector2} v2 the second operand
  280. * @param {Boolean} direction the direction of two vector2's
  281. * @return {Number} angle of v1 and v2
  282. */
  283. angleTo: function angleTo(v1, v2, direction) {
  284. var angle = this.angle(v1, v2);
  285. var angleLargeThanPI = this.direction(v1, v2) >= 0;
  286. if (direction) {
  287. if (angleLargeThanPI) {
  288. return Math.PI * 2 - angle;
  289. }
  290. return angle;
  291. }
  292. if (angleLargeThanPI) {
  293. return angle;
  294. }
  295. return Math.PI * 2 - angle;
  296. },
  297. /**
  298. * whether a vector2 is zero vector
  299. *
  300. * @param {vector2} v vector to calculate
  301. * @return {Boolean} is or not a zero vector
  302. */
  303. zero: function zero(v) {
  304. return v[0] === 0 && v[1] === 0;
  305. },
  306. /**
  307. * Calculates the euclidian distance between two vector2's
  308. *
  309. * @param {vector2} v1 the first operand
  310. * @param {vector2} v2 the second operand
  311. * @return {Number} distance between a and b
  312. */
  313. distance: function distance(v1, v2) {
  314. var x = v2[0] - v1[0];
  315. var y = v2[1] - v1[1];
  316. return Math.sqrt(x * x + y * y);
  317. },
  318. /**
  319. * Creates a new vector2 initialized with values from an existing vector
  320. *
  321. * @param {vector2} v vector to clone
  322. * @return {Array} a new 2D vector
  323. */
  324. clone: function clone(v) {
  325. return [v[0], v[1]];
  326. },
  327. /**
  328. * Return the minimum of two vector2's
  329. *
  330. * @param {vector2} out the receiving vector
  331. * @param {vector2} v1 the first operand
  332. * @param {vector2} v2 the second operand
  333. * @return {vector2} out
  334. */
  335. min: function min(out, v1, v2) {
  336. out[0] = Math.min(v1[0], v2[0]);
  337. out[1] = Math.min(v1[1], v2[1]);
  338. return out;
  339. },
  340. /**
  341. * Return the maximum of two vector2's
  342. *
  343. * @param {vector2} out the receiving vector
  344. * @param {vector2} v1 the first operand
  345. * @param {vector2} v2 the second operand
  346. * @return {vector2} out
  347. */
  348. max: function max(out, v1, v2) {
  349. out[0] = Math.max(v1[0], v2[0]);
  350. out[1] = Math.max(v1[1], v2[1]);
  351. return out;
  352. },
  353. /**
  354. * Transforms the vector2 with a mat2d
  355. *
  356. * @param {vector2} out the receiving vector
  357. * @param {vector2} v the vector to transform
  358. * @param {mat2d} m matrix to transform with
  359. * @return {vector2} out
  360. */
  361. transformMat2d: function transformMat2d(out, v, m) {
  362. var x = v[0];
  363. var y = v[1];
  364. out[0] = m[0] * x + m[2] * y + m[4];
  365. out[1] = m[1] * x + m[3] * y + m[5];
  366. return out;
  367. }
  368. };
  369. exports.default = _default;
  370. }, function(modId) { var map = {}; return __REQUIRE__(map[modId], modId); })
  371. __DEFINE__(1663749502290, function(require, module, exports) {
  372. var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
  373. Object.defineProperty(exports, "__esModule", {
  374. value: true
  375. });
  376. exports.smooth = catmullRom2bezier;
  377. var _vector = _interopRequireDefault(require("./vector2"));
  378. /**
  379. * @fileOverview convert the line to curve
  380. * @author dxq613@gmail.com
  381. */
  382. function getPoint(v) {
  383. return [v.x, v.y];
  384. }
  385. function smoothBezier(points, smooth, isLoop, constraint) {
  386. var cps = [];
  387. var prevPoint;
  388. var nextPoint;
  389. var hasConstraint = !!constraint;
  390. var min;
  391. var max;
  392. var point;
  393. var len;
  394. var l;
  395. var i;
  396. if (hasConstraint) {
  397. min = [Infinity, Infinity];
  398. max = [-Infinity, -Infinity];
  399. for (i = 0, l = points.length; i < l; i++) {
  400. point = getPoint(points[i]);
  401. _vector.default.min(min, min, point);
  402. _vector.default.max(max, max, point);
  403. }
  404. _vector.default.min(min, min, constraint[0]);
  405. _vector.default.max(max, max, constraint[1]);
  406. }
  407. for (i = 0, len = points.length; i < len; i++) {
  408. point = getPoint(points[i]);
  409. if (isLoop) {
  410. prevPoint = getPoint(points[i ? i - 1 : len - 1]);
  411. nextPoint = getPoint(points[(i + 1) % len]);
  412. } else {
  413. if (i === 0 || i === len - 1) {
  414. cps.push([point[0], point[1]]);
  415. continue;
  416. } else {
  417. prevPoint = getPoint(points[i - 1]);
  418. nextPoint = getPoint(points[i + 1]);
  419. }
  420. }
  421. var v = _vector.default.sub([], nextPoint, prevPoint);
  422. _vector.default.scale(v, v, smooth);
  423. var d0 = _vector.default.distance(point, prevPoint);
  424. var d1 = _vector.default.distance(point, nextPoint);
  425. var sum = d0 + d1;
  426. if (sum !== 0) {
  427. d0 /= sum;
  428. d1 /= sum;
  429. }
  430. var v1 = _vector.default.scale([], v, -d0);
  431. var v2 = _vector.default.scale([], v, d1);
  432. var cp0 = _vector.default.add([], point, v1);
  433. var cp1 = _vector.default.add([], point, v2);
  434. if (hasConstraint) {
  435. _vector.default.max(cp0, cp0, min);
  436. _vector.default.min(cp0, cp0, max);
  437. _vector.default.max(cp1, cp1, min);
  438. _vector.default.min(cp1, cp1, max);
  439. }
  440. cps.push([cp0[0], cp0[1]]);
  441. cps.push([cp1[0], cp1[1]]);
  442. }
  443. if (isLoop) {
  444. cps.push(cps.shift());
  445. }
  446. return cps;
  447. }
  448. function catmullRom2bezier(pointList, z, constraint) {
  449. var isLoop = !!z;
  450. var controlPointList = smoothBezier(pointList, 0.4, isLoop, constraint);
  451. var len = pointList.length;
  452. var d1 = [];
  453. var cp1;
  454. var cp2;
  455. var p;
  456. for (var i = 0; i < len - 1; i++) {
  457. cp1 = controlPointList[i * 2];
  458. cp2 = controlPointList[i * 2 + 1];
  459. p = pointList[i + 1];
  460. d1.push(['C', cp1[0], cp1[1], cp2[0], cp2[1], p.x, p.y]);
  461. }
  462. if (isLoop) {
  463. cp1 = controlPointList[len];
  464. cp2 = controlPointList[len + 1];
  465. p = pointList[0];
  466. d1.push(['C', cp1[0], cp1[1], cp2[0], cp2[1], p.x, p.y]);
  467. }
  468. return d1;
  469. }
  470. }, function(modId) { var map = {"./vector2":1663749502289}; return __REQUIRE__(map[modId], modId); })
  471. __DEFINE__(1663749502291, function(require, module, exports) {
  472. var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
  473. Object.defineProperty(exports, "__esModule", {
  474. value: true
  475. });
  476. exports.getBBoxFromArc = getBBoxFromArc;
  477. exports.getBBoxFromBezierGroup = getBBoxFromBezierGroup;
  478. exports.getBBoxFromLine = getBBoxFromLine;
  479. exports.getBBoxFromPoints = getBBoxFromPoints;
  480. var _vector = _interopRequireDefault(require("./vector2"));
  481. var start = _vector.default.create();
  482. var end = _vector.default.create();
  483. var extremity = _vector.default.create();
  484. function getCubicBezierXYatT(startPt, controlPt1, controlPt2, endPt, T) {
  485. var x = CubicN(T, startPt.x, controlPt1.x, controlPt2.x, endPt.x);
  486. var y = CubicN(T, startPt.y, controlPt1.y, controlPt2.y, endPt.y);
  487. return {
  488. x: x,
  489. y: y
  490. };
  491. } // cubic helper formula at T distance
  492. function CubicN(T, a, b, c, d) {
  493. var t2 = T * T;
  494. var t3 = t2 * T;
  495. return a + (-a * 3 + T * (3 * a - a * T)) * T + (3 * b + T * (-6 * b + b * 3 * T)) * T + (c * 3 - c * 3 * T) * t2 + d * t3;
  496. }
  497. function cubicBezierBounds(c) {
  498. var minX = Infinity;
  499. var maxX = -Infinity;
  500. var minY = Infinity;
  501. var maxY = -Infinity;
  502. var s = {
  503. x: c[0],
  504. y: c[1]
  505. };
  506. var c1 = {
  507. x: c[2],
  508. y: c[3]
  509. };
  510. var c2 = {
  511. x: c[4],
  512. y: c[5]
  513. };
  514. var e = {
  515. x: c[6],
  516. y: c[7]
  517. };
  518. for (var t = 0; t < 100; t++) {
  519. var pt = getCubicBezierXYatT(s, c1, c2, e, t / 100);
  520. if (pt.x < minX) {
  521. minX = pt.x;
  522. }
  523. if (pt.x > maxX) {
  524. maxX = pt.x;
  525. }
  526. if (pt.y < minY) {
  527. minY = pt.y;
  528. }
  529. if (pt.y > maxY) {
  530. maxY = pt.y;
  531. }
  532. }
  533. return {
  534. minX: minX,
  535. minY: minY,
  536. maxX: maxX,
  537. maxY: maxY
  538. };
  539. }
  540. function getBBoxFromPoints(points, lineWidth) {
  541. if (points.length === 0) {
  542. return;
  543. }
  544. var p = points[0];
  545. var left = p.x;
  546. var right = p.x;
  547. var top = p.y;
  548. var bottom = p.y;
  549. var len = points.length;
  550. for (var i = 1; i < len; i++) {
  551. p = points[i];
  552. left = Math.min(left, p.x);
  553. right = Math.max(right, p.x);
  554. top = Math.min(top, p.y);
  555. bottom = Math.max(bottom, p.y);
  556. }
  557. lineWidth = lineWidth / 2 || 0;
  558. return {
  559. minX: left - lineWidth,
  560. minY: top - lineWidth,
  561. maxX: right + lineWidth,
  562. maxY: bottom + lineWidth
  563. };
  564. }
  565. function getBBoxFromLine(x0, y0, x1, y1, lineWidth) {
  566. lineWidth = lineWidth / 2 || 0;
  567. return {
  568. minX: Math.min(x0, x1) - lineWidth,
  569. minY: Math.min(y0, y1) - lineWidth,
  570. maxX: Math.max(x0, x1) + lineWidth,
  571. maxY: Math.max(y0, y1) + lineWidth
  572. };
  573. }
  574. function getBBoxFromArc(x, y, r, startAngle, endAngle, anticlockwise) {
  575. var diff = Math.abs(startAngle - endAngle);
  576. if (diff % (Math.PI * 2) < 1e-4 && diff > 1e-4) {
  577. // Is a circle
  578. return {
  579. minX: x - r,
  580. minY: y - r,
  581. maxX: x + r,
  582. maxY: y + r
  583. };
  584. }
  585. start[0] = Math.cos(startAngle) * r + x;
  586. start[1] = Math.sin(startAngle) * r + y;
  587. end[0] = Math.cos(endAngle) * r + x;
  588. end[1] = Math.sin(endAngle) * r + y;
  589. var min = [0, 0];
  590. var max = [0, 0];
  591. _vector.default.min(min, start, end);
  592. _vector.default.max(max, start, end); // Thresh to [0, Math.PI * 2]
  593. startAngle = startAngle % (Math.PI * 2);
  594. if (startAngle < 0) {
  595. startAngle = startAngle + Math.PI * 2;
  596. }
  597. endAngle = endAngle % (Math.PI * 2);
  598. if (endAngle < 0) {
  599. endAngle = endAngle + Math.PI * 2;
  600. }
  601. if (startAngle > endAngle && !anticlockwise) {
  602. endAngle += Math.PI * 2;
  603. } else if (startAngle < endAngle && anticlockwise) {
  604. startAngle += Math.PI * 2;
  605. }
  606. if (anticlockwise) {
  607. var tmp = endAngle;
  608. endAngle = startAngle;
  609. startAngle = tmp;
  610. }
  611. for (var angle = 0; angle < endAngle; angle += Math.PI / 2) {
  612. if (angle > startAngle) {
  613. extremity[0] = Math.cos(angle) * r + x;
  614. extremity[1] = Math.sin(angle) * r + y;
  615. _vector.default.min(min, extremity, min);
  616. _vector.default.max(max, extremity, max);
  617. }
  618. }
  619. return {
  620. minX: min[0],
  621. minY: min[1],
  622. maxX: max[0],
  623. maxY: max[1]
  624. };
  625. }
  626. function getBBoxFromBezierGroup(points, lineWidth) {
  627. var minX = Infinity;
  628. var maxX = -Infinity;
  629. var minY = Infinity;
  630. var maxY = -Infinity;
  631. for (var i = 0, len = points.length; i < len; i++) {
  632. var bbox = cubicBezierBounds(points[i]);
  633. if (bbox.minX < minX) {
  634. minX = bbox.minX;
  635. }
  636. if (bbox.maxX > maxX) {
  637. maxX = bbox.maxX;
  638. }
  639. if (bbox.minY < minY) {
  640. minY = bbox.minY;
  641. }
  642. if (bbox.maxY > maxY) {
  643. maxY = bbox.maxY;
  644. }
  645. }
  646. lineWidth = lineWidth / 2 || 0;
  647. return {
  648. minX: minX - lineWidth,
  649. minY: minY - lineWidth,
  650. maxX: maxX + lineWidth,
  651. maxY: maxY + lineWidth
  652. };
  653. }
  654. }, function(modId) { var map = {"./vector2":1663749502289}; return __REQUIRE__(map[modId], modId); })
  655. __DEFINE__(1663749502292, function(require, module, exports) {
  656. var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
  657. Object.defineProperty(exports, "__esModule", {
  658. value: true
  659. });
  660. Object.defineProperty(exports, "Canvas", {
  661. enumerable: true,
  662. get: function get() {
  663. return _canvas.default;
  664. }
  665. });
  666. Object.defineProperty(exports, "Group", {
  667. enumerable: true,
  668. get: function get() {
  669. return _group.default;
  670. }
  671. });
  672. Object.defineProperty(exports, "Shape", {
  673. enumerable: true,
  674. get: function get() {
  675. return _shape.default;
  676. }
  677. });
  678. var _canvas = _interopRequireDefault(require("./canvas"));
  679. var _group = _interopRequireDefault(require("./group"));
  680. var _shape = _interopRequireDefault(require("./shape"));
  681. }, function(modId) { var map = {"./canvas":1663749502293,"./group":1663749502316,"./shape":1663749502300}; return __REQUIRE__(map[modId], modId); })
  682. __DEFINE__(1663749502293, function(require, module, exports) {
  683. var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
  684. var _typeof = require("@babel/runtime/helpers/typeof");
  685. Object.defineProperty(exports, "__esModule", {
  686. value: true
  687. });
  688. exports.default = void 0;
  689. var _classCallCheck2 = _interopRequireDefault(require("@babel/runtime/helpers/classCallCheck"));
  690. var _createClass2 = _interopRequireDefault(require("@babel/runtime/helpers/createClass"));
  691. var _inherits2 = _interopRequireDefault(require("@babel/runtime/helpers/inherits"));
  692. var _createSuper2 = _interopRequireDefault(require("@babel/runtime/helpers/createSuper"));
  693. var _emit = _interopRequireDefault(require("../event/emit"));
  694. var _controller = _interopRequireDefault(require("../event/controller"));
  695. var _canvasElement = _interopRequireDefault(require("./canvas-element"));
  696. var _util = require("@antv/util");
  697. var DOMUtil = _interopRequireWildcard(require("../util/dom"));
  698. var _container = _interopRequireDefault(require("./container"));
  699. var _group = _interopRequireDefault(require("./group"));
  700. var _requestAnimationFrame = require("../util/requestAnimationFrame");
  701. var _lang = _interopRequireDefault(require("./lang"));
  702. function _getRequireWildcardCache(nodeInterop) { if (typeof WeakMap !== "function") return null; var cacheBabelInterop = new WeakMap(); var cacheNodeInterop = new WeakMap(); return (_getRequireWildcardCache = function _getRequireWildcardCache(nodeInterop) { return nodeInterop ? cacheNodeInterop : cacheBabelInterop; })(nodeInterop); }
  703. function _interopRequireWildcard(obj, nodeInterop) { if (!nodeInterop && obj && obj.__esModule) { return obj; } if (obj === null || _typeof(obj) !== "object" && typeof obj !== "function") { return { default: obj }; } var cache = _getRequireWildcardCache(nodeInterop); if (cache && cache.has(obj)) { return cache.get(obj); } var newObj = {}; var hasPropertyDescriptor = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var key in obj) { if (key !== "default" && Object.prototype.hasOwnProperty.call(obj, key)) { var desc = hasPropertyDescriptor ? Object.getOwnPropertyDescriptor(obj, key) : null; if (desc && (desc.get || desc.set)) { Object.defineProperty(newObj, key, desc); } else { newObj[key] = obj[key]; } } } newObj.default = obj; if (cache) { cache.set(obj, newObj); } return newObj; }
  704. var getPixelRatio = DOMUtil.getPixelRatio,
  705. getDomById = DOMUtil.getDomById,
  706. getWidth = DOMUtil.getWidth,
  707. getHeight = DOMUtil.getHeight,
  708. isCanvasElement = DOMUtil.isCanvasElement;
  709. var Canvas = /*#__PURE__*/function (_EventEmit) {
  710. (0, _inherits2.default)(Canvas, _EventEmit);
  711. var _super = (0, _createSuper2.default)(Canvas);
  712. function Canvas(cfg) {
  713. var _this;
  714. (0, _classCallCheck2.default)(this, Canvas);
  715. _this = _super.call(this);
  716. var title = cfg.title;
  717. var ariaLabel = title ? (0, _util.substitute)(_lang.default.general.withTitle, {
  718. title: title
  719. }) : _lang.default.general.title;
  720. _this._attrs = (0, _util.mix)({
  721. type: 'canvas',
  722. children: [],
  723. ariaLabel: ariaLabel
  724. }, cfg);
  725. _this._initPixelRatio();
  726. _this._initCanvas();
  727. return _this;
  728. }
  729. /* eslint-enable */
  730. (0, _createClass2.default)(Canvas, [{
  731. key: "get",
  732. value: function get(name) {
  733. return this._attrs[name];
  734. }
  735. }, {
  736. key: "set",
  737. value: function set(name, value) {
  738. this._attrs[name] = value;
  739. }
  740. }, {
  741. key: "_initPixelRatio",
  742. value: function _initPixelRatio() {
  743. var pixelRatio = this.get('pixelRatio');
  744. if (!pixelRatio) {
  745. this.set('pixelRatio', getPixelRatio());
  746. }
  747. }
  748. }, {
  749. key: "beforeDraw",
  750. value: function beforeDraw() {
  751. var context = this._attrs.context;
  752. var el = this._attrs.el;
  753. context && context.clearRect && context.clearRect(0, 0, el.width, el.height);
  754. }
  755. }, {
  756. key: "_initCanvas",
  757. value: function _initCanvas() {
  758. var el = this.get('el');
  759. var context = this.get('context');
  760. if (!el && !context) {
  761. throw new Error('Please specify the id, el or context of the chart!');
  762. }
  763. var canvas;
  764. if (el) {
  765. // DOMElement or String
  766. canvas = (0, _util.isString)(el) ? getDomById(el) : el;
  767. } else {
  768. // 说明没有指定el
  769. canvas = _canvasElement.default.create(context);
  770. }
  771. if (context && canvas && !canvas.getContext) {
  772. canvas.getContext = function () {
  773. return context;
  774. };
  775. }
  776. var width = this.get('width') || getWidth(canvas) || canvas.width;
  777. var height = this.get('height') || getHeight(canvas) || canvas.height;
  778. this.set('canvas', this);
  779. this.set('el', canvas);
  780. this.set('context', context || canvas.getContext('2d'));
  781. this.changeSize(width, height); // 初始化事件控制器
  782. var eventController = new _controller.default({
  783. canvas: this,
  784. el: canvas
  785. });
  786. this.set('eventController', eventController);
  787. }
  788. }, {
  789. key: "changeSize",
  790. value: function changeSize(width, height) {
  791. var pixelRatio = this.get('pixelRatio');
  792. var canvasDOM = this.get('el'); // HTMLCanvasElement or canvasElement
  793. // 浏览器环境设置style样式
  794. if (canvasDOM.style) {
  795. canvasDOM.style.width = width + 'px';
  796. canvasDOM.style.height = height + 'px';
  797. }
  798. if (isCanvasElement(canvasDOM)) {
  799. canvasDOM.width = width * pixelRatio;
  800. canvasDOM.height = height * pixelRatio;
  801. if (pixelRatio !== 1) {
  802. var ctx = this.get('context');
  803. ctx.scale(pixelRatio, pixelRatio);
  804. }
  805. }
  806. this.set('width', width);
  807. this.set('height', height);
  808. }
  809. }, {
  810. key: "getWidth",
  811. value: function getWidth() {
  812. var pixelRatio = this.get('pixelRatio');
  813. var width = this.get('width');
  814. return width * pixelRatio;
  815. }
  816. }, {
  817. key: "getHeight",
  818. value: function getHeight() {
  819. var pixelRatio = this.get('pixelRatio');
  820. var height = this.get('height');
  821. return height * pixelRatio;
  822. }
  823. }, {
  824. key: "getPointByClient",
  825. value: function getPointByClient(clientX, clientY) {
  826. var el = this.get('el');
  827. var bbox = el.getBoundingClientRect();
  828. var width = bbox.right - bbox.left;
  829. var height = bbox.bottom - bbox.top;
  830. return {
  831. x: (clientX - bbox.left) * (el.width / width),
  832. y: (clientY - bbox.top) * (el.height / height)
  833. };
  834. }
  835. }, {
  836. key: "_beginDraw",
  837. value: function _beginDraw() {
  838. this._attrs.toDraw = true;
  839. }
  840. }, {
  841. key: "_endDraw",
  842. value: function _endDraw() {
  843. this._attrs.toDraw = false;
  844. }
  845. }, {
  846. key: "draw",
  847. value: function draw() {
  848. var _this2 = this;
  849. var drawInner = function drawInner() {
  850. _this2.set('animateHandler', (0, _requestAnimationFrame.requestAnimationFrame)(function () {
  851. _this2.set('animateHandler', undefined);
  852. if (_this2.get('toDraw')) {
  853. drawInner();
  854. }
  855. }));
  856. _this2.beforeDraw();
  857. try {
  858. var context = _this2._attrs.context;
  859. _this2.drawChildren(context); // 支付宝,微信小程序,需要调context.draw才能完成绘制, 所以这里直接判断是否有.draw方法
  860. if (context.draw) {
  861. context.draw();
  862. } // 设置无障碍文本
  863. _this2.setAriaLabel();
  864. } catch (ev) {
  865. console.warn('error in draw canvas, detail as:');
  866. console.warn(ev);
  867. _this2._endDraw();
  868. }
  869. _this2._endDraw();
  870. };
  871. if (this.get('destroyed')) {
  872. return;
  873. }
  874. if (this.get('animateHandler')) {
  875. this._beginDraw();
  876. } else {
  877. drawInner();
  878. }
  879. } // 设置无障碍文本
  880. }, {
  881. key: "setAriaLabel",
  882. value: function setAriaLabel() {
  883. var el = this._attrs.el;
  884. var ariaLabel = this._getAriaLabel();
  885. if (ariaLabel && el.setAttribute) {
  886. el.setAttribute('aria-label', ariaLabel);
  887. }
  888. }
  889. }, {
  890. key: "destroy",
  891. value: function destroy() {
  892. if (this.get('destroyed')) {
  893. return;
  894. } // 需要清理 canvas 画布内容,否则会导致 spa 应用 ios 下 canvas 白屏
  895. // https://stackoverflow.com/questions/52532614/total-canvas-memory-use-exceeds-the-maximum-limit-safari-12
  896. // https://github.com/antvis/F2/issues/630
  897. var el = this.get('el');
  898. el.width = 0;
  899. el.height = 0;
  900. this.clear();
  901. this._attrs = {};
  902. this.set('destroyed', true);
  903. }
  904. }, {
  905. key: "isDestroyed",
  906. value: function isDestroyed() {
  907. return this.get('destroyed');
  908. }
  909. }]);
  910. return Canvas;
  911. }(_emit.default); // @ts-ignore
  912. (0, _util.mix)(Canvas.prototype, _container.default, {
  913. getGroupClass: function getGroupClass() {
  914. return _group.default;
  915. }
  916. });
  917. var _default = Canvas;
  918. exports.default = _default;
  919. }, function(modId) { var map = {"../event/emit":1663749502294,"../event/controller":1663749502295,"./canvas-element":1663749502297,"../util/dom":1663749502296,"./container":1663749502298,"./group":1663749502316,"../util/requestAnimationFrame":1663749502317,"./lang":1663749502318}; return __REQUIRE__(map[modId], modId); })
  920. __DEFINE__(1663749502294, function(require, module, exports) {
  921. var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
  922. Object.defineProperty(exports, "__esModule", {
  923. value: true
  924. });
  925. exports.default = void 0;
  926. var _classCallCheck2 = _interopRequireDefault(require("@babel/runtime/helpers/classCallCheck"));
  927. var _createClass2 = _interopRequireDefault(require("@babel/runtime/helpers/createClass"));
  928. var _util = require("@antv/util");
  929. // 实现简单的事件机制
  930. var EventEmit = /*#__PURE__*/function () {
  931. function EventEmit() {
  932. (0, _classCallCheck2.default)(this, EventEmit);
  933. this.__events = {};
  934. }
  935. (0, _createClass2.default)(EventEmit, [{
  936. key: "on",
  937. value: function on(type, listener) {
  938. if (!type || !listener) {
  939. return;
  940. }
  941. var events = this.__events[type] || [];
  942. events.push(listener);
  943. this.__events[type] = events;
  944. }
  945. }, {
  946. key: "emit",
  947. value: function emit(type, e) {
  948. var _this = this;
  949. if ((0, _util.isObject)(type)) {
  950. e = type;
  951. type = e && e.type;
  952. }
  953. if (!type) {
  954. return;
  955. }
  956. var events = this.__events[type];
  957. if (!events || !events.length) {
  958. return;
  959. }
  960. events.forEach(function (listener) {
  961. listener.call(_this, e);
  962. });
  963. }
  964. }, {
  965. key: "off",
  966. value: function off(type, listener) {
  967. var __events = this.__events;
  968. var events = __events[type];
  969. if (!events || !events.length) {
  970. return;
  971. } // 如果没有指定方法,则删除所有项
  972. if (!listener) {
  973. delete __events[type];
  974. return;
  975. } // 删除指定的 listener
  976. for (var i = 0, len = events.length; i < len; i++) {
  977. if (events[i] === listener) {
  978. events.splice(i, 1);
  979. i--;
  980. }
  981. }
  982. }
  983. }]);
  984. return EventEmit;
  985. }();
  986. var _default = EventEmit;
  987. exports.default = _default;
  988. }, function(modId) { var map = {}; return __REQUIRE__(map[modId], modId); })
  989. __DEFINE__(1663749502295, function(require, module, exports) {
  990. var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
  991. var _typeof = require("@babel/runtime/helpers/typeof");
  992. Object.defineProperty(exports, "__esModule", {
  993. value: true
  994. });
  995. exports.default = void 0;
  996. var _classCallCheck2 = _interopRequireDefault(require("@babel/runtime/helpers/classCallCheck"));
  997. var _createClass2 = _interopRequireDefault(require("@babel/runtime/helpers/createClass"));
  998. var DOMUtil = _interopRequireWildcard(require("../util/dom"));
  999. function _getRequireWildcardCache(nodeInterop) { if (typeof WeakMap !== "function") return null; var cacheBabelInterop = new WeakMap(); var cacheNodeInterop = new WeakMap(); return (_getRequireWildcardCache = function _getRequireWildcardCache(nodeInterop) { return nodeInterop ? cacheNodeInterop : cacheBabelInterop; })(nodeInterop); }
  1000. function _interopRequireWildcard(obj, nodeInterop) { if (!nodeInterop && obj && obj.__esModule) { return obj; } if (obj === null || _typeof(obj) !== "object" && typeof obj !== "function") { return { default: obj }; } var cache = _getRequireWildcardCache(nodeInterop); if (cache && cache.has(obj)) { return cache.get(obj); } var newObj = {}; var hasPropertyDescriptor = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var key in obj) { if (key !== "default" && Object.prototype.hasOwnProperty.call(obj, key)) { var desc = hasPropertyDescriptor ? Object.getOwnPropertyDescriptor(obj, key) : null; if (desc && (desc.get || desc.set)) { Object.defineProperty(newObj, key, desc); } else { newObj[key] = obj[key]; } } } newObj.default = obj; if (cache) { cache.set(obj, newObj); } return newObj; }
  1001. var convertPoints = DOMUtil.convertPoints; // 计算滑动的方向
  1002. var calcDirection = function calcDirection(start, end) {
  1003. var xDistance = end.x - start.x;
  1004. var yDistance = end.y - start.y; // x 的距离大于y 说明是横向,否则就是纵向
  1005. if (Math.abs(xDistance) > Math.abs(yDistance)) {
  1006. return xDistance > 0 ? 'right' : 'left';
  1007. }
  1008. return yDistance > 0 ? 'down' : 'up';
  1009. }; // 计算2点之间的距离
  1010. var calcDistance = function calcDistance(point1, point2) {
  1011. var xDistance = Math.abs(point2.x - point1.x);
  1012. var yDistance = Math.abs(point2.y - point1.y);
  1013. return Math.sqrt(xDistance * xDistance + yDistance * yDistance);
  1014. };
  1015. var getCenter = function getCenter(point1, point2) {
  1016. var x = point1.x + (point2.x - point1.x) / 2;
  1017. var y = point1.y + (point2.y - point1.y) / 2;
  1018. return {
  1019. x: x,
  1020. y: y
  1021. };
  1022. };
  1023. var PRESS_DELAY = 250;
  1024. var EventController = /*#__PURE__*/function () {
  1025. function EventController(_ref) {
  1026. var _this = this;
  1027. var canvas = _ref.canvas,
  1028. el = _ref.el;
  1029. (0, _classCallCheck2.default)(this, EventController);
  1030. this._click = function (ev) {
  1031. var points = convertPoints(ev, _this.canvas);
  1032. ev.points = points;
  1033. _this.emitEvent('click', ev);
  1034. };
  1035. this._start = function (ev) {
  1036. var points = convertPoints(ev, _this.canvas);
  1037. if (!points) {
  1038. return;
  1039. }
  1040. ev.points = points;
  1041. _this.emitEvent('touchstart', ev); // 防止上次的内容没有清理掉,重新reset下
  1042. _this.reset(); // 记录touch start 的时间
  1043. _this.startTime = Date.now(); // 记录touch start 的点
  1044. _this.startPoints = points;
  1045. if (points.length > 1) {
  1046. _this.startDistance = calcDistance(points[0], points[1]);
  1047. _this.center = getCenter(points[0], points[1]);
  1048. } else {
  1049. // 如果touchstart后停顿250ms, 则也触发press事件
  1050. _this.pressTimeout = setTimeout(function () {
  1051. // 这里固定触发press事件
  1052. var eventType = 'press';
  1053. var direction = 'none';
  1054. ev.direction = direction;
  1055. _this.emitStart(eventType, ev);
  1056. _this.emitEvent(eventType, ev);
  1057. _this.eventType = eventType;
  1058. _this.direction = direction;
  1059. }, PRESS_DELAY);
  1060. }
  1061. };
  1062. this._move = function (ev) {
  1063. var points = convertPoints(ev, _this.canvas);
  1064. if (!points) return;
  1065. _this.clearPressTimeout();
  1066. ev.points = points;
  1067. _this.emitEvent('touchmove', ev);
  1068. var startPoints = _this.startPoints;
  1069. if (!startPoints) return; // 多指触控
  1070. if (points.length > 1) {
  1071. // touchstart的距离
  1072. var startDistance = _this.startDistance;
  1073. var currentDistance = calcDistance(points[0], points[1]);
  1074. ev.zoom = currentDistance / startDistance;
  1075. ev.center = _this.center; // 触发缩放事件
  1076. _this.emitStart('pinch', ev);
  1077. _this.emitEvent('pinch', ev);
  1078. } else {
  1079. var deltaX = points[0].x - startPoints[0].x;
  1080. var deltaY = points[0].y - startPoints[0].y;
  1081. var direction = _this.direction || calcDirection(startPoints[0], points[0]);
  1082. _this.direction = direction; // 获取press或者pan的事件类型
  1083. // press 按住滑动, pan表示平移
  1084. // 如果start后立刻move,则触发pan, 如果有停顿,则触发press
  1085. var eventType = _this.getEventType(points);
  1086. ev.direction = direction;
  1087. ev.deltaX = deltaX;
  1088. ev.deltaY = deltaY;
  1089. _this.emitStart(eventType, ev);
  1090. _this.emitEvent(eventType, ev); // 记录最后2次move的时间和坐标,为了给swipe事件用
  1091. var prevMoveTime = _this.lastMoveTime;
  1092. var now = Date.now(); // 最后2次的时间间隔一定要大于0,否则swipe没发计算
  1093. if (now - prevMoveTime > 0) {
  1094. _this.prevMoveTime = prevMoveTime;
  1095. _this.prevMovePoints = _this.lastMovePoints;
  1096. _this.lastMoveTime = now;
  1097. _this.lastMovePoints = points;
  1098. }
  1099. }
  1100. };
  1101. this._end = function (ev) {
  1102. var points = convertPoints(ev, _this.canvas);
  1103. ev.points = points;
  1104. _this.emitEnd(ev);
  1105. _this.emitEvent('touchend', ev); // swipe事件处理, 在touchend之后触发
  1106. var lastMoveTime = _this.lastMoveTime;
  1107. var now = Date.now(); // 做这个判断是为了最后一次touchmove后到end前,还有一个停顿的过程
  1108. // 100 是拍的一个值,理论这个值会很短,一般不卡顿的话在10ms以内
  1109. if (now - lastMoveTime < 100) {
  1110. var prevMoveTime = _this.prevMoveTime || _this.startTime;
  1111. var intervalTime = lastMoveTime - prevMoveTime; // 时间间隔一定要大于0, 否则计算没意义
  1112. if (intervalTime > 0) {
  1113. var prevMovePoints = _this.prevMovePoints || _this.startPoints;
  1114. var lastMovePoints = _this.lastMovePoints; // move速率
  1115. var velocity = calcDistance(prevMovePoints[0], lastMovePoints[0]) / intervalTime; // 0.3 是参考hammerjs的设置
  1116. if (velocity > 0.3) {
  1117. ev.velocity = velocity;
  1118. ev.direction = calcDirection(prevMovePoints[0], lastMovePoints[0]);
  1119. ev.velocityX = (lastMovePoints[0].x - prevMovePoints[0].x) / intervalTime;
  1120. ev.velocityY = (lastMovePoints[0].y - prevMovePoints[0].y) / intervalTime;
  1121. _this.emitEvent('swipe', ev);
  1122. }
  1123. }
  1124. }
  1125. _this.reset();
  1126. var touches = ev.touches; // 当多指只释放了1指时也会触发end, 这时重新触发一次start
  1127. if (touches && touches.length > 0) {
  1128. _this._start(ev);
  1129. }
  1130. };
  1131. this._cancel = function (ev) {
  1132. _this.emitEvent('touchcancel', ev);
  1133. _this.reset();
  1134. }; // canvasEl
  1135. this.canvas = canvas;
  1136. this.delegateEvent(el); // 用来记录当前触发的事件
  1137. this.processEvent = {};
  1138. }
  1139. (0, _createClass2.default)(EventController, [{
  1140. key: "delegateEvent",
  1141. value: function delegateEvent(canvasEl) {
  1142. // 代理这几个事件
  1143. canvasEl.addEventListener('click', this._click);
  1144. canvasEl.addEventListener('touchstart', this._start);
  1145. canvasEl.addEventListener('touchmove', this._move);
  1146. canvasEl.addEventListener('touchend', this._end);
  1147. canvasEl.addEventListener('touchcancel', this._cancel);
  1148. }
  1149. }, {
  1150. key: "emitEvent",
  1151. value: function emitEvent(type, ev) {
  1152. var canvas = this.canvas;
  1153. canvas.emit(type, ev);
  1154. }
  1155. }, {
  1156. key: "getEventType",
  1157. value: function getEventType(points) {
  1158. var eventType = this.eventType,
  1159. canvas = this.canvas,
  1160. startTime = this.startTime,
  1161. startPoints = this.startPoints;
  1162. if (eventType) {
  1163. return eventType;
  1164. }
  1165. var type;
  1166. var panEventListeners = canvas.__events.pan; // 如果没有pan事件的监听,默认都是press
  1167. if (!panEventListeners || !panEventListeners.length) {
  1168. type = 'press';
  1169. } else {
  1170. // 如果有pan事件的处理,press则需要停顿250ms, 且移动距离小于10
  1171. var now = Date.now();
  1172. if (now - startTime > PRESS_DELAY && calcDistance(startPoints[0], points[0]) < 10) {
  1173. type = 'press';
  1174. } else {
  1175. type = 'pan';
  1176. }
  1177. }
  1178. this.eventType = type;
  1179. return type;
  1180. }
  1181. }, {
  1182. key: "enable",
  1183. value: function enable(eventType) {
  1184. this.processEvent[eventType] = true;
  1185. } // 是否进行中的事件
  1186. }, {
  1187. key: "isProcess",
  1188. value: function isProcess(eventType) {
  1189. return this.processEvent[eventType];
  1190. } // 触发start事件
  1191. }, {
  1192. key: "emitStart",
  1193. value: function emitStart(type, ev) {
  1194. if (this.isProcess(type)) {
  1195. return;
  1196. }
  1197. this.enable(type);
  1198. this.emitEvent("".concat(type, "start"), ev);
  1199. } // 触发end事件
  1200. }, {
  1201. key: "emitEnd",
  1202. value: function emitEnd(ev) {
  1203. var _this2 = this;
  1204. var processEvent = this.processEvent;
  1205. Object.keys(processEvent).forEach(function (type) {
  1206. _this2.emitEvent("".concat(type, "end"), ev);
  1207. delete processEvent[type];
  1208. });
  1209. }
  1210. }, {
  1211. key: "clearPressTimeout",
  1212. value: function clearPressTimeout() {
  1213. if (this.pressTimeout) {
  1214. clearTimeout(this.pressTimeout);
  1215. this.pressTimeout = null;
  1216. }
  1217. }
  1218. }, {
  1219. key: "reset",
  1220. value: function reset() {
  1221. this.clearPressTimeout();
  1222. this.startTime = 0;
  1223. this.startPoints = null;
  1224. this.startDistance = 0;
  1225. this.direction = null;
  1226. this.eventType = null;
  1227. this.pinch = false;
  1228. this.prevMoveTime = 0;
  1229. this.prevMovePoints = null;
  1230. this.lastMoveTime = 0;
  1231. this.lastMovePoints = null;
  1232. }
  1233. }]);
  1234. return EventController;
  1235. }();
  1236. var _default = EventController;
  1237. exports.default = _default;
  1238. }, function(modId) { var map = {"../util/dom":1663749502296}; return __REQUIRE__(map[modId], modId); })
  1239. __DEFINE__(1663749502296, function(require, module, exports) {
  1240. var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
  1241. Object.defineProperty(exports, "__esModule", {
  1242. value: true
  1243. });
  1244. exports.addEventListener = addEventListener;
  1245. exports.convertPoints = convertPoints;
  1246. exports.createEvent = createEvent;
  1247. exports.getDomById = getDomById;
  1248. exports.getHeight = getHeight;
  1249. exports.getPixelRatio = getPixelRatio;
  1250. exports.getRelativePosition = getRelativePosition;
  1251. exports.getStyle = getStyle;
  1252. exports.getWidth = getWidth;
  1253. exports.isBrowser = void 0;
  1254. exports.isCanvasElement = isCanvasElement;
  1255. exports.isWx = exports.isNode = exports.isMy = void 0;
  1256. exports.measureText = measureText;
  1257. exports.removeEventListener = removeEventListener;
  1258. var _typeof2 = _interopRequireDefault(require("@babel/runtime/helpers/typeof"));
  1259. var _util = require("@antv/util");
  1260. /**
  1261. * Detects support for options object argument in addEventListener.
  1262. * https://developer.mozilla.org/en-US/docs/Web/API/EventTarget/addEventListener#Safely_detecting_option_support
  1263. * @private
  1264. */
  1265. var supportsEventListenerOptions = function () {
  1266. var supports = false;
  1267. try {
  1268. var options = Object.defineProperty({}, 'passive', {
  1269. get: function get() {
  1270. supports = true;
  1271. }
  1272. });
  1273. window.addEventListener('e', null, options);
  1274. } catch (e) {// continue regardless of error
  1275. }
  1276. return supports;
  1277. }(); // Default passive to true as expected by Chrome for 'touchstart' and 'touchend' events.
  1278. // https://github.com/chartjs/Chart.js/issues/4287
  1279. var eventListenerOptions = supportsEventListenerOptions ? {
  1280. passive: true
  1281. } : false;
  1282. /* global wx, my */
  1283. // weixin miniprogram
  1284. // @ts-ignore
  1285. var isWx = (typeof wx === "undefined" ? "undefined" : (0, _typeof2.default)(wx)) === 'object' && typeof wx.getSystemInfoSync === 'function'; // ant miniprogram
  1286. // @ts-ignore
  1287. exports.isWx = isWx;
  1288. var isMy = (typeof my === "undefined" ? "undefined" : (0, _typeof2.default)(my)) === 'object' && typeof my.getSystemInfoSync === 'function'; // in node
  1289. // @ts-ignore
  1290. exports.isMy = isMy;
  1291. var isNode = (typeof global === "undefined" ? "undefined" : (0, _typeof2.default)(global)) && !(typeof window === "undefined" ? "undefined" : (0, _typeof2.default)(window)); // in browser
  1292. exports.isNode = isNode;
  1293. var isBrowser = typeof window !== 'undefined' && typeof window.document !== 'undefined' && typeof window.sessionStorage !== 'undefined';
  1294. exports.isBrowser = isBrowser;
  1295. function isCanvasElement(el) {
  1296. if (!el || (0, _typeof2.default)(el) !== 'object') return false;
  1297. if (el.nodeType === 1 && el.nodeName) {
  1298. // HTMLCanvasElement
  1299. return true;
  1300. } // CanvasElement
  1301. return !!el.isCanvasElement;
  1302. }
  1303. function getPixelRatio() {
  1304. return window && window.devicePixelRatio || 1;
  1305. }
  1306. function getStyle(el, property) {
  1307. return el.currentStyle ? el.currentStyle[property] : document.defaultView.getComputedStyle(el, null).getPropertyValue(property);
  1308. }
  1309. function getWidth(el) {
  1310. var width = getStyle(el, 'width');
  1311. if (width === 'auto') {
  1312. width = el.offsetWidth;
  1313. }
  1314. return parseFloat(width);
  1315. }
  1316. function getHeight(el) {
  1317. var height = getStyle(el, 'height');
  1318. if (height === 'auto') {
  1319. height = el.offsetHeight;
  1320. }
  1321. return parseFloat(height);
  1322. }
  1323. function getDomById(id) {
  1324. if (!id) {
  1325. return null;
  1326. }
  1327. return document.getElementById(id);
  1328. }
  1329. function getRelativePosition(point, canvas) {
  1330. var canvasDom = canvas.get('el');
  1331. if (!canvasDom) return point;
  1332. var _canvasDom$getBoundin = canvasDom.getBoundingClientRect(),
  1333. top = _canvasDom$getBoundin.top,
  1334. left = _canvasDom$getBoundin.left;
  1335. var paddingLeft = parseFloat(getStyle(canvasDom, 'padding-left'));
  1336. var paddingTop = parseFloat(getStyle(canvasDom, 'padding-top'));
  1337. var mouseX = point.x - left - paddingLeft;
  1338. var mouseY = point.y - top - paddingTop;
  1339. return {
  1340. x: mouseX,
  1341. y: mouseY
  1342. };
  1343. }
  1344. function addEventListener(source, type, listener) {
  1345. source.addEventListener(type, listener, eventListenerOptions);
  1346. }
  1347. function removeEventListener(source, type, listener) {
  1348. source.removeEventListener(type, listener, eventListenerOptions);
  1349. }
  1350. function landscapePoint(point, canvas) {
  1351. var landscape = canvas.get('landscape');
  1352. if (!landscape) {
  1353. return point;
  1354. }
  1355. if ((0, _util.isFunction)(landscape)) {
  1356. return landscape(point, canvas);
  1357. } // 默认顺时针旋转90度
  1358. var height = canvas.get('height');
  1359. var x = point.y;
  1360. var y = height - point.x;
  1361. return {
  1362. x: x,
  1363. y: y
  1364. };
  1365. }
  1366. function convertPoints(ev, canvas) {
  1367. var touches = ev.touches; // 认为是mouse事件
  1368. if (!touches) {
  1369. var point = getRelativePosition({
  1370. x: ev.clientX,
  1371. y: ev.clientY
  1372. }, canvas);
  1373. return [landscapePoint(point, canvas)];
  1374. } // 单指 touchend 后,touchs 会变空,最后的触点要从changedTouches里拿
  1375. if (!touches.length) {
  1376. // 为了防止万一,加个空逻辑
  1377. touches = ev.changedTouches || [];
  1378. }
  1379. var points = [];
  1380. for (var i = 0, len = touches.length; i < len; i++) {
  1381. var touch = touches[i]; // x, y: 相对canvas原点的位置,clientX, clientY 相对于可视窗口的位置
  1382. var x = touch.x,
  1383. y = touch.y,
  1384. clientX = touch.clientX,
  1385. clientY = touch.clientY;
  1386. var _point = void 0; // 小程序环境会有x,y
  1387. if ((0, _util.isNumber)(x) || (0, _util.isNumber)(y)) {
  1388. _point = {
  1389. x: x,
  1390. y: y
  1391. };
  1392. } else {
  1393. // 浏览器环境再计算下canvas的相对位置
  1394. _point = getRelativePosition({
  1395. x: clientX,
  1396. y: clientY
  1397. }, canvas);
  1398. }
  1399. points.push(landscapePoint(_point, canvas));
  1400. }
  1401. return points;
  1402. }
  1403. function createEvent(event, chart) {
  1404. var canvas = chart.get('canvas');
  1405. var points = convertPoints(event, canvas); // touchend会没有points
  1406. var point = points[0] || {};
  1407. return {
  1408. type: event.type,
  1409. chart: chart,
  1410. native: event,
  1411. x: point.x,
  1412. y: point.y
  1413. };
  1414. }
  1415. function measureText(text, font, ctx) {
  1416. if (!ctx) {
  1417. ctx = document.createElement('canvas').getContext('2d');
  1418. }
  1419. ctx.font = font || '12px sans-serif';
  1420. return ctx.measureText(text);
  1421. }
  1422. }, function(modId) { var map = {}; return __REQUIRE__(map[modId], modId); })
  1423. __DEFINE__(1663749502297, function(require, module, exports) {
  1424. var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
  1425. Object.defineProperty(exports, "__esModule", {
  1426. value: true
  1427. });
  1428. exports.default = void 0;
  1429. var _classCallCheck2 = _interopRequireDefault(require("@babel/runtime/helpers/classCallCheck"));
  1430. var _createClass2 = _interopRequireDefault(require("@babel/runtime/helpers/createClass"));
  1431. var _inherits2 = _interopRequireDefault(require("@babel/runtime/helpers/inherits"));
  1432. var _createSuper2 = _interopRequireDefault(require("@babel/runtime/helpers/createSuper"));
  1433. var _emit = _interopRequireDefault(require("../event/emit"));
  1434. var CanvasElement = /*#__PURE__*/function (_EventEmit) {
  1435. (0, _inherits2.default)(CanvasElement, _EventEmit);
  1436. var _super = (0, _createSuper2.default)(CanvasElement);
  1437. /* eslint-enable */
  1438. function CanvasElement(ctx) {
  1439. var _this;
  1440. (0, _classCallCheck2.default)(this, CanvasElement);
  1441. _this = _super.call(this);
  1442. _this.context = ctx; // canvas实际的宽高 (width/height) * pixelRatio
  1443. // 有可能是 node canvas 创建的 context 对象
  1444. var canvas = ctx.canvas || {};
  1445. _this.width = canvas.width || 0;
  1446. _this.height = canvas.height || 0;
  1447. _this.style = {};
  1448. _this.currentStyle = {};
  1449. _this.attrs = {}; // 用来标识是CanvasElement实例
  1450. _this.isCanvasElement = true;
  1451. return _this;
  1452. }
  1453. (0, _createClass2.default)(CanvasElement, [{
  1454. key: "getContext",
  1455. value: function
  1456. /* type */
  1457. getContext() {
  1458. return this.context;
  1459. }
  1460. }, {
  1461. key: "getBoundingClientRect",
  1462. value: function getBoundingClientRect() {
  1463. var width = this.width;
  1464. var height = this.height; // 默认都处理成可视窗口的顶部位置
  1465. return {
  1466. top: 0,
  1467. right: width,
  1468. bottom: height,
  1469. left: 0
  1470. };
  1471. }
  1472. }, {
  1473. key: "setAttribute",
  1474. value: function setAttribute(key, value) {
  1475. this.attrs[key] = value;
  1476. }
  1477. }, {
  1478. key: "addEventListener",
  1479. value: function addEventListener(type, listener) {
  1480. this.on(type, listener);
  1481. }
  1482. }, {
  1483. key: "removeEventListener",
  1484. value: function removeEventListener(type, listener) {
  1485. this.off(type, listener);
  1486. }
  1487. }, {
  1488. key: "dispatchEvent",
  1489. value: function dispatchEvent(type, e) {
  1490. this.emit(type, e);
  1491. }
  1492. }]);
  1493. return CanvasElement;
  1494. }(_emit.default);
  1495. function supportEventListener(canvas) {
  1496. if (!canvas) {
  1497. return false;
  1498. } // 非 HTMLCanvasElement
  1499. if (canvas.nodeType !== 1 || !canvas.nodeName || canvas.nodeName.toLowerCase() !== 'canvas') {
  1500. return false;
  1501. } // 微信小程序canvas.getContext('2d')时也是CanvasRenderingContext2D
  1502. // 也会有ctx.canvas, 而且nodeType也是1,所以还要在看下是否支持addEventListener
  1503. var support = false;
  1504. try {
  1505. canvas.addEventListener('eventTest', function () {
  1506. support = true;
  1507. });
  1508. canvas.dispatchEvent(new Event('eventTest'));
  1509. } catch (error) {
  1510. support = false;
  1511. }
  1512. return support;
  1513. }
  1514. var _default = {
  1515. create: function create(ctx) {
  1516. if (!ctx) {
  1517. return null;
  1518. }
  1519. if (supportEventListener(ctx.canvas)) {
  1520. return ctx.canvas;
  1521. }
  1522. return new CanvasElement(ctx);
  1523. }
  1524. };
  1525. exports.default = _default;
  1526. }, function(modId) { var map = {"../event/emit":1663749502294}; return __REQUIRE__(map[modId], modId); })
  1527. __DEFINE__(1663749502298, function(require, module, exports) {
  1528. var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
  1529. Object.defineProperty(exports, "__esModule", {
  1530. value: true
  1531. });
  1532. exports.default = void 0;
  1533. var _util = require("@antv/util");
  1534. var _array = require("../util/array");
  1535. var _shape = _interopRequireDefault(require("./shape"));
  1536. var SHAPE_MAP = {};
  1537. var INDEX = '_INDEX';
  1538. function getComparer(compare) {
  1539. return function (left, right) {
  1540. var result = compare(left, right);
  1541. return result === 0 ? left[INDEX] - right[INDEX] : result;
  1542. };
  1543. }
  1544. var _default = {
  1545. getGroupClass: function getGroupClass() {},
  1546. getChildren: function getChildren() {
  1547. return this.get('children');
  1548. },
  1549. addShape: function addShape(type) {
  1550. var cfg = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {};
  1551. var shapeType = SHAPE_MAP[type];
  1552. if (!shapeType) {
  1553. shapeType = (0, _util.upperFirst)(type);
  1554. SHAPE_MAP[type] = shapeType;
  1555. }
  1556. var shape = new _shape.default[shapeType](cfg);
  1557. this.add(shape);
  1558. return shape;
  1559. },
  1560. addGroup: function addGroup(cfg) {
  1561. var groupClass = this.getGroupClass();
  1562. var rst = new groupClass(cfg);
  1563. this.add(rst);
  1564. return rst;
  1565. },
  1566. contain: function contain(item) {
  1567. var children = this.get('children');
  1568. return children.indexOf(item) > -1;
  1569. },
  1570. sort: function sort() {
  1571. var children = this.get('children');
  1572. for (var i = 0, len = children.length; i < len; i++) {
  1573. var child = children[i];
  1574. child[INDEX] = i;
  1575. }
  1576. children.sort(getComparer(function (obj1, obj2) {
  1577. return obj1.get('zIndex') - obj2.get('zIndex');
  1578. }));
  1579. return this;
  1580. },
  1581. drawChildren: function drawChildren(context) {
  1582. this.sort();
  1583. var children = this.get('children');
  1584. for (var i = 0, len = children.length; i < len; i++) {
  1585. var child = children[i];
  1586. child.draw(context);
  1587. }
  1588. return this;
  1589. },
  1590. clear: function clear() {
  1591. var children = this.get('children') || [];
  1592. while (children.length !== 0) {
  1593. children[children.length - 1].remove(true);
  1594. }
  1595. return this;
  1596. },
  1597. add: function add(items) {
  1598. var children = this.get('children');
  1599. if (!children) {
  1600. children = [];
  1601. this.set('children', children);
  1602. }
  1603. if (!(0, _util.isArray)(items)) {
  1604. items = [items];
  1605. }
  1606. for (var i = 0, len = items.length; i < len; i++) {
  1607. var item = items[i];
  1608. var parent = item.get('parent');
  1609. if (parent) {
  1610. var descendants = parent.get('children');
  1611. (0, _array.remove)(descendants, item);
  1612. }
  1613. this._setEvn(item);
  1614. children.push(item);
  1615. }
  1616. return this;
  1617. },
  1618. _setEvn: function _setEvn(item) {
  1619. var _this$_attrs = this._attrs,
  1620. context = _this$_attrs.context,
  1621. canvas = _this$_attrs.canvas,
  1622. aria = _this$_attrs.aria;
  1623. var _item$_attrs = item._attrs,
  1624. isGroup = _item$_attrs.isGroup,
  1625. type = _item$_attrs.type;
  1626. item._attrs.parent = this;
  1627. item._attrs.context = context;
  1628. item._attrs.canvas = canvas; // 是否需要无障碍处理
  1629. if (aria && item._attrs.aria !== false) {
  1630. item._attrs.aria = aria;
  1631. }
  1632. if (type === 'text' && canvas && canvas.get('fontFamily') && !item._attrs.attrs.fontFamily) {
  1633. item.attr('fontFamily', canvas.get('fontFamily'));
  1634. }
  1635. var clip = item._attrs.attrs.clip;
  1636. if (clip) {
  1637. clip._attrs.parent = this;
  1638. clip._attrs.context = context;
  1639. clip._attrs.canvas = canvas;
  1640. }
  1641. if (isGroup) {
  1642. var children = item._attrs.children;
  1643. for (var i = 0, len = children.length; i < len; i++) {
  1644. item._setEvn(children[i]);
  1645. }
  1646. }
  1647. },
  1648. _getAriaLabel: function _getAriaLabel() {
  1649. var _this$_attrs2 = this._attrs,
  1650. aria = _this$_attrs2.aria,
  1651. ariaLabel = _this$_attrs2.ariaLabel,
  1652. children = _this$_attrs2.children; // 主动关闭
  1653. if (!aria) return;
  1654. var childAriaLabels = [];
  1655. if (children && children.length) {
  1656. for (var i = 0, len = children.length; i < len; i++) {
  1657. var _childAriaLabel = children[i].getAriaLabel();
  1658. if (_childAriaLabel) {
  1659. childAriaLabels.push(_childAriaLabel);
  1660. }
  1661. }
  1662. }
  1663. var childAriaLabel = childAriaLabels.join(' '); // 2个都有时拼接成完整句子
  1664. if (ariaLabel && childAriaLabel) {
  1665. return "".concat(ariaLabel, " ").concat(childAriaLabel, " ");
  1666. } // 只有1个,或者都没有
  1667. return ariaLabel || childAriaLabel;
  1668. }
  1669. };
  1670. exports.default = _default;
  1671. }, function(modId) { var map = {"../util/array":1663749502299,"./shape":1663749502300}; return __REQUIRE__(map[modId], modId); })
  1672. __DEFINE__(1663749502299, function(require, module, exports) {
  1673. Object.defineProperty(exports, "__esModule", {
  1674. value: true
  1675. });
  1676. exports.remove = remove;
  1677. function remove(arr, obj) {
  1678. if (!arr) {
  1679. return;
  1680. }
  1681. var index = arr.indexOf(obj);
  1682. if (index !== -1) {
  1683. arr.splice(index, 1);
  1684. }
  1685. }
  1686. }, function(modId) { var map = {}; return __REQUIRE__(map[modId], modId); })
  1687. __DEFINE__(1663749502300, function(require, module, exports) {
  1688. var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
  1689. Object.defineProperty(exports, "__esModule", {
  1690. value: true
  1691. });
  1692. exports.default = void 0;
  1693. var _shape = _interopRequireDefault(require("./shape"));
  1694. var _rect = _interopRequireDefault(require("./rect"));
  1695. var _image = _interopRequireDefault(require("./image"));
  1696. var _circle = _interopRequireDefault(require("./circle"));
  1697. var _line = _interopRequireDefault(require("./line"));
  1698. var _polygon = _interopRequireDefault(require("./polygon"));
  1699. var _polyline = _interopRequireDefault(require("./polyline"));
  1700. var _arc = _interopRequireDefault(require("./arc"));
  1701. var _sector = _interopRequireDefault(require("./sector"));
  1702. var _text = _interopRequireDefault(require("./text"));
  1703. var _custom = _interopRequireDefault(require("./custom"));
  1704. var _marker = _interopRequireDefault(require("./marker"));
  1705. _shape.default.Rect = _rect.default;
  1706. _shape.default.Image = _image.default;
  1707. _shape.default.Circle = _circle.default;
  1708. _shape.default.Line = _line.default;
  1709. _shape.default.Polygon = _polygon.default;
  1710. _shape.default.Polyline = _polyline.default;
  1711. _shape.default.Arc = _arc.default;
  1712. _shape.default.Sector = _sector.default;
  1713. _shape.default.Text = _text.default;
  1714. _shape.default.Custom = _custom.default;
  1715. _shape.default.Marker = _marker.default;
  1716. var _default = _shape.default;
  1717. exports.default = _default;
  1718. }, function(modId) { var map = {"./shape":1663749502301,"./rect":1663749502304,"./image":1663749502305,"./circle":1663749502306,"./line":1663749502307,"./polygon":1663749502308,"./polyline":1663749502309,"./arc":1663749502310,"./sector":1663749502311,"./text":1663749502312,"./custom":1663749502314,"./marker":1663749502315}; return __REQUIRE__(map[modId], modId); })
  1719. __DEFINE__(1663749502301, function(require, module, exports) {
  1720. var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
  1721. Object.defineProperty(exports, "__esModule", {
  1722. value: true
  1723. });
  1724. exports.default = void 0;
  1725. var _objectSpread2 = _interopRequireDefault(require("@babel/runtime/helpers/objectSpread2"));
  1726. var _classCallCheck2 = _interopRequireDefault(require("@babel/runtime/helpers/classCallCheck"));
  1727. var _createClass2 = _interopRequireDefault(require("@babel/runtime/helpers/createClass"));
  1728. var _inherits2 = _interopRequireDefault(require("@babel/runtime/helpers/inherits"));
  1729. var _createSuper2 = _interopRequireDefault(require("@babel/runtime/helpers/createSuper"));
  1730. var _util = require("@antv/util");
  1731. var _element = _interopRequireDefault(require("../element"));
  1732. var Shape = /*#__PURE__*/function (_Element) {
  1733. (0, _inherits2.default)(Shape, _Element);
  1734. var _super = (0, _createSuper2.default)(Shape);
  1735. function Shape() {
  1736. (0, _classCallCheck2.default)(this, Shape);
  1737. return _super.apply(this, arguments);
  1738. }
  1739. (0, _createClass2.default)(Shape, [{
  1740. key: "_initProperties",
  1741. value:
  1742. /* eslint-enable */
  1743. function _initProperties() {
  1744. this._attrs = (0, _objectSpread2.default)((0, _objectSpread2.default)({}, this._attrs), {}, {
  1745. zIndex: 0,
  1746. visible: true,
  1747. destroyed: false,
  1748. isShape: true,
  1749. attrs: {}
  1750. });
  1751. }
  1752. }, {
  1753. key: "getType",
  1754. value: function getType() {
  1755. return this._attrs.type;
  1756. }
  1757. }, {
  1758. key: "drawInner",
  1759. value: function drawInner(context) {
  1760. var attrs = this.get('attrs');
  1761. this.createPath(context);
  1762. var originOpacity = context.globalAlpha;
  1763. if (this.hasFill()) {
  1764. var fillOpacity = attrs.fillOpacity;
  1765. if (!(0, _util.isNil)(fillOpacity) && fillOpacity !== 1) {
  1766. context.globalAlpha = fillOpacity;
  1767. context.fill();
  1768. context.globalAlpha = originOpacity;
  1769. } else {
  1770. context.fill();
  1771. }
  1772. }
  1773. if (this.hasStroke()) {
  1774. var lineWidth = attrs.lineWidth;
  1775. if (lineWidth > 0) {
  1776. var strokeOpacity = attrs.strokeOpacity;
  1777. if (!(0, _util.isNil)(strokeOpacity) && strokeOpacity !== 1) {
  1778. context.globalAlpha = strokeOpacity;
  1779. }
  1780. context.stroke();
  1781. }
  1782. }
  1783. }
  1784. }, {
  1785. key: "getBBox",
  1786. value: function getBBox() {
  1787. var bbox = this._attrs.bbox;
  1788. if (!bbox) {
  1789. bbox = this.calculateBox();
  1790. if (bbox) {
  1791. bbox.x = bbox.minX;
  1792. bbox.y = bbox.minY;
  1793. bbox.width = bbox.maxX - bbox.minX;
  1794. bbox.height = bbox.maxY - bbox.minY;
  1795. }
  1796. this._attrs.bbox = bbox;
  1797. }
  1798. return bbox;
  1799. }
  1800. }, {
  1801. key: "calculateBox",
  1802. value: function calculateBox() {
  1803. return null;
  1804. }
  1805. }, {
  1806. key: "createPath",
  1807. value: function createPath(_context) {}
  1808. }]);
  1809. return Shape;
  1810. }(_element.default);
  1811. var _default = Shape;
  1812. exports.default = _default;
  1813. }, function(modId) { var map = {"../element":1663749502302}; return __REQUIRE__(map[modId], modId); })
  1814. __DEFINE__(1663749502302, function(require, module, exports) {
  1815. var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
  1816. Object.defineProperty(exports, "__esModule", {
  1817. value: true
  1818. });
  1819. exports.default = void 0;
  1820. var _objectSpread2 = _interopRequireDefault(require("@babel/runtime/helpers/objectSpread2"));
  1821. var _classCallCheck2 = _interopRequireDefault(require("@babel/runtime/helpers/classCallCheck"));
  1822. var _createClass2 = _interopRequireDefault(require("@babel/runtime/helpers/createClass"));
  1823. var _util = require("@antv/util");
  1824. var _matrix = _interopRequireDefault(require("../util/matrix"));
  1825. var _vector = _interopRequireDefault(require("../util/vector2"));
  1826. var _styleParse = require("../util/style-parse");
  1827. var _array = require("../util/array");
  1828. var ALIAS_ATTRS_MAP = {
  1829. stroke: 'strokeStyle',
  1830. fill: 'fillStyle',
  1831. opacity: 'globalAlpha'
  1832. };
  1833. var SHAPE_ATTRS = ['fillStyle', 'font', 'globalAlpha', 'lineCap', 'lineWidth', 'lineJoin', 'miterLimit', 'shadowBlur', 'shadowColor', 'shadowOffsetX', 'shadowOffsetY', 'strokeStyle', 'textAlign', 'textBaseline', 'lineDash', 'shadow' // 兼容支付宝小程序
  1834. ];
  1835. var CLIP_SHAPES = ['circle', 'sector', 'polygon', 'rect', 'polyline', 'custom'];
  1836. var Element = /*#__PURE__*/function () {
  1837. function Element(cfg) {
  1838. (0, _classCallCheck2.default)(this, Element);
  1839. this._initProperties();
  1840. (0, _util.mix)(this._attrs, cfg);
  1841. var attrs = this._attrs.attrs;
  1842. if (attrs) {
  1843. this.initAttrs(attrs);
  1844. }
  1845. this.initTransform();
  1846. }
  1847. (0, _createClass2.default)(Element, [{
  1848. key: "_initProperties",
  1849. value: function _initProperties() {
  1850. this._attrs = (0, _objectSpread2.default)((0, _objectSpread2.default)({}, this._attrs), {}, {
  1851. zIndex: 0,
  1852. visible: true,
  1853. destroyed: false
  1854. });
  1855. }
  1856. }, {
  1857. key: "get",
  1858. value: function get(name) {
  1859. return this._attrs[name];
  1860. }
  1861. }, {
  1862. key: "set",
  1863. value: function set(name, value) {
  1864. this._attrs[name] = value;
  1865. }
  1866. }, {
  1867. key: "isGroup",
  1868. value: function isGroup() {
  1869. return this.get('isGroup');
  1870. }
  1871. }, {
  1872. key: "isShape",
  1873. value: function isShape() {
  1874. return this.get('isShape');
  1875. }
  1876. }, {
  1877. key: "initAttrs",
  1878. value: function initAttrs(attrs) {
  1879. this.attr((0, _util.mix)(this.getDefaultAttrs(), attrs));
  1880. }
  1881. }, {
  1882. key: "getDefaultAttrs",
  1883. value: function getDefaultAttrs() {
  1884. return {};
  1885. }
  1886. }, {
  1887. key: "_setAttr",
  1888. value: function _setAttr(name, value) {
  1889. var attrs = this._attrs.attrs;
  1890. if (name === 'clip') {
  1891. value = this._setAttrClip(value);
  1892. } else {
  1893. var alias = ALIAS_ATTRS_MAP[name];
  1894. if (alias) {
  1895. attrs[alias] = value;
  1896. }
  1897. }
  1898. attrs[name] = value;
  1899. }
  1900. }, {
  1901. key: "_getAttr",
  1902. value: function _getAttr(name) {
  1903. var _this$_attrs, _this$_attrs$attrs;
  1904. return (_this$_attrs = this._attrs) === null || _this$_attrs === void 0 ? void 0 : (_this$_attrs$attrs = _this$_attrs.attrs) === null || _this$_attrs$attrs === void 0 ? void 0 : _this$_attrs$attrs[name];
  1905. }
  1906. }, {
  1907. key: "_afterAttrsSet",
  1908. value: function _afterAttrsSet() {}
  1909. }, {
  1910. key: "_setAttrClip",
  1911. value: function _setAttrClip(clip) {
  1912. if (clip && CLIP_SHAPES.indexOf(clip._attrs.type) > -1) {
  1913. if (clip.get('canvas') === null) {
  1914. clip = (0, _objectSpread2.default)({}, clip);
  1915. }
  1916. clip.set('parent', this.get('parent'));
  1917. clip.set('context', this.get('context'));
  1918. return clip;
  1919. }
  1920. return null;
  1921. }
  1922. }, {
  1923. key: "attr",
  1924. value: function attr(name, value) {
  1925. if (this.get('destroyed')) return null;
  1926. var argumentsLen = arguments.length;
  1927. if (argumentsLen === 0) {
  1928. return this._attrs.attrs;
  1929. }
  1930. if ((0, _util.isObject)(name)) {
  1931. this._attrs.bbox = null;
  1932. for (var k in name) {
  1933. this._setAttr(k, name[k]);
  1934. }
  1935. if (this._afterAttrsSet) {
  1936. this._afterAttrsSet();
  1937. }
  1938. return this;
  1939. }
  1940. if (argumentsLen === 2) {
  1941. this._attrs.bbox = null;
  1942. this._setAttr(name, value);
  1943. if (this._afterAttrsSet) {
  1944. this._afterAttrsSet();
  1945. }
  1946. return this;
  1947. }
  1948. return this._getAttr(name);
  1949. }
  1950. }, {
  1951. key: "getParent",
  1952. value: function getParent() {
  1953. return this.get('parent');
  1954. }
  1955. }, {
  1956. key: "draw",
  1957. value: function draw(context) {
  1958. if (this.get('destroyed')) {
  1959. return;
  1960. }
  1961. if (this.get('visible')) {
  1962. this.setContext(context);
  1963. this.drawInner(context);
  1964. this.restoreContext(context);
  1965. }
  1966. }
  1967. }, {
  1968. key: "setContext",
  1969. value: function setContext(context) {
  1970. var clip = this._attrs.attrs.clip;
  1971. context.save();
  1972. if (clip && !clip._attrs.destroyed) {
  1973. clip.resetTransform(context);
  1974. clip.createPath(context);
  1975. context.clip();
  1976. }
  1977. this.resetContext(context);
  1978. this.resetTransform(context);
  1979. }
  1980. }, {
  1981. key: "restoreContext",
  1982. value: function restoreContext(context) {
  1983. context.restore();
  1984. }
  1985. }, {
  1986. key: "resetContext",
  1987. value: function resetContext(context) {
  1988. var elAttrs = this._attrs.attrs;
  1989. for (var k in elAttrs) {
  1990. if (SHAPE_ATTRS.indexOf(k) > -1) {
  1991. var v = elAttrs[k];
  1992. if ((k === 'fillStyle' || k === 'strokeStyle') && v) {
  1993. v = (0, _styleParse.parseStyle)(v, this, context);
  1994. }
  1995. if (k === 'lineDash' && context.setLineDash && (0, _util.isArray)(v)) {
  1996. context.setLineDash(v);
  1997. } else {
  1998. context[k] = v;
  1999. }
  2000. }
  2001. }
  2002. }
  2003. }, {
  2004. key: "hasFill",
  2005. value: function hasFill() {
  2006. return this.get('canFill') && this._attrs.attrs.fillStyle;
  2007. }
  2008. }, {
  2009. key: "hasStroke",
  2010. value: function hasStroke() {
  2011. return this.get('canStroke') && this._attrs.attrs.strokeStyle;
  2012. }
  2013. }, {
  2014. key: "drawInner",
  2015. value: function drawInner(_context) {}
  2016. }, {
  2017. key: "show",
  2018. value: function show() {
  2019. this.set('visible', true);
  2020. return this;
  2021. }
  2022. }, {
  2023. key: "hide",
  2024. value: function hide() {
  2025. this.set('visible', false);
  2026. return this;
  2027. }
  2028. }, {
  2029. key: "isVisible",
  2030. value: function isVisible() {
  2031. return this.get('visible');
  2032. }
  2033. }, {
  2034. key: "getAriaLabel",
  2035. value: function getAriaLabel() {
  2036. var _this$_attrs2 = this._attrs,
  2037. destroyed = _this$_attrs2.destroyed,
  2038. visible = _this$_attrs2.visible,
  2039. isShape = _this$_attrs2.isShape,
  2040. aria = _this$_attrs2.aria;
  2041. if (destroyed || !visible || isShape && !aria) {
  2042. return;
  2043. }
  2044. return this._getAriaLabel();
  2045. }
  2046. }, {
  2047. key: "_getAriaLabel",
  2048. value: function _getAriaLabel() {
  2049. return this._attrs.ariaLabel;
  2050. }
  2051. }, {
  2052. key: "_removeFromParent",
  2053. value: function _removeFromParent() {
  2054. var parent = this.get('parent');
  2055. if (parent) {
  2056. var children = parent.get('children');
  2057. (0, _array.remove)(children, this);
  2058. }
  2059. return this;
  2060. }
  2061. }, {
  2062. key: "remove",
  2063. value: function remove(destroy) {
  2064. if (destroy) {
  2065. this.destroy();
  2066. } else {
  2067. this._removeFromParent();
  2068. }
  2069. }
  2070. }, {
  2071. key: "destroy",
  2072. value: function destroy() {
  2073. var destroyed = this.get('destroyed');
  2074. if (destroyed) {
  2075. return null;
  2076. }
  2077. this._removeFromParent();
  2078. this._attrs = {};
  2079. this.set('destroyed', true);
  2080. }
  2081. }, {
  2082. key: "getBBox",
  2083. value: function getBBox() {
  2084. return {
  2085. minX: 0,
  2086. maxX: 0,
  2087. minY: 0,
  2088. maxY: 0,
  2089. width: 0,
  2090. height: 0
  2091. };
  2092. }
  2093. }, {
  2094. key: "initTransform",
  2095. value: function initTransform() {
  2096. var attrs = this._attrs.attrs;
  2097. if (!attrs) {
  2098. attrs = {};
  2099. }
  2100. if (!attrs.matrix) {
  2101. attrs.matrix = [1, 0, 0, 1, 0, 0];
  2102. }
  2103. this._attrs.attrs = attrs;
  2104. }
  2105. }, {
  2106. key: "getMatrix",
  2107. value: function getMatrix() {
  2108. return this._attrs.attrs.matrix;
  2109. }
  2110. }, {
  2111. key: "setMatrix",
  2112. value: function setMatrix(m) {
  2113. this._attrs.attrs.matrix = [m[0], m[1], m[2], m[3], m[4], m[5]];
  2114. }
  2115. }, {
  2116. key: "transform",
  2117. value: function transform(actions) {
  2118. var matrix = this._attrs.attrs.matrix;
  2119. this._attrs.attrs.matrix = _matrix.default.transform(matrix, actions);
  2120. return this;
  2121. }
  2122. }, {
  2123. key: "setTransform",
  2124. value: function setTransform(actions) {
  2125. this._attrs.attrs.matrix = [1, 0, 0, 1, 0, 0];
  2126. return this.transform(actions);
  2127. }
  2128. }, {
  2129. key: "translate",
  2130. value: function translate(x, y) {
  2131. var matrix = this._attrs.attrs.matrix;
  2132. _matrix.default.translate(matrix, matrix, [x, y]);
  2133. }
  2134. }, {
  2135. key: "rotate",
  2136. value: function rotate(rad) {
  2137. var matrix = this._attrs.attrs.matrix;
  2138. _matrix.default.rotate(matrix, matrix, rad);
  2139. }
  2140. }, {
  2141. key: "scale",
  2142. value: function scale(sx, sy) {
  2143. var matrix = this._attrs.attrs.matrix;
  2144. _matrix.default.scale(matrix, matrix, [sx, sy]);
  2145. }
  2146. }, {
  2147. key: "moveTo",
  2148. value: function moveTo(x, y) {
  2149. var cx = this._attrs.x || 0;
  2150. var cy = this._attrs.y || 0;
  2151. this.translate(x - cx, y - cy);
  2152. this.set('x', x);
  2153. this.set('y', y);
  2154. }
  2155. }, {
  2156. key: "apply",
  2157. value: function apply(v) {
  2158. var m = this._attrs.attrs.matrix;
  2159. _vector.default.transformMat2d(v, v, m);
  2160. return this;
  2161. }
  2162. }, {
  2163. key: "resetTransform",
  2164. value: function resetTransform(context) {
  2165. var mo = this._attrs.attrs.matrix;
  2166. if (_matrix.default.isChanged(mo)) {
  2167. context.transform(mo[0], mo[1], mo[2], mo[3], mo[4], mo[5]);
  2168. }
  2169. }
  2170. }, {
  2171. key: "isDestroyed",
  2172. value: function isDestroyed() {
  2173. return this.get('destroyed');
  2174. }
  2175. }]);
  2176. return Element;
  2177. }();
  2178. var _default = Element;
  2179. exports.default = _default;
  2180. }, function(modId) { var map = {"../util/matrix":1663749502288,"../util/vector2":1663749502289,"../util/style-parse":1663749502303,"../util/array":1663749502299}; return __REQUIRE__(map[modId], modId); })
  2181. __DEFINE__(1663749502303, function(require, module, exports) {
  2182. Object.defineProperty(exports, "__esModule", {
  2183. value: true
  2184. });
  2185. exports.default = void 0;
  2186. exports.parseStyle = parseStyle;
  2187. var _util = require("@antv/util");
  2188. function _mod(n, m) {
  2189. return (n % m + m) % m;
  2190. }
  2191. function _addStop(steps, gradient) {
  2192. (0, _util.each)(steps, function (item) {
  2193. item = item.split(':');
  2194. gradient.addColorStop(Number(item[0]), item[1]);
  2195. });
  2196. } // the string format: 'l(0) 0:#ffffff 0.5:#7ec2f3 1:#1890ff'
  2197. function _parseLineGradient(color, shape, context) {
  2198. var arr = color.split(' ');
  2199. var angle = arr[0].slice(2, arr[0].length - 1);
  2200. angle = _mod(parseFloat(angle) * Math.PI / 180, Math.PI * 2);
  2201. var steps = arr.slice(1);
  2202. var _shape$getBBox = shape.getBBox(),
  2203. minX = _shape$getBBox.minX,
  2204. minY = _shape$getBBox.minY,
  2205. maxX = _shape$getBBox.maxX,
  2206. maxY = _shape$getBBox.maxY;
  2207. var start;
  2208. var end;
  2209. if (angle >= 0 && angle < 0.5 * Math.PI) {
  2210. start = {
  2211. x: minX,
  2212. y: minY
  2213. };
  2214. end = {
  2215. x: maxX,
  2216. y: maxY
  2217. };
  2218. } else if (0.5 * Math.PI <= angle && angle < Math.PI) {
  2219. start = {
  2220. x: maxX,
  2221. y: minY
  2222. };
  2223. end = {
  2224. x: minX,
  2225. y: maxY
  2226. };
  2227. } else if (Math.PI <= angle && angle < 1.5 * Math.PI) {
  2228. start = {
  2229. x: maxX,
  2230. y: maxY
  2231. };
  2232. end = {
  2233. x: minX,
  2234. y: minY
  2235. };
  2236. } else {
  2237. start = {
  2238. x: minX,
  2239. y: maxY
  2240. };
  2241. end = {
  2242. x: maxX,
  2243. y: minY
  2244. };
  2245. }
  2246. var tanTheta = Math.tan(angle);
  2247. var tanTheta2 = tanTheta * tanTheta;
  2248. var x = (end.x - start.x + tanTheta * (end.y - start.y)) / (tanTheta2 + 1) + start.x;
  2249. var y = tanTheta * (end.x - start.x + tanTheta * (end.y - start.y)) / (tanTheta2 + 1) + start.y;
  2250. var gradient = context.createLinearGradient(start.x, start.y, x, y);
  2251. _addStop(steps, gradient);
  2252. return gradient;
  2253. } // the string format: 'r(0.5, 0.5, 0.1) 0:#ffffff 1:#1890ff'
  2254. function _parseRadialGradient(color, shape, context) {
  2255. var arr = color.split(' ');
  2256. var circleCfg = arr[0].slice(2, arr[0].length - 1);
  2257. circleCfg = circleCfg.split(',');
  2258. var fx = parseFloat(circleCfg[0]);
  2259. var fy = parseFloat(circleCfg[1]);
  2260. var fr = parseFloat(circleCfg[2]);
  2261. var steps = arr.slice(1); // if radius is 0, no gradient, stroke with the last color
  2262. if (fr === 0) {
  2263. var _color = steps[steps.length - 1];
  2264. return _color.split(':')[1];
  2265. }
  2266. var _shape$getBBox2 = shape.getBBox(),
  2267. width = _shape$getBBox2.width,
  2268. height = _shape$getBBox2.height,
  2269. minX = _shape$getBBox2.minX,
  2270. minY = _shape$getBBox2.minY;
  2271. var r = Math.sqrt(width * width + height * height) / 2;
  2272. var gradient = context.createRadialGradient(minX + width * fx, minY + height * fy, fr * r, minX + width / 2, minY + height / 2, r);
  2273. _addStop(steps, gradient);
  2274. return gradient;
  2275. }
  2276. function parseStyle(color, shape, context) {
  2277. if (color[1] === '(') {
  2278. try {
  2279. var firstCode = color[0];
  2280. if (firstCode === 'l') {
  2281. return _parseLineGradient(color, shape, context);
  2282. } else if (firstCode === 'r') {
  2283. return _parseRadialGradient(color, shape, context);
  2284. }
  2285. } catch (ev) {
  2286. console.error('error in parsing gradient string, please check if there are any extra whitespaces.');
  2287. console.error(ev);
  2288. }
  2289. }
  2290. return color;
  2291. }
  2292. var _default = {
  2293. parseStyle: parseStyle
  2294. };
  2295. exports.default = _default;
  2296. }, function(modId) { var map = {}; return __REQUIRE__(map[modId], modId); })
  2297. __DEFINE__(1663749502304, function(require, module, exports) {
  2298. var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
  2299. Object.defineProperty(exports, "__esModule", {
  2300. value: true
  2301. });
  2302. exports.default = void 0;
  2303. var _classCallCheck2 = _interopRequireDefault(require("@babel/runtime/helpers/classCallCheck"));
  2304. var _createClass2 = _interopRequireDefault(require("@babel/runtime/helpers/createClass"));
  2305. var _get2 = _interopRequireDefault(require("@babel/runtime/helpers/get"));
  2306. var _getPrototypeOf2 = _interopRequireDefault(require("@babel/runtime/helpers/getPrototypeOf"));
  2307. var _inherits2 = _interopRequireDefault(require("@babel/runtime/helpers/inherits"));
  2308. var _createSuper2 = _interopRequireDefault(require("@babel/runtime/helpers/createSuper"));
  2309. var _shape = _interopRequireDefault(require("./shape"));
  2310. var _util = require("@antv/util");
  2311. function parsePadding(padding) {
  2312. var top = 0;
  2313. var right = 0;
  2314. var bottom = 0;
  2315. var left = 0;
  2316. if ((0, _util.isNumber)(padding)) {
  2317. top = bottom = left = right = padding;
  2318. } else if ((0, _util.isArray)(padding)) {
  2319. top = padding[0];
  2320. right = !(0, _util.isNil)(padding[1]) ? padding[1] : padding[0];
  2321. bottom = !(0, _util.isNil)(padding[2]) ? padding[2] : padding[0];
  2322. left = !(0, _util.isNil)(padding[3]) ? padding[3] : right;
  2323. }
  2324. return [top, right, bottom, left];
  2325. } // 为了处理radius 大于 width 或 height 的场景
  2326. function parseRadius(radius, width, height) {
  2327. radius = parsePadding(radius); // 都为0
  2328. if (!radius[0] && !radius[1] && !radius[2] && !radius[3]) {
  2329. return radius;
  2330. }
  2331. var minWidth = Math.max(radius[0] + radius[1], radius[2] + radius[3]);
  2332. var minHeight = Math.max(radius[0] + radius[3], radius[1] + radius[2]);
  2333. var scale = Math.min(width / minWidth, height / minHeight);
  2334. if (scale < 1) {
  2335. return radius.map(function (r) {
  2336. return r * scale;
  2337. });
  2338. }
  2339. return radius;
  2340. }
  2341. var Rect = /*#__PURE__*/function (_Shape) {
  2342. (0, _inherits2.default)(Rect, _Shape);
  2343. var _super = (0, _createSuper2.default)(Rect);
  2344. function Rect() {
  2345. (0, _classCallCheck2.default)(this, Rect);
  2346. return _super.apply(this, arguments);
  2347. }
  2348. (0, _createClass2.default)(Rect, [{
  2349. key: "_initProperties",
  2350. value: function _initProperties() {
  2351. (0, _get2.default)((0, _getPrototypeOf2.default)(Rect.prototype), "_initProperties", this).call(this);
  2352. this._attrs.canFill = true;
  2353. this._attrs.canStroke = true;
  2354. this._attrs.type = 'rect';
  2355. }
  2356. }, {
  2357. key: "getDefaultAttrs",
  2358. value: function getDefaultAttrs() {
  2359. return {
  2360. x: 0,
  2361. y: 0,
  2362. width: 0,
  2363. height: 0,
  2364. radius: 0,
  2365. lineWidth: 0
  2366. };
  2367. }
  2368. }, {
  2369. key: "createRadiusPath",
  2370. value: function createRadiusPath(context, x, y, width, height, radius) {
  2371. radius = parseRadius(radius, width, height);
  2372. context.moveTo(x + radius[0], y);
  2373. context.lineTo(x + width - radius[1], y);
  2374. context.arc(x + width - radius[1], y + radius[1], radius[1], -Math.PI / 2, 0, false);
  2375. context.lineTo(x + width, y + height - radius[2]);
  2376. context.arc(x + width - radius[2], y + height - radius[2], radius[2], 0, Math.PI / 2, false);
  2377. context.lineTo(x + radius[3], y + height);
  2378. context.arc(x + radius[3], y + height - radius[3], radius[3], Math.PI / 2, Math.PI, false);
  2379. context.lineTo(x, y + radius[0]);
  2380. context.arc(x + radius[0], y + radius[0], radius[0], Math.PI, Math.PI * 3 / 2, false);
  2381. context.closePath();
  2382. }
  2383. }, {
  2384. key: "createPath",
  2385. value: function createPath(context) {
  2386. var attrs = this.get('attrs');
  2387. var x = attrs.x,
  2388. y = attrs.y,
  2389. width = attrs.width,
  2390. height = attrs.height,
  2391. radius = attrs.radius;
  2392. context.beginPath();
  2393. if (!radius || !(width * height)) {
  2394. context.rect(x, y, width, height);
  2395. } else {
  2396. this.createRadiusPath(context, x, y, width, height, radius);
  2397. }
  2398. }
  2399. }, {
  2400. key: "calculateBox",
  2401. value: function calculateBox() {
  2402. var attrs = this.get('attrs');
  2403. var x = attrs.x,
  2404. y = attrs.y,
  2405. width = attrs.width,
  2406. height = attrs.height;
  2407. return {
  2408. minX: x,
  2409. minY: y,
  2410. maxX: x + width,
  2411. maxY: y + height
  2412. };
  2413. }
  2414. }]);
  2415. return Rect;
  2416. }(_shape.default);
  2417. var _default = Rect;
  2418. exports.default = _default;
  2419. }, function(modId) { var map = {"./shape":1663749502301}; return __REQUIRE__(map[modId], modId); })
  2420. __DEFINE__(1663749502305, function(require, module, exports) {
  2421. var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
  2422. Object.defineProperty(exports, "__esModule", {
  2423. value: true
  2424. });
  2425. exports.default = void 0;
  2426. var _classCallCheck2 = _interopRequireDefault(require("@babel/runtime/helpers/classCallCheck"));
  2427. var _createClass2 = _interopRequireDefault(require("@babel/runtime/helpers/createClass"));
  2428. var _get2 = _interopRequireDefault(require("@babel/runtime/helpers/get"));
  2429. var _getPrototypeOf2 = _interopRequireDefault(require("@babel/runtime/helpers/getPrototypeOf"));
  2430. var _inherits2 = _interopRequireDefault(require("@babel/runtime/helpers/inherits"));
  2431. var _createSuper2 = _interopRequireDefault(require("@babel/runtime/helpers/createSuper"));
  2432. var _util = require("@antv/util");
  2433. var _rect = _interopRequireDefault(require("./rect"));
  2434. var imageCaches = {};
  2435. var ImageShape = /*#__PURE__*/function (_Rect) {
  2436. (0, _inherits2.default)(ImageShape, _Rect);
  2437. var _super = (0, _createSuper2.default)(ImageShape);
  2438. function ImageShape() {
  2439. (0, _classCallCheck2.default)(this, ImageShape);
  2440. return _super.apply(this, arguments);
  2441. }
  2442. (0, _createClass2.default)(ImageShape, [{
  2443. key: "_initProperties",
  2444. value: function _initProperties() {
  2445. (0, _get2.default)((0, _getPrototypeOf2.default)(ImageShape.prototype), "_initProperties", this).call(this);
  2446. this._attrs.canFill = false;
  2447. this._attrs.canStroke = false;
  2448. this._attrs.loading = false;
  2449. this._attrs.image = null;
  2450. this._attrs.type = 'image';
  2451. }
  2452. }, {
  2453. key: "draw",
  2454. value: function draw(context) {
  2455. var _this = this;
  2456. // 如果图片还在loading中直接返回,等下次绘制
  2457. if (this.get('loading')) {
  2458. return;
  2459. } // 如果已经有image对象,直接绘制,会调用createPath绘制
  2460. var image = this.get('image');
  2461. if (image) {
  2462. (0, _get2.default)((0, _getPrototypeOf2.default)(ImageShape.prototype), "draw", this).call(this, context);
  2463. return;
  2464. }
  2465. var attrs = this.get('attrs');
  2466. var src = attrs.src;
  2467. if (src) {
  2468. var cacheImage = this.get('cacheImage'); // 如果有缓存,则直接从缓存中拿
  2469. if (cacheImage && imageCaches[src]) {
  2470. this.set('image', imageCaches[src]);
  2471. this.draw(context);
  2472. return;
  2473. }
  2474. var _image = null;
  2475. var canvas = this.get('canvas');
  2476. if (canvas && canvas.get('createImage')) {
  2477. var createImage = canvas.get('createImage');
  2478. _image = createImage();
  2479. } else if (window.Image) {
  2480. _image = new Image();
  2481. }
  2482. if (_image) {
  2483. this.set('loading', true); // 设置跨域, 等同于 image.crossOrigin = 'anonymous'
  2484. _image.crossOrigin = '';
  2485. _image.onload = function () {
  2486. _this.set('loading', false);
  2487. _this.set('image', _image); // this.draw(context);
  2488. // 这里需要调用 canvas.draw 进行重新绘制,否则 image 会一直在最上层
  2489. canvas.draw();
  2490. }; // src 一定要在 crossOrigin 之后,否则 toDataURL 就会报 SecurityError
  2491. _image.src = src; // 设置全局缓存
  2492. if (cacheImage) {
  2493. imageCaches[src] = _image;
  2494. }
  2495. }
  2496. }
  2497. }
  2498. }, {
  2499. key: "createPath",
  2500. value: function createPath(context) {
  2501. var image = this.get('image');
  2502. this.drawImage(context, image);
  2503. }
  2504. }, {
  2505. key: "drawImage",
  2506. value: function drawImage(context, image) {
  2507. var _this$_attrs = this._attrs,
  2508. attrs = _this$_attrs.attrs,
  2509. destroyed = _this$_attrs.destroyed;
  2510. if (destroyed) {
  2511. return;
  2512. }
  2513. var x = attrs.x,
  2514. y = attrs.y,
  2515. width = attrs.width,
  2516. height = attrs.height,
  2517. sx = attrs.sx,
  2518. sy = attrs.sy,
  2519. swidth = attrs.swidth,
  2520. sheight = attrs.sheight,
  2521. radius = attrs.radius,
  2522. fillOpacity = attrs.fillOpacity;
  2523. if (radius) {
  2524. context.save();
  2525. this.createRadiusPath(context, x, y, width, height, radius);
  2526. context.clip();
  2527. } // 设置透明度
  2528. var originOpacity = context.globalAlpha;
  2529. if (!(0, _util.isNil)(fillOpacity)) {
  2530. context.globalAlpha = fillOpacity;
  2531. }
  2532. if (!(0, _util.isNil)(sx) && !(0, _util.isNil)(sy) && !(0, _util.isNil)(swidth) && !(0, _util.isNil)(sheight)) {
  2533. context.drawImage(image, sx, sy, swidth, sheight, x, y, width, height);
  2534. } else {
  2535. context.drawImage(image, x, y, width, height);
  2536. }
  2537. context.globalAlpha = originOpacity;
  2538. if (radius) {
  2539. // 因为 save 和 restore 会一定程度上影响绘图性能,所以只在必要是调用
  2540. context.restore();
  2541. }
  2542. }
  2543. }]);
  2544. return ImageShape;
  2545. }(_rect.default);
  2546. var _default = ImageShape;
  2547. exports.default = _default;
  2548. }, function(modId) { var map = {"./rect":1663749502304}; return __REQUIRE__(map[modId], modId); })
  2549. __DEFINE__(1663749502306, function(require, module, exports) {
  2550. var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
  2551. Object.defineProperty(exports, "__esModule", {
  2552. value: true
  2553. });
  2554. exports.default = void 0;
  2555. var _classCallCheck2 = _interopRequireDefault(require("@babel/runtime/helpers/classCallCheck"));
  2556. var _createClass2 = _interopRequireDefault(require("@babel/runtime/helpers/createClass"));
  2557. var _get2 = _interopRequireDefault(require("@babel/runtime/helpers/get"));
  2558. var _getPrototypeOf2 = _interopRequireDefault(require("@babel/runtime/helpers/getPrototypeOf"));
  2559. var _inherits2 = _interopRequireDefault(require("@babel/runtime/helpers/inherits"));
  2560. var _createSuper2 = _interopRequireDefault(require("@babel/runtime/helpers/createSuper"));
  2561. var _shape = _interopRequireDefault(require("./shape"));
  2562. var Circle = /*#__PURE__*/function (_Shape) {
  2563. (0, _inherits2.default)(Circle, _Shape);
  2564. var _super = (0, _createSuper2.default)(Circle);
  2565. function Circle() {
  2566. (0, _classCallCheck2.default)(this, Circle);
  2567. return _super.apply(this, arguments);
  2568. }
  2569. (0, _createClass2.default)(Circle, [{
  2570. key: "_initProperties",
  2571. value: function _initProperties() {
  2572. (0, _get2.default)((0, _getPrototypeOf2.default)(Circle.prototype), "_initProperties", this).call(this);
  2573. this._attrs.canFill = true;
  2574. this._attrs.canStroke = true;
  2575. this._attrs.type = 'circle';
  2576. }
  2577. }, {
  2578. key: "getDefaultAttrs",
  2579. value: function getDefaultAttrs() {
  2580. return {
  2581. x: 0,
  2582. y: 0,
  2583. r: 0,
  2584. lineWidth: 0
  2585. };
  2586. }
  2587. }, {
  2588. key: "createPath",
  2589. value: function createPath(context) {
  2590. var attrs = this.get('attrs');
  2591. var x = attrs.x,
  2592. y = attrs.y,
  2593. r = attrs.r;
  2594. context.beginPath();
  2595. context.arc(x, y, r, 0, Math.PI * 2, false);
  2596. context.closePath();
  2597. }
  2598. }, {
  2599. key: "calculateBox",
  2600. value: function calculateBox() {
  2601. var attrs = this.get('attrs');
  2602. var x = attrs.x,
  2603. y = attrs.y,
  2604. r = attrs.r;
  2605. return {
  2606. minX: x - r,
  2607. maxX: x + r,
  2608. minY: y - r,
  2609. maxY: y + r
  2610. };
  2611. }
  2612. }]);
  2613. return Circle;
  2614. }(_shape.default);
  2615. var _default = Circle;
  2616. exports.default = _default;
  2617. }, function(modId) { var map = {"./shape":1663749502301}; return __REQUIRE__(map[modId], modId); })
  2618. __DEFINE__(1663749502307, function(require, module, exports) {
  2619. var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
  2620. Object.defineProperty(exports, "__esModule", {
  2621. value: true
  2622. });
  2623. exports.default = void 0;
  2624. var _classCallCheck2 = _interopRequireDefault(require("@babel/runtime/helpers/classCallCheck"));
  2625. var _createClass2 = _interopRequireDefault(require("@babel/runtime/helpers/createClass"));
  2626. var _get2 = _interopRequireDefault(require("@babel/runtime/helpers/get"));
  2627. var _getPrototypeOf2 = _interopRequireDefault(require("@babel/runtime/helpers/getPrototypeOf"));
  2628. var _inherits2 = _interopRequireDefault(require("@babel/runtime/helpers/inherits"));
  2629. var _createSuper2 = _interopRequireDefault(require("@babel/runtime/helpers/createSuper"));
  2630. var _shape = _interopRequireDefault(require("./shape"));
  2631. var _bbox = require("../../util/bbox");
  2632. var Line = /*#__PURE__*/function (_Shape) {
  2633. (0, _inherits2.default)(Line, _Shape);
  2634. var _super = (0, _createSuper2.default)(Line);
  2635. function Line() {
  2636. (0, _classCallCheck2.default)(this, Line);
  2637. return _super.apply(this, arguments);
  2638. }
  2639. (0, _createClass2.default)(Line, [{
  2640. key: "_initProperties",
  2641. value: function _initProperties() {
  2642. (0, _get2.default)((0, _getPrototypeOf2.default)(Line.prototype), "_initProperties", this).call(this);
  2643. this._attrs.canStroke = true;
  2644. this._attrs.type = 'line';
  2645. }
  2646. }, {
  2647. key: "getDefaultAttrs",
  2648. value: function getDefaultAttrs() {
  2649. return {
  2650. x1: 0,
  2651. y1: 0,
  2652. x2: 0,
  2653. y2: 0,
  2654. lineWidth: 1
  2655. };
  2656. }
  2657. }, {
  2658. key: "createPath",
  2659. value: function createPath(context) {
  2660. var attrs = this.get('attrs');
  2661. var x1 = attrs.x1,
  2662. y1 = attrs.y1,
  2663. x2 = attrs.x2,
  2664. y2 = attrs.y2;
  2665. context.beginPath();
  2666. context.moveTo(x1, y1);
  2667. context.lineTo(x2, y2);
  2668. }
  2669. }, {
  2670. key: "calculateBox",
  2671. value: function calculateBox() {
  2672. var attrs = this.get('attrs');
  2673. var x1 = attrs.x1,
  2674. y1 = attrs.y1,
  2675. x2 = attrs.x2,
  2676. y2 = attrs.y2,
  2677. lineWidth = attrs.lineWidth;
  2678. return (0, _bbox.getBBoxFromLine)(x1, y1, x2, y2, lineWidth);
  2679. }
  2680. }]);
  2681. return Line;
  2682. }(_shape.default);
  2683. var _default = Line;
  2684. exports.default = _default;
  2685. }, function(modId) { var map = {"./shape":1663749502301,"../../util/bbox":1663749502291}; return __REQUIRE__(map[modId], modId); })
  2686. __DEFINE__(1663749502308, function(require, module, exports) {
  2687. var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
  2688. Object.defineProperty(exports, "__esModule", {
  2689. value: true
  2690. });
  2691. exports.default = void 0;
  2692. var _classCallCheck2 = _interopRequireDefault(require("@babel/runtime/helpers/classCallCheck"));
  2693. var _createClass2 = _interopRequireDefault(require("@babel/runtime/helpers/createClass"));
  2694. var _get2 = _interopRequireDefault(require("@babel/runtime/helpers/get"));
  2695. var _getPrototypeOf2 = _interopRequireDefault(require("@babel/runtime/helpers/getPrototypeOf"));
  2696. var _inherits2 = _interopRequireDefault(require("@babel/runtime/helpers/inherits"));
  2697. var _createSuper2 = _interopRequireDefault(require("@babel/runtime/helpers/createSuper"));
  2698. var _shape = _interopRequireDefault(require("./shape"));
  2699. var _bbox = require("../../util/bbox");
  2700. var Polygon = /*#__PURE__*/function (_Shape) {
  2701. (0, _inherits2.default)(Polygon, _Shape);
  2702. var _super = (0, _createSuper2.default)(Polygon);
  2703. function Polygon() {
  2704. (0, _classCallCheck2.default)(this, Polygon);
  2705. return _super.apply(this, arguments);
  2706. }
  2707. (0, _createClass2.default)(Polygon, [{
  2708. key: "_initProperties",
  2709. value: function _initProperties() {
  2710. (0, _get2.default)((0, _getPrototypeOf2.default)(Polygon.prototype), "_initProperties", this).call(this);
  2711. this._attrs.canFill = true;
  2712. this._attrs.canStroke = true;
  2713. this._attrs.type = 'polygon';
  2714. }
  2715. }, {
  2716. key: "getDefaultAttrs",
  2717. value: function getDefaultAttrs() {
  2718. return {
  2719. points: null,
  2720. lineWidth: 0
  2721. };
  2722. }
  2723. }, {
  2724. key: "createPath",
  2725. value: function createPath(context) {
  2726. var attrs = this.get('attrs');
  2727. var points = attrs.points;
  2728. context.beginPath();
  2729. for (var i = 0, len = points.length; i < len; i++) {
  2730. var point = points[i];
  2731. if (i === 0) {
  2732. context.moveTo(point.x, point.y);
  2733. } else {
  2734. context.lineTo(point.x, point.y);
  2735. }
  2736. }
  2737. context.closePath();
  2738. }
  2739. }, {
  2740. key: "calculateBox",
  2741. value: function calculateBox() {
  2742. var attrs = this.get('attrs');
  2743. var points = attrs.points;
  2744. return (0, _bbox.getBBoxFromPoints)(points);
  2745. }
  2746. }]);
  2747. return Polygon;
  2748. }(_shape.default);
  2749. var _default = Polygon;
  2750. exports.default = _default;
  2751. }, function(modId) { var map = {"./shape":1663749502301,"../../util/bbox":1663749502291}; return __REQUIRE__(map[modId], modId); })
  2752. __DEFINE__(1663749502309, function(require, module, exports) {
  2753. var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
  2754. var _typeof = require("@babel/runtime/helpers/typeof");
  2755. Object.defineProperty(exports, "__esModule", {
  2756. value: true
  2757. });
  2758. exports.default = void 0;
  2759. var _classCallCheck2 = _interopRequireDefault(require("@babel/runtime/helpers/classCallCheck"));
  2760. var _createClass2 = _interopRequireDefault(require("@babel/runtime/helpers/createClass"));
  2761. var _get2 = _interopRequireDefault(require("@babel/runtime/helpers/get"));
  2762. var _getPrototypeOf2 = _interopRequireDefault(require("@babel/runtime/helpers/getPrototypeOf"));
  2763. var _inherits2 = _interopRequireDefault(require("@babel/runtime/helpers/inherits"));
  2764. var _createSuper2 = _interopRequireDefault(require("@babel/runtime/helpers/createSuper"));
  2765. var _shape = _interopRequireDefault(require("./shape"));
  2766. var _bbox = require("../../util/bbox");
  2767. var Smooth = _interopRequireWildcard(require("../../util/smooth"));
  2768. function _getRequireWildcardCache(nodeInterop) { if (typeof WeakMap !== "function") return null; var cacheBabelInterop = new WeakMap(); var cacheNodeInterop = new WeakMap(); return (_getRequireWildcardCache = function _getRequireWildcardCache(nodeInterop) { return nodeInterop ? cacheNodeInterop : cacheBabelInterop; })(nodeInterop); }
  2769. function _interopRequireWildcard(obj, nodeInterop) { if (!nodeInterop && obj && obj.__esModule) { return obj; } if (obj === null || _typeof(obj) !== "object" && typeof obj !== "function") { return { default: obj }; } var cache = _getRequireWildcardCache(nodeInterop); if (cache && cache.has(obj)) { return cache.get(obj); } var newObj = {}; var hasPropertyDescriptor = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var key in obj) { if (key !== "default" && Object.prototype.hasOwnProperty.call(obj, key)) { var desc = hasPropertyDescriptor ? Object.getOwnPropertyDescriptor(obj, key) : null; if (desc && (desc.get || desc.set)) { Object.defineProperty(newObj, key, desc); } else { newObj[key] = obj[key]; } } } newObj.default = obj; if (cache) { cache.set(obj, newObj); } return newObj; }
  2770. // filter the point which x or y is NaN
  2771. function _filterPoints(points) {
  2772. var filteredPoints = [];
  2773. for (var i = 0, len = points.length; i < len; i++) {
  2774. var point = points[i];
  2775. if (!isNaN(point.x) && !isNaN(point.y)) {
  2776. filteredPoints.push(point);
  2777. }
  2778. }
  2779. return filteredPoints;
  2780. }
  2781. var Polyline = /*#__PURE__*/function (_Shape) {
  2782. (0, _inherits2.default)(Polyline, _Shape);
  2783. var _super = (0, _createSuper2.default)(Polyline);
  2784. function Polyline() {
  2785. (0, _classCallCheck2.default)(this, Polyline);
  2786. return _super.apply(this, arguments);
  2787. }
  2788. (0, _createClass2.default)(Polyline, [{
  2789. key: "_initProperties",
  2790. value: function _initProperties() {
  2791. (0, _get2.default)((0, _getPrototypeOf2.default)(Polyline.prototype), "_initProperties", this).call(this);
  2792. this._attrs.canFill = true;
  2793. this._attrs.canStroke = true;
  2794. this._attrs.type = 'polyline';
  2795. }
  2796. }, {
  2797. key: "getDefaultAttrs",
  2798. value: function getDefaultAttrs() {
  2799. return {
  2800. points: null,
  2801. lineWidth: 1,
  2802. smooth: false
  2803. };
  2804. }
  2805. }, {
  2806. key: "createPath",
  2807. value: function createPath(context) {
  2808. var attrs = this.get('attrs');
  2809. var points = attrs.points,
  2810. smooth = attrs.smooth;
  2811. var filteredPoints = _filterPoints(points);
  2812. context.beginPath();
  2813. if (filteredPoints.length) {
  2814. context.moveTo(filteredPoints[0].x, filteredPoints[0].y);
  2815. if (smooth) {
  2816. var constaint = [[0, 0], [1, 1]];
  2817. var sps = Smooth.smooth(filteredPoints, false, constaint);
  2818. for (var i = 0, n = sps.length; i < n; i++) {
  2819. var sp = sps[i];
  2820. context.bezierCurveTo(sp[1], sp[2], sp[3], sp[4], sp[5], sp[6]);
  2821. }
  2822. } else {
  2823. var _i;
  2824. var l;
  2825. for (_i = 1, l = filteredPoints.length - 1; _i < l; _i++) {
  2826. context.lineTo(filteredPoints[_i].x, filteredPoints[_i].y);
  2827. }
  2828. context.lineTo(filteredPoints[l].x, filteredPoints[l].y);
  2829. }
  2830. }
  2831. }
  2832. }, {
  2833. key: "calculateBox",
  2834. value: function calculateBox() {
  2835. var attrs = this.get('attrs');
  2836. var points = attrs.points,
  2837. smooth = attrs.smooth,
  2838. lineWidth = attrs.lineWidth;
  2839. var filteredPoints = _filterPoints(points);
  2840. if (smooth) {
  2841. var newPoints = [];
  2842. var constaint = [[0, 0], [1, 1]];
  2843. var sps = Smooth.smooth(filteredPoints, false, constaint);
  2844. for (var i = 0, n = sps.length; i < n; i++) {
  2845. var sp = sps[i];
  2846. if (i === 0) {
  2847. newPoints.push([filteredPoints[0].x, filteredPoints[0].y, sp[1], sp[2], sp[3], sp[4], sp[5], sp[6]]);
  2848. } else {
  2849. var lastPoint = sps[i - 1];
  2850. newPoints.push([lastPoint[5], lastPoint[6], sp[1], sp[2], sp[3], sp[4], sp[5], sp[6]]);
  2851. }
  2852. }
  2853. return (0, _bbox.getBBoxFromBezierGroup)(newPoints, lineWidth);
  2854. }
  2855. return (0, _bbox.getBBoxFromPoints)(filteredPoints, lineWidth);
  2856. }
  2857. }]);
  2858. return Polyline;
  2859. }(_shape.default);
  2860. var _default = Polyline;
  2861. exports.default = _default;
  2862. }, function(modId) { var map = {"./shape":1663749502301,"../../util/bbox":1663749502291,"../../util/smooth":1663749502290}; return __REQUIRE__(map[modId], modId); })
  2863. __DEFINE__(1663749502310, function(require, module, exports) {
  2864. var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
  2865. Object.defineProperty(exports, "__esModule", {
  2866. value: true
  2867. });
  2868. exports.default = void 0;
  2869. var _classCallCheck2 = _interopRequireDefault(require("@babel/runtime/helpers/classCallCheck"));
  2870. var _createClass2 = _interopRequireDefault(require("@babel/runtime/helpers/createClass"));
  2871. var _get2 = _interopRequireDefault(require("@babel/runtime/helpers/get"));
  2872. var _getPrototypeOf2 = _interopRequireDefault(require("@babel/runtime/helpers/getPrototypeOf"));
  2873. var _inherits2 = _interopRequireDefault(require("@babel/runtime/helpers/inherits"));
  2874. var _createSuper2 = _interopRequireDefault(require("@babel/runtime/helpers/createSuper"));
  2875. var _shape = _interopRequireDefault(require("./shape"));
  2876. var _bbox = require("../../util/bbox");
  2877. var Arc = /*#__PURE__*/function (_Shape) {
  2878. (0, _inherits2.default)(Arc, _Shape);
  2879. var _super = (0, _createSuper2.default)(Arc);
  2880. function Arc() {
  2881. (0, _classCallCheck2.default)(this, Arc);
  2882. return _super.apply(this, arguments);
  2883. }
  2884. (0, _createClass2.default)(Arc, [{
  2885. key: "_initProperties",
  2886. value: function _initProperties() {
  2887. (0, _get2.default)((0, _getPrototypeOf2.default)(Arc.prototype), "_initProperties", this).call(this);
  2888. this._attrs.canStroke = true;
  2889. this._attrs.canFill = true;
  2890. this._attrs.type = 'arc';
  2891. }
  2892. }, {
  2893. key: "getDefaultAttrs",
  2894. value: function getDefaultAttrs() {
  2895. return {
  2896. x: 0,
  2897. y: 0,
  2898. r: 0,
  2899. startAngle: 0,
  2900. endAngle: Math.PI * 2,
  2901. anticlockwise: false,
  2902. lineWidth: 1
  2903. };
  2904. }
  2905. }, {
  2906. key: "createPath",
  2907. value: function createPath(context) {
  2908. var attrs = this.get('attrs');
  2909. var x = attrs.x,
  2910. y = attrs.y,
  2911. r = attrs.r,
  2912. startAngle = attrs.startAngle,
  2913. endAngle = attrs.endAngle,
  2914. anticlockwise = attrs.anticlockwise;
  2915. context.beginPath();
  2916. if (startAngle !== endAngle) {
  2917. context.arc(x, y, r, startAngle, endAngle, anticlockwise);
  2918. }
  2919. }
  2920. }, {
  2921. key: "calculateBox",
  2922. value: function calculateBox() {
  2923. var attrs = this.get('attrs');
  2924. var x = attrs.x,
  2925. y = attrs.y,
  2926. r = attrs.r,
  2927. startAngle = attrs.startAngle,
  2928. endAngle = attrs.endAngle,
  2929. anticlockwise = attrs.anticlockwise;
  2930. return (0, _bbox.getBBoxFromArc)(x, y, r, startAngle, endAngle, anticlockwise);
  2931. }
  2932. }]);
  2933. return Arc;
  2934. }(_shape.default);
  2935. var _default = Arc;
  2936. exports.default = _default;
  2937. }, function(modId) { var map = {"./shape":1663749502301,"../../util/bbox":1663749502291}; return __REQUIRE__(map[modId], modId); })
  2938. __DEFINE__(1663749502311, function(require, module, exports) {
  2939. var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
  2940. Object.defineProperty(exports, "__esModule", {
  2941. value: true
  2942. });
  2943. exports.default = void 0;
  2944. var _classCallCheck2 = _interopRequireDefault(require("@babel/runtime/helpers/classCallCheck"));
  2945. var _createClass2 = _interopRequireDefault(require("@babel/runtime/helpers/createClass"));
  2946. var _get2 = _interopRequireDefault(require("@babel/runtime/helpers/get"));
  2947. var _getPrototypeOf2 = _interopRequireDefault(require("@babel/runtime/helpers/getPrototypeOf"));
  2948. var _inherits2 = _interopRequireDefault(require("@babel/runtime/helpers/inherits"));
  2949. var _createSuper2 = _interopRequireDefault(require("@babel/runtime/helpers/createSuper"));
  2950. var _shape = _interopRequireDefault(require("./shape"));
  2951. var _bbox = require("../../util/bbox");
  2952. var Sector = /*#__PURE__*/function (_Shape) {
  2953. (0, _inherits2.default)(Sector, _Shape);
  2954. var _super = (0, _createSuper2.default)(Sector);
  2955. function Sector() {
  2956. (0, _classCallCheck2.default)(this, Sector);
  2957. return _super.apply(this, arguments);
  2958. }
  2959. (0, _createClass2.default)(Sector, [{
  2960. key: "_initProperties",
  2961. value: function _initProperties() {
  2962. (0, _get2.default)((0, _getPrototypeOf2.default)(Sector.prototype), "_initProperties", this).call(this);
  2963. this._attrs.canFill = true;
  2964. this._attrs.canStroke = true;
  2965. this._attrs.type = 'sector';
  2966. }
  2967. }, {
  2968. key: "getDefaultAttrs",
  2969. value: function getDefaultAttrs() {
  2970. return {
  2971. x: 0,
  2972. y: 0,
  2973. lineWidth: 0,
  2974. r: 0,
  2975. r0: 0,
  2976. startAngle: 0,
  2977. endAngle: Math.PI * 2,
  2978. anticlockwise: false
  2979. };
  2980. }
  2981. }, {
  2982. key: "createPath",
  2983. value: function createPath(context) {
  2984. var attrs = this.get('attrs');
  2985. var x = attrs.x,
  2986. y = attrs.y,
  2987. startAngle = attrs.startAngle,
  2988. r = attrs.r,
  2989. r0 = attrs.r0,
  2990. anticlockwise = attrs.anticlockwise; // 最大为整个圆
  2991. var endAngle = Math.min(attrs.endAngle, startAngle + Math.PI * 2);
  2992. context.beginPath();
  2993. var unitX = Math.cos(startAngle);
  2994. var unitY = Math.sin(startAngle);
  2995. context.moveTo(unitX * r0 + x, unitY * r0 + y);
  2996. context.lineTo(unitX * r + x, unitY * r + y); // 当扇形的角度非常小的时候,就不进行弧线的绘制;或者整个只有1个扇形时,会出现end<0的情况不绘制
  2997. if (Math.abs(endAngle - startAngle) > 0.0001 || startAngle === 0 && endAngle < 0) {
  2998. context.arc(x, y, r, startAngle, endAngle, anticlockwise);
  2999. context.lineTo(Math.cos(endAngle) * r0 + x, Math.sin(endAngle) * r0 + y);
  3000. if (r0 !== 0) {
  3001. context.arc(x, y, r0, endAngle, startAngle, !anticlockwise);
  3002. }
  3003. }
  3004. context.closePath();
  3005. }
  3006. }, {
  3007. key: "calculateBox",
  3008. value: function calculateBox() {
  3009. var attrs = this.get('attrs');
  3010. var x = attrs.x,
  3011. y = attrs.y,
  3012. r = attrs.r,
  3013. r0 = attrs.r0,
  3014. startAngle = attrs.startAngle,
  3015. endAngle = attrs.endAngle,
  3016. anticlockwise = attrs.anticlockwise;
  3017. var outerBBox = (0, _bbox.getBBoxFromArc)(x, y, r, startAngle, endAngle, anticlockwise);
  3018. var innerBBox = (0, _bbox.getBBoxFromArc)(x, y, r0, startAngle, endAngle, anticlockwise);
  3019. return {
  3020. minX: Math.min(outerBBox.minX, innerBBox.minX),
  3021. minY: Math.min(outerBBox.minY, innerBBox.minY),
  3022. maxX: Math.max(outerBBox.maxX, innerBBox.maxX),
  3023. maxY: Math.max(outerBBox.maxY, innerBBox.maxY)
  3024. };
  3025. }
  3026. }]);
  3027. return Sector;
  3028. }(_shape.default);
  3029. var _default = Sector;
  3030. exports.default = _default;
  3031. }, function(modId) { var map = {"./shape":1663749502301,"../../util/bbox":1663749502291}; return __REQUIRE__(map[modId], modId); })
  3032. __DEFINE__(1663749502312, function(require, module, exports) {
  3033. var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
  3034. var _typeof = require("@babel/runtime/helpers/typeof");
  3035. Object.defineProperty(exports, "__esModule", {
  3036. value: true
  3037. });
  3038. exports.default = void 0;
  3039. var _classCallCheck2 = _interopRequireDefault(require("@babel/runtime/helpers/classCallCheck"));
  3040. var _createClass2 = _interopRequireDefault(require("@babel/runtime/helpers/createClass"));
  3041. var _get2 = _interopRequireDefault(require("@babel/runtime/helpers/get"));
  3042. var _getPrototypeOf2 = _interopRequireDefault(require("@babel/runtime/helpers/getPrototypeOf"));
  3043. var _inherits2 = _interopRequireDefault(require("@babel/runtime/helpers/inherits"));
  3044. var _createSuper2 = _interopRequireDefault(require("@babel/runtime/helpers/createSuper"));
  3045. var _util = require("@antv/util");
  3046. var DOMUtil = _interopRequireWildcard(require("../../util/dom"));
  3047. var _shape = _interopRequireDefault(require("./shape"));
  3048. var _rect = _interopRequireDefault(require("../../util/rect"));
  3049. function _getRequireWildcardCache(nodeInterop) { if (typeof WeakMap !== "function") return null; var cacheBabelInterop = new WeakMap(); var cacheNodeInterop = new WeakMap(); return (_getRequireWildcardCache = function _getRequireWildcardCache(nodeInterop) { return nodeInterop ? cacheNodeInterop : cacheBabelInterop; })(nodeInterop); }
  3050. function _interopRequireWildcard(obj, nodeInterop) { if (!nodeInterop && obj && obj.__esModule) { return obj; } if (obj === null || _typeof(obj) !== "object" && typeof obj !== "function") { return { default: obj }; } var cache = _getRequireWildcardCache(nodeInterop); if (cache && cache.has(obj)) { return cache.get(obj); } var newObj = {}; var hasPropertyDescriptor = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var key in obj) { if (key !== "default" && Object.prototype.hasOwnProperty.call(obj, key)) { var desc = hasPropertyDescriptor ? Object.getOwnPropertyDescriptor(obj, key) : null; if (desc && (desc.get || desc.set)) { Object.defineProperty(newObj, key, desc); } else { newObj[key] = obj[key]; } } } newObj.default = obj; if (cache) { cache.set(obj, newObj); } return newObj; }
  3051. var measureText = DOMUtil.measureText;
  3052. var textWidthCacheCounter = 0;
  3053. var textWidthCache = {};
  3054. var TEXT_CACHE_MAX = 5000;
  3055. var Text = /*#__PURE__*/function (_Shape) {
  3056. (0, _inherits2.default)(Text, _Shape);
  3057. var _super = (0, _createSuper2.default)(Text);
  3058. function Text() {
  3059. (0, _classCallCheck2.default)(this, Text);
  3060. return _super.apply(this, arguments);
  3061. }
  3062. (0, _createClass2.default)(Text, [{
  3063. key: "_initProperties",
  3064. value: function _initProperties() {
  3065. (0, _get2.default)((0, _getPrototypeOf2.default)(Text.prototype), "_initProperties", this).call(this);
  3066. this._attrs.canFill = true;
  3067. this._attrs.canStroke = true;
  3068. this._attrs.type = 'text';
  3069. }
  3070. }, {
  3071. key: "getDefaultAttrs",
  3072. value: function getDefaultAttrs() {
  3073. return {
  3074. lineWidth: 0,
  3075. lineCount: 1,
  3076. fontSize: 12,
  3077. fontFamily: '',
  3078. fontStyle: 'normal',
  3079. fontWeight: 'normal',
  3080. fontVariant: 'normal',
  3081. textAlign: 'start',
  3082. textBaseline: 'bottom',
  3083. lineHeight: null,
  3084. textArr: null
  3085. };
  3086. }
  3087. }, {
  3088. key: "_getFontStyle",
  3089. value: function _getFontStyle() {
  3090. var attrs = this._attrs.attrs;
  3091. var fontSize = attrs.fontSize,
  3092. fontFamily = attrs.fontFamily,
  3093. fontWeight = attrs.fontWeight,
  3094. fontStyle = attrs.fontStyle,
  3095. fontVariant = attrs.fontVariant;
  3096. return "".concat(fontStyle, " ").concat(fontVariant, " ").concat(fontWeight, " ").concat(fontSize, "px ").concat(fontFamily);
  3097. }
  3098. }, {
  3099. key: "_afterAttrsSet",
  3100. value: function _afterAttrsSet() {
  3101. var attrs = this._attrs.attrs;
  3102. attrs.font = this._getFontStyle();
  3103. if (attrs.text) {
  3104. var text = attrs.text;
  3105. var textArr = null;
  3106. var lineCount = 1;
  3107. if ((0, _util.isString)(text) && text.indexOf('\n') !== -1) {
  3108. textArr = text.split('\n');
  3109. lineCount = textArr.length;
  3110. }
  3111. attrs.lineCount = lineCount;
  3112. attrs.textArr = textArr;
  3113. }
  3114. this.set('attrs', attrs);
  3115. }
  3116. }, {
  3117. key: "_getTextHeight",
  3118. value: function _getTextHeight() {
  3119. var attrs = this._attrs.attrs;
  3120. if (attrs.height) {
  3121. return attrs.height;
  3122. }
  3123. var lineCount = attrs.lineCount;
  3124. var fontSize = attrs.fontSize * 1;
  3125. if (lineCount > 1) {
  3126. var spaceingY = this._getSpaceingY();
  3127. return fontSize * lineCount + spaceingY * (lineCount - 1);
  3128. }
  3129. return fontSize;
  3130. }
  3131. }, {
  3132. key: "_getSpaceingY",
  3133. value: function _getSpaceingY() {
  3134. var attrs = this._attrs.attrs;
  3135. var lineHeight = attrs.lineHeight;
  3136. var fontSize = attrs.fontSize * 1;
  3137. return lineHeight ? lineHeight - fontSize : fontSize * 0.14;
  3138. }
  3139. }, {
  3140. key: "drawInner",
  3141. value: function drawInner(context) {
  3142. var attrs = this._attrs.attrs;
  3143. var text = attrs.text;
  3144. var x = attrs.x;
  3145. var y = attrs.y;
  3146. if ((0, _util.isNil)(text) || isNaN(x) || isNaN(y)) {
  3147. // text will be 0
  3148. return;
  3149. }
  3150. var textArr = attrs.textArr;
  3151. var fontSize = attrs.fontSize * 1;
  3152. var spaceingY = this._getSpaceingY();
  3153. if (attrs.rotate) {
  3154. // do rotation
  3155. context.translate(x, y);
  3156. context.rotate(attrs.rotate);
  3157. x = 0;
  3158. y = 0;
  3159. }
  3160. var textBaseline = attrs.textBaseline;
  3161. var height;
  3162. if (textArr) {
  3163. height = this._getTextHeight();
  3164. }
  3165. var subY; // context.beginPath();
  3166. if (this.hasFill()) {
  3167. var fillOpacity = attrs.fillOpacity;
  3168. if (!(0, _util.isNil)(fillOpacity) && fillOpacity !== 1) {
  3169. context.globalAlpha = fillOpacity;
  3170. }
  3171. if (textArr) {
  3172. for (var i = 0, len = textArr.length; i < len; i++) {
  3173. var subText = textArr[i];
  3174. subY = y + i * (spaceingY + fontSize) - height + fontSize; // bottom;
  3175. if (textBaseline === 'middle') {
  3176. subY += height - fontSize - (height - fontSize) / 2;
  3177. }
  3178. if (textBaseline === 'top') {
  3179. subY += height - fontSize;
  3180. }
  3181. context.fillText(subText, x, subY);
  3182. }
  3183. } else {
  3184. context.fillText(text, x, y);
  3185. }
  3186. }
  3187. if (this.hasStroke()) {
  3188. if (textArr) {
  3189. for (var _i = 0, _len = textArr.length; _i < _len; _i++) {
  3190. var _subText = textArr[_i];
  3191. subY = y + _i * (spaceingY + fontSize) - height + fontSize; // bottom;
  3192. if (textBaseline === 'middle') {
  3193. subY += height - fontSize - (height - fontSize) / 2;
  3194. }
  3195. if (textBaseline === 'top') {
  3196. subY += height - fontSize;
  3197. }
  3198. context.strokeText(_subText, x, subY);
  3199. }
  3200. } else {
  3201. context.strokeText(text, x, y);
  3202. }
  3203. }
  3204. }
  3205. }, {
  3206. key: "_getAriaLabel",
  3207. value: function _getAriaLabel() {
  3208. return this._attrs.attrs.text;
  3209. }
  3210. }, {
  3211. key: "calculateBox",
  3212. value: function calculateBox() {
  3213. var attrs = this._attrs.attrs;
  3214. var x = attrs.x,
  3215. y = attrs.y,
  3216. textAlign = attrs.textAlign,
  3217. textBaseline = attrs.textBaseline;
  3218. var width = this._getTextWidth(); // attrs.width
  3219. if (!width) {
  3220. return {
  3221. minX: x,
  3222. minY: y,
  3223. maxX: x,
  3224. maxY: y
  3225. };
  3226. }
  3227. var height = this._getTextHeight(); // attrs.height
  3228. if (attrs.rotate) {
  3229. var rotatedBox = _rect.default.calcRotatedBox({
  3230. width: width,
  3231. height: height,
  3232. rotate: attrs.rotate
  3233. });
  3234. width = rotatedBox.width;
  3235. height = rotatedBox.height;
  3236. }
  3237. var point = {
  3238. x: x,
  3239. y: y - height
  3240. }; // default textAlign: start, textBaseline: bottom
  3241. if (textAlign) {
  3242. if (textAlign === 'end' || textAlign === 'right') {
  3243. point.x -= width;
  3244. } else if (textAlign === 'center') {
  3245. point.x -= width / 2;
  3246. }
  3247. }
  3248. if (textBaseline) {
  3249. if (textBaseline === 'top') {
  3250. point.y += height;
  3251. } else if (textBaseline === 'middle') {
  3252. point.y += height / 2;
  3253. }
  3254. }
  3255. return {
  3256. minX: point.x,
  3257. minY: point.y,
  3258. maxX: point.x + width,
  3259. maxY: point.y + height
  3260. };
  3261. }
  3262. }, {
  3263. key: "_getTextWidth",
  3264. value: function _getTextWidth() {
  3265. var attrs = this._attrs.attrs;
  3266. if (attrs.width) {
  3267. return attrs.width;
  3268. }
  3269. var text = attrs.text;
  3270. var context = this.get('context');
  3271. if ((0, _util.isNil)(text)) return undefined;
  3272. var font = attrs.font;
  3273. var textArr = attrs.textArr;
  3274. var key = text + '' + font;
  3275. if (textWidthCache[key]) {
  3276. return textWidthCache[key];
  3277. }
  3278. var width = 0;
  3279. if (textArr) {
  3280. for (var i = 0, length = textArr.length; i < length; i++) {
  3281. var subText = textArr[i];
  3282. width = Math.max(width, measureText(subText, font, context).width);
  3283. }
  3284. } else {
  3285. width = measureText(text, font, context).width;
  3286. }
  3287. if (textWidthCacheCounter > TEXT_CACHE_MAX) {
  3288. textWidthCacheCounter = 0;
  3289. textWidthCache = {};
  3290. }
  3291. textWidthCacheCounter++;
  3292. textWidthCache[key] = width;
  3293. return width;
  3294. }
  3295. }]);
  3296. return Text;
  3297. }(_shape.default);
  3298. var _default = Text;
  3299. exports.default = _default;
  3300. }, function(modId) { var map = {"../../util/dom":1663749502296,"./shape":1663749502301,"../../util/rect":1663749502313}; return __REQUIRE__(map[modId], modId); })
  3301. __DEFINE__(1663749502313, function(require, module, exports) {
  3302. Object.defineProperty(exports, "__esModule", {
  3303. value: true
  3304. });
  3305. exports.default = void 0;
  3306. var Rect = {
  3307. calcRotatedBox: function calcRotatedBox(_ref) {
  3308. var width = _ref.width,
  3309. height = _ref.height,
  3310. rotate = _ref.rotate;
  3311. var absRotate = Math.abs(rotate);
  3312. return {
  3313. width: Math.abs(width * Math.cos(absRotate) + height * Math.sin(absRotate)),
  3314. height: Math.abs(height * Math.cos(absRotate) + width * Math.sin(absRotate))
  3315. };
  3316. }
  3317. };
  3318. var _default = Rect;
  3319. exports.default = _default;
  3320. }, function(modId) { var map = {}; return __REQUIRE__(map[modId], modId); })
  3321. __DEFINE__(1663749502314, function(require, module, exports) {
  3322. var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
  3323. Object.defineProperty(exports, "__esModule", {
  3324. value: true
  3325. });
  3326. exports.default = void 0;
  3327. var _classCallCheck2 = _interopRequireDefault(require("@babel/runtime/helpers/classCallCheck"));
  3328. var _createClass2 = _interopRequireDefault(require("@babel/runtime/helpers/createClass"));
  3329. var _get2 = _interopRequireDefault(require("@babel/runtime/helpers/get"));
  3330. var _getPrototypeOf2 = _interopRequireDefault(require("@babel/runtime/helpers/getPrototypeOf"));
  3331. var _inherits2 = _interopRequireDefault(require("@babel/runtime/helpers/inherits"));
  3332. var _createSuper2 = _interopRequireDefault(require("@babel/runtime/helpers/createSuper"));
  3333. var _shape = _interopRequireDefault(require("./shape"));
  3334. var Custom = /*#__PURE__*/function (_Shape) {
  3335. (0, _inherits2.default)(Custom, _Shape);
  3336. var _super = (0, _createSuper2.default)(Custom);
  3337. function Custom() {
  3338. (0, _classCallCheck2.default)(this, Custom);
  3339. return _super.apply(this, arguments);
  3340. }
  3341. (0, _createClass2.default)(Custom, [{
  3342. key: "_initProperties",
  3343. value: function _initProperties() {
  3344. (0, _get2.default)((0, _getPrototypeOf2.default)(Custom.prototype), "_initProperties", this).call(this);
  3345. this._attrs.canFill = true;
  3346. this._attrs.canStroke = true;
  3347. this._attrs.createPath = null;
  3348. this._attrs.type = 'custom';
  3349. }
  3350. }, {
  3351. key: "createPath",
  3352. value: function createPath(context) {
  3353. var createPath = this.get('createPath');
  3354. createPath && createPath.call(this, context);
  3355. }
  3356. }, {
  3357. key: "calculateBox",
  3358. value: function calculateBox() {
  3359. var calculateBox = this.get('calculateBox');
  3360. return calculateBox && calculateBox.call(this);
  3361. }
  3362. }]);
  3363. return Custom;
  3364. }(_shape.default);
  3365. var _default = Custom;
  3366. exports.default = _default;
  3367. }, function(modId) { var map = {"./shape":1663749502301}; return __REQUIRE__(map[modId], modId); })
  3368. __DEFINE__(1663749502315, function(require, module, exports) {
  3369. var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
  3370. Object.defineProperty(exports, "__esModule", {
  3371. value: true
  3372. });
  3373. exports.default = void 0;
  3374. var _classCallCheck2 = _interopRequireDefault(require("@babel/runtime/helpers/classCallCheck"));
  3375. var _createClass2 = _interopRequireDefault(require("@babel/runtime/helpers/createClass"));
  3376. var _get2 = _interopRequireDefault(require("@babel/runtime/helpers/get"));
  3377. var _getPrototypeOf2 = _interopRequireDefault(require("@babel/runtime/helpers/getPrototypeOf"));
  3378. var _inherits2 = _interopRequireDefault(require("@babel/runtime/helpers/inherits"));
  3379. var _createSuper2 = _interopRequireDefault(require("@babel/runtime/helpers/createSuper"));
  3380. var _util = require("@antv/util");
  3381. var _shape = _interopRequireDefault(require("./shape"));
  3382. /**
  3383. * marker shapes,used for tooltip and legend
  3384. */
  3385. var SYMBOLS = {
  3386. circle: function circle(x, y, r, ctx) {
  3387. ctx.arc(x, y, r, 0, Math.PI * 2, false);
  3388. },
  3389. square: function square(x, y, r, ctx) {
  3390. ctx.moveTo(x - r, y - r);
  3391. ctx.lineTo(x + r, y - r);
  3392. ctx.lineTo(x + r, y + r);
  3393. ctx.lineTo(x - r, y + r);
  3394. ctx.closePath();
  3395. }
  3396. };
  3397. var Marker = /*#__PURE__*/function (_Shape) {
  3398. (0, _inherits2.default)(Marker, _Shape);
  3399. var _super = (0, _createSuper2.default)(Marker);
  3400. function Marker() {
  3401. (0, _classCallCheck2.default)(this, Marker);
  3402. return _super.apply(this, arguments);
  3403. }
  3404. (0, _createClass2.default)(Marker, [{
  3405. key: "_initProperties",
  3406. value: function _initProperties() {
  3407. (0, _get2.default)((0, _getPrototypeOf2.default)(Marker.prototype), "_initProperties", this).call(this);
  3408. this._attrs.canFill = true;
  3409. this._attrs.canStroke = true;
  3410. this._attrs.type = 'marker';
  3411. }
  3412. }, {
  3413. key: "getDefaultAttrs",
  3414. value: function getDefaultAttrs() {
  3415. return {
  3416. x: 0,
  3417. y: 0,
  3418. lineWidth: 0
  3419. };
  3420. }
  3421. }, {
  3422. key: "createPath",
  3423. value: function createPath(context) {
  3424. var attrs = this.get('attrs');
  3425. var x = attrs.x,
  3426. y = attrs.y,
  3427. radius = attrs.radius;
  3428. var symbol = attrs.symbol || 'circle';
  3429. var method;
  3430. if ((0, _util.isFunction)(symbol)) {
  3431. method = symbol;
  3432. } else {
  3433. method = SYMBOLS[symbol];
  3434. }
  3435. context.beginPath();
  3436. method(x, y, radius, context, this);
  3437. }
  3438. }, {
  3439. key: "calculateBox",
  3440. value: function calculateBox() {
  3441. var attrs = this.get('attrs');
  3442. var x = attrs.x,
  3443. y = attrs.y,
  3444. radius = attrs.radius;
  3445. return {
  3446. minX: x - radius,
  3447. minY: y - radius,
  3448. maxX: x + radius,
  3449. maxY: y + radius
  3450. };
  3451. }
  3452. }]);
  3453. return Marker;
  3454. }(_shape.default);
  3455. var _default = Marker;
  3456. exports.default = _default;
  3457. }, function(modId) { var map = {"./shape":1663749502301}; return __REQUIRE__(map[modId], modId); })
  3458. __DEFINE__(1663749502316, function(require, module, exports) {
  3459. var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
  3460. Object.defineProperty(exports, "__esModule", {
  3461. value: true
  3462. });
  3463. exports.default = void 0;
  3464. var _classCallCheck2 = _interopRequireDefault(require("@babel/runtime/helpers/classCallCheck"));
  3465. var _createClass2 = _interopRequireDefault(require("@babel/runtime/helpers/createClass"));
  3466. var _get2 = _interopRequireDefault(require("@babel/runtime/helpers/get"));
  3467. var _getPrototypeOf2 = _interopRequireDefault(require("@babel/runtime/helpers/getPrototypeOf"));
  3468. var _inherits2 = _interopRequireDefault(require("@babel/runtime/helpers/inherits"));
  3469. var _createSuper2 = _interopRequireDefault(require("@babel/runtime/helpers/createSuper"));
  3470. var _util = require("@antv/util");
  3471. var _rect = _interopRequireDefault(require("./shape/rect"));
  3472. var _container = _interopRequireDefault(require("./container"));
  3473. var _vector = _interopRequireDefault(require("../util/vector2"));
  3474. var Group = /*#__PURE__*/function (_Rect) {
  3475. (0, _inherits2.default)(Group, _Rect);
  3476. var _super = (0, _createSuper2.default)(Group);
  3477. function Group() {
  3478. (0, _classCallCheck2.default)(this, Group);
  3479. return _super.apply(this, arguments);
  3480. }
  3481. (0, _createClass2.default)(Group, [{
  3482. key: "_initProperties",
  3483. value:
  3484. /* eslint-enable */
  3485. function _initProperties() {
  3486. this._attrs = {
  3487. type: 'group',
  3488. zIndex: 0,
  3489. visible: true,
  3490. destroyed: false,
  3491. isGroup: true,
  3492. canFill: true,
  3493. canStroke: true,
  3494. children: [],
  3495. attrs: {
  3496. x: 0,
  3497. y: 0,
  3498. width: 0,
  3499. height: 0,
  3500. radius: 0,
  3501. lineWidth: 0
  3502. }
  3503. };
  3504. }
  3505. }, {
  3506. key: "getBBox",
  3507. value: function getBBox() {
  3508. var minX = Infinity;
  3509. var maxX = -Infinity;
  3510. var minY = Infinity;
  3511. var maxY = -Infinity;
  3512. var children = this.get('children');
  3513. for (var i = 0, length = children.length; i < length; i++) {
  3514. var child = children[i];
  3515. if (child.get('visible')) {
  3516. var box = child.getBBox();
  3517. if (!box) {
  3518. continue;
  3519. }
  3520. var leftTop = [box.minX, box.minY];
  3521. var leftBottom = [box.minX, box.maxY];
  3522. var rightTop = [box.maxX, box.minY];
  3523. var rightBottom = [box.maxX, box.maxY];
  3524. var matrix = child.attr('matrix');
  3525. _vector.default.transformMat2d(leftTop, leftTop, matrix);
  3526. _vector.default.transformMat2d(leftBottom, leftBottom, matrix);
  3527. _vector.default.transformMat2d(rightTop, rightTop, matrix);
  3528. _vector.default.transformMat2d(rightBottom, rightBottom, matrix);
  3529. minX = Math.min(leftTop[0], leftBottom[0], rightTop[0], rightBottom[0], minX);
  3530. maxX = Math.max(leftTop[0], leftBottom[0], rightTop[0], rightBottom[0], maxX);
  3531. minY = Math.min(leftTop[1], leftBottom[1], rightTop[1], rightBottom[1], minY);
  3532. maxY = Math.max(leftTop[1], leftBottom[1], rightTop[1], rightBottom[1], maxY);
  3533. }
  3534. }
  3535. return {
  3536. minX: minX,
  3537. minY: minY,
  3538. maxX: maxX,
  3539. maxY: maxY,
  3540. x: minX,
  3541. y: minY,
  3542. width: maxX - minX,
  3543. height: maxY - minY
  3544. };
  3545. }
  3546. }, {
  3547. key: "createPath",
  3548. value: function createPath(context) {
  3549. var attrs = this.get('attrs'); // 只有在有fillStyle或strokeStyle 时才需要绘制
  3550. if (!attrs.fillStyle && !attrs.strokeStyle) {
  3551. return;
  3552. }
  3553. (0, _get2.default)((0, _getPrototypeOf2.default)(Group.prototype), "createPath", this).call(this, context);
  3554. }
  3555. }, {
  3556. key: "drawInner",
  3557. value: function drawInner(context) {
  3558. (0, _get2.default)((0, _getPrototypeOf2.default)(Group.prototype), "drawInner", this).call(this, context);
  3559. this.drawChildren(context);
  3560. }
  3561. }, {
  3562. key: "destroy",
  3563. value: function destroy() {
  3564. if (this.get('destroyed')) {
  3565. return;
  3566. }
  3567. this.clear();
  3568. (0, _get2.default)((0, _getPrototypeOf2.default)(Group.prototype), "destroy", this).call(this);
  3569. }
  3570. }]);
  3571. return Group;
  3572. }(_rect.default); // @ts-ignore
  3573. (0, _util.mix)(Group.prototype, _container.default, {
  3574. getGroupClass: function getGroupClass() {
  3575. return Group;
  3576. }
  3577. });
  3578. var _default = Group;
  3579. exports.default = _default;
  3580. }, function(modId) { var map = {"./shape/rect":1663749502304,"./container":1663749502298,"../util/vector2":1663749502289}; return __REQUIRE__(map[modId], modId); })
  3581. __DEFINE__(1663749502317, function(require, module, exports) {
  3582. var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
  3583. Object.defineProperty(exports, "__esModule", {
  3584. value: true
  3585. });
  3586. exports.requestAnimationFrame = void 0;
  3587. var _typeof2 = _interopRequireDefault(require("@babel/runtime/helpers/typeof"));
  3588. var requestAnimationFrame = (typeof window === "undefined" ? "undefined" : (0, _typeof2.default)(window)) === 'object' && window.requestAnimationFrame ? window.requestAnimationFrame : function (fn) {
  3589. return setTimeout(fn, 16);
  3590. };
  3591. exports.requestAnimationFrame = requestAnimationFrame;
  3592. }, function(modId) { var map = {}; return __REQUIRE__(map[modId], modId); })
  3593. __DEFINE__(1663749502318, function(require, module, exports) {
  3594. Object.defineProperty(exports, "__esModule", {
  3595. value: true
  3596. });
  3597. exports.default = void 0;
  3598. var _default = {
  3599. general: {
  3600. title: '这是一个图表,',
  3601. withTitle: '这是一个关于“{title}”的图表。'
  3602. },
  3603. coord: {
  3604. cartesian: 'X轴是{xLabel}Y轴是{yLabel}' // polar: '弧度是{xLabel}半径是{yLabel}'
  3605. },
  3606. scale: {
  3607. linear: '数值型,数据最小值为{min},最大值为{max};',
  3608. cat: '分类型, 分类类型有:{values};',
  3609. timeCat: '时间型,时间范围从{start}到{end};'
  3610. },
  3611. geometry: {
  3612. prefix: '共有{count}种分类组成,',
  3613. oneData: '第{index}类是{name},数据是{values};',
  3614. partData: '第{index}类是{name},共有{count}项数据,前{part}项是{values};',
  3615. allData: '第{index}类是{name},有{count}项数据,分别是{values};'
  3616. },
  3617. legend: {
  3618. prefix: '图例分类有:'
  3619. }
  3620. };
  3621. exports.default = _default;
  3622. }, function(modId) { var map = {}; return __REQUIRE__(map[modId], modId); })
  3623. __DEFINE__(1663749502319, function(require, module, exports) {
  3624. Object.defineProperty(exports, "__esModule", {
  3625. value: true
  3626. });
  3627. }, function(modId) { var map = {}; return __REQUIRE__(map[modId], modId); })
  3628. return __REQUIRE__(1663749502287);
  3629. })()
  3630. //miniprogram-npm-outsideDeps=["@babel/runtime/helpers/interopRequireDefault","@babel/runtime/helpers/typeof","@babel/runtime/helpers/classCallCheck","@babel/runtime/helpers/createClass","@babel/runtime/helpers/inherits","@babel/runtime/helpers/createSuper","@antv/util","@babel/runtime/helpers/objectSpread2","@babel/runtime/helpers/get","@babel/runtime/helpers/getPrototypeOf"]
  3631. //# sourceMappingURL=index.js.map