/*
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 { Base, Type, typeCast, Delegate_$type, runOn, markType, getInstanceType, delegateRemove, delegateCombine, Point_$type, fromEnum, Number_$type, IEnumerable_$type, EnumUtil, Array_$type, enumGetBox, markDep } from "igniteui-angular-core";
import { ServiceProvider_Spark } from "./ServiceProvider_Spark";
import { Dictionary$2 } from "igniteui-angular-core";
import { MessageChannel_Spark } from "./MessageChannel_Spark";
import { AxisRenderMessage_Spark } from "./AxisRenderMessage_Spark";
import { ContainerResizedMessage_Spark } from "./ContainerResizedMessage_Spark";
import { ViewportChangedMessage_Spark } from "./ViewportChangedMessage_Spark";
import { PixelRatioMessage_Spark } from "./PixelRatioMessage_Spark";
import { RenderingContext } from "igniteui-angular-core";
import { FontUtil } from "igniteui-angular-core";
import { Brush } from "igniteui-angular-core";
import { Color } from "igniteui-angular-core";
import { Line } from "igniteui-angular-core";
import { TextBlock } from "igniteui-angular-core";
import { SparklineAxisVisualData } from "./SparklineAxisVisualData";
import { LineVisualData } from "igniteui-angular-core";
import { AppearanceHelper } from "igniteui-angular-core";
import { Visibility_$type } from "igniteui-angular-core";
import { ClearMessage_Spark } from "./ClearMessage_Spark";
import { ISchedulableRender_$type } from "igniteui-angular-core";
import { CanvasRenderScheduler } from "igniteui-angular-core";
import { Path } from "igniteui-angular-core";
import { PolygonMessage_Spark } from "./PolygonMessage_Spark";
import { ColumnMessage_Spark } from "./ColumnMessage_Spark";
import { WinLossColumnMessage_Spark } from "./WinLossColumnMessage_Spark";
import { MarkerMessage_Spark } from "./MarkerMessage_Spark";
import { NormalRangeMessage_Spark } from "./NormalRangeMessage_Spark";
import { TrendLineMessage_Spark } from "./TrendLineMessage_Spark";
import { TooltipMessage_Spark } from "./TooltipMessage_Spark";
import { ToooltipTemplateMessage_Spark } from "./ToooltipTemplateMessage_Spark";
import { ContainerMessage_Spark } from "./ContainerMessage_Spark";
import { BrushChangedMessage_Spark } from "./BrushChangedMessage_Spark";
import { VisibilityMessage_Spark } from "./VisibilityMessage_Spark";
import { NumberChangedMessage_Spark } from "./NumberChangedMessage_Spark";
import { ContainerSizeChangedMessage_Spark } from "./ContainerSizeChangedMessage_Spark";
import { MouseMoveMessage_Spark } from "./MouseMoveMessage_Spark";
import { MouseLeaveMessage_Spark } from "./MouseLeaveMessage_Spark";
import { CanvasGestureDOMEventProxy } from "igniteui-angular-core";
import { CanvasViewRenderer } from "igniteui-angular-core";
import { Rect } from "igniteui-angular-core";
import { List$1 } from "igniteui-angular-core";
import { TranslateTransform } from "igniteui-angular-core";
import { DeviceUtils } from "igniteui-angular-core";
import { GeometryGroup } from "igniteui-angular-core";
import { EllipseGeometry } from "igniteui-angular-core";
import { PathGeometry } from "igniteui-angular-core";
import { PathFigure } from "igniteui-angular-core";
import { LineSegment } from "igniteui-angular-core";
import { RectangleGeometry } from "igniteui-angular-core";
import { SparklineToolTipContext } from "./SparklineToolTipContext";
import { DataContext } from "igniteui-angular-core";
import { SparklineVisualData } from "./SparklineVisualData";
import { RectData } from "igniteui-angular-core";
import { PathVisualData } from "igniteui-angular-core";
import { SparklineDisplayType_$type } from "./SparklineDisplayType";
import { truncate, isNaN_, isInfinity } from "igniteui-angular-core";
import { SparkFrame } from "./SparkFrame";
import { TrendLineType_$type } from "igniteui-angular-core";
import { TrendCalculators } from "igniteui-angular-core";
import { LeastSquaresFit } from "igniteui-angular-core";
import { DependencyObject } from "igniteui-angular-core";
import { IFastItemsSourceProvider_$type } from "igniteui-angular-core";
import { IFastItemsSource_$type } from "igniteui-angular-core";
import { DependencyProperty } from "igniteui-angular-core";
import { PropertyChangedMessage_Spark } from "./PropertyChangedMessage_Spark";
import { FastItemsSource } from "igniteui-angular-core";
import { DataChangedMessage_Spark } from "./DataChangedMessage_Spark";
import { NotifyCollectionChangedEventArgs } from "igniteui-angular-core";
import { FastItemsSourceReference } from "igniteui-angular-core";
import { PropertyMetadata } from "igniteui-angular-core";
import { UnknownValuePlotting_$type } from "igniteui-angular-core";
import { Control } from "igniteui-angular-core";
/**
 * @hidden
 */
export class HorizontalAxisView extends Base {
    constructor(a) {
        super();
        this.j = null;
        this.w = null;
        this.m = null;
        this.l = null;
        this.s = 0;
        this.v = 0;
        this.u = 0;
        this.k = null;
        this.r = -1;
        this.ag = null;
        this.af = null;
        this.ah = null;
        this.a = ["border-top-width", "border-top-color", "color"];
        this.n = false;
        this.q = 1;
        this.g = null;
        this.o = new Dictionary$2(Type.$, Delegate_$type, 0);
        this.d = null;
        this.c = null;
        this.p.item(AxisRenderMessage_Spark.$, (b) => this.ac(typeCast(AxisRenderMessage_Spark.$, b)));
        this.p.item(ContainerResizedMessage_Spark.$, (b) => this.y(typeCast(ContainerResizedMessage_Spark.$, b)));
        this.p.item(ViewportChangedMessage_Spark.$, (b) => this.ae(typeCast(ViewportChangedMessage_Spark.$, b)));
        this.p.item(PixelRatioMessage_Spark.$, (b) => this.ab(typeCast(PixelRatioMessage_Spark.$, b)));
        this.j = a;
    }
    b() {
        if (!this.n) {
            this.n = true;
            this.k.a("ui-sparkline-axis-x", this.a);
        }
        return this.a;
    }
    t() {
        let a = this.r;
        if (a >= 0) {
            return a;
        }
        let b = this.b()[0];
        if (b != null) {
            a = parseInt(b);
        }
        this.r = a = (a < 1) ? 1 : a;
        return a;
    }
    get h() {
        return this.g;
    }
    set h(a) {
        let b = this.g;
        this.g = a;
        this.k = a.getService("View");
        this.aa(b, this.g);
    }
    get p() {
        return this.o;
    }
    set p(a) {
        this.o = a;
    }
    get f() {
        return this.d;
    }
    set f(a) {
        this.d = a;
    }
    get e() {
        return this.c;
    }
    set e(a) {
        this.c = a;
    }
    z(a) {
        let b;
        if (((() => { let c = this.p.tryGetValue(getInstanceType(a), b); b = c.p1; return c.ret; })())) {
            b(a);
        }
    }
    aa(a, b) {
        if (a != null) {
            this.f.detachTarget(runOn(this, this.z));
        }
        if (b != null) {
            this.f = b.getService("RenderingMessages");
            this.e = b.getService("InteractionMessages");
            this.f.attachTarget(runOn(this, this.z));
        }
    }
    y(a) {
        this.w = a.j;
        this.m = a.b;
        this.l = this.k.n("ui-sparkline-axis-x");
        if (this.l == null) {
            this.l = FontUtil.getFont(a.h);
        }
        if (this.m != null) {
            this.m.ac(this.l);
        }
        this.s = FontUtil.getCurrentFontHeight(a.h, this.l);
        if (this.j != null && this.j.e8 != 1) {
            a.d = a.d - this.s;
            a.e = this.t();
        }
    }
    ae(a) {
        this.v = this.w.width();
        this.u = this.s + this.t();
    }
    ac(a) {
        this.ad(a.c);
    }
    ad(a) {
        this.ah = null;
        let b = (!a || this.j == null) ? null : this.m;
        if (b == null || !b.d) {
            return;
        }
        b.k(0, 0, this.v, this.u);
        if (this.l != null) {
            b.ac(this.l);
        }
        if (this.q != 1) {
            b.z();
            b.aa(this.q, this.q);
        }
        let c = this.t(), d = c / 2;
        let e = this.j.ar == null || this.j.ar.count == 0;
        if (e) {
            this.u = 0;
        }
        let f = e ? null : this.x(this.j.ar.item(0));
        let g = f == null ? "" : f.toString();
        this.ag = new TextBlock();
        this.ag.ak = g;
        this.ag.n = 2;
        this.af = new TextBlock();
        let h = e ? null : this.x(this.j.ar.item(this.j.ar.count - 1));
        this.af.ak = g = h == null ? "" : h.toString();
        this.af.o = this.ag.o = c;
        this.af.n = this.v - b.f(g) - 4;
        let i = this.j.ex;
        let j = i == null ? null : i._fill;
        let k = new Color();
        let l = true;
        if (i != null) {
            l = false;
            k = i.color;
        }
        i = new Brush();
        if (l) {
            i._fill = (this.a[2] == null) ? "#000000" : this.a[2];
        }
        else {
            i.color = k;
        }
        this.ag.am = this.af.am = i;
        b.w(this.ag);
        b.w(this.af);
        if (c < 0.5) {
            return;
        }
        i = new Brush();
        if (j == null) {
            j = this.a[1];
        }
        i._fill = (j == null) ? "#000000" : j;
        this.ah = new Line();
        this.ah.ak = 0;
        this.ah.al = this.w.width();
        this.ah.am = d;
        this.ah.an = d;
        this.ah._stroke = i;
        this.ah.ac = c;
        b.r(this.ah);
        if (this.q != 1) {
            b.y();
        }
    }
    x(dataItem_) {
        if (this.j.at()) {
            return this.j.cu(dataItem_);
        }
        let label_ = this.j.bn;
        return (typeof dataItem_ != 'undefined') ? dataItem_ : '';
        ;
    }
    i() {
        let a = new SparklineAxisVisualData();
        if (this.ah != null) {
            a.axisLine = new LineVisualData(1, "HorizontalAxisLine", this.ah);
            a.axisLine.appearance.isVisible = this.w.height() > 0;
        }
        let b = this.l;
        if (this.ag != null) {
            a.minLabel = AppearanceHelper.c(this.ag, this.l);
        }
        if (this.af != null) {
            a.maxLabel = AppearanceHelper.c(this.af, this.l);
        }
        return a;
    }
    ab(a) {
        this.q = a.b;
    }
}
HorizontalAxisView.$t = markType(HorizontalAxisView, 'HorizontalAxisView');
/**
 * @hidden
 */
export class VerticalAxisView extends Base {
    constructor(a) {
        super();
        this.ad = null;
        this.ac = null;
        this.al = null;
        this.ak = null;
        this.am = null;
        this.w = -1;
        this.u = -1;
        this.j = null;
        this.aa = null;
        this.m = null;
        this.l = null;
        this.t = 0;
        this.v = 0;
        this.z = 0;
        this.y = 0;
        this.k = null;
        this.s = -1;
        this.a = ["border-top-width", "border-top-color", "color", "text-align"];
        this.n = false;
        this.g = null;
        this.p = new Dictionary$2(Type.$, Delegate_$type, 0);
        this.d = null;
        this.c = null;
        this.r = 1;
        this.q.item(AxisRenderMessage_Spark.$, (b) => this.ai(typeCast(AxisRenderMessage_Spark.$, b)));
        this.q.item(ContainerResizedMessage_Spark.$, (b) => this.ae(typeCast(ContainerResizedMessage_Spark.$, b)));
        this.q.item(ViewportChangedMessage_Spark.$, (b) => this.aj(typeCast(ViewportChangedMessage_Spark.$, b)));
        this.q.item(PixelRatioMessage_Spark.$, (b) => this.ah(typeCast(PixelRatioMessage_Spark.$, b)));
        this.j = a;
    }
    b() {
        if (!this.n) {
            this.n = true;
            this.k.a("ui-sparkline-axis-y", this.a);
        }
        return this.a;
    }
    x() {
        let a = this.s;
        if (a >= 0) {
            return a;
        }
        let b = this.b()[0];
        if (b != null) {
            a = parseInt(b);
        }
        this.s = a = (a < 1) ? 1 : a;
        return a;
    }
    get h() {
        return this.g;
    }
    set h(a) {
        let b = this.g;
        this.g = a;
        this.k = a.getService("View");
        this.ag(b, this.g);
    }
    get q() {
        return this.p;
    }
    set q(a) {
        this.p = a;
    }
    get f() {
        return this.d;
    }
    set f(a) {
        this.d = a;
    }
    get e() {
        return this.c;
    }
    set e(a) {
        this.c = a;
    }
    af(a) {
        let b;
        if (((() => { let c = this.q.tryGetValue(getInstanceType(a), b); b = c.p1; return c.ret; })())) {
            b(a);
        }
    }
    ag(a, b) {
        if (a != null) {
            this.f.detachTarget(runOn(this, this.af));
        }
        if (b != null) {
            this.f = b.getService("RenderingMessages");
            this.e = b.getService("InteractionMessages");
            this.f.attachTarget(runOn(this, this.af));
        }
    }
    ae(a) {
        this.aa = a.k;
        this.m = a.c;
        this.l = this.k.n("ui-sparkline-axis-y");
        if (this.l == null) {
            this.l = FontUtil.getFont(a.h);
        }
        if (this.m != null) {
            this.m.ac(this.l);
        }
        this.t = FontUtil.getCurrentFontHeight(a.h, this.l);
        if (this.j != null && this.j.ff != 1) {
            this.o(false);
            a.g = a.g - this.v;
            a.f = this.x();
        }
    }
    aj(a) {
        this.z = this.v + this.x();
        this.y = this.aa.height();
    }
    ai(a) {
        if (this.o(a.c)) {
            let b = new ClearMessage_Spark();
            b.c = true;
            this.f.sendMessage(b);
        }
    }
    o(a) {
        this.am = null;
        if (this.j == null || this.m == null || !this.m.d || (a && this.ak == null)) {
            return false;
        }
        let b = this.m;
        if (a) {
            b.k(0, 0, this.z, this.y);
        }
        let c = false;
        if (b != null && this.l != null) {
            b.ac(this.l);
        }
        if (!a) {
            this.al = new TextBlock();
            this.ak = new TextBlock();
            let d = this.ab(this.j.a0);
            this.al.ak = this.ad = d == null ? "" : d.toString();
            let e = this.ab(this.j.az);
            this.ak.ak = this.ac = e == null ? "" : e.toString();
            if (b != null) {
                this.w = b.f(this.ad) + 3;
                if (this.w > this.v) {
                    c = true;
                    this.v = this.w;
                }
                this.u = b.f(this.ac) + 3;
                if (this.u > this.v) {
                    c = true;
                    this.v = this.u;
                }
            }
            if (!c) {
                let f = Math.max(this.w, this.u);
                if (f < this.v) {
                    this.v = f;
                    c = true;
                }
            }
            if (c) {
                this.z = this.v;
            }
        }
        else if (b != null) {
            if (this.r != 1) {
                b.z();
                b.aa(this.r, this.r);
            }
            let g = this.j.e5;
            let h = 1;
            let i = g == null ? null : g._fill;
            let j = this.b()[3];
            if (j == "left") {
                h = 0;
            }
            else if (j == "center") {
                h = 0.5;
            }
            this.ak.o = 2;
            this.ak.n = (this.v - this.u) * h + 1;
            this.al.n = (this.v - this.w) * h + 1;
            this.al.o = this.y - this.t - 2;
            let k = new Color();
            let l = true;
            if (g != null) {
                k = g.color;
                l = false;
            }
            g = new Brush();
            if (l) {
                g._fill = (this.a[2] == null) ? "#000000" : this.a[2];
            }
            else {
                g.color = k;
            }
            this.al.am = this.ak.am = g;
            b.w(this.al);
            b.w(this.ak);
            let m = this.x(), n = m / 2;
            if (m >= 0.5) {
                g = new Brush();
                if (i == null) {
                    i = this.a[1];
                }
                g._fill = (i == null) ? "#000000" : i;
                this.am = new Line();
                this.am.ak = this.z - n;
                this.am.al = this.z - n;
                this.am.am = 0;
                this.am.an = this.y;
                this.am._stroke = g;
                this.am.ac = m;
                b.r(this.am);
            }
            if (this.r != 1) {
                b.y();
            }
        }
        return c;
    }
    ab(dataItem_) {
        if (this.j.at()) {
            return this.j.cu(dataItem_);
        }
        let label_ = this.j.bp;
        return (typeof dataItem_ != 'undefined') ? dataItem_ : '';
        ;
    }
    i() {
        let a = new SparklineAxisVisualData();
        if (this.am != null) {
            a.axisLine = new LineVisualData(1, "VerticalAxisLine", this.am);
            a.axisLine.appearance.isVisible = this.aa.width() > 0;
        }
        if (this.al != null) {
            a.minLabel = AppearanceHelper.c(this.al, this.l);
        }
        if (this.ak != null) {
            a.maxLabel = AppearanceHelper.c(this.ak, this.l);
        }
        return a;
    }
    ah(a) {
        this.r = a.b;
    }
}
VerticalAxisView.$t = markType(VerticalAxisView, 'VerticalAxisView');
/**
 * @hidden
 */
export class XamSparklineView extends Base {
    constructor() {
        super();
        this.bm = null;
        this.bl = null;
        this.ad = null;
        this.ae = null;
        this.af = null;
        this.ag = null;
        this.o = null;
        this.p = null;
        this.q = null;
        this.m = null;
        this.t = false;
        this.b = new Array(6);
        this.x = -1;
        this.bv = new Path();
        this.bt = new Path();
        this.bw = new Path();
        this.bu = new Path();
        this.br = new Path();
        this.bs = new Path();
        this.bq = new Path();
        this.bo = new Path();
        this.bn = new Path();
        this.bp = new Path();
        this.i = null;
        this.e = null;
        this.f = null;
        this.u = new Dictionary$2(Type.$, Delegate_$type, 0);
        this.k = null;
        this.r = false;
        this.ah = null;
        this.d = null;
        this.c = null;
        this.s = false;
        this.w = 1;
        this.br._visibility = 1;
        this.bs._visibility = 1;
        this.bq._visibility = 1;
        this.bo._visibility = 1;
        this.bn._visibility = 1;
        this.bp._visibility = 1;
        this.bu._visibility = 1;
        let a = this.v;
        a.item(ClearMessage_Spark.$, (b) => this.ai(typeCast(ClearMessage_Spark.$, b)));
        a.item(PolygonMessage_Spark.$, (b) => this.bb(typeCast(PolygonMessage_Spark.$, b)));
        a.item(ColumnMessage_Spark.$, (b) => this.a4(typeCast(ColumnMessage_Spark.$, b)));
        a.item(WinLossColumnMessage_Spark.$, (b) => this.bi(typeCast(WinLossColumnMessage_Spark.$, b)));
        a.item(MarkerMessage_Spark.$, (b) => this.a7(typeCast(MarkerMessage_Spark.$, b)));
        a.item(NormalRangeMessage_Spark.$, (b) => this.bc(typeCast(NormalRangeMessage_Spark.$, b)));
        a.item(TrendLineMessage_Spark.$, (b) => this.bf(typeCast(TrendLineMessage_Spark.$, b)));
        a.item(TooltipMessage_Spark.$, (b) => this.bd(typeCast(TooltipMessage_Spark.$, b)));
        a.item(ToooltipTemplateMessage_Spark.$, (b) => this.be(typeCast(ToooltipTemplateMessage_Spark.$, b)));
        a.item(ContainerMessage_Spark.$, (b) => this.aj(typeCast(ContainerMessage_Spark.$, b)));
        a.item(PixelRatioMessage_Spark.$, (b) => this.av(typeCast(PixelRatioMessage_Spark.$, b)));
        a.item(BrushChangedMessage_Spark.$, (b) => this.a2(typeCast(BrushChangedMessage_Spark.$, b)));
        a.item(ContainerResizedMessage_Spark.$, (b) => this.as());
        a.item(VisibilityMessage_Spark.$, (b) => this.bh(typeCast(VisibilityMessage_Spark.$, b)));
        a.item(NumberChangedMessage_Spark.$, (b) => this.ba(typeCast(NumberChangedMessage_Spark.$, b)));
        a.item(ContainerSizeChangedMessage_Spark.$, (b) => this.as());
        this.c = new CanvasRenderScheduler();
        this.c.l(this);
    }
    av(a) {
        this.w = a.b;
    }
    get j() {
        return this.i;
    }
    set j(a) {
        let b = this.i;
        this.i = a;
        this.au(b, this.i);
        this.k = null;
    }
    get g() {
        return this.e;
    }
    set g(a) {
        this.e = a;
    }
    get h() {
        return this.f;
    }
    set h(a) {
        this.f = a;
    }
    get v() {
        return this.u;
    }
    set v(a) {
        this.u = a;
    }
    au(a, b) {
        if (a != null) {
            this.h.detachTarget(runOn(this, this.aq));
            this.g = null;
        }
        if (b != null) {
            this.h = b.getService("RenderingMessages");
            this.g = b.getService("InteractionMessages");
            this.h.attachTarget(runOn(this, this.aq));
            this.a1(this.g);
        }
    }
    a1(a) {
        this.g = a;
    }
    aq(a) {
        let b;
        if (((() => { let c = this.v.tryGetValue(getInstanceType(a), b); b = c.p1; return c.ret; })())) {
            b(a);
        }
    }
    get l() {
        if (this.k == null) {
            this.k = this.j.getService("Controller");
        }
        return this.k;
    }
    a0(a, b, c) {
        let d = new MouseMoveMessage_Spark();
        d.position = a;
        this.g.sendMessage(d);
    }
    az(a) {
        let b = new MouseLeaveMessage_Spark();
        this.g.sendMessage(b);
    }
    a2(a) {
        this.a3(a.b, a.c, null, -1, -1);
    }
    a3(a, b, c, d, e) {
        let f = null;
        let g = true, h = true;
        switch (a) {
            case "sparkpath":
            case XamSparkline.$$p[0]:
                f = this.bv;
                break;
            case "negativesparkpath":
            case XamSparkline.$$p[27]:
                f = this.bt;
                break;
            case "markers":
            case XamSparkline.$$p[22]:
                f = this.br;
                break;
            case "firstmarker":
            case XamSparkline.$$p[3]:
                f = this.bn;
                break;
            case "lastmarker":
            case XamSparkline.$$p[15]:
                f = this.bp;
                break;
            case "highmarker":
            case XamSparkline.$$p[7]:
                f = this.bo;
                break;
            case "lowmarker":
            case XamSparkline.$$p[19]:
                f = this.bq;
                break;
            case "negativemarkers":
            case XamSparkline.$$p[28]:
                f = this.bs;
                break;
            case "trendline":
            case XamSparkline.$$p[36]:
                f = this.bw;
                h = false;
                break;
            case "range":
            case XamSparkline.$$p[31]:
                f = this.bu;
                g = false;
                break;
        }
        if (f == null) {
            return;
        }
        if (b == null && c != null) {
            b = new Brush();
            b._fill = c;
        }
        if (b != null) {
            if (h && (c == null || f._fill == null)) {
                f._fill = b;
            }
            if (g && (c == null || f._stroke == null)) {
                f._stroke = b;
            }
        }
        if (d > 0 && d < 1) {
            f._opacity = d;
        }
        if (e > 0 && (c == null || f.ac <= 0)) {
            f.ac = e;
        }
        this.ap();
    }
    bh(a) {
        switch (a.b) {
            case XamSparkline.$$p[24]:
                this.br._visibility = a.c;
                break;
            case XamSparkline.$$p[5]:
                this.bn._visibility = a.c;
                break;
            case XamSparkline.$$p[17]:
                this.bp._visibility = a.c;
                break;
            case XamSparkline.$$p[9]:
                this.bo._visibility = a.c;
                break;
            case XamSparkline.$$p[21]:
                this.bq._visibility = a.c;
                break;
            case XamSparkline.$$p[30]:
                this.bs._visibility = a.c;
                break;
            case XamSparkline.$$p[34]:
                this.bu._visibility = a.c;
                break;
            case XamSparkline.$$p[35]:
                this.t = a.c == 0;
                break;
        }
        this.ap();
    }
    ba(a) {
        let b = a.b;
        if (b <= 0) {
            return;
        }
        switch (a.c) {
            case XamSparkline.$$p[18]:
                this.bv.ac = this.bt.ac = b;
                break;
            case XamSparkline.$$p[38]:
                this.bw.ac = b;
                break;
        }
        this.ap();
    }
    aj(a) {
        if (a.b == null) {
            if (this.m != null) {
                this.m.aq();
                let b = this.m;
                b.onMouseLeave = delegateRemove(b.onMouseLeave, runOn(this, this.az));
                let c = this.m;
                c.onMouseOver = delegateRemove(c.onMouseOver, runOn(this, this.a0));
                this.m = null;
            }
            this.ad = null;
            this.ae = null;
            this.af = null;
            this.ag = null;
            this.o = this.p = this.q = null;
            this.c.j(null);
            return;
        }
        let d = a.b;
        this.c.j(d);
        this.ad = d;
        this.ad.rootWrapper.setStyleProperty("position", "relative");
        this.ae = this.ad.createElement("canvas");
        this.ae.setStyleProperty("position", "absolute");
        this.af = this.ad.createElement("canvas");
        this.af.setStyleProperty("position", "absolute");
        this.ag = this.ad.createElement("canvas");
        this.ag.setStyleProperty("position", "absolute");
        this.ad.append(this.ae);
        this.ad.append(this.af);
        this.ad.append(this.ag);
        this.o = new RenderingContext(new CanvasViewRenderer(), this.ad.get2DCanvasContext(this.ae));
        this.p = new RenderingContext(new CanvasViewRenderer(), this.ad.get2DCanvasContext(this.af));
        this.q = new RenderingContext(new CanvasViewRenderer(), this.ad.get2DCanvasContext(this.ag));
        this.m = new CanvasGestureDOMEventProxy(this.ae, this.ad, false);
        let e = this.m;
        e.onMouseLeave = delegateCombine(e.onMouseLeave, runOn(this, this.az));
        let f = this.m;
        f.onMouseOver = delegateCombine(f.onMouseOver, runOn(this, this.a0));
        this.m.al = (g) => false;
        this.an();
        this.as();
    }
    an() {
        let a = ["sparkpath", "negativesparkpath", "trendline", "markers", "firstmarker", "lastmarker", "highmarker", "lowmarker", "negativemarkers", "range"];
        let b = ["#7446B9", "#C62828", "#565656", "#9FB328", "#2E9CA6", "#DC3F76", "#F96232", "#3F51B5", "#C62828", "#66666666"];
        for (let c = 0; c < 10; c++) {
            let d = a[c];
            let e = ["background-color", "opacity", "border-top-width"];
            this.a("ui-sparkline-" + d, e);
            let f = XamSparklineView.ac(e[2], (c < 3) ? (c < 2 ? 2 : 1.5) : -1);
            if (c > 2 && c < 9) {
                this.b[c - 3] = f;
            }
            this.a3(d, null, (e[0] == null) ? b[c] : e[0], XamSparklineView.ac(e[1], -1), c < 3 ? f : -1);
        }
    }
    static ac(v_, a) {
        let d_ = (v_ == null || v_.length < 1) ? null : parseFloat(v_);
        return (d_ == null || d_.toString() == "NaN") ? a : d_;
    }
    a(a, b) {
        this.ad.startCSSQuery();
        for (let c = 0; c < b.length; c++) {
            b[c] = this.ad.getCssDefaultPropertyValue(a, b[c]);
        }
        this.ad.endCSSQuery();
        return b;
    }
    as() {
        if (this.ad == null || this.r) {
            return;
        }
        this.r = true;
        this.ao(this.l.q);
        let a = this.ad.rootWrapper.width(), b = this.ad.rootWrapper.height();
        let c, d, e;
        c = this.ae;
        d = this.af;
        e = this.ag;
        let f = new ContainerResizedMessage_Spark();
        f.g = a;
        f.d = b;
        f.b = this.p;
        f.h = this.ad;
        f.c = this.q;
        f.f = 0;
        f.e = 0;
        f.j = d;
        f.i = c;
        f.k = e;
        this.h.sendMessage(f);
        let g = f.e, h = f.f, i = f.g - h, j = f.d - g;
        let k = i, l = a - i, m = j, n = b - j;
        c.setStyleProperty("width", k.toString() + "px");
        c.setStyleProperty("height", m.toString() + "px");
        c.setAttribute("width", (k * this.w).toString());
        c.setAttribute("height", (m * this.w).toString());
        c.setStyleProperty("marginLeft", l + "px");
        k = (i + h);
        this.ay(d, k, n, k * this.w, n * this.w);
        d.setStyleProperty("marginTop", m + "px");
        d.setStyleProperty("marginLeft", (a - i - h).toString() + "px");
        this.ay(e, l, m, l * this.w, m * this.w);
        this.bm = new Rect(0, 0, 0, i, j);
        if (this.m != null) {
            this.m.bf = this.bm;
        }
        this.bg();
        let o = new ViewportChangedMessage_Spark();
        o.newLeft = this.bm.left;
        o.newTop = this.bm.top;
        o.newHeight = this.bm.height;
        o.newWidth = this.bm.width;
        this.h.sendMessage(o);
        this.r = false;
    }
    ak(a) {
        if (a) {
            this.x = -1;
        }
        else if (this.x < 0) {
            this.bg();
        }
    }
    bg() {
        let a = this.bm.left;
        let b = this.bm.width;
        let c = this.bm.height;
        let d = this.aa(true);
        let e = new Rect(0, a + d, d, b - d * 2, c - d * 2);
        let f = new ViewportChangedMessage_Spark();
        f.newLeft = e.left;
        f.newTop = e.top;
        f.newHeight = e.height;
        f.newWidth = e.width;
        this.bl = e;
        this.g.sendMessage(f);
    }
    ai(a) {
        if (Rect.l_op_Equality(this.bm, null)) {
            return;
        }
        switch (a.b) {
            case 2:
                this.br.ak = null;
                this.bn.ak = null;
                this.bp.ak = null;
                this.bo.ak = null;
                this.bq.ak = null;
                this.bs.ak = null;
                break;
            case 8:
                this.bu.ak = null;
                break;
            case 1:
                this.bv.ak = null;
                this.bt.ak = null;
                break;
            case 4:
                this.al(null);
                break;
            case 16:
                this.bw.ak = null;
                break;
        }
        if (a.c) {
            this.as();
        }
    }
    aa(a) {
        if (a) {
            this.x = -1;
        }
        let b = this.x;
        if (b >= 0) {
            return b;
        }
        b = 0;
        let c = this.l.q;
        if (c.fb == 0) {
            b = this.ab(b, c.a9, 0);
        }
        if (c.e6 == 0) {
            b = this.ab(b, c.a2, 1);
        }
        if (c.e9 == 0) {
            b = this.ab(b, c.a4, 2);
        }
        if (c.e7 == 0) {
            b = this.ab(b, c.a3, 3);
        }
        if (c.fa == 0) {
            b = this.ab(b, c.a8, 4);
        }
        if (c.fc == 0) {
            b = this.ab(b, c.be, 5);
        }
        this.x = b;
        return b;
    }
    ab(a, b, c) {
        if (b >= 0) {
            return b > a ? b : a;
        }
        return this.b[c] > a ? this.b[c] : a;
    }
    a7(a) {
        this.a8(this.br, a.e, a.k, 0);
        this.a8(this.bs, a.f, a.l, 5);
        this.a8(this.bq, a.d, a.j, 4);
        this.a8(this.bo, a.c, a.h, 3);
        this.a9(this.bn, a.m, a.g, 1);
        this.a9(this.bp, a.n, a.i, 2);
        this.ap();
    }
    a9(a, b, c, d) {
        let e = ((() => {
            let $ret = new List$1(Point_$type, 0);
            $ret.add(b);
            return $ret;
        })());
        this.a8(a, e, c, d);
    }
    a8(a, b, c, d) {
        if (c < 0) {
            c = this.b[d];
        }
        a.ak = this.bk(b, c < 0.1 ? DeviceUtils.g(3) : c);
        if (this.l.q.am != 3) {
            let e = new TranslateTransform();
            e.j = this.l.o.d;
            a.j = e;
        }
        else {
            a.j = null;
        }
    }
    bk(a, b) {
        let c = new GeometryGroup();
        c.c = 1;
        let d = this.bm.right;
        let e = this.bm.bottom;
        for (let f of fromEnum(a)) {
            if ((!f)) {
                continue;
            }
            if (f.x < 0 || f.y < 0 || f.x > d || f.y > e) {
                continue;
            }
            let g = new EllipseGeometry();
            g.c = b;
            g.d = b;
            g.e = f;
            c.d.add(g);
        }
        return c;
    }
    bb(a) {
        let b = new PathGeometry();
        let c = this.l.q.am == 1;
        for (let d of fromEnum(a.points)) {
            let e = d.length;
            if (e == 0) {
                continue;
            }
            let f = new PathFigure();
            f._isClosed = f._isFilled = c;
            f._startPoint = d[0];
            for (let g = 1; g < e; g++) {
                let h = new LineSegment(1);
                h.c = d[g];
                f._segments.add(h);
            }
            b.c.add(f);
        }
        this.bv.ak = b;
        this.ap();
    }
    bj(a, b) {
        let c = typeCast(WinLossColumnMessage_Spark.$, b);
        let d = typeCast(ColumnMessage_Spark.$, b);
        let e = new GeometryGroup();
        let f = c != null ? c.i : d.i;
        let g = c != null ? c.h : d.h;
        let h = f * 0.1;
        for (let i of fromEnum(a)) {
            let j = f * 2 - h * 2;
            let k = Math.abs(g - i.y);
            let l = i.x + h;
            let m = (i.y > g ? g : i.y);
            let n = new RectangleGeometry();
            n.e = new Rect(0, l, m, j, k);
            e.d.add(n);
        }
        return e;
    }
    a4(a) {
        this.a5(this.bv, a.d, a);
        this.a5(this.bt, a.g, a);
        this.ap();
    }
    a6(a, b, c) {
        let d = ((() => {
            let $ret = new List$1(Point_$type, 0);
            $ret.add(b);
            return $ret;
        })());
        this.a5(a, d, c);
    }
    a5(a, b, c) {
        a.ak = this.bj(b, c);
    }
    bi(a) {
        this.a5(this.bv, a.d, a);
        this.a5(this.bt, a.g, a);
        this.ap();
    }
    bc(a) {
        let b = new RectangleGeometry();
        b.e = new Rect(0, a.k, a.l, a.j, a.i);
        this.bu.ak = b;
        this.ap();
    }
    bf(a) {
        if (a.points.length == 0) {
            return;
        }
        let b = new PathGeometry();
        let c = new PathFigure();
        c._isClosed = c._isFilled = false;
        c._startPoint = a.points[0];
        let d = a.points.length;
        for (let e = 1; e < d; e++) {
            let f = new LineSegment(1);
            f.c = a.points[e];
            c._segments.add(f);
        }
        b.c.add(c);
        this.bw.ak = b;
        this.ap();
    }
    be(a) {
        this.ah = a.template;
    }
    bd(a) {
        if (!this.t) {
            this.al(null);
            return;
        }
        let b = truncate(Math.round(a.xOffset - 10));
        let c = truncate(Math.round(a.yOffset - 10));
        b = truncate(Math.round(b * this.w));
        c = truncate(Math.round(c * this.w));
        let d = this.o.a(b, c);
        if (d[3] > 0) {
            this.al(a);
        }
        else {
            this.al(null);
        }
    }
    al(a) {
        let x_ = 0, y_ = 0;
        let v_ = null, t_ = null, i_ = this.ad;
        {
            if (a != null) {
                t_ = this.ah;
                x_ = a.xOffset + 6;
                y_ = a.yOffset + 6;
                let b = a.context;
                let f_ = b.first, l_ = b.last, o_ = b.low, h_ = b.high;
                v_ = { First: f_, Last: l_, Low: o_, High: h_ };
            }
            let ren_ = this.ad;
            if (this.d == null) {
                this.d = new DataContext();
            }
            let dc_ = this.d;
            dc_.item = v_;
            dc_.series = this;
            let tt_ = this.ah;
            if (tt_ != null) {
                if (v_ != null) {
                    tt_.updateToolTip(dc_);
                    tt_.setRawPosition(x_, y_);
                }
                else {
                    tt_.hideToolTip();
                }
            }
        }
    }
    get isDirty() {
        return this.s;
    }
    set isDirty(a) {
        this.s = a;
    }
    ap() {
        if (!this.isDirty) {
            this.isDirty = true;
            this.c.o(this.o, null);
        }
    }
    undirty(a) {
        this.s = false;
        this.aw();
    }
    get index() {
        return 10;
    }
    ax(a, b) {
        b.s(a);
    }
    aw() {
        let a = this.o;
        if (a != null && a.d) {
            if (this.w != 1) {
                a.z();
                a.aa(this.w, this.w);
            }
            a.k(this.bm.left, this.bm.top, this.bm.width, this.bm.height);
            a.s(this.bv);
            a.s(this.bt);
            this.ax(this.br, a);
            this.ax(this.bs, a);
            this.ax(this.bo, a);
            this.ax(this.bq, a);
            this.ax(this.bn, a);
            this.ax(this.bp, a);
            a.s(this.bu);
            a.s(this.bw);
            if (this.w != 1) {
                a.y();
            }
        }
        let b = new AxisRenderMessage_Spark();
        b.c = true;
        this.h.sendMessage(b);
        this.postRender();
    }
    postRender() {
    }
    am(a) {
        a.viewport = new RectData(this.bm.left, this.bm.top, this.bm.width, this.bm.height);
        a.marginViewport = new RectData(this.bl.left, this.bl.top, this.bl.width, this.bl.height);
        a.sparkPath = new PathVisualData(1, "SparkPath", this.bv);
        a.negativeSparkPath = new PathVisualData(1, "NegativeSparkPath", this.bt);
        a.trendLinePath = new PathVisualData(1, "TrendLinePath", this.bw);
        a.rangePath = new PathVisualData(1, "RangePath", this.bu);
        a.markersPath = new PathVisualData(1, "MarkersPath", this.br);
        a.negativeMarkersPath = new PathVisualData(1, "NegativeMarkersPath", this.bs);
        a.lowMarkersPath = new PathVisualData(1, "LowMarkersPath", this.bq);
        a.highMarkersPath = new PathVisualData(1, "HighMarkersPath", this.bo);
        a.firstMarkerPath = new PathVisualData(1, "FirstMarkerPath", this.bn);
        a.lastMarkerPath = new PathVisualData(1, "LastMarkerPath", this.bp);
    }
    preRender() {
    }
    isValid() {
        return true;
    }
    n(a) {
        return FontUtil.getFontForClass(this.ad, a);
    }
    ay(a, b, c, d, e) {
        a.setStyleProperty("width", b + "px");
        a.setStyleProperty("height", c + "px");
        a.setAttribute("width", d.toString());
        a.setAttribute("height", e.toString());
    }
    ao(a) {
        let b = a.bh;
        let c = a.a1;
        if (!isNaN_(b) && b != 0) {
            return;
        }
        if (window.devicePixelRatio != undefined && window.devicePixelRatio != c) {
            a.a1 = window.devicePixelRatio;
        }
    }
    at() {
        if (this.m != null) {
            this.m.bb(this.ae, "");
        }
    }
    ar() {
        this.ao(this.k.q);
        if (this.m != null) {
            this.m.ap(this.ae, "");
        }
    }
}
XamSparklineView.$t = markType(XamSparklineView, 'XamSparklineView', Base.$, [ISchedulableRender_$type]);
/**
 * @hidden
 */
export class SparkFramePreparer extends Base {
    constructor() {
        super(...arguments);
        this.b = null;
        this.d = 0;
        this.c = 0;
    }
    e(a) {
        this.b.r.ak(false);
        a.g.clear();
        a.l.clear();
        a.j.clear();
        a.k.clear();
        a.i.clear();
        a.h.clear();
        let b = this.b.t;
        if (b == null) {
            return;
        }
        let c = b.count;
        let d = this.b.a3.top;
        let e = this.b.a3.left;
        let f = this.b.a3.width;
        let g = this.b.a3.height;
        let h = this.b.a3.bottom;
        let i = Math.floor((c + 1) / f);
        let j = truncate(Math.max(1, i));
        let k = 0;
        let l = truncate(Math.ceil(1 * c / j));
        let m = 0;
        let n = new List$1(Number_$type, 0);
        let o = this.b.q.an;
        let p = this.b.q.am;
        let q = this.b.q.bm;
        let r = o != 0 && q >= 1;
        let s = null;
        let t = null;
        if (p == 1 || p == 0) {
            this.d = 0;
        }
        else {
            if (l == 0) {
                this.d = 0;
            }
            else {
                this.d = f / l / 2;
            }
        }
        if (r) {
            let u = (v) => v + 1;
            let v = (w) => b.item(w);
            let w = (x) => this.b.y(x);
            let x = (y) => this.b.z(y);
            switch (this.b.q.an) {
                case 9:
                    s = TrendCalculators.e(b, q);
                    break;
                case 10:
                    s = TrendCalculators.b(b, q);
                    break;
                case 11:
                    s = TrendCalculators.c(b, q);
                    break;
                case 12:
                    s = TrendCalculators.a(b);
                    break;
                case 13:
                    s = TrendCalculators.g(b, q);
                    break;
                case 1:
                    t = LeastSquaresFit.k(c, u, v);
                    break;
                case 2:
                    t = LeastSquaresFit.o(c, u, v);
                    break;
                case 3:
                    t = LeastSquaresFit.i(c, u, v);
                    break;
                case 4:
                    t = LeastSquaresFit.p(c, u, v);
                    break;
                case 5:
                    t = LeastSquaresFit.q(c, u, v);
                    break;
                case 7:
                    t = LeastSquaresFit.j(c, u, v);
                    break;
                case 6:
                    t = LeastSquaresFit.l(c, u, v);
                    break;
                case 8:
                    t = LeastSquaresFit.n(c, u, v);
                    break;
            }
            if (s != null) {
                for (let y of fromEnum(s)) {
                    n.add(y);
                }
            }
            if (t != null) {
                let z = k * j;
                let aa = l * j;
                if (p == 1 || p == 0) {
                    aa = aa - 1;
                }
                let ab = 0 + this.d;
                let ac = f - this.d;
                let ad = 0;
                if (this.d != 0) {
                    ad = 0.5;
                }
                for (let ae = ab; ae <= ac; ae += 2) {
                    let af = ae / (f - 1);
                    let ag = z + af * (aa - z);
                    let ah = NaN;
                    switch (o) {
                        case 1:
                            ah = LeastSquaresFit.ad(t, ag - ad);
                            break;
                        case 2:
                            ah = LeastSquaresFit.ah(t, ag - ad);
                            break;
                        case 3:
                            ah = LeastSquaresFit.ab(t, ag - ad);
                            break;
                        case 4:
                            ah = LeastSquaresFit.ai(t, ag - ad);
                            break;
                        case 5:
                            ah = LeastSquaresFit.aj(t, ag - ad);
                            break;
                        case 7:
                            ah = LeastSquaresFit.ac(t, ag - ad);
                            break;
                        case 6:
                            ah = LeastSquaresFit.ae(t, ag - ad);
                            break;
                        case 8:
                            ah = LeastSquaresFit.ag(t, ag - ad);
                            break;
                    }
                    ag = w(ag);
                    ah = x(ah);
                    if (!isNaN_(ah) && !isInfinity(ah)) {
                        a.l.add({ $type: Point_$type, x: ag, y: ah });
                    }
                }
            }
        }
        let ai = this.b.t.minimum;
        let aj = this.b.t.maximum;
        let ak = this.b.q.a0;
        let al = this.b.q.az;
        this.c = h - (m - ak) / (al - ak) * g;
        if (this.c < 0) {
            this.c = 0;
        }
        else if (this.c > h) {
            this.c = h;
        }
        let am = this.c;
        let an;
        for (let ao = k; ao < l; ao++) {
            let ap = this.a(ao, j, c);
            let aq = ap[1];
            let ar = ap[2];
            this.f(ap, c, this.b.a3, ak, al);
            an = ap[1];
            if (ap[2] < am) {
                an = ap[2];
            }
            a.g.add(ap);
            if (!isNaN_(ap[0]) && !isNaN_(ap[1])) {
                a.j.add({ $type: Point_$type, x: ap[0], y: an });
            }
            if (r && s != null) {
                let as = ao * j;
                let at = h - (((n._inner[as] - ai) / (aj - ai)) * g);
                a.l.add({ $type: Point_$type, x: ap[0] + this.d, y: at });
            }
            if (aq < m) {
                a.k.add({ $type: Point_$type, x: ap[0], y: ap[1] });
            }
            if (ai == aq) {
                a.i.add({ $type: Point_$type, x: ap[0], y: ap[1] });
            }
            if (aj == ar) {
                a.h.add({ $type: Point_$type, x: ap[0], y: ap[2] });
            }
        }
        if (a.j.count == 0) {
            a.m = a.n = { $type: Point_$type, x: NaN, y: NaN };
        }
        else {
            a.m = a.j._inner[0];
            a.n = a.j._inner[a.j.count - 1];
        }
    }
    a(a, b, c) {
        let d = Math.min(a * b, c - 1);
        let e = Math.min(d + b - 1, c - 1);
        let f = true;
        let g = 0;
        let h = 0;
        for (let i = d; i <= e; ++i) {
            let j = this.b.t.item(i);
            if (f) {
                f = false;
                g = j;
                h = j;
            }
            else {
                g = Math.min(g, j);
                h = Math.max(h, j);
            }
        }
        let k = [0, 0, 0];
        k[0] = (0.5 * (d + e));
        k[1] = g;
        k[2] = h;
        return k;
    }
    f(a, b, c, d, e) {
        let f = c.left;
        let g = c.top;
        let h = c.width;
        let i = c.height;
        if (this.b.q.am == 1 || this.b.q.am == 0) {
            b--;
        }
        if (b < 0) {
            b = 0;
        }
        let j = b > 0 ? a[0] / b : b == 0 ? 0.5 : NaN;
        a[0] = f + j * h;
        if (this.b.q.am == 3) {
            if (a[1] > 0) {
                a[1] = g;
                a[2] = g;
            }
            else if (a[1] < 0) {
                a[1] = g + i;
                a[2] = g + i;
            }
            else {
                a[1] = g + (1 - ((a[1] - d) / (e - d))) * i;
                a[2] = g + (1 - ((a[2] - d) / (e - d))) * i;
            }
        }
        else {
            a[1] = g + (1 - ((a[1] - d) / (e - d))) * i;
            a[2] = g + (1 - ((a[2] - d) / (e - d))) * i;
        }
    }
}
SparkFramePreparer.$t = markType(SparkFramePreparer, 'SparkFramePreparer');
/**
 * @hidden
 */
export class SparklineConnector extends Base {
    constructor(a, b) {
        super();
        this.d = null;
        this.b = null;
        this.e = null;
        this.a = null;
        this.c = null;
        this.e = b;
        if (a == null) {
            return;
        }
        this.d = typeCast(XamSparkline.$, a);
        this.a = this.d.ag;
        this.c = this.d.ap;
        b.ao(this.d);
        let c = new ServiceProvider_Spark();
        c.addService("ConfigurationMessages", new MessageChannel_Spark());
        c.addService("RenderingMessages", new MessageChannel_Spark());
        c.addService("InteractionMessages", new MessageChannel_Spark());
        c.addService("Model", this.d);
        c.addService("View", this.e);
        c.addService("HorizontalAxis", this.a);
        c.addService("VerticalAxis", this.c);
        this.d.ak = c;
        this.e.j = c;
        this.a.h = c;
        this.c.h = c;
        this.b = new SparklineController(c);
        c.addService("Controller", this.b);
    }
}
SparklineConnector.$t = markType(SparklineConnector, 'SparklineConnector');
/**
 * @hidden
 */
export class SparklineController extends DependencyObject {
    constructor(a) {
        super();
        this.k = null;
        this.m = null;
        this.l = null;
        this.p = null;
        this.r = null;
        this.t = null;
        this.s = null;
        this.o = new SparkFramePreparer();
        this.n = new SparkFrame();
        this.a3 = Rect.empty;
        this.aa = null;
        this.k = a.getService("ConfigurationMessages");
        this.m = a.getService("RenderingMessages");
        this.l = a.getService("InteractionMessages");
        this.aa = (b, c) => this.ah(c.action, c.position, c.count, c.propertyName);
        this.q = a.getService("Model");
        this.r = a.getService("View");
        this.k.attachTarget(runOn(this, this.ag));
        this.l.attachTarget(runOn(this, this.aj));
    }
    get q() {
        return this.p;
    }
    set q(a) {
        let b = this.p != a;
        if (b) {
            this.p = a;
            this.an(runOn(this, this.aw));
        }
    }
    get x() {
        return this.q != null ? this.q.itemsSource : null;
    }
    get u() {
        return this.c(SparklineController.a2);
    }
    set u(a) {
        this.h(SparklineController.a2, a);
    }
    get ad() {
        return this.q != null ? this.q.c2 : null;
    }
    get ac() {
        return this.q != null ? this.q.b7 : null;
    }
    get ab() {
        return this.q != null ? this.q.toolTip : null;
    }
    y(a) {
        let b = this.t.count;
        if (this.q.am == 1 || this.q.am == 0) {
            b--;
        }
        if (b < 0) {
            b = 0;
        }
        let c = b > 0 ? a / b : b == 0 ? 0.5 : NaN;
        c = this.a3.left + (c) * this.a3.width;
        return c;
    }
    z(a) {
        let b = ((a - this.q.a0) / (this.q.az - this.q.a0));
        b = (1 - b);
        b = this.a3.top + (b) * this.a3.height;
        return b;
    }
    w() {
        return !this.a3.isEmpty && this.a3.width > 0 && this.a3.height > 0 && this.q != null && this.q.a0 != this.q.az;
    }
    v(a) {
        if (a.oldValue != a.newValue) {
            return true;
        }
        return false;
    }
    av(a, b) {
        if (this.aa == null) {
            this.aa = (c, d) => this.ah(d.action, d.position, d.count, d.propertyName);
        }
        let c = typeCast(FastItemsSource.$, a);
        if (c != null) {
            c.event = delegateRemove(c.event, this.aa);
        }
        let d = typeCast(FastItemsSource.$, b);
        if (d != null) {
            d.event = delegateCombine(d.event, this.aa);
        }
    }
    ay() {
        if (this.q != null) {
            if (this.t == null) {
                this.q.a0 = this.q.az = NaN;
            }
            else {
                if (isNaN_(this.q.bd)) {
                    this.q.a0 = this.t.minimum;
                }
                else {
                    this.q.a0 = this.q.bd;
                }
                if (isNaN_(this.q.bc)) {
                    this.q.az = this.t.maximum;
                }
                else {
                    this.q.az = this.q.bc;
                }
                if (this.q.a0 == this.q.az) {
                    if (!isNaN_(this.q.bc) && isNaN_(this.q.bd)) {
                        this.q.a0 = this.q.az - 1;
                    }
                    else if (isNaN_(this.q.bc) && !isNaN_(this.q.bd)) {
                        this.q.az = this.q.a0 + 1;
                    }
                    else {
                        if (Math.floor(this.q.a0) < this.q.a0) {
                            this.q.a0 = Math.floor(this.q.a0);
                        }
                        else {
                            this.q.a0 = Math.floor(this.q.a0) - 1;
                        }
                        if (Math.ceil(this.q.az) > this.q.az) {
                            this.q.az = Math.ceil(this.q.az);
                        }
                        else {
                            this.q.az = Math.ceil(this.q.az) + 1;
                        }
                    }
                }
            }
        }
    }
    a0() {
        if (this.u != null) {
            this.u.deregisterColumn(this.t);
            this.t = this.u.registerColumn(this.ad, null, false);
        }
        else {
            this.t = null;
        }
    }
    ax() {
        if (this.u != null) {
            this.u.deregisterColumn(this.s);
            this.s = this.u.registerColumnObject(this.ac, null, false);
            this.q.ar = this.s;
        }
        else {
            this.q.ar = this.s = null;
        }
    }
    au() {
        let a = new AxisRenderMessage_Spark();
        this.m.sendMessage(a);
    }
    an(a) {
        a();
    }
    aw() {
        this.u = this.getFastItemsSource(this.x);
        this.a0();
        this.ax();
        this.ay();
        this.au();
    }
    ah(a, b, c, d) {
        this.a0();
        this.ax();
        this.ay();
        this.au();
        this.an(runOn(this, this.ao));
    }
    az() {
        let a = new ToooltipTemplateMessage_Spark();
        a.template = this.ab;
        this.m.sendMessage(a);
    }
    ag(a) {
        if (typeCast(PropertyChangedMessage_Spark.$, a) !== null) {
            this.am(a);
        }
        else if (typeCast(ContainerSizeChangedMessage_Spark.$, a) !== null) {
            this.m.sendMessage(a);
        }
        else if (typeCast(DataChangedMessage_Spark.$, a) !== null) {
            this.ai(a);
        }
    }
    ai(a) {
        let b = this.u;
        if (b == null) {
            return;
        }
        switch (a.b) {
            case 2:
                b.handleCollectionChanged(new NotifyCollectionChangedEventArgs(2, 2, a.d, a.e, a.c));
                break;
            case 0:
                b.handleCollectionChanged(new NotifyCollectionChangedEventArgs(1, 0, a.d, a.c));
                break;
            case 1:
                b.handleCollectionChanged(new NotifyCollectionChangedEventArgs(1, 1, a.e, a.c));
                break;
            case 4:
                b.handleCollectionChanged(new NotifyCollectionChangedEventArgs(0, 4));
                break;
        }
        this.an(runOn(this, this.aw));
    }
    aj(a) {
        let b = a;
        if (typeCast(ViewportChangedMessage_Spark.$, b) !== null) {
            this.a1(b);
        }
        else if (typeCast(MouseLeaveMessage_Spark.$, b) !== null) {
            this.ak(b);
        }
        else if (typeCast(MouseMoveMessage_Spark.$, b) !== null) {
            this.al(b);
        }
        else if (typeCast(ContainerSizeChangedMessage_Spark.$, b) !== null) {
            this.m.sendMessage(a);
        }
    }
    am(a) {
        switch (a.propertyName) {
            case XamSparkline.$$p[13]:
                this.an(runOn(this, this.aw));
                break;
            case XamSparkline.$$p[41]:
                this.an(runOn(this, this.aw));
                break;
            case XamSparkline.$$p[14]:
                this.an(runOn(this, this.aw));
                break;
            case "ToolTip":
                this.az();
                break;
            case XamSparkline.$$p[26]:
            case XamSparkline.$$p[25]:
                this.ay();
                this.au();
                break;
            case XamSparkline.$$p[11]:
            case XamSparkline.$$p[43]:
                this.au();
                break;
            case XamSparkline.$$p[0]:
            case XamSparkline.$$p[27]:
            case XamSparkline.$$p[22]:
            case XamSparkline.$$p[3]:
            case XamSparkline.$$p[15]:
            case XamSparkline.$$p[7]:
            case XamSparkline.$$p[19]:
            case XamSparkline.$$p[28]:
            case XamSparkline.$$p[36]:
            case XamSparkline.$$p[31]:
                let b = new BrushChangedMessage_Spark();
                b.c = typeCast(Brush.$, a.newValue);
                b.b = a.propertyName;
                this.m.sendMessage(b);
                break;
            case XamSparkline.$$p[24]:
            case XamSparkline.$$p[5]:
            case XamSparkline.$$p[17]:
            case XamSparkline.$$p[9]:
            case XamSparkline.$$p[21]:
            case XamSparkline.$$p[30]:
            case XamSparkline.$$p[34]:
            case XamSparkline.$$p[35]:
                let c = new VisibilityMessage_Spark();
                c.c = EnumUtil.getEnumValue(Visibility_$type, a.newValue);
                c.b = a.propertyName;
                this.m.sendMessage(c);
                this.r.ak(true);
                break;
            case XamSparkline.$$p[23]:
            case XamSparkline.$$p[4]:
            case XamSparkline.$$p[16]:
            case XamSparkline.$$p[8]:
            case XamSparkline.$$p[20]:
            case XamSparkline.$$p[29]:
                this.r.ak(true);
                break;
            case XamSparkline.$$p[18]:
            case XamSparkline.$$p[38]:
                let d = new NumberChangedMessage_Spark();
                d.b = a.newValue;
                d.c = a.propertyName;
                this.m.sendMessage(d);
                break;
            case XamSparkline.$$p[10]:
            case XamSparkline.$$p[42]:
            case XamSparkline.$$p[12]:
            case XamSparkline.$$p[44]:
                this.at();
                break;
            case "Container":
                let e = new ContainerMessage_Spark();
                e.b = a.newValue;
                this.m.sendMessage(e);
                break;
            case "ActualPixelScalingRatio":
                {
                    let f = new PixelRatioMessage_Spark();
                    f.b = a.newValue;
                    this.m.sendMessage(f);
                }
                break;
        }
        if (this.v(a)) {
            this.an(runOn(this, this.ao));
        }
    }
    at() {
        let a = new ClearMessage_Spark();
        a.c = true;
        this.m.sendMessage(a);
    }
    a1(a) {
        this.a3 = new Rect(0, a.newLeft, a.newTop, a.newWidth, a.newHeight);
        this.an(runOn(this, this.ao));
    }
    al(a) {
        let b = new ClearMessage_Spark();
        b.b = 4;
        this.m.sendMessage(b);
        let c = new TooltipMessage_Spark();
        c.b = 4;
        c.xOffset = a.position.x + 10;
        c.yOffset = a.position.y + 10;
        if (this.t != null && this.t.count > 0) {
            let d = new SparklineToolTipContext();
            d.high = this.t.maximum;
            d.low = this.t.minimum;
            d.first = this.t.item(0);
            d.last = this.t.item(this.t.count - 1);
            c.context = d;
        }
        this.m.sendMessage(c);
    }
    ak(a) {
        let b = new ClearMessage_Spark();
        b.b = 4;
        this.m.sendMessage(b);
    }
    af(a) {
        let b = new ClearMessage_Spark();
        b.b = a;
        this.m.sendMessage(b);
    }
    ae() {
        this.af(1);
        this.af(2);
        this.af(16);
        this.af(8);
    }
    ao() {
        this.ae();
        if (!this.w()) {
            return;
        }
        this.o.b = this;
        this.o.e(this.n);
        switch (this.q.am) {
            case 2:
                this.ap();
                break;
            case 3:
                this.as();
                break;
            case 0:
            case 1:
                this.ar();
                break;
        }
        let a = new NormalRangeMessage_Spark();
        a.k = this.a3.left;
        a.l = Math.max(this.a3.top, Math.min(this.a3.bottom, this.z(this.q.bf)));
        a.j = this.a3.width;
        let b = Math.max(this.a3.top, Math.min(this.a3.bottom, this.z(this.q.bg)));
        a.i = Math.abs(b - a.l);
        a.l = Math.min(a.l, b);
        a.d = this.q.as;
        this.m.sendMessage(a);
        let c = new TrendLineMessage_Spark();
        c.points = this.n.l.toArray();
        this.m.sendMessage(c);
    }
    ap() {
        let a = new ColumnMessage_Spark();
        a.d = this.n.j;
        a.g = this.n.k;
        a.f = this.n.i;
        a.e = this.n.h;
        a.k = this.n.m;
        a.l = this.n.n;
        a.j = this.n.g.count;
        a.h = this.o.c;
        a.i = this.o.d;
        a.c = this.q.am;
        this.m.sendMessage(a);
        this.aq();
    }
    as() {
        let a = new WinLossColumnMessage_Spark();
        a.d = this.n.j;
        a.g = this.n.k;
        a.f = this.n.i;
        a.e = this.n.h;
        a.k = this.n.m;
        a.l = this.n.n;
        a.j = this.n.g.count;
        a.h = this.o.c;
        a.i = this.o.d;
        a.c = this.q.am;
        this.m.sendMessage(a);
    }
    ar() {
        if (this.n.g.count == 0) {
            return;
        }
        let a = new List$1(List$1.$.specialize(Array_$type), 0);
        let b = new List$1(Array_$type, 0);
        let c = true;
        for (let d of fromEnum(this.n.g)) {
            if (isNaN_(d[1]) || isInfinity(d[1])) {
                if (!c) {
                    a.add(b);
                }
                c = true;
                continue;
            }
            if (c) {
                b = new List$1(Array_$type, 0);
                c = false;
            }
            b.add(d);
        }
        if (!c) {
            a.add(b);
        }
        let e = new PolygonMessage_Spark();
        e.points = new List$1(Array_$type, 0);
        if (this.q.ao == 0) {
            let f = new List$1(Array_$type, 0);
            for (let g of fromEnum(a)) {
                f.o(g);
            }
            let h = this.j(f);
            e.points.add(h);
        }
        else {
            for (let i of fromEnum(a)) {
                let j = this.j(i);
                e.points.add(j);
            }
        }
        this.m.sendMessage(e);
        this.aq();
    }
    j(a) {
        let b = this.o.c;
        let c = new List$1(Point_$type, 0);
        let d;
        let e = this.q.am == 1;
        for (let f of fromEnum(a)) {
            d = f[1];
            if (e) {
                if (f[2] <= b) {
                    d = f[2];
                }
            }
            c.add({ $type: Point_$type, x: f[0], y: d });
        }
        if (this.q.am == 0) {
            let g = new List$1(Point_$type, 0);
            for (let h of fromEnum(a)) {
                g.add({ $type: Point_$type, x: h[0], y: h[2] });
            }
            g.w();
            c.o(g);
        }
        if (this.q.am == 1 && c.count > 0) {
            let i = c._inner[0];
            let j = c._inner[c.count - 1];
            c.add({ $type: Point_$type, x: j.x, y: this.o.c });
            c.add({ $type: Point_$type, x: i.x, y: this.o.c });
        }
        return c.toArray();
    }
    aq() {
        let a = new MarkerMessage_Spark();
        a.e = this.n.j;
        a.f = this.n.k;
        a.d = this.n.i;
        a.c = this.n.h;
        a.m = this.n.m;
        a.n = this.n.n;
        a.k = this.q.a9;
        a.g = this.q.a2;
        a.i = this.q.a4;
        a.h = this.q.a3;
        a.j = this.q.a8;
        a.l = this.q.be;
        this.m.sendMessage(a);
    }
    getFastItemsSource(a) {
        let b = null;
        if (this.x != null) {
            let c = null;
            b = new FastItemsSource();
            b.e = this.x;
            c = new FastItemsSourceReference(b);
            c.b++;
            b = c.a;
        }
        return b;
    }
    releaseFastItemsSource(a) {
        if (a != null) {
            let b = null;
            --b.b;
        }
        return null;
    }
}
SparklineController.$t = markType(SparklineController, 'SparklineController', DependencyObject.$, [IFastItemsSourceProvider_$type]);
SparklineController.a2 = DependencyProperty.i("FastItemsSource", IFastItemsSource_$type, SparklineController.$, new PropertyMetadata(1, (a, b) => (typeCast(SparklineController.$, a)).av(b.oldValue, b.newValue)));
/**
 * @hidden
 */
export class XamSparkline extends Control {
    constructor() {
        super();
        this.al = null;
        this.aj = null;
        this.ah = new MessageChannel_Spark();
        this.aw = NaN;
        this.av = NaN;
        this.ar = null;
        this.ag = null;
        this.ap = null;
        this.ay = NaN;
        this.ax = 1;
        this.ab = XamSparkline.$;
        this.ap = new VerticalAxisView(this);
        this.ag = new HorizontalAxisView(this);
        this.al = new SparklineConnector(this, new XamSparklineView());
    }
    get toolTip() {
        return this.c(XamSparkline.ej);
    }
    set toolTip(a) {
        this.h(XamSparkline.ej, a);
        this.fe = a == null || a.toString().length == 0 ? 1 : 0;
    }
    at() {
        return this.bl != null;
    }
    cu(a) {
        return this.bl(a);
    }
    get ak() {
        return this.aj;
    }
    set ak(a) {
        let b = this.aj;
        this.aj = a;
        this.dh(b, this.aj);
    }
    get ai() {
        return this.ah;
    }
    set ai(a) {
        this.ah = a;
    }
    get a0() {
        return this.aw;
    }
    set a0(a) {
        this.aw = a;
    }
    get az() {
        return this.av;
    }
    set az(a) {
        this.av = a;
    }
    dh(a, b) {
        if (a != null) {
            this.ai.detachFromNext();
        }
        if (b != null) {
            this.ai.connectTo(b.getService("ConfigurationMessages"));
        }
    }
    onDetachedFromUI() {
        this.al.e.at();
    }
    onAttachedToUI() {
        this.al.e.ar();
    }
    dg(a, b, c) {
        if (a == "PixelScalingRatio") {
            if (!isNaN_(DeviceUtils.a(this.bh))) {
                this.a1 = DeviceUtils.a(this.bh);
            }
        }
        this.ai.sendMessage(((() => {
            let $ret = new PropertyChangedMessage_Spark();
            $ret.propertyName = a;
            $ret.oldValue = b;
            $ret.newValue = c;
            return $ret;
        })()));
    }
    destroy() {
        this.ai.sendMessage(((() => {
            let $ret = new PropertyChangedMessage_Spark();
            $ret.propertyName = "Container";
            $ret.newValue = null;
            return $ret;
        })()));
    }
    provideContainer(a) {
        this.ai.sendMessage(((() => {
            let $ret = new PropertyChangedMessage_Spark();
            $ret.propertyName = "Container";
            $ret.newValue = a;
            return $ret;
        })()));
    }
    notifyResized() {
        this.ai.sendMessage(new ContainerSizeChangedMessage_Spark());
    }
    dd(source_, a, b, c) {
        if (source_.dataView && source_.dataSource) {
            source_ = source_.dataView();
        }
        ;
        if (source_ != this.itemsSource) {
            return;
        }
        this.ai.sendMessage(((() => {
            let $ret = new DataChangedMessage_Spark();
            $ret.b = 2;
            $ret.e = b;
            $ret.d = c;
            $ret.c = a;
            return $ret;
        })()));
    }
    c9(source_) {
        if (source_.dataView && source_.dataSource) {
            source_ = source_.dataView();
        }
        ;
        if (source_ != this.itemsSource) {
            return;
        }
        this.ai.sendMessage(((() => {
            let $ret = new DataChangedMessage_Spark();
            $ret.b = 4;
            return $ret;
        })()));
    }
    da(source_, a, b) {
        if (source_.dataView && source_.dataSource) {
            source_ = source_.dataView();
        }
        ;
        if (source_ != this.itemsSource) {
            return;
        }
        this.ai.sendMessage(((() => {
            let $ret = new DataChangedMessage_Spark();
            $ret.b = 0;
            $ret.d = b;
            $ret.c = a;
            return $ret;
        })()));
    }
    db(source_, a, b) {
        if (source_.dataView && source_.dataSource) {
            source_ = source_.dataView();
        }
        ;
        if (source_ != this.itemsSource) {
            return;
        }
        this.ai.sendMessage(((() => {
            let $ret = new DataChangedMessage_Spark();
            $ret.b = 1;
            $ret.e = b;
            $ret.c = a;
            return $ret;
        })()));
    }
    aq() {
        let a = new SparklineVisualData();
        a.name = "SparklineVisualData";
        a.horizontalAxis = this.ag.i();
        a.verticalAxis = this.ap.i();
        this.al.e.am(a);
        return a;
    }
    bu() {
        let a = this.aq();
        a.scaleByViewport();
        return a.serialize();
    }
    get bh() {
        return this.ay;
    }
    set bh(a) {
        let b = this.ay;
        this.ay = a;
        this.dg("PixelScalingRatio", b, this.ay);
        if (this.ay != b) {
            this.dg("PixelScalingRatio", b, this.ay);
        }
    }
    get a1() {
        return this.ax;
    }
    set a1(a) {
        let b = this.ax;
        this.ax = a;
        if (this.ax != b) {
            this.dg("ActualPixelScalingRatio", b, this.ax);
        }
    }
}
XamSparkline.$t = markType(XamSparkline, 'XamSparkline', Control.$);
XamSparkline.bb = -1;
XamSparkline.a7 = -1;
XamSparkline.ej = DependencyProperty.i("ToolTip", Base.$, XamSparkline.$, new PropertyMetadata(2, null, (a, b) => (typeCast(XamSparkline.$, a)).dg("ToolTip", b.oldValue, b.newValue)));
XamSparkline.bk = -1;
XamSparkline.$$p = markDep(DependencyProperty, PropertyMetadata, XamSparkline, 'dg', ['Brush:eu:dj', [Brush.$, null], 'DisplayNormalRangeInFront:as:dk', [0, true], 'DisplayType:am:dl', [SparklineDisplayType_$type, enumGetBox(SparklineDisplayType_$type, 0)], 'FirstMarkerBrush:ev:dm', [Brush.$, null], 'FirstMarkerSize:a2:dn', [1, XamSparkline.bb], 'FirstMarkerVisibility:e6:dp', [Visibility_$type, enumGetBox(Visibility_$type, 1)], 'FormatLabel:bl:dq', [Delegate_$type], 'HighMarkerBrush:ew:dr', [Brush.$, null], 'HighMarkerSize:a3:ds', [1, XamSparkline.bb], 'HighMarkerVisibility:e7:dt', [Visibility_$type, enumGetBox(Visibility_$type, 1)], 'HorizontalAxisBrush:ex:du', [Brush.$, null], 'HorizontalAxisLabel:bn:dv', [4, "{0}"], 'HorizontalAxisVisibility:e8:dw', [Visibility_$type, enumGetBox(Visibility_$type, 1)], 'ItemsSource::dx', [IEnumerable_$type, null], 'LabelMemberPath:b7:dy', [2, null], 'LastMarkerBrush:ey:dz', [Brush.$, null], 'LastMarkerSize:a4:d0', [1, XamSparkline.bb], 'LastMarkerVisibility:e9:d1', [Visibility_$type, enumGetBox(Visibility_$type, 1)], 'LineThickness:a5:d2', [1, XamSparkline.a7], 'LowMarkerBrush:ez:d3', [Brush.$, null], 'LowMarkerSize:a8:d4', [1, XamSparkline.bb], 'LowMarkerVisibility:fa:d5', [Visibility_$type, enumGetBox(Visibility_$type, 1)], 'MarkerBrush:e0:d6', [Brush.$, null], 'MarkerSize:a9:d7', [1, XamSparkline.bb], 'MarkerVisibility:fb:d8', [Visibility_$type, enumGetBox(Visibility_$type, 1)], 'Maximum:bc:d9', [1, NaN], 'Minimum:bd:ea', [1, NaN], 'NegativeBrush:e1:eb', [Brush.$, null], 'NegativeMarkerBrush:e2:ec', [Brush.$, null], 'NegativeMarkerSize:be:ed', [1, XamSparkline.bb], 'NegativeMarkerVisibility:fc:ee', [Visibility_$type, enumGetBox(Visibility_$type, 1)], 'NormalRangeFill:e3:ef', [Brush.$, null], 'NormalRangeMaximum:bf:eg', [1, 0], 'NormalRangeMinimum:bg:eh', [1, 0], 'NormalRangeVisibility:fd:ei', [Visibility_$type, enumGetBox(Visibility_$type, 1)], 'ToolTipVisibility:fe:ek', [Visibility_$type, enumGetBox(Visibility_$type, 1)], 'TrendLineBrush:e4:el', [Brush.$, null], 'TrendLinePeriod:bm:em', [1, 7], 'TrendLineThickness:bi:en', [1, XamSparkline.bk], 'TrendLineType:an:eo', [TrendLineType_$type, enumGetBox(TrendLineType_$type, 0)], 'UnknownValuePlotting:ao:ep', [UnknownValuePlotting_$type, enumGetBox(UnknownValuePlotting_$type, 1)], 'ValueMemberPath:c2:eq', [2, null], 'VerticalAxisBrush:e5:er', [Brush.$, null], 'VerticalAxisLabel:bp:es', [4, "{0:n}"], 'VerticalAxisVisibility:ff:et', [Visibility_$type, enumGetBox(Visibility_$type, 1)]]);
//# sourceMappingURL=HorizontalAxisView_combined.js.map