/*
THIS INFRAGISTICS ULTIMATE SOFTWARE LICENSE  AGREEMENT ("AGREEMENT") LOCATED HERE:
https://www.infragistics.com/legal/license/igultimate-la
https://www.infragistics.com/legal/license/igultimate-eula
GOVERNS THE LICENSING, INSTALLATION AND USE OF INFRAGISTICS SOFTWARE. BY DOWNLOADING AND/OR INSTALLING AND USING INFRAGISTICS SOFTWARE:  you are indicating that you have read and understand this Agreement, and agree to be legally bound by it on behalf of the yourself and your company.
*/
import * as tslib_1 from "tslib";
import { CategorySeries } from "./CategorySeries";
import { IIsCategoryBased_$type } from "./IIsCategoryBased";
import { IHasSingleValueCategory_$type } from "./IHasSingleValueCategory";
import { IHasCategoryTrendline_$type } from "./IHasCategoryTrendline";
import { ITrendLineSeries_$type } from "./ITrendLineSeries";
import { IAnchoredCategorySeriesInteractionManager_$type } from "./IAnchoredCategorySeriesInteractionManager";
import { DVContainer } from "igniteui-angular-core/ES5/DVContainer";
import { Type, enumGetBox, typeCast, Point_$type, markType } from "igniteui-angular-core/ES5/type";
import { DependencyProperty } from "igniteui-angular-core/ES5/DependencyProperty";
import { Series } from "./Series";
import { TrendLineType_$type } from "igniteui-angular-core/ES5/TrendLineType";
import { Brush } from "igniteui-angular-core/ES5/Brush";
import { PenLineCap_$type } from "igniteui-angular-core/ES5/PenLineCap";
import { DoubleCollection } from "igniteui-angular-core/ES5/DoubleCollection";
import { CategoryFrame } from "./CategoryFrame";
import { CategoryAxisBase } from "./CategoryAxisBase";
import { ICategoryScaler_$type } from "./ICategoryScaler";
import { IScaler_$type } from "./IScaler";
import { CategorySeriesView } from "./CategorySeriesView";
import { CategorySeriesMarkerCollisionAvoidance_$type } from "./CategorySeriesMarkerCollisionAvoidance";
import { ConsolidatedItemHitTestBehavior_$type } from "./ConsolidatedItemHitTestBehavior";
import { CategoryFramePreparer } from "./CategoryFramePreparer";
import { Rect } from "igniteui-angular-core/ES5/Rect";
import { ISortingAxis_$type } from "./ISortingAxis";
import { IFastItemsSource_$type } from "igniteui-angular-core/ES5/IFastItemsSource";
import { NumericAxisBase } from "./NumericAxisBase";
import { CategoryBucketCalculator } from "./CategoryBucketCalculator";
import { AxisRange } from "./AxisRange";
import { NumericYAxis } from "./NumericYAxis";
import { ScalerParams } from "./ScalerParams";
import { CategoryMarkerManager } from "./CategoryMarkerManager";
import { CollisionAvoider } from "./CollisionAvoider";
import { NonCollisionAvoider } from "./NonCollisionAvoider";
import { PropertyMetadata } from "igniteui-angular-core/ES5/PropertyMetadata";
import { truncate, isNaN_ } from "igniteui-angular-core/ES5/number";
import { CategoryTrendLineManagerFactory } from "./CategoryTrendLineManagerFactory";
/**
 * @hidden
 */
var AnchoredCategorySeries = /** @class */ (function (_super) {
    tslib_1.__extends(AnchoredCategorySeries, _super);
    function AnchoredCategorySeries() {
        var _this = _super.call(this) || this;
        _this.o1 = null;
        _this.o5 = false;
        _this.o3 = null;
        _this.oy = null;
        _this.o8 = null;
        _this.na = new CategoryFramePreparer(1, _this, _this.ne, _this, _this, _this.ne.cn);
        return _this;
    }
    Object.defineProperty(AnchoredCategorySeries.prototype, "o2", {
        get: function () {
            var _this = this;
            if (this.o1 == null) {
                this.o1 = DVContainer.instance.createInstance(IAnchoredCategorySeriesInteractionManager_$type, function () { return _this.b2.n; });
            }
            return this.o1;
        },
        enumerable: true,
        configurable: true
    });
    AnchoredCategorySeries.prototype.getHostReferenceValue = function () {
        return this.eh();
    };
    AnchoredCategorySeries.prototype.bf = function () {
        var a = new AnchoredCategorySeriesView(this);
        return a;
    };
    AnchoredCategorySeries.prototype.it = function (a) {
        _super.prototype.it.call(this, a);
        this.ox = a;
    };
    AnchoredCategorySeries.prototype.fs = function (a, b) {
        var c = this.gu(b);
        if (c == AnchoredCategorySeries.$$p[2]) {
            return this.ft(a, b, this.pc);
        }
        return _super.prototype.fs.call(this, a, b);
    };
    Object.defineProperty(AnchoredCategorySeries.prototype, "valueColumn", {
        get: function () {
            return this.o3;
        },
        set: function (a) {
            if (this.o3 != a) {
                var b = this.o3;
                this.o3 = a;
                if (!this.o5) {
                    this.raisePropertyChanged("ValueColumn", b, this.o3);
                }
            }
        },
        enumerable: true,
        configurable: true
    });
    Object.defineProperty(AnchoredCategorySeries.prototype, "pu", {
        get: function () {
            return this.c(AnchoredCategorySeries.pj);
        },
        set: function (a) {
            this.h(AnchoredCategorySeries.pj, a);
        },
        enumerable: true,
        configurable: true
    });
    AnchoredCategorySeries.prototype.c9 = function (a) {
        var b = new Rect(0, 0, 0, 1, 1);
        var c = this.fetchXAxis();
        var d = this.fetchYAxis();
        var e = this.lr(this.bi);
        var f = c != null ? this.na.r(typeCast(ICategoryScaler_$type, c), b, b, e) : 0;
        return this.o2.c$a(this, this.valueColumn, c, d, f, a);
    };
    AnchoredCategorySeries.prototype.ou = function (a, b, c) {
        if (b < a || a < 0 || a > this.valueColumn.count || b < 0 || b > this.valueColumn.count || c == null) {
            return null;
        }
        var d = new Array((b - a) + 1);
        var e = c.cc;
        var f = null;
        if (e) {
            f = c.i$b;
        }
        for (var g = a; g <= b; g++) {
            var h = g;
            if (e) {
                h = f._inner[h];
            }
            d[g - a] = this.bz.item(g);
        }
        return d;
    };
    AnchoredCategorySeries.prototype.iy = function (a, b, c, d) {
        _super.prototype.iy.call(this, a, b, c, d);
        if (this.ox.cz && this.ox.cy.g$b(a, b, c, d)) {
            this.jc(false);
            this.ij();
        }
        switch (b) {
            case "FastItemsSource":
                if (typeCast(IFastItemsSource_$type, c) != null) {
                    c.deregisterColumn(this.valueColumn);
                    this.valueColumn = null;
                }
                if (typeCast(IFastItemsSource_$type, d) != null) {
                    this.valueColumn = this.bw(this.pc);
                }
                var e = typeCast(NumericAxisBase.$, this.fetchYAxis());
                if (e != null && !e.ck()) {
                    this.ox.cn.g(this.eu);
                    this.jc(false);
                }
                break;
            case AnchoredCategorySeries.$$p[2]:
                if (this.bz != null) {
                    this.bz.deregisterColumn(this.valueColumn);
                    this.valueColumn = this.bw(this.pc);
                }
                this.o8 = this.pc;
                break;
            case "ValueColumn":
                if (this.ox.cz) {
                    this.ox.cy.g$i();
                }
                var f = typeCast(NumericAxisBase.$, this.fetchYAxis());
                if (f != null && !f.ck()) {
                    this.ox.cn.g(this.eu);
                    this.jc(false);
                }
                this.pi();
                this.jp();
                break;
            case "TrendLineBrush":
                this.jn();
                break;
            case "ErrorBarSettings":
                this.jc(false);
                break;
            case "TrendLineType":
                this.ij();
                break;
            case AnchoredCategorySeries.$$p[1]:
                this.jc(false);
                break;
        }
    };
    AnchoredCategorySeries.prototype.an = function (a) {
        if (this.valueColumn == null || this.valueColumn.count == 0) {
            return null;
        }
        if (a == this.fetchXAxis()) {
            return new AxisRange(0, this.valueColumn.count - 1);
        }
        if (a == this.fetchYAxis()) {
            return new AxisRange(this.valueColumn.minimum, this.valueColumn.maximum);
        }
        return null;
    };
    AnchoredCategorySeries.prototype.hy = function (a, b, c, d) {
        switch (a) {
            case 4:
            case 1:
            case 0:
                this.ox.cn.g(this.eu);
                break;
        }
        if (this.ox.cz) {
            this.ox.cy.g$e(a, b, c, d);
        }
        this.pi();
        this.jp();
    };
    AnchoredCategorySeries.prototype.n5 = function () {
        return this.o6(this.ne);
    };
    AnchoredCategorySeries.prototype.o6 = function (a) {
        var b = 0;
        var c = a.bs;
        var d = a.br;
        var e = this.getEffectiveViewport1(a);
        var f = typeCast(NumericYAxis.$, this.fetchYAxis());
        if (!c.isEmpty && !d.isEmpty && f != null) {
            var g = new ScalerParams(0, c, d, f.b8, e);
            if (f.ce) {
                g.b = this.eh();
            }
            b = f.dv(f.kd, g);
        }
        return b;
    };
    AnchoredCategorySeries.prototype.ph = function (a, b, c) {
        var d = this.o6(c);
        if (a.count > 0) {
            var e = d;
            a.add({ $type: Point_$type, x: a._inner[a.count - 1].x, y: e });
            a.add({ $type: Point_$type, x: a._inner[0].x, y: e });
        }
    };
    AnchoredCategorySeries.prototype.ov = function (a, b, c, d) {
        return this.ow(a, b, c, d, false);
    };
    AnchoredCategorySeries.prototype.ow = function (a, b, c, d, e) {
        return CategorySeries.m0(a, b, c, d, e);
    };
    AnchoredCategorySeries.prototype.dw = function (a, b, c) {
        var d = _super.prototype.dw.call(this, a, b, c);
        var e = c;
        if (this.valueColumn == null || this.valueColumn.count == 0 || e.cn.d < 1) {
            d = false;
        }
        return d;
    };
    AnchoredCategorySeries.prototype.hv = function (a, b) {
        _super.prototype.hv.call(this, a, b);
        var c = b;
        c.ct();
        if (c.cz) {
            c.cy.g$d();
        }
    };
    AnchoredCategorySeries.prototype.ok = function (a, b) {
        _super.prototype.ok.call(this, a, b);
        this.nb(b).d(a, b);
    };
    AnchoredCategorySeries.prototype.on = function (a, b) {
        _super.prototype.on.call(this, a, b);
        var c = typeCast(AnchoredCategorySeriesView.$, b);
        c.b0 = true;
        if (c.cz) {
            c.cy.g$g(a.p);
        }
        if (this.l2()) {
            CategoryMarkerManager.b(this, a.m, b.cq, this.l4);
            this.oh(b, a);
            b.cj();
        }
        this.pe(a, b);
    };
    AnchoredCategorySeries.prototype.jb = function (a, b, c, d, e) {
        _super.prototype.jb.call(this, a, b, c, d, e);
        var f = this.a0.a$h.item(d);
        var g = f;
        g.cn.g(this.eu);
        f.ay(c);
        if (this.cc(g)) {
            return;
        }
        if (this.oy == null) {
            this.oy = new CategoryFrame(3);
        }
        this.oy.u();
        this.ok(this.oy, g);
        this.on(this.oy, g);
    };
    AnchoredCategorySeries.prototype.pe = function (a, b) {
    };
    AnchoredCategorySeries.prototype.jn = function () {
        _super.prototype.jn.call(this);
        if (this.fh < 0) {
            return;
        }
        this.ox.c3();
        if (this.trendLineBrush != null) {
            this.ox.c1();
        }
        else {
            this.ox.c0();
        }
    };
    AnchoredCategorySeries.prototype.fv = function (a, b) {
        if (this.ox.cz && a == this.ox.cy.g$j) {
            return null;
        }
        return _super.prototype.fv.call(this, a, b);
    };
    Object.defineProperty(AnchoredCategorySeries.prototype, "currentCategoryMode", {
        get: function () {
            return this.preferredCategoryMode(typeCast(CategoryAxisBase.$, this.fetchXAxis()));
        },
        enumerable: true,
        configurable: true
    });
    Object.defineProperty(AnchoredCategorySeries.prototype, "scaler", {
        get: function () {
            return typeCast(ICategoryScaler_$type, this.fetchXAxis());
        },
        enumerable: true,
        configurable: true
    });
    Object.defineProperty(AnchoredCategorySeries.prototype, "yScaler", {
        get: function () {
            return typeCast(IScaler_$type, this.fetchYAxis());
        },
        enumerable: true,
        configurable: true
    });
    Object.defineProperty(AnchoredCategorySeries.prototype, "bucketizer", {
        get: function () {
            return this.ox.cn;
        },
        enumerable: true,
        configurable: true
    });
    Object.defineProperty(AnchoredCategorySeries.prototype, "currentMode2Index", {
        get: function () {
            return this.n8();
        },
        enumerable: true,
        configurable: true
    });
    AnchoredCategorySeries.prototype.provideCollisionDetector = function () {
        if (this.oz == 1) {
            return new CollisionAvoider();
        }
        return NonCollisionAvoider.a;
    };
    Object.defineProperty(AnchoredCategorySeries.prototype, "trendlinePreparer", {
        get: function () {
            return this.ox.cz ? this.ox.cy : null;
        },
        enumerable: true,
        configurable: true
    });
    AnchoredCategorySeries.prototype.h4 = function (a) {
        _super.prototype.h4.call(this, a);
        if (this.ox.cz) {
            this.a2.exportTrendlineData(this, a, this.ox.cy.g$j);
        }
    };
    AnchoredCategorySeries.prototype.fp = function (a) {
        var _this = this;
        var b = this.fetchXAxis();
        var c = this.fetchYAxis();
        return this.o2.c$b(this, a, this.n6(this.bi), this.valueColumn, b, c, this.o0 == 1, function (d) { return _super.prototype.fp.call(_this, d); });
    };
    Object.defineProperty(AnchoredCategorySeries.prototype, "mayContainUnknowns", {
        get: function () {
            return this.valueColumn == null || this.valueColumn.mayContainUnknowns;
        },
        enumerable: true,
        configurable: true
    });
    AnchoredCategorySeries.prototype.eh = function () {
        return Series.ei(this.valueColumn, typeCast(ISortingAxis_$type, this.fetchXAxis()));
    };
    AnchoredCategorySeries.prototype.ao = function () {
        if (this.valueColumn == null) {
            return null;
        }
        var a = this.m5();
        var b = new ScalerParams(0, this.bs.mq, this.bs.m3, a.b8, this.getEffectiveViewport());
        var c = (a.dy(this.bs.m3.left, b));
        var d = (a.dy(this.bs.m3.right, b));
        var e = null;
        if (a.cc) {
            e = a;
            c = e.i$f(c);
            d = e.i$f(d);
        }
        else {
            c = Math.floor(c);
            d = Math.ceil(d);
        }
        if (isNaN_(c) || isNaN_(d)) {
            return null;
        }
        c = Math.max(0, Math.min(this.valueColumn.count - 1, c));
        d = Math.max(0, Math.min(this.valueColumn.count - 1, d));
        var f = 1.7976931348623157E+308;
        var g = -1.7976931348623157E+308;
        for (var h = truncate(c); h <= truncate(d); h++) {
            var i = h;
            if (e != null) {
                i = e.i$b._inner[h];
            }
            f = Math.min(f, this.valueColumn.item(i));
            g = Math.max(g, this.valueColumn.item(i));
        }
        return new AxisRange(f, g);
    };
    AnchoredCategorySeries.prototype.pi = function () {
        this.d8 = this.valueColumn == null || this.valueColumn.count == 0 ? NaN : this.valueColumn.item(this.valueColumn.count - 1);
    };
    Object.defineProperty(AnchoredCategorySeries.prototype, "useHighMarkerFidelity", {
        get: function () {
            return this.n1;
        },
        enumerable: true,
        configurable: true
    });
    AnchoredCategorySeries.$t = markType(AnchoredCategorySeries, 'AnchoredCategorySeries', CategorySeries.$, [IIsCategoryBased_$type, IHasSingleValueCategory_$type, IHasCategoryTrendline_$type, ITrendLineSeries_$type]);
    AnchoredCategorySeries.pj = DependencyProperty.i("ActualTrendLineBrush", Brush.$, AnchoredCategorySeries.$, new PropertyMetadata(2, null, function (a, b) { return a.raisePropertyChanged("ActualTrendLineBrush", b.oldValue, b.newValue); }));
    return AnchoredCategorySeries;
}(CategorySeries));
export { AnchoredCategorySeries };
Type.dep(DependencyProperty, PropertyMetadata, AnchoredCategorySeries, 'raisePropertyChanged', ['ConsolidatedItemHitTestBehavior:o0:pk', [ConsolidatedItemHitTestBehavior_$type, enumGetBox(ConsolidatedItemHitTestBehavior_$type, 0)], 'MarkerCollisionAvoidance:oz:pl', [CategorySeriesMarkerCollisionAvoidance_$type, enumGetBox(CategorySeriesMarkerCollisionAvoidance_$type, 1)], 'ValueMemberPath:pc:pt', [2, null], 'TrendLineType::pr', [TrendLineType_$type, enumGetBox(TrendLineType_$type, 0)], 'TrendLineThickness::pq', [1, 1.5], 'TrendLinePeriod::pp', [1, 7], 'TrendLineBrush::pm', [Brush.$, null], 'TrendLineZIndex:o7:ps', [1, 1001], 'TrendLineDashArray:pv:pn', [DoubleCollection.$], 'TrendLineDashCap:pw:po', [PenLineCap_$type, enumGetBox(PenLineCap_$type, 0)]]);
/**
 * @hidden
 */
var AnchoredCategoryBucketCalculator = /** @class */ (function (_super) {
    tslib_1.__extends(AnchoredCategoryBucketCalculator, _super);
    function AnchoredCategoryBucketCalculator(a) {
        var _this = _super.call(this, a) || this;
        _this.i = null;
        _this.h = null;
        _this.j = 0;
        _this.i = a;
        return _this;
    }
    AnchoredCategoryBucketCalculator.prototype.getBucketWithoutUnknowns = function (a) {
        var b = this.h;
        var c = this.j;
        var d = a * this.d;
        var e = d + this.d - 1;
        var f = c - 1;
        d = d < f ? d : f;
        e = e < f ? e : f;
        var g = 1.7976931348623157E+308;
        var h = -1.7976931348623157E+308;
        var i = true;
        for (var j = d; j <= e; ++j) {
            var k = b[j];
            g = g < k ? g : k;
            h = h > k ? h : k;
            i = false;
        }
        if (!i) {
            return [0.5 * (d + e), g, h];
        }
        return [0.5 * (d + e), NaN, NaN];
    };
    AnchoredCategoryBucketCalculator.prototype.getBucket = function (a) {
        var b = this.h;
        var c = this.j;
        var d = a * this.d;
        var e = d + this.d - 1;
        var f = c - 1;
        d = d < f ? d : f;
        e = e < f ? e : f;
        var g = 0;
        var h = 0;
        var i = true;
        for (var j = d; j <= e; ++j) {
            var k = b[j];
            if (!i) {
                if (!isNaN_(k)) {
                    g = g < k ? g : k;
                    h = h > k ? h : k;
                }
            }
            else {
                if (!isNaN_(k)) {
                    g = k;
                    h = k;
                    i = false;
                }
            }
        }
        if (!i) {
            return [0.5 * (d + e), g, h];
        }
        return [0.5 * (d + e), NaN, NaN];
    };
    AnchoredCategoryBucketCalculator.prototype.cacheValues = function () {
        this.j = this.i.cw.valueColumn.count;
        this.h = this.i.cw.valueColumn.asArray();
    };
    AnchoredCategoryBucketCalculator.prototype.unCacheValues = function () {
        this.h = null;
    };
    AnchoredCategoryBucketCalculator.$t = markType(AnchoredCategoryBucketCalculator, 'AnchoredCategoryBucketCalculator', CategoryBucketCalculator.$);
    return AnchoredCategoryBucketCalculator;
}(CategoryBucketCalculator));
export { AnchoredCategoryBucketCalculator };
/**
 * @hidden
 */
var AnchoredCategorySeriesView = /** @class */ (function (_super) {
    tslib_1.__extends(AnchoredCategorySeriesView, _super);
    function AnchoredCategorySeriesView(a) {
        var _this = _super.call(this, a) || this;
        _this.cw = null;
        _this.cx = null;
        _this.cw = a;
        return _this;
    }
    Object.defineProperty(AnchoredCategorySeriesView.prototype, "cy", {
        get: function () {
            if (this.cx == null) {
                this.cx = CategoryTrendLineManagerFactory.a(this.cx, this.e.ap(), this.e.jw, this.e, this.e.b2);
            }
            return this.cx;
        },
        set: function (a) {
            this.cx = a;
        },
        enumerable: true,
        configurable: true
    });
    Object.defineProperty(AnchoredCategorySeriesView.prototype, "cz", {
        get: function () {
            return this.cx != null;
        },
        enumerable: true,
        configurable: true
    });
    AnchoredCategorySeriesView.prototype.c3 = function () {
        this.cw.pu = null;
    };
    AnchoredCategorySeriesView.prototype.c1 = function () {
        this.cw.pu = this.cw.trendLineBrush;
    };
    AnchoredCategorySeriesView.prototype.c0 = function () {
        this.cw.pu = this.cw.k2;
    };
    AnchoredCategorySeriesView.prototype.co = function () {
        return new AnchoredCategoryBucketCalculator(this);
    };
    AnchoredCategorySeriesView.prototype.c2 = function () {
        this.cn.cacheValues();
    };
    AnchoredCategorySeriesView.prototype.c4 = function () {
        this.cn.unCacheValues();
    };
    AnchoredCategorySeriesView.prototype.c5 = function (a) {
        var b = this.cq.item(a);
        return this.cm(b);
    };
    AnchoredCategorySeriesView.prototype.a2 = function (a, b) {
        if (a.d) {
            if (this.cw.trendLineType != 0 && !b) {
                var c = this.cy.g$j;
                c.ac = this.cw.trendLineThickness;
                c._stroke = this.cw.pu;
                c.ai = this.cw.pv;
                c.ad = this.cw.pw;
                a.u(c);
            }
        }
        _super.prototype.a2.call(this, a, b);
    };
    AnchoredCategorySeriesView.prototype.getDefaultTooltipTemplate = function () {
        return this.cw.o2.c$c(this.e, this.cw.pc);
    };
    AnchoredCategorySeriesView.$t = markType(AnchoredCategorySeriesView, 'AnchoredCategorySeriesView', CategorySeriesView.$);
    return AnchoredCategorySeriesView;
}(CategorySeriesView));
export { AnchoredCategorySeriesView };
//# sourceMappingURL=AnchoredCategorySeries_combined.js.map