/*
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 } from "tslib";
import { CategoryAngleAxis } from "./CategoryAngleAxis";
import { ICoalescingModerator_$type } from "./ICoalescingModerator";
import { DependencyProperty } from "igniteui-react-core";
import { OthersCategoryType_$type } from "igniteui-react-core";
import { typeCast, Number_$type, enumGetBox, Boolean_$type, markType, markDep } from "igniteui-react-core";
import { OthersCategoryContext } from "./OthersCategoryContext";
import { IFastItemsSource_$type } from "igniteui-react-core";
import { SeriesViewer } from "./SeriesViewer";
import { List$1 } from "igniteui-react-core";
import { CoreGeometryUtil } from "igniteui-react-core";
import { ArrayExtension } from "igniteui-react-core";
import { PropertyMetadata } from "igniteui-react-core";
import { truncate, isNaN_, isInfinity } from "igniteui-react-core";
/**
 * @hidden
 */
var ProportionalCategoryAngleAxis = /** @class */ /*@__PURE__*/ (function (_super) {
    __extends(ProportionalCategoryAngleAxis, _super);
    function ProportionalCategoryAngleAxis() {
        var _this = _super !== null && _super.apply(this, arguments) || this;
        _this.n9 = null;
        _this.nv = null;
        _this.nz = true;
        _this.n4 = NaN;
        _this.n2 = new List$1(Number_$type, 0);
        _this.n1 = new List$1(Number_$type, 0);
        _this.n0 = new List$1(Boolean_$type, 0);
        _this.ny = false;
        _this.n3 = NaN;
        _this.n8 = -1;
        return _this;
    }
    Object.defineProperty(ProportionalCategoryAngleAxis.prototype, "og", {
        get: function () {
            return this.n9;
        },
        set: function (a) {
            var b = this.og;
            if (a != b) {
                this.n9 = a;
                this.h3("ValueMemberPath", b, this.og);
            }
        },
        enumerable: false,
        configurable: true
    });
    ProportionalCategoryAngleAxis.prototype.fy = function (a, b) {
        var c = this.gt(b);
        if (this.hasOthersCategory && c == "Label") {
            if (typeCast(OthersCategoryContext.$, a) !== null) {
                return this.oe();
            }
        }
        return _super.prototype.fy.call(this, a, b);
    };
    Object.defineProperty(ProportionalCategoryAngleAxis.prototype, "normalizationMayContainUnknowns", {
        get: function () {
            return this.nx == null || this.nx.mayContainUnknowns;
        },
        enumerable: false,
        configurable: true
    });
    Object.defineProperty(ProportionalCategoryAngleAxis.prototype, "nx", {
        get: function () {
            return this.nv;
        },
        set: function (a) {
            if (this.nv != a) {
                var b = this.nv;
                this.nv = a;
                this.h3("ValueColumn", b, this.nv);
            }
        },
        enumerable: false,
        configurable: true
    });
    ProportionalCategoryAngleAxis.prototype.nw = function (a) {
        if (a == null) {
            return this.ks.registerColumn(null, null, false);
        }
        var b = null;
        var c = SeriesViewer.cu(a, this.coercionMethods);
        b = c.a;
        return this.ks.registerColumn(a, b, this.expectFunctions);
    };
    ProportionalCategoryAngleAxis.prototype.hx = function (a, b, c, d) {
        _super.prototype.hx.call(this, a, b, c, d);
        switch (b) {
            case "ValueMemberPath":
                if (this.ks != null) {
                    this.ks.deregisterColumn(this.nx);
                    this.nx = this.nw(this.og);
                }
                break;
            case "ValueColumn":
                this.nz = true;
                this.ny = false;
                this.h8();
                break;
            case ProportionalCategoryAngleAxis.$$p[0]:
            case ProportionalCategoryAngleAxis.$$p[1]:
            case ProportionalCategoryAngleAxis.$$p[2]:
                this.nz = true;
                this.ny = false;
                this.h8();
                break;
            case "FastItemsSource":
                this.nz = true;
                this.ny = false;
                var e = typeCast(IFastItemsSource_$type, c);
                if (e != null) {
                    e.deregisterColumn(this.nx);
                    this.nx = null;
                }
                var f = typeCast(IFastItemsSource_$type, d);
                if (f != null) {
                    this.nx = this.nw(this.og);
                }
                this.h8();
                break;
        }
    };
    ProportionalCategoryAngleAxis.prototype.l4 = function (a) {
        _super.prototype.l4.call(this, a);
        this.nz = true;
        this.ny = false;
    };
    ProportionalCategoryAngleAxis.prototype.getScaledAngle = function (a) {
        this.oi();
        if (isNaN_(a) || isInfinity(a)) {
            return NaN;
        }
        var b = this.lg;
        var c = a % b;
        if (c < 0) {
            c = b + c;
        }
        var d = truncate(Math.floor(c));
        var e = this.n1._inner[d];
        var f = c - d;
        var g = 0;
        if (isNaN_(this.n2._inner[d])) {
            g = 0 * f;
        }
        else {
            g = this.n2._inner[d] * f;
        }
        var h = e + g;
        if (this.ci) {
            h = 1 - h;
        }
        var i = (h * 2 * Math.PI);
        if (a >= b) {
            i += (2 * Math.PI) * Math.floor(a / b);
        }
        if (a < 0) {
            i -= (2 * Math.PI) * Math.abs(Math.floor(a / b));
        }
        return i + this.mz;
    };
    ProportionalCategoryAngleAxis.prototype.get_cl = function () {
        return true;
    };
    ProportionalCategoryAngleAxis.prototype.m3 = function (a, b, c, d, e) {
        var f = 0.5;
        if (this.li > 1) {
            var g = this.lc(c, d, e);
            var h = 0;
            if (!isNaN_(this.lb)) {
                h = Math.min(this.lb, 1);
            }
            var i = 1 - 0.5 * g;
            var j = i / (this.li - (this.li - 1) * h);
            var k = (i - j) / (this.li - 1);
            f = 0.25 * g + 0.5 * j + a * k;
        }
        return this.n5(a, c, d, e) * f;
    };
    ProportionalCategoryAngleAxis.prototype.n5 = function (a, b, c, d) {
        if (a < 0 || a > this.lh - 1) {
            return this.getCategorySize(b, c, d);
        }
        this.oi();
        var e = this.n2._inner[a];
        if (isNaN_(e)) {
            return NaN;
        }
        var f = Math.PI * 2 * this.n2._inner[a];
        return f;
    };
    ProportionalCategoryAngleAxis.prototype.m4 = function (a, b, c, d) {
        this.oi();
        var e = this.lc(b, c, d);
        var f = 0;
        if (!isNaN_(this.lb)) {
            f = Math.min(this.lb, 1);
        }
        var g = 1 - 0.5 * e;
        if (a < 0 || a > this.lh - 1) {
            return this.k5(b, c, d);
        }
        var h = this.n2._inner[a];
        if (isNaN_(h)) {
            return NaN;
        }
        var i = Math.PI * 2 * h;
        return i * g / (this.li - (this.li - 1) * f);
    };
    ProportionalCategoryAngleAxis.prototype.lj = function () {
        if (this.ks == null) {
            return 0;
        }
        this.oi();
        if (this.ny) {
            return _super.prototype.lj.call(this) + 1;
        }
        return _super.prototype.lj.call(this);
    };
    ProportionalCategoryAngleAxis.prototype.mu = function (a) {
        return this.hasOthersCategory && a == this.lh - 1;
    };
    ProportionalCategoryAngleAxis.prototype.ng = function () {
        return this.oe();
    };
    ProportionalCategoryAngleAxis.prototype.mv = function (a) {
        if (a >= 0 && a < this.lh) {
            if (isNaN_(this.n2._inner[a])) {
                return true;
            }
        }
        return _super.prototype.mv.call(this, a);
    };
    ProportionalCategoryAngleAxis.prototype.ia = function (a) {
        this.oi();
        _super.prototype.ia.call(this, a);
    };
    ProportionalCategoryAngleAxis.prototype.ensureSum = function () {
        this.oi();
    };
    ProportionalCategoryAngleAxis.prototype.oi = function () {
        if (this.nz) {
            this.nz = false;
            this.ny = false;
            this.lh = this.lj();
            this.n3 = NaN;
            this.n8 = -1;
            if (this.nx != null && this.nx.count > 0) {
                this.n4 = NaN;
                var a = true;
                for (var b = 0; b < this.nx.count; b++) {
                    var c = this.nx.item(b);
                    if (isNaN_(c) || isInfinity(c) || c < 0) {
                        continue;
                    }
                    if (a) {
                        a = false;
                        this.n4 = 0;
                    }
                    this.n4 += c;
                }
                var d = 0;
                this.n2.clear();
                this.n1.clear();
                this.n0.clear();
                var e = 0;
                for (var f = 0; f < this.nx.count; f++) {
                    var g = 0;
                    if (isNaN_(this.n4)) {
                        g = 1 / this.lh;
                    }
                    else {
                        var h = this.nx.item(f);
                        if (isNaN_(h) || isInfinity(h) || h < 0) {
                            g = 0;
                        }
                        else {
                            g = h;
                        }
                    }
                    var i = false;
                    if (this.nu == 0) {
                        if (g < this.n7) {
                            i = true;
                        }
                    }
                    else {
                        if ((g / this.n4) * 100 < this.n7) {
                            i = true;
                        }
                    }
                    if (i) {
                        this.n1.add(d);
                        this.n2.add(NaN);
                        this.n0.add(true);
                        e += g;
                    }
                    else {
                        this.n1.add(d);
                        this.n2.add(g / this.n4);
                        this.n0.add(false);
                        d += (g / this.n4);
                    }
                }
                if (e > 0) {
                    this.ny = true;
                    this.n1.add(d);
                    this.n2.add(e / this.n4);
                    this.n0.add(false);
                    this.n3 = e;
                    this.n8 = this.n1.count - 1;
                }
            }
            else {
                if (this.lh > 0) {
                    this.n2.clear();
                    this.n1.clear();
                    var j = 0;
                    for (var k = 0; k < this.lh; k++) {
                        this.n1.add(j);
                        this.n2.add(1 / this.lh);
                        j += (1 / this.lh);
                    }
                }
            }
            this.lh = this.lj();
        }
    };
    Object.defineProperty(ProportionalCategoryAngleAxis.prototype, "othersValue", {
        get: function () {
            return this.n3;
        },
        enumerable: false,
        configurable: true
    });
    Object.defineProperty(ProportionalCategoryAngleAxis.prototype, "othersIndex", {
        get: function () {
            return this.n8;
        },
        enumerable: false,
        configurable: true
    });
    Object.defineProperty(ProportionalCategoryAngleAxis.prototype, "hasOthersCategory", {
        get: function () {
            return this.ny;
        },
        enumerable: false,
        configurable: true
    });
    ProportionalCategoryAngleAxis.prototype.ho = function (a, b, c, d) {
        for (var e = b; e < c; e++) {
            a.item(e, this.ek(a.item(e), d));
        }
    };
    ProportionalCategoryAngleAxis.prototype.getUnscaledAngle = function (a) {
        this.oi();
        if (isNaN_(a) || isInfinity(a)) {
            return NaN;
        }
        a = CoreGeometryUtil.b(a);
        while (a < this.mz) {
            a += 2 * Math.PI;
        }
        while (a > (this.mz + (2 * Math.PI))) {
            a -= 2 * Math.PI;
        }
        var b = (a - this.mz) / (2 * Math.PI);
        if (this.ch) {
            b = 1 - b;
        }
        var c = -1;
        c = ArrayExtension.binarySearch$11(Number_$type, this.n1, function (d) { return b < d ? -1 : (b > d ? 1 : 0); });
        if (c < 0) {
            c = ~c;
            c--;
        }
        if (c < 0) {
            c = 0;
        }
        if (c > this.n1.count - 1) {
            c = this.n1.count - 1;
        }
        var d = this.n1._inner[c];
        var e = this.n2._inner[c];
        if (isNaN_(e)) {
            b = c;
        }
        else {
            b = c + (b - d) / e;
        }
        return b;
    };
    ProportionalCategoryAngleAxis.prototype.isOthersValue = function (a) {
        if (a < 0 || a > this.n0.count - 1) {
            return false;
        }
        return this.n0._inner[a];
    };
    ProportionalCategoryAngleAxis.prototype.ge = function (a) {
        var b = a;
        if (this.categoryMode == 0) {
            b = truncate(Math.round(a));
        }
        else {
            b = truncate(Math.floor(a));
        }
        if (this.hasOthersCategory && b >= this.lh - 1) {
            b = this.lh - 1;
            return this.oe();
        }
        return _super.prototype.ge.call(this, a);
    };
    ProportionalCategoryAngleAxis.prototype.oe = function () {
        if (this.oa != null) {
            return this.oa;
        }
        return "Others";
    };
    ProportionalCategoryAngleAxis.prototype.getNormalizingValueAtIndex = function (a, b) {
        if (a < 0 || this.nx == null || a > this.nx.count - 1) {
            return b;
        }
        return this.nx.item(a);
    };
    ProportionalCategoryAngleAxis.prototype.n6 = function (a) {
        this.oi();
        var b = this.n2._inner[a] * 100;
        return b;
    };
    Object.defineProperty(ProportionalCategoryAngleAxis.prototype, "isVertical", {
        get: function () {
            return this.cp;
        },
        enumerable: false,
        configurable: true
    });
    ProportionalCategoryAngleAxis.prototype.j$d = function (a, b) {
        return this.en.apply(this, arguments);
    };
    ProportionalCategoryAngleAxis.prototype.j$c = function (a, b) {
        return this.ek.apply(this, arguments);
    };
    ProportionalCategoryAngleAxis.prototype.j$e = function (a, b, c, d, e) {
        this.hn.apply(this, arguments);
    };
    ProportionalCategoryAngleAxis.prototype.j$f = function (a, b, c, d) {
        this.ho.apply(this, arguments);
    };
    ProportionalCategoryAngleAxis.prototype.j$g = function (a, b, c, d) {
        this.hp.apply(this, arguments);
    };
    Object.defineProperty(ProportionalCategoryAngleAxis.prototype, "j$b", {
        get: function () {
            return this.ch;
        },
        enumerable: false,
        configurable: true
    });
    ProportionalCategoryAngleAxis.prototype.j$a = function () {
        return this.ag.apply(this, arguments);
    };
    Object.defineProperty(ProportionalCategoryAngleAxis.prototype, "itemsCount", {
        get: function () {
            return this.lh;
        },
        enumerable: false,
        configurable: true
    });
    ProportionalCategoryAngleAxis.$t = markType(ProportionalCategoryAngleAxis, 'ProportionalCategoryAngleAxis', CategoryAngleAxis.$, [ICoalescingModerator_$type]);
    ProportionalCategoryAngleAxis.$$p = markDep(DependencyProperty, PropertyMetadata, ProportionalCategoryAngleAxis, 'h3', ['OthersCategoryText:oa:oj', [2, null], 'OthersCategoryThreshold:n7:ok', [1, 3], 'OthersCategoryType:nu:ol', [OthersCategoryType_$type, enumGetBox(OthersCategoryType_$type, 1)]]);
    return ProportionalCategoryAngleAxis;
}(CategoryAngleAxis));
export { ProportionalCategoryAngleAxis };
