"use strict";

Object.defineProperty(exports, "__esModule", {
    value: !0
}), exports.clearChartInstanceListByRowDirection = exports.generateChartInstanceListByRowDirection = exports.clearChartInstanceListByColumnDirection = exports.generateChartInstanceListByColumnDirection = exports.chartInstanceListRowByRowDirection = exports.chartInstanceListColumnByColumnDirection = void 0;

const vutils_1 = require("@visactor/vutils");

function generateChartInstanceListByColumnDirection(col, dimensionValueOrXValue, positionValueOrYValue, canvasXY, table, hideTooltip = !1, isScatter = !1) {
    var _a;
    (0, vutils_1.isValid)(exports.chartInstanceListColumnByColumnDirection[col]) || (exports.chartInstanceListColumnByColumnDirection[col] = {});
    const {rowStart: rowStart} = table.getBodyVisibleRowRange();
    let rowEnd = table.getBodyVisibleRowRange().rowEnd;
    rowEnd = Math.min(table.rowCount - 1 - table.bottomFrozenRowCount, rowEnd);
    for (let i = rowStart; i <= rowEnd; i++) {
        const cellGroup = table.scenegraph.getCell(col, i), chartNode = null === (_a = null == cellGroup ? void 0 : cellGroup.getChildren()) || void 0 === _a ? void 0 : _a[0];
        chartNode.addUpdateShapeAndBoundsTag(), exports.chartInstanceListColumnByColumnDirection[col][i] || (0, 
        vutils_1.isValid)(chartNode) && (chartNode.activeChartInstance || chartNode.activate(table), 
        exports.chartInstanceListColumnByColumnDirection[col][i] = chartNode.activeChartInstance), 
        table.stateManager.hover.cellPos.col === col && table.stateManager.hover.cellPos.row === i || setTimeout((() => {
            var _a, _b, _c, _d;
            if (null === (_a = exports.chartInstanceListColumnByColumnDirection[col]) || void 0 === _a ? void 0 : _a[i]) {
                const absolutePosition = table.getCellRelativeRect(col, i), chartDimensionLinkage = table.options.chartDimensionLinkage;
                let isShowTooltip = !isScatter;
                if (!isScatter && "object" == typeof chartDimensionLinkage && (isShowTooltip = null === (_b = chartDimensionLinkage.showTooltip) || void 0 === _b || _b, 
                i === rowEnd && isShowTooltip)) {
                    const heightLimitToShowTooltipForLastRow = chartDimensionLinkage.heightLimitToShowTooltipForLastRow, {rowEnd: rowEnd1} = table.getBodyVisibleRowRange(-heightLimitToShowTooltipForLastRow);
                    if (rowEnd1 === rowEnd) isShowTooltip = !0; else {
                        const {rowEnd: rowEnd2} = table.getBodyVisibleRowRange(5);
                        isShowTooltip = rowEnd2 !== rowEnd;
                    }
                }
                isScatter ? null === (_d = (_c = exports.chartInstanceListColumnByColumnDirection[col][i]).showCrosshair) || void 0 === _d || _d.call(_c, (axis => "left" === axis.layoutOrient ? positionValueOrYValue : dimensionValueOrXValue)) : hideTooltip ? (exports.chartInstanceListColumnByColumnDirection[col][i].hideTooltip(), 
                exports.chartInstanceListColumnByColumnDirection[col][i].setDimensionIndex(dimensionValueOrXValue, {
                    tooltip: !1,
                    showTooltipOption: {
                        x: canvasXY.x,
                        y: absolutePosition.top + 3,
                        activeType: "dimension"
                    }
                })) : exports.chartInstanceListColumnByColumnDirection[col][i].setDimensionIndex(dimensionValueOrXValue, {
                    tooltip: isShowTooltip,
                    showTooltipOption: {
                        x: canvasXY.x,
                        y: absolutePosition.top + 3,
                        activeType: "dimension"
                    }
                });
            }
        }), 0), table.scenegraph.updateNextFrame();
    }
}

function clearChartInstanceListByColumnDirection(col, excludedRow, table) {
    var _a;
    if ((0, vutils_1.isValid)(exports.chartInstanceListColumnByColumnDirection[col])) {
        for (const i in exports.chartInstanceListColumnByColumnDirection[col]) {
            if ((0, vutils_1.isValid)(excludedRow) && Number(i) === excludedRow) continue;
            const cellGroup = table.scenegraph.getCell(col, Number(i)), chartNode = null === (_a = null == cellGroup ? void 0 : cellGroup.getChildren()) || void 0 === _a ? void 0 : _a[0];
            chartNode.addUpdateShapeAndBoundsTag(), (0, vutils_1.isValid)(chartNode) && (chartNode.deactivate(table, {
                releaseChartInstance: !0,
                releaseColumnChartInstance: !1,
                releaseRowChartInstance: !1
            }), exports.chartInstanceListColumnByColumnDirection[col][i] = null);
        }
        delete exports.chartInstanceListColumnByColumnDirection[col];
    }
}

function generateChartInstanceListByRowDirection(row, dimensionValueOrXValue, positionValueOrYValue, canvasXY, table, hideTooltip = !1, isScatter = !1) {
    var _a;
    (0, vutils_1.isValid)(exports.chartInstanceListRowByRowDirection[row]) || (exports.chartInstanceListRowByRowDirection[row] = {});
    const {colStart: colStart} = table.getBodyVisibleColRange();
    let colEnd = table.getBodyVisibleColRange().colEnd;
    colEnd = Math.min(table.colCount - 1 - table.rightFrozenColCount, colEnd);
    for (let i = colStart; i <= colEnd; i++) {
        const cellGroup = table.scenegraph.getCell(i, row), chartNode = null === (_a = null == cellGroup ? void 0 : cellGroup.getChildren()) || void 0 === _a ? void 0 : _a[0];
        chartNode.addUpdateShapeAndBoundsTag(), exports.chartInstanceListRowByRowDirection[row][i] || (0, 
        vutils_1.isValid)(chartNode) && (chartNode.activeChartInstance || chartNode.activate(table), 
        exports.chartInstanceListRowByRowDirection[row][i] = chartNode.activeChartInstance), 
        table.stateManager.hover.cellPos.col === i && table.stateManager.hover.cellPos.row === row || setTimeout((() => {
            var _a, _b, _c, _d;
            if (null === (_a = exports.chartInstanceListRowByRowDirection[row]) || void 0 === _a ? void 0 : _a[i]) {
                const absolutePosition = table.getCellRelativeRect(i, row), chartDimensionLinkage = table.options.chartDimensionLinkage;
                let isShowTooltip = !isScatter;
                if (!isScatter && "object" == typeof chartDimensionLinkage && (isShowTooltip = null === (_b = chartDimensionLinkage.showTooltip) || void 0 === _b || _b, 
                i === colEnd && isShowTooltip)) {
                    const widthLimitToShowTooltipForLastColumn = chartDimensionLinkage.widthLimitToShowTooltipForLastColumn, {colEnd: colEnd1} = table.getBodyVisibleColRange(-widthLimitToShowTooltipForLastColumn);
                    if (colEnd1 === colEnd) isShowTooltip = !0; else {
                        const {colEnd: colEnd2} = table.getBodyVisibleColRange(5);
                        isShowTooltip = colEnd2 !== colEnd;
                    }
                }
                isScatter ? null === (_d = (_c = exports.chartInstanceListRowByRowDirection[row][i]).showCrosshair) || void 0 === _d || _d.call(_c, (axis => "left" === axis.layoutOrient ? positionValueOrYValue : dimensionValueOrXValue)) : hideTooltip ? (exports.chartInstanceListRowByRowDirection[row][i].hideTooltip(), 
                exports.chartInstanceListRowByRowDirection[row][i].setDimensionIndex(dimensionValueOrXValue, {
                    tooltip: !1,
                    showTooltipOption: {
                        x: absolutePosition.left + 3,
                        y: canvasXY.y,
                        activeType: "dimension"
                    }
                })) : exports.chartInstanceListRowByRowDirection[row][i].setDimensionIndex(dimensionValueOrXValue, {
                    tooltip: isShowTooltip,
                    showTooltipOption: {
                        x: absolutePosition.left + 3,
                        y: canvasXY.y,
                        activeType: "dimension"
                    }
                });
            }
        }), 0), table.scenegraph.updateNextFrame();
    }
}

function clearChartInstanceListByRowDirection(row, excludedCol, table) {
    var _a;
    if ((0, vutils_1.isValid)(exports.chartInstanceListRowByRowDirection[row])) for (const i in exports.chartInstanceListRowByRowDirection[row]) {
        if ((0, vutils_1.isValid)(excludedCol) && Number(i) === excludedCol) continue;
        const cellGroup = table.scenegraph.getCell(Number(i), row), chartNode = null === (_a = null == cellGroup ? void 0 : cellGroup.getChildren()) || void 0 === _a ? void 0 : _a[0];
        chartNode.addUpdateShapeAndBoundsTag(), (0, vutils_1.isValid)(chartNode) && (chartNode.deactivate(table, {
            releaseChartInstance: !0,
            releaseColumnChartInstance: !1,
            releaseRowChartInstance: !1
        }), exports.chartInstanceListRowByRowDirection[row][i] = null);
    }
    delete exports.chartInstanceListRowByRowDirection[row];
}

exports.chartInstanceListColumnByColumnDirection = {}, exports.chartInstanceListRowByRowDirection = {}, 
exports.generateChartInstanceListByColumnDirection = generateChartInstanceListByColumnDirection, 
exports.clearChartInstanceListByColumnDirection = clearChartInstanceListByColumnDirection, 
exports.generateChartInstanceListByRowDirection = generateChartInstanceListByRowDirection, 
exports.clearChartInstanceListByRowDirection = clearChartInstanceListByRowDirection;
//# sourceMappingURL=active-cell-chart-list.js.map
