/*
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 { CategoryCollisionMode_$type } from "./CategoryCollisionMode";
import { Series } from "./Series";
import { Defaults } from "./Defaults";
import { enumGetBox, EnumUtil, Number_$type, 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 { ChartSelection } from "./ChartSelection";
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.aa2 = true;
        _this.aa3 = 0;
        _this.aa4 = 0;
        _this.ab = FinancialPriceSeries.$;
        _this.w8 = new CategoryFrame(5);
        _this.xa = new CategoryFrame(5);
        _this.w6 = new CategoryFrame(5);
        return _this;
    }
    FinancialPriceSeries.prototype.bj = function () {
        return new FinancialPriceSeries();
    };
    FinancialPriceSeries.prototype.get_e9 = function () {
        return true;
    };
    FinancialPriceSeries.prototype.jk = function () {
        if (!isNaN_(this.jj)) {
            return _super.prototype.jk.call(this);
        }
        return Defaults.k;
    };
    FinancialPriceSeries.prototype.cs = function () {
        return new FinancialPriceSeriesView(this);
    };
    FinancialPriceSeries.prototype.qz = function (a) {
        _super.prototype.qz.call(this, a);
        this.aa0 = a;
    };
    Object.defineProperty(FinancialPriceSeries.prototype, "acj", {
        get: function () {
            return this.c(FinancialPriceSeries.ab0);
        },
        set: function (a) {
            this.h(FinancialPriceSeries.ab0, a);
        },
        enumerable: false,
        configurable: true
    });
    FinancialPriceSeries.prototype.pb = function (a, b, c, d) {
        _super.prototype.pb.call(this, a, b, c, d);
        if (this.w4 != null && typeCast(ISortingAxis_$type, this.w4) !== null) {
            this.w4.i$i();
        }
        this.aa0.b0.e(this.id);
        if (this.aa0.ca) {
            this.aa0.b8.g$e(a, b, c, d);
        }
        if (this.xn != null) {
            this.xn.c1();
        }
        this.rp(true);
        if (a == 0 || a == 2 || a == 3 || a == 4) {
            this.aa2 = true;
        }
        else if (a == 1) {
            for (var e = b; e < b + c; e++) {
                var f = 0;
                f += this.xy.item(e);
                f += this.xz.item(e);
                f += this.xx.item(e);
                this.aa3 += f / 3;
            }
            this.aa4 = this.aa3 / this.xy.count;
        }
    };
    FinancialPriceSeries.prototype.b2 = function () {
        if (this.b3 == 0) {
            return 1;
        }
        else {
            return _super.prototype.b2.call(this);
        }
    };
    FinancialPriceSeries.prototype.wl = function (a) {
        if (this.w6 == null || this.w6.f.count == 0) {
            return Rect.empty;
        }
        var b = this.v5(a);
        var c = this.cv.by;
        var d = this.cv.bx;
        var e = this.getEffectiveViewport1(this.cv);
        var f = this.an(this.w4, this.w6.f, this.y1(this.cv), this.y3(this.cv), 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.aa5(this.xl, 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.aay = 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.aa1 == 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.ao = function (a) {
        var b = new List$1(Rect.$, 0);
        var c = this.v5(a);
        var d = this.cv.by;
        var e = this.cv.bx;
        var f = this.getEffectiveViewport1(this.cv);
        var g = this.an(this.w4, this.w6.f, this.y1(this.cv), this.y3(this.cv), 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.aa5(this.xl, f);
        l = Math.max(l, 3);
        var m = (l - 1) / 2;
        if (j < k) {
            return this.aay(h, m);
        }
        else {
            return this.aay(i, m);
        }
    };
    FinancialPriceSeries.prototype.gw = function (a, b) {
        if (this.gz(a, b)) {
            return true;
        }
        return false;
    };
    FinancialPriceSeries.prototype.gz = function (a, b) {
        var c = this.wm(a);
        if (c.isEmpty) {
            return false;
        }
        var d = RectUtil.r(c, (this.ie / 2) + this.iu(b));
        if (d.containsPoint(a)) {
            var e = this.ap(a);
            if (e != null) {
                for (var f = 0; f < e.length; f++) {
                    var g = e[f];
                    var h = RectUtil.r(g, (this.ie / 2) + this.iu(b));
                    if (h.containsPoint(a)) {
                        return true;
                    }
                }
            }
        }
        return false;
    };
    FinancialPriceSeries.prototype.q7 = function (a, b, c, d) {
        switch (b) {
            case FinancialPriceSeries.$$p[4]:
            case FinancialPriceSeries.$$p[5]:
            case FinancialPriceSeries.$$p[6]:
            case FinancialPriceSeries.$$p[7]:
            case FinancialPriceSeries.$$p[1]:
            case FinancialPriceSeries.$$p[2]:
            case FinancialPriceSeries.$$p[9]:
            case FinancialPriceSeries.$$p[10]:
                this.qd();
                break;
            case FinancialSeries.$$p[14]:
                this.aa0.cg();
                if (this.db != null) {
                    this.db.n2();
                }
                break;
            case "TrendLineType":
                var e = EnumUtil.getEnumValue(TrendLineType_$type, d);
                if (e != 0) {
                    this.aa0.b8 = CategoryTrendLineManagerFactory.a(this.aa0.b8, this.w4, this.st, this, this.dr);
                }
                break;
        }
        _super.prototype.q7.call(this, a, b, c, d);
        if (this.aa0.ca && this.aa0.b8 != null && this.aa0.b8.g$b(a, b, c, d)) {
            this.rp(false);
            this.qj();
        }
        switch (b) {
            case FinancialPriceSeries.$$p[3]:
                if (this.st != null) {
                    this.abz();
                    this.sg();
                    this.w6.x();
                    this.aac(this.w6, this.aa0);
                }
                this.qj();
                break;
            case "ActualHighlightingMode":
            case "ActualSelectionMode":
            case "ActualFocusMode":
                this.rp(true);
                break;
            case "TrendLineBrush":
                this.rd(b);
                break;
            case "TrendLineType":
                this.qj();
                break;
            case FinancialSeries.$$p[10]:
            case FinancialPriceSeries.$$p[8]:
                this.q1();
                break;
        }
    };
    FinancialPriceSeries.prototype.abz = function () {
        this.aa0.ck();
        if (this.cu != null) {
            this.cu.ck();
        }
    };
    FinancialPriceSeries.prototype.ay = function (a) {
        if (a != null && a == this.xn && this.xz != null && !isNaN_(this.xz.minimum) && this.xy != null && !isNaN_(this.xy.maximum)) {
            return new AxisRange(this.xz.minimum, this.xy.maximum);
        }
        return null;
    };
    FinancialPriceSeries.prototype.az = function (a) {
        if (a.isEmpty && this.db != null) {
            a = this.db.v4;
        }
        if (this.xz == null || this.xy == null) {
            return null;
        }
        var b = this.wh(this.cv);
        var c = new ScalerParams(0, a, this.db.wj, this.w4.ch, this.getEffectiveViewport());
        var d = (this.w4.eo(b.left, c));
        var e = (this.w4.eo(b.right, c));
        if (this.w4.ch) {
            var f = d;
            d = e;
            e = f;
        }
        var g = null;
        if (this.w4.cn) {
            g = this.w4;
            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.xz.count - 1, d));
        e = Math.max(0, Math.min(this.xz.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.xz.item(k);
            if (this.xz.mayContainUnknowns) {
                if (isInfinity(l) || isNaN_(l)) {
                    continue;
                }
            }
            var m = this.xy.item(k);
            if (this.xy.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.ax(n, this.xn, a);
        return n;
    };
    FinancialPriceSeries.prototype.iy = function () {
        return Series.iz(this.x0, typeCast(ISortingAxis_$type, this.w4));
    };
    FinancialPriceSeries.prototype.gd = function (a) {
        var b = this.dn != null ? this.dn.indexOf(a) : -1;
        var c = this.cv.by;
        c = c.copy();
        var d = this.cv.bx;
        var e = new Rect(0, 0, 0, 1, 1);
        var f = this.wj(this.cv);
        if (b >= 0 && Rect.l_op_Inequality(c, null) && Rect.l_op_Inequality(d, null)) {
            if (this.w4 != null) {
                var g = new ScalerParams(0, e, e, this.w4.ch, f);
                var h = this.w4.el(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.xn != null && this.xz != null && this.xy != null && b < this.xz.count && b < this.xy.count) {
                var i = new ScalerParams(0, e, e, this.xn.ch, f);
                i.b = this.iy();
                var j = this.xn.el(this.xz.item(b), i);
                var k = this.xn.el(this.xy.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.c3.au(this.db, c, true);
        }
        return b >= 0;
    };
    FinancialPriceSeries.prototype.he = function (a, b, c) {
        var d = _super.prototype.he.call(this, a, b, c);
        if (this.x0 == null || this.xx == null || this.xy == null || this.xz == null) {
            d = false;
        }
        return d;
    };
    FinancialPriceSeries.prototype.aaa = function (a, b) {
        var e_1, _a;
        var _this = this;
        _super.prototype.aaa.call(this, a, b);
        var c = b.by;
        var d = b.bx;
        var e = this.getEffectiveViewport1(b);
        var f = this.w4;
        var g = this.xn;
        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.iy();
            return $ret;
        })());
        var j = this.w4.ag();
        var k = j[0];
        var l = j[1];
        a.f.clear();
        if (a.m != null) {
            a.m.clear();
        }
        a.n.clear();
        a.q.clear();
        var m = 0;
        var n = typeCast(ISortingAxis_$type, this.w4);
        if (n != null && (n.i$b == null || n.i$b.count != this.dn.count)) {
            return;
        }
        m = this.yv(c, d, e);
        var o = typeCast(FinancialPriceSeriesView.$, b);
        var p = this.id;
        var q = b.b0.b;
        if (this.trendLineType != 0) {
            var r = new Array(this.dn.count);
            var s = 0;
            try {
                for (var _b = __values(fromEnum(this.ym)), _c = _b.next(); !_c.done; _c = _b.next()) {
                    var t = _c.value;
                    r[s] = t;
                    s++;
                }
            }
            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.aa0.ca) {
                this.aa0.b8.prepareLineCore(a.q, this.trendLineType, boxArray$1(r), this.trendLinePeriod, function (u) { return _this.w4.el(u, h); }, function (u) { return _this.xn.el(u, 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.i = d;
                    $ret.h = e;
                    $ret.c = k;
                    $ret.b = l;
                    return $ret;
                })()));
            }
        }
        var u = this.w4.eo(2, h) - this.w4.eo(1, h);
        for (var v = b.b0.c; v <= b.b0.d; ++v) {
            var w = void 0;
            var x = v * q;
            if (n == null) {
                w = b.b0.getBucket(v);
            }
            else {
                var y = n.i$b._inner[v];
                x = y;
                var z = n.i$d(y);
                var aa = this.x0.item(y);
                var ab = this.xy.item(y);
                var ac = this.xz.item(y);
                var ad = this.xx.item(y);
                var ae = aa;
                var af = ab;
                var ag = ac;
                var ah = ad;
                var ai = z;
                while (v < b.b0.d) {
                    y = n.i$b._inner[v + 1];
                    ai = n.i$d(y);
                    if (ai - z > u * p) {
                        break;
                    }
                    x = y;
                    v++;
                    af = Math.max(af, this.xy.item(y));
                    ag = Math.min(ag, this.xz.item(y));
                    ah = this.xx.item(y);
                }
                var aj = NaN;
                if (!isNaN_(z)) {
                    aj = this.w4.el(z, h);
                }
                w = [aj, ae, af, ag, ah];
            }
            if (!isNaN_(w[0])) {
                if (n != null) {
                    w[0] = w[0] + m;
                }
                else {
                    w[0] = f.el(w[0], h) + m;
                }
                w[1] = g.el(w[1], i);
                w[2] = g.el(w[2], i);
                w[3] = g.el(w[3], i);
                w[4] = g.el(w[4], i);
                if (n != null) {
                    if (a.m == null) {
                        a.m = new List$1(Number_$type, 0);
                    }
                    a.m.add(x);
                }
                a.f.add(w);
            }
        }
        return;
    };
    FinancialPriceSeries.prototype.o5 = function (a, b) {
        _super.prototype.o5.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.so = function (a, b) {
        _super.prototype.so.call(this, a, b);
        if (this.db != null) {
            this.db.n2();
        }
    };
    FinancialPriceSeries.prototype.wt = function (a, b) {
        if (this.w4 != null && this.w4.categoryMode == 0) {
            var c = this.getEffectiveViewport1(this.cv);
            var d = this.aa5(this.xl, c) / 2;
            return new Thickness(1, d, 0, d, 0);
        }
        return _super.prototype.wt.call(this, a, b);
    };
    FinancialPriceSeries.prototype.get_ed = function () {
        return true;
    };
    FinancialPriceSeries.prototype.aac = function (a, b) {
        _super.prototype.aac.call(this, a, b);
        if (this.w4 == null || this.xn == null) {
            return;
        }
        var c = false;
        if (b.b3(a)) {
            c = true;
            b.b5(a);
        }
        this.xd.a2(this, this.yc(), runOn(this, this.ww), this.y1(b), this.y3(b));
        var d = false;
        var e = this.xd.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.q);
        }
        if (d) {
            this.abx(a, b, c);
        }
        else {
            f.b9.count = 0;
            this.abw(a, b);
        }
    };
    FinancialPriceSeries.prototype.iw = function () {
        var a = this.getEffectiveViewport1(this.cv);
        return this.aa5(this.xl, a);
    };
    FinancialPriceSeries.prototype.abx = function (a, b, c) {
        var d = this.aa1;
        var e = this.getEffectiveViewport1(b);
        var f = this.aa5(b, e);
        var g = (f - 1) / 2;
        var h = typeCast(ISortingAxis_$type, this.w4) !== null;
        var i = typeCast(FinancialPriceSeriesView.$, b);
        i.cb = true;
        var j = a.f;
        var k = 0;
        var l = this.dn.count;
        var m = this.w4;
        var n = new ScalerParams(0, b.by, b.bx, m.ch, e);
        var o = this.u7;
        var p = this.aau;
        if (p == null) {
            p = o;
        }
        var q = this.vb;
        var r = this.ack;
        if (r == null) {
            r = q;
        }
        var _loop_1 = function (s) {
            var t = j._inner[s][0] - g;
            var u = j._inner[s][0];
            var v = j._inner[s][0] + g;
            var w = j._inner[s][1];
            var x = j._inner[s][2];
            var y = j._inner[s][3];
            var z = j._inner[s][4];
            if (isNaN_(w) || isNaN_(x) || isNaN_(y) || isNaN_(z)) {
                return "continue";
            }
            var aa = i.b9.item(k);
            k++;
            var ab = w < z;
            var ac = new PathGeometry();
            if (c) {
                switch (d) {
                    case 0:
                        if (ab) {
                            var ad = w;
                            w = z;
                            z = ad;
                        }
                        var ae = new PathFigure();
                        ae._startPoint = { $type: Point_$type, x: u, y: y };
                        ae._segments.add(((function () {
                            var $ret = new LineSegment(1);
                            $ret.c = { $type: Point_$type, x: u, y: w };
                            return $ret;
                        })()));
                        var af = new PathFigure();
                        af._startPoint = { $type: Point_$type, x: t, y: z };
                        af._segments.add(((function () {
                            var $ret = new LineSegment(1);
                            $ret.c = { $type: Point_$type, x: v, y: z };
                            return $ret;
                        })()));
                        af._segments.add(((function () {
                            var $ret = new LineSegment(1);
                            $ret.c = { $type: Point_$type, x: v, y: w };
                            return $ret;
                        })()));
                        af._segments.add(((function () {
                            var $ret = new LineSegment(1);
                            $ret.c = { $type: Point_$type, x: t, y: w };
                            return $ret;
                        })()));
                        af._segments.add(((function () {
                            var $ret = new LineSegment(1);
                            $ret.c = { $type: Point_$type, x: t, y: z };
                            return $ret;
                        })()));
                        var ag = new PathFigure();
                        ag._startPoint = { $type: Point_$type, x: u, y: z };
                        ag._segments.add(((function () {
                            var $ret = new LineSegment(1);
                            $ret.c = { $type: Point_$type, x: u, y: x };
                            return $ret;
                        })()));
                        ac.c.add(ae);
                        ac.c.add(af);
                        ac.c.add(ag);
                        break;
                    case 1:
                        var ah = new PathFigure();
                        ah._startPoint = { $type: Point_$type, x: t, y: w };
                        ah._segments.add(((function () {
                            var $ret = new LineSegment(1);
                            $ret.c = { $type: Point_$type, x: u, y: w };
                            return $ret;
                        })()));
                        var ai = new PathFigure();
                        ai._startPoint = { $type: Point_$type, x: u, y: y };
                        ai._segments.add(((function () {
                            var $ret = new LineSegment(1);
                            $ret.c = { $type: Point_$type, x: u, y: x };
                            return $ret;
                        })()));
                        var aj = new PathFigure();
                        aj._startPoint = { $type: Point_$type, x: u, y: z };
                        aj._segments.add(((function () {
                            var $ret = new LineSegment(1);
                            $ret.c = { $type: Point_$type, x: v, y: z };
                            return $ret;
                        })()));
                        ac.c.add(ah);
                        ac.c.add(ai);
                        ac.c.add(aj);
                        break;
                }
            }
            if (ab) {
                this_1.xd.ak = p;
                this_1.xd.ag = p;
                this_1.xd.ah = r;
                this_1.xd.al = r;
                this_1.xd.f = true;
            }
            else {
                this_1.xd.ak = o;
                this_1.xd.ag = o;
                this_1.xd.ah = q;
                this_1.xd.al = q;
                this_1.xd.f = false;
            }
            var ak = this_1.xd.aw(l, s)[0];
            if (h && a.m != null && s >= 0 && s < a.m.count) {
                ak = truncate(Math.round(a.m._inner[s]));
            }
            this_1.z9(j, s, l, m, n, b.q, ak);
            if (d == 1) {
                this_1.xd.ad(aa, true, false, false, false);
            }
            else {
                this_1.xd.ad(aa, false, false, false, false);
            }
            if (c) {
                aa.an = ac;
            }
        };
        var this_1 = this;
        for (var s = 0; s < j.count; ++s) {
            _loop_1(s);
        }
        i.b9.count = k;
        i.cf();
    };
    FinancialPriceSeries.prototype.aa5 = function (a, b) {
        var c = this.w4.k8(a.by, a.bx, b);
        c = Math.max(c, this.id * 0.9);
        c = Math.max(c, 3);
        return c;
    };
    FinancialPriceSeries.prototype.abw = function (a, b) {
        var c = this.aa1;
        var d = this.getEffectiveViewport1(b);
        var e = this.aa5(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.kx = function (a, b) {
        if (this.aa0.ca && a == this.aa0.b8.g$j) {
            return null;
        }
        return _super.prototype.kx.call(this, a, b);
    };
    FinancialPriceSeries.prototype.sf = function () {
        _super.prototype.sf.call(this);
        if (this.index < 0) {
            return;
        }
        this.aa0.cl();
    };
    FinancialPriceSeries.prototype.px = function (a) {
        _super.prototype.px.call(this, a);
        if (this.aa0.ca) {
            this.bc.exportTrendlineData(this, a, this.aa0.b8.g$j);
        }
    };
    FinancialPriceSeries.prototype.vv = function () {
        return this.ack;
    };
    FinancialPriceSeries.prototype.r1 = function (a, b) {
        _super.prototype.r1.call(this, a, b);
        this.ack = b;
    };
    FinancialPriceSeries.prototype.be = function (a) {
        if (this.aa1 == 0) {
            return 3;
        }
        else if (this.aa1 == 1) {
            if (this.bd == 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.i3(c, false, false);
        var e = this.i1(c, false, false);
        var f = new DataLegendSeriesValueInfo();
        f.a = 4;
        f.l = this.yw(c, false, false);
        f.q = "Close";
        f.r = this.y8 != null ? this.y8 : "Close";
        f.s = this.aa9 != null ? this.aa9 : "C:";
        f.t = this.abb != null ? this.abb : "";
        var g = new DataLegendSeriesValueInfo();
        g.l = this.yx(c, false, false);
        g.a = 3;
        g.q = "Open";
        g.r = this.zu != null ? this.zu : "Open";
        g.s = this.abn != null ? this.abn : "O:";
        g.t = this.abp != null ? this.abp : "";
        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.q = "Change";
        h.r = "Change";
        h.s = "";
        h.v = "";
        h.x = "+";
        h.w = "%";
        h.y = "%";
        h.t = 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.z = h.l >= 0 ? this.u7 : this.aau;
        f.z = h.l >= 0 ? this.u7 : this.aau;
        h.z = h.l >= 0 ? this.u7 : this.aau;
        var i = new DataLegendSeriesValueInfo();
        i.l = e > d ? d : e;
        i.a = 1;
        i.q = "Low";
        i.r = this.zq != null ? this.zq : "Low";
        i.s = this.abi != null ? this.abi : "L:";
        i.t = this.abk != null ? this.abk : "";
        i.k = true;
        var j = new DataLegendSeriesValueInfo();
        j.l = e > d ? e : d;
        j.a = 2;
        j.q = "High";
        j.r = this.zl != null ? this.zl : "High";
        j.s = this.abe != null ? this.abe : "H:";
        j.t = this.abg != null ? this.abg : "";
        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.q = "TypicalPrice";
        k.r = "TypicalPrice";
        k.s = "TP:";
        k.t = "";
        k.k = true;
        var l = new DataLegendSeriesValueInfo();
        l.l = this.yy(c, false, false);
        l.a = 8;
        l.q = "Volume";
        l.r = this.zy != null ? this.zy : "Volume";
        l.s = "VOL:";
        l.t = "";
        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.h = this.mc();
        n.e = m;
        return n;
    };
    FinancialPriceSeries.prototype.aby = function () {
        if (this.aa2) {
            this.aa3 = 0;
            for (var a = 0; a < this.xy.count; a++) {
                var b = 0;
                b += this.xy.item(a);
                b += this.xz.item(a);
                b += this.xx.item(a);
                this.aa3 += b / 3;
            }
            this.aa4 = this.aa3 / this.xy.count;
            this.aa2 = false;
        }
    };
    FinancialPriceSeries.prototype.aq = function (a) {
        var b = NaN;
        switch (a) {
            case 2:
                b = this.xy.maximum;
                break;
            case 1:
                b = this.xz.minimum;
                break;
            case 3:
                if (this.aa2) {
                    this.aby();
                }
                b = this.aa4;
                break;
        }
        var c = this.xn;
        if (c.cp) {
            return [NaN, b];
        }
        else {
            return [b, NaN];
        }
    };
    FinancialPriceSeries.prototype.wd = function (a) {
        var b = NaN;
        switch (a) {
            case 2:
                b = this.xy.maximum;
                break;
            case 1:
                b = this.xz.minimum;
                break;
            case 3:
                if (this.aa2) {
                    this.aby();
                }
                b = this.aa4;
                break;
        }
        if (isNaN_(b)) {
            return { $type: Point_$type, x: NaN, y: NaN };
        }
        var c = this.xn;
        var d = this.getEffectiveViewport1(this.cv);
        var e = new ScalerParams(0, this.cv.by, this.cv.bx, c.ch, d);
        if (c.cp) {
            e.b = this.iy();
        }
        e.c = d;
        if (c.cp) {
            return { $type: Point_$type, x: NaN, y: c.el(b, e) };
        }
        else {
            return { $type: Point_$type, x: c.el(b, e), y: NaN };
        }
    };
    FinancialPriceSeries.prototype.we = function (a) {
        var b = this.xn;
        var c = this.getEffectiveViewport1(this.cv);
        var d = new ScalerParams(0, this.cv.by, this.cv.bx, b.ch, c);
        if (b.cp) {
            d.b = this.iy();
        }
        d.c = c;
        if (b.cp) {
            return { $type: Point_$type, x: NaN, y: b.el(a[1], d) };
        }
        else {
            return { $type: Point_$type, x: b.el(a[0], d), y: NaN };
        }
    };
    FinancialPriceSeries.prototype.ak = function (a, b) {
        var c = new List$1(ChartSelection.$, 0);
        this.p2(a, c, b);
        return c.toArray();
    };
    FinancialPriceSeries.prototype.p2 = function (a, b, c) {
        var d = this.wp(a);
        var e = this.xn;
        var f = this.w4;
        var g = this.wh(this.cv);
        var h, i;
        var j = this.abt(d, f, true, g, h, i);
        h = j.p4;
        i = j.p5;
        if (this.aaz == 0) {
            this.abv(b, h, i, c);
        }
        else {
            var k = void 0, l = void 0;
            var m = this.abs(d, e, true, g, k, l);
            k = m.p4;
            l = m.p5;
            this.abu(1, b, h, i, k, l, c);
        }
    };
    FinancialPriceSeries.prototype.abt = function (a, b, c, d, e, f) {
        var g = new ScalerParams(0, a, this.db.wj, this.w4.ch, this.getEffectiveViewport());
        var h = (this.w4.eo(d.left, g));
        var i = (this.w4.eo(d.right, g));
        if (this.w4.ch) {
            var j = h;
            h = i;
            i = j;
        }
        if (this.w4.cn) {
            var k = this.w4;
            h = k.i$f(h);
            i = k.i$f(i);
        }
        else {
            h = Math.floor(h);
            i = Math.ceil(i);
        }
        e = truncate(Math.max(0, Math.min(this.xz.count - 1, h)));
        f = truncate(Math.max(0, Math.min(this.xz.count - 1, i)));
        return {
            p4: e,
            p5: f
        };
    };
    FinancialPriceSeries.prototype.abs = function (a, b, c, d, e, f) {
        var g = new ScalerParams(0, a, this.db.wj, b.ch, this.getEffectiveViewport());
        var h = c ? (b.ch ? d.top : d.bottom) : (b.ch ? d.left : d.right);
        var i = c ? (b.ch ? d.bottom : d.top) : (b.ch ? d.right : d.left);
        e = b.eo(h, g);
        f = b.eo(i, g);
        return {
            p4: e,
            p5: f
        };
    };
    FinancialPriceSeries.prototype.abr = function (a, b, c) {
        var _this = this;
        if (c == 2 || c == 1) {
            a.add(((function () {
                var $ret = new ChartSelection();
                $ret.item = _this.dn.item(b);
                return $ret;
            })()));
        }
        else {
            a.add(((function () {
                var $ret = new ChartSelection();
                $ret.item = _this.dn.item(b);
                $ret.series = _this;
                return $ret;
            })()));
        }
    };
    FinancialPriceSeries.prototype.abv = function (a, b, c, d) {
        var _this = this;
        if (b == -1 || c == -1) {
            return;
        }
        if (d == 7 || d == 6) {
            a.add(((function () {
                var $ret = new ChartSelection();
                $ret.series = _this;
                return $ret;
            })()));
            return;
        }
        for (var e = b; e <= c; e++) {
            this.abr(a, e, d);
        }
    };
    FinancialPriceSeries.prototype.abu = function (a, b, c, d, e, f, g) {
        var _this = this;
        if (c == -1 || d == -1) {
            return;
        }
        for (var h = c; h <= d; h++) {
            var i = Math.min(this.x0.item(h), this.xz.item(h));
            var j = Math.max(this.xx.item(h), this.xy.item(h));
            var k = Math.min(i, j);
            var l = Math.max(i, j);
            if (k < f && e < l) {
                if (g == 7 || g == 6) {
                    b.add(((function () {
                        var $ret = new ChartSelection();
                        $ret.series = _this;
                        return $ret;
                    })()));
                    return;
                }
                this.abr(b, h, g);
            }
        }
    };
    FinancialPriceSeries.$t = markType(FinancialPriceSeries, 'FinancialPriceSeries', FinancialSeries.$, [ITrendLineSeries_$type]);
    FinancialPriceSeries.ab0 = 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', ['CategoryCollisionMode:aaz:ab1', [CategoryCollisionMode_$type, enumGetBox(CategoryCollisionMode_$type, 0)], 'CloseMemberAsLegendLabel:aa9:ab2', [2, null], 'CloseMemberAsLegendUnit:abb:ab3', [2, null], 'DisplayType:aa1:ab4', [PriceDisplayType_$type, enumGetBox(PriceDisplayType_$type, 0)], 'HighMemberAsLegendLabel:abe:ab5', [2, null], 'HighMemberAsLegendUnit:abg:ab6', [2, null], 'LowMemberAsLegendLabel:abi:ab7', [2, null], 'LowMemberAsLegendUnit:abk:ab8', [2, null], 'NegativeOutline:ack:ab9', [Brush.$, null], 'OpenMemberAsLegendLabel:abn:aca', [2, null], 'OpenMemberAsLegendUnit:abp:acb', [2, null], 'TrendLineType::ach', [TrendLineType_$type, enumGetBox(TrendLineType_$type, 0)], 'TrendLineThickness::acg', [1, 1.5], 'TrendLinePeriod::acf', [1, 7], 'TrendLineBrush::acc', [Brush.$, null], 'TrendLineZIndex:aa7:aci', [1, 1001], 'TrendLineDashArray:acl:acd', [DoubleCollection.$], 'TrendLineDashCap:acm:ace', [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.aa1 = Defaults.g;
            this.b6.aau = Defaults.ah;
            this.b6.ack = Defaults.ai;
            this.b6.jp = Defaults.l;
            this.b6.vt = this.b6.vb;
        }
    };
    Object.defineProperty(FinancialPriceSeriesView.prototype, "b8", {
        get: function () {
            if (this.b7 == null) {
                this.b7 = CategoryTrendLineManagerFactory.a(this.b7, this.e.a0(), this.e.st, this.e, this.e.dr);
            }
            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.aa1 == 1) {
            this.cq._stroke = this.e.u7;
        }
        else {
            this.cq._stroke = this.e.vb;
        }
        if (this.b6.aa1 == 1) {
            this.cp._stroke = this.b2.aau;
        }
        else {
            this.cp._stroke = this.b6.ack;
        }
    };
    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.acj = null;
        if (this.b6.trendLineBrush != null) {
            this.b6.acj = this.b6.trendLineBrush;
        }
        else {
            this.b6.acj = this.b6.u7;
        }
    };
    FinancialPriceSeriesView.prototype.bd = function () {
        _super.prototype.bd.call(this);
        this.cq.ad = this.e.ie;
        this.cq.ai = this.e.v0;
        this.cq.aj = this.e.v1;
        if (this.b6.aa1 == 1) {
            this.cq._stroke = this.e.u7;
        }
        else {
            this.cq._stroke = this.e.vb;
            this.cq._fill = this.e.u7;
        }
        this.cp.ad = this.e.ie;
        this.cp.ai = this.e.v0;
        this.cp.aj = this.e.v1;
        if (this.b6.aa1 == 1) {
            this.cp._stroke = this.b2.aau;
        }
        else {
            this.cp._stroke = this.b6.ack;
            this.cp._fill = this.b2.aau;
        }
    };
    FinancialPriceSeriesView.prototype.be = function () {
        _super.prototype.be.call(this);
        var a = this.br();
        this.cq.ad = this.e.ie + 3;
        if (this.b6.aa1 == 1) {
            this.cq._stroke = a;
        }
        else {
            this.cq._stroke = a;
            this.cq._fill = a;
        }
        this.cp.ad = this.e.ie + 3;
        if (this.b6.aa1 == 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.ie + 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.acj;
                c.ai = this.b6.acl;
                c.aj = this.b6.acm;
                a.v(c);
            }
        }
        _super.prototype.a7.call(this, a, b);
    };
    FinancialPriceSeriesView.prototype.an = function (a) {
        _super.prototype.an.call(this, a);
        if (this.b6.yc()) {
            for (var b = 0; b < this.cc.count; b++) {
                var c = this.cc._inner[b];
                if (c._fill == this.b6.aau) {
                    this.e.bc.exportPathData(a, c, "negativePathShape" + b, ["Negative"]);
                }
                else {
                    this.e.bc.exportPathData(a, c, "positivePathShape" + b, ["Positive", "Main"]);
                }
            }
        }
        else {
            this.e.bc.exportPathData(a, this.cq, "positivePathShape", ["Positive", "Main"]);
            this.e.bc.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.a0(), this.e.st, this.e, this.e.dr);
        }
    };
    FinancialPriceSeriesView.$t = markType(FinancialPriceSeriesView, 'FinancialPriceSeriesView', FinancialSeriesView.$);
    return FinancialPriceSeriesView;
}(FinancialSeriesView));
export { FinancialPriceSeriesView };
