/*
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 { RadialBucketCalculator } from "./RadialBucketCalculator";
import { Type, markType, Point_$type, enumGetBox, typeCast } from "igniteui-angular-core/ES2015/type";
import { isNaN_, intDivide, isInfinity } from "igniteui-angular-core/ES2015/number";
import { RadialBase } from "./RadialBase";
import { CategoryLineRasterizer } from "./CategoryLineRasterizer";
import { DependencyProperty } from "igniteui-angular-core/ES2015/DependencyProperty";
import { TrendLineType_$type } from "igniteui-angular-core/ES2015/TrendLineType";
import { Brush } from "igniteui-angular-core/ES2015/Brush";
import { PenLineCap_$type } from "igniteui-angular-core/ES2015/PenLineCap";
import { DoubleCollection } from "igniteui-angular-core/ES2015/DoubleCollection";
import { RadialFrame } from "./RadialFrame";
import { ScalerParams } from "./ScalerParams";
import { Rect } from "igniteui-angular-core/ES2015/Rect";
import { AxisRange } from "./AxisRange";
import { NumericAxisBase } from "./NumericAxisBase";
import { IFastItemsSource_$type } from "igniteui-angular-core/ES2015/IFastItemsSource";
import { RadialBaseView } from "./RadialBaseView";
import { CollisionAvoider } from "./CollisionAvoider";
import { Clipper } from "igniteui-angular-core/ES2015/Clipper";
import { TrendResolutionParams } from "./TrendResolutionParams";
import { RadialTrendLineManager } from "./RadialTrendLineManager";
import { CategoryMarkerManager } from "./CategoryMarkerManager";
import { PropertyMetadata } from "igniteui-angular-core/ES2015/PropertyMetadata";
import { stringIsNullOrEmpty } from "igniteui-angular-core/ES2015/string";
/**
 * @hidden
 */
export class AnchoredRadialBucketCalculator extends RadialBucketCalculator {
    constructor(a) {
        super(a);
        this.f = null;
        this.f = a;
    }
    getBucket(a) {
        let b = this.f.cs.no;
        let c = Math.min(a * this.b, b.count - 1);
        let d = Math.min(c + this.b - 1, b.count - 1);
        let e = NaN;
        let f = NaN;
        for (let g = c; g <= d; ++g) {
            let h = b.item(g);
            if (!isNaN_(e)) {
                if (!isNaN_(h)) {
                    e = Math.min(e, h);
                    f = Math.max(f, h);
                }
            }
            else {
                e = h;
                f = h;
            }
        }
        if (!isNaN_(e)) {
            return [0.5 * (c + d), e, f];
        }
        return [0.5 * (c + d), NaN, NaN];
    }
}
AnchoredRadialBucketCalculator.$t = markType(AnchoredRadialBucketCalculator, 'AnchoredRadialBucketCalculator', RadialBucketCalculator.$);
/**
 * @hidden
 */
export class AnchoredRadialSeries extends RadialBase {
    constructor() {
        super();
        this.nj = null;
        this.nn = null;
        this.oh = { $type: Point_$type, x: 0, y: 0 };
        this.nl = null;
        this.nk = null;
        this.nl = new RadialFrame(3);
        this.nj = new CategoryLineRasterizer();
    }
    bf() {
        return new AnchoredRadialSeriesView(this);
    }
    hn() {
        super.hn();
        this.ms = null;
        this.mu = null;
    }
    im(a) {
        super.im(a);
        this.ni = a;
    }
    fb(a, b) {
        return this.fc(a, b, this.ms, null, this.no);
    }
    e9(a, b) {
        return this.fa(a, b, this.ms, null, this.no);
    }
    d6(a, b, c, d, e) {
        if (this.no == null) {
            return Number.POSITIVE_INFINITY;
        }
        return this.d7(a, b, this.ms, d, e, this.no.count, null);
    }
    ek(a, b, c) {
        let d = this.getEffectiveViewport1(this.bi);
        let e = this.nt(this.ms, this.bi.bs, this.bi.br, d);
        let f = new ScalerParams(0, this.bi.bs, this.bi.br, this.ms.b8, d);
        f.c = this.bs.m3;
        return this.em(this.no, a, this.ms, f, e, null, b, c);
    }
    ld(a, b, c) {
        if (this.mu == null || this.ms == null || this.bi == null || this.bi.bs.isEmpty || this.bi.br.isEmpty) {
            return { $type: Point_$type, x: NaN, y: NaN };
        }
        let d = this.getEffectiveViewport1(this.bi);
        let e = new ScalerParams(0, this.bi.bs, this.bi.br, this.mu.b8, d);
        e.c = this.getEffectiveViewport1(this.bi);
        let f = this.ek(a, b, c);
        f = this.mu.dt(f, e);
        let g = this.mv.c(a);
        if (!b && this.ms != null) {
            let h = this.fb(a, c);
            let i = this.e9(a, c);
            let j = this.nt(this.ms, this.bi.bs, this.bi.br, d);
            let k = new ScalerParams(0, this.bi.bs, this.bi.br, this.ms.b8, d);
            k.c = this.bs.m3;
            let l = this.d6(a, h, this.ms, k, j);
            let m = this.d6(a, i, this.ms, k, j);
            if (m <= l) {
                g = this.ms.dt(i, k) + j;
            }
            else {
                g = this.ms.dt(h, k) + j;
            }
        }
        let n = this.mv.d(g, f, this.bi.bs, this.bi.br);
        let o = this.mv.e(g, f, this.bi.bs, this.bi.br);
        return { $type: Point_$type, x: n, y: o };
    }
    get no() {
        return this.nn;
    }
    set no(a) {
        if (this.nn != a) {
            let b = this.nn;
            this.nn = a;
            this.raisePropertyChanged("ValueColumn", b, this.nn);
        }
    }
    get od() {
        return this.c(AnchoredRadialSeries.n4);
    }
    set od(a) {
        this.h(AnchoredRadialSeries.n4, a);
    }
    an(a) {
        if (a != null && a == this.ms && this.no != null && this.no.count > 0) {
            return new AxisRange(0, this.no.count - 1);
        }
        if (a != null && a == this.mu && this.no != null && this.no.count > 0) {
            return new AxisRange(this.no.minimum, this.no.maximum);
        }
        return null;
    }
    is(a, b, c, d) {
        super.is(a, b, c, d);
        if (this.ni.ct.g$b(a, b, c, d)) {
            this.i5(false);
            this.ic();
        }
        let e = typeCast(NumericAxisBase.$, this.mu);
        switch (b) {
            case "FastItemsSource":
                if (typeCast(IFastItemsSource_$type, c) !== null) {
                    c.deregisterColumn(this.no);
                    this.no = null;
                }
                if (typeCast(IFastItemsSource_$type, d) !== null) {
                    this.no = this.bw(this.n0);
                    this.ni.co.e(this.er);
                }
                if (e != null && !e.ck()) {
                    this.ni.co.e(this.er);
                    this.i5(false);
                }
                break;
            case AnchoredRadialSeries.$$p[0]:
                if (this.bz != null) {
                    this.bz.deregisterColumn(this.no);
                    this.no = this.bw(this.n0);
                }
                break;
            case "ValueColumn":
                if (e != null && !e.ck()) {
                    this.ni.co.e(this.er);
                    this.i5(false);
                }
                break;
            case "TrendLineBrush":
                this.jg();
                break;
            case "TrendLineType":
                this.ic();
                break;
        }
    }
    hs(a, b, c, d) {
        switch (a) {
            case 4:
            case 1:
            case 0:
                this.ni.co.e(this.er);
                break;
        }
        this.ni.ct.g$e(a, b, c, d);
        switch (a) {
            case 4:
                if (this.mu != null && !this.mu.ck()) {
                    this.i5(true);
                }
                break;
            case 1:
                if (this.mu != null && !this.mu.ck()) {
                    this.i5(true);
                }
                break;
            case 0:
                if (this.mu != null && !this.mu.ck()) {
                    this.i5(true);
                }
                break;
            case 2:
                if (this.n0 != null && this.ni.co.b > 0 && this.mu != null && !this.mu.ck()) {
                    this.i5(true);
                }
                break;
            case 3:
                if (d == this.n0) {
                    if (this.mu != null && !this.mu.ck()) {
                        this.i5(true);
                    }
                }
                break;
        }
    }
    dv(a, b, c) {
        let d = super.dv(a, b, c);
        let e = c;
        if (this.bz == null || this.bz.count == 0 || this.ms == null || this.no == null || this.ms.jr == 0 || this.mu == null || isInfinity(this.mu.jx) || isInfinity(this.mu.jw) || e.co.b < 1) {
            d = false;
        }
        return d;
    }
    getOffsetValue() {
        return this.nt(this.ms, this.bi.bs, this.bi.br, this.getEffectiveViewport1(this.bi));
    }
    getCategoryWidth() {
        return this.ms.getCategorySize(this.bi.bs, this.bi.br, this.getEffectiveViewport1(this.bi));
    }
    get_nr() {
        return false;
    }
    get nr() {
        return this.get_nr();
    }
    nt(a, b, c, d) {
        let e = 0;
        let f = this.preferredCategoryMode(a);
        if (f == 0 && a.categoryMode != 0) {
            f = 1;
        }
        switch (f) {
            case 0:
                e = 0;
                break;
            case 1:
                e = 0.5 * a.getCategorySize(b, c, d);
                break;
            case 2:
                e = a.getGroupCenter(this.m7(), b, c, d);
                break;
        }
        if (a.b8) {
            e = -e;
        }
        return e;
    }
    nc(a, b) {
        let c = b.bs;
        let d = b.br;
        let e = this.getEffectiveViewport1(b);
        let f = this.ms;
        let g = this.mu;
        let h = g.jx;
        let i = g.jw;
        a.f.clear();
        a.m.clear();
        a.p.clear();
        let j = this.lv();
        let k = 0;
        let l = b;
        let m = new CollisionAvoider();
        let n = 0;
        let o = b.co.d;
        n = this.nt(f, c, d, e);
        l.ct.q = this.mu.lc;
        l.ct.p = this.mu.lb;
        l.ct.r = (p, q) => this.nu(p, q, c, d);
        l.ct.s = (p, q) => this.nv(p, q, c, d);
        let p = ((() => {
            let $ret = new Clipper(0, d, false);
            $ret.i = a.p;
            return $ret;
        })());
        let q = ((() => {
            let $ret = new TrendResolutionParams();
            $ret.c = b.co.b;
            $ret.d = b.co.c;
            $ret.e = o;
            $ret.a = n;
            $ret.b = this.er;
            $ret.f = d;
            $ret.g = c;
            return $ret;
        })());
        l.ct.t(a.p, this.nm, this.no, this.nx, (r) => this.ms.getScaledAngle(r), (r) => this.mu.li(r), q, p);
        let r = true;
        if (this.ns(b)) {
            o--;
        }
        for (let s = b.co.c; s <= o; ++s) {
            let t = s;
            if (t * b.co.b >= this.ms.jr) {
                t -= intDivide((this.ms.jr), b.co.b);
            }
            let u = b.co.getBucket(t);
            if (!isNaN_(u[0])) {
                u[0] = f.getScaledAngle(u[0]) + n;
                if (u[1] < h || u[1] > i) {
                    continue;
                }
                u[1] = g.li(u[1]);
                if (b.co.b > 1) {
                    if (u[2] < h || u[2] > i) {
                        continue;
                    }
                    u[2] = g.li(u[2]);
                }
                else {
                    u[2] = u[1];
                }
                if ((isNaN_(u[1]) || isNaN_(u[2])) && r && this.nr && this.nq()) {
                    o++;
                }
                else {
                    r = false;
                }
                a.f.add(u);
                if (j) {
                    let v = Math.min(t * b.co.b, this.bz.count - 1);
                    let w = this.mv.d(u[0], u[1], c, d);
                    let x = this.mv.e(u[0], u[1], c, d);
                    let y = new Rect(0, w - 5, x - 5, 11, 11);
                    if (!isNaN_(w) && !isNaN_(x) && !isInfinity(w) && !isInfinity(x) && m.tryAdd(y)) {
                        a.m.add({ $type: Point_$type, x: w, y: x });
                        let z = b.cp.item(k);
                        z.ak = v;
                        z.content.item = this.bz.item(v);
                        ++k;
                    }
                }
            }
            else {
                if (r && this.nr && this.nq()) {
                    o++;
                }
            }
        }
        b.cp.count = k;
        return;
    }
    nu(a, b, c, d) {
        return this.mv.d(a, b, c, d);
    }
    nv(a, b, c, d) {
        return this.mv.e(a, b, c, d);
    }
    ns(a) {
        let b = a;
        return !this.nr && b.co.c == 0 && b.co.d == this.ms.jr;
    }
    nh(a, b, c) {
        let d = null;
        let e = c.bs;
        let f = c.br;
        if (b > -1 && !e.isEmpty && !f.isEmpty) {
            let g = a._inner[0][0] < f.left - 2000 ? f.left - 10 : NaN;
            let h = f.bottom + 10;
            let i = a._inner[b][0] > f.right + 2000 ? f.right + 10 : NaN;
            let j = f.top - 10;
            d = new Clipper(1, g, h, i, j, false);
        }
        return d;
    }
    n3(a, b, c, d, e) {
        if (a.count > 0 && d.count > 0) {
            if (!e || this.np()) {
                a.add(this.oh);
                a.add(a._inner[0]);
                d.add(this.oh);
                d.add(d._inner[0]);
            }
        }
    }
    nq() {
        return !this.np();
    }
    np() {
        let a = this.bi.bs;
        return !a.containsPoint({ $type: Point_$type, x: 0.5, y: 0.5 });
    }
    hp(a, b) {
        super.hp(a, b);
        let c = b;
        if (a) {
            c.cp.clear();
        }
        c.ct.g$d();
    }
    nd(a, b) {
        let c = b.bs;
        let d = b.br;
        let e = this.getEffectiveViewport1(b);
        let f = this.li(b);
        let g = b;
        g.ct.g$g(a.p);
        CategoryMarkerManager.b(this, a.m, g.cp, this.lx);
        g.cj();
        this.n2(d, c, e, f, g);
    }
    n2(a, b, c, d, e) {
        e.cu(a, b, c, d);
    }
    jg() {
        super.jg();
        if (this.fe < 0) {
            return;
        }
        this.ni.cv();
    }
    fq(a, b) {
        if (a == this.ni.ct.g$j) {
            return null;
        }
        return super.fq(a, b);
    }
    c8(a) {
        let b = this.bi.bs;
        b = b.copy();
        let c = this.bi.br;
        let d = !b.isEmpty && !c.isEmpty && this.bz != null ? this.bz.indexOf(a) : -1;
        if (this.ms == null || this.no == null || this.mu == null) {
            return false;
        }
        if (d < 0 || d > this.no.count - 1) {
            return false;
        }
        let e = this.ms.getScaledAngle(d);
        let f = this.mu.li(this.no.item(d));
        if (isNaN_(f)) {
            f = (this.mu.lb + this.mu.lc) / 2;
        }
        let g = 0.5 + (Math.cos(e) * f);
        let h = 0.5 + (Math.sin(e) * f);
        if (!isNaN_(g)) {
            if (g < b.left + 0.1 * b.width) {
                g = g + 0.4 * b.width;
                b.x = g - 0.5 * b.width;
            }
            if (g > b.right - 0.1 * b.width) {
                g = g - 0.4 * b.width;
                b.x = g - 0.5 * b.width;
            }
        }
        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;
            }
        }
        if (this.bn != null) {
            this.bn.ap(this.bs, b, true);
        }
        return d >= 0;
    }
    i7(a, b) {
        super.i7(a, b);
        if (!this.dk) {
            this.bi.az(b);
            return;
        }
        this.bi.az(b);
        let c = typeCast(AnchoredRadialSeriesView.$, this.bh);
        c.co.e(this.er);
        if (this.cc(this.bh)) {
            return;
        }
        if (!this.de) {
            this.nl = new RadialFrame(3);
            this.nc(this.nl, c);
        }
        this.de = false;
        this.nd(this.nl, c);
        this.dk = false;
    }
    i4(a, b, c, d, e) {
        super.i4(a, b, c, d, e);
        let f = this.a0.a$h.item(d);
        let g = f;
        g.co.e(this.er);
        f.ay(c);
        if (this.cc(g)) {
            return;
        }
        if (this.nk == null) {
            this.nk = new RadialFrame(3);
        }
        this.nk.u();
        this.nc(this.nk, g);
        this.nd(this.nk, g);
    }
    hy(a) {
        super.hy(a);
        this.a2.exportTrendlineData(this, a, this.ni.ct.g$j);
    }
}
AnchoredRadialSeries.$t = markType(AnchoredRadialSeries, 'AnchoredRadialSeries', RadialBase.$);
AnchoredRadialSeries.n4 = DependencyProperty.i("ActualTrendLineBrush", Brush.$, AnchoredRadialSeries.$, new PropertyMetadata(2, null, (a, b) => a.raisePropertyChanged("ActualTrendLineBrush", b.oldValue, b.newValue)));
Type.dep(DependencyProperty, PropertyMetadata, AnchoredRadialSeries, 'raisePropertyChanged', ['ValueMemberPath:n0:oc', [2, null], 'TrendLineType:nm:oa', [TrendLineType_$type, enumGetBox(TrendLineType_$type, 0)], 'TrendLineThickness:nw:n9', [1, 1.5], 'TrendLinePeriod:nx:n8', [1, 7], 'TrendLineZIndex:ny:ob', [1, 1], 'TrendLineBrush:oe:n5', [Brush.$, null], 'TrendLineDashArray:of:n6', [DoubleCollection.$], 'TrendLineDashCap:og:n7', [PenLineCap_$type, enumGetBox(PenLineCap_$type, 0)]]);
/**
 * @hidden
 */
export class AnchoredRadialSeriesView extends RadialBaseView {
    constructor(a) {
        super(a);
        this.cs = null;
        this.ct = null;
        this.co = new AnchoredRadialBucketCalculator(this);
        this.cs = a;
        this.ct = new RadialTrendLineManager();
    }
    cu(a, b, c, d) {
    }
    cv() {
        this.cs.od = null;
        if (this.cs.oe != null) {
            this.cs.od = this.cs.oe;
        }
        else {
            this.cs.od = this.cs.kv;
        }
    }
    a2(a, b) {
        if (a.d) {
            if (!b) {
            }
            if (this.cs.nm != 0 && !b) {
                let c = this.ct.g$j;
                c.ac = this.cs.nw;
                c._stroke = this.cs.od;
                c.ai = this.cs.of;
                c.ad = this.cs.og;
                a.u(c);
            }
        }
        super.a2(a, b);
    }
    getDefaultTooltipTemplate() {
        let a = "<div class='ui-chart-default-tooltip-content'>";
        if (this.cs.ms.e2 != null) {
            a += "<span>${item." + this.cs.ms.e2 + "}</span><br/>";
        }
        a += "<span";
        let b = this.e.a0.a$q(this.e);
        if (!stringIsNullOrEmpty(b)) {
            a += " style='color:" + b + "'";
        }
        a += ">" + this.cs.fs + ": </span><span class='ui-priority-primary'>" + "${item." + this.cs.n0 + "}</span></div>";
        return a;
    }
}
AnchoredRadialSeriesView.$t = markType(AnchoredRadialSeriesView, 'AnchoredRadialSeriesView', RadialBaseView.$);
//# sourceMappingURL=AnchoredRadialBucketCalculator_combined.js.map