/*
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-angular-core";
import { Base, String_$type, typeCast, enumGetBox, fromEnum, runOn, delegateCombine, delegateRemove, Date_$type, Point_$type, markType, markDep } from "igniteui-angular-core";
import { Series } from "./Series";
import { Brush } from "igniteui-angular-core";
import { Thickness } from "igniteui-angular-core";
import { CalloutCollisionMode_$type } from "./CalloutCollisionMode";
import { FontUtil } from "igniteui-angular-core";
import { Rect } from "igniteui-angular-core";
import { CalloutLayerFrame } from "./CalloutLayerFrame";
import { HashSet$1 } from "igniteui-angular-core";
import { CalloutAnnotationWrapper } from "./CalloutAnnotationWrapper";
import { List$1 } from "igniteui-angular-core";
import { LinkedList$1 } from "igniteui-angular-core";
import { Dictionary$2 } from "igniteui-angular-core";
import { LinkedListNode$1 } from "igniteui-angular-core";
import { LabelCollisionManager } from "igniteui-angular-core";
import { SeriesPointOfInterest } from "./SeriesPointOfInterest";
import { CalloutAnnotation } from "./CalloutAnnotation";
import { IFastItemsSource_$type } from "igniteui-angular-core";
import { CalloutSeriesSelectingEventArgs } from "./CalloutSeriesSelectingEventArgs";
import { CalloutStyleUpdatingEventArgs } from "./CalloutStyleUpdatingEventArgs";
import { QuadTreeBoundingBox } from "igniteui-angular-core";
import { LabelCollisionInfo } from "igniteui-angular-core";
import { ScalerParams } from "./ScalerParams";
import { Size } from "igniteui-angular-core";
import { CalloutContentUpdatingEventArgs } from "./CalloutContentUpdatingEventArgs";
import { CalloutLabelUpdatingEventArgs } from "./CalloutLabelUpdatingEventArgs";
import { CalloutKey } from "./CalloutKey";
import { DataContext } from "igniteui-angular-core";
import { HashPool$2 } from "igniteui-angular-core";
import { PropertyMetadata } from "igniteui-angular-core";
import { isNaN_ } from "igniteui-angular-core";
import { stringIsNullOrEmpty } from "igniteui-angular-core";
import { FastItemObjectColumn } from "igniteui-angular-core";
import { AnnotationLayerView } from "./AnnotationLayerView";
import { BrushUtil } from "igniteui-angular-core";
import { TextBlock } from "igniteui-angular-core";
import { DOMExecutionContext } from "igniteui-angular-core";
import { Color } from "igniteui-angular-core";
import { Line } from "igniteui-angular-core";
import { CalloutViewHelper } from "./CalloutViewHelper";
import { Rectangle } from "igniteui-angular-core";
import { TranslateTransform } from "igniteui-angular-core";
/**
 * @hidden
 */
var CalloutLayer = /** @class */ (function (_super) {
    tslib_1.__extends(CalloutLayer, _super);
    function CalloutLayer() {
        var _this = _super.call(this) || this;
        _this.calloutStyleUpdating = null;
        _this.nf = null;
        _this.ng = null;
        _this.nh = null;
        _this.ne = null;
        _this.nd = null;
        _this.n3 = new HashSet$1(CalloutAnnotationWrapper.$, 0);
        _this.n6 = new List$1(CalloutAnnotationWrapper.$, 0);
        _this.n7 = new List$1(CalloutAnnotationWrapper.$, 0);
        _this.nb = null;
        _this.n4 = new LinkedList$1(CalloutAnnotationWrapper.$);
        _this.n1 = new Dictionary$2(CalloutAnnotationWrapper.$, LinkedListNode$1.$.specialize(CalloutAnnotationWrapper.$), 0);
        _this.nn = null;
        _this.qw = new Rect(0, 0, 0, 1, 1);
        _this.nt = false;
        _this.oh = 0;
        _this.qv = Rect.empty;
        _this.ns = false;
        _this.calloutContentUpdating = null;
        _this.calloutLabelUpdating = null;
        _this.calloutSeriesSelecting = null;
        _this.n5 = new List$1(SeriesPointOfInterest.$, 0);
        _this.nv = false;
        _this.nw = false;
        _this.n9 = 0;
        _this.nu = false;
        _this.nr = true;
        FastItemObjectColumn.m();
        _this.ma = true;
        var a = new CalloutLayerFrame();
        var b = new CalloutLayerFrame();
        var c = new CalloutLayerFrame();
        var d = _this.fi / 1000;
        _this.l2 = a;
        _this.l1 = b;
        _this.l3 = c;
        _this.ab = CalloutLayer.$;
        return _this;
    }
    CalloutLayer.prototype.po = function (a, b) {
        this.n7.clear();
        this.jd(false);
    };
    CalloutLayer.prototype.hy = function (a, b, c, d) {
        _super.prototype.hy.call(this, a, b, c, d);
        var e = this.n2();
        switch (a) {
            case 3:
                this.p0(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.na;
                    this.n7.insert(f, h);
                    this.p0(f, e);
                }
                break;
            case 0:
                this.n7.v(b, c);
                break;
            case 2:
                for (var i = b; i < b + c; i++) {
                    this.p0(i, e);
                }
                break;
            case 4:
                this.n7.clear();
                for (var j = 0; j < this.bz.count; j++) {
                    var k = new CalloutAnnotation();
                    var l = new CalloutAnnotationWrapper();
                    l.b = k;
                    l.b.series = this.na;
                    this.n7.add(l);
                    this.p0(j, e);
                }
                break;
        }
        this.jd(true);
    };
    CalloutLayer.prototype.da = function (a) {
        return false;
    };
    CalloutLayer.prototype.n2 = function () {
        var a = new Dictionary$2(String_$type, Series.$, 0);
        if (this.bs != null) {
            for (var b = 0; b < this.bs.series.count; b++) {
                var c = this.bs.series._inner[b];
                if (c.name != null && !a.containsKey(c.name)) {
                    a.addItem(c.name, c);
                }
            }
        }
        return a;
    };
    CalloutLayer.prototype.p0 = function (a, b) {
        var _this = this;
        if (this.nm == null || this.nk == null) {
            return;
        }
        var c = a;
        if (this.nl != null) {
            c = this.nl.item(a);
        }
        var d = this.nm.item(a);
        var e = this.nk.item(a);
        var f = this.n7._inner[a];
        f.b.xValue = c;
        f.b.yValue = d;
        f.b.text = e != null ? e.toString() : "";
        if (this.nj != null) {
            f.b.key = this.nj.item(a);
        }
        if (this.ni != null) {
            f.b.content = this.ni.item(a);
        }
        else {
            f.b.content = this.bz.item(a);
        }
        if (this.calloutSeriesSelecting != null) {
            var g = ((function () {
                var $ret = new CalloutSeriesSelectingEventArgs();
                $ret.c = c;
                $ret.d = d;
                $ret.item = _this.bz.item(a);
                return $ret;
            })());
            this.calloutSeriesSelecting(this, g);
            if (g.a != null) {
                f.b.series = g.a;
            }
            else if (g.e != null) {
                if (b.containsKey(g.e)) {
                    f.b.series = b.item(g.e);
                }
            }
        }
        this.p1(f);
    };
    CalloutLayer.prototype.p1 = function (a) {
        var b = new Thickness(0, 3);
        if (isNaN_(this.qy.left) || isNaN_(this.qy.top) || isNaN_(this.qy.right) || isNaN_(this.qy.bottom)) {
            b = new Thickness(0, 3);
        }
        else {
            b = this.qy;
        }
        var c = this.qr != null ? this.qr : this.m7.ce(a.b.series);
        var d = this.qu != null ? this.qu : this.m7.ch();
        var e = this.qt != null ? this.qt : this.m7.cg();
        var f = this.qs != null ? this.qs : this.m7.cf(a.b.series);
        var g = isNaN_(this.of) ? 0 : this.of;
        if (this.nz && this.calloutStyleUpdating != null) {
            var h = new CalloutStyleUpdatingEventArgs();
            h.item = a.b.content;
            h.xValue = a.b.xValue;
            h.yValue = a.b.yValue;
            h.series = a.b.series;
            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.fs = function (a, b) {
        var c = this.gu(b);
        if (c == CalloutLayer.$$p[19]) {
            return this.ft(a, b, this.pc);
        }
        if (c == CalloutLayer.$$p[23]) {
            return this.ft(a, b, this.pj);
        }
        if (c == CalloutLayer.$$p[24]) {
            return this.ft(a, b, this.pm);
        }
        if (c == CalloutLayer.$$p[18]) {
            return this.ft(a, b, this.o9);
        }
        if (c == CalloutLayer.$$p[14]) {
            return this.ft(a, b, this.o3);
        }
        return _super.prototype.fs.call(this, a, b);
    };
    Object.defineProperty(CalloutLayer.prototype, "nk", {
        get: function () {
            return this.nf;
        },
        set: function (a) {
            if (this.nf != a) {
                var b = this.nf;
                this.nf = a;
                this.raisePropertyChanged("LabelColumn", b, this.nf);
            }
        },
        enumerable: true,
        configurable: true
    });
    Object.defineProperty(CalloutLayer.prototype, "nl", {
        get: function () {
            return this.ng;
        },
        set: function (a) {
            if (this.ng != a) {
                var b = this.ng;
                this.ng = a;
                this.raisePropertyChanged("XColumn", b, this.ng);
            }
        },
        enumerable: true,
        configurable: true
    });
    Object.defineProperty(CalloutLayer.prototype, "nm", {
        get: function () {
            return this.nh;
        },
        set: function (a) {
            if (this.nh != a) {
                var b = this.nh;
                this.nh = a;
                this.raisePropertyChanged("YColumn", b, this.nh);
            }
        },
        enumerable: true,
        configurable: true
    });
    Object.defineProperty(CalloutLayer.prototype, "nj", {
        get: function () {
            return this.ne;
        },
        set: function (a) {
            if (this.ne != a) {
                var b = this.ne;
                this.ne = a;
                this.raisePropertyChanged("KeyColumn", b, this.ne);
            }
        },
        enumerable: true,
        configurable: true
    });
    Object.defineProperty(CalloutLayer.prototype, "ni", {
        get: function () {
            return this.nd;
        },
        set: function (a) {
            if (this.nd != a) {
                var b = this.nd;
                this.nd = a;
                this.raisePropertyChanged("ContentColumn", b, this.nd);
            }
        },
        enumerable: true,
        configurable: true
    });
    CalloutLayer.prototype.pq = function (a, b) {
        if (b.propertyName == CalloutAnnotation.$$p[13] || b.propertyName == CalloutAnnotation.$$p[14]) {
            var c = a.k;
            if (!this.n3.contains(c)) {
                this.n6.add(c);
                this.jd(false);
            }
        }
    };
    CalloutLayer.prototype.bf = function () {
        return new CalloutLayerView(this);
    };
    CalloutLayer.prototype.iu = function (a) {
        _super.prototype.iu.call(this, a);
        this.m7 = a;
    };
    Object.defineProperty(CalloutLayer.prototype, "qy", {
        get: function () {
            return new Thickness(1, this.ob, this.od, this.oc, this.oa);
        },
        enumerable: true,
        configurable: true
    });
    Object.defineProperty(CalloutLayer.prototype, "nc", {
        get: function () {
            if (this.nb == null) {
                this.nb = FontUtil.toFontInfo(this.e4, this.pf);
            }
            return this.nb;
        },
        enumerable: true,
        configurable: true
    });
    CalloutLayer.prototype.ml = function (a, b) {
        if (this.na == null || this.na == a) {
            if (!this.aq.c) {
                this.jd(b);
            }
        }
    };
    CalloutLayer.prototype.mn = function (a, b) {
        var e_1, _a;
        _super.prototype.mn.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.n8();
        var e = new List$1(CalloutAnnotationWrapper.$, 0);
        if (this.nx) {
            if (this.l8(this.na)) {
                this.px(this.na, c, e);
            }
            else {
                try {
                    for (var _b = tslib_1.__values(fromEnum(this.bs.series)), _c = _b.next(); !_c.done; _c = _b.next()) {
                        var f = _c.value;
                        if (this.l8(f)) {
                            this.px(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.pw(c, d, e);
    };
    CalloutLayer.prototype.jt = function (a, b) {
        _super.prototype.jt.call(this, a, b);
        var c = b.width - this.qw.width;
        var d = b.height - this.qw.height;
        var e = 0;
        if (Math.abs(c) > Math.abs(d)) {
            e = c;
            this.n9 = c * this.ly.width;
        }
        else {
            e = d;
            this.n9 = d * this.ly.height;
        }
        if (e > 0 && this.n9 > 5) {
            this.nw = true;
        }
        if (e < 0 && this.n9 > 5) {
            this.nv = true;
        }
    };
    CalloutLayer.prototype.js = function (a, b) {
        _super.prototype.js.call(this, a, b);
        if (!a.equals1(b)) {
            this.nu = true;
        }
    };
    Object.defineProperty(CalloutLayer.prototype, "qx", {
        get: function () {
            return this.qv;
        },
        set: function (a) {
            this.qv = a;
        },
        enumerable: true,
        configurable: true
    });
    CalloutLayer.prototype.pw = function (a, b, c) {
        var e_2, _a;
        if (this.bs != null) {
            this.qw = this.bs.mq;
        }
        if (this.ly.isEmpty) {
            return;
        }
        this.qx = new Rect(0, this.ly.left, this.ly.top, this.ly.width, this.ly.height);
        if (this.nn != null && this.o0 != null && this.o0 != this.nn.ak) {
            this.ps();
        }
        if (this.nn == null) {
            var d = this.no();
            if (d != null) {
                this.nn = d;
                var e = this.nn;
                e.labelsMoved = delegateCombine(e.labelsMoved, runOn(this, this.pp));
            }
            else {
                var f = this.lq(this.bi);
                var g = 0;
                if (this.na != null) {
                    if (this.na.isVertical) {
                        g = 2;
                    }
                }
                else {
                    var h = false;
                    if (this.bs != null && this.bs.series.count > 0) {
                        h = true;
                        try {
                            for (var _b = tslib_1.__values(fromEnum(this.bs.series)), _c = _b.next(); !_c.done; _c = _b.next()) {
                                var i = _c.value;
                                if (!i.cj) {
                                    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.nn = new LabelCollisionManager(this.ly.right, this.ly.bottom, this.ly, this.m7.b4(), this.oe, this.np(), g, this.ol(), this.ok(), this.ny);
                if (this.o0 != null) {
                    this.nn.ak = this.o0;
                    this.nn.ai = this;
                }
                var j = this.nn;
                j.labelsMoved = delegateCombine(j.labelsMoved, runOn(this, this.pp));
            }
        }
        if (this.nv) {
            this.nv = false;
            if (this.nn.ag > 2) {
                this.nt = true;
            }
        }
        if (this.nw) {
            this.nw = false;
            if (this.n9 > 5) {
                this.nt = true;
            }
        }
        if (this.nu) {
            this.nu = false;
            this.nn.ax(this.ly.right, this.ly.bottom, this.ly);
            this.nt = 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.n4.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.pq));
                this.n4.h(r);
                this.n1.removeItem(r.c);
                this.nn.aw(r.c.c);
            }
            r = s;
        }
        for (var u = 0; u < b.count; u++) {
            if (!this.n1.containsKey(b._inner[u])) {
                this.n4.f(b._inner[u]);
                var v = b._inner[u].b;
                v.propertyChanged = delegateCombine(v.propertyChanged, runOn(this, this.pq));
                this.n1.addItem(b._inner[u], this.n4.d);
                m.add(b._inner[u]);
                k.add_1(b._inner[u]);
                this.nt = true;
            }
        }
        for (var w = 0; w < c.count; w++) {
            if (!this.n1.containsKey(c._inner[w])) {
                this.n4.f(c._inner[w]);
                this.n1.addItem(c._inner[w], this.n4.d);
                var x = c._inner[w].b;
                x.propertyChanged = delegateCombine(x.propertyChanged, runOn(this, this.pq));
                m.add(c._inner[w]);
                k.add_1(c._inner[w]);
                this.nt = true;
            }
        }
        if (this.n6.count > 0) {
            this.nt = true;
            this.n6.clear();
            this.n3.clear();
        }
        r = this.n4.c;
        while (r != null) {
            var y = this.nq(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.nn.p(aa);
                    }
                    if (z) {
                        this.nn.al(aa);
                    }
                    else {
                        this.nn.at(aa);
                    }
                }
            }
            r = r.a;
        }
        var ab = this.nn.ah();
        var ac = this.nn.q();
        if (this.nt && (ab != 0 || ac)) {
            this.nt = false;
            this.oh = 0x7FFFFFFF;
            if (this.o0 != null) {
                var ad = true;
                for (var ae = 0; ae < this.bs.series.count; ae++) {
                    var af = this.bs.series._inner[ae];
                    if (af.cj && typeCast(CalloutLayer.$, af) !== null) {
                        var ag = af;
                        if (ag.o0 == this.o0) {
                            if (!ag.qx.equals1(this.nn.az)) {
                                ad = false;
                                break;
                            }
                        }
                    }
                }
                if (ad) {
                    this.nn.ay();
                }
                else {
                    this.nn.am();
                }
            }
            else {
                this.nn.ay();
            }
        }
        var ah = this.n4.c;
        while (ah != null) {
            var ai = ah.c;
            a.m.add1(ai);
            a.f.add(ai.b.background);
            a.h.add(ai.b.outline);
            a.g.add(ai.b.leaderBrush);
            a.j.add(ai.b.backgroundPadding.left);
            a.l.add(ai.b.backgroundPadding.top);
            a.k.add(ai.b.backgroundPadding.right);
            a.i.add(ai.b.backgroundPadding.bottom);
            a.n.add(ai.b.strokeThickness);
            a.o.add(ai.b.textColor);
            a.p.add1(ai.b.text);
            a.q.add1(ai.b.content);
            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.ps = function () {
        if (this.nn != null) {
            var a = this.n4.c;
            while (a != null) {
                var b = a.c.c;
                if (b != null) {
                    this.nn.aw(b);
                }
                a = a.a;
            }
            var c = this.nn;
            c.labelsMoved = delegateRemove(c.labelsMoved, runOn(this, this.pp));
            this.nn = null;
        }
        this.pr();
    };
    CalloutLayer.prototype.no = function () {
        if (this.bs == null) {
            return null;
        }
        for (var a = 0; a < this.bs.series.count; a++) {
            var b = this.bs.series._inner[a];
            if (b.cj && typeCast(CalloutLayer.$, b) !== null) {
                var c = b;
                if (c != this) {
                    if (c.o0 != null && c.o0 == this.o0) {
                        if (c.nn != null) {
                            return c.nn;
                        }
                    }
                }
            }
        }
        return null;
    };
    CalloutLayer.prototype.ok = function () {
        return 20000;
    };
    CalloutLayer.prototype.ol = function () {
        return 300;
    };
    CalloutLayer.prototype.np = function () {
        switch (this.m4) {
            case 0: return 2;
            case 2: return 1;
            case 3: return 2;
            case 1: return 0;
        }
        return 2;
    };
    CalloutLayer.prototype.pp = function (a) {
        var b = this.nn.ah();
        if (b < this.oh) {
            this.oh = b;
            this.jd(false);
        }
    };
    CalloutLayer.prototype.nq = function (a) {
        var b = this.na;
        if (a.b.series != null) {
            b = a.b.series;
        }
        if (b == null) {
            for (var c = 0; c < this.bs.series.count; c++) {
                var d = this.bs.series._inner[c];
                if (!d.cj) {
                    b = d;
                    break;
                }
            }
        }
        if (b == null) {
            return null;
        }
        var e = b.ag();
        var f = b.eh();
        var g = null;
        var h = null;
        for (var i = 0; i < e.length; i++) {
            if (e[i].cf) {
                h = e[i];
            }
            else {
                g = e[i];
            }
        }
        if (g == null || h == null) {
            return null;
        }
        if (!g.ce() || !h.ce()) {
            return null;
        }
        var j = 0;
        var k = 0;
        if (g.b2 && g.categoryMode != 0) {
            if (b.cr) {
                j = b.getOffsetValue();
            }
            else if (b.cl) {
                j = b.getOffsetValue();
            }
        }
        if (h.b2 && h.categoryMode != 0) {
            if (b.cl) {
                k = b.getOffsetValue();
            }
        }
        var l = new ScalerParams(0, this.bs.mq, g.i1, g.b8, g.iw());
        l.b = f;
        var m = new ScalerParams(0, this.bs.mq, h.i1, h.b8, h.iw());
        m.b = f;
        var n = g.dw(this.og(a.b.xValue), l) + j;
        var o = h.dw(this.og(a.b.yValue), m) + k;
        var p = new QuadTreeBoundingBox();
        p.b = n;
        p.c = o;
        p.e = 3;
        p.d = 3;
        p.g = a.b;
        return p;
    };
    CalloutLayer.prototype.og = function (a) {
        if (typeCast(Date_$type, a) !== null) {
            return a.getTime();
        }
        if (a == null) {
            return 0;
        }
        return a;
    };
    CalloutLayer.prototype.n8 = function () {
        var a = new List$1(CalloutAnnotationWrapper.$, 0);
        for (var b = 0; b < this.n7.count; b++) {
            if (stringIsNullOrEmpty(this.n7._inner[b].b.text)) {
                continue;
            }
            if (this.n7._inner[b].c == null) {
                var c = new LabelCollisionInfo();
                this.n7._inner[b].c = c;
                var d = this.m7.cj(this.om(this.n7._inner[b]), this.n7._inner[b].b.backgroundPadding);
                c.k = d.height / 2;
                c.l = d.width / 2;
            }
            var e = this.nq(this.n7._inner[b]);
            if (e == null || e.b < this.ly.left || e.b > this.ly.right || e.c < this.ly.top || e.c > this.ly.bottom) {
                continue;
            }
            a.add(this.n7._inner[b]);
        }
        return a;
    };
    CalloutLayer.prototype.om = function (a) {
        return a.b.text;
    };
    CalloutLayer.prototype.l8 = function (a) {
        if (!_super.prototype.l8.call(this, a)) {
            return false;
        }
        return true;
    };
    CalloutLayer.prototype.io = function () {
        _super.prototype.io.call(this);
        if (!this.aq.c && !this.ca()) {
            return;
        }
        if (this.nr) {
            this.nr = false;
            this.pu();
        }
        if (this.ca()) {
            this.pz(this.l3, false);
        }
        else {
            this.pz(this.l1, false);
        }
    };
    CalloutLayer.prototype.pv = function () {
        if (!this.ns) {
            this.ns = true;
            this.jd(true);
        }
    };
    CalloutLayer.prototype.px = function (a, b, c) {
        if (a.ch(this.n5, this.n0, this.oi)) {
            var d = this.n5;
            var _loop_1 = function (e) {
                var f = d._inner[e];
                var g = f.a.item != null ? f.a.item : f.a;
                var h = a;
                var i = new CalloutKey(g, h);
                var j = new CalloutAnnotationWrapper();
                var k = new CalloutAnnotation();
                j.b = k;
                k.key = i;
                var l = false;
                var m = false;
                if (this_1.ns) {
                    this_1.ns = false;
                    m = true;
                }
                if (this_1.n1.containsKey(j)) {
                    j = this_1.n1.item(j).c;
                    k = j.b;
                }
                else {
                    if (!m) {
                        l = true;
                    }
                }
                var n = k.xValue;
                var o = k.yValue;
                if (this_1.og(n) != this_1.og(f.b)) {
                    k.xValue = f.b;
                }
                if (this_1.og(o) != this_1.og(f.c)) {
                    k.yValue = f.c;
                }
                k.series = a;
                if (l && this_1.calloutLabelUpdating != null) {
                    var p = ((function () {
                        var $ret = new CalloutLabelUpdatingEventArgs();
                        $ret.c = k.xValue;
                        $ret.d = k.yValue;
                        $ret.item = g;
                        return $ret;
                    })());
                    this_1.calloutLabelUpdating(this_1, p);
                    if (p.b != null && !Base.equalsStatic(p.b, j.b.text)) {
                        var q = p.b;
                        j.b.text = q != null ? q.toString() : "";
                    }
                }
                else {
                    if (f.d != null) {
                        k.text = f.d;
                    }
                }
                if (k.text == null) {
                    return "continue";
                }
                if (l) {
                    if (this_1.calloutContentUpdating != null) {
                        var r = ((function () {
                            var $ret = new CalloutContentUpdatingEventArgs();
                            $ret.c = k.xValue;
                            $ret.d = k.yValue;
                            $ret.item = g;
                            $ret.a = g;
                            return $ret;
                        })());
                        this_1.calloutContentUpdating(this_1, r);
                        if (r.a != null && r.a != j.b.content) {
                            j.b.content = r.a;
                        }
                    }
                    else {
                        if (g != null && g != j.b.content) {
                            j.b.content = g;
                        }
                    }
                }
                if (l) {
                    this_1.p1(j);
                }
                if (j.c == null) {
                    var s = new LabelCollisionInfo();
                    j.c = s;
                    var t = this_1.m7.cj(this_1.om(j), j.b.backgroundPadding);
                    s.k = t.height / 2;
                    s.l = t.width / 2;
                }
                var u = this_1.nq(j);
                if (u == null || u.b < this_1.ly.left || u.b > this_1.ly.right || u.c < this_1.ly.top || u.c > this_1.ly.bottom) {
                    return "continue";
                }
                c.add(j);
            };
            var this_1 = this;
            for (var e = 0; e < this.n5.count; e++) {
                _loop_1(e);
            }
        }
    };
    CalloutLayer.prototype.bd = function () {
        return 1;
    };
    CalloutLayer.prototype.ar = function (a, b) {
        var c = this.nn.d(a, b);
        if (c == null) {
            return null;
        }
        return c.u;
    };
    CalloutLayer.prototype.dh = function (a, b) {
        if (this.nn == null) {
            return false;
        }
        return this.nn.d(a, b) != null;
    };
    CalloutLayer.prototype.pz = 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.m7.b6.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.bi.bn();
            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.m7.cc(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.m7.cd(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.m7.b6.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.m7.b6.g(h._inner[j]);
        }
    };
    CalloutLayer.prototype.mq = function (a, b) {
        _super.prototype.mq.call(this, a, b);
        if (this.ca()) {
            this.pz(this.l3, true);
        }
        else {
            this.pz(this.l1, false);
        }
    };
    CalloutLayer.prototype.c8 = function () {
        return true;
    };
    CalloutLayer.prototype.iz = function (a, b, c, d) {
        _super.prototype.iz.call(this, a, b, c, d);
        switch (b) {
            case CalloutLayer.$$p[21]:
                this.nb = null;
                this.jd(true);
                break;
            case CalloutLayer.$$p[20]:
                this.jd(true);
                break;
            case CalloutLayer.$$p[13]:
                this.jd(true);
                break;
            case "SeriesViewer":
                if (c != null) {
                    var e = c;
                    e.seriesAnimating = delegateRemove(e.seriesAnimating, runOn(this, this.py));
                }
                if (d != null) {
                    var f = d;
                    f.seriesAnimating = delegateCombine(f.seriesAnimating, runOn(this, this.py));
                }
                if (d == null) {
                    this.ps();
                }
                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.pt();
                break;
            case CalloutLayer.$$p[19]:
                if (this.bz != null) {
                    this.bz.deregisterColumn(this.nk);
                    this.nk = this.by(this.pc);
                }
                break;
            case "LabelColumn":
                this.pt();
                break;
            case CalloutLayer.$$p[14]:
                if (this.bz != null) {
                    this.bz.deregisterColumn(this.ni);
                    this.ni = this.by(this.o3);
                }
                break;
            case "ContentColumn":
                this.pt();
                break;
            case CalloutLayer.$$p[23]:
                if (this.bz != null) {
                    this.bz.deregisterColumn(this.nl);
                    this.nl = stringIsNullOrEmpty(this.pj) == false ? this.by(this.pj) : null;
                }
                break;
            case "XColumn":
                this.pt();
                break;
            case CalloutLayer.$$p[24]:
                if (this.bz != null) {
                    this.bz.deregisterColumn(this.nm);
                    this.nm = this.by(this.pm);
                }
                break;
            case "YColumn":
                this.pt();
                break;
            case CalloutLayer.$$p[18]:
                if (this.bz != null) {
                    this.bz.deregisterColumn(this.nj);
                    this.nj = this.by(this.o9);
                }
                break;
            case "KeyColumn":
                this.pt();
                break;
            case "FastItemsSource":
                if (typeCast(IFastItemsSource_$type, c) != null) {
                    c.deregisterColumn(this.nk);
                    c.deregisterColumn(this.ni);
                    c.deregisterColumn(this.nl);
                    c.deregisterColumn(this.nm);
                    c.deregisterColumn(this.nj);
                    this.nk = null;
                    this.ni = null;
                    this.nl = null;
                    this.nm = null;
                    this.nj = null;
                    this.n7.clear();
                }
                if (typeCast(IFastItemsSource_$type, d) != null) {
                    this.nk = this.by(this.pc);
                    this.ni = this.by(this.o3);
                    if (stringIsNullOrEmpty(this.pj) == false) {
                        this.nl = this.by(this.pj);
                    }
                    this.nm = this.by(this.pm);
                    this.nj = this.by(this.o9);
                }
                this.pt();
                break;
        }
    };
    CalloutLayer.prototype.py = function (a) {
        if (a.cj) {
            return;
        }
        if ((a == this.na || this.na == null) && this.nx) {
            this.jd(false);
        }
    };
    CalloutLayer.prototype.pt = function () {
        if (this.nr == false) {
            this.nr = true;
            this.jd(false);
        }
    };
    CalloutLayer.prototype.pr = function () {
        this.m7.b6.clear();
        this.n4.g();
        this.n1.clear();
    };
    CalloutLayer.prototype.pu = function () {
        if (this.nm == null || this.nk == null) {
            var a = this.n4.c;
            while (a != null) {
                this.p1(a.c);
                a = a.a;
            }
            return;
        }
        var b = this.n2();
        for (var c = 0; c < this.nm.count; c++) {
            var d = void 0;
            if (this.n7.count <= c) {
                var e = new CalloutAnnotation();
                d = new CalloutAnnotationWrapper();
                d.b = e;
                d.b.series = this.na;
                this.n7.add(d);
            }
            else {
                d = this.n7._inner[c];
            }
            this.p0(c, b);
        }
    };
    CalloutLayer.$t = markType(CalloutLayer, 'CalloutLayer', AnnotationLayer.$);
    CalloutLayer.$$p = markDep(DependencyProperty, PropertyMetadata, CalloutLayer, 'raisePropertyChanged', ['AutoCalloutLabelPrecision:oi:p2', [1, 5], 'CalloutBackground:qr:p3', [Brush.$, null], 'CalloutCollisionMode:m4:p4', [CalloutCollisionMode_$type, enumGetBox(CalloutCollisionMode_$type, 3)], 'CalloutInterpolatedValuePrecision:oj:p5', [1, -1], 'CalloutLeaderBrush:qs:p6', [Brush.$, null], 'CalloutOutline:qt:p7', [Brush.$, null], 'CalloutPaddingBottom:oa:p8', [1, NaN], 'CalloutPaddingLeft:ob:p9', [1, NaN], 'CalloutPaddingRight:oc:qa', [1, NaN], 'CalloutPaddingTop:od:qb', [1, NaN], 'CalloutPositionPadding:oe:qc', [1, 10], 'CalloutStrokeThickness:of:qd', [1, NaN], 'CalloutTextColor:qu:qe', [Brush.$, null], 'CollisionChannel:o0:qf', [2, null], 'ContentMemberPath:o3:qg', [2, null], 'IsAutoCalloutBehaviorEnabled:nx:qh', [0, false], 'IsCalloutOffsettingEnabled:ny:qi', [0, true], 'IsCustomCalloutStyleEnabled:nz:qj', [0, false], 'KeyMemberPath:o9:qk', [2, null], 'LabelMemberPath:pc:ql', [2, null], 'TargetSeries:na:qm', [Series.$, null], 'TextStyle:pf:qn', [2, null], 'UseValueForAutoCalloutLabels:n0:qo', [0, true], 'XMemberPath:pj:qp', [2, null], 'YMemberPath:pm:qq', [2, null]]);
    return CalloutLayer;
}(AnnotationLayer));
export { CalloutLayer };
/**
 * @hidden
 */
var CalloutLayerView = /** @class */ (function (_super) {
    tslib_1.__extends(CalloutLayerView, _super);
    function CalloutLayerView(a) {
        var _this = _super.call(this, a) || this;
        _this.b1 = null;
        _this.b7 = null;
        _this.b6 = null;
        _this.b8 = NaN;
        _this.b2 = null;
        _this.b1 = a;
        _this.b7 = new List$1(CalloutView.$, 0);
        return _this;
    }
    CalloutLayerView.prototype.ap = function () {
        var _this = this;
        _super.prototype.ap.call(this);
        this.b6 = ((function () {
            var $ret = new HashPool$2(CalloutAnnotationWrapper.$, CalloutView.$);
            $ret.create = runOn(_this, _this.b3);
            $ret.activate = runOn(_this, _this.b9);
            $ret.disactivate = runOn(_this, _this.cb);
            $ret.destroy = runOn(_this, _this.ca);
            return $ret;
        })());
    };
    CalloutLayerView.prototype.b3 = function () {
        var a = new CalloutView(this);
        this.b7.add(a);
        return a;
    };
    CalloutLayerView.prototype.b9 = function (a) {
        a.w = 0;
    };
    CalloutLayerView.prototype.cb = function (a) {
        a.w = 1;
    };
    CalloutLayerView.prototype.ca = function (a) {
        this.b7.remove(a);
    };
    CalloutLayerView.prototype.ci = function (a) {
        if (a == null) {
            return a;
        }
        return BrushUtil.l(a, 0.1);
    };
    CalloutLayerView.prototype.a3 = function (a, b) {
        _super.prototype.a3.call(this, a, b);
        a.ac(this.b5());
        if (a.d && !b) {
            for (var c = 0; c < this.b7.count; c++) {
                var d = this.b7._inner[c];
                if (d.w == 0) {
                    d.h(a);
                }
            }
        }
    };
    CalloutLayerView.prototype.b5 = function () {
        if (this.b1.nc != null) {
            return this.b1.nc;
        }
        return this.e.bs.getFontInfo();
    };
    CalloutLayerView.prototype.ai = function (a) {
        _super.prototype.ai.call(this, a);
        for (var b = 0; b < this.b7.count; b++) {
            var c = this.b7._inner[b];
            if (c.w != 0) {
                continue;
            }
            c.g(this.b1, this.b5(), a);
        }
    };
    CalloutLayerView.prototype.ck = function (a) {
        if (isNaN_(this.b8)) {
            this.b8 = this.e.bs.bn.a7;
        }
        return new Size(1, this.h.f(a.ak), this.b8);
    };
    CalloutLayerView.prototype.cj = function (a, b) {
        if (this.b2 == null) {
            this.b2 = new CalloutView(this);
        }
        this.b2.f = a;
        this.b2.v = b;
        var c = this.b2.s();
        this.b2.f = null;
        return c;
    };
    CalloutLayerView.prototype.b4 = function () {
        return new DOMExecutionContext(this.e.bs.bn.i.ae);
    };
    CalloutLayerView.prototype.cc = function (a, b, c) {
        a.d = b;
        a.e = c;
    };
    CalloutLayerView.prototype.cd = function (a, b, c) {
        a.i(this.e, b, c);
    };
    CalloutLayerView.prototype.ce = function (a) {
        if (a != null) {
            return this.ci(a.k3);
        }
        return this.e.k3;
    };
    CalloutLayerView.prototype.ch = function () {
        return ((function () {
            var $ret = new Brush();
            $ret.color = Color.u(255, 255, 255, 255);
            return $ret;
        })());
    };
    CalloutLayerView.prototype.cg = function () {
        return ((function () {
            var $ret = new Brush();
            $ret.color = Color.u(255, 255, 255, 255);
            return $ret;
        })());
    };
    CalloutLayerView.prototype.cf = function (a) {
        if (a != null) {
            return this.ci(a.k3);
        }
        return this.e.k3;
    };
    CalloutLayerView.$t = markType(CalloutLayerView, 'CalloutLayerView', AnnotationLayerView.$);
    return CalloutLayerView;
}(AnnotationLayerView));
export { CalloutLayerView };
/**
 * @hidden
 */
var CalloutView = /** @class */ (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.left;
        b.k = this.t.top;
        this.r.j = b;
        a.r(this.q);
        a.z();
        this.r.width = this.j.m + this.u.left + this.u.right;
        this.r.height = this.j.l + this.u.top + this.u.bottom;
        a.j(this.r.j);
        a.v(this.r);
        this.j.o = this.u.top;
        this.j.n = this.u.left;
        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.ck(this.j);
        this.j.m = a.width;
        this.j.l = a.height;
        return new Size(1, a.width + this.u.left + this.u.right, a.height + this.u.top + this.u.bottom);
    };
    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.a2.exportCalloutData(this.d, this.e, this.t.left, this.t.top, 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