@stackone/malachite 2.136.0 → 2.138.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/COMPONENTS.md +4 -3
- package/dist/components/DatePicker.js +24 -22
- package/dist/components/DatePicker.js.map +1 -1
- package/dist/components/DatePickerField.js +151 -146
- package/dist/components/DatePickerField.js.map +1 -1
- package/dist/components/DatePickerPanel.js +190 -179
- package/dist/components/DatePickerPanel.js.map +1 -1
- package/dist/components/DateRangePicker.js +31 -29
- package/dist/components/DateRangePicker.js.map +1 -1
- package/dist/components/Table/Table.js +1118 -798
- package/dist/components/Table/Table.js.map +1 -1
- package/dist/components/Table/TableColumnPicker.js +70 -0
- package/dist/components/Table/TableColumnPicker.js.map +1 -0
- package/dist/components/TimeBarChart/TimeBarChart.js +120 -118
- package/dist/components/TimeBarChart/TimeBarChart.js.map +1 -1
- package/dist/components/TimeBarChart/TimeBarChartTable.js +14 -13
- package/dist/components/TimeBarChart/TimeBarChartTable.js.map +1 -1
- package/dist/components/TimeBarChart/timeBuckets.js +91 -87
- package/dist/components/TimeBarChart/timeBuckets.js.map +1 -1
- package/dist/components/Tooltip.js +80 -80
- package/dist/components/Tooltip.js.map +1 -1
- package/dist/index.d.ts +98 -1
- package/dist/index.js +36 -34
- package/dist/index.js.map +1 -1
- package/package.json +1 -1
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"TimeBarChartTable.js","sources":["../../../src/components/TimeBarChart/TimeBarChartTable.tsx"],"sourcesContent":["import type React from 'react';\nimport type { TimeBarChartSeries } from './TimeBarChart';\nimport { type TimeBarChartUnit
|
|
1
|
+
{"version":3,"file":"TimeBarChartTable.js","sources":["../../../src/components/TimeBarChart/TimeBarChartTable.tsx"],"sourcesContent":["import type React from 'react';\nimport type { TimeBarChartSeries } from './TimeBarChart';\nimport {\n type TimeBarChartTimeZone,\n type TimeBarChartUnit,\n type TimeSlot,\n formatBucket,\n formatCount,\n} from './timeBuckets';\n\ninterface TimeBarChartTableProps {\n timeZone: TimeBarChartTimeZone;\n caption?: string;\n /** Names the table when there is no caption, from the element naming the chart. */\n labelledBy?: string;\n series: TimeBarChartSeries[];\n slots: TimeSlot[];\n values: number[][];\n totals: number[];\n unit: TimeBarChartUnit;\n valueLabel: string;\n}\n\n/** The chart's numbers for screen readers, one row per non-empty bucket. */\nconst TimeBarChartTable: React.FC<TimeBarChartTableProps> = ({\n timeZone,\n caption,\n labelledBy,\n series,\n slots,\n values,\n totals,\n unit,\n valueLabel,\n}) => (\n // On a wrapper: a table ignores sr-only's 1px box and would still take its full height.\n <div className=\"sr-only\">\n <table aria-labelledby={caption ? undefined : labelledBy}>\n {caption && <caption>{caption}</caption>}\n <thead>\n <tr>\n <th scope=\"col\">Time</th>\n {series.map((entry) => (\n <th key={entry.key} scope=\"col\">\n {entry.label}\n </th>\n ))}\n <th scope=\"col\">{valueLabel}</th>\n </tr>\n </thead>\n <tbody>\n {slots.map((slot, index) =>\n totals[index] ? (\n <tr key={slot.start}>\n <th scope=\"row\">{formatBucket(slot.start, unit, timeZone)}</th>\n {values[index].map((value, position) => (\n <td key={series[position].key}>{formatCount(value)}</td>\n ))}\n <td>{formatCount(totals[index])}</td>\n </tr>\n ) : null,\n )}\n </tbody>\n </table>\n </div>\n);\n\nexport default TimeBarChartTable;\n"],"names":["TimeBarChartTable","timeZone","caption","labelledBy","series","slots","values","totals","unit","valueLabel","jsx","jsxs","entry","slot","index","formatBucket","value","position","formatCount"],"mappings":";;AAwBA,MAAMA,IAAsD,CAAC;AAAA,EACzD,UAAAC;AAAA,EACA,SAAAC;AAAA,EACA,YAAAC;AAAA,EACA,QAAAC;AAAA,EACA,OAAAC;AAAA,EACA,QAAAC;AAAA,EACA,QAAAC;AAAA,EACA,MAAAC;AAAA,EACA,YAAAC;AACJ;AAAA;AAAA,EAEI,gBAAAC,EAAC,SAAI,WAAU,WACX,4BAAC,SAAA,EAAM,mBAAiBR,IAAU,SAAYC,GACzC,UAAA;AAAA,IAAAD,KAAW,gBAAAQ,EAAC,aAAS,UAAAR,EAAA,CAAQ;AAAA,IAC9B,gBAAAQ,EAAC,SAAA,EACG,UAAA,gBAAAC,EAAC,MAAA,EACG,UAAA;AAAA,MAAA,gBAAAD,EAAC,MAAA,EAAG,OAAM,OAAM,UAAA,QAAI;AAAA,MACnBN,EAAO,IAAI,CAACQ,MACT,gBAAAF,EAAC,MAAA,EAAmB,OAAM,OACrB,UAAAE,EAAM,MAAA,GADFA,EAAM,GAEf,CACH;AAAA,MACD,gBAAAF,EAAC,MAAA,EAAG,OAAM,OAAO,UAAAD,EAAA,CAAW;AAAA,IAAA,EAAA,CAChC,EAAA,CACJ;AAAA,IACA,gBAAAC,EAAC,WACI,UAAAL,EAAM;AAAA,MAAI,CAACQ,GAAMC,MACdP,EAAOO,CAAK,sBACP,MAAA,EACG,UAAA;AAAA,QAAA,gBAAAJ,EAAC,MAAA,EAAG,OAAM,OAAO,UAAAK,EAAaF,EAAK,OAAOL,GAAMP,CAAQ,EAAA,CAAE;AAAA,QACzDK,EAAOQ,CAAK,EAAE,IAAI,CAACE,GAAOC,MACvB,gBAAAP,EAAC,MAAA,EAA+B,UAAAQ,EAAYF,CAAK,EAAA,GAAxCZ,EAAOa,CAAQ,EAAE,GAAyB,CACtD;AAAA,0BACA,MAAA,EAAI,UAAAC,EAAYX,EAAOO,CAAK,CAAC,EAAA,CAAE;AAAA,MAAA,KAL3BD,EAAK,KAMd,IACA;AAAA,IAAA,EACR,CACJ;AAAA,EAAA,EAAA,CACJ,EAAA,CACJ;AAAA;"}
|
|
@@ -1,55 +1,55 @@
|
|
|
1
|
-
import { MONTHS_SHORT as
|
|
2
|
-
const
|
|
3
|
-
minute:
|
|
1
|
+
import { fromParts as k, partsOf as Y, MONTHS_SHORT as p, daysInMonth as I } from "../dateMath.js";
|
|
2
|
+
const i = 6e4, g = 60 * i, h = 24 * g, y = {
|
|
3
|
+
minute: i,
|
|
4
4
|
hour: g,
|
|
5
5
|
day: h,
|
|
6
6
|
week: 7 * h
|
|
7
|
-
},
|
|
7
|
+
}, H = /^\d{4}-\d{2}-\d{2}(?:[ T]\d{2}:\d{2}(?::\d{2}(?:\.\d+)?)?)?$/, G = (t) => {
|
|
8
8
|
if (typeof t == "number") return t;
|
|
9
9
|
if (t instanceof Date) return t.getTime();
|
|
10
|
-
const
|
|
11
|
-
if (
|
|
12
|
-
const [
|
|
13
|
-
return Date.parse(`${
|
|
10
|
+
const e = t.trim();
|
|
11
|
+
if (H.test(e)) {
|
|
12
|
+
const [o, n = "00:00:00"] = e.split(/[ T]/);
|
|
13
|
+
return Date.parse(`${o}T${n}Z`);
|
|
14
14
|
}
|
|
15
|
-
return Date.parse(
|
|
16
|
-
},
|
|
17
|
-
const
|
|
18
|
-
if (
|
|
15
|
+
return Date.parse(e);
|
|
16
|
+
}, l = (t) => Math.max(1, Math.floor(t.step ?? 1)), $ = (t, e, o = 1) => {
|
|
17
|
+
const n = y[e.unit];
|
|
18
|
+
if (n !== void 0) return t + n * l(e) * o;
|
|
19
19
|
const r = new Date(t);
|
|
20
20
|
return Date.UTC(
|
|
21
21
|
r.getUTCFullYear(),
|
|
22
|
-
r.getUTCMonth() +
|
|
22
|
+
r.getUTCMonth() + l(e) * o,
|
|
23
23
|
r.getUTCDate(),
|
|
24
24
|
r.getUTCHours(),
|
|
25
25
|
r.getUTCMinutes()
|
|
26
26
|
);
|
|
27
|
-
}, w = 4 * h,
|
|
28
|
-
const
|
|
29
|
-
if (
|
|
30
|
-
const
|
|
31
|
-
return Date.UTC(Math.floor(
|
|
27
|
+
}, w = 4 * h, C = (t, e) => {
|
|
28
|
+
const o = l(e);
|
|
29
|
+
if (e.unit === "month") {
|
|
30
|
+
const s = new Date(t), c = s.getUTCFullYear() * 12 + s.getUTCMonth(), a = c - c % o;
|
|
31
|
+
return Date.UTC(Math.floor(a / 12), a % 12, 1);
|
|
32
32
|
}
|
|
33
|
-
const
|
|
34
|
-
return Math.floor((t - r) /
|
|
35
|
-
},
|
|
36
|
-
const
|
|
37
|
-
for (let
|
|
38
|
-
const
|
|
39
|
-
|
|
33
|
+
const n = (y[e.unit] ?? h) * o, r = e.unit === "week" ? w : 0;
|
|
34
|
+
return Math.floor((t - r) / n) * n + r;
|
|
35
|
+
}, _ = 2e3, Q = (t, e, o) => {
|
|
36
|
+
const n = [], r = C(e, o), s = Math.max(C(t, o), $(r, o, 1 - _));
|
|
37
|
+
for (let c = s; c <= r && n.length < _; ) {
|
|
38
|
+
const a = $(c, o);
|
|
39
|
+
n.push({ start: c, end: a }), c = a;
|
|
40
40
|
}
|
|
41
|
-
return
|
|
42
|
-
},
|
|
43
|
-
if (!Number.isFinite(
|
|
44
|
-
let
|
|
45
|
-
for (;
|
|
46
|
-
const r =
|
|
47
|
-
if (
|
|
48
|
-
else if (
|
|
41
|
+
return n;
|
|
42
|
+
}, V = (t, e) => {
|
|
43
|
+
if (!Number.isFinite(e)) return -1;
|
|
44
|
+
let o = 0, n = t.length - 1;
|
|
45
|
+
for (; o <= n; ) {
|
|
46
|
+
const r = o + n >> 1;
|
|
47
|
+
if (e < t[r].start) n = r - 1;
|
|
48
|
+
else if (e >= t[r].end) o = r + 1;
|
|
49
49
|
else return r;
|
|
50
50
|
}
|
|
51
51
|
return -1;
|
|
52
|
-
},
|
|
52
|
+
}, F = [
|
|
53
53
|
"January",
|
|
54
54
|
"February",
|
|
55
55
|
"March",
|
|
@@ -62,72 +62,76 @@ const M = 6e4, g = 60 * M, h = 24 * g, _ = {
|
|
|
62
62
|
"October",
|
|
63
63
|
"November",
|
|
64
64
|
"December"
|
|
65
|
-
],
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
65
|
+
], E = ["Sun", "Mon", "Tue", "Wed", "Thu", "Fri", "Sat"], T = (t) => String(t).padStart(2, "0"), d = (t) => `${T(t.getUTCHours())}:${T(t.getUTCMinutes())}`, L = (t) => `${E[t.getUTCDay()]} ${t.getUTCDate()}`, M = (t) => `${p[t.getUTCMonth()]} ${T(t.getUTCDate())}`, f = (t, e) => k(Y(new Date(t), e), "utc"), N = (t, e) => {
|
|
66
|
+
if (e === "utc") return "";
|
|
67
|
+
const o = Math.round((f(t, "local").getTime() - t) / i);
|
|
68
|
+
return ` UTC${o < 0 ? "-" : "+"}${T(Math.floor(Math.abs(o) / 60))}:${T(Math.abs(o) % 60)}`;
|
|
69
|
+
}, Z = (t, e, o = "utc") => {
|
|
70
|
+
const n = f(t, o), r = N(t, o);
|
|
71
|
+
return e === "minute" || e === "hour" ? `${M(n)} ${d(n)}${r}` : n.getUTCHours() || n.getUTCMinutes() ? `${M(n)}, ${n.getUTCFullYear()} ${d(n)}${r}` : e === "month" ? `${F[n.getUTCMonth()]} ${n.getUTCFullYear()}${r}` : `${M(n)}, ${n.getUTCFullYear()}${r}`;
|
|
72
|
+
}, R = 3 * g, X = 72 * g, x = 92 * h, B = (t, e) => t === "month" || e >= x ? "month" : t === "day" || t === "week" || e >= X ? "day" : t === "hour" || e >= R ? "hour" : "minute", J = {
|
|
69
73
|
minute: [1, 5, 10, 15, 30, 60, 120, 180, 360, 720],
|
|
70
74
|
hour: [1, 2, 3, 4, 6, 12, 24],
|
|
71
75
|
day: [1, 2, 3, 7, 14],
|
|
72
76
|
month: [1, 2, 3, 6, 12]
|
|
73
|
-
},
|
|
77
|
+
}, P = (t, e, o) => {
|
|
78
|
+
const n = new Date(t);
|
|
79
|
+
if (e === "minute") return (n.getUTCHours() * 60 + n.getUTCMinutes()) % o === 0;
|
|
80
|
+
if (e === "hour") return n.getUTCHours() % o === 0;
|
|
81
|
+
if (e === "month") return n.getUTCMonth() % o === 0;
|
|
82
|
+
const r = I({ year: n.getUTCFullYear(), month: n.getUTCMonth() });
|
|
83
|
+
return (n.getUTCDate() - 1) % o === 0 && n.getUTCDate() + o <= r + 1;
|
|
84
|
+
}, O = (t, e) => {
|
|
85
|
+
if (e === "minute") return t + i;
|
|
86
|
+
if (e === "hour") return t + g;
|
|
87
|
+
if (e === "day") return t + h;
|
|
74
88
|
const o = new Date(t);
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
return (o.getUTCDate() - 1) % e === 0 && o.getUTCDate() + e <= r + 1;
|
|
80
|
-
}, F = (t, n) => {
|
|
81
|
-
if (n === "minute") return t + M;
|
|
82
|
-
if (n === "hour") return t + g;
|
|
83
|
-
if (n === "day") return t + h;
|
|
84
|
-
const e = new Date(t);
|
|
85
|
-
return Date.UTC(e.getUTCFullYear(), e.getUTCMonth() + 1, 1);
|
|
86
|
-
}, X = (t, n) => {
|
|
87
|
-
const e = i(t, {
|
|
88
|
-
unit: n === "month" ? "month" : n
|
|
89
|
+
return Date.UTC(o.getUTCFullYear(), o.getUTCMonth() + 1, 1);
|
|
90
|
+
}, W = (t, e) => {
|
|
91
|
+
const o = C(t, {
|
|
92
|
+
unit: e === "month" ? "month" : e
|
|
89
93
|
});
|
|
90
|
-
return
|
|
91
|
-
},
|
|
94
|
+
return o < t ? O(o, e) : o;
|
|
95
|
+
}, z = 64, K = {
|
|
92
96
|
minute: "hour",
|
|
93
97
|
hour: "day",
|
|
94
98
|
day: "month",
|
|
95
99
|
month: void 0
|
|
96
|
-
},
|
|
97
|
-
const
|
|
98
|
-
for (let
|
|
99
|
-
|
|
100
|
-
const
|
|
101
|
-
if (
|
|
102
|
-
const
|
|
103
|
-
return
|
|
104
|
-
at:
|
|
105
|
-
label:
|
|
100
|
+
}, v = (t, e, o, n, r = "utc") => A(t, e, B(o, e - t), n, r), A = (t, e, o, n, r) => {
|
|
101
|
+
const s = [];
|
|
102
|
+
for (let u = W(t, o); u <= e && s.length < 5e3; u = O(u, o))
|
|
103
|
+
s.push(u);
|
|
104
|
+
const c = Math.max(1, Math.floor(n / z)), a = J[o], m = a.find((u) => s.length / u <= c), U = K[o];
|
|
105
|
+
if (m === void 0 && U) return A(t, e, U, n, r);
|
|
106
|
+
const b = m ?? a[a.length - 1], S = s.filter((u) => P(u, o, b));
|
|
107
|
+
return S.map((u, D) => ({
|
|
108
|
+
at: u,
|
|
109
|
+
label: j(u, o, D === 0 ? u - 1 : S[D - 1], r)
|
|
106
110
|
}));
|
|
107
|
-
},
|
|
108
|
-
const
|
|
109
|
-
return
|
|
110
|
-
},
|
|
111
|
+
}, j = (t, e, o, n) => {
|
|
112
|
+
const r = f(t, n), s = f(o, n);
|
|
113
|
+
return r.getUTCFullYear() !== s.getUTCFullYear() ? String(r.getUTCFullYear()) : r.getUTCMonth() !== s.getUTCMonth() ? F[r.getUTCMonth()] : e === "month" ? p[r.getUTCMonth()] : r.getUTCDate() !== s.getUTCDate() || e === "day" ? L(r) : d(r);
|
|
114
|
+
}, tt = (t, e = 4) => {
|
|
111
115
|
if (t <= 0) return [0, 1];
|
|
112
|
-
const
|
|
116
|
+
const o = t / e, n = 10 ** Math.floor(Math.log10(o)), r = Math.max(
|
|
113
117
|
1,
|
|
114
|
-
[1, 2, 5, 10].map((
|
|
115
|
-
),
|
|
116
|
-
return Array.from({ length:
|
|
117
|
-
},
|
|
118
|
+
[1, 2, 5, 10].map((c) => c * n).find((c) => c >= o) ?? 10 * n
|
|
119
|
+
), s = Math.ceil(t / r) * r;
|
|
120
|
+
return Array.from({ length: s / r + 1 }, (c, a) => a * r);
|
|
121
|
+
}, et = (t) => t.toLocaleString("en", { notation: "compact", maximumFractionDigits: 1 }), ot = (t) => t.toLocaleString("en");
|
|
118
122
|
export {
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
123
|
+
z as AXIS_LABEL_WIDTH_PX,
|
|
124
|
+
_ as MAX_SLOTS,
|
|
125
|
+
$ as addBuckets,
|
|
126
|
+
v as axisTicks,
|
|
127
|
+
B as axisUnitFor,
|
|
128
|
+
Q as bucketSlots,
|
|
129
|
+
C as bucketStart,
|
|
130
|
+
Z as formatBucket,
|
|
131
|
+
et as formatCompact,
|
|
132
|
+
ot as formatCount,
|
|
133
|
+
V as slotIndexOf,
|
|
134
|
+
G as toInstant,
|
|
135
|
+
tt as valueTicks
|
|
132
136
|
};
|
|
133
137
|
//# sourceMappingURL=timeBuckets.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"timeBuckets.js","sources":["../../../src/components/TimeBarChart/timeBuckets.ts"],"sourcesContent":["import { MONTHS_SHORT, daysInMonth } from '../dateMath';\n\n// UTC time arithmetic for TimeBarChart, kept free of a date library so the component adds no\n// dependency. Every instant is milliseconds since the epoch, read and written in UTC.\n\nexport type TimeBarChartUnit = 'minute' | 'hour' | 'day' | 'week' | 'month';\n\nexport interface TimeBarChartInterval {\n unit: TimeBarChartUnit;\n /** How many `unit`s one bucket spans, e.g. 3 with `hour` for 3-hour buckets. Default 1. */\n step?: number;\n}\n\nexport type TimeInput = string | number | Date;\n\nexport interface TimeSlot {\n start: number;\n end: number;\n}\n\nconst MINUTE_MS = 60_000;\nconst HOUR_MS = 60 * MINUTE_MS;\nconst DAY_MS = 24 * HOUR_MS;\n\nconst FIXED_UNIT_MS: Partial<Record<TimeBarChartUnit, number>> = {\n minute: MINUTE_MS,\n hour: HOUR_MS,\n day: DAY_MS,\n week: 7 * DAY_MS,\n};\n\n// A date and time with no zone, as APIs often send bucket starts (\"2026-10-14 12:00:00\").\nconst ZONELESS = /^\\d{4}-\\d{2}-\\d{2}(?:[ T]\\d{2}:\\d{2}(?::\\d{2}(?:\\.\\d+)?)?)?$/;\n\n/** An instant in ms. A string with no zone is read as UTC, not as the viewer's local time. */\nexport const toInstant = (value: TimeInput): number => {\n if (typeof value === 'number') return value;\n if (value instanceof Date) return value.getTime();\n const text = value.trim();\n if (ZONELESS.test(text)) {\n const [date, time = '00:00:00'] = text.split(/[ T]/);\n return Date.parse(`${date}T${time}Z`);\n }\n return Date.parse(text);\n};\n\nconst stepOf = (interval: TimeBarChartInterval) => Math.max(1, Math.floor(interval.step ?? 1));\n\n/** `instant` moved on by `count` buckets. Months move by calendar month, keeping the day. */\nexport const addBuckets = (instant: number, interval: TimeBarChartInterval, count = 1): number => {\n const fixed = FIXED_UNIT_MS[interval.unit];\n if (fixed !== undefined) return instant + fixed * stepOf(interval) * count;\n const date = new Date(instant);\n return Date.UTC(\n date.getUTCFullYear(),\n date.getUTCMonth() + stepOf(interval) * count,\n date.getUTCDate(),\n date.getUTCHours(),\n date.getUTCMinutes(),\n );\n};\n\n// The Unix epoch was a Thursday; ISO weeks start on Monday, three days later.\nconst FIRST_MONDAY_MS = 4 * DAY_MS;\n\n/**\n * The start of the bucket holding `instant`. Minute, hour and day buckets count from the epoch,\n * as bucketing APIs do, weeks from a Monday and months from the 1st.\n */\nexport const bucketStart = (instant: number, interval: TimeBarChartInterval): number => {\n const step = stepOf(interval);\n if (interval.unit === 'month') {\n const date = new Date(instant);\n const months = date.getUTCFullYear() * 12 + date.getUTCMonth();\n const first = months - (months % step);\n return Date.UTC(Math.floor(first / 12), first % 12, 1);\n }\n const length = (FIXED_UNIT_MS[interval.unit] ?? DAY_MS) * step;\n const origin = interval.unit === 'week' ? FIRST_MONDAY_MS : 0;\n return Math.floor((instant - origin) / length) * length + origin;\n};\n\n/** Bounded so a range thousands of buckets wide cannot hang the page. */\nexport const MAX_SLOTS = 2000;\n\n/**\n * A slot for every bucket from the one holding `from` to the one holding `to`, empty ones\n * included, so an empty bucket can still be hovered and selected. Past `MAX_SLOTS` the newest\n * are kept, so a live window still ends at \"now\".\n */\nexport const bucketSlots = (\n from: number,\n to: number,\n interval: TimeBarChartInterval,\n): TimeSlot[] => {\n const slots: TimeSlot[] = [];\n const last = bucketStart(to, interval);\n const first = Math.max(bucketStart(from, interval), addBuckets(last, interval, 1 - MAX_SLOTS));\n for (let start = first; start <= last && slots.length < MAX_SLOTS; ) {\n const end = addBuckets(start, interval);\n slots.push({ start, end });\n start = end;\n }\n return slots;\n};\n\n/** The index of the slot whose span holds `instant`, or -1. */\nexport const slotIndexOf = (slots: TimeSlot[], instant: number): number => {\n if (!Number.isFinite(instant)) return -1;\n let low = 0;\n let high = slots.length - 1;\n while (low <= high) {\n const middle = (low + high) >> 1;\n if (instant < slots[middle].start) high = middle - 1;\n else if (instant >= slots[middle].end) low = middle + 1;\n else return middle;\n }\n return -1;\n};\n\nconst MONTHS = [\n 'January',\n 'February',\n 'March',\n 'April',\n 'May',\n 'June',\n 'July',\n 'August',\n 'September',\n 'October',\n 'November',\n 'December',\n];\nconst WEEKDAYS = ['Sun', 'Mon', 'Tue', 'Wed', 'Thu', 'Fri', 'Sat'];\nconst pad = (value: number) => String(value).padStart(2, '0');\n\nconst clock = (date: Date) => `${pad(date.getUTCHours())}:${pad(date.getUTCMinutes())}`;\nconst weekday = (date: Date) => `${WEEKDAYS[date.getUTCDay()]} ${date.getUTCDate()}`;\nconst shortDate = (date: Date) => `${MONTHS_SHORT[date.getUTCMonth()]} ${pad(date.getUTCDate())}`;\n\n/** How a bucket is named in the tooltip, e.g. \"Oct 29 14:00\" or \"Oct 29, 2026\". */\nexport const formatBucket = (instant: number, unit: TimeBarChartUnit): string => {\n const date = new Date(instant);\n if (unit === 'month') return `${MONTHS[date.getUTCMonth()]} ${date.getUTCFullYear()}`;\n if (unit === 'day' || unit === 'week') {\n return `${shortDate(date)}, ${date.getUTCFullYear()}`;\n }\n return `${shortDate(date)} ${clock(date)}`;\n};\n\nexport type AxisUnit = 'minute' | 'hour' | 'day' | 'month';\n\n// Below these spans a minute or hour axis is labelled in its own unit; from them, in a coarser\n// one, as 3-hour buckets over 14 days read better against days.\nconst HOUR_AXIS_FROM_MS = 3 * HOUR_MS;\nconst DAY_AXIS_FROM_MS = 72 * HOUR_MS;\nconst MONTH_AXIS_FROM_MS = 92 * DAY_MS;\n\nexport const axisUnitFor = (unit: TimeBarChartUnit, span: number): AxisUnit => {\n if (unit === 'month' || span >= MONTH_AXIS_FROM_MS) return 'month';\n if (unit === 'day' || unit === 'week' || span >= DAY_AXIS_FROM_MS) return 'day';\n if (unit === 'hour' || span >= HOUR_AXIS_FROM_MS) return 'hour';\n return 'minute';\n};\n\n// Steps a label may sit on, smallest first. Minute and hour steps divide a day and day steps\n// start each month on the 1st, so labels stay even and land on the boundaries.\nconst LABEL_STEPS: Record<AxisUnit, number[]> = {\n minute: [1, 5, 10, 15, 30, 60, 120, 180, 360, 720],\n hour: [1, 2, 3, 4, 6, 12, 24],\n day: [1, 2, 3, 7, 14],\n month: [1, 2, 3, 6, 12],\n};\n\nconst isOnStep = (instant: number, unit: AxisUnit, step: number): boolean => {\n const date = new Date(instant);\n if (unit === 'minute') return (date.getUTCHours() * 60 + date.getUTCMinutes()) % step === 0;\n if (unit === 'hour') return date.getUTCHours() % step === 0;\n if (unit === 'month') return date.getUTCMonth() % step === 0;\n // Day 1 is always on the step, so a day too close to the next month's 1st is dropped\n // rather than crowding it.\n const monthLength = daysInMonth({ year: date.getUTCFullYear(), month: date.getUTCMonth() });\n return (date.getUTCDate() - 1) % step === 0 && date.getUTCDate() + step <= monthLength + 1;\n};\n\nconst nextBoundary = (instant: number, unit: AxisUnit): number => {\n if (unit === 'minute') return instant + MINUTE_MS;\n if (unit === 'hour') return instant + HOUR_MS;\n if (unit === 'day') return instant + DAY_MS;\n const date = new Date(instant);\n return Date.UTC(date.getUTCFullYear(), date.getUTCMonth() + 1, 1);\n};\n\nconst firstBoundary = (from: number, unit: AxisUnit): number => {\n const start = bucketStart(from, {\n unit: unit === 'month' ? 'month' : unit,\n });\n return start < from ? nextBoundary(start, unit) : start;\n};\n\n/** Roughly the width a label needs, gap included. */\nexport const AXIS_LABEL_WIDTH_PX = 64;\n\nexport interface AxisTick {\n at: number;\n label: string;\n}\n\nconst COARSER_AXIS: Record<AxisUnit, AxisUnit | undefined> = {\n minute: 'hour',\n hour: 'day',\n day: 'month',\n month: undefined,\n};\n\n/**\n * The labelled ticks between `from` and `to`, on the smallest clock- or calendar-aligned step\n * that fits `width`, moving to a coarser unit when no step of this one does. A tick names a\n * boundary it passes instead of its short form: the year on a new year, the month on a new\n * month, the day on a new day.\n */\nexport const axisTicks = (\n from: number,\n to: number,\n unit: TimeBarChartUnit,\n width: number,\n): AxisTick[] => ticksOn(from, to, axisUnitFor(unit, to - from), width);\n\nconst ticksOn = (from: number, to: number, axisUnit: AxisUnit, width: number): AxisTick[] => {\n const boundaries: number[] = [];\n for (\n let at = firstBoundary(from, axisUnit);\n at <= to && boundaries.length < 5000;\n at = nextBoundary(at, axisUnit)\n ) {\n boundaries.push(at);\n }\n const capacity = Math.max(1, Math.floor(width / AXIS_LABEL_WIDTH_PX));\n const steps = LABEL_STEPS[axisUnit];\n const fitting = steps.find((candidate) => boundaries.length / candidate <= capacity);\n const coarser = COARSER_AXIS[axisUnit];\n if (fitting === undefined && coarser) return ticksOn(from, to, coarser, width);\n const step = fitting ?? steps[steps.length - 1];\n const kept = boundaries.filter((at) => isOnStep(at, axisUnit, step));\n return kept.map((at, index) => ({\n at,\n label: tickLabel(at, axisUnit, index === 0 ? at - 1 : kept[index - 1]),\n }));\n};\n\nconst tickLabel = (at: number, unit: AxisUnit, previousAt: number): string => {\n const date = new Date(at);\n const previous = new Date(previousAt);\n if (date.getUTCFullYear() !== previous.getUTCFullYear()) return String(date.getUTCFullYear());\n if (date.getUTCMonth() !== previous.getUTCMonth()) return MONTHS[date.getUTCMonth()];\n if (unit === 'month') return MONTHS_SHORT[date.getUTCMonth()];\n if (date.getUTCDate() !== previous.getUTCDate() || unit === 'day') return weekday(date);\n return clock(date);\n};\n\n/**\n * A y-axis that ends on a round number, with about `count` steps of 1, 2 or 5 times a power of\n * ten, never below 1 since the values are counts.\n */\nexport const valueTicks = (max: number, count = 4): number[] => {\n if (max <= 0) return [0, 1];\n const rough = max / count;\n const magnitude = 10 ** Math.floor(Math.log10(rough));\n const step = Math.max(\n 1,\n [1, 2, 5, 10].map((factor) => factor * magnitude).find((size) => size >= rough) ??\n 10 * magnitude,\n );\n const top = Math.ceil(max / step) * step;\n return Array.from({ length: top / step + 1 }, (_unused, index) => index * step);\n};\n\n// Built per call rather than at module scope: nothing in the library may run at import time.\nexport const formatCompact = (value: number): string =>\n value.toLocaleString('en', { notation: 'compact', maximumFractionDigits: 1 });\nexport const formatCount = (value: number): string => value.toLocaleString('en');\n"],"names":["MINUTE_MS","HOUR_MS","DAY_MS","FIXED_UNIT_MS","ZONELESS","toInstant","value","text","date","time","stepOf","interval","addBuckets","instant","count","fixed","FIRST_MONDAY_MS","bucketStart","step","months","first","length","origin","MAX_SLOTS","bucketSlots","from","to","slots","last","start","end","slotIndexOf","low","high","middle","MONTHS","WEEKDAYS","pad","clock","weekday","shortDate","MONTHS_SHORT","formatBucket","unit","HOUR_AXIS_FROM_MS","DAY_AXIS_FROM_MS","MONTH_AXIS_FROM_MS","axisUnitFor","span","LABEL_STEPS","isOnStep","monthLength","daysInMonth","nextBoundary","firstBoundary","AXIS_LABEL_WIDTH_PX","COARSER_AXIS","axisTicks","width","ticksOn","axisUnit","boundaries","at","capacity","steps","fitting","candidate","coarser","kept","index","tickLabel","previousAt","previous","valueTicks","max","rough","magnitude","factor","size","top","_unused","formatCompact","formatCount"],"mappings":";AAoBA,MAAMA,IAAY,KACZC,IAAU,KAAKD,GACfE,IAAS,KAAKD,GAEdE,IAA2D;AAAA,EAC7D,QAAQH;AAAA,EACR,MAAMC;AAAA,EACN,KAAKC;AAAA,EACL,MAAM,IAAIA;AACd,GAGME,IAAW,gEAGJC,IAAY,CAACC,MAA6B;AACnD,MAAI,OAAOA,KAAU,SAAU,QAAOA;AACtC,MAAIA,aAAiB,KAAM,QAAOA,EAAM,QAAA;AACxC,QAAMC,IAAOD,EAAM,KAAA;AACnB,MAAIF,EAAS,KAAKG,CAAI,GAAG;AACrB,UAAM,CAACC,GAAMC,IAAO,UAAU,IAAIF,EAAK,MAAM,MAAM;AACnD,WAAO,KAAK,MAAM,GAAGC,CAAI,IAAIC,CAAI,GAAG;AAAA,EACxC;AACA,SAAO,KAAK,MAAMF,CAAI;AAC1B,G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,UAAU,WAAW,uBAAuB,EAAA,CAAG,GACnE4E,IAAc,CAAC5E,MAA0BA,EAAM,eAAe,IAAI;"}
|
|
1
|
+
{"version":3,"file":"timeBuckets.js","sources":["../../../src/components/TimeBarChart/timeBuckets.ts"],"sourcesContent":["import { type DatePickerTimeZone, MONTHS_SHORT, daysInMonth, fromParts, partsOf } from '../dateMath';\n\n// Time arithmetic for TimeBarChart, kept free of a date library so the component adds no\n// dependency. Every instant is milliseconds since the epoch. Buckets and tick positions are UTC,\n// as the data is bucketed; only labels follow a local display zone, so a tick stays on a bar.\n\nexport type TimeBarChartUnit = 'minute' | 'hour' | 'day' | 'week' | 'month';\n\nexport interface TimeBarChartInterval {\n unit: TimeBarChartUnit;\n /** How many `unit`s one bucket spans, e.g. 3 with `hour` for 3-hour buckets. Default 1. */\n step?: number;\n}\n\nexport type TimeInput = string | number | Date;\n\nexport interface TimeSlot {\n start: number;\n end: number;\n}\n\nconst MINUTE_MS = 60_000;\nconst HOUR_MS = 60 * MINUTE_MS;\nconst DAY_MS = 24 * HOUR_MS;\n\nconst FIXED_UNIT_MS: Partial<Record<TimeBarChartUnit, number>> = {\n minute: MINUTE_MS,\n hour: HOUR_MS,\n day: DAY_MS,\n week: 7 * DAY_MS,\n};\n\n// A date and time with no zone, as APIs often send bucket starts (\"2026-10-14 12:00:00\").\nconst ZONELESS = /^\\d{4}-\\d{2}-\\d{2}(?:[ T]\\d{2}:\\d{2}(?::\\d{2}(?:\\.\\d+)?)?)?$/;\n\n/** An instant in ms. A string with no zone is read as UTC, not as the viewer's local time. */\nexport const toInstant = (value: TimeInput): number => {\n if (typeof value === 'number') return value;\n if (value instanceof Date) return value.getTime();\n const text = value.trim();\n if (ZONELESS.test(text)) {\n const [date, time = '00:00:00'] = text.split(/[ T]/);\n return Date.parse(`${date}T${time}Z`);\n }\n return Date.parse(text);\n};\n\nconst stepOf = (interval: TimeBarChartInterval) => Math.max(1, Math.floor(interval.step ?? 1));\n\n/** `instant` moved on by `count` buckets. Months move by calendar month, keeping the day. */\nexport const addBuckets = (instant: number, interval: TimeBarChartInterval, count = 1): number => {\n const fixed = FIXED_UNIT_MS[interval.unit];\n if (fixed !== undefined) return instant + fixed * stepOf(interval) * count;\n const date = new Date(instant);\n return Date.UTC(\n date.getUTCFullYear(),\n date.getUTCMonth() + stepOf(interval) * count,\n date.getUTCDate(),\n date.getUTCHours(),\n date.getUTCMinutes(),\n );\n};\n\n// The Unix epoch was a Thursday; ISO weeks start on Monday, three days later.\nconst FIRST_MONDAY_MS = 4 * DAY_MS;\n\n/**\n * The start of the bucket holding `instant`. Minute, hour and day buckets count from the epoch,\n * as bucketing APIs do, weeks from a Monday and months from the 1st.\n */\nexport const bucketStart = (instant: number, interval: TimeBarChartInterval): number => {\n const step = stepOf(interval);\n if (interval.unit === 'month') {\n const date = new Date(instant);\n const months = date.getUTCFullYear() * 12 + date.getUTCMonth();\n const first = months - (months % step);\n return Date.UTC(Math.floor(first / 12), first % 12, 1);\n }\n const length = (FIXED_UNIT_MS[interval.unit] ?? DAY_MS) * step;\n const origin = interval.unit === 'week' ? FIRST_MONDAY_MS : 0;\n return Math.floor((instant - origin) / length) * length + origin;\n};\n\n/** Bounded so a range thousands of buckets wide cannot hang the page. */\nexport const MAX_SLOTS = 2000;\n\n/**\n * A slot for every bucket from the one holding `from` to the one holding `to`, empty ones\n * included, so an empty bucket can still be hovered and selected. Past `MAX_SLOTS` the newest\n * are kept, so a live window still ends at \"now\".\n */\nexport const bucketSlots = (\n from: number,\n to: number,\n interval: TimeBarChartInterval,\n): TimeSlot[] => {\n const slots: TimeSlot[] = [];\n const last = bucketStart(to, interval);\n const first = Math.max(bucketStart(from, interval), addBuckets(last, interval, 1 - MAX_SLOTS));\n for (let start = first; start <= last && slots.length < MAX_SLOTS; ) {\n const end = addBuckets(start, interval);\n slots.push({ start, end });\n start = end;\n }\n return slots;\n};\n\n/** The index of the slot whose span holds `instant`, or -1. */\nexport const slotIndexOf = (slots: TimeSlot[], instant: number): number => {\n if (!Number.isFinite(instant)) return -1;\n let low = 0;\n let high = slots.length - 1;\n while (low <= high) {\n const middle = (low + high) >> 1;\n if (instant < slots[middle].start) high = middle - 1;\n else if (instant >= slots[middle].end) low = middle + 1;\n else return middle;\n }\n return -1;\n};\n\nconst MONTHS = [\n 'January',\n 'February',\n 'March',\n 'April',\n 'May',\n 'June',\n 'July',\n 'August',\n 'September',\n 'October',\n 'November',\n 'December',\n];\nconst WEEKDAYS = ['Sun', 'Mon', 'Tue', 'Wed', 'Thu', 'Fri', 'Sat'];\nconst pad = (value: number) => String(value).padStart(2, '0');\n\nconst clock = (date: Date) => `${pad(date.getUTCHours())}:${pad(date.getUTCMinutes())}`;\nconst weekday = (date: Date) => `${WEEKDAYS[date.getUTCDay()]} ${date.getUTCDate()}`;\nconst shortDate = (date: Date) => `${MONTHS_SHORT[date.getUTCMonth()]} ${pad(date.getUTCDate())}`;\n\nexport type TimeBarChartTimeZone = DatePickerTimeZone;\n\n/** A date whose UTC fields read as the wall clock of `timeZone` at `instant`. */\nconst displayDate = (instant: number, timeZone: TimeBarChartTimeZone): Date =>\n fromParts(partsOf(new Date(instant), timeZone), 'utc');\n\nconst zoneSuffix = (instant: number, timeZone: TimeBarChartTimeZone): string => {\n if (timeZone === 'utc') return '';\n const offset = Math.round((displayDate(instant, 'local').getTime() - instant) / MINUTE_MS);\n return ` UTC${offset < 0 ? '-' : '+'}${pad(Math.floor(Math.abs(offset) / 60))}:${pad(Math.abs(offset) % 60)}`;\n};\n\n/** Formats a bucket in the requested zone; its instant and bucket boundaries remain UTC. */\nexport const formatBucket = (\n instant: number,\n unit: TimeBarChartUnit,\n timeZone: TimeBarChartTimeZone = 'utc',\n): string => {\n const date = displayDate(instant, timeZone);\n const suffix = zoneSuffix(instant, timeZone);\n if (unit === 'minute' || unit === 'hour') return `${shortDate(date)} ${clock(date)}${suffix}`;\n // A UTC-aligned bucket shown in a non-UTC zone starts mid-day, so its date alone misnames it.\n if (date.getUTCHours() || date.getUTCMinutes()) {\n return `${shortDate(date)}, ${date.getUTCFullYear()} ${clock(date)}${suffix}`;\n }\n if (unit === 'month') return `${MONTHS[date.getUTCMonth()]} ${date.getUTCFullYear()}${suffix}`;\n return `${shortDate(date)}, ${date.getUTCFullYear()}${suffix}`;\n};\n\nexport type AxisUnit = 'minute' | 'hour' | 'day' | 'month';\n\n// Below these spans a minute or hour axis is labelled in its own unit; from them, in a coarser\n// one, as 3-hour buckets over 14 days read better against days.\nconst HOUR_AXIS_FROM_MS = 3 * HOUR_MS;\nconst DAY_AXIS_FROM_MS = 72 * HOUR_MS;\nconst MONTH_AXIS_FROM_MS = 92 * DAY_MS;\n\nexport const axisUnitFor = (unit: TimeBarChartUnit, span: number): AxisUnit => {\n if (unit === 'month' || span >= MONTH_AXIS_FROM_MS) return 'month';\n if (unit === 'day' || unit === 'week' || span >= DAY_AXIS_FROM_MS) return 'day';\n if (unit === 'hour' || span >= HOUR_AXIS_FROM_MS) return 'hour';\n return 'minute';\n};\n\n// Steps a label may sit on, smallest first. Minute and hour steps divide a day and day steps\n// start each month on the 1st, so labels stay even and land on the boundaries.\nconst LABEL_STEPS: Record<AxisUnit, number[]> = {\n minute: [1, 5, 10, 15, 30, 60, 120, 180, 360, 720],\n hour: [1, 2, 3, 4, 6, 12, 24],\n day: [1, 2, 3, 7, 14],\n month: [1, 2, 3, 6, 12],\n};\n\nconst isOnStep = (instant: number, unit: AxisUnit, step: number): boolean => {\n const date = new Date(instant);\n if (unit === 'minute') return (date.getUTCHours() * 60 + date.getUTCMinutes()) % step === 0;\n if (unit === 'hour') return date.getUTCHours() % step === 0;\n if (unit === 'month') return date.getUTCMonth() % step === 0;\n // Day 1 is always on the step, so a day too close to the next month's 1st is dropped\n // rather than crowding it.\n const monthLength = daysInMonth({ year: date.getUTCFullYear(), month: date.getUTCMonth() });\n return (date.getUTCDate() - 1) % step === 0 && date.getUTCDate() + step <= monthLength + 1;\n};\n\nconst nextBoundary = (instant: number, unit: AxisUnit): number => {\n if (unit === 'minute') return instant + MINUTE_MS;\n if (unit === 'hour') return instant + HOUR_MS;\n if (unit === 'day') return instant + DAY_MS;\n const date = new Date(instant);\n return Date.UTC(date.getUTCFullYear(), date.getUTCMonth() + 1, 1);\n};\n\nconst firstBoundary = (from: number, unit: AxisUnit): number => {\n const start = bucketStart(from, {\n unit: unit === 'month' ? 'month' : unit,\n });\n return start < from ? nextBoundary(start, unit) : start;\n};\n\n/** Roughly the width a label needs, gap included. */\nexport const AXIS_LABEL_WIDTH_PX = 64;\n\nexport interface AxisTick {\n at: number;\n label: string;\n}\n\nconst COARSER_AXIS: Record<AxisUnit, AxisUnit | undefined> = {\n minute: 'hour',\n hour: 'day',\n day: 'month',\n month: undefined,\n};\n\n/**\n * The labelled ticks between `from` and `to`, on the smallest clock- or calendar-aligned step\n * that fits `width`, moving to a coarser unit when no step of this one does. A tick names a\n * boundary it passes instead of its short form: the year on a new year, the month on a new\n * month, the day on a new day.\n */\nexport const axisTicks = (\n from: number,\n to: number,\n unit: TimeBarChartUnit,\n width: number,\n timeZone: TimeBarChartTimeZone = 'utc',\n): AxisTick[] => ticksOn(from, to, axisUnitFor(unit, to - from), width, timeZone);\n\nconst ticksOn = (\n from: number,\n to: number,\n axisUnit: AxisUnit,\n width: number,\n timeZone: TimeBarChartTimeZone,\n): AxisTick[] => {\n const boundaries: number[] = [];\n for (\n let at = firstBoundary(from, axisUnit);\n at <= to && boundaries.length < 5000;\n at = nextBoundary(at, axisUnit)\n ) {\n boundaries.push(at);\n }\n const capacity = Math.max(1, Math.floor(width / AXIS_LABEL_WIDTH_PX));\n const steps = LABEL_STEPS[axisUnit];\n const fitting = steps.find((candidate) => boundaries.length / candidate <= capacity);\n const coarser = COARSER_AXIS[axisUnit];\n if (fitting === undefined && coarser) return ticksOn(from, to, coarser, width, timeZone);\n const step = fitting ?? steps[steps.length - 1];\n const kept = boundaries.filter((at) => isOnStep(at, axisUnit, step));\n return kept.map((at, index) => ({\n at,\n label: tickLabel(at, axisUnit, index === 0 ? at - 1 : kept[index - 1], timeZone),\n }));\n};\n\nconst tickLabel = (\n at: number,\n unit: AxisUnit,\n previousAt: number,\n timeZone: TimeBarChartTimeZone,\n): string => {\n const date = displayDate(at, timeZone);\n const previous = displayDate(previousAt, timeZone);\n if (date.getUTCFullYear() !== previous.getUTCFullYear()) return String(date.getUTCFullYear());\n if (date.getUTCMonth() !== previous.getUTCMonth()) return MONTHS[date.getUTCMonth()];\n if (unit === 'month') return MONTHS_SHORT[date.getUTCMonth()];\n if (date.getUTCDate() !== previous.getUTCDate() || unit === 'day') return weekday(date);\n return clock(date);\n};\n\n/**\n * A y-axis that ends on a round number, with about `count` steps of 1, 2 or 5 times a power of\n * ten, never below 1 since the values are counts.\n */\nexport const valueTicks = (max: number, count = 4): number[] => {\n if (max <= 0) return [0, 1];\n const rough = max / count;\n const magnitude = 10 ** Math.floor(Math.log10(rough));\n const step = Math.max(\n 1,\n [1, 2, 5, 10].map((factor) => factor * magnitude).find((size) => size >= rough) ??\n 10 * magnitude,\n );\n const top = Math.ceil(max / step) * step;\n return Array.from({ length: top / step + 1 }, (_unused, index) => index * step);\n};\n\n// Built per call rather than at module scope: nothing in the library may run at import time.\nexport const formatCompact = (value: number): string =>\n value.toLocaleString('en', { notation: 'compact', maximumFractionDigits: 1 });\nexport const formatCount = (value: number): string => value.toLocaleString('en');\n"],"names":["MINUTE_MS","HOUR_MS","DAY_MS","FIXED_UNIT_MS","ZONELESS","toInstant","value","text","date","time","stepOf","interval","addBuckets","instant","count","fixed","FIRST_MONDAY_MS","bucketStart","step","months","first","length","origin","MAX_SLOTS","bucketSlots","from","to","slots","last","start","end","slotIndexOf","low","high","middle","MONTHS","WEEKDAYS","pad","clock","weekday","shortDate","MONTHS_SHORT","displayDate","timeZone","fromParts","partsOf","zoneSuffix","offset","formatBucket","unit","suffix","HOUR_AXIS_FROM_MS","DAY_AXIS_FROM_MS","MONTH_AXIS_FROM_MS","axisUnitFor","span","LABEL_STEPS","isOnStep","monthLength","daysInMonth","nextBoundary","firstBoundary","AXIS_LABEL_WIDTH_PX","COARSER_AXIS","axisTicks","width","ticksOn","axisUnit","boundaries","at","capacity","steps","fitting","candidate","coarser","kept","index","tickLabel","previousAt","previous","valueTicks","max","rough","magnitude","factor","size","top","_unused","formatCompact","formatCount"],"mappings":";AAqBA,MAAMA,IAAY,KACZC,IAAU,KAAKD,GACfE,IAAS,KAAKD,GAEdE,IAA2D;AAAA,EAC7D,QAAQH;AAAA,EACR,MAAMC;AAAA,EACN,KAAKC;AAAA,EACL,MAAM,IAAIA;AACd,GAGME,IAAW,gEAGJC,IAAY,CAACC,MAA6B;AACnD,MAAI,OAAOA,KAAU,SAAU,QAAOA;AACtC,MAAIA,aAAiB,KAAM,QAAOA,EAAM,QAAA;AACxC,QAAMC,IAAOD,EAAM,KAAA;AACnB,MAAIF,EAAS,KAAKG,CAAI,GAAG;AACrB,UAAM,CAACC,GAAMC,IAAO,UAAU,IAAIF,EAAK,MAAM,MAAM;AACnD,WAAO,KAAK,MAAM,GAAGC,CAAI,IAAIC,CAAI,GAAG;AAAA,EACxC;AACA,SAAO,KAAK,MAAMF,CAAI;AAC1B,GAEMG,IAAS,CAACC,MAAmC,KAAK,IAAI,GAAG,KAAK,MAAMA,EAAS,QAAQ,CAAC,CAAC,GAGhFC,IAAa,CAACC,GAAiBF,GAAgCG,IAAQ,MAAc;AAC9F,QAAMC,IAAQZ,EAAcQ,EAAS,IAAI;AACzC,MAAII,MAAU,OAAW,QAAOF,IAAUE,IAAQL,EAAOC,CAAQ,IAAIG;AACrE,QAAMN,IAAO,IAAI,KAAKK,CAAO;AAC7B,SAAO,KAAK;AAAA,IACRL,EAAK,eAAA;AAAA,IACLA,EAAK,YAAA,IAAgBE,EAAOC,CAAQ,IAAIG;AAAA,IACxCN,EAAK,WAAA;AAAA,IACLA,EAAK,YAAA;AAAA,IACLA,EAAK,cAAA;AAAA,EAAc;AAE3B,GAGMQ,IAAkB,IAAId,GAMfe,IAAc,CAACJ,G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M,KAAK,KAAKL,IAAM/D,CAAI,IAAIA;AACpC,SAAO,MAAM,KAAK,EAAE,QAAQoE,IAAMpE,IAAO,EAAA,GAAK,CAACqE,GAASX,MAAUA,IAAQ1D,CAAI;AAClF,GAGasE,KAAgB,CAAClF,MAC1BA,EAAM,eAAe,MAAM,EAAE,UAAU,WAAW,uBAAuB,EAAA,CAAG,GACnEmF,KAAc,CAACnF,MAA0BA,EAAM,eAAe,IAAI;"}
|
|
@@ -1,90 +1,90 @@
|
|
|
1
|
-
import { jsx as p, jsxs as
|
|
2
|
-
import B, { useState as v, useRef as m, useCallback as
|
|
3
|
-
import { createPortal as
|
|
4
|
-
import { FOCUS_RING as
|
|
5
|
-
import { ensureOverlayStyles as
|
|
6
|
-
import { useTopLayer as
|
|
7
|
-
import { useFollowTrigger as
|
|
8
|
-
const
|
|
1
|
+
import { jsx as p, jsxs as J, Fragment as ut } from "react/jsx-runtime";
|
|
2
|
+
import B, { useState as v, useRef as m, useCallback as X, useId as mt, useEffect as w, useInsertionEffect as pt } from "react";
|
|
3
|
+
import { createPortal as ht } from "react-dom";
|
|
4
|
+
import { FOCUS_RING as gt } from "./focusRing.js";
|
|
5
|
+
import { ensureOverlayStyles as bt, overlayIdentity as yt } from "./portalOverlay.js";
|
|
6
|
+
import { useTopLayer as vt } from "./topLayer.js";
|
|
7
|
+
import { useFollowTrigger as wt } from "./useFollowTrigger.js";
|
|
8
|
+
const xt = new RegExp("(?<=[/\\\\.\\-_?&#=:@])"), Tt = (o) => o.split(xt).map((s, T) => /* @__PURE__ */ J(B.Fragment, { children: [
|
|
9
9
|
s,
|
|
10
10
|
/* @__PURE__ */ p("wbr", {})
|
|
11
|
-
] },
|
|
11
|
+
] }, T)), Rt = {
|
|
12
12
|
minWidth: 0,
|
|
13
13
|
overflow: "hidden"
|
|
14
|
-
},
|
|
14
|
+
}, D = {
|
|
15
15
|
flex: 1,
|
|
16
16
|
minWidth: 0
|
|
17
|
-
}, x = 8, It = '"Inter", ui-sans-serif, system-ui, sans-serif',
|
|
17
|
+
}, x = 8, It = '"Inter", ui-sans-serif, system-ui, sans-serif', Ot = ({
|
|
18
18
|
text: o,
|
|
19
19
|
children: s,
|
|
20
|
-
delay:
|
|
21
|
-
wrapChildren:
|
|
22
|
-
triggerAs:
|
|
20
|
+
delay: T = 0.2,
|
|
21
|
+
wrapChildren: Q = !1,
|
|
22
|
+
triggerAs: Z = "div",
|
|
23
23
|
inline: M = !1,
|
|
24
|
-
placement:
|
|
25
|
-
isShrinkable:
|
|
26
|
-
maxWidth:
|
|
24
|
+
placement: R = "top",
|
|
25
|
+
isShrinkable: O = !1,
|
|
26
|
+
maxWidth: I = "320px",
|
|
27
27
|
fill: S = !1,
|
|
28
28
|
shouldShow: h,
|
|
29
|
-
suppressed:
|
|
30
|
-
describesTrigger:
|
|
29
|
+
suppressed: r = !1,
|
|
30
|
+
describesTrigger: W = !0,
|
|
31
31
|
showOnFocus: f = !0,
|
|
32
32
|
focusableTrigger: g = !1
|
|
33
33
|
}) => {
|
|
34
|
-
const
|
|
34
|
+
const tt = O || S ? { ...O ? Rt : {}, ...S ? D : {} } : void 0, [e, d] = v(!1), [et, nt] = v(!1), b = et || g, y = m(null), a = m(null), n = X(() => {
|
|
35
35
|
y.current && (clearTimeout(y.current), y.current = null), a.current !== null && (cancelAnimationFrame(a.current), a.current = null);
|
|
36
|
-
}, []),
|
|
37
|
-
|
|
36
|
+
}, []), $ = () => {
|
|
37
|
+
nt(!0), a.current !== null && cancelAnimationFrame(a.current), a.current = requestAnimationFrame(() => {
|
|
38
38
|
a.current = null, d(!0);
|
|
39
39
|
});
|
|
40
|
-
},
|
|
41
|
-
|
|
42
|
-
const C =
|
|
43
|
-
t
|
|
44
|
-
|
|
45
|
-
},
|
|
46
|
-
},
|
|
47
|
-
t
|
|
40
|
+
}, E = m(null), u = m(null);
|
|
41
|
+
vt(E, e);
|
|
42
|
+
const C = mt(), l = o != null && o !== "" && o !== !1, N = (t) => !(t.relatedTarget instanceof Node && t.currentTarget.contains(t.relatedTarget)), ot = (t) => {
|
|
43
|
+
!N(t) || !l || r || h && !h() || (n(), y.current = setTimeout(() => {
|
|
44
|
+
$();
|
|
45
|
+
}, T * 1e3));
|
|
46
|
+
}, rt = (t) => {
|
|
47
|
+
N(t) && (n(), d(!1));
|
|
48
48
|
}, H = () => {
|
|
49
|
-
!f || !l ||
|
|
49
|
+
!f || !l || r || h && !h() || (n(), $());
|
|
50
50
|
}, it = () => {
|
|
51
51
|
n(), d(!1);
|
|
52
|
-
},
|
|
52
|
+
}, P = m(f);
|
|
53
53
|
w(() => {
|
|
54
|
-
var
|
|
55
|
-
const t = f && !
|
|
56
|
-
|
|
54
|
+
var i;
|
|
55
|
+
const t = f && !P.current;
|
|
56
|
+
P.current = f, t && ((i = u.current) != null && i.matches(":focus-within")) && H();
|
|
57
57
|
});
|
|
58
|
-
const [
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
}, [
|
|
62
|
-
const [,
|
|
58
|
+
const [st, at] = v(r);
|
|
59
|
+
r !== st && (at(r), r && d(!1)), w(() => {
|
|
60
|
+
r && n();
|
|
61
|
+
}, [r, n]);
|
|
62
|
+
const [, F] = v({}), lt = X(() => {
|
|
63
63
|
n(), d(!1);
|
|
64
64
|
}, [n]);
|
|
65
|
-
|
|
65
|
+
wt(e, u, () => F({}), lt), w(() => {
|
|
66
66
|
if (!e)
|
|
67
67
|
return () => {
|
|
68
68
|
n();
|
|
69
69
|
};
|
|
70
70
|
const t = () => {
|
|
71
|
-
|
|
71
|
+
F({});
|
|
72
72
|
};
|
|
73
73
|
return window.addEventListener("resize", t), () => {
|
|
74
74
|
n(), window.removeEventListener("resize", t);
|
|
75
75
|
};
|
|
76
76
|
}, [e, n]), w(() => {
|
|
77
|
-
e &&
|
|
77
|
+
e && F({});
|
|
78
78
|
}, [e]);
|
|
79
|
-
const
|
|
80
|
-
var
|
|
79
|
+
const ct = () => {
|
|
80
|
+
var U;
|
|
81
81
|
if (!u.current)
|
|
82
82
|
return { display: "none" };
|
|
83
|
-
const t = u.current.getBoundingClientRect(),
|
|
83
|
+
const t = u.current.getBoundingClientRect(), i = {
|
|
84
84
|
position: "fixed",
|
|
85
85
|
display: "flex",
|
|
86
86
|
width: "max-content",
|
|
87
|
-
maxWidth: typeof
|
|
87
|
+
maxWidth: typeof I == "number" ? `${I}px` : I,
|
|
88
88
|
minWidth: "32px",
|
|
89
89
|
minHeight: "32px",
|
|
90
90
|
padding: "8px 12px",
|
|
@@ -103,83 +103,83 @@ const wt = new RegExp("(?<=[/\\\\.\\-_?&#=:@])"), xt = (o) => o.split(wt).map((s
|
|
|
103
103
|
opacity: e ? 1 : 0,
|
|
104
104
|
visibility: e ? "visible" : "hidden",
|
|
105
105
|
transition: "opacity 150ms ease-in-out, transform 150ms ease-in-out, visibility 150ms ease-in-out"
|
|
106
|
-
}, c = (
|
|
106
|
+
}, c = (U = E.current) == null ? void 0 : U.getBoundingClientRect(), Y = (c == null ? void 0 : c.width) ?? 0, j = (c == null ? void 0 : c.height) ?? 0, A = () => {
|
|
107
107
|
const _ = t.left + t.width / 2;
|
|
108
|
-
if (
|
|
108
|
+
if (Y === 0)
|
|
109
109
|
return _;
|
|
110
|
-
const
|
|
111
|
-
return
|
|
112
|
-
},
|
|
113
|
-
switch (
|
|
110
|
+
const G = Y / 2, q = x + G, K = window.innerWidth - x - G;
|
|
111
|
+
return q > K ? _ : Math.min(Math.max(_, q), K);
|
|
112
|
+
}, k = t.top - 8 - j >= x, z = t.bottom + 8 + j <= window.innerHeight - x;
|
|
113
|
+
switch (R === "top" && !k && z ? "bottom" : R === "bottom" && !z && k ? "top" : R) {
|
|
114
114
|
case "top":
|
|
115
115
|
return {
|
|
116
|
-
...
|
|
116
|
+
...i,
|
|
117
117
|
top: t.top - 8,
|
|
118
118
|
left: A(),
|
|
119
119
|
transform: `translate(-50%, -100%) ${e ? "scale(1)" : "scale(0.95)"}`
|
|
120
120
|
};
|
|
121
121
|
case "bottom":
|
|
122
122
|
return {
|
|
123
|
-
...
|
|
123
|
+
...i,
|
|
124
124
|
top: t.bottom + 8,
|
|
125
125
|
left: A(),
|
|
126
126
|
transform: `translateX(-50%) ${e ? "scale(1)" : "scale(0.95)"}`
|
|
127
127
|
};
|
|
128
128
|
case "left":
|
|
129
129
|
return {
|
|
130
|
-
...
|
|
130
|
+
...i,
|
|
131
131
|
top: t.top + t.height / 2,
|
|
132
132
|
left: t.left - 8,
|
|
133
133
|
transform: `translate(-100%, -50%) ${e ? "scale(1)" : "scale(0.95)"}`
|
|
134
134
|
};
|
|
135
135
|
case "right":
|
|
136
136
|
return {
|
|
137
|
-
...
|
|
137
|
+
...i,
|
|
138
138
|
top: t.top + t.height / 2,
|
|
139
139
|
left: t.right + 8,
|
|
140
140
|
transform: `translateY(-50%) ${e ? "scale(1)" : "scale(0.95)"}`
|
|
141
141
|
};
|
|
142
142
|
default:
|
|
143
143
|
return {
|
|
144
|
-
...
|
|
144
|
+
...i,
|
|
145
145
|
top: t.top - 8,
|
|
146
146
|
left: A(),
|
|
147
147
|
transform: `translate(-50%, -100%) ${e ? "scale(1)" : "scale(0.95)"}`
|
|
148
148
|
};
|
|
149
149
|
}
|
|
150
|
-
},
|
|
151
|
-
|
|
152
|
-
l && b &&
|
|
150
|
+
}, L = l && b && W ? C : void 0;
|
|
151
|
+
pt(() => {
|
|
152
|
+
l && b && bt();
|
|
153
153
|
}, [l, b]);
|
|
154
|
-
const
|
|
155
|
-
"aria-describedby": [s.props["aria-describedby"],
|
|
156
|
-
}),
|
|
157
|
-
return /* @__PURE__ */
|
|
154
|
+
const ft = g ? s : Q || !B.isValidElement(s) ? /* @__PURE__ */ p("span", { "aria-describedby": L, style: S ? D : void 0, children: s }) : B.cloneElement(s, {
|
|
155
|
+
"aria-describedby": [s.props["aria-describedby"], L].filter(Boolean).join(" ") || void 0
|
|
156
|
+
}), dt = M ? "span" : Z, V = g && l && !r && f;
|
|
157
|
+
return /* @__PURE__ */ J(ut, { children: [
|
|
158
158
|
/* @__PURE__ */ p(
|
|
159
|
-
|
|
159
|
+
dt,
|
|
160
160
|
{
|
|
161
161
|
ref: u,
|
|
162
|
-
className: `relative ${M ? "inline-flex max-w-full align-middle" : "flex"} items-center${
|
|
163
|
-
style:
|
|
164
|
-
tabIndex:
|
|
165
|
-
"aria-describedby": g ?
|
|
166
|
-
|
|
167
|
-
|
|
162
|
+
className: `relative ${M ? "inline-flex max-w-full align-middle" : "flex"} items-center${V ? ` ${gt}` : ""}`,
|
|
163
|
+
style: tt,
|
|
164
|
+
tabIndex: V ? 0 : void 0,
|
|
165
|
+
"aria-describedby": g ? L : void 0,
|
|
166
|
+
onMouseOver: ot,
|
|
167
|
+
onMouseOut: rt,
|
|
168
168
|
onFocus: H,
|
|
169
169
|
onBlur: it,
|
|
170
|
-
children:
|
|
170
|
+
children: ft
|
|
171
171
|
}
|
|
172
172
|
),
|
|
173
|
-
l && b &&
|
|
173
|
+
l && b && ht(
|
|
174
174
|
/* @__PURE__ */ p(
|
|
175
175
|
"div",
|
|
176
176
|
{
|
|
177
|
-
ref:
|
|
177
|
+
ref: E,
|
|
178
178
|
id: C,
|
|
179
179
|
role: "tooltip",
|
|
180
|
-
"aria-hidden":
|
|
181
|
-
...
|
|
182
|
-
style:
|
|
180
|
+
"aria-hidden": W ? void 0 : !0,
|
|
181
|
+
...yt("tooltip"),
|
|
182
|
+
style: ct(),
|
|
183
183
|
children: /* @__PURE__ */ p(
|
|
184
184
|
"span",
|
|
185
185
|
{
|
|
@@ -187,7 +187,7 @@ const wt = new RegExp("(?<=[/\\\\.\\-_?&#=:@])"), xt = (o) => o.split(wt).map((s
|
|
|
187
187
|
minWidth: 0,
|
|
188
188
|
overflowWrap: "anywhere"
|
|
189
189
|
},
|
|
190
|
-
children: typeof o == "string" ?
|
|
190
|
+
children: typeof o == "string" ? Tt(o) : o
|
|
191
191
|
}
|
|
192
192
|
)
|
|
193
193
|
}
|
|
@@ -197,6 +197,6 @@ const wt = new RegExp("(?<=[/\\\\.\\-_?&#=:@])"), xt = (o) => o.split(wt).map((s
|
|
|
197
197
|
] });
|
|
198
198
|
};
|
|
199
199
|
export {
|
|
200
|
-
|
|
200
|
+
Ot as default
|
|
201
201
|
};
|
|
202
202
|
//# sourceMappingURL=Tooltip.js.map
|