UNPKG

wetrade-design

Version:

一款多语言支持Vue3的UI框架

73 lines (71 loc) 4.7 kB
"use strict"; var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault"); Object.defineProperty(exports, "__esModule", { value: true }); exports.pieLegendFormatter = pieLegendFormatter; exports.pieTooltipFormatter = pieTooltipFormatter; var _lodash = _interopRequireDefault(require("lodash")); var _bignumber = _interopRequireDefault(require("bignumber.js")); var _wetradeTools = require("wetrade-tools"); var $bn = _bignumber.default; // 饼图图例处理 function pieLegendFormatter(ev) { var props = ev.props; var tarValue = 0; var tarObj = ev.list.find(function (t) { return t.name === (ev === null || ev === void 0 ? void 0 : ev.name); //获取当前value }); tarValue = tarObj.value; //获取当前占比 var ratio = props.isValueComputed ? tarValue : new $bn(ev.total > 0 ? new $bn(tarValue).div(ev.total).toNumber() : new $bn(1).div(ev.list.length).toNumber()).times(100).toNumber(); var arr = ['{a|' + (ev === null || ev === void 0 ? void 0 : ev.name) + '}', props.originalValue ? '{b|' + (0, _wetradeTools.inThanMinOrMax)({ value: tarValue, decimal: props.digits, sign: props.showThousandSign }) + '}' : '', props.accountedFor ? '{c|' + (0, _wetradeTools.inThanMinOrMax)({ value: ratio || 0, decimal: props.digits, isPercent: true }) + '}' : '']; var res = arr.join(''); return res; } // 饼图tooltip浮层处理 function pieTooltipFormatter(ev) { var _ev$v, _name, _ev$v8, _ev$v9, _ev$v10; var props = ev.props; var name = (_ev$v = ev.v) === null || _ev$v === void 0 ? void 0 : _ev$v.name; var findIndexs = (_name = name) === null || _name === void 0 ? void 0 : _name.indexOf('['); if (findIndexs > -1 && props.isLabelRemoveId) { var _name2; name = (_name2 = name) === null || _name2 === void 0 ? void 0 : _name2.substring(0, findIndexs); } var symbolVal = props.originalValue || props.accountedFor ? ':' : ''; // 自定义,显示原值,值为null则不显示,需要外层处理好数值 if (props.customTooltip) { var _ev$v2, _ev$v3, _ev$v4, _ev$v5, _ev$v5$data, _ev$v6, _ev$v6$data; var _list = "<div>" + "<i style=\"background-color: ".concat((_ev$v2 = ev.v) === null || _ev$v2 === void 0 ? void 0 : _ev$v2.color, ";display: inline-block;width: 8px;height: 8px;border-radius: 50%; margin-right: 6px; vertical-align: middle;\"></i>") + "<span style=\"display: inline-block; line-height: 18px; vertical-align: middle;\">" + "".concat(name) + "".concat(props.originalValue && !_lodash.default.isNil((_ev$v3 = ev.v) === null || _ev$v3 === void 0 ? void 0 : _ev$v3.value) ? symbolVal + '&nbsp;' + ((_ev$v4 = ev.v) === null || _ev$v4 === void 0 ? void 0 : _ev$v4.value) : '') + "".concat(props.accountedFor && !_lodash.default.isNil((_ev$v5 = ev.v) === null || _ev$v5 === void 0 ? void 0 : (_ev$v5$data = _ev$v5.data) === null || _ev$v5$data === void 0 ? void 0 : _ev$v5$data.percent) ? '&nbsp;&nbsp;' + (((_ev$v6 = ev.v) === null || _ev$v6 === void 0 ? void 0 : (_ev$v6$data = _ev$v6.data) === null || _ev$v6$data === void 0 ? void 0 : _ev$v6$data.percent) || '') : '') + "</span></div>"; return "<div class=\"all_tooltip\">".concat(_list, "</div>"); } else if (props.toolTipPatchFunc) { // 是否自定义tooltip return props.toolTipPatchFunc(ev.v); } //获取当前占比 var tarValue = 0; var tarObj = ev.list.find(function (t) { var _ev$v7; return t.name === ((_ev$v7 = ev.v) === null || _ev$v7 === void 0 ? void 0 : _ev$v7.name); }); tarValue = (tarObj === null || tarObj === void 0 ? void 0 : tarObj.value) || 0; var ratio = props.isValueComputed ? tarValue : (ev.total > 0 ? new $bn(tarValue).div(ev.total) : new $bn(1).div(ev.list.length)).times(100).toNumber(); var list = "<div>" + "<i style=\"background-color: ".concat(ev.v.color, "; display: inline-block;width: 8px;height: 8px;border-radius: 50%; margin-right: 6px; vertical-align: middle;\"></i>") + "<span style=\"display: inline-block;line-height: 18px;vertical-align: middle;\">" + "".concat(name).concat(symbolVal, " ").concat(props.originalValue ? ((_ev$v8 = ev.v) === null || _ev$v8 === void 0 ? void 0 : _ev$v8.value) < 0.01 && ((_ev$v9 = ev.v) === null || _ev$v9 === void 0 ? void 0 : _ev$v9.value) > 0 ? '<0.01' : (0, _wetradeTools.numberFormat)((_ev$v10 = ev.v) === null || _ev$v10 === void 0 ? void 0 : _ev$v10.value, { decimal: props.digits, t: props.showThousandSign }) + props.unit : '') + "".concat(props.accountedFor ? '&nbsp;&nbsp;' + (0, _wetradeTools.inThanMinOrMax)({ value: ratio, decimal: props.digits, isPercent: true }) : '') + "</span> </div>"; return "<div class=\"all_tooltip\">".concat(list, "</div>"); }