import { getCommonEChartsConfig } from '../shared/getCommonEChartsConfig';
/**
 * Generates vertical bar chart echarts config for server-side rendering
 */
export const getVerticalBarChartEchartsConfig = async (vizTool, rows, fieldsMap, sorts, getPivotedResults) => {
    let chartData = rows;
    let metrics = vizTool.vizConfig.yMetrics;
    if (vizTool.vizConfig.breakdownByDimension) {
        const pivoted = await getPivotedResults(rows, fieldsMap, [vizTool.vizConfig.breakdownByDimension], vizTool.vizConfig.yMetrics, sorts);
        chartData = pivoted.results;
        metrics = pivoted.metrics;
    }
    return {
        ...getCommonEChartsConfig({
            title: vizTool.title,
            showLegend: metrics.length > 1,
            chartData,
            xAxisLabel: vizTool.vizConfig.xAxisLabel,
            yAxisLabel: vizTool.vizConfig.yAxisLabel,
        }),
        xAxis: [
            {
                type: vizTool.vizConfig.xAxisType,
                ...(vizTool.vizConfig.xAxisLabel
                    ? { name: vizTool.vizConfig.xAxisLabel }
                    : {}),
            },
        ],
        yAxis: [
            {
                type: 'value',
                ...(vizTool.vizConfig.yAxisLabel
                    ? { name: vizTool.vizConfig.yAxisLabel }
                    : {}),
            },
        ],
        series: metrics.map((metric) => ({
            type: 'bar',
            name: metric,
            encode: {
                x: vizTool.vizConfig.xDimension,
                y: metric,
            },
            ...(vizTool.vizConfig.stackBars ? { stack: 'stack' } : {}),
        })),
    };
};
//# sourceMappingURL=getVerticalBarChartEchartsConfig.js.map