/*
THIS INFRAGISTICS ULTIMATE SOFTWARE LICENSE  AGREEMENT ("AGREEMENT") LOCATED HERE:
https://www.infragistics.com/legal/license/igultimate-la
https://www.infragistics.com/legal/license/igultimate-eula
GOVERNS THE LICENSING, INSTALLATION AND USE OF INFRAGISTICS SOFTWARE. BY DOWNLOADING AND/OR INSTALLING AND USING INFRAGISTICS SOFTWARE:  you are indicating that you have read and understand this Agreement, and agree to be legally bound by it on behalf of the yourself and your company.
*/
import { AnnotationLayer } from "./AnnotationLayer";
import { DependencyProperty } from "igniteui-angular-core/ES2015/DependencyProperty";
import { Base, Type, String_$type, typeCast, enumGetBox, fromEnum, runOn, delegateCombine, delegateRemove, Date_$type, Point_$type, markType } from "igniteui-angular-core/ES2015/type";
import { Series } from "./Series";
import { Brush } from "igniteui-angular-core/ES2015/Brush";
import { Thickness } from "igniteui-angular-core/ES2015/Thickness";
import { CalloutCollisionMode_$type } from "./CalloutCollisionMode";
import { FontUtil } from "igniteui-angular-core/ES2015/FontUtil";
import { Rect } from "igniteui-angular-core/ES2015/Rect";
import { CalloutLayerFrame } from "./CalloutLayerFrame";
import { HashSet$1 } from "igniteui-angular-core/ES2015/HashSet$1";
import { CalloutAnnotationWrapper } from "./CalloutAnnotationWrapper";
import { List$1 } from "igniteui-angular-core/ES2015/List$1";
import { LinkedList$1 } from "igniteui-angular-core/ES2015/LinkedList$1";
import { Dictionary$2 } from "igniteui-angular-core/ES2015/Dictionary$2";
import { LinkedListNode$1 } from "igniteui-angular-core/ES2015/LinkedListNode$1";
import { LabelCollisionManager } from "igniteui-angular-core/ES2015/LabelCollisionManager";
import { SeriesPointOfInterest } from "./SeriesPointOfInterest";
import { CalloutAnnotation } from "./CalloutAnnotation";
import { IFastItemsSource_$type } from "igniteui-angular-core/ES2015/IFastItemsSource";
import { CalloutSeriesSelectingEventArgs } from "./CalloutSeriesSelectingEventArgs";
import { CalloutStyleUpdatingEventArgs } from "./CalloutStyleUpdatingEventArgs";
import { QuadTreeBoundingBox } from "igniteui-angular-core/ES2015/QuadTreeBoundingBox";
import { LabelCollisionInfo } from "igniteui-angular-core/ES2015/LabelCollisionInfo";
import { ScalerParams } from "./ScalerParams";
import { Size } from "igniteui-angular-core/ES2015/Size";
import { CalloutContentUpdatingEventArgs } from "./CalloutContentUpdatingEventArgs";
import { CalloutLabelUpdatingEventArgs } from "./CalloutLabelUpdatingEventArgs";
import { CalloutKey } from "./CalloutKey";
import { DataContext } from "igniteui-angular-core/ES2015/DataContext";
import { HashPool$2 } from "igniteui-angular-core/ES2015/HashPool$2";
import { PropertyMetadata } from "igniteui-angular-core/ES2015/PropertyMetadata";
import { isNaN_ } from "igniteui-angular-core/ES2015/number";
import { stringIsNullOrEmpty } from "igniteui-angular-core/ES2015/string";
import { FastItemObjectColumn } from "igniteui-angular-core/ES2015/FastItemObjectColumn";
import { AnnotationLayerView } from "./AnnotationLayerView";
import { BrushUtil } from "igniteui-angular-core/ES2015/BrushUtil";
import { TextBlock } from "igniteui-angular-core/ES2015/TextBlock";
import { DOMExecutionContext } from "igniteui-angular-core/ES2015/DOMExecutionContext";
import { Color } from "igniteui-angular-core/ES2015/Color";
import { Line } from "igniteui-angular-core/ES2015/Line";
import { CalloutViewHelper } from "./CalloutViewHelper";
import { Rectangle } from "igniteui-angular-core/ES2015/Rectangle";
import { TranslateTransform } from "igniteui-angular-core/ES2015/TranslateTransform";
/**
 * @hidden
 */
export class CalloutLayer extends AnnotationLayer {
    constructor() {
        super();
        this.calloutStyleUpdating = null;
        this.ne = null;
        this.nf = null;
        this.ng = null;
        this.nd = null;
        this.nc = null;
        this.n2 = new HashSet$1(CalloutAnnotationWrapper.$, 0);
        this.n5 = new List$1(CalloutAnnotationWrapper.$, 0);
        this.n6 = new List$1(CalloutAnnotationWrapper.$, 0);
        this.na = null;
        this.n3 = new LinkedList$1(CalloutAnnotationWrapper.$);
        this.n0 = new Dictionary$2(CalloutAnnotationWrapper.$, LinkedListNode$1.$.specialize(CalloutAnnotationWrapper.$), 0);
        this.nm = null;
        this.qv = new Rect(0, 0, 0, 1, 1);
        this.ns = false;
        this.og = 0;
        this.qu = Rect.empty;
        this.nr = false;
        this.calloutContentUpdating = null;
        this.calloutLabelUpdating = null;
        this.calloutSeriesSelecting = null;
        this.n4 = new List$1(SeriesPointOfInterest.$, 0);
        this.nu = false;
        this.nv = false;
        this.n8 = 0;
        this.nt = false;
        this.nq = true;
        FastItemObjectColumn.m();
        this.l9 = true;
        let a = new CalloutLayerFrame();
        let b = new CalloutLayerFrame();
        let c = new CalloutLayerFrame();
        let d = this.fi / 1000;
        this.l1 = a;
        this.l0 = b;
        this.l2 = c;
        this.ab = CalloutLayer.$;
    }
    pn(a, b) {
        this.n6.clear();
        this.jc(false);
    }
    hy(a, b, c, d) {
        super.hy(a, b, c, d);
        let e = this.n1();
        switch (a) {
            case 3:
                this.pz(b, e);
                break;
            case 1:
                for (let f = b; f < b + c; f++) {
                    let g = new CalloutAnnotation();
                    let h = new CalloutAnnotationWrapper();
                    h.b = g;
                    h.b.series = this.m9;
                    this.n6.insert(f, h);
                    this.pz(f, e);
                }
                break;
            case 0:
                this.n6.v(b, c);
                break;
            case 2:
                for (let i = b; i < b + c; i++) {
                    this.pz(i, e);
                }
                break;
            case 4:
                this.n6.clear();
                for (let j = 0; j < this.bz.count; j++) {
                    let k = new CalloutAnnotation();
                    let l = new CalloutAnnotationWrapper();
                    l.b = k;
                    l.b.series = this.m9;
                    this.n6.add(l);
                    this.pz(j, e);
                }
                break;
        }
        this.jc(true);
    }
    da(a) {
        return false;
    }
    n1() {
        let a = new Dictionary$2(String_$type, Series.$, 0);
        if (this.bs != null) {
            for (let b = 0; b < this.bs.series.count; b++) {
                let c = this.bs.series._inner[b];
                if (c.name != null && !a.containsKey(c.name)) {
                    a.addItem(c.name, c);
                }
            }
        }
        return a;
    }
    pz(a, b) {
        if (this.nl == null || this.nj == null) {
            return;
        }
        let c = a;
        if (this.nk != null) {
            c = this.nk.item(a);
        }
        let d = this.nl.item(a);
        let e = this.nj.item(a);
        let f = this.n6._inner[a];
        f.b.xValue = c;
        f.b.yValue = d;
        f.b.text = e != null ? e.toString() : "";
        if (this.ni != null) {
            f.b.key = this.ni.item(a);
        }
        if (this.nh != null) {
            f.b.content = this.nh.item(a);
        }
        else {
            f.b.content = this.bz.item(a);
        }
        if (this.calloutSeriesSelecting != null) {
            let g = ((() => {
                let $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.p0(f);
    }
    p0(a) {
        let b = new Thickness(0, 3);
        if (isNaN_(this.qx.c) || isNaN_(this.qx.e) || isNaN_(this.qx.d) || isNaN_(this.qx.b)) {
            b = new Thickness(0, 3);
        }
        else {
            b = this.qx;
        }
        let c = this.qq != null ? this.qq : this.m6.ce(a.b.series);
        let d = this.qt != null ? this.qt : this.m6.ch();
        let e = this.qs != null ? this.qs : this.m6.cg();
        let f = this.qr != null ? this.qr : this.m6.cf(a.b.series);
        let g = isNaN_(this.oe) ? 0 : this.oe;
        if (this.ny && this.calloutStyleUpdating != null) {
            let 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;
    }
    fs(a, b) {
        let c = this.gu(b);
        if (c == CalloutLayer.$$p[19]) {
            return this.ft(a, b, this.pb);
        }
        if (c == CalloutLayer.$$p[23]) {
            return this.ft(a, b, this.pi);
        }
        if (c == CalloutLayer.$$p[24]) {
            return this.ft(a, b, this.pl);
        }
        if (c == CalloutLayer.$$p[18]) {
            return this.ft(a, b, this.o8);
        }
        if (c == CalloutLayer.$$p[14]) {
            return this.ft(a, b, this.o2);
        }
        return super.fs(a, b);
    }
    get nj() {
        return this.ne;
    }
    set nj(a) {
        if (this.ne != a) {
            let b = this.ne;
            this.ne = a;
            this.raisePropertyChanged("LabelColumn", b, this.ne);
        }
    }
    get nk() {
        return this.nf;
    }
    set nk(a) {
        if (this.nf != a) {
            let b = this.nf;
            this.nf = a;
            this.raisePropertyChanged("XColumn", b, this.nf);
        }
    }
    get nl() {
        return this.ng;
    }
    set nl(a) {
        if (this.ng != a) {
            let b = this.ng;
            this.ng = a;
            this.raisePropertyChanged("YColumn", b, this.ng);
        }
    }
    get ni() {
        return this.nd;
    }
    set ni(a) {
        if (this.nd != a) {
            let b = this.nd;
            this.nd = a;
            this.raisePropertyChanged("KeyColumn", b, this.nd);
        }
    }
    get nh() {
        return this.nc;
    }
    set nh(a) {
        if (this.nc != a) {
            let b = this.nc;
            this.nc = a;
            this.raisePropertyChanged("ContentColumn", b, this.nc);
        }
    }
    pp(a, b) {
        if (b.propertyName == CalloutAnnotation.$$p[13] || b.propertyName == CalloutAnnotation.$$p[14]) {
            let c = a.k;
            if (!this.n2.contains(c)) {
                this.n5.add(c);
                this.jc(false);
            }
        }
    }
    bf() {
        return new CalloutLayerView(this);
    }
    it(a) {
        super.it(a);
        this.m6 = a;
    }
    get qx() {
        return new Thickness(1, this.oa, this.oc, this.ob, this.n9);
    }
    get nb() {
        if (this.na == null) {
            this.na = FontUtil.toFontInfo(this.e4, this.pe);
        }
        return this.na;
    }
    mk(a, b) {
        if (this.m9 == null || this.m9 == a) {
            if (!this.aq.c) {
                this.jc(b);
            }
        }
    }
    mm(a, b) {
        super.mm(a, b);
        let 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();
        let d = this.n7();
        let e = new List$1(CalloutAnnotationWrapper.$, 0);
        if (this.nw) {
            if (this.l7(this.m9)) {
                this.pw(this.m9, c, e);
            }
            else {
                for (let f of fromEnum(this.bs.series)) {
                    if (this.l7(f)) {
                        this.pw(f, c, e);
                    }
                }
            }
        }
        this.pv(c, d, e);
    }
    js(a, b) {
        super.js(a, b);
        let c = b.width - this.qv.width;
        let d = b.height - this.qv.height;
        let e = 0;
        if (Math.abs(c) > Math.abs(d)) {
            e = c;
            this.n8 = c * this.lx.width;
        }
        else {
            e = d;
            this.n8 = d * this.lx.height;
        }
        if (e > 0 && this.n8 > 5) {
            this.nv = true;
        }
        if (e < 0 && this.n8 > 5) {
            this.nu = true;
        }
    }
    jr(a, b) {
        super.jr(a, b);
        if (!a.equals1(b)) {
            this.nt = true;
        }
    }
    get qw() {
        return this.qu;
    }
    set qw(a) {
        this.qu = a;
    }
    pv(a, b, c) {
        if (this.bs != null) {
            this.qv = this.bs.mq;
        }
        if (this.lx.isEmpty) {
            return;
        }
        this.qw = new Rect(0, this.lx.left, this.lx.top, this.lx.width, this.lx.height);
        if (this.nm != null && this.oz != null && this.oz != this.nm.ak) {
            this.pr();
        }
        if (this.nm == null) {
            let d = this.nn();
            if (d != null) {
                this.nm = d;
                let e = this.nm;
                e.labelsMoved = delegateCombine(e.labelsMoved, runOn(this, this.po));
            }
            else {
                let f = this.lp(this.bi);
                let g = 0;
                if (this.m9 != null) {
                    if (this.m9.isVertical) {
                        g = 2;
                    }
                }
                else {
                    let h = false;
                    if (this.bs != null && this.bs.series.count > 0) {
                        h = true;
                        for (let i of fromEnum(this.bs.series)) {
                            if (!i.cj) {
                                if (!i.isVertical) {
                                    h = false;
                                }
                            }
                        }
                    }
                    if (h) {
                        g = 2;
                    }
                }
                this.nm = new LabelCollisionManager(this.lx.right, this.lx.bottom, this.lx, this.m6.b4(), this.od, this.no(), g, this.ok(), this.oj(), this.nx);
                if (this.oz != null) {
                    this.nm.ak = this.oz;
                    this.nm.ai = this;
                }
                let j = this.nm;
                j.labelsMoved = delegateCombine(j.labelsMoved, runOn(this, this.po));
            }
        }
        if (this.nu) {
            this.nu = false;
            if (this.nm.ag > 2) {
                this.ns = true;
            }
        }
        if (this.nv) {
            this.nv = false;
            if (this.n8 > 5) {
                this.ns = true;
            }
        }
        if (this.nt) {
            this.nt = false;
            this.nm.ax(this.lx.right, this.lx.bottom, this.lx);
            this.ns = true;
        }
        let k = new HashSet$1(CalloutAnnotationWrapper.$, 0);
        let l = new HashSet$1(CalloutAnnotationWrapper.$, 0);
        let m = new List$1(CalloutAnnotationWrapper.$, 0);
        let n = new List$1(CalloutAnnotationWrapper.$, 0);
        let o = new HashSet$1(CalloutAnnotationWrapper.$, 0);
        for (let p = 0; p < b.count; p++) {
            o.add_1(b._inner[p]);
        }
        for (let q = 0; q < c.count; q++) {
            o.add_1(c._inner[q]);
        }
        let r = this.n3.c;
        while (r != null) {
            let s = r.a;
            if (!o.contains(r.c)) {
                n.add(r.c);
                l.add_1(r.c);
                let t = r.c.b;
                t.propertyChanged = delegateRemove(t.propertyChanged, runOn(this, this.pp));
                this.n3.h(r);
                this.n0.removeItem(r.c);
                this.nm.aw(r.c.c);
            }
            r = s;
        }
        for (let u = 0; u < b.count; u++) {
            if (!this.n0.containsKey(b._inner[u])) {
                this.n3.f(b._inner[u]);
                let v = b._inner[u].b;
                v.propertyChanged = delegateCombine(v.propertyChanged, runOn(this, this.pp));
                this.n0.addItem(b._inner[u], this.n3.d);
                m.add(b._inner[u]);
                k.add_1(b._inner[u]);
                this.ns = true;
            }
        }
        for (let w = 0; w < c.count; w++) {
            if (!this.n0.containsKey(c._inner[w])) {
                this.n3.f(c._inner[w]);
                this.n0.addItem(c._inner[w], this.n3.d);
                let x = c._inner[w].b;
                x.propertyChanged = delegateCombine(x.propertyChanged, runOn(this, this.pp));
                m.add(c._inner[w]);
                k.add_1(c._inner[w]);
                this.ns = true;
            }
        }
        if (this.n5.count > 0) {
            this.ns = true;
            this.n5.clear();
            this.n2.clear();
        }
        r = this.n3.c;
        while (r != null) {
            let y = this.np(r.c);
            if (y == null) {
                return;
            }
            if (!Base.equalsStatic(y, r.c.c.c)) {
                let z = false;
                if (r.c.c.c == null) {
                    z = true;
                }
                let 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.nm.p(aa);
                    }
                    if (z) {
                        this.nm.al(aa);
                    }
                    else {
                        this.nm.at(aa);
                    }
                }
            }
            r = r.a;
        }
        let ab = this.nm.ah();
        let ac = this.nm.q();
        if (this.ns && (ab != 0 || ac)) {
            this.ns = false;
            this.og = 0x7FFFFFFF;
            if (this.oz != null) {
                let ad = true;
                for (let ae = 0; ae < this.bs.series.count; ae++) {
                    let af = this.bs.series._inner[ae];
                    if (af.cj && typeCast(CalloutLayer.$, af) !== null) {
                        let ag = af;
                        if (ag.oz == this.oz) {
                            if (!ag.qw.equals1(this.nm.az)) {
                                ad = false;
                                break;
                            }
                        }
                    }
                }
                if (ad) {
                    this.nm.ay();
                }
                else {
                    this.nm.am();
                }
            }
            else {
                this.nm.ay();
            }
        }
        let ah = this.n3.c;
        while (ah != null) {
            let 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.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.strokeThickness);
            a.o.add(ai.b.textColor);
            a.p.add1(ai.b.text);
            a.q.add1(ai.b.content);
            let 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;
        }
    }
    pr() {
        if (this.nm != null) {
            let a = this.n3.c;
            while (a != null) {
                let b = a.c.c;
                if (b != null) {
                    this.nm.aw(b);
                }
                a = a.a;
            }
            let c = this.nm;
            c.labelsMoved = delegateRemove(c.labelsMoved, runOn(this, this.po));
            this.nm = null;
        }
        this.pq();
    }
    nn() {
        if (this.bs == null) {
            return null;
        }
        for (let a = 0; a < this.bs.series.count; a++) {
            let b = this.bs.series._inner[a];
            if (b.cj && typeCast(CalloutLayer.$, b) !== null) {
                let c = b;
                if (c != this) {
                    if (c.oz != null && c.oz == this.oz) {
                        if (c.nm != null) {
                            return c.nm;
                        }
                    }
                }
            }
        }
        return null;
    }
    oj() {
        return 20000;
    }
    ok() {
        return 300;
    }
    no() {
        switch (this.m3) {
            case 0: return 2;
            case 2: return 1;
            case 3: return 2;
            case 1: return 0;
        }
        return 2;
    }
    po(a) {
        let b = this.nm.ah();
        if (b < this.og) {
            this.og = b;
            this.jc(false);
        }
    }
    np(a) {
        let b = this.m9;
        if (a.b.series != null) {
            b = a.b.series;
        }
        if (b == null) {
            for (let c = 0; c < this.bs.series.count; c++) {
                let d = this.bs.series._inner[c];
                if (!d.cj) {
                    b = d;
                    break;
                }
            }
        }
        if (b == null) {
            return null;
        }
        let e = b.ag();
        let f = b.eh();
        let g = null;
        let h = null;
        for (let i = 0; i < e.length; i++) {
            if (e[i].ce) {
                h = e[i];
            }
            else {
                g = e[i];
            }
        }
        if (g == null || h == null) {
            return null;
        }
        if (!g.cd() || !h.cd()) {
            return null;
        }
        let j = 0;
        let 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();
            }
        }
        let l = new ScalerParams(0, this.bs.mq, g.i0, g.b8, g.iv());
        l.b = f;
        let m = new ScalerParams(0, this.bs.mq, h.i0, h.b8, h.iv());
        m.b = f;
        let n = g.dv(this.of(a.b.xValue), l) + j;
        let o = h.dv(this.of(a.b.yValue), m) + k;
        let p = new QuadTreeBoundingBox();
        p.b = n;
        p.c = o;
        p.e = 3;
        p.d = 3;
        p.g = a.b;
        return p;
    }
    of(a) {
        if (typeCast(Date_$type, a) !== null) {
            return a.getTime();
        }
        if (a == null) {
            return 0;
        }
        return a;
    }
    n7() {
        let a = new List$1(CalloutAnnotationWrapper.$, 0);
        for (let b = 0; b < this.n6.count; b++) {
            if (stringIsNullOrEmpty(this.n6._inner[b].b.text)) {
                continue;
            }
            if (this.n6._inner[b].c == null) {
                let c = new LabelCollisionInfo();
                this.n6._inner[b].c = c;
                let d = this.m6.cj(this.ol(this.n6._inner[b]), this.n6._inner[b].b.backgroundPadding);
                c.k = d.height / 2;
                c.l = d.width / 2;
            }
            let e = this.np(this.n6._inner[b]);
            if (e == null || e.b < this.lx.left || e.b > this.lx.right || e.c < this.lx.top || e.c > this.lx.bottom) {
                continue;
            }
            a.add(this.n6._inner[b]);
        }
        return a;
    }
    ol(a) {
        return a.b.text;
    }
    l7(a) {
        if (!super.l7(a)) {
            return false;
        }
        return true;
    }
    im() {
        super.im();
        if (!this.aq.c && !this.ca()) {
            return;
        }
        if (this.nq) {
            this.nq = false;
            this.pt();
        }
        if (this.ca()) {
            this.py(this.l2, false);
        }
        else {
            this.py(this.l0, false);
        }
    }
    pu() {
        if (!this.nr) {
            this.nr = true;
            this.jc(true);
        }
    }
    pw(a, b, c) {
        if (a.ch(this.n4, this.nz, this.oh)) {
            let d = this.n4;
            for (let e = 0; e < this.n4.count; e++) {
                let f = d._inner[e];
                let g = f.a.item != null ? f.a.item : f.a;
                let h = a;
                let i = new CalloutKey(g, h);
                let j = new CalloutAnnotationWrapper();
                let k = new CalloutAnnotation();
                j.b = k;
                k.key = i;
                let l = false;
                let m = false;
                if (this.nr) {
                    this.nr = false;
                    m = true;
                }
                if (this.n0.containsKey(j)) {
                    j = this.n0.item(j).c;
                    k = j.b;
                }
                else {
                    if (!m) {
                        l = true;
                    }
                }
                let n = k.xValue;
                let o = k.yValue;
                if (this.of(n) != this.of(f.b)) {
                    k.xValue = f.b;
                }
                if (this.of(o) != this.of(f.c)) {
                    k.yValue = f.c;
                }
                k.series = a;
                if (l && this.calloutLabelUpdating != null) {
                    let p = ((() => {
                        let $ret = new CalloutLabelUpdatingEventArgs();
                        $ret.c = k.xValue;
                        $ret.d = k.yValue;
                        $ret.item = g;
                        return $ret;
                    })());
                    this.calloutLabelUpdating(this, p);
                    if (p.b != null && !Base.equalsStatic(p.b, j.b.text)) {
                        let q = p.b;
                        j.b.text = q != null ? q.toString() : "";
                    }
                }
                else {
                    if (f.d != null) {
                        k.text = f.d;
                    }
                }
                if (k.text == null) {
                    continue;
                }
                if (l) {
                    if (this.calloutContentUpdating != null) {
                        let r = ((() => {
                            let $ret = new CalloutContentUpdatingEventArgs();
                            $ret.c = k.xValue;
                            $ret.d = k.yValue;
                            $ret.item = g;
                            $ret.a = g;
                            return $ret;
                        })());
                        this.calloutContentUpdating(this, 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.p0(j);
                }
                if (j.c == null) {
                    let s = new LabelCollisionInfo();
                    j.c = s;
                    let t = this.m6.cj(this.ol(j), j.b.backgroundPadding);
                    s.k = t.height / 2;
                    s.l = t.width / 2;
                }
                let u = this.np(j);
                if (u == null || u.b < this.lx.left || u.b > this.lx.right || u.c < this.lx.top || u.c > this.lx.bottom) {
                    continue;
                }
                c.add(j);
            }
        }
    }
    bd() {
        return 1;
    }
    ar(a, b) {
        let c = this.nm.d(a, b);
        if (c == null) {
            return null;
        }
        return c.u;
    }
    dh(a, b) {
        if (this.nm == null) {
            return false;
        }
        return this.nm.d(a, b) != null;
    }
    py(a, b) {
        let c = 0;
        let d = new HashSet$1(CalloutAnnotationWrapper.$, 0);
        for (c = 0; c < a.p.count; c++) {
            let e = a.m._inner[c];
            if (isNaN_(a.t._inner[c]) || isNaN_(a.u._inner[c])) {
                continue;
            }
            let f = this.m6.b6.item(e);
            d.add_1(e);
            if (f.f != a.p._inner[c]) {
                f.f = a.p._inner[c];
                let 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.m6.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.m6.cd(f, e, a.q._inner[c]);
            f.p = { $type: Point_$type, x: a.t._inner[c], y: a.u._inner[c] };
        }
        let h = new List$1(CalloutAnnotationWrapper.$, 0);
        for (let i of fromEnum(this.m6.b6.c)) {
            if (!d.contains(i)) {
                h.add(i);
            }
        }
        for (let j = 0; j < h.count; j++) {
            this.m6.b6.g(h._inner[j]);
        }
    }
    mp(a, b) {
        super.mp(a, b);
        if (this.ca()) {
            this.py(this.l2, true);
        }
        else {
            this.py(this.l0, false);
        }
    }
    c8() {
        return true;
    }
    iy(a, b, c, d) {
        super.iy(a, b, c, d);
        switch (b) {
            case CalloutLayer.$$p[21]:
                this.na = null;
                this.jc(true);
                break;
            case CalloutLayer.$$p[20]:
                this.jc(true);
                break;
            case CalloutLayer.$$p[13]:
                this.jc(true);
                break;
            case "SeriesViewer":
                if (c != null) {
                    let e = c;
                    e.seriesAnimating = delegateRemove(e.seriesAnimating, runOn(this, this.px));
                }
                if (d != null) {
                    let f = d;
                    f.seriesAnimating = delegateCombine(f.seriesAnimating, runOn(this, this.px));
                }
                if (d == null) {
                    this.pr();
                }
                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.ps();
                break;
            case CalloutLayer.$$p[19]:
                if (this.bz != null) {
                    this.bz.deregisterColumn(this.nj);
                    this.nj = this.by(this.pb);
                }
                break;
            case "LabelColumn":
                this.ps();
                break;
            case CalloutLayer.$$p[14]:
                if (this.bz != null) {
                    this.bz.deregisterColumn(this.nh);
                    this.nh = this.by(this.o2);
                }
                break;
            case "ContentColumn":
                this.ps();
                break;
            case CalloutLayer.$$p[23]:
                if (this.bz != null) {
                    this.bz.deregisterColumn(this.nk);
                    this.nk = stringIsNullOrEmpty(this.pi) == false ? this.by(this.pi) : null;
                }
                break;
            case "XColumn":
                this.ps();
                break;
            case CalloutLayer.$$p[24]:
                if (this.bz != null) {
                    this.bz.deregisterColumn(this.nl);
                    this.nl = this.by(this.pl);
                }
                break;
            case "YColumn":
                this.ps();
                break;
            case CalloutLayer.$$p[18]:
                if (this.bz != null) {
                    this.bz.deregisterColumn(this.ni);
                    this.ni = this.by(this.o8);
                }
                break;
            case "KeyColumn":
                this.ps();
                break;
            case "FastItemsSource":
                if (typeCast(IFastItemsSource_$type, c) != null) {
                    c.deregisterColumn(this.nj);
                    c.deregisterColumn(this.nh);
                    c.deregisterColumn(this.nk);
                    c.deregisterColumn(this.nl);
                    c.deregisterColumn(this.ni);
                    this.nj = null;
                    this.nh = null;
                    this.nk = null;
                    this.nl = null;
                    this.ni = null;
                    this.n6.clear();
                }
                if (typeCast(IFastItemsSource_$type, d) != null) {
                    this.nj = this.by(this.pb);
                    this.nh = this.by(this.o2);
                    if (stringIsNullOrEmpty(this.pi) == false) {
                        this.nk = this.by(this.pi);
                    }
                    this.nl = this.by(this.pl);
                    this.ni = this.by(this.o8);
                }
                this.ps();
                break;
        }
    }
    px(a) {
        if (a.cj) {
            return;
        }
        if ((a == this.m9 || this.m9 == null) && this.nw) {
            this.jc(false);
        }
    }
    ps() {
        if (this.nq == false) {
            this.nq = true;
            this.jc(false);
        }
    }
    pq() {
        this.m6.b6.clear();
        this.n3.g();
        this.n0.clear();
    }
    pt() {
        if (this.nl == null || this.nj == null) {
            let a = this.n3.c;
            while (a != null) {
                this.p0(a.c);
                a = a.a;
            }
            return;
        }
        let b = this.n1();
        for (let c = 0; c < this.nl.count; c++) {
            let d;
            if (this.n6.count <= c) {
                let e = new CalloutAnnotation();
                d = new CalloutAnnotationWrapper();
                d.b = e;
                d.b.series = this.m9;
                this.n6.add(d);
            }
            else {
                d = this.n6._inner[c];
            }
            this.pz(c, b);
        }
    }
}
CalloutLayer.$t = markType(CalloutLayer, 'CalloutLayer', AnnotationLayer.$);
Type.dep(DependencyProperty, PropertyMetadata, CalloutLayer, 'raisePropertyChanged', ['AutoCalloutLabelPrecision:oh:p1', [1, 5], 'CalloutBackground:qq:p2', [Brush.$, null], 'CalloutCollisionMode:m3:p3', [CalloutCollisionMode_$type, enumGetBox(CalloutCollisionMode_$type, 3)], 'CalloutInterpolatedValuePrecision:oi:p4', [1, -1], 'CalloutLeaderBrush:qr:p5', [Brush.$, null], 'CalloutOutline:qs:p6', [Brush.$, null], 'CalloutPaddingBottom:n9:p7', [1, NaN], 'CalloutPaddingLeft:oa:p8', [1, NaN], 'CalloutPaddingRight:ob:p9', [1, NaN], 'CalloutPaddingTop:oc:qa', [1, NaN], 'CalloutPositionPadding:od:qb', [1, 10], 'CalloutStrokeThickness:oe:qc', [1, NaN], 'CalloutTextColor:qt:qd', [Brush.$, null], 'CollisionChannel:oz:qe', [2, null], 'ContentMemberPath:o2:qf', [2, null], 'IsAutoCalloutBehaviorEnabled:nw:qg', [0, false], 'IsCalloutOffsettingEnabled:nx:qh', [0, true], 'IsCustomCalloutStyleEnabled:ny:qi', [0, false], 'KeyMemberPath:o8:qj', [2, null], 'LabelMemberPath:pb:qk', [2, null], 'TargetSeries:m9:ql', [Series.$, null], 'TextStyle:pe:qm', [2, null], 'UseValueForAutoCalloutLabels:nz:qn', [0, true], 'XMemberPath:pi:qo', [2, null], 'YMemberPath:pl:qp', [2, null]]);
/**
 * @hidden
 */
export class CalloutLayerView extends AnnotationLayerView {
    constructor(a) {
        super(a);
        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);
    }
    ap() {
        super.ap();
        this.b6 = ((() => {
            let $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;
        })());
    }
    b3() {
        let a = new CalloutView(this);
        this.b7.add(a);
        return a;
    }
    b9(a) {
        a.w = 0;
    }
    cb(a) {
        a.w = 1;
    }
    ca(a) {
        this.b7.remove(a);
    }
    ci(a) {
        if (a == null) {
            return a;
        }
        return BrushUtil.h(a, 0.1);
    }
    a3(a, b) {
        super.a3(a, b);
        a.ac(this.b5());
        if (a.d && !b) {
            for (let c = 0; c < this.b7.count; c++) {
                let d = this.b7._inner[c];
                if (d.w == 0) {
                    d.h(a);
                }
            }
        }
    }
    b5() {
        if (this.b1.nb != null) {
            return this.b1.nb;
        }
        return this.e.bs.getFontInfo();
    }
    ai(a) {
        super.ai(a);
        for (let b = 0; b < this.b7.count; b++) {
            let c = this.b7._inner[b];
            if (c.w != 0) {
                continue;
            }
            c.g(this.b1, this.b5(), a);
        }
    }
    ck(a) {
        if (isNaN_(this.b8)) {
            this.b8 = this.e.bs.bn.a7;
        }
        return new Size(1, this.h.f(a.ak), this.b8);
    }
    cj(a, b) {
        if (this.b2 == null) {
            this.b2 = new CalloutView(this);
        }
        this.b2.f = a;
        this.b2.v = b;
        let c = this.b2.s();
        this.b2.f = null;
        return c;
    }
    b4() {
        return new DOMExecutionContext(this.e.bs.bn.i.af);
    }
    cc(a, b, c) {
        a.d = b;
        a.e = c;
    }
    cd(a, b, c) {
        a.i(this.e, b, c);
    }
    ce(a) {
        if (a != null) {
            return this.ci(a.k2);
        }
        return this.e.k2;
    }
    ch() {
        return ((() => {
            let $ret = new Brush();
            $ret.color = Color.u(255, 255, 255, 255);
            return $ret;
        })());
    }
    cg() {
        return ((() => {
            let $ret = new Brush();
            $ret.color = Color.u(255, 255, 255, 255);
            return $ret;
        })());
    }
    cf(a) {
        if (a != null) {
            return this.ci(a.k2);
        }
        return this.e.k2;
    }
}
CalloutLayerView.$t = markType(CalloutLayerView, 'CalloutLayerView', AnnotationLayerView.$);
/**
 * @hidden
 */
export class CalloutView extends Base {
    constructor(a) {
        super();
        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 = ((() => {
            let $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;
    }
    h(a) {
        a.z();
        a.af(this.d, this.e);
        let 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();
    }
    get p() {
        return this.o;
    }
    set p(a) {
        if (this.o.x != a.x || this.o.y != a.y) {
            let b = this.s();
            let c = b.height;
            let d = b.width;
            this.o = a;
            let e = CalloutViewHelper.b(this.p, d, c, this.q);
            this.t = e;
        }
    }
    get n() {
        return this.j.am;
    }
    set n(a) {
        this.j.am = a;
    }
    get m() {
        return this.r._stroke;
    }
    set m(a) {
        this.r._stroke = a;
    }
    get l() {
        return this.q._stroke;
    }
    set l(a) {
        this.q._stroke = a;
    }
    get k() {
        return this.r._fill;
    }
    set k(a) {
        this.r._fill = a;
    }
    get c() {
        return this.r.ac;
    }
    set c(a) {
        this.r.ac = a;
    }
    get v() {
        return this.u;
    }
    set v(a) {
        this.u = a;
    }
    get f() {
        return this.j.ak;
    }
    set f(a) {
        if (a == null) {
            this.j.ak = "";
        }
        else {
            this.j.ak = a.toString();
        }
        let b = this.s();
        let c = b.height;
        let d = b.width;
        let e = CalloutViewHelper.b(this.p, d, c, this.q);
        this.t = e;
    }
    s() {
        let a = this.a.ck(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);
    }
    i(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;
        }
    }
    g(a, b, c) {
        a.a2.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');
//# sourceMappingURL=CalloutLayer_combined.js.map