/*
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 * as tslib_1 from "tslib";
import { ScatterTriangulationSeries } from "./ScatterTriangulationSeries";
import { Type, runOn, delegateRemove, delegateCombine, typeCast, Point_$type, markType } from "igniteui-react-core/ES5/type";
import { DependencyProperty } from "igniteui-react-core/ES5/DependencyProperty";
import { Color } from "igniteui-react-core/ES5/Color";
import { FastItemIntColumn } from "igniteui-react-core/ES5/FastItemIntColumn";
import { IFastItemsSource_$type } from "igniteui-react-core/ES5/IFastItemsSource";
import { Rect } from "igniteui-react-core/ES5/Rect";
import { SeriesView } from "./SeriesView";
import { TriangleRasterizer } from "./TriangleRasterizer";
import { ScalerParams } from "./ScalerParams";
import { ObservableColorCollection } from "igniteui-react-core/ES5/ObservableColorCollection";
import { ColorUtil } from "igniteui-react-core/ES5/ColorUtil";
import { CustomPaletteColorScale } from "./CustomPaletteColorScale";
import { PropertyMetadata } from "igniteui-react-core/ES5/PropertyMetadata";
import { truncate, intDivide } from "igniteui-react-core/ES5/number";
import { boxArray$1 } from "igniteui-react-core/ES5/array";
import { RenderingContext } from "igniteui-react-core/ES5/RenderingContext";
import { CanvasViewRenderer } from "igniteui-react-core/ES5/CanvasViewRenderer";
import { Rectangle } from "igniteui-react-core/ES5/Rectangle";
import { stringIsNullOrEmpty } from "igniteui-react-core/ES5/string";
var ScatterAreaSeries = /** @class */ (function (_super) {
    tslib_1.__extends(ScatterAreaSeries, _super);
    function ScatterAreaSeries() {
        var _this = _super.call(this) || this;
        _this.nb = null;
        _this.ng = null;
        _this.m9 = null;
        _this.na = null;
        _this.m8 = [Color.u(255, 0, 0, 255), Color.u(255, 0, 255, 0), Color.u(255, 255, 0, 0)];
        FastItemIntColumn.k();
        _this.ab = ScatterAreaSeries.$;
        return _this;
    }
    Object.defineProperty(ScatterAreaSeries.prototype, "nc", {
        get: function () {
            return this.nb;
        },
        set: function (a) {
            var b = this.nb != a;
            if (b) {
                var c = this.nb;
                if (this.nb != null) {
                    var d = this.nb;
                    d.propertyChanged = delegateRemove(d.propertyChanged, runOn(this, this.np));
                }
                this.nb = a;
                if (this.nb != null) {
                    var e = this.nb;
                    e.propertyChanged = delegateCombine(e.propertyChanged, runOn(this, this.np));
                }
                this.raisePropertyChanged("ColorScale", c, this.nb);
            }
        },
        enumerable: true,
        configurable: true
    });
    ScatterAreaSeries.prototype.np = function (a, b) {
        this.i4(false);
    };
    Object.defineProperty(ScatterAreaSeries.prototype, "nh", {
        get: function () {
            return this.ng;
        },
        set: function (a) {
            var b = this.nh != a;
            if (b) {
                var c = this.nh;
                this.ng = a;
                this.raisePropertyChanged("ColorColumn", c, this.nh);
            }
        },
        enumerable: true,
        configurable: true
    });
    ScatterAreaSeries.prototype.get_dn = function () {
        return true;
    };
    ScatterAreaSeries.prototype.set_dn = function (a) {
        _super.prototype.set_dn.call(this, a);
    };
    ScatterAreaSeries.prototype.ir = function (a, b, c, d) {
        _super.prototype.ir.call(this, a, b, c, d);
        switch (b) {
            case "FastItemsSource":
                var e = typeCast(IFastItemsSource_$type, c);
                if (e != null) {
                    e.deregisterColumn(this.nh);
                    this.nh = null;
                }
                var f = typeCast(IFastItemsSource_$type, d);
                if (f != null) {
                    this.nh = this.bw(this.nk);
                }
                this.i4(false);
                break;
            case ScatterAreaSeries.$$p[0]:
                if (this.bz != null) {
                    this.bz.deregisterColumn(this.nh);
                    this.nh = this.bw(this.nk);
                }
                this.i4(false);
                this.ib();
                break;
            case "ColorScale":
                this.i4(false);
                this.ib();
                break;
        }
    };
    ScatterAreaSeries.prototype.i5 = function (a) {
        _super.prototype.i5.call(this, a);
        this.nq(this.bi);
    };
    ScatterAreaSeries.prototype.i3 = function (a, b, c, d, e) {
        _super.prototype.i3.call(this, a, b, c, d, e);
        var f = this.a0.a$h.item(d);
        f.ay(c);
        if (this.cc(f)) {
            return;
        }
        this.nq(f);
    };
    ScatterAreaSeries.prototype.nq = function (a) {
        if (this.cc(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.lr;
        var i = this.ls;
        var j = this.getEffectiveViewport1(a);
        var k = new ScalerParams(1, b, c, h.b8);
        k.c = j;
        var l = new ScalerParams(1, b, c, i.b8);
        l.c = j;
        g = this.nf(a, k, l);
        if (g != null) {
            e.b5(g);
        }
        else {
            e.b8(f);
        }
    };
    ScatterAreaSeries.prototype.nn = 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.bx;
        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.bx = f;
    };
    ScatterAreaSeries.prototype.fl = function (a) {
        var b = truncate(Math.round(this.lp.width));
        var c = truncate(Math.round(this.lp.height));
        var d = this.bi.bx;
        if (d == null || d.length != (b * c) || this.l1 == null || this.l1.count < 1 || this.l2 == null || this.l2.count < 1 || this.l3 == null || this.l3.count < 1) {
            return null;
        }
        var e = this.bs.m1;
        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.l1.count) {
            return null;
        }
        var l = this.m9.length;
        var m = this.l1.item(k);
        var n = this.l2.item(k);
        var o = this.l3.item(k);
        if ((m >= l) || (n >= l) || (o >= l)) {
            return null;
        }
        var p = (this.m9[m] - this.lp.left) / this.lp.width;
        var q = (this.na[m] - this.lp.top) / this.lp.height;
        var r = (this.m9[n] - this.lp.left) / this.lp.width;
        var s = (this.na[n] - this.lp.top) / this.lp.height;
        var t = (this.m9[o] - this.lp.left) / this.lp.width;
        var u = (this.na[o] - this.lp.top) / this.lp.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.bz.item(m);
        }
        if (w < v && w < x) {
            return this.bz.item(n);
        }
        if (x < v && x < w) {
            return this.bz.item(o);
        }
        return this.bz.item(m);
    };
    ScatterAreaSeries.prototype.nf = 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.ed();
        var g = a;
        var h = this.lr;
        var i = this.ls;
        var j = this.l1.count;
        var k;
        var xArr_ = this.l4.asArray();
        k = (xArr_.slice(0));
        var l;
        var yArr_ = this.l5.asArray();
        l = (yArr_.slice(0));
        var m = this.nh.asArray();
        var n = this.l1.asArray();
        var o = this.l2.asArray();
        var p = this.l3.asArray();
        this.m9 = k;
        this.na = l;
        h.gh(boxArray$1(k), 0, k.length, b);
        i.gh(boxArray$1(l), 0, l.length, c);
        var q = this.nd();
        var r = g.bz(b.d, q, this.nh);
        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.nn(g);
        var aa = g.bx;
        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.ni = function () {
        var a = new Color();
        var b = this.ku;
        if (b == null) {
            a = this.m8[this.fd % this.m8.length];
        }
        else {
            a = ColorUtil.j(b);
        }
        var c = new ObservableColorCollection();
        c.add(ColorUtil.o(a, -0.5));
        c.add(a);
        return c;
    };
    ScatterAreaSeries.prototype.nd = function () {
        var _this = this;
        var a = this.nc;
        if (a == null) {
            a = ((function () {
                var $ret = new CustomPaletteColorScale();
                $ret.palette = _this.ni();
                $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.ni();
            }
            a = b;
        }
        return a;
    };
    ScatterAreaSeries.prototype.ho = function (a, b) {
        _super.prototype.ho.call(this, a, b);
        var c = b;
        c.b4();
    };
    ScatterAreaSeries.prototype.bf = function () {
        return new ScatterAreaSeriesView(this);
    };
    ScatterAreaSeries.prototype.il = function (a) {
        _super.prototype.il.call(this, a);
        this.ne = typeCast(ScatterAreaSeriesView.$, a);
    };
    ScatterAreaSeries.prototype.no = function (a) {
        if (this.ne != null) {
            this.ne.b3(a);
        }
    };
    ScatterAreaSeries.$t = markType(ScatterAreaSeries, 'ScatterAreaSeries', ScatterTriangulationSeries.$);
    return ScatterAreaSeries;
}(ScatterTriangulationSeries));
export { ScatterAreaSeries };
Type.dep(DependencyProperty, PropertyMetadata, ScatterAreaSeries, 'raisePropertyChanged', ['ColorMemberPath:nk:nr', [2, null]]);
var ScatterAreaSeriesView = /** @class */ (function (_super) {
    tslib_1.__extends(ScatterAreaSeriesView, _super);
    function ScatterAreaSeriesView(a) {
        var _this = _super.call(this, a) || this;
        _this.by = null;
        _this.bu = null;
        _this.b2 = null;
        _this.b1 = null;
        _this.b0 = null;
        _this.by = a;
        return _this;
    }
    Object.defineProperty(ScatterAreaSeriesView.prototype, "bx", {
        get: function () {
            return this.bu;
        },
        set: function (a) {
            this.bu = a;
        },
        enumerable: true,
        configurable: true
    });
    ScatterAreaSeriesView.prototype.b7 = function (a, b) {
    };
    ScatterAreaSeriesView.prototype.b3 = function (a) {
    };
    ScatterAreaSeriesView.prototype.bv = function () {
        return this.bw(true);
    };
    ScatterAreaSeriesView.prototype.bw = function (a) {
        this.b6();
        var b = truncate(Math.round(this.br.left));
        var c = truncate(Math.round(this.br.left));
        var d = truncate(Math.round(this.br.width));
        var e = truncate(Math.round(this.br.height));
        var f = d.toString();
        var g = e.toString();
        if (this.b1.getAttribute("width") != f) {
            this.b1.setAttribute("width", d.toString());
        }
        if (this.b1.getAttribute("height") != g) {
            this.b1.setAttribute("height", e.toString());
        }
        var h = this.b0.g();
        if (a) {
            h.clearRect(0, 0, d, e);
        }
        this.b2 = h.getImageData(0, 0, d, e);
        var imageDataArray_ = this.b2.data;
        return imageDataArray_;
    };
    ScatterAreaSeriesView.prototype.b6 = function () {
        if (this.b1 == null) {
            this.b1 = this.e.e0.createElement("canvas");
            var a = this.e.e0.get2DCanvasContext(this.b1);
            this.b0 = new RenderingContext(new CanvasViewRenderer(), a);
        }
    };
    ScatterAreaSeriesView.prototype.bz = function (a, b, c) {
        var d = truncate(Math.round(this.br.left));
        var e = truncate(Math.round(this.br.left));
        var f = truncate(Math.round(this.br.width));
        var g = truncate(Math.round(this.br.height));
        return new TriangleRasterizer(this.bv(), b, c.minimum, c.maximum, c, f, g);
    };
    ScatterAreaSeriesView.prototype.b5 = function (a) {
        this.b8(null);
    };
    ScatterAreaSeriesView.prototype.b4 = function () {
        if (this.b0 != null) {
            this.b0.k(this.br.left, this.br.top, this.br.width, this.br.height);
        }
        this.an();
    };
    ScatterAreaSeriesView.prototype.a3 = function (a, b) {
        _super.prototype.a3.call(this, a, b);
        if (this.b1 == null) {
            return;
        }
        if (b) {
            var c = new Rectangle();
            c.n = this.br.left;
            c.o = this.br.top;
            c.width = this.br.width;
            c.height = this.br.height;
            c._fill = this.bl();
            a.v(c);
        }
        else {
            var d = truncate(Math.round(this.br.left));
            var e = truncate(Math.round(this.br.top));
            var f = truncate(Math.round(this.br.width));
            var g = truncate(Math.round(this.br.height));
            a.m(this.b1.getNativeElement(), 1, d, e, f, g);
        }
    };
    ScatterAreaSeriesView.prototype.b8 = function (a) {
        var b = truncate(Math.round(this.br.left));
        var c = truncate(Math.round(this.br.left));
        var d = truncate(Math.round(this.br.width));
        var e = truncate(Math.round(this.br.height));
        this.b6();
        this.b0.g().putImageData(this.b2, 0, 0);
        this.an();
    };
    ScatterAreaSeriesView.prototype.ai = function (a) {
        _super.prototype.ai.call(this, a);
        var b = truncate(Math.round(this.br.width));
        var c = truncate(Math.round(this.br.height));
        var d = this.bw(false);
        if (d == null || d.length == 0) {
            this.e.a2.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.a2.exportSeriesPixelsData(a, e, b, c);
    };
    ScatterAreaSeriesView.prototype.getDefaultTooltipTemplate = function () {
        var a = "<div class='ui-chart-default-tooltip-content'><span";
        var b = this.e.a0.a$q(this.e);
        if (!stringIsNullOrEmpty(b)) {
            a += " style='color:" + b + "'";
        }
        a += ">" + this.by.fr + "</span><br/><span>" + "(${item." + this.by.mp + "}, ${item." + this.by.mt + "})</span>";
        if (!stringIsNullOrEmpty(this.by.nk)) {
            a += "<span>, Value: ${item." + this.by.nk + "}</span>";
        }
        a += "</div>";
        return a;
    };
    ScatterAreaSeriesView.$t = markType(ScatterAreaSeriesView, 'ScatterAreaSeriesView', SeriesView.$);
    return ScatterAreaSeriesView;
}(SeriesView));
export { ScatterAreaSeriesView };
