/*
THIS INFRAGISTICS ULTIMATE SOFTWARE LICENSE  AGREEMENT ("AGREEMENT") LOCATED HERE:
https://www.infragistics.com/legal/license/igultimate-la
https://www.infragistics.com/legal/license/igultimate-eula
GOVERNS THE LICENSING, INSTALLATION AND USE OF INFRAGISTICS SOFTWARE. BY DOWNLOADING AND/OR INSTALLING AND USING INFRAGISTICS SOFTWARE:  you are indicating that you have read and understand this Agreement, and agree to be legally bound by it on behalf of the yourself and your company.
*/
import * as tslib_1 from "tslib";
import { ScatterBase } from "./ScatterBase";
import { UnknownValuePlotting_$type } from "igniteui-react-core/ES5/UnknownValuePlotting";
import { DependencyProperty } from "igniteui-react-core/ES5/DependencyProperty";
import { Type, Point_$type, typeCast, Number_$type, enumGetBox, markType } from "igniteui-react-core/ES5/type";
import { OwnedPoint } from "./OwnedPoint";
import { ScatterFrame } from "./ScatterFrame";
import { ScatterLineSeriesView } from "./ScatterLineSeriesView";
import { PathGeometry } from "igniteui-react-core/ES5/PathGeometry";
import { Rect } from "igniteui-react-core/ES5/Rect";
import { Clipper } from "igniteui-react-core/ES5/Clipper";
import { List$1 } from "igniteui-react-core/ES5/List$1";
import { ScalerParams } from "./ScalerParams";
import { RectUtil } from "igniteui-react-core/ES5/RectUtil";
import { PolyLineSegment } from "igniteui-react-core/ES5/PolyLineSegment";
import { PathFigure } from "igniteui-react-core/ES5/PathFigure";
import { PathFigureCollection } from "igniteui-react-core/ES5/PathFigureCollection";
import { Flattener } from "igniteui-react-core/ES5/Flattener";
import { PropertyMetadata } from "igniteui-react-core/ES5/PropertyMetadata";
import { isNaN_ } from "igniteui-react-core/ES5/number";
/**
 * @hidden
 */
var ScatterLineSeries = /** @class */ (function (_super) {
    tslib_1.__extends(ScatterLineSeries, _super);
    function ScatterLineSeries() {
        var _this = _super.call(this) || this;
        _this.ab = ScatterLineSeries.$;
        _this.m2 = new ScatterFrame();
        _this.m4 = new ScatterFrame();
        _this.m1 = new ScatterFrame();
        var a = function (b, c, d) {
            var e = _this.bz.indexOf(b.a);
            if (e == -1 || e == 0) {
                return b;
            }
            var f = _this.bz.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.m2.o = a;
        _this.m4.o = a;
        _this.m1.o = a;
        return _this;
    }
    ScatterLineSeries.prototype.bf = function () {
        return new ScatterLineSeriesView(this);
    };
    ScatterLineSeries.prototype.dg = function (a, b) {
        if (this.lx(a, b)) {
            return true;
        }
        if (this.or(a, b)) {
            return true;
        }
        return false;
    };
    ScatterLineSeries.prototype.or = function (a, b) {
        var c = this.bi;
        var d = c.da;
        return this.dh(a, b, d.aj);
    };
    ScatterLineSeries.prototype.nv = function (a, b) {
        var _this = this;
        _super.prototype.nv.call(this, a, b);
        a.m.clear();
        a.u.clear();
        var c = b.bs;
        var d = b.br;
        var e = this.getEffectiveViewport1(b);
        var f = this.er * this.er;
        var g = 0;
        if (this.m6 != null) {
            g = this.m6.count;
        }
        if (this.m8 != null) {
            g = Math.min(this.m8.count, g);
        }
        var h = new ScalerParams(0, c, d, this.mx.d, e);
        var i = ((function () {
            var $ret = new ScalerParams(0, c, d, _this.mx.e, e);
            $ret.b = _this.ee();
            return $ret;
        })());
        var j = function (k) { return _this.mx.a.dt(_this.m6.item(k), h); };
        var k = function (l) { return _this.mx.b.dt(_this.m8.item(l), 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.m;
            return $ret;
        })());
        for (var q = 0; q < g;) {
            var r = q;
            ++q;
            if (g > this.nd) {
                while (q < g && this.ot(j, k, r, q) < f) {
                    ++q;
                }
                p.j(this.oz(j, k, r, q - 1));
            }
            else {
                var s = new OwnedPoint();
                s.c = { $type: Point_$type, x: j(r), y: k(r) };
                s.a = this.bz.item(r);
                if (!a.u.containsKey(s.a)) {
                    a.u.addItem(s.a, s);
                }
            }
        }
        if (g > this.nd) {
            p.i = null;
        }
    };
    ScatterLineSeries.prototype.oz = 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.ot = function (a, b, c, d) {
        var e = a(d) - a(c);
        var f = b(d) - b(c);
        return e * e + f * f;
    };
    ScatterLineSeries.prototype.n4 = function (a, b) {
        b.c0(false);
        _super.prototype.n4.call(this, a, b);
        var c = new Rect(0, b.br.left, b.br.top, b.br.width, b.br.height);
        c = RectUtil.t(c, this.ev, this.ev);
        this.nz(a, new Clipper(0, c, false));
        var d = typeCast(ScatterLineSeriesView.$, b);
        this.ox(d.da, a.m.count, function (e) { return a.m._inner[e].x; }, function (e) { return a.m._inner[e].y; }, this.oq, this.er);
    };
    ScatterLineSeries.prototype.ox = function (a, b, c, d, e, f) {
        var g = new PathGeometry();
        a.aj = g;
        g.b = 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.ow(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.ow(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.b.add(p);
            }
        };
        for (var n = 0; n < h.count; n++) {
            _loop_1(n);
        }
    };
    ScatterLineSeries.prototype.os = 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.ow = function (a, b, c, d, e, f) {
        if (c > -1) {
            var g = this.er;
            var h = this.os(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.is = function (a, b, c, d) {
        _super.prototype.is.call(this, a, b, c, d);
        switch (b) {
            case ScatterLineSeries.$$p[0]:
                this.i6(false);
                this.ic();
                break;
        }
    };
    ScatterLineSeries.$t = markType(ScatterLineSeries, 'ScatterLineSeries', ScatterBase.$);
    return ScatterLineSeries;
}(ScatterBase));
export { ScatterLineSeries };
Type.dep(DependencyProperty, PropertyMetadata, ScatterLineSeries, 'raisePropertyChanged', ['UnknownValuePlotting:oq:oy', [UnknownValuePlotting_$type, enumGetBox(UnknownValuePlotting_$type, 1)]]);
