/*
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 { runOn, delegateRemove, delegateCombine, typeCast, Point_$type, markType, markDep } from "igniteui-angular-core";
import { DependencyProperty } from "igniteui-angular-core";
import { Color } 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 { ColorUtil } from "igniteui-angular-core";
import { CustomPaletteColorScale } from "./CustomPaletteColorScale";
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 */ (function (_super) {
    tslib_1.__extends(ScatterAreaSeries, _super);
    function ScatterAreaSeries() {
        var _this = _super.call(this) || this;
        _this.nk = null;
        _this.np = null;
        _this.ni = null;
        _this.nj = null;
        _this.nh = [Color.u(255, 0, 0, 255), Color.u(255, 0, 255, 0), Color.u(255, 255, 0, 0)];
        FastItemIntColumn.m();
        _this.ab = ScatterAreaSeries.$;
        return _this;
    }
    Object.defineProperty(ScatterAreaSeries.prototype, "nl", {
        get: function () {
            return this.nk;
        },
        set: function (a) {
            var b = this.nk != a;
            if (b) {
                var c = this.nk;
                if (this.nk != null) {
                    var d = this.nk;
                    d.propertyChanged = delegateRemove(d.propertyChanged, runOn(this, this.ny));
                }
                this.nk = a;
                if (this.nk != null) {
                    var e = this.nk;
                    e.propertyChanged = delegateCombine(e.propertyChanged, runOn(this, this.ny));
                }
                this.raisePropertyChanged("ColorScale", c, this.nk);
            }
        },
        enumerable: true,
        configurable: true
    });
    ScatterAreaSeries.prototype.ny = function (a, b) {
        this.jd(false);
    };
    ScatterAreaSeries.prototype.fs = function (a, b) {
        var c = this.gu(b);
        if (c == ScatterAreaSeries.$$p[0]) {
            return this.ft(a, b, this.nt);
        }
        return _super.prototype.fs.call(this, a, b);
    };
    Object.defineProperty(ScatterAreaSeries.prototype, "nq", {
        get: function () {
            return this.np;
        },
        set: function (a) {
            var b = this.nq != a;
            if (b) {
                var c = this.nq;
                this.np = a;
                this.raisePropertyChanged("ColorColumn", c, this.nq);
            }
        },
        enumerable: true,
        configurable: true
    });
    ScatterAreaSeries.prototype.get_dq = function () {
        return true;
    };
    ScatterAreaSeries.prototype.set_dq = function (a) {
        _super.prototype.set_dq.call(this, a);
    };
    ScatterAreaSeries.prototype.iz = function (a, b, c, d) {
        _super.prototype.iz.call(this, a, b, c, d);
        switch (b) {
            case "FastItemsSource":
                var e = typeCast(IFastItemsSource_$type, c);
                if (e != null) {
                    e.deregisterColumn(this.nq);
                    this.nq = null;
                }
                var f = typeCast(IFastItemsSource_$type, d);
                if (f != null) {
                    this.nq = this.bw(this.nt);
                }
                this.jd(false);
                break;
            case ScatterAreaSeries.$$p[0]:
                if (this.bz != null) {
                    this.bz.deregisterColumn(this.nq);
                    this.nq = this.bw(this.nt);
                }
                this.jd(false);
                this.ik();
                break;
            case "ColorScale":
                this.jd(false);
                this.ik();
                break;
        }
    };
    ScatterAreaSeries.prototype.je = function (a) {
        _super.prototype.je.call(this, a);
        this.nz(this.bi);
    };
    ScatterAreaSeries.prototype.jc = function (a, b, c, d, e) {
        _super.prototype.jc.call(this, a, b, c, d, e);
        var f = this.a0.a$h.item(d);
        f.ay(c);
        if (this.cc(f)) {
            return;
        }
        this.nz(f);
    };
    ScatterAreaSeries.prototype.nz = 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.l0;
        var i = this.l1;
        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.no(a, k, l);
        if (g != null) {
            e.b5(g);
        }
        else {
            e.b8(f);
        }
    };
    ScatterAreaSeries.prototype.nw = 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.fp = function (a) {
        var b = truncate(Math.round(this.ly.width));
        var c = truncate(Math.round(this.ly.height));
        var d = this.bi.bx;
        if (d == null || d.length != (b * c) || this.ma == null || this.ma.count < 1 || this.mb == null || this.mb.count < 1 || this.mc == null || this.mc.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.ma.count) {
            return null;
        }
        var l = this.ni.length;
        var m = this.ma.item(k);
        var n = this.mb.item(k);
        var o = this.mc.item(k);
        if ((m >= l) || (n >= l) || (o >= l)) {
            return null;
        }
        var p = (this.ni[m] - this.ly.left) / this.ly.width;
        var q = (this.nj[m] - this.ly.top) / this.ly.height;
        var r = (this.ni[n] - this.ly.left) / this.ly.width;
        var s = (this.nj[n] - this.ly.top) / this.ly.height;
        var t = (this.ni[o] - this.ly.left) / this.ly.width;
        var u = (this.nj[o] - this.ly.top) / this.ly.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.no = 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.eh();
        var g = a;
        var h = this.l0;
        var i = this.l1;
        var j = this.ma.count;
        var k;
        var xArr_ = this.md.asArray();
        k = (xArr_.slice(0));
        var l;
        var yArr_ = this.me.asArray();
        l = (yArr_.slice(0));
        var m = this.nq.asArray();
        var n = this.ma.asArray();
        var o = this.mb.asArray();
        var p = this.mc.asArray();
        this.ni = k;
        this.nj = l;
        h.gn(boxArray$1(k), 0, k.length, b);
        i.gn(boxArray$1(l), 0, l.length, c);
        var q = this.nm();
        var r = g.bz(b.d, q, this.nq);
        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.nw(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.nr = function () {
        var a = new Color();
        var b = this.k3;
        if (b == null) {
            a = this.nh[this.fh % this.nh.length];
        }
        else {
            a = ColorUtil.j(b);
        }
        var c = new ObservableColorCollection();
        c.add(ColorUtil.o(a, -0.5));
        c.add(a);
        return c;
    };
    ScatterAreaSeries.prototype.nm = function () {
        var _this = this;
        var a = this.nl;
        if (a == null) {
            a = ((function () {
                var $ret = new CustomPaletteColorScale();
                $ret.palette = _this.nr();
                $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.nr();
            }
            a = b;
        }
        return a;
    };
    ScatterAreaSeries.prototype.hv = function (a, b) {
        _super.prototype.hv.call(this, a, b);
        var c = b;
        c.b4();
    };
    ScatterAreaSeries.prototype.bf = function () {
        return new ScatterAreaSeriesView(this);
    };
    ScatterAreaSeries.prototype.iu = function (a) {
        _super.prototype.iu.call(this, a);
        this.nn = typeCast(ScatterAreaSeriesView.$, a);
    };
    ScatterAreaSeries.prototype.nx = function (a) {
        if (this.nn != null) {
            this.nn.b3(a);
        }
    };
    ScatterAreaSeries.$t = markType(ScatterAreaSeries, 'ScatterAreaSeries', ScatterTriangulationSeries.$);
    ScatterAreaSeries.$$p = markDep(DependencyProperty, PropertyMetadata, ScatterAreaSeries, 'raisePropertyChanged', ['ColorMemberPath:nt:n0', [2, null]]);
    return ScatterAreaSeries;
}(ScatterTriangulationSeries));
export { ScatterAreaSeries };
/**
 * @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.e4.createElement("canvas");
            var a = this.e.e4.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.fx + "</span><br/><span>" + "(${item." + this.by.my + "}, ${item." + this.by.m2 + "})</span>";
        if (!stringIsNullOrEmpty(this.by.nt)) {
            a += "<span>, Value: ${item." + this.by.nt + "}</span>";
        }
        a += "</div>";
        return a;
    };
    ScatterAreaSeriesView.$t = markType(ScatterAreaSeriesView, 'ScatterAreaSeriesView', SeriesView.$);
    return ScatterAreaSeriesView;
}(SeriesView));
export { ScatterAreaSeriesView };
//# sourceMappingURL=ScatterAreaSeries_combined.js.map