@sincpro/web-ui 1.11.1 → 2.1.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/components/activity/Activity.d.ts +13 -14
- package/dist/components/activity/Activity.js +1 -1
- package/dist/components/activity/Messages.d.ts +5 -5
- package/dist/components/activity/Messages.js +8 -8
- package/dist/components/form/Form.js +6 -6
- package/dist/components/form/index.js +2 -2
- package/dist/components/frame/FrameView.d.ts +5 -5
- package/dist/components/frame/FrameView.js +4 -4
- package/dist/components/listing/GroupingLevels.d.ts +22 -22
- package/dist/components/listing/GroupingLevels.js +9 -9
- package/dist/components/listing/Listing.d.ts +11 -11
- package/dist/components/listing/Listing.js +11 -11
- package/dist/components/listing/ListingBar.js +11 -11
- package/dist/components/listing/Row.d.ts +19 -19
- package/dist/components/listing/Row.js +25 -25
- package/dist/components/listing/SortMenu.d.ts +36 -36
- package/dist/components/listing/SortMenu.js +6 -6
- package/dist/components/listing/grouping.d.ts +16 -16
- package/dist/components/listing/grouping.js +6 -6
- package/dist/components/listing/index.js +1 -1
- package/dist/components/listing/modelColumns.d.ts +25 -25
- package/dist/components/listing/modelColumns.js +24 -24
- package/dist/components/listing/pages.js +4 -4
- package/dist/components/listing/set.d.ts +18 -18
- package/dist/components/navigation/index.js +2 -2
- package/dist/components/record/RecordSkeleton.js +7 -7
- package/dist/components/search/CriteriaBuilder.d.ts +35 -22
- package/dist/components/search/CriteriaBuilder.js +95 -85
- package/dist/components/search/CriteriaChips.d.ts +9 -9
- package/dist/components/search/CriteriaChips.js +13 -13
- package/dist/components/search/FilterBuilder.d.ts +72 -71
- package/dist/components/search/FilterBuilder.js +190 -145
- package/dist/components/search/JoinWord.d.ts +1 -1
- package/dist/components/search/JoinWord.js +14 -14
- package/dist/components/search/JsonEditor.d.ts +8 -8
- package/dist/components/search/JsonEditor.js +21 -18
- package/dist/components/search/SearchBar.d.ts +34 -34
- package/dist/components/search/SearchBar.js +113 -113
- package/dist/components/search/criteria.d.ts +86 -74
- package/dist/components/search/criteria.js +44 -43
- package/dist/components/search/datePeriods.d.ts +47 -48
- package/dist/components/search/datePeriods.js +29 -29
- package/dist/components/search/dateRanges.d.ts +27 -27
- package/dist/components/search/dateRanges.js +16 -16
- package/dist/components/search/index.d.ts +2 -2
- package/dist/components/search/index.js +14 -14
- package/dist/components/search/model.d.ts +28 -28
- package/dist/components/search/model.js +21 -21
- package/dist/components/search/query.d.ts +71 -71
- package/dist/components/search/query.js +119 -119
- package/dist/components/shell/AppFrame.js +3 -3
- package/dist/components/shell/index.js +1 -1
- package/dist/foundations/calendar.d.ts +27 -27
- package/dist/foundations/calendar.js +72 -72
- package/dist/foundations/chart.d.ts +57 -57
- package/dist/foundations/chart.js +27 -27
- package/dist/foundations/copy.d.ts +104 -94
- package/dist/foundations/copy.es.js +6 -1
- package/dist/foundations/copy.js +6 -1
- package/dist/foundations/grouping.d.ts +175 -175
- package/dist/foundations/grouping.js +0 -0
- package/dist/foundations/index.d.ts +1 -1
- package/dist/foundations/index.js +21 -21
- package/dist/foundations/pivot.d.ts +133 -131
- package/dist/foundations/pivot.js +54 -54
- package/dist/foundations/pivotSheet.d.ts +36 -36
- package/dist/foundations/pivotSheet.js +0 -0
- package/dist/foundations/slots.d.ts +38 -38
- package/dist/foundations/slots.js +18 -18
- package/dist/foundations/sticky.d.ts +28 -28
- package/dist/foundations/sticky.js +59 -59
- package/dist/foundations/xlsx.d.ts +47 -47
- package/dist/foundations/xlsx.js +0 -0
- package/dist/primitives/block/Line.d.ts +4 -4
- package/dist/primitives/block/Line.js +28 -28
- package/dist/primitives/block/index.js +2 -2
- package/dist/primitives/cell/index.js +2 -2
- package/dist/primitives/choice/index.js +3 -3
- package/dist/primitives/date/Calendar.d.ts +7 -1
- package/dist/primitives/date/Calendar.js +13 -3
- package/dist/primitives/date/DatePicker.d.ts +4 -1
- package/dist/primitives/date/DatePicker.js +2 -2
- package/dist/primitives/date/index.js +3 -3
- package/dist/primitives/disclosure/index.js +1 -1
- package/dist/primitives/menu/Menu.d.ts +3 -3
- package/dist/primitives/notice/Callout.d.ts +30 -30
- package/dist/primitives/notice/Callout.js +6 -6
- package/dist/primitives/overlay/index.js +3 -3
- package/dist/primitives/picker/Picker.d.ts +6 -0
- package/dist/primitives/picker/Picker.js +27 -4
- package/dist/primitives/picker/index.js +2 -2
- package/dist/primitives/table/DataTable.d.ts +32 -32
- package/dist/primitives/table/DataTable.js +24 -24
- package/dist/primitives/table/EditableTable.d.ts +10 -10
- package/dist/primitives/table/EditableTable.js +9 -9
- package/dist/primitives/table/ReportTable.js +7 -7
- package/dist/primitives/table/SheetTable.d.ts +13 -13
- package/dist/primitives/table/SheetTable.js +14 -14
- package/dist/primitives/table/Table.js +8 -8
- package/dist/primitives/tabs/Tabs.d.ts +46 -46
- package/dist/primitives/tabs/Tabs.js +7 -7
- package/dist/primitives/tag/index.js +2 -2
- package/dist/primitives/toolbar/index.js +1 -1
- package/dist/primitives/value/Copyable.d.ts +22 -22
- package/dist/primitives/value/Copyable.js +9 -9
- package/dist/tokens.css +17 -17
- package/dist/views/list/List.d.ts +36 -36
- package/dist/views/list/List.js +19 -19
- package/dist/views/list/ListView.js +74 -74
- package/dist/views/list/columns.d.ts +10 -10
- package/dist/views/list/columns.js +10 -10
- package/dist/views/list/derive.d.ts +30 -30
- package/dist/views/list/derive.js +49 -49
- package/dist/views/list/index.js +2 -2
- package/dist/views/list/presentations.js +3 -3
- package/dist/views/list/types.d.ts +109 -109
- package/dist/views/record/Record.d.ts +14 -14
- package/dist/views/record/Record.js +24 -24
- package/dist/views/record/index.js +1 -1
- package/package.json +1 -1
|
@@ -1,49 +1,49 @@
|
|
|
1
1
|
import { currentCopy, currentCopyLocale, fillCopy } from "./copy.js";
|
|
2
2
|
/**
|
|
3
|
-
*
|
|
3
|
+
* THE CALENDAR: from a date to a KEY, and from a key to a LABEL.
|
|
4
4
|
*
|
|
5
|
-
* Context:
|
|
6
|
-
*
|
|
7
|
-
*
|
|
8
|
-
*
|
|
9
|
-
*
|
|
10
|
-
*
|
|
5
|
+
* Context: a date bucket has two texts and they are not the same. «2026-09» is
|
|
6
|
+
* what the engine writes —what identifies the bucket, what is compared with what
|
|
7
|
+
* the server counted, what is stored folded— and «Septiembre» is what is
|
|
8
|
+
* read. Writing only one forces a choice of which one is lost: with the key in view
|
|
9
|
+
* the interface speaks machine, and with the label as identity two Septembers of
|
|
10
|
+
* different years melt into a bucket that does not exist.
|
|
11
11
|
*
|
|
12
|
-
*
|
|
12
|
+
* That is why there are two functions and not one:
|
|
13
13
|
*
|
|
14
|
-
* dateKey(when, "month") → «2026-09»
|
|
15
|
-
* dateLabel("2026-09", …) → «Septiembre»
|
|
14
|
+
* dateKey(when, "month") → «2026-09» the identity, in a single language
|
|
15
|
+
* dateLabel("2026-09", …) → «Septiembre» the label, in the active language
|
|
16
16
|
*
|
|
17
|
-
* ──
|
|
17
|
+
* ── The language is not translated: it is ASKED for ─────────────────
|
|
18
18
|
*
|
|
19
|
-
*
|
|
20
|
-
*
|
|
21
|
-
*
|
|
22
|
-
*
|
|
23
|
-
*
|
|
19
|
+
* The months and the days of the week are said by `Intl` with the `locale` the copy
|
|
20
|
+
* has set, so there is no table of twelve months here, in Spanish or in
|
|
21
|
+
* English — nor would one have to be written for a third language. The only things that
|
|
22
|
+
* are copy are the week and the quarter, because no calendar names them: «W38»
|
|
23
|
+
* is not a word and `Intl` does not have it.
|
|
24
24
|
*
|
|
25
|
-
* ──
|
|
25
|
+
* ── A label says what the one above did NOT say ─────────────────────
|
|
26
26
|
*
|
|
27
|
-
*
|
|
28
|
-
*
|
|
29
|
-
*
|
|
27
|
+
* A tree of dates is read from top to bottom, and repeating the year in every month
|
|
28
|
+
* and the month in every day fills the indentation with text that is already two lines
|
|
29
|
+
* above:
|
|
30
30
|
*
|
|
31
|
-
* 2026 ←
|
|
32
|
-
* Septiembre ←
|
|
33
|
-
* Semana 38 ←
|
|
34
|
-
* Martes ←
|
|
31
|
+
* 2026 ← the year is said once
|
|
32
|
+
* Septiembre ← not «Septiembre de 2026»
|
|
33
|
+
* Semana 38 ← not «Semana 38 de 2026»
|
|
34
|
+
* Martes ← not «martes, 15 sept 2026»
|
|
35
35
|
*
|
|
36
|
-
*
|
|
37
|
-
*
|
|
38
|
-
*
|
|
36
|
+
* `within` takes care of that: the grains that the buckets above —of the same
|
|
37
|
+
* field— already said. With nobody above, the label stands alone and says the whole
|
|
38
|
+
* date, because a bare «Martes» is not a day.
|
|
39
39
|
*/
|
|
40
40
|
/**
|
|
41
|
-
*
|
|
42
|
-
*
|
|
41
|
+
* The shape of each grain's key. It is the whole `GroupGrain`: a grain the
|
|
42
|
+
* calendar could not cut would be a level that splits nothing.
|
|
43
43
|
*
|
|
44
|
-
*
|
|
45
|
-
*
|
|
46
|
-
*
|
|
44
|
+
* The ranges go in the expression and not in an `if` because `new Date(2026, 12, 1)`
|
|
45
|
+
* does not fail: it rolls over to January 2027. A key «2026-13» drawn as «Enero»
|
|
46
|
+
* is a month nobody counted, and that is worse than an unreadable label.
|
|
47
47
|
*/
|
|
48
48
|
const KEY_SHAPES = {
|
|
49
49
|
year: /^(\d{4})$/,
|
|
@@ -53,13 +53,13 @@ const KEY_SHAPES = {
|
|
|
53
53
|
day: /^(\d{4})-(0[1-9]|1[0-2])-(0[1-9]|[12]\d|3[01])$/,
|
|
54
54
|
};
|
|
55
55
|
/**
|
|
56
|
-
*
|
|
56
|
+
* A date cut down to the KEY of its grain.
|
|
57
57
|
*
|
|
58
|
-
*
|
|
59
|
-
* «2026-09-15»—,
|
|
60
|
-
*
|
|
61
|
-
*
|
|
62
|
-
*
|
|
58
|
+
* The text is the one the engine produces —«2026», «2026-Q3», «2026-09», «2026-W38»,
|
|
59
|
+
* «2026-09-15»—, and both sides writing it the same is what lets a grouping
|
|
60
|
+
* made in the browser be compared with one counted a thousand kilometres away. Without a date
|
|
61
|
+
* the key is empty: a bucket that exists —the one for those that have none— and that is
|
|
62
|
+
* drawn with the words of the copy.
|
|
63
63
|
*/
|
|
64
64
|
export function dateKey(when, grain) {
|
|
65
65
|
if (when === null || when === undefined || when === "")
|
|
@@ -90,13 +90,13 @@ export function dateKey(when, grain) {
|
|
|
90
90
|
return `${year}-${pad(month)}-${pad(date.getDate())}`;
|
|
91
91
|
}
|
|
92
92
|
/**
|
|
93
|
-
*
|
|
93
|
+
* The LABEL of a date key, in the active language.
|
|
94
94
|
*
|
|
95
|
-
* `within`
|
|
96
|
-
*
|
|
97
|
-
*
|
|
98
|
-
*
|
|
99
|
-
*
|
|
95
|
+
* `within` are the grains the buckets above already said: with the year
|
|
96
|
+
* above, a month is «Septiembre» and not «Septiembre de 2026». A key that does not
|
|
97
|
+
* have the shape of its grain is drawn AS IS —that is what keeps a bucket
|
|
98
|
+
* counted elsewhere, with a key this layer did not write, readable
|
|
99
|
+
* instead of vanishing behind an invented date.
|
|
100
100
|
*/
|
|
101
101
|
export function dateLabel(key, grain, within = []) {
|
|
102
102
|
const copy = currentCopy();
|
|
@@ -118,8 +118,8 @@ export function dateLabel(key, grain, within = []) {
|
|
|
118
118
|
}
|
|
119
119
|
if (grain === "week") {
|
|
120
120
|
const week = Number(parts[2]);
|
|
121
|
-
/*
|
|
122
|
-
|
|
121
|
+
/* The month is enough too: a week inside September already knows which
|
|
122
|
+
year it is, because the month said so. */
|
|
123
123
|
return said("year") || said("quarter") || said("month")
|
|
124
124
|
? fillCopy(copy.calendar.week, { n: week })
|
|
125
125
|
: fillCopy(copy.calendar.weekOfYear, { n: week, year });
|
|
@@ -132,13 +132,13 @@ export function dateLabel(key, grain, within = []) {
|
|
|
132
132
|
}
|
|
133
133
|
const day = Number(parts[3]);
|
|
134
134
|
const when = new Date(year, Number(parts[2]) - 1, day);
|
|
135
|
-
/*
|
|
136
|
-
|
|
135
|
+
/* 31 February has the shape of a day and is none: `Date` rolls it over
|
|
136
|
+
to 3 March instead of complaining, so we ask whether the same day came back. */
|
|
137
137
|
if (when.getDate() !== day)
|
|
138
138
|
return key;
|
|
139
|
-
/*
|
|
140
|
-
|
|
141
|
-
«Martes»
|
|
139
|
+
/* Inside a week, the day is its NAME: there are seven and none repeats,
|
|
140
|
+
so «Martes» is enough and the day number would be noise. Outside it is not: a bare
|
|
141
|
+
«Martes» does not say which of the fifty-two. */
|
|
142
142
|
if (said("week"))
|
|
143
143
|
return capitalized(format(locale, { weekday: "long" }).format(when));
|
|
144
144
|
return capitalized(format(locale, {
|
|
@@ -149,9 +149,9 @@ export function dateLabel(key, grain, within = []) {
|
|
|
149
149
|
}).format(when));
|
|
150
150
|
}
|
|
151
151
|
/**
|
|
152
|
-
*
|
|
153
|
-
* «2026-W52» →
|
|
154
|
-
*
|
|
152
|
+
* The NEXT key in the same grain: «2026-09» → «2026-10», «2026-Q4» → «2027-Q1»,
|
|
153
|
+
* «2026-W52» → the ISO week that follows. `null` if the key does not have the shape of its grain —
|
|
154
|
+
* one counted elsewhere, which this layer did not write and so cannot continue.
|
|
155
155
|
*/
|
|
156
156
|
export function nextDateKey(key, grain) {
|
|
157
157
|
const parts = KEY_SHAPES[grain].exec(key);
|
|
@@ -179,12 +179,12 @@ export function nextDateKey(key, grain) {
|
|
|
179
179
|
return dateKey(date, "day");
|
|
180
180
|
}
|
|
181
181
|
/**
|
|
182
|
-
*
|
|
182
|
+
* All the keys of a grain between two, both included: the whole time AXIS.
|
|
183
183
|
*
|
|
184
|
-
*
|
|
185
|
-
*
|
|
186
|
-
*
|
|
187
|
-
*
|
|
184
|
+
* An axis that skips the month where nothing happened lies about time —August stuck to
|
|
185
|
+
* October reads as one month— and that gap is often exactly what someone is looking for. `null` if
|
|
186
|
+
* some key cannot be continued or if there would be more than `max`: an axis by day over ten years
|
|
187
|
+
* is not a chart.
|
|
188
188
|
*/
|
|
189
189
|
export function dateKeysBetween(first, last, grain, max = 1000) {
|
|
190
190
|
const out = [first];
|
|
@@ -198,24 +198,24 @@ export function dateKeysBetween(first, last, grain, max = 1000) {
|
|
|
198
198
|
}
|
|
199
199
|
return key === last ? out : null;
|
|
200
200
|
}
|
|
201
|
-
/**
|
|
202
|
-
*
|
|
201
|
+
/** The name of a month —1 to 12— in the active language. Used by whoever offers months
|
|
202
|
+
* without holding any date, like the cut by period. */
|
|
203
203
|
export function monthName(month) {
|
|
204
204
|
return capitalized(format(currentCopyLocale(), { month: "long" }).format(new Date(2000, month - 1, 1)));
|
|
205
205
|
}
|
|
206
|
-
/**
|
|
207
|
-
*
|
|
208
|
-
*
|
|
206
|
+
/** What a GRAIN is called —«día», «semana»—, which is different from what a bucket
|
|
207
|
+
* of it is called: the grain names the cut and the label names what was cut. It comes from
|
|
208
|
+
* the copy, which is where the time units in the singular already live. */
|
|
209
209
|
export function grainName(grain) {
|
|
210
210
|
return capitalized(currentCopy().dates[grain]);
|
|
211
211
|
}
|
|
212
212
|
/**
|
|
213
|
-
*
|
|
213
|
+
* The ISO year and week of a date.
|
|
214
214
|
*
|
|
215
|
-
*
|
|
216
|
-
*
|
|
217
|
-
*
|
|
218
|
-
*
|
|
215
|
+
* Week 1 is the one holding the first Thursday of the year, so it is computed with
|
|
216
|
+
* the Thursday of the datum's week: it decides which year it belongs to, and that is
|
|
217
|
+
* why a week at the end of December can be week 1 of the next year. The year
|
|
218
|
+
* that comes out of here is that of THAT week and not that of the date.
|
|
219
219
|
*/
|
|
220
220
|
function isoWeek(date) {
|
|
221
221
|
const thursday = new Date(date.getFullYear(), date.getMonth(), date.getDate());
|
|
@@ -229,9 +229,9 @@ function isoWeek(date) {
|
|
|
229
229
|
function format(locale, options) {
|
|
230
230
|
return new Intl.DateTimeFormat(locale, options);
|
|
231
231
|
}
|
|
232
|
-
/**
|
|
233
|
-
*
|
|
234
|
-
*
|
|
232
|
+
/** A label heads a bucket, and in Spanish `Intl` returns «septiembre» in
|
|
233
|
+
* lowercase. The first letter is raised with the active language, which is the one that knows
|
|
234
|
+
* what the capital of that letter is. */
|
|
235
235
|
function capitalized(text) {
|
|
236
236
|
const first = text.charAt(0);
|
|
237
237
|
return first === "" ? text : first.toLocaleUpperCase(currentCopyLocale()) + text.slice(1);
|
|
@@ -1,46 +1,46 @@
|
|
|
1
1
|
import { type Pivot, type PivotKey } from "./pivot.js";
|
|
2
2
|
/**
|
|
3
|
-
*
|
|
3
|
+
* THE CHART: a pivot read as marks.
|
|
4
4
|
*
|
|
5
|
-
* Context:
|
|
6
|
-
*
|
|
7
|
-
* series),
|
|
8
|
-
*
|
|
9
|
-
* (`pivotFrom`),
|
|
10
|
-
*
|
|
11
|
-
* a
|
|
5
|
+
* Context: an ERP chart —Odoo's, anyone's— answers the same question
|
|
6
|
+
* as a pivot: the set split by one field (the axis), sometimes by another (the
|
|
7
|
+
* series), and at each crossing a folded number. That is why this brings NO other way to fold:
|
|
8
|
+
* it reads a `Pivot`. And since a `Pivot` is built the same by whoever holds the records in hand
|
|
9
|
+
* (`pivotFrom`), whoever folded it on the server (`pivotOf`) or whoever built it from the cells
|
|
10
|
+
* of a file, the same chart serves records, a dataset and what is grouped
|
|
11
|
+
* a thousand kilometres away. A dictionary or a `SeriesBar[]` come in through the two helpers below.
|
|
12
12
|
*
|
|
13
|
-
* ──
|
|
13
|
+
* ── The pivot's rows are the AXIS; its columns, the SERIES ──────────
|
|
14
14
|
*
|
|
15
|
-
*
|
|
15
|
+
* As in Odoo: the first grouping goes below and the second is stacked or set beside it.
|
|
16
16
|
*
|
|
17
|
-
* ──
|
|
17
|
+
* ── Three rules that come from the pivot, and still hold ────────────
|
|
18
18
|
*
|
|
19
|
-
* 1. **
|
|
20
|
-
*
|
|
21
|
-
* 2. **
|
|
22
|
-
*
|
|
23
|
-
*
|
|
24
|
-
* 3. **
|
|
25
|
-
*
|
|
19
|
+
* 1. **A hole is not a zero.** `null` is «there are no rows there»: the bar is not drawn and
|
|
20
|
+
* the line breaks. A zero is a bar flush with the axis.
|
|
21
|
+
* 2. **Sums are not invented.** Gathering the tail into «otros» or accumulating a line is summing, and
|
|
22
|
+
* it is only done if the measure sums (`additive`; the count always). Otherwise the tail is
|
|
23
|
+
* left out and SAID (`hiddenSeries`): an average of averages is not an average.
|
|
24
|
+
* 3. **Colour follows the series, not its position.** The remaining series keep the
|
|
25
|
+
* pivot's order; sorting by size sorts the AXIS, never repaints.
|
|
26
26
|
*/
|
|
27
27
|
export type ChartKind = "bar" | "line" | "pie";
|
|
28
28
|
export type ChartOrder = "asc" | "desc";
|
|
29
|
-
/**
|
|
30
|
-
*
|
|
29
|
+
/** The row count of each crossing, offered as one more measure: it is the only one that
|
|
30
|
+
* can always be answered. */
|
|
31
31
|
export declare const COUNT_MEASURE = "__count";
|
|
32
|
-
/**
|
|
33
|
-
*
|
|
32
|
+
/** How many series are told apart by colour. It is the palette's length (`--color-series-*`):
|
|
33
|
+
* a ninth series would be a generated colour, and under colour blindness that one gets confused with another. */
|
|
34
34
|
export declare const SERIES_COLORS = 8;
|
|
35
|
-
/**
|
|
35
|
+
/** A key of a chart axis: its path in the pivot and how it reads. */
|
|
36
36
|
export type ChartPoint = {
|
|
37
37
|
key: PivotKey;
|
|
38
|
-
/** `pathKey(key)`:
|
|
38
|
+
/** `pathKey(key)`: the stable identity for React and for colour. */
|
|
39
39
|
id: string;
|
|
40
40
|
label: string;
|
|
41
|
-
/**
|
|
41
|
+
/** The tail gathered into one: «otros (12)». Drawn quieter and does not open. */
|
|
42
42
|
rest?: boolean;
|
|
43
|
-
/**
|
|
43
|
+
/** The previous period of a comparison: drawn quiet, behind the current one. */
|
|
44
44
|
previous?: boolean;
|
|
45
45
|
};
|
|
46
46
|
export type ChartMeasure = {
|
|
@@ -52,72 +52,72 @@ export type ChartMeasure = {
|
|
|
52
52
|
export type ChartData = {
|
|
53
53
|
categories: readonly ChartPoint[];
|
|
54
54
|
series: readonly ChartPoint[];
|
|
55
|
-
/** `values[
|
|
55
|
+
/** `values[category][series]`; `null` is a hole. */
|
|
56
56
|
values: readonly (readonly (number | null)[])[];
|
|
57
|
-
/**
|
|
58
|
-
*
|
|
57
|
+
/** What each whole category gives, folded from the base when the pivot brings it. It is what
|
|
58
|
+
* a pie measures and what orders the axis. */
|
|
59
59
|
totals: readonly (number | null)[];
|
|
60
60
|
measure: ChartMeasure;
|
|
61
|
-
/**
|
|
61
|
+
/** What the cuts are called: «sucursal», «año · forma de pago». */
|
|
62
62
|
categoryTitle: string;
|
|
63
63
|
seriesTitle: string;
|
|
64
|
-
/** Series
|
|
64
|
+
/** Series that did not make it and could not be gathered into «otros» (the measure does not sum). */
|
|
65
65
|
hiddenSeries: number;
|
|
66
|
-
/**
|
|
66
|
+
/** The same, for the categories a pie cannot show. */
|
|
67
67
|
hiddenCategories: number;
|
|
68
|
-
/**
|
|
68
|
+
/** The two series are the current and the previous period (`chartCompare`). */
|
|
69
69
|
compare?: boolean;
|
|
70
70
|
};
|
|
71
71
|
export type ChartReading = {
|
|
72
|
-
/**
|
|
72
|
+
/** The measure's id, or `COUNT_MEASURE`. By default the pivot's first. */
|
|
73
73
|
measure?: string;
|
|
74
|
-
/**
|
|
74
|
+
/** Sorts the AXIS by what each category gives. Without this, the order of its keys. */
|
|
75
75
|
order?: ChartOrder;
|
|
76
|
-
/**
|
|
76
|
+
/** Each point adds the previous ones: «how much we have so far». Only with a measure that sums. */
|
|
77
77
|
cumulative?: boolean;
|
|
78
|
-
/**
|
|
78
|
+
/** More series than this are gathered into «otros». By default, the palette's colours. */
|
|
79
79
|
maxSeries?: number;
|
|
80
|
-
/**
|
|
80
|
+
/** More categories than this are gathered into «otros». A pie asks for six. */
|
|
81
81
|
maxCategories?: number;
|
|
82
82
|
/**
|
|
83
|
-
*
|
|
84
|
-
*
|
|
85
|
-
*
|
|
83
|
+
* With a single DATE level on the axis, fills in the periods where nothing happened:
|
|
84
|
+
* August is not left stuck to October. The count of an empty period is 0; any other
|
|
85
|
+
* measure is a hole (`null`), like any crossing without rows. On by default.
|
|
86
86
|
*/
|
|
87
87
|
fillDates?: boolean;
|
|
88
88
|
};
|
|
89
|
-
/**
|
|
89
|
+
/** The measures that can be charted from a pivot: the count and its own. */
|
|
90
90
|
export declare function chartMeasures(pivot: Pivot): ChartMeasure[];
|
|
91
91
|
/**
|
|
92
|
-
*
|
|
93
|
-
*
|
|
92
|
+
* The pivot as a chart: the rows are the axis, the columns the series, and at each crossing
|
|
93
|
+
* the number of the chosen measure.
|
|
94
94
|
*/
|
|
95
95
|
export declare function chartFromPivot(pivot: Pivot, reading?: ChartReading): ChartData;
|
|
96
96
|
/**
|
|
97
|
-
*
|
|
98
|
-
* («otros»)
|
|
99
|
-
*
|
|
97
|
+
* Sorts the AXIS of an already built chart by what each category gives. The gathered tail
|
|
98
|
+
* («otros») stays last. It is the same as `order` in `chartFromPivot`, for a chart
|
|
99
|
+
* that was built another way —a comparison, a dictionary—.
|
|
100
100
|
*/
|
|
101
101
|
export declare function orderChart(data: ChartData, order: ChartOrder | undefined): ChartData;
|
|
102
102
|
/**
|
|
103
|
-
*
|
|
103
|
+
* THE PREVIOUS PERIOD beside the current one — Odoo's «comparar con».
|
|
104
104
|
*
|
|
105
|
-
*
|
|
106
|
-
*
|
|
107
|
-
*
|
|
105
|
+
* Each chart is built on its own (`chartFromPivot` over each period's records)
|
|
106
|
+
* and this joins them into two series: the current and the previous, which is drawn quiet. What is
|
|
107
|
+
* compared is what each whole category gives.
|
|
108
108
|
*
|
|
109
|
-
* `by`
|
|
110
|
-
*
|
|
111
|
-
* «2025-09»
|
|
112
|
-
*
|
|
109
|
+
* `by` says how they are matched: by KEY when the axis is a thing —La Paz with La Paz— and
|
|
110
|
+
* by POSITION when it is time —the first month with the first month—, because «2026-09» and
|
|
111
|
+
* «2025-09» are different keys and what is compared is «the same moment of the period».
|
|
112
|
+
* A category of the previous that is not in the current is not drawn: the axis is today's.
|
|
113
113
|
*/
|
|
114
114
|
export declare function chartCompare(current: ChartData, previous: ChartData, labels: {
|
|
115
115
|
current: string;
|
|
116
116
|
previous: string;
|
|
117
117
|
}, by?: "key" | "position"): ChartData;
|
|
118
118
|
/**
|
|
119
|
-
*
|
|
120
|
-
*
|
|
119
|
+
* A DICTIONARY as a chart: `{ "La Paz": 120, "Oruro": 40 }`, or its pairs. It is what
|
|
120
|
+
* a summary endpoint returns, and there is no need to build a pivot for it.
|
|
121
121
|
*/
|
|
122
122
|
export declare function chartFromRecord(entries: Readonly<Record<string, number | null>> | readonly (readonly [string, number | null])[], measure: {
|
|
123
123
|
header: string;
|
|
@@ -2,13 +2,13 @@ import { dateKeysBetween } from "./calendar.js";
|
|
|
2
2
|
import { currentCopy, fillCopy } from "./copy.js";
|
|
3
3
|
import { pathKey } from "./grouping.js";
|
|
4
4
|
import { axisLabels, } from "./pivot.js";
|
|
5
|
-
/**
|
|
6
|
-
*
|
|
5
|
+
/** The row count of each crossing, offered as one more measure: it is the only one that
|
|
6
|
+
* can always be answered. */
|
|
7
7
|
export const COUNT_MEASURE = "__count";
|
|
8
|
-
/**
|
|
9
|
-
*
|
|
8
|
+
/** How many series are told apart by colour. It is the palette's length (`--color-series-*`):
|
|
9
|
+
* a ninth series would be a generated colour, and under colour blindness that one gets confused with another. */
|
|
10
10
|
export const SERIES_COLORS = 8;
|
|
11
|
-
/**
|
|
11
|
+
/** The measures that can be charted from a pivot: the count and its own. */
|
|
12
12
|
export function chartMeasures(pivot) {
|
|
13
13
|
return [
|
|
14
14
|
{ id: COUNT_MEASURE, header: currentCopy().chart.count, additive: true },
|
|
@@ -63,8 +63,8 @@ function keep(totals, max, additive) {
|
|
|
63
63
|
};
|
|
64
64
|
}
|
|
65
65
|
/**
|
|
66
|
-
*
|
|
67
|
-
*
|
|
66
|
+
* The pivot as a chart: the rows are the axis, the columns the series, and at each crossing
|
|
67
|
+
* the number of the chosen measure.
|
|
68
68
|
*/
|
|
69
69
|
export function chartFromPivot(pivot, reading = {}) {
|
|
70
70
|
const words = currentCopy();
|
|
@@ -79,11 +79,11 @@ export function chartFromPivot(pivot, reading = {}) {
|
|
|
79
79
|
let categories = pivot.rows.keys.map((key) => pointOf(pivot.rows, key, words.pivot.total));
|
|
80
80
|
let series = pivot.columns.keys.map((key) => pointOf(pivot.columns, key, measure.header));
|
|
81
81
|
let values = categories.map((row) => series.map((column) => read(pivot.cell(row.key, column.key))));
|
|
82
|
-
/*
|
|
83
|
-
|
|
82
|
+
/* The margins come from the BASE when the pivot brings them; summing cells is the honest
|
|
83
|
+
way out only when the measure sums. */
|
|
84
84
|
const margin = (cell, inside) => cell !== undefined ? read(cell) : measure.additive ? sum(inside) : null;
|
|
85
85
|
let totals = categories.map((row, at) => margin(pivot.rowTotal?.(row.key), values[at] ?? []));
|
|
86
|
-
/* 0 ·
|
|
86
|
+
/* 0 · The whole time span: the empty periods between the first and the last. */
|
|
87
87
|
const grain = pivot.rows.levels.length === 1 ? pivot.rows.levels[0]?.grain : undefined;
|
|
88
88
|
if (grain !== undefined && reading.fillDates !== false) {
|
|
89
89
|
const dated = categories
|
|
@@ -122,7 +122,7 @@ export function chartFromPivot(pivot, reading = {}) {
|
|
|
122
122
|
totals = filled.map((one) => one.total);
|
|
123
123
|
}
|
|
124
124
|
}
|
|
125
|
-
/* 1 ·
|
|
125
|
+
/* 1 · The series that do not fit in the palette. */
|
|
126
126
|
let hiddenSeries = 0;
|
|
127
127
|
const seriesTotals = series.map((column, at) => margin(pivot.columnTotal?.(column.key), values.map((row) => row[at] ?? null)));
|
|
128
128
|
const seriesCut = keep(seriesTotals, reading.maxSeries ?? SERIES_COLORS, measure.additive);
|
|
@@ -149,7 +149,7 @@ export function chartFromPivot(pivot, reading = {}) {
|
|
|
149
149
|
values = values.map((row) => kept.map((at) => row[at] ?? null));
|
|
150
150
|
}
|
|
151
151
|
}
|
|
152
|
-
/* 2 ·
|
|
152
|
+
/* 2 · The categories that do not fit (a pie). */
|
|
153
153
|
let hiddenCategories = 0;
|
|
154
154
|
let restCategory = null;
|
|
155
155
|
if (reading.maxCategories !== undefined) {
|
|
@@ -175,7 +175,7 @@ export function chartFromPivot(pivot, reading = {}) {
|
|
|
175
175
|
totals = cut.kept.map((at) => totals[at] ?? null);
|
|
176
176
|
}
|
|
177
177
|
}
|
|
178
|
-
/* 3 ·
|
|
178
|
+
/* 3 · The axis order. The gathered tail always goes last: it is not one more category. */
|
|
179
179
|
if (reading.order !== undefined) {
|
|
180
180
|
const at = categories.map((_, index) => index).sort(byTotal(totals, reading.order));
|
|
181
181
|
categories = at.map((index) => categories[index]);
|
|
@@ -187,7 +187,7 @@ export function chartFromPivot(pivot, reading = {}) {
|
|
|
187
187
|
values = [...values, restCategory.values];
|
|
188
188
|
totals = [...totals, restCategory.total];
|
|
189
189
|
}
|
|
190
|
-
/* 4 ·
|
|
190
|
+
/* 4 · Cumulative: a hole carries over what was running, it does not cut it. */
|
|
191
191
|
if (reading.cumulative === true && measure.additive) {
|
|
192
192
|
const running = series.map(() => null);
|
|
193
193
|
values = values.map((row) => row.map((value, s) => {
|
|
@@ -215,9 +215,9 @@ export function chartFromPivot(pivot, reading = {}) {
|
|
|
215
215
|
};
|
|
216
216
|
}
|
|
217
217
|
/**
|
|
218
|
-
*
|
|
219
|
-
* («otros»)
|
|
220
|
-
*
|
|
218
|
+
* Sorts the AXIS of an already built chart by what each category gives. The gathered tail
|
|
219
|
+
* («otros») stays last. It is the same as `order` in `chartFromPivot`, for a chart
|
|
220
|
+
* that was built another way —a comparison, a dictionary—.
|
|
221
221
|
*/
|
|
222
222
|
export function orderChart(data, order) {
|
|
223
223
|
if (order === undefined)
|
|
@@ -238,16 +238,16 @@ export function orderChart(data, order) {
|
|
|
238
238
|
};
|
|
239
239
|
}
|
|
240
240
|
/**
|
|
241
|
-
*
|
|
241
|
+
* THE PREVIOUS PERIOD beside the current one — Odoo's «comparar con».
|
|
242
242
|
*
|
|
243
|
-
*
|
|
244
|
-
*
|
|
245
|
-
*
|
|
243
|
+
* Each chart is built on its own (`chartFromPivot` over each period's records)
|
|
244
|
+
* and this joins them into two series: the current and the previous, which is drawn quiet. What is
|
|
245
|
+
* compared is what each whole category gives.
|
|
246
246
|
*
|
|
247
|
-
* `by`
|
|
248
|
-
*
|
|
249
|
-
* «2025-09»
|
|
250
|
-
*
|
|
247
|
+
* `by` says how they are matched: by KEY when the axis is a thing —La Paz with La Paz— and
|
|
248
|
+
* by POSITION when it is time —the first month with the first month—, because «2026-09» and
|
|
249
|
+
* «2025-09» are different keys and what is compared is «the same moment of the period».
|
|
250
|
+
* A category of the previous that is not in the current is not drawn: the axis is today's.
|
|
251
251
|
*/
|
|
252
252
|
export function chartCompare(current, previous, labels, by = "key") {
|
|
253
253
|
const whole = (data, at) => data.series.length === 1 ? (data.values[at]?.[0] ?? null) : (data.totals[at] ?? null);
|
|
@@ -271,8 +271,8 @@ export function chartCompare(current, previous, labels, by = "key") {
|
|
|
271
271
|
};
|
|
272
272
|
}
|
|
273
273
|
/**
|
|
274
|
-
*
|
|
275
|
-
*
|
|
274
|
+
* A DICTIONARY as a chart: `{ "La Paz": 120, "Oruro": 40 }`, or its pairs. It is what
|
|
275
|
+
* a summary endpoint returns, and there is no need to build a pivot for it.
|
|
276
276
|
*/
|
|
277
277
|
export function chartFromRecord(entries, measure) {
|
|
278
278
|
const pairs = Array.isArray(entries)
|