/*
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 { CategoryAxisBase } from "./CategoryAxisBase";
import { DependencyProperty } from "igniteui-angular-core";
import { Rect } from "igniteui-angular-core";
import { Base, typeCast, Array_$type, Number_$type, markType } from "igniteui-angular-core";
import { List$1 } from "igniteui-angular-core";
import { ScalerParams } from "./ScalerParams";
import { NumericScaler } from "./NumericScaler";
import { VerticalAxisLabelPanel } from "./VerticalAxisLabelPanel";
import { MathUtil } from "igniteui-angular-core";
import { AxisRangeChangedEventArgs } from "./AxisRangeChangedEventArgs";
import { LinearCategorySnapper } from "./LinearCategorySnapper";
import { NumericXAxis } from "./NumericXAxis";
import { LabelPosition } from "./LabelPosition";
import { PropertyMetadata } from "igniteui-angular-core";
import { truncate, isNaN_, isInfinity } from "igniteui-angular-core";
import { CategoryAxisBaseView } from "./CategoryAxisBaseView";
/**
 * @hidden
 */
export class CategoryYAxis extends CategoryAxisBase {
    constructor() {
        super();
        this.ky = 0;
        this.k0 = 0;
        this.k6 = 1;
        this.k5 = 1;
        this.jm = new List$1(Number_$type, 0);
        this.ab = CategoryYAxis.$;
    }
    a1() {
        return new CategoryYAxisView(this);
    }
    gs(a) {
        super.gs(a);
        this.kx = a;
    }
    get_cf() {
        return true;
    }
    dv() {
        return this.i1.height;
    }
    ku(a, b, c) {
        return this.kv(a, b, c, true);
    }
    kw(a) {
        if (typeCast(List$1.$.specialize(Array_$type), a) !== null) {
            return a.asArray();
        }
        return null;
    }
    gm(a, b, c, d, e) {
        let f;
        let g = e.e;
        let h = e.d;
        let i = e.c;
        let j = e.a;
        let k = !i.isEmpty;
        let l = this.categoryMode == 0 ? this.jy - 1 : this.jy;
        if (l < 0) {
            l = 0;
        }
        let m = i.top;
        let n = i.height;
        let o = g.top;
        let p = g.height;
        let q = h.top;
        let r = h.height;
        let s = 0;
        let t = 1;
        let u = this.kw(a);
        let v = false;
        if (u != null) {
            v = true;
        }
        let w;
        for (let x = 0; x < b.count; x++) {
            w = b.item(x);
            for (let y = c; y < d; y++) {
                if (v) {
                    f = u[y];
                }
                else {
                    f = a.item(y);
                }
                if (k) {
                    let z = l >= 1 ? (f[w]) / (l) : l == 0 ? 0.5 : NaN;
                    if (!j) {
                        z = 1 - z;
                    }
                    z = m + n * (z - s) / t;
                    let aa = (z - (o * r)) / p;
                    f[w] = aa;
                }
                else {
                    let 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;
                }
            }
        }
    }
    get k3() {
        return this.c(CategoryYAxis.lf);
    }
    set k3(a) {
        this.h(CategoryYAxis.lf, a);
    }
    get kz() {
        return this.ky;
    }
    set kz(a) {
        if (this.kz != a) {
            let b = this.ky;
            this.ky = a;
            this.g0("ActualInterval", b, this.kz);
        }
    }
    d7() {
        return this.kz;
    }
    get k4() {
        return this.c(CategoryYAxis.lg);
    }
    set k4(a) {
        this.h(CategoryYAxis.lg, a);
    }
    get k1() {
        return this.k0;
    }
    set k1(a) {
        if (this.k1 != a) {
            let b = this.k0;
            this.k0 = a;
            this.g0("ActualMinorInterval", b, this.k1);
        }
    }
    get k8() {
        return this.k6;
    }
    set k8(a) {
        this.k6 = a;
    }
    get k7() {
        return this.k5;
    }
    set k7(a) {
        this.k5 = a;
    }
    dw(a, b) {
        if (!b.c.isEmpty) {
            let c = this.k2(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.k2(a, b.e, b.d);
    }
    k2(a, b, c) {
        let d = this.categoryMode == 0 ? this.jy - 1 : this.jy;
        if (d < 0) {
            d = 0;
        }
        let 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;
    }
    dz(a, b) {
        if (!b.c.isEmpty) {
            let 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);
    }
    d0(a, b, c) {
        if (!b.c.isEmpty) {
            let 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);
    }
    getUnscaledValue3(a, b, c, d) {
        let e = b.top + (a - c.top) * b.height / c.height;
        if (!this.b9) {
            e = 1 - e;
        }
        let f = d == 0 ? this.jy - 1 : this.jy;
        if (f < 0) {
            f = 0;
        }
        return e * f;
    }
    le(a, b) {
        if (a == NaN || b == NaN || this.jf == null || this.jf.count == 0) {
            return;
        }
        let c = a / this.jf.count;
        let d = b / this.jf.count;
        this.bf.m4 = new Rect(0, this.bf.m4.x, 1 - d, this.bf.m4.width, d - c);
    }
    as() {
        return new VerticalAxisLabelPanel();
    }
    dj() {
        return this.k3;
    }
    getCategorySize(a, b, c) {
        let d = this.iz(b, c);
        return d.height / (this.jy * a.height);
    }
    jr(a, b, c) {
        let d = 0;
        if (!isNaN_(this.jo)) {
            d = MathUtil.b(this.jo, 0, 1);
        }
        let e = 0;
        if (!isNaN_(this.jv)) {
            e = Math.min(this.jv, 1);
        }
        let f = 1 - 0.5 * d;
        let g = this.getCategorySize(a, b, c) * f / (this.j1 - (this.j1 - 1) * e);
        return g;
    }
    getGroupCenter(a, b, c, d) {
        let e = 0.5;
        if (this.j1 > 1) {
            let f = 0;
            if (!isNaN_(this.jo)) {
                f = MathUtil.b(this.jo, 0, 1);
            }
            let g = 0;
            if (!isNaN_(this.jv)) {
                g = Math.min(this.jv, 1);
            }
            let h = 1 - 0.5 * f;
            let i = h / (this.j1 - (this.j1 - 1) * g);
            let j = (h - i) / (this.j1 - 1);
            e = 0.25 * f + 0.5 * i + a * j;
        }
        return this.getCategorySize(b, c, d) * e;
    }
    ld(a) {
        let b = this.bf != null ? this.bf.mq : Rect.empty;
        b = b.copy();
        let c = this.i1;
        let d = new Rect(0, 0, 0, 1, 1);
        let e = this.iy();
        let f = new ScalerParams(0, d, d, this.b8, e);
        let g = !b.isEmpty && !c.isEmpty && this.jf != null ? this.jf.indexOf(a) : -1;
        let h = g > -1 ? this.dw(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);
        }
    }
    cn() {
        if (this.cg && this.co) {
            this.a9 = this.a8();
        }
        if (this.jf == null) {
            return false;
        }
        let a = this.jf.count;
        if (a != this.k7) {
            let b = new AxisRangeChangedEventArgs(0, 1, 1, this.k7, a);
            this.k7 = a;
            this.g1(b);
            return true;
        }
        return false;
    }
    ji(a) {
        if (a == null) {
            return false;
        }
        let b = this.bb();
        if (b == null) {
            return false;
        }
        return b.synchronizeVertically;
    }
    g7(a) {
        super.g7(a);
        let b = this.bf != null ? this.bf.mq : Rect.empty;
        let c = this.i1;
        let d = this.iw();
        let e = this.iv();
        let f = new ScalerParams(0, b, c, this.b8, d);
        let g = this.a2.ay();
        let h = this.a2.a1();
        let i = this.a2.az();
        let j = this.a2.a0();
        let k = this.a2.e();
        let l = this.a2.f();
        let m = this.a2.g();
        this.he();
        this.gi(g);
        this.gi(h);
        this.gi(i);
        this.gi(j);
        this.cv.clear();
        this.cw.clear();
        this.jm.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.jf == null || this.jf.count == 0) {
            this.bo.count = 0;
            this.bn.count = 0;
            this.bm.count = 0;
            this.a2.y();
            return;
        }
        if (!b.isEmpty && !c.isEmpty) {
            let n = this.dz(e.top, f);
            let o = this.dz(e.bottom, f);
            if (!this.b8) {
                n = Math.ceil(n);
                o = Math.floor(o);
            }
            else {
                n = Math.floor(n);
                o = Math.ceil(o);
            }
            let p = c.left;
            let q = 0;
            if (this.ag != null) {
                let r = typeCast(NumericXAxis.$, this.ag);
                if (r != null) {
                    let s = this.ha(p, q, b, c, d, c.left, c.right);
                    p = s.p0;
                    q = s.p1;
                }
            }
            this.hf(g, p, c, k, true);
            this.a2.ao(q);
            let t = Math.min(n, o);
            let u = Math.max(n, o);
            let v = new LinearCategorySnapper(1, t, u, e.height, this.k3, this.categoryMode, this.d9());
            let w = Math.floor((t - 0) / v.g);
            let x = Math.ceil((u - 0) / v.g);
            if (!isNaN_(w) && !isNaN_(x)) {
                let y = truncate(w);
                let z = truncate(x);
                let aa = this.dw(0 + y * v.g, f);
                let ab = Math.abs(this.dw(v.g, f) - this.dw(0, f));
                this.at.bn = this.dw(v.g, f);
                for (let ac = y; ac <= z; ++ac) {
                    let ad = this.dw(0 + (ac + 1) * v.g, f);
                    if (aa <= e.bottom) {
                        if (ac % 2 == 0) {
                            this.gr(h, aa, ad, c);
                        }
                        this.gq(i, aa, c, l, false);
                        this.jm.add(aa);
                    }
                    if (this.categoryMode != 0 && this.j1 != 0 && this.cj) {
                        if (this.k4 > 0 && this.k4 < v.g) {
                            let ae = ab * this.k4;
                            if (!this.b8) {
                                let af = aa;
                                while (af - ae > ad) {
                                    af -= ae;
                                    if (Math.abs(af - ad) < 0.0001) {
                                        break;
                                    }
                                    this.gq(j, af, c, m, false);
                                }
                            }
                            else {
                                let ag = aa;
                                while (ag + ae < ad) {
                                    ag += ae;
                                    if (Math.abs(ag - ad) < 0.0001) {
                                        break;
                                    }
                                    this.gq(j, ag, c, m, false);
                                }
                            }
                            this.k1 = this.k4;
                        }
                        else {
                            for (let ah = 0; ah < truncate(v.g); ah++) {
                                for (let ai = 0; ai < this.j1; ai++) {
                                    let aj = this.getGroupCenter(ai, b, c, d);
                                    if (!this.b8) {
                                        aj = -aj;
                                    }
                                    let ak = this.dw(ah + ac * v.g, f) + aj;
                                    this.gq(j, ak, c, m, false);
                                }
                            }
                            this.k1 = 0.5;
                        }
                    }
                    let al = aa;
                    if (this.categoryMode != 0) {
                        let am = this.dw(ac * v.g + 1, f);
                        al = (aa + am) / 2;
                    }
                    if (al <= e.bottom && al >= e.top) {
                        let 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.jf != null && an < this.jf.count && an >= 0) {
                            let ao = this.jf.item(an);
                            let ap = this.e6(ao);
                            if (!isNaN_(al) && !isInfinity(al) && ap != null) {
                                if ((typeof ap === 'string') && Base.equalsStatic(ap, "")) {
                                }
                                else {
                                    this.cv.add1(ap);
                                    this.cw.add(new LabelPosition(al));
                                }
                            }
                        }
                    }
                    aa = ad;
                }
            }
            this.kz = 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.cv, this.cw);
            this.km();
        }
    }
    get_az() {
        return 1;
    }
    get az() {
        return this.get_az();
    }
    get isVertical() {
        return this.cf;
    }
    j$c(a, b) {
        return this.dz.apply(this, arguments);
    }
    j$b(a, b) {
        return this.dw.apply(this, arguments);
    }
    j$d(a, b, c, d, e) {
        this.gm.apply(this, arguments);
    }
    j$e(a, b, c, d) {
        this.gn.apply(this, arguments);
    }
    j$f(a, b, c, d) {
        this.go.apply(this, arguments);
    }
    get j$a() {
        return this.b8;
    }
}
CategoryYAxis.$t = markType(CategoryYAxis, 'CategoryYAxis', CategoryAxisBase.$);
CategoryYAxis.lf = DependencyProperty.i("Interval", Number_$type, CategoryYAxis.$, new PropertyMetadata(2, NaN, (a, b) => {
    a.g0("Interval", b.oldValue, b.newValue);
    a.g6(false);
}));
CategoryYAxis.lg = DependencyProperty.i("MinorInterval", Number_$type, CategoryYAxis.$, new PropertyMetadata(2, NaN, (a, b) => {
    (typeCast(CategoryYAxis.$, a)).g0("MinorInterval", b.oldValue, b.newValue);
    (typeCast(CategoryYAxis.$, a)).g6(false);
}));
/**
 * @hidden
 */
export class CategoryYAxisView extends CategoryAxisBaseView {
    constructor(a) {
        super(a);
        this.bg = null;
        this.bg = a;
    }
}
CategoryYAxisView.$t = markType(CategoryYAxisView, 'CategoryYAxisView', CategoryAxisBaseView.$);
//# sourceMappingURL=CategoryYAxis_combined.js.map