/*
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 * as tslib_1 from "tslib";
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/ES5/List$1";
import { TimeAxisIntervalCollection } from "./TimeAxisIntervalCollection";
import { runOn, delegateCombine, Number_$type, fromEnum, fromEn, typeCast, Date_$type, markType } from "igniteui-react-core/ES5/type";
import { ScalerParams } from "./ScalerParams";
import { KeyValuePair$2 } from "igniteui-react-core/ES5/KeyValuePair$2";
import { Rect } from "igniteui-react-core/ES5/Rect";
import { TimeAxisInterval } from "./TimeAxisInterval";
import { NumericYAxis } from "./NumericYAxis";
import { LabelPosition } from "./LabelPosition";
import { Extensions } from "igniteui-react-core/ES5/Extensions";
import { SortedListView$1 } from "./SortedListView$1";
import { Dictionary$2 } from "igniteui-react-core/ES5/Dictionary$2";
import { truncate, intDivide, isNaN_ } from "igniteui-react-core/ES5/number";
import { dateFromTicks, dateMaxValue, dateAdd, dateSubtract, dateAddMonths, dateFromValues, dateGetMonth, dateGetTimeOfDay, dateAddDays, dateAddHours, dateMinValue } from "igniteui-react-core/ES5/date";
import { timeSpanTicks, timeSpanInit3, timeSpanInit1, timeSpanFromMilliseconds, timeSpanFromSeconds, timeSpanFromMinutes, timeSpanFromHours, timeSpanFromDays, timeSpanFromTicks, timeSpanTotalMilliseconds } from "igniteui-react-core/ES5/timespan";
import { dateToStringFormat } from "igniteui-react-core/ES5/dateExtended";
var TimeXAxis = /** @class */ (function (_super) {
    tslib_1.__extends(TimeXAxis, _super);
    function TimeXAxis() {
        var _this = _super.call(this) || this;
        _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();
        var a = _this.lw;
        a.collectionChanged = delegateCombine(a.collectionChanged, runOn(_this, _this.mo));
        _this.lz = new TimeAxisIntervalCollection();
        var b = _this.l0;
        b.collectionChanged = delegateCombine(b.collectionChanged, runOn(_this, _this.mp));
        _this.l1 = new TimeAxisLabelFormatCollection();
        var c = _this.l2;
        c.collectionChanged = delegateCombine(c.collectionChanged, runOn(_this, _this.mq));
        _this.ml = (0);
        return _this;
    }
    TimeXAxis.prototype.dt = function (a, b) {
        var c = new KeyValuePair$2(TimeAxisBreak.$, Number_$type);
        var d = this.mb != -2147483648 ? this.mb : 0;
        var e = this.lt != null ? this.lt.count : 0;
        while (d < e) {
            var 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;
        }
        var g;
        var h;
        if (c.key != null) {
            g = c.value;
            h = c.key.c;
        }
        else {
            g = 0;
            h = this.actualMinimumValue;
        }
        var fromPrecedingBreak_ = +(dateFromTicks(truncate(a))) - +h;
        var i = (fromPrecedingBreak_ / ((this.actualMaximumValue.getTime() - this.actualMinimumValue.getTime()) - this.omission));
        var j = g + i;
        j -= b.e.left;
        j /= b.e.width;
        var k = b.d.left;
        var l = b.d.right;
        var m = b.d.width;
        if (this.categoryMode != 0) {
            var 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;
    };
    TimeXAxis.prototype.gg = function (a, b, c, d) {
        this.mb = 0;
        for (var e = b; e < c; e++) {
            a.item(e, this.dt(a.item(e), d));
        }
        this.mb = -2147483648;
    };
    TimeXAxis.prototype.startCursor = function () {
        this.mb = 0;
    };
    TimeXAxis.prototype.resetCursor = function () {
        this.mb = -2147483648;
    };
    TimeXAxis.prototype.dw = function (a, b) {
        var c = b.d.left;
        var d = b.d.width;
        if (this.categoryMode != 0) {
            var e = this.getCategorySize(b.e, b.d, b.c);
            c += e / 2;
            d -= e;
        }
        var f = b.e.left + b.e.width * (a - c) / d;
        if (this.b8) {
            f = 1 - f;
        }
        var g = new KeyValuePair$2(TimeAxisBreak.$, Number_$type);
        if (this.lt != null) {
            try {
                for (var _a = tslib_1.__values(fromEnum(this.lt)), _b = _a.next(); !_b.done; _b = _a.next()) {
                    var h = _b.value;
                    if (h.value >= f && h.value <= f) {
                        return h.key.d.getTime();
                    }
                    if (h.value < f && h.value > g.value) {
                        g = h;
                    }
                }
            }
            catch (e_1_1) { e_1 = { error: e_1_1 }; }
            finally {
                try {
                    if (_b && !_b.done && (_c = _a.return)) _c.call(_a);
                }
                finally { if (e_1) throw e_1.error; }
            }
        }
        var precedingBreakEnd_;
        var i;
        if (g.key != null) {
            i = g.value;
            precedingBreakEnd_ = g.key.c;
        }
        else {
            i = 0;
            precedingBreakEnd_ = this.actualMinimumValue;
        }
        var portionFromPrecedingBreak_ = f - i;
        var actualRange_ = +(this.actualMaximumValue) - +(this.actualMinimumValue) - this.omission;
        return (precedingBreakEnd_.getTime() + portionFromPrecedingBreak_ * actualRange_);
        var e_1, _c;
    };
    Object.defineProperty(TimeXAxis.prototype, "lw", {
        get: function () {
            return this.lv;
        },
        enumerable: true,
        configurable: true
    });
    Object.defineProperty(TimeXAxis.prototype, "l2", {
        get: function () {
            return this.l1;
        },
        enumerable: true,
        configurable: true
    });
    TimeXAxis.prototype.gn = function (a, b, c, d) {
        _super.prototype.gn.call(this, a, b, c, d);
        switch (b) {
            case "ActualMaximumValue":
                this.mn();
                break;
            case "DateTimeColumn":
                this.mj = this.mi();
                break;
        }
    };
    TimeXAxis.prototype.hb = function (a, b) {
        _super.prototype.hb.call(this, a, b);
        this.mm();
        this.ln();
    };
    TimeXAxis.prototype.ha = function (a, b) {
        _super.prototype.ha.call(this, a, b);
        this.mm();
        this.ln();
    };
    TimeXAxis.prototype.cm = function () {
        var a = _super.prototype.cm.call(this);
        this.mm();
        return a;
    };
    Object.defineProperty(TimeXAxis.prototype, "omission", {
        get: function () {
            return this._omission;
        },
        set: function (a) {
            this._omission = a;
        },
        enumerable: true,
        configurable: true
    });
    TimeXAxis.prototype.mn = function () {
        var a = this.l4(this.lw);
        var b = (0);
        try {
            for (var _a = tslib_1.__values(fromEnum(a)), _b = _a.next(); !_b.done; _b = _a.next()) {
                var c = _b.value;
                b += (+(c.c) - +(c.d));
            }
        }
        catch (e_2_1) { e_2 = { error: e_2_1 }; }
        finally {
            try {
                if (_b && !_b.done && (_c = _a.return)) _c.call(_a);
            }
            finally { if (e_2) throw e_2.error; }
        }
        this.omission = b;
        var e_2, _c;
    };
    TimeXAxis.prototype.l4 = function (a) {
        var b = new List$1(TimeAxisBreak.$, 0);
        if (a == null || +(this.actualMaximumValue) == +(dateMaxValue())) {
            return b;
        }
        var _loop_1 = function (c) {
            if (c.c >= this_1.actualMinimumValue && c.d <= this_1.actualMaximumValue) {
                b.add(c);
            }
            if (c.i != (0)) {
                var d = +(c.c) - +(c.d);
                var e_3 = dateAdd(+(c.d), +(c.i));
                var _loop_2 = function () {
                    var f = this_1.l8(e_3, d);
                    var g = ((function () {
                        var $ret = new TimeAxisBreak();
                        $ret.d = e_3;
                        $ret.c = f;
                        return $ret;
                    })());
                    if (g.c >= this_1.actualMinimumValue && g.d <= this_1.actualMaximumValue) {
                        b.add(g);
                    }
                    if (dateSubtract(+(dateMaxValue()), +(c.i)) < g.d) {
                        return "break";
                    }
                    e_3 = this_1.l8(g.d, c.i);
                };
                while (e_3 <= this_1.actualMaximumValue) {
                    var state_1 = _loop_2();
                    if (state_1 === "break")
                        break;
                }
            }
        };
        var this_1 = this;
        try {
            for (var _a = tslib_1.__values(fromEn(a)), _b = _a.next(); !_b.done; _b = _a.next()) {
                var c = _b.value;
                _loop_1(c);
            }
        }
        catch (e_4_1) { e_4 = { error: e_4_1 }; }
        finally {
            try {
                if (_b && !_b.done && (_c = _a.return)) _c.call(_a);
            }
            finally { if (e_4) throw e_4.error; }
        }
        return b;
        var e_4, _c;
    };
    TimeXAxis.prototype.l8 = function (a, b) {
        var c = dateFromTicks(a.getTime());
        c.setMilliseconds(c.getMilliseconds() + b);
        return c;
    };
    TimeXAxis.prototype.mm = function () {
        this.lt = new OrderedDictionary$2(TimeAxisBreak.$, Number_$type);
        if (+(this.actualMaximumValue) == +(dateMaxValue()) || this.lw == null || this.lw.count == 0 || this.bf == null) {
            return;
        }
        var a = new List$1(TimeAxisBreak.$, 1, this.l4(this.lw));
        a.aa(function (b, c) { return b.d < c.d ? -1 : b.d > c.d ? 1 : 0; });
        var b = this.bf.mk;
        var c = new ScalerParams(0, this.bf.mk, this.bf.mx, this.b8, this.bf.mo);
        var d = +(this.actualMaximumValue) - +(this.actualMinimumValue) - this.omission;
        var e = 0;
        try {
            for (var _a = tslib_1.__values(fromEnum(a)), _b = _a.next(); !_b.done; _b = _a.next()) {
                var f = _b.value;
                var g = timeSpanTicks((+(f.d) - +(this.actualMinimumValue))) / timeSpanTicks(d);
                var h = timeSpanTicks((+(f.c) - +(this.actualMinimumValue))) / timeSpanTicks(d);
                if (h < 0 || g - e > 1) {
                    continue;
                }
                this.lt.addItem(f, g - e);
                e += (h - g);
            }
        }
        catch (e_5_1) { e_5 = { error: e_5_1 }; }
        finally {
            try {
                if (_b && !_b.done && (_c = _a.return)) _c.call(_a);
            }
            finally { if (e_5) throw e_5.error; }
        }
        var e_5, _c;
    };
    TimeXAxis.prototype.e0 = function (a) {
        if (!(typeCast(Date_$type, a) !== null)) {
            return _super.prototype.e0.call(this, a);
        }
        var b = TimeXAxis.mc(a, this.ml, this.l2);
        return b == null ? _super.prototype.e0.call(this, a) : b;
    };
    TimeXAxis.mc = function (a, b, c) {
        var d = null;
        if (b == (0)) {
            return null;
        }
        var e;
        if (c == null || c.count == 0) {
            e = TimeXAxis.mf(b);
        }
        else {
            try {
                for (var _a = tslib_1.__values(fromEnum(c)), _b = _a.next(); !_b.done; _b = _a.next()) {
                    var f = _b.value;
                    if (f.b > b) {
                        continue;
                    }
                    if (d == null || f.b > d.b) {
                        d = f;
                    }
                }
            }
            catch (e_6_1) { e_6 = { error: e_6_1 }; }
            finally {
                try {
                    if (_b && !_b.done && (_c = _a.return)) _c.call(_a);
                }
                finally { if (e_6) throw e_6.error; }
            }
            if (d == null) {
                return null;
            }
            e = d.a;
        }
        return dateToStringFormat(a, e);
        var e_6, _c;
    };
    TimeXAxis.prototype.get_ku = function () {
        return _super.prototype.get_ku.call(this) || (this.l0 != null && this.l0.count > 0);
    };
    TimeXAxis.prototype.set_ku = function (a) {
        _super.prototype.set_ku.call(this, a);
    };
    Object.defineProperty(TimeXAxis.prototype, "ku", {
        get: function () {
            return this.get_ku();
        },
        set: function (a) {
            this.set_ku(a);
        },
        enumerable: true,
        configurable: true
    });
    Object.defineProperty(TimeXAxis.prototype, "l0", {
        get: function () {
            return this.lz;
        },
        enumerable: true,
        configurable: true
    });
    TimeXAxis.prototype.me = function () {
        return TimeXAxis.mf(this.ml);
    };
    TimeXAxis.mf = function (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";
    };
    TimeXAxis.lu = function () {
        if (TimeXAxis.ls == null) {
            TimeXAxis.ls = ((function () {
                var $ret = new OrderedDictionary$2(Number_$type, TimeAxisInterval.$);
                $ret.addItem((0), ((function () {
                    var $ret = new TimeAxisInterval();
                    $ret.a = 0;
                    $ret.d = 1;
                    return $ret;
                })()));
                $ret.addItem(timeSpanFromMilliseconds(1), ((function () {
                    var $ret = new TimeAxisInterval();
                    $ret.a = 1;
                    $ret.d = 1;
                    return $ret;
                })()));
                $ret.addItem(timeSpanFromSeconds(1), ((function () {
                    var $ret = new TimeAxisInterval();
                    $ret.a = 2;
                    $ret.d = 1;
                    return $ret;
                })()));
                $ret.addItem(timeSpanFromSeconds(30), ((function () {
                    var $ret = new TimeAxisInterval();
                    $ret.a = 2;
                    $ret.d = 30;
                    return $ret;
                })()));
                $ret.addItem(timeSpanFromMinutes(2), ((function () {
                    var $ret = new TimeAxisInterval();
                    $ret.a = 3;
                    $ret.d = 2;
                    return $ret;
                })()));
                $ret.addItem(timeSpanFromMinutes(5), ((function () {
                    var $ret = new TimeAxisInterval();
                    $ret.a = 3;
                    $ret.d = 5;
                    return $ret;
                })()));
                $ret.addItem(timeSpanFromHours(1), ((function () {
                    var $ret = new TimeAxisInterval();
                    $ret.a = 4;
                    $ret.d = 1;
                    return $ret;
                })()));
                $ret.addItem(timeSpanFromHours(12), ((function () {
                    var $ret = new TimeAxisInterval();
                    $ret.a = 4;
                    $ret.d = 12;
                    return $ret;
                })()));
                $ret.addItem(timeSpanFromDays(1), ((function () {
                    var $ret = new TimeAxisInterval();
                    $ret.a = 5;
                    $ret.d = 1;
                    return $ret;
                })()));
                $ret.addItem(timeSpanFromDays(2), ((function () {
                    var $ret = new TimeAxisInterval();
                    $ret.a = 5;
                    $ret.d = 2;
                    return $ret;
                })()));
                $ret.addItem(timeSpanFromDays(5), ((function () {
                    var $ret = new TimeAxisInterval();
                    $ret.a = 5;
                    $ret.d = 5;
                    return $ret;
                })()));
                $ret.addItem(timeSpanFromDays(10), ((function () {
                    var $ret = new TimeAxisInterval();
                    $ret.a = 5;
                    $ret.d = 10;
                    return $ret;
                })()));
                $ret.addItem(timeSpanFromDays(30), ((function () {
                    var $ret = new TimeAxisInterval();
                    $ret.a = 7;
                    $ret.d = 1;
                    return $ret;
                })()));
                $ret.addItem(timeSpanFromDays(60), ((function () {
                    var $ret = new TimeAxisInterval();
                    $ret.a = 7;
                    $ret.d = 3;
                    return $ret;
                })()));
                $ret.addItem(timeSpanFromDays(365), ((function () {
                    var $ret = new TimeAxisInterval();
                    $ret.a = 8;
                    $ret.d = 1;
                    return $ret;
                })()));
                $ret.addItem(timeSpanFromDays(365 * 10), ((function () {
                    var $ret = new TimeAxisInterval();
                    $ret.a = 8;
                    $ret.d = 10;
                    return $ret;
                })()));
                return $ret;
            })());
        }
        return TimeXAxis.ls;
    };
    TimeXAxis.prototype.lx = function () {
        if (this.cn) {
            var a = this.d5();
            var b = this.it.width;
            var c = truncate(Math.floor(b / a));
            var d = Number.MAX_VALUE;
            var e = c == 0 ? d : timeSpanFromTicks((intDivide(timeSpanTicks(this.ml), c)));
            var f = null;
            try {
                for (var _a = tslib_1.__values(fromEnum(TimeXAxis.lu())), _b = _a.next(); !_b.done; _b = _a.next()) {
                    var g = _b.value;
                    f = g.value;
                    if (g.key > e) {
                        break;
                    }
                }
            }
            catch (e_7_1) { e_7 = { error: e_7_1 }; }
            finally {
                try {
                    if (_b && !_b.done && (_c = _a.return)) _c.call(_a);
                }
                finally { if (e_7) throw e_7.error; }
            }
            return f;
        }
        var h = this.ml;
        if (h == (0)) {
            return ((function () {
                var $ret = new TimeAxisInterval();
                $ret.a = 8;
                $ret.d = 1;
                return $ret;
            })());
        }
        if (h >= timeSpanFromDays(365 * 100)) {
            return ((function () {
                var $ret = new TimeAxisInterval();
                $ret.a = 8;
                $ret.d = 10;
                return $ret;
            })());
        }
        if (h >= timeSpanFromDays(365 * 5)) {
            return ((function () {
                var $ret = new TimeAxisInterval();
                $ret.a = 8;
                $ret.d = 1;
                return $ret;
            })());
        }
        if (h >= timeSpanFromDays(365 * 2)) {
            return ((function () {
                var $ret = new TimeAxisInterval();
                $ret.a = 7;
                $ret.d = 3;
                return $ret;
            })());
        }
        if (h >= timeSpanFromDays(150)) {
            return ((function () {
                var $ret = new TimeAxisInterval();
                $ret.a = 7;
                $ret.d = 1;
                return $ret;
            })());
        }
        if (h >= timeSpanFromDays(60)) {
            return ((function () {
                var $ret = new TimeAxisInterval();
                $ret.a = 5;
                $ret.d = 10;
                return $ret;
            })());
        }
        if (h >= timeSpanFromDays(30)) {
            return ((function () {
                var $ret = new TimeAxisInterval();
                $ret.a = 5;
                $ret.d = 5;
                return $ret;
            })());
        }
        if (h >= timeSpanFromDays(20)) {
            return ((function () {
                var $ret = new TimeAxisInterval();
                $ret.a = 5;
                $ret.d = 2;
                return $ret;
            })());
        }
        if (h >= timeSpanFromDays(4)) {
            return ((function () {
                var $ret = new TimeAxisInterval();
                $ret.a = 5;
                $ret.d = 1;
                return $ret;
            })());
        }
        if (h >= timeSpanFromDays(1)) {
            return ((function () {
                var $ret = new TimeAxisInterval();
                $ret.a = 4;
                $ret.d = 12;
                return $ret;
            })());
        }
        if (h >= timeSpanFromHours(6)) {
            return ((function () {
                var $ret = new TimeAxisInterval();
                $ret.a = 4;
                $ret.d = 1;
                return $ret;
            })());
        }
        if (h >= timeSpanFromMinutes(30)) {
            return ((function () {
                var $ret = new TimeAxisInterval();
                $ret.a = 3;
                $ret.d = 5;
                return $ret;
            })());
        }
        if (h >= timeSpanFromMinutes(10)) {
            return ((function () {
                var $ret = new TimeAxisInterval();
                $ret.a = 3;
                $ret.d = 2;
                return $ret;
            })());
        }
        return ((function () {
            var $ret = new TimeAxisInterval();
            $ret.a = 2;
            $ret.d = 30;
            return $ret;
        })());
        var e_7, _c;
    };
    TimeXAxis.prototype.ly = function () {
        if (this.l0 == null || this.l0.count == 0) {
            return this.lx();
        }
        if (this.ml == (0)) {
            return ((function () {
                var $ret = new TimeAxisInterval();
                $ret.a = 8;
                $ret.d = 1;
                return $ret;
            })());
        }
        var a = null;
        try {
            for (var _a = tslib_1.__values(fromEnum(this.l0)), _b = _a.next(); !_b.done; _b = _a.next()) {
                var b = _b.value;
                if (b.e > this.ml) {
                    continue;
                }
                if (a == null || b.e > a.e) {
                    a = b;
                }
            }
        }
        catch (e_8_1) { e_8 = { error: e_8_1 }; }
        finally {
            try {
                if (_b && !_b.done && (_c = _a.return)) _c.call(_a);
            }
            finally { if (e_8) throw e_8.error; }
        }
        return a == null ? this.lx() : a;
        var e_8, _c;
    };
    TimeXAxis.prototype.g0 = function (a) {
        _super.prototype.g0.call(this, a);
        var b = this.bf != null ? this.bf.mk : Rect.empty;
        var c = !b.isEmpty ? this.it : Rect.empty;
        var d = this.io();
        var e = this.im();
        var f = new ScalerParams(0, b, c, this.b8, d);
        if (this.kq == null && !this.kw() && !this.kx()) {
            return;
        }
        if (!b.isEmpty && !c.isEmpty) {
            var g = c.bottom;
            var h = g - c.top;
            if (this.ag != null) {
                var i = typeCast(NumericYAxis.$, this.ag);
                if (i != null) {
                    var 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;
            var k = truncate(Math.ceil(e.right));
            var l = truncate(Math.floor(e.left));
            var m = this.a2.a0();
            var n = this.a2.f();
            var o = this.a2.ay();
            this.ln();
            var p = new List$1(Date_$type, 1, this.l3());
            var q = new List$1(Number_$type, 0);
            for (var r = 0; r < p.count; r++) {
                q.add(p._inner[r].getTime());
            }
            this.gg(q, 0, q.count, f);
            for (var s = 0; s < p.count; s++) {
                var t = p._inner[s];
                var u = q._inner[s];
                var v = truncate(Math.round(u));
                if (v <= k) {
                    if (s % 2 == 0) {
                        var 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) {
                    var 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();
    };
    TimeXAxis.prototype.l3 = function () {
        var a = this.bf != null ? this.bf.mk : Rect.empty;
        var b = !a.isEmpty ? this.it : Rect.empty;
        var c = this.io();
        var d = this.im();
        var e = new ScalerParams(0, a, b, this.b8, c);
        var f = this.ly();
        var 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);
            }
        }
        var h = new List$1(Date_$type, 0);
        var i = 0;
        var j = 10000;
        if (f.d == 0) {
            return h;
        }
        while (g <= this.visibleMaximum && i++ < j) {
            var k = this.l5(g);
            var l = g;
            if (k.key != null) {
                l = f.c(k.key.c);
            }
            h.add(l);
            while (g <= l) {
                g = f.b(g);
            }
        }
        return h;
    };
    TimeXAxis.prototype.l5 = function (a) {
        if (this.lt == null) {
            return new KeyValuePair$2(TimeAxisBreak.$, Number_$type);
        }
        try {
            for (var _a = tslib_1.__values(fromEnum(this.lt)), _b = _a.next(); !_b.done; _b = _a.next()) {
                var b = _b.value;
                if (b.key.d <= a && b.key.c >= a) {
                    return b;
                }
            }
        }
        catch (e_9_1) { e_9 = { error: e_9_1 }; }
        finally {
            try {
                if (_b && !_b.done && (_c = _a.return)) _c.call(_a);
            }
            finally { if (e_9) throw e_9.error; }
        }
        return new KeyValuePair$2(TimeAxisBreak.$, Number_$type);
        var e_9, _c;
    };
    Object.defineProperty(TimeXAxis.prototype, "visibleMinimum", {
        get: function () {
            return this.l7;
        },
        set: function (a) {
            this.l7 = a;
        },
        enumerable: true,
        configurable: true
    });
    Object.defineProperty(TimeXAxis.prototype, "visibleMaximum", {
        get: function () {
            return this.l6;
        },
        set: function (a) {
            this.l6 = a;
        },
        enumerable: true,
        configurable: true
    });
    TimeXAxis.prototype.ln = function () {
        _super.prototype.ln.call(this);
        if (this.bf == null || !Extensions.b(this.bf.mx)) {
            return;
        }
        var a = new ScalerParams(0, this.bf.mk, this.bf.mx, this.b8, this.bf.mo);
        var b = this.bf.mx.left;
        var c = this.bf.mx.right;
        if (this.categoryMode != 0) {
            var d = this.getCategorySize(a.e, a.d, a.c);
            b += d / 2;
            c -= d / 2;
        }
        var e = truncate(this.dw(b, a));
        var 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);
    };
    TimeXAxis.prototype.getOffset1 = function (a, b, c, d, e) {
        return 0;
    };
    TimeXAxis.prototype.i$f = function (a) {
        if (this.lw == null || this.lw.count == 0) {
            return _super.prototype.i$f.call(this, a);
        }
        var b = this;
        if (b.i$b == null) {
            return -1;
        }
        var c = new SortedListView$1(Date_$type, this.kq, b.i$b);
        var ticks_ = a;
        var d = (new Date(ticks_));
        var e = this.k8(d, c);
        e = Math.max(0, Math.min(b.i$b.count - 1, e));
        var f = c.item(e);
        var g;
        var 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;
        }
        var i = c.item(g);
        var j = c.item(h);
        var k = new ScalerParams(0, this.bf.my, this.it, this.b8, this.bf.mo);
        this.startCursor();
        var l = this.dt(i.getTime(), k);
        var m = this.dt(a, k);
        var 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];
        }
    };
    TimeXAxis.prototype.mo = function (a, b) {
        this.mn();
        this.mm();
        if (this.at != null) {
            this.at.ak = this.lw.count > 0;
        }
        this.gz(false);
        try {
            for (var _a = tslib_1.__values(fromEnum(this.cr())), _b = _a.next(); !_b.done; _b = _a.next()) {
                var c = _b.value;
                c.i1(false);
            }
        }
        catch (e_10_1) { e_10 = { error: e_10_1 }; }
        finally {
            try {
                if (_b && !_b.done && (_c = _a.return)) _c.call(_a);
            }
            finally { if (e_10) throw e_10.error; }
        }
        var e_10, _c;
    };
    TimeXAxis.prototype.mq = function (a, b) {
        this.gz(false);
    };
    TimeXAxis.prototype.mp = function (a, b) {
        this.gz(false);
    };
    TimeXAxis.prototype.get_b3 = function () {
        return false;
    };
    Object.defineProperty(TimeXAxis.prototype, "b3", {
        get: function () {
            return this.get_b3();
        },
        enumerable: true,
        configurable: true
    });
    TimeXAxis.prototype.getWindowRectForSelection = function (a, b) {
        var c = +(this.actualMaximumValue) - +(this.actualMinimumValue);
        var d = timeSpanTotalMilliseconds((+a - +(this.actualMinimumValue))) / timeSpanTotalMilliseconds(c);
        var 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);
    };
    TimeXAxis.prototype.getCategorySize = function (a, b, c) {
        if (this.ml != (0)) {
            var d = timeSpanFromTicks(truncate((timeSpanTicks(this.ml) * (a.width / (this.bf != null ? this.bf.mk.width : 1)))));
            var e = timeSpanTicks(d) / timeSpanTicks(this.mj);
            var f = b.width / 4;
            return Math.min(f, b.width / (e + 1));
        }
        return _super.prototype.getCategorySize.call(this, a, b, c);
    };
    TimeXAxis.prototype.mi = function () {
        if (this.kq == null || this.kq.count < 2 || this.kz == null) {
            return (0);
        }
        var a = Math.min(5, this.kq.count);
        var b = this.kq.item(this.kz._inner[0]);
        var c = new Dictionary$2(Number_$type, Number_$type, 0);
        var d = 0;
        var e = (0);
        for (var f = 0; f < a; f++) {
            var g = this.kq.item(this.kz._inner[f]);
            var 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;
    };
    TimeXAxis.prototype.lj = function () {
        _super.prototype.lj.call(this);
        this.mj = this.mi();
    };
    Object.defineProperty(TimeXAxis.prototype, "isVertical", {
        get: function () {
            return this.ce;
        },
        enumerable: true,
        configurable: true
    });
    TimeXAxis.prototype.j$c = function (a, b) {
        return this.dw.apply(this, arguments);
    };
    TimeXAxis.prototype.j$b = function (a, b) {
        return this.dt.apply(this, arguments);
    };
    TimeXAxis.prototype.j$d = function (a, b, c, d, e) {
        this.gf.apply(this, arguments);
    };
    TimeXAxis.prototype.j$e = function (a, b, c, d) {
        this.gg.apply(this, arguments);
    };
    TimeXAxis.prototype.j$f = function (a, b, c, d) {
        this.gh.apply(this, arguments);
    };
    Object.defineProperty(TimeXAxis.prototype, "j$a", {
        get: function () {
            return this.b8;
        },
        enumerable: true,
        configurable: true
    });
    Object.defineProperty(TimeXAxis.prototype, "i$a", {
        get: function () {
            return this.b5;
        },
        enumerable: true,
        configurable: true
    });
    TimeXAxis.ls = null;
    TimeXAxis.$t = markType(TimeXAxis, 'TimeXAxis', TimeAxisBase.$, [ITimeRangeSelectorAxis_$type]);
    return TimeXAxis;
}(TimeAxisBase));
export { TimeXAxis };
/*<BeginStatics Name="Infragistics.Controls.Charts.TimeXAxis" />*/
/*<EndStatics Name="Infragistics.Controls.Charts.TimeXAxis" />*/
