/*
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.ql = null;
        _this.qn = null;
        _this.rw = 0;
        _this.qp = false;
        _this.rb = Defaults.aq.o;
        _this.ra = Defaults.aq.n;
        _this.q9 = Defaults.aq.m;
        _this.q8 = Defaults.aq.l;
        _this.q7 = Defaults.ap.o;
        _this.q6 = Defaults.ap.n;
        _this.q5 = Defaults.ap.m;
        _this.q4 = Defaults.ap.l;
        _this.qd = null;
        _this.qi = null;
        _this.qj = null;
        _this.qe = null;
        _this.qg = null;
        _this.qr = false;
        _this.rx = 0;
        _this.rz = 0;
        _this.rt = 0;
        _this.rs = 0;
        _this.progressiveLoadStatusChanged = null;
        _this.qw = null;
        _this.q2 = 0;
        _this.q1 = 0;
        _this.q3 = 0;
        _this.ri = 0;
        _this.rg = 0;
        _this.rh = 0;
        _this.rj = 0;
        _this.rl = 0;
        _this.rn = 0;
        _this.rm = 0;
        _this.rk = 0;
        _this.qy = 0;
        _this.qz = 0;
        _this.q0 = 0;
        _this.qx = 0;
        _this.rv = 0;
        _this.ru = 0;
        _this.qa = null;
        _this.ry = 0;
        _this.qq = false;
        _this._itemIndexes = null;
        _this.qb = null;
        _this.p8 = null;
        _this.qk = null;
        _this.ab = HighDensityScatterSeries.$;
        _this.em = false;
        return _this;
    }
    HighDensityScatterSeries.prototype.get_d6 = function () {
        return true;
    };
    HighDensityScatterSeries.prototype.gw = function () {
        if (!isNaN_(this.gv)) {
            return _super.prototype.gw.call(this);
        }
        return Defaults.q;
    };
    HighDensityScatterSeries.prototype.get_ed = function () {
        return true;
    };
    Object.defineProperty(HighDensityScatterSeries.prototype, "qm", {
        get: function () {
            return this.ql;
        },
        set: function (a) {
            if (this.ql != a) {
                var b = this.qm;
                this.ql = a;
                this.raisePropertyChanged("XColumn", b, this.qm);
            }
        },
        enumerable: false,
        configurable: true
    });
    HighDensityScatterSeries.prototype.getDataLegendSeriesContextAt = function (a, b) {
        var c = { $type: Point_$type, x: a, y: b };
        var d = this.hv(c);
        var e = d == null ? NaN : this.gd(d, "XMemberPath");
        var f = d == null ? NaN : this.gd(d, "YMemberPath");
        var g = new DataLegendSeriesValueInfo();
        g.l = e;
        g.a = 13;
        g.p = "X";
        g.q = this.si != null ? this.si : "X";
        g.r = this.se != null ? this.se : "X:";
        g.s = this.sg != null ? this.sg : "";
        var h = new DataLegendSeriesValueInfo();
        h.l = f;
        h.a = 14;
        h.p = "Y";
        h.q = this.sq != null ? this.sq : "Y";
        h.r = this.sm != null ? this.sm : "Y:";
        h.s = this.so != null ? this.so : "";
        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.hy = function (a, b) {
        var c = this.js(b);
        if (c == HighDensityScatterSeries.$$p[10]) {
            return this.hz(a, b, this.si);
        }
        if (c == HighDensityScatterSeries.$$p[14]) {
            return this.hz(a, b, this.sq);
        }
        return _super.prototype.hy.call(this, a, b);
    };
    Object.defineProperty(HighDensityScatterSeries.prototype, "qo", {
        get: function () {
            return this.qn;
        },
        set: function (a) {
            if (this.qn != a) {
                var b = this.qo;
                this.qn = a;
                this.raisePropertyChanged("YColumn", b, this.qo);
            }
        },
        enumerable: false,
        configurable: true
    });
    HighDensityScatterSeries.prototype.s5 = function () {
        if (this.qd == null) {
            return;
        }
        this.qd.s();
        var a = this.qd;
        a.progressiveThunkCompleted = delegateRemove(a.progressiveThunkCompleted, runOn(this, this.ss));
        this.qd = null;
    };
    HighDensityScatterSeries.prototype.l7 = function (a, b, c, d) {
        _super.prototype.l7.call(this, a, b, c, d);
        switch (b) {
            case "SeriesViewer":
                if (this.cd != null) {
                    var e = this.getEffectiveViewport1(this.b0);
                    this.qq = !e.isEmpty;
                }
                break;
            case "FastItemsSource":
                this.s5();
                if (typeCast(IFastItemsSource_$type, c) != null) {
                    c.deregisterColumn(this.qm);
                    c.deregisterColumn(this.qo);
                    this.qm = null;
                    this.qo = null;
                }
                if (typeCast(IFastItemsSource_$type, d) != null) {
                    this.qm = this.ch(this.si);
                    this.qo = this.ch(this.sq);
                }
                if ((this.qh != null && !this.qh.c0()) || (this.qf != null && !this.qf.c0())) {
                    this.ml(false);
                }
                this.lt();
                break;
            case HighDensityScatterSeries.$$p[7]:
                var f = this.qe;
                this.qe = this.qf;
                this.s5();
                if (f != null) {
                    f.rangeChanged = delegateRemove(f.rangeChanged, runOn(this, this.sv));
                }
                if (this.qe != null) {
                    var g = this.qe;
                    g.rangeChanged = delegateCombine(g.rangeChanged, runOn(this, this.sv));
                }
                if (c != null) {
                    c.bz(this);
                }
                if (d != null) {
                    d.cs(this);
                }
                if ((this.qf != null && !this.qf.c0()) || (d == null && c != null)) {
                    this.ml(false);
                }
                break;
            case HighDensityScatterSeries.$$p[11]:
                var h = this.qg;
                this.qg = this.qh;
                this.s5();
                if (h != null) {
                    h.rangeChanged = delegateRemove(h.rangeChanged, runOn(this, this.sv));
                }
                if (this.qg != null) {
                    var i = this.qg;
                    i.rangeChanged = delegateCombine(i.rangeChanged, runOn(this, this.sv));
                }
                if (c != null) {
                    c.bz(this);
                }
                if (d != null) {
                    d.cs(this);
                }
                if ((this.qh != null && !this.qh.c0()) || (d == null && c != null)) {
                    this.ml(false);
                }
                break;
            case "MouseOverEnabled":
                this.qr = this.em;
                this.ml(false);
                break;
            case HighDensityScatterSeries.$$p[10]:
                if (this.ck != null) {
                    this.ck.deregisterColumn(this.qm);
                    this.qm = this.ch(this.si);
                }
                break;
            case "XColumn":
                this.s5();
                if (this.qf != null && !this.qf.c0()) {
                    this.ml(false);
                }
                this.lt();
                break;
            case HighDensityScatterSeries.$$p[14]:
                if (this.ck != null) {
                    this.ck.deregisterColumn(this.qo);
                    this.qo = this.ch(this.sq);
                }
                break;
            case "YColumn":
                this.s5();
                if (this.qh != null && !this.qh.c0()) {
                    this.ml(false);
                }
                this.lt();
                break;
            case HighDensityScatterSeries.$$p[6]:
                this.s5();
                this.ml(false);
                this.ls();
                break;
            case HighDensityScatterSeries.$$p[3]:
                this.ml(false);
                this.ls();
                break;
            case HighDensityScatterSeries.$$p[1]:
                this.ml(false);
                this.ls();
                break;
            case HighDensityScatterSeries.$$p[0]:
            case HighDensityScatterSeries.$$p[2]:
                if (!this.qc.b1(this.to, this.tn)) {
                    return;
                }
                this.sz();
                this.ml(false);
                this.ls();
                break;
            case HighDensityScatterSeries.$$p[4]:
                this.rw = Math.max(typeGetValue(d) - 1, 0);
                this.qp = this.rw > 0;
                this.ml(false);
                this.ls();
                break;
            case HighDensityScatterSeries.$$p[5]:
                this.ml(false);
                this.ls();
                break;
        }
    };
    HighDensityScatterSeries.prototype.sz = function () {
        this.q8 = this.to.l;
        this.rb = this.to.o;
        this.ra = this.to.n;
        this.q9 = this.to.m;
        this.q4 = this.tn.l;
        this.q7 = this.tn.o;
        this.q6 = this.tn.n;
        this.q5 = this.tn.m;
        this.pc = BrushUtil.g(truncate(this.q8), truncate(this.rb), truncate(this.ra), truncate(this.q9));
        this.o7 = BrushUtil.g(truncate(this.q4), truncate(this.q7), truncate(this.q6), truncate(this.q5));
    };
    HighDensityScatterSeries.prototype.qt = function (a) {
        if (typeCast(NumericYAxis.$, a) !== null) {
            return true;
        }
        return false;
    };
    HighDensityScatterSeries.prototype.qs = function (a) {
        if (typeCast(NumericXAxis.$, a) !== null) {
            return true;
        }
        return false;
    };
    HighDensityScatterSeries.prototype.sv = function (a, b) {
        this.s5();
        this.ml(false);
    };
    Object.defineProperty(HighDensityScatterSeries.prototype, "rf", {
        get: function () {
            return this.q7 - this.rb;
        },
        enumerable: false,
        configurable: true
    });
    Object.defineProperty(HighDensityScatterSeries.prototype, "re", {
        get: function () {
            return this.q6 - this.ra;
        },
        enumerable: false,
        configurable: true
    });
    Object.defineProperty(HighDensityScatterSeries.prototype, "rd", {
        get: function () {
            return this.q5 - this.q9;
        },
        enumerable: false,
        configurable: true
    });
    Object.defineProperty(HighDensityScatterSeries.prototype, "rc", {
        get: function () {
            return this.q4 - this.q8;
        },
        enumerable: false,
        configurable: true
    });
    HighDensityScatterSeries.prototype.fb = function (a, b, c) {
        var d = _super.prototype.fb.call(this, a, b, c);
        if (this.qh == null || this.qf == null || this.qf.bh == null || this.qh.bh == null || this.qo == null || this.qm == null || this.qo.count < 1 || this.qm.count < 1 || this.qo.count != this.qm.count || this.qf.lv == this.qf.lu || this.qh.lv == this.qh.lu || this.p3.isEmpty) {
            d = false;
        }
        return d;
    };
    Object.defineProperty(HighDensityScatterSeries.prototype, "r3", {
        get: function () {
            return this.rx;
        },
        set: function (a) {
            var b = this.rx;
            this.rx = a;
            this.raisePropertyChanged("ProgressiveStatus", b, this.rx);
        },
        enumerable: false,
        configurable: true
    });
    HighDensityScatterSeries.prototype.mm = function (a) {
        _super.prototype.mm.call(this, a);
        this.sx(a, this.b0);
    };
    HighDensityScatterSeries.prototype.sx = function (a, b) {
        if (this.cx(b)) {
            return;
        }
        if (this.qd == null && !this.qv) {
            var c = new List$1(KDPointData.$, 2, this.qm.count);
            var d = this.qf;
            var e = this.qh;
            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.qm.item(l), h);
                k_1 = e.ei(this_1.qo.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.qm.count; l++) {
                _loop_1(l);
            }
            if (this.qu) {
                this.rs = 1;
                this.rt = truncate(logBase(c.count, 2)) + 3;
                this.r3 = truncate(((this.rs / this.rt) * 100));
                if (this.progressiveLoadStatusChanged != null) {
                    this.progressiveLoadStatusChanged(this, new ProgressiveLoadStatusEventArgs(this.r3));
                }
                this.qd = KDTree2D.b(c.toArray(), 1);
                var m = this.qd;
                m.progressiveThunkCompleted = delegateCombine(m.progressiveThunkCompleted, runOn(this, this.ss));
                if (!this.qd.f(this.hb)) {
                    var n = this.qd;
                    n.progressiveThunkCompleted = delegateRemove(n.progressiveThunkCompleted, runOn(this, this.ss));
                }
                this.ls();
            }
            else {
                var o = dateNow();
                this.qd = new KDTree2D(0, c.toArray(), 1);
                var p = dateNow();
            }
        }
        if (this.qu && !this.qv) {
            this.sy(b);
        }
        else {
            this.s0(b);
        }
    };
    HighDensityScatterSeries.prototype.k3 = function (a, b, c, d) {
        _super.prototype.k3.call(this, a, b, c, d);
        this.s5();
        var e = false;
        if (this.qf != null && !this.qf.c0()) {
            e = true;
        }
        if (this.qh != null && !this.qh.c0()) {
            e = true;
        }
        if (e) {
            this.ml(false);
        }
        this.lt();
    };
    HighDensityScatterSeries.prototype.su = function (a) {
        var b = a;
        var c = this.rv * this.ru;
        if (this.qr) {
            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.s0 = 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.qi = new ScalerParams(0, b, c, this.qe.cg, g);
        this.qj = new ScalerParams(0, b, c, this.qg.cg, g);
        this.st(a);
        this.su(a);
        var h = this.rv * this.ru;
        if (this.qb == null || this.qb.length != h) {
            this.qb = new Array(h);
            this.p8 = new Array(h);
        }
        var i = this.qb.length;
        var j = this.qb;
        var k = this.p8;
        for (var l = 0; l < i; l++) {
            j[l] = 0;
            k[l] = 0;
        }
        this.rz = truncate(Math.round(this.fv));
        this.qa = f.by();
        var m = this.qa.length;
        var n = this.qa;
        for (var o = 0; o < m; o++) {
            n[o] = 0;
        }
        var p = this.rq;
        var q = this.rp;
        if (isNaN_(p) || isInfinity(p)) {
            p = 0;
        }
        if (isNaN_(q) || isInfinity(q)) {
            q = 50;
        }
        this.q2 = Math.min(p, q);
        this.q1 = Math.max(p, q);
        if (this.q2 < 0) {
            this.q2 = 0;
        }
        if (this.q1 < 0) {
            this.q1 = 0;
        }
        this.q3 = this.q1 - this.q2;
        if (this.qv) {
            this.sw(a);
        }
        else {
            this.s7(a);
        }
        f.b9();
        if (a.q) {
            this._itemIndexes = d;
            this.qc.ca();
        }
    };
    HighDensityScatterSeries.prototype.sy = function (a) {
        if (this.qd == null) {
            return;
        }
        this.s0(a);
    };
    HighDensityScatterSeries.prototype.ss = function (a, b) {
        var _this = this;
        this.qc.b8(function () {
            if (_this.rs < _this.rt - 1) {
                _this.rs++;
            }
            _this.r3 = truncate(((_this.rs / _this.rt) * 100));
            if (_this.progressiveLoadStatusChanged != null) {
                _this.progressiveLoadStatusChanged(_this, new ProgressiveLoadStatusEventArgs(_this.r3));
            }
            _this.sy(_this.b0);
            _this.ls();
            if (_this.qd != null) {
                if (!_this.qd.f(_this.hb)) {
                    var c = _this.qd;
                    c.progressiveThunkCompleted = delegateRemove(c.progressiveThunkCompleted, runOn(_this, _this.ss));
                    _this.r3 = 100;
                    if (_this.progressiveLoadStatusChanged != null) {
                        _this.progressiveLoadStatusChanged(_this, new ProgressiveLoadStatusEventArgs(_this.r3));
                    }
                }
            }
        });
    };
    HighDensityScatterSeries.prototype.sw = function (a) {
        var b = arrayShallowClone(this.qm.asArray());
        this.qf.hm(boxArray$1(b), 0, b.length, this.qi);
        var c = arrayShallowClone(this.qo.asArray());
        this.ry = 0;
        var d = this.rw;
        var e = this.qp;
        var f = this.qb.length;
        this.qh.hm(boxArray$1(c), 0, c.length, this.qj);
        var g = 255 << 24 | truncate(this.rb) << 16 | truncate(this.ra) << 8 | truncate(this.q9);
        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.rv || j < 0 || j >= this.ru) {
                continue;
            }
            if (e) {
                var k = i - d;
                var l = i + d;
                l = l > (this.rv - 1) ? (this.rv - 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.rv) + o;
                        if (q < 0 || q > f - 1) {
                            continue;
                        }
                        this.qb[q] = this.qb[q] + 1;
                        this.p8[q] = 1;
                        this.ry++;
                        if (this.qr) {
                            this._itemIndexes[q] = h + 1;
                        }
                    }
                }
            }
            else {
                var r = (j * this.rv) + i;
                this.qb[r] = this.qb[r] + 1;
                this.p8[r] = 1;
                this.ry++;
                if (this.qr) {
                    this._itemIndexes[r] = h + 1;
                }
            }
        }
        this.s1();
    };
    HighDensityScatterSeries.prototype.s7 = function (a) {
        var b;
        var c;
        var d = a.getViewInfo(b, c);
        b = d.p0;
        c = d.p1;
        if (this.qd == null) {
            return;
        }
        if (this.qw == null) {
            this.qw = new List$1(KDTreeNode2D.$, 2, truncate(Math.round(b.width * b.height)));
        }
        else {
            this.qw.clear();
        }
        var e = c.left;
        var f = c.right;
        var g = c.top;
        var h = c.bottom;
        this.rm = c.top;
        this.rk = c.height;
        this.rl = c.left;
        this.rn = c.width;
        this.ri = b.top;
        this.rg = b.height;
        this.rh = b.left;
        this.rj = b.width;
        var i = this.getEffectiveViewport1(a);
        this.qy = (i.left - this.rh) / this.rj;
        this.qz = (i.top - this.ri) / this.rg;
        var j = (i.right - this.rh) / this.rj;
        this.q0 = j - this.qy;
        var k = (i.bottom - this.ri) / this.rg;
        this.qx = k - this.qz;
        if (this.qq) {
            e = (e - this.qy) / this.q0;
            f = (f - this.qy) / this.q0;
            g = (g - this.qz) / this.qx;
            h = (h - this.qz) / this.qx;
        }
        var l = this.fv / b.width * c.width;
        var m = this.fv / 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.qd.t(this.qw, o, 0, 1, 0, 1);
        var p;
        this.ry = 0;
        for (var q = 0; q < this.qw.count; q++) {
            p = this.qw._inner[q];
            this.s2(p);
        }
        this.s1();
    };
    HighDensityScatterSeries.prototype.s2 = 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.s4(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.s4(e, d, false, a.e);
            }
        }
        if (a.e != null) {
            a.e.a = false;
        }
    };
    HighDensityScatterSeries.prototype.eo = function (a) {
        var b = this.cd != null ? this.cd.s9 : Rect.empty;
        var c = this.cd != null ? this.cd.to : Rect.empty;
        var d = new Rect(0, 0, 0, 1, 1);
        var e = this.px(this.b0);
        var f = new ScalerParams(0, d, d, this.qf.cg, e);
        var g = new ScalerParams(0, d, d, this.qh.cg, e);
        var h = !b.isEmpty && !c.isEmpty && this.ck != null ? this.ck.indexOf(a) : -1;
        var i = this.qf != null && this.qm != null && h < this.qm.count ? this.qf.ei(this.qm.item(h), f) : NaN;
        var j = this.qh != null && this.qo != null && h < this.qo.count ? this.qh.ei(this.qo.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.s4 = function (a, b, c, d) {
        var e = this.r1(b);
        var f = a.c;
        var g = this.rw;
        if (c) {
            var h = d.d;
            var i = d.b;
            var j = d.e;
            var k = d.c;
            if (this.qq) {
                h = this.qy + this.q0 * h;
                i = this.qy + this.q0 * i;
                j = this.qz + this.qx * j;
                k = this.qz + this.qx * k;
            }
            var l = truncate((this.rh + this.rj * (h - this.rl) / this.rn));
            var m = truncate((this.rh + this.rj * (i - this.rl) / this.rn));
            var n = truncate((this.ri + this.rg * (j - this.rm) / this.rk));
            var o = truncate((this.ri + this.rg * (k - this.rm) / this.rk));
            l = truncate(Math.floor(l));
            m = truncate(Math.floor(m));
            n = truncate(Math.floor(n));
            o = truncate(Math.floor(o));
            if (this.qp) {
                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.s3(f, s, t, q, r);
                }
            }
        }
        else {
            var u = a.a;
            var v = a.b;
            if (this.qq) {
                u = this.qy + this.q0 * u;
                v = this.qz + this.qx * v;
            }
            var w = truncate((this.rh + this.rj * (u - this.rl) / this.rn));
            var x = truncate((this.ri + this.rg * (v - this.rm) / this.rk));
            w = truncate(Math.floor(w));
            x = truncate(Math.floor(x));
            if (this.qp) {
                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.s3(f, af, ag, ad, ae);
                    }
                }
            }
            else {
                this.s3(f, w, x, b, 1);
            }
        }
    };
    HighDensityScatterSeries.prototype.r0 = function (a, b) {
        return truncate((Math.floor(255 * b))) << 24 | truncate(Math.floor(b * (this.rb + a * this.rf))) << 16 | truncate(Math.floor(b * (this.ra + a * this.re))) << 8 | truncate(Math.floor(b * (this.q9 + a * this.rd)));
    };
    HighDensityScatterSeries.prototype.r1 = function (a) {
        return 255 << 24 | truncate(Math.floor((this.rb + a * this.rf))) << 16 | truncate(Math.floor((this.ra + a * this.re))) << 8 | truncate(Math.floor((this.q9 + a * this.rd)));
    };
    HighDensityScatterSeries.prototype.ro = function (a) {
        return (a >> 24 & 255) / 255;
    };
    HighDensityScatterSeries.prototype.s3 = function (a, b, c, d, e) {
        if (b < 0 || b >= this.rv || c < 0 || c >= this.ru) {
            return;
        }
        var f = (c * this.rv) + b;
        this.qb[f] = this.qb[f] + d;
        this.p8[f] = this.p8[f] + e;
        if (this.qr) {
            this._itemIndexes[f] = a + 1;
        }
        this.ry += truncate(d);
    };
    HighDensityScatterSeries.prototype.s1 = function () {
        var a = 0;
        var b = 0;
        var c = this.q3;
        var d = this.q2;
        var e = this.q1;
        var f = this.qb.length;
        var g = this.qb;
        var h = this.p8;
        var i = this.qa;
        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.r0(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.st = function (a) {
        var b = a;
        b.b6();
    };
    HighDensityScatterSeries.prototype.bx = function () {
        return new HighDensityScatterSeriesView(this);
    };
    HighDensityScatterSeries.prototype.l2 = function (a) {
        _super.prototype.l2.call(this, a);
        this.qc = a;
    };
    HighDensityScatterSeries.prototype.ap = function (a) {
        if (a != null && a == this.qf && this.qm != null) {
            return new AxisRange(this.qm.minimum, this.qm.maximum);
        }
        if (a != null && a == this.qh && this.qo != null) {
            return new AxisRange(this.qo.minimum, this.qo.maximum);
        }
        return null;
    };
    HighDensityScatterSeries.prototype.m8 = function (a, b) {
        if (this.cd != null) {
            var c = this.getEffectiveViewport1(this.b0);
            this.qq = !c.isEmpty;
        }
        this.ml(false);
    };
    HighDensityScatterSeries.prototype.m9 = function (a, b) {
        this.ml(false);
    };
    HighDensityScatterSeries.prototype.hv = function (a) {
        if (!this.qr || this._itemIndexes == null || this.cd == null || this.ck == null || this._itemIndexes.length != (this.rv * this.ru)) {
            return null;
        }
        var b = this.cd.s9;
        var c = (a.x - b.left) / b.width;
        var d = (a.y - b.top) / b.height;
        var e = truncate(Math.round(this.p3.left + (this.p3.width * c)));
        var f = truncate(Math.round(this.p3.top + (this.p3.height * d)));
        var g = this.r4(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.r4 = function (a, b) {
        var c = (this.rv * b) + a;
        if (c > 0 && c < this._itemIndexes.length && this._itemIndexes[c] > 0) {
            return c;
        }
        var d = 1;
        c = (this.rv * (b - d)) + a;
        if (c > 0 && c < this._itemIndexes.length && this._itemIndexes[c] > 0) {
            return c;
        }
        c = (this.rv * (b + d)) + a;
        if (c > 0 && c < this._itemIndexes.length && this._itemIndexes[c] > 0) {
            return c;
        }
        c = (this.rv * (b)) + a - 1;
        if (c > 0 && c < this._itemIndexes.length && this._itemIndexes[c] > 0) {
            return c;
        }
        c = (this.rv * (b)) + a + 1;
        if (c > 0 && c < this._itemIndexes.length && this._itemIndexes[c] > 0) {
            return c;
        }
        c = (this.rv * (b - d)) + a - 1;
        if (c > 0 && c < this._itemIndexes.length && this._itemIndexes[c] > 0) {
            return c;
        }
        c = (this.rv * (b + d)) + a + 1;
        if (c > 0 && c < this._itemIndexes.length && this._itemIndexes[c] > 0) {
            return c;
        }
        c = (this.rv * (b - d)) + a + 1;
        if (c > 0 && c < this._itemIndexes.length && this._itemIndexes[c] > 0) {
            return c;
        }
        c = (this.rv * (b + d)) + a - 1;
        if (c > 0 && c < this._itemIndexes.length && this._itemIndexes[c] > 0) {
            return c;
        }
        return 0;
    };
    HighDensityScatterSeries.prototype.s6 = function (a, b, c) {
        this.qa = a;
        this.rv = b;
        this.ru = c;
    };
    HighDensityScatterSeries.prototype.get_e5 = function () {
        return true;
    };
    HighDensityScatterSeries.prototype.set_e5 = function (a) {
        _super.prototype.set_e5.call(this, a);
    };
    HighDensityScatterSeries.prototype.k0 = function (a, b) {
        _super.prototype.k0.call(this, a, b);
        this.qc.b7();
        if (this.bz != null) {
            this.bz.b7();
        }
        this.ls();
    };
    HighDensityScatterSeries.prototype.mn = function (a, b) {
        _super.prototype.mn.call(this, a, b);
        if (!this.e1) {
            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.sx(false, c);
        this.e1 = false;
    };
    HighDensityScatterSeries.prototype.mk = function (a, b, c, d, e) {
        _super.prototype.mk.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.qk == null) {
            this.qk = new ScatterFrame();
        }
        this.sx(false, f);
    };
    HighDensityScatterSeries.prototype.kx = function () {
        _super.prototype.kx.call(this);
        this.qf = null;
        this.qh = null;
    };
    HighDensityScatterSeries.$t = markType(HighDensityScatterSeries, 'HighDensityScatterSeries', Series.$);
    HighDensityScatterSeries.$$p = markDep(DependencyProperty, PropertyMetadata, HighDensityScatterSeries, 'raisePropertyChanged', ['HeatMaximumColor:tn:s8', [Color.$, Defaults.ap], 'HeatMaximum:rp:s9', [1, 50], 'HeatMinimumColor:to:ta', [Color.$, Defaults.aq], 'HeatMinimum:rq:tb', [1, 0], 'PointExtent:r2:tc', [1, 1], 'ProgressiveLoad:qu:td', [0, true], 'UseBruteForce:qv:te', [0, false], 'XAxis:qf:tf', [NumericXAxis.$, null], 'XMemberAsLegendLabel:se:tg', [2, null], 'XMemberAsLegendUnit:sg:th', [2, null], 'XMemberPath:si:ti', [2, null], 'YAxis:qh:tj', [NumericYAxis.$, null], 'YMemberAsLegendLabel:sm:tk', [2, null], 'YMemberAsLegendUnit:so:tl', [2, null], 'YMemberPath:sq:tm', [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.to = Defaults.aq;
            this.bz.tn = Defaults.ap;
            this.bz.o7 = Defaults.al;
            this.bz.pc = Defaults.ak;
        }
    };
    HighDensityScatterSeriesView.prototype.ca = function () {
        this.bz.s6(this.bx, this.b5, this.b4);
    };
    HighDensityScatterSeriesView.prototype.b6 = function () {
        if (this.b2 == null) {
            this.b2 = this.e.hb.createElement("canvas");
            var a = this.e.hb.get2DCanvasContext(this.b2);
            this.b0 = new RenderingContext(new CanvasViewRenderer(), a);
        }
        var b;
        if (this.p) {
            b = this.bu;
        }
        else {
            b = this.e.cd.te();
        }
        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.h().getImageData(0, 0, e, f);
            var imageDataArray_ = this.b3.data;
            this.bx = imageDataArray_;
        }
        this.bz.s6(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.h().putImageData(this.b3, 0, 0);
        this.aq();
    };
    HighDensityScatterSeriesView.prototype.b8 = function (a) {
        if (this.e.hb != null) {
            this.e.hb.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.em) {
                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.w(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.o(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 };
