/*
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.xb = null;
        _this.xd = null;
        _this.yn = 0;
        _this.xg = false;
        _this.x2 = Defaults.aq.o;
        _this.x1 = Defaults.aq.n;
        _this.x0 = Defaults.aq.m;
        _this.xz = Defaults.aq.l;
        _this.xy = Defaults.ap.o;
        _this.xx = Defaults.ap.n;
        _this.xw = Defaults.ap.m;
        _this.xv = Defaults.ap.l;
        _this.w3 = null;
        _this.w8 = null;
        _this.w9 = null;
        _this.w4 = null;
        _this.w6 = null;
        _this.xi = false;
        _this.yo = 0;
        _this.yq = 0;
        _this.yk = 0;
        _this.yj = 0;
        _this.progressiveLoadStatusChanged = null;
        _this.xn = null;
        _this.xt = 0;
        _this.xs = 0;
        _this.xu = 0;
        _this.x9 = 0;
        _this.x7 = 0;
        _this.x8 = 0;
        _this.ya = 0;
        _this.yc = 0;
        _this.ye = 0;
        _this.yd = 0;
        _this.yb = 0;
        _this.xp = 0;
        _this.xq = 0;
        _this.xr = 0;
        _this.xo = 0;
        _this.ym = 0;
        _this.yl = 0;
        _this.w0 = null;
        _this.yp = 0;
        _this.xh = false;
        _this._itemIndexes = null;
        _this.w1 = null;
        _this.wy = null;
        _this.xa = 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, "xc", {
        get: function () {
            return this.xb;
        },
        set: function (a) {
            if (this.xb != a) {
                var b = this.xc;
                this.xb = a;
                this.raisePropertyChanged("XColumn", b, this.xc);
            }
        },
        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.y9 != null ? this.y9 : "X";
        g.s = this.y5 != null ? this.y5 : "X:";
        g.t = this.y7 != null ? this.y7 : "";
        var h = new DataLegendSeriesValueInfo();
        h.l = f;
        h.a = 14;
        h.q = "Y";
        h.r = this.zh != null ? this.zh : "Y";
        h.s = this.zd != null ? this.zd : "Y:";
        h.t = this.zf != null ? this.zf : "";
        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.y9);
        }
        if (c == HighDensityScatterSeries.$$p[14]) {
            return this.kr(a, b, this.zh);
        }
        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.y9;
        }
        if (b == HighDensityScatterSeries.$$p[14]) {
            return this.zh;
        }
        return _super.prototype.md.call(this, a);
    };
    Object.defineProperty(HighDensityScatterSeries.prototype, "xe", {
        get: function () {
            return this.xd;
        },
        set: function (a) {
            if (this.xd != a) {
                var b = this.xe;
                this.xd = a;
                this.raisePropertyChanged("YColumn", b, this.xe);
            }
        },
        enumerable: false,
        configurable: true
    });
    HighDensityScatterSeries.prototype.zw = function () {
        if (this.w3 == null) {
            return;
        }
        this.w3.t();
        var a = this.w3;
        a.progressiveThunkCompleted = delegateRemove(a.progressiveThunkCompleted, runOn(this, this.zj));
        this.w3 = null;
    };
    HighDensityScatterSeries.prototype.q9 = function (a, b, c, d) {
        _super.prototype.q9.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.qf();
                break;
            case "SeriesViewer":
                if (this.db != null) {
                    var e = this.getEffectiveViewport1(this.cv);
                    this.xh = !e.isEmpty;
                }
                break;
            case "FastItemsSource":
                this.zw();
                if (typeCast(IFastItemsSource_$type, c) != null) {
                    c.deregisterColumn(this.xc);
                    c.deregisterColumn(this.xe);
                    this.xc = null;
                    this.xe = null;
                }
                if (typeCast(IFastItemsSource_$type, d) != null) {
                    this.xc = this.dk(this.y9);
                    this.xe = this.dk(this.zh);
                }
                if ((this.w7 != null && !this.w7.c1()) || (this.w5 != null && !this.w5.c1())) {
                    this.rr(this.gg && c != null);
                }
                this.qm();
                break;
            case HighDensityScatterSeries.$$p[7]:
                var f = this.w4;
                this.w4 = this.w5;
                this.zw();
                if (f != null) {
                    f.rangeChanged = delegateRemove(f.rangeChanged, runOn(this, this.zm));
                }
                if (this.w4 != null) {
                    var g = this.w4;
                    g.rangeChanged = delegateCombine(g.rangeChanged, runOn(this, this.zm));
                }
                if (c != null) {
                    c.b0(this);
                }
                if (d != null) {
                    d.ct(this);
                }
                if ((this.w5 != null && !this.w5.c1()) || (d == null && c != null)) {
                    this.rr(false);
                }
                break;
            case HighDensityScatterSeries.$$p[11]:
                var h = this.w6;
                this.w6 = this.w7;
                this.zw();
                if (h != null) {
                    h.rangeChanged = delegateRemove(h.rangeChanged, runOn(this, this.zm));
                }
                if (this.w6 != null) {
                    var i = this.w6;
                    i.rangeChanged = delegateCombine(i.rangeChanged, runOn(this, this.zm));
                }
                if (c != null) {
                    c.b0(this);
                }
                if (d != null) {
                    d.ct(this);
                }
                if ((this.w7 != null && !this.w7.c1()) || (d == null && c != null)) {
                    this.rr(false);
                }
                break;
            case "MouseOverEnabled":
                this.xi = this.f8;
                this.rr(false);
                break;
            case HighDensityScatterSeries.$$p[10]:
                if (this.dn != null) {
                    this.dn.deregisterColumn(this.xc);
                    this.xc = this.dk(this.y9);
                }
                break;
            case "XColumn":
                this.zw();
                if (this.w5 != null && !this.w5.c1()) {
                    this.rr(false);
                }
                this.qm();
                break;
            case HighDensityScatterSeries.$$p[14]:
                if (this.dn != null) {
                    this.dn.deregisterColumn(this.xe);
                    this.xe = this.dk(this.zh);
                }
                break;
            case "YColumn":
                this.zw();
                if (this.w7 != null && !this.w7.c1()) {
                    this.rr(false);
                }
                this.qm();
                break;
            case HighDensityScatterSeries.$$p[6]:
                this.zw();
                this.rr(false);
                this.ql();
                break;
            case HighDensityScatterSeries.$$p[3]:
                this.rr(false);
                this.ql();
                break;
            case HighDensityScatterSeries.$$p[1]:
                this.rr(false);
                this.ql();
                break;
            case HighDensityScatterSeries.$$p[0]:
            case HighDensityScatterSeries.$$p[2]:
                if (!this.w2.b4(this.aaf, this.aae)) {
                    return;
                }
                this.zq();
                this.rr(false);
                this.ql();
                break;
            case HighDensityScatterSeries.$$p[4]:
                this.yn = Math.max(typeGetValue(d) - 1, 0);
                this.xg = this.yn > 0;
                this.rr(false);
                this.ql();
                break;
            case HighDensityScatterSeries.$$p[5]:
                this.rr(false);
                this.ql();
                break;
        }
    };
    HighDensityScatterSeries.prototype.zq = function () {
        this.xz = this.aaf.l;
        this.x2 = this.aaf.o;
        this.x1 = this.aaf.n;
        this.x0 = this.aaf.m;
        this.xv = this.aae.l;
        this.xy = this.aae.o;
        this.xx = this.aae.n;
        this.xw = this.aae.m;
        this.vv = BrushUtil.h(truncate(this.xz), truncate(this.x2), truncate(this.x1), truncate(this.x0));
        this.vf = BrushUtil.h(truncate(this.xv), truncate(this.xy), truncate(this.xx), truncate(this.xw));
    };
    HighDensityScatterSeries.prototype.xk = function (a) {
        if (typeCast(NumericYAxis.$, a) !== null) {
            return true;
        }
        return false;
    };
    HighDensityScatterSeries.prototype.xj = function (a) {
        if (typeCast(NumericXAxis.$, a) !== null) {
            return true;
        }
        return false;
    };
    HighDensityScatterSeries.prototype.zm = function (a, b) {
        this.zw();
        this.rr(false);
    };
    Object.defineProperty(HighDensityScatterSeries.prototype, "x6", {
        get: function () {
            return this.xy - this.x2;
        },
        enumerable: false,
        configurable: true
    });
    Object.defineProperty(HighDensityScatterSeries.prototype, "x5", {
        get: function () {
            return this.xx - this.x1;
        },
        enumerable: false,
        configurable: true
    });
    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
    });
    HighDensityScatterSeries.prototype.he = function (a, b, c) {
        var d = _super.prototype.he.call(this, a, b, c);
        if (this.w7 == null || this.w5 == null || this.w5.bi == null || this.w7.bi == null || this.xe == null || this.xc == null || this.xe.count < 1 || this.xc.count < 1 || this.xe.count != this.xc.count || this.w5.l4 == this.w5.l3 || this.w7.l4 == this.w7.l3 || this.ws.isEmpty) {
            d = false;
        }
        return d;
    };
    Object.defineProperty(HighDensityScatterSeries.prototype, "yu", {
        get: function () {
            return this.yo;
        },
        set: function (a) {
            var b = this.yo;
            this.yo = a;
            this.raisePropertyChanged("ProgressiveStatus", b, this.yo);
        },
        enumerable: false,
        configurable: true
    });
    HighDensityScatterSeries.prototype.rs = function (a) {
        _super.prototype.rs.call(this, a);
        this.zo(a, this.cv);
    };
    HighDensityScatterSeries.prototype.xf = function () {
        if (TestRandomness.instance.testRandomnessSource != null) {
            return TestRandomness.instance.testRandomnessSource;
        }
        return new DefaultRandomnessSource(0);
    };
    HighDensityScatterSeries.prototype.zo = function (a, b) {
        if (this.d5(b)) {
            return;
        }
        if (this.w3 == null && !this.xm) {
            var c = new List$1(KDPointData.$, 2, this.xc.count);
            var d = this.w5;
            var e = this.w7;
            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.xc.item(l), h);
                k_1 = e.el(this_1.xe.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.xc.count; l++) {
                _loop_1(l);
            }
            if (this.xl) {
                this.yj = 1;
                this.yk = truncate(logBase(c.count, 2)) + 3;
                this.yu = truncate(((this.yj / this.yk) * 100));
                if (this.progressiveLoadStatusChanged != null) {
                    this.progressiveLoadStatusChanged(this, new ProgressiveLoadStatusEventArgs(this.yu));
                }
                this.w3 = KDTree2D.b(c.toArray(), 1, this.xf());
                var m = this.w3;
                m.progressiveThunkCompleted = delegateCombine(m.progressiveThunkCompleted, runOn(this, this.zj));
                if (!this.w3.h(this.jz)) {
                    var n = this.w3;
                    n.progressiveThunkCompleted = delegateRemove(n.progressiveThunkCompleted, runOn(this, this.zj));
                }
                this.ql();
            }
            else {
                var o = dateNow();
                this.w3 = new KDTree2D(0, c.toArray(), 1, this.xf());
                var p = dateNow();
            }
        }
        if (this.xl && !this.xm) {
            this.zp(b);
        }
        else {
            this.zr(b);
        }
    };
    HighDensityScatterSeries.prototype.pb = function (a, b, c, d) {
        _super.prototype.pb.call(this, a, b, c, d);
        this.zw();
        var e = false;
        if (this.w5 != null && !this.w5.c1()) {
            e = true;
        }
        if (this.w7 != null && !this.w7.c1()) {
            e = true;
        }
        if (e) {
            this.rr(false);
        }
        this.qm();
    };
    HighDensityScatterSeries.prototype.zl = function (a) {
        var b = a;
        var c = this.ym * this.yl;
        if (this.xi) {
            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.zr = 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.w8 = new ScalerParams(0, b, c, this.w4.ch, g);
        this.w9 = new ScalerParams(0, b, c, this.w6.ch, g);
        this.zk(a);
        this.zl(a);
        var h = this.ym * this.yl;
        if (this.w1 == null || this.w1.length != h) {
            this.w1 = new Array(h);
            this.wy = new Array(h);
        }
        var i = this.w1.length;
        var j = this.w1;
        var k = this.wy;
        for (var l = 0; l < i; l++) {
            j[l] = 0;
            k[l] = 0;
        }
        this.yq = truncate(Math.round(this.id));
        this.w0 = f.b1();
        var m = this.w0.length;
        var n = this.w0;
        for (var o = 0; o < m; o++) {
            n[o] = 0;
        }
        var p = this.yh;
        var q = this.yg;
        if (isNaN_(p) || isInfinity(p)) {
            p = 0;
        }
        if (isNaN_(q) || isInfinity(q)) {
            q = 50;
        }
        this.xt = Math.min(p, q);
        this.xs = Math.max(p, q);
        if (this.xt < 0) {
            this.xt = 0;
        }
        if (this.xs < 0) {
            this.xs = 0;
        }
        this.xu = this.xs - this.xt;
        if (this.xm) {
            this.zn(a);
        }
        else {
            this.zy(a);
        }
        f.cc();
        if (a.q) {
            this._itemIndexes = d;
            this.w2.cd();
        }
    };
    HighDensityScatterSeries.prototype.zp = function (a) {
        if (this.w3 == null) {
            return;
        }
        this.zr(a);
    };
    HighDensityScatterSeries.prototype.zj = function (a, b) {
        var _this = this;
        this.w2.cb(function () {
            if (_this.yj < _this.yk - 1) {
                _this.yj++;
            }
            _this.yu = truncate(((_this.yj / _this.yk) * 100));
            if (_this.progressiveLoadStatusChanged != null) {
                _this.progressiveLoadStatusChanged(_this, new ProgressiveLoadStatusEventArgs(_this.yu));
            }
            _this.zp(_this.cv);
            _this.ql();
            if (_this.w3 != null) {
                if (!_this.w3.h(_this.jz)) {
                    var c = _this.w3;
                    c.progressiveThunkCompleted = delegateRemove(c.progressiveThunkCompleted, runOn(_this, _this.zj));
                    _this.yu = 100;
                    if (_this.progressiveLoadStatusChanged != null) {
                        _this.progressiveLoadStatusChanged(_this, new ProgressiveLoadStatusEventArgs(_this.yu));
                    }
                }
            }
        });
    };
    HighDensityScatterSeries.prototype.zn = function (a) {
        var b = arrayShallowClone(this.xc.asArray());
        this.w5.hq(boxArray$1(b), 0, b.length, this.w8);
        var c = arrayShallowClone(this.xe.asArray());
        this.yp = 0;
        var d = this.yn;
        var e = this.xg;
        var f = this.w1.length;
        this.w7.hq(boxArray$1(c), 0, c.length, this.w9);
        var g = 255 << 24 | truncate(this.x2) << 16 | truncate(this.x1) << 8 | truncate(this.x0);
        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.ym || j < 0 || j >= this.yl) {
                continue;
            }
            if (e) {
                var k = i - d;
                var l = i + d;
                l = l > (this.ym - 1) ? (this.ym - 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.ym) + o;
                        if (q < 0 || q > f - 1) {
                            continue;
                        }
                        this.w1[q] = this.w1[q] + 1;
                        this.wy[q] = 1;
                        this.yp++;
                        if (this.xi) {
                            this._itemIndexes[q] = h + 1;
                        }
                    }
                }
            }
            else {
                var r = (j * this.ym) + i;
                this.w1[r] = this.w1[r] + 1;
                this.wy[r] = 1;
                this.yp++;
                if (this.xi) {
                    this._itemIndexes[r] = h + 1;
                }
            }
        }
        this.zs();
    };
    HighDensityScatterSeries.prototype.zy = function (a) {
        var b;
        var c;
        var d = a.getViewInfo(b, c);
        b = d.p0;
        c = d.p1;
        if (this.w3 == null) {
            return;
        }
        if (this.xn == null) {
            this.xn = new List$1(KDTreeNode2D.$, 2, truncate(Math.round(b.width * b.height)));
        }
        else {
            this.xn.clear();
        }
        var e = c.left;
        var f = c.right;
        var g = c.top;
        var h = c.bottom;
        this.yd = c.top;
        this.yb = c.height;
        this.yc = c.left;
        this.ye = c.width;
        this.x9 = b.top;
        this.x7 = b.height;
        this.x8 = b.left;
        this.ya = b.width;
        var i = this.getEffectiveViewport1(a);
        this.xp = (i.left - this.x8) / this.ya;
        this.xq = (i.top - this.x9) / this.x7;
        var j = (i.right - this.x8) / this.ya;
        this.xr = j - this.xp;
        var k = (i.bottom - this.x9) / this.x7;
        this.xo = k - this.xq;
        if (this.xh) {
            e = (e - this.xp) / this.xr;
            f = (f - this.xp) / this.xr;
            g = (g - this.xq) / this.xo;
            h = (h - this.xq) / this.xo;
        }
        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.w3.u(this.xn, o, 0, 1, 0, 1);
        var p;
        this.yp = 0;
        for (var q = 0; q < this.xn.count; q++) {
            p = this.xn._inner[q];
            this.zt(p);
        }
        this.zs();
    };
    HighDensityScatterSeries.prototype.zt = 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.zv(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.zv(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.wk : Rect.empty;
        var d = new Rect(0, 0, 0, 1, 1);
        var e = this.wl(this.cv);
        var f = new ScalerParams(0, d, d, this.w5.ch, e);
        var g = new ScalerParams(0, d, d, this.w7.ch, e);
        var h = !b.isEmpty && !c.isEmpty && this.dn != null ? this.dn.indexOf(a) : -1;
        var i = this.w5 != null && this.xc != null && h < this.xc.count ? this.w5.el(this.xc.item(h), f) : NaN;
        var j = this.w7 != null && this.xe != null && h < this.xe.count ? this.w7.el(this.xe.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.zv = function (a, b, c, d) {
        var e = this.ys(b);
        var f = a.c;
        var g = this.yn;
        if (c) {
            var h = d.d;
            var i = d.b;
            var j = d.e;
            var k = d.c;
            if (this.xh) {
                h = this.xp + this.xr * h;
                i = this.xp + this.xr * i;
                j = this.xq + this.xo * j;
                k = this.xq + this.xo * k;
            }
            var l = truncate((this.x8 + this.ya * (h - this.yc) / this.ye));
            var m = truncate((this.x8 + this.ya * (i - this.yc) / this.ye));
            var n = truncate((this.x9 + this.x7 * (j - this.yd) / this.yb));
            var o = truncate((this.x9 + this.x7 * (k - this.yd) / this.yb));
            l = truncate(Math.floor(l));
            m = truncate(Math.floor(m));
            n = truncate(Math.floor(n));
            o = truncate(Math.floor(o));
            if (this.xg) {
                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.zu(f, s, t, q, r);
                }
            }
        }
        else {
            var u = a.a;
            var v = a.b;
            if (this.xh) {
                u = this.xp + this.xr * u;
                v = this.xq + this.xo * v;
            }
            var w = truncate((this.x8 + this.ya * (u - this.yc) / this.ye));
            var x = truncate((this.x9 + this.x7 * (v - this.yd) / this.yb));
            w = truncate(Math.floor(w));
            x = truncate(Math.floor(x));
            if (this.xg) {
                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.zu(f, af, ag, ad, ae);
                    }
                }
            }
            else {
                this.zu(f, w, x, b, 1);
            }
        }
    };
    HighDensityScatterSeries.prototype.yr = function (a, b) {
        return truncate((Math.floor(255 * b))) << 24 | truncate(Math.floor(b * (this.x2 + a * this.x6))) << 16 | truncate(Math.floor(b * (this.x1 + a * this.x5))) << 8 | truncate(Math.floor(b * (this.x0 + a * this.x4)));
    };
    HighDensityScatterSeries.prototype.ys = function (a) {
        return 255 << 24 | truncate(Math.floor((this.x2 + a * this.x6))) << 16 | truncate(Math.floor((this.x1 + a * this.x5))) << 8 | truncate(Math.floor((this.x0 + a * this.x4)));
    };
    HighDensityScatterSeries.prototype.yf = function (a) {
        return (a >> 24 & 255) / 255;
    };
    HighDensityScatterSeries.prototype.zu = function (a, b, c, d, e) {
        if (b < 0 || b >= this.ym || c < 0 || c >= this.yl) {
            return;
        }
        var f = (c * this.ym) + b;
        this.w1[f] = this.w1[f] + d;
        this.wy[f] = this.wy[f] + e;
        if (this.xi) {
            this._itemIndexes[f] = a + 1;
        }
        this.yp += truncate(d);
    };
    HighDensityScatterSeries.prototype.zs = function () {
        var a = 0;
        var b = 0;
        var c = this.xu;
        var d = this.xt;
        var e = this.xs;
        var f = this.w1.length;
        var g = this.w1;
        var h = this.wy;
        var i = this.w0;
        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.yr(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.zk = function (a) {
        var b = a;
        b.b9();
    };
    HighDensityScatterSeries.prototype.cs = function () {
        return new HighDensityScatterSeriesView(this);
    };
    HighDensityScatterSeries.prototype.q1 = function (a) {
        _super.prototype.q1.call(this, a);
        this.w2 = a;
    };
    HighDensityScatterSeries.prototype.ay = function (a) {
        if (a != null && a == this.w5 && this.xc != null) {
            return new AxisRange(this.xc.minimum, this.xc.maximum);
        }
        if (a != null && a == this.w7 && this.xe != null) {
            return new AxisRange(this.xe.minimum, this.xe.maximum);
        }
        return null;
    };
    HighDensityScatterSeries.prototype.sq = function (a, b) {
        if (this.db != null) {
            var c = this.getEffectiveViewport1(this.cv);
            this.xh = !c.isEmpty;
        }
        this.rr(false);
    };
    HighDensityScatterSeries.prototype.sr = function (a, b) {
        this.rr(false);
    };
    HighDensityScatterSeries.prototype.kn = function (a) {
        if (!this.xi || this._itemIndexes == null || this.db == null || this.dn == null || this._itemIndexes.length != (this.ym * this.yl)) {
            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.ws.left + (this.ws.width * c)));
        var f = truncate(Math.round(this.ws.top + (this.ws.height * d)));
        var g = this.yv(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.yv = function (a, b) {
        var c = (this.ym * b) + a;
        if (c > 0 && c < this._itemIndexes.length && this._itemIndexes[c] > 0) {
            return c;
        }
        var d = 1;
        c = (this.ym * (b - d)) + a;
        if (c > 0 && c < this._itemIndexes.length && this._itemIndexes[c] > 0) {
            return c;
        }
        c = (this.ym * (b + d)) + a;
        if (c > 0 && c < this._itemIndexes.length && this._itemIndexes[c] > 0) {
            return c;
        }
        c = (this.ym * (b)) + a - 1;
        if (c > 0 && c < this._itemIndexes.length && this._itemIndexes[c] > 0) {
            return c;
        }
        c = (this.ym * (b)) + a + 1;
        if (c > 0 && c < this._itemIndexes.length && this._itemIndexes[c] > 0) {
            return c;
        }
        c = (this.ym * (b - d)) + a - 1;
        if (c > 0 && c < this._itemIndexes.length && this._itemIndexes[c] > 0) {
            return c;
        }
        c = (this.ym * (b + d)) + a + 1;
        if (c > 0 && c < this._itemIndexes.length && this._itemIndexes[c] > 0) {
            return c;
        }
        c = (this.ym * (b - d)) + a + 1;
        if (c > 0 && c < this._itemIndexes.length && this._itemIndexes[c] > 0) {
            return c;
        }
        c = (this.ym * (b + d)) + a - 1;
        if (c > 0 && c < this._itemIndexes.length && this._itemIndexes[c] > 0) {
            return c;
        }
        return 0;
    };
    HighDensityScatterSeries.prototype.zx = function (a, b, c) {
        this.w0 = a;
        this.ym = b;
        this.yl = 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.w2.ca();
        if (this.cu != null) {
            this.cu.ca();
        }
        this.ql();
    };
    HighDensityScatterSeries.prototype.rt = function (a, b) {
        _super.prototype.rt.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.zo(false, c);
        this.g0 = false;
    };
    HighDensityScatterSeries.prototype.rq = function (a, b, c, d, e) {
        _super.prototype.rq.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.xa == null) {
            this.xa = new ScatterFrame();
        }
        this.zo(false, f);
    };
    HighDensityScatterSeries.prototype.o2 = function () {
        _super.prototype.o2.call(this);
        this.w5 = null;
        this.w7 = null;
    };
    HighDensityScatterSeries.$t = markType(HighDensityScatterSeries, 'HighDensityScatterSeries', Series.$);
    HighDensityScatterSeries.$$p = markDep(DependencyProperty, PropertyMetadata, HighDensityScatterSeries, 'raisePropertyChanged', ['HeatMaximumColor:aae:zz', [Color.$, Defaults.ap], 'HeatMaximum:yg:z0', [1, 50], 'HeatMinimumColor:aaf:z1', [Color.$, Defaults.aq], 'HeatMinimum:yh:z2', [1, 0], 'PointExtent:yt:z3', [1, 1], 'ProgressiveLoad:xl:z4', [0, true], 'UseBruteForce:xm:z5', [0, false], 'XAxis:w5:z6', [NumericXAxis.$, null], 'XMemberAsLegendLabel:y5:z7', [2, null], 'XMemberAsLegendUnit:y7:z8', [2, null], 'XMemberPath:y9:z9', [2, null], 'YAxis:w7:aaa', [NumericYAxis.$, null], 'YMemberAsLegendLabel:zd:aab', [2, null], 'YMemberAsLegendUnit:zf:aac', [2, null], 'YMemberPath:zh:aad', [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.aaf = Defaults.aq;
            this.b2.aae = Defaults.ap;
            this.b2.vf = Defaults.al;
            this.b2.vv = Defaults.ak;
        }
    };
    HighDensityScatterSeriesView.prototype.cd = function () {
        this.b2.zx(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.zx(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 };
