@gravity-ui/date-components 2.10.0 → 2.11.0-beta.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/cjs/components/RangeDateSelection/RangeDateSelection.css +28 -0
- package/dist/cjs/components/RangeDateSelection/RangeDateSelection.d.ts +24 -0
- package/dist/cjs/components/RangeDateSelection/RangeDateSelection.js +49 -0
- package/dist/cjs/components/RangeDateSelection/components/NowLine/NowLine.css +4 -0
- package/dist/cjs/components/RangeDateSelection/components/NowLine/NowLine.d.ts +2 -0
- package/dist/cjs/components/RangeDateSelection/components/NowLine/NowLine.js +43 -0
- package/dist/cjs/components/RangeDateSelection/components/Ruler/Ruler.d.ts +32 -0
- package/dist/cjs/components/RangeDateSelection/components/Ruler/Ruler.js +61 -0
- package/dist/cjs/components/RangeDateSelection/components/RulerViewport/RulerViewport.css +25 -0
- package/dist/cjs/components/RangeDateSelection/components/RulerViewport/RulerViewport.d.ts +13 -0
- package/dist/cjs/components/RangeDateSelection/components/RulerViewport/RulerViewport.js +35 -0
- package/dist/cjs/components/RangeDateSelection/components/SelectionControl/SelectionControl.css +78 -0
- package/dist/cjs/components/RangeDateSelection/components/SelectionControl/SelectionControl.d.ts +8 -0
- package/dist/cjs/components/RangeDateSelection/components/SelectionControl/SelectionControl.js +135 -0
- package/dist/cjs/components/RangeDateSelection/components/Ticks/MiddleTicks.d.ts +3 -0
- package/dist/cjs/components/RangeDateSelection/components/Ticks/MiddleTicks.js +10 -0
- package/dist/cjs/components/RangeDateSelection/components/Ticks/SlitTicks.d.ts +5 -0
- package/dist/cjs/components/RangeDateSelection/components/Ticks/SlitTicks.js +10 -0
- package/dist/cjs/components/RangeDateSelection/components/Ticks/Ticks.css +16 -0
- package/dist/cjs/components/RangeDateSelection/components/Ticks/Ticks.d.ts +18 -0
- package/dist/cjs/components/RangeDateSelection/components/Ticks/Ticks.js +52 -0
- package/dist/cjs/components/RangeDateSelection/components/Ticks/UnavialableTicks.d.ts +15 -0
- package/dist/cjs/components/RangeDateSelection/components/Ticks/UnavialableTicks.js +50 -0
- package/dist/cjs/components/RangeDateSelection/components/Ticks/utils.d.ts +24 -0
- package/dist/cjs/components/RangeDateSelection/components/Ticks/utils.js +166 -0
- package/dist/cjs/components/RangeDateSelection/hooks/useRangeDateSelectionState.d.ts +60 -0
- package/dist/cjs/components/RangeDateSelection/hooks/useRangeDateSelectionState.js +150 -0
- package/dist/cjs/components/RangeDateSelection/i18n/en.json +7 -0
- package/dist/cjs/components/RangeDateSelection/i18n/index.d.ts +1 -0
- package/dist/cjs/components/RangeDateSelection/i18n/index.js +11 -0
- package/dist/cjs/components/RangeDateSelection/i18n/ru.json +7 -0
- package/dist/cjs/components/RangeDateSelection/index.d.ts +3 -0
- package/dist/cjs/components/RangeDateSelection/index.js +18 -0
- package/dist/cjs/components/RangeDateSelection/utils/date.d.ts +2 -0
- package/dist/cjs/components/RangeDateSelection/utils/date.js +10 -0
- package/dist/cjs/components/RangeDateSelection/utils/span.d.ts +23 -0
- package/dist/cjs/components/RangeDateSelection/utils/span.js +27 -0
- package/dist/cjs/components/RelativeRangeDatePicker/components/Presets/i18n/index.d.ts +1 -1
- package/dist/cjs/components/RelativeRangeDatePicker/index.d.ts +1 -0
- package/dist/cjs/components/RelativeRangeDatePicker/index.js +1 -0
- package/dist/cjs/components/index.d.ts +1 -0
- package/dist/cjs/components/index.js +1 -0
- package/dist/cjs/components/mixins.css +0 -0
- package/dist/cjs/components/utils/constants.d.ts +7 -0
- package/dist/cjs/components/utils/constants.js +10 -0
- package/dist/cjs/components/utils/filterDOMProps.d.ts +17 -0
- package/dist/cjs/components/utils/filterDOMProps.js +27 -0
- package/dist/cjs/hooks/useEventHandler.d.ts +1 -0
- package/dist/cjs/hooks/useEventHandler.js +24 -0
- package/dist/cjs/hooks/useMove.d.ts +31 -0
- package/dist/cjs/hooks/useMove.js +173 -0
- package/dist/cjs/hooks/useResizeObserver.d.ts +8 -0
- package/dist/cjs/hooks/useResizeObserver.js +32 -0
- package/dist/esm/components/RangeDateSelection/RangeDateSelection.css +28 -0
- package/dist/esm/components/RangeDateSelection/RangeDateSelection.d.ts +24 -0
- package/dist/esm/components/RangeDateSelection/RangeDateSelection.js +43 -0
- package/dist/esm/components/RangeDateSelection/components/NowLine/NowLine.css +4 -0
- package/dist/esm/components/RangeDateSelection/components/NowLine/NowLine.d.ts +2 -0
- package/dist/esm/components/RangeDateSelection/components/NowLine/NowLine.js +37 -0
- package/dist/esm/components/RangeDateSelection/components/Ruler/Ruler.d.ts +32 -0
- package/dist/esm/components/RangeDateSelection/components/Ruler/Ruler.js +53 -0
- package/dist/esm/components/RangeDateSelection/components/RulerViewport/RulerViewport.css +25 -0
- package/dist/esm/components/RangeDateSelection/components/RulerViewport/RulerViewport.d.ts +13 -0
- package/dist/esm/components/RangeDateSelection/components/RulerViewport/RulerViewport.js +29 -0
- package/dist/esm/components/RangeDateSelection/components/SelectionControl/SelectionControl.css +78 -0
- package/dist/esm/components/RangeDateSelection/components/SelectionControl/SelectionControl.d.ts +8 -0
- package/dist/esm/components/RangeDateSelection/components/SelectionControl/SelectionControl.js +132 -0
- package/dist/esm/components/RangeDateSelection/components/Ticks/MiddleTicks.d.ts +3 -0
- package/dist/esm/components/RangeDateSelection/components/Ticks/MiddleTicks.js +7 -0
- package/dist/esm/components/RangeDateSelection/components/Ticks/SlitTicks.d.ts +5 -0
- package/dist/esm/components/RangeDateSelection/components/Ticks/SlitTicks.js +7 -0
- package/dist/esm/components/RangeDateSelection/components/Ticks/Ticks.css +16 -0
- package/dist/esm/components/RangeDateSelection/components/Ticks/Ticks.d.ts +18 -0
- package/dist/esm/components/RangeDateSelection/components/Ticks/Ticks.js +44 -0
- package/dist/esm/components/RangeDateSelection/components/Ticks/UnavialableTicks.d.ts +15 -0
- package/dist/esm/components/RangeDateSelection/components/Ticks/UnavialableTicks.js +42 -0
- package/dist/esm/components/RangeDateSelection/components/Ticks/utils.d.ts +24 -0
- package/dist/esm/components/RangeDateSelection/components/Ticks/utils.js +158 -0
- package/dist/esm/components/RangeDateSelection/hooks/useRangeDateSelectionState.d.ts +60 -0
- package/dist/esm/components/RangeDateSelection/hooks/useRangeDateSelectionState.js +144 -0
- package/dist/esm/components/RangeDateSelection/i18n/en.json +7 -0
- package/dist/esm/components/RangeDateSelection/i18n/index.d.ts +1 -0
- package/dist/esm/components/RangeDateSelection/i18n/index.js +5 -0
- package/dist/esm/components/RangeDateSelection/i18n/ru.json +7 -0
- package/dist/esm/components/RangeDateSelection/index.d.ts +3 -0
- package/dist/esm/components/RangeDateSelection/index.js +2 -0
- package/dist/esm/components/RangeDateSelection/utils/date.d.ts +2 -0
- package/dist/esm/components/RangeDateSelection/utils/date.js +7 -0
- package/dist/esm/components/RangeDateSelection/utils/span.d.ts +23 -0
- package/dist/esm/components/RangeDateSelection/utils/span.js +23 -0
- package/dist/esm/components/RelativeRangeDatePicker/components/Presets/i18n/index.d.ts +1 -1
- package/dist/esm/components/RelativeRangeDatePicker/index.d.ts +1 -0
- package/dist/esm/components/RelativeRangeDatePicker/index.js +1 -0
- package/dist/esm/components/index.d.ts +1 -0
- package/dist/esm/components/index.js +1 -0
- package/dist/esm/components/mixins.css +0 -0
- package/dist/esm/components/utils/constants.d.ts +7 -0
- package/dist/esm/components/utils/constants.js +7 -0
- package/dist/esm/components/utils/filterDOMProps.d.ts +17 -0
- package/dist/esm/components/utils/filterDOMProps.js +24 -0
- package/dist/esm/hooks/useEventHandler.d.ts +1 -0
- package/dist/esm/hooks/useEventHandler.js +18 -0
- package/dist/esm/hooks/useMove.d.ts +31 -0
- package/dist/esm/hooks/useMove.js +167 -0
- package/dist/esm/hooks/useResizeObserver.d.ts +8 -0
- package/dist/esm/hooks/useResizeObserver.js +26 -0
- package/package.json +1 -1
|
@@ -0,0 +1,52 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
+
};
|
|
5
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
+
exports.makeSlitTicksGeometry = exports.makeMiddleTicksGeometry = void 0;
|
|
7
|
+
exports.Ticks = Ticks;
|
|
8
|
+
const jsx_runtime_1 = require("react/jsx-runtime");
|
|
9
|
+
const react_1 = __importDefault(require("react"));
|
|
10
|
+
const date_utils_1 = require("@gravity-ui/date-utils");
|
|
11
|
+
const cn_1 = require("../../../../utils/cn");
|
|
12
|
+
const span_1 = require("../../utils/span");
|
|
13
|
+
const Ruler_1 = require("../Ruler/Ruler");
|
|
14
|
+
const utils_1 = require("./utils");
|
|
15
|
+
Object.defineProperty(exports, "makeMiddleTicksGeometry", { enumerable: true, get: function () { return utils_1.makeMiddleTicksGeometry; } });
|
|
16
|
+
Object.defineProperty(exports, "makeSlitTicksGeometry", { enumerable: true, get: function () { return utils_1.makeSlitTicksGeometry; } });
|
|
17
|
+
require("./Ticks.css");
|
|
18
|
+
const b = (0, cn_1.block)('timeline-ticks');
|
|
19
|
+
function Ticks({ theme, minTickWidth, maxTickWidth, hasLabels, geometry, className, labelsClassName, formatTime, timeZone, }) {
|
|
20
|
+
const viewport = (0, Ruler_1.useViewportDimensions)();
|
|
21
|
+
const interval = (0, Ruler_1.useViewportInterval)();
|
|
22
|
+
const tickTimes = react_1.default.useMemo(() => (0, utils_1.calculateTickTimes)({
|
|
23
|
+
minTickWidth,
|
|
24
|
+
maxTickWidth,
|
|
25
|
+
viewportStart: interval.start,
|
|
26
|
+
viewportEnd: interval.end,
|
|
27
|
+
viewportWidth: viewport.width,
|
|
28
|
+
timeZone,
|
|
29
|
+
}), [maxTickWidth, minTickWidth, interval, viewport.width, timeZone]);
|
|
30
|
+
const tickCoords = react_1.default.useMemo(() => {
|
|
31
|
+
const timeToXCoeff = (0, span_1.getLerpCoeff)({ start: interval.start.valueOf(), end: interval.end.valueOf() }, { start: 0, end: viewport.width });
|
|
32
|
+
return tickTimes.map((t) => 0 + Math.round((t.valueOf() - interval.start.valueOf()) * timeToXCoeff));
|
|
33
|
+
}, [tickTimes, interval, viewport.width]);
|
|
34
|
+
const ticksGeometry = react_1.default.useMemo(() => {
|
|
35
|
+
return tickCoords.map(geometry).join('');
|
|
36
|
+
}, [geometry, tickCoords]);
|
|
37
|
+
const ticksPath = (0, jsx_runtime_1.jsx)("path", { className: b({ theme }, className), d: ticksGeometry });
|
|
38
|
+
const tickLabels = react_1.default.useMemo(() => {
|
|
39
|
+
if (!hasLabels || tickCoords.length < 2) {
|
|
40
|
+
return null;
|
|
41
|
+
}
|
|
42
|
+
const result = [];
|
|
43
|
+
for (let i = 0; i < tickCoords.length; i++) {
|
|
44
|
+
const x = tickCoords[i];
|
|
45
|
+
const t = tickTimes[i];
|
|
46
|
+
const dt = (0, date_utils_1.dateTime)({ input: t, timeZone });
|
|
47
|
+
result.push((0, jsx_runtime_1.jsx)("text", { className: b('label', labelsClassName), dominantBaseline: "middle", x: x, y: "50%", filter: "url(#g-date-tt-ticklabelbg)", children: formatTime ? formatTime(dt) : (0, utils_1.formatTick)(dt) }, i));
|
|
48
|
+
}
|
|
49
|
+
return result;
|
|
50
|
+
}, [hasLabels, tickCoords, tickTimes, timeZone, labelsClassName, formatTime]);
|
|
51
|
+
return ((0, jsx_runtime_1.jsxs)(react_1.default.Fragment, { children: [ticksPath, tickLabels] }));
|
|
52
|
+
}
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
import type { DateTime } from '@gravity-ui/date-utils';
|
|
2
|
+
import type { Geometry } from './utils';
|
|
3
|
+
import { makeMiddleTicksGeometry, makeSlitTicksGeometry } from './utils';
|
|
4
|
+
import './Ticks.css';
|
|
5
|
+
interface TicksProps {
|
|
6
|
+
theme: 'normal' | 'dim';
|
|
7
|
+
tickWidth: number;
|
|
8
|
+
minValue?: DateTime;
|
|
9
|
+
maxValue?: DateTime;
|
|
10
|
+
geometry: Geometry;
|
|
11
|
+
className?: string;
|
|
12
|
+
}
|
|
13
|
+
export { makeMiddleTicksGeometry, makeSlitTicksGeometry };
|
|
14
|
+
export type { Geometry };
|
|
15
|
+
export declare function UnavailableTicks({ theme, geometry, tickWidth, minValue, maxValue, className, }: TicksProps): import("react/jsx-runtime").JSX.Element;
|
|
@@ -0,0 +1,50 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
+
};
|
|
5
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
+
exports.makeSlitTicksGeometry = exports.makeMiddleTicksGeometry = void 0;
|
|
7
|
+
exports.UnavailableTicks = UnavailableTicks;
|
|
8
|
+
const jsx_runtime_1 = require("react/jsx-runtime");
|
|
9
|
+
const react_1 = __importDefault(require("react"));
|
|
10
|
+
const cn_1 = require("../../../../utils/cn");
|
|
11
|
+
const Ruler_1 = require("../Ruler/Ruler");
|
|
12
|
+
const utils_1 = require("./utils");
|
|
13
|
+
Object.defineProperty(exports, "makeMiddleTicksGeometry", { enumerable: true, get: function () { return utils_1.makeMiddleTicksGeometry; } });
|
|
14
|
+
Object.defineProperty(exports, "makeSlitTicksGeometry", { enumerable: true, get: function () { return utils_1.makeSlitTicksGeometry; } });
|
|
15
|
+
require("./Ticks.css");
|
|
16
|
+
const b = (0, cn_1.block)('timeline-ticks');
|
|
17
|
+
function UnavailableTicks({ theme, geometry, tickWidth, minValue, maxValue, className, }) {
|
|
18
|
+
const viewport = (0, Ruler_1.useViewportDimensions)();
|
|
19
|
+
const interval = (0, Ruler_1.useViewportInterval)();
|
|
20
|
+
const endPoint = (0, utils_1.calculatePosition)(minValue, interval, viewport.width);
|
|
21
|
+
const startPoint = (0, utils_1.calculatePosition)(maxValue, interval, viewport.width);
|
|
22
|
+
const tickCoords = [];
|
|
23
|
+
if (!isNaN(endPoint) && endPoint > 0) {
|
|
24
|
+
let x = endPoint - tickWidth;
|
|
25
|
+
if (endPoint > viewport.width) {
|
|
26
|
+
x = endPoint - tickWidth * Math.floor((endPoint - viewport.width) / tickWidth);
|
|
27
|
+
}
|
|
28
|
+
tickCoords.push(x);
|
|
29
|
+
while (x > 0) {
|
|
30
|
+
x -= tickWidth;
|
|
31
|
+
tickCoords.push(x);
|
|
32
|
+
}
|
|
33
|
+
}
|
|
34
|
+
if (!isNaN(startPoint) && startPoint < viewport.width) {
|
|
35
|
+
let x = startPoint;
|
|
36
|
+
if (startPoint < 0) {
|
|
37
|
+
x = startPoint + tickWidth * Math.floor((0 - startPoint) / tickWidth) - tickWidth;
|
|
38
|
+
}
|
|
39
|
+
tickCoords.push(x);
|
|
40
|
+
while (x < viewport.width) {
|
|
41
|
+
x += tickWidth;
|
|
42
|
+
tickCoords.push(x);
|
|
43
|
+
}
|
|
44
|
+
}
|
|
45
|
+
const ticksGeometry = react_1.default.useMemo(() => {
|
|
46
|
+
return tickCoords.map(geometry).join('');
|
|
47
|
+
}, [geometry, tickCoords]);
|
|
48
|
+
const ticksPath = (0, jsx_runtime_1.jsx)("path", { className: b({ theme }, className), d: ticksGeometry });
|
|
49
|
+
return (0, jsx_runtime_1.jsx)(react_1.default.Fragment, { children: ticksPath });
|
|
50
|
+
}
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
import type { DateTime } from '@gravity-ui/date-utils/build/typings';
|
|
2
|
+
import type { RangeValue } from '../../../types';
|
|
3
|
+
interface CalculateTicksOptions {
|
|
4
|
+
viewportStart: DateTime;
|
|
5
|
+
viewportEnd: DateTime;
|
|
6
|
+
minTickWidth: number;
|
|
7
|
+
maxTickWidth: number;
|
|
8
|
+
viewportWidth: number;
|
|
9
|
+
timeZone?: string;
|
|
10
|
+
}
|
|
11
|
+
export declare function calculateTickTimes({ viewportStart, viewportEnd, minTickWidth, maxTickWidth, viewportWidth, timeZone, }: CalculateTicksOptions): number[];
|
|
12
|
+
export declare function formatTick(t: DateTime): string;
|
|
13
|
+
export interface Geometry {
|
|
14
|
+
(x: number): string;
|
|
15
|
+
}
|
|
16
|
+
interface MakeTicksOptions {
|
|
17
|
+
tickHeight: number;
|
|
18
|
+
viewportHeight: number;
|
|
19
|
+
}
|
|
20
|
+
export declare function makeMiddleTicksGeometry({ tickHeight, viewportHeight }: MakeTicksOptions): Geometry;
|
|
21
|
+
export declare function makeSlitTicksGeometry({ tickHeight, viewportHeight }: MakeTicksOptions): Geometry;
|
|
22
|
+
export declare function makeUnavailableTicksGeometry({ tickHeight, viewportHeight, }: MakeTicksOptions): Geometry;
|
|
23
|
+
export declare function calculatePosition(value: DateTime | undefined, interval: RangeValue<DateTime>, width: number): number;
|
|
24
|
+
export {};
|
|
@@ -0,0 +1,166 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.calculateTickTimes = calculateTickTimes;
|
|
4
|
+
exports.formatTick = formatTick;
|
|
5
|
+
exports.makeMiddleTicksGeometry = makeMiddleTicksGeometry;
|
|
6
|
+
exports.makeSlitTicksGeometry = makeSlitTicksGeometry;
|
|
7
|
+
exports.makeUnavailableTicksGeometry = makeUnavailableTicksGeometry;
|
|
8
|
+
exports.calculatePosition = calculatePosition;
|
|
9
|
+
const date_utils_1 = require("@gravity-ui/date-utils");
|
|
10
|
+
const constants_1 = require("../../../utils/constants");
|
|
11
|
+
const span_1 = require("../../utils/span");
|
|
12
|
+
const MAX_TICKS = 100000;
|
|
13
|
+
function makeTickSizes(periodSize, periodName, ...multipliers) {
|
|
14
|
+
return multipliers.map((m) => ({
|
|
15
|
+
duration: m * periodSize,
|
|
16
|
+
period: periodName,
|
|
17
|
+
multiplier: m,
|
|
18
|
+
}));
|
|
19
|
+
}
|
|
20
|
+
const tickSizes = [
|
|
21
|
+
...makeTickSizes(constants_1.SECOND, 'second', 1, 2, 5, 10, 15, 30),
|
|
22
|
+
...makeTickSizes(constants_1.MINUTE, 'minute', 1, 2, 5, 10, 20, 30),
|
|
23
|
+
...makeTickSizes(constants_1.HOUR, 'hour', 1, 2, 3, 6, 12),
|
|
24
|
+
...makeTickSizes(constants_1.DAY, 'day', 1, 2, 3),
|
|
25
|
+
...makeTickSizes(constants_1.WEEK, 'week', 1, 2),
|
|
26
|
+
...makeTickSizes(constants_1.MONTH, 'month', 1, 2, 3, 6),
|
|
27
|
+
...makeTickSizes(constants_1.YEAR, 'year', 1, 2, 5, 10, 15, 20, 30),
|
|
28
|
+
];
|
|
29
|
+
const TickFormat = {
|
|
30
|
+
SECONDS: 'HH:mm:ss',
|
|
31
|
+
MINUTES: 'HH:mm',
|
|
32
|
+
DATE: 'DD.MM.YY',
|
|
33
|
+
MONTH: 'MM-YYYY',
|
|
34
|
+
YEAR: 'YYYY',
|
|
35
|
+
};
|
|
36
|
+
function findTickSize({ minWidth, maxWidth, timelineWidth, timelineDuration }) {
|
|
37
|
+
const minDuration = (minWidth / timelineWidth) * timelineDuration;
|
|
38
|
+
const maxDuration = (maxWidth / timelineWidth) * timelineDuration;
|
|
39
|
+
const suitableSizes = [];
|
|
40
|
+
for (const size of tickSizes) {
|
|
41
|
+
if (minDuration <= size.duration) {
|
|
42
|
+
if (size.duration <= maxDuration) {
|
|
43
|
+
suitableSizes.push(size);
|
|
44
|
+
}
|
|
45
|
+
else if (!suitableSizes.length) {
|
|
46
|
+
return size;
|
|
47
|
+
}
|
|
48
|
+
}
|
|
49
|
+
}
|
|
50
|
+
if (!suitableSizes.length) {
|
|
51
|
+
return tickSizes[tickSizes.length - 1];
|
|
52
|
+
}
|
|
53
|
+
return suitableSizes[Math.floor(suitableSizes.length / 2)];
|
|
54
|
+
}
|
|
55
|
+
function calculateTickTimes({ viewportStart, viewportEnd, minTickWidth, maxTickWidth, viewportWidth, timeZone, }) {
|
|
56
|
+
const tickSize = findTickSize({
|
|
57
|
+
minWidth: minTickWidth,
|
|
58
|
+
maxWidth: maxTickWidth,
|
|
59
|
+
timelineDuration: viewportEnd.valueOf() - viewportStart.valueOf(),
|
|
60
|
+
timelineWidth: viewportWidth,
|
|
61
|
+
});
|
|
62
|
+
let cursor;
|
|
63
|
+
const stableDate = (0, date_utils_1.dateTimeUtc)({ input: '1977-01-01' }).timeZone(timeZone || date_utils_1.settings.getDefaultTimeZone(), true);
|
|
64
|
+
const diff = stableDate.diff(viewportStart, tickSize.period);
|
|
65
|
+
const divider = tickSize.multiplier;
|
|
66
|
+
const multiplier = Math.floor(diff / divider);
|
|
67
|
+
cursor = stableDate.subtract(multiplier * divider, tickSize.period);
|
|
68
|
+
if (viewportStart.isBefore(cursor)) {
|
|
69
|
+
cursor = cursor.subtract(divider, tickSize.period);
|
|
70
|
+
}
|
|
71
|
+
const timeDiff = stableDate.utcOffset() - cursor.utcOffset();
|
|
72
|
+
if (timeDiff !== 0 &&
|
|
73
|
+
(tickSize.period === 'hour' || tickSize.period === 'minute' || tickSize.period === 'second')) {
|
|
74
|
+
cursor = cursor.add(timeDiff, 'minutes');
|
|
75
|
+
}
|
|
76
|
+
const ticks = [];
|
|
77
|
+
let i = 0;
|
|
78
|
+
let maxTickValue = cursor.valueOf();
|
|
79
|
+
while (cursor.valueOf() < viewportEnd.valueOf()) {
|
|
80
|
+
if (i >= MAX_TICKS) {
|
|
81
|
+
throw new Error('TimeLine: too much ticks');
|
|
82
|
+
}
|
|
83
|
+
i++;
|
|
84
|
+
ticks.push(cursor.valueOf());
|
|
85
|
+
let next = cursor.add(tickSize.multiplier, tickSize.period);
|
|
86
|
+
// Get time shift when season timeZone changed
|
|
87
|
+
const timeDiff = cursor.utcOffset() - next.utcOffset();
|
|
88
|
+
if (timeDiff !== 0 &&
|
|
89
|
+
(tickSize.period === 'hour' ||
|
|
90
|
+
tickSize.period === 'minute' ||
|
|
91
|
+
tickSize.period === 'second')) {
|
|
92
|
+
// Tick should be on same local time distance. Then labels will have correct format (such as date/week/month)
|
|
93
|
+
// For example, Amsterdam timezone:
|
|
94
|
+
//
|
|
95
|
+
// 2023-10-28T22:00Z -> Summer time is 2023-10-29T00:00, displays as 29.10.2023
|
|
96
|
+
// 2023-10-29T22:00Z -> Winter time is 2023-10-29T23:00, displays as 23:00
|
|
97
|
+
//
|
|
98
|
+
// Add 1h:
|
|
99
|
+
// 2023-10-29T23:00Z -> Winter time is 2023-10-30T00:00, displays as 30.10.2023
|
|
100
|
+
//
|
|
101
|
+
next = next.add(timeDiff, 'minutes');
|
|
102
|
+
let k = 1;
|
|
103
|
+
while (next.valueOf() <= maxTickValue) {
|
|
104
|
+
// Example of case, Amsterdam timezone:
|
|
105
|
+
// 2023-03-26T00:00Z -> Winter time is 2023-03-26T01:00, displays as 01:00
|
|
106
|
+
// 2023-03-26T01:00Z -> Summer time is 2023-03-26T03:00, displays as 03:00
|
|
107
|
+
// We shift time on -1h... And again:
|
|
108
|
+
// 2023-03-26T00:00Z -> Winter time is 2023-03-26T01:00, displays as 01:00
|
|
109
|
+
// Infinite loop
|
|
110
|
+
//
|
|
111
|
+
// Therefore we need to skip period in the past
|
|
112
|
+
next = next
|
|
113
|
+
.add(tickSize.multiplier * k++, tickSize.period)
|
|
114
|
+
.add(timeDiff, 'minutes');
|
|
115
|
+
}
|
|
116
|
+
}
|
|
117
|
+
cursor = next;
|
|
118
|
+
maxTickValue = Math.max(maxTickValue, cursor.valueOf());
|
|
119
|
+
}
|
|
120
|
+
return ticks;
|
|
121
|
+
}
|
|
122
|
+
function formatTick(t) {
|
|
123
|
+
let format;
|
|
124
|
+
if (t.valueOf() % constants_1.MINUTE === 0) {
|
|
125
|
+
if (t.hour() === 0 && t.minute() === 0) {
|
|
126
|
+
if (t.date() === 1) {
|
|
127
|
+
if (t.month() === 0) {
|
|
128
|
+
format = TickFormat.YEAR;
|
|
129
|
+
}
|
|
130
|
+
else {
|
|
131
|
+
format = TickFormat.MONTH;
|
|
132
|
+
}
|
|
133
|
+
}
|
|
134
|
+
else {
|
|
135
|
+
format = TickFormat.DATE;
|
|
136
|
+
}
|
|
137
|
+
}
|
|
138
|
+
else {
|
|
139
|
+
format = TickFormat.MINUTES;
|
|
140
|
+
}
|
|
141
|
+
}
|
|
142
|
+
else {
|
|
143
|
+
format = TickFormat.SECONDS;
|
|
144
|
+
}
|
|
145
|
+
return t.format(format);
|
|
146
|
+
}
|
|
147
|
+
function makeMiddleTicksGeometry({ tickHeight, viewportHeight }) {
|
|
148
|
+
const tickYStart = (viewportHeight - tickHeight) / 2;
|
|
149
|
+
return (x) => `M${x},${tickYStart}l0,${tickHeight}`;
|
|
150
|
+
}
|
|
151
|
+
function makeSlitTicksGeometry({ tickHeight, viewportHeight }) {
|
|
152
|
+
const slitHeight = viewportHeight - 2 * tickHeight;
|
|
153
|
+
return (x) => `M${x},0l0,${tickHeight}m0,${slitHeight}l0,${tickHeight}`;
|
|
154
|
+
}
|
|
155
|
+
function makeUnavailableTicksGeometry({ tickHeight, viewportHeight, }) {
|
|
156
|
+
const w = tickHeight;
|
|
157
|
+
const h = viewportHeight;
|
|
158
|
+
return (x) => `M${x},0l${h},${h}l${w},0l${-h},${-h}l${-w},0`;
|
|
159
|
+
}
|
|
160
|
+
function calculatePosition(value, interval, width) {
|
|
161
|
+
if (!value) {
|
|
162
|
+
return NaN;
|
|
163
|
+
}
|
|
164
|
+
const timeToXCoeff = (0, span_1.getLerpCoeff)({ start: interval.start.valueOf(), end: interval.end.valueOf() }, { start: 0, end: width });
|
|
165
|
+
return Math.round((value.valueOf() - interval.start.valueOf()) * timeToXCoeff);
|
|
166
|
+
}
|
|
@@ -0,0 +1,60 @@
|
|
|
1
|
+
import type { DateTime } from '@gravity-ui/date-utils';
|
|
2
|
+
import type { RangeValue, ValueBase } from '../../types';
|
|
3
|
+
export interface RangeDateSelectionState {
|
|
4
|
+
viewportInterval: RangeValue<DateTime>;
|
|
5
|
+
value: RangeValue<DateTime>;
|
|
6
|
+
setValue: (value: RangeValue<DateTime>) => void;
|
|
7
|
+
timeZone: string;
|
|
8
|
+
setDraggingValue: (value: RangeValue<DateTime> | null) => void;
|
|
9
|
+
canResize: boolean;
|
|
10
|
+
startDragging: () => void;
|
|
11
|
+
move: (delta: number, options?: {
|
|
12
|
+
visualMinDuration?: number;
|
|
13
|
+
}) => void;
|
|
14
|
+
scale: (scale: number, options?: {
|
|
15
|
+
visualMinDuration?: number;
|
|
16
|
+
fixedPoint?: number;
|
|
17
|
+
}) => void;
|
|
18
|
+
moveStart: (delta: number, options?: {
|
|
19
|
+
visualMinDuration?: number;
|
|
20
|
+
}) => void;
|
|
21
|
+
moveEnd: (delta: number, options?: {
|
|
22
|
+
visualMinDuration?: number;
|
|
23
|
+
}) => void;
|
|
24
|
+
endDragging: () => void;
|
|
25
|
+
align: number;
|
|
26
|
+
isDragging: boolean;
|
|
27
|
+
}
|
|
28
|
+
export interface RangeDateSelectionOptions extends ValueBase<RangeValue<DateTime>> {
|
|
29
|
+
/** The minimum allowed date that a user may select. */
|
|
30
|
+
minValue?: DateTime;
|
|
31
|
+
/** The maximum allowed date that a user may select. */
|
|
32
|
+
maxValue?: DateTime;
|
|
33
|
+
/** Minimum duration of the selection in milliseconds. Defaults to 1 second. */
|
|
34
|
+
minDuration?: number;
|
|
35
|
+
/** Maximum duration of the selection in milliseconds. Defaults to 15 years. */
|
|
36
|
+
maxDuration?: number;
|
|
37
|
+
/** Alignment of the selection in milliseconds. Defaults to 1 second. */
|
|
38
|
+
align?: number;
|
|
39
|
+
/** A placeholder date that controls the default values of each segment when the user first interacts with them. Defaults to today's date at midnight. */
|
|
40
|
+
placeholderValue?: DateTime;
|
|
41
|
+
/**
|
|
42
|
+
* Which timezone use to show values. Example: 'default', 'system', 'Europe/Amsterdam'.
|
|
43
|
+
* @default The timezone of the `value` or `defaultValue` or `placeholderValue`, 'default' otherwise.
|
|
44
|
+
*/
|
|
45
|
+
timeZone?: string;
|
|
46
|
+
/**
|
|
47
|
+
* The number of selection intervals that fit into the underlying ruler.
|
|
48
|
+
*
|
|
49
|
+
* @default 4
|
|
50
|
+
*/
|
|
51
|
+
numberOfIntervals?: number;
|
|
52
|
+
/**
|
|
53
|
+
* Place of the selection on the underlying ruler.
|
|
54
|
+
* Value must be between 0 and 1, where 0 is the start of the ruler and 1 is the end.
|
|
55
|
+
*
|
|
56
|
+
* @default 0.5 - center of the ruler
|
|
57
|
+
*/
|
|
58
|
+
placeOnRuler?: number;
|
|
59
|
+
}
|
|
60
|
+
export declare function useRangeDateSelectionState(props: RangeDateSelectionOptions): RangeDateSelectionState;
|
|
@@ -0,0 +1,150 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
+
};
|
|
5
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
+
exports.useRangeDateSelectionState = useRangeDateSelectionState;
|
|
7
|
+
const react_1 = __importDefault(require("react"));
|
|
8
|
+
const uikit_1 = require("@gravity-ui/uikit");
|
|
9
|
+
const constants_1 = require("../../utils/constants");
|
|
10
|
+
const dates_1 = require("../../utils/dates");
|
|
11
|
+
const useDefaultTimeZone_1 = require("../../utils/useDefaultTimeZone");
|
|
12
|
+
const date_1 = require("../utils/date");
|
|
13
|
+
function getViewportIntervalFromDates(start, end, numberOfIntervals = 4, placeInViewport = 0.5) {
|
|
14
|
+
const diff = end.diff(start);
|
|
15
|
+
return {
|
|
16
|
+
start: start.subtract(diff * (numberOfIntervals - 1) * placeInViewport),
|
|
17
|
+
end: end.add(diff * (numberOfIntervals - 1) * (1 - placeInViewport)),
|
|
18
|
+
};
|
|
19
|
+
}
|
|
20
|
+
function useRangeDateSelectionState(props) {
|
|
21
|
+
var _a, _b, _c, _d, _e, _f, _g, _h;
|
|
22
|
+
const inputTimeZone = (0, useDefaultTimeZone_1.useDefaultTimeZone)(((_a = props.value) === null || _a === void 0 ? void 0 : _a.start) || ((_b = props.defaultValue) === null || _b === void 0 ? void 0 : _b.start) || props.placeholderValue);
|
|
23
|
+
const timeZone = props.timeZone || inputTimeZone;
|
|
24
|
+
const placeholderValue = (0, dates_1.createPlaceholderValue)({
|
|
25
|
+
placeholderValue: props.placeholderValue,
|
|
26
|
+
timeZone,
|
|
27
|
+
});
|
|
28
|
+
const [isDragging, setIsDragging] = react_1.default.useState(false);
|
|
29
|
+
const [currentValue, setCurrentValue] = react_1.default.useState(null);
|
|
30
|
+
const [value, setValue] = (0, uikit_1.useControlledState)(props.value, (_c = props.defaultValue) !== null && _c !== void 0 ? _c : {
|
|
31
|
+
start: placeholderValue.startOf('day').timeZone(inputTimeZone),
|
|
32
|
+
end: placeholderValue.endOf('day').timeZone(inputTimeZone),
|
|
33
|
+
}, props.onUpdate);
|
|
34
|
+
const setInterval = (newValue) => {
|
|
35
|
+
setCurrentValue(null);
|
|
36
|
+
setValue({
|
|
37
|
+
start: (0, date_1.alignDateTime)(newValue.start, props.align).timeZone(inputTimeZone),
|
|
38
|
+
end: (0, date_1.alignDateTime)(newValue.end, props.align).timeZone(inputTimeZone),
|
|
39
|
+
});
|
|
40
|
+
};
|
|
41
|
+
const displayValue = {
|
|
42
|
+
start: value.start.timeZone(timeZone),
|
|
43
|
+
end: value.end.timeZone(timeZone),
|
|
44
|
+
};
|
|
45
|
+
const interval = isDragging ? displayValue : currentValue !== null && currentValue !== void 0 ? currentValue : displayValue;
|
|
46
|
+
const viewportInterval = getViewportIntervalFromDates(interval.start, interval.end, props.numberOfIntervals, props.placeOnRuler);
|
|
47
|
+
const minValue = ((_d = props.minValue) === null || _d === void 0 ? void 0 : _d.isAfter(viewportInterval.start))
|
|
48
|
+
? props.minValue
|
|
49
|
+
: viewportInterval.start;
|
|
50
|
+
const maxValue = ((_e = props.maxValue) === null || _e === void 0 ? void 0 : _e.isBefore(viewportInterval.end))
|
|
51
|
+
? props.maxValue
|
|
52
|
+
: viewportInterval.end;
|
|
53
|
+
const align = (_f = props.align) !== null && _f !== void 0 ? _f : constants_1.SECOND;
|
|
54
|
+
const minDuration = Math.max((_g = props.minDuration) !== null && _g !== void 0 ? _g : constants_1.SECOND, align);
|
|
55
|
+
const maxDuration = Math.max(Math.min((_h = props.maxDuration) !== null && _h !== void 0 ? _h : 15 * constants_1.YEAR, maxValue.diff(minValue)), minDuration);
|
|
56
|
+
const canResize = minDuration < maxDuration;
|
|
57
|
+
const draggingState = react_1.default.useRef(null);
|
|
58
|
+
const setDraggingValue = (v) => {
|
|
59
|
+
draggingState.current = v;
|
|
60
|
+
setCurrentValue(v);
|
|
61
|
+
};
|
|
62
|
+
const startDragging = () => {
|
|
63
|
+
setIsDragging(true);
|
|
64
|
+
setDraggingValue(displayValue);
|
|
65
|
+
};
|
|
66
|
+
const endDragging = () => {
|
|
67
|
+
setIsDragging(false);
|
|
68
|
+
if (draggingState.current) {
|
|
69
|
+
setInterval(draggingState.current);
|
|
70
|
+
}
|
|
71
|
+
};
|
|
72
|
+
const moveInterval = (delta) => {
|
|
73
|
+
if (!draggingState.current) {
|
|
74
|
+
return;
|
|
75
|
+
}
|
|
76
|
+
const { start, end } = draggingState.current;
|
|
77
|
+
let newStart = start.add(delta, 'millisecond');
|
|
78
|
+
let newEnd = end.add(delta, 'millisecond');
|
|
79
|
+
const diff = newEnd.diff(newStart);
|
|
80
|
+
if (newStart.valueOf() < minValue.valueOf()) {
|
|
81
|
+
newStart = minValue;
|
|
82
|
+
newEnd = (0, dates_1.constrainValue)(newStart.add(diff, 'millisecond'), newStart, maxValue);
|
|
83
|
+
}
|
|
84
|
+
else if (newEnd.valueOf() > maxValue.valueOf()) {
|
|
85
|
+
newEnd = maxValue;
|
|
86
|
+
newStart = (0, dates_1.constrainValue)(newEnd.subtract(diff, 'millisecond'), minValue, newEnd);
|
|
87
|
+
}
|
|
88
|
+
setDraggingValue({ start: newStart, end: newEnd });
|
|
89
|
+
};
|
|
90
|
+
const moveStart = (delta, { visualMinDuration = minDuration } = {}) => {
|
|
91
|
+
if (!draggingState.current) {
|
|
92
|
+
return;
|
|
93
|
+
}
|
|
94
|
+
const { start, end } = draggingState.current;
|
|
95
|
+
let newStart = start.add(delta, 'millisecond');
|
|
96
|
+
const deltaMin = Math.max(visualMinDuration, minDuration);
|
|
97
|
+
const deltaMax = Math.min(maxDuration, end.diff(minValue));
|
|
98
|
+
newStart = (0, dates_1.constrainValue)(newStart, end.subtract(deltaMax, 'millisecond'), end.subtract(deltaMin, 'millisecond'));
|
|
99
|
+
setDraggingValue({ start: newStart, end });
|
|
100
|
+
};
|
|
101
|
+
const moveEnd = (delta, { visualMinDuration = minDuration } = {}) => {
|
|
102
|
+
if (!draggingState.current) {
|
|
103
|
+
return;
|
|
104
|
+
}
|
|
105
|
+
const { start, end } = draggingState.current;
|
|
106
|
+
let newEnd = end.add(delta, 'millisecond');
|
|
107
|
+
const deltaMin = Math.max(visualMinDuration, minDuration);
|
|
108
|
+
const deltaMax = Math.min(maxDuration, maxValue.diff(start));
|
|
109
|
+
newEnd = (0, dates_1.constrainValue)(end.add(delta, 'millisecond'), start.add(deltaMin, 'millisecond'), start.add(deltaMax, 'millisecond'));
|
|
110
|
+
setDraggingValue({ start, end: newEnd });
|
|
111
|
+
};
|
|
112
|
+
const zoomInterval = (scale, { visualMinDuration = minDuration, fixedPoint = 0.5, } = {}) => {
|
|
113
|
+
if (!draggingState.current) {
|
|
114
|
+
return;
|
|
115
|
+
}
|
|
116
|
+
const { start, end } = draggingState.current;
|
|
117
|
+
const len = end.diff(start);
|
|
118
|
+
let newDiff = len * scale;
|
|
119
|
+
newDiff = align * Math.round(newDiff / align);
|
|
120
|
+
newDiff = Math.min(Math.max(newDiff, Math.max(visualMinDuration, minDuration)), maxDuration);
|
|
121
|
+
let newStart = start.subtract(fixedPoint * (newDiff - len));
|
|
122
|
+
let newEnd = newStart.add(newDiff, 'millisecond');
|
|
123
|
+
const diff = newEnd.diff(newStart);
|
|
124
|
+
if (newStart.valueOf() < minValue.valueOf()) {
|
|
125
|
+
newStart = minValue;
|
|
126
|
+
newEnd = (0, dates_1.constrainValue)(newStart.add(diff, 'millisecond'), newStart, maxValue);
|
|
127
|
+
}
|
|
128
|
+
else if (newEnd.valueOf() > maxValue.valueOf()) {
|
|
129
|
+
newEnd = maxValue;
|
|
130
|
+
newStart = (0, dates_1.constrainValue)(newEnd.subtract(diff, 'millisecond'), minValue, newEnd);
|
|
131
|
+
}
|
|
132
|
+
setDraggingValue({ start: newStart, end: newEnd });
|
|
133
|
+
};
|
|
134
|
+
return {
|
|
135
|
+
viewportInterval,
|
|
136
|
+
value: currentValue !== null && currentValue !== void 0 ? currentValue : displayValue,
|
|
137
|
+
setValue: setInterval,
|
|
138
|
+
setDraggingValue,
|
|
139
|
+
canResize,
|
|
140
|
+
startDragging,
|
|
141
|
+
move: moveInterval,
|
|
142
|
+
scale: zoomInterval,
|
|
143
|
+
moveStart,
|
|
144
|
+
moveEnd,
|
|
145
|
+
endDragging,
|
|
146
|
+
timeZone,
|
|
147
|
+
align,
|
|
148
|
+
isDragging,
|
|
149
|
+
};
|
|
150
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export declare const i18n: (key: "Range" | "Start of range" | "End of range" | "Increase range" | "Decrease range", params?: import("@gravity-ui/i18n").Params | undefined) => string;
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
+
};
|
|
5
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
+
exports.i18n = void 0;
|
|
7
|
+
const i18n_1 = require("@gravity-ui/uikit/i18n");
|
|
8
|
+
const cn_1 = require("../../../utils/cn");
|
|
9
|
+
const en_json_1 = __importDefault(require("./en.json"));
|
|
10
|
+
const ru_json_1 = __importDefault(require("./ru.json"));
|
|
11
|
+
exports.i18n = (0, i18n_1.addComponentKeysets)({ en: en_json_1.default, ru: ru_json_1.default }, `${cn_1.NAMESPACE}range-date-selection`);
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
+
if (k2 === undefined) k2 = k;
|
|
4
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
+
}
|
|
8
|
+
Object.defineProperty(o, k2, desc);
|
|
9
|
+
}) : (function(o, m, k, k2) {
|
|
10
|
+
if (k2 === undefined) k2 = k;
|
|
11
|
+
o[k2] = m[k];
|
|
12
|
+
}));
|
|
13
|
+
var __exportStar = (this && this.__exportStar) || function(m, exports) {
|
|
14
|
+
for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
|
|
15
|
+
};
|
|
16
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
17
|
+
__exportStar(require("./RangeDateSelection"), exports);
|
|
18
|
+
__exportStar(require("./hooks/useRangeDateSelectionState"), exports);
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.alignDateTime = alignDateTime;
|
|
4
|
+
const date_utils_1 = require("@gravity-ui/date-utils");
|
|
5
|
+
const constants_1 = require("../../utils/constants");
|
|
6
|
+
function alignDateTime(date, align = constants_1.SECOND) {
|
|
7
|
+
return (0, date_utils_1.dateTimeUtc)({
|
|
8
|
+
input: Math.round(date.utc(true).valueOf() / align) * align,
|
|
9
|
+
}).timeZone(date.timeZone(), true);
|
|
10
|
+
}
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
export interface Span {
|
|
2
|
+
start: number;
|
|
3
|
+
end: number;
|
|
4
|
+
}
|
|
5
|
+
/**
|
|
6
|
+
* Implements linear interpolation (lerp).
|
|
7
|
+
*
|
|
8
|
+
* Calculates such a linear mapping `R -> R` that `from.start` will be mapped
|
|
9
|
+
* into `to.start`, and `from.end` will be mapped to `to.end`. Then applies
|
|
10
|
+
* this mapping to `value`.
|
|
11
|
+
* @param from Interpolation domain
|
|
12
|
+
* @param to Interpolation target
|
|
13
|
+
* @param value Value from domain
|
|
14
|
+
* @returns Value from target
|
|
15
|
+
*/
|
|
16
|
+
export declare function lerp(from: Span, to: Span, value: number): number;
|
|
17
|
+
/**
|
|
18
|
+
* Calculates a lerp scale coefficient
|
|
19
|
+
* @param from Interpolation domain
|
|
20
|
+
* @param to Interpolation target
|
|
21
|
+
* @returns Scale coefficient
|
|
22
|
+
*/
|
|
23
|
+
export declare function getLerpCoeff(from: Span, to: Span): number;
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.lerp = lerp;
|
|
4
|
+
exports.getLerpCoeff = getLerpCoeff;
|
|
5
|
+
/**
|
|
6
|
+
* Implements linear interpolation (lerp).
|
|
7
|
+
*
|
|
8
|
+
* Calculates such a linear mapping `R -> R` that `from.start` will be mapped
|
|
9
|
+
* into `to.start`, and `from.end` will be mapped to `to.end`. Then applies
|
|
10
|
+
* this mapping to `value`.
|
|
11
|
+
* @param from Interpolation domain
|
|
12
|
+
* @param to Interpolation target
|
|
13
|
+
* @param value Value from domain
|
|
14
|
+
* @returns Value from target
|
|
15
|
+
*/
|
|
16
|
+
function lerp(from, to, value) {
|
|
17
|
+
return to.start + ((value - from.start) * (to.end - to.start)) / (from.end - from.start);
|
|
18
|
+
}
|
|
19
|
+
/**
|
|
20
|
+
* Calculates a lerp scale coefficient
|
|
21
|
+
* @param from Interpolation domain
|
|
22
|
+
* @param to Interpolation target
|
|
23
|
+
* @returns Scale coefficient
|
|
24
|
+
*/
|
|
25
|
+
function getLerpCoeff(from, to) {
|
|
26
|
+
return (to.end - to.start) / (from.end - from.start);
|
|
27
|
+
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
export declare const i18n: (key: "Last 5 minutes" | "Last 15 minutes" | "Last 30 minutes" | "Last hour" | "Last 3 hours" | "Last 6 hours" | "Last 12 hours" | "Last day" | "Last 3 days" | "Last week" | "Last month" | "Last 3 months" | "Last 6 months" | "Last year" | "Last 3 years" | "Today" | "Yesterday" | "Day before yesterday" | "This week" | "This month" | "This year" | "From start of day" | "From start of week" | "From start of month" | "From start of year" | "Previous month" | "Last second" | "Last minute" | "Main" | "Other" | "
|
|
1
|
+
export declare const i18n: (key: "Range" | "Last 5 minutes" | "Last 15 minutes" | "Last 30 minutes" | "Last hour" | "Last 3 hours" | "Last 6 hours" | "Last 12 hours" | "Last day" | "Last 3 days" | "Last week" | "Last month" | "Last 3 months" | "Last 6 months" | "Last year" | "Last 3 years" | "Today" | "Yesterday" | "Day before yesterday" | "This week" | "This month" | "This year" | "From start of day" | "From start of week" | "From start of month" | "From start of year" | "Previous month" | "Last second" | "Last minute" | "Main" | "Other" | "From" | "To" | "Last {count} second" | "Last {count} minute" | "Last {count} hour" | "Last {count} day" | "Last {count} week" | "Last {count} month" | "Last {count} year", params?: import("@gravity-ui/i18n").Params | undefined) => string;
|