import * as echarts from 'echarts';
import Factory from './factory.js';

echarts.extendChartView({
  type: 'mark',
  render: function render(seriesModel, ecModel, api) {
    var _this = this;
    this.group.removeAll();
    var data = seriesModel.getData();
    data.each(function (index) {
      var model = data.getItemModel(index);
      var grids = model.get('gridIndex') || [0];
      grids.forEach(function (grid) {
        var sys = api.getCoordinateSystems()[grid];
        var shape = model.get('shape');
        var xAxisIndex = model.get('xAxisIndex');
        var yAxisIndex = model.get('yAxisIndex');
        var xAxis = sys.getAxis('x', xAxisIndex);
        var yAxis = sys.getAxis('y', yAxisIndex);
        if (xAxis && yAxis && Factory[shape]) {
          var finder = {
            xAxisModel: xAxis.model,
            yAxisModel: yAxis.model
          };
          _this.group.add(Factory[shape](model, sys, finder, api, 0));
        }
      });
    });
  },
  dispose: function dispose() {
    this.group.removeAll();
  }
});
