/*
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 { TimeAxisBase } from "./TimeAxisBase";
import { ITimeRangeSelectorAxis_$type } from "./ITimeRangeSelectorAxis";
import { TimeAxisBreakCollection } from "./TimeAxisBreakCollection";
import { TimeAxisLabelFormatCollection } from "./TimeAxisLabelFormatCollection";
import { OrderedDictionary$2 } from "./OrderedDictionary$2";
import { TimeAxisBreak } from "./TimeAxisBreak";
import { List$1 } from "igniteui-react-core/ES2015/List$1";
import { TimeAxisIntervalCollection } from "./TimeAxisIntervalCollection";
import { runOn, delegateCombine, Number_$type, fromEnum, fromEn, typeCast, Date_$type, markType } from "igniteui-react-core/ES2015/type";
import { ScalerParams } from "./ScalerParams";
import { KeyValuePair$2 } from "igniteui-react-core/ES2015/KeyValuePair$2";
import { Rect } from "igniteui-react-core/ES2015/Rect";
import { TimeAxisInterval } from "./TimeAxisInterval";
import { NumericYAxis } from "./NumericYAxis";
import { LabelPosition } from "./LabelPosition";
import { Extensions } from "igniteui-react-core/ES2015/Extensions";
import { SortedListView$1 } from "./SortedListView$1";
import { Dictionary$2 } from "igniteui-react-core/ES2015/Dictionary$2";
import { truncate, intDivide, isNaN_ } from "igniteui-react-core/ES2015/number";
import { dateFromTicks, dateMaxValue, dateAdd, dateSubtract, dateAddMonths, dateFromValues, dateGetMonth, dateGetTimeOfDay, dateAddDays, dateAddHours, dateMinValue } from "igniteui-react-core/ES2015/date";
import { timeSpanTicks, timeSpanInit3, timeSpanInit1, timeSpanFromMilliseconds, timeSpanFromSeconds, timeSpanFromMinutes, timeSpanFromHours, timeSpanFromDays, timeSpanFromTicks, timeSpanTotalMilliseconds } from "igniteui-react-core/ES2015/timespan";
import { dateToStringFormat } from "igniteui-react-core/ES2015/dateExtended";
export class TimeXAxis extends TimeAxisBase {
    constructor() {
        super();
        this.mb = 0;
        this.lv = null;
        this.l1 = null;
        this._omission = 0;
        this.lt = null;
        this.lz = null;
        this.ml = 0;
        this.l7 = dateMaxValue();
        this.l6 = dateMinValue();
        this.mj = 0;
        this.ab = TimeXAxis.$;
        this.omission = (0);
        this.mb = -2147483648;
        this.lv = new TimeAxisBreakCollection();
        let a = this.lw;
        a.collectionChanged = delegateCombine(a.collectionChanged, runOn(this, this.mo));
        this.lz = new TimeAxisIntervalCollection();
        let b = this.l0;
        b.collectionChanged = delegateCombine(b.collectionChanged, runOn(this, this.mp));
        this.l1 = new TimeAxisLabelFormatCollection();
        let c = this.l2;
        c.collectionChanged = delegateCombine(c.collectionChanged, runOn(this, this.mq));
        this.ml = (0);
    }
    dt(a, b) {
        let c = new KeyValuePair$2(TimeAxisBreak.$, Number_$type);
        let d = this.mb != -2147483648 ? this.mb : 0;
        let e = this.lt != null ? this.lt.count : 0;
        while (d < e) {
            let f = this.lt.item1(d);
            if (f.d.getTime() <= a && f.c.getTime() >= a) {
                return NaN;
            }
            if (f.c.getTime() <= a) {
                c = new KeyValuePair$2(TimeAxisBreak.$, Number_$type, 1, f, this.lt.item(f));
                d++;
            }
            else {
                break;
            }
        }
        if (d > 0) {
            d -= 1;
        }
        if (this.mb != -2147483648) {
            this.mb = d;
        }
        let g;
        let h;
        if (c.key != null) {
            g = c.value;
            h = c.key.c;
        }
        else {
            g = 0;
            h = this.actualMinimumValue;
        }
        let fromPrecedingBreak_ = +(dateFromTicks(truncate(a))) - +h;
        let i = (fromPrecedingBreak_ / ((this.actualMaximumValue.getTime() - this.actualMinimumValue.getTime()) - this.omission));
        let j = g + i;
        j -= b.e.left;
        j /= b.e.width;
        let k = b.d.left;
        let l = b.d.right;
        let m = b.d.width;
        if (this.categoryMode != 0) {
            let n = this.getCategorySize(b.e, b.d, b.c);
            k += n / 2;
            l -= n / 2;
            m -= n;
        }
        if (this.b8) {
            return l - m * j;
        }
        return k + m * j;
    }
    gg(a, b, c, d) {
        this.mb = 0;
        for (let e = b; e < c; e++) {
            a.item(e, this.dt(a.item(e), d));
        }
        this.mb = -2147483648;
    }
    startCursor() {
        this.mb = 0;
    }
    resetCursor() {
        this.mb = -2147483648;
    }
    dw(a, b) {
        let c = b.d.left;
        let d = b.d.width;
        if (this.categoryMode != 0) {
            let e = this.getCategorySize(b.e, b.d, b.c);
            c += e / 2;
            d -= e;
        }
        let f = b.e.left + b.e.width * (a - c) / d;
        if (this.b8) {
            f = 1 - f;
        }
        let g = new KeyValuePair$2(TimeAxisBreak.$, Number_$type);
        if (this.lt != null) {
            for (let h of fromEnum(this.lt)) {
                if (h.value >= f && h.value <= f) {
                    return h.key.d.getTime();
                }
                if (h.value < f && h.value > g.value) {
                    g = h;
                }
            }
        }
        let precedingBreakEnd_;
        let i;
        if (g.key != null) {
            i = g.value;
            precedingBreakEnd_ = g.key.c;
        }
        else {
            i = 0;
            precedingBreakEnd_ = this.actualMinimumValue;
        }
        let portionFromPrecedingBreak_ = f - i;
        let actualRange_ = +(this.actualMaximumValue) - +(this.actualMinimumValue) - this.omission;
        return (precedingBreakEnd_.getTime() + portionFromPrecedingBreak_ * actualRange_);
    }
    get lw() {
        return this.lv;
    }
    get l2() {
        return this.l1;
    }
    gn(a, b, c, d) {
        super.gn(a, b, c, d);
        switch (b) {
            case "ActualMaximumValue":
                this.mn();
                break;
            case "DateTimeColumn":
                this.mj = this.mi();
                break;
        }
    }
    hb(a, b) {
        super.hb(a, b);
        this.mm();
        this.ln();
    }
    ha(a, b) {
        super.ha(a, b);
        this.mm();
        this.ln();
    }
    cm() {
        let a = super.cm();
        this.mm();
        return a;
    }
    get omission() {
        return this._omission;
    }
    set omission(a) {
        this._omission = a;
    }
    mn() {
        let a = this.l4(this.lw);
        let b = (0);
        for (let c of fromEnum(a)) {
            b += (+(c.c) - +(c.d));
        }
        this.omission = b;
    }
    l4(a) {
        let b = new List$1(TimeAxisBreak.$, 0);
        if (a == null || +(this.actualMaximumValue) == +(dateMaxValue())) {
            return b;
        }
        for (let c of fromEn(a)) {
            if (c.c >= this.actualMinimumValue && c.d <= this.actualMaximumValue) {
                b.add(c);
            }
            if (c.i != (0)) {
                let d = +(c.c) - +(c.d);
                let e = dateAdd(+(c.d), +(c.i));
                while (e <= this.actualMaximumValue) {
                    let f = this.l8(e, d);
                    let g = ((() => {
                        let $ret = new TimeAxisBreak();
                        $ret.d = e;
                        $ret.c = f;
                        return $ret;
                    })());
                    if (g.c >= this.actualMinimumValue && g.d <= this.actualMaximumValue) {
                        b.add(g);
                    }
                    if (dateSubtract(+(dateMaxValue()), +(c.i)) < g.d) {
                        break;
                    }
                    e = this.l8(g.d, c.i);
                }
            }
        }
        return b;
    }
    l8(a, b) {
        let c = dateFromTicks(a.getTime());
        c.setMilliseconds(c.getMilliseconds() + b);
        return c;
    }
    mm() {
        this.lt = new OrderedDictionary$2(TimeAxisBreak.$, Number_$type);
        if (+(this.actualMaximumValue) == +(dateMaxValue()) || this.lw == null || this.lw.count == 0 || this.bf == null) {
            return;
        }
        let a = new List$1(TimeAxisBreak.$, 1, this.l4(this.lw));
        a.aa((b, c) => b.d < c.d ? -1 : b.d > c.d ? 1 : 0);
        let b = this.bf.mk;
        let c = new ScalerParams(0, this.bf.mk, this.bf.mx, this.b8, this.bf.mo);
        let d = +(this.actualMaximumValue) - +(this.actualMinimumValue) - this.omission;
        let e = 0;
        for (let f of fromEnum(a)) {
            let g = timeSpanTicks((+(f.d) - +(this.actualMinimumValue))) / timeSpanTicks(d);
            let h = timeSpanTicks((+(f.c) - +(this.actualMinimumValue))) / timeSpanTicks(d);
            if (h < 0 || g - e > 1) {
                continue;
            }
            this.lt.addItem(f, g - e);
            e += (h - g);
        }
    }
    e0(a) {
        if (!(typeCast(Date_$type, a) !== null)) {
            return super.e0(a);
        }
        let b = TimeXAxis.mc(a, this.ml, this.l2);
        return b == null ? super.e0(a) : b;
    }
    static mc(a, b, c) {
        let d = null;
        if (b == (0)) {
            return null;
        }
        let e;
        if (c == null || c.count == 0) {
            e = TimeXAxis.mf(b);
        }
        else {
            for (let f of fromEnum(c)) {
                if (f.b > b) {
                    continue;
                }
                if (d == null || f.b > d.b) {
                    d = f;
                }
            }
            if (d == null) {
                return null;
            }
            e = d.a;
        }
        return dateToStringFormat(a, e);
    }
    get_ku() {
        return super.get_ku() || (this.l0 != null && this.l0.count > 0);
    }
    set_ku(a) {
        super.set_ku(a);
    }
    get ku() {
        return this.get_ku();
    }
    set ku(a) {
        this.set_ku(a);
    }
    get l0() {
        return this.lz;
    }
    me() {
        return TimeXAxis.mf(this.ml);
    }
    static mf(a) {
        a = Math.abs(a);
        if (a > timeSpanInit3(1825, 0, 0, 0)) {
            return "yyyy";
        }
        if (a > timeSpanInit3(365, 0, 0, 0)) {
            return "MMM yyyy";
        }
        if (a > timeSpanInit3(4, 0, 0, 0)) {
            return "MMM dd";
        }
        if (a > timeSpanInit3(1, 0, 0, 0)) {
            return "MMM dd hh:mmtt";
        }
        if (a > timeSpanInit1(0, 10, 0)) {
            return "hh:mm";
        }
        return "hh:mm:ss";
    }
    static lu() {
        if (TimeXAxis.ls == null) {
            TimeXAxis.ls = ((() => {
                let $ret = new OrderedDictionary$2(Number_$type, TimeAxisInterval.$);
                $ret.addItem((0), ((() => {
                    let $ret = new TimeAxisInterval();
                    $ret.a = 0;
                    $ret.d = 1;
                    return $ret;
                })()));
                $ret.addItem(timeSpanFromMilliseconds(1), ((() => {
                    let $ret = new TimeAxisInterval();
                    $ret.a = 1;
                    $ret.d = 1;
                    return $ret;
                })()));
                $ret.addItem(timeSpanFromSeconds(1), ((() => {
                    let $ret = new TimeAxisInterval();
                    $ret.a = 2;
                    $ret.d = 1;
                    return $ret;
                })()));
                $ret.addItem(timeSpanFromSeconds(30), ((() => {
                    let $ret = new TimeAxisInterval();
                    $ret.a = 2;
                    $ret.d = 30;
                    return $ret;
                })()));
                $ret.addItem(timeSpanFromMinutes(2), ((() => {
                    let $ret = new TimeAxisInterval();
                    $ret.a = 3;
                    $ret.d = 2;
                    return $ret;
                })()));
                $ret.addItem(timeSpanFromMinutes(5), ((() => {
                    let $ret = new TimeAxisInterval();
                    $ret.a = 3;
                    $ret.d = 5;
                    return $ret;
                })()));
                $ret.addItem(timeSpanFromHours(1), ((() => {
                    let $ret = new TimeAxisInterval();
                    $ret.a = 4;
                    $ret.d = 1;
                    return $ret;
                })()));
                $ret.addItem(timeSpanFromHours(12), ((() => {
                    let $ret = new TimeAxisInterval();
                    $ret.a = 4;
                    $ret.d = 12;
                    return $ret;
                })()));
                $ret.addItem(timeSpanFromDays(1), ((() => {
                    let $ret = new TimeAxisInterval();
                    $ret.a = 5;
                    $ret.d = 1;
                    return $ret;
                })()));
                $ret.addItem(timeSpanFromDays(2), ((() => {
                    let $ret = new TimeAxisInterval();
                    $ret.a = 5;
                    $ret.d = 2;
                    return $ret;
                })()));
                $ret.addItem(timeSpanFromDays(5), ((() => {
                    let $ret = new TimeAxisInterval();
                    $ret.a = 5;
                    $ret.d = 5;
                    return $ret;
                })()));
                $ret.addItem(timeSpanFromDays(10), ((() => {
                    let $ret = new TimeAxisInterval();
                    $ret.a = 5;
                    $ret.d = 10;
                    return $ret;
                })()));
                $ret.addItem(timeSpanFromDays(30), ((() => {
                    let $ret = new TimeAxisInterval();
                    $ret.a = 7;
                    $ret.d = 1;
                    return $ret;
                })()));
                $ret.addItem(timeSpanFromDays(60), ((() => {
                    let $ret = new TimeAxisInterval();
                    $ret.a = 7;
                    $ret.d = 3;
                    return $ret;
                })()));
                $ret.addItem(timeSpanFromDays(365), ((() => {
                    let $ret = new TimeAxisInterval();
                    $ret.a = 8;
                    $ret.d = 1;
                    return $ret;
                })()));
                $ret.addItem(timeSpanFromDays(365 * 10), ((() => {
                    let $ret = new TimeAxisInterval();
                    $ret.a = 8;
                    $ret.d = 10;
                    return $ret;
                })()));
                return $ret;
            })());
        }
        return TimeXAxis.ls;
    }
    lx() {
        if (this.cn) {
            let a = this.d5();
            let b = this.it.width;
            let c = truncate(Math.floor(b / a));
            let d = Number.MAX_VALUE;
            let e = c == 0 ? d : timeSpanFromTicks((intDivide(timeSpanTicks(this.ml), c)));
            let f = null;
            for (let g of fromEnum(TimeXAxis.lu())) {
                f = g.value;
                if (g.key > e) {
                    break;
                }
            }
            return f;
        }
        let h = this.ml;
        if (h == (0)) {
            return ((() => {
                let $ret = new TimeAxisInterval();
                $ret.a = 8;
                $ret.d = 1;
                return $ret;
            })());
        }
        if (h >= timeSpanFromDays(365 * 100)) {
            return ((() => {
                let $ret = new TimeAxisInterval();
                $ret.a = 8;
                $ret.d = 10;
                return $ret;
            })());
        }
        if (h >= timeSpanFromDays(365 * 5)) {
            return ((() => {
                let $ret = new TimeAxisInterval();
                $ret.a = 8;
                $ret.d = 1;
                return $ret;
            })());
        }
        if (h >= timeSpanFromDays(365 * 2)) {
            return ((() => {
                let $ret = new TimeAxisInterval();
                $ret.a = 7;
                $ret.d = 3;
                return $ret;
            })());
        }
        if (h >= timeSpanFromDays(150)) {
            return ((() => {
                let $ret = new TimeAxisInterval();
                $ret.a = 7;
                $ret.d = 1;
                return $ret;
            })());
        }
        if (h >= timeSpanFromDays(60)) {
            return ((() => {
                let $ret = new TimeAxisInterval();
                $ret.a = 5;
                $ret.d = 10;
                return $ret;
            })());
        }
        if (h >= timeSpanFromDays(30)) {
            return ((() => {
                let $ret = new TimeAxisInterval();
                $ret.a = 5;
                $ret.d = 5;
                return $ret;
            })());
        }
        if (h >= timeSpanFromDays(20)) {
            return ((() => {
                let $ret = new TimeAxisInterval();
                $ret.a = 5;
                $ret.d = 2;
                return $ret;
            })());
        }
        if (h >= timeSpanFromDays(4)) {
            return ((() => {
                let $ret = new TimeAxisInterval();
                $ret.a = 5;
                $ret.d = 1;
                return $ret;
            })());
        }
        if (h >= timeSpanFromDays(1)) {
            return ((() => {
                let $ret = new TimeAxisInterval();
                $ret.a = 4;
                $ret.d = 12;
                return $ret;
            })());
        }
        if (h >= timeSpanFromHours(6)) {
            return ((() => {
                let $ret = new TimeAxisInterval();
                $ret.a = 4;
                $ret.d = 1;
                return $ret;
            })());
        }
        if (h >= timeSpanFromMinutes(30)) {
            return ((() => {
                let $ret = new TimeAxisInterval();
                $ret.a = 3;
                $ret.d = 5;
                return $ret;
            })());
        }
        if (h >= timeSpanFromMinutes(10)) {
            return ((() => {
                let $ret = new TimeAxisInterval();
                $ret.a = 3;
                $ret.d = 2;
                return $ret;
            })());
        }
        return ((() => {
            let $ret = new TimeAxisInterval();
            $ret.a = 2;
            $ret.d = 30;
            return $ret;
        })());
    }
    ly() {
        if (this.l0 == null || this.l0.count == 0) {
            return this.lx();
        }
        if (this.ml == (0)) {
            return ((() => {
                let $ret = new TimeAxisInterval();
                $ret.a = 8;
                $ret.d = 1;
                return $ret;
            })());
        }
        let a = null;
        for (let b of fromEnum(this.l0)) {
            if (b.e > this.ml) {
                continue;
            }
            if (a == null || b.e > a.e) {
                a = b;
            }
        }
        return a == null ? this.lx() : a;
    }
    g0(a) {
        super.g0(a);
        let b = this.bf != null ? this.bf.mk : Rect.empty;
        let c = !b.isEmpty ? this.it : Rect.empty;
        let d = this.io();
        let e = this.im();
        let f = new ScalerParams(0, b, c, this.b8, d);
        if (this.kq == null && !this.kw() && !this.kx()) {
            return;
        }
        if (!b.isEmpty && !c.isEmpty) {
            let g = c.bottom;
            let h = g - c.top;
            if (this.ag != null) {
                let i = typeCast(NumericYAxis.$, this.ag);
                if (i != null) {
                    let j = this.g3(g, h, b, c, d, c.top, c.bottom);
                    g = j.p0;
                    h = j.p1;
                }
            }
            if (isNaN_(g)) {
                g = 0;
            }
            this.gj(this.a2.ax(), g, c, this.a2.e(), true);
            this.at.a8 = h;
            let k = truncate(Math.ceil(e.right));
            let l = truncate(Math.floor(e.left));
            let m = this.a2.a0();
            let n = this.a2.f();
            let o = this.a2.ay();
            this.ln();
            let p = new List$1(Date_$type, 1, this.l3());
            let q = new List$1(Number_$type, 0);
            for (let r = 0; r < p.count; r++) {
                q.add(p._inner[r].getTime());
            }
            this.gg(q, 0, q.count, f);
            for (let s = 0; s < p.count; s++) {
                let t = p._inner[s];
                let u = q._inner[s];
                let v = truncate(Math.round(u));
                if (v <= k) {
                    if (s % 2 == 0) {
                        let w = s < q.count - 1 ? q._inner[s + 1] : e.right;
                        this.g9(m, u, w, c);
                    }
                    this.g8(o, u, c, n, false);
                    this.je.add(u);
                }
                if (v >= l && v <= k) {
                    let x = this.e0(t);
                    if (x != null) {
                        this.cs.add1(x);
                        this.ct.add(new LabelPosition(u));
                    }
                }
            }
        }
        if ((this.aw == null || this.aw.visibility == 0) && this.ag != null) {
            if (this.aw != null && (this.aw.location == 4 || this.aw.location == 5)) {
                this.bf.hp();
            }
        }
        this.at.a1 = this.cs;
        this.at.a2 = this.ct;
        this.ke();
    }
    l3() {
        let a = this.bf != null ? this.bf.mk : Rect.empty;
        let b = !a.isEmpty ? this.it : Rect.empty;
        let c = this.io();
        let d = this.im();
        let e = new ScalerParams(0, a, b, this.b8, c);
        let f = this.ly();
        let g = this.visibleMinimum;
        if (!this.kx() && f != null) {
            if (f.a == 7 && g.getDate() != 1) {
                g = dateAddMonths(g, 1);
                g = dateFromValues(g.getFullYear(), dateGetMonth(g), 1, 0, 0, 0, 0);
            }
            else if (f.a == 5 && dateGetTimeOfDay(g) != (0)) {
                g = dateAddDays(g, 1);
                g = dateFromValues(g.getFullYear(), dateGetMonth(g), g.getDate(), 0, 0, 0, 0);
            }
            else if (f.a == 4 && g.getMinutes() != 0) {
                g = dateAddHours(g, 1);
                g = dateFromValues(g.getFullYear(), dateGetMonth(g), g.getDate(), g.getHours(), 0, 0, 0);
            }
        }
        let h = new List$1(Date_$type, 0);
        let i = 0;
        let j = 10000;
        if (f.d == 0) {
            return h;
        }
        while (g <= this.visibleMaximum && i++ < j) {
            let k = this.l5(g);
            let l = g;
            if (k.key != null) {
                l = f.c(k.key.c);
            }
            h.add(l);
            while (g <= l) {
                g = f.b(g);
            }
        }
        return h;
    }
    l5(a) {
        if (this.lt == null) {
            return new KeyValuePair$2(TimeAxisBreak.$, Number_$type);
        }
        for (let b of fromEnum(this.lt)) {
            if (b.key.d <= a && b.key.c >= a) {
                return b;
            }
        }
        return new KeyValuePair$2(TimeAxisBreak.$, Number_$type);
    }
    get visibleMinimum() {
        return this.l7;
    }
    set visibleMinimum(a) {
        this.l7 = a;
    }
    get visibleMaximum() {
        return this.l6;
    }
    set visibleMaximum(a) {
        this.l6 = a;
    }
    ln() {
        super.ln();
        if (this.bf == null || !Extensions.b(this.bf.mx)) {
            return;
        }
        let a = new ScalerParams(0, this.bf.mk, this.bf.mx, this.b8, this.bf.mo);
        let b = this.bf.mx.left;
        let c = this.bf.mx.right;
        if (this.categoryMode != 0) {
            let d = this.getCategorySize(a.e, a.d, a.c);
            b += d / 2;
            c -= d / 2;
        }
        let e = truncate(this.dw(b, a));
        let f = truncate(this.dw(c, a));
        if (e < 0 || f < 0) {
            this.ml = (0);
            return;
        }
        e = Math.min(dateMaxValue().getTime(), e);
        f = Math.min(dateMaxValue().getTime(), f);
        this.visibleMinimum = dateFromTicks(Math.min(e, f));
        this.visibleMaximum = dateFromTicks(Math.max(e, f));
        this.ml = +(this.visibleMaximum) - +(this.visibleMinimum);
    }
    getOffset1(a, b, c, d, e) {
        return 0;
    }
    i$f(a) {
        if (this.lw == null || this.lw.count == 0) {
            return super.i$f(a);
        }
        let b = this;
        if (b.i$b == null) {
            return -1;
        }
        let c = new SortedListView$1(Date_$type, this.kq, b.i$b);
        let ticks_ = a;
        let d = (new Date(ticks_));
        let e = this.k8(d, c);
        e = Math.max(0, Math.min(b.i$b.count - 1, e));
        let f = c.item(e);
        let g;
        let h;
        if (f < d) {
            g = e;
            h = g + 1;
        }
        else {
            h = e;
            g = e - 1;
        }
        if (g < 0) {
            return h;
        }
        if (h >= b.i$b.count) {
            return g;
        }
        let i = c.item(g);
        let j = c.item(h);
        let k = new ScalerParams(0, this.bf.my, this.it, this.b8, this.bf.mo);
        this.startCursor();
        let l = this.dt(i.getTime(), k);
        let m = this.dt(a, k);
        let n = this.dt(j.getTime(), k);
        this.resetCursor();
        if (Math.abs(l - m) < Math.abs(n - m)) {
            return this.kz._inner[g];
        }
        else {
            return this.kz._inner[h];
        }
    }
    mo(a, b) {
        this.mn();
        this.mm();
        if (this.at != null) {
            this.at.ak = this.lw.count > 0;
        }
        this.gz(false);
        for (let c of fromEnum(this.cr())) {
            c.i1(false);
        }
    }
    mq(a, b) {
        this.gz(false);
    }
    mp(a, b) {
        this.gz(false);
    }
    get_b3() {
        return false;
    }
    get b3() {
        return this.get_b3();
    }
    getWindowRectForSelection(a, b) {
        let c = +(this.actualMaximumValue) - +(this.actualMinimumValue);
        let d = timeSpanTotalMilliseconds((+a - +(this.actualMinimumValue))) / timeSpanTotalMilliseconds(c);
        let e = 1 - (timeSpanTotalMilliseconds((+(this.actualMaximumValue) - +b)) / timeSpanTotalMilliseconds(c));
        e = Math.min(1, e);
        return new Rect(0, d, NaN, Math.max(0, e - d), NaN);
    }
    getCategorySize(a, b, c) {
        if (this.ml != (0)) {
            let d = timeSpanFromTicks(truncate((timeSpanTicks(this.ml) * (a.width / (this.bf != null ? this.bf.mk.width : 1)))));
            let e = timeSpanTicks(d) / timeSpanTicks(this.mj);
            let f = b.width / 4;
            return Math.min(f, b.width / (e + 1));
        }
        return super.getCategorySize(a, b, c);
    }
    mi() {
        if (this.kq == null || this.kq.count < 2 || this.kz == null) {
            return (0);
        }
        let a = Math.min(5, this.kq.count);
        let b = this.kq.item(this.kz._inner[0]);
        let c = new Dictionary$2(Number_$type, Number_$type, 0);
        let d = 0;
        let e = (0);
        for (let f = 0; f < a; f++) {
            let g = this.kq.item(this.kz._inner[f]);
            let h = +g - +b;
            if (!c.containsKey(h)) {
                c.addItem(h, 0);
            }
            c.item(h, c.item(h) + 1);
            if (c.item(h) > d) {
                d = c.item(h);
                e = h;
            }
            b = g;
        }
        return e;
    }
    lj() {
        super.lj();
        this.mj = this.mi();
    }
    get isVertical() {
        return this.ce;
    }
    j$c(a, b) {
        return this.dw.apply(this, arguments);
    }
    j$b(a, b) {
        return this.dt.apply(this, arguments);
    }
    j$d(a, b, c, d, e) {
        this.gf.apply(this, arguments);
    }
    j$e(a, b, c, d) {
        this.gg.apply(this, arguments);
    }
    j$f(a, b, c, d) {
        this.gh.apply(this, arguments);
    }
    get j$a() {
        return this.b8;
    }
    get i$a() {
        return this.b5;
    }
}
TimeXAxis.ls = null;
TimeXAxis.$t = markType(TimeXAxis, 'TimeXAxis', TimeAxisBase.$, [ITimeRangeSelectorAxis_$type]);
/*<BeginStatics Name="Infragistics.Controls.Charts.TimeXAxis" />*/
/*<EndStatics Name="Infragistics.Controls.Charts.TimeXAxis" />*/
