tltv-timeline-element 1.0.8 → 1.0.12

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