/*
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 { DataAnnotationAxisLayer } from "./DataAnnotationAxisLayer";
import { DependencyProperty } from "igniteui-angular-core";
import { OverlayTextLocation_$type } from "./OverlayTextLocation";
import { Brush } from "igniteui-angular-core";
import { enumGetBox, Number_$type, typeCast, fromEnum, Point_$type, markType, markDep, getInstanceType, runOn } from "igniteui-angular-core";
import { AnnotationAppearanceMode_$type } from "./AnnotationAppearanceMode";
import { OverlayTextUtil } from "./OverlayTextUtil";
import { OverlayTextUpdatingEventArgs } from "./OverlayTextUpdatingEventArgs";
import { DataAnnotationItem } from "./DataAnnotationItem";
import { DataAnnotationInfo } from "./DataAnnotationInfo";
import { DataAnnotationShapeLayerFrame } from "./DataAnnotationShapeLayerFrame";
import { Dictionary$2 } from "igniteui-angular-core";
import { Axis } from "./Axis";
import { Pool$1 } from "igniteui-angular-core";
import { AxisAnnotation } from "./AxisAnnotation";
import { IFastItemsSource_$type } from "igniteui-angular-core";
import { List$1 } from "igniteui-angular-core";
import { ScalerParams } from "./ScalerParams";
import { Defaults } from "./Defaults";
import { DataAnnotationShapeFrameManager } from "./DataAnnotationShapeFrameManager";
import { XamDataChart } from "./XamDataChart";
import { CategoryAxisBase } from "./CategoryAxisBase";
import { Size } from "igniteui-angular-core";
import { BrushUtil } from "igniteui-angular-core";
import { TextBlock } from "igniteui-angular-core";
import { Rectangle } from "igniteui-angular-core";
import { Extensions } from "igniteui-angular-core";
import { NumberFormatSpecifier } from "igniteui-angular-core";
import { BindingFormatter } from "igniteui-angular-core";
import { Path } from "igniteui-angular-core";
import { Tuple$2 } from "igniteui-angular-core";
import { PathFigure } from "igniteui-angular-core";
import { PathGeometry } from "igniteui-angular-core";
import { LineSegment } from "igniteui-angular-core";
import { OverlayTextInfo } from "./OverlayTextInfo";
import { DoubleCollection } from "igniteui-angular-core";
import { DeviceUtils } from "igniteui-angular-core";
import { PropertyMetadata } from "igniteui-angular-core";
import { truncate, isNaN_, log10, isInfinity } from "igniteui-angular-core";
import { stringIsNullOrEmpty } from "igniteui-angular-core";
import { round10N } from "igniteui-angular-core";
import { AnnotationLayerView } from "./AnnotationLayerView";
import { TranslateTransform } from "igniteui-angular-core";
import { LineGeometry } from "igniteui-angular-core";
/**
 * @hidden
 */
var DataAnnotationShapeLayer = /** @class */ /*@__PURE__*/ (function (_super) {
    __extends(DataAnnotationShapeLayer, _super);
    function DataAnnotationShapeLayer() {
        var _this = _super.call(this) || this;
        _this.stylingOverlayText = null;
        _this.stylingShapeAnnotation = null;
        _this.stylingAxisAnnotation = null;
        _this.aco = null;
        _this.acm = null;
        _this.ac1 = null;
        _this.ac0 = null;
        _this.ac2 = new List$1(DataAnnotationItem.$, 0);
        _this.afj = null;
        _this.adk = 0;
        _this.acr = false;
        _this.acd = null;
        _this.ace = null;
        _this.ack = null;
        _this.acl = null;
        var a = new DataAnnotationShapeLayerFrame();
        var b = new DataAnnotationShapeLayerFrame();
        var c = new DataAnnotationShapeLayerFrame();
        var d = _this.kh / 1000;
        _this.xm = a;
        _this.xl = b;
        _this.xn = c;
        _this.ab = DataAnnotationShapeLayer.$;
        return _this;
    }
    DataAnnotationShapeLayer.prototype.get_acz = function () {
        return true;
    };
    Object.defineProperty(DataAnnotationShapeLayer.prototype, "acz", {
        get: function () {
            return this.get_acz();
        },
        enumerable: false,
        configurable: true
    });
    Object.defineProperty(DataAnnotationShapeLayer.prototype, "acp", {
        get: function () {
            return this.aco;
        },
        set: function (a) {
            if (this.aco != a) {
                var b = this.aco;
                this.aco = a;
                this.raisePropertyChanged("OverlayTextColumn", b, this.aco);
            }
        },
        enumerable: false,
        configurable: true
    });
    Object.defineProperty(DataAnnotationShapeLayer.prototype, "acn", {
        get: function () {
            return this.acm;
        },
        set: function (a) {
            var b = this.acm;
            if (OverlayTextUtil.q(a)) {
                a = OverlayTextUtil.c();
            }
            this.acm = a;
            if (b != this.acm) {
                this.raisePropertyChanged("OverlayTextStyle", b, this.acm);
            }
        },
        enumerable: false,
        configurable: true
    });
    DataAnnotationShapeLayer.prototype.rg = function (a, b, c, d) {
        if (b == "CrosshairPoint") {
            return;
        }
        _super.prototype.rg.call(this, a, b, c, d);
        switch (b) {
            case "SeriesViewer":
                if (d == null) {
                    if (this.ac0 != null && this.ac0.count > 0) {
                        var e = void 0;
                        if (this.d4()) {
                            e = this.xn;
                        }
                        else {
                            e = this.xl;
                        }
                        e.a3();
                        this.aep(e, true, true);
                    }
                }
                break;
            case DataAnnotationShapeLayer.$$p[0]:
            case "AreaFillOpacity":
                this.ry(true);
                break;
            case DataAnnotationShapeLayer.$$p[1]:
            case "OverlayTextColumn":
            case DataAnnotationShapeLayer.$$p[24]:
            case DataAnnotationShapeLayer.$$p[19]:
            case DataAnnotationShapeLayer.$$p[2]:
            case DataAnnotationShapeLayer.$$p[13]:
            case DataAnnotationShapeLayer.$$p[14]:
            case DataAnnotationShapeLayer.$$p[16]:
            case DataAnnotationShapeLayer.$$p[15]:
            case DataAnnotationShapeLayer.$$p[3]:
            case DataAnnotationShapeLayer.$$p[4]:
            case DataAnnotationShapeLayer.$$p[6]:
            case DataAnnotationShapeLayer.$$p[5]:
            case DataAnnotationShapeLayer.$$p[8]:
            case DataAnnotationShapeLayer.$$p[9]:
            case DataAnnotationShapeLayer.$$p[11]:
            case DataAnnotationShapeLayer.$$p[7]:
            case DataAnnotationShapeLayer.$$p[10]:
            case DataAnnotationShapeLayer.$$p[12]:
            case DataAnnotationShapeLayer.$$p[17]:
            case DataAnnotationShapeLayer.$$p[18]:
            case DataAnnotationShapeLayer.$$p[23]:
            case DataAnnotationShapeLayer.$$p[22]:
                this.abj();
                break;
            case "FastItemsSource":
                this.aem(c, d);
                this.abj();
                break;
            case DataAnnotationShapeLayer.$$p[21]:
            case DataAnnotationShapeLayer.$$p[20]:
                if (this.dp != null) {
                    this.dp.deregisterColumn(this.acp);
                    this.acp = this.dn(this.aea);
                }
                break;
        }
    };
    DataAnnotationShapeLayer.prototype.act = function (a) {
        return !stringIsNullOrEmpty(a);
    };
    DataAnnotationShapeLayer.prototype.dl = function (a) {
        if (this.dp == null) {
            return null;
        }
        if (!this.act(a)) {
            return null;
        }
        return _super.prototype.dl.call(this, a);
    };
    DataAnnotationShapeLayer.prototype.dn = function (a) {
        if (this.dp == null) {
            return null;
        }
        if (!this.act(a)) {
            return null;
        }
        return _super.prototype.dn.call(this, a);
    };
    DataAnnotationShapeLayer.prototype.aei = function (a) {
        if (this.dp != null) {
            this.dp.deregisterColumn(a);
        }
    };
    DataAnnotationShapeLayer.prototype.aem = function (a, b) {
        this.ac2.clear();
        if (typeCast(IFastItemsSource_$type, a) != null) {
            a.deregisterColumn(this.acp);
            this.acp = null;
        }
        if (typeCast(IFastItemsSource_$type, b) != null) {
            this.acp = this.dn(this.aea);
        }
    };
    DataAnnotationShapeLayer.prototype.ph = function (a, b, c, d) {
        _super.prototype.ph.call(this, a, b, c, d);
        switch (a) {
            case 3:
                this.aek(b);
                break;
            case 1:
                for (var e = b; e < b + c; e++) {
                    var f = new DataAnnotationItem();
                    this.ac2.insert(e, f);
                    this.aek(e);
                }
                break;
            case 0:
                this.ac2.v(b, c);
                break;
            case 2:
                for (var g = b; g < b + c; g++) {
                    this.aek(g);
                }
                break;
            case 4:
                this.aej();
                break;
        }
        this.ry(true);
    };
    DataAnnotationShapeLayer.prototype.ct = function () {
        return new DataAnnotationShapeLayerView(this);
    };
    DataAnnotationShapeLayer.prototype.q7 = function (a) {
        _super.prototype.q7.call(this, a);
        this.acg = a;
    };
    DataAnnotationShapeLayer.prototype.ael = function () {
        this.jt = Defaults.dataAnnotationShapeThickness;
        this.im = Defaults.dataAnnotationShapeThickness;
        this.ig = Defaults.dataAnnotationShapeThickness;
        this.il = Defaults.dataAnnotationShapeFillOpacity;
        this.aau = Defaults.dataAnnotationLabelThickness;
        this.acm = OverlayTextUtil.c();
    };
    DataAnnotationShapeLayer.prototype.qv = function () {
        _super.prototype.qv.call(this);
        if (!this.a1.c && !this.d4()) {
            return;
        }
        if (this.aal) {
            this.aal = false;
            this.aej();
        }
        if (this.d4()) {
            this.aeq(this.xn, false);
        }
        else {
            this.aeq(this.xl, false);
        }
    };
    DataAnnotationShapeLayer.prototype.aej = function () {
        this.ac2.clear();
        if (this.dp == null || this.dp.count == 0) {
            return;
        }
        for (var a = 0; a < this.dp.count; a++) {
            var b = new DataAnnotationItem();
            this.ac2.add(b);
            this.aek(a);
        }
    };
    DataAnnotationShapeLayer.prototype.aek = function (a) {
    };
    DataAnnotationShapeLayer.prototype.aeq = function (a, b) {
        var c = false;
        if (this.ac0 == null) {
            c = true;
            this.ac1 = new List$1(Axis.$, 0);
            this.ac0 = new Dictionary$2(Axis.$, Pool$1.$.specialize(AxisAnnotation.$), 0);
        }
        this.aep(a, c, b);
    };
    DataAnnotationShapeLayer.prototype.aep = function (a, b, c) {
        DataAnnotationShapeFrameManager.c(this, a, b, this.ac0, this.ac1, c, this.aax, this.aaw);
    };
    DataAnnotationShapeLayer.prototype.y3 = function (a, b) {
        var e_1, _a, e_2, _b;
        _super.prototype.y3.call(this, a, b);
        var c = a;
        var d = true;
        c.a3();
        this.adk = 0;
        if (this.aai != null) {
            if (this.aaq(this.aai)) {
                this.aeo(this.aai, c, d);
            }
        }
        else {
            if (typeCast(XamDataChart.$, this.dc) !== null) {
                var e = this.dc;
                var f = true;
                try {
                    for (var _c = __values(fromEnum(e.axes)), _d = _c.next(); !_d.done; _d = _c.next()) {
                        var g = _d.value;
                        if (!this.aaq(g)) {
                            continue;
                        }
                        if (!g.dh) {
                            f = false;
                        }
                    }
                }
                catch (e_1_1) {
                    e_1 = { error: e_1_1 };
                }
                finally {
                    try {
                        if (_d && !_d.done && (_a = _c.return))
                            _a.call(_c);
                    }
                    finally {
                        if (e_1)
                            throw e_1.error;
                    }
                }
                try {
                    for (var _e = __values(fromEnum(e.axes)), _f = _e.next(); !_f.done; _f = _e.next()) {
                        var h = _f.value;
                        if (!this.aaq(h)) {
                            continue;
                        }
                        if (this.aak == 0) {
                            if (typeCast(CategoryAxisBase.$, h) !== null) {
                                this.aeo(h, c, d);
                            }
                            else if (h.dh && !h.dq && f) {
                                this.aeo(h, c, d);
                            }
                        }
                        else if (this.aak == 1 && (h.c8 || h.dc)) {
                            this.aeo(h, c, d);
                        }
                        else if (this.aak == 4 && h.c8) {
                            this.aeo(h, c, d);
                        }
                        else if (this.aak == 5 && h.dc) {
                            this.aeo(h, c, d);
                        }
                        else if (this.aak == 6 && h.dh && !h.dq) {
                            this.aeo(h, c, d);
                        }
                        else if (this.aak == 7 && h.dh && h.dq) {
                            this.aeo(h, c, d);
                        }
                        else if (this.aak == 3 && h.dq) {
                            this.aeo(h, c, d);
                        }
                        else if (this.aak == 2 && !h.dq) {
                            this.aeo(h, c, d);
                        }
                    }
                }
                catch (e_2_1) {
                    e_2 = { error: e_2_1 };
                }
                finally {
                    try {
                        if (_f && !_f.done && (_b = _e.return))
                            _b.call(_e);
                    }
                    finally {
                        if (e_2)
                            throw e_2.error;
                    }
                }
            }
        }
    };
    DataAnnotationShapeLayer.prototype.aeo = function (a, b, c) {
        var e_3, _a;
        this.acd = null;
        this.ace = null;
        this.ack = null;
        this.acl = null;
        var d = this.getEffectiveViewport();
        var e = this.dc.xm;
        if (a.dq) {
            this.ace = a;
            if (this.ace.am != null) {
                this.acd = this.ace.am;
            }
            else {
                this.acd = this.acc(a);
            }
            this.acr = false;
        }
        else {
            this.acd = a;
            if (this.acd.am != null) {
                this.ace = this.acd.am;
            }
            else {
                this.ace = this.acc(a);
            }
            this.acr = true;
        }
        if (this.acd == null) {
            return;
        }
        if (this.ace == null) {
            return;
        }
        this.acl = new ScalerParams(1, e, this.ace.n1, this.ace.df);
        this.ack = new ScalerParams(1, e, this.acd.n1, this.acd.df);
        this.ack.c = d;
        this.acl.c = d;
        var f = this.ig;
        var g = this.zy();
        if (g == null) {
            g = BrushUtil.j(255, 0, 0, 0);
        }
        var h = this.acz ? this.zz() : g;
        if (h == null) {
            h = BrushUtil.j(255, 0, 0, 0);
        }
        g = OverlayTextUtil.ah(g, this.xx, this.w8);
        h = OverlayTextUtil.ah(h, this.xx, this.w8);
        var i = this.acr;
        this.aej();
        this.acg.cu();
        this.aen();
        var j = this.acn;
        var k = OverlayTextUtil.o(j, this.acy);
        var l = this.aci;
        if (l == 18) {
            k = false;
        }
        if (k) {
            this.acg.cq.count = this.ac2.count;
            this.acg.cp.count = this.ac2.count;
        }
        for (var m = 0; m < this.ac2.count; m++) {
            var n = this.ac2._inner[m];
            n.dataIndex = m;
            n.shapeBrush = n.shapeBrush != null ? n.shapeBrush : g;
            n.shapeOutline = n.shapeOutline != null ? n.shapeOutline : h;
            if (this.acz) {
                n.shapeBrush = BrushUtil.s(n.shapeBrush, this.il);
            }
            n.shapeThickness = !isNaN_(n.shapeThickness) ? n.shapeThickness : f;
            n.h = 1.7976931348623157E+308;
            n.f = 1.7976931348623157E+308;
            n.g = -1.7976931348623157E+308;
            n.d = -1.7976931348623157E+308;
            var o = new List$1(Point_$type, 0);
            for (var p = 0; p < n.c.count; p++) {
                var q = n.c._inner[p];
                var r = this.afm(q.y, false);
                o.add(r);
                var s = this.afm(q.y, true);
                n.h = Math.min(s.y, n.h);
                n.d = Math.max(s.y, n.d);
                n.f = Math.min(s.x, n.f);
                n.g = Math.max(s.x, n.g);
            }
            var t = new List$1(DataAnnotationInfo.$, 0);
            t = new List$1(DataAnnotationInfo.$, 0);
            t.o(n.c);
            t.o(n.b);
            if (this.stylingShapeAnnotation != null) {
                this.stylingShapeAnnotation(this, n);
            }
            b.ay.add(o);
            b.aw.add(n.a);
            b.av.add(n.shapeBrush);
            b.ax.add(n.shapeOutline);
            b.az.add(n.shapeThickness);
            b.a0.add(this.acq);
            var u = this.ab5;
            if (u == null) {
                u = this.aam ? g : Defaults.dataAnnotationLabelBackground;
            }
            var v = this.ab6;
            if (v == null) {
                v = this.aan ? h : Defaults.dataAnnotationLabelBorderStroke;
            }
            var w = this.acz ? n.shapeOutline : n.shapeBrush;
            var x = this.ab7;
            if (x == null) {
                x = this.aap ? w : this.ab7;
            }
            var y = OverlayTextUtil.t(this.aau, Defaults.dataAnnotationLabelBorderThickness);
            var z = OverlayTextUtil.t(this.aas, Defaults.dataAnnotationLabelBorderRadius);
            try {
                for (var _b = (e_3 = void 0, __values(fromEnum(t))), _c = _b.next(); !_c.done; _c = _b.next()) {
                    var aa = _c.value;
                    if (aa.borderColor == null) {
                        aa.borderColor = v;
                    }
                    if (aa.background == null) {
                        aa.background = u;
                    }
                    if (aa.textColor == null) {
                        aa.textColor = x;
                    }
                    aa.borderColor = OverlayTextUtil.ah(aa.borderColor, this.aat, this.aag);
                    aa.background = OverlayTextUtil.ah(aa.background, this.aar, this.aaf);
                    aa.textColor = OverlayTextUtil.af(aa.background, aa.textColor, this.aav, this.aah);
                    if (isNaN_(aa.borderThickness)) {
                        aa.borderThickness = y;
                    }
                    if (isNaN_(aa.borderRadius)) {
                        aa.borderRadius = z;
                    }
                    var ab = this.afm(aa.y, false);
                    aa.xAxisPixel = ab.x;
                    aa.yAxisPixel = ab.y;
                    aa.xAxisWindow = this.adi(ab.x);
                    aa.yAxisWindow = this.adj(ab.y);
                    aa.xAxisValue = aa.c ? this.acd.fw(ab.x, this.ack) : NaN;
                    aa.yAxisValue = aa.d ? this.ace.fw(ab.y, this.acl) : NaN;
                    aa.xAxisLabel = this.adm(this.acd, aa, true);
                    aa.yAxisLabel = this.adm(this.ace, aa, false);
                    aa.dataIndex = n.dataIndex;
                    if (this.stylingAxisAnnotation != null) {
                        this.stylingAxisAnnotation(this, aa);
                    }
                }
            }
            catch (e_3_1) {
                e_3 = { error: e_3_1 };
            }
            finally {
                try {
                    if (_c && !_c.done && (_a = _b.return))
                        _a.call(_b);
                }
                finally {
                    if (e_3)
                        throw e_3.error;
                }
            }
            if (this.aao) {
                for (var ac = 0; ac < t.count; ac++) {
                    var ad = t._inner[ac];
                    var ae = !stringIsNullOrEmpty(ad.xAxisLabel);
                    var af = !stringIsNullOrEmpty(ad.yAxisLabel);
                    DataAnnotationShapeFrameManager.b(b, ad.xAxisValue, ad.yAxisValue, ad.xAxisLabel, ad.yAxisLabel, ad.textColor, ad.background, ad.borderColor, ad.borderThickness, ad.borderRadius, this.ab8, ae, af, this.acd, this.ace, this.ack, this.acl);
                }
            }
            var ag = this.adq;
            if (stringIsNullOrEmpty(ag)) {
                ag = this.ado(m, this.acp);
            }
            var ah = new Size(1, 0, 0);
            var ai = { $type: Point_$type, x: NaN, y: NaN };
            var aj = this.afi;
            if (aj == null && this.acx) {
                aj = g;
            }
            var ak = this.afg;
            if (ak == null && this.acv) {
                ak = g;
            }
            var al = this.afh;
            if (al == null && this.acw) {
                al = g;
            }
            var am = new OverlayTextUpdatingEventArgs();
            am.dataIndex = m;
            am.backgroundMode = this.ab9;
            am.backgroundShift = this.ac9;
            am.background = ak;
            am.borderMode = this.aca;
            am.borderShift = this.adb;
            am.borderStroke = al;
            am.borderRadius = this.ada;
            am.borderThickness = this.adc;
            am.textLocation = this.aci;
            am.textAngle = this.ac8;
            am.textVisible = this.acy;
            am.textContent = ag;
            am.textColorMode = this.acb;
            am.textColorShift = this.add;
            am.textColor = aj;
            am.shapeBrush = g;
            am.shapeOutline = h;
            am.f = !i;
            am.horizontalMargin = this.ade;
            am.verticalPadding = this.adh;
            am.verticalMargin = this.adg;
            am.horizontalPadding = this.adf;
            if (this.stylingOverlayText != null && k) {
                this.stylingOverlayText(this, am);
            }
            OverlayTextUtil.ad(am);
            if (k && !am.textEmpty && am.textVisible) {
                ah = this.cw.cc(am.textContent, j);
                ai = OverlayTextUtil.ak(am.textLocation, ah, am.textAngle, am.horizontalMargin, am.verticalMargin, am.horizontalPadding, am.verticalPadding, n.ac, i);
            }
            else {
                am.textVisible = false;
            }
            if (!Extensions.a(ai)) {
                am.textVisible = false;
            }
            b.aj.add(am.borderThickness);
            b.ah.add(am.borderStroke);
            b.ai.add(am.borderRadius);
            b.ag.add(am.background);
            b.ar.add(ah);
            b.am.add(j);
            b.ak.add(am.textColor);
            b.af.add(am.textAngle);
            b.al.add(am.textContent);
            b.ao.add(am.horizontalPadding);
            b.at.add(am.verticalPadding);
            b.an.add(am.horizontalMargin);
            b.as.add(am.verticalMargin);
            b.au.add(am.textVisible);
            b.ap.add(ai.x);
            b.aq.add(ai.y);
        }
    };
    DataAnnotationShapeLayer.prototype.aen = function () {
        if (OverlayTextUtil.q(this.acm)) {
            this.acm = OverlayTextUtil.c();
        }
        else if (OverlayTextUtil.k(this.acm)) {
            this.acm = this.cw.l(this.acm.fontString);
        }
    };
    DataAnnotationShapeLayer.prototype.adn = function (a, b, c, d) {
        if (isNaN_(b)) {
            return null;
        }
        if (c >= 0) {
            var e = new NumberFormatSpecifier();
            e.minimumFractionDigits = c;
            e.maximumFractionDigits = d > 0 ? d : c;
            var f = new BindingFormatter();
            f.j = "{0}";
            f.d = [e];
            return f.i(b);
        }
        var g = 0;
        if (d >= 0) {
            g = d;
        }
        else if (a.dh) {
            var h = a.f5();
            g = h == 0 ? 0 : truncate(Math.max(-Math.floor(log10(h)), 0));
            g += 1;
        }
        return round10N(b, g).toString();
    };
    DataAnnotationShapeLayer.prototype.adm = function (a, b, c) {
        var d = c ? b.dataValueX : b.dataValueY;
        var e = c ? b.dataLabelX : b.dataLabelY;
        var f = c ? b.xAxisValue : b.yAxisValue;
        var g = c ? b.xAxisPixel : b.yAxisPixel;
        var h = c ? b.xAxisWindow : b.yAxisWindow;
        var i = c ? b.a : b.b;
        if (i == 6) {
            return null;
        }
        if (this.aaj != 0 && i == 0) {
            i = this.aaj;
        }
        if (i == 0) {
            if (!stringIsNullOrEmpty(e)) {
                return e;
            }
            else if (!isNaN_(d)) {
                return this.adn(a, d, this.aax, this.aaw);
            }
        }
        else if (i == 1) {
            return this.adn(a, d, this.aax, this.aaw);
        }
        else if (i == 2) {
            if (stringIsNullOrEmpty(e)) {
                return null;
            }
            else {
                return e;
            }
        }
        else if (i == 4) {
            var j = this.aax;
            if (j < 0) {
                j = 0;
            }
            var k = this.aax;
            if (k < 0) {
                k = 0;
            }
            return this.adn(a, g, j, k);
        }
        else if (i == 5) {
            var l = this.aax;
            if (l < 0) {
                l = 2;
            }
            var m = this.aax;
            if (m < 0) {
                m = 2;
            }
            return this.adn(a, h, l, m);
        }
        else if (i == 3) {
            if (a.dh) {
                return this.adn(a, f, this.aax, this.aaw);
            }
            else {
                return a.ih(d);
            }
        }
        return null;
    };
    DataAnnotationShapeLayer.prototype.y6 = function (a, b) {
        var e_4, _a, e_5, _b;
        _super.prototype.y6.call(this, a, b);
        var c = this.acg.co;
        var d = a;
        var e = d.ay.count;
        var f = 0;
        var g = b.b9.top;
        var h = b.b9.left;
        var i = b.b9.right;
        var j = b.b9.bottom;
        var k = Math.min(h, i);
        var l = Math.min(g, j);
        var m = Math.max(h, i);
        var n = Math.max(g, j);
        var o = m - k;
        var p = n - l;
        for (var q = 0; q < e; q++) {
            if (!d.a0._inner[q]) {
                continue;
            }
            var r = null;
            var s = this.aeh(c, f, q, d);
            r = s.c;
            f = s.d;
            var t = true;
            var u = new List$1(PathFigure.$, 0);
            var v = null;
            var _loop_1 = function (w) {
                if (!Extensions.a(w)) {
                    t = true;
                    if (v != null && v._segments.count > 0) {
                        u.add(v);
                    }
                    return "continue";
                }
                if (t) {
                    t = false;
                    v = new PathFigure();
                    v._startPoint = w;
                }
                else {
                    var x = ((function () {
                        var $ret = new LineSegment(1);
                        $ret.c = w;
                        return $ret;
                    })());
                    v._segments.add(x);
                }
            };
            try {
                for (var _c = (e_4 = void 0, __values(fromEnum(d.ay._inner[q]))), _d = _c.next(); !_d.done; _d = _c.next()) {
                    var w = _d.value;
                    _loop_1(w);
                }
            }
            catch (e_4_1) {
                e_4 = { error: e_4_1 };
            }
            finally {
                try {
                    if (_d && !_d.done && (_a = _c.return))
                        _a.call(_c);
                }
                finally {
                    if (e_4)
                        throw e_4.error;
                }
            }
            if (v != null && v._segments.count > 0) {
                u.add(v);
            }
            var y = new PathGeometry();
            try {
                for (var _e = (e_5 = void 0, __values(fromEnum(u))), _f = _e.next(); !_f.done; _f = _e.next()) {
                    var z = _f.value;
                    z._isClosed = d.aw._inner[q];
                    y.c.add(z);
                }
            }
            catch (e_5_1) {
                e_5 = { error: e_5_1 };
            }
            finally {
                try {
                    if (_f && !_f.done && (_b = _e.return))
                        _b.call(_e);
                }
                finally {
                    if (e_5)
                        throw e_5.error;
                }
            }
            r.an = y;
            if (d.au._inner[q]) {
                this.acg.cq.item(q)._visibility = 0;
                this.acg.cp.item(q)._visibility = 0;
            }
            else {
                this.acg.cq.item(q)._visibility = 1;
                this.acg.cp.item(q)._visibility = 1;
            }
            if (d.au._inner[q]) {
                var aa = new OverlayTextInfo();
                aa.background = d.ag._inner[q];
                aa.textColor = d.ak._inner[q];
                aa.verticalPadding = d.at._inner[q];
                aa.horizontalPadding = d.ao._inner[q];
                aa.horizontalMargin = d.an._inner[q];
                aa.verticalMargin = d.as._inner[q];
                aa.borderThickness = d.aj._inner[q];
                aa.borderStroke = d.ah._inner[q];
                aa.borderRadius = d.ai._inner[q];
                aa.textLocation = this.aci;
                aa.textAngle = d.af._inner[q];
                aa.textVisible = d.au._inner[q];
                aa.textContent = d.al._inner[q];
                aa.f = d.am._inner[q];
                aa.ad = d.ar._inner[q];
                aa.u = this.acg.cq.item(q);
                aa.ac = this.acg.cp.item(q);
                var ab = d.ap._inner[q];
                var ac = d.aq._inner[q];
                aa.aa = { $type: Point_$type, x: ab, y: ac };
                OverlayTextUtil.y(aa.ac, aa.background, aa.borderStroke, aa.borderThickness, aa.borderRadius);
                OverlayTextUtil.z(aa.u, aa.textColor);
                OverlayTextUtil.x(aa);
                OverlayTextUtil.w(aa);
                this.cw.av(aa.u, aa.f);
                this.cw.aw(aa.u, aa.f);
            }
        }
        c.count = f;
        if (this.d4()) {
            this.aeq(this.xn, true);
        }
        else {
            this.aeq(this.xl, false);
        }
    };
    DataAnnotationShapeLayer.prototype.aeh = function (a, b, c, d) {
        var e = a.item(b);
        b++;
        e.ad = d.az._inner[c];
        e._stroke = d.ax._inner[c];
        e._fill = d.av._inner[c];
        e.ai = this.z0;
        e.am = this.wf;
        e.al = this.we;
        e.ak = this.we;
        e.aj = this.wd;
        e.ac = this.jk;
        return new Tuple$2(Path.$, Number_$type, e, b);
    };
    DataAnnotationShapeLayer.prototype.xc = function () {
        return 3;
    };
    DataAnnotationShapeLayer.prototype.xz = function () {
        return 0.1;
    };
    DataAnnotationShapeLayer.prototype.x2 = function () {
        return -0.4;
    };
    DataAnnotationShapeLayer.prototype.x1 = function () {
        return NaN;
    };
    DataAnnotationShapeLayer.prototype.zb = function () {
        _super.prototype.zb.call(this);
        this.xx = this.x5();
    };
    DataAnnotationShapeLayer.prototype.x5 = function () {
        if (isNaN_(this.x8)) {
            switch (this.w8) {
                case 1: return this.xz();
                case 2: return this.x2();
                case 4:
                case 3: return this.x1();
            }
        }
        return this.x8;
    };
    DataAnnotationShapeLayer.prototype.z3 = function () {
        if (this.afj == null) {
            this.afj = new DoubleCollection();
            this.afj.add(DeviceUtils.g(2));
            this.afj.add(DeviceUtils.g(4));
        }
        return this.afj;
    };
    DataAnnotationShapeLayer.prototype.ado = function (a, b) {
        if (b == null || b.count <= a) {
            return null;
        }
        var c = b.item(a);
        return c != null ? c.toString() : null;
    };
    DataAnnotationShapeLayer.prototype.ac7 = function (a, b) {
        if (b == null || b.count <= a) {
            return NaN;
        }
        return b.item(a);
    };
    DataAnnotationShapeLayer.prototype.afl = function (a, b) {
        if (b == null || b.count <= a) {
            return { $type: Point_$type, x: NaN, y: NaN };
        }
        var c = b.item(a);
        if (c == null || getInstanceType(c) != Point_$type) {
            return { $type: Point_$type, x: NaN, y: NaN };
        }
        return b.item(a);
    };
    DataAnnotationShapeLayer.prototype.afm = function (a, b) {
        if (b === void 0) {
            b = false;
        }
        var c = b ? 1 : 2;
        var d = b ? 0 : -1;
        if (this.acu) {
            var e = a.x;
            var f = a.y;
            if (isInfinity(e) && e > 0) {
                e = c;
            }
            if (isInfinity(e) && e < 0) {
                e = d;
            }
            if (isInfinity(f) && f > 0) {
                f = c;
            }
            if (isInfinity(f) && f < 0) {
                f = d;
            }
            return this.dc.xe({ $type: Point_$type, x: e, y: f });
        }
        else {
            var g = a.x;
            var h = a.y;
            var i = false;
            var j = false;
            if (isInfinity(g) && g > 0) {
                g = Math.floor(this.ac5(c));
                i = true;
            }
            if (isInfinity(g) && g < 0) {
                g = Math.floor(this.ac5(d));
                i = true;
            }
            if (isInfinity(h) && h > 0) {
                h = Math.floor(this.ac6(c));
                j = true;
            }
            if (isInfinity(h) && h < 0) {
                h = Math.floor(this.ac6(d));
                j = true;
            }
            if (!i && !isNaN_(g)) {
                g = this.acd.ft(g, this.ack);
            }
            if (!j && !isNaN_(h)) {
                h = this.ace.ft(h, this.acl);
            }
            return { $type: Point_$type, x: g, y: h };
        }
    };
    DataAnnotationShapeLayer.prototype.ac3 = function (a) {
        return this.acd.ft(a, this.ack);
    };
    DataAnnotationShapeLayer.prototype.ac4 = function (a) {
        return this.ace.ft(a, this.acl);
    };
    DataAnnotationShapeLayer.prototype.acs = function (a) {
        if (this.acd == null) {
            return false;
        }
        if (this.ace == null) {
            return false;
        }
        if (this.ack == null) {
            return false;
        }
        if (this.acl == null) {
            return false;
        }
        if (this.dp == null) {
            return false;
        }
        if (a < 0 || a >= this.dp.count) {
            return false;
        }
        if (this.ac2 == null) {
            return false;
        }
        if (a < 0 || a >= this.ac2.count) {
            return false;
        }
        return true;
    };
    DataAnnotationShapeLayer.prototype.acc = function (a) {
        var e_6, _a;
        if (typeCast(XamDataChart.$, this.dc) !== null) {
            var b = this.dc;
            try {
                for (var _b = __values(fromEnum(b.axes)), _c = _b.next(); !_c.done; _c = _b.next()) {
                    var c = _c.value;
                    if (c.dq && !a.dq) {
                        return c;
                    }
                    if (!c.dq && a.dq) {
                        return c;
                    }
                }
            }
            catch (e_6_1) {
                e_6 = { error: e_6_1 };
            }
            finally {
                try {
                    if (_c && !_c.done && (_a = _b.return))
                        _a.call(_b);
                }
                finally {
                    if (e_6)
                        throw e_6.error;
                }
            }
        }
        return null;
    };
    DataAnnotationShapeLayer.prototype.afk = function (a) {
        return this.dc.xe(a);
    };
    DataAnnotationShapeLayer.prototype.ac5 = function (a) {
        return this.dc.xe({ $type: Point_$type, x: a, y: NaN }).x;
    };
    DataAnnotationShapeLayer.prototype.ac6 = function (a) {
        return this.dc.xe({ $type: Point_$type, x: NaN, y: a }).y;
    };
    DataAnnotationShapeLayer.prototype.afn = function (a) {
        return this.dc.xg(a);
    };
    DataAnnotationShapeLayer.prototype.adi = function (a) {
        return this.dc.xg({ $type: Point_$type, x: a, y: NaN }).x;
    };
    DataAnnotationShapeLayer.prototype.adj = function (a) {
        return this.dc.xg({ $type: Point_$type, x: NaN, y: a }).y;
    };
    DataAnnotationShapeLayer.$t = markType(DataAnnotationShapeLayer, 'DataAnnotationShapeLayer', DataAnnotationAxisLayer.$);
    DataAnnotationShapeLayer.$$p = markDep(DependencyProperty, PropertyMetadata, DataAnnotationShapeLayer, 'raisePropertyChanged', ['AnnotationShapeVisible:acq:aer', [0, true], 'ItemsUseWorldCoordinates:acu:aes', [0, false], 'OverlayTextAngle:ac8:aet', [1, NaN], 'OverlayTextBackgroundMatchLayer:acv:aeu', [0, false], 'OverlayTextBackgroundMode:ab9:aev', [AnnotationAppearanceMode_$type, enumGetBox(AnnotationAppearanceMode_$type, 0)], 'OverlayTextBackground:afg:aew', [Brush.$, null], 'OverlayTextBackgroundShift:ac9:aex', [1, NaN], 'OverlayTextBorderColor:afh:aey', [Brush.$, null], 'OverlayTextBorderMatchLayer:acw:aez', [0, false], 'OverlayTextBorderMode:aca:ae0', [AnnotationAppearanceMode_$type, enumGetBox(AnnotationAppearanceMode_$type, 0)], 'OverlayTextBorderRadius:ada:ae1', [1, NaN], 'OverlayTextBorderShift:adb:ae2', [1, NaN], 'OverlayTextBorderThickness:adc:ae3', [1, 1], 'OverlayTextColorMatchLayer:acx:ae4', [0, true], 'OverlayTextColorMode:acb:ae5', [AnnotationAppearanceMode_$type, enumGetBox(AnnotationAppearanceMode_$type, 0)], 'OverlayTextColor:afi:ae6', [Brush.$, null], 'OverlayTextColorShift:add:ae7', [1, NaN], 'OverlayTextHorizontalMargin:ade:ae8', [1, NaN], 'OverlayTextHorizontalPadding:adf:ae9', [1, NaN], 'OverlayTextLocation:aci:afa', [OverlayTextLocation_$type, enumGetBox(OverlayTextLocation_$type, 0)], 'OverlayTextMemberPath:aea:afb', [2, null], 'OverlayText:adq:afc', [2, null], 'OverlayTextVerticalMargin:adg:afd', [1, NaN], 'OverlayTextVerticalPadding:adh:afe', [1, NaN], 'OverlayTextVisible:acy:aff', [0, true]]);
    return DataAnnotationShapeLayer;
}(DataAnnotationAxisLayer));
export { DataAnnotationShapeLayer };
/**
 * @hidden
 */
var DataAnnotationShapeLayerView = /** @class */ /*@__PURE__*/ (function (_super) {
    __extends(DataAnnotationShapeLayerView, _super);
    function DataAnnotationShapeLayerView(a) {
        var _this = _super.call(this, a) || this;
        _this.cn = null;
        _this.co = null;
        _this.ct = null;
        _this.cs = null;
        _this.cq = null;
        _this.cr = null;
        _this.cp = null;
        _this.cn = a;
        _this.ct = new List$1(Path.$, 0);
        return _this;
    }
    DataAnnotationShapeLayerView.prototype.a4 = function () {
        var _this = this;
        _super.prototype.a4.call(this);
        this.co = ((function () {
            var $ret = new Pool$1(Path.$);
            $ret.create = runOn(_this, _this.c6);
            $ret.activate = runOn(_this, _this.cv);
            $ret.disactivate = runOn(_this, _this.cx);
            $ret.destroy = runOn(_this, _this.cw);
            return $ret;
        })());
        this.cs = new List$1(TextBlock.$, 0);
        this.cq = ((function () {
            var $ret = new Pool$1(TextBlock.$);
            $ret.create = runOn(_this, _this.c5);
            $ret.activate = runOn(_this, _this.c1);
            $ret.disactivate = runOn(_this, _this.c3);
            $ret.destroy = runOn(_this, _this.c2);
            return $ret;
        })());
        this.cr = new List$1(Rectangle.$, 0);
        this.cp = ((function () {
            var $ret = new Pool$1(Rectangle.$);
            $ret.create = runOn(_this, _this.c7);
            $ret.activate = runOn(_this, _this.cy);
            $ret.disactivate = runOn(_this, _this.c0);
            $ret.destroy = runOn(_this, _this.cz);
            return $ret;
        })());
        this.cn.ael();
    };
    DataAnnotationShapeLayerView.prototype.cu = function () {
    };
    DataAnnotationShapeLayerView.prototype.c5 = function () {
        var a = new TextBlock();
        this.cs.add(a);
        return a;
    };
    DataAnnotationShapeLayerView.prototype.c2 = function (a) {
        if (this.cs.contains(a)) {
            this.cs.remove(a);
        }
    };
    DataAnnotationShapeLayerView.prototype.c1 = function (a) {
        a._visibility = 0;
        a.s = 0;
    };
    DataAnnotationShapeLayerView.prototype.c3 = function (a) {
        a._visibility = 1;
    };
    DataAnnotationShapeLayerView.prototype.c7 = function () {
        var a = new Rectangle();
        this.cr.add(a);
        return a;
    };
    DataAnnotationShapeLayerView.prototype.cz = function (a) {
        a.dataContext = null;
        if (this.cr.contains(a)) {
            this.cr.remove(a);
        }
    };
    DataAnnotationShapeLayerView.prototype.cy = function (a) {
        a._visibility = 0;
    };
    DataAnnotationShapeLayerView.prototype.c0 = function (a) {
        a._visibility = 1;
    };
    DataAnnotationShapeLayerView.prototype.c6 = function () {
        var a = new Path();
        a.j = new TranslateTransform();
        this.ct.add(a);
        return a;
    };
    DataAnnotationShapeLayerView.prototype.cv = function (a) {
        a._visibility = 0;
    };
    DataAnnotationShapeLayerView.prototype.cx = function (a) {
        a._visibility = 1;
    };
    DataAnnotationShapeLayerView.prototype.cw = function (a) {
        this.ct.remove(a);
    };
    DataAnnotationShapeLayerView.prototype.c4 = function (a, b, c, d) {
        if (a.an == null || a.an.c.x != d || a.an.d.x != c) {
            var e = ((function () {
                var $ret = new LineGeometry();
                $ret.d = { $type: Point_$type, x: c, y: b };
                $ret.c = { $type: Point_$type, x: d, y: b };
                return $ret;
            })());
            a.an = e;
        }
    };
    DataAnnotationShapeLayerView.prototype.bj = function (a, b) {
        _super.prototype.bj.call(this, a, b);
        if (a.d && !b) {
            for (var c = 0; c < this.ct.count; c++) {
                var d = this.ct._inner[c];
                if (d._visibility == 0) {
                    a.t(d);
                }
            }
            for (var e = 0; e < this.cr.count; e++) {
                var f = this.cr._inner[e];
                if (f._visibility == 0) {
                    a.w(f);
                }
            }
            for (var g = 0; g < this.cs.count; g++) {
                var h = this.cs._inner[g];
                if (h._visibility == 0) {
                    a.ae(h.dataContext);
                    a.x(h);
                }
            }
        }
    };
    DataAnnotationShapeLayerView.prototype.ax = function (a) {
        _super.prototype.ax.call(this, a);
        for (var b = 0; b < this.ct.count; b++) {
            this.f.bc.exportPathData(a, this.ct._inner[b], "DataAnnotationPath", ["Main", "DataAnnotation"]);
        }
    };
    DataAnnotationShapeLayerView.$t = markType(DataAnnotationShapeLayerView, 'DataAnnotationShapeLayerView', AnnotationLayerView.$);
    return DataAnnotationShapeLayerView;
}(AnnotationLayerView));
export { DataAnnotationShapeLayerView };
