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/bar');
  
  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: {
      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 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 parseFloat((val * 100).toFixed(2)) + '%';
      case 'normal':
        return formatTausends(val);
      default:
        return val;
    }
  };
  
  
  
  var getStackMap = function getStackMap(stack) {
    var stackMap = {};
    Object.keys(stack).forEach(function (item) {
      stack[item].forEach(function (name) {
        stackMap[name] = item;
      });
    });
    return stackMap;
  };
  
  var defineProperty = function (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;
  };
  
  function getBarDimAxis(args) {
    var rows = args.rows,
        dimAxisName = args.dimAxisName,
        dimension = args.dimension,
        axisVisible = args.axisVisible;
  
    return dimension.map(function (item) {
      return {
        type: 'category',
        name: dimAxisName,
        nameLocation: 'middle',
        nameGap: 22,
        data: rows.map(function (row) {
          return row[item];
        }),
        axisLabel: {
          formatter: function formatter(v) {
            return String(v);
          }
        },
        show: axisVisible
      };
    });
  }
  
  function getBarMeaAxis(args) {
    var meaAxisName = args.meaAxisName,
        meaAxisType = args.meaAxisType,
        axisVisible = args.axisVisible;
  
    var meaAxisBase = {
      type: 'value',
      axisTick: {
        show: false
      },
      show: axisVisible
    };
    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;
  }
  
  function getBarTooltip(args) {
    var axisSite = args.axisSite,
        isHistogram = args.isHistogram,
        meaAxisType = args.meaAxisType;
  
    var secondAxis = isHistogram ? axisSite.right : axisSite.top;
    return {
      trigger: 'axis',
      formatter: function formatter(items) {
        var tpl = [];
        tpl.push(items[0].name + '<br>');
        items.forEach(function (item) {
          var seriesName = item.seriesName;
          var type = ~secondAxis.indexOf(seriesName) ? meaAxisType[1] : meaAxisType[0];
          tpl.push(itemPoint(item.color));
          tpl.push(seriesName + ': ');
          tpl.push(getFormated(item.value, type));
          tpl.push('<br>');
        });
  
        return tpl.join('');
      }
    };
  }
  
  function getBarSeries(args) {
    var rows = args.rows,
        metrics = args.metrics,
        stack = args.stack,
        axisSite = args.axisSite,
        isHistogram = args.isHistogram;
  
    var series = [];
    var seriesTemp = {};
    var secondAxis = isHistogram ? axisSite.right : axisSite.top;
    var secondDimAxisIndex = isHistogram ? 'yAxisIndex' : 'xAxisIndex';
    var stackMap = stack && getStackMap(stack);
    metrics.forEach(function (item) {
      seriesTemp[item] = [];
    });
    rows.forEach(function (row) {
      metrics.forEach(function (item) {
        seriesTemp[item].push(row[item]);
      });
    });
    series = Object.keys(seriesTemp).map(function (item) {
      var seriesItem = defineProperty({
        name: item,
        type: 'bar',
        data: seriesTemp[item]
      }, secondDimAxisIndex, ~secondAxis.indexOf(item) ? '1' : '0');
  
      if (stack && stackMap[item]) seriesItem.stack = stackMap[item];
  
      return seriesItem;
    });
  
    return series.length ? series : false;
  }
  
  var histogram$1 = function histogram(columns, rows, settings, status) {
    var _settings$axisSite2 = settings.axisSite,
        axisSite = _settings$axisSite2 === undefined ? { right: [] } : _settings$axisSite2,
        _settings$dimension2 = settings.dimension,
        dimension = _settings$dimension2 === undefined ? [columns[0]] : _settings$dimension2,
        _settings$stack2 = settings.stack,
        stack = _settings$stack2 === undefined ? {} : _settings$stack2,
        _settings$axisVisible2 = settings.axisVisible,
        axisVisible = _settings$axisVisible2 === undefined ? true : _settings$axisVisible2;
    var tooltipVisible = status.tooltipVisible,
        legendVisible = status.legendVisible;
  
    var metrics = columns.slice();
    if (settings.metrics) {
      metrics = settings.metrics;
    } else {
      metrics.splice(columns.indexOf(dimension[0]), 1);
    }
    var meaAxisType = settings.yAxisType || ['normal', 'normal'];
    var meaAxisName = settings.yAxisName || [];
    var dimAxisName = settings.xAxisName || '';
    var isHistogram = true;
  
    var legend = legendVisible && { data: metrics };
    var xAxis = getBarDimAxis({ rows: rows, dimAxisName: dimAxisName, dimension: dimension, axisVisible: axisVisible });
    var yAxis = getBarMeaAxis({ meaAxisName: meaAxisName, meaAxisType: meaAxisType, axisVisible: axisVisible });
    var series = getBarSeries({ rows: rows, metrics: metrics, stack: stack, axisSite: axisSite, isHistogram: isHistogram });
    var tooltipParams = { axisSite: axisSite, isHistogram: isHistogram, meaAxisType: meaAxisType };
    var tooltip = tooltipVisible && getBarTooltip(tooltipParams);
    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 },
      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] }
    },
  
    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'
        };
      }
    },
  
    methods: {
      dataHandler: function dataHandler(data) {
        var _this = this;
  
        if (!this.chartHandler) return;
        if (!data || !Array.isArray(data.columns) || !Array.isArray(data.rows)) return false;
        var _data = data,
            columns = _data.columns,
            rows = _data.rows;
  
        var extra = {
          tooltipVisible: this.tooltipVisible,
          legendVisible: this.legendVisible
        };
        if (this.beforeConfig) data = this.beforeConfig(data);
  
        var options = this.chartHandler(columns, rows, this.settings, extra);
  
        if (options) {
          if (this.colors) options.color = this.colors;
          if (this.grid) options.grid = this.grid;
          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.dataZoom) options.dataZoom = this.dataZoom;
          if (this.visualMap) options.visualMap = this.visualMap;
          if (this.markArea || this.markLine || this.markPoint) {
            var marks = {
              markArea: this.markArea,
              markLine: this.markLine,
              markPoint: this.markPoint
            };
            var series = options.series;
            if (this.getType(series) === '[object Array]') {
              series.forEach(function (item) {
                _this.addMark(item, marks);
              });
            } else if (this.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];
          }
        });
      },
      getType: function getType(v) {
        return Object.prototype.toString.call(v);
      },
      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 _this2 = this;
  
        Object.keys(this.events).forEach(function (event) {
          _this2.echarts.on(event, _this2.events[event]);
        });
      }
    },
  
    mounted: function mounted() {
      var _this3 = this;
  
      this.$nextTick(function () {
        _this3.init();
        window.addEventListener('resize', _this3.echarts.resize);
      });
    },
    beforeDestory: function beforeDestory() {
      window.removeEventListener('resize', this.echarts.resize);
      this.echarts.dispose();
    }
  };
  
  var histogram$$1 = {
    render: function render() {
      var _vm = this;var _h = _vm.$createElement;var _c = _vm._self._c || _h;return _c('div', { ref: "canvas", staticClass: "ve-histogram", style: _vm.canvasStyle });
    },
    staticRenderFns: [],
    name: 'VeHistogram',
    mixins: [chartMixin],
    created: function created() {
      this.chartHandler = histogram$1;
      this.echartsLib = echarts;
    }
  };
  
  module.exports = histogram$$1;
  