"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.adaptor = exports.axis = exports.meta = void 0;
var tslib_1 = require("tslib");
var common_1 = require("../../adaptor/common");
var utils_1 = require("../../utils");
var geometries_1 = require("../../adaptor/geometries");
var pattern_1 = require("../../adaptor/pattern");
var utils_2 = require("../../utils");
var utils_3 = require("./utils");
/**
 * geometry 处理
 * @param params
 */
function geometry(params) {
    var chart = params.chart, options = params.options;
    var style = options.barStyle, color = options.color, tooltip = options.tooltip, colorField = options.colorField, type = options.type, xField = options.xField, yField = options.yField, data = options.data;
    // 处理不合法的数据
    var processData = utils_2.processIllegalData(data, yField);
    chart.data(processData);
    var p = utils_1.deepAssign({}, params, {
        options: {
            tooltip: tooltip,
            seriesField: colorField,
            interval: {
                style: style,
                color: color,
                shape: type === 'line' ? 'line' : 'intervel',
            },
            // 柱子的一些样式设置：柱子最小宽度、柱子最大宽度、柱子背景
            minColumnWidth: options.minBarWidth,
            maxColumnWidth: options.maxBarWidth,
            columnBackground: options.barBackground,
        },
    });
    geometries_1.interval(p);
    if (type === 'line') {
        geometries_1.point({
            chart: chart,
            options: { xField: xField, yField: yField, seriesField: colorField, point: { shape: 'circle', color: color } },
        });
    }
    return params;
}
/**
 * meta 配置
 * @param params
 */
function meta(params) {
    var _a;
    var options = params.options;
    var yField = options.yField, xField = options.xField, data = options.data, isStack = options.isStack, isGroup = options.isGroup, colorField = options.colorField, maxAngle = options.maxAngle;
    var actualData = isStack && !isGroup && colorField ? utils_3.getStackedData(data, xField, yField) : data;
    var processData = utils_2.processIllegalData(actualData, yField);
    return utils_1.flow(common_1.scale((_a = {},
        _a[yField] = {
            min: 0,
            max: utils_3.getScaleMax(maxAngle, yField, processData),
        },
        _a)))(params);
}
exports.meta = meta;
/**
 * coordinate 配置
 * @param params
 */
function coordinate(params) {
    var chart = params.chart, options = params.options;
    var radius = options.radius, innerRadius = options.innerRadius, startAngle = options.startAngle, endAngle = options.endAngle;
    chart
        .coordinate({
        type: 'polar',
        cfg: {
            radius: radius,
            innerRadius: innerRadius,
            startAngle: startAngle,
            endAngle: endAngle,
        },
    })
        .transpose();
    return params;
}
/**
 * axis 配置
 * @param params
 */
function axis(params) {
    var chart = params.chart, options = params.options;
    var xField = options.xField, xAxis = options.xAxis;
    chart.axis(xField, xAxis);
    return params;
}
exports.axis = axis;
/**
 * 数据标签
 * @param params
 */
function label(params) {
    var chart = params.chart, options = params.options;
    var label = options.label, yField = options.yField;
    var intervalGeometry = utils_1.findGeometry(chart, 'interval');
    // label 为 false, 空 则不显示 label
    if (!label) {
        intervalGeometry.label(false);
    }
    else {
        var callback = label.callback, cfg = tslib_1.__rest(label, ["callback"]);
        intervalGeometry.label({
            fields: [yField],
            callback: callback,
            cfg: tslib_1.__assign(tslib_1.__assign({}, utils_1.transformLabel(cfg)), { type: 'polar' }),
        });
    }
    return params;
}
/**
 * 图适配器
 * @param chart
 * @param options
 */
function adaptor(params) {
    return utils_1.flow(pattern_1.pattern('barStyle'), geometry, meta, axis, coordinate, common_1.interaction, common_1.animation, common_1.theme, common_1.tooltip, common_1.legend, common_1.annotation(), label)(params);
}
exports.adaptor = adaptor;
//# sourceMappingURL=adaptor.js.map