/*
THIS INFRAGISTICS ULTIMATE SOFTWARE LICENSE  AGREEMENT ("AGREEMENT") LOCATED HERE:
https://www.infragistics.com/legal/license/igultimate-la
https://www.infragistics.com/legal/license/igultimate-eula
GOVERNS THE LICENSING, INSTALLATION AND USE OF INFRAGISTICS SOFTWARE. BY DOWNLOADING AND/OR INSTALLING AND USING INFRAGISTICS SOFTWARE:  you are indicating that you have read and understand this Agreement, and agree to be legally bound by it on behalf of the yourself and your company.
*/
import { __extends } from "tslib";
import { Series } from "./Series";
import { NumericXAxis } from "./NumericXAxis";
import { DependencyProperty } from "igniteui-react-core";
import { NumericYAxis } from "./NumericYAxis";
import { Color } from "igniteui-react-core";
import { ScatterFrame } from "./ScatterFrame";
import { Defaults } from "./Defaults";
import { KDTree2D } from "./KDTree2D";
import { Point_$type, typeGetValue, runOn, delegateRemove, typeCast, delegateCombine, markType, markDep, toNullable } from "igniteui-react-core";
import { DataLegendSeriesValueInfo } from "igniteui-react-core";
import { DataLegendSeriesContext } from "igniteui-react-core";
import { List$1 } from "igniteui-react-core";
import { Rect } from "igniteui-react-core";
import { IFastItemsSource_$type } from "igniteui-react-core";
import { BrushUtil } from "igniteui-react-core";
import { SeriesView } from "./SeriesView";
import { KDPointData } from "./KDPointData";
import { ScalerParams } from "./ScalerParams";
import { ProgressiveLoadStatusEventArgs } from "./ProgressiveLoadStatusEventArgs";
import { SearchArgs } from "./SearchArgs";
import { KDTreeNode2D } from "./KDTreeNode2D";
import { AxisRange } from "./AxisRange";
import { PropertyMetadata } from "igniteui-react-core";
import { truncate, isNaN_, isInfinity, logBase, intDivide } from "igniteui-react-core";
import { boxArray$1, arrayShallowClone } from "igniteui-react-core";
import { dateNow } from "igniteui-react-core";
import { RenderingContext } from "igniteui-react-core";
import { CanvasViewRenderer } from "igniteui-react-core";
import { Rectangle } from "igniteui-react-core";
/**
 * @hidden
 */
var HighDensityScatterSeries = /** @class */ /*@__PURE__*/ (function (_super) {
    __extends(HighDensityScatterSeries, _super);
    function HighDensityScatterSeries() {
        var _this = _super.call(this) || this;
        _this.w2 = null;
        _this.w4 = null;
        _this.yd = 0;
        _this.w6 = false;
        _this.xs = Defaults.aq.o;
        _this.xr = Defaults.aq.n;
        _this.xq = Defaults.aq.m;
        _this.xp = Defaults.aq.l;
        _this.xo = Defaults.ap.o;
        _this.xn = Defaults.ap.n;
        _this.xm = Defaults.ap.m;
        _this.xl = Defaults.ap.l;
        _this.wu = null;
        _this.wz = null;
        _this.w0 = null;
        _this.wv = null;
        _this.wx = null;
        _this.w8 = false;
        _this.ye = 0;
        _this.yg = 0;
        _this.ya = 0;
        _this.x9 = 0;
        _this.progressiveLoadStatusChanged = null;
        _this.xd = null;
        _this.xj = 0;
        _this.xi = 0;
        _this.xk = 0;
        _this.xz = 0;
        _this.xx = 0;
        _this.xy = 0;
        _this.x0 = 0;
        _this.x2 = 0;
        _this.x4 = 0;
        _this.x3 = 0;
        _this.x1 = 0;
        _this.xf = 0;
        _this.xg = 0;
        _this.xh = 0;
        _this.xe = 0;
        _this.yc = 0;
        _this.yb = 0;
        _this.wr = null;
        _this.yf = 0;
        _this.w7 = false;
        _this._itemIndexes = null;
        _this.ws = null;
        _this.wp = null;
        _this.w1 = null;
        _this.ab = HighDensityScatterSeries.$;
        _this.f6 = false;
        return _this;
    }
    HighDensityScatterSeries.prototype.bi = function () {
        return new HighDensityScatterSeries();
    };
    HighDensityScatterSeries.prototype.get_fm = function () {
        return true;
    };
    HighDensityScatterSeries.prototype.ji = function () {
        if (!isNaN_(this.jh)) {
            return _super.prototype.ji.call(this);
        }
        return Defaults.q;
    };
    HighDensityScatterSeries.prototype.get_fu = function () {
        return true;
    };
    Object.defineProperty(HighDensityScatterSeries.prototype, "w3", {
        get: function () {
            return this.w2;
        },
        set: function (a) {
            if (this.w2 != a) {
                var b = this.w3;
                this.w2 = a;
                this.raisePropertyChanged("XColumn", b, this.w3);
            }
        },
        enumerable: false,
        configurable: true
    });
    HighDensityScatterSeries.prototype.getDataLegendSeriesContextAt = function (a, b) {
        var c = { $type: Point_$type, x: a, y: b };
        var d = this.kl(c);
        var e = d == null ? NaN : this.iv(d, "XMemberPath");
        var f = d == null ? NaN : this.iv(d, "YMemberPath");
        var g = new DataLegendSeriesValueInfo();
        g.l = e;
        g.a = 13;
        g.q = "X";
        g.r = this.yz != null ? this.yz : "X";
        g.s = this.yv != null ? this.yv : "X:";
        g.t = this.yx != null ? this.yx : "";
        var h = new DataLegendSeriesValueInfo();
        h.l = f;
        h.a = 14;
        h.q = "Y";
        h.r = this.y7 != null ? this.y7 : "Y";
        h.s = this.y3 != null ? this.y3 : "Y:";
        h.t = this.y5 != null ? this.y5 : "";
        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.l9();
        return i;
    };
    HighDensityScatterSeries.prototype.ko = function (a, b) {
        var c = this.na(b);
        if (c == HighDensityScatterSeries.$$p[10]) {
            return this.kp(a, b, this.yz);
        }
        if (c == HighDensityScatterSeries.$$p[14]) {
            return this.kp(a, b, this.y7);
        }
        return _super.prototype.ko.call(this, a, b);
    };
    HighDensityScatterSeries.prototype.ma = function (a) {
        var b = this.na(a);
        if (b == HighDensityScatterSeries.$$p[10]) {
            return this.yz;
        }
        if (b == HighDensityScatterSeries.$$p[14]) {
            return this.y7;
        }
        return _super.prototype.ma.call(this, a);
    };
    Object.defineProperty(HighDensityScatterSeries.prototype, "w5", {
        get: function () {
            return this.w4;
        },
        set: function (a) {
            if (this.w4 != a) {
                var b = this.w5;
                this.w4 = a;
                this.raisePropertyChanged("YColumn", b, this.w5);
            }
        },
        enumerable: false,
        configurable: true
    });
    HighDensityScatterSeries.prototype.zm = function () {
        if (this.wu == null) {
            return;
        }
        this.wu.s();
        var a = this.wu;
        a.progressiveThunkCompleted = delegateRemove(a.progressiveThunkCompleted, runOn(this, this.y9));
        this.wu = null;
    };
    HighDensityScatterSeries.prototype.q4 = function (a, b, c, d) {
        _super.prototype.q4.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.qa();
                break;
            case "SeriesViewer":
                if (this.c9 != null) {
                    var e = this.getEffectiveViewport1(this.ct);
                    this.w7 = !e.isEmpty;
                }
                break;
            case "FastItemsSource":
                this.zm();
                if (typeCast(IFastItemsSource_$type, c) != null) {
                    c.deregisterColumn(this.w3);
                    c.deregisterColumn(this.w5);
                    this.w3 = null;
                    this.w5 = null;
                }
                if (typeCast(IFastItemsSource_$type, d) != null) {
                    this.w3 = this.di(this.yz);
                    this.w5 = this.di(this.y7);
                }
                if ((this.wy != null && !this.wy.c1()) || (this.ww != null && !this.ww.c1())) {
                    this.rm(this.ge && c != null);
                }
                this.qh();
                break;
            case HighDensityScatterSeries.$$p[7]:
                var f = this.wv;
                this.wv = this.ww;
                this.zm();
                if (f != null) {
                    f.rangeChanged = delegateRemove(f.rangeChanged, runOn(this, this.zc));
                }
                if (this.wv != null) {
                    var g = this.wv;
                    g.rangeChanged = delegateCombine(g.rangeChanged, runOn(this, this.zc));
                }
                if (c != null) {
                    c.b0(this);
                }
                if (d != null) {
                    d.ct(this);
                }
                if ((this.ww != null && !this.ww.c1()) || (d == null && c != null)) {
                    this.rm(false);
                }
                break;
            case HighDensityScatterSeries.$$p[11]:
                var h = this.wx;
                this.wx = this.wy;
                this.zm();
                if (h != null) {
                    h.rangeChanged = delegateRemove(h.rangeChanged, runOn(this, this.zc));
                }
                if (this.wx != null) {
                    var i = this.wx;
                    i.rangeChanged = delegateCombine(i.rangeChanged, runOn(this, this.zc));
                }
                if (c != null) {
                    c.b0(this);
                }
                if (d != null) {
                    d.ct(this);
                }
                if ((this.wy != null && !this.wy.c1()) || (d == null && c != null)) {
                    this.rm(false);
                }
                break;
            case "MouseOverEnabled":
                this.w8 = this.f6;
                this.rm(false);
                break;
            case HighDensityScatterSeries.$$p[10]:
                if (this.dl != null) {
                    this.dl.deregisterColumn(this.w3);
                    this.w3 = this.di(this.yz);
                }
                break;
            case "XColumn":
                this.zm();
                if (this.ww != null && !this.ww.c1()) {
                    this.rm(false);
                }
                this.qh();
                break;
            case HighDensityScatterSeries.$$p[14]:
                if (this.dl != null) {
                    this.dl.deregisterColumn(this.w5);
                    this.w5 = this.di(this.y7);
                }
                break;
            case "YColumn":
                this.zm();
                if (this.wy != null && !this.wy.c1()) {
                    this.rm(false);
                }
                this.qh();
                break;
            case HighDensityScatterSeries.$$p[6]:
                this.zm();
                this.rm(false);
                this.qg();
                break;
            case HighDensityScatterSeries.$$p[3]:
                this.rm(false);
                this.qg();
                break;
            case HighDensityScatterSeries.$$p[1]:
                this.rm(false);
                this.qg();
                break;
            case HighDensityScatterSeries.$$p[0]:
            case HighDensityScatterSeries.$$p[2]:
                if (!this.wt.b4(this.z5, this.z4)) {
                    return;
                }
                this.zg();
                this.rm(false);
                this.qg();
                break;
            case HighDensityScatterSeries.$$p[4]:
                this.yd = Math.max(typeGetValue(d) - 1, 0);
                this.w6 = this.yd > 0;
                this.rm(false);
                this.qg();
                break;
            case HighDensityScatterSeries.$$p[5]:
                this.rm(false);
                this.qg();
                break;
        }
    };
    HighDensityScatterSeries.prototype.zg = function () {
        this.xp = this.z5.l;
        this.xs = this.z5.o;
        this.xr = this.z5.n;
        this.xq = this.z5.m;
        this.xl = this.z4.l;
        this.xo = this.z4.o;
        this.xn = this.z4.n;
        this.xm = this.z4.m;
        this.vo = BrushUtil.h(truncate(this.xp), truncate(this.xs), truncate(this.xr), truncate(this.xq));
        this.u8 = BrushUtil.h(truncate(this.xl), truncate(this.xo), truncate(this.xn), truncate(this.xm));
    };
    HighDensityScatterSeries.prototype.xa = function (a) {
        if (typeCast(NumericYAxis.$, a) !== null) {
            return true;
        }
        return false;
    };
    HighDensityScatterSeries.prototype.w9 = function (a) {
        if (typeCast(NumericXAxis.$, a) !== null) {
            return true;
        }
        return false;
    };
    HighDensityScatterSeries.prototype.zc = function (a, b) {
        this.zm();
        this.rm(false);
    };
    Object.defineProperty(HighDensityScatterSeries.prototype, "xw", {
        get: function () {
            return this.xo - this.xs;
        },
        enumerable: false,
        configurable: true
    });
    Object.defineProperty(HighDensityScatterSeries.prototype, "xv", {
        get: function () {
            return this.xn - this.xr;
        },
        enumerable: false,
        configurable: true
    });
    Object.defineProperty(HighDensityScatterSeries.prototype, "xu", {
        get: function () {
            return this.xm - this.xq;
        },
        enumerable: false,
        configurable: true
    });
    Object.defineProperty(HighDensityScatterSeries.prototype, "xt", {
        get: function () {
            return this.xl - this.xp;
        },
        enumerable: false,
        configurable: true
    });
    HighDensityScatterSeries.prototype.hc = function (a, b, c) {
        var d = _super.prototype.hc.call(this, a, b, c);
        if (this.wy == null || this.ww == null || this.ww.bi == null || this.wy.bi == null || this.w5 == null || this.w3 == null || this.w5.count < 1 || this.w3.count < 1 || this.w5.count != this.w3.count || this.ww.ly == this.ww.lx || this.wy.ly == this.wy.lx || this.wk.isEmpty) {
            d = false;
        }
        return d;
    };
    Object.defineProperty(HighDensityScatterSeries.prototype, "yk", {
        get: function () {
            return this.ye;
        },
        set: function (a) {
            var b = this.ye;
            this.ye = a;
            this.raisePropertyChanged("ProgressiveStatus", b, this.ye);
        },
        enumerable: false,
        configurable: true
    });
    HighDensityScatterSeries.prototype.rn = function (a) {
        _super.prototype.rn.call(this, a);
        this.ze(a, this.ct);
    };
    HighDensityScatterSeries.prototype.ze = function (a, b) {
        if (this.d3(b)) {
            return;
        }
        if (this.wu == null && !this.xc) {
            var c = new List$1(KDPointData.$, 2, this.w3.count);
            var d = this.ww;
            var e = this.wy;
            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.ek(this_1.w3.item(l), h);
                k_1 = e.ek(this_1.w5.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.w3.count; l++) {
                _loop_1(l);
            }
            if (this.xb) {
                this.x9 = 1;
                this.ya = truncate(logBase(c.count, 2)) + 3;
                this.yk = truncate(((this.x9 / this.ya) * 100));
                if (this.progressiveLoadStatusChanged != null) {
                    this.progressiveLoadStatusChanged(this, new ProgressiveLoadStatusEventArgs(this.yk));
                }
                this.wu = KDTree2D.b(c.toArray(), 1);
                var m = this.wu;
                m.progressiveThunkCompleted = delegateCombine(m.progressiveThunkCompleted, runOn(this, this.y9));
                if (!this.wu.f(this.jx)) {
                    var n = this.wu;
                    n.progressiveThunkCompleted = delegateRemove(n.progressiveThunkCompleted, runOn(this, this.y9));
                }
                this.qg();
            }
            else {
                var o = dateNow();
                this.wu = new KDTree2D(0, c.toArray(), 1);
                var p = dateNow();
            }
        }
        if (this.xb && !this.xc) {
            this.zf(b);
        }
        else {
            this.zh(b);
        }
    };
    HighDensityScatterSeries.prototype.o8 = function (a, b, c, d) {
        _super.prototype.o8.call(this, a, b, c, d);
        this.zm();
        var e = false;
        if (this.ww != null && !this.ww.c1()) {
            e = true;
        }
        if (this.wy != null && !this.wy.c1()) {
            e = true;
        }
        if (e) {
            this.rm(false);
        }
        this.qh();
    };
    HighDensityScatterSeries.prototype.zb = function (a) {
        var b = a;
        var c = this.yc * this.yb;
        if (this.w8) {
            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.zh = 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.wz = new ScalerParams(0, b, c, this.wv.ch, g);
        this.w0 = new ScalerParams(0, b, c, this.wx.ch, g);
        this.za(a);
        this.zb(a);
        var h = this.yc * this.yb;
        if (this.ws == null || this.ws.length != h) {
            this.ws = new Array(h);
            this.wp = new Array(h);
        }
        var i = this.ws.length;
        var j = this.ws;
        var k = this.wp;
        for (var l = 0; l < i; l++) {
            j[l] = 0;
            k[l] = 0;
        }
        this.yg = truncate(Math.round(this.ib));
        this.wr = f.b1();
        var m = this.wr.length;
        var n = this.wr;
        for (var o = 0; o < m; o++) {
            n[o] = 0;
        }
        var p = this.x7;
        var q = this.x6;
        if (isNaN_(p) || isInfinity(p)) {
            p = 0;
        }
        if (isNaN_(q) || isInfinity(q)) {
            q = 50;
        }
        this.xj = Math.min(p, q);
        this.xi = Math.max(p, q);
        if (this.xj < 0) {
            this.xj = 0;
        }
        if (this.xi < 0) {
            this.xi = 0;
        }
        this.xk = this.xi - this.xj;
        if (this.xc) {
            this.zd(a);
        }
        else {
            this.zo(a);
        }
        f.cc();
        if (a.q) {
            this._itemIndexes = d;
            this.wt.cd();
        }
    };
    HighDensityScatterSeries.prototype.zf = function (a) {
        if (this.wu == null) {
            return;
        }
        this.zh(a);
    };
    HighDensityScatterSeries.prototype.y9 = function (a, b) {
        var _this = this;
        this.wt.cb(function () {
            if (_this.x9 < _this.ya - 1) {
                _this.x9++;
            }
            _this.yk = truncate(((_this.x9 / _this.ya) * 100));
            if (_this.progressiveLoadStatusChanged != null) {
                _this.progressiveLoadStatusChanged(_this, new ProgressiveLoadStatusEventArgs(_this.yk));
            }
            _this.zf(_this.ct);
            _this.qg();
            if (_this.wu != null) {
                if (!_this.wu.f(_this.jx)) {
                    var c = _this.wu;
                    c.progressiveThunkCompleted = delegateRemove(c.progressiveThunkCompleted, runOn(_this, _this.y9));
                    _this.yk = 100;
                    if (_this.progressiveLoadStatusChanged != null) {
                        _this.progressiveLoadStatusChanged(_this, new ProgressiveLoadStatusEventArgs(_this.yk));
                    }
                }
            }
        });
    };
    HighDensityScatterSeries.prototype.zd = function (a) {
        var b = arrayShallowClone(this.w3.asArray());
        this.ww.ho(boxArray$1(b), 0, b.length, this.wz);
        var c = arrayShallowClone(this.w5.asArray());
        this.yf = 0;
        var d = this.yd;
        var e = this.w6;
        var f = this.ws.length;
        this.wy.ho(boxArray$1(c), 0, c.length, this.w0);
        var g = 255 << 24 | truncate(this.xs) << 16 | truncate(this.xr) << 8 | truncate(this.xq);
        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.yc || j < 0 || j >= this.yb) {
                continue;
            }
            if (e) {
                var k = i - d;
                var l = i + d;
                l = l > (this.yc - 1) ? (this.yc - 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.yc) + o;
                        if (q < 0 || q > f - 1) {
                            continue;
                        }
                        this.ws[q] = this.ws[q] + 1;
                        this.wp[q] = 1;
                        this.yf++;
                        if (this.w8) {
                            this._itemIndexes[q] = h + 1;
                        }
                    }
                }
            }
            else {
                var r = (j * this.yc) + i;
                this.ws[r] = this.ws[r] + 1;
                this.wp[r] = 1;
                this.yf++;
                if (this.w8) {
                    this._itemIndexes[r] = h + 1;
                }
            }
        }
        this.zi();
    };
    HighDensityScatterSeries.prototype.zo = function (a) {
        var b;
        var c;
        var d = a.getViewInfo(b, c);
        b = d.p0;
        c = d.p1;
        if (this.wu == null) {
            return;
        }
        if (this.xd == null) {
            this.xd = new List$1(KDTreeNode2D.$, 2, truncate(Math.round(b.width * b.height)));
        }
        else {
            this.xd.clear();
        }
        var e = c.left;
        var f = c.right;
        var g = c.top;
        var h = c.bottom;
        this.x3 = c.top;
        this.x1 = c.height;
        this.x2 = c.left;
        this.x4 = c.width;
        this.xz = b.top;
        this.xx = b.height;
        this.xy = b.left;
        this.x0 = b.width;
        var i = this.getEffectiveViewport1(a);
        this.xf = (i.left - this.xy) / this.x0;
        this.xg = (i.top - this.xz) / this.xx;
        var j = (i.right - this.xy) / this.x0;
        this.xh = j - this.xf;
        var k = (i.bottom - this.xz) / this.xx;
        this.xe = k - this.xg;
        if (this.w7) {
            e = (e - this.xf) / this.xh;
            f = (f - this.xf) / this.xh;
            g = (g - this.xg) / this.xe;
            h = (h - this.xg) / this.xe;
        }
        var l = this.ib / b.width * c.width;
        var m = this.ib / 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.wu.t(this.xd, o, 0, 1, 0, 1);
        var p;
        this.yf = 0;
        for (var q = 0; q < this.xd.count; q++) {
            p = this.xd._inner[q];
            this.zj(p);
        }
        this.zi();
    };
    HighDensityScatterSeries.prototype.zj = 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.zl(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.zl(e, d, false, a.e);
            }
        }
        if (a.e != null) {
            a.e.a = false;
        }
    };
    HighDensityScatterSeries.prototype.gb = function (a) {
        var b = this.c9 != null ? this.c9.vl : Rect.empty;
        var c = this.c9 != null ? this.c9.v0 : Rect.empty;
        var d = new Rect(0, 0, 0, 1, 1);
        var e = this.we(this.ct);
        var f = new ScalerParams(0, d, d, this.ww.ch, e);
        var g = new ScalerParams(0, d, d, this.wy.ch, e);
        var h = !b.isEmpty && !c.isEmpty && this.dl != null ? this.dl.indexOf(a) : -1;
        var i = this.ww != null && this.w3 != null && h < this.w3.count ? this.ww.ek(this.w3.item(h), f) : NaN;
        var j = this.wy != null && this.w5 != null && h < this.w5.count ? this.wy.ek(this.w5.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.c1 != null) {
            this.c1.au(this.c9, b, true);
        }
        return h >= 0;
    };
    HighDensityScatterSeries.prototype.zl = function (a, b, c, d) {
        var e = this.yi(b);
        var f = a.c;
        var g = this.yd;
        if (c) {
            var h = d.d;
            var i = d.b;
            var j = d.e;
            var k = d.c;
            if (this.w7) {
                h = this.xf + this.xh * h;
                i = this.xf + this.xh * i;
                j = this.xg + this.xe * j;
                k = this.xg + this.xe * k;
            }
            var l = truncate((this.xy + this.x0 * (h - this.x2) / this.x4));
            var m = truncate((this.xy + this.x0 * (i - this.x2) / this.x4));
            var n = truncate((this.xz + this.xx * (j - this.x3) / this.x1));
            var o = truncate((this.xz + this.xx * (k - this.x3) / this.x1));
            l = truncate(Math.floor(l));
            m = truncate(Math.floor(m));
            n = truncate(Math.floor(n));
            o = truncate(Math.floor(o));
            if (this.w6) {
                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.zk(f, s, t, q, r);
                }
            }
        }
        else {
            var u = a.a;
            var v = a.b;
            if (this.w7) {
                u = this.xf + this.xh * u;
                v = this.xg + this.xe * v;
            }
            var w = truncate((this.xy + this.x0 * (u - this.x2) / this.x4));
            var x = truncate((this.xz + this.xx * (v - this.x3) / this.x1));
            w = truncate(Math.floor(w));
            x = truncate(Math.floor(x));
            if (this.w6) {
                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.zk(f, af, ag, ad, ae);
                    }
                }
            }
            else {
                this.zk(f, w, x, b, 1);
            }
        }
    };
    HighDensityScatterSeries.prototype.yh = function (a, b) {
        return truncate((Math.floor(255 * b))) << 24 | truncate(Math.floor(b * (this.xs + a * this.xw))) << 16 | truncate(Math.floor(b * (this.xr + a * this.xv))) << 8 | truncate(Math.floor(b * (this.xq + a * this.xu)));
    };
    HighDensityScatterSeries.prototype.yi = function (a) {
        return 255 << 24 | truncate(Math.floor((this.xs + a * this.xw))) << 16 | truncate(Math.floor((this.xr + a * this.xv))) << 8 | truncate(Math.floor((this.xq + a * this.xu)));
    };
    HighDensityScatterSeries.prototype.x5 = function (a) {
        return (a >> 24 & 255) / 255;
    };
    HighDensityScatterSeries.prototype.zk = function (a, b, c, d, e) {
        if (b < 0 || b >= this.yc || c < 0 || c >= this.yb) {
            return;
        }
        var f = (c * this.yc) + b;
        this.ws[f] = this.ws[f] + d;
        this.wp[f] = this.wp[f] + e;
        if (this.w8) {
            this._itemIndexes[f] = a + 1;
        }
        this.yf += truncate(d);
    };
    HighDensityScatterSeries.prototype.zi = function () {
        var a = 0;
        var b = 0;
        var c = this.xk;
        var d = this.xj;
        var e = this.xi;
        var f = this.ws.length;
        var g = this.ws;
        var h = this.wp;
        var i = this.wr;
        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.yh(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.za = function (a) {
        var b = a;
        b.b9();
    };
    HighDensityScatterSeries.prototype.cq = function () {
        return new HighDensityScatterSeriesView(this);
    };
    HighDensityScatterSeries.prototype.qw = function (a) {
        _super.prototype.qw.call(this, a);
        this.wt = a;
    };
    HighDensityScatterSeries.prototype.ax = function (a) {
        if (a != null && a == this.ww && this.w3 != null) {
            return new AxisRange(this.w3.minimum, this.w3.maximum);
        }
        if (a != null && a == this.wy && this.w5 != null) {
            return new AxisRange(this.w5.minimum, this.w5.maximum);
        }
        return null;
    };
    HighDensityScatterSeries.prototype.sj = function (a, b) {
        if (this.c9 != null) {
            var c = this.getEffectiveViewport1(this.ct);
            this.w7 = !c.isEmpty;
        }
        this.rm(false);
    };
    HighDensityScatterSeries.prototype.sk = function (a, b) {
        this.rm(false);
    };
    HighDensityScatterSeries.prototype.kl = function (a) {
        if (!this.w8 || this._itemIndexes == null || this.c9 == null || this.dl == null || this._itemIndexes.length != (this.yc * this.yb)) {
            return null;
        }
        var b = this.c9.vl;
        var c = (a.x - b.left) / b.width;
        var d = (a.y - b.top) / b.height;
        var e = truncate(Math.round(this.wk.left + (this.wk.width * c)));
        var f = truncate(Math.round(this.wk.top + (this.wk.height * d)));
        var g = this.yl(e, f);
        if (g < 0 || g > this._itemIndexes.length - 1) {
            return null;
        }
        var h = this._itemIndexes[g] - 1;
        if (h < 0 || h > this.dl.count) {
            return null;
        }
        return this.dl.item(h);
    };
    HighDensityScatterSeries.prototype.yl = function (a, b) {
        var c = (this.yc * b) + a;
        if (c > 0 && c < this._itemIndexes.length && this._itemIndexes[c] > 0) {
            return c;
        }
        var d = 1;
        c = (this.yc * (b - d)) + a;
        if (c > 0 && c < this._itemIndexes.length && this._itemIndexes[c] > 0) {
            return c;
        }
        c = (this.yc * (b + d)) + a;
        if (c > 0 && c < this._itemIndexes.length && this._itemIndexes[c] > 0) {
            return c;
        }
        c = (this.yc * (b)) + a - 1;
        if (c > 0 && c < this._itemIndexes.length && this._itemIndexes[c] > 0) {
            return c;
        }
        c = (this.yc * (b)) + a + 1;
        if (c > 0 && c < this._itemIndexes.length && this._itemIndexes[c] > 0) {
            return c;
        }
        c = (this.yc * (b - d)) + a - 1;
        if (c > 0 && c < this._itemIndexes.length && this._itemIndexes[c] > 0) {
            return c;
        }
        c = (this.yc * (b + d)) + a + 1;
        if (c > 0 && c < this._itemIndexes.length && this._itemIndexes[c] > 0) {
            return c;
        }
        c = (this.yc * (b - d)) + a + 1;
        if (c > 0 && c < this._itemIndexes.length && this._itemIndexes[c] > 0) {
            return c;
        }
        c = (this.yc * (b + d)) + a - 1;
        if (c > 0 && c < this._itemIndexes.length && this._itemIndexes[c] > 0) {
            return c;
        }
        return 0;
    };
    HighDensityScatterSeries.prototype.zn = function (a, b, c) {
        this.wr = a;
        this.yc = b;
        this.yb = c;
    };
    HighDensityScatterSeries.prototype.get_g5 = function () {
        return true;
    };
    HighDensityScatterSeries.prototype.set_g5 = function (a) {
        _super.prototype.set_g5.call(this, a);
    };
    HighDensityScatterSeries.prototype.o2 = function (a, b) {
        _super.prototype.o2.call(this, a, b);
        this.wt.ca();
        if (this.cs != null) {
            this.cs.ca();
        }
        this.qg();
    };
    HighDensityScatterSeries.prototype.ro = function (a, b) {
        _super.prototype.ro.call(this, a, b);
        if (!this.gy) {
            this.ct.a4(b);
            return;
        }
        this.ct.a4(b);
        if (this.d3(this.cs)) {
            return;
        }
        var c = typeCast(HighDensityScatterSeriesView.$, this.cs);
        var d = new ScatterFrame();
        this.ze(false, c);
        this.gy = false;
    };
    HighDensityScatterSeries.prototype.rl = function (a, b, c, d, e) {
        _super.prototype.rl.call(this, a, b, c, d, e);
        var f = this.a9.a$j.item(d);
        var g = f;
        f.a3(c);
        if (this.d3(g)) {
            return;
        }
        if (this.w1 == null) {
            this.w1 = new ScatterFrame();
        }
        this.ze(false, f);
    };
    HighDensityScatterSeries.prototype.oz = function () {
        _super.prototype.oz.call(this);
        this.ww = null;
        this.wy = null;
    };
    HighDensityScatterSeries.$t = markType(HighDensityScatterSeries, 'HighDensityScatterSeries', Series.$);
    HighDensityScatterSeries.$$p = markDep(DependencyProperty, PropertyMetadata, HighDensityScatterSeries, 'raisePropertyChanged', ['HeatMaximumColor:z4:zp', [Color.$, Defaults.ap], 'HeatMaximum:x6:zq', [1, 50], 'HeatMinimumColor:z5:zr', [Color.$, Defaults.aq], 'HeatMinimum:x7:zs', [1, 0], 'PointExtent:yj:zt', [1, 1], 'ProgressiveLoad:xb:zu', [0, true], 'UseBruteForce:xc:zv', [0, false], 'XAxis:ww:zw', [NumericXAxis.$, null], 'XMemberAsLegendLabel:yv:zx', [2, null], 'XMemberAsLegendUnit:yx:zy', [2, null], 'XMemberPath:yz:zz', [2, null], 'YAxis:wy:z0', [NumericYAxis.$, null], 'YMemberAsLegendLabel:y3:z1', [2, null], 'YMemberAsLegendUnit:y5:z2', [2, null], 'YMemberPath:y7:z3', [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.z5 = Defaults.aq;
            this.b2.z4 = Defaults.ap;
            this.b2.u8 = Defaults.al;
            this.b2.vo = Defaults.ak;
        }
    };
    HighDensityScatterSeriesView.prototype.cd = function () {
        this.b2.zn(this.b0, this.b8, this.b7);
    };
    HighDensityScatterSeriesView.prototype.b9 = function () {
        if (this.b5 == null) {
            this.b5 = this.e.jx.createElement("canvas");
            var a = this.e.jx.get2DCanvasContext(this.b5);
            this.b3 = new RenderingContext(new CanvasViewRenderer(), a);
        }
        var b;
        if (this.p) {
            b = this.bx;
        }
        else {
            b = this.e.c9.vq();
        }
        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.zn(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.jx != null) {
            this.e.jx.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.f6) {
                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.bb.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.bb.exportSeriesPixelsData(a, b, this.b8, this.b7);
    };
    HighDensityScatterSeriesView.$t = markType(HighDensityScatterSeriesView, 'HighDensityScatterSeriesView', SeriesView.$);
    return HighDensityScatterSeriesView;
}(SeriesView));
export { HighDensityScatterSeriesView };
