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