/*
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-angular-core";
import { NumericYAxis } from "./NumericYAxis";
import { Color } from "igniteui-angular-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-angular-core";
import { DataLegendSeriesValueInfo } from "igniteui-angular-core";
import { DataLegendSeriesContext } from "igniteui-angular-core";
import { List$1 } from "igniteui-angular-core";
import { Rect } from "igniteui-angular-core";
import { IFastItemsSource_$type } from "igniteui-angular-core";
import { BrushUtil } from "igniteui-angular-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-angular-core";
import { truncate, isNaN_, isInfinity, logBase, intDivide } from "igniteui-angular-core";
import { boxArray$1, arrayShallowClone } from "igniteui-angular-core";
import { dateNow } from "igniteui-angular-core";
import { RenderingContext } from "igniteui-angular-core";
import { CanvasViewRenderer } from "igniteui-angular-core";
import { Rectangle } from "igniteui-angular-core";
/**
 * @hidden
 */
var HighDensityScatterSeries = /** @class */ /*@__PURE__*/ (function (_super) {
    __extends(HighDensityScatterSeries, _super);
    function HighDensityScatterSeries() {
        var _this = _super.call(this) || this;
        _this.qg = null;
        _this.qi = null;
        _this.rr = 0;
        _this.qk = false;
        _this.q6 = Defaults.aq.o;
        _this.q5 = Defaults.aq.n;
        _this.q4 = Defaults.aq.m;
        _this.q3 = Defaults.aq.l;
        _this.q2 = Defaults.ap.o;
        _this.q1 = Defaults.ap.n;
        _this.q0 = Defaults.ap.m;
        _this.qz = Defaults.ap.l;
        _this.p8 = null;
        _this.qd = null;
        _this.qe = null;
        _this.p9 = null;
        _this.qb = null;
        _this.qm = false;
        _this.rs = 0;
        _this.ru = 0;
        _this.ro = 0;
        _this.rn = 0;
        _this.progressiveLoadStatusChanged = null;
        _this.qr = null;
        _this.qx = 0;
        _this.qw = 0;
        _this.qy = 0;
        _this.rd = 0;
        _this.rb = 0;
        _this.rc = 0;
        _this.re = 0;
        _this.rg = 0;
        _this.ri = 0;
        _this.rh = 0;
        _this.rf = 0;
        _this.qt = 0;
        _this.qu = 0;
        _this.qv = 0;
        _this.qs = 0;
        _this.rq = 0;
        _this.rp = 0;
        _this.p5 = null;
        _this.rt = 0;
        _this.ql = false;
        _this._itemIndexes = null;
        _this.p6 = null;
        _this.p3 = null;
        _this.qf = null;
        _this.ab = HighDensityScatterSeries.$;
        _this.el = false;
        return _this;
    }
    HighDensityScatterSeries.prototype.get_d5 = function () {
        return true;
    };
    HighDensityScatterSeries.prototype.gu = function () {
        if (!isNaN_(this.gt)) {
            return _super.prototype.gu.call(this);
        }
        return Defaults.q;
    };
    HighDensityScatterSeries.prototype.get_ec = function () {
        return true;
    };
    Object.defineProperty(HighDensityScatterSeries.prototype, "qh", {
        get: function () {
            return this.qg;
        },
        set: function (a) {
            if (this.qg != a) {
                var b = this.qh;
                this.qg = a;
                this.raisePropertyChanged("XColumn", b, this.qh);
            }
        },
        enumerable: false,
        configurable: true
    });
    HighDensityScatterSeries.prototype.getDataLegendSeriesContextAt = function (a, b) {
        var c = { $type: Point_$type, x: a, y: b };
        var d = this.ht(c);
        var e = d == null ? NaN : this.gb(d, "XMemberPath");
        var f = d == null ? NaN : this.gb(d, "YMemberPath");
        var g = new DataLegendSeriesValueInfo();
        g.l = e;
        g.a = 13;
        g.p = this.sd != null ? this.sd : "X";
        g.q = this.r9 != null ? this.r9 : "X:";
        g.r = this.sb != null ? this.sb : "";
        var h = new DataLegendSeriesValueInfo();
        h.l = f;
        h.a = 14;
        h.p = this.sl != null ? this.sl : "Y";
        h.q = this.sh != null ? this.sh : "Y:";
        g.r = this.sj != null ? this.sj : "";
        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.av();
        return i;
    };
    HighDensityScatterSeries.prototype.hw = function (a, b) {
        var c = this.jq(b);
        if (c == HighDensityScatterSeries.$$p[10]) {
            return this.hx(a, b, this.sd);
        }
        if (c == HighDensityScatterSeries.$$p[14]) {
            return this.hx(a, b, this.sl);
        }
        return _super.prototype.hw.call(this, a, b);
    };
    Object.defineProperty(HighDensityScatterSeries.prototype, "qj", {
        get: function () {
            return this.qi;
        },
        set: function (a) {
            if (this.qi != a) {
                var b = this.qj;
                this.qi = a;
                this.raisePropertyChanged("YColumn", b, this.qj);
            }
        },
        enumerable: false,
        configurable: true
    });
    HighDensityScatterSeries.prototype.s0 = function () {
        if (this.p8 == null) {
            return;
        }
        this.p8.s();
        var a = this.p8;
        a.progressiveThunkCompleted = delegateRemove(a.progressiveThunkCompleted, runOn(this, this.sn));
        this.p8 = null;
    };
    HighDensityScatterSeries.prototype.l3 = function (a, b, c, d) {
        _super.prototype.l3.call(this, a, b, c, d);
        switch (b) {
            case "SeriesViewer":
                if (this.cd != null) {
                    var e = this.getEffectiveViewport1(this.b0);
                    this.ql = !e.isEmpty;
                }
                break;
            case "FastItemsSource":
                this.s0();
                if (typeCast(IFastItemsSource_$type, c) != null) {
                    c.deregisterColumn(this.qh);
                    c.deregisterColumn(this.qj);
                    this.qh = null;
                    this.qj = null;
                }
                if (typeCast(IFastItemsSource_$type, d) != null) {
                    this.qh = this.ch(this.sd);
                    this.qj = this.ch(this.sl);
                }
                if ((this.qc != null && !this.qc.c0()) || (this.qa != null && !this.qa.c0())) {
                    this.mh(false);
                }
                this.lp();
                break;
            case HighDensityScatterSeries.$$p[7]:
                var f = this.p9;
                this.p9 = this.qa;
                this.s0();
                if (f != null) {
                    f.rangeChanged = delegateRemove(f.rangeChanged, runOn(this, this.sq));
                }
                if (this.p9 != null) {
                    var g = this.p9;
                    g.rangeChanged = delegateCombine(g.rangeChanged, runOn(this, this.sq));
                }
                if (c != null) {
                    c.bz(this);
                }
                if (d != null) {
                    d.cs(this);
                }
                if ((this.qa != null && !this.qa.c0()) || (d == null && c != null)) {
                    this.mh(false);
                }
                break;
            case HighDensityScatterSeries.$$p[11]:
                var h = this.qb;
                this.qb = this.qc;
                this.s0();
                if (h != null) {
                    h.rangeChanged = delegateRemove(h.rangeChanged, runOn(this, this.sq));
                }
                if (this.qb != null) {
                    var i = this.qb;
                    i.rangeChanged = delegateCombine(i.rangeChanged, runOn(this, this.sq));
                }
                if (c != null) {
                    c.bz(this);
                }
                if (d != null) {
                    d.cs(this);
                }
                if ((this.qc != null && !this.qc.c0()) || (d == null && c != null)) {
                    this.mh(false);
                }
                break;
            case "MouseOverEnabled":
                this.qm = this.el;
                this.mh(false);
                break;
            case HighDensityScatterSeries.$$p[10]:
                if (this.ck != null) {
                    this.ck.deregisterColumn(this.qh);
                    this.qh = this.ch(this.sd);
                }
                break;
            case "XColumn":
                this.s0();
                if (this.qa != null && !this.qa.c0()) {
                    this.mh(false);
                }
                this.lp();
                break;
            case HighDensityScatterSeries.$$p[14]:
                if (this.ck != null) {
                    this.ck.deregisterColumn(this.qj);
                    this.qj = this.ch(this.sl);
                }
                break;
            case "YColumn":
                this.s0();
                if (this.qc != null && !this.qc.c0()) {
                    this.mh(false);
                }
                this.lp();
                break;
            case HighDensityScatterSeries.$$p[6]:
                this.s0();
                this.mh(false);
                this.lo();
                break;
            case HighDensityScatterSeries.$$p[3]:
                this.mh(false);
                this.lo();
                break;
            case HighDensityScatterSeries.$$p[1]:
                this.mh(false);
                this.lo();
                break;
            case HighDensityScatterSeries.$$p[0]:
            case HighDensityScatterSeries.$$p[2]:
                if (!this.p7.b1(this.tj, this.ti)) {
                    return;
                }
                this.su();
                this.mh(false);
                this.lo();
                break;
            case HighDensityScatterSeries.$$p[4]:
                this.rr = Math.max(typeGetValue(d) - 1, 0);
                this.qk = this.rr > 0;
                this.mh(false);
                this.lo();
                break;
            case HighDensityScatterSeries.$$p[5]:
                this.mh(false);
                this.lo();
                break;
        }
    };
    HighDensityScatterSeries.prototype.su = function () {
        this.q3 = this.tj.l;
        this.q6 = this.tj.o;
        this.q5 = this.tj.n;
        this.q4 = this.tj.m;
        this.qz = this.ti.l;
        this.q2 = this.ti.o;
        this.q1 = this.ti.n;
        this.q0 = this.ti.m;
        this.o7 = BrushUtil.g(truncate(this.q3), truncate(this.q6), truncate(this.q5), truncate(this.q4));
        this.o2 = BrushUtil.g(truncate(this.qz), truncate(this.q2), truncate(this.q1), truncate(this.q0));
    };
    HighDensityScatterSeries.prototype.qo = function (a) {
        if (typeCast(NumericYAxis.$, a) !== null) {
            return true;
        }
        return false;
    };
    HighDensityScatterSeries.prototype.qn = function (a) {
        if (typeCast(NumericXAxis.$, a) !== null) {
            return true;
        }
        return false;
    };
    HighDensityScatterSeries.prototype.sq = function (a, b) {
        this.s0();
        this.mh(false);
    };
    Object.defineProperty(HighDensityScatterSeries.prototype, "ra", {
        get: function () {
            return this.q2 - this.q6;
        },
        enumerable: false,
        configurable: true
    });
    Object.defineProperty(HighDensityScatterSeries.prototype, "q9", {
        get: function () {
            return this.q1 - this.q5;
        },
        enumerable: false,
        configurable: true
    });
    Object.defineProperty(HighDensityScatterSeries.prototype, "q8", {
        get: function () {
            return this.q0 - this.q4;
        },
        enumerable: false,
        configurable: true
    });
    Object.defineProperty(HighDensityScatterSeries.prototype, "q7", {
        get: function () {
            return this.qz - this.q3;
        },
        enumerable: false,
        configurable: true
    });
    HighDensityScatterSeries.prototype.e9 = function (a, b, c) {
        var d = _super.prototype.e9.call(this, a, b, c);
        if (this.qc == null || this.qa == null || this.qa.bh == null || this.qc.bh == null || this.qj == null || this.qh == null || this.qj.count < 1 || this.qh.count < 1 || this.qj.count != this.qh.count || this.qa.lv == this.qa.lu || this.qc.lv == this.qc.lu || this.py.isEmpty) {
            d = false;
        }
        return d;
    };
    Object.defineProperty(HighDensityScatterSeries.prototype, "ry", {
        get: function () {
            return this.rs;
        },
        set: function (a) {
            var b = this.rs;
            this.rs = a;
            this.raisePropertyChanged("ProgressiveStatus", b, this.rs);
        },
        enumerable: false,
        configurable: true
    });
    HighDensityScatterSeries.prototype.mi = function (a) {
        _super.prototype.mi.call(this, a);
        this.ss(a, this.b0);
    };
    HighDensityScatterSeries.prototype.ss = function (a, b) {
        if (this.cx(b)) {
            return;
        }
        if (this.p8 == null && !this.qq) {
            var c = new List$1(KDPointData.$, 2, this.qh.count);
            var d = this.qa;
            var e = this.qc;
            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.cg);
            var i = new ScalerParams(1, f, g, e.cg);
            var j_1;
            var k_1;
            var _loop_1 = function (l) {
                j_1 = d.ei(this_1.qh.item(l), h);
                k_1 = e.ei(this_1.qj.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.qh.count; l++) {
                _loop_1(l);
            }
            if (this.qp) {
                this.rn = 1;
                this.ro = truncate(logBase(c.count, 2)) + 3;
                this.ry = truncate(((this.rn / this.ro) * 100));
                if (this.progressiveLoadStatusChanged != null) {
                    this.progressiveLoadStatusChanged(this, new ProgressiveLoadStatusEventArgs(this.ry));
                }
                this.p8 = KDTree2D.b(c.toArray(), 1);
                var m = this.p8;
                m.progressiveThunkCompleted = delegateCombine(m.progressiveThunkCompleted, runOn(this, this.sn));
                if (!this.p8.f(this.g9)) {
                    var n = this.p8;
                    n.progressiveThunkCompleted = delegateRemove(n.progressiveThunkCompleted, runOn(this, this.sn));
                }
                this.lo();
            }
            else {
                var o = dateNow();
                this.p8 = new KDTree2D(0, c.toArray(), 1);
                var p = dateNow();
            }
        }
        if (this.qp && !this.qq) {
            this.st(b);
        }
        else {
            this.sv(b);
        }
    };
    HighDensityScatterSeries.prototype.k0 = function (a, b, c, d) {
        _super.prototype.k0.call(this, a, b, c, d);
        this.s0();
        var e = false;
        if (this.qa != null && !this.qa.c0()) {
            e = true;
        }
        if (this.qc != null && !this.qc.c0()) {
            e = true;
        }
        if (e) {
            this.mh(false);
        }
        this.lp();
    };
    HighDensityScatterSeries.prototype.sp = function (a) {
        var b = a;
        var c = this.rq * this.rp;
        if (this.qm) {
            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.sv = 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.qd = new ScalerParams(0, b, c, this.p9.cg, g);
        this.qe = new ScalerParams(0, b, c, this.qb.cg, g);
        this.so(a);
        this.sp(a);
        var h = this.rq * this.rp;
        if (this.p6 == null || this.p6.length != h) {
            this.p6 = new Array(h);
            this.p3 = new Array(h);
        }
        var i = this.p6.length;
        var j = this.p6;
        var k = this.p3;
        for (var l = 0; l < i; l++) {
            j[l] = 0;
            k[l] = 0;
        }
        this.ru = truncate(Math.round(this.ft));
        this.p5 = f.by();
        var m = this.p5.length;
        var n = this.p5;
        for (var o = 0; o < m; o++) {
            n[o] = 0;
        }
        var p = this.rl;
        var q = this.rk;
        if (isNaN_(p) || isInfinity(p)) {
            p = 0;
        }
        if (isNaN_(q) || isInfinity(q)) {
            q = 50;
        }
        this.qx = Math.min(p, q);
        this.qw = Math.max(p, q);
        if (this.qx < 0) {
            this.qx = 0;
        }
        if (this.qw < 0) {
            this.qw = 0;
        }
        this.qy = this.qw - this.qx;
        if (this.qq) {
            this.sr(a);
        }
        else {
            this.s2(a);
        }
        f.b9();
        if (a.q) {
            this._itemIndexes = d;
            this.p7.ca();
        }
    };
    HighDensityScatterSeries.prototype.st = function (a) {
        if (this.p8 == null) {
            return;
        }
        this.sv(a);
    };
    HighDensityScatterSeries.prototype.sn = function (a, b) {
        var _this = this;
        this.p7.b8(function () {
            if (_this.rn < _this.ro - 1) {
                _this.rn++;
            }
            _this.ry = truncate(((_this.rn / _this.ro) * 100));
            if (_this.progressiveLoadStatusChanged != null) {
                _this.progressiveLoadStatusChanged(_this, new ProgressiveLoadStatusEventArgs(_this.ry));
            }
            _this.st(_this.b0);
            _this.lo();
            if (_this.p8 != null) {
                if (!_this.p8.f(_this.g9)) {
                    var c = _this.p8;
                    c.progressiveThunkCompleted = delegateRemove(c.progressiveThunkCompleted, runOn(_this, _this.sn));
                    _this.ry = 100;
                    if (_this.progressiveLoadStatusChanged != null) {
                        _this.progressiveLoadStatusChanged(_this, new ProgressiveLoadStatusEventArgs(_this.ry));
                    }
                }
            }
        });
    };
    HighDensityScatterSeries.prototype.sr = function (a) {
        var b = arrayShallowClone(this.qh.asArray());
        this.qa.hm(boxArray$1(b), 0, b.length, this.qd);
        var c = arrayShallowClone(this.qj.asArray());
        this.rt = 0;
        var d = this.rr;
        var e = this.qk;
        var f = this.p6.length;
        this.qc.hm(boxArray$1(c), 0, c.length, this.qe);
        var g = 255 << 24 | truncate(this.q6) << 16 | truncate(this.q5) << 8 | truncate(this.q4);
        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.rq || j < 0 || j >= this.rp) {
                continue;
            }
            if (e) {
                var k = i - d;
                var l = i + d;
                l = l > (this.rq - 1) ? (this.rq - 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.rq) + o;
                        if (q < 0 || q > f - 1) {
                            continue;
                        }
                        this.p6[q] = this.p6[q] + 1;
                        this.p3[q] = 1;
                        this.rt++;
                        if (this.qm) {
                            this._itemIndexes[q] = h + 1;
                        }
                    }
                }
            }
            else {
                var r = (j * this.rq) + i;
                this.p6[r] = this.p6[r] + 1;
                this.p3[r] = 1;
                this.rt++;
                if (this.qm) {
                    this._itemIndexes[r] = h + 1;
                }
            }
        }
        this.sw();
    };
    HighDensityScatterSeries.prototype.s2 = function (a) {
        var b;
        var c;
        var d = a.getViewInfo(b, c);
        b = d.p0;
        c = d.p1;
        if (this.p8 == null) {
            return;
        }
        if (this.qr == null) {
            this.qr = new List$1(KDTreeNode2D.$, 2, truncate(Math.round(b.width * b.height)));
        }
        else {
            this.qr.clear();
        }
        var e = c.left;
        var f = c.right;
        var g = c.top;
        var h = c.bottom;
        this.rh = c.top;
        this.rf = c.height;
        this.rg = c.left;
        this.ri = c.width;
        this.rd = b.top;
        this.rb = b.height;
        this.rc = b.left;
        this.re = b.width;
        var i = this.getEffectiveViewport1(a);
        this.qt = (i.left - this.rc) / this.re;
        this.qu = (i.top - this.rd) / this.rb;
        var j = (i.right - this.rc) / this.re;
        this.qv = j - this.qt;
        var k = (i.bottom - this.rd) / this.rb;
        this.qs = k - this.qu;
        if (this.ql) {
            e = (e - this.qt) / this.qv;
            f = (f - this.qt) / this.qv;
            g = (g - this.qu) / this.qs;
            h = (h - this.qu) / this.qs;
        }
        var l = this.ft / b.width * c.width;
        var m = this.ft / 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.p8.t(this.qr, o, 0, 1, 0, 1);
        var p;
        this.rt = 0;
        for (var q = 0; q < this.qr.count; q++) {
            p = this.qr._inner[q];
            this.sx(p);
        }
        this.sw();
    };
    HighDensityScatterSeries.prototype.sx = 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.sz(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.sz(e, d, false, a.e);
            }
        }
        if (a.e != null) {
            a.e.a = false;
        }
    };
    HighDensityScatterSeries.prototype.en = function (a) {
        var b = this.cd != null ? this.cd.sf : Rect.empty;
        var c = this.cd != null ? this.cd.su : Rect.empty;
        var d = new Rect(0, 0, 0, 1, 1);
        var e = this.ps(this.b0);
        var f = new ScalerParams(0, d, d, this.qa.cg, e);
        var g = new ScalerParams(0, d, d, this.qc.cg, e);
        var h = !b.isEmpty && !c.isEmpty && this.ck != null ? this.ck.indexOf(a) : -1;
        var i = this.qa != null && this.qh != null && h < this.qh.count ? this.qa.ei(this.qh.item(h), f) : NaN;
        var j = this.qc != null && this.qj != null && h < this.qj.count ? this.qc.ei(this.qj.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.b8 != null) {
            this.b8.au(this.cd, b, true);
        }
        return h >= 0;
    };
    HighDensityScatterSeries.prototype.sz = function (a, b, c, d) {
        var e = this.rw(b);
        var f = a.c;
        var g = this.rr;
        if (c) {
            var h = d.d;
            var i = d.b;
            var j = d.e;
            var k = d.c;
            if (this.ql) {
                h = this.qt + this.qv * h;
                i = this.qt + this.qv * i;
                j = this.qu + this.qs * j;
                k = this.qu + this.qs * k;
            }
            var l = truncate((this.rc + this.re * (h - this.rg) / this.ri));
            var m = truncate((this.rc + this.re * (i - this.rg) / this.ri));
            var n = truncate((this.rd + this.rb * (j - this.rh) / this.rf));
            var o = truncate((this.rd + this.rb * (k - this.rh) / this.rf));
            l = truncate(Math.floor(l));
            m = truncate(Math.floor(m));
            n = truncate(Math.floor(n));
            o = truncate(Math.floor(o));
            if (this.qk) {
                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.sy(f, s, t, q, r);
                }
            }
        }
        else {
            var u = a.a;
            var v = a.b;
            if (this.ql) {
                u = this.qt + this.qv * u;
                v = this.qu + this.qs * v;
            }
            var w = truncate((this.rc + this.re * (u - this.rg) / this.ri));
            var x = truncate((this.rd + this.rb * (v - this.rh) / this.rf));
            w = truncate(Math.floor(w));
            x = truncate(Math.floor(x));
            if (this.qk) {
                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.sy(f, af, ag, ad, ae);
                    }
                }
            }
            else {
                this.sy(f, w, x, b, 1);
            }
        }
    };
    HighDensityScatterSeries.prototype.rv = function (a, b) {
        return truncate((Math.floor(255 * b))) << 24 | truncate(Math.floor(b * (this.q6 + a * this.ra))) << 16 | truncate(Math.floor(b * (this.q5 + a * this.q9))) << 8 | truncate(Math.floor(b * (this.q4 + a * this.q8)));
    };
    HighDensityScatterSeries.prototype.rw = function (a) {
        return 255 << 24 | truncate(Math.floor((this.q6 + a * this.ra))) << 16 | truncate(Math.floor((this.q5 + a * this.q9))) << 8 | truncate(Math.floor((this.q4 + a * this.q8)));
    };
    HighDensityScatterSeries.prototype.rj = function (a) {
        return (a >> 24 & 255) / 255;
    };
    HighDensityScatterSeries.prototype.sy = function (a, b, c, d, e) {
        if (b < 0 || b >= this.rq || c < 0 || c >= this.rp) {
            return;
        }
        var f = (c * this.rq) + b;
        this.p6[f] = this.p6[f] + d;
        this.p3[f] = this.p3[f] + e;
        if (this.qm) {
            this._itemIndexes[f] = a + 1;
        }
        this.rt += truncate(d);
    };
    HighDensityScatterSeries.prototype.sw = function () {
        var a = 0;
        var b = 0;
        var c = this.qy;
        var d = this.qx;
        var e = this.qw;
        var f = this.p6.length;
        var g = this.p6;
        var h = this.p3;
        var i = this.p5;
        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.rv(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.so = function (a) {
        var b = a;
        b.b6();
    };
    HighDensityScatterSeries.prototype.bx = function () {
        return new HighDensityScatterSeriesView(this);
    };
    HighDensityScatterSeries.prototype.ly = function (a) {
        _super.prototype.ly.call(this, a);
        this.p7 = a;
    };
    HighDensityScatterSeries.prototype.ap = function (a) {
        if (a != null && a == this.qa && this.qh != null) {
            return new AxisRange(this.qh.minimum, this.qh.maximum);
        }
        if (a != null && a == this.qc && this.qj != null) {
            return new AxisRange(this.qj.minimum, this.qj.maximum);
        }
        return null;
    };
    HighDensityScatterSeries.prototype.m4 = function (a, b) {
        if (this.cd != null) {
            var c = this.getEffectiveViewport1(this.b0);
            this.ql = !c.isEmpty;
        }
        this.mh(false);
    };
    HighDensityScatterSeries.prototype.m5 = function (a, b) {
        this.mh(false);
    };
    HighDensityScatterSeries.prototype.ht = function (a) {
        if (!this.qm || this._itemIndexes == null || this.cd == null || this.ck == null || this._itemIndexes.length != (this.rq * this.rp)) {
            return null;
        }
        var b = this.cd.sf;
        var c = (a.x - b.left) / b.width;
        var d = (a.y - b.top) / b.height;
        var e = truncate(Math.round(this.py.left + (this.py.width * c)));
        var f = truncate(Math.round(this.py.top + (this.py.height * d)));
        var g = this.rz(e, f);
        if (g < 0 || g > this._itemIndexes.length - 1) {
            return null;
        }
        var h = this._itemIndexes[g] - 1;
        if (h < 0 || h > this.ck.count) {
            return null;
        }
        return this.ck.item(h);
    };
    HighDensityScatterSeries.prototype.rz = function (a, b) {
        var c = (this.rq * b) + a;
        if (c > 0 && c < this._itemIndexes.length && this._itemIndexes[c] > 0) {
            return c;
        }
        var d = 1;
        c = (this.rq * (b - d)) + a;
        if (c > 0 && c < this._itemIndexes.length && this._itemIndexes[c] > 0) {
            return c;
        }
        c = (this.rq * (b + d)) + a;
        if (c > 0 && c < this._itemIndexes.length && this._itemIndexes[c] > 0) {
            return c;
        }
        c = (this.rq * (b)) + a - 1;
        if (c > 0 && c < this._itemIndexes.length && this._itemIndexes[c] > 0) {
            return c;
        }
        c = (this.rq * (b)) + a + 1;
        if (c > 0 && c < this._itemIndexes.length && this._itemIndexes[c] > 0) {
            return c;
        }
        c = (this.rq * (b - d)) + a - 1;
        if (c > 0 && c < this._itemIndexes.length && this._itemIndexes[c] > 0) {
            return c;
        }
        c = (this.rq * (b + d)) + a + 1;
        if (c > 0 && c < this._itemIndexes.length && this._itemIndexes[c] > 0) {
            return c;
        }
        c = (this.rq * (b - d)) + a + 1;
        if (c > 0 && c < this._itemIndexes.length && this._itemIndexes[c] > 0) {
            return c;
        }
        c = (this.rq * (b + d)) + a - 1;
        if (c > 0 && c < this._itemIndexes.length && this._itemIndexes[c] > 0) {
            return c;
        }
        return 0;
    };
    HighDensityScatterSeries.prototype.s1 = function (a, b, c) {
        this.p5 = a;
        this.rq = b;
        this.rp = c;
    };
    HighDensityScatterSeries.prototype.get_e3 = function () {
        return true;
    };
    HighDensityScatterSeries.prototype.set_e3 = function (a) {
        _super.prototype.set_e3.call(this, a);
    };
    HighDensityScatterSeries.prototype.kx = function (a, b) {
        _super.prototype.kx.call(this, a, b);
        this.p7.b7();
        if (this.bz != null) {
            this.bz.b7();
        }
        this.lo();
    };
    HighDensityScatterSeries.prototype.mj = function (a, b) {
        _super.prototype.mj.call(this, a, b);
        if (!this.ez) {
            this.b0.a2(b);
            return;
        }
        this.b0.a2(b);
        if (this.cx(this.bz)) {
            return;
        }
        var c = typeCast(HighDensityScatterSeriesView.$, this.bz);
        var d = new ScatterFrame();
        this.ss(false, c);
        this.ez = false;
    };
    HighDensityScatterSeries.prototype.mg = function (a, b, c, d, e) {
        _super.prototype.mg.call(this, a, b, c, d, e);
        var f = this.a6.a$h.item(d);
        var g = f;
        f.a1(c);
        if (this.cx(g)) {
            return;
        }
        if (this.qf == null) {
            this.qf = new ScatterFrame();
        }
        this.ss(false, f);
    };
    HighDensityScatterSeries.prototype.ku = function () {
        _super.prototype.ku.call(this);
        this.qa = null;
        this.qc = null;
    };
    HighDensityScatterSeries.$t = markType(HighDensityScatterSeries, 'HighDensityScatterSeries', Series.$);
    HighDensityScatterSeries.$$p = markDep(DependencyProperty, PropertyMetadata, HighDensityScatterSeries, 'raisePropertyChanged', ['HeatMaximumColor:ti:s3', [Color.$, Defaults.ap], 'HeatMaximum:rk:s4', [1, 50], 'HeatMinimumColor:tj:s5', [Color.$, Defaults.aq], 'HeatMinimum:rl:s6', [1, 0], 'PointExtent:rx:s7', [1, 1], 'ProgressiveLoad:qp:s8', [0, true], 'UseBruteForce:qq:s9', [0, false], 'XAxis:qa:ta', [NumericXAxis.$, null], 'XMemberAsLegendLabel:r9:tb', [2, null], 'XMemberAsLegendUnit:sb:tc', [2, null], 'XMemberPath:sd:td', [2, null], 'YAxis:qc:te', [NumericYAxis.$, null], 'YMemberAsLegendLabel:sh:tf', [2, null], 'YMemberAsLegendUnit:sj:tg', [2, null], 'YMemberPath:sl:th', [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.bz = null;
        _this.bx = null;
        _this.b5 = 0;
        _this.b4 = 0;
        _this.b2 = null;
        _this.b3 = null;
        _this.b0 = null;
        _this.bz = a;
        return _this;
    }
    HighDensityScatterSeriesView.prototype.as = function () {
        _super.prototype.as.call(this);
        if (!this.q) {
            this.bz.tj = Defaults.aq;
            this.bz.ti = Defaults.ap;
            this.bz.o2 = Defaults.al;
            this.bz.o7 = Defaults.ak;
        }
    };
    HighDensityScatterSeriesView.prototype.ca = function () {
        this.bz.s1(this.bx, this.b5, this.b4);
    };
    HighDensityScatterSeriesView.prototype.b6 = function () {
        if (this.b2 == null) {
            this.b2 = this.e.g9.createElement("canvas");
            var a = this.e.g9.get2DCanvasContext(this.b2);
            this.b0 = new RenderingContext(new CanvasViewRenderer(), a);
        }
        var b;
        if (this.p) {
            b = this.bu;
        }
        else {
            b = this.e.cd.sk();
        }
        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.b5;
        var h = this.b4;
        this.b5 = e;
        this.b4 = f;
        if (g != this.b5 || h != this.b4 || this.bx == null) {
            this.b2.setAttribute("width", e.toString());
            this.b2.setAttribute("height", f.toString());
            this.b3 = this.b0.g().getImageData(0, 0, e, f);
            var imageDataArray_ = this.b3.data;
            this.bx = imageDataArray_;
        }
        this.bz.s1(this.bx, this.b5, this.b4);
    };
    HighDensityScatterSeriesView.prototype.by = function () {
        return this.bx;
    };
    HighDensityScatterSeriesView.prototype.b9 = function () {
        var a = truncate(Math.round(this.bu.left));
        var b = truncate(Math.round(this.bu.left));
        var c = truncate(Math.round(this.bu.width));
        var d = truncate(Math.round(this.bu.height));
        this.b0.g().putImageData(this.b3, 0, 0);
        this.aq();
    };
    HighDensityScatterSeriesView.prototype.b8 = function (a) {
        if (this.e.g9 != null) {
            this.e.g9.setTimeout(a, 0);
        }
        else {
            window.setTimeout(a, 0);
        }
    };
    HighDensityScatterSeriesView.prototype.a6 = function (a, b) {
        _super.prototype.a6.call(this, a, b);
        if (b) {
            if (!this.bz.el) {
                return;
            }
            var c = new Rectangle();
            c.n = this.bu.left;
            c.o = this.bu.top;
            c.width = this.bu.width;
            c.height = this.bu.height;
            c._fill = this.bo();
            a.v(c);
            return;
        }
        if (this.b2 == null) {
            return;
        }
        var d = truncate(Math.round(this.bu.left));
        var e = truncate(Math.round(this.bu.top));
        var f = truncate(Math.round(this.bu.width));
        var g = truncate(Math.round(this.bu.height));
        this.k.n(this.b2.getNativeElement(), this.e._opacity, d, e, f, g, d, e, f, g);
    };
    HighDensityScatterSeriesView.prototype.b1 = function (a, b) {
        return Color.e(toNullable(Color.$, a), toNullable(Color.$, null)) && Color.e(toNullable(Color.$, b), toNullable(Color.$, null));
    };
    HighDensityScatterSeriesView.prototype.b7 = function () {
        if (this.bx != null) {
            for (var a = 0; a < this.bx.length; a++) {
                this.bx[a] = 0;
            }
            this.b9();
        }
    };
    HighDensityScatterSeriesView.prototype.al = function (a) {
        _super.prototype.al.call(this, a);
        if (this.bx == null) {
            this.e.a8.exportSeriesPixelsData(a, null, this.b5, this.b4);
            return;
        }
        var b = new Array(intDivide(this.bx.length, 4));
        var c;
        for (var d = 0; d < intDivide(this.bx.length, 4); d++) {
            c = d * 4;
            b[d] = this.bx[c + 3] << 24 | this.bx[c] << 16 | this.bx[c + 1] << 8 | this.bx[c + 2];
        }
        this.e.a8.exportSeriesPixelsData(a, b, this.b5, this.b4);
    };
    HighDensityScatterSeriesView.$t = markType(HighDensityScatterSeriesView, 'HighDensityScatterSeriesView', SeriesView.$);
    return HighDensityScatterSeriesView;
}(SeriesView));
export { HighDensityScatterSeriesView };
