UNPKG

@alicloud/cloud-charts

Version:

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

122 lines (116 loc) 3.74 kB
"use strict"; exports.__esModule = true; exports["default"] = chartLog; exports.getLog = getLog; exports.test = test; exports.themeLog = themeLog; exports.track = track; exports.warn = warn; var _platform = require("./platform"); var _constants = require("../constants"); var _postMessage = require("./postMessage"); /** * 日志记录 * * 包含 chartLog getLog 方法 * */ var logMap = {}; /** * chartLog 图表日志 * * @param {string} name 图表名称 * @param {string} logType 单次日志类型 * */ function chartLog(name, logType, logInfo) { var _logMap$name$renderTi; if (!logMap[name]) { logMap[name] = { init: 0, rulesInfo: [], configInfo: [], renderTimeArray: [] }; } if (logType === 'init') { logMap[name][logType] += 1; } else if (logType === 'rulesInfo') { var chartClass = _constants.FullCrossName + " " + name; logMap[name][logType].push({ domInfo: { tagName: 'div', className: chartClass, selector: logInfo.selector }, checkItem: logInfo.checkItem, errorInfo: logInfo.errorInfo }); } else if (logType === 'configInfo') { logMap[name][logType].push(logInfo); } else if (logType === 'renderTime' && ((_logMap$name$renderTi = logMap[name]['renderTimeArray'].filter(function (el) { return el.chartId === logInfo.chartId; })) === null || _logMap$name$renderTi === void 0 ? void 0 : _logMap$name$renderTi.length) === 0) { // 需要增加不重复的逻辑,只统计初次渲染的时间 logMap[name]['renderTimeArray'].push(logInfo); } } function getLog() { return logMap; } var currentTheme = ''; function themeLog(name) { currentTheme = name; } var trackable = window[_constants.FullTrackName] !== false; var testable = window[_constants.FullTestName] === true; /** * 打点控制函数 * * @param {bool} enable 是否开启打点 * */ function track(enable) { // 新版本中 G2 不再打点,所以关闭该指令 // G2.track(enable); // F2.track(enable); trackable = enable; } /** * test控制函数 * * @param {bool} enable 是否开启打点 * */ function test(enable) { testable = enable; } // 打点逻辑,使用黄金令箭 var logUrl = "//gm.mmstat.com/" + _constants.TrackName; setTimeout(function () { // 规则计算部分 var chartRulesResult = (0, _postMessage.calcChartScore)(logMap); window[_constants.FullQualityName] = chartRulesResult; if (testable) { // 方便图表获取质量分数 // 增加一个当前统计的图表数量 (0, _postMessage.postMessageForChartsInfo)(chartRulesResult); } // 打点部分 if (trackable && process.env.NODE_ENV === 'production') { var chartInit = Object.keys(logMap).map(function (name) { var chartLog = logMap[name]; return name + ":" + chartLog.init; }).join(','); var image = new Image(); // 统计 版本、主题、当前域名、图表初始化次数 image.src = logUrl + "?version=" + _constants.VERSION + "&theme=" + (currentTheme || _constants.THEME) + "&t=" + Date.now() + "&host=" + (location && location.host) + "&chartinit=" + chartInit + "&uamobile=" + _platform.isMobile + "&totalChart=" + (chartRulesResult.chartInfo.chartRealSum || 0).toString(); } }, 6000); function warn(component, info) { /** -- teamix debugger start -- **/ if (!window[_constants.FullConsoleName]) { var _console; for (var _len = arguments.length, other = new Array(_len > 2 ? _len - 2 : 0), _key = 2; _key < _len; _key++) { other[_key - 2] = arguments[_key]; } (_console = console).warn.apply(_console, ["[" + _constants.FullCamelName + "] " + component + ":", info].concat(other)); } /** -- teamix debugger end -- **/ }