/*
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 * as tslib_1 from "tslib";
import { Series } from "./Series";
import { NumericXAxis } from "./NumericXAxis";
import { DependencyProperty } from "igniteui-react-core/ES5/DependencyProperty";
import { NumericYAxis } from "./NumericYAxis";
import { Color } from "igniteui-react-core/ES5/Color";
import { ScatterFrame } from "./ScatterFrame";
import { KDTree2D } from "./KDTree2D";
import { Type, typeGetValue, runOn, delegateRemove, typeCast, delegateCombine, markType, Nullable$1 } from "igniteui-react-core/ES5/type";
import { Rect } from "igniteui-react-core/ES5/Rect";
import { IFastItemsSource_$type } from "igniteui-react-core/ES5/IFastItemsSource";
import { SeriesView } from "./SeriesView";
import { List$1 } from "igniteui-react-core/ES5/List$1";
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/ES5/PropertyMetadata";
import { truncate, isNaN_, isInfinity, logBase, intDivide } from "igniteui-react-core/ES5/number";
import { boxArray$1, arrayShallowClone } from "igniteui-react-core/ES5/array";
import { dateNow } from "igniteui-react-core/ES5/date";
import { RenderingContext } from "igniteui-react-core/ES5/RenderingContext";
import { CanvasViewRenderer } from "igniteui-react-core/ES5/CanvasViewRenderer";
import { Rectangle } from "igniteui-react-core/ES5/Rectangle";
/**
 * @hidden
 */
var HighDensityScatterSeries = /** @class */ (function (_super) {
    tslib_1.__extends(HighDensityScatterSeries, _super);
    function HighDensityScatterSeries() {
        var _this = _super.call(this) || this;
        _this.l6 = null;
        _this.l8 = null;
        _this.ne = 0;
        _this.ma = false;
        _this.mu = 0;
        _this.mt = 0;
        _this.ms = 0;
        _this.mr = 255;
        _this.mq = 0;
        _this.mp = 0;
        _this.mx = 255;
        _this.mw = 0;
        _this.mv = 0;
        _this.ly = null;
        _this.l3 = null;
        _this.l4 = null;
        _this.lz = null;
        _this.l1 = null;
        _this.mc = false;
        _this.nf = 0;
        _this.nh = 0;
        _this.nb = 0;
        _this.na = 0;
        _this.progressiveLoadStatusChanged = null;
        _this.mh = null;
        _this.mn = 0;
        _this.mm = 0;
        _this.mo = 0;
        _this.m0 = 0;
        _this.my = 0;
        _this.mz = 0;
        _this.m1 = 0;
        _this.m3 = 0;
        _this.m5 = 0;
        _this.m4 = 0;
        _this.m2 = 0;
        _this.mj = 0;
        _this.mk = 0;
        _this.ml = 0;
        _this.mi = 0;
        _this.nd = 0;
        _this.nc = 0;
        _this.lv = null;
        _this.ng = 0;
        _this.mb = false;
        _this._itemIndexes = null;
        _this.lw = null;
        _this.lt = null;
        _this.l5 = null;
        _this.ab = HighDensityScatterSeries.$;
        _this.c6 = false;
        return _this;
    }
    HighDensityScatterSeries.prototype.get_c4 = function () {
        return true;
    };
    Object.defineProperty(HighDensityScatterSeries.prototype, "l7", {
        get: function () {
            return this.l6;
        },
        set: function (a) {
            if (this.l6 != a) {
                var b = this.l7;
                this.l6 = a;
                this.raisePropertyChanged("XColumn", b, this.l7);
            }
        },
        enumerable: true,
        configurable: true
    });
    Object.defineProperty(HighDensityScatterSeries.prototype, "l9", {
        get: function () {
            return this.l8;
        },
        set: function (a) {
            if (this.l8 != a) {
                var b = this.l9;
                this.l8 = a;
                this.raisePropertyChanged("YColumn", b, this.l9);
            }
        },
        enumerable: true,
        configurable: true
    });
    HighDensityScatterSeries.prototype.oe = function () {
        if (this.ly == null) {
            return;
        }
        this.ly.s();
        var a = this.ly;
        a.progressiveThunkCompleted = delegateRemove(a.progressiveThunkCompleted, runOn(this, this.n2));
        this.ly = null;
    };
    HighDensityScatterSeries.prototype.is = function (a, b, c, d) {
        _super.prototype.is.call(this, a, b, c, d);
        switch (b) {
            case "SeriesViewer":
                if (this.bs != null) {
                    var e = this.getEffectiveViewport1(this.bi);
                    this.mb = !e.isEmpty;
                }
                break;
            case "FastItemsSource":
                this.oe();
                if (typeCast(IFastItemsSource_$type, c) != null) {
                    c.deregisterColumn(this.l7);
                    c.deregisterColumn(this.l9);
                    this.l7 = null;
                    this.l9 = null;
                }
                if (typeCast(IFastItemsSource_$type, d) != null) {
                    this.l7 = this.bw(this.nw);
                    this.l9 = this.bw(this.n0);
                }
                if ((this.l2 != null && !this.l2.ck()) || (this.l0 != null && !this.l0.ck())) {
                    this.i6(false);
                }
                this.id();
                break;
            case HighDensityScatterSeries.$$p[7]:
                var f = this.lz;
                this.lz = this.l0;
                this.oe();
                if (f != null) {
                    f.rangeChanged = delegateRemove(f.rangeChanged, runOn(this, this.n5));
                }
                if (this.lz != null) {
                    var g = this.lz;
                    g.rangeChanged = delegateCombine(g.rangeChanged, runOn(this, this.n5));
                }
                if (c != null) {
                    c.bv(this);
                }
                if (d != null) {
                    d.ch(this);
                }
                if ((this.l0 != null && !this.l0.ck()) || (d == null && c != null)) {
                    this.i6(false);
                }
                break;
            case HighDensityScatterSeries.$$p[9]:
                var h = this.l1;
                this.l1 = this.l2;
                this.oe();
                if (h != null) {
                    h.rangeChanged = delegateRemove(h.rangeChanged, runOn(this, this.n5));
                }
                if (this.l1 != null) {
                    var i = this.l1;
                    i.rangeChanged = delegateCombine(i.rangeChanged, runOn(this, this.n5));
                }
                if (c != null) {
                    c.bv(this);
                }
                if (d != null) {
                    d.ch(this);
                }
                if ((this.l2 != null && !this.l2.ck()) || (d == null && c != null)) {
                    this.i6(false);
                }
                break;
            case "MouseOverEnabled":
                this.mc = this.c6;
                this.i6(false);
                break;
            case HighDensityScatterSeries.$$p[8]:
                if (this.bz != null) {
                    this.bz.deregisterColumn(this.l7);
                    this.l7 = this.bw(this.nw);
                }
                break;
            case "XColumn":
                this.oe();
                if (this.l0 != null && !this.l0.ck()) {
                    this.i6(false);
                }
                this.id();
                break;
            case HighDensityScatterSeries.$$p[10]:
                if (this.bz != null) {
                    this.bz.deregisterColumn(this.l9);
                    this.l9 = this.bw(this.n0);
                }
                break;
            case "YColumn":
                this.oe();
                if (this.l2 != null && !this.l2.ck()) {
                    this.i6(false);
                }
                this.id();
                break;
            case HighDensityScatterSeries.$$p[6]:
                this.oe();
                this.i6(false);
                this.ic();
                break;
            case HighDensityScatterSeries.$$p[3]:
                this.i6(false);
                this.ic();
                break;
            case HighDensityScatterSeries.$$p[1]:
                this.i6(false);
                this.ic();
                break;
            case HighDensityScatterSeries.$$p[0]:
            case HighDensityScatterSeries.$$p[2]:
                if (!this.lx.by(this.ot, this.os)) {
                    return;
                }
                this.mu = this.ot.o;
                this.mt = this.ot.n;
                this.ms = this.ot.m;
                this.mr = this.os.o;
                this.mq = this.os.n;
                this.mp = this.os.m;
                this.mx = this.mr - this.mu;
                this.mw = this.mq - this.mt;
                this.mv = this.mp - this.ms;
                this.i6(false);
                this.ic();
                break;
            case HighDensityScatterSeries.$$p[4]:
                this.ne = Math.max(typeGetValue(d) - 1, 0);
                this.ma = this.ne > 0;
                this.i6(false);
                this.ic();
                break;
            case HighDensityScatterSeries.$$p[5]:
                this.i6(false);
                this.ic();
                break;
        }
    };
    HighDensityScatterSeries.prototype.me = function (a) {
        if (typeCast(NumericYAxis.$, a) !== null) {
            return true;
        }
        return false;
    };
    HighDensityScatterSeries.prototype.md = function (a) {
        if (typeCast(NumericXAxis.$, a) !== null) {
            return true;
        }
        return false;
    };
    HighDensityScatterSeries.prototype.n5 = function (a, b) {
        this.oe();
        this.i6(false);
    };
    HighDensityScatterSeries.prototype.dv = function (a, b, c) {
        var d = _super.prototype.dv.call(this, a, b, c);
        if (this.l2 == null || this.l0 == null || this.l0.bf == null || this.l2.bf == null || this.l9 == null || this.l7 == null || this.l9.count < 1 || this.l7.count < 1 || this.l9.count != this.l7.count || this.l0.jx == this.l0.jw || this.l2.jx == this.l2.jw || this.lr.isEmpty) {
            d = false;
        }
        return d;
    };
    Object.defineProperty(HighDensityScatterSeries.prototype, "nl", {
        get: function () {
            return this.nf;
        },
        set: function (a) {
            var b = this.nf;
            this.nf = a;
            this.raisePropertyChanged("ProgressiveStatus", b, this.nf);
        },
        enumerable: true,
        configurable: true
    });
    HighDensityScatterSeries.prototype.i7 = function (a) {
        _super.prototype.i7.call(this, a);
        this.n7(a, this.bi);
    };
    HighDensityScatterSeries.prototype.n7 = function (a, b) {
        if (this.cc(b)) {
            return;
        }
        if (this.ly == null && !this.mg) {
            var c = new List$1(KDPointData.$, 2, this.l7.count);
            var d = this.l0;
            var e = this.l2;
            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.b8);
            var i = new ScalerParams(1, f, g, e.b8);
            var j_1;
            var k_1;
            var _loop_1 = function (l) {
                j_1 = d.dt(this_1.l7.item(l), h);
                k_1 = e.dt(this_1.l9.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.l7.count; l++) {
                _loop_1(l);
            }
            if (this.mf) {
                this.na = 1;
                this.nb = truncate(logBase(c.count, 2)) + 3;
                this.nl = truncate(((this.na / this.nb) * 100));
                if (this.progressiveLoadStatusChanged != null) {
                    this.progressiveLoadStatusChanged(this, new ProgressiveLoadStatusEventArgs(this.nl));
                }
                this.ly = KDTree2D.b(c.toArray(), 1);
                var m = this.ly;
                m.progressiveThunkCompleted = delegateCombine(m.progressiveThunkCompleted, runOn(this, this.n2));
                if (!this.ly.f(this.e1)) {
                    var n = this.ly;
                    n.progressiveThunkCompleted = delegateRemove(n.progressiveThunkCompleted, runOn(this, this.n2));
                }
                this.ic();
            }
            else {
                var o = dateNow();
                this.ly = new KDTree2D(0, c.toArray(), 1);
                var p = dateNow();
            }
        }
        if (this.mf && !this.mg) {
            this.n8(b);
        }
        else {
            this.n9(b);
        }
    };
    HighDensityScatterSeries.prototype.hs = function (a, b, c, d) {
        _super.prototype.hs.call(this, a, b, c, d);
        this.oe();
        var e = false;
        if (this.l0 != null && !this.l0.ck()) {
            e = true;
        }
        if (this.l2 != null && !this.l2.ck()) {
            e = true;
        }
        if (e) {
            this.i6(false);
        }
        this.id();
    };
    HighDensityScatterSeries.prototype.n4 = function (a) {
        var b = a;
        var c = this.nd * this.nc;
        if (this.mc) {
            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.n9 = function (a) {
        var b;
        var c;
        var d = null;
        if (a.n) {
            d = this._itemIndexes;
        }
        var e = a.getViewInfo(c, b);
        c = e.p0;
        b = e.p1;
        var f = a;
        var g = this.getEffectiveViewport1(a);
        this.l3 = new ScalerParams(0, b, c, this.lz.b8, g);
        this.l4 = new ScalerParams(0, b, c, this.l1.b8, g);
        this.n3(a);
        this.n4(a);
        var h = this.nd * this.nc;
        if (this.lw == null || this.lw.length != h) {
            this.lw = new Array(h);
            this.lt = new Array(h);
        }
        var i = this.lw.length;
        var j = this.lw;
        var k = this.lt;
        for (var l = 0; l < i; l++) {
            j[l] = 0;
            k[l] = 0;
        }
        this.nh = truncate(Math.round(this.er));
        this.lv = f.bv();
        var m = this.lv.length;
        var n = this.lv;
        for (var o = 0; o < m; o++) {
            n[o] = 0;
        }
        var p = this.m8;
        var q = this.m7;
        if (isNaN_(p) || isInfinity(p)) {
            p = 0;
        }
        if (isNaN_(q) || isInfinity(q)) {
            q = 50;
        }
        this.mn = Math.min(p, q);
        this.mm = Math.max(p, q);
        if (this.mn < 0) {
            this.mn = 0;
        }
        if (this.mm < 0) {
            this.mm = 0;
        }
        this.mo = this.mm - this.mn;
        if (this.mg) {
            this.n6(a);
        }
        else {
            this.og(a);
        }
        f.b6();
        if (a.n) {
            this._itemIndexes = d;
            this.lx.b7();
        }
    };
    HighDensityScatterSeries.prototype.n8 = function (a) {
        if (this.ly == null) {
            return;
        }
        this.n9(a);
    };
    HighDensityScatterSeries.prototype.n2 = function (a, b) {
        var _this = this;
        this.lx.b5(function () {
            if (_this.na < _this.nb - 1) {
                _this.na++;
            }
            _this.nl = truncate(((_this.na / _this.nb) * 100));
            if (_this.progressiveLoadStatusChanged != null) {
                _this.progressiveLoadStatusChanged(_this, new ProgressiveLoadStatusEventArgs(_this.nl));
            }
            _this.n8(_this.bi);
            _this.ic();
            if (_this.ly != null) {
                if (!_this.ly.f(_this.e1)) {
                    var c = _this.ly;
                    c.progressiveThunkCompleted = delegateRemove(c.progressiveThunkCompleted, runOn(_this, _this.n2));
                    _this.nl = 100;
                    if (_this.progressiveLoadStatusChanged != null) {
                        _this.progressiveLoadStatusChanged(_this, new ProgressiveLoadStatusEventArgs(_this.nl));
                    }
                }
            }
        });
    };
    HighDensityScatterSeries.prototype.n6 = function (a) {
        var b = arrayShallowClone(this.l7.asArray());
        this.l0.gh(boxArray$1(b), 0, b.length, this.l3);
        var c = arrayShallowClone(this.l9.asArray());
        this.ng = 0;
        var d = this.ne;
        var e = this.ma;
        var f = this.lw.length;
        this.l2.gh(boxArray$1(c), 0, c.length, this.l4);
        var g = 255 << 24 | truncate(this.mu) << 16 | truncate(this.mt) << 8 | truncate(this.ms);
        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.nd || j < 0 || j >= this.nc) {
                continue;
            }
            if (e) {
                var k = i - d;
                var l = i + d;
                l = l > (this.nd - 1) ? (this.nd - 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.nd) + o;
                        if (q < 0 || q > f - 1) {
                            continue;
                        }
                        this.lw[q] = this.lw[q] + 1;
                        this.lt[q] = 1;
                        this.ng++;
                        if (this.mc) {
                            this._itemIndexes[q] = h + 1;
                        }
                    }
                }
            }
            else {
                var r = (j * this.nd) + i;
                this.lw[r] = this.lw[r] + 1;
                this.lt[r] = 1;
                this.ng++;
                if (this.mc) {
                    this._itemIndexes[r] = h + 1;
                }
            }
        }
        this.oa();
    };
    HighDensityScatterSeries.prototype.og = function (a) {
        var b;
        var c;
        var d = a.getViewInfo(b, c);
        b = d.p0;
        c = d.p1;
        if (this.ly == null) {
            return;
        }
        if (this.mh == null) {
            this.mh = new List$1(KDTreeNode2D.$, 2, truncate(Math.round(b.width * b.height)));
        }
        else {
            this.mh.clear();
        }
        var e = c.left;
        var f = c.right;
        var g = c.top;
        var h = c.bottom;
        this.m4 = c.top;
        this.m2 = c.height;
        this.m3 = c.left;
        this.m5 = c.width;
        this.m0 = b.top;
        this.my = b.height;
        this.mz = b.left;
        this.m1 = b.width;
        var i = this.getEffectiveViewport1(a);
        this.mj = (i.left - this.mz) / this.m1;
        this.mk = (i.top - this.m0) / this.my;
        var j = (i.right - this.mz) / this.m1;
        this.ml = j - this.mj;
        var k = (i.bottom - this.m0) / this.my;
        this.mi = k - this.mk;
        if (this.mb) {
            e = (e - this.mj) / this.ml;
            f = (f - this.mj) / this.ml;
            g = (g - this.mk) / this.mi;
            h = (h - this.mk) / this.mi;
        }
        var l = this.er / b.width * c.width;
        var m = this.er / 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.ly.t(this.mh, o, 0, 1, 0, 1);
        var p;
        this.ng = 0;
        for (var q = 0; q < this.mh.count; q++) {
            p = this.mh._inner[q];
            this.ob(p);
        }
        this.oa();
    };
    HighDensityScatterSeries.prototype.ob = 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.od(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.od(e, d, false, a.e);
            }
        }
        if (a.e != null) {
            a.e.a = false;
        }
    };
    HighDensityScatterSeries.prototype.c8 = function (a) {
        var b = this.bs != null ? this.bs.mq : Rect.empty;
        var c = this.bs != null ? this.bs.m3 : Rect.empty;
        var d = new Rect(0, 0, 0, 1, 1);
        var e = this.ll(this.bi);
        var f = new ScalerParams(0, d, d, this.l0.b8, e);
        var g = new ScalerParams(0, d, d, this.l2.b8, e);
        var h = !b.isEmpty && !c.isEmpty && this.bz != null ? this.bz.indexOf(a) : -1;
        var i = this.l0 != null && this.l7 != null && h < this.l7.count ? this.l0.dt(this.l7.item(h), f) : NaN;
        var j = this.l2 != null && this.l9 != null && h < this.l9.count ? this.l2.dt(this.l9.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.bn != null) {
            this.bn.ap(this.bs, b, true);
        }
        return h >= 0;
    };
    HighDensityScatterSeries.prototype.od = function (a, b, c, d) {
        var e = this.nj(b);
        var f = a.c;
        var g = this.ne;
        if (c) {
            var h = d.d;
            var i = d.b;
            var j = d.e;
            var k = d.c;
            if (this.mb) {
                h = this.mj + this.ml * h;
                i = this.mj + this.ml * i;
                j = this.mk + this.mi * j;
                k = this.mk + this.mi * k;
            }
            var l = truncate((this.mz + this.m1 * (h - this.m3) / this.m5));
            var m = truncate((this.mz + this.m1 * (i - this.m3) / this.m5));
            var n = truncate((this.m0 + this.my * (j - this.m4) / this.m2));
            var o = truncate((this.m0 + this.my * (k - this.m4) / this.m2));
            l = truncate(Math.floor(l));
            m = truncate(Math.floor(m));
            n = truncate(Math.floor(n));
            o = truncate(Math.floor(o));
            if (this.ma) {
                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.oc(f, s, t, q, r);
                }
            }
        }
        else {
            var u = a.a;
            var v = a.b;
            if (this.mb) {
                u = this.mj + this.ml * u;
                v = this.mk + this.mi * v;
            }
            var w = truncate((this.mz + this.m1 * (u - this.m3) / this.m5));
            var x = truncate((this.m0 + this.my * (v - this.m4) / this.m2));
            w = truncate(Math.floor(w));
            x = truncate(Math.floor(x));
            if (this.ma) {
                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.oc(f, af, ag, ad, ae);
                    }
                }
            }
            else {
                this.oc(f, w, x, b, 1);
            }
        }
    };
    HighDensityScatterSeries.prototype.ni = function (a, b) {
        return truncate((Math.floor(255 * b))) << 24 | truncate(Math.floor(b * (this.mu + a * this.mx))) << 16 | truncate(Math.floor(b * (this.mt + a * this.mw))) << 8 | truncate(Math.floor(b * (this.ms + a * this.mv)));
    };
    HighDensityScatterSeries.prototype.nj = function (a) {
        return 255 << 24 | truncate(Math.floor((this.mu + a * this.mx))) << 16 | truncate(Math.floor((this.mt + a * this.mw))) << 8 | truncate(Math.floor((this.ms + a * this.mv)));
    };
    HighDensityScatterSeries.prototype.m6 = function (a) {
        return (a >> 24 & 255) / 255;
    };
    HighDensityScatterSeries.prototype.oc = function (a, b, c, d, e) {
        if (b < 0 || b >= this.nd || c < 0 || c >= this.nc) {
            return;
        }
        var f = (c * this.nd) + b;
        this.lw[f] = this.lw[f] + d;
        this.lt[f] = this.lt[f] + e;
        if (this.mc) {
            this._itemIndexes[f] = a + 1;
        }
        this.ng += truncate(d);
    };
    HighDensityScatterSeries.prototype.oa = function () {
        var a = 0;
        var b = 0;
        var c = this.mo;
        var d = this.mn;
        var e = this.mm;
        var f = this.lw.length;
        var g = this.lw;
        var h = this.lt;
        var i = this.lv;
        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.ni(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.n3 = function (a) {
        var b = a;
        b.b3();
    };
    HighDensityScatterSeries.prototype.bf = function () {
        return new HighDensityScatterSeriesView(this);
    };
    HighDensityScatterSeries.prototype.im = function (a) {
        _super.prototype.im.call(this, a);
        this.lx = a;
    };
    HighDensityScatterSeries.prototype.an = function (a) {
        if (a != null && a == this.l0 && this.l7 != null) {
            return new AxisRange(this.l7.minimum, this.l7.maximum);
        }
        if (a != null && a == this.l2 && this.l9 != null) {
            return new AxisRange(this.l9.minimum, this.l9.maximum);
        }
        return null;
    };
    HighDensityScatterSeries.prototype.jl = function (a, b) {
        if (this.bs != null) {
            var c = this.getEffectiveViewport1(this.bi);
            this.mb = !c.isEmpty;
        }
        this.i6(false);
    };
    HighDensityScatterSeries.prototype.jm = function (a, b) {
        this.i6(false);
    };
    HighDensityScatterSeries.prototype.fm = function (a) {
        if (!this.mc || this._itemIndexes == null || this.bs == null || this.bz == null || this._itemIndexes.length != (this.nd * this.nc)) {
            return null;
        }
        var b = this.bs.mq;
        var c = (a.x - b.left) / b.width;
        var d = (a.y - b.top) / b.height;
        var e = truncate(Math.round(this.lr.left + (this.lr.width * c)));
        var f = truncate(Math.round(this.lr.top + (this.lr.height * d)));
        var g = this.nm(e, f);
        if (g < 0 || g > this._itemIndexes.length - 1) {
            return null;
        }
        var h = this._itemIndexes[g] - 1;
        if (h < 0 || h > this.bz.count) {
            return null;
        }
        return this.bz.item(h);
    };
    HighDensityScatterSeries.prototype.nm = function (a, b) {
        var c = (this.nd * b) + a;
        if (c > 0 && c < this._itemIndexes.length && this._itemIndexes[c] > 0) {
            return c;
        }
        var d = 1;
        c = (this.nd * (b - d)) + a;
        if (c > 0 && c < this._itemIndexes.length && this._itemIndexes[c] > 0) {
            return c;
        }
        c = (this.nd * (b + d)) + a;
        if (c > 0 && c < this._itemIndexes.length && this._itemIndexes[c] > 0) {
            return c;
        }
        c = (this.nd * (b)) + a - 1;
        if (c > 0 && c < this._itemIndexes.length && this._itemIndexes[c] > 0) {
            return c;
        }
        c = (this.nd * (b)) + a + 1;
        if (c > 0 && c < this._itemIndexes.length && this._itemIndexes[c] > 0) {
            return c;
        }
        c = (this.nd * (b - d)) + a - 1;
        if (c > 0 && c < this._itemIndexes.length && this._itemIndexes[c] > 0) {
            return c;
        }
        c = (this.nd * (b + d)) + a + 1;
        if (c > 0 && c < this._itemIndexes.length && this._itemIndexes[c] > 0) {
            return c;
        }
        c = (this.nd * (b - d)) + a + 1;
        if (c > 0 && c < this._itemIndexes.length && this._itemIndexes[c] > 0) {
            return c;
        }
        c = (this.nd * (b + d)) + a - 1;
        if (c > 0 && c < this._itemIndexes.length && this._itemIndexes[c] > 0) {
            return c;
        }
        return 0;
    };
    HighDensityScatterSeries.prototype.of = function (a, b, c) {
        this.lv = a;
        this.nd = b;
        this.nc = c;
    };
    HighDensityScatterSeries.prototype.get_dp = function () {
        return true;
    };
    HighDensityScatterSeries.prototype.set_dp = function (a) {
        _super.prototype.set_dp.call(this, a);
    };
    HighDensityScatterSeries.prototype.hp = function (a, b) {
        _super.prototype.hp.call(this, a, b);
        this.lx.b4();
        if (this.bh != null) {
            this.bh.b4();
        }
        this.ic();
    };
    HighDensityScatterSeries.prototype.i8 = function (a, b) {
        _super.prototype.i8.call(this, a, b);
        if (!this.dk) {
            this.bi.az(b);
            return;
        }
        this.bi.az(b);
        if (this.cc(this.bh)) {
            return;
        }
        var c = typeCast(HighDensityScatterSeriesView.$, this.bh);
        var d = new ScatterFrame();
        this.n7(false, c);
        this.dk = false;
    };
    HighDensityScatterSeries.prototype.i5 = function (a, b, c, d, e) {
        _super.prototype.i5.call(this, a, b, c, d, e);
        var f = this.a0.a$h.item(d);
        var g = f;
        f.ay(c);
        if (this.cc(g)) {
            return;
        }
        if (this.l5 == null) {
            this.l5 = new ScatterFrame();
        }
        this.n7(false, f);
    };
    HighDensityScatterSeries.prototype.hn = function () {
        _super.prototype.hn.call(this);
        this.l0 = null;
        this.l2 = null;
    };
    HighDensityScatterSeries.$t = markType(HighDensityScatterSeries, 'HighDensityScatterSeries', Series.$);
    return HighDensityScatterSeries;
}(Series));
export { HighDensityScatterSeries };
Type.dep(DependencyProperty, PropertyMetadata, HighDensityScatterSeries, 'raisePropertyChanged', ['HeatMaximumColor:os:oh', [Color.$, null], 'HeatMaximum:m7:oi', [1, 50], 'HeatMinimumColor:ot:oj', [Color.$, null], 'HeatMinimum:m8:ok', [1, 0], 'PointExtent:nk:ol', [1, 1], 'ProgressiveLoad:mf:om', [0, true], 'UseBruteForce:mg:on', [0, false], 'XAxis:l0:oo', [NumericXAxis.$, null], 'XMemberPath:nw:op', [2, null], 'YAxis:l2:oq', [NumericYAxis.$, null], 'YMemberPath:n0:or', [2, null]]);
/**
 * @hidden
 */
var HighDensityScatterSeriesView = /** @class */ (function (_super) {
    tslib_1.__extends(HighDensityScatterSeriesView, _super);
    function HighDensityScatterSeriesView(a) {
        var _this = _super.call(this, a) || this;
        _this.bw = null;
        _this.bu = null;
        _this.b2 = 0;
        _this.b1 = 0;
        _this.bz = null;
        _this.b0 = null;
        _this.bx = null;
        _this.bw = a;
        return _this;
    }
    HighDensityScatterSeriesView.prototype.ap = function () {
        _super.prototype.ap.call(this);
        if (!this.n) {
            this.e.er = 4;
            this.bw.ot = Color.u(255, 0, 0, 0);
            this.bw.os = Color.u(255, 255, 0, 0);
        }
    };
    HighDensityScatterSeriesView.prototype.b7 = function () {
        this.bw.of(this.bu, this.b2, this.b1);
    };
    HighDensityScatterSeriesView.prototype.b3 = function () {
        if (this.bz == null) {
            this.bz = this.e.e1.createElement("canvas");
            var a = this.e.e1.get2DCanvasContext(this.bz);
            this.bx = new RenderingContext(new CanvasViewRenderer(), a);
        }
        var b;
        if (this.m) {
            b = this.br;
        }
        else {
            b = this.e.bs.mv();
        }
        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.b2;
        var h = this.b1;
        this.b2 = e;
        this.b1 = f;
        if (g != this.b2 || h != this.b1 || this.bu == null) {
            this.bz.setAttribute("width", e.toString());
            this.bz.setAttribute("height", f.toString());
            this.b0 = this.bx.g().getImageData(0, 0, e, f);
            var imageDataArray_ = this.b0.data;
            this.bu = imageDataArray_;
        }
        this.bw.of(this.bu, this.b2, this.b1);
    };
    HighDensityScatterSeriesView.prototype.bv = function () {
        return this.bu;
    };
    HighDensityScatterSeriesView.prototype.b6 = function () {
        var a = truncate(Math.round(this.br.left));
        var b = truncate(Math.round(this.br.left));
        var c = truncate(Math.round(this.br.width));
        var d = truncate(Math.round(this.br.height));
        this.bx.g().putImageData(this.b0, 0, 0);
        this.an();
    };
    HighDensityScatterSeriesView.prototype.b5 = function (a) {
        if (this.e.e1 != null) {
            this.e.e1.setTimeout(a, 0);
        }
        else {
            window.setTimeout(a, 0);
        }
    };
    HighDensityScatterSeriesView.prototype.a3 = function (a, b) {
        _super.prototype.a3.call(this, a, b);
        if (b) {
            if (!this.bw.c6) {
                return;
            }
            var c = new Rectangle();
            c.n = this.br.left;
            c.o = this.br.top;
            c.width = this.br.width;
            c.height = this.br.height;
            c._fill = this.bl();
            a.v(c);
            return;
        }
        if (this.bz == null) {
            return;
        }
        var d = truncate(Math.round(this.br.left));
        var e = truncate(Math.round(this.br.top));
        var f = truncate(Math.round(this.br.width));
        var g = truncate(Math.round(this.br.height));
        this.h.n(this.bz.getNativeElement(), this.e._opacity, d, e, f, g, d, e, f, g);
    };
    HighDensityScatterSeriesView.prototype.by = function (a, b) {
        return Color.e(Nullable$1.toNullable(Color.$, a), Nullable$1.toNullable(Color.$, null)) && Color.e(Nullable$1.toNullable(Color.$, b), Nullable$1.toNullable(Color.$, null));
    };
    HighDensityScatterSeriesView.prototype.b4 = function () {
        if (this.bu != null) {
            for (var a = 0; a < this.bu.length; a++) {
                this.bu[a] = 0;
            }
            this.b6();
        }
    };
    HighDensityScatterSeriesView.prototype.ai = function (a) {
        _super.prototype.ai.call(this, a);
        if (this.bu == null) {
            this.e.a2.exportSeriesPixelsData(a, null, this.b2, this.b1);
            return;
        }
        var b = new Array(intDivide(this.bu.length, 4));
        var c;
        for (var d = 0; d < intDivide(this.bu.length, 4); d++) {
            c = d * 4;
            b[d] = this.bu[c + 3] << 24 | this.bu[c] << 16 | this.bu[c + 1] << 8 | this.bu[c + 2];
        }
        this.e.a2.exportSeriesPixelsData(a, b, this.b2, this.b1);
    };
    HighDensityScatterSeriesView.$t = markType(HighDensityScatterSeriesView, 'HighDensityScatterSeriesView', SeriesView.$);
    return HighDensityScatterSeriesView;
}(SeriesView));
export { HighDensityScatterSeriesView };
