/*
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-angular-core";
import { DependencyProperty } 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 { Color } from "igniteui-angular-core";
import { ColorUtil } from "igniteui-angular-core";
import { List$1 } from "igniteui-angular-core";
import { CustomPaletteColorScale } from "./CustomPaletteColorScale";
import { DataLegendSeriesValueInfo } from "igniteui-angular-core";
import { DataLegendSeriesContext } from "igniteui-angular-core";
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 let ScatterAreaSeries = /*@__PURE__*/ (() => {
    class ScatterAreaSeries extends ScatterTriangulationSeries {
        constructor() {
            super();
            this.y3 = null;
            this.y8 = null;
            this.y1 = null;
            this.y2 = null;
            FastItemIntColumn.m();
            this.ab = ScatterAreaSeries.$;
        }
        bk() {
            return new ScatterAreaSeries();
        }
        get_ew() {
            return true;
        }
        get y5() {
            return this.y3;
        }
        set y5(a) {
            let b = this.y3 != a;
            if (b) {
                let c = this.y3;
                if (this.y3 != null) {
                    let d = this.y3;
                    d.propertyChanged = delegateRemove(d.propertyChanged, runOn(this, this.zm));
                }
                this.y3 = a;
                if (this.y3 != null) {
                    let e = this.y3;
                    e.propertyChanged = delegateCombine(e.propertyChanged, runOn(this, this.zm));
                }
                this.raisePropertyChanged("ColorScale", c, this.y3);
            }
        }
        zm(a, b) {
            this.zo();
            this.ry(false);
        }
        ku(a, b) {
            let c = this.ni(b);
            if (c == ScatterAreaSeries.$$p[3]) {
                return this.kv(a, b, this.zh);
            }
            return super.ku(a, b);
        }
        mi(a) {
            let b = this.ni(a);
            if (b == ScatterAreaSeries.$$p[3]) {
                return this.zh;
            }
            return super.mi(a);
        }
        get y9() {
            return this.y8;
        }
        set y9(a) {
            let b = this.y9 != a;
            if (b) {
                let c = this.y9;
                this.y8 = a;
                this.raisePropertyChanged("ColorColumn", c, this.y9);
            }
        }
        get_g8() {
            return true;
        }
        set_g8(a) {
            super.set_g8(a);
        }
        rg(a, b, c, d) {
            super.rg(a, b, c, d);
            switch (b) {
                case ScatterAreaSeries.$$p[1]:
                case ScatterAreaSeries.$$p[2]:
                    this.ql();
                    break;
                case "FastItemsSource":
                    let e = typeCast(IFastItemsSource_$type, c);
                    if (e != null) {
                        e.deregisterColumn(this.y9);
                        this.y9 = null;
                    }
                    let f = typeCast(IFastItemsSource_$type, d);
                    if (f != null) {
                        this.y9 = this.dl(this.zh);
                    }
                    this.ry(this.gh && c != null);
                    break;
                case ScatterAreaSeries.$$p[3]:
                    if (this.dp != null) {
                        this.dp.deregisterColumn(this.y9);
                        this.y9 = this.dl(this.zh);
                    }
                    this.ry(false);
                    this.qr();
                    break;
                case "ColorScale":
                    this.zo();
                    this.ry(false);
                    this.qr();
                    break;
            }
        }
        rz(a) {
            super.rz(a);
            this.zn(this.cw);
        }
        rx(a, b, c, d, e) {
            super.rx(a, b, c, d, e);
            let f = this.ba.a$j.item(d);
            f.bd(c);
            if (this.d7(f)) {
                return;
            }
            this.zn(f);
        }
        zn(a) {
            if (this.d7(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.w8;
            let i = this.w9;
            let j = this.getEffectiveViewport1(a);
            let k = new ScalerParams(1, b, c, h.df);
            k.c = j;
            let l = new ScalerParams(1, b, c, i.df);
            l.c = j;
            g = this.y7(a, k, l);
            if (g != null) {
                e.co(g);
            }
            else {
                e.cr(f);
            }
        }
        zk(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.cg;
            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.cg = f;
        }
        kr(a) {
            let b = truncate(Math.round(this.w2.width));
            let c = truncate(Math.round(this.w2.height));
            let d = this.cw.cg;
            if (d == null || d.length != (b * c) || this.xi == null || this.xi.count < 1 || this.xj == null || this.xj.count < 1 || this.xk == null || this.xk.count < 1) {
                return null;
            }
            let e = this.dc.x5;
            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.xi.count) {
                return null;
            }
            let l = this.y1.length;
            let m = this.xi.item(k);
            let n = this.xj.item(k);
            let o = this.xk.item(k);
            if ((m >= l) || (n >= l) || (o >= l)) {
                return null;
            }
            let p = (this.y1[m] - this.w2.left) / this.w2.width;
            let q = (this.y2[m] - this.w2.top) / this.w2.height;
            let r = (this.y1[n] - this.w2.left) / this.w2.width;
            let s = (this.y2[n] - this.w2.top) / this.w2.height;
            let t = (this.y1[o] - this.w2.left) / this.w2.width;
            let u = (this.y2[o] - this.w2.top) / this.w2.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.dp.item(m);
            }
            if (w < v && w < x) {
                return this.dp.item(n);
            }
            if (x < v && x < w) {
                return this.dp.item(o);
            }
            return this.dp.item(m);
        }
        y7(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.i0();
            let g = a;
            let h = this.w8;
            let i = this.w9;
            let j = this.xi.count;
            let k;
            let xArr_ = this.xl.asArray();
            k = (xArr_.slice(0));
            let l;
            let yArr_ = this.xm.asArray();
            l = (yArr_.slice(0));
            let m = this.y9.asArray();
            let n = this.xi.asArray();
            let o = this.xj.asArray();
            let p = this.xk.asArray();
            this.y1 = k;
            this.y2 = l;
            h.j6(boxArray$1(k), 0, k.length, b);
            i.j6(boxArray$1(l), 0, l.length, c);
            let q = this.y4;
            let r = g.ci(b.d, q, this.y9);
            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.zk(g);
            let aa = g.cg;
            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;
        }
        za() {
            let a = new Color();
            let b = this.vj;
            if (b == null) {
                a = ColorUtil.u("#000000");
            }
            else {
                a = ColorUtil.t(b);
            }
            let c = new ObservableColorCollection();
            c.add(ColorUtil.y(a, -0.5));
            c.add(a);
            return c;
        }
        zo() {
            let a = this.y5;
            if (a == null) {
                a = ((() => {
                    let $ret = new CustomPaletteColorScale();
                    $ret.palette = this.za();
                    $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.za();
                }
                a = b;
            }
            let c = new ObservableColorCollection();
            if (typeCast(CustomPaletteColorScale.$, a) !== null) {
                c = a.palette;
            }
            else {
                c = this.za();
            }
            this.y4 = a;
        }
        sp() {
            super.sp();
            this.zo();
        }
        pb(a, b) {
            super.pb(a, b);
            let c = b;
            c.cn();
        }
        ct() {
            return new ScatterAreaSeriesView(this);
        }
        q7(a) {
            super.q7(a);
            this.y6 = typeCast(ScatterAreaSeriesView.$, a);
        }
        zl(a) {
            if (this.y6 != null) {
                this.y6.cm(a);
            }
        }
        getDataLegendSeriesContextAt(a, b) {
            let c = { $type: Point_$type, x: a, y: b };
            let d = this.kr(c);
            let e = d == null ? NaN : this.iz(d, "XMemberPath");
            let f = d == null ? NaN : this.iz(d, "YMemberPath");
            let g = d == null ? NaN : this.iz(d, "ColorMemberPath");
            let h = new DataLegendSeriesValueInfo();
            h.l = e;
            h.a = 13;
            h.q = "X";
            h.r = this.ya != null ? this.ya : "X";
            h.s = this.x6 != null ? this.x6 : "X:";
            h.t = this.x8 != null ? this.x8 : "";
            let i = new DataLegendSeriesValueInfo();
            i.l = f;
            i.a = 14;
            i.q = "Y";
            i.r = this.yi != null ? this.yi : "Y";
            i.s = this.ye != null ? this.ye : "Y:";
            i.t = this.yg != null ? this.yg : "";
            let j = new DataLegendSeriesValueInfo();
            j.l = g;
            j.a = 0;
            j.q = "Value";
            j.r = this.zh != null ? this.zh : "Value";
            j.s = this.zd != null ? this.zd : "V:";
            j.t = this.zf != null ? this.zf : "";
            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.mh();
            return k;
        }
    }
    ScatterAreaSeries.$t = markType(ScatterAreaSeries, 'ScatterAreaSeries', ScatterTriangulationSeries.$);
    ScatterAreaSeries.$$p = markDep(DependencyProperty, PropertyMetadata, ScatterAreaSeries, 'raisePropertyChanged', ['ActualColorScale:y4:zp', [ColorScale.$, null], 'ColorMemberAsLegendLabel:zd:zq', [2, null], 'ColorMemberAsLegendUnit:zf:zr', [2, null], 'ColorMemberPath:zh:zs', [2, null]]);
    return ScatterAreaSeries;
})();
/**
 * @hidden
 */
export let ScatterAreaSeriesView = /*@__PURE__*/ (() => {
    class ScatterAreaSeriesView extends SeriesView {
        constructor(a) {
            super(a);
            this.ch = null;
            this.cd = null;
            this.cl = null;
            this.ck = null;
            this.cj = null;
            this.ch = a;
        }
        get cg() {
            return this.cd;
        }
        set cg(a) {
            this.cd = a;
        }
        cq(a, b) {
        }
        cm(a) {
        }
        ce() {
            return this.cf(true);
        }
        cf(a) {
            this.cp();
            let b = truncate(Math.round(this.b9.left));
            let c = truncate(Math.round(this.b9.left));
            let d = truncate(Math.round(this.b9.width));
            let e = truncate(Math.round(this.b9.height));
            let f = d.toString();
            let g = e.toString();
            if (this.ck.getAttribute("width") != f) {
                this.ck.setAttribute("width", d.toString());
            }
            if (this.ck.getAttribute("height") != g) {
                this.ck.setAttribute("height", e.toString());
            }
            let h = this.cj.h();
            if (a) {
                h.clearRect(0, 0, d, e);
            }
            this.cl = h.getImageData(0, 0, d, e);
            let imageDataArray_ = this.cl.data;
            return imageDataArray_;
        }
        cp() {
            if (this.ck == null) {
                this.ck = this.f.j3.createElement("canvas");
                let a = this.f.j3.get2DCanvasContext(this.ck);
                this.cj = new RenderingContext(new CanvasViewRenderer(), a);
            }
        }
        ci(a, b, c) {
            let d = truncate(Math.round(this.b9.left));
            let e = truncate(Math.round(this.b9.left));
            let f = truncate(Math.round(this.b9.width));
            let g = truncate(Math.round(this.b9.height));
            return new TriangleRasterizer(this.ce(), b, c.minimum, c.maximum, c, f, g);
        }
        co(a) {
            this.cr(null);
        }
        cn() {
            if (this.cj != null) {
                this.cj.l(this.b9.left, this.b9.top, this.b9.width, this.b9.height);
            }
            this.a2();
        }
        bj(a, b) {
            super.bj(a, b);
            if (this.ck == null) {
                return;
            }
            if (b) {
                let c = new Rectangle();
                c.n = this.b9.left;
                c.o = this.b9.top;
                c.width = this.b9.width;
                c.height = this.b9.height;
                c._fill = this.b3();
                a.w(c);
            }
            else {
                let d = truncate(Math.round(this.b9.left));
                let e = truncate(Math.round(this.b9.top));
                let f = truncate(Math.round(this.b9.width));
                let g = truncate(Math.round(this.b9.height));
                a.n(this.ck.getNativeElement(), 1, d, e, f, g);
            }
        }
        cr(a) {
            let b = truncate(Math.round(this.b9.left));
            let c = truncate(Math.round(this.b9.left));
            let d = truncate(Math.round(this.b9.width));
            let e = truncate(Math.round(this.b9.height));
            this.cp();
            this.cj.h().putImageData(this.cl, 0, 0);
            this.a2();
        }
        ax(a) {
            super.ax(a);
            let b = truncate(Math.round(this.b9.width));
            let c = truncate(Math.round(this.b9.height));
            let d = this.cf(false);
            if (d == null || d.length == 0) {
                this.f.bc.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.f.bc.exportSeriesPixelsData(a, e, b, c);
        }
        getDefaultTooltipTemplate() {
            let a = "<div class='ui-chart-default-tooltip-content'><span";
            let b = this.f.ba.a$u(this.f);
            if (!stringIsNullOrEmpty(b)) {
                a += " style='color:" + b + "'";
            }
            a += ">" + this.ch.title + "</span><br/><span>" + "(${item." + this.ch.ya + "}, ${item." + this.ch.yi + "})</span>";
            if (!stringIsNullOrEmpty(this.ch.zh)) {
                a += "<span>, Value: ${item." + this.ch.zh + "}</span>";
            }
            a += "</div>";
            return a;
        }
    }
    ScatterAreaSeriesView.$t = markType(ScatterAreaSeriesView, 'ScatterAreaSeriesView', SeriesView.$);
    return ScatterAreaSeriesView;
})();
