UNPKG

@alicloud/cloud-charts

Version:

![](https://img.shields.io/npm/v/@alicloud/cloud-charts?color=%23ff8200)

73 lines (69 loc) 2.55 kB
"use strict"; exports.__esModule = true; exports.processFinalData = processFinalData; exports.runDataRules = runDataRules; var _lodash = require("lodash"); // 统一数据处理 function runDataRules(data, config) { var sourceData = (0, _lodash.cloneDeep)(data); if (Array.isArray(sourceData)) { var _config$yAxis; var dataList = sourceData === null || sourceData === void 0 ? void 0 : sourceData.map(function (el) { return el.y || (el === null || el === void 0 ? void 0 : el.y0) || (el === null || el === void 0 ? void 0 : el.y1); }); var maxDecimals = 0; var minDecimals = 4; dataList === null || dataList === void 0 ? void 0 : dataList.forEach(function (number) { var _number$toString; if (number && number !== null && number !== void 0 && (_number$toString = number.toString()) !== null && _number$toString !== void 0 && _number$toString.includes('.')) { // 将数字转换为字符串,然后查找小数点后的字符长度 var decimals = number.toString().split('.')[1] ? number.toString().split('.')[1].length : 0; // 更新最大小数位数 if (decimals > maxDecimals) { maxDecimals = decimals; } if (decimals < minDecimals) { minDecimals = decimals; } } }); // 兜底6位 if (maxDecimals > 6) { maxDecimals = 6; } if (!((_config$yAxis = config.yAxis) !== null && _config$yAxis !== void 0 && _config$yAxis.decimal) && !(config !== null && config !== void 0 && config.closeDataRules) && maxDecimals !== 0) { config.decimal = maxDecimals; if (!Array.isArray(config.yAxis)) { if (config.yAxis) { config.yAxis.decimal = maxDecimals; } else { config.yAxis = { decimal: maxDecimals }; } } } } return { data: data, config: config }; } // 后置数据处理 function processFinalData(chartObj, data, config) { var chartRule = chartObj.chartRule; var finalConfig = config; var finalData = data; // 增加预处理数据 if (chartRule !== null && chartRule !== void 0 && chartRule.processData) { var _chartRule$processDat = chartRule === null || chartRule === void 0 ? void 0 : chartRule.processData(data, config), targetData = _chartRule$processDat.data, targetConfig = _chartRule$processDat.config; finalConfig = (0, _lodash.merge)({}, config, targetConfig); finalData = targetData; } return { data: finalData, config: finalConfig }; }