/*
THIS INFRAGISTICS ULTIMATE SOFTWARE LICENSE  AGREEMENT ("AGREEMENT") LOCATED HERE:
https://www.infragistics.com/legal/license/igultimate-la
https://www.infragistics.com/legal/license/igultimate-eula
GOVERNS THE LICENSING, INSTALLATION AND USE OF INFRAGISTICS SOFTWARE. BY DOWNLOADING AND/OR INSTALLING AND USING INFRAGISTICS SOFTWARE:  you are indicating that you have read and understand this Agreement, and agree to be legally bound by it on behalf of the yourself and your company.
*/
import { __extends } from "tslib";
import { Series } from "./Series";
import { NumericXAxis } from "./NumericXAxis";
import { DependencyProperty } from "igniteui-react-core";
import { NumericYAxis } from "./NumericYAxis";
import { Color } from "igniteui-react-core";
import { ScatterFrame } from "./ScatterFrame";
import { Defaults } from "./Defaults";
import { KDTree2D } from "./KDTree2D";
import { Point_$type, typeGetValue, runOn, delegateRemove, typeCast, delegateCombine, markType, markDep, toNullable } from "igniteui-react-core";
import { DataLegendSeriesValueInfo } from "igniteui-react-core";
import { DataLegendSeriesContext } from "igniteui-react-core";
import { List$1 } from "igniteui-react-core";
import { Rect } from "igniteui-react-core";
import { IFastItemsSource_$type } from "igniteui-react-core";
import { BrushUtil } from "igniteui-react-core";
import { SeriesView } from "./SeriesView";
import { TestRandomness } from "igniteui-react-core";
import { DefaultRandomnessSource } from "igniteui-react-core";
import { KDPointData } from "./KDPointData";
import { ScalerParams } from "./ScalerParams";
import { ProgressiveLoadStatusEventArgs } from "./ProgressiveLoadStatusEventArgs";
import { SearchArgs } from "./SearchArgs";
import { KDTreeNode2D } from "./KDTreeNode2D";
import { AxisRange } from "./AxisRange";
import { PropertyMetadata } from "igniteui-react-core";
import { truncate, isNaN_, isInfinity, logBase, intDivide } from "igniteui-react-core";
import { boxArray$1, arrayShallowClone } from "igniteui-react-core";
import { dateNow } from "igniteui-react-core";
import { RenderingContext } from "igniteui-react-core";
import { CanvasViewRenderer } from "igniteui-react-core";
import { Rectangle } from "igniteui-react-core";
/**
 * @hidden
 */
var HighDensityScatterSeries = /** @class */ /*@__PURE__*/ (function (_super) {
    __extends(HighDensityScatterSeries, _super);
    function HighDensityScatterSeries() {
        var _this = _super.call(this) || this;
        _this.w9 = null;
        _this.xb = null;
        _this.yl = 0;
        _this.xe = false;
        _this.x0 = Defaults.aq.o;
        _this.xz = Defaults.aq.n;
        _this.xy = Defaults.aq.m;
        _this.xx = Defaults.aq.l;
        _this.xw = Defaults.ap.o;
        _this.xv = Defaults.ap.n;
        _this.xu = Defaults.ap.m;
        _this.xt = Defaults.ap.l;
        _this.w1 = null;
        _this.w6 = null;
        _this.w7 = null;
        _this.w2 = null;
        _this.w4 = null;
        _this.xg = false;
        _this.ym = 0;
        _this.yo = 0;
        _this.yi = 0;
        _this.yh = 0;
        _this.progressiveLoadStatusChanged = null;
        _this.xl = null;
        _this.xr = 0;
        _this.xq = 0;
        _this.xs = 0;
        _this.x7 = 0;
        _this.x5 = 0;
        _this.x6 = 0;
        _this.x8 = 0;
        _this.ya = 0;
        _this.yc = 0;
        _this.yb = 0;
        _this.x9 = 0;
        _this.xn = 0;
        _this.xo = 0;
        _this.xp = 0;
        _this.xm = 0;
        _this.yk = 0;
        _this.yj = 0;
        _this.wy = null;
        _this.yn = 0;
        _this.xf = false;
        _this._itemIndexes = null;
        _this.wz = null;
        _this.ww = null;
        _this.w8 = null;
        _this.ab = HighDensityScatterSeries.$;
        _this.f8 = false;
        return _this;
    }
    HighDensityScatterSeries.prototype.bj = function () {
        return new HighDensityScatterSeries();
    };
    HighDensityScatterSeries.prototype.get_fo = function () {
        return true;
    };
    HighDensityScatterSeries.prototype.jk = function () {
        if (!isNaN_(this.jj)) {
            return _super.prototype.jk.call(this);
        }
        return Defaults.q;
    };
    HighDensityScatterSeries.prototype.get_fw = function () {
        return true;
    };
    Object.defineProperty(HighDensityScatterSeries.prototype, "xa", {
        get: function () {
            return this.w9;
        },
        set: function (a) {
            if (this.w9 != a) {
                var b = this.xa;
                this.w9 = a;
                this.raisePropertyChanged("XColumn", b, this.xa);
            }
        },
        enumerable: false,
        configurable: true
    });
    HighDensityScatterSeries.prototype.getDataLegendSeriesContextAt = function (a, b) {
        var c = { $type: Point_$type, x: a, y: b };
        var d = this.kn(c);
        var e = d == null ? NaN : this.ix(d, "XMemberPath");
        var f = d == null ? NaN : this.ix(d, "YMemberPath");
        var g = new DataLegendSeriesValueInfo();
        g.l = e;
        g.a = 13;
        g.q = "X";
        g.r = this.y7 != null ? this.y7 : "X";
        g.s = this.y3 != null ? this.y3 : "X:";
        g.t = this.y5 != null ? this.y5 : "";
        var h = new DataLegendSeriesValueInfo();
        h.l = f;
        h.a = 14;
        h.q = "Y";
        h.r = this.zf != null ? this.zf : "Y";
        h.s = this.zb != null ? this.zb : "Y:";
        h.t = this.zd != null ? this.zd : "";
        var i = new DataLegendSeriesContext();
        i.e = ((function () {
            var $ret = new List$1(DataLegendSeriesValueInfo.$, 0);
            $ret.add(g);
            $ret.add(h);
            return $ret;
        })());
        i.h = this.mc();
        return i;
    };
    HighDensityScatterSeries.prototype.kq = function (a, b) {
        var c = this.nd(b);
        if (c == HighDensityScatterSeries.$$p[10]) {
            return this.kr(a, b, this.y7);
        }
        if (c == HighDensityScatterSeries.$$p[14]) {
            return this.kr(a, b, this.zf);
        }
        return _super.prototype.kq.call(this, a, b);
    };
    HighDensityScatterSeries.prototype.md = function (a) {
        var b = this.nd(a);
        if (b == HighDensityScatterSeries.$$p[10]) {
            return this.y7;
        }
        if (b == HighDensityScatterSeries.$$p[14]) {
            return this.zf;
        }
        return _super.prototype.md.call(this, a);
    };
    Object.defineProperty(HighDensityScatterSeries.prototype, "xc", {
        get: function () {
            return this.xb;
        },
        set: function (a) {
            if (this.xb != a) {
                var b = this.xc;
                this.xb = a;
                this.raisePropertyChanged("YColumn", b, this.xc);
            }
        },
        enumerable: false,
        configurable: true
    });
    HighDensityScatterSeries.prototype.zu = function () {
        if (this.w1 == null) {
            return;
        }
        this.w1.t();
        var a = this.w1;
        a.progressiveThunkCompleted = delegateRemove(a.progressiveThunkCompleted, runOn(this, this.zh));
        this.w1 = null;
    };
    HighDensityScatterSeries.prototype.q7 = function (a, b, c, d) {
        _super.prototype.q7.call(this, a, b, c, d);
        switch (b) {
            case HighDensityScatterSeries.$$p[8]:
            case HighDensityScatterSeries.$$p[12]:
            case HighDensityScatterSeries.$$p[9]:
            case HighDensityScatterSeries.$$p[13]:
                this.qd();
                break;
            case "SeriesViewer":
                if (this.db != null) {
                    var e = this.getEffectiveViewport1(this.cv);
                    this.xf = !e.isEmpty;
                }
                break;
            case "FastItemsSource":
                this.zu();
                if (typeCast(IFastItemsSource_$type, c) != null) {
                    c.deregisterColumn(this.xa);
                    c.deregisterColumn(this.xc);
                    this.xa = null;
                    this.xc = null;
                }
                if (typeCast(IFastItemsSource_$type, d) != null) {
                    this.xa = this.dk(this.y7);
                    this.xc = this.dk(this.zf);
                }
                if ((this.w5 != null && !this.w5.c1()) || (this.w3 != null && !this.w3.c1())) {
                    this.rp(this.gg && c != null);
                }
                this.qk();
                break;
            case HighDensityScatterSeries.$$p[7]:
                var f = this.w2;
                this.w2 = this.w3;
                this.zu();
                if (f != null) {
                    f.rangeChanged = delegateRemove(f.rangeChanged, runOn(this, this.zk));
                }
                if (this.w2 != null) {
                    var g = this.w2;
                    g.rangeChanged = delegateCombine(g.rangeChanged, runOn(this, this.zk));
                }
                if (c != null) {
                    c.b0(this);
                }
                if (d != null) {
                    d.ct(this);
                }
                if ((this.w3 != null && !this.w3.c1()) || (d == null && c != null)) {
                    this.rp(false);
                }
                break;
            case HighDensityScatterSeries.$$p[11]:
                var h = this.w4;
                this.w4 = this.w5;
                this.zu();
                if (h != null) {
                    h.rangeChanged = delegateRemove(h.rangeChanged, runOn(this, this.zk));
                }
                if (this.w4 != null) {
                    var i = this.w4;
                    i.rangeChanged = delegateCombine(i.rangeChanged, runOn(this, this.zk));
                }
                if (c != null) {
                    c.b0(this);
                }
                if (d != null) {
                    d.ct(this);
                }
                if ((this.w5 != null && !this.w5.c1()) || (d == null && c != null)) {
                    this.rp(false);
                }
                break;
            case "MouseOverEnabled":
                this.xg = this.f8;
                this.rp(false);
                break;
            case HighDensityScatterSeries.$$p[10]:
                if (this.dn != null) {
                    this.dn.deregisterColumn(this.xa);
                    this.xa = this.dk(this.y7);
                }
                break;
            case "XColumn":
                this.zu();
                if (this.w3 != null && !this.w3.c1()) {
                    this.rp(false);
                }
                this.qk();
                break;
            case HighDensityScatterSeries.$$p[14]:
                if (this.dn != null) {
                    this.dn.deregisterColumn(this.xc);
                    this.xc = this.dk(this.zf);
                }
                break;
            case "YColumn":
                this.zu();
                if (this.w5 != null && !this.w5.c1()) {
                    this.rp(false);
                }
                this.qk();
                break;
            case HighDensityScatterSeries.$$p[6]:
                this.zu();
                this.rp(false);
                this.qj();
                break;
            case HighDensityScatterSeries.$$p[3]:
                this.rp(false);
                this.qj();
                break;
            case HighDensityScatterSeries.$$p[1]:
                this.rp(false);
                this.qj();
                break;
            case HighDensityScatterSeries.$$p[0]:
            case HighDensityScatterSeries.$$p[2]:
                if (!this.w0.b4(this.aad, this.aac)) {
                    return;
                }
                this.zo();
                this.rp(false);
                this.qj();
                break;
            case HighDensityScatterSeries.$$p[4]:
                this.yl = Math.max(typeGetValue(d) - 1, 0);
                this.xe = this.yl > 0;
                this.rp(false);
                this.qj();
                break;
            case HighDensityScatterSeries.$$p[5]:
                this.rp(false);
                this.qj();
                break;
        }
    };
    HighDensityScatterSeries.prototype.zo = function () {
        this.xx = this.aad.l;
        this.x0 = this.aad.o;
        this.xz = this.aad.n;
        this.xy = this.aad.m;
        this.xt = this.aac.l;
        this.xw = this.aac.o;
        this.xv = this.aac.n;
        this.xu = this.aac.m;
        this.vt = BrushUtil.h(truncate(this.xx), truncate(this.x0), truncate(this.xz), truncate(this.xy));
        this.vd = BrushUtil.h(truncate(this.xt), truncate(this.xw), truncate(this.xv), truncate(this.xu));
    };
    HighDensityScatterSeries.prototype.xi = function (a) {
        if (typeCast(NumericYAxis.$, a) !== null) {
            return true;
        }
        return false;
    };
    HighDensityScatterSeries.prototype.xh = function (a) {
        if (typeCast(NumericXAxis.$, a) !== null) {
            return true;
        }
        return false;
    };
    HighDensityScatterSeries.prototype.zk = function (a, b) {
        this.zu();
        this.rp(false);
    };
    Object.defineProperty(HighDensityScatterSeries.prototype, "x4", {
        get: function () {
            return this.xw - this.x0;
        },
        enumerable: false,
        configurable: true
    });
    Object.defineProperty(HighDensityScatterSeries.prototype, "x3", {
        get: function () {
            return this.xv - this.xz;
        },
        enumerable: false,
        configurable: true
    });
    Object.defineProperty(HighDensityScatterSeries.prototype, "x2", {
        get: function () {
            return this.xu - this.xy;
        },
        enumerable: false,
        configurable: true
    });
    Object.defineProperty(HighDensityScatterSeries.prototype, "x1", {
        get: function () {
            return this.xt - this.xx;
        },
        enumerable: false,
        configurable: true
    });
    HighDensityScatterSeries.prototype.he = function (a, b, c) {
        var d = _super.prototype.he.call(this, a, b, c);
        if (this.w5 == null || this.w3 == null || this.w3.bi == null || this.w5.bi == null || this.xc == null || this.xa == null || this.xc.count < 1 || this.xa.count < 1 || this.xc.count != this.xa.count || this.w3.l4 == this.w3.l3 || this.w5.l4 == this.w5.l3 || this.wq.isEmpty) {
            d = false;
        }
        return d;
    };
    Object.defineProperty(HighDensityScatterSeries.prototype, "ys", {
        get: function () {
            return this.ym;
        },
        set: function (a) {
            var b = this.ym;
            this.ym = a;
            this.raisePropertyChanged("ProgressiveStatus", b, this.ym);
        },
        enumerable: false,
        configurable: true
    });
    HighDensityScatterSeries.prototype.rq = function (a) {
        _super.prototype.rq.call(this, a);
        this.zm(a, this.cv);
    };
    HighDensityScatterSeries.prototype.xd = function () {
        if (TestRandomness.instance.testRandomnessSource != null) {
            return TestRandomness.instance.testRandomnessSource;
        }
        return new DefaultRandomnessSource(0);
    };
    HighDensityScatterSeries.prototype.zm = function (a, b) {
        if (this.d5(b)) {
            return;
        }
        if (this.w1 == null && !this.xk) {
            var c = new List$1(KDPointData.$, 2, this.xa.count);
            var d = this.w3;
            var e = this.w5;
            var f = new Rect(0, 0, 0, 1, 1);
            var g = new Rect(0, 0, 0, 1, 1);
            var h = new ScalerParams(1, f, g, d.ch);
            var i = new ScalerParams(1, f, g, e.ch);
            var j_1;
            var k_1;
            var _loop_1 = function (l) {
                j_1 = d.el(this_1.xa.item(l), h);
                k_1 = e.el(this_1.xc.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.xa.count; l++) {
                _loop_1(l);
            }
            if (this.xj) {
                this.yh = 1;
                this.yi = truncate(logBase(c.count, 2)) + 3;
                this.ys = truncate(((this.yh / this.yi) * 100));
                if (this.progressiveLoadStatusChanged != null) {
                    this.progressiveLoadStatusChanged(this, new ProgressiveLoadStatusEventArgs(this.ys));
                }
                this.w1 = KDTree2D.b(c.toArray(), 1, this.xd());
                var m = this.w1;
                m.progressiveThunkCompleted = delegateCombine(m.progressiveThunkCompleted, runOn(this, this.zh));
                if (!this.w1.h(this.jz)) {
                    var n = this.w1;
                    n.progressiveThunkCompleted = delegateRemove(n.progressiveThunkCompleted, runOn(this, this.zh));
                }
                this.qj();
            }
            else {
                var o = dateNow();
                this.w1 = new KDTree2D(0, c.toArray(), 1, this.xd());
                var p = dateNow();
            }
        }
        if (this.xj && !this.xk) {
            this.zn(b);
        }
        else {
            this.zp(b);
        }
    };
    HighDensityScatterSeries.prototype.pb = function (a, b, c, d) {
        _super.prototype.pb.call(this, a, b, c, d);
        this.zu();
        var e = false;
        if (this.w3 != null && !this.w3.c1()) {
            e = true;
        }
        if (this.w5 != null && !this.w5.c1()) {
            e = true;
        }
        if (e) {
            this.rp(false);
        }
        this.qk();
    };
    HighDensityScatterSeries.prototype.zj = function (a) {
        var b = a;
        var c = this.yk * this.yj;
        if (this.xg) {
            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.zp = 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.w6 = new ScalerParams(0, b, c, this.w2.ch, g);
        this.w7 = new ScalerParams(0, b, c, this.w4.ch, g);
        this.zi(a);
        this.zj(a);
        var h = this.yk * this.yj;
        if (this.wz == null || this.wz.length != h) {
            this.wz = new Array(h);
            this.ww = new Array(h);
        }
        var i = this.wz.length;
        var j = this.wz;
        var k = this.ww;
        for (var l = 0; l < i; l++) {
            j[l] = 0;
            k[l] = 0;
        }
        this.yo = truncate(Math.round(this.id));
        this.wy = f.b1();
        var m = this.wy.length;
        var n = this.wy;
        for (var o = 0; o < m; o++) {
            n[o] = 0;
        }
        var p = this.yf;
        var q = this.ye;
        if (isNaN_(p) || isInfinity(p)) {
            p = 0;
        }
        if (isNaN_(q) || isInfinity(q)) {
            q = 50;
        }
        this.xr = Math.min(p, q);
        this.xq = Math.max(p, q);
        if (this.xr < 0) {
            this.xr = 0;
        }
        if (this.xq < 0) {
            this.xq = 0;
        }
        this.xs = this.xq - this.xr;
        if (this.xk) {
            this.zl(a);
        }
        else {
            this.zw(a);
        }
        f.cc();
        if (a.q) {
            this._itemIndexes = d;
            this.w0.cd();
        }
    };
    HighDensityScatterSeries.prototype.zn = function (a) {
        if (this.w1 == null) {
            return;
        }
        this.zp(a);
    };
    HighDensityScatterSeries.prototype.zh = function (a, b) {
        var _this = this;
        this.w0.cb(function () {
            if (_this.yh < _this.yi - 1) {
                _this.yh++;
            }
            _this.ys = truncate(((_this.yh / _this.yi) * 100));
            if (_this.progressiveLoadStatusChanged != null) {
                _this.progressiveLoadStatusChanged(_this, new ProgressiveLoadStatusEventArgs(_this.ys));
            }
            _this.zn(_this.cv);
            _this.qj();
            if (_this.w1 != null) {
                if (!_this.w1.h(_this.jz)) {
                    var c = _this.w1;
                    c.progressiveThunkCompleted = delegateRemove(c.progressiveThunkCompleted, runOn(_this, _this.zh));
                    _this.ys = 100;
                    if (_this.progressiveLoadStatusChanged != null) {
                        _this.progressiveLoadStatusChanged(_this, new ProgressiveLoadStatusEventArgs(_this.ys));
                    }
                }
            }
        });
    };
    HighDensityScatterSeries.prototype.zl = function (a) {
        var b = arrayShallowClone(this.xa.asArray());
        this.w3.hq(boxArray$1(b), 0, b.length, this.w6);
        var c = arrayShallowClone(this.xc.asArray());
        this.yn = 0;
        var d = this.yl;
        var e = this.xe;
        var f = this.wz.length;
        this.w5.hq(boxArray$1(c), 0, c.length, this.w7);
        var g = 255 << 24 | truncate(this.x0) << 16 | truncate(this.xz) << 8 | truncate(this.xy);
        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.yk || j < 0 || j >= this.yj) {
                continue;
            }
            if (e) {
                var k = i - d;
                var l = i + d;
                l = l > (this.yk - 1) ? (this.yk - 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.yk) + o;
                        if (q < 0 || q > f - 1) {
                            continue;
                        }
                        this.wz[q] = this.wz[q] + 1;
                        this.ww[q] = 1;
                        this.yn++;
                        if (this.xg) {
                            this._itemIndexes[q] = h + 1;
                        }
                    }
                }
            }
            else {
                var r = (j * this.yk) + i;
                this.wz[r] = this.wz[r] + 1;
                this.ww[r] = 1;
                this.yn++;
                if (this.xg) {
                    this._itemIndexes[r] = h + 1;
                }
            }
        }
        this.zq();
    };
    HighDensityScatterSeries.prototype.zw = function (a) {
        var b;
        var c;
        var d = a.getViewInfo(b, c);
        b = d.p0;
        c = d.p1;
        if (this.w1 == null) {
            return;
        }
        if (this.xl == null) {
            this.xl = new List$1(KDTreeNode2D.$, 2, truncate(Math.round(b.width * b.height)));
        }
        else {
            this.xl.clear();
        }
        var e = c.left;
        var f = c.right;
        var g = c.top;
        var h = c.bottom;
        this.yb = c.top;
        this.x9 = c.height;
        this.ya = c.left;
        this.yc = c.width;
        this.x7 = b.top;
        this.x5 = b.height;
        this.x6 = b.left;
        this.x8 = b.width;
        var i = this.getEffectiveViewport1(a);
        this.xn = (i.left - this.x6) / this.x8;
        this.xo = (i.top - this.x7) / this.x5;
        var j = (i.right - this.x6) / this.x8;
        this.xp = j - this.xn;
        var k = (i.bottom - this.x7) / this.x5;
        this.xm = k - this.xo;
        if (this.xf) {
            e = (e - this.xn) / this.xp;
            f = (f - this.xn) / this.xp;
            g = (g - this.xo) / this.xm;
            h = (h - this.xo) / this.xm;
        }
        var l = this.id / b.width * c.width;
        var m = this.id / 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.w1.u(this.xl, o, 0, 1, 0, 1);
        var p;
        this.yn = 0;
        for (var q = 0; q < this.xl.count; q++) {
            p = this.xl._inner[q];
            this.zr(p);
        }
        this.zq();
    };
    HighDensityScatterSeries.prototype.zr = 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.zt(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.zt(e, d, false, a.e);
            }
        }
        if (a.e != null) {
            a.e.a = false;
        }
    };
    HighDensityScatterSeries.prototype.gd = function (a) {
        var b = this.db != null ? this.db.v4 : Rect.empty;
        var c = this.db != null ? this.db.wj : Rect.empty;
        var d = new Rect(0, 0, 0, 1, 1);
        var e = this.wj(this.cv);
        var f = new ScalerParams(0, d, d, this.w3.ch, e);
        var g = new ScalerParams(0, d, d, this.w5.ch, e);
        var h = !b.isEmpty && !c.isEmpty && this.dn != null ? this.dn.indexOf(a) : -1;
        var i = this.w3 != null && this.xa != null && h < this.xa.count ? this.w3.el(this.xa.item(h), f) : NaN;
        var j = this.w5 != null && this.xc != null && h < this.xc.count ? this.w5.el(this.xc.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.c3 != null) {
            this.c3.au(this.db, b, true);
        }
        return h >= 0;
    };
    HighDensityScatterSeries.prototype.zt = function (a, b, c, d) {
        var e = this.yq(b);
        var f = a.c;
        var g = this.yl;
        if (c) {
            var h = d.d;
            var i = d.b;
            var j = d.e;
            var k = d.c;
            if (this.xf) {
                h = this.xn + this.xp * h;
                i = this.xn + this.xp * i;
                j = this.xo + this.xm * j;
                k = this.xo + this.xm * k;
            }
            var l = truncate((this.x6 + this.x8 * (h - this.ya) / this.yc));
            var m = truncate((this.x6 + this.x8 * (i - this.ya) / this.yc));
            var n = truncate((this.x7 + this.x5 * (j - this.yb) / this.x9));
            var o = truncate((this.x7 + this.x5 * (k - this.yb) / this.x9));
            l = truncate(Math.floor(l));
            m = truncate(Math.floor(m));
            n = truncate(Math.floor(n));
            o = truncate(Math.floor(o));
            if (this.xe) {
                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.zs(f, s, t, q, r);
                }
            }
        }
        else {
            var u = a.a;
            var v = a.b;
            if (this.xf) {
                u = this.xn + this.xp * u;
                v = this.xo + this.xm * v;
            }
            var w = truncate((this.x6 + this.x8 * (u - this.ya) / this.yc));
            var x = truncate((this.x7 + this.x5 * (v - this.yb) / this.x9));
            w = truncate(Math.floor(w));
            x = truncate(Math.floor(x));
            if (this.xe) {
                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.zs(f, af, ag, ad, ae);
                    }
                }
            }
            else {
                this.zs(f, w, x, b, 1);
            }
        }
    };
    HighDensityScatterSeries.prototype.yp = function (a, b) {
        return truncate((Math.floor(255 * b))) << 24 | truncate(Math.floor(b * (this.x0 + a * this.x4))) << 16 | truncate(Math.floor(b * (this.xz + a * this.x3))) << 8 | truncate(Math.floor(b * (this.xy + a * this.x2)));
    };
    HighDensityScatterSeries.prototype.yq = function (a) {
        return 255 << 24 | truncate(Math.floor((this.x0 + a * this.x4))) << 16 | truncate(Math.floor((this.xz + a * this.x3))) << 8 | truncate(Math.floor((this.xy + a * this.x2)));
    };
    HighDensityScatterSeries.prototype.yd = function (a) {
        return (a >> 24 & 255) / 255;
    };
    HighDensityScatterSeries.prototype.zs = function (a, b, c, d, e) {
        if (b < 0 || b >= this.yk || c < 0 || c >= this.yj) {
            return;
        }
        var f = (c * this.yk) + b;
        this.wz[f] = this.wz[f] + d;
        this.ww[f] = this.ww[f] + e;
        if (this.xg) {
            this._itemIndexes[f] = a + 1;
        }
        this.yn += truncate(d);
    };
    HighDensityScatterSeries.prototype.zq = function () {
        var a = 0;
        var b = 0;
        var c = this.xs;
        var d = this.xr;
        var e = this.xq;
        var f = this.wz.length;
        var g = this.wz;
        var h = this.ww;
        var i = this.wy;
        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.yp(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.zi = function (a) {
        var b = a;
        b.b9();
    };
    HighDensityScatterSeries.prototype.cs = function () {
        return new HighDensityScatterSeriesView(this);
    };
    HighDensityScatterSeries.prototype.qz = function (a) {
        _super.prototype.qz.call(this, a);
        this.w0 = a;
    };
    HighDensityScatterSeries.prototype.ay = function (a) {
        if (a != null && a == this.w3 && this.xa != null) {
            return new AxisRange(this.xa.minimum, this.xa.maximum);
        }
        if (a != null && a == this.w5 && this.xc != null) {
            return new AxisRange(this.xc.minimum, this.xc.maximum);
        }
        return null;
    };
    HighDensityScatterSeries.prototype.so = function (a, b) {
        if (this.db != null) {
            var c = this.getEffectiveViewport1(this.cv);
            this.xf = !c.isEmpty;
        }
        this.rp(false);
    };
    HighDensityScatterSeries.prototype.sp = function (a, b) {
        this.rp(false);
    };
    HighDensityScatterSeries.prototype.kn = function (a) {
        if (!this.xg || this._itemIndexes == null || this.db == null || this.dn == null || this._itemIndexes.length != (this.yk * this.yj)) {
            return null;
        }
        var b = this.db.v4;
        var c = (a.x - b.left) / b.width;
        var d = (a.y - b.top) / b.height;
        var e = truncate(Math.round(this.wq.left + (this.wq.width * c)));
        var f = truncate(Math.round(this.wq.top + (this.wq.height * d)));
        var g = this.yt(e, f);
        if (g < 0 || g > this._itemIndexes.length - 1) {
            return null;
        }
        var h = this._itemIndexes[g] - 1;
        if (h < 0 || h > this.dn.count) {
            return null;
        }
        return this.dn.item(h);
    };
    HighDensityScatterSeries.prototype.yt = function (a, b) {
        var c = (this.yk * b) + a;
        if (c > 0 && c < this._itemIndexes.length && this._itemIndexes[c] > 0) {
            return c;
        }
        var d = 1;
        c = (this.yk * (b - d)) + a;
        if (c > 0 && c < this._itemIndexes.length && this._itemIndexes[c] > 0) {
            return c;
        }
        c = (this.yk * (b + d)) + a;
        if (c > 0 && c < this._itemIndexes.length && this._itemIndexes[c] > 0) {
            return c;
        }
        c = (this.yk * (b)) + a - 1;
        if (c > 0 && c < this._itemIndexes.length && this._itemIndexes[c] > 0) {
            return c;
        }
        c = (this.yk * (b)) + a + 1;
        if (c > 0 && c < this._itemIndexes.length && this._itemIndexes[c] > 0) {
            return c;
        }
        c = (this.yk * (b - d)) + a - 1;
        if (c > 0 && c < this._itemIndexes.length && this._itemIndexes[c] > 0) {
            return c;
        }
        c = (this.yk * (b + d)) + a + 1;
        if (c > 0 && c < this._itemIndexes.length && this._itemIndexes[c] > 0) {
            return c;
        }
        c = (this.yk * (b - d)) + a + 1;
        if (c > 0 && c < this._itemIndexes.length && this._itemIndexes[c] > 0) {
            return c;
        }
        c = (this.yk * (b + d)) + a - 1;
        if (c > 0 && c < this._itemIndexes.length && this._itemIndexes[c] > 0) {
            return c;
        }
        return 0;
    };
    HighDensityScatterSeries.prototype.zv = function (a, b, c) {
        this.wy = a;
        this.yk = b;
        this.yj = c;
    };
    HighDensityScatterSeries.prototype.get_g7 = function () {
        return true;
    };
    HighDensityScatterSeries.prototype.set_g7 = function (a) {
        _super.prototype.set_g7.call(this, a);
    };
    HighDensityScatterSeries.prototype.o5 = function (a, b) {
        _super.prototype.o5.call(this, a, b);
        this.w0.ca();
        if (this.cu != null) {
            this.cu.ca();
        }
        this.qj();
    };
    HighDensityScatterSeries.prototype.rr = function (a, b) {
        _super.prototype.rr.call(this, a, b);
        if (!this.g0) {
            this.cv.a4(b);
            return;
        }
        this.cv.a4(b);
        if (this.d5(this.cu)) {
            return;
        }
        var c = typeCast(HighDensityScatterSeriesView.$, this.cu);
        var d = new ScatterFrame();
        this.zm(false, c);
        this.g0 = false;
    };
    HighDensityScatterSeries.prototype.ro = function (a, b, c, d, e) {
        _super.prototype.ro.call(this, a, b, c, d, e);
        var f = this.ba.a$j.item(d);
        var g = f;
        f.a3(c);
        if (this.d5(g)) {
            return;
        }
        if (this.w8 == null) {
            this.w8 = new ScatterFrame();
        }
        this.zm(false, f);
    };
    HighDensityScatterSeries.prototype.o2 = function () {
        _super.prototype.o2.call(this);
        this.w3 = null;
        this.w5 = null;
    };
    HighDensityScatterSeries.$t = markType(HighDensityScatterSeries, 'HighDensityScatterSeries', Series.$);
    HighDensityScatterSeries.$$p = markDep(DependencyProperty, PropertyMetadata, HighDensityScatterSeries, 'raisePropertyChanged', ['HeatMaximumColor:aac:zx', [Color.$, Defaults.ap], 'HeatMaximum:ye:zy', [1, 50], 'HeatMinimumColor:aad:zz', [Color.$, Defaults.aq], 'HeatMinimum:yf:z0', [1, 0], 'PointExtent:yr:z1', [1, 1], 'ProgressiveLoad:xj:z2', [0, true], 'UseBruteForce:xk:z3', [0, false], 'XAxis:w3:z4', [NumericXAxis.$, null], 'XMemberAsLegendLabel:y3:z5', [2, null], 'XMemberAsLegendUnit:y5:z6', [2, null], 'XMemberPath:y7:z7', [2, null], 'YAxis:w5:z8', [NumericYAxis.$, null], 'YMemberAsLegendLabel:zb:z9', [2, null], 'YMemberAsLegendUnit:zd:aaa', [2, null], 'YMemberPath:zf:aab', [2, null]]);
    return HighDensityScatterSeries;
}(Series));
export { HighDensityScatterSeries };
/**
 * @hidden
 */
var HighDensityScatterSeriesView = /** @class */ /*@__PURE__*/ (function (_super) {
    __extends(HighDensityScatterSeriesView, _super);
    function HighDensityScatterSeriesView(a) {
        var _this = _super.call(this, a) || this;
        _this.b2 = null;
        _this.b0 = null;
        _this.b8 = 0;
        _this.b7 = 0;
        _this.b5 = null;
        _this.b6 = null;
        _this.b3 = null;
        _this.b2 = a;
        return _this;
    }
    HighDensityScatterSeriesView.prototype.au = function () {
        _super.prototype.au.call(this);
        if (!this.q) {
            this.b2.aad = Defaults.aq;
            this.b2.aac = Defaults.ap;
            this.b2.vd = Defaults.al;
            this.b2.vt = Defaults.ak;
        }
    };
    HighDensityScatterSeriesView.prototype.cd = function () {
        this.b2.zv(this.b0, this.b8, this.b7);
    };
    HighDensityScatterSeriesView.prototype.b9 = function () {
        if (this.b5 == null) {
            this.b5 = this.e.jz.createElement("canvas");
            var a = this.e.jz.get2DCanvasContext(this.b5);
            this.b3 = new RenderingContext(new CanvasViewRenderer(), a);
        }
        var b;
        if (this.p) {
            b = this.bx;
        }
        else {
            b = this.e.db.v9();
        }
        var c = truncate(Math.round(b.left));
        var d = truncate(Math.round(b.top));
        var e = truncate(Math.round(b.width));
        var f = truncate(Math.round(b.height));
        var g = this.b8;
        var h = this.b7;
        this.b8 = e;
        this.b7 = f;
        if (g != this.b8 || h != this.b7 || this.b0 == null) {
            this.b5.setAttribute("width", e.toString());
            this.b5.setAttribute("height", f.toString());
            this.b6 = this.b3.h().getImageData(0, 0, e, f);
            var imageDataArray_ = this.b6.data;
            this.b0 = imageDataArray_;
        }
        this.b2.zv(this.b0, this.b8, this.b7);
    };
    HighDensityScatterSeriesView.prototype.b1 = function () {
        return this.b0;
    };
    HighDensityScatterSeriesView.prototype.cc = function () {
        var a = truncate(Math.round(this.bx.left));
        var b = truncate(Math.round(this.bx.left));
        var c = truncate(Math.round(this.bx.width));
        var d = truncate(Math.round(this.bx.height));
        this.b3.h().putImageData(this.b6, 0, 0);
        this.as();
    };
    HighDensityScatterSeriesView.prototype.cb = function (a) {
        if (this.e.jz != null) {
            this.e.jz.setTimeout(a, 0);
        }
        else {
            window.setTimeout(a, 0);
        }
    };
    HighDensityScatterSeriesView.prototype.a8 = function (a, b) {
        _super.prototype.a8.call(this, a, b);
        if (b) {
            if (!this.b2.f8) {
                return;
            }
            var c = new Rectangle();
            c.n = this.bx.left;
            c.o = this.bx.top;
            c.width = this.bx.width;
            c.height = this.bx.height;
            c._fill = this.br();
            a.w(c);
            return;
        }
        if (this.b5 == null) {
            return;
        }
        var d = truncate(Math.round(this.bx.left));
        var e = truncate(Math.round(this.bx.top));
        var f = truncate(Math.round(this.bx.width));
        var g = truncate(Math.round(this.bx.height));
        this.k.o(this.b5.getNativeElement(), this.e._opacity, d, e, f, g, d, e, f, g);
    };
    HighDensityScatterSeriesView.prototype.b4 = function (a, b) {
        return Color.e(toNullable(Color.$, a), toNullable(Color.$, null)) && Color.e(toNullable(Color.$, b), toNullable(Color.$, null));
    };
    HighDensityScatterSeriesView.prototype.ca = function () {
        if (this.b0 != null) {
            for (var a = 0; a < this.b0.length; a++) {
                this.b0[a] = 0;
            }
            this.cc();
        }
    };
    HighDensityScatterSeriesView.prototype.an = function (a) {
        _super.prototype.an.call(this, a);
        if (this.b0 == null) {
            this.e.bc.exportSeriesPixelsData(a, null, this.b8, this.b7);
            return;
        }
        var b = new Array(intDivide(this.b0.length, 4));
        var c;
        for (var d = 0; d < intDivide(this.b0.length, 4); d++) {
            c = d * 4;
            b[d] = this.b0[c + 3] << 24 | this.b0[c] << 16 | this.b0[c + 1] << 8 | this.b0[c + 2];
        }
        this.e.bc.exportSeriesPixelsData(a, b, this.b8, this.b7);
    };
    HighDensityScatterSeriesView.$t = markType(HighDensityScatterSeriesView, 'HighDensityScatterSeriesView', SeriesView.$);
    return HighDensityScatterSeriesView;
}(SeriesView));
export { HighDensityScatterSeriesView };
