"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), 
        setTimeout((() => {
            var _a, _b, _c, _d, _e, _f;
            if (null === (_a = exports.chartInstanceListColumnByColumnDirection[col]) || void 0 === _a ? void 0 : _a[i]) {
                const chartDimensionLinkage = table.options.chartDimensionLinkage;
                let isShowTooltip = !isScatter;
                if (!isScatter && "object" == typeof chartDimensionLinkage) if (isShowTooltip = null === (_b = chartDimensionLinkage.showTooltip) || void 0 === _b || _b, 
                i === rowEnd && isShowTooltip) {
                    const heightLimitToShowTooltipForEdgeRow = null !== (_c = chartDimensionLinkage.heightLimitToShowTooltipForEdgeRow) && void 0 !== _c ? _c : 0, {rowEnd: rowEnd1} = table.getBodyVisibleRowRange(0, -heightLimitToShowTooltipForEdgeRow);
                    if (rowEnd1 === rowEnd) isShowTooltip = !0; else {
                        const {rowEnd: rowEnd2} = table.getBodyVisibleRowRange(0, 5);
                        isShowTooltip = rowEnd2 !== rowEnd;
                    }
                } else if (i === rowStart && isShowTooltip) {
                    const heightLimitToShowTooltipForEdgeRow = null !== (_d = chartDimensionLinkage.heightLimitToShowTooltipForEdgeRow) && void 0 !== _d ? _d : 0, {rowStart: rowStart1} = table.getBodyVisibleRowRange(heightLimitToShowTooltipForEdgeRow, 0);
                    if (rowStart1 === rowStart) isShowTooltip = !0; else {
                        const {rowStart: rowStart2} = table.getBodyVisibleRowRange(0, -5);
                        isShowTooltip = rowStart2 !== rowStart;
                    }
                }
                if (isScatter) table.stateManager.hover.cellPos.col === col && table.stateManager.hover.cellPos.row === i || null === (_f = (_e = exports.chartInstanceListColumnByColumnDirection[col][i]).showCrosshair) || void 0 === _f || _f.call(_e, (axis => "left" === axis.layoutOrient ? positionValueOrYValue : dimensionValueOrXValue)); else {
                    const bodyBoundryTop = table.frozenRowCount ? table.getCellRelativeRect(col, table.frozenRowCount - 1).bottom : 0, absolutePositionTop = Math.max(bodyBoundryTop, table.getCellRelativeRect(col, i).top);
                    hideTooltip ? (table.stateManager.hover.cellPos.col === col && table.stateManager.hover.cellPos.row === i || exports.chartInstanceListColumnByColumnDirection[col][i].hideTooltip(), 
                    exports.chartInstanceListColumnByColumnDirection[col][i].setDimensionIndex(dimensionValueOrXValue, {
                        tooltip: !1,
                        showTooltipOption: {
                            x: canvasXY.x,
                            y: absolutePositionTop,
                            activeType: "dimension"
                        }
                    })) : exports.chartInstanceListColumnByColumnDirection[col][i].setDimensionIndex(dimensionValueOrXValue, {
                        tooltip: isShowTooltip,
                        showTooltipOption: {
                            x: canvasXY.x,
                            y: absolutePositionTop,
                            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), 
        setTimeout((() => {
            var _a, _b, _c, _d;
            if (null === (_a = exports.chartInstanceListRowByRowDirection[row]) || void 0 === _a ? void 0 : _a[i]) {
                const chartDimensionLinkage = table.options.chartDimensionLinkage;
                let isShowTooltip = !isScatter;
                if (!isScatter && "object" == typeof chartDimensionLinkage) if (isShowTooltip = null === (_b = chartDimensionLinkage.showTooltip) || void 0 === _b || _b, 
                i === colEnd && isShowTooltip) {
                    const widthLimitToShowTooltipForEdgeColumn = chartDimensionLinkage.widthLimitToShowTooltipForEdgeColumn, {colEnd: colEnd1} = table.getBodyVisibleColRange(0, -widthLimitToShowTooltipForEdgeColumn);
                    if (colEnd1 === colEnd) isShowTooltip = !0; else {
                        const {colEnd: colEnd2} = table.getBodyVisibleColRange(0, 5);
                        isShowTooltip = colEnd2 !== colEnd;
                    }
                } else if (i === colStart && isShowTooltip) {
                    const widthLimitToShowTooltipForEdgeColumn = chartDimensionLinkage.widthLimitToShowTooltipForEdgeColumn, {colStart: colStart1} = table.getBodyVisibleColRange(widthLimitToShowTooltipForEdgeColumn, 0);
                    if (colStart1 === colStart) isShowTooltip = !0; else {
                        const {colStart: colStart2} = table.getBodyVisibleColRange(0, -5);
                        isShowTooltip = colStart2 !== colStart;
                    }
                }
                if (isScatter) table.stateManager.hover.cellPos.col === i && table.stateManager.hover.cellPos.row === row || null === (_d = (_c = exports.chartInstanceListRowByRowDirection[row][i]).showCrosshair) || void 0 === _d || _d.call(_c, (axis => "left" === axis.layoutOrient ? positionValueOrYValue : dimensionValueOrXValue)); else {
                    const bodyBoundryLeft = table.frozenColCount ? table.getCellRelativeRect(table.frozenColCount - 1, row).right : 0, absolutePositionLeft = Math.max(bodyBoundryLeft, table.getCellRelativeRect(i, row).left);
                    hideTooltip ? (table.stateManager.hover.cellPos.col === i && table.stateManager.hover.cellPos.row === row || exports.chartInstanceListRowByRowDirection[row][i].hideTooltip(), 
                    exports.chartInstanceListRowByRowDirection[row][i].setDimensionIndex(dimensionValueOrXValue, {
                        tooltip: !1,
                        showTooltipOption: {
                            x: absolutePositionLeft,
                            y: canvasXY.y,
                            activeType: "dimension"
                        }
                    })) : exports.chartInstanceListRowByRowDirection[row][i].setDimensionIndex(dimensionValueOrXValue, {
                        tooltip: isShowTooltip,
                        showTooltipOption: {
                            x: absolutePositionLeft,
                            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
