/*
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 { VerticalAnchoredCategorySeries } from "./VerticalAnchoredCategorySeries";
import { IIsCategoryBased_$type } from "./IIsCategoryBased";
import { IBarSeries_$type } from "./IBarSeries";
import { DependencyProperty } from "igniteui-angular-core";
import { Rect } from "igniteui-angular-core";
import { typeCast, fromEnum, runOn, markType, markDep } from "igniteui-angular-core";
import { ScalerParams } from "./ScalerParams";
import { List$1 } from "igniteui-angular-core";
import { CategorySeriesView } from "./CategorySeriesView";
import { BarFramePreparer } from "./BarFramePreparer";
import { Pool$1 } from "igniteui-angular-core";
import { Rectangle } from "igniteui-angular-core";
import { AxisRange } from "./AxisRange";
import { CategoryBucketCalculator } from "./CategoryBucketCalculator";
import { AnchoredCategorySeriesView } from "./AnchoredCategorySeriesView";
import { CategoryTrendLineManagerFactory } from "./CategoryTrendLineManagerFactory";
import { PropertyMetadata } from "igniteui-angular-core";
import { truncate, isNaN_, isInfinity } from "igniteui-angular-core";
import { ISupportsMarkers_$type } from "./ISupportsMarkers";
import { BarTrendLineManager } from "./BarTrendLineManager";
import { Color } from "igniteui-angular-core";
/**
 * @hidden
 */
export class BarSeries extends VerticalAnchoredCategorySeries {
    constructor() {
        super();
        this.ab = BarSeries.$;
        this.nb = new BarFramePreparer(1, this, this.p9, this, this, this.p9.cn);
    }
    bf() {
        return new BarSeriesView(this);
    }
    ng() {
        return 1;
    }
    getHostReferenceValue() {
        return this.eh();
    }
    iu(a) {
        super.iu(a);
        this.p9 = a;
    }
    get_nv() {
        return true;
    }
    lu(a) {
        if (this.xAxis == null || this.yAxis == null || this.m7.f.count == 0) {
            return Rect.empty;
        }
        let b = this.bi.bs;
        let c = this.bi.br;
        let d = this.getEffectiveViewport1(this.bi);
        let e = new ScalerParams(0, b, c, this.xAxis.b8, d);
        let f = this.lg(a);
        let g = this.fe(a, true);
        let h = this.fc(a, true);
        let i = truncate(Math.floor(g / this.n7(this.bi)));
        let j = truncate(Math.floor(h / this.n7(this.bi)));
        let k = i - this.n8(this.bi);
        let l = j - this.n8(this.bi);
        if (k < 0) {
            k = 0;
        }
        if (k > this.m7.f.count - 1) {
            k = this.m7.f.count - 1;
        }
        if (l < 0) {
            l = 0;
        }
        if (l > this.m7.f.count - 1) {
            l = this.m7.f.count - 1;
        }
        let m = this.m7.f._inner[k];
        let n = this.m7.f._inner[l];
        let o = Math.abs(f.y - m[0]);
        let p = Math.abs(f.y - n[0]);
        let q = this.o7(this.nf);
        let r = this.yAxis.jr(b, c, d);
        if (o < p) {
            let s = m[0] - 0.5 * r;
            let t = m[1];
            let u = q;
            return new Rect(0, Math.min(u, t), s, Math.max(u, t) - Math.min(u, t), r);
        }
        else {
            let v = n[0] - 0.5 * r;
            let w = n[1];
            let x = q;
            return new Rect(0, Math.min(x, w), v, Math.max(x, w) - Math.min(x, w), r);
        }
    }
    dh(a, b) {
        if (this.dk(a, b)) {
            return true;
        }
        if (this.l4(a, b)) {
            return true;
        }
        return false;
    }
    nc(a) {
        let b = typeCast(CategorySeriesView.$, a);
        if (b != null && b.n) {
            if (b.m) {
                return new BarFramePreparer(1, this, typeCast(ISupportsMarkers_$type, b), b, this, b.cn);
            }
            else {
                return new BarFramePreparer(1, this, typeCast(ISupportsMarkers_$type, b), this.bs.bn.m, this, b.cn);
            }
        }
        else {
            return this.nb;
        }
    }
    ac() {
        super.ac();
    }
    preferredCategoryMode(a) {
        return 2;
    }
    hv(a, b) {
        super.hv(a, b);
        let c = typeCast(BarSeriesView.$, b);
        if (a && c != null && c.c7 != null) {
            c.c7.count = 0;
        }
    }
    n9() {
        let a = 0;
        for (let b of fromEnum(this.bs.series)) {
            if (b == this) {
                return a;
            }
            let c = typeCast(IBarSeries_$type, b);
            if (c != null && c.yAxis == this.yAxis && c.getPreferredCategoryMode() == 2) {
                a++;
            }
        }
        return -1;
    }
    o7(a) {
        let b = 0;
        let c = a.bs;
        let d = a.br;
        let e = this.getEffectiveViewport1(a);
        if (!c.isEmpty && !d.isEmpty && this.xAxis != null) {
            let f = new ScalerParams(0, c, d, this.xAxis.b8, e);
            b = this.xAxis.dw(this.xAxis.ke, f);
        }
        return b;
    }
    an(a) {
        if (this.valueColumn == null || this.valueColumn.count == 0) {
            return null;
        }
        if (a == this.yAxis) {
            return new AxisRange(0, this.valueColumn.count - 1);
        }
        if (a == this.xAxis) {
            return new AxisRange(this.valueColumn.minimum, this.valueColumn.maximum);
        }
        return null;
    }
    c9(a) {
        let b = this.bi.bs;
        b = b.copy();
        let c = this.bi.br;
        let d = new Rect(0, 0, 0, 1, 1);
        let e = !b.isEmpty && !c.isEmpty && this.bz != null ? this.bz.indexOf(a) : -1;
        let f = this.ls(this.bi);
        let g = new ScalerParams(0, d, d, this.xAxis.b8, f);
        let h = new ScalerParams(0, d, d, this.yAxis.b8, f);
        let i = this.yAxis != null ? this.yAxis.dw(e, h) : NaN;
        let j = this.yAxis != null ? this.nb.r(this.yAxis, d, d, f) : 0;
        i += j;
        let k = this.xAxis != null && this.valueColumn != null && e < this.valueColumn.count ? this.xAxis.dw(this.valueColumn.item(e), g) : NaN;
        if (!isNaN_(k)) {
            if (k < b.left + 0.1 * b.width) {
                k = k + 0.4 * b.width;
                b.x = k - 0.5 * b.width;
            }
            if (k > b.right - 0.1 * b.width) {
                k = k - 0.4 * b.width;
                b.x = k - 0.5 * b.width;
            }
        }
        if (!isNaN_(i)) {
            if (i < b.top + 0.1 * b.height) {
                i = i + 0.4 * b.height;
                b.y = i - 0.5 * b.height;
            }
            if (i > b.bottom - 0.1 * b.height) {
                i = i - 0.4 * b.height;
                b.y = i - 0.5 * b.height;
            }
        }
        if (this.bn != null) {
            this.bn.ap(this.bs, b, true);
        }
        return e >= 0;
    }
    eg() {
        return this.yAxis.jr(this.bi.bs, this.bi.br, this.getEffectiveViewport1(this.bi));
    }
    oo(a, b) {
        super.oo(a, b);
        let c = a.f;
        if (!b.l()) {
            return;
        }
        let d = b.bs;
        let e = b.br;
        let f = this.getEffectiveViewport1(b);
        let g = new ScalerParams(0, d, e, this.xAxis.b8, f);
        let h = this.yAxis;
        let i = new ScalerParams(0, d, e, this.yAxis.b8, f);
        let j = this.xAxis;
        let k = j.dw(j.ke, g);
        let l = this.yAxis.jr(d, e, f);
        let m = typeCast(BarSeriesView.$, b);
        if (isNaN_(l) || isInfinity(l) || isNaN_(k)) {
            m.c7.count = 0;
            return;
        }
        this.ne.x(this, this.nz(), this.yAxis, runOn(this, this.m0), this.n7(b), this.n8(b));
        this.ne.p = this.qa;
        this.ne.q = this.qb;
        this.ne.j = this.qa;
        this.ne.k = this.qb;
        let n = false;
        let o = this.ne.c;
        if (o != null) {
            n = true;
        }
        let p = this.xAxis.cd;
        let q = this.valueColumn.count;
        for (let r = 0; r < c.count; ++r) {
            let s = c._inner[r][0] - 0.5 * l;
            let t = c._inner[r][1];
            let u = k;
            u = Math.max(u, -100);
            t = Math.min(t, e.right + 100);
            let v = m.c7.item(r);
            v.height = l;
            v.width = Math.abs(t - u);
            if (n) {
                this.ok(c, r, q, h, i, b.n);
            }
            this.ne.ae(v, false, false, false, false);
            v.am = this.ne.j;
            v.an = this.ne.k;
            m.dc(v, Math.min(t, u), s);
        }
        m.c7.count = c.count;
        b.cu(a);
    }
    hy(a, b, c, d) {
        switch (a) {
            case 4:
            case 1:
            case 0:
                this.oy.cn.g(this.eu);
                break;
        }
        if (this.oy.cz) {
            this.oy.cy.g$e(a, b, c, d);
        }
        switch (a) {
            case 4:
                if (this.xAxis != null && !this.xAxis.cl()) {
                    this.jd(true);
                }
                break;
            case 1:
                if (this.xAxis != null && !this.xAxis.cl()) {
                    this.jd(true);
                }
                break;
            case 0:
                if (this.xAxis != null && !this.xAxis.cl()) {
                    this.jd(true);
                }
                break;
            case 2:
                if (this.pd != null && this.oy.cn.d > 0) {
                    this.jd(true);
                }
                break;
            case 3:
                if (d == this.pd) {
                    if (this.xAxis != null && !this.xAxis.cl()) {
                        this.jd(true);
                    }
                }
                break;
        }
    }
    iz(a, b, c, d) {
        super.iz(a, b, c, d);
        switch (b) {
            case VerticalAnchoredCategorySeries.$$p[0]:
                if (c != null) {
                    c.bv(this);
                }
                if (d != null) {
                    d.ci(this);
                }
                this.oy.cn.g(this.eu);
                if (this.xAxis != null && this.xAxis.cl()) {
                    this.jd(false);
                }
                break;
            case VerticalAnchoredCategorySeries.$$p[1]:
                if (c != null) {
                    c.bv(this);
                }
                if (d != null) {
                    d.ci(this);
                }
                if (this.oy.cz) {
                    this.oy.cy = CategoryTrendLineManagerFactory.a(this.oy.cy, this.yAxis, this.jx, this, this.b2);
                }
                this.oy.cn.g(this.eu);
                this.jd(false);
                break;
            case "FastItemsSource":
                if (this.xAxis != null && !this.xAxis.cl()) {
                    this.oy.cn.g(this.eu);
                    this.jd(false);
                }
                break;
            case "ValueColumn":
                if (this.xAxis != null && !this.xAxis.cl()) {
                    this.oy.cn.g(this.eu);
                    this.jd(false);
                }
                break;
            case "SeriesViewer":
                if (c != null && d == null) {
                    this.hz(this.xAxis);
                    this.hz(this.yAxis);
                }
                if (c == null && d != null) {
                    this.i4(this.xAxis);
                    this.i4(this.yAxis);
                }
                this.oy.cn.g(this.eu);
                this.jd(false);
                break;
        }
    }
    getPreferredCategoryMode() {
        return this.preferredCategoryMode(this.yAxis);
    }
    get currentCategoryMode() {
        return this.preferredCategoryMode(this.yAxis);
    }
    get scaler() {
        return this.yAxis;
    }
    get yScaler() {
        return this.xAxis;
    }
    get useHighMarkerFidelity() {
        return this.n2;
    }
}
BarSeries.$t = markType(BarSeries, 'BarSeries', VerticalAnchoredCategorySeries.$, [IIsCategoryBased_$type, IBarSeries_$type]);
BarSeries.$$p = markDep(DependencyProperty, PropertyMetadata, BarSeries, 'raisePropertyChanged', ['RadiusX:qa:qe', [1, 2], 'RadiusY:qb:qf', [1, 2]]);
/**
 * @hidden
 */
export class BarBucketCalculator extends CategoryBucketCalculator {
    constructor(a) {
        super(a);
        this.i = null;
        this.h = null;
        this.j = 0;
        this.i = a;
    }
    g(a) {
        let b = this.c.bs;
        let c = this.c.br;
        let d = this.c.cp.bz;
        if (b.isEmpty || c.isEmpty || this.i.c6.yAxis == null || d == null || d.count == 0) {
            this.d = 0;
            return;
        }
        let e = typeCast(BarSeries.$, this.c.cp);
        let f = e.lq(this.c);
        let g = e.getEffectiveViewport1(this.c);
        let h = new ScalerParams(0, b, c, e.yAxis.b8, g);
        let i = Math.floor(e.yAxis.d0(f.top, h, 0));
        let j = Math.ceil(e.yAxis.d0(f.bottom, h, 0));
        if (!e.yAxis.b8) {
            j = Math.ceil(e.yAxis.d0(f.top, h, 0));
            i = Math.floor(e.yAxis.d0(f.bottom, h, 0));
        }
        let k = Math.floor((j - i + 1) * a / f.height);
        this.d = truncate(Math.max(1, k));
        this.e = truncate(Math.max(0, Math.floor(i / this.d) - 1));
        this.f = truncate(Math.ceil(j / this.d));
    }
    getBucketWithoutUnknowns(a) {
        let b = this.h;
        let c = this.j;
        let d = a * this.d;
        let e = d + this.d - 1;
        let f = c - 1;
        d = d < f ? d : f;
        e = e < f ? e : f;
        let g = 1.7976931348623157E+308;
        let h = -1.7976931348623157E+308;
        let i = true;
        for (let j = d; j <= e; ++j) {
            let k = b[j];
            g = g < k ? g : k;
            h = h > k ? h : k;
            Math.max(h, k);
            i = false;
        }
        if (!i) {
            return [0.5 * (d + e), g, h];
        }
        return [0.5 * (d + e), NaN, NaN];
    }
    getBucket(a) {
        let b = this.h;
        let c = this.j;
        let d = a * this.d;
        let e = d + this.d - 1;
        let f = c - 1;
        d = d < f ? d : f;
        e = e < f ? e : f;
        let g = NaN;
        let h = NaN;
        for (let i = d; i <= e; ++i) {
            let j = b[i];
            if (!isNaN_(g)) {
                if (!isNaN_(j)) {
                    g = Math.min(g, j);
                    h = Math.max(h, j);
                }
            }
            else {
                g = j;
                h = j;
            }
        }
        if (!isNaN_(g)) {
            return [0.5 * (d + e), g, h];
        }
        return [0.5 * (d + e), NaN, NaN];
    }
    cacheValues() {
        this.j = this.i.c6.valueColumn.count;
        this.h = this.i.c6.valueColumn.asArray();
    }
    unCacheValues() {
        this.h = null;
    }
}
BarBucketCalculator.$t = markType(BarBucketCalculator, 'BarBucketCalculator', CategoryBucketCalculator.$);
/**
 * @hidden
 */
export class BarSeriesView extends AnchoredCategorySeriesView {
    constructor(a) {
        super(a);
        this.c6 = null;
        this.c7 = null;
        this.c8 = null;
        this.dd = new Rectangle();
        this.c6 = a;
        this.c7 = ((() => {
            let $ret = new Pool$1(Rectangle.$);
            $ret.create = runOn(this, this.de);
            $ret.activate = runOn(this, this.c9);
            $ret.disactivate = runOn(this, this.db);
            $ret.destroy = runOn(this, this.da);
            return $ret;
        })());
        this.cy = new BarTrendLineManager();
    }
    ap() {
        super.ap();
        this.c8 = new List$1(Rectangle.$, 0);
        if (!this.n) {
            this.e.eu = 4;
            this.e.bj = 1;
        }
    }
    de() {
        let a = new Rectangle();
        this.c8.add(a);
        a._visibility = 1;
        return a;
    }
    c9(a) {
        a._visibility = 0;
    }
    db(a) {
        a._visibility = 1;
    }
    da(a) {
        this.c8.remove(a);
    }
    dc(a, b, c) {
        if (!this.isDirty) {
            this.an();
        }
        a.o = c;
        a.n = b;
    }
    co() {
        return new BarBucketCalculator(this);
    }
    bc(a, b) {
        super.bc(a, b);
        let c = a;
        let d = this.bm(b);
        c._fill = d;
        c._stroke = d;
        c.ac = this.e.ey;
    }
    z(a) {
        return this.c8._inner[a];
    }
    y(a) {
        let b = this.c8._inner[a];
        this.dd.n = b.n;
        this.dd.o = b.o;
        this.dd.width = b.width;
        this.dd.height = b.height;
        let c = this.bm(a);
        this.dd._fill = c;
        this.dd._stroke = c;
        this.dd.ac = this.e.ey + 3;
        return this.dd;
    }
    a3(a, b) {
        super.a3(a, b);
        if (a.d) {
            for (let c = 0; c < this.c8.count; c++) {
                let d = this.x(c, b);
                this.ba(d, c, b);
                a.v(d);
            }
        }
    }
    ai(a) {
        super.ai(a);
        let b = 0;
        let c = new List$1(Rectangle.$, 0);
        for (let d of fromEnum(this.c7.a)) {
            c.add(d);
        }
        c.aa((e, f) => {
            if (e.o > f.o) {
                return -1;
            }
            else if (e.o < f.o) {
                return 1;
            }
            else {
                return 0;
            }
        });
        for (let e of fromEnum(c)) {
            this.e.a2.exportRectangleData(a, e, "column" + b, ["Main", "Fill"]);
        }
        b++;
    }
    ac() {
        let a = new Color();
        a.colorString = "rgba(95,95,95,0.5)";
        this.e.la = a;
        this.e.ev = 5;
        this.e.ew = 5;
        this.e.ex = -5;
    }
}
BarSeriesView.$t = markType(BarSeriesView, 'BarSeriesView', AnchoredCategorySeriesView.$);
//# sourceMappingURL=BarSeries_combined.js.map