/*
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.qp = null;
        _this.qr = null;
        _this.r0 = 0;
        _this.qt = false;
        _this.rf = Defaults.aq.o;
        _this.re = Defaults.aq.n;
        _this.rd = Defaults.aq.m;
        _this.rc = Defaults.aq.l;
        _this.rb = Defaults.ap.o;
        _this.ra = Defaults.ap.n;
        _this.q9 = Defaults.ap.m;
        _this.q8 = Defaults.ap.l;
        _this.qh = null;
        _this.qm = null;
        _this.qn = null;
        _this.qi = null;
        _this.qk = null;
        _this.qv = false;
        _this.r1 = 0;
        _this.r3 = 0;
        _this.rx = 0;
        _this.rw = 0;
        _this.progressiveLoadStatusChanged = null;
        _this.q0 = null;
        _this.q6 = 0;
        _this.q5 = 0;
        _this.q7 = 0;
        _this.rm = 0;
        _this.rk = 0;
        _this.rl = 0;
        _this.rn = 0;
        _this.rp = 0;
        _this.rr = 0;
        _this.rq = 0;
        _this.ro = 0;
        _this.q2 = 0;
        _this.q3 = 0;
        _this.q4 = 0;
        _this.q1 = 0;
        _this.rz = 0;
        _this.ry = 0;
        _this.qe = null;
        _this.r2 = 0;
        _this.qu = false;
        _this._itemIndexes = null;
        _this.qf = null;
        _this.qc = null;
        _this.qo = null;
        _this.ab = HighDensityScatterSeries.$;
        _this.eo = false;
        return _this;
    }
    HighDensityScatterSeries.prototype.get_d8 = function () {
        return true;
    };
    HighDensityScatterSeries.prototype.gz = function () {
        if (!isNaN_(this.gy)) {
            return _super.prototype.gz.call(this);
        }
        return Defaults.q;
    };
    HighDensityScatterSeries.prototype.get_ef = function () {
        return true;
    };
    Object.defineProperty(HighDensityScatterSeries.prototype, "qq", {
        get: function () {
            return this.qp;
        },
        set: function (a) {
            if (this.qp != a) {
                var b = this.qq;
                this.qp = a;
                this.raisePropertyChanged("XColumn", b, this.qq);
            }
        },
        enumerable: false,
        configurable: true
    });
    HighDensityScatterSeries.prototype.getDataLegendSeriesContextAt = function (a, b) {
        var c = { $type: Point_$type, x: a, y: b };
        var d = this.hy(c);
        var e = d == null ? NaN : this.gf(d, "XMemberPath");
        var f = d == null ? NaN : this.gf(d, "YMemberPath");
        var g = new DataLegendSeriesValueInfo();
        g.l = e;
        g.a = 13;
        g.p = "X";
        g.q = this.sm != null ? this.sm : "X";
        g.r = this.si != null ? this.si : "X:";
        g.s = this.sk != null ? this.sk : "";
        var h = new DataLegendSeriesValueInfo();
        h.l = f;
        h.a = 14;
        h.p = "Y";
        h.q = this.su != null ? this.su : "Y";
        h.r = this.sq != null ? this.sq : "Y:";
        h.s = this.ss != null ? this.ss : "";
        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.h1 = function (a, b) {
        var c = this.jv(b);
        if (c == HighDensityScatterSeries.$$p[10]) {
            return this.h2(a, b, this.sm);
        }
        if (c == HighDensityScatterSeries.$$p[14]) {
            return this.h2(a, b, this.su);
        }
        return _super.prototype.h1.call(this, a, b);
    };
    Object.defineProperty(HighDensityScatterSeries.prototype, "qs", {
        get: function () {
            return this.qr;
        },
        set: function (a) {
            if (this.qr != a) {
                var b = this.qs;
                this.qr = a;
                this.raisePropertyChanged("YColumn", b, this.qs);
            }
        },
        enumerable: false,
        configurable: true
    });
    HighDensityScatterSeries.prototype.s9 = function () {
        if (this.qh == null) {
            return;
        }
        this.qh.s();
        var a = this.qh;
        a.progressiveThunkCompleted = delegateRemove(a.progressiveThunkCompleted, runOn(this, this.sw));
        this.qh = null;
    };
    HighDensityScatterSeries.prototype.l9 = function (a, b, c, d) {
        _super.prototype.l9.call(this, a, b, c, d);
        switch (b) {
            case "SeriesViewer":
                if (this.ce != null) {
                    var e = this.getEffectiveViewport1(this.b1);
                    this.qu = !e.isEmpty;
                }
                break;
            case "FastItemsSource":
                this.s9();
                if (typeCast(IFastItemsSource_$type, c) != null) {
                    c.deregisterColumn(this.qq);
                    c.deregisterColumn(this.qs);
                    this.qq = null;
                    this.qs = null;
                }
                if (typeCast(IFastItemsSource_$type, d) != null) {
                    this.qq = this.ci(this.sm);
                    this.qs = this.ci(this.su);
                }
                if ((this.ql != null && !this.ql.c0()) || (this.qj != null && !this.qj.c0())) {
                    this.mn(false);
                }
                this.lv();
                break;
            case HighDensityScatterSeries.$$p[7]:
                var f = this.qi;
                this.qi = this.qj;
                this.s9();
                if (f != null) {
                    f.rangeChanged = delegateRemove(f.rangeChanged, runOn(this, this.sz));
                }
                if (this.qi != null) {
                    var g = this.qi;
                    g.rangeChanged = delegateCombine(g.rangeChanged, runOn(this, this.sz));
                }
                if (c != null) {
                    c.bz(this);
                }
                if (d != null) {
                    d.cs(this);
                }
                if ((this.qj != null && !this.qj.c0()) || (d == null && c != null)) {
                    this.mn(false);
                }
                break;
            case HighDensityScatterSeries.$$p[11]:
                var h = this.qk;
                this.qk = this.ql;
                this.s9();
                if (h != null) {
                    h.rangeChanged = delegateRemove(h.rangeChanged, runOn(this, this.sz));
                }
                if (this.qk != null) {
                    var i = this.qk;
                    i.rangeChanged = delegateCombine(i.rangeChanged, runOn(this, this.sz));
                }
                if (c != null) {
                    c.bz(this);
                }
                if (d != null) {
                    d.cs(this);
                }
                if ((this.ql != null && !this.ql.c0()) || (d == null && c != null)) {
                    this.mn(false);
                }
                break;
            case "MouseOverEnabled":
                this.qv = this.eo;
                this.mn(false);
                break;
            case HighDensityScatterSeries.$$p[10]:
                if (this.cl != null) {
                    this.cl.deregisterColumn(this.qq);
                    this.qq = this.ci(this.sm);
                }
                break;
            case "XColumn":
                this.s9();
                if (this.qj != null && !this.qj.c0()) {
                    this.mn(false);
                }
                this.lv();
                break;
            case HighDensityScatterSeries.$$p[14]:
                if (this.cl != null) {
                    this.cl.deregisterColumn(this.qs);
                    this.qs = this.ci(this.su);
                }
                break;
            case "YColumn":
                this.s9();
                if (this.ql != null && !this.ql.c0()) {
                    this.mn(false);
                }
                this.lv();
                break;
            case HighDensityScatterSeries.$$p[6]:
                this.s9();
                this.mn(false);
                this.lu();
                break;
            case HighDensityScatterSeries.$$p[3]:
                this.mn(false);
                this.lu();
                break;
            case HighDensityScatterSeries.$$p[1]:
                this.mn(false);
                this.lu();
                break;
            case HighDensityScatterSeries.$$p[0]:
            case HighDensityScatterSeries.$$p[2]:
                if (!this.qg.b1(this.ts, this.tr)) {
                    return;
                }
                this.s3();
                this.mn(false);
                this.lu();
                break;
            case HighDensityScatterSeries.$$p[4]:
                this.r0 = Math.max(typeGetValue(d) - 1, 0);
                this.qt = this.r0 > 0;
                this.mn(false);
                this.lu();
                break;
            case HighDensityScatterSeries.$$p[5]:
                this.mn(false);
                this.lu();
                break;
        }
    };
    HighDensityScatterSeries.prototype.s3 = function () {
        this.rc = this.ts.l;
        this.rf = this.ts.o;
        this.re = this.ts.n;
        this.rd = this.ts.m;
        this.q8 = this.tr.l;
        this.rb = this.tr.o;
        this.ra = this.tr.n;
        this.q9 = this.tr.m;
        this.pe = BrushUtil.g(truncate(this.rc), truncate(this.rf), truncate(this.re), truncate(this.rd));
        this.o9 = BrushUtil.g(truncate(this.q8), truncate(this.rb), truncate(this.ra), truncate(this.q9));
    };
    HighDensityScatterSeries.prototype.qx = function (a) {
        if (typeCast(NumericYAxis.$, a) !== null) {
            return true;
        }
        return false;
    };
    HighDensityScatterSeries.prototype.qw = function (a) {
        if (typeCast(NumericXAxis.$, a) !== null) {
            return true;
        }
        return false;
    };
    HighDensityScatterSeries.prototype.sz = function (a, b) {
        this.s9();
        this.mn(false);
    };
    Object.defineProperty(HighDensityScatterSeries.prototype, "rj", {
        get: function () {
            return this.rb - this.rf;
        },
        enumerable: false,
        configurable: true
    });
    Object.defineProperty(HighDensityScatterSeries.prototype, "ri", {
        get: function () {
            return this.ra - this.re;
        },
        enumerable: false,
        configurable: true
    });
    Object.defineProperty(HighDensityScatterSeries.prototype, "rh", {
        get: function () {
            return this.q9 - this.rd;
        },
        enumerable: false,
        configurable: true
    });
    Object.defineProperty(HighDensityScatterSeries.prototype, "rg", {
        get: function () {
            return this.q8 - this.rc;
        },
        enumerable: false,
        configurable: true
    });
    HighDensityScatterSeries.prototype.fd = function (a, b, c) {
        var d = _super.prototype.fd.call(this, a, b, c);
        if (this.ql == null || this.qj == null || this.qj.bh == null || this.ql.bh == null || this.qs == null || this.qq == null || this.qs.count < 1 || this.qq.count < 1 || this.qs.count != this.qq.count || this.qj.lw == this.qj.lv || this.ql.lw == this.ql.lv || this.p7.isEmpty) {
            d = false;
        }
        return d;
    };
    Object.defineProperty(HighDensityScatterSeries.prototype, "r7", {
        get: function () {
            return this.r1;
        },
        set: function (a) {
            var b = this.r1;
            this.r1 = a;
            this.raisePropertyChanged("ProgressiveStatus", b, this.r1);
        },
        enumerable: false,
        configurable: true
    });
    HighDensityScatterSeries.prototype.mo = function (a) {
        _super.prototype.mo.call(this, a);
        this.s1(a, this.b1);
    };
    HighDensityScatterSeries.prototype.s1 = function (a, b) {
        if (this.cy(b)) {
            return;
        }
        if (this.qh == null && !this.qz) {
            var c = new List$1(KDPointData.$, 2, this.qq.count);
            var d = this.qj;
            var e = this.ql;
            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.qq.item(l), h);
                k_1 = e.ei(this_1.qs.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.qq.count; l++) {
                _loop_1(l);
            }
            if (this.qy) {
                this.rw = 1;
                this.rx = truncate(logBase(c.count, 2)) + 3;
                this.r7 = truncate(((this.rw / this.rx) * 100));
                if (this.progressiveLoadStatusChanged != null) {
                    this.progressiveLoadStatusChanged(this, new ProgressiveLoadStatusEventArgs(this.r7));
                }
                this.qh = KDTree2D.b(c.toArray(), 1);
                var m = this.qh;
                m.progressiveThunkCompleted = delegateCombine(m.progressiveThunkCompleted, runOn(this, this.sw));
                if (!this.qh.f(this.he)) {
                    var n = this.qh;
                    n.progressiveThunkCompleted = delegateRemove(n.progressiveThunkCompleted, runOn(this, this.sw));
                }
                this.lu();
            }
            else {
                var o = dateNow();
                this.qh = new KDTree2D(0, c.toArray(), 1);
                var p = dateNow();
            }
        }
        if (this.qy && !this.qz) {
            this.s2(b);
        }
        else {
            this.s4(b);
        }
    };
    HighDensityScatterSeries.prototype.k5 = function (a, b, c, d) {
        _super.prototype.k5.call(this, a, b, c, d);
        this.s9();
        var e = false;
        if (this.qj != null && !this.qj.c0()) {
            e = true;
        }
        if (this.ql != null && !this.ql.c0()) {
            e = true;
        }
        if (e) {
            this.mn(false);
        }
        this.lv();
    };
    HighDensityScatterSeries.prototype.sy = function (a) {
        var b = a;
        var c = this.rz * this.ry;
        if (this.qv) {
            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.s4 = 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.qm = new ScalerParams(0, b, c, this.qi.cg, g);
        this.qn = new ScalerParams(0, b, c, this.qk.cg, g);
        this.sx(a);
        this.sy(a);
        var h = this.rz * this.ry;
        if (this.qf == null || this.qf.length != h) {
            this.qf = new Array(h);
            this.qc = new Array(h);
        }
        var i = this.qf.length;
        var j = this.qf;
        var k = this.qc;
        for (var l = 0; l < i; l++) {
            j[l] = 0;
            k[l] = 0;
        }
        this.r3 = truncate(Math.round(this.fx));
        this.qe = f.by();
        var m = this.qe.length;
        var n = this.qe;
        for (var o = 0; o < m; o++) {
            n[o] = 0;
        }
        var p = this.ru;
        var q = this.rt;
        if (isNaN_(p) || isInfinity(p)) {
            p = 0;
        }
        if (isNaN_(q) || isInfinity(q)) {
            q = 50;
        }
        this.q6 = Math.min(p, q);
        this.q5 = Math.max(p, q);
        if (this.q6 < 0) {
            this.q6 = 0;
        }
        if (this.q5 < 0) {
            this.q5 = 0;
        }
        this.q7 = this.q5 - this.q6;
        if (this.qz) {
            this.s0(a);
        }
        else {
            this.tb(a);
        }
        f.b9();
        if (a.q) {
            this._itemIndexes = d;
            this.qg.ca();
        }
    };
    HighDensityScatterSeries.prototype.s2 = function (a) {
        if (this.qh == null) {
            return;
        }
        this.s4(a);
    };
    HighDensityScatterSeries.prototype.sw = function (a, b) {
        var _this = this;
        this.qg.b8(function () {
            if (_this.rw < _this.rx - 1) {
                _this.rw++;
            }
            _this.r7 = truncate(((_this.rw / _this.rx) * 100));
            if (_this.progressiveLoadStatusChanged != null) {
                _this.progressiveLoadStatusChanged(_this, new ProgressiveLoadStatusEventArgs(_this.r7));
            }
            _this.s2(_this.b1);
            _this.lu();
            if (_this.qh != null) {
                if (!_this.qh.f(_this.he)) {
                    var c = _this.qh;
                    c.progressiveThunkCompleted = delegateRemove(c.progressiveThunkCompleted, runOn(_this, _this.sw));
                    _this.r7 = 100;
                    if (_this.progressiveLoadStatusChanged != null) {
                        _this.progressiveLoadStatusChanged(_this, new ProgressiveLoadStatusEventArgs(_this.r7));
                    }
                }
            }
        });
    };
    HighDensityScatterSeries.prototype.s0 = function (a) {
        var b = arrayShallowClone(this.qq.asArray());
        this.qj.hm(boxArray$1(b), 0, b.length, this.qm);
        var c = arrayShallowClone(this.qs.asArray());
        this.r2 = 0;
        var d = this.r0;
        var e = this.qt;
        var f = this.qf.length;
        this.ql.hm(boxArray$1(c), 0, c.length, this.qn);
        var g = 255 << 24 | truncate(this.rf) << 16 | truncate(this.re) << 8 | truncate(this.rd);
        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.rz || j < 0 || j >= this.ry) {
                continue;
            }
            if (e) {
                var k = i - d;
                var l = i + d;
                l = l > (this.rz - 1) ? (this.rz - 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.rz) + o;
                        if (q < 0 || q > f - 1) {
                            continue;
                        }
                        this.qf[q] = this.qf[q] + 1;
                        this.qc[q] = 1;
                        this.r2++;
                        if (this.qv) {
                            this._itemIndexes[q] = h + 1;
                        }
                    }
                }
            }
            else {
                var r = (j * this.rz) + i;
                this.qf[r] = this.qf[r] + 1;
                this.qc[r] = 1;
                this.r2++;
                if (this.qv) {
                    this._itemIndexes[r] = h + 1;
                }
            }
        }
        this.s5();
    };
    HighDensityScatterSeries.prototype.tb = function (a) {
        var b;
        var c;
        var d = a.getViewInfo(b, c);
        b = d.p0;
        c = d.p1;
        if (this.qh == null) {
            return;
        }
        if (this.q0 == null) {
            this.q0 = new List$1(KDTreeNode2D.$, 2, truncate(Math.round(b.width * b.height)));
        }
        else {
            this.q0.clear();
        }
        var e = c.left;
        var f = c.right;
        var g = c.top;
        var h = c.bottom;
        this.rq = c.top;
        this.ro = c.height;
        this.rp = c.left;
        this.rr = c.width;
        this.rm = b.top;
        this.rk = b.height;
        this.rl = b.left;
        this.rn = b.width;
        var i = this.getEffectiveViewport1(a);
        this.q2 = (i.left - this.rl) / this.rn;
        this.q3 = (i.top - this.rm) / this.rk;
        var j = (i.right - this.rl) / this.rn;
        this.q4 = j - this.q2;
        var k = (i.bottom - this.rm) / this.rk;
        this.q1 = k - this.q3;
        if (this.qu) {
            e = (e - this.q2) / this.q4;
            f = (f - this.q2) / this.q4;
            g = (g - this.q3) / this.q1;
            h = (h - this.q3) / this.q1;
        }
        var l = this.fx / b.width * c.width;
        var m = this.fx / 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.qh.t(this.q0, o, 0, 1, 0, 1);
        var p;
        this.r2 = 0;
        for (var q = 0; q < this.q0.count; q++) {
            p = this.q0._inner[q];
            this.s6(p);
        }
        this.s5();
    };
    HighDensityScatterSeries.prototype.s6 = 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.s8(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.s8(e, d, false, a.e);
            }
        }
        if (a.e != null) {
            a.e.a = false;
        }
    };
    HighDensityScatterSeries.prototype.eq = function (a) {
        var b = this.ce != null ? this.ce.ta : Rect.empty;
        var c = this.ce != null ? this.ce.tp : Rect.empty;
        var d = new Rect(0, 0, 0, 1, 1);
        var e = this.p1(this.b1);
        var f = new ScalerParams(0, d, d, this.qj.cg, e);
        var g = new ScalerParams(0, d, d, this.ql.cg, e);
        var h = !b.isEmpty && !c.isEmpty && this.cl != null ? this.cl.indexOf(a) : -1;
        var i = this.qj != null && this.qq != null && h < this.qq.count ? this.qj.ei(this.qq.item(h), f) : NaN;
        var j = this.ql != null && this.qs != null && h < this.qs.count ? this.ql.ei(this.qs.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.b9 != null) {
            this.b9.au(this.ce, b, true);
        }
        return h >= 0;
    };
    HighDensityScatterSeries.prototype.s8 = function (a, b, c, d) {
        var e = this.r5(b);
        var f = a.c;
        var g = this.r0;
        if (c) {
            var h = d.d;
            var i = d.b;
            var j = d.e;
            var k = d.c;
            if (this.qu) {
                h = this.q2 + this.q4 * h;
                i = this.q2 + this.q4 * i;
                j = this.q3 + this.q1 * j;
                k = this.q3 + this.q1 * k;
            }
            var l = truncate((this.rl + this.rn * (h - this.rp) / this.rr));
            var m = truncate((this.rl + this.rn * (i - this.rp) / this.rr));
            var n = truncate((this.rm + this.rk * (j - this.rq) / this.ro));
            var o = truncate((this.rm + this.rk * (k - this.rq) / this.ro));
            l = truncate(Math.floor(l));
            m = truncate(Math.floor(m));
            n = truncate(Math.floor(n));
            o = truncate(Math.floor(o));
            if (this.qt) {
                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.s7(f, s, t, q, r);
                }
            }
        }
        else {
            var u = a.a;
            var v = a.b;
            if (this.qu) {
                u = this.q2 + this.q4 * u;
                v = this.q3 + this.q1 * v;
            }
            var w = truncate((this.rl + this.rn * (u - this.rp) / this.rr));
            var x = truncate((this.rm + this.rk * (v - this.rq) / this.ro));
            w = truncate(Math.floor(w));
            x = truncate(Math.floor(x));
            if (this.qt) {
                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.s7(f, af, ag, ad, ae);
                    }
                }
            }
            else {
                this.s7(f, w, x, b, 1);
            }
        }
    };
    HighDensityScatterSeries.prototype.r4 = function (a, b) {
        return truncate((Math.floor(255 * b))) << 24 | truncate(Math.floor(b * (this.rf + a * this.rj))) << 16 | truncate(Math.floor(b * (this.re + a * this.ri))) << 8 | truncate(Math.floor(b * (this.rd + a * this.rh)));
    };
    HighDensityScatterSeries.prototype.r5 = function (a) {
        return 255 << 24 | truncate(Math.floor((this.rf + a * this.rj))) << 16 | truncate(Math.floor((this.re + a * this.ri))) << 8 | truncate(Math.floor((this.rd + a * this.rh)));
    };
    HighDensityScatterSeries.prototype.rs = function (a) {
        return (a >> 24 & 255) / 255;
    };
    HighDensityScatterSeries.prototype.s7 = function (a, b, c, d, e) {
        if (b < 0 || b >= this.rz || c < 0 || c >= this.ry) {
            return;
        }
        var f = (c * this.rz) + b;
        this.qf[f] = this.qf[f] + d;
        this.qc[f] = this.qc[f] + e;
        if (this.qv) {
            this._itemIndexes[f] = a + 1;
        }
        this.r2 += truncate(d);
    };
    HighDensityScatterSeries.prototype.s5 = function () {
        var a = 0;
        var b = 0;
        var c = this.q7;
        var d = this.q6;
        var e = this.q5;
        var f = this.qf.length;
        var g = this.qf;
        var h = this.qc;
        var i = this.qe;
        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.r4(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.sx = function (a) {
        var b = a;
        b.b6();
    };
    HighDensityScatterSeries.prototype.by = function () {
        return new HighDensityScatterSeriesView(this);
    };
    HighDensityScatterSeries.prototype.l4 = function (a) {
        _super.prototype.l4.call(this, a);
        this.qg = a;
    };
    HighDensityScatterSeries.prototype.aq = function (a) {
        if (a != null && a == this.qj && this.qq != null) {
            return new AxisRange(this.qq.minimum, this.qq.maximum);
        }
        if (a != null && a == this.ql && this.qs != null) {
            return new AxisRange(this.qs.minimum, this.qs.maximum);
        }
        return null;
    };
    HighDensityScatterSeries.prototype.na = function (a, b) {
        if (this.ce != null) {
            var c = this.getEffectiveViewport1(this.b1);
            this.qu = !c.isEmpty;
        }
        this.mn(false);
    };
    HighDensityScatterSeries.prototype.nb = function (a, b) {
        this.mn(false);
    };
    HighDensityScatterSeries.prototype.hy = function (a) {
        if (!this.qv || this._itemIndexes == null || this.ce == null || this.cl == null || this._itemIndexes.length != (this.rz * this.ry)) {
            return null;
        }
        var b = this.ce.ta;
        var c = (a.x - b.left) / b.width;
        var d = (a.y - b.top) / b.height;
        var e = truncate(Math.round(this.p7.left + (this.p7.width * c)));
        var f = truncate(Math.round(this.p7.top + (this.p7.height * d)));
        var g = this.r8(e, f);
        if (g < 0 || g > this._itemIndexes.length - 1) {
            return null;
        }
        var h = this._itemIndexes[g] - 1;
        if (h < 0 || h > this.cl.count) {
            return null;
        }
        return this.cl.item(h);
    };
    HighDensityScatterSeries.prototype.r8 = function (a, b) {
        var c = (this.rz * b) + a;
        if (c > 0 && c < this._itemIndexes.length && this._itemIndexes[c] > 0) {
            return c;
        }
        var d = 1;
        c = (this.rz * (b - d)) + a;
        if (c > 0 && c < this._itemIndexes.length && this._itemIndexes[c] > 0) {
            return c;
        }
        c = (this.rz * (b + d)) + a;
        if (c > 0 && c < this._itemIndexes.length && this._itemIndexes[c] > 0) {
            return c;
        }
        c = (this.rz * (b)) + a - 1;
        if (c > 0 && c < this._itemIndexes.length && this._itemIndexes[c] > 0) {
            return c;
        }
        c = (this.rz * (b)) + a + 1;
        if (c > 0 && c < this._itemIndexes.length && this._itemIndexes[c] > 0) {
            return c;
        }
        c = (this.rz * (b - d)) + a - 1;
        if (c > 0 && c < this._itemIndexes.length && this._itemIndexes[c] > 0) {
            return c;
        }
        c = (this.rz * (b + d)) + a + 1;
        if (c > 0 && c < this._itemIndexes.length && this._itemIndexes[c] > 0) {
            return c;
        }
        c = (this.rz * (b - d)) + a + 1;
        if (c > 0 && c < this._itemIndexes.length && this._itemIndexes[c] > 0) {
            return c;
        }
        c = (this.rz * (b + d)) + a - 1;
        if (c > 0 && c < this._itemIndexes.length && this._itemIndexes[c] > 0) {
            return c;
        }
        return 0;
    };
    HighDensityScatterSeries.prototype.ta = function (a, b, c) {
        this.qe = a;
        this.rz = b;
        this.ry = c;
    };
    HighDensityScatterSeries.prototype.get_e7 = function () {
        return true;
    };
    HighDensityScatterSeries.prototype.set_e7 = function (a) {
        _super.prototype.set_e7.call(this, a);
    };
    HighDensityScatterSeries.prototype.k2 = function (a, b) {
        _super.prototype.k2.call(this, a, b);
        this.qg.b7();
        if (this.b0 != null) {
            this.b0.b7();
        }
        this.lu();
    };
    HighDensityScatterSeries.prototype.mp = function (a, b) {
        _super.prototype.mp.call(this, a, b);
        if (!this.e3) {
            this.b1.a2(b);
            return;
        }
        this.b1.a2(b);
        if (this.cy(this.b0)) {
            return;
        }
        var c = typeCast(HighDensityScatterSeriesView.$, this.b0);
        var d = new ScatterFrame();
        this.s1(false, c);
        this.e3 = false;
    };
    HighDensityScatterSeries.prototype.mm = function (a, b, c, d, e) {
        _super.prototype.mm.call(this, a, b, c, d, e);
        var f = this.a7.a$h.item(d);
        var g = f;
        f.a1(c);
        if (this.cy(g)) {
            return;
        }
        if (this.qo == null) {
            this.qo = new ScatterFrame();
        }
        this.s1(false, f);
    };
    HighDensityScatterSeries.prototype.kz = function () {
        _super.prototype.kz.call(this);
        this.qj = null;
        this.ql = null;
    };
    HighDensityScatterSeries.$t = markType(HighDensityScatterSeries, 'HighDensityScatterSeries', Series.$);
    HighDensityScatterSeries.$$p = markDep(DependencyProperty, PropertyMetadata, HighDensityScatterSeries, 'raisePropertyChanged', ['HeatMaximumColor:tr:tc', [Color.$, Defaults.ap], 'HeatMaximum:rt:td', [1, 50], 'HeatMinimumColor:ts:te', [Color.$, Defaults.aq], 'HeatMinimum:ru:tf', [1, 0], 'PointExtent:r6:tg', [1, 1], 'ProgressiveLoad:qy:th', [0, true], 'UseBruteForce:qz:ti', [0, false], 'XAxis:qj:tj', [NumericXAxis.$, null], 'XMemberAsLegendLabel:si:tk', [2, null], 'XMemberAsLegendUnit:sk:tl', [2, null], 'XMemberPath:sm:tm', [2, null], 'YAxis:ql:tn', [NumericYAxis.$, null], 'YMemberAsLegendLabel:sq:to', [2, null], 'YMemberAsLegendUnit:ss:tp', [2, null], 'YMemberPath:su:tq', [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.ts = Defaults.aq;
            this.bz.tr = Defaults.ap;
            this.bz.o9 = Defaults.al;
            this.bz.pe = Defaults.ak;
        }
    };
    HighDensityScatterSeriesView.prototype.ca = function () {
        this.bz.ta(this.bx, this.b5, this.b4);
    };
    HighDensityScatterSeriesView.prototype.b6 = function () {
        if (this.b2 == null) {
            this.b2 = this.e.he.createElement("canvas");
            var a = this.e.he.get2DCanvasContext(this.b2);
            this.b0 = new RenderingContext(new CanvasViewRenderer(), a);
        }
        var b;
        if (this.p) {
            b = this.bu;
        }
        else {
            b = this.e.ce.tf();
        }
        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.ta(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.he != null) {
            this.e.he.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.eo) {
                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.a9.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.a9.exportSeriesPixelsData(a, b, this.b5, this.b4);
    };
    HighDensityScatterSeriesView.$t = markType(HighDensityScatterSeriesView, 'HighDensityScatterSeriesView', SeriesView.$);
    return HighDensityScatterSeriesView;
}(SeriesView));
export { HighDensityScatterSeriesView };
