UNPKG

bytev-charts-beta1.0

Version:

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

194 lines (162 loc) 7.36 kB
import _Reflect$construct from "@babel/runtime-corejs2/core-js/reflect/construct"; import _classCallCheck from "@babel/runtime-corejs2/helpers/classCallCheck"; import _createClass from "@babel/runtime-corejs2/helpers/createClass"; import _assertThisInitialized from "@babel/runtime-corejs2/helpers/assertThisInitialized"; import _get from "@babel/runtime-corejs2/helpers/get"; import _inherits from "@babel/runtime-corejs2/helpers/inherits"; import _possibleConstructorReturn from "@babel/runtime-corejs2/helpers/possibleConstructorReturn"; import _getPrototypeOf from "@babel/runtime-corejs2/helpers/getPrototypeOf"; import _defineProperty from "@babel/runtime-corejs2/helpers/defineProperty"; import _JSON$stringify from "@babel/runtime-corejs2/core-js/json/stringify"; import _Object$assign from "@babel/runtime-corejs2/core-js/object/assign"; import "core-js/modules/es.array.concat.js"; import "core-js/modules/es.array.sort.js"; import "core-js/modules/es.regexp.exec.js"; import "core-js/modules/es.string.replace.js"; import "core-js/modules/es.array.for-each.js"; import "core-js/modules/es.object.to-string.js"; import "core-js/modules/web.dom-collections.for-each.js"; import "core-js/modules/es.function.name.js"; function _createSuper(Derived) { var hasNativeReflectConstruct = _isNativeReflectConstruct(); return function _createSuperInternal() { var Super = _getPrototypeOf(Derived), result; if (hasNativeReflectConstruct) { var NewTarget = _getPrototypeOf(this).constructor; result = _Reflect$construct(Super, arguments, NewTarget); } else { result = Super.apply(this, arguments); } return _possibleConstructorReturn(this, result); }; } function _isNativeReflectConstruct() { if (typeof Reflect === "undefined" || !_Reflect$construct) return false; if (_Reflect$construct.sham) return false; if (typeof Proxy === "function") return true; try { Boolean.prototype.valueOf.call(_Reflect$construct(Boolean, [], function () {})); return true; } catch (e) { return false; } } import DoughnutLeftRightComponent from "../DoughnutLeftRightComponent.class.js"; /* * 玉珏图 径向占比图 * */ var RadialPieGraph = /*#__PURE__*/function (_DoughnutLeftRightCom) { _inherits(RadialPieGraph, _DoughnutLeftRightCom); var _super = _createSuper(RadialPieGraph); function RadialPieGraph() { var _this; _classCallCheck(this, RadialPieGraph); for (var _len = arguments.length, args = new Array(_len), _key = 0; _key < _len; _key++) { args[_key] = arguments[_key]; } _this = _super.call.apply(_super, [this].concat(args)); _defineProperty(_assertThisInitialized(_this), "name", 'RadialPieGraph'); return _this; } _createClass(RadialPieGraph, [{ key: "buildByteVModel", value: function buildByteVModel() { var _this$byteVModel; _get(_getPrototypeOf(RadialPieGraph.prototype), "buildByteVModel", this).call(this); this.byteVModel.tooltip = { show: false }; // let style = this.byteVModel.legend.textStyle // style.padding = -10 // style.rich.name.padding[3] = 20 // style.rich.name.borderRadius = 0 //切换皮肤时判断之前是否有自定义radius var radius = ((_this$byteVModel = this.byteVModel) === null || _this$byteVModel === void 0 ? void 0 : _this$byteVModel.radius) || ''; this.byteVModel.radius = radius ? radius : this.theme.series.doughnutThinShadowRadius; } }, { key: "setRadiusByOption", value: function setRadiusByOption() { _get(_getPrototypeOf(RadialPieGraph.prototype), "setRadiusByOption", this).call(this); this.theme.series.convertRadialBarGraphRadius(this.byteVModel.radius); } }, { key: "setData", value: function setData(data) { var _this2 = this; _get(_getPrototypeOf(RadialPieGraph.prototype), "setData", this).call(this, data); var lengthAndTotal = this.getDataValueTotalAndNameMaxLength(data); //按大小排序(从大到小) data.sort(function (a, b) { return b.value - a.value; }); //取出最大值 var max = data[0].value; // for(let i = 0; i < data.length; i++){ // max = Math.max(max, data[i].value); // } this.byteVModel.series = []; var outer = this.theme.series.radialBarGraph.radius[1].replace('%', '') - 0; // 1 64 // 2 32 // 4 16 // 8 8 // 16 4 // 32 2 // 64 1 var n = 64 / data.length; data.forEach(function (m, i) { // m.per = ((m.value-0) / lengthAndTotal.total * 100).toFixed(2) m.per = _this2.zeroPer(m.value, lengthAndTotal.total); //放每个玉环的背景 var bg = JSON.parse(_JSON$stringify(_this2.theme.series.radialBarGraphBackGround)); bg.radius = [outer - n / 2 + '%', outer + '%']; var ser = JSON.parse(_JSON$stringify(_this2.theme.series.radialBarGraph)); ser.minAngle = 0; _Object$assign(ser.emphasis.label, { formatter: '{c}', position: 'inside', fontSize: '20', width: 2000 }); ser.emphasis.label.formatter = function (param) { // console.log(param) // // if(!param.data.value || !param.data.unit){ // if(!param.data.hasOwnProperty('value')){ // return '' // } return param.data.name + '\n\n' + param.data.per + '%' + '\n\n' + param.data.value + (param.data.unit || ''); }; ser.radius = [outer - n / 2 + '%', outer + '%']; outer -= n; m.itemStyle = { color: _this2.byteVModel.color[i % _this2.byteVModel.color.length] }; ser.data.push(m); // if(m.value < max){ // ser.data.push({ // value: max - m.value, // //name: m.name, // //标记是分割线 // spilt: true, // cursor: "auto", // itemStyle: { // color: 'transparent' // }, // }) // } //拼接放置补位的部分 var added = JSON.parse(_JSON$stringify(m)); _Object$assign(added, { // value: m.value / (m.per/100) - m.value, value: lengthAndTotal.total - m.value + lengthAndTotal.total * 0.25, itemStyle: { // color: 'red', color: 'transparent' }, label: { show: false }, emphasis: { label: { show: false } }, tooltip: { show: false } }); ser.data.push(added); // ser.data.push({ // value: 0, // //name: m.name, // //标记是分割线 // spilt: true, // cursor: "auto", // itemStyle: { color: 'transparent' }, // label: { show: false }, // emphasis: { // label: { show: false } // }, // tooltip: { show: false } // }) _this2.byteVModel.series.push(ser, bg); }); this.setCenterByOption(this.byteVModel.series); this.setRadiusByOption(this.byteVModel.series); this.componentInstance.setOption(this.byteVModel, true); } }]); return RadialPieGraph; }(DoughnutLeftRightComponent); export { RadialPieGraph as default };