/*
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 { AnnotationLayer } from "./AnnotationLayer";
import { DependencyProperty } from "igniteui-angular-core";
import { Base, runOn, delegateCombine, String_$type, Array_$type, enumGetBox, EnumUtil, typeCast, fromEnum, delegateRemove, Point_$type, Date_$type, markType, markDep } from "igniteui-angular-core";
import { Series } from "./Series";
import { CalloutPlacementPositionsCollection } from "./CalloutPlacementPositionsCollection";
import { HighlightedValueLabelMode_$type } from "igniteui-angular-core";
import { AutoCalloutVisibilityMode_$type } from "./AutoCalloutVisibilityMode";
import { Brush } from "igniteui-angular-core";
import { Thickness } from "igniteui-angular-core";
import { CalloutCollisionMode_$type } from "igniteui-angular-core";
import { FontUtil } from "igniteui-angular-core";
import { Rect } from "igniteui-angular-core";
import { BindingFormatter } from "igniteui-angular-core";
import { CalloutLayerFrame } from "./CalloutLayerFrame";
import { Size } from "igniteui-angular-core";
import { HashSet$1 } from "igniteui-angular-core";
import { CalloutAnnotationWrapper } from "./CalloutAnnotationWrapper";
import { List$1 } from "igniteui-angular-core";
import { LinkedList$1 } from "igniteui-angular-core";
import { Dictionary$2 } from "igniteui-angular-core";
import { LinkedListNode$1 } from "igniteui-angular-core";
import { LabelCollisionManager } from "igniteui-angular-core";
import { SeriesPointOfInterest } from "./SeriesPointOfInterest";
import { CalloutAnnotation } from "./CalloutAnnotation";
import { IFastItemsSource_$type } from "igniteui-angular-core";
import { DeviceUtils } from "igniteui-angular-core";
import { CalloutLabelUpdatingEventArgs } from "./CalloutLabelUpdatingEventArgs";
import { CalloutSeriesSelectingEventArgs } from "./CalloutSeriesSelectingEventArgs";
import { CalloutStyleUpdatingEventArgs } from "./CalloutStyleUpdatingEventArgs";
import { BrushUtilCore } from "igniteui-angular-core";
import { LabelCollisionInfo } from "igniteui-angular-core";
import { BrushUtil } from "igniteui-angular-core";
import { CalloutRenderStyleUpdatingEventArgs } from "./CalloutRenderStyleUpdatingEventArgs";
import { IHasCategoryAxis_$type } from "./IHasCategoryAxis";
import { QuadTreeBoundingBox } from "igniteui-angular-core";
import { ScalerParams } from "./ScalerParams";
import { ViewportUtils } from "./ViewportUtils";
import { CalloutContentUpdatingEventArgs } from "./CalloutContentUpdatingEventArgs";
import { CalloutKey } from "./CalloutKey";
import { DataContext } from "igniteui-angular-core";
import { HashPool$2 } from "igniteui-angular-core";
import { AxisRange } from "./AxisRange";
import { PropertyMetadata } from "igniteui-angular-core";
import { isNaN_, isInfinity } from "igniteui-angular-core";
import { stringIsNullOrEmpty } from "igniteui-angular-core";
import { FastItemObjectColumn } from "igniteui-angular-core";
import { AnnotationLayerView } from "./AnnotationLayerView";
import { TextBlock } from "igniteui-angular-core";
import { Color } from "igniteui-angular-core";
import { Line } from "igniteui-angular-core";
import { CalloutViewHelper } from "./CalloutViewHelper";
import { Rectangle } from "igniteui-angular-core";
import { TranslateTransform } from "igniteui-angular-core";
/**
 * @hidden
 */
var CalloutLayer = /** @class */ /*@__PURE__*/ (function (_super) {
    __extends(CalloutLayer, _super);
    function CalloutLayer() {
        var _this = _super.call(this) || this;
        _this.abk = false;
        _this.abf = false;
        _this.abh = false;
        _this.abg = true;
        _this.agz = new Size(1, 0, 0);
        _this.abe = true;
        _this.calloutStyleUpdating = null;
        _this.calloutRenderStyleUpdating = null;
        _this.aa2 = null;
        _this.aa3 = null;
        _this.aa4 = null;
        _this.aa1 = null;
        _this.aa0 = null;
        _this.ab9 = new HashSet$1(CalloutAnnotationWrapper.$, 0);
        _this.acc = new List$1(CalloutAnnotationWrapper.$, 0);
        _this.acd = new List$1(CalloutAnnotationWrapper.$, 0);
        _this.aar = null;
        _this.aaf = null;
        _this.aay = null;
        _this.ace = new List$1(CalloutAnnotationWrapper.$, 0);
        _this.acf = new List$1(CalloutAnnotationWrapper.$, 0);
        _this.acx = 0;
        _this.aci = -1;
        _this.ach = -1;
        _this.aca = new LinkedList$1(CalloutAnnotationWrapper.$);
        _this.ab7 = new Dictionary$2(CalloutAnnotationWrapper.$, LinkedListNode$1.$.specialize(CalloutAnnotationWrapper.$), 0);
        _this.aba = null;
        _this.agx = new Rect(0, 0, 0, 1, 1);
        _this.abm = false;
        _this.abo = false;
        _this.acw = 0;
        _this.agw = Rect.empty;
        _this.abl = false;
        _this.abn = false;
        _this.calloutContentUpdating = null;
        _this.calloutLabelUpdating = null;
        _this.calloutSeriesSelecting = null;
        _this.acb = new List$1(SeriesPointOfInterest.$, 0);
        _this.abq = false;
        _this.abr = false;
        _this.acj = 0;
        _this.abp = false;
        _this.aai = null;
        _this.abi = false;
        _this.abj = true;
        _this.aaj = 1;
        FastItemObjectColumn.m();
        _this.aaf = null;
        _this.aar = new CalloutPlacementPositionsCollection();
        var a = _this.aar;
        a.collectionChanged = delegateCombine(a.collectionChanged, runOn(_this, _this.aev));
        _this.xu = true;
        var b = new CalloutLayerFrame();
        var c = new CalloutLayerFrame();
        var d = new CalloutLayerFrame();
        var e = _this.kh / 1000;
        _this.xm = b;
        _this.xl = c;
        _this.xn = d;
        _this.ab = CalloutLayer.$;
        return _this;
    }
    CalloutLayer.prototype.bk = function () {
        return new CalloutLayer();
    };
    CalloutLayer.prototype.get_eq = function () {
        return true;
    };
    CalloutLayer.prototype.aev = function (a, b) {
        this.ae4();
    };
    CalloutLayer.prototype.ae4 = function () {
        this.aaf = this.aah(this.aas);
        this.ae1();
    };
    CalloutLayer.prototype.aew = function (a, b) {
        this.acd.clear();
        this.ry(false);
    };
    CalloutLayer.prototype.ph = function (a, b, c, d) {
        _super.prototype.ph.call(this, a, b, c, d);
        var e = this.ab8();
        switch (a) {
            case 3:
                this.afc(b, e);
                break;
            case 1:
                for (var f = b; f < b + c; f++) {
                    var g = new CalloutAnnotation();
                    var h = new CalloutAnnotationWrapper();
                    h.b = g;
                    h.b.series = this.aax;
                    this.acd.insert(f, h);
                    this.afc(f, e);
                }
                break;
            case 0:
                this.acd.v(b, c);
                break;
            case 2:
                for (var i = b; i < b + c; i++) {
                    this.afc(i, e);
                }
                break;
            case 4:
                this.acd.clear();
                for (var j = 0; j < this.dp.count; j++) {
                    var k = new CalloutAnnotation();
                    var l = new CalloutAnnotationWrapper();
                    l.b = k;
                    l.b.series = this.aax;
                    this.acd.add(l);
                    this.afc(j, e);
                }
                break;
        }
        this.ry(true);
    };
    CalloutLayer.prototype.gg = function (a) {
        return false;
    };
    CalloutLayer.prototype.ag1 = function () {
        var a = new Thickness(0, DeviceUtils.g(3));
        if (isNaN_(this.ag0.left) || isNaN_(this.ag0.top) || isNaN_(this.ag0.right) || isNaN_(this.ag0.bottom)) {
            a = new Thickness(0, DeviceUtils.g(3));
        }
        else {
            a = this.ag0;
        }
        return a;
    };
    CalloutLayer.prototype.w3 = function () {
        if (!this.abe) {
            return this.agz;
        }
        var a = 0;
        var b = 0;
        if (!this.abs) {
            this.agz = new Size(1, 0, 0);
            return this.agz;
        }
        if (this.abu) {
            this.abk = true;
            var c = new CalloutLayerFrame();
            this.y3(c, this.cw);
            this.abk = false;
            if (this.ace != null && this.ace.count == 0) {
                this.agz = new Size(1, 0, 0);
                return this.agz;
            }
        }
        var d = this.ag1();
        var e = -1.7976931348623157E+308;
        var f = -1.7976931348623157E+308;
        for (var g = 0; g < this.ace.count; g++) {
            var h = this.ace._inner[g].b.text;
            var i = this.aaq.c7(h, d);
            if (!isNaN_(i.height)) {
                f = Math.max(i.height, f);
            }
            if (!isNaN_(i.width)) {
                e = Math.max(i.width, e);
            }
        }
        a = f;
        b = e;
        if (!isNaN_(this.act)) {
            a += this.act;
        }
        if (!isNaN_(this.act)) {
            b += this.act;
        }
        if (!isNaN_(this.acn)) {
            a = Math.max(a, this.acn);
        }
        if (!isNaN_(this.acl)) {
            a = Math.min(a, this.acl);
        }
        if (!isNaN_(this.aco)) {
            b = Math.max(b, this.aco);
        }
        if (!isNaN_(this.acm)) {
            b = Math.min(b, this.acm);
        }
        this.abg = false;
        this.agz = new Size(1, b, a);
        return this.agz;
    };
    CalloutLayer.prototype.ab8 = function () {
        var a = new Dictionary$2(String_$type, Series.$, 0);
        if (this.dc != null) {
            for (var b = 0; b < this.dc.series.count; b++) {
                var c = this.dc.series._inner[b];
                if (c.name != null && !a.containsKey(c.name)) {
                    a.addItem(c.name, c);
                }
            }
        }
        return a;
    };
    CalloutLayer.prototype.afc = function (a, b) {
        var _this = this;
        if (this.aa9 == null || this.aa7 == null) {
            return;
        }
        var c = a;
        if (this.aa8 != null) {
            c = this.aa8.item(a);
        }
        var d = this.aa9.item(a);
        var e = this.aa7.item(a);
        var f = this.acd._inner[a];
        if (this.aa6 != null) {
            if (f.b.ab != this.aa6.item(a)) {
                f.b.key = this.aa6.item(a);
            }
        }
        if (this.ab7.containsKey(f)) {
            f.b = this.ab7.item(f).c.b;
        }
        f.b.xValue = c;
        f.b.yValue = d;
        var g = true;
        if (this.calloutLabelUpdating != null) {
            var h = ((function () {
                var $ret = new CalloutLabelUpdatingEventArgs();
                $ret.d = c;
                $ret.e = d;
                $ret.item = _this.dp.item(a);
                return $ret;
            })());
            this.calloutLabelUpdating(this, h);
            if (h.c != null && !Base.equalsStatic(h.c, f.b.ao)) {
                g = false;
                var i = h.c;
                if (this.aai != null) {
                    f.b.text = this.aai.i(i);
                }
                else {
                    f.b.text = i != null ? i.toString() : "";
                }
            }
        }
        if (g) {
            if (this.aai != null) {
                f.b.text = this.aai.i(e);
            }
            else {
                f.b.text = e != null ? e.toString() : "";
            }
        }
        if (this.aa5 != null) {
            f.b.content = this.aa5.item(a);
        }
        else {
            f.b.content = this.dp.item(a);
        }
        if (this.calloutSeriesSelecting != null) {
            var j = ((function () {
                var $ret = new CalloutSeriesSelectingEventArgs();
                $ret.c = c;
                $ret.d = d;
                $ret.item = _this.dp.item(a);
                return $ret;
            })());
            this.calloutSeriesSelecting(this, j);
            if (j.a != null) {
                f.b.series = j.a;
            }
            else if (j.e != null) {
                if (b.containsKey(j.e)) {
                    f.b.series = b.item(j.e);
                }
            }
        }
        this.afd(f);
    };
    CalloutLayer.prototype.afd = function (a) {
        var b = new Thickness(0, DeviceUtils.g(3));
        if (isNaN_(this.ag0.left) || isNaN_(this.ag0.top) || isNaN_(this.ag0.right) || isNaN_(this.ag0.bottom)) {
            b = new Thickness(0, DeviceUtils.g(3));
        }
        else {
            b = this.ag0;
        }
        var c = DeviceUtils.g(3);
        if (isNaN_(this.ack)) {
            c = DeviceUtils.g(3);
        }
        else {
            c = this.ack;
        }
        var d = this.agq != null && !this.ab3 ? this.agq : this.aaq.c1(a.b.l, a.b.itemColor);
        var e = this.agv != null ? this.agv : null;
        var f = this.agt != null ? this.agt : this.aaq.c4();
        var g = this.agr != null ? this.agr : this.aaq.c2();
        var h = this.agu != null && !this.ab4 ? this.agu : this.aaq.c5(a.b.l, a.b.itemColor);
        var i = this.ags != null ? this.ags : this.aaq.c3(a.b.l, a.b.itemColor);
        var j = isNaN_(this.acu) ? 0 : this.acu;
        if (e == null && (this.ab1 || this.agt != null || this.agr != null)) {
            var k = d;
            if (k == null || BrushUtilCore.a(d)) {
                k = this.dc != null ? this.dc.w2 : null;
                if (a.c != null && (a.c.b == 8 || a.c.b == 9)) {
                    k = a.b.itemColor;
                }
                if (k == null || BrushUtilCore.a(d)) {
                    k = BrushUtil.j(255, 255, 255, 255);
                }
            }
            e = BrushUtil.l(k, g, f);
        }
        if (e == null) {
            e = this.aaq.c4();
        }
        if (this.abz && this.calloutStyleUpdating != null) {
            var l = new CalloutStyleUpdatingEventArgs();
            l.item = a.b.aa;
            l.xValue = a.b.ac;
            l.yValue = a.b.ad;
            l.series = a.b.l;
            l.background = d;
            l.textColor = e;
            l.outline = h;
            l.leaderBrush = i;
            l.strokeThickness = j;
            this.calloutStyleUpdating(this, l);
            d = l.background;
            e = l.textColor;
            h = l.outline;
            i = l.leaderBrush;
            j = l.strokeThickness;
        }
        a.b.backgroundPadding = b;
        a.b.backgroundCornerRadius = c;
        a.b.background = d;
        a.b.textColor = e;
        a.b.outline = h;
        a.b.leaderBrush = i;
        a.b.strokeThickness = j;
    };
    CalloutLayer.prototype.ku = function (a, b) {
        var c = this.ni(b);
        if (c == CalloutLayer.$$p[34]) {
            return this.kv(a, b, this.aea);
        }
        if (c == CalloutLayer.$$p[45]) {
            return this.kv(a, b, this.aeq);
        }
        if (c == CalloutLayer.$$p[46]) {
            return this.kv(a, b, this.aet);
        }
        if (c == CalloutLayer.$$p[31]) {
            return this.kv(a, b, this.ad4);
        }
        if (c == CalloutLayer.$$p[25]) {
            return this.kv(a, b, this.adw);
        }
        return _super.prototype.ku.call(this, a, b);
    };
    CalloutLayer.prototype.mi = function (a) {
        var b = this.ni(a);
        if (b == CalloutLayer.$$p[34]) {
            return this.aea;
        }
        if (b == CalloutLayer.$$p[45]) {
            return this.aeq;
        }
        if (b == CalloutLayer.$$p[46]) {
            return this.aet;
        }
        if (b == CalloutLayer.$$p[31]) {
            return this.ad4;
        }
        if (b == CalloutLayer.$$p[25]) {
            return this.adw;
        }
        return _super.prototype.mi.call(this, a);
    };
    Object.defineProperty(CalloutLayer.prototype, "aa7", {
        get: function () {
            return this.aa2;
        },
        set: function (a) {
            if (this.aa2 != a) {
                var b = this.aa2;
                this.aa2 = a;
                this.raisePropertyChanged("LabelColumn", b, this.aa2);
            }
        },
        enumerable: false,
        configurable: true
    });
    Object.defineProperty(CalloutLayer.prototype, "aa8", {
        get: function () {
            return this.aa3;
        },
        set: function (a) {
            if (this.aa3 != a) {
                var b = this.aa3;
                this.aa3 = a;
                this.raisePropertyChanged("XColumn", b, this.aa3);
            }
        },
        enumerable: false,
        configurable: true
    });
    Object.defineProperty(CalloutLayer.prototype, "aa9", {
        get: function () {
            return this.aa4;
        },
        set: function (a) {
            if (this.aa4 != a) {
                var b = this.aa4;
                this.aa4 = a;
                this.raisePropertyChanged("YColumn", b, this.aa4);
            }
        },
        enumerable: false,
        configurable: true
    });
    Object.defineProperty(CalloutLayer.prototype, "aa6", {
        get: function () {
            return this.aa1;
        },
        set: function (a) {
            if (this.aa1 != a) {
                var b = this.aa1;
                this.aa1 = a;
                this.raisePropertyChanged("KeyColumn", b, this.aa1);
            }
        },
        enumerable: false,
        configurable: true
    });
    Object.defineProperty(CalloutLayer.prototype, "aa5", {
        get: function () {
            return this.aa0;
        },
        set: function (a) {
            if (this.aa0 != a) {
                var b = this.aa0;
                this.aa0 = a;
                this.raisePropertyChanged("ContentColumn", b, this.aa0);
            }
        },
        enumerable: false,
        configurable: true
    });
    CalloutLayer.prototype.aey = function (a, b) {
        if (b.propertyName == CalloutAnnotation.$$p[15] || b.propertyName == CalloutAnnotation.$$p[16]) {
            var c = a.k;
            if (!this.ab9.contains(c)) {
                this.ab9.add_1(c);
                this.acc.add(c);
                this.ry(false);
            }
        }
    };
    CalloutLayer.prototype.ct = function () {
        return new CalloutLayerView(this);
    };
    CalloutLayer.prototype.q7 = function (a) {
        _super.prototype.q7.call(this, a);
        this.aaq = a;
    };
    Object.defineProperty(CalloutLayer.prototype, "aas", {
        get: function () {
            return this.aar;
        },
        set: function (a) {
            var b = this.aas;
            if (a != b) {
                this.aar = a;
                this.raisePropertyChanged("AllowedPositions", b, this.aas);
            }
        },
        enumerable: false,
        configurable: true
    });
    CalloutLayer.prototype.gv = function (a) {
        if (this.aax == null) {
            return true;
        }
        if (this.aax == a) {
            return true;
        }
        return false;
    };
    Object.defineProperty(CalloutLayer.prototype, "aal", {
        get: function () {
            return EnumUtil.getEnumValue(AutoCalloutVisibilityMode_$type, this.c(CalloutLayer.af2));
        },
        set: function (a) {
            this.h(CalloutLayer.af2, enumGetBox(AutoCalloutVisibilityMode_$type, a));
        },
        enumerable: false,
        configurable: true
    });
    Object.defineProperty(CalloutLayer.prototype, "aak", {
        get: function () {
            return this.aaj;
        },
        set: function (a) {
            this.aaj = a;
        },
        enumerable: false,
        configurable: true
    });
    Object.defineProperty(CalloutLayer.prototype, "ag0", {
        get: function () {
            return new Thickness(1, this.acq, this.acs, this.acr, this.acp);
        },
        enumerable: false,
        configurable: true
    });
    Object.defineProperty(CalloutLayer.prototype, "aaz", {
        get: function () {
            if (this.aay == null) {
                this.aay = FontUtil.toFontInfo(this.j3, this.aeg);
            }
            return this.aay;
        },
        enumerable: false,
        configurable: true
    });
    CalloutLayer.prototype.y1 = function (a, b) {
        if (this.aax == null || this.aax == a) {
            if (!this.a1.c) {
                this.ry(b);
            }
        }
    };
    CalloutLayer.prototype.y3 = function (a, b) {
        var e_1, _a;
        var _this = this;
        _super.prototype.y3.call(this, a, b);
        var c = a;
        c.q.clear();
        c.r.clear();
        c.n.clear();
        c.f.clear();
        c.i.clear();
        c.h.clear();
        c.k.clear();
        c.m.clear();
        c.l.clear();
        c.j.clear();
        c.g.clear();
        c.o.clear();
        c.p.clear();
        c.u.clear();
        c.v.clear();
        c.s.clear();
        c.t.clear();
        this.acf = this.acg();
        this.ace = new List$1(CalloutAnnotationWrapper.$, 0);
        var d = Number.POSITIVE_INFINITY;
        var e = true;
        if (this.abw) {
            if (this.xs(this.aax)) {
                if (typeCast(IHasCategoryAxis_$type, this.aax) !== null) {
                    var f = this.aax.iy() > 0 ? this.aax.iy() : this.aax.getCategoryWidth();
                    if (!isNaN_(f) && !isInfinity(f) && f > 0) {
                        d = Math.min(d, f);
                    }
                }
                this.ae6(this.aax, c, this.ace);
            }
            else {
                try {
                    for (var _b = __values(fromEnum(this.dc.series)), _c = _b.next(); !_c.done; _c = _b.next()) {
                        var g = _c.value;
                        if (this.xs(g)) {
                            if (typeCast(IHasCategoryAxis_$type, g) !== null) {
                                var h = g.iy() > 0 ? g.iy() : g.getCategoryWidth();
                                if (!isNaN_(h) && !isInfinity(h) && h > 0) {
                                    d = Math.min(d, h);
                                }
                            }
                            if (!g.eu) {
                                if (!g.isVertical) {
                                    e = false;
                                }
                            }
                            var i = false;
                            if (g.ei && this.aaw == 0 || this.aaw == 3 || this.aaw == 2) {
                                if (this.aaw == 0 || this.aaw == 2) {
                                    i = true;
                                }
                                g.p7(function (j) {
                                    _this.ae6(j, c, _this.ace);
                                    return true;
                                });
                            }
                            if (!i) {
                                this.ae6(g, c, this.ace);
                            }
                        }
                    }
                }
                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.abw && this.aak == 2) {
            var j = 0;
            var k = 0;
            var l = 1.7976931348623157E+308;
            var m = 1.7976931348623157E+308;
            var n = -1.7976931348623157E+308;
            var o = -1.7976931348623157E+308;
            if (this.ace.count > 0) {
                if (this.ace._inner[0].c != null) {
                    j = this.ace._inner[0].e;
                    k = this.ace._inner[0].f;
                }
                for (var p = 0; p < this.ace.count; p++) {
                    var q = this.ace._inner[p];
                    if (q.c != null) {
                        var r = q.e;
                        var s = q.f;
                        if (r != j) {
                            l = Math.min(l, Math.abs(r - j));
                        }
                        if (s != k) {
                            m = Math.min(m, Math.abs(s - k));
                        }
                        n = Math.max(q.c.p + q.c.p, n);
                        o = Math.max(q.c.o + q.c.o, o);
                    }
                }
                if (e) {
                    if (!isNaN_(d) && !isInfinity(d)) {
                        if (o > d) {
                            this.ace.clear();
                        }
                    }
                    else {
                        if (o > m) {
                            this.ace.clear();
                        }
                    }
                }
                else {
                    if (!isNaN_(d) && !isInfinity(d)) {
                        if (n > d) {
                            this.ace.clear();
                        }
                    }
                    else {
                        if (n > l) {
                            this.ace.clear();
                        }
                    }
                }
            }
        }
        var t = this.acx <= 0 && this.ace.count > 0;
        var u = this.acx > 0 && this.ace.count <= 0;
        var v = t || u;
        var w = this.acx != this.ace.count;
        if (t && this.abv) {
            return;
        }
        if (!this.abk) {
            this.ae5(c, this.acf, this.ace);
        }
        var x = this.da.ig();
        var y = this.da.ie();
        var z = x != this.aci;
        var aa = y != this.ach;
        var ab = z || aa;
        if (ab) {
            this.aci = x;
            this.ach = y;
        }
        this.acx = this.ace.count;
        if (this.abk) {
            return;
        }
        if (!this.abf && this.abs && this.abt && this.ace.count > 0 && this.ace.count == this.acx && this.aak == 2) {
            this.abf = true;
            this.ae8();
        }
    };
    CalloutLayer.prototype.sz = function (a, b) {
        _super.prototype.sz.call(this, a, b);
        var c = b.width - this.agx.width;
        var d = b.height - this.agx.height;
        var e = 0;
        if (Math.abs(c) > Math.abs(d)) {
            e = c;
            this.acj = c * this.w2.width;
        }
        else {
            e = d;
            this.acj = d * this.w2.height;
        }
        if (e > 0 && this.acj > 5) {
            this.abr = true;
        }
        if (e < 0 && this.acj > 5) {
            this.abq = true;
        }
    };
    CalloutLayer.prototype.sy = function (a, b) {
        _super.prototype.sy.call(this, a, b);
        if (!a.equals1(b)) {
            this.abp = true;
        }
    };
    Object.defineProperty(CalloutLayer.prototype, "agy", {
        get: function () {
            return this.agw;
        },
        set: function (a) {
            this.agw = a;
        },
        enumerable: false,
        configurable: true
    });
    CalloutLayer.prototype.ae5 = function (a, b, c) {
        var e_2, _a;
        if (this.dc != null) {
            this.agx = this.dc.xm;
        }
        if (this.w2.isEmpty) {
            return;
        }
        this.agy = new Rect(0, this.w2.left, this.w2.top, this.w2.width, this.w2.height);
        if (this.aba != null && this.adt != null && this.adt != this.aba.bd) {
            this.ae0();
        }
        if (this.aba != null && this.aba.j != this.abc()) {
            this.ae0();
        }
        if (this.aba == null) {
            var d = this.abb();
            if (d != null) {
                this.aba = d;
                var e = this.aba;
                e.labelsMoved = delegateCombine(e.labelsMoved, runOn(this, this.aex));
            }
            else {
                var f = this.wt(this.cw);
                var g = new Array(2);
                g[0] = 0;
                g[1] = 3;
                if (this.aax != null) {
                    if (this.aax.isVertical) {
                        g = new Array(2);
                        g[0] = 2;
                        g[1] = 1;
                    }
                }
                else {
                    var h = false;
                    if (this.dc != null && this.dc.series.count > 0) {
                        h = true;
                        try {
                            for (var _b = __values(fromEnum(this.dc.series)), _c = _b.next(); !_c.done; _c = _b.next()) {
                                var i = _c.value;
                                if (!i.eu) {
                                    if (!i.isVertical) {
                                        h = false;
                                    }
                                }
                            }
                        }
                        catch (e_2_1) {
                            e_2 = { error: e_2_1 };
                        }
                        finally {
                            try {
                                if (_c && !_c.done && (_a = _b.return))
                                    _a.call(_b);
                            }
                            finally {
                                if (e_2)
                                    throw e_2.error;
                            }
                        }
                    }
                    if (h) {
                        g = new Array(2);
                        g[0] = 2;
                        g[1] = 1;
                    }
                }
                if (this.aan == 4 || this.aan == 6) {
                    g = new Array(4);
                    g[0] = 10;
                    g[1] = 11;
                    g[2] = 8;
                    g[3] = 9;
                }
                if (this.aan == 5) {
                    g = new Array(4);
                    g[0] = 9;
                    g[1] = 10;
                    g[2] = 11;
                    g[3] = 8;
                }
                if (this.aan == 7) {
                    g = new Array(4);
                    g = new Array(4);
                    g[0] = 8;
                    g[1] = 10;
                    g[2] = 11;
                    g[3] = 9;
                }
                this.aba = new LabelCollisionManager(this.w2.right, this.w2.bottom, this.w2, this.aaq.k(), this.act, this.abc(), g, this.ac1(), this.ac0(), this.abx, this.aaf);
                this.aba.v = this.ab0;
                if (this.adt != null) {
                    this.aba.bd = this.adt;
                    this.aba.bb = this;
                }
                var j = this.aba;
                j.labelsMoved = delegateCombine(j.labelsMoved, runOn(this, this.aex));
            }
        }
        if (this.abq) {
            this.abq = false;
            if (this.aba.a9 > 2) {
                this.abo = true;
            }
        }
        if (this.abr) {
            this.abr = false;
            if (this.acj > 5) {
                this.abo = true;
            }
        }
        if (this.abp) {
            this.abp = false;
            this.aba.bs(this.w2.right, this.w2.bottom, this.w2);
            this.abo = true;
        }
        var k = new HashSet$1(CalloutAnnotationWrapper.$, 0);
        var l = new HashSet$1(CalloutAnnotationWrapper.$, 0);
        var m = new List$1(CalloutAnnotationWrapper.$, 0);
        var n = new List$1(CalloutAnnotationWrapper.$, 0);
        var o = new HashSet$1(CalloutAnnotationWrapper.$, 0);
        for (var p = 0; p < b.count; p++) {
            o.add_1(b._inner[p]);
        }
        for (var q = 0; q < c.count; q++) {
            o.add_1(c._inner[q]);
        }
        var r = this.aca.c;
        while (r != null) {
            var s = r.a;
            if (!o.contains(r.c)) {
                n.add(r.c);
                l.add_1(r.c);
                var t = r.c.b;
                t.propertyChanged = delegateRemove(t.propertyChanged, runOn(this, this.aey));
                this.aca.h(r);
                this.ab7.removeItem(r.c);
                this.aba.br(r.c.c);
            }
            r = s;
        }
        for (var u = 0; u < b.count; u++) {
            if (!this.ab7.containsKey(b._inner[u])) {
                this.aca.f(b._inner[u]);
                var v = b._inner[u].b;
                v.propertyChanged = delegateCombine(v.propertyChanged, runOn(this, this.aey));
                this.ab7.addItem(b._inner[u], this.aca.d);
                m.add(b._inner[u]);
                k.add_1(b._inner[u]);
                this.abo = true;
            }
        }
        for (var w = 0; w < c.count; w++) {
            if (!this.ab7.containsKey(c._inner[w])) {
                this.aca.f(c._inner[w]);
                this.ab7.addItem(c._inner[w], this.aca.d);
                var x = c._inner[w].b;
                x.propertyChanged = delegateCombine(x.propertyChanged, runOn(this, this.aey));
                m.add(c._inner[w]);
                k.add_1(c._inner[w]);
                this.abo = true;
            }
        }
        if (this.abl == true) {
            this.abl = false;
            this.abo = true;
        }
        var y = false;
        if (this.acc.count > 0) {
            y = true;
            this.acc.clear();
            this.ab9.clear();
        }
        r = this.aca.c;
        while (r != null) {
            var z = this.abd(r.c);
            if (z == null) {
                return;
            }
            if (!Base.equalsStatic(z, r.c.c.e)) {
                var aa = false;
                if (r.c.c.e == null) {
                    aa = true;
                }
                var ab = r.c.c;
                ab.s = z.d;
                ab.t = z.e;
                if (!isNaN_(ab.s) && !isNaN_(ab.t)) {
                    ab.r = z.g;
                    ab.q = z.f;
                    if (ab.c == null) {
                        this.aba.ad(ab, false);
                    }
                    if (aa) {
                        this.aba.be(ab);
                    }
                    else {
                        this.aba.bo(ab);
                    }
                }
            }
            r = r.a;
        }
        var ac = this.aba.ba();
        var ad = this.aba.af();
        if (!this.abo && y && (ac != 0 || ad)) {
            {
                this.abo = true;
            }
        }
        if (ad) {
            if (this.aba.x()) {
                this.abo = true;
            }
        }
        if (this.abo && (ac != 0 || ad || this.abm)) {
            this.abm = false;
            this.abo = false;
            this.acw = 0x7FFFFFFF;
            if (this.adt != null) {
                var ae = true;
                for (var af = 0; af < this.dc.series.count; af++) {
                    var ag = this.dc.series._inner[af];
                    if (ag.eu && typeCast(CalloutLayer.$, ag) !== null) {
                        var ah = ag;
                        if (ah.adt == this.adt) {
                            if (!ah.agy.equals1(this.aba.b0)) {
                                ae = false;
                                break;
                            }
                        }
                    }
                }
                if (ae) {
                    this.aba.bv();
                }
                else {
                    this.aba.bf();
                    this.aba.bg();
                }
            }
            else {
                this.aba.bv();
            }
        }
        else {
            this.aba.bg();
        }
        var ai = this.aca.c;
        var aj;
        var ak;
        var al;
        var am;
        var an;
        var ao;
        var ap;
        var aq;
        var ar;
        var as;
        var at;
        var au;
        var av;
        var aw;
        var ax;
        var ay;
        var az = this.aby;
        var a0 = this.ab0;
        var a1 = this.cw.b5();
        while (ai != null) {
            var a2 = ai.c;
            var a3 = a2.b;
            aj = a3.bm;
            ak = a3.bp;
            al = a3.bo;
            am = a3.backgroundPadding.left;
            an = a3.backgroundPadding.top;
            ao = a3.backgroundPadding.right;
            ap = a3.backgroundPadding.bottom;
            ar = a3.backgroundCornerRadius;
            aq = a3.y;
            as = a3.bq;
            at = a3.ao;
            au = a3.aa;
            var a4 = a2.c;
            av = a4.s - (a4.k - a4.p);
            aw = a4.t - (a4.l - a4.o);
            ax = a4.k - a4.p;
            ay = a4.l - a4.o;
            var a5 = false;
            if (a0) {
                if (a4.c != null && this.aba.ab(a4.c)) {
                    a5 = true;
                }
            }
            if (a2.c.h && !a5) {
                av = NaN;
                aw = NaN;
            }
            if (!a2.c.h && (a2.c.b == 8 || a2.c.b == 9)) {
                al = a1;
                av = a4.k;
                aw = a4.l;
            }
            if (a5) {
                at = this.aei(a2, at);
                var a6 = this.aba.as(a2.c.c);
                if (a6 > 0) {
                    ax += a6;
                    av -= a6;
                }
            }
            if (az) {
                var a7 = new CalloutRenderStyleUpdatingEventArgs();
                a7.background = aj;
                a7.outline = ak;
                a7.leaderBrush = al;
                a7.strokeThickness = aq;
                a7.textColor = as;
                a7.item = au;
                a7.series = a3.l;
                a7.actualPosition = a4.b;
                a7.xValue = a3.ac;
                a7.yValue = a3.ad;
                if (this.calloutRenderStyleUpdating != null) {
                    this.calloutRenderStyleUpdating(this, a7);
                    aj = a7.background;
                    ak = a7.outline;
                    al = a7.leaderBrush;
                    aq = a7.strokeThickness;
                    as = a7.textColor;
                }
            }
            a.n.add1(a2);
            a.f.add(aj);
            a.i.add(ak);
            a.h.add(al);
            a.k.add(am);
            a.m.add(an);
            a.l.add(ao);
            a.j.add(ap);
            a.g.add(ar);
            a.o.add(aq);
            a.p.add(as);
            a.q.add1(at);
            a.r.add1(au);
            a.u.add(av);
            a.v.add(aw);
            a.s.add(ax);
            a.t.add(ay);
            ai = ai.a;
        }
    };
    CalloutLayer.prototype.aei = function (a, b) {
        var c = Math.max(this.aba.as(a.c.c), this.aba.at(a.c.c));
        if (c <= 0) {
            return b;
        }
        var d = b.length;
        var e = this.aaq.c7(b, a.b.backgroundPadding);
        var f = e.width;
        var g = f - c;
        while (f - g > 0.0001 && d > 0) {
            d--;
            b = b.substr(0, d) + "…";
            e = this.aaq.c7(b, a.b.backgroundPadding);
            f = e.width;
        }
        return b;
    };
    CalloutLayer.prototype.ae0 = function () {
        if (this.aba != null) {
            var a = this.aca.c;
            while (a != null) {
                var b = a.c.c;
                if (b != null) {
                    this.aba.br(b);
                }
                a = a.a;
            }
            var c = this.aba;
            c.labelsMoved = delegateRemove(c.labelsMoved, runOn(this, this.aex));
            this.aba = null;
        }
        this.aez();
    };
    CalloutLayer.prototype.abb = function () {
        if (this.dc == null) {
            return null;
        }
        for (var a = 0; a < this.dc.series.count; a++) {
            var b = this.dc.series._inner[a];
            if (b.eu && typeCast(CalloutLayer.$, b) !== null) {
                var c = b;
                if (c != this) {
                    if (c.adt != null && c.adt == this.adt) {
                        if (c.aba != null) {
                            return c.aba;
                        }
                    }
                }
            }
        }
        return null;
    };
    CalloutLayer.prototype.ac0 = function () {
        return 20000;
    };
    CalloutLayer.prototype.ac1 = function () {
        return 300;
    };
    CalloutLayer.prototype.abc = function () {
        switch (this.aan) {
            case 0: return 2;
            case 2: return 1;
            case 3: return 2;
            case 1: return 0;
            case 4: return 3;
            case 7: return 7;
            case 5: return 5;
            case 6: return 6;
        }
        return 2;
    };
    CalloutLayer.prototype.aex = function (a) {
        var b = this.aba.ba();
        var c = this.acw;
        if (b < this.acw) {
            this.acw = b;
            if (c != 0x7FFFFFFF) {
                this.ry(false);
            }
        }
    };
    CalloutLayer.prototype.abd = function (a) {
        var b = this.aax;
        if (a.b.l != null) {
            b = a.b.l;
        }
        if (b == null) {
            for (var c = 0; c < this.dc.series.count; c++) {
                var d = this.dc.series._inner[c];
                if (!d.eu) {
                    b = d;
                    break;
                }
            }
        }
        if (b == null) {
            return null;
        }
        var e = b.ai();
        var f = b.i0();
        var g = null;
        var h = null;
        var i = false;
        for (var j = 0; j < e.length; j++) {
            if (e[j] == null) {
                continue;
            }
            if (e[j].c5) {
                i = true;
                g = e[j];
            }
            else if (e[j].dl) {
                i = true;
                h = e[j];
            }
            else if (e[j].dq) {
                h = e[j];
            }
            else {
                g = e[j];
            }
        }
        if (g == null || h == null) {
            return null;
        }
        if (!g.dp() || !h.dp()) {
            return null;
        }
        var k = 0;
        var l = 0;
        if (g.c8 && g.categoryMode != 0) {
            if (b.e8) {
                k = b.getOffsetValue();
            }
            else if (b.e0) {
                k = b.getOffsetValue();
            }
        }
        if (h.c8 && h.categoryMode != 0) {
            if (b.e0) {
                l = b.getOffsetValue();
            }
        }
        var m = new ScalerParams(0, this.dc.xm, g.n1, g.df, g.nw());
        m.b = f;
        var n = new ScalerParams(0, this.dc.xm, h.n1, h.df, h.nw());
        n.b = f;
        var o = 0;
        var p = 0;
        if (i) {
            o = g.ft(this.acv(a.b.ac), m) + k;
            p = h.ft(this.acv(a.b.ad), n) + l;
            var q = o;
            var r = p;
            var s = { $type: Point_$type, x: 0.5, y: 0.5 };
            var t = s.x + (r * Math.cos(q));
            o = ViewportUtils.e(t, m.e, m.d, m.c);
            var u = s.y + (r * Math.sin(q));
            p = ViewportUtils.i(u, n.e, n.d, n.c);
        }
        else {
            o = g.ft(this.acv(a.b.ac), m) + k;
            p = h.ft(this.acv(a.b.ad), n) + l;
        }
        var v = new QuadTreeBoundingBox();
        v.d = o;
        v.e = p;
        v.g = 3;
        v.f = 3;
        v.i = a.b;
        return v;
    };
    CalloutLayer.prototype.acv = function (a) {
        if (typeCast(Date_$type, a) !== null) {
            return a.getTime();
        }
        if (a == null) {
            return 0;
        }
        return a;
    };
    CalloutLayer.prototype.acg = function () {
        var a = new List$1(CalloutAnnotationWrapper.$, 0);
        for (var b = 0; b < this.acd.count; b++) {
            if (stringIsNullOrEmpty(this.acd._inner[b].b.ao)) {
                continue;
            }
            if (this.acd._inner[b].c == null) {
                var c = new LabelCollisionInfo();
                this.acd._inner[b].c = c;
                var d = this.aaq.c7(this.ac2(this.acd._inner[b]), this.acd._inner[b].b.backgroundPadding);
                c.o = d.height / 2;
                c.p = d.width / 2;
            }
            var e = this.abd(this.acd._inner[b]);
            if (e == null || e.d < this.w2.left || e.d > this.w2.right || e.e < this.w2.top || e.e > this.w2.bottom) {
                continue;
            }
            a.add(this.acd._inner[b]);
        }
        return a;
    };
    CalloutLayer.prototype.ac2 = function (a) {
        return a.b.ao;
    };
    CalloutLayer.prototype.xs = function (a) {
        if (!_super.prototype.xs.call(this, a)) {
            return false;
        }
        if (this.aed != null) {
            if (a.isFragment) {
                var b = a.nh();
                if (!Base.equalsStatic(this.aed, b)) {
                    return false;
                }
            }
            else {
                if (!Base.equalsStatic(this.aed, a.name)) {
                    return false;
                }
            }
        }
        return true;
    };
    CalloutLayer.prototype.qv = function () {
        _super.prototype.qv.call(this);
        if (!this.a1.c && !this.d4()) {
            return;
        }
        if (this.abj) {
            this.abj = false;
            this.ae7();
            this.ae2();
        }
        if (this.d4()) {
            this.afb(this.xn, false);
        }
        else {
            this.afb(this.xl, false);
        }
    };
    CalloutLayer.prototype.ae3 = function () {
        if (!this.abn) {
            this.abn = true;
            this.ry(true);
        }
    };
    CalloutLayer.prototype.ae6 = function (a, b, c) {
        var d = false;
        if (this.abn) {
            this.abn = false;
            d = true;
        }
        a.km = this.aai;
        if (!a.gj && a.ed(this.acb, this.ab6, this.ab2, this.acy, false)) {
            var e = this.acb;
            var _loop_1 = function (f) {
                var g = e._inner[f];
                var h = g.b != null ? g.b.item : null;
                var i = g.b.item != null ? g.b.item : g.b;
                var j = g.g;
                var k = a;
                var l = new CalloutKey(i, k);
                var m = new CalloutAnnotationWrapper();
                var n = new CalloutAnnotation();
                m.b = n;
                n.key = l;
                var o = false;
                if (this_1.ab7.containsKey(m)) {
                    m = this_1.ab7.item(m).c;
                    n = m.b;
                    o = d;
                }
                else {
                    o = true;
                }
                var p = n.ac;
                var q = n.ad;
                if (this_1.acv(p) != this_1.acv(g.d) && (!isNaN_(this_1.acv(p)) || !isNaN_(this_1.acv(g.d)))) {
                    n.xValue = g.d;
                }
                if (this_1.acv(q) != this_1.acv(g.e) && (!isNaN_(this_1.acv(q)) || !isNaN_(this_1.acv(g.e)))) {
                    n.yValue = g.e;
                }
                n.itemColor = j;
                n.series = a;
                var r = false;
                if (g.f != n.az) {
                    n.az = g.f;
                    r = true;
                }
                if (o || r) {
                    var s = true;
                    if (this_1.calloutLabelUpdating != null) {
                        var t = ((function () {
                            var $ret = new CalloutLabelUpdatingEventArgs();
                            $ret.d = n.ac;
                            $ret.e = n.ad;
                            $ret.item = h;
                            $ret.a = a;
                            $ret.f = a.name;
                            return $ret;
                        })());
                        this_1.calloutLabelUpdating(this_1, t);
                        if (t.c != null && !Base.equalsStatic(t.c, m.b.ao)) {
                            s = false;
                            var u = t.c;
                            if (this_1.aai != null) {
                                m.b.text = this_1.aai.i(u);
                            }
                            else {
                                m.b.text = u != null ? u.toString() : "";
                            }
                        }
                    }
                    if (s) {
                        if (g.f != null) {
                            n.text = g.f;
                        }
                    }
                }
                if (n.ao == null) {
                    return "continue";
                }
                if (o || r) {
                    if (this_1.calloutContentUpdating != null) {
                        var v = ((function () {
                            var $ret = new CalloutContentUpdatingEventArgs();
                            $ret.c = n.ac;
                            $ret.d = n.ad;
                            $ret.item = h;
                            $ret.a = i;
                            return $ret;
                        })());
                        this_1.calloutContentUpdating(this_1, v);
                        if (v.a != null && v.a != m.b.aa) {
                            m.b.content = v.a;
                        }
                    }
                    else {
                        if (i != null && i != m.b.aa) {
                            m.b.content = i;
                        }
                    }
                }
                if (o) {
                    this_1.afd(m);
                }
                if (m.c == null) {
                    var w = new LabelCollisionInfo();
                    m.c = w;
                    var x = this_1.aaq.c7(this_1.ac2(m), m.b.backgroundPadding);
                    w.o = x.height / 2;
                    w.p = x.width / 2;
                }
                var y = this_1.abd(m);
                if (y == null || y.d < this_1.w2.left || y.d > this_1.w2.right || y.e < this_1.w2.top || y.e > this_1.w2.bottom) {
                    return "continue";
                }
                m.e = y.d;
                m.f = y.e;
                if (g.a != null) {
                    m.c.a = g.a;
                }
                c.add(m);
            };
            var this_1 = this;
            for (var f = 0; f < this.acb.count; f++) {
                _loop_1(f);
            }
        }
        a.km = null;
    };
    CalloutLayer.prototype.b3 = function () {
        return 1;
    };
    CalloutLayer.prototype.a2 = function (a, b) {
        var c = this.aba.i(a, b);
        if (c == null) {
            return null;
        }
        return c.y;
    };
    CalloutLayer.prototype.gx = function (a, b) {
        if (this.aba == null) {
            return false;
        }
        return this.aba.i(a, b) != null;
    };
    CalloutLayer.prototype.afb = function (a, b) {
        var e_3, _a;
        var c = 0;
        var d = new HashSet$1(CalloutAnnotationWrapper.$, 0);
        for (c = 0; c < a.q.count; c++) {
            var e = a.n._inner[c];
            if (isNaN_(a.u._inner[c]) || isNaN_(a.v._inner[c])) {
                continue;
            }
            var f = this.aaq.cr.item(e);
            d.add_1(e);
            if (f.h != a.q._inner[c]) {
                f.h = a.q._inner[c];
                var g = f.u();
            }
            f.e = a.o._inner[c];
            f.m = a.f._inner[c];
            f.p = a.p._inner[c];
            f.o = f.e > 0 ? a.i._inner[c] : this.cw.b5();
            f.n = a.h._inner[c];
            f.x = new Thickness(1, a.k._inner[c], a.m._inner[c], a.l._inner[c], a.j._inner[c]);
            f.d = a.g._inner[c];
            this.aaq.cz(f, Math.min(a.s._inner[c], a.s._inner[c] + a.u._inner[c]), Math.min(a.t._inner[c], a.t._inner[c] + a.v._inner[c]));
            this.aaq.c0(f, e, a.r._inner[c]);
            f.r = { $type: Point_$type, x: a.u._inner[c], y: a.v._inner[c] };
        }
        var h = new List$1(CalloutAnnotationWrapper.$, 0);
        try {
            for (var _b = __values(fromEnum(this.aaq.cr.c)), _c = _b.next(); !_c.done; _c = _b.next()) {
                var i = _c.value;
                if (!d.contains(i)) {
                    h.add(i);
                }
            }
        }
        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;
            }
        }
        for (var j = 0; j < h.count; j++) {
            this.aaq.cr.h(h._inner[j]);
        }
    };
    CalloutLayer.prototype.y6 = function (a, b) {
        _super.prototype.y6.call(this, a, b);
        if (this.d4()) {
            this.afb(this.xn, true);
        }
        else {
            this.afb(this.xl, false);
        }
    };
    CalloutLayer.prototype.gb = function () {
        return true;
    };
    CalloutLayer.prototype.rg = function (a, b, c, d) {
        _super.prototype.rg.call(this, a, b, c, d);
        switch (b) {
            case CalloutLayer.$$p[38]:
                this.aay = null;
                this.aaq.cy();
                this.ry(true);
                break;
            case CalloutLayer.$$p[36]:
            case CalloutLayer.$$p[37]:
                this.ry(true);
                break;
            case CalloutLayer.$$p[32]:
            case CalloutLayer.$$p[33]:
                if (this.ad7 != null) {
                    this.aai = new BindingFormatter();
                    this.aai.j = this.ad7;
                    this.aai.d = this.aag;
                }
                else {
                    this.aai = null;
                }
                break;
            case CalloutLayer.$$p[24]:
            case CalloutLayer.$$p[26]:
                this.ry(true);
                break;
            case "SeriesViewer":
                if (c != null) {
                    var e = c;
                    e.seriesAnimating = delegateRemove(e.seriesAnimating, runOn(this, this.afa));
                }
                if (d != null) {
                    var f = d;
                    f.seriesAnimating = delegateCombine(f.seriesAnimating, runOn(this, this.afa));
                }
                if (d == null) {
                    this.ae0();
                }
                break;
            case "AutoCalloutVisibilityMode":
                this.aak = this.aam();
                this.ae1();
                break;
            case "AllowedPositions":
                if (c != null) {
                    var g = c;
                    g.collectionChanged = delegateRemove(g.collectionChanged, runOn(this, this.aev));
                }
                if (d != null) {
                    var h = d;
                    h.collectionChanged = delegateCombine(h.collectionChanged, runOn(this, this.aev));
                }
                this.aaf = this.aah(this.aas);
                this.ae1();
                break;
            case CalloutLayer.$$p[27]:
            case CalloutLayer.$$p[28]:
            case CalloutLayer.$$p[1]:
            case CalloutLayer.$$p[15]:
            case CalloutLayer.$$p[13]:
            case CalloutLayer.$$p[40]:
            case CalloutLayer.$$p[43]:
            case CalloutLayer.$$p[30]:
            case CalloutLayer.$$p[29]:
            case CalloutLayer.$$p[17]:
            case CalloutLayer.$$p[19]:
            case CalloutLayer.$$p[18]:
            case CalloutLayer.$$p[16]:
            case "Visibility":
                this.ae1();
                break;
            case CalloutLayer.$$p[5]:
            case CalloutLayer.$$p[11]:
            case CalloutLayer.$$p[10]:
            case CalloutLayer.$$p[8]:
            case CalloutLayer.$$p[6]:
            case CalloutLayer.$$p[9]:
            case CalloutLayer.$$p[7]:
            case CalloutLayer.$$p[22]:
                this.ae8();
                break;
            case CalloutLayer.$$p[20]:
            case CalloutLayer.$$p[21]:
            case CalloutLayer.$$p[23]:
            case CalloutLayer.$$p[2]:
                this.ae1();
                break;
            case CalloutLayer.$$p[35]:
                this.ae1();
                if (this.aba != null) {
                    this.aba.v = d;
                }
                break;
            case CalloutLayer.$$p[34]:
                if (this.dp != null) {
                    this.dp.deregisterColumn(this.aa7);
                    this.aa7 = this.dn(this.aea);
                }
                break;
            case "LabelColumn":
                this.ae1();
                break;
            case CalloutLayer.$$p[25]:
                if (this.dp != null) {
                    this.dp.deregisterColumn(this.aa5);
                    this.aa5 = this.dn(this.adw);
                }
                break;
            case "ContentColumn":
                this.ae1();
                break;
            case CalloutLayer.$$p[45]:
                if (this.dp != null) {
                    this.dp.deregisterColumn(this.aa8);
                    this.aa8 = stringIsNullOrEmpty(this.aeq) == false ? this.dn(this.aeq) : null;
                }
                break;
            case "XColumn":
                this.ae1();
                break;
            case CalloutLayer.$$p[46]:
                if (this.dp != null) {
                    this.dp.deregisterColumn(this.aa9);
                    this.aa9 = this.dn(this.aet);
                }
                break;
            case "YColumn":
                this.ae1();
                break;
            case CalloutLayer.$$p[31]:
                if (this.dp != null) {
                    this.dp.deregisterColumn(this.aa6);
                    this.aa6 = this.dn(this.ad4);
                }
                break;
            case "KeyColumn":
                this.ae1();
                break;
            case "FastItemsSource":
                this.abl = true;
                if (typeCast(IFastItemsSource_$type, c) != null) {
                    c.deregisterColumn(this.aa7);
                    c.deregisterColumn(this.aa5);
                    c.deregisterColumn(this.aa8);
                    c.deregisterColumn(this.aa9);
                    c.deregisterColumn(this.aa6);
                    this.aa7 = null;
                    this.aa5 = null;
                    this.aa8 = null;
                    this.aa9 = null;
                    this.aa6 = null;
                    this.acd.clear();
                }
                if (typeCast(IFastItemsSource_$type, d) != null) {
                    this.aa7 = this.dn(this.aea);
                    this.aa5 = this.dn(this.adw);
                    if (stringIsNullOrEmpty(this.aeq) == false) {
                        this.aa8 = this.dn(this.aeq);
                    }
                    this.aa9 = this.dn(this.aet);
                    this.aa6 = this.dn(this.ad4);
                }
                this.ae1();
                break;
        }
    };
    CalloutLayer.prototype.aam = function () {
        if (this.aal == 0) {
            return 1;
        }
        return this.aal;
    };
    CalloutLayer.prototype.aah = function (a) {
        if (a == null || a.count == 0) {
            return null;
        }
        var b = new Array(a.count);
        for (var c = 0; c < a.count; c++) {
            b[c] = a._inner[c];
        }
        return b;
    };
    CalloutLayer.prototype.afa = function (a) {
        if (a.eu) {
            return;
        }
        if ((a == this.aax || this.aax == null) && this.abw) {
            this.ry(false);
        }
    };
    CalloutLayer.prototype.ae1 = function () {
        if (this.abg) {
            this.ae7();
            this.abg = false;
        }
        if (this.abj == false) {
            this.abj = true;
            this.ry(false);
        }
    };
    CalloutLayer.prototype.ax = function (a, b, c) {
        var d = this.getEffectiveViewport();
        var e = this.dc.x4;
        var f = this.w3();
        var g = 0;
        if (b.dq) {
            var h = new ScalerParams(0, c, e, !b.df, d);
            var i = b.fw(0, h);
            var j = b.fw(f.height, h);
            g = Math.abs(j - i);
            return new AxisRange(a.c - g, a.b + g);
        }
        else {
            var k = new ScalerParams(0, c, e, b.df, d);
            var l = b.fw(0, k);
            var m = b.fw(f.width, k);
            g = Math.abs(m - l);
            return new AxisRange(a.c - g, a.b + g);
        }
    };
    CalloutLayer.prototype.ae7 = function () {
        var e_4, _a;
        if (this.da == null) {
            return;
        }
        var a = this.da.series;
        if (a == null) {
            return;
        }
        var b = this.da.axes;
        if (b == null) {
            return;
        }
        if (this.abv) {
            return;
        }
        if (!this.abh) {
            var c = this.agz;
            var d = this.w3();
            if (c.width == d.width && c.height == d.height) {
                return;
            }
        }
        this.abe = false;
        try {
            for (var _b = __values(fromEnum(b)), _c = _b.next(); !_c.done; _c = _b.next()) {
                var e = _c.value;
                e.jq();
                e.d3(true);
            }
        }
        catch (e_4_1) {
            e_4 = { error: e_4_1 };
        }
        finally {
            try {
                if (_c && !_c.done && (_a = _b.return))
                    _a.call(_b);
            }
            finally {
                if (e_4)
                    throw e_4.error;
            }
        }
        this.abe = true;
    };
    CalloutLayer.prototype.ae8 = function () {
        if (this.abh) {
            return;
        }
        if (this.abv) {
            return;
        }
        var a = this.agz;
        var b = this.w3();
        if (a.width == b.width && a.height == b.height) {
            return;
        }
        this.abh = true;
        this.abm = true;
        this.abo = true;
        this.abg = true;
        this.ae7();
        this.abg = false;
        if (this.abj == false) {
            this.abj = true;
            this.ry(false);
        }
        this.abh = false;
    };
    CalloutLayer.prototype.aez = function () {
        this.aaq.cr.clear();
        this.aca.g();
        this.ab7.clear();
    };
    CalloutLayer.prototype.ae2 = function () {
        if (this.aa9 == null || this.aa7 == null) {
            var a = this.aca.c;
            while (a != null) {
                this.afd(a.c);
                a = a.a;
            }
            return;
        }
        var b = this.ab8();
        for (var c = 0; c < this.aa9.count; c++) {
            var d = void 0;
            if (this.acd.count <= c) {
                var e = new CalloutAnnotation();
                d = new CalloutAnnotationWrapper();
                d.b = e;
                d.b.series = this.aax;
                this.acd.add(d);
            }
            else {
                d = this.acd._inner[c];
            }
            this.afc(c, b);
        }
    };
    CalloutLayer.prototype.ae9 = function () {
        this.abm = true;
        this.abo = true;
        this.ae1();
    };
    CalloutLayer.$t = markType(CalloutLayer, 'CalloutLayer', AnnotationLayer.$);
    CalloutLayer.af2 = DependencyProperty.i("AutoCalloutVisibilityMode", AutoCalloutVisibilityMode_$type, CalloutLayer.$, new PropertyMetadata(2, enumGetBox(AutoCalloutVisibilityMode_$type, 0), function (a, b) { return a.raisePropertyChanged("AutoCalloutVisibilityMode", b.oldValue, b.newValue); }));
    CalloutLayer.$$p = markDep(DependencyProperty, PropertyMetadata, CalloutLayer, 'raisePropertyChanged', ['AutoCalloutLabelPrecision:acy:afe', [1, 5], 'CalloutBackground:agq:aff', [Brush.$, null], 'CalloutCollisionMode:aan:afg', [CalloutCollisionMode_$type, enumGetBox(CalloutCollisionMode_$type, 3)], 'CalloutCornerRadius:ack:afh', [1, NaN], 'CalloutDarkTextColor:agr:afi', [Brush.$, null], 'CalloutExpandsAxisBufferEnabled:abs:afj', [0, false], 'CalloutExpandsAxisBufferMaxHeight:acl:afk', [1, 400], 'CalloutExpandsAxisBufferMaxWidth:acm:afl', [1, 400], 'CalloutExpandsAxisBufferMinHeight:acn:afm', [1, 20], 'CalloutExpandsAxisBufferMinWidth:aco:afn', [1, 20], 'CalloutExpandsAxisBufferOnInitialVisibility:abt:afo', [0, false], 'CalloutExpandsAxisBufferOnlyWhenVisible:abu:afp', [0, false], 'CalloutInterpolatedValuePrecision:acz:afq', [1, -1], 'CalloutLeaderBrush:ags:afr', [Brush.$, null], 'CalloutLightTextColor:agt:afs', [Brush.$, null], 'CalloutOutline:agu:aft', [Brush.$, null], 'CalloutPaddingBottom:acp:afu', [1, NaN], 'CalloutPaddingLeft:acq:afv', [1, NaN], 'CalloutPaddingRight:acr:afw', [1, NaN], 'CalloutPaddingTop:acs:afx', [1, NaN], 'CalloutPositionPadding:act:afy', [1, 10], 'CalloutStrokeThickness:acu:afz', [1, NaN], 'CalloutSuspendedWhenShiftingToVisible:abv:af0', [0, false], 'CalloutTextColor:agv:af1', [Brush.$, null], 'CollisionChannel:adt:af3', [2, null], 'ContentMemberPath:adw:af4', [2, null], 'HighlightedValueLabelMode:aaw:af5', [HighlightedValueLabelMode_$type, enumGetBox(HighlightedValueLabelMode_$type, 0)], 'IsAutoCalloutBehaviorEnabled:abw:af6', [0, false], 'IsCalloutOffsettingEnabled:abx:af7', [0, true], 'IsCustomCalloutRenderStyleEnabled:aby:af8', [0, false], 'IsCustomCalloutStyleEnabled:abz:af9', [0, false], 'KeyMemberPath:ad4:aga', [2, null], 'LabelFormat:ad7:agb', [2, null], 'LabelFormatSpecifiers:aag:agc', [Array_$type, null], 'LabelMemberPath:aea:agd', [2, null], 'ShouldTruncateOnBoundaryCollisions:ab0:age', [0, false], 'TargetSeriesName:aed:agf', [2, null], 'TargetSeries:aax:agg', [Series.$, null], 'TextStyle:aeg:agh', [2, null], 'UseAutoContrastingLabelColors:ab1:agi', [0, false], 'UseInterpolatedValueForAutoCalloutLabels:ab2:agj', [0, false], 'UseItemColorForFill:ab3:agk', [0, false], 'UseItemColorForOutline:ab4:agl', [0, false], 'UseSeriesColorForOutline:ab5:agm', [0, false], 'UseValueForAutoCalloutLabels:ab6:agn', [0, true], 'XMemberPath:aeq:ago', [2, null], 'YMemberPath:aet:agp', [2, null]]);
    return CalloutLayer;
}(AnnotationLayer));
export { CalloutLayer };
/**
 * @hidden
 */
var CalloutLayerView = /** @class */ /*@__PURE__*/ (function (_super) {
    __extends(CalloutLayerView, _super);
    function CalloutLayerView(a) {
        var _this = _super.call(this, a) || this;
        _this.cn = null;
        _this.cs = null;
        _this.cr = null;
        _this.ct = NaN;
        _this.co = null;
        _this.cn = a;
        _this.cs = new List$1(CalloutView.$, 0);
        return _this;
    }
    CalloutLayerView.prototype.a4 = function () {
        var _this = this;
        _super.prototype.a4.call(this);
        this.cr = ((function () {
            var $ret = new HashPool$2(CalloutAnnotationWrapper.$, CalloutView.$);
            $ret.create = runOn(_this, _this.cp);
            $ret.activate = runOn(_this, _this.cv);
            $ret.disactivate = runOn(_this, _this.cx);
            $ret.destroy = runOn(_this, _this.cw);
            return $ret;
        })());
    };
    CalloutLayerView.prototype.cp = function () {
        var a = new CalloutView(this);
        this.cs.add(a);
        return a;
    };
    CalloutLayerView.prototype.cv = function (a) {
        a.y = 0;
    };
    CalloutLayerView.prototype.cx = function (a) {
        a.y = 1;
    };
    CalloutLayerView.prototype.cw = function (a) {
        this.cs.remove(a);
    };
    CalloutLayerView.prototype.c6 = function (a) {
        if (a == null) {
            return a;
        }
        return BrushUtil.o(a, 0.1);
    };
    CalloutLayerView.prototype.bj = function (a, b) {
        _super.prototype.bj.call(this, a, b);
        a.ae(this.cq());
        if (a.d && !b) {
            for (var c = 0; c < this.cs.count; c++) {
                var d = this.cs._inner[c];
                if (d.y == 0) {
                    d.j(a);
                }
            }
        }
    };
    CalloutLayerView.prototype.cq = function () {
        if (this.cn.aaz != null) {
            return this.cn.aaz;
        }
        return this.f.dc.getFontInfo();
    };
    CalloutLayerView.prototype.ax = function (a) {
        _super.prototype.ax.call(this, a);
        for (var b = 0; b < this.cs.count; b++) {
            var c = this.cs._inner[b];
            if (c.y != 0) {
                continue;
            }
            c.i(this.cn, this.cq(), a);
        }
    };
    CalloutLayerView.prototype.c8 = function (a) {
        this.m.ae(this.cq());
        this.ct = this.cu();
        var b = this.m.ai(a, this.ct, true);
        return new Size(1, b.c, b.b);
    };
    CalloutLayerView.prototype.cu = function () {
        var a = this.cq();
        if (isNaN_(this.ct)) {
            var b = FontUtil.getCurrentFontHeight(this.f.dc.dp.j.ae, a);
            this.ct = b;
        }
        return this.ct;
    };
    CalloutLayerView.prototype.c7 = function (a, b) {
        if (this.co == null) {
            this.co = new CalloutView(this);
        }
        this.co.h = a;
        this.co.x = b;
        var c = this.co.u();
        this.co.h = null;
        return c;
    };
    CalloutLayerView.prototype.cz = function (a, b, c) {
        a.f = b;
        a.g = c;
    };
    CalloutLayerView.prototype.c0 = function (a, b, c) {
        a.k(this.f, b, c);
    };
    CalloutLayerView.prototype.c1 = function (a, b) {
        if (b != null && this.cn.ab3) {
            return this.c6(b);
        }
        if (a != null) {
            return this.c6(a.vq);
        }
        return this.f.vq;
    };
    CalloutLayerView.prototype.c4 = function () {
        return ((function () {
            var $ret = new Brush();
            $ret.color = Color.u(255, 255, 255, 255);
            return $ret;
        })());
    };
    CalloutLayerView.prototype.c2 = function () {
        return ((function () {
            var $ret = new Brush();
            $ret.color = Color.u(255, 0, 0, 0);
            return $ret;
        })());
    };
    CalloutLayerView.prototype.c5 = function (a, b) {
        if (b != null && this.cn.ab4) {
            return this.c6(b);
        }
        if (this.cn.ab5) {
            if (a != null) {
                return this.c6(a.vq);
            }
        }
        return ((function () {
            var $ret = new Brush();
            $ret.color = Color.u(255, 255, 255, 255);
            return $ret;
        })());
    };
    CalloutLayerView.prototype.c3 = function (a, b) {
        if (b != null && this.cn.ab4) {
            return this.c6(b);
        }
        if (a != null) {
            return this.c6(a.vj);
        }
        return this.f.vj;
    };
    CalloutLayerView.prototype.cy = function () {
        this.ct = NaN;
    };
    CalloutLayerView.$t = markType(CalloutLayerView, 'CalloutLayerView', AnnotationLayerView.$);
    return CalloutLayerView;
}(AnnotationLayerView));
export { CalloutLayerView };
/**
 * @hidden
 */
var CalloutView = /** @class */ /*@__PURE__*/ (function (_super) {
    __extends(CalloutView, _super);
    function CalloutView(a) {
        var _this = _super.call(this) || this;
        _this.a = null;
        _this.y = 0;
        _this.l = null;
        _this.t = null;
        _this.q = { $type: Point_$type, x: 0, y: 0 };
        _this.s = null;
        _this.w = new Thickness(0, 0);
        _this.v = null;
        _this.c = 0;
        _this.f = 0;
        _this.g = 0;
        _this.b = null;
        _this.s = new Line();
        _this.s.ab = false;
        _this.s._stroke = ((function () {
            var $ret = new Brush();
            $ret.color = Color.u(255, 0, 0, 0);
            return $ret;
        })());
        _this.s.ad = 2;
        _this.l = new TextBlock();
        _this.t = new Rectangle();
        _this.t.ad = 0;
        _this.a = a;
        _this.y = 0;
        return _this;
    }
    CalloutView.prototype.j = function (a) {
        a.aa();
        a.ah(this.f, this.g);
        var b = new TranslateTransform();
        b.j = this.v.left;
        b.k = this.v.top;
        this.t.j = b;
        a.s(this.s);
        a.aa();
        this.t.width = this.l.m + this.w.left + this.w.right;
        this.t.height = this.l.l + this.w.top + this.w.bottom;
        this.t.ap = this.c;
        this.t.aq = this.c;
        a.k(this.t.j);
        a.w(this.t);
        this.l.ag = true;
        this.l.o = this.w.top;
        this.l.n = this.w.left;
        a.x(this.l);
        a.z();
        a.z();
    };
    Object.defineProperty(CalloutView.prototype, "r", {
        get: function () {
            return this.q;
        },
        set: function (a) {
            if (this.q.x != a.x || this.q.y != a.y) {
                var b = this.u();
                var c = b.height;
                var d = b.width;
                this.q = a;
                var e = CalloutViewHelper.b(this.r, d, c, this.s);
                this.v = e;
            }
        },
        enumerable: false,
        configurable: true
    });
    Object.defineProperty(CalloutView.prototype, "p", {
        get: function () {
            return this.l.ao;
        },
        set: function (a) {
            this.l.ao = a;
        },
        enumerable: false,
        configurable: true
    });
    Object.defineProperty(CalloutView.prototype, "o", {
        get: function () {
            return this.t._stroke;
        },
        set: function (a) {
            this.t._stroke = a;
        },
        enumerable: false,
        configurable: true
    });
    Object.defineProperty(CalloutView.prototype, "n", {
        get: function () {
            return this.s._stroke;
        },
        set: function (a) {
            this.s._stroke = a;
        },
        enumerable: false,
        configurable: true
    });
    Object.defineProperty(CalloutView.prototype, "m", {
        get: function () {
            return this.t._fill;
        },
        set: function (a) {
            this.t._fill = a;
        },
        enumerable: false,
        configurable: true
    });
    Object.defineProperty(CalloutView.prototype, "e", {
        get: function () {
            return this.t.ad;
        },
        set: function (a) {
            this.t.ad = a;
        },
        enumerable: false,
        configurable: true
    });
    Object.defineProperty(CalloutView.prototype, "x", {
        get: function () {
            return this.w;
        },
        set: function (a) {
            this.w = a;
        },
        enumerable: false,
        configurable: true
    });
    Object.defineProperty(CalloutView.prototype, "d", {
        get: function () {
            return this.c;
        },
        set: function (a) {
            this.c = a;
        },
        enumerable: false,
        configurable: true
    });
    Object.defineProperty(CalloutView.prototype, "h", {
        get: function () {
            return this.l.al;
        },
        set: function (a) {
            if (a == null) {
                this.l.al = "";
            }
            else {
                this.l.al = a.toString();
            }
            var b = this.u();
            var c = b.height;
            var d = b.width;
            var e = CalloutViewHelper.b(this.r, d, c, this.s);
            this.v = e;
        },
        enumerable: false,
        configurable: true
    });
    CalloutView.prototype.u = function () {
        var a = this.a.c8(this.l);
        this.l.m = a.width;
        this.l.l = a.height;
        return new Size(1, a.width + this.w.left + this.w.right, a.height + this.w.top + this.w.bottom);
    };
    CalloutView.prototype.k = function (a, b, c) {
        if (this.b == null) {
            this.b = new DataContext();
        }
        this.b.series = a;
        this.b.item = c;
        if (b.c != null) {
            b.c.y = this.b;
        }
    };
    CalloutView.prototype.i = function (a, b, c) {
        a.bc.exportCalloutData(this.f, this.g, this.v.left, this.v.top, c, this.t, this.l, b, this.s, "callout", ["Main", "Callout"]);
    };
    CalloutView.$t = markType(CalloutView, 'CalloutView');
    return CalloutView;
}(Base));
export { CalloutView };
