text: "use strict";
  Object.defineProperty(exports, "__esModule", { value: true });
  var tslib_1 = require("tslib");
  /**
   * Create By Bruce Too
   * On 2020-02-17
   */
  var util_1 = require("@antv/util");
  var global_1 = require("../../base/global");
  var view_layer_1 = tslib_1.__importDefault(require("../../base/view-layer"));
  var factory_1 = require("../../components/factory");
  var factory_2 = require("../../geoms/factory");
  var EventParser = tslib_1.__importStar(require("./event"));
  var G2_GEOM_MAP = {
      rose: 'interval',
  };
  var PLOT_GEOM_MAP = {
      rose: 'column',
  };
  var RoseLayer = /** @class */ (function (_super) {
      tslib_1.__extends(RoseLayer, _super);
      function RoseLayer() {
          var _this = _super !== null && _super.apply(this, arguments) || this;
          _this.type = 'rose';
          return _this;
      }
      RoseLayer.getDefaultOptions = function () {
          return util_1.deepMix({}, _super.getDefaultOptions.call(this), {
              width: 400,
              height: 400,
              title: {
                  visible: false,
              },
              description: {
                  visible: false,
              },
              forceFit: true,
              padding: 'auto',
              radius: 0.8,
              innerRadius: 0,
              label: {
                  visible: true,
                  type: 'inner',
                  autoRotate: true,
                  adjustColor: false,
              },
              legend: {
                  visible: true,
                  position: 'right',
              },
              tooltip: {
                  visible: true,
                  shared: false,
                  showCrosshairs: false,
                  showMarkers: false,
              },
              columnStyle: {
                  stroke: 'white',
                  lineWidth: 1,
              },
              xAxis: {
                  visible: false,
                  line: {
                      visible: false,
                  },
                  tickLine: {
                      visible: false,
                  },
                  grid: {
                      visible: true,
                      alignTick: false,
                      style: {
                          lineWidth: 0.5,
                      },
                  },
                  label: {
                      offset: 5,
                      autoRotate: true,
                  },
              },
              yAxis: {
                  visible: false,
              },
          });
      };
      RoseLayer.prototype.getOptions = function (props) {
          var options = _super.prototype.getOptions.call(this, props);
          var columnStyle = props.sectorStyle;
          var xField = props.categoryField;
          var yField = props.radiusField;
          return util_1.deepMix({}, options, { columnStyle: columnStyle, xField: xField, yField: yField });
      };
      RoseLayer.prototype.getRadiusScale = function () {
          var radiusField = this.options.radiusField;
          if (radiusField) {
              this.view.getScaleByField(radiusField);
          }
      };
      RoseLayer.prototype.getAngleScale = function () {
          var categoryField = this.options.categoryField;
          if (categoryField) {
              this.view.getScaleByField(categoryField);
          }
      };
      RoseLayer.prototype.geometryParser = function (dim, type) {
          if (dim === 'g2') {
              return G2_GEOM_MAP[type];
          }
          return PLOT_GEOM_MAP[type];
      };
      RoseLayer.prototype.scale = function () {
          // super.scale();
          var props = this.options;
          var scales = {};
          scales[props.radiusField] = {};
          scales[props.categoryField] = { type: 'cat' };
          this.setConfig('scales', scales);
      };
      /** 不显示坐标轴 */
      /*protected axis() {
        super.axis();
        const options = this.options;
        if (!options.stackField && !options.groupField) {
          this.setConfig('axes', false);
        }
      }*/
      RoseLayer.prototype.coord = function () {
          var props = this.options;
          var coordConfig = {
              type: 'polar',
              cfg: {
                  radius: props.radius,
                  innerRadius: props.innerRadius || 0,
              },
          };
          this.setConfig('coordinate', coordConfig);
      };
      RoseLayer.prototype.addGeometry = function () {
          var options = this.options;
          var rose = factory_2.getGeom('interval', 'main', {
              plot: this,
              positionFields: [options.categoryField, options.radiusField],
              widthRatio: {
                  rose: 1,
              },
          });
          rose.label = this.extractLabel();
          rose.adjust = this.adjustRoseAdjust();
          this.rose = rose;
          if (options.tooltip && (options.tooltip.fields || options.tooltip.formatter)) {
              this.geometryTooltip();
          }
          this.setConfig('geometry', rose);
      };
      RoseLayer.prototype.adjustRoseAdjust = function () {
          return;
      };
      RoseLayer.prototype.geometryTooltip = function () {
          this.rose.tooltip = {};
          var tooltipOptions = this.options.tooltip;
          if (tooltipOptions.fields) {
              this.rose.tooltip.fields = tooltipOptions.fields;
          }
          if (tooltipOptions.formatter) {
              this.rose.tooltip.callback = tooltipOptions.formatter;
              if (!tooltipOptions.fields) {
                  this.rose.tooltip.fields = [this.options.radiusField, this.options.categoryField, this.options.colorField];
              }
          }
      };
      RoseLayer.prototype.animation = function () {
          _super.prototype.animation.call(this);
          var props = this.options;
          if (props.animation === false) {
              /** 关闭动画 */
              this.rose.animate = false;
          }
      };
      RoseLayer.prototype.annotation = function () {
          return;
      };
      RoseLayer.prototype.parseEvents = function () {
          _super.prototype.parseEvents.call(this, EventParser);
      };
      RoseLayer.prototype.extractLabel = function () {
          var options = this.options;
          if (!options.label || !options.label.visible) {
              return false;
          }
          var label = util_1.deepMix({}, options.label);
          this.adjustLabelOptions(label);
          var fields = [options.categoryField, options.radiusField];
          var labelConfig = factory_1.getComponent('label', tslib_1.__assign({ plot: this, labelType: 'polar', fields: fields }, label));
          return labelConfig;
      };
      RoseLayer.prototype.adjustLabelOptions = function (labelOptions) {
          var radiusField = this.options.radiusField;
          if (labelOptions) {
              var offset = labelOptions.offset, type = labelOptions.type, content = labelOptions.content;
              if (type === 'inner') {
                  labelOptions.offset = offset < 0 ? offset : -10;
              }
              else if (type === 'outer') {
                  labelOptions.offset = offset >= 0 ? offset : 10;
              }
              if (!content) {
                  // 默认显示 数值
                  labelOptions.content = function (text, item) { return "" + item._origin[radiusField]; };
              }
          }
      };
      return RoseLayer;
  }(view_layer_1.default));
  exports.default = RoseLayer;
  global_1.registerPlotType('rose', RoseLayer);
  //# sourceMappingURL=layer.js.map