'use strict';

Object.defineProperty(exports, '__esModule', { value: true });

function _interopDefault (ex) { return (ex && (typeof ex === 'object') && 'default' in ex) ? ex['default'] : ex; }

var echarts = _interopDefault(require('echarts/lib/echarts'));
require('echarts/lib/component/tooltip');
require('echarts/lib/component/legend');
require('echarts/lib/component/title');
require('echarts/lib/chart/bar');
require('echarts/lib/chart/line');
require('echarts/lib/chart/pie');
require('echarts/lib/chart/scatter');
require('echarts/lib/chart/funnel');
require('echarts/lib/chart/radar');

var SIGN = '@_@';
var getLabelName = function getLabelName(item) {
  return item.split(SIGN)[0];
}; // TODO: delete
var getLegendName = function getLegendName(item) {
  return item.split(SIGN)[0];
};
var tipPointStyle = [// TODO: delete
'display: inline-block;', 'width: 10px;', 'height: 10px;', 'border-radius: 50%;', 'margin-right:2px;'].join('');

var itemPoint = function itemPoint(color) {
  return ['<span style="', 'background-color:' + color + ';', 'display: inline-block;', 'width: 10px;', 'height: 10px;', 'border-radius: 50%;', 'margin-right:2px;', '"></span>'].join('');
};

echarts.registerTheme('ve-chart', {
  color: ['#19d4ae', '#5ab1ef', '#fa6e86', '#ffb980', '#0067a6', '#c4b4e4', '#d87a80', '#9cbbff', '#d9d0c7', '#87a997', '#d49ea2', '#5b4947', '#7ba3a8'],
  categoryAxis: {
    axisLine: { show: false },
    axisTick: { show: false },
    splitLine: { show: false }
  },
  valueAxis: {
    axisLine: { show: false }
  },
  line: {
    smooth: true
  },
  grid: {
    left: 60,
    right: 60,
    top: 60,
    bottom: 60
  }
});

var numberFormat = function numberFormat(val) {
  var digits = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : 2;

  if (isNaN(+val)) return val;

  var symbolMap = [{ value: 1E18, symbol: 'E' }, { value: 1E15, symbol: 'P' }, { value: 1E12, symbol: 'T' }, { value: 1E9, symbol: 'B' }, { value: 1E6, symbol: 'M' }, { value: 1E3, symbol: 'k' }];

  for (var i = 0; i < symbolMap.length; i++) {
    if (Math.abs(val) >= symbolMap[i].value) {
      return (val / symbolMap[i].value).toFixed(digits) + symbolMap[i].symbol;
    }
  }

  return val.toString();
};

var formatTausends = function formatTausends(num) {
  return String(num).replace(/^(\s+|-)?\d+(?=.?\d*($|\s))/g, function (m) {
    return m.replace(/(?=(?!\b)(\d{3})+$)/g, ',');
  });
};

var getFormated = function getFormated(val, type) {
  switch (type) {
    case 'KMB':
      return numberFormat(val);
    case 'percent':
      return (val * 100).toFixed(2) + '%';
    case 'normal':
      return formatTausends(val);
    default:
      return val;
  }
};

var getLineKB = function getLineKB(s, v) {
  var result = [];
  result[0] = (s[1] - s[0]) / (v[1] - v[0]);
  result[1] = s[0] - result[0] * v[0];
  return result;
};

var _slicedToArray = function () { function sliceIterator(arr, i) { var _arr = []; var _n = true; var _d = false; var _e = undefined; try { for (var _i = arr[Symbol.iterator](), _s; !(_n = (_s = _i.next()).done); _n = true) { _arr.push(_s.value); if (i && _arr.length === i) break; } } catch (err) { _d = true; _e = err; } finally { try { if (!_n && _i["return"]) _i["return"](); } finally { if (_d) throw _e; } } return _arr; } return function (arr, i) { if (Array.isArray(arr)) { return arr; } else if (Symbol.iterator in Object(arr)) { return sliceIterator(arr, i); } else { throw new TypeError("Invalid attempt to destructure non-iterable instance"); } }; }();

function _defineProperty(obj, key, value) { if (key in obj) { Object.defineProperty(obj, key, { value: value, enumerable: true, configurable: true, writable: true }); } else { obj[key] = value; } return obj; }

var dataHandler = {
  getBarLegends: function getBarLegends(_ref) {
    var measures = _ref.measures,
        axisSite = _ref.axisSite,
        meaAxisType = _ref.meaAxisType,
        isColumn = _ref.isColumn;

    var legends = [];

    var formatter = getLabelName;
    var secondAxis = isColumn ? axisSite.right : axisSite.top;
    measures.forEach(function (measure) {
      var legendItem = ~secondAxis.indexOf(measure) ? '' + measure + SIGN + meaAxisType[1] : '' + measure + SIGN + meaAxisType[0];
      legends.push(legendItem);
    });

    return legends.length ? { data: legends, formatter: formatter } : false;
  },
  getBarDimAxis: function getBarDimAxis(_ref2) {
    var rows = _ref2.rows,
        dimAxisName = _ref2.dimAxisName,
        dimensions = _ref2.dimensions;

    return dimensions.map(function (dimension) {
      return {
        type: 'category',
        name: dimAxisName || dimension,
        nameLocation: 'middle',
        nameGap: 22,
        data: rows.map(function (row) {
          return row[dimension];
        }),
        axisLabel: {
          formatter: function formatter(v) {
            return String(v);
          }
        }
      };
    });
  },
  getBarMeaAxis: function getBarMeaAxis(_ref3) {
    var columns = _ref3.columns,
        meaAxisName = _ref3.meaAxisName,
        measures = _ref3.measures,
        meaAxisType = _ref3.meaAxisType;

    var meaAxisBase = { type: 'value', axisTick: { show: false } };
    var meaAxis = [];

    var _loop = function _loop(i) {
      if (meaAxisType[i]) {
        meaAxis[i] = Object.assign({}, meaAxisBase, {
          axisLabel: {
            formatter: function formatter(val) {
              return getFormated(val, meaAxisType[i]);
            }
          }
        });
      } else {
        meaAxis[i] = Object.assign({}, meaAxisBase);
      }
      meaAxis[i].name = meaAxisName[i] || '';
    };

    for (var i = 0; i < 2; i++) {
      _loop(i);
    }

    return meaAxis;
  },
  getBarTooltip: function getBarTooltip() {
    return {
      trigger: 'axis',
      formatter: function formatter(items) {
        var tpl = [];
        var title = String(items[0].name).split(SIGN)[0];
        tpl.push(title + '<br>');
        items.forEach(function (item) {
          var _item$seriesName$spli = item.seriesName.split(SIGN),
              _item$seriesName$spli2 = _slicedToArray(_item$seriesName$spli, 2),
              name = _item$seriesName$spli2[0],
              type = _item$seriesName$spli2[1];

          tpl.push(itemPoint(item.color));
          tpl.push(name + ': ');
          tpl.push(getFormated(item.value, type));
          tpl.push('<br>');
        });

        return tpl.join('');
      }
    };
  },
  getStackMap: function getStackMap(stack) {
    var stackMap = {};
    Object.keys(stack).forEach(function (item) {
      stack[item].forEach(function (name) {
        stackMap[name] = item;
      });
    });
    return stackMap;
  },
  getBarSeries: function getBarSeries(_ref4) {
    var rows = _ref4.rows,
        measures = _ref4.measures,
        stackMap = _ref4.stackMap,
        axisSite = _ref4.axisSite,
        meaAxisType = _ref4.meaAxisType,
        isColumn = _ref4.isColumn;

    var series = [];
    var seriesTemp = {};
    var secondAxis = isColumn ? axisSite.right : axisSite.top;
    var secondDimAxisIndex = isColumn ? 'yAxisIndex' : 'xAxisIndex';
    measures.forEach(function (measure) {
      seriesTemp[measure] = [];
    });
    rows.forEach(function (row) {
      measures.forEach(function (measure) {
        seriesTemp[measure].push(row[measure]);
      });
    });
    series = Object.keys(seriesTemp).map(function (item) {
      var itemName = ~secondAxis.indexOf(item) ? '' + item + SIGN + meaAxisType[1] : '' + item + SIGN + meaAxisType[0];
      var seriesItem = _defineProperty({
        name: itemName,
        type: 'bar',
        data: seriesTemp[item]
      }, secondDimAxisIndex, ~secondAxis.indexOf(item) ? '1' : '0');

      if (stackMap[item]) seriesItem.stack = stackMap[item];

      return seriesItem;
    });

    return series.length ? series : false;
  }
};
var bar = function bar(data, settings) {
  if (!data || !Array.isArray(data.columns) || !Array.isArray(data.rows)) return false;
  var columns = data.columns,
      rows = data.rows;
  var _settings$axisSite = settings.axisSite,
      axisSite = _settings$axisSite === undefined ? { top: [] } : _settings$axisSite,
      _settings$dimensions = settings.dimensions,
      dimensions = _settings$dimensions === undefined ? [columns[0]] : _settings$dimensions,
      _settings$stack = settings.stack,
      stack = _settings$stack === undefined ? {} : _settings$stack;

  var measures = columns.slice();
  if (settings.measures) {
    measures = settings.measures;
  } else {
    measures.splice(columns.indexOf(dimensions[0]), 1);
  }
  var meaAxisType = settings.xAxisType || ['normal', 'normal'];
  var meaAxisName = settings.xAxisName || [];
  var dimAxisName = settings.yAxisName || dimensions[0];
  var isColumn = false;

  var stackMap = stack ? dataHandler.getStackMap(stack) : {};
  var legend = dataHandler.getBarLegends({ measures: measures, axisSite: axisSite, meaAxisType: meaAxisType, isColumn: isColumn });
  var yAxis = dataHandler.getBarDimAxis({ rows: rows, dimAxisName: dimAxisName, dimensions: dimensions });
  var xAxis = dataHandler.getBarMeaAxis({ columns: columns, meaAxisName: meaAxisName, measures: measures, meaAxisType: meaAxisType });
  var series = dataHandler.getBarSeries({ rows: rows, measures: measures, stackMap: stackMap, axisSite: axisSite, meaAxisType: meaAxisType, isColumn: isColumn });
  var tooltip = dataHandler.getBarTooltip();
  var options = { legend: legend, yAxis: yAxis, series: series, xAxis: xAxis, tooltip: tooltip };
  return options;
};

var column = function column(data, settings) {
  if (!data || !Array.isArray(data.columns) || !Array.isArray(data.rows)) return false;
  var columns = data.columns,
      rows = data.rows;
  var _settings$axisSite2 = settings.axisSite,
      axisSite = _settings$axisSite2 === undefined ? { right: [] } : _settings$axisSite2,
      _settings$dimensions2 = settings.dimensions,
      dimensions = _settings$dimensions2 === undefined ? [columns[0]] : _settings$dimensions2,
      _settings$stack2 = settings.stack,
      stack = _settings$stack2 === undefined ? {} : _settings$stack2;

  var measures = columns.slice();
  if (settings.measures) {
    measures = settings.measures;
  } else {
    measures.splice(columns.indexOf(dimensions[0]), 1);
  }
  var meaAxisType = settings.yAxisType || ['normal', 'normal'];
  var meaAxisName = settings.yAxisName || [];
  var dimAxisName = settings.xAxisName || dimensions[0];
  var isColumn = true;

  var stackMap = stack ? dataHandler.getStackMap(stack) : {};
  var legend = dataHandler.getBarLegends({ measures: measures, axisSite: axisSite, meaAxisType: meaAxisType, isColumn: isColumn });
  var xAxis = dataHandler.getBarDimAxis({ rows: rows, dimAxisName: dimAxisName, dimensions: dimensions });
  var yAxis = dataHandler.getBarMeaAxis({ columns: columns, meaAxisName: meaAxisName, measures: measures, meaAxisType: meaAxisType });
  var series = dataHandler.getBarSeries({ rows: rows, measures: measures, stackMap: stackMap, axisSite: axisSite, meaAxisType: meaAxisType, isColumn: isColumn });
  var tooltip = dataHandler.getBarTooltip();
  var options = { legend: legend, yAxis: yAxis, series: series, xAxis: xAxis, tooltip: tooltip };
  return options;
};

var chartMixin = {
  props: {
    data: { type: [Object, Array], default: null },
    settings: { type: Object, default: function _default() {
        return {};
      }
    },
    width: { type: String, default: 'auto' },
    height: { type: String, default: '400px' },
    beforeConfig: { type: Function },
    afterConfig: { type: Function },
    events: { type: Object }
  },

  watch: {
    data: function data(v) {
      var dataKeys = Object.keys(v);
      var dataKeyProp = v.key;
      if (dataKeyProp && Array.isArray(dataKeyProp) && dataKeyProp.length || dataKeys.length) {
        this.dataHandler(v);
      }
    },

    settings: {
      deep: true,
      handler: function handler(v) {
        this.chartHandler = this.chartLib[v.type];
        this.dataHandler(this.data);
      }
    }
  },

  computed: {
    canvasStyle: function canvasStyle() {
      return { width: this.width, height: this.height };
    }
  },

  methods: {
    dataHandler: function dataHandler(data) {
      if (!this.chartHandler) return;
      if (this.beforeConfig) data = this.beforeConfig(data);
      var options = this.chartHandler(data, this.settings);
      if (Array.isArray(this.settings.color)) options.color = this.settings.color;
      if (this.settings.grid) options.grid = this.settings.grid;
      if (this.afterConfig) options = this.afterConfig(options);
      if (options) this.echarts.setOption(options, true);
    },
    init: function init() {
      if (this.echarts) return;
      this.echarts = this.echartsLib.init(this.$refs.canvas, 've-chart');
      if (this.data) this.dataHandler(this.data);
      if (this.events) this.bindEvents();
    },
    bindEvents: function bindEvents() {
      var _this = this;

      Object.keys(this.events).forEach(function (event) {
        _this.echarts.on(event, _this.events[event]);
      });
    }
  },

  mounted: function mounted() {
    var _this2 = this;

    this.$nextTick(function () {
      _this2.init();
      window.addEventListener('resize', _this2.echarts.resize);
    });
  },
  beforeDestory: function beforeDestory() {
    window.removeEventListener('resize', this.echarts.resize);
    this.echarts.dispose();
  }
};

var index = {
  render: function render() {
    var _vm = this;var _h = _vm.$createElement;var _c = _vm._self._c || _h;return _c('div', { ref: "canvas", style: _vm.canvasStyle });
  },
  staticRenderFns: [],
  name: 'VeBar',
  mixins: [chartMixin],
  created: function created() {
    this.chartHandler = bar;
    this.echartsLib = echarts;
  }
};

var column$1 = {
  render: function render() {
    var _vm = this;var _h = _vm.$createElement;var _c = _vm._self._c || _h;return _c('div', { ref: "canvas", style: _vm.canvasStyle });
  },
  staticRenderFns: [],
  name: 'VeColumn',
  mixins: [chartMixin],
  created: function created() {
    this.chartHandler = column;
    this.echartsLib = echarts;
  }
};

var _slicedToArray$1 = function () { function sliceIterator(arr, i) { var _arr = []; var _n = true; var _d = false; var _e = undefined; try { for (var _i = arr[Symbol.iterator](), _s; !(_n = (_s = _i.next()).done); _n = true) { _arr.push(_s.value); if (i && _arr.length === i) break; } } catch (err) { _d = true; _e = err; } finally { try { if (!_n && _i["return"]) _i["return"](); } finally { if (_d) throw _e; } } return _arr; } return function (arr, i) { if (Array.isArray(arr)) { return arr; } else if (Symbol.iterator in Object(arr)) { return sliceIterator(arr, i); } else { throw new TypeError("Invalid attempt to destructure non-iterable instance"); } }; }();

var dataHandler$1 = {
  getLineLegends: function getLineLegends(_ref) {
    var measures = _ref.measures,
        axisSite = _ref.axisSite,
        yAxisType = _ref.yAxisType;

    var legends = [];

    var formatter = getLegendName;

    measures.forEach(function (measure) {
      var legendItem = ~axisSite.right.indexOf(measure) ? '' + measure + SIGN + yAxisType[1] : '' + measure + SIGN + yAxisType[0];
      legends.push(legendItem);
    });

    return legends.length ? { data: legends, formatter: formatter } : false;
  },
  getLineXAxis: function getLineXAxis(_ref2) {
    var dimensions = _ref2.dimensions,
        rows = _ref2.rows,
        xAxisName = _ref2.xAxisName;

    return dimensions.map(function (dimension, index) {
      return {
        type: 'category',
        nameLocation: 'middle',
        nameGap: 22,
        name: xAxisName[index] || dimension,
        axisTick: { show: true, lineStyle: { color: '#eee' } },
        data: rows.map(function (row) {
          return row[dimension];
        }),
        axisLabel: {
          formatter: function formatter(v) {
            return String(v);
          }
        }
      };
    });
  },
  getLineSeries: function getLineSeries(_ref3) {
    var rows = _ref3.rows,
        axisSite = _ref3.axisSite,
        yAxisType = _ref3.yAxisType,
        dimensions = _ref3.dimensions,
        measures = _ref3.measures;

    var series = [];
    var dataTemp = {};
    measures.forEach(function (measure) {
      dataTemp[measure] = [];
    });
    rows.forEach(function (row) {
      measures.forEach(function (measure) {
        dataTemp[measure].push(row[measure] || 0);
      });
    });
    measures.forEach(function (measure) {
      var seriesItem = {
        name: measure,
        type: 'line',
        data: dataTemp[measure]
      };

      if (~axisSite.right.indexOf(measure)) {
        seriesItem.yAxisIndex = 1;
        seriesItem.name = '' + measure + SIGN + yAxisType[1];
      } else {
        seriesItem.yAxisIndex = 0;
        seriesItem.name = '' + measure + SIGN + yAxisType[0];
      }

      series.push(seriesItem);
    });
    return series.length ? series : false;
  },
  getLineYAxis: function getLineYAxis(_ref4) {
    var yAxisName = _ref4.yAxisName,
        yAxisType = _ref4.yAxisType;

    var yAxisBase = { type: 'value', axisTick: { show: false } };
    var yAxis = [];

    var _loop = function _loop(i) {
      if (yAxisType[i]) {
        yAxis[i] = Object.assign({}, yAxisBase, {
          axisLabel: {
            formatter: function formatter(val) {
              return getFormated(val, yAxisType[i]);
            }
          }
        });
      } else {
        yAxis[i] = Object.assign({}, yAxisBase);
      }
      yAxis[i].name = yAxisName[i] || '';
    };

    for (var i = 0; i < 2; i++) {
      _loop(i);
    }
    return yAxis;
  },
  getLineTooltip: function getLineTooltip() {
    return {
      trigger: 'axis',
      formatter: function formatter(items) {
        var tpl = [];
        tpl.push(items[0].name + '<br>');
        items.forEach(function (item) {
          var showData = void 0;

          var _item$seriesName$spli = item.seriesName.split(SIGN),
              _item$seriesName$spli2 = _slicedToArray$1(_item$seriesName$spli, 2),
              name = _item$seriesName$spli2[0],
              type = _item$seriesName$spli2[1];

          showData = getFormated(item.data, type);
          tpl.push(itemPoint(item.color));
          tpl.push(name + ': ' + showData);
          tpl.push('<br>');
        });
        return tpl.join('');
      }
    };
  }
};

var line = function line(data, settings) {
  if (!data || !Array.isArray(data.columns) || !Array.isArray(data.rows)) return false;
  var columns = data.columns,
      rows = data.rows;
  var _settings$axisSite = settings.axisSite,
      axisSite = _settings$axisSite === undefined ? { right: [] } : _settings$axisSite,
      _settings$yAxisType = settings.yAxisType,
      yAxisType = _settings$yAxisType === undefined ? ['normal', 'normal'] : _settings$yAxisType,
      _settings$yAxisName = settings.yAxisName,
      yAxisName = _settings$yAxisName === undefined ? [] : _settings$yAxisName,
      _settings$dimensions = settings.dimensions,
      dimensions = _settings$dimensions === undefined ? [columns[0]] : _settings$dimensions,
      _settings$xAxisName = settings.xAxisName,
      xAxisName = _settings$xAxisName === undefined ? dimensions : _settings$xAxisName;

  var measures = columns.slice();
  if (settings.measures) {
    measures = settings.measures;
  } else {
    measures.splice(columns.indexOf(dimensions[0]), 1);
  }
  var legend = dataHandler$1.getLineLegends({ measures: measures, axisSite: axisSite, yAxisType: yAxisType });
  var tooltip = dataHandler$1.getLineTooltip();
  var xAxis = dataHandler$1.getLineXAxis({ dimensions: dimensions, rows: rows, xAxisName: xAxisName });
  var yAxis = dataHandler$1.getLineYAxis({ yAxisName: yAxisName, yAxisType: yAxisType });
  var series = dataHandler$1.getLineSeries({ rows: rows, axisSite: axisSite, yAxisType: yAxisType, dimensions: dimensions, measures: measures });
  if (!legend || !xAxis || !series) return false;

  var options = { legend: legend, xAxis: xAxis, series: series, yAxis: yAxis, tooltip: tooltip };
  return options;
};

var index$1 = {
  render: function render() {
    var _vm = this;var _h = _vm.$createElement;var _c = _vm._self._c || _h;return _c('div', { ref: "canvas", style: _vm.canvasStyle });
  },
  staticRenderFns: [],
  name: 'VeLine',
  mixins: [chartMixin],
  created: function created() {
    this.chartHandler = line;
    this.echartsLib = echarts;
  }
};

var pieRadius = 100;
var ringRadius = [80, 100];
var pieOffsetY = 200;

var dataHandler$2 = {
  getPieSeries: function getPieSeries(args) {
    var rows = args.rows,
        dataType = args.dataType,
        percentShow = args.percentShow,
        dimension = args.dimension,
        measure = args.measure,
        radius = args.radius,
        offsetY = args.offsetY;


    var series = {
      type: 'pie',
      radius: radius,
      data: [],
      center: ['50%', offsetY]
    };
    if (percentShow) {
      series.label = {
        normal: {
          show: true,
          formatter: function formatter(item) {
            var tpl = [];
            tpl.push(item.name + ':');
            tpl.push(getFormated(item.value, dataType));
            tpl.push('(' + item.percent + '%)');
            return tpl.join(' ');
          }
        }
      };
    }
    series.data = rows.map(function (row) {
      return { name: row[dimension], value: row[measure] };
    });

    return series;
  },
  getPieLegend: function getPieLegend(_ref) {
    var rows = _ref.rows,
        dimension = _ref.dimension,
        legendLimit = _ref.legendLimit;

    var legend = rows.map(function (row) {
      return row[dimension];
    });
    return legend.length ? { data: legend, show: legend.length < legendLimit } : false;
  },
  getPieTooltip: function getPieTooltip(dataType) {
    return {
      formatter: function formatter(item) {
        var tpl = [];
        tpl.push(itemPoint(item.color));
        tpl.push(item.name + ':');
        tpl.push(getFormated(item.value, dataType));
        tpl.push('(' + item.percent + '%)');
        return tpl.join(' ');
      }
    };
  }
};

var pie = function pie(data, settings, isRing) {
  if (!data || !Array.isArray(data.columns) || !Array.isArray(data.rows)) return false;

  var columns = data.columns,
      rows = data.rows;
  var _settings$dataType = settings.dataType,
      dataType = _settings$dataType === undefined ? 'normal' : _settings$dataType,
      percentShow = settings.percentShow,
      _settings$dimension = settings.dimension,
      dimension = _settings$dimension === undefined ? columns[0] : _settings$dimension,
      _settings$measure = settings.measure,
      measure = _settings$measure === undefined ? columns[1] : _settings$measure,
      _settings$radius = settings.radius,
      radius = _settings$radius === undefined ? isRing ? ringRadius : pieRadius : _settings$radius,
      _settings$offsetY = settings.offsetY,
      offsetY = _settings$offsetY === undefined ? pieOffsetY : _settings$offsetY,
      _settings$legendLimit = settings.legendLimit,
      legendLimit = _settings$legendLimit === undefined ? 30 : _settings$legendLimit;


  var series = dataHandler$2.getPieSeries({
    rows: rows, dataType: dataType, percentShow: percentShow, dimension: dimension, measure: measure, radius: radius, offsetY: offsetY
  });
  var legend = dataHandler$2.getPieLegend({ rows: rows, dimension: dimension, legendLimit: legendLimit });
  var tooltip = dataHandler$2.getPieTooltip(dataType);
  if (!legend) return false;
  var options = { series: series, legend: legend, tooltip: tooltip };
  return options;
};

var ring = function ring(data, settings) {
  return pie(data, settings, true);
};

var index$2 = {
  render: function render() {
    var _vm = this;var _h = _vm.$createElement;var _c = _vm._self._c || _h;return _c('div', { ref: "canvas", style: _vm.canvasStyle });
  },
  staticRenderFns: [],
  name: 'VePie',
  mixins: [chartMixin],
  created: function created() {
    this.chartHandler = pie;
    this.echartsLib = echarts;
  }
};

var ring$1 = {
  render: function render() {
    var _vm = this;var _h = _vm.$createElement;var _c = _vm._self._c || _h;return _c('div', { ref: "canvas", style: _vm.canvasStyle });
  },
  staticRenderFns: [],
  name: 'VeRing',
  mixins: [chartMixin],
  created: function created() {
    this.chartHandler = ring;
    this.echartsLib = echarts;
  }
};

var dataHandler$3 = {
  getWaterfallTooltip: function getWaterfallTooltip(dataType) {
    return {
      trigger: 'axis',
      axisPointer: { type: 'shadow' },
      formatter: function formatter(items) {
        var item = items[1];
        return [item.name + '<br/>' + item.seriesName + ' :', '' + getFormated(item.value, dataType)].join('');
      }
    };
  },
  getWaterfallXAxis: function getWaterfallXAxis(data) {
    return {
      type: 'category',
      splitLine: { show: false },
      data: ['总计'].concat(Object.keys(data))
    };
  },
  getWaterfallYAxis: function getWaterfallYAxis(dataType) {
    return {
      type: 'value',
      axisTick: { show: false },
      axisLabel: {
        formatter: function formatter(val) {
          return getFormated(val, dataType);
        }
      }
    };
  },
  getWaterfallSeries: function getWaterfallSeries(data, dataType) {
    var seriesBase = { type: 'bar', stack: '总量' };
    var dataSum = Object.keys(data).reduce(function (pre, cur) {
      return pre + Number(data[cur]);
    }, 0).toFixed(2);
    var dataSumTemp = dataSum;
    var series = [];
    series.push(Object.assign({
      name: '辅助',
      itemStyle: {
        normal: { opacity: 0 },
        emphasis: { opacity: 0 }
      },
      data: [0].concat(Object.keys(data).map(function (key) {
        dataSumTemp -= data[key];
        return dataSumTemp;
      }))
    }, seriesBase));
    series.push(Object.assign({
      name: '数值',
      label: {
        normal: {
          show: true,
          position: 'top',
          formatter: function formatter(item) {
            return getFormated(item.value, dataType);
          }
        }
      },
      data: [dataSum].concat(Object.keys(data).map(function (key) {
        return data[key];
      }))
    }, seriesBase));
    return series;
  }
};

/**
 * 瀑布图
 * settings = { dataType: 'KMB' } 坐标轴类型 支持KMB, percent, normal
 * data = { d1: 100, d2: 200, d3: 300 }
 * @param {Object} data 原始数据
 * @param {Object} settings 配置项
 * @returns Object
 */
var waterfall = function waterfall(data, settings) {
  var dataType = settings.dataType;

  var tooltip = dataHandler$3.getWaterfallTooltip(dataType);
  var xAxis = dataHandler$3.getWaterfallXAxis(data);
  var yAxis = dataHandler$3.getWaterfallYAxis(dataType);
  var series = dataHandler$3.getWaterfallSeries(data, dataType);
  var options = { tooltip: tooltip, xAxis: xAxis, yAxis: yAxis, series: series };
  return options;
};

var index$3 = {
  render: function render() {
    var _vm = this;var _h = _vm.$createElement;var _c = _vm._self._c || _h;return _c('div', { ref: "canvas", style: _vm.canvasStyle });
  },
  staticRenderFns: [],
  name: 'VeWaterfall',
  mixins: [chartMixin],
  created: function created() {
    this.chartHandler = waterfall;
    this.echartsLib = echarts;
  }
};

var scatterRange = [10, 80];
var dataHandler$4 = {
  getScatterLegend: function getScatterLegend(data, dataType, axisNames) {
    var formatter = getLabelName;
    var legendData = [];

    data.forEach(function (items) {
      if (legendData.indexOf(items.name) === -1) legendData.push(items.name);
    });

    return { data: legendData, formatter: formatter };
  },
  getScatterTooltip: function getScatterTooltip(dataNames, dataType) {
    return {
      formatter: function formatter(item) {
        var tpl = [];
        tpl.push('<span style="background-color:' + item.color + ';' + tipPointStyle + '"></span>');
        tpl.push(item.seriesName + '<br>');
        dataNames.forEach(function (name, index) {
          tpl.push(name + ' : ' + getFormated(item.data[index], dataType[index]) + '<br>');
        });
        return tpl.join('');
      }
    };
  },
  getScatterAxis: function getScatterAxis() {
    var type = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : 'normal';
    var axisName = arguments[1];

    return {
      splitLine: { lineStyle: { type: 'dashed' } },
      scale: true,
      axisTick: { show: false },
      name: axisName,
      axisLabel: {
        formatter: function formatter(val) {
          return getFormated(val, type);
        }
      }
    };
  },
  getScatterSeries: function getScatterSeries(data, dataType, axisNames) {
    data = JSON.parse(JSON.stringify(data));
    var type = 'scatter';
    var itemStyle = {
      normal: {
        shadowBlur: 10,
        shadowColor: 'rgba(25, 100, 150, 0.5)',
        shadowOffsetY: 5
      }
    };
    var dataTypeObj = {};

    axisNames.forEach(function (name, index) {
      dataTypeObj[name] = dataType[index];
    });

    var valueRange = [data[0][axisNames[2]], data[0][axisNames[2]]];
    var dataTemp = {};

    data.forEach(function (items) {
      var name = items.name;

      delete items.name;
      if (!dataTemp[name]) {
        dataTemp[name] = [items];
      } else {
        dataTemp[name].push(items);
      }
      if (items[axisNames[2]] < valueRange[0]) valueRange[0] = items[axisNames[2]];
      if (items[axisNames[2]] > valueRange[1]) valueRange[1] = items[axisNames[2]];
    });

    var lineKB = getLineKB(scatterRange, valueRange);
    var series = Object.keys(dataTemp).map(function (name, index) {
      var result = [];

      dataTemp[name].forEach(function (val, index) {
        result[index] = [];
        axisNames.forEach(function (name) {
          result[index].push(val[name]);
        });
      });

      return {
        type: type,
        itemStyle: itemStyle,
        name: name,
        data: result,
        symbolSize: function symbolSize(data) {
          return data[2] * lineKB[0] + lineKB[1];
        }
      };
    });
    return series;
  }
};
/**
 * 气泡图
 * settings = {
 *   dataType: ['normal','normal',KMB'], 坐标轴类型 支持KMB, percent, normal
 *   axisNames: ['d1', 'd2', 'd3'], 显示在X轴，Y轴，气泡上的数据名称
 * }
 * data = [
 *   { d1: 1000, d2: 2000, d3: 3000, name: '1991' },
 *   { d1: 2000, d2: 3000, d3: 4000, name: '1991' },
 *   { d1: 3000, d2: 5000, d3: 8000, name: '1991' },
 *   { d1: 300, d2: 400, d3: 500, name: '1992' },
 *   { d1: 330, d2: 500, d3: 200, name: '1992' },
 *   { d1: 30, d2: 40, d3: 50, name: '1992' },
 *   { d1: 100, d2: 200, d3: 30, name: '1993' },
 *   { d1: 150, d2: 250, d3: 60, name: '1993' },
 *   { d1: 200, d2: 200, d3: 30, name: '1993' }
 * ]
 * @param {Object} data 原始数据
 * @param {Object} settings 配置项
 * @returns Object
 */
var scatter = function scatter(data, settings) {
  var _settings$dataType = settings.dataType,
      dataType = _settings$dataType === undefined ? [] : _settings$dataType,
      _settings$axisNames = settings.axisNames,
      axisNames = _settings$axisNames === undefined ? [] : _settings$axisNames;

  var legend = dataHandler$4.getScatterLegend(data, dataType, axisNames);
  var tooltip = dataHandler$4.getScatterTooltip(axisNames, dataType);
  var xAxis = dataHandler$4.getScatterAxis(dataType[0], axisNames[0]);
  var yAxis = dataHandler$4.getScatterAxis(dataType[1], axisNames[1]);
  var series = dataHandler$4.getScatterSeries(data, dataType, axisNames);
  var options = { legend: legend, tooltip: tooltip, xAxis: xAxis, yAxis: yAxis, series: series };
  return options;
};

var index$4 = {
  render: function render() {
    var _vm = this;var _h = _vm.$createElement;var _c = _vm._self._c || _h;return _c('div', { ref: "canvas", style: _vm.canvasStyle });
  },
  staticRenderFns: [],
  name: 'VeScatter',
  mixins: [chartMixin],
  created: function created() {
    this.chartHandler = scatter;
    this.echartsLib = echarts;
  }
};

var dataHandler$5 = {
  getFunnelTooltip: function getFunnelTooltip() {
    return {
      trigger: 'item',
      formatter: function formatter(item) {
        var tpl = [];
        var name = item.name.split(SIGN)[0];
        var type = item.name.split(SIGN)[1];
        tpl.push('<span style="background-color:' + item.color + ';' + tipPointStyle + '"></span>');
        tpl.push(name + ': ' + getFormated(item.data.realValue, type));
        return tpl.join('');
      }
    };
  },
  getFunnelLegend: function getFunnelLegend(data, sequence, dataType) {
    var legendData = (sequence || Object.keys(data)).map(function (item) {
      return '' + item + SIGN + dataType;
    });
    var formatter = function formatter(item) {
      return item.split(SIGN)[0];
    };

    return { data: legendData, formatter: formatter };
  },
  getFunnelSeries: function getFunnelSeries(data, sequence, dataType, ascending) {
    var series = {
      type: 'funnel',
      label: { normal: {
          formatter: function formatter(item) {
            return item.name.split(SIGN)[0];
          }
        } },
      data: []
    };

    var realData = dataHandler$5.getFunnelValue(data, sequence);
    realData.forEach(function (d) {
      series.data.push({ name: '' + d.name + SIGN + dataType, value: d.value, realValue: d.realValue });
    });
    if (ascending) series.sort = 'ascending';
    return series;
  },
  getFunnelValue: function getFunnelValue(data, sequence) {
    var lastName = void 0;
    var falseFunnel = false;
    if (sequence) {
      sequence.some(function (value) {
        if (data[lastName] - data[value] < 0) {
          falseFunnel = true;
          return true;
        } else {
          lastName = value;
        }
      });
    }
    var step = 100 / Object.keys(data).length;
    var resultData = falseFunnel ? sequence.slice().reverse().map(function (key, index) {
      return { name: key, value: (index + 1) * step, realValue: data[key] };
    }) : Object.keys(data).map(function (key) {
      return { name: key, value: data[key], realValue: data[key] };
    });
    return resultData;
  }
};
/**
 * 漏斗图
 * settings = {
 *   dataType: 'KMB', 坐标轴类型 支持KMB, percent, normal
 *   sequence: ['d-1', 'd-2', 'd-3', 'd-4'], 可选，漏斗展示顺序
 *   ascending: true, 是否为金字塔
 * }
 * data = {
 *   'd-1': 100000,
 *   'd-2': 200000,
 *   'd-3': 50000,
 *   'd-4': 3000000
 * }
 * @param {Object} data 原始数据
 * @param {Object} settings 配置项
 * @returns Object
 */
var funnel = function funnel(data, settings) {
  var dataType = settings.dataType,
      sequence = settings.sequence,
      ascending = settings.ascending;

  var tooltip = dataHandler$5.getFunnelTooltip();
  var legend = dataHandler$5.getFunnelLegend(data, sequence, dataType);
  var series = dataHandler$5.getFunnelSeries(data, sequence, dataType, ascending);
  var options = { tooltip: tooltip, legend: legend, series: series };
  return options;
};

var index$5 = {
  render: function render() {
    var _vm = this;var _h = _vm.$createElement;var _c = _vm._self._c || _h;return _c('div', { ref: "canvas", style: _vm.canvasStyle });
  },
  staticRenderFns: [],
  name: 'VeFunnel',
  mixins: [chartMixin],
  created: function created() {
    this.chartHandler = funnel;
    this.echartsLib = echarts;
  }
};

var dataHandler$6 = {
  getRadarLegend: function getRadarLegend(data) {
    var legendData = [];
    data.forEach(function (val) {
      if (legendData.indexOf(val.name) === -1) legendData.push(val.name);
    });

    return { data: legendData };
  },
  getRadarTooltip: function getRadarTooltip(dataType, radar) {
    var typeTemp = [];
    var nameTemp = [];
    radar.indicator.map(function (item, index) {
      typeTemp[index] = dataType[item.name];
      nameTemp[index] = item.name;
    });
    return {
      formatter: function formatter(item) {
        var tpl = [];
        tpl.push('<span style="background-color:' + item.color + ';' + tipPointStyle + '"></span>');
        tpl.push(item.seriesName + '<br />');
        item.data.forEach(function (val, index) {
          tpl.push(nameTemp[index] + ': ' + getFormated(val, typeTemp[index]) + '<br />');
        });
        return tpl.join('');
      }
    };
  },
  getRadarSetting: function getRadarSetting(data) {
    var settingBase = {
      indicator: [],
      shape: 'circle',
      splitNumber: 5
    };
    var indicatorTemp = {};
    data.forEach(function (items) {
      Object.keys(items).forEach(function (key) {
        if (key !== 'name') {
          if (!indicatorTemp[key]) {
            indicatorTemp[key] = [items[key]];
          } else {
            indicatorTemp[key].push(items[key]);
          }
        }
      });
    });
    settingBase.indicator = Object.keys(indicatorTemp).map(function (key) {
      return {
        name: key,
        max: Math.max.apply(null, indicatorTemp[key])
      };
    });
    return settingBase;
  },
  getRadarSeries: function getRadarSeries(data, legend, radar) {
    data = JSON.parse(JSON.stringify(data));
    var radarIndexObj = {};
    radar.indicator.forEach(function (item, index) {
      radarIndexObj[item.name] = index;
    });
    var dataStore = {};
    data.forEach(function (items) {
      var name = items.name;
      delete items.name;
      if (!dataStore[name]) {
        dataStore[name] = [items];
      } else {
        dataStore[name].push(items);
      }
    });
    var series = legend.data.map(function (name, index) {
      var seriesBase = {
        name: name,
        type: 'radar',
        data: []
      };
      dataStore[name].forEach(function (items) {
        var dataArr = [];
        Object.keys(items).forEach(function (key) {
          dataArr[radarIndexObj[key]] = items[key];
        });
        seriesBase.data.push(dataArr);
      });
      return seriesBase;
    });
    return series;
  }
};

var radar = function radar(data, settings) {
  var _settings$dataType = settings.dataType,
      dataType = _settings$dataType === undefined ? {} : _settings$dataType;

  var legend = dataHandler$6.getRadarLegend(data);
  var radar = dataHandler$6.getRadarSetting(data);
  var tooltip = dataHandler$6.getRadarTooltip(dataType, radar);
  var series = dataHandler$6.getRadarSeries(data, legend, radar);
  var options = { legend: legend, tooltip: tooltip, radar: radar, series: series };
  return options;
};

var index$6 = {
  render: function render() {
    var _vm = this;var _h = _vm.$createElement;var _c = _vm._self._c || _h;return _c('div', { ref: "canvas", style: _vm.canvasStyle });
  },
  staticRenderFns: [],
  name: 'VeRadar',
  mixins: [chartMixin],
  created: function created() {
    this.chartHandler = radar;
    this.echartsLib = echarts;
  }
};

var index$7 = {
  render: function render() {
    var _vm = this;var _h = _vm.$createElement;var _c = _vm._self._c || _h;return _c('div', { ref: "canvas", style: _vm.canvasStyle });
  },
  staticRenderFns: [],
  name: 'VeChart',
  mixins: [chartMixin],
  created: function created() {
    this.chartLib = { bar: bar, column: column, line: line, pie: pie, ring: ring };
    this.chartHandler = this.chartLib[this.settings.type];
    this.echartsLib = echarts;
  }
};

exports.VeBar = index;
exports.VeColumn = column$1;
exports.VeRing = ring$1;
exports.VeLine = index$1;
exports.VePie = index$2;
exports.VeWaterfall = index$3;
exports.VeScatter = index$4;
exports.VeFunnel = index$5;
exports.VeRadar = index$6;
exports.VeChart = index$7;
