/*
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 { TestRandomness } from "igniteui-angular-core";
import { DefaultRandomnessSource } from "igniteui-angular-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-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.xl = null;
        _this.xn = null;
        _this.yx = 0;
        _this.xq = false;
        _this.yc = Defaults.bf.o;
        _this.yb = Defaults.bf.n;
        _this.ya = Defaults.bf.m;
        _this.x9 = Defaults.bf.l;
        _this.x8 = Defaults.be.o;
        _this.x7 = Defaults.be.n;
        _this.x6 = Defaults.be.m;
        _this.x5 = Defaults.be.l;
        _this.xd = null;
        _this.xi = null;
        _this.xj = null;
        _this.xe = null;
        _this.xg = null;
        _this.xs = false;
        _this.yy = 0;
        _this.y0 = 0;
        _this.yu = 0;
        _this.yt = 0;
        _this.progressiveLoadStatusChanged = null;
        _this.xx = null;
        _this.x3 = 0;
        _this.x2 = 0;
        _this.x4 = 0;
        _this.yj = 0;
        _this.yh = 0;
        _this.yi = 0;
        _this.yk = 0;
        _this.ym = 0;
        _this.yo = 0;
        _this.yn = 0;
        _this.yl = 0;
        _this.xz = 0;
        _this.x0 = 0;
        _this.x1 = 0;
        _this.xy = 0;
        _this.yw = 0;
        _this.yv = 0;
        _this.xa = null;
        _this.yz = 0;
        _this.xr = false;
        _this._itemIndexes = null;
        _this.xb = null;
        _this.w8 = null;
        _this.xk = null;
        _this.ab = HighDensityScatterSeries.$;
        _this.f9 = false;
        return _this;
    }
    HighDensityScatterSeries.prototype.bk = function () {
        return new HighDensityScatterSeries();
    };
    HighDensityScatterSeries.prototype.get_fp = function () {
        return true;
    };
    HighDensityScatterSeries.prototype.jn = function () {
        if (!isNaN_(this.jm)) {
            return _super.prototype.jn.call(this);
        }
        return Defaults.ad;
    };
    HighDensityScatterSeries.prototype.get_fx = function () {
        return true;
    };
    Object.defineProperty(HighDensityScatterSeries.prototype, "xm", {
        get: function () {
            return this.xl;
        },
        set: function (a) {
            if (this.xl != a) {
                var b = this.xm;
                this.xl = a;
                this.raisePropertyChanged("XColumn", b, this.xm);
            }
        },
        enumerable: false,
        configurable: true
    });
    HighDensityScatterSeries.prototype.getDataLegendSeriesContextAt = function (a, b) {
        var c = { $type: Point_$type, x: a, y: b };
        var d = this.kr(c);
        var e = d == null ? NaN : this.iz(d, "XMemberPath");
        var f = d == null ? NaN : this.iz(d, "YMemberPath");
        var g = new DataLegendSeriesValueInfo();
        g.l = e;
        g.a = 13;
        g.q = "X";
        g.r = this.zj != null ? this.zj : "X";
        g.s = this.zf != null ? this.zf : "X:";
        g.t = this.zh != null ? this.zh : "";
        var h = new DataLegendSeriesValueInfo();
        h.l = f;
        h.a = 14;
        h.q = "Y";
        h.r = this.zr != null ? this.zr : "Y";
        h.s = this.zn != null ? this.zn : "Y:";
        h.t = this.zp != null ? this.zp : "";
        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.mh();
        return i;
    };
    HighDensityScatterSeries.prototype.ku = function (a, b) {
        var c = this.ni(b);
        if (c == HighDensityScatterSeries.$$p[10]) {
            return this.kv(a, b, this.zj);
        }
        if (c == HighDensityScatterSeries.$$p[14]) {
            return this.kv(a, b, this.zr);
        }
        return _super.prototype.ku.call(this, a, b);
    };
    HighDensityScatterSeries.prototype.mi = function (a) {
        var b = this.ni(a);
        if (b == HighDensityScatterSeries.$$p[10]) {
            return this.zj;
        }
        if (b == HighDensityScatterSeries.$$p[14]) {
            return this.zr;
        }
        return _super.prototype.mi.call(this, a);
    };
    Object.defineProperty(HighDensityScatterSeries.prototype, "xo", {
        get: function () {
            return this.xn;
        },
        set: function (a) {
            if (this.xn != a) {
                var b = this.xo;
                this.xn = a;
                this.raisePropertyChanged("YColumn", b, this.xo);
            }
        },
        enumerable: false,
        configurable: true
    });
    HighDensityScatterSeries.prototype.z6 = function () {
        if (this.xd == null) {
            return;
        }
        this.xd.t();
        var a = this.xd;
        a.progressiveThunkCompleted = delegateRemove(a.progressiveThunkCompleted, runOn(this, this.zt));
        this.xd = null;
    };
    HighDensityScatterSeries.prototype.rg = function (a, b, c, d) {
        _super.prototype.rg.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.ql();
                break;
            case "SeriesViewer":
                if (this.dc != null) {
                    var e = this.getEffectiveViewport1(this.cw);
                    this.xr = !e.isEmpty;
                }
                break;
            case "FastItemsSource":
                this.z6();
                if (typeCast(IFastItemsSource_$type, c) != null) {
                    c.deregisterColumn(this.xm);
                    c.deregisterColumn(this.xo);
                    this.xm = null;
                    this.xo = null;
                }
                if (typeCast(IFastItemsSource_$type, d) != null) {
                    this.xm = this.dl(this.zj);
                    this.xo = this.dl(this.zr);
                }
                if ((this.xh != null && !this.xh.d2()) || (this.xf != null && !this.xf.d2())) {
                    this.ry(this.gh && c != null);
                }
                this.qs();
                break;
            case HighDensityScatterSeries.$$p[7]:
                var f = this.xe;
                this.xe = this.xf;
                this.z6();
                if (f != null) {
                    f.rangeChanged = delegateRemove(f.rangeChanged, runOn(this, this.zw));
                }
                if (this.xe != null) {
                    var g = this.xe;
                    g.rangeChanged = delegateCombine(g.rangeChanged, runOn(this, this.zw));
                }
                if (c != null) {
                    c.cq(this);
                }
                if (d != null) {
                    d.du(this);
                }
                if ((this.xf != null && !this.xf.d2()) || (d == null && c != null)) {
                    this.ry(false);
                }
                break;
            case HighDensityScatterSeries.$$p[11]:
                var h = this.xg;
                this.xg = this.xh;
                this.z6();
                if (h != null) {
                    h.rangeChanged = delegateRemove(h.rangeChanged, runOn(this, this.zw));
                }
                if (this.xg != null) {
                    var i = this.xg;
                    i.rangeChanged = delegateCombine(i.rangeChanged, runOn(this, this.zw));
                }
                if (c != null) {
                    c.cq(this);
                }
                if (d != null) {
                    d.du(this);
                }
                if ((this.xh != null && !this.xh.d2()) || (d == null && c != null)) {
                    this.ry(false);
                }
                break;
            case "MouseOverEnabled":
                this.xs = this.f9;
                this.ry(false);
                break;
            case HighDensityScatterSeries.$$p[10]:
                if (this.dp != null) {
                    this.dp.deregisterColumn(this.xm);
                    this.xm = this.dl(this.zj);
                }
                break;
            case "XColumn":
                this.z6();
                if (this.xf != null && !this.xf.d2()) {
                    this.ry(false);
                }
                this.qs();
                break;
            case HighDensityScatterSeries.$$p[14]:
                if (this.dp != null) {
                    this.dp.deregisterColumn(this.xo);
                    this.xo = this.dl(this.zr);
                }
                break;
            case "YColumn":
                this.z6();
                if (this.xh != null && !this.xh.d2()) {
                    this.ry(false);
                }
                this.qs();
                break;
            case HighDensityScatterSeries.$$p[6]:
                this.z6();
                this.ry(false);
                this.qr();
                break;
            case HighDensityScatterSeries.$$p[3]:
                this.ry(false);
                this.qr();
                break;
            case HighDensityScatterSeries.$$p[1]:
                this.ry(false);
                this.qr();
                break;
            case HighDensityScatterSeries.$$p[0]:
            case HighDensityScatterSeries.$$p[2]:
                if (!this.xc.ch(this.aap, this.aao)) {
                    return;
                }
                this.z0();
                this.ry(false);
                this.qr();
                break;
            case HighDensityScatterSeries.$$p[4]:
                this.yx = Math.max(typeGetValue(d) - 1, 0);
                this.xq = this.yx > 0;
                this.ry(false);
                this.qr();
                break;
            case HighDensityScatterSeries.$$p[5]:
                this.ry(false);
                this.qr();
                break;
        }
    };
    HighDensityScatterSeries.prototype.z0 = function () {
        this.x9 = this.aap.l;
        this.yc = this.aap.o;
        this.yb = this.aap.n;
        this.ya = this.aap.m;
        this.x5 = this.aao.l;
        this.x8 = this.aao.o;
        this.x7 = this.aao.n;
        this.x6 = this.aao.m;
        this.v5 = BrushUtil.j(truncate(this.x9), truncate(this.yc), truncate(this.yb), truncate(this.ya));
        this.vp = BrushUtil.j(truncate(this.x5), truncate(this.x8), truncate(this.x7), truncate(this.x6));
    };
    HighDensityScatterSeries.prototype.xu = function (a) {
        if (typeCast(NumericYAxis.$, a) !== null) {
            return true;
        }
        return false;
    };
    HighDensityScatterSeries.prototype.xt = function (a) {
        if (typeCast(NumericXAxis.$, a) !== null) {
            return true;
        }
        return false;
    };
    HighDensityScatterSeries.prototype.zw = function (a, b) {
        this.z6();
        this.ry(false);
    };
    Object.defineProperty(HighDensityScatterSeries.prototype, "yg", {
        get: function () {
            return this.x8 - this.yc;
        },
        enumerable: false,
        configurable: true
    });
    Object.defineProperty(HighDensityScatterSeries.prototype, "yf", {
        get: function () {
            return this.x7 - this.yb;
        },
        enumerable: false,
        configurable: true
    });
    Object.defineProperty(HighDensityScatterSeries.prototype, "ye", {
        get: function () {
            return this.x6 - this.ya;
        },
        enumerable: false,
        configurable: true
    });
    Object.defineProperty(HighDensityScatterSeries.prototype, "yd", {
        get: function () {
            return this.x5 - this.x9;
        },
        enumerable: false,
        configurable: true
    });
    HighDensityScatterSeries.prototype.hf = function (a, b, c) {
        var d = _super.prototype.hf.call(this, a, b, c);
        if (this.xh == null || this.xf == null || this.xf.b0 == null || this.xh.b0 == null || this.xo == null || this.xm == null || this.xo.count < 1 || this.xm.count < 1 || this.xo.count != this.xm.count || this.xf.pr == this.xf.pq || this.xh.pr == this.xh.pq || this.w2.isEmpty) {
            d = false;
        }
        return d;
    };
    Object.defineProperty(HighDensityScatterSeries.prototype, "y4", {
        get: function () {
            return this.yy;
        },
        set: function (a) {
            var b = this.yy;
            this.yy = a;
            this.raisePropertyChanged("ProgressiveStatus", b, this.yy);
        },
        enumerable: false,
        configurable: true
    });
    HighDensityScatterSeries.prototype.rz = function (a) {
        _super.prototype.rz.call(this, a);
        this.zy(a, this.cw);
    };
    HighDensityScatterSeries.prototype.xp = function () {
        if (TestRandomness.instance.testRandomnessSource != null) {
            return TestRandomness.instance.testRandomnessSource;
        }
        return new DefaultRandomnessSource(0);
    };
    HighDensityScatterSeries.prototype.zy = function (a, b) {
        if (this.d7(b)) {
            return;
        }
        if (this.xd == null && !this.xw) {
            var c = new List$1(KDPointData.$, 2, this.xm.count);
            var d = this.xf;
            var e = this.xh;
            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.df);
            var i = new ScalerParams(1, f, g, e.df);
            var j_1;
            var k_1;
            var _loop_1 = function (l) {
                j_1 = d.ft(this_1.xm.item(l), h);
                k_1 = e.ft(this_1.xo.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.xm.count; l++) {
                _loop_1(l);
            }
            if (this.xv) {
                this.yt = 1;
                this.yu = truncate(logBase(c.count, 2)) + 3;
                this.y4 = truncate(((this.yt / this.yu) * 100));
                if (this.progressiveLoadStatusChanged != null) {
                    this.progressiveLoadStatusChanged(this, new ProgressiveLoadStatusEventArgs(this.y4));
                }
                this.xd = KDTree2D.b(c.toArray(), 1, this.xp());
                var m = this.xd;
                m.progressiveThunkCompleted = delegateCombine(m.progressiveThunkCompleted, runOn(this, this.zt));
                if (!this.xd.h(this.j3)) {
                    var n = this.xd;
                    n.progressiveThunkCompleted = delegateRemove(n.progressiveThunkCompleted, runOn(this, this.zt));
                }
                this.qr();
            }
            else {
                var o = dateNow();
                this.xd = new KDTree2D(0, c.toArray(), 1, this.xp());
                var p = dateNow();
            }
        }
        if (this.xv && !this.xw) {
            this.zz(b);
        }
        else {
            this.z1(b);
        }
    };
    HighDensityScatterSeries.prototype.ph = function (a, b, c, d) {
        _super.prototype.ph.call(this, a, b, c, d);
        this.z6();
        var e = false;
        if (this.xf != null && !this.xf.d2()) {
            e = true;
        }
        if (this.xh != null && !this.xh.d2()) {
            e = true;
        }
        if (e) {
            this.ry(false);
        }
        this.qs();
    };
    HighDensityScatterSeries.prototype.zv = function (a) {
        var b = a;
        var c = this.yw * this.yv;
        if (this.xs) {
            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.z1 = function (a) {
        var b;
        var c;
        var d = null;
        if (a.t) {
            d = this._itemIndexes;
        }
        var e = a.getViewInfo(c, b);
        c = e.p0;
        b = e.p1;
        var f = a;
        var g = this.getEffectiveViewport1(a);
        this.xi = new ScalerParams(0, b, c, this.xe.df, g);
        this.xj = new ScalerParams(0, b, c, this.xg.df, g);
        this.zu(a);
        this.zv(a);
        var h = this.yw * this.yv;
        if (this.xb == null || this.xb.length != h) {
            this.xb = new Array(h);
            this.w8 = new Array(h);
        }
        var i = this.xb.length;
        var j = this.xb;
        var k = this.w8;
        for (var l = 0; l < i; l++) {
            j[l] = 0;
            k[l] = 0;
        }
        this.y0 = truncate(Math.round(this.ie));
        this.xa = f.ce();
        var m = this.xa.length;
        var n = this.xa;
        for (var o = 0; o < m; o++) {
            n[o] = 0;
        }
        var p = this.yr;
        var q = this.yq;
        if (isNaN_(p) || isInfinity(p)) {
            p = 0;
        }
        if (isNaN_(q) || isInfinity(q)) {
            q = 50;
        }
        this.x3 = Math.min(p, q);
        this.x2 = Math.max(p, q);
        if (this.x3 < 0) {
            this.x3 = 0;
        }
        if (this.x2 < 0) {
            this.x2 = 0;
        }
        this.x4 = this.x2 - this.x3;
        if (this.xw) {
            this.zx(a);
        }
        else {
            this.z8(a);
        }
        f.cp();
        if (a.t) {
            this._itemIndexes = d;
            this.xc.cq();
        }
    };
    HighDensityScatterSeries.prototype.zz = function (a) {
        if (this.xd == null) {
            return;
        }
        this.z1(a);
    };
    HighDensityScatterSeries.prototype.zt = function (a, b) {
        var _this = this;
        this.xc.co(function () {
            if (_this.yt < _this.yu - 1) {
                _this.yt++;
            }
            _this.y4 = truncate(((_this.yt / _this.yu) * 100));
            if (_this.progressiveLoadStatusChanged != null) {
                _this.progressiveLoadStatusChanged(_this, new ProgressiveLoadStatusEventArgs(_this.y4));
            }
            _this.zz(_this.cw);
            _this.qr();
            if (_this.xd != null) {
                if (!_this.xd.h(_this.j3)) {
                    var c = _this.xd;
                    c.progressiveThunkCompleted = delegateRemove(c.progressiveThunkCompleted, runOn(_this, _this.zt));
                    _this.y4 = 100;
                    if (_this.progressiveLoadStatusChanged != null) {
                        _this.progressiveLoadStatusChanged(_this, new ProgressiveLoadStatusEventArgs(_this.y4));
                    }
                }
            }
        });
    };
    HighDensityScatterSeries.prototype.zx = function (a) {
        var b = arrayShallowClone(this.xm.asArray());
        this.xf.j6(boxArray$1(b), 0, b.length, this.xi);
        var c = arrayShallowClone(this.xo.asArray());
        this.yz = 0;
        var d = this.yx;
        var e = this.xq;
        var f = this.xb.length;
        this.xh.j6(boxArray$1(c), 0, c.length, this.xj);
        var g = 255 << 24 | truncate(this.yc) << 16 | truncate(this.yb) << 8 | truncate(this.ya);
        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.yw || j < 0 || j >= this.yv) {
                continue;
            }
            if (e) {
                var k = i - d;
                var l = i + d;
                l = l > (this.yw - 1) ? (this.yw - 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.yw) + o;
                        if (q < 0 || q > f - 1) {
                            continue;
                        }
                        this.xb[q] = this.xb[q] + 1;
                        this.w8[q] = 1;
                        this.yz++;
                        if (this.xs) {
                            this._itemIndexes[q] = h + 1;
                        }
                    }
                }
            }
            else {
                var r = (j * this.yw) + i;
                this.xb[r] = this.xb[r] + 1;
                this.w8[r] = 1;
                this.yz++;
                if (this.xs) {
                    this._itemIndexes[r] = h + 1;
                }
            }
        }
        this.z2();
    };
    HighDensityScatterSeries.prototype.z8 = function (a) {
        var b;
        var c;
        var d = a.getViewInfo(b, c);
        b = d.p0;
        c = d.p1;
        if (this.xd == null) {
            return;
        }
        if (this.xx == null) {
            this.xx = new List$1(KDTreeNode2D.$, 2, truncate(Math.round(b.width * b.height)));
        }
        else {
            this.xx.clear();
        }
        var e = c.left;
        var f = c.right;
        var g = c.top;
        var h = c.bottom;
        this.yn = c.top;
        this.yl = c.height;
        this.ym = c.left;
        this.yo = c.width;
        this.yj = b.top;
        this.yh = b.height;
        this.yi = b.left;
        this.yk = b.width;
        var i = this.getEffectiveViewport1(a);
        this.xz = (i.left - this.yi) / this.yk;
        this.x0 = (i.top - this.yj) / this.yh;
        var j = (i.right - this.yi) / this.yk;
        this.x1 = j - this.xz;
        var k = (i.bottom - this.yj) / this.yh;
        this.xy = k - this.x0;
        if (this.xr) {
            e = (e - this.xz) / this.x1;
            f = (f - this.xz) / this.x1;
            g = (g - this.x0) / this.xy;
            h = (h - this.x0) / this.xy;
        }
        var l = this.ie / b.width * c.width;
        var m = this.ie / 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.xd.u(this.xx, o, 0, 1, 0, 1);
        var p;
        this.yz = 0;
        for (var q = 0; q < this.xx.count; q++) {
            p = this.xx._inner[q];
            this.z3(p);
        }
        this.z2();
    };
    HighDensityScatterSeries.prototype.z3 = 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.z5(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.z5(e, d, false, a.e);
            }
        }
        if (a.e != null) {
            a.e.a = false;
        }
    };
    HighDensityScatterSeries.prototype.ge = function (a) {
        var b = this.dc != null ? this.dc.xm : Rect.empty;
        var c = this.dc != null ? this.dc.x4 : Rect.empty;
        var d = new Rect(0, 0, 0, 1, 1);
        var e = this.wv(this.cw);
        var f = new ScalerParams(0, d, d, this.xf.df, e);
        var g = new ScalerParams(0, d, d, this.xh.df, e);
        var h = !b.isEmpty && !c.isEmpty && this.dp != null ? this.dp.indexOf(a) : -1;
        var i = this.xf != null && this.xm != null && h < this.xm.count ? this.xf.ft(this.xm.item(h), f) : NaN;
        var j = this.xh != null && this.xo != null && h < this.xo.count ? this.xh.ft(this.xo.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.c4 != null) {
            this.c4.au(this.dc, b, true);
        }
        return h >= 0;
    };
    HighDensityScatterSeries.prototype.z5 = function (a, b, c, d) {
        var e = this.y2(b);
        var f = a.c;
        var g = this.yx;
        if (c) {
            var h = d.d;
            var i = d.b;
            var j = d.e;
            var k = d.c;
            if (this.xr) {
                h = this.xz + this.x1 * h;
                i = this.xz + this.x1 * i;
                j = this.x0 + this.xy * j;
                k = this.x0 + this.xy * k;
            }
            var l = truncate((this.yi + this.yk * (h - this.ym) / this.yo));
            var m = truncate((this.yi + this.yk * (i - this.ym) / this.yo));
            var n = truncate((this.yj + this.yh * (j - this.yn) / this.yl));
            var o = truncate((this.yj + this.yh * (k - this.yn) / this.yl));
            l = truncate(Math.floor(l));
            m = truncate(Math.floor(m));
            n = truncate(Math.floor(n));
            o = truncate(Math.floor(o));
            if (this.xq) {
                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.z4(f, s, t, q, r);
                }
            }
        }
        else {
            var u = a.a;
            var v = a.b;
            if (this.xr) {
                u = this.xz + this.x1 * u;
                v = this.x0 + this.xy * v;
            }
            var w = truncate((this.yi + this.yk * (u - this.ym) / this.yo));
            var x = truncate((this.yj + this.yh * (v - this.yn) / this.yl));
            w = truncate(Math.floor(w));
            x = truncate(Math.floor(x));
            if (this.xq) {
                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.z4(f, af, ag, ad, ae);
                    }
                }
            }
            else {
                this.z4(f, w, x, b, 1);
            }
        }
    };
    HighDensityScatterSeries.prototype.y1 = function (a, b) {
        return truncate((Math.floor(255 * b))) << 24 | truncate(Math.floor(b * (this.yc + a * this.yg))) << 16 | truncate(Math.floor(b * (this.yb + a * this.yf))) << 8 | truncate(Math.floor(b * (this.ya + a * this.ye)));
    };
    HighDensityScatterSeries.prototype.y2 = function (a) {
        return 255 << 24 | truncate(Math.floor((this.yc + a * this.yg))) << 16 | truncate(Math.floor((this.yb + a * this.yf))) << 8 | truncate(Math.floor((this.ya + a * this.ye)));
    };
    HighDensityScatterSeries.prototype.yp = function (a) {
        return (a >> 24 & 255) / 255;
    };
    HighDensityScatterSeries.prototype.z4 = function (a, b, c, d, e) {
        if (b < 0 || b >= this.yw || c < 0 || c >= this.yv) {
            return;
        }
        var f = (c * this.yw) + b;
        this.xb[f] = this.xb[f] + d;
        this.w8[f] = this.w8[f] + e;
        if (this.xs) {
            this._itemIndexes[f] = a + 1;
        }
        this.yz += truncate(d);
    };
    HighDensityScatterSeries.prototype.z2 = function () {
        var a = 0;
        var b = 0;
        var c = this.x4;
        var d = this.x3;
        var e = this.x2;
        var f = this.xb.length;
        var g = this.xb;
        var h = this.w8;
        var i = this.xa;
        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.y1(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.zu = function (a) {
        var b = a;
        b.cm();
    };
    HighDensityScatterSeries.prototype.ct = function () {
        return new HighDensityScatterSeriesView(this);
    };
    HighDensityScatterSeries.prototype.q7 = function (a) {
        _super.prototype.q7.call(this, a);
        this.xc = a;
    };
    HighDensityScatterSeries.prototype.ay = function (a) {
        if (a != null && a == this.xf && this.xm != null) {
            return new AxisRange(this.xm.minimum, this.xm.maximum);
        }
        if (a != null && a == this.xh && this.xo != null) {
            return new AxisRange(this.xo.minimum, this.xo.maximum);
        }
        return null;
    };
    HighDensityScatterSeries.prototype.sy = function (a, b) {
        if (this.dc != null) {
            var c = this.getEffectiveViewport1(this.cw);
            this.xr = !c.isEmpty;
        }
        this.ry(false);
    };
    HighDensityScatterSeries.prototype.sz = function (a, b) {
        this.ry(false);
    };
    HighDensityScatterSeries.prototype.kr = function (a) {
        if (!this.xs || this._itemIndexes == null || this.dc == null || this.dp == null || this._itemIndexes.length != (this.yw * this.yv)) {
            return null;
        }
        var b = this.dc.xm;
        var c = (a.x - b.left) / b.width;
        var d = (a.y - b.top) / b.height;
        var e = truncate(Math.round(this.w2.left + (this.w2.width * c)));
        var f = truncate(Math.round(this.w2.top + (this.w2.height * d)));
        var g = this.y5(e, f);
        if (g < 0 || g > this._itemIndexes.length - 1) {
            return null;
        }
        var h = this._itemIndexes[g] - 1;
        if (h < 0 || h > this.dp.count) {
            return null;
        }
        return this.dp.item(h);
    };
    HighDensityScatterSeries.prototype.y5 = function (a, b) {
        var c = (this.yw * b) + a;
        if (c > 0 && c < this._itemIndexes.length && this._itemIndexes[c] > 0) {
            return c;
        }
        var d = 1;
        c = (this.yw * (b - d)) + a;
        if (c > 0 && c < this._itemIndexes.length && this._itemIndexes[c] > 0) {
            return c;
        }
        c = (this.yw * (b + d)) + a;
        if (c > 0 && c < this._itemIndexes.length && this._itemIndexes[c] > 0) {
            return c;
        }
        c = (this.yw * (b)) + a - 1;
        if (c > 0 && c < this._itemIndexes.length && this._itemIndexes[c] > 0) {
            return c;
        }
        c = (this.yw * (b)) + a + 1;
        if (c > 0 && c < this._itemIndexes.length && this._itemIndexes[c] > 0) {
            return c;
        }
        c = (this.yw * (b - d)) + a - 1;
        if (c > 0 && c < this._itemIndexes.length && this._itemIndexes[c] > 0) {
            return c;
        }
        c = (this.yw * (b + d)) + a + 1;
        if (c > 0 && c < this._itemIndexes.length && this._itemIndexes[c] > 0) {
            return c;
        }
        c = (this.yw * (b - d)) + a + 1;
        if (c > 0 && c < this._itemIndexes.length && this._itemIndexes[c] > 0) {
            return c;
        }
        c = (this.yw * (b + d)) + a - 1;
        if (c > 0 && c < this._itemIndexes.length && this._itemIndexes[c] > 0) {
            return c;
        }
        return 0;
    };
    HighDensityScatterSeries.prototype.z7 = function (a, b, c) {
        this.xa = a;
        this.yw = b;
        this.yv = c;
    };
    HighDensityScatterSeries.prototype.get_g8 = function () {
        return true;
    };
    HighDensityScatterSeries.prototype.set_g8 = function (a) {
        _super.prototype.set_g8.call(this, a);
    };
    HighDensityScatterSeries.prototype.pb = function (a, b) {
        _super.prototype.pb.call(this, a, b);
        this.xc.cn();
        if (this.cv != null) {
            this.cv.cn();
        }
        this.qr();
    };
    HighDensityScatterSeries.prototype.r0 = function (a, b) {
        _super.prototype.r0.call(this, a, b);
        if (!this.g1) {
            this.cw.be(b);
            return;
        }
        this.cw.be(b);
        if (this.d7(this.cv)) {
            return;
        }
        var c = typeCast(HighDensityScatterSeriesView.$, this.cv);
        var d = new ScatterFrame();
        this.zy(false, c);
        this.g1 = false;
    };
    HighDensityScatterSeries.prototype.rx = function (a, b, c, d, e) {
        _super.prototype.rx.call(this, a, b, c, d, e);
        var f = this.ba.a$j.item(d);
        var g = f;
        f.bd(c);
        if (this.d7(g)) {
            return;
        }
        if (this.xk == null) {
            this.xk = new ScatterFrame();
        }
        this.zy(false, f);
    };
    HighDensityScatterSeries.prototype.o8 = function () {
        _super.prototype.o8.call(this);
        this.xf = null;
        this.xh = null;
    };
    HighDensityScatterSeries.$t = markType(HighDensityScatterSeries, 'HighDensityScatterSeries', Series.$);
    HighDensityScatterSeries.$$p = markDep(DependencyProperty, PropertyMetadata, HighDensityScatterSeries, 'raisePropertyChanged', ['HeatMaximumColor:aao:z9', [Color.$, Defaults.be], 'HeatMaximum:yq:aaa', [1, 50], 'HeatMinimumColor:aap:aab', [Color.$, Defaults.bf], 'HeatMinimum:yr:aac', [1, 0], 'PointExtent:y3:aad', [1, 1], 'ProgressiveLoad:xv:aae', [0, true], 'UseBruteForce:xw:aaf', [0, false], 'XAxis:xf:aag', [NumericXAxis.$, null], 'XMemberAsLegendLabel:zf:aah', [2, null], 'XMemberAsLegendUnit:zh:aai', [2, null], 'XMemberPath:zj:aaj', [2, null], 'YAxis:xh:aak', [NumericYAxis.$, null], 'YMemberAsLegendLabel:zn:aal', [2, null], 'YMemberAsLegendUnit:zp:aam', [2, null], 'YMemberPath:zr:aan', [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.cf = null;
        _this.cd = null;
        _this.cl = 0;
        _this.ck = 0;
        _this.ci = null;
        _this.cj = null;
        _this.cg = null;
        _this.cf = a;
        return _this;
    }
    HighDensityScatterSeriesView.prototype.a4 = function () {
        _super.prototype.a4.call(this);
        if (!this.t) {
            this.cf.aap = Defaults.bf;
            this.cf.aao = Defaults.be;
            this.cf.vp = Defaults.ba;
            this.cf.v5 = Defaults.a9;
        }
    };
    HighDensityScatterSeriesView.prototype.cq = function () {
        this.cf.z7(this.cd, this.cl, this.ck);
    };
    HighDensityScatterSeriesView.prototype.cm = function () {
        if (this.ci == null) {
            this.ci = this.f.j3.createElement("canvas");
            var a = this.f.j3.get2DCanvasContext(this.ci);
            this.cg = new RenderingContext(new CanvasViewRenderer(), a);
        }
        var b;
        if (this.s) {
            b = this.b9;
        }
        else {
            b = this.f.dc.xs();
        }
        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.cl;
        var h = this.ck;
        this.cl = e;
        this.ck = f;
        if (g != this.cl || h != this.ck || this.cd == null) {
            this.ci.setAttribute("width", e.toString());
            this.ci.setAttribute("height", f.toString());
            this.cj = this.cg.h().getImageData(0, 0, e, f);
            var imageDataArray_ = this.cj.data;
            this.cd = imageDataArray_;
        }
        this.cf.z7(this.cd, this.cl, this.ck);
    };
    HighDensityScatterSeriesView.prototype.ce = function () {
        return this.cd;
    };
    HighDensityScatterSeriesView.prototype.cp = function () {
        var a = truncate(Math.round(this.b9.left));
        var b = truncate(Math.round(this.b9.left));
        var c = truncate(Math.round(this.b9.width));
        var d = truncate(Math.round(this.b9.height));
        this.cg.h().putImageData(this.cj, 0, 0);
        this.a2();
    };
    HighDensityScatterSeriesView.prototype.co = function (a) {
        if (this.f.j3 != null) {
            this.f.j3.setTimeout(a, 0);
        }
        else {
            window.setTimeout(a, 0);
        }
    };
    HighDensityScatterSeriesView.prototype.bj = function (a, b) {
        _super.prototype.bj.call(this, a, b);
        if (b) {
            if (!this.cf.f9) {
                return;
            }
            var c = new Rectangle();
            c.n = this.b9.left;
            c.o = this.b9.top;
            c.width = this.b9.width;
            c.height = this.b9.height;
            c._fill = this.b3();
            a.w(c);
            return;
        }
        if (this.ci == null) {
            return;
        }
        var d = truncate(Math.round(this.b9.left));
        var e = truncate(Math.round(this.b9.top));
        var f = truncate(Math.round(this.b9.width));
        var g = truncate(Math.round(this.b9.height));
        this.m.o(this.ci.getNativeElement(), this.f._opacity, d, e, f, g, d, e, f, g);
    };
    HighDensityScatterSeriesView.prototype.ch = function (a, b) {
        return Color.e(toNullable(Color.$, a), toNullable(Color.$, null)) && Color.e(toNullable(Color.$, b), toNullable(Color.$, null));
    };
    HighDensityScatterSeriesView.prototype.cn = function () {
        if (this.cd != null) {
            for (var a = 0; a < this.cd.length; a++) {
                this.cd[a] = 0;
            }
            this.cp();
        }
    };
    HighDensityScatterSeriesView.prototype.ax = function (a) {
        _super.prototype.ax.call(this, a);
        if (this.cd == null) {
            this.f.bc.exportSeriesPixelsData(a, null, this.cl, this.ck);
            return;
        }
        var b = new Array(intDivide(this.cd.length, 4));
        var c;
        for (var d = 0; d < intDivide(this.cd.length, 4); d++) {
            c = d * 4;
            b[d] = this.cd[c + 3] << 24 | this.cd[c] << 16 | this.cd[c + 1] << 8 | this.cd[c + 2];
        }
        this.f.bc.exportSeriesPixelsData(a, b, this.cl, this.ck);
    };
    HighDensityScatterSeriesView.$t = markType(HighDensityScatterSeriesView, 'HighDensityScatterSeriesView', SeriesView.$);
    return HighDensityScatterSeriesView;
}(SeriesView));
export { HighDensityScatterSeriesView };
