/*
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 { ScatterTriangulationSeries } from "./ScatterTriangulationSeries";
import { DependencyProperty } from "igniteui-angular-core";
import { typeCast, Number_$type, Point_$type, fromEnum, runOn, delegateRemove, delegateCombine, markType, markDep } from "igniteui-angular-core";
import { ValueBrushScale } from "./ValueBrushScale";
import { FastItemIntColumn } from "igniteui-angular-core";
import { LinearContourValueResolver } from "./LinearContourValueResolver";
import { SeriesView } from "./SeriesView";
import { IFastItemsSource_$type } from "igniteui-angular-core";
import { ScalerParams } from "./ScalerParams";
import { ContourBuilder } from "./ContourBuilder";
import { Clipper } from "igniteui-angular-core";
import { List$1 } from "igniteui-angular-core";
import { RectUtil } from "igniteui-angular-core";
import { DataContext } from "igniteui-angular-core";
import { Path } from "igniteui-angular-core";
import { PropertyMetadata } from "igniteui-angular-core";
import { boxArray$1 } from "igniteui-angular-core";
import { isNaN_ } from "igniteui-angular-core";
import { Pool$1 } from "igniteui-angular-core";
import { Brush } from "igniteui-angular-core";
import { PathGeometry } from "igniteui-angular-core";
import { PathFigure } from "igniteui-angular-core";
import { BrushUtil } from "igniteui-angular-core";
import { BrushCollection } from "igniteui-angular-core";
import { PointCollectionUtil } from "igniteui-angular-core";
import { PolyLineSegment } from "igniteui-angular-core";
import { Tuple$2 } from "igniteui-angular-core";
import { GeometryUtil } from "igniteui-angular-core";
import { stringIsNullOrEmpty } from "igniteui-angular-core";
/**
 * @hidden
 */
export class ScatterContourSeries extends ScatterTriangulationSeries {
    constructor() {
        super();
        this.nl = null;
        this.nh = null;
        FastItemIntColumn.m();
        this.ab = ScatterContourSeries.$;
        this.ni = new LinearContourValueResolver();
    }
    fs(a, b) {
        let c = this.gu(b);
        if (c == ScatterContourSeries.$$p[1]) {
            return this.ft(a, b, this.np);
        }
        return super.fs(a, b);
    }
    bf() {
        this.nj = new ScatterContourSeriesView(this);
        return this.nj;
    }
    get nm() {
        return this.nl;
    }
    set nm(a) {
        let b = this.nm != a;
        if (b) {
            let c = this.nm;
            this.nl = a;
            this.raisePropertyChanged("ValueColumn", c, this.nm);
        }
    }
    iz(a, b, c, d) {
        super.iz(a, b, c, d);
        switch (b) {
            case "FastItemsSource":
                let e = typeCast(IFastItemsSource_$type, c);
                if (e != null) {
                    e.deregisterColumn(this.nm);
                    this.nm = null;
                }
                let f = typeCast(IFastItemsSource_$type, d);
                if (f != null) {
                    this.nm = this.bw(this.np);
                }
                this.jd(false);
                break;
            case ScatterContourSeries.$$p[1]:
                if (this.bz != null) {
                    this.bz.deregisterColumn(this.nm);
                    this.nm = this.bw(this.np);
                }
                this.jd(false);
                this.ik();
                break;
            case "ValueResolver":
                this.jd(false);
                this.ik();
                break;
            case ScatterContourSeries.$$p[0]:
                let g = c;
                let h = d;
                if (g != null) {
                    g.unregisterSeries(this);
                }
                if (h != null) {
                    h.registerSeries(this);
                }
                this.jd(false);
                this.ik();
                break;
            case "ActualBrush":
                this.jd(false);
                this.ik();
                break;
        }
    }
    hv(a, b) {
        super.hv(a, b);
        if (a) {
            b.b0(a);
        }
    }
    je(a) {
        super.je(a);
        this.ns(this.bi);
    }
    jc(a, b, c, d, e) {
        super.jc(a, b, c, d, e);
        let f = this.a0.a$h.item(d);
        f.ay(c);
        if (this.cc(f)) {
            return;
        }
        this.ns(f);
    }
    ns(a) {
        if (this.cc(a)) {
            return;
        }
        let b;
        let c;
        let d = a;
        let e = a.getViewInfo(c, b);
        c = e.p0;
        b = e.p1;
        let f = new ScalerParams(1, b, c, this.l0.b8);
        f.c = this.getEffectiveViewport1(a);
        let g = new ScalerParams(1, b, c, this.l1.b8);
        g.c = this.getEffectiveViewport1(a);
        let h = this.l0;
        let i = this.l1;
        let j = this.ma.count;
        let k;
        let xArr_ = this.md.asArray();
        k = (xArr_.slice(0));
        let l;
        let yArr_ = this.me.asArray();
        l = (yArr_.slice(0));
        let m = this.nm.asArray();
        let n = this.ma.asArray();
        let o = this.mb.asArray();
        let p = this.mc.asArray();
        let q = this.ni.j(this.nm);
        let r = new List$1(Number_$type, 1, q).toArray();
        h.gn(boxArray$1(k), 0, k.length, f);
        i.gn(boxArray$1(l), 0, l.length, g);
        let s = r.length;
        let t = new Array(s);
        for (let u = 0; u < s; ++u) {
            t[u] = new ContourBuilder();
        }
        let v = c.top;
        let w = c.left;
        let x = c.right;
        let y = c.bottom;
        let z;
        let aa;
        let ab;
        let ac;
        let ad = k.length;
        for (let ae = 0; ae < j; ae++) {
            let af = n[ae];
            let ag = o[ae];
            let ah = p[ae];
            if ((af >= ad) || (ag >= ad) || (ah >= ad) || (af < 0) || (ag < 0) || (ah < 0)) {
                continue;
            }
            let ai = k[af];
            let aj = l[af];
            let ak = { $type: Point_$type, x: ai, y: aj };
            let al = k[ag];
            let am = l[ag];
            let an = { $type: Point_$type, x: al, y: am };
            let ao = k[ah];
            let ap = l[ah];
            let aq = { $type: Point_$type, x: ao, y: ap };
            z = an.y < aq.y ? an.y : aq.y;
            z = ak.y < z ? ak.y : z;
            aa = an.y > aq.y ? an.y : aq.y;
            aa = ak.y > aa ? ak.y : aa;
            ab = an.x < aq.x ? an.x : aq.x;
            ab = ak.x < ab ? ak.x : ab;
            ac = an.x > aq.x ? an.x : aq.x;
            ac = ak.x > ac ? ak.x : ac;
            if (z < y && aa > v && ab < x && ac > w) {
                let ar = m[af];
                let as = m[ag];
                let at = m[ah];
                if (isNaN_(ar) || isNaN_(as) || isNaN_(at)) {
                    continue;
                }
                for (let au = 0; au < s; au++) {
                    let av = r[au];
                    let aw = t[au];
                    switch ((ar < av ? 1 : 0) | (as < av ? 2 : 0) | (at < av ? 4 : 0)) {
                        case 0: break;
                        case 1:
                            aw.d(aw.k(af, ak.x, ak.y, ar, ag, an.x, an.y, as, av), aw.k(ah, aq.x, aq.y, at, af, ak.x, ak.y, ar, av));
                            break;
                        case 2:
                            aw.d(aw.k(ag, an.x, an.y, as, ah, aq.x, aq.y, at, av), aw.k(af, ak.x, ak.y, ar, ag, an.x, an.y, as, av));
                            break;
                        case 3:
                            aw.d(aw.k(ag, an.x, an.y, as, ah, aq.x, aq.y, at, av), aw.k(ah, aq.x, aq.y, at, af, ak.x, ak.y, ar, av));
                            break;
                        case 4:
                            aw.d(aw.k(ah, aq.x, aq.y, at, af, ak.x, ak.y, ar, av), aw.k(ag, an.x, an.y, as, ah, aq.x, aq.y, at, av));
                            break;
                        case 5:
                            aw.d(aw.k(af, ak.x, ak.y, ar, ag, an.x, an.y, as, av), aw.k(ag, an.x, an.y, as, ah, aq.x, aq.y, at, av));
                            break;
                        case 6:
                            aw.d(aw.k(ah, aq.x, aq.y, at, af, ak.x, ak.y, ar, av), aw.k(af, ak.x, ak.y, ar, ag, an.x, an.y, as, av));
                            break;
                        case 7: break;
                    }
                }
            }
        }
        let ax = new Clipper(0, RectUtil.r(c, 2), false);
        let ay = new List$1(List$1.$.specialize(List$1.$.specialize(Point_$type)), 0);
        for (let az = 0; az < s; ++az) {
            let a0 = t[az];
            let a1 = new List$1(List$1.$.specialize(Point_$type), 0);
            let a2 = a0.c();
            for (let a3 = 0; a3 < a2.count; a3++) {
                let a4 = a2._inner[a3];
                let a5 = new List$1(Point_$type, 0);
                ax.i = a5;
                for (let a6 of fromEnum(a4)) {
                    ax.j({ $type: Point_$type, x: a0.g.item(a6), y: a0.h.item(a6) });
                }
                ax.i = null;
                a1.add(a5);
            }
            ay.add(a1);
        }
        d.bz(ay, r);
    }
    get ni() {
        return this.nh;
    }
    set ni(a) {
        let b = a != this.ni;
        if (b) {
            if (this.nh != null) {
                let c = this.nh;
                c.updated = delegateRemove(c.updated, runOn(this, this.nt));
            }
            let d = this.nh;
            this.nh = a;
            if (this.nh != null) {
                let e = this.nh;
                e.updated = delegateCombine(e.updated, runOn(this, this.nt));
            }
            this.raisePropertyChanged("ValueResolver", d, a);
            this.jd(false);
        }
    }
    nt(a, b) {
        this.jd(false);
    }
    dw(a, b, c) {
        return super.dw(a, b, c) && this.ni != null && this.md != null && this.me != null && this.ma != null && this.mb != null && this.mc != null && this.md.count > 0 && this.me.count > 0 && this.ma.count > 0 && this.mb.count > 0 && this.mc.count > 0;
    }
    ar(a, b) {
        let c = this.nj.b4(a, b);
        if (c != null) {
            return c.dataContext;
        }
        return null;
    }
}
ScatterContourSeries.$t = markType(ScatterContourSeries, 'ScatterContourSeries', ScatterTriangulationSeries.$);
ScatterContourSeries.$$p = markDep(DependencyProperty, PropertyMetadata, ScatterContourSeries, 'raisePropertyChanged', ['FillScale:nk:nu', [ValueBrushScale.$, null], 'ValueMemberPath:np:nv', [2, null]]);
/**
 * @hidden
 */
export class ScatterContourSeriesView extends SeriesView {
    constructor(a) {
        super(a);
        this.bw = null;
        this.bv = null;
        this.by = null;
        this.bx = new List$1(Brush.$, 0);
        this.bu = null;
        this.by = new List$1(Path.$, 0);
        this.bv = a;
        this.bw = ((() => {
            let $ret = new Pool$1(Path.$);
            $ret.create = runOn(this, this.b5);
            $ret.destroy = runOn(this, this.b3);
            $ret.activate = runOn(this, this.b1);
            $ret.disactivate = runOn(this, this.b2);
            return $ret;
        })());
    }
    b5() {
        let a = new Path();
        a.dataContext = ((() => {
            let $ret = new DataContext();
            $ret.series = this.e;
            return $ret;
        })());
        this.by.add(a);
        return a;
    }
    b1(a) {
        a._visibility = 0;
    }
    b2(a) {
        a._visibility = 1;
    }
    b3(a) {
        this.by.remove(a);
    }
    bz(a, b) {
        let c = 0;
        this.bu = b;
        this.bx.clear();
        let d = this.bv.nk;
        if (d == null) {
            d = new ValueBrushScale();
            d.brushes.add(BrushUtil.l(this.e.k3, -0.5));
            d.brushes.add(this.e.k3);
        }
        else if (d.brushes == null) {
            d.brushes = new BrushCollection();
            d.brushes.add(BrushUtil.l(this.e.k3, -0.5));
            d.brushes.add(this.e.k3);
        }
        else if (d.brushes.count == 0) {
            d.brushes.add(BrushUtil.l(this.e.k3, -0.5));
            d.brushes.add(this.e.k3);
        }
        for (let e = 0; e < b.length; e++) {
            let f = b[e];
            let g = a._inner[c];
            let h = new PathGeometry();
            for (let i = 0; i < g.count; i++) {
                let j = g._inner[i];
                if (j.count == 0) {
                    continue;
                }
                let k = PointCollectionUtil.f(j);
                let l = ((() => {
                    let $ret = new PathFigure();
                    $ret.isClosed = false;
                    $ret.isFilled = false;
                    $ret.startPoint = k._inner[0];
                    return $ret;
                })());
                l._segments.add(((() => {
                    let $ret = new PolyLineSegment();
                    $ret.points = k;
                    return $ret;
                })()));
                h.c.add(l);
            }
            this.bw.item(c).ak = h;
            if (this.bw.item(c).dataContext != null) {
                this.bw.item(c).dataContext.item = f;
            }
            if (d != null) {
                let m = d.getBrushByValue(f, this.bv.nm);
                if (m == null) {
                    m = this.e.k3;
                }
                this.bx.add(m);
            }
            else {
                this.bx.add(this.e.k3);
            }
            c++;
        }
        this.bw.count = c;
        this.an();
    }
    bb(a, b) {
        super.bb(a, b);
        let c = a;
        c._stroke = this.bx._inner[b];
        c.ac = this.e.ey;
        if (c.y != null) {
            this.h.i(c, c.y);
        }
    }
    bc(a, b) {
        super.bc(a, b);
        let c = a;
        let d = this.bm(b);
        c._stroke = d;
        c.ac = this.e.ey + 3;
    }
    a3(a, b) {
        super.a3(a, b);
        for (let c = 0; c < this.by.count; c++) {
            let d = this.by._inner[c];
            if (d._visibility != 1) {
                this.ba(d, c, b);
                a.s(d);
            }
        }
    }
    b0(a) {
        this.bw.count = 0;
        this.an();
    }
    ai(a) {
        super.ai(a);
        let b = new List$1(Tuple$2.$.specialize(Number_$type, Path.$), 0);
        if (this.bu != null) {
            for (let c = 0; c < this.bw.count; c++) {
                b.add(new Tuple$2(Number_$type, Path.$, this.bu[c], this.bw.item(c)));
            }
        }
        b.aa((d, e) => {
            if (d.c < e.c) {
                return -1;
            }
            else if (d.c > e.c) {
                return 1;
            }
            return 0;
        });
        for (let d = 0; d < b.count; d++) {
            let e = typeCast(Path.$, b._inner[d].d);
            if (e._visibility != 1) {
                this.e.a2.exportPathData(a, e, "contour" + d, ["Main "]);
            }
        }
    }
    getDefaultTooltipTemplate() {
        let a = "<div class='ui-chart-default-tooltip-content'><span";
        let b = this.e.a0.a$q(this.e);
        if (!stringIsNullOrEmpty(b)) {
            a += " style='color:" + b + "'";
        }
        a += ">" + this.bv.fx + "</span><br/>";
        if (!stringIsNullOrEmpty(this.bv.np)) {
            a += "<span>Value: ${item}</span>";
        }
        a += "</div>";
        return a;
    }
    b4(a, b) {
        for (let c = 0; c < this.by.count; c++) {
            let d = this.by._inner[c];
            let e = typeCast(PathGeometry.$, d.ak);
            if (e != null) {
                for (let f = 0; f < e.c.count; f++) {
                    let g = e.c._inner[f];
                    let h = e.c._inner[f]._startPoint;
                    for (let i = 0; i < g._segments.count; i++) {
                        let j = typeCast(PolyLineSegment.$, g._segments._inner[i]);
                        if (j != null) {
                            let k = this.bv.ey / 2 + this.bv.ee(b);
                            if (j._points.count > 0 && GeometryUtil.b(a, h, j._points, k)) {
                                return d;
                            }
                        }
                    }
                }
            }
        }
        return null;
    }
}
ScatterContourSeriesView.$t = markType(ScatterContourSeriesView, 'ScatterContourSeriesView', SeriesView.$);
//# sourceMappingURL=ScatterContourSeries_combined.js.map