bin-charts-next
Version:
基于echarts的 vue插件,用于配合实现图表组件
7 lines (6 loc) • 11.4 kB
JavaScript
/*!
* bin-charts-next v1.1.0
* (c) 2022 wangbin
* @license MIT
*/
var BinChartsNext=function(t,e,n){"use strict";function r(t){if(t&&t.__esModule)return t;var e=Object.create(null);if(t)for(var n in t)e[n]=t[n];return e.default=t,Object.freeze(e)}var i=r(n);function o(t,e){return function(t,e,n){var r,i=0;return function(){var o=this,s=Number(new Date)-i,a=arguments;function c(){r&&clearTimeout(r)}function u(){r=void 0}function h(){i=Number(new Date),t.apply(o,a)}n&&!r&&h(),c(),void 0===n&&s>e?h():r=setTimeout(n?u:h,void 0===n?e-s:e)}}(t,e,!1)}var s=function(){if("undefined"!=typeof Map)return Map;function t(t,e){var n=-1;return t.some((function(t,r){return t[0]===e&&(n=r,!0)})),n}return function(){function e(){this.__entries__=[]}return Object.defineProperty(e.prototype,"size",{get:function(){return this.__entries__.length},enumerable:!0,configurable:!0}),e.prototype.get=function(e){var n=t(this.__entries__,e),r=this.__entries__[n];return r&&r[1]},e.prototype.set=function(e,n){var r=t(this.__entries__,e);~r?this.__entries__[r][1]=n:this.__entries__.push([e,n])},e.prototype.delete=function(e){var n=this.__entries__,r=t(n,e);~r&&n.splice(r,1)},e.prototype.has=function(e){return!!~t(this.__entries__,e)},e.prototype.clear=function(){this.__entries__.splice(0)},e.prototype.forEach=function(t,e){void 0===e&&(e=null);for(var n=0,r=this.__entries__;n<r.length;n++){var i=r[n];t.call(e,i[1],i[0])}},e}()}(),a="undefined"!=typeof window&&"undefined"!=typeof document&&window.document===document,c="undefined"!=typeof global&&global.Math===Math?global:"undefined"!=typeof self&&self.Math===Math?self:"undefined"!=typeof window&&window.Math===Math?window:Function("return this")(),u="function"==typeof requestAnimationFrame?requestAnimationFrame.bind(c):function(t){return setTimeout((function(){return t(Date.now())}),1e3/60)};var h=["top","right","bottom","left","width","height","size","weight"],f="undefined"!=typeof MutationObserver,d=function(){function t(){this.connected_=!1,this.mutationEventsAdded_=!1,this.mutationsObserver_=null,this.observers_=[],this.onTransitionEnd_=this.onTransitionEnd_.bind(this),this.refresh=function(t,e){var n=!1,r=!1,i=0;function o(){n&&(n=!1,t()),r&&a()}function s(){u(o)}function a(){var t=Date.now();if(n){if(t-i<2)return;r=!0}else n=!0,r=!1,setTimeout(s,e);i=t}return a}(this.refresh.bind(this),20)}return t.prototype.addObserver=function(t){~this.observers_.indexOf(t)||this.observers_.push(t),this.connected_||this.connect_()},t.prototype.removeObserver=function(t){var e=this.observers_,n=e.indexOf(t);~n&&e.splice(n,1),!e.length&&this.connected_&&this.disconnect_()},t.prototype.refresh=function(){this.updateObservers_()&&this.refresh()},t.prototype.updateObservers_=function(){var t=this.observers_.filter((function(t){return t.gatherActive(),t.hasActive()}));return t.forEach((function(t){return t.broadcastActive()})),t.length>0},t.prototype.connect_=function(){a&&!this.connected_&&(document.addEventListener("transitionend",this.onTransitionEnd_),window.addEventListener("resize",this.refresh),f?(this.mutationsObserver_=new MutationObserver(this.refresh),this.mutationsObserver_.observe(document,{attributes:!0,childList:!0,characterData:!0,subtree:!0})):(document.addEventListener("DOMSubtreeModified",this.refresh),this.mutationEventsAdded_=!0),this.connected_=!0)},t.prototype.disconnect_=function(){a&&this.connected_&&(document.removeEventListener("transitionend",this.onTransitionEnd_),window.removeEventListener("resize",this.refresh),this.mutationsObserver_&&this.mutationsObserver_.disconnect(),this.mutationEventsAdded_&&document.removeEventListener("DOMSubtreeModified",this.refresh),this.mutationsObserver_=null,this.mutationEventsAdded_=!1,this.connected_=!1)},t.prototype.onTransitionEnd_=function(t){var e=t.propertyName,n=void 0===e?"":e;h.some((function(t){return!!~n.indexOf(t)}))&&this.refresh()},t.getInstance=function(){return this.instance_||(this.instance_=new t),this.instance_},t.instance_=null,t}(),l=function(t,e){for(var n=0,r=Object.keys(e);n<r.length;n++){var i=r[n];Object.defineProperty(t,i,{value:e[i],enumerable:!1,writable:!1,configurable:!0})}return t},p=function(t){return t&&t.ownerDocument&&t.ownerDocument.defaultView||c},_=w(0,0,0,0);function v(t){return parseFloat(t)||0}function b(t){for(var e=[],n=1;n<arguments.length;n++)e[n-1]=arguments[n];return e.reduce((function(e,n){return e+v(t["border-"+n+"-width"])}),0)}function m(t){var e=t.clientWidth,n=t.clientHeight;if(!e&&!n)return _;var r=p(t).getComputedStyle(t),i=function(t){for(var e={},n=0,r=["top","right","bottom","left"];n<r.length;n++){var i=r[n],o=t["padding-"+i];e[i]=v(o)}return e}(r),o=i.left+i.right,s=i.top+i.bottom,a=v(r.width),c=v(r.height);if("border-box"===r.boxSizing&&(Math.round(a+o)!==e&&(a-=b(r,"left","right")+o),Math.round(c+s)!==n&&(c-=b(r,"top","bottom")+s)),!function(t){return t===p(t).document.documentElement}(t)){var u=Math.round(a+o)-e,h=Math.round(c+s)-n;1!==Math.abs(u)&&(a-=u),1!==Math.abs(h)&&(c-=h)}return w(i.left,i.top,a,c)}var y="undefined"!=typeof SVGGraphicsElement?function(t){return t instanceof p(t).SVGGraphicsElement}:function(t){return t instanceof p(t).SVGElement&&"function"==typeof t.getBBox};function g(t){return a?y(t)?function(t){var e=t.getBBox();return w(0,0,e.width,e.height)}(t):m(t):_}function w(t,e,n,r){return{x:t,y:e,width:n,height:r}}var O=function(){function t(t){this.broadcastWidth=0,this.broadcastHeight=0,this.contentRect_=w(0,0,0,0),this.target=t}return t.prototype.isActive=function(){var t=g(this.target);return this.contentRect_=t,t.width!==this.broadcastWidth||t.height!==this.broadcastHeight},t.prototype.broadcastRect=function(){var t=this.contentRect_;return this.broadcastWidth=t.width,this.broadcastHeight=t.height,t},t}(),E=function(t,e){var n,r,i,o,s,a,c,u=(r=(n=e).x,i=n.y,o=n.width,s=n.height,a="undefined"!=typeof DOMRectReadOnly?DOMRectReadOnly:Object,c=Object.create(a.prototype),l(c,{x:r,y:i,width:o,height:s,top:i,right:r+o,bottom:s+i,left:r}),c);l(this,{target:t,contentRect:u})},A=function(){function t(t,e,n){if(this.activeObservations_=[],this.observations_=new s,"function"!=typeof t)throw new TypeError("The callback provided as parameter 1 is not a function.");this.callback_=t,this.controller_=e,this.callbackCtx_=n}return t.prototype.observe=function(t){if(!arguments.length)throw new TypeError("1 argument required, but only 0 present.");if("undefined"!=typeof Element&&Element instanceof Object){if(!(t instanceof p(t).Element))throw new TypeError('parameter 1 is not of type "Element".');var e=this.observations_;e.has(t)||(e.set(t,new O(t)),this.controller_.addObserver(this),this.controller_.refresh())}},t.prototype.unobserve=function(t){if(!arguments.length)throw new TypeError("1 argument required, but only 0 present.");if("undefined"!=typeof Element&&Element instanceof Object){if(!(t instanceof p(t).Element))throw new TypeError('parameter 1 is not of type "Element".');var e=this.observations_;e.has(t)&&(e.delete(t),e.size||this.controller_.removeObserver(this))}},t.prototype.disconnect=function(){this.clearActive(),this.observations_.clear(),this.controller_.removeObserver(this)},t.prototype.gatherActive=function(){var t=this;this.clearActive(),this.observations_.forEach((function(e){e.isActive()&&t.activeObservations_.push(e)}))},t.prototype.broadcastActive=function(){if(this.hasActive()){var t=this.callbackCtx_,e=this.activeObservations_.map((function(t){return new E(t.target,t.broadcastRect())}));this.callback_.call(t,e,t),this.clearActive()}},t.prototype.clearActive=function(){this.activeObservations_.splice(0)},t.prototype.hasActive=function(){return this.activeObservations_.length>0},t}(),M="undefined"!=typeof WeakMap?new WeakMap:new s,z=function t(e){if(!(this instanceof t))throw new TypeError("Cannot call a class as a function.");if(!arguments.length)throw new TypeError("1 argument required, but only 0 present.");var n=d.getInstance(),r=new A(e,n,this);M.set(this,r)};["observe","unobserve","disconnect"].forEach((function(t){z.prototype[t]=function(){var e;return(e=M.get(this))[t].apply(e,arguments)}}));var x=void 0!==c.ResizeObserver?c.ResizeObserver:z;function L(t,e){var n="undefined"!=typeof Symbol&&t[Symbol.iterator]||t["@@iterator"];if(n)return(n=n.call(t)).next.bind(n);if(Array.isArray(t)||(n=function(t,e){if(!t)return;if("string"==typeof t)return S(t,e);var n=Object.prototype.toString.call(t).slice(8,-1);"Object"===n&&t.constructor&&(n=t.constructor.name);if("Map"===n||"Set"===n)return Array.from(t);if("Arguments"===n||/^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n))return S(t,e)}(t))||e&&t&&"number"==typeof t.length){n&&(t=n);var r=0;return function(){return r>=t.length?{done:!0}:{done:!1,value:t[r++]}}}throw new TypeError("Invalid attempt to iterate non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.")}function S(t,e){(null==e||e>t.length)&&(e=t.length);for(var n=0,r=new Array(e);n<e;n++)r[n]=t[n];return r}var T="undefined"==typeof window,k=function(t){for(var e,n=L(t);!(e=n()).done;){var r=e.value.target.__resizeListeners__||[];r.length&&r.forEach((function(t){t()}))}},j={name:"BCharts",props:{width:{type:String,default:"100%"},height:{type:String,default:"350px"},options:{type:Object,required:!0}},computed:{wrapStyle:function(){return{width:this.width,height:this.height}}},setup:function(t){var n=e.ref(null),r=null,s=null;function a(){r&&(r.dispose(),r=null),r=i.init(n.value),u(t.options)}function c(){r&&r.resize()}function u(t){r&&r.setOption(t)}function h(){r&&r.clear()}return e.onMounted((function(){var t,e;a(),s=o(c,100),t=n.value,e=s,!T&&t&&(t.__resizeListeners__||(t.__resizeListeners__=[],t.__ro__=new x(k),t.__ro__.observe(t)),t.__resizeListeners__.push(e))})),e.onBeforeUnmount((function(){var t,e;t=n.value,e=s,t&&t.__resizeListeners__&&(t.__resizeListeners__.splice(t.__resizeListeners__.indexOf(e),1),t.__resizeListeners__.length||t.__ro__.disconnect()),r&&(r.dispose(),r=null)})),e.watch((function(){return t.options}),(function(t){u(t)}),{deep:!0}),{elRef:n,resize:c,init:a,getInstance:function(){return r},refresh:function(){h(),u(t.options)},clear:h,setOptions:u,dispatchAction:function(t){r&&r.dispatchAction(t)},showLoading:function(t){r&&r.showLoading(t)},hideLoading:function(){r&&r.hideLoading()}}}};function R(t){void 0===t&&(t="default");var e="";switch(t){case"primary":e="#1089ff";break;case"success":e="#52c41a";break;case"warning":e="#fa8c16";break;case"danger":e="#f5222d";break;case"default":e="#35495E";break;default:e=t}return e}j.render=function(t,n,r,i,o,s){return e.openBlock(),e.createElementBlock("div",{class:"bin-charts-next",ref:"elRef",style:e.normalizeStyle(s.wrapStyle)},null,4)},j.__file="src/components/charts/charts.vue",j.install=function(t){t.component(j.name,j)};var D=function(t,e,n,r,i,o){void 0===r&&(r="primary"),void 0===i&&(i="20px"),void 0===o&&(o="#999"),console.log("%c"+t.toUpperCase()+" %cV"+e+" "+n,"color: "+R(r)+";font-weight: 500;font-size: "+i+";font-family: Source Sans Pro,Helvetica Neue,Arial,sans-serif;","color: "+o+";")},B="bin-charts-next",C="1.1.0",q="https://wangbin3162.gitee.io/bin-charts-next/",I={version:C,install:function(t,e){return void 0===e&&(e={}),t.component(j.name,j),e.disabledDoc||D(B,C,q,"#11afaf"),t}};return t.Charts=j,t.default=I,Object.defineProperty(t,"__esModule",{value:!0}),t}({},Vue,echarts);