tltv-timeline-element 1.0.21 → 1.0.23
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +17 -1
- package/dist/src/model/DefaultLocaleDataProvider.d.ts +27 -27
- package/dist/src/model/DefaultLocaleDataProvider.js +111 -111
- package/dist/src/model/ILocaleDataProvider.d.ts +62 -62
- package/dist/src/model/ILocaleDataProvider.js +1 -1
- package/dist/src/model/IResolutionBlockFiller.d.ts +4 -4
- package/dist/src/model/IResolutionBlockFiller.js +1 -1
- package/dist/src/model/IResolutionBlockRegisterer.d.ts +3 -3
- package/dist/src/model/IResolutionBlockRegisterer.js +1 -1
- package/dist/src/model/Resolution.d.ts +5 -5
- package/dist/src/model/Resolution.js +6 -6
- package/dist/src/model/Weekday.d.ts +5 -5
- package/dist/src/model/Weekday.js +6 -6
- package/dist/src/model/blockRowData.d.ts +11 -11
- package/dist/src/model/blockRowData.js +28 -28
- package/dist/src/timeline-element.d.ts +369 -352
- package/dist/src/timeline-element.js +1709 -1634
- package/dist/src/timeline-element.js.map +1 -1
- package/dist/src/util/dateTimeUtil.d.ts +14 -14
- package/dist/src/util/dateTimeUtil.js +55 -55
- package/dist/src/util/elementUtil.d.ts +4 -4
- package/dist/src/util/elementUtil.js +48 -48
- package/package.json +1 -1
- package/src/index.html +33 -0
- package/src/timeline-element.ts +84 -5
package/src/timeline-element.ts
CHANGED
|
@@ -55,6 +55,10 @@ export class TimelineElement extends LitElement {
|
|
|
55
55
|
private static readonly STYLE_CENTER: string = "c-col";
|
|
56
56
|
private static readonly STYLE_LAST: string = "l-col";
|
|
57
57
|
private static readonly STYLE_MEASURE: string = "measure";
|
|
58
|
+
private static readonly STYLE_CURRENT: string = "current";
|
|
59
|
+
private static readonly CURRENT_DAY_FORMAT: string = "yyyy-MM-dd";
|
|
60
|
+
// Offset is included to tell apart the repeated hour when daylight saving time ends.
|
|
61
|
+
private static readonly CURRENT_HOUR_FORMAT: string = "yyyy-MM-dd HH xxx";
|
|
58
62
|
|
|
59
63
|
private readonly resolutionWeekDayblockWidth: number = 4;
|
|
60
64
|
|
|
@@ -119,7 +123,13 @@ export class TimelineElement extends LitElement {
|
|
|
119
123
|
@property() monthNames: string[];
|
|
120
124
|
@property() weekdayNames: string[];
|
|
121
125
|
|
|
126
|
+
/* When true, the resolution block (and the day row block) covering the current date/time is highlighted with 'current' style. */
|
|
127
|
+
@property({ reflect: true, type: Boolean }) currentDateVisible: boolean = false;
|
|
128
|
+
|
|
122
129
|
private localeDataProvider: ILocaleDataProvider;
|
|
130
|
+
/* Current day formatted as 'yyyy-MM-dd' in the timeline's time zone. Refreshed before each fill. */
|
|
131
|
+
private currentDayString: string = null;
|
|
132
|
+
private currentHourString: string = null;
|
|
123
133
|
|
|
124
134
|
/*
|
|
125
135
|
* number of blocks in resolution range. Days for Day/Week resolution, Hours
|
|
@@ -237,10 +247,10 @@ export class TimelineElement extends LitElement {
|
|
|
237
247
|
|
|
238
248
|
.month:nth-of-type(even),
|
|
239
249
|
.day:nth-of-type(even) {
|
|
240
|
-
background-color: #ddd;
|
|
250
|
+
background-color: var(--timeline-row-even-background, #ddd);
|
|
241
251
|
}
|
|
242
252
|
.col.even {
|
|
243
|
-
background-color: #ccc;
|
|
253
|
+
background-color: var(--timeline-col-even-background-color, #ccc);
|
|
244
254
|
}
|
|
245
255
|
|
|
246
256
|
.col {
|
|
@@ -280,6 +290,11 @@ export class TimelineElement extends LitElement {
|
|
|
280
290
|
background-color: var(--timeline-col-weekend, #ccc);
|
|
281
291
|
}
|
|
282
292
|
|
|
293
|
+
.col.current,
|
|
294
|
+
.day.current {
|
|
295
|
+
background-color: var(--timeline-col-current, #ffe082);
|
|
296
|
+
}
|
|
297
|
+
|
|
283
298
|
.col.measure {
|
|
284
299
|
// Change min-width to adjust grid's cell width with day and hour-resolution.
|
|
285
300
|
//min-width: 40px;
|
|
@@ -344,6 +359,7 @@ export class TimelineElement extends LitElement {
|
|
|
344
359
|
|| changedProperties.has('monthRowVisible')
|
|
345
360
|
|| changedProperties.has('monthNames')
|
|
346
361
|
|| changedProperties.has('weekdayNames')
|
|
362
|
+
|| changedProperties.has('currentDateVisible')
|
|
347
363
|
;
|
|
348
364
|
}
|
|
349
365
|
|
|
@@ -645,7 +661,8 @@ export class TimelineElement extends LitElement {
|
|
|
645
661
|
let day: string = this.getDay(date);
|
|
646
662
|
|
|
647
663
|
return this.addBlock(currentDay, day, date, this.dayRowData, (day: string, key: string, date: Date) => {
|
|
648
|
-
this.addDayBlockElement(key, this.formatDayCaption(day, date));
|
|
664
|
+
let block: HTMLDivElement = this.addDayBlockElement(key, this.formatDayCaption(day, date));
|
|
665
|
+
block.dataset.day = this.localeDataProvider.formatDate(date, TimelineElement.CURRENT_DAY_FORMAT);
|
|
649
666
|
});
|
|
650
667
|
}
|
|
651
668
|
|
|
@@ -673,8 +690,8 @@ export class TimelineElement extends LitElement {
|
|
|
673
690
|
this.createTimelineBlock(key, text, TimelineElement.STYLE_YEAR, this.yearRowData);
|
|
674
691
|
}
|
|
675
692
|
|
|
676
|
-
addDayBlockElement(key: string, text: string) {
|
|
677
|
-
this.createTimelineBlock(key, text, TimelineElement.STYLE_DAY, this.dayRowData);
|
|
693
|
+
addDayBlockElement(key: string, text: string): HTMLDivElement {
|
|
694
|
+
return this.createTimelineBlock(key, text, TimelineElement.STYLE_DAY, this.dayRowData);
|
|
678
695
|
}
|
|
679
696
|
|
|
680
697
|
createTimelineBlock(key: string, text: string, styleSuffix: string, rowData: BlockRowData): HTMLDivElement {
|
|
@@ -1316,7 +1333,61 @@ export class TimelineElement extends LitElement {
|
|
|
1316
1333
|
this.fillTimelineForResolution(this.internalInclusiveStartDateTime, this.internalInclusiveEndDateTime, 0);
|
|
1317
1334
|
}
|
|
1318
1335
|
|
|
1336
|
+
/**
|
|
1337
|
+
* Re-applies 'current' style to the currently shown resolution blocks and day
|
|
1338
|
+
* row blocks without rebuilding the timeline. Call this when the current day
|
|
1339
|
+
* or hour changes.
|
|
1340
|
+
*/
|
|
1341
|
+
public refreshCurrentDate() {
|
|
1342
|
+
if (!this.localeDataProvider || !this.resolutionDiv || !this.internalInclusiveStartDateTime
|
|
1343
|
+
|| !this.internalInclusiveEndDateTime || this.resolutionDiv.childElementCount === 0) {
|
|
1344
|
+
return;
|
|
1345
|
+
}
|
|
1346
|
+
this.fillVisibleTimeline();
|
|
1347
|
+
}
|
|
1348
|
+
|
|
1349
|
+
updateCurrentDayString() {
|
|
1350
|
+
this.currentDayString = (this.currentDateVisible && this.localeDataProvider)
|
|
1351
|
+
? this.localeDataProvider.formatDate(new Date(), TimelineElement.CURRENT_DAY_FORMAT)
|
|
1352
|
+
: null;
|
|
1353
|
+
this.currentHourString = (this.currentDateVisible && this.localeDataProvider)
|
|
1354
|
+
? this.localeDataProvider.formatDate(new Date(), TimelineElement.CURRENT_HOUR_FORMAT)
|
|
1355
|
+
: null;
|
|
1356
|
+
}
|
|
1357
|
+
|
|
1358
|
+
isCurrentDay(date: Date): boolean {
|
|
1359
|
+
return this.currentDayString != null && date != null
|
|
1360
|
+
&& this.localeDataProvider.formatDate(date, TimelineElement.CURRENT_DAY_FORMAT) === this.currentDayString;
|
|
1361
|
+
}
|
|
1362
|
+
|
|
1363
|
+
isCurrentHour(date: Date): boolean {
|
|
1364
|
+
// Compare the hour bucket in the configured time zone, so the result does
|
|
1365
|
+
// not depend on where inside the hour the given date falls.
|
|
1366
|
+
return this.currentHourString != null && date != null
|
|
1367
|
+
&& this.localeDataProvider.formatDate(date, TimelineElement.CURRENT_HOUR_FORMAT) === this.currentHourString;
|
|
1368
|
+
}
|
|
1369
|
+
|
|
1370
|
+
setCurrentStyle(element: HTMLElement, current: boolean) {
|
|
1371
|
+
if (current) {
|
|
1372
|
+
element.classList.add(TimelineElement.STYLE_CURRENT);
|
|
1373
|
+
} else {
|
|
1374
|
+
element.classList.remove(TimelineElement.STYLE_CURRENT);
|
|
1375
|
+
}
|
|
1376
|
+
}
|
|
1377
|
+
|
|
1378
|
+
updateDayRowCurrentStyles() {
|
|
1379
|
+
if (!this.isDayRowVisible()) {
|
|
1380
|
+
return;
|
|
1381
|
+
}
|
|
1382
|
+
for (let entry of this.dayRowData.getBlockEntries()) {
|
|
1383
|
+
let block: HTMLElement = <HTMLElement>entry[1];
|
|
1384
|
+
this.setCurrentStyle(block, this.currentDayString != null && block.dataset.day === this.currentDayString);
|
|
1385
|
+
}
|
|
1386
|
+
}
|
|
1387
|
+
|
|
1319
1388
|
fillTimelineForResolution(startDate: Date, endDate: Date, left: number) {
|
|
1389
|
+
this.updateCurrentDayString();
|
|
1390
|
+
this.updateDayRowCurrentStyles();
|
|
1320
1391
|
if (this.resolution === Resolution.Day || this.resolution === Resolution.Week) {
|
|
1321
1392
|
this.fillTimelineForDayResolution(startDate, endDate, left);
|
|
1322
1393
|
} else if (this.resolution == Resolution.Hour) {
|
|
@@ -1822,6 +1893,7 @@ export class TimelineElement extends LitElement {
|
|
|
1822
1893
|
} else {
|
|
1823
1894
|
resBlock.classList.remove(TimelineElement.STYLE_WEEKEND);
|
|
1824
1895
|
}
|
|
1896
|
+
this.setCurrentStyle(resBlock, this.isCurrentDay(date));
|
|
1825
1897
|
|
|
1826
1898
|
if (this.setPositionForEachBlock && this.isTimelineOverflowingHorizontally()) {
|
|
1827
1899
|
resBlock.style.position = "relative";
|
|
@@ -1846,6 +1918,12 @@ export class TimelineElement extends LitElement {
|
|
|
1846
1918
|
}
|
|
1847
1919
|
|
|
1848
1920
|
resBlock.classList.remove(TimelineElement.STYLE_FIRST, TimelineElement.STYLE_LAST);
|
|
1921
|
+
// block is (re)filled starting from its first visible day; clear old state.
|
|
1922
|
+
this.setCurrentStyle(resBlock, false);
|
|
1923
|
+
}
|
|
1924
|
+
|
|
1925
|
+
if (this.isCurrentDay(date) && this.isValidChildIndex(index, this.resolutionDiv.childElementCount)) {
|
|
1926
|
+
this.setCurrentStyle(<HTMLElement>this.resolutionDiv.childNodes.item(index), true);
|
|
1849
1927
|
}
|
|
1850
1928
|
|
|
1851
1929
|
if (firstWeek && (weekDay === Weekday.Last || lastBlock)) {
|
|
@@ -1875,6 +1953,7 @@ export class TimelineElement extends LitElement {
|
|
|
1875
1953
|
resBlock.classList.remove(TimelineElement.STYLE_EVEN);
|
|
1876
1954
|
|
|
1877
1955
|
}
|
|
1956
|
+
this.setCurrentStyle(resBlock, this.isCurrentHour(date));
|
|
1878
1957
|
|
|
1879
1958
|
if (this.firstDay && (hourCounter == 24 || lastBlock)) {
|
|
1880
1959
|
this.firstDay = false;
|