/*
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 { List$1 } from "igniteui-angular-core";
import { Base, Number_$type, typeCast, Array_$type, markType, TypeRegistrar } from "igniteui-angular-core";
import { HorizontalAxisLabelPanel } from "./HorizontalAxisLabelPanel";
import { Rect } from "igniteui-angular-core";
import { MathUtil } from "igniteui-angular-core";
import { ScalerParams } from "./ScalerParams";
import { NumericScaler } from "./NumericScaler";
import { LinearCategorySnapper } from "./LinearCategorySnapper";
import { NumericYAxis } from "./NumericYAxis";
import { LabelPosition } from "./LabelPosition";
import { AxisRangeChangedEventArgs } from "./AxisRangeChangedEventArgs";
import { PropertyMetadata } from "igniteui-angular-core";
import { truncate, isNaN_, isInfinity } from "igniteui-angular-core";
import { CategoryAxisBaseView } from "./CategoryAxisBaseView";
/**
 * @hidden
 */
export class CategoryXAxis extends CategoryAxisBase {
    constructor() {
        super();
        this.k9 = 1;
        this.k8 = 1;
        this.kz = 0;
        this.k0 = 0;
        this.jm = new List$1(Number_$type, 0);
        this.ab = CategoryXAxis.$;
    }
    a1() {
        return new CategoryXAxisView(this);
    }
    gs(a) {
        super.gs(a);
        this.kx = a;
    }
    get lb() {
        return this.k9;
    }
    set lb(a) {
        this.k9 = a;
    }
    get la() {
        return this.k8;
    }
    set la(a) {
        this.k8 = a;
    }
    as() {
        if (this.cp) {
            return (TypeRegistrar.create('HorizontalSmartAxisLabelPanel'));
        }
        else {
            return new HorizontalAxisLabelPanel();
        }
    }
    getCategorySize(a, b, c) {
        let d = this.iz(b, c);
        return d.width / (this.jy * a.width);
    }
    jr(a, b, c) {
        let d = !isNaN_(this.jo) ? MathUtil.b(this.jo, 0, 1) : 0;
        let e = 0;
        if (!isNaN_(this.jv)) {
            e = Math.min(this.jv, 1);
        }
        else {
            e = 0;
        }
        ;
        let f = 1 - 0.5 * d;
        let g = this.j1 == 0 ? 1 : this.j1;
        let h = this.getCategorySize(a, b, c) * f / (g - (g - 1) * e);
        return h;
    }
    getGroupCenter(a, b, c, d) {
        let e = 0.5;
        if (this.j1 > 1) {
            let f = !isNaN_(this.jo) ? MathUtil.b(this.jo, 0, 1) : 0;
            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;
    }
    dj() {
        return this.k6;
    }
    lg(a) {
        let b = this.bf != null ? this.bf.mq : Rect.empty;
        b = b.copy();
        let c = this.i1;
        let d = this.iy();
        let e = new Rect(0, 0, 0, 1, 1);
        let f = new ScalerParams(0, e, e, this.b8, d);
        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.left + 0.1 * b.width) {
                    h = h + 0.4 * b.width;
                    b.x = h - 0.5 * b.width;
                }
                if (h > b.right - 0.1 * b.width) {
                    h = h - 0.4 * b.width;
                    b.x = h - 0.5 * b.width;
                }
            }
            this.bf.km(b, false, true);
        }
    }
    dw(a, b) {
        if (!b.c.isEmpty) {
            let c = this.k5(a, NumericScaler.ac, b.c, this.categoryMode);
            c = (c - b.d.left) / b.d.width;
            c = b.d.left + b.d.width * (c - b.e.left) / b.e.width;
            return c;
        }
        return this.k5(a, b.e, b.d, this.categoryMode);
    }
    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.left;
        let n = i.width;
        let o = g.left;
        let p = g.width;
        let q = h.left;
        let r = h.width;
        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;
                }
            }
        }
    }
    dx(a, b, c) {
        if (!b.c.isEmpty) {
            let d = this.k5(a, NumericScaler.ac, b.c, c);
            d = (d - b.d.left) / b.d.width;
            d = b.d.left + b.d.width * (d - b.e.left) / b.e.width;
            return d;
        }
        return this.k5(a, b.e, b.d, c);
    }
    k5(a, b, c, d) {
        let e = d == 0 ? this.jy - 1 : this.jy;
        if (e < 0) {
            e = 0;
        }
        let f = e >= 1 ? (a) / (e) : e == 0 ? 0.5 : NaN;
        if (this.b9) {
            f = 1 - f;
        }
        return c.left + c.width * (f - b.left) / b.width;
    }
    dz(a, b) {
        if (!b.c.isEmpty) {
            let c = b.e.left + b.e.width * (a - b.d.left) / b.d.width;
            c = (c * b.d.width) + b.d.left;
            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.left + b.e.width * (a - b.d.left) / b.d.width;
            d = (d * b.d.width) + b.d.left;
            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.left + (a - c.left) * b.width / c.width;
        if (this.b9) {
            e = 1 - e;
        }
        let f = d == 0 ? this.jy - 1 : this.jy;
        if (f < 0) {
            f = 0;
        }
        return e * f;
    }
    lh(a, b) {
        if (a == NaN || b == NaN || this.jf == null || this.jf.count == 0) {
            return;
        }
        let c = a / this.jf.count;
        let d = (b + 1) / this.jf.count;
        this.bf.m4 = new Rect(0, c, this.bf.m4.y, d - c, this.bf.m4.height);
    }
    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();
        let n = this.jf;
        let o = this.ky();
        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 || o == null || n.count == 0) {
            this.bo.count = 0;
            this.bn.count = 0;
            this.bm.count = 0;
            this.a2.y();
            return;
        }
        if (!b.isEmpty && !c.isEmpty) {
            let p = this.dz(e.left, f);
            let q = this.dz(e.right, f);
            if (this.b8) {
                p = Math.ceil(p);
                q = Math.floor(q);
            }
            else {
                p = Math.floor(p);
                q = Math.ceil(q);
            }
            let r = c.bottom;
            let s = r - c.top;
            if (this.ag != null) {
                let t = typeCast(NumericYAxis.$, this.ag);
                if (t != null) {
                    let u = this.ha(r, s, b, c, d, c.top, c.bottom);
                    r = u.p0;
                    s = u.p1;
                }
            }
            this.gq(g, r, c, k, true);
            this.a2.ao(s);
            let v = Math.min(p, q);
            let w = Math.max(p, q);
            let x = new LinearCategorySnapper(1, v, w, e.width, this.k6, this.categoryMode, this.d9());
            let y = Math.floor((v - 0) / x.g);
            let z = Math.ceil((w - 0) / x.g);
            this.k1 = x.g;
            if (!isNaN_(y) && !isNaN_(z)) {
                let aa = truncate(y);
                let ab = truncate(z);
                let ac = this.k4(0 + aa * x.g, f);
                let ad = this.dw(x.g, f);
                let ae = Math.abs(ad - this.dw(0, f));
                this.a2.ap(ad);
                let af = truncate(Math.ceil(e.right));
                let ag = truncate(Math.floor(e.left));
                let ah = this.k7;
                let ai = ah > 0 && ah < x.g;
                let aj = c.right;
                let ak = this.jm;
                let al = x.g;
                let am = truncate(al);
                let an = this.j1;
                let ao = this.b8;
                let ap = this.categoryMode;
                for (let aq = aa; aq <= ab; ++aq) {
                    let ar = this.k4(0 + (aq + 1) * x.g, f);
                    if (ac <= aj) {
                        if (aq % 2 == 0) {
                            this.hg(h, ac, ar, c);
                        }
                        this.hf(i, ac, c, l, false);
                        ak.add(ac);
                    }
                    if (this.categoryMode != 0 && this.j1 != 0 && this.cj) {
                        if (ai) {
                            let as = ae * this.k7;
                            if (this.b8) {
                                let at = ac;
                                while (at - as > ar) {
                                    at -= as;
                                    if (Math.abs(at - ar) < 0.0001) {
                                        break;
                                    }
                                    this.hf(j, at, c, m, false);
                                }
                            }
                            else {
                                let au = ac;
                                while (au + as < ar) {
                                    au += as;
                                    if (Math.abs(au - ar) < 0.0001) {
                                        break;
                                    }
                                    this.hf(j, au, c, m, false);
                                }
                            }
                            this.k2 = this.k7;
                        }
                        else {
                            for (let av = 0; av < truncate(x.g); av++) {
                                for (let aw = 0; aw < this.j1; aw++) {
                                    let ax = this.getGroupCenter(aw, b, c, d);
                                    if (this.b8) {
                                        ax = -ax;
                                    }
                                    let ay = this.dw(av + aq * x.g, f) + ax;
                                    this.hf(j, ay, c, m, false);
                                }
                            }
                            this.k2 = 0.5;
                        }
                    }
                    let az = this.k3(aq * al, ac, ap == 0, f);
                    let a0 = truncate(Math.round(az));
                    if (a0 >= ag && a0 <= af) {
                        let a1 = 0;
                        if (al >= 1) {
                            a1 = aq * truncate(Math.floor(al));
                        }
                        else {
                            if ((aq * al) * 2 % 2 == 0) {
                                a1 = truncate(Math.floor(aq * al));
                            }
                            else {
                                a1 = -1;
                            }
                        }
                        if (o != null && a1 < n.count && a1 >= 0) {
                            let a2 = o.getItem(a1);
                            let a3 = this.e6(a2);
                            if (!isNaN_(az) && !isInfinity(az) && a3 != null) {
                                if ((typeof a3 === 'string') && Base.equalsStatic(a3, "")) {
                                }
                                else {
                                    this.cv.add1(a3);
                                    this.cw.add(new LabelPosition(az));
                                }
                            }
                        }
                    }
                    ac = ar;
                }
            }
            if ((this.aw == null || this.aw.visibility == 0) && this.ag != null) {
                if (this.aw != null && (this.aw.location == 4 || this.aw.location == 5)) {
                    this.bf.ht();
                }
            }
            this.a2.au(this.cv, this.cw);
            this.km();
        }
    }
    cn() {
        if (this.cg && this.co) {
            this.a9 = this.a8();
        }
        if (this.jf == null) {
            return false;
        }
        let a = this.jf.count;
        if (a != this.la) {
            let b = new AxisRangeChangedEventArgs(0, 1, 1, this.la, a);
            this.la = a;
            this.g1(b);
            return true;
        }
        return false;
    }
    get k6() {
        return this.c(CategoryXAxis.li);
    }
    set k6(a) {
        this.h(CategoryXAxis.li, a);
    }
    get k1() {
        return this.kz;
    }
    set k1(a) {
        if (this.k1 != a) {
            let b = this.kz;
            this.kz = a;
            this.g0("ActualInterval", b, this.k1);
        }
    }
    d7() {
        return this.k1;
    }
    get k7() {
        return this.c(CategoryXAxis.lj);
    }
    set k7(a) {
        this.h(CategoryXAxis.lj, a);
    }
    get k2() {
        return this.k0;
    }
    set k2(a) {
        if (this.k2 != a) {
            let b = this.k0;
            this.k0 = a;
            this.g0("ActualMinorInterval", b, this.k2);
        }
    }
    ji(a) {
        if (a == null) {
            return false;
        }
        let b = this.bb();
        if (b == null) {
            return false;
        }
        return b.synchronizeHorizontally;
    }
    get_az() {
        return 0;
    }
    get az() {
        return this.get_az();
    }
    ky() {
        return this.jf;
    }
    k4(a, b) {
        return this.dw(a, b);
    }
    k3(a, b, c, d) {
        if (!c) {
            let e = this.k4(a + 1, d);
            return (b + e) / 2;
        }
        return b;
    }
    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;
    }
}
CategoryXAxis.$t = markType(CategoryXAxis, 'CategoryXAxis', CategoryAxisBase.$);
CategoryXAxis.li = DependencyProperty.i("Interval", Number_$type, CategoryXAxis.$, new PropertyMetadata(2, NaN, (a, b) => {
    a.g0("Interval", b.oldValue, b.newValue);
    a.g6(false);
}));
CategoryXAxis.lj = DependencyProperty.i("MinorInterval", Number_$type, CategoryXAxis.$, new PropertyMetadata(2, NaN, (a, b) => {
    (typeCast(CategoryXAxis.$, a)).g0("MinorInterval", b.oldValue, b.newValue);
    (typeCast(CategoryXAxis.$, a)).g6(false);
}));
/**
 * @hidden
 */
export class CategoryXAxisView extends CategoryAxisBaseView {
    constructor(a) {
        super(a);
        this.bg = null;
        this.bg = a;
    }
}
CategoryXAxisView.$t = markType(CategoryXAxisView, 'CategoryXAxisView', CategoryAxisBaseView.$);
//# sourceMappingURL=CategoryXAxis_combined.js.map