@deephaven/grid 0.7.0 → 0.7.1-beta.4

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,10 +1,75 @@
1
1
  function _defineProperty(obj, key, value) { if (key in obj) { Object.defineProperty(obj, key, { value: value, enumerable: true, configurable: true, writable: true }); } else { obj[key] = value; } return obj; }
2
2
 
3
3
  import GridUtils from "./GridUtils.js";
4
- /* eslint class-methods-use-this: "off" */
5
4
 
6
- /* eslint react/destructuring-assignment: "off" */
5
+ /**
6
+ * Retrieve a value from a map. If the value is not found and no default value is provided, throw.
7
+ * Use when the value _must_ be present
8
+ * @param map The map to get the value from
9
+ * @param key The key to fetch the value for
10
+ * @param defaultValue A default value to set if the key is not present
11
+ * @returns The value set for that key
12
+ */
13
+ export function getOrThrow(map, key) {
14
+ var _map$get;
15
+
16
+ var defaultValue = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : undefined;
17
+ var value = (_map$get = map.get(key)) !== null && _map$get !== void 0 ? _map$get : defaultValue;
18
+
19
+ if (value !== undefined) {
20
+ return value;
21
+ }
22
+
23
+ throw new Error("Missing value for key ".concat(key));
24
+ }
25
+ /**
26
+ * Trim the provided map in place. Trims oldest inserted items down to the target size if the cache size is exceeded.
27
+ * Instead of trimming one item on every tick, we trim half the items so there isn't a cache clear on every new item.
28
+ * @param map The map to trim
29
+ * @param cacheSize The maximum number of elements to cache
30
+ * @param targetSize The number of elements to reduce the cache down to if `cacheSize` is exceeded
31
+ */
32
+
33
+ export function trimMap(map) {
34
+ var cacheSize = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : GridMetricCalculator.CACHE_SIZE;
35
+ var targetSize = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : Math.floor(cacheSize / 2);
36
+
37
+ if (map.size > cacheSize) {
38
+ var iter = map.keys();
39
+
40
+ while (map.size > targetSize) {
41
+ map.delete(iter.next().value);
42
+ }
43
+ }
44
+ }
45
+ /**
46
+ * Get the coordinates of floating items in one dimension.
47
+ * Can be used for getting the y coordinates of floating rows, or x coordinates of floating columns, calculated using the `sizeMap` passed in.
48
+ * @param startCount The number of floating items at the start (ie. `floatingTopRowCount` for rows, `floatingLeftColumnCount` for columns)
49
+ * @param endCount The number of floating items at the end (ie. `floatingBottomRowCount` for rows, `floatingRightColumnCount` for columns)
50
+ * @param totalCount Total number of items in this dimension (ie. `rowCount` for rows, `columnCount` for columns)
51
+ * @param max The max coordinate value (ie. `maxY` for rows, `maxX` for columns)
52
+ * @param sizeMap Map from index to size of item (ie. `rowHeightMap` for rows, `columnWidthMap` for columns)
53
+ */
54
+
55
+ export function getFloatingCoordinates(startCount, endCount, totalCount, max, sizeMap) {
56
+ var coordinates = new Map();
57
+ var x = 0;
58
+
59
+ for (var i = 0; i < startCount && i < totalCount; i += 1) {
60
+ coordinates.set(i, x);
61
+ x += getOrThrow(sizeMap, i);
62
+ }
7
63
 
64
+ x = max;
65
+
66
+ for (var _i = 0; _i < endCount && totalCount - _i - 1 >= 0; _i += 1) {
67
+ x -= getOrThrow(sizeMap, totalCount - _i - 1);
68
+ coordinates.set(totalCount - _i - 1, x);
69
+ }
70
+
71
+ return coordinates;
72
+ }
8
73
  /**
9
74
  * Class to calculate all the metrics for drawing a grid.
10
75
  * Call getMetrics() with the state to get the full metrics.
@@ -16,67 +81,54 @@ class GridMetricCalculator {
16
81
 
17
82
  /** The maximum column width as a percentage of the full grid */
18
83
 
19
- /**
20
- * Trim the provided map in place. Trims oldest inserted items down to the target size if the cache size is exceeded.
21
- * Instead of trimming one item on every tick, we trim half the items so there isn't a cache clear on every new item.
22
- * @param {Map} map The map to trim
23
- * @param {number} cacheSize The maximum number of elements to cache
24
- * @param {number} targetSize The number of elements to reduce the cache down to if `cacheSize` is exceeded
25
- */
26
- static trimMap(map) {
27
- var cacheSize = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : GridMetricCalculator.CACHE_SIZE;
28
- var targetSize = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : Math.floor(cacheSize / 2);
84
+ /** User set column widths */
29
85
 
30
- if (map.size > cacheSize) {
31
- var iter = map.keys();
86
+ /** User set row heights */
32
87
 
33
- while (map.size > targetSize) {
34
- map.delete(iter.next().value);
35
- }
36
- }
37
- }
38
- /**
39
- * Get the coordinates of floating items in one dimension.
40
- * Can be used for getting the y coordinates of floating rows, or x coordinates of floating columns, calculated using the `sizeMap` passed in.
41
- * @param {number} startCount The number of floating items at the start (ie. `floatingTopRowCount` for rows, `floatingLeftColumnCount` for columns)
42
- * @param {number} endCount The number of floating items at the end (ie. `floatingBottomRowCount` for rows, `floatingRightColumnCount` for columns)
43
- * @param {number} totalCount Total number of items in this dimension (ie. `rowCount` for rows, `columnCount` for columns)
44
- * @param {number} max The max coordinate value (ie. `maxY` for rows, `maxX` for columns)
45
- * @param {Map<number, number>} sizeMap Map from index to size of item (ie. `rowHeightMap` for rows, `columnWidthMap` for columns)
46
- */
88
+ /** Calculated column widths based on cell contents */
47
89
 
90
+ /** Calculated row heights based on cell contents */
48
91
 
49
- static getFloatingCoordinates(startCount, endCount, totalCount, max, sizeMap) {
50
- var coordinates = new Map();
51
- var x = 0;
92
+ /** Cache of fonts to estimated width of one char */
52
93
 
53
- for (var i = 0; i < startCount && i < totalCount; i += 1) {
54
- coordinates.set(i, x);
55
- x += sizeMap.get(i);
56
- }
94
+ /** Map from visible index to model index for rows (e.g. reversing movedRows operations) */
57
95
 
58
- x = max;
96
+ /** Map from visible index to model index for columns (e.g. reversing movedColumns operations) */
59
97
 
60
- for (var _i = 0; _i < endCount && totalCount - _i - 1 >= 0; _i += 1) {
61
- x -= sizeMap.get(totalCount - _i - 1);
62
- coordinates.set(totalCount - _i - 1, x);
63
- }
64
-
65
- return coordinates;
66
- }
98
+ /** List of moved row operations. Need to track the previous value so we know if modelRows needs to be cleared. */
67
99
 
100
+ /** List of moved column operations. Need to track the previous value so we know if modelColumns needs to be cleared. */
68
101
  constructor() {
69
102
  var {
70
103
  userColumnWidths = new Map(),
71
104
  userRowHeights = new Map(),
72
- calculatedRowHeights = new Map(),
73
105
  calculatedColumnWidths = new Map(),
106
+ calculatedRowHeights = new Map(),
74
107
  fontWidths = new Map(),
75
108
  modelRows = new Map(),
76
109
  modelColumns = new Map(),
77
- movedRows = null,
78
- movedColumns = null
110
+ movedRows = [],
111
+ movedColumns = []
79
112
  } = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
113
+
114
+ _defineProperty(this, "userColumnWidths", void 0);
115
+
116
+ _defineProperty(this, "userRowHeights", void 0);
117
+
118
+ _defineProperty(this, "calculatedColumnWidths", void 0);
119
+
120
+ _defineProperty(this, "calculatedRowHeights", void 0);
121
+
122
+ _defineProperty(this, "fontWidths", void 0);
123
+
124
+ _defineProperty(this, "modelRows", void 0);
125
+
126
+ _defineProperty(this, "modelColumns", void 0);
127
+
128
+ _defineProperty(this, "movedRows", void 0);
129
+
130
+ _defineProperty(this, "movedColumns", void 0);
131
+
80
132
  this.userColumnWidths = userColumnWidths;
81
133
  this.userRowHeights = userRowHeights;
82
134
  this.calculatedRowHeights = calculatedRowHeights;
@@ -88,7 +140,11 @@ class GridMetricCalculator {
88
140
  this.movedRows = movedRows;
89
141
  this.movedColumns = movedColumns;
90
142
  }
91
- /** update the calculated metrics from the model/canvas that are useful for many functions */
143
+ /**
144
+ * Get the metrics for the provided metric state
145
+ * @params state The state to get metrics for
146
+ * @returns The full metrics
147
+ */
92
148
 
93
149
 
94
150
  getMetrics(state) {
@@ -144,7 +200,11 @@ class GridMetricCalculator {
144
200
  var visibleColumnWidths = this.getVisibleColumnWidths(state, firstColumn, treePaddingX); // Calculate the metrics for the main grid
145
201
 
146
202
  var visibleRows = Array.from(visibleRowHeights.keys());
147
- var visibleColumns = Array.from(visibleColumnWidths.keys());
203
+ var visibleColumns = Array.from(visibleColumnWidths.keys()); // Add the floating row heights/column widths
204
+ // TODO #316: Create an allRowHeights/allColumnWidths maps
205
+
206
+ visibleRowHeights = new Map([...visibleRowHeights, ...this.getFloatingRowHeights(state)]);
207
+ visibleColumnWidths = new Map([...visibleColumnWidths, ...this.getFloatingColumnWidths(state)]);
148
208
  var visibleColumnXs = this.getVisibleColumnXs(visibleColumnWidths, visibleColumns, leftOffset);
149
209
  var visibleRowYs = this.getVisibleRowYs(visibleRowHeights, visibleRows, topOffset);
150
210
  var bottom = visibleRows.length > 0 ? visibleRows[visibleRows.length - 1] : top;
@@ -167,18 +227,17 @@ class GridMetricCalculator {
167
227
  var barHeight = height - columnHeaderHeight - horizontalBarHeight;
168
228
  var handleWidth = lastLeft > 0 ? Math.min(Math.max(minScrollHandleSize, barWidth * ((columnCount - lastLeft) / columnCount)), barWidth - 1) : 0;
169
229
  var handleHeight = lastTop > 0 ? Math.min(Math.max(minScrollHandleSize, barHeight * ((rowCount - lastTop) / rowCount)), barHeight - 1) : 0;
170
- var leftColumnWidth = visibleColumnWidths.get(left);
171
- var topRowHeight = visibleRowHeights.get(top);
230
+ var leftColumnWidth = getOrThrow(visibleColumnWidths, left, 0);
231
+ var topRowHeight = getOrThrow(visibleRowHeights, top, 0);
172
232
  var leftOffsetPercent = leftColumnWidth > 0 ? leftOffset / leftColumnWidth : 0;
173
233
  var topOffsetPercent = topRowHeight > 0 ? topOffset / topRowHeight : 0;
174
234
  var scrollX = lastLeft > 0 ? (left + leftOffsetPercent) / lastLeft * (barWidth - handleWidth) : 0;
175
- var scrollY = lastTop > 0 ? (top + topOffsetPercent) / lastTop * (barHeight - handleHeight) : 0; // Now add the floating sections
235
+ var scrollY = lastTop > 0 ? (top + topOffsetPercent) / lastTop * (barHeight - handleHeight) : 0; // Now add the floating sections positions
176
236
 
177
237
  var floatingRows = [];
178
238
 
179
239
  if (floatingTopRowCount > 0 || floatingBottomRowCount > 0) {
180
240
  floatingRows = [...Array(floatingTopRowCount).keys(), ...[...Array(floatingBottomRowCount).keys()].map(i => rowCount - i - 1)];
181
- visibleRowHeights = new Map([...visibleRowHeights, ...this.getFloatingRowHeights(state)]);
182
241
  visibleRowYs = new Map([...visibleRowYs, ...this.getFloatingRowYs(state, visibleRowHeights, Math.floor(height - gridY - horizontalBarHeight))]);
183
242
  }
184
243
 
@@ -186,7 +245,6 @@ class GridMetricCalculator {
186
245
 
187
246
  if (floatingLeftColumnCount > 0 || floatingRightColumnCount > 0) {
188
247
  floatingColumns = [...Array(floatingLeftColumnCount).keys(), ...[...Array(floatingRightColumnCount).keys()].map(i => columnCount - i - 1)];
189
- visibleColumnWidths = new Map([...visibleColumnWidths, ...this.getFloatingColumnWidths(state)]);
190
248
  visibleColumnXs = new Map([...visibleColumnXs, ...this.getFloatingColumnXs(state, visibleColumnWidths, Math.floor(width - gridX - verticalBarWidth))]);
191
249
  }
192
250
 
@@ -196,8 +254,8 @@ class GridMetricCalculator {
196
254
  var modelColumns = this.getModelColumns(allColumns, state);
197
255
  var visibleRowTreeBoxes = this.getVisibleRowTreeBoxes(visibleRowHeights, modelRows, state); // Calculate the visible viewport based on scroll position and floating sections
198
256
 
199
- var topVisible = this.getTopVisible(state, visibleRowYs, visibleRowHeights, visibleRows, gridY);
200
- var leftVisible = this.getLeftVisible(state, visibleColumnXs, visibleColumnWidths, visibleColumns, gridX);
257
+ var topVisible = this.getTopVisible(state, visibleRowYs, visibleRowHeights, visibleRows);
258
+ var leftVisible = this.getLeftVisible(state, visibleColumnXs, visibleColumnWidths, visibleColumns);
201
259
  var bottomVisible = lastTop > 0 ? this.getBottomVisible(state, visibleRowYs, visibleRowHeights, visibleRows, gridY) : bottom;
202
260
  var rightVisible = lastLeft > 0 ? this.getRightVisible(state, visibleColumnXs, visibleColumnWidths, visibleColumns, gridX) : right;
203
261
  var floatingTopHeight = this.getFloatingTopHeight(state, visibleRowHeights);
@@ -279,6 +337,7 @@ class GridMetricCalculator {
279
337
  allRows,
280
338
  allColumns,
281
339
  // Map of the height/width of visible rows/columns
340
+ // TODO #316: This should be split into allRowHeights/visibleRowHeights/floatingRowHeights ideally
282
341
  visibleRowHeights,
283
342
  visibleColumnWidths,
284
343
  // Floating metrics
@@ -304,6 +363,12 @@ class GridMetricCalculator {
304
363
  calculatedColumnWidths
305
364
  };
306
365
  }
366
+ /**
367
+ * The x offset of the grid
368
+ * @param state The current grid state
369
+ * @returns x value of the left side of the first cell
370
+ */
371
+
307
372
 
308
373
  getGridX(state) {
309
374
  var {
@@ -314,6 +379,12 @@ class GridMetricCalculator {
314
379
  } = theme;
315
380
  return rowHeaderWidth;
316
381
  }
382
+ /**
383
+ * The y offset of the grid
384
+ * @param state The current grid state
385
+ * @returns y value of the top side of the first cell
386
+ */
387
+
317
388
 
318
389
  getGridY(state) {
319
390
  var {
@@ -324,6 +395,13 @@ class GridMetricCalculator {
324
395
  } = theme;
325
396
  return columnHeaderHeight;
326
397
  }
398
+ /**
399
+ * The height of the "visible" area (excludes floating areas)
400
+ * @param state The current grid state
401
+ * @param visibleRowHeights All the visible row heights
402
+ * @returns The visible height in pixels
403
+ */
404
+
327
405
 
328
406
  getVisibleHeight(state) {
329
407
  var visibleRowHeights = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : this.getFloatingRowHeights(state);
@@ -339,6 +417,13 @@ class GridMetricCalculator {
339
417
  var floatingTopHeight = this.getFloatingTopHeight(state, visibleRowHeights);
340
418
  return height - floatingBottomHeight - floatingTopHeight - gridY - scrollBarSize;
341
419
  }
420
+ /**
421
+ * The width of the "visible" area (excludes floating areas)
422
+ * @param state The current grid state
423
+ * @param visibleColumnWidths All the visible column widths
424
+ * @returns The visible width in pixels
425
+ */
426
+
342
427
 
343
428
  getVisibleWidth(state) {
344
429
  var visibleColumnWidths = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : this.getFloatingColumnWidths(state);
@@ -355,6 +440,14 @@ class GridMetricCalculator {
355
440
  var floatingLeftWidth = this.getFloatingLeftWidth(state, visibleColumnWidths);
356
441
  return width - floatingLeftWidth - floatingRightWidth - gridX - scrollBarSize - rowFooterWidth;
357
442
  }
443
+ /**
444
+ * Retrieve the index of the first non-hidden item
445
+ * @param itemSizes The size of the items in this dimension
446
+ * @param getModelIndex A function to map from the Index to the ModelIndex
447
+ * @param state The current grid state
448
+ * @returns The first item that is not hidden
449
+ */
450
+
358
451
 
359
452
  getFirstIndex(itemSizes, getModelIndex, state) {
360
453
  // We only need to check at the very most the number of items the user has hidden + 1
@@ -370,21 +463,33 @@ class GridMetricCalculator {
370
463
 
371
464
  return 0;
372
465
  }
373
- /** Get the first column index that isn't hidden */
466
+ /**
467
+ * Get the first column index that isn't hidden
468
+ * @param state The current grid state
469
+ * @returns The first column that is not hidden
470
+ */
374
471
 
375
472
 
376
473
  getFirstColumn(state) {
377
474
  return this.getFirstIndex(this.userColumnWidths, this.getModelColumn.bind(this), state);
378
475
  }
379
- /** Get the first row index that isn't hidden */
476
+ /**
477
+ * Get the first row index that isn't hidden
478
+ * @param state The current grid state
479
+ * @returns The first row that is not hidden
480
+ */
380
481
 
381
482
 
382
483
  getFirstRow(state) {
383
484
  return this.getFirstIndex(this.userRowHeights, this.getModelRow.bind(this), state);
384
485
  }
385
486
  /**
386
- * Get the last column that can be the left most column (eg. scrolled to the right)
487
+ * Get the last column that can be the left most column (e.g. scrolled to the right)
387
488
  * If no right column is provided, then the last column is used.
489
+ * @param state The current grid state
490
+ * @param right The right-most column to be visible, or null to default to last cell
491
+ * @param visibleWidth The width of the "visible" area (excluding floating items)
492
+ * @returns The index of the last left visible column
388
493
  */
389
494
 
390
495
 
@@ -419,10 +524,19 @@ class GridMetricCalculator {
419
524
  return 0;
420
525
  }
421
526
  /**
422
- * The last row that can be the top row (eg. scrolled to the bottom)
527
+ * The last row that can be the top row (e.g. scrolled to the bottom)
423
528
  * If no bottom row is provided, then the last row that is not floating is used
424
529
  */
425
530
 
531
+ /**
532
+ * The last row that can be the top row (e.g. scrolled to the bottom)
533
+ * If no bottom row is provided, then the last row that is not floating is used
534
+ * @param state The current grid state
535
+ * @param bottom The bottom-most row to be visible, or null to default to last cell
536
+ * @param visibleHeight The height of the "visible" area (excluding floating items)
537
+ * @returns The index of the last left visible column
538
+ */
539
+
426
540
 
427
541
  getLastTop(state) {
428
542
  var bottom = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : null;
@@ -455,6 +569,15 @@ class GridMetricCalculator {
455
569
 
456
570
  return 0;
457
571
  }
572
+ /**
573
+ * Retrieve the top row to scroll to so the passed in `topVisible` is completely visible, taking the floating rows into account.
574
+ * The `top` row is at the top underneath any floating rows, whereas `topVisible` is visible below the floating rows.
575
+ * If there are no floating rows, they should be the same value.
576
+ * @param state The grid metric state
577
+ * @param topVisible The top row to be visible
578
+ * @returns The index of the top row to scroll to (under the floating top rows)
579
+ */
580
+
458
581
 
459
582
  getTopForTopVisible(state, topVisible) {
460
583
  var floatingTopHeight = this.getFloatingTopHeight(state);
@@ -468,6 +591,14 @@ class GridMetricCalculator {
468
591
 
469
592
  return top;
470
593
  }
594
+ /**
595
+ * Retrieve the top row to scroll to so the passed in `bottomVisible` is completely visible
596
+ * at the bottom of the visible viewport, taking the floating rows into account.
597
+ * @param state The grid metric state
598
+ * @param bottomVisible The bottom row to be visible
599
+ * @returns The index of the top row to scroll to (under the floating top rows)
600
+ */
601
+
471
602
 
472
603
  getTopForBottomVisible(state, bottomVisible) {
473
604
  var {
@@ -478,6 +609,14 @@ class GridMetricCalculator {
478
609
  var availableHeight = height - gridY - floatingBottomHeight;
479
610
  return this.getLastTop(state, bottomVisible, availableHeight);
480
611
  }
612
+ /**
613
+ * Retrieve the left column to scroll to so the passed in `leftVisible` is completely visible
614
+ * at the left of the visible viewport, taking the floating columns into account.
615
+ * @param state The grid metric state
616
+ * @param leftVisible The left column to be visible
617
+ * @returns The index of the left column to scroll to (under the floating left columns)
618
+ */
619
+
481
620
 
482
621
  getLeftForLeftVisible(state, leftVisible) {
483
622
  var floatingLeftWidth = this.getFloatingLeftWidth(state);
@@ -491,6 +630,14 @@ class GridMetricCalculator {
491
630
 
492
631
  return left;
493
632
  }
633
+ /**
634
+ * Retrieve the left column to scroll to so the passed in `rightVisible` is completely visible
635
+ * at the right of the visible viewport, taking the floating columns into account.
636
+ * @param state The grid metric state
637
+ * @param rightVisible The right column to be visible
638
+ * @returns The index of the left column to scroll to (under the floating left columns)
639
+ */
640
+
494
641
 
495
642
  getLeftForRightVisible(state, rightVisible) {
496
643
  var {
@@ -501,6 +648,12 @@ class GridMetricCalculator {
501
648
  var availableWidth = width - gridX - floatingRightWidth;
502
649
  return this.getLastLeft(state, rightVisible, availableWidth);
503
650
  }
651
+ /**
652
+ * Retrieve a map of the height of each floating row
653
+ * @param state The grid metric state
654
+ * @returns The heights of all the floating rows
655
+ */
656
+
504
657
 
505
658
  getFloatingRowHeights(state) {
506
659
  var {
@@ -524,6 +677,12 @@ class GridMetricCalculator {
524
677
 
525
678
  return rowHeights;
526
679
  }
680
+ /**
681
+ * Retrieve a map of the height of all the visible rows (non-floating)
682
+ * @param state The grid metric state
683
+ * @returns The heights of all the visible rows
684
+ */
685
+
527
686
 
528
687
  getVisibleRowHeights(state) {
529
688
  var {
@@ -548,6 +707,14 @@ class GridMetricCalculator {
548
707
 
549
708
  return rowHeights;
550
709
  }
710
+ /**
711
+ * Retrieve a map of the width of each floating column
712
+ * @param state The grid metric state
713
+ * @param firstColumn The first non-hidden column
714
+ * @param treePaddingX The amount of padding taken up for the tree expansion buttons
715
+ * @returns The widths of all the floating columns
716
+ */
717
+
551
718
 
552
719
  getFloatingColumnWidths(state) {
553
720
  var firstColumn = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : this.getFirstColumn(state);
@@ -573,6 +740,12 @@ class GridMetricCalculator {
573
740
 
574
741
  return columnWidths;
575
742
  }
743
+ /**
744
+ * Retrieve a map of the width of all the visible columns (non-floating)
745
+ * @param state The grid metric state
746
+ * @returns The widths of all the visible columns
747
+ */
748
+
576
749
 
577
750
  getVisibleColumnWidths(state) {
578
751
  var firstColumn = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : this.getFirstColumn(state);
@@ -599,6 +772,14 @@ class GridMetricCalculator {
599
772
 
600
773
  return columnWidths;
601
774
  }
775
+ /**
776
+ * Retrieve a map of all the floating columns to their x coordinate
777
+ * @param state The grid metric state
778
+ * @param columnWidthMap Map from visible index to column width
779
+ * @param maxX The maximum X size for the grid
780
+ * @returns Map of the x coordinate of all floating columns
781
+ */
782
+
602
783
 
603
784
  getFloatingColumnXs(state, columnWidthMap, maxX) {
604
785
  var {
@@ -609,8 +790,18 @@ class GridMetricCalculator {
609
790
  floatingLeftColumnCount,
610
791
  floatingRightColumnCount
611
792
  } = model;
612
- return GridMetricCalculator.getFloatingCoordinates(floatingLeftColumnCount, floatingRightColumnCount, columnCount, maxX, columnWidthMap);
793
+ return getFloatingCoordinates(floatingLeftColumnCount, floatingRightColumnCount, columnCount, maxX, columnWidthMap);
613
794
  }
795
+ /**
796
+ * Retrieve a map of all the visible columns to their x coordinate.
797
+ * Starts at leftOffset with the first index in `visibleColumns`, then
798
+ * calculates all the coordinates from there
799
+ * @param visibleColumnWidths Map of visible column index to widths
800
+ * @param visibleColumns All visible columns
801
+ * @param leftOffset The left scroll offset
802
+ * @returns Map of the x coordinate of all visible columns
803
+ */
804
+
614
805
 
615
806
  getVisibleColumnXs(visibleColumnWidths, visibleColumns, leftOffset) {
616
807
  var visibleColumnXs = new Map();
@@ -618,13 +809,21 @@ class GridMetricCalculator {
618
809
 
619
810
  for (var i = 0; i < visibleColumns.length; i += 1) {
620
811
  var column = visibleColumns[i];
621
- var columnWidth = visibleColumnWidths.get(column);
812
+ var columnWidth = getOrThrow(visibleColumnWidths, column);
622
813
  visibleColumnXs.set(column, x);
623
814
  x += columnWidth;
624
815
  }
625
816
 
626
817
  return visibleColumnXs;
627
818
  }
819
+ /**
820
+ * Retrieve a map of all the floating rows to their y coordinate
821
+ * @param state The grid metric state
822
+ * @param rowHeightMap Map of visible index to row height
823
+ * @param maxY The maximum Y size for the grid
824
+ * @returns Map of the y coordinate of all floating rows
825
+ */
826
+
628
827
 
629
828
  getFloatingRowYs(state, rowHeightMap, maxY) {
630
829
  var {
@@ -635,8 +834,18 @@ class GridMetricCalculator {
635
834
  floatingBottomRowCount,
636
835
  rowCount
637
836
  } = model;
638
- return GridMetricCalculator.getFloatingCoordinates(floatingTopRowCount, floatingBottomRowCount, rowCount, maxY, rowHeightMap);
837
+ return getFloatingCoordinates(floatingTopRowCount, floatingBottomRowCount, rowCount, maxY, rowHeightMap);
639
838
  }
839
+ /**
840
+ * Retrieve a map of all the visible rows to their y coordinate.
841
+ * Starts at topOffset with the first index in `visibleRows`, then
842
+ * calculates all the coordinates from there
843
+ * @param visibleRowHeights Map of visible row index to heights
844
+ * @param visibleRows All visible rows
845
+ * @param topOffset The top scroll offset
846
+ * @returns Map of the y coordinate of all visible rows
847
+ */
848
+
640
849
 
641
850
  getVisibleRowYs(visibleRowHeights, visibleRows, topOffset) {
642
851
  var visibleRowYs = new Map();
@@ -644,14 +853,20 @@ class GridMetricCalculator {
644
853
 
645
854
  for (var i = 0; i < visibleRows.length; i += 1) {
646
855
  var row = visibleRows[i];
647
- var rowHeight = visibleRowHeights.get(row);
856
+ var rowHeight = getOrThrow(visibleRowHeights, row);
648
857
  visibleRowYs.set(row, y);
649
858
  y += rowHeight;
650
859
  }
651
860
 
652
861
  return visibleRowYs;
653
862
  }
654
- /** Calculates the tree box click areas that are visible. In relation to the columnX/rowY */
863
+ /**
864
+ * Calculates the tree box click areas that are visible. In relation to the columnX/rowY
865
+ * @param visibleRowHeights Map of visible index to row height
866
+ * @param modelRows Map from visible `Index` to `ModelIndex`
867
+ * @param state The grid metric state
868
+ * @returns Coordinates of tree boxes for each row
869
+ */
655
870
 
656
871
 
657
872
  getVisibleRowTreeBoxes(visibleRowHeights, modelRows, state) {
@@ -675,13 +890,25 @@ class GridMetricCalculator {
675
890
  var x2 = (depth + 1) * treeDepthIndent + treeHorizontalPadding;
676
891
  var y1 = 0;
677
892
  var y2 = rowHeight;
678
- visibleRowTreeBoxes.set(row, [x1, y1, x2, y2]);
893
+ visibleRowTreeBoxes.set(row, {
894
+ x1,
895
+ y1,
896
+ x2,
897
+ y2
898
+ });
679
899
  }
680
900
  });
681
901
  }
682
902
 
683
903
  return visibleRowTreeBoxes;
684
904
  }
905
+ /**
906
+ * Get the total width of the floating columns on the left
907
+ * @param state The grid metric state
908
+ * @param columnWidths Map of column index to width
909
+ * @returns The total width of the floating left section
910
+ */
911
+
685
912
 
686
913
  getFloatingLeftWidth(state) {
687
914
  var columnWidths = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : this.getFloatingColumnWidths(state);
@@ -694,13 +921,18 @@ class GridMetricCalculator {
694
921
  var floatingWidth = 0;
695
922
 
696
923
  for (var i = 0; i < floatingLeftColumnCount; i += 1) {
697
- var _columnWidths$get;
698
-
699
- floatingWidth += (_columnWidths$get = columnWidths.get(i)) !== null && _columnWidths$get !== void 0 ? _columnWidths$get : 0;
924
+ floatingWidth += getOrThrow(columnWidths, i);
700
925
  }
701
926
 
702
927
  return floatingWidth;
703
928
  }
929
+ /**
930
+ * Get the total width of the floating columns on the right
931
+ * @param state The grid metric state
932
+ * @param columnWidths Map of column index to width
933
+ * @returns The total width of the floating right section
934
+ */
935
+
704
936
 
705
937
  getFloatingRightWidth(state) {
706
938
  var columnWidths = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : this.getFloatingColumnWidths(state);
@@ -714,13 +946,18 @@ class GridMetricCalculator {
714
946
  var floatingWidth = 0;
715
947
 
716
948
  for (var i = 0; i < floatingRightColumnCount; i += 1) {
717
- var _columnWidths$get2;
718
-
719
- floatingWidth += (_columnWidths$get2 = columnWidths.get(columnCount - i - 1)) !== null && _columnWidths$get2 !== void 0 ? _columnWidths$get2 : 0;
949
+ floatingWidth += getOrThrow(columnWidths, columnCount - i - 1);
720
950
  }
721
951
 
722
952
  return floatingWidth;
723
953
  }
954
+ /**
955
+ * Get the total height of the floating rows on the top
956
+ * @param state The grid metric state
957
+ * @param rowHeights Map of row index to height
958
+ * @returns The total height of the floating top section
959
+ */
960
+
724
961
 
725
962
  getFloatingTopHeight(state) {
726
963
  var rowHeights = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : this.getFloatingRowHeights(state);
@@ -733,13 +970,18 @@ class GridMetricCalculator {
733
970
  var floatingHeight = 0;
734
971
 
735
972
  for (var i = 0; i < floatingTopRowCount; i += 1) {
736
- var _rowHeights$get;
737
-
738
- floatingHeight += (_rowHeights$get = rowHeights.get(i)) !== null && _rowHeights$get !== void 0 ? _rowHeights$get : 0;
973
+ floatingHeight += getOrThrow(rowHeights, i);
739
974
  }
740
975
 
741
976
  return floatingHeight;
742
977
  }
978
+ /**
979
+ * Get the total height of the floating rows on the bottom
980
+ * @param state The grid metric state
981
+ * @param rowHeights Map of row index to height
982
+ * @returns The total height of the floating bottom section
983
+ */
984
+
743
985
 
744
986
  getFloatingBottomHeight(state) {
745
987
  var rowHeights = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : this.getFloatingRowHeights(state);
@@ -753,41 +995,72 @@ class GridMetricCalculator {
753
995
  var floatingHeight = 0;
754
996
 
755
997
  for (var i = 0; i < floatingBottomRowCount; i += 1) {
756
- var _rowHeights$get2;
757
-
758
- floatingHeight += (_rowHeights$get2 = rowHeights.get(rowCount - i - 1)) !== null && _rowHeights$get2 !== void 0 ? _rowHeights$get2 : 0;
998
+ floatingHeight += getOrThrow(rowHeights, rowCount - i - 1);
759
999
  }
760
1000
 
761
1001
  return floatingHeight;
762
1002
  }
1003
+ /**
1004
+ * Retrieve the index of the first fully visible row in the "visible" viewport of the grid.
1005
+ * E.g. First row visible after the floating rows, provided the visible rows.
1006
+ * @param state The grid metric state
1007
+ * @param visibleRowYs Map of row index to y coordinate
1008
+ * @param visibleRowHeights Map of row index to height
1009
+ * @param visibleRows Array of visible row indexes
1010
+ * @returns Index of the top visible row
1011
+ */
1012
+
763
1013
 
764
1014
  getTopVisible(state, visibleRowYs, visibleRowHeights, visibleRows) {
765
1015
  var floatingHeight = this.getFloatingTopHeight(state, visibleRowHeights);
766
1016
 
767
1017
  for (var i = 0; i < visibleRows.length; i += 1) {
768
1018
  var row = visibleRows[i];
1019
+ var y = getOrThrow(visibleRowYs, row);
769
1020
 
770
- if (visibleRowYs.get(row) >= floatingHeight) {
1021
+ if (y >= floatingHeight) {
771
1022
  return row;
772
1023
  }
773
1024
  }
774
1025
 
775
1026
  return 0;
776
1027
  }
1028
+ /**
1029
+ * Retrieve the index of the first fully visible column in the "visible" viewport of the grid.
1030
+ * E.g. First column visible after the floating columns, provided the visible columns.
1031
+ * @param state The grid metric state
1032
+ * @param visibleColumnXs Map of column index to x coordinate
1033
+ * @param visibleColumnWidths Map of column index to widths
1034
+ * @param visibleColumns Array of visible row indexes
1035
+ * @returns Index of the left visible column
1036
+ */
1037
+
777
1038
 
778
1039
  getLeftVisible(state, visibleColumnXs, visibleColumnWidths, visibleColumns) {
779
1040
  var floatingWidth = this.getFloatingLeftWidth(state, visibleColumnWidths);
780
1041
 
781
1042
  for (var i = 0; i < visibleColumns.length; i += 1) {
782
1043
  var column = visibleColumns[i];
1044
+ var x = getOrThrow(visibleColumnXs, column);
783
1045
 
784
- if (visibleColumnXs.get(column) >= floatingWidth) {
1046
+ if (x >= floatingWidth) {
785
1047
  return column;
786
1048
  }
787
1049
  }
788
1050
 
789
1051
  return 0;
790
1052
  }
1053
+ /**
1054
+ * Retrieve the index of the last fully visible row in the "visible" viewport of the grid.
1055
+ * E.g. Last row visible before the bottom floating rows, provided the visible rows.
1056
+ * @param state The grid metric state
1057
+ * @param visibleRowYs Map of row index to y coordinate
1058
+ * @param visibleRowHeights Map of row index to height
1059
+ * @param visibleRows Array of visible row indexes
1060
+ * @param gridY The starting y coordinate of the grid
1061
+ * @returns Index of the bottom visible row
1062
+ */
1063
+
791
1064
 
792
1065
  getBottomVisible(state, visibleRowYs, visibleRowHeights, visibleRows, gridY) {
793
1066
  var {
@@ -802,8 +1075,8 @@ class GridMetricCalculator {
802
1075
 
803
1076
  for (var i = visibleRows.length - 1; i >= 0; i -= 1) {
804
1077
  var row = visibleRows[i];
805
- var rowY = visibleRowYs.get(row);
806
- var rowHeight = visibleRowHeights.get(row);
1078
+ var rowY = getOrThrow(visibleRowYs, row);
1079
+ var rowHeight = getOrThrow(visibleRowHeights, row);
807
1080
 
808
1081
  if (rowY + rowHeight <= visibleHeight) {
809
1082
  return row;
@@ -812,6 +1085,16 @@ class GridMetricCalculator {
812
1085
 
813
1086
  return 0;
814
1087
  }
1088
+ /**
1089
+ * Retrieve the index of the last fully visible column in the "visible" viewport of the grid.
1090
+ * E.g. Last column visible before the floating columns, provided the visible columns.
1091
+ * @param state The grid metric state
1092
+ * @param visibleColumnXs Map of column index to x coordinate
1093
+ * @param visibleColumnWidths Map of column index to widths
1094
+ * @param visibleColumns Array of visible column indexes
1095
+ * @returns Index of the right visible column
1096
+ */
1097
+
815
1098
 
816
1099
  getRightVisible(state, visibleColumnXs, visibleColumnWidths, visibleColumns, gridX) {
817
1100
  var {
@@ -826,8 +1109,8 @@ class GridMetricCalculator {
826
1109
 
827
1110
  for (var i = visibleColumns.length - 1; i >= 0; i -= 1) {
828
1111
  var column = visibleColumns[i];
829
- var columnX = visibleColumnXs.get(column);
830
- var columnWidth = visibleColumnWidths.get(column);
1112
+ var columnX = getOrThrow(visibleColumnXs, column);
1113
+ var columnWidth = getOrThrow(visibleColumnWidths, column);
831
1114
 
832
1115
  if (columnX + columnWidth <= visibleWidth) {
833
1116
  return column;
@@ -836,6 +1119,15 @@ class GridMetricCalculator {
836
1119
 
837
1120
  return 0;
838
1121
  }
1122
+ /**
1123
+ * Retrieve the possible bottom of the visible viewport (not limited by data size)
1124
+ * @param state The grid metric state
1125
+ * @param visibleRows Array of visible row indexes
1126
+ * @param visibleRowYs Map of row index to y coordinate
1127
+ * @param visibleRowHeights Map of row index to height
1128
+ * @returns The index of the bottom viewport possible
1129
+ */
1130
+
839
1131
 
840
1132
  getBottomViewport(state, visibleRows, visibleRowYs, visibleRowHeights) {
841
1133
  var {
@@ -847,6 +1139,15 @@ class GridMetricCalculator {
847
1139
  } = theme;
848
1140
  return this.getLastIndexViewport(visibleRows, visibleRowYs, visibleRowHeights, height, rowHeight);
849
1141
  }
1142
+ /**
1143
+ * Retrieve the possible right of the visible viewport (not limited by data size)
1144
+ * @param state The grid metric state
1145
+ * @param visibleColumns Array of visible column indexes
1146
+ * @param visibleColumnXs Map of column index to x coordinate
1147
+ * @param visibleColumnWidths Map of column index to width
1148
+ * @returns The index of the right viewport possible
1149
+ */
1150
+
850
1151
 
851
1152
  getRightViewport(state, visibleColumns, visibleColumnXs, visibleColumnWidths) {
852
1153
  var {
@@ -858,6 +1159,16 @@ class GridMetricCalculator {
858
1159
  } = theme;
859
1160
  return this.getLastIndexViewport(visibleColumns, visibleColumnXs, visibleColumnWidths, width, columnWidth);
860
1161
  }
1162
+ /**
1163
+ * Get the Index of the of the last index visible
1164
+ * @param items Array of visible item indexes
1165
+ * @param itemXs Map of index to coordinate
1166
+ * @param itemSizes Map of index to size
1167
+ * @param maxSize Full size of the grid
1168
+ * @param defaultItemSize Default size of an item
1169
+ * @returns The Index of the last index visible
1170
+ */
1171
+
861
1172
 
862
1173
  getLastIndexViewport(items, itemXs, itemSizes, maxSize, defaultItemSize) {
863
1174
  var lastIndex = 0;
@@ -865,7 +1176,7 @@ class GridMetricCalculator {
865
1176
 
866
1177
  if (items.length > 0) {
867
1178
  lastIndex = items[items.length - 1];
868
- dataSize = itemXs.get(lastIndex) + itemSizes.get(lastIndex);
1179
+ dataSize = getOrThrow(itemXs, lastIndex) + getOrThrow(itemSizes, lastIndex);
869
1180
  }
870
1181
 
871
1182
  if (dataSize < maxSize) {
@@ -874,19 +1185,41 @@ class GridMetricCalculator {
874
1185
 
875
1186
  return lastIndex;
876
1187
  }
1188
+ /**
1189
+ * Get the size from the provided size map of the specified item
1190
+ * @param modelIndex The model index to get the size for
1191
+ * @param userSizes The user set sizes
1192
+ * @param calculateSize Method to calculate the size for this item
1193
+ * @returns The size from the provided size map of the specified item
1194
+ */
1195
+
877
1196
 
878
1197
  getVisibleItemSize(modelIndex, userSizes, calculateSize) {
879
- if (userSizes.has(modelIndex)) {
880
- return userSizes.get(modelIndex);
881
- }
1198
+ var _userSizes$get;
882
1199
 
883
- return calculateSize();
1200
+ return (_userSizes$get = userSizes.get(modelIndex)) !== null && _userSizes$get !== void 0 ? _userSizes$get : calculateSize();
884
1201
  }
1202
+ /**
1203
+ * Get the height of the specified row
1204
+ * @param row Index of the row to get the height of
1205
+ * @param state The grid metric state
1206
+ * @returns The height of the row specified
1207
+ */
1208
+
885
1209
 
886
1210
  getVisibleRowHeight(row, state) {
887
1211
  var modelRow = this.getModelRow(row, state);
888
1212
  return this.getVisibleItemSize(modelRow, this.userRowHeights, () => this.calculateRowHeight(row, modelRow, state));
889
1213
  }
1214
+ /**
1215
+ * Get the width of the specified column
1216
+ * @param column Index of the column to get the width of
1217
+ * @param state The grid metric state
1218
+ * @param firstColumn Index of first visible column
1219
+ * @param treePaddingX The amount of tree padding to add to the first visible column
1220
+ * @returns The width of the column
1221
+ */
1222
+
890
1223
 
891
1224
  getVisibleColumnWidth(column, state) {
892
1225
  var firstColumn = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : this.getFirstColumn(state);
@@ -894,6 +1227,13 @@ class GridMetricCalculator {
894
1227
  var modelColumn = this.getModelColumn(column, state);
895
1228
  return this.getVisibleItemSize(modelColumn, this.userColumnWidths, () => this.calculateColumnWidth(column, modelColumn, state, firstColumn, treePaddingX));
896
1229
  }
1230
+ /**
1231
+ * Get a map of ModelIndex to Index
1232
+ * @param visibleRows Array of visible row indexes
1233
+ * @param state The grid metric state
1234
+ * @returns Map of Index to ModelIndex
1235
+ */
1236
+
897
1237
 
898
1238
  getModelRows(visibleRows, state) {
899
1239
  var modelRows = new Map();
@@ -906,10 +1246,17 @@ class GridMetricCalculator {
906
1246
 
907
1247
  return modelRows;
908
1248
  }
1249
+ /**
1250
+ * Get the ModelIndex of the specified row
1251
+ * @param visibleRow Index of the row
1252
+ * @param state The grid metric state
1253
+ * @returns ModelIndex of the row
1254
+ */
1255
+
909
1256
 
910
1257
  getModelRow(visibleRow, state) {
911
1258
  if (this.modelRows.has(visibleRow)) {
912
- return this.modelRows.get(visibleRow);
1259
+ return getOrThrow(this.modelRows, visibleRow);
913
1260
  }
914
1261
 
915
1262
  var {
@@ -919,6 +1266,13 @@ class GridMetricCalculator {
919
1266
  this.modelRows.set(visibleRow, modelRow);
920
1267
  return modelRow;
921
1268
  }
1269
+ /**
1270
+ * Get a map of Index to ModelIndex. Applies the move operations to get the transformation.
1271
+ * @param visibleColumns Array of visible column indexes
1272
+ * @param state The grid metric state
1273
+ * @returns Map of Index to ModelIndex
1274
+ */
1275
+
922
1276
 
923
1277
  getModelColumns(visibleColumns, state) {
924
1278
  var modelColumns = new Map();
@@ -931,10 +1285,17 @@ class GridMetricCalculator {
931
1285
 
932
1286
  return modelColumns;
933
1287
  }
1288
+ /**
1289
+ * Get the ModelIndex of the specified column
1290
+ * @param visibleColumn Index of the column
1291
+ * @param state The grid metric state
1292
+ * @returns ModelIndex of the column
1293
+ */
1294
+
934
1295
 
935
1296
  getModelColumn(visibleColumn, state) {
936
1297
  if (this.modelColumns.has(visibleColumn)) {
937
- return this.modelColumns.get(visibleColumn);
1298
+ return getOrThrow(this.modelColumns, visibleColumn);
938
1299
  }
939
1300
 
940
1301
  var {
@@ -944,6 +1305,14 @@ class GridMetricCalculator {
944
1305
  this.modelColumns.set(visibleColumn, modelColumn);
945
1306
  return modelColumn;
946
1307
  }
1308
+ /**
1309
+ * Calculate the height of the row specified.
1310
+ * @param row Index of the row to calculate the height for
1311
+ * @param modelRow ModelIndex of the row to calculate the height
1312
+ * @param state The grid metric state
1313
+ * @returns The height of the row
1314
+ */
1315
+
947
1316
 
948
1317
  calculateRowHeight(row, modelRow, state) {
949
1318
  var {
@@ -966,10 +1335,18 @@ class GridMetricCalculator {
966
1335
 
967
1336
 
968
1337
  this.calculatedRowHeights.set(modelRow, Math.ceil(rowHeight));
969
- GridMetricCalculator.trimMap(this.calculatedRowHeights);
1338
+ trimMap(this.calculatedRowHeights);
970
1339
  return rowHeight;
971
1340
  }
972
- /** Calculates the column width based on the provided column model index */
1341
+ /**
1342
+ * Calculates the column width based on the provided column model index
1343
+ * @param column Index of the column to calculate the width for
1344
+ * @param modelColumn ModelIndex of the column to calculate the width
1345
+ * @param state The grid metric state
1346
+ * @param firstColumn The first visible column
1347
+ * @param treePaddingX Tree padding offset for expandable rows
1348
+ * @returns The width of the column
1349
+ */
973
1350
 
974
1351
 
975
1352
  calculateColumnWidth(column, modelColumn, state) {
@@ -1000,7 +1377,7 @@ class GridMetricCalculator {
1000
1377
  columnWidth = cachedValue;
1001
1378
  } else {
1002
1379
  this.calculatedColumnWidths.set(modelColumn, columnWidth);
1003
- GridMetricCalculator.trimMap(this.calculatedColumnWidths);
1380
+ trimMap(this.calculatedColumnWidths);
1004
1381
  }
1005
1382
 
1006
1383
  if (column === firstColumn) {
@@ -1009,6 +1386,13 @@ class GridMetricCalculator {
1009
1386
 
1010
1387
  return columnWidth;
1011
1388
  }
1389
+ /**
1390
+ * Calculate the width of the specified column's header
1391
+ * @param modelColumn ModelIndex of the column to get the header width for
1392
+ * @param state The grid metric state
1393
+ * @returns The calculated width of the column header
1394
+ */
1395
+
1012
1396
 
1013
1397
  calculateColumnHeaderWidth(modelColumn, state) {
1014
1398
  var {
@@ -1028,6 +1412,13 @@ class GridMetricCalculator {
1028
1412
 
1029
1413
  return headerHorizontalPadding * 2;
1030
1414
  }
1415
+ /**
1416
+ * Calculate the width of the specified column's data
1417
+ * @param modelColumn ModelIndex of the column to get the data width for
1418
+ * @param state The grid metric state
1419
+ * @returns The calculated width of the column data
1420
+ */
1421
+
1031
1422
 
1032
1423
  calculateColumnDataWidth(modelColumn, state) {
1033
1424
  var {
@@ -1066,6 +1457,12 @@ class GridMetricCalculator {
1066
1457
  columnWidth = Math.max(Math.min(columnWidth, (width - rowHeaderWidth - scrollBarSize - rowFooterWidth) * GridMetricCalculator.MAX_COLUMN_WIDTH), cellHorizontalPadding * 2);
1067
1458
  return columnWidth;
1068
1459
  }
1460
+ /**
1461
+ * The coordinate for where the tree padding should be drawn
1462
+ * @param state The grid metric state
1463
+ * @returns The coordinate for tree padding
1464
+ */
1465
+
1069
1466
 
1070
1467
  calculateTreePaddingX(state) {
1071
1468
  var {
@@ -1095,12 +1492,18 @@ class GridMetricCalculator {
1095
1492
 
1096
1493
  return treePadding;
1097
1494
  }
1098
- /** Get the width of the provided font. Exploits the fact that we're using tabular figures so every character is same width */
1495
+ /**
1496
+ * Get the width of the provided font. Exploits the fact that we're
1497
+ * using tabular figures so every character is same width
1498
+ * @param font The font to get the width for
1499
+ * @param state The grid metric state
1500
+ * @returns Width of the char `8` for the specified font
1501
+ */
1099
1502
 
1100
1503
 
1101
1504
  getWidthForFont(font, state) {
1102
1505
  if (this.fontWidths.has(font)) {
1103
- return this.fontWidths.get(font);
1506
+ return getOrThrow(this.fontWidths, font);
1104
1507
  }
1105
1508
 
1106
1509
  var {
@@ -1110,7 +1513,7 @@ class GridMetricCalculator {
1110
1513
  var textMetrics = context.measureText('8');
1111
1514
  var {
1112
1515
  width
1113
- } = textMetrics; // context.font changes the string a little bit, eg. '10px Arial, sans serif' => '10px Arial, "sans serif"'
1516
+ } = textMetrics; // context.font changes the string a little bit, e.g. '10px Arial, sans serif' => '10px Arial, "sans serif"'
1114
1517
  // Rather than require checking with the correct font def (theme, or context font), just key it to both
1115
1518
 
1116
1519
  this.fontWidths.set(font, width);
@@ -1119,55 +1522,56 @@ class GridMetricCalculator {
1119
1522
  }
1120
1523
  /**
1121
1524
  * Sets the width for the specified column
1122
- * @param {Number} column The column model index to set
1123
- * @param {Number} size The size to set it to, or null to reset the column size
1525
+ * @param column The column model index to set
1526
+ * @param size The size to set it to
1124
1527
  */
1125
1528
 
1126
1529
 
1127
1530
  setColumnWidth(column, size) {
1531
+ // Always use a new instance of the map so any consumer of the metrics knows there has been a change
1128
1532
  var userColumnWidths = new Map(this.userColumnWidths);
1129
-
1130
- if (size != null) {
1131
- userColumnWidths.set(column, Math.ceil(size));
1132
- GridMetricCalculator.trimMap(userColumnWidths);
1133
- } else {
1134
- userColumnWidths.delete(column);
1135
- }
1136
-
1533
+ userColumnWidths.set(column, Math.ceil(size));
1534
+ trimMap(userColumnWidths);
1137
1535
  this.userColumnWidths = userColumnWidths;
1138
1536
  }
1139
1537
  /**
1140
1538
  * Resets the column width for the specified column to the calculated width
1141
- * @param {Number} column The column model index to reset
1539
+ * @param column The column model index to reset
1142
1540
  */
1143
1541
 
1144
1542
 
1145
1543
  resetColumnWidth(column) {
1146
- this.setColumnWidth(column, null);
1544
+ // Always use a new instance of the map so any consumer of the metrics knows there has been a change
1545
+ var userColumnWidths = new Map(this.userColumnWidths);
1546
+ userColumnWidths.delete(column);
1547
+ this.userColumnWidths = userColumnWidths;
1147
1548
  this.calculatedColumnWidths.delete(column);
1148
1549
  }
1149
1550
  /**
1150
1551
  * Sets the width for the specified row
1151
- * @param {Number} row The row model index to set
1152
- * @param {Number} size The size to set it to, or null to reset the row size
1552
+ * @param row The row model index to set
1553
+ * @param size The size to set it to
1153
1554
  */
1154
1555
 
1155
1556
 
1156
1557
  setRowHeight(row, size) {
1558
+ // Always use a new instance of the map so any consumer of the metrics knows there has been a change
1157
1559
  var userRowHeights = new Map(this.userRowHeights);
1158
-
1159
- if (size != null) {
1160
- userRowHeights.set(row, Math.ceil(size));
1161
- GridMetricCalculator.trimMap(userRowHeights);
1162
- } else {
1163
- userRowHeights.delete(row);
1164
- }
1165
-
1560
+ userRowHeights.set(row, Math.ceil(size));
1561
+ trimMap(userRowHeights);
1166
1562
  this.userRowHeights = userRowHeights;
1167
1563
  }
1564
+ /**
1565
+ * Resets the row height for the specified row to the calculated height
1566
+ * @param row The row model index to reset
1567
+ */
1568
+
1168
1569
 
1169
1570
  resetRowHeight(row) {
1170
- this.setRowHeight(row, null);
1571
+ // Always use a new instance of the map so any consumer of the metrics knows there has been a change
1572
+ var userRowHeights = new Map(this.userRowHeights);
1573
+ userRowHeights.delete(row);
1574
+ this.userRowHeights = userRowHeights;
1171
1575
  this.calculatedRowHeights.delete(row);
1172
1576
  }
1173
1577