'use strict';

var categoryFilter = require('./categoryFilter.js');
var categoryVisual = require('./categoryVisual.js');
var edgeVisual = require('./edgeVisual.js');
var simpleLayout = require('./simpleLayout.js');
var circularLayout = require('./circularLayout.js');
var forceLayout = require('./forceLayout.js');
var createView = require('./createView.js');
var View = require('../../coord/View.js');
var GraphView = require('./GraphView.js');
var GraphSeries = require('./GraphSeries.js');
var roamHelper = require('../../component/helper/roamHelper.js');
var util = require('../../../../../../zrender@6.0.0/node_modules/zrender/lib/core/util.js');

function install(registers) {
  registers.registerChartView(GraphView.default);
  registers.registerSeriesModel(GraphSeries.default);
  registers.registerProcessor(categoryFilter.default);
  registers.registerVisual(categoryVisual.default);
  registers.registerVisual(edgeVisual.default);
  registers.registerLayout(simpleLayout.default);
  registers.registerLayout(registers.PRIORITY.VISUAL.POST_CHART_LAYOUT, circularLayout.default);
  registers.registerLayout(forceLayout.default);
  registers.registerCoordinateSystem('graphView', {
    dimensions: View.default.dimensions,
    create: createView.default
  });
  // Register legacy focus actions
  registers.registerAction({
    type: 'focusNodeAdjacency',
    event: 'focusNodeAdjacency',
    update: 'series:focusNodeAdjacency'
  }, util.noop);
  registers.registerAction({
    type: 'unfocusNodeAdjacency',
    event: 'unfocusNodeAdjacency',
    update: 'series:unfocusNodeAdjacency'
  }, util.noop);
  // Register roam action.
  registers.registerAction({
    type: 'graphRoam',
    event: 'graphRoam',
    update: 'none'
  }, function (payload, ecModel, api) {
    ecModel.eachComponent({
      mainType: 'series',
      query: payload
    }, function (seriesModel) {
      var graphView = api.getViewOfSeriesModel(seriesModel);
      if (graphView) {
        if (payload.dx != null && payload.dy != null) {
          graphView.updateViewOnPan(seriesModel, api, payload);
        }
        if (payload.zoom != null && payload.originX != null && payload.originY != null) {
          graphView.updateViewOnZoom(seriesModel, api, payload);
        }
      }
      var coordSys = seriesModel.coordinateSystem;
      var res = roamHelper.updateCenterAndZoomInAction(coordSys, payload, seriesModel.get('scaleLimit'));
      seriesModel.setCenter && seriesModel.setCenter(res.center);
      seriesModel.setZoom && seriesModel.setZoom(res.zoom);
    });
  });
}

exports.install = install;
