/*
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 { __extends } from "tslib";
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
 */
var ScatterAreaSeries = /** @class */ /*@__PURE__*/ (function (_super) {
    __extends(ScatterAreaSeries, _super);
    function ScatterAreaSeries() {
        var _this = _super.call(this) || this;
        _this.y3 = null;
        _this.y8 = null;
        _this.y1 = null;
        _this.y2 = null;
        FastItemIntColumn.m();
        _this.ab = ScatterAreaSeries.$;
        return _this;
    }
    ScatterAreaSeries.prototype.bk = function () {
        return new ScatterAreaSeries();
    };
    ScatterAreaSeries.prototype.get_ew = function () {
        return true;
    };
    Object.defineProperty(ScatterAreaSeries.prototype, "y5", {
        get: function () {
            return this.y3;
        },
        set: function (a) {
            var b = this.y3 != a;
            if (b) {
                var c = this.y3;
                if (this.y3 != null) {
                    var d = this.y3;
                    d.propertyChanged = delegateRemove(d.propertyChanged, runOn(this, this.zm));
                }
                this.y3 = a;
                if (this.y3 != null) {
                    var e = this.y3;
                    e.propertyChanged = delegateCombine(e.propertyChanged, runOn(this, this.zm));
                }
                this.raisePropertyChanged("ColorScale", c, this.y3);
            }
        },
        enumerable: false,
        configurable: true
    });
    ScatterAreaSeries.prototype.zm = function (a, b) {
        this.zo();
        this.ry(false);
    };
    ScatterAreaSeries.prototype.ku = function (a, b) {
        var c = this.ni(b);
        if (c == ScatterAreaSeries.$$p[3]) {
            return this.kv(a, b, this.zh);
        }
        return _super.prototype.ku.call(this, a, b);
    };
    ScatterAreaSeries.prototype.mi = function (a) {
        var b = this.ni(a);
        if (b == ScatterAreaSeries.$$p[3]) {
            return this.zh;
        }
        return _super.prototype.mi.call(this, a);
    };
    Object.defineProperty(ScatterAreaSeries.prototype, "y9", {
        get: function () {
            return this.y8;
        },
        set: function (a) {
            var b = this.y9 != a;
            if (b) {
                var c = this.y9;
                this.y8 = a;
                this.raisePropertyChanged("ColorColumn", c, this.y9);
            }
        },
        enumerable: false,
        configurable: true
    });
    ScatterAreaSeries.prototype.get_g8 = function () {
        return true;
    };
    ScatterAreaSeries.prototype.set_g8 = function (a) {
        _super.prototype.set_g8.call(this, a);
    };
    ScatterAreaSeries.prototype.rg = function (a, b, c, d) {
        _super.prototype.rg.call(this, a, b, c, d);
        switch (b) {
            case ScatterAreaSeries.$$p[1]:
            case ScatterAreaSeries.$$p[2]:
                this.ql();
                break;
            case "FastItemsSource":
                var e = typeCast(IFastItemsSource_$type, c);
                if (e != null) {
                    e.deregisterColumn(this.y9);
                    this.y9 = null;
                }
                var 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;
        }
    };
    ScatterAreaSeries.prototype.rz = function (a) {
        _super.prototype.rz.call(this, a);
        this.zn(this.cw);
    };
    ScatterAreaSeries.prototype.rx = function (a, b, c, d, e) {
        _super.prototype.rx.call(this, a, b, c, d, e);
        var f = this.ba.a$j.item(d);
        f.bd(c);
        if (this.d7(f)) {
            return;
        }
        this.zn(f);
    };
    ScatterAreaSeries.prototype.zn = function (a) {
        if (this.d7(a)) {
            return;
        }
        var b;
        var c;
        var d = a.getViewInfo(c, b);
        c = d.p0;
        b = d.p1;
        var e = a;
        var f = null;
        var g = null;
        var h = this.w8;
        var i = this.w9;
        var j = this.getEffectiveViewport1(a);
        var k = new ScalerParams(1, b, c, h.df);
        k.c = j;
        var 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);
        }
    };
    ScatterAreaSeries.prototype.zk = function (a) {
        var b;
        var c;
        var d = a.getViewInfo(b, c);
        b = d.p0;
        c = d.p1;
        var e = truncate(Math.round(b.width)) * truncate(Math.round(b.height));
        var f = a.cg;
        if (f == null || f.length != e) {
            f = new Array(e);
            for (var g = 0; g < e; g++) {
                f[g] = 0;
            }
        }
        else {
            for (var h = 0; h < e; h++) {
                f[h] = 0;
            }
        }
        a.cg = f;
    };
    ScatterAreaSeries.prototype.kr = function (a) {
        var b = truncate(Math.round(this.w2.width));
        var c = truncate(Math.round(this.w2.height));
        var 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;
        }
        var e = this.dc.x5;
        var f = (a.x - e.left) / e.width;
        var g = (a.y - e.top) / e.height;
        var h = truncate(Math.round(b * f));
        var i = truncate(Math.round(c * g));
        var j = (b * i) + h;
        if (j < 0 || j > d.length - 1) {
            return null;
        }
        var k = d[j] - 1;
        if (k < 0 || k > this.xi.count) {
            return null;
        }
        var l = this.y1.length;
        var m = this.xi.item(k);
        var n = this.xj.item(k);
        var o = this.xk.item(k);
        if ((m >= l) || (n >= l) || (o >= l)) {
            return null;
        }
        var p = (this.y1[m] - this.w2.left) / this.w2.width;
        var q = (this.y2[m] - this.w2.top) / this.w2.height;
        var r = (this.y1[n] - this.w2.left) / this.w2.width;
        var s = (this.y2[n] - this.w2.top) / this.w2.height;
        var t = (this.y1[o] - this.w2.left) / this.w2.width;
        var u = (this.y2[o] - this.w2.top) / this.w2.height;
        var v = Math.pow(p - f, 2) + Math.pow(q - g, 2);
        var w = Math.pow(r - f, 2) + Math.pow(s - g, 2);
        var 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);
    };
    ScatterAreaSeries.prototype.y7 = function (a, b, c) {
        var d;
        var e;
        var 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();
        var g = a;
        var h = this.w8;
        var i = this.w9;
        var j = this.xi.count;
        var k;
        var xArr_ = this.xl.asArray();
        k = (xArr_.slice(0));
        var l;
        var yArr_ = this.xm.asArray();
        l = (yArr_.slice(0));
        var m = this.y9.asArray();
        var n = this.xi.asArray();
        var o = this.xj.asArray();
        var 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);
        var q = this.y4;
        var r = g.ci(b.d, q, this.y9);
        var s = e.top;
        var t = e.left;
        var u = e.right;
        var v = e.bottom;
        var w;
        var x;
        var y;
        var z;
        this.zk(g);
        var aa = g.cg;
        var ab = k.length;
        for (var ac = 0; ac < j; ac++) {
            var ad = n[ac];
            var ae = o[ac];
            var af = p[ac];
            if ((ad >= ab) || (ae >= ab) || (af >= ab) || (ad < 0) || (ae < 0) || (af < 0)) {
                continue;
            }
            var ag = k[ad];
            var ah = l[ad];
            var ai = { $type: Point_$type, x: ag, y: ah };
            var aj = k[ae];
            var ak = l[ae];
            var al = { $type: Point_$type, x: aj, y: ak };
            var am = k[af];
            var an = l[af];
            var 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) {
                var ap = m[ad];
                var aq = m[ae];
                var ar = m[af];
                r.p(ac, aa, ai, al, ao, ap, aq, ar);
            }
        }
        return r;
    };
    ScatterAreaSeries.prototype.za = function () {
        var a = new Color();
        var b = this.vj;
        if (b == null) {
            a = ColorUtil.u("#000000");
        }
        else {
            a = ColorUtil.t(b);
        }
        var c = new ObservableColorCollection();
        c.add(ColorUtil.y(a, -0.5));
        c.add(a);
        return c;
    };
    ScatterAreaSeries.prototype.zo = function () {
        var _this = this;
        var a = this.y5;
        if (a == null) {
            a = ((function () {
                var $ret = new CustomPaletteColorScale();
                $ret.palette = _this.za();
                $ret.interpolationMode = 2;
                return $ret;
            })());
        }
        else if (typeCast(CustomPaletteColorScale.$, a) !== null) {
            var b = a;
            if (b.palette == null || b.palette.count == 0) {
                b.palette = this.za();
            }
            a = b;
        }
        var c = new ObservableColorCollection();
        if (typeCast(CustomPaletteColorScale.$, a) !== null) {
            c = a.palette;
        }
        else {
            c = this.za();
        }
        this.y4 = a;
    };
    ScatterAreaSeries.prototype.sp = function () {
        _super.prototype.sp.call(this);
        this.zo();
    };
    ScatterAreaSeries.prototype.pb = function (a, b) {
        _super.prototype.pb.call(this, a, b);
        var c = b;
        c.cn();
    };
    ScatterAreaSeries.prototype.ct = function () {
        return new ScatterAreaSeriesView(this);
    };
    ScatterAreaSeries.prototype.q7 = function (a) {
        _super.prototype.q7.call(this, a);
        this.y6 = typeCast(ScatterAreaSeriesView.$, a);
    };
    ScatterAreaSeries.prototype.zl = function (a) {
        if (this.y6 != null) {
            this.y6.cm(a);
        }
    };
    ScatterAreaSeries.prototype.getDataLegendSeriesContextAt = function (a, b) {
        var c = { $type: Point_$type, x: a, y: b };
        var d = this.kr(c);
        var e = d == null ? NaN : this.iz(d, "XMemberPath");
        var f = d == null ? NaN : this.iz(d, "YMemberPath");
        var g = d == null ? NaN : this.iz(d, "ColorMemberPath");
        var 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 : "";
        var 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 : "";
        var 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 : "";
        var k = new DataLegendSeriesContext();
        k.e = ((function () {
            var $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;
}(ScatterTriangulationSeries));
export { ScatterAreaSeries };
/**
 * @hidden
 */
var ScatterAreaSeriesView = /** @class */ /*@__PURE__*/ (function (_super) {
    __extends(ScatterAreaSeriesView, _super);
    function ScatterAreaSeriesView(a) {
        var _this = _super.call(this, a) || this;
        _this.ch = null;
        _this.cd = null;
        _this.cl = null;
        _this.ck = null;
        _this.cj = null;
        _this.ch = a;
        return _this;
    }
    Object.defineProperty(ScatterAreaSeriesView.prototype, "cg", {
        get: function () {
            return this.cd;
        },
        set: function (a) {
            this.cd = a;
        },
        enumerable: false,
        configurable: true
    });
    ScatterAreaSeriesView.prototype.cq = function (a, b) {
    };
    ScatterAreaSeriesView.prototype.cm = function (a) {
    };
    ScatterAreaSeriesView.prototype.ce = function () {
        return this.cf(true);
    };
    ScatterAreaSeriesView.prototype.cf = function (a) {
        this.cp();
        var b = truncate(Math.round(this.b9.left));
        var c = truncate(Math.round(this.b9.left));
        var d = truncate(Math.round(this.b9.width));
        var e = truncate(Math.round(this.b9.height));
        var f = d.toString();
        var 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());
        }
        var h = this.cj.h();
        if (a) {
            h.clearRect(0, 0, d, e);
        }
        this.cl = h.getImageData(0, 0, d, e);
        var imageDataArray_ = this.cl.data;
        return imageDataArray_;
    };
    ScatterAreaSeriesView.prototype.cp = function () {
        if (this.ck == null) {
            this.ck = this.f.j3.createElement("canvas");
            var a = this.f.j3.get2DCanvasContext(this.ck);
            this.cj = new RenderingContext(new CanvasViewRenderer(), a);
        }
    };
    ScatterAreaSeriesView.prototype.ci = function (a, b, c) {
        var d = truncate(Math.round(this.b9.left));
        var e = truncate(Math.round(this.b9.left));
        var f = truncate(Math.round(this.b9.width));
        var g = truncate(Math.round(this.b9.height));
        return new TriangleRasterizer(this.ce(), b, c.minimum, c.maximum, c, f, g);
    };
    ScatterAreaSeriesView.prototype.co = function (a) {
        this.cr(null);
    };
    ScatterAreaSeriesView.prototype.cn = function () {
        if (this.cj != null) {
            this.cj.l(this.b9.left, this.b9.top, this.b9.width, this.b9.height);
        }
        this.a2();
    };
    ScatterAreaSeriesView.prototype.bj = function (a, b) {
        _super.prototype.bj.call(this, a, b);
        if (this.ck == null) {
            return;
        }
        if (b) {
            var 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 {
            var d = truncate(Math.round(this.b9.left));
            var e = truncate(Math.round(this.b9.top));
            var f = truncate(Math.round(this.b9.width));
            var g = truncate(Math.round(this.b9.height));
            a.n(this.ck.getNativeElement(), 1, d, e, f, g);
        }
    };
    ScatterAreaSeriesView.prototype.cr = function (a) {
        var b = truncate(Math.round(this.b9.left));
        var c = truncate(Math.round(this.b9.left));
        var d = truncate(Math.round(this.b9.width));
        var e = truncate(Math.round(this.b9.height));
        this.cp();
        this.cj.h().putImageData(this.cl, 0, 0);
        this.a2();
    };
    ScatterAreaSeriesView.prototype.ax = function (a) {
        _super.prototype.ax.call(this, a);
        var b = truncate(Math.round(this.b9.width));
        var c = truncate(Math.round(this.b9.height));
        var d = this.cf(false);
        if (d == null || d.length == 0) {
            this.f.bc.exportSeriesPixelsData(a, null, b, c);
            return;
        }
        var e = new Array(intDivide(d.length, 4));
        var f;
        for (var 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);
    };
    ScatterAreaSeriesView.prototype.getDefaultTooltipTemplate = function () {
        var a = "<div class='ui-chart-default-tooltip-content'><span";
        var 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;
}(SeriesView));
export { ScatterAreaSeriesView };
