/*
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 * as tslib_1 from "tslib";
import { AnnotationLayer } from "./AnnotationLayer";
import { DependencyProperty } from "igniteui-react-core";
import { Base, String_$type, typeCast, enumGetBox, fromEnum, runOn, delegateCombine, delegateRemove, Point_$type, Date_$type, markType, markDep } from "igniteui-react-core";
import { Series } from "./Series";
import { Brush } from "igniteui-react-core";
import { Thickness } from "igniteui-react-core";
import { CalloutCollisionMode_$type } from "./CalloutCollisionMode";
import { FontUtil } from "igniteui-react-core";
import { Rect } from "igniteui-react-core";
import { CalloutLayerFrame } from "./CalloutLayerFrame";
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 { CalloutLabelUpdatingEventArgs } from "./CalloutLabelUpdatingEventArgs";
import { CalloutSeriesSelectingEventArgs } from "./CalloutSeriesSelectingEventArgs";
import { CalloutStyleUpdatingEventArgs } from "./CalloutStyleUpdatingEventArgs";
import { QuadTreeBoundingBox } from "igniteui-react-core";
import { LabelCollisionInfo } from "igniteui-react-core";
import { ScalerParams } from "./ScalerParams";
import { ViewportUtils } from "./ViewportUtils";
import { Size } from "igniteui-react-core";
import { CalloutContentUpdatingEventArgs } from "./CalloutContentUpdatingEventArgs";
import { CalloutKey } from "./CalloutKey";
import { DataContext } from "igniteui-react-core";
import { HashPool$2 } from "igniteui-react-core";
import { PropertyMetadata } from "igniteui-react-core";
import { isNaN_ } from "igniteui-react-core";
import { stringIsNullOrEmpty } from "igniteui-react-core";
import { FastItemObjectColumn } from "igniteui-react-core";
import { AnnotationLayerView } from "./AnnotationLayerView";
import { BrushUtil } from "igniteui-react-core";
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
 */
var CalloutLayer = /** @class */ /*@__PURE__*/ (function (_super) {
    tslib_1.__extends(CalloutLayer, _super);
    function CalloutLayer() {
        var _this = _super.call(this) || this;
        _this.calloutStyleUpdating = null;
        _this.po = null;
        _this.pp = null;
        _this.pq = null;
        _this.pn = null;
        _this.pm = null;
        _this.qd = new HashSet$1(CalloutAnnotationWrapper.$, 0);
        _this.qg = new List$1(CalloutAnnotationWrapper.$, 0);
        _this.qh = new List$1(CalloutAnnotationWrapper.$, 0);
        _this.pk = null;
        _this.qe = new LinkedList$1(CalloutAnnotationWrapper.$);
        _this.qb = new Dictionary$2(CalloutAnnotationWrapper.$, LinkedListNode$1.$.specialize(CalloutAnnotationWrapper.$), 0);
        _this.pw = null;
        _this.s9 = new Rect(0, 0, 0, 1, 1);
        _this.p3 = false;
        _this.qr = 0;
        _this.s8 = Rect.empty;
        _this.p1 = false;
        _this.p2 = false;
        _this.calloutContentUpdating = null;
        _this.calloutLabelUpdating = null;
        _this.calloutSeriesSelecting = null;
        _this.qf = new List$1(SeriesPointOfInterest.$, 0);
        _this.p5 = false;
        _this.p6 = false;
        _this.qj = 0;
        _this.p4 = false;
        _this.p0 = true;
        FastItemObjectColumn.m();
        _this.oj = true;
        var a = new CalloutLayerFrame();
        var b = new CalloutLayerFrame();
        var c = new CalloutLayerFrame();
        var d = _this.gj / 1000;
        _this.ob = a;
        _this.oa = b;
        _this.oc = c;
        _this.ab = CalloutLayer.$;
        return _this;
    }
    CalloutLayer.prototype.r0 = function (a, b) {
        this.qh.clear();
        this.k3(false);
    };
    CalloutLayer.prototype.jo = function (a, b, c, d) {
        _super.prototype.jo.call(this, a, b, c, d);
        var e = this.qc();
        switch (a) {
            case 3:
                this.sc(b, e);
                break;
            case 1:
                for (var f = b; f < b + c; f++) {
                    var g = new CalloutAnnotation();
                    var h = new CalloutAnnotationWrapper();
                    h.b = g;
                    h.b.series = this.pj;
                    this.qh.insert(f, h);
                    this.sc(f, e);
                }
                break;
            case 0:
                this.qh.v(b, c);
                break;
            case 2:
                for (var i = b; i < b + c; i++) {
                    this.sc(i, e);
                }
                break;
            case 4:
                this.qh.clear();
                for (var j = 0; j < this.cd.count; j++) {
                    var k = new CalloutAnnotation();
                    var l = new CalloutAnnotationWrapper();
                    l.b = k;
                    l.b.series = this.pj;
                    this.qh.add(l);
                    this.sc(j, e);
                }
                break;
        }
        this.k3(true);
    };
    CalloutLayer.prototype.dr = function (a) {
        return false;
    };
    CalloutLayer.prototype.qc = function () {
        var a = new Dictionary$2(String_$type, Series.$, 0);
        if (this.b6 != null) {
            for (var b = 0; b < this.b6.series.count; b++) {
                var c = this.b6.series._inner[b];
                if (c.name != null && !a.containsKey(c.name)) {
                    a.addItem(c.name, c);
                }
            }
        }
        return a;
    };
    CalloutLayer.prototype.sc = function (a, b) {
        var _this = this;
        if (this.pv == null || this.pt == null) {
            return;
        }
        var c = a;
        if (this.pu != null) {
            c = this.pu.item(a);
        }
        var d = this.pv.item(a);
        var e = this.pt.item(a);
        var f = this.qh._inner[a];
        if (this.ps != null) {
            if (f.b.aa != this.ps.item(a)) {
                f.b.key = this.ps.item(a);
            }
        }
        if (this.qb.containsKey(f)) {
            f.b = this.qb.item(f).c.b;
        }
        f.b.xValue = c;
        f.b.yValue = d;
        if (this.calloutLabelUpdating != null) {
            var g = ((function () {
                var $ret = new CalloutLabelUpdatingEventArgs();
                $ret.c = c;
                $ret.d = d;
                $ret.item = _this.cd.item(a);
                return $ret;
            })());
            this.calloutLabelUpdating(this, g);
            if (g.b != null && !Base.equalsStatic(g.b, f.b.am)) {
                var h = g.b;
                f.b.text = h != null ? h.toString() : "";
            }
        }
        else {
            f.b.text = e != null ? e.toString() : "";
        }
        if (this.pr != null) {
            f.b.content = this.pr.item(a);
        }
        else {
            f.b.content = this.cd.item(a);
        }
        if (this.calloutSeriesSelecting != null) {
            var i = ((function () {
                var $ret = new CalloutSeriesSelectingEventArgs();
                $ret.c = c;
                $ret.d = d;
                $ret.item = _this.cd.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.sd(f);
    };
    CalloutLayer.prototype.sd = function (a) {
        var b = new Thickness(0, 3);
        if (isNaN_(this.tb.c) || isNaN_(this.tb.e) || isNaN_(this.tb.d) || isNaN_(this.tb.b)) {
            b = new Thickness(0, 3);
        }
        else {
            b = this.tb;
        }
        var c = this.s4 != null ? this.s4 : this.pg.ci(a.b.l);
        var d = this.s7 != null ? this.s7 : this.pg.cl();
        var e = this.s6 != null ? this.s6 : this.pg.ck();
        var f = this.s5 != null ? this.s5 : this.pg.cj(a.b.l);
        var g = isNaN_(this.qp) ? 0 : this.qp;
        if (this.p9 && this.calloutStyleUpdating != null) {
            var h = new CalloutStyleUpdatingEventArgs();
            h.item = a.b.z;
            h.xValue = a.b.ab;
            h.yValue = a.b.ac;
            h.series = a.b.l;
            h.background = c;
            h.textColor = d;
            h.outline = e;
            h.leaderBrush = f;
            h.strokeThickness = g;
            this.calloutStyleUpdating(this, h);
            c = h.background;
            d = h.textColor;
            e = h.outline;
            f = h.leaderBrush;
            g = h.strokeThickness;
        }
        a.b.backgroundPadding = b;
        a.b.background = c;
        a.b.textColor = d;
        a.b.outline = e;
        a.b.leaderBrush = f;
        a.b.strokeThickness = g;
    };
    CalloutLayer.prototype.gt = function (a, b) {
        var c = this.ic(b);
        if (c == CalloutLayer.$$p[19]) {
            return this.gu(a, b, this.rm);
        }
        if (c == CalloutLayer.$$p[24]) {
            return this.gu(a, b, this.rv);
        }
        if (c == CalloutLayer.$$p[25]) {
            return this.gu(a, b, this.ry);
        }
        if (c == CalloutLayer.$$p[18]) {
            return this.gu(a, b, this.rj);
        }
        if (c == CalloutLayer.$$p[14]) {
            return this.gu(a, b, this.rd);
        }
        return _super.prototype.gt.call(this, a, b);
    };
    Object.defineProperty(CalloutLayer.prototype, "pt", {
        get: function () {
            return this.po;
        },
        set: function (a) {
            if (this.po != a) {
                var b = this.po;
                this.po = a;
                this.raisePropertyChanged("LabelColumn", b, this.po);
            }
        },
        enumerable: true,
        configurable: true
    });
    Object.defineProperty(CalloutLayer.prototype, "pu", {
        get: function () {
            return this.pp;
        },
        set: function (a) {
            if (this.pp != a) {
                var b = this.pp;
                this.pp = a;
                this.raisePropertyChanged("XColumn", b, this.pp);
            }
        },
        enumerable: true,
        configurable: true
    });
    Object.defineProperty(CalloutLayer.prototype, "pv", {
        get: function () {
            return this.pq;
        },
        set: function (a) {
            if (this.pq != a) {
                var b = this.pq;
                this.pq = a;
                this.raisePropertyChanged("YColumn", b, this.pq);
            }
        },
        enumerable: true,
        configurable: true
    });
    Object.defineProperty(CalloutLayer.prototype, "ps", {
        get: function () {
            return this.pn;
        },
        set: function (a) {
            if (this.pn != a) {
                var b = this.pn;
                this.pn = a;
                this.raisePropertyChanged("KeyColumn", b, this.pn);
            }
        },
        enumerable: true,
        configurable: true
    });
    Object.defineProperty(CalloutLayer.prototype, "pr", {
        get: function () {
            return this.pm;
        },
        set: function (a) {
            if (this.pm != a) {
                var b = this.pm;
                this.pm = a;
                this.raisePropertyChanged("ContentColumn", b, this.pm);
            }
        },
        enumerable: true,
        configurable: true
    });
    CalloutLayer.prototype.r2 = function (a, b) {
        if (b.propertyName == CalloutAnnotation.$$p[13] || b.propertyName == CalloutAnnotation.$$p[14]) {
            var c = a.k;
            if (!this.qd.contains(c)) {
                this.qd.add_1(c);
                this.qg.add(c);
                this.k3(false);
            }
        }
    };
    CalloutLayer.prototype.bp = function () {
        return new CalloutLayerView(this);
    };
    CalloutLayer.prototype.kk = function (a) {
        _super.prototype.kk.call(this, a);
        this.pg = a;
    };
    Object.defineProperty(CalloutLayer.prototype, "tb", {
        get: function () {
            return new Thickness(1, this.ql, this.qn, this.qm, this.qk);
        },
        enumerable: true,
        configurable: true
    });
    Object.defineProperty(CalloutLayer.prototype, "pl", {
        get: function () {
            if (this.pk == null) {
                this.pk = FontUtil.toFontInfo(this.f5, this.rr);
            }
            return this.pk;
        },
        enumerable: true,
        configurable: true
    });
    CalloutLayer.prototype.ou = function (a, b) {
        if (this.pj == null || this.pj == a) {
            if (!this.ar.c) {
                this.k3(b);
            }
        }
    };
    CalloutLayer.prototype.ow = function (a, b) {
        var e_1, _a;
        _super.prototype.ow.call(this, a, b);
        var c = a;
        c.p.clear();
        c.q.clear();
        c.m.clear();
        c.f.clear();
        c.h.clear();
        c.g.clear();
        c.j.clear();
        c.l.clear();
        c.k.clear();
        c.i.clear();
        c.n.clear();
        c.o.clear();
        c.t.clear();
        c.u.clear();
        c.r.clear();
        c.s.clear();
        var d = this.qi();
        var e = new List$1(CalloutAnnotationWrapper.$, 0);
        if (this.p7) {
            if (this.oh(this.pj)) {
                this.r9(this.pj, c, e);
            }
            else {
                try {
                    for (var _b = tslib_1.__values(fromEnum(this.b6.series)), _c = _b.next(); !_c.done; _c = _b.next()) {
                        var f = _c.value;
                        if (this.oh(f)) {
                            this.r9(f, c, e);
                        }
                    }
                }
                catch (e_1_1) {
                    e_1 = { error: e_1_1 };
                }
                finally {
                    try {
                        if (_c && !_c.done && (_a = _b.return))
                            _a.call(_b);
                    }
                    finally {
                        if (e_1)
                            throw e_1.error;
                    }
                }
            }
        }
        this.r8(c, d, e);
    };
    CalloutLayer.prototype.lo = function (a, b) {
        _super.prototype.lo.call(this, a, b);
        var c = b.width - this.s9.width;
        var d = b.height - this.s9.height;
        var e = 0;
        if (Math.abs(c) > Math.abs(d)) {
            e = c;
            this.qj = c * this.n6.width;
        }
        else {
            e = d;
            this.qj = d * this.n6.height;
        }
        if (e > 0 && this.qj > 5) {
            this.p6 = true;
        }
        if (e < 0 && this.qj > 5) {
            this.p5 = true;
        }
    };
    CalloutLayer.prototype.ln = function (a, b) {
        _super.prototype.ln.call(this, a, b);
        if (!a.equals1(b)) {
            this.p4 = true;
        }
    };
    Object.defineProperty(CalloutLayer.prototype, "ta", {
        get: function () {
            return this.s8;
        },
        set: function (a) {
            this.s8 = a;
        },
        enumerable: true,
        configurable: true
    });
    CalloutLayer.prototype.r8 = function (a, b, c) {
        var e_2, _a;
        if (this.b6 != null) {
            this.s9 = this.b6.os;
        }
        if (this.n6.isEmpty) {
            return;
        }
        this.ta = new Rect(0, this.n6.left, this.n6.top, this.n6.width, this.n6.height);
        if (this.pw != null && this.ra != null && this.ra != this.pw.ak) {
            this.r4();
        }
        if (this.pw == null) {
            var d = this.px();
            if (d != null) {
                this.pw = d;
                var e = this.pw;
                e.labelsMoved = delegateCombine(e.labelsMoved, runOn(this, this.r1));
            }
            else {
                var f = this.ny(this.bs);
                var g = 0;
                if (this.pj != null) {
                    if (this.pj.isVertical) {
                        g = 2;
                    }
                }
                else {
                    var h = false;
                    if (this.b6 != null && this.b6.series.count > 0) {
                        h = true;
                        try {
                            for (var _b = tslib_1.__values(fromEnum(this.b6.series)), _c = _b.next(); !_c.done; _c = _b.next()) {
                                var i = _c.value;
                                if (!i.cx) {
                                    if (!i.isVertical) {
                                        h = false;
                                    }
                                }
                            }
                        }
                        catch (e_2_1) {
                            e_2 = { error: e_2_1 };
                        }
                        finally {
                            try {
                                if (_c && !_c.done && (_a = _b.return))
                                    _a.call(_b);
                            }
                            finally {
                                if (e_2)
                                    throw e_2.error;
                            }
                        }
                    }
                    if (h) {
                        g = 2;
                    }
                }
                this.pw = new LabelCollisionManager(this.n6.right, this.n6.bottom, this.n6, this.pg.j(), this.qo, this.py(), g, this.qv(), this.qu(), this.p8);
                if (this.ra != null) {
                    this.pw.ak = this.ra;
                    this.pw.ai = this;
                }
                var j = this.pw;
                j.labelsMoved = delegateCombine(j.labelsMoved, runOn(this, this.r1));
            }
        }
        if (this.p5) {
            this.p5 = false;
            if (this.pw.ag > 2) {
                this.p3 = true;
            }
        }
        if (this.p6) {
            this.p6 = false;
            if (this.qj > 5) {
                this.p3 = true;
            }
        }
        if (this.p4) {
            this.p4 = false;
            this.pw.ay(this.n6.right, this.n6.bottom, this.n6);
            this.p3 = true;
        }
        var k = new HashSet$1(CalloutAnnotationWrapper.$, 0);
        var l = new HashSet$1(CalloutAnnotationWrapper.$, 0);
        var m = new List$1(CalloutAnnotationWrapper.$, 0);
        var n = new List$1(CalloutAnnotationWrapper.$, 0);
        var o = new HashSet$1(CalloutAnnotationWrapper.$, 0);
        for (var p = 0; p < b.count; p++) {
            o.add_1(b._inner[p]);
        }
        for (var q = 0; q < c.count; q++) {
            o.add_1(c._inner[q]);
        }
        var r = this.qe.c;
        while (r != null) {
            var s = r.a;
            if (!o.contains(r.c)) {
                n.add(r.c);
                l.add_1(r.c);
                var t = r.c.b;
                t.propertyChanged = delegateRemove(t.propertyChanged, runOn(this, this.r2));
                this.qe.h(r);
                this.qb.removeItem(r.c);
                this.pw.ax(r.c.c);
            }
            r = s;
        }
        for (var u = 0; u < b.count; u++) {
            if (!this.qb.containsKey(b._inner[u])) {
                this.qe.f(b._inner[u]);
                var v = b._inner[u].b;
                v.propertyChanged = delegateCombine(v.propertyChanged, runOn(this, this.r2));
                this.qb.addItem(b._inner[u], this.qe.d);
                m.add(b._inner[u]);
                k.add_1(b._inner[u]);
                this.p3 = true;
            }
        }
        for (var w = 0; w < c.count; w++) {
            if (!this.qb.containsKey(c._inner[w])) {
                this.qe.f(c._inner[w]);
                this.qb.addItem(c._inner[w], this.qe.d);
                var x = c._inner[w].b;
                x.propertyChanged = delegateCombine(x.propertyChanged, runOn(this, this.r2));
                m.add(c._inner[w]);
                k.add_1(c._inner[w]);
                this.p3 = true;
            }
        }
        if (this.p1 == true) {
            this.p1 = false;
            this.p3 = true;
        }
        if (this.qg.count > 0) {
            this.p3 = true;
            this.qg.clear();
            this.qd.clear();
        }
        r = this.qe.c;
        while (r != null) {
            var y = this.pz(r.c);
            if (y == null) {
                return;
            }
            if (!Base.equalsStatic(y, r.c.c.c)) {
                var z = false;
                if (r.c.c.c == null) {
                    z = true;
                }
                var aa = r.c.c;
                aa.o = y.b;
                aa.p = y.c;
                if (!isNaN_(aa.o) && !isNaN_(aa.p)) {
                    aa.n = y.e;
                    aa.m = y.d;
                    if (aa.b == null) {
                        this.pw.p(aa);
                    }
                    if (z) {
                        this.pw.al(aa);
                    }
                    else {
                        this.pw.au(aa);
                    }
                }
            }
            r = r.a;
        }
        var ab = this.pw.ah();
        var ac = this.pw.q();
        if (this.p3 && (ab != 0 || ac)) {
            this.p3 = false;
            this.qr = 0x7FFFFFFF;
            if (this.ra != null) {
                var ad = true;
                for (var ae = 0; ae < this.b6.series.count; ae++) {
                    var af = this.b6.series._inner[ae];
                    if (af.cx && typeCast(CalloutLayer.$, af) !== null) {
                        var ag = af;
                        if (ag.ra == this.ra) {
                            if (!ag.ta.equals1(this.pw.a0)) {
                                ad = false;
                                break;
                            }
                        }
                    }
                }
                if (ad) {
                    this.pw.az();
                }
                else {
                    this.pw.am();
                    this.pw.an();
                }
            }
            else {
                this.pw.az();
            }
        }
        else {
            this.pw.an();
        }
        var ah = this.qe.c;
        while (ah != null) {
            var ai = ah.c;
            a.m.add1(ai);
            a.f.add(ai.b.bh);
            a.h.add(ai.b.bj);
            a.g.add(ai.b.bi);
            a.j.add(ai.b.backgroundPadding.c);
            a.l.add(ai.b.backgroundPadding.e);
            a.k.add(ai.b.backgroundPadding.d);
            a.i.add(ai.b.backgroundPadding.b);
            a.n.add(ai.b.x);
            a.o.add(ai.b.bk);
            a.p.add1(ai.b.am);
            a.q.add1(ai.b.z);
            var aj = ai.c;
            a.t.add(ai.c.o - (ai.c.g - ai.c.l));
            a.u.add(ai.c.p - (ai.c.h - ai.c.k));
            a.r.add(ai.c.g - ai.c.l);
            a.s.add(ai.c.h - ai.c.k);
            ah = ah.a;
        }
    };
    CalloutLayer.prototype.r4 = function () {
        if (this.pw != null) {
            var a = this.qe.c;
            while (a != null) {
                var b = a.c.c;
                if (b != null) {
                    this.pw.ax(b);
                }
                a = a.a;
            }
            var c = this.pw;
            c.labelsMoved = delegateRemove(c.labelsMoved, runOn(this, this.r1));
            this.pw = null;
        }
        this.r3();
    };
    CalloutLayer.prototype.px = function () {
        if (this.b6 == null) {
            return null;
        }
        for (var a = 0; a < this.b6.series.count; a++) {
            var b = this.b6.series._inner[a];
            if (b.cx && typeCast(CalloutLayer.$, b) !== null) {
                var c = b;
                if (c != this) {
                    if (c.ra != null && c.ra == this.ra) {
                        if (c.pw != null) {
                            return c.pw;
                        }
                    }
                }
            }
        }
        return null;
    };
    CalloutLayer.prototype.qu = function () {
        return 20000;
    };
    CalloutLayer.prototype.qv = function () {
        return 300;
    };
    CalloutLayer.prototype.py = function () {
        switch (this.pd) {
            case 0: return 2;
            case 2: return 1;
            case 3: return 2;
            case 1: return 0;
        }
        return 2;
    };
    CalloutLayer.prototype.r1 = function (a) {
        var b = this.pw.ah();
        if (b < this.qr) {
            this.qr = b;
            this.k3(false);
        }
    };
    CalloutLayer.prototype.pz = function (a) {
        var b = this.pj;
        if (a.b.l != null) {
            b = a.b.l;
        }
        if (b == null) {
            for (var c = 0; c < this.b6.series.count; c++) {
                var d = this.b6.series._inner[c];
                if (!d.cx) {
                    b = d;
                    break;
                }
            }
        }
        if (b == null) {
            return null;
        }
        var e = b.ag();
        var f = b.fa();
        var g = null;
        var h = null;
        var i = false;
        for (var j = 0; j < e.length; j++) {
            if (e[j].b2) {
                i = true;
                g = e[j];
            }
            else if (e[j].ce) {
                i = true;
                h = e[j];
            }
            else if (e[j].ch) {
                h = e[j];
            }
            else {
                g = e[j];
            }
        }
        if (g == null || h == null) {
            return null;
        }
        if (!g.cg() || !h.cg()) {
            return null;
        }
        var k = 0;
        var l = 0;
        if (g.b4 && g.categoryMode != 0) {
            if (b.c6) {
                k = b.getOffsetValue();
            }
            else if (b.cz) {
                k = b.getOffsetValue();
            }
        }
        if (h.b4 && h.categoryMode != 0) {
            if (b.cz) {
                l = b.getOffsetValue();
            }
        }
        var m = new ScalerParams(0, this.b6.os, g.ja, g.ca, g.i5());
        m.b = f;
        var n = new ScalerParams(0, this.b6.os, h.ja, h.ca, h.i5());
        n.b = f;
        var o = 0;
        var p = 0;
        if (i) {
            o = g.dz(this.qq(a.b.ab), m) + k;
            p = h.dz(this.qq(a.b.ac), n) + l;
            var q = o;
            var r = p;
            var s = { $type: Point_$type, x: 0.5, y: 0.5 };
            var t = s.x + (r * Math.cos(q));
            o = ViewportUtils.c(t, m.e, m.d);
            var u = s.y + (r * Math.sin(q));
            p = ViewportUtils.f(u, n.e, n.d);
        }
        else {
            o = g.dz(this.qq(a.b.ab), m) + k;
            p = h.dz(this.qq(a.b.ac), n) + l;
        }
        var v = new QuadTreeBoundingBox();
        v.b = o;
        v.c = p;
        v.e = 3;
        v.d = 3;
        v.g = a.b;
        return v;
    };
    CalloutLayer.prototype.qq = function (a) {
        if (typeCast(Date_$type, a) !== null) {
            return a.getTime();
        }
        if (a == null) {
            return 0;
        }
        return a;
    };
    CalloutLayer.prototype.qi = function () {
        var a = new List$1(CalloutAnnotationWrapper.$, 0);
        for (var b = 0; b < this.qh.count; b++) {
            if (stringIsNullOrEmpty(this.qh._inner[b].b.am)) {
                continue;
            }
            if (this.qh._inner[b].c == null) {
                var c = new LabelCollisionInfo();
                this.qh._inner[b].c = c;
                var d = this.pg.cn(this.qw(this.qh._inner[b]), this.qh._inner[b].b.backgroundPadding);
                c.k = d.height / 2;
                c.l = d.width / 2;
            }
            var e = this.pz(this.qh._inner[b]);
            if (e == null || e.b < this.n6.left || e.b > this.n6.right || e.c < this.n6.top || e.c > this.n6.bottom) {
                continue;
            }
            a.add(this.qh._inner[b]);
        }
        return a;
    };
    CalloutLayer.prototype.qw = function (a) {
        return a.b.am;
    };
    CalloutLayer.prototype.oh = function (a) {
        if (!_super.prototype.oh.call(this, a)) {
            return false;
        }
        if (this.ro != null) {
            if (a.c7) {
                var b = a.ib();
                if (!Base.equalsStatic(this.ro, b)) {
                    return false;
                }
            }
            else {
                if (!Base.equalsStatic(this.ro, a.name)) {
                    return false;
                }
            }
        }
        return true;
    };
    CalloutLayer.prototype.kd = function () {
        _super.prototype.kd.call(this);
        if (!this.ar.c && !this.cn()) {
            return;
        }
        if (this.p0) {
            this.p0 = false;
            this.r6();
        }
        if (this.cn()) {
            this.sb(this.oc, false);
        }
        else {
            this.sb(this.oa, false);
        }
    };
    CalloutLayer.prototype.r7 = function () {
        if (!this.p2) {
            this.p2 = true;
            this.k3(true);
        }
    };
    CalloutLayer.prototype.r9 = function (a, b, c) {
        var d = false;
        if (this.p2) {
            this.p2 = false;
            d = true;
        }
        if (a.ct(this.qf, this.qa, this.qs)) {
            var e = this.qf;
            var _loop_1 = function (f) {
                var g = e._inner[f];
                var h = g.a.item != null ? g.a.item : g.a;
                var i = a;
                var j = new CalloutKey(h, i);
                var k = new CalloutAnnotationWrapper();
                var l = new CalloutAnnotation();
                k.b = l;
                l.key = j;
                var m = false;
                if (this_1.qb.containsKey(k)) {
                    k = this_1.qb.item(k).c;
                    l = k.b;
                    m = d;
                }
                else {
                    m = true;
                }
                var n = l.ab;
                var o = l.ac;
                if (this_1.qq(n) != this_1.qq(g.b)) {
                    l.xValue = g.b;
                }
                if (this_1.qq(o) != this_1.qq(g.c)) {
                    l.yValue = g.c;
                }
                l.series = a;
                var p = false;
                if (g.d != l.aw) {
                    l.aw = g.d;
                    p = true;
                }
                if (m || p) {
                    if (this_1.calloutLabelUpdating != null) {
                        var q = ((function () {
                            var $ret = new CalloutLabelUpdatingEventArgs();
                            $ret.c = l.ab;
                            $ret.d = l.ac;
                            $ret.item = h;
                            return $ret;
                        })());
                        this_1.calloutLabelUpdating(this_1, q);
                        if (q.b != null && !Base.equalsStatic(q.b, k.b.am)) {
                            var r = q.b;
                            k.b.text = r != null ? r.toString() : "";
                        }
                    }
                    else {
                        if (g.d != null) {
                            l.text = g.d;
                        }
                    }
                }
                if (l.am == null) {
                    return "continue";
                }
                if (m || p) {
                    if (this_1.calloutContentUpdating != null) {
                        var s = ((function () {
                            var $ret = new CalloutContentUpdatingEventArgs();
                            $ret.c = l.ab;
                            $ret.d = l.ac;
                            $ret.item = h;
                            $ret.a = h;
                            return $ret;
                        })());
                        this_1.calloutContentUpdating(this_1, s);
                        if (s.a != null && s.a != k.b.z) {
                            k.b.content = s.a;
                        }
                    }
                    else {
                        if (h != null && h != k.b.z) {
                            k.b.content = h;
                        }
                    }
                }
                if (m) {
                    this_1.sd(k);
                }
                if (k.c == null) {
                    var t = new LabelCollisionInfo();
                    k.c = t;
                    var u = this_1.pg.cn(this_1.qw(k), k.b.backgroundPadding);
                    t.k = u.height / 2;
                    t.l = u.width / 2;
                }
                var v = this_1.pz(k);
                if (v == null || v.b < this_1.n6.left || v.b > this_1.n6.right || v.c < this_1.n6.top || v.c > this_1.n6.bottom) {
                    return "continue";
                }
                c.add(k);
            };
            var this_1 = this;
            for (var f = 0; f < this.qf.count; f++) {
                _loop_1(f);
            }
        }
    };
    CalloutLayer.prototype.bj = function () {
        return 1;
    };
    CalloutLayer.prototype.as = function (a, b) {
        var c = this.pw.d(a, b);
        if (c == null) {
            return null;
        }
        return c.u;
    };
    CalloutLayer.prototype.dy = function (a, b) {
        if (this.pw == null) {
            return false;
        }
        return this.pw.d(a, b) != null;
    };
    CalloutLayer.prototype.sb = function (a, b) {
        var e_3, _a;
        var c = 0;
        var d = new HashSet$1(CalloutAnnotationWrapper.$, 0);
        for (c = 0; c < a.p.count; c++) {
            var e = a.m._inner[c];
            if (isNaN_(a.t._inner[c]) || isNaN_(a.u._inner[c])) {
                continue;
            }
            var f = this.pg.b8.item(e);
            d.add_1(e);
            if (f.f != a.p._inner[c]) {
                f.f = a.p._inner[c];
                var g = f.s();
            }
            f.c = a.n._inner[c];
            f.k = a.f._inner[c];
            f.n = a.o._inner[c];
            f.m = f.c > 0 ? a.h._inner[c] : this.bs.bq();
            f.l = a.g._inner[c];
            f.v = new Thickness(1, a.j._inner[c], a.l._inner[c], a.k._inner[c], a.i._inner[c]);
            this.pg.cg(f, Math.min(a.r._inner[c], a.r._inner[c] + a.t._inner[c]), Math.min(a.s._inner[c], a.s._inner[c] + a.u._inner[c]));
            this.pg.ch(f, e, a.q._inner[c]);
            f.p = { $type: Point_$type, x: a.t._inner[c], y: a.u._inner[c] };
        }
        var h = new List$1(CalloutAnnotationWrapper.$, 0);
        try {
            for (var _b = tslib_1.__values(fromEnum(this.pg.b8.c)), _c = _b.next(); !_c.done; _c = _b.next()) {
                var i = _c.value;
                if (!d.contains(i)) {
                    h.add(i);
                }
            }
        }
        catch (e_3_1) {
            e_3 = { error: e_3_1 };
        }
        finally {
            try {
                if (_c && !_c.done && (_a = _b.return))
                    _a.call(_b);
            }
            finally {
                if (e_3)
                    throw e_3.error;
            }
        }
        for (var j = 0; j < h.count; j++) {
            this.pg.b8.h(h._inner[j]);
        }
    };
    CalloutLayer.prototype.oz = function (a, b) {
        _super.prototype.oz.call(this, a, b);
        if (this.cn()) {
            this.sb(this.oc, true);
        }
        else {
            this.sb(this.oa, false);
        }
    };
    CalloutLayer.prototype.dp = function () {
        return true;
    };
    CalloutLayer.prototype.kp = function (a, b, c, d) {
        _super.prototype.kp.call(this, a, b, c, d);
        switch (b) {
            case CalloutLayer.$$p[22]:
                this.pk = null;
                this.pg.cf();
                this.k3(true);
                break;
            case CalloutLayer.$$p[20]:
            case CalloutLayer.$$p[21]:
                this.k3(true);
                break;
            case CalloutLayer.$$p[13]:
                this.k3(true);
                break;
            case "SeriesViewer":
                if (c != null) {
                    var e = c;
                    e.seriesAnimating = delegateRemove(e.seriesAnimating, runOn(this, this.sa));
                }
                if (d != null) {
                    var f = d;
                    f.seriesAnimating = delegateCombine(f.seriesAnimating, runOn(this, this.sa));
                }
                if (d == null) {
                    this.r4();
                }
                break;
            case CalloutLayer.$$p[15]:
            case CalloutLayer.$$p[16]:
            case CalloutLayer.$$p[1]:
            case CalloutLayer.$$p[5]:
            case CalloutLayer.$$p[4]:
            case CalloutLayer.$$p[7]:
            case CalloutLayer.$$p[9]:
            case CalloutLayer.$$p[8]:
            case CalloutLayer.$$p[6]:
            case CalloutLayer.$$p[11]:
            case CalloutLayer.$$p[12]:
                this.r5();
                break;
            case CalloutLayer.$$p[19]:
                if (this.cd != null) {
                    this.cd.deregisterColumn(this.pt);
                    this.pt = this.cc(this.rm);
                }
                break;
            case "LabelColumn":
                this.r5();
                break;
            case CalloutLayer.$$p[14]:
                if (this.cd != null) {
                    this.cd.deregisterColumn(this.pr);
                    this.pr = this.cc(this.rd);
                }
                break;
            case "ContentColumn":
                this.r5();
                break;
            case CalloutLayer.$$p[24]:
                if (this.cd != null) {
                    this.cd.deregisterColumn(this.pu);
                    this.pu = stringIsNullOrEmpty(this.rv) == false ? this.cc(this.rv) : null;
                }
                break;
            case "XColumn":
                this.r5();
                break;
            case CalloutLayer.$$p[25]:
                if (this.cd != null) {
                    this.cd.deregisterColumn(this.pv);
                    this.pv = this.cc(this.ry);
                }
                break;
            case "YColumn":
                this.r5();
                break;
            case CalloutLayer.$$p[18]:
                if (this.cd != null) {
                    this.cd.deregisterColumn(this.ps);
                    this.ps = this.cc(this.rj);
                }
                break;
            case "KeyColumn":
                this.r5();
                break;
            case "FastItemsSource":
                this.p1 = true;
                if (typeCast(IFastItemsSource_$type, c) != null) {
                    c.deregisterColumn(this.pt);
                    c.deregisterColumn(this.pr);
                    c.deregisterColumn(this.pu);
                    c.deregisterColumn(this.pv);
                    c.deregisterColumn(this.ps);
                    this.pt = null;
                    this.pr = null;
                    this.pu = null;
                    this.pv = null;
                    this.ps = null;
                    this.qh.clear();
                }
                if (typeCast(IFastItemsSource_$type, d) != null) {
                    this.pt = this.cc(this.rm);
                    this.pr = this.cc(this.rd);
                    if (stringIsNullOrEmpty(this.rv) == false) {
                        this.pu = this.cc(this.rv);
                    }
                    this.pv = this.cc(this.ry);
                    this.ps = this.cc(this.rj);
                }
                this.r5();
                break;
        }
    };
    CalloutLayer.prototype.sa = function (a) {
        if (a.cx) {
            return;
        }
        if ((a == this.pj || this.pj == null) && this.p7) {
            this.k3(false);
        }
    };
    CalloutLayer.prototype.r5 = function () {
        if (this.p0 == false) {
            this.p0 = true;
            this.k3(false);
        }
    };
    CalloutLayer.prototype.r3 = function () {
        this.pg.b8.clear();
        this.qe.g();
        this.qb.clear();
    };
    CalloutLayer.prototype.r6 = function () {
        if (this.pv == null || this.pt == null) {
            var a = this.qe.c;
            while (a != null) {
                this.sd(a.c);
                a = a.a;
            }
            return;
        }
        var b = this.qc();
        for (var c = 0; c < this.pv.count; c++) {
            var d = void 0;
            if (this.qh.count <= c) {
                var e = new CalloutAnnotation();
                d = new CalloutAnnotationWrapper();
                d.b = e;
                d.b.series = this.pj;
                this.qh.add(d);
            }
            else {
                d = this.qh._inner[c];
            }
            this.sc(c, b);
        }
    };
    CalloutLayer.$t = markType(CalloutLayer, 'CalloutLayer', AnnotationLayer.$);
    CalloutLayer.$$p = markDep(DependencyProperty, PropertyMetadata, CalloutLayer, 'raisePropertyChanged', ['AutoCalloutLabelPrecision:qs:se', [1, 5], 'CalloutBackground:s4:sf', [Brush.$, null], 'CalloutCollisionMode:pd:sg', [CalloutCollisionMode_$type, enumGetBox(CalloutCollisionMode_$type, 3)], 'CalloutInterpolatedValuePrecision:qt:sh', [1, -1], 'CalloutLeaderBrush:s5:si', [Brush.$, null], 'CalloutOutline:s6:sj', [Brush.$, null], 'CalloutPaddingBottom:qk:sk', [1, NaN], 'CalloutPaddingLeft:ql:sl', [1, NaN], 'CalloutPaddingRight:qm:sm', [1, NaN], 'CalloutPaddingTop:qn:sn', [1, NaN], 'CalloutPositionPadding:qo:so', [1, 10], 'CalloutStrokeThickness:qp:sp', [1, NaN], 'CalloutTextColor:s7:sq', [Brush.$, null], 'CollisionChannel:ra:sr', [2, null], 'ContentMemberPath:rd:ss', [2, null], 'IsAutoCalloutBehaviorEnabled:p7:st', [0, false], 'IsCalloutOffsettingEnabled:p8:su', [0, true], 'IsCustomCalloutStyleEnabled:p9:sv', [0, false], 'KeyMemberPath:rj:sw', [2, null], 'LabelMemberPath:rm:sx', [2, null], 'TargetSeriesName:ro:sy', [2, null], 'TargetSeries:pj:sz', [Series.$, null], 'TextStyle:rr:s0', [2, null], 'UseValueForAutoCalloutLabels:qa:s1', [0, true], 'XMemberPath:rv:s2', [2, null], 'YMemberPath:ry:s3', [2, null]]);
    return CalloutLayer;
}(AnnotationLayer));
export { CalloutLayer };
/**
 * @hidden
 */
var CalloutLayerView = /** @class */ /*@__PURE__*/ (function (_super) {
    tslib_1.__extends(CalloutLayerView, _super);
    function CalloutLayerView(a) {
        var _this = _super.call(this, a) || this;
        _this.b4 = null;
        _this.b9 = null;
        _this.b8 = null;
        _this.ca = NaN;
        _this.b5 = null;
        _this.b4 = a;
        _this.b9 = new List$1(CalloutView.$, 0);
        return _this;
    }
    CalloutLayerView.prototype.as = function () {
        var _this = this;
        _super.prototype.as.call(this);
        this.b8 = ((function () {
            var $ret = new HashPool$2(CalloutAnnotationWrapper.$, CalloutView.$);
            $ret.create = runOn(_this, _this.b6);
            $ret.activate = runOn(_this, _this.cc);
            $ret.disactivate = runOn(_this, _this.ce);
            $ret.destroy = runOn(_this, _this.cd);
            return $ret;
        })());
    };
    CalloutLayerView.prototype.b6 = function () {
        var a = new CalloutView(this);
        this.b9.add(a);
        return a;
    };
    CalloutLayerView.prototype.cc = function (a) {
        a.w = 0;
    };
    CalloutLayerView.prototype.ce = function (a) {
        a.w = 1;
    };
    CalloutLayerView.prototype.cd = function (a) {
        this.b9.remove(a);
    };
    CalloutLayerView.prototype.cm = function (a) {
        if (a == null) {
            return a;
        }
        return BrushUtil.l(a, 0.1);
    };
    CalloutLayerView.prototype.a6 = function (a, b) {
        _super.prototype.a6.call(this, a, b);
        a.ac(this.b7());
        if (a.d && !b) {
            for (var c = 0; c < this.b9.count; c++) {
                var d = this.b9._inner[c];
                if (d.w == 0) {
                    d.h(a);
                }
            }
        }
    };
    CalloutLayerView.prototype.b7 = function () {
        if (this.b4.pl != null) {
            return this.b4.pl;
        }
        return this.e.b6.getFontInfo();
    };
    CalloutLayerView.prototype.al = function (a) {
        _super.prototype.al.call(this, a);
        for (var b = 0; b < this.b9.count; b++) {
            var c = this.b9._inner[b];
            if (c.w != 0) {
                continue;
            }
            c.g(this.b4, this.b7(), a);
        }
    };
    CalloutLayerView.prototype.co = function (a) {
        this.k.ac(this.b7());
        this.ca = this.cb();
        return new Size(1, this.k.f(a.ak), this.ca);
    };
    CalloutLayerView.prototype.cb = function () {
        var a = this.b7();
        if (isNaN_(this.ca)) {
            var b = FontUtil.getCurrentFontHeight(this.e.b6.b8.j.ae, a);
            this.ca = b;
        }
        return this.ca;
    };
    CalloutLayerView.prototype.cn = function (a, b) {
        if (this.b5 == null) {
            this.b5 = new CalloutView(this);
        }
        this.b5.f = a;
        this.b5.v = b;
        var c = this.b5.s();
        this.b5.f = null;
        return c;
    };
    CalloutLayerView.prototype.cg = function (a, b, c) {
        a.d = b;
        a.e = c;
    };
    CalloutLayerView.prototype.ch = function (a, b, c) {
        a.i(this.e, b, c);
    };
    CalloutLayerView.prototype.ci = function (a) {
        if (a != null) {
            return this.cm(a.nc);
        }
        return this.e.nc;
    };
    CalloutLayerView.prototype.cl = function () {
        return ((function () {
            var $ret = new Brush();
            $ret.color = Color.u(255, 255, 255, 255);
            return $ret;
        })());
    };
    CalloutLayerView.prototype.ck = function () {
        return ((function () {
            var $ret = new Brush();
            $ret.color = Color.u(255, 255, 255, 255);
            return $ret;
        })());
    };
    CalloutLayerView.prototype.cj = function (a) {
        if (a != null) {
            return this.cm(a.m9);
        }
        return this.e.m9;
    };
    CalloutLayerView.prototype.cf = function () {
        this.ca = NaN;
    };
    CalloutLayerView.$t = markType(CalloutLayerView, 'CalloutLayerView', AnnotationLayerView.$);
    return CalloutLayerView;
}(AnnotationLayerView));
export { CalloutLayerView };
/**
 * @hidden
 */
var CalloutView = /** @class */ /*@__PURE__*/ (function (_super) {
    tslib_1.__extends(CalloutView, _super);
    function CalloutView(a) {
        var _this = _super.call(this) || this;
        _this.a = null;
        _this.w = 0;
        _this.j = null;
        _this.r = null;
        _this.o = { $type: Point_$type, x: 0, y: 0 };
        _this.q = null;
        _this.u = new Thickness(0, 0);
        _this.t = null;
        _this.d = 0;
        _this.e = 0;
        _this.b = null;
        _this.q = new Line();
        _this.q.ab = false;
        _this.q._stroke = ((function () {
            var $ret = new Brush();
            $ret.color = Color.u(255, 0, 0, 0);
            return $ret;
        })());
        _this.q.ac = 2;
        _this.j = new TextBlock();
        _this.r = new Rectangle();
        _this.r.ac = 0;
        _this.a = a;
        _this.w = 0;
        return _this;
    }
    CalloutView.prototype.h = function (a) {
        a.z();
        a.af(this.d, this.e);
        var b = new TranslateTransform();
        b.j = this.t.c;
        b.k = this.t.e;
        this.r.j = b;
        a.r(this.q);
        a.z();
        this.r.width = this.j.m + this.u.c + this.u.d;
        this.r.height = this.j.l + this.u.e + this.u.b;
        a.j(this.r.j);
        a.v(this.r);
        this.j.o = this.u.e;
        this.j.n = this.u.c;
        a.w(this.j);
        a.y();
        a.y();
    };
    Object.defineProperty(CalloutView.prototype, "p", {
        get: function () {
            return this.o;
        },
        set: function (a) {
            if (this.o.x != a.x || this.o.y != a.y) {
                var b = this.s();
                var c = b.height;
                var d = b.width;
                this.o = a;
                var e = CalloutViewHelper.b(this.p, d, c, this.q);
                this.t = e;
            }
        },
        enumerable: true,
        configurable: true
    });
    Object.defineProperty(CalloutView.prototype, "n", {
        get: function () {
            return this.j.am;
        },
        set: function (a) {
            this.j.am = a;
        },
        enumerable: true,
        configurable: true
    });
    Object.defineProperty(CalloutView.prototype, "m", {
        get: function () {
            return this.r._stroke;
        },
        set: function (a) {
            this.r._stroke = a;
        },
        enumerable: true,
        configurable: true
    });
    Object.defineProperty(CalloutView.prototype, "l", {
        get: function () {
            return this.q._stroke;
        },
        set: function (a) {
            this.q._stroke = a;
        },
        enumerable: true,
        configurable: true
    });
    Object.defineProperty(CalloutView.prototype, "k", {
        get: function () {
            return this.r._fill;
        },
        set: function (a) {
            this.r._fill = a;
        },
        enumerable: true,
        configurable: true
    });
    Object.defineProperty(CalloutView.prototype, "c", {
        get: function () {
            return this.r.ac;
        },
        set: function (a) {
            this.r.ac = a;
        },
        enumerable: true,
        configurable: true
    });
    Object.defineProperty(CalloutView.prototype, "v", {
        get: function () {
            return this.u;
        },
        set: function (a) {
            this.u = a;
        },
        enumerable: true,
        configurable: true
    });
    Object.defineProperty(CalloutView.prototype, "f", {
        get: function () {
            return this.j.ak;
        },
        set: function (a) {
            if (a == null) {
                this.j.ak = "";
            }
            else {
                this.j.ak = a.toString();
            }
            var b = this.s();
            var c = b.height;
            var d = b.width;
            var e = CalloutViewHelper.b(this.p, d, c, this.q);
            this.t = e;
        },
        enumerable: true,
        configurable: true
    });
    CalloutView.prototype.s = function () {
        var a = this.a.co(this.j);
        this.j.m = a.width;
        this.j.l = a.height;
        return new Size(1, a.width + this.u.c + this.u.d, a.height + this.u.e + this.u.b);
    };
    CalloutView.prototype.i = function (a, b, c) {
        if (this.b == null) {
            this.b = new DataContext();
        }
        this.b.series = a;
        this.b.item = c;
        if (b.c != null) {
            b.c.u = this.b;
        }
    };
    CalloutView.prototype.g = function (a, b, c) {
        a.a5.exportCalloutData(this.d, this.e, this.t.c, this.t.e, c, this.r, this.j, b, this.q, "callout", ["Main", "Callout"]);
    };
    CalloutView.$t = markType(CalloutView, 'CalloutView');
    return CalloutView;
}(Base));
export { CalloutView };
//# sourceMappingURL=CalloutLayer_combined.js.map
