@alicloud/cloud-charts
Version:

127 lines (104 loc) • 3.21 kB
JavaScript
;
exports.__esModule = true;
exports["default"] = chartLog;
exports.getLog = getLog;
exports.themeLog = themeLog;
exports.track = track;
exports.test = test;
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) {
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]['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] !== false;
/**
* 打点控制函数
*
* @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 () {
// 规则计算部分
if (testable) {
var chartRulesResult = (0, _postMessage.calcChartScore)(logMap); // 方便图表获取质量分数
// 增加一个当前统计的图表数量
window[_constants.FullQualityName] = chartRulesResult;
(0, _postMessage.postMessage)(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;
}
}, 6000);
function warn(component, info) {
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));
}