@teipublisher/pb-components 2.26.1-next.3 → 3.0.0-next-4.1
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/.github/workflows/docker-cypress.yml +54 -0
- package/.github/workflows/main.yml +6 -4
- package/.github/workflows/node.js.yml +56 -21
- package/.github/workflows/release.js.yml +19 -17
- package/.releaserc.json +1 -1
- package/CHANGELOG.md +346 -11
- package/Dockerfile +78 -70
- package/README.md +112 -4
- package/css/components.css +5 -5
- package/css/gridjs/mermaid.min.css +1 -1
- package/css/leaflet/Control.Geocoder.css +1 -126
- package/css/leaflet/images/layers.png +0 -0
- package/css/tify/tify.css +6 -5
- package/css/tom-select/tom-select.bootstrap4.min.css +1 -1
- package/css/tom-select/tom-select.bootstrap5.min.css +1 -1
- package/css/tom-select/tom-select.default.min.css +1 -1
- package/css/tom-select/tom-select.default.min.css.map +1 -0
- package/css/tom-select/tom-select.min.css +1 -1
- package/cypress.config.js +84 -0
- package/dist/api.html +1 -1
- package/dist/css/design-system.css +607 -0
- package/dist/demo/bundle-test.html +4 -3
- package/dist/demo/components.css +46 -1
- package/dist/demo/design-system.html +710 -0
- package/dist/demo/dts-client.html +2 -2
- package/dist/demo/pb-autocomplete.html +23 -11
- package/dist/demo/pb-autocomplete2.html +66 -55
- package/dist/demo/pb-autocomplete3.html +17 -8
- package/dist/demo/pb-blacklab-highlight.html +28 -11
- package/dist/demo/pb-blacklab-results.html +3 -2
- package/dist/demo/pb-browse-docs.html +24 -24
- package/dist/demo/pb-browse-docs2.html +3 -3
- package/dist/demo/pb-clipboard.html +32 -28
- package/dist/demo/pb-code-editor.html +6 -6
- package/dist/demo/pb-code-highlight.html +63 -63
- package/dist/demo/pb-codepen.html +1 -1
- package/dist/demo/pb-collapse.html +1 -1
- package/dist/demo/pb-collapse2.html +2 -2
- package/dist/demo/pb-combo-box.html +135 -130
- package/dist/demo/pb-custom-form.html +64 -55
- package/dist/demo/pb-dialog.html +12 -6
- package/dist/demo/pb-document.html +1 -1
- package/dist/demo/pb-download.html +68 -59
- package/dist/demo/pb-drawer.html +67 -46
- package/dist/demo/pb-drawer2.html +65 -58
- package/dist/demo/pb-edit-app.html +2 -2
- package/dist/demo/pb-edit-xml.html +1 -1
- package/dist/demo/pb-facsimile-2.html +26 -11
- package/dist/demo/pb-facsimile-3.html +25 -10
- package/dist/demo/pb-facsimile-dedup-test-2.html +48 -0
- package/dist/demo/pb-facsimile-dedup-test.html +48 -0
- package/dist/demo/pb-facsimile.html +4 -4
- package/dist/demo/pb-formula.html +1 -1
- package/dist/demo/pb-grid.html +22 -8
- package/dist/demo/pb-highlight.html +2 -2
- package/dist/demo/pb-i18n-simple.html +1 -0
- package/dist/demo/pb-i18n.html +15 -5
- package/dist/demo/pb-image-strip-standalone.html +2 -2
- package/dist/demo/pb-image-strip-view.html +2 -2
- package/dist/demo/pb-leaflet-map.html +3 -3
- package/dist/demo/pb-leaflet-map2.html +2 -2
- package/dist/demo/pb-leaflet-map3.html +3 -3
- package/dist/demo/pb-link.html +1 -1
- package/dist/demo/pb-load.html +2 -6
- package/dist/demo/pb-login.html +1 -3
- package/dist/demo/pb-manage-odds.html +9 -4
- package/dist/demo/pb-markdown.html +1 -1
- package/dist/demo/pb-media-query.html +2 -2
- package/dist/demo/pb-mei.html +2 -2
- package/dist/demo/pb-mei2.html +2 -2
- package/dist/demo/pb-message.html +2 -3
- package/dist/demo/pb-odd-editor.html +54 -52
- package/dist/demo/pb-page-header.html +27 -0
- package/dist/demo/pb-popover.html +1 -1
- package/dist/demo/pb-print-preview.html +2 -2
- package/dist/demo/pb-progress.html +4 -4
- package/dist/demo/pb-repeat.html +32 -36
- package/dist/demo/pb-search.html +16 -5
- package/dist/demo/pb-search2.html +4 -4
- package/dist/demo/pb-search3.html +3 -3
- package/dist/demo/pb-search4.html +3 -3
- package/dist/demo/pb-select-feature.html +4 -4
- package/dist/demo/pb-select-feature2.html +4 -4
- package/dist/demo/pb-select-feature3.html +2 -2
- package/dist/demo/pb-select-i18n.html +58 -53
- package/dist/demo/pb-select-odd.html +1 -1
- package/dist/demo/pb-select.html +190 -75
- package/dist/demo/pb-select2.html +91 -37
- package/dist/demo/pb-select3.html +109 -41
- package/dist/demo/pb-svg.html +1 -1
- package/dist/demo/pb-table-grid.html +26 -15
- package/dist/demo/pb-tabs.html +15 -7
- package/dist/demo/pb-tify.html +7 -7
- package/dist/demo/pb-timeline.html +1 -1
- package/dist/demo/pb-timeline2.html +1 -1
- package/dist/demo/pb-toggle-feature.html +26 -23
- package/dist/demo/pb-toggle-feature2.html +4 -4
- package/dist/demo/pb-toggle-feature3.html +2 -2
- package/dist/demo/pb-toggle-feature4.html +56 -54
- package/dist/demo/pb-version.html +2 -2
- package/dist/demo/pb-view.html +78 -40
- package/dist/demo/pb-view2.html +69 -46
- package/dist/demo/pb-view3.html +53 -48
- package/dist/demo/pb-view4.html +70 -49
- package/dist/demo/pb-zoom.html +2 -2
- package/dist/{es-global-bridge-d8ce175d.js → es-global-bridge-D8ZcUcx_.js} +0 -4
- package/dist/focus-mixin-VCsFap6b.js +768 -0
- package/dist/images/icons.svg +217 -0
- package/dist/jinn-codemirror-DETLdm08.js +1 -0
- package/dist/lib/openseadragon.min.js +80 -0
- package/dist/lib/openseadragon.min.js.map +1 -0
- package/dist/pb-code-editor.js +25 -20
- package/dist/pb-component-docs.js +414 -3225
- package/dist/pb-components-bundle.js +3046 -4402
- package/dist/pb-dialog-tklYGWfc.js +121 -0
- package/dist/pb-edit-app.js +208 -107
- package/dist/pb-elements.json +716 -249
- package/dist/pb-facsimile.js +46 -0
- package/dist/pb-i18n-C0NDma4h.js +1 -0
- package/dist/pb-leaflet-map.js +23 -23
- package/dist/pb-mei.js +152 -134
- package/dist/pb-mixin-DHoWQheB.js +1 -0
- package/dist/pb-odd-editor.js +1671 -1231
- package/dist/pb-tify.js +1 -27
- package/dist/unsafe-html-D5VGo9Oq.js +1 -0
- package/dist/urls-BEONu_g4.js +1 -0
- package/eslint.config.mjs +92 -0
- package/gh-pages.js +5 -3
- package/i18n/common/en.json +6 -0
- package/i18n/common/pl.json +2 -2
- package/images/icons.svg +217 -0
- package/index.html +0 -5
- package/lib/leaflet-src.js.map +1 -0
- package/lib/leaflet.markercluster-src.js.map +1 -0
- package/lib/openseadragon.min.js +6 -6
- package/package.json +56 -81
- package/pb-elements.json +716 -249
- package/rollup.config.mjs +312 -0
- package/src/assets/components.css +5 -5
- package/src/assets/design-system.css +607 -0
- package/src/authority/airtable.js +20 -21
- package/src/authority/anton.js +129 -129
- package/src/authority/custom.js +70 -27
- package/src/authority/geonames.js +38 -32
- package/src/authority/gnd.js +50 -42
- package/src/authority/kbga.js +136 -134
- package/src/authority/metagrid.js +44 -46
- package/src/authority/reconciliation.js +66 -68
- package/src/authority/registry.js +4 -4
- package/src/docs/demo-utils.js +91 -0
- package/src/docs/pb-component-docs.js +287 -147
- package/src/docs/pb-component-view.js +380 -273
- package/src/docs/pb-components-list.js +115 -51
- package/src/docs/pb-demo-snippet.js +199 -174
- package/src/dts-client.js +306 -303
- package/src/dts-select-endpoint.js +125 -85
- package/src/parse-date-service.js +184 -135
- package/src/pb-ajax.js +175 -173
- package/src/pb-authority-lookup.js +198 -158
- package/src/pb-autocomplete.js +731 -313
- package/src/pb-blacklab-highlight.js +266 -260
- package/src/pb-blacklab-results.js +230 -225
- package/src/pb-browse-docs.js +601 -484
- package/src/pb-browse.js +68 -65
- package/src/pb-clipboard.js +97 -76
- package/src/pb-code-editor.js +111 -103
- package/src/pb-code-highlight.js +234 -204
- package/src/pb-codepen.js +81 -73
- package/src/pb-collapse.js +265 -152
- package/src/pb-combo-box.js +191 -191
- package/src/pb-components-bundle.js +1 -7
- package/src/pb-components.js +2 -6
- package/src/pb-custom-form.js +230 -141
- package/src/pb-dialog.js +99 -63
- package/src/pb-document.js +118 -91
- package/src/pb-download.js +214 -198
- package/src/pb-drawer.js +146 -149
- package/src/pb-edit-app.js +471 -240
- package/src/pb-edit-xml.js +101 -98
- package/src/pb-events.js +126 -107
- package/src/pb-facs-link.js +130 -101
- package/src/pb-facsimile.js +494 -410
- package/src/pb-fetch.js +389 -0
- package/src/pb-formula.js +152 -154
- package/src/pb-geolocation.js +130 -132
- package/src/pb-grid-action.js +59 -56
- package/src/pb-grid.js +388 -228
- package/src/pb-highlight.js +142 -142
- package/src/pb-hotkeys.js +40 -42
- package/src/pb-i18n.js +115 -127
- package/src/pb-icon-button.js +108 -0
- package/src/pb-icon.js +283 -0
- package/src/pb-image-strip.js +85 -79
- package/src/pb-lang.js +142 -57
- package/src/pb-leaflet-map.js +551 -483
- package/src/pb-link.js +132 -126
- package/src/pb-load.js +495 -428
- package/src/pb-login.js +303 -248
- package/src/pb-manage-odds.js +384 -338
- package/src/pb-map-icon.js +90 -90
- package/src/pb-map-layer.js +86 -86
- package/src/pb-markdown.js +107 -110
- package/src/pb-media-query.js +75 -73
- package/src/pb-mei.js +523 -303
- package/src/pb-message.js +144 -98
- package/src/pb-mixin.js +268 -265
- package/src/pb-navigation.js +83 -96
- package/src/pb-observable.js +39 -39
- package/src/pb-odd-editor.js +1209 -948
- package/src/pb-odd-elementspec-editor.js +375 -310
- package/src/pb-odd-model-editor.js +1189 -941
- package/src/pb-odd-parameter-editor.js +269 -170
- package/src/pb-odd-rendition-editor.js +184 -131
- package/src/pb-page.js +451 -422
- package/src/pb-paginate.js +260 -178
- package/src/pb-panel.js +217 -183
- package/src/pb-popover-themes.js +16 -9
- package/src/pb-popover.js +297 -288
- package/src/pb-print-preview.js +128 -128
- package/src/pb-progress.js +52 -52
- package/src/pb-repeat.js +141 -108
- package/src/pb-restricted.js +85 -78
- package/src/pb-search.js +258 -230
- package/src/pb-select-feature.js +210 -126
- package/src/pb-select-odd.js +184 -118
- package/src/pb-select-template.js +113 -78
- package/src/pb-select.js +330 -229
- package/src/pb-split-list.js +181 -176
- package/src/pb-svg.js +81 -80
- package/src/pb-table-column.js +55 -55
- package/src/pb-table-grid.js +334 -205
- package/src/pb-tabs.js +238 -61
- package/src/pb-tify.js +3331 -126
- package/src/pb-timeline.js +394 -255
- package/src/pb-toggle-feature.js +196 -188
- package/src/pb-upload.js +201 -176
- package/src/pb-version.js +22 -34
- package/src/pb-view-annotate.js +138 -102
- package/src/pb-view.js +1722 -1272
- package/src/pb-zoom.js +144 -46
- package/src/search-result-service.js +256 -223
- package/src/seed-element.js +14 -22
- package/src/settings.js +4 -4
- package/src/theming.js +98 -91
- package/src/urls.js +403 -289
- package/src/utils.js +53 -51
- package/vite.config.js +86 -0
- package/css/pb-styles.css +0 -51
- package/dist/iron-form-3b8dcaa7.js +0 -210
- package/dist/jinn-codemirror-da0e2d1f.js +0 -1
- package/dist/paper-checkbox-515a5284.js +0 -1597
- package/dist/paper-icon-button-b1d31571.js +0 -398
- package/dist/paper-listbox-a3b7175c.js +0 -1265
- package/dist/pb-i18n-0611135a.js +0 -1
- package/dist/pb-mixin-b1caa22e.js +0 -158
- package/dist/polymer-hack.js +0 -1
- package/dist/vaadin-element-mixin-fe4a4883.js +0 -527
- package/lib/Control.Geocoder.min.js +0 -2
- package/lib/Control.Geocoder.min.js.map +0 -1
- package/src/assets/pb-styles.css +0 -51
- package/src/pb-light-dom.js +0 -41
- package/src/polymer-hack.js +0 -6
|
@@ -1,30 +1,30 @@
|
|
|
1
|
-
import { get as i18n } from
|
|
1
|
+
import { get as i18n } from './pb-i18n.js';
|
|
2
2
|
|
|
3
3
|
export class SearchResultService {
|
|
4
4
|
/*
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
5
|
+
* SEARCH RESULT OBJECT
|
|
6
|
+
* Service that loads initial data from a datasource,
|
|
7
|
+
* can be a database or an API, and converts it in
|
|
8
|
+
* a format that can be used by the pb-timeline component.
|
|
9
|
+
*
|
|
10
|
+
* public methods:
|
|
11
|
+
* getMinDateStr()
|
|
12
|
+
* getMaxDateStr()
|
|
13
|
+
* getMinDate()
|
|
14
|
+
* getMaxDate()
|
|
15
|
+
* export()
|
|
16
|
+
* getIntervalSizes()
|
|
17
|
+
*/
|
|
18
18
|
|
|
19
19
|
/*
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
constructor(jsonData = {}, maxInterval = 60, scopes = [
|
|
20
|
+
* CONSRTUCTOR INPUTS EXPLAINED
|
|
21
|
+
* jsonData: data to load, object with
|
|
22
|
+
* keys => valid datestrings formatted YYYY-MM-DD
|
|
23
|
+
* values => number of results for this day
|
|
24
|
+
* maxInterval: max amount of bins allowed
|
|
25
|
+
* scopes: array of all 6 possible values for scope
|
|
26
|
+
*/
|
|
27
|
+
constructor(jsonData = {}, maxInterval = 60, scopes = ['D', 'W', 'M', 'Y', '5Y', '10Y']) {
|
|
28
28
|
this.data = { invalid: {}, valid: {} };
|
|
29
29
|
this.maxInterval = maxInterval;
|
|
30
30
|
this.scopes = scopes;
|
|
@@ -32,20 +32,23 @@ export class SearchResultService {
|
|
|
32
32
|
}
|
|
33
33
|
|
|
34
34
|
/*
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
35
|
+
* based on the loaded jsonData, compute
|
|
36
|
+
* - min date as dateStr or utc-date-object
|
|
37
|
+
* - max date as dateStr or utc-date-object
|
|
38
|
+
*/
|
|
39
39
|
getMinDateStr() {
|
|
40
40
|
return Object.keys(this.data.valid).sort()[0];
|
|
41
41
|
}
|
|
42
|
+
|
|
42
43
|
getMaxDateStr() {
|
|
43
|
-
|
|
44
|
+
const days = Object.keys(this.data.valid);
|
|
44
45
|
return days.sort()[days.length - 1];
|
|
45
46
|
}
|
|
47
|
+
|
|
46
48
|
getMinDate() {
|
|
47
49
|
return this._dateStrToUTCDate(this.getMinDateStr());
|
|
48
50
|
}
|
|
51
|
+
|
|
49
52
|
getMaxDate() {
|
|
50
53
|
return this._dateStrToUTCDate(this.getMaxDateStr());
|
|
51
54
|
}
|
|
@@ -53,25 +56,27 @@ export class SearchResultService {
|
|
|
53
56
|
getEndOfRangeDate(scope, date) {
|
|
54
57
|
return this._UTCDateToDateStr(this._increaseDateBy(scope, date));
|
|
55
58
|
}
|
|
56
|
-
|
|
59
|
+
|
|
57
60
|
/*
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
61
|
+
* exports data for each scope
|
|
62
|
+
* when no argument is provided, the optimal scope based
|
|
63
|
+
* on the maxInterval (default 60) will be assigned
|
|
64
|
+
*/
|
|
62
65
|
export(scope) {
|
|
63
66
|
// auto assign scope when no argument provided
|
|
64
67
|
scope = scope || this._autoAssignScope();
|
|
65
68
|
// validate scope
|
|
66
69
|
if (!this.scopes.includes(scope)) {
|
|
67
|
-
throw new Error(
|
|
70
|
+
throw new Error(
|
|
71
|
+
`invalid scope provided, expected: ["10Y", "5Y", "Y", "M", "W", "D"]. Got: "${scope}"`,
|
|
72
|
+
);
|
|
68
73
|
}
|
|
69
74
|
// initialize object to export
|
|
70
75
|
const exportData = {
|
|
71
76
|
data: [],
|
|
72
|
-
scope
|
|
73
|
-
binTitleRotated: this._binTitleRotatedLookup(scope)
|
|
74
|
-
}
|
|
77
|
+
scope,
|
|
78
|
+
binTitleRotated: this._binTitleRotatedLookup(scope),
|
|
79
|
+
};
|
|
75
80
|
if (Object.keys(this.data.valid).length === 0) {
|
|
76
81
|
return exportData;
|
|
77
82
|
}
|
|
@@ -88,29 +93,31 @@ export class SearchResultService {
|
|
|
88
93
|
currentDate = this._increaseDateBy(scope, currentDate);
|
|
89
94
|
}
|
|
90
95
|
// count all values
|
|
91
|
-
Object.keys(this.data.valid)
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
const
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
if (value
|
|
99
|
-
targetBinObject.
|
|
96
|
+
Object.keys(this.data.valid)
|
|
97
|
+
.sort()
|
|
98
|
+
.forEach(dateStr => {
|
|
99
|
+
const currentCategory = this._classify(dateStr, scope);
|
|
100
|
+
const targetBinObject = exportData.data.find(it => it.category === currentCategory);
|
|
101
|
+
try {
|
|
102
|
+
const value = this.data.valid[dateStr];
|
|
103
|
+
if (typeof value === 'object') {
|
|
104
|
+
targetBinObject.value += value.count || 0;
|
|
105
|
+
if (value.info) {
|
|
106
|
+
targetBinObject.info = targetBinObject.info.concat(value.info);
|
|
107
|
+
}
|
|
108
|
+
} else {
|
|
109
|
+
targetBinObject.value += this.data.valid[dateStr] || 0;
|
|
100
110
|
}
|
|
101
|
-
}
|
|
102
|
-
|
|
111
|
+
} catch (e) {
|
|
112
|
+
console.log(e);
|
|
113
|
+
console.log('currentCategory');
|
|
114
|
+
console.log(currentCategory);
|
|
103
115
|
}
|
|
104
|
-
}
|
|
105
|
-
console.log(e);
|
|
106
|
-
console.log("currentCategory");
|
|
107
|
-
console.log(currentCategory);
|
|
108
|
-
}
|
|
109
|
-
});
|
|
116
|
+
});
|
|
110
117
|
if (this.data.invalid) {
|
|
111
118
|
let invalid = 0;
|
|
112
119
|
let info = [];
|
|
113
|
-
Object.values(this.data.invalid).forEach(
|
|
120
|
+
Object.values(this.data.invalid).forEach(value => {
|
|
114
121
|
if (typeof value === 'object') {
|
|
115
122
|
invalid += value.count || 0;
|
|
116
123
|
info = info.concat(value.info);
|
|
@@ -126,7 +133,7 @@ export class SearchResultService {
|
|
|
126
133
|
category: '?',
|
|
127
134
|
separator: true,
|
|
128
135
|
value: invalid,
|
|
129
|
-
info
|
|
136
|
+
info,
|
|
130
137
|
});
|
|
131
138
|
}
|
|
132
139
|
}
|
|
@@ -134,67 +141,73 @@ export class SearchResultService {
|
|
|
134
141
|
}
|
|
135
142
|
|
|
136
143
|
/*
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
144
|
+
* returns optimal scope based on the maxInterval
|
|
145
|
+
* by computing the scope that meets the criteria
|
|
146
|
+
* nbr of bins <= maxInterval
|
|
147
|
+
*/
|
|
141
148
|
_autoAssignScope() {
|
|
142
149
|
for (let i = 0; i < this.scopes.length; i++) {
|
|
143
150
|
if (this._computeIntervalSize(this.scopes[i]) <= this.maxInterval) {
|
|
144
151
|
return this.scopes[i];
|
|
145
152
|
}
|
|
146
153
|
}
|
|
147
|
-
throw new Error(
|
|
154
|
+
throw new Error(
|
|
155
|
+
`Interval too big! Computed: ${this._computeIntervalSize(this.scopes[i])}. Allowed: ${
|
|
156
|
+
this.maxInterval
|
|
157
|
+
}. Try to increase maxInterval.`,
|
|
158
|
+
);
|
|
148
159
|
}
|
|
149
160
|
|
|
150
161
|
/*
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
162
|
+
* splits input data in 2 sections
|
|
163
|
+
* => valid data
|
|
164
|
+
* => invalid (if not a vaid date, for example 2012-00-00 is invalid)
|
|
165
|
+
*/
|
|
155
166
|
_validateJsonData(jsonData) {
|
|
156
|
-
Object.keys(jsonData)
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
167
|
+
Object.keys(jsonData)
|
|
168
|
+
.sort()
|
|
169
|
+
.forEach(key => {
|
|
170
|
+
if (this._isValidDateStr(key)) {
|
|
171
|
+
this.data.valid[key] = jsonData[key];
|
|
172
|
+
} else {
|
|
173
|
+
this.data.invalid[key] = jsonData[key];
|
|
174
|
+
}
|
|
175
|
+
});
|
|
163
176
|
}
|
|
164
177
|
|
|
165
178
|
/*
|
|
166
|
-
|
|
167
|
-
|
|
179
|
+
* lookup table which bin titles should be rotated
|
|
180
|
+
*/
|
|
168
181
|
_binTitleRotatedLookup(scope) {
|
|
169
182
|
const lookup = {
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
}
|
|
183
|
+
'10Y': true,
|
|
184
|
+
'5Y': true,
|
|
185
|
+
Y: true,
|
|
186
|
+
M: false, // only exception not to rotate in monthly scope
|
|
187
|
+
W: true,
|
|
188
|
+
D: true,
|
|
189
|
+
};
|
|
177
190
|
return lookup[scope];
|
|
178
191
|
}
|
|
179
192
|
|
|
180
193
|
/*
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
194
|
+
* Helper method that builds a binObject that
|
|
195
|
+
* can be read by the pb-timeline component
|
|
196
|
+
*/
|
|
184
197
|
_buildBinObject(dateStr, category, scope) {
|
|
185
|
-
const split = dateStr.split(
|
|
198
|
+
const split = dateStr.split('-');
|
|
186
199
|
const yearStr = split[0];
|
|
187
200
|
const monthStr = split[1];
|
|
188
201
|
const dayStr = split[2];
|
|
189
202
|
// for all scopes this remains the same
|
|
190
203
|
const binObject = {
|
|
191
|
-
dateStr
|
|
192
|
-
category
|
|
204
|
+
dateStr,
|
|
205
|
+
category,
|
|
193
206
|
value: 0,
|
|
194
|
-
info: []
|
|
195
|
-
}
|
|
207
|
+
info: [],
|
|
208
|
+
};
|
|
196
209
|
// scope specific bin data
|
|
197
|
-
if (scope ===
|
|
210
|
+
if (scope === '10Y') {
|
|
198
211
|
binObject.tooltip = `${category} - ${Number(category) + 9}`; // 1900 - 1999
|
|
199
212
|
binObject.selectionStart = `${category}`;
|
|
200
213
|
binObject.selectionEnd = `${Number(category) + 9}`;
|
|
@@ -203,8 +216,8 @@ export class SearchResultService {
|
|
|
203
216
|
binObject.title = `${category} - ${Number(category) + 99}`;
|
|
204
217
|
binObject.binTitle = category;
|
|
205
218
|
binObject.seperator = true;
|
|
206
|
-
}
|
|
207
|
-
} else if (scope ===
|
|
219
|
+
}
|
|
220
|
+
} else if (scope === '5Y') {
|
|
208
221
|
binObject.tooltip = `${category} - ${Number(category) + 4}`; // 1995 - 1999
|
|
209
222
|
binObject.selectionStart = `${category}`;
|
|
210
223
|
binObject.selectionEnd = `${Number(category) + 4}`;
|
|
@@ -214,7 +227,7 @@ export class SearchResultService {
|
|
|
214
227
|
binObject.binTitle = category;
|
|
215
228
|
binObject.seperator = true;
|
|
216
229
|
}
|
|
217
|
-
} else if (scope ===
|
|
230
|
+
} else if (scope === 'Y') {
|
|
218
231
|
binObject.tooltip = category;
|
|
219
232
|
binObject.selectionStart = category;
|
|
220
233
|
binObject.selectionEnd = category;
|
|
@@ -224,7 +237,7 @@ export class SearchResultService {
|
|
|
224
237
|
binObject.binTitle = `${category}`;
|
|
225
238
|
binObject.seperator = true;
|
|
226
239
|
}
|
|
227
|
-
} else if (scope ===
|
|
240
|
+
} else if (scope === 'M') {
|
|
228
241
|
const monthNum = Number(monthStr);
|
|
229
242
|
const month = this._monthLookup(monthNum); // Jan,Feb,Mar,...,Nov,Dez
|
|
230
243
|
binObject.binTitle = month[0]; // J,F,M,A,M,J,J,..N,D
|
|
@@ -236,122 +249,134 @@ export class SearchResultService {
|
|
|
236
249
|
binObject.title = yearStr; // YYYY
|
|
237
250
|
binObject.seperator = true;
|
|
238
251
|
}
|
|
239
|
-
} else if (scope ===
|
|
240
|
-
const week = category.split(
|
|
252
|
+
} else if (scope === 'W') {
|
|
253
|
+
const week = category.split('-')[1]; // => W52
|
|
241
254
|
binObject.tooltip = `${yearStr} ${week}`; // 1996 W52
|
|
242
255
|
binObject.selectionStart = `${yearStr} ${week}`; // 1996 W52
|
|
243
256
|
binObject.selectionEnd = `${yearStr} ${week}`; // 1996 W52
|
|
244
|
-
|
|
245
|
-
|
|
257
|
+
const currentDate = this._dateStrToUTCDate(dateStr);
|
|
258
|
+
const lastWeek = this._addDays(currentDate, -7);
|
|
246
259
|
// title and binTitle every first monday of the month
|
|
247
260
|
if (currentDate.getUTCMonth() !== lastWeek.getUTCMonth()) {
|
|
248
261
|
binObject.binTitle = week;
|
|
249
262
|
binObject.title = this._monthLookup(currentDate.getUTCMonth() + 1);
|
|
250
263
|
}
|
|
251
264
|
// seperator every start of the year
|
|
252
|
-
binObject.seperator = week ===
|
|
253
|
-
} else if (scope ===
|
|
265
|
+
binObject.seperator = week === 'W1';
|
|
266
|
+
} else if (scope === 'D') {
|
|
254
267
|
binObject.tooltip = dateStr;
|
|
255
268
|
binObject.selectionStart = dateStr;
|
|
256
269
|
binObject.selectionEnd = dateStr;
|
|
257
270
|
// every monday
|
|
258
271
|
if (this._dateStrToUTCDate(dateStr).getUTCDay() === 1) {
|
|
259
272
|
binObject.binTitle = `${Number(dayStr)}.${Number(monthStr)}`;
|
|
260
|
-
binObject.title = `${this._classify(dateStr,
|
|
273
|
+
binObject.title = `${this._classify(dateStr, 'W').replace('-', ' ')}`;
|
|
261
274
|
binObject.seperator = true;
|
|
262
275
|
}
|
|
263
276
|
} else {
|
|
264
|
-
throw new Error(
|
|
277
|
+
throw new Error(
|
|
278
|
+
`invalid scope provided, expected: ["10Y", "5Y", "Y", "M", "W", "D"]. Got: "${scope}"`,
|
|
279
|
+
);
|
|
265
280
|
}
|
|
266
281
|
return binObject;
|
|
267
282
|
}
|
|
268
283
|
|
|
269
284
|
/*
|
|
270
|
-
|
|
271
|
-
|
|
272
|
-
|
|
273
|
-
|
|
274
|
-
|
|
275
|
-
|
|
276
|
-
|
|
277
|
-
|
|
278
|
-
|
|
279
|
-
_classify(dateStr, scope) {
|
|
280
|
-
|
|
285
|
+
* ...classifies dateStr into category (based on scope)
|
|
286
|
+
* EXAMPLES:
|
|
287
|
+
* _classify("2016-01-12", "10Y") // => "2010"
|
|
288
|
+
* _classify("2016-01-12", "5Y") // => "2015"
|
|
289
|
+
* _classify("2016-01-12", "Y") // => "2016"
|
|
290
|
+
* _classify("2016-01-12", "M") // => "2010-01"
|
|
291
|
+
* _classify("2016-01-12", "W") // => "2016-W2"
|
|
292
|
+
* _classify("2016-01-12", "D") // => "2016-01-12"
|
|
293
|
+
*/
|
|
294
|
+
_classify(dateStr, scope) {
|
|
295
|
+
// returns category (as string)
|
|
296
|
+
if (!dateStr.match(/^\d{4}-\d{2}-\d{2}$/)) {
|
|
297
|
+
// quick validate dateStr
|
|
281
298
|
throw new Error(`invalid dateStr format, expected "YYYY-MM-DD", got: "${dateStr}".`);
|
|
282
299
|
}
|
|
283
|
-
if (!dateStr || !scope) {
|
|
300
|
+
if (!dateStr || !scope) {
|
|
301
|
+
// both inputs provided
|
|
284
302
|
throw new Error(`both inputs must be provided. Got dateStr=${dateStr}, scope=${scope}`);
|
|
285
303
|
}
|
|
286
304
|
switch (scope) {
|
|
287
|
-
case
|
|
288
|
-
|
|
289
|
-
const
|
|
305
|
+
case '10Y':
|
|
306
|
+
case '5Y':
|
|
307
|
+
const intervalSize = Number(scope.replace('Y', ''));
|
|
308
|
+
const startYear = Math.floor(Number(dateStr.split('-')[0]) / intervalSize) * intervalSize;
|
|
290
309
|
return startYear.toString();
|
|
291
|
-
case
|
|
310
|
+
case 'Y':
|
|
292
311
|
return dateStr.substr(0, 4);
|
|
293
|
-
case
|
|
312
|
+
case 'M':
|
|
294
313
|
return dateStr.substr(0, 7);
|
|
295
|
-
case
|
|
314
|
+
case 'W':
|
|
296
315
|
const UTCDate = this._dateStrToUTCDate(dateStr);
|
|
297
316
|
return this._UTCDateToWeekFormat(UTCDate);
|
|
298
|
-
case
|
|
317
|
+
case 'D':
|
|
299
318
|
return dateStr;
|
|
300
319
|
}
|
|
301
320
|
}
|
|
302
321
|
|
|
303
322
|
/*
|
|
304
|
-
|
|
305
|
-
|
|
306
|
-
|
|
307
|
-
|
|
308
|
-
|
|
309
|
-
|
|
323
|
+
* ...gets first day as UTC Date, based on the category
|
|
324
|
+
* EXAMPLES:
|
|
325
|
+
* _getFirstDay("2010") // => 2010-01-01
|
|
326
|
+
* _getFirstDay("2010-12") // => 2010-12-01
|
|
327
|
+
* _getFirstDay("2010-W10") // => 2010-03-08
|
|
328
|
+
*/
|
|
310
329
|
_getFirstDay(categoryStr) {
|
|
311
|
-
if (categoryStr.match(/^\d{4}-\d{2}-\d{2}$/)) {
|
|
330
|
+
if (categoryStr.match(/^\d{4}-\d{2}-\d{2}$/)) {
|
|
331
|
+
// YYYY-MM-DD => return same value
|
|
312
332
|
return categoryStr;
|
|
313
333
|
}
|
|
314
|
-
if (categoryStr.match(/^\d{4}-\d{2}$/)) {
|
|
315
|
-
|
|
334
|
+
if (categoryStr.match(/^\d{4}-\d{2}$/)) {
|
|
335
|
+
// YYYY-MM
|
|
336
|
+
return `${categoryStr}-01`; // add -01
|
|
316
337
|
}
|
|
317
|
-
if (categoryStr.match(/^\d{4}$/)) {
|
|
318
|
-
|
|
338
|
+
if (categoryStr.match(/^\d{4}$/)) {
|
|
339
|
+
// YYYY
|
|
340
|
+
return `${categoryStr}-01-01`; // add -01-01
|
|
319
341
|
}
|
|
320
|
-
if (categoryStr.match(/^\d{4}-W([1-9]|[1-4][0-9]|5[0-3])$/)) {
|
|
342
|
+
if (categoryStr.match(/^\d{4}-W([1-9]|[1-4][0-9]|5[0-3])$/)) {
|
|
343
|
+
// YYYY-W? // ? => [1-53]
|
|
321
344
|
// |YYYY-W |1-9 | 10-49 | 50-53 |
|
|
322
|
-
const split = categoryStr.split(
|
|
345
|
+
const split = categoryStr.split('-');
|
|
323
346
|
const year = Number(split[0]);
|
|
324
|
-
const weekNumber = Number(split[1].replace(
|
|
347
|
+
const weekNumber = Number(split[1].replace('W', ''));
|
|
325
348
|
return this._getDateStrOfISOWeek(year, weekNumber);
|
|
326
349
|
}
|
|
327
|
-
throw new Error(
|
|
350
|
+
throw new Error('invalid categoryStr');
|
|
328
351
|
}
|
|
329
352
|
|
|
330
353
|
/*
|
|
331
|
-
|
|
332
|
-
|
|
354
|
+
* converts dateStr (YYYY-MM-DD) to a date object in UTC time
|
|
355
|
+
*/
|
|
333
356
|
_dateStrToUTCDate(dateStr) {
|
|
334
357
|
if (!this._isValidDateStr(dateStr)) {
|
|
335
|
-
throw new Error(
|
|
358
|
+
throw new Error(
|
|
359
|
+
`invalid dateStr, expected "YYYY-MM-DD" with month[1-12] and day[1-31], got: "${dateStr}".`,
|
|
360
|
+
);
|
|
336
361
|
}
|
|
337
|
-
const split = dateStr.split(
|
|
338
|
-
const year
|
|
362
|
+
const split = dateStr.split('-');
|
|
363
|
+
const year = Number(split[0]);
|
|
339
364
|
const month = Number(split[1]);
|
|
340
|
-
const day
|
|
365
|
+
const day = Number(split[2]);
|
|
341
366
|
return new Date(Date.UTC(year, month - 1, day));
|
|
342
367
|
}
|
|
343
368
|
|
|
344
369
|
/*
|
|
345
|
-
|
|
346
|
-
|
|
370
|
+
* converts a UTC date object to a dateStr (YYYY-MM-DD)
|
|
371
|
+
*/
|
|
347
372
|
_UTCDateToDateStr(UTCDate) {
|
|
348
|
-
return UTCDate.toISOString().split(
|
|
373
|
+
return UTCDate.toISOString().split('T')[0];
|
|
349
374
|
}
|
|
350
375
|
|
|
351
376
|
/*
|
|
352
|
-
|
|
353
|
-
|
|
354
|
-
|
|
377
|
+
* example:
|
|
378
|
+
* 1 Jan 2020 => 2020-W1
|
|
379
|
+
*/
|
|
355
380
|
_UTCDateToWeekFormat(UTCDate) {
|
|
356
381
|
const year = this._getISOWeekYear(UTCDate);
|
|
357
382
|
const weekNbr = this._getISOWeek(UTCDate);
|
|
@@ -362,56 +387,63 @@ export class SearchResultService {
|
|
|
362
387
|
* returns the ISO week (_getISOWeek) or year (_getISOWeekYear)
|
|
363
388
|
* as number based on a UTC date.
|
|
364
389
|
*/
|
|
365
|
-
_getISOWeek(UTCDate) {
|
|
366
|
-
|
|
390
|
+
_getISOWeek(UTCDate) {
|
|
391
|
+
// https://weeknumber.net/how-to/javascript
|
|
392
|
+
const date = new Date(UTCDate.getTime());
|
|
367
393
|
date.setHours(0, 0, 0, 0);
|
|
368
394
|
// Thursday in current week decides the year.
|
|
369
|
-
date.setDate(date.getDate() + 3 - (date.getDay() + 6) % 7);
|
|
395
|
+
date.setDate(date.getDate() + 3 - ((date.getDay() + 6) % 7));
|
|
370
396
|
// January 4 is always in week 1.
|
|
371
|
-
|
|
397
|
+
const week1 = new Date(date.getFullYear(), 0, 4);
|
|
372
398
|
// Adjust to Thursday in week 1 and count number of weeks from date to week1.
|
|
373
|
-
return
|
|
374
|
-
|
|
399
|
+
return (
|
|
400
|
+
1 +
|
|
401
|
+
Math.round(
|
|
402
|
+
((date.getTime() - week1.getTime()) / 86400000 - 3 + ((week1.getDay() + 6) % 7)) / 7,
|
|
403
|
+
)
|
|
404
|
+
);
|
|
375
405
|
}
|
|
406
|
+
|
|
376
407
|
/*
|
|
377
|
-
|
|
378
|
-
|
|
379
|
-
|
|
380
|
-
|
|
381
|
-
_getISOWeekYear(UTCDate) {
|
|
382
|
-
|
|
383
|
-
date
|
|
408
|
+
* returns the ISO week year as number based on a UTC date
|
|
409
|
+
* this is only needed for rollovers, for example:
|
|
410
|
+
* => 1.jan 2011 is in W52 of year 2010.
|
|
411
|
+
*/
|
|
412
|
+
_getISOWeekYear(UTCDate) {
|
|
413
|
+
// https://weeknumber.net/how-to/javascript
|
|
414
|
+
const date = new Date(UTCDate.getTime());
|
|
415
|
+
date.setDate(date.getDate() + 3 - ((date.getDay() + 6) % 7));
|
|
384
416
|
return date.getFullYear();
|
|
385
417
|
}
|
|
386
418
|
|
|
387
419
|
/*
|
|
388
|
-
|
|
389
|
-
|
|
390
|
-
_getDateStrOfISOWeek(year, weekNumber) {
|
|
391
|
-
|
|
392
|
-
|
|
393
|
-
|
|
394
|
-
|
|
395
|
-
|
|
396
|
-
else
|
|
397
|
-
|
|
398
|
-
return ISOweekStart.toISOString().split("T")[0];
|
|
420
|
+
* given the year and weeknumber -> return dateStr (YYYY-MM-DD)
|
|
421
|
+
*/
|
|
422
|
+
_getDateStrOfISOWeek(year, weekNumber) {
|
|
423
|
+
// https://stackoverflow.com/a/16591175/6272061
|
|
424
|
+
const simple = new Date(Date.UTC(year, 0, 1 + (weekNumber - 1) * 7));
|
|
425
|
+
const dow = simple.getUTCDay();
|
|
426
|
+
const ISOweekStart = simple;
|
|
427
|
+
if (dow <= 4) ISOweekStart.setDate(simple.getDate() - simple.getUTCDay() + 1);
|
|
428
|
+
else ISOweekStart.setDate(simple.getDate() + 8 - simple.getUTCDay());
|
|
429
|
+
return ISOweekStart.toISOString().split('T')[0];
|
|
399
430
|
}
|
|
400
431
|
|
|
401
432
|
/*
|
|
402
|
-
|
|
403
|
-
|
|
404
|
-
|
|
433
|
+
* compute the interval sizes based on the scope
|
|
434
|
+
* prediction only, not the actuall export of the data
|
|
435
|
+
*/
|
|
405
436
|
getIntervalSizes() {
|
|
406
437
|
return {
|
|
407
|
-
|
|
408
|
-
|
|
409
|
-
|
|
410
|
-
|
|
411
|
-
|
|
412
|
-
|
|
413
|
-
}
|
|
438
|
+
D: this._computeIntervalSize('D'),
|
|
439
|
+
W: this._computeIntervalSize('W'),
|
|
440
|
+
M: this._computeIntervalSize('M'),
|
|
441
|
+
Y: this._computeIntervalSize('Y'),
|
|
442
|
+
'5Y': this._computeIntervalSize('5Y'),
|
|
443
|
+
'10Y': this._computeIntervalSize('10Y'),
|
|
444
|
+
};
|
|
414
445
|
}
|
|
446
|
+
|
|
415
447
|
_computeIntervalSize(scope) {
|
|
416
448
|
const maxDate = this.getMaxDateStr();
|
|
417
449
|
if (!maxDate) {
|
|
@@ -427,65 +459,68 @@ export class SearchResultService {
|
|
|
427
459
|
}
|
|
428
460
|
return count;
|
|
429
461
|
}
|
|
462
|
+
|
|
430
463
|
_increaseDateBy(scope, date) {
|
|
431
464
|
switch (scope) {
|
|
432
|
-
case
|
|
465
|
+
case 'D':
|
|
433
466
|
return this._addDays(date, 1);
|
|
434
|
-
case
|
|
467
|
+
case 'W':
|
|
435
468
|
return this._addDays(date, 7);
|
|
436
|
-
case
|
|
469
|
+
case 'M':
|
|
437
470
|
return this._addMonths(date, 1);
|
|
438
|
-
case
|
|
471
|
+
case 'Y':
|
|
439
472
|
return this._addYears(date, 1);
|
|
440
|
-
case
|
|
473
|
+
case '5Y':
|
|
441
474
|
return this._addYears(date, 5);
|
|
442
|
-
case
|
|
475
|
+
case '10Y':
|
|
443
476
|
return this._addYears(date, 10);
|
|
444
477
|
}
|
|
445
478
|
}
|
|
446
479
|
|
|
447
480
|
/*
|
|
448
|
-
|
|
449
|
-
|
|
450
|
-
|
|
451
|
-
|
|
481
|
+
* functions that add n days (_addDays), months (_addMonths)
|
|
482
|
+
* or years (_addYears) to a UTC date object
|
|
483
|
+
* returns the computed new UTC date
|
|
484
|
+
*/
|
|
452
485
|
_addDays(UTCDate, days) {
|
|
453
|
-
|
|
486
|
+
const newUTCDate = new Date(UTCDate.valueOf());
|
|
454
487
|
newUTCDate.setUTCDate(newUTCDate.getUTCDate() + days);
|
|
455
488
|
return newUTCDate;
|
|
456
489
|
}
|
|
490
|
+
|
|
457
491
|
_addMonths(UTCdate, months) {
|
|
458
|
-
|
|
459
|
-
|
|
492
|
+
const newUTCDate = new Date(UTCdate.valueOf());
|
|
493
|
+
const d = newUTCDate.getUTCDate();
|
|
460
494
|
newUTCDate.setUTCMonth(newUTCDate.getUTCMonth() + +months);
|
|
461
495
|
if (newUTCDate.getUTCDate() != d) {
|
|
462
496
|
newUTCDate.setUTCDate(0);
|
|
463
497
|
}
|
|
464
498
|
return newUTCDate;
|
|
465
499
|
}
|
|
500
|
+
|
|
466
501
|
_addYears(UTCdate, years) {
|
|
467
|
-
|
|
502
|
+
const newUTCDate = new Date(UTCdate.valueOf());
|
|
468
503
|
newUTCDate.setUTCFullYear(newUTCDate.getUTCFullYear() + years);
|
|
469
504
|
return newUTCDate;
|
|
470
505
|
}
|
|
471
506
|
|
|
472
507
|
/*
|
|
473
|
-
|
|
474
|
-
|
|
475
|
-
|
|
476
|
-
|
|
477
|
-
|
|
508
|
+
* Validates dateStr. rules:
|
|
509
|
+
* => year: 4 digit number
|
|
510
|
+
* => month: [1-12]
|
|
511
|
+
* => day: [1-31]
|
|
512
|
+
*/
|
|
478
513
|
_isValidDateStr(str) {
|
|
479
514
|
if (!str) {
|
|
480
515
|
return false;
|
|
481
516
|
}
|
|
482
517
|
|
|
483
|
-
|
|
518
|
+
const split = str.split('-');
|
|
484
519
|
if (split.length !== 3) return false;
|
|
485
|
-
|
|
486
|
-
|
|
487
|
-
|
|
488
|
-
if (year ===
|
|
520
|
+
const year = split[0];
|
|
521
|
+
const month = split[1];
|
|
522
|
+
const day = split[2];
|
|
523
|
+
if (year === '0000' || day === '00' || month === '00') return false;
|
|
489
524
|
if (Number(day) < 1 || Number(day) > 31) return false;
|
|
490
525
|
if (Number(month) < 1 || Number(month) > 12) return false;
|
|
491
526
|
// if all checks are passed => valid datestring!
|
|
@@ -493,29 +528,27 @@ export class SearchResultService {
|
|
|
493
528
|
}
|
|
494
529
|
|
|
495
530
|
/*
|
|
496
|
-
|
|
497
|
-
|
|
498
|
-
|
|
531
|
+
* Converts month number (str or number) to a 3 char
|
|
532
|
+
* abbreviation of the month (in english)
|
|
533
|
+
*/
|
|
499
534
|
_monthLookup(num) {
|
|
500
535
|
if (num > 12 || num < 1) {
|
|
501
536
|
throw new Error(`invalid 'num' provided, expected 1-12. Got: ${num}`);
|
|
502
537
|
}
|
|
503
538
|
const lookup = {
|
|
504
|
-
|
|
505
|
-
|
|
506
|
-
|
|
507
|
-
|
|
508
|
-
|
|
509
|
-
|
|
510
|
-
|
|
511
|
-
|
|
512
|
-
|
|
513
|
-
|
|
514
|
-
|
|
515
|
-
|
|
516
|
-
}
|
|
539
|
+
1: 'Jan',
|
|
540
|
+
2: 'Feb',
|
|
541
|
+
3: 'Mar',
|
|
542
|
+
4: 'Apr',
|
|
543
|
+
5: 'May',
|
|
544
|
+
6: 'Jun',
|
|
545
|
+
7: 'Jul',
|
|
546
|
+
8: 'Aug',
|
|
547
|
+
9: 'Sep',
|
|
548
|
+
10: 'Oct',
|
|
549
|
+
11: 'Nov',
|
|
550
|
+
12: 'Dec',
|
|
551
|
+
};
|
|
517
552
|
return lookup[num.toString()];
|
|
518
553
|
}
|
|
519
554
|
}
|
|
520
|
-
|
|
521
|
-
|