/*
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 { ColorScale } from "./ColorScale";
import { runOn, delegateRemove, delegateCombine, typeCast, Point_$type, markType, markDep } from "igniteui-react-core";
import { DependencyProperty } 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 { Color } from "igniteui-react-core";
import { ColorUtil } from "igniteui-react-core";
import { List$1 } from "igniteui-react-core";
import { CustomPaletteColorScale } from "./CustomPaletteColorScale";
import { DataLegendSeriesValueInfo } from "igniteui-react-core";
import { DataLegendSeriesContext } from "igniteui-react-core";
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 {
        bi() {
            return new ScatterAreaSeries();
        }
        get_es() {
            return true;
        }
        constructor() {
            super();
            this.yk = null;
            this.yp = null;
            this.yi = null;
            this.yj = null;
            FastItemIntColumn.m();
            this.ab = ScatterAreaSeries.$;
        }
        get ym() {
            return this.yk;
        }
        set ym(a) {
            let b = this.yk != a;
            if (b) {
                let c = this.yk;
                if (this.yk != null) {
                    let d = this.yk;
                    d.propertyChanged = delegateRemove(d.propertyChanged, runOn(this, this.y3));
                }
                this.yk = a;
                if (this.yk != null) {
                    let e = this.yk;
                    e.propertyChanged = delegateCombine(e.propertyChanged, runOn(this, this.y3));
                }
                this.raisePropertyChanged("ColorScale", c, this.yk);
            }
        }
        y3(a, b) {
            this.y5();
            this.rm(false);
        }
        ko(a, b) {
            let c = this.na(b);
            if (c == ScatterAreaSeries.$$p[3]) {
                return this.kp(a, b, this.yy);
            }
            return super.ko(a, b);
        }
        ma(a) {
            let b = this.na(a);
            if (b == ScatterAreaSeries.$$p[3]) {
                return this.yy;
            }
            return super.ma(a);
        }
        get yq() {
            return this.yp;
        }
        set yq(a) {
            let b = this.yq != a;
            if (b) {
                let c = this.yq;
                this.yp = a;
                this.raisePropertyChanged("ColorColumn", c, this.yq);
            }
        }
        get_g5() {
            return true;
        }
        set_g5(a) {
            super.set_g5(a);
        }
        q4(a, b, c, d) {
            super.q4(a, b, c, d);
            switch (b) {
                case ScatterAreaSeries.$$p[1]:
                case ScatterAreaSeries.$$p[2]:
                    this.qa();
                    break;
                case "FastItemsSource":
                    let e = typeCast(IFastItemsSource_$type, c);
                    if (e != null) {
                        e.deregisterColumn(this.yq);
                        this.yq = null;
                    }
                    let f = typeCast(IFastItemsSource_$type, d);
                    if (f != null) {
                        this.yq = this.di(this.yy);
                    }
                    this.rm(this.ge && c != null);
                    break;
                case ScatterAreaSeries.$$p[3]:
                    if (this.dl != null) {
                        this.dl.deregisterColumn(this.yq);
                        this.yq = this.di(this.yy);
                    }
                    this.rm(false);
                    this.qg();
                    break;
                case "ColorScale":
                    this.y5();
                    this.rm(false);
                    this.qg();
                    break;
            }
        }
        rn(a) {
            super.rn(a);
            this.y4(this.ct);
        }
        rl(a, b, c, d, e) {
            super.rl(a, b, c, d, e);
            let f = this.a9.a$j.item(d);
            f.a3(c);
            if (this.d3(f)) {
                return;
            }
            this.y4(f);
        }
        y4(a) {
            if (this.d3(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.wp;
            let i = this.wq;
            let j = this.getEffectiveViewport1(a);
            let k = new ScalerParams(1, b, c, h.ch);
            k.c = j;
            let l = new ScalerParams(1, b, c, i.ch);
            l.c = j;
            g = this.yo(a, k, l);
            if (g != null) {
                e.cb(g);
            }
            else {
                e.ce(f);
            }
        }
        y1(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.b3;
            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.b3 = f;
        }
        kl(a) {
            let b = truncate(Math.round(this.wk.width));
            let c = truncate(Math.round(this.wk.height));
            let d = this.ct.b3;
            if (d == null || d.length != (b * c) || this.wz == null || this.wz.count < 1 || this.w0 == null || this.w0.count < 1 || this.w1 == null || this.w1.count < 1) {
                return null;
            }
            let e = this.c9.v1;
            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.wz.count) {
                return null;
            }
            let l = this.yi.length;
            let m = this.wz.item(k);
            let n = this.w0.item(k);
            let o = this.w1.item(k);
            if ((m >= l) || (n >= l) || (o >= l)) {
                return null;
            }
            let p = (this.yi[m] - this.wk.left) / this.wk.width;
            let q = (this.yj[m] - this.wk.top) / this.wk.height;
            let r = (this.yi[n] - this.wk.left) / this.wk.width;
            let s = (this.yj[n] - this.wk.top) / this.wk.height;
            let t = (this.yi[o] - this.wk.left) / this.wk.width;
            let u = (this.yj[o] - this.wk.top) / this.wk.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.dl.item(m);
            }
            if (w < v && w < x) {
                return this.dl.item(n);
            }
            if (x < v && x < w) {
                return this.dl.item(o);
            }
            return this.dl.item(m);
        }
        yo(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.iw();
            let g = a;
            let h = this.wp;
            let i = this.wq;
            let j = this.wz.count;
            let k;
            let xArr_ = this.w2.asArray();
            k = (xArr_.slice(0));
            let l;
            let yArr_ = this.w3.asArray();
            l = (yArr_.slice(0));
            let m = this.yq.asArray();
            let n = this.wz.asArray();
            let o = this.w0.asArray();
            let p = this.w1.asArray();
            this.yi = k;
            this.yj = l;
            h.ho(boxArray$1(k), 0, k.length, b);
            i.ho(boxArray$1(l), 0, l.length, c);
            let q = this.yl;
            let r = g.b5(b.d, q, this.yq);
            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.y1(g);
            let aa = g.b3;
            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;
        }
        yr() {
            let a = new Color();
            let b = this.u2;
            if (b == null) {
                a = ColorUtil.t("#000000");
            }
            else {
                a = ColorUtil.s(b);
            }
            let c = new ObservableColorCollection();
            c.add(ColorUtil.x(a, -0.5));
            c.add(a);
            return c;
        }
        y5() {
            let a = this.ym;
            if (a == null) {
                a = ((() => {
                    let $ret = new CustomPaletteColorScale();
                    $ret.palette = this.yr();
                    $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.yr();
                }
                a = b;
            }
            let c = new ObservableColorCollection();
            if (typeCast(CustomPaletteColorScale.$, a) !== null) {
                c = a.palette;
            }
            else {
                c = this.yr();
            }
            this.yl = a;
        }
        sa() {
            super.sa();
            this.y5();
        }
        o2(a, b) {
            super.o2(a, b);
            let c = b;
            c.ca();
        }
        cq() {
            return new ScatterAreaSeriesView(this);
        }
        qw(a) {
            super.qw(a);
            this.yn = typeCast(ScatterAreaSeriesView.$, a);
        }
        y2(a) {
            if (this.yn != null) {
                this.yn.b9(a);
            }
        }
        getDataLegendSeriesContextAt(a, b) {
            let c = { $type: Point_$type, x: a, y: b };
            let d = this.kl(c);
            let e = d == null ? NaN : this.iv(d, "XMemberPath");
            let f = d == null ? NaN : this.iv(d, "YMemberPath");
            let g = d == null ? NaN : this.iv(d, "ColorMemberPath");
            let h = new DataLegendSeriesValueInfo();
            h.l = e;
            h.a = 13;
            h.q = "X";
            h.r = this.xr != null ? this.xr : "X";
            h.s = this.xn != null ? this.xn : "X:";
            h.t = this.xp != null ? this.xp : "";
            let i = new DataLegendSeriesValueInfo();
            i.l = f;
            i.a = 14;
            i.q = "Y";
            i.r = this.xz != null ? this.xz : "Y";
            i.s = this.xv != null ? this.xv : "Y:";
            i.t = this.xx != null ? this.xx : "";
            let j = new DataLegendSeriesValueInfo();
            j.l = g;
            j.a = 0;
            j.q = "Value";
            j.r = this.yy != null ? this.yy : "Value";
            j.s = this.yu != null ? this.yu : "V:";
            j.t = this.yw != null ? this.yw : "";
            let k = new DataLegendSeriesContext();
            k.e = ((() => {
                let $ret = new List$1(DataLegendSeriesValueInfo.$, 0);
                $ret.add(h);
                $ret.add(i);
                $ret.add(j);
                return $ret;
            })());
            k.h = this.l9();
            return k;
        }
    }
    ScatterAreaSeries.$t = /*@__PURE__*/ markType(ScatterAreaSeries, 'ScatterAreaSeries', ScatterTriangulationSeries.$);
    ScatterAreaSeries.$$p = /*@__PURE__*/ markDep(DependencyProperty, PropertyMetadata, ScatterAreaSeries, 'raisePropertyChanged', ['ActualColorScale:yl:y6', [ColorScale.$, null], 'ColorMemberAsLegendLabel:yu:y7', [2, null], 'ColorMemberAsLegendUnit:yw:y8', [2, null], 'ColorMemberPath:yy:y9', [2, null]]);
    return ScatterAreaSeries;
})();
/**
 * @hidden
 */
export let ScatterAreaSeriesView = /*@__PURE__*/ (() => {
    class ScatterAreaSeriesView extends SeriesView {
        get b3() {
            return this.b0;
        }
        set b3(a) {
            this.b0 = a;
        }
        constructor(a) {
            super(a);
            this.b4 = null;
            this.b0 = null;
            this.b8 = null;
            this.b7 = null;
            this.b6 = null;
            this.b4 = a;
        }
        cd(a, b) {
        }
        b9(a) {
        }
        b1() {
            return this.b2(true);
        }
        b2(a) {
            this.cc();
            let b = truncate(Math.round(this.bx.left));
            let c = truncate(Math.round(this.bx.left));
            let d = truncate(Math.round(this.bx.width));
            let e = truncate(Math.round(this.bx.height));
            let f = d.toString();
            let g = e.toString();
            if (this.b7.getAttribute("width") != f) {
                this.b7.setAttribute("width", d.toString());
            }
            if (this.b7.getAttribute("height") != g) {
                this.b7.setAttribute("height", e.toString());
            }
            let h = this.b6.h();
            if (a) {
                h.clearRect(0, 0, d, e);
            }
            this.b8 = h.getImageData(0, 0, d, e);
            let imageDataArray_ = this.b8.data;
            return imageDataArray_;
        }
        cc() {
            if (this.b7 == null) {
                this.b7 = this.e.jx.createElement("canvas");
                let a = this.e.jx.get2DCanvasContext(this.b7);
                this.b6 = new RenderingContext(new CanvasViewRenderer(), a);
            }
        }
        b5(a, b, c) {
            let d = truncate(Math.round(this.bx.left));
            let e = truncate(Math.round(this.bx.left));
            let f = truncate(Math.round(this.bx.width));
            let g = truncate(Math.round(this.bx.height));
            return new TriangleRasterizer(this.b1(), b, c.minimum, c.maximum, c, f, g);
        }
        cb(a) {
            this.ce(null);
        }
        ca() {
            if (this.b6 != null) {
                this.b6.l(this.bx.left, this.bx.top, this.bx.width, this.bx.height);
            }
            this.as();
        }
        a8(a, b) {
            super.a8(a, b);
            if (this.b7 == null) {
                return;
            }
            if (b) {
                let c = new Rectangle();
                c.n = this.bx.left;
                c.o = this.bx.top;
                c.width = this.bx.width;
                c.height = this.bx.height;
                c._fill = this.br();
                a.w(c);
            }
            else {
                let d = truncate(Math.round(this.bx.left));
                let e = truncate(Math.round(this.bx.top));
                let f = truncate(Math.round(this.bx.width));
                let g = truncate(Math.round(this.bx.height));
                a.n(this.b7.getNativeElement(), 1, d, e, f, g);
            }
        }
        ce(a) {
            let b = truncate(Math.round(this.bx.left));
            let c = truncate(Math.round(this.bx.left));
            let d = truncate(Math.round(this.bx.width));
            let e = truncate(Math.round(this.bx.height));
            this.cc();
            this.b6.h().putImageData(this.b8, 0, 0);
            this.as();
        }
        an(a) {
            super.an(a);
            let b = truncate(Math.round(this.bx.width));
            let c = truncate(Math.round(this.bx.height));
            let d = this.b2(false);
            if (d == null || d.length == 0) {
                this.e.bb.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.bb.exportSeriesPixelsData(a, e, b, c);
        }
        getDefaultTooltipTemplate() {
            let a = "<div class='ui-chart-default-tooltip-content'><span";
            let b = this.e.a9.a$u(this.e);
            if (!stringIsNullOrEmpty(b)) {
                a += " style='color:" + b + "'";
            }
            a += ">" + this.b4.title + "</span><br/><span>" + "(${item." + this.b4.xr + "}, ${item." + this.b4.xz + "})</span>";
            if (!stringIsNullOrEmpty(this.b4.yy)) {
                a += "<span>, Value: ${item." + this.b4.yy + "}</span>";
            }
            a += "</div>";
            return a;
        }
    }
    ScatterAreaSeriesView.$t = /*@__PURE__*/ markType(ScatterAreaSeriesView, 'ScatterAreaSeriesView', SeriesView.$);
    return ScatterAreaSeriesView;
})();
