import assertUnreachable from '../utils/assertUnreachable';
export var ChartKind;
(function (ChartKind) {
    ChartKind["LINE"] = "line";
    ChartKind["HORIZONTAL_BAR"] = "horizontal_bar";
    ChartKind["VERTICAL_BAR"] = "vertical_bar";
    ChartKind["SCATTER"] = "scatter";
    ChartKind["AREA"] = "area";
    ChartKind["MIXED"] = "mixed";
    ChartKind["PIE"] = "pie";
    ChartKind["TABLE"] = "table";
    ChartKind["BIG_NUMBER"] = "big_number";
    ChartKind["FUNNEL"] = "funnel";
    ChartKind["CUSTOM"] = "custom";
    ChartKind["TREEMAP"] = "treemap";
    ChartKind["GAUGE"] = "gauge";
    ChartKind["MAP"] = "map";
    ChartKind["SANKEY"] = "sankey";
})(ChartKind || (ChartKind = {}));
export var ChartType;
(function (ChartType) {
    ChartType["CARTESIAN"] = "cartesian";
    ChartType["TABLE"] = "table";
    ChartType["BIG_NUMBER"] = "big_number";
    ChartType["PIE"] = "pie";
    ChartType["FUNNEL"] = "funnel";
    ChartType["TREEMAP"] = "treemap";
    ChartType["GAUGE"] = "gauge";
    ChartType["CUSTOM"] = "custom";
    ChartType["MAP"] = "map";
    ChartType["SANKEY"] = "sankey";
})(ChartType || (ChartType = {}));
export var ComparisonFormatTypes;
(function (ComparisonFormatTypes) {
    ComparisonFormatTypes["RAW"] = "raw";
    ComparisonFormatTypes["PERCENTAGE"] = "percentage";
})(ComparisonFormatTypes || (ComparisonFormatTypes = {}));
export var ComparisonDiffTypes;
(function (ComparisonDiffTypes) {
    ComparisonDiffTypes["POSITIVE"] = "positive";
    ComparisonDiffTypes["NEGATIVE"] = "negative";
    ComparisonDiffTypes["NONE"] = "none";
    ComparisonDiffTypes["NAN"] = "NaN";
    ComparisonDiffTypes["UNDEFINED"] = "undefined";
})(ComparisonDiffTypes || (ComparisonDiffTypes = {}));
export const PieChartValueLabels = {
    hidden: 'Hidden',
    inside: 'Inside',
    outside: 'Outside',
};
export const PieChartLegendPositions = {
    horizontal: 'Horizontal',
    vertical: 'Vertical',
};
export const PieChartLegendPositionDefault = Object.keys(PieChartLegendPositions)[0];
export const PieChartLegendLabelMaxLengthDefault = 30;
export const PieChartTooltipLabelMaxLength = 40;
export var MapChartLocation;
(function (MapChartLocation) {
    MapChartLocation["USA"] = "USA";
    MapChartLocation["WORLD"] = "world";
    MapChartLocation["EUROPE"] = "europe";
    MapChartLocation["CUSTOM"] = "custom";
})(MapChartLocation || (MapChartLocation = {}));
export var MapChartType;
(function (MapChartType) {
    MapChartType["SCATTER"] = "scatter";
    MapChartType["AREA"] = "area";
    MapChartType["HEATMAP"] = "heatmap";
    MapChartType["HEXBIN"] = "hexbin";
})(MapChartType || (MapChartType = {}));
export var MapHexbinSizingMode;
(function (MapHexbinSizingMode) {
    /** Resolution is derived from current map zoom level. */
    MapHexbinSizingMode["DYNAMIC"] = "dynamic";
    /** Resolution is fixed by the user, independent of zoom. */
    MapHexbinSizingMode["FIXED"] = "fixed";
})(MapHexbinSizingMode || (MapHexbinSizingMode = {}));
export var MapHexbinValueBasis;
(function (MapHexbinValueBasis) {
    /** Color cells by the count of points they contain. */
    MapHexbinValueBasis["COUNT"] = "count";
    /** Color cells by an aggregation over a chosen value field. */
    MapHexbinValueBasis["FIELD"] = "field";
})(MapHexbinValueBasis || (MapHexbinValueBasis = {}));
export var MapHexbinAggregation;
(function (MapHexbinAggregation) {
    MapHexbinAggregation["SUM"] = "sum";
    MapHexbinAggregation["AVG"] = "avg";
    MapHexbinAggregation["MIN"] = "min";
    MapHexbinAggregation["MAX"] = "max";
})(MapHexbinAggregation || (MapHexbinAggregation = {}));
export var MapTileBackground;
(function (MapTileBackground) {
    MapTileBackground["NONE"] = "none";
    MapTileBackground["OPENSTREETMAP"] = "openstreetmap";
    MapTileBackground["LIGHT"] = "light";
    MapTileBackground["DARK"] = "dark";
    MapTileBackground["SATELLITE"] = "satellite";
    MapTileBackground["VOYAGER"] = "voyager";
})(MapTileBackground || (MapTileBackground = {}));
export var FunnelChartDataInput;
(function (FunnelChartDataInput) {
    FunnelChartDataInput["ROW"] = "row";
    FunnelChartDataInput["COLUMN"] = "column";
})(FunnelChartDataInput || (FunnelChartDataInput = {}));
export var FunnelChartLabelPosition;
(function (FunnelChartLabelPosition) {
    FunnelChartLabelPosition["INSIDE"] = "inside";
    FunnelChartLabelPosition["LEFT"] = "left";
    FunnelChartLabelPosition["RIGHT"] = "right";
    FunnelChartLabelPosition["HIDDEN"] = "hidden";
})(FunnelChartLabelPosition || (FunnelChartLabelPosition = {}));
export var FunnelChartLegendPosition;
(function (FunnelChartLegendPosition) {
    FunnelChartLegendPosition["HORIZONTAL"] = "horizontal";
    FunnelChartLegendPosition["VERTICAL"] = "vertical";
})(FunnelChartLegendPosition || (FunnelChartLegendPosition = {}));
export var CartesianSeriesType;
(function (CartesianSeriesType) {
    CartesianSeriesType["LINE"] = "line";
    CartesianSeriesType["BAR"] = "bar";
    CartesianSeriesType["SCATTER"] = "scatter";
    CartesianSeriesType["AREA"] = "area";
})(CartesianSeriesType || (CartesianSeriesType = {}));
export const isPivotReferenceWithValues = (value) => !!value.pivotValues && value.pivotValues.length > 0;
export const TooltipSortByOptions = {
    DEFAULT: 'default',
    ALPHABETICAL: 'alphabetical',
    VALUE_ASCENDING: 'value_ascending',
    VALUE_DESCENDING: 'value_descending',
};
export var XAxisSortType;
(function (XAxisSortType) {
    XAxisSortType["DEFAULT"] = "default";
    XAxisSortType["CATEGORY"] = "category";
    XAxisSortType["BAR_TOTALS"] = "bar_totals";
})(XAxisSortType || (XAxisSortType = {}));
export var XAxisSort;
(function (XAxisSort) {
    XAxisSort["DEFAULT"] = "default";
    XAxisSort["DEFAULT_REVERSED"] = "default_reversed";
    XAxisSort["ASCENDING"] = "ascending";
    XAxisSort["DESCENDING"] = "descending";
    XAxisSort["BAR_TOTALS_ASCENDING"] = "bar_totals_ascending";
    XAxisSort["BAR_TOTALS_DESCENDING"] = "bar_totals_descending";
})(XAxisSort || (XAxisSort = {}));
export function getXAxisSort(xAxis) {
    if (!xAxis)
        return XAxisSort.DEFAULT;
    switch (xAxis.sortType) {
        case XAxisSortType.CATEGORY:
            return xAxis.inverse ? XAxisSort.DESCENDING : XAxisSort.ASCENDING;
        case XAxisSortType.BAR_TOTALS:
            return xAxis.inverse
                ? XAxisSort.BAR_TOTALS_DESCENDING
                : XAxisSort.BAR_TOTALS_ASCENDING;
        case XAxisSortType.DEFAULT:
        default:
            return xAxis.inverse
                ? XAxisSort.DEFAULT_REVERSED
                : XAxisSort.DEFAULT;
    }
}
export const isCompleteLayout = (value) => !!value && !!value.xField && !!value.yField && value.yField.length > 0;
export const isCompleteEchartsConfig = (value) => !!value && !!value.series && value.series.length > 0;
export const isCartesianChartConfig = (value) => !!value && 'layout' in value && 'eChartsConfig' in value;
export const isBigNumberConfig = (value) => !!value && !isCartesianChartConfig(value);
export const isTableChartConfig = (value) => !!value && !isCartesianChartConfig(value);
export const isPieChartConfig = (value) => !!value && 'isDonut' in value;
export const getCustomLabelsFromColumnProperties = (columns) => columns
    ? Object.entries(columns).reduce((acc, [key, value]) => value.name
        ? {
            ...acc,
            [key]: value.name,
        }
        : acc, {})
    : undefined;
export const getCustomLabelsFromTableConfig = (config) => config && isTableChartConfig(config)
    ? getCustomLabelsFromColumnProperties(config.columns)
    : undefined;
export const hashFieldReference = (reference) => reference.pivotValues
    ? `${reference.field}.${reference.pivotValues
        .map(({ field, value }) => `${field}.${value}`)
        .join('.')}`
    : reference.field;
export const getSeriesId = (series) => `${hashFieldReference(series.encode.xRef)}|${hashFieldReference(series.encode.yRef)}`;
export const ECHARTS_DEFAULT_COLORS = [
    '#5470c6',
    '#fc8452',
    '#91cc75',
    '#fac858',
    '#ee6666',
    '#73c0de',
    '#3ba272',
    '#9a60b4',
    '#ea7ccc',
];
export const getDefaultSeriesColor = (index) => ECHARTS_DEFAULT_COLORS[index % ECHARTS_DEFAULT_COLORS.length];
export const getDefaultResolvedColorPalette = () => ({
    colors: ECHARTS_DEFAULT_COLORS,
    darkColors: null,
    paletteUuid: null,
    paletteName: null,
    source: { type: 'default' },
});
export const isSeriesWithMixedChartTypes = (series) => new Set(series?.map(({ type, areaStyle }) => `${type}${type === CartesianSeriesType.LINE ? areaStyle : undefined}`)).size >= 2;
export const getChartType = (chartKind) => {
    if (chartKind === undefined)
        return ChartType.CARTESIAN;
    switch (chartKind) {
        case ChartKind.PIE:
            return ChartType.PIE;
        case ChartKind.FUNNEL:
            return ChartType.FUNNEL;
        case ChartKind.BIG_NUMBER:
            return ChartType.BIG_NUMBER;
        case ChartKind.TABLE:
            return ChartType.TABLE;
        case ChartKind.TREEMAP:
            return ChartType.TREEMAP;
        case ChartKind.GAUGE:
            return ChartType.GAUGE;
        case ChartKind.SANKEY:
            return ChartType.SANKEY;
        default:
            return ChartType.CARTESIAN;
    }
};
export const getChartKind = (chartType, value) => {
    switch (chartType) {
        case ChartType.PIE:
            return ChartKind.PIE;
        case ChartType.FUNNEL:
            return ChartKind.FUNNEL;
        case ChartType.BIG_NUMBER:
            return ChartKind.BIG_NUMBER;
        case ChartType.TABLE:
            return ChartKind.TABLE;
        case ChartType.CUSTOM:
            return ChartKind.CUSTOM;
        case ChartType.CARTESIAN:
            if (isCartesianChartConfig(value)) {
                const { series } = value.eChartsConfig;
                if (isSeriesWithMixedChartTypes(series)) {
                    return ChartKind.MIXED;
                }
                const type = series?.[0]?.type;
                if (!type)
                    return undefined;
                switch (type) {
                    case CartesianSeriesType.AREA:
                        return ChartKind.AREA;
                    case CartesianSeriesType.BAR:
                        return value.layout.flipAxes
                            ? ChartKind.HORIZONTAL_BAR
                            : ChartKind.VERTICAL_BAR;
                    case CartesianSeriesType.LINE:
                        return series?.[0]?.areaStyle
                            ? ChartKind.AREA
                            : ChartKind.LINE;
                    case CartesianSeriesType.SCATTER:
                        return ChartKind.SCATTER;
                    default:
                        return assertUnreachable(type, `Unknown cartesian series type: ${type}`);
                }
            }
            return undefined;
        case ChartType.TREEMAP:
            return ChartKind.TREEMAP;
        case ChartType.GAUGE:
            return ChartKind.GAUGE;
        case ChartType.MAP:
            return ChartKind.MAP;
        case ChartType.SANKEY:
            return ChartKind.SANKEY;
        default:
            return assertUnreachable(chartType, `Unknown chart type: ${chartType}`);
    }
};
export const getEChartsChartTypeFromChartKind = (chartKind) => {
    switch (chartKind) {
        case ChartKind.VERTICAL_BAR:
            return CartesianSeriesType.BAR;
        case ChartKind.LINE:
            return CartesianSeriesType.LINE;
        case ChartKind.AREA:
            return CartesianSeriesType.AREA;
        case ChartKind.SCATTER:
            return CartesianSeriesType.SCATTER;
        default:
            return CartesianSeriesType.BAR;
    }
};
export const getHiddenTableFields = (config) => {
    // get hidden fields from chart config
    if (config.type === 'table' && config.config?.columns) {
        return Object.entries(config.config?.columns).reduce((acc, [col, props]) => {
            if (props.visible === false)
                return [...acc, col];
            return acc;
        }, []);
    }
    return [];
};
//# sourceMappingURL=savedCharts.js.map