/*
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-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 { 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
 */
export let HighDensityScatterSeries = /*@__PURE__*/ (() => {
    class HighDensityScatterSeries extends Series {
        constructor() {
            super();
            this.qp = null;
            this.qr = null;
            this.r0 = 0;
            this.qt = false;
            this.rf = Defaults.aq.o;
            this.re = Defaults.aq.n;
            this.rd = Defaults.aq.m;
            this.rc = Defaults.aq.l;
            this.rb = Defaults.ap.o;
            this.ra = Defaults.ap.n;
            this.q9 = Defaults.ap.m;
            this.q8 = Defaults.ap.l;
            this.qh = null;
            this.qm = null;
            this.qn = null;
            this.qi = null;
            this.qk = null;
            this.qv = false;
            this.r1 = 0;
            this.r3 = 0;
            this.rx = 0;
            this.rw = 0;
            this.progressiveLoadStatusChanged = null;
            this.q0 = null;
            this.q6 = 0;
            this.q5 = 0;
            this.q7 = 0;
            this.rm = 0;
            this.rk = 0;
            this.rl = 0;
            this.rn = 0;
            this.rp = 0;
            this.rr = 0;
            this.rq = 0;
            this.ro = 0;
            this.q2 = 0;
            this.q3 = 0;
            this.q4 = 0;
            this.q1 = 0;
            this.rz = 0;
            this.ry = 0;
            this.qe = null;
            this.r2 = 0;
            this.qu = false;
            this._itemIndexes = null;
            this.qf = null;
            this.qc = null;
            this.qo = null;
            this.ab = HighDensityScatterSeries.$;
            this.eo = false;
        }
        get_d8() {
            return true;
        }
        gz() {
            if (!isNaN_(this.gy)) {
                return super.gz();
            }
            return Defaults.q;
        }
        get_ef() {
            return true;
        }
        get qq() {
            return this.qp;
        }
        set qq(a) {
            if (this.qp != a) {
                let b = this.qq;
                this.qp = a;
                this.raisePropertyChanged("XColumn", b, this.qq);
            }
        }
        getDataLegendSeriesContextAt(a, b) {
            let c = { $type: Point_$type, x: a, y: b };
            let d = this.hy(c);
            let e = d == null ? NaN : this.gf(d, "XMemberPath");
            let f = d == null ? NaN : this.gf(d, "YMemberPath");
            let g = new DataLegendSeriesValueInfo();
            g.l = e;
            g.a = 13;
            g.p = "X";
            g.q = this.sm != null ? this.sm : "X";
            g.r = this.si != null ? this.si : "X:";
            g.s = this.sk != null ? this.sk : "";
            let h = new DataLegendSeriesValueInfo();
            h.l = f;
            h.a = 14;
            h.p = "Y";
            h.q = this.su != null ? this.su : "Y";
            h.r = this.sq != null ? this.sq : "Y:";
            h.s = this.ss != null ? this.ss : "";
            let i = new DataLegendSeriesContext();
            i.f = ((() => {
                let $ret = new List$1(DataLegendSeriesValueInfo.$, 0);
                $ret.add(g);
                $ret.add(h);
                return $ret;
            })());
            i.b = this.aw();
            return i;
        }
        h1(a, b) {
            let c = this.jv(b);
            if (c == HighDensityScatterSeries.$$p[10]) {
                return this.h2(a, b, this.sm);
            }
            if (c == HighDensityScatterSeries.$$p[14]) {
                return this.h2(a, b, this.su);
            }
            return super.h1(a, b);
        }
        get qs() {
            return this.qr;
        }
        set qs(a) {
            if (this.qr != a) {
                let b = this.qs;
                this.qr = a;
                this.raisePropertyChanged("YColumn", b, this.qs);
            }
        }
        s9() {
            if (this.qh == null) {
                return;
            }
            this.qh.s();
            let a = this.qh;
            a.progressiveThunkCompleted = delegateRemove(a.progressiveThunkCompleted, runOn(this, this.sw));
            this.qh = null;
        }
        l9(a, b, c, d) {
            super.l9(a, b, c, d);
            switch (b) {
                case "SeriesViewer":
                    if (this.ce != null) {
                        let e = this.getEffectiveViewport1(this.b1);
                        this.qu = !e.isEmpty;
                    }
                    break;
                case "FastItemsSource":
                    this.s9();
                    if (typeCast(IFastItemsSource_$type, c) != null) {
                        c.deregisterColumn(this.qq);
                        c.deregisterColumn(this.qs);
                        this.qq = null;
                        this.qs = null;
                    }
                    if (typeCast(IFastItemsSource_$type, d) != null) {
                        this.qq = this.ci(this.sm);
                        this.qs = this.ci(this.su);
                    }
                    if ((this.ql != null && !this.ql.c0()) || (this.qj != null && !this.qj.c0())) {
                        this.mn(false);
                    }
                    this.lv();
                    break;
                case HighDensityScatterSeries.$$p[7]:
                    let f = this.qi;
                    this.qi = this.qj;
                    this.s9();
                    if (f != null) {
                        f.rangeChanged = delegateRemove(f.rangeChanged, runOn(this, this.sz));
                    }
                    if (this.qi != null) {
                        let g = this.qi;
                        g.rangeChanged = delegateCombine(g.rangeChanged, runOn(this, this.sz));
                    }
                    if (c != null) {
                        c.bz(this);
                    }
                    if (d != null) {
                        d.cs(this);
                    }
                    if ((this.qj != null && !this.qj.c0()) || (d == null && c != null)) {
                        this.mn(false);
                    }
                    break;
                case HighDensityScatterSeries.$$p[11]:
                    let h = this.qk;
                    this.qk = this.ql;
                    this.s9();
                    if (h != null) {
                        h.rangeChanged = delegateRemove(h.rangeChanged, runOn(this, this.sz));
                    }
                    if (this.qk != null) {
                        let i = this.qk;
                        i.rangeChanged = delegateCombine(i.rangeChanged, runOn(this, this.sz));
                    }
                    if (c != null) {
                        c.bz(this);
                    }
                    if (d != null) {
                        d.cs(this);
                    }
                    if ((this.ql != null && !this.ql.c0()) || (d == null && c != null)) {
                        this.mn(false);
                    }
                    break;
                case "MouseOverEnabled":
                    this.qv = this.eo;
                    this.mn(false);
                    break;
                case HighDensityScatterSeries.$$p[10]:
                    if (this.cl != null) {
                        this.cl.deregisterColumn(this.qq);
                        this.qq = this.ci(this.sm);
                    }
                    break;
                case "XColumn":
                    this.s9();
                    if (this.qj != null && !this.qj.c0()) {
                        this.mn(false);
                    }
                    this.lv();
                    break;
                case HighDensityScatterSeries.$$p[14]:
                    if (this.cl != null) {
                        this.cl.deregisterColumn(this.qs);
                        this.qs = this.ci(this.su);
                    }
                    break;
                case "YColumn":
                    this.s9();
                    if (this.ql != null && !this.ql.c0()) {
                        this.mn(false);
                    }
                    this.lv();
                    break;
                case HighDensityScatterSeries.$$p[6]:
                    this.s9();
                    this.mn(false);
                    this.lu();
                    break;
                case HighDensityScatterSeries.$$p[3]:
                    this.mn(false);
                    this.lu();
                    break;
                case HighDensityScatterSeries.$$p[1]:
                    this.mn(false);
                    this.lu();
                    break;
                case HighDensityScatterSeries.$$p[0]:
                case HighDensityScatterSeries.$$p[2]:
                    if (!this.qg.b1(this.ts, this.tr)) {
                        return;
                    }
                    this.s3();
                    this.mn(false);
                    this.lu();
                    break;
                case HighDensityScatterSeries.$$p[4]:
                    this.r0 = Math.max(typeGetValue(d) - 1, 0);
                    this.qt = this.r0 > 0;
                    this.mn(false);
                    this.lu();
                    break;
                case HighDensityScatterSeries.$$p[5]:
                    this.mn(false);
                    this.lu();
                    break;
            }
        }
        s3() {
            this.rc = this.ts.l;
            this.rf = this.ts.o;
            this.re = this.ts.n;
            this.rd = this.ts.m;
            this.q8 = this.tr.l;
            this.rb = this.tr.o;
            this.ra = this.tr.n;
            this.q9 = this.tr.m;
            this.pe = BrushUtil.g(truncate(this.rc), truncate(this.rf), truncate(this.re), truncate(this.rd));
            this.o9 = BrushUtil.g(truncate(this.q8), truncate(this.rb), truncate(this.ra), truncate(this.q9));
        }
        qx(a) {
            if (typeCast(NumericYAxis.$, a) !== null) {
                return true;
            }
            return false;
        }
        qw(a) {
            if (typeCast(NumericXAxis.$, a) !== null) {
                return true;
            }
            return false;
        }
        sz(a, b) {
            this.s9();
            this.mn(false);
        }
        get rj() {
            return this.rb - this.rf;
        }
        get ri() {
            return this.ra - this.re;
        }
        get rh() {
            return this.q9 - this.rd;
        }
        get rg() {
            return this.q8 - this.rc;
        }
        fd(a, b, c) {
            let d = super.fd(a, b, c);
            if (this.ql == null || this.qj == null || this.qj.bh == null || this.ql.bh == null || this.qs == null || this.qq == null || this.qs.count < 1 || this.qq.count < 1 || this.qs.count != this.qq.count || this.qj.lw == this.qj.lv || this.ql.lw == this.ql.lv || this.p7.isEmpty) {
                d = false;
            }
            return d;
        }
        get r7() {
            return this.r1;
        }
        set r7(a) {
            let b = this.r1;
            this.r1 = a;
            this.raisePropertyChanged("ProgressiveStatus", b, this.r1);
        }
        mo(a) {
            super.mo(a);
            this.s1(a, this.b1);
        }
        s1(a, b) {
            if (this.cy(b)) {
                return;
            }
            if (this.qh == null && !this.qz) {
                let c = new List$1(KDPointData.$, 2, this.qq.count);
                let d = this.qj;
                let e = this.ql;
                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.cg);
                let i = new ScalerParams(1, f, g, e.cg);
                let j;
                let k;
                for (let l = 0; l < this.qq.count; l++) {
                    j = d.ei(this.qq.item(l), h);
                    k = e.ei(this.qs.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.qy) {
                    this.rw = 1;
                    this.rx = truncate(logBase(c.count, 2)) + 3;
                    this.r7 = truncate(((this.rw / this.rx) * 100));
                    if (this.progressiveLoadStatusChanged != null) {
                        this.progressiveLoadStatusChanged(this, new ProgressiveLoadStatusEventArgs(this.r7));
                    }
                    this.qh = KDTree2D.b(c.toArray(), 1);
                    let m = this.qh;
                    m.progressiveThunkCompleted = delegateCombine(m.progressiveThunkCompleted, runOn(this, this.sw));
                    if (!this.qh.f(this.he)) {
                        let n = this.qh;
                        n.progressiveThunkCompleted = delegateRemove(n.progressiveThunkCompleted, runOn(this, this.sw));
                    }
                    this.lu();
                }
                else {
                    let o = dateNow();
                    this.qh = new KDTree2D(0, c.toArray(), 1);
                    let p = dateNow();
                }
            }
            if (this.qy && !this.qz) {
                this.s2(b);
            }
            else {
                this.s4(b);
            }
        }
        k5(a, b, c, d) {
            super.k5(a, b, c, d);
            this.s9();
            let e = false;
            if (this.qj != null && !this.qj.c0()) {
                e = true;
            }
            if (this.ql != null && !this.ql.c0()) {
                e = true;
            }
            if (e) {
                this.mn(false);
            }
            this.lv();
        }
        sy(a) {
            let b = a;
            let c = this.rz * this.ry;
            if (this.qv) {
                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;
                    }
                }
            }
        }
        s4(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.qm = new ScalerParams(0, b, c, this.qi.cg, g);
            this.qn = new ScalerParams(0, b, c, this.qk.cg, g);
            this.sx(a);
            this.sy(a);
            let h = this.rz * this.ry;
            if (this.qf == null || this.qf.length != h) {
                this.qf = new Array(h);
                this.qc = new Array(h);
            }
            let i = this.qf.length;
            let j = this.qf;
            let k = this.qc;
            for (let l = 0; l < i; l++) {
                j[l] = 0;
                k[l] = 0;
            }
            this.r3 = truncate(Math.round(this.fx));
            this.qe = f.by();
            let m = this.qe.length;
            let n = this.qe;
            for (let o = 0; o < m; o++) {
                n[o] = 0;
            }
            let p = this.ru;
            let q = this.rt;
            if (isNaN_(p) || isInfinity(p)) {
                p = 0;
            }
            if (isNaN_(q) || isInfinity(q)) {
                q = 50;
            }
            this.q6 = Math.min(p, q);
            this.q5 = Math.max(p, q);
            if (this.q6 < 0) {
                this.q6 = 0;
            }
            if (this.q5 < 0) {
                this.q5 = 0;
            }
            this.q7 = this.q5 - this.q6;
            if (this.qz) {
                this.s0(a);
            }
            else {
                this.tb(a);
            }
            f.b9();
            if (a.q) {
                this._itemIndexes = d;
                this.qg.ca();
            }
        }
        s2(a) {
            if (this.qh == null) {
                return;
            }
            this.s4(a);
        }
        sw(a, b) {
            this.qg.b8(() => {
                if (this.rw < this.rx - 1) {
                    this.rw++;
                }
                this.r7 = truncate(((this.rw / this.rx) * 100));
                if (this.progressiveLoadStatusChanged != null) {
                    this.progressiveLoadStatusChanged(this, new ProgressiveLoadStatusEventArgs(this.r7));
                }
                this.s2(this.b1);
                this.lu();
                if (this.qh != null) {
                    if (!this.qh.f(this.he)) {
                        let c = this.qh;
                        c.progressiveThunkCompleted = delegateRemove(c.progressiveThunkCompleted, runOn(this, this.sw));
                        this.r7 = 100;
                        if (this.progressiveLoadStatusChanged != null) {
                            this.progressiveLoadStatusChanged(this, new ProgressiveLoadStatusEventArgs(this.r7));
                        }
                    }
                }
            });
        }
        s0(a) {
            let b = arrayShallowClone(this.qq.asArray());
            this.qj.hm(boxArray$1(b), 0, b.length, this.qm);
            let c = arrayShallowClone(this.qs.asArray());
            this.r2 = 0;
            let d = this.r0;
            let e = this.qt;
            let f = this.qf.length;
            this.ql.hm(boxArray$1(c), 0, c.length, this.qn);
            let g = 255 << 24 | truncate(this.rf) << 16 | truncate(this.re) << 8 | truncate(this.rd);
            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.rz || j < 0 || j >= this.ry) {
                    continue;
                }
                if (e) {
                    let k = i - d;
                    let l = i + d;
                    l = l > (this.rz - 1) ? (this.rz - 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.rz) + o;
                            if (q < 0 || q > f - 1) {
                                continue;
                            }
                            this.qf[q] = this.qf[q] + 1;
                            this.qc[q] = 1;
                            this.r2++;
                            if (this.qv) {
                                this._itemIndexes[q] = h + 1;
                            }
                        }
                    }
                }
                else {
                    let r = (j * this.rz) + i;
                    this.qf[r] = this.qf[r] + 1;
                    this.qc[r] = 1;
                    this.r2++;
                    if (this.qv) {
                        this._itemIndexes[r] = h + 1;
                    }
                }
            }
            this.s5();
        }
        tb(a) {
            let b;
            let c;
            let d = a.getViewInfo(b, c);
            b = d.p0;
            c = d.p1;
            if (this.qh == null) {
                return;
            }
            if (this.q0 == null) {
                this.q0 = new List$1(KDTreeNode2D.$, 2, truncate(Math.round(b.width * b.height)));
            }
            else {
                this.q0.clear();
            }
            let e = c.left;
            let f = c.right;
            let g = c.top;
            let h = c.bottom;
            this.rq = c.top;
            this.ro = c.height;
            this.rp = c.left;
            this.rr = c.width;
            this.rm = b.top;
            this.rk = b.height;
            this.rl = b.left;
            this.rn = b.width;
            let i = this.getEffectiveViewport1(a);
            this.q2 = (i.left - this.rl) / this.rn;
            this.q3 = (i.top - this.rm) / this.rk;
            let j = (i.right - this.rl) / this.rn;
            this.q4 = j - this.q2;
            let k = (i.bottom - this.rm) / this.rk;
            this.q1 = k - this.q3;
            if (this.qu) {
                e = (e - this.q2) / this.q4;
                f = (f - this.q2) / this.q4;
                g = (g - this.q3) / this.q1;
                h = (h - this.q3) / this.q1;
            }
            let l = this.fx / b.width * c.width;
            let m = this.fx / 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.qh.t(this.q0, o, 0, 1, 0, 1);
            let p;
            this.r2 = 0;
            for (let q = 0; q < this.q0.count; q++) {
                p = this.q0._inner[q];
                this.s6(p);
            }
            this.s5();
        }
        s6(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.s8(a.b, d, b, a.e);
            if (c > 0 && !b) {
                let e;
                for (let f = 0; f < c; f++) {
                    e = a.a[f];
                    this.s8(e, d, false, a.e);
                }
            }
            if (a.e != null) {
                a.e.a = false;
            }
        }
        eq(a) {
            let b = this.ce != null ? this.ce.ta : Rect.empty;
            let c = this.ce != null ? this.ce.tp : Rect.empty;
            let d = new Rect(0, 0, 0, 1, 1);
            let e = this.p1(this.b1);
            let f = new ScalerParams(0, d, d, this.qj.cg, e);
            let g = new ScalerParams(0, d, d, this.ql.cg, e);
            let h = !b.isEmpty && !c.isEmpty && this.cl != null ? this.cl.indexOf(a) : -1;
            let i = this.qj != null && this.qq != null && h < this.qq.count ? this.qj.ei(this.qq.item(h), f) : NaN;
            let j = this.ql != null && this.qs != null && h < this.qs.count ? this.ql.ei(this.qs.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.b9 != null) {
                this.b9.au(this.ce, b, true);
            }
            return h >= 0;
        }
        s8(a, b, c, d) {
            let e = this.r5(b);
            let f = a.c;
            let g = this.r0;
            if (c) {
                let h = d.d;
                let i = d.b;
                let j = d.e;
                let k = d.c;
                if (this.qu) {
                    h = this.q2 + this.q4 * h;
                    i = this.q2 + this.q4 * i;
                    j = this.q3 + this.q1 * j;
                    k = this.q3 + this.q1 * k;
                }
                let l = truncate((this.rl + this.rn * (h - this.rp) / this.rr));
                let m = truncate((this.rl + this.rn * (i - this.rp) / this.rr));
                let n = truncate((this.rm + this.rk * (j - this.rq) / this.ro));
                let o = truncate((this.rm + this.rk * (k - this.rq) / this.ro));
                l = truncate(Math.floor(l));
                m = truncate(Math.floor(m));
                n = truncate(Math.floor(n));
                o = truncate(Math.floor(o));
                if (this.qt) {
                    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.s7(f, s, t, q, r);
                    }
                }
            }
            else {
                let u = a.a;
                let v = a.b;
                if (this.qu) {
                    u = this.q2 + this.q4 * u;
                    v = this.q3 + this.q1 * v;
                }
                let w = truncate((this.rl + this.rn * (u - this.rp) / this.rr));
                let x = truncate((this.rm + this.rk * (v - this.rq) / this.ro));
                w = truncate(Math.floor(w));
                x = truncate(Math.floor(x));
                if (this.qt) {
                    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.s7(f, af, ag, ad, ae);
                        }
                    }
                }
                else {
                    this.s7(f, w, x, b, 1);
                }
            }
        }
        r4(a, b) {
            return truncate((Math.floor(255 * b))) << 24 | truncate(Math.floor(b * (this.rf + a * this.rj))) << 16 | truncate(Math.floor(b * (this.re + a * this.ri))) << 8 | truncate(Math.floor(b * (this.rd + a * this.rh)));
        }
        r5(a) {
            return 255 << 24 | truncate(Math.floor((this.rf + a * this.rj))) << 16 | truncate(Math.floor((this.re + a * this.ri))) << 8 | truncate(Math.floor((this.rd + a * this.rh)));
        }
        rs(a) {
            return (a >> 24 & 255) / 255;
        }
        s7(a, b, c, d, e) {
            if (b < 0 || b >= this.rz || c < 0 || c >= this.ry) {
                return;
            }
            let f = (c * this.rz) + b;
            this.qf[f] = this.qf[f] + d;
            this.qc[f] = this.qc[f] + e;
            if (this.qv) {
                this._itemIndexes[f] = a + 1;
            }
            this.r2 += truncate(d);
        }
        s5() {
            let a = 0;
            let b = 0;
            let c = this.q7;
            let d = this.q6;
            let e = this.q5;
            let f = this.qf.length;
            let g = this.qf;
            let h = this.qc;
            let i = this.qe;
            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.r4(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;
            }
        }
        sx(a) {
            let b = a;
            b.b6();
        }
        by() {
            return new HighDensityScatterSeriesView(this);
        }
        l4(a) {
            super.l4(a);
            this.qg = a;
        }
        aq(a) {
            if (a != null && a == this.qj && this.qq != null) {
                return new AxisRange(this.qq.minimum, this.qq.maximum);
            }
            if (a != null && a == this.ql && this.qs != null) {
                return new AxisRange(this.qs.minimum, this.qs.maximum);
            }
            return null;
        }
        na(a, b) {
            if (this.ce != null) {
                let c = this.getEffectiveViewport1(this.b1);
                this.qu = !c.isEmpty;
            }
            this.mn(false);
        }
        nb(a, b) {
            this.mn(false);
        }
        hy(a) {
            if (!this.qv || this._itemIndexes == null || this.ce == null || this.cl == null || this._itemIndexes.length != (this.rz * this.ry)) {
                return null;
            }
            let b = this.ce.ta;
            let c = (a.x - b.left) / b.width;
            let d = (a.y - b.top) / b.height;
            let e = truncate(Math.round(this.p7.left + (this.p7.width * c)));
            let f = truncate(Math.round(this.p7.top + (this.p7.height * d)));
            let g = this.r8(e, f);
            if (g < 0 || g > this._itemIndexes.length - 1) {
                return null;
            }
            let h = this._itemIndexes[g] - 1;
            if (h < 0 || h > this.cl.count) {
                return null;
            }
            return this.cl.item(h);
        }
        r8(a, b) {
            let c = (this.rz * b) + a;
            if (c > 0 && c < this._itemIndexes.length && this._itemIndexes[c] > 0) {
                return c;
            }
            let d = 1;
            c = (this.rz * (b - d)) + a;
            if (c > 0 && c < this._itemIndexes.length && this._itemIndexes[c] > 0) {
                return c;
            }
            c = (this.rz * (b + d)) + a;
            if (c > 0 && c < this._itemIndexes.length && this._itemIndexes[c] > 0) {
                return c;
            }
            c = (this.rz * (b)) + a - 1;
            if (c > 0 && c < this._itemIndexes.length && this._itemIndexes[c] > 0) {
                return c;
            }
            c = (this.rz * (b)) + a + 1;
            if (c > 0 && c < this._itemIndexes.length && this._itemIndexes[c] > 0) {
                return c;
            }
            c = (this.rz * (b - d)) + a - 1;
            if (c > 0 && c < this._itemIndexes.length && this._itemIndexes[c] > 0) {
                return c;
            }
            c = (this.rz * (b + d)) + a + 1;
            if (c > 0 && c < this._itemIndexes.length && this._itemIndexes[c] > 0) {
                return c;
            }
            c = (this.rz * (b - d)) + a + 1;
            if (c > 0 && c < this._itemIndexes.length && this._itemIndexes[c] > 0) {
                return c;
            }
            c = (this.rz * (b + d)) + a - 1;
            if (c > 0 && c < this._itemIndexes.length && this._itemIndexes[c] > 0) {
                return c;
            }
            return 0;
        }
        ta(a, b, c) {
            this.qe = a;
            this.rz = b;
            this.ry = c;
        }
        get_e7() {
            return true;
        }
        set_e7(a) {
            super.set_e7(a);
        }
        k2(a, b) {
            super.k2(a, b);
            this.qg.b7();
            if (this.b0 != null) {
                this.b0.b7();
            }
            this.lu();
        }
        mp(a, b) {
            super.mp(a, b);
            if (!this.e3) {
                this.b1.a2(b);
                return;
            }
            this.b1.a2(b);
            if (this.cy(this.b0)) {
                return;
            }
            let c = typeCast(HighDensityScatterSeriesView.$, this.b0);
            let d = new ScatterFrame();
            this.s1(false, c);
            this.e3 = false;
        }
        mm(a, b, c, d, e) {
            super.mm(a, b, c, d, e);
            let f = this.a7.a$h.item(d);
            let g = f;
            f.a1(c);
            if (this.cy(g)) {
                return;
            }
            if (this.qo == null) {
                this.qo = new ScatterFrame();
            }
            this.s1(false, f);
        }
        kz() {
            super.kz();
            this.qj = null;
            this.ql = null;
        }
    }
    HighDensityScatterSeries.$t = markType(HighDensityScatterSeries, 'HighDensityScatterSeries', Series.$);
    HighDensityScatterSeries.$$p = markDep(DependencyProperty, PropertyMetadata, HighDensityScatterSeries, 'raisePropertyChanged', ['HeatMaximumColor:tr:tc', [Color.$, Defaults.ap], 'HeatMaximum:rt:td', [1, 50], 'HeatMinimumColor:ts:te', [Color.$, Defaults.aq], 'HeatMinimum:ru:tf', [1, 0], 'PointExtent:r6:tg', [1, 1], 'ProgressiveLoad:qy:th', [0, true], 'UseBruteForce:qz:ti', [0, false], 'XAxis:qj:tj', [NumericXAxis.$, null], 'XMemberAsLegendLabel:si:tk', [2, null], 'XMemberAsLegendUnit:sk:tl', [2, null], 'XMemberPath:sm:tm', [2, null], 'YAxis:ql:tn', [NumericYAxis.$, null], 'YMemberAsLegendLabel:sq:to', [2, null], 'YMemberAsLegendUnit:ss:tp', [2, null], 'YMemberPath:su:tq', [2, null]]);
    return HighDensityScatterSeries;
})();
/**
 * @hidden
 */
export let HighDensityScatterSeriesView = /*@__PURE__*/ (() => {
    class HighDensityScatterSeriesView extends SeriesView {
        constructor(a) {
            super(a);
            this.bz = null;
            this.bx = null;
            this.b5 = 0;
            this.b4 = 0;
            this.b2 = null;
            this.b3 = null;
            this.b0 = null;
            this.bz = a;
        }
        as() {
            super.as();
            if (!this.q) {
                this.bz.ts = Defaults.aq;
                this.bz.tr = Defaults.ap;
                this.bz.o9 = Defaults.al;
                this.bz.pe = Defaults.ak;
            }
        }
        ca() {
            this.bz.ta(this.bx, this.b5, this.b4);
        }
        b6() {
            if (this.b2 == null) {
                this.b2 = this.e.he.createElement("canvas");
                let a = this.e.he.get2DCanvasContext(this.b2);
                this.b0 = new RenderingContext(new CanvasViewRenderer(), a);
            }
            let b;
            if (this.p) {
                b = this.bu;
            }
            else {
                b = this.e.ce.tf();
            }
            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.b5;
            let h = this.b4;
            this.b5 = e;
            this.b4 = f;
            if (g != this.b5 || h != this.b4 || this.bx == null) {
                this.b2.setAttribute("width", e.toString());
                this.b2.setAttribute("height", f.toString());
                this.b3 = this.b0.h().getImageData(0, 0, e, f);
                let imageDataArray_ = this.b3.data;
                this.bx = imageDataArray_;
            }
            this.bz.ta(this.bx, this.b5, this.b4);
        }
        by() {
            return this.bx;
        }
        b9() {
            let a = truncate(Math.round(this.bu.left));
            let b = truncate(Math.round(this.bu.left));
            let c = truncate(Math.round(this.bu.width));
            let d = truncate(Math.round(this.bu.height));
            this.b0.h().putImageData(this.b3, 0, 0);
            this.aq();
        }
        b8(a) {
            if (this.e.he != null) {
                this.e.he.setTimeout(a, 0);
            }
            else {
                window.setTimeout(a, 0);
            }
        }
        a6(a, b) {
            super.a6(a, b);
            if (b) {
                if (!this.bz.eo) {
                    return;
                }
                let c = new Rectangle();
                c.n = this.bu.left;
                c.o = this.bu.top;
                c.width = this.bu.width;
                c.height = this.bu.height;
                c._fill = this.bo();
                a.w(c);
                return;
            }
            if (this.b2 == null) {
                return;
            }
            let d = truncate(Math.round(this.bu.left));
            let e = truncate(Math.round(this.bu.top));
            let f = truncate(Math.round(this.bu.width));
            let g = truncate(Math.round(this.bu.height));
            this.k.o(this.b2.getNativeElement(), this.e._opacity, d, e, f, g, d, e, f, g);
        }
        b1(a, b) {
            return Color.e(toNullable(Color.$, a), toNullable(Color.$, null)) && Color.e(toNullable(Color.$, b), toNullable(Color.$, null));
        }
        b7() {
            if (this.bx != null) {
                for (let a = 0; a < this.bx.length; a++) {
                    this.bx[a] = 0;
                }
                this.b9();
            }
        }
        al(a) {
            super.al(a);
            if (this.bx == null) {
                this.e.a9.exportSeriesPixelsData(a, null, this.b5, this.b4);
                return;
            }
            let b = new Array(intDivide(this.bx.length, 4));
            let c;
            for (let d = 0; d < intDivide(this.bx.length, 4); d++) {
                c = d * 4;
                b[d] = this.bx[c + 3] << 24 | this.bx[c] << 16 | this.bx[c + 1] << 8 | this.bx[c + 2];
            }
            this.e.a9.exportSeriesPixelsData(a, b, this.b5, this.b4);
        }
    }
    HighDensityScatterSeriesView.$t = markType(HighDensityScatterSeriesView, 'HighDensityScatterSeriesView', SeriesView.$);
    return HighDensityScatterSeriesView;
})();
