"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.adaptor = exports.axis = exports.legend = exports.LEGEND_SPACE = void 0;
var util_1 = require("@antv/util");
var common_1 = require("../../adaptor/common");
var geometries_1 = require("../../adaptor/geometries");
var utils_1 = require("../../utils");
var utils_2 = require("./utils");
var constant_1 = require("./constant");
require("./shape");
/** 图例默认预留空间 */
exports.LEGEND_SPACE = 40;
/**
 * color options 转换
 */
function transformColor(params, data) {
    var chart = params.chart, options = params.options;
    var color = options.color, setsField = options.setsField;
    if (typeof color !== 'function') {
        var colorPalette_1 = typeof color === 'string' ? [color] : color;
        if (!util_1.isArray(colorPalette_1)) {
            var _a = chart.getTheme(), colors10 = _a.colors10, colors20 = _a.colors20;
            colorPalette_1 = data.filter(function (d) { return d[setsField].length === 1; }).length <= 10 ? colors10 : colors20;
        }
        var colorMap_1 = utils_2.getColorMap(colorPalette_1, data, options);
        return function (datum) { return colorMap_1.get(datum[constant_1.ID_FIELD]) || colorPalette_1[0]; };
    }
    return color;
}
/**
 * 处理 padding
 */
function padding(params) {
    var chart = params.chart, options = params.options;
    var legend = options.legend, appendPadding = options.appendPadding, padding = options.padding;
    // 处理 legend 的位置. 默认预留 40px, 业务上可以通过 appendPadding 增加
    var tempPadding = utils_1.normalPadding(appendPadding);
    if (legend !== false) {
        tempPadding = utils_1.getAdjustAppendPadding(appendPadding, util_1.get(legend, 'position'), exports.LEGEND_SPACE);
    }
    chart.appendPadding = utils_1.resolveAllPadding([tempPadding, padding]);
    return params;
}
/**
 * geometry 处理
 * @param params
 */
function geometry(params) {
    var chart = params.chart, options = params.options;
    var pointStyle = options.pointStyle, label = options.label, setsField = options.setsField, sizeField = options.sizeField;
    // 获取容器大小
    var _a = utils_1.normalPadding(chart.appendPadding), t = _a[0], r = _a[1], b = _a[2], l = _a[3];
    // 处理 legend 的位置. 默认预留 40px, 业务上可以通过 appendPadding 增加
    var customInfo = { offsetX: l, offsetY: t, label: label };
    // coordinateBBox + appendPadding = viewBBox, 不需要再计算 appendPadding 部分，因此直接使用 viewBBox
    var _b = chart.viewBBox, width = _b.width, height = _b.height;
    var vennData = utils_2.layoutVennData(options, width - (r + l), height - (t + b), 0);
    chart.data(vennData);
    var ext = geometries_1.schema(utils_1.deepAssign({}, params, {
        options: {
            xField: 'x',
            yField: 'y',
            sizeField: sizeField,
            seriesField: constant_1.ID_FIELD,
            rawFields: [setsField, sizeField],
            // 不使用 G2 的label，直接在自定义 shape 中实现
            label: false,
            schema: {
                shape: 'venn',
                style: pointStyle,
                color: transformColor(params, vennData),
            },
        },
    })).ext;
    var geometry = ext.geometry;
    geometry.customInfo(customInfo);
    return params;
}
/**
 * legend 配置
 * @param params
 */
function legend(params) {
    var chart = params.chart, options = params.options;
    var legend = options.legend, sizeField = options.sizeField;
    chart.legend(constant_1.ID_FIELD, legend);
    // 强制不开启 连续图例
    chart.legend(sizeField, false);
    return params;
}
exports.legend = legend;
/**
 * 默认关闭坐标轴
 * @param params
 */
function axis(params) {
    var chart = params.chart;
    chart.axis(false);
    return params;
}
exports.axis = axis;
/**
 * 图适配器
 * @param chart
 * @param options
 */
function adaptor(params) {
    // flow 的方式处理所有的配置到 G2 API
    return utils_1.flow(padding, common_1.theme, geometry, common_1.scale({}), legend, axis, common_1.tooltip, common_1.interaction, common_1.animation
    // ... 其他的 adaptor flow
    )(params);
}
exports.adaptor = adaptor;
//# sourceMappingURL=adaptor.js.map