/*
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 { CategoryAxisBase } from "./CategoryAxisBase";
import { DependencyProperty } from "igniteui-react-core";
import { Rect } from "igniteui-react-core";
import { Base, typeCast, Array_$type, Number_$type, markType } from "igniteui-react-core";
import { List$1 } from "igniteui-react-core";
import { ScalerParams } from "./ScalerParams";
import { NumericScaler } from "./NumericScaler";
import { VerticalAxisLabelPanel } from "./VerticalAxisLabelPanel";
import { MathUtil } from "igniteui-react-core";
import { AxisRangeChangedEventArgs } from "./AxisRangeChangedEventArgs";
import { LinearCategorySnapper } from "./LinearCategorySnapper";
import { NumericXAxis } from "./NumericXAxis";
import { LabelPosition } from "./LabelPosition";
import { PropertyMetadata } from "igniteui-react-core";
import { truncate, isNaN_, isInfinity } from "igniteui-react-core";
import { CategoryAxisBaseView } from "./CategoryAxisBaseView";
/**
 * @hidden
 */
var CategoryYAxis = /** @class */ /*@__PURE__*/ (function (_super) {
    tslib_1.__extends(CategoryYAxis, _super);
    function CategoryYAxis() {
        var _this = _super.call(this) || this;
        _this.k7 = 0;
        _this.k8 = 0;
        _this.lf = 1;
        _this.le = 1;
        _this.jv = new List$1(Number_$type, 0);
        _this.ab = CategoryYAxis.$;
        return _this;
    }
    CategoryYAxis.prototype.a3 = function () {
        return new CategoryYAxisView(this);
    };
    CategoryYAxis.prototype.gy = function (a) {
        _super.prototype.gy.call(this, a);
        this.k6 = a;
    };
    CategoryYAxis.prototype.get_ch = function () {
        return true;
    };
    CategoryYAxis.prototype.dy = function () {
        return this.ja.height;
    };
    CategoryYAxis.prototype.k3 = function (a, b, c) {
        return this.k4(a, b, c, true);
    };
    CategoryYAxis.prototype.k5 = function (a) {
        if (typeCast(List$1.$.specialize(Array_$type), a) !== null) {
            return a.asArray();
        }
        return null;
    };
    CategoryYAxis.prototype.gs = function (a, b, c, d, e) {
        var f;
        var g = e.e;
        var h = e.d;
        var i = e.c;
        var j = e.a;
        var k = !i.isEmpty;
        var l = this.categoryMode == 0 ? this.j8 - 1 : this.j8;
        if (l < 0) {
            l = 0;
        }
        var m = i.top;
        var n = i.height;
        var o = g.top;
        var p = g.height;
        var q = h.top;
        var r = h.height;
        var s = 0;
        var t = 1;
        var u = this.k5(a);
        var v = false;
        if (u != null) {
            v = true;
        }
        var w;
        for (var x = 0; x < b.count; x++) {
            w = b.item(x);
            for (var y = c; y < d; y++) {
                if (v) {
                    f = u[y];
                }
                else {
                    f = a.item(y);
                }
                if (k) {
                    var z = l >= 1 ? (f[w]) / (l) : l == 0 ? 0.5 : NaN;
                    if (!j) {
                        z = 1 - z;
                    }
                    z = m + n * (z - s) / t;
                    var aa = (z - e.d.top) / e.d.height;
                    aa = e.d.top + e.d.height * (aa - e.e.top) / e.e.height;
                    f[w] = aa;
                }
                else {
                    var ab = l >= 1 ? (f[w]) / (l) : l == 0 ? 0.5 : NaN;
                    if (!j) {
                        ab = 1 - ab;
                    }
                    ab = q + r * (ab - o) / p;
                    f[w] = ab;
                }
            }
        }
    };
    Object.defineProperty(CategoryYAxis.prototype, "lc", {
        get: function () {
            return this.c(CategoryYAxis.lo);
        },
        set: function (a) {
            this.h(CategoryYAxis.lo, a);
        },
        enumerable: true,
        configurable: true
    });
    Object.defineProperty(CategoryYAxis.prototype, "k9", {
        get: function () {
            return this.k7;
        },
        set: function (a) {
            if (this.k9 != a) {
                var b = this.k7;
                this.k7 = a;
                this.g6("ActualInterval", b, this.k9);
            }
        },
        enumerable: true,
        configurable: true
    });
    CategoryYAxis.prototype.ea = function () {
        return this.k9;
    };
    Object.defineProperty(CategoryYAxis.prototype, "ld", {
        get: function () {
            return this.c(CategoryYAxis.lp);
        },
        set: function (a) {
            this.h(CategoryYAxis.lp, a);
        },
        enumerable: true,
        configurable: true
    });
    Object.defineProperty(CategoryYAxis.prototype, "la", {
        get: function () {
            return this.k8;
        },
        set: function (a) {
            if (this.la != a) {
                var b = this.k8;
                this.k8 = a;
                this.g6("ActualMinorInterval", b, this.la);
            }
        },
        enumerable: true,
        configurable: true
    });
    Object.defineProperty(CategoryYAxis.prototype, "lh", {
        get: function () {
            return this.lf;
        },
        set: function (a) {
            this.lf = a;
        },
        enumerable: true,
        configurable: true
    });
    Object.defineProperty(CategoryYAxis.prototype, "lg", {
        get: function () {
            return this.le;
        },
        set: function (a) {
            this.le = a;
        },
        enumerable: true,
        configurable: true
    });
    CategoryYAxis.prototype.dz = function (a, b) {
        if (!b.c.isEmpty) {
            var c = this.lb(a, NumericScaler.ac, b.c);
            c = (c - b.d.top) / b.d.height;
            c = b.d.top + b.d.height * (c - b.e.top) / b.e.height;
            return c;
        }
        return this.lb(a, b.e, b.d);
    };
    CategoryYAxis.prototype.lb = function (a, b, c) {
        var d = this.categoryMode == 0 ? this.j8 - 1 : this.j8;
        if (d < 0) {
            d = 0;
        }
        var e = d >= 1 ? (a) / (d) : d == 0 ? 0.5 : NaN;
        if (!this.cb) {
            e = 1 - e;
        }
        return c.top + c.height * (e - b.top) / b.height;
    };
    CategoryYAxis.prototype.d2 = function (a, b) {
        if (!b.c.isEmpty) {
            var c = b.e.top + b.e.height * (a - b.d.top) / b.d.height;
            c = (c * b.d.height) + b.d.top;
            c = this.getUnscaledValue3(c, NumericScaler.ac, b.c, this.categoryMode);
            return c;
        }
        return this.getUnscaledValue3(a, b.e, b.d, this.categoryMode);
    };
    CategoryYAxis.prototype.d3 = function (a, b, c) {
        if (!b.c.isEmpty) {
            var d = b.e.top + b.e.height * (a - b.d.top) / b.d.height;
            d = (d * b.d.height) + b.d.top;
            d = this.getUnscaledValue3(d, NumericScaler.ac, b.c, c);
            return d;
        }
        return this.getUnscaledValue3(a, b.e, b.d, c);
    };
    CategoryYAxis.prototype.getUnscaledValue3 = function (a, b, c, d) {
        var e = b.top + (a - c.top) * b.height / c.height;
        if (!this.cb) {
            e = 1 - e;
        }
        var f = d == 0 ? this.j8 - 1 : this.j8;
        if (f < 0) {
            f = 0;
        }
        return e * f;
    };
    CategoryYAxis.prototype.ln = function (a, b) {
        if (a == NaN || b == NaN || this.jo == null || this.jo.count == 0) {
            return;
        }
        var c = a / this.jo.count;
        var d = b / this.jo.count;
        this.bh.o8 = new Rect(0, this.bh.o8.x, 1 - d, this.bh.o8.width, d - c);
    };
    CategoryYAxis.prototype.au = function () {
        return new VerticalAxisLabelPanel();
    };
    CategoryYAxis.prototype.dm = function () {
        return this.lc;
    };
    CategoryYAxis.prototype.getCategorySize = function (a, b, c) {
        var d = this.i8(b, c);
        return d.height / (this.j8 * a.height);
    };
    CategoryYAxis.prototype.j0 = function (a, b, c) {
        var d = 0;
        if (!isNaN_(this.jx)) {
            d = MathUtil.b(this.jx, 0, 1);
        }
        var e = 0;
        if (!isNaN_(this.j4)) {
            e = Math.min(this.j4, 1);
        }
        var f = 1 - 0.5 * d;
        var g = this.getCategorySize(a, b, c) * f / (this.ka - (this.ka - 1) * e);
        return g;
    };
    CategoryYAxis.prototype.getGroupCenter = function (a, b, c, d) {
        var e = 0.5;
        if (this.ka > 1) {
            var f = 0;
            if (!isNaN_(this.jx)) {
                f = MathUtil.b(this.jx, 0, 1);
            }
            var g = 0;
            if (!isNaN_(this.j4)) {
                g = Math.min(this.j4, 1);
            }
            var h = 1 - 0.5 * f;
            var i = h / (this.ka - (this.ka - 1) * g);
            var j = (h - i) / (this.ka - 1);
            e = 0.25 * f + 0.5 * i + a * j;
        }
        return this.getCategorySize(b, c, d) * e;
    };
    CategoryYAxis.prototype.lm = function (a) {
        var b = this.bh != null ? this.bh.os : Rect.empty;
        b = b.copy();
        var c = this.ja;
        var d = new Rect(0, 0, 0, 1, 1);
        var e = this.i7();
        var f = new ScalerParams(0, d, d, this.ca, e);
        var g = !b.isEmpty && !c.isEmpty && this.jo != null ? this.jo.indexOf(a) : -1;
        var h = g > -1 ? this.dz(g, f) : NaN;
        if (!isNaN_(h) && this.bh.dt) {
            if (!isNaN_(h)) {
                if (h < b.top + 0.1 * b.height) {
                    h = h + 0.4 * b.height;
                    b.y = h - 0.5 * b.height;
                }
                if (h > b.bottom - 0.1 * b.height) {
                    h = h - 0.4 * b.height;
                    b.y = h - 0.5 * b.height;
                }
            }
            this.bh.md(b, false, true);
        }
    };
    CategoryYAxis.prototype.cp = function () {
        if (this.ci && this.cq) {
            this.bb = this.ba();
        }
        if (this.jo == null) {
            return false;
        }
        var a = this.jo.count;
        if (a != this.lg) {
            var b = new AxisRangeChangedEventArgs(0, 1, 1, this.lg, a);
            this.lg = a;
            this.g7(b);
            return true;
        }
        return false;
    };
    CategoryYAxis.prototype.jr = function (a) {
        if (a == null) {
            return false;
        }
        var b = this.bd();
        if (b == null) {
            return false;
        }
        return b.synchronizeVertically;
    };
    CategoryYAxis.prototype.hd = function (a) {
        _super.prototype.hd.call(this, a);
        var b = this.bh != null ? this.bh.os : Rect.empty;
        var c = this.ja;
        var d = this.i5();
        var e = this.i4();
        var f = new ScalerParams(0, b, c, this.ca, d);
        var g = this.a4.ay();
        var h = this.a4.a1();
        var i = this.a4.az();
        var j = this.a4.a0();
        var k = this.a4.e();
        var l = this.a4.f();
        var m = this.a4.g();
        this.hl();
        this.go(g);
        this.go(h);
        this.go(i);
        this.go(j);
        this.cx.clear();
        this.cy.clear();
        this.jv.clear();
        this.a4.at(this, b, c);
        if (b.isEmpty || c.isEmpty) {
            this.bq.count = 0;
            this.bp.count = 0;
            this.bo.count = 0;
        }
        if (this.bq.count == 0 && this.bp.count == 0) {
            this.a4.y();
        }
        if (this.ay != null) {
            this.ay.registerAxis(this);
        }
        if (this.itemsSource == null || this.jo == null || this.jo.count == 0) {
            this.bq.count = 0;
            this.bp.count = 0;
            this.bo.count = 0;
            this.a4.y();
            return;
        }
        if (!b.isEmpty && !c.isEmpty) {
            var n = this.d2(e.top, f);
            var o = this.d2(e.bottom, f);
            if (!this.ca) {
                n = Math.ceil(n);
                o = Math.floor(o);
            }
            else {
                n = Math.floor(n);
                o = Math.ceil(o);
            }
            var p = c.left;
            var q = 0;
            if (this.ai != null) {
                var r = typeCast(NumericXAxis.$, this.ai);
                if (r != null) {
                    var s = this.hh(p, q, b, c, d, c.left, c.right);
                    p = s.p0;
                    q = s.p1;
                }
            }
            this.hm(g, p, c, k, true);
            this.a4.ao(q);
            var t = Math.min(n, o);
            var u = Math.max(n, o);
            var v = new LinearCategorySnapper(1, t, u, e.height, this.lc, this.categoryMode, this.ec());
            var w = Math.floor((t - 0) / v.g);
            var x = Math.ceil((u - 0) / v.g);
            if (!isNaN_(w) && !isNaN_(x)) {
                var y = truncate(w);
                var z = truncate(x);
                var aa = this.dz(0 + y * v.g, f);
                var ab = Math.abs(this.dz(v.g, f) - this.dz(0, f));
                this.av.bo = this.dz(v.g, f);
                for (var ac = y; ac <= z; ++ac) {
                    var ad = this.dz(0 + (ac + 1) * v.g, f);
                    if (aa <= e.bottom) {
                        if (ac % 2 == 0) {
                            this.gx(h, aa, ad, c);
                        }
                        this.gw(i, aa, c, l, false);
                        this.jv.add(aa);
                    }
                    if (this.categoryMode != 0 && this.ka != 0 && this.cl) {
                        if (this.ld > 0 && this.ld < v.g) {
                            var ae = ab * this.ld;
                            if (!this.ca) {
                                var af = aa;
                                while (af - ae > ad) {
                                    af -= ae;
                                    if (Math.abs(af - ad) < 0.0001) {
                                        break;
                                    }
                                    this.gw(j, af, c, m, false);
                                }
                            }
                            else {
                                var ag = aa;
                                while (ag + ae < ad) {
                                    ag += ae;
                                    if (Math.abs(ag - ad) < 0.0001) {
                                        break;
                                    }
                                    this.gw(j, ag, c, m, false);
                                }
                            }
                            this.la = this.ld;
                        }
                        else {
                            for (var ah = 0; ah < truncate(v.g); ah++) {
                                for (var ai = 0; ai < this.ka; ai++) {
                                    var aj = this.getGroupCenter(ai, b, c, d);
                                    if (!this.ca) {
                                        aj = -aj;
                                    }
                                    var ak = this.dz(ah + ac * v.g, f) + aj;
                                    this.gw(j, ak, c, m, false);
                                }
                            }
                            this.la = 0.5;
                        }
                    }
                    var al = aa;
                    if (this.categoryMode != 0) {
                        var am = this.dz(ac * v.g + 1, f);
                        al = (aa + am) / 2;
                    }
                    if (al <= e.bottom && al >= e.top) {
                        var an = 0;
                        if (v.g >= 1) {
                            an = ac * truncate(Math.floor(v.g));
                        }
                        else {
                            if ((ac * v.g) * 2 % 2 == 0) {
                                an = truncate(Math.floor(ac * v.g));
                            }
                            else {
                                an = -1;
                            }
                        }
                        if (this.jo != null && an < this.jo.count && an >= 0) {
                            var ao = this.jo.item(an);
                            var ap = this.e9(ao);
                            if (!isNaN_(al) && !isInfinity(al) && ap != null) {
                                if ((typeof ap === 'string') && Base.equalsStatic(ap, "")) {
                                }
                                else {
                                    this.cx.add1(ap);
                                    this.cy.add(new LabelPosition(al));
                                }
                            }
                        }
                    }
                    aa = ad;
                }
            }
            this.k9 = v.g;
            if ((this.ay == null || this.ay.visibility == 0) && this.ai != null) {
                if (this.ay != null && (this.ay.location == 6 || this.ay.location == 7)) {
                    this.bh.ja();
                }
            }
            this.a4.au(this.cx, this.cy);
            this.kv();
        }
    };
    CategoryYAxis.prototype.get_a1 = function () {
        return 1;
    };
    Object.defineProperty(CategoryYAxis.prototype, "a1", {
        get: function () {
            return this.get_a1();
        },
        enumerable: true,
        configurable: true
    });
    Object.defineProperty(CategoryYAxis.prototype, "isVertical", {
        get: function () {
            return this.ch;
        },
        enumerable: true,
        configurable: true
    });
    CategoryYAxis.prototype.j$c = function (a, b) {
        return this.d2.apply(this, arguments);
    };
    CategoryYAxis.prototype.j$b = function (a, b) {
        return this.dz.apply(this, arguments);
    };
    CategoryYAxis.prototype.j$d = function (a, b, c, d, e) {
        this.gs.apply(this, arguments);
    };
    CategoryYAxis.prototype.j$e = function (a, b, c, d) {
        this.gt.apply(this, arguments);
    };
    CategoryYAxis.prototype.j$f = function (a, b, c, d) {
        this.gu.apply(this, arguments);
    };
    Object.defineProperty(CategoryYAxis.prototype, "j$a", {
        get: function () {
            return this.ca;
        },
        enumerable: true,
        configurable: true
    });
    CategoryYAxis.$t = markType(CategoryYAxis, 'CategoryYAxis', CategoryAxisBase.$);
    CategoryYAxis.lo = DependencyProperty.i("Interval", Number_$type, CategoryYAxis.$, new PropertyMetadata(2, NaN, function (a, b) {
        a.g6("Interval", b.oldValue, b.newValue);
        a.hc(false);
    }));
    CategoryYAxis.lp = DependencyProperty.i("MinorInterval", Number_$type, CategoryYAxis.$, new PropertyMetadata(2, NaN, function (a, b) {
        (typeCast(CategoryYAxis.$, a)).g6("MinorInterval", b.oldValue, b.newValue);
        (typeCast(CategoryYAxis.$, a)).hc(false);
    }));
    return CategoryYAxis;
}(CategoryAxisBase));
export { CategoryYAxis };
/**
 * @hidden
 */
var CategoryYAxisView = /** @class */ /*@__PURE__*/ (function (_super) {
    tslib_1.__extends(CategoryYAxisView, _super);
    function CategoryYAxisView(a) {
        var _this = _super.call(this, a) || this;
        _this.bg = null;
        _this.bg = a;
        return _this;
    }
    CategoryYAxisView.$t = markType(CategoryYAxisView, 'CategoryYAxisView', CategoryAxisBaseView.$);
    return CategoryYAxisView;
}(CategoryAxisBaseView));
export { CategoryYAxisView };
//# sourceMappingURL=CategoryYAxis_combined.js.map
