/*
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.pt = null;
            this.py = null;
            this.pr = null;
            this.ps = null;
            this.pq = [Color.u(255, 0, 0, 255), Color.u(255, 0, 255, 0), Color.u(255, 255, 0, 0)];
            FastItemIntColumn.m();
            this.ab = ScatterAreaSeries.$;
        }
        get pu() {
            return this.pt;
        }
        set pu(a) {
            let b = this.pt != a;
            if (b) {
                let c = this.pt;
                if (this.pt != null) {
                    let d = this.pt;
                    d.propertyChanged = delegateRemove(d.propertyChanged, runOn(this, this.p7));
                }
                this.pt = a;
                if (this.pt != null) {
                    let e = this.pt;
                    e.propertyChanged = delegateCombine(e.propertyChanged, runOn(this, this.p7));
                }
                this.raisePropertyChanged("ColorScale", c, this.pt);
            }
        }
        p7(a, b) {
            this.k3(false);
        }
        gt(a, b) {
            let c = this.ic(b);
            if (c == ScatterAreaSeries.$$p[0]) {
                return this.gu(a, b, this.p2);
            }
            return super.gt(a, b);
        }
        get pz() {
            return this.py;
        }
        set pz(a) {
            let b = this.pz != a;
            if (b) {
                let c = this.pz;
                this.py = a;
                this.raisePropertyChanged("ColorColumn", c, this.pz);
            }
        }
        get_d6() {
            return true;
        }
        set_d6(a) {
            super.set_d6(a);
        }
        kp(a, b, c, d) {
            super.kp(a, b, c, d);
            switch (b) {
                case "FastItemsSource":
                    let e = typeCast(IFastItemsSource_$type, c);
                    if (e != null) {
                        e.deregisterColumn(this.pz);
                        this.pz = null;
                    }
                    let f = typeCast(IFastItemsSource_$type, d);
                    if (f != null) {
                        this.pz = this.ca(this.p2);
                    }
                    this.k3(false);
                    break;
                case ScatterAreaSeries.$$p[0]:
                    if (this.cd != null) {
                        this.cd.deregisterColumn(this.pz);
                        this.pz = this.ca(this.p2);
                    }
                    this.k3(false);
                    this.ka();
                    break;
                case "ColorScale":
                    this.k3(false);
                    this.ka();
                    break;
            }
        }
        k4(a) {
            super.k4(a);
            this.p8(this.bs);
        }
        k2(a, b, c, d, e) {
            super.k2(a, b, c, d, e);
            let f = this.a3.a$h.item(d);
            f.a1(c);
            if (this.cp(f)) {
                return;
            }
            this.p8(f);
        }
        p8(a) {
            if (this.cp(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.n9;
            let i = this.oa;
            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.px(a, k, l);
            if (g != null) {
                e.b8(g);
            }
            else {
                e.cb(f);
            }
        }
        p5(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.b0;
            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.b0 = f;
        }
        gq(a) {
            let b = truncate(Math.round(this.n6.width));
            let c = truncate(Math.round(this.n6.height));
            let d = this.bs.b0;
            if (d == null || d.length != (b * c) || this.oj == null || this.oj.count < 1 || this.ok == null || this.ok.count < 1 || this.ol == null || this.ol.count < 1) {
                return null;
            }
            let e = this.b6.o8;
            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.oj.count) {
                return null;
            }
            let l = this.pr.length;
            let m = this.oj.item(k);
            let n = this.ok.item(k);
            let o = this.ol.item(k);
            if ((m >= l) || (n >= l) || (o >= l)) {
                return null;
            }
            let p = (this.pr[m] - this.n6.left) / this.n6.width;
            let q = (this.ps[m] - this.n6.top) / this.n6.height;
            let r = (this.pr[n] - this.n6.left) / this.n6.width;
            let s = (this.ps[n] - this.n6.top) / this.n6.height;
            let t = (this.pr[o] - this.n6.left) / this.n6.width;
            let u = (this.ps[o] - this.n6.top) / this.n6.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.cd.item(m);
            }
            if (w < v && w < x) {
                return this.cd.item(n);
            }
            if (x < v && x < w) {
                return this.cd.item(o);
            }
            return this.cd.item(m);
        }
        px(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.fa();
            let g = a;
            let h = this.n9;
            let i = this.oa;
            let j = this.oj.count;
            let k;
            let xArr_ = this.om.asArray();
            k = (xArr_.slice(0));
            let l;
            let yArr_ = this.on.asArray();
            l = (yArr_.slice(0));
            let m = this.pz.asArray();
            let n = this.oj.asArray();
            let o = this.ok.asArray();
            let p = this.ol.asArray();
            this.pr = k;
            this.ps = l;
            h.gt(boxArray$1(k), 0, k.length, b);
            i.gt(boxArray$1(l), 0, l.length, c);
            let q = this.pv();
            let r = g.b2(b.d, q, this.pz);
            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.p5(g);
            let aa = g.b0;
            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;
        }
        p0() {
            let a = new Color();
            let b = this.m9;
            if (b == null) {
                a = this.pq[this.gi % this.pq.length];
            }
            else {
                a = ColorUtil.q(b);
            }
            let c = new ObservableColorCollection();
            c.add(ColorUtil.v(a, -0.5));
            c.add(a);
            return c;
        }
        pv() {
            let a = this.pu;
            if (a == null) {
                a = ((() => {
                    let $ret = new CustomPaletteColorScale();
                    $ret.palette = this.p0();
                    $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.p0();
                }
                a = b;
            }
            return a;
        }
        jl(a, b) {
            super.jl(a, b);
            let c = b;
            c.b7();
        }
        bp() {
            return new ScatterAreaSeriesView(this);
        }
        kk(a) {
            super.kk(a);
            this.pw = typeCast(ScatterAreaSeriesView.$, a);
        }
        p6(a) {
            if (this.pw != null) {
                this.pw.b6(a);
            }
        }
    }
    ScatterAreaSeries.$t = /*@__PURE__*/ markType(ScatterAreaSeries, 'ScatterAreaSeries', ScatterTriangulationSeries.$);
    ScatterAreaSeries.$$p = /*@__PURE__*/ markDep(DependencyProperty, PropertyMetadata, ScatterAreaSeries, 'raisePropertyChanged', ['ColorMemberPath:p2:p9', [2, null]]);
    return ScatterAreaSeries;
})();
/**
 * @hidden
 */
export let ScatterAreaSeriesView = /*@__PURE__*/ (() => {
    class ScatterAreaSeriesView extends SeriesView {
        constructor(a) {
            super(a);
            this.b1 = null;
            this.bx = null;
            this.b5 = null;
            this.b4 = null;
            this.b3 = null;
            this.b1 = a;
        }
        get b0() {
            return this.bx;
        }
        set b0(a) {
            this.bx = a;
        }
        ca(a, b) {
        }
        b6(a) {
        }
        by() {
            return this.bz(true);
        }
        bz(a) {
            this.b9();
            let b = truncate(Math.round(this.bu.left));
            let c = truncate(Math.round(this.bu.left));
            let d = truncate(Math.round(this.bu.width));
            let e = truncate(Math.round(this.bu.height));
            let f = d.toString();
            let g = e.toString();
            if (this.b4.getAttribute("width") != f) {
                this.b4.setAttribute("width", d.toString());
            }
            if (this.b4.getAttribute("height") != g) {
                this.b4.setAttribute("height", e.toString());
            }
            let h = this.b3.g();
            if (a) {
                h.clearRect(0, 0, d, e);
            }
            this.b5 = h.getImageData(0, 0, d, e);
            let imageDataArray_ = this.b5.data;
            return imageDataArray_;
        }
        b9() {
            if (this.b4 == null) {
                this.b4 = this.e.f5.createElement("canvas");
                let a = this.e.f5.get2DCanvasContext(this.b4);
                this.b3 = new RenderingContext(new CanvasViewRenderer(), a);
            }
        }
        b2(a, b, c) {
            let d = truncate(Math.round(this.bu.left));
            let e = truncate(Math.round(this.bu.left));
            let f = truncate(Math.round(this.bu.width));
            let g = truncate(Math.round(this.bu.height));
            return new TriangleRasterizer(this.by(), b, c.minimum, c.maximum, c, f, g);
        }
        b8(a) {
            this.cb(null);
        }
        b7() {
            if (this.b3 != null) {
                this.b3.k(this.bu.left, this.bu.top, this.bu.width, this.bu.height);
            }
            this.aq();
        }
        a6(a, b) {
            super.a6(a, b);
            if (this.b4 == null) {
                return;
            }
            if (b) {
                let c = new Rectangle();
                c.n = this.bu.left;
                c.o = this.bu.top;
                c.width = this.bu.width;
                c.height = this.bu.height;
                c._fill = this.bo();
                a.v(c);
            }
            else {
                let d = truncate(Math.round(this.bu.left));
                let e = truncate(Math.round(this.bu.top));
                let f = truncate(Math.round(this.bu.width));
                let g = truncate(Math.round(this.bu.height));
                a.m(this.b4.getNativeElement(), 1, d, e, f, g);
            }
        }
        cb(a) {
            let b = truncate(Math.round(this.bu.left));
            let c = truncate(Math.round(this.bu.left));
            let d = truncate(Math.round(this.bu.width));
            let e = truncate(Math.round(this.bu.height));
            this.b9();
            this.b3.g().putImageData(this.b5, 0, 0);
            this.aq();
        }
        al(a) {
            super.al(a);
            let b = truncate(Math.round(this.bu.width));
            let c = truncate(Math.round(this.bu.height));
            let d = this.bz(false);
            if (d == null || d.length == 0) {
                this.e.a5.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.a5.exportSeriesPixelsData(a, e, b, c);
        }
        getDefaultTooltipTemplate() {
            let a = "<div class='ui-chart-default-tooltip-content'><span";
            let b = this.e.a3.a$r(this.e);
            if (!stringIsNullOrEmpty(b)) {
                a += " style='color:" + b + "'";
            }
            a += ">" + this.b1.gy + "</span><br/><span>" + "(${item." + this.b1.o7 + "}, ${item." + this.b1.pb + "})</span>";
            if (!stringIsNullOrEmpty(this.b1.p2)) {
                a += "<span>, Value: ${item." + this.b1.p2 + "}</span>";
            }
            a += "</div>";
            return a;
        }
    }
    ScatterAreaSeriesView.$t = /*@__PURE__*/ markType(ScatterAreaSeriesView, 'ScatterAreaSeriesView', SeriesView.$);
    return ScatterAreaSeriesView;
})();
//# sourceMappingURL=ScatterAreaSeries_combined.js.map
