import { CartesianSeriesType, ChartType, } from '../../../../../../types/savedCharts';
import { formatFieldLabel } from '../../../shared/formatFieldLabel';
import { formatPivotValueLabel } from '../../shared/formatPivotValueLabel';
export 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: 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: CartesianSeriesType.SCATTER,
                        yAxisIndex: 0,
                        // Scatter charts should show symbols by default
                        showSymbol: true,
                    };
                    if (typeof metric === 'string') {
                        return {
                            ...defaultProperties,
                            name: formatFieldLabel(metric, fieldsMap),
                            encode: {
                                xRef: { field: xDimension },
                                yRef: { field: metric },
                            },
                        };
                    }
                    return {
                        ...defaultProperties,
                        name: formatPivotValueLabel(metric, fieldsMap),
                        encode: {
                            xRef: { field: xDimension },
                            yRef: metric,
                        },
                    };
                }),
            },
        },
    };
};
//# sourceMappingURL=scatter.js.map