text: "use strict";
  Object.defineProperty(exports, "__esModule", { value: true });
  exports.compareFunnel = void 0;
  var util_1 = require("@antv/util");
  var utils_1 = require("../../../utils");
  var tooltip_1 = require("../../../utils/tooltip");
  var base_1 = require("../../../adaptor/geometries/base");
  var constant_1 = require("../constant");
  var common_1 = require("./common");
  /**
   * 处理字段数据
   * @param params
   */
  function field(params) {
      var _a;
      var chart = params.chart, options = params.options;
      var _b = options.data, data = _b === void 0 ? [] : _b, yField = options.yField;
      // 绘制漏斗图
      chart.data(data);
      chart.scale((_a = {},
          _a[yField] = {
              sync: true,
          },
          _a));
      return params;
  }
  /**
   * geometry处理
   * @param params
   */
  function geometry(params) {
      var chart = params.chart, options = params.options;
      var data = options.data, xField = options.xField, yField = options.yField, color = options.color, compareField = options.compareField, isTransposed = options.isTransposed, tooltip = options.tooltip, maxSize = options.maxSize, minSize = options.minSize, label = options.label;
      chart.facet('mirror', {
          fields: [compareField],
          // 漏斗图的转置规则与分面相反，默认是垂直布局
          transpose: !isTransposed,
          padding: isTransposed ? 0 : [32, 0, 0, 0],
          eachView: function (view, facet) {
              var index = isTransposed ? facet.rowIndex : facet.columnIndex;
              if (!isTransposed) {
                  view.coordinate({
                      type: 'rect',
                      actions: [['transpose'], ['scale', index === 0 ? -1 : 1, -1]],
                  });
              }
              var formatterData = common_1.transformData(facet.data, data, {
                  yField: yField,
                  maxSize: maxSize,
                  minSize: minSize,
              });
              view.data(formatterData);
              // 绘制图形
              var _a = tooltip_1.getTooltipMapping(tooltip, [xField, yField, compareField]), fields = _a.fields, formatter = _a.formatter;
              var defaultFacetLabel = isTransposed
                  ? {
                      offset: index === 0 ? 10 : -23,
                      position: (index === 0 ? 'bottom' : 'top'),
                  }
                  : {
                      offset: 10,
                      position: 'left',
                      style: {
                          textAlign: index === 0 ? 'end' : 'start',
                      },
                  };
              base_1.geometry({
                  chart: view,
                  options: {
                      type: 'interval',
                      xField: xField,
                      yField: constant_1.FUNNEL_MAPPING_VALUE,
                      colorField: xField,
                      tooltipFields: util_1.isArray(fields) && fields.concat([constant_1.FUNNEL_PERCENT, constant_1.FUNNEL_CONVERSATION]),
                      mapping: {
                          shape: 'funnel',
                          tooltip: formatter,
                          color: color,
                          style: {
                              lineWidth: 1,
                              stroke: '#fff',
                          },
                      },
                      label: label === false ? false : utils_1.deepAssign({}, defaultFacetLabel, label),
                  },
              });
          },
      });
      return params;
  }
  /**
   * 转化率组件
   * @param params
   */
  function conversionTag(params) {
      var chart = params.chart, options = params.options;
      var conversionTag = options.conversionTag, isTransposed = options.isTransposed;
      chart.once('beforepaint', function () {
          chart.views.forEach(function (view, viewIndex) {
              var getLineCoordinate = function (datum, datumIndex, data, initLineOption) {
                  var ratio = viewIndex === 0 ? -1 : 1;
                  return utils_1.deepAssign({}, initLineOption, {
                      start: [datumIndex - 0.5, datum[constant_1.FUNNEL_MAPPING_VALUE]],
                      end: [datumIndex - 0.5, datum[constant_1.FUNNEL_MAPPING_VALUE] + 0.05],
                      text: isTransposed
                          ? {
                              style: {
                                  textAlign: 'start',
                              },
                          }
                          : {
                              offsetX: conversionTag !== false ? ratio * conversionTag.offsetX : 0,
                              style: {
                                  textAlign: viewIndex === 0 ? 'end' : 'start',
                              },
                          },
                  });
              };
              common_1.conversionTagComponent(getLineCoordinate)(utils_1.deepAssign({}, {
                  chart: view,
                  options: options,
              }));
          });
      });
      return params;
  }
  /**
   * 对比漏斗
   * @param chart
   * @param options
   */
  function compareFunnel(params) {
      return utils_1.flow(field, geometry, conversionTag)(params);
  }
  exports.compareFunnel = compareFunnel;
  //# sourceMappingURL=compare.js.map