@uvalib/web-components 1.2.0 → 1.3.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/CHANGELOG.md +87 -0
- package/README.md +808 -46
- package/dist/analytics.d.ts +10 -0
- package/dist/analytics.js +9 -0
- package/dist/analytics.js.map +1 -0
- package/dist/base/UvalibElement.js +8 -5
- package/dist/base/UvalibElement.js.map +1 -1
- package/dist/base/analytics-state.d.ts +7 -0
- package/dist/base/analytics-state.js.map +1 -1
- package/dist/base/light-dom-styles.d.ts +13 -0
- package/dist/base/light-dom-styles.js +26 -0
- package/dist/base/light-dom-styles.js.map +1 -1
- package/dist/base/search-tracker.d.ts +57 -0
- package/dist/base/search-tracker.js +51 -0
- package/dist/base/search-tracker.js.map +1 -0
- package/dist/base.css +286 -14
- package/dist/base.d.ts +2 -0
- package/dist/base.js +1 -0
- package/dist/base.js.map +1 -1
- package/dist/components/site-analytics/SiteAnalytics.d.ts +20 -1
- package/dist/components/site-analytics/SiteAnalytics.js +93 -12
- package/dist/components/site-analytics/SiteAnalytics.js.map +1 -1
- package/dist/components/site-page/SitePage.d.ts +23 -0
- package/dist/components/site-page/SitePage.js +77 -0
- package/dist/components/site-page/SitePage.js.map +1 -1
- package/dist/components/uvalib-back-to-top/UvalibBackToTop.d.ts +58 -0
- package/dist/components/uvalib-back-to-top/UvalibBackToTop.js +250 -0
- package/dist/components/uvalib-back-to-top/UvalibBackToTop.js.map +1 -0
- package/dist/components/uvalib-back-to-top/uvalib-back-to-top.d.ts +1 -0
- package/dist/components/uvalib-back-to-top/uvalib-back-to-top.js +4 -0
- package/dist/components/uvalib-back-to-top/uvalib-back-to-top.js.map +1 -0
- package/dist/components/uvalib-breadcrumbs/UvalibBreadcrumbs.d.ts +14 -0
- package/dist/components/uvalib-breadcrumbs/UvalibBreadcrumbs.js +56 -4
- package/dist/components/uvalib-breadcrumbs/UvalibBreadcrumbs.js.map +1 -1
- package/dist/components/uvalib-chip-group/UvalibChipGroup.d.ts +25 -3
- package/dist/components/uvalib-chip-group/UvalibChipGroup.js +80 -10
- package/dist/components/uvalib-chip-group/UvalibChipGroup.js.map +1 -1
- package/dist/components/uvalib-combobox/UvalibCombobox.d.ts +212 -0
- package/dist/components/uvalib-combobox/UvalibCombobox.js +1088 -0
- package/dist/components/uvalib-combobox/UvalibCombobox.js.map +1 -0
- package/dist/components/uvalib-combobox/uvalib-combobox.d.ts +1 -0
- package/dist/components/uvalib-combobox/uvalib-combobox.js +4 -0
- package/dist/components/uvalib-combobox/uvalib-combobox.js.map +1 -0
- package/dist/components/uvalib-contents/UvalibContents.d.ts +53 -0
- package/dist/components/uvalib-contents/UvalibContents.js +202 -3
- package/dist/components/uvalib-contents/UvalibContents.js.map +1 -1
- package/dist/components/uvalib-date-histogram/UvalibDateHistogram.d.ts +56 -17
- package/dist/components/uvalib-date-histogram/UvalibDateHistogram.js +285 -81
- package/dist/components/uvalib-date-histogram/UvalibDateHistogram.js.map +1 -1
- package/dist/components/uvalib-date-range/UvalibDateRange.d.ts +6 -0
- package/dist/components/uvalib-date-range/UvalibDateRange.js +23 -0
- package/dist/components/uvalib-date-range/UvalibDateRange.js.map +1 -1
- package/dist/components/uvalib-filter-drawer/UvalibFilterDrawer.d.ts +113 -0
- package/dist/components/uvalib-filter-drawer/UvalibFilterDrawer.js +589 -0
- package/dist/components/uvalib-filter-drawer/UvalibFilterDrawer.js.map +1 -0
- package/dist/components/uvalib-filter-drawer/uvalib-filter-drawer.d.ts +1 -0
- package/dist/components/uvalib-filter-drawer/uvalib-filter-drawer.js +4 -0
- package/dist/components/uvalib-filter-drawer/uvalib-filter-drawer.js.map +1 -0
- package/dist/components/uvalib-image-regions/UvalibImageRegions.d.ts +130 -0
- package/dist/components/uvalib-image-regions/UvalibImageRegions.js +658 -0
- package/dist/components/uvalib-image-regions/UvalibImageRegions.js.map +1 -0
- package/dist/components/uvalib-image-regions/regions.d.ts +57 -0
- package/dist/components/uvalib-image-regions/regions.js +117 -0
- package/dist/components/uvalib-image-regions/regions.js.map +1 -0
- package/dist/components/uvalib-image-regions/uvalib-image-regions.d.ts +1 -0
- package/dist/components/uvalib-image-regions/uvalib-image-regions.js +4 -0
- package/dist/components/uvalib-image-regions/uvalib-image-regions.js.map +1 -0
- package/dist/components/uvalib-lightbox/UvalibLightbox.d.ts +40 -0
- package/dist/components/uvalib-lightbox/UvalibLightbox.js +144 -16
- package/dist/components/uvalib-lightbox/UvalibLightbox.js.map +1 -1
- package/dist/components/uvalib-map/UvalibMap.d.ts +182 -0
- package/dist/components/uvalib-map/UvalibMap.js +1001 -0
- package/dist/components/uvalib-map/UvalibMap.js.map +1 -0
- package/dist/components/uvalib-map/uvalib-map.d.ts +1 -0
- package/dist/components/uvalib-map/uvalib-map.js +4 -0
- package/dist/components/uvalib-map/uvalib-map.js.map +1 -0
- package/dist/components/uvalib-metadata/UvalibMetadata.d.ts +39 -2
- package/dist/components/uvalib-metadata/UvalibMetadata.js +214 -8
- package/dist/components/uvalib-metadata/UvalibMetadata.js.map +1 -1
- package/dist/components/uvalib-pager/UvalibPager.d.ts +22 -3
- package/dist/components/uvalib-pager/UvalibPager.js +42 -4
- package/dist/components/uvalib-pager/UvalibPager.js.map +1 -1
- package/dist/custom-elements.json +9253 -3253
- package/dist/index.d.ts +8 -0
- package/dist/index.js +5 -0
- package/dist/index.js.map +1 -1
- package/dist/pagefind.css +4 -0
- package/dist/styles/base.js +119 -0
- package/dist/styles/base.js.map +1 -1
- package/dist/styles/color-scheme.js +5 -0
- package/dist/styles/color-scheme.js.map +1 -1
- package/dist/styles/controls.js +6 -0
- package/dist/styles/controls.js.map +1 -1
- package/dist/styles/hidden.d.ts +2 -0
- package/dist/styles/hidden.js +51 -0
- package/dist/styles/hidden.js.map +1 -0
- package/dist/styles/message.d.ts +1 -0
- package/dist/styles/message.js +82 -0
- package/dist/styles/message.js.map +1 -0
- package/dist/styles/pagefind.js +4 -0
- package/dist/styles/pagefind.js.map +1 -1
- package/dist/styles/result-list.d.ts +1 -0
- package/dist/styles/result-list.js +111 -0
- package/dist/styles/result-list.js.map +1 -0
- package/dist/styles/results.js +0 -15
- package/dist/styles/results.js.map +1 -1
- package/dist/testing/index.d.ts +110 -0
- package/dist/testing/index.js +100 -0
- package/dist/testing/index.js.map +1 -0
- package/dist/testing/lighthouse-rules.d.ts +10 -0
- package/dist/testing/lighthouse-rules.js +44 -0
- package/dist/testing/lighthouse-rules.js.map +1 -0
- package/dist/tokens.css +5 -0
- package/dist-cdn/analytics.js +32 -0
- package/dist-cdn/analytics.js.map +1 -0
- package/dist-cdn/base.css +286 -14
- package/dist-cdn/bento-box.js +3 -3
- package/dist-cdn/chunks/{SiteAnalytics-Cm-FyhYS.js → SiteAnalytics-B9gu5aGO.js} +59 -30
- package/dist-cdn/chunks/SiteAnalytics-B9gu5aGO.js.map +1 -0
- package/dist-cdn/chunks/{UvalibElement-BnI-eRRR.js → UvalibElement-pGONDAwB.js} +108 -101
- package/dist-cdn/chunks/UvalibElement-pGONDAwB.js.map +1 -0
- package/dist-cdn/chunks/{accessible-GqhVn5_H.js → accessible-DJv7YOtS.js} +2 -2
- package/dist-cdn/chunks/{accessible-GqhVn5_H.js.map → accessible-DJv7YOtS.js.map} +1 -1
- package/dist-cdn/chunks/analytics-state-Ce8DKe4F.js.map +1 -1
- package/dist-cdn/chunks/{base-p5pk0vb2.js → base-BI8h0Gf3.js} +121 -2
- package/dist-cdn/chunks/base-BI8h0Gf3.js.map +1 -0
- package/dist-cdn/chunks/{library-weekly-hours-COE7Vv6V.js → library-weekly-hours-CrV3TlP5.js} +3 -3
- package/dist-cdn/chunks/{library-weekly-hours-COE7Vv6V.js.map → library-weekly-hours-CrV3TlP5.js.map} +1 -1
- package/dist-cdn/chunks/regions-B8ExwUGP.js +86 -0
- package/dist-cdn/chunks/regions-B8ExwUGP.js.map +1 -0
- package/dist-cdn/chunks/{repeat-CIFUYkyh.js → repeat-m5Zd_QeP.js} +2 -2
- package/dist-cdn/chunks/{repeat-CIFUYkyh.js.map → repeat-m5Zd_QeP.js.map} +1 -1
- package/dist-cdn/chunks/{site-header-BlOYvQg1.js → site-header-DYRMpdBj.js} +9 -4
- package/dist-cdn/chunks/{site-header-BlOYvQg1.js.map → site-header-DYRMpdBj.js.map} +1 -1
- package/dist-cdn/chunks/{site-main-nav-AaxZ9rQf.js → site-main-nav-DURrQMal.js} +3 -3
- package/dist-cdn/chunks/{site-main-nav-AaxZ9rQf.js.map → site-main-nav-DURrQMal.js.map} +1 -1
- package/dist-cdn/chunks/{static-html-1mTAG6nS.js → static-html-C1rhtCHu.js} +2 -2
- package/dist-cdn/chunks/{static-html-1mTAG6nS.js.map → static-html-C1rhtCHu.js.map} +1 -1
- package/dist-cdn/custom-elements.json +9253 -3253
- package/dist-cdn/events-section.js +3 -3
- package/dist-cdn/library-hours-setup.js +2 -2
- package/dist-cdn/library-weekly-hours.js +1 -1
- package/dist-cdn/manifest.json +10 -2
- package/dist-cdn/pagefind.css +4 -0
- package/dist-cdn/site-alerts.js +4 -4
- package/dist-cdn/site-analytics.js +2 -2
- package/dist-cdn/site-footer.js +2 -2
- package/dist-cdn/site-header.js +1 -1
- package/dist-cdn/site-hours-section.js +4 -4
- package/dist-cdn/site-main-nav.js +1 -1
- package/dist-cdn/site-page.js +56 -11
- package/dist-cdn/site-page.js.map +1 -1
- package/dist-cdn/site-style.js +2 -2
- package/dist-cdn/skills/uvalib-web-components/SKILL.md +98 -13
- package/dist-cdn/skills/uvalib-web-components/reference/accessibility-testing.md +34 -2
- package/dist-cdn/skills/uvalib-web-components/reference/components.md +300 -13
- package/dist-cdn/skills/uvalib-web-components/reference/snippets.md +1 -1
- package/dist-cdn/tokens.css +5 -0
- package/dist-cdn/uvalib-analytics.js +2 -2
- package/dist-cdn/uvalib-back-to-top.js +156 -0
- package/dist-cdn/uvalib-back-to-top.js.map +1 -0
- package/dist-cdn/uvalib-breadcrumbs.js +31 -11
- package/dist-cdn/uvalib-breadcrumbs.js.map +1 -1
- package/dist-cdn/uvalib-card-grid.js +1 -1
- package/dist-cdn/uvalib-card.js +3 -3
- package/dist-cdn/uvalib-chip-group.js +53 -14
- package/dist-cdn/uvalib-chip-group.js.map +1 -1
- package/dist-cdn/uvalib-combobox.js +667 -0
- package/dist-cdn/uvalib-combobox.js.map +1 -0
- package/dist-cdn/uvalib-contents.js +100 -22
- package/dist-cdn/uvalib-contents.js.map +1 -1
- package/dist-cdn/uvalib-date-histogram.js +237 -127
- package/dist-cdn/uvalib-date-histogram.js.map +1 -1
- package/dist-cdn/uvalib-date-range.js +14 -2
- package/dist-cdn/uvalib-date-range.js.map +1 -1
- package/dist-cdn/uvalib-filter-drawer.js +355 -0
- package/dist-cdn/uvalib-filter-drawer.js.map +1 -0
- package/dist-cdn/uvalib-filter.js +3 -3
- package/dist-cdn/uvalib-image-regions.js +447 -0
- package/dist-cdn/uvalib-image-regions.js.map +1 -0
- package/dist-cdn/uvalib-lightbox.js +144 -55
- package/dist-cdn/uvalib-lightbox.js.map +1 -1
- package/dist-cdn/uvalib-map.js +471 -0
- package/dist-cdn/uvalib-map.js.map +1 -0
- package/dist-cdn/uvalib-metadata.js +150 -24
- package/dist-cdn/uvalib-metadata.js.map +1 -1
- package/dist-cdn/uvalib-pager.js +29 -17
- package/dist-cdn/uvalib-pager.js.map +1 -1
- package/dist-cdn/uvalib-photo-grid.js +2 -2
- package/dist-cdn/uvalib-results-count.js +2 -2
- package/dist-cdn/uvalib-tabs.js +2 -2
- package/dist-cdn/uvalib-tag-list.js +2 -2
- package/package.json +43 -1
- package/skills/uvalib-web-components/SKILL.md +98 -13
- package/skills/uvalib-web-components/reference/accessibility-testing.md +34 -2
- package/skills/uvalib-web-components/reference/components.md +300 -13
- package/skills/uvalib-web-components/reference/snippets.md +1 -1
- package/dist-cdn/chunks/SiteAnalytics-Cm-FyhYS.js.map +0 -1
- package/dist-cdn/chunks/UvalibElement-BnI-eRRR.js.map +0 -1
- package/dist-cdn/chunks/base-p5pk0vb2.js.map +0 -1
|
@@ -58,11 +58,27 @@ function monthIndex(token) {
|
|
|
58
58
|
const n = Number(t);
|
|
59
59
|
return Number.isInteger(n) && n >= 1 && n <= 12 ? n : 0;
|
|
60
60
|
}
|
|
61
|
-
/**
|
|
61
|
+
/** A decade key, `1810s`. */
|
|
62
|
+
const DECADE = /^(\d{3}0)s$/;
|
|
63
|
+
const decadeKey = (year) => `${String(Math.floor(year / 10) * 10).padStart(4, '0')}s`;
|
|
64
|
+
/** The `selected` value a decade bar sets: its first and last year (`1810/1819`). */
|
|
65
|
+
function decadeSelection(key) {
|
|
66
|
+
const d = Number(key.slice(0, 4));
|
|
67
|
+
return `${key.slice(0, 4)}/${String(d + 9).padStart(4, '0')}`;
|
|
68
|
+
}
|
|
69
|
+
/**
|
|
70
|
+
* `granularity="auto"`: month bars when every dated count is a month and they span at most
|
|
71
|
+
* 3 years (36 bars), year bars up to 30 years, decades beyond.
|
|
72
|
+
*/
|
|
73
|
+
const AUTO_MONTH_YEARS = 3;
|
|
74
|
+
const AUTO_YEAR_YEARS = 30;
|
|
75
|
+
/** `YYYY`, `YYYY-MM` and `YYYYs` (a decade) are buckets. A day, a month name or anything else is an odd date. */
|
|
62
76
|
function parseDate(raw) {
|
|
63
77
|
const s = raw.replace(/\s+/g, ' ').trim();
|
|
64
78
|
if (!s)
|
|
65
79
|
return null;
|
|
80
|
+
if (DECADE.test(s))
|
|
81
|
+
return { key: s, kind: 'decade' };
|
|
66
82
|
if (ISO_DAY.test(s))
|
|
67
83
|
return { key: isIsoDate(s) ? s : s, kind: 'odd' };
|
|
68
84
|
const month = /^(\d{4})-(\d{2})$/.exec(s);
|
|
@@ -84,7 +100,7 @@ function parseDate(raw) {
|
|
|
84
100
|
}
|
|
85
101
|
return { key: s, kind: 'odd' };
|
|
86
102
|
}
|
|
87
|
-
/** Inclusive ISO span of a bucket key, or null when `key` is not a year, month or day. */
|
|
103
|
+
/** Inclusive ISO span of a bucket key, or null when `key` is not a decade, year, month or day. */
|
|
88
104
|
function keyToSpan(key) {
|
|
89
105
|
if (isIsoDate(key))
|
|
90
106
|
return { from: key, to: key };
|
|
@@ -94,6 +110,11 @@ function keyToSpan(key) {
|
|
|
94
110
|
}
|
|
95
111
|
if (/^\d{4}$/.test(key))
|
|
96
112
|
return { from: `${key}-01-01`, to: `${key}-12-31` };
|
|
113
|
+
const decade = DECADE.exec(key);
|
|
114
|
+
if (decade) {
|
|
115
|
+
const last = String(Number(decade[1]) + 9).padStart(4, '0');
|
|
116
|
+
return { from: `${decade[1]}-01-01`, to: `${last}-12-31` };
|
|
117
|
+
}
|
|
97
118
|
return null;
|
|
98
119
|
}
|
|
99
120
|
function splitSelection(raw) {
|
|
@@ -119,6 +140,8 @@ function parseSelected(raw) {
|
|
|
119
140
|
}
|
|
120
141
|
return keyToSpan(trimmed) ?? { from: trimmed, to: trimmed };
|
|
121
142
|
}
|
|
143
|
+
/** The first year of the half-century a year is in (decade rows are 1800–1849, 1850–1899, …). */
|
|
144
|
+
const halfCentury = (year) => Math.floor(year / 50) * 50;
|
|
122
145
|
/** Years touched by two ISO dates, inclusive. */
|
|
123
146
|
function yearCount(min, max) {
|
|
124
147
|
const a = /^(\d{4})/.exec(min.trim());
|
|
@@ -161,10 +184,9 @@ function bucketName(key, count, unit) {
|
|
|
161
184
|
function addOdd(odds, key, count) {
|
|
162
185
|
odds.set(key, (odds.get(key) ?? 0) + count);
|
|
163
186
|
}
|
|
164
|
-
/**
|
|
165
|
-
function
|
|
166
|
-
const
|
|
167
|
-
const odds = new Map();
|
|
187
|
+
/** Each valid item as a parsed date and a count. */
|
|
188
|
+
function parsedItems(items) {
|
|
189
|
+
const out = [];
|
|
168
190
|
for (const item of items) {
|
|
169
191
|
if (!item || typeof item.date !== 'string')
|
|
170
192
|
continue;
|
|
@@ -172,13 +194,41 @@ function buildModel(items, grain) {
|
|
|
172
194
|
if (!Number.isFinite(count) || count < 0)
|
|
173
195
|
continue;
|
|
174
196
|
const parsed = parseDate(item.date);
|
|
175
|
-
if (
|
|
176
|
-
|
|
177
|
-
|
|
197
|
+
if (parsed)
|
|
198
|
+
out.push({ ...parsed, count });
|
|
199
|
+
}
|
|
200
|
+
return out;
|
|
201
|
+
}
|
|
202
|
+
/** The grain `granularity="auto"` draws. `span` is the years to cover when there are no counts yet. */
|
|
203
|
+
function autoGrain(items, span) {
|
|
204
|
+
const dated = parsedItems(items).filter((p) => p.kind !== 'odd');
|
|
205
|
+
if (!dated.length)
|
|
206
|
+
return span != null && span > AUTO_YEAR_YEARS ? 'decade' : 'year';
|
|
207
|
+
const years = dated.map((p) => Number(p.key.slice(0, 4)));
|
|
208
|
+
const width = Math.max(...years) - Math.min(...years) + 1;
|
|
209
|
+
if (dated.every((p) => p.kind === 'month') && width <= AUTO_MONTH_YEARS)
|
|
210
|
+
return 'month';
|
|
211
|
+
if (dated.some((p) => p.kind === 'decade'))
|
|
212
|
+
return 'decade';
|
|
213
|
+
return width <= AUTO_YEAR_YEARS ? 'year' : 'decade';
|
|
214
|
+
}
|
|
215
|
+
/** Continuous buckets from the earliest date to the latest, with the months, years or decades between filled in. */
|
|
216
|
+
function buildModel(items, grain) {
|
|
217
|
+
const buckets = new Map();
|
|
218
|
+
const odds = new Map();
|
|
219
|
+
for (const parsed of parsedItems(items)) {
|
|
220
|
+
const { count } = parsed;
|
|
221
|
+
if (parsed.kind === 'odd' ||
|
|
222
|
+
(grain === 'month' && parsed.kind === 'year') ||
|
|
223
|
+
(grain !== 'decade' && parsed.kind === 'decade')) {
|
|
178
224
|
addOdd(odds, parsed.key, count);
|
|
179
225
|
continue;
|
|
180
226
|
}
|
|
181
|
-
const key = grain === 'year'
|
|
227
|
+
const key = grain === 'year'
|
|
228
|
+
? parsed.key.slice(0, 4)
|
|
229
|
+
: grain === 'decade'
|
|
230
|
+
? decadeKey(Number(parsed.key.slice(0, 4)))
|
|
231
|
+
: parsed.key;
|
|
182
232
|
buckets.set(key, (buckets.get(key) ?? 0) + count);
|
|
183
233
|
}
|
|
184
234
|
const bars = [];
|
|
@@ -186,8 +236,12 @@ function buildModel(items, grain) {
|
|
|
186
236
|
if (keys.length) {
|
|
187
237
|
const first = Number(keys[0].slice(0, 4));
|
|
188
238
|
const last = Number(keys[keys.length - 1].slice(0, 4));
|
|
189
|
-
for (let year = first; year <= last; year
|
|
190
|
-
if (grain === '
|
|
239
|
+
for (let year = first; year <= last; year += grain === 'decade' ? 10 : 1) {
|
|
240
|
+
if (grain === 'decade') {
|
|
241
|
+
const key = decadeKey(year);
|
|
242
|
+
bars.push({ key, count: buckets.get(key) ?? 0, year, month: 0 });
|
|
243
|
+
}
|
|
244
|
+
else if (grain === 'year') {
|
|
191
245
|
const key = String(year);
|
|
192
246
|
bars.push({ key, count: buckets.get(key) ?? 0, year, month: 0 });
|
|
193
247
|
}
|
|
@@ -291,7 +345,7 @@ const structuralRules = (host) => {
|
|
|
291
345
|
return `
|
|
292
346
|
${host} { display: block; max-width: 100%; min-width: 0; box-sizing: border-box; }
|
|
293
347
|
${host} .scroller { overflow-x: auto; max-width: 100%; overscroll-behavior-x: contain; }
|
|
294
|
-
${host} .by-month .scroller { scroll-padding-inline-start: 4rem; }
|
|
348
|
+
${host} :is(.by-month, .by-decade) .scroller { scroll-padding-inline-start: 4rem; }
|
|
295
349
|
${host} .year {
|
|
296
350
|
display: grid;
|
|
297
351
|
grid-template-columns: 3.5rem minmax(0, 1fr);
|
|
@@ -316,6 +370,10 @@ const structuralRules = (host) => {
|
|
|
316
370
|
block-size: var(--uvalib-date-histogram-bar-size, 8rem);
|
|
317
371
|
min-inline-size: calc(12 * 1.5rem + 11 * 2px);
|
|
318
372
|
}
|
|
373
|
+
${host} .by-decade .bars {
|
|
374
|
+
grid-template-columns: repeat(5, minmax(1.5rem, 1fr));
|
|
375
|
+
min-inline-size: calc(5 * 1.5rem + 4 * 2px);
|
|
376
|
+
}
|
|
319
377
|
${host} .bar {
|
|
320
378
|
position: relative;
|
|
321
379
|
box-sizing: border-box;
|
|
@@ -472,12 +530,22 @@ function tableCaption(text) {
|
|
|
472
530
|
return html `<caption>${text}</caption>`;
|
|
473
531
|
}
|
|
474
532
|
/**
|
|
475
|
-
* Monthly or
|
|
476
|
-
* timeline or a card. Give `items` (`{ date, count }`, `date` a `YYYY` or `YYYY-MM`)
|
|
477
|
-
* child `<table>` (the no-JS fallback). `granularity="month"` draws twelve bars for every
|
|
533
|
+
* Monthly, yearly or per-decade counts as bars: a date distribution for a search page, an
|
|
534
|
+
* archive timeline or a card. Give `items` (`{ date, count }`, `date` a `YYYY` or `YYYY-MM`)
|
|
535
|
+
* or a child `<table>` (the no-JS fallback). `granularity="month"` draws twelve bars for every
|
|
478
536
|
* year from the first date to the last, including months with a count of zero. A year-only
|
|
479
537
|
* count in a month chart, a day, or any other date is a chip beside the chart.
|
|
480
538
|
*
|
|
539
|
+
* `granularity="decade"` is for a long span (two centuries of minutes): one bar per decade
|
|
540
|
+
* ("1810s: 22 meetings"), an empty decade a gap, five decades to a row labelled with its
|
|
541
|
+
* first year (1800, 1850, …), the decades lined up in columns. Choosing a decade selects
|
|
542
|
+
* its first to last year (`selected="1810/1819"`, `select` `{ from: '1810-01-01', to:
|
|
543
|
+
* '1819-12-31' }`); up and down arrows move 50 years. `granularity="auto"` draws months
|
|
544
|
+
* when every count is a month within 3 years (at most 36 bars), years up to 30 years, and
|
|
545
|
+
* decades beyond. A year row that scrolls sideways is not offered: 200 years at the 24px
|
|
546
|
+
* minimum bar is over 5,000px, so a sidebar would show ten years at a time and lose the
|
|
547
|
+
* shape that decades show whole.
|
|
548
|
+
*
|
|
481
549
|
* Each bar is a button named like "October 2015: 5,311 photos". Arrow keys move between
|
|
482
550
|
* bars; Enter or Space selects. `selected` is one bucket (`2015-10`, `2015`) or a range
|
|
483
551
|
* (`2015-03/2016-01`, also `..` or an en dash). The selection is `aria-pressed`, an inset
|
|
@@ -486,20 +554,23 @@ function tableCaption(text) {
|
|
|
486
554
|
* again clears it (`from` and `to` are empty strings).
|
|
487
555
|
*
|
|
488
556
|
* `range-for` is the id of a `<uvalib-date-range>`. A bar click sets that element's
|
|
489
|
-
* `value`.
|
|
490
|
-
*
|
|
491
|
-
* that is exactly the range's own `min`
|
|
492
|
-
*
|
|
493
|
-
*
|
|
557
|
+
* `value`. Whenever the range's value changes, from its controls or set in script (a Clear
|
|
558
|
+
* button, Back/Forward, a restored URL), this element highlights the buckets that overlap it
|
|
559
|
+
* (it listens for `uvalib-date-range-value`). A value that is exactly the range's own `min`
|
|
560
|
+
* and `max` is no selection. On connect or reconnect, or when the range is added later, the
|
|
561
|
+
* range's value wins when it holds a selection or changed while this element was away;
|
|
562
|
+
* otherwise `selected` is written to it. A range value is never rounded to whole buckets
|
|
563
|
+
* and written back. Setting `selected` here updates the date range.
|
|
494
564
|
*
|
|
495
565
|
* `variant="strip"` is the small per-year row for a card: not interactive, `role="img"`,
|
|
496
|
-
* one bar per year
|
|
566
|
+
* one bar per year, or per decade with `decade` (or `auto` over more than 30 years).
|
|
497
567
|
*
|
|
498
568
|
* The chart reserves its height before the counts arrive: one bar track, or one track
|
|
499
|
-
* per year when those years are already known from the
|
|
500
|
-
* table (`--uvalib-date-histogram-bar-size`, 8rem, plus
|
|
501
|
-
* bars in does not move the page. On a narrow screen a month row
|
|
502
|
-
* component; "Scroll sideways to see more." shows while it overflows.
|
|
569
|
+
* per year (per half-century for decades) when those years are already known from the
|
|
570
|
+
* data, a linked date range or the table (`--uvalib-date-histogram-bar-size`, 8rem, plus
|
|
571
|
+
* the row gap). Filling the bars in does not move the page. On a narrow screen a month row
|
|
572
|
+
* scrolls inside the component; "Scroll sideways to see more." shows while it overflows.
|
|
573
|
+
* Years wrap; a decade row fits 320px.
|
|
503
574
|
*
|
|
504
575
|
* @tagname uvalib-date-histogram
|
|
505
576
|
* @slot - A `<table>` of dates and counts: two columns (date, count) or a year-by-month grid. Without JavaScript it is the fallback. With JavaScript it supplies the counts when `items` is empty. Show as table lists those counts, including odd dates; once `items` is set it lists `items` instead.
|
|
@@ -573,7 +644,11 @@ export class UvalibDateHistogram extends UvalibElement {
|
|
|
573
644
|
super();
|
|
574
645
|
/** Counts to draw. When non-empty, wins over the child table. Set a new array to update. */
|
|
575
646
|
this.items = [];
|
|
576
|
-
/**
|
|
647
|
+
/**
|
|
648
|
+
* `month` (twelve bars per year), `year`, `decade` (one bar per decade, five to a row), or
|
|
649
|
+
* `auto`: months when every count is a month within 3 years, years up to 30 years, else
|
|
650
|
+
* decades. Anything else is month, with one console warning.
|
|
651
|
+
*/
|
|
577
652
|
this.granularity = 'month';
|
|
578
653
|
/** `log` scales bar height by log(count + 1). Anything else is linear. */
|
|
579
654
|
this.scale = 'linear';
|
|
@@ -603,8 +678,8 @@ export class UvalibDateHistogram extends UvalibElement {
|
|
|
603
678
|
this.seen = false;
|
|
604
679
|
/** True while `choose()` assigns `selected`, so that click keeps the roving tab stop. */
|
|
605
680
|
this.choosing = false;
|
|
606
|
-
this.onPartner = (
|
|
607
|
-
this.
|
|
681
|
+
this.onPartner = () => {
|
|
682
|
+
this.pullPartner();
|
|
608
683
|
};
|
|
609
684
|
new SourceChildren(this, () => this.lightDom, (nodes) => this.readTable(nodes));
|
|
610
685
|
}
|
|
@@ -627,19 +702,24 @@ export class UvalibDateHistogram extends UvalibElement {
|
|
|
627
702
|
});
|
|
628
703
|
}
|
|
629
704
|
this.bindPartner();
|
|
705
|
+
// A reconnect schedules no update, so take up the date range here.
|
|
706
|
+
if (this.hasUpdated) {
|
|
707
|
+
this.seen = true;
|
|
708
|
+
this.syncOnBind();
|
|
709
|
+
}
|
|
630
710
|
this.measureOverflow();
|
|
631
711
|
if (!customElements.get('uvalib-date-range')) {
|
|
632
712
|
void customElements.whenDefined('uvalib-date-range').then(() => {
|
|
633
|
-
if (!this.isConnected
|
|
713
|
+
if (!this.isConnected)
|
|
634
714
|
return;
|
|
635
715
|
this.bindPartner();
|
|
636
|
-
this.
|
|
716
|
+
this.syncOnBind();
|
|
637
717
|
});
|
|
638
718
|
}
|
|
639
719
|
}
|
|
640
720
|
disconnectedCallback() {
|
|
641
721
|
super.disconnectedCallback();
|
|
642
|
-
this.
|
|
722
|
+
this.unlisten(this.partner);
|
|
643
723
|
this.partner = null;
|
|
644
724
|
this.ro?.disconnect();
|
|
645
725
|
this.ro = undefined;
|
|
@@ -651,10 +731,9 @@ export class UvalibDateHistogram extends UvalibElement {
|
|
|
651
731
|
willUpdate(changed) {
|
|
652
732
|
if (!this.warnedGrain &&
|
|
653
733
|
changed.has('granularity') &&
|
|
654
|
-
|
|
655
|
-
this.granularity !== 'month') {
|
|
734
|
+
!['year', 'month', 'decade', 'auto'].includes(this.granularity)) {
|
|
656
735
|
this.warnedGrain = true;
|
|
657
|
-
console.warn(`<${TAG}>: granularity must be "year" or "
|
|
736
|
+
console.warn(`<${TAG}>: granularity must be "month", "year", "decade" or "auto"; using "month".`);
|
|
658
737
|
}
|
|
659
738
|
if (changed.has('selected') && !this.choosing)
|
|
660
739
|
this.activeKey = '';
|
|
@@ -668,19 +747,42 @@ export class UvalibDateHistogram extends UvalibElement {
|
|
|
668
747
|
const appeared = this.partner != null && this.partner !== before;
|
|
669
748
|
if (!this.seen || changed.has('rangeFor') || appeared) {
|
|
670
749
|
this.seen = true;
|
|
671
|
-
if (this.selected)
|
|
672
|
-
this.
|
|
673
|
-
else if (!echoing)
|
|
674
|
-
this.pullPartner();
|
|
750
|
+
if (!echoing || this.selected)
|
|
751
|
+
this.syncOnBind();
|
|
675
752
|
}
|
|
676
753
|
else if (changed.has('selected') && !echoing) {
|
|
677
754
|
this.pushPartner();
|
|
678
755
|
}
|
|
756
|
+
// With `auto`, counts arriving can change the grain, so a range read before them is read again.
|
|
757
|
+
const grain = this.grain;
|
|
758
|
+
if (this.drawnGrain && grain !== this.drawnGrain && this.partner)
|
|
759
|
+
this.pullPartner();
|
|
760
|
+
this.drawnGrain = grain;
|
|
679
761
|
this.watchForPartner();
|
|
680
762
|
this.measureOverflow();
|
|
681
763
|
}
|
|
682
764
|
get grain() {
|
|
683
|
-
|
|
765
|
+
const g = this.granularity;
|
|
766
|
+
if (g === 'year' || g === 'decade')
|
|
767
|
+
return g;
|
|
768
|
+
if (g === 'auto')
|
|
769
|
+
return autoGrain(this.data, this.partnerSpan());
|
|
770
|
+
return 'month';
|
|
771
|
+
}
|
|
772
|
+
/** The strip is one bar per year, or per decade for `decade` (or `auto` over a long span). */
|
|
773
|
+
get stripGrain() {
|
|
774
|
+
if (this.granularity === 'decade')
|
|
775
|
+
return 'decade';
|
|
776
|
+
if (this.granularity === 'auto')
|
|
777
|
+
return this.grain === 'decade' ? 'decade' : 'year';
|
|
778
|
+
return 'year';
|
|
779
|
+
}
|
|
780
|
+
/** Years from the linked date range's `min` to its `max`, or null. */
|
|
781
|
+
partnerSpan() {
|
|
782
|
+
const partner = this.partner ?? this.findPartner();
|
|
783
|
+
if (!partner)
|
|
784
|
+
return null;
|
|
785
|
+
return yearCount(partner.min || partner.getAttribute('min') || '', partner.max || partner.getAttribute('max') || '');
|
|
684
786
|
}
|
|
685
787
|
get strip() {
|
|
686
788
|
return this.variant === 'strip';
|
|
@@ -722,10 +824,33 @@ export class UvalibDateHistogram extends UvalibElement {
|
|
|
722
824
|
const el = this.findPartner();
|
|
723
825
|
if (el === this.partner)
|
|
724
826
|
return;
|
|
725
|
-
this.
|
|
827
|
+
this.unlisten(this.partner);
|
|
726
828
|
this.partner = el;
|
|
829
|
+
// `uvalib-date-range-value` also covers a `value` set in script; `date-range-change`
|
|
830
|
+
// is kept for a date range from an older release.
|
|
831
|
+
el?.addEventListener('uvalib-date-range-value', this.onPartner);
|
|
727
832
|
el?.addEventListener('date-range-change', this.onPartner);
|
|
728
833
|
}
|
|
834
|
+
unlisten(el) {
|
|
835
|
+
el?.removeEventListener('uvalib-date-range-value', this.onPartner);
|
|
836
|
+
el?.removeEventListener('date-range-change', this.onPartner);
|
|
837
|
+
}
|
|
838
|
+
/**
|
|
839
|
+
* On connect, or when the date range appears: the range's value wins when it holds a
|
|
840
|
+
* selection or changed while this element was away; otherwise `selected` is written to it.
|
|
841
|
+
*/
|
|
842
|
+
syncOnBind() {
|
|
843
|
+
const el = this.partner;
|
|
844
|
+
if (!el)
|
|
845
|
+
return;
|
|
846
|
+
const r = this.partnerRange();
|
|
847
|
+
const changedAway = !!r && this.lastSeenEl === el && this.lastSeen != null && r.join('/') !== this.lastSeen;
|
|
848
|
+
this.lastSeenEl = el;
|
|
849
|
+
if (!this.selected || changedAway || (r && !this.isFullSpan(r[0], r[1])))
|
|
850
|
+
this.pullPartner();
|
|
851
|
+
else
|
|
852
|
+
this.pushPartner();
|
|
853
|
+
}
|
|
729
854
|
/** While the named date range is not in the tree yet, take its value when it appears. */
|
|
730
855
|
watchForPartner() {
|
|
731
856
|
if (!this.isConnected || !this.rangeFor.trim() || this.partner) {
|
|
@@ -746,10 +871,7 @@ export class UvalibDateHistogram extends UvalibElement {
|
|
|
746
871
|
return;
|
|
747
872
|
this.partnerObserver?.disconnect();
|
|
748
873
|
this.partnerObserver = undefined;
|
|
749
|
-
|
|
750
|
-
this.pushPartner();
|
|
751
|
-
else
|
|
752
|
-
this.pullPartner();
|
|
874
|
+
this.syncOnBind();
|
|
753
875
|
this.requestUpdate();
|
|
754
876
|
});
|
|
755
877
|
this.partnerObserver.observe(root, { childList: true, subtree: true });
|
|
@@ -770,11 +892,28 @@ export class UvalibDateHistogram extends UvalibElement {
|
|
|
770
892
|
return false;
|
|
771
893
|
return from === ends.min && to === ends.max;
|
|
772
894
|
}
|
|
773
|
-
|
|
774
|
-
|
|
895
|
+
/** The date range's value as it shows it: missing ends are `min` / `max`, both clamped to them. */
|
|
896
|
+
partnerRange() {
|
|
897
|
+
const el = this.partner;
|
|
898
|
+
const ends = this.partnerEnds();
|
|
899
|
+
if (!el || !ends)
|
|
900
|
+
return null;
|
|
901
|
+
const value = Array.isArray(el.value) ? el.value : [];
|
|
902
|
+
const bounded = isIsoDate(ends.min) && isIsoDate(ends.max) && ends.min <= ends.max;
|
|
903
|
+
const clamp = (iso) => !bounded ? iso : iso < ends.min ? ends.min : iso > ends.max ? ends.max : iso;
|
|
904
|
+
const a = isIsoDate(value[0]) ? clamp(value[0]) : bounded ? ends.min : '';
|
|
905
|
+
const b = isIsoDate(value[1]) ? clamp(value[1]) : bounded ? ends.max : '';
|
|
906
|
+
if (!a || !b)
|
|
907
|
+
return null;
|
|
908
|
+
return a <= b ? [a, b] : [b, b];
|
|
909
|
+
}
|
|
910
|
+
/** Show the date range's value. A `selected` that already spans it exactly is kept as written. */
|
|
911
|
+
pullPartner() {
|
|
912
|
+
const r = this.partnerRange();
|
|
913
|
+
if (!r)
|
|
775
914
|
return;
|
|
776
|
-
|
|
777
|
-
const to =
|
|
915
|
+
this.lastSeen = r.join('/');
|
|
916
|
+
const [from, to] = r;
|
|
778
917
|
if (this.isFullSpan(from, to)) {
|
|
779
918
|
if (this.selected) {
|
|
780
919
|
this.echo = true;
|
|
@@ -782,16 +921,31 @@ export class UvalibDateHistogram extends UvalibElement {
|
|
|
782
921
|
}
|
|
783
922
|
return;
|
|
784
923
|
}
|
|
785
|
-
|
|
924
|
+
// Compared as the range shows it, so a decade from before `min` (1810–1819 with a
|
|
925
|
+
// 1817 minimum) stays as chosen.
|
|
926
|
+
const cur = this.selected ? parseSelected(this.selected) : null;
|
|
927
|
+
const ends = this.partnerEnds();
|
|
928
|
+
const clamp = (iso) => ends && isIsoDate(ends.min) && isIsoDate(ends.max)
|
|
929
|
+
? iso < ends.min
|
|
930
|
+
? ends.min
|
|
931
|
+
: iso > ends.max
|
|
932
|
+
? ends.max
|
|
933
|
+
: iso
|
|
934
|
+
: iso;
|
|
935
|
+
if (cur && clamp(cur.from) === from && clamp(cur.to) === to)
|
|
936
|
+
return;
|
|
937
|
+
const next = isoToSelected(from, to, this.grain === 'month' ? 'month' : 'year');
|
|
786
938
|
if (!next || next === this.selected)
|
|
787
939
|
return;
|
|
788
940
|
this.echo = true;
|
|
789
941
|
this.selected = next;
|
|
790
942
|
}
|
|
791
|
-
|
|
792
|
-
|
|
793
|
-
|
|
794
|
-
|
|
943
|
+
/**
|
|
944
|
+
* Write `selected` to the date range. A `selected` that is only the range's own value
|
|
945
|
+
* rounded to this chart's buckets is not written back (that would widen the range),
|
|
946
|
+
* unless `force` (a visitor chose that bar again to take the whole bucket).
|
|
947
|
+
*/
|
|
948
|
+
pushPartner(force = false) {
|
|
795
949
|
const el = this.partner;
|
|
796
950
|
if (!el)
|
|
797
951
|
return;
|
|
@@ -806,7 +960,17 @@ export class UvalibDateHistogram extends UvalibElement {
|
|
|
806
960
|
const cur = el.value;
|
|
807
961
|
if (Array.isArray(cur) && cur[0] === next[0] && cur[1] === next[1])
|
|
808
962
|
return;
|
|
963
|
+
const r = this.partnerRange();
|
|
964
|
+
if (!force &&
|
|
965
|
+
r &&
|
|
966
|
+
this.selected &&
|
|
967
|
+
!this.isFullSpan(r[0], r[1]) &&
|
|
968
|
+
isoToSelected(r[0], r[1], this.grain === 'month' ? 'month' : 'year') === this.selected.trim()) {
|
|
969
|
+
this.lastSeen = r.join('/');
|
|
970
|
+
return;
|
|
971
|
+
}
|
|
809
972
|
el.value = next;
|
|
973
|
+
this.lastSeen = next.join('/');
|
|
810
974
|
}
|
|
811
975
|
emit(from, to) {
|
|
812
976
|
this.dispatchEvent(new CustomEvent('select', { detail: { from, to }, bubbles: true, composed: true }));
|
|
@@ -819,17 +983,19 @@ export class UvalibDateHistogram extends UvalibElement {
|
|
|
819
983
|
this.activeKey = key;
|
|
820
984
|
const token = this.selected.trim();
|
|
821
985
|
const bucket = keyToSpan(key);
|
|
986
|
+
// A decade selects its first to last year, the form a linked date range writes back.
|
|
987
|
+
const pick = this.grain === 'decade' && DECADE.test(key) ? decadeSelection(key) : key;
|
|
822
988
|
// A second click on the same token clears it. A stored month that only names part
|
|
823
989
|
// of the linked range (October 5–20 shown as 2015-10) expands to the whole bucket
|
|
824
990
|
// instead: assigning the same `selected` string would not run `pushPartner()`.
|
|
825
|
-
if (token === key) {
|
|
991
|
+
if (token === key || token === pick) {
|
|
826
992
|
const value = this.partner?.value;
|
|
827
993
|
const partial = !!bucket &&
|
|
828
994
|
Array.isArray(value) &&
|
|
829
995
|
value.length >= 2 &&
|
|
830
996
|
(value[0] !== bucket.from || value[1] !== bucket.to);
|
|
831
997
|
if (partial && bucket) {
|
|
832
|
-
this.pushPartner();
|
|
998
|
+
this.pushPartner(true);
|
|
833
999
|
this.emit(bucket.from, bucket.to);
|
|
834
1000
|
return;
|
|
835
1001
|
}
|
|
@@ -839,8 +1005,8 @@ export class UvalibDateHistogram extends UvalibElement {
|
|
|
839
1005
|
return;
|
|
840
1006
|
}
|
|
841
1007
|
this.choosing = true;
|
|
842
|
-
this.selected =
|
|
843
|
-
const span = parseSelected(
|
|
1008
|
+
this.selected = pick;
|
|
1009
|
+
const span = parseSelected(pick);
|
|
844
1010
|
this.emit(span?.from ?? key, span?.to ?? key);
|
|
845
1011
|
}
|
|
846
1012
|
onBarClick(e) {
|
|
@@ -853,7 +1019,12 @@ export class UvalibDateHistogram extends UvalibElement {
|
|
|
853
1019
|
const i = keys.indexOf(e.currentTarget.dataset.date ?? '');
|
|
854
1020
|
if (i < 0)
|
|
855
1021
|
return;
|
|
856
|
-
const
|
|
1022
|
+
const grain = this.grain;
|
|
1023
|
+
const step = grain === 'month' ? 12 : 1;
|
|
1024
|
+
// Decade rows are half-centuries that may start part-way, so up and down move 50 years.
|
|
1025
|
+
const row = (dir) => grain === 'decade'
|
|
1026
|
+
? keys.indexOf(decadeKey(Number(keys[i].slice(0, 4)) + dir * 50))
|
|
1027
|
+
: i + dir * step;
|
|
857
1028
|
let next = -1;
|
|
858
1029
|
switch (e.key) {
|
|
859
1030
|
case 'ArrowRight':
|
|
@@ -863,10 +1034,10 @@ export class UvalibDateHistogram extends UvalibElement {
|
|
|
863
1034
|
next = i - 1;
|
|
864
1035
|
break;
|
|
865
1036
|
case 'ArrowDown':
|
|
866
|
-
next =
|
|
1037
|
+
next = row(1);
|
|
867
1038
|
break;
|
|
868
1039
|
case 'ArrowUp':
|
|
869
|
-
next =
|
|
1040
|
+
next = row(-1);
|
|
870
1041
|
break;
|
|
871
1042
|
case 'Home':
|
|
872
1043
|
next = 0;
|
|
@@ -939,7 +1110,10 @@ export class UvalibDateHistogram extends UvalibElement {
|
|
|
939
1110
|
return true;
|
|
940
1111
|
if (parts.length !== 1)
|
|
941
1112
|
return false;
|
|
942
|
-
|
|
1113
|
+
const grain = this.grain;
|
|
1114
|
+
if (grain === 'decade')
|
|
1115
|
+
return /^\d{4}$/.test(trimmed) || DECADE.test(trimmed);
|
|
1116
|
+
return grain === 'year' ? /^\d{4}$/.test(trimmed) : /^\d{4}-\d{2}$/.test(trimmed);
|
|
943
1117
|
}
|
|
944
1118
|
overlaps(key, span) {
|
|
945
1119
|
if (!span || !isIsoDate(span.from) || !isIsoDate(span.to))
|
|
@@ -975,14 +1149,15 @@ export class UvalibDateHistogram extends UvalibElement {
|
|
|
975
1149
|
const selected = bars.find((b) => this.pressed(b.key, span));
|
|
976
1150
|
return selected?.key ?? keys[0] ?? '';
|
|
977
1151
|
}
|
|
978
|
-
barTemplate(bar, tab, span) {
|
|
979
|
-
const pct = barPercent(bar.count,
|
|
1152
|
+
barTemplate(bar, tab, span, max, column = 0) {
|
|
1153
|
+
const pct = barPercent(bar.count, max, this.log);
|
|
980
1154
|
const on = this.pressed(bar.key, span);
|
|
981
1155
|
return html `
|
|
982
1156
|
<button
|
|
983
1157
|
type="button"
|
|
984
1158
|
class="bar ${bar.count ? '' : 'is-empty'}"
|
|
985
1159
|
part="bar"
|
|
1160
|
+
style=${column ? `grid-column-start: ${column}` : nothing}
|
|
986
1161
|
data-date=${bar.key}
|
|
987
1162
|
tabindex=${bar.key === tab ? '0' : '-1'}
|
|
988
1163
|
aria-pressed=${on ? 'true' : 'false'}
|
|
@@ -996,11 +1171,32 @@ export class UvalibDateHistogram extends UvalibElement {
|
|
|
996
1171
|
}
|
|
997
1172
|
renderBars(model, span) {
|
|
998
1173
|
const tab = this.focusKey(model.bars);
|
|
999
|
-
|
|
1174
|
+
const grain = this.grain;
|
|
1175
|
+
if (grain === 'decade') {
|
|
1176
|
+
const rows = [...new Set(model.bars.map((b) => halfCentury(b.year)))];
|
|
1177
|
+
return html `
|
|
1178
|
+
<div class="scroller" role="group" aria-label=${this.labelText}>
|
|
1179
|
+
${rows.map((start) => {
|
|
1180
|
+
const inRow = model.bars.filter((b) => halfCentury(b.year) === start);
|
|
1181
|
+
// The first decade keeps its column, so decades line up from row to row.
|
|
1182
|
+
const column = (inRow[0].year - start) / 10 + 1;
|
|
1183
|
+
return html `
|
|
1184
|
+
<div class="year">
|
|
1185
|
+
<span class="year-label" aria-hidden="true">${start}</span>
|
|
1186
|
+
<div class="bars" role="group" aria-label=${`${start} to ${start + 49}`}>
|
|
1187
|
+
${repeat(inRow, (b) => b.key, (b, i) => this.barTemplate(b, tab, span, model.max, i === 0 ? column : 0))}
|
|
1188
|
+
</div>
|
|
1189
|
+
</div>
|
|
1190
|
+
`;
|
|
1191
|
+
})}
|
|
1192
|
+
</div>
|
|
1193
|
+
`;
|
|
1194
|
+
}
|
|
1195
|
+
if (grain === 'year') {
|
|
1000
1196
|
return html `
|
|
1001
1197
|
<div class="scroller" role="group" aria-label=${this.labelText}>
|
|
1002
1198
|
<div class="bars">
|
|
1003
|
-
${repeat(model.bars, (b) => b.key, (b) => this.barTemplate(b, tab, span))}
|
|
1199
|
+
${repeat(model.bars, (b) => b.key, (b) => this.barTemplate(b, tab, span, model.max))}
|
|
1004
1200
|
</div>
|
|
1005
1201
|
</div>
|
|
1006
1202
|
`;
|
|
@@ -1012,7 +1208,7 @@ export class UvalibDateHistogram extends UvalibElement {
|
|
|
1012
1208
|
<div class="year">
|
|
1013
1209
|
<span class="year-label" id=${`${this.uid}-${year}`}>${year}</span>
|
|
1014
1210
|
<div class="bars" role="group" aria-labelledby=${`${this.uid}-${year}`}>
|
|
1015
|
-
${repeat(model.bars.filter((b) => b.year === year), (b) => b.key, (b) => this.barTemplate(b, tab, span))}
|
|
1211
|
+
${repeat(model.bars.filter((b) => b.year === year), (b) => b.key, (b) => this.barTemplate(b, tab, span, model.max))}
|
|
1016
1212
|
</div>
|
|
1017
1213
|
</div>
|
|
1018
1214
|
`)}
|
|
@@ -1078,7 +1274,7 @@ export class UvalibDateHistogram extends UvalibElement {
|
|
|
1078
1274
|
${tableCaption(caption)}
|
|
1079
1275
|
<thead>
|
|
1080
1276
|
<tr>
|
|
1081
|
-
<th scope="col">${
|
|
1277
|
+
<th scope="col">${{ year: 'Year', decade: 'Decade', month: 'Date' }[this.grain]}</th>
|
|
1082
1278
|
<th scope="col">Count</th>
|
|
1083
1279
|
</tr>
|
|
1084
1280
|
</thead>
|
|
@@ -1146,34 +1342,42 @@ export class UvalibDateHistogram extends UvalibElement {
|
|
|
1146
1342
|
const size = 'var(--uvalib-date-histogram-bar-size, 8rem)';
|
|
1147
1343
|
if (this.grain === 'year')
|
|
1148
1344
|
return `min-block-size: ${size}`;
|
|
1149
|
-
return `min-block-size: calc(${this.
|
|
1345
|
+
return `min-block-size: calc(${this.reservedRows()} * (${size} + 0.5rem))`;
|
|
1150
1346
|
}
|
|
1151
|
-
|
|
1152
|
-
|
|
1347
|
+
/** Rows: one per year for months, one per half-century for decades. */
|
|
1348
|
+
reservedRows() {
|
|
1349
|
+
const grain = this.grain;
|
|
1350
|
+
const rowOf = (year) => (grain === 'decade' ? halfCentury(year) : year);
|
|
1351
|
+
const model = buildModel(this.data, grain);
|
|
1153
1352
|
if (model.bars.length)
|
|
1154
|
-
return new Set(model.bars.map((b) => b.year)).size;
|
|
1353
|
+
return new Set(model.bars.map((b) => rowOf(b.year))).size;
|
|
1155
1354
|
const partner = this.partner ?? this.findPartner();
|
|
1156
1355
|
if (!partner)
|
|
1157
1356
|
return 1;
|
|
1158
|
-
const
|
|
1159
|
-
|
|
1357
|
+
const a = /^(\d{4})/.exec((partner.min || partner.getAttribute('min') || '').trim());
|
|
1358
|
+
const b = /^(\d{4})/.exec((partner.max || partner.getAttribute('max') || '').trim());
|
|
1359
|
+
if (!a || !b)
|
|
1360
|
+
return 1;
|
|
1361
|
+
const [lo, hi] = [Number(a[1]), Number(b[1])].sort((x, y) => x - y);
|
|
1362
|
+
return grain === 'decade' ? (rowOf(hi) - rowOf(lo)) / 50 + 1 : hi - lo + 1;
|
|
1160
1363
|
}
|
|
1161
1364
|
renderStrip(model) {
|
|
1162
1365
|
const years = model.bars;
|
|
1163
1366
|
const total = years.reduce((s, b) => s + b.count, 0);
|
|
1164
1367
|
const span = parseSelected(this.selected);
|
|
1368
|
+
// A year bar's key is the year, a decade bar's is `1810s`.
|
|
1165
1369
|
const range = years.length === 0
|
|
1166
1370
|
? ''
|
|
1167
|
-
: years
|
|
1168
|
-
?
|
|
1169
|
-
: `${years[0].
|
|
1371
|
+
: years.length === 1
|
|
1372
|
+
? years[0].key
|
|
1373
|
+
: `${years[0].key} to ${years[years.length - 1].key}`;
|
|
1170
1374
|
let name = years.length
|
|
1171
1375
|
? `${this.labelText}: ${range}, ${total.toLocaleString('en-US')} ${unitWord(total, this.unit)}`
|
|
1172
1376
|
: `${this.labelText}: no dates`;
|
|
1173
1377
|
if (span && years.some((b) => this.pressed(b.key, span))) {
|
|
1174
1378
|
const on = years.filter((b) => this.pressed(b.key, span));
|
|
1175
|
-
const a = on[0].
|
|
1176
|
-
const b = on[on.length - 1].
|
|
1379
|
+
const a = on[0].key;
|
|
1380
|
+
const b = on[on.length - 1].key;
|
|
1177
1381
|
name += a === b ? `. Selected ${a}.` : `. Selected ${a} to ${b}.`;
|
|
1178
1382
|
}
|
|
1179
1383
|
return html `
|
|
@@ -1191,11 +1395,11 @@ export class UvalibDateHistogram extends UvalibElement {
|
|
|
1191
1395
|
`;
|
|
1192
1396
|
}
|
|
1193
1397
|
render() {
|
|
1194
|
-
const model = buildModel(this.data, this.strip ?
|
|
1398
|
+
const model = buildModel(this.data, this.strip ? this.stripGrain : this.grain);
|
|
1195
1399
|
if (this.strip)
|
|
1196
1400
|
return this.renderStrip(model);
|
|
1197
1401
|
const span = parseSelected(this.selected);
|
|
1198
|
-
const chartClass = this.grain
|
|
1402
|
+
const chartClass = `by-${this.grain}`;
|
|
1199
1403
|
return html `
|
|
1200
1404
|
<div class="chart ${chartClass}" part="chart">
|
|
1201
1405
|
<p class="scroll-hint" ?hidden=${!this.overflowing}>Scroll sideways to see more.</p>
|