text: "use strict";
  
  exports.__esModule = true;
  exports["default"] = void 0;
  
  var _common = require("../../util/common");
  
  var _global = _interopRequireDefault(require("../../global"));
  
  var _vector = _interopRequireDefault(require("../../graphic/util/vector2"));
  
  function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { "default": obj }; }
  
  var Abastract = /*#__PURE__*/function () {
    var _proto = Abastract.prototype;
  
    _proto._initDefaultCfg = function _initDefaultCfg() {
      /**
       * ticks
       * @type {Array}
       */
      this.ticks = [];
      /**
       * the configuration for tickLine
       * @type {Object}
       */
  
      this.tickLine = {};
      /**
       * the direction of ticks, 1 means clockwise
       * @type {Number}
       */
  
      this.offsetFactor = 1;
      /**
       * the top container
       * @type {container}
       */
  
      this.frontContainer = null;
      /**
       * the back container
       * @type {[type]}
       */
  
      this.backContainer = null;
      /**
       * points for draw grid line
       * @type {Array}
       */
  
      this.gridPoints = [];
    };
  
    function Abastract(cfg) {
      this._initDefaultCfg();
  
      (0, _common.mix)(this, cfg);
      this.draw();
    }
  
    _proto.draw = function draw() {
      var line = this.line,
          tickLine = this.tickLine,
          label = this.label,
          grid = this.grid;
      grid && this.drawGrid(grid); // draw the grid lines
  
      tickLine && this.drawTicks(tickLine); // draw the tickLine
  
      line && this.drawLine(line); // draw axis line
  
      label && this.drawLabels(); // draw ticks
    };
  
    _proto.drawTicks = function drawTicks(tickCfg) {
      var self = this;
      var ticks = self.ticks;
      var length = tickCfg.length;
      var container = self.getContainer(tickCfg.top);
      (0, _common.each)(ticks, function (tick) {
        var start = self.getOffsetPoint(tick.value);
        var end = self.getSidePoint(start, length);
        var shape = container.addShape('line', {
          className: 'axis-tick',
          attrs: (0, _common.mix)({
            x1: start.x,
            y1: start.y,
            x2: end.x,
            y2: end.y
          }, tickCfg)
        });
        shape._id = self._id + '-ticks';
      });
    };
  
    _proto.drawLabels = function drawLabels() {
      var self = this;
      var labelOffset = self.labelOffset;
      var labels = self.labels;
      (0, _common.each)(labels, function (labelShape) {
        var container = self.getContainer(labelShape.get('top'));
        var start = self.getOffsetPoint(labelShape.get('value'));
  
        var _self$getSidePoint = self.getSidePoint(start, labelOffset),
            x = _self$getSidePoint.x,
            y = _self$getSidePoint.y;
  
        labelShape.attr((0, _common.mix)({
          x: x,
          y: y
        }, self.getTextAlignInfo(start, labelOffset), labelShape.get('textStyle')));
        labelShape._id = self._id + '-' + labelShape.attr('text');
        container.add(labelShape);
      });
    };
  
    _proto.drawLine = function drawLine() {};
  
    _proto.drawGrid = function drawGrid(grid) {
      var self = this;
      var gridPoints = self.gridPoints,
          ticks = self.ticks;
      var gridCfg = grid;
      var count = gridPoints.length;
      (0, _common.each)(gridPoints, function (subPoints, index) {
        if ((0, _common.isFunction)(grid)) {
          var tick = ticks[index] || {};
          var executedGrid = grid(tick.text, index, count);
          gridCfg = executedGrid ? (0, _common.mix)({}, _global["default"]._defaultAxis.grid, executedGrid) : null;
        }
  
        if (gridCfg) {
          var type = gridCfg.type; // has two types: 'line' and 'arc'
  
          var points = subPoints.points;
          var container = self.getContainer(gridCfg.top);
          var shape;
  
          if (type === 'arc') {
            var center = self.center,
                startAngle = self.startAngle,
                endAngle = self.endAngle;
  
            var radius = _vector["default"].length([points[0].x - center.x, points[0].y - center.y]);
  
            shape = container.addShape('Arc', {
              className: 'axis-grid',
              attrs: (0, _common.mix)({
                x: center.x,
                y: center.y,
                startAngle: startAngle,
                endAngle: endAngle,
                r: radius
              }, gridCfg)
            });
          } else {
            shape = container.addShape('Polyline', {
              className: 'axis-grid',
              attrs: (0, _common.mix)({
                points: points
              }, gridCfg)
            });
          }
  
          shape._id = subPoints._id;
        }
      });
    };
  
    _proto.getOffsetPoint = function getOffsetPoint() {};
  
    _proto.getAxisVector = function getAxisVector() {};
  
    _proto.getOffsetVector = function getOffsetVector(point, offset) {
      var self = this;
      var axisVector = self.getAxisVector(point);
  
      var normal = _vector["default"].normalize([], axisVector);
  
      var factor = self.offsetFactor;
      var verticalVector = [normal[1] * -1 * factor, normal[0] * factor];
      return _vector["default"].scale([], verticalVector, offset);
    };
  
    _proto.getSidePoint = function getSidePoint(point, offset) {
      var self = this;
      var offsetVector = self.getOffsetVector(point, offset);
      return {
        x: point.x + offsetVector[0],
        y: point.y + offsetVector[1]
      };
    };
  
    _proto.getTextAlignInfo = function getTextAlignInfo(point, offset) {
      var self = this;
      var offsetVector = self.getOffsetVector(point, offset);
      var align;
      var baseLine;
  
      if (offsetVector[0] > 0) {
        align = 'left';
      } else if (offsetVector[0] < 0) {
        align = 'right';
      } else {
        align = 'center';
      }
  
      if (offsetVector[1] > 0) {
        baseLine = 'top';
      } else if (offsetVector[1] < 0) {
        baseLine = 'bottom';
      } else {
        baseLine = 'middle';
      }
  
      return {
        textAlign: align,
        textBaseline: baseLine
      };
    };
  
    _proto.getContainer = function getContainer(isTop) {
      var frontContainer = this.frontContainer,
          backContainer = this.backContainer;
      return isTop ? frontContainer : backContainer;
    };
  
    return Abastract;
  }();
  
  var _default = Abastract;
  exports["default"] = _default;