tltv-timeline-element 1.0.22 → 1.0.24

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/README.md CHANGED
@@ -3,4 +3,38 @@ Timeline LitElement web component
3
3
  Migrated from GWT Timeline widget for Gantt component (Java/Vaadin Framework 8).
4
4
 
5
5
  Guide to how to use LitElements:
6
- https://lit-element.polymer-project.org/guide/use
6
+ https://lit-element.polymer-project.org/guide/use
7
+
8
+ ## Resolutions
9
+
10
+ The `resolution` attribute accepts `Hour`, `Day`, `Week`, `Month` and `Year`.
11
+
12
+ - `Hour` uses `startdatetime`/`enddatetime` with hour accuracy (e.g. `2020-04-01T08`).
13
+ Other resolutions use day accuracy (e.g. `2020-04-01`).
14
+ - `Month` and `Year` resolution blocks have variable widths based on the number
15
+ of days in each month or year. The first and last block may be partial when
16
+ the range doesn't start or end on a month (year) boundary.
17
+ - With `Month` resolution the month header row is not shown, and with `Year`
18
+ resolution the year header row is not shown, as the resolution row already
19
+ shows the same information.
20
+ - Minimum block widths are measured from the `min-width` of the
21
+ `.col.w.measure` (one week), `.col.m.measure` (a 30 day month) and
22
+ `.col.y.measure` (a 365 day year) rules in the element's styles. When no
23
+ `min-width` is set, the defaults are 4px per day for week and month, and
24
+ 1px per day for year.
25
+
26
+ ## Styling
27
+
28
+ The timeline styles live in the element's shadow DOM. Colors and sizes can be
29
+ customized with the following CSS custom properties (defaults in parentheses):
30
+
31
+ | Property | Description |
32
+ | --- | --- |
33
+ | `--timeline-row-background` (`#d0d0d0`) | Background of header rows (year, month, day). |
34
+ | `--timeline-row-even-background` (`#ddd`) | Background of every even month and day block in the header. |
35
+ | `--timeline-row-height` (`15px`) | Height of a header row. |
36
+ | `--timeline-row-font-size` (`10px`) | Font size of a header row. |
37
+ | `--timeline-col-background-color` (`#ddd`) | Background of resolution blocks. |
38
+ | `--timeline-col-even-background-color` (`#ccc`) | Background of even resolution blocks. |
39
+ | `--timeline-col-weekend` (`#ccc`) | Background of weekend resolution blocks. |
40
+ | `--timeline-col-font-size` (`10px`) | Font size of resolution blocks. |
@@ -1,5 +1,7 @@
1
1
  export declare enum Resolution {
2
2
  Hour = 1,
3
3
  Day = 2,
4
- Week = 3
4
+ Week = 3,
5
+ Month = 4,
6
+ Year = 5
5
7
  }
@@ -3,5 +3,7 @@ export var Resolution;
3
3
  Resolution[Resolution["Hour"] = 1] = "Hour";
4
4
  Resolution[Resolution["Day"] = 2] = "Day";
5
5
  Resolution[Resolution["Week"] = 3] = "Week";
6
+ Resolution[Resolution["Month"] = 4] = "Month";
7
+ Resolution[Resolution["Year"] = 5] = "Year";
6
8
  })(Resolution || (Resolution = {}));
7
9
  //# sourceMappingURL=Resolution.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"Resolution.js","sourceRoot":"","sources":["../../../src/model/Resolution.ts"],"names":[],"mappings":"AAAA,MAAM,CAAN,IAAY,UAIX;AAJD,WAAY,UAAU;IAClB,2CAAQ,CAAA;IACR,yCAAO,CAAA;IACP,2CAAQ,CAAA;AACZ,CAAC,EAJW,UAAU,KAAV,UAAU,QAIrB"}
1
+ {"version":3,"file":"Resolution.js","sourceRoot":"","sources":["../../../src/model/Resolution.ts"],"names":[],"mappings":"AAAA,MAAM,CAAN,IAAY,UAMX;AAND,WAAY,UAAU;IAClB,2CAAQ,CAAA;IACR,yCAAO,CAAA;IACP,2CAAQ,CAAA;IACR,6CAAS,CAAA;IACT,2CAAQ,CAAA;AACZ,CAAC,EANW,UAAU,KAAV,UAAU,QAMrB"}
@@ -36,6 +36,8 @@ export declare class TimelineElement extends LitElement {
36
36
  private static readonly STYLE_YEAR;
37
37
  private static readonly STYLE_DAY;
38
38
  private static readonly STYLE_WEEK;
39
+ private static readonly STYLE_MONTH_RES;
40
+ private static readonly STYLE_YEAR_RES;
39
41
  private static readonly STYLE_RESOLUTION;
40
42
  private static readonly STYLE_EVEN;
41
43
  private static readonly STYLE_WEEKEND;
@@ -48,6 +50,10 @@ export declare class TimelineElement extends LitElement {
48
50
  private static readonly CURRENT_DAY_FORMAT;
49
51
  private static readonly CURRENT_HOUR_FORMAT;
50
52
  private readonly resolutionWeekDayblockWidth;
53
+ private readonly resolutionMonthDayblockWidth;
54
+ private readonly resolutionYearDayblockWidth;
55
+ private static readonly AVERAGE_DAYS_IN_MONTH;
56
+ private static readonly AVERAGE_DAYS_IN_YEAR;
51
57
  resolution: Resolution;
52
58
  startDateTime: string;
53
59
  endDateTime: string;
@@ -79,6 +85,9 @@ export declare class TimelineElement extends LitElement {
79
85
  private resolutionBlockCount;
80
86
  private firstResBlockCount;
81
87
  private lastResBlockCount;
88
+ private resBlockDayCounts;
89
+ private resBlockStartDates;
90
+ private resBlockKeys;
82
91
  private firstDay;
83
92
  private timelineOverflowingHorizontally;
84
93
  private monthFormat;
@@ -148,6 +157,11 @@ export declare class TimelineElement extends LitElement {
148
157
  registerHourResolutionBlock(): void;
149
158
  registerDayResolutionBlock(): void;
150
159
  registerWeekResolutionBlock(index: number, weekDay: Weekday, lastBlock: boolean, firstWeek: boolean): void;
160
+ registerMonthOrYearResolutionBlock(index: number, date: Date): void;
161
+ getMonthOrYearResolutionBlockKey(date: Date): string;
162
+ isMonthOrYearResolution(): boolean;
163
+ isYearRowVisible(): boolean;
164
+ isMonthRowVisible(): boolean;
151
165
  timelineBlocks(rowData: BlockRowData, style: string): import("lit-html").TemplateResult<1>[];
152
166
  /**
153
167
  * Returns true if Widget is set to calculate widths by itself. Default is
@@ -310,6 +324,8 @@ export declare class TimelineElement extends LitElement {
310
324
  createHourResolutionBlock(): HTMLDivElement;
311
325
  createDayResolutionBlock(): HTMLDivElement;
312
326
  createWeekResolutionBlock(): HTMLDivElement;
327
+ createMonthResolutionBlock(): HTMLDivElement;
328
+ createYearResolutionBlock(): HTMLDivElement;
313
329
  fillVisibleTimeline(): void;
314
330
  showResolutionBlocksOnView(): void;
315
331
  showAllResolutionBlocks(): void;
@@ -349,6 +365,7 @@ export declare class TimelineElement extends LitElement {
349
365
  adjustLeftPositionForDateDetection(left: number): number;
350
366
  createCalcCssValue(v: number, multiplier: number): string;
351
367
  updateResolutionBlockWidths(pct: string): void;
368
+ updateMonthOrYearResolutionBlockWidths(): void;
352
369
  getWidth(multiplier: number): string;
353
370
  setWidth(element: HTMLElement, multiplier: number): void;
354
371
  setWidthPct(resBlockWidthPx: number, pct: string, element: HTMLElement): void;
@@ -357,6 +374,8 @@ export declare class TimelineElement extends LitElement {
357
374
  setCssPercentageWidthFor(element: HTMLElement, nValue: number, pct: string): void;
358
375
  getPercentageWidthString(nValue: number, pct: string): string;
359
376
  getWidthStyleValue(pct: string): string;
377
+ fillTimelineForMonthOrYearResolution(): void;
378
+ fillMonthOrYearResolutionBlock(resBlock: HTMLElement, date: Date, even: boolean, current: boolean): void;
360
379
  fillTimelineForHourResolution(startDate: Date, endDate: Date, left: number): void;
361
380
  fillTimelineForDayResolution(startDate: Date, endDate: Date, left: number): void;
362
381
  logIndexOutOfBounds(indexName: string, index: number, childCount: number): void;
@@ -45,6 +45,10 @@ export let TimelineElement = TimelineElement_1 = class TimelineElement extends L
45
45
  constructor() {
46
46
  super(...arguments);
47
47
  this.resolutionWeekDayblockWidth = 4;
48
+ /* Default minimum width (px) of one day inside a month resolution block. */
49
+ this.resolutionMonthDayblockWidth = 4;
50
+ /* Default minimum width (px) of one day inside a year resolution block. */
51
+ this.resolutionYearDayblockWidth = 1;
48
52
  this.resolution = Resolution.Day;
49
53
  /** Timezone for date and time formatting. Doesn't match with actual start and end Date object's time zone. */
50
54
  this.timeZone = "Europe/London";
@@ -59,17 +63,27 @@ export let TimelineElement = TimelineElement_1 = class TimelineElement extends L
59
63
  this.currentDayString = null;
60
64
  this.currentHourString = null;
61
65
  /*
62
- * number of blocks in resolution range. Days for Day/Week resolution, Hours
63
- * for hour resolution..
66
+ * number of blocks in resolution range. Days for Day/Week/Month/Year
67
+ * resolution, Hours for hour resolution..
64
68
  */
65
69
  this.blocksInRange = 0;
66
70
  /*
67
71
  * number of elements in resolution range. Same as blocksInRange for
68
- * Day/Hour resolution. blocksInRange / 7 for Week resolution.
72
+ * Day/Hour resolution. blocksInRange / 7 for Week resolution. Number of
73
+ * (partial) months/years for Month/Year resolution.
69
74
  */
70
75
  this.resolutionBlockCount = 0;
71
76
  this.firstResBlockCount = 0;
72
77
  this.lastResBlockCount = 0;
78
+ /*
79
+ * Month/Year resolution only: number of days in each resolution block, the
80
+ * date of the first day in each block and a key ('yyyy-MM' or 'yyyy')
81
+ * identifying the block. Blocks have variable length (28-31 or 365-366 days,
82
+ * first and last block may be partial).
83
+ */
84
+ this.resBlockDayCounts = [];
85
+ this.resBlockStartDates = [];
86
+ this.resBlockKeys = [];
73
87
  this.spacerBlocks = [];
74
88
  this.yearRowData = new BlockRowData();
75
89
  this.monthRowData = new BlockRowData();
@@ -147,10 +161,10 @@ export let TimelineElement = TimelineElement_1 = class TimelineElement extends L
147
161
 
148
162
  .month:nth-of-type(even),
149
163
  .day:nth-of-type(even) {
150
- background-color: #ddd;
164
+ background-color: var(--timeline-row-even-background, #ddd);
151
165
  }
152
166
  .col.even {
153
- background-color: #ccc;
167
+ background-color: var(--timeline-col-even-background-color, #ccc);
154
168
  }
155
169
 
156
170
  .col {
@@ -182,7 +196,9 @@ export let TimelineElement = TimelineElement_1 = class TimelineElement extends L
182
196
  width: var(--timeline-col-last-width);
183
197
  }
184
198
 
185
- .col.w {
199
+ .col.w,
200
+ .col.m,
201
+ .col.y {
186
202
  text-align: left;
187
203
  }
188
204
 
@@ -203,6 +219,14 @@ export let TimelineElement = TimelineElement_1 = class TimelineElement extends L
203
219
  // Change min-width to adjust grid's cell width with week-resolution.
204
220
  //min-width: 70px;
205
221
  }
222
+ .col.m.measure {
223
+ // Change min-width to adjust grid's cell width with month-resolution (width of a 30 day month).
224
+ //min-width: 120px;
225
+ }
226
+ .col.y.measure {
227
+ // Change min-width to adjust grid's cell width with year-resolution (width of a 365 day year).
228
+ //min-width: 365px;
229
+ }
206
230
 
207
231
  .row {
208
232
  width: 100%;
@@ -225,13 +249,13 @@ export let TimelineElement = TimelineElement_1 = class TimelineElement extends L
225
249
  <div id="resolutionDiv" class="row resolution"></div>`;
226
250
  }
227
251
  yearBlocks() {
228
- if (this.yearRowVisible) {
252
+ if (this.isYearRowVisible()) {
229
253
  return this.timelineBlocks(this.yearRowData, TimelineElement_1.STYLE_YEAR);
230
254
  }
231
255
  return nothing;
232
256
  }
233
257
  monthBlocks() {
234
- if (this.monthRowVisible) {
258
+ if (this.isMonthRowVisible()) {
235
259
  return this.timelineBlocks(this.monthRowData, TimelineElement_1.STYLE_MONTH);
236
260
  }
237
261
  return nothing;
@@ -285,7 +309,8 @@ export let TimelineElement = TimelineElement_1 = class TimelineElement extends L
285
309
  if (!(this.resolution) || !this.internalInclusiveStartDateTime || !this.internalInclusiveEndDateTime) {
286
310
  return;
287
311
  }
288
- if (this.resolution !== Resolution.Day && this.resolution !== Resolution.Week && this.resolution !== Resolution.Hour) {
312
+ if (this.resolution !== Resolution.Day && this.resolution !== Resolution.Week && this.resolution !== Resolution.Hour
313
+ && !this.isMonthOrYearResolution()) {
289
314
  console.log("TimelineElement resolution " + (this.resolution ? Resolution[this.resolution] : "null")
290
315
  + " is not supported");
291
316
  return;
@@ -336,7 +361,7 @@ export let TimelineElement = TimelineElement_1 = class TimelineElement extends L
336
361
  if (this.minResolutionWidth < 0) {
337
362
  this.minResolutionWidth = this.calculateResolutionMinWidth();
338
363
  }
339
- if (this.resolution === Resolution.Day || this.resolution === Resolution.Week) {
364
+ if (this.resolution === Resolution.Day || this.resolution === Resolution.Week || this.isMonthOrYearResolution()) {
340
365
  this.prepareTimelineForDayOrWeekResolution(this.internalInclusiveStartDateTime, this.internalInclusiveEndDateTime);
341
366
  }
342
367
  else if (this.resolution === Resolution.Hour) {
@@ -409,6 +434,14 @@ export let TimelineElement = TimelineElement_1 = class TimelineElement extends L
409
434
  // configurable with '.col.w.measure' selector
410
435
  resBlockMeasure.classList.add(TimelineElement_1.STYLE_COL, TimelineElement_1.STYLE_WEEK, TimelineElement_1.STYLE_MEASURE);
411
436
  }
437
+ else if (this.resolution === Resolution.Month) {
438
+ // configurable with '.col.m.measure' selector
439
+ resBlockMeasure.classList.add(TimelineElement_1.STYLE_COL, TimelineElement_1.STYLE_MONTH_RES, TimelineElement_1.STYLE_MEASURE);
440
+ }
441
+ else if (this.resolution === Resolution.Year) {
442
+ // configurable with '.col.y.measure' selector
443
+ resBlockMeasure.classList.add(TimelineElement_1.STYLE_COL, TimelineElement_1.STYLE_YEAR_RES, TimelineElement_1.STYLE_MEASURE);
444
+ }
412
445
  else {
413
446
  // measure for text 'MM'
414
447
  resBlockMeasure.innerText = "MM";
@@ -422,7 +455,18 @@ export let TimelineElement = TimelineElement_1 = class TimelineElement extends L
422
455
  // divide given width by number of days in week
423
456
  width = width / DateTimeConstants.DAYS_IN_WEEK;
424
457
  }
425
- width = (width < this.resolutionWeekDayblockWidth) ? this.resolutionWeekDayblockWidth : width;
458
+ let minDayWidth = this.resolutionWeekDayblockWidth;
459
+ if (this.resolution === Resolution.Month) {
460
+ // divide given width by average number of days in month
461
+ width = width / TimelineElement_1.AVERAGE_DAYS_IN_MONTH;
462
+ minDayWidth = this.resolutionMonthDayblockWidth;
463
+ }
464
+ else if (this.resolution === Resolution.Year) {
465
+ // divide given width by number of days in year
466
+ width = width / TimelineElement_1.AVERAGE_DAYS_IN_YEAR;
467
+ minDayWidth = this.resolutionYearDayblockWidth;
468
+ }
469
+ width = (width < minDayWidth) ? minDayWidth : width;
426
470
  this.shadowRoot.removeChild(resDivMeasure);
427
471
  return width;
428
472
  }
@@ -446,6 +490,42 @@ export let TimelineElement = TimelineElement_1 = class TimelineElement extends L
446
490
  }
447
491
  this.blocksInRange++;
448
492
  }
493
+ /*
494
+ * Registers one day for Month or Year resolution. A new resolution block is
495
+ * started whenever the month (or year) of the given date changes.
496
+ */
497
+ registerMonthOrYearResolutionBlock(index, date) {
498
+ let key = this.getMonthOrYearResolutionBlockKey(date);
499
+ let lastIndex = this.resBlockKeys.length - 1;
500
+ if (index == 0 || lastIndex < 0 || this.resBlockKeys[lastIndex] !== key) {
501
+ this.resolutionBlockCount++;
502
+ this.resBlockKeys.push(key);
503
+ this.resBlockStartDates.push(date);
504
+ this.resBlockDayCounts.push(1);
505
+ }
506
+ else {
507
+ this.resBlockDayCounts[lastIndex]++;
508
+ }
509
+ this.firstResBlockCount = this.resBlockDayCounts[0];
510
+ this.lastResBlockCount = this.resBlockDayCounts[this.resBlockDayCounts.length - 1];
511
+ this.blocksInRange++;
512
+ }
513
+ /* Returns 'yyyy-MM' key for Month resolution and 'yyyy' key for Year resolution. */
514
+ getMonthOrYearResolutionBlockKey(date) {
515
+ return this.localeDataProvider.formatDate(date, this.resolution === Resolution.Year ? "yyyy" : "yyyy-MM");
516
+ }
517
+ isMonthOrYearResolution() {
518
+ return this.resolution === Resolution.Month || this.resolution === Resolution.Year;
519
+ }
520
+ /* Year row is hidden with Year resolution as the resolution row shows years already. */
521
+ isYearRowVisible() {
522
+ return this.yearRowVisible && this.resolution !== Resolution.Year;
523
+ }
524
+ /* Month row is hidden with Month and Year resolutions: Month resolution row shows months already,
525
+ * and Year resolution shows a single year row. */
526
+ isMonthRowVisible() {
527
+ return this.monthRowVisible && !this.isMonthOrYearResolution();
528
+ }
449
529
  timelineBlocks(rowData, style) {
450
530
  const itemTemplates = [];
451
531
  for (let entry of rowData.getBlockEntries()) {
@@ -638,10 +718,16 @@ export let TimelineElement = TimelineElement_1 = class TimelineElement extends L
638
718
  let dayCounter = this.firstDayOfRange;
639
719
  let weekday;
640
720
  let firstWeek = true;
721
+ this.resBlockDayCounts = [];
722
+ this.resBlockStartDates = [];
723
+ this.resBlockKeys = [];
641
724
  this.prepareTimelineForDayOrWeek(DateTimeConstants.DAY_INTERVAL, startDate, endDate, {
642
725
  registerResolutionBlock: function (index, date, currentYear, lastTimelineBlock) {
643
726
  weekday = timeline.getWeekday(dayCounter);
644
- if (timeline.resolution === Resolution.Week) {
727
+ if (timeline.isMonthOrYearResolution()) {
728
+ timeline.registerMonthOrYearResolutionBlock(index, date);
729
+ }
730
+ else if (timeline.resolution === Resolution.Week) {
645
731
  timeline.registerWeekResolutionBlock(index, weekday, lastTimelineBlock, firstWeek);
646
732
  if (firstWeek && (weekday === Weekday.Last || lastTimelineBlock)) {
647
733
  firstWeek = false;
@@ -676,10 +762,10 @@ export let TimelineElement = TimelineElement_1 = class TimelineElement extends L
676
762
  let d = new Date(date.getTime() + interval);
677
763
  lastTimelineBlock = DateUtil.getDSTAdjustedDate(isDST, d, this.localeDataProvider.getDaylightAdjustment(d)).getTime() > end.getTime();
678
764
  resBlockRegisterer.registerResolutionBlock(index, date, currentYear, lastTimelineBlock);
679
- if (this.yearRowVisible) {
765
+ if (this.isYearRowVisible()) {
680
766
  currentYear = this.addYearBlock(currentYear, date);
681
767
  }
682
- if (this.monthRowVisible) {
768
+ if (this.isMonthRowVisible()) {
683
769
  currentMonth = this.addMonthBlock(currentMonth, date);
684
770
  }
685
771
  if (this.isDayRowVisible()) {
@@ -938,13 +1024,23 @@ export let TimelineElement = TimelineElement_1 = class TimelineElement extends L
938
1024
  this.resBlockWidthPercentage = this.dayWidthPercentage * DateTimeConstants.DAYS_IN_WEEK;
939
1025
  pct = this.createCalcCssValue(this.blocksInRange, DateTimeConstants.DAYS_IN_WEEK);
940
1026
  }
1027
+ else if (this.isMonthOrYearResolution()) {
1028
+ // Month and year blocks have variable widths; these values represent an average block.
1029
+ this.resBlockMinWidthPx = this.calculateMinimumResolutionBlockWidth();
1030
+ this.resBlockWidthPercentage = 100.0 / this.resolutionBlockCount;
1031
+ }
941
1032
  // update resolution block widths
942
- this.updateResolutionBlockWidths(pct);
943
- if (this.yearRowVisible) {
1033
+ if (this.isMonthOrYearResolution()) {
1034
+ this.updateMonthOrYearResolutionBlockWidths();
1035
+ }
1036
+ else {
1037
+ this.updateResolutionBlockWidths(pct);
1038
+ }
1039
+ if (this.isYearRowVisible()) {
944
1040
  // update year block widths
945
1041
  this.updateBlockWidths(this.yearRowData);
946
1042
  }
947
- if (this.monthRowVisible) {
1043
+ if (this.isMonthRowVisible()) {
948
1044
  // update month block widths
949
1045
  this.updateBlockWidths(this.monthRowData);
950
1046
  }
@@ -1020,7 +1116,9 @@ export let TimelineElement = TimelineElement_1 = class TimelineElement extends L
1020
1116
  // on scroll.
1021
1117
  // first: detect how many blocks we can fit in the screen
1022
1118
  let blocks = this.resolutionBlockCount;
1023
- if (this.isTimelineOverflowingHorizontally()) {
1119
+ // Month and Year resolutions have variable width blocks and only a few of
1120
+ // them even for long ranges, so all of them are created.
1121
+ if (this.isTimelineOverflowingHorizontally() && !this.isMonthOrYearResolution()) {
1024
1122
  blocks = Math.floor((ElementUtil.getWidth(this.getParentElement(this))
1025
1123
  / this.calculateMinimumResolutionBlockWidth()));
1026
1124
  if (this.resolutionBlockCount < blocks) {
@@ -1043,6 +1141,12 @@ export let TimelineElement = TimelineElement_1 = class TimelineElement extends L
1043
1141
  case Resolution.Week:
1044
1142
  element = this.createWeekResolutionBlock();
1045
1143
  break;
1144
+ case Resolution.Month:
1145
+ element = this.createMonthResolutionBlock();
1146
+ break;
1147
+ case Resolution.Year:
1148
+ element = this.createYearResolutionBlock();
1149
+ break;
1046
1150
  }
1047
1151
  this.resolutionDiv.appendChild(element);
1048
1152
  }
@@ -1052,6 +1156,12 @@ export let TimelineElement = TimelineElement_1 = class TimelineElement extends L
1052
1156
  if (this.resolution === Resolution.Week) {
1053
1157
  return DateTimeConstants.DAYS_IN_WEEK * this.minResolutionWidth;
1054
1158
  }
1159
+ else if (this.resolution === Resolution.Month) {
1160
+ return TimelineElement_1.AVERAGE_DAYS_IN_MONTH * this.minResolutionWidth;
1161
+ }
1162
+ else if (this.resolution === Resolution.Year) {
1163
+ return TimelineElement_1.AVERAGE_DAYS_IN_YEAR * this.minResolutionWidth;
1164
+ }
1055
1165
  return this.minResolutionWidth;
1056
1166
  }
1057
1167
  createResolutionBlock() {
@@ -1074,8 +1184,24 @@ export let TimelineElement = TimelineElement_1 = class TimelineElement extends L
1074
1184
  resBlock.classList.add("w", TimelineElement_1.STYLE_CENTER);
1075
1185
  return resBlock;
1076
1186
  }
1187
+ createMonthResolutionBlock() {
1188
+ // width is set explicitly for each block, see updateMonthOrYearResolutionBlockWidths()
1189
+ let resBlock = this.createResolutionBlock();
1190
+ resBlock.classList.add(TimelineElement_1.STYLE_MONTH_RES);
1191
+ return resBlock;
1192
+ }
1193
+ createYearResolutionBlock() {
1194
+ // width is set explicitly for each block, see updateMonthOrYearResolutionBlockWidths()
1195
+ let resBlock = this.createResolutionBlock();
1196
+ resBlock.classList.add(TimelineElement_1.STYLE_YEAR_RES);
1197
+ return resBlock;
1198
+ }
1077
1199
  fillVisibleTimeline() {
1078
- if (this.isTimelineOverflowingHorizontally()) {
1200
+ if (this.isMonthOrYearResolution()) {
1201
+ // all month/year blocks exist and are positioned statically; scrolling needs no re-positioning.
1202
+ this.showAllResolutionBlocks();
1203
+ }
1204
+ else if (this.isTimelineOverflowingHorizontally()) {
1079
1205
  this.showResolutionBlocksOnView();
1080
1206
  }
1081
1207
  else {
@@ -1161,7 +1287,10 @@ export let TimelineElement = TimelineElement_1 = class TimelineElement extends L
1161
1287
  fillTimelineForResolution(startDate, endDate, left) {
1162
1288
  this.updateCurrentDayString();
1163
1289
  this.updateDayRowCurrentStyles();
1164
- if (this.resolution === Resolution.Day || this.resolution === Resolution.Week) {
1290
+ if (this.isMonthOrYearResolution()) {
1291
+ this.fillTimelineForMonthOrYearResolution();
1292
+ }
1293
+ else if (this.resolution === Resolution.Day || this.resolution === Resolution.Week) {
1165
1294
  this.fillTimelineForDayResolution(startDate, endDate, left);
1166
1295
  }
1167
1296
  else if (this.resolution == Resolution.Hour) {
@@ -1217,6 +1346,14 @@ export let TimelineElement = TimelineElement_1 = class TimelineElement extends L
1217
1346
  * @return
1218
1347
  */
1219
1348
  getFirstResolutionElementWidth() {
1349
+ if (this.isMonthOrYearResolution()) {
1350
+ if (this.isTimelineOverflowingHorizontally()) {
1351
+ return this.firstResBlockCount * this.minResolutionWidth;
1352
+ }
1353
+ else {
1354
+ return ElementUtil.getWidth(this.getFirstResolutionElement());
1355
+ }
1356
+ }
1220
1357
  if (this.isFirstResBlockShort()) {
1221
1358
  if (this.isTimelineOverflowingHorizontally()) {
1222
1359
  return this.firstResBlockCount * this.minResolutionWidth;
@@ -1290,6 +1427,14 @@ export let TimelineElement = TimelineElement_1 = class TimelineElement extends L
1290
1427
  if (this.resolution === Resolution.Week) {
1291
1428
  return DateTimeConstants.DAYS_IN_WEEK * dayOrHourBlockWidthPx;
1292
1429
  }
1430
+ else if (this.resolution === Resolution.Month) {
1431
+ // average width; actual month block widths vary by number of days.
1432
+ return TimelineElement_1.AVERAGE_DAYS_IN_MONTH * dayOrHourBlockWidthPx;
1433
+ }
1434
+ else if (this.resolution === Resolution.Year) {
1435
+ // average width; actual year block widths vary by number of days.
1436
+ return TimelineElement_1.AVERAGE_DAYS_IN_YEAR * dayOrHourBlockWidthPx;
1437
+ }
1293
1438
  return dayOrHourBlockWidthPx;
1294
1439
  }
1295
1440
  /**
@@ -1367,6 +1512,22 @@ export let TimelineElement = TimelineElement_1 = class TimelineElement extends L
1367
1512
  this.style.setProperty("--timeline-col-last-width", last);
1368
1513
  }
1369
1514
  }
1515
+ /*
1516
+ * Sets the width explicitly for each Month/Year resolution block based on
1517
+ * the number of days in the block. Blocks are kept vertically in-line with
1518
+ * the day based year and month rows.
1519
+ */
1520
+ updateMonthOrYearResolutionBlockWidths() {
1521
+ this.resolutionDiv.style.removeProperty("display");
1522
+ let count = Math.min(this.resolutionDiv.childElementCount, this.resBlockDayCounts.length);
1523
+ for (let i = 0; i < count; i++) {
1524
+ let resBlock = this.resolutionDiv.children.item(i);
1525
+ if (resBlock === this.resSpacerDiv) {
1526
+ continue;
1527
+ }
1528
+ this.setWidth(resBlock, this.resBlockDayCounts[i]);
1529
+ }
1530
+ }
1370
1531
  getWidth(multiplier) {
1371
1532
  if (this.isTimelineOverflowingHorizontally()) {
1372
1533
  return (multiplier * this.minResolutionWidth) + "px";
@@ -1446,6 +1607,42 @@ export let TimelineElement = TimelineElement_1 = class TimelineElement extends L
1446
1607
  }
1447
1608
  }
1448
1609
  }
1610
+ /*
1611
+ * Fills captions and styles for all Month/Year resolution blocks. Uses block
1612
+ * data collected in prepareTimelineForDayOrWeekResolution().
1613
+ */
1614
+ fillTimelineForMonthOrYearResolution() {
1615
+ let childCount = this.resolutionDiv.childElementCount;
1616
+ // currentDayString is 'yyyy-MM-dd'; take 'yyyy-MM' or 'yyyy' part of it.
1617
+ let currentKey = null;
1618
+ if (this.currentDayString != null) {
1619
+ currentKey = this.currentDayString.substring(0, this.resolution === Resolution.Year ? 4 : 7);
1620
+ }
1621
+ for (let i = 0; i < this.resBlockStartDates.length; i++) {
1622
+ if (!this.isValidChildIndex(i, childCount)) {
1623
+ this.logIndexOutOfBounds(this.resolution === Resolution.Year ? "year" : "month", i, childCount);
1624
+ return;
1625
+ }
1626
+ let resBlock = this.resolutionDiv.children.item(i);
1627
+ let date = this.resBlockStartDates[i];
1628
+ this.fillMonthOrYearResolutionBlock(resBlock, date, i % 2 === 1, currentKey != null && this.resBlockKeys[i] === currentKey);
1629
+ }
1630
+ }
1631
+ fillMonthOrYearResolutionBlock(resBlock, date, even, current) {
1632
+ if (this.resolution === Resolution.Year) {
1633
+ resBlock.innerText = this.formatYearCaption(this.getYear(date), date);
1634
+ }
1635
+ else {
1636
+ resBlock.innerText = this.formatMonthCaption(this.getMonth(date), date);
1637
+ }
1638
+ if (even) {
1639
+ resBlock.classList.add(TimelineElement_1.STYLE_EVEN);
1640
+ }
1641
+ else {
1642
+ resBlock.classList.remove(TimelineElement_1.STYLE_EVEN);
1643
+ }
1644
+ this.setCurrentStyle(resBlock, current);
1645
+ }
1449
1646
  fillTimelineForHourResolution(startDate, endDate, left) {
1450
1647
  let timeline = this;
1451
1648
  this.firstDay = true;
@@ -1710,6 +1907,8 @@ TimelineElement.STYLE_MONTH = "month";
1710
1907
  TimelineElement.STYLE_YEAR = "year";
1711
1908
  TimelineElement.STYLE_DAY = "day";
1712
1909
  TimelineElement.STYLE_WEEK = "w";
1910
+ TimelineElement.STYLE_MONTH_RES = "m";
1911
+ TimelineElement.STYLE_YEAR_RES = "y";
1713
1912
  TimelineElement.STYLE_RESOLUTION = "resolution";
1714
1913
  TimelineElement.STYLE_EVEN = "even";
1715
1914
  TimelineElement.STYLE_WEEKEND = "weekend";
@@ -1722,6 +1921,9 @@ TimelineElement.STYLE_CURRENT = "current";
1722
1921
  TimelineElement.CURRENT_DAY_FORMAT = "yyyy-MM-dd";
1723
1922
  // Offset is included to tell apart the repeated hour when daylight saving time ends.
1724
1923
  TimelineElement.CURRENT_HOUR_FORMAT = "yyyy-MM-dd HH xxx";
1924
+ /* Average day counts used to convert a measured month/year block width to a day width. */
1925
+ TimelineElement.AVERAGE_DAYS_IN_MONTH = 30;
1926
+ TimelineElement.AVERAGE_DAYS_IN_YEAR = 365;
1725
1927
  __decorate([
1726
1928
  property({
1727
1929
  reflect: true,