/*
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 { ScatterBase } from "./ScatterBase";
import { IScaleLegendSeries_$type } from "igniteui-angular-core/ES2015/IScaleLegendSeries";
import { List$1 } from "igniteui-angular-core/ES2015/List$1";
import { UIElement } from "igniteui-angular-core/ES2015/UIElement";
import { Base, Type, typeCast, Point_$type, fromEnum, markType, enumGetBox, runOn } from "igniteui-angular-core/ES2015/type";
import { DependencyProperty } from "igniteui-angular-core/ES2015/DependencyProperty";
import { SizeScale } from "./SizeScale";
import { BrushScale } from "./BrushScale";
import { ScatterFrame } from "./ScatterFrame";
import { IChartLegend_$type } from "igniteui-angular-core/ES2015/IChartLegend";
import { ValueBrushScale } from "./ValueBrushScale";
import { IFastItemsSource_$type } from "igniteui-angular-core/ES2015/IFastItemsSource";
import { ScatterBaseView } from "./ScatterBaseView";
import { ScalerParams } from "./ScalerParams";
import { Dictionary$2 } from "igniteui-angular-core/ES2015/Dictionary$2";
import { OwnedPoint } from "./OwnedPoint";
import { BubbleMarkerManager } from "./BubbleMarkerManager";
import { ContentControl } from "igniteui-angular-core/ES2015/ContentControl";
import { DataContext } from "igniteui-angular-core/ES2015/DataContext";
import { DeviceUtils } from "igniteui-angular-core/ES2015/DeviceUtils";
import { PropertyMetadata } from "igniteui-angular-core/ES2015/PropertyMetadata";
import { isNaN_, isInfinity, logBase } from "igniteui-angular-core/ES2015/number";
import { stringIsNullOrEmpty } from "igniteui-angular-core/ES2015/string";
import { BrushSelectionMode_$type } from "./BrushSelectionMode";
import { ScatterTrendLineManager } from "./ScatterTrendLineManager";
/**
 * @hidden
 */
export class BubbleSeries extends ScatterBase {
    constructor() {
        super();
        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();
    }
    bf() {
        return new BubbleSeriesView(this);
    }
    im(a) {
        super.im(a);
        this.oq = a;
    }
    isAttachedTo(a) {
        return this.aw == a;
    }
    ci() {
        return true;
    }
    h0(a) {
        super.h0(a);
        if (this.ox != null && this.oz != null && this.oz.count > 0) {
            for (let b = 0; b < this.oz.count; b++) {
                a(this.oz._inner[b]);
            }
        }
    }
    get ow() {
        return this.oy;
    }
    pm(a) {
        let b = typeCast(CustomPaletteBrushScale.$, this.op);
        let c = typeCast(ValueBrushScale.$, this.op);
        let 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;
    }
    get legendReady() {
        return this.oy != null && this.oy.count != 0;
    }
    get minScaleText() {
        return (Math.round(this.oy.minimum * 1000) / 1000).toString();
    }
    get maxScaleText() {
        return (Math.round(this.oy.maximum * 1000) / 1000).toString();
    }
    forScaleColors(a) {
        for (let b = 0; b < this.oy.count; b++) {
            if (this.op == null || !this.op.isReady) {
                return false;
            }
            let c = NaN;
            if (this.ov != null) {
                c = (this.ov.item(b) - this.ov.minimum) / (this.ov.maximum - this.ov.minimum);
            }
            let d = (this.oy.item(b) - this.oy.minimum) / (this.oy.maximum - this.oy.minimum);
            if (isNaN_(c)) {
                c = 0;
            }
            if (isNaN_(d)) {
                d = c;
            }
            let e = this.mn;
            let f = this.pm(b);
            let g = f != null ? f : e;
            a(g, d);
        }
        return true;
    }
    get oy() {
        return this.ou;
    }
    set oy(a) {
        if (this.ou != a) {
            let b = this.oy;
            this.ou = a;
            this.raisePropertyChanged("RadiusColumn", b, this.oy);
        }
    }
    get ox() {
        return this.ot;
    }
    set ox(a) {
        if (this.ot != a) {
            let b = this.ox;
            this.ot = a;
            this.raisePropertyChanged("LabelColumn", b, this.ox);
        }
    }
    get ov() {
        return this.os;
    }
    set ov(a) {
        if (this.os != a) {
            let b = this.ov;
            this.os = a;
            this.raisePropertyChanged("FillColumn", b, this.ov);
        }
    }
    nq(a, b, c, d, e) {
        if (c <= this.nc) {
            b.g = new Dictionary$2(Base.$, OwnedPoint.$, 1, c);
        }
        let f = this.nc;
        let g = this.bz;
        let h;
        let i;
        let j = this.getEffectiveViewport1(a);
        let k = new ScalerParams(0, d, e, this.mw.d, j);
        let l = new ScalerParams(0, d, e, this.mw.e, j);
        for (let m = 0; m < c; m++) {
            h = this.m5.item(m);
            i = this.m7.item(m);
            let n = { $type: Point_$type, x: this.mw.a.dt(h, k), y: this.mw.b.dt(i, l) };
            if (!isInfinity(n.x) && !isInfinity(n.y)) {
                let o = g.item(m);
                if (c <= f) {
                    if (!b.g.containsKey(o)) {
                        let p = { $type: Point_$type, x: h, y: i };
                        b.g.addItem(o, ((() => {
                            let $ret = new OwnedPoint();
                            $ret.a = o;
                            $ret.b = p;
                            $ret.c = n;
                            return $ret;
                        })()));
                    }
                }
            }
        }
    }
    nu(a, b) {
        let c = typeCast(BubbleSeriesView.$, b);
        let d = c.cr;
        d.m = this.oy;
        super.nu(a, b);
        let 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();
    }
    pe() {
        if (this.bs == null) {
            return;
        }
        if (this.aw == null) {
            return;
        }
        if (this.aw.isItemwise) {
            let a = this.aw;
            this.aw.clearLegendItemsForSeries(this);
            this.pd();
            a.renderItemwiseContent(this);
        }
        if (this.aw.isScale) {
            let b = this.aw;
            b.restoreOriginalState();
            b.initializeLegend(this);
        }
    }
    static o0(a, b, c, d, e) {
        if (e <= a || isNaN_(e) || isInfinity(e)) {
            return c;
        }
        if (e >= b) {
            return d;
        }
        let f = c + ((d - c) / (b - a)) * (e - a);
        return f;
    }
    static o1(a, b, c, d, logBase_, e) {
        let f = logBase(e, logBase_);
        let g = logBase(a, logBase_);
        let h = logBase(b, logBase_);
        return BubbleSeries.o0(g, h, c, d, f);
    }
    dv(a, b, c) {
        let d = super.dv(a, b, c);
        if (this.oy == null || this.bz == null || this.oy.count == 0 || this.bz.count != this.oy.count) {
            d = false;
        }
        return d;
    }
    na(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;
    }
    pd() {
        let a = typeCast(IChartLegend_$type, this.aw);
        if (a == null || this.bz == null) {
            return;
        }
        this.oz = new List$1(UIElement.$, 0);
        let b = this.bz;
        for (let c = 0; c < b.count; c++) {
            let d = null;
            if (typeCast(ValueBrushScale.$, this.op) !== null && this.ov != null) {
                d = this.op.getBrushByIndex(c, this.ov);
            }
            else if (typeCast(CustomPaletteBrushScale.$, this.op) !== null) {
                d = this.op.getBrush1(c, b.count);
            }
            else if (this.op != null) {
                d = this.op.getBrush(c);
            }
            let e = new ContentControl();
            let f = this.ox != null && this.ox.item(c) != null ? this.ox.item(c).toString() : "";
            e.content = ((() => {
                let $ret = new DataContext();
                $ret.series = this;
                $ret.item = b.item(c);
                $ret.itemBrush = d;
                $ret.itemLabel = f;
                return $ret;
            })());
            let g = this.jq;
            if (g == null) {
                g = this.bi.bi(this.bk);
            }
            e.ah = g;
            this.oz.add(e);
        }
    }
    hs(a, b, c, d) {
        super.hs(a, b, c, d);
        this.pe();
    }
    h6() {
        super.h6();
        this.pe();
    }
    ib() {
        super.ib();
        this.pe();
    }
    is(a, b, c, d) {
        super.is(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":
                let e = typeCast(IChartLegend_$type, c);
                if (e != null) {
                    e.clearLegendItemsForSeries(this);
                }
                if (e != null && e.isScale) {
                    let f = e;
                    let g = true;
                    let h = null;
                    if (this.bs != null) {
                        for (let i of fromEnum(this.bs.series)) {
                            if (i.legend == f) {
                                h = i;
                                g = false;
                            }
                        }
                    }
                    if (g) {
                        f.restoreOriginalState();
                    }
                    else {
                        f.initializeLegend(typeCast(IScaleLegendSeries_$type, h));
                    }
                }
                this.pe();
                break;
            case "SeriesViewer":
                this.pe();
                break;
        }
    }
    pg(a, b, c, d) {
        let e = this.oy.minimum;
        let f = this.oy.maximum;
        let 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;
        }
        let h = DeviceUtils.c(g);
        let i = this.or || ((() => {
            let $ret = new SizeScale();
            $ret.minimumValue = h / 10;
            $ret.maximumValue = h / 5;
            return $ret;
        })());
        if (i != null) {
            let j = i.minimumValue;
            let k = i.maximumValue;
            let l = i.logarithmBase;
            if (!i.l.contains(this)) {
                i.l.add(this);
            }
            if (i.isLogarithmic) {
                for (let m = 0; m < b.count; m++) {
                    b._inner[m] = BubbleSeries.o1(e, f, j, k, l, b._inner[m]);
                }
            }
            else {
                for (let n = 0; n < b.count; n++) {
                    b._inner[n] = BubbleSeries.o0(e, f, j, k, b._inner[n]);
                }
            }
        }
        let o = 1;
        o = DeviceUtils.d();
        let p = this.or == null;
        if (d) {
            let q = c.width / g;
            for (let r = 0; r < b.count; r++) {
                if (p) {
                    b._inner[r] = b._inner[r] / o;
                }
                b._inner[r] = b._inner[r] * q;
            }
        }
        for (let s = 0; s < a.count; s++) {
            let 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]);
            }
        }
    }
    pf(a) {
        if (this.op != null && !this.op.o.contains(this)) {
            this.op.o.add(this);
        }
        let b = typeCast(CustomPaletteBrushScale.$, this.op);
        let c = typeCast(ValueBrushScale.$, this.op);
        let d = this.op;
        let e = this.op == null || !this.op.isReady || (c != null && this.o3 == null);
        if (e) {
            this.oq.db();
            let f = typeCast(BubbleSeriesView.$, this.bh);
            if (f != null) {
                f.db();
            }
            return;
        }
        let g = a.count;
        let h = this.bz;
        for (let i = 0; i < g; i++) {
            let j = a._inner[i];
            let k = typeCast(DataContext.$, j.content);
            if (k != null) {
                let l = null;
                let 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;
            }
        }
    }
    get_cy() {
        return false;
    }
    get actualMarkerBrush() {
        return this.mn;
    }
}
BubbleSeries.$t = markType(BubbleSeries, 'BubbleSeries', ScatterBase.$, [IScaleLegendSeries_$type]);
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
 */
export class CustomPaletteBrushScale extends BrushScale {
    constructor() {
        super();
    }
    getBrush1(a, b) {
        if (this.brushes == null || this.brushes.count == 0) {
            return null;
        }
        if (this.brushSelectionMode == 0) {
            return super.getBrush(a % this.brushes.count);
        }
        let c = BubbleSeries.o0(0, b - 1, 0, this.brushes.count - 1, a);
        return this.v(c);
    }
    get_isReady() {
        return this.brushes != null && this.brushes.count > 0;
    }
}
CustomPaletteBrushScale.$t = markType(CustomPaletteBrushScale, 'CustomPaletteBrushScale', BrushScale.$);
Type.dep(DependencyProperty, PropertyMetadata, CustomPaletteBrushScale, 'r', ['BrushSelectionMode', [BrushSelectionMode_$type, enumGetBox(BrushSelectionMode_$type, 0)]]);
/**
 * @hidden
 */
export class BubbleSeriesView extends ScatterBaseView {
    constructor(a) {
        super(a);
        this.da = null;
        this.da = a;
        this.ct = new ScatterTrendLineManager();
    }
    ap() {
        super.ap();
        if (!this.n) {
            this.by.lt = 2;
            this.e.bj = 4;
        }
    }
    cq() {
        return new BubbleMarkerManager((a) => this.cu.item(a), (a) => this.cs.mw.c.item(a), runOn(this, this.c4), runOn(this, this.cn), runOn(this, this.cv));
    }
    dc() {
        let a = this.cr;
        this.da.pg(a.n, a.o, this.br, this == this.e.bh);
        this.an();
    }
    dd() {
        let a = this.cr;
        this.da.pf(a.n);
    }
    db() {
        let a = this.cr;
        for (let b of fromEnum(a.n)) {
            let c = typeCast(DataContext.$, b.content);
            if (c != null) {
                c.itemBrush = null;
            }
        }
    }
    getDefaultTooltipTemplate() {
        let a = "<div class='ui-chart-default-tooltip-content'><span";
        let 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.$);
//# sourceMappingURL=BubbleSeries_combined.js.map