/*
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/ES5/IScaleLegendSeries";
import { List$1 } from "igniteui-angular-core/ES5/List$1";
import { UIElement } from "igniteui-angular-core/ES5/UIElement";
import { Base, Type, typeCast, Point_$type, fromEnum, markType, enumGetBox, runOn } from "igniteui-angular-core/ES5/type";
import { DependencyProperty } from "igniteui-angular-core/ES5/DependencyProperty";
import { SizeScale } from "./SizeScale";
import { BrushScale } from "./BrushScale";
import { ScatterFrame } from "./ScatterFrame";
import { IChartLegend_$type } from "igniteui-angular-core/ES5/IChartLegend";
import { ValueBrushScale } from "./ValueBrushScale";
import { IFastItemsSource_$type } from "igniteui-angular-core/ES5/IFastItemsSource";
import { ScatterBaseView } from "./ScatterBaseView";
import { ScalerParams } from "./ScalerParams";
import { Dictionary$2 } from "igniteui-angular-core/ES5/Dictionary$2";
import { OwnedPoint } from "./OwnedPoint";
import { BubbleMarkerManager } from "./BubbleMarkerManager";
import { ContentControl } from "igniteui-angular-core/ES5/ContentControl";
import { DataContext } from "igniteui-angular-core/ES5/DataContext";
import { DeviceUtils } from "igniteui-angular-core/ES5/DeviceUtils";
import { PropertyMetadata } from "igniteui-angular-core/ES5/PropertyMetadata";
import { isNaN_, isInfinity, logBase } from "igniteui-angular-core/ES5/number";
import { stringIsNullOrEmpty } from "igniteui-angular-core/ES5/string";
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.po = null;
        _this.pn = null;
        _this.oz = null;
        _this.ou = null;
        _this.ot = null;
        _this.os = null;
        _this.ab = BubbleSeries.$;
        _this.m1 = new ScatterFrame();
        _this.m3 = new ScatterFrame();
        _this.m0 = new ScatterFrame();
        return _this;
    }
    BubbleSeries.prototype.bf = function () {
        return new BubbleSeriesView(this);
    };
    BubbleSeries.prototype.im = function (a) {
        _super.prototype.im.call(this, a);
        this.oq = a;
    };
    BubbleSeries.prototype.isAttachedTo = function (a) {
        return this.aw == a;
    };
    BubbleSeries.prototype.ci = function () {
        return true;
    };
    BubbleSeries.prototype.h0 = function (a) {
        _super.prototype.h0.call(this, a);
        if (this.ox != null && this.oz != null && this.oz.count > 0) {
            for (var b = 0; b < this.oz.count; b++) {
                a(this.oz._inner[b]);
            }
        }
    };
    Object.defineProperty(BubbleSeries.prototype, "ow", {
        get: function () {
            return this.oy;
        },
        enumerable: true,
        configurable: true
    });
    BubbleSeries.prototype.pm = function (a) {
        var b = typeCast(CustomPaletteBrushScale.$, this.op);
        var c = typeCast(ValueBrushScale.$, this.op);
        var d = this.op;
        if (b != null && this.bz != null) {
            return b.getBrush1(a, this.bz.count);
        }
        else if (c != null) {
            return c.getBrushByIndex(a, this.ov);
        }
        else if (d != null) {
            return d.getBrush(a);
        }
        return null;
    };
    Object.defineProperty(BubbleSeries.prototype, "legendReady", {
        get: function () {
            return this.oy != null && this.oy.count != 0;
        },
        enumerable: true,
        configurable: true
    });
    Object.defineProperty(BubbleSeries.prototype, "minScaleText", {
        get: function () {
            return (Math.round(this.oy.minimum * 1000) / 1000).toString();
        },
        enumerable: true,
        configurable: true
    });
    Object.defineProperty(BubbleSeries.prototype, "maxScaleText", {
        get: function () {
            return (Math.round(this.oy.maximum * 1000) / 1000).toString();
        },
        enumerable: true,
        configurable: true
    });
    BubbleSeries.prototype.forScaleColors = function (a) {
        for (var b = 0; b < this.oy.count; b++) {
            if (this.op == null || !this.op.isReady) {
                return false;
            }
            var c = NaN;
            if (this.ov != null) {
                c = (this.ov.item(b) - this.ov.minimum) / (this.ov.maximum - this.ov.minimum);
            }
            var d = (this.oy.item(b) - this.oy.minimum) / (this.oy.maximum - this.oy.minimum);
            if (isNaN_(c)) {
                c = 0;
            }
            if (isNaN_(d)) {
                d = c;
            }
            var e = this.mn;
            var f = this.pm(b);
            var g = f != null ? f : e;
            a(g, d);
        }
        return true;
    };
    Object.defineProperty(BubbleSeries.prototype, "oy", {
        get: function () {
            return this.ou;
        },
        set: function (a) {
            if (this.ou != a) {
                var b = this.oy;
                this.ou = a;
                this.raisePropertyChanged("RadiusColumn", b, this.oy);
            }
        },
        enumerable: true,
        configurable: true
    });
    Object.defineProperty(BubbleSeries.prototype, "ox", {
        get: function () {
            return this.ot;
        },
        set: function (a) {
            if (this.ot != a) {
                var b = this.ox;
                this.ot = a;
                this.raisePropertyChanged("LabelColumn", b, this.ox);
            }
        },
        enumerable: true,
        configurable: true
    });
    Object.defineProperty(BubbleSeries.prototype, "ov", {
        get: function () {
            return this.os;
        },
        set: function (a) {
            if (this.os != a) {
                var b = this.ov;
                this.os = a;
                this.raisePropertyChanged("FillColumn", b, this.ov);
            }
        },
        enumerable: true,
        configurable: true
    });
    BubbleSeries.prototype.nq = function (a, b, c, d, e) {
        if (c <= this.nc) {
            b.g = new Dictionary$2(Base.$, OwnedPoint.$, 1, c);
        }
        var f = this.nc;
        var g = this.bz;
        var h;
        var i;
        var j = this.getEffectiveViewport1(a);
        var k = new ScalerParams(0, d, e, this.mw.d, j);
        var l = new ScalerParams(0, d, e, this.mw.e, j);
        var _loop_1 = function (m) {
            h = this_1.m5.item(m);
            i = this_1.m7.item(m);
            var n = { $type: Point_$type, x: this_1.mw.a.dt(h, k), y: this_1.mw.b.dt(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.nu = function (a, b) {
        var c = typeCast(BubbleSeriesView.$, b);
        var d = c.cr;
        d.m = this.oy;
        _super.prototype.nu.call(this, a, b);
        var e = Math.min(this.m5 != null ? this.m5.count : 0, this.m7 != null ? this.m7.count : 0);
        if (e < 1) {
            return;
        }
        c.dc();
        c.dd();
    };
    BubbleSeries.prototype.pe = function () {
        if (this.bs == null) {
            return;
        }
        if (this.aw == null) {
            return;
        }
        if (this.aw.isItemwise) {
            var a = this.aw;
            this.aw.clearLegendItemsForSeries(this);
            this.pd();
            a.renderItemwiseContent(this);
        }
        if (this.aw.isScale) {
            var b = this.aw;
            b.restoreOriginalState();
            b.initializeLegend(this);
        }
    };
    BubbleSeries.o0 = 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.o1 = function (a, b, c, d, logBase_, e) {
        var f = logBase(e, logBase_);
        var g = logBase(a, logBase_);
        var h = logBase(b, logBase_);
        return BubbleSeries.o0(g, h, c, d, f);
    };
    BubbleSeries.prototype.dv = function (a, b, c) {
        var d = _super.prototype.dv.call(this, a, b, c);
        if (this.oy == null || this.bz == null || this.oy.count == 0 || this.bz.count != this.oy.count) {
            d = false;
        }
        return d;
    };
    BubbleSeries.prototype.na = function (a, b) {
        if (b != 3) {
            return true;
        }
        if (a == null) {
            return true;
        }
        if (this.nj == a || this.nn == a || this.pa == a) {
            return true;
        }
        return false;
    };
    BubbleSeries.prototype.pd = function () {
        var _this = this;
        var a = typeCast(IChartLegend_$type, this.aw);
        if (a == null || this.bz == null) {
            return;
        }
        this.oz = new List$1(UIElement.$, 0);
        var b = this.bz;
        var _loop_2 = function (c) {
            var d = null;
            if (typeCast(ValueBrushScale.$, this_2.op) !== null && this_2.ov != null) {
                d = this_2.op.getBrushByIndex(c, this_2.ov);
            }
            else if (typeCast(CustomPaletteBrushScale.$, this_2.op) !== null) {
                d = this_2.op.getBrush1(c, b.count);
            }
            else if (this_2.op != null) {
                d = this_2.op.getBrush(c);
            }
            var e = new ContentControl();
            var f = this_2.ox != null && this_2.ox.item(c) != null ? this_2.ox.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.jq;
            if (g == null) {
                g = this_2.bi.bi(this_2.bk);
            }
            e.ah = g;
            this_2.oz.add(e);
        };
        var this_2 = this;
        for (var c = 0; c < b.count; c++) {
            _loop_2(c);
        }
    };
    BubbleSeries.prototype.hs = function (a, b, c, d) {
        _super.prototype.hs.call(this, a, b, c, d);
        this.pe();
    };
    BubbleSeries.prototype.h6 = function () {
        _super.prototype.h6.call(this);
        this.pe();
    };
    BubbleSeries.prototype.ib = function () {
        _super.prototype.ib.call(this);
        this.pe();
    };
    BubbleSeries.prototype.is = function (a, b, c, d) {
        var e_1, _a;
        _super.prototype.is.call(this, a, b, c, d);
        switch (b) {
            case "FastItemsSource":
                if (typeCast(IFastItemsSource_$type, c) != null) {
                    c.deregisterColumn(this.oy);
                    c.deregisterColumn(this.ov);
                    c.deregisterColumn(this.ox);
                    this.oy = null;
                    this.ov = null;
                    this.ox = null;
                }
                if (typeCast(IFastItemsSource_$type, d) != null) {
                    this.oy = this.bw(this.pa);
                    if (!stringIsNullOrEmpty(this.o3)) {
                        this.ov = this.bw(this.o3);
                    }
                    this.ox = this.by(this.o7);
                }
                this.i5(false);
                this.pe();
                break;
            case BubbleSeries.$$p[3]:
                if (this.bz != null) {
                    this.bz.deregisterColumn(this.oy);
                    this.oy = this.bw(this.pa);
                    this.pe();
                }
                break;
            case "RadiusColumn":
                this.mx.ct.g$i();
                this.i5(false);
                this.id();
                break;
            case BubbleSeries.$$p[4]:
                this.i5(false);
                this.ic();
                break;
            case "DiscreteLegendItemTemplate":
                this.pe();
                break;
            case BubbleSeries.$$p[1]:
                this.i5(false);
                this.pe();
                this.ic();
                break;
            case "FillColumn":
                this.i5(false);
                this.ic();
                break;
            case BubbleSeries.$$p[0]:
                if (this.bz != null) {
                    this.bz.deregisterColumn(this.ov);
                    this.ov = this.bw(this.o3);
                    this.pe();
                }
                break;
            case BubbleSeries.$$p[2]:
                if (this.bz != null) {
                    this.bz.deregisterColumn(this.ox);
                    this.ox = this.by(this.o7);
                    this.pe();
                }
                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.pe();
                break;
            case "SeriesViewer":
                this.pe();
                break;
        }
    };
    BubbleSeries.prototype.pg = function (a, b, c, d) {
        var e = this.oy.minimum;
        var f = this.oy.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.or || ((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.o1(e, f, j, k, l, b._inner[m]);
                }
            }
            else {
                for (var n = 0; n < b.count; n++) {
                    b._inner[n] = BubbleSeries.o0(e, f, j, k, b._inner[n]);
                }
            }
        }
        var o = 1;
        o = DeviceUtils.d();
        var p = this.or == 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.pf = function (a) {
        if (this.op != null && !this.op.o.contains(this)) {
            this.op.o.add(this);
        }
        var b = typeCast(CustomPaletteBrushScale.$, this.op);
        var c = typeCast(ValueBrushScale.$, this.op);
        var d = this.op;
        var e = this.op == null || !this.op.isReady || (c != null && this.o3 == null);
        if (e) {
            this.oq.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.ov);
                }
                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.mn;
        },
        enumerable: true,
        configurable: true
    });
    BubbleSeries.$t = markType(BubbleSeries, 'BubbleSeries', ScatterBase.$, [IScaleLegendSeries_$type]);
    return BubbleSeries;
}(ScatterBase));
export { BubbleSeries };
Type.dep(DependencyProperty, PropertyMetadata, BubbleSeries, 'raisePropertyChanged', ['FillMemberPath:o3:ph', [2], 'FillScale:op:pi', [BrushScale.$], 'LabelMemberPath:o7:pj', [2], 'RadiusMemberPath:pa:pk', [2, null], 'RadiusScale:or:pl', [SizeScale.$]]);
/**
 * @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.o0(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.$);
    return CustomPaletteBrushScale;
}(BrushScale));
export { CustomPaletteBrushScale };
Type.dep(DependencyProperty, PropertyMetadata, CustomPaletteBrushScale, 'r', ['BrushSelectionMode', [BrushSelectionMode_$type, enumGetBox(BrushSelectionMode_$type, 0)]]);
/**
 * @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.lt = 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.mw.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.pg(a.n, a.o, this.br, this == this.e.bh);
        this.an();
    };
    BubbleSeriesView.prototype.dd = function () {
        var a = this.cr;
        this.da.pf(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.fs + "</span><br/><span>" + "(${item." + this.da.nj + "}, ${item." + this.da.nn + "})</span>";
        if (!stringIsNullOrEmpty(this.da.pa)) {
            a += "<span>, Radius: ${item." + this.da.pa + "}</span>";
        }
        a += "</div>";
        return a;
    };
    BubbleSeriesView.$t = markType(BubbleSeriesView, 'BubbleSeriesView', ScatterBaseView.$);
    return BubbleSeriesView;
}(ScatterBaseView));
export { BubbleSeriesView };
//# sourceMappingURL=BubbleSeries_combined.js.map