UNPKG

bytev-charts-beta1.0

Version:

测试版-1.0,版本号为小版本; 基于echarts和JavaScript及ES6封装的一个可以直接调用的图表组件库,内置主题设计,简单快捷,且支持用户自定义配置; npm 安装方式: npm install bytev-charts 若启动提示还需额外install插件,则运行 npm install @babel/runtime-corejs2 即可;

120 lines (102 loc) 2.91 kB
import _classCallCheck from "@babel/runtime-corejs2/helpers/classCallCheck"; import _createClass from "@babel/runtime-corejs2/helpers/createClass"; import _defineProperty from "@babel/runtime-corejs2/helpers/defineProperty"; import "core-js/modules/web.timers.js"; /** * ByteVCharts周期定时器 */ var Interval = /*#__PURE__*/function () { function Interval() { _classCallCheck(this, Interval); _defineProperty(this, "timeout", 50); _defineProperty(this, "suspended", false); _defineProperty(this, "eventObj", {}); try { this.init(); } catch (e) { //TODO handle the exception console.warn(e); } } /** * 初始化周期定时器 */ _createClass(Interval, [{ key: "init", value: function init() { var _this = this; this.dispose(); window.ByteVChartsIntervalTimer = setInterval(function () { if (!_this.suspended) // console.log('.') for (var k in _this.eventObj) { _this.eventObj[k].currentTakt++; if (_this.eventObj[k].currentTakt >= _this.eventObj[k].takt) { var _this$eventObj$k, _this$eventObj$k$even; (_this$eventObj$k = _this.eventObj[k]) === null || _this$eventObj$k === void 0 ? void 0 : (_this$eventObj$k$even = _this$eventObj$k.event) === null || _this$eventObj$k$even === void 0 ? void 0 : _this$eventObj$k$even.call(_this$eventObj$k); _this.eventObj[k].currentTakt = 0; } } }, this.timeout); } /** * 销毁周期定时器 */ }, { key: "dispose", value: function dispose() { this.eventObj = {}; clearInterval(window.ByteVChartsIntervalTimer); } /* * 暂停 * */ }, { key: "stop", value: function stop() { this.suspended = true; } /* * 继续 * */ }, { key: "play", value: function play() { this.suspended = false; } /** * 添加事件方法 * @param {String} key name or id 事件名称或id(将作为key保存在对象中) * @param {function} fun 事件函数 * @param {number} takt 间隔几毫秒执行一次(最少100毫秒) */ }, { key: "add", value: function add(key, fun, takt) { takt = takt || this.timeout; if (key && fun) this.eventObj[key] = { takt: takt / this.timeout, currentTakt: 0, event: fun }; } /** * 删除事件 * @param {String} key name or id 要删除的事件名称或id(从保存在对象中删除该命名的key) */ }, { key: "remove", value: function remove(key) { if (key) delete this.eventObj[key]; } /** * 删除所有事件 */ }, { key: "removeAll", value: function removeAll() { this.eventObj = {}; } }]); return Interval; }(); export { Interval as default };