/*
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";
/**
 * @hidden
 */
var ScatterAreaSeries = /** @class */ (function (_super) {
    tslib_1.__extends(ScatterAreaSeries, _super);
    function ScatterAreaSeries() {
        var _this = _super.call(this) || this;
        _this.nd = null;
        _this.ni = null;
        _this.nb = null;
        _this.nc = null;
        _this.na = [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, "ne", {
        get: function () {
            return this.nd;
        },
        set: function (a) {
            var b = this.nd != a;
            if (b) {
                var c = this.nd;
                if (this.nd != null) {
                    var d = this.nd;
                    d.propertyChanged = delegateRemove(d.propertyChanged, runOn(this, this.nr));
                }
                this.nd = a;
                if (this.nd != null) {
                    var e = this.nd;
                    e.propertyChanged = delegateCombine(e.propertyChanged, runOn(this, this.nr));
                }
                this.raisePropertyChanged("ColorScale", c, this.nd);
            }
        },
        enumerable: true,
        configurable: true
    });
    ScatterAreaSeries.prototype.nr = function (a, b) {
        this.i6(false);
    };
    Object.defineProperty(ScatterAreaSeries.prototype, "nj", {
        get: function () {
            return this.ni;
        },
        set: function (a) {
            var b = this.nj != a;
            if (b) {
                var c = this.nj;
                this.ni = a;
                this.raisePropertyChanged("ColorColumn", c, this.nj);
            }
        },
        enumerable: true,
        configurable: true
    });
    ScatterAreaSeries.prototype.get_dp = function () {
        return true;
    };
    ScatterAreaSeries.prototype.set_dp = function (a) {
        _super.prototype.set_dp.call(this, a);
    };
    ScatterAreaSeries.prototype.is = function (a, b, c, d) {
        _super.prototype.is.call(this, a, b, c, d);
        switch (b) {
            case "FastItemsSource":
                var e = typeCast(IFastItemsSource_$type, c);
                if (e != null) {
                    e.deregisterColumn(this.nj);
                    this.nj = null;
                }
                var f = typeCast(IFastItemsSource_$type, d);
                if (f != null) {
                    this.nj = this.bw(this.nm);
                }
                this.i6(false);
                break;
            case ScatterAreaSeries.$$p[0]:
                if (this.bz != null) {
                    this.bz.deregisterColumn(this.nj);
                    this.nj = this.bw(this.nm);
                }
                this.i6(false);
                this.ic();
                break;
            case "ColorScale":
                this.i6(false);
                this.ic();
                break;
        }
    };
    ScatterAreaSeries.prototype.i7 = function (a) {
        _super.prototype.i7.call(this, a);
        this.ns(this.bi);
    };
    ScatterAreaSeries.prototype.i5 = function (a, b, c, d, e) {
        _super.prototype.i5.call(this, a, b, c, d, e);
        var f = this.a0.a$h.item(d);
        f.ay(c);
        if (this.cc(f)) {
            return;
        }
        this.ns(f);
    };
    ScatterAreaSeries.prototype.ns = 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.lt;
        var i = this.lu;
        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.nh(a, k, l);
        if (g != null) {
            e.b5(g);
        }
        else {
            e.b8(f);
        }
    };
    ScatterAreaSeries.prototype.np = 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.fm = function (a) {
        var b = truncate(Math.round(this.lr.width));
        var c = truncate(Math.round(this.lr.height));
        var d = this.bi.bx;
        if (d == null || d.length != (b * c) || this.l3 == null || this.l3.count < 1 || this.l4 == null || this.l4.count < 1 || this.l5 == null || this.l5.count < 1) {
            return null;
        }
        var e = this.bs.m4;
        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.l3.count) {
            return null;
        }
        var l = this.nb.length;
        var m = this.l3.item(k);
        var n = this.l4.item(k);
        var o = this.l5.item(k);
        if ((m >= l) || (n >= l) || (o >= l)) {
            return null;
        }
        var p = (this.nb[m] - this.lr.left) / this.lr.width;
        var q = (this.nc[m] - this.lr.top) / this.lr.height;
        var r = (this.nb[n] - this.lr.left) / this.lr.width;
        var s = (this.nc[n] - this.lr.top) / this.lr.height;
        var t = (this.nb[o] - this.lr.left) / this.lr.width;
        var u = (this.nc[o] - this.lr.top) / this.lr.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.nh = 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.ee();
        var g = a;
        var h = this.lt;
        var i = this.lu;
        var j = this.l3.count;
        var k;
        var xArr_ = this.l6.asArray();
        k = (xArr_.slice(0));
        var l;
        var yArr_ = this.l7.asArray();
        l = (yArr_.slice(0));
        var m = this.nj.asArray();
        var n = this.l3.asArray();
        var o = this.l4.asArray();
        var p = this.l5.asArray();
        this.nb = k;
        this.nc = l;
        h.gh(boxArray$1(k), 0, k.length, b);
        i.gh(boxArray$1(l), 0, l.length, c);
        var q = this.nf();
        var r = g.bz(b.d, q, this.nj);
        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.np(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.nk = function () {
        var a = new Color();
        var b = this.kw;
        if (b == null) {
            a = this.na[this.fe % this.na.length];
        }
        else {
            a = ColorUtil.j(b);
        }
        var c = new ObservableColorCollection();
        c.add(ColorUtil.o(a, -0.5));
        c.add(a);
        return c;
    };
    ScatterAreaSeries.prototype.nf = function () {
        var _this = this;
        var a = this.ne;
        if (a == null) {
            a = ((function () {
                var $ret = new CustomPaletteColorScale();
                $ret.palette = _this.nk();
                $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.nk();
            }
            a = b;
        }
        return a;
    };
    ScatterAreaSeries.prototype.hp = function (a, b) {
        _super.prototype.hp.call(this, a, b);
        var c = b;
        c.b4();
    };
    ScatterAreaSeries.prototype.bf = function () {
        return new ScatterAreaSeriesView(this);
    };
    ScatterAreaSeries.prototype.im = function (a) {
        _super.prototype.im.call(this, a);
        this.ng = typeCast(ScatterAreaSeriesView.$, a);
    };
    ScatterAreaSeries.prototype.nq = function (a) {
        if (this.ng != null) {
            this.ng.b3(a);
        }
    };
    ScatterAreaSeries.$t = markType(ScatterAreaSeries, 'ScatterAreaSeries', ScatterTriangulationSeries.$);
    return ScatterAreaSeries;
}(ScatterTriangulationSeries));
export { ScatterAreaSeries };
Type.dep(DependencyProperty, PropertyMetadata, ScatterAreaSeries, 'raisePropertyChanged', ['ColorMemberPath:nm:nt', [2, null]]);
/**
 * @hidden
 */
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.e1.createElement("canvas");
            var a = this.e.e1.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.fs + "</span><br/><span>" + "(${item." + this.by.mr + "}, ${item." + this.by.mv + "})</span>";
        if (!stringIsNullOrEmpty(this.by.nm)) {
            a += "<span>, Value: ${item." + this.by.nm + "}</span>";
        }
        a += "</div>";
        return a;
    };
    ScatterAreaSeriesView.$t = markType(ScatterAreaSeriesView, 'ScatterAreaSeriesView', SeriesView.$);
    return ScatterAreaSeriesView;
}(SeriesView));
export { ScatterAreaSeriesView };
