@internetarchive/histogram-date-range 1.2.2-alpha-webdev7377.8 → 1.3.1-alpha-webdev7745.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/.github/workflows/ci.yml +2 -2
- package/demo/index.html +4 -4
- package/dist/src/dayjs/fix-first-century-years.d.ts +2 -0
- package/dist/src/dayjs/fix-first-century-years.js +25 -0
- package/dist/src/dayjs/fix-first-century-years.js.map +1 -0
- package/dist/src/dayjs/fix-two-digit-dates.d.ts +2 -0
- package/dist/src/dayjs/fix-two-digit-dates.js +25 -0
- package/dist/src/dayjs/fix-two-digit-dates.js.map +1 -0
- package/dist/src/histogram-date-range.d.ts +13 -2
- package/dist/src/histogram-date-range.js +71 -35
- package/dist/src/histogram-date-range.js.map +1 -1
- package/dist/src/plugins/fix-first-century-years.d.ts +23 -0
- package/dist/src/plugins/fix-first-century-years.js +43 -0
- package/dist/src/plugins/fix-first-century-years.js.map +1 -0
- package/dist/test/histogram-date-range.test.js +214 -5
- package/dist/test/histogram-date-range.test.js.map +1 -1
- package/docs/_snowpack/pkg/common/directive-d639fc45.js +8 -0
- package/docs/_snowpack/pkg/import-map.json +1 -0
- package/docs/_snowpack/pkg/lit/directives/class-map.js +10 -0
- package/docs/_snowpack/pkg/lit/directives/live.js +3 -9
- package/docs/demo/index.html +4 -4
- package/docs/dist/src/histogram-date-range.js +37 -25
- package/docs/dist/src/plugins/fix-first-century-years.js +19 -0
- package/package.json +1 -1
- package/src/histogram-date-range.ts +73 -36
- package/src/plugins/fix-first-century-years.ts +52 -0
- package/test/histogram-date-range.test.ts +255 -5
- package/types/dayjs.d.ts +10 -0
package/.github/workflows/ci.yml
CHANGED
package/demo/index.html
CHANGED
|
@@ -80,7 +80,7 @@
|
|
|
80
80
|
</div>
|
|
81
81
|
|
|
82
82
|
<div class="container">
|
|
83
|
-
<div class="description">bins
|
|
83
|
+
<div class="description">bins snapped to nearest month</div>
|
|
84
84
|
<histogram-date-range
|
|
85
85
|
width="175"
|
|
86
86
|
tooltipwidth="120"
|
|
@@ -95,14 +95,14 @@
|
|
|
95
95
|
</div>
|
|
96
96
|
|
|
97
97
|
<div class="container">
|
|
98
|
-
<div class="description">bins
|
|
98
|
+
<div class="description">bins snapped to nearest year</div>
|
|
99
99
|
<histogram-date-range
|
|
100
100
|
width="175"
|
|
101
101
|
dateFormat="YYYY"
|
|
102
102
|
binSnapping="year"
|
|
103
103
|
minDate="2009"
|
|
104
|
-
maxDate="
|
|
105
|
-
bins="[100,
|
|
104
|
+
maxDate="2018"
|
|
105
|
+
bins="[100,1000,10000,100,1000,10000,100,1000,10000,100]"
|
|
106
106
|
></histogram-date-range>
|
|
107
107
|
</div>
|
|
108
108
|
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
export function fixFirstCenturyYears(_, cls) {
|
|
2
|
+
const proto = cls.prototype;
|
|
3
|
+
const oldParse = proto.parse;
|
|
4
|
+
proto.parse = function (cfg) {
|
|
5
|
+
this.__lastDate = cfg === null || cfg === void 0 ? void 0 : cfg.date;
|
|
6
|
+
this.__lastFormat = cfg === null || cfg === void 0 ? void 0 : cfg.args[1];
|
|
7
|
+
oldParse.call(this, cfg);
|
|
8
|
+
const isProblemDateRange = this.$y >= 1900 && this.$y < 2000;
|
|
9
|
+
const isProblemStringFormat = typeof this.__lastFormat === 'string' &&
|
|
10
|
+
this.__lastFormat.includes('YYYY');
|
|
11
|
+
const isProblemArrayFormat = Array.isArray(this.__lastFormat) &&
|
|
12
|
+
typeof this.__lastFormat[1] === 'string' &&
|
|
13
|
+
this.__lastFormat[1].includes('YYYY');
|
|
14
|
+
const isProblemFormat = isProblemStringFormat || isProblemArrayFormat;
|
|
15
|
+
const missingParsedYear = typeof this.__lastDate === 'string' &&
|
|
16
|
+
!this.__lastDate.includes(`${this.$y}`);
|
|
17
|
+
if (isProblemDateRange && isProblemFormat && missingParsedYear) {
|
|
18
|
+
const old = new Date(this.$d);
|
|
19
|
+
this.$d.setFullYear(this.$y - 1900);
|
|
20
|
+
this.init();
|
|
21
|
+
console.log('fixed year', this.__lastDate, this.__lastFormat, old, this.$d);
|
|
22
|
+
}
|
|
23
|
+
};
|
|
24
|
+
}
|
|
25
|
+
//# sourceMappingURL=fix-first-century-years.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"fix-first-century-years.js","sourceRoot":"","sources":["../../../src/dayjs/fix-first-century-years.ts"],"names":[],"mappings":"AAEA,MAAM,UAAU,oBAAoB,CAAC,CAAU,EAAE,GAAuB;IACtE,MAAM,KAAK,GAAG,GAAG,CAAC,SAAS,CAAC;IAC5B,MAAM,QAAQ,GAAG,KAAK,CAAC,KAAK,CAAC;IAC7B,KAAK,CAAC,KAAK,GAAG,UAAU,GAAG;QACzB,IAAI,CAAC,UAAU,GAAG,GAAG,aAAH,GAAG,uBAAH,GAAG,CAAE,IAAI,CAAC;QAC5B,IAAI,CAAC,YAAY,GAAG,GAAG,aAAH,GAAG,uBAAH,GAAG,CAAE,IAAI,CAAC,CAAC,CAAC,CAAC;QACjC,QAAQ,CAAC,IAAI,CAAC,IAAI,EAAE,GAAG,CAAC,CAAC;QAEzB,MAAM,kBAAkB,GAAG,IAAI,CAAC,EAAE,IAAI,IAAI,IAAI,IAAI,CAAC,EAAE,GAAG,IAAI,CAAC;QAC7D,MAAM,qBAAqB,GACzB,OAAO,IAAI,CAAC,YAAY,KAAK,QAAQ;YACrC,IAAI,CAAC,YAAY,CAAC,QAAQ,CAAC,MAAM,CAAC,CAAC;QACrC,MAAM,oBAAoB,GACxB,KAAK,CAAC,OAAO,CAAC,IAAI,CAAC,YAAY,CAAC;YAChC,OAAO,IAAI,CAAC,YAAY,CAAC,CAAC,CAAC,KAAK,QAAQ;YACxC,IAAI,CAAC,YAAY,CAAC,CAAC,CAAC,CAAC,QAAQ,CAAC,MAAM,CAAC,CAAC;QACxC,MAAM,eAAe,GAAG,qBAAqB,IAAI,oBAAoB,CAAC;QACtE,MAAM,iBAAiB,GACrB,OAAO,IAAI,CAAC,UAAU,KAAK,QAAQ;YACnC,CAAC,IAAI,CAAC,UAAU,CAAC,QAAQ,CAAC,GAAG,IAAI,CAAC,EAAE,EAAE,CAAC,CAAC;QAE1C,IAAI,kBAAkB,IAAI,eAAe,IAAI,iBAAiB,EAAE;YAC9D,MAAM,GAAG,GAAG,IAAI,IAAI,CAAC,IAAI,CAAC,EAAE,CAAC,CAAC;YAC9B,IAAI,CAAC,EAAE,CAAC,WAAW,CAAC,IAAI,CAAC,EAAE,GAAG,IAAI,CAAC,CAAC;YACpC,IAAI,CAAC,IAAI,EAAE,CAAC;YACZ,OAAO,CAAC,GAAG,CAAC,YAAY,EAAE,IAAI,CAAC,UAAU,EAAE,IAAI,CAAC,YAAY,EAAE,GAAG,EAAE,IAAI,CAAC,EAAE,CAAC,CAAC;SAC7E;IACH,CAAC,CAAC;AACJ,CAAC","sourcesContent":["import dayjs from 'dayjs/esm';\n\nexport function fixFirstCenturyYears(_: unknown, cls: typeof dayjs.Dayjs) {\n const proto = cls.prototype;\n const oldParse = proto.parse;\n proto.parse = function (cfg) {\n this.__lastDate = cfg?.date;\n this.__lastFormat = cfg?.args[1];\n oldParse.call(this, cfg);\n\n const isProblemDateRange = this.$y >= 1900 && this.$y < 2000;\n const isProblemStringFormat =\n typeof this.__lastFormat === 'string' &&\n this.__lastFormat.includes('YYYY');\n const isProblemArrayFormat =\n Array.isArray(this.__lastFormat) &&\n typeof this.__lastFormat[1] === 'string' &&\n this.__lastFormat[1].includes('YYYY');\n const isProblemFormat = isProblemStringFormat || isProblemArrayFormat;\n const missingParsedYear = \n typeof this.__lastDate === 'string' &&\n !this.__lastDate.includes(`${this.$y}`);\n \n if (isProblemDateRange && isProblemFormat && missingParsedYear) {\n const old = new Date(this.$d);\n this.$d.setFullYear(this.$y - 1900);\n this.init();\n console.log('fixed year', this.__lastDate, this.__lastFormat, old, this.$d);\n }\n };\n}"]}
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
export function fixFirstCenturyYears(_, cls) {
|
|
2
|
+
const proto = cls.prototype;
|
|
3
|
+
const oldParse = proto.parse;
|
|
4
|
+
proto.parse = function (cfg) {
|
|
5
|
+
this.__lastDate = cfg === null || cfg === void 0 ? void 0 : cfg.date;
|
|
6
|
+
this.__lastFormat = cfg === null || cfg === void 0 ? void 0 : cfg.args[1];
|
|
7
|
+
oldParse.call(this, cfg);
|
|
8
|
+
const isProblemDateRange = this.$y >= 1900 && this.$y < 2000;
|
|
9
|
+
const isProblemStringFormat = typeof this.__lastFormat === 'string' &&
|
|
10
|
+
this.__lastFormat.includes('YYYY');
|
|
11
|
+
const isProblemArrayFormat = Array.isArray(this.__lastFormat) &&
|
|
12
|
+
typeof this.__lastFormat[1] === 'string' &&
|
|
13
|
+
this.__lastFormat[1].includes('YYYY');
|
|
14
|
+
const isProblemFormat = isProblemStringFormat || isProblemArrayFormat;
|
|
15
|
+
const missingParsedYear = typeof this.__lastDate === 'string' &&
|
|
16
|
+
!this.__lastDate.includes(`${this.$y}`);
|
|
17
|
+
if (isProblemDateRange && isProblemFormat && missingParsedYear) {
|
|
18
|
+
const old = new Date(this.$d);
|
|
19
|
+
this.$d.setFullYear(this.$y - 1900);
|
|
20
|
+
this.init();
|
|
21
|
+
console.log('fixed year', this.__lastDate, this.__lastFormat, old, this.$d);
|
|
22
|
+
}
|
|
23
|
+
};
|
|
24
|
+
}
|
|
25
|
+
//# sourceMappingURL=fix-two-digit-dates.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"fix-two-digit-dates.js","sourceRoot":"","sources":["../../../src/dayjs/fix-two-digit-dates.ts"],"names":[],"mappings":"AAEA,MAAM,UAAU,oBAAoB,CAAC,CAAU,EAAE,GAAuB;IACtE,MAAM,KAAK,GAAG,GAAG,CAAC,SAAS,CAAC;IAC5B,MAAM,QAAQ,GAAG,KAAK,CAAC,KAAK,CAAC;IAC7B,KAAK,CAAC,KAAK,GAAG,UAAU,GAAG;QACzB,IAAI,CAAC,UAAU,GAAG,GAAG,aAAH,GAAG,uBAAH,GAAG,CAAE,IAAI,CAAC;QAC5B,IAAI,CAAC,YAAY,GAAG,GAAG,aAAH,GAAG,uBAAH,GAAG,CAAE,IAAI,CAAC,CAAC,CAAC,CAAC;QACjC,QAAQ,CAAC,IAAI,CAAC,IAAI,EAAE,GAAG,CAAC,CAAC;QAEzB,MAAM,kBAAkB,GAAG,IAAI,CAAC,EAAE,IAAI,IAAI,IAAI,IAAI,CAAC,EAAE,GAAG,IAAI,CAAC;QAC7D,MAAM,qBAAqB,GACzB,OAAO,IAAI,CAAC,YAAY,KAAK,QAAQ;YACrC,IAAI,CAAC,YAAY,CAAC,QAAQ,CAAC,MAAM,CAAC,CAAC;QACrC,MAAM,oBAAoB,GACxB,KAAK,CAAC,OAAO,CAAC,IAAI,CAAC,YAAY,CAAC;YAChC,OAAO,IAAI,CAAC,YAAY,CAAC,CAAC,CAAC,KAAK,QAAQ;YACxC,IAAI,CAAC,YAAY,CAAC,CAAC,CAAC,CAAC,QAAQ,CAAC,MAAM,CAAC,CAAC;QACxC,MAAM,eAAe,GAAG,qBAAqB,IAAI,oBAAoB,CAAC;QACtE,MAAM,iBAAiB,GACrB,OAAO,IAAI,CAAC,UAAU,KAAK,QAAQ;YACnC,CAAC,IAAI,CAAC,UAAU,CAAC,QAAQ,CAAC,GAAG,IAAI,CAAC,EAAE,EAAE,CAAC,CAAC;QAE1C,IAAI,kBAAkB,IAAI,eAAe,IAAI,iBAAiB,EAAE;YAC9D,MAAM,GAAG,GAAG,IAAI,IAAI,CAAC,IAAI,CAAC,EAAE,CAAC,CAAC;YAC9B,IAAI,CAAC,EAAE,CAAC,WAAW,CAAC,IAAI,CAAC,EAAE,GAAG,IAAI,CAAC,CAAC;YACpC,IAAI,CAAC,IAAI,EAAE,CAAC;YACZ,OAAO,CAAC,GAAG,CAAC,YAAY,EAAE,IAAI,CAAC,UAAU,EAAE,IAAI,CAAC,YAAY,EAAE,GAAG,EAAE,IAAI,CAAC,EAAE,CAAC,CAAC;SAC7E;IACH,CAAC,CAAC;AACJ,CAAC","sourcesContent":["import dayjs from 'dayjs/esm';\n\nexport function fixFirstCenturyYears(_: unknown, cls: typeof dayjs.Dayjs) {\n const proto = cls.prototype;\n const oldParse = proto.parse;\n proto.parse = function (cfg) {\n this.__lastDate = cfg?.date;\n this.__lastFormat = cfg?.args[1];\n oldParse.call(this, cfg);\n\n const isProblemDateRange = this.$y >= 1900 && this.$y < 2000;\n const isProblemStringFormat =\n typeof this.__lastFormat === 'string' &&\n this.__lastFormat.includes('YYYY');\n const isProblemArrayFormat =\n Array.isArray(this.__lastFormat) &&\n typeof this.__lastFormat[1] === 'string' &&\n this.__lastFormat[1].includes('YYYY');\n const isProblemFormat = isProblemStringFormat || isProblemArrayFormat;\n const missingParsedYear = \n typeof this.__lastDate === 'string' &&\n !this.__lastDate.includes(`${this.$y}`);\n \n if (isProblemDateRange && isProblemFormat && missingParsedYear) {\n const old = new Date(this.$d);\n this.$d.setFullYear(this.$y - 1900);\n this.init();\n console.log('fixed year', this.__lastDate, this.__lastFormat, old, this.$d);\n }\n };\n}"]}
|
|
@@ -16,7 +16,17 @@ export declare class HistogramDateRange extends LitElement {
|
|
|
16
16
|
bins: number[];
|
|
17
17
|
/** If true, update events will not be canceled by the date inputs receiving focus */
|
|
18
18
|
updateWhileFocused: boolean;
|
|
19
|
-
/**
|
|
19
|
+
/**
|
|
20
|
+
* What interval bins should be snapped to for determining their time ranges.
|
|
21
|
+
* - `none` (default): Bins should each represent an identical duration of time,
|
|
22
|
+
* without regard for the actual dates represented.
|
|
23
|
+
* - `month`: Bins should each represent one or more full, non-overlapping months.
|
|
24
|
+
* The bin ranges will be "snapped" to the nearest month boundaries, which can
|
|
25
|
+
* result in bins that represent different amounts of time, particularly if the
|
|
26
|
+
* provided bins do not evenly divide the provided date range, or if the months
|
|
27
|
+
* represented are of different lengths.
|
|
28
|
+
* - `year`: Same as `month`, but snapping to year boundaries instead of months.
|
|
29
|
+
*/
|
|
20
30
|
binSnapping: BinSnappingInterval;
|
|
21
31
|
private _tooltipOffset;
|
|
22
32
|
private _tooltipContent?;
|
|
@@ -76,7 +86,8 @@ export declare class HistogramDateRange extends LitElement {
|
|
|
76
86
|
*/
|
|
77
87
|
private get snapInterval();
|
|
78
88
|
/**
|
|
79
|
-
* Offset added to the end of each bin to ensure
|
|
89
|
+
* Offset added to the end of each bin to ensure disjoint intervals,
|
|
90
|
+
* depending on whether snapping is enabled and there are multiple bins.
|
|
80
91
|
*/
|
|
81
92
|
private get snapEndOffset();
|
|
82
93
|
/**
|
|
@@ -2,10 +2,13 @@ import { __decorate } from "tslib";
|
|
|
2
2
|
import '@internetarchive/ia-activity-indicator';
|
|
3
3
|
import dayjs from 'dayjs/esm';
|
|
4
4
|
import customParseFormat from 'dayjs/esm/plugin/customParseFormat';
|
|
5
|
+
import fixFirstCenturyYears from './plugins/fix-first-century-years';
|
|
5
6
|
import { css, html, LitElement, nothing, svg, } from 'lit';
|
|
6
7
|
import { customElement, property, state } from 'lit/decorators.js';
|
|
7
8
|
import { live } from 'lit/directives/live.js';
|
|
9
|
+
import { classMap } from 'lit/directives/class-map.js';
|
|
8
10
|
dayjs.extend(customParseFormat);
|
|
11
|
+
dayjs.extend(fixFirstCenturyYears);
|
|
9
12
|
// these values can be overridden via the component's HTML (camelCased) attributes
|
|
10
13
|
const WIDTH = 180;
|
|
11
14
|
const HEIGHT = 40;
|
|
@@ -51,7 +54,17 @@ let HistogramDateRange = class HistogramDateRange extends LitElement {
|
|
|
51
54
|
this.bins = [];
|
|
52
55
|
/** If true, update events will not be canceled by the date inputs receiving focus */
|
|
53
56
|
this.updateWhileFocused = false;
|
|
54
|
-
/**
|
|
57
|
+
/**
|
|
58
|
+
* What interval bins should be snapped to for determining their time ranges.
|
|
59
|
+
* - `none` (default): Bins should each represent an identical duration of time,
|
|
60
|
+
* without regard for the actual dates represented.
|
|
61
|
+
* - `month`: Bins should each represent one or more full, non-overlapping months.
|
|
62
|
+
* The bin ranges will be "snapped" to the nearest month boundaries, which can
|
|
63
|
+
* result in bins that represent different amounts of time, particularly if the
|
|
64
|
+
* provided bins do not evenly divide the provided date range, or if the months
|
|
65
|
+
* represented are of different lengths.
|
|
66
|
+
* - `year`: Same as `month`, but snapping to year boundaries instead of months.
|
|
67
|
+
*/
|
|
55
68
|
this.binSnapping = 'none';
|
|
56
69
|
// internal reactive properties not exposed as attributes
|
|
57
70
|
this._tooltipOffset = 0;
|
|
@@ -141,7 +154,8 @@ let HistogramDateRange = class HistogramDateRange extends LitElement {
|
|
|
141
154
|
}
|
|
142
155
|
this._histWidth = this.width - this.sliderWidth * 2;
|
|
143
156
|
this._minDateMS = this.snapTimestamp(this.getMSFromString(this.minDate));
|
|
144
|
-
// NB: The max date string, converted as-is to ms, represents the
|
|
157
|
+
// NB: The max date string, converted as-is to ms, represents the *start* of the
|
|
158
|
+
// final date interval; we want the *end*, so we add any snap interval/offset.
|
|
145
159
|
this._maxDateMS =
|
|
146
160
|
this.snapTimestamp(this.getMSFromString(this.maxDate) + this.snapInterval) + this.snapEndOffset;
|
|
147
161
|
this._binWidth = this._histWidth / this._numBins;
|
|
@@ -166,11 +180,16 @@ let HistogramDateRange = class HistogramDateRange extends LitElement {
|
|
|
166
180
|
* while dates past the 15th are rounded up.
|
|
167
181
|
*/
|
|
168
182
|
snapToMonth(timestamp) {
|
|
169
|
-
const d =
|
|
170
|
-
const
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
183
|
+
const d = dayjs(timestamp);
|
|
184
|
+
const monthsToAdd = d.date() < 16 ? 0 : 1;
|
|
185
|
+
const snapped = d
|
|
186
|
+
.add(monthsToAdd, 'month')
|
|
187
|
+
.date(1)
|
|
188
|
+
.hour(0)
|
|
189
|
+
.minute(0)
|
|
190
|
+
.second(0)
|
|
191
|
+
.millisecond(0); // First millisecond of the month
|
|
192
|
+
return snapped.valueOf();
|
|
174
193
|
}
|
|
175
194
|
/**
|
|
176
195
|
* Rounds the given timestamp to the (approximate) nearest start of a year,
|
|
@@ -178,11 +197,17 @@ let HistogramDateRange = class HistogramDateRange extends LitElement {
|
|
|
178
197
|
* July or later are rounded up.
|
|
179
198
|
*/
|
|
180
199
|
snapToYear(timestamp) {
|
|
181
|
-
const d =
|
|
182
|
-
const
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
200
|
+
const d = dayjs(timestamp);
|
|
201
|
+
const yearsToAdd = d.month() < 6 ? 0 : 1;
|
|
202
|
+
const snapped = d
|
|
203
|
+
.add(yearsToAdd, 'year')
|
|
204
|
+
.month(0)
|
|
205
|
+
.date(1)
|
|
206
|
+
.hour(0)
|
|
207
|
+
.minute(0)
|
|
208
|
+
.second(0)
|
|
209
|
+
.millisecond(0); // First millisecond of the year
|
|
210
|
+
return snapped.valueOf();
|
|
186
211
|
}
|
|
187
212
|
/**
|
|
188
213
|
* Rounds the given timestamp according to the `binSnapping` property.
|
|
@@ -196,6 +221,7 @@ let HistogramDateRange = class HistogramDateRange extends LitElement {
|
|
|
196
221
|
return this.snapToMonth(timestamp);
|
|
197
222
|
case 'none':
|
|
198
223
|
default:
|
|
224
|
+
// We still align it to second boundaries to resolve minor discrepancies
|
|
199
225
|
return this.snapToNextSecond(timestamp);
|
|
200
226
|
}
|
|
201
227
|
}
|
|
@@ -263,7 +289,8 @@ let HistogramDateRange = class HistogramDateRange extends LitElement {
|
|
|
263
289
|
}
|
|
264
290
|
}
|
|
265
291
|
/**
|
|
266
|
-
* Offset added to the end of each bin to ensure
|
|
292
|
+
* Offset added to the end of each bin to ensure disjoint intervals,
|
|
293
|
+
* depending on whether snapping is enabled and there are multiple bins.
|
|
267
294
|
*/
|
|
268
295
|
get snapEndOffset() {
|
|
269
296
|
return this.binSnapping !== 'none' && this._numBins > 1 ? -1 : 0;
|
|
@@ -273,8 +300,8 @@ let HistogramDateRange = class HistogramDateRange extends LitElement {
|
|
|
273
300
|
* Falls back to `dateFormat` if not provided.
|
|
274
301
|
*/
|
|
275
302
|
get tooltipDateFormat() {
|
|
276
|
-
var _a
|
|
277
|
-
return (
|
|
303
|
+
var _a;
|
|
304
|
+
return (_a = this._tooltipDateFormat) !== null && _a !== void 0 ? _a : this.dateFormat;
|
|
278
305
|
}
|
|
279
306
|
set tooltipDateFormat(value) {
|
|
280
307
|
this._tooltipDateFormat = value;
|
|
@@ -578,13 +605,16 @@ let HistogramDateRange = class HistogramDateRange extends LitElement {
|
|
|
578
605
|
// whether the curved part of the slider is facing towards the left (1), ie
|
|
579
606
|
// minimum, or facing towards the right (-1), ie maximum
|
|
580
607
|
const k = id === 'slider-min' ? 1 : -1;
|
|
608
|
+
const sliderClasses = classMap({
|
|
609
|
+
slider: true,
|
|
610
|
+
draggable: !this.disabled,
|
|
611
|
+
dragging: this._isDragging,
|
|
612
|
+
});
|
|
581
613
|
return svg `
|
|
582
614
|
<svg
|
|
583
|
-
id
|
|
584
|
-
class
|
|
585
|
-
|
|
586
|
-
${this._isDragging ? 'dragging' : ''}"
|
|
587
|
-
@pointerdown="${this.drag}"
|
|
615
|
+
id=${id}
|
|
616
|
+
class=${sliderClasses}
|
|
617
|
+
@pointerdown=${this.drag}
|
|
588
618
|
>
|
|
589
619
|
<path d="${sliderShape} z" fill="${sliderColor}" />
|
|
590
620
|
<rect
|
|
@@ -668,9 +698,12 @@ let HistogramDateRange = class HistogramDateRange extends LitElement {
|
|
|
668
698
|
}
|
|
669
699
|
const date = dayjs(dateMS);
|
|
670
700
|
if (date.year() < 1000) {
|
|
671
|
-
// years before 1000 don't play well with dayjs custom formatting, so
|
|
672
|
-
//
|
|
673
|
-
|
|
701
|
+
// years before 1000 don't play well with dayjs custom formatting, so work around dayjs
|
|
702
|
+
// by setting the year to a sentinel value and then replacing it instead.
|
|
703
|
+
// this is a bit hacky but it does the trick for essentially all reasonable cases
|
|
704
|
+
// until such time as we replace dayjs.
|
|
705
|
+
const tmpDate = date.year(199999);
|
|
706
|
+
return tmpDate.format(format).replace(/199999/g, date.year().toString());
|
|
674
707
|
}
|
|
675
708
|
return date.format(format);
|
|
676
709
|
}
|
|
@@ -684,13 +717,13 @@ let HistogramDateRange = class HistogramDateRange extends LitElement {
|
|
|
684
717
|
return html `
|
|
685
718
|
<input
|
|
686
719
|
id="date-min"
|
|
687
|
-
placeholder
|
|
720
|
+
placeholder=${this.dateFormat}
|
|
688
721
|
type="text"
|
|
689
|
-
@focus
|
|
690
|
-
@blur
|
|
691
|
-
@keyup
|
|
692
|
-
.value
|
|
693
|
-
?disabled
|
|
722
|
+
@focus=${this.handleInputFocus}
|
|
723
|
+
@blur=${this.handleMinDateInput}
|
|
724
|
+
@keyup=${this.handleKeyUp}
|
|
725
|
+
.value=${live(this.minSelectedDate)}
|
|
726
|
+
?disabled=${this.disabled}
|
|
694
727
|
/>
|
|
695
728
|
`;
|
|
696
729
|
}
|
|
@@ -698,13 +731,13 @@ let HistogramDateRange = class HistogramDateRange extends LitElement {
|
|
|
698
731
|
return html `
|
|
699
732
|
<input
|
|
700
733
|
id="date-max"
|
|
701
|
-
placeholder
|
|
734
|
+
placeholder=${this.dateFormat}
|
|
702
735
|
type="text"
|
|
703
|
-
@focus
|
|
704
|
-
@blur
|
|
705
|
-
@keyup
|
|
706
|
-
.value
|
|
707
|
-
?disabled
|
|
736
|
+
@focus=${this.handleInputFocus}
|
|
737
|
+
@blur=${this.handleMaxDateInput}
|
|
738
|
+
@keyup=${this.handleKeyUp}
|
|
739
|
+
.value=${live(this.maxSelectedDate)}
|
|
740
|
+
?disabled=${this.disabled}
|
|
708
741
|
/>
|
|
709
742
|
`;
|
|
710
743
|
}
|
|
@@ -854,6 +887,9 @@ HistogramDateRange.styles = css `
|
|
|
854
887
|
transparent;
|
|
855
888
|
}
|
|
856
889
|
/****** slider ********/
|
|
890
|
+
.slider {
|
|
891
|
+
shape-rendering: crispEdges; /* So the slider doesn't get blurry if dragged between pixels */
|
|
892
|
+
}
|
|
857
893
|
.draggable:hover {
|
|
858
894
|
cursor: grab;
|
|
859
895
|
}
|