"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.getScatterChartConfig = void 0;
const savedCharts_1 = require("../../../../../../types/savedCharts");
const formatFieldLabel_1 = require("../../../shared/formatFieldLabel");
const formatPivotValueLabel_1 = require("../../shared/formatPivotValueLabel");
const getScatterChartConfig = ({ 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,
            },
            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) => {
                    const defaultProperties = {
                        type: savedCharts_1.CartesianSeriesType.SCATTER,
                        yAxisIndex: 0,
                        // Scatter charts should show symbols by default
                        showSymbol: true,
                    };
                    if (typeof metric === 'string') {
                        return {
                            ...defaultProperties,
                            name: (0, formatFieldLabel_1.formatFieldLabel)(metric, fieldsMap),
                            encode: {
                                xRef: { field: xDimension },
                                yRef: { field: metric },
                            },
                        };
                    }
                    return {
                        ...defaultProperties,
                        name: (0, formatPivotValueLabel_1.formatPivotValueLabel)(metric, fieldsMap),
                        encode: {
                            xRef: { field: xDimension },
                            yRef: metric,
                        },
                    };
                }),
            },
        },
    };
};
exports.getScatterChartConfig = getScatterChartConfig;
//# sourceMappingURL=scatter.js.map