text: 'use strict';
  
  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/chart/funnel');
  
  if (typeof Object.assign !== 'function') {
    Object.assign = function (target) {
      if (target == null) {
        throw new TypeError('Cannot convert undefined or null to object');
      }
  
      target = Object(target);
      for (var index = 1; index < arguments.length; index++) {
        var source = arguments[index];
        if (source != null) {
          for (var key in source) {
            if (Object.prototype.hasOwnProperty.call(source, key)) {
              target[key] = source[key];
            }
          }
        }
      }
      return target;
    };
  }
  
  echarts.registerTheme('ve-chart', {
    categoryAxis: {
      axisLine: { show: false },
      axisTick: { show: false },
      splitLine: { show: false }
    },
    valueAxis: {
      axisLine: { show: false }
    },
    line: {
      smooth: true
    },
    grid: {
      containLabel: true,
      left: 10,
      right: 10
    }
  });
  
  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('');
  };
  
  var color = ['#19d4ae', '#5ab1ef', '#fa6e86', '#ffb980', '#0067a6', '#c4b4e4', '#d87a80', '#9cbbff', '#d9d0c7', '#87a997', '#d49ea2', '#5b4947', '#7ba3a8'];
  
  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) {
    var digit = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : 2;
    var defaultVal = arguments.length > 3 && arguments[3] !== undefined ? arguments[3] : '-';
  
    if (val == null || isNaN(val)) return defaultVal;
    switch (type) {
      case 'KMB':
        return numberFormat(val);
      case 'percent':
        return parseFloat((val * 100).toFixed(digit)) + '%';
      case 'normal':
        return formatTausends(val);
      default:
        return val;
    }
  };
  
  
  
  
  
  
  
  
  
  
  
  
  var getType = function getType(v) {
    return Object.prototype.toString.call(v);
  };
  
  function getFunnelTooltip(dataType, digit) {
    return {
      trigger: 'item',
      formatter: function formatter(item) {
        var tpl = [];
        tpl.push(itemPoint(item.color));
        tpl.push(item.name + ': ' + getFormated(item.data.realValue, dataType, digit));
        return tpl.join('');
      }
    };
  }
  
  function getFunnelSeries(args) {
    var dimension = args.dimension,
        metrics = args.metrics,
        rows = args.rows,
        sequence = args.sequence,
        ascending = args.ascending;
  
    var series = { type: 'funnel' };
    rows.sort(function (a, b) {
      return sequence.indexOf(a[dimension]) - sequence.indexOf(b[dimension]);
    });
  
    var falseFunnel = false;
    rows.some(function (row, index) {
      if (index && row[metrics] > rows[index - 1][metrics]) {
        falseFunnel = true;
        return true;
      }
    });
  
    var step = 100 / rows.length;
  
    if (falseFunnel) {
      series.data = rows.slice().reverse().map(function (row, index) {
        return {
          name: row[dimension],
          value: (index + 1) * step,
          realValue: row[metrics]
        };
      });
    } else {
      series.data = rows.map(function (row) {
        return {
          name: row[dimension],
          value: row[metrics],
          realValue: row[metrics]
        };
      });
    }
  
    if (ascending) series.sort = 'ascending';
    return series;
  }
  
  var funnel = function funnel(outerColumns, outerRows, settings, extra) {
    var columns = outerColumns.slice();
    var rows = outerRows.slice();
    var _settings$dataType = settings.dataType,
        dataType = _settings$dataType === undefined ? 'normal' : _settings$dataType,
        _settings$dimension = settings.dimension,
        dimension = _settings$dimension === undefined ? columns[0] : _settings$dimension,
        _settings$sequence = settings.sequence,
        sequence = _settings$sequence === undefined ? rows.map(function (row) {
      return row[dimension];
    }) : _settings$sequence,
        _settings$digit = settings.digit,
        digit = _settings$digit === undefined ? 2 : _settings$digit,
        ascending = settings.ascending;
    var tooltipVisible = extra.tooltipVisible,
        legendVisible = extra.legendVisible;
  
    var metrics = void 0;
    if (settings.metrics) {
      metrics = settings.metrics;
    } else {
      var metricsTemp = columns.slice();
      metricsTemp.splice(columns.indexOf(dimension), 1);
      metrics = metricsTemp[0];
    }
  
    var tooltip = tooltipVisible && getFunnelTooltip(dataType, digit);
    var legend = legendVisible && { data: sequence };
    var seriesParams = { dimension: dimension, metrics: metrics, rows: rows, sequence: sequence, ascending: ascending };
    var series = getFunnelSeries(seriesParams);
    var options = { tooltip: tooltip, legend: legend, series: series };
    return options;
  };
  
  var chartMixin = {
    props: {
      data: { type: [Object, Array], default: function _default() {
          return {};
        }
      },
      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 },
      grid: { type: Object },
      colors: { type: Array },
      tooltipVisible: { type: Boolean, default: true },
      legendVisible: { type: Boolean, default: true },
      legendPosition: { type: String },
      markLine: { type: Object },
      markArea: { type: Object },
      markPoint: { type: Object },
      visualMap: { type: [Object, Array] },
      dataZoom: { type: [Object, Array] },
      toolbox: { type: Object },
      initOptions: { type: Object, default: function _default() {
          return {};
        }
      },
      title: Object,
      legend: Object,
      xAxis: Object,
      yAxis: Object,
      radar: Object,
      tooltip: Object,
      axisPointer: Object,
      brush: Object,
      geo: Object,
      timeline: Object,
      graphic: Object,
      series: [Object, Array],
      backgroundColor: [Object, String],
      textStyle: Object,
      animation: Object,
      theme: Object,
      themeName: String
    },
  
    watch: {
      data: {
        deep: true,
        handler: function handler(v) {
          if (v) {
            this.dataHandler(v);
          }
        }
      },
  
      settings: {
        deep: true,
        handler: function handler(v) {
          if (v.type && this.chartLib) this.chartHandler = this.chartLib[v.type];
          this.dataHandler(this.data);
        }
      }
    },
  
    computed: {
      canvasStyle: function canvasStyle() {
        return {
          width: this.width,
          height: this.height,
          position: 'relative'
        };
      },
      chartColor: function chartColor() {
        return this.colors || this.theme && this.theme.color || color;
      }
    },
  
    methods: {
      dataHandler: function dataHandler(data) {
        if (!this.chartHandler) return;
        var _data = data,
            columns = _data.columns,
            rows = _data.rows;
  
        var extra = {
          tooltipVisible: this.tooltipVisible,
          legendVisible: this.legendVisible,
          echarts: this.echarts,
          color: this.chartColor
        };
        if (this.beforeConfig) data = this.beforeConfig(data);
  
        var options = this.chartHandler(columns, rows, this.settings, extra);
        if (options) {
          if (typeof options.then === 'function') {
            options.then(this.optionsHandler);
          } else {
            this.optionsHandler(options);
          }
        }
      },
      optionsHandler: function optionsHandler(options) {
        var _this = this;
  
        if (this.legendPosition && options.legend) {
          options.legend[this.legendPosition] = 10;
          if (~['left', 'right'].indexOf(this.legendPosition)) {
            options.legend.top = 'middle';
            options.legend.orient = 'vertical';
          }
        }
        if (!this.themeName) options.color = this.chartColor;
        var echartsSettings = ['grid', 'dataZoom', 'visualMap', 'toolbox', 'title', 'legend', 'xAxis', 'yAxis', 'radar', 'tooltip', 'axisPointer', 'brush', 'geo', 'timeline', 'graphic', 'series', 'backgroundColor', 'textStyle'];
        echartsSettings.forEach(function (setting) {
          if (_this[setting]) options[setting] = _this[setting];
        });
        if (this.animation) {
          Object.keys(this.animation).forEach(function (key) {
            options[key] = _this.animation[key];
          });
        }
        if (this.markArea || this.markLine || this.markPoint) {
          var marks = {
            markArea: this.markArea,
            markLine: this.markLine,
            markPoint: this.markPoint
          };
          var series = options.series;
          if (getType(series) === '[object Array]') {
            series.forEach(function (item) {
              _this.addMark(item, marks);
            });
          } else if (getType(series) === '[object Object]') {
            this.addMark(series, marks);
          }
        }
        if (this.afterConfig) options = this.afterConfig(options);
        this.echarts.setOption(options, true);
      },
      addMark: function addMark(seriesItem, marks) {
        Object.keys(marks).forEach(function (key) {
          if (marks[key]) {
            seriesItem[key] = marks[key];
          }
        });
      },
      init: function init() {
        if (this.echarts) return;
        var themeName = this.themeName || (this.theme ? 'outer-theme' : 've-chart');
        this.echarts = this.echartsLib.init(this.$refs.canvas, themeName, this.initOptions);
        if (this.data) this.dataHandler(this.data);
        if (this.events) this.bindEvents();
      },
      bindEvents: function bindEvents() {
        var _this2 = this;
  
        Object.keys(this.events).forEach(function (event) {
          _this2.echarts.on(event, _this2.events[event]);
        });
      },
      addWatchToProps: function addWatchToProps() {
        var _this3 = this;
  
        var watchedVariable = this._watchers.map(function (watcher) {
          return watcher.expression;
        });
        Object.keys(this.$props).forEach(function (prop) {
          if (!~watchedVariable.indexOf(prop)) {
            var opts = {};
            if (getType(prop) === '[object Object]') {
              opts.deep = true;
            }
            _this3.$watch(prop, function () {
              _this3.dataHandler(_this3.data);
            }, opts);
          }
        });
      },
      registerTheme: function registerTheme() {
        echarts.registerTheme('outer-theme', this.theme);
      }
    },
  
    created: function created() {
      this.addWatchToProps();
      if (this.theme) this.registerTheme();
    },
    mounted: function mounted() {
      this.init();
      window.addEventListener('resize', this.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", staticClass: "ve-funnel", style: _vm.canvasStyle });
    },
    staticRenderFns: [],
    name: 'VeFunnel',
    mixins: [chartMixin],
    created: function created() {
      this.chartHandler = funnel;
      this.echartsLib = echarts;
    }
  };
  
  module.exports = index;
  