/*
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-react-core";
import { Base, runOn, delegateCombine, String_$type, Array_$type, enumGetBox, EnumUtil, typeCast, fromEnum, delegateRemove, Point_$type, Date_$type, markType, markDep } from "igniteui-react-core";
import { Series } from "./Series";
import { CalloutPlacementPositionsCollection } from "./CalloutPlacementPositionsCollection";
import { HighlightedValueLabelMode_$type } from "igniteui-react-core";
import { AutoCalloutVisibilityMode_$type } from "./AutoCalloutVisibilityMode";
import { Brush } from "igniteui-react-core";
import { Thickness } from "igniteui-react-core";
import { CalloutCollisionMode_$type } from "igniteui-react-core";
import { FontUtil } from "igniteui-react-core";
import { Rect } from "igniteui-react-core";
import { BindingFormatter } from "igniteui-react-core";
import { CalloutLayerFrame } from "./CalloutLayerFrame";
import { Size } from "igniteui-react-core";
import { HashSet$1 } from "igniteui-react-core";
import { CalloutAnnotationWrapper } from "./CalloutAnnotationWrapper";
import { List$1 } from "igniteui-react-core";
import { LinkedList$1 } from "igniteui-react-core";
import { Dictionary$2 } from "igniteui-react-core";
import { LinkedListNode$1 } from "igniteui-react-core";
import { LabelCollisionManager } from "igniteui-react-core";
import { SeriesPointOfInterest } from "./SeriesPointOfInterest";
import { CalloutAnnotation } from "./CalloutAnnotation";
import { IFastItemsSource_$type } from "igniteui-react-core";
import { DeviceUtils } from "igniteui-react-core";
import { CalloutLabelUpdatingEventArgs } from "./CalloutLabelUpdatingEventArgs";
import { CalloutSeriesSelectingEventArgs } from "./CalloutSeriesSelectingEventArgs";
import { CalloutStyleUpdatingEventArgs } from "./CalloutStyleUpdatingEventArgs";
import { BrushUtilCore } from "igniteui-react-core";
import { LabelCollisionInfo } from "igniteui-react-core";
import { BrushUtil } from "igniteui-react-core";
import { CalloutRenderStyleUpdatingEventArgs } from "./CalloutRenderStyleUpdatingEventArgs";
import { IHasCategoryAxis_$type } from "./IHasCategoryAxis";
import { QuadTreeBoundingBox } from "igniteui-react-core";
import { ScalerParams } from "./ScalerParams";
import { ViewportUtils } from "./ViewportUtils";
import { CalloutContentUpdatingEventArgs } from "./CalloutContentUpdatingEventArgs";
import { CalloutKey } from "./CalloutKey";
import { DataContext } from "igniteui-react-core";
import { HashPool$2 } from "igniteui-react-core";
import { AxisRange } from "./AxisRange";
import { PropertyMetadata } from "igniteui-react-core";
import { isNaN_, isInfinity } from "igniteui-react-core";
import { stringIsNullOrEmpty } from "igniteui-react-core";
import { FastItemObjectColumn } from "igniteui-react-core";
import { AnnotationLayerView } from "./AnnotationLayerView";
import { TextBlock } from "igniteui-react-core";
import { Color } from "igniteui-react-core";
import { Line } from "igniteui-react-core";
import { CalloutViewHelper } from "./CalloutViewHelper";
import { Rectangle } from "igniteui-react-core";
import { TranslateTransform } from "igniteui-react-core";
/**
 * @hidden
 */
export let CalloutLayer = /*@__PURE__*/ (() => {
    class CalloutLayer extends AnnotationLayer {
        bj() {
            return new CalloutLayer();
        }
        get_eo() {
            return true;
        }
        constructor() {
            super();
            this.aau = true;
            this.aft = new Size(1, 0, 0);
            this.calloutStyleUpdating = null;
            this.calloutRenderStyleUpdating = null;
            this.aai = null;
            this.aaj = null;
            this.aak = null;
            this.aah = null;
            this.aag = null;
            this.abg = new HashSet$1(CalloutAnnotationWrapper.$, 0);
            this.abj = new List$1(CalloutAnnotationWrapper.$, 0);
            this.abk = new List$1(CalloutAnnotationWrapper.$, 0);
            this.z7 = null;
            this.zv = null;
            this.aae = null;
            this.abh = new LinkedList$1(CalloutAnnotationWrapper.$);
            this.abe = new Dictionary$2(CalloutAnnotationWrapper.$, LinkedListNode$1.$.specialize(CalloutAnnotationWrapper.$), 0);
            this.aaq = null;
            this.afr = new Rect(0, 0, 0, 1, 1);
            this.aay = false;
            this.abz = 0;
            this.afq = Rect.empty;
            this.aaw = false;
            this.aax = false;
            this.calloutContentUpdating = null;
            this.calloutLabelUpdating = null;
            this.calloutSeriesSelecting = null;
            this.abi = new List$1(SeriesPointOfInterest.$, 0);
            this.aa0 = false;
            this.aa1 = false;
            this.abm = 0;
            this.aaz = false;
            this.zy = null;
            this.aav = true;
            this.zz = 1;
            FastItemObjectColumn.m();
            this.zv = null;
            this.z7 = new CalloutPlacementPositionsCollection();
            let a = this.z7;
            a.collectionChanged = delegateCombine(a.collectionChanged, runOn(this, this.adu));
            this.xi = true;
            let b = new CalloutLayerFrame();
            let c = new CalloutLayerFrame();
            let d = new CalloutLayerFrame();
            let e = this.kd / 1000;
            this.xa = b;
            this.w9 = c;
            this.xb = d;
            this.ab = CalloutLayer.$;
        }
        adu(a, b) {
            this.ad3();
        }
        ad3() {
            this.zv = this.zx(this.z8);
            this.ad0();
        }
        adv(a, b) {
            this.abk.clear();
            this.rp(false);
        }
        pb(a, b, c, d) {
            super.pb(a, b, c, d);
            let e = this.abf();
            switch (a) {
                case 3:
                    this.ad9(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.aad;
                        this.abk.insert(f, h);
                        this.ad9(f, e);
                    }
                    break;
                case 0:
                    this.abk.v(b, c);
                    break;
                case 2:
                    for (let i = b; i < b + c; i++) {
                        this.ad9(i, e);
                    }
                    break;
                case 4:
                    this.abk.clear();
                    for (let j = 0; j < this.dn.count; j++) {
                        let k = new CalloutAnnotation();
                        let l = new CalloutAnnotationWrapper();
                        l.b = k;
                        l.b.series = this.aad;
                        this.abk.add(l);
                        this.ad9(j, e);
                    }
                    break;
            }
            this.rp(true);
        }
        gf(a) {
            return false;
        }
        afv() {
            let a = new Thickness(0, DeviceUtils.g(3));
            if (isNaN_(this.afu.left) || isNaN_(this.afu.top) || isNaN_(this.afu.right) || isNaN_(this.afu.bottom)) {
                a = new Thickness(0, DeviceUtils.g(3));
            }
            else {
                a = this.afu;
            }
            return a;
        }
        wr() {
            let a = 0;
            let b = 0;
            if (!this.aa2) {
                return new Size(1, b, a);
            }
            if (!this.aau) {
                return this.aft;
            }
            let c = "Ig";
            let d = this.afv();
            let e = this.z6.cr(c, d);
            if (!isNaN_(e.height)) {
                a = Math.max(e.height, a);
            }
            if (!isNaN_(this.abw)) {
                a += this.abw;
            }
            if (!isNaN_(this.abw)) {
                b += this.abw;
            }
            if (!isNaN_(this.abq)) {
                a = Math.max(a, this.abq);
            }
            if (!isNaN_(this.abo)) {
                a = Math.min(a, this.abo);
            }
            if (!isNaN_(this.abr)) {
                b = Math.max(b, this.abr);
            }
            if (!isNaN_(this.abp)) {
                b = Math.min(b, this.abp);
            }
            this.aau = false;
            this.aft = new Size(1, b, a);
            return this.aft;
        }
        abf() {
            let a = new Dictionary$2(String_$type, Series.$, 0);
            if (this.db != null) {
                for (let b = 0; b < this.db.series.count; b++) {
                    let c = this.db.series._inner[b];
                    if (c.name != null && !a.containsKey(c.name)) {
                        a.addItem(c.name, c);
                    }
                }
            }
            return a;
        }
        ad9(a, b) {
            if (this.aap == null || this.aan == null) {
                return;
            }
            let c = a;
            if (this.aao != null) {
                c = this.aao.item(a);
            }
            let d = this.aap.item(a);
            let e = this.aan.item(a);
            let f = this.abk._inner[a];
            if (this.aam != null) {
                if (f.b.ab != this.aam.item(a)) {
                    f.b.key = this.aam.item(a);
                }
            }
            if (this.abe.containsKey(f)) {
                f.b = this.abe.item(f).c.b;
            }
            f.b.xValue = c;
            f.b.yValue = d;
            if (this.calloutLabelUpdating != null) {
                let g = ((() => {
                    let $ret = new CalloutLabelUpdatingEventArgs();
                    $ret.d = c;
                    $ret.e = d;
                    $ret.item = this.dn.item(a);
                    return $ret;
                })());
                this.calloutLabelUpdating(this, g);
                if (g.c != null && !Base.equalsStatic(g.c, f.b.ao)) {
                    let h = g.c;
                    if (this.zy != null) {
                        f.b.text = this.zy.i(h);
                    }
                    else {
                        f.b.text = h != null ? h.toString() : "";
                    }
                }
            }
            else {
                if (this.zy != null) {
                    f.b.text = this.zy.i(e);
                }
                else {
                    f.b.text = e != null ? e.toString() : "";
                }
            }
            if (this.aal != null) {
                f.b.content = this.aal.item(a);
            }
            else {
                f.b.content = this.dn.item(a);
            }
            if (this.calloutSeriesSelecting != null) {
                let i = ((() => {
                    let $ret = new CalloutSeriesSelectingEventArgs();
                    $ret.c = c;
                    $ret.d = d;
                    $ret.item = this.dn.item(a);
                    return $ret;
                })());
                this.calloutSeriesSelecting(this, i);
                if (i.a != null) {
                    f.b.series = i.a;
                }
                else if (i.e != null) {
                    if (b.containsKey(i.e)) {
                        f.b.series = b.item(i.e);
                    }
                }
            }
            this.aea(f);
        }
        aea(a) {
            let b = new Thickness(0, DeviceUtils.g(3));
            if (isNaN_(this.afu.left) || isNaN_(this.afu.top) || isNaN_(this.afu.right) || isNaN_(this.afu.bottom)) {
                b = new Thickness(0, DeviceUtils.g(3));
            }
            else {
                b = this.afu;
            }
            let c = DeviceUtils.g(3);
            if (isNaN_(this.abn)) {
                c = DeviceUtils.g(3);
            }
            else {
                c = this.abn;
            }
            let d = this.afk != null && !this.aba ? this.afk : this.z6.cl(a.b.l, a.b.itemColor);
            let e = this.afp != null ? this.afp : null;
            let f = this.afn != null ? this.afn : this.z6.co();
            let g = this.afl != null ? this.afl : this.z6.cm();
            let h = this.afo != null && !this.abb ? this.afo : this.z6.cp(a.b.l, a.b.itemColor);
            let i = this.afm != null ? this.afm : this.z6.cn(a.b.l, a.b.itemColor);
            let j = isNaN_(this.abx) ? 0 : this.abx;
            if (e == null && (this.aa8 || this.afn != null || this.afl != null)) {
                let k = d;
                if (k == null || BrushUtilCore.a(d)) {
                    k = this.db != null ? this.db.vk : 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.h(255, 255, 255, 255);
                    }
                }
                e = BrushUtil.j(k, g, f);
            }
            if (e == null) {
                e = this.z6.co();
            }
            if (this.aa6 && 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;
        }
        kq(a, b) {
            let c = this.nd(b);
            if (c == CalloutLayer.$$p[31]) {
                return this.kr(a, b, this.ac9);
            }
            if (c == CalloutLayer.$$p[42]) {
                return this.kr(a, b, this.adp);
            }
            if (c == CalloutLayer.$$p[43]) {
                return this.kr(a, b, this.ads);
            }
            if (c == CalloutLayer.$$p[28]) {
                return this.kr(a, b, this.ac3);
            }
            if (c == CalloutLayer.$$p[22]) {
                return this.kr(a, b, this.acv);
            }
            return super.kq(a, b);
        }
        md(a) {
            let b = this.nd(a);
            if (b == CalloutLayer.$$p[31]) {
                return this.ac9;
            }
            if (b == CalloutLayer.$$p[42]) {
                return this.adp;
            }
            if (b == CalloutLayer.$$p[43]) {
                return this.ads;
            }
            if (b == CalloutLayer.$$p[28]) {
                return this.ac3;
            }
            if (b == CalloutLayer.$$p[22]) {
                return this.acv;
            }
            return super.md(a);
        }
        get aan() {
            return this.aai;
        }
        set aan(a) {
            if (this.aai != a) {
                let b = this.aai;
                this.aai = a;
                this.raisePropertyChanged("LabelColumn", b, this.aai);
            }
        }
        get aao() {
            return this.aaj;
        }
        set aao(a) {
            if (this.aaj != a) {
                let b = this.aaj;
                this.aaj = a;
                this.raisePropertyChanged("XColumn", b, this.aaj);
            }
        }
        get aap() {
            return this.aak;
        }
        set aap(a) {
            if (this.aak != a) {
                let b = this.aak;
                this.aak = a;
                this.raisePropertyChanged("YColumn", b, this.aak);
            }
        }
        get aam() {
            return this.aah;
        }
        set aam(a) {
            if (this.aah != a) {
                let b = this.aah;
                this.aah = a;
                this.raisePropertyChanged("KeyColumn", b, this.aah);
            }
        }
        get aal() {
            return this.aag;
        }
        set aal(a) {
            if (this.aag != a) {
                let b = this.aag;
                this.aag = a;
                this.raisePropertyChanged("ContentColumn", b, this.aag);
            }
        }
        adx(a, b) {
            if (b.propertyName == CalloutAnnotation.$$p[15] || b.propertyName == CalloutAnnotation.$$p[16]) {
                let c = a.k;
                if (!this.abg.contains(c)) {
                    this.abg.add_1(c);
                    this.abj.add(c);
                    this.rp(false);
                }
            }
        }
        cs() {
            return new CalloutLayerView(this);
        }
        qz(a) {
            super.qz(a);
            this.z6 = a;
        }
        get z8() {
            return this.z7;
        }
        set z8(a) {
            let b = this.z8;
            if (a != b) {
                this.z7 = a;
                this.raisePropertyChanged("AllowedPositions", b, this.z8);
            }
        }
        gu(a) {
            if (this.aad == null) {
                return true;
            }
            if (this.aad == a) {
                return true;
            }
            return false;
        }
        get z1() {
            return EnumUtil.getEnumValue(AutoCalloutVisibilityMode_$type, this.c(CalloutLayer.aew));
        }
        set z1(a) {
            this.h(CalloutLayer.aew, enumGetBox(AutoCalloutVisibilityMode_$type, a));
        }
        get z0() {
            return this.zz;
        }
        set z0(a) {
            this.zz = a;
        }
        get afu() {
            return new Thickness(1, this.abt, this.abv, this.abu, this.abs);
        }
        get aaf() {
            if (this.aae == null) {
                this.aae = FontUtil.toFontInfo(this.jz, this.adf);
            }
            return this.aae;
        }
        yn(a, b) {
            if (this.aad == null || this.aad == a) {
                if (!this.a1.c) {
                    this.rp(b);
                }
            }
        }
        yp(a, b) {
            super.yp(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();
            let d = this.abl();
            let e = new List$1(CalloutAnnotationWrapper.$, 0);
            let f = Number.POSITIVE_INFINITY;
            let g = true;
            if (this.aa3) {
                if (this.xg(this.aad)) {
                    if (typeCast(IHasCategoryAxis_$type, this.aad) !== null) {
                        let h = this.aad.getCategoryWidth();
                        if (!isNaN_(h) && !isInfinity(h) && h > 0) {
                            f = Math.min(f, h);
                        }
                    }
                    this.ad5(this.aad, c, e);
                }
                else {
                    for (let i of fromEnum(this.db.series)) {
                        if (this.xg(i)) {
                            if (typeCast(IHasCategoryAxis_$type, i) !== null) {
                                let j = i.getCategoryWidth();
                                if (!isNaN_(j) && !isInfinity(j) && j > 0) {
                                    f = Math.min(f, j);
                                }
                            }
                            if (!i.es) {
                                if (!i.isVertical) {
                                    g = false;
                                }
                            }
                            let k = false;
                            if (i.eg && this.aac == 0 || this.aac == 3 || this.aac == 2) {
                                if (this.aac == 0 || this.aac == 2) {
                                    k = true;
                                }
                                i.pz((l) => {
                                    this.ad5(l, c, e);
                                    return true;
                                });
                            }
                            if (!k) {
                                this.ad5(i, c, e);
                            }
                        }
                    }
                }
            }
            if (this.aa3 && this.z0 == 2) {
                let l = 0;
                let m = 0;
                let n = 1.7976931348623157E+308;
                let o = 1.7976931348623157E+308;
                let p = -1.7976931348623157E+308;
                let q = -1.7976931348623157E+308;
                if (e.count > 0) {
                    if (e._inner[0].c != null) {
                        l = e._inner[0].e;
                        m = e._inner[0].f;
                    }
                    for (let r = 0; r < e.count; r++) {
                        let s = e._inner[r];
                        if (s.c != null) {
                            let t = s.e;
                            let u = s.f;
                            if (t != l) {
                                n = Math.min(n, Math.abs(t - l));
                            }
                            if (u != m) {
                                o = Math.min(o, Math.abs(u - m));
                            }
                            p = Math.max(s.c.p + s.c.p, p);
                            q = Math.max(s.c.o + s.c.o, q);
                        }
                    }
                    if (g) {
                        if (!isNaN_(f) && !isInfinity(f)) {
                            if (q > f) {
                                e.clear();
                            }
                        }
                        else {
                            if (q > o) {
                                e.clear();
                            }
                        }
                    }
                    else {
                        if (!isNaN_(f) && !isInfinity(f)) {
                            if (p > f) {
                                e.clear();
                            }
                        }
                        else {
                            if (p > n) {
                                e.clear();
                            }
                        }
                    }
                }
            }
            this.ad4(c, d, e);
        }
        sp(a, b) {
            super.sp(a, b);
            let c = b.width - this.afr.width;
            let d = b.height - this.afr.height;
            let e = 0;
            if (Math.abs(c) > Math.abs(d)) {
                e = c;
                this.abm = c * this.wq.width;
            }
            else {
                e = d;
                this.abm = d * this.wq.height;
            }
            if (e > 0 && this.abm > 5) {
                this.aa1 = true;
            }
            if (e < 0 && this.abm > 5) {
                this.aa0 = true;
            }
        }
        so(a, b) {
            super.so(a, b);
            if (!a.equals1(b)) {
                this.aaz = true;
            }
        }
        get afs() {
            return this.afq;
        }
        set afs(a) {
            this.afq = a;
        }
        ad4(a, b, c) {
            if (this.db != null) {
                this.afr = this.db.v4;
            }
            if (this.wq.isEmpty) {
                return;
            }
            this.afs = new Rect(0, this.wq.left, this.wq.top, this.wq.width, this.wq.height);
            if (this.aaq != null && this.acs != null && this.acs != this.aaq.bd) {
                this.adz();
            }
            if (this.aaq != null && this.aaq.j != this.aas()) {
                this.adz();
            }
            if (this.aaq == null) {
                let d = this.aar();
                if (d != null) {
                    this.aaq = d;
                    let e = this.aaq;
                    e.labelsMoved = delegateCombine(e.labelsMoved, runOn(this, this.adw));
                }
                else {
                    let f = this.wh(this.cv);
                    let g = new Array(2);
                    g[0] = 0;
                    g[1] = 3;
                    if (this.aad != null) {
                        if (this.aad.isVertical) {
                            g = new Array(2);
                            g[0] = 2;
                            g[1] = 1;
                        }
                    }
                    else {
                        let h = false;
                        if (this.db != null && this.db.series.count > 0) {
                            h = true;
                            for (let i of fromEnum(this.db.series)) {
                                if (!i.es) {
                                    if (!i.isVertical) {
                                        h = false;
                                    }
                                }
                            }
                        }
                        if (h) {
                            g = new Array(2);
                            g[0] = 2;
                            g[1] = 1;
                        }
                    }
                    if (this.z3 == 4 || this.z3 == 6) {
                        g = new Array(4);
                        g[0] = 10;
                        g[1] = 11;
                        g[2] = 8;
                        g[3] = 9;
                    }
                    if (this.z3 == 5) {
                        g = new Array(4);
                        g[0] = 9;
                        g[1] = 10;
                        g[2] = 11;
                        g[3] = 8;
                    }
                    if (this.z3 == 7) {
                        g = new Array(4);
                        g = new Array(4);
                        g[0] = 8;
                        g[1] = 10;
                        g[2] = 11;
                        g[3] = 9;
                    }
                    this.aaq = new LabelCollisionManager(this.wq.right, this.wq.bottom, this.wq, this.z6.j(), this.abw, this.aas(), g, this.ab3(), this.ab2(), this.aa4, this.zv);
                    this.aaq.v = this.aa7;
                    if (this.acs != null) {
                        this.aaq.bd = this.acs;
                        this.aaq.bb = this;
                    }
                    let j = this.aaq;
                    j.labelsMoved = delegateCombine(j.labelsMoved, runOn(this, this.adw));
                }
            }
            if (this.aa0) {
                this.aa0 = false;
                if (this.aaq.a9 > 2) {
                    this.aay = true;
                }
            }
            if (this.aa1) {
                this.aa1 = false;
                if (this.abm > 5) {
                    this.aay = true;
                }
            }
            if (this.aaz) {
                this.aaz = false;
                this.aaq.bs(this.wq.right, this.wq.bottom, this.wq);
                this.aay = 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.abh.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.adx));
                    this.abh.h(r);
                    this.abe.removeItem(r.c);
                    this.aaq.br(r.c.c);
                }
                r = s;
            }
            for (let u = 0; u < b.count; u++) {
                if (!this.abe.containsKey(b._inner[u])) {
                    this.abh.f(b._inner[u]);
                    let v = b._inner[u].b;
                    v.propertyChanged = delegateCombine(v.propertyChanged, runOn(this, this.adx));
                    this.abe.addItem(b._inner[u], this.abh.d);
                    m.add(b._inner[u]);
                    k.add_1(b._inner[u]);
                    this.aay = true;
                }
            }
            for (let w = 0; w < c.count; w++) {
                if (!this.abe.containsKey(c._inner[w])) {
                    this.abh.f(c._inner[w]);
                    this.abe.addItem(c._inner[w], this.abh.d);
                    let x = c._inner[w].b;
                    x.propertyChanged = delegateCombine(x.propertyChanged, runOn(this, this.adx));
                    m.add(c._inner[w]);
                    k.add_1(c._inner[w]);
                    this.aay = true;
                }
            }
            if (this.aaw == true) {
                this.aaw = false;
                this.aay = true;
            }
            let y = false;
            if (this.abj.count > 0) {
                y = true;
                this.abj.clear();
                this.abg.clear();
            }
            r = this.abh.c;
            while (r != null) {
                let z = this.aat(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.aaq.ad(ab, false);
                        }
                        if (aa) {
                            this.aaq.be(ab);
                        }
                        else {
                            this.aaq.bo(ab);
                        }
                    }
                }
                r = r.a;
            }
            let ac = this.aaq.ba();
            let ad = this.aaq.af();
            if (!this.aay && y && (ac != 0 || ad)) {
                {
                    this.aay = true;
                }
            }
            if (ad) {
                if (this.aaq.x()) {
                    this.aay = true;
                }
            }
            if (this.aay && (ac != 0 || ad)) {
                this.aay = false;
                this.abz = 0x7FFFFFFF;
                if (this.acs != null) {
                    let ae = true;
                    for (let af = 0; af < this.db.series.count; af++) {
                        let ag = this.db.series._inner[af];
                        if (ag.es && typeCast(CalloutLayer.$, ag) !== null) {
                            let ah = ag;
                            if (ah.acs == this.acs) {
                                if (!ah.afs.equals1(this.aaq.b0)) {
                                    ae = false;
                                    break;
                                }
                            }
                        }
                    }
                    if (ae) {
                        this.aaq.bv();
                    }
                    else {
                        this.aaq.bf();
                        this.aaq.bg();
                    }
                }
                else {
                    this.aaq.bv();
                }
            }
            else {
                this.aaq.bg();
            }
            let ai = this.abh.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.aa5;
            let a0 = this.aa7;
            let a1 = this.cv.bt();
            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.aaq.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.adh(a2, at);
                    let a6 = this.aaq.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;
            }
        }
        adh(a, b) {
            let c = Math.max(this.aaq.as(a.c.c), this.aaq.at(a.c.c));
            if (c <= 0) {
                return b;
            }
            let d = b.length;
            let e = this.z6.cr(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.z6.cr(b, a.b.backgroundPadding);
                f = e.width;
            }
            return b;
        }
        adz() {
            if (this.aaq != null) {
                let a = this.abh.c;
                while (a != null) {
                    let b = a.c.c;
                    if (b != null) {
                        this.aaq.br(b);
                    }
                    a = a.a;
                }
                let c = this.aaq;
                c.labelsMoved = delegateRemove(c.labelsMoved, runOn(this, this.adw));
                this.aaq = null;
            }
            this.ady();
        }
        aar() {
            if (this.db == null) {
                return null;
            }
            for (let a = 0; a < this.db.series.count; a++) {
                let b = this.db.series._inner[a];
                if (b.es && typeCast(CalloutLayer.$, b) !== null) {
                    let c = b;
                    if (c != this) {
                        if (c.acs != null && c.acs == this.acs) {
                            if (c.aaq != null) {
                                return c.aaq;
                            }
                        }
                    }
                }
            }
            return null;
        }
        ab2() {
            return 20000;
        }
        ab3() {
            return 300;
        }
        aas() {
            switch (this.z3) {
                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;
        }
        adw(a) {
            let b = this.aaq.ba();
            let c = this.abz;
            if (b < this.abz) {
                this.abz = b;
                if (c != 0x7FFFFFFF) {
                    this.rp(false);
                }
            }
        }
        aat(a) {
            let b = this.aad;
            if (a.b.l != null) {
                b = a.b.l;
            }
            if (b == null) {
                for (let c = 0; c < this.db.series.count; c++) {
                    let d = this.db.series._inner[c];
                    if (!d.es) {
                        b = d;
                        break;
                    }
                }
            }
            if (b == null) {
                return null;
            }
            let e = b.ai();
            let f = b.iy();
            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].b9) {
                    i = true;
                    g = e[j];
                }
                else if (e[j].cm) {
                    i = true;
                    h = e[j];
                }
                else if (e[j].cp) {
                    h = e[j];
                }
                else {
                    g = e[j];
                }
            }
            if (g == null || h == null) {
                return null;
            }
            if (!g.co() || !h.co()) {
                return null;
            }
            let k = 0;
            let l = 0;
            if (g.cb && g.categoryMode != 0) {
                if (b.e6) {
                    k = b.getOffsetValue();
                }
                else if (b.ey) {
                    k = b.getOffsetValue();
                }
            }
            if (h.cb && h.categoryMode != 0) {
                if (b.ey) {
                    l = b.getOffsetValue();
                }
            }
            let m = new ScalerParams(0, this.db.v4, g.kh, g.ch, g.kc());
            m.b = f;
            let n = new ScalerParams(0, this.db.v4, h.kh, h.ch, h.kc());
            n.b = f;
            let o = 0;
            let p = 0;
            if (i) {
                o = g.el(this.aby(a.b.ac), m) + k;
                p = h.el(this.aby(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.el(this.aby(a.b.ac), m) + k;
                p = h.el(this.aby(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;
        }
        aby(a) {
            if (typeCast(Date_$type, a) !== null) {
                return a.getTime();
            }
            if (a == null) {
                return 0;
            }
            return a;
        }
        abl() {
            let a = new List$1(CalloutAnnotationWrapper.$, 0);
            for (let b = 0; b < this.abk.count; b++) {
                if (stringIsNullOrEmpty(this.abk._inner[b].b.ao)) {
                    continue;
                }
                if (this.abk._inner[b].c == null) {
                    let c = new LabelCollisionInfo();
                    this.abk._inner[b].c = c;
                    let d = this.z6.cr(this.ab4(this.abk._inner[b]), this.abk._inner[b].b.backgroundPadding);
                    c.o = d.height / 2;
                    c.p = d.width / 2;
                }
                let e = this.aat(this.abk._inner[b]);
                if (e == null || e.d < this.wq.left || e.d > this.wq.right || e.e < this.wq.top || e.e > this.wq.bottom) {
                    continue;
                }
                a.add(this.abk._inner[b]);
            }
            return a;
        }
        ab4(a) {
            return a.b.ao;
        }
        xg(a) {
            if (!super.xg(a)) {
                return false;
            }
            if (this.adc != null) {
                if (a.fb) {
                    let b = a.nc();
                    if (!Base.equalsStatic(this.adc, b)) {
                        return false;
                    }
                }
                else {
                    if (!Base.equalsStatic(this.adc, a.name)) {
                        return false;
                    }
                }
            }
            return true;
        }
        qn() {
            super.qn();
            if (!this.a1.c && !this.d3()) {
                return;
            }
            if (this.aav) {
                this.aav = false;
                this.ad6();
                this.ad1();
            }
            if (this.d3()) {
                this.ad8(this.xb, false);
            }
            else {
                this.ad8(this.w9, false);
            }
        }
        ad2() {
            if (!this.aax) {
                this.aax = true;
                this.rp(true);
            }
        }
        ad5(a, b, c) {
            let d = false;
            if (this.aax) {
                this.aax = false;
                d = true;
            }
            a.ki = this.zy;
            if (!a.gi && a.eb(this.abi, this.abd, this.aa9, this.ab0, false)) {
                let e = this.abi;
                for (let f = 0; f < this.abi.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.abe.containsKey(m)) {
                        m = this.abe.item(m).c;
                        n = m.b;
                        o = d;
                    }
                    else {
                        o = true;
                    }
                    let p = n.ac;
                    let q = n.ad;
                    if (this.aby(p) != this.aby(g.d) && (!isNaN_(this.aby(p)) || !isNaN_(this.aby(g.d)))) {
                        n.xValue = g.d;
                    }
                    if (this.aby(q) != this.aby(g.e) && (!isNaN_(this.aby(q)) || !isNaN_(this.aby(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) {
                        if (this.calloutLabelUpdating != null) {
                            let s = ((() => {
                                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, s);
                            if (s.c != null && !Base.equalsStatic(s.c, m.b.ao)) {
                                let t = s.c;
                                if (this.zy != null) {
                                    m.b.text = this.zy.i(t);
                                }
                                else {
                                    m.b.text = t != null ? t.toString() : "";
                                }
                            }
                        }
                        else {
                            if (g.f != null) {
                                n.text = g.f;
                            }
                        }
                    }
                    if (n.ao == null) {
                        continue;
                    }
                    if (o || r) {
                        if (this.calloutContentUpdating != null) {
                            let u = ((() => {
                                let $ret = new CalloutContentUpdatingEventArgs();
                                $ret.c = n.ac;
                                $ret.d = n.ad;
                                $ret.item = h;
                                $ret.a = i;
                                return $ret;
                            })());
                            this.calloutContentUpdating(this, u);
                            if (u.a != null && u.a != m.b.aa) {
                                m.b.content = u.a;
                            }
                        }
                        else {
                            if (i != null && i != m.b.aa) {
                                m.b.content = i;
                            }
                        }
                    }
                    if (o) {
                        this.aea(m);
                    }
                    if (m.c == null) {
                        let v = new LabelCollisionInfo();
                        m.c = v;
                        let w = this.z6.cr(this.ab4(m), m.b.backgroundPadding);
                        v.o = w.height / 2;
                        v.p = w.width / 2;
                    }
                    let x = this.aat(m);
                    if (x == null || x.d < this.wq.left || x.d > this.wq.right || x.e < this.wq.top || x.e > this.wq.bottom) {
                        continue;
                    }
                    m.e = x.d;
                    m.f = x.e;
                    if (g.a != null) {
                        m.c.a = g.a;
                    }
                    c.add(m);
                }
            }
            a.ki = null;
        }
        b2() {
            return 1;
        }
        a2(a, b) {
            let c = this.aaq.i(a, b);
            if (c == null) {
                return null;
            }
            return c.y;
        }
        gw(a, b) {
            if (this.aaq == null) {
                return false;
            }
            return this.aaq.i(a, b) != null;
        }
        ad8(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.z6.cb.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.cv.bt();
                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.z6.cj(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.z6.ck(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.z6.cb.c)) {
                if (!d.contains(i)) {
                    h.add(i);
                }
            }
            for (let j = 0; j < h.count; j++) {
                this.z6.cb.h(h._inner[j]);
            }
        }
        ys(a, b) {
            super.ys(a, b);
            if (this.d3()) {
                this.ad8(this.xb, true);
            }
            else {
                this.ad8(this.w9, false);
            }
        }
        ga() {
            return true;
        }
        q7(a, b, c, d) {
            super.q7(a, b, c, d);
            switch (b) {
                case CalloutLayer.$$p[35]:
                    this.aae = null;
                    this.z6.ci();
                    this.rp(true);
                    break;
                case CalloutLayer.$$p[33]:
                case CalloutLayer.$$p[34]:
                    this.rp(true);
                    break;
                case CalloutLayer.$$p[29]:
                case CalloutLayer.$$p[30]:
                    if (this.ac6 != null) {
                        this.zy = new BindingFormatter();
                        this.zy.j = this.ac6;
                        this.zy.d = this.zw;
                    }
                    else {
                        this.zy = null;
                    }
                    break;
                case CalloutLayer.$$p[21]:
                case CalloutLayer.$$p[23]:
                    this.rp(true);
                    break;
                case "SeriesViewer":
                    if (c != null) {
                        let e = c;
                        e.seriesAnimating = delegateRemove(e.seriesAnimating, runOn(this, this.ad7));
                    }
                    if (d != null) {
                        let f = d;
                        f.seriesAnimating = delegateCombine(f.seriesAnimating, runOn(this, this.ad7));
                    }
                    if (d == null) {
                        this.adz();
                    }
                    break;
                case "AutoCalloutVisibilityMode":
                    this.z0 = this.z2();
                    this.ad0();
                    break;
                case "AllowedPositions":
                    if (c != null) {
                        let g = c;
                        g.collectionChanged = delegateRemove(g.collectionChanged, runOn(this, this.adu));
                    }
                    if (d != null) {
                        let h = d;
                        h.collectionChanged = delegateCombine(h.collectionChanged, runOn(this, this.adu));
                    }
                    this.zv = this.zx(this.z8);
                    this.ad0();
                    break;
                case CalloutLayer.$$p[24]:
                case CalloutLayer.$$p[25]:
                case CalloutLayer.$$p[1]:
                case CalloutLayer.$$p[13]:
                case CalloutLayer.$$p[11]:
                case CalloutLayer.$$p[37]:
                case CalloutLayer.$$p[40]:
                case CalloutLayer.$$p[27]:
                case CalloutLayer.$$p[26]:
                case CalloutLayer.$$p[15]:
                case CalloutLayer.$$p[17]:
                case CalloutLayer.$$p[16]:
                case CalloutLayer.$$p[14]:
                case "Visibility":
                case CalloutLayer.$$p[18]:
                case CalloutLayer.$$p[5]:
                case CalloutLayer.$$p[8]:
                case CalloutLayer.$$p[6]:
                case CalloutLayer.$$p[9]:
                case CalloutLayer.$$p[7]:
                    this.aau = true;
                    this.ad0();
                    break;
                case CalloutLayer.$$p[19]:
                case CalloutLayer.$$p[20]:
                case CalloutLayer.$$p[2]:
                    this.ad0();
                    break;
                case CalloutLayer.$$p[32]:
                    this.ad0();
                    if (this.aaq != null) {
                        this.aaq.v = d;
                    }
                    break;
                case CalloutLayer.$$p[31]:
                    if (this.dn != null) {
                        this.dn.deregisterColumn(this.aan);
                        this.aan = this.dm(this.ac9);
                    }
                    break;
                case "LabelColumn":
                    this.ad0();
                    break;
                case CalloutLayer.$$p[22]:
                    if (this.dn != null) {
                        this.dn.deregisterColumn(this.aal);
                        this.aal = this.dm(this.acv);
                    }
                    break;
                case "ContentColumn":
                    this.ad0();
                    break;
                case CalloutLayer.$$p[42]:
                    if (this.dn != null) {
                        this.dn.deregisterColumn(this.aao);
                        this.aao = stringIsNullOrEmpty(this.adp) == false ? this.dm(this.adp) : null;
                    }
                    break;
                case "XColumn":
                    this.ad0();
                    break;
                case CalloutLayer.$$p[43]:
                    if (this.dn != null) {
                        this.dn.deregisterColumn(this.aap);
                        this.aap = this.dm(this.ads);
                    }
                    break;
                case "YColumn":
                    this.ad0();
                    break;
                case CalloutLayer.$$p[28]:
                    if (this.dn != null) {
                        this.dn.deregisterColumn(this.aam);
                        this.aam = this.dm(this.ac3);
                    }
                    break;
                case "KeyColumn":
                    this.ad0();
                    break;
                case "FastItemsSource":
                    this.aaw = true;
                    if (typeCast(IFastItemsSource_$type, c) != null) {
                        c.deregisterColumn(this.aan);
                        c.deregisterColumn(this.aal);
                        c.deregisterColumn(this.aao);
                        c.deregisterColumn(this.aap);
                        c.deregisterColumn(this.aam);
                        this.aan = null;
                        this.aal = null;
                        this.aao = null;
                        this.aap = null;
                        this.aam = null;
                        this.abk.clear();
                    }
                    if (typeCast(IFastItemsSource_$type, d) != null) {
                        this.aan = this.dm(this.ac9);
                        this.aal = this.dm(this.acv);
                        if (stringIsNullOrEmpty(this.adp) == false) {
                            this.aao = this.dm(this.adp);
                        }
                        this.aap = this.dm(this.ads);
                        this.aam = this.dm(this.ac3);
                    }
                    this.ad0();
                    break;
            }
        }
        z2() {
            if (this.z1 == 0) {
                return 1;
            }
            return this.z1;
        }
        zx(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;
        }
        ad7(a) {
            if (a.es) {
                return;
            }
            if ((a == this.aad || this.aad == null) && this.aa3) {
                this.rp(false);
            }
        }
        ad0() {
            if (this.aav == false) {
                this.aav = true;
                this.rp(false);
            }
        }
        ax(a, b, c) {
            let d = this.getEffectiveViewport();
            let e = this.db.wj;
            let f = this.wr();
            let g = 0;
            if (b.cp) {
                let h = new ScalerParams(0, c, e, !b.ch, d);
                g = (b.eo(f.height, h));
                return new AxisRange(a.c - g, a.b + g);
            }
            else {
                let i = new ScalerParams(0, c, e, b.ch, d);
                g = (b.eo(f.width, i));
                return new AxisRange(a.c - g, a.b + g);
            }
        }
        ad6() {
            if (!this.aa2) {
                return;
            }
            if (this.c9 == null) {
                return;
            }
            let a = this.c9.series;
            if (a == null) {
                return;
            }
            let b = this.c9.axes;
            if (b == null) {
                return;
            }
            for (let c of fromEnum(b)) {
                c.hl();
                c.c2(true);
            }
        }
        ady() {
            this.z6.cb.clear();
            this.abh.g();
            this.abe.clear();
        }
        ad1() {
            if (this.aap == null || this.aan == null) {
                let a = this.abh.c;
                while (a != null) {
                    this.aea(a.c);
                    a = a.a;
                }
                return;
            }
            let b = this.abf();
            for (let c = 0; c < this.aap.count; c++) {
                let d;
                if (this.abk.count <= c) {
                    let e = new CalloutAnnotation();
                    d = new CalloutAnnotationWrapper();
                    d.b = e;
                    d.b.series = this.aad;
                    this.abk.add(d);
                }
                else {
                    d = this.abk._inner[c];
                }
                this.ad9(c, b);
            }
        }
    }
    CalloutLayer.$t = /*@__PURE__*/ markType(CalloutLayer, 'CalloutLayer', AnnotationLayer.$);
    CalloutLayer.aew = /*@__PURE__*/ DependencyProperty.i("AutoCalloutVisibilityMode", AutoCalloutVisibilityMode_$type, CalloutLayer.$, /*@__PURE__*/ new PropertyMetadata(2, /*@__PURE__*/ enumGetBox(AutoCalloutVisibilityMode_$type, 0), (a, b) => a.raisePropertyChanged("AutoCalloutVisibilityMode", b.oldValue, b.newValue)));
    CalloutLayer.$$p = /*@__PURE__*/ markDep(DependencyProperty, PropertyMetadata, CalloutLayer, 'raisePropertyChanged', ['AutoCalloutLabelPrecision:ab0:aeb', [1, 5], 'CalloutBackground:afk:aec', [Brush.$, null], 'CalloutCollisionMode:z3:aed', [CalloutCollisionMode_$type, /*@__PURE__*/ enumGetBox(CalloutCollisionMode_$type, 3)], 'CalloutCornerRadius:abn:aee', [1, NaN], 'CalloutDarkTextColor:afl:aef', [Brush.$, null], 'CalloutExpandsAxisBufferEnabled:aa2:aeg', [0, false], 'CalloutExpandsAxisBufferMaxHeight:abo:aeh', [1, 400], 'CalloutExpandsAxisBufferMaxWidth:abp:aei', [1, 400], 'CalloutExpandsAxisBufferMinHeight:abq:aej', [1, 50], 'CalloutExpandsAxisBufferMinWidth:abr:aek', [1, 50], 'CalloutInterpolatedValuePrecision:ab1:ael', [1, -1], 'CalloutLeaderBrush:afm:aem', [Brush.$, null], 'CalloutLightTextColor:afn:aen', [Brush.$, null], 'CalloutOutline:afo:aeo', [Brush.$, null], 'CalloutPaddingBottom:abs:aep', [1, NaN], 'CalloutPaddingLeft:abt:aeq', [1, NaN], 'CalloutPaddingRight:abu:aer', [1, NaN], 'CalloutPaddingTop:abv:aes', [1, NaN], 'CalloutPositionPadding:abw:aet', [1, 10], 'CalloutStrokeThickness:abx:aeu', [1, NaN], 'CalloutTextColor:afp:aev', [Brush.$, null], 'CollisionChannel:acs:aex', [2, null], 'ContentMemberPath:acv:aey', [2, null], 'HighlightedValueLabelMode:aac:aez', [HighlightedValueLabelMode_$type, /*@__PURE__*/ enumGetBox(HighlightedValueLabelMode_$type, 0)], 'IsAutoCalloutBehaviorEnabled:aa3:ae0', [0, false], 'IsCalloutOffsettingEnabled:aa4:ae1', [0, true], 'IsCustomCalloutRenderStyleEnabled:aa5:ae2', [0, false], 'IsCustomCalloutStyleEnabled:aa6:ae3', [0, false], 'KeyMemberPath:ac3:ae4', [2, null], 'LabelFormat:ac6:ae5', [2, null], 'LabelFormatSpecifiers:zw:ae6', [Array_$type, null], 'LabelMemberPath:ac9:ae7', [2, null], 'ShouldTruncateOnBoundaryCollisions:aa7:ae8', [0, false], 'TargetSeriesName:adc:ae9', [2, null], 'TargetSeries:aad:afa', [Series.$, null], 'TextStyle:adf:afb', [2, null], 'UseAutoContrastingLabelColors:aa8:afc', [0, false], 'UseInterpolatedValueForAutoCalloutLabels:aa9:afd', [0, false], 'UseItemColorForFill:aba:afe', [0, false], 'UseItemColorForOutline:abb:aff', [0, false], 'UseSeriesColorForOutline:abc:afg', [0, false], 'UseValueForAutoCalloutLabels:abd:afh', [0, true], 'XMemberPath:adp:afi', [2, null], 'YMemberPath:ads:afj', [2, null]]);
    return CalloutLayer;
})();
/**
 * @hidden
 */
export let CalloutLayerView = /*@__PURE__*/ (() => {
    class CalloutLayerView extends AnnotationLayerView {
        constructor(a) {
            super(a);
            this.b7 = null;
            this.cc = null;
            this.cb = null;
            this.cd = NaN;
            this.b8 = null;
            this.b7 = a;
            this.cc = new List$1(CalloutView.$, 0);
        }
        au() {
            super.au();
            this.cb = ((() => {
                let $ret = new HashPool$2(CalloutAnnotationWrapper.$, CalloutView.$);
                $ret.create = runOn(this, this.b9);
                $ret.activate = runOn(this, this.cf);
                $ret.disactivate = runOn(this, this.ch);
                $ret.destroy = runOn(this, this.cg);
                return $ret;
            })());
        }
        b9() {
            let a = new CalloutView(this);
            this.cc.add(a);
            return a;
        }
        cf(a) {
            a.y = 0;
        }
        ch(a) {
            a.y = 1;
        }
        cg(a) {
            this.cc.remove(a);
        }
        cq(a) {
            if (a == null) {
                return a;
            }
            return BrushUtil.m(a, 0.1);
        }
        a8(a, b) {
            super.a8(a, b);
            a.ad(this.ca());
            if (a.d && !b) {
                for (let c = 0; c < this.cc.count; c++) {
                    let d = this.cc._inner[c];
                    if (d.y == 0) {
                        d.j(a);
                    }
                }
            }
        }
        ca() {
            if (this.b7.aaf != null) {
                return this.b7.aaf;
            }
            return this.e.db.getFontInfo();
        }
        an(a) {
            super.an(a);
            for (let b = 0; b < this.cc.count; b++) {
                let c = this.cc._inner[b];
                if (c.y != 0) {
                    continue;
                }
                c.i(this.b7, this.ca(), a);
            }
        }
        cs(a) {
            this.k.ad(this.ca());
            this.cd = this.ce();
            let b = this.k.ah(a, this.cd, true);
            return new Size(1, b.c, b.b);
        }
        ce() {
            let a = this.ca();
            if (isNaN_(this.cd)) {
                let b = FontUtil.getCurrentFontHeight(this.e.db.c9.j.ae, a);
                this.cd = b;
            }
            return this.cd;
        }
        cr(a, b) {
            if (this.b8 == null) {
                this.b8 = new CalloutView(this);
            }
            this.b8.h = a;
            this.b8.x = b;
            let c = this.b8.u();
            this.b8.h = null;
            return c;
        }
        cj(a, b, c) {
            a.f = b;
            a.g = c;
        }
        ck(a, b, c) {
            a.k(this.e, b, c);
        }
        cl(a, b) {
            if (b != null && this.b7.aba) {
                return this.cq(b);
            }
            if (a != null) {
                return this.cq(a.ve);
            }
            return this.e.ve;
        }
        co() {
            return ((() => {
                let $ret = new Brush();
                $ret.color = Color.u(255, 255, 255, 255);
                return $ret;
            })());
        }
        cm() {
            return ((() => {
                let $ret = new Brush();
                $ret.color = Color.u(255, 0, 0, 0);
                return $ret;
            })());
        }
        cp(a, b) {
            if (b != null && this.b7.abb) {
                return this.cq(b);
            }
            if (this.b7.abc) {
                if (a != null) {
                    return this.cq(a.ve);
                }
            }
            return ((() => {
                let $ret = new Brush();
                $ret.color = Color.u(255, 255, 255, 255);
                return $ret;
            })());
        }
        cn(a, b) {
            if (b != null && this.b7.abb) {
                return this.cq(b);
            }
            if (a != null) {
                return this.cq(a.u7);
            }
            return this.e.u7;
        }
        ci() {
            this.cd = NaN;
        }
    }
    CalloutLayerView.$t = /*@__PURE__*/ 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.ag(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.cs(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 = /*@__PURE__*/ markType(CalloutView, 'CalloutView');
    return CalloutView;
})();
