/*
THIS INFRAGISTICS ULTIMATE SOFTWARE LICENSE  AGREEMENT ("AGREEMENT") LOCATED HERE:
https://www.infragistics.com/legal/license/igultimate-la
https://www.infragistics.com/legal/license/igultimate-eula
GOVERNS THE LICENSING, INSTALLATION AND USE OF INFRAGISTICS SOFTWARE. BY DOWNLOADING AND/OR INSTALLING AND USING INFRAGISTICS SOFTWARE:  you are indicating that you have read and understand this Agreement, and agree to be legally bound by it on behalf of the yourself and your company.
*/
import * as tslib_1 from "tslib";
import { ScatterBase } from "./ScatterBase";
import { IScaleLegendSeries_$type } from "igniteui-angular-core";
import { List$1 } from "igniteui-angular-core";
import { UIElement } from "igniteui-angular-core";
import { Base, typeCast, Point_$type, fromEnum, markType, markDep, enumGetBox, runOn } from "igniteui-angular-core";
import { DependencyProperty } from "igniteui-angular-core";
import { SizeScale } from "./SizeScale";
import { BrushScale } from "./BrushScale";
import { ScatterFrame } from "./ScatterFrame";
import { IChartLegend_$type } from "igniteui-angular-core";
import { ValueBrushScale } from "./ValueBrushScale";
import { IFastItemsSource_$type } from "igniteui-angular-core";
import { ScatterBaseView } from "./ScatterBaseView";
import { ScalerParams } from "./ScalerParams";
import { Dictionary$2 } from "igniteui-angular-core";
import { OwnedPoint } from "./OwnedPoint";
import { BubbleMarkerManager } from "./BubbleMarkerManager";
import { ContentControl } from "igniteui-angular-core";
import { DataContext } from "igniteui-angular-core";
import { DeviceUtils } from "igniteui-angular-core";
import { PropertyMetadata } from "igniteui-angular-core";
import { isNaN_, isInfinity, logBase } from "igniteui-angular-core";
import { stringIsNullOrEmpty } from "igniteui-angular-core";
import { BrushSelectionMode_$type } from "./BrushSelectionMode";
import { ScatterTrendLineManager } from "./ScatterTrendLineManager";
/**
 * @hidden
 */
var BubbleSeries = /** @class */ (function (_super) {
    tslib_1.__extends(BubbleSeries, _super);
    function BubbleSeries() {
        var _this = _super.call(this) || this;
        _this.pw = null;
        _this.pv = null;
        _this.o7 = null;
        _this.o2 = null;
        _this.o1 = null;
        _this.o0 = null;
        _this.ab = BubbleSeries.$;
        _this.m9 = new ScatterFrame();
        _this.nb = new ScatterFrame();
        _this.m8 = new ScatterFrame();
        return _this;
    }
    BubbleSeries.prototype.bf = function () {
        return new BubbleSeriesView(this);
    };
    BubbleSeries.prototype.iu = function (a) {
        _super.prototype.iu.call(this, a);
        this.oy = a;
    };
    BubbleSeries.prototype.isAttachedTo = function (a) {
        return this.aw == a;
    };
    BubbleSeries.prototype.ci = function () {
        return true;
    };
    BubbleSeries.prototype.h6 = function (a) {
        _super.prototype.h6.call(this, a);
        if (this.o5 != null && this.o7 != null && this.o7.count > 0) {
            for (var b = 0; b < this.o7.count; b++) {
                a(this.o7._inner[b]);
            }
        }
    };
    Object.defineProperty(BubbleSeries.prototype, "o4", {
        get: function () {
            return this.o6;
        },
        enumerable: true,
        configurable: true
    });
    BubbleSeries.prototype.pu = function (a) {
        var b = typeCast(CustomPaletteBrushScale.$, this.ox);
        var c = typeCast(ValueBrushScale.$, this.ox);
        var d = this.ox;
        if (b != null && this.bz != null) {
            return b.getBrush1(a, this.bz.count);
        }
        else if (c != null) {
            return c.getBrushByIndex(a, this.o3);
        }
        else if (d != null) {
            return d.getBrush(a);
        }
        return null;
    };
    Object.defineProperty(BubbleSeries.prototype, "legendReady", {
        get: function () {
            return this.o6 != null && this.o6.count != 0;
        },
        enumerable: true,
        configurable: true
    });
    Object.defineProperty(BubbleSeries.prototype, "minScaleText", {
        get: function () {
            return (Math.round(this.o6.minimum * 1000) / 1000).toString();
        },
        enumerable: true,
        configurable: true
    });
    Object.defineProperty(BubbleSeries.prototype, "maxScaleText", {
        get: function () {
            return (Math.round(this.o6.maximum * 1000) / 1000).toString();
        },
        enumerable: true,
        configurable: true
    });
    BubbleSeries.prototype.forScaleColors = function (a) {
        for (var b = 0; b < this.o6.count; b++) {
            if (this.ox == null || !this.ox.isReady) {
                return false;
            }
            var c = NaN;
            if (this.o3 != null) {
                c = (this.o3.item(b) - this.o3.minimum) / (this.o3.maximum - this.o3.minimum);
            }
            var d = (this.o6.item(b) - this.o6.minimum) / (this.o6.maximum - this.o6.minimum);
            if (isNaN_(c)) {
                c = 0;
            }
            if (isNaN_(d)) {
                d = c;
            }
            var e = this.mv;
            var f = this.pu(b);
            var g = f != null ? f : e;
            a(g, d);
        }
        return true;
    };
    BubbleSeries.prototype.fs = function (a, b) {
        var c = this.gu(b);
        if (c == BubbleSeries.$$p[2]) {
            return this.ft(a, b, this.pf);
        }
        if (c == BubbleSeries.$$p[3]) {
            return this.ft(a, b, this.pi);
        }
        if (c == ScatterBase.$$p[4]) {
            return this.ft(a, b, this.nr);
        }
        if (c == ScatterBase.$$p[6]) {
            return this.ft(a, b, this.nv);
        }
        if (c == BubbleSeries.$$p[0]) {
            return this.ft(a, b, this.pb);
        }
        return _super.prototype.fs.call(this, a, b);
    };
    Object.defineProperty(BubbleSeries.prototype, "o6", {
        get: function () {
            return this.o2;
        },
        set: function (a) {
            if (this.o2 != a) {
                var b = this.o6;
                this.o2 = a;
                this.raisePropertyChanged("RadiusColumn", b, this.o6);
            }
        },
        enumerable: true,
        configurable: true
    });
    Object.defineProperty(BubbleSeries.prototype, "o5", {
        get: function () {
            return this.o1;
        },
        set: function (a) {
            if (this.o1 != a) {
                var b = this.o5;
                this.o1 = a;
                this.raisePropertyChanged("LabelColumn", b, this.o5);
            }
        },
        enumerable: true,
        configurable: true
    });
    Object.defineProperty(BubbleSeries.prototype, "o3", {
        get: function () {
            return this.o0;
        },
        set: function (a) {
            if (this.o0 != a) {
                var b = this.o3;
                this.o0 = a;
                this.raisePropertyChanged("FillColumn", b, this.o3);
            }
        },
        enumerable: true,
        configurable: true
    });
    BubbleSeries.prototype.ny = function (a, b, c, d, e) {
        if (c <= this.nk) {
            b.g = new Dictionary$2(Base.$, OwnedPoint.$, 1, c);
        }
        var f = this.nk;
        var g = this.bz;
        var h;
        var i;
        var j = this.getEffectiveViewport1(a);
        var k = new ScalerParams(0, d, e, this.m4.d, j);
        var l = new ScalerParams(0, d, e, this.m4.e, j);
        var _loop_1 = function (m) {
            h = this_1.nd.item(m);
            i = this_1.nf.item(m);
            var n = { $type: Point_$type, x: this_1.m4.a.dw(h, k), y: this_1.m4.b.dw(i, l) };
            if (!isInfinity(n.x) && !isInfinity(n.y)) {
                var o_1 = g.item(m);
                if (c <= f) {
                    if (!b.g.containsKey(o_1)) {
                        var p_1 = { $type: Point_$type, x: h, y: i };
                        b.g.addItem(o_1, ((function () {
                            var $ret = new OwnedPoint();
                            $ret.a = o_1;
                            $ret.b = p_1;
                            $ret.c = n;
                            return $ret;
                        })()));
                    }
                }
            }
        };
        var this_1 = this;
        for (var m = 0; m < c; m++) {
            _loop_1(m);
        }
    };
    BubbleSeries.prototype.n2 = function (a, b) {
        var c = typeCast(BubbleSeriesView.$, b);
        var d = c.cr;
        d.m = this.o6;
        _super.prototype.n2.call(this, a, b);
        var e = Math.min(this.nd != null ? this.nd.count : 0, this.nf != null ? this.nf.count : 0);
        if (e < 1) {
            return;
        }
        c.dc();
        c.dd();
    };
    BubbleSeries.prototype.pm = function () {
        if (this.bs == null) {
            return;
        }
        if (this.aw == null) {
            return;
        }
        if (this.aw.isItemwise) {
            var a = this.aw;
            this.aw.clearLegendItemsForSeries(this);
            this.pl();
            a.renderItemwiseContent(this);
        }
        if (this.aw.isScale) {
            var b = this.aw;
            b.restoreOriginalState();
            b.initializeLegend(this);
        }
    };
    BubbleSeries.o8 = function (a, b, c, d, e) {
        if (e <= a || isNaN_(e) || isInfinity(e)) {
            return c;
        }
        if (e >= b) {
            return d;
        }
        var f = c + ((d - c) / (b - a)) * (e - a);
        return f;
    };
    BubbleSeries.o9 = function (a, b, c, d, logBase_, e) {
        var f = logBase(e, logBase_);
        var g = logBase(a, logBase_);
        var h = logBase(b, logBase_);
        return BubbleSeries.o8(g, h, c, d, f);
    };
    BubbleSeries.prototype.dw = function (a, b, c) {
        var d = _super.prototype.dw.call(this, a, b, c);
        if (this.o6 == null || this.bz == null || this.o6.count == 0 || this.bz.count != this.o6.count) {
            d = false;
        }
        return d;
    };
    BubbleSeries.prototype.ni = function (a, b) {
        if (b != 3) {
            return true;
        }
        if (a == null) {
            return true;
        }
        if (this.nr == a || this.nv == a || this.pi == a) {
            return true;
        }
        return false;
    };
    BubbleSeries.prototype.pl = function () {
        var _this = this;
        var a = typeCast(IChartLegend_$type, this.aw);
        if (a == null || this.bz == null) {
            return;
        }
        this.o7 = new List$1(UIElement.$, 0);
        var b = this.bz;
        var _loop_2 = function (c) {
            var d = null;
            if (typeCast(ValueBrushScale.$, this_2.ox) !== null && this_2.o3 != null) {
                d = this_2.ox.getBrushByIndex(c, this_2.o3);
            }
            else if (typeCast(CustomPaletteBrushScale.$, this_2.ox) !== null) {
                d = this_2.ox.getBrush1(c, b.count);
            }
            else if (this_2.ox != null) {
                d = this_2.ox.getBrush(c);
            }
            var e = new ContentControl();
            var f = this_2.o5 != null && this_2.o5.item(c) != null ? this_2.o5.item(c).toString() : "";
            e.content = ((function () {
                var $ret = new DataContext();
                $ret.series = _this;
                $ret.item = b.item(c);
                $ret.itemBrush = d;
                $ret.itemLabel = f;
                return $ret;
            })());
            var g = this_2.jy;
            if (g == null) {
                g = this_2.bi.bi(this_2.bk);
            }
            e.ah = g;
            this_2.o7.add(e);
        };
        var this_2 = this;
        for (var c = 0; c < b.count; c++) {
            _loop_2(c);
        }
    };
    BubbleSeries.prototype.hy = function (a, b, c, d) {
        _super.prototype.hy.call(this, a, b, c, d);
        this.pm();
    };
    BubbleSeries.prototype.id = function () {
        _super.prototype.id.call(this);
        this.pm();
    };
    BubbleSeries.prototype.ij = function () {
        _super.prototype.ij.call(this);
        this.pm();
    };
    BubbleSeries.prototype.iz = function (a, b, c, d) {
        var e_1, _a;
        _super.prototype.iz.call(this, a, b, c, d);
        switch (b) {
            case "FastItemsSource":
                if (typeCast(IFastItemsSource_$type, c) != null) {
                    c.deregisterColumn(this.o6);
                    c.deregisterColumn(this.o3);
                    c.deregisterColumn(this.o5);
                    this.o6 = null;
                    this.o3 = null;
                    this.o5 = null;
                }
                if (typeCast(IFastItemsSource_$type, d) != null) {
                    this.o6 = this.bw(this.pi);
                    if (!stringIsNullOrEmpty(this.pb)) {
                        this.o3 = this.bw(this.pb);
                    }
                    this.o5 = this.by(this.pf);
                }
                this.jd(false);
                this.pm();
                break;
            case BubbleSeries.$$p[3]:
                if (this.bz != null) {
                    this.bz.deregisterColumn(this.o6);
                    this.o6 = this.bw(this.pi);
                    this.pm();
                }
                break;
            case "RadiusColumn":
                this.m5.ct.g$i();
                this.jd(false);
                this.il();
                break;
            case BubbleSeries.$$p[4]:
                this.jd(false);
                this.ik();
                break;
            case "DiscreteLegendItemTemplate":
                this.pm();
                break;
            case BubbleSeries.$$p[1]:
                this.jd(false);
                this.pm();
                this.ik();
                break;
            case "FillColumn":
                this.jd(false);
                this.ik();
                break;
            case BubbleSeries.$$p[0]:
                if (this.bz != null) {
                    this.bz.deregisterColumn(this.o3);
                    this.o3 = this.bw(this.pb);
                    this.pm();
                }
                break;
            case BubbleSeries.$$p[2]:
                if (this.bz != null) {
                    this.bz.deregisterColumn(this.o5);
                    this.o5 = this.by(this.pf);
                    this.pm();
                }
                break;
            case "ActualLegend":
                var e = typeCast(IChartLegend_$type, c);
                if (e != null) {
                    e.clearLegendItemsForSeries(this);
                }
                if (e != null && e.isScale) {
                    var f = e;
                    var g = true;
                    var h = null;
                    if (this.bs != null) {
                        try {
                            for (var _b = tslib_1.__values(fromEnum(this.bs.series)), _c = _b.next(); !_c.done; _c = _b.next()) {
                                var i = _c.value;
                                if (i.legend == f) {
                                    h = i;
                                    g = false;
                                }
                            }
                        }
                        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 (g) {
                        f.restoreOriginalState();
                    }
                    else {
                        f.initializeLegend(typeCast(IScaleLegendSeries_$type, h));
                    }
                }
                this.pm();
                break;
            case "SeriesViewer":
                this.pm();
                break;
        }
    };
    BubbleSeries.prototype.po = function (a, b, c, d) {
        var e = this.o6.minimum;
        var f = this.o6.maximum;
        var g = c.width;
        if (!this.bi.br.isEmpty) {
            g = this.bi.br.width;
        }
        else if (this.bs != null && !this.bs.m3.isEmpty) {
            g = this.bs.m3.width;
        }
        var h = DeviceUtils.c(g);
        var i = this.oz || ((function () {
            var $ret = new SizeScale();
            $ret.minimumValue = h / 10;
            $ret.maximumValue = h / 5;
            return $ret;
        })());
        if (i != null) {
            var j = i.minimumValue;
            var k = i.maximumValue;
            var l = i.logarithmBase;
            if (!i.l.contains(this)) {
                i.l.add(this);
            }
            if (i.isLogarithmic) {
                for (var m = 0; m < b.count; m++) {
                    b._inner[m] = BubbleSeries.o9(e, f, j, k, l, b._inner[m]);
                }
            }
            else {
                for (var n = 0; n < b.count; n++) {
                    b._inner[n] = BubbleSeries.o8(e, f, j, k, b._inner[n]);
                }
            }
        }
        var o = 1;
        o = DeviceUtils.d();
        var p = this.oz == null;
        if (d) {
            var q = c.width / g;
            for (var r = 0; r < b.count; r++) {
                if (p) {
                    b._inner[r] = b._inner[r] / o;
                }
                b._inner[r] = b._inner[r] * q;
            }
        }
        for (var s = 0; s < a.count; s++) {
            var t = a._inner[s];
            if (p && !d) {
                t.width = Math.max(0, b._inner[s] / o);
                t.height = Math.max(0, b._inner[s] / o);
            }
            else {
                t.width = Math.max(0, b._inner[s]);
                t.height = Math.max(0, b._inner[s]);
            }
        }
    };
    BubbleSeries.prototype.pn = function (a) {
        if (this.ox != null && !this.ox.o.contains(this)) {
            this.ox.o.add(this);
        }
        var b = typeCast(CustomPaletteBrushScale.$, this.ox);
        var c = typeCast(ValueBrushScale.$, this.ox);
        var d = this.ox;
        var e = this.ox == null || !this.ox.isReady || (c != null && this.pb == null);
        if (e) {
            this.oy.db();
            var f = typeCast(BubbleSeriesView.$, this.bh);
            if (f != null) {
                f.db();
            }
            return;
        }
        var g = a.count;
        var h = this.bz;
        for (var i = 0; i < g; i++) {
            var j = a._inner[i];
            var k = typeCast(DataContext.$, j.content);
            if (k != null) {
                var l = null;
                var m = h.indexOf(k.item);
                if (b != null) {
                    l = b.getBrush1(m, h.count);
                }
                else if (c != null) {
                    l = c.getBrushByIndex(m, this.o3);
                }
                else if (d != null) {
                    l = d.getBrush(m);
                }
                k.itemBrush = l;
            }
        }
    };
    BubbleSeries.prototype.get_cy = function () {
        return false;
    };
    Object.defineProperty(BubbleSeries.prototype, "actualMarkerBrush", {
        get: function () {
            return this.mv;
        },
        enumerable: true,
        configurable: true
    });
    BubbleSeries.$t = markType(BubbleSeries, 'BubbleSeries', ScatterBase.$, [IScaleLegendSeries_$type]);
    BubbleSeries.$$p = markDep(DependencyProperty, PropertyMetadata, BubbleSeries, 'raisePropertyChanged', ['FillMemberPath:pb:pp', [2], 'FillScale:ox:pq', [BrushScale.$], 'LabelMemberPath:pf:pr', [2], 'RadiusMemberPath:pi:ps', [2, null], 'RadiusScale:oz:pt', [SizeScale.$]]);
    return BubbleSeries;
}(ScatterBase));
export { BubbleSeries };
/**
 * @hidden
 */
var CustomPaletteBrushScale = /** @class */ (function (_super) {
    tslib_1.__extends(CustomPaletteBrushScale, _super);
    function CustomPaletteBrushScale() {
        return _super.call(this) || this;
    }
    CustomPaletteBrushScale.prototype.getBrush1 = function (a, b) {
        if (this.brushes == null || this.brushes.count == 0) {
            return null;
        }
        if (this.brushSelectionMode == 0) {
            return _super.prototype.getBrush.call(this, a % this.brushes.count);
        }
        var c = BubbleSeries.o8(0, b - 1, 0, this.brushes.count - 1, a);
        return this.v(c);
    };
    CustomPaletteBrushScale.prototype.get_isReady = function () {
        return this.brushes != null && this.brushes.count > 0;
    };
    CustomPaletteBrushScale.$t = markType(CustomPaletteBrushScale, 'CustomPaletteBrushScale', BrushScale.$);
    CustomPaletteBrushScale.$$p = markDep(DependencyProperty, PropertyMetadata, CustomPaletteBrushScale, 'r', ['BrushSelectionMode', [BrushSelectionMode_$type, enumGetBox(BrushSelectionMode_$type, 0)]]);
    return CustomPaletteBrushScale;
}(BrushScale));
export { CustomPaletteBrushScale };
/**
 * @hidden
 */
var BubbleSeriesView = /** @class */ (function (_super) {
    tslib_1.__extends(BubbleSeriesView, _super);
    function BubbleSeriesView(a) {
        var _this = _super.call(this, a) || this;
        _this.da = null;
        _this.da = a;
        _this.ct = new ScatterTrendLineManager();
        return _this;
    }
    BubbleSeriesView.prototype.ap = function () {
        _super.prototype.ap.call(this);
        if (!this.n) {
            this.by.l1 = 2;
            this.e.bj = 4;
        }
    };
    BubbleSeriesView.prototype.cq = function () {
        var _this = this;
        return new BubbleMarkerManager(function (a) { return _this.cu.item(a); }, function (a) { return _this.cs.m4.c.item(a); }, runOn(this, this.c4), runOn(this, this.cn), runOn(this, this.cv));
    };
    BubbleSeriesView.prototype.dc = function () {
        var a = this.cr;
        this.da.po(a.n, a.o, this.br, this == this.e.bh);
        this.an();
    };
    BubbleSeriesView.prototype.dd = function () {
        var a = this.cr;
        this.da.pn(a.n);
    };
    BubbleSeriesView.prototype.db = function () {
        var e_2, _a;
        var a = this.cr;
        try {
            for (var _b = tslib_1.__values(fromEnum(a.n)), _c = _b.next(); !_c.done; _c = _b.next()) {
                var b = _c.value;
                var c = typeCast(DataContext.$, b.content);
                if (c != null) {
                    c.itemBrush = null;
                }
            }
        }
        catch (e_2_1) { e_2 = { error: e_2_1 }; }
        finally {
            try {
                if (_c && !_c.done && (_a = _b.return)) _a.call(_b);
            }
            finally { if (e_2) throw e_2.error; }
        }
    };
    BubbleSeriesView.prototype.getDefaultTooltipTemplate = function () {
        var a = "<div class='ui-chart-default-tooltip-content'><span";
        var b = this.e.a0.a$q(this.e);
        if (!stringIsNullOrEmpty(b)) {
            a += " style='color:" + b + "'";
        }
        a += ">" + this.da.fx + "</span><br/><span>" + "(${item." + this.da.nr + "}, ${item." + this.da.nv + "})</span>";
        if (!stringIsNullOrEmpty(this.da.pi)) {
            a += "<span>, Radius: ${item." + this.da.pi + "}</span>";
        }
        a += "</div>";
        return a;
    };
    BubbleSeriesView.$t = markType(BubbleSeriesView, 'BubbleSeriesView', ScatterBaseView.$);
    return BubbleSeriesView;
}(ScatterBaseView));
export { BubbleSeriesView };
//# sourceMappingURL=BubbleSeries_combined.js.map