1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092209320942095209620972098209921002101210221032104210521062107210821092110211121122113211421152116211721182119212021212122212321242125212621272128212921302131213221332134213521362137213821392140214121422143214421452146214721482149215021512152215321542155215621572158215921602161216221632164216521662167216821692170217121722173217421752176217721782179218021812182218321842185218621872188218921902191219221932194219521962197219821992200220122022203220422052206220722082209221022112212221322142215221622172218221922202221222222232224222522262227222822292230223122322233223422352236223722382239224022412242224322442245224622472248224922502251225222532254225522562257225822592260226122622263226422652266226722682269227022712272227322742275227622772278227922802281228222832284228522862287228822892290229122922293229422952296229722982299230023012302230323042305230623072308230923102311231223132314231523162317231823192320232123222323232423252326232723282329233023312332233323342335233623372338233923402341234223432344234523462347234823492350235123522353235423552356235723582359236023612362236323642365236623672368236923702371237223732374237523762377237823792380238123822383238423852386238723882389239023912392239323942395239623972398239924002401240224032404240524062407240824092410241124122413241424152416241724182419242024212422242324242425242624272428242924302431243224332434243524362437243824392440244124422443244424452446244724482449245024512452245324542455245624572458245924602461246224632464246524662467246824692470247124722473247424752476247724782479248024812482248324842485248624872488248924902491249224932494249524962497249824992500250125022503250425052506250725082509251025112512251325142515251625172518251925202521252225232524252525262527252825292530253125322533253425352536253725382539254025412542254325442545254625472548254925502551255225532554255525562557255825592560256125622563256425652566256725682569257025712572257325742575257625772578257925802581258225832584258525862587258825892590259125922593259425952596259725982599260026012602260326042605260626072608260926102611261226132614261526162617261826192620262126222623262426252626262726282629263026312632263326342635263626372638263926402641264226432644264526462647264826492650265126522653265426552656265726582659266026612662266326642665266626672668266926702671267226732674267526762677267826792680268126822683268426852686268726882689269026912692269326942695269626972698269927002701270227032704270527062707270827092710271127122713271427152716271727182719272027212722272327242725272627272728272927302731273227332734273527362737273827392740274127422743274427452746274727482749275027512752275327542755275627572758275927602761276227632764276527662767276827692770277127722773277427752776277727782779278027812782278327842785278627872788278927902791279227932794279527962797279827992800280128022803280428052806280728082809281028112812281328142815281628172818281928202821282228232824282528262827282828292830283128322833283428352836283728382839284028412842284328442845284628472848284928502851285228532854285528562857285828592860286128622863286428652866286728682869287028712872287328742875287628772878287928802881288228832884288528862887288828892890289128922893289428952896289728982899290029012902290329042905290629072908290929102911291229132914291529162917291829192920292129222923292429252926292729282929293029312932293329342935293629372938293929402941294229432944294529462947294829492950295129522953295429552956295729582959296029612962296329642965296629672968296929702971297229732974297529762977297829792980298129822983298429852986298729882989299029912992299329942995299629972998299930003001300230033004300530063007300830093010301130123013301430153016301730183019302030213022302330243025302630273028302930303031303230333034303530363037303830393040304130423043304430453046304730483049305030513052305330543055305630573058305930603061306230633064306530663067306830693070307130723073307430753076307730783079308030813082308330843085308630873088308930903091309230933094309530963097309830993100310131023103310431053106310731083109311031113112311331143115311631173118311931203121312231233124312531263127312831293130313131323133313431353136313731383139314031413142314331443145314631473148314931503151315231533154315531563157315831593160316131623163316431653166316731683169317031713172317331743175317631773178317931803181318231833184318531863187318831893190319131923193319431953196319731983199320032013202320332043205320632073208320932103211321232133214321532163217321832193220322132223223322432253226322732283229323032313232323332343235323632373238323932403241324232433244324532463247324832493250325132523253325432553256325732583259326032613262326332643265326632673268326932703271327232733274327532763277327832793280328132823283328432853286328732883289329032913292329332943295329632973298329933003301330233033304330533063307330833093310331133123313331433153316331733183319332033213322332333243325332633273328332933303331333233333334333533363337333833393340334133423343334433453346334733483349335033513352335333543355335633573358335933603361336233633364336533663367336833693370337133723373337433753376337733783379338033813382338333843385338633873388338933903391339233933394339533963397339833993400340134023403340434053406340734083409341034113412341334143415341634173418341934203421342234233424342534263427342834293430343134323433343434353436343734383439344034413442344334443445344634473448344934503451345234533454345534563457345834593460346134623463346434653466346734683469347034713472347334743475347634773478347934803481348234833484348534863487348834893490349134923493349434953496349734983499350035013502350335043505350635073508350935103511351235133514351535163517351835193520352135223523352435253526352735283529353035313532353335343535353635373538353935403541354235433544354535463547354835493550355135523553355435553556355735583559356035613562356335643565356635673568356935703571357235733574357535763577357835793580358135823583358435853586358735883589359035913592359335943595359635973598359936003601360236033604360536063607360836093610361136123613361436153616361736183619362036213622362336243625362636273628362936303631363236333634363536363637363836393640364136423643364436453646364736483649365036513652365336543655365636573658365936603661366236633664366536663667366836693670367136723673367436753676367736783679368036813682368336843685368636873688368936903691369236933694369536963697369836993700370137023703370437053706370737083709371037113712371337143715371637173718371937203721372237233724372537263727372837293730373137323733373437353736373737383739374037413742374337443745374637473748374937503751375237533754375537563757375837593760376137623763376437653766376737683769377037713772377337743775377637773778377937803781 |
- module.exports = (function() {
- var __MODS__ = {};
- var __DEFINE__ = function(modId, func, req) { var m = { exports: {}, _tempexports: {} }; __MODS__[modId] = { status: 0, func: func, req: req, m: m }; };
- 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; };
- 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; } };
- var __REQUIRE_DEFAULT__ = function(obj) { return obj && obj.__esModule ? obj.default : obj; };
- __DEFINE__(1679043784148, function(require, module, exports) {
- var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
- var _typeof = require("@babel/runtime/helpers/typeof");
- Object.defineProperty(exports, "__esModule", {
- value: true
- });
- exports.BBox = void 0;
- Object.defineProperty(exports, "Canvas", {
- enumerable: true,
- get: function get() {
- return _engine.Canvas;
- }
- });
- Object.defineProperty(exports, "Group", {
- enumerable: true,
- get: function get() {
- return _engine.Group;
- }
- });
- Object.defineProperty(exports, "Matrix", {
- enumerable: true,
- get: function get() {
- return _matrix.default;
- }
- });
- Object.defineProperty(exports, "Shape", {
- enumerable: true,
- get: function get() {
- return _engine.Shape;
- }
- });
- exports.Types = exports.Smooth = void 0;
- Object.defineProperty(exports, "Vector2", {
- enumerable: true,
- get: function get() {
- return _vector.default;
- }
- });
- exports.createCanvas = createCanvas;
- exports.getEngine = getEngine;
- exports.registerEngine = registerEngine;
- var _matrix = _interopRequireDefault(require("./util/matrix"));
- var _vector = _interopRequireDefault(require("./util/vector2"));
- var Smooth = _interopRequireWildcard(require("./util/smooth"));
- exports.Smooth = Smooth;
- var BBox = _interopRequireWildcard(require("./util/bbox"));
- exports.BBox = BBox;
- var _engine = require("./engine");
- var Types = _interopRequireWildcard(require("./types"));
- exports.Types = Types;
- 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); }
- 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; }
- var engines = {};
- function registerEngine(name, engine) {
- engines[name] = engine;
- }
- function getEngine(name) {
- var G = engines[name];
- if (G) {
- return G;
- }
- return {
- Canvas: _engine.Canvas,
- Group: _engine.Group,
- Shape: _engine.Shape
- };
- }
- function createCanvas(cfg) {
- var renderer = cfg.renderer;
- var G = getEngine(renderer);
- return new G.Canvas(cfg);
- }
- }, 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); })
- __DEFINE__(1679043784149, function(require, module, exports) {
- Object.defineProperty(exports, "__esModule", {
- value: true
- });
- exports.default = void 0;
- var Matrix = {
- generateDefault: function generateDefault() {
- return [1, 0, 0, 1, 0, 0];
- },
- isChanged: function isChanged(m) {
- return m[0] !== 1 || m[1] !== 0 || m[2] !== 0 || m[3] !== 1 || m[4] !== 0 || m[5] !== 0;
- },
- multiply: function multiply(m1, m2) {
- var m11 = m1[0] * m2[0] + m1[2] * m2[1];
- var m12 = m1[1] * m2[0] + m1[3] * m2[1];
- var m21 = m1[0] * m2[2] + m1[2] * m2[3];
- var m22 = m1[1] * m2[2] + m1[3] * m2[3];
- var dx = m1[0] * m2[4] + m1[2] * m2[5] + m1[4];
- var dy = m1[1] * m2[4] + m1[3] * m2[5] + m1[5];
- return [m11, m12, m21, m22, dx, dy];
- },
- scale: function scale(out, m, v) {
- out[0] = m[0] * v[0];
- out[1] = m[1] * v[0];
- out[2] = m[2] * v[1];
- out[3] = m[3] * v[1];
- out[4] = m[4];
- out[5] = m[5];
- return out;
- },
- rotate: function rotate(out, m, radian) {
- var c = Math.cos(radian);
- var s = Math.sin(radian);
- var m11 = m[0] * c + m[2] * s;
- var m12 = m[1] * c + m[3] * s;
- var m21 = m[0] * -s + m[2] * c;
- var m22 = m[1] * -s + m[3] * c;
- out[0] = m11;
- out[1] = m12;
- out[2] = m21;
- out[3] = m22;
- out[4] = m[4];
- out[5] = m[5];
- return out;
- },
- translate: function translate(out, m, v) {
- out[0] = m[0];
- out[1] = m[1];
- out[2] = m[2];
- out[3] = m[3];
- out[4] = m[4] + m[0] * v[0] + m[2] * v[1];
- out[5] = m[5] + m[1] * v[0] + m[3] * v[1];
- return out;
- },
- transform: function transform(m, actions) {
- var out = [].concat(m);
- for (var i = 0, len = actions.length; i < len; i++) {
- var action = actions[i];
- switch (action[0]) {
- case 't':
- Matrix.translate(out, out, [action[1], action[2]]);
- break;
- case 's':
- Matrix.scale(out, out, [action[1], action[2]]);
- break;
- case 'r':
- Matrix.rotate(out, out, action[1]);
- break;
- default:
- break;
- }
- }
- return out;
- }
- };
- var _default = Matrix;
- exports.default = _default;
- }, function(modId) { var map = {}; return __REQUIRE__(map[modId], modId); })
- __DEFINE__(1679043784150, function(require, module, exports) {
- Object.defineProperty(exports, "__esModule", {
- value: true
- });
- exports.default = void 0;
- /**
- * 2 Dimensional Vector
- * @module vector2
- */
- var _default = {
- /**
- * Creates a new, empty vector2
- *
- * @return {vector2} a new 2D vector
- */
- create: function create() {
- return [0, 0];
- },
- /**
- * Calculates the length of a vector2
- *
- * @param {vector2} v vector to calculate length of
- * @return {Number} length of v
- */
- length: function length(v) {
- var x = v[0];
- var y = v[1];
- return Math.sqrt(x * x + y * y);
- },
- /**
- * Normalize a vector2
- *
- * @param {vector2} out the receiving vector
- * @param {vector2} v vector to normalize
- * @return {vector2} out
- */
- normalize: function normalize(out, v) {
- var len = this.length(v);
- if (len === 0) {
- out[0] = 0;
- out[1] = 0;
- } else {
- out[0] = v[0] / len;
- out[1] = v[1] / len;
- }
- return out;
- },
- /**
- * Adds two vector2's
- *
- * @param {vector2} out the receiving vector
- * @param {vector2} v1 the first operand
- * @param {vector2} v2 the second operand
- * @return {vector2} out
- */
- add: function add(out, v1, v2) {
- out[0] = v1[0] + v2[0];
- out[1] = v1[1] + v2[1];
- return out;
- },
- /**
- * Subtracts vector v2 from vector v1
- *
- * @param {vector2} out the receiving vector
- * @param {vector2} v1 the first operand
- * @param {vector2} v2 the second operand
- * @return {vector2} out
- */
- sub: function sub(out, v1, v2) {
- out[0] = v1[0] - v2[0];
- out[1] = v1[1] - v2[1];
- return out;
- },
- /**
- * Scales a vector2 by a scalar number
- *
- * @param {vector2} out the receiving vector
- * @param {vector2} v the vector to scale
- * @param {Number} s amount to scale the vector by
- * @return {vector2} out
- */
- scale: function scale(out, v, s) {
- out[0] = v[0] * s;
- out[1] = v[1] * s;
- return out;
- },
- /**
- * Calculates the dot product of two vector2's
- *
- * @param {vector2} v1 the first operand
- * @param {vector2} v2 the second operand
- * @return {Number} dot product of v1 and v2
- */
- dot: function dot(v1, v2) {
- return v1[0] * v2[0] + v1[1] * v2[1];
- },
- /**
- * Calculates the direction of two vector2's
- *
- * @param {vector2} v1 the first operand
- * @param {vector2} v2 the second operand
- * @return {Boolean} the direction of v1 and v2
- */
- direction: function direction(v1, v2) {
- return v1[0] * v2[1] - v2[0] * v1[1];
- },
- /**
- * Calculates the angle of two vector2's
- *
- * @param {vector2} v1 the first operand
- * @param {vector2} v2 the second operand
- * @return {Number} angle of v1 and v2
- */
- angle: function angle(v1, v2) {
- var theta = this.dot(v1, v2) / (this.length(v1) * this.length(v2));
- return Math.acos(theta);
- },
- /**
- * Calculates the angle of two vector2's with direction
- *
- * @param {vector2} v1 the first operand
- * @param {vector2} v2 the second operand
- * @param {Boolean} direction the direction of two vector2's
- * @return {Number} angle of v1 and v2
- */
- angleTo: function angleTo(v1, v2, direction) {
- var angle = this.angle(v1, v2);
- var angleLargeThanPI = this.direction(v1, v2) >= 0;
- if (direction) {
- if (angleLargeThanPI) {
- return Math.PI * 2 - angle;
- }
- return angle;
- }
- if (angleLargeThanPI) {
- return angle;
- }
- return Math.PI * 2 - angle;
- },
- /**
- * whether a vector2 is zero vector
- *
- * @param {vector2} v vector to calculate
- * @return {Boolean} is or not a zero vector
- */
- zero: function zero(v) {
- return v[0] === 0 && v[1] === 0;
- },
- /**
- * Calculates the euclidian distance between two vector2's
- *
- * @param {vector2} v1 the first operand
- * @param {vector2} v2 the second operand
- * @return {Number} distance between a and b
- */
- distance: function distance(v1, v2) {
- var x = v2[0] - v1[0];
- var y = v2[1] - v1[1];
- return Math.sqrt(x * x + y * y);
- },
- /**
- * Creates a new vector2 initialized with values from an existing vector
- *
- * @param {vector2} v vector to clone
- * @return {Array} a new 2D vector
- */
- clone: function clone(v) {
- return [v[0], v[1]];
- },
- /**
- * Return the minimum of two vector2's
- *
- * @param {vector2} out the receiving vector
- * @param {vector2} v1 the first operand
- * @param {vector2} v2 the second operand
- * @return {vector2} out
- */
- min: function min(out, v1, v2) {
- out[0] = Math.min(v1[0], v2[0]);
- out[1] = Math.min(v1[1], v2[1]);
- return out;
- },
- /**
- * Return the maximum of two vector2's
- *
- * @param {vector2} out the receiving vector
- * @param {vector2} v1 the first operand
- * @param {vector2} v2 the second operand
- * @return {vector2} out
- */
- max: function max(out, v1, v2) {
- out[0] = Math.max(v1[0], v2[0]);
- out[1] = Math.max(v1[1], v2[1]);
- return out;
- },
- /**
- * Transforms the vector2 with a mat2d
- *
- * @param {vector2} out the receiving vector
- * @param {vector2} v the vector to transform
- * @param {mat2d} m matrix to transform with
- * @return {vector2} out
- */
- transformMat2d: function transformMat2d(out, v, m) {
- var x = v[0];
- var y = v[1];
- out[0] = m[0] * x + m[2] * y + m[4];
- out[1] = m[1] * x + m[3] * y + m[5];
- return out;
- }
- };
- exports.default = _default;
- }, function(modId) { var map = {}; return __REQUIRE__(map[modId], modId); })
- __DEFINE__(1679043784151, function(require, module, exports) {
- var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
- Object.defineProperty(exports, "__esModule", {
- value: true
- });
- exports.smooth = catmullRom2bezier;
- var _vector = _interopRequireDefault(require("./vector2"));
- /**
- * @fileOverview convert the line to curve
- * @author dxq613@gmail.com
- */
- function getPoint(v) {
- return [v.x, v.y];
- }
- function smoothBezier(points, smooth, isLoop, constraint) {
- var cps = [];
- var prevPoint;
- var nextPoint;
- var hasConstraint = !!constraint;
- var min;
- var max;
- var point;
- var len;
- var l;
- var i;
- if (hasConstraint) {
- min = [Infinity, Infinity];
- max = [-Infinity, -Infinity];
- for (i = 0, l = points.length; i < l; i++) {
- point = getPoint(points[i]);
- _vector.default.min(min, min, point);
- _vector.default.max(max, max, point);
- }
- _vector.default.min(min, min, constraint[0]);
- _vector.default.max(max, max, constraint[1]);
- }
- for (i = 0, len = points.length; i < len; i++) {
- point = getPoint(points[i]);
- if (isLoop) {
- prevPoint = getPoint(points[i ? i - 1 : len - 1]);
- nextPoint = getPoint(points[(i + 1) % len]);
- } else {
- if (i === 0 || i === len - 1) {
- cps.push([point[0], point[1]]);
- continue;
- } else {
- prevPoint = getPoint(points[i - 1]);
- nextPoint = getPoint(points[i + 1]);
- }
- }
- var v = _vector.default.sub([], nextPoint, prevPoint);
- _vector.default.scale(v, v, smooth);
- var d0 = _vector.default.distance(point, prevPoint);
- var d1 = _vector.default.distance(point, nextPoint);
- var sum = d0 + d1;
- if (sum !== 0) {
- d0 /= sum;
- d1 /= sum;
- }
- var v1 = _vector.default.scale([], v, -d0);
- var v2 = _vector.default.scale([], v, d1);
- var cp0 = _vector.default.add([], point, v1);
- var cp1 = _vector.default.add([], point, v2);
- if (hasConstraint) {
- _vector.default.max(cp0, cp0, min);
- _vector.default.min(cp0, cp0, max);
- _vector.default.max(cp1, cp1, min);
- _vector.default.min(cp1, cp1, max);
- }
- cps.push([cp0[0], cp0[1]]);
- cps.push([cp1[0], cp1[1]]);
- }
- if (isLoop) {
- cps.push(cps.shift());
- }
- return cps;
- }
- function catmullRom2bezier(pointList, z, constraint) {
- var isLoop = !!z;
- var controlPointList = smoothBezier(pointList, 0.4, isLoop, constraint);
- var len = pointList.length;
- var d1 = [];
- var cp1;
- var cp2;
- var p;
- for (var i = 0; i < len - 1; i++) {
- cp1 = controlPointList[i * 2];
- cp2 = controlPointList[i * 2 + 1];
- p = pointList[i + 1];
- d1.push(['C', cp1[0], cp1[1], cp2[0], cp2[1], p.x, p.y]);
- }
- if (isLoop) {
- cp1 = controlPointList[len];
- cp2 = controlPointList[len + 1];
- p = pointList[0];
- d1.push(['C', cp1[0], cp1[1], cp2[0], cp2[1], p.x, p.y]);
- }
- return d1;
- }
- }, function(modId) { var map = {"./vector2":1679043784150}; return __REQUIRE__(map[modId], modId); })
- __DEFINE__(1679043784152, function(require, module, exports) {
- var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
- Object.defineProperty(exports, "__esModule", {
- value: true
- });
- exports.getBBoxFromArc = getBBoxFromArc;
- exports.getBBoxFromBezierGroup = getBBoxFromBezierGroup;
- exports.getBBoxFromLine = getBBoxFromLine;
- exports.getBBoxFromPoints = getBBoxFromPoints;
- var _vector = _interopRequireDefault(require("./vector2"));
- var start = _vector.default.create();
- var end = _vector.default.create();
- var extremity = _vector.default.create();
- function getCubicBezierXYatT(startPt, controlPt1, controlPt2, endPt, T) {
- var x = CubicN(T, startPt.x, controlPt1.x, controlPt2.x, endPt.x);
- var y = CubicN(T, startPt.y, controlPt1.y, controlPt2.y, endPt.y);
- return {
- x: x,
- y: y
- };
- }
- // cubic helper formula at T distance
- function CubicN(T, a, b, c, d) {
- var t2 = T * T;
- var t3 = t2 * T;
- 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;
- }
- function cubicBezierBounds(c) {
- var minX = Infinity;
- var maxX = -Infinity;
- var minY = Infinity;
- var maxY = -Infinity;
- var s = {
- x: c[0],
- y: c[1]
- };
- var c1 = {
- x: c[2],
- y: c[3]
- };
- var c2 = {
- x: c[4],
- y: c[5]
- };
- var e = {
- x: c[6],
- y: c[7]
- };
- for (var t = 0; t < 100; t++) {
- var pt = getCubicBezierXYatT(s, c1, c2, e, t / 100);
- if (pt.x < minX) {
- minX = pt.x;
- }
- if (pt.x > maxX) {
- maxX = pt.x;
- }
- if (pt.y < minY) {
- minY = pt.y;
- }
- if (pt.y > maxY) {
- maxY = pt.y;
- }
- }
- return {
- minX: minX,
- minY: minY,
- maxX: maxX,
- maxY: maxY
- };
- }
- function getBBoxFromPoints(points, lineWidth) {
- if (points.length === 0) {
- return;
- }
- var p = points[0];
- var left = p.x;
- var right = p.x;
- var top = p.y;
- var bottom = p.y;
- var len = points.length;
- for (var i = 1; i < len; i++) {
- p = points[i];
- left = Math.min(left, p.x);
- right = Math.max(right, p.x);
- top = Math.min(top, p.y);
- bottom = Math.max(bottom, p.y);
- }
- lineWidth = lineWidth / 2 || 0;
- return {
- minX: left - lineWidth,
- minY: top - lineWidth,
- maxX: right + lineWidth,
- maxY: bottom + lineWidth
- };
- }
- function getBBoxFromLine(x0, y0, x1, y1, lineWidth) {
- lineWidth = lineWidth / 2 || 0;
- return {
- minX: Math.min(x0, x1) - lineWidth,
- minY: Math.min(y0, y1) - lineWidth,
- maxX: Math.max(x0, x1) + lineWidth,
- maxY: Math.max(y0, y1) + lineWidth
- };
- }
- function getBBoxFromArc(x, y, r, startAngle, endAngle, anticlockwise) {
- var diff = Math.abs(startAngle - endAngle);
- if (diff % (Math.PI * 2) < 1e-4 && diff > 1e-4) {
- // Is a circle
- return {
- minX: x - r,
- minY: y - r,
- maxX: x + r,
- maxY: y + r
- };
- }
- start[0] = Math.cos(startAngle) * r + x;
- start[1] = Math.sin(startAngle) * r + y;
- end[0] = Math.cos(endAngle) * r + x;
- end[1] = Math.sin(endAngle) * r + y;
- var min = [0, 0];
- var max = [0, 0];
- _vector.default.min(min, start, end);
- _vector.default.max(max, start, end);
- // Thresh to [0, Math.PI * 2]
- startAngle = startAngle % (Math.PI * 2);
- if (startAngle < 0) {
- startAngle = startAngle + Math.PI * 2;
- }
- endAngle = endAngle % (Math.PI * 2);
- if (endAngle < 0) {
- endAngle = endAngle + Math.PI * 2;
- }
- if (startAngle > endAngle && !anticlockwise) {
- endAngle += Math.PI * 2;
- } else if (startAngle < endAngle && anticlockwise) {
- startAngle += Math.PI * 2;
- }
- if (anticlockwise) {
- var tmp = endAngle;
- endAngle = startAngle;
- startAngle = tmp;
- }
- for (var angle = 0; angle < endAngle; angle += Math.PI / 2) {
- if (angle > startAngle) {
- extremity[0] = Math.cos(angle) * r + x;
- extremity[1] = Math.sin(angle) * r + y;
- _vector.default.min(min, extremity, min);
- _vector.default.max(max, extremity, max);
- }
- }
- return {
- minX: min[0],
- minY: min[1],
- maxX: max[0],
- maxY: max[1]
- };
- }
- function getBBoxFromBezierGroup(points, lineWidth) {
- var minX = Infinity;
- var maxX = -Infinity;
- var minY = Infinity;
- var maxY = -Infinity;
- for (var i = 0, len = points.length; i < len; i++) {
- var bbox = cubicBezierBounds(points[i]);
- if (bbox.minX < minX) {
- minX = bbox.minX;
- }
- if (bbox.maxX > maxX) {
- maxX = bbox.maxX;
- }
- if (bbox.minY < minY) {
- minY = bbox.minY;
- }
- if (bbox.maxY > maxY) {
- maxY = bbox.maxY;
- }
- }
- lineWidth = lineWidth / 2 || 0;
- return {
- minX: minX - lineWidth,
- minY: minY - lineWidth,
- maxX: maxX + lineWidth,
- maxY: maxY + lineWidth
- };
- }
- }, function(modId) { var map = {"./vector2":1679043784150}; return __REQUIRE__(map[modId], modId); })
- __DEFINE__(1679043784153, function(require, module, exports) {
- var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
- Object.defineProperty(exports, "__esModule", {
- value: true
- });
- Object.defineProperty(exports, "Canvas", {
- enumerable: true,
- get: function get() {
- return _canvas.default;
- }
- });
- Object.defineProperty(exports, "Group", {
- enumerable: true,
- get: function get() {
- return _group.default;
- }
- });
- Object.defineProperty(exports, "Shape", {
- enumerable: true,
- get: function get() {
- return _shape.default;
- }
- });
- var _canvas = _interopRequireDefault(require("./canvas"));
- var _group = _interopRequireDefault(require("./group"));
- var _shape = _interopRequireDefault(require("./shape"));
- }, function(modId) { var map = {"./canvas":1679043784154,"./group":1679043784177,"./shape":1679043784161}; return __REQUIRE__(map[modId], modId); })
- __DEFINE__(1679043784154, function(require, module, exports) {
- var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
- var _typeof = require("@babel/runtime/helpers/typeof");
- Object.defineProperty(exports, "__esModule", {
- value: true
- });
- exports.default = void 0;
- var _classCallCheck2 = _interopRequireDefault(require("@babel/runtime/helpers/classCallCheck"));
- var _createClass2 = _interopRequireDefault(require("@babel/runtime/helpers/createClass"));
- var _inherits2 = _interopRequireDefault(require("@babel/runtime/helpers/inherits"));
- var _createSuper2 = _interopRequireDefault(require("@babel/runtime/helpers/createSuper"));
- var _emit = _interopRequireDefault(require("../event/emit"));
- var _controller = _interopRequireDefault(require("../event/controller"));
- var _canvasElement = _interopRequireDefault(require("./canvas-element"));
- var _util = require("@antv/util");
- var DOMUtil = _interopRequireWildcard(require("../util/dom"));
- var _container = _interopRequireDefault(require("./container"));
- var _group = _interopRequireDefault(require("./group"));
- var _requestAnimationFrame = require("../util/requestAnimationFrame");
- var _lang = _interopRequireDefault(require("./lang"));
- 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); }
- 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; }
- var getPixelRatio = DOMUtil.getPixelRatio,
- getDomById = DOMUtil.getDomById,
- getWidth = DOMUtil.getWidth,
- getHeight = DOMUtil.getHeight,
- isCanvasElement = DOMUtil.isCanvasElement;
- var Canvas = /*#__PURE__*/function (_EventEmit) {
- (0, _inherits2.default)(Canvas, _EventEmit);
- var _super = (0, _createSuper2.default)(Canvas);
- function Canvas(cfg) {
- var _this;
- (0, _classCallCheck2.default)(this, Canvas);
- _this = _super.call(this);
- var title = cfg.title;
- var ariaLabel = title ? (0, _util.substitute)(_lang.default.general.withTitle, {
- title: title
- }) : _lang.default.general.title;
- _this._attrs = (0, _util.mix)({
- type: 'canvas',
- children: [],
- ariaLabel: ariaLabel
- }, cfg);
- _this._initPixelRatio();
- _this._initCanvas();
- return _this;
- }
- (0, _createClass2.default)(Canvas, [{
- key: "get",
- value: /* eslint-enable */
- function get(name) {
- return this._attrs[name];
- }
- }, {
- key: "set",
- value: function set(name, value) {
- this._attrs[name] = value;
- }
- }, {
- key: "_initPixelRatio",
- value: function _initPixelRatio() {
- var pixelRatio = this.get('pixelRatio');
- if (!pixelRatio) {
- this.set('pixelRatio', getPixelRatio());
- }
- }
- }, {
- key: "beforeDraw",
- value: function beforeDraw() {
- var context = this._attrs.context;
- var el = this._attrs.el;
- context && context.clearRect && context.clearRect(0, 0, el.width, el.height);
- }
- }, {
- key: "_initCanvas",
- value: function _initCanvas() {
- var el = this.get('el');
- var context = this.get('context');
- if (!el && !context) {
- throw new Error('Please specify the id, el or context of the chart!');
- }
- var canvas;
- if (el) {
- // DOMElement or String
- canvas = (0, _util.isString)(el) ? getDomById(el) : el;
- } else {
- // 说明没有指定el
- canvas = _canvasElement.default.create(context);
- }
- if (context && canvas && !canvas.getContext) {
- canvas.getContext = function () {
- return context;
- };
- }
- var width = this.get('width') || getWidth(canvas) || canvas.width;
- var height = this.get('height') || getHeight(canvas) || canvas.height;
- this.set('canvas', this);
- this.set('el', canvas);
- this.set('context', context || canvas.getContext('2d'));
- this.changeSize(width, height);
- // 初始化事件控制器
- var eventController = new _controller.default({
- canvas: this,
- el: canvas
- });
- this.set('eventController', eventController);
- }
- }, {
- key: "changeSize",
- value: function changeSize(width, height) {
- var pixelRatio = this.get('pixelRatio');
- var canvasDOM = this.get('el'); // HTMLCanvasElement or canvasElement
- // 浏览器环境设置style样式
- if (canvasDOM.style) {
- canvasDOM.style.width = width + 'px';
- canvasDOM.style.height = height + 'px';
- }
- if (isCanvasElement(canvasDOM)) {
- canvasDOM.width = width * pixelRatio;
- canvasDOM.height = height * pixelRatio;
- if (pixelRatio !== 1) {
- var ctx = this.get('context');
- ctx.scale(pixelRatio, pixelRatio);
- }
- }
- this.set('width', width);
- this.set('height', height);
- }
- }, {
- key: "getWidth",
- value: function getWidth() {
- var pixelRatio = this.get('pixelRatio');
- var width = this.get('width');
- return width * pixelRatio;
- }
- }, {
- key: "getHeight",
- value: function getHeight() {
- var pixelRatio = this.get('pixelRatio');
- var height = this.get('height');
- return height * pixelRatio;
- }
- }, {
- key: "getPointByClient",
- value: function getPointByClient(clientX, clientY) {
- var el = this.get('el');
- var bbox = el.getBoundingClientRect();
- var width = bbox.right - bbox.left;
- var height = bbox.bottom - bbox.top;
- return {
- x: (clientX - bbox.left) * (el.width / width),
- y: (clientY - bbox.top) * (el.height / height)
- };
- }
- }, {
- key: "_beginDraw",
- value: function _beginDraw() {
- this._attrs.toDraw = true;
- }
- }, {
- key: "_endDraw",
- value: function _endDraw() {
- this._attrs.toDraw = false;
- }
- }, {
- key: "draw",
- value: function draw() {
- var _this2 = this;
- var drawInner = function drawInner() {
- _this2.set('animateHandler', (0, _requestAnimationFrame.requestAnimationFrame)(function () {
- _this2.set('animateHandler', undefined);
- if (_this2.get('toDraw')) {
- drawInner();
- }
- }));
- _this2.beforeDraw();
- try {
- var context = _this2._attrs.context;
- _this2.drawChildren(context);
- // 支付宝,微信小程序,需要调context.draw才能完成绘制, 所以这里直接判断是否有.draw方法
- if (context.draw) {
- context.draw();
- }
- // 设置无障碍文本
- _this2.setAriaLabel();
- } catch (ev) {
- console.warn('error in draw canvas, detail as:');
- console.warn(ev);
- _this2._endDraw();
- }
- _this2._endDraw();
- };
- if (this.get('destroyed')) {
- return;
- }
- if (this.get('animateHandler')) {
- this._beginDraw();
- } else {
- drawInner();
- }
- }
- // 设置无障碍文本
- }, {
- key: "setAriaLabel",
- value: function setAriaLabel() {
- var el = this._attrs.el;
- var ariaLabel = this._getAriaLabel();
- if (ariaLabel && el.setAttribute) {
- el.setAttribute('aria-label', ariaLabel);
- }
- }
- }, {
- key: "destroy",
- value: function destroy() {
- if (this.get('destroyed')) {
- return;
- }
- // 需要清理 canvas 画布内容,否则会导致 spa 应用 ios 下 canvas 白屏
- // https://stackoverflow.com/questions/52532614/total-canvas-memory-use-exceeds-the-maximum-limit-safari-12
- // https://github.com/antvis/F2/issues/630
- var el = this.get('el');
- el.width = 0;
- el.height = 0;
- this.clear();
- this._attrs = {};
- this.set('destroyed', true);
- }
- }, {
- key: "isDestroyed",
- value: function isDestroyed() {
- return this.get('destroyed');
- }
- }]);
- return Canvas;
- }(_emit.default); // @ts-ignore
- (0, _util.mix)(Canvas.prototype, _container.default, {
- getGroupClass: function getGroupClass() {
- return _group.default;
- }
- });
- var _default = Canvas;
- exports.default = _default;
- }, 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); })
- __DEFINE__(1679043784155, function(require, module, exports) {
- var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
- Object.defineProperty(exports, "__esModule", {
- value: true
- });
- exports.default = void 0;
- var _classCallCheck2 = _interopRequireDefault(require("@babel/runtime/helpers/classCallCheck"));
- var _createClass2 = _interopRequireDefault(require("@babel/runtime/helpers/createClass"));
- var _util = require("@antv/util");
- // 实现简单的事件机制
- // 多个事件分隔符
- var TYPE_SEP = ' ';
- var EventEmit = /*#__PURE__*/function () {
- function EventEmit() {
- (0, _classCallCheck2.default)(this, EventEmit);
- this.__events = {};
- }
- (0, _createClass2.default)(EventEmit, [{
- key: "on",
- value: function on(type, listener) {
- var _this = this;
- if (!type || !listener) {
- return;
- }
- type.split(TYPE_SEP).forEach(function (item) {
- var events = _this.__events[item] || [];
- events.push(listener);
- _this.__events[item] = events;
- });
- }
- }, {
- key: "emit",
- value: function emit(type, e) {
- var _this2 = this;
- if ((0, _util.isObject)(type)) {
- e = type;
- type = e && e.type;
- }
- if (!type) {
- return;
- }
- var events = this.__events[type];
- if (!events || !events.length) {
- return;
- }
- events.forEach(function (listener) {
- listener.call(_this2, e);
- });
- }
- }, {
- key: "off",
- value: function off(type, listener) {
- var __events = this.__events;
- type.split(TYPE_SEP).forEach(function (item) {
- var events = __events[item];
- if (!events || !events.length) {
- return;
- }
- // 如果没有指定方法,则删除所有项
- if (!listener) {
- delete __events[item];
- return;
- }
- // 删除指定的 listener
- for (var i = 0, len = events.length; i < len; i++) {
- if (events[i] === listener) {
- events.splice(i, 1);
- i--;
- }
- }
- });
- }
- }]);
- return EventEmit;
- }();
- var _default = EventEmit;
- exports.default = _default;
- }, function(modId) { var map = {}; return __REQUIRE__(map[modId], modId); })
- __DEFINE__(1679043784156, function(require, module, exports) {
- var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
- var _typeof = require("@babel/runtime/helpers/typeof");
- Object.defineProperty(exports, "__esModule", {
- value: true
- });
- exports.default = void 0;
- var _classCallCheck2 = _interopRequireDefault(require("@babel/runtime/helpers/classCallCheck"));
- var _createClass2 = _interopRequireDefault(require("@babel/runtime/helpers/createClass"));
- var DOMUtil = _interopRequireWildcard(require("../util/dom"));
- 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); }
- 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; }
- var convertPoints = DOMUtil.convertPoints;
- // 计算滑动的方向
- var calcDirection = function calcDirection(start, end) {
- var xDistance = end.x - start.x;
- var yDistance = end.y - start.y;
- // x 的距离大于y 说明是横向,否则就是纵向
- if (Math.abs(xDistance) > Math.abs(yDistance)) {
- return xDistance > 0 ? 'right' : 'left';
- }
- return yDistance > 0 ? 'down' : 'up';
- };
- // 计算2点之间的距离
- var calcDistance = function calcDistance(point1, point2) {
- var xDistance = Math.abs(point2.x - point1.x);
- var yDistance = Math.abs(point2.y - point1.y);
- return Math.sqrt(xDistance * xDistance + yDistance * yDistance);
- };
- var getCenter = function getCenter(point1, point2) {
- var x = point1.x + (point2.x - point1.x) / 2;
- var y = point1.y + (point2.y - point1.y) / 2;
- return {
- x: x,
- y: y
- };
- };
- var PRESS_DELAY = 250;
- var EventController = /*#__PURE__*/function () {
- function EventController(_ref) {
- var _this = this;
- var canvas = _ref.canvas,
- el = _ref.el;
- (0, _classCallCheck2.default)(this, EventController);
- this._click = function (ev) {
- var points = convertPoints(ev, _this.canvas);
- ev.points = points;
- _this.emitEvent('click', ev);
- };
- this._start = function (ev) {
- var points = convertPoints(ev, _this.canvas);
- if (!points) {
- return;
- }
- ev.points = points;
- _this.emitEvent('touchstart', ev);
- // 防止上次的内容没有清理掉,重新reset下
- _this.reset();
- // 记录touch start 的时间
- _this.startTime = Date.now();
- // 记录touch start 的点
- _this.startPoints = points;
- if (points.length > 1) {
- _this.startDistance = calcDistance(points[0], points[1]);
- _this.center = getCenter(points[0], points[1]);
- } else {
- // 如果touchstart后停顿250ms, 则也触发press事件
- _this.pressTimeout = setTimeout(function () {
- // 这里固定触发press事件
- var eventType = 'press';
- var direction = 'none';
- ev.direction = direction;
- _this.emitStart(eventType, ev);
- _this.emitEvent(eventType, ev);
- _this.eventType = eventType;
- _this.direction = direction;
- }, PRESS_DELAY);
- }
- };
- this._move = function (ev) {
- var points = convertPoints(ev, _this.canvas);
- if (!points) return;
- _this.clearPressTimeout();
- ev.points = points;
- _this.emitEvent('touchmove', ev);
- var startPoints = _this.startPoints;
- if (!startPoints) return;
- // 多指触控
- if (points.length > 1) {
- // touchstart的距离
- var startDistance = _this.startDistance;
- var currentDistance = calcDistance(points[0], points[1]);
- ev.zoom = currentDistance / startDistance;
- ev.center = _this.center;
- // 触发缩放事件
- _this.emitStart('pinch', ev);
- _this.emitEvent('pinch', ev);
- } else {
- var deltaX = points[0].x - startPoints[0].x;
- var deltaY = points[0].y - startPoints[0].y;
- var direction = _this.direction || calcDirection(startPoints[0], points[0]);
- _this.direction = direction;
- // 获取press或者pan的事件类型
- // press 按住滑动, pan表示平移
- // 如果start后立刻move,则触发pan, 如果有停顿,则触发press
- var eventType = _this.getEventType(points);
- ev.direction = direction;
- ev.deltaX = deltaX;
- ev.deltaY = deltaY;
- _this.emitStart(eventType, ev);
- _this.emitEvent(eventType, ev);
- // 记录最后2次move的时间和坐标,为了给swipe事件用
- var prevMoveTime = _this.lastMoveTime;
- var now = Date.now();
- // 最后2次的时间间隔一定要大于0,否则swipe没发计算
- if (now - prevMoveTime > 0) {
- _this.prevMoveTime = prevMoveTime;
- _this.prevMovePoints = _this.lastMovePoints;
- _this.lastMoveTime = now;
- _this.lastMovePoints = points;
- }
- }
- };
- this._end = function (ev) {
- var points = convertPoints(ev, _this.canvas);
- ev.points = points;
- _this.emitEnd(ev);
- _this.emitEvent('touchend', ev);
- // swipe事件处理, 在touchend之后触发
- var lastMoveTime = _this.lastMoveTime;
- var now = Date.now();
- // 做这个判断是为了最后一次touchmove后到end前,还有一个停顿的过程
- // 100 是拍的一个值,理论这个值会很短,一般不卡顿的话在10ms以内
- if (now - lastMoveTime < 100) {
- var prevMoveTime = _this.prevMoveTime || _this.startTime;
- var intervalTime = lastMoveTime - prevMoveTime;
- // 时间间隔一定要大于0, 否则计算没意义
- if (intervalTime > 0) {
- var prevMovePoints = _this.prevMovePoints || _this.startPoints;
- var lastMovePoints = _this.lastMovePoints;
- // move速率
- var velocity = calcDistance(prevMovePoints[0], lastMovePoints[0]) / intervalTime;
- // 0.3 是参考hammerjs的设置
- if (velocity > 0.3) {
- ev.velocity = velocity;
- ev.direction = calcDirection(prevMovePoints[0], lastMovePoints[0]);
- ev.velocityX = (lastMovePoints[0].x - prevMovePoints[0].x) / intervalTime;
- ev.velocityY = (lastMovePoints[0].y - prevMovePoints[0].y) / intervalTime;
- _this.emitEvent('swipe', ev);
- }
- }
- }
- _this.reset();
- var touches = ev.touches;
- // 当多指只释放了1指时也会触发end, 这时重新触发一次start
- if (touches && touches.length > 0) {
- _this._start(ev);
- }
- };
- this._cancel = function (ev) {
- _this.emitEvent('touchcancel', ev);
- _this.reset();
- };
- // canvasEl
- this.canvas = canvas;
- this.delegateEvent(el);
- // 用来记录当前触发的事件
- this.processEvent = {};
- }
- (0, _createClass2.default)(EventController, [{
- key: "delegateEvent",
- value: function delegateEvent(canvasEl) {
- // 代理这几个事件
- canvasEl.addEventListener('click', this._click);
- canvasEl.addEventListener('touchstart', this._start);
- canvasEl.addEventListener('touchmove', this._move);
- canvasEl.addEventListener('touchend', this._end);
- canvasEl.addEventListener('touchcancel', this._cancel);
- }
- }, {
- key: "emitEvent",
- value: function emitEvent(type, ev) {
- var canvas = this.canvas;
- canvas.emit(type, ev);
- }
- }, {
- key: "getEventType",
- value: function getEventType(points) {
- var eventType = this.eventType,
- canvas = this.canvas,
- startTime = this.startTime,
- startPoints = this.startPoints;
- if (eventType) {
- return eventType;
- }
- var type;
- var panEventListeners = canvas.__events.pan;
- // 如果没有pan事件的监听,默认都是press
- if (!panEventListeners || !panEventListeners.length) {
- type = 'press';
- } else {
- // 如果有pan事件的处理,press则需要停顿250ms, 且移动距离小于10
- var now = Date.now();
- if (now - startTime > PRESS_DELAY && calcDistance(startPoints[0], points[0]) < 10) {
- type = 'press';
- } else {
- type = 'pan';
- }
- }
- this.eventType = type;
- return type;
- }
- }, {
- key: "enable",
- value: function enable(eventType) {
- this.processEvent[eventType] = true;
- }
- // 是否进行中的事件
- }, {
- key: "isProcess",
- value: function isProcess(eventType) {
- return this.processEvent[eventType];
- }
- // 触发start事件
- }, {
- key: "emitStart",
- value: function emitStart(type, ev) {
- if (this.isProcess(type)) {
- return;
- }
- this.enable(type);
- this.emitEvent("".concat(type, "start"), ev);
- }
- // 触发end事件
- }, {
- key: "emitEnd",
- value: function emitEnd(ev) {
- var _this2 = this;
- var processEvent = this.processEvent;
- Object.keys(processEvent).forEach(function (type) {
- _this2.emitEvent("".concat(type, "end"), ev);
- delete processEvent[type];
- });
- }
- }, {
- key: "clearPressTimeout",
- value: function clearPressTimeout() {
- if (this.pressTimeout) {
- clearTimeout(this.pressTimeout);
- this.pressTimeout = null;
- }
- }
- }, {
- key: "reset",
- value: function reset() {
- this.clearPressTimeout();
- this.startTime = 0;
- this.startPoints = null;
- this.startDistance = 0;
- this.direction = null;
- this.eventType = null;
- this.pinch = false;
- this.prevMoveTime = 0;
- this.prevMovePoints = null;
- this.lastMoveTime = 0;
- this.lastMovePoints = null;
- }
- }]);
- return EventController;
- }();
- var _default = EventController;
- exports.default = _default;
- }, function(modId) { var map = {"../util/dom":1679043784157}; return __REQUIRE__(map[modId], modId); })
- __DEFINE__(1679043784157, function(require, module, exports) {
- var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
- Object.defineProperty(exports, "__esModule", {
- value: true
- });
- exports.addEventListener = addEventListener;
- exports.convertPoints = convertPoints;
- exports.createEvent = createEvent;
- exports.getDomById = getDomById;
- exports.getHeight = getHeight;
- exports.getPixelRatio = getPixelRatio;
- exports.getRelativePosition = getRelativePosition;
- exports.getStyle = getStyle;
- exports.getWidth = getWidth;
- exports.isBrowser = void 0;
- exports.isCanvasElement = isCanvasElement;
- exports.isWx = exports.isNode = exports.isMy = void 0;
- exports.measureText = measureText;
- exports.removeEventListener = removeEventListener;
- var _typeof2 = _interopRequireDefault(require("@babel/runtime/helpers/typeof"));
- var _util = require("@antv/util");
- /**
- * Detects support for options object argument in addEventListener.
- * https://developer.mozilla.org/en-US/docs/Web/API/EventTarget/addEventListener#Safely_detecting_option_support
- * @private
- */
- var supportsEventListenerOptions = function () {
- var supports = false;
- try {
- var options = Object.defineProperty({}, 'passive', {
- get: function get() {
- supports = true;
- }
- });
- window.addEventListener('e', null, options);
- } catch (e) {
- // continue regardless of error
- }
- return supports;
- }();
- // Default passive to true as expected by Chrome for 'touchstart' and 'touchend' events.
- // https://github.com/chartjs/Chart.js/issues/4287
- var eventListenerOptions = supportsEventListenerOptions ? {
- passive: true
- } : false;
- /* global wx, my */
- // weixin miniprogram
- // @ts-ignore
- var isWx = (typeof wx === "undefined" ? "undefined" : (0, _typeof2.default)(wx)) === 'object' && typeof wx.getSystemInfoSync === 'function';
- // ant miniprogram
- // @ts-ignore
- exports.isWx = isWx;
- var isMy = (typeof my === "undefined" ? "undefined" : (0, _typeof2.default)(my)) === 'object' && typeof my.getSystemInfoSync === 'function';
- // in node
- // @ts-ignore
- exports.isMy = isMy;
- var isNode = (typeof global === "undefined" ? "undefined" : (0, _typeof2.default)(global)) && !(typeof window === "undefined" ? "undefined" : (0, _typeof2.default)(window));
- // in browser
- exports.isNode = isNode;
- var isBrowser = typeof window !== 'undefined' && typeof window.document !== 'undefined' && typeof window.sessionStorage !== 'undefined';
- exports.isBrowser = isBrowser;
- function isCanvasElement(el) {
- if (!el || (0, _typeof2.default)(el) !== 'object') return false;
- if (el.nodeType === 1 && el.nodeName) {
- // HTMLCanvasElement
- return true;
- }
- // CanvasElement
- return !!el.isCanvasElement;
- }
- function getPixelRatio() {
- return window && window.devicePixelRatio || 1;
- }
- function getStyle(el, property) {
- return el.currentStyle ? el.currentStyle[property] : document.defaultView.getComputedStyle(el, null).getPropertyValue(property);
- }
- function getWidth(el) {
- var width = getStyle(el, 'width');
- if (width === 'auto') {
- width = el.offsetWidth;
- }
- return parseFloat(width);
- }
- function getHeight(el) {
- var height = getStyle(el, 'height');
- if (height === 'auto') {
- height = el.offsetHeight;
- }
- return parseFloat(height);
- }
- function getDomById(id) {
- if (!id) {
- return null;
- }
- return document.getElementById(id);
- }
- function getRelativePosition(point, canvas) {
- var canvasDom = canvas.get('el');
- if (!canvasDom) return point;
- var _canvasDom$getBoundin = canvasDom.getBoundingClientRect(),
- top = _canvasDom$getBoundin.top,
- left = _canvasDom$getBoundin.left;
- var paddingLeft = parseFloat(getStyle(canvasDom, 'padding-left'));
- var paddingTop = parseFloat(getStyle(canvasDom, 'padding-top'));
- var mouseX = point.x - left - paddingLeft;
- var mouseY = point.y - top - paddingTop;
- return {
- x: mouseX,
- y: mouseY
- };
- }
- function addEventListener(source, type, listener) {
- source.addEventListener(type, listener, eventListenerOptions);
- }
- function removeEventListener(source, type, listener) {
- source.removeEventListener(type, listener, eventListenerOptions);
- }
- function landscapePoint(point, canvas) {
- var landscape = canvas.get('landscape');
- if (!landscape) {
- return point;
- }
- if ((0, _util.isFunction)(landscape)) {
- return landscape(point, canvas);
- }
- // 默认顺时针旋转90度
- var height = canvas.get('height');
- var x = point.y;
- var y = height - point.x;
- return {
- x: x,
- y: y
- };
- }
- function convertPoints(ev, canvas) {
- var touches = ev.touches;
- // 认为是mouse事件
- if (!touches) {
- var point = getRelativePosition({
- x: ev.clientX,
- y: ev.clientY
- }, canvas);
- return [landscapePoint(point, canvas)];
- }
- // 单指 touchend 后,touchs 会变空,最后的触点要从changedTouches里拿
- if (!touches.length) {
- // 为了防止万一,加个空逻辑
- touches = ev.changedTouches || [];
- }
- var points = [];
- for (var i = 0, len = touches.length; i < len; i++) {
- var touch = touches[i];
- // x, y: 相对canvas原点的位置,clientX, clientY 相对于可视窗口的位置
- var x = touch.x,
- y = touch.y,
- clientX = touch.clientX,
- clientY = touch.clientY;
- var _point = void 0;
- // 小程序环境会有x,y
- if ((0, _util.isNumber)(x) || (0, _util.isNumber)(y)) {
- _point = {
- x: x,
- y: y
- };
- } else {
- // 浏览器环境再计算下canvas的相对位置
- _point = getRelativePosition({
- x: clientX,
- y: clientY
- }, canvas);
- }
- points.push(landscapePoint(_point, canvas));
- }
- return points;
- }
- function createEvent(event, chart) {
- var canvas = chart.get('canvas');
- var points = convertPoints(event, canvas);
- // touchend会没有points
- var point = points[0] || {};
- return {
- type: event.type,
- chart: chart,
- native: event,
- x: point.x,
- y: point.y
- };
- }
- function measureText(text, font, ctx) {
- if (!ctx) {
- ctx = document.createElement('canvas').getContext('2d');
- }
- ctx.font = font || '12px sans-serif';
- return ctx.measureText(text);
- }
- }, function(modId) { var map = {}; return __REQUIRE__(map[modId], modId); })
- __DEFINE__(1679043784158, function(require, module, exports) {
- var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
- Object.defineProperty(exports, "__esModule", {
- value: true
- });
- exports.default = void 0;
- var _classCallCheck2 = _interopRequireDefault(require("@babel/runtime/helpers/classCallCheck"));
- var _createClass2 = _interopRequireDefault(require("@babel/runtime/helpers/createClass"));
- var _inherits2 = _interopRequireDefault(require("@babel/runtime/helpers/inherits"));
- var _createSuper2 = _interopRequireDefault(require("@babel/runtime/helpers/createSuper"));
- var _emit = _interopRequireDefault(require("../event/emit"));
- var CanvasElement = /*#__PURE__*/function (_EventEmit) {
- (0, _inherits2.default)(CanvasElement, _EventEmit);
- var _super = (0, _createSuper2.default)(CanvasElement);
- /* eslint-enable */
- function CanvasElement(ctx) {
- var _this;
- (0, _classCallCheck2.default)(this, CanvasElement);
- _this = _super.call(this);
- _this.context = ctx;
- // canvas实际的宽高 (width/height) * pixelRatio
- // 有可能是 node canvas 创建的 context 对象
- var canvas = ctx.canvas || {};
- _this.width = canvas.width || 0;
- _this.height = canvas.height || 0;
- _this.style = {};
- _this.currentStyle = {};
- _this.attrs = {};
- // 用来标识是CanvasElement实例
- _this.isCanvasElement = true;
- return _this;
- }
- (0, _createClass2.default)(CanvasElement, [{
- key: "getContext",
- value: function getContext( /* type */
- ) {
- return this.context;
- }
- }, {
- key: "getBoundingClientRect",
- value: function getBoundingClientRect() {
- var width = this.width;
- var height = this.height;
- // 默认都处理成可视窗口的顶部位置
- return {
- top: 0,
- right: width,
- bottom: height,
- left: 0
- };
- }
- }, {
- key: "setAttribute",
- value: function setAttribute(key, value) {
- this.attrs[key] = value;
- }
- }, {
- key: "addEventListener",
- value: function addEventListener(type, listener) {
- this.on(type, listener);
- }
- }, {
- key: "removeEventListener",
- value: function removeEventListener(type, listener) {
- this.off(type, listener);
- }
- }, {
- key: "dispatchEvent",
- value: function dispatchEvent(type, e) {
- this.emit(type, e);
- }
- }]);
- return CanvasElement;
- }(_emit.default);
- function supportEventListener(canvas) {
- if (!canvas) {
- return false;
- }
- // 非 HTMLCanvasElement
- if (canvas.nodeType !== 1 || !canvas.nodeName || canvas.nodeName.toLowerCase() !== 'canvas') {
- return false;
- }
- // 微信小程序canvas.getContext('2d')时也是CanvasRenderingContext2D
- // 也会有ctx.canvas, 而且nodeType也是1,所以还要在看下是否支持addEventListener
- var support = false;
- try {
- canvas.addEventListener('eventTest', function () {
- support = true;
- });
- canvas.dispatchEvent(new Event('eventTest'));
- } catch (error) {
- support = false;
- }
- return support;
- }
- var _default = {
- create: function create(ctx) {
- if (!ctx) {
- return null;
- }
- if (supportEventListener(ctx.canvas)) {
- return ctx.canvas;
- }
- return new CanvasElement(ctx);
- }
- };
- exports.default = _default;
- }, function(modId) { var map = {"../event/emit":1679043784155}; return __REQUIRE__(map[modId], modId); })
- __DEFINE__(1679043784159, function(require, module, exports) {
- var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
- Object.defineProperty(exports, "__esModule", {
- value: true
- });
- exports.default = void 0;
- var _util = require("@antv/util");
- var _array = require("../util/array");
- var _shape = _interopRequireDefault(require("./shape"));
- var SHAPE_MAP = {};
- var INDEX = '_INDEX';
- function getComparer(compare) {
- return function (left, right) {
- var result = compare(left, right);
- return result === 0 ? left[INDEX] - right[INDEX] : result;
- };
- }
- var _default = {
- getGroupClass: function getGroupClass() {},
- getChildren: function getChildren() {
- return this.get('children');
- },
- addShape: function addShape(type) {
- var cfg = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {};
- var shapeType = SHAPE_MAP[type];
- if (!shapeType) {
- shapeType = (0, _util.upperFirst)(type);
- SHAPE_MAP[type] = shapeType;
- }
- var shape = new _shape.default[shapeType](cfg);
- this.add(shape);
- return shape;
- },
- addGroup: function addGroup(cfg) {
- var groupClass = this.getGroupClass();
- var rst = new groupClass(cfg);
- this.add(rst);
- return rst;
- },
- contain: function contain(item) {
- var children = this.get('children');
- return children.indexOf(item) > -1;
- },
- sort: function sort() {
- var children = this.get('children');
- for (var i = 0, len = children.length; i < len; i++) {
- var child = children[i];
- child[INDEX] = i;
- }
- children.sort(getComparer(function (obj1, obj2) {
- return obj1.get('zIndex') - obj2.get('zIndex');
- }));
- return this;
- },
- drawChildren: function drawChildren(context) {
- this.sort();
- var children = this.get('children');
- for (var i = 0, len = children.length; i < len; i++) {
- var child = children[i];
- child.draw(context);
- }
- return this;
- },
- clear: function clear() {
- var children = this.get('children') || [];
- while (children.length !== 0) {
- children[children.length - 1].remove(true);
- }
- return this;
- },
- add: function add(items) {
- var children = this.get('children');
- if (!children) {
- children = [];
- this.set('children', children);
- }
- if (!(0, _util.isArray)(items)) {
- items = [items];
- }
- for (var i = 0, len = items.length; i < len; i++) {
- var item = items[i];
- var parent = item.get('parent');
- if (parent) {
- var descendants = parent.get('children');
- (0, _array.remove)(descendants, item);
- }
- this._setEvn(item);
- children.push(item);
- }
- return this;
- },
- _setEvn: function _setEvn(item) {
- var _item$_attrs$attrs, _item$_attrs$attrs2;
- var _this$_attrs = this._attrs,
- context = _this$_attrs.context,
- canvas = _this$_attrs.canvas,
- aria = _this$_attrs.aria;
- var _item$_attrs = item._attrs,
- isGroup = _item$_attrs.isGroup,
- type = _item$_attrs.type;
- item._attrs.parent = this;
- item._attrs.context = context;
- item._attrs.canvas = canvas;
- // 是否需要无障碍处理
- if (aria && item._attrs.aria !== false) {
- item._attrs.aria = aria;
- }
- 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)) {
- item.attr('fontFamily', canvas.get('fontFamily'));
- }
- var clip = (_item$_attrs$attrs2 = item._attrs.attrs) === null || _item$_attrs$attrs2 === void 0 ? void 0 : _item$_attrs$attrs2.clip;
- if (clip) {
- clip._attrs.parent = this;
- clip._attrs.context = context;
- clip._attrs.canvas = canvas;
- }
- if (isGroup) {
- var children = item._attrs.children;
- for (var i = 0, len = children.length; i < len; i++) {
- item._setEvn(children[i]);
- }
- }
- },
- _getAriaLabel: function _getAriaLabel() {
- var _this$_attrs2 = this._attrs,
- aria = _this$_attrs2.aria,
- ariaLabel = _this$_attrs2.ariaLabel,
- children = _this$_attrs2.children;
- // 主动关闭
- if (!aria) return;
- var childAriaLabels = [];
- if (children && children.length) {
- for (var i = 0, len = children.length; i < len; i++) {
- var _childAriaLabel = children[i].getAriaLabel();
- if (_childAriaLabel) {
- childAriaLabels.push(_childAriaLabel);
- }
- }
- }
- var childAriaLabel = childAriaLabels.join(' ');
- // 2个都有时拼接成完整句子
- if (ariaLabel && childAriaLabel) {
- return "".concat(ariaLabel, " ").concat(childAriaLabel, " ");
- }
- // 只有1个,或者都没有
- return ariaLabel || childAriaLabel;
- }
- };
- exports.default = _default;
- }, function(modId) { var map = {"../util/array":1679043784160,"./shape":1679043784161}; return __REQUIRE__(map[modId], modId); })
- __DEFINE__(1679043784160, function(require, module, exports) {
- Object.defineProperty(exports, "__esModule", {
- value: true
- });
- exports.remove = remove;
- function remove(arr, obj) {
- if (!arr) {
- return;
- }
- var index = arr.indexOf(obj);
- if (index !== -1) {
- arr.splice(index, 1);
- }
- }
- }, function(modId) { var map = {}; return __REQUIRE__(map[modId], modId); })
- __DEFINE__(1679043784161, function(require, module, exports) {
- var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
- Object.defineProperty(exports, "__esModule", {
- value: true
- });
- exports.default = void 0;
- var _shape = _interopRequireDefault(require("./shape"));
- var _rect = _interopRequireDefault(require("./rect"));
- var _image = _interopRequireDefault(require("./image"));
- var _circle = _interopRequireDefault(require("./circle"));
- var _line = _interopRequireDefault(require("./line"));
- var _polygon = _interopRequireDefault(require("./polygon"));
- var _polyline = _interopRequireDefault(require("./polyline"));
- var _arc = _interopRequireDefault(require("./arc"));
- var _sector = _interopRequireDefault(require("./sector"));
- var _text = _interopRequireDefault(require("./text"));
- var _custom = _interopRequireDefault(require("./custom"));
- var _marker = _interopRequireDefault(require("./marker"));
- _shape.default.Rect = _rect.default;
- _shape.default.Image = _image.default;
- _shape.default.Circle = _circle.default;
- _shape.default.Line = _line.default;
- _shape.default.Polygon = _polygon.default;
- _shape.default.Polyline = _polyline.default;
- _shape.default.Arc = _arc.default;
- _shape.default.Sector = _sector.default;
- _shape.default.Text = _text.default;
- _shape.default.Custom = _custom.default;
- _shape.default.Marker = _marker.default;
- var _default = _shape.default;
- exports.default = _default;
- }, 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); })
- __DEFINE__(1679043784162, function(require, module, exports) {
- var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
- Object.defineProperty(exports, "__esModule", {
- value: true
- });
- exports.default = void 0;
- var _objectSpread2 = _interopRequireDefault(require("@babel/runtime/helpers/objectSpread2"));
- var _classCallCheck2 = _interopRequireDefault(require("@babel/runtime/helpers/classCallCheck"));
- var _createClass2 = _interopRequireDefault(require("@babel/runtime/helpers/createClass"));
- var _inherits2 = _interopRequireDefault(require("@babel/runtime/helpers/inherits"));
- var _createSuper2 = _interopRequireDefault(require("@babel/runtime/helpers/createSuper"));
- var _util = require("@antv/util");
- var _element = _interopRequireDefault(require("../element"));
- var Shape = /*#__PURE__*/function (_Element) {
- (0, _inherits2.default)(Shape, _Element);
- var _super = (0, _createSuper2.default)(Shape);
- function Shape() {
- (0, _classCallCheck2.default)(this, Shape);
- return _super.apply(this, arguments);
- }
- (0, _createClass2.default)(Shape, [{
- key: "_initProperties",
- value: /* eslint-enable */
- function _initProperties() {
- this._attrs = (0, _objectSpread2.default)((0, _objectSpread2.default)({}, this._attrs), {}, {
- zIndex: 0,
- visible: true,
- destroyed: false,
- isShape: true,
- attrs: {}
- });
- }
- }, {
- key: "getType",
- value: function getType() {
- return this._attrs.type;
- }
- }, {
- key: "drawInner",
- value: function drawInner(context) {
- var attrs = this.get('attrs');
- this.createPath(context);
- var originOpacity = context.globalAlpha;
- if (this.hasFill()) {
- var fillOpacity = attrs.fillOpacity;
- if (!(0, _util.isNil)(fillOpacity) && fillOpacity !== 1) {
- context.globalAlpha = fillOpacity;
- context.fill();
- context.globalAlpha = originOpacity;
- } else {
- context.fill();
- }
- }
- if (this.hasStroke()) {
- var lineWidth = attrs.lineWidth;
- if (lineWidth > 0) {
- var strokeOpacity = attrs.strokeOpacity;
- if (!(0, _util.isNil)(strokeOpacity) && strokeOpacity !== 1) {
- context.globalAlpha = strokeOpacity;
- }
- context.stroke();
- }
- }
- }
- }, {
- key: "getBBox",
- value: function getBBox() {
- var bbox = this._attrs.bbox;
- if (!bbox) {
- bbox = this.calculateBox();
- if (bbox) {
- bbox.x = bbox.minX;
- bbox.y = bbox.minY;
- bbox.width = bbox.maxX - bbox.minX;
- bbox.height = bbox.maxY - bbox.minY;
- }
- this._attrs.bbox = bbox;
- }
- return bbox;
- }
- }, {
- key: "calculateBox",
- value: function calculateBox() {
- return null;
- }
- }, {
- key: "createPath",
- value: function createPath(_context) {}
- }]);
- return Shape;
- }(_element.default);
- var _default = Shape;
- exports.default = _default;
- }, function(modId) { var map = {"../element":1679043784163}; return __REQUIRE__(map[modId], modId); })
- __DEFINE__(1679043784163, function(require, module, exports) {
- var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
- Object.defineProperty(exports, "__esModule", {
- value: true
- });
- exports.default = void 0;
- var _objectSpread2 = _interopRequireDefault(require("@babel/runtime/helpers/objectSpread2"));
- var _classCallCheck2 = _interopRequireDefault(require("@babel/runtime/helpers/classCallCheck"));
- var _createClass2 = _interopRequireDefault(require("@babel/runtime/helpers/createClass"));
- var _util = require("@antv/util");
- var _array = require("../util/array");
- var _matrix = _interopRequireDefault(require("../util/matrix"));
- var _styleParse = require("../util/style-parse");
- var _vector = _interopRequireDefault(require("../util/vector2"));
- var ALIAS_ATTRS_MAP = {
- stroke: 'strokeStyle',
- fill: 'fillStyle',
- opacity: 'globalAlpha'
- };
- var SHAPE_ATTRS = ['fillStyle', 'font', 'globalAlpha', 'lineCap', 'lineWidth', 'lineJoin', 'miterLimit', 'shadowBlur', 'shadowColor', 'shadowOffsetX', 'shadowOffsetY', 'strokeStyle', 'textAlign', 'textBaseline', 'lineDash', 'shadow' // 兼容支付宝小程序
- ];
- var CLIP_SHAPES = ['circle', 'sector', 'polygon', 'rect', 'polyline', 'custom'];
- var Element = /*#__PURE__*/function () {
- function Element(cfg) {
- (0, _classCallCheck2.default)(this, Element);
- this._initProperties();
- (0, _util.mix)(this._attrs, cfg);
- var attrs = this._attrs.attrs;
- if (attrs) {
- this.initAttrs(attrs);
- }
- this.initTransform();
- }
- (0, _createClass2.default)(Element, [{
- key: "_initProperties",
- value: function _initProperties() {
- this._attrs = (0, _objectSpread2.default)((0, _objectSpread2.default)({}, this._attrs), {}, {
- zIndex: 0,
- visible: true,
- destroyed: false
- });
- }
- }, {
- key: "get",
- value: function get(name) {
- return this._attrs[name];
- }
- }, {
- key: "set",
- value: function set(name, value) {
- this._attrs[name] = value;
- }
- }, {
- key: "isGroup",
- value: function isGroup() {
- return this.get('isGroup');
- }
- }, {
- key: "isShape",
- value: function isShape() {
- return this.get('isShape');
- }
- }, {
- key: "initAttrs",
- value: function initAttrs(attrs) {
- this.attr((0, _util.mix)(this.getDefaultAttrs(), attrs));
- }
- }, {
- key: "getDefaultAttrs",
- value: function getDefaultAttrs() {
- return {};
- }
- }, {
- key: "_setAttr",
- value: function _setAttr(name, value) {
- var attrs = this._attrs.attrs;
- if (name === 'clip') {
- value = this._setAttrClip(value);
- } else {
- var alias = ALIAS_ATTRS_MAP[name];
- if (alias) {
- attrs[alias] = value;
- }
- }
- attrs[name] = value;
- }
- }, {
- key: "_getAttr",
- value: function _getAttr(name) {
- var _this$_attrs, _this$_attrs$attrs;
- 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];
- }
- }, {
- key: "_afterAttrsSet",
- value: function _afterAttrsSet() {}
- }, {
- key: "_setAttrClip",
- value: function _setAttrClip(clip) {
- if (clip && CLIP_SHAPES.indexOf(clip._attrs.type) > -1) {
- if (clip.get('canvas') === null) {
- clip = (0, _objectSpread2.default)({}, clip);
- }
- clip.set('parent', this.get('parent'));
- clip.set('context', this.get('context'));
- return clip;
- }
- return null;
- }
- }, {
- key: "attr",
- value: function attr(name, value) {
- if (this.get('destroyed')) return null;
- var argumentsLen = arguments.length;
- if (argumentsLen === 0) {
- return this._attrs.attrs;
- }
- if ((0, _util.isObject)(name)) {
- this._attrs.bbox = null;
- for (var k in name) {
- this._setAttr(k, name[k]);
- }
- if (this._afterAttrsSet) {
- this._afterAttrsSet();
- }
- return this;
- }
- if (argumentsLen === 2) {
- this._attrs.bbox = null;
- this._setAttr(name, value);
- if (this._afterAttrsSet) {
- this._afterAttrsSet();
- }
- return this;
- }
- return this._getAttr(name);
- }
- }, {
- key: "getParent",
- value: function getParent() {
- return this.get('parent');
- }
- }, {
- key: "draw",
- value: function draw(context) {
- if (this.get('destroyed')) {
- return;
- }
- if (this.get('visible')) {
- this.setContext(context);
- this.drawInner(context);
- this.restoreContext(context);
- }
- }
- }, {
- key: "setContext",
- value: function setContext(context) {
- var clip = this._attrs.attrs.clip;
- context.save();
- if (clip && !clip._attrs.destroyed) {
- clip.resetTransform(context);
- clip.createPath(context);
- context.clip();
- }
- this.resetContext(context);
- this.resetTransform(context);
- }
- }, {
- key: "restoreContext",
- value: function restoreContext(context) {
- context.restore();
- }
- }, {
- key: "resetContext",
- value: function resetContext(context) {
- var elAttrs = this._attrs.attrs;
- for (var k in elAttrs) {
- if (SHAPE_ATTRS.indexOf(k) > -1) {
- var v = elAttrs[k];
- if ((k === 'fillStyle' || k === 'strokeStyle') && v) {
- v = (0, _styleParse.parseStyle)(v, this, context);
- }
- if (k === 'lineDash' && context.setLineDash && (0, _util.isArray)(v)) {
- context.setLineDash(v);
- } else {
- context[k] = v;
- }
- }
- }
- }
- }, {
- key: "hasFill",
- value: function hasFill() {
- return this.get('canFill') && this._attrs.attrs.fillStyle;
- }
- }, {
- key: "hasStroke",
- value: function hasStroke() {
- return this.get('canStroke') && this._attrs.attrs.strokeStyle;
- }
- }, {
- key: "drawInner",
- value: function drawInner(_context) {}
- }, {
- key: "show",
- value: function show() {
- this.set('visible', true);
- return this;
- }
- }, {
- key: "hide",
- value: function hide() {
- this.set('visible', false);
- return this;
- }
- }, {
- key: "isVisible",
- value: function isVisible() {
- return this.get('visible');
- }
- }, {
- key: "getAriaLabel",
- value: function getAriaLabel() {
- var _this$_attrs2 = this._attrs,
- destroyed = _this$_attrs2.destroyed,
- visible = _this$_attrs2.visible,
- isShape = _this$_attrs2.isShape,
- aria = _this$_attrs2.aria;
- if (destroyed || !visible || isShape && !aria) {
- return;
- }
- return this._getAriaLabel();
- }
- }, {
- key: "_getAriaLabel",
- value: function _getAriaLabel() {
- return this._attrs.ariaLabel;
- }
- }, {
- key: "_removeFromParent",
- value: function _removeFromParent() {
- var parent = this.get('parent');
- if (parent) {
- var children = parent.get('children');
- (0, _array.remove)(children, this);
- }
- return this;
- }
- }, {
- key: "remove",
- value: function remove(destroy) {
- if (destroy) {
- this.destroy();
- } else {
- this._removeFromParent();
- }
- }
- }, {
- key: "destroy",
- value: function destroy() {
- var destroyed = this.get('destroyed');
- if (destroyed) {
- return null;
- }
- this._removeFromParent();
- // 保留 attrs
- var attrs = this._attrs.attrs;
- this._attrs = {
- attrs: attrs
- };
- this.set('destroyed', true);
- }
- }, {
- key: "getBBox",
- value: function getBBox() {
- return {
- minX: 0,
- maxX: 0,
- minY: 0,
- maxY: 0,
- width: 0,
- height: 0
- };
- }
- }, {
- key: "initTransform",
- value: function initTransform() {
- var attrs = this._attrs.attrs;
- if (!attrs) {
- attrs = {};
- }
- if (!attrs.matrix) {
- attrs.matrix = [1, 0, 0, 1, 0, 0];
- }
- this._attrs.attrs = attrs;
- }
- }, {
- key: "getMatrix",
- value: function getMatrix() {
- return this._attrs.attrs.matrix;
- }
- }, {
- key: "setMatrix",
- value: function setMatrix(m) {
- this._attrs.attrs.matrix = [m[0], m[1], m[2], m[3], m[4], m[5]];
- }
- }, {
- key: "transform",
- value: function transform(actions) {
- var matrix = this._attrs.attrs.matrix;
- this._attrs.attrs.matrix = _matrix.default.transform(matrix, actions);
- return this;
- }
- }, {
- key: "setTransform",
- value: function setTransform(actions) {
- this._attrs.attrs.matrix = [1, 0, 0, 1, 0, 0];
- return this.transform(actions);
- }
- }, {
- key: "translate",
- value: function translate(x, y) {
- var matrix = this._attrs.attrs.matrix;
- _matrix.default.translate(matrix, matrix, [x, y]);
- }
- }, {
- key: "rotate",
- value: function rotate(rad) {
- var matrix = this._attrs.attrs.matrix;
- _matrix.default.rotate(matrix, matrix, rad);
- }
- }, {
- key: "scale",
- value: function scale(sx, sy) {
- var matrix = this._attrs.attrs.matrix;
- _matrix.default.scale(matrix, matrix, [sx, sy]);
- }
- }, {
- key: "moveTo",
- value: function moveTo(x, y) {
- var cx = this._attrs.x || 0;
- var cy = this._attrs.y || 0;
- this.translate(x - cx, y - cy);
- this.set('x', x);
- this.set('y', y);
- }
- }, {
- key: "apply",
- value: function apply(v) {
- var m = this._attrs.attrs.matrix;
- _vector.default.transformMat2d(v, v, m);
- return this;
- }
- }, {
- key: "resetTransform",
- value: function resetTransform(context) {
- var mo = this._attrs.attrs.matrix;
- if (_matrix.default.isChanged(mo)) {
- context.transform(mo[0], mo[1], mo[2], mo[3], mo[4], mo[5]);
- }
- }
- }, {
- key: "isDestroyed",
- value: function isDestroyed() {
- return this.get('destroyed');
- }
- }]);
- return Element;
- }();
- var _default = Element;
- exports.default = _default;
- }, function(modId) { var map = {"../util/array":1679043784160,"../util/matrix":1679043784149,"../util/style-parse":1679043784164,"../util/vector2":1679043784150}; return __REQUIRE__(map[modId], modId); })
- __DEFINE__(1679043784164, function(require, module, exports) {
- Object.defineProperty(exports, "__esModule", {
- value: true
- });
- exports.default = void 0;
- exports.parseStyle = parseStyle;
- var _util = require("@antv/util");
- function _mod(n, m) {
- return (n % m + m) % m;
- }
- function _addStop(steps, gradient) {
- (0, _util.each)(steps, function (item) {
- item = item.split(':');
- gradient.addColorStop(Number(item[0]), item[1]);
- });
- }
- // the string format: 'l(0) 0:#ffffff 0.5:#7ec2f3 1:#1890ff'
- function _parseLineGradient(color, shape, context) {
- var arr = color.split(' ');
- var angle = arr[0].slice(2, arr[0].length - 1);
- angle = _mod(parseFloat(angle) * Math.PI / 180, Math.PI * 2);
- var steps = arr.slice(1);
- var _shape$getBBox = shape.getBBox(),
- minX = _shape$getBBox.minX,
- minY = _shape$getBBox.minY,
- maxX = _shape$getBBox.maxX,
- maxY = _shape$getBBox.maxY;
- var start;
- var end;
- if (angle >= 0 && angle < 0.5 * Math.PI) {
- start = {
- x: minX,
- y: minY
- };
- end = {
- x: maxX,
- y: maxY
- };
- } else if (0.5 * Math.PI <= angle && angle < Math.PI) {
- start = {
- x: maxX,
- y: minY
- };
- end = {
- x: minX,
- y: maxY
- };
- } else if (Math.PI <= angle && angle < 1.5 * Math.PI) {
- start = {
- x: maxX,
- y: maxY
- };
- end = {
- x: minX,
- y: minY
- };
- } else {
- start = {
- x: minX,
- y: maxY
- };
- end = {
- x: maxX,
- y: minY
- };
- }
- var tanTheta = Math.tan(angle);
- var tanTheta2 = tanTheta * tanTheta;
- var x = (end.x - start.x + tanTheta * (end.y - start.y)) / (tanTheta2 + 1) + start.x;
- var y = tanTheta * (end.x - start.x + tanTheta * (end.y - start.y)) / (tanTheta2 + 1) + start.y;
- var gradient = context.createLinearGradient(start.x, start.y, x, y);
- _addStop(steps, gradient);
- return gradient;
- }
- // the string format: 'r(0.5, 0.5, 0.1) 0:#ffffff 1:#1890ff'
- function _parseRadialGradient(color, shape, context) {
- var arr = color.split(' ');
- var circleCfg = arr[0].slice(2, arr[0].length - 1);
- circleCfg = circleCfg.split(',');
- var fx = parseFloat(circleCfg[0]);
- var fy = parseFloat(circleCfg[1]);
- var fr = parseFloat(circleCfg[2]);
- var steps = arr.slice(1);
- // if radius is 0, no gradient, stroke with the last color
- if (fr === 0) {
- var _color = steps[steps.length - 1];
- return _color.split(':')[1];
- }
- var _shape$getBBox2 = shape.getBBox(),
- width = _shape$getBBox2.width,
- height = _shape$getBBox2.height,
- minX = _shape$getBBox2.minX,
- minY = _shape$getBBox2.minY;
- var r = Math.sqrt(width * width + height * height) / 2;
- var gradient = context.createRadialGradient(minX + width * fx, minY + height * fy, fr * r, minX + width / 2, minY + height / 2, r);
- _addStop(steps, gradient);
- return gradient;
- }
- function parseStyle(color, shape, context) {
- if (color[1] === '(') {
- try {
- var firstCode = color[0];
- if (firstCode === 'l') {
- return _parseLineGradient(color, shape, context);
- } else if (firstCode === 'r') {
- return _parseRadialGradient(color, shape, context);
- }
- } catch (ev) {
- console.error('error in parsing gradient string, please check if there are any extra whitespaces.');
- console.error(ev);
- }
- }
- return color;
- }
- var _default = {
- parseStyle: parseStyle
- };
- exports.default = _default;
- }, function(modId) { var map = {}; return __REQUIRE__(map[modId], modId); })
- __DEFINE__(1679043784165, function(require, module, exports) {
- var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
- Object.defineProperty(exports, "__esModule", {
- value: true
- });
- exports.default = void 0;
- var _classCallCheck2 = _interopRequireDefault(require("@babel/runtime/helpers/classCallCheck"));
- var _createClass2 = _interopRequireDefault(require("@babel/runtime/helpers/createClass"));
- var _get2 = _interopRequireDefault(require("@babel/runtime/helpers/get"));
- var _getPrototypeOf2 = _interopRequireDefault(require("@babel/runtime/helpers/getPrototypeOf"));
- var _inherits2 = _interopRequireDefault(require("@babel/runtime/helpers/inherits"));
- var _createSuper2 = _interopRequireDefault(require("@babel/runtime/helpers/createSuper"));
- var _shape = _interopRequireDefault(require("./shape"));
- var _util = require("@antv/util");
- function parsePadding(padding) {
- var top = 0;
- var right = 0;
- var bottom = 0;
- var left = 0;
- if ((0, _util.isNumber)(padding)) {
- top = bottom = left = right = padding;
- } else if ((0, _util.isArray)(padding)) {
- top = padding[0];
- right = !(0, _util.isNil)(padding[1]) ? padding[1] : padding[0];
- bottom = !(0, _util.isNil)(padding[2]) ? padding[2] : padding[0];
- left = !(0, _util.isNil)(padding[3]) ? padding[3] : right;
- }
- return [top, right, bottom, left];
- }
- // 为了处理radius 大于 width 或 height 的场景
- function parseRadius(radius, width, height) {
- radius = parsePadding(radius);
- // 都为0
- if (!radius[0] && !radius[1] && !radius[2] && !radius[3]) {
- return radius;
- }
- var minWidth = Math.max(radius[0] + radius[1], radius[2] + radius[3]);
- var minHeight = Math.max(radius[0] + radius[3], radius[1] + radius[2]);
- var scale = Math.min(width / minWidth, height / minHeight);
- if (scale < 1) {
- return radius.map(function (r) {
- return r * scale;
- });
- }
- return radius;
- }
- var Rect = /*#__PURE__*/function (_Shape) {
- (0, _inherits2.default)(Rect, _Shape);
- var _super = (0, _createSuper2.default)(Rect);
- function Rect() {
- (0, _classCallCheck2.default)(this, Rect);
- return _super.apply(this, arguments);
- }
- (0, _createClass2.default)(Rect, [{
- key: "_initProperties",
- value: function _initProperties() {
- (0, _get2.default)((0, _getPrototypeOf2.default)(Rect.prototype), "_initProperties", this).call(this);
- this._attrs.canFill = true;
- this._attrs.canStroke = true;
- this._attrs.type = 'rect';
- }
- }, {
- key: "getDefaultAttrs",
- value: function getDefaultAttrs() {
- return {
- x: 0,
- y: 0,
- width: 0,
- height: 0,
- radius: 0,
- lineWidth: 0
- };
- }
- }, {
- key: "createRadiusPath",
- value: function createRadiusPath(context, x, y, width, height, radius) {
- radius = parseRadius(radius, width, height);
- context.moveTo(x + radius[0], y);
- context.lineTo(x + width - radius[1], y);
- context.arc(x + width - radius[1], y + radius[1], radius[1], -Math.PI / 2, 0, false);
- context.lineTo(x + width, y + height - radius[2]);
- context.arc(x + width - radius[2], y + height - radius[2], radius[2], 0, Math.PI / 2, false);
- context.lineTo(x + radius[3], y + height);
- context.arc(x + radius[3], y + height - radius[3], radius[3], Math.PI / 2, Math.PI, false);
- context.lineTo(x, y + radius[0]);
- context.arc(x + radius[0], y + radius[0], radius[0], Math.PI, Math.PI * 3 / 2, false);
- context.closePath();
- }
- }, {
- key: "createPath",
- value: function createPath(context) {
- var attrs = this.get('attrs');
- var x = attrs.x,
- y = attrs.y,
- width = attrs.width,
- height = attrs.height,
- radius = attrs.radius;
- context.beginPath();
- if (!radius || !(width * height)) {
- context.rect(x, y, width, height);
- } else {
- this.createRadiusPath(context, x, y, width, height, radius);
- }
- }
- }, {
- key: "calculateBox",
- value: function calculateBox() {
- var attrs = this.get('attrs');
- var x = attrs.x,
- y = attrs.y,
- width = attrs.width,
- height = attrs.height;
- return {
- minX: x,
- minY: y,
- maxX: x + width,
- maxY: y + height
- };
- }
- }]);
- return Rect;
- }(_shape.default);
- var _default = Rect;
- exports.default = _default;
- }, function(modId) { var map = {"./shape":1679043784162}; return __REQUIRE__(map[modId], modId); })
- __DEFINE__(1679043784166, function(require, module, exports) {
- var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
- Object.defineProperty(exports, "__esModule", {
- value: true
- });
- exports.default = void 0;
- var _classCallCheck2 = _interopRequireDefault(require("@babel/runtime/helpers/classCallCheck"));
- var _createClass2 = _interopRequireDefault(require("@babel/runtime/helpers/createClass"));
- var _get2 = _interopRequireDefault(require("@babel/runtime/helpers/get"));
- var _getPrototypeOf2 = _interopRequireDefault(require("@babel/runtime/helpers/getPrototypeOf"));
- var _inherits2 = _interopRequireDefault(require("@babel/runtime/helpers/inherits"));
- var _createSuper2 = _interopRequireDefault(require("@babel/runtime/helpers/createSuper"));
- var _util = require("@antv/util");
- var _rect = _interopRequireDefault(require("./rect"));
- var imageCaches = {};
- var ImageShape = /*#__PURE__*/function (_Rect) {
- (0, _inherits2.default)(ImageShape, _Rect);
- var _super = (0, _createSuper2.default)(ImageShape);
- function ImageShape() {
- (0, _classCallCheck2.default)(this, ImageShape);
- return _super.apply(this, arguments);
- }
- (0, _createClass2.default)(ImageShape, [{
- key: "_initProperties",
- value: function _initProperties() {
- (0, _get2.default)((0, _getPrototypeOf2.default)(ImageShape.prototype), "_initProperties", this).call(this);
- this._attrs.canFill = false;
- this._attrs.canStroke = false;
- this._attrs.loading = false;
- this._attrs.image = null;
- this._attrs.type = 'image';
- }
- }, {
- key: "draw",
- value: function draw(context) {
- var _this = this;
- // 如果图片还在loading中直接返回,等下次绘制
- if (this.get('loading')) {
- return;
- }
- // 如果已经有image对象,直接绘制,会调用createPath绘制
- var image = this.get('image');
- if (image) {
- (0, _get2.default)((0, _getPrototypeOf2.default)(ImageShape.prototype), "draw", this).call(this, context);
- return;
- }
- var attrs = this.get('attrs');
- var src = attrs.src;
- if (src) {
- var cacheImage = this.get('cacheImage');
- // 如果有缓存,则直接从缓存中拿
- if (cacheImage && imageCaches[src]) {
- this.set('image', imageCaches[src]);
- this.draw(context);
- return;
- }
- var _image = null;
- var canvas = this.get('canvas');
- if (canvas && canvas.get('createImage')) {
- var createImage = canvas.get('createImage');
- _image = createImage();
- } else if (window.Image) {
- _image = new Image();
- }
- if (_image) {
- this.set('loading', true);
- // 设置跨域, 等同于 image.crossOrigin = 'anonymous'
- _image.crossOrigin = '';
- _image.onload = function () {
- _this.set('loading', false);
- _this.set('image', _image);
- // this.draw(context);
- // 这里需要调用 canvas.draw 进行重新绘制,否则 image 会一直在最上层
- canvas.draw();
- };
- // src 一定要在 crossOrigin 之后,否则 toDataURL 就会报 SecurityError
- _image.src = src;
- // 设置全局缓存
- if (cacheImage) {
- imageCaches[src] = _image;
- }
- }
- }
- }
- }, {
- key: "createPath",
- value: function createPath(context) {
- var image = this.get('image');
- this.drawImage(context, image);
- }
- }, {
- key: "drawImage",
- value: function drawImage(context, image) {
- var _this$_attrs = this._attrs,
- attrs = _this$_attrs.attrs,
- destroyed = _this$_attrs.destroyed;
- if (destroyed) {
- return;
- }
- var x = attrs.x,
- y = attrs.y,
- width = attrs.width,
- height = attrs.height,
- sx = attrs.sx,
- sy = attrs.sy,
- swidth = attrs.swidth,
- sheight = attrs.sheight,
- radius = attrs.radius,
- fillOpacity = attrs.fillOpacity;
- if (radius) {
- context.save();
- this.createRadiusPath(context, x, y, width, height, radius);
- context.clip();
- }
- // 设置透明度
- var originOpacity = context.globalAlpha;
- if (!(0, _util.isNil)(fillOpacity)) {
- context.globalAlpha = fillOpacity;
- }
- if (!(0, _util.isNil)(sx) && !(0, _util.isNil)(sy) && !(0, _util.isNil)(swidth) && !(0, _util.isNil)(sheight)) {
- context.drawImage(image, sx, sy, swidth, sheight, x, y, width, height);
- } else {
- context.drawImage(image, x, y, width, height);
- }
- context.globalAlpha = originOpacity;
- if (radius) {
- // 因为 save 和 restore 会一定程度上影响绘图性能,所以只在必要是调用
- context.restore();
- }
- }
- }]);
- return ImageShape;
- }(_rect.default);
- var _default = ImageShape;
- exports.default = _default;
- }, function(modId) { var map = {"./rect":1679043784165}; return __REQUIRE__(map[modId], modId); })
- __DEFINE__(1679043784167, function(require, module, exports) {
- var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
- Object.defineProperty(exports, "__esModule", {
- value: true
- });
- exports.default = void 0;
- var _classCallCheck2 = _interopRequireDefault(require("@babel/runtime/helpers/classCallCheck"));
- var _createClass2 = _interopRequireDefault(require("@babel/runtime/helpers/createClass"));
- var _get2 = _interopRequireDefault(require("@babel/runtime/helpers/get"));
- var _getPrototypeOf2 = _interopRequireDefault(require("@babel/runtime/helpers/getPrototypeOf"));
- var _inherits2 = _interopRequireDefault(require("@babel/runtime/helpers/inherits"));
- var _createSuper2 = _interopRequireDefault(require("@babel/runtime/helpers/createSuper"));
- var _shape = _interopRequireDefault(require("./shape"));
- var Circle = /*#__PURE__*/function (_Shape) {
- (0, _inherits2.default)(Circle, _Shape);
- var _super = (0, _createSuper2.default)(Circle);
- function Circle() {
- (0, _classCallCheck2.default)(this, Circle);
- return _super.apply(this, arguments);
- }
- (0, _createClass2.default)(Circle, [{
- key: "_initProperties",
- value: function _initProperties() {
- (0, _get2.default)((0, _getPrototypeOf2.default)(Circle.prototype), "_initProperties", this).call(this);
- this._attrs.canFill = true;
- this._attrs.canStroke = true;
- this._attrs.type = 'circle';
- }
- }, {
- key: "getDefaultAttrs",
- value: function getDefaultAttrs() {
- return {
- x: 0,
- y: 0,
- r: 0,
- lineWidth: 0
- };
- }
- }, {
- key: "createPath",
- value: function createPath(context) {
- var attrs = this.get('attrs');
- var x = attrs.x,
- y = attrs.y,
- r = attrs.r;
- context.beginPath();
- context.arc(x, y, r, 0, Math.PI * 2, false);
- context.closePath();
- }
- }, {
- key: "calculateBox",
- value: function calculateBox() {
- var attrs = this.get('attrs');
- var x = attrs.x,
- y = attrs.y,
- r = attrs.r;
- return {
- minX: x - r,
- maxX: x + r,
- minY: y - r,
- maxY: y + r
- };
- }
- }]);
- return Circle;
- }(_shape.default);
- var _default = Circle;
- exports.default = _default;
- }, function(modId) { var map = {"./shape":1679043784162}; return __REQUIRE__(map[modId], modId); })
- __DEFINE__(1679043784168, function(require, module, exports) {
- var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
- Object.defineProperty(exports, "__esModule", {
- value: true
- });
- exports.default = void 0;
- var _classCallCheck2 = _interopRequireDefault(require("@babel/runtime/helpers/classCallCheck"));
- var _createClass2 = _interopRequireDefault(require("@babel/runtime/helpers/createClass"));
- var _get2 = _interopRequireDefault(require("@babel/runtime/helpers/get"));
- var _getPrototypeOf2 = _interopRequireDefault(require("@babel/runtime/helpers/getPrototypeOf"));
- var _inherits2 = _interopRequireDefault(require("@babel/runtime/helpers/inherits"));
- var _createSuper2 = _interopRequireDefault(require("@babel/runtime/helpers/createSuper"));
- var _shape = _interopRequireDefault(require("./shape"));
- var _bbox = require("../../util/bbox");
- var Line = /*#__PURE__*/function (_Shape) {
- (0, _inherits2.default)(Line, _Shape);
- var _super = (0, _createSuper2.default)(Line);
- function Line() {
- (0, _classCallCheck2.default)(this, Line);
- return _super.apply(this, arguments);
- }
- (0, _createClass2.default)(Line, [{
- key: "_initProperties",
- value: function _initProperties() {
- (0, _get2.default)((0, _getPrototypeOf2.default)(Line.prototype), "_initProperties", this).call(this);
- this._attrs.canStroke = true;
- this._attrs.type = 'line';
- }
- }, {
- key: "getDefaultAttrs",
- value: function getDefaultAttrs() {
- return {
- x1: 0,
- y1: 0,
- x2: 0,
- y2: 0,
- lineWidth: 1
- };
- }
- }, {
- key: "createPath",
- value: function createPath(context) {
- var attrs = this.get('attrs');
- var x1 = attrs.x1,
- y1 = attrs.y1,
- x2 = attrs.x2,
- y2 = attrs.y2;
- context.beginPath();
- context.moveTo(x1, y1);
- context.lineTo(x2, y2);
- }
- }, {
- key: "calculateBox",
- value: function calculateBox() {
- var attrs = this.get('attrs');
- var x1 = attrs.x1,
- y1 = attrs.y1,
- x2 = attrs.x2,
- y2 = attrs.y2,
- lineWidth = attrs.lineWidth;
- return (0, _bbox.getBBoxFromLine)(x1, y1, x2, y2, lineWidth);
- }
- }]);
- return Line;
- }(_shape.default);
- var _default = Line;
- exports.default = _default;
- }, function(modId) { var map = {"./shape":1679043784162,"../../util/bbox":1679043784152}; return __REQUIRE__(map[modId], modId); })
- __DEFINE__(1679043784169, function(require, module, exports) {
- var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
- Object.defineProperty(exports, "__esModule", {
- value: true
- });
- exports.default = void 0;
- var _classCallCheck2 = _interopRequireDefault(require("@babel/runtime/helpers/classCallCheck"));
- var _createClass2 = _interopRequireDefault(require("@babel/runtime/helpers/createClass"));
- var _get2 = _interopRequireDefault(require("@babel/runtime/helpers/get"));
- var _getPrototypeOf2 = _interopRequireDefault(require("@babel/runtime/helpers/getPrototypeOf"));
- var _inherits2 = _interopRequireDefault(require("@babel/runtime/helpers/inherits"));
- var _createSuper2 = _interopRequireDefault(require("@babel/runtime/helpers/createSuper"));
- var _shape = _interopRequireDefault(require("./shape"));
- var _bbox = require("../../util/bbox");
- var Polygon = /*#__PURE__*/function (_Shape) {
- (0, _inherits2.default)(Polygon, _Shape);
- var _super = (0, _createSuper2.default)(Polygon);
- function Polygon() {
- (0, _classCallCheck2.default)(this, Polygon);
- return _super.apply(this, arguments);
- }
- (0, _createClass2.default)(Polygon, [{
- key: "_initProperties",
- value: function _initProperties() {
- (0, _get2.default)((0, _getPrototypeOf2.default)(Polygon.prototype), "_initProperties", this).call(this);
- this._attrs.canFill = true;
- this._attrs.canStroke = true;
- this._attrs.type = 'polygon';
- }
- }, {
- key: "getDefaultAttrs",
- value: function getDefaultAttrs() {
- return {
- points: null,
- lineWidth: 0
- };
- }
- }, {
- key: "createPath",
- value: function createPath(context) {
- var attrs = this.get('attrs');
- var points = attrs.points;
- context.beginPath();
- for (var i = 0, len = points.length; i < len; i++) {
- var point = points[i];
- if (i === 0) {
- context.moveTo(point.x, point.y);
- } else {
- context.lineTo(point.x, point.y);
- }
- }
- context.closePath();
- }
- }, {
- key: "calculateBox",
- value: function calculateBox() {
- var attrs = this.get('attrs');
- var points = attrs.points;
- return (0, _bbox.getBBoxFromPoints)(points);
- }
- }]);
- return Polygon;
- }(_shape.default);
- var _default = Polygon;
- exports.default = _default;
- }, function(modId) { var map = {"./shape":1679043784162,"../../util/bbox":1679043784152}; return __REQUIRE__(map[modId], modId); })
- __DEFINE__(1679043784170, function(require, module, exports) {
- var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
- var _typeof = require("@babel/runtime/helpers/typeof");
- Object.defineProperty(exports, "__esModule", {
- value: true
- });
- exports.default = void 0;
- var _classCallCheck2 = _interopRequireDefault(require("@babel/runtime/helpers/classCallCheck"));
- var _createClass2 = _interopRequireDefault(require("@babel/runtime/helpers/createClass"));
- var _get2 = _interopRequireDefault(require("@babel/runtime/helpers/get"));
- var _getPrototypeOf2 = _interopRequireDefault(require("@babel/runtime/helpers/getPrototypeOf"));
- var _inherits2 = _interopRequireDefault(require("@babel/runtime/helpers/inherits"));
- var _createSuper2 = _interopRequireDefault(require("@babel/runtime/helpers/createSuper"));
- var _shape = _interopRequireDefault(require("./shape"));
- var _bbox = require("../../util/bbox");
- var Smooth = _interopRequireWildcard(require("../../util/smooth"));
- 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); }
- 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; }
- // filter the point which x or y is NaN
- function _filterPoints(points) {
- var filteredPoints = [];
- for (var i = 0, len = points.length; i < len; i++) {
- var point = points[i];
- if (!isNaN(point.x) && !isNaN(point.y)) {
- filteredPoints.push(point);
- }
- }
- return filteredPoints;
- }
- var Polyline = /*#__PURE__*/function (_Shape) {
- (0, _inherits2.default)(Polyline, _Shape);
- var _super = (0, _createSuper2.default)(Polyline);
- function Polyline() {
- (0, _classCallCheck2.default)(this, Polyline);
- return _super.apply(this, arguments);
- }
- (0, _createClass2.default)(Polyline, [{
- key: "_initProperties",
- value: function _initProperties() {
- (0, _get2.default)((0, _getPrototypeOf2.default)(Polyline.prototype), "_initProperties", this).call(this);
- this._attrs.canFill = true;
- this._attrs.canStroke = true;
- this._attrs.type = 'polyline';
- }
- }, {
- key: "getDefaultAttrs",
- value: function getDefaultAttrs() {
- return {
- points: null,
- lineWidth: 1,
- smooth: false
- };
- }
- }, {
- key: "createPath",
- value: function createPath(context) {
- var attrs = this.get('attrs');
- var points = attrs.points,
- smooth = attrs.smooth;
- var filteredPoints = _filterPoints(points);
- context.beginPath();
- if (filteredPoints.length) {
- context.moveTo(filteredPoints[0].x, filteredPoints[0].y);
- if (smooth) {
- var constaint = [[0, 0], [1, 1]];
- var sps = Smooth.smooth(filteredPoints, false, constaint);
- for (var i = 0, n = sps.length; i < n; i++) {
- var sp = sps[i];
- context.bezierCurveTo(sp[1], sp[2], sp[3], sp[4], sp[5], sp[6]);
- }
- } else {
- var _i;
- var l;
- for (_i = 1, l = filteredPoints.length - 1; _i < l; _i++) {
- context.lineTo(filteredPoints[_i].x, filteredPoints[_i].y);
- }
- context.lineTo(filteredPoints[l].x, filteredPoints[l].y);
- }
- }
- }
- }, {
- key: "calculateBox",
- value: function calculateBox() {
- var attrs = this.get('attrs');
- var points = attrs.points,
- smooth = attrs.smooth,
- lineWidth = attrs.lineWidth;
- var filteredPoints = _filterPoints(points);
- if (smooth) {
- var newPoints = [];
- var constaint = [[0, 0], [1, 1]];
- var sps = Smooth.smooth(filteredPoints, false, constaint);
- for (var i = 0, n = sps.length; i < n; i++) {
- var sp = sps[i];
- if (i === 0) {
- newPoints.push([filteredPoints[0].x, filteredPoints[0].y, sp[1], sp[2], sp[3], sp[4], sp[5], sp[6]]);
- } else {
- var lastPoint = sps[i - 1];
- newPoints.push([lastPoint[5], lastPoint[6], sp[1], sp[2], sp[3], sp[4], sp[5], sp[6]]);
- }
- }
- return (0, _bbox.getBBoxFromBezierGroup)(newPoints, lineWidth);
- }
- return (0, _bbox.getBBoxFromPoints)(filteredPoints, lineWidth);
- }
- }]);
- return Polyline;
- }(_shape.default);
- var _default = Polyline;
- exports.default = _default;
- }, function(modId) { var map = {"./shape":1679043784162,"../../util/bbox":1679043784152,"../../util/smooth":1679043784151}; return __REQUIRE__(map[modId], modId); })
- __DEFINE__(1679043784171, function(require, module, exports) {
- var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
- Object.defineProperty(exports, "__esModule", {
- value: true
- });
- exports.default = void 0;
- var _classCallCheck2 = _interopRequireDefault(require("@babel/runtime/helpers/classCallCheck"));
- var _createClass2 = _interopRequireDefault(require("@babel/runtime/helpers/createClass"));
- var _get2 = _interopRequireDefault(require("@babel/runtime/helpers/get"));
- var _getPrototypeOf2 = _interopRequireDefault(require("@babel/runtime/helpers/getPrototypeOf"));
- var _inherits2 = _interopRequireDefault(require("@babel/runtime/helpers/inherits"));
- var _createSuper2 = _interopRequireDefault(require("@babel/runtime/helpers/createSuper"));
- var _shape = _interopRequireDefault(require("./shape"));
- var _bbox = require("../../util/bbox");
- var Arc = /*#__PURE__*/function (_Shape) {
- (0, _inherits2.default)(Arc, _Shape);
- var _super = (0, _createSuper2.default)(Arc);
- function Arc() {
- (0, _classCallCheck2.default)(this, Arc);
- return _super.apply(this, arguments);
- }
- (0, _createClass2.default)(Arc, [{
- key: "_initProperties",
- value: function _initProperties() {
- (0, _get2.default)((0, _getPrototypeOf2.default)(Arc.prototype), "_initProperties", this).call(this);
- this._attrs.canStroke = true;
- this._attrs.canFill = true;
- this._attrs.type = 'arc';
- }
- }, {
- key: "getDefaultAttrs",
- value: function getDefaultAttrs() {
- return {
- x: 0,
- y: 0,
- r: 0,
- startAngle: 0,
- endAngle: Math.PI * 2,
- anticlockwise: false,
- lineWidth: 1
- };
- }
- }, {
- key: "createPath",
- value: function createPath(context) {
- var attrs = this.get('attrs');
- var x = attrs.x,
- y = attrs.y,
- r = attrs.r,
- startAngle = attrs.startAngle,
- endAngle = attrs.endAngle,
- anticlockwise = attrs.anticlockwise;
- context.beginPath();
- if (startAngle !== endAngle) {
- context.arc(x, y, r, startAngle, endAngle, anticlockwise);
- }
- }
- }, {
- key: "calculateBox",
- value: function calculateBox() {
- var attrs = this.get('attrs');
- var x = attrs.x,
- y = attrs.y,
- r = attrs.r,
- startAngle = attrs.startAngle,
- endAngle = attrs.endAngle,
- anticlockwise = attrs.anticlockwise;
- return (0, _bbox.getBBoxFromArc)(x, y, r, startAngle, endAngle, anticlockwise);
- }
- }]);
- return Arc;
- }(_shape.default);
- var _default = Arc;
- exports.default = _default;
- }, function(modId) { var map = {"./shape":1679043784162,"../../util/bbox":1679043784152}; return __REQUIRE__(map[modId], modId); })
- __DEFINE__(1679043784172, function(require, module, exports) {
- var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
- Object.defineProperty(exports, "__esModule", {
- value: true
- });
- exports.default = void 0;
- var _classCallCheck2 = _interopRequireDefault(require("@babel/runtime/helpers/classCallCheck"));
- var _createClass2 = _interopRequireDefault(require("@babel/runtime/helpers/createClass"));
- var _get2 = _interopRequireDefault(require("@babel/runtime/helpers/get"));
- var _getPrototypeOf2 = _interopRequireDefault(require("@babel/runtime/helpers/getPrototypeOf"));
- var _inherits2 = _interopRequireDefault(require("@babel/runtime/helpers/inherits"));
- var _createSuper2 = _interopRequireDefault(require("@babel/runtime/helpers/createSuper"));
- var _shape = _interopRequireDefault(require("./shape"));
- var _bbox = require("../../util/bbox");
- var Sector = /*#__PURE__*/function (_Shape) {
- (0, _inherits2.default)(Sector, _Shape);
- var _super = (0, _createSuper2.default)(Sector);
- function Sector() {
- (0, _classCallCheck2.default)(this, Sector);
- return _super.apply(this, arguments);
- }
- (0, _createClass2.default)(Sector, [{
- key: "_initProperties",
- value: function _initProperties() {
- (0, _get2.default)((0, _getPrototypeOf2.default)(Sector.prototype), "_initProperties", this).call(this);
- this._attrs.canFill = true;
- this._attrs.canStroke = true;
- this._attrs.type = 'sector';
- }
- }, {
- key: "getDefaultAttrs",
- value: function getDefaultAttrs() {
- return {
- x: 0,
- y: 0,
- lineWidth: 0,
- r: 0,
- r0: 0,
- startAngle: 0,
- endAngle: Math.PI * 2,
- anticlockwise: false
- };
- }
- }, {
- key: "createPath",
- value: function createPath(context) {
- var attrs = this.get('attrs');
- var x = attrs.x,
- y = attrs.y,
- startAngle = attrs.startAngle,
- r = attrs.r,
- r0 = attrs.r0,
- anticlockwise = attrs.anticlockwise;
- // 最大为整个圆
- var endAngle = Math.min(attrs.endAngle, startAngle + Math.PI * 2);
- context.beginPath();
- var unitX = Math.cos(startAngle);
- var unitY = Math.sin(startAngle);
- context.moveTo(unitX * r0 + x, unitY * r0 + y);
- context.lineTo(unitX * r + x, unitY * r + y);
- // 当扇形的角度非常小的时候,就不进行弧线的绘制;或者整个只有1个扇形时,会出现end<0的情况不绘制
- if (Math.abs(endAngle - startAngle) > 0.0001 || startAngle === 0 && endAngle < 0) {
- context.arc(x, y, r, startAngle, endAngle, anticlockwise);
- context.lineTo(Math.cos(endAngle) * r0 + x, Math.sin(endAngle) * r0 + y);
- if (r0 !== 0) {
- context.arc(x, y, r0, endAngle, startAngle, !anticlockwise);
- }
- }
- context.closePath();
- }
- }, {
- key: "calculateBox",
- value: function calculateBox() {
- var attrs = this.get('attrs');
- var x = attrs.x,
- y = attrs.y,
- r = attrs.r,
- r0 = attrs.r0,
- startAngle = attrs.startAngle,
- endAngle = attrs.endAngle,
- anticlockwise = attrs.anticlockwise;
- var outerBBox = (0, _bbox.getBBoxFromArc)(x, y, r, startAngle, endAngle, anticlockwise);
- var innerBBox = (0, _bbox.getBBoxFromArc)(x, y, r0, startAngle, endAngle, anticlockwise);
- return {
- minX: Math.min(outerBBox.minX, innerBBox.minX),
- minY: Math.min(outerBBox.minY, innerBBox.minY),
- maxX: Math.max(outerBBox.maxX, innerBBox.maxX),
- maxY: Math.max(outerBBox.maxY, innerBBox.maxY)
- };
- }
- }]);
- return Sector;
- }(_shape.default);
- var _default = Sector;
- exports.default = _default;
- }, function(modId) { var map = {"./shape":1679043784162,"../../util/bbox":1679043784152}; return __REQUIRE__(map[modId], modId); })
- __DEFINE__(1679043784173, function(require, module, exports) {
- var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
- var _typeof = require("@babel/runtime/helpers/typeof");
- Object.defineProperty(exports, "__esModule", {
- value: true
- });
- exports.default = void 0;
- var _classCallCheck2 = _interopRequireDefault(require("@babel/runtime/helpers/classCallCheck"));
- var _createClass2 = _interopRequireDefault(require("@babel/runtime/helpers/createClass"));
- var _get2 = _interopRequireDefault(require("@babel/runtime/helpers/get"));
- var _getPrototypeOf2 = _interopRequireDefault(require("@babel/runtime/helpers/getPrototypeOf"));
- var _inherits2 = _interopRequireDefault(require("@babel/runtime/helpers/inherits"));
- var _createSuper2 = _interopRequireDefault(require("@babel/runtime/helpers/createSuper"));
- var _util = require("@antv/util");
- var DOMUtil = _interopRequireWildcard(require("../../util/dom"));
- var _shape = _interopRequireDefault(require("./shape"));
- var _rect = _interopRequireDefault(require("../../util/rect"));
- 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); }
- 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; }
- var measureText = DOMUtil.measureText;
- var textWidthCacheCounter = 0;
- var textWidthCache = {};
- var TEXT_CACHE_MAX = 5000;
- var Text = /*#__PURE__*/function (_Shape) {
- (0, _inherits2.default)(Text, _Shape);
- var _super = (0, _createSuper2.default)(Text);
- function Text() {
- (0, _classCallCheck2.default)(this, Text);
- return _super.apply(this, arguments);
- }
- (0, _createClass2.default)(Text, [{
- key: "_initProperties",
- value: function _initProperties() {
- (0, _get2.default)((0, _getPrototypeOf2.default)(Text.prototype), "_initProperties", this).call(this);
- this._attrs.canFill = true;
- this._attrs.canStroke = true;
- this._attrs.type = 'text';
- }
- }, {
- key: "getDefaultAttrs",
- value: function getDefaultAttrs() {
- return {
- lineWidth: 0,
- lineCount: 1,
- fontSize: 12,
- fontFamily: '',
- fontStyle: 'normal',
- fontWeight: 'normal',
- fontVariant: 'normal',
- textAlign: 'start',
- textBaseline: 'bottom',
- lineHeight: null,
- textArr: null
- };
- }
- }, {
- key: "_getFontStyle",
- value: function _getFontStyle() {
- var attrs = this._attrs.attrs;
- var fontSize = attrs.fontSize,
- fontFamily = attrs.fontFamily,
- fontWeight = attrs.fontWeight,
- fontStyle = attrs.fontStyle,
- fontVariant = attrs.fontVariant;
- return "".concat(fontStyle, " ").concat(fontVariant, " ").concat(fontWeight, " ").concat(fontSize, "px ").concat(fontFamily);
- }
- }, {
- key: "_afterAttrsSet",
- value: function _afterAttrsSet() {
- var attrs = this._attrs.attrs;
- attrs.font = this._getFontStyle();
- if (attrs.text) {
- var text = attrs.text;
- var textArr = null;
- var lineCount = 1;
- if ((0, _util.isString)(text) && text.indexOf('\n') !== -1) {
- textArr = text.split('\n');
- lineCount = textArr.length;
- }
- attrs.lineCount = lineCount;
- attrs.textArr = textArr;
- }
- this.set('attrs', attrs);
- }
- }, {
- key: "_getTextHeight",
- value: function _getTextHeight() {
- var attrs = this._attrs.attrs;
- if (attrs.height) {
- return attrs.height;
- }
- var lineCount = attrs.lineCount;
- var fontSize = attrs.fontSize * 1;
- if (lineCount > 1) {
- var spaceingY = this._getSpaceingY();
- return fontSize * lineCount + spaceingY * (lineCount - 1);
- }
- return fontSize;
- }
- }, {
- key: "_getSpaceingY",
- value: function _getSpaceingY() {
- var attrs = this._attrs.attrs;
- var lineHeight = attrs.lineHeight;
- var fontSize = attrs.fontSize * 1;
- return lineHeight ? lineHeight - fontSize : fontSize * 0.14;
- }
- }, {
- key: "drawInner",
- value: function drawInner(context) {
- var attrs = this._attrs.attrs;
- var text = attrs.text;
- var x = attrs.x;
- var y = attrs.y;
- if ((0, _util.isNil)(text) || isNaN(x) || isNaN(y)) {
- // text will be 0
- return;
- }
- var textArr = attrs.textArr;
- var fontSize = attrs.fontSize * 1;
- var spaceingY = this._getSpaceingY();
- if (attrs.rotate) {
- // do rotation
- context.translate(x, y);
- context.rotate(attrs.rotate);
- x = 0;
- y = 0;
- }
- var textBaseline = attrs.textBaseline;
- var height;
- if (textArr) {
- height = this._getTextHeight();
- }
- var subY;
- // context.beginPath();
- if (this.hasFill()) {
- var fillOpacity = attrs.fillOpacity;
- if (!(0, _util.isNil)(fillOpacity) && fillOpacity !== 1) {
- context.globalAlpha = fillOpacity;
- }
- if (textArr) {
- for (var i = 0, len = textArr.length; i < len; i++) {
- var subText = textArr[i];
- subY = y + i * (spaceingY + fontSize) - height + fontSize; // bottom;
- if (textBaseline === 'middle') {
- subY += height - fontSize - (height - fontSize) / 2;
- }
- if (textBaseline === 'top') {
- subY += height - fontSize;
- }
- context.fillText(subText, x, subY);
- }
- } else {
- context.fillText(text, x, y);
- }
- }
- if (this.hasStroke()) {
- if (textArr) {
- for (var _i = 0, _len = textArr.length; _i < _len; _i++) {
- var _subText = textArr[_i];
- subY = y + _i * (spaceingY + fontSize) - height + fontSize; // bottom;
- if (textBaseline === 'middle') {
- subY += height - fontSize - (height - fontSize) / 2;
- }
- if (textBaseline === 'top') {
- subY += height - fontSize;
- }
- context.strokeText(_subText, x, subY);
- }
- } else {
- context.strokeText(text, x, y);
- }
- }
- }
- }, {
- key: "_getAriaLabel",
- value: function _getAriaLabel() {
- return this._attrs.attrs.text;
- }
- }, {
- key: "calculateBox",
- value: function calculateBox() {
- var attrs = this._attrs.attrs;
- var x = attrs.x,
- y = attrs.y,
- textAlign = attrs.textAlign,
- textBaseline = attrs.textBaseline;
- var width = this._getTextWidth(); // attrs.width
- if (!width) {
- return {
- minX: x,
- minY: y,
- maxX: x,
- maxY: y
- };
- }
- var height = this._getTextHeight(); // attrs.height
- if (attrs.rotate) {
- var rotatedBox = _rect.default.calcRotatedBox({
- width: width,
- height: height,
- rotate: attrs.rotate
- });
- width = rotatedBox.width;
- height = rotatedBox.height;
- }
- var point = {
- x: x,
- y: y - height
- }; // default textAlign: start, textBaseline: bottom
- if (textAlign) {
- if (textAlign === 'end' || textAlign === 'right') {
- point.x -= width;
- } else if (textAlign === 'center') {
- point.x -= width / 2;
- }
- }
- if (textBaseline) {
- if (textBaseline === 'top') {
- point.y += height;
- } else if (textBaseline === 'middle') {
- point.y += height / 2;
- }
- }
- return {
- minX: point.x,
- minY: point.y,
- maxX: point.x + width,
- maxY: point.y + height
- };
- }
- }, {
- key: "_getTextWidth",
- value: function _getTextWidth() {
- var attrs = this._attrs.attrs;
- if (attrs.width) {
- return attrs.width;
- }
- var text = attrs.text;
- var context = this.get('context');
- if ((0, _util.isNil)(text)) return undefined;
- var font = attrs.font;
- var textArr = attrs.textArr;
- var key = text + '' + font;
- if (textWidthCache[key]) {
- return textWidthCache[key];
- }
- var width = 0;
- if (textArr) {
- for (var i = 0, length = textArr.length; i < length; i++) {
- var subText = textArr[i];
- width = Math.max(width, measureText(subText, font, context).width);
- }
- } else {
- width = measureText(text, font, context).width;
- }
- if (textWidthCacheCounter > TEXT_CACHE_MAX) {
- textWidthCacheCounter = 0;
- textWidthCache = {};
- }
- textWidthCacheCounter++;
- textWidthCache[key] = width;
- return width;
- }
- }]);
- return Text;
- }(_shape.default);
- var _default = Text;
- exports.default = _default;
- }, function(modId) { var map = {"../../util/dom":1679043784157,"./shape":1679043784162,"../../util/rect":1679043784174}; return __REQUIRE__(map[modId], modId); })
- __DEFINE__(1679043784174, function(require, module, exports) {
- Object.defineProperty(exports, "__esModule", {
- value: true
- });
- exports.default = void 0;
- var Rect = {
- calcRotatedBox: function calcRotatedBox(_ref) {
- var width = _ref.width,
- height = _ref.height,
- rotate = _ref.rotate;
- var absRotate = Math.abs(rotate);
- return {
- width: Math.abs(width * Math.cos(absRotate) + height * Math.sin(absRotate)),
- height: Math.abs(height * Math.cos(absRotate) + width * Math.sin(absRotate))
- };
- }
- };
- var _default = Rect;
- exports.default = _default;
- }, function(modId) { var map = {}; return __REQUIRE__(map[modId], modId); })
- __DEFINE__(1679043784175, function(require, module, exports) {
- var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
- Object.defineProperty(exports, "__esModule", {
- value: true
- });
- exports.default = void 0;
- var _classCallCheck2 = _interopRequireDefault(require("@babel/runtime/helpers/classCallCheck"));
- var _createClass2 = _interopRequireDefault(require("@babel/runtime/helpers/createClass"));
- var _get2 = _interopRequireDefault(require("@babel/runtime/helpers/get"));
- var _getPrototypeOf2 = _interopRequireDefault(require("@babel/runtime/helpers/getPrototypeOf"));
- var _inherits2 = _interopRequireDefault(require("@babel/runtime/helpers/inherits"));
- var _createSuper2 = _interopRequireDefault(require("@babel/runtime/helpers/createSuper"));
- var _shape = _interopRequireDefault(require("./shape"));
- var Custom = /*#__PURE__*/function (_Shape) {
- (0, _inherits2.default)(Custom, _Shape);
- var _super = (0, _createSuper2.default)(Custom);
- function Custom() {
- (0, _classCallCheck2.default)(this, Custom);
- return _super.apply(this, arguments);
- }
- (0, _createClass2.default)(Custom, [{
- key: "_initProperties",
- value: function _initProperties() {
- (0, _get2.default)((0, _getPrototypeOf2.default)(Custom.prototype), "_initProperties", this).call(this);
- this._attrs.canFill = true;
- this._attrs.canStroke = true;
- this._attrs.createPath = null;
- this._attrs.type = 'custom';
- }
- }, {
- key: "createPath",
- value: function createPath(context) {
- var createPath = this.get('createPath');
- createPath && createPath.call(this, context);
- }
- }, {
- key: "calculateBox",
- value: function calculateBox() {
- var calculateBox = this.get('calculateBox');
- return calculateBox && calculateBox.call(this);
- }
- }]);
- return Custom;
- }(_shape.default);
- var _default = Custom;
- exports.default = _default;
- }, function(modId) { var map = {"./shape":1679043784162}; return __REQUIRE__(map[modId], modId); })
- __DEFINE__(1679043784176, function(require, module, exports) {
- var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
- Object.defineProperty(exports, "__esModule", {
- value: true
- });
- exports.default = void 0;
- var _classCallCheck2 = _interopRequireDefault(require("@babel/runtime/helpers/classCallCheck"));
- var _createClass2 = _interopRequireDefault(require("@babel/runtime/helpers/createClass"));
- var _get2 = _interopRequireDefault(require("@babel/runtime/helpers/get"));
- var _getPrototypeOf2 = _interopRequireDefault(require("@babel/runtime/helpers/getPrototypeOf"));
- var _inherits2 = _interopRequireDefault(require("@babel/runtime/helpers/inherits"));
- var _createSuper2 = _interopRequireDefault(require("@babel/runtime/helpers/createSuper"));
- var _util = require("@antv/util");
- var _shape = _interopRequireDefault(require("./shape"));
- /**
- * marker shapes,used for tooltip and legend
- */
- var SYMBOLS = {
- circle: function circle(x, y, r, ctx) {
- ctx.arc(x, y, r, 0, Math.PI * 2, false);
- },
- square: function square(x, y, r, ctx) {
- ctx.moveTo(x - r, y - r);
- ctx.lineTo(x + r, y - r);
- ctx.lineTo(x + r, y + r);
- ctx.lineTo(x - r, y + r);
- ctx.closePath();
- }
- };
- var Marker = /*#__PURE__*/function (_Shape) {
- (0, _inherits2.default)(Marker, _Shape);
- var _super = (0, _createSuper2.default)(Marker);
- function Marker() {
- (0, _classCallCheck2.default)(this, Marker);
- return _super.apply(this, arguments);
- }
- (0, _createClass2.default)(Marker, [{
- key: "_initProperties",
- value: function _initProperties() {
- (0, _get2.default)((0, _getPrototypeOf2.default)(Marker.prototype), "_initProperties", this).call(this);
- this._attrs.canFill = true;
- this._attrs.canStroke = true;
- this._attrs.type = 'marker';
- }
- }, {
- key: "getDefaultAttrs",
- value: function getDefaultAttrs() {
- return {
- x: 0,
- y: 0,
- lineWidth: 0
- };
- }
- }, {
- key: "createPath",
- value: function createPath(context) {
- var attrs = this.get('attrs');
- var x = attrs.x,
- y = attrs.y,
- radius = attrs.radius;
- var symbol = attrs.symbol || 'circle';
- var method;
- if ((0, _util.isFunction)(symbol)) {
- method = symbol;
- } else {
- method = SYMBOLS[symbol];
- }
- context.beginPath();
- method(x, y, radius, context, this);
- }
- }, {
- key: "calculateBox",
- value: function calculateBox() {
- var attrs = this.get('attrs');
- var x = attrs.x,
- y = attrs.y,
- radius = attrs.radius;
- return {
- minX: x - radius,
- minY: y - radius,
- maxX: x + radius,
- maxY: y + radius
- };
- }
- }]);
- return Marker;
- }(_shape.default);
- var _default = Marker;
- exports.default = _default;
- }, function(modId) { var map = {"./shape":1679043784162}; return __REQUIRE__(map[modId], modId); })
- __DEFINE__(1679043784177, function(require, module, exports) {
- var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
- Object.defineProperty(exports, "__esModule", {
- value: true
- });
- exports.default = void 0;
- var _classCallCheck2 = _interopRequireDefault(require("@babel/runtime/helpers/classCallCheck"));
- var _createClass2 = _interopRequireDefault(require("@babel/runtime/helpers/createClass"));
- var _get2 = _interopRequireDefault(require("@babel/runtime/helpers/get"));
- var _getPrototypeOf2 = _interopRequireDefault(require("@babel/runtime/helpers/getPrototypeOf"));
- var _inherits2 = _interopRequireDefault(require("@babel/runtime/helpers/inherits"));
- var _createSuper2 = _interopRequireDefault(require("@babel/runtime/helpers/createSuper"));
- var _util = require("@antv/util");
- var _rect = _interopRequireDefault(require("./shape/rect"));
- var _container = _interopRequireDefault(require("./container"));
- var _vector = _interopRequireDefault(require("../util/vector2"));
- var Group = /*#__PURE__*/function (_Rect) {
- (0, _inherits2.default)(Group, _Rect);
- var _super = (0, _createSuper2.default)(Group);
- function Group() {
- (0, _classCallCheck2.default)(this, Group);
- return _super.apply(this, arguments);
- }
- (0, _createClass2.default)(Group, [{
- key: "_initProperties",
- value: /* eslint-enable */
- function _initProperties() {
- this._attrs = {
- type: 'group',
- zIndex: 0,
- visible: true,
- destroyed: false,
- isGroup: true,
- canFill: true,
- canStroke: true,
- children: [],
- attrs: {
- x: 0,
- y: 0,
- width: 0,
- height: 0,
- radius: 0,
- lineWidth: 0
- }
- };
- }
- }, {
- key: "getBBox",
- value: function getBBox() {
- var minX = Infinity;
- var maxX = -Infinity;
- var minY = Infinity;
- var maxY = -Infinity;
- var children = this.get('children');
- for (var i = 0, length = children.length; i < length; i++) {
- var child = children[i];
- if (child.get('visible')) {
- var box = child.getBBox();
- if (!box) {
- continue;
- }
- var leftTop = [box.minX, box.minY];
- var leftBottom = [box.minX, box.maxY];
- var rightTop = [box.maxX, box.minY];
- var rightBottom = [box.maxX, box.maxY];
- var matrix = child.attr('matrix');
- _vector.default.transformMat2d(leftTop, leftTop, matrix);
- _vector.default.transformMat2d(leftBottom, leftBottom, matrix);
- _vector.default.transformMat2d(rightTop, rightTop, matrix);
- _vector.default.transformMat2d(rightBottom, rightBottom, matrix);
- minX = Math.min(leftTop[0], leftBottom[0], rightTop[0], rightBottom[0], minX);
- maxX = Math.max(leftTop[0], leftBottom[0], rightTop[0], rightBottom[0], maxX);
- minY = Math.min(leftTop[1], leftBottom[1], rightTop[1], rightBottom[1], minY);
- maxY = Math.max(leftTop[1], leftBottom[1], rightTop[1], rightBottom[1], maxY);
- }
- }
- return {
- minX: minX,
- minY: minY,
- maxX: maxX,
- maxY: maxY,
- x: minX,
- y: minY,
- width: maxX - minX,
- height: maxY - minY
- };
- }
- }, {
- key: "createPath",
- value: function createPath(context) {
- var attrs = this.get('attrs');
- // 只有在有fillStyle或strokeStyle 时才需要绘制
- if (!attrs.fillStyle && !attrs.strokeStyle) {
- return;
- }
- (0, _get2.default)((0, _getPrototypeOf2.default)(Group.prototype), "createPath", this).call(this, context);
- }
- }, {
- key: "drawInner",
- value: function drawInner(context) {
- (0, _get2.default)((0, _getPrototypeOf2.default)(Group.prototype), "drawInner", this).call(this, context);
- this.drawChildren(context);
- }
- }, {
- key: "destroy",
- value: function destroy() {
- if (this.get('destroyed')) {
- return;
- }
- this.clear();
- (0, _get2.default)((0, _getPrototypeOf2.default)(Group.prototype), "destroy", this).call(this);
- }
- }]);
- return Group;
- }(_rect.default); // @ts-ignore
- (0, _util.mix)(Group.prototype, _container.default, {
- getGroupClass: function getGroupClass() {
- return Group;
- }
- });
- var _default = Group;
- exports.default = _default;
- }, function(modId) { var map = {"./shape/rect":1679043784165,"./container":1679043784159,"../util/vector2":1679043784150}; return __REQUIRE__(map[modId], modId); })
- __DEFINE__(1679043784178, function(require, module, exports) {
- var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
- Object.defineProperty(exports, "__esModule", {
- value: true
- });
- exports.requestAnimationFrame = void 0;
- var _typeof2 = _interopRequireDefault(require("@babel/runtime/helpers/typeof"));
- var requestAnimationFrame = (typeof window === "undefined" ? "undefined" : (0, _typeof2.default)(window)) === 'object' && window.requestAnimationFrame ? window.requestAnimationFrame : function (fn) {
- return setTimeout(fn, 16);
- };
- exports.requestAnimationFrame = requestAnimationFrame;
- }, function(modId) { var map = {}; return __REQUIRE__(map[modId], modId); })
- __DEFINE__(1679043784179, function(require, module, exports) {
- Object.defineProperty(exports, "__esModule", {
- value: true
- });
- exports.default = void 0;
- var _default = {
- general: {
- title: '这是一个图表,',
- withTitle: '这是一个关于“{title}”的图表。'
- },
- coord: {
- cartesian: 'X轴是{xLabel}Y轴是{yLabel}'
- // polar: '弧度是{xLabel}半径是{yLabel}'
- },
- scale: {
- linear: '数值型,数据最小值为{min},最大值为{max};',
- cat: '分类型, 分类类型有:{values};',
- timeCat: '时间型,时间范围从{start}到{end};'
- },
- geometry: {
- prefix: '共有{count}种分类组成,',
- oneData: '第{index}类是{name},数据是{values};',
- partData: '第{index}类是{name},共有{count}项数据,前{part}项是{values};',
- allData: '第{index}类是{name},有{count}项数据,分别是{values};'
- },
- legend: {
- prefix: '图例分类有:'
- }
- };
- exports.default = _default;
- }, function(modId) { var map = {}; return __REQUIRE__(map[modId], modId); })
- __DEFINE__(1679043784180, function(require, module, exports) {
- Object.defineProperty(exports, "__esModule", {
- value: true
- });
- }, function(modId) { var map = {}; return __REQUIRE__(map[modId], modId); })
- return __REQUIRE__(1679043784148);
- })()
- //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"]
- //# sourceMappingURL=index.js.map
|