"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.getTimeSeriesChartEchartsConfig = void 0;
const getCommonEChartsConfig_1 = require("../shared/getCommonEChartsConfig");
/**
 * Generates time series chart echarts config for server-side rendering
 */
const getTimeSeriesChartEchartsConfig = async (vizTool, rows, fieldsMap, sorts, getPivotedResults) => {
    let chartData = rows;
    let metrics = vizTool.vizConfig.yMetrics;
    if (vizTool.vizConfig.breakdownByDimension) {
        // Sort the pivoted data
        const pivoted = await getPivotedResults(rows, fieldsMap, [vizTool.vizConfig.breakdownByDimension], vizTool.vizConfig.yMetrics, sorts);
        chartData = pivoted.results;
        metrics = pivoted.metrics;
    }
    return {
        ...(0, getCommonEChartsConfig_1.getCommonEChartsConfig)({
            title: vizTool.title,
            showLegend: metrics.length > 1,
            chartData,
            xAxisLabel: vizTool.vizConfig.xAxisLabel,
            yAxisLabel: vizTool.vizConfig.yAxisLabel,
            useLinePointer: true,
        }),
        xAxis: [
            {
                type: 'time',
                ...(vizTool.vizConfig.xAxisLabel
                    ? { name: vizTool.vizConfig.xAxisLabel }
                    : {}),
            },
        ],
        yAxis: [
            {
                type: 'value',
                ...(vizTool.vizConfig.yAxisLabel
                    ? { name: vizTool.vizConfig.yAxisLabel }
                    : {}),
            },
        ],
        series: metrics.map((metric) => ({
            type: 'line',
            name: metric,
            encode: {
                x: vizTool.vizConfig.xDimension,
                y: metric,
            },
            ...(vizTool.vizConfig.lineType === 'area' && { areaStyle: {} }),
        })),
    };
};
exports.getTimeSeriesChartEchartsConfig = getTimeSeriesChartEchartsConfig;
//# sourceMappingURL=getTimeSeriesChartEchartsConfig.js.map