/*
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-angular-core/ES5/DependencyProperty";
import { Rect } from "igniteui-angular-core/ES5/Rect";
import { Base, typeCast, Array_$type, Number_$type, markType } from "igniteui-angular-core/ES5/type";
import { List$1 } from "igniteui-angular-core/ES5/List$1";
import { ScalerParams } from "./ScalerParams";
import { NumericScaler } from "./NumericScaler";
import { VerticalAxisLabelPanel } from "./VerticalAxisLabelPanel";
import { MathUtil } from "igniteui-angular-core/ES5/MathUtil";
import { AxisRangeChangedEventArgs } from "./AxisRangeChangedEventArgs";
import { LinearCategorySnapper } from "./LinearCategorySnapper";
import { NumericXAxis } from "./NumericXAxis";
import { LabelPosition } from "./LabelPosition";
import { PropertyMetadata } from "igniteui-angular-core/ES5/PropertyMetadata";
import { truncate, isNaN_, isInfinity } from "igniteui-angular-core/ES5/number";
import { CategoryAxisBaseView } from "./CategoryAxisBaseView";
/**
 * @hidden
 */
var CategoryYAxis = /** @class */ (function (_super) {
    tslib_1.__extends(CategoryYAxis, _super);
    function CategoryYAxis() {
        var _this = _super.call(this) || this;
        _this.kx = 0;
        _this.kz = 0;
        _this.k5 = 1;
        _this.k4 = 1;
        _this.jl = new List$1(Number_$type, 0);
        _this.ab = CategoryYAxis.$;
        return _this;
    }
    CategoryYAxis.prototype.a1 = function () {
        return new CategoryYAxisView(this);
    };
    CategoryYAxis.prototype.gr = function (a) {
        _super.prototype.gr.call(this, a);
        this.kw = a;
    };
    CategoryYAxis.prototype.get_ce = function () {
        return true;
    };
    CategoryYAxis.prototype.du = function () {
        return this.i0.height;
    };
    CategoryYAxis.prototype.kt = function (a, b, c) {
        return this.ku(a, b, c, true);
    };
    CategoryYAxis.prototype.kv = function (a) {
        if (typeCast(List$1.$.specialize(Array_$type), a) !== null) {
            return a.asArray();
        }
        return null;
    };
    CategoryYAxis.prototype.gl = 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.jx - 1 : this.jx;
        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.kv(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 - (o * r)) / p;
                    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, "k2", {
        get: function () {
            return this.c(CategoryYAxis.le);
        },
        set: function (a) {
            this.h(CategoryYAxis.le, a);
        },
        enumerable: true,
        configurable: true
    });
    Object.defineProperty(CategoryYAxis.prototype, "ky", {
        get: function () {
            return this.kx;
        },
        set: function (a) {
            if (this.ky != a) {
                var b = this.kx;
                this.kx = a;
                this.gz("ActualInterval", b, this.ky);
            }
        },
        enumerable: true,
        configurable: true
    });
    CategoryYAxis.prototype.d6 = function () {
        return this.ky;
    };
    Object.defineProperty(CategoryYAxis.prototype, "k3", {
        get: function () {
            return this.c(CategoryYAxis.lf);
        },
        set: function (a) {
            this.h(CategoryYAxis.lf, a);
        },
        enumerable: true,
        configurable: true
    });
    Object.defineProperty(CategoryYAxis.prototype, "k0", {
        get: function () {
            return this.kz;
        },
        set: function (a) {
            if (this.k0 != a) {
                var b = this.kz;
                this.kz = a;
                this.gz("ActualMinorInterval", b, this.k0);
            }
        },
        enumerable: true,
        configurable: true
    });
    Object.defineProperty(CategoryYAxis.prototype, "k7", {
        get: function () {
            return this.k5;
        },
        set: function (a) {
            this.k5 = a;
        },
        enumerable: true,
        configurable: true
    });
    Object.defineProperty(CategoryYAxis.prototype, "k6", {
        get: function () {
            return this.k4;
        },
        set: function (a) {
            this.k4 = a;
        },
        enumerable: true,
        configurable: true
    });
    CategoryYAxis.prototype.dv = function (a, b) {
        if (!b.c.isEmpty) {
            var c = this.k1(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.k1(a, b.e, b.d);
    };
    CategoryYAxis.prototype.k1 = function (a, b, c) {
        var d = this.categoryMode == 0 ? this.jx - 1 : this.jx;
        if (d < 0) {
            d = 0;
        }
        var e = d >= 1 ? (a) / (d) : d == 0 ? 0.5 : NaN;
        if (!this.b9) {
            e = 1 - e;
        }
        return c.top + c.height * (e - b.top) / b.height;
    };
    CategoryYAxis.prototype.dy = 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.dz = 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.b9) {
            e = 1 - e;
        }
        var f = d == 0 ? this.jx - 1 : this.jx;
        if (f < 0) {
            f = 0;
        }
        return e * f;
    };
    CategoryYAxis.prototype.ld = function (a, b) {
        if (a == NaN || b == NaN || this.je == null || this.je.count == 0) {
            return;
        }
        var c = a / this.je.count;
        var d = b / this.je.count;
        this.bf.m4 = new Rect(0, this.bf.m4.x, 1 - d, this.bf.m4.width, d - c);
    };
    CategoryYAxis.prototype.as = function () {
        return new VerticalAxisLabelPanel();
    };
    CategoryYAxis.prototype.di = function () {
        return this.k2;
    };
    CategoryYAxis.prototype.getCategorySize = function (a, b, c) {
        var d = this.iy(b, c);
        return d.height / (this.jx * a.height);
    };
    CategoryYAxis.prototype.jq = function (a, b, c) {
        var d = 0;
        if (!isNaN_(this.jn)) {
            d = MathUtil.b(this.jn, 0, 1);
        }
        var e = 0;
        if (!isNaN_(this.ju)) {
            e = Math.min(this.ju, 1);
        }
        var f = 1 - 0.5 * d;
        var g = this.getCategorySize(a, b, c) * f / (this.j0 - (this.j0 - 1) * e);
        return g;
    };
    CategoryYAxis.prototype.getGroupCenter = function (a, b, c, d) {
        var e = 0.5;
        if (this.j0 > 1) {
            var f = 0;
            if (!isNaN_(this.jn)) {
                f = MathUtil.b(this.jn, 0, 1);
            }
            var g = 0;
            if (!isNaN_(this.ju)) {
                g = Math.min(this.ju, 1);
            }
            var h = 1 - 0.5 * f;
            var i = h / (this.j0 - (this.j0 - 1) * g);
            var j = (h - i) / (this.j0 - 1);
            e = 0.25 * f + 0.5 * i + a * j;
        }
        return this.getCategorySize(b, c, d) * e;
    };
    CategoryYAxis.prototype.lc = function (a) {
        var b = this.bf != null ? this.bf.mq : Rect.empty;
        b = b.copy();
        var c = this.i0;
        var d = new Rect(0, 0, 0, 1, 1);
        var e = this.ix();
        var f = new ScalerParams(0, d, d, this.b8, e);
        var g = !b.isEmpty && !c.isEmpty && this.je != null ? this.je.indexOf(a) : -1;
        var h = g > -1 ? this.dv(g, f) : NaN;
        if (!isNaN_(h) && this.bf.c0) {
            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.bf.km(b, false, true);
        }
    };
    CategoryYAxis.prototype.cm = function () {
        if (this.cf && this.cn) {
            this.a9 = this.a8();
        }
        if (this.je == null) {
            return false;
        }
        var a = this.je.count;
        if (a != this.k6) {
            var b = new AxisRangeChangedEventArgs(0, 1, 1, this.k6, a);
            this.k6 = a;
            this.g0(b);
            return true;
        }
        return false;
    };
    CategoryYAxis.prototype.jh = function (a) {
        if (a == null) {
            return false;
        }
        var b = this.bb();
        if (b == null) {
            return false;
        }
        return b.synchronizeVertically;
    };
    CategoryYAxis.prototype.g6 = function (a) {
        _super.prototype.g6.call(this, a);
        var b = this.bf != null ? this.bf.mq : Rect.empty;
        var c = this.i0;
        var d = this.iv();
        var e = this.iu();
        var f = new ScalerParams(0, b, c, this.b8, d);
        var g = this.a2.ay();
        var h = this.a2.a1();
        var i = this.a2.az();
        var j = this.a2.a0();
        var k = this.a2.e();
        var l = this.a2.f();
        var m = this.a2.g();
        this.hd();
        this.gh(g);
        this.gh(h);
        this.gh(i);
        this.gh(j);
        this.cu.clear();
        this.cv.clear();
        this.jl.clear();
        this.a2.at(this, b, c);
        if (b.isEmpty || c.isEmpty) {
            this.bo.count = 0;
            this.bn.count = 0;
            this.bm.count = 0;
        }
        if (this.bo.count == 0 && this.bn.count == 0) {
            this.a2.y();
        }
        if (this.aw != null) {
            this.aw.registerAxis(this);
        }
        if (this.itemsSource == null || this.je == null || this.je.count == 0) {
            this.bo.count = 0;
            this.bn.count = 0;
            this.bm.count = 0;
            this.a2.y();
            return;
        }
        if (!b.isEmpty && !c.isEmpty) {
            var n = this.dy(e.top, f);
            var o = this.dy(e.bottom, f);
            if (!this.b8) {
                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.ag != null) {
                var r = typeCast(NumericXAxis.$, this.ag);
                if (r != null) {
                    var s = this.g9(p, q, b, c, d, c.left, c.right);
                    p = s.p0;
                    q = s.p1;
                }
            }
            this.he(g, p, c, k, true);
            this.a2.ao(q);
            var t = Math.min(n, o);
            var u = Math.max(n, o);
            var v = new LinearCategorySnapper(1, t, u, e.height, this.k2, this.categoryMode, this.d8());
            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.dv(0 + y * v.g, f);
                var ab = Math.abs(this.dv(v.g, f) - this.dv(0, f));
                this.at.bn = this.dv(v.g, f);
                for (var ac = y; ac <= z; ++ac) {
                    var ad = this.dv(0 + (ac + 1) * v.g, f);
                    if (aa <= e.bottom) {
                        if (ac % 2 == 0) {
                            this.gq(h, aa, ad, c);
                        }
                        this.gp(i, aa, c, l, false);
                        this.jl.add(aa);
                    }
                    if (this.categoryMode != 0 && this.j0 != 0 && this.ci) {
                        if (this.k3 > 0 && this.k3 < v.g) {
                            var ae = ab * this.k3;
                            if (!this.b8) {
                                var af = aa;
                                while (af - ae > ad) {
                                    af -= ae;
                                    if (Math.abs(af - ad) < 0.0001) {
                                        break;
                                    }
                                    this.gp(j, af, c, m, false);
                                }
                            }
                            else {
                                var ag = aa;
                                while (ag + ae < ad) {
                                    ag += ae;
                                    if (Math.abs(ag - ad) < 0.0001) {
                                        break;
                                    }
                                    this.gp(j, ag, c, m, false);
                                }
                            }
                            this.k0 = this.k3;
                        }
                        else {
                            for (var ah = 0; ah < truncate(v.g); ah++) {
                                for (var ai = 0; ai < this.j0; ai++) {
                                    var aj = this.getGroupCenter(ai, b, c, d);
                                    if (!this.b8) {
                                        aj = -aj;
                                    }
                                    var ak = this.dv(ah + ac * v.g, f) + aj;
                                    this.gp(j, ak, c, m, false);
                                }
                            }
                            this.k0 = 0.5;
                        }
                    }
                    var al = aa;
                    if (this.categoryMode != 0) {
                        var am = this.dv(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.je != null && an < this.je.count && an >= 0) {
                            var ao = this.je.item(an);
                            var ap = this.e5(ao);
                            if (!isNaN_(al) && !isInfinity(al) && ap != null) {
                                if ((typeof ap === 'string') && Base.equalsStatic(ap, "")) {
                                }
                                else {
                                    this.cu.add1(ap);
                                    this.cv.add(new LabelPosition(al));
                                }
                            }
                        }
                    }
                    aa = ad;
                }
            }
            this.ky = v.g;
            if ((this.aw == null || this.aw.visibility == 0) && this.ag != null) {
                if (this.aw != null && (this.aw.location == 6 || this.aw.location == 7)) {
                    this.bf.ht();
                }
            }
            this.a2.au(this.cu, this.cv);
            this.kl();
        }
    };
    CategoryYAxis.prototype.get_az = function () {
        return 1;
    };
    Object.defineProperty(CategoryYAxis.prototype, "az", {
        get: function () {
            return this.get_az();
        },
        enumerable: true,
        configurable: true
    });
    Object.defineProperty(CategoryYAxis.prototype, "isVertical", {
        get: function () {
            return this.ce;
        },
        enumerable: true,
        configurable: true
    });
    CategoryYAxis.prototype.j$c = function (a, b) {
        return this.dy.apply(this, arguments);
    };
    CategoryYAxis.prototype.j$b = function (a, b) {
        return this.dv.apply(this, arguments);
    };
    CategoryYAxis.prototype.j$d = function (a, b, c, d, e) {
        this.gl.apply(this, arguments);
    };
    CategoryYAxis.prototype.j$e = function (a, b, c, d) {
        this.gm.apply(this, arguments);
    };
    CategoryYAxis.prototype.j$f = function (a, b, c, d) {
        this.gn.apply(this, arguments);
    };
    Object.defineProperty(CategoryYAxis.prototype, "j$a", {
        get: function () {
            return this.b8;
        },
        enumerable: true,
        configurable: true
    });
    CategoryYAxis.$t = markType(CategoryYAxis, 'CategoryYAxis', CategoryAxisBase.$);
    CategoryYAxis.le = DependencyProperty.i("Interval", Number_$type, CategoryYAxis.$, new PropertyMetadata(2, NaN, function (a, b) {
        a.gz("Interval", b.oldValue, b.newValue);
        a.g5(false);
    }));
    CategoryYAxis.lf = DependencyProperty.i("MinorInterval", Number_$type, CategoryYAxis.$, new PropertyMetadata(2, NaN, function (a, b) {
        (typeCast(CategoryYAxis.$, a)).gz("MinorInterval", b.oldValue, b.newValue);
        (typeCast(CategoryYAxis.$, a)).g5(false);
    }));
    return CategoryYAxis;
}(CategoryAxisBase));
export { CategoryYAxis };
/**
 * @hidden
 */
var CategoryYAxisView = /** @class */ (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