/*
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 { runOn, delegateRemove, delegateCombine, typeCast, Point_$type, markType, markDep } from "igniteui-angular-core";
import { DependencyProperty } from "igniteui-angular-core";
import { Color } from "igniteui-angular-core";
import { FastItemIntColumn } from "igniteui-angular-core";
import { IFastItemsSource_$type } from "igniteui-angular-core";
import { Rect } from "igniteui-angular-core";
import { SeriesView } from "./SeriesView";
import { TriangleRasterizer } from "./TriangleRasterizer";
import { ScalerParams } from "./ScalerParams";
import { ObservableColorCollection } from "igniteui-angular-core";
import { ColorUtil } from "igniteui-angular-core";
import { CustomPaletteColorScale } from "./CustomPaletteColorScale";
import { PropertyMetadata } from "igniteui-angular-core";
import { truncate, intDivide } from "igniteui-angular-core";
import { boxArray$1 } from "igniteui-angular-core";
import { RenderingContext } from "igniteui-angular-core";
import { CanvasViewRenderer } from "igniteui-angular-core";
import { Rectangle } from "igniteui-angular-core";
import { stringIsNullOrEmpty } from "igniteui-angular-core";
/**
 * @hidden
 */
export class ScatterAreaSeries extends ScatterTriangulationSeries {
    constructor() {
        super();
        this.nk = null;
        this.np = null;
        this.ni = null;
        this.nj = null;
        this.nh = [Color.u(255, 0, 0, 255), Color.u(255, 0, 255, 0), Color.u(255, 255, 0, 0)];
        FastItemIntColumn.m();
        this.ab = ScatterAreaSeries.$;
    }
    get nl() {
        return this.nk;
    }
    set nl(a) {
        let b = this.nk != a;
        if (b) {
            let c = this.nk;
            if (this.nk != null) {
                let d = this.nk;
                d.propertyChanged = delegateRemove(d.propertyChanged, runOn(this, this.ny));
            }
            this.nk = a;
            if (this.nk != null) {
                let e = this.nk;
                e.propertyChanged = delegateCombine(e.propertyChanged, runOn(this, this.ny));
            }
            this.raisePropertyChanged("ColorScale", c, this.nk);
        }
    }
    ny(a, b) {
        this.jd(false);
    }
    fs(a, b) {
        let c = this.gu(b);
        if (c == ScatterAreaSeries.$$p[0]) {
            return this.ft(a, b, this.nt);
        }
        return super.fs(a, b);
    }
    get nq() {
        return this.np;
    }
    set nq(a) {
        let b = this.nq != a;
        if (b) {
            let c = this.nq;
            this.np = a;
            this.raisePropertyChanged("ColorColumn", c, this.nq);
        }
    }
    get_dq() {
        return true;
    }
    set_dq(a) {
        super.set_dq(a);
    }
    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.nq);
                    this.nq = null;
                }
                let f = typeCast(IFastItemsSource_$type, d);
                if (f != null) {
                    this.nq = this.bw(this.nt);
                }
                this.jd(false);
                break;
            case ScatterAreaSeries.$$p[0]:
                if (this.bz != null) {
                    this.bz.deregisterColumn(this.nq);
                    this.nq = this.bw(this.nt);
                }
                this.jd(false);
                this.ik();
                break;
            case "ColorScale":
                this.jd(false);
                this.ik();
                break;
        }
    }
    je(a) {
        super.je(a);
        this.nz(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.nz(f);
    }
    nz(a) {
        if (this.cc(a)) {
            return;
        }
        let b;
        let c;
        let d = a.getViewInfo(c, b);
        c = d.p0;
        b = d.p1;
        let e = a;
        let f = null;
        let g = null;
        let h = this.l0;
        let i = this.l1;
        let j = this.getEffectiveViewport1(a);
        let k = new ScalerParams(1, b, c, h.b8);
        k.c = j;
        let l = new ScalerParams(1, b, c, i.b8);
        l.c = j;
        g = this.no(a, k, l);
        if (g != null) {
            e.b5(g);
        }
        else {
            e.b8(f);
        }
    }
    nw(a) {
        let b;
        let c;
        let d = a.getViewInfo(b, c);
        b = d.p0;
        c = d.p1;
        let e = truncate(Math.round(b.width)) * truncate(Math.round(b.height));
        let f = a.bx;
        if (f == null || f.length != e) {
            f = new Array(e);
            for (let g = 0; g < e; g++) {
                f[g] = 0;
            }
        }
        else {
            for (let h = 0; h < e; h++) {
                f[h] = 0;
            }
        }
        a.bx = f;
    }
    fp(a) {
        let b = truncate(Math.round(this.ly.width));
        let c = truncate(Math.round(this.ly.height));
        let d = this.bi.bx;
        if (d == null || d.length != (b * c) || this.ma == null || this.ma.count < 1 || this.mb == null || this.mb.count < 1 || this.mc == null || this.mc.count < 1) {
            return null;
        }
        let e = this.bs.m4;
        let f = (a.x - e.left) / e.width;
        let g = (a.y - e.top) / e.height;
        let h = truncate(Math.round(b * f));
        let i = truncate(Math.round(c * g));
        let j = (b * i) + h;
        if (j < 0 || j > d.length - 1) {
            return null;
        }
        let k = d[j] - 1;
        if (k < 0 || k > this.ma.count) {
            return null;
        }
        let l = this.ni.length;
        let m = this.ma.item(k);
        let n = this.mb.item(k);
        let o = this.mc.item(k);
        if ((m >= l) || (n >= l) || (o >= l)) {
            return null;
        }
        let p = (this.ni[m] - this.ly.left) / this.ly.width;
        let q = (this.nj[m] - this.ly.top) / this.ly.height;
        let r = (this.ni[n] - this.ly.left) / this.ly.width;
        let s = (this.nj[n] - this.ly.top) / this.ly.height;
        let t = (this.ni[o] - this.ly.left) / this.ly.width;
        let u = (this.nj[o] - this.ly.top) / this.ly.height;
        let v = Math.pow(p - f, 2) + Math.pow(q - g, 2);
        let w = Math.pow(r - f, 2) + Math.pow(s - g, 2);
        let x = Math.pow(t - f, 2) + Math.pow(u - g, 2);
        if (v < w && v < x) {
            return this.bz.item(m);
        }
        if (w < v && w < x) {
            return this.bz.item(n);
        }
        if (x < v && x < w) {
            return this.bz.item(o);
        }
        return this.bz.item(m);
    }
    no(a, b, c) {
        let d;
        let e;
        let f = a.getViewInfo(e, d);
        e = f.p0;
        d = f.p1;
        e = new Rect(0, 0, 0, e.width, e.height);
        b = new ScalerParams(0, b.e, e, b.a, b.c);
        c = new ScalerParams(0, c.e, e, c.a, c.c);
        c.b = this.eh();
        let g = 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.nq.asArray();
        let n = this.ma.asArray();
        let o = this.mb.asArray();
        let p = this.mc.asArray();
        this.ni = k;
        this.nj = l;
        h.gn(boxArray$1(k), 0, k.length, b);
        i.gn(boxArray$1(l), 0, l.length, c);
        let q = this.nm();
        let r = g.bz(b.d, q, this.nq);
        let s = e.top;
        let t = e.left;
        let u = e.right;
        let v = e.bottom;
        let w;
        let x;
        let y;
        let z;
        this.nw(g);
        let aa = g.bx;
        let ab = k.length;
        for (let ac = 0; ac < j; ac++) {
            let ad = n[ac];
            let ae = o[ac];
            let af = p[ac];
            if ((ad >= ab) || (ae >= ab) || (af >= ab) || (ad < 0) || (ae < 0) || (af < 0)) {
                continue;
            }
            let ag = k[ad];
            let ah = l[ad];
            let ai = { $type: Point_$type, x: ag, y: ah };
            let aj = k[ae];
            let ak = l[ae];
            let al = { $type: Point_$type, x: aj, y: ak };
            let am = k[af];
            let an = l[af];
            let ao = { $type: Point_$type, x: am, y: an };
            w = al.y < ao.y ? al.y : ao.y;
            w = ai.y < w ? ai.y : w;
            x = al.y > ao.y ? al.y : ao.y;
            x = ai.y > x ? ai.y : x;
            y = al.x < ao.x ? al.x : ao.x;
            y = ai.x < y ? ai.x : y;
            z = al.x > ao.x ? al.x : ao.x;
            z = ai.x > z ? ai.x : z;
            if (w < v && x > s && y < u && z > t) {
                let ap = m[ad];
                let aq = m[ae];
                let ar = m[af];
                r.p(ac, aa, ai, al, ao, ap, aq, ar);
            }
        }
        return r;
    }
    nr() {
        let a = new Color();
        let b = this.k3;
        if (b == null) {
            a = this.nh[this.fh % this.nh.length];
        }
        else {
            a = ColorUtil.j(b);
        }
        let c = new ObservableColorCollection();
        c.add(ColorUtil.o(a, -0.5));
        c.add(a);
        return c;
    }
    nm() {
        let a = this.nl;
        if (a == null) {
            a = ((() => {
                let $ret = new CustomPaletteColorScale();
                $ret.palette = this.nr();
                $ret.interpolationMode = 2;
                return $ret;
            })());
        }
        else if (typeCast(CustomPaletteColorScale.$, a) !== null) {
            let b = a;
            if (b.palette == null || b.palette.count == 0) {
                b.palette = this.nr();
            }
            a = b;
        }
        return a;
    }
    hv(a, b) {
        super.hv(a, b);
        let c = b;
        c.b4();
    }
    bf() {
        return new ScatterAreaSeriesView(this);
    }
    iu(a) {
        super.iu(a);
        this.nn = typeCast(ScatterAreaSeriesView.$, a);
    }
    nx(a) {
        if (this.nn != null) {
            this.nn.b3(a);
        }
    }
}
ScatterAreaSeries.$t = markType(ScatterAreaSeries, 'ScatterAreaSeries', ScatterTriangulationSeries.$);
ScatterAreaSeries.$$p = markDep(DependencyProperty, PropertyMetadata, ScatterAreaSeries, 'raisePropertyChanged', ['ColorMemberPath:nt:n0', [2, null]]);
/**
 * @hidden
 */
export class ScatterAreaSeriesView extends SeriesView {
    constructor(a) {
        super(a);
        this.by = null;
        this.bu = null;
        this.b2 = null;
        this.b1 = null;
        this.b0 = null;
        this.by = a;
    }
    get bx() {
        return this.bu;
    }
    set bx(a) {
        this.bu = a;
    }
    b7(a, b) {
    }
    b3(a) {
    }
    bv() {
        return this.bw(true);
    }
    bw(a) {
        this.b6();
        let b = truncate(Math.round(this.br.left));
        let c = truncate(Math.round(this.br.left));
        let d = truncate(Math.round(this.br.width));
        let e = truncate(Math.round(this.br.height));
        let f = d.toString();
        let g = e.toString();
        if (this.b1.getAttribute("width") != f) {
            this.b1.setAttribute("width", d.toString());
        }
        if (this.b1.getAttribute("height") != g) {
            this.b1.setAttribute("height", e.toString());
        }
        let h = this.b0.g();
        if (a) {
            h.clearRect(0, 0, d, e);
        }
        this.b2 = h.getImageData(0, 0, d, e);
        let imageDataArray_ = this.b2.data;
        return imageDataArray_;
    }
    b6() {
        if (this.b1 == null) {
            this.b1 = this.e.e4.createElement("canvas");
            let a = this.e.e4.get2DCanvasContext(this.b1);
            this.b0 = new RenderingContext(new CanvasViewRenderer(), a);
        }
    }
    bz(a, b, c) {
        let d = truncate(Math.round(this.br.left));
        let e = truncate(Math.round(this.br.left));
        let f = truncate(Math.round(this.br.width));
        let g = truncate(Math.round(this.br.height));
        return new TriangleRasterizer(this.bv(), b, c.minimum, c.maximum, c, f, g);
    }
    b5(a) {
        this.b8(null);
    }
    b4() {
        if (this.b0 != null) {
            this.b0.k(this.br.left, this.br.top, this.br.width, this.br.height);
        }
        this.an();
    }
    a3(a, b) {
        super.a3(a, b);
        if (this.b1 == null) {
            return;
        }
        if (b) {
            let c = new Rectangle();
            c.n = this.br.left;
            c.o = this.br.top;
            c.width = this.br.width;
            c.height = this.br.height;
            c._fill = this.bl();
            a.v(c);
        }
        else {
            let d = truncate(Math.round(this.br.left));
            let e = truncate(Math.round(this.br.top));
            let f = truncate(Math.round(this.br.width));
            let g = truncate(Math.round(this.br.height));
            a.m(this.b1.getNativeElement(), 1, d, e, f, g);
        }
    }
    b8(a) {
        let b = truncate(Math.round(this.br.left));
        let c = truncate(Math.round(this.br.left));
        let d = truncate(Math.round(this.br.width));
        let e = truncate(Math.round(this.br.height));
        this.b6();
        this.b0.g().putImageData(this.b2, 0, 0);
        this.an();
    }
    ai(a) {
        super.ai(a);
        let b = truncate(Math.round(this.br.width));
        let c = truncate(Math.round(this.br.height));
        let d = this.bw(false);
        if (d == null || d.length == 0) {
            this.e.a2.exportSeriesPixelsData(a, null, b, c);
            return;
        }
        let e = new Array(intDivide(d.length, 4));
        let f;
        for (let g = 0; g < intDivide(d.length, 4); g++) {
            f = g * 4;
            e[g] = d[f + 3] << 24 | d[f] << 16 | d[f + 1] << 8 | d[f + 2];
        }
        this.e.a2.exportSeriesPixelsData(a, e, b, c);
    }
    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.by.fx + "</span><br/><span>" + "(${item." + this.by.my + "}, ${item." + this.by.m2 + "})</span>";
        if (!stringIsNullOrEmpty(this.by.nt)) {
            a += "<span>, Value: ${item." + this.by.nt + "}</span>";
        }
        a += "</div>";
        return a;
    }
}
ScatterAreaSeriesView.$t = markType(ScatterAreaSeriesView, 'ScatterAreaSeriesView', SeriesView.$);
//# sourceMappingURL=ScatterAreaSeries_combined.js.map