text: import { __assign, __extends } from "tslib";
  import { deepMix, has, each, clone } from '@antv/util';
  import { registerPlotType } from '../../base/global';
  import ViewLayer from '../../base/view-layer';
  import { getComponent } from '../../components/factory';
  import ConversionTag from '../../components/conversion-tag';
  import { getGeom } from '../../geoms/factory';
  import { extractScale } from '../../util/scale';
  import responsiveMethods from './apply-responsive';
  import './theme';
  import './component/label';
  import './component/label-auto';
  import * as EventParser from './event';
  import { getGeometryByType } from '../../util/view';
  var G2_GEOM_MAP = {
      bar: 'interval',
  };
  var PLOT_GEOM_MAP = {
      interval: 'bar',
  };
  var BaseBarLayer = /** @class */ (function (_super) {
      __extends(BaseBarLayer, _super);
      function BaseBarLayer() {
          var _this = _super !== null && _super.apply(this, arguments) || this;
          _this.type = 'bar';
          return _this;
      }
      BaseBarLayer.getDefaultOptions = function () {
          var cfg = {
              xAxis: {
                  visible: true,
                  line: {
                      visible: false,
                  },
                  title: {
                      visible: true,
                  },
                  label: {
                      visible: false,
                  },
                  tickLine: {
                      visible: false,
                  },
                  grid: {
                      visible: false,
                  },
                  nice: true,
              },
              yAxis: {
                  visible: true,
                  grid: {
                      visible: false,
                  },
                  line: {
                      visible: false,
                  },
                  tickLine: {
                      visible: false,
                  },
                  label: {
                      visible: true,
                      autoRotate: false,
                      autoHide: true,
                  },
                  title: {
                      visible: false,
                      offset: 12,
                  },
              },
              tooltip: {
                  visible: true,
                  shared: true,
                  showCrosshairs: false,
                  showMarkers: false,
              },
              label: {
                  visible: true,
                  position: 'left',
                  adjustColor: true,
              },
              legend: {
                  visible: false,
                  position: 'top-left',
              },
              interactions: [
                  { type: 'tooltip' },
                  { type: 'active-region' },
                  { type: 'legend-active' },
                  { type: 'legend-filter' },
              ],
              conversionTag: {
                  visible: false,
              },
          };
          return deepMix({}, _super.getDefaultOptions.call(this), cfg);
      };
      BaseBarLayer.prototype.beforeInit = function () {
          _super.prototype.beforeInit.call(this);
          var props = this.options;
          /** 响应式图形 */
          if (props.responsive && props.padding !== 'auto') {
              this.applyResponsive('preRender');
          }
      };
      BaseBarLayer.prototype.afterRender = function () {
          var props = this.options;
          this.renderLabel();
          /** 响应式 */
          if (props.responsive && props.padding !== 'auto') {
              this.applyResponsive('afterRender');
          }
          if (props.conversionTag.visible) {
              this.conversionTag = new ConversionTag(__assign({ view: this.view, field: props.xField, animation: props.animation === false ? false : true }, props.conversionTag));
          }
          _super.prototype.afterRender.call(this);
      };
      BaseBarLayer.prototype.geometryParser = function (dim, type) {
          if (dim === 'g2') {
              return G2_GEOM_MAP[type];
          }
          return PLOT_GEOM_MAP[type];
      };
      BaseBarLayer.prototype.processData = function (originData) {
          var inputData = originData ? originData.slice().reverse() : originData;
          var yField = this.options.yField;
          var processedData = [];
          each(inputData, function (data) {
              var d = clone(data);
              d[yField] = d[yField].toString();
              processedData.push(d);
          });
          return processedData;
      };
      BaseBarLayer.prototype.scale = function () {
          var props = this.options;
          var scales = {};
          /** 配置x-scale */
          scales[props.yField] = {
              type: 'cat',
          };
          if (has(props, 'yAxis')) {
              extractScale(scales[props.yField], props.yAxis);
          }
          /** 配置y-scale */
          scales[props.xField] = {};
          if (has(props, 'xAxis')) {
              extractScale(scales[props.xField], props.xAxis);
          }
          this.setConfig('scales', scales);
          _super.prototype.scale.call(this);
      };
      BaseBarLayer.prototype.coord = function () {
          this.setConfig('coordinate', {
              actions: [['transpose']],
          });
      };
      BaseBarLayer.prototype.axis = function () {
          var xAxis_parser = getComponent('axis', {
              plot: this,
              dim: 'x',
          });
          var yAxis_parser = getComponent('axis', {
              plot: this,
              dim: 'y',
          });
          /** 转置坐标系特殊配置 */
          if (xAxis_parser) {
              xAxis_parser.position = 'left';
          }
          if (yAxis_parser) {
              yAxis_parser.position = 'bottom';
          }
          var axesConfig = {};
          axesConfig[this.options.xField] = xAxis_parser;
          axesConfig[this.options.yField] = yAxis_parser;
          /** 存储坐标轴配置项到config */
          this.setConfig('axes', axesConfig);
      };
      //eslint-disable-next-line @typescript-eslint/no-unused-vars
      BaseBarLayer.prototype.adjustBar = function (bar) {
          return null;
      };
      BaseBarLayer.prototype.addGeometry = function () {
          var props = this.options;
          var bar = getGeom('interval', 'main', {
              positionFields: [props.yField, props.xField],
              plot: this,
          });
          if (props.conversionTag.visible) {
              this.setConfig('theme', deepMix({}, this.getTheme(), {
                  columnWidthRatio: 1 / 3,
              }));
          }
          this.adjustBar(bar);
          this.bar = bar;
          if (props.tooltip && (props.tooltip.fields || props.tooltip.formatter)) {
              this.geometryTooltip();
          }
          this.setConfig('geometry', bar);
      };
      BaseBarLayer.prototype.animation = function () {
          _super.prototype.animation.call(this);
          var props = this.options;
          if (props.animation === false) {
              /** 关闭动画 */
              this.bar.animate = false;
          }
      };
      BaseBarLayer.prototype.parseEvents = function () {
          _super.prototype.parseEvents.call(this, EventParser);
      };
      BaseBarLayer.prototype.renderLabel = function () {
          var scales = this.config.scales;
          var _a = this.options, label = _a.label, xField = _a.xField;
          var scale = scales[xField];
          if (label === null || label === void 0 ? void 0 : label.visible) {
              var geometry = getGeometryByType(this.view, 'interval');
              this.doRenderLabel(geometry, __assign({ type: 'bar', formatter: scale.formatter && (function (value) { return scale.formatter(value); }) }, this.options.label));
          }
      };
      BaseBarLayer.prototype.geometryTooltip = function () {
          this.bar.tooltip = {};
          var tooltipOptions = this.options.tooltip;
          if (tooltipOptions.fields) {
              this.bar.tooltip.fields = tooltipOptions.fields;
          }
          if (tooltipOptions.formatter) {
              this.bar.tooltip.callback = tooltipOptions.formatter;
              if (!tooltipOptions.fields) {
                  this.bar.tooltip.fields = [this.options.xField, this.options.yField];
                  if (this.options.colorField) {
                      this.bar.tooltip.fields.push(this.options.colorField);
                  }
              }
          }
      };
      BaseBarLayer.prototype.applyResponsive = function (stage) {
          var _this = this;
          var methods = responsiveMethods[stage];
          each(methods, function (r) {
              var responsive = r;
              responsive.method(_this);
          });
      };
      BaseBarLayer.prototype.getLabelOptionsByPosition = function (position) {
          if (position === 'middle') {
              return {
                  offset: 0,
              };
          }
          if (position === 'left') {
              return {
                  offset: 7,
                  style: {
                      stroke: null,
                      lineWidth: 0,
                  },
              };
          }
          if (position === 'right') {
              return {
                  offset: 4,
              };
          }
      };
      return BaseBarLayer;
  }(ViewLayer));
  export default BaseBarLayer;
  registerPlotType('bar', BaseBarLayer);
  //# sourceMappingURL=layer.js.map