/*
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 { __extends, __values } from "tslib";
import { Base, markType, INotifyPropertyChanged_$type, PropertyChangedEventArgs, Array_$type, enumGetBox, EnumUtil, typeGetValue, Number_$type, String_$type, fromEnum, typeCast, Date_$type, markDep, runOn, TypeRegistrar } from "igniteui-angular-core";
import { List$1 } from "igniteui-angular-core";
import { DataAbbreviationMode_$type } from "igniteui-angular-core";
import { Brush } from "igniteui-angular-core";
import { FontInfo } from "igniteui-angular-core";
import { Thickness } from "igniteui-angular-core";
import { Size } from "igniteui-angular-core";
import { Rect } from "igniteui-angular-core";
import { stringIsNullOrEmpty, stringEmpty } from "igniteui-angular-core";
import { DataLegendSeriesContext } from "igniteui-angular-core";
import { LegendItemBadgeShape_$type } from "igniteui-angular-core";
import { Control } from "igniteui-angular-core";
import { IDataLegend_$type } from "igniteui-angular-core";
import { IOnDemandRender_$type } from "igniteui-angular-core";
import { DependencyProperty } from "igniteui-angular-core";
import { DataLegendValueMode_$type } from "igniteui-angular-core";
import { FontUtil } from "igniteui-angular-core";
import { DataLegendHeaderDateMode_$type } from "igniteui-angular-core";
import { DataLegendHeaderTimeMode_$type } from "igniteui-angular-core";
import { DataLegendSummaryType_$type } from "igniteui-angular-core";
import { DataLegendUnitsMode_$type } from "igniteui-angular-core";
import { DataLegendLabelMode_$type } from "igniteui-angular-core";
import { BindingFormatter } from "igniteui-angular-core";
import { DataLegendVisualData } from "./DataLegendVisualData";
import { Extensions } from "igniteui-angular-core";
import { TextBlock } from "igniteui-angular-core";
import { DataLegendVisualDataRow } from "./DataLegendVisualDataRow";
import { DataLegendVisualDataColumn } from "./DataLegendVisualDataColumn";
import { IDataLegendSeries_$type } from "igniteui-angular-core";
import { RectData } from "igniteui-angular-core";
import { AppearanceHelper } from "igniteui-angular-core";
import { FrameworkElement } from "igniteui-angular-core";
import { DataLegendSummaryEventArgs } from "./DataLegendSummaryEventArgs";
import { DataLegendSummaryCalculationTotal } from "./DataLegendSummaryCalculationTotal";
import { DataLegendSummaryCalculationAverage } from "./DataLegendSummaryCalculationAverage";
import { DataLegendSummaryCalculationMin } from "./DataLegendSummaryCalculationMin";
import { DataLegendSummaryCalculationMax } from "./DataLegendSummaryCalculationMax";
import { DataLegendSummaryCalculationEmpty } from "./DataLegendSummaryCalculationEmpty";
import { DataLegendStylingRowEventArgs } from "./DataLegendStylingRowEventArgs";
import { DataLegendStylingColumnEventArgs } from "./DataLegendStylingColumnEventArgs";
import { Dictionary$2 } from "igniteui-angular-core";
import { DataLegendColumn } from "./DataLegendColumn";
import { RenderingContext } from "igniteui-angular-core";
import { DataLegendRenderContext } from "./DataLegendRenderContext";
import { Pool$1 } from "igniteui-angular-core";
import { ContentControl } from "igniteui-angular-core";
import { DataLegendSeriesValueInfo } from "igniteui-angular-core";
import { DataLegendSummaryColumn } from "igniteui-angular-core";
import { DataLegendSeriesGroup_$type } from "igniteui-angular-core";
import { DataAbbreviator } from "./DataAbbreviator";
import { NumberFormatSpecifier } from "igniteui-angular-core";
import { DateTimeFormatSpecifier } from "igniteui-angular-core";
import { PropertyMetadata } from "igniteui-angular-core";
import { isNaN_, isInfinity, truncate } from "igniteui-angular-core";
import { numberToString2 } from "igniteui-angular-core";
import { EventProxy } from "igniteui-angular-core";
import { Tuple$2 } from "igniteui-angular-core";
import { CanvasViewRenderer } from "igniteui-angular-core";
import { DataTemplatePassInfo } from "igniteui-angular-core";
import { DataTemplateMeasureInfo } from "igniteui-angular-core";
import { DataTemplateRenderInfo } from "igniteui-angular-core";
import { FontDefaults } from "igniteui-angular-core";
/**
 * @hidden
 */
var DataLegendContent = /** @class */ /*@__PURE__*/ (function (_super) {
    __extends(DataLegendContent, _super);
    function DataLegendContent() {
        var _this = _super !== null && _super.apply(this, arguments) || this;
        _this.a = new List$1(DataLegendRowInfo.$, 0);
        _this.d = 0;
        _this.c = 0;
        return _this;
    }
    Object.defineProperty(DataLegendContent.prototype, "b", {
        get: function () {
            return this.a;
        },
        enumerable: false,
        configurable: true
    });
    DataLegendContent.prototype.f = function () {
        this.b.clear();
    };
    DataLegendContent.prototype.e = function (a) {
        this.b.add(a);
    };
    DataLegendContent.$t = markType(DataLegendContent, 'DataLegendContent');
    return DataLegendContent;
}(Base));
export { DataLegendContent };
/**
 * @hidden
 */
var DataLegendRowBase = /** @class */ /*@__PURE__*/ (function (_super) {
    __extends(DataLegendRowBase, _super);
    function DataLegendRowBase(a, b, c, d) {
        var _this = _super.call(this) || this;
        _this.e = 0;
        _this.b = false;
        _this.d = false;
        _this.a = false;
        _this.c = false;
        _this.e = d;
        _this.d = b;
        _this.a = c;
        _this.c = !c && !b;
        _this.b = true;
        return _this;
    }
    DataLegendRowBase.$t = markType(DataLegendRowBase, 'DataLegendRowBase');
    return DataLegendRowBase;
}(Base));
export { DataLegendRowBase };
/**
 * @hidden
 */
var DataLegendRowCell = /** @class */ /*@__PURE__*/ (function (_super) {
    __extends(DataLegendRowCell, _super);
    function DataLegendRowCell(a, b, c, d) {
        var _this = _super.call(this, a, b, c, d) || this;
        _this.s = 0;
        _this.f = 0;
        _this.r = 0;
        _this.v = null;
        _this.t = null;
        _this.w = null;
        _this.u = null;
        _this.y = null;
        _this.z = null;
        _this.aa = null;
        _this.g = null;
        _this.i = null;
        _this.h = null;
        _this.ak = null;
        _this.am = null;
        _this.al = null;
        _this.af = new Size();
        _this.aj = new Size();
        _this.ah = new Size();
        _this.m = false;
        _this.j = false;
        _this.ab = null;
        _this.ad = null;
        _this.ac = null;
        _this.ae = new Size();
        _this.ai = new Size();
        _this.ag = new Size();
        _this.r = NaN;
        _this.ak = new Thickness(0, 0);
        _this.am = new Thickness(0, 0);
        _this.al = new Thickness(0, 0);
        _this.af = new Size(1, 0, 0);
        _this.aj = new Size(1, 0, 0);
        _this.ah = new Size(1, 0, 0);
        _this.m = true;
        _this.j = true;
        if (_this.c) {
            _this.y = a.br();
            _this.aa = a.bt();
            _this.z = a.bs();
            _this.g = a.j();
            _this.i = a.n();
            _this.h = a.m();
        }
        else if (_this.d) {
            var e = a.bq();
            var f = a.k();
            _this.y = e;
            _this.aa = e;
            _this.z = e;
            _this.g = f;
            _this.i = f;
            _this.h = f;
        }
        else {
            var g = a.bo();
            var h = a.i();
            _this.y = g;
            _this.aa = g;
            _this.z = g;
            _this.g = h;
            _this.i = h;
            _this.h = h;
        }
        _this.ab = Rect.empty;
        _this.ad = Rect.empty;
        _this.ac = Rect.empty;
        return _this;
    }
    DataLegendRowCell.prototype.k = function () {
        return this.af.width > 0 && this.af.height > 0;
    };
    DataLegendRowCell.prototype.n = function () {
        return this.ah.width > 0 && this.ah.height > 0;
    };
    DataLegendRowCell.prototype.p = function () {
        return this.aj.width > 0 && this.aj.height > 0;
    };
    DataLegendRowCell.prototype.l = function () {
        return this.t != null;
    };
    DataLegendRowCell.prototype.o = function () {
        return this.u != null;
    };
    DataLegendRowCell.prototype.q = function () {
        return !stringIsNullOrEmpty(this.w) && this.aj.width > 0 && this.aj.height > 0;
    };
    DataLegendRowCell.prototype.x = function () {
        this.ae = new Size(1, 0, 0);
        this.ai = new Size(1, 0, 0);
        this.ag = new Size(1, 0, 0);
    };
    DataLegendRowCell.$t = markType(DataLegendRowCell, 'DataLegendRowCell', DataLegendRowBase.$);
    return DataLegendRowCell;
}(DataLegendRowBase));
export { DataLegendRowCell };
/**
 * @hidden
 */
var DataLegendRowInfo = /** @class */ /*@__PURE__*/ (function (_super) {
    __extends(DataLegendRowInfo, _super);
    function DataLegendRowInfo(a, b, c, d) {
        var _this = _super.call(this, a, b, c, d) || this;
        _this.k = null;
        _this.j = false;
        _this.m = null;
        _this.f = null;
        _this.g = null;
        _this.n = null;
        _this.q = null;
        _this.i = null;
        _this.p = null;
        _this.t = new Size();
        _this.l = null;
        _this.h = 0;
        _this.w = null;
        _this.v = null;
        _this.x = null;
        _this.u = new Size();
        _this.r = null;
        _this.s = null;
        _this.f = new Array(0);
        _this.k = new List$1(DataLegendRowCell.$, 0);
        _this.j = _this.c;
        _this.w = new Thickness(0, 0);
        _this.v = new Thickness(0, 0);
        _this.x = new Thickness(0, 0);
        _this.t = new Size(1, 0, 0);
        _this.u = new Size(1, 0, 0);
        if (_this.c) {
            _this.q = a.br();
            _this.i = a.l();
        }
        else if (_this.d) {
            var e = a.bq();
            var f = a.k();
            _this.q = e;
            _this.i = f;
        }
        else {
            var g = a.bo();
            var h = a.i();
            _this.q = g;
            _this.i = h;
        }
        _this.s = Rect.empty;
        _this.r = Rect.empty;
        _this.h = 7;
        return _this;
    }
    DataLegendRowInfo.prototype.o = function (a) {
        if (this.k == null) {
            return;
        }
        for (var b = 0; b < this.k.count; b++) {
            a(this.k._inner[b]);
        }
    };
    DataLegendRowInfo.$t = markType(DataLegendRowInfo, 'DataLegendRowInfo', DataLegendRowBase.$);
    return DataLegendRowInfo;
}(DataLegendRowBase));
export { DataLegendRowInfo };
/**
 * @hidden
 */
var XamDataLegend = /** @class */ /*@__PURE__*/ (function (_super) {
    __extends(XamDataLegend, _super);
    function XamDataLegend() {
        var _this = _super.call(this) || this;
        _this.bw = false;
        _this.ch = NaN;
        _this.ci = NaN;
        _this.cj = 1;
        _this.bx = false;
        _this.bj = null;
        _this.bb = null;
        _this.be = null;
        _this.bg = null;
        _this.bd = null;
        _this.bf = null;
        _this.a7 = null;
        _this.bi = null;
        _this.bh = null;
        _this.bc = null;
        _this.ck = NaN;
        _this.calculateColumnSummary = null;
        _this.styleHeaderRow = null;
        _this.styleSeriesRow = null;
        _this.styleSummaryRow = null;
        _this.styleSeriesColumn = null;
        _this.styleSummaryColumn = null;
        _this.propertyChanged = null;
        _this.b8 = null;
        _this.b7 = null;
        _this.ca = null;
        _this.b9 = null;
        _this.a5 = null;
        _this.ib = null;
        _this._externalObject = null;
        _this.bu = false;
        _this.bv = false;
        _this.ao = new DataLegendContent();
        _this.cc = null;
        _this.cd = new List$1(DataLegendSeriesContext.$, 0);
        _this.b6 = new Dictionary$2(Number_$type, DataLegendColumn.$, 0);
        _this.cr = 0;
        _this.ak = null;
        _this.al = null;
        _this.cx = "";
        _this.ai = null;
        _this.aj = null;
        _this.ib = Rect.empty;
        _this.bx = true;
        _this.ab = XamDataLegend.$;
        _this.a5 = _this.a4();
        return _this;
    }
    Object.defineProperty(XamDataLegend.prototype, "cl", {
        get: function () {
            return this.ch;
        },
        set: function (a) {
            var b = this.ch;
            this.ch = a;
            if (b != this.ch) {
                this.fx("ActualCursorPositionX", b, this.ch);
            }
        },
        enumerable: false,
        configurable: true
    });
    Object.defineProperty(XamDataLegend.prototype, "cm", {
        get: function () {
            return this.ci;
        },
        set: function (a) {
            var b = this.ci;
            this.ci = a;
            if (b != this.ci) {
                this.fx("ActualCursorPositionY", b, this.ci);
            }
        },
        enumerable: false,
        configurable: true
    });
    Object.defineProperty(XamDataLegend.prototype, "cn", {
        get: function () {
            return this.cj;
        },
        set: function (a) {
            var b = this.cj;
            this.cj = a;
            this.fx("ActualPixelScalingRatio", b, this.cj);
        },
        enumerable: false,
        configurable: true
    });
    Object.defineProperty(XamDataLegend.prototype, "bt", {
        get: function () {
            return this.bj;
        },
        set: function (a) {
            var b = this.bj;
            if (typeof a === 'string') {
                a = FontUtil.getFontInfoFromString(this.a5.ah, a);
            }
            this.bj = a;
            if (b != this.bj) {
                this.fx("ValueTextStyle", b, this.bj);
            }
        },
        enumerable: false,
        configurable: true
    });
    Object.defineProperty(XamDataLegend.prototype, "bl", {
        get: function () {
            return this.bb;
        },
        set: function (a) {
            var b = this.bb;
            if (typeof a === 'string') {
                a = FontUtil.getFontInfoFromString(this.a5.ah, a);
            }
            this.bb = a;
            if (b != this.bb) {
                this.fx("HeaderTextStyle", b, this.bb);
            }
        },
        enumerable: false,
        configurable: true
    });
    Object.defineProperty(XamDataLegend.prototype, "bo", {
        get: function () {
            return this.be;
        },
        set: function (a) {
            var b = this.be;
            if (typeof a === 'string') {
                a = FontUtil.getFontInfoFromString(this.a5.ah, a);
            }
            this.be = a;
            if (b != this.be) {
                this.fx("SummaryTitleTextStyle", b, this.be);
            }
        },
        enumerable: false,
        configurable: true
    });
    Object.defineProperty(XamDataLegend.prototype, "bq", {
        get: function () {
            return this.bg;
        },
        set: function (a) {
            var b = this.bg;
            if (typeof a === 'string') {
                a = FontUtil.getFontInfoFromString(this.a5.ah, a);
            }
            this.bg = a;
            if (b != this.bg) {
                this.fx("SummaryValueTextStyle", b, this.bg);
            }
        },
        enumerable: false,
        configurable: true
    });
    Object.defineProperty(XamDataLegend.prototype, "bn", {
        get: function () {
            return this.bd;
        },
        set: function (a) {
            var b = this.bd;
            if (typeof a === 'string') {
                a = FontUtil.getFontInfoFromString(this.a5.ah, a);
            }
            this.bd = a;
            if (b != this.bd) {
                this.fx("SummaryLabelTextStyle", b, this.bd);
            }
        },
        enumerable: false,
        configurable: true
    });
    Object.defineProperty(XamDataLegend.prototype, "bp", {
        get: function () {
            return this.bf;
        },
        set: function (a) {
            var b = this.bf;
            if (typeof a === 'string') {
                a = FontUtil.getFontInfoFromString(this.a5.ah, a);
            }
            this.bf = a;
            if (b != this.bf) {
                this.fx("SummaryUnitsTextStyle", b, this.bf);
            }
        },
        enumerable: false,
        configurable: true
    });
    Object.defineProperty(XamDataLegend.prototype, "bs", {
        get: function () {
            return this.bi;
        },
        set: function (a) {
            var b = this.bi;
            if (typeof a === 'string') {
                a = FontUtil.getFontInfoFromString(this.a5.ah, a);
            }
            this.bi = a;
            if (b != this.bi) {
                this.fx("UnitsTextStyle", b, this.bi);
            }
        },
        enumerable: false,
        configurable: true
    });
    Object.defineProperty(XamDataLegend.prototype, "br", {
        get: function () {
            return this.bh;
        },
        set: function (a) {
            var b = this.bh;
            if (typeof a === 'string') {
                a = FontUtil.getFontInfoFromString(this.a5.ah, a);
            }
            this.bh = a;
            if (b != this.bh) {
                this.fx("TitleTextStyle", b, this.bh);
            }
        },
        enumerable: false,
        configurable: true
    });
    Object.defineProperty(XamDataLegend.prototype, "bm", {
        get: function () {
            return this.bc;
        },
        set: function (a) {
            var b = this.bc;
            if (typeof a === 'string') {
                a = FontUtil.getFontInfoFromString(this.a5.ah, a);
            }
            this.bc = a;
            if (b != this.bc) {
                this.fx("LabelTextStyle", b, this.bc);
            }
        },
        enumerable: false,
        configurable: true
    });
    Object.defineProperty(XamDataLegend.prototype, "pixelScalingRatio", {
        get: function () {
            return this.ck;
        },
        set: function (a) {
            var b = this.ck;
            this.ck = a;
            this.fx("PixelScalingRatio", b, this.ck);
        },
        enumerable: false,
        configurable: true
    });
    XamDataLegend.prototype.exportSerializedVisualData = function () {
        var a = this.exportVisualData();
        return a.serialize();
    };
    XamDataLegend.prototype.cp = function (a, b) {
        var c = Math.max(b.left, a);
        var d = Math.max(b.right, a);
        var e = Math.max(b.right, a);
        return Math.min(b.top, a);
    };
    XamDataLegend.prototype.co = function (a, b) {
        return Math.min(b.left, a);
    };
    XamDataLegend.prototype.ia = function (a, b) {
        var c = Rect.l_op_Equality(a, null) || a.isEmpty || !Extensions.b(a);
        var d = Rect.l_op_Equality(b, null) || b.isEmpty || !Extensions.b(b);
        if (c) {
            return b;
        }
        if (d) {
            return a;
        }
        if (c && c) {
            return Rect.empty;
        }
        var e = Math.min(a.top, b.top);
        var f = Math.min(a.left, b.left);
        var g = Math.max(a.right, b.right);
        var h = Math.max(a.bottom, b.bottom);
        return new Rect(0, f, e, g - f, h - e);
    };
    XamDataLegend.prototype.exportVisualData = function () {
        var e_1, _a;
        var a = new DataLegendVisualData();
        a.width = this.ao.d;
        a.height = this.ao.c;
        if (this.a5 == null) {
            return a;
        }
        var b = -1;
        var c = -1;
        var d = -1;
        var e = -1;
        var f = this.a5.ab;
        var g = this.a5.z;
        var h = this.a5.ad;
        var i = this.a5.ac;
        if (f.count < this.ao.b.count) {
            return a;
        }
        if (Rect.l_op_Equality(this.ib, null) || this.ib.isEmpty) {
            a.viewport = null;
        }
        else {
            a.viewport = new RectData(0, 0, this.ib.width, this.ib.height);
        }
        for (var j = 0; j < this.ao.b.count; j++) {
            var k = this.ao.b._inner[j];
            var l = new DataLegendVisualDataRow();
            l.seriesIndex = k.e;
            l.rowMarginTop = k.w.top;
            l.rowMarginBottom = k.w.bottom;
            l.rowMarginRight = k.w.right;
            l.rowMarginLeft = k.w.left;
            var m = Rect.empty;
            if (k.b) {
                if (Extensions.b(k.s) && f.count > (b + 1)) {
                    b++;
                    var n = f._inner[b];
                    var o = this.bk(n, k.i);
                    var p = new DataLegendVisualDataColumn();
                    p.bounds = RectData.b(k.s);
                    p.text = n.al;
                    p.textColor = AppearanceHelper.b(k.q);
                    p.marginTop = k.x.top;
                    p.marginLeft = k.x.left;
                    p.marginRight = k.x.right;
                    p.marginBottom = k.x.bottom;
                    this.f7(p, o);
                    l.columns.add(p);
                    m = this.ia(m, k.s);
                }
                try {
                    for (var _b = (e_1 = void 0, __values(fromEnum(k.k))), _c = _b.next(); !_c.done; _c = _b.next()) {
                        var q = _c.value;
                        if (Extensions.b(q.ab) && g.count > (c + 1)) {
                            c++;
                            var r = g._inner[c];
                            var s = this.bk(r, q.g);
                            var t = new DataLegendVisualDataColumn();
                            t.bounds = RectData.b(q.ab);
                            t.text = r.al;
                            t.textColor = AppearanceHelper.b(q.y);
                            t.marginTop = q.ak.top;
                            t.marginLeft = q.ak.left;
                            t.marginRight = q.ak.right;
                            t.marginBottom = q.ak.bottom;
                            this.f7(t, s);
                            l.columns.add(t);
                            m = this.ia(m, q.ab);
                        }
                        if (Extensions.b(q.ad) && h.count > (d + 1)) {
                            d++;
                            var u = h._inner[d];
                            var v = this.bk(u, q.i);
                            var w = new DataLegendVisualDataColumn();
                            w.bounds = RectData.b(q.ad);
                            w.text = u.al;
                            w.textColor = AppearanceHelper.b(q.aa);
                            w.marginTop = q.am.top;
                            w.marginLeft = q.am.left;
                            w.marginRight = q.am.right;
                            w.marginBottom = q.am.bottom;
                            this.f7(w, v);
                            l.columns.add(w);
                            m = this.ia(m, q.ad);
                        }
                        if (Extensions.b(q.ac) && i.count > (e + 1)) {
                            e++;
                            var x = i._inner[e];
                            var y = this.bk(x, q.h);
                            var z = new DataLegendVisualDataColumn();
                            z.bounds = RectData.b(q.ac);
                            z.text = q.m ? q.u : null;
                            z.textColor = AppearanceHelper.b(q.z);
                            z.marginTop = q.al.top;
                            z.marginLeft = q.al.left;
                            z.marginRight = q.al.right;
                            z.marginBottom = q.al.bottom;
                            this.f7(z, y);
                            l.columns.add(z);
                            m = this.ia(m, q.ac);
                        }
                    }
                }
                catch (e_1_1) {
                    e_1 = { error: e_1_1 };
                }
                finally {
                    try {
                        if (_c && !_c.done && (_a = _b.return))
                            _a.call(_b);
                    }
                    finally {
                        if (e_1)
                            throw e_1.error;
                    }
                }
                if (k.j) {
                    m = this.ia(m, k.r);
                    l.badgeBounds = RectData.b(k.r);
                    l.badgeMarginTop = k.v.top;
                    l.badgeMarginBottom = k.v.bottom;
                    l.badgeMarginRight = k.v.right;
                    l.badgeMarginLeft = k.v.left;
                    if (k.e >= 0 && k.e < this.cc.count) {
                        var aa = this.cc._inner[k.e];
                        l.badgeShape = aa.getDataLegendBadgeShapeAndMarker();
                    }
                    else {
                        l.badgeShape = "None";
                    }
                }
                l.rowBounds = RectData.b(m);
            }
            a.rows.add(l);
        }
        return a;
    };
    XamDataLegend.prototype.f7 = function (a, b) {
        if (b != null) {
            if (b.n != null) {
                a.fontFamily = b.n;
            }
            if (!isNaN_(b.d)) {
                a.fontSize = b.d;
            }
            a.fontWeight = stringIsNullOrEmpty(b.s) ? "Normal" : b.s;
            a.fontStyle = stringIsNullOrEmpty(b.q) ? "Normal" : b.q;
            if (b.o != null) {
                a.fontStretch = b.q;
            }
        }
    };
    XamDataLegend.prototype.bk = function (a, b) {
        var c = a.dataContext;
        if (c != null) {
            b = a.dataContext;
        }
        if (b == null || stringIsNullOrEmpty(b.fontString)) {
            return b;
        }
        else {
            return FontUtil.toFontInfo(this.a5.ah, b.fontString);
        }
    };
    XamDataLegend.prototype.a0 = function (a) {
        if (this.calculateColumnSummary != null) {
            var b = new DataLegendSummaryEventArgs(a.a, a.d);
            b.summaryValue = a.c;
            this.calculateColumnSummary(this, b);
            a.c = b.summaryValue;
            a.f = b.summaryUnits;
            a.e = b.summaryLabel;
        }
        return a;
    };
    XamDataLegend.prototype.a6 = function () {
        switch (this.a1) {
            case 0:
            case 1: return new DataLegendSummaryCalculationTotal();
            case 2: return new DataLegendSummaryCalculationAverage();
            case 3: return new DataLegendSummaryCalculationMin();
            case 4: return new DataLegendSummaryCalculationMax();
            case 5: return new DataLegendSummaryCalculationEmpty();
            default: return new DataLegendSummaryCalculationEmpty();
        }
    };
    XamDataLegend.prototype.gb = function (a) {
        if (this.styleSummaryRow != null) {
            var b = this.ay(a);
            this.styleSummaryRow(this, b);
            this.f8(a, b);
        }
        if (a.b && a.k != null && this.styleSummaryColumn != null) {
            for (var c = 0; c < a.k.count; c++) {
                var d = this.ax(a.k._inner[c]);
                d.d = a.e;
                d.f = a.m;
                d.c = c;
                this.styleSummaryColumn(this, d);
                this.gc(a.k._inner[c], d);
            }
        }
    };
    XamDataLegend.prototype.ga = function (a) {
        if (this.styleSeriesRow != null) {
            var b = this.ay(a);
            this.styleSeriesRow(this, b);
            this.f8(a, b);
        }
        if (a.b && a.k != null && this.styleSeriesColumn != null) {
            for (var c = 0; c < a.k.count; c++) {
                var d = this.ax(a.k._inner[c]);
                d.d = a.e;
                d.f = a.m;
                d.c = c;
                this.styleSeriesColumn(this, d);
                this.gc(a.k._inner[c], d);
            }
        }
    };
    XamDataLegend.prototype.f9 = function (a) {
        if (this.styleHeaderRow != null) {
            var b = this.ay(a);
            this.styleHeaderRow(this, b);
            this.f8(a, b);
        }
    };
    XamDataLegend.prototype.ay = function (a) {
        var b = new DataLegendStylingRowEventArgs();
        b.f = a.n;
        b.g = a.q;
        b.a = a.h;
        b.b = a.j;
        b.c = a.b;
        b.d = a.e;
        b.e = a.m;
        return b;
    };
    XamDataLegend.prototype.f8 = function (a, b) {
        a.n = b.f;
        a.q = b.g;
        a.h = b.a;
        a.j = b.b;
        a.b = b.c;
    };
    XamDataLegend.prototype.ax = function (a) {
        var b = new DataLegendStylingColumnEventArgs();
        b.e = a.t;
        b.j = a.y;
        b.g = a.u;
        b.k = a.z;
        b.i = a.w;
        b.l = a.aa;
        b.b = a.r;
        b.h = a.v;
        b.a = a.f;
        return b;
    };
    XamDataLegend.prototype.gc = function (a, b) {
        a.y = b.j;
        a.t = b.e;
        a.j = !stringIsNullOrEmpty(a.t);
        a.u = b.g;
        a.z = b.k;
        a.m = !stringIsNullOrEmpty(a.u);
        a.w = b.i;
        a.aa = b.l;
    };
    XamDataLegend.prototype.f0 = function (a, b, c) {
        var _this = this;
        switch (a) {
            case XamDataLegend.$$p[19]:
                this.bx = c;
                break;
            case XamDataLegend.$$p[15]:
            case XamDataLegend.$$p[3]:
                this.gg();
                break;
            case XamDataLegend.$$p[14]:
            case XamDataLegend.$$p[2]:
                this.gf();
                break;
            case XamDataLegend.$$p[32]:
                var d = c;
                var e = b;
                this.fy(e, d);
                break;
            case XamDataLegend.$$p[30]:
                if (this.b0(this.targetCursorPositionX)) {
                    this.cl = this.targetCursorPositionX;
                }
                break;
            case XamDataLegend.$$p[31]:
                if (this.b0(this.targetCursorPositionY)) {
                    this.cm = this.targetCursorPositionY;
                }
                break;
            case XamDataLegend.$$p[46]:
            case XamDataLegend.$$p[45]:
                if (!stringIsNullOrEmpty(this.e5)) {
                    this.ak = ((function () {
                        var $ret = new BindingFormatter();
                        $ret.j = _this.e5;
                        $ret.d = _this.ah;
                        return $ret;
                    })());
                }
                else {
                    this.ak = null;
                }
                break;
            case XamDataLegend.$$p[7]:
            case XamDataLegend.$$p[6]:
                if (!stringIsNullOrEmpty(this.dc)) {
                    this.ai = ((function () {
                        var $ret = new BindingFormatter();
                        $ret.j = _this.dc;
                        $ret.d = _this.ag;
                        return $ret;
                    })());
                }
                else {
                    this.ai = null;
                }
                break;
            case "PixelScalingRatio":
                if (isNaN_(this.cn)) {
                    this.a5.au();
                }
                else {
                    this.cn = this.pixelScalingRatio;
                }
                break;
            case "ActualPixelScalingRatio":
                this.a5.a5(c);
                break;
        }
        this.f2();
    };
    XamDataLegend.prototype.fx = function (a, b, c) {
        this.f0(a, b, c);
        if (this.propertyChanged != null) {
            this.propertyChanged(this, new PropertyChangedEventArgs(a));
        }
    };
    XamDataLegend.prototype.fy = function (a, b) {
        this.a7 = b;
        if (a != null) {
            a.detachDataLegend(this);
        }
        if (b != null) {
            b.attachDataLegend(this);
            if (isNaN_(this.targetCursorPositionX)) {
                this.cl = 1;
            }
            if (isNaN_(this.targetCursorPositionY)) {
                this.cm = 0.5;
            }
        }
    };
    XamDataLegend.prototype.gg = function () {
        this.ca = this.cb(this.includedSeries);
        this.b9 = this.cb(this.excludedSeries);
    };
    XamDataLegend.prototype.gf = function () {
        var e_2, _a, e_3, _b;
        this.b8 = this.cb(this.includedColumns);
        this.b7 = this.cb(this.excludedColumns);
        if (this.b8 != null) {
            var a = new List$1(String_$type, 1, this.b8.keys);
            try {
                for (var _c = __values(fromEnum(a)), _d = _c.next(); !_d.done; _d = _c.next()) {
                    var b = _d.value;
                    var c = b + ":";
                    var d = this.b8.item(b);
                    if (!this.b8.containsKey(c)) {
                        this.b8.addItem(c, d);
                    }
                }
            }
            catch (e_2_1) {
                e_2 = { error: e_2_1 };
            }
            finally {
                try {
                    if (_d && !_d.done && (_a = _c.return))
                        _a.call(_c);
                }
                finally {
                    if (e_2)
                        throw e_2.error;
                }
            }
            this.fg(this.b8);
        }
        if (this.b7 != null) {
            var e = new List$1(String_$type, 1, this.b7.keys);
            try {
                for (var _e = __values(fromEnum(e)), _f = _e.next(); !_f.done; _f = _e.next()) {
                    var f = _f.value;
                    var g = f + ":";
                    var h = this.b7.item(f);
                    if (!this.b7.containsKey(g)) {
                        this.b7.addItem(g, h);
                    }
                }
            }
            catch (e_3_1) {
                e_3 = { error: e_3_1 };
            }
            finally {
                try {
                    if (_f && !_f.done && (_b = _e.return))
                        _b.call(_e);
                }
                finally {
                    if (e_3)
                        throw e_3.error;
                }
            }
            this.fg(this.b7);
        }
    };
    XamDataLegend.prototype.fg = function (a) {
        var e_4, _a;
        var b = new List$1(String_$type, 1, a.keys);
        try {
            for (var _b = __values(fromEnum(b)), _c = _b.next(); !_c.done; _c = _b.next()) {
                var c = _c.value;
                var d = a.item(c);
                var e = c.toLowerCase();
                if (!a.containsKey(e)) {
                    a.addItem(e, d);
                }
                var f = c.toUpperCase();
                if (!a.containsKey(f)) {
                    a.addItem(f, d);
                }
                if (c.length > 0) {
                    var g = f.substr(0, 1) + e.substr(1);
                    if (!a.containsKey(g)) {
                        a.addItem(g, d);
                    }
                }
            }
        }
        catch (e_4_1) {
            e_4 = { error: e_4_1 };
        }
        finally {
            try {
                if (_c && !_c.done && (_a = _b.return))
                    _a.call(_b);
            }
            finally {
                if (e_4)
                    throw e_4.error;
            }
        }
    };
    XamDataLegend.prototype.cb = function (a) {
        if (a == null) {
            return null;
        }
        var b = new Dictionary$2(String_$type, Number_$type, 0);
        for (var c = 0; c < a.length; c++) {
            var d = a[c];
            if (!stringIsNullOrEmpty(d) && !b.containsKey(d.trim())) {
                b.addItem(d.trim(), b.count);
            }
        }
        return b;
    };
    XamDataLegend.prototype.b0 = function (a) {
        return a >= 0 && a <= 1;
    };
    XamDataLegend.prototype.notifyCursorPositionChanged = function (a) {
        var b = !isNaN_(this.targetCursorPositionX) || !isNaN_(this.targetCursorPositionY);
        var c = !isNaN_(a.x) && this.b0(a.x);
        var d = !isNaN_(a.y) && this.b0(a.y);
        if (!b && c && d) {
            this.cl = a.x;
            this.cm = a.y;
        }
    };
    XamDataLegend.prototype.notifySizeChanged = function () {
        this.a5.a3();
    };
    XamDataLegend.prototype.notifyVisualPropertiesChanged = function (a) {
    };
    XamDataLegend.prototype.notifySeriesCollectionChanged = function () {
        this.f2();
    };
    XamDataLegend.prototype.notifySeriesDataChanged = function () {
        if (this.bx) {
            this.f2();
        }
    };
    XamDataLegend.prototype.updatePropertyByName = function (a, b) {
        switch (a) {
            case XamDataLegend.$$p[15]:
                this.includedSeries = b;
                break;
            case XamDataLegend.$$p[3]:
                this.excludedSeries = b;
                break;
            case XamDataLegend.$$p[14]:
                this.includedColumns = b;
                break;
            case XamDataLegend.$$p[2]:
                this.excludedColumns = b;
                break;
            case XamDataLegend.$$p[39]:
                this.an = EnumUtil.getEnumValue(DataAbbreviationMode_$type, b);
                break;
            case XamDataLegend.$$p[42]:
                this.ct = typeGetValue(b);
                break;
            case XamDataLegend.$$p[43]:
                this.cu = typeGetValue(b);
                break;
            case XamDataLegend.$$p[44]:
                this.a3 = EnumUtil.getEnumValue(DataLegendValueMode_$type, b);
                break;
            case XamDataLegend.$$p[40]:
                this.ex = b;
                break;
            case XamDataLegend.$$p[47]:
                this.b3 = b;
                break;
            case XamDataLegend.$$p[46]:
                this.e5 = b;
                break;
            case XamDataLegend.$$p[45]:
                this.ah = b;
                break;
            case XamDataLegend.$$p[48]:
                this.ir = b;
                break;
            case XamDataLegend.$$p[49]:
                this.b4 = b;
                break;
            case XamDataLegend.$$p[53]:
                this.fe = b;
                break;
            case XamDataLegend.$$p[52]:
                this.b5 = b;
                break;
            case XamDataLegend.$$p[51]:
                this.is = b;
                break;
            case XamDataLegend.$$p[50]:
                this.h9 = b;
                break;
            case "ValueTextStyle":
                this.bt = b;
                break;
            case XamDataLegend.$$p[7]:
                this.dc = b;
                break;
            case XamDataLegend.$$p[6]:
                this.ag = b;
                break;
            case XamDataLegend.$$p[4]:
                this.c8 = b;
                break;
            case XamDataLegend.$$p[5]:
                this.ap = EnumUtil.getEnumValue(DataLegendHeaderDateMode_$type, b);
                break;
            case XamDataLegend.$$p[8]:
                this.aq = EnumUtil.getEnumValue(DataLegendHeaderTimeMode_$type, b);
                break;
            case XamDataLegend.$$p[13]:
                this.dh = b;
                break;
            case XamDataLegend.$$p[11]:
                this.h0 = b;
                break;
            case XamDataLegend.$$p[12]:
                this.ij = b;
                break;
            case XamDataLegend.$$p[9]:
                this.ii = b;
                break;
            case XamDataLegend.$$p[10]:
                this.bz = b;
                break;
            case "HeaderTextStyle":
                this.bl = b;
                break;
            case XamDataLegend.$$p[23]:
                this.h4 = b;
                break;
            case "SummaryTitleTextStyle":
                this.bo = b;
                break;
            case XamDataLegend.$$p[26]:
                this.a1 = EnumUtil.getEnumValue(DataLegendSummaryType_$type, b);
                break;
            case XamDataLegend.$$p[25]:
                this.d8 = b;
                break;
            case XamDataLegend.$$p[24]:
                this.im = b;
                break;
            case XamDataLegend.$$p[22]:
                this.il = b;
                break;
            case XamDataLegend.$$p[29]:
                this.h6 = b;
                break;
            case "SummaryValueTextStyle":
                this.bq = b;
                break;
            case XamDataLegend.$$p[21]:
                this.d3 = b;
                break;
            case XamDataLegend.$$p[20]:
                this.h3 = b;
                break;
            case "SummaryLabelTextStyle":
                this.bn = b;
                break;
            case XamDataLegend.$$p[28]:
                this.ee = b;
                break;
            case XamDataLegend.$$p[27]:
                this.h5 = b;
                break;
            case "SummaryUnitsTextStyle":
                this.bp = b;
                break;
            case XamDataLegend.$$p[0]:
                this.ih = b;
                break;
            case XamDataLegend.$$p[1]:
                this.a8 = EnumUtil.getEnumValue(LegendItemBadgeShape_$type, b);
                break;
            case XamDataLegend.$$p[35]:
                this.a2 = EnumUtil.getEnumValue(DataLegendUnitsMode_$type, b);
                break;
            case XamDataLegend.$$p[38]:
                this.er = b;
                break;
            case XamDataLegend.$$p[36]:
                this.h8 = b;
                break;
            case XamDataLegend.$$p[37]:
                this.ip = b;
                break;
            case "UnitsTextStyle":
                this.bs = b;
                break;
            case XamDataLegend.$$p[34]:
                this.io = b;
                break;
            case XamDataLegend.$$p[33]:
                this.h7 = b;
                break;
            case "TitleTextStyle":
                this.br = b;
                break;
            case XamDataLegend.$$p[16]:
                this.ar = EnumUtil.getEnumValue(DataLegendLabelMode_$type, b);
                break;
            case XamDataLegend.$$p[17]:
                this.h1 = b;
                break;
            case XamDataLegend.$$p[18]:
                this.ik = b;
                break;
            case "LabelTextStyle":
                this.bm = b;
                break;
        }
    };
    XamDataLegend.prototype.a4 = function () {
        return new DataLegendView(this);
    };
    XamDataLegend.prototype.destroy = function () {
        this.provideContainer(null);
    };
    Object.defineProperty(XamDataLegend.prototype, "externalObject", {
        get: function () {
            return this._externalObject;
        },
        set: function (a) {
            this._externalObject = a;
        },
        enumerable: false,
        configurable: true
    });
    XamDataLegend.prototype.flush = function () {
        this.a5.ar();
    };
    XamDataLegend.prototype.onAttachedToUI = function () {
        this.a5.a1();
    };
    XamDataLegend.prototype.onDetachedFromUI = function () {
        this.a5.a4();
    };
    XamDataLegend.prototype.provideContainer = function (a) {
        this.a5.a2(a);
    };
    XamDataLegend.prototype.f2 = function () {
        if (this.bu) {
            return;
        }
        this.bu = this.a5.w();
    };
    Object.defineProperty(XamDataLegend.prototype, "shouldOnDemandRender", {
        get: function () {
            return this.bv;
        },
        set: function (a) {
            this.bv = a;
        },
        enumerable: false,
        configurable: true
    });
    XamDataLegend.prototype.doRender = function (a, b) {
        if (this.ib.isEmpty) {
            var c = this.getDesiredSize();
            this.ib = new Rect(0, 0, 0, c.width, c.height);
        }
        this.f3(this.ao, true);
        this.a5.a7(a, b);
    };
    XamDataLegend.prototype.ensureUpdated = function () {
        var a = this.getDesiredSize();
    };
    XamDataLegend.prototype.fp = function () {
        if (!this.bu) {
            if (this.ao == null) {
                this.f2();
            }
            else {
                return;
            }
        }
        this.ge();
    };
    XamDataLegend.prototype.getDesiredSize = function () {
        this.fp();
        if (this.ao == null) {
            return new Size(1, 0, 0);
        }
        return new Size(1, this.ao.d, this.ao.c);
    };
    XamDataLegend.prototype.ge = function () {
        if (this.a7 == null) {
            this.fm();
            return;
        }
        var a = this.a7;
        var b = a.getDataLegendSeries();
        var c = this.cf(b);
        this.fr(c);
    };
    XamDataLegend.prototype.cf = function (a) {
        var e_5, _a;
        var b = new Dictionary$2(Number_$type, IDataLegendSeries_$type, 0);
        for (var c = 0; c < a.length; c++) {
            var d = a[c].title == null ? null : a[c].title.toString();
            var e = this.ca == null || this.ca.containsKey(a[c].dataLegendKey) || this.ca.containsKey(a[c].index.toString()) || this.ca.containsKey(d);
            var f = this.b9 != null && (this.b9.containsKey(a[c].dataLegendKey) || this.b9.containsKey(a[c].index.toString()) || this.b9.containsKey(d));
            if (a[c].isValueOverlay && (!e || this.ca == null)) {
                continue;
            }
            if (e && !f) {
                var g = this.cs(a[c]);
                b.addItem(g, a[c]);
            }
        }
        var h = new List$1(Number_$type, 1, b.keys);
        h.y();
        var i = new List$1(IDataLegendSeries_$type, 0);
        try {
            for (var _b = __values(fromEnum(h)), _c = _b.next(); !_c.done; _c = _b.next()) {
                var j = _c.value;
                i.add(b.item(j));
            }
        }
        catch (e_5_1) {
            e_5 = { error: e_5_1 };
        }
        finally {
            try {
                if (_c && !_c.done && (_a = _b.return))
                    _a.call(_b);
            }
            finally {
                if (e_5)
                    throw e_5.error;
            }
        }
        return i;
    };
    XamDataLegend.prototype.cs = function (a) {
        if (this.ca == null) {
            return a.index;
        }
        var b = a.dataLegendKey;
        if (this.ca.containsKey(b)) {
            return this.ca.item(b);
        }
        var c = a.index.toString();
        if (this.ca.containsKey(c)) {
            return this.ca.item(c);
        }
        var d = a.title == null ? null : a.title.toString();
        if (this.ca.containsKey(d)) {
            return this.ca.item(d);
        }
        return a.index;
    };
    XamDataLegend.prototype.fo = function () {
        this.bu = false;
        var a = new Size(1, 0, 0);
        if (this.ao != null) {
            a = new Size(1, this.ao.d, this.ao.c);
        }
        this.ge();
        var b = new Size(1, 0, 0);
        if (this.ao != null) {
            b = new Size(1, this.ao.d, this.ao.c);
        }
        if (!a.equals(b)) {
            this.a5.am(b.width, b.height);
        }
        this.f3(this.ao, this.bv);
    };
    XamDataLegend.prototype.fs = function (message_) {
    };
    XamDataLegend.prototype.f3 = function (a, b) {
        var c = new DataLegendRenderContext();
        for (var d = 0; d < a.b.count; d++) {
            var e = a.b._inner[d];
            this.f5(a, e, c);
        }
        this.a5.p.count = c.b;
        this.a5.q.count = c.c;
        this.a5.s.count = c.e;
        this.a5.r.count = c.d;
        this.a5.o.count = c.a;
        if (!b) {
            this.a5.aq(a);
        }
    };
    XamDataLegend.prototype.f5 = function (a, b, c) {
        var e_6, _a;
        if (b.t.width > 0 && b.t.height > 0 && !b.a && !b.d && b.j) {
            var d = this.a5.p.item(c.b);
            c.b += 1;
            this.f4(d, a, b, c);
        }
        this.a5.a9();
        if (!b.s.isEmpty && b.s.width > 0 && b.s.height > 0) {
            var e = this.a5.q.item(c.c);
            c.c += 1;
            this.f6(e, b.n, b.q, b.i, b.s);
        }
        try {
            for (var _b = __values(fromEnum(b.k)), _c = _b.next(); !_c.done; _c = _b.next()) {
                var f = _c.value;
                if (!f.ad.isEmpty && f.q()) {
                    var g = this.a5.s.item(c.e);
                    c.e += 1;
                    this.f6(g, f.w, f.aa, f.i, f.ad);
                }
                if (!f.ac.isEmpty && f.o() && f.m) {
                    var h = this.a5.r.item(c.d);
                    c.d += 1;
                    this.f6(h, f.u, f.z, f.h, f.ac);
                }
                if (!f.ab.isEmpty && f.l() && f.j) {
                    var i = this.a5.o.item(c.a);
                    c.a += 1;
                    this.f6(i, f.t, f.y, f.g, f.ab);
                }
            }
        }
        catch (e_6_1) {
            e_6 = { error: e_6_1 };
        }
        finally {
            try {
                if (_c && !_c.done && (_a = _b.return))
                    _a.call(_b);
            }
            finally {
                if (e_6)
                    throw e_6.error;
            }
        }
        this.a5.an();
    };
    XamDataLegend.prototype.f6 = function (a, b, c, d, e) {
        a.al = b;
        this.a5.a8(a, e.left, e.top);
        this.a5.ao(a, d);
        this.a5.ap(a, d);
        a.ao = c;
    };
    XamDataLegend.prototype.f4 = function (a, b, c, d) {
        a.ah = c.p;
        a.content = c.l;
        a.width = c.t.width;
        a.height = c.t.height;
        this.a5.a8(a, c.r.left, c.r.top);
    };
    XamDataLegend.prototype.fr = function (a) {
        var e_7, _a;
        if (this.by()) {
            this.ao.f();
            this.cc = a;
            this.cd.clear();
            this.cr = 0;
            this.b6.clear();
        }
        else {
            return;
        }
        for (var b = 0; b < a.count; b++) {
            var c = a._inner[b];
            var d = b;
            var e = typeCast(DataLegendSeriesContext.$, c.getDataLegendSeriesContextAt(this.cl, this.cm));
            if (e != null) {
                var f = new List$1(DataLegendSeriesValueInfo.$, 0);
                for (var g = 0; g < e.f.count; g++) {
                    var h = e.f._inner[g];
                    var i = this.b8 == null || this.b8.containsKey(h.p) || this.b8.containsKey(h.q) || this.b8.containsKey("ALL");
                    var j = this.b7 != null && (this.b7.containsKey(h.p) || this.b7.containsKey(h.q) || this.b7.containsKey("ALL"));
                    var k = this.b8 == null && this.b7 == null && h.k;
                    if (i && (!j && !k)) {
                        h.o = f.count;
                        f.add(h);
                        if (!this.b6.containsKey(h.o)) {
                            this.b6.addItem(h.o, new DataLegendColumn());
                        }
                        this.b6.item(h.o).i = h.o;
                        this.b6.item(h.o).d.q(d, h.r);
                        this.b6.item(h.o).b.q(d, h.q);
                        this.b6.item(h.o).e.q(d, h.l);
                        this.b6.item(h.o).c.q(d, h);
                        this.b6.item(h.o).h.add(d);
                    }
                }
                e.f = f;
                this.cd.add(e);
                this.cr = Math.max(this.cr, e.f.count);
            }
        }
        try {
            for (var _b = __values(fromEnum(this.b6.values)), _c = _b.next(); !_c.done; _c = _b.next()) {
                var l = _c.value;
                l.f.clear();
                l.a.clear();
                var m = l.e.p(l.h);
                var n = this.ce(m);
                for (var o = 0; o < n.count; o++) {
                    var p = n._inner[o];
                    var q = l.h._inner[o];
                    l.a.q(q, p);
                    var r = l.c.item(q);
                    var s = this.d1(p, r);
                    l.f.q(q, s);
                    var t = !stringIsNullOrEmpty(p.l);
                    if (t) {
                        l.g = true;
                    }
                }
            }
        }
        catch (e_7_1) {
            e_7 = { error: e_7_1 };
        }
        finally {
            try {
                if (_c && !_c.done && (_a = _b.return))
                    _a.call(_b);
            }
            finally {
                if (e_7)
                    throw e_7.error;
            }
        }
        this.fh(this.ao, a);
        for (var u = 0; u < a.count; u++) {
            this.gd(a._inner[u], this.a8);
            this.fi(this.ao, a._inner[u], u);
        }
        this.fj(this.ao, a);
        this.bw = this.b1();
        this.fl(this.ao);
    };
    XamDataLegend.prototype.b1 = function () {
        var a = false;
        for (var b = 0; b < this.ao.b.count; b++) {
            var c = this.ao.b._inner[b];
            if (c.c && c.j && c.h != 7) {
                a = true;
                break;
            }
        }
        return a;
    };
    XamDataLegend.prototype.fl = function (a) {
        var e_8, _a;
        var b = 0;
        var c = 0;
        for (var d = 0; d < a.b.count; d++) {
            var e = a.b._inner[d];
            this.ft(e);
        }
        var f = 0;
        var g = new Size(1, 0, 0);
        var h = new Size(1, 0, 0);
        var i = new Dictionary$2(Number_$type, Size.$, 0);
        var j = new Dictionary$2(Number_$type, Size.$, 0);
        var k = new Dictionary$2(Number_$type, Size.$, 0);
        try {
            for (var _b = __values(fromEnum(a.b)), _c = _b.next(); !_c.done; _c = _b.next()) {
                var l = _c.value;
                for (var m = 0; m < l.k.count; m++) {
                    var n = l.k._inner[m];
                    if (!i.containsKey(m)) {
                        i.addItem(m, new Size(1, 0, 0));
                    }
                    i.item(m, this.ig(i.item(m), n.aj, n.am));
                    if (!j.containsKey(m)) {
                        j.addItem(m, new Size(1, 0, 0));
                    }
                    j.item(m, this.ig(j.item(m), n.ah, n.al));
                    if (!k.containsKey(m)) {
                        k.addItem(m, new Size(1, 0, 0));
                    }
                    k.item(m, this.ig(k.item(m), n.af, n.ak));
                }
            }
        }
        catch (e_8_1) {
            e_8 = { error: e_8_1 };
        }
        finally {
            try {
                if (_c && !_c.done && (_a = _b.return))
                    _a.call(_b);
            }
            finally {
                if (e_8)
                    throw e_8.error;
            }
        }
        for (var o = 0; o < a.b.count; o++) {
            var p = a.b._inner[o];
            h = this.ie(h, p.t, p.v);
            g = this.ig(g, p.u, p.x);
            for (var q = 0; q < p.k.count; q++) {
                p.k._inner[q].ai = i.item(q);
                p.k._inner[q].ag = j.item(q);
                p.k._inner[q].ae = k.item(q);
            }
            if (p.d) {
                var r = p.u.width + p.x.left + p.x.right;
                f = Math.max(f, r + p.w.left);
            }
            else if (p.c) {
                var s = p.u.width + p.x.left + p.x.right;
                var t = p.t.width + p.v.left + p.v.right;
                f = Math.max(f, s + p.w.left + t);
            }
        }
        var u = 0;
        var v = 0;
        for (var w = 0; w < a.b.count; w++) {
            var x = a.b._inner[w];
            var y = this.ic(v, x, f, g, h);
            v = y.height;
            u = Math.max(u, y.width);
        }
        c = v;
        b = u;
        a.d = b;
        a.c = c;
    };
    XamDataLegend.prototype.ie = function (a, b, c) {
        return new Size(1, Math.max(a.width, b.width + c.left + c.right), Math.max(a.height, b.height + c.top + c.bottom));
    };
    XamDataLegend.prototype.ig = function (a, b, c) {
        return new Size(1, Math.max(a.width, b.width + c.left + c.right), Math.max(a.height, b.height + c.top + c.bottom));
    };
    XamDataLegend.prototype.ic = function (a, b, c, d, e) {
        var e_9, _a, e_10, _b;
        var f = 0;
        var g = 0;
        g = Math.max(b.t.height, g);
        g = Math.max(b.u.height, g);
        try {
            for (var _c = __values(fromEnum(b.k)), _d = _c.next(); !_d.done; _d = _c.next()) {
                var h = _d.value;
                g = Math.max(h.aj.height, g);
                if (h.m) {
                    g = Math.max(h.ah.height, g);
                }
                if (h.j) {
                    g = Math.max(h.af.height, g);
                }
            }
        }
        catch (e_9_1) {
            e_9 = { error: e_9_1 };
        }
        finally {
            try {
                if (_d && !_d.done && (_a = _c.return))
                    _a.call(_c);
            }
            finally {
                if (e_9)
                    throw e_9.error;
            }
        }
        f += b.w.left;
        a += b.w.top;
        if (!b.a && !b.d && this.bw) {
            f += b.v.left;
            var i = 0;
            if (g > b.t.height) {
                i = (g - b.t.height) / 2;
            }
            b.r = new Rect(0, f, a + i, b.t.width, b.t.height);
            f += (b.r.width) + b.v.right;
        }
        else {
            b.r = new Rect(0, 0, 0, 0, 0);
        }
        f += b.x.left;
        var j = 0;
        if (g > b.u.height) {
            j = (g - b.u.height) / 2;
        }
        b.s = new Rect(0, f, a + j, b.u.width + b.x.right, b.u.height);
        f = Math.max(c, b.s.right);
        try {
            for (var _e = __values(fromEnum(b.k)), _f = _e.next(); !_f.done; _f = _e.next()) {
                var k = _f.value;
                var l = " C=" + k.s + " SR=" + numberToString2(f, "000");
                if ((k.l() && k.j) && k.ae.width > 0) {
                    var m = 0;
                    if (g > k.af.height) {
                        m = (g - k.af.height) / 2;
                    }
                    k.ab = new Rect(0, f + k.ak.left, a + m, k.af.width, k.af.height);
                    f += k.ae.width;
                    l += " label L=" + numberToString2(k.ab.left, "000") + " R=" + numberToString2(k.ab.right, "000");
                }
                if (k.q()) {
                    l += " v MW=" + numberToString2(k.ai.width, "000");
                    f += k.am.left;
                    f += (k.ai.width - (k.aj.width + k.am.right));
                    var n = 0;
                    if (g > k.aj.height) {
                        n = (g - k.aj.height) / 2;
                    }
                    k.ad = new Rect(0, f, a + n, k.aj.width, k.aj.height);
                    l += " v ML=" + numberToString2(k.am.left, "00") + " MR=" + numberToString2(k.am.right, "00");
                    l += " v BL=" + numberToString2(k.ad.left, "000") + " BR=" + numberToString2(k.ad.right, "000");
                    f += k.ad.width;
                    f += k.am.right;
                }
                if ((k.o() && k.m) && k.ag.width > 0) {
                    var o = 0;
                    if (g > k.ah.height) {
                        o = (g - k.ah.height) / 2;
                    }
                    k.ac = new Rect(0, f + k.al.left, a + o, k.ah.width, k.ah.height);
                    f += k.ag.width;
                    l += " unit L=" + numberToString2(k.ac.left, "000") + " R=" + numberToString2(k.ac.right, "000");
                }
                this.fs("maxRight " + numberToString2(c, "0") + l);
            }
        }
        catch (e_10_1) {
            e_10 = { error: e_10_1 };
        }
        finally {
            try {
                if (_f && !_f.done && (_b = _e.return))
                    _b.call(_e);
            }
            finally {
                if (e_10)
                    throw e_10.error;
            }
        }
        f += b.w.right;
        a += g;
        a += b.w.bottom;
        return new Size(1, f, a);
    };
    XamDataLegend.prototype.ft = function (a) {
        var e_11, _a;
        a.u = a.n == null ? new Size(1, 0, 0) : this.a5.bu(a.n, a.i);
        try {
            for (var _b = __values(fromEnum(a.k)), _c = _b.next(); !_c.done; _c = _b.next()) {
                var b = _c.value;
                b.aj = b.w == null ? new Size(1, 0, 0) : this.a5.bu(b.w, b.i);
                b.ah = b.u == null ? new Size(1, 0, 0) : this.a5.bu(b.u, b.h);
                b.af = b.t == null ? new Size(1, 0, 0) : this.a5.bu(b.t, b.g);
            }
        }
        catch (e_11_1) {
            e_11 = { error: e_11_1 };
        }
        finally {
            try {
                if (_c && !_c.done && (_a = _b.return))
                    _a.call(_b);
            }
            finally {
                if (e_11)
                    throw e_11.error;
            }
        }
    };
    XamDataLegend.prototype.d0 = function (a, b, c, d) {
        if (this.a2 == 2) {
            return null;
        }
        var e = "";
        if (stringIsNullOrEmpty(this.er)) {
            e = b;
        }
        else {
            e = this.er;
        }
        if (d) {
            if (stringIsNullOrEmpty(e)) {
                e = c;
            }
            else {
                e = c + e;
            }
        }
        var f = this.b6.item(a).d;
        var g = this.b6.item(a).g;
        if (g && stringIsNullOrEmpty(e)) {
            e = " ";
        }
        else if (f.count > 0 && stringIsNullOrEmpty(e)) {
            e = " ";
        }
        else if (!d) {
            return null;
        }
        return e;
    };
    XamDataLegend.prototype.dx = function (a, b, c) {
        if (this.ar == 2) {
            return null;
        }
        var d = this.cr > 1;
        var e = this.ar == 1;
        var f = this.b6.item(a).b.count > 0;
        if (f && (d || e)) {
            if (stringIsNullOrEmpty(b)) {
                return " ";
            }
            else if (c) {
                return b;
            }
        }
        return null;
    };
    XamDataLegend.prototype.fj = function (a, b) {
        var e_12, _a, e_13, _b;
        if (this.a1 == 5) {
            return;
        }
        if (b == null || b.count <= 1) {
            return;
        }
        var c = new Dictionary$2(Number_$type, DataLegendSummaryColumn.$, 0);
        var d = 0;
        var e = new List$1(DataLegendSeriesGroup_$type, 0);
        try {
            for (var _c = __values(fromEnum(this.cd)), _d = _c.next(); !_d.done; _d = _c.next()) {
                var f = _d.value;
                d = Math.max(d, f.f.count);
                if (!e.contains(f.b)) {
                    e.add(f.b);
                }
                for (var g = 0; g < f.f.count; g++) {
                    var h = f.f._inner[g];
                    if (!c.containsKey(g)) {
                        c.addItem(g, new DataLegendSummaryColumn());
                    }
                    var i = c.item(g);
                    i.n = h.n;
                    i.m = h.m;
                    i.e = h.e;
                    i.h = h.h;
                    i.f = h.f;
                    i.f = h.g;
                    i.d = h.d;
                    i.x = h.x;
                    i.ai(h.l);
                    i.ag(h.q);
                    i.ah(h.r);
                    if (stringIsNullOrEmpty(i.t)) {
                        i.t = h.t;
                    }
                    if (stringIsNullOrEmpty(i.u)) {
                        i.u = h.u;
                    }
                    if (stringIsNullOrEmpty(i.v)) {
                        i.v = h.v;
                    }
                    if (stringIsNullOrEmpty(i.w)) {
                        i.w = h.w;
                    }
                    if (stringIsNullOrEmpty(i.p)) {
                        i.p = h.p;
                    }
                }
            }
        }
        catch (e_12_1) {
            e_12 = { error: e_12_1 };
        }
        finally {
            try {
                if (_d && !_d.done && (_a = _c.return))
                    _a.call(_c);
            }
            finally {
                if (e_12)
                    throw e_12.error;
            }
        }
        if (this.a1 == 0) {
            if (e.count > 1) {
                return;
            }
            if (!e.contains(0)) {
                return;
            }
        }
        var j = this.a6();
        var k = new DataLegendRowInfo(this.a5, true, false, -1);
        k.n = this.d8 != null ? this.d8 : j.title;
        k.q = this.h4 || k.q;
        k.i = this.bo || k.i;
        for (var l = 0; l < d; l++) {
            var m = c.item(l);
            var n = j.calculate(m.aa, m.p);
            n = this.a0(n);
            var o = this.an;
            var p = o == 0 || o == 2 || o == 8;
            var q = -1;
            try {
                for (var _e = (e_13 = void 0, __values(fromEnum(this.b6.item(l).a.values))), _f = _e.next(); !_f.done; _f = _e.next()) {
                    var r = _f.value;
                    if (r.b()) {
                        q = Math.max(q, r.h);
                        if (p) {
                            o = r.a;
                        }
                    }
                }
            }
            catch (e_13_1) {
                e_13 = { error: e_13_1 };
            }
            finally {
                try {
                    if (_f && !_f.done && (_b = _e.return))
                        _b.call(_e);
                }
                finally {
                    if (e_13)
                        throw e_13.error;
                }
            }
            var s = this.cu >= 0 ? this.cu : q;
            var t = this.ct >= 0 ? this.ct : q;
            var u = this.am(n.c, o, s, t);
            u.i = s;
            u.h = t;
            var v = this.d1(u, m);
            var w = new DataLegendRowCell(this.a5, true, false, -1);
            w.s = k.k.count;
            w.t = this.dx(w.s, " ", m.b);
            if (!stringIsNullOrEmpty(this.d3)) {
                w.t = this.d3;
            }
            if (n.e != null) {
                w.t = n.e;
            }
            w.j = !stringIsNullOrEmpty(w.t);
            w.y = this.h3 || w.y;
            w.g = this.bn || w.g;
            w.w = v;
            w.i = this.bq || w.i;
            w.aa = this.h2(this.h6, w.aa, null);
            w.r = n.c;
            w.f = u.a;
            w.v = m.p;
            var x = m.z.length >= 1 ? m.z[0] : " ";
            w.u = this.d0(w.s, x, u.l, m.d);
            if (n.f != null) {
                w.u = n.f;
            }
            w.m = !stringIsNullOrEmpty(w.u);
            w.z = this.h5 || w.z;
            w.h = this.bp || w.h;
            k.k.add(w);
        }
        this.gb(k);
        if (k.b) {
            this.fk(k);
            this.fz(k);
            a.e(k);
        }
    };
    XamDataLegend.prototype.am = function (a, b, c, d) {
        if (b == 8 || b == 0) {
            b = this.an;
        }
        if (d < 0) {
            d = this.ct;
        }
        if (c < 0) {
            c = this.cu;
        }
        return DataAbbreviator.a(a, b, c, d);
    };
    XamDataLegend.prototype.cq = function (a, b, c, d) {
        return this.am(a, b, c, d).d;
    };
    XamDataLegend.prototype.c7 = function (a, b, c, d) {
        return this.am(a, b, c, d).l;
    };
    XamDataLegend.prototype.c6 = function (a, b, c, d) {
        var e = this.am(a, b, c, d);
        return e.m + e.l;
    };
    XamDataLegend.prototype.ce = function (a) {
        var b = this.cu;
        var c = this.ct;
        var d = this.an;
        var e = DataAbbreviator.h(a, d, b, c);
        return e;
    };
    XamDataLegend.prototype.cg = function (a) {
        var b = new List$1(Number_$type, 0);
        if (a < 0) {
            return b;
        }
        for (var c = 0; c < this.cd.count; c++) {
            var d = this.cd._inner[c];
            if (d.f.count > a) {
                var e = d.f._inner[a].l;
                if (!isNaN_(e)) {
                    b.add(e);
                }
            }
        }
        return b;
    };
    XamDataLegend.prototype.fk = function (a) {
    };
    XamDataLegend.prototype.h2 = function (a, b, c) {
        if (a != null) {
            return a;
        }
        if (this.b5 && c != null) {
            return c;
        }
        return b;
    };
    XamDataLegend.prototype.dy = function (a, b) {
        return stringIsNullOrEmpty(a) ? b : a;
    };
    XamDataLegend.prototype.d1 = function (a, b) {
        var c = a.d;
        if (b == null || isNaN_(c) || isInfinity(c)) {
            return this.fe;
        }
        var d;
        var e = b.d ? a.d : a.g;
        if (this.ak != null) {
            d = this.ak.i(e);
        }
        else {
            var f = this.a3;
            if (f == 0) {
                f = 1;
            }
            var g = new NumberFormatSpecifier();
            g.useGrouping = this.b3;
            g.locale = this.dy(this.ex, null);
            g.currencyCode = this.ez;
            if (b.d) {
                g.minimumFractionDigits = a.i;
                g.maximumFractionDigits = a.h;
                if (b.n >= 0 && b.n > a.i) {
                    g.minimumFractionDigits = b.n;
                }
                else if (this.cu >= 0) {
                    g.minimumFractionDigits = this.cu;
                }
                if (b.m >= 0 && b.m > a.h) {
                    g.maximumFractionDigits = b.m;
                }
                else if (this.ct >= 0) {
                    g.maximumFractionDigits = this.ct;
                }
            }
            else {
                g.minimumFractionDigits = b.n;
                g.maximumFractionDigits = b.m;
            }
            if (g.minimumFractionDigits > g.maximumFractionDigits) {
                g.maximumFractionDigits = g.minimumFractionDigits;
            }
            if (f == 2 && b.e) {
                g.style = "currency";
            }
            if (this.al == null) {
                this.al = new BindingFormatter();
            }
            this.al.j = "{0}";
            this.al.d = [g];
            d = this.al.i(e);
            if (e > 0) {
                d = b.v + d;
            }
            else if (e < 0) {
                d = b.t + d;
            }
            if (e >= 0) {
                d += b.w;
            }
            else {
                d += b.u;
            }
        }
        return d;
    };
    XamDataLegend.prototype.fi = function (a, b, c) {
        if (this.b4 == false) {
            return;
        }
        var d = this.cd._inner[c];
        var e = this.dz(b);
        var f = new DataLegendRowInfo(this.a5, false, false, c);
        f.f = d.a();
        f.m = e;
        f.n = e;
        f.q = this.h7 || f.q;
        f.i = this.br || f.i;
        for (var g = 0; g < d.f.count; g++) {
            var h = d.f._inner[g];
            var i = this.b6.item(g).a.item(c);
            var j = this.b6.item(g).f.item(c);
            var k = new DataLegendRowCell(this.a5, false, false, c);
            k.s = f.k.count;
            k.i = this.bt || k.i;
            k.w = j;
            k.aa = this.h2(this.h9, k.aa, h.x);
            k.v = h.p;
            k.r = h.l;
            k.f = i.a;
            k.u = this.d0(k.s, h.r, i.l, h.d);
            k.m = !stringIsNullOrEmpty(k.u);
            k.z = this.h8 || k.z;
            k.h = this.bs || k.h;
            k.t = this.dx(k.s, h.q, h.b);
            k.j = !stringIsNullOrEmpty(k.t);
            k.y = this.h1 || k.y;
            k.g = this.bm || k.g;
            f.k.add(k);
        }
        f.h = this.a9(b);
        this.fk(f);
        this.fz(f);
        this.ga(f);
        if (f.b) {
            if (f.j) {
                this.gd(b, f.h);
                var l = this.gh(b);
                var m = this.cw(b);
                f.p = l;
                f.l = m;
            }
            a.e(f);
        }
    };
    XamDataLegend.prototype.cw = function (a) {
        return a.getDataLegendBadgeContext();
    };
    XamDataLegend.prototype.a9 = function (a) {
        if (this.a8 != 0) {
            return this.a8;
        }
        return a.legendItemBadgeShape;
    };
    XamDataLegend.prototype.gd = function (a, b) {
        if (b == 0) {
            return;
        }
        if (a.legendItemBadgeShape != b) {
            a.legendItemBadgeShape = b;
        }
    };
    XamDataLegend.prototype.by = function () {
        return !isNaN_(this.cl) && !isNaN_(this.cm);
    };
    XamDataLegend.prototype.gh = function (a) {
        return a.getDataLegendBadge();
    };
    XamDataLegend.prototype.dz = function (a) {
        return a.getDataLegendSeriesTitle();
    };
    XamDataLegend.prototype.fh = function (a, b) {
        if (this.bz == false) {
            return;
        }
        var c = this.dw(b);
        if (c == null) {
            c = this.cx;
        }
        else {
            this.cx = c;
        }
        if (stringIsNullOrEmpty(c)) {
            return;
        }
        var d = new DataLegendRowInfo(this.a5, false, true, -1);
        d.n = c;
        d.q = this.h0 || d.q;
        d.i = this.bl || d.i;
        this.fk(d);
        this.fz(d);
        this.f9(d);
        if (d.b) {
            a.e(d);
        }
    };
    XamDataLegend.prototype.iq = function (a) {
        var b = new Thickness(0, 0);
        if (a.top >= 0) {
            b.top = a.top;
        }
        if (a.bottom >= 0) {
            b.bottom = a.bottom;
        }
        if (a.left >= 0) {
            b.left = a.left;
        }
        if (a.right >= 0) {
            b.right = a.right;
        }
        return b;
    };
    XamDataLegend.prototype.fz = function (a) {
        var e_14, _a;
        if (a.c) {
            a.x = this.iq(this.io);
            a.w = this.iq(this.ir);
        }
        else if (a.a) {
            a.x = this.iq(this.ij);
            a.w = this.iq(this.ii);
        }
        else {
            a.x = this.iq(this.im);
            a.w = this.iq(this.il);
        }
        try {
            for (var _b = __values(fromEnum(a.k)), _c = _b.next(); !_c.done; _c = _b.next()) {
                var b = _c.value;
                b.am = this.iq(this.is);
                b.al = this.iq(this.ip);
                b.ak = this.iq(this.ik);
            }
        }
        catch (e_14_1) {
            e_14 = { error: e_14_1 };
        }
        finally {
            try {
                if (_c && !_c.done && (_a = _b.return))
                    _a.call(_b);
            }
            finally {
                if (e_14)
                    throw e_14.error;
            }
        }
        if (a.c) {
            a.v = this.iq(this.ih);
            a.t = new Size(1, 20, 15);
        }
    };
    XamDataLegend.prototype.dw = function (a) {
        if (this.dh != null) {
            return this.dh;
        }
        var b = true;
        var c = null;
        for (var d = 0; d < a.count; d++) {
            var e = a._inner[d];
            var f = this.du(e);
            if (f == null) {
                continue;
            }
            if (c == null) {
                c = f;
            }
            else {
                if (!Base.equalsStatic(c, f)) {
                    b = false;
                    break;
                }
            }
        }
        if (b || !stringIsNullOrEmpty(c)) {
            return c;
        }
        return null;
    };
    XamDataLegend.prototype.du = function (a) {
        if (this.by()) {
            var b = a.getDataLegendAxisLabelFromCursorPosition(this.cl, this.cm);
            if (typeCast(Date_$type, b) !== null) {
                var c = b;
                b = this.dv(c);
            }
            return b == null ? "" : b.toString();
        }
        else {
            return null;
        }
    };
    XamDataLegend.prototype.dv = function (a) {
        if (this.ai != null) {
            var b = this.ai.i(a);
            return b;
        }
        else {
            var c = new DateTimeFormatSpecifier();
            c.dateStyle = "short";
            c.timeStyle = "full";
            var d = this.ap;
            if (d == 0) {
                d = 1;
            }
            if (d == 3) {
                c.dateStyle = "medium";
            }
            if (d == 1) {
                c.dateStyle = "short";
            }
            if (d == 4) {
                c.dateStyle = "full";
            }
            if (d == 2) {
                c.dateStyle = "long";
            }
            if (d == 5) {
                c.dateStyle = null;
            }
            var e = this.aq;
            if (e == 0) {
                e = 1;
            }
            if (e == 3) {
                c.timeStyle = "medium";
            }
            if (e == 1) {
                c.timeStyle = "short";
            }
            if (e == 4) {
                c.timeStyle = "full";
            }
            if (e == 2) {
                c.timeStyle = "long";
            }
            if (e == 5) {
                c.timeStyle = null;
            }
            c.locale = this.dy(this.c8, "en-US");
            if (this.aj == null) {
                this.aj = new BindingFormatter();
            }
            this.aj.j = "{0}";
            this.aj.d = [c];
            var f = this.aj.i(a);
            return f;
        }
    };
    XamDataLegend.prototype.fm = function () {
    };
    XamDataLegend.$t = markType(XamDataLegend, 'XamDataLegend', Control.$, [INotifyPropertyChanged_$type, IDataLegend_$type, IOnDemandRender_$type]);
    XamDataLegend.$$p = markDep(DependencyProperty, PropertyMetadata, XamDataLegend, 'fx', ['BadgeMargin:ih:gi', [Thickness.$, new Thickness(1, 0, 0, 0, 0)], 'BadgeShape:a8:gj', [LegendItemBadgeShape_$type, enumGetBox(LegendItemBadgeShape_$type, 0)], 'ExcludedColumns::gk', [Array_$type, null], 'ExcludedSeries::gl', [Array_$type, null], 'HeaderFormatCulture:c8:gm', [2, stringEmpty()], 'HeaderFormatDate:ap:gn', [DataLegendHeaderDateMode_$type, enumGetBox(DataLegendHeaderDateMode_$type, 0)], 'HeaderFormatSpecifiers:ag:go', [Array_$type, null], 'HeaderFormatString:dc:gp', [2, null], 'HeaderFormatTime:aq:gq', [DataLegendHeaderTimeMode_$type, enumGetBox(DataLegendHeaderTimeMode_$type, 0)], 'HeaderRowMargin:ii:gr', [Thickness.$, new Thickness(0, 5)], 'HeaderRowVisible:bz:gs', [0, true], 'HeaderTextColor:h0:gt', [Brush.$, null], 'HeaderTextMargin:ij:gu', [Thickness.$, new Thickness(1, 2, 0, 0, 0)], 'HeaderText:dh:gv', [2, null], 'IncludedColumns::gw', [Array_$type, null], 'IncludedSeries::gx', [Array_$type, null], 'LabelDisplayMode:ar:gy', [DataLegendLabelMode_$type, enumGetBox(DataLegendLabelMode_$type, 0)], 'LabelTextColor:h1:gz', [Brush.$, null], 'LabelTextMargin:ik:g0', [Thickness.$, new Thickness(1, 12, 0, 0, 0)], 'ShouldUpdateWhenSeriesDataChanges:b2:g1', [0, true], 'SummaryLabelTextColor:h3:g2', [Brush.$, null], 'SummaryLabelText:d3:g3', [2, null], 'SummaryRowMargin:il:g4', [Thickness.$, new Thickness(0, 5)], 'SummaryTitleTextColor:h4:g5', [Brush.$, null], 'SummaryTitleTextMargin:im:g6', [Thickness.$, new Thickness(1, 2, 0, 4, 0)], 'SummaryTitleText:d8:g7', [2, null], 'SummaryType:a1:g8', [DataLegendSummaryType_$type, enumGetBox(DataLegendSummaryType_$type, 0)], 'SummaryUnitsTextColor:h5:g9', [Brush.$, null], 'SummaryUnitsText:ee:ha', [2, null], 'SummaryValueTextColor:h6:hb', [Brush.$, null], 'TargetCursorPositionX::hc', [1, NaN], 'TargetCursorPositionY::hd', [1, NaN], 'Target::he', [4, null], 'TitleTextColor:h7:hf', [Brush.$, null], 'TitleTextMargin:io:hg', [Thickness.$, new Thickness(1, 0, 0, 4, 0)], 'UnitsDisplayMode:a2:hh', [DataLegendUnitsMode_$type, enumGetBox(DataLegendUnitsMode_$type, 0)], 'UnitsTextColor:h8:hi', [Brush.$, null], 'UnitsTextMargin:ip:hj', [Thickness.$, new Thickness(1, 0, 0, 0, 0)], 'UnitsText:er:hk', [2, null], 'ValueFormatAbbreviation:an:hl', [DataAbbreviationMode_$type, enumGetBox(DataAbbreviationMode_$type, 0)], 'ValueFormatCulture:ex:hm', [2, stringEmpty()], 'ValueFormatCurrencyCode:ez:hn', [2, null], 'ValueFormatMaxFractions:ct:ho', [1, -1], 'ValueFormatMinFractions:cu:hp', [1, -1], 'ValueFormatMode:a3:hq', [DataLegendValueMode_$type, enumGetBox(DataLegendValueMode_$type, 0)], 'ValueFormatSpecifiers:ah:hr', [Array_$type, null], 'ValueFormatString:e5:hs', [2, null], 'ValueFormatUseGrouping:b3:ht', [0, true], 'ValueRowMargin:ir:hu', [Thickness.$, new Thickness(0, 5)], 'ValueRowVisible:b4:hv', [0, true], 'ValueTextColor:h9:hw', [Brush.$, null], 'ValueTextMargin:is:hx', [Thickness.$, new Thickness(1, 2, 0, 2, 0)], 'ValueTextUseSeriesColors:b5:hy', [0, false], 'ValueTextWhenMissingData:fe:hz', [2, "N/A"]]);
    return XamDataLegend;
}(Control));
export { XamDataLegend };
/**
 * @hidden
 */
var DataLegendView = /** @class */ /*@__PURE__*/ (function (_super) {
    __extends(DataLegendView, _super);
    function DataLegendView(a) {
        var _this = _super.call(this) || this;
        _this.z = null;
        _this.ab = null;
        _this.ad = null;
        _this.ac = null;
        _this.aa = null;
        _this.o = null;
        _this.q = null;
        _this.s = null;
        _this.r = null;
        _this.p = null;
        _this.a = null;
        _this.ai = null;
        _this.ah = null;
        _this.t = null;
        _this.b = null;
        _this.ae = 1;
        _this.ak = -1;
        _this.aj = -1;
        _this.x = new Dictionary$2(FontInfo.$, Tuple$2.$.specialize(Number_$type, FontInfo.$), 0);
        _this.v = false;
        _this.y = new List$1(FrameworkElement.$, 0);
        _this.af = 0;
        _this.f = null;
        _this.h = null;
        _this.g = null;
        _this.d = null;
        _this.e = null;
        _this.c = null;
        _this.u = null;
        _this.a = a;
        _this.q = ((function () {
            var $ret = new Pool$1(TextBlock.$);
            $ret.create = runOn(_this, _this.bl);
            $ret.activate = runOn(_this, _this.ba);
            $ret.disactivate = runOn(_this, _this.bc);
            $ret.destroy = runOn(_this, _this.bb);
            return $ret;
        })());
        _this.s = ((function () {
            var $ret = new Pool$1(TextBlock.$);
            $ret.create = runOn(_this, _this.bn);
            $ret.activate = runOn(_this, _this.bg);
            $ret.disactivate = runOn(_this, _this.bi);
            $ret.destroy = runOn(_this, _this.bh);
            return $ret;
        })());
        _this.r = ((function () {
            var $ret = new Pool$1(TextBlock.$);
            $ret.create = runOn(_this, _this.bm);
            $ret.activate = runOn(_this, _this.bd);
            $ret.disactivate = runOn(_this, _this.bf);
            $ret.destroy = runOn(_this, _this.be);
            return $ret;
        })());
        _this.p = ((function () {
            var $ret = new Pool$1(ContentControl.$);
            $ret.create = runOn(_this, _this.bj);
            $ret.activate = runOn(_this, _this.ay);
            $ret.disactivate = runOn(_this, _this.a0);
            $ret.destroy = runOn(_this, _this.az);
            return $ret;
        })());
        _this.o = ((function () {
            var $ret = new Pool$1(TextBlock.$);
            $ret.create = runOn(_this, _this.bk);
            $ret.activate = runOn(_this, _this.av);
            $ret.disactivate = runOn(_this, _this.ax);
            $ret.destroy = runOn(_this, _this.aw);
            return $ret;
        })());
        _this.z = new List$1(TextBlock.$, 0);
        _this.ab = new List$1(TextBlock.$, 0);
        _this.ad = new List$1(TextBlock.$, 0);
        _this.ac = new List$1(TextBlock.$, 0);
        _this.aa = new List$1(ContentControl.$, 0);
        return _this;
    }
    DataLegendView.prototype.ar = function () {
        this.a.fo();
    };
    DataLegendView.prototype.bl = function () {
        var a = new TextBlock();
        this.ab.add(a);
        return a;
    };
    DataLegendView.prototype.ba = function (a) {
        a._visibility = 0;
    };
    DataLegendView.prototype.bc = function (a) {
        a._visibility = 1;
    };
    DataLegendView.prototype.bb = function (a) {
        this.ab.remove(a);
    };
    DataLegendView.prototype.bn = function () {
        var a = new TextBlock();
        this.ad.add(a);
        return a;
    };
    DataLegendView.prototype.bg = function (a) {
        a._visibility = 0;
    };
    DataLegendView.prototype.bi = function (a) {
        a._visibility = 1;
    };
    DataLegendView.prototype.bh = function (a) {
        this.ad.remove(a);
    };
    DataLegendView.prototype.bm = function () {
        var a = new TextBlock();
        this.ac.add(a);
        return a;
    };
    DataLegendView.prototype.bd = function (a) {
        a._visibility = 0;
    };
    DataLegendView.prototype.bf = function (a) {
        a._visibility = 1;
    };
    DataLegendView.prototype.be = function (a) {
        this.ac.remove(a);
    };
    DataLegendView.prototype.bk = function () {
        var a = new TextBlock();
        this.z.add(a);
        return a;
    };
    DataLegendView.prototype.av = function (a) {
        a._visibility = 0;
    };
    DataLegendView.prototype.ax = function (a) {
        a._visibility = 1;
    };
    DataLegendView.prototype.aw = function (a) {
        this.z.remove(a);
    };
    DataLegendView.prototype.bj = function () {
        var a = new ContentControl();
        this.aa.add(a);
        return a;
    };
    DataLegendView.prototype.ay = function (a) {
        a._visibility = 0;
    };
    DataLegendView.prototype.a0 = function (a) {
        a._visibility = 1;
    };
    DataLegendView.prototype.az = function (a) {
    };
    DataLegendView.prototype.au = function () {
        var a = this.a.pixelScalingRatio;
        var b = this.a.cn;
        if (!isNaN_(a) && a != 0) {
            return;
        }
        if (window.devicePixelRatio != undefined && window.devicePixelRatio != b) {
            this.a.cn = window.devicePixelRatio;
        }
    };
    DataLegendView.prototype.a3 = function () {
        this.au();
        var a = Math.round(this.ah.rootWrapper.width());
        var b = Math.round(this.ah.rootWrapper.height());
        this.a.ib = new Rect(0, 0, 0, a, b);
        if (this.b != null) {
            this.b.bl = this.a.ib;
        }
        this.a.f2();
    };
    DataLegendView.prototype.al = function () {
        if (this.b != null) {
            this.b.ao = null;
            this.b.av();
        }
    };
    DataLegendView.prototype.a2 = function (a) {
        if (a == null) {
            this.ai = null;
            this.ah = null;
            this.t = null;
            this.al();
            return;
        }
        this.ae = (isNaN_(this.a.pixelScalingRatio) ? this.a.cn : this.a.pixelScalingRatio);
        var b = a;
        this.ah = b;
        var c = this.ae;
        var d = Math.round(b.rootWrapper.width());
        var e = Math.round(b.rootWrapper.height());
        var f = d * c;
        var g = e * c;
        this.ah.rootWrapper.setStyleProperty("position", "relative");
        var h = this.ah.createElement("canvas");
        h.setStyleProperty("position", "absolute");
        this.ah.append(h);
        this.ak = truncate(Math.round(f));
        this.aj = truncate(Math.round(g));
        h.setAttribute("width", f.toString());
        h.setAttribute("height", g.toString());
        h.setStyleProperty("width", d.toString() + "px");
        h.setStyleProperty("height", e.toString() + "px");
        this.a.ib = new Rect(0, 0, 0, d, e);
        this.ai = h;
        var i = this.ah.get2DCanvasContext(this.ai);
        this.t = new RenderingContext(new CanvasViewRenderer(), i);
        this.al();
        if (TypeRegistrar.isRegistered("CanvasGestureDOMEventProxy")) {
            this.b = typeCast(EventProxy.$, TypeRegistrar.create("CanvasGestureDOMEventProxy", this.ah.rootWrapper, this.ah, false));
        }
        if (this.b != null) {
        }
    };
    DataLegendView.prototype.at = function (a, b) {
        this.a3();
    };
    DataLegendView.prototype.as = function (a) {
    };
    DataLegendView.prototype.a6 = function () {
        var a = this.a.ib.width;
        var b = this.a.ib.height;
        var c = Math.round(a * this.ae);
        var d = Math.round(b * this.ae);
        if (this.ak != c || this.aj != d) {
            this.ai.setAttribute("width", c.toString());
            this.ai.setAttribute("height", d.toString());
            this.ai.setStyleProperty("width", a.toString() + "px");
            this.ai.setStyleProperty("height", b.toString() + "px");
            this.ak = truncate(Math.round(c));
            this.aj = truncate(Math.round(d));
        }
        this.a7(this.t, this.ae);
    };
    DataLegendView.prototype.a7 = function (a, b) {
        if (a.d && b != 1) {
            a.z();
            a.aa(b, b);
        }
        if (a == this.t) {
            a.k(this.a.ib.left, this.a.ib.top, this.a.ib.width, this.a.ib.height);
        }
        var c = new DataTemplatePassInfo();
        c.passID = "LegendItem";
        for (var d = 0; d < this.aa.count; d++) {
            var e = this.aa._inner[d];
            if (e == null) {
                continue;
            }
            var f = e.ah;
            if (f == null) {
                continue;
            }
            var g = new DataTemplateMeasureInfo();
            g.passInfo = c;
            g.context = this.t.g();
            g.width = e.width;
            g.height = e.height;
            g.data = e.content;
            g.renderContext = a;
            f.measure(g);
            var h = new DataTemplateRenderInfo();
            h.availableWidth = e.width;
            h.availableHeight = e.height;
            h.passInfo = c;
            h.context = a.g();
            h.renderContext = a;
            h.data = e.content;
            h.xPosition = e.n;
            h.yPosition = e.o;
            a.z();
            a.af(e.n, e.o);
            f.render(h);
            a.y();
        }
        for (var i = 0; i < this.ab.count; i++) {
            var j = this.ab._inner[i];
            a.ac(j.dataContext);
            a.w(j);
        }
        for (var k = 0; k < this.z.count; k++) {
            var l = this.z._inner[k];
            a.ac(l.dataContext);
            a.w(l);
        }
        for (var m = 0; m < this.ad.count; m++) {
            var n = this.ad._inner[m];
            a.ac(n.dataContext);
            a.w(n);
        }
        for (var o = 0; o < this.ac.count; o++) {
            var p = this.ac._inner[o];
            a.ac(p.dataContext);
            a.w(p);
        }
        if (a.d && b != 1) {
            a.y();
        }
    };
    DataLegendView.prototype.w = function () {
        if (this.ah != null) {
            this.ah.setTimeout(runOn(this.a, this.a.fo), 0);
            return true;
        }
        return false;
    };
    DataLegendView.prototype.bu = function (a, b) {
        this.t.ac(b);
        var c = new TextBlock();
        c.al = a;
        var d = this.t.ag(c, this.ag(b), true);
        return new Size(1, d.c, d.b);
    };
    DataLegendView.prototype.ag = function (a) {
        if (this.x.containsKey(a)) {
            var b = this.x.item(a);
            if (b.d.g == a.g) {
                return b.c;
            }
        }
        var c = FontUtil.getCurrentFontHeight(this.ah, a);
        var d = new Tuple$2(Number_$type, FontInfo.$, c, a);
        this.x.item(a, d);
        return c;
    };
    DataLegendView.prototype.a8 = function (a, b, c) {
        if (this.v) {
            this.y.add(a);
        }
        a.n = b;
        a.o = c;
    };
    DataLegendView.prototype.aq = function (a) {
        this.a6();
    };
    DataLegendView.prototype.ao = function (a, b) {
        a.dataContext = b;
    };
    DataLegendView.prototype.bt = function () {
        return FontDefaults.dataLegendFontBrush;
    };
    DataLegendView.prototype.br = function () {
        return FontDefaults.dataLegendFontBrush;
    };
    DataLegendView.prototype.bs = function () {
        return FontDefaults.dataLegendFontBrush;
    };
    DataLegendView.prototype.bp = function () {
        return FontDefaults.dataLegendFontBrush;
    };
    DataLegendView.prototype.bq = function () {
        return FontDefaults.dataLegendFontBrush;
    };
    DataLegendView.prototype.bo = function () {
        return FontDefaults.dataLegendFontBrush;
    };
    DataLegendView.prototype.l = function () {
        if (this.f == null) {
            this.f = ((function () {
                var $ret = new FontInfo();
                $ret.n = FontDefaults.dataLegendFontFamily;
                $ret.d = FontDefaults.dataLegendFontSize;
                $ret.q = FontDefaults.dataLegendFontStyle;
                $ret.s = FontDefaults.dataLegendFontWeight;
                $ret.o = FontDefaults.dataLegendFontStretch;
                $ret.r = FontDefaults.dataLegendFontVariant;
                return $ret;
            })());
        }
        return this.f;
    };
    DataLegendView.prototype.n = function () {
        if (this.h == null) {
            this.h = ((function () {
                var $ret = new FontInfo();
                $ret.n = FontDefaults.dataLegendFontFamily;
                $ret.d = FontDefaults.dataLegendFontSize;
                $ret.q = FontDefaults.dataLegendFontStyle;
                $ret.s = FontDefaults.dataLegendFontWeight;
                $ret.o = FontDefaults.dataLegendFontStretch;
                $ret.r = FontDefaults.dataLegendFontVariant;
                return $ret;
            })());
        }
        return this.h;
    };
    DataLegendView.prototype.m = function () {
        if (this.g == null) {
            this.g = ((function () {
                var $ret = new FontInfo();
                $ret.n = FontDefaults.dataLegendFontFamily;
                $ret.d = FontDefaults.dataLegendFontSize;
                $ret.q = FontDefaults.dataLegendFontStyle;
                $ret.s = FontDefaults.dataLegendFontWeight;
                $ret.o = FontDefaults.dataLegendFontStretch;
                $ret.r = FontDefaults.dataLegendFontVariant;
                return $ret;
            })());
        }
        return this.g;
    };
    DataLegendView.prototype.j = function () {
        if (this.d == null) {
            this.d = ((function () {
                var $ret = new FontInfo();
                $ret.n = FontDefaults.dataLegendFontFamily;
                $ret.d = FontDefaults.dataLegendFontSize;
                $ret.q = FontDefaults.dataLegendFontStyle;
                $ret.s = FontDefaults.dataLegendFontWeight;
                $ret.o = FontDefaults.dataLegendFontStretch;
                $ret.r = FontDefaults.dataLegendFontVariant;
                return $ret;
            })());
        }
        return this.d;
    };
    DataLegendView.prototype.k = function () {
        if (this.e == null) {
            this.e = ((function () {
                var $ret = new FontInfo();
                $ret.n = FontDefaults.dataLegendFontFamily;
                $ret.d = FontDefaults.dataLegendFontSize;
                $ret.q = FontDefaults.dataLegendFontStyle;
                $ret.s = FontDefaults.dataLegendFontWeight;
                $ret.o = FontDefaults.dataLegendFontStretch;
                $ret.r = FontDefaults.dataLegendFontVariant;
                return $ret;
            })());
        }
        return this.e;
    };
    DataLegendView.prototype.i = function () {
        if (this.c == null) {
            this.c = ((function () {
                var $ret = new FontInfo();
                $ret.n = FontDefaults.dataLegendFontFamily;
                $ret.d = FontDefaults.dataLegendFontSize;
                $ret.q = FontDefaults.dataLegendFontStyle;
                $ret.s = FontDefaults.dataLegendHeaderFontWeight;
                $ret.o = FontDefaults.dataLegendFontStretch;
                $ret.r = FontDefaults.dataLegendFontVariant;
                return $ret;
            })());
        }
        return this.c;
    };
    DataLegendView.prototype.am = function (a, b) {
        var model_ = this.a;
        var ext_ = model_.externalObject;
        if (ext_ != null) {
            var width_ = a;
            var height_ = b;
            this.ah.rootWrapper.setStyleProperty("min-height", b + "px");
            this.ah.rootWrapper.setStyleProperty("min-width", a + "px");
            this.a.notifySizeChanged();
        }
    };
    DataLegendView.prototype.a5 = function (a) {
        this.ae = a;
    };
    DataLegendView.prototype.a1 = function () {
        if (this.b != null) {
            this.b.at(this.ai, "");
        }
    };
    DataLegendView.prototype.a4 = function () {
        if (this.b != null) {
            this.b.bh(this.ai, "");
        }
    };
    DataLegendView.prototype.ap = function (a, b) {
        a.ag = true;
        var c = this.t.ag(a, this.ag(b), true);
    };
    DataLegendView.prototype.a9 = function () {
        this.y.clear();
        this.v = true;
        this.af = 0;
    };
    DataLegendView.prototype.an = function () {
        for (var a = 0; a < this.y.count; a++) {
            this.af = Math.max(this.af, this.y._inner[a].ah);
        }
        if (this.af > 0) {
            for (var b = 0; b < this.y.count; b++) {
                this.y._inner[b].ah = this.af;
            }
        }
        this.v = false;
        this.af = 0;
    };
    DataLegendView.$t = markType(DataLegendView, 'DataLegendView');
    return DataLegendView;
}(Base));
export { DataLegendView };
