import { ChartTypeEnum } from "../../../../../utils/index.js";
const horizontalTypes = [
    ChartTypeEnum.Bar,
    ChartTypeEnum.BarParallel,
    ChartTypeEnum.BarPercent
];
const isHorizontalBar = (chartType)=>horizontalTypes.includes(chartType);
const getBarGrowOptions = (isHorizontal)=>(_datum, _element, _opt, context)=>{
        const overall = context.vchart.getChart().getComponentsByType('cartesianAxis-linear')[0]._scale.range()[0];
        return isHorizontal ? {
            overall
        } : {
            orient: 'negative',
            overall
        };
    };
const growBar = (chartType)=>{
    const isHorizontal = isHorizontalBar(chartType);
    return {
        type: isHorizontal ? 'growWidthIn' : 'growHeightIn',
        oneByOne: false,
        options: getBarGrowOptions(isHorizontal),
        controlOptions: {
            immediatelyApply: true
        }
    };
};
const fadeInBar = ()=>({
        type: 'fadeIn',
        oneByOne: true
    });
const setRandomDataKey = (spec)=>{
    if (!spec?.data?.[0]?.values) return;
    const dataKey = 'dataKey';
    spec.data[0].values.forEach((datum)=>datum[dataKey] = Math.random());
    spec.dataKey = dataKey;
    if ('common' === spec.type && Array.isArray(spec.series)) spec.series.forEach((series)=>series.dataKey = dataKey);
};
const getBarMoveOptions = (chartType, orient)=>{
    const direction = isHorizontalBar(chartType) ? 'y' : 'x';
    const size = 'x' === direction ? 'width' : 'height';
    const offsetSign = 'in' === orient ? 1 : -1;
    return {
        direction,
        orient: 'negative',
        point: (_datum, element, opt)=>({
                [direction]: element.getGraphicAttribute(direction) + offsetSign * opt[size]
            })
    };
};
const moveInBar = (chartType, spec, isUpdate = false)=>{
    if (!isUpdate && spec) setRandomDataKey(spec);
    const excludeChannels = isHorizontalBar(chartType) ? [
        'x'
    ] : [
        'y'
    ];
    return {
        type: 'moveIn',
        options: {
            ...getBarMoveOptions(chartType, 'in'),
            excludeChannels
        }
    };
};
const moveOutBar = (chartType)=>({
        type: 'moveOut',
        options: getBarMoveOptions(chartType, 'out')
    });
export { fadeInBar, growBar, isHorizontalBar, moveInBar, moveOutBar };

//# sourceMappingURL=barMotion.js.map