/*
THIS INFRAGISTICS ULTIMATE SOFTWARE LICENSE  AGREEMENT ("AGREEMENT") LOCATED HERE:
https://www.infragistics.com/legal/license/igultimate-la
https://www.infragistics.com/legal/license/igultimate-eula
GOVERNS THE LICENSING, INSTALLATION AND USE OF INFRAGISTICS SOFTWARE. BY DOWNLOADING AND/OR INSTALLING AND USING INFRAGISTICS SOFTWARE:  you are indicating that you have read and understand this Agreement, and agree to be legally bound by it on behalf of the yourself and your company.
*/
import { __extends } from "tslib";
import { ScatterBase } from "./ScatterBase";
import { UnknownValuePlotting_$type } from "igniteui-angular-core";
import { DependencyProperty } from "igniteui-angular-core";
import { Point_$type, typeCast, runOn, Number_$type, enumGetBox, markType, markDep } from "igniteui-angular-core";
import { OwnedPoint } from "./OwnedPoint";
import { ScatterFrame } from "./ScatterFrame";
import { ScatterLineSeriesView } from "./ScatterLineSeriesView";
import { Defaults } from "./Defaults";
import { PathGeometry } from "igniteui-angular-core";
import { Rect } from "igniteui-angular-core";
import { ScalerParams } from "./ScalerParams";
import { Clipper } from "igniteui-angular-core";
import { List$1 } from "igniteui-angular-core";
import { RectUtil } from "igniteui-angular-core";
import { PolyLineSegment } from "igniteui-angular-core";
import { PathFigure } from "igniteui-angular-core";
import { PathFigureCollection } from "igniteui-angular-core";
import { Flattener } from "igniteui-angular-core";
import { PropertyMetadata } from "igniteui-angular-core";
import { boxArray$1, arrayShallowClone } from "igniteui-angular-core";
import { isNaN_ } from "igniteui-angular-core";
/**
 * @hidden
 */
var ScatterLineSeries = /** @class */ /*@__PURE__*/ (function (_super) {
    __extends(ScatterLineSeries, _super);
    function ScatterLineSeries() {
        var _this = _super.call(this) || this;
        _this.ab = ScatterLineSeries.$;
        _this.zc = new ScatterFrame();
        _this.ze = new ScatterFrame();
        _this.za = new ScatterFrame();
        var a = function (b, c, d) {
            var e = _this.dp.indexOf(b.a);
            if (e == -1 || e == 0) {
                return b;
            }
            var f = _this.dp.item(e - 1);
            var g;
            if (!((function () { var h = c.g.tryGetValue(f, g); g = h.p1; return h.ret; })())) {
                return b;
            }
            return g;
        };
        _this.zc.p = a;
        _this.ze.p = a;
        _this.za.p = a;
        return _this;
    }
    ScatterLineSeries.prototype.bk = function () {
        return new ScatterLineSeries();
    };
    ScatterLineSeries.prototype.get_fl = function () {
        return true;
    };
    ScatterLineSeries.prototype.ct = function () {
        return new ScatterLineSeriesView(this);
    };
    ScatterLineSeries.prototype.z6 = function () {
        return true;
    };
    ScatterLineSeries.prototype.jn = function () {
        if (!isNaN_(this.jm)) {
            return _super.prototype.jn.call(this);
        }
        return Defaults.ak;
    };
    ScatterLineSeries.prototype.gx = function (a, b) {
        if (this.xr(a, b)) {
            return true;
        }
        if (this.acy(a, b)) {
            return true;
        }
        return false;
    };
    ScatterLineSeries.prototype.acy = function (a, b) {
        var c = this.cw;
        var d = c.dz;
        return this.gy(a, b, d.an);
    };
    ScatterLineSeries.prototype.abp = function (a, b) {
        var _this = this;
        _super.prototype.abp.call(this, a, b);
        a.n.clear();
        a.v.clear();
        var c = b.ca;
        var d = b.b9;
        var e = this.getEffectiveViewport1(b);
        var f = this.ie * this.ie;
        var g = 0;
        if (this.zr != null) {
            g = this.zr.count;
        }
        if (this.zs != null) {
            g = Math.min(this.zs.count, g);
        }
        var h = new ScalerParams(0, c, d, this.y6.d, e);
        var i = ((function () {
            var $ret = new ScalerParams(0, c, d, _this.y6.e, e);
            $ret.b = _this.i0();
            return $ret;
        })());
        var j = arrayShallowClone(this.zr.asArray());
        var k = arrayShallowClone(this.zs.asArray());
        this.xAxis.j6(boxArray$1(j), 0, j.length, h);
        this.yAxis.j6(boxArray$1(k), 0, k.length, i);
        var l = d.top - 10;
        var m = d.bottom + 10;
        var n = d.left - 10;
        var o = d.right + 10;
        var p = ((function () {
            var $ret = new Clipper(1, n, m, o, l, false);
            $ret.i = a.n;
            return $ret;
        })());
        for (var q = 0; q < g;) {
            var r = q;
            ++q;
            if (g > this.aaj) {
                while (q < g) {
                    var s = j[q] - j[r];
                    var t = k[q] - k[r];
                    var u = s * s + t * t;
                    if (isNaN_(u) || u >= f) {
                        break;
                    }
                    ++q;
                }
                p.j(this.ac5(j, k, r, q - 1));
            }
            else {
                var v = new OwnedPoint();
                v.c = { $type: Point_$type, x: j[r], y: k[r] };
                v.a = this.dp.item(r);
                if (!a.v.containsKey(v.a)) {
                    a.v.addItem(v.a, v);
                }
            }
        }
        if (g > this.aaj) {
            p.i = null;
        }
    };
    ScatterLineSeries.prototype.ac5 = function (a, b, c, d) {
        if (c == d) {
            return { $type: Point_$type, x: a[c], y: b[c] };
        }
        var e = 0;
        var f = 0;
        var g = (d - c + 1);
        for (var h = c; h <= d; ++h) {
            e += a[h];
            f += b[h];
        }
        return { $type: Point_$type, x: e / g, y: f / g };
    };
    ScatterLineSeries.prototype.get_z0 = function () {
        return true;
    };
    ScatterLineSeries.prototype.ab0 = function (a, b) {
        b.dm(false);
        _super.prototype.ab0.call(this, a, b);
        var c = this.getEffectiveViewport1(b);
        var d = new Rect(0, b.b9.left, b.b9.top, b.b9.width, b.b9.height);
        d = RectUtil.t(d, this.ig, this.ig);
        this.abt(a, new Clipper(0, d, false));
        var e = typeCast(ScatterLineSeriesView.$, b);
        this.zj.az(this, this.z5(), runOn(this, this.yz));
        var f = false;
        var g = this.zj.b;
        if (g != null) {
            f = true;
        }
        if (f) {
            this.abl(-1, this.zr.count, b.t);
        }
        this.zj.ad(e.dz, true, false, true, false);
        this.ac3(e.dz, a.n.count, function (h) { return a.n._inner[h].x; }, function (h) { return a.n._inner[h].y; }, this.acx, this.ie);
    };
    ScatterLineSeries.prototype.ac3 = function (a, b, c, d, e, f) {
        var g = new PathGeometry();
        a.an = g;
        g.c = new PathFigureCollection();
        var h = new List$1(PolyLineSegment.$, 0);
        var i = 0;
        for (var j = 0; j < b; j++) {
            if (isNaN_(c(j)) || isNaN_(d(j))) {
                var k = j - i;
                if (k > 0) {
                    if (e == 1 || h.count == 0) {
                        var l = new PolyLineSegment();
                        h.add(l);
                    }
                    this.ac2(h._inner[h.count - 1]._points, i, j - 1, c, d, f);
                }
                i = j + 1;
            }
        }
        if (e == 1 || h.count == 0) {
            var m = new PolyLineSegment();
            h.add(m);
        }
        this.ac2(h._inner[h.count - 1]._points, i, b - 1, c, d, f);
        var _loop_1 = function (n) {
            var o = h._inner[n];
            if (o._points.count > 0) {
                var p = ((function () {
                    var $ret = new PathFigure();
                    $ret.startPoint = o._points._inner[0];
                    return $ret;
                })());
                p._segments.add(o);
                g.c.add(p);
            }
        };
        for (var n = 0; n < h.count; n++) {
            _loop_1(n);
        }
    };
    ScatterLineSeries.prototype.acz = function (a, b, c, d, e, f) {
        var g = new List$1(Number_$type, 0);
        var h = d;
        var i = e;
        var j = i - h + 1;
        while (j > 0) {
            if (j <= 512) {
                Flattener.c(g, b, c, h, i, f);
                h = i + 1;
            }
            else {
                var k = h + 512 - 1;
                Flattener.c(g, b, c, h, k, f);
                h = k + 1;
            }
            j = i - h + 1;
        }
        return g;
    };
    ScatterLineSeries.prototype.ac2 = function (a, b, c, d, e, f) {
        if (c > -1) {
            var g = !isNaN_(this.jm) ? f : 1;
            var h = this.acz(new List$1(Number_$type, 0), d, e, b, c, g);
            var i = void 0;
            for (var j = 0; j < h.count; j++) {
                i = h.item(j);
                a.add({ $type: Point_$type, x: d(i), y: e(i) });
            }
        }
    };
    ScatterLineSeries.prototype.rg = function (a, b, c, d) {
        _super.prototype.rg.call(this, a, b, c, d);
        switch (b) {
            case ScatterLineSeries.$$p[0]:
                this.ry(false);
                this.qr();
                break;
        }
    };
    ScatterLineSeries.$t = markType(ScatterLineSeries, 'ScatterLineSeries', ScatterBase.$);
    ScatterLineSeries.$$p = markDep(DependencyProperty, PropertyMetadata, ScatterLineSeries, 'raisePropertyChanged', ['UnknownValuePlotting:acx:ac4', [UnknownValuePlotting_$type, enumGetBox(UnknownValuePlotting_$type, 1)]]);
    return ScatterLineSeries;
}(ScatterBase));
export { ScatterLineSeries };
