"use strict";

exports.__esModule = true;
exports.domId = exports.datasetTrans = void 0;

/**
 * 约定格式转echart5-dataset格式
 * @param dataArray[Array] 必传，前后端约定图表通用格式
 * @param legendArray[Array] 必传，legend数组，长度应与dataArray一致
 * @return echart5-dataset格式，详见：https://echarts.apache.org/handbook/zh/concepts/dataset
 * */
var datasetTrans = function datasetTrans(dataArray, legendArray) {
  // 列头
  var colNames = ['product'].concat(dataArray.map(function (e, i) {
    return legendArray[i] || "legend_" + i;
  }));
  var source = []; // 约定格式校验

  if (dataArray[0] && Array.isArray(dataArray[0].label)) {
    source = dataArray[0].label.map(function (label, labelIndex) {
      return [label].concat(dataArray.map(function (data) {
        return data.value[labelIndex] || 0;
      }));
    });
  }

  return [colNames].concat(source);
};
/**
 * 生成随机DOM Id
 * */


exports.datasetTrans = datasetTrans;

var domId = function domId(prefix) {
  return (prefix && prefix.split ? prefix.trim() : 'dom') + "_" + parseInt(Math.random() * 1e5, 10);
};

exports.domId = domId;