index.js 125 KB

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