/*
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 { Base, typeCast, markType, Array_$type, Number_$type, Point_$type, enumGetBox, runOn, fromEnum, markDep } from "igniteui-angular-core";
import { IBucketizer_$type } from "./IBucketizer";
import { ArgumentNullException } from "igniteui-angular-core";
import { Rect } from "igniteui-angular-core";
import { CategoryAxisBase } from "./CategoryAxisBase";
import { ISortingAxis_$type } from "./ISortingAxis";
import { ScalerParams } from "./ScalerParams";
import { Series } from "./Series";
import { truncate, intDivide, isNaN_, isInfinity } from "igniteui-angular-core";
import { FramePreparer } from "./FramePreparer";
import { IIsCategoryBased_$type } from "./IIsCategoryBased";
import { List$1 } from "igniteui-angular-core";
import { ISupportsMarkers_$type } from "./ISupportsMarkers";
import { IProvidesViewport_$type } from "./IProvidesViewport";
import { ISupportsErrorBars_$type } from "./ISupportsErrorBars";
import { CategoryFrame } from "./CategoryFrame";
import { PreparationParams } from "./PreparationParams";
import { IDateTimeAxis_$type } from "./IDateTimeAxis";
import { NumericAxisBase } from "./NumericAxisBase";
import { IHasCategoryTrendline_$type } from "./IHasCategoryTrendline";
import { IHasSingleValueCategory_$type } from "./IHasSingleValueCategory";
import { DefaultCategoryTrendlineHost } from "./DefaultCategoryTrendlineHost";
import { DefaultSingleValueProvider } from "./DefaultSingleValueProvider";
import { SingleValuesHolder } from "./SingleValuesHolder";
import { MarkerSeries } from "./MarkerSeries";
import { IHasCategoryModePreference_$type } from "./IHasCategoryModePreference";
import { ICategorySeriesInteractionManager_$type } from "./ICategorySeriesInteractionManager";
import { DVContainer } from "igniteui-angular-core";
import { DependencyProperty } from "igniteui-angular-core";
import { CategoryTransitionInMode_$type } from "./CategoryTransitionInMode";
import { HighlightingInfo } from "./HighlightingInfo";
import { CategoryTransitionSourceFramePreparer } from "./CategoryTransitionSourceFramePreparer";
import { SeriesPointOfInterest } from "./SeriesPointOfInterest";
import { Marker } from "./Marker";
import { MarkerSeriesView } from "./MarkerSeriesView";
import { CategorySeriesRenderManager } from "./CategorySeriesRenderManager";
import { Pool$1 } from "igniteui-angular-core";
import { Clipper } from "igniteui-angular-core";
import { PropertyMetadata } from "igniteui-angular-core";
import { round10N } from "igniteui-angular-core";
/**
 * @hidden
 */
export let CategoryBucketCalculator = /*@__PURE__*/ (() => {
    class CategoryBucketCalculator extends Base {
        constructor(a) {
            super();
            this.c = null;
            this.e = 0;
            this.f = 0;
            this.d = 0;
            if (a == null) {
                throw new ArgumentNullException(0, "view");
            }
            this.c = a;
            this.e = -1;
            this.d = 0;
        }
        getBucket(a) {
            return null;
        }
        getBucketWithoutUnknowns(a) {
            return this.getBucket(a);
        }
        getErrorBucket(a, b) {
            return NaN;
        }
        g(a) {
            let b = this.c.bv;
            let c = this.c.bu;
            let d = this.c.ct;
            let e = typeCast(CategoryAxisBase.$, d.fetchXAxis());
            let f = d.ck;
            if (b.isEmpty || c.isEmpty || e == null || f == null || f.count == 0) {
                this.d = 0;
                return;
            }
            let g = d.getEffectiveViewport1(this.c);
            let h = d.pq(this.c);
            let i = typeCast(ISortingAxis_$type, e);
            if (i == null || i.i$b == null) {
                let j = new ScalerParams(0, b, c, e.cg, g);
                let k = Math.floor(e.em(h.left, j, 0));
                let l = Math.ceil(e.em(h.right, j, 0));
                if (e.cg) {
                    l = Math.ceil(e.em(h.left, j, 0));
                    k = Math.floor(e.em(h.right, j, 0));
                }
                let m = Math.floor((l - k + 1) * a / h.width);
                this.d = truncate(Math.max(1, m));
                this.e = truncate(Math.max(0, Math.floor(k / this.d) - 1));
                this.f = truncate(Math.ceil(l / this.d));
            }
            else {
                this.e = i.i$e(b, c, g, h);
                this.f = i.i$g(b, c, g, h);
                this.d = 1;
            }
        }
        getBucketInfo(a, b, c, d) {
            a = this.e;
            b = this.f;
            c = this.d;
            d = this.c.ct.ft;
            return {
                p0: a,
                p1: b,
                p2: c,
                p3: d
            };
        }
        cacheValues() {
        }
        unCacheValues() {
        }
    }
    CategoryBucketCalculator.$t = markType(CategoryBucketCalculator, 'CategoryBucketCalculator', Base.$, [IBucketizer_$type]);
    return CategoryBucketCalculator;
})();
/**
 * @hidden
 */
export let CategoryFramePreparerBase = /*@__PURE__*/ (() => {
    class CategoryFramePreparerBase extends FramePreparer {
        constructor(a, ..._rest) {
            a = (a == void 0) ? 0 : a;
            switch (a) {
                case 0:
                    {
                        let c = _rest[0];
                        let d = [c, typeCast(ISupportsMarkers_$type, c), typeCast(IProvidesViewport_$type, c), typeCast(ISupportsErrorBars_$type, c), typeCast(IBucketizer_$type, c)];
                        {
                            let f = d[0];
                            let g = d[1];
                            let h = d[2];
                            let i = d[3];
                            let j = d[4];
                            super(1, g, h, i);
                            this.g = null;
                            this.h = null;
                            this.m = false;
                            this.o = new List$1(Array_$type, 0);
                            this.p = new List$1(Number_$type, 0);
                            this.n = new List$1(Number_$type, 0);
                            this.h = f;
                            this.g = j;
                        }
                    }
                    break;
                case 1:
                    {
                        let c = _rest[0];
                        let d = _rest[1];
                        let e = _rest[2];
                        let f = _rest[3];
                        let g = _rest[4];
                        super(1, d, e, f);
                        this.g = null;
                        this.h = null;
                        this.m = false;
                        this.o = new List$1(Array_$type, 0);
                        this.p = new List$1(Number_$type, 0);
                        this.n = new List$1(Number_$type, 0);
                        this.h = c;
                        this.g = g;
                    }
                    break;
            }
        }
        i(a) {
            let b = new PreparationParams();
            b.f = this.h.useHighMarkerFidelity;
            b.b = this.h.scaler;
            b.c = this.h.yScaler;
            b.d = typeCast(ISortingAxis_$type, b.b);
            b.a = typeCast(CategoryFrame.$, a);
            if (b.a == null || b.b == null || b.c == null) {
                return null;
            }
            let c;
            let d;
            let e;
            let f;
            let g = this.g.getBucketInfo(c, d, e, f);
            c = g.p0;
            d = g.p1;
            e = g.p2;
            f = g.p3;
            b.i = c;
            b.j = d;
            b.h = e;
            b.g = f;
            if (b.j < b.i) {
                return null;
            }
            let h;
            let i;
            let j;
            let k = this.a.getViewInfo(i, h);
            i = k.p0;
            h = k.p1;
            j = this.a.getEffectiveViewport();
            b.m = h;
            b.l = i;
            b.k = j;
            if (Rect.l_op_Equality(b.m, Rect.empty) || Rect.l_op_Equality(b.l, Rect.empty)) {
                return null;
            }
            if (this.h != null && (typeCast(Series.$, this.h) !== null && this.h.du) && this.g != null) {
                b.e = true;
            }
            return b;
        }
        r(a, b, c, d) {
            return a.getSeriesOffset(b, c, d, this.h.currentMode2Index, this.h.currentCategoryMode);
        }
        s(a) {
            return this.r(a.b, a.m, a.l, a.k);
        }
        d(a, b) {
            let c = this.i(a);
            if (c == null || this.g == null) {
                return;
            }
            c.a.f.clear();
            c.a.k.clear();
            c.a.m.clear();
            c.a.p.clear();
            c.a.i.clear();
            c.a.h.clear();
            c.a.g.clear();
            let d = this.c.shouldDisplayMarkers;
            let e = false;
            let f = this.s(c);
            let g = this.j(c);
            if (c.d != null && c.d.i$b != null && c.d.i$b.count != g.e) {
                return;
            }
            if (c.d != null && c.d.i$a) {
                c.d.i$h();
            }
            this.g.cacheValues();
            if (this.m && c.d != null && c.d.i$b.count > 0) {
                let h = c.d.i$b._inner[c.i];
                this.z(g, h, true, c.e);
                while ((isNaN_(g.c) || isNaN_(g.d)) && c.i > 0) {
                    c.i = c.i - 1;
                    h = c.d.i$b._inner[c.i];
                    this.z(g, h, true, c.e);
                }
                let i = c.d.i$b._inner[c.j];
                this.z(g, i, true, c.e);
                while ((isNaN_(g.c) || isNaN_(g.d)) && c.j < g.e - 1) {
                    c.j = c.j + 1;
                    i = c.d.i$b._inner[c.j];
                    this.z(g, i, true, c.e);
                }
            }
            if (this.m && c.d == null) {
                let j = c.i;
                let k = this.g.getBucket(j);
                while ((isNaN_(k[1]) || isNaN_(k[2])) && c.i > 0) {
                    c.i = c.i - 1;
                    j = c.i;
                    k = this.g.getBucket(j);
                }
                let l = c.j;
                k = this.g.getBucket(l);
                while ((isNaN_(k[1]) || isNaN_(k[2])) && c.j < (intDivide(g.e, c.h))) {
                    c.j = c.j + 1;
                    l = c.j;
                    k = this.g.getBucket(l);
                }
            }
            this.w(c, g, f);
            let m = this.t(c, g, f, d, e);
            this.c.updateMarkerCount(m);
            this.v(typeCast(CategoryFrame.$, a), b);
            this.g.unCacheValues();
            return;
        }
        v(a, b) {
        }
        get q() {
            return this.o;
        }
        t(a, b, c, d, e) {
            let f = 0;
            let g = false;
            let h = null;
            let i = false;
            let j = a.d != null;
            let k = a.m;
            let l = a.l;
            let m = typeCast(NumericAxisBase.$, a.c) !== null && a.c.lh;
            let n = a.f;
            let o = this.h.mayContainUnknowns;
            let p = this.o;
            let q = this.n;
            let r = this.p;
            p.clear();
            q.clear();
            r.clear();
            let s = this.g;
            let t = this.h.provideCollisionDetector();
            let u = 0;
            let v = a.k;
            let w = new ScalerParams(0, k, l, a.b.j$a, v);
            let x = ((() => {
                let $ret = new ScalerParams(0, k, l, a.c.j$a, v);
                $ret.b = typeCast(Series.$, this.h) !== null ? this.h.gc() : NaN;
                return $ret;
            })());
            if (j) {
                u = a.b.j$c(2, w) - a.b.j$c(1, w);
                i = this.k();
            }
            let y = a.i;
            let z = a.j;
            let aa = a.a.f;
            let ab = typeCast(IDateTimeAxis_$type, a.b);
            if (ab != null) {
                ab.StartTimeCursor();
            }
            for (let ac = y; ac <= z; ++ac) {
                let ad;
                if (!j) {
                    if (!o) {
                        ad = s.getBucketWithoutUnknowns(ac);
                    }
                    else {
                        ad = s.getBucket(ac);
                    }
                }
                else {
                    ad = ((() => { let ae = this.f(a, ac, b, u, g, h, c); ac = ae.p1; g = ae.p4; h = ae.p5; return ae.ret; })());
                }
                let ae = !m || (m && ad[1] > 0);
                let af = ad[0];
                if (!j || !isNaN_(ad[0])) {
                    aa.add(ad);
                    if (g && i) {
                        if (h != null) {
                            aa.add(h);
                        }
                    }
                    if (d && ae) {
                        let ag = ac * a.h;
                        let ah = ag;
                        if (j && a.d.i$b != null && ag >= 0 && ag < a.d.i$b.count) {
                            ag = a.d.i$b._inner[ag];
                        }
                        let ai = new Array(ad.length);
                        ai[0] = ad[0];
                        ai[1] = ad[1];
                        ai[2] = ad[2];
                        if (n && ag < b.e) {
                            ai = new Array(ad.length);
                            ai[0] = af;
                            this.z(b, ag, true, a.e);
                            ai[1] = b.c;
                            ai[2] = b.d;
                        }
                        p.add(ai);
                        q.add(a.a.f.count - 1);
                        r.add(ag);
                    }
                }
            }
            if (ab != null) {
                ab.ResetTimeCursor();
            }
            this.y(a, c, j, w, x, e, d);
            if (d) {
                let aj = p.count;
                let ak;
                for (let al = 0; al < aj; al++) {
                    ak = p._inner[al];
                    if (this.l(a.a, ak, t, Math.min(r._inner[al], b.e - 1), f, q._inner[al])) {
                        ++f;
                    }
                }
            }
            return f;
        }
        k() {
            if (typeCast(Series.$, this.h) !== null) {
                return this.h.de;
            }
            return false;
        }
        f(a, b, c, d, e, f, g) {
            let h;
            f = null;
            e = false;
            let i = typeCast(CategorySeries.$, this.h);
            let j = a.l;
            let k = a.m;
            let l = a.k;
            let m = new ScalerParams(0, k, j, a.b.j$a, l);
            let n = new ScalerParams(0, k, j, a.c.j$a, l);
            let o = a.e;
            if (a.d == null || a.d.i$b == null || a.d.i$b.count == 0) {
                return {
                    ret: [NaN, NaN, NaN],
                    p1: b,
                    p4: e,
                    p5: f
                };
            }
            if (i != null && i.ck != null && i.ck.count < a.d.i$b.count) {
                return {
                    ret: [NaN, NaN, NaN],
                    p1: b,
                    p4: e,
                    p5: f
                };
            }
            let p = a.d.i$b._inner[b];
            let q = a.d.i$d(p);
            let r = q;
            this.z(c, p, false, o);
            while (b < a.j) {
                p = a.d.i$b._inner[b + 1];
                r = a.d.i$d(p);
                this.z(c, p, true, o);
                if (r - q >= d || isNaN_(c.c) || isNaN_(c.d)) {
                    if (e) {
                        let s = a.d.i$b._inner[b];
                        this.z(c, s, true, o);
                        f = [a.b.j$b(q, m), c.c, c.d];
                    }
                    break;
                }
                if (!e && this.k()) {
                    let t = a.d.i$b._inner[b];
                    this.z(c, t, true, o);
                    let u = [a.b.j$b(q, m), c.c, c.d];
                    if (!isNaN_(u[0])) {
                        if (!isNaN_(u[1]) && !isNaN_(u[2])) {
                            if (a.d != null) {
                                u[0] = u[0] + g;
                            }
                            a.a.f.add(u);
                            e = true;
                        }
                        else {
                            break;
                        }
                    }
                }
                b++;
                this.u(c, p, o);
            }
            let v = NaN;
            if (!isNaN_(q)) {
                v = a.b.j$b(q, m);
            }
            h = this.e(v, c);
            return {
                ret: h,
                p1: b,
                p4: e,
                p5: f
            };
        }
        y(a, b, c, d, e, f, g) {
            let h = a.h;
            let i = a.a.f.count;
            let j = a.a.f;
            let k = this.o;
            let l = k.count;
            if (f) {
                let m = a.c.j$b(a.c.l5, e);
                a.c.j$e(a.a.k, 0, a.a.k.count, e);
                let n = a.a.k;
                let o = n.count;
                for (let p = 0; p < n.count; p++) {
                    n._inner[p] = Math.abs(n._inner[p] - m);
                }
            }
        }
        w(a, b, c) {
        }
    }
    CategoryFramePreparerBase.$t = markType(CategoryFramePreparerBase, 'CategoryFramePreparerBase', FramePreparer.$);
    return CategoryFramePreparerBase;
})();
/**
 * @hidden
 */
export let CategoryFramePreparer = /*@__PURE__*/ (() => {
    class CategoryFramePreparer extends CategoryFramePreparerBase {
        constructor(a, ..._rest) {
            a = (a == void 0) ? 0 : a;
            switch (a) {
                case 0:
                    {
                        let c = _rest[0];
                        let d = [c, typeCast(ISupportsMarkers_$type, c), typeCast(IProvidesViewport_$type, c), typeCast(ISupportsErrorBars_$type, c), typeCast(IBucketizer_$type, c)];
                        {
                            let f = d[0];
                            let g = d[1];
                            let h = d[2];
                            let i = d[3];
                            let j = d[4];
                            super(1, f, g, h, i, j);
                            this.aa = new DefaultCategoryTrendlineHost();
                            this.ab = new DefaultSingleValueProvider();
                            this.ac = null;
                            this.ad = null;
                            this.ac = this.aa;
                            if (typeCast(IHasCategoryTrendline_$type, f) !== null) {
                                this.ac = typeCast(IHasCategoryTrendline_$type, f);
                            }
                            this.ad = this.ab;
                            if (typeCast(IHasSingleValueCategory_$type, f) !== null) {
                                this.ad = typeCast(IHasSingleValueCategory_$type, f);
                            }
                        }
                    }
                    break;
                case 1:
                    {
                        let c = _rest[0];
                        let d = _rest[1];
                        let e = _rest[2];
                        let f = _rest[3];
                        let g = _rest[4];
                        super(1, c, d, e, f, g);
                        this.aa = new DefaultCategoryTrendlineHost();
                        this.ab = new DefaultSingleValueProvider();
                        this.ac = null;
                        this.ad = null;
                        this.ac = this.aa;
                        if (typeCast(IHasCategoryTrendline_$type, c) !== null) {
                            this.ac = typeCast(IHasCategoryTrendline_$type, c);
                        }
                        this.ad = this.ab;
                        if (typeCast(IHasSingleValueCategory_$type, c) !== null) {
                            this.ad = typeCast(IHasSingleValueCategory_$type, c);
                        }
                    }
                    break;
            }
        }
        l(a, b, c, d, e, f) {
            let g = b[0];
            let h = b[1];
            let i = new Rect(0, g - 5, h - 5, 11, 11);
            if (!isNaN_(g) && !isNaN_(h) && !isInfinity(g) && !isInfinity(h) && c.tryAdd(i)) {
                a.m.add({ $type: Point_$type, x: g, y: h });
                this.c.updateMarkerTemplate(e, d, f);
                return true;
            }
            return false;
        }
        j(a) {
            let b = new SingleValuesHolder();
            let c = this.ad.valueColumn;
            b.f = c;
            return b;
        }
        x(a, b, c, d, e, f) {
            if (d) {
                b[0] = b[0] + c;
            }
            else {
                b[0] = a.b.j$b(b[0], e) + c;
            }
            b[1] = a.c.j$b(b[1], f);
            if (a.h > 1 || d) {
                b[2] = a.c.j$b(b[2], f);
            }
            else {
                b[2] = b[1];
            }
        }
        y(a, b, c, d, e, f, g) {
            super.y(a, b, c, d, e, f, g);
            let h = a.h;
            let i = a.a.f.count;
            let j = a.a.f;
            let k = this.q;
            let l = k.count;
            let m = new List$1(Number_$type, 0);
            if (!c) {
                m.add(0);
            }
            let n = new List$1(Number_$type, 0);
            n.add(1);
            if (c || h > 1) {
                n.add(2);
            }
            a.b.j$d(j, m, 0, i, d);
            a.c.j$d(j, n, 0, i, e);
            for (let o = 0; o < i; o++) {
                j._inner[o][0] = j._inner[o][0] + b;
            }
            if (h == 1 && !c) {
                for (let p = 0; p < i; p++) {
                    j._inner[p][2] = j._inner[p][1];
                }
            }
            if (g) {
                a.b.j$d(k, m, 0, l, d);
                a.c.j$d(k, n, 0, l, e);
                for (let q = 0; q < l; q++) {
                    k._inner[q][0] = k._inner[q][0] + b;
                }
                if (h == 1 && !c) {
                    for (let r = 0; r < l; r++) {
                        k._inner[r][2] = k._inner[r][1];
                    }
                }
            }
        }
        w(a, b, c) {
            if (this.ac.trendLineType == 0 || this.ac.trendlinePreparer == null || this.ac.trendLinePeriod < 1) {
                return;
            }
            this.ac.trendlinePreparer.prepareLine(this.ac, a, b, c);
        }
        z(a, b, c, d) {
            let e = a;
            let f = e.f;
            let g = f.item(b);
            let h = g;
            if (d) {
                let i = this.g.getBucket(b);
                g = i[1];
                h = i[1];
            }
            if (c) {
                e.c = g;
                e.d = h;
            }
            else {
                e.a = g;
                e.b = h;
            }
        }
        u(a, b, c) {
            let d = a;
            let e = d.f;
            if (b < e.count) {
                let f;
                if (c) {
                    let g = this.g.getBucket(b);
                    f = g[1];
                }
                else {
                    f = e.item(b);
                }
                d.a = Math.min(d.a, f);
                d.b = Math.max(d.b, f);
            }
        }
        e(a, b) {
            let c = b;
            return [a, c.a, c.b];
        }
    }
    CategoryFramePreparer.$t = markType(CategoryFramePreparer, 'CategoryFramePreparer', CategoryFramePreparerBase.$);
    return CategoryFramePreparer;
})();
/**
 * @hidden
 */
export let CategorySeries = /*@__PURE__*/ (() => {
    class CategorySeries extends MarkerSeries {
        constructor() {
            super();
            this.rt = null;
            this.r6 = null;
            this.sa = false;
            this.r9 = false;
            this.assigningCategoryStyle = null;
            this.assigningCategoryMarkerStyle = null;
            this.r4 = null;
            this.r5 = null;
            this.rq = new CategoryFrame(3);
            this.rs = new CategoryFrame(3);
            this.ro = new CategoryFrame(3);
            this.rr = new CategoryFrame(3);
            this.rw = null;
            this.r0 = null;
            this.rw = new CategorySeriesRenderManager();
            this.r0 = new CategoryTransitionSourceFramePreparer();
            this.sa = false;
            this.r9 = false;
            this.ab = CategorySeries.$;
        }
        bx() {
            let a = new CategorySeriesView(this);
            return a;
        }
        get r7() {
            if (this.r6 == null) {
                this.r6 = DVContainer.instance.createInstance(ICategorySeriesInteractionManager_$type, () => this.cn.n);
            }
            return this.r6;
        }
        c1(a, b, c, d) {
            if (!this.hasMarkers) {
                return false;
            }
            let e = this.getEffectiveViewport1(this.b0);
            let f = this.rn();
            let g = new ScalerParams(1, this.cd.sf, this.py, f.cg);
            g.c = e;
            let h = this.r8();
            let i = new ScalerParams(1, this.cd.sf, this.py, h.cg);
            i.c = e;
            let j = this.cd.sf;
            let k = this.py;
            let l = this.currentMode2Index;
            let m = 0;
            if (f.cd && f.cb) {
                m = f.getSeriesOffset(j, k, e, l, f.categoryMode);
            }
            a.clear();
            this.qb.cf((n) => {
                if (n._visibility == 0) {
                    let o = new SeriesPointOfInterest();
                    let p = n.n;
                    let q = n.o;
                    if (p < this.py.left || p > this.py.right || q < this.py.top || q > this.py.bottom) {
                        return;
                    }
                    if (this.isVertical) {
                        if (f.ca && !f.cd && f.categoryMode != 0) {
                            o.c = n.ak;
                        }
                        else {
                            o.c = f.el(q, g);
                        }
                        o.b = h.el(p, i);
                    }
                    else {
                        if (f.ca && !f.cd && f.categoryMode != 0) {
                            o.b = n.ak;
                        }
                        else {
                            o.b = f.el(p, g);
                        }
                        o.c = h.el(q, i);
                    }
                    o.a = n.content;
                    if (b) {
                        if (this.isVertical) {
                            if (c) {
                                o.d = this.ss(o.b, d);
                            }
                            else {
                                let r = this.go(n);
                                if (!isNaN_(r)) {
                                    o.d = this.ss(r, d);
                                }
                                else {
                                    o.d = this.ss(o.b, d);
                                }
                            }
                        }
                        else {
                            if (c) {
                                o.d = this.ss(o.c, d);
                            }
                            else {
                                let s = this.go(n);
                                if (!isNaN_(s)) {
                                    o.d = this.ss(s, d);
                                }
                                else {
                                    o.d = this.ss(o.c, d);
                                }
                            }
                        }
                    }
                    else {
                        o.d = f.gc(n.ak);
                    }
                    a.add(o);
                }
            });
            return true;
        }
        ss(a, b) {
            if (b >= 0) {
                return round10N(a, b).toString();
            }
            else {
                return a.toString();
            }
        }
        ly(a) {
            super.ly(a);
            this.rx = a;
        }
        preferredCategoryMode(a) {
            return 0;
        }
        get categoryAxis() {
            return this.rn();
        }
        rn() {
            return this.fetchXAxis();
        }
        r8() {
            return this.fetchYAxis();
        }
        get_c6() {
            return true;
        }
        get_ej() {
            return this.r8() != null && this.r8().cg;
        }
        get_dg() {
            return true;
        }
        ac() {
            super.ac();
            this.rx.cr.g(this.ft);
        }
        sg() {
            return (this.assigningCategoryStyle != null && this.sa) || (this.bk != 1);
        }
        sh() {
            return (this.assigningCategoryMarkerStyle != null && this.r9) || (this.bk != 1);
        }
        s5(a) {
            if (this.assigningCategoryStyle != null && this.sa) {
                this.assigningCategoryStyle(this, a);
            }
        }
        s4(a) {
            if (this.assigningCategoryMarkerStyle != null && this.r9) {
                this.assigningCategoryMarkerStyle(this, a);
            }
        }
        rh(a, b) {
            return null;
        }
        kx(a, b) {
            super.kx(a, b);
            if (a) {
                this.sz(b);
            }
        }
        bh() {
            let a = super.bh();
            return a;
        }
        le() {
            super.le();
            let a = this.fetchXAxis();
            if (a != null) {
                a.h7(false);
            }
            let b = this.fetchYAxis();
            if (b != null) {
                b.h7(false);
            }
        }
        m5(a, b) {
            super.m5(a, b);
            this.rx.cr.g(this.ft);
            this.mh(false);
        }
        m4(a, b) {
            if (this.e0 && this.g0 < 0.05 && (this.cd == null || !this.cd.eo())) {
                this.e1 = true;
            }
            super.m4(a, b);
            this.rx.cr.g(this.ft);
            this.mh(false);
        }
        l3(a, b, c, d) {
            super.l3(a, b, c, d);
            switch (b) {
                case "SeriesViewer":
                    let e = this.fetchYAxis();
                    let f = this.fetchXAxis();
                    if (c != null && d == null) {
                        this.k1(f);
                        this.k1(e);
                    }
                    if (c == null && d != null) {
                        this.l8(f);
                        this.l8(e);
                    }
                    this.rx.cr.g(this.ft);
                    this.mh(false);
                    break;
                case "SyncLink":
                    if (this.b8 != null && this.cd != null) {
                        this.rx.cr.g(this.ft);
                    }
                    this.mh(false);
                    break;
                case "TransitionProgress":
                    this.rs.c(this.g0, this.rq, this.ro);
                    if (this.cx(this.b0)) {
                        return;
                    }
                    if (this.g0 == 1) {
                        this.ro.v();
                        this.s6(this.ro, this.rx);
                        if (this.e0) {
                            this.e0 = false;
                            this.ky();
                            this.ce.r = truncate(this.gm());
                            this.ce.b = this.cf;
                        }
                    }
                    else {
                        this.s6(this.rs, this.rx);
                    }
                    if (this.cd != null) {
                        this.cd.nn(this);
                    }
                    break;
                case "ErrorBarSettings":
                    this.lo();
                    break;
                case CategorySeries.$$p[4]:
                    this.mh(false);
                    break;
                case CategorySeries.$$p[1]:
                    this.sa = this.sc();
                    this.mh(false);
                    break;
                case CategorySeries.$$p[0]:
                    this.r9 = this.sb();
                    this.mh(false);
                    break;
            }
        }
        sc() {
            return this.se;
        }
        sb() {
            return this.sd;
        }
        sm(a) {
            return this.f7(a, this.fetchXAxis());
        }
        get_d9() {
            return typeCast(ISortingAxis_$type, this.rn()) !== null;
        }
        ar() {
            return this.rn();
        }
        hf(a) {
            return this.r7.b$d(this, a);
        }
        ht(a) {
            return this.r7.b$f(this, a);
        }
        hd(a) {
            let b = truncate(Math.round(this.f5(a)));
            return b;
        }
        f5(a) {
            return this.r7.b$c(this, a);
        }
        ax(a, b, c) {
            if (this.ef(this.bk) && !c) {
                let d = this.r3(a, b, this.r5);
                this.r5 = d;
                return d;
            }
            else {
                let e = this.r1(a, b, this.r5);
                e.e = true;
                this.r5 = e;
                return e;
            }
        }
        get_dx() {
            return true;
        }
        kv() {
            super.kv();
            this.r4 = null;
            this.r5 = null;
        }
        aw(a, b, c) {
            if (this.c2 && this.ef(this.bk) && !c) {
                let d = this.r2(a, b, this.r4);
                this.r4 = d;
                return d;
            }
            else {
                let e = this.r1(a, b, this.r4);
                this.r4 = e;
                return e;
            }
        }
        sl() {
            return this.rx.cu.a;
        }
        r3(a, b, c) {
            if (!this.qe()) {
                return null;
            }
            let d = this.rp();
            let e = this.sl();
            return this.r7.b$b(this, e, this.sp(this.b0), this.so(this.b0), d.f, a, b, c);
        }
        r2(a, b, c) {
            let d = this.sp(this.b0);
            let e = this.sq(this.b0);
            let f = this.so(this.b0);
            let g = this.rp();
            return this.r7.b$a(this, g.f, d, e, f, a, b, c);
        }
        r1(a, b, c) {
            let d = new HighlightingInfo();
            d.b = this;
            d.h = 0;
            d.g = this.ck.count - 1;
            d.d = true;
            if (c != null && c.h == d.h && c.g == d.g) {
                return c;
            }
            return d;
        }
        rp() {
            let a = this.ro;
            if (this.cv()) {
                if (this.ce.g) {
                    this.ce.t();
                }
                a = this.rs;
            }
            return a;
        }
        s1(a, b, c, d, e, f) {
            let g = this.bk != 1;
            this.rw.a1(this.rw.d, d.cm, a, b, c, d, e, f, true);
            this.rw.aa(this.fr);
            let h = this.rw.av;
            let i = null;
            let j = this.ck;
            let k = null;
            if (g && this.cd != null) {
                i = this.cd.a3.getHighlightingInfo(this, j, h.o, h.n, true);
                if (this.cd.a3.isCrossSeriesHighlight(this)) {
                    k = this.cd.a3.getHighlightingInfo(this, j, h.o, h.n, true);
                }
                h.b = i;
            }
            h.f = f;
            this.s4(h);
            this.rw.y(this, i, f, g, h.m, this.cd.a3.totalHighlightingProgress);
        }
        s2(a, b, c, d, e, f) {
            let g = this.bk != 1;
            this.rw.a1(this.rw.b, d.cm, a, b, c, d, e, f, false);
            this.rw.ab(this.fr);
            let h = this.rw.aw;
            let i = null;
            let j = this.ck;
            if (g && this.cd != null) {
                i = this.cd.a3.getHighlightingInfo(this, j, h.o, h.n, false);
                h.b = i;
            }
            h.f = f;
            this.s5(h);
            this.rw.z(this, i, f, g, b < 0);
        }
        e9(a, b, c) {
            let d = super.e9(a, b, c);
            d = d && this.sk(this.fetchXAxis());
            d = d && this.sk(this.fetchYAxis());
            let e = c;
            if (!c.o() || b.isEmpty || a.isEmpty || this.ck == null) {
                d = false;
            }
            if (!d) {
                e.cr.d = 0;
            }
            return d;
        }
        sk(a) {
            if (a == null || a.bh == null) {
                return false;
            }
            let b = typeCast(CategoryAxisBase.$, a);
            if (b != null) {
                if (b.itemsSource == null) {
                    return false;
                }
                if (b.le < 1) {
                    return false;
                }
            }
            else {
                let c = typeCast(NumericAxisBase.$, a);
                if (c != null) {
                    return c.lv != c.lu;
                }
            }
            return true;
        }
        eq() {
            return this.sf;
        }
        ry() {
            return 12;
        }
        ky() {
            super.ky();
            this.rq.v();
            this.ro.v();
            this.rs.v();
        }
        mi(a) {
            super.mi(a);
            this.rx.cr.g(this.ft);
            if (this.cx(this.b0)) {
                this.ro.y();
                this.rs.y();
                this.rq.y();
                return;
            }
            if (this.es) {
                if (this.cv()) {
                    if (this.ce.g) {
                        this.ce.t();
                    }
                    this.s6(this.rs, this.rx);
                }
                else {
                    this.s6(this.ro, this.rx);
                }
                return;
            }
            if (this.eo(a)) {
                let b = this.rq;
                if (this.cv()) {
                    if (this.ce.g) {
                        this.ce.t();
                    }
                    this.rq = this.rs;
                    this.rs = b;
                }
                else {
                    this.rq = this.ro;
                    this.ro = b;
                }
                this.s3(this.ro, this.rx);
                if (this.e2) {
                    this.ce.w();
                    this.ce.r = truncate(this.gn());
                    this.ce.b = this.cg != null ? this.cg : this.cf;
                    this.r0.p(this.rq, this.ro, this.isVertical, this.fetchXAxis(), this.fetchYAxis(), this.rz, this.ry(), this.ca, this.b9(), runOn(this, this.sn), this.rx.bu);
                }
                this.kt();
                this.mq();
                if (this.e2) {
                    this.e1 = false;
                    this.e0 = true;
                }
            }
            else {
                this.s3(this.ro, this.rx);
                this.s6(this.ro, this.rx);
            }
        }
        b9() {
            return 3;
        }
        sn() {
            if (this.isVertical) {
                return this.py.left;
            }
            return this.py.bottom;
        }
        sr() {
            let a = 0;
            let b = this.fetchXAxis();
            for (let c of fromEnum(this.cd.series)) {
                if (c == this) {
                    return a;
                }
                let d = typeCast(CategorySeries.$, c);
                if (d != null) {
                    let e = typeCast(CategoryAxisBase.$, d.fetchXAxis());
                    if (e == b && d.preferredCategoryMode(e) == 2) {
                        a++;
                    }
                }
            }
            return -1;
        }
        get GetErrorBarsXAxis() {
            return this.fetchXAxis();
        }
        get GetErrorBarsYAxis() {
            return this.fetchYAxis();
        }
        s0(a, b) {
            this.rw.az(this, this.sh(), runOn(this, this.rh), this.so(a), this.sp(a));
            let c = this.rw.d;
            let d = c != null;
            let e = this.rn();
            if (e == null) {
                return;
            }
            let f = this.getEffectiveViewport1(a);
            let g = new ScalerParams(0, a.bv, a.bu, e.cg, f);
            let h = this.ck == null ? 0 : this.ck.count;
            let i = a;
            let j = b.f;
            let k = i.cr.e;
            let l = i.cr.f;
            let m = i.cr.d;
            let n = k * m;
            for (let o = 0; o < a.cu.count; o++) {
                let p = a.cu.item(o);
                let q = p.content;
                if (d) {
                    let r = p.al;
                    this.s1(j, r, h, e, g, a.q);
                }
                this.rw.ac(p, q);
            }
        }
        s6(a, b) {
            this.pp = a.aa;
            b.au();
        }
        s3(a, b) {
            a.u();
        }
        so(a) {
            return a.cr.d;
        }
        sp(a) {
            return a.cr.e;
        }
        sq(a) {
            return a.cr.f;
        }
        sz(a) {
            let b = a;
            b.cu.count = 0;
        }
        mj(a, b) {
            super.mj(a, b);
            if (!this.ez) {
                this.b0.a2(b);
                return;
            }
            let c = typeCast(CategorySeriesView.$, this.bz);
            c.cr.g(this.ft);
            this.b0.a2(b);
            if (this.cx(this.bz)) {
                return;
            }
            this.s7();
            this.ez = false;
        }
        s7() {
            let a = typeCast(CategorySeriesView.$, this.bz);
            if (!this.et) {
                this.s3(this.rr, a);
            }
            this.et = false;
            this.s6(this.rr, a);
        }
        ru(a) {
            let b = typeCast(CategorySeriesView.$, a);
            if (b != null && b.q) {
                if (b.p) {
                    return new CategoryFramePreparer(1, typeCast(IIsCategoryBased_$type, this), typeCast(ISupportsMarkers_$type, b), b, this, b.cr);
                }
                else {
                    return new CategoryFramePreparer(1, typeCast(IIsCategoryBased_$type, this), typeCast(ISupportsMarkers_$type, b), this.cd.cq.o, this, b.cr);
                }
            }
            else {
                return this.rt;
            }
        }
        an(a) {
            if (this.fetchXAxis() == a) {
                return this.fetchYAxis();
            }
            if (this.fetchYAxis() == a) {
                return this.fetchXAxis();
            }
            return null;
        }
        ag() {
            return [this.fetchXAxis(), this.fetchYAxis()];
        }
        static ri(a, b, c, d, e) {
            let f = null;
            if (b > -1 && !d.isEmpty && !c.isEmpty) {
                let g = a._inner[0][0] < c.left - 2000 ? c.left - 10 : NaN;
                let h = c.bottom + 10;
                let i = a._inner[b][0] > c.right + 2000 ? c.right + 10 : NaN;
                let j = c.top - 10;
                f = new Clipper(1, g, h, i, j, e);
            }
            return f;
        }
    }
    CategorySeries.$t = markType(CategorySeries, 'CategorySeries', MarkerSeries.$, [IHasCategoryModePreference_$type, ISupportsErrorBars_$type]);
    CategorySeries.$$p = markDep(DependencyProperty, PropertyMetadata, CategorySeries, 'raisePropertyChanged', ['IsCustomCategoryMarkerStyleAllowed:sd:s8', [0, false], 'IsCustomCategoryStyleAllowed:se:s9', [0, false], 'IsTransitionInEnabled:sf:ta', [0, false], 'TransitionInMode:rz:tb', [CategoryTransitionInMode_$type, enumGetBox(CategoryTransitionInMode_$type, 0)], 'UseHighMarkerFidelity:sj:tc', [0, false]]);
    return CategorySeries;
})();
/**
 * @hidden
 */
export let CategorySeriesView = /*@__PURE__*/ (() => {
    class CategorySeriesView extends MarkerSeriesView {
        constructor(a) {
            super(a);
            this.ct = null;
            this.cw = 0;
            this.cr = null;
            this.cu = null;
            this.cw = -1;
            this.ct = a;
            this.cr = this.cs();
            this.cu = ((() => {
                let $ret = new Pool$1(Marker.$);
                $ret.create = runOn(this, this.b0);
                $ret.activate = runOn(this, this.cj);
                $ret.disactivate = runOn(this, this.cl);
                $ret.destroy = runOn(this, this.ck);
                return $ret;
            })());
        }
        cv(a) {
            if (this.cw != a.t) {
                return true;
            }
            return false;
        }
        cy(a) {
            this.cw = a.t;
        }
        updateMarkerTemplate(a, b, c) {
            if (!this.b1.qg) {
                let d = this.cu.item(a);
                let e = d.content;
                e.item = this.e.ck.item(b);
                d.ak = b;
                d.al = c;
            }
        }
        cs() {
            return new CategoryBucketCalculator(this);
        }
        get shouldDisplayMarkers() {
            return this.ct.qe();
        }
        updateMarkerCount(a) {
            this.cu.count = a;
        }
        cf(a) {
            this.cu.c(a);
        }
        cx() {
        }
    }
    CategorySeriesView.$t = markType(CategorySeriesView, 'CategorySeriesView', MarkerSeriesView.$, [ISupportsMarkers_$type]);
    return CategorySeriesView;
})();
