/*
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-react-core";
import { DependencyProperty } from "igniteui-react-core";
import { Color } from "igniteui-react-core";
import { FastItemIntColumn } from "igniteui-react-core";
import { IFastItemsSource_$type } from "igniteui-react-core";
import { Rect } from "igniteui-react-core";
import { SeriesView } from "./SeriesView";
import { TriangleRasterizer } from "./TriangleRasterizer";
import { ScalerParams } from "./ScalerParams";
import { ObservableColorCollection } from "igniteui-react-core";
import { ColorUtil } from "igniteui-react-core";
import { CustomPaletteColorScale } from "./CustomPaletteColorScale";
import { PropertyMetadata } from "igniteui-react-core";
import { truncate, intDivide } from "igniteui-react-core";
import { boxArray$1 } from "igniteui-react-core";
import { RenderingContext } from "igniteui-react-core";
import { CanvasViewRenderer } from "igniteui-react-core";
import { Rectangle } from "igniteui-react-core";
import { stringIsNullOrEmpty } from "igniteui-react-core";
/**
 * @hidden
 */
export let ScatterAreaSeries = /*@__PURE__*/ (() => {
    class ScatterAreaSeries extends ScatterTriangulationSeries {
        constructor() {
            super();
            this.nu = null;
            this.nz = null;
            this.ns = null;
            this.nt = null;
            this.nr = [Color.u(255, 0, 0, 255), Color.u(255, 0, 255, 0), Color.u(255, 255, 0, 0)];
            FastItemIntColumn.m();
            this.ab = ScatterAreaSeries.$;
        }
        get nv() {
            return this.nu;
        }
        set nv(a) {
            let b = this.nu != a;
            if (b) {
                let c = this.nu;
                if (this.nu != null) {
                    let d = this.nu;
                    d.propertyChanged = delegateRemove(d.propertyChanged, runOn(this, this.n8));
                }
                this.nu = a;
                if (this.nu != null) {
                    let e = this.nu;
                    e.propertyChanged = delegateCombine(e.propertyChanged, runOn(this, this.n8));
                }
                this.raisePropertyChanged("ColorScale", c, this.nu);
            }
        }
        n8(a, b) {
            this.jl(false);
        }
        fs(a, b) {
            let c = this.g2(b);
            if (c == ScatterAreaSeries.$$p[0]) {
                return this.ft(a, b, this.n3);
            }
            return super.fs(a, b);
        }
        get n0() {
            return this.nz;
        }
        set n0(a) {
            let b = this.n0 != a;
            if (b) {
                let c = this.n0;
                this.nz = a;
                this.raisePropertyChanged("ColorColumn", c, this.n0);
            }
        }
        get_dq() {
            return true;
        }
        set_dq(a) {
            super.set_dq(a);
        }
        i7(a, b, c, d) {
            super.i7(a, b, c, d);
            switch (b) {
                case "FastItemsSource":
                    let e = typeCast(IFastItemsSource_$type, c);
                    if (e != null) {
                        e.deregisterColumn(this.n0);
                        this.n0 = null;
                    }
                    let f = typeCast(IFastItemsSource_$type, d);
                    if (f != null) {
                        this.n0 = this.bw(this.n3);
                    }
                    this.jl(false);
                    break;
                case ScatterAreaSeries.$$p[0]:
                    if (this.bz != null) {
                        this.bz.deregisterColumn(this.n0);
                        this.n0 = this.bw(this.n3);
                    }
                    this.jl(false);
                    this.it();
                    break;
                case "ColorScale":
                    this.jl(false);
                    this.it();
                    break;
            }
        }
        jm(a) {
            super.jm(a);
            this.n9(this.bi);
        }
        jk(a, b, c, d, e) {
            super.jk(a, b, c, d, e);
            let f = this.a0.a$h.item(d);
            f.ay(c);
            if (this.cc(f)) {
                return;
            }
            this.n9(f);
        }
        n9(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.ma;
            let i = this.mb;
            let j = this.getEffectiveViewport1(a);
            let k = new ScalerParams(1, b, c, h.ca);
            k.c = j;
            let l = new ScalerParams(1, b, c, i.ca);
            l.c = j;
            g = this.ny(a, k, l);
            if (g != null) {
                e.b5(g);
            }
            else {
                e.b8(f);
            }
        }
        n6(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.l8.width));
            let c = truncate(Math.round(this.l8.height));
            let d = this.bi.bx;
            if (d == null || d.length != (b * c) || this.mk == null || this.mk.count < 1 || this.ml == null || this.ml.count < 1 || this.mm == null || this.mm.count < 1) {
                return null;
            }
            let e = this.bs.oi;
            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.mk.count) {
                return null;
            }
            let l = this.ns.length;
            let m = this.mk.item(k);
            let n = this.ml.item(k);
            let o = this.mm.item(k);
            if ((m >= l) || (n >= l) || (o >= l)) {
                return null;
            }
            let p = (this.ns[m] - this.l8.left) / this.l8.width;
            let q = (this.nt[m] - this.l8.top) / this.l8.height;
            let r = (this.ns[n] - this.l8.left) / this.l8.width;
            let s = (this.nt[n] - this.l8.top) / this.l8.height;
            let t = (this.ns[o] - this.l8.left) / this.l8.width;
            let u = (this.nt[o] - this.l8.top) / this.l8.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);
        }
        ny(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.ma;
            let i = this.mb;
            let j = this.mk.count;
            let k;
            let xArr_ = this.mn.asArray();
            k = (xArr_.slice(0));
            let l;
            let yArr_ = this.mo.asArray();
            l = (yArr_.slice(0));
            let m = this.n0.asArray();
            let n = this.mk.asArray();
            let o = this.ml.asArray();
            let p = this.mm.asArray();
            this.ns = k;
            this.nt = l;
            h.gs(boxArray$1(k), 0, k.length, b);
            i.gs(boxArray$1(l), 0, l.length, c);
            let q = this.nw();
            let r = g.bz(b.d, q, this.n0);
            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.n6(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;
        }
        n1() {
            let a = new Color();
            let b = this.lb;
            if (b == null) {
                a = this.nr[this.fh % this.nr.length];
            }
            else {
                a = ColorUtil.j(b);
            }
            let c = new ObservableColorCollection();
            c.add(ColorUtil.o(a, -0.5));
            c.add(a);
            return c;
        }
        nw() {
            let a = this.nv;
            if (a == null) {
                a = ((() => {
                    let $ret = new CustomPaletteColorScale();
                    $ret.palette = this.n1();
                    $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.n1();
                }
                a = b;
            }
            return a;
        }
        h3(a, b) {
            super.h3(a, b);
            let c = b;
            c.b4();
        }
        bf() {
            return new ScatterAreaSeriesView(this);
        }
        i2(a) {
            super.i2(a);
            this.nx = typeCast(ScatterAreaSeriesView.$, a);
        }
        n7(a) {
            if (this.nx != null) {
                this.nx.b3(a);
            }
        }
    }
    ScatterAreaSeries.$t = /*@__PURE__*/ markType(ScatterAreaSeries, 'ScatterAreaSeries', ScatterTriangulationSeries.$);
    ScatterAreaSeries.$$p = /*@__PURE__*/ markDep(DependencyProperty, PropertyMetadata, ScatterAreaSeries, 'raisePropertyChanged', ['ColorMemberPath:n3:oa', [2, null]]);
    return ScatterAreaSeries;
})();
/**
 * @hidden
 */
export let ScatterAreaSeriesView = /*@__PURE__*/ (() => {
    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.m8 + "}, ${item." + this.by.nc + "})</span>";
            if (!stringIsNullOrEmpty(this.by.n3)) {
                a += "<span>, Value: ${item." + this.by.n3 + "}</span>";
            }
            a += "</div>";
            return a;
        }
    }
    ScatterAreaSeriesView.$t = /*@__PURE__*/ markType(ScatterAreaSeriesView, 'ScatterAreaSeriesView', SeriesView.$);
    return ScatterAreaSeriesView;
})();
//# sourceMappingURL=ScatterAreaSeries_combined.js.map
