/*
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 { Series } from "./Series";
import { NumericXAxis } from "./NumericXAxis";
import { DependencyProperty } from "igniteui-react-core";
import { NumericYAxis } from "./NumericYAxis";
import { Color } from "igniteui-react-core";
import { ScatterFrame } from "./ScatterFrame";
import { Defaults } from "./Defaults";
import { KDTree2D } from "./KDTree2D";
import { Point_$type, typeGetValue, runOn, delegateRemove, typeCast, delegateCombine, markType, markDep, toNullable } from "igniteui-react-core";
import { DataLegendSeriesValueInfo } from "igniteui-react-core";
import { DataLegendSeriesContext } from "igniteui-react-core";
import { List$1 } from "igniteui-react-core";
import { Rect } from "igniteui-react-core";
import { IFastItemsSource_$type } from "igniteui-react-core";
import { BrushUtil } from "igniteui-react-core";
import { SeriesView } from "./SeriesView";
import { KDPointData } from "./KDPointData";
import { ScalerParams } from "./ScalerParams";
import { ProgressiveLoadStatusEventArgs } from "./ProgressiveLoadStatusEventArgs";
import { SearchArgs } from "./SearchArgs";
import { KDTreeNode2D } from "./KDTreeNode2D";
import { AxisRange } from "./AxisRange";
import { PropertyMetadata } from "igniteui-react-core";
import { truncate, isNaN_, isInfinity, logBase, intDivide } from "igniteui-react-core";
import { boxArray$1, arrayShallowClone } from "igniteui-react-core";
import { dateNow } from "igniteui-react-core";
import { RenderingContext } from "igniteui-react-core";
import { CanvasViewRenderer } from "igniteui-react-core";
import { Rectangle } from "igniteui-react-core";
/**
 * @hidden
 */
var HighDensityScatterSeries = /** @class */ /*@__PURE__*/ (function (_super) {
    __extends(HighDensityScatterSeries, _super);
    function HighDensityScatterSeries() {
        var _this = _super.call(this) || this;
        _this.ug = null;
        _this.ui = null;
        _this.vr = 0;
        _this.uk = false;
        _this.u6 = Defaults.aq.o;
        _this.u5 = Defaults.aq.n;
        _this.u4 = Defaults.aq.m;
        _this.u3 = Defaults.aq.l;
        _this.u2 = Defaults.ap.o;
        _this.u1 = Defaults.ap.n;
        _this.u0 = Defaults.ap.m;
        _this.uz = Defaults.ap.l;
        _this.t8 = null;
        _this.ud = null;
        _this.ue = null;
        _this.t9 = null;
        _this.ub = null;
        _this.um = false;
        _this.vs = 0;
        _this.vu = 0;
        _this.vo = 0;
        _this.vn = 0;
        _this.progressiveLoadStatusChanged = null;
        _this.ur = null;
        _this.ux = 0;
        _this.uw = 0;
        _this.uy = 0;
        _this.vd = 0;
        _this.vb = 0;
        _this.vc = 0;
        _this.ve = 0;
        _this.vg = 0;
        _this.vi = 0;
        _this.vh = 0;
        _this.vf = 0;
        _this.ut = 0;
        _this.uu = 0;
        _this.uv = 0;
        _this.us = 0;
        _this.vq = 0;
        _this.vp = 0;
        _this.t5 = null;
        _this.vt = 0;
        _this.ul = false;
        _this._itemIndexes = null;
        _this.t6 = null;
        _this.t3 = null;
        _this.uf = null;
        _this.ab = HighDensityScatterSeries.$;
        _this.fl = false;
        return _this;
    }
    HighDensityScatterSeries.prototype.bc = function () {
        return new HighDensityScatterSeries();
    };
    HighDensityScatterSeries.prototype.get_e2 = function () {
        return true;
    };
    HighDensityScatterSeries.prototype.iq = function () {
        if (!isNaN_(this.ip)) {
            return _super.prototype.iq.call(this);
        }
        return Defaults.q;
    };
    HighDensityScatterSeries.prototype.get_fa = function () {
        return true;
    };
    Object.defineProperty(HighDensityScatterSeries.prototype, "uh", {
        get: function () {
            return this.ug;
        },
        set: function (a) {
            if (this.ug != a) {
                var b = this.uh;
                this.ug = a;
                this.raisePropertyChanged("XColumn", b, this.uh);
            }
        },
        enumerable: false,
        configurable: true
    });
    HighDensityScatterSeries.prototype.getDataLegendSeriesContextAt = function (a, b) {
        var c = { $type: Point_$type, x: a, y: b };
        var d = this.js(c);
        var e = d == null ? NaN : this.h2(d, "XMemberPath");
        var f = d == null ? NaN : this.h2(d, "YMemberPath");
        var g = new DataLegendSeriesValueInfo();
        g.l = e;
        g.a = 13;
        g.p = "X";
        g.q = this.wd != null ? this.wd : "X";
        g.r = this.v9 != null ? this.v9 : "X:";
        g.s = this.wb != null ? this.wb : "";
        var h = new DataLegendSeriesValueInfo();
        h.l = f;
        h.a = 14;
        h.p = "Y";
        h.q = this.wl != null ? this.wl : "Y";
        h.r = this.wh != null ? this.wh : "Y:";
        h.s = this.wj != null ? this.wj : "";
        var i = new DataLegendSeriesContext();
        i.f = ((function () {
            var $ret = new List$1(DataLegendSeriesValueInfo.$, 0);
            $ret.add(g);
            $ret.add(h);
            return $ret;
        })());
        i.b = this.aw();
        return i;
    };
    HighDensityScatterSeries.prototype.jv = function (a, b) {
        var c = this.lw(b);
        if (c == HighDensityScatterSeries.$$p[10]) {
            return this.jw(a, b, this.wd);
        }
        if (c == HighDensityScatterSeries.$$p[14]) {
            return this.jw(a, b, this.wl);
        }
        return _super.prototype.jv.call(this, a, b);
    };
    Object.defineProperty(HighDensityScatterSeries.prototype, "uj", {
        get: function () {
            return this.ui;
        },
        set: function (a) {
            if (this.ui != a) {
                var b = this.uj;
                this.ui = a;
                this.raisePropertyChanged("YColumn", b, this.uj);
            }
        },
        enumerable: false,
        configurable: true
    });
    HighDensityScatterSeries.prototype.w0 = function () {
        if (this.t8 == null) {
            return;
        }
        this.t8.s();
        var a = this.t8;
        a.progressiveThunkCompleted = delegateRemove(a.progressiveThunkCompleted, runOn(this, this.wn));
        this.t8 = null;
    };
    HighDensityScatterSeries.prototype.pa = function (a, b, c, d) {
        _super.prototype.pa.call(this, a, b, c, d);
        switch (b) {
            case "SeriesViewer":
                if (this.cv != null) {
                    var e = this.getEffectiveViewport1(this.cg);
                    this.ul = !e.isEmpty;
                }
                break;
            case "FastItemsSource":
                this.w0();
                if (typeCast(IFastItemsSource_$type, c) != null) {
                    c.deregisterColumn(this.uh);
                    c.deregisterColumn(this.uj);
                    this.uh = null;
                    this.uj = null;
                }
                if (typeCast(IFastItemsSource_$type, d) != null) {
                    this.uh = this.c4(this.wd);
                    this.uj = this.c4(this.wl);
                }
                if ((this.uc != null && !this.uc.c1()) || (this.ua != null && !this.ua.c1())) {
                    this.pr(this.fr && c != null);
                }
                this.on();
                break;
            case HighDensityScatterSeries.$$p[7]:
                var f = this.t9;
                this.t9 = this.ua;
                this.w0();
                if (f != null) {
                    f.rangeChanged = delegateRemove(f.rangeChanged, runOn(this, this.wq));
                }
                if (this.t9 != null) {
                    var g = this.t9;
                    g.rangeChanged = delegateCombine(g.rangeChanged, runOn(this, this.wq));
                }
                if (c != null) {
                    c.b0(this);
                }
                if (d != null) {
                    d.ct(this);
                }
                if ((this.ua != null && !this.ua.c1()) || (d == null && c != null)) {
                    this.pr(false);
                }
                break;
            case HighDensityScatterSeries.$$p[11]:
                var h = this.ub;
                this.ub = this.uc;
                this.w0();
                if (h != null) {
                    h.rangeChanged = delegateRemove(h.rangeChanged, runOn(this, this.wq));
                }
                if (this.ub != null) {
                    var i = this.ub;
                    i.rangeChanged = delegateCombine(i.rangeChanged, runOn(this, this.wq));
                }
                if (c != null) {
                    c.b0(this);
                }
                if (d != null) {
                    d.ct(this);
                }
                if ((this.uc != null && !this.uc.c1()) || (d == null && c != null)) {
                    this.pr(false);
                }
                break;
            case "MouseOverEnabled":
                this.um = this.fl;
                this.pr(false);
                break;
            case HighDensityScatterSeries.$$p[10]:
                if (this.c7 != null) {
                    this.c7.deregisterColumn(this.uh);
                    this.uh = this.c4(this.wd);
                }
                break;
            case "XColumn":
                this.w0();
                if (this.ua != null && !this.ua.c1()) {
                    this.pr(false);
                }
                this.on();
                break;
            case HighDensityScatterSeries.$$p[14]:
                if (this.c7 != null) {
                    this.c7.deregisterColumn(this.uj);
                    this.uj = this.c4(this.wl);
                }
                break;
            case "YColumn":
                this.w0();
                if (this.uc != null && !this.uc.c1()) {
                    this.pr(false);
                }
                this.on();
                break;
            case HighDensityScatterSeries.$$p[6]:
                this.w0();
                this.pr(false);
                this.om();
                break;
            case HighDensityScatterSeries.$$p[3]:
                this.pr(false);
                this.om();
                break;
            case HighDensityScatterSeries.$$p[1]:
                this.pr(false);
                this.om();
                break;
            case HighDensityScatterSeries.$$p[0]:
            case HighDensityScatterSeries.$$p[2]:
                if (!this.t7.b4(this.xj, this.xi)) {
                    return;
                }
                this.wu();
                this.pr(false);
                this.om();
                break;
            case HighDensityScatterSeries.$$p[4]:
                this.vr = Math.max(typeGetValue(d) - 1, 0);
                this.uk = this.vr > 0;
                this.pr(false);
                this.om();
                break;
            case HighDensityScatterSeries.$$p[5]:
                this.pr(false);
                this.om();
                break;
        }
    };
    HighDensityScatterSeries.prototype.wu = function () {
        this.u3 = this.xj.l;
        this.u6 = this.xj.o;
        this.u5 = this.xj.n;
        this.u4 = this.xj.m;
        this.uz = this.xi.l;
        this.u2 = this.xi.o;
        this.u1 = this.xi.n;
        this.u0 = this.xi.m;
        this.s4 = BrushUtil.h(truncate(this.u3), truncate(this.u6), truncate(this.u5), truncate(this.u4));
        this.sy = BrushUtil.h(truncate(this.uz), truncate(this.u2), truncate(this.u1), truncate(this.u0));
    };
    HighDensityScatterSeries.prototype.uo = function (a) {
        if (typeCast(NumericYAxis.$, a) !== null) {
            return true;
        }
        return false;
    };
    HighDensityScatterSeries.prototype.un = function (a) {
        if (typeCast(NumericXAxis.$, a) !== null) {
            return true;
        }
        return false;
    };
    HighDensityScatterSeries.prototype.wq = function (a, b) {
        this.w0();
        this.pr(false);
    };
    Object.defineProperty(HighDensityScatterSeries.prototype, "va", {
        get: function () {
            return this.u2 - this.u6;
        },
        enumerable: false,
        configurable: true
    });
    Object.defineProperty(HighDensityScatterSeries.prototype, "u9", {
        get: function () {
            return this.u1 - this.u5;
        },
        enumerable: false,
        configurable: true
    });
    Object.defineProperty(HighDensityScatterSeries.prototype, "u8", {
        get: function () {
            return this.u0 - this.u4;
        },
        enumerable: false,
        configurable: true
    });
    Object.defineProperty(HighDensityScatterSeries.prototype, "u7", {
        get: function () {
            return this.uz - this.u3;
        },
        enumerable: false,
        configurable: true
    });
    HighDensityScatterSeries.prototype.gm = function (a, b, c) {
        var d = _super.prototype.gm.call(this, a, b, c);
        if (this.uc == null || this.ua == null || this.ua.bi == null || this.uc.bi == null || this.uj == null || this.uh == null || this.uj.count < 1 || this.uh.count < 1 || this.uj.count != this.uh.count || this.ua.lx == this.ua.lw || this.uc.lx == this.uc.lw || this.ty.isEmpty) {
            d = false;
        }
        return d;
    };
    Object.defineProperty(HighDensityScatterSeries.prototype, "vy", {
        get: function () {
            return this.vs;
        },
        set: function (a) {
            var b = this.vs;
            this.vs = a;
            this.raisePropertyChanged("ProgressiveStatus", b, this.vs);
        },
        enumerable: false,
        configurable: true
    });
    HighDensityScatterSeries.prototype.ps = function (a) {
        _super.prototype.ps.call(this, a);
        this.ws(a, this.cg);
    };
    HighDensityScatterSeries.prototype.ws = function (a, b) {
        if (this.dm(b)) {
            return;
        }
        if (this.t8 == null && !this.uq) {
            var c = new List$1(KDPointData.$, 2, this.uh.count);
            var d = this.ua;
            var e = this.uc;
            var f = new Rect(0, 0, 0, 1, 1);
            var g = new Rect(0, 0, 0, 1, 1);
            var h = new ScalerParams(1, f, g, d.ch);
            var i = new ScalerParams(1, f, g, e.ch);
            var j_1;
            var k_1;
            var _loop_1 = function (l) {
                j_1 = d.ej(this_1.uh.item(l), h);
                k_1 = e.ej(this_1.uj.item(l), i);
                if (!isNaN_(j_1) && !isNaN_(k_1) && !isInfinity(j_1) && !isInfinity(k_1)) {
                    c.add(((function () {
                        var $ret = new KDPointData();
                        $ret.a = j_1;
                        $ret.b = k_1;
                        $ret.c = l;
                        return $ret;
                    })()));
                }
            };
            var this_1 = this;
            for (var l = 0; l < this.uh.count; l++) {
                _loop_1(l);
            }
            if (this.up) {
                this.vn = 1;
                this.vo = truncate(logBase(c.count, 2)) + 3;
                this.vy = truncate(((this.vn / this.vo) * 100));
                if (this.progressiveLoadStatusChanged != null) {
                    this.progressiveLoadStatusChanged(this, new ProgressiveLoadStatusEventArgs(this.vy));
                }
                this.t8 = KDTree2D.b(c.toArray(), 1);
                var m = this.t8;
                m.progressiveThunkCompleted = delegateCombine(m.progressiveThunkCompleted, runOn(this, this.wn));
                if (!this.t8.f(this.i5)) {
                    var n = this.t8;
                    n.progressiveThunkCompleted = delegateRemove(n.progressiveThunkCompleted, runOn(this, this.wn));
                }
                this.om();
            }
            else {
                var o = dateNow();
                this.t8 = new KDTree2D(0, c.toArray(), 1);
                var p = dateNow();
            }
        }
        if (this.up && !this.uq) {
            this.wt(b);
        }
        else {
            this.wv(b);
        }
    };
    HighDensityScatterSeries.prototype.np = function (a, b, c, d) {
        _super.prototype.np.call(this, a, b, c, d);
        this.w0();
        var e = false;
        if (this.ua != null && !this.ua.c1()) {
            e = true;
        }
        if (this.uc != null && !this.uc.c1()) {
            e = true;
        }
        if (e) {
            this.pr(false);
        }
        this.on();
    };
    HighDensityScatterSeries.prototype.wp = function (a) {
        var b = a;
        var c = this.vq * this.vp;
        if (this.um) {
            if (this._itemIndexes == null || this._itemIndexes.length != c) {
                this._itemIndexes = new Array(c);
                for (var d = 0; d < c; d++) {
                    this._itemIndexes[d] = 0;
                }
            }
            else {
                for (var e = 0; e < c; e++) {
                    this._itemIndexes[e] = 0;
                }
            }
        }
    };
    HighDensityScatterSeries.prototype.wv = function (a) {
        var b;
        var c;
        var d = null;
        if (a.q) {
            d = this._itemIndexes;
        }
        var e = a.getViewInfo(c, b);
        c = e.p0;
        b = e.p1;
        var f = a;
        var g = this.getEffectiveViewport1(a);
        this.ud = new ScalerParams(0, b, c, this.t9.ch, g);
        this.ue = new ScalerParams(0, b, c, this.ub.ch, g);
        this.wo(a);
        this.wp(a);
        var h = this.vq * this.vp;
        if (this.t6 == null || this.t6.length != h) {
            this.t6 = new Array(h);
            this.t3 = new Array(h);
        }
        var i = this.t6.length;
        var j = this.t6;
        var k = this.t3;
        for (var l = 0; l < i; l++) {
            j[l] = 0;
            k[l] = 0;
        }
        this.vu = truncate(Math.round(this.hk));
        this.t5 = f.b1();
        var m = this.t5.length;
        var n = this.t5;
        for (var o = 0; o < m; o++) {
            n[o] = 0;
        }
        var p = this.vl;
        var q = this.vk;
        if (isNaN_(p) || isInfinity(p)) {
            p = 0;
        }
        if (isNaN_(q) || isInfinity(q)) {
            q = 50;
        }
        this.ux = Math.min(p, q);
        this.uw = Math.max(p, q);
        if (this.ux < 0) {
            this.ux = 0;
        }
        if (this.uw < 0) {
            this.uw = 0;
        }
        this.uy = this.uw - this.ux;
        if (this.uq) {
            this.wr(a);
        }
        else {
            this.w2(a);
        }
        f.cc();
        if (a.q) {
            this._itemIndexes = d;
            this.t7.cd();
        }
    };
    HighDensityScatterSeries.prototype.wt = function (a) {
        if (this.t8 == null) {
            return;
        }
        this.wv(a);
    };
    HighDensityScatterSeries.prototype.wn = function (a, b) {
        var _this = this;
        this.t7.cb(function () {
            if (_this.vn < _this.vo - 1) {
                _this.vn++;
            }
            _this.vy = truncate(((_this.vn / _this.vo) * 100));
            if (_this.progressiveLoadStatusChanged != null) {
                _this.progressiveLoadStatusChanged(_this, new ProgressiveLoadStatusEventArgs(_this.vy));
            }
            _this.wt(_this.cg);
            _this.om();
            if (_this.t8 != null) {
                if (!_this.t8.f(_this.i5)) {
                    var c = _this.t8;
                    c.progressiveThunkCompleted = delegateRemove(c.progressiveThunkCompleted, runOn(_this, _this.wn));
                    _this.vy = 100;
                    if (_this.progressiveLoadStatusChanged != null) {
                        _this.progressiveLoadStatusChanged(_this, new ProgressiveLoadStatusEventArgs(_this.vy));
                    }
                }
            }
        });
    };
    HighDensityScatterSeries.prototype.wr = function (a) {
        var b = arrayShallowClone(this.uh.asArray());
        this.ua.hn(boxArray$1(b), 0, b.length, this.ud);
        var c = arrayShallowClone(this.uj.asArray());
        this.vt = 0;
        var d = this.vr;
        var e = this.uk;
        var f = this.t6.length;
        this.uc.hn(boxArray$1(c), 0, c.length, this.ue);
        var g = 255 << 24 | truncate(this.u6) << 16 | truncate(this.u5) << 8 | truncate(this.u4);
        for (var h = 0; h < b.length; h++) {
            var i = truncate(b[h]);
            var j = truncate(c[h]);
            i = truncate(Math.floor(i));
            j = truncate(Math.floor(j));
            if (i < 0 || i >= this.vq || j < 0 || j >= this.vp) {
                continue;
            }
            if (e) {
                var k = i - d;
                var l = i + d;
                l = l > (this.vq - 1) ? (this.vq - 1) : l;
                k = k < 0 ? 0 : k;
                var m = j + d;
                var n = j - d;
                for (var o = k; o <= l; o++) {
                    for (var p = n; p <= m; p++) {
                        var q = (p * this.vq) + o;
                        if (q < 0 || q > f - 1) {
                            continue;
                        }
                        this.t6[q] = this.t6[q] + 1;
                        this.t3[q] = 1;
                        this.vt++;
                        if (this.um) {
                            this._itemIndexes[q] = h + 1;
                        }
                    }
                }
            }
            else {
                var r = (j * this.vq) + i;
                this.t6[r] = this.t6[r] + 1;
                this.t3[r] = 1;
                this.vt++;
                if (this.um) {
                    this._itemIndexes[r] = h + 1;
                }
            }
        }
        this.ww();
    };
    HighDensityScatterSeries.prototype.w2 = function (a) {
        var b;
        var c;
        var d = a.getViewInfo(b, c);
        b = d.p0;
        c = d.p1;
        if (this.t8 == null) {
            return;
        }
        if (this.ur == null) {
            this.ur = new List$1(KDTreeNode2D.$, 2, truncate(Math.round(b.width * b.height)));
        }
        else {
            this.ur.clear();
        }
        var e = c.left;
        var f = c.right;
        var g = c.top;
        var h = c.bottom;
        this.vh = c.top;
        this.vf = c.height;
        this.vg = c.left;
        this.vi = c.width;
        this.vd = b.top;
        this.vb = b.height;
        this.vc = b.left;
        this.ve = b.width;
        var i = this.getEffectiveViewport1(a);
        this.ut = (i.left - this.vc) / this.ve;
        this.uu = (i.top - this.vd) / this.vb;
        var j = (i.right - this.vc) / this.ve;
        this.uv = j - this.ut;
        var k = (i.bottom - this.vd) / this.vb;
        this.us = k - this.uu;
        if (this.ul) {
            e = (e - this.ut) / this.uv;
            f = (f - this.ut) / this.uv;
            g = (g - this.uu) / this.us;
            h = (h - this.uu) / this.us;
        }
        var l = this.hk / b.width * c.width;
        var m = this.hk / b.height * c.height;
        var n = Math.min(l, m);
        var o = ((function () {
            var $ret = new SearchArgs();
            $ret.c = e;
            $ret.a = f;
            $ret.d = g;
            $ret.b = h;
            $ret.e = l;
            $ret.f = m;
            $ret.g = 0x7FFFFFFF;
            return $ret;
        })());
        this.t8.t(this.ur, o, 0, 1, 0, 1);
        var p;
        this.vt = 0;
        for (var q = 0; q < this.ur.count; q++) {
            p = this.ur._inner[q];
            this.wx(p);
        }
        this.ww();
    };
    HighDensityScatterSeries.prototype.wx = function (a) {
        if (a.g) {
            return;
        }
        var b = a.e != null && a.e.a;
        var c = a.a == null ? 0 : a.a.length;
        var d = (a.h - c) + 1;
        if (b && d > 0) {
        }
        else {
            d = 1;
        }
        this.wz(a.b, d, b, a.e);
        if (c > 0 && !b) {
            var e = void 0;
            for (var f = 0; f < c; f++) {
                e = a.a[f];
                this.wz(e, d, false, a.e);
            }
        }
        if (a.e != null) {
            a.e.a = false;
        }
    };
    HighDensityScatterSeries.prototype.fp = function (a) {
        var b = this.cv != null ? this.cv.tr : Rect.empty;
        var c = this.cv != null ? this.cv.t6 : Rect.empty;
        var d = new Rect(0, 0, 0, 1, 1);
        var e = this.ts(this.cg);
        var f = new ScalerParams(0, d, d, this.ua.ch, e);
        var g = new ScalerParams(0, d, d, this.uc.ch, e);
        var h = !b.isEmpty && !c.isEmpty && this.c7 != null ? this.c7.indexOf(a) : -1;
        var i = this.ua != null && this.uh != null && h < this.uh.count ? this.ua.ej(this.uh.item(h), f) : NaN;
        var j = this.uc != null && this.uj != null && h < this.uj.count ? this.uc.ej(this.uj.item(h), g) : NaN;
        if (!isNaN_(i)) {
            if (i < b.left + 0.1 * b.width) {
                i = i + 0.4 * b.width;
                b.x = i - 0.5 * b.width;
            }
            if (i > b.right - 0.1 * b.width) {
                i = i - 0.4 * b.width;
                b.x = i - 0.5 * b.width;
            }
        }
        if (!isNaN_(j)) {
            if (j < b.top + 0.1 * b.height) {
                j = j + 0.4 * b.height;
                b.y = j - 0.5 * b.height;
            }
            if (j > b.bottom - 0.1 * b.height) {
                j = j - 0.4 * b.height;
                b.y = j - 0.5 * b.height;
            }
        }
        if (this.co != null) {
            this.co.au(this.cv, b, true);
        }
        return h >= 0;
    };
    HighDensityScatterSeries.prototype.wz = function (a, b, c, d) {
        var e = this.vw(b);
        var f = a.c;
        var g = this.vr;
        if (c) {
            var h = d.d;
            var i = d.b;
            var j = d.e;
            var k = d.c;
            if (this.ul) {
                h = this.ut + this.uv * h;
                i = this.ut + this.uv * i;
                j = this.uu + this.us * j;
                k = this.uu + this.us * k;
            }
            var l = truncate((this.vc + this.ve * (h - this.vg) / this.vi));
            var m = truncate((this.vc + this.ve * (i - this.vg) / this.vi));
            var n = truncate((this.vd + this.vb * (j - this.vh) / this.vf));
            var o = truncate((this.vd + this.vb * (k - this.vh) / this.vf));
            l = truncate(Math.floor(l));
            m = truncate(Math.floor(m));
            n = truncate(Math.floor(n));
            o = truncate(Math.floor(o));
            if (this.uk) {
                l -= g;
                m += g;
                n -= g;
                o += g;
            }
            var p = ((m - l) + 1) * ((o - n) + 1);
            var q = b / p;
            var r = q;
            for (var s = l; s <= m; s++) {
                for (var t = n; t <= o; t++) {
                    this.wy(f, s, t, q, r);
                }
            }
        }
        else {
            var u = a.a;
            var v = a.b;
            if (this.ul) {
                u = this.ut + this.uv * u;
                v = this.uu + this.us * v;
            }
            var w = truncate((this.vc + this.ve * (u - this.vg) / this.vi));
            var x = truncate((this.vd + this.vb * (v - this.vh) / this.vf));
            w = truncate(Math.floor(w));
            x = truncate(Math.floor(x));
            if (this.uk) {
                var y = w - g;
                var z = w + g;
                var aa = x + g;
                var ab = x - g;
                var ac = ((z - y) + 1) * ((aa - ab) + 1);
                var ad = b / ac;
                var ae = ad;
                for (var af = y; af <= z; af++) {
                    for (var ag = ab; ag <= aa; ag++) {
                        this.wy(f, af, ag, ad, ae);
                    }
                }
            }
            else {
                this.wy(f, w, x, b, 1);
            }
        }
    };
    HighDensityScatterSeries.prototype.vv = function (a, b) {
        return truncate((Math.floor(255 * b))) << 24 | truncate(Math.floor(b * (this.u6 + a * this.va))) << 16 | truncate(Math.floor(b * (this.u5 + a * this.u9))) << 8 | truncate(Math.floor(b * (this.u4 + a * this.u8)));
    };
    HighDensityScatterSeries.prototype.vw = function (a) {
        return 255 << 24 | truncate(Math.floor((this.u6 + a * this.va))) << 16 | truncate(Math.floor((this.u5 + a * this.u9))) << 8 | truncate(Math.floor((this.u4 + a * this.u8)));
    };
    HighDensityScatterSeries.prototype.vj = function (a) {
        return (a >> 24 & 255) / 255;
    };
    HighDensityScatterSeries.prototype.wy = function (a, b, c, d, e) {
        if (b < 0 || b >= this.vq || c < 0 || c >= this.vp) {
            return;
        }
        var f = (c * this.vq) + b;
        this.t6[f] = this.t6[f] + d;
        this.t3[f] = this.t3[f] + e;
        if (this.um) {
            this._itemIndexes[f] = a + 1;
        }
        this.vt += truncate(d);
    };
    HighDensityScatterSeries.prototype.ww = function () {
        var a = 0;
        var b = 0;
        var c = this.uy;
        var d = this.ux;
        var e = this.uw;
        var f = this.t6.length;
        var g = this.t6;
        var h = this.t3;
        var i = this.t5;
        var j = NaN;
        var k = NaN;
        var l = 0;
        var m = 0;
        for (var n = 0; n < f; n++) {
            a = g[n];
            if (a != 0) {
                b = h[n];
                if (a >= e) {
                    a = 1;
                }
                else if (a <= d) {
                    a = 0;
                }
                else {
                    a = (a - d) / (c);
                }
                if (b > 1) {
                    b = 1;
                }
                if (b < 0.2) {
                    b = 0.2;
                }
                if (j != a || k != b) {
                    l = this.vv(a, b);
                    j = a;
                    k = b;
                }
                i[m] = l >> 16 & 255;
                i[m + 1] = l >> 8 & 255;
                i[m + 2] = l & 255;
                i[m + 3] = l >> 24 & 255;
            }
            m += 4;
        }
    };
    HighDensityScatterSeries.prototype.wo = function (a) {
        var b = a;
        b.b9();
    };
    HighDensityScatterSeries.prototype.cd = function () {
        return new HighDensityScatterSeriesView(this);
    };
    HighDensityScatterSeries.prototype.o2 = function (a) {
        _super.prototype.o2.call(this, a);
        this.t7 = a;
    };
    HighDensityScatterSeries.prototype.aq = function (a) {
        if (a != null && a == this.ua && this.uh != null) {
            return new AxisRange(this.uh.minimum, this.uh.maximum);
        }
        if (a != null && a == this.uc && this.uj != null) {
            return new AxisRange(this.uj.minimum, this.uj.maximum);
        }
        return null;
    };
    HighDensityScatterSeries.prototype.qo = function (a, b) {
        if (this.cv != null) {
            var c = this.getEffectiveViewport1(this.cg);
            this.ul = !c.isEmpty;
        }
        this.pr(false);
    };
    HighDensityScatterSeries.prototype.qp = function (a, b) {
        this.pr(false);
    };
    HighDensityScatterSeries.prototype.js = function (a) {
        if (!this.um || this._itemIndexes == null || this.cv == null || this.c7 == null || this._itemIndexes.length != (this.vq * this.vp)) {
            return null;
        }
        var b = this.cv.tr;
        var c = (a.x - b.left) / b.width;
        var d = (a.y - b.top) / b.height;
        var e = truncate(Math.round(this.ty.left + (this.ty.width * c)));
        var f = truncate(Math.round(this.ty.top + (this.ty.height * d)));
        var g = this.vz(e, f);
        if (g < 0 || g > this._itemIndexes.length - 1) {
            return null;
        }
        var h = this._itemIndexes[g] - 1;
        if (h < 0 || h > this.c7.count) {
            return null;
        }
        return this.c7.item(h);
    };
    HighDensityScatterSeries.prototype.vz = function (a, b) {
        var c = (this.vq * b) + a;
        if (c > 0 && c < this._itemIndexes.length && this._itemIndexes[c] > 0) {
            return c;
        }
        var d = 1;
        c = (this.vq * (b - d)) + a;
        if (c > 0 && c < this._itemIndexes.length && this._itemIndexes[c] > 0) {
            return c;
        }
        c = (this.vq * (b + d)) + a;
        if (c > 0 && c < this._itemIndexes.length && this._itemIndexes[c] > 0) {
            return c;
        }
        c = (this.vq * (b)) + a - 1;
        if (c > 0 && c < this._itemIndexes.length && this._itemIndexes[c] > 0) {
            return c;
        }
        c = (this.vq * (b)) + a + 1;
        if (c > 0 && c < this._itemIndexes.length && this._itemIndexes[c] > 0) {
            return c;
        }
        c = (this.vq * (b - d)) + a - 1;
        if (c > 0 && c < this._itemIndexes.length && this._itemIndexes[c] > 0) {
            return c;
        }
        c = (this.vq * (b + d)) + a + 1;
        if (c > 0 && c < this._itemIndexes.length && this._itemIndexes[c] > 0) {
            return c;
        }
        c = (this.vq * (b - d)) + a + 1;
        if (c > 0 && c < this._itemIndexes.length && this._itemIndexes[c] > 0) {
            return c;
        }
        c = (this.vq * (b + d)) + a - 1;
        if (c > 0 && c < this._itemIndexes.length && this._itemIndexes[c] > 0) {
            return c;
        }
        return 0;
    };
    HighDensityScatterSeries.prototype.w1 = function (a, b, c) {
        this.t5 = a;
        this.vq = b;
        this.vp = c;
    };
    HighDensityScatterSeries.prototype.get_gg = function () {
        return true;
    };
    HighDensityScatterSeries.prototype.set_gg = function (a) {
        _super.prototype.set_gg.call(this, a);
    };
    HighDensityScatterSeries.prototype.nk = function (a, b) {
        _super.prototype.nk.call(this, a, b);
        this.t7.ca();
        if (this.cf != null) {
            this.cf.ca();
        }
        this.om();
    };
    HighDensityScatterSeries.prototype.pt = function (a, b) {
        _super.prototype.pt.call(this, a, b);
        if (!this.f9) {
            this.cg.a4(b);
            return;
        }
        this.cg.a4(b);
        if (this.dm(this.cf)) {
            return;
        }
        var c = typeCast(HighDensityScatterSeriesView.$, this.cf);
        var d = new ScatterFrame();
        this.ws(false, c);
        this.f9 = false;
    };
    HighDensityScatterSeries.prototype.pq = function (a, b, c, d, e) {
        _super.prototype.pq.call(this, a, b, c, d, e);
        var f = this.a3.a$h.item(d);
        var g = f;
        f.a3(c);
        if (this.dm(g)) {
            return;
        }
        if (this.uf == null) {
            this.uf = new ScatterFrame();
        }
        this.ws(false, f);
    };
    HighDensityScatterSeries.prototype.nh = function () {
        _super.prototype.nh.call(this);
        this.ua = null;
        this.uc = null;
    };
    HighDensityScatterSeries.$t = markType(HighDensityScatterSeries, 'HighDensityScatterSeries', Series.$);
    HighDensityScatterSeries.$$p = markDep(DependencyProperty, PropertyMetadata, HighDensityScatterSeries, 'raisePropertyChanged', ['HeatMaximumColor:xi:w3', [Color.$, Defaults.ap], 'HeatMaximum:vk:w4', [1, 50], 'HeatMinimumColor:xj:w5', [Color.$, Defaults.aq], 'HeatMinimum:vl:w6', [1, 0], 'PointExtent:vx:w7', [1, 1], 'ProgressiveLoad:up:w8', [0, true], 'UseBruteForce:uq:w9', [0, false], 'XAxis:ua:xa', [NumericXAxis.$, null], 'XMemberAsLegendLabel:v9:xb', [2, null], 'XMemberAsLegendUnit:wb:xc', [2, null], 'XMemberPath:wd:xd', [2, null], 'YAxis:uc:xe', [NumericYAxis.$, null], 'YMemberAsLegendLabel:wh:xf', [2, null], 'YMemberAsLegendUnit:wj:xg', [2, null], 'YMemberPath:wl:xh', [2, null]]);
    return HighDensityScatterSeries;
}(Series));
export { HighDensityScatterSeries };
/**
 * @hidden
 */
var HighDensityScatterSeriesView = /** @class */ /*@__PURE__*/ (function (_super) {
    __extends(HighDensityScatterSeriesView, _super);
    function HighDensityScatterSeriesView(a) {
        var _this = _super.call(this, a) || this;
        _this.b2 = null;
        _this.b0 = null;
        _this.b8 = 0;
        _this.b7 = 0;
        _this.b5 = null;
        _this.b6 = null;
        _this.b3 = null;
        _this.b2 = a;
        return _this;
    }
    HighDensityScatterSeriesView.prototype.au = function () {
        _super.prototype.au.call(this);
        if (!this.q) {
            this.b2.xj = Defaults.aq;
            this.b2.xi = Defaults.ap;
            this.b2.sy = Defaults.al;
            this.b2.s4 = Defaults.ak;
        }
    };
    HighDensityScatterSeriesView.prototype.cd = function () {
        this.b2.w1(this.b0, this.b8, this.b7);
    };
    HighDensityScatterSeriesView.prototype.b9 = function () {
        if (this.b5 == null) {
            this.b5 = this.e.i5.createElement("canvas");
            var a = this.e.i5.get2DCanvasContext(this.b5);
            this.b3 = new RenderingContext(new CanvasViewRenderer(), a);
        }
        var b;
        if (this.p) {
            b = this.bx;
        }
        else {
            b = this.e.cv.tw();
        }
        var c = truncate(Math.round(b.left));
        var d = truncate(Math.round(b.top));
        var e = truncate(Math.round(b.width));
        var f = truncate(Math.round(b.height));
        var g = this.b8;
        var h = this.b7;
        this.b8 = e;
        this.b7 = f;
        if (g != this.b8 || h != this.b7 || this.b0 == null) {
            this.b5.setAttribute("width", e.toString());
            this.b5.setAttribute("height", f.toString());
            this.b6 = this.b3.h().getImageData(0, 0, e, f);
            var imageDataArray_ = this.b6.data;
            this.b0 = imageDataArray_;
        }
        this.b2.w1(this.b0, this.b8, this.b7);
    };
    HighDensityScatterSeriesView.prototype.b1 = function () {
        return this.b0;
    };
    HighDensityScatterSeriesView.prototype.cc = function () {
        var a = truncate(Math.round(this.bx.left));
        var b = truncate(Math.round(this.bx.left));
        var c = truncate(Math.round(this.bx.width));
        var d = truncate(Math.round(this.bx.height));
        this.b3.h().putImageData(this.b6, 0, 0);
        this.as();
    };
    HighDensityScatterSeriesView.prototype.cb = function (a) {
        if (this.e.i5 != null) {
            this.e.i5.setTimeout(a, 0);
        }
        else {
            window.setTimeout(a, 0);
        }
    };
    HighDensityScatterSeriesView.prototype.a8 = function (a, b) {
        _super.prototype.a8.call(this, a, b);
        if (b) {
            if (!this.b2.fl) {
                return;
            }
            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);
            return;
        }
        if (this.b5 == null) {
            return;
        }
        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));
        this.k.o(this.b5.getNativeElement(), this.e._opacity, d, e, f, g, d, e, f, g);
    };
    HighDensityScatterSeriesView.prototype.b4 = function (a, b) {
        return Color.e(toNullable(Color.$, a), toNullable(Color.$, null)) && Color.e(toNullable(Color.$, b), toNullable(Color.$, null));
    };
    HighDensityScatterSeriesView.prototype.ca = function () {
        if (this.b0 != null) {
            for (var a = 0; a < this.b0.length; a++) {
                this.b0[a] = 0;
            }
            this.cc();
        }
    };
    HighDensityScatterSeriesView.prototype.an = function (a) {
        _super.prototype.an.call(this, a);
        if (this.b0 == null) {
            this.e.a5.exportSeriesPixelsData(a, null, this.b8, this.b7);
            return;
        }
        var b = new Array(intDivide(this.b0.length, 4));
        var c;
        for (var d = 0; d < intDivide(this.b0.length, 4); d++) {
            c = d * 4;
            b[d] = this.b0[c + 3] << 24 | this.b0[c] << 16 | this.b0[c + 1] << 8 | this.b0[c + 2];
        }
        this.e.a5.exportSeriesPixelsData(a, b, this.b8, this.b7);
    };
    HighDensityScatterSeriesView.$t = markType(HighDensityScatterSeriesView, 'HighDensityScatterSeriesView', SeriesView.$);
    return HighDensityScatterSeriesView;
}(SeriesView));
export { HighDensityScatterSeriesView };
