'use strict';

var SankeyView = require('./SankeyView.js');
var SankeySeries = require('./SankeySeries.js');
var sankeyLayout = require('./sankeyLayout.js');
var sankeyVisual = require('./sankeyVisual.js');
var roamHelper = require('../../component/helper/roamHelper.js');

function install(registers) {
  registers.registerChartView(SankeyView.default);
  registers.registerSeriesModel(SankeySeries.default);
  registers.registerLayout(sankeyLayout.default);
  registers.registerVisual(sankeyVisual.default);
  registers.registerAction({
    type: 'dragNode',
    event: 'dragnode',
    // here can only use 'update' now, other value is not support in echarts.
    update: 'update'
  }, function (payload, ecModel) {
    ecModel.eachComponent({
      mainType: 'series',
      subType: 'sankey',
      query: payload
    }, function (seriesModel) {
      seriesModel.setNodePosition(payload.dataIndex, [payload.localX, payload.localY]);
    });
  });
  registers.registerAction({
    type: 'sankeyRoam',
    event: 'sankeyRoam',
    update: 'none'
  }, function (payload, ecModel, api) {
    ecModel.eachComponent({
      mainType: 'series',
      subType: 'sankey',
      query: payload
    }, function (seriesModel) {
      var coordSys = seriesModel.coordinateSystem;
      var res = roamHelper.updateCenterAndZoomInAction(coordSys, payload, seriesModel.get('scaleLimit'));
      seriesModel.setCenter(res.center);
      seriesModel.setZoom(res.zoom);
    });
  });
}

exports.install = install;
