/*
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.pv = null;
        this.pu = null;
        this.o6 = null;
        this.o1 = null;
        this.o0 = null;
        this.oz = null;
        this.ab = BubbleSeries.$;
        this.m8 = new ScatterFrame();
        this.na = new ScatterFrame();
        this.m7 = new ScatterFrame();
    }
    bf() {
        return new BubbleSeriesView(this);
    }
    it(a) {
        super.it(a);
        this.ox = a;
    }
    isAttachedTo(a) {
        return this.aw == a;
    }
    ci() {
        return true;
    }
    h6(a) {
        super.h6(a);
        if (this.o4 != null && this.o6 != null && this.o6.count > 0) {
            for (let b = 0; b < this.o6.count; b++) {
                a(this.o6._inner[b]);
            }
        }
    }
    get o3() {
        return this.o5;
    }
    pt(a) {
        let b = typeCast(CustomPaletteBrushScale.$, this.ow);
        let c = typeCast(ValueBrushScale.$, this.ow);
        let d = this.ow;
        if (b != null && this.bz != null) {
            return b.getBrush1(a, this.bz.count);
        }
        else if (c != null) {
            return c.getBrushByIndex(a, this.o2);
        }
        else if (d != null) {
            return d.getBrush(a);
        }
        return null;
    }
    get legendReady() {
        return this.o5 != null && this.o5.count != 0;
    }
    get minScaleText() {
        return (Math.round(this.o5.minimum * 1000) / 1000).toString();
    }
    get maxScaleText() {
        return (Math.round(this.o5.maximum * 1000) / 1000).toString();
    }
    forScaleColors(a) {
        for (let b = 0; b < this.o5.count; b++) {
            if (this.ow == null || !this.ow.isReady) {
                return false;
            }
            let c = NaN;
            if (this.o2 != null) {
                c = (this.o2.item(b) - this.o2.minimum) / (this.o2.maximum - this.o2.minimum);
            }
            let d = (this.o5.item(b) - this.o5.minimum) / (this.o5.maximum - this.o5.minimum);
            if (isNaN_(c)) {
                c = 0;
            }
            if (isNaN_(d)) {
                d = c;
            }
            let e = this.mu;
            let f = this.pt(b);
            let g = f != null ? f : e;
            a(g, d);
        }
        return true;
    }
    fs(a, b) {
        let c = this.gu(b);
        if (c == BubbleSeries.$$p[2]) {
            return this.ft(a, b, this.pe);
        }
        if (c == BubbleSeries.$$p[3]) {
            return this.ft(a, b, this.ph);
        }
        if (c == ScatterBase.$$p[4]) {
            return this.ft(a, b, this.nq);
        }
        if (c == ScatterBase.$$p[6]) {
            return this.ft(a, b, this.nu);
        }
        if (c == BubbleSeries.$$p[0]) {
            return this.ft(a, b, this.pa);
        }
        return super.fs(a, b);
    }
    get o5() {
        return this.o1;
    }
    set o5(a) {
        if (this.o1 != a) {
            let b = this.o5;
            this.o1 = a;
            this.raisePropertyChanged("RadiusColumn", b, this.o5);
        }
    }
    get o4() {
        return this.o0;
    }
    set o4(a) {
        if (this.o0 != a) {
            let b = this.o4;
            this.o0 = a;
            this.raisePropertyChanged("LabelColumn", b, this.o4);
        }
    }
    get o2() {
        return this.oz;
    }
    set o2(a) {
        if (this.oz != a) {
            let b = this.o2;
            this.oz = a;
            this.raisePropertyChanged("FillColumn", b, this.o2);
        }
    }
    nx(a, b, c, d, e) {
        if (c <= this.nj) {
            b.g = new Dictionary$2(Base.$, OwnedPoint.$, 1, c);
        }
        let f = this.nj;
        let g = this.bz;
        let h;
        let i;
        let j = this.getEffectiveViewport1(a);
        let k = new ScalerParams(0, d, e, this.m3.d, j);
        let l = new ScalerParams(0, d, e, this.m3.e, j);
        for (let m = 0; m < c; m++) {
            h = this.nc.item(m);
            i = this.ne.item(m);
            let n = { $type: Point_$type, x: this.m3.a.dv(h, k), y: this.m3.b.dv(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;
                        })()));
                    }
                }
            }
        }
    }
    n1(a, b) {
        let c = typeCast(BubbleSeriesView.$, b);
        let d = c.cr;
        d.m = this.o5;
        super.n1(a, b);
        let e = Math.min(this.nc != null ? this.nc.count : 0, this.ne != null ? this.ne.count : 0);
        if (e < 1) {
            return;
        }
        c.dc();
        c.dd();
    }
    pl() {
        if (this.bs == null) {
            return;
        }
        if (this.aw == null) {
            return;
        }
        if (this.aw.isItemwise) {
            let a = this.aw;
            this.aw.clearLegendItemsForSeries(this);
            this.pk();
            a.renderItemwiseContent(this);
        }
        if (this.aw.isScale) {
            let b = this.aw;
            b.restoreOriginalState();
            b.initializeLegend(this);
        }
    }
    static o7(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 o8(a, b, c, d, logBase_, e) {
        let f = logBase(e, logBase_);
        let g = logBase(a, logBase_);
        let h = logBase(b, logBase_);
        return BubbleSeries.o7(g, h, c, d, f);
    }
    dw(a, b, c) {
        let d = super.dw(a, b, c);
        if (this.o5 == null || this.bz == null || this.o5.count == 0 || this.bz.count != this.o5.count) {
            d = false;
        }
        return d;
    }
    nh(a, b) {
        if (b != 3) {
            return true;
        }
        if (a == null) {
            return true;
        }
        if (this.nq == a || this.nu == a || this.ph == a) {
            return true;
        }
        return false;
    }
    pk() {
        let a = typeCast(IChartLegend_$type, this.aw);
        if (a == null || this.bz == null) {
            return;
        }
        this.o6 = new List$1(UIElement.$, 0);
        let b = this.bz;
        for (let c = 0; c < b.count; c++) {
            let d = null;
            if (typeCast(ValueBrushScale.$, this.ow) !== null && this.o2 != null) {
                d = this.ow.getBrushByIndex(c, this.o2);
            }
            else if (typeCast(CustomPaletteBrushScale.$, this.ow) !== null) {
                d = this.ow.getBrush1(c, b.count);
            }
            else if (this.ow != null) {
                d = this.ow.getBrush(c);
            }
            let e = new ContentControl();
            let f = this.o4 != null && this.o4.item(c) != null ? this.o4.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.jx;
            if (g == null) {
                g = this.bi.bi(this.bk);
            }
            e.ah = g;
            this.o6.add(e);
        }
    }
    hy(a, b, c, d) {
        super.hy(a, b, c, d);
        this.pl();
    }
    ic() {
        super.ic();
        this.pl();
    }
    ii() {
        super.ii();
        this.pl();
    }
    iy(a, b, c, d) {
        super.iy(a, b, c, d);
        switch (b) {
            case "FastItemsSource":
                if (typeCast(IFastItemsSource_$type, c) != null) {
                    c.deregisterColumn(this.o5);
                    c.deregisterColumn(this.o2);
                    c.deregisterColumn(this.o4);
                    this.o5 = null;
                    this.o2 = null;
                    this.o4 = null;
                }
                if (typeCast(IFastItemsSource_$type, d) != null) {
                    this.o5 = this.bw(this.ph);
                    if (!stringIsNullOrEmpty(this.pa)) {
                        this.o2 = this.bw(this.pa);
                    }
                    this.o4 = this.by(this.pe);
                }
                this.jc(false);
                this.pl();
                break;
            case BubbleSeries.$$p[3]:
                if (this.bz != null) {
                    this.bz.deregisterColumn(this.o5);
                    this.o5 = this.bw(this.ph);
                    this.pl();
                }
                break;
            case "RadiusColumn":
                this.m4.ct.g$i();
                this.jc(false);
                this.ik();
                break;
            case BubbleSeries.$$p[4]:
                this.jc(false);
                this.ij();
                break;
            case "DiscreteLegendItemTemplate":
                this.pl();
                break;
            case BubbleSeries.$$p[1]:
                this.jc(false);
                this.pl();
                this.ij();
                break;
            case "FillColumn":
                this.jc(false);
                this.ij();
                break;
            case BubbleSeries.$$p[0]:
                if (this.bz != null) {
                    this.bz.deregisterColumn(this.o2);
                    this.o2 = this.bw(this.pa);
                    this.pl();
                }
                break;
            case BubbleSeries.$$p[2]:
                if (this.bz != null) {
                    this.bz.deregisterColumn(this.o4);
                    this.o4 = this.by(this.pe);
                    this.pl();
                }
                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.pl();
                break;
            case "SeriesViewer":
                this.pl();
                break;
        }
    }
    pn(a, b, c, d) {
        let e = this.o5.minimum;
        let f = this.o5.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.oy || ((() => {
            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.o8(e, f, j, k, l, b._inner[m]);
                }
            }
            else {
                for (let n = 0; n < b.count; n++) {
                    b._inner[n] = BubbleSeries.o7(e, f, j, k, b._inner[n]);
                }
            }
        }
        let o = 1;
        o = DeviceUtils.d();
        let p = this.oy == 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]);
            }
        }
    }
    pm(a) {
        if (this.ow != null && !this.ow.o.contains(this)) {
            this.ow.o.add(this);
        }
        let b = typeCast(CustomPaletteBrushScale.$, this.ow);
        let c = typeCast(ValueBrushScale.$, this.ow);
        let d = this.ow;
        let e = this.ow == null || !this.ow.isReady || (c != null && this.pa == null);
        if (e) {
            this.ox.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.o2);
                }
                else if (d != null) {
                    l = d.getBrush(m);
                }
                k.itemBrush = l;
            }
        }
    }
    get_cy() {
        return false;
    }
    get actualMarkerBrush() {
        return this.mu;
    }
}
BubbleSeries.$t = markType(BubbleSeries, 'BubbleSeries', ScatterBase.$, [IScaleLegendSeries_$type]);
Type.dep(DependencyProperty, PropertyMetadata, BubbleSeries, 'raisePropertyChanged', ['FillMemberPath:pa:po', [2], 'FillScale:ow:pp', [BrushScale.$], 'LabelMemberPath:pe:pq', [2], 'RadiusMemberPath:ph:pr', [2, null], 'RadiusScale:oy:ps', [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.o7(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.l0 = 2;
            this.e.bj = 4;
        }
    }
    cq() {
        return new BubbleMarkerManager((a) => this.cu.item(a), (a) => this.cs.m3.c.item(a), runOn(this, this.c4), runOn(this, this.cn), runOn(this, this.cv));
    }
    dc() {
        let a = this.cr;
        this.da.pn(a.n, a.o, this.br, this == this.e.bh);
        this.an();
    }
    dd() {
        let a = this.cr;
        this.da.pm(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.fx + "</span><br/><span>" + "(${item." + this.da.nq + "}, ${item." + this.da.nu + "})</span>";
        if (!stringIsNullOrEmpty(this.da.ph)) {
            a += "<span>, Radius: ${item." + this.da.ph + "}</span>";
        }
        a += "</div>";
        return a;
    }
}
BubbleSeriesView.$t = markType(BubbleSeriesView, 'BubbleSeriesView', ScatterBaseView.$);
//# sourceMappingURL=BubbleSeries_combined.js.map