@yuneta/gobj-ui 7.26.51 → 7.26.53
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/README.md +88 -2
- package/dist/gobj-ui.cjs.js +330 -71
- package/dist/gobj-ui.es.js +321 -63
- package/index.js +1 -0
- package/package.json +1 -1
- package/src/c_yui_form.js +48 -5
- package/src/c_yui_json.js +36 -3
- package/src/c_yui_treedb_topic_with_form.js +13 -28
- package/src/c_yui_uplot.js +51 -2
- package/src/fmt_date_time.test.js +138 -0
- package/src/form_table_rows.wiring.test.js +5 -4
- package/src/form_time_value.js +9 -6
- package/src/form_time_value.test.js +1 -1
- package/src/json_view_helpers.js +8 -3
- package/src/time_text.wiring.test.js +489 -0
- package/src/yui_date_text.js +82 -0
- package/src/yui_time.js +6 -22
- package/src/yui_uplot_time.js +142 -0
|
@@ -0,0 +1,142 @@
|
|
|
1
|
+
/***********************************************************************
|
|
2
|
+
* yui_uplot_time.js
|
|
3
|
+
*
|
|
4
|
+
* The texts uPlot writes for a moment -- the ticks of a time axis
|
|
5
|
+
* and the reading of the legend -- in the APP's language, with a
|
|
6
|
+
* clock of 24 hours, as every other time a gobj-ui view shows
|
|
7
|
+
* (fmt_date_time of yui_time.js).
|
|
8
|
+
*
|
|
9
|
+
* uPlot writes them from templates of its own, in English and
|
|
10
|
+
* 12 hours: "3pm", "3:05pm", "10/14" (month first), "Oct", and
|
|
11
|
+
* "2026-10-14 3:05pm" in the legend. Its `fmtDate` option takes
|
|
12
|
+
* the template and returns the function that writes a Date with
|
|
13
|
+
* it; this one is given to it:
|
|
14
|
+
*
|
|
15
|
+
* legend "{YYYY}-{MM}-{DD} {h}:{mm}{aa}" -> fmt_date_time()
|
|
16
|
+
* "14 oct 2026, 15:05:09"
|
|
17
|
+
* "{h}{aa}" "3pm" -> "15:00"
|
|
18
|
+
* "{h}:{mm}{aa}" "3:05pm" -> "15:05"
|
|
19
|
+
* "{M}/{D}" "10/14" -> es "14/10", en "10/14"
|
|
20
|
+
* "{M}/{D}/{YY}" "10/14/26"-> es "14/10/26", en "10/14/26"
|
|
21
|
+
* "{MMM}" "Oct" -> es "oct", en "Oct"
|
|
22
|
+
*
|
|
23
|
+
* The language is asked for on every call, so a redraw after a
|
|
24
|
+
* language change writes the new one (C_YUI_UPLOT redraws its
|
|
25
|
+
* axes on EV_LANGUAGE_CHANGED).
|
|
26
|
+
*
|
|
27
|
+
* Copyright (c) 2026, ArtGins.
|
|
28
|
+
* All Rights Reserved.
|
|
29
|
+
***********************************************************************/
|
|
30
|
+
import {fmt_date_time, safe_locale} from "./yui_date_text.js";
|
|
31
|
+
|
|
32
|
+
/* The legend's stamp, as uPlot 1.6 writes it (_timeSeriesStamp). */
|
|
33
|
+
const LEGEND_STAMP = "{YYYY}-{MM}-{DD} {h}:{mm}{aa}";
|
|
34
|
+
|
|
35
|
+
const pad2 = (n) => String(n).padStart(2, "0");
|
|
36
|
+
|
|
37
|
+
/* Intl formatters by locale and options: a redraw writes a dozen
|
|
38
|
+
* ticks, and a formatter is not cheap to build. */
|
|
39
|
+
const __formatters__ = new Map();
|
|
40
|
+
|
|
41
|
+
function intl(locale, opts)
|
|
42
|
+
{
|
|
43
|
+
let key = locale + "|" + JSON.stringify(opts);
|
|
44
|
+
let f = __formatters__.get(key);
|
|
45
|
+
if(!f) {
|
|
46
|
+
try {
|
|
47
|
+
f = new Intl.DateTimeFormat(locale, opts);
|
|
48
|
+
} catch(e) {
|
|
49
|
+
f = new Intl.DateTimeFormat("en", opts);
|
|
50
|
+
}
|
|
51
|
+
__formatters__.set(key, f);
|
|
52
|
+
}
|
|
53
|
+
return f;
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
/* A template fragment that has no word for a language is rewritten
|
|
57
|
+
* whole: the order of day and month is the language's. */
|
|
58
|
+
const WHOLE = [
|
|
59
|
+
["{M}/{D}/{YY}", (d, loc) => intl(loc, {day: "numeric", month: "numeric", year: "2-digit"}).format(d)],
|
|
60
|
+
["{M}/{D}", (d, loc) => intl(loc, {day: "numeric", month: "numeric"}).format(d)],
|
|
61
|
+
["{h}{aa}", (d) => `${pad2(d.getHours())}:00`],
|
|
62
|
+
];
|
|
63
|
+
|
|
64
|
+
const TOKENS = {
|
|
65
|
+
YYYY: (d) => String(d.getFullYear()),
|
|
66
|
+
YY: (d) => String(d.getFullYear()).slice(2),
|
|
67
|
+
MMMM: (d, loc) => intl(loc, {month: "long"}).format(d),
|
|
68
|
+
MMM: (d, loc) => intl(loc, {month: "short"}).format(d),
|
|
69
|
+
MM: (d) => pad2(d.getMonth() + 1),
|
|
70
|
+
M: (d) => String(d.getMonth() + 1),
|
|
71
|
+
DD: (d) => pad2(d.getDate()),
|
|
72
|
+
D: (d) => String(d.getDate()),
|
|
73
|
+
WWWW: (d, loc) => intl(loc, {weekday: "long"}).format(d),
|
|
74
|
+
WWW: (d, loc) => intl(loc, {weekday: "short"}).format(d),
|
|
75
|
+
HH: (d) => pad2(d.getHours()),
|
|
76
|
+
H: (d) => String(d.getHours()),
|
|
77
|
+
hh: (d) => pad2(d.getHours()),
|
|
78
|
+
h: (d) => pad2(d.getHours()),
|
|
79
|
+
AA: () => "",
|
|
80
|
+
aa: () => "",
|
|
81
|
+
a: () => "",
|
|
82
|
+
mm: (d) => pad2(d.getMinutes()),
|
|
83
|
+
m: (d) => String(d.getMinutes()),
|
|
84
|
+
ss: (d) => pad2(d.getSeconds()),
|
|
85
|
+
s: (d) => String(d.getSeconds()),
|
|
86
|
+
fff: (d) => String(d.getMilliseconds()).padStart(3, "0"),
|
|
87
|
+
};
|
|
88
|
+
|
|
89
|
+
/***************************************************************
|
|
90
|
+
* A template -> its parts: literal text, or a function of
|
|
91
|
+
* (date, locale).
|
|
92
|
+
***************************************************************/
|
|
93
|
+
function template_parts(tpl)
|
|
94
|
+
{
|
|
95
|
+
let parts = [];
|
|
96
|
+
let rest = String(tpl);
|
|
97
|
+
while(rest.length > 0) {
|
|
98
|
+
let whole = WHOLE.find(([frag]) => rest.startsWith(frag));
|
|
99
|
+
if(whole) {
|
|
100
|
+
parts.push(whole[1]);
|
|
101
|
+
rest = rest.slice(whole[0].length);
|
|
102
|
+
continue;
|
|
103
|
+
}
|
|
104
|
+
let m = /^\{([a-z]+)\}/i.exec(rest);
|
|
105
|
+
if(m && TOKENS[m[1]]) {
|
|
106
|
+
parts.push(TOKENS[m[1]]);
|
|
107
|
+
rest = rest.slice(m[0].length);
|
|
108
|
+
continue;
|
|
109
|
+
}
|
|
110
|
+
let next = rest.indexOf("{", 1);
|
|
111
|
+
let text = (next < 0)? rest : rest.slice(0, next);
|
|
112
|
+
parts.push(text);
|
|
113
|
+
rest = rest.slice(text.length);
|
|
114
|
+
}
|
|
115
|
+
return parts;
|
|
116
|
+
}
|
|
117
|
+
|
|
118
|
+
/***************************************************************
|
|
119
|
+
* uPlot's `fmtDate` option. `get_locale` answers the app's
|
|
120
|
+
* language at the moment of the call (the views pass
|
|
121
|
+
* `() => i18next.language`).
|
|
122
|
+
***************************************************************/
|
|
123
|
+
function yui_uplot_fmt_date(get_locale)
|
|
124
|
+
{
|
|
125
|
+
let locale = () => safe_locale(typeof get_locale === "function"? get_locale() : null);
|
|
126
|
+
return function(tpl) {
|
|
127
|
+
if(tpl === LEGEND_STAMP) {
|
|
128
|
+
return (date) => fmt_date_time(date, locale());
|
|
129
|
+
}
|
|
130
|
+
let parts = template_parts(tpl);
|
|
131
|
+
return function(date) {
|
|
132
|
+
let loc = locale();
|
|
133
|
+
let out = "";
|
|
134
|
+
for(let part of parts) {
|
|
135
|
+
out += (typeof part === "string")? part : part(date, loc);
|
|
136
|
+
}
|
|
137
|
+
return out;
|
|
138
|
+
};
|
|
139
|
+
};
|
|
140
|
+
}
|
|
141
|
+
|
|
142
|
+
export {yui_uplot_fmt_date};
|