"use strict";

Object.defineProperty(exports, "__esModule", {
    value: !0
}), exports.DataFilterBaseComponent = void 0;

const model_1 = require("../../util/model"), base_component_1 = require("../base/base-component"), interface_1 = require("../interface"), util_1 = require("./util"), register_1 = require("../../data/register"), vscale_1 = require("@visactor/vscale"), common_1 = require("../axis/cartesian/util/common"), vutils_1 = require("@visactor/vutils"), vdataset_1 = require("@visactor/vdataset"), compilable_data_1 = require("../../compile/data/compilable-data"), zoomable_1 = require("../../interaction/zoom/zoomable"), initialize_1 = require("../../data/initialize"), attribute_1 = require("../../constant/attribute");

class DataFilterBaseComponent extends base_component_1.BaseComponent {
    get relatedAxisComponent() {
        return this._relatedAxisComponent;
    }
    setStartAndEnd(start, end, rangeMode = [ "percent", "percent" ]) {
        const [startMode = "percent", endMode = "percent"] = rangeMode, startPercent = "percent" === startMode ? start : this.dataToStatePoint(start), endPercent = "percent" === endMode ? end : this.dataToStatePoint(end);
        this._handleChange(startPercent, endPercent, !0);
    }
    enableInteraction() {
        this._activeRoam = !0;
    }
    disableInteraction() {
        this._activeRoam = !1;
    }
    zoomIn(location) {
        this._handleChartZoom({
            zoomDelta: 1.2,
            zoomX: null == location ? void 0 : location.x,
            zoomY: null == location ? void 0 : location.y
        });
    }
    zoomOut(location) {
        this._handleChartZoom({
            zoomDelta: .8,
            zoomX: null == location ? void 0 : location.x,
            zoomY: null == location ? void 0 : location.y
        });
    }
    _handleChange(start, end, updateComponent) {
        var _a, _b;
        null !== (_b = null === (_a = this._spec) || void 0 === _a ? void 0 : _a.zoomLock) && void 0 !== _b && _b || end - start !== this._spanCache && (end - start < this._minSpan || end - start > this._maxSpan) ? this._shouldChange = !1 : (this._shouldChange = !0, 
        this._spanCache = end - start);
    }
    _isReverse() {
        const axis = this._relatedAxisComponent;
        if (!axis) return !1;
        const axisScale = axis.getScale();
        return axisScale.range()[0] > axisScale.range()[1] && (!axis.getInverse() || this._isHorizontal);
    }
    _updateRangeFactor(tag) {
        const axis = this._relatedAxisComponent, axisScale = axis.getScale(), reverse = this._isReverse(), newRangeFactor = reverse ? [ 1 - this._end, 1 - this._start ] : [ this._start, this._end ];
        if (reverse) switch (tag) {
          case "startHandler":
            axis.scaleRangeFactorEnd(newRangeFactor[1]);
            break;

          case "endHandler":
            axis.scaleRangeFactorStart(newRangeFactor[0]);
            break;

          default:
            axis.scaleRangeFactorStart(newRangeFactor[0], !0), axis.scaleRangeFactorEnd(newRangeFactor[1]);
        } else switch (tag) {
          case "startHandler":
            axis.scaleRangeFactorStart(newRangeFactor[0]);
            break;

          case "endHandler":
            axis.scaleRangeFactorEnd(newRangeFactor[1]);
            break;

          default:
            axis.scaleRangeFactorEnd(newRangeFactor[1], !0), axis.scaleRangeFactorStart(newRangeFactor[0]);
        }
        const newFactor = axisScale.rangeFactor();
        newFactor ? (this._start = reverse ? 1 - newFactor[1] : newFactor[0], this._end = reverse ? 1 - newFactor[0] : newFactor[1]) : (this._start = 0, 
        this._end = 1);
    }
    get visible() {
        return this._visible;
    }
    constructor(spec, options) {
        super(spec, options), this.layoutType = "none", this._orient = "left", this._cacheVisibility = void 0, 
        this._dataUpdating = !1, this._shouldChange = !0, this._stateField = "x", this._activeRoam = !0, 
        this._zoomAttr = {
            enable: !0,
            rate: 1,
            focus: !0
        }, this._dragAttr = {
            enable: !0,
            rate: 1,
            reverse: !0
        }, this._scrollAttr = {
            enable: !0,
            rate: 1,
            reverse: !0
        }, this.effect = {
            onZoomChange: tag => {
                var _a, _b;
                const axis = this._relatedAxisComponent;
                if (axis && "axis" === this._filterMode) {
                    const axisScale = axis.getScale(), axisSpec = axis.getSpec();
                    this._auto && this._getAxisBandSize(axisSpec) && this._spec.ignoreBandSize && (axisScale.bandwidth("auto"), 
                    axisScale.maxBandwidth("auto"), axisScale.minBandwidth("auto")), this._updateRangeFactor(tag), 
                    this._auto && (null === (_b = null === (_a = this._component) || void 0 === _a ? void 0 : _a.setStartAndEnd) || void 0 === _b || _b.call(_a, this._start, this._end)), 
                    axis.effect.scaleUpdate({
                        value: "force"
                    });
                } else (0, model_1.eachSeries)(this._regions, (s => {
                    var _a;
                    null === (_a = s.getViewData()) || void 0 === _a || _a.markRunning();
                }), {
                    userId: this._seriesUserId,
                    specIndex: this._seriesIndex
                }), (0, model_1.eachSeries)(this._regions, (s => {
                    s.reFilterViewData();
                }), {
                    userId: this._seriesUserId,
                    specIndex: this._seriesIndex
                });
            }
        }, this._visible = !0, this._handleStateChange = (startValue, endValue, tag) => {
            var _a, _b;
            return this._startValue = startValue, this._endValue = endValue, this._newDomain = this._parseDomainFromState(this._startValue, this._endValue), 
            null === (_b = (_a = this.effect).onZoomChange) || void 0 === _b || _b.call(_a, tag), 
            !0;
        }, this._handleChartZoom = (params, e) => {
            var _a, _b;
            if (!this._activeRoam || this._zoomAttr.filter && !this._zoomAttr.filter(params, e)) return;
            const {zoomDelta: zoomDelta, zoomX: zoomX, zoomY: zoomY} = params, {x: x, y: y} = this._regions[0].getLayoutStartPoint(), {width: width, height: height} = this._regions[0].getLayoutRect(), delta = Math.abs(this._start - this._end), zoomRate = null !== (_b = null === (_a = this._spec.roamZoom) || void 0 === _a ? void 0 : _a.rate) && void 0 !== _b ? _b : 1;
            if (delta >= 1 && zoomDelta < 1) return;
            if (delta <= .01 && zoomDelta > 1) return;
            const focusLoc = this._isHorizontal ? zoomX : zoomY, totalValue = delta * (zoomDelta - 1) * zoomRate;
            let startValue = totalValue / 2, endValue = totalValue / 2;
            if (focusLoc) {
                const startLoc = this._isHorizontal ? x : y, endLoc = this._isHorizontal ? width : height;
                startValue = Math.abs(startLoc - focusLoc) / Math.abs(endLoc - startLoc) * totalValue, 
                endValue = Math.abs(endLoc - focusLoc) / Math.abs(endLoc - startLoc) * totalValue;
            }
            const start = (0, vutils_1.clamp)(this._start + startValue, 0, 1), end = (0, vutils_1.clamp)(this._end - endValue, 0, 1);
            this._handleChange(Math.min(start, end), Math.max(start, end), !0);
        }, this._handleChartScroll = (params, e) => {
            var _a;
            if (!this._activeRoam || this._scrollAttr.filter && !this._scrollAttr.filter(params, e)) return !1;
            const {scrollX: scrollX, scrollY: scrollY} = params;
            let value = this._isHorizontal ? scrollX : scrollY;
            const active = this._isHorizontal ? (0, vutils_1.abs)(scrollX / scrollY) >= .5 : (0, 
            vutils_1.abs)(scrollY / scrollX) >= .5;
            this._scrollAttr.reverse || (value = -value), active && this._handleChartMove(value, null !== (_a = this._scrollAttr.rate) && void 0 !== _a ? _a : 1);
            const hasChange = 0 !== this._start && 1 !== this._end;
            return active && hasChange;
        }, this._handleChartDrag = (delta, e) => {
            var _a;
            if (!this._activeRoam || this._dragAttr.filter && !this._dragAttr.filter(delta, e)) return;
            const [dx, dy] = delta;
            let value = this._isHorizontal ? dx : dy;
            this._dragAttr.reverse && (value = -value), this._handleChartMove(value, null !== (_a = this._dragAttr.rate) && void 0 !== _a ? _a : 1);
        }, this._handleChartMove = (value, rate) => {
            const totalValue = this._isHorizontal ? this.getLayoutRect().width : this.getLayoutRect().height;
            if (Math.abs(value) >= 1e-6) if (value > 0 && this._end < 1) {
                const moveDelta = Math.min(1 - this._end, value / totalValue) * rate;
                this._handleChange(this._start + moveDelta, this._end + moveDelta, !0);
            } else if (value < 0 && this._start > 0) {
                const moveDelta = Math.max(-this._start, value / totalValue) * rate;
                this._handleChange(this._start + moveDelta, this._end + moveDelta, !0);
            }
            return !1;
        }, this._orient = (0, common_1.getOrient)(spec), this._isHorizontal = "horizontal" === (0, 
        common_1.getDirectionByOrient)(this._orient);
    }
    created() {
        super.created(), this._setAxisFromSpec(), this._setRegionsFromSpec(), this._initEvent(), 
        this._initData(), this._initStateScale(), this._setStateFromSpec();
    }
    initLayout() {
        super.initLayout(), this._layout && (this._layout.layoutOrient = this._orient);
    }
    _setAxisFromSpec() {
        if ((0, vutils_1.isValid)(this._spec.axisId) ? this._relatedAxisComponent = this._option.getComponentByUserId(this._spec.axisId) : (0, 
        vutils_1.isValid)(this._spec.axisIndex) && (this._relatedAxisComponent = this._option.getComponentByIndex("axes", this._spec.axisIndex)), 
        (0, vutils_1.isNil)(this._spec.field) && !this._relatedAxisComponent) {
            const axes = this._option.getComponentsByKey("axes"), sameOrientAxis = axes.find((cm => cm._orient === this._orient));
            if (sameOrientAxis) this._relatedAxisComponent = sameOrientAxis; else {
                const bandAxis = axes.find((cm => !(0, vscale_1.isContinuous)(cm.getScale().type)));
                this._relatedAxisComponent = bandAxis;
            }
        }
        this._relatedAxisComponent && "axis" === this._filterMode && (this._relatedAxisComponent.autoIndentOnce = !0);
    }
    _setRegionsFromSpec() {
        var _a, _b;
        this._regions = this._relatedAxisComponent ? this._relatedAxisComponent.getRegions() : this._option.getAllRegions();
        const bindSeriesFilter = this._relatedAxisComponent ? null === (_b = (_a = this._relatedAxisComponent).getBindSeriesFilter) || void 0 === _b ? void 0 : _b.call(_a) : null;
        if ((0, vutils_1.isValid)(bindSeriesFilter) && ((0, vutils_1.isValid)(bindSeriesFilter.userId) && (this._seriesUserId = (0, 
        vutils_1.array)(bindSeriesFilter.userId)), (0, vutils_1.isValid)(bindSeriesFilter.specIndex) && (this._seriesIndex = (0, 
        vutils_1.array)(bindSeriesFilter.specIndex))), (0, vutils_1.isValid)(this._spec.seriesId)) {
            const specSeriesId = (0, vutils_1.array)(this._spec.seriesId);
            this._seriesUserId ? this._seriesUserId = this._seriesUserId.filter((s => specSeriesId.includes(s))) : this._seriesUserId = specSeriesId;
        }
        if ((0, vutils_1.isValid)(this._spec.seriesIndex)) {
            const specSeriesIndex = (0, vutils_1.array)(this._spec.seriesIndex);
            this._seriesIndex ? this._seriesIndex = this._seriesIndex.filter((s => specSeriesIndex.includes(s))) : this._seriesIndex = specSeriesIndex;
        }
        if ((0, vutils_1.isValid)(this._spec.regionIndex)) {
            const regionsFromSpec = this._option.getRegionsInIndex((0, vutils_1.array)(this._spec.regionIndex));
            this._regions = this._regions.filter((r => regionsFromSpec.includes(r)));
        } else if ((0, vutils_1.isValid)(this._spec.regionId)) {
            const ids = (0, vutils_1.array)(this._spec.regionId);
            this._regions = ids.length ? this._regions.filter((r => ids.includes(r.id))) : [];
        } else ;
    }
    onDataUpdate() {
        var _a;
        const domain = this._computeDomainOfStateScale((0, vscale_1.isContinuous)(this._stateScale.type));
        this._stateScale.domain(domain, !1), this._handleChange(this._start, this._end, !0), 
        this._spec.auto && !(0, vutils_1.isEqual)(this._domainCache, domain) && (this._domainCache = domain, 
        this._dataUpdating = !0, null === (_a = this.getChart()) || void 0 === _a || _a.setLayoutTag(!0, null, !1));
    }
    _computeDomainOfStateScale(isContinuous) {
        if (this._spec.customDomain) return this._spec.customDomain;
        const domain = this._data.getLatestData().map((d => d[this._stateField]));
        if (isContinuous) {
            const domainNum = domain.map((n => 1 * n));
            return domain.length ? [ (0, vutils_1.minInArray)(domainNum), (0, vutils_1.maxInArray)(domainNum) ] : [ -1 / 0, 1 / 0 ];
        }
        return domain;
    }
    _initEvent() {
        this._initCommonEvent();
    }
    _initData() {
        const dataCollection = [], stateFields = [], valueFields = [];
        let isCategoryState;
        if (this._relatedAxisComponent) {
            const originalStateFields = {};
            (0, model_1.eachSeries)(this._regions, (s => {
                var _a, _b;
                const xAxisHelper = "cartesian" === s.coordinate ? s.getXAxisHelper() : "polar" === s.coordinate ? s.angleAxisHelper : null, yAxisHelper = "cartesian" === s.coordinate ? s.getYAxisHelper() : "polar" === s.coordinate ? s.radiusAxisHelper : null;
                if (!xAxisHelper || !yAxisHelper) return;
                const stateAxisHelper = xAxisHelper.getAxisId() === this._relatedAxisComponent.id ? xAxisHelper : yAxisHelper.getAxisId() === this._relatedAxisComponent.id ? yAxisHelper : this._isHorizontal ? xAxisHelper : yAxisHelper, valueAxisHelper = stateAxisHelper === xAxisHelper ? yAxisHelper : xAxisHelper;
                dataCollection.push(s.getRawData());
                const seriesSpec = s.getSpec(), xField = "cartesian" === s.coordinate ? (0, vutils_1.array)(seriesSpec.xField) : (0, 
                vutils_1.array)(null !== (_a = seriesSpec.angleField) && void 0 !== _a ? _a : seriesSpec.categoryField), yField = "cartesian" === s.coordinate ? (0, 
                vutils_1.array)(seriesSpec.yField) : (0, vutils_1.array)(null !== (_b = seriesSpec.radiusField) && void 0 !== _b ? _b : seriesSpec.valueField);
                if (originalStateFields[s.id] = "link" === s.type ? [ "from_xField" ] : stateAxisHelper === xAxisHelper ? xField : yField, 
                (0, vscale_1.isContinuous)(stateAxisHelper.getScale(0).type) ? (isCategoryState = !1, 
                stateFields.push(originalStateFields[s.id])) : stateFields.push(originalStateFields[s.id][0]), 
                this._valueField) {
                    const valueField = "link" === s.type ? [ "from_yField" ] : valueAxisHelper === xAxisHelper ? xField : yField;
                    (0, vscale_1.isContinuous)(valueAxisHelper.getScale(0).type) && valueFields.push(...valueField);
                }
            }), {
                userId: this._seriesUserId,
                specIndex: this._seriesIndex
            }), this._originalStateFields = originalStateFields;
        } else (0, model_1.eachSeries)(this._regions, (s => {
            dataCollection.push(s.getRawData()), stateFields.push(this._field), this._valueField && valueFields.push(this._spec.valueField);
        }), {
            userId: this._seriesUserId,
            specIndex: this._seriesIndex
        });
        const {dataSet: dataSet} = this._option;
        (0, register_1.registerDataSetInstanceParser)(dataSet, "dataview", vdataset_1.dataViewParser), 
        (0, register_1.registerDataSetInstanceTransform)(dataSet, "dataFilterComputeDomain", util_1.dataFilterComputeDomain);
        const data = new vdataset_1.DataView(dataSet, {
            name: `${this.type}_${this.id}_data`
        });
        data.transform({
            type: "dataFilterComputeDomain",
            options: {
                input: {
                    dataCollection: dataCollection,
                    stateFields: stateFields,
                    valueFields: valueFields,
                    isCategoryState: isCategoryState
                },
                output: {
                    stateField: this._stateField,
                    valueField: this._valueField
                }
            }
        }, !1), this._data = new compilable_data_1.CompilableData(this._option, data), data.reRunAllTransform(), 
        dataSet.multipleDataViewAddListener(dataCollection, "change", this._handleDataCollectionChange.bind(this));
    }
    setAttrFromSpec() {
        var _a;
        super.setAttrFromSpec(), !0 === this._spec.roamZoom || this._spec.roamZoom ? this._zoomAttr = (0, 
        vutils_1.merge)({}, this._zoomAttr, this._spec.roamZoom) : this._zoomAttr.enable = !1, 
        !0 === this._spec.roamDrag || this._spec.roamDrag ? this._dragAttr = (0, vutils_1.merge)({}, this._dragAttr, this._spec.roamDrag) : this._dragAttr.enable = !1, 
        !0 === this._spec.roamScroll || this._spec.roamScroll ? this._scrollAttr = (0, vutils_1.merge)({}, this._scrollAttr, this._spec.roamScroll) : this._scrollAttr.enable = !1, 
        this._field = this._spec.field, this._width = this._computeWidth(), this._height = this._computeHeight(), 
        this._visible = null === (_a = this._spec.visible) || void 0 === _a || _a;
    }
    statePointToData(state) {
        const scale = this._stateScale, domain = scale.domain();
        if ((0, vscale_1.isContinuous)(scale.type)) return this._isReverse() ? domain[0] + ((0, 
        vutils_1.last)(domain) - domain[0]) * (1 - state) : domain[0] + ((0, vutils_1.last)(domain) - domain[0]) * state;
        let range = scale.range();
        this._isReverse() && (range = range.slice().reverse());
        const posInRange = range[0] + ((0, vutils_1.last)(range) - range[0]) * state;
        return scale.invert(posInRange);
    }
    dataToStatePoint(data) {
        const scale = this._stateScale, pos = scale.scale(data);
        let range = scale.range();
        return !this._isHorizontal && (0, vscale_1.isContinuous)(scale.type) && (range = range.slice().reverse()), 
        (pos - range[0]) / ((0, vutils_1.last)(range) - range[0]);
    }
    _modeCheck(statePoint, mode) {
        return "start" === statePoint ? "percent" === mode && (0, vutils_1.isValid)(this._spec.start) || "value" === mode && (0, 
        vutils_1.isValid)(this._spec.startValue) : "percent" === mode && (0, vutils_1.isValid)(this._spec.end) || "value" === mode && (0, 
        vutils_1.isValid)(this._spec.endValue);
    }
    _setStateFromSpec() {
        var _a, _b;
        let start, end;
        if (this._auto = !!this._spec.auto, this._spec.rangeMode) {
            const [startMode, endMode] = this._spec.rangeMode;
            this._modeCheck("start", startMode) && this._modeCheck("end", endMode) && (start = "percent" === startMode ? this._spec.start : this.dataToStatePoint(this._spec.startValue), 
            end = "percent" === endMode ? this._spec.end : this.dataToStatePoint(this._spec.endValue));
        } else start = this._spec.start ? this._spec.start : this._spec.startValue ? this.dataToStatePoint(this._spec.startValue) : 0, 
        end = this._spec.end ? this._spec.end : this._spec.endValue ? this.dataToStatePoint(this._spec.endValue) : 1;
        this._startValue = this.statePointToData(start), this._endValue = this.statePointToData(end), 
        this._start = start, this._end = end, this._minSpan = null !== (_a = this._spec.minSpan) && void 0 !== _a ? _a : 0, 
        this._maxSpan = null !== (_b = this._spec.maxSpan) && void 0 !== _b ? _b : 1, (0, 
        vscale_1.isContinuous)(this._stateScale.type) && this._stateScale.domain()[0] !== (0, 
        vutils_1.last)(this._stateScale.domain()) && (this._spec.minValueSpan && (this._minSpan = this._spec.minValueSpan / ((0, 
        vutils_1.last)(this._stateScale.domain()) - this._stateScale.domain()[0])), this._spec.maxValueSpan && (this._maxSpan = this._spec.maxValueSpan / ((0, 
        vutils_1.last)(this._stateScale.domain()) - this._stateScale.domain()[0]))), this._minSpan = Math.max(0, this._minSpan), 
        this._maxSpan = Math.min(this._maxSpan, 1), this._relatedAxisComponent && "axis" === this._filterMode || 0 === this._start && 1 === this._end || (this._newDomain = this._parseDomainFromState(this._startValue, this._endValue));
    }
    _parseFieldOfSeries(s) {
        var _a;
        return null === (_a = this._originalStateFields) || void 0 === _a ? void 0 : _a[s.id];
    }
    _initStateScale() {
        const defaultRange = [ 0, 1 ];
        if (this._relatedAxisComponent) {
            const scale = this._relatedAxisComponent.getScale(), isContinuousScale = (0, vscale_1.isContinuous)(scale.type), domain = this._computeDomainOfStateScale(isContinuousScale);
            if (this._stateScale = scale.clone(), isContinuousScale) {
                const domainNum = domain.map((n => 1 * n));
                this._stateScale.domain(domain.length ? [ (0, vutils_1.minInArray)(domainNum), (0, 
                vutils_1.maxInArray)(domainNum) ] : [ 0, 1 ], !0).range(defaultRange);
            } else this._stateScale.domain(domain, !0).range(defaultRange);
        } else this._stateScale = new vscale_1.BandScale, this._stateScale.domain(this._computeDomainOfStateScale(), !0).range(defaultRange);
    }
    init(option) {
        super.init(option), this._addTransformToSeries(), 0 === this._start && 1 === this._end || this.effect.onZoomChange();
    }
    _addTransformToSeries() {
        this._relatedAxisComponent && "axis" === this._filterMode || ((0, register_1.registerDataSetInstanceTransform)(this._option.dataSet, "dataFilterWithNewDomain", util_1.dataFilterWithNewDomain), 
        (0, register_1.registerDataSetInstanceTransform)(this._option.dataSet, "lockStatisticsFilter", util_1.lockStatisticsFilter), 
        (0, model_1.eachSeries)(this._regions, (s => {
            s.getViewDataStatistics().transform({
                type: "lockStatisticsFilter",
                options: {
                    originalFields: () => s.getViewDataStatistics().getFields(),
                    getNewDomain: () => this._newDomain,
                    field: () => {
                        var _a;
                        return null !== (_a = this._field) && void 0 !== _a ? _a : this._parseFieldOfSeries(s);
                    },
                    isContinuous: () => (0, vscale_1.isContinuous)(this._stateScale.type)
                },
                level: 1
            }, !1), s.addViewDataFilter({
                type: "dataFilterWithNewDomain",
                options: {
                    getNewDomain: () => this._newDomain,
                    field: () => {
                        var _a;
                        return null !== (_a = this._field) && void 0 !== _a ? _a : this._parseFieldOfSeries(s);
                    },
                    isContinuous: () => (0, vscale_1.isContinuous)(this._stateScale.type)
                },
                level: initialize_1.TransformLevel.dataZoomFilter
            });
        }), {
            userId: this._seriesUserId,
            specIndex: this._seriesIndex
        }));
    }
    _compareSpec(spec, prevSpec) {
        const result = super._compareSpec(spec, prevSpec);
        return result.reMake || (0, vutils_1.isEqual)(prevSpec, spec) || (result.reRender = !0, 
        result.reMake = !0), result;
    }
    reInit(spec) {
        super.reInit(spec), this._marks.forEach((g => {
            g.getMarks().forEach((m => {
                this.initMarkStyleWithSpec(m, this._spec[m.name]);
            }));
        }));
    }
    _parseDomainFromState(startValue, endValue) {
        if ((0, vscale_1.isContinuous)(this._stateScale.type)) return [ Math.min(endValue, startValue), Math.max(endValue, startValue) ];
        const allDomain = this._stateScale.domain(), startIndex = allDomain.indexOf(startValue), endIndex = allDomain.indexOf(endValue);
        return allDomain.slice(Math.min(startIndex, endIndex), Math.max(startIndex, endIndex) + 1);
    }
    _initCommonEvent() {
        var _a, _b, _c, _d, _e, _f, _g;
        const option = {
            delayType: null !== (_b = null === (_a = this._spec) || void 0 === _a ? void 0 : _a.delayType) && void 0 !== _b ? _b : "throttle",
            delayTime: (0, vutils_1.isValid)(null === (_c = this._spec) || void 0 === _c ? void 0 : _c.delayType) ? null !== (_e = null === (_d = this._spec) || void 0 === _d ? void 0 : _d.delayTime) && void 0 !== _e ? _e : 30 : 0,
            realTime: null === (_g = null === (_f = this._spec) || void 0 === _f ? void 0 : _f.realTime) || void 0 === _g || _g,
            allowComponentZoom: !0
        };
        this._zoomAttr.enable && this.initZoomEventOfRegions(this._regions, null, this._handleChartZoom, option), 
        this._scrollAttr.enable && this.initScrollEventOfRegions(this._regions, null, this._handleChartScroll, option), 
        this._dragAttr.enable && this.initDragEventOfRegions(this._regions, null, this._handleChartDrag, option);
    }
    updateLayoutAttribute() {
        this._visible && this._createOrUpdateComponent(), super.updateLayoutAttribute();
    }
    _autoVisible(isShown) {
        if (!this._auto) return;
        isShown ? this.show() : this.hide();
        const sizeKey = this._isHorizontal ? "height" : "width";
        this.layout.setLayoutRect({
            [sizeKey]: isShown ? this[`_${sizeKey}`] : 0
        }, {
            [sizeKey]: attribute_1.AttributeLevel.Built_In
        });
    }
    onLayoutStart(layoutRect, viewRect) {
        super.onLayoutStart(layoutRect, viewRect);
        const isShown = this._autoUpdate(layoutRect);
        this._autoVisible(isShown), this._dataUpdating = !1;
    }
    onLayoutEnd() {
        const isShown = !(0 === this._start && 1 === this._end);
        this._autoVisible(isShown), super.onLayoutEnd();
    }
    getBoundsInRect(rect) {
        const result = {
            x1: this.getLayoutStartPoint().x,
            y1: this.getLayoutStartPoint().y,
            x2: 0,
            y2: 0
        };
        return this._isHorizontal ? (result.y2 = result.y1 + this._height, result.x2 = result.x1 + rect.width) : (result.x2 = result.x1 + this._width, 
        result.y2 = result.y1 + rect.height), result;
    }
    hide() {
        var _a;
        null === (_a = this._component) || void 0 === _a || _a.hideAll();
    }
    show() {
        var _a;
        null === (_a = this._component) || void 0 === _a || _a.showAll();
    }
    _getAxisBandSize(axisSpec) {
        const bandSize = null == axisSpec ? void 0 : axisSpec.bandSize, maxBandSize = null == axisSpec ? void 0 : axisSpec.maxBandSize, minBandSize = null == axisSpec ? void 0 : axisSpec.minBandSize;
        if (bandSize || minBandSize || maxBandSize) return {
            bandSize: bandSize,
            maxBandSize: maxBandSize,
            minBandSize: minBandSize
        };
    }
    _autoUpdate(rect) {
        var _a, _b, _c, _d, _e, _f;
        if (!this._auto) return this._cacheVisibility = void 0, !0;
        const axis = this._relatedAxisComponent, axisSpec = null == axis ? void 0 : axis.getSpec(), axisScale = null == axis ? void 0 : axis.getScale(), bandSizeResult = this._getAxisBandSize(axisSpec);
        if (!this._dataUpdating && (0, vscale_1.isDiscrete)(axisScale.type) && (null == rect ? void 0 : rect.height) === (null === (_a = this._cacheRect) || void 0 === _a ? void 0 : _a.height) && (null == rect ? void 0 : rect.width) === (null === (_b = this._cacheRect) || void 0 === _b ? void 0 : _b.width) && this._fixedBandSize === (null == bandSizeResult ? void 0 : bandSizeResult.bandSize)) return this._cacheVisibility;
        let isShown = !0;
        if (this._isHorizontal && (null == rect ? void 0 : rect.width) !== (null === (_c = this._cacheRect) || void 0 === _c ? void 0 : _c.width) ? axisScale.range(axis.getInverse() ? [ rect.width, 0 ] : [ 0, rect.width ]) : (null == rect ? void 0 : rect.height) !== (null === (_d = this._cacheRect) || void 0 === _d ? void 0 : _d.height) && axisScale.range(axis.getInverse() ? [ 0, rect.height ] : [ rect.height, 0 ]), 
        this._cacheRect = {
            width: null == rect ? void 0 : rect.width,
            height: null == rect ? void 0 : rect.height
        }, this._fixedBandSize = null == bandSizeResult ? void 0 : bandSizeResult.bandSize, 
        (0, vscale_1.isDiscrete)(axisScale.type)) {
            bandSizeResult && (this._start || this._end) && (this.type === interface_1.ComponentTypeEnum.scrollBar && (this._start = 0, 
            this._end = 1), this._updateRangeFactor());
            const [start, end] = null !== (_e = axisScale.rangeFactor()) && void 0 !== _e ? _e : [];
            isShown = (!(0, vutils_1.isNil)(start) || !(0, vutils_1.isNil)(end)) && !(0 === start && 1 === end);
        } else {
            const [start, end] = null !== (_f = axisScale.rangeFactor()) && void 0 !== _f ? _f : [ this._start, this._end ];
            isShown = !(0 === start && 1 === end);
        }
        return this.setStartAndEnd(this._start, this._end), this._cacheVisibility = isShown, 
        isShown;
    }
    _getNeedClearVRenderComponents() {
        return [ this._component ];
    }
}

exports.DataFilterBaseComponent = DataFilterBaseComponent, (0, vutils_1.mixin)(DataFilterBaseComponent, zoomable_1.Zoomable);
//# sourceMappingURL=data-filter-base-component.js.map
