/*
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 { PieChartBase } from "./PieChartBase";
import { DependencyProperty } from "igniteui-react-core/ES2015/DependencyProperty";
import { PieChartBaseView } from "./PieChartBaseView";
import { Type, Base, Number_$type, typeCast, fromEnum, markType, IEnumerable_$type, INotifyPropertyChanged_$type, PropertyChangedEventArgs, Point_$type, delegateCombine, enumGetBox, EnumUtil, Delegate_$type, Boolean_$type, delegateRemove, DomRenderer_$type, runOn, fromEn, toEnum } from "igniteui-react-core/ES2015/type";
import { Control } from "igniteui-react-core/ES2015/Control";
import { List$1 } from "igniteui-react-core/ES2015/List$1";
import { NotifyCollectionChangedEventArgs } from "igniteui-react-core/ES2015/NotifyCollectionChangedEventArgs";
import { Pool$1 } from "igniteui-react-core/ES2015/Pool$1";
import { FastItemsSource } from "igniteui-react-core/ES2015/FastItemsSource";
import { IChartLegend_$type } from "igniteui-react-core/ES2015/IChartLegend";
import { ContentControl } from "igniteui-react-core/ES2015/ContentControl";
import { Brush } from "igniteui-react-core/ES2015/Brush";
import { PieSliceDataContext } from "./PieSliceDataContext";
import { UIElement } from "igniteui-react-core/ES2015/UIElement";
import { PropertyMetadata } from "igniteui-react-core/ES2015/PropertyMetadata";
import { Visibility_$type } from "igniteui-react-core/ES2015/Visibility";
import { OthersCategoryType_$type } from "./OthersCategoryType";
import { BrushCollection } from "igniteui-react-core/ES2015/BrushCollection";
import { isNaN_, isInfinity, intDivide } from "igniteui-react-core/ES2015/number";
import { ILegendSeries_$type } from "igniteui-react-core/ES2015/ILegendSeries";
import { ILegendTemplateProvider_$type } from "igniteui-react-core/ES2015/ILegendTemplateProvider";
import { LabelsPosition_$type } from "./LabelsPosition";
import { Style } from "igniteui-react-core/ES2015/Style";
import { LeaderLineType_$type } from "./LeaderLineType";
import { DataTemplate } from "igniteui-react-core/ES2015/DataTemplate";
import { ILegendOwner_$type } from "igniteui-react-core/ES2015/ILegendOwner";
import { PropertyUpdatedEventArgs } from "igniteui-react-core/ES2015/PropertyUpdatedEventArgs";
import { Size } from "igniteui-react-core/ES2015/Size";
import { ObservableCollection$1 } from "igniteui-react-core/ES2015/ObservableCollection$1";
import { DeviceUtils } from "igniteui-react-core/ES2015/DeviceUtils";
import { Rect } from "igniteui-react-core/ES2015/Rect";
import { HoleDimensionsChangedEventArgs } from "./HoleDimensionsChangedEventArgs";
import { DoughnutChartVisualData } from "./DoughnutChartVisualData";
import { RingSeriesVisualDataList } from "./RingSeriesVisualDataList";
import { RectData } from "igniteui-react-core/ES2015/RectData";
import { Dictionary$2 } from "igniteui-react-core/ES2015/Dictionary$2";
import { PieLegendTemplates } from "./PieLegendTemplates";
import { BrushUtil } from "igniteui-react-core/ES2015/BrushUtil";
import { FontUtil } from "igniteui-react-core/ES2015/FontUtil";
import { DOMEventProxy } from "igniteui-react-core/ES2015/DOMEventProxy";
import { SliceVisualData } from "./SliceVisualData";
import { RingSeriesVisualData } from "./RingSeriesVisualData";
import { RingVisualDataList } from "./RingVisualDataList";
import { RingVisualData } from "./RingVisualData";
import { ArcVisualDataList } from "./ArcVisualDataList";
import { ArcVisualData } from "./ArcVisualData";
import { SliceVisualDataList } from "./SliceVisualDataList";
import { PointData } from "igniteui-react-core/ES2015/PointData";
import { AppearanceHelper } from "igniteui-react-core/ES2015/AppearanceHelper";
import { PathVisualData } from "igniteui-react-core/ES2015/PathVisualData";
import { DoughnutChartLabelVisualData } from "./DoughnutChartLabelVisualData";
import { RectUtil } from "igniteui-react-core/ES2015/RectUtil";
import { SizeData } from "igniteui-react-core/ES2015/SizeData";
/**
 * @hidden
 */
export class Arc extends PieChartBase {
    constructor() {
        super();
        this.hb = null;
        this.g9 = null;
        this.he = 0;
        this.ab = Arc.$;
    }
    ar() {
        return new ArcView(this);
    }
    e4(a) {
        super.e4(a);
        this.ha = a;
    }
    get hc() {
        return this.hb;
    }
    set hc(a) {
        let b = this.hb;
        this.hb = a;
        this.ha.b4(b, this.hb);
    }
    get hf() {
        if (this.hc != null) {
            return this.hc.i;
        }
        return 0;
    }
    e3(a, b) {
        super.e3(a, b);
        if (this.hc != null) {
            this.hc.c.at.bs(a, b);
        }
    }
    ek(a, b) {
        if (this.hc != null && this.hc.d != null) {
            super.ek(a, b);
            let c = this.hd(a);
            if (c != null) {
                this.hc.d.bj(c, b);
            }
        }
    }
    fi(a, b) {
        if (this.hc != null && this.hc.d != null) {
            super.fi(a, b);
            let c = this.hd(a);
            if (c != null) {
                this.hc.d.b3(c, b);
            }
        }
    }
    hd(a) {
        for (let b of fromEnum(this.g9.g)) {
            if (b.b == a) {
                return b;
            }
        }
        return null;
    }
    fh(a) {
        if (this.bq) {
            this.e7();
            this.ff();
            this.fe();
        }
    }
    e7() {
        if (this.itemsSource == null || this.a5 == null) {
            this.bg.count = 0;
            return;
        }
        let a = this.b2.count;
        let b = this.b1.count > 0;
        let c = PieChartBase.cs(this.cf);
        let d = PieChartBase.cs(this.cf);
        this.cx = a;
        if (b) {
            a++;
        }
        for (let e = 0; e < a; e++) {
            let f = false;
            let g;
            if (e == a - 1 && b) {
                g = this.cp;
                f = true;
            }
            else {
                g = this.be.item(this.b2._inner[e]);
            }
            if (this.gx == 1) {
                d += PieChartBase.cs(Math.abs(g) * this.hg / this.cu);
            }
            else {
                d -= PieChartBase.cs(Math.abs(g) * this.hg / this.cu);
            }
            let h = this.bg.item(e);
            if (this.cc >= 100) {
                h._visibility = 1;
            }
            else {
                h._visibility = 0;
            }
            h.aw = true;
            h.a3 = c;
            h.ax = d;
            h.a1 = h.a0 = this.cc;
            h.isOthersSlice = f;
            h.ay = this.cb;
            h.a5 = e;
            h.dataContext = f ? this.b0 : this.a5.item(this.b2._inner[e]);
            h.isExploded = this.explodedSlices.contains(e);
            h.isSelected = this.selectedSlices.contains(e);
            c = d;
            h.aw = false;
        }
        this.bg.count = a;
        if (this.g9 != null) {
            this.g9.q(this);
        }
    }
    fe() {
        let a = typeCast(IChartLegend_$type, this.legend);
        if (a == null) {
            return;
        }
        if (this.ba == null || this.ba.count == 0 || ((this.hc != null && this.hc.c != null) && (this.hc.d != null && !this.hc.d.series.contains(this.hc.c)))) {
            a.clearLegendItemsForSeries(this.hc.c);
            return;
        }
        this.bz = new List$1(UIElement.$, 0);
        for (let b of fromEnum(this.bg.a)) {
            let c = new ContentControl();
            let d = this.cy(b);
            let e = b.b0;
            let f = b.isOthersSlice ? this.dz : (this.bb != null && this.bb.count > 0) ? this.bb.item(this.b2._inner[b.a5]) : null;
            f = (f == null && this.ba.count > 0) ? this.ba.item(this.b2._inner[b.a5]) : f;
            c.content = ((() => {
                let $ret = new PieSliceDataContext();
                $ret.series = this.hc.c;
                $ret.slice = b;
                $ret.item = b.dataContext;
                $ret.itemBrush = e;
                $ret.legendLabel = f != null ? f.toString() : null;
                $ret.itemLabel = d != null ? d.toString() : null;
                $ret.percentValue = this.ck(b);
                $ret.isOthersSlice = b.isOthersSlice;
                return $ret;
            })());
            let g = c.content;
            if (this.au != null) {
                let h = this.au(g);
                if (h != null) {
                    g.legendLabel = h.toString();
                }
            }
            if (this.legendItemTemplate != null) {
                c.ah = this.legendItemTemplate;
            }
            this.bz.add(c);
        }
        if (a.isItemwise) {
            let i = a;
            i.createLegendItemsInsert(this.bz, this.hc.c);
        }
    }
    e8(a, b, c, d) {
        super.e8(a, b, c, d);
        switch (b) {
            case Arc.$$p[0]:
                this.he = d;
                this.e7();
                this.e6();
                this.ff();
                this.fd();
                break;
            case "RadiusFactor":
                if (this.hc != null && this.hc.d != null) {
                    this.hc.d.bu();
                }
                break;
            case "Legend":
                let e = typeCast(IChartLegend_$type, c);
                if (e != null && this.hc != null && this.hc.c != null) {
                    e.clearLegendItemsForSeries(this.hc.c);
                }
                break;
        }
    }
    hh() {
        return this.as.ac();
    }
}
Arc.$t = markType(Arc, 'Arc', PieChartBase.$);
Type.dep(DependencyProperty, PropertyMetadata, Arc, 'fa', ['EndAngle:hg:hj', [1, 360]]);
/**
 * @hidden
 */
export class ArcItem extends Base {
    constructor() {
        super();
        this.d = null;
        this.b = null;
        this.n = null;
        this.l = 0;
        this.m = 0;
        this.k = 0;
        this.i = 0;
        this.j = 0;
        this.c = 0;
        this.a = null;
        this.g = null;
        this.e = null;
        this.h = null;
        this.k = 0;
        this.i = 360;
        this.g = new List$1(SliceItem.$, 0);
    }
    o(a, b) {
        let c = 0;
        let d = 0;
        let e = new List$1(Number_$type, 0);
        let f = new List$1(Number_$type, 0);
        let g = new List$1(Base.$, 0);
        this.g.clear();
        if (this.h == null) {
            return;
        }
        let h = new FastItemsSource();
        h.e = this.h;
        let i = this.f(h, this.n);
        if (i == null || i.count == 0) {
            h.deregisterColumn(i);
            h.m();
            return;
        }
        for (let j of fromEnum(i)) {
            if (isNaN_(j) || isInfinity(j) || j <= 0) {
                continue;
            }
            c = c + j;
        }
        for (let k = 0; k < i.count; k++) {
            let l = i.item(k);
            if (isNaN_(l) || isInfinity(l) || l <= 0) {
                continue;
            }
            let m = this.c == 1 ? l / c : l;
            let n = this.c == 1 ? this.j / 100 : this.j;
            if (m <= n) {
                d = d + l;
                f.add(k);
                g.add1(h.item(k));
            }
            else {
                e.add(k);
            }
        }
        let o = e.count;
        let p = f.count > 0;
        let q = PieChartBase.cs(a);
        let r = PieChartBase.cs(a);
        if (p) {
            o++;
        }
        for (let s = 0; s < o; s++) {
            let t = false;
            let u;
            if (s == o - 1 && p) {
                u = d;
                t = true;
            }
            else {
                u = i.item(e._inner[s]);
            }
            let v = 1;
            if (v == 1) {
                r += PieChartBase.cs(Math.abs(u) * b / c);
            }
            else {
                r -= PieChartBase.cs(Math.abs(u) * b / c);
            }
            this.g.add(((() => {
                let $ret = new SliceItem();
                $ret.e = q;
                $ret.d = r - q;
                $ret.g = t ? g : h.item(e._inner[s]);
                return $ret;
            })()));
            q = r;
        }
        h.deregisterColumn(i);
        h.m();
    }
    f(a, b) {
        let c = null;
        return a.registerColumn(b, c, false);
    }
    p(a) {
        let b = this.e == null ? a : this.e.e;
        let c = this.e == null ? 360 : this.e.d;
        this.o(b, c);
    }
    q(a) {
        this.g.clear();
        for (let b = 0; b < a.bg.count; b++) {
            let c = a.bg.item(b);
            this.g.add(((() => {
                let $ret = new SliceItem();
                $ret.e = c.a3;
                $ret.d = c.ax - c.a3;
                $ret.f = b;
                $ret.a = this;
                $ret.g = c.dataContext;
                $ret.c = c.isOthersSlice;
                $ret.b = c;
                return $ret;
            })()));
        }
    }
}
ArcItem.$t = markType(ArcItem, 'ArcItem');
/**
 * @hidden
 */
export class RingSeriesBase extends Control {
    constructor() {
        super();
        this.ao = null;
        this.at = null;
        this.propertyChanged = null;
        this.propertyUpdated = null;
        this.a7 = null;
        this.aw = false;
        this.av = false;
        this.a5 = null;
        this.dj = null;
        this.as = null;
        this.co = null;
        this.dj = { $type: Point_$type, x: 0, y: 0 };
        this.ao = (a, b) => this.cj(a, b.propertyName, b.oldValue, b.newValue);
        this.propertyUpdated = delegateCombine(this.propertyUpdated, this.ao);
        this.as = this.ar();
        this.cg(this.as);
        this.as.k();
        this.a5 = (a, b) => this.ca(b.action, b.position, b.count, b.propertyName);
    }
    cl(a, b, c) {
        if (this.propertyChanged != null) {
            this.propertyChanged(this, new PropertyChangedEventArgs(a));
        }
        if (this.propertyUpdated != null) {
            this.propertyUpdated(this, new PropertyUpdatedEventArgs(a, b, c));
        }
    }
    get dn() {
        if (this.dm != null) {
            return this.dm;
        }
        if (this.at != null && this.at.ce != null) {
            return this.at.ce;
        }
        return null;
    }
    set dn(a) {
        let b = this.dn;
        if (this.dm != null && a != this.dm) {
            a = this.dm;
        }
        this.cl("SelectedStyleResolved", b, a);
    }
    get b3() {
        return this.a7;
    }
    set b3(a) {
        let b = this.a7;
        this.a7 = a;
        this.cl("TextStyle", b, a);
    }
    get cp() {
        return typeCast(DataTemplate.$, this.c(RingSeriesBase.cz));
    }
    set cp(a) {
        this.h(RingSeriesBase.cz, a);
    }
    get ax() {
        return this.c(RingSeriesBase.cu);
    }
    set ax(a) {
        this.aw = true;
        this.h(RingSeriesBase.cu, a);
    }
    get ay() {
        if (!this.aw) {
            return this.at.ax;
        }
        else {
            return this.ax;
        }
    }
    cj(a, b, c, d) {
        if (b == RingSeriesBase.$$p[4]) {
            this.au = ((() => {
                let $ret = new FastItemsSource();
                $ret.e = d;
                return $ret;
            })());
        }
        if (b == RingSeriesBase.$$p[1]) {
            if (typeCast(FastItemsSource.$, c) != null) {
                let e = (typeCast(FastItemsSource.$, c));
                e.event = delegateRemove(e.event, this.a5);
                this.av = false;
            }
            if (typeCast(FastItemsSource.$, d) != null) {
                let f = (typeCast(FastItemsSource.$, d));
                f.event = delegateCombine(f.event, this.a5);
                this.av = true;
            }
            this.ci();
        }
        switch (b) {
            case RingSeriesBase.$$p[22]:
                this.dn = d;
                break;
            case RingSeriesBase.$$p[26]:
                this.ci();
                break;
        }
    }
    get container() {
        return this.at;
    }
    get isStacked() {
        return false;
    }
    get isVertical() {
        return false;
    }
    get isUsableInLegend() {
        return true;
    }
    get hasMarkers() {
        return false;
    }
    get hasSubItems() {
        return false;
    }
    ca(a, b, c, d) {
        this.ci();
    }
    ar() {
        return new RingSeriesBaseView(this);
    }
    cg(a) {
    }
    ck(a) {
        this.as.n(a);
    }
    b9() {
        if (this.as != null) {
            this.as.i();
        }
    }
    cd(a, b) {
        this.cb(new NotifyCollectionChangedEventArgs(1, 0, b, a));
    }
    cf(a, b, c) {
        this.cb(new NotifyCollectionChangedEventArgs(2, 2, c, b, a));
    }
    cc() {
        this.cb(new NotifyCollectionChangedEventArgs(0, 4));
    }
    ce(a, b) {
        this.cb(new NotifyCollectionChangedEventArgs(1, 1, b, a));
    }
    cb(a) {
        if (this.au != null) {
            this.au.handleCollectionChanged(a);
        }
    }
    resolveLegendIndex() {
        return -1;
    }
    forSubItems(a) {
    }
}
RingSeriesBase.$t = markType(RingSeriesBase, 'RingSeriesBase', Control.$, [INotifyPropertyChanged_$type, ILegendSeries_$type, ILegendTemplateProvider_$type]);
RingSeriesBase.cz = DependencyProperty.i("LabelTemplate", DataTemplate.$, RingSeriesBase.$, new PropertyMetadata(2, null, (a, b) => (typeCast(RingSeriesBase.$, a)).cl("LabelTemplate", b.oldValue, b.newValue)));
RingSeriesBase.cu = DependencyProperty.i("IsSurfaceInteractionDisabled", Boolean_$type, RingSeriesBase.$, new PropertyMetadata(2, false, (a, b) => a.cl("IsSurfaceInteractionDisabled", b.oldValue, b.newValue)));
Type.dep(DependencyProperty, PropertyMetadata, RingSeriesBase, 'cl', ['Brushes:ag:cq', [BrushCollection.$, null], 'FastItemsSource:au:cr', [FastItemsSource.$], 'FormatLabel:am:cs', [Delegate_$type], 'FormatLegendLabel:an:ct', [Delegate_$type], 'ItemsSource::cv', [IEnumerable_$type, null], 'LabelExtent:a0:cw', [1, 10], 'LabelMemberPath:bf:cx', [2], 'LabelsPosition:aj:cy', [LabelsPosition_$type, enumGetBox(LabelsPosition_$type, 1)], 'LeaderLineMargin:a1:c0', [1, 6], 'LeaderLineStyle:dk:c1', [Style.$, null], 'LeaderLineType:ak:c2', [LeaderLineType_$type, enumGetBox(LeaderLineType_$type, 0)], 'LeaderLineVisibility:dq:c3', [Visibility_$type, enumGetBox(Visibility_$type, 0)], 'LegendItemBadgeTemplate::c4', [DataTemplate.$, null], 'LegendItemTemplate::c5', [DataTemplate.$, null], 'LegendLabelMemberPath:bp:c6', [2], 'Legend::c7', [IChartLegend_$type, null], 'OthersCategoryStyle:dl:c8', [Style.$, null], 'OthersCategoryText:bt:c9', [2, "Others"], 'OthersCategoryThreshold:a2:da', [1, 3], 'OthersCategoryType:al:db', [OthersCategoryType_$type, enumGetBox(OthersCategoryType_$type, 1)], 'Outlines:ah:dc', [BrushCollection.$, null], 'RadiusFactor:a3:dd', [1, 0.9], 'SelectedStyle:dm:de', [Style.$, null], 'StartAngle:a4:df', [1, 0], 'ToolTip::dg', [4, null], 'ToolTipStyle:dp:dh', [Style.$, null], 'ValueMemberPath:b7:di', [2, null]]);
/**
 * @hidden
 */
export class Ring extends Base {
    constructor() {
        super();
        this.j = 0;
        this.h = 0;
        this.q = new Size();
        this.p = null;
        this._ringControl = null;
        this.b = null;
        this.i = 0;
        this.g = null;
        this.d = null;
        this.e = false;
        this.p = { $type: Point_$type, x: 0, y: 0 };
        this.q = new Size(1, 0, 0);
        this.ringControl = ((() => {
            let $ret = new RingControl();
            $ret.ai = this;
            return $ret;
        })());
        this.g = new List$1(ArcItem.$, 0);
        this.e = true;
    }
    get ringControl() {
        return this._ringControl;
    }
    set ringControl(a) {
        this._ringControl = a;
    }
    get c() {
        return this.b;
    }
    set c(a) {
        this.b = a;
        this.b.as.h(this.ringControl);
        if (this.ringControl != null) {
            this.ringControl.ak.s(a);
        }
    }
    f() {
        if (this.ringControl != null && this.ringControl.ak.d()) {
            let a, b;
            a = this.p.x - this.c.dj.x;
            b = this.p.y - this.c.dj.y;
            this.ringControl.ak.v(a, b);
            return this.ringControl.an();
        }
        return false;
    }
    o() {
        if (this.ringControl != null) {
            this.ringControl.width = this.q.width;
            this.ringControl.height = this.q.height;
            this.c.as.h(this.ringControl);
            this.ringControl.ao = this.g;
        }
    }
    l(source_, a, b) {
        this.ringControl.as(source_, a, b);
    }
    k(source_) {
        this.ringControl.ar(source_);
    }
    m(source_, a, b) {
        this.ringControl.at(source_, a, b);
    }
    n(source_, a, b, c) {
        this.ringControl.au(source_, a, b, c);
    }
}
Ring.$t = markType(Ring, 'Ring');
/**
 * @hidden
 */
export class RingCollection extends ObservableCollection$1 {
    constructor() {
        super(Ring.$, 0);
    }
    p() {
        for (let a of fromEnum(this)) {
            if (a.e) {
                let b = 0;
                let c = a.ringControl.arcs.count;
                while (b < c) {
                    a.ringControl.arcs.destroy(a.ringControl.arcs.item(b));
                    b++;
                }
                a.ringControl.arcs.count = 0;
                a.ringControl = null;
            }
        }
        super.p();
    }
    u(a) {
        let b = this._inner[a];
        if (b.e) {
            b.ringControl.arcs.destroy(b.ringControl.arcs.item(a));
            b.ringControl.arcs.count = 0;
            b.ringControl = null;
        }
        super.u(a);
    }
}
RingCollection.$t = markType(RingCollection, 'RingCollection', ObservableCollection$1.$.specialize(Ring.$));
/**
 * @hidden
 */
export class RingControl extends Control {
    constructor() {
        super();
        this.ak = null;
        this.ah = null;
        this.arcs = null;
        this.ao = null;
        this.a0 = null;
        this.propertyChanged = null;
        this.propertyUpdated = null;
        this.ab = RingControl.$;
        this.ak = this.aj();
        this.ax(this.ak);
        this.ak.r();
        this.arcs = ((() => {
            let $ret = new Pool$1(Arc.$);
            $ret.create = runOn(this.ak, this.ak.a);
            $ret.activate = runOn(this.ak, this.ak.l);
            $ret.disactivate = runOn(this.ak, this.ak.n);
            $ret.destroy = runOn(this.ak, this.ak.m);
            return $ret;
        })());
    }
    get al() {
        return this.ai.c;
    }
    get ai() {
        return this.ah;
    }
    set ai(a) {
        this.ah = a;
        if (this.ah == null) {
            this.ak.s(null);
        }
        else {
            this.ak.s(this.ah.c);
        }
    }
    aj() {
        return new RingControlView(this);
    }
    ax(a) {
    }
    az(a, b, c) {
        if (this.propertyChanged != null) {
            this.propertyChanged(this, new PropertyChangedEventArgs(a));
        }
        if (this.propertyUpdated != null) {
            this.propertyUpdated(this, new PropertyUpdatedEventArgs(a, b, c));
        }
    }
    aw() {
        this.an();
    }
    an() {
        if (this.ao == null) {
            return false;
        }
        if (!this.ak.d()) {
            return false;
        }
        let a = 0;
        let b = false;
        for (let c of fromEnum(this.ao)) {
            let d = this.arcs.item(a);
            d.g9 = c;
            if (d.cl != this.ai.h) {
                d.cl = this.ai.h;
            }
            if ((d.width != this.ai.q.width || d.height != this.ai.q.height) && d.as.r()) {
                d.width = this.ai.q.width;
                d.height = this.ai.q.height;
                this.ak.ab(d);
                b = true;
            }
            if (d.ct != c.k) {
                d.ct = c.k;
            }
            if (d.hg != c.i) {
                d.hg = c.i;
            }
            if (d.itemsSource != c.h) {
                d.itemsSource = c.h;
            }
            if (d.ag != c.a) {
                d.ag = c.a;
            }
            this.ak.t(d, 0, 0);
            a++;
        }
        this.arcs.count = a;
        return b;
    }
    ay(a) {
        this.ak.w(a);
    }
    av() {
        this.ak.q();
    }
    ap() {
        return this.ak.j();
    }
    as(source_, a, b) {
        for (let c = 0; c < this.arcs.count; c++) {
            this.arcs.item(c).es(source_, a, b);
        }
    }
    ar(source_) {
        for (let a = 0; a < this.arcs.count; a++) {
            this.arcs.item(a).eq(source_);
        }
    }
    at(source_, a, b) {
        for (let c = 0; c < this.arcs.count; c++) {
            this.arcs.item(c).et(source_, a, b);
        }
    }
    au(source_, a, b, c) {
        for (let d = 0; d < this.arcs.count; d++) {
            this.arcs.item(d).eu(source_, a, b, c);
        }
    }
}
RingControl.$t = markType(RingControl, 'RingControl', Control.$, [INotifyPropertyChanged_$type]);
/**
 * @hidden
 */
export class RingSeriesCollection extends ObservableCollection$1 {
    constructor() {
        super(RingSeriesBase.$, 0);
    }
}
RingSeriesCollection.$t = markType(RingSeriesCollection, 'RingSeriesCollection', ObservableCollection$1.$.specialize(RingSeriesBase.$));
/**
 * @hidden
 */
export class SliceItem extends Base {
    constructor() {
        super();
        this.e = 0;
        this.d = 0;
        this.a = null;
        this.f = 0;
        this.b = null;
        this.g = null;
        this.c = false;
    }
}
SliceItem.$t = markType(SliceItem, 'SliceItem');
/**
 * @hidden
 */
export class SliceCollection extends ObservableCollection$1 {
    constructor() {
        super(SliceItem.$, 0);
        this.ae = false;
        this.ag = false;
    }
    r(a, b) {
        if (this.contains(b)) {
            return;
        }
        let c = this.ah(b.b);
        if (c != -1) {
            super.x(c, b);
        }
        else {
            super.r(a, b);
            if (this.ae) {
                if (this.ag) {
                    b.b.isSelected = true;
                }
                else {
                    b.b.isExploded = true;
                }
            }
        }
    }
    x(a, b) {
        if (this.ae) {
            if (this.ag) {
                this._inner[a].b.isSelected = false;
            }
            else {
                this._inner[a].b.isExploded = false;
            }
        }
        super.x(a, b);
    }
    u(a) {
        let b = this._inner[a];
        super.u(a);
        if (this.ae) {
            if (this.ag) {
                b.b.isSelected = false;
            }
            else {
                b.b.isExploded = false;
            }
        }
    }
    remove(a) {
        let b = this.ah(a.b);
        if (b != -1) {
            this.u(b);
            return true;
        }
        else {
            return false;
        }
    }
    p() {
        while (this.count > 0) {
            this.u(0);
        }
    }
    ah(a) {
        for (let b = 0; b < this.count; b++) {
            if (this._inner[b].b == a) {
                return b;
            }
        }
        return -1;
    }
}
SliceCollection.$t = markType(SliceCollection, 'SliceCollection', ObservableCollection$1.$.specialize(SliceItem.$));
/**
 * @hidden
 */
export class XamDoughnutChart extends Control {
    constructor() {
        super();
        this.al = new RingSeriesCollection();
        this.aj = new RingCollection();
        this.ap = ((() => {
            let $ret = new SliceCollection();
            $ret.ae = true;
            $ret.ag = true;
            return $ret;
        })());
        this.ao = ((() => {
            let $ret = new SliceCollection();
            $ret.ae = true;
            $ret.ag = false;
            return $ret;
        })());
        this.ah = null;
        this.a0 = NaN;
        this.az = 1;
        this.au = null;
        this.sliceClick = null;
        this.propertyChanged = null;
        this.propertyUpdated = null;
        this.holeDimensionsChanged = null;
        let a = this.at();
        this.bt(a);
        a.r();
        this.ab = XamDoughnutChart.$;
        this.ah = (b, c) => this.bx(b, c.propertyName, c.oldValue, c.newValue);
        this.propertyUpdated = delegateCombine(this.propertyUpdated, this.ah);
        let b = this.series;
        b.collectionChanged = delegateCombine(b.collectionChanged, runOn(this, this.b4));
    }
    get ak() {
        return this.aj;
    }
    get series() {
        return this.al;
    }
    b4(a, b) {
        let c = new List$1(RingSeriesBase.$, 0);
        if (b.oldItems != null) {
            for (let d of fromEn(b.oldItems)) {
                if (b.newItems == null || !b.newItems.contains(d)) {
                    d.b9();
                    this.au.v(d);
                }
            }
        }
        this.bv();
        this.b0();
    }
    get a3() {
        return this.c(XamDoughnutChart.ca);
    }
    set a3(a) {
        this.h(XamDoughnutChart.ca, a);
    }
    get ar() {
        return this.ap;
    }
    set ar(a) {
        this.ap.clear();
        this.ap.ae = false;
        this.ap = a;
        this.ap.ae = true;
        this.ap.ag = true;
        for (let b = 0; b < this.ap.count; b++) {
            this.ap._inner[b].b.isSelected = true;
        }
    }
    get aq() {
        return this.ao;
    }
    set aq(a) {
        this.ao.clear();
        this.ao.ae = false;
        this.ao = a;
        this.ao.ae = true;
        this.ao.ag = false;
        for (let b = 0; b < this.ao.count; b++) {
            this.ao._inner[b].b.isExploded = true;
        }
    }
    get a4() {
        return this.a0;
    }
    set a4(a) {
        let b = this.a0;
        this.a0 = a;
        this.bz("PixelScalingRatio", b, this.a0);
    }
    get a1() {
        return this.az;
    }
    set a1(a) {
        let b = this.az;
        this.az = a;
        this.bz("ActualPixelScalingRatio", b, this.az);
    }
    destroy() {
        this.au.u(null);
        for (let a of fromEnum(this.series)) {
            a.b9();
        }
    }
    b3(a, b) {
        if (b) {
            this.ar.add(a);
        }
        else {
            this.ar.remove(a);
        }
    }
    bj(a, b) {
        if (b) {
            this.aq.add(a);
        }
        else {
            this.aq.remove(a);
        }
    }
    bx(a, b, c, d) {
        switch (b) {
            case XamDoughnutChart.$$p[5]:
                for (let e of fromEnum(this.series)) {
                    e.dn = d;
                }
                break;
            case XamDoughnutChart.$$p[0]:
                for (let f = 0; f < this.aj.count; f++) {
                    for (let g of fromEnum(this.aj._inner[f].ringControl.arcs.a)) {
                        g.bp = this.av;
                    }
                }
                break;
            case XamDoughnutChart.$$p[1]:
                for (let h = 0; h < this.aj.count; h++) {
                    for (let i of fromEnum(this.aj._inner[h].ringControl.arcs.a)) {
                        i.bq = this.aw;
                    }
                }
                break;
            case "PixelScalingRatio":
                let j = DeviceUtils.a(this.a4);
                if (isNaN_(j)) {
                    this.a1 = 1;
                }
                else {
                    this.a1 = j;
                }
                break;
            case "ActualPixelScalingRatio":
                for (let k of fromEnum(this.aj)) {
                    for (let l of fromEnum(k.ringControl.arcs.a)) {
                        l.cd = this.a1;
                    }
                }
                break;
        }
    }
    at() {
        return new XamDoughnutChartView(this);
    }
    bt(a) {
        this.au = a;
    }
    b0() {
        this.bw();
        this.b2();
        this.b1();
        this.bu();
        this.au.y();
    }
    b2() {
        for (let a of fromEnum(this.series)) {
            a.cn();
        }
    }
    bu() {
        let a = this.au.aa;
        if (a.isEmpty || a.width == 0 || a.height == 0) {
            return;
        }
        let b = { $type: Point_$type, x: a.width / 2, y: a.height / 2 };
        let c = Math.min(a.width / 2, a.height / 2);
        let d = 0.9;
        if (this.series.count > 0) {
            d = this.series._inner[0].a3;
            if (isNaN_(d) || isInfinity(d) || d < 0) {
                d = 0;
            }
            else if (d > 1) {
                d = 1;
            }
        }
        let e = this.a3 * c / 100 * d;
        this.au.w(e * 2, e * 2);
        this.au.t(b.x - e, b.y - e);
    }
    b1() {
        let a = false;
        for (let b of fromEnum(this.aj)) {
            if (b.f()) {
                a = true;
            }
        }
        if (a) {
            for (let c of fromEnum(this.aj)) {
                c.c.as.l();
            }
        }
    }
    bw() {
        let a = this.au.aa;
        if (a.isEmpty || a.width == 0 || a.height == 0) {
            return;
        }
        let b = { $type: Point_$type, x: a.width / 2, y: a.height / 2 };
        let c = Math.min(a.width / 2, a.height / 2);
        let d = Math.max(a.width / 2, a.height / 2);
        if (a.width > a.height) {
            c = c + d;
            d = c - d;
            c = c - d;
        }
        let e = ((100 - this.a3) / 100 * c) / this.aj.count;
        let f = ((100 - this.a3) / 100 * d) / this.aj.count;
        let g = this.a3 * c / 100;
        let h = this.a3 * d / 100;
        let i = 1;
        for (let j of fromEnum(this.aj)) {
            let k = (g + (e * i));
            let l = (h + (f * i));
            j.i = e;
            j.q = new Size(1, k * 2, l * 2);
            j.p = { $type: Point_$type, x: b.x - k, y: b.y - l };
            j.h = 100 - (e / k * 100);
            j.o();
            i++;
        }
    }
    bv() {
        this.aq.clear();
        this.ar.clear();
        this.aj.clear();
        this.au.k();
        this.au.j();
        let a = 0;
        for (let b = 0; b < this.series.count; b++) {
            let c = this.series._inner[b];
            c.at = this;
            this.au.i(c);
            let series_ = c;
            series_.externalObject.sychronizeCollections();
            let d = c.aq();
            for (let e of fromEnum(d)) {
                e.d = this;
                e.j = a;
                this.aj.add(e);
                a++;
            }
        }
    }
    br() {
        if (this.au != null) {
            this.height = this.au.aa.height;
            this.width = this.au.aa.width;
        }
        this.b0();
    }
    bs(a, b) {
        let c = a;
        let d = c.hc.c;
        if (d.ay) {
            return;
        }
        if (this.sliceClick != null) {
            this.sliceClick(a, b);
        }
    }
    bz(a, b, c) {
        if (this.propertyChanged != null) {
            this.propertyChanged(this, new PropertyChangedEventArgs(a));
        }
        if (this.propertyUpdated != null) {
            this.propertyUpdated(this, new PropertyUpdatedEventArgs(a, b, c));
        }
    }
    provideContainer(a) {
        this.au.u(a);
    }
    notifyResized() {
        this.au.x();
    }
    bd() {
        return this.au.h();
    }
    cd() {
        return this.au.z;
    }
    a2() {
        return this.au.d;
    }
    bk() {
        let a;
        let b;
        for (let c = 0; c < this.series.count; c++) {
            b = this.series._inner[c].aq();
            for (let d = 0; d < b.count; d++) {
                a = b._inner[d].ringControl.ak.h();
                for (let e = 0; e < a.count; e++) {
                    a._inner[e].el();
                }
            }
        }
    }
    bq() {
        if (this.holeDimensionsChanged != null) {
            this.holeDimensionsChanged(this, new HoleDimensionsChangedEventArgs(this.cd(), this.a2()));
        }
    }
    as() {
        let a = new DoughnutChartVisualData();
        a.series = new RingSeriesVisualDataList();
        a.viewport = RectData.b(this.au.aa);
        this.au.p(a);
        return a;
    }
    bc() {
        let a = this.as();
        a.scaleByViewport();
        return a.serialize();
    }
    *_ay(a) {
        for (let b of fromEnum(this.series)) {
            if (PieChartBase.by(a, b.itemsSource)) {
                yield b;
            }
        }
    }
    ay(a) {
        return toEnum(() => this._ay(a));
    }
    bm(source_, a, b) {
        for (let c of fromEnum(this.ay(source_))) {
            c.cd(a, b);
        }
    }
    bp(source_, a, b, c) {
        for (let d of fromEnum(this.ay(source_))) {
            d.cf(a, b, c);
        }
    }
    bl(source_) {
        for (let a of fromEnum(this.ay(source_))) {
            a.cc();
        }
    }
    bn(source_, a, b) {
        for (let c of fromEnum(this.ay(source_))) {
            c.ce(a, b);
        }
    }
}
XamDoughnutChart.$t = markType(XamDoughnutChart, 'XamDoughnutChart', Control.$, [INotifyPropertyChanged_$type, ILegendOwner_$type]);
XamDoughnutChart.ca = DependencyProperty.i("InnerExtent", Number_$type, XamDoughnutChart.$, new PropertyMetadata(2, 40, (a, b) => {
    let c = b.newValue;
    if (c < 0 || c > 100) {
        if (b.oldValue != null) {
            a.a3 = b.oldValue;
        }
        return;
    }
    a.b0();
    a.bz("InnerExtent", b.oldValue, b.newValue);
}));
Type.dep(DependencyProperty, PropertyMetadata, XamDoughnutChart, 'bz', ['AllowSliceExplosion:av:b6', [0, true], 'AllowSliceSelection:aw:b7', [0, true], 'CenterData:a5:b8', [4, null], 'CenterDataTemplate:b5:b9', [DataTemplate.$, null], 'IsSurfaceInteractionDisabled:ax:cb', [0, false], 'SelectedStyle:ce:cc', [Style.$, null]]);
/**
 * @hidden
 */
export class ArcView extends PieChartBaseView {
    constructor(a) {
        super(a);
        this.b2 = null;
        this.b2 = a;
    }
    b4(a, b) {
        this.e.series = this.b2.hc.c;
    }
    b3() {
        return this.f;
    }
    b5() {
        this.a9();
        this.bq = new Brush();
        let a = this.c.u();
        this.bq._fill = a.rootWrapper.getStyleProperty("color");
    }
}
ArcView.$t = markType(ArcView, 'ArcView', PieChartBaseView.$);
/**
 * @hidden
 */
export class RingControlView extends Base {
    constructor(a) {
        super();
        this.b = null;
        this.f = new List$1(Arc.$, 0);
        this.g = new List$1(Arc.$, 0);
        this.i = null;
        this.e = new Dictionary$2(Arc.$, DomRenderer_$type, 0);
        this.c = null;
        this.b = a;
    }
    a() {
        let a = new Arc();
        a.o = 0;
        a.n = 0;
        a.hc = this.b.ai;
        this.f.add(a);
        this.z(a);
        if (a.eb != this.b.al.b3) {
            a.eb = this.b.al.b3;
        }
        a.cm = this.b.al.a0;
        a.at = this.b.al.am;
        a.di = this.b.al.bf;
        a.ao = this.b.al.aj;
        a.fs = this.b.al.cp;
        a.eg = this.b.al.b7;
        if (this.b.al.toolTip != null) {
            a.c0 = this.b.al.toolTip;
        }
        a.g8 = this.b.al.dq;
        a.g4 = this.b.al.dk;
        a.ap = this.b.al.ak;
        a.cn = this.b.al.a1;
        a.co = this.b.al.a2;
        a.aq = this.b.al.al;
        a.dz = this.b.al.bt;
        a.g5 = this.b.al.dl;
        a.legend = this.b.al.legend;
        a.legendItemTemplate = this.b.al.legendItemTemplate;
        a.legendItemBadgeTemplate = this.b.al.legendItemBadgeTemplate;
        a.ah = this.b.al.ah;
        a.ct = this.b.al.a4;
        a.ag = this.b.al.ag;
        a.g6 = this.b.al.dn;
        a.bv = true;
        a.cr = this.b.al.a3;
        a.bp = this.b.al.at.av;
        a.bq = this.b.al.at.aw;
        a.au = this.b.al.an;
        a.dv = this.b.al.bp;
        a.cd = this.b.al.at.a1;
        return a;
    }
    l(a) {
        let b = this.e.item(a).rootWrapper;
        if (b != null) {
            b.show();
        }
        this.g.add(a);
    }
    n(a) {
        let b = this.e.item(a).rootWrapper;
        if (b != null) {
            b.hide();
        }
        this.g.remove(a);
    }
    m(a) {
        this.o(a);
        this.f.remove(a);
    }
    h() {
        return this.f;
    }
    r() {
    }
    aa() {
        this.b.aw();
    }
    t(a, b, c) {
        b = b + this.b.n;
        c = c + this.b.o;
        if (this.c != null) {
            b = b + this.c.n;
            c = c + this.c.o;
        }
        if (a.n != b || a.o != c) {
            a.n = b;
            a.o = c;
            this.u(a, this.e.item(a).rootWrapper);
        }
    }
    w(a) {
        if (a == null) {
            this.b.arcs.count = 0;
            for (let b of fromEnum(this.f)) {
                b.destroy();
            }
            this.f.clear();
            this.e.clear();
            this.g.clear();
            return;
        }
        this.i = a;
        this.i.rootWrapper.setStyleProperty("position", "relative");
        for (let c of fromEnum(this.f)) {
            let d = this.e.item(c);
            this.i.append(d.rootWrapper);
            c.ha.b5();
        }
        this.aa();
    }
    z(a) {
        let b = this.i.createElement("div");
        b.setStyleProperty("position", "absolute");
        this.e.addItem(a, this.i.getSubRenderer(b));
        this.k(a, b);
        this.u(a, b);
        if (this.i != null) {
            this.i.append(b);
        }
        a.provideContainer(this.e.item(a));
        b.setStyleProperty("position", "absolute");
    }
    k(a, b) {
        b.setStyleProperty("width", a.width.toString() + "px");
        b.setStyleProperty("height", a.height.toString() + "px");
    }
    u(a, b) {
        b.setStyleProperty("top", a.o.toString() + "px");
        b.setStyleProperty("left", a.n.toString() + "px");
    }
    o(a) {
        let b = this.e.item(a);
        b.rootWrapper.remove();
        this.e.removeItem(a);
        a.provideContainer(null);
    }
    ab(a) {
        this.k(a, a.hh().rootWrapper);
        a.ev(a.width, a.height);
    }
    d() {
        return this.i != null;
    }
    q() {
    }
    s(a) {
        this.c = a;
        if (a != null) {
            a.propertyUpdated = delegateCombine(a.propertyUpdated, runOn(this, this.y));
        }
    }
    y(a, b) {
        switch (b.propertyName) {
            case "LabelExtent":
                for (let c = 0; c < this.f.count; c++) {
                    this.f._inner[c].cm = b.newValue;
                }
                break;
            case "LabelMemberPath":
                for (let d = 0; d < this.f.count; d++) {
                    this.f._inner[d].di = b.newValue;
                }
                break;
            case "LabelsPosition":
                for (let e = 0; e < this.f.count; e++) {
                    this.f._inner[e].ao = EnumUtil.getEnumValue(LabelsPosition_$type, b.newValue);
                }
                break;
            case "LabelTemplate":
                for (let f = 0; f < this.f.count; f++) {
                    this.f._inner[f].fs = b.newValue;
                }
                break;
            case "ValueMemberPath":
                for (let g = 0; g < this.f.count; g++) {
                    this.f._inner[g].eg = b.newValue;
                }
                break;
            case "ToolTip":
                for (let h = 0; h < this.f.count; h++) {
                    this.f._inner[h].c0 = b.newValue;
                }
                break;
            case "LeaderLineVisibility":
                for (let i = 0; i < this.f.count; i++) {
                    this.f._inner[i].g8 = EnumUtil.getEnumValue(Visibility_$type, b.newValue);
                }
                break;
            case "LeaderLineStyle":
                for (let j = 0; j < this.f.count; j++) {
                    this.f._inner[j].g4 = b.newValue;
                }
                break;
            case "LeaderLineType":
                for (let k = 0; k < this.f.count; k++) {
                    this.f._inner[k].ap = EnumUtil.getEnumValue(LeaderLineType_$type, b.newValue);
                }
                break;
            case "LeaderLineMargin":
                for (let l = 0; l < this.f.count; l++) {
                    this.f._inner[l].cn = b.newValue;
                }
                break;
            case "OthersCategoryThreshold":
                for (let m = 0; m < this.f.count; m++) {
                    this.f._inner[m].co = b.newValue;
                }
                break;
            case "OthersCategoryType":
                for (let n = 0; n < this.f.count; n++) {
                    this.f._inner[n].aq = EnumUtil.getEnumValue(OthersCategoryType_$type, b.newValue);
                }
                break;
            case "OthersCategoryText":
                for (let o = 0; o < this.f.count; o++) {
                    this.f._inner[o].dz = b.newValue;
                }
                break;
            case "OthersCategoryStyle":
                for (let p = 0; p < this.f.count; p++) {
                    this.f._inner[p].g5 = b.newValue;
                }
                break;
            case "Legend":
                for (let q = 0; q < this.f.count; q++) {
                    this.f._inner[q].legend = b.newValue;
                }
                break;
            case "LegendItemTemplate":
                for (let r = 0; r < this.f.count; r++) {
                    this.f._inner[r].legendItemTemplate = b.newValue;
                }
                break;
            case "LegendItemBadgeTemplate":
                for (let s = 0; s < this.f.count; s++) {
                    this.f._inner[s].legendItemBadgeTemplate = b.newValue;
                }
                break;
            case "Outlines":
                for (let t = 0; t < this.f.count; t++) {
                    this.f._inner[t].ah = b.newValue;
                }
                break;
            case "Brushes":
                for (let u = 0; u < this.f.count; u++) {
                    this.f._inner[u].ag = b.newValue;
                }
                break;
            case "SelectedStyle":
                for (let v = 0; v < this.f.count; v++) {
                    this.f._inner[v].g6 = b.newValue;
                }
                break;
            case "SelectedStyleResolved":
                for (let w = 0; w < this.f.count; w++) {
                    this.f._inner[w].g6 = b.newValue;
                }
                break;
            case "RadiusFactor":
                for (let x = 0; x < this.f.count; x++) {
                    this.f._inner[x].cr = b.newValue;
                }
                break;
        }
    }
    p() {
        for (let a of fromEnum(this.f)) {
            a.el();
        }
    }
    j() {
        return this.i;
    }
    v(a, b) {
        this.b.n = a;
        this.b.o = b;
        this.x();
    }
    x() {
        for (let a = 0; a < this.f.count; a++) {
            let b = this.f._inner[a];
            this.t(b, 0, 0);
        }
    }
}
RingControlView.$t = markType(RingControlView, 'RingControlView');
/**
 * @hidden
 */
export class RingSeriesBaseView extends Base {
    constructor(a) {
        super();
        this.c = null;
        this.f = null;
        this.g = null;
        this.a = null;
        this.b = null;
        this.o = null;
        this.d = null;
        this.f = new List$1(RingControl.$, 0);
        this.c = a;
    }
    k() {
        this.c.legendItemTemplate = ((() => {
            let $ret = new DataTemplate();
            $ret.render = PieLegendTemplates.c;
            $ret.measure = PieLegendTemplates.a;
            return $ret;
        })());
        this.c.legendItemBadgeTemplate = ((() => {
            let $ret = new DataTemplate();
            $ret.render = PieLegendTemplates.b;
            $ret.measure = PieLegendTemplates.d;
            return $ret;
        })());
    }
    h(a) {
        if (!this.f.contains(a)) {
            this.f.add(a);
        }
        if (this.g != null && (a.ap() != this.g)) {
            a.ay(this.g);
        }
    }
    j(a, b, c, d, e) {
        let f = BrushUtil.d("chart", a, b, c);
        b = f.p2;
        c = f.p3;
        let g = new Array(b.count * 2);
        for (let h = 0; h < g.length; h += 2) {
            g[h] = "#fff";
            g[h + 1] = b.item(intDivide(h, 2))._fill;
        }
        let i = BrushUtil.d("doughnut", a, b, c, g);
        b = i.p2;
        c = i.p3;
        d = new Brush();
        d._fill = this.g.rootWrapper.getStyleProperty("color");
        e = FontUtil.getFont(a);
        return {
            p1: b,
            p2: c,
            p3: d,
            p4: e
        };
    }
    n(a) {
        if (a == null) {
            for (let b of fromEnum(this.f)) {
                b.ay(null);
            }
            return;
        }
        this.g = a;
        let c;
        let d;
        let e;
        let f;
        let g = this.j(this.g, c, d, e, f);
        c = g.p1;
        d = g.p2;
        e = g.p3;
        f = g.p4;
        this.a = c;
        this.b = d;
        this.o = e;
        this.d = f;
        if (this.c.ag == null) {
            this.c.ag = this.a;
        }
        if (this.c.ah == null) {
            this.c.ah = this.b;
        }
        for (let h of fromEnum(this.f)) {
            h.ay(this.g);
        }
    }
    e() {
        return true;
    }
    i() {
        this.n(null);
    }
    l() {
        for (let a = 0; a < this.f.count; a++) {
            let b = this.f._inner[a];
            for (let c = 0; c < b.arcs.a.count; c++) {
                let d = b.arcs.a._inner[c];
                d.el();
            }
        }
    }
    m(a, b) {
        this.c.n = a;
        this.c.o = b;
        this.c.dj = { $type: Point_$type, x: a, y: b };
    }
}
RingSeriesBaseView.$t = markType(RingSeriesBaseView, 'RingSeriesBaseView');
/**
 * @hidden
 */
export class XamDoughnutChartView extends Base {
    constructor(a) {
        super();
        this.e = null;
        this.a = null;
        this.z = null;
        this.d = 0;
        this.c = null;
        this.aa = null;
        this.g = null;
        this.f = null;
        this.b = null;
        this.aa = Rect.empty;
        this.z = { $type: Point_$type, x: 0, y: 0 };
        this.d = 0;
        this.c = new List$1(RingSeriesBase.$, 0);
        this.a = a;
    }
    r() {
        this.q();
    }
    y() {
    }
    i(a) {
        if (!this.c.contains(a)) {
            a.ck(this.f);
            this.c.add(a);
        }
    }
    v(a) {
        if (this.c.contains(a)) {
            a.ck(null);
            this.c.remove(a);
        }
    }
    j() {
    }
    x() {
        if (this.f == null) {
            return;
        }
        let a = this.f.rootWrapper.width();
        let b = this.f.rootWrapper.height();
        this.aa = new Rect(0, 0, 0, a, b);
        if (this.b != null) {
            this.b.bd = this.aa;
        }
        this.a.br();
    }
    u(a) {
        if (a == null) {
            if (this.b != null) {
                this.b.ao();
            }
            return;
        }
        let b = a;
        this.f = b;
        let c = this.f.rootWrapper.width();
        let d = this.f.rootWrapper.height();
        this.aa = new Rect(0, 0, 0, c, d);
        this.b = new DOMEventProxy(this.f.rootWrapper, this.f, false);
        this.b.bd = this.aa;
        let e = this.b;
        e.onMouseOver = delegateCombine(e.onMouseOver, runOn(this, this.n));
        let f = this.b;
        f.onMouseLeave = delegateCombine(f.onMouseLeave, runOn(this, this.m));
        let g = this.b;
        g.onMouseDown = delegateCombine(g.onMouseDown, runOn(this, this.l));
        let h = this.b;
        h.onMouseUp = delegateCombine(h.onMouseUp, runOn(this, this.o));
        this.x();
    }
    s(a, b, c) {
        for (let d = this.c.count - 1; d >= 0; d--) {
            let e = this.c._inner[d];
            if (e.ay) {
                continue;
            }
            let f = e.as.f;
            for (let g = 0; g < f.count; g++) {
                let h = f._inner[g];
                let i = h.arcs.a;
                for (let j = 0; j < i.count; j++) {
                    let k = i._inner[j];
                    let l = { $type: Point_$type, x: a.x - k.n, y: a.y - k.o };
                    b(k.as, l);
                    if (c == "mouseUp") {
                        let m = k.ha.b3();
                        if (m != null) {
                            return;
                        }
                    }
                }
            }
        }
    }
    o(a) {
        this.s(a, (b, c) => b.ak(c), "mouseUp");
    }
    l(a) {
        this.s(a, (b, c) => b.ah(c), "mouseDown");
    }
    m(a) {
        this.s(a, (b, c) => b.ai(c), "mouseLeave");
    }
    n(a, b, c) {
        this.s(a, (d, e) => d.aj(e, b, c), "mouseOver");
    }
    h() {
        return this.f.rootWrapper.getAttribute("id");
    }
    t(a, b) {
        if (!this.aa.isEmpty && this.aa.width != 0 && this.aa.height != 0) {
            let c = this.z.x;
            let d = this.z.y;
            this.z.x = this.aa.width / 2;
            this.z.y = this.aa.height / 2;
            if (this.z.x != c || this.z.y != d) {
                this.a.bq();
            }
        }
    }
    w(a, b) {
        let c = this.d;
        this.d = a / 2;
        if (c != this.d) {
            this.a.bq();
        }
    }
    k() {
    }
    p(a) {
        a.width = this.a.width;
        a.height = this.a.height;
        a.holeRadius = this.a.a2();
        for (let b = 0; b < this.a.series.count; b++) {
            a.series.add(new RingSeriesVisualData());
            a.series._inner[b].rings = new RingVisualDataList();
            a.series._inner[b].name = this.a.series._inner[b].name;
            a.series._inner[b].labelExtent = this.a.series._inner[b].a0;
            a.series._inner[b].leaderLineMargin = this.a.series._inner[b].a1;
            a.series._inner[b].leaderLineType = EnumUtil.getName(LeaderLineType_$type, this.a.series._inner[b].ak);
            a.series._inner[b].labelsPosition = EnumUtil.getName(LabelsPosition_$type, this.a.series._inner[b].aj);
            a.series._inner[b].leaderLineVisibility = this.a.series._inner[b].dq == 0;
            for (let c = 0; c < this.a.series._inner[b].aq().count; c++) {
                a.series._inner[b].rings.add(new RingVisualData());
                a.series._inner[b].rings._inner[c].arcs = new ArcVisualDataList();
                for (let d = 0; d < this.a.series._inner[b].aq()._inner[c].g.count; d++) {
                    a.series._inner[b].rings._inner[c].arcs.add(new ArcVisualData());
                    a.series._inner[b].rings._inner[c].arcs._inner[d].a = new SliceVisualDataList();
                    for (let e = 0; e < this.a.series._inner[b].aq()._inner[c].g._inner[d].g.count; e++) {
                        if (null == this.a.series._inner[b].aq()._inner[c].g._inner[d].g._inner[e].b) {
                            continue;
                        }
                        a.series._inner[b].rings._inner[c].arcs._inner[d].a.add(new SliceVisualData());
                        let f = new SliceVisualData();
                        let g = this.a.series._inner[b].aq()._inner[c].g._inner[d].g._inner[e].b;
                        f.visibility = g._visibility == 0;
                        f.endAngle = g.ax;
                        f.startAngle = g.a3;
                        f.radius = g.a2;
                        f.origin = PointData.b(g.b7);
                        f.explodedOrigin = PointData.b(g.b5);
                        f.index = g.a5;
                        f.isExploded = g.isExploded;
                        f.isSelected = g.isSelected;
                        f.outline = AppearanceHelper.a(g.b1);
                        f.backgroundPath = new PathVisualData(1, "slicePath", g.al.f());
                        a.series._inner[b].rings._inner[c].arcs._inner[d].a._inner[e] = f;
                        let h = g.aj;
                        if (null != h) {
                            a.series._inner[b].rings._inner[c].arcs._inner[d].a._inner[e].labelVisualData = ((() => {
                                let $ret = new DoughnutChartLabelVisualData();
                                $ret.labelSize = SizeData.b(RectUtil.z(h.ao));
                                $ret.labelValue = h.aj.ak;
                                return $ret;
                            })());
                            if (!isNaN_(h.n) && !isNaN_(h.o)) {
                                a.series._inner[b].rings._inner[c].arcs._inner[d].a._inner[e].labelVisualData.labelPosition = new PointData(h.n, h.o);
                            }
                        }
                    }
                }
            }
        }
    }
    q() {
        if (this.e == null) {
            this.e = (a) => {
                let b = this.a.a4;
                let c = this.a.a1;
                if (!isNaN_(b) && b != 0) {
                    return;
                }
                if (window.devicePixelRatio != undefined && window.devicePixelRatio != c) {
                    this.a.a1 = window.devicePixelRatio;
                }
            };
            window.addEventListener("resize", this.e, false);
        }
        this.e(null);
    }
}
XamDoughnutChartView.$t = markType(XamDoughnutChartView, 'XamDoughnutChartView');
