/*
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";
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
 */
export class BubbleSeries extends ScatterBase {
    constructor() {
        super();
        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();
    }
    bf() {
        return new BubbleSeriesView(this);
    }
    iu(a) {
        super.iu(a);
        this.oy = a;
    }
    isAttachedTo(a) {
        return this.aw == a;
    }
    ci() {
        return true;
    }
    h6(a) {
        super.h6(a);
        if (this.o5 != null && this.o7 != null && this.o7.count > 0) {
            for (let b = 0; b < this.o7.count; b++) {
                a(this.o7._inner[b]);
            }
        }
    }
    get o4() {
        return this.o6;
    }
    pu(a) {
        let b = typeCast(CustomPaletteBrushScale.$, this.ox);
        let c = typeCast(ValueBrushScale.$, this.ox);
        let 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;
    }
    get legendReady() {
        return this.o6 != null && this.o6.count != 0;
    }
    get minScaleText() {
        return (Math.round(this.o6.minimum * 1000) / 1000).toString();
    }
    get maxScaleText() {
        return (Math.round(this.o6.maximum * 1000) / 1000).toString();
    }
    forScaleColors(a) {
        for (let b = 0; b < this.o6.count; b++) {
            if (this.ox == null || !this.ox.isReady) {
                return false;
            }
            let c = NaN;
            if (this.o3 != null) {
                c = (this.o3.item(b) - this.o3.minimum) / (this.o3.maximum - this.o3.minimum);
            }
            let d = (this.o6.item(b) - this.o6.minimum) / (this.o6.maximum - this.o6.minimum);
            if (isNaN_(c)) {
                c = 0;
            }
            if (isNaN_(d)) {
                d = c;
            }
            let e = this.mv;
            let f = this.pu(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.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.fs(a, b);
    }
    get o6() {
        return this.o2;
    }
    set o6(a) {
        if (this.o2 != a) {
            let b = this.o6;
            this.o2 = a;
            this.raisePropertyChanged("RadiusColumn", b, this.o6);
        }
    }
    get o5() {
        return this.o1;
    }
    set o5(a) {
        if (this.o1 != a) {
            let b = this.o5;
            this.o1 = a;
            this.raisePropertyChanged("LabelColumn", b, this.o5);
        }
    }
    get o3() {
        return this.o0;
    }
    set o3(a) {
        if (this.o0 != a) {
            let b = this.o3;
            this.o0 = a;
            this.raisePropertyChanged("FillColumn", b, this.o3);
        }
    }
    ny(a, b, c, d, e) {
        if (c <= this.nk) {
            b.g = new Dictionary$2(Base.$, OwnedPoint.$, 1, c);
        }
        let f = this.nk;
        let g = this.bz;
        let h;
        let i;
        let j = this.getEffectiveViewport1(a);
        let k = new ScalerParams(0, d, e, this.m4.d, j);
        let l = new ScalerParams(0, d, e, this.m4.e, j);
        for (let m = 0; m < c; m++) {
            h = this.nd.item(m);
            i = this.nf.item(m);
            let n = { $type: Point_$type, x: this.m4.a.dw(h, k), y: this.m4.b.dw(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;
                        })()));
                    }
                }
            }
        }
    }
    n2(a, b) {
        let c = typeCast(BubbleSeriesView.$, b);
        let d = c.cr;
        d.m = this.o6;
        super.n2(a, b);
        let 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();
    }
    pm() {
        if (this.bs == null) {
            return;
        }
        if (this.aw == null) {
            return;
        }
        if (this.aw.isItemwise) {
            let a = this.aw;
            this.aw.clearLegendItemsForSeries(this);
            this.pl();
            a.renderItemwiseContent(this);
        }
        if (this.aw.isScale) {
            let b = this.aw;
            b.restoreOriginalState();
            b.initializeLegend(this);
        }
    }
    static o8(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 o9(a, b, c, d, logBase_, e) {
        let f = logBase(e, logBase_);
        let g = logBase(a, logBase_);
        let h = logBase(b, logBase_);
        return BubbleSeries.o8(g, h, c, d, f);
    }
    dw(a, b, c) {
        let d = super.dw(a, b, c);
        if (this.o6 == null || this.bz == null || this.o6.count == 0 || this.bz.count != this.o6.count) {
            d = false;
        }
        return d;
    }
    ni(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;
    }
    pl() {
        let a = typeCast(IChartLegend_$type, this.aw);
        if (a == null || this.bz == null) {
            return;
        }
        this.o7 = new List$1(UIElement.$, 0);
        let b = this.bz;
        for (let c = 0; c < b.count; c++) {
            let d = null;
            if (typeCast(ValueBrushScale.$, this.ox) !== null && this.o3 != null) {
                d = this.ox.getBrushByIndex(c, this.o3);
            }
            else if (typeCast(CustomPaletteBrushScale.$, this.ox) !== null) {
                d = this.ox.getBrush1(c, b.count);
            }
            else if (this.ox != null) {
                d = this.ox.getBrush(c);
            }
            let e = new ContentControl();
            let f = this.o5 != null && this.o5.item(c) != null ? this.o5.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.jy;
            if (g == null) {
                g = this.bi.bi(this.bk);
            }
            e.ah = g;
            this.o7.add(e);
        }
    }
    hy(a, b, c, d) {
        super.hy(a, b, c, d);
        this.pm();
    }
    id() {
        super.id();
        this.pm();
    }
    ij() {
        super.ij();
        this.pm();
    }
    iz(a, b, c, d) {
        super.iz(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":
                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.pm();
                break;
            case "SeriesViewer":
                this.pm();
                break;
        }
    }
    po(a, b, c, d) {
        let e = this.o6.minimum;
        let f = this.o6.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.oz || ((() => {
            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.o9(e, f, j, k, l, b._inner[m]);
                }
            }
            else {
                for (let n = 0; n < b.count; n++) {
                    b._inner[n] = BubbleSeries.o8(e, f, j, k, b._inner[n]);
                }
            }
        }
        let o = 1;
        o = DeviceUtils.d();
        let p = this.oz == 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]);
            }
        }
    }
    pn(a) {
        if (this.ox != null && !this.ox.o.contains(this)) {
            this.ox.o.add(this);
        }
        let b = typeCast(CustomPaletteBrushScale.$, this.ox);
        let c = typeCast(ValueBrushScale.$, this.ox);
        let d = this.ox;
        let e = this.ox == null || !this.ox.isReady || (c != null && this.pb == null);
        if (e) {
            this.oy.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.o3);
                }
                else if (d != null) {
                    l = d.getBrush(m);
                }
                k.itemBrush = l;
            }
        }
    }
    get_cy() {
        return false;
    }
    get actualMarkerBrush() {
        return this.mv;
    }
}
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.$]]);
/**
 * @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.o8(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.$);
CustomPaletteBrushScale.$$p = markDep(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.l1 = 2;
            this.e.bj = 4;
        }
    }
    cq() {
        return new BubbleMarkerManager((a) => this.cu.item(a), (a) => this.cs.m4.c.item(a), runOn(this, this.c4), runOn(this, this.cn), runOn(this, this.cv));
    }
    dc() {
        let a = this.cr;
        this.da.po(a.n, a.o, this.br, this == this.e.bh);
        this.an();
    }
    dd() {
        let a = this.cr;
        this.da.pn(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.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.$);
//# sourceMappingURL=BubbleSeries_combined.js.map