"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.getTimeSeriesChartConfig = void 0;
const savedCharts_1 = require("../../../../../types/savedCharts");
const formatFieldLabel_1 = require("../../shared/formatFieldLabel");
const getTimeSeriesChartConfig = (config, metricQuery, metadata, fieldsMap) => {
    const metrics = config.yMetrics;
    return {
        type: savedCharts_1.ChartType.CARTESIAN,
        config: {
            layout: {
                xField: metricQuery.dimensions[0],
                yField: metricQuery.metrics,
            },
            eChartsConfig: {
                ...(metadata.title ? { title: { text: metadata.title } } : {}),
                legend: {
                    show: true,
                    type: 'scroll',
                },
                grid: { containLabel: true },
                xAxis: [
                    {
                        ...(config.xAxisLabel
                            ? { name: config.xAxisLabel }
                            : {}),
                    },
                ],
                yAxis: [
                    {
                        ...(config.yAxisLabel
                            ? { name: config.yAxisLabel }
                            : {}),
                    },
                ],
                series: metrics.map((metric) => ({
                    type: savedCharts_1.CartesianSeriesType.LINE,
                    yAxisIndex: 0,
                    ...(config.lineType === 'area' && { areaStyle: {} }),
                    name: (0, formatFieldLabel_1.formatFieldLabel)(metric, fieldsMap),
                    encode: {
                        xRef: { field: config.xDimension },
                        yRef: { field: metric },
                    },
                })),
            },
        },
    };
};
exports.getTimeSeriesChartConfig = getTimeSeriesChartConfig;
//# sourceMappingURL=getTimeSeriesChartConfig.js.map