/*
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.yt = null;
        _this.yy = null;
        _this.yr = null;
        _this.ys = null;
        FastItemIntColumn.m();
        _this.ab = ScatterAreaSeries.$;
        return _this;
    }
    ScatterAreaSeries.prototype.bj = function () {
        return new ScatterAreaSeries();
    };
    ScatterAreaSeries.prototype.get_eu = function () {
        return true;
    };
    Object.defineProperty(ScatterAreaSeries.prototype, "yv", {
        get: function () {
            return this.yt;
        },
        set: function (a) {
            var b = this.yt != a;
            if (b) {
                var c = this.yt;
                if (this.yt != null) {
                    var d = this.yt;
                    d.propertyChanged = delegateRemove(d.propertyChanged, runOn(this, this.zc));
                }
                this.yt = a;
                if (this.yt != null) {
                    var e = this.yt;
                    e.propertyChanged = delegateCombine(e.propertyChanged, runOn(this, this.zc));
                }
                this.raisePropertyChanged("ColorScale", c, this.yt);
            }
        },
        enumerable: false,
        configurable: true
    });
    ScatterAreaSeries.prototype.zc = function (a, b) {
        this.ze();
        this.rr(false);
    };
    ScatterAreaSeries.prototype.kq = function (a, b) {
        var c = this.nd(b);
        if (c == ScatterAreaSeries.$$p[3]) {
            return this.kr(a, b, this.y7);
        }
        return _super.prototype.kq.call(this, a, b);
    };
    ScatterAreaSeries.prototype.md = function (a) {
        var b = this.nd(a);
        if (b == ScatterAreaSeries.$$p[3]) {
            return this.y7;
        }
        return _super.prototype.md.call(this, a);
    };
    Object.defineProperty(ScatterAreaSeries.prototype, "yz", {
        get: function () {
            return this.yy;
        },
        set: function (a) {
            var b = this.yz != a;
            if (b) {
                var c = this.yz;
                this.yy = a;
                this.raisePropertyChanged("ColorColumn", c, this.yz);
            }
        },
        enumerable: false,
        configurable: true
    });
    ScatterAreaSeries.prototype.get_g7 = function () {
        return true;
    };
    ScatterAreaSeries.prototype.set_g7 = function (a) {
        _super.prototype.set_g7.call(this, a);
    };
    ScatterAreaSeries.prototype.q9 = function (a, b, c, d) {
        _super.prototype.q9.call(this, a, b, c, d);
        switch (b) {
            case ScatterAreaSeries.$$p[1]:
            case ScatterAreaSeries.$$p[2]:
                this.qf();
                break;
            case "FastItemsSource":
                var e = typeCast(IFastItemsSource_$type, c);
                if (e != null) {
                    e.deregisterColumn(this.yz);
                    this.yz = null;
                }
                var f = typeCast(IFastItemsSource_$type, d);
                if (f != null) {
                    this.yz = this.dk(this.y7);
                }
                this.rr(this.gg && c != null);
                break;
            case ScatterAreaSeries.$$p[3]:
                if (this.dn != null) {
                    this.dn.deregisterColumn(this.yz);
                    this.yz = this.dk(this.y7);
                }
                this.rr(false);
                this.ql();
                break;
            case "ColorScale":
                this.ze();
                this.rr(false);
                this.ql();
                break;
        }
    };
    ScatterAreaSeries.prototype.rs = function (a) {
        _super.prototype.rs.call(this, a);
        this.zd(this.cv);
    };
    ScatterAreaSeries.prototype.rq = function (a, b, c, d, e) {
        _super.prototype.rq.call(this, a, b, c, d, e);
        var f = this.ba.a$j.item(d);
        f.a3(c);
        if (this.d5(f)) {
            return;
        }
        this.zd(f);
    };
    ScatterAreaSeries.prototype.zd = function (a) {
        if (this.d5(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.wy;
        var i = this.wz;
        var j = this.getEffectiveViewport1(a);
        var k = new ScalerParams(1, b, c, h.ch);
        k.c = j;
        var l = new ScalerParams(1, b, c, i.ch);
        l.c = j;
        g = this.yx(a, k, l);
        if (g != null) {
            e.cb(g);
        }
        else {
            e.ce(f);
        }
    };
    ScatterAreaSeries.prototype.za = 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.b3;
        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.b3 = f;
    };
    ScatterAreaSeries.prototype.kn = function (a) {
        var b = truncate(Math.round(this.ws.width));
        var c = truncate(Math.round(this.ws.height));
        var d = this.cv.b3;
        if (d == null || d.length != (b * c) || this.w8 == null || this.w8.count < 1 || this.w9 == null || this.w9.count < 1 || this.xa == null || this.xa.count < 1) {
            return null;
        }
        var e = this.db.wl;
        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.w8.count) {
            return null;
        }
        var l = this.yr.length;
        var m = this.w8.item(k);
        var n = this.w9.item(k);
        var o = this.xa.item(k);
        if ((m >= l) || (n >= l) || (o >= l)) {
            return null;
        }
        var p = (this.yr[m] - this.ws.left) / this.ws.width;
        var q = (this.ys[m] - this.ws.top) / this.ws.height;
        var r = (this.yr[n] - this.ws.left) / this.ws.width;
        var s = (this.ys[n] - this.ws.top) / this.ws.height;
        var t = (this.yr[o] - this.ws.left) / this.ws.width;
        var u = (this.ys[o] - this.ws.top) / this.ws.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.dn.item(m);
        }
        if (w < v && w < x) {
            return this.dn.item(n);
        }
        if (x < v && x < w) {
            return this.dn.item(o);
        }
        return this.dn.item(m);
    };
    ScatterAreaSeries.prototype.yx = 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.iy();
        var g = a;
        var h = this.wy;
        var i = this.wz;
        var j = this.w8.count;
        var k;
        var xArr_ = this.xb.asArray();
        k = (xArr_.slice(0));
        var l;
        var yArr_ = this.xc.asArray();
        l = (yArr_.slice(0));
        var m = this.yz.asArray();
        var n = this.w8.asArray();
        var o = this.w9.asArray();
        var p = this.xa.asArray();
        this.yr = k;
        this.ys = l;
        h.hq(boxArray$1(k), 0, k.length, b);
        i.hq(boxArray$1(l), 0, l.length, c);
        var q = this.yu;
        var r = g.b5(b.d, q, this.yz);
        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.za(g);
        var aa = g.b3;
        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.y0 = function () {
        var a = new Color();
        var b = this.u9;
        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.ze = function () {
        var _this = this;
        var a = this.yv;
        if (a == null) {
            a = ((function () {
                var $ret = new CustomPaletteColorScale();
                $ret.palette = _this.y0();
                $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.y0();
            }
            a = b;
        }
        var c = new ObservableColorCollection();
        if (typeCast(CustomPaletteColorScale.$, a) !== null) {
            c = a.palette;
        }
        else {
            c = this.y0();
        }
        this.yu = a;
    };
    ScatterAreaSeries.prototype.sh = function () {
        _super.prototype.sh.call(this);
        this.ze();
    };
    ScatterAreaSeries.prototype.o5 = function (a, b) {
        _super.prototype.o5.call(this, a, b);
        var c = b;
        c.ca();
    };
    ScatterAreaSeries.prototype.cs = function () {
        return new ScatterAreaSeriesView(this);
    };
    ScatterAreaSeries.prototype.q1 = function (a) {
        _super.prototype.q1.call(this, a);
        this.yw = typeCast(ScatterAreaSeriesView.$, a);
    };
    ScatterAreaSeries.prototype.zb = function (a) {
        if (this.yw != null) {
            this.yw.b9(a);
        }
    };
    ScatterAreaSeries.prototype.getDataLegendSeriesContextAt = function (a, b) {
        var c = { $type: Point_$type, x: a, y: b };
        var d = this.kn(c);
        var e = d == null ? NaN : this.ix(d, "XMemberPath");
        var f = d == null ? NaN : this.ix(d, "YMemberPath");
        var g = d == null ? NaN : this.ix(d, "ColorMemberPath");
        var h = new DataLegendSeriesValueInfo();
        h.l = e;
        h.a = 13;
        h.q = "X";
        h.r = this.x0 != null ? this.x0 : "X";
        h.s = this.xw != null ? this.xw : "X:";
        h.t = this.xy != null ? this.xy : "";
        var i = new DataLegendSeriesValueInfo();
        i.l = f;
        i.a = 14;
        i.q = "Y";
        i.r = this.x8 != null ? this.x8 : "Y";
        i.s = this.x4 != null ? this.x4 : "Y:";
        i.t = this.x6 != null ? this.x6 : "";
        var j = new DataLegendSeriesValueInfo();
        j.l = g;
        j.a = 0;
        j.q = "Value";
        j.r = this.y7 != null ? this.y7 : "Value";
        j.s = this.y3 != null ? this.y3 : "V:";
        j.t = this.y5 != null ? this.y5 : "";
        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.mc();
        return k;
    };
    ScatterAreaSeries.$t = markType(ScatterAreaSeries, 'ScatterAreaSeries', ScatterTriangulationSeries.$);
    ScatterAreaSeries.$$p = markDep(DependencyProperty, PropertyMetadata, ScatterAreaSeries, 'raisePropertyChanged', ['ActualColorScale:yu:zf', [ColorScale.$, null], 'ColorMemberAsLegendLabel:y3:zg', [2, null], 'ColorMemberAsLegendUnit:y5:zh', [2, null], 'ColorMemberPath:y7:zi', [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.b4 = null;
        _this.b0 = null;
        _this.b8 = null;
        _this.b7 = null;
        _this.b6 = null;
        _this.b4 = a;
        return _this;
    }
    Object.defineProperty(ScatterAreaSeriesView.prototype, "b3", {
        get: function () {
            return this.b0;
        },
        set: function (a) {
            this.b0 = a;
        },
        enumerable: false,
        configurable: true
    });
    ScatterAreaSeriesView.prototype.cd = function (a, b) {
    };
    ScatterAreaSeriesView.prototype.b9 = function (a) {
    };
    ScatterAreaSeriesView.prototype.b1 = function () {
        return this.b2(true);
    };
    ScatterAreaSeriesView.prototype.b2 = function (a) {
        this.cc();
        var b = truncate(Math.round(this.bx.left));
        var c = truncate(Math.round(this.bx.left));
        var d = truncate(Math.round(this.bx.width));
        var e = truncate(Math.round(this.bx.height));
        var f = d.toString();
        var 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());
        }
        var h = this.b6.h();
        if (a) {
            h.clearRect(0, 0, d, e);
        }
        this.b8 = h.getImageData(0, 0, d, e);
        var imageDataArray_ = this.b8.data;
        return imageDataArray_;
    };
    ScatterAreaSeriesView.prototype.cc = function () {
        if (this.b7 == null) {
            this.b7 = this.e.jz.createElement("canvas");
            var a = this.e.jz.get2DCanvasContext(this.b7);
            this.b6 = new RenderingContext(new CanvasViewRenderer(), a);
        }
    };
    ScatterAreaSeriesView.prototype.b5 = function (a, b, c) {
        var d = truncate(Math.round(this.bx.left));
        var e = truncate(Math.round(this.bx.left));
        var f = truncate(Math.round(this.bx.width));
        var g = truncate(Math.round(this.bx.height));
        return new TriangleRasterizer(this.b1(), b, c.minimum, c.maximum, c, f, g);
    };
    ScatterAreaSeriesView.prototype.cb = function (a) {
        this.ce(null);
    };
    ScatterAreaSeriesView.prototype.ca = function () {
        if (this.b6 != null) {
            this.b6.l(this.bx.left, this.bx.top, this.bx.width, this.bx.height);
        }
        this.as();
    };
    ScatterAreaSeriesView.prototype.a8 = function (a, b) {
        _super.prototype.a8.call(this, a, b);
        if (this.b7 == null) {
            return;
        }
        if (b) {
            var 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 {
            var d = truncate(Math.round(this.bx.left));
            var e = truncate(Math.round(this.bx.top));
            var f = truncate(Math.round(this.bx.width));
            var g = truncate(Math.round(this.bx.height));
            a.n(this.b7.getNativeElement(), 1, d, e, f, g);
        }
    };
    ScatterAreaSeriesView.prototype.ce = function (a) {
        var b = truncate(Math.round(this.bx.left));
        var c = truncate(Math.round(this.bx.left));
        var d = truncate(Math.round(this.bx.width));
        var e = truncate(Math.round(this.bx.height));
        this.cc();
        this.b6.h().putImageData(this.b8, 0, 0);
        this.as();
    };
    ScatterAreaSeriesView.prototype.an = function (a) {
        _super.prototype.an.call(this, a);
        var b = truncate(Math.round(this.bx.width));
        var c = truncate(Math.round(this.bx.height));
        var d = this.b2(false);
        if (d == null || d.length == 0) {
            this.e.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.e.bc.exportSeriesPixelsData(a, e, b, c);
    };
    ScatterAreaSeriesView.prototype.getDefaultTooltipTemplate = function () {
        var a = "<div class='ui-chart-default-tooltip-content'><span";
        var b = this.e.ba.a$u(this.e);
        if (!stringIsNullOrEmpty(b)) {
            a += " style='color:" + b + "'";
        }
        a += ">" + this.b4.title + "</span><br/><span>" + "(${item." + this.b4.x0 + "}, ${item." + this.b4.x8 + "})</span>";
        if (!stringIsNullOrEmpty(this.b4.y7)) {
            a += "<span>, Value: ${item." + this.b4.y7 + "}</span>";
        }
        a += "</div>";
        return a;
    };
    ScatterAreaSeriesView.$t = markType(ScatterAreaSeriesView, 'ScatterAreaSeriesView', SeriesView.$);
    return ScatterAreaSeriesView;
}(SeriesView));
export { ScatterAreaSeriesView };
