/*
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.r3 = null;
        _this.r8 = null;
        _this.r1 = null;
        _this.r2 = null;
        FastItemIntColumn.m();
        _this.ab = ScatterAreaSeries.$;
        return _this;
    }
    ScatterAreaSeries.prototype.get_dd = function () {
        return true;
    };
    Object.defineProperty(ScatterAreaSeries.prototype, "r5", {
        get: function () {
            return this.r3;
        },
        set: function (a) {
            var b = this.r3 != a;
            if (b) {
                var c = this.r3;
                if (this.r3 != null) {
                    var d = this.r3;
                    d.propertyChanged = delegateRemove(d.propertyChanged, runOn(this, this.sm));
                }
                this.r3 = a;
                if (this.r3 != null) {
                    var e = this.r3;
                    e.propertyChanged = delegateCombine(e.propertyChanged, runOn(this, this.sm));
                }
                this.raisePropertyChanged("ColorScale", c, this.r3);
            }
        },
        enumerable: false,
        configurable: true
    });
    ScatterAreaSeries.prototype.sm = function (a, b) {
        this.so();
        this.ml(false);
    };
    ScatterAreaSeries.prototype.hy = function (a, b) {
        var c = this.js(b);
        if (c == ScatterAreaSeries.$$p[3]) {
            return this.hz(a, b, this.sh);
        }
        return _super.prototype.hy.call(this, a, b);
    };
    Object.defineProperty(ScatterAreaSeries.prototype, "r9", {
        get: function () {
            return this.r8;
        },
        set: function (a) {
            var b = this.r9 != a;
            if (b) {
                var c = this.r9;
                this.r8 = a;
                this.raisePropertyChanged("ColorColumn", c, this.r9);
            }
        },
        enumerable: false,
        configurable: true
    });
    ScatterAreaSeries.prototype.get_e5 = function () {
        return true;
    };
    ScatterAreaSeries.prototype.set_e5 = function (a) {
        _super.prototype.set_e5.call(this, a);
    };
    ScatterAreaSeries.prototype.l7 = function (a, b, c, d) {
        _super.prototype.l7.call(this, a, b, c, d);
        switch (b) {
            case "FastItemsSource":
                var e = typeCast(IFastItemsSource_$type, c);
                if (e != null) {
                    e.deregisterColumn(this.r9);
                    this.r9 = null;
                }
                var f = typeCast(IFastItemsSource_$type, d);
                if (f != null) {
                    this.r9 = this.ch(this.sh);
                }
                this.ml(false);
                break;
            case ScatterAreaSeries.$$p[3]:
                if (this.ck != null) {
                    this.ck.deregisterColumn(this.r9);
                    this.r9 = this.ch(this.sh);
                }
                this.ml(false);
                this.ls();
                break;
            case "ColorScale":
                this.so();
                this.ml(false);
                this.ls();
                break;
        }
    };
    ScatterAreaSeries.prototype.mm = function (a) {
        _super.prototype.mm.call(this, a);
        this.sn(this.b0);
    };
    ScatterAreaSeries.prototype.mk = function (a, b, c, d, e) {
        _super.prototype.mk.call(this, a, b, c, d, e);
        var f = this.a6.a$h.item(d);
        f.a1(c);
        if (this.cx(f)) {
            return;
        }
        this.sn(f);
    };
    ScatterAreaSeries.prototype.sn = function (a) {
        if (this.cx(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.p8;
        var i = this.p9;
        var j = this.getEffectiveViewport1(a);
        var k = new ScalerParams(1, b, c, h.cg);
        k.c = j;
        var l = new ScalerParams(1, b, c, i.cg);
        l.c = j;
        g = this.r7(a, k, l);
        if (g != null) {
            e.b8(g);
        }
        else {
            e.cb(f);
        }
    };
    ScatterAreaSeries.prototype.sk = 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.b0;
        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.b0 = f;
    };
    ScatterAreaSeries.prototype.hv = function (a) {
        var b = truncate(Math.round(this.p3.width));
        var c = truncate(Math.round(this.p3.height));
        var d = this.b0.b0;
        if (d == null || d.length != (b * c) || this.qi == null || this.qi.count < 1 || this.qj == null || this.qj.count < 1 || this.qk == null || this.qk.count < 1) {
            return null;
        }
        var e = this.cd.tp;
        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.qi.count) {
            return null;
        }
        var l = this.r1.length;
        var m = this.qi.item(k);
        var n = this.qj.item(k);
        var o = this.qk.item(k);
        if ((m >= l) || (n >= l) || (o >= l)) {
            return null;
        }
        var p = (this.r1[m] - this.p3.left) / this.p3.width;
        var q = (this.r2[m] - this.p3.top) / this.p3.height;
        var r = (this.r1[n] - this.p3.left) / this.p3.width;
        var s = (this.r2[n] - this.p3.top) / this.p3.height;
        var t = (this.r1[o] - this.p3.left) / this.p3.width;
        var u = (this.r2[o] - this.p3.top) / this.p3.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.ck.item(m);
        }
        if (w < v && w < x) {
            return this.ck.item(n);
        }
        if (x < v && x < w) {
            return this.ck.item(o);
        }
        return this.ck.item(m);
    };
    ScatterAreaSeries.prototype.r7 = 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.ge();
        var g = a;
        var h = this.p8;
        var i = this.p9;
        var j = this.qi.count;
        var k;
        var xArr_ = this.ql.asArray();
        k = (xArr_.slice(0));
        var l;
        var yArr_ = this.qm.asArray();
        l = (yArr_.slice(0));
        var m = this.r9.asArray();
        var n = this.qi.asArray();
        var o = this.qj.asArray();
        var p = this.qk.asArray();
        this.r1 = k;
        this.r2 = l;
        h.hm(boxArray$1(k), 0, k.length, b);
        i.hm(boxArray$1(l), 0, l.length, c);
        var q = this.r4;
        var r = g.b2(b.d, q, this.r9);
        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.sk(g);
        var aa = g.b0;
        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.sa = function () {
        var a = new Color();
        var b = this.o3;
        if (b == null) {
            a = ColorUtil.r("#000000");
        }
        else {
            a = ColorUtil.q(b);
        }
        var c = new ObservableColorCollection();
        c.add(ColorUtil.v(a, -0.5));
        c.add(a);
        return c;
    };
    ScatterAreaSeries.prototype.so = function () {
        var _this = this;
        var a = this.r5;
        if (a == null) {
            a = ((function () {
                var $ret = new CustomPaletteColorScale();
                $ret.palette = _this.sa();
                $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.sa();
            }
            a = b;
        }
        var c = new ObservableColorCollection();
        if (typeCast(CustomPaletteColorScale.$, a) !== null) {
            c = a.palette;
        }
        else {
            c = this.sa();
        }
        this.r4 = a;
    };
    ScatterAreaSeries.prototype.mz = function () {
        _super.prototype.mz.call(this);
        this.so();
    };
    ScatterAreaSeries.prototype.k0 = function (a, b) {
        _super.prototype.k0.call(this, a, b);
        var c = b;
        c.b7();
    };
    ScatterAreaSeries.prototype.bx = function () {
        return new ScatterAreaSeriesView(this);
    };
    ScatterAreaSeries.prototype.l2 = function (a) {
        _super.prototype.l2.call(this, a);
        this.r6 = typeCast(ScatterAreaSeriesView.$, a);
    };
    ScatterAreaSeries.prototype.sl = function (a) {
        if (this.r6 != null) {
            this.r6.b6(a);
        }
    };
    ScatterAreaSeries.prototype.getDataLegendSeriesContextAt = function (a, b) {
        var c = { $type: Point_$type, x: a, y: b };
        var d = this.hv(c);
        var e = d == null ? NaN : this.gd(d, "XMemberPath");
        var f = d == null ? NaN : this.gd(d, "YMemberPath");
        var g = d == null ? NaN : this.gd(d, "ColorMemberPath");
        var h = new DataLegendSeriesValueInfo();
        h.l = e;
        h.a = 13;
        h.p = "X";
        h.q = this.ra != null ? this.ra : "X";
        h.r = this.q6 != null ? this.q6 : "X:";
        h.s = this.q8 != null ? this.q8 : "";
        var i = new DataLegendSeriesValueInfo();
        i.l = f;
        i.a = 14;
        i.p = "Y";
        i.q = this.ri != null ? this.ri : "Y";
        i.r = this.re != null ? this.re : "Y:";
        i.s = this.rg != null ? this.rg : "";
        var j = new DataLegendSeriesValueInfo();
        j.l = g;
        j.a = 0;
        j.p = "Value";
        j.q = this.sh != null ? this.sh : "Value";
        j.r = this.sd != null ? this.sd : "V:";
        j.s = this.sf != null ? this.sf : "";
        var k = new DataLegendSeriesContext();
        k.f = ((function () {
            var $ret = new List$1(DataLegendSeriesValueInfo.$, 0);
            $ret.add(h);
            $ret.add(i);
            $ret.add(j);
            return $ret;
        })());
        k.b = this.av();
        return k;
    };
    ScatterAreaSeries.$t = markType(ScatterAreaSeries, 'ScatterAreaSeries', ScatterTriangulationSeries.$);
    ScatterAreaSeries.$$p = markDep(DependencyProperty, PropertyMetadata, ScatterAreaSeries, 'raisePropertyChanged', ['ActualColorScale:r4:sp', [ColorScale.$, null], 'ColorMemberAsLegendLabel:sd:sq', [2, null], 'ColorMemberAsLegendUnit:sf:sr', [2, null], 'ColorMemberPath:sh:ss', [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.b1 = null;
        _this.bx = null;
        _this.b5 = null;
        _this.b4 = null;
        _this.b3 = null;
        _this.b1 = a;
        return _this;
    }
    Object.defineProperty(ScatterAreaSeriesView.prototype, "b0", {
        get: function () {
            return this.bx;
        },
        set: function (a) {
            this.bx = a;
        },
        enumerable: false,
        configurable: true
    });
    ScatterAreaSeriesView.prototype.ca = function (a, b) {
    };
    ScatterAreaSeriesView.prototype.b6 = function (a) {
    };
    ScatterAreaSeriesView.prototype.by = function () {
        return this.bz(true);
    };
    ScatterAreaSeriesView.prototype.bz = function (a) {
        this.b9();
        var b = truncate(Math.round(this.bu.left));
        var c = truncate(Math.round(this.bu.left));
        var d = truncate(Math.round(this.bu.width));
        var e = truncate(Math.round(this.bu.height));
        var f = d.toString();
        var 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());
        }
        var h = this.b3.h();
        if (a) {
            h.clearRect(0, 0, d, e);
        }
        this.b5 = h.getImageData(0, 0, d, e);
        var imageDataArray_ = this.b5.data;
        return imageDataArray_;
    };
    ScatterAreaSeriesView.prototype.b9 = function () {
        if (this.b4 == null) {
            this.b4 = this.e.hb.createElement("canvas");
            var a = this.e.hb.get2DCanvasContext(this.b4);
            this.b3 = new RenderingContext(new CanvasViewRenderer(), a);
        }
    };
    ScatterAreaSeriesView.prototype.b2 = function (a, b, c) {
        var d = truncate(Math.round(this.bu.left));
        var e = truncate(Math.round(this.bu.left));
        var f = truncate(Math.round(this.bu.width));
        var g = truncate(Math.round(this.bu.height));
        return new TriangleRasterizer(this.by(), b, c.minimum, c.maximum, c, f, g);
    };
    ScatterAreaSeriesView.prototype.b8 = function (a) {
        this.cb(null);
    };
    ScatterAreaSeriesView.prototype.b7 = function () {
        if (this.b3 != null) {
            this.b3.l(this.bu.left, this.bu.top, this.bu.width, this.bu.height);
        }
        this.aq();
    };
    ScatterAreaSeriesView.prototype.a6 = function (a, b) {
        _super.prototype.a6.call(this, a, b);
        if (this.b4 == null) {
            return;
        }
        if (b) {
            var 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.w(c);
        }
        else {
            var d = truncate(Math.round(this.bu.left));
            var e = truncate(Math.round(this.bu.top));
            var f = truncate(Math.round(this.bu.width));
            var g = truncate(Math.round(this.bu.height));
            a.n(this.b4.getNativeElement(), 1, d, e, f, g);
        }
    };
    ScatterAreaSeriesView.prototype.cb = function (a) {
        var b = truncate(Math.round(this.bu.left));
        var c = truncate(Math.round(this.bu.left));
        var d = truncate(Math.round(this.bu.width));
        var e = truncate(Math.round(this.bu.height));
        this.b9();
        this.b3.h().putImageData(this.b5, 0, 0);
        this.aq();
    };
    ScatterAreaSeriesView.prototype.al = function (a) {
        _super.prototype.al.call(this, a);
        var b = truncate(Math.round(this.bu.width));
        var c = truncate(Math.round(this.bu.height));
        var d = this.bz(false);
        if (d == null || d.length == 0) {
            this.e.a8.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.a8.exportSeriesPixelsData(a, e, b, c);
    };
    ScatterAreaSeriesView.prototype.getDefaultTooltipTemplate = function () {
        var a = "<div class='ui-chart-default-tooltip-content'><span";
        var b = this.e.a6.a$r(this.e);
        if (!stringIsNullOrEmpty(b)) {
            a += " style='color:" + b + "'";
        }
        a += ">" + this.b1.title + "</span><br/><span>" + "(${item." + this.b1.ra + "}, ${item." + this.b1.ri + "})</span>";
        if (!stringIsNullOrEmpty(this.b1.sh)) {
            a += "<span>, Value: ${item." + this.b1.sh + "}</span>";
        }
        a += "</div>";
        return a;
    };
    ScatterAreaSeriesView.$t = markType(ScatterAreaSeriesView, 'ScatterAreaSeriesView', SeriesView.$);
    return ScatterAreaSeriesView;
}(SeriesView));
export { ScatterAreaSeriesView };
