/*
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 { 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 {
        get_e1() {
            return true;
        }
        ip() {
            if (!isNaN_(this.io)) {
                return super.ip();
            }
            return Defaults.q;
        }
        constructor() {
            super();
            this.ue = null;
            this.ug = null;
            this.vp = 0;
            this.ui = false;
            this.u4 = Defaults.aq.o;
            this.u3 = Defaults.aq.n;
            this.u2 = Defaults.aq.m;
            this.u1 = Defaults.aq.l;
            this.u0 = Defaults.ap.o;
            this.uz = Defaults.ap.n;
            this.uy = Defaults.ap.m;
            this.ux = Defaults.ap.l;
            this.t6 = null;
            this.ub = null;
            this.uc = null;
            this.t7 = null;
            this.t9 = null;
            this.uk = false;
            this.vq = 0;
            this.vs = 0;
            this.vm = 0;
            this.vl = 0;
            this.progressiveLoadStatusChanged = null;
            this.up = null;
            this.uv = 0;
            this.uu = 0;
            this.uw = 0;
            this.vb = 0;
            this.u9 = 0;
            this.va = 0;
            this.vc = 0;
            this.ve = 0;
            this.vg = 0;
            this.vf = 0;
            this.vd = 0;
            this.ur = 0;
            this.us = 0;
            this.ut = 0;
            this.uq = 0;
            this.vo = 0;
            this.vn = 0;
            this.t3 = null;
            this.vr = 0;
            this.uj = false;
            this._itemIndexes = null;
            this.t4 = null;
            this.t1 = null;
            this.ud = null;
            this.ab = HighDensityScatterSeries.$;
            this.fk = false;
        }
        get_e9() {
            return true;
        }
        get uf() {
            return this.ue;
        }
        set uf(a) {
            if (this.ue != a) {
                let b = this.uf;
                this.ue = a;
                this.raisePropertyChanged("XColumn", b, this.uf);
            }
        }
        getDataLegendSeriesContextAt(a, b) {
            let c = { $type: Point_$type, x: a, y: b };
            let d = this.jr(c);
            let e = d == null ? NaN : this.h1(d, "XMemberPath");
            let f = d == null ? NaN : this.h1(d, "YMemberPath");
            let g = new DataLegendSeriesValueInfo();
            g.l = e;
            g.a = 13;
            g.p = "X";
            g.q = this.wb != null ? this.wb : "X";
            g.r = this.v7 != null ? this.v7 : "X:";
            g.s = this.v9 != null ? this.v9 : "";
            let h = new DataLegendSeriesValueInfo();
            h.l = f;
            h.a = 14;
            h.p = "Y";
            h.q = this.wj != null ? this.wj : "Y";
            h.r = this.wf != null ? this.wf : "Y:";
            h.s = this.wh != null ? this.wh : "";
            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;
        }
        ju(a, b) {
            let c = this.lv(b);
            if (c == HighDensityScatterSeries.$$p[10]) {
                return this.jv(a, b, this.wb);
            }
            if (c == HighDensityScatterSeries.$$p[14]) {
                return this.jv(a, b, this.wj);
            }
            return super.ju(a, b);
        }
        get uh() {
            return this.ug;
        }
        set uh(a) {
            if (this.ug != a) {
                let b = this.uh;
                this.ug = a;
                this.raisePropertyChanged("YColumn", b, this.uh);
            }
        }
        wy() {
            if (this.t6 == null) {
                return;
            }
            this.t6.s();
            let a = this.t6;
            a.progressiveThunkCompleted = delegateRemove(a.progressiveThunkCompleted, runOn(this, this.wl));
            this.t6 = null;
        }
        o8(a, b, c, d) {
            super.o8(a, b, c, d);
            switch (b) {
                case "SeriesViewer":
                    if (this.cy != null) {
                        let e = this.getEffectiveViewport1(this.cj);
                        this.uj = !e.isEmpty;
                    }
                    break;
                case "FastItemsSource":
                    this.wy();
                    if (typeCast(IFastItemsSource_$type, c) != null) {
                        c.deregisterColumn(this.uf);
                        c.deregisterColumn(this.uh);
                        this.uf = null;
                        this.uh = null;
                    }
                    if (typeCast(IFastItemsSource_$type, d) != null) {
                        this.uf = this.c3(this.wb);
                        this.uh = this.c3(this.wj);
                    }
                    if ((this.ua != null && !this.ua.c1()) || (this.t8 != null && !this.t8.c1())) {
                        this.pp(this.fq && c != null);
                    }
                    this.om();
                    break;
                case HighDensityScatterSeries.$$p[7]:
                    let f = this.t7;
                    this.t7 = this.t8;
                    this.wy();
                    if (f != null) {
                        f.rangeChanged = delegateRemove(f.rangeChanged, runOn(this, this.wo));
                    }
                    if (this.t7 != null) {
                        let g = this.t7;
                        g.rangeChanged = delegateCombine(g.rangeChanged, runOn(this, this.wo));
                    }
                    if (c != null) {
                        c.b0(this);
                    }
                    if (d != null) {
                        d.ct(this);
                    }
                    if ((this.t8 != null && !this.t8.c1()) || (d == null && c != null)) {
                        this.pp(false);
                    }
                    break;
                case HighDensityScatterSeries.$$p[11]:
                    let h = this.t9;
                    this.t9 = this.ua;
                    this.wy();
                    if (h != null) {
                        h.rangeChanged = delegateRemove(h.rangeChanged, runOn(this, this.wo));
                    }
                    if (this.t9 != null) {
                        let i = this.t9;
                        i.rangeChanged = delegateCombine(i.rangeChanged, runOn(this, this.wo));
                    }
                    if (c != null) {
                        c.b0(this);
                    }
                    if (d != null) {
                        d.ct(this);
                    }
                    if ((this.ua != null && !this.ua.c1()) || (d == null && c != null)) {
                        this.pp(false);
                    }
                    break;
                case "MouseOverEnabled":
                    this.uk = this.fk;
                    this.pp(false);
                    break;
                case HighDensityScatterSeries.$$p[10]:
                    if (this.c6 != null) {
                        this.c6.deregisterColumn(this.uf);
                        this.uf = this.c3(this.wb);
                    }
                    break;
                case "XColumn":
                    this.wy();
                    if (this.t8 != null && !this.t8.c1()) {
                        this.pp(false);
                    }
                    this.om();
                    break;
                case HighDensityScatterSeries.$$p[14]:
                    if (this.c6 != null) {
                        this.c6.deregisterColumn(this.uh);
                        this.uh = this.c3(this.wj);
                    }
                    break;
                case "YColumn":
                    this.wy();
                    if (this.ua != null && !this.ua.c1()) {
                        this.pp(false);
                    }
                    this.om();
                    break;
                case HighDensityScatterSeries.$$p[6]:
                    this.wy();
                    this.pp(false);
                    this.ol();
                    break;
                case HighDensityScatterSeries.$$p[3]:
                    this.pp(false);
                    this.ol();
                    break;
                case HighDensityScatterSeries.$$p[1]:
                    this.pp(false);
                    this.ol();
                    break;
                case HighDensityScatterSeries.$$p[0]:
                case HighDensityScatterSeries.$$p[2]:
                    if (!this.t5.b4(this.xh, this.xg)) {
                        return;
                    }
                    this.ws();
                    this.pp(false);
                    this.ol();
                    break;
                case HighDensityScatterSeries.$$p[4]:
                    this.vp = Math.max(typeGetValue(d) - 1, 0);
                    this.ui = this.vp > 0;
                    this.pp(false);
                    this.ol();
                    break;
                case HighDensityScatterSeries.$$p[5]:
                    this.pp(false);
                    this.ol();
                    break;
            }
        }
        ws() {
            this.u1 = this.xh.l;
            this.u4 = this.xh.o;
            this.u3 = this.xh.n;
            this.u2 = this.xh.m;
            this.ux = this.xg.l;
            this.u0 = this.xg.o;
            this.uz = this.xg.n;
            this.uy = this.xg.m;
            this.s2 = BrushUtil.h(truncate(this.u1), truncate(this.u4), truncate(this.u3), truncate(this.u2));
            this.sw = BrushUtil.h(truncate(this.ux), truncate(this.u0), truncate(this.uz), truncate(this.uy));
        }
        um(a) {
            if (typeCast(NumericYAxis.$, a) !== null) {
                return true;
            }
            return false;
        }
        ul(a) {
            if (typeCast(NumericXAxis.$, a) !== null) {
                return true;
            }
            return false;
        }
        wo(a, b) {
            this.wy();
            this.pp(false);
        }
        get u8() {
            return this.u0 - this.u4;
        }
        get u7() {
            return this.uz - this.u3;
        }
        get u6() {
            return this.uy - this.u2;
        }
        get u5() {
            return this.ux - this.u1;
        }
        gl(a, b, c) {
            let d = super.gl(a, b, c);
            if (this.ua == null || this.t8 == null || this.t8.bi == null || this.ua.bi == null || this.uh == null || this.uf == null || this.uh.count < 1 || this.uf.count < 1 || this.uh.count != this.uf.count || this.t8.lx == this.t8.lw || this.ua.lx == this.ua.lw || this.tw.isEmpty) {
                d = false;
            }
            return d;
        }
        get vw() {
            return this.vq;
        }
        set vw(a) {
            let b = this.vq;
            this.vq = a;
            this.raisePropertyChanged("ProgressiveStatus", b, this.vq);
        }
        pq(a) {
            super.pq(a);
            this.wq(a, this.cj);
        }
        wq(a, b) {
            if (this.dl(b)) {
                return;
            }
            if (this.t6 == null && !this.uo) {
                let c = new List$1(KDPointData.$, 2, this.uf.count);
                let d = this.t8;
                let e = this.ua;
                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.uf.count; l++) {
                    j = d.ej(this.uf.item(l), h);
                    k = e.ej(this.uh.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.un) {
                    this.vl = 1;
                    this.vm = truncate(logBase(c.count, 2)) + 3;
                    this.vw = truncate(((this.vl / this.vm) * 100));
                    if (this.progressiveLoadStatusChanged != null) {
                        this.progressiveLoadStatusChanged(this, new ProgressiveLoadStatusEventArgs(this.vw));
                    }
                    this.t6 = KDTree2D.b(c.toArray(), 1);
                    let m = this.t6;
                    m.progressiveThunkCompleted = delegateCombine(m.progressiveThunkCompleted, runOn(this, this.wl));
                    if (!this.t6.f(this.i4)) {
                        let n = this.t6;
                        n.progressiveThunkCompleted = delegateRemove(n.progressiveThunkCompleted, runOn(this, this.wl));
                    }
                    this.ol();
                }
                else {
                    let o = dateNow();
                    this.t6 = new KDTree2D(0, c.toArray(), 1);
                    let p = dateNow();
                }
            }
            if (this.un && !this.uo) {
                this.wr(b);
            }
            else {
                this.wt(b);
            }
        }
        no(a, b, c, d) {
            super.no(a, b, c, d);
            this.wy();
            let e = false;
            if (this.t8 != null && !this.t8.c1()) {
                e = true;
            }
            if (this.ua != null && !this.ua.c1()) {
                e = true;
            }
            if (e) {
                this.pp(false);
            }
            this.om();
        }
        wn(a) {
            let b = a;
            let c = this.vo * this.vn;
            if (this.uk) {
                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;
                    }
                }
            }
        }
        wt(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.ub = new ScalerParams(0, b, c, this.t7.ch, g);
            this.uc = new ScalerParams(0, b, c, this.t9.ch, g);
            this.wm(a);
            this.wn(a);
            let h = this.vo * this.vn;
            if (this.t4 == null || this.t4.length != h) {
                this.t4 = new Array(h);
                this.t1 = new Array(h);
            }
            let i = this.t4.length;
            let j = this.t4;
            let k = this.t1;
            for (let l = 0; l < i; l++) {
                j[l] = 0;
                k[l] = 0;
            }
            this.vs = truncate(Math.round(this.hj));
            this.t3 = f.b1();
            let m = this.t3.length;
            let n = this.t3;
            for (let o = 0; o < m; o++) {
                n[o] = 0;
            }
            let p = this.vj;
            let q = this.vi;
            if (isNaN_(p) || isInfinity(p)) {
                p = 0;
            }
            if (isNaN_(q) || isInfinity(q)) {
                q = 50;
            }
            this.uv = Math.min(p, q);
            this.uu = Math.max(p, q);
            if (this.uv < 0) {
                this.uv = 0;
            }
            if (this.uu < 0) {
                this.uu = 0;
            }
            this.uw = this.uu - this.uv;
            if (this.uo) {
                this.wp(a);
            }
            else {
                this.w0(a);
            }
            f.cc();
            if (a.q) {
                this._itemIndexes = d;
                this.t5.cd();
            }
        }
        wr(a) {
            if (this.t6 == null) {
                return;
            }
            this.wt(a);
        }
        wl(a, b) {
            this.t5.cb(() => {
                if (this.vl < this.vm - 1) {
                    this.vl++;
                }
                this.vw = truncate(((this.vl / this.vm) * 100));
                if (this.progressiveLoadStatusChanged != null) {
                    this.progressiveLoadStatusChanged(this, new ProgressiveLoadStatusEventArgs(this.vw));
                }
                this.wr(this.cj);
                this.ol();
                if (this.t6 != null) {
                    if (!this.t6.f(this.i4)) {
                        let c = this.t6;
                        c.progressiveThunkCompleted = delegateRemove(c.progressiveThunkCompleted, runOn(this, this.wl));
                        this.vw = 100;
                        if (this.progressiveLoadStatusChanged != null) {
                            this.progressiveLoadStatusChanged(this, new ProgressiveLoadStatusEventArgs(this.vw));
                        }
                    }
                }
            });
        }
        wp(a) {
            let b = arrayShallowClone(this.uf.asArray());
            this.t8.hn(boxArray$1(b), 0, b.length, this.ub);
            let c = arrayShallowClone(this.uh.asArray());
            this.vr = 0;
            let d = this.vp;
            let e = this.ui;
            let f = this.t4.length;
            this.ua.hn(boxArray$1(c), 0, c.length, this.uc);
            let g = 255 << 24 | truncate(this.u4) << 16 | truncate(this.u3) << 8 | truncate(this.u2);
            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.vo || j < 0 || j >= this.vn) {
                    continue;
                }
                if (e) {
                    let k = i - d;
                    let l = i + d;
                    l = l > (this.vo - 1) ? (this.vo - 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.vo) + o;
                            if (q < 0 || q > f - 1) {
                                continue;
                            }
                            this.t4[q] = this.t4[q] + 1;
                            this.t1[q] = 1;
                            this.vr++;
                            if (this.uk) {
                                this._itemIndexes[q] = h + 1;
                            }
                        }
                    }
                }
                else {
                    let r = (j * this.vo) + i;
                    this.t4[r] = this.t4[r] + 1;
                    this.t1[r] = 1;
                    this.vr++;
                    if (this.uk) {
                        this._itemIndexes[r] = h + 1;
                    }
                }
            }
            this.wu();
        }
        w0(a) {
            let b;
            let c;
            let d = a.getViewInfo(b, c);
            b = d.p0;
            c = d.p1;
            if (this.t6 == null) {
                return;
            }
            if (this.up == null) {
                this.up = new List$1(KDTreeNode2D.$, 2, truncate(Math.round(b.width * b.height)));
            }
            else {
                this.up.clear();
            }
            let e = c.left;
            let f = c.right;
            let g = c.top;
            let h = c.bottom;
            this.vf = c.top;
            this.vd = c.height;
            this.ve = c.left;
            this.vg = c.width;
            this.vb = b.top;
            this.u9 = b.height;
            this.va = b.left;
            this.vc = b.width;
            let i = this.getEffectiveViewport1(a);
            this.ur = (i.left - this.va) / this.vc;
            this.us = (i.top - this.vb) / this.u9;
            let j = (i.right - this.va) / this.vc;
            this.ut = j - this.ur;
            let k = (i.bottom - this.vb) / this.u9;
            this.uq = k - this.us;
            if (this.uj) {
                e = (e - this.ur) / this.ut;
                f = (f - this.ur) / this.ut;
                g = (g - this.us) / this.uq;
                h = (h - this.us) / this.uq;
            }
            let l = this.hj / b.width * c.width;
            let m = this.hj / 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.t6.t(this.up, o, 0, 1, 0, 1);
            let p;
            this.vr = 0;
            for (let q = 0; q < this.up.count; q++) {
                p = this.up._inner[q];
                this.wv(p);
            }
            this.wu();
        }
        wv(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.wx(a.b, d, b, a.e);
            if (c > 0 && !b) {
                let e;
                for (let f = 0; f < c; f++) {
                    e = a.a[f];
                    this.wx(e, d, false, a.e);
                }
            }
            if (a.e != null) {
                a.e.a = false;
            }
        }
        fo(a) {
            let b = this.cy != null ? this.cy.tn : Rect.empty;
            let c = this.cy != null ? this.cy.t2 : Rect.empty;
            let d = new Rect(0, 0, 0, 1, 1);
            let e = this.tq(this.cj);
            let f = new ScalerParams(0, d, d, this.t8.ch, e);
            let g = new ScalerParams(0, d, d, this.ua.ch, e);
            let h = !b.isEmpty && !c.isEmpty && this.c6 != null ? this.c6.indexOf(a) : -1;
            let i = this.t8 != null && this.uf != null && h < this.uf.count ? this.t8.ej(this.uf.item(h), f) : NaN;
            let j = this.ua != null && this.uh != null && h < this.uh.count ? this.ua.ej(this.uh.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.cr != null) {
                this.cr.au(this.cy, b, true);
            }
            return h >= 0;
        }
        wx(a, b, c, d) {
            let e = this.vu(b);
            let f = a.c;
            let g = this.vp;
            if (c) {
                let h = d.d;
                let i = d.b;
                let j = d.e;
                let k = d.c;
                if (this.uj) {
                    h = this.ur + this.ut * h;
                    i = this.ur + this.ut * i;
                    j = this.us + this.uq * j;
                    k = this.us + this.uq * k;
                }
                let l = truncate((this.va + this.vc * (h - this.ve) / this.vg));
                let m = truncate((this.va + this.vc * (i - this.ve) / this.vg));
                let n = truncate((this.vb + this.u9 * (j - this.vf) / this.vd));
                let o = truncate((this.vb + this.u9 * (k - this.vf) / this.vd));
                l = truncate(Math.floor(l));
                m = truncate(Math.floor(m));
                n = truncate(Math.floor(n));
                o = truncate(Math.floor(o));
                if (this.ui) {
                    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.ww(f, s, t, q, r);
                    }
                }
            }
            else {
                let u = a.a;
                let v = a.b;
                if (this.uj) {
                    u = this.ur + this.ut * u;
                    v = this.us + this.uq * v;
                }
                let w = truncate((this.va + this.vc * (u - this.ve) / this.vg));
                let x = truncate((this.vb + this.u9 * (v - this.vf) / this.vd));
                w = truncate(Math.floor(w));
                x = truncate(Math.floor(x));
                if (this.ui) {
                    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.ww(f, af, ag, ad, ae);
                        }
                    }
                }
                else {
                    this.ww(f, w, x, b, 1);
                }
            }
        }
        vt(a, b) {
            return truncate((Math.floor(255 * b))) << 24 | truncate(Math.floor(b * (this.u4 + a * this.u8))) << 16 | truncate(Math.floor(b * (this.u3 + a * this.u7))) << 8 | truncate(Math.floor(b * (this.u2 + a * this.u6)));
        }
        vu(a) {
            return 255 << 24 | truncate(Math.floor((this.u4 + a * this.u8))) << 16 | truncate(Math.floor((this.u3 + a * this.u7))) << 8 | truncate(Math.floor((this.u2 + a * this.u6)));
        }
        vh(a) {
            return (a >> 24 & 255) / 255;
        }
        ww(a, b, c, d, e) {
            if (b < 0 || b >= this.vo || c < 0 || c >= this.vn) {
                return;
            }
            let f = (c * this.vo) + b;
            this.t4[f] = this.t4[f] + d;
            this.t1[f] = this.t1[f] + e;
            if (this.uk) {
                this._itemIndexes[f] = a + 1;
            }
            this.vr += truncate(d);
        }
        wu() {
            let a = 0;
            let b = 0;
            let c = this.uw;
            let d = this.uv;
            let e = this.uu;
            let f = this.t4.length;
            let g = this.t4;
            let h = this.t1;
            let i = this.t3;
            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.vt(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;
            }
        }
        wm(a) {
            let b = a;
            b.b9();
        }
        cg() {
            return new HighDensityScatterSeriesView(this);
        }
        o0(a) {
            super.o0(a);
            this.t5 = a;
        }
        aq(a) {
            if (a != null && a == this.t8 && this.uf != null) {
                return new AxisRange(this.uf.minimum, this.uf.maximum);
            }
            if (a != null && a == this.ua && this.uh != null) {
                return new AxisRange(this.uh.minimum, this.uh.maximum);
            }
            return null;
        }
        qm(a, b) {
            if (this.cy != null) {
                let c = this.getEffectiveViewport1(this.cj);
                this.uj = !c.isEmpty;
            }
            this.pp(false);
        }
        qn(a, b) {
            this.pp(false);
        }
        jr(a) {
            if (!this.uk || this._itemIndexes == null || this.cy == null || this.c6 == null || this._itemIndexes.length != (this.vo * this.vn)) {
                return null;
            }
            let b = this.cy.tn;
            let c = (a.x - b.left) / b.width;
            let d = (a.y - b.top) / b.height;
            let e = truncate(Math.round(this.tw.left + (this.tw.width * c)));
            let f = truncate(Math.round(this.tw.top + (this.tw.height * d)));
            let g = this.vx(e, f);
            if (g < 0 || g > this._itemIndexes.length - 1) {
                return null;
            }
            let h = this._itemIndexes[g] - 1;
            if (h < 0 || h > this.c6.count) {
                return null;
            }
            return this.c6.item(h);
        }
        vx(a, b) {
            let c = (this.vo * b) + a;
            if (c > 0 && c < this._itemIndexes.length && this._itemIndexes[c] > 0) {
                return c;
            }
            let d = 1;
            c = (this.vo * (b - d)) + a;
            if (c > 0 && c < this._itemIndexes.length && this._itemIndexes[c] > 0) {
                return c;
            }
            c = (this.vo * (b + d)) + a;
            if (c > 0 && c < this._itemIndexes.length && this._itemIndexes[c] > 0) {
                return c;
            }
            c = (this.vo * (b)) + a - 1;
            if (c > 0 && c < this._itemIndexes.length && this._itemIndexes[c] > 0) {
                return c;
            }
            c = (this.vo * (b)) + a + 1;
            if (c > 0 && c < this._itemIndexes.length && this._itemIndexes[c] > 0) {
                return c;
            }
            c = (this.vo * (b - d)) + a - 1;
            if (c > 0 && c < this._itemIndexes.length && this._itemIndexes[c] > 0) {
                return c;
            }
            c = (this.vo * (b + d)) + a + 1;
            if (c > 0 && c < this._itemIndexes.length && this._itemIndexes[c] > 0) {
                return c;
            }
            c = (this.vo * (b - d)) + a + 1;
            if (c > 0 && c < this._itemIndexes.length && this._itemIndexes[c] > 0) {
                return c;
            }
            c = (this.vo * (b + d)) + a - 1;
            if (c > 0 && c < this._itemIndexes.length && this._itemIndexes[c] > 0) {
                return c;
            }
            return 0;
        }
        wz(a, b, c) {
            this.t3 = a;
            this.vo = b;
            this.vn = c;
        }
        get_gf() {
            return true;
        }
        set_gf(a) {
            super.set_gf(a);
        }
        nj(a, b) {
            super.nj(a, b);
            this.t5.ca();
            if (this.ci != null) {
                this.ci.ca();
            }
            this.ol();
        }
        pr(a, b) {
            super.pr(a, b);
            if (!this.f8) {
                this.cj.a4(b);
                return;
            }
            this.cj.a4(b);
            if (this.dl(this.ci)) {
                return;
            }
            let c = typeCast(HighDensityScatterSeriesView.$, this.ci);
            let d = new ScatterFrame();
            this.wq(false, c);
            this.f8 = false;
        }
        po(a, b, c, d, e) {
            super.po(a, b, c, d, e);
            let f = this.a7.a$h.item(d);
            let g = f;
            f.a3(c);
            if (this.dl(g)) {
                return;
            }
            if (this.ud == null) {
                this.ud = new ScatterFrame();
            }
            this.wq(false, f);
        }
        ng() {
            super.ng();
            this.t8 = null;
            this.ua = null;
        }
    }
    HighDensityScatterSeries.$t = /*@__PURE__*/ markType(HighDensityScatterSeries, 'HighDensityScatterSeries', Series.$);
    HighDensityScatterSeries.$$p = /*@__PURE__*/ markDep(DependencyProperty, PropertyMetadata, HighDensityScatterSeries, 'raisePropertyChanged', ['HeatMaximumColor:xg:w1', [Color.$, Defaults.ap], 'HeatMaximum:vi:w2', [1, 50], 'HeatMinimumColor:xh:w3', [Color.$, Defaults.aq], 'HeatMinimum:vj:w4', [1, 0], 'PointExtent:vv:w5', [1, 1], 'ProgressiveLoad:un:w6', [0, true], 'UseBruteForce:uo:w7', [0, false], 'XAxis:t8:w8', [NumericXAxis.$, null], 'XMemberAsLegendLabel:v7:w9', [2, null], 'XMemberAsLegendUnit:v9:xa', [2, null], 'XMemberPath:wb:xb', [2, null], 'YAxis:ua:xc', [NumericYAxis.$, null], 'YMemberAsLegendLabel:wf:xd', [2, null], 'YMemberAsLegendUnit:wh:xe', [2, null], 'YMemberPath:wj:xf', [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.xh = Defaults.aq;
                this.b2.xg = Defaults.ap;
                this.b2.sw = Defaults.al;
                this.b2.s2 = Defaults.ak;
            }
        }
        cd() {
            this.b2.wz(this.b0, this.b8, this.b7);
        }
        b9() {
            if (this.b5 == null) {
                this.b5 = this.e.i4.createElement("canvas");
                let a = this.e.i4.get2DCanvasContext(this.b5);
                this.b3 = new RenderingContext(new CanvasViewRenderer(), a);
            }
            let b;
            if (this.p) {
                b = this.bx;
            }
            else {
                b = this.e.cy.ts();
            }
            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.wz(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.i4 != null) {
                this.e.i4.setTimeout(a, 0);
            }
            else {
                window.setTimeout(a, 0);
            }
        }
        a8(a, b) {
            super.a8(a, b);
            if (b) {
                if (!this.b2.fk) {
                    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.a9.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.a9.exportSeriesPixelsData(a, b, this.b8, this.b7);
        }
    }
    HighDensityScatterSeriesView.$t = /*@__PURE__*/ markType(HighDensityScatterSeriesView, 'HighDensityScatterSeriesView', SeriesView.$);
    return HighDensityScatterSeriesView;
})();
