/*
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 { 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
 */
export let CalloutLayer = /*@__PURE__*/ (() => {
    class CalloutLayer extends AnnotationLayer {
        constructor() {
            super();
            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();
            let a = this.aar;
            a.collectionChanged = delegateCombine(a.collectionChanged, runOn(this, this.aev));
            this.xu = true;
            let b = new CalloutLayerFrame();
            let c = new CalloutLayerFrame();
            let d = new CalloutLayerFrame();
            let e = this.kh / 1000;
            this.xm = b;
            this.xl = c;
            this.xn = d;
            this.ab = CalloutLayer.$;
        }
        bk() {
            return new CalloutLayer();
        }
        get_eq() {
            return true;
        }
        aev(a, b) {
            this.ae4();
        }
        ae4() {
            this.aaf = this.aah(this.aas);
            this.ae1();
        }
        aew(a, b) {
            this.acd.clear();
            this.ry(false);
        }
        ph(a, b, c, d) {
            super.ph(a, b, c, d);
            let e = this.ab8();
            switch (a) {
                case 3:
                    this.afc(b, e);
                    break;
                case 1:
                    for (let f = b; f < b + c; f++) {
                        let g = new CalloutAnnotation();
                        let 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 (let i = b; i < b + c; i++) {
                        this.afc(i, e);
                    }
                    break;
                case 4:
                    this.acd.clear();
                    for (let j = 0; j < this.dp.count; j++) {
                        let k = new CalloutAnnotation();
                        let l = new CalloutAnnotationWrapper();
                        l.b = k;
                        l.b.series = this.aax;
                        this.acd.add(l);
                        this.afc(j, e);
                    }
                    break;
            }
            this.ry(true);
        }
        gg(a) {
            return false;
        }
        ag1() {
            let 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;
        }
        w3() {
            if (!this.abe) {
                return this.agz;
            }
            let a = 0;
            let b = 0;
            if (!this.abs) {
                this.agz = new Size(1, 0, 0);
                return this.agz;
            }
            if (this.abu) {
                this.abk = true;
                let 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;
                }
            }
            let d = this.ag1();
            let e = -1.7976931348623157E+308;
            let f = -1.7976931348623157E+308;
            for (let g = 0; g < this.ace.count; g++) {
                let h = this.ace._inner[g].b.text;
                let 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;
        }
        ab8() {
            let a = new Dictionary$2(String_$type, Series.$, 0);
            if (this.dc != null) {
                for (let b = 0; b < this.dc.series.count; b++) {
                    let c = this.dc.series._inner[b];
                    if (c.name != null && !a.containsKey(c.name)) {
                        a.addItem(c.name, c);
                    }
                }
            }
            return a;
        }
        afc(a, b) {
            if (this.aa9 == null || this.aa7 == null) {
                return;
            }
            let c = a;
            if (this.aa8 != null) {
                c = this.aa8.item(a);
            }
            let d = this.aa9.item(a);
            let e = this.aa7.item(a);
            let 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;
            let g = true;
            if (this.calloutLabelUpdating != null) {
                let h = ((() => {
                    let $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;
                    let 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) {
                let j = ((() => {
                    let $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);
        }
        afd(a) {
            let 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;
            }
            let c = DeviceUtils.g(3);
            if (isNaN_(this.ack)) {
                c = DeviceUtils.g(3);
            }
            else {
                c = this.ack;
            }
            let d = this.agq != null && !this.ab3 ? this.agq : this.aaq.c1(a.b.l, a.b.itemColor);
            let e = this.agv != null ? this.agv : null;
            let f = this.agt != null ? this.agt : this.aaq.c4();
            let g = this.agr != null ? this.agr : this.aaq.c2();
            let h = this.agu != null && !this.ab4 ? this.agu : this.aaq.c5(a.b.l, a.b.itemColor);
            let i = this.ags != null ? this.ags : this.aaq.c3(a.b.l, a.b.itemColor);
            let j = isNaN_(this.acu) ? 0 : this.acu;
            if (e == null && (this.ab1 || this.agt != null || this.agr != null)) {
                let 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) {
                let 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;
        }
        ku(a, b) {
            let 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.ku(a, b);
        }
        mi(a) {
            let 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.mi(a);
        }
        get aa7() {
            return this.aa2;
        }
        set aa7(a) {
            if (this.aa2 != a) {
                let b = this.aa2;
                this.aa2 = a;
                this.raisePropertyChanged("LabelColumn", b, this.aa2);
            }
        }
        get aa8() {
            return this.aa3;
        }
        set aa8(a) {
            if (this.aa3 != a) {
                let b = this.aa3;
                this.aa3 = a;
                this.raisePropertyChanged("XColumn", b, this.aa3);
            }
        }
        get aa9() {
            return this.aa4;
        }
        set aa9(a) {
            if (this.aa4 != a) {
                let b = this.aa4;
                this.aa4 = a;
                this.raisePropertyChanged("YColumn", b, this.aa4);
            }
        }
        get aa6() {
            return this.aa1;
        }
        set aa6(a) {
            if (this.aa1 != a) {
                let b = this.aa1;
                this.aa1 = a;
                this.raisePropertyChanged("KeyColumn", b, this.aa1);
            }
        }
        get aa5() {
            return this.aa0;
        }
        set aa5(a) {
            if (this.aa0 != a) {
                let b = this.aa0;
                this.aa0 = a;
                this.raisePropertyChanged("ContentColumn", b, this.aa0);
            }
        }
        aey(a, b) {
            if (b.propertyName == CalloutAnnotation.$$p[15] || b.propertyName == CalloutAnnotation.$$p[16]) {
                let c = a.k;
                if (!this.ab9.contains(c)) {
                    this.ab9.add_1(c);
                    this.acc.add(c);
                    this.ry(false);
                }
            }
        }
        ct() {
            return new CalloutLayerView(this);
        }
        q7(a) {
            super.q7(a);
            this.aaq = a;
        }
        get aas() {
            return this.aar;
        }
        set aas(a) {
            let b = this.aas;
            if (a != b) {
                this.aar = a;
                this.raisePropertyChanged("AllowedPositions", b, this.aas);
            }
        }
        gv(a) {
            if (this.aax == null) {
                return true;
            }
            if (this.aax == a) {
                return true;
            }
            return false;
        }
        get aal() {
            return EnumUtil.getEnumValue(AutoCalloutVisibilityMode_$type, this.c(CalloutLayer.af2));
        }
        set aal(a) {
            this.h(CalloutLayer.af2, enumGetBox(AutoCalloutVisibilityMode_$type, a));
        }
        get aak() {
            return this.aaj;
        }
        set aak(a) {
            this.aaj = a;
        }
        get ag0() {
            return new Thickness(1, this.acq, this.acs, this.acr, this.acp);
        }
        get aaz() {
            if (this.aay == null) {
                this.aay = FontUtil.toFontInfo(this.j3, this.aeg);
            }
            return this.aay;
        }
        y1(a, b) {
            if (this.aax == null || this.aax == a) {
                if (!this.a1.c) {
                    this.ry(b);
                }
            }
        }
        y3(a, b) {
            super.y3(a, b);
            let 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);
            let d = Number.POSITIVE_INFINITY;
            let e = true;
            if (this.abw) {
                if (this.xs(this.aax)) {
                    if (typeCast(IHasCategoryAxis_$type, this.aax) !== null) {
                        let 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 {
                    for (let g of fromEnum(this.dc.series)) {
                        if (this.xs(g)) {
                            if (typeCast(IHasCategoryAxis_$type, g) !== null) {
                                let 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;
                                }
                            }
                            let 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((j) => {
                                    this.ae6(j, c, this.ace);
                                    return true;
                                });
                            }
                            if (!i) {
                                this.ae6(g, c, this.ace);
                            }
                        }
                    }
                }
            }
            if (this.abw && this.aak == 2) {
                let j = 0;
                let k = 0;
                let l = 1.7976931348623157E+308;
                let m = 1.7976931348623157E+308;
                let n = -1.7976931348623157E+308;
                let 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 (let p = 0; p < this.ace.count; p++) {
                        let q = this.ace._inner[p];
                        if (q.c != null) {
                            let r = q.e;
                            let 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();
                            }
                        }
                    }
                }
            }
            let t = this.acx <= 0 && this.ace.count > 0;
            let u = this.acx > 0 && this.ace.count <= 0;
            let v = t || u;
            let w = this.acx != this.ace.count;
            if (t && this.abv) {
                return;
            }
            if (!this.abk) {
                this.ae5(c, this.acf, this.ace);
            }
            let x = this.da.ig();
            let y = this.da.ie();
            let z = x != this.aci;
            let aa = y != this.ach;
            let 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();
            }
        }
        sz(a, b) {
            super.sz(a, b);
            let c = b.width - this.agx.width;
            let d = b.height - this.agx.height;
            let 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;
            }
        }
        sy(a, b) {
            super.sy(a, b);
            if (!a.equals1(b)) {
                this.abp = true;
            }
        }
        get agy() {
            return this.agw;
        }
        set agy(a) {
            this.agw = a;
        }
        ae5(a, b, c) {
            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) {
                let d = this.abb();
                if (d != null) {
                    this.aba = d;
                    let e = this.aba;
                    e.labelsMoved = delegateCombine(e.labelsMoved, runOn(this, this.aex));
                }
                else {
                    let f = this.wt(this.cw);
                    let 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 {
                        let h = false;
                        if (this.dc != null && this.dc.series.count > 0) {
                            h = true;
                            for (let i of fromEnum(this.dc.series)) {
                                if (!i.eu) {
                                    if (!i.isVertical) {
                                        h = false;
                                    }
                                }
                            }
                        }
                        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;
                    }
                    let 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;
            }
            let k = new HashSet$1(CalloutAnnotationWrapper.$, 0);
            let l = new HashSet$1(CalloutAnnotationWrapper.$, 0);
            let m = new List$1(CalloutAnnotationWrapper.$, 0);
            let n = new List$1(CalloutAnnotationWrapper.$, 0);
            let o = new HashSet$1(CalloutAnnotationWrapper.$, 0);
            for (let p = 0; p < b.count; p++) {
                o.add_1(b._inner[p]);
            }
            for (let q = 0; q < c.count; q++) {
                o.add_1(c._inner[q]);
            }
            let r = this.aca.c;
            while (r != null) {
                let s = r.a;
                if (!o.contains(r.c)) {
                    n.add(r.c);
                    l.add_1(r.c);
                    let 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 (let u = 0; u < b.count; u++) {
                if (!this.ab7.containsKey(b._inner[u])) {
                    this.aca.f(b._inner[u]);
                    let 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 (let 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);
                    let 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;
            }
            let y = false;
            if (this.acc.count > 0) {
                y = true;
                this.acc.clear();
                this.ab9.clear();
            }
            r = this.aca.c;
            while (r != null) {
                let z = this.abd(r.c);
                if (z == null) {
                    return;
                }
                if (!Base.equalsStatic(z, r.c.c.e)) {
                    let aa = false;
                    if (r.c.c.e == null) {
                        aa = true;
                    }
                    let 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;
            }
            let ac = this.aba.ba();
            let 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) {
                    let ae = true;
                    for (let af = 0; af < this.dc.series.count; af++) {
                        let ag = this.dc.series._inner[af];
                        if (ag.eu && typeCast(CalloutLayer.$, ag) !== null) {
                            let 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();
            }
            let ai = this.aca.c;
            let aj;
            let ak;
            let al;
            let am;
            let an;
            let ao;
            let ap;
            let aq;
            let ar;
            let as;
            let at;
            let au;
            let av;
            let aw;
            let ax;
            let ay;
            let az = this.aby;
            let a0 = this.ab0;
            let a1 = this.cw.b5();
            while (ai != null) {
                let a2 = ai.c;
                let 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;
                let 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;
                let 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);
                    let a6 = this.aba.as(a2.c.c);
                    if (a6 > 0) {
                        ax += a6;
                        av -= a6;
                    }
                }
                if (az) {
                    let 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;
            }
        }
        aei(a, b) {
            let c = Math.max(this.aba.as(a.c.c), this.aba.at(a.c.c));
            if (c <= 0) {
                return b;
            }
            let d = b.length;
            let e = this.aaq.c7(b, a.b.backgroundPadding);
            let f = e.width;
            let 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;
        }
        ae0() {
            if (this.aba != null) {
                let a = this.aca.c;
                while (a != null) {
                    let b = a.c.c;
                    if (b != null) {
                        this.aba.br(b);
                    }
                    a = a.a;
                }
                let c = this.aba;
                c.labelsMoved = delegateRemove(c.labelsMoved, runOn(this, this.aex));
                this.aba = null;
            }
            this.aez();
        }
        abb() {
            if (this.dc == null) {
                return null;
            }
            for (let a = 0; a < this.dc.series.count; a++) {
                let b = this.dc.series._inner[a];
                if (b.eu && typeCast(CalloutLayer.$, b) !== null) {
                    let c = b;
                    if (c != this) {
                        if (c.adt != null && c.adt == this.adt) {
                            if (c.aba != null) {
                                return c.aba;
                            }
                        }
                    }
                }
            }
            return null;
        }
        ac0() {
            return 20000;
        }
        ac1() {
            return 300;
        }
        abc() {
            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;
        }
        aex(a) {
            let b = this.aba.ba();
            let c = this.acw;
            if (b < this.acw) {
                this.acw = b;
                if (c != 0x7FFFFFFF) {
                    this.ry(false);
                }
            }
        }
        abd(a) {
            let b = this.aax;
            if (a.b.l != null) {
                b = a.b.l;
            }
            if (b == null) {
                for (let c = 0; c < this.dc.series.count; c++) {
                    let d = this.dc.series._inner[c];
                    if (!d.eu) {
                        b = d;
                        break;
                    }
                }
            }
            if (b == null) {
                return null;
            }
            let e = b.ai();
            let f = b.i0();
            let g = null;
            let h = null;
            let i = false;
            for (let 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;
            }
            let k = 0;
            let 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();
                }
            }
            let m = new ScalerParams(0, this.dc.xm, g.n1, g.df, g.nw());
            m.b = f;
            let n = new ScalerParams(0, this.dc.xm, h.n1, h.df, h.nw());
            n.b = f;
            let o = 0;
            let p = 0;
            if (i) {
                o = g.ft(this.acv(a.b.ac), m) + k;
                p = h.ft(this.acv(a.b.ad), n) + l;
                let q = o;
                let r = p;
                let s = { $type: Point_$type, x: 0.5, y: 0.5 };
                let t = s.x + (r * Math.cos(q));
                o = ViewportUtils.e(t, m.e, m.d, m.c);
                let 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;
            }
            let v = new QuadTreeBoundingBox();
            v.d = o;
            v.e = p;
            v.g = 3;
            v.f = 3;
            v.i = a.b;
            return v;
        }
        acv(a) {
            if (typeCast(Date_$type, a) !== null) {
                return a.getTime();
            }
            if (a == null) {
                return 0;
            }
            return a;
        }
        acg() {
            let a = new List$1(CalloutAnnotationWrapper.$, 0);
            for (let b = 0; b < this.acd.count; b++) {
                if (stringIsNullOrEmpty(this.acd._inner[b].b.ao)) {
                    continue;
                }
                if (this.acd._inner[b].c == null) {
                    let c = new LabelCollisionInfo();
                    this.acd._inner[b].c = c;
                    let 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;
                }
                let 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;
        }
        ac2(a) {
            return a.b.ao;
        }
        xs(a) {
            if (!super.xs(a)) {
                return false;
            }
            if (this.aed != null) {
                if (a.isFragment) {
                    let b = a.nh();
                    if (!Base.equalsStatic(this.aed, b)) {
                        return false;
                    }
                }
                else {
                    if (!Base.equalsStatic(this.aed, a.name)) {
                        return false;
                    }
                }
            }
            return true;
        }
        qv() {
            super.qv();
            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);
            }
        }
        ae3() {
            if (!this.abn) {
                this.abn = true;
                this.ry(true);
            }
        }
        ae6(a, b, c) {
            let 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)) {
                let e = this.acb;
                for (let f = 0; f < this.acb.count; f++) {
                    let g = e._inner[f];
                    let h = g.b != null ? g.b.item : null;
                    let i = g.b.item != null ? g.b.item : g.b;
                    let j = g.g;
                    let k = a;
                    let l = new CalloutKey(i, k);
                    let m = new CalloutAnnotationWrapper();
                    let n = new CalloutAnnotation();
                    m.b = n;
                    n.key = l;
                    let o = false;
                    if (this.ab7.containsKey(m)) {
                        m = this.ab7.item(m).c;
                        n = m.b;
                        o = d;
                    }
                    else {
                        o = true;
                    }
                    let p = n.ac;
                    let q = n.ad;
                    if (this.acv(p) != this.acv(g.d) && (!isNaN_(this.acv(p)) || !isNaN_(this.acv(g.d)))) {
                        n.xValue = g.d;
                    }
                    if (this.acv(q) != this.acv(g.e) && (!isNaN_(this.acv(q)) || !isNaN_(this.acv(g.e)))) {
                        n.yValue = g.e;
                    }
                    n.itemColor = j;
                    n.series = a;
                    let r = false;
                    if (g.f != n.az) {
                        n.az = g.f;
                        r = true;
                    }
                    if (o || r) {
                        let s = true;
                        if (this.calloutLabelUpdating != null) {
                            let t = ((() => {
                                let $ret = new CalloutLabelUpdatingEventArgs();
                                $ret.d = n.ac;
                                $ret.e = n.ad;
                                $ret.item = h;
                                $ret.a = a;
                                $ret.f = a.name;
                                return $ret;
                            })());
                            this.calloutLabelUpdating(this, t);
                            if (t.c != null && !Base.equalsStatic(t.c, m.b.ao)) {
                                s = false;
                                let u = t.c;
                                if (this.aai != null) {
                                    m.b.text = this.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) {
                        continue;
                    }
                    if (o || r) {
                        if (this.calloutContentUpdating != null) {
                            let v = ((() => {
                                let $ret = new CalloutContentUpdatingEventArgs();
                                $ret.c = n.ac;
                                $ret.d = n.ad;
                                $ret.item = h;
                                $ret.a = i;
                                return $ret;
                            })());
                            this.calloutContentUpdating(this, 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.afd(m);
                    }
                    if (m.c == null) {
                        let w = new LabelCollisionInfo();
                        m.c = w;
                        let x = this.aaq.c7(this.ac2(m), m.b.backgroundPadding);
                        w.o = x.height / 2;
                        w.p = x.width / 2;
                    }
                    let y = this.abd(m);
                    if (y == null || y.d < this.w2.left || y.d > this.w2.right || y.e < this.w2.top || y.e > this.w2.bottom) {
                        continue;
                    }
                    m.e = y.d;
                    m.f = y.e;
                    if (g.a != null) {
                        m.c.a = g.a;
                    }
                    c.add(m);
                }
            }
            a.km = null;
        }
        b3() {
            return 1;
        }
        a2(a, b) {
            let c = this.aba.i(a, b);
            if (c == null) {
                return null;
            }
            return c.y;
        }
        gx(a, b) {
            if (this.aba == null) {
                return false;
            }
            return this.aba.i(a, b) != null;
        }
        afb(a, b) {
            let c = 0;
            let d = new HashSet$1(CalloutAnnotationWrapper.$, 0);
            for (c = 0; c < a.q.count; c++) {
                let e = a.n._inner[c];
                if (isNaN_(a.u._inner[c]) || isNaN_(a.v._inner[c])) {
                    continue;
                }
                let f = this.aaq.cr.item(e);
                d.add_1(e);
                if (f.h != a.q._inner[c]) {
                    f.h = a.q._inner[c];
                    let 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] };
            }
            let h = new List$1(CalloutAnnotationWrapper.$, 0);
            for (let i of fromEnum(this.aaq.cr.c)) {
                if (!d.contains(i)) {
                    h.add(i);
                }
            }
            for (let j = 0; j < h.count; j++) {
                this.aaq.cr.h(h._inner[j]);
            }
        }
        y6(a, b) {
            super.y6(a, b);
            if (this.d4()) {
                this.afb(this.xn, true);
            }
            else {
                this.afb(this.xl, false);
            }
        }
        gb() {
            return true;
        }
        rg(a, b, c, d) {
            super.rg(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) {
                        let e = c;
                        e.seriesAnimating = delegateRemove(e.seriesAnimating, runOn(this, this.afa));
                    }
                    if (d != null) {
                        let 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) {
                        let g = c;
                        g.collectionChanged = delegateRemove(g.collectionChanged, runOn(this, this.aev));
                    }
                    if (d != null) {
                        let 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;
            }
        }
        aam() {
            if (this.aal == 0) {
                return 1;
            }
            return this.aal;
        }
        aah(a) {
            if (a == null || a.count == 0) {
                return null;
            }
            let b = new Array(a.count);
            for (let c = 0; c < a.count; c++) {
                b[c] = a._inner[c];
            }
            return b;
        }
        afa(a) {
            if (a.eu) {
                return;
            }
            if ((a == this.aax || this.aax == null) && this.abw) {
                this.ry(false);
            }
        }
        ae1() {
            if (this.abg) {
                this.ae7();
                this.abg = false;
            }
            if (this.abj == false) {
                this.abj = true;
                this.ry(false);
            }
        }
        ax(a, b, c) {
            let d = this.getEffectiveViewport();
            let e = this.dc.x4;
            let f = this.w3();
            let g = 0;
            if (b.dq) {
                let h = new ScalerParams(0, c, e, !b.df, d);
                let i = b.fw(0, h);
                let j = b.fw(f.height, h);
                g = Math.abs(j - i);
                return new AxisRange(a.c - g, a.b + g);
            }
            else {
                let k = new ScalerParams(0, c, e, b.df, d);
                let l = b.fw(0, k);
                let m = b.fw(f.width, k);
                g = Math.abs(m - l);
                return new AxisRange(a.c - g, a.b + g);
            }
        }
        ae7() {
            if (this.da == null) {
                return;
            }
            let a = this.da.series;
            if (a == null) {
                return;
            }
            let b = this.da.axes;
            if (b == null) {
                return;
            }
            if (this.abv) {
                return;
            }
            if (!this.abh) {
                let c = this.agz;
                let d = this.w3();
                if (c.width == d.width && c.height == d.height) {
                    return;
                }
            }
            this.abe = false;
            for (let e of fromEnum(b)) {
                e.jq();
                e.d3(true);
            }
            this.abe = true;
        }
        ae8() {
            if (this.abh) {
                return;
            }
            if (this.abv) {
                return;
            }
            let a = this.agz;
            let 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;
        }
        aez() {
            this.aaq.cr.clear();
            this.aca.g();
            this.ab7.clear();
        }
        ae2() {
            if (this.aa9 == null || this.aa7 == null) {
                let a = this.aca.c;
                while (a != null) {
                    this.afd(a.c);
                    a = a.a;
                }
                return;
            }
            let b = this.ab8();
            for (let c = 0; c < this.aa9.count; c++) {
                let d;
                if (this.acd.count <= c) {
                    let 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);
            }
        }
        ae9() {
            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), (a, b) => 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;
})();
/**
 * @hidden
 */
export let CalloutLayerView = /*@__PURE__*/ (() => {
    class CalloutLayerView extends AnnotationLayerView {
        constructor(a) {
            super(a);
            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);
        }
        a4() {
            super.a4();
            this.cr = ((() => {
                let $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;
            })());
        }
        cp() {
            let a = new CalloutView(this);
            this.cs.add(a);
            return a;
        }
        cv(a) {
            a.y = 0;
        }
        cx(a) {
            a.y = 1;
        }
        cw(a) {
            this.cs.remove(a);
        }
        c6(a) {
            if (a == null) {
                return a;
            }
            return BrushUtil.o(a, 0.1);
        }
        bj(a, b) {
            super.bj(a, b);
            a.ae(this.cq());
            if (a.d && !b) {
                for (let c = 0; c < this.cs.count; c++) {
                    let d = this.cs._inner[c];
                    if (d.y == 0) {
                        d.j(a);
                    }
                }
            }
        }
        cq() {
            if (this.cn.aaz != null) {
                return this.cn.aaz;
            }
            return this.f.dc.getFontInfo();
        }
        ax(a) {
            super.ax(a);
            for (let b = 0; b < this.cs.count; b++) {
                let c = this.cs._inner[b];
                if (c.y != 0) {
                    continue;
                }
                c.i(this.cn, this.cq(), a);
            }
        }
        c8(a) {
            this.m.ae(this.cq());
            this.ct = this.cu();
            let b = this.m.ai(a, this.ct, true);
            return new Size(1, b.c, b.b);
        }
        cu() {
            let a = this.cq();
            if (isNaN_(this.ct)) {
                let b = FontUtil.getCurrentFontHeight(this.f.dc.dp.j.ae, a);
                this.ct = b;
            }
            return this.ct;
        }
        c7(a, b) {
            if (this.co == null) {
                this.co = new CalloutView(this);
            }
            this.co.h = a;
            this.co.x = b;
            let c = this.co.u();
            this.co.h = null;
            return c;
        }
        cz(a, b, c) {
            a.f = b;
            a.g = c;
        }
        c0(a, b, c) {
            a.k(this.f, b, c);
        }
        c1(a, b) {
            if (b != null && this.cn.ab3) {
                return this.c6(b);
            }
            if (a != null) {
                return this.c6(a.vq);
            }
            return this.f.vq;
        }
        c4() {
            return ((() => {
                let $ret = new Brush();
                $ret.color = Color.u(255, 255, 255, 255);
                return $ret;
            })());
        }
        c2() {
            return ((() => {
                let $ret = new Brush();
                $ret.color = Color.u(255, 0, 0, 0);
                return $ret;
            })());
        }
        c5(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 ((() => {
                let $ret = new Brush();
                $ret.color = Color.u(255, 255, 255, 255);
                return $ret;
            })());
        }
        c3(a, b) {
            if (b != null && this.cn.ab4) {
                return this.c6(b);
            }
            if (a != null) {
                return this.c6(a.vj);
            }
            return this.f.vj;
        }
        cy() {
            this.ct = NaN;
        }
    }
    CalloutLayerView.$t = markType(CalloutLayerView, 'CalloutLayerView', AnnotationLayerView.$);
    return CalloutLayerView;
})();
/**
 * @hidden
 */
export let CalloutView = /*@__PURE__*/ (() => {
    class CalloutView extends Base {
        constructor(a) {
            super();
            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 = ((() => {
                let $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;
        }
        j(a) {
            a.aa();
            a.ah(this.f, this.g);
            let 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();
        }
        get r() {
            return this.q;
        }
        set r(a) {
            if (this.q.x != a.x || this.q.y != a.y) {
                let b = this.u();
                let c = b.height;
                let d = b.width;
                this.q = a;
                let e = CalloutViewHelper.b(this.r, d, c, this.s);
                this.v = e;
            }
        }
        get p() {
            return this.l.ao;
        }
        set p(a) {
            this.l.ao = a;
        }
        get o() {
            return this.t._stroke;
        }
        set o(a) {
            this.t._stroke = a;
        }
        get n() {
            return this.s._stroke;
        }
        set n(a) {
            this.s._stroke = a;
        }
        get m() {
            return this.t._fill;
        }
        set m(a) {
            this.t._fill = a;
        }
        get e() {
            return this.t.ad;
        }
        set e(a) {
            this.t.ad = a;
        }
        get x() {
            return this.w;
        }
        set x(a) {
            this.w = a;
        }
        get d() {
            return this.c;
        }
        set d(a) {
            this.c = a;
        }
        get h() {
            return this.l.al;
        }
        set h(a) {
            if (a == null) {
                this.l.al = "";
            }
            else {
                this.l.al = a.toString();
            }
            let b = this.u();
            let c = b.height;
            let d = b.width;
            let e = CalloutViewHelper.b(this.r, d, c, this.s);
            this.v = e;
        }
        u() {
            let 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);
        }
        k(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;
            }
        }
        i(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;
})();
