/*
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, __values } from "tslib";
import { FinancialSeries } from "./FinancialSeries";
import { ITrendLineSeries_$type } from "./ITrendLineSeries";
import { TrendLineType_$type } from "igniteui-react-core";
import { DependencyProperty } from "igniteui-react-core";
import { Brush } from "igniteui-react-core";
import { PenLineCap_$type } from "igniteui-react-core";
import { DoubleCollection } from "igniteui-react-core";
import { PriceDisplayType_$type } from "./PriceDisplayType";
import { Series } from "./Series";
import { Defaults } from "./Defaults";
import { enumGetBox, EnumUtil, typeCast, fromEnum, runOn, Point_$type, markType, markDep } from "igniteui-react-core";
import { CategoryFrame } from "./CategoryFrame";
import { ISortingAxis_$type } from "./ISortingAxis";
import { FinancialSeriesView } from "./FinancialSeriesView";
import { Rect } from "igniteui-react-core";
import { List$1 } from "igniteui-react-core";
import { RectUtil } from "igniteui-react-core";
import { CategoryTrendLineManagerFactory } from "./CategoryTrendLineManagerFactory";
import { AxisRange } from "./AxisRange";
import { ScalerParams } from "./ScalerParams";
import { TrendResolutionParams } from "./TrendResolutionParams";
import { Pool$1 } from "igniteui-react-core";
import { Path } from "igniteui-react-core";
import { Thickness } from "igniteui-react-core";
import { PathGeometry } from "igniteui-react-core";
import { PathFigure } from "igniteui-react-core";
import { LineSegment } from "igniteui-react-core";
import { GeometryGroup } from "igniteui-react-core";
import { LineGeometry } from "igniteui-react-core";
import { RectangleGeometry } from "igniteui-react-core";
import { DataLegendSeriesValueInfo } from "igniteui-react-core";
import { DataLegendSeriesContext } from "igniteui-react-core";
import { PropertyMetadata } from "igniteui-react-core";
import { truncate, isNaN_, isInfinity } from "igniteui-react-core";
import { boxArray$1 } from "igniteui-react-core";
import { round10N } from "igniteui-react-core";
import { FinancialPriceBucketCalculator } from "./FinancialPriceBucketCalculator";
import { Extensions } from "igniteui-react-core";
/**
 * @hidden
 */
var FinancialPriceSeries = /** @class */ /*@__PURE__*/ (function (_super) {
    __extends(FinancialPriceSeries, _super);
    function FinancialPriceSeries() {
        var _this = _super.call(this) || this;
        _this.x6 = true;
        _this.x7 = 0;
        _this.x8 = 0;
        _this.ab = FinancialPriceSeries.$;
        _this.ud = new CategoryFrame(5);
        _this.uf = new CategoryFrame(5);
        _this.ub = new CategoryFrame(5);
        return _this;
    }
    FinancialPriceSeries.prototype.get_en = function () {
        return true;
    };
    FinancialPriceSeries.prototype.ip = function () {
        if (!isNaN_(this.io)) {
            return _super.prototype.ip.call(this);
        }
        return Defaults.k;
    };
    FinancialPriceSeries.prototype.cg = function () {
        return new FinancialPriceSeriesView(this);
    };
    FinancialPriceSeries.prototype.o0 = function (a) {
        _super.prototype.o0.call(this, a);
        this.x4 = a;
    };
    Object.defineProperty(FinancialPriceSeries.prototype, "zg", {
        get: function () {
            return this.c(FinancialPriceSeries.yy);
        },
        set: function (a) {
            this.h(FinancialPriceSeries.yy, a);
        },
        enumerable: false,
        configurable: true
    });
    FinancialPriceSeries.prototype.no = function (a, b, c, d) {
        _super.prototype.no.call(this, a, b, c, d);
        if (this.t9 != null && typeCast(ISortingAxis_$type, this.t9) !== null) {
            this.t9.i$i();
        }
        this.x4.b0.e(this.hj);
        if (this.x4.ca) {
            this.x4.b8.g$e(a, b, c, d);
        }
        if (this.uv != null) {
            this.uv.c1();
        }
        this.pp(true);
        if (a == 0 || a == 2 || a == 3 || a == 4) {
            this.x6 = true;
        }
        else if (a == 1) {
            for (var e = b; e < b + c; e++) {
                var f = 0;
                f += this.u3.item(e);
                f += this.u4.item(e);
                f += this.u2.item(e);
                this.x7 += f / 3;
            }
            this.x8 = this.x7 / this.u3.count;
        }
    };
    FinancialPriceSeries.prototype.bx = function () {
        if (this.by == 0) {
            return 1;
        }
        else {
            return _super.prototype.bx.call(this);
        }
    };
    FinancialPriceSeries.prototype.ts = function (a) {
        if (this.ub == null || this.ub.f.count == 0) {
            return Rect.empty;
        }
        var b = this.tc(a);
        var c = this.cj.by;
        var d = this.cj.bx;
        var e = this.getEffectiveViewport1(this.cj);
        var f = this.aj(this.t9, this.ub.f, this.v6(this.cj), this.v8(this.cj), a, true);
        var g = f[0];
        var h = f[1];
        var i = Math.abs(b.x - g[0]);
        var j = Math.abs(b.x - h[0]);
        var k = this.x9(this.uq, e);
        k = Math.max(k, 3);
        var l = (k - 1) / 2;
        if (i < j) {
            var m = g[0] - l;
            var n = g[0];
            var o = g[0] + l;
            var p = g[1];
            var q = g[2];
            var r = g[3];
            var s = g[4];
            var t = Math.min(Math.min(Math.min(p, q), r), s);
            var u = Math.max(Math.max(Math.max(p, q), r), s);
            return new Rect(0, m, t, Math.abs(o - m), u - t);
        }
        else {
            var v = h[0] - l;
            var w = h[0];
            var x = h[0] + l;
            var y = h[1];
            var z = h[2];
            var aa = h[3];
            var ab = h[4];
            var ac = Math.min(Math.min(Math.min(y, z), aa), ab);
            var ad = Math.max(Math.max(Math.max(y, z), aa), ab);
            return new Rect(0, v, ac, Math.abs(x - v), ad - ac);
        }
    };
    FinancialPriceSeries.prototype.x3 = function (a, b) {
        var c = a[0] - b;
        var d = a[0];
        var e = a[0] + b;
        var f = a[1];
        var g = a[2];
        var h = a[3];
        var i = a[4];
        var j = Math.min(Math.min(Math.min(f, g), h), i);
        var k = Math.max(Math.max(Math.max(f, g), h), i);
        var l = Math.min(g, h);
        var m = Math.max(g, h);
        var n = Math.min(f, i);
        var o = Math.max(f, i);
        if (this.x5 == 1) {
            var p = new Array(3);
            var q = new Rect(0, c, f, b, 0);
            var r = new Rect(0, d, i, b, 0);
            var s = new Rect(0, d, l, 0, m - l);
            p[0] = q;
            p[1] = r;
            p[2] = s;
            return p;
        }
        else {
            var t = new Array(2);
            var u = new Rect(0, d, l, 0, m - l);
            var v = new Rect(0, c, n, b * 2, o - n);
            t[0] = u;
            t[1] = v;
            return t;
        }
    };
    FinancialPriceSeries.prototype.ak = function (a) {
        var b = new List$1(Rect.$, 0);
        var c = this.tc(a);
        var d = this.cj.by;
        var e = this.cj.bx;
        var f = this.getEffectiveViewport1(this.cj);
        var g = this.aj(this.t9, this.ub.f, this.v6(this.cj), this.v8(this.cj), a, true);
        var h = g[0];
        var i = g[1];
        var j = Math.abs(c.x - h[0]);
        var k = Math.abs(c.x - i[0]);
        var l = this.x9(this.uq, f);
        l = Math.max(l, 3);
        var m = (l - 1) / 2;
        if (j < k) {
            return this.x3(h, m);
        }
        else {
            return this.x3(i, m);
        }
    };
    FinancialPriceSeries.prototype.f4 = function (a, b) {
        if (this.f7(a, b)) {
            return true;
        }
        return false;
    };
    FinancialPriceSeries.prototype.f7 = function (a, b) {
        var c = this.tt(a);
        if (c.isEmpty) {
            return false;
        }
        var d = RectUtil.r(c, (this.hk / 2) + this.hy(b));
        if (d.containsPoint(a)) {
            var e = this.al(a);
            if (e != null) {
                for (var f = 0; f < e.length; f++) {
                    var g = e[f];
                    var h = RectUtil.r(g, (this.hk / 2) + this.hy(b));
                    if (h.containsPoint(a)) {
                        return true;
                    }
                }
            }
        }
        return false;
    };
    FinancialPriceSeries.prototype.o8 = function (a, b, c, d) {
        switch (b) {
            case FinancialSeries.$$p[14]:
                this.x4.cg();
                if (this.cy != null) {
                    this.cy.mf();
                }
                break;
            case "TrendLineType":
                var e = EnumUtil.getEnumValue(TrendLineType_$type, d);
                if (e != 0) {
                    this.x4.b8 = CategoryTrendLineManagerFactory.a(this.x4.b8, this.t9, this.qr, this, this.c9);
                }
                break;
        }
        _super.prototype.o8.call(this, a, b, c, d);
        if (this.x4.ca && this.x4.b8 != null && this.x4.b8.g$b(a, b, c, d)) {
            this.pp(false);
            this.ol();
        }
        switch (b) {
            case FinancialPriceSeries.$$p[2]:
                if (this.qr != null) {
                    this.yx();
                    this.qe();
                    this.ub.w();
                    this.xh(this.ub, this.x4);
                }
                this.ol();
                break;
            case "ActualHighlightingMode":
                this.pp(true);
                break;
            case "TrendLineBrush":
                this.pe(b);
                break;
            case "TrendLineType":
                this.ol();
                break;
            case FinancialSeries.$$p[10]:
            case FinancialPriceSeries.$$p[7]:
                this.o2();
                break;
        }
    };
    FinancialPriceSeries.prototype.yx = function () {
        this.x4.ck();
        if (this.ci != null) {
            this.ci.ck();
        }
    };
    FinancialPriceSeries.prototype.aq = function (a) {
        if (a != null && a == this.uv && this.u4 != null && !isNaN_(this.u4.minimum) && this.u3 != null && !isNaN_(this.u3.maximum)) {
            return new AxisRange(this.u4.minimum, this.u3.maximum);
        }
        return null;
    };
    FinancialPriceSeries.prototype.ar = function (a) {
        if (a.isEmpty && this.cy != null) {
            a = this.cy.tn;
        }
        if (this.u4 == null || this.u3 == null) {
            return null;
        }
        var b = this.to(this.cj);
        var c = new ScalerParams(0, a, this.cy.t2, this.t9.ch, this.getEffectiveViewport());
        var d = (this.t9.em(b.left, c));
        var e = (this.t9.em(b.right, c));
        if (this.t9.ch) {
            var f = d;
            d = e;
            e = f;
        }
        var g = null;
        if (this.t9.cn) {
            g = this.t9;
            d = g.i$f(d);
            e = g.i$f(e);
        }
        else {
            d = Math.floor(d);
            e = Math.ceil(e);
        }
        d = Math.max(0, Math.min(this.u4.count - 1, d));
        e = Math.max(0, Math.min(this.u4.count - 1, e));
        var h = 1.7976931348623157E+308;
        var i = -1.7976931348623157E+308;
        for (var j = truncate(d); j <= truncate(e); j++) {
            var k = j;
            if (g != null) {
                k = g.i$b._inner[j];
            }
            var l = this.u4.item(k);
            if (this.u4.mayContainUnknowns) {
                if (isInfinity(l) || isNaN_(l)) {
                    continue;
                }
            }
            var m = this.u3.item(k);
            if (this.u3.mayContainUnknowns) {
                if (isInfinity(m) || isNaN_(m)) {
                    continue;
                }
            }
            h = Math.min(h, l);
            i = Math.max(i, m);
        }
        var n = new AxisRange(h, i);
        n = this.ap(n, this.uv, a);
        return n;
    };
    FinancialPriceSeries.prototype.h2 = function () {
        return Series.h3(this.u5, typeCast(ISortingAxis_$type, this.t9));
    };
    FinancialPriceSeries.prototype.fo = function (a) {
        var b = this.c6 != null ? this.c6.indexOf(a) : -1;
        var c = this.cj.by;
        c = c.copy();
        var d = this.cj.bx;
        var e = new Rect(0, 0, 0, 1, 1);
        var f = this.tq(this.cj);
        if (b >= 0 && Rect.l_op_Inequality(c, null) && Rect.l_op_Inequality(d, null)) {
            if (this.t9 != null) {
                var g = new ScalerParams(0, e, e, this.t9.ch, f);
                var h = this.t9.ej(b, g);
                if (h < c.left + 0.1 * c.width) {
                    h = h + 0.4 * c.width;
                }
                if (h > c.right - 0.1 * c.width) {
                    h = h - 0.4 * c.width;
                }
                c.x = h - 0.5 * c.width;
            }
            if (this.uv != null && this.u4 != null && this.u3 != null && b < this.u4.count && b < this.u3.count) {
                var i = new ScalerParams(0, e, e, this.uv.ch, f);
                i.b = this.h2();
                var j = this.uv.ej(this.u4.item(b), i);
                var k = this.uv.ej(this.u3.item(b), i);
                if (!isNaN_(j) && !isNaN_(k)) {
                    var l = Math.abs(j - k);
                    if (c.height < l) {
                        c.height = l;
                        c.y = Math.min(j, k);
                    }
                    else {
                        if (j < c.top + 0.1 * c.height) {
                            j = j + 0.4 * c.height;
                        }
                        if (j > c.bottom - 0.1 * c.height) {
                            j = j - 0.4 * c.height;
                        }
                        c.y = j - 0.5 * c.height;
                    }
                }
            }
            this.cr.au(this.cy, c, true);
        }
        return b >= 0;
    };
    FinancialPriceSeries.prototype.gl = function (a, b, c) {
        var d = _super.prototype.gl.call(this, a, b, c);
        if (this.u5 == null || this.u2 == null || this.u3 == null || this.u4 == null) {
            d = false;
        }
        return d;
    };
    FinancialPriceSeries.prototype.xf = function (a, b) {
        var e_1, _a;
        var _this = this;
        _super.prototype.xf.call(this, a, b);
        var c = b.by;
        var d = b.bx;
        var e = this.getEffectiveViewport1(b);
        var f = this.t9;
        var g = this.uv;
        var h = new ScalerParams(0, c, d, f.ch, e);
        var i = ((function () {
            var $ret = new ScalerParams(0, c, d, g.ch, e);
            $ret.b = _this.h2();
            return $ret;
        })());
        var j = this.t9.ag();
        var k = j[0];
        var l = j[1];
        a.f.clear();
        a.m.clear();
        a.p.clear();
        var m = 0;
        var n = typeCast(ISortingAxis_$type, this.t9);
        if (n != null && (n.i$b == null || n.i$b.count != this.c6.count)) {
            return;
        }
        m = this.v0(c, d, e);
        var o = typeCast(FinancialPriceSeriesView.$, b);
        var p = this.hj;
        if (this.trendLineType != 0) {
            var q = new Array(this.c6.count);
            var r = 0;
            try {
                for (var _b = __values(fromEnum(this.vr)), _c = _b.next(); !_c.done; _c = _b.next()) {
                    var s = _c.value;
                    q[r] = s;
                    r++;
                }
            }
            catch (e_1_1) {
                e_1 = { error: e_1_1 };
            }
            finally {
                try {
                    if (_c && !_c.done && (_a = _b.return))
                        _a.call(_b);
                }
                finally {
                    if (e_1)
                        throw e_1.error;
                }
            }
            if (this.x4.ca) {
                this.x4.b8.prepareLineCore(a.p, this.trendLineType, boxArray$1(q), this.trendLinePeriod, function (t) { return _this.t9.ej(t, h); }, function (t) { return _this.uv.ej(t, i); }, ((function () {
                    var $ret = new TrendResolutionParams();
                    $ret.e = b.b0.b;
                    $ret.f = b.b0.c;
                    $ret.g = b.b0.d;
                    $ret.a = m;
                    $ret.d = p;
                    $ret.h = d;
                    $ret.c = k;
                    $ret.b = l;
                    return $ret;
                })()));
            }
        }
        var t = this.t9.em(2, h) - this.t9.em(1, h);
        for (var u = b.b0.c; u <= b.b0.d; ++u) {
            var v = void 0;
            if (n == null) {
                v = b.b0.getBucket(u);
            }
            else {
                var w = n.i$b._inner[u];
                var x = n.i$d(w);
                var y = this.u5.item(w);
                var z = this.u3.item(w);
                var aa = this.u4.item(w);
                var ab = this.u2.item(w);
                var ac = y;
                var ad = z;
                var ae = aa;
                var af = ab;
                var ag = x;
                while (u < b.b0.d) {
                    w = n.i$b._inner[u + 1];
                    ag = n.i$d(w);
                    if (ag - x > t * p) {
                        break;
                    }
                    u++;
                    ad = Math.max(ad, this.u3.item(w));
                    ae = Math.min(ae, this.u4.item(w));
                    af = this.u2.item(w);
                }
                var ah = NaN;
                if (!isNaN_(x)) {
                    ah = this.t9.ej(x, h);
                }
                v = [ah, ac, ad, ae, af];
            }
            if (!isNaN_(v[0])) {
                if (n != null) {
                    v[0] = v[0] + m;
                }
                else {
                    v[0] = f.ej(v[0], h) + m;
                }
                v[1] = g.ej(v[1], i);
                v[2] = g.ej(v[2], i);
                v[3] = g.ej(v[3], i);
                v[4] = g.ej(v[4], i);
                a.f.add(v);
            }
        }
        return;
    };
    FinancialPriceSeries.prototype.nj = function (a, b) {
        _super.prototype.nj.call(this, a, b);
        var c = typeCast(FinancialPriceSeriesView.$, b);
        c.ce();
        if (a) {
            c.b9.count = 0;
        }
        if (c.ca && c.b8 != null) {
            c.b8.g$d();
        }
    };
    FinancialPriceSeries.prototype.qm = function (a, b) {
        _super.prototype.qm.call(this, a, b);
        if (this.cy != null) {
            this.cy.mf();
        }
    };
    FinancialPriceSeries.prototype.ty = function (a, b) {
        if (this.t9 != null && this.t9.categoryMode == 0) {
            var c = this.getEffectiveViewport1(this.cj);
            var d = this.x9(this.uq, c) / 2;
            return new Thickness(1, d, 0, d, 0);
        }
        return _super.prototype.ty.call(this, a, b);
    };
    FinancialPriceSeries.prototype.get_du = function () {
        return true;
    };
    FinancialPriceSeries.prototype.xh = function (a, b) {
        _super.prototype.xh.call(this, a, b);
        if (this.t9 == null || this.uv == null) {
            return;
        }
        var c = false;
        if (b.b3(a)) {
            c = true;
            b.b5(a);
        }
        this.ui.a2(this, this.vh(), runOn(this, this.t1), this.v6(b), this.v8(b));
        var d = false;
        var e = this.ui.b;
        if (e != null) {
            d = true;
        }
        var f = typeCast(FinancialPriceSeriesView.$, b);
        f.cd();
        f.cb = false;
        if (f.ca) {
            f.b8.g$d();
        }
        if (this.trendLineType != 0) {
            f.b8.g$g(a.p);
        }
        if (d) {
            this.yv(a, b, c);
        }
        else {
            f.b9.count = 0;
            this.yu(a, b);
        }
    };
    FinancialPriceSeries.prototype.h0 = function () {
        var a = this.getEffectiveViewport1(this.cj);
        return this.x9(this.uq, a);
    };
    FinancialPriceSeries.prototype.yv = function (a, b, c) {
        var d = this.x5;
        var e = this.getEffectiveViewport1(b);
        var f = this.x9(b, e);
        var g = (f - 1) / 2;
        var h = typeCast(FinancialPriceSeriesView.$, b);
        h.cb = true;
        var i = a.f;
        var j = 0;
        var k = this.c6.count;
        var l = this.t9;
        var m = new ScalerParams(0, b.by, b.bx, l.ch, e);
        var n = this.ss;
        var o = this.xz;
        if (o == null) {
            o = n;
        }
        var p = this.sv;
        var q = this.zh;
        if (q == null) {
            q = p;
        }
        var _loop_1 = function (r) {
            var s = i._inner[r][0] - g;
            var t = i._inner[r][0];
            var u = i._inner[r][0] + g;
            var v = i._inner[r][1];
            var w = i._inner[r][2];
            var x = i._inner[r][3];
            var y = i._inner[r][4];
            if (isNaN_(v) || isNaN_(w) || isNaN_(x) || isNaN_(y)) {
                return "continue";
            }
            var z = h.b9.item(j);
            j++;
            var aa = v < y;
            var ab = new PathGeometry();
            if (c) {
                switch (d) {
                    case 0:
                        if (aa) {
                            var ac = v;
                            v = y;
                            y = ac;
                        }
                        var ad = new PathFigure();
                        ad._startPoint = { $type: Point_$type, x: t, y: x };
                        ad._segments.add(((function () {
                            var $ret = new LineSegment(1);
                            $ret.c = { $type: Point_$type, x: t, y: v };
                            return $ret;
                        })()));
                        var ae = new PathFigure();
                        ae._startPoint = { $type: Point_$type, x: s, y: y };
                        ae._segments.add(((function () {
                            var $ret = new LineSegment(1);
                            $ret.c = { $type: Point_$type, x: u, y: y };
                            return $ret;
                        })()));
                        ae._segments.add(((function () {
                            var $ret = new LineSegment(1);
                            $ret.c = { $type: Point_$type, x: u, y: v };
                            return $ret;
                        })()));
                        ae._segments.add(((function () {
                            var $ret = new LineSegment(1);
                            $ret.c = { $type: Point_$type, x: s, y: v };
                            return $ret;
                        })()));
                        ae._segments.add(((function () {
                            var $ret = new LineSegment(1);
                            $ret.c = { $type: Point_$type, x: s, y: y };
                            return $ret;
                        })()));
                        var af = new PathFigure();
                        af._startPoint = { $type: Point_$type, x: t, y: y };
                        af._segments.add(((function () {
                            var $ret = new LineSegment(1);
                            $ret.c = { $type: Point_$type, x: t, y: w };
                            return $ret;
                        })()));
                        ab.c.add(ad);
                        ab.c.add(ae);
                        ab.c.add(af);
                        break;
                    case 1:
                        var ag = new PathFigure();
                        ag._startPoint = { $type: Point_$type, x: s, y: v };
                        ag._segments.add(((function () {
                            var $ret = new LineSegment(1);
                            $ret.c = { $type: Point_$type, x: t, y: v };
                            return $ret;
                        })()));
                        var ah = new PathFigure();
                        ah._startPoint = { $type: Point_$type, x: t, y: x };
                        ah._segments.add(((function () {
                            var $ret = new LineSegment(1);
                            $ret.c = { $type: Point_$type, x: t, y: w };
                            return $ret;
                        })()));
                        var ai = new PathFigure();
                        ai._startPoint = { $type: Point_$type, x: t, y: y };
                        ai._segments.add(((function () {
                            var $ret = new LineSegment(1);
                            $ret.c = { $type: Point_$type, x: u, y: y };
                            return $ret;
                        })()));
                        ab.c.add(ag);
                        ab.c.add(ah);
                        ab.c.add(ai);
                        break;
                }
            }
            if (aa) {
                this_1.ui.ak = o;
                this_1.ui.ag = o;
                this_1.ui.ah = q;
                this_1.ui.al = q;
                this_1.ui.f = true;
            }
            else {
                this_1.ui.ak = n;
                this_1.ui.ag = n;
                this_1.ui.ah = p;
                this_1.ui.al = p;
                this_1.ui.f = false;
            }
            this_1.xe(i, r, k, l, m, b.q);
            if (d == 1) {
                this_1.ui.ad(z, true, false, false, false);
            }
            else {
                this_1.ui.ad(z, false, false, false, false);
            }
            if (c) {
                z.an = ab;
            }
        };
        var this_1 = this;
        for (var r = 0; r < i.count; ++r) {
            _loop_1(r);
        }
        h.b9.count = j;
        h.cf();
    };
    FinancialPriceSeries.prototype.x9 = function (a, b) {
        var c = this.t9.k4(a.by, a.bx, b);
        c = Math.max(c, this.hj * 0.9);
        c = Math.max(c, 3);
        return c;
    };
    FinancialPriceSeries.prototype.yu = function (a, b) {
        var c = this.x5;
        var d = this.getEffectiveViewport1(b);
        var e = this.x9(b, d);
        var f = (e - 1) / 2;
        var g = typeCast(FinancialPriceSeriesView.$, b);
        var h = g.cn();
        var i = g.cm();
        var j = a.f;
        var _loop_2 = function (k) {
            var l = j._inner[k][0] - f;
            var m = j._inner[k][0];
            var n = j._inner[k][0] + f;
            var o = j._inner[k][1];
            var p = j._inner[k][2];
            var q = j._inner[k][3];
            var r = j._inner[k][4];
            if (isNaN_(o) || isNaN_(p) || isNaN_(q) || isNaN_(r)) {
                return "continue";
            }
            var s = o < r;
            var t = s ? i : h;
            switch (c) {
                case 0:
                    if (s) {
                        var u = o;
                        o = r;
                        r = u;
                    }
                    t.d.add(((function () {
                        var $ret = new LineGeometry();
                        $ret.d = { $type: Point_$type, x: m, y: q };
                        $ret.c = { $type: Point_$type, x: m, y: o };
                        return $ret;
                    })()));
                    t.d.add(((function () {
                        var $ret = new RectangleGeometry();
                        $ret.e = new Rect(0, l, r, n - l, o - r);
                        return $ret;
                    })()));
                    t.d.add(((function () {
                        var $ret = new LineGeometry();
                        $ret.d = { $type: Point_$type, x: m, y: r };
                        $ret.c = { $type: Point_$type, x: m, y: p };
                        return $ret;
                    })()));
                    break;
                case 1:
                    t.d.add(((function () {
                        var $ret = new LineGeometry();
                        $ret.d = { $type: Point_$type, x: l, y: o };
                        $ret.c = { $type: Point_$type, x: m, y: o };
                        return $ret;
                    })()));
                    t.d.add(((function () {
                        var $ret = new LineGeometry();
                        $ret.d = { $type: Point_$type, x: m, y: q };
                        $ret.c = { $type: Point_$type, x: m, y: p };
                        return $ret;
                    })()));
                    t.d.add(((function () {
                        var $ret = new LineGeometry();
                        $ret.d = { $type: Point_$type, x: m, y: r };
                        $ret.c = { $type: Point_$type, x: n, y: r };
                        return $ret;
                    })()));
                    break;
            }
        };
        for (var k = 0; k < j.count; ++k) {
            _loop_2(k);
        }
    };
    FinancialPriceSeries.prototype.jy = function (a, b) {
        if (this.x4.ca && a == this.x4.b8.g$j) {
            return null;
        }
        return _super.prototype.jy.call(this, a, b);
    };
    FinancialPriceSeries.prototype.qd = function () {
        _super.prototype.qd.call(this);
        if (this.index < 0) {
            return;
        }
        this.x4.cl();
    };
    FinancialPriceSeries.prototype.n1 = function (a) {
        _super.prototype.n1.call(this, a);
        if (this.x4.ca) {
            this.a9.exportTrendlineData(this, a, this.x4.b8.g$j);
        }
    };
    FinancialPriceSeries.prototype.s4 = function () {
        return this.zh;
    };
    FinancialPriceSeries.prototype.pz = function (a, b) {
        _super.prototype.pz.call(this, a, b);
        this.zh = b;
    };
    FinancialPriceSeries.prototype.bb = function (a) {
        if (this.x5 == 0) {
            return 3;
        }
        else if (this.x5 == 1) {
            if (this.ba == 1) {
                return 3;
            }
            return 2;
        }
        return a;
    };
    FinancialPriceSeries.prototype.getDataLegendSeriesContextAt = function (a, b) {
        var c = { $type: Point_$type, x: a, y: b };
        var d = this.h7(c, false, false);
        var e = this.h5(c, false, false);
        var f = new DataLegendSeriesValueInfo();
        f.a = 4;
        f.l = this.v1(c, false, false);
        f.p = "Close";
        f.q = this.wd != null ? this.wd : "Close";
        f.r = this.yc != null ? this.yc : "C:";
        f.s = this.ye != null ? this.ye : "";
        var g = new DataLegendSeriesValueInfo();
        g.l = this.v2(c, false, false);
        g.a = 3;
        g.p = "Open";
        g.q = this.wz != null ? this.wz : "Open";
        g.r = this.yq != null ? this.yq : "O:";
        g.s = this.ys != null ? this.ys : "";
        g.k = true;
        var h = new DataLegendSeriesValueInfo();
        h.l = (f.l - g.l) / g.l * 100;
        h.l = round10N(h.l, 1);
        h.a = 9;
        h.p = "Change";
        h.q = "Change";
        h.r = "";
        h.u = "";
        h.w = "+";
        h.v = "%";
        h.x = "%";
        h.s = null;
        h.c = false;
        h.k = true;
        h.e = false;
        h.f = true;
        h.h = false;
        h.g = false;
        h.d = false;
        h.n = 1;
        h.m = 1;
        g.y = h.l >= 0 ? this.ss : this.xz;
        f.y = h.l >= 0 ? this.ss : this.xz;
        h.y = h.l >= 0 ? this.ss : this.xz;
        var i = new DataLegendSeriesValueInfo();
        i.l = e > d ? d : e;
        i.a = 1;
        i.p = "Low";
        i.q = this.wv != null ? this.wv : "Low";
        i.r = this.yl != null ? this.yl : "L:";
        i.s = this.yn != null ? this.yn : "";
        i.k = true;
        var j = new DataLegendSeriesValueInfo();
        j.l = e > d ? e : d;
        j.a = 2;
        j.p = "High";
        j.q = this.wq != null ? this.wq : "High";
        j.r = this.yh != null ? this.yh : "H:";
        j.s = this.yj != null ? this.yj : "";
        j.k = true;
        var k = new DataLegendSeriesValueInfo();
        k.l = (j.l + i.l + f.l) / 3;
        k.l = round10N(k.l, 2);
        k.a = 5;
        k.p = "TypicalPrice";
        k.q = "TypicalPrice";
        k.r = "TP:";
        k.s = "";
        k.k = true;
        var l = new DataLegendSeriesValueInfo();
        l.l = this.v3(c, false, false);
        l.a = 8;
        l.p = "Volume";
        l.q = this.w3 != null ? this.w3 : "Volume";
        l.r = "VOL:";
        l.s = "";
        l.k = true;
        l.n = 0;
        l.m = 0;
        l.e = false;
        l.f = false;
        l.h = false;
        var m = new List$1(DataLegendSeriesValueInfo.$, 0);
        m.add(g);
        m.add(j);
        m.add(i);
        m.add(f);
        m.add(k);
        m.add(h);
        m.add(l);
        var n = new DataLegendSeriesContext();
        n.b = this.aw();
        n.f = m;
        return n;
    };
    FinancialPriceSeries.prototype.yw = function () {
        if (this.x6) {
            this.x7 = 0;
            for (var a = 0; a < this.u3.count; a++) {
                var b = 0;
                b += this.u3.item(a);
                b += this.u4.item(a);
                b += this.u2.item(a);
                this.x7 += b / 3;
            }
            this.x8 = this.x7 / this.u3.count;
            this.x6 = false;
        }
    };
    FinancialPriceSeries.prototype.am = function (a) {
        var b = NaN;
        switch (a) {
            case 2:
                b = this.u3.maximum;
                break;
            case 1:
                b = this.u4.minimum;
                break;
            case 3:
                if (this.x6) {
                    this.yw();
                }
                b = this.x8;
                break;
        }
        var c = this.uv;
        if (c.cp) {
            return [NaN, b];
        }
        else {
            return [b, NaN];
        }
    };
    FinancialPriceSeries.prototype.tk = function (a) {
        var b = NaN;
        switch (a) {
            case 2:
                b = this.u3.maximum;
                break;
            case 1:
                b = this.u4.minimum;
                break;
            case 3:
                if (this.x6) {
                    this.yw();
                }
                b = this.x8;
                break;
        }
        if (isNaN_(b)) {
            return { $type: Point_$type, x: NaN, y: NaN };
        }
        var c = this.uv;
        var d = this.getEffectiveViewport1(this.cj);
        var e = new ScalerParams(0, this.cj.by, this.cj.bx, c.ch, d);
        if (c.cp) {
            e.b = this.h2();
        }
        e.c = d;
        if (c.cp) {
            return { $type: Point_$type, x: NaN, y: c.ej(b, e) };
        }
        else {
            return { $type: Point_$type, x: c.ej(b, e), y: NaN };
        }
    };
    FinancialPriceSeries.prototype.tl = function (a) {
        var b = this.uv;
        var c = this.getEffectiveViewport1(this.cj);
        var d = new ScalerParams(0, this.cj.by, this.cj.bx, b.ch, c);
        if (b.cp) {
            d.b = this.h2();
        }
        d.c = c;
        if (b.cp) {
            return { $type: Point_$type, x: NaN, y: b.ej(a[1], d) };
        }
        else {
            return { $type: Point_$type, x: b.ej(a[0], d), y: NaN };
        }
    };
    FinancialPriceSeries.$t = markType(FinancialPriceSeries, 'FinancialPriceSeries', FinancialSeries.$, [ITrendLineSeries_$type]);
    FinancialPriceSeries.yy = DependencyProperty.i("ActualTrendLineBrush", Brush.$, FinancialPriceSeries.$, new PropertyMetadata(2, null, function (a, b) { return a.raisePropertyChanged("ActualTrendLineBrush", b.oldValue, b.newValue); }));
    FinancialPriceSeries.$$p = markDep(DependencyProperty, PropertyMetadata, FinancialPriceSeries, 'raisePropertyChanged', ['CloseMemberAsLegendLabel:yc:yz', [2, null], 'CloseMemberAsLegendUnit:ye:y0', [2, null], 'DisplayType:x5:y1', [PriceDisplayType_$type, enumGetBox(PriceDisplayType_$type, 0)], 'HighMemberAsLegendLabel:yh:y2', [2, null], 'HighMemberAsLegendUnit:yj:y3', [2, null], 'LowMemberAsLegendLabel:yl:y4', [2, null], 'LowMemberAsLegendUnit:yn:y5', [2, null], 'NegativeOutline:zh:y6', [Brush.$, null], 'OpenMemberAsLegendLabel:yq:y7', [2, null], 'OpenMemberAsLegendUnit:ys:y8', [2, null], 'TrendLineType::ze', [TrendLineType_$type, enumGetBox(TrendLineType_$type, 0)], 'TrendLineThickness::zd', [1, 1.5], 'TrendLinePeriod::zc', [1, 7], 'TrendLineBrush::y9', [Brush.$, null], 'TrendLineZIndex:yb:zf', [1, 1001], 'TrendLineDashArray:zi:za', [DoubleCollection.$], 'TrendLineDashCap:zj:zb', [PenLineCap_$type, enumGetBox(PenLineCap_$type, 0)]]);
    return FinancialPriceSeries;
}(FinancialSeries));
export { FinancialPriceSeries };
/**
 * @hidden
 */
var FinancialPriceSeriesView = /** @class */ /*@__PURE__*/ (function (_super) {
    __extends(FinancialPriceSeriesView, _super);
    function FinancialPriceSeriesView(a) {
        var _this = _super.call(this, a) || this;
        _this.b6 = null;
        _this.b9 = null;
        _this.cc = null;
        _this.cq = ((function () {
            var $ret = new Path();
            $ret.an = new GeometryGroup();
            return $ret;
        })());
        _this.cp = ((function () {
            var $ret = new Path();
            $ret.an = new GeometryGroup();
            return $ret;
        })());
        _this.b7 = null;
        _this.co = new Path();
        _this.cb = false;
        _this.b6 = a;
        _this.cc = new List$1(Path.$, 0);
        _this.b9 = ((function () {
            var $ret = new Pool$1(Path.$);
            $ret.create = runOn(_this, _this.cr);
            $ret.activate = runOn(_this, _this.ch);
            $ret.disactivate = runOn(_this, _this.cj);
            $ret.destroy = runOn(_this, _this.ci);
            return $ret;
        })());
        return _this;
    }
    FinancialPriceSeriesView.prototype.cr = function () {
        var a = new Path();
        this.cc.add(a);
        a._visibility = 1;
        return a;
    };
    FinancialPriceSeriesView.prototype.ch = function (a) {
        a._visibility = 0;
    };
    FinancialPriceSeriesView.prototype.cj = function (a) {
        a._visibility = 1;
    };
    FinancialPriceSeriesView.prototype.ci = function (a) {
        this.cc.remove(a);
    };
    FinancialPriceSeriesView.prototype.b1 = function () {
        return new FinancialPriceBucketCalculator(this);
    };
    FinancialPriceSeriesView.prototype.au = function () {
        _super.prototype.au.call(this);
        if (!this.q) {
            this.b6.x5 = Defaults.g;
            this.b6.xz = Defaults.ah;
            this.b6.zh = Defaults.ai;
            this.b6.iu = Defaults.l;
            this.b6.s2 = this.b6.sv;
        }
    };
    Object.defineProperty(FinancialPriceSeriesView.prototype, "b8", {
        get: function () {
            if (this.b7 == null) {
                this.b7 = CategoryTrendLineManagerFactory.a(this.b7, this.e.as(), this.e.qr, this.e, this.e.c9);
            }
            return this.b7;
        },
        set: function (a) {
            this.b7 = a;
        },
        enumerable: false,
        configurable: true
    });
    Object.defineProperty(FinancialPriceSeriesView.prototype, "ca", {
        get: function () {
            return this.b7 != null;
        },
        enumerable: false,
        configurable: true
    });
    FinancialPriceSeriesView.prototype.ck = function () {
        if (this.b6.x5 == 1) {
            this.cq._stroke = this.e.ss;
        }
        else {
            this.cq._stroke = this.e.sv;
        }
        if (this.b6.x5 == 1) {
            this.cp._stroke = this.b2.xz;
        }
        else {
            this.cp._stroke = this.b6.zh;
        }
    };
    FinancialPriceSeriesView.prototype.ce = function () {
        this.as();
        this.b9.count = 0;
        this.cd();
    };
    FinancialPriceSeriesView.prototype.cd = function () {
        var a = typeCast(GeometryGroup.$, this.cq.an);
        var b = typeCast(GeometryGroup.$, this.cp.an);
        Extensions.d(a);
        Extensions.d(b);
    };
    FinancialPriceSeriesView.prototype.cn = function () {
        this.as();
        return typeCast(GeometryGroup.$, this.cq.an);
    };
    FinancialPriceSeriesView.prototype.cm = function () {
        this.as();
        return typeCast(GeometryGroup.$, this.cp.an);
    };
    FinancialPriceSeriesView.prototype.cl = function () {
        this.b6.zg = null;
        if (this.b6.trendLineBrush != null) {
            this.b6.zg = this.b6.trendLineBrush;
        }
        else {
            this.b6.zg = this.b6.ss;
        }
    };
    FinancialPriceSeriesView.prototype.bd = function () {
        _super.prototype.bd.call(this);
        this.cq.ad = this.e.hk;
        this.cq.ai = this.e.s7;
        this.cq.aj = this.e.s8;
        if (this.b6.x5 == 1) {
            this.cq._stroke = this.e.ss;
        }
        else {
            this.cq._stroke = this.e.sv;
            this.cq._fill = this.e.ss;
        }
        this.cp.ad = this.e.hk;
        this.cp.ai = this.e.s7;
        this.cp.aj = this.e.s8;
        if (this.b6.x5 == 1) {
            this.cp._stroke = this.b2.xz;
        }
        else {
            this.cp._stroke = this.b6.zh;
            this.cp._fill = this.b2.xz;
        }
    };
    FinancialPriceSeriesView.prototype.be = function () {
        _super.prototype.be.call(this);
        var a = this.br();
        this.cq.ad = this.e.hk + 3;
        if (this.b6.x5 == 1) {
            this.cq._stroke = a;
        }
        else {
            this.cq._stroke = a;
            this.cq._fill = a;
        }
        this.cp.ad = this.e.hk + 3;
        if (this.b6.x5 == 1) {
            this.cp._stroke = a;
        }
        else {
            this.cp._stroke = a;
            this.cp._fill = a;
        }
    };
    FinancialPriceSeriesView.prototype.ac = function (a) {
        return this.cc._inner[a];
    };
    FinancialPriceSeriesView.prototype.ab = function (a) {
        var b = this.cc._inner[a];
        this.co._visibility = b._visibility;
        this.co.an = b.an;
        var c = this.bs(a);
        this.co._fill = c;
        this.co._stroke = c;
        this.co.ad = this.e.hk + 3;
        return this.co;
    };
    FinancialPriceSeriesView.prototype.a8 = function (a, b) {
        _super.prototype.a8.call(this, a, b);
        if (a.d) {
            if (this.cb) {
                for (var c = 0; c < this.cc.count; c++) {
                    var d = this.aa(c, b);
                    if (d._visibility == 0) {
                        a.t(d);
                    }
                }
            }
            else {
                a.t(this.cq);
                a.t(this.cp);
            }
        }
    };
    FinancialPriceSeriesView.prototype.a7 = function (a, b) {
        if (a.d) {
            if (this.b6.trendLineType != 0 && !b) {
                var c = this.b8.g$j;
                c.ad = this.b6.trendLineThickness;
                c._stroke = this.b6.zg;
                c.ai = this.b6.zi;
                c.aj = this.b6.zj;
                a.v(c);
            }
        }
        _super.prototype.a7.call(this, a, b);
    };
    FinancialPriceSeriesView.prototype.an = function (a) {
        _super.prototype.an.call(this, a);
        if (this.b6.vh()) {
            for (var b = 0; b < this.cc.count; b++) {
                var c = this.cc._inner[b];
                if (c._fill == this.b6.xz) {
                    this.e.a9.exportPathData(a, c, "negativePathShape" + b, ["Negative"]);
                }
                else {
                    this.e.a9.exportPathData(a, c, "positivePathShape" + b, ["Positive", "Main"]);
                }
            }
        }
        else {
            this.e.a9.exportPathData(a, this.cq, "positivePathShape", ["Positive", "Main"]);
            this.e.a9.exportPathData(a, this.cp, "negativePathShape", ["Negative"]);
        }
    };
    FinancialPriceSeriesView.prototype.cf = function () {
        this.as();
    };
    FinancialPriceSeriesView.prototype.cg = function () {
        if (this.ca) {
            this.b7 = CategoryTrendLineManagerFactory.a(this.b7, this.e.as(), this.e.qr, this.e, this.e.c9);
        }
    };
    FinancialPriceSeriesView.$t = markType(FinancialPriceSeriesView, 'FinancialPriceSeriesView', FinancialSeriesView.$);
    return FinancialPriceSeriesView;
}(FinancialSeriesView));
export { FinancialPriceSeriesView };
