"use strict";
Object.defineProperties(exports, { __esModule: { value: true }, [Symbol.toStringTag]: { value: "Module" } });
const SingleAxis = require("./SingleAxis.js");
const axisHelper = require("../axisHelper.js");
const layout = require("../../util/layout.js");
const util = require("../../../../../../zrender@5.4.4/node_modules/zrender/lib/core/util.js");
var singleDimensions = ["single"];
var Single = (
  /** @class */
  function() {
    function Single2(axisModel, ecModel, api) {
      this.type = "single";
      this.dimension = "single";
      this.dimensions = singleDimensions;
      this.axisPointerEnabled = true;
      this.model = axisModel;
      this._init(axisModel, ecModel, api);
    }
    Single2.prototype._init = function(axisModel, ecModel, api) {
      var dim = this.dimension;
      var axis = new SingleAxis.default(dim, axisHelper.createScaleByModel(axisModel), [0, 0], axisModel.get("type"), axisModel.get("position"));
      var isCategory = axis.type === "category";
      axis.onBand = isCategory && axisModel.get("boundaryGap");
      axis.inverse = axisModel.get("inverse");
      axis.orient = axisModel.get("orient");
      axisModel.axis = axis;
      axis.model = axisModel;
      axis.coordinateSystem = this;
      this._axis = axis;
    };
    Single2.prototype.update = function(ecModel, api) {
      ecModel.eachSeries(function(seriesModel) {
        if (seriesModel.coordinateSystem === this) {
          var data_1 = seriesModel.getData();
          util.each(data_1.mapDimensionsAll(this.dimension), function(dim) {
            this._axis.scale.unionExtentFromData(data_1, dim);
          }, this);
          axisHelper.niceScaleExtent(this._axis.scale, this._axis.model);
        }
      }, this);
    };
    Single2.prototype.resize = function(axisModel, api) {
      this._rect = layout.getLayoutRect({
        left: axisModel.get("left"),
        top: axisModel.get("top"),
        right: axisModel.get("right"),
        bottom: axisModel.get("bottom"),
        width: axisModel.get("width"),
        height: axisModel.get("height")
      }, {
        width: api.getWidth(),
        height: api.getHeight()
      });
      this._adjustAxis();
    };
    Single2.prototype.getRect = function() {
      return this._rect;
    };
    Single2.prototype._adjustAxis = function() {
      var rect = this._rect;
      var axis = this._axis;
      var isHorizontal = axis.isHorizontal();
      var extent = isHorizontal ? [0, rect.width] : [0, rect.height];
      var idx = axis.inverse ? 1 : 0;
      axis.setExtent(extent[idx], extent[1 - idx]);
      this._updateAxisTransform(axis, isHorizontal ? rect.x : rect.y);
    };
    Single2.prototype._updateAxisTransform = function(axis, coordBase) {
      var axisExtent = axis.getExtent();
      var extentSum = axisExtent[0] + axisExtent[1];
      var isHorizontal = axis.isHorizontal();
      axis.toGlobalCoord = isHorizontal ? function(coord) {
        return coord + coordBase;
      } : function(coord) {
        return extentSum - coord + coordBase;
      };
      axis.toLocalCoord = isHorizontal ? function(coord) {
        return coord - coordBase;
      } : function(coord) {
        return extentSum - coord + coordBase;
      };
    };
    Single2.prototype.getAxis = function() {
      return this._axis;
    };
    Single2.prototype.getBaseAxis = function() {
      return this._axis;
    };
    Single2.prototype.getAxes = function() {
      return [this._axis];
    };
    Single2.prototype.getTooltipAxes = function() {
      return {
        baseAxes: [this.getAxis()],
        // Empty otherAxes
        otherAxes: []
      };
    };
    Single2.prototype.containPoint = function(point) {
      var rect = this.getRect();
      var axis = this.getAxis();
      var orient = axis.orient;
      if (orient === "horizontal") {
        return axis.contain(axis.toLocalCoord(point[0])) && point[1] >= rect.y && point[1] <= rect.y + rect.height;
      } else {
        return axis.contain(axis.toLocalCoord(point[1])) && point[0] >= rect.y && point[0] <= rect.y + rect.height;
      }
    };
    Single2.prototype.pointToData = function(point) {
      var axis = this.getAxis();
      return [axis.coordToData(axis.toLocalCoord(point[axis.orient === "horizontal" ? 0 : 1]))];
    };
    Single2.prototype.dataToPoint = function(val) {
      var axis = this.getAxis();
      var rect = this.getRect();
      var pt = [];
      var idx = axis.orient === "horizontal" ? 0 : 1;
      if (val instanceof Array) {
        val = val[0];
      }
      pt[idx] = axis.toGlobalCoord(axis.dataToCoord(+val));
      pt[1 - idx] = idx === 0 ? rect.y + rect.height / 2 : rect.x + rect.width / 2;
      return pt;
    };
    Single2.prototype.convertToPixel = function(ecModel, finder, value) {
      var coordSys = getCoordSys(finder);
      return coordSys === this ? this.dataToPoint(value) : null;
    };
    Single2.prototype.convertFromPixel = function(ecModel, finder, pixel) {
      var coordSys = getCoordSys(finder);
      return coordSys === this ? this.pointToData(pixel) : null;
    };
    return Single2;
  }()
);
function getCoordSys(finder) {
  var seriesModel = finder.seriesModel;
  var singleModel = finder.singleAxisModel;
  return singleModel && singleModel.coordinateSystem || seriesModel && seriesModel.coordinateSystem;
}
exports.default = Single;
exports.singleDimensions = singleDimensions;
