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.
@@ -1,110 +1,115 @@
1
- var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
2
- var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
3
- if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
4
- else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
5
- return c > 3 && r && Object.defineProperty(target, key, r), r;
6
- };
7
- var TimelineElement_1;
8
- import { LitElement, html, css, nothing } from 'lit';
9
- import { property, customElement } from 'lit/decorators.js';
10
- import { toDate } from 'date-fns-tz';
11
- import { Resolution } from './model/Resolution';
12
- import { Weekday } from './model/Weekday';
13
- import { BlockRowData } from './model/blockRowData';
14
- import * as DateUtil from './util/dateTimeUtil';
15
- import { DateTimeConstants } from './util/dateTimeUtil';
16
- import * as ElementUtil from './util/elementUtil';
17
- import { DefaultLocaleDataProvider } from './model/DefaultLocaleDataProvider';
18
- import { getISOWeek } from 'date-fns';
19
- import { query } from 'lit-element/decorators.js';
20
- /**
21
- * Scalable timeline web component that supports more than one
22
- * resolutions ({@link Resolution}). When timeline element doesn't overflow
23
- * horizontally in it's parent element, it scales the content width up to fit in
24
- * the space available.
25
- * <p>
26
- * When this component scales up, all widths are calculated as percentages.
27
- * Pixel widths are used otherwise. Some browsers may not support percentages
28
- * accurately enough, and for those it's best to call
29
- * {@link #setAlwaysCalculatePixelWidths(boolean)} with 'true' to disable
30
- * percentage values.
31
- * <p>
32
- * There's always a minimum width calculated and updated to the timeline
33
- * element. Percentage values set some limitation for the component's width.
34
- * Wider the component (&gt; 4000px), bigger the chance to get year, month and
35
- * date blocks not being vertically in-line with each others.
36
- * <p>
37
- * Supports setting a scroll left position.
38
- * <p>
39
- * After construction, attach the component to it's parent and call update
40
- * method with a required parameters and the timeline is ready. After that, all
41
- * widths are calculated and all other API methods available can be used safely.
42
- *
43
- */
44
- export let TimelineElement = TimelineElement_1 = class TimelineElement extends LitElement {
45
- constructor() {
46
- super(...arguments);
47
- this.resolutionWeekDayblockWidth = 4;
48
- this.resolution = Resolution.Day;
49
- /** Timezone for date and time formatting. Doesn't match with actual start and end Date object's time zone. */
50
- this.timeZone = "Europe/London";
51
- this.locale = "en-US";
52
- this.firstDayOfWeek = 1; // sunday;
53
- this.twelveHourClock = false;
54
- this.monthRowVisible = true;
55
- this.yearRowVisible = true;
56
- /*
57
- * number of blocks in resolution range. Days for Day/Week resolution, Hours
58
- * for hour resolution..
59
- */
60
- this.blocksInRange = 0;
61
- /*
62
- * number of elements in resolution range. Same as blocksInRange for
63
- * Day/Hour resolution. blocksInRange / 7 for Week resolution.
64
- */
65
- this.resolutionBlockCount = 0;
66
- this.firstResBlockCount = 0;
67
- this.lastResBlockCount = 0;
68
- this.spacerBlocks = [];
69
- this.yearRowData = new BlockRowData();
70
- this.monthRowData = new BlockRowData();
71
- // days/daysLength are needed only with resolutions smaller than Day.
72
- this.dayRowData = new BlockRowData();
73
- /*
74
- * Currently active widths. Updated each time when timeline column widths
75
- * are updated.
76
- */
77
- this.dayWidthPercentage = 0;
78
- this.dayOrHourWidthPx = 0;
79
- this.resBlockMinWidthPx = 0;
80
- this.resBlockWidthPx = 0;
81
- this.resBlockWidthPercentage = 0;
82
- this.minResolutionWidth = -1;
83
- this.calcPixels = false;
84
- this.positionLeft = 0;
85
- this.setPositionForEachBlock = false;
86
- this.firstWeekBlockHidden = false;
87
- this.ie = false; // deprecated property
88
- /* directlyInsideScrollContainer:
89
- true: timeline element is a child element inside a container with scroll bar.
90
- false: timeline.style.left is adjusted by scrollHandler. */
91
- this.directlyInsideScrollContainer = true;
92
- this.previousContainerScrollLeft = 0;
93
- this.previousContainerScrollTop = 0;
94
- }
95
- connectedCallback() {
96
- super.connectedCallback();
97
- if (this.scrollContainer && this.scrollHandler) {
98
- this.scrollContainer.addEventListener('scroll', this.scrollHandler);
99
- }
100
- }
101
- disconnectedCallback() {
102
- super.disconnectedCallback();
103
- if (this.scrollContainer && this.scrollHandler) {
104
- this.scrollContainer.removeEventListener('scroll', this.scrollHandler);
105
- }
106
- }
107
- static get styles() {
1
+ var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
2
+ var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
3
+ if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
4
+ else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
5
+ return c > 3 && r && Object.defineProperty(target, key, r), r;
6
+ };
7
+ var TimelineElement_1;
8
+ import { LitElement, html, css, nothing } from 'lit';
9
+ import { property, customElement } from 'lit/decorators.js';
10
+ import { toDate } from 'date-fns-tz';
11
+ import { Resolution } from './model/Resolution';
12
+ import { Weekday } from './model/Weekday';
13
+ import { BlockRowData } from './model/blockRowData';
14
+ import * as DateUtil from './util/dateTimeUtil';
15
+ import { DateTimeConstants } from './util/dateTimeUtil';
16
+ import * as ElementUtil from './util/elementUtil';
17
+ import { DefaultLocaleDataProvider } from './model/DefaultLocaleDataProvider';
18
+ import { getISOWeek } from 'date-fns';
19
+ import { query } from 'lit-element/decorators.js';
20
+ /**
21
+ * Scalable timeline web component that supports more than one
22
+ * resolutions ({@link Resolution}). When timeline element doesn't overflow
23
+ * horizontally in it's parent element, it scales the content width up to fit in
24
+ * the space available.
25
+ * <p>
26
+ * When this component scales up, all widths are calculated as percentages.
27
+ * Pixel widths are used otherwise. Some browsers may not support percentages
28
+ * accurately enough, and for those it's best to call
29
+ * {@link #setAlwaysCalculatePixelWidths(boolean)} with 'true' to disable
30
+ * percentage values.
31
+ * <p>
32
+ * There's always a minimum width calculated and updated to the timeline
33
+ * element. Percentage values set some limitation for the component's width.
34
+ * Wider the component (&gt; 4000px), bigger the chance to get year, month and
35
+ * date blocks not being vertically in-line with each others.
36
+ * <p>
37
+ * Supports setting a scroll left position.
38
+ * <p>
39
+ * After construction, attach the component to it's parent and call update
40
+ * method with a required parameters and the timeline is ready. After that, all
41
+ * widths are calculated and all other API methods available can be used safely.
42
+ *
43
+ */
44
+ export let TimelineElement = TimelineElement_1 = class TimelineElement extends LitElement {
45
+ constructor() {
46
+ super(...arguments);
47
+ this.resolutionWeekDayblockWidth = 4;
48
+ this.resolution = Resolution.Day;
49
+ /** Timezone for date and time formatting. Doesn't match with actual start and end Date object's time zone. */
50
+ this.timeZone = "Europe/London";
51
+ this.locale = "en-US";
52
+ this.firstDayOfWeek = 1; // sunday;
53
+ this.twelveHourClock = false;
54
+ this.monthRowVisible = true;
55
+ this.yearRowVisible = true;
56
+ /* When true, the resolution block (and the day row block) covering the current date/time is highlighted with 'current' style. */
57
+ this.currentDateVisible = false;
58
+ /* Current day formatted as 'yyyy-MM-dd' in the timeline's time zone. Refreshed before each fill. */
59
+ this.currentDayString = null;
60
+ this.currentHourString = null;
61
+ /*
62
+ * number of blocks in resolution range. Days for Day/Week resolution, Hours
63
+ * for hour resolution..
64
+ */
65
+ this.blocksInRange = 0;
66
+ /*
67
+ * number of elements in resolution range. Same as blocksInRange for
68
+ * Day/Hour resolution. blocksInRange / 7 for Week resolution.
69
+ */
70
+ this.resolutionBlockCount = 0;
71
+ this.firstResBlockCount = 0;
72
+ this.lastResBlockCount = 0;
73
+ this.spacerBlocks = [];
74
+ this.yearRowData = new BlockRowData();
75
+ this.monthRowData = new BlockRowData();
76
+ // days/daysLength are needed only with resolutions smaller than Day.
77
+ this.dayRowData = new BlockRowData();
78
+ /*
79
+ * Currently active widths. Updated each time when timeline column widths
80
+ * are updated.
81
+ */
82
+ this.dayWidthPercentage = 0;
83
+ this.dayOrHourWidthPx = 0;
84
+ this.resBlockMinWidthPx = 0;
85
+ this.resBlockWidthPx = 0;
86
+ this.resBlockWidthPercentage = 0;
87
+ this.minResolutionWidth = -1;
88
+ this.calcPixels = false;
89
+ this.positionLeft = 0;
90
+ this.setPositionForEachBlock = false;
91
+ this.firstWeekBlockHidden = false;
92
+ this.ie = false; // deprecated property
93
+ /* directlyInsideScrollContainer:
94
+ true: timeline element is a child element inside a container with scroll bar.
95
+ false: timeline.style.left is adjusted by scrollHandler. */
96
+ this.directlyInsideScrollContainer = true;
97
+ this.previousContainerScrollLeft = 0;
98
+ this.previousContainerScrollTop = 0;
99
+ }
100
+ connectedCallback() {
101
+ super.connectedCallback();
102
+ if (this.scrollContainer && this.scrollHandler) {
103
+ this.scrollContainer.addEventListener('scroll', this.scrollHandler);
104
+ }
105
+ }
106
+ disconnectedCallback() {
107
+ super.disconnectedCallback();
108
+ if (this.scrollContainer && this.scrollHandler) {
109
+ this.scrollContainer.removeEventListener('scroll', this.scrollHandler);
110
+ }
111
+ }
112
+ static get styles() {
108
113
  return css `
109
114
  :host {
110
115
  display: block;
@@ -142,10 +147,10 @@ export let TimelineElement = TimelineElement_1 = class TimelineElement extends L
142
147
 
143
148
  .month:nth-of-type(even),
144
149
  .day:nth-of-type(even) {
145
- background-color: #ddd;
150
+ background-color: var(--timeline-row-even-background, #ddd);
146
151
  }
147
152
  .col.even {
148
- background-color: #ccc;
153
+ background-color: var(--timeline-col-even-background-color, #ccc);
149
154
  }
150
155
 
151
156
  .col {
@@ -185,6 +190,11 @@ export let TimelineElement = TimelineElement_1 = class TimelineElement extends L
185
190
  background-color: var(--timeline-col-weekend, #ccc);
186
191
  }
187
192
 
193
+ .col.current,
194
+ .day.current {
195
+ background-color: var(--timeline-col-current, #ffe082);
196
+ }
197
+
188
198
  .col.measure {
189
199
  // Change min-width to adjust grid's cell width with day and hour-resolution.
190
200
  //min-width: 40px;
@@ -205,1533 +215,1598 @@ export let TimelineElement = TimelineElement_1 = class TimelineElement extends L
205
215
  -webkit-touch-callout: none;
206
216
  @apply --no-user-select;
207
217
  }
208
- `;
209
- }
210
- render() {
218
+ `;
219
+ }
220
+ render() {
211
221
  return html `
212
222
  ${this.yearBlocks()}
213
223
  ${this.monthBlocks()}
214
224
  ${this.dayBlocks()}
215
- <div id="resolutionDiv" class="row resolution"></div>`;
216
- }
217
- yearBlocks() {
218
- if (this.yearRowVisible) {
219
- return this.timelineBlocks(this.yearRowData, TimelineElement_1.STYLE_YEAR);
220
- }
221
- return nothing;
222
- }
223
- monthBlocks() {
224
- if (this.monthRowVisible) {
225
- return this.timelineBlocks(this.monthRowData, TimelineElement_1.STYLE_MONTH);
226
- }
227
- return nothing;
228
- }
229
- dayBlocks() {
230
- if (this.isDayRowVisible) {
231
- return this.timelineBlocks(this.dayRowData, TimelineElement_1.STYLE_DAY);
232
- }
233
- return nothing;
234
- }
235
- shouldUpdate(changedProperties) {
236
- return changedProperties.has('resolution')
237
- || changedProperties.has('startDateTime')
238
- || changedProperties.has('endDateTime')
239
- || changedProperties.has('locale')
240
- || changedProperties.has('timeZone')
241
- || changedProperties.has('firstDayOfWeek')
242
- || changedProperties.has('twelveHourClock')
243
- || changedProperties.has('yearRowVisible')
244
- || changedProperties.has('monthRowVisible')
245
- || changedProperties.has('monthNames')
246
- || changedProperties.has('weekdayNames');
247
- }
248
- willUpdate(changedProps) {
249
- if (changedProps.has('resolution')) {
250
- this.minResolutionWidth = -1;
251
- }
252
- if (changedProps.has('resolution') || changedProps.has('startDateTime') || changedProps.has('timeZone')) {
253
- this.firstDayOfRange = null;
254
- if (this.resolution === Resolution.Hour) {
255
- this.internalInclusiveStartDateTime = toDate(this.startDateTime, { timeZone: this.timeZone });
256
- }
257
- else {
258
- this.internalInclusiveStartDateTime = toDate(this.startDateTime.substring(0, 10) + 'T00:00:00.000', { timeZone: this.timeZone });
259
- }
260
- }
261
- if (changedProps.has('resolution') || changedProps.has('endDateTime') || changedProps.has('timeZone')) {
262
- // given time must be always exact hour in millisecod accuracy 1AM means exactly "01:00:00.000".
263
- if (this.resolution === Resolution.Hour) {
264
- // convert given time to last millisecond in the given hour. 1AM becomes "01:59:59.999" set to internalEndDateTime.
265
- this.internalInclusiveEndDateTime = toDate(this.endDateTime.substring(0, 13) + ':59:59.999', { timeZone: this.timeZone });
266
- }
267
- else {
268
- this.internalInclusiveEndDateTime = toDate(this.endDateTime.substring(0, 10) + 'T23:59:59.999', { timeZone: this.timeZone });
269
- }
270
- }
271
- this.updateTimeLine(this.resolution, this.internalInclusiveStartDateTime, this.internalInclusiveEndDateTime, new DefaultLocaleDataProvider(this.locale, this.timeZone, this.firstDayOfWeek, this.twelveHourClock));
272
- }
273
- updated(changedProps) {
274
- if (!(this.resolution) || !this.internalInclusiveStartDateTime || !this.internalInclusiveEndDateTime) {
275
- return;
276
- }
277
- if (this.resolution !== Resolution.Day && this.resolution !== Resolution.Week && this.resolution !== Resolution.Hour) {
278
- console.log("TimelineElement resolution " + (this.resolution ? Resolution[this.resolution] : "null")
279
- + " is not supported");
280
- return;
281
- }
282
- console.log("TimelineElement Constructed content.");
283
- this.updateWidths();
284
- console.log("TimelineElement is updated for resolution " + Resolution[this.resolution] + ".");
285
- this.registerScrollHandler();
286
- }
287
- /**
288
- * <p>
289
- * Updates the content of this component. Builds the time-line and calculates
290
- * width and heights for the content (calls in the end
291
- * {@link #updateWidths()}). This should be called explicitly. Otherwise the
292
- * component will be empty.
293
- * <p>
294
- * Date values should always follow specification in {@link Date#getTime()}.
295
- * Start and end date is always required.
296
- *
297
- * @param resolution
298
- * Resolution enum (not null)
299
- * @param startDate
300
- * Time-line's start date. (inclusive; not null)
301
- * @param endDate
302
- * Time-line's end date. (inclusive; not null)
303
- * @param localeDataProvider
304
- * Data provider for locale specific data. month names, first day
305
- * of week etc.
306
- *
307
- */
308
- updateTimeLine(resolution, startDate, endDate, localeDataProvider) {
309
- if (!localeDataProvider) {
310
- console.log("TimelineElement requires ILocaleDataProvider. Can't complete update(...) operation.");
311
- return;
312
- }
313
- this.clear();
314
- console.log("TimelineElement content cleared.");
315
- if (!(resolution) || !startDate || !endDate) {
316
- return;
317
- }
318
- console.log("TimelineElement Updating content.");
319
- this.localeDataProvider = localeDataProvider;
320
- this.resolution = resolution;
321
- this.resetDateRange(startDate, endDate);
322
- this.lastDayOfWeek = (localeDataProvider.getFirstDayOfWeek() == 1) ? 7 : Math.max((localeDataProvider.getFirstDayOfWeek() - 1) % 8, 1);
323
- this.monthNames = this.monthNames || localeDataProvider.getMonthNames();
324
- this.weekdayNames = this.weekdayNames || localeDataProvider.getWeekdayNames();
325
- if (this.minResolutionWidth < 0) {
326
- this.minResolutionWidth = this.calculateResolutionMinWidth();
327
- }
328
- if (this.resolution === Resolution.Day || this.resolution === Resolution.Week) {
329
- this.prepareTimelineForDayOrWeekResolution(this.internalInclusiveStartDateTime, this.internalInclusiveEndDateTime);
330
- }
331
- else if (this.resolution === Resolution.Hour) {
332
- this.prepareTimelineForHourResolution(this.internalInclusiveStartDateTime, this.internalInclusiveEndDateTime);
333
- }
334
- }
335
- resetDateRange(startDate, endDate) {
336
- this.internalInclusiveStartDateTime = startDate;
337
- this.internalInclusiveEndDateTime = endDate;
338
- this.normalStartDate = this.toNormalDate(this.internalInclusiveStartDateTime);
339
- this.normalEndDate = this.toNormalDate(this.internalInclusiveEndDateTime);
340
- // Date#getDay() is zero-based: Sunday = 0, Monday = 1, ...
341
- // this.firstDayOfRange is 1-based (Sunday = 1).
342
- this.firstDayOfRange = this.firstDayOfRange || this.internalInclusiveStartDateTime.getDay() + 1; // TODO is weekday still correct here?
343
- this.firstHourOfRange = this.firstHourOfRange || parseInt(this.localeDataProvider.formatTime(this.internalInclusiveStartDateTime, "HH"));
344
- }
345
- registerScrollHandler() {
346
- if (this.scrollHandler) {
347
- return;
348
- }
349
- let timeline = this;
350
- this.scrollContainer = this.setupScrollContainer();
351
- this.scrollHandler = function (e) {
352
- window.requestAnimationFrame(function () {
353
- let container = timeline.scrollContainer;
354
- let sl = container.scrollLeft || container.scrollX;
355
- let st = container.scrollTop || container.scrollY;
356
- if (sl != timeline.previousContainerScrollLeft) {
357
- timeline.setScrollLeft(sl);
358
- timeline.previousContainerScrollLeft = sl;
359
- }
360
- if (st != timeline.previousContainerScrollTop) {
361
- timeline.previousContainerScrollTop = st;
362
- }
363
- });
364
- };
365
- this.scrollContainer.addEventListener('scroll', this.scrollHandler);
366
- }
367
- setupScrollContainer() {
368
- let scrollContainer;
369
- if (this.scrollContainerId) {
370
- scrollContainer = this.getParentElement(this).querySelector('#' + this.scrollContainerId);
371
- if (!scrollContainer) {
372
- scrollContainer = document.querySelector('#' + this.scrollContainerId);
373
- }
374
- if (scrollContainer) {
375
- scrollContainer.style.overflowX = "auto";
376
- }
377
- }
378
- if (!scrollContainer) {
379
- scrollContainer = this.getParentElement(this);
380
- this.directlyInsideScrollContainer = true;
381
- if (scrollContainer === document.body) {
382
- return window; // window scrolls by default, not body
383
- }
384
- }
385
- return scrollContainer;
386
- }
387
- clear() {
388
- this.spacerBlocks = [];
389
- this.yearRowData.clear();
390
- this.monthRowData.clear();
391
- this.dayRowData.clear();
392
- }
393
- calculateResolutionMinWidth() {
394
- let resDivMeasure = document.createElement('div');
395
- resDivMeasure.classList.add(TimelineElement_1.STYLE_ROW, TimelineElement_1.STYLE_RESOLUTION);
396
- let resBlockMeasure = document.createElement('div');
397
- if (this.resolution === Resolution.Week) {
398
- // configurable with '.col.w.measure' selector
399
- resBlockMeasure.classList.add(TimelineElement_1.STYLE_COL, TimelineElement_1.STYLE_WEEK, TimelineElement_1.STYLE_MEASURE);
400
- }
401
- else {
402
- // measure for text 'MM'
403
- resBlockMeasure.innerText = "MM";
404
- // configurable with '.col.measure' selector
405
- resBlockMeasure.classList.add(TimelineElement_1.STYLE_COL, TimelineElement_1.STYLE_MEASURE);
406
- }
407
- resDivMeasure.appendChild(resBlockMeasure);
408
- this.shadowRoot.appendChild(resDivMeasure);
409
- let width = resBlockMeasure.clientWidth;
410
- if (this.resolution === Resolution.Week) {
411
- // divide given width by number of days in week
412
- width = width / DateTimeConstants.DAYS_IN_WEEK;
413
- }
414
- width = (width < this.resolutionWeekDayblockWidth) ? this.resolutionWeekDayblockWidth : width;
415
- this.shadowRoot.removeChild(resDivMeasure);
416
- return width;
417
- }
418
- registerHourResolutionBlock() {
419
- this.blocksInRange++;
420
- this.resolutionBlockCount++;
421
- }
422
- registerDayResolutionBlock() {
423
- this.blocksInRange++;
424
- this.resolutionBlockCount++;
425
- }
426
- registerWeekResolutionBlock(index, weekDay, lastBlock, firstWeek) {
427
- if (index == 0 || weekDay === Weekday.First) {
428
- this.resolutionBlockCount++;
429
- }
430
- if (firstWeek && (weekDay === Weekday.Last || lastBlock)) {
431
- this.firstResBlockCount = index + 1;
432
- }
433
- else if (lastBlock) {
434
- this.lastResBlockCount = (index + 1 - this.firstResBlockCount) % 7;
435
- }
436
- this.blocksInRange++;
437
- }
438
- timelineBlocks(rowData, style) {
439
- const itemTemplates = [];
440
- for (let entry of rowData.getBlockEntries()) {
441
- itemTemplates.push(html `${entry[1]}`);
442
- }
443
- if (this.isAlwaysCalculatePixelWidths()) {
444
- itemTemplates.push(html `${this.createSpacerBlock(style)}`);
445
- }
446
- return itemTemplates;
447
- }
448
- /**
449
- * Returns true if Widget is set to calculate widths by itself. Default is
450
- * false.
451
- *
452
- * @return
453
- */
454
- isAlwaysCalculatePixelWidths() {
455
- return this.calcPixels;
456
- }
457
- createSpacerBlock(className) {
458
- let block = document.createElement('div');
459
- block.classList.add(TimelineElement_1.STYLE_ROW, TimelineElement_1.STYLE_YEAR, TimelineElement_1.STYLE_SPACER);
460
- block.innerText = " ";
461
- block.style.display = "none"; // not visible by default
462
- this.spacerBlocks.push(block);
463
- return block;
464
- }
465
- /** Clears Daylight saving time adjustment from the given time. */
466
- toNormalDate(zonedDate) {
467
- return DateUtil.toNormalDate(zonedDate, this.localeDataProvider.getDaylightAdjustment(zonedDate));
468
- }
469
- getDSTAdjustedDate(previousIsDST, zonedDate) {
470
- return DateUtil.getDSTAdjustedDate(previousIsDST, zonedDate, this.localeDataProvider.getDaylightAdjustment(zonedDate));
471
- }
472
- getParentElement(node) {
473
- var parent = node.parentNode;
474
- if (!parent || parent.nodeType != 1) {
475
- parent = null;
476
- }
477
- return parent;
478
- }
479
- getDay(date) {
480
- // by adjusting the date to the middle of the day before formatting is a
481
- // workaround to avoid DST issues with DateTimeFormatter.
482
- let adjusted = DateUtil.adjustToMiddleOfDay(date, this.localeDataProvider.getTimeZone());
483
- return this.localeDataProvider.formatDate(adjusted, "d");
484
- }
485
- getYear(date) {
486
- return this.localeDataProvider.formatDate(date, "yyyy");
487
- }
488
- getMonth(date) {
489
- let m = this.localeDataProvider.formatDate(date, "M");
490
- return parseInt(m) - 1;
491
- }
492
- isWeekEnd(dayCounter) {
493
- return dayCounter == 1 || dayCounter == 7;
494
- }
495
- key(prefix, rowData) {
496
- return prefix + "_" + (rowData.size());
497
- }
498
- newKey(prefix, rowData) {
499
- return prefix + "_" + (rowData.size() + 1);
500
- }
501
- addBlock(current, target, date, rowData, operation) {
502
- let key;
503
- if (target !== current) {
504
- current = target;
505
- key = this.newKey("" + current, rowData);
506
- operation(target, key, date);
507
- }
508
- else {
509
- key = this.key("" + current, rowData);
510
- rowData.setBlockLength(key, rowData.getBlockLength(key) + 1);
511
- }
512
- return current;
513
- }
514
- addDayBlock(currentDay, date) {
515
- let day = this.getDay(date);
516
- return this.addBlock(currentDay, day, date, this.dayRowData, (day, key, date) => {
517
- this.addDayBlockElement(key, this.formatDayCaption(day, date));
518
- });
519
- }
520
- addMonthBlock(currentMonth, date) {
521
- let month = this.getMonth(date);
522
- return this.addBlock(currentMonth, "" + month, date, this.monthRowData, (target, key, date) => {
523
- this.addMonthBlockElement(key, this.formatMonthCaption(month, date));
524
- });
525
- }
526
- addYearBlock(currentYear, date) {
527
- let year = this.getYear(date);
528
- return this.addBlock(currentYear, year, date, this.yearRowData, (year, key, date) => {
529
- this.addYearBlockElement(key, this.formatYearCaption(year, date));
530
- });
531
- }
532
- addMonthBlockElement(key, text) {
533
- this.createTimelineBlock(key, text, TimelineElement_1.STYLE_MONTH, this.monthRowData);
534
- }
535
- addYearBlockElement(key, text) {
536
- this.createTimelineBlock(key, text, TimelineElement_1.STYLE_YEAR, this.yearRowData);
537
- }
538
- addDayBlockElement(key, text) {
539
- this.createTimelineBlock(key, text, TimelineElement_1.STYLE_DAY, this.dayRowData);
540
- }
541
- createTimelineBlock(key, text, styleSuffix, rowData) {
542
- let div = document.createElement('div');
543
- div.classList.add(TimelineElement_1.STYLE_ROW, styleSuffix);
544
- div.innerText = text;
545
- rowData.setBlockLength(key, 1);
546
- rowData.setBlock(key, div);
547
- return div;
548
- }
549
- formatDayCaption(day, date) {
550
- if (!this.dayFormat || this.dayFormat === "") {
551
- return day;
552
- }
553
- return this.localeDataProvider.formatDate(date, this.dayFormat);
554
- }
555
- formatYearCaption(year, date) {
556
- if (!this.yearFormat || this.yearFormat === "") {
557
- return year;
558
- }
559
- return this.localeDataProvider.formatDate(date, this.yearFormat);
560
- }
561
- formatWeekCaption(date) {
562
- if (!this.weekFormat || this.weekFormat === "") {
563
- return "" + getISOWeek(date);
564
- }
565
- return this.localeDataProvider.formatDate(date, this.weekFormat);
566
- }
567
- formatMonthCaption(month, date) {
568
- if (!this.monthFormat || this.monthFormat === "") {
569
- return this.monthNames[month];
570
- }
571
- return this.localeDataProvider.formatDate(date, this.monthFormat);
572
- }
573
- getWeekday(dayCounter) {
574
- if (dayCounter === this.localeDataProvider.getFirstDayOfWeek()) {
575
- return Weekday.First;
576
- }
577
- if (dayCounter === this.lastDayOfWeek) {
578
- return Weekday.Last;
579
- }
580
- return Weekday.Between;
581
- }
582
- prepareTimelineForHourResolution(startDate, endDate) {
583
- let timeline = this;
584
- this.firstDay = true;
585
- let hourCounter = this.firstHourOfRange;
586
- this.prepareTimelineForHour(DateTimeConstants.HOUR_INTERVAL, startDate, endDate, {
587
- registerResolutionBlock(index, date, currentYear, lastTimelineBlock) {
588
- timeline.registerHourResolutionBlock();
589
- hourCounter = Math.max((hourCounter + 1) % 25, 1);
590
- }
591
- });
592
- }
593
- prepareTimelineForHour(interval, startDate, endDate, resBlockRegisterer) {
594
- this.blocksInRange = 0;
595
- this.resolutionBlockCount = 0;
596
- this.firstResBlockCount = 0;
597
- this.lastResBlockCount = 0;
598
- let currentYear = null;
599
- let currentMonth = null;
600
- let currentDay = null;
601
- let pos = startDate;
602
- let end = endDate;
603
- let index = 0;
604
- let lastTimelineBlock = false;
605
- let date;
606
- while (pos.getTime() <= end.getTime()) {
607
- date = pos;
608
- let nextHour = new Date(pos.getTime() + interval);
609
- lastTimelineBlock = nextHour.getTime() > end.getTime();
610
- resBlockRegisterer.registerResolutionBlock(index, date, currentYear, lastTimelineBlock);
611
- if (this.yearRowVisible) {
612
- currentYear = this.addYearBlock(currentYear, date);
613
- }
614
- if (this.monthRowVisible) {
615
- currentMonth = this.addMonthBlock(currentMonth, date);
616
- }
617
- if (this.isDayRowVisible()) {
618
- currentDay = this.addDayBlock(currentDay, date);
619
- }
620
- pos = nextHour;
621
- index++;
622
- }
623
- }
624
- prepareTimelineForDayOrWeekResolution(startDate, endDate) {
625
- let timeline = this;
626
- let dayCounter = this.firstDayOfRange;
627
- let weekday;
628
- let firstWeek = true;
629
- this.prepareTimelineForDayOrWeek(DateTimeConstants.DAY_INTERVAL, startDate, endDate, {
630
- registerResolutionBlock: function (index, date, currentYear, lastTimelineBlock) {
631
- weekday = timeline.getWeekday(dayCounter);
632
- if (timeline.resolution === Resolution.Week) {
633
- timeline.registerWeekResolutionBlock(index, weekday, lastTimelineBlock, firstWeek);
634
- if (firstWeek && (weekday === Weekday.Last || lastTimelineBlock)) {
635
- firstWeek = false;
636
- }
637
- }
638
- else {
639
- timeline.registerDayResolutionBlock();
640
- }
641
- dayCounter = Math.max((dayCounter + 1) % 8, 1);
642
- }
643
- });
644
- }
645
- prepareTimelineForDayOrWeek(interval, startDate, endDate, resBlockRegisterer) {
646
- this.blocksInRange = 0;
647
- this.resolutionBlockCount = 0;
648
- this.firstResBlockCount = 0;
649
- this.lastResBlockCount = 0;
650
- let currentYear = null;
651
- let currentMonth = null;
652
- let currentDay = null;
653
- let pos = DateUtil.adjustToMiddleOfDay(startDate, this.localeDataProvider.getTimeZone());
654
- let end = endDate;
655
- let index = 0;
656
- let lastTimelineBlock = false;
657
- let date;
658
- let isDST = false;
659
- let isPreviousDst = this.localeDataProvider.isDaylightTime(startDate);
660
- while (!lastTimelineBlock) {
661
- let date = DateUtil.getDSTAdjustedDate(isPreviousDst, pos, this.localeDataProvider.getDaylightAdjustment(pos));
662
- pos = date;
663
- isDST = this.localeDataProvider.isDaylightTime(date);
664
- let d = new Date(date.getTime() + interval);
665
- lastTimelineBlock = DateUtil.getDSTAdjustedDate(isDST, d, this.localeDataProvider.getDaylightAdjustment(d)).getTime() > end.getTime();
666
- resBlockRegisterer.registerResolutionBlock(index, date, currentYear, lastTimelineBlock);
667
- if (this.yearRowVisible) {
668
- currentYear = this.addYearBlock(currentYear, date);
669
- }
670
- if (this.monthRowVisible) {
671
- currentMonth = this.addMonthBlock(currentMonth, date);
672
- }
673
- if (this.isDayRowVisible()) {
674
- currentDay = this.addDayBlock(currentDay, date);
675
- }
676
- isPreviousDst = isDST;
677
- pos = new Date(pos.getTime() + interval);
678
- index++;
679
- }
680
- }
681
- isDayRowVisible() {
682
- return this.resolution === Resolution.Hour;
683
- }
684
- /**
685
- * Get actual width of the timeline.
686
- *
687
- * @return
688
- */
689
- getResolutionWidth() {
690
- if (!this.isTimelineOverflowingHorizontally()) {
691
- return this.calculateTimelineWidth();
692
- }
693
- let width = this.getResolutionDivWidth();
694
- if (this.isAlwaysCalculatePixelWidths() && this.containsResBlockSpacer()) {
695
- width = width - ElementUtil.getWidth(this.resSpacerDiv);
696
- }
697
- return width;
698
- }
699
- /**
700
- * Calculate the exact width of the timeline. Excludes any spacers in the
701
- * end.
702
- *
703
- * @return
704
- */
705
- calculateTimelineWidth() {
706
- let last = this.getLastResolutionElement();
707
- if (last === null) {
708
- return 0.0;
709
- }
710
- let r = ElementUtil.getRight(last);
711
- let l = ElementUtil.getLeft(this.getFirstResolutionElement());
712
- let timelineRealWidth = r - l;
713
- return timelineRealWidth;
714
- }
715
- /*
716
- * Get width of the resolution div element.
717
- */
718
- getResolutionDivWidth() {
719
- if (!this.isTimelineOverflowingHorizontally()) {
720
- return ElementUtil.getWidth(this.resolutionDiv);
721
- }
722
- return this.blocksInRange * this.minResolutionWidth;
723
- }
724
- /**
725
- * Calculate matching left offset in percentage for a date (
726
- * {@link Date#getTime()}).
727
- *
728
- * @param date
729
- * Target date in milliseconds.
730
- * @param contentWidth
731
- * Width of the content that the given 'date' is relative to.
732
- * @return Left offset in percentage.
733
- */
734
- getLeftPositionPercentageForDate(date, contentWidth) {
735
- let timelineLeft = this.getLeftPositionForDate(date);
736
- let relativeLeft = this.convertRelativeLeftPosition(timelineLeft, contentWidth);
737
- let width = this.getResolutionWidth();
738
- return (100.0 / width) * relativeLeft;
739
- }
740
- /**
741
- * Calculate CSS value for 'left' property matching left offset in
742
- * percentage for a date ( {@link Date#getTime()}).
743
- * <p>
744
- * May return '2.123456%' or 'calc(2.123456%)' if IE;
745
- *
746
- * @param date
747
- * Target date in milliseconds.
748
- * @param contentWidth
749
- * Width of the content that the given 'date' is relative to.
750
- * @return Left offset as a String value.
751
- */
752
- getLeftPositionPercentageStringForDate(date, contentWidth) {
753
- let timelineLeft = this.getLeftPositionForDate(date);
754
- let relativeLeft = this.convertRelativeLeftPosition(timelineLeft, contentWidth);
755
- let width = this.getResolutionWidth();
756
- let calc = this.createCalcCssValue(width, relativeLeft);
757
- if (calc != null) {
758
- return calc;
759
- }
760
- return (100.0 / width) * relativeLeft + "%";
761
- }
762
- getLeftPositionPercentageStringForDateRange(date, rangeWidth, rangeStartDate, rangeEndDate) {
763
- let rangeLeft = this.getLeftPositionForDateRange(date, rangeWidth, rangeStartDate, rangeEndDate);
764
- let width = rangeWidth;
765
- let calc = this.createCalcCssValue(width, rangeLeft);
766
- if (calc != null) {
767
- return calc;
768
- }
769
- return (100.0 / width) * rangeLeft + "%";
770
- }
771
- /**
772
- * Calculate CSS value for 'width' property matching date interval inside
773
- * the time-line. Returns percentage value. Interval is in milliseconds.
774
- * <p>
775
- * May return '2.123456%' or 'calc(2.123456%)' if IE;
776
- *
777
- * @param interval
778
- * Date interval in milliseconds.
779
- * @return
780
- */
781
- getWidthPercentageStringForDateInterval(interval) {
782
- let range = this.internalInclusiveEndDateTime.getTime() - this.internalInclusiveStartDateTime.getTime();
783
- return this.getWidthPercentageStringForDateIntervalForRange(interval, range);
784
- }
785
- /** @see #getWidthPercentageStringForDateInterval(long) */
786
- getWidthPercentageStringForDateIntervalForRange(interval, range) {
787
- let calc = this.createCalcCssValue(range, interval);
788
- if (calc != null) {
789
- return calc;
790
- }
791
- return (100.0 / range) * interval + "%";
792
- }
793
- /**
794
- * Calculate matching left offset in pixels for a date (
795
- * {@link Date#getTime()}).
796
- *
797
- * @param date
798
- * Target date in milliseconds.
799
- * @return Left offset in pixels.
800
- */
801
- getLeftPositionForDate(date) {
802
- return this.getLeftPositionForDateRange(date, this.getResolutionWidth(), this.internalInclusiveStartDateTime, this.internalInclusiveEndDateTime);
803
- }
804
- getLeftPositionForDateRange(date, rangeWidth, rangeStartDate, rangeEndDate) {
805
- let width = rangeWidth;
806
- let range = rangeEndDate.getTime() - rangeStartDate.getTime();
807
- if (range <= 0) {
808
- return 0;
809
- }
810
- let p = width / range;
811
- let offset = date.getTime() - rangeStartDate.getTime();
812
- let left = p * offset;
813
- return left;
814
- }
815
- /**
816
- * Calculate matching date ({@link Date#getTime()}) for the target left
817
- * pixel offset.
818
- *
819
- * @param left
820
- * Left offset in pixels.
821
- * @return Date in a milliseconds or null if timeline width is invalid (<=0).
822
- */
823
- getDateForLeftPosition(left) {
824
- return this.getDateForLeftPositionNoticeDST(left, this.resolution === Resolution.Hour);
825
- }
826
- getDateForLeftPositionNoticeDST(left, noticeDST) {
827
- let width = this.getResolutionWidth();
828
- if (width <= 0) {
829
- return null;
830
- }
831
- let range = this.normalEndDate.getTime() - this.normalStartDate.getTime();
832
- if (noticeDST) {
833
- range = this.adjustDateRangeByDST(range);
834
- }
835
- let p = range / width;
836
- let offset = p * left;
837
- let date = new Date(this.internalInclusiveStartDateTime.getTime() + offset);
838
- console.log("Zoned: " + this.localeDataProvider.formatDate(date, "dd. HH:mm") + " DST: "
839
- + this.localeDataProvider.getDaylightAdjustment(date) / 60000);
840
- return date;
841
- }
842
- /**
843
- * Convert left position for other relative target width.
844
- *
845
- * @param left
846
- * @param contentWidthToConvertFor
847
- * @return
848
- */
849
- convertRelativeLeftPosition(left, contentWidthToConvertFor) {
850
- let width = this.getResolutionWidth();
851
- if (width <= 0 || contentWidthToConvertFor <= 0) {
852
- return 0;
853
- }
854
- let relativePosition = (1.0 / contentWidthToConvertFor) * left;
855
- let timelineLeft = relativePosition * width;
856
- return timelineLeft;
857
- }
858
- adjustDateRangeByDST(range) {
859
- /*
860
- * Notice extra block(s) or missing block(s) in range when start time is
861
- * in DST and end time is not, or vice versa.
862
- */
863
- let dstStart = this.localeDataProvider.getDaylightAdjustment(this.internalInclusiveStartDateTime);
864
- let dstEnd = this.localeDataProvider.getDaylightAdjustment(this.internalInclusiveEndDateTime);
865
- if (dstStart > dstEnd) {
866
- range -= Math.abs(dstStart - dstEnd);
867
- }
868
- else if (dstEnd > dstStart) {
869
- range += Math.abs(dstEnd - dstStart);
870
- }
871
- return range;
872
- }
873
- /**
874
- * Set horizontal scroll position for the time-line.
875
- *
876
- * @param left
877
- * Scroll position in pixels.
878
- */
879
- setScrollLeft(left) {
880
- if (this.positionLeft === left) {
881
- return;
882
- }
883
- this.positionLeft = left || 0;
884
- if (!this.directlyInsideScrollContainer) {
885
- this.style.left = -this.positionLeft + "px";
886
- }
887
- this.lazyResolutionPaint = setTimeout(() => this.fillVisibleTimeline(), 20);
888
- }
889
- /**
890
- * Re-calculates required widths for this widget.
891
- * <p>
892
- * Re-creates and fills the visible part of the resolution element.
893
- */
894
- updateWidths() {
895
- if (this.resolutionDiv == null) {
896
- console.log("TimelineElement is not ready for updateWidths() call. Call update(...) instead.");
897
- return;
898
- }
899
- console.log("TimelineElement Started updating widths.");
900
- // start by clearing old content in resolution element
901
- while (this.resolutionDiv.firstChild) {
902
- this.resolutionDiv.removeChild(this.resolutionDiv.lastChild);
903
- }
904
- this.setMinWidth(this.blocksInRange * this.minResolutionWidth);
905
- // update horizontal overflow state here, after min-width is updated.
906
- this.updateTimelineOverflowingHorizontally();
907
- this.createTimelineElementsOnVisibleArea();
908
- // fill timeline
909
- this.fillVisibleTimeline();
910
- // remove spacer block if it exist
911
- this.removeResolutionSpacerBlock();
912
- // calculate new block width for day-resolution.
913
- // Year and month blocks are vertically in-line with days.
914
- this.dayWidthPercentage = 100.0 / this.blocksInRange;
915
- this.dayOrHourWidthPx = this.calculateDayOrHourResolutionBlockWidthPx(this.blocksInRange);
916
- // calculate block width for currently selected resolution
917
- // (day,week,...)
918
- // resolution div's content may not be vertically in-line with
919
- // year/month blocks. This is the case for example with Week resolution.
920
- this.resBlockMinWidthPx = this.minResolutionWidth;
921
- this.resBlockWidthPx = this.calculateActualResolutionBlockWidthPx(this.dayOrHourWidthPx);
922
- this.resBlockWidthPercentage = 100.0 / this.resolutionBlockCount;
923
- let pct = this.createCalcCssValue(this.resolutionBlockCount, null);
924
- if (this.resolution === Resolution.Week) {
925
- this.resBlockMinWidthPx = DateTimeConstants.DAYS_IN_WEEK * this.minResolutionWidth;
926
- this.resBlockWidthPercentage = this.dayWidthPercentage * DateTimeConstants.DAYS_IN_WEEK;
927
- pct = this.createCalcCssValue(this.blocksInRange, DateTimeConstants.DAYS_IN_WEEK);
928
- }
929
- // update resolution block widths
930
- this.updateResolutionBlockWidths(pct);
931
- if (this.yearRowVisible) {
932
- // update year block widths
933
- this.updateBlockWidths(this.yearRowData);
934
- }
935
- if (this.monthRowVisible) {
936
- // update month block widths
937
- this.updateBlockWidths(this.monthRowData);
938
- }
939
- if (this.isDayRowVisible()) {
940
- this.updateBlockWidths(this.dayRowData);
941
- }
942
- if (this.isAlwaysCalculatePixelWidths()) {
943
- this.updateSpacerBlocks(this.dayOrHourWidthPx);
944
- }
945
- console.log("TimelineElement Widths are updated.");
946
- }
947
- updateBlockWidths(rowData) {
948
- for (let entry of rowData.getBlockEntries()) {
949
- this.setWidth(entry[1], rowData.getBlockLength(entry[0]));
950
- }
951
- }
952
- updateSpacerBlocks(dayWidthPx) {
953
- let spaceLeft = this.getResolutionDivWidth() - (this.blocksInRange * dayWidthPx);
954
- if (spaceLeft > 0) {
955
- for (let e of this.spacerBlocks) {
956
- e.style.removeProperty("display");
957
- e.style.width = spaceLeft + "px";
958
- }
959
- this.resSpacerDiv = this.createResolutionBlock();
960
- this.resSpacerDiv.classList.add(TimelineElement_1.STYLE_SPACER);
961
- this.resSpacerDiv.style.width = spaceLeft + "px";
962
- this.resSpacerDiv.innerText = " ";
963
- this.resolutionDiv.appendChild(this.resSpacerDiv);
964
- }
965
- else {
966
- this.hideSpacerBlocks();
967
- }
968
- }
969
- hideSpacerBlocks() {
970
- for (let e of this.spacerBlocks) {
971
- e.style.display = "none";
972
- }
973
- }
974
- /**
975
- * Set minimum width (pixels) of this widget's root DIV element. Default is
976
- * -1. Notice that
977
- * {@link #update(Resolution, long, long, int, int, LocaleDataProvider)}
978
- * will calculate min-width and call this internally.
979
- *
980
- * @param minWidth
981
- * Minimum width in pixels.
982
- */
983
- setMinWidth(minWidth) {
984
- this.minWidth = minWidth;
985
- this.style.minWidth = this.minWidth + "px";
986
- this.resolutionDiv.style.minWidth = this.minWidth + "px";
987
- }
988
- /**
989
- * Returns true if the timeline is overflowing the parent's width. This
990
- * works only when this widget is attached to some parent.
991
- *
992
- * @return True when timeline width is more than the parent's width (@see
993
- * {@link Element#getClientWidth()}).
994
- */
995
- isTimelineOverflowingHorizontally() {
996
- return this.timelineOverflowingHorizontally;
997
- }
998
- /**
999
- * Update horizontal overflow state.
1000
- */
1001
- updateTimelineOverflowingHorizontally() {
1002
- this.timelineOverflowingHorizontally = (ElementUtil.getWidth(this.resolutionDiv) > ElementUtil.getWidth(this.getParentElement(this)));
1003
- }
1004
- createTimelineElementsOnVisibleArea() {
1005
- // create place holder elements that represents weeks/days/hours
1006
- // depending on the resolution in the timeline.
1007
- // Only visible blocks are created, and only once, content will change
1008
- // on scroll.
1009
- // first: detect how many blocks we can fit in the screen
1010
- let blocks = this.resolutionBlockCount;
1011
- if (this.isTimelineOverflowingHorizontally()) {
1012
- blocks = Math.floor((ElementUtil.getWidth(this.getParentElement(this))
1013
- / this.calculateMinimumResolutionBlockWidth()));
1014
- if (this.resolutionBlockCount < blocks) {
1015
- // blocks need to be scaled up to fit the screen
1016
- blocks = this.resolutionBlockCount;
1017
- }
1018
- else {
1019
- blocks += 2;
1020
- }
1021
- }
1022
- let element = null;
1023
- for (let i = 0; i < blocks; i++) {
1024
- switch (this.resolution) {
1025
- case Resolution.Hour:
1026
- element = this.createHourResolutionBlock();
1027
- break;
1028
- case Resolution.Day:
1029
- element = this.createDayResolutionBlock();
1030
- break;
1031
- case Resolution.Week:
1032
- element = this.createWeekResolutionBlock();
1033
- break;
1034
- }
1035
- this.resolutionDiv.appendChild(element);
1036
- }
1037
- console.log(`TimelineElement Added ${blocks} visible timeline elements for resolution ${Resolution[this.resolution]}`);
1038
- }
1039
- calculateMinimumResolutionBlockWidth() {
1040
- if (this.resolution === Resolution.Week) {
1041
- return DateTimeConstants.DAYS_IN_WEEK * this.minResolutionWidth;
1042
- }
1043
- return this.minResolutionWidth;
1044
- }
1045
- createResolutionBlock() {
1046
- let resBlock = document.createElement('div');
1047
- resBlock.classList.add("col");
1048
- return resBlock;
1049
- }
1050
- createHourResolutionBlock() {
1051
- let resBlock = this.createResolutionBlock();
1052
- resBlock.classList.add("h", TimelineElement_1.STYLE_CENTER);
1053
- return resBlock;
1054
- }
1055
- createDayResolutionBlock() {
1056
- let resBlock = this.createResolutionBlock();
1057
- resBlock.classList.add(TimelineElement_1.STYLE_CENTER);
1058
- return resBlock;
1059
- }
1060
- createWeekResolutionBlock() {
1061
- let resBlock = this.createResolutionBlock();
1062
- resBlock.classList.add("w", TimelineElement_1.STYLE_CENTER);
1063
- return resBlock;
1064
- }
1065
- fillVisibleTimeline() {
1066
- if (this.isTimelineOverflowingHorizontally()) {
1067
- this.showResolutionBlocksOnView();
1068
- }
1069
- else {
1070
- this.showAllResolutionBlocks();
1071
- }
1072
- }
1073
- showResolutionBlocksOnView() {
1074
- let positionLeftSnapshot = this.positionLeft;
1075
- let datePos = positionLeftSnapshot;
1076
- this.firstWeekBlockHidden = false;
1077
- let left = Math.floor(positionLeftSnapshot);
1078
- if (positionLeftSnapshot > 0 && this.resBlockWidthPx > 0) {
1079
- let overflow = 0.0;
1080
- let firstResBlockShort = this.isFirstResBlockShort();
1081
- overflow = this.getScrollOverflowForResolutionBlock(positionLeftSnapshot, left, firstResBlockShort);
1082
- left = Math.floor(positionLeftSnapshot - overflow);
1083
- datePos = this.adjustLeftPositionForDateDetection(left);
1084
- }
1085
- if (datePos < 0.0) {
1086
- datePos = positionLeftSnapshot;
1087
- }
1088
- let leftDate;
1089
- let noticeDst = this.resolution === Resolution.Hour;
1090
- leftDate = this.getDateForLeftPositionNoticeDST(datePos, noticeDst);
1091
- let containerWidth = ElementUtil.getWidth(this.getParentElement(this));
1092
- this.fillTimelineForResolution(leftDate, new Date(Math.min(this.internalInclusiveEndDateTime.getTime(), this.getDateForLeftPositionNoticeDST(datePos + containerWidth, noticeDst).getTime())), left);
1093
- this.style.setProperty("--timeline-col-position", "relative");
1094
- this.style.setProperty("--timeline-col-left", left + "px");
1095
- console.log(`TimelineElement Updated visible timeline elements for horizontal scroll position ${left} (plus ${datePos - left} to center-of-first-block)`);
1096
- }
1097
- showAllResolutionBlocks() {
1098
- this.style.setProperty("--timeline-col-position", "relative");
1099
- this.style.setProperty("--timeline-col-left", "0px");
1100
- this.fillTimelineForResolution(this.internalInclusiveStartDateTime, this.internalInclusiveEndDateTime, 0);
1101
- }
1102
- fillTimelineForResolution(startDate, endDate, left) {
1103
- if (this.resolution === Resolution.Day || this.resolution === Resolution.Week) {
1104
- this.fillTimelineForDayResolution(startDate, endDate, left);
1105
- }
1106
- else if (this.resolution == Resolution.Hour) {
1107
- this.fillTimelineForHourResolution(startDate, endDate, left);
1108
- }
1109
- else {
1110
- console.log("TimelineElement resolution " + (this.resolution != null ? Resolution[this.resolution] : "null")
1111
- + " is not supported");
1112
- return;
1113
- }
1114
- console.log("TimelineElement Filled new data and styles to visible timeline elements");
1115
- }
1116
- isFirstResBlockShort() {
1117
- return this.firstResBlockCount > 0 && ((this.resolution === Resolution.Week && this.firstResBlockCount < DateTimeConstants.DAYS_IN_WEEK));
1118
- }
1119
- isLastResBlockShort() {
1120
- return this.lastResBlockCount > 0 && ((this.resolution === Resolution.Week && this.lastResBlockCount < DateTimeConstants.DAYS_IN_WEEK));
1121
- }
1122
- getScrollOverflowForResolutionBlock(positionLeftSnapshot, left, firstResBlockShort) {
1123
- let overflow;
1124
- if (firstResBlockShort && left <= this.getFirstResolutionElementWidth()) {
1125
- overflow = this.getScrollOverflowForShortFirstResolutionBlock(positionLeftSnapshot);
1126
- }
1127
- else {
1128
- overflow = this.getScrollOverflowForRegularResoultionBlock(positionLeftSnapshot, firstResBlockShort);
1129
- }
1130
- return overflow;
1131
- }
1132
- getScrollOverflowForRegularResoultionBlock(positionLeftSnapshot, firstResBlockShort) {
1133
- let overflow;
1134
- let firstBlockWidth = this.getFirstResolutionElementWidth();
1135
- let positionLeft = (positionLeftSnapshot - (firstResBlockShort ? firstBlockWidth : 0));
1136
- overflow = positionLeft % this.resBlockWidthPx;
1137
- if (firstResBlockShort) {
1138
- overflow += firstBlockWidth;
1139
- this.firstWeekBlockHidden = true;
1140
- }
1141
- return overflow;
1142
- }
1143
- getScrollOverflowForShortFirstResolutionBlock(positionLeftSnapshot) {
1144
- let overflow;
1145
- // need to notice a short resolution block due to timeline's
1146
- // start date which is in middle of a week.
1147
- overflow = positionLeftSnapshot % this.getFirstResolutionElementWidth();
1148
- if (overflow == 0.0) {
1149
- overflow = this.getFirstResolutionElementWidth();
1150
- }
1151
- return overflow;
1152
- }
1153
- /**
1154
- * Returns a width of the first resolution block.
1155
- *
1156
- * @return
1157
- */
1158
- getFirstResolutionElementWidth() {
1159
- if (this.isFirstResBlockShort()) {
1160
- if (this.isTimelineOverflowingHorizontally()) {
1161
- return this.firstResBlockCount * this.minResolutionWidth;
1162
- }
1163
- else {
1164
- return ElementUtil.getWidth(this.getFirstResolutionElement());
1165
- }
1166
- }
1167
- else {
1168
- if (this.isTimelineOverflowingHorizontally()) {
1169
- return this.resBlockMinWidthPx;
1170
- }
1171
- else {
1172
- return ElementUtil.getWidth(this.getFirstResolutionElement());
1173
- }
1174
- }
1175
- }
1176
- getFirstResolutionElement() {
1177
- if (this.resolutionDiv.hasChildNodes()) {
1178
- return this.resolutionDiv.firstElementChild;
1179
- }
1180
- return null;
1181
- }
1182
- getLastResolutionElement() {
1183
- let div = this.resolutionDiv;
1184
- if (!div) {
1185
- return null;
1186
- }
1187
- let nodeList = div.childNodes;
1188
- if (!nodeList) {
1189
- return null;
1190
- }
1191
- let blockCount = nodeList.length;
1192
- if (blockCount < 1) {
1193
- return null;
1194
- }
1195
- if (this.containsResBlockSpacer()) {
1196
- let index = blockCount - 2;
1197
- if (blockCount > 1 && index >= 0) {
1198
- return this.resolutionDiv.childNodes.item(index);
1199
- }
1200
- return null;
1201
- }
1202
- return this.resolutionDiv.lastChild;
1203
- }
1204
- containsResBlockSpacer() {
1205
- return this.resSpacerDiv != null && this.resSpacerDiv.parentElement
1206
- && this.resSpacerDiv.parentElement === this.resolutionDiv;
1207
- }
1208
- removeResolutionSpacerBlock() {
1209
- if (this.containsResBlockSpacer()) {
1210
- this.resSpacerDiv.parentNode.removeChild(this.resSpacerDiv);
1211
- }
1212
- }
1213
- /*
1214
- * Calculates either day or hour resolution block width depending on the
1215
- * current resolution.
1216
- */
1217
- calculateDayOrHourResolutionBlockWidthPx(blockCount) {
1218
- let dayOrHourWidthPx = Math.round(this.resolutionDiv.clientWidth / blockCount);
1219
- while ((blockCount * dayOrHourWidthPx) < this.resolutionDiv.clientWidth) {
1220
- dayOrHourWidthPx++;
1221
- }
1222
- return dayOrHourWidthPx;
1223
- }
1224
- /*
1225
- * Calculates the actual width of one resolution block element. For example:
1226
- * week resolution will return 7 * dayOrHourBlockWidthPx.
1227
- */
1228
- calculateActualResolutionBlockWidthPx(dayOrHourBlockWidthPx) {
1229
- if (this.resolution === Resolution.Week) {
1230
- return DateTimeConstants.DAYS_IN_WEEK * dayOrHourBlockWidthPx;
1231
- }
1232
- return dayOrHourBlockWidthPx;
1233
- }
1234
- /**
1235
- * Adjust left position for optimal position to detect accurate date with
1236
- * the current resolution.
1237
- */
1238
- adjustLeftPositionForDateDetection(left) {
1239
- let datePos;
1240
- if (this.resolution === Resolution.Week) {
1241
- // detect date from the center of the first day block inside the
1242
- // week block.
1243
- datePos = left + this.dayOrHourWidthPx / 2;
1244
- }
1245
- else {
1246
- // detect date from the center of the block (day/hour)
1247
- datePos = left + this.resBlockWidthPx / 2;
1248
- }
1249
- return datePos;
1250
- }
1251
- createCalcCssValue(v, multiplier) {
1252
- if (this.ie) {
1253
- // see comments in createCalcCssValue(int, Integer)
1254
- let percents = 100.0 / v * multiplier;
1255
- return "calc(" + percents + "%)";
1256
- }
1257
- return null;
1258
- }
1259
- updateResolutionBlockWidths(pct) {
1260
- if (this.setPositionForEachBlock) {
1261
- if (!this.isTimelineOverflowingHorizontally()) {
1262
- this.resolutionDiv.style.display = "flex";
1263
- }
1264
- else {
1265
- this.resolutionDiv.style.removeProperty("display");
1266
- }
1267
- let firstResBlockIsShort = this.isFirstResBlockShort();
1268
- let lastResBlockIsShort = this.isLastResBlockShort();
1269
- // when setPositionForEachBlock is true, set width for each block explicitly.
1270
- let count = this.resolutionDiv.childElementCount;
1271
- if (this.containsResBlockSpacer()) {
1272
- count--;
1273
- }
1274
- let lastIndex = count - 1;
1275
- let i;
1276
- let resBlock;
1277
- for (i = 0; i < count; i++) {
1278
- resBlock = this.resolutionDiv.childNodes.item(i);
1279
- // first and last week blocks may be thinner than other
1280
- // resolution blocks.
1281
- if (firstResBlockIsShort && i == 0) {
1282
- this.setWidth(resBlock, this.firstResBlockCount);
1283
- }
1284
- else if (lastResBlockIsShort && i == lastIndex) {
1285
- this.setWidth(resBlock, this.lastResBlockCount);
1286
- }
1287
- else {
1288
- this.setWidthPct(this.resBlockWidthPx, pct, resBlock);
1289
- }
1290
- }
1291
- }
1292
- else {
1293
- // set widths by updating injected styles in one place. Faster than
1294
- // setting widths explicitly for each element.
1295
- let center = this.getWidthStyleValue(pct);
1296
- let first = center;
1297
- let last = center;
1298
- if (this.isFirstResBlockShort()) {
1299
- first = this.getWidth(this.firstResBlockCount);
1300
- }
1301
- if (this.isLastResBlockShort()) {
1302
- last = this.getWidth(this.lastResBlockCount);
1303
- }
1304
- this.style.setProperty("--timeline-col-center-width", center);
1305
- this.style.setProperty("--timeline-col-first-width", first);
1306
- this.style.setProperty("--timeline-col-last-width", last);
1307
- }
1308
- }
1309
- getWidth(multiplier) {
1310
- if (this.isTimelineOverflowingHorizontally()) {
1311
- return (multiplier * this.minResolutionWidth) + "px";
1312
- }
1313
- else {
1314
- if (this.isAlwaysCalculatePixelWidths()) {
1315
- return multiplier * this.dayOrHourWidthPx + "px";
1316
- }
1317
- else {
1318
- return this.getCssPercentageWidth(this.blocksInRange, this.dayWidthPercentage, multiplier);
1319
- }
1320
- }
1321
- }
1322
- setWidth(element, multiplier) {
1323
- if (this.isTimelineOverflowingHorizontally()) {
1324
- element.style.width = (multiplier * this.minResolutionWidth) + "px";
1325
- }
1326
- else {
1327
- if (this.isAlwaysCalculatePixelWidths()) {
1328
- element.style.width = (multiplier * this.dayOrHourWidthPx) + "px";
1329
- }
1330
- else {
1331
- this.setCssPercentageWidth(element, this.blocksInRange, this.dayWidthPercentage, multiplier);
1332
- }
1333
- }
1334
- }
1335
- setWidthPct(resBlockWidthPx, pct, element) {
1336
- if (this.isTimelineOverflowingHorizontally()) {
1337
- element.style.width = this.resBlockMinWidthPx + "px";
1338
- }
1339
- else {
1340
- if (this.isAlwaysCalculatePixelWidths()) {
1341
- element.style.width = resBlockWidthPx + "px";
1342
- }
1343
- else {
1344
- if (this.ie) {
1345
- element.style.flex = "1";
1346
- }
1347
- this.setCssPercentageWidthFor(element, this.resBlockWidthPercentage, pct);
1348
- }
1349
- }
1350
- }
1351
- setCssPercentageWidth(element, daysInRange, width, position) {
1352
- let pct = this.createCalcCssValue(daysInRange, position);
1353
- this.setCssPercentageWidthFor(element, position * width, pct);
1354
- }
1355
- getCssPercentageWidth(daysInRange, width, position) {
1356
- let pct = this.createCalcCssValue(daysInRange, position);
1357
- return this.getPercentageWidthString(position * width, pct);
1358
- }
1359
- setCssPercentageWidthFor(element, nValue, pct) {
1360
- if (pct) {
1361
- element.style.width = pct;
1362
- }
1363
- else {
1364
- element.style.width = nValue + "%";
1365
- }
1366
- }
1367
- getPercentageWidthString(nValue, pct) {
1368
- if (pct) {
1369
- return pct;
1370
- }
1371
- else {
1372
- return nValue + "%";
1373
- }
1374
- }
1375
- getWidthStyleValue(pct) {
1376
- if (this.isTimelineOverflowingHorizontally()) {
1377
- return this.resBlockMinWidthPx + "px";
1378
- }
1379
- else {
1380
- if (this.isAlwaysCalculatePixelWidths()) {
1381
- return this.resBlockWidthPx + "px";
1382
- }
1383
- else {
1384
- return this.getPercentageWidthString(this.resBlockWidthPercentage, pct);
1385
- }
1386
- }
1387
- }
1388
- fillTimelineForHourResolution(startDate, endDate, left) {
1389
- let timeline = this;
1390
- this.firstDay = true;
1391
- let hourCounter;
1392
- let even;
1393
- this.fillTimelineForHour(DateTimeConstants.HOUR_INTERVAL, startDate, endDate, {
1394
- setup() {
1395
- hourCounter = this.getFirstHourOfVisibleRange(startDate);
1396
- even = this.isEven(startDate);
1397
- },
1398
- fillResolutionBlock(index, date, currentYear, lastTimelineBlock) {
1399
- let childCount = timeline.resolutionDiv.childElementCount;
1400
- if (timeline.isValidChildIndex(index, childCount)) {
1401
- let resBlock = timeline.resolutionDiv.childNodes.item(index);
1402
- timeline.fillHourResolutionBlock(resBlock, date, index, hourCounter, lastTimelineBlock, left, even);
1403
- hourCounter = (hourCounter + 1) % 24;
1404
- even = !even;
1405
- }
1406
- else {
1407
- timeline.logIndexOutOfBounds("hour", index, childCount);
1408
- return;
1409
- }
1410
- },
1411
- isEven(startDate) {
1412
- let normalDate = timeline.toNormalDate(startDate);
1413
- if (timeline.normalStartDate.getTime() < normalDate.getTime()) {
1414
- let hours = Math.floor(((normalDate.getTime() - timeline.normalStartDate.getTime()) / DateTimeConstants.HOUR_INTERVAL));
1415
- return (hours % 2) == 1;
1416
- }
1417
- return false;
1418
- },
1419
- getFirstHourOfVisibleRange(startDate) {
1420
- let normalDate = timeline.toNormalDate(startDate);
1421
- if (timeline.normalStartDate.getTime() < normalDate.getTime()) {
1422
- let hours = Math.floor(((normalDate.getTime() - timeline.normalStartDate.getTime()) / DateTimeConstants.HOUR_INTERVAL));
1423
- return ((timeline.firstHourOfRange + hours) % 24);
1424
- }
1425
- return timeline.firstHourOfRange;
1426
- }
1427
- });
1428
- }
1429
- fillTimelineForDayResolution(startDate, endDate, left) {
1430
- let timeline = this;
1431
- let dayCounter;
1432
- let even;
1433
- let firstWeek = true;
1434
- let weekIndex = 0;
1435
- let weekday;
1436
- this.fillTimelineForDayOrWeek(DateTimeConstants.DAY_INTERVAL, startDate, endDate, {
1437
- setup: function () {
1438
- dayCounter = this.getFirstDayOfVisibleRange(startDate);
1439
- even = this.isEven(startDate, timeline.firstDayOfRange);
1440
- },
1441
- fillResolutionBlock: function (index, date, currentYear, lastTimelineBlock) {
1442
- try {
1443
- weekday = timeline.getWeekday(dayCounter);
1444
- if (timeline.resolution === Resolution.Week) {
1445
- this.fillWeekBlock(left, index, date, lastTimelineBlock);
1446
- }
1447
- else {
1448
- this.fillDayBlock(left, index, date);
1449
- }
1450
- }
1451
- finally {
1452
- dayCounter = Math.max((dayCounter + 1) % 8, 1);
1453
- }
1454
- },
1455
- fillDayBlock: function (left, index, date) {
1456
- let childCount = timeline.resolutionDiv.childElementCount;
1457
- if (timeline.isValidChildIndex(index, childCount)) {
1458
- let resBlock = timeline.resolutionDiv.childNodes.item(index);
1459
- timeline.fillDayResolutionBlock(resBlock, date, index, timeline.isWeekEnd(dayCounter), left);
1460
- }
1461
- else {
1462
- timeline.logIndexOutOfBounds("day", index, childCount);
1463
- return;
1464
- }
1465
- },
1466
- fillWeekBlock: function (left, index, date, lastTimelineBlock) {
1467
- let resBlock = null;
1468
- if (index > 0 && weekday == Weekday.First) {
1469
- weekIndex++;
1470
- firstWeek = false;
1471
- even = !even;
1472
- }
1473
- if (index == 0 || weekday == Weekday.First) {
1474
- let childCount = timeline.resolutionDiv.childElementCount;
1475
- if (timeline.isValidChildIndex(weekIndex, childCount)) {
1476
- resBlock = timeline.resolutionDiv.childNodes.item(weekIndex);
1477
- }
1478
- else {
1479
- timeline.logIndexOutOfBounds("week", weekIndex, childCount);
1480
- return;
1481
- }
1482
- }
1483
- timeline.fillWeekResolutionBlock(resBlock, date, weekIndex, weekday, firstWeek, lastTimelineBlock, left, even);
1484
- },
1485
- calcDaysLeftInFirstWeek: function (startDay) {
1486
- let daysLeftInWeek = 0;
1487
- if (startDay != timeline.firstDayOfWeek) {
1488
- for (let i = startDay;; i++) {
1489
- daysLeftInWeek++;
1490
- if (Math.max(i % 8, 1) === timeline.lastDayOfWeek) {
1491
- break;
1492
- }
1493
- }
1494
- }
1495
- return daysLeftInWeek;
1496
- },
1497
- isEven: function (startDate, startDay) {
1498
- let visibleRangeNormalStartDate = timeline.toNormalDate(startDate);
1499
- if (timeline.normalStartDate.getTime() < visibleRangeNormalStartDate.getTime()) {
1500
- let daysHidden = Math.floor(((visibleRangeNormalStartDate.getTime() - timeline.normalStartDate.getTime()) / DateTimeConstants.DAY_INTERVAL));
1501
- console.log("Days hidden: " + daysHidden);
1502
- console.log("firstWeekBlockHidden = " + timeline.firstWeekBlockHidden);
1503
- if (daysHidden === 0) {
1504
- return false;
1505
- }
1506
- let daysLeftInFirstWeek = this.calcDaysLeftInFirstWeek(startDay);
1507
- if (daysHidden > daysLeftInFirstWeek) {
1508
- daysHidden -= daysLeftInFirstWeek;
1509
- }
1510
- let weeks = daysHidden / DateTimeConstants.DAYS_IN_WEEK;
1511
- let even = (weeks % 2) === 1;
1512
- return (timeline.firstWeekBlockHidden) ? !even : even;
1513
- }
1514
- return false;
1515
- },
1516
- getFirstDayOfVisibleRange: function (startDate) {
1517
- let visibleRangeNormalStartDate = timeline.toNormalDate(startDate);
1518
- if (timeline.normalStartDate.getTime() < visibleRangeNormalStartDate.getTime()) {
1519
- let days = Math.floor(((visibleRangeNormalStartDate.getTime() - timeline.normalStartDate.getTime()) / DateTimeConstants.DAY_INTERVAL));
1520
- return ((timeline.firstDayOfRange - 1 + days) % 7) + 1;
1521
- }
1522
- return timeline.firstDayOfRange;
1523
- }
1524
- });
1525
- }
1526
- logIndexOutOfBounds(indexName, index, childCount) {
1527
- console.log("${indexName} index ${index} out of bounds with childCount ${childCount}. Can't fill content.");
1528
- }
1529
- fillTimelineForHour(interval, startDate, endDate, resBlockFiller) {
1530
- let currentYear = null;
1531
- let pos = startDate;
1532
- let end = endDate;
1533
- let index = 0;
1534
- let lastTimelineBlock = false;
1535
- let date;
1536
- resBlockFiller.setup();
1537
- while (pos <= end) {
1538
- date = pos;
1539
- let nextHour = new Date(pos.getTime() + interval);
1540
- lastTimelineBlock = nextHour.getTime() > end.getTime();
1541
- resBlockFiller.fillResolutionBlock(index, date, currentYear, lastTimelineBlock);
1542
- pos = nextHour;
1543
- index++;
1544
- }
1545
- }
1546
- fillTimelineForDayOrWeek(interval, startDate, endDate, resBlockFiller) {
1547
- let currentYear = null;
1548
- let pos = startDate;
1549
- pos = DateUtil.adjustToMiddleOfDay(pos, this.localeDataProvider.getTimeZone());
1550
- let end = endDate;
1551
- let index = 0;
1552
- let lastTimelineBlock = false;
1553
- let date;
1554
- let isDST = false;
1555
- let previousIsDST = this.localeDataProvider.isDaylightTime(startDate);
1556
- resBlockFiller.setup();
1557
- while (!lastTimelineBlock) {
1558
- let dstAdjusted = this.getDSTAdjustedDate(previousIsDST, pos);
1559
- date = dstAdjusted;
1560
- pos = dstAdjusted;
1561
- isDST = this.localeDataProvider.isDaylightTime(date);
1562
- lastTimelineBlock = this.getDSTAdjustedDate(isDST, new Date(date.getTime() + interval)).getTime() > end.getTime();
1563
- resBlockFiller.fillResolutionBlock(index, date, currentYear, lastTimelineBlock);
1564
- previousIsDST = isDST;
1565
- pos = new Date(pos.getTime() + interval);
1566
- index++;
1567
- }
1568
- }
1569
- isValidChildIndex(index, childCount) {
1570
- return (index >= 0) && (index < childCount);
1571
- }
1572
- fillDayResolutionBlock(resBlock, date, index, weekend, left) {
1573
- resBlock.innerText = this.localeDataProvider.formatDate(date, "d");
1574
- if (weekend) {
1575
- resBlock.classList.add(TimelineElement_1.STYLE_WEEKEND);
1576
- }
1577
- else {
1578
- resBlock.classList.remove(TimelineElement_1.STYLE_WEEKEND);
1579
- }
1580
- if (this.setPositionForEachBlock && this.isTimelineOverflowingHorizontally()) {
1581
- resBlock.style.position = "relative";
1582
- resBlock.style.left = left + "px";
1583
- }
1584
- }
1585
- fillWeekResolutionBlock(resBlock, date, index, weekDay, firstWeek, lastBlock, left, even) {
1586
- if (resBlock != null) {
1587
- resBlock.innerText = this.formatWeekCaption(date);
1588
- if (even) {
1589
- resBlock.classList.add(TimelineElement_1.STYLE_EVEN);
1590
- }
1591
- else {
1592
- resBlock.classList.remove(TimelineElement_1.STYLE_EVEN);
1593
- }
1594
- if (this.setPositionForEachBlock && this.isTimelineOverflowingHorizontally()) {
1595
- resBlock.style.position = "relative";
1596
- resBlock.style.left = left + "px";
1597
- }
1598
- resBlock.classList.remove(TimelineElement_1.STYLE_FIRST, TimelineElement_1.STYLE_LAST);
1599
- }
1600
- if (firstWeek && (weekDay === Weekday.Last || lastBlock)) {
1601
- let firstEl = this.resolutionDiv.firstElementChild;
1602
- if (!firstEl.classList.contains(TimelineElement_1.STYLE_FIRST)) {
1603
- firstEl.classList.add(TimelineElement_1.STYLE_FIRST);
1604
- }
1605
- }
1606
- else if (lastBlock) {
1607
- let lastEl = this.resolutionDiv.lastChild;
1608
- if (!lastEl.classList.contains(TimelineElement_1.STYLE_LAST)) {
1609
- lastEl.classList.add(TimelineElement_1.STYLE_LAST);
1610
- }
1611
- }
1612
- }
1613
- fillHourResolutionBlock(resBlock, date, index, hourCounter, lastBlock, left, even) {
1614
- if (this.localeDataProvider.isTwelveHourClock()) {
1615
- resBlock.innerText = this.localeDataProvider.formatTime(date, "h");
1616
- }
1617
- else {
1618
- resBlock.innerText = this.localeDataProvider.formatTime(date, "HH");
1619
- }
1620
- if (even) {
1621
- resBlock.classList.add(TimelineElement_1.STYLE_EVEN);
1622
- }
1623
- else {
1624
- resBlock.classList.remove(TimelineElement_1.STYLE_EVEN);
1625
- }
1626
- if (this.firstDay && (hourCounter == 24 || lastBlock)) {
1627
- this.firstDay = false;
1628
- this.firstResBlockCount = index + 1;
1629
- }
1630
- else if (lastBlock) {
1631
- this.lastResBlockCount = (index + 1 - this.firstResBlockCount) % 24;
1632
- }
1633
- if (this.setPositionForEachBlock && this.isTimelineOverflowingHorizontally()) {
1634
- resBlock.style.position = "relative";
1635
- resBlock.style.left = left + "px";
1636
- }
1637
- }
1638
- };
1639
- TimelineElement.STYLE_ROW = "row";
1640
- TimelineElement.STYLE_COL = "col";
1641
- TimelineElement.STYLE_MONTH = "month";
1642
- TimelineElement.STYLE_YEAR = "year";
1643
- TimelineElement.STYLE_DAY = "day";
1644
- TimelineElement.STYLE_WEEK = "w";
1645
- TimelineElement.STYLE_RESOLUTION = "resolution";
1646
- TimelineElement.STYLE_EVEN = "even";
1647
- TimelineElement.STYLE_WEEKEND = "weekend";
1648
- TimelineElement.STYLE_SPACER = "spacer";
1649
- TimelineElement.STYLE_FIRST = "f-col";
1650
- TimelineElement.STYLE_CENTER = "c-col";
1651
- TimelineElement.STYLE_LAST = "l-col";
1652
- TimelineElement.STYLE_MEASURE = "measure";
1653
- __decorate([
1654
- property({
1655
- reflect: true,
1656
- converter: {
1657
- fromAttribute: (value, type) => {
1658
- return Resolution[value];
1659
- },
1660
- toAttribute: (value, type) => {
1661
- return Resolution[value];
1662
- }
1663
- }
1664
- })
1665
- ], TimelineElement.prototype, "resolution", void 0);
1666
- __decorate([
1667
- property({
1668
- reflect: true,
1669
- converter: {
1670
- fromAttribute: (value, type) => {
1671
- return (value) ? (value.length > 13) ? value.substring(0, 13) : value : value;
1672
- },
1673
- }
1674
- })
1675
- ], TimelineElement.prototype, "startDateTime", void 0);
1676
- __decorate([
1677
- property({
1678
- reflect: true,
1679
- converter: {
1680
- fromAttribute: (value, type) => {
1681
- return (value) ? (value.length > 13) ? value.substring(0, 13) : value : value;
1682
- },
1683
- }
1684
- })
1685
- ], TimelineElement.prototype, "endDateTime", void 0);
1686
- __decorate([
1687
- property({ reflect: true })
1688
- ], TimelineElement.prototype, "timeZone", void 0);
1689
- __decorate([
1690
- property({ reflect: true })
1691
- ], TimelineElement.prototype, "locale", void 0);
1692
- __decorate([
1693
- property({ reflect: true })
1694
- ], TimelineElement.prototype, "firstDayOfWeek", void 0);
1695
- __decorate([
1696
- property({ reflect: true, type: Boolean })
1697
- ], TimelineElement.prototype, "twelveHourClock", void 0);
1698
- __decorate([
1699
- property()
1700
- ], TimelineElement.prototype, "minWidth", void 0);
1701
- __decorate([
1702
- property()
1703
- ], TimelineElement.prototype, "normalStartDate", void 0);
1704
- __decorate([
1705
- property()
1706
- ], TimelineElement.prototype, "normalEndDate", void 0);
1707
- __decorate([
1708
- property()
1709
- ], TimelineElement.prototype, "lastDayOfWeek", void 0);
1710
- __decorate([
1711
- property()
1712
- ], TimelineElement.prototype, "firstDayOfRange", void 0);
1713
- __decorate([
1714
- property()
1715
- ], TimelineElement.prototype, "firstHourOfRange", void 0);
1716
- __decorate([
1717
- property({ reflect: true })
1718
- ], TimelineElement.prototype, "scrollContainerId", void 0);
1719
- __decorate([
1720
- property()
1721
- ], TimelineElement.prototype, "monthRowVisible", void 0);
1722
- __decorate([
1723
- property()
1724
- ], TimelineElement.prototype, "yearRowVisible", void 0);
1725
- __decorate([
1726
- property()
1727
- ], TimelineElement.prototype, "monthNames", void 0);
1728
- __decorate([
1729
- property()
1730
- ], TimelineElement.prototype, "weekdayNames", void 0);
1731
- __decorate([
1732
- query('#resolutionDiv')
1733
- ], TimelineElement.prototype, "resolutionDiv", void 0);
1734
- TimelineElement = TimelineElement_1 = __decorate([
1735
- customElement('timeline-element')
1736
- ], TimelineElement);
225
+ <div id="resolutionDiv" class="row resolution"></div>`;
226
+ }
227
+ yearBlocks() {
228
+ if (this.yearRowVisible) {
229
+ return this.timelineBlocks(this.yearRowData, TimelineElement_1.STYLE_YEAR);
230
+ }
231
+ return nothing;
232
+ }
233
+ monthBlocks() {
234
+ if (this.monthRowVisible) {
235
+ return this.timelineBlocks(this.monthRowData, TimelineElement_1.STYLE_MONTH);
236
+ }
237
+ return nothing;
238
+ }
239
+ dayBlocks() {
240
+ if (this.isDayRowVisible) {
241
+ return this.timelineBlocks(this.dayRowData, TimelineElement_1.STYLE_DAY);
242
+ }
243
+ return nothing;
244
+ }
245
+ shouldUpdate(changedProperties) {
246
+ return changedProperties.has('resolution')
247
+ || changedProperties.has('startDateTime')
248
+ || changedProperties.has('endDateTime')
249
+ || changedProperties.has('locale')
250
+ || changedProperties.has('timeZone')
251
+ || changedProperties.has('firstDayOfWeek')
252
+ || changedProperties.has('twelveHourClock')
253
+ || changedProperties.has('yearRowVisible')
254
+ || changedProperties.has('monthRowVisible')
255
+ || changedProperties.has('monthNames')
256
+ || changedProperties.has('weekdayNames')
257
+ || changedProperties.has('currentDateVisible');
258
+ }
259
+ willUpdate(changedProps) {
260
+ if (changedProps.has('resolution')) {
261
+ this.minResolutionWidth = -1;
262
+ }
263
+ if (changedProps.has('resolution') || changedProps.has('startDateTime') || changedProps.has('timeZone')) {
264
+ this.firstDayOfRange = null;
265
+ if (this.resolution === Resolution.Hour) {
266
+ this.internalInclusiveStartDateTime = toDate(this.startDateTime, { timeZone: this.timeZone });
267
+ }
268
+ else {
269
+ this.internalInclusiveStartDateTime = toDate(this.startDateTime.substring(0, 10) + 'T00:00:00.000', { timeZone: this.timeZone });
270
+ }
271
+ }
272
+ if (changedProps.has('resolution') || changedProps.has('endDateTime') || changedProps.has('timeZone')) {
273
+ // given time must be always exact hour in millisecod accuracy 1AM means exactly "01:00:00.000".
274
+ if (this.resolution === Resolution.Hour) {
275
+ // convert given time to last millisecond in the given hour. 1AM becomes "01:59:59.999" set to internalEndDateTime.
276
+ this.internalInclusiveEndDateTime = toDate(this.endDateTime.substring(0, 13) + ':59:59.999', { timeZone: this.timeZone });
277
+ }
278
+ else {
279
+ this.internalInclusiveEndDateTime = toDate(this.endDateTime.substring(0, 10) + 'T23:59:59.999', { timeZone: this.timeZone });
280
+ }
281
+ }
282
+ this.updateTimeLine(this.resolution, this.internalInclusiveStartDateTime, this.internalInclusiveEndDateTime, new DefaultLocaleDataProvider(this.locale, this.timeZone, this.firstDayOfWeek, this.twelveHourClock));
283
+ }
284
+ updated(changedProps) {
285
+ if (!(this.resolution) || !this.internalInclusiveStartDateTime || !this.internalInclusiveEndDateTime) {
286
+ return;
287
+ }
288
+ if (this.resolution !== Resolution.Day && this.resolution !== Resolution.Week && this.resolution !== Resolution.Hour) {
289
+ console.log("TimelineElement resolution " + (this.resolution ? Resolution[this.resolution] : "null")
290
+ + " is not supported");
291
+ return;
292
+ }
293
+ console.log("TimelineElement Constructed content.");
294
+ this.updateWidths();
295
+ console.log("TimelineElement is updated for resolution " + Resolution[this.resolution] + ".");
296
+ this.registerScrollHandler();
297
+ }
298
+ /**
299
+ * <p>
300
+ * Updates the content of this component. Builds the time-line and calculates
301
+ * width and heights for the content (calls in the end
302
+ * {@link #updateWidths()}). This should be called explicitly. Otherwise the
303
+ * component will be empty.
304
+ * <p>
305
+ * Date values should always follow specification in {@link Date#getTime()}.
306
+ * Start and end date is always required.
307
+ *
308
+ * @param resolution
309
+ * Resolution enum (not null)
310
+ * @param startDate
311
+ * Time-line's start date. (inclusive; not null)
312
+ * @param endDate
313
+ * Time-line's end date. (inclusive; not null)
314
+ * @param localeDataProvider
315
+ * Data provider for locale specific data. month names, first day
316
+ * of week etc.
317
+ *
318
+ */
319
+ updateTimeLine(resolution, startDate, endDate, localeDataProvider) {
320
+ if (!localeDataProvider) {
321
+ console.log("TimelineElement requires ILocaleDataProvider. Can't complete update(...) operation.");
322
+ return;
323
+ }
324
+ this.clear();
325
+ console.log("TimelineElement content cleared.");
326
+ if (!(resolution) || !startDate || !endDate) {
327
+ return;
328
+ }
329
+ console.log("TimelineElement Updating content.");
330
+ this.localeDataProvider = localeDataProvider;
331
+ this.resolution = resolution;
332
+ this.resetDateRange(startDate, endDate);
333
+ this.lastDayOfWeek = (localeDataProvider.getFirstDayOfWeek() == 1) ? 7 : Math.max((localeDataProvider.getFirstDayOfWeek() - 1) % 8, 1);
334
+ this.monthNames = this.monthNames || localeDataProvider.getMonthNames();
335
+ this.weekdayNames = this.weekdayNames || localeDataProvider.getWeekdayNames();
336
+ if (this.minResolutionWidth < 0) {
337
+ this.minResolutionWidth = this.calculateResolutionMinWidth();
338
+ }
339
+ if (this.resolution === Resolution.Day || this.resolution === Resolution.Week) {
340
+ this.prepareTimelineForDayOrWeekResolution(this.internalInclusiveStartDateTime, this.internalInclusiveEndDateTime);
341
+ }
342
+ else if (this.resolution === Resolution.Hour) {
343
+ this.prepareTimelineForHourResolution(this.internalInclusiveStartDateTime, this.internalInclusiveEndDateTime);
344
+ }
345
+ }
346
+ resetDateRange(startDate, endDate) {
347
+ this.internalInclusiveStartDateTime = startDate;
348
+ this.internalInclusiveEndDateTime = endDate;
349
+ this.normalStartDate = this.toNormalDate(this.internalInclusiveStartDateTime);
350
+ this.normalEndDate = this.toNormalDate(this.internalInclusiveEndDateTime);
351
+ // Date#getDay() is zero-based: Sunday = 0, Monday = 1, ...
352
+ // this.firstDayOfRange is 1-based (Sunday = 1).
353
+ this.firstDayOfRange = this.firstDayOfRange || this.internalInclusiveStartDateTime.getDay() + 1; // TODO is weekday still correct here?
354
+ this.firstHourOfRange = this.firstHourOfRange || parseInt(this.localeDataProvider.formatTime(this.internalInclusiveStartDateTime, "HH"));
355
+ }
356
+ registerScrollHandler() {
357
+ if (this.scrollHandler) {
358
+ return;
359
+ }
360
+ let timeline = this;
361
+ this.scrollContainer = this.setupScrollContainer();
362
+ this.scrollHandler = function (e) {
363
+ window.requestAnimationFrame(function () {
364
+ let container = timeline.scrollContainer;
365
+ let sl = container.scrollLeft || container.scrollX;
366
+ let st = container.scrollTop || container.scrollY;
367
+ if (sl != timeline.previousContainerScrollLeft) {
368
+ timeline.setScrollLeft(sl);
369
+ timeline.previousContainerScrollLeft = sl;
370
+ }
371
+ if (st != timeline.previousContainerScrollTop) {
372
+ timeline.previousContainerScrollTop = st;
373
+ }
374
+ });
375
+ };
376
+ this.scrollContainer.addEventListener('scroll', this.scrollHandler);
377
+ }
378
+ setupScrollContainer() {
379
+ let scrollContainer;
380
+ if (this.scrollContainerId) {
381
+ scrollContainer = this.getParentElement(this).querySelector('#' + this.scrollContainerId);
382
+ if (!scrollContainer) {
383
+ scrollContainer = document.querySelector('#' + this.scrollContainerId);
384
+ }
385
+ if (scrollContainer) {
386
+ scrollContainer.style.overflowX = "auto";
387
+ }
388
+ }
389
+ if (!scrollContainer) {
390
+ scrollContainer = this.getParentElement(this);
391
+ this.directlyInsideScrollContainer = true;
392
+ if (scrollContainer === document.body) {
393
+ return window; // window scrolls by default, not body
394
+ }
395
+ }
396
+ return scrollContainer;
397
+ }
398
+ clear() {
399
+ this.spacerBlocks = [];
400
+ this.yearRowData.clear();
401
+ this.monthRowData.clear();
402
+ this.dayRowData.clear();
403
+ }
404
+ calculateResolutionMinWidth() {
405
+ let resDivMeasure = document.createElement('div');
406
+ resDivMeasure.classList.add(TimelineElement_1.STYLE_ROW, TimelineElement_1.STYLE_RESOLUTION);
407
+ let resBlockMeasure = document.createElement('div');
408
+ if (this.resolution === Resolution.Week) {
409
+ // configurable with '.col.w.measure' selector
410
+ resBlockMeasure.classList.add(TimelineElement_1.STYLE_COL, TimelineElement_1.STYLE_WEEK, TimelineElement_1.STYLE_MEASURE);
411
+ }
412
+ else {
413
+ // measure for text 'MM'
414
+ resBlockMeasure.innerText = "MM";
415
+ // configurable with '.col.measure' selector
416
+ resBlockMeasure.classList.add(TimelineElement_1.STYLE_COL, TimelineElement_1.STYLE_MEASURE);
417
+ }
418
+ resDivMeasure.appendChild(resBlockMeasure);
419
+ this.shadowRoot.appendChild(resDivMeasure);
420
+ let width = resBlockMeasure.clientWidth;
421
+ if (this.resolution === Resolution.Week) {
422
+ // divide given width by number of days in week
423
+ width = width / DateTimeConstants.DAYS_IN_WEEK;
424
+ }
425
+ width = (width < this.resolutionWeekDayblockWidth) ? this.resolutionWeekDayblockWidth : width;
426
+ this.shadowRoot.removeChild(resDivMeasure);
427
+ return width;
428
+ }
429
+ registerHourResolutionBlock() {
430
+ this.blocksInRange++;
431
+ this.resolutionBlockCount++;
432
+ }
433
+ registerDayResolutionBlock() {
434
+ this.blocksInRange++;
435
+ this.resolutionBlockCount++;
436
+ }
437
+ registerWeekResolutionBlock(index, weekDay, lastBlock, firstWeek) {
438
+ if (index == 0 || weekDay === Weekday.First) {
439
+ this.resolutionBlockCount++;
440
+ }
441
+ if (firstWeek && (weekDay === Weekday.Last || lastBlock)) {
442
+ this.firstResBlockCount = index + 1;
443
+ }
444
+ else if (lastBlock) {
445
+ this.lastResBlockCount = (index + 1 - this.firstResBlockCount) % 7;
446
+ }
447
+ this.blocksInRange++;
448
+ }
449
+ timelineBlocks(rowData, style) {
450
+ const itemTemplates = [];
451
+ for (let entry of rowData.getBlockEntries()) {
452
+ itemTemplates.push(html `${entry[1]}`);
453
+ }
454
+ if (this.isAlwaysCalculatePixelWidths()) {
455
+ itemTemplates.push(html `${this.createSpacerBlock(style)}`);
456
+ }
457
+ return itemTemplates;
458
+ }
459
+ /**
460
+ * Returns true if Widget is set to calculate widths by itself. Default is
461
+ * false.
462
+ *
463
+ * @return
464
+ */
465
+ isAlwaysCalculatePixelWidths() {
466
+ return this.calcPixels;
467
+ }
468
+ createSpacerBlock(className) {
469
+ let block = document.createElement('div');
470
+ block.classList.add(TimelineElement_1.STYLE_ROW, TimelineElement_1.STYLE_YEAR, TimelineElement_1.STYLE_SPACER);
471
+ block.innerText = " ";
472
+ block.style.display = "none"; // not visible by default
473
+ this.spacerBlocks.push(block);
474
+ return block;
475
+ }
476
+ /** Clears Daylight saving time adjustment from the given time. */
477
+ toNormalDate(zonedDate) {
478
+ return DateUtil.toNormalDate(zonedDate, this.localeDataProvider.getDaylightAdjustment(zonedDate));
479
+ }
480
+ getDSTAdjustedDate(previousIsDST, zonedDate) {
481
+ return DateUtil.getDSTAdjustedDate(previousIsDST, zonedDate, this.localeDataProvider.getDaylightAdjustment(zonedDate));
482
+ }
483
+ getParentElement(node) {
484
+ var parent = node.parentNode;
485
+ if (!parent || parent.nodeType != 1) {
486
+ parent = null;
487
+ }
488
+ return parent;
489
+ }
490
+ getDay(date) {
491
+ // by adjusting the date to the middle of the day before formatting is a
492
+ // workaround to avoid DST issues with DateTimeFormatter.
493
+ let adjusted = DateUtil.adjustToMiddleOfDay(date, this.localeDataProvider.getTimeZone());
494
+ return this.localeDataProvider.formatDate(adjusted, "d");
495
+ }
496
+ getYear(date) {
497
+ return this.localeDataProvider.formatDate(date, "yyyy");
498
+ }
499
+ getMonth(date) {
500
+ let m = this.localeDataProvider.formatDate(date, "M");
501
+ return parseInt(m) - 1;
502
+ }
503
+ isWeekEnd(dayCounter) {
504
+ return dayCounter == 1 || dayCounter == 7;
505
+ }
506
+ key(prefix, rowData) {
507
+ return prefix + "_" + (rowData.size());
508
+ }
509
+ newKey(prefix, rowData) {
510
+ return prefix + "_" + (rowData.size() + 1);
511
+ }
512
+ addBlock(current, target, date, rowData, operation) {
513
+ let key;
514
+ if (target !== current) {
515
+ current = target;
516
+ key = this.newKey("" + current, rowData);
517
+ operation(target, key, date);
518
+ }
519
+ else {
520
+ key = this.key("" + current, rowData);
521
+ rowData.setBlockLength(key, rowData.getBlockLength(key) + 1);
522
+ }
523
+ return current;
524
+ }
525
+ addDayBlock(currentDay, date) {
526
+ let day = this.getDay(date);
527
+ return this.addBlock(currentDay, day, date, this.dayRowData, (day, key, date) => {
528
+ let block = this.addDayBlockElement(key, this.formatDayCaption(day, date));
529
+ block.dataset.day = this.localeDataProvider.formatDate(date, TimelineElement_1.CURRENT_DAY_FORMAT);
530
+ });
531
+ }
532
+ addMonthBlock(currentMonth, date) {
533
+ let month = this.getMonth(date);
534
+ return this.addBlock(currentMonth, "" + month, date, this.monthRowData, (target, key, date) => {
535
+ this.addMonthBlockElement(key, this.formatMonthCaption(month, date));
536
+ });
537
+ }
538
+ addYearBlock(currentYear, date) {
539
+ let year = this.getYear(date);
540
+ return this.addBlock(currentYear, year, date, this.yearRowData, (year, key, date) => {
541
+ this.addYearBlockElement(key, this.formatYearCaption(year, date));
542
+ });
543
+ }
544
+ addMonthBlockElement(key, text) {
545
+ this.createTimelineBlock(key, text, TimelineElement_1.STYLE_MONTH, this.monthRowData);
546
+ }
547
+ addYearBlockElement(key, text) {
548
+ this.createTimelineBlock(key, text, TimelineElement_1.STYLE_YEAR, this.yearRowData);
549
+ }
550
+ addDayBlockElement(key, text) {
551
+ return this.createTimelineBlock(key, text, TimelineElement_1.STYLE_DAY, this.dayRowData);
552
+ }
553
+ createTimelineBlock(key, text, styleSuffix, rowData) {
554
+ let div = document.createElement('div');
555
+ div.classList.add(TimelineElement_1.STYLE_ROW, styleSuffix);
556
+ div.innerText = text;
557
+ rowData.setBlockLength(key, 1);
558
+ rowData.setBlock(key, div);
559
+ return div;
560
+ }
561
+ formatDayCaption(day, date) {
562
+ if (!this.dayFormat || this.dayFormat === "") {
563
+ return day;
564
+ }
565
+ return this.localeDataProvider.formatDate(date, this.dayFormat);
566
+ }
567
+ formatYearCaption(year, date) {
568
+ if (!this.yearFormat || this.yearFormat === "") {
569
+ return year;
570
+ }
571
+ return this.localeDataProvider.formatDate(date, this.yearFormat);
572
+ }
573
+ formatWeekCaption(date) {
574
+ if (!this.weekFormat || this.weekFormat === "") {
575
+ return "" + getISOWeek(date);
576
+ }
577
+ return this.localeDataProvider.formatDate(date, this.weekFormat);
578
+ }
579
+ formatMonthCaption(month, date) {
580
+ if (!this.monthFormat || this.monthFormat === "") {
581
+ return this.monthNames[month];
582
+ }
583
+ return this.localeDataProvider.formatDate(date, this.monthFormat);
584
+ }
585
+ getWeekday(dayCounter) {
586
+ if (dayCounter === this.localeDataProvider.getFirstDayOfWeek()) {
587
+ return Weekday.First;
588
+ }
589
+ if (dayCounter === this.lastDayOfWeek) {
590
+ return Weekday.Last;
591
+ }
592
+ return Weekday.Between;
593
+ }
594
+ prepareTimelineForHourResolution(startDate, endDate) {
595
+ let timeline = this;
596
+ this.firstDay = true;
597
+ let hourCounter = this.firstHourOfRange;
598
+ this.prepareTimelineForHour(DateTimeConstants.HOUR_INTERVAL, startDate, endDate, {
599
+ registerResolutionBlock(index, date, currentYear, lastTimelineBlock) {
600
+ timeline.registerHourResolutionBlock();
601
+ hourCounter = Math.max((hourCounter + 1) % 25, 1);
602
+ }
603
+ });
604
+ }
605
+ prepareTimelineForHour(interval, startDate, endDate, resBlockRegisterer) {
606
+ this.blocksInRange = 0;
607
+ this.resolutionBlockCount = 0;
608
+ this.firstResBlockCount = 0;
609
+ this.lastResBlockCount = 0;
610
+ let currentYear = null;
611
+ let currentMonth = null;
612
+ let currentDay = null;
613
+ let pos = startDate;
614
+ let end = endDate;
615
+ let index = 0;
616
+ let lastTimelineBlock = false;
617
+ let date;
618
+ while (pos.getTime() <= end.getTime()) {
619
+ date = pos;
620
+ let nextHour = new Date(pos.getTime() + interval);
621
+ lastTimelineBlock = nextHour.getTime() > end.getTime();
622
+ resBlockRegisterer.registerResolutionBlock(index, date, currentYear, lastTimelineBlock);
623
+ if (this.yearRowVisible) {
624
+ currentYear = this.addYearBlock(currentYear, date);
625
+ }
626
+ if (this.monthRowVisible) {
627
+ currentMonth = this.addMonthBlock(currentMonth, date);
628
+ }
629
+ if (this.isDayRowVisible()) {
630
+ currentDay = this.addDayBlock(currentDay, date);
631
+ }
632
+ pos = nextHour;
633
+ index++;
634
+ }
635
+ }
636
+ prepareTimelineForDayOrWeekResolution(startDate, endDate) {
637
+ let timeline = this;
638
+ let dayCounter = this.firstDayOfRange;
639
+ let weekday;
640
+ let firstWeek = true;
641
+ this.prepareTimelineForDayOrWeek(DateTimeConstants.DAY_INTERVAL, startDate, endDate, {
642
+ registerResolutionBlock: function (index, date, currentYear, lastTimelineBlock) {
643
+ weekday = timeline.getWeekday(dayCounter);
644
+ if (timeline.resolution === Resolution.Week) {
645
+ timeline.registerWeekResolutionBlock(index, weekday, lastTimelineBlock, firstWeek);
646
+ if (firstWeek && (weekday === Weekday.Last || lastTimelineBlock)) {
647
+ firstWeek = false;
648
+ }
649
+ }
650
+ else {
651
+ timeline.registerDayResolutionBlock();
652
+ }
653
+ dayCounter = Math.max((dayCounter + 1) % 8, 1);
654
+ }
655
+ });
656
+ }
657
+ prepareTimelineForDayOrWeek(interval, startDate, endDate, resBlockRegisterer) {
658
+ this.blocksInRange = 0;
659
+ this.resolutionBlockCount = 0;
660
+ this.firstResBlockCount = 0;
661
+ this.lastResBlockCount = 0;
662
+ let currentYear = null;
663
+ let currentMonth = null;
664
+ let currentDay = null;
665
+ let pos = DateUtil.adjustToMiddleOfDay(startDate, this.localeDataProvider.getTimeZone());
666
+ let end = endDate;
667
+ let index = 0;
668
+ let lastTimelineBlock = false;
669
+ let date;
670
+ let isDST = false;
671
+ let isPreviousDst = this.localeDataProvider.isDaylightTime(startDate);
672
+ while (!lastTimelineBlock) {
673
+ let date = DateUtil.getDSTAdjustedDate(isPreviousDst, pos, this.localeDataProvider.getDaylightAdjustment(pos));
674
+ pos = date;
675
+ isDST = this.localeDataProvider.isDaylightTime(date);
676
+ let d = new Date(date.getTime() + interval);
677
+ lastTimelineBlock = DateUtil.getDSTAdjustedDate(isDST, d, this.localeDataProvider.getDaylightAdjustment(d)).getTime() > end.getTime();
678
+ resBlockRegisterer.registerResolutionBlock(index, date, currentYear, lastTimelineBlock);
679
+ if (this.yearRowVisible) {
680
+ currentYear = this.addYearBlock(currentYear, date);
681
+ }
682
+ if (this.monthRowVisible) {
683
+ currentMonth = this.addMonthBlock(currentMonth, date);
684
+ }
685
+ if (this.isDayRowVisible()) {
686
+ currentDay = this.addDayBlock(currentDay, date);
687
+ }
688
+ isPreviousDst = isDST;
689
+ pos = new Date(pos.getTime() + interval);
690
+ index++;
691
+ }
692
+ }
693
+ isDayRowVisible() {
694
+ return this.resolution === Resolution.Hour;
695
+ }
696
+ /**
697
+ * Get actual width of the timeline.
698
+ *
699
+ * @return
700
+ */
701
+ getResolutionWidth() {
702
+ if (!this.isTimelineOverflowingHorizontally()) {
703
+ return this.calculateTimelineWidth();
704
+ }
705
+ let width = this.getResolutionDivWidth();
706
+ if (this.isAlwaysCalculatePixelWidths() && this.containsResBlockSpacer()) {
707
+ width = width - ElementUtil.getWidth(this.resSpacerDiv);
708
+ }
709
+ return width;
710
+ }
711
+ /**
712
+ * Calculate the exact width of the timeline. Excludes any spacers in the
713
+ * end.
714
+ *
715
+ * @return
716
+ */
717
+ calculateTimelineWidth() {
718
+ let last = this.getLastResolutionElement();
719
+ if (last === null) {
720
+ return 0.0;
721
+ }
722
+ let r = ElementUtil.getRight(last);
723
+ let l = ElementUtil.getLeft(this.getFirstResolutionElement());
724
+ let timelineRealWidth = r - l;
725
+ return timelineRealWidth;
726
+ }
727
+ /*
728
+ * Get width of the resolution div element.
729
+ */
730
+ getResolutionDivWidth() {
731
+ if (!this.isTimelineOverflowingHorizontally()) {
732
+ return ElementUtil.getWidth(this.resolutionDiv);
733
+ }
734
+ return this.blocksInRange * this.minResolutionWidth;
735
+ }
736
+ /**
737
+ * Calculate matching left offset in percentage for a date (
738
+ * {@link Date#getTime()}).
739
+ *
740
+ * @param date
741
+ * Target date in milliseconds.
742
+ * @param contentWidth
743
+ * Width of the content that the given 'date' is relative to.
744
+ * @return Left offset in percentage.
745
+ */
746
+ getLeftPositionPercentageForDate(date, contentWidth) {
747
+ let timelineLeft = this.getLeftPositionForDate(date);
748
+ let relativeLeft = this.convertRelativeLeftPosition(timelineLeft, contentWidth);
749
+ let width = this.getResolutionWidth();
750
+ return (100.0 / width) * relativeLeft;
751
+ }
752
+ /**
753
+ * Calculate CSS value for 'left' property matching left offset in
754
+ * percentage for a date ( {@link Date#getTime()}).
755
+ * <p>
756
+ * May return '2.123456%' or 'calc(2.123456%)' if IE;
757
+ *
758
+ * @param date
759
+ * Target date in milliseconds.
760
+ * @param contentWidth
761
+ * Width of the content that the given 'date' is relative to.
762
+ * @return Left offset as a String value.
763
+ */
764
+ getLeftPositionPercentageStringForDate(date, contentWidth) {
765
+ let timelineLeft = this.getLeftPositionForDate(date);
766
+ let relativeLeft = this.convertRelativeLeftPosition(timelineLeft, contentWidth);
767
+ let width = this.getResolutionWidth();
768
+ let calc = this.createCalcCssValue(width, relativeLeft);
769
+ if (calc != null) {
770
+ return calc;
771
+ }
772
+ return (100.0 / width) * relativeLeft + "%";
773
+ }
774
+ getLeftPositionPercentageStringForDateRange(date, rangeWidth, rangeStartDate, rangeEndDate) {
775
+ let rangeLeft = this.getLeftPositionForDateRange(date, rangeWidth, rangeStartDate, rangeEndDate);
776
+ let width = rangeWidth;
777
+ let calc = this.createCalcCssValue(width, rangeLeft);
778
+ if (calc != null) {
779
+ return calc;
780
+ }
781
+ return (100.0 / width) * rangeLeft + "%";
782
+ }
783
+ /**
784
+ * Calculate CSS value for 'width' property matching date interval inside
785
+ * the time-line. Returns percentage value. Interval is in milliseconds.
786
+ * <p>
787
+ * May return '2.123456%' or 'calc(2.123456%)' if IE;
788
+ *
789
+ * @param interval
790
+ * Date interval in milliseconds.
791
+ * @return
792
+ */
793
+ getWidthPercentageStringForDateInterval(interval) {
794
+ let range = this.internalInclusiveEndDateTime.getTime() - this.internalInclusiveStartDateTime.getTime();
795
+ return this.getWidthPercentageStringForDateIntervalForRange(interval, range);
796
+ }
797
+ /** @see #getWidthPercentageStringForDateInterval(long) */
798
+ getWidthPercentageStringForDateIntervalForRange(interval, range) {
799
+ let calc = this.createCalcCssValue(range, interval);
800
+ if (calc != null) {
801
+ return calc;
802
+ }
803
+ return (100.0 / range) * interval + "%";
804
+ }
805
+ /**
806
+ * Calculate matching left offset in pixels for a date (
807
+ * {@link Date#getTime()}).
808
+ *
809
+ * @param date
810
+ * Target date in milliseconds.
811
+ * @return Left offset in pixels.
812
+ */
813
+ getLeftPositionForDate(date) {
814
+ return this.getLeftPositionForDateRange(date, this.getResolutionWidth(), this.internalInclusiveStartDateTime, this.internalInclusiveEndDateTime);
815
+ }
816
+ getLeftPositionForDateRange(date, rangeWidth, rangeStartDate, rangeEndDate) {
817
+ let width = rangeWidth;
818
+ let range = rangeEndDate.getTime() - rangeStartDate.getTime();
819
+ if (range <= 0) {
820
+ return 0;
821
+ }
822
+ let p = width / range;
823
+ let offset = date.getTime() - rangeStartDate.getTime();
824
+ let left = p * offset;
825
+ return left;
826
+ }
827
+ /**
828
+ * Calculate matching date ({@link Date#getTime()}) for the target left
829
+ * pixel offset.
830
+ *
831
+ * @param left
832
+ * Left offset in pixels.
833
+ * @return Date in a milliseconds or null if timeline width is invalid (<=0).
834
+ */
835
+ getDateForLeftPosition(left) {
836
+ return this.getDateForLeftPositionNoticeDST(left, this.resolution === Resolution.Hour);
837
+ }
838
+ getDateForLeftPositionNoticeDST(left, noticeDST) {
839
+ let width = this.getResolutionWidth();
840
+ if (width <= 0) {
841
+ return null;
842
+ }
843
+ let range = this.normalEndDate.getTime() - this.normalStartDate.getTime();
844
+ if (noticeDST) {
845
+ range = this.adjustDateRangeByDST(range);
846
+ }
847
+ let p = range / width;
848
+ let offset = p * left;
849
+ let date = new Date(this.internalInclusiveStartDateTime.getTime() + offset);
850
+ console.log("Zoned: " + this.localeDataProvider.formatDate(date, "dd. HH:mm") + " DST: "
851
+ + this.localeDataProvider.getDaylightAdjustment(date) / 60000);
852
+ return date;
853
+ }
854
+ /**
855
+ * Convert left position for other relative target width.
856
+ *
857
+ * @param left
858
+ * @param contentWidthToConvertFor
859
+ * @return
860
+ */
861
+ convertRelativeLeftPosition(left, contentWidthToConvertFor) {
862
+ let width = this.getResolutionWidth();
863
+ if (width <= 0 || contentWidthToConvertFor <= 0) {
864
+ return 0;
865
+ }
866
+ let relativePosition = (1.0 / contentWidthToConvertFor) * left;
867
+ let timelineLeft = relativePosition * width;
868
+ return timelineLeft;
869
+ }
870
+ adjustDateRangeByDST(range) {
871
+ /*
872
+ * Notice extra block(s) or missing block(s) in range when start time is
873
+ * in DST and end time is not, or vice versa.
874
+ */
875
+ let dstStart = this.localeDataProvider.getDaylightAdjustment(this.internalInclusiveStartDateTime);
876
+ let dstEnd = this.localeDataProvider.getDaylightAdjustment(this.internalInclusiveEndDateTime);
877
+ if (dstStart > dstEnd) {
878
+ range -= Math.abs(dstStart - dstEnd);
879
+ }
880
+ else if (dstEnd > dstStart) {
881
+ range += Math.abs(dstEnd - dstStart);
882
+ }
883
+ return range;
884
+ }
885
+ /**
886
+ * Set horizontal scroll position for the time-line.
887
+ *
888
+ * @param left
889
+ * Scroll position in pixels.
890
+ */
891
+ setScrollLeft(left) {
892
+ if (this.positionLeft === left) {
893
+ return;
894
+ }
895
+ this.positionLeft = left || 0;
896
+ if (!this.directlyInsideScrollContainer) {
897
+ this.style.left = -this.positionLeft + "px";
898
+ }
899
+ this.lazyResolutionPaint = setTimeout(() => this.fillVisibleTimeline(), 20);
900
+ }
901
+ /**
902
+ * Re-calculates required widths for this widget.
903
+ * <p>
904
+ * Re-creates and fills the visible part of the resolution element.
905
+ */
906
+ updateWidths() {
907
+ if (this.resolutionDiv == null) {
908
+ console.log("TimelineElement is not ready for updateWidths() call. Call update(...) instead.");
909
+ return;
910
+ }
911
+ console.log("TimelineElement Started updating widths.");
912
+ // start by clearing old content in resolution element
913
+ while (this.resolutionDiv.firstChild) {
914
+ this.resolutionDiv.removeChild(this.resolutionDiv.lastChild);
915
+ }
916
+ this.setMinWidth(this.blocksInRange * this.minResolutionWidth);
917
+ // update horizontal overflow state here, after min-width is updated.
918
+ this.updateTimelineOverflowingHorizontally();
919
+ this.createTimelineElementsOnVisibleArea();
920
+ // fill timeline
921
+ this.fillVisibleTimeline();
922
+ // remove spacer block if it exist
923
+ this.removeResolutionSpacerBlock();
924
+ // calculate new block width for day-resolution.
925
+ // Year and month blocks are vertically in-line with days.
926
+ this.dayWidthPercentage = 100.0 / this.blocksInRange;
927
+ this.dayOrHourWidthPx = this.calculateDayOrHourResolutionBlockWidthPx(this.blocksInRange);
928
+ // calculate block width for currently selected resolution
929
+ // (day,week,...)
930
+ // resolution div's content may not be vertically in-line with
931
+ // year/month blocks. This is the case for example with Week resolution.
932
+ this.resBlockMinWidthPx = this.minResolutionWidth;
933
+ this.resBlockWidthPx = this.calculateActualResolutionBlockWidthPx(this.dayOrHourWidthPx);
934
+ this.resBlockWidthPercentage = 100.0 / this.resolutionBlockCount;
935
+ let pct = this.createCalcCssValue(this.resolutionBlockCount, null);
936
+ if (this.resolution === Resolution.Week) {
937
+ this.resBlockMinWidthPx = DateTimeConstants.DAYS_IN_WEEK * this.minResolutionWidth;
938
+ this.resBlockWidthPercentage = this.dayWidthPercentage * DateTimeConstants.DAYS_IN_WEEK;
939
+ pct = this.createCalcCssValue(this.blocksInRange, DateTimeConstants.DAYS_IN_WEEK);
940
+ }
941
+ // update resolution block widths
942
+ this.updateResolutionBlockWidths(pct);
943
+ if (this.yearRowVisible) {
944
+ // update year block widths
945
+ this.updateBlockWidths(this.yearRowData);
946
+ }
947
+ if (this.monthRowVisible) {
948
+ // update month block widths
949
+ this.updateBlockWidths(this.monthRowData);
950
+ }
951
+ if (this.isDayRowVisible()) {
952
+ this.updateBlockWidths(this.dayRowData);
953
+ }
954
+ if (this.isAlwaysCalculatePixelWidths()) {
955
+ this.updateSpacerBlocks(this.dayOrHourWidthPx);
956
+ }
957
+ console.log("TimelineElement Widths are updated.");
958
+ }
959
+ updateBlockWidths(rowData) {
960
+ for (let entry of rowData.getBlockEntries()) {
961
+ this.setWidth(entry[1], rowData.getBlockLength(entry[0]));
962
+ }
963
+ }
964
+ updateSpacerBlocks(dayWidthPx) {
965
+ let spaceLeft = this.getResolutionDivWidth() - (this.blocksInRange * dayWidthPx);
966
+ if (spaceLeft > 0) {
967
+ for (let e of this.spacerBlocks) {
968
+ e.style.removeProperty("display");
969
+ e.style.width = spaceLeft + "px";
970
+ }
971
+ this.resSpacerDiv = this.createResolutionBlock();
972
+ this.resSpacerDiv.classList.add(TimelineElement_1.STYLE_SPACER);
973
+ this.resSpacerDiv.style.width = spaceLeft + "px";
974
+ this.resSpacerDiv.innerText = " ";
975
+ this.resolutionDiv.appendChild(this.resSpacerDiv);
976
+ }
977
+ else {
978
+ this.hideSpacerBlocks();
979
+ }
980
+ }
981
+ hideSpacerBlocks() {
982
+ for (let e of this.spacerBlocks) {
983
+ e.style.display = "none";
984
+ }
985
+ }
986
+ /**
987
+ * Set minimum width (pixels) of this widget's root DIV element. Default is
988
+ * -1. Notice that
989
+ * {@link #update(Resolution, long, long, int, int, LocaleDataProvider)}
990
+ * will calculate min-width and call this internally.
991
+ *
992
+ * @param minWidth
993
+ * Minimum width in pixels.
994
+ */
995
+ setMinWidth(minWidth) {
996
+ this.minWidth = minWidth;
997
+ this.style.minWidth = this.minWidth + "px";
998
+ this.resolutionDiv.style.minWidth = this.minWidth + "px";
999
+ }
1000
+ /**
1001
+ * Returns true if the timeline is overflowing the parent's width. This
1002
+ * works only when this widget is attached to some parent.
1003
+ *
1004
+ * @return True when timeline width is more than the parent's width (@see
1005
+ * {@link Element#getClientWidth()}).
1006
+ */
1007
+ isTimelineOverflowingHorizontally() {
1008
+ return this.timelineOverflowingHorizontally;
1009
+ }
1010
+ /**
1011
+ * Update horizontal overflow state.
1012
+ */
1013
+ updateTimelineOverflowingHorizontally() {
1014
+ this.timelineOverflowingHorizontally = (ElementUtil.getWidth(this.resolutionDiv) > ElementUtil.getWidth(this.getParentElement(this)));
1015
+ }
1016
+ createTimelineElementsOnVisibleArea() {
1017
+ // create place holder elements that represents weeks/days/hours
1018
+ // depending on the resolution in the timeline.
1019
+ // Only visible blocks are created, and only once, content will change
1020
+ // on scroll.
1021
+ // first: detect how many blocks we can fit in the screen
1022
+ let blocks = this.resolutionBlockCount;
1023
+ if (this.isTimelineOverflowingHorizontally()) {
1024
+ blocks = Math.floor((ElementUtil.getWidth(this.getParentElement(this))
1025
+ / this.calculateMinimumResolutionBlockWidth()));
1026
+ if (this.resolutionBlockCount < blocks) {
1027
+ // blocks need to be scaled up to fit the screen
1028
+ blocks = this.resolutionBlockCount;
1029
+ }
1030
+ else {
1031
+ blocks += 2;
1032
+ }
1033
+ }
1034
+ let element = null;
1035
+ for (let i = 0; i < blocks; i++) {
1036
+ switch (this.resolution) {
1037
+ case Resolution.Hour:
1038
+ element = this.createHourResolutionBlock();
1039
+ break;
1040
+ case Resolution.Day:
1041
+ element = this.createDayResolutionBlock();
1042
+ break;
1043
+ case Resolution.Week:
1044
+ element = this.createWeekResolutionBlock();
1045
+ break;
1046
+ }
1047
+ this.resolutionDiv.appendChild(element);
1048
+ }
1049
+ console.log(`TimelineElement Added ${blocks} visible timeline elements for resolution ${Resolution[this.resolution]}`);
1050
+ }
1051
+ calculateMinimumResolutionBlockWidth() {
1052
+ if (this.resolution === Resolution.Week) {
1053
+ return DateTimeConstants.DAYS_IN_WEEK * this.minResolutionWidth;
1054
+ }
1055
+ return this.minResolutionWidth;
1056
+ }
1057
+ createResolutionBlock() {
1058
+ let resBlock = document.createElement('div');
1059
+ resBlock.classList.add("col");
1060
+ return resBlock;
1061
+ }
1062
+ createHourResolutionBlock() {
1063
+ let resBlock = this.createResolutionBlock();
1064
+ resBlock.classList.add("h", TimelineElement_1.STYLE_CENTER);
1065
+ return resBlock;
1066
+ }
1067
+ createDayResolutionBlock() {
1068
+ let resBlock = this.createResolutionBlock();
1069
+ resBlock.classList.add(TimelineElement_1.STYLE_CENTER);
1070
+ return resBlock;
1071
+ }
1072
+ createWeekResolutionBlock() {
1073
+ let resBlock = this.createResolutionBlock();
1074
+ resBlock.classList.add("w", TimelineElement_1.STYLE_CENTER);
1075
+ return resBlock;
1076
+ }
1077
+ fillVisibleTimeline() {
1078
+ if (this.isTimelineOverflowingHorizontally()) {
1079
+ this.showResolutionBlocksOnView();
1080
+ }
1081
+ else {
1082
+ this.showAllResolutionBlocks();
1083
+ }
1084
+ }
1085
+ showResolutionBlocksOnView() {
1086
+ let positionLeftSnapshot = this.positionLeft;
1087
+ let datePos = positionLeftSnapshot;
1088
+ this.firstWeekBlockHidden = false;
1089
+ let left = Math.floor(positionLeftSnapshot);
1090
+ if (positionLeftSnapshot > 0 && this.resBlockWidthPx > 0) {
1091
+ let overflow = 0.0;
1092
+ let firstResBlockShort = this.isFirstResBlockShort();
1093
+ overflow = this.getScrollOverflowForResolutionBlock(positionLeftSnapshot, left, firstResBlockShort);
1094
+ left = Math.floor(positionLeftSnapshot - overflow);
1095
+ datePos = this.adjustLeftPositionForDateDetection(left);
1096
+ }
1097
+ if (datePos < 0.0) {
1098
+ datePos = positionLeftSnapshot;
1099
+ }
1100
+ let leftDate;
1101
+ let noticeDst = this.resolution === Resolution.Hour;
1102
+ leftDate = this.getDateForLeftPositionNoticeDST(datePos, noticeDst);
1103
+ let containerWidth = ElementUtil.getWidth(this.getParentElement(this));
1104
+ this.fillTimelineForResolution(leftDate, new Date(Math.min(this.internalInclusiveEndDateTime.getTime(), this.getDateForLeftPositionNoticeDST(datePos + containerWidth, noticeDst).getTime())), left);
1105
+ this.style.setProperty("--timeline-col-position", "relative");
1106
+ this.style.setProperty("--timeline-col-left", left + "px");
1107
+ console.log(`TimelineElement Updated visible timeline elements for horizontal scroll position ${left} (plus ${datePos - left} to center-of-first-block)`);
1108
+ }
1109
+ showAllResolutionBlocks() {
1110
+ this.style.setProperty("--timeline-col-position", "relative");
1111
+ this.style.setProperty("--timeline-col-left", "0px");
1112
+ this.fillTimelineForResolution(this.internalInclusiveStartDateTime, this.internalInclusiveEndDateTime, 0);
1113
+ }
1114
+ /**
1115
+ * Re-applies 'current' style to the currently shown resolution blocks and day
1116
+ * row blocks without rebuilding the timeline. Call this when the current day
1117
+ * or hour changes.
1118
+ */
1119
+ refreshCurrentDate() {
1120
+ if (!this.localeDataProvider || !this.resolutionDiv || !this.internalInclusiveStartDateTime
1121
+ || !this.internalInclusiveEndDateTime || this.resolutionDiv.childElementCount === 0) {
1122
+ return;
1123
+ }
1124
+ this.fillVisibleTimeline();
1125
+ }
1126
+ updateCurrentDayString() {
1127
+ this.currentDayString = (this.currentDateVisible && this.localeDataProvider)
1128
+ ? this.localeDataProvider.formatDate(new Date(), TimelineElement_1.CURRENT_DAY_FORMAT)
1129
+ : null;
1130
+ this.currentHourString = (this.currentDateVisible && this.localeDataProvider)
1131
+ ? this.localeDataProvider.formatDate(new Date(), TimelineElement_1.CURRENT_HOUR_FORMAT)
1132
+ : null;
1133
+ }
1134
+ isCurrentDay(date) {
1135
+ return this.currentDayString != null && date != null
1136
+ && this.localeDataProvider.formatDate(date, TimelineElement_1.CURRENT_DAY_FORMAT) === this.currentDayString;
1137
+ }
1138
+ isCurrentHour(date) {
1139
+ // Compare the hour bucket in the configured time zone, so the result does
1140
+ // not depend on where inside the hour the given date falls.
1141
+ return this.currentHourString != null && date != null
1142
+ && this.localeDataProvider.formatDate(date, TimelineElement_1.CURRENT_HOUR_FORMAT) === this.currentHourString;
1143
+ }
1144
+ setCurrentStyle(element, current) {
1145
+ if (current) {
1146
+ element.classList.add(TimelineElement_1.STYLE_CURRENT);
1147
+ }
1148
+ else {
1149
+ element.classList.remove(TimelineElement_1.STYLE_CURRENT);
1150
+ }
1151
+ }
1152
+ updateDayRowCurrentStyles() {
1153
+ if (!this.isDayRowVisible()) {
1154
+ return;
1155
+ }
1156
+ for (let entry of this.dayRowData.getBlockEntries()) {
1157
+ let block = entry[1];
1158
+ this.setCurrentStyle(block, this.currentDayString != null && block.dataset.day === this.currentDayString);
1159
+ }
1160
+ }
1161
+ fillTimelineForResolution(startDate, endDate, left) {
1162
+ this.updateCurrentDayString();
1163
+ this.updateDayRowCurrentStyles();
1164
+ if (this.resolution === Resolution.Day || this.resolution === Resolution.Week) {
1165
+ this.fillTimelineForDayResolution(startDate, endDate, left);
1166
+ }
1167
+ else if (this.resolution == Resolution.Hour) {
1168
+ this.fillTimelineForHourResolution(startDate, endDate, left);
1169
+ }
1170
+ else {
1171
+ console.log("TimelineElement resolution " + (this.resolution != null ? Resolution[this.resolution] : "null")
1172
+ + " is not supported");
1173
+ return;
1174
+ }
1175
+ console.log("TimelineElement Filled new data and styles to visible timeline elements");
1176
+ }
1177
+ isFirstResBlockShort() {
1178
+ return this.firstResBlockCount > 0 && ((this.resolution === Resolution.Week && this.firstResBlockCount < DateTimeConstants.DAYS_IN_WEEK));
1179
+ }
1180
+ isLastResBlockShort() {
1181
+ return this.lastResBlockCount > 0 && ((this.resolution === Resolution.Week && this.lastResBlockCount < DateTimeConstants.DAYS_IN_WEEK));
1182
+ }
1183
+ getScrollOverflowForResolutionBlock(positionLeftSnapshot, left, firstResBlockShort) {
1184
+ let overflow;
1185
+ if (firstResBlockShort && left <= this.getFirstResolutionElementWidth()) {
1186
+ overflow = this.getScrollOverflowForShortFirstResolutionBlock(positionLeftSnapshot);
1187
+ }
1188
+ else {
1189
+ overflow = this.getScrollOverflowForRegularResoultionBlock(positionLeftSnapshot, firstResBlockShort);
1190
+ }
1191
+ return overflow;
1192
+ }
1193
+ getScrollOverflowForRegularResoultionBlock(positionLeftSnapshot, firstResBlockShort) {
1194
+ let overflow;
1195
+ let firstBlockWidth = this.getFirstResolutionElementWidth();
1196
+ let positionLeft = (positionLeftSnapshot - (firstResBlockShort ? firstBlockWidth : 0));
1197
+ overflow = positionLeft % this.resBlockWidthPx;
1198
+ if (firstResBlockShort) {
1199
+ overflow += firstBlockWidth;
1200
+ this.firstWeekBlockHidden = true;
1201
+ }
1202
+ return overflow;
1203
+ }
1204
+ getScrollOverflowForShortFirstResolutionBlock(positionLeftSnapshot) {
1205
+ let overflow;
1206
+ // need to notice a short resolution block due to timeline's
1207
+ // start date which is in middle of a week.
1208
+ overflow = positionLeftSnapshot % this.getFirstResolutionElementWidth();
1209
+ if (overflow == 0.0) {
1210
+ overflow = this.getFirstResolutionElementWidth();
1211
+ }
1212
+ return overflow;
1213
+ }
1214
+ /**
1215
+ * Returns a width of the first resolution block.
1216
+ *
1217
+ * @return
1218
+ */
1219
+ getFirstResolutionElementWidth() {
1220
+ if (this.isFirstResBlockShort()) {
1221
+ if (this.isTimelineOverflowingHorizontally()) {
1222
+ return this.firstResBlockCount * this.minResolutionWidth;
1223
+ }
1224
+ else {
1225
+ return ElementUtil.getWidth(this.getFirstResolutionElement());
1226
+ }
1227
+ }
1228
+ else {
1229
+ if (this.isTimelineOverflowingHorizontally()) {
1230
+ return this.resBlockMinWidthPx;
1231
+ }
1232
+ else {
1233
+ return ElementUtil.getWidth(this.getFirstResolutionElement());
1234
+ }
1235
+ }
1236
+ }
1237
+ getFirstResolutionElement() {
1238
+ if (this.resolutionDiv.hasChildNodes()) {
1239
+ return this.resolutionDiv.firstElementChild;
1240
+ }
1241
+ return null;
1242
+ }
1243
+ getLastResolutionElement() {
1244
+ let div = this.resolutionDiv;
1245
+ if (!div) {
1246
+ return null;
1247
+ }
1248
+ let nodeList = div.childNodes;
1249
+ if (!nodeList) {
1250
+ return null;
1251
+ }
1252
+ let blockCount = nodeList.length;
1253
+ if (blockCount < 1) {
1254
+ return null;
1255
+ }
1256
+ if (this.containsResBlockSpacer()) {
1257
+ let index = blockCount - 2;
1258
+ if (blockCount > 1 && index >= 0) {
1259
+ return this.resolutionDiv.childNodes.item(index);
1260
+ }
1261
+ return null;
1262
+ }
1263
+ return this.resolutionDiv.lastChild;
1264
+ }
1265
+ containsResBlockSpacer() {
1266
+ return this.resSpacerDiv != null && this.resSpacerDiv.parentElement
1267
+ && this.resSpacerDiv.parentElement === this.resolutionDiv;
1268
+ }
1269
+ removeResolutionSpacerBlock() {
1270
+ if (this.containsResBlockSpacer()) {
1271
+ this.resSpacerDiv.parentNode.removeChild(this.resSpacerDiv);
1272
+ }
1273
+ }
1274
+ /*
1275
+ * Calculates either day or hour resolution block width depending on the
1276
+ * current resolution.
1277
+ */
1278
+ calculateDayOrHourResolutionBlockWidthPx(blockCount) {
1279
+ let dayOrHourWidthPx = Math.round(this.resolutionDiv.clientWidth / blockCount);
1280
+ while ((blockCount * dayOrHourWidthPx) < this.resolutionDiv.clientWidth) {
1281
+ dayOrHourWidthPx++;
1282
+ }
1283
+ return dayOrHourWidthPx;
1284
+ }
1285
+ /*
1286
+ * Calculates the actual width of one resolution block element. For example:
1287
+ * week resolution will return 7 * dayOrHourBlockWidthPx.
1288
+ */
1289
+ calculateActualResolutionBlockWidthPx(dayOrHourBlockWidthPx) {
1290
+ if (this.resolution === Resolution.Week) {
1291
+ return DateTimeConstants.DAYS_IN_WEEK * dayOrHourBlockWidthPx;
1292
+ }
1293
+ return dayOrHourBlockWidthPx;
1294
+ }
1295
+ /**
1296
+ * Adjust left position for optimal position to detect accurate date with
1297
+ * the current resolution.
1298
+ */
1299
+ adjustLeftPositionForDateDetection(left) {
1300
+ let datePos;
1301
+ if (this.resolution === Resolution.Week) {
1302
+ // detect date from the center of the first day block inside the
1303
+ // week block.
1304
+ datePos = left + this.dayOrHourWidthPx / 2;
1305
+ }
1306
+ else {
1307
+ // detect date from the center of the block (day/hour)
1308
+ datePos = left + this.resBlockWidthPx / 2;
1309
+ }
1310
+ return datePos;
1311
+ }
1312
+ createCalcCssValue(v, multiplier) {
1313
+ if (this.ie) {
1314
+ // see comments in createCalcCssValue(int, Integer)
1315
+ let percents = 100.0 / v * multiplier;
1316
+ return "calc(" + percents + "%)";
1317
+ }
1318
+ return null;
1319
+ }
1320
+ updateResolutionBlockWidths(pct) {
1321
+ if (this.setPositionForEachBlock) {
1322
+ if (!this.isTimelineOverflowingHorizontally()) {
1323
+ this.resolutionDiv.style.display = "flex";
1324
+ }
1325
+ else {
1326
+ this.resolutionDiv.style.removeProperty("display");
1327
+ }
1328
+ let firstResBlockIsShort = this.isFirstResBlockShort();
1329
+ let lastResBlockIsShort = this.isLastResBlockShort();
1330
+ // when setPositionForEachBlock is true, set width for each block explicitly.
1331
+ let count = this.resolutionDiv.childElementCount;
1332
+ if (this.containsResBlockSpacer()) {
1333
+ count--;
1334
+ }
1335
+ let lastIndex = count - 1;
1336
+ let i;
1337
+ let resBlock;
1338
+ for (i = 0; i < count; i++) {
1339
+ resBlock = this.resolutionDiv.childNodes.item(i);
1340
+ // first and last week blocks may be thinner than other
1341
+ // resolution blocks.
1342
+ if (firstResBlockIsShort && i == 0) {
1343
+ this.setWidth(resBlock, this.firstResBlockCount);
1344
+ }
1345
+ else if (lastResBlockIsShort && i == lastIndex) {
1346
+ this.setWidth(resBlock, this.lastResBlockCount);
1347
+ }
1348
+ else {
1349
+ this.setWidthPct(this.resBlockWidthPx, pct, resBlock);
1350
+ }
1351
+ }
1352
+ }
1353
+ else {
1354
+ // set widths by updating injected styles in one place. Faster than
1355
+ // setting widths explicitly for each element.
1356
+ let center = this.getWidthStyleValue(pct);
1357
+ let first = center;
1358
+ let last = center;
1359
+ if (this.isFirstResBlockShort()) {
1360
+ first = this.getWidth(this.firstResBlockCount);
1361
+ }
1362
+ if (this.isLastResBlockShort()) {
1363
+ last = this.getWidth(this.lastResBlockCount);
1364
+ }
1365
+ this.style.setProperty("--timeline-col-center-width", center);
1366
+ this.style.setProperty("--timeline-col-first-width", first);
1367
+ this.style.setProperty("--timeline-col-last-width", last);
1368
+ }
1369
+ }
1370
+ getWidth(multiplier) {
1371
+ if (this.isTimelineOverflowingHorizontally()) {
1372
+ return (multiplier * this.minResolutionWidth) + "px";
1373
+ }
1374
+ else {
1375
+ if (this.isAlwaysCalculatePixelWidths()) {
1376
+ return multiplier * this.dayOrHourWidthPx + "px";
1377
+ }
1378
+ else {
1379
+ return this.getCssPercentageWidth(this.blocksInRange, this.dayWidthPercentage, multiplier);
1380
+ }
1381
+ }
1382
+ }
1383
+ setWidth(element, multiplier) {
1384
+ if (this.isTimelineOverflowingHorizontally()) {
1385
+ element.style.width = (multiplier * this.minResolutionWidth) + "px";
1386
+ }
1387
+ else {
1388
+ if (this.isAlwaysCalculatePixelWidths()) {
1389
+ element.style.width = (multiplier * this.dayOrHourWidthPx) + "px";
1390
+ }
1391
+ else {
1392
+ this.setCssPercentageWidth(element, this.blocksInRange, this.dayWidthPercentage, multiplier);
1393
+ }
1394
+ }
1395
+ }
1396
+ setWidthPct(resBlockWidthPx, pct, element) {
1397
+ if (this.isTimelineOverflowingHorizontally()) {
1398
+ element.style.width = this.resBlockMinWidthPx + "px";
1399
+ }
1400
+ else {
1401
+ if (this.isAlwaysCalculatePixelWidths()) {
1402
+ element.style.width = resBlockWidthPx + "px";
1403
+ }
1404
+ else {
1405
+ if (this.ie) {
1406
+ element.style.flex = "1";
1407
+ }
1408
+ this.setCssPercentageWidthFor(element, this.resBlockWidthPercentage, pct);
1409
+ }
1410
+ }
1411
+ }
1412
+ setCssPercentageWidth(element, daysInRange, width, position) {
1413
+ let pct = this.createCalcCssValue(daysInRange, position);
1414
+ this.setCssPercentageWidthFor(element, position * width, pct);
1415
+ }
1416
+ getCssPercentageWidth(daysInRange, width, position) {
1417
+ let pct = this.createCalcCssValue(daysInRange, position);
1418
+ return this.getPercentageWidthString(position * width, pct);
1419
+ }
1420
+ setCssPercentageWidthFor(element, nValue, pct) {
1421
+ if (pct) {
1422
+ element.style.width = pct;
1423
+ }
1424
+ else {
1425
+ element.style.width = nValue + "%";
1426
+ }
1427
+ }
1428
+ getPercentageWidthString(nValue, pct) {
1429
+ if (pct) {
1430
+ return pct;
1431
+ }
1432
+ else {
1433
+ return nValue + "%";
1434
+ }
1435
+ }
1436
+ getWidthStyleValue(pct) {
1437
+ if (this.isTimelineOverflowingHorizontally()) {
1438
+ return this.resBlockMinWidthPx + "px";
1439
+ }
1440
+ else {
1441
+ if (this.isAlwaysCalculatePixelWidths()) {
1442
+ return this.resBlockWidthPx + "px";
1443
+ }
1444
+ else {
1445
+ return this.getPercentageWidthString(this.resBlockWidthPercentage, pct);
1446
+ }
1447
+ }
1448
+ }
1449
+ fillTimelineForHourResolution(startDate, endDate, left) {
1450
+ let timeline = this;
1451
+ this.firstDay = true;
1452
+ let hourCounter;
1453
+ let even;
1454
+ this.fillTimelineForHour(DateTimeConstants.HOUR_INTERVAL, startDate, endDate, {
1455
+ setup() {
1456
+ hourCounter = this.getFirstHourOfVisibleRange(startDate);
1457
+ even = this.isEven(startDate);
1458
+ },
1459
+ fillResolutionBlock(index, date, currentYear, lastTimelineBlock) {
1460
+ let childCount = timeline.resolutionDiv.childElementCount;
1461
+ if (timeline.isValidChildIndex(index, childCount)) {
1462
+ let resBlock = timeline.resolutionDiv.childNodes.item(index);
1463
+ timeline.fillHourResolutionBlock(resBlock, date, index, hourCounter, lastTimelineBlock, left, even);
1464
+ hourCounter = (hourCounter + 1) % 24;
1465
+ even = !even;
1466
+ }
1467
+ else {
1468
+ timeline.logIndexOutOfBounds("hour", index, childCount);
1469
+ return;
1470
+ }
1471
+ },
1472
+ isEven(startDate) {
1473
+ let normalDate = timeline.toNormalDate(startDate);
1474
+ if (timeline.normalStartDate.getTime() < normalDate.getTime()) {
1475
+ let hours = Math.floor(((normalDate.getTime() - timeline.normalStartDate.getTime()) / DateTimeConstants.HOUR_INTERVAL));
1476
+ return (hours % 2) == 1;
1477
+ }
1478
+ return false;
1479
+ },
1480
+ getFirstHourOfVisibleRange(startDate) {
1481
+ let normalDate = timeline.toNormalDate(startDate);
1482
+ if (timeline.normalStartDate.getTime() < normalDate.getTime()) {
1483
+ let hours = Math.floor(((normalDate.getTime() - timeline.normalStartDate.getTime()) / DateTimeConstants.HOUR_INTERVAL));
1484
+ return ((timeline.firstHourOfRange + hours) % 24);
1485
+ }
1486
+ return timeline.firstHourOfRange;
1487
+ }
1488
+ });
1489
+ }
1490
+ fillTimelineForDayResolution(startDate, endDate, left) {
1491
+ let timeline = this;
1492
+ let dayCounter;
1493
+ let even;
1494
+ let firstWeek = true;
1495
+ let weekIndex = 0;
1496
+ let weekday;
1497
+ this.fillTimelineForDayOrWeek(DateTimeConstants.DAY_INTERVAL, startDate, endDate, {
1498
+ setup: function () {
1499
+ dayCounter = this.getFirstDayOfVisibleRange(startDate);
1500
+ even = this.isEven(startDate, timeline.firstDayOfRange);
1501
+ },
1502
+ fillResolutionBlock: function (index, date, currentYear, lastTimelineBlock) {
1503
+ try {
1504
+ weekday = timeline.getWeekday(dayCounter);
1505
+ if (timeline.resolution === Resolution.Week) {
1506
+ this.fillWeekBlock(left, index, date, lastTimelineBlock);
1507
+ }
1508
+ else {
1509
+ this.fillDayBlock(left, index, date);
1510
+ }
1511
+ }
1512
+ finally {
1513
+ dayCounter = Math.max((dayCounter + 1) % 8, 1);
1514
+ }
1515
+ },
1516
+ fillDayBlock: function (left, index, date) {
1517
+ let childCount = timeline.resolutionDiv.childElementCount;
1518
+ if (timeline.isValidChildIndex(index, childCount)) {
1519
+ let resBlock = timeline.resolutionDiv.childNodes.item(index);
1520
+ timeline.fillDayResolutionBlock(resBlock, date, index, timeline.isWeekEnd(dayCounter), left);
1521
+ }
1522
+ else {
1523
+ timeline.logIndexOutOfBounds("day", index, childCount);
1524
+ return;
1525
+ }
1526
+ },
1527
+ fillWeekBlock: function (left, index, date, lastTimelineBlock) {
1528
+ let resBlock = null;
1529
+ if (index > 0 && weekday == Weekday.First) {
1530
+ weekIndex++;
1531
+ firstWeek = false;
1532
+ even = !even;
1533
+ }
1534
+ if (index == 0 || weekday == Weekday.First) {
1535
+ let childCount = timeline.resolutionDiv.childElementCount;
1536
+ if (timeline.isValidChildIndex(weekIndex, childCount)) {
1537
+ resBlock = timeline.resolutionDiv.childNodes.item(weekIndex);
1538
+ }
1539
+ else {
1540
+ timeline.logIndexOutOfBounds("week", weekIndex, childCount);
1541
+ return;
1542
+ }
1543
+ }
1544
+ timeline.fillWeekResolutionBlock(resBlock, date, weekIndex, weekday, firstWeek, lastTimelineBlock, left, even);
1545
+ },
1546
+ calcDaysLeftInFirstWeek: function (startDay) {
1547
+ let daysLeftInWeek = 0;
1548
+ if (startDay != timeline.firstDayOfWeek) {
1549
+ for (let i = startDay;; i++) {
1550
+ daysLeftInWeek++;
1551
+ if (Math.max(i % 8, 1) === timeline.lastDayOfWeek) {
1552
+ break;
1553
+ }
1554
+ }
1555
+ }
1556
+ return daysLeftInWeek;
1557
+ },
1558
+ isEven: function (startDate, startDay) {
1559
+ let visibleRangeNormalStartDate = timeline.toNormalDate(startDate);
1560
+ if (timeline.normalStartDate.getTime() < visibleRangeNormalStartDate.getTime()) {
1561
+ let daysHidden = Math.floor(((visibleRangeNormalStartDate.getTime() - timeline.normalStartDate.getTime()) / DateTimeConstants.DAY_INTERVAL));
1562
+ console.log("Days hidden: " + daysHidden);
1563
+ console.log("firstWeekBlockHidden = " + timeline.firstWeekBlockHidden);
1564
+ if (daysHidden === 0) {
1565
+ return false;
1566
+ }
1567
+ let daysLeftInFirstWeek = this.calcDaysLeftInFirstWeek(startDay);
1568
+ if (daysHidden > daysLeftInFirstWeek) {
1569
+ daysHidden -= daysLeftInFirstWeek;
1570
+ }
1571
+ let weeks = daysHidden / DateTimeConstants.DAYS_IN_WEEK;
1572
+ let even = (weeks % 2) === 1;
1573
+ return (timeline.firstWeekBlockHidden) ? !even : even;
1574
+ }
1575
+ return false;
1576
+ },
1577
+ getFirstDayOfVisibleRange: function (startDate) {
1578
+ let visibleRangeNormalStartDate = timeline.toNormalDate(startDate);
1579
+ if (timeline.normalStartDate.getTime() < visibleRangeNormalStartDate.getTime()) {
1580
+ let days = Math.floor(((visibleRangeNormalStartDate.getTime() - timeline.normalStartDate.getTime()) / DateTimeConstants.DAY_INTERVAL));
1581
+ return ((timeline.firstDayOfRange - 1 + days) % 7) + 1;
1582
+ }
1583
+ return timeline.firstDayOfRange;
1584
+ }
1585
+ });
1586
+ }
1587
+ logIndexOutOfBounds(indexName, index, childCount) {
1588
+ console.log("${indexName} index ${index} out of bounds with childCount ${childCount}. Can't fill content.");
1589
+ }
1590
+ fillTimelineForHour(interval, startDate, endDate, resBlockFiller) {
1591
+ let currentYear = null;
1592
+ let pos = startDate;
1593
+ let end = endDate;
1594
+ let index = 0;
1595
+ let lastTimelineBlock = false;
1596
+ let date;
1597
+ resBlockFiller.setup();
1598
+ while (pos <= end) {
1599
+ date = pos;
1600
+ let nextHour = new Date(pos.getTime() + interval);
1601
+ lastTimelineBlock = nextHour.getTime() > end.getTime();
1602
+ resBlockFiller.fillResolutionBlock(index, date, currentYear, lastTimelineBlock);
1603
+ pos = nextHour;
1604
+ index++;
1605
+ }
1606
+ }
1607
+ fillTimelineForDayOrWeek(interval, startDate, endDate, resBlockFiller) {
1608
+ let currentYear = null;
1609
+ let pos = startDate;
1610
+ pos = DateUtil.adjustToMiddleOfDay(pos, this.localeDataProvider.getTimeZone());
1611
+ let end = endDate;
1612
+ let index = 0;
1613
+ let lastTimelineBlock = false;
1614
+ let date;
1615
+ let isDST = false;
1616
+ let previousIsDST = this.localeDataProvider.isDaylightTime(startDate);
1617
+ resBlockFiller.setup();
1618
+ while (!lastTimelineBlock) {
1619
+ let dstAdjusted = this.getDSTAdjustedDate(previousIsDST, pos);
1620
+ date = dstAdjusted;
1621
+ pos = dstAdjusted;
1622
+ isDST = this.localeDataProvider.isDaylightTime(date);
1623
+ lastTimelineBlock = this.getDSTAdjustedDate(isDST, new Date(date.getTime() + interval)).getTime() > end.getTime();
1624
+ resBlockFiller.fillResolutionBlock(index, date, currentYear, lastTimelineBlock);
1625
+ previousIsDST = isDST;
1626
+ pos = new Date(pos.getTime() + interval);
1627
+ index++;
1628
+ }
1629
+ }
1630
+ isValidChildIndex(index, childCount) {
1631
+ return (index >= 0) && (index < childCount);
1632
+ }
1633
+ fillDayResolutionBlock(resBlock, date, index, weekend, left) {
1634
+ resBlock.innerText = this.localeDataProvider.formatDate(date, "d");
1635
+ if (weekend) {
1636
+ resBlock.classList.add(TimelineElement_1.STYLE_WEEKEND);
1637
+ }
1638
+ else {
1639
+ resBlock.classList.remove(TimelineElement_1.STYLE_WEEKEND);
1640
+ }
1641
+ this.setCurrentStyle(resBlock, this.isCurrentDay(date));
1642
+ if (this.setPositionForEachBlock && this.isTimelineOverflowingHorizontally()) {
1643
+ resBlock.style.position = "relative";
1644
+ resBlock.style.left = left + "px";
1645
+ }
1646
+ }
1647
+ fillWeekResolutionBlock(resBlock, date, index, weekDay, firstWeek, lastBlock, left, even) {
1648
+ if (resBlock != null) {
1649
+ resBlock.innerText = this.formatWeekCaption(date);
1650
+ if (even) {
1651
+ resBlock.classList.add(TimelineElement_1.STYLE_EVEN);
1652
+ }
1653
+ else {
1654
+ resBlock.classList.remove(TimelineElement_1.STYLE_EVEN);
1655
+ }
1656
+ if (this.setPositionForEachBlock && this.isTimelineOverflowingHorizontally()) {
1657
+ resBlock.style.position = "relative";
1658
+ resBlock.style.left = left + "px";
1659
+ }
1660
+ resBlock.classList.remove(TimelineElement_1.STYLE_FIRST, TimelineElement_1.STYLE_LAST);
1661
+ // block is (re)filled starting from its first visible day; clear old state.
1662
+ this.setCurrentStyle(resBlock, false);
1663
+ }
1664
+ if (this.isCurrentDay(date) && this.isValidChildIndex(index, this.resolutionDiv.childElementCount)) {
1665
+ this.setCurrentStyle(this.resolutionDiv.childNodes.item(index), true);
1666
+ }
1667
+ if (firstWeek && (weekDay === Weekday.Last || lastBlock)) {
1668
+ let firstEl = this.resolutionDiv.firstElementChild;
1669
+ if (!firstEl.classList.contains(TimelineElement_1.STYLE_FIRST)) {
1670
+ firstEl.classList.add(TimelineElement_1.STYLE_FIRST);
1671
+ }
1672
+ }
1673
+ else if (lastBlock) {
1674
+ let lastEl = this.resolutionDiv.lastChild;
1675
+ if (!lastEl.classList.contains(TimelineElement_1.STYLE_LAST)) {
1676
+ lastEl.classList.add(TimelineElement_1.STYLE_LAST);
1677
+ }
1678
+ }
1679
+ }
1680
+ fillHourResolutionBlock(resBlock, date, index, hourCounter, lastBlock, left, even) {
1681
+ if (this.localeDataProvider.isTwelveHourClock()) {
1682
+ resBlock.innerText = this.localeDataProvider.formatTime(date, "h");
1683
+ }
1684
+ else {
1685
+ resBlock.innerText = this.localeDataProvider.formatTime(date, "HH");
1686
+ }
1687
+ if (even) {
1688
+ resBlock.classList.add(TimelineElement_1.STYLE_EVEN);
1689
+ }
1690
+ else {
1691
+ resBlock.classList.remove(TimelineElement_1.STYLE_EVEN);
1692
+ }
1693
+ this.setCurrentStyle(resBlock, this.isCurrentHour(date));
1694
+ if (this.firstDay && (hourCounter == 24 || lastBlock)) {
1695
+ this.firstDay = false;
1696
+ this.firstResBlockCount = index + 1;
1697
+ }
1698
+ else if (lastBlock) {
1699
+ this.lastResBlockCount = (index + 1 - this.firstResBlockCount) % 24;
1700
+ }
1701
+ if (this.setPositionForEachBlock && this.isTimelineOverflowingHorizontally()) {
1702
+ resBlock.style.position = "relative";
1703
+ resBlock.style.left = left + "px";
1704
+ }
1705
+ }
1706
+ };
1707
+ TimelineElement.STYLE_ROW = "row";
1708
+ TimelineElement.STYLE_COL = "col";
1709
+ TimelineElement.STYLE_MONTH = "month";
1710
+ TimelineElement.STYLE_YEAR = "year";
1711
+ TimelineElement.STYLE_DAY = "day";
1712
+ TimelineElement.STYLE_WEEK = "w";
1713
+ TimelineElement.STYLE_RESOLUTION = "resolution";
1714
+ TimelineElement.STYLE_EVEN = "even";
1715
+ TimelineElement.STYLE_WEEKEND = "weekend";
1716
+ TimelineElement.STYLE_SPACER = "spacer";
1717
+ TimelineElement.STYLE_FIRST = "f-col";
1718
+ TimelineElement.STYLE_CENTER = "c-col";
1719
+ TimelineElement.STYLE_LAST = "l-col";
1720
+ TimelineElement.STYLE_MEASURE = "measure";
1721
+ TimelineElement.STYLE_CURRENT = "current";
1722
+ TimelineElement.CURRENT_DAY_FORMAT = "yyyy-MM-dd";
1723
+ // Offset is included to tell apart the repeated hour when daylight saving time ends.
1724
+ TimelineElement.CURRENT_HOUR_FORMAT = "yyyy-MM-dd HH xxx";
1725
+ __decorate([
1726
+ property({
1727
+ reflect: true,
1728
+ converter: {
1729
+ fromAttribute: (value, type) => {
1730
+ return Resolution[value];
1731
+ },
1732
+ toAttribute: (value, type) => {
1733
+ return Resolution[value];
1734
+ }
1735
+ }
1736
+ })
1737
+ ], TimelineElement.prototype, "resolution", void 0);
1738
+ __decorate([
1739
+ property({
1740
+ reflect: true,
1741
+ converter: {
1742
+ fromAttribute: (value, type) => {
1743
+ return (value) ? (value.length > 13) ? value.substring(0, 13) : value : value;
1744
+ },
1745
+ }
1746
+ })
1747
+ ], TimelineElement.prototype, "startDateTime", void 0);
1748
+ __decorate([
1749
+ property({
1750
+ reflect: true,
1751
+ converter: {
1752
+ fromAttribute: (value, type) => {
1753
+ return (value) ? (value.length > 13) ? value.substring(0, 13) : value : value;
1754
+ },
1755
+ }
1756
+ })
1757
+ ], TimelineElement.prototype, "endDateTime", void 0);
1758
+ __decorate([
1759
+ property({ reflect: true })
1760
+ ], TimelineElement.prototype, "timeZone", void 0);
1761
+ __decorate([
1762
+ property({ reflect: true })
1763
+ ], TimelineElement.prototype, "locale", void 0);
1764
+ __decorate([
1765
+ property({ reflect: true })
1766
+ ], TimelineElement.prototype, "firstDayOfWeek", void 0);
1767
+ __decorate([
1768
+ property({ reflect: true, type: Boolean })
1769
+ ], TimelineElement.prototype, "twelveHourClock", void 0);
1770
+ __decorate([
1771
+ property()
1772
+ ], TimelineElement.prototype, "minWidth", void 0);
1773
+ __decorate([
1774
+ property()
1775
+ ], TimelineElement.prototype, "normalStartDate", void 0);
1776
+ __decorate([
1777
+ property()
1778
+ ], TimelineElement.prototype, "normalEndDate", void 0);
1779
+ __decorate([
1780
+ property()
1781
+ ], TimelineElement.prototype, "lastDayOfWeek", void 0);
1782
+ __decorate([
1783
+ property()
1784
+ ], TimelineElement.prototype, "firstDayOfRange", void 0);
1785
+ __decorate([
1786
+ property()
1787
+ ], TimelineElement.prototype, "firstHourOfRange", void 0);
1788
+ __decorate([
1789
+ property({ reflect: true })
1790
+ ], TimelineElement.prototype, "scrollContainerId", void 0);
1791
+ __decorate([
1792
+ property()
1793
+ ], TimelineElement.prototype, "monthRowVisible", void 0);
1794
+ __decorate([
1795
+ property()
1796
+ ], TimelineElement.prototype, "yearRowVisible", void 0);
1797
+ __decorate([
1798
+ property()
1799
+ ], TimelineElement.prototype, "monthNames", void 0);
1800
+ __decorate([
1801
+ property()
1802
+ ], TimelineElement.prototype, "weekdayNames", void 0);
1803
+ __decorate([
1804
+ property({ reflect: true, type: Boolean })
1805
+ ], TimelineElement.prototype, "currentDateVisible", void 0);
1806
+ __decorate([
1807
+ query('#resolutionDiv')
1808
+ ], TimelineElement.prototype, "resolutionDiv", void 0);
1809
+ TimelineElement = TimelineElement_1 = __decorate([
1810
+ customElement('timeline-element')
1811
+ ], TimelineElement);
1737
1812
  //# sourceMappingURL=timeline-element.js.map