"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.getHorizontalBarChartConfig = void 0;
const savedCharts_1 = require("../../../../../../types/savedCharts");
const formatFieldLabel_1 = require("../../../shared/formatFieldLabel");
const getHorizontalBarChartConfig = ({ queryTool, metricQuery, fieldsMap, chartConfig, metadata, }) => {
    const { dimensions, metrics } = queryTool.queryConfig;
    const xDimension = chartConfig?.xAxisDimension || dimensions[0];
    const yMetrics = chartConfig?.yAxisMetrics || metrics;
    return {
        type: savedCharts_1.ChartType.CARTESIAN,
        config: {
            layout: {
                xField: xDimension,
                yField: chartConfig?.yAxisMetrics || metricQuery.metrics,
                flipAxes: true, // This makes it horizontal
            },
            eChartsConfig: {
                ...(metadata.title ? { title: { text: metadata.title } } : {}),
                legend: {
                    show: true,
                    type: 'scroll',
                },
                grid: { containLabel: true },
                xAxis: [
                    {
                        ...(chartConfig?.xAxisLabel
                            ? { name: chartConfig.xAxisLabel }
                            : {}),
                    },
                ],
                yAxis: [
                    {
                        ...(chartConfig?.yAxisLabel
                            ? { name: chartConfig.yAxisLabel }
                            : {}),
                    },
                ],
                series: yMetrics.map((metric) => ({
                    type: savedCharts_1.CartesianSeriesType.BAR,
                    yAxisIndex: 0,
                    ...(chartConfig?.stackBars && {
                        stack: metric,
                    }),
                    encode: {
                        xRef: { field: xDimension },
                        yRef: { field: metric },
                    },
                    name: (0, formatFieldLabel_1.formatFieldLabel)(metric, fieldsMap),
                })),
            },
        },
    };
};
exports.getHorizontalBarChartConfig = getHorizontalBarChartConfig;
//# sourceMappingURL=horizontalBar.js.map