canvas-datagrid 0.25.4 → 0.27.0

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/lib/draw.js CHANGED
@@ -2,6 +2,8 @@
2
2
  /*globals XMLSerializer: false, define: true, Blob: false, MutationObserver: false, requestAnimationFrame: false, performance: false, btoa: false*/
3
3
  'use strict';
4
4
 
5
+ import { isCellSelected } from './selections/util';
6
+
5
7
  export default function (self) {
6
8
  var perfCounters = [],
7
9
  cachedImagesDrawn = false,
@@ -108,6 +110,98 @@ export default function (self) {
108
110
  '</svg>\n',
109
111
  );
110
112
  }
113
+ /**
114
+ * @param {number[]} coords [x0,y0, x1,y1, x2,y2, ...]
115
+ * @param {boolean} [fill] fill the area that construct by these lines but not stroke
116
+ */
117
+ function drawLines(coords, fill) {
118
+ if (coords.length < 4) return;
119
+ self.ctx.beginPath();
120
+ self.ctx.moveTo(
121
+ coords[0] + self.canvasOffsetLeft,
122
+ coords[1] + self.canvasOffsetTop,
123
+ );
124
+ for (let i = 2; i < coords.length; i += 2) {
125
+ const x = coords[i] + self.canvasOffsetLeft;
126
+ const y = coords[i + 1] + self.canvasOffsetTop;
127
+ self.ctx.lineTo(x, y);
128
+ }
129
+ if (fill) self.ctx.fill();
130
+ else self.ctx.stroke();
131
+ }
132
+ /**
133
+ * @param {number} x based-X (left-top)
134
+ * @param {number} y based-Y (left-top)
135
+ * @param {number} width
136
+ * @param {boolean} collapsed true: '+'; false: '-'
137
+ */
138
+ function drawGroupHandle(x, y, width, collapsed) {
139
+ fillRect(x, y, width, width);
140
+ strokeRect(x, y, width, width);
141
+ const cx = x + width * 0.5;
142
+ const cy = y + width * 0.5;
143
+ drawLines([x + width * 0.2, cy, x + width * 0.78, cy]);
144
+ if (collapsed) drawLines([cx, y + width * 0.22, cx, y + width * 0.8]);
145
+ }
146
+ /**
147
+ * @param {number} x
148
+ * @param {number} y
149
+ * @param {number} size
150
+ * @param {string} dir Direction of the triangle, one of the 't','b','l' and 'r'
151
+ * @param {boolean} [active]
152
+ */
153
+ function drawUnhideIndicator(x, y, size, dir, active) {
154
+ const minPadding = size * 0.2;
155
+ const maxPadding = size * 0.3;
156
+ /** The long edge width of the triangle */
157
+ const longEdge = size - 2 * minPadding;
158
+ /** The median width of the triangle */
159
+ const median = size - 2 * maxPadding;
160
+ const halfLongEdge = longEdge * 0.5;
161
+ let x0, y0;
162
+ let coords, borderCoords;
163
+ switch (dir) {
164
+ case 'r':
165
+ x0 = x + maxPadding;
166
+ y0 = y + minPadding;
167
+ borderCoords = [x, y, x + size, y, x + size, y + size, x, y + size];
168
+ coords = [x0, y0, x0, y0 + longEdge, x0 + median, y0 + halfLongEdge];
169
+ break;
170
+ case 'l':
171
+ x0 = x + size - maxPadding;
172
+ y0 = y + minPadding;
173
+ borderCoords = [x + size, y, x, y, x, y + size, x + size, y + size];
174
+ coords = [x0, y0, x0, y0 + longEdge, x0 - median, y0 + halfLongEdge];
175
+ break;
176
+ case 't':
177
+ x0 = x + minPadding;
178
+ y0 = y + size - maxPadding;
179
+ borderCoords = [x, y + size, x, y, x + size, y, x + size, y + size];
180
+ coords = [x0, y0, x0 + longEdge, y0, x0 + halfLongEdge, y0 - median];
181
+ break;
182
+ case 'b':
183
+ x0 = x + minPadding;
184
+ y0 = y + maxPadding;
185
+ borderCoords = [x, y, x, y + size, x + size, y + size, x + size, y];
186
+ coords = [x0, y0, x0 + longEdge, y0, x0 + halfLongEdge, y0 + median];
187
+ break;
188
+ }
189
+
190
+ if (active) {
191
+ self.ctx.strokeStyle = self.style.unhideIndicatorBorderColor;
192
+ self.ctx.lineWidth = 2;
193
+ drawLines(borderCoords);
194
+
195
+ self.ctx.fillStyle = self.style.unhideIndicatorBackgroundColor;
196
+ let offset = dir === 'r' || dir === 'b' ? 1 : 0;
197
+ if (dir === 'l' || dir === 'r')
198
+ fillRect(x - offset, y, size + offset, size);
199
+ else fillRect(x, y - offset, size, size + offset);
200
+ }
201
+
202
+ self.ctx.fillStyle = self.style.unhideIndicatorColor;
203
+ drawLines(coords, true);
204
+ }
111
205
  function drawOrderByArrow(x, y) {
112
206
  var mt = self.style.columnHeaderOrderByArrowMarginTop * self.scale,
113
207
  ml = self.style.columnHeaderOrderByArrowMarginLeft * self.scale,
@@ -122,15 +216,15 @@ export default function (self) {
122
216
  x = x + ml;
123
217
  y = y + mt;
124
218
  if (self.orderDirection === 'asc') {
125
- self.ctx.moveTo(x, y);
126
- self.ctx.lineTo(x + aw, y);
127
- self.ctx.lineTo(x + aw * 0.5, y + ah);
128
- self.ctx.moveTo(x, y);
129
- } else {
130
219
  self.ctx.lineTo(x, y + ah);
131
220
  self.ctx.lineTo(x + aw, y + ah);
132
221
  self.ctx.lineTo(x + aw * 0.5, y);
133
222
  self.ctx.lineTo(x, y + ah);
223
+ } else {
224
+ self.ctx.moveTo(x, y);
225
+ self.ctx.lineTo(x + aw, y);
226
+ self.ctx.lineTo(x + aw * 0.5, y + ah);
227
+ self.ctx.moveTo(x, y);
134
228
  }
135
229
  self.ctx.stroke();
136
230
  self.ctx.fill();
@@ -164,6 +258,82 @@ export default function (self) {
164
258
  self.ctx.fill();
165
259
  return ml + aw + mr;
166
260
  }
261
+ function drawCellTreeIcon(cell, tree, rowTree) {
262
+ const parentCount = rowTree ? tree.parentCount : 0;
263
+ const iconSize = self.style.cellTreeIconWidth * self.scale,
264
+ marginTop = self.style.cellTreeIconMarginTop * self.scale,
265
+ marginRight = self.style.cellTreeIconMarginRight * self.scale,
266
+ marginLeft =
267
+ self.style.cellTreeIconMarginLeft * self.scale +
268
+ parentCount * (iconSize + cell.paddingLeft);
269
+
270
+ let x = cell.x + cell.paddingLeft + self.canvasOffsetLeft + marginLeft,
271
+ y = cell.y + self.canvasOffsetTop + marginTop;
272
+
273
+ if (tree.icon) {
274
+ self.ctx.beginPath();
275
+ const oldFillStyle = self.ctx.fillStyle;
276
+ const oldStrokeStyle = self.ctx.strokeStyle;
277
+
278
+ if (cell.hovered && self.hovers.onCellTreeIcon) {
279
+ self.ctx.fillStyle = self.style.cellTreeIconHoverFillColor;
280
+ } else {
281
+ self.ctx.fillStyle = self.style.cellTreeIconFillColor;
282
+ }
283
+
284
+ self.ctx.fillRect(x, y, iconSize, iconSize);
285
+ self.ctx.strokeStyle = self.style.cellTreeIconBorderColor;
286
+ self.ctx.rect(x, y, iconSize, iconSize);
287
+ self.ctx.stroke();
288
+
289
+ self.ctx.beginPath();
290
+ if (tree.expand) {
291
+ self.ctx.moveTo(x + 3, y + iconSize * 0.5);
292
+ self.ctx.lineTo(x + iconSize - 3, y + iconSize * 0.5);
293
+ } else {
294
+ self.ctx.moveTo(x + 2, y + iconSize * 0.5);
295
+ self.ctx.lineTo(x + iconSize - 2, y + iconSize * 0.5);
296
+ self.ctx.moveTo(x + iconSize * 0.5, y + 2);
297
+ self.ctx.lineTo(x + iconSize * 0.5, y + iconSize - 2);
298
+ }
299
+ self.ctx.lineWidth = self.style.cellTreeIconLineWidth;
300
+ self.ctx.strokeStyle = self.style.cellTreeIconLineColor;
301
+ self.ctx.stroke();
302
+
303
+ self.ctx.strokeStyle = oldStrokeStyle;
304
+ self.ctx.fillStyle = oldFillStyle;
305
+ }
306
+
307
+ return marginLeft + iconSize + marginRight;
308
+ }
309
+ function drawFilterButtonArrow(x, y) {
310
+ var mt =
311
+ ((self.style.filterButtonHeight - self.style.filterButtonArrowHeight) /
312
+ 2) *
313
+ self.scale,
314
+ ml =
315
+ ((self.style.filterButtonWidth - self.style.filterButtonArrowWidth) /
316
+ 2) *
317
+ self.scale,
318
+ aw = self.style.filterButtonArrowWidth * self.scale,
319
+ ah = self.style.filterButtonArrowHeight * self.scale;
320
+ x += self.canvasOffsetLeft;
321
+ y += self.canvasOffsetTop;
322
+ self.ctx.fillStyle = self.style.filterButtonArrowColor;
323
+ self.ctx.strokeStyle = self.style.filterButtonArrowBorderColor;
324
+ self.ctx.beginPath();
325
+ x = x + ml;
326
+ y = y + mt;
327
+
328
+ self.ctx.moveTo(x, y);
329
+ self.ctx.lineTo(x + aw, y);
330
+ self.ctx.lineTo(x + aw * 0.5, y + ah);
331
+ self.ctx.moveTo(x, y);
332
+
333
+ self.ctx.stroke();
334
+ self.ctx.fill();
335
+ return ml + aw;
336
+ }
167
337
  function radiusRect(x, y, w, h, radius) {
168
338
  x += self.canvasOffsetLeft;
169
339
  y += self.canvasOffsetTop;
@@ -362,9 +532,10 @@ export default function (self) {
362
532
  elWidth = self.ctx.measureText(' ' + et).width;
363
533
  for (x = 0; x < words.length; x += 1) {
364
534
  word = words[x];
365
- var measure = self.ctx.measureText(word + splitChar);
535
+ var curSplitChar = word[word.length - 1] === '-' ? '' : splitChar;
536
+ var measure = self.ctx.measureText(word + curSplitChar);
366
537
  if (line.width + measure.width + elWidth < cell.paddedWidth) {
367
- line.value += word + splitChar;
538
+ line.value += word + curSplitChar;
368
539
  line.width += measure.width;
369
540
  continue;
370
541
  }
@@ -373,13 +544,17 @@ export default function (self) {
373
544
  // then back up and re-read new split set
374
545
  // this behavior seems right, it might not be
375
546
  if (/\w-\w/.test(word) && cell.paddedWidth < measure.width) {
376
- words.splice(x, 1, word.split('-')[0] + '-', word.split('-')[1]);
547
+ var arr = word.split('-');
548
+ arr = arr.map((item, index) => {
549
+ return index === arr.length - 1 ? item : item + '-';
550
+ });
551
+ words.splice(x, 1, ...arr);
377
552
  x -= 1;
378
553
  continue;
379
554
  }
380
555
  line = {
381
556
  width: measure.width,
382
- value: word + splitChar,
557
+ value: word + curSplitChar,
383
558
  };
384
559
  if (x === 0) {
385
560
  lines = [];
@@ -427,35 +602,58 @@ export default function (self) {
427
602
  height: cell.calculatedLineHeight * lines.length,
428
603
  };
429
604
  }
430
- function drawText(cell) {
605
+ function drawText(cell, treeCellPadding = 0) {
431
606
  var ll = cell.text.lines.length,
432
607
  h = cell.fontHeight * cell.lineHeight,
433
608
  x,
434
609
  line,
435
610
  wrap = self.style.cellWhiteSpace !== 'nowrap',
436
611
  textHeight = 0;
612
+ // text supplied by a rendertext handler may omit width/height (#460)
613
+ var textBlockHeight =
614
+ cell.text.height === undefined
615
+ ? cell.calculatedLineHeight * ll
616
+ : cell.text.height;
437
617
  for (x = 0; x < cell.text.lines.length; x += 1) {
438
618
  line = cell.text.lines[x];
619
+ if (line.width === undefined) {
620
+ line.width = self.ctx.measureText(
621
+ line.value === undefined || line.value === null
622
+ ? ''
623
+ : String(line.value),
624
+ ).width;
625
+ }
439
626
  var vPos =
440
627
  Math.max(
441
628
  (cell.height -
442
- (wrap ? cell.text.height : cell.calculatedLineHeight)) *
629
+ (wrap ? textBlockHeight : cell.calculatedLineHeight)) *
443
630
  0.5,
444
631
  0,
445
632
  ) + h,
446
- hPos = cell.paddingLeft + cell.treeArrowWidth + cell.orderByArrowWidth;
633
+ hPos =
634
+ cell.paddingLeft +
635
+ treeCellPadding +
636
+ cell.treeArrowWidth +
637
+ cell.orderByArrowWidth;
447
638
  if (cell.horizontalAlignment === 'right') {
448
- hPos = cell.paddingLeft + cell.paddedWidth - line.width;
639
+ hPos =
640
+ cell.paddingLeft + treeCellPadding + cell.paddedWidth - line.width;
449
641
  } else if (cell.horizontalAlignment === 'center') {
450
642
  hPos =
451
643
  cell.paddingLeft +
644
+ treeCellPadding +
452
645
  (cell.paddedWidth + cell.paddingRight) / 2 -
453
646
  line.width / 2;
454
647
  }
455
648
  if (cell.verticalAlignment === 'top') {
456
649
  vPos = cell.calculatedLineHeight;
457
650
  } else if (cell.verticalAlignment === 'bottom') {
458
- vPos = cell.height - cell.paddingBottom - cell.text.height;
651
+ // baseline of the last line sits on the bottom padding (#530)
652
+ vPos =
653
+ cell.height -
654
+ cell.paddingBottom -
655
+ textBlockHeight +
656
+ cell.calculatedLineHeight;
459
657
  }
460
658
  line.height = h + cell.lineSpacing;
461
659
  line.offsetLeft = hPos;
@@ -505,6 +703,7 @@ export default function (self) {
505
703
  s = self.getSchema(),
506
704
  x = 0,
507
705
  n = Math.min(self.frozenColumn, s.length),
706
+ collapsedGroups = self.getCollapsedColumnGroups(),
508
707
  column;
509
708
  hiddenFrozenColumnCount = 0;
510
709
  while (x < n) {
@@ -512,7 +711,15 @@ export default function (self) {
512
711
  if (column.hidden) {
513
712
  hiddenFrozenColumnCount += 1;
514
713
  } else {
515
- w += self.getColummnWidth(x);
714
+ const isCollapsed =
715
+ collapsedGroups.findIndex(
716
+ (group) => x >= group.from && x <= group.to,
717
+ ) >= 0;
718
+ if (isCollapsed) {
719
+ hiddenFrozenColumnCount += 1;
720
+ } else {
721
+ w += self.getColumnWidth(x);
722
+ }
516
723
  }
517
724
  x += 1;
518
725
  }
@@ -568,43 +775,100 @@ export default function (self) {
568
775
  c,
569
776
  h,
570
777
  w,
571
- s,
572
- r,
573
- rd,
778
+ schema,
779
+ rowIndex,
780
+ rowData,
574
781
  aCell,
575
- data = self.data || [],
782
+ viewData = self.viewData || [],
576
783
  bc = self.style.gridBorderCollapse === 'collapse',
577
784
  selectionBorders = [],
578
785
  moveBorders = [],
579
786
  selectionHandles = [],
580
787
  rowHeaders = [],
581
- l = data.length,
788
+ l = viewData.length,
582
789
  u = self.currentCell || {},
583
790
  columnHeaderCellHeight = self.getColumnHeaderCellHeight(),
584
791
  rowHeaderCellWidth = self.getRowHeaderCellWidth(),
585
- cellHeight = self.style.cellHeight;
792
+ rowGroupsAreaWidth = self.getRowGroupAreaWidth(),
793
+ columnGroupsAreaHeight = self.getColumnGroupAreaHeight(),
794
+ /** key: boundRowIndex, value: `{y,h}` */
795
+ rowGroupsRectInfo = {},
796
+ /** value: `{y,h}` */
797
+ rowGroupsFrozenInfo = {},
798
+ /** key: columnIndex, value: `{x,w}` */
799
+ columnGroupsRectInfo = {},
800
+ collapsedColumnGroups = self.getCollapsedColumnGroups(),
801
+ collapsedRowGroups = self.getCollapsedRowGroups(),
802
+ cellHeight = self.style.cellHeight,
803
+ currentRowIndexOffset = 0,
804
+ /** @type {Array<{from:number,plus:number}>} */
805
+ rowIndexOffsetByHiddenRows = self.hiddenRowRanges
806
+ .map((range) => ({
807
+ from: range[0],
808
+ plus: range[1] - range[0] + 1,
809
+ }))
810
+ .sort((a, b) => a.from - b.from);
586
811
  drawCount += 1;
587
812
  p = performance.now();
588
813
  self.visibleRowHeights = [];
589
814
  // if data length has changed, there is no way to know
590
- if (data.length > self.orders.rows.length) {
815
+ if (viewData.length > self.orders.rows.length) {
591
816
  self.createRowOrders();
592
817
  }
818
+ function saveRowGroupsRectInfo(cell) {
819
+ let index = cell.boundRowIndex;
820
+ if (index >= -1 === false)
821
+ if (cell.rowIndex === -1) index = -1;
822
+ else return;
823
+ if (rowGroupsRectInfo[index]) return;
824
+ rowGroupsRectInfo[index] = { y: cell.y, h: cell.height };
825
+ }
826
+ function saveColumnGroupsRectInfo(cell) {
827
+ const index = cell.columnIndex;
828
+ if (columnGroupsRectInfo[index]) return;
829
+ columnGroupsRectInfo[index] = { x: cell.x, w: cell.width };
830
+ }
831
+ /**
832
+ * @param {number} columnIndex
833
+ * @returns {boolean}
834
+ */
835
+ function isColumnCollapsedByGroup(columnIndex) {
836
+ return (
837
+ collapsedColumnGroups.findIndex(
838
+ (group) => columnIndex >= group.from && columnIndex <= group.to,
839
+ ) >= 0
840
+ );
841
+ }
842
+
593
843
  function drawScrollBars() {
594
844
  var drawCorner,
595
845
  en = self.scrollBox.entities,
596
846
  m = self.style.scrollBarBoxMargin * 2;
597
847
  self.ctx.strokeStyle = self.style.scrollBarBorderColor;
598
848
  self.ctx.lineWidth = self.style.scrollBarBorderWidth;
599
- en.horizontalBox.x =
600
- rowHeaderCellWidth +
601
- self.style.scrollBarBoxMargin +
602
- (en.horizontalBar.width - self.scrollBox.scrollBoxWidth) *
603
- (self.scrollBox.scrollLeft / self.scrollBox.scrollWidth);
849
+ if (self.frozenColumn > 0) {
850
+ en.horizontalBox.x =
851
+ rowHeaderCellWidth +
852
+ self.style.scrollBarBoxMargin +
853
+ self.scrollCache.x[self.frozenColumn - 1] +
854
+ (en.horizontalBar.width -
855
+ self.scrollCache.x[self.frozenColumn - 1] -
856
+ self.scrollBox.scrollBoxWidth) *
857
+ (self.scrollBox.scrollLeft / self.scrollBox.scrollWidth);
858
+ } else {
859
+ en.horizontalBox.x =
860
+ rowHeaderCellWidth +
861
+ self.style.scrollBarBoxMargin +
862
+ (en.horizontalBar.width - self.scrollBox.scrollBoxWidth) *
863
+ (self.scrollBox.scrollLeft / self.scrollBox.scrollWidth);
864
+ }
604
865
  en.verticalBox.y =
605
866
  columnHeaderCellHeight +
606
867
  self.style.scrollBarBoxMargin +
607
- (en.verticalBar.height - self.scrollBox.scrollBoxHeight) *
868
+ self.scrollCache.y[self.frozenRow] +
869
+ (en.verticalBar.height -
870
+ self.scrollBox.scrollBoxHeight -
871
+ self.scrollCache.y[self.frozenRow]) *
608
872
  (self.scrollBox.scrollTop / self.scrollBox.scrollHeight);
609
873
  if (self.scrollBox.horizontalBarVisible) {
610
874
  self.ctx.fillStyle = self.style.scrollBarBackgroundColor;
@@ -698,13 +962,17 @@ export default function (self) {
698
962
  selectionHandles.push([cell, 'tr']);
699
963
  cell.selectionHandle = 'tr';
700
964
  }
701
- if (
702
- cell.selectionBorderTop &&
703
- cell.selectionBorderLeft &&
704
- self.mobile
705
- ) {
706
- selectionHandles.push([cell, 'tl']);
707
- cell.selectionHandle = 'tl';
965
+ if (cell.selectionBorderTop && cell.selectionBorderLeft) {
966
+ if (self.mobile) {
967
+ selectionHandles.push([cell, 'tl']);
968
+ cell.selectionHandle = 'tl';
969
+ }
970
+ if (self.fillOverlay.handle) {
971
+ self.fillOverlay.snapTo = {
972
+ x: cell.x,
973
+ y: cell.y,
974
+ };
975
+ }
708
976
  }
709
977
  if (
710
978
  cell.selectionBorderBottom &&
@@ -721,6 +989,22 @@ export default function (self) {
721
989
  ) {
722
990
  selectionHandles.push([cell, 'br']);
723
991
  cell.selectionHandle = 'br';
992
+
993
+ if (self.fillOverlay.handle) {
994
+ self.fillOverlay.handle.x = cell.x + cell.width;
995
+ self.fillOverlay.handle.y = cell.y + cell.height;
996
+ }
997
+ }
998
+
999
+ if (self.fillOverlay.handle) {
1000
+ // Some corners may not be displaying, so we get at least
1001
+ // one correct axis in order to display a fill overlay.
1002
+ if (self.fillOverlay.snapTo.x === -1 && cell.selectionBorderLeft) {
1003
+ self.fillOverlay.snapTo.x = cell.x;
1004
+ }
1005
+ if (self.fillOverlay.snapTo.y === -1 && cell.selectionBorderTop) {
1006
+ self.fillOverlay.snapTo.y = cell.y;
1007
+ }
724
1008
  }
725
1009
  }
726
1010
  }
@@ -730,21 +1014,23 @@ export default function (self) {
730
1014
  propPrefix,
731
1015
  offsetPoint,
732
1016
  ) {
733
- offsetPoint = offsetPoint || { x: 0, y: 0 };
734
1017
  cell.selectionBorder = '';
735
- if (
736
- !cell.isRowHeader &&
737
- self.selections[cell.rowIndex + -offsetPoint.y] &&
738
- self.selections[cell.rowIndex + -offsetPoint.y].indexOf(
739
- cell.columnIndex + -offsetPoint.x,
740
- ) !== -1
741
- ) {
1018
+ // TODO: optimize it by `getSelectionStateFromCells`
1019
+ const isSelected = offsetPoint
1020
+ ? (row, col) =>
1021
+ isCellSelected(
1022
+ self.selections,
1023
+ row - offsetPoint.y,
1024
+ col - offsetPoint.x,
1025
+ )
1026
+ : (row, col) => isCellSelected(self.selections, row, col);
1027
+ const lastColumnIndex = Math.max(schema.length - 1, 0);
1028
+ const lastRowIndex = Math.max(viewData.length - 1, 0);
1029
+ const { isRowHeader, rowIndex, columnIndex } = cell;
1030
+
1031
+ if (!isRowHeader && isSelected(rowIndex, columnIndex)) {
742
1032
  if (
743
- (!self.selections[cell.rowIndex - 1 + -offsetPoint.y] ||
744
- self.selections[cell.rowIndex - 1 + -offsetPoint.y].indexOf(
745
- cell.columnIndex + -offsetPoint.x,
746
- ) === -1 ||
747
- cell.rowIndex === 0) &&
1033
+ (!isSelected(rowIndex - 1, columnIndex) || rowIndex === 0) &&
748
1034
  !cell.isHeader
749
1035
  ) {
750
1036
  drawArray.push([cell, 't']);
@@ -752,32 +1038,21 @@ export default function (self) {
752
1038
  cell[propPrefix + 'Border'] += 't';
753
1039
  }
754
1040
  if (
755
- !self.selections[cell.rowIndex + 1 + -offsetPoint.y] ||
756
- self.selections[cell.rowIndex + 1 + -offsetPoint.y].indexOf(
757
- cell.columnIndex + -offsetPoint.x,
758
- ) === -1
1041
+ rowIndex >= lastRowIndex ||
1042
+ !isSelected(rowIndex + 1, columnIndex)
759
1043
  ) {
760
1044
  drawArray.push([cell, 'b']);
761
1045
  cell[propPrefix + 'BorderBottom'] = true;
762
1046
  cell[propPrefix + 'Border'] += 'b';
763
1047
  }
764
- if (
765
- !self.selections[cell.rowIndex + -offsetPoint.y] ||
766
- cell.columnIndex === 0 ||
767
- self.selections[cell.rowIndex + -offsetPoint.y].indexOf(
768
- cell.columnIndex - 1 + -offsetPoint.x,
769
- ) === -1
770
- ) {
1048
+ if (columnIndex === 0 || !isSelected(rowIndex, columnIndex - 1)) {
771
1049
  drawArray.push([cell, 'l']);
772
1050
  cell[propPrefix + 'BorderLeft'] = true;
773
1051
  cell[propPrefix + 'Border'] += 'l';
774
1052
  }
775
1053
  if (
776
- !self.selections[cell.rowIndex + -offsetPoint.y] ||
777
- cell.columnIndex === s.length ||
778
- self.selections[cell.rowIndex + -offsetPoint.y].indexOf(
779
- cell.columnIndex + 1 + -offsetPoint.x,
780
- ) === -1
1054
+ columnIndex >= lastColumnIndex ||
1055
+ !isSelected(rowIndex, columnIndex + 1)
781
1056
  ) {
782
1057
  drawArray.push([cell, 'r']);
783
1058
  cell[propPrefix + 'BorderRight'] = true;
@@ -785,7 +1060,11 @@ export default function (self) {
785
1060
  }
786
1061
  }
787
1062
  }
788
- function drawCell(d, rowOrderIndex, rowIndex) {
1063
+ function drawCell(rowData, rowOrderIndex, rowIndex) {
1064
+ const isActiveRowHeader =
1065
+ self.orders.rows[self.activeCell.rowIndex] === rowOrderIndex ||
1066
+ self.isRowSelected(rowOrderIndex);
1067
+
789
1068
  return function drawEach(header, headerIndex, columnOrderIndex) {
790
1069
  if (header.hidden) {
791
1070
  return 0;
@@ -797,38 +1076,55 @@ export default function (self) {
797
1076
  isCorner = /cornerCell/.test(cellStyle),
798
1077
  isRowHeader = 'rowHeaderCell' === cellStyle,
799
1078
  isColumnHeader = 'columnHeaderCell' === cellStyle,
1079
+ isFilterable =
1080
+ self.filterable.rows.includes(rowIndex) &&
1081
+ self.filterable.columns.includes(headerIndex),
800
1082
  wrap = self.style.cellWhiteSpace !== 'nowrap',
801
- selected =
802
- self.selections[rowOrderIndex] &&
803
- self.selections[rowOrderIndex].indexOf(columnOrderIndex) !== -1,
1083
+ // TODO: optimize it by `getSelectionStateFromCells`
1084
+ selected = isCellSelected(
1085
+ self.selections,
1086
+ rowOrderIndex,
1087
+ columnOrderIndex,
1088
+ ),
804
1089
  hovered =
805
1090
  self.hovers.rowIndex === rowOrderIndex &&
806
- self.hovers.columnIndex === columnOrderIndex,
1091
+ (self.attributes.hoverMode === 'row' ||
1092
+ self.hovers.columnIndex === columnOrderIndex),
1093
+ openedFilter =
1094
+ self.selectedFilterButton.rowIndex == rowIndex &&
1095
+ self.selectedFilterButton.columnIndex == headerIndex,
807
1096
  active =
808
1097
  self.activeCell.rowIndex === rowOrderIndex &&
809
1098
  self.activeCell.columnIndex === columnOrderIndex,
810
1099
  isColumnHeaderCellCap = cellStyle === 'columnHeaderCellCap',
811
- rawValue = d ? d[header.name] : undefined,
1100
+ rawValue = rowData ? rowData[header.name] : undefined,
812
1101
  isGrid = header.type === 'canvas-datagrid',
813
- activeHeader =
814
- (self.orders.rows[self.activeCell.rowIndex] === rowOrderIndex ||
815
- self.orders.columns[self.activeCell.columnIndex] ===
816
- headerIndex) &&
817
- (columnOrderIndex === -1 || rowOrderIndex === -1)
818
- ? isRowHeader
819
- ? 'activeRowHeaderCell'
820
- : 'activeColumnHeaderCell'
821
- : false,
822
1102
  val,
823
1103
  f = self.formatters[header.type || 'string'],
824
1104
  orderByArrowSize = 0,
825
1105
  treeArrowSize = 0,
826
- cellWidth = self.sizes.columns[headerIndex] || header.width,
1106
+ cellWidth =
1107
+ headerIndex >= 0
1108
+ ? self.getColumnWidth(headerIndex)
1109
+ : self.sizes.columns[headerIndex] || header.width,
827
1110
  ev = {
828
1111
  value: rawValue,
829
- row: d,
1112
+ row: rowData,
830
1113
  header: header,
831
1114
  };
1115
+
1116
+ const isActiveColumnHeader =
1117
+ self.orders.columns[self.activeCell.columnIndex] === headerIndex ||
1118
+ self.isColumnSelected(self.activeCell.viewColumnIndex);
1119
+ let activeHeader = false;
1120
+ if (
1121
+ (isActiveColumnHeader || isActiveRowHeader) &&
1122
+ (columnOrderIndex === -1 || rowOrderIndex === -1)
1123
+ )
1124
+ activeHeader = isRowHeader
1125
+ ? 'activeRowHeaderCell'
1126
+ : 'activeColumnHeaderCell';
1127
+
832
1128
  if (isColumnHeaderCellCap) {
833
1129
  cellWidth = w - x;
834
1130
  }
@@ -836,7 +1132,9 @@ export default function (self) {
836
1132
  if (cellWidth === undefined) {
837
1133
  cellWidth = self.style.cellWidth;
838
1134
  }
839
- cellWidth = cellWidth * self.scale;
1135
+ if (headerIndex < 0) {
1136
+ cellWidth = cellWidth * self.scale;
1137
+ }
840
1138
  if (x + cellWidth + self.style.cellBorderWidth < 0) {
841
1139
  x += cellWidth + self.style.cellBorderWidth;
842
1140
  }
@@ -889,18 +1187,30 @@ export default function (self) {
889
1187
  offsetHeight: cellHeight,
890
1188
  parentNode: self.intf.parentNode,
891
1189
  offsetParent: self.intf.parentNode,
892
- data: d,
1190
+ data: rowData,
893
1191
  isCorner: isCorner,
894
1192
  isHeader: isHeader,
895
1193
  isColumnHeader: isColumnHeader,
896
1194
  isColumnHeaderCellCap: isColumnHeaderCellCap,
897
1195
  isRowHeader: isRowHeader,
1196
+ isFilterable: isFilterable,
1197
+ openedFilter: openedFilter,
898
1198
  rowOpen: rowOpen,
899
1199
  header: header,
1200
+
900
1201
  columnIndex: columnOrderIndex,
901
1202
  rowIndex: rowOrderIndex,
1203
+
1204
+ viewRowIndex: rowOrderIndex,
1205
+ viewColumnIndex: columnOrderIndex,
1206
+
1207
+ boundRowIndex: self.getBoundRowIndexFromViewRowIndex(rowOrderIndex),
1208
+ boundColumnIndex:
1209
+ self.getBoundColumnIndexFromViewColumnIndex(columnOrderIndex),
1210
+
902
1211
  sortColumnIndex: headerIndex,
903
1212
  sortRowIndex: rowIndex,
1213
+
904
1214
  isGrid: isGrid,
905
1215
  isNormal: !isGrid && !isCorner && !isHeader,
906
1216
  gridId: (self.attributes.name || '') + rowIndex + ':' + headerIndex,
@@ -909,6 +1219,15 @@ export default function (self) {
909
1219
  activeHeader: activeHeader,
910
1220
  value:
911
1221
  isHeader && !isRowHeader ? header.title || header.name : rawValue,
1222
+ isRowTree:
1223
+ rowOrderIndex >= 0 &&
1224
+ columnOrderIndex == self.cellTree.rowTreeColIndex &&
1225
+ self.cellTree.rows.length > 0 &&
1226
+ self.cellTree.rows[rowOrderIndex].icon,
1227
+ isColumnTree:
1228
+ columnOrderIndex >= 0 &&
1229
+ self.cellTree.columns[rowOrderIndex] &&
1230
+ self.cellTree.columns[rowOrderIndex][columnOrderIndex].icon,
912
1231
  };
913
1232
  cell.calculatedLineHeight =
914
1233
  cell.fontHeight * cell.lineHeight + cell.lineSpacing;
@@ -920,6 +1239,8 @@ export default function (self) {
920
1239
  ? self.sizes.columns.cornerCell
921
1240
  : self.sizes.columns[headerIndex];
922
1241
  self.visibleCells.unshift(cell);
1242
+ saveRowGroupsRectInfo(cell);
1243
+ saveColumnGroupsRectInfo(cell);
923
1244
  if (self.dispatchEvent('beforerendercell', ev)) {
924
1245
  return;
925
1246
  }
@@ -994,9 +1315,8 @@ export default function (self) {
994
1315
  if (self.dispatchEvent('beforecreatecellgrid', ev)) {
995
1316
  return;
996
1317
  }
997
- self.childGrids[cell.gridId] = self.createGrid(
998
- cellGridAttributes,
999
- );
1318
+ self.childGrids[cell.gridId] =
1319
+ self.createGrid(cellGridAttributes);
1000
1320
  self.sizes.rows[rowIndex] =
1001
1321
  self.sizes.rows[rowIndex] || self.style.cellGridHeight;
1002
1322
  checkScrollHeight = true;
@@ -1040,9 +1360,8 @@ export default function (self) {
1040
1360
  ' add a cellFormater',
1041
1361
  );
1042
1362
  }
1043
- cell.formattedValue = (val !== undefined && val !== null
1044
- ? val
1045
- : ''
1363
+ cell.formattedValue = (
1364
+ val !== undefined && val !== null ? val : ''
1046
1365
  ).toString();
1047
1366
  if (
1048
1367
  self.columnFilters &&
@@ -1051,10 +1370,7 @@ export default function (self) {
1051
1370
  ) {
1052
1371
  cell.formattedValue = self.attributes.filterTextPrefix + val;
1053
1372
  }
1054
- self.ctx.font =
1055
- self.style[cellStyle + 'FontHeight'] * self.scale +
1056
- 'px ' +
1057
- self.style[cellStyle + 'FontName'];
1373
+ self.ctx.font = self.getScaledFont(cellStyle + 'Font');
1058
1374
  if (!self.dispatchEvent('formattext', ev)) {
1059
1375
  cell.text = wrapText(cell, ' ');
1060
1376
  }
@@ -1062,7 +1378,53 @@ export default function (self) {
1062
1378
  if (cell.innerHTML || header.type === 'html') {
1063
1379
  drawHtml(cell);
1064
1380
  } else {
1065
- drawText(cell);
1381
+ let treeCellPadding = 0,
1382
+ isDrawText = true;
1383
+ if (
1384
+ cell.columnIndex == self.cellTree.rowTreeColIndex &&
1385
+ !cell.isColumnHeader &&
1386
+ self.cellTree.rows.length > 0 &&
1387
+ Object.keys(self.cellTree.rows[cell.rowIndex]).length > 1
1388
+ )
1389
+ treeCellPadding = drawCellTreeIcon(
1390
+ cell,
1391
+ self.cellTree.rows[cell.rowIndex],
1392
+ true,
1393
+ );
1394
+
1395
+ if (
1396
+ !cell.isRowHeader &&
1397
+ cell.rowIndex > 0 &&
1398
+ self.cellTree.columns[cell.rowIndex - 1] &&
1399
+ self.cellTree.columns[cell.rowIndex - 1][cell.columnIndex]
1400
+ .icon
1401
+ ) {
1402
+ for (let r = cell.rowIndex - 1; r >= 0; r--) {
1403
+ if (!self.cellTree.columns[r]) break;
1404
+ if (!self.cellTree.columns[r][cell.columnIndex].icon) break;
1405
+ if (!self.cellTree.columns[r][cell.columnIndex].expand) {
1406
+ isDrawText = false;
1407
+ break;
1408
+ }
1409
+ }
1410
+ }
1411
+ if (
1412
+ isDrawText &&
1413
+ !cell.isRowHeader &&
1414
+ self.cellTree.columns[cell.rowIndex] &&
1415
+ self.cellTree.columns[cell.rowIndex][cell.columnIndex].icon
1416
+ ) {
1417
+ if (
1418
+ self.viewData.length > 0 &&
1419
+ self.viewData[cell.rowIndex][cell.columnIndex].length > 0
1420
+ )
1421
+ treeCellPadding = drawCellTreeIcon(
1422
+ cell,
1423
+ self.cellTree.columns[cell.rowIndex][cell.columnIndex],
1424
+ false,
1425
+ );
1426
+ }
1427
+ if (isDrawText) drawText(cell, treeCellPadding);
1066
1428
  }
1067
1429
 
1068
1430
  if (wrap && cell.text && cell.text.height > rowHeight) {
@@ -1082,31 +1444,283 @@ export default function (self) {
1082
1444
  createBorderOverlayArray(cell, moveBorders, 'move', self.moveOffset);
1083
1445
  }
1084
1446
  self.ctx.restore();
1447
+
1448
+ if (isFilterable) {
1449
+ drawFilterButton(cell);
1450
+ }
1451
+
1452
+ // Gaps may occur in row numbers between consecutively rendered rows
1453
+ // when we are filtering. We draw attention to this by drawing a thick
1454
+ // border overlapping the two consecutive row headers. If sorting, visible
1455
+ // row numbers stay the same (i.e. they don't correspond to the underlying
1456
+ // data's row number), so we do not show row gaps in that case.
1457
+ const isSorting =
1458
+ self.orderings.columns && self.orderings.columns.length > 0;
1459
+
1460
+ if (
1461
+ isRowHeader &&
1462
+ self.attributes.showRowNumbers &&
1463
+ self.attributes.showRowNumberGaps &&
1464
+ isSorting === false
1465
+ ) {
1466
+ const previousRowNumber = self.getBoundRowIndexFromViewRowIndex(
1467
+ rowOrderIndex - 1,
1468
+ );
1469
+ let hasRowGap =
1470
+ previousRowNumber !== undefined &&
1471
+ cell.boundRowIndex > 0 &&
1472
+ cell.boundRowIndex - previousRowNumber > 1;
1473
+ if (hasRowGap && collapsedRowGroups.length > 0) {
1474
+ hasRowGap =
1475
+ collapsedRowGroups.find(
1476
+ (group) =>
1477
+ group.from === previousRowNumber &&
1478
+ group.to === cell.boundRowIndex,
1479
+ ) >= 0;
1480
+ }
1481
+ // We don't treat the row index difference from hidden rows as the row gap.
1482
+ if (hasRowGap && self.hiddenRowRanges.length > 0) {
1483
+ for (let i = 0; i < self.hiddenRowRanges.length; i++) {
1484
+ const [beginRowIndex, endRowIndex] = self.hiddenRowRanges[i];
1485
+ if (
1486
+ cell.boundRowIndex === endRowIndex + 1 &&
1487
+ previousRowNumber === beginRowIndex - 1
1488
+ ) {
1489
+ hasRowGap = false;
1490
+ break;
1491
+ }
1492
+ }
1493
+ }
1494
+
1495
+ if (hasRowGap) {
1496
+ const barHeight = self.style.rowHeaderCellRowNumberGapHeight;
1497
+ const barColor = self.style.rowHeaderCellRowNumberGapColor;
1498
+
1499
+ self.ctx.save();
1500
+
1501
+ self.ctx.fillStyle = barColor;
1502
+
1503
+ fillRect(cell.x, cell.y - barHeight / 2, cell.width, barHeight);
1504
+
1505
+ self.ctx.restore();
1506
+ }
1507
+ }
1508
+
1509
+ //#region draw unhide indicator for column headers
1510
+ if (isColumnHeader && self.attributes.showUnhideColumnsIndicator) {
1511
+ const hovered = self.hovers.unhideIndicator;
1512
+ const size = self.style.unhideIndicatorSize;
1513
+ const cellX = x;
1514
+ const topY = cell.y + Math.max(0.5 * (cell.height - size), 0);
1515
+
1516
+ const isActive = (orderIndex) =>
1517
+ hovered &&
1518
+ (hovered.dir === 'l' || hovered.dir === 'r') &&
1519
+ orderIndex >= hovered.orderIndex0 &&
1520
+ orderIndex <= hovered.orderIndex1;
1521
+ const isHiddenColumn = (columnIndex) =>
1522
+ columnIndex >= 0 &&
1523
+ schema[columnIndex] &&
1524
+ schema[columnIndex].hidden;
1525
+
1526
+ let orderIndex0, orderIndex1;
1527
+ const drawIndicator = (leftX, dir, active) => {
1528
+ self.visibleUnhideIndicators.push({
1529
+ x: leftX - 1,
1530
+ y: topY - 1,
1531
+ x2: leftX + size + 2,
1532
+ y2: topY + size + 2,
1533
+ orderIndex0,
1534
+ orderIndex1,
1535
+ dir,
1536
+ });
1537
+ if (!active) {
1538
+ const line = cell.text && cell.text.lines && cell.text.lines[0];
1539
+ if (line) {
1540
+ const iconsWidth = orderByArrowSize + treeArrowSize;
1541
+ const lineX0 = iconsWidth > 0 ? iconsWidth : line.x;
1542
+ const lineX1 = line.x + line.width;
1543
+ if (leftX + size >= lineX0 && leftX <= lineX1) return;
1544
+ }
1545
+ }
1546
+ drawUnhideIndicator(leftX, topY, size, dir, active);
1547
+ }; // end of drawIndicator
1548
+
1549
+ let orderIndexPtr = columnOrderIndex - 1;
1550
+ const prevColumnIndex = self.orders.columns[orderIndexPtr];
1551
+ if (isHiddenColumn(prevColumnIndex)) {
1552
+ const active = isActive(prevColumnIndex);
1553
+ orderIndex0 = orderIndexPtr;
1554
+ orderIndex1 = orderIndexPtr;
1555
+ while (--orderIndexPtr >= 0) {
1556
+ if (isHiddenColumn(self.orders.columns[orderIndexPtr]))
1557
+ orderIndex0 = orderIndexPtr;
1558
+ else break;
1559
+ }
1560
+ drawIndicator(cellX, 'r', active);
1561
+ }
1562
+
1563
+ orderIndexPtr = columnOrderIndex + 1;
1564
+ const nextColumnIndex = self.orders.columns[orderIndexPtr];
1565
+ if (isHiddenColumn(nextColumnIndex)) {
1566
+ const active = isActive(nextColumnIndex);
1567
+ orderIndex0 = orderIndexPtr;
1568
+ orderIndex1 = orderIndexPtr;
1569
+ while (++orderIndexPtr < self.orders.columns.length) {
1570
+ if (isHiddenColumn(self.orders.columns[orderIndexPtr]))
1571
+ orderIndex1 = orderIndexPtr;
1572
+ else break;
1573
+ }
1574
+ const indicatorX = x + cell.width - size;
1575
+ drawIndicator(indicatorX, 'l', active);
1576
+ }
1577
+ }
1578
+ //#endregion draw unhide indicator for column headers
1579
+
1580
+ //#region draw unhide indicator for row headers
1581
+ if (
1582
+ isRowHeader &&
1583
+ self.attributes.showUnhideRowsIndicator &&
1584
+ self.hiddenRowRanges.length > 0
1585
+ ) {
1586
+ // Leo's comment:
1587
+ // from the first row to the last row, `rowIndex` is from 0 to the count of rows
1588
+ // but `boundRowIndex` can be disordered if there are any ordered columns or filtered columns
1589
+ // Like this statement:
1590
+ // console.log(rowIndex, cell.boundRowIndex, cell.formattedValue);
1591
+ // can output the result like this:
1592
+ // 0 1 '2'
1593
+ // 1 3 '4'
1594
+ const hovered = self.hovers.unhideIndicator;
1595
+ const size = self.style.unhideIndicatorSize;
1596
+ const leftX = cell.x + cell.width - size - 2;
1597
+ const cellY = y;
1598
+ const topIndicators = {};
1599
+ const bottomIndicators = {};
1600
+ self.hiddenRowRanges.forEach((it) => {
1601
+ topIndicators[it[0] - 1] = it;
1602
+ bottomIndicators[it[1] + 1] = it;
1603
+ });
1604
+
1605
+ const rowIndex = cell.rowIndex + currentRowIndexOffset;
1606
+ const isActive = () =>
1607
+ hovered &&
1608
+ (hovered.dir === 't' || hovered.dir === 'b') &&
1609
+ rowIndex >= hovered.orderIndex0 - 1 &&
1610
+ rowIndex <= hovered.orderIndex1 + 1;
1611
+
1612
+ let orderIndex0, orderIndex1;
1613
+ const drawIndicator = (topY, dir, active) => {
1614
+ self.visibleUnhideIndicators.push({
1615
+ x: leftX - 1,
1616
+ y: topY - 1,
1617
+ x2: leftX + size + 2,
1618
+ y2: topY + size + 2,
1619
+ orderIndex0,
1620
+ orderIndex1,
1621
+ dir,
1622
+ });
1623
+ drawUnhideIndicator(leftX, topY, size, dir, active);
1624
+ }; // end of drawIndicator
1625
+
1626
+ let matched = topIndicators[rowIndex];
1627
+ if (matched) {
1628
+ const indicatorY = cellY + cell.height - size;
1629
+ [orderIndex0, orderIndex1] = matched;
1630
+ drawIndicator(indicatorY, 't', isActive());
1631
+ }
1632
+ matched = bottomIndicators[rowIndex];
1633
+ if (matched) {
1634
+ const indicatorY = cellY;
1635
+ [orderIndex0, orderIndex1] = matched;
1636
+ drawIndicator(indicatorY, 'b', isActive());
1637
+ }
1638
+ }
1639
+ //#endregion draw unhide indicator for row headers
1640
+
1085
1641
  x += cell.width + (bc ? 0 : self.style.cellBorderWidth);
1086
1642
  return cell.width;
1087
- };
1643
+ }; // end of drawEach
1644
+ }
1645
+ function drawFilterButton(cell, ev) {
1646
+ var posX = cell.x + cell.width - self.style.filterButtonWidth - 1;
1647
+ var posY = cell.y + cell.height - self.style.filterButtonHeight - 2;
1648
+ if (self.dispatchEvent('beforerenderfilterbutton', ev)) {
1649
+ return;
1650
+ }
1651
+ self.ctx.save();
1652
+ self.ctx.strokeStyle = self.style.filterButtonBorderColor;
1653
+ self.ctx.fillStyle = self.style.filterButtonBackgroundColor;
1654
+ if (cell.openedFilter) {
1655
+ self.ctx.fillStyle = self.style.filterButtonActiveBackgroundColor;
1656
+ } else if (cell.hovered && self.hovers.onFilterButton) {
1657
+ self.ctx.fillStyle = self.style.filterButtonHoverBackgroundColor;
1658
+ }
1659
+ radiusRect(
1660
+ posX,
1661
+ posY,
1662
+ self.style.filterButtonWidth,
1663
+ self.style.filterButtonHeight,
1664
+ self.style.filterButtonBorderRadius,
1665
+ );
1666
+ self.ctx.stroke();
1667
+ self.ctx.fill();
1668
+ drawFilterButtonArrow(posX, posY);
1669
+ self.ctx.clip();
1670
+ self.dispatchEvent('afterrenderfilterbutton', ev);
1671
+ self.ctx.restore();
1088
1672
  }
1089
- function drawRowHeader(rowData, index, rowOrderIndex) {
1090
- var a, i;
1673
+ function drawRowHeader(rowData, rowIndex, rowOrderIndex) {
1091
1674
  if (self.attributes.showRowHeaders) {
1092
1675
  x = 0;
1093
- i = index + 1;
1094
- rowHeaderCell = { rowHeaderCell: i };
1095
- a = {
1676
+
1677
+ // When filtering we'd like to display the actual row numbers,
1678
+ // as it is in the unfiltered data, instead of simply the viewed
1679
+ // row index + 1. If rowIndex > viewData.length, it's a new row
1680
+ // added to the end, and we want to render that new row's number
1681
+ let filteredRowNumber;
1682
+ if (self.viewData && rowIndex < self.viewData.length)
1683
+ filteredRowNumber =
1684
+ self.getBoundRowIndexFromViewRowIndex(rowIndex) + 1;
1685
+ else
1686
+ filteredRowNumber = self.originalData
1687
+ ? self.originalData.length + 1
1688
+ : rowOrderIndex + 1;
1689
+
1690
+ let rowHeaderValue =
1691
+ self.hasActiveFilters() || self.hasCollapsedRowGroup()
1692
+ ? filteredRowNumber
1693
+ : rowIndex + 1;
1694
+ rowHeaderValue += currentRowIndexOffset;
1695
+
1696
+ const rowHeaderCell = { rowHeaderCell: rowHeaderValue };
1697
+ const headerDescription = {
1096
1698
  name: 'rowHeaderCell',
1097
1699
  width: self.sizes.columns[-1] || self.style.rowHeaderCellWidth,
1098
1700
  style: 'rowHeaderCell',
1099
1701
  type: 'string',
1100
- data: i,
1702
+ data: rowHeaderValue,
1101
1703
  index: -1,
1102
1704
  };
1103
- rowOpen = self.openChildren[index];
1104
- drawCell(rowHeaderCell, index, rowOrderIndex)(a, -1, -1);
1705
+ rowOpen = self.openChildren[rowIndex];
1706
+ drawCell(rowHeaderCell, rowOrderIndex, rowIndex)(
1707
+ headerDescription,
1708
+ -1,
1709
+ -1,
1710
+ );
1711
+
1712
+ if (
1713
+ rowIndexOffsetByHiddenRows[0] &&
1714
+ rowHeaderValue >= rowIndexOffsetByHiddenRows[0].from
1715
+ ) {
1716
+ const { plus } = rowIndexOffsetByHiddenRows.shift();
1717
+ currentRowIndexOffset += plus;
1718
+ }
1105
1719
  }
1106
1720
  }
1107
1721
  function drawHeaders() {
1108
1722
  var d,
1109
- g = s.length,
1723
+ g = schema.length,
1110
1724
  i,
1111
1725
  o,
1112
1726
  columnHeaderCell,
@@ -1116,8 +1730,8 @@ export default function (self) {
1116
1730
  end = Math.min(end, g);
1117
1731
  for (o = start; o < end; o += 1) {
1118
1732
  i = self.orders.columns[o];
1119
- header = s[i];
1120
- if (!header.hidden) {
1733
+ header = schema[i];
1734
+ if (!header.hidden && !isColumnCollapsedByGroup(o)) {
1121
1735
  d = {
1122
1736
  title: header.title,
1123
1737
  name: header.name,
@@ -1182,7 +1796,7 @@ export default function (self) {
1182
1796
  isColumnHeaderCell: true,
1183
1797
  isColumnHeaderCellCap: true,
1184
1798
  type: 'string',
1185
- index: s.length,
1799
+ index: schema.length,
1186
1800
  };
1187
1801
  drawCell({ endCap: '' }, -1, -1)(c, -1, -1);
1188
1802
  }
@@ -1201,20 +1815,20 @@ export default function (self) {
1201
1815
  }
1202
1816
  }
1203
1817
  }
1204
- function drawRow(r, d) {
1205
- var i,
1818
+ function drawRow(rowOrderIndex, rowIndex) {
1819
+ var headerIndex,
1206
1820
  treeHeight,
1207
1821
  rowSansTreeHeight,
1208
- o,
1209
- g = s.length;
1822
+ columnOrderIndex,
1823
+ g = schema.length;
1210
1824
  if (y - cellHeight * 2 > h) {
1211
1825
  return false;
1212
1826
  }
1213
- rd = data[r];
1214
- rowOpen = self.openChildren[r];
1827
+ rowData = viewData[rowOrderIndex];
1828
+ rowOpen = self.openChildren[rowOrderIndex];
1215
1829
  rowSansTreeHeight =
1216
- (self.sizes.rows[r] || self.style.cellHeight) * self.scale;
1217
- treeHeight = (rowOpen ? self.sizes.trees[r] : 0) * self.scale;
1830
+ (self.sizes.rows[rowOrderIndex] || self.style.cellHeight) * self.scale;
1831
+ treeHeight = (rowOpen ? self.sizes.trees[rowOrderIndex] : 0) * self.scale;
1218
1832
  rowHeight = rowSansTreeHeight + treeHeight;
1219
1833
  if (y < -rowHeight) {
1220
1834
  return false;
@@ -1224,23 +1838,43 @@ export default function (self) {
1224
1838
  }
1225
1839
  cellHeight = rowHeight;
1226
1840
  //draw normal columns
1227
- for (o = self.scrollIndexLeft; o < g; o += 1) {
1228
- i = self.orders.columns[o];
1229
- x += drawCell(rd, r, d)(s[i], i, o);
1841
+ for (
1842
+ columnOrderIndex = self.scrollIndexLeft;
1843
+ columnOrderIndex < g;
1844
+ columnOrderIndex += 1
1845
+ ) {
1846
+ if (!isColumnCollapsedByGroup(columnOrderIndex)) {
1847
+ headerIndex = self.orders.columns[columnOrderIndex];
1848
+ x += drawCell(rowData, rowOrderIndex, rowIndex)(
1849
+ schema[headerIndex],
1850
+ headerIndex,
1851
+ columnOrderIndex,
1852
+ );
1853
+ }
1230
1854
  if (x > self.width) {
1231
- self.scrollIndexRight = o;
1855
+ self.scrollIndexRight = columnOrderIndex;
1232
1856
  self.scrollPixelRight = x;
1233
1857
  break;
1234
1858
  }
1235
1859
  }
1236
1860
  //draw frozen columns
1237
- x = 0;
1861
+ x = 1;
1238
1862
  if (self.attributes.showRowHeaders) {
1239
1863
  x += rowHeaderCellWidth;
1240
1864
  }
1241
- for (o = 0; o < self.frozenColumn; o += 1) {
1242
- i = self.orders.columns[o];
1243
- x += drawCell(rd, r, d)(s[i], i, o);
1865
+ for (
1866
+ columnOrderIndex = 0;
1867
+ columnOrderIndex < self.frozenColumn;
1868
+ columnOrderIndex += 1
1869
+ ) {
1870
+ if (!isColumnCollapsedByGroup(columnOrderIndex)) {
1871
+ headerIndex = self.orders.columns[columnOrderIndex];
1872
+ x += drawCell(rowData, rowOrderIndex, rowIndex)(
1873
+ schema[headerIndex],
1874
+ headerIndex,
1875
+ columnOrderIndex,
1876
+ );
1877
+ }
1244
1878
  if (x > self.width) {
1245
1879
  break;
1246
1880
  }
@@ -1253,8 +1887,8 @@ export default function (self) {
1253
1887
  self.scrollPixelLeft +
1254
1888
  self.style.cellBorderWidth;
1255
1889
  // don't draw a tree for the new row
1256
- treeGrid = self.childGrids[r];
1257
- if (r !== data.length && rowOpen) {
1890
+ treeGrid = self.childGrids[rowOrderIndex];
1891
+ if (rowOrderIndex !== viewData.length && rowOpen) {
1258
1892
  treeGrid.visible = true;
1259
1893
  treeGrid.parentNode = {
1260
1894
  offsetTop: y + rowSansTreeHeight + self.canvasOffsetTop,
@@ -1268,66 +1902,472 @@ export default function (self) {
1268
1902
  nodeType: 'canvas-datagrid-tree',
1269
1903
  scrollTop: self.scrollBox.scrollTop,
1270
1904
  scrollLeft: self.scrollBox.scrollLeft,
1271
- rowIndex: r,
1905
+ rowIndex: rowOrderIndex,
1906
+ columnGroupsAreaHeight: columnGroupsAreaHeight,
1907
+ rowGroupsAreaWidth: rowGroupsAreaWidth,
1272
1908
  };
1909
+ if (self.intf.parentNode) {
1910
+ const { columnGroupsAreaHeight, rowGroupsAreaWidth } =
1911
+ self.intf.parentNode;
1912
+ treeGrid.parentNode.columnGroupsAreaHeight +=
1913
+ columnGroupsAreaHeight || 0;
1914
+ treeGrid.parentNode.rowGroupsAreaWidth += rowGroupsAreaWidth || 0;
1915
+ }
1916
+ // Hit-test entry for the child grid's area. Like every other visible
1917
+ // cell it is in this grid's own coordinates (the child's offsetTop and
1918
+ // offsetLeft are canvas coordinates) and carries the real tree size:
1919
+ // `treeGrid.height`/`width` are undefined on child grids, which made
1920
+ // this entry unmatchable, so a pointer over a tree grid still counted
1921
+ // as hovering the parent and the parent scrolled along with the tree.
1273
1922
  self.visibleCells.unshift({
1274
- rowIndex: r,
1923
+ rowIndex: rowOrderIndex,
1275
1924
  columnIndex: 0,
1276
- y: treeGrid.parentNode.offsetTop,
1277
- x: treeGrid.parentNode.offsetLeft,
1278
- height: treeGrid.height,
1279
- width: treeGrid.width,
1925
+ y: y + rowSansTreeHeight,
1926
+ x: rowHeaderCellWidth - 1,
1927
+ height: treeHeight,
1928
+ width: treeGrid.parentNode.offsetWidth,
1280
1929
  style: 'tree-grid',
1281
1930
  type: treeGrid.parentNode.nodeType,
1931
+ data: rowData,
1932
+ header: {},
1933
+ isGrid: false,
1934
+ isNormal: false,
1935
+ isHeader: false,
1936
+ isCorner: false,
1937
+ isRowHeader: false,
1938
+ isColumnHeader: false,
1939
+ selected: false,
1940
+ hovered: false,
1282
1941
  });
1283
1942
  treeGrid.draw();
1284
1943
  } else if (treeGrid) {
1285
1944
  treeGrid.parentNode.offsetHeight = 0;
1286
- delete self.sizes.trees[r];
1945
+ delete self.sizes.trees[rowOrderIndex];
1287
1946
  }
1288
- rowHeaders.push([rd, r, d, y, rowHeight]);
1289
- self.visibleRowHeights[r] = rowHeight;
1947
+ rowHeaders.push([rowData, rowOrderIndex, rowIndex, y, rowHeight]);
1948
+ self.visibleRowHeights[rowOrderIndex] = rowHeight;
1290
1949
  y += cellHeight + (bc ? 0 : self.style.cellBorderWidth);
1291
1950
  return true;
1292
1951
  }
1293
1952
  function initDraw() {
1294
1953
  self.visibleRows = [];
1295
- s = self.getSchema();
1954
+ schema = self.getSchema();
1296
1955
  self.visibleCells = [];
1956
+ self.visibleGroups = [];
1957
+ self.visibleUnhideIndicators = [];
1297
1958
  self.canvasOffsetTop = self.isChildGrid ? self.parentNode.offsetTop : 0.5;
1298
1959
  self.canvasOffsetLeft = self.isChildGrid
1299
1960
  ? self.parentNode.offsetLeft
1300
1961
  : -0.5;
1301
1962
  h = self.height;
1302
1963
  w = self.width;
1964
+
1965
+ // patch for first row being hidden
1966
+ const firstRowIndexOffset = rowIndexOffsetByHiddenRows[0];
1967
+ if (firstRowIndexOffset && firstRowIndexOffset.from === 0) {
1968
+ currentRowIndexOffset = firstRowIndexOffset.plus;
1969
+ rowIndexOffsetByHiddenRows.shift();
1970
+ }
1303
1971
  }
1304
1972
  function drawBackground() {
1305
1973
  radiusRect(0, 0, w, h, 0);
1306
1974
  self.ctx.clip();
1975
+ self.ctx.clearRect(0, 0, w, h);
1307
1976
  self.ctx.fillStyle = self.style.gridBackgroundColor;
1308
1977
  fillRect(0, 0, w, h);
1309
1978
  }
1979
+ function initGroupArea() {
1980
+ self.ctx.translate(rowGroupsAreaWidth, columnGroupsAreaHeight);
1981
+ }
1982
+ function drawGroupArea() {
1983
+ const mx = rowGroupsAreaWidth;
1984
+ const my = columnGroupsAreaHeight;
1985
+ const frozenColumnsWidth = getFrozenColumnsWidth();
1986
+ const frozenRowsHeight =
1987
+ rowGroupsFrozenInfo.y + rowGroupsFrozenInfo.h - columnHeaderCellHeight;
1988
+ const onTheLeft = self.attributes.columnGroupIndicatorPosition === 'left';
1989
+ const onTheTop = self.attributes.rowGroupIndicatorPosition === 'top';
1990
+
1991
+ /** @type {CanvasRenderingContext2D} */
1992
+ const ctx = self.ctx;
1993
+ ctx.save();
1994
+ ctx.fillStyle = self.style.groupingAreaBackgroundColor;
1995
+ fillRect(0, -my, w, my);
1996
+ fillRect(-mx, -my, mx, h);
1997
+ ctx.restore();
1998
+
1999
+ //#region Columns Grouping
2000
+ /** it extends `self.groupedRows` */
2001
+ const groupedColumns = [];
2002
+ for (let row = 0; row < self.groupedColumns.length; row++) {
2003
+ const groups = self.groupedColumns[row];
2004
+ for (let j = 0; j < groups.length; j++) {
2005
+ groupedColumns.push(Object.assign({ row }, groups[j]));
2006
+ }
2007
+ }
2008
+ if (groupedColumns.length > 0) {
2009
+ const rowHeight = self.style.columnGroupRowHeight;
2010
+ const toggleHandleSize = rowHeight * 0.5;
2011
+ const toggleHandlePadding = (rowHeight - toggleHandleSize) * 0.5;
2012
+
2013
+ for (let i = 0; i < groupedColumns.length; i++) {
2014
+ const group = groupedColumns[i];
2015
+ const { row, collapsed } = group;
2016
+
2017
+ const topY = -my + row * rowHeight;
2018
+ const centerY = topY + rowHeight * 0.5;
2019
+ const bottomY = topY + rowHeight - toggleHandlePadding;
2020
+ const leftmostX =
2021
+ rowHeaderCellWidth - toggleHandleSize - toggleHandlePadding;
2022
+
2023
+ const drawGroupHandleAtX = (x) =>
2024
+ drawGroupHandle(
2025
+ x,
2026
+ topY + toggleHandlePadding,
2027
+ toggleHandleSize,
2028
+ group.collapsed,
2029
+ );
2030
+ const pushToVisibleGroups = (leftX, rightX) =>
2031
+ self.visibleGroups.push({
2032
+ type: 'c',
2033
+ collapsed,
2034
+ from: group.from,
2035
+ to: group.to,
2036
+ row,
2037
+ x: leftX + mx,
2038
+ y: topY + my,
2039
+ x2: rightX + mx,
2040
+ y2: bottomY + my,
2041
+ });
2042
+
2043
+ //#region check the relationship between this group and frozen columns
2044
+ const crossTheFrozen =
2045
+ group.from < self.frozenColumn && group.to >= self.frozenColumn;
2046
+ const notInFrozen = group.from >= self.frozenColumn;
2047
+ //#endregion
2048
+
2049
+ if (collapsed) {
2050
+ let leftX = leftmostX + toggleHandleSize;
2051
+ // This group is not sticking on the first column
2052
+ if (group.from > 0) {
2053
+ let colIndex = group.to + 1;
2054
+ let col = columnGroupsRectInfo[colIndex];
2055
+ if (!col) {
2056
+ colIndex = group.from - 1;
2057
+ col = columnGroupsRectInfo[colIndex];
2058
+ if (!col) continue; // don't draw this group indicator because it is invisible
2059
+ leftX = col.x + col.w - toggleHandleSize * 0.5;
2060
+ } else {
2061
+ leftX = col.x + toggleHandlePadding;
2062
+ }
2063
+ if (colIndex >= self.frozenColumn) {
2064
+ const compare =
2065
+ frozenColumnsWidth + rowHeaderCellWidth - toggleHandlePadding;
2066
+ // don't draw this group indicator because it is hidden by frozen columns
2067
+ if (leftX < compare) continue;
2068
+ }
2069
+ }
2070
+ const rightX = leftX + toggleHandleSize;
2071
+ ctx.save();
2072
+ ctx.strokeStyle = self.style.groupIndicatorColor;
2073
+ ctx.fillStyle = self.style.groupIndicatorBackgroundColor;
2074
+ drawGroupHandleAtX(leftX);
2075
+ ctx.restore();
2076
+ pushToVisibleGroups(leftX, rightX);
2077
+ } // end of collapsed group
2078
+
2079
+ /** @type {number} pointer for loop */
2080
+ let ptr;
2081
+ let left = columnGroupsRectInfo[group.from];
2082
+ let right = columnGroupsRectInfo[group.to];
2083
+
2084
+ let containsBegining = true;
2085
+ let containsEnd = true;
2086
+ ptr = group.from;
2087
+ while (!left && ptr < group.to) {
2088
+ left = columnGroupsRectInfo[++ptr];
2089
+ containsBegining = false;
2090
+ }
2091
+ ptr = group.to;
2092
+ while (!right && ptr > group.from) {
2093
+ right = columnGroupsRectInfo[--ptr];
2094
+ containsEnd = false;
2095
+ }
2096
+ if (!left || !right) continue;
2097
+ let rightX = right.x + right.w;
2098
+ let leftX = left.x;
2099
+ if (crossTheFrozen) {
2100
+ const rightCompare = columnGroupsRectInfo[self.frozenColumn - 1];
2101
+ if (rightCompare) {
2102
+ let compareX = rightCompare.x + rightCompare.w;
2103
+ if (!onTheLeft) compareX += toggleHandleSize;
2104
+ if (compareX >= rightX) {
2105
+ right = rightCompare;
2106
+ rightX = right.x + right.w;
2107
+ containsEnd = false;
2108
+ }
2109
+ }
2110
+ }
2111
+
2112
+ let minLeftX =
2113
+ rowHeaderCellWidth + (notInFrozen ? frozenColumnsWidth : 0);
2114
+ if (rightX + (onTheLeft ? 0 : toggleHandleSize) < minLeftX) continue;
2115
+
2116
+ rightX -= toggleHandlePadding;
2117
+ leftX += toggleHandlePadding;
2118
+
2119
+ ctx.save();
2120
+ ctx.strokeStyle = self.style.groupIndicatorColor;
2121
+ ctx.fillStyle = self.style.groupIndicatorBackgroundColor;
2122
+ const lineCoords = [];
2123
+
2124
+ if (onTheLeft) {
2125
+ // avoid lines from two groups be overlapping
2126
+ minLeftX += toggleHandlePadding * 2;
2127
+ if (leftX < minLeftX) leftX = minLeftX;
2128
+ if (group.from === 0) leftX -= toggleHandlePadding * 2;
2129
+ if (rightX >= leftX) {
2130
+ lineCoords.push(leftX, centerY, rightX, centerY);
2131
+ if (containsEnd) lineCoords.push(rightX, bottomY);
2132
+ } else {
2133
+ rightX = leftX;
2134
+ }
2135
+
2136
+ leftX -= toggleHandleSize;
2137
+ drawGroupHandleAtX(leftX);
2138
+ // add more clickable area into `visibleGroups`
2139
+ rightX += toggleHandlePadding - 1;
2140
+ } else {
2141
+ // handle on the right
2142
+ if (leftX < minLeftX) leftX = minLeftX;
2143
+ if (group.from === 0) leftX -= toggleHandlePadding * 2;
2144
+ if (containsEnd) {
2145
+ if (group.to === self.frozenColumn - 1) {
2146
+ rightX -= toggleHandleSize;
2147
+ } else {
2148
+ rightX += toggleHandlePadding * 2;
2149
+ }
2150
+ drawGroupHandleAtX(rightX);
2151
+ }
2152
+ if (leftX > rightX) {
2153
+ leftX = rightX;
2154
+ } else {
2155
+ if (group.from === 0) {
2156
+ containsBegining = true;
2157
+ leftX = leftmostX + toggleHandleSize;
2158
+ }
2159
+ if (containsBegining) lineCoords.push(leftX, bottomY);
2160
+ lineCoords.push(leftX, centerY, rightX, centerY);
2161
+ }
2162
+
2163
+ // add more clickable area into `visibleGroups`
2164
+ leftX -= toggleHandlePadding + 1;
2165
+ if (containsEnd) rightX += toggleHandleSize;
2166
+ }
2167
+ drawLines(lineCoords);
2168
+ ctx.restore();
2169
+ pushToVisibleGroups(leftX, rightX);
2170
+ }
2171
+ }
2172
+ //#endregion Columns Grouping
2173
+
2174
+ //#region Rows Grouping
2175
+ /** it extends `self.groupedRows` */
2176
+ const groupedRows = [];
2177
+ for (let col = 0; col < self.groupedRows.length; col++) {
2178
+ const groups = self.groupedRows[col];
2179
+ for (let j = 0; j < groups.length; j++) {
2180
+ groupedRows.push(Object.assign({ col }, groups[j]));
2181
+ }
2182
+ }
2183
+ if (groupedRows.length > 0) {
2184
+ const colWidth = self.style.rowGroupColumnWidth;
2185
+ const toggleHandleSize = colWidth * 0.5;
2186
+ const toggleHandlePadding = (colWidth - toggleHandleSize) * 0.5;
2187
+
2188
+ for (let i = 0; i < groupedRows.length; i++) {
2189
+ const group = groupedRows[i];
2190
+ const { col, collapsed } = group;
2191
+
2192
+ const leftX = -mx + col * colWidth;
2193
+ const centerX = leftX + colWidth * 0.5;
2194
+ const rightX = leftX + colWidth - toggleHandlePadding;
2195
+ const topmostY =
2196
+ columnHeaderCellHeight - toggleHandleSize - toggleHandlePadding;
2197
+
2198
+ const drawGroupHandleAtY = (y) =>
2199
+ drawGroupHandle(
2200
+ leftX + toggleHandlePadding,
2201
+ y,
2202
+ toggleHandleSize,
2203
+ group.collapsed,
2204
+ );
2205
+ const pushToVisibleGroups = (topY, bottomY) =>
2206
+ self.visibleGroups.push({
2207
+ type: 'r',
2208
+ collapsed,
2209
+ from: group.from,
2210
+ to: group.to,
2211
+ col,
2212
+ x: leftX + mx,
2213
+ y: topY + my,
2214
+ x2: rightX + mx,
2215
+ y2: bottomY + my,
2216
+ });
2217
+
2218
+ //#region check the relationship between this group and frozen columns
2219
+ const crossTheFrozen =
2220
+ group.from < self.frozenRow && group.to >= self.frozenRow;
2221
+ const notInFrozen = group.from >= self.frozenRow;
2222
+ //#endregion
2223
+
2224
+ if (collapsed) {
2225
+ let topY = topmostY + toggleHandleSize;
2226
+ // This group is not sticking on the first column
2227
+ if (group.from > 0) {
2228
+ let rowIndex = group.to + 1;
2229
+ let row = rowGroupsRectInfo[rowIndex];
2230
+ if (!row) {
2231
+ rowIndex = group.from - 1;
2232
+ row = rowGroupsRectInfo[rowIndex];
2233
+ if (!row) continue; // don't draw this group indicator because it is invisible
2234
+ topY = row.y + row.h - toggleHandleSize * 0.5;
2235
+ } else {
2236
+ topY = row.y;
2237
+ }
2238
+ if (rowIndex >= self.frozenRow) {
2239
+ const compare =
2240
+ frozenRowsHeight +
2241
+ columnHeaderCellHeight -
2242
+ toggleHandlePadding;
2243
+ // don't draw this group indicator because it is hidden by frozen columns
2244
+ if (topY < compare) continue;
2245
+ }
2246
+ }
2247
+ const bottomY = topY + toggleHandleSize;
2248
+ ctx.save();
2249
+ ctx.strokeStyle = self.style.groupIndicatorColor;
2250
+ ctx.fillStyle = self.style.groupIndicatorBackgroundColor;
2251
+ drawGroupHandleAtY(topY);
2252
+ ctx.restore();
2253
+ pushToVisibleGroups(topY, bottomY);
2254
+ } // end of collapsed group
2255
+
2256
+ /** @type {number} pointer for loop */
2257
+ let ptr;
2258
+ let top = rowGroupsRectInfo[group.from];
2259
+ let bottom = rowGroupsRectInfo[group.to];
2260
+
2261
+ let containsBegining = true;
2262
+ let containsEnd = true;
2263
+ ptr = group.from;
2264
+ while (!top && ptr < group.to) {
2265
+ top = rowGroupsRectInfo[++ptr];
2266
+ containsBegining = false;
2267
+ }
2268
+ ptr = group.to;
2269
+ while (!bottom && ptr > group.from) {
2270
+ bottom = rowGroupsRectInfo[--ptr];
2271
+ containsEnd = false;
2272
+ }
2273
+ if (!top || !bottom) continue;
2274
+ let bottomY = bottom.y + bottom.h;
2275
+ let topY = top.y;
2276
+ if (crossTheFrozen) {
2277
+ const bottomCompare = rowGroupsRectInfo[self.frozenRow - 1];
2278
+ if (bottomCompare) {
2279
+ let compareY = bottomCompare.y + bottomCompare.h;
2280
+ if (!onTheTop) compareY += toggleHandleSize;
2281
+ if (compareY >= bottomY) {
2282
+ bottom = bottomCompare;
2283
+ bottomY = bottom.y + bottom.h;
2284
+ containsEnd = false;
2285
+ }
2286
+ }
2287
+ }
2288
+
2289
+ let minTopY =
2290
+ columnHeaderCellHeight + (notInFrozen ? frozenRowsHeight : 0);
2291
+ if (bottomY + (onTheTop ? 0 : toggleHandleSize) < minTopY) continue;
2292
+
2293
+ bottomY -= toggleHandlePadding;
2294
+ topY += toggleHandlePadding;
2295
+
2296
+ ctx.save();
2297
+ ctx.strokeStyle = self.style.groupIndicatorColor;
2298
+ ctx.fillStyle = self.style.groupIndicatorBackgroundColor;
2299
+ const lineCoords = [];
2300
+
2301
+ if (onTheTop) {
2302
+ // avoid lines from two groups be overlapping
2303
+ minTopY += toggleHandlePadding * 2;
2304
+ if (topY < minTopY) topY = minTopY;
2305
+ if (group.from === 0) topY -= toggleHandlePadding * 2;
2306
+ if (bottomY >= topY) {
2307
+ lineCoords.push(centerX, topY, centerX, bottomY);
2308
+ if (containsEnd) lineCoords.push(rightX, bottomY);
2309
+ } else {
2310
+ bottomY = topY;
2311
+ }
2312
+
2313
+ topY -= toggleHandleSize;
2314
+ drawGroupHandleAtY(topY);
2315
+
2316
+ // add more clickable area into `visibleGroups`
2317
+ bottomY += toggleHandlePadding - 1;
2318
+ } else {
2319
+ // handle on the bottom
2320
+ if (topY < minTopY) topY = minTopY;
2321
+ if (group.from === 0) topY -= toggleHandlePadding * 2;
2322
+ if (containsEnd) {
2323
+ if (group.to === self.frozenRow - 1) {
2324
+ bottomY -= toggleHandleSize;
2325
+ } else {
2326
+ // bottomY += toggleHandlePadding * 2;
2327
+ }
2328
+ drawGroupHandleAtY(bottomY);
2329
+ }
2330
+ if (topY > bottomY) {
2331
+ topY = bottomY;
2332
+ } else {
2333
+ if (group.from === 0) {
2334
+ containsBegining = true;
2335
+ topY = topmostY + toggleHandleSize;
2336
+ }
2337
+ if (containsBegining) lineCoords.push(rightX, topY);
2338
+ lineCoords.push(centerX, topY, centerX, bottomY);
2339
+ // add more clickable area into `visibleGroups`
2340
+ topY -= toggleHandlePadding + 1;
2341
+ }
2342
+ // add more clickable area into `visibleGroups`
2343
+ if (containsEnd) bottomY += toggleHandleSize;
2344
+ }
2345
+ drawLines(lineCoords);
2346
+ ctx.restore();
2347
+ pushToVisibleGroups(topY, bottomY);
2348
+ }
2349
+ }
2350
+ //#endregion Rows Grouping
2351
+ }
1310
2352
  function drawFrozenRows() {
1311
- var n,
1312
- ln = Math.min(data.length, self.frozenRow);
2353
+ var rowOrderIndex,
2354
+ ln = Math.min(viewData.length, self.frozenRow);
1313
2355
  x =
1314
2356
  -self.scrollBox.scrollLeft +
1315
2357
  self.scrollPixelLeft +
1316
2358
  self.style.cellBorderWidth;
1317
2359
  y = columnHeaderCellHeight;
1318
- for (r = 0; r < ln; r += 1) {
1319
- n = self.orders.rows[r];
1320
- if (!drawRow(n, r)) {
2360
+ for (rowIndex = 0; rowIndex < ln; rowIndex += 1) {
2361
+ rowOrderIndex = self.orders.rows[rowIndex];
2362
+ if (!drawRow(rowOrderIndex, rowIndex)) {
1321
2363
  break;
1322
2364
  }
1323
2365
  }
1324
2366
  if (self.attributes.allowFreezingRows) {
1325
2367
  // HACK great, another stupid magic number.
1326
2368
  // Background will appear as a 0.5px artifact behind the row freeze bar without this hack
1327
- y +=
1328
- self.style.frozenMarkerBorderWidth +
1329
- self.style.frozenMarkerWidth -
1330
- 0.4999999999;
2369
+ if (y > columnHeaderCellHeight) y += self.style.frozenMarkerWidth;
2370
+ y += self.style.frozenMarkerBorderWidth - 0.4999999999;
1331
2371
  }
1332
2372
  self.lastFrozenRowPixel = y;
1333
2373
  }
@@ -1343,10 +2383,10 @@ export default function (self) {
1343
2383
  );
1344
2384
  self.ctx.clip();
1345
2385
  }
1346
- var o,
1347
- n,
1348
- i,
1349
- g = s.length;
2386
+ var columnOrderIndex,
2387
+ rowOrderIndex,
2388
+ headerIndex,
2389
+ g = schema.length;
1350
2390
  x =
1351
2391
  -self.scrollBox.scrollLeft +
1352
2392
  self.scrollPixelLeft +
@@ -1357,11 +2397,21 @@ export default function (self) {
1357
2397
  self.scrollPixelTop +
1358
2398
  self.style.cellBorderWidth;
1359
2399
  }
1360
- for (r = self.frozenRow + self.scrollIndexTop; r < l; r += 1) {
1361
- n = self.orders.rows[r];
1362
- self.scrollIndexBottom = r;
2400
+ for (
2401
+ rowIndex = self.frozenRow + self.scrollIndexTop;
2402
+ rowIndex < l;
2403
+ rowIndex += 1
2404
+ ) {
2405
+ rowOrderIndex = self.orders.rows[rowIndex];
2406
+ self.scrollIndexBottom = rowIndex;
1363
2407
  self.scrollPixelBottom = y;
1364
- if (!drawRow(n, r)) {
2408
+ if (
2409
+ self.cellTree.rows.length > 0 &&
2410
+ Object.keys(self.cellTree.rows[rowOrderIndex]).length > 0 &&
2411
+ self.cellTree.rows[rowOrderIndex].hide
2412
+ )
2413
+ continue;
2414
+ if (!drawRow(rowOrderIndex, rowIndex)) {
1365
2415
  break;
1366
2416
  }
1367
2417
  }
@@ -1371,14 +2421,30 @@ export default function (self) {
1371
2421
  }
1372
2422
  rowHeight = cellHeight = self.style.cellHeight;
1373
2423
  rowOpen = false;
1374
- for (o = self.scrollIndexLeft; o < g; o += 1) {
1375
- i = self.orders.columns[o];
1376
- x += drawCell(self.newRow, data.length, data.length)(s[i], i, o);
2424
+ for (
2425
+ columnOrderIndex = self.scrollIndexLeft;
2426
+ columnOrderIndex < g;
2427
+ columnOrderIndex += 1
2428
+ ) {
2429
+ if (!isColumnCollapsedByGroup(columnOrderIndex)) {
2430
+ headerIndex = self.orders.columns[columnOrderIndex];
2431
+ x += drawCell(self.newRow, viewData.length, viewData.length)(
2432
+ schema[headerIndex],
2433
+ headerIndex,
2434
+ columnOrderIndex,
2435
+ );
2436
+ }
1377
2437
  if (x > self.width + self.scrollBox.scrollLeft) {
1378
2438
  break;
1379
2439
  }
1380
2440
  }
1381
- rowHeaders.push([self.newRow, data.length, data.length, y, rowHeight]);
2441
+ rowHeaders.push([
2442
+ self.newRow,
2443
+ viewData.length,
2444
+ viewData.length,
2445
+ y,
2446
+ rowHeight,
2447
+ ]);
1382
2448
  }
1383
2449
  self.ctx.restore();
1384
2450
  }
@@ -1414,6 +2480,7 @@ export default function (self) {
1414
2480
  self.ctx.lineWidth = self.style.reorderMarkerBorderWidth;
1415
2481
  self.ctx.strokeStyle = self.style.reorderMarkerBorderColor;
1416
2482
  if (self.dragMode === 'row-reorder') {
2483
+ b.height = self.getSelectedRowsHeight();
1417
2484
  b.width = w;
1418
2485
  b.x = 0;
1419
2486
  m.width = w;
@@ -1424,6 +2491,7 @@ export default function (self) {
1424
2491
  self.ctx.lineWidth = self.style.reorderMarkerIndexBorderWidth;
1425
2492
  self.ctx.strokeStyle = self.style.reorderMarkerIndexBorderColor;
1426
2493
  if (
2494
+ !self.isRowSelected(self.reorderTarget.sortRowIndex) &&
1427
2495
  self.currentCell.rowIndex !== self.reorderObject.rowIndex &&
1428
2496
  self.currentCell.rowIndex > -1 &&
1429
2497
  self.currentCell.rowIndex < l
@@ -1436,6 +2504,7 @@ export default function (self) {
1436
2504
  );
1437
2505
  }
1438
2506
  } else if (self.dragMode === 'column-reorder' && self.reorderObject) {
2507
+ b.width = self.getSelectedColumnsWidth();
1439
2508
  b.height = h;
1440
2509
  b.y = 0;
1441
2510
  m.height = h;
@@ -1447,10 +2516,12 @@ export default function (self) {
1447
2516
  self.ctx.lineWidth = self.style.reorderMarkerIndexBorderWidth;
1448
2517
  self.ctx.strokeStyle = self.style.reorderMarkerIndexBorderColor;
1449
2518
  if (
2519
+ !self.isColumnSelected(self.reorderTarget.sortColumnIndex) &&
1450
2520
  self.currentCell.sortColumnIndex !==
1451
2521
  self.reorderObject.sortColumnIndex &&
2522
+ self.reorderTarget.columnIndex !== self.reorderObject.columnIndex &&
1452
2523
  self.currentCell.sortColumnIndex > -1 &&
1453
- self.currentCell.sortColumnIndex < s.length
2524
+ self.currentCell.sortColumnIndex < schema.length
1454
2525
  ) {
1455
2526
  addBorderLine(
1456
2527
  m,
@@ -1461,16 +2532,43 @@ export default function (self) {
1461
2532
  }
1462
2533
  }
1463
2534
  }
2535
+ function drawResizeMarkers() {
2536
+ if (
2537
+ !self.attributes.resizeAfterDragged ||
2538
+ !self.draggingItem ||
2539
+ !self.pendingDragResize ||
2540
+ (self.dragMode != 'ew-resize' && self.dragMode != 'ns-resize')
2541
+ ) {
2542
+ return;
2543
+ }
2544
+
2545
+ const resizingRow = self.dragMode == 'ns-resize';
2546
+ const height = resizingRow ? self.style.resizeMarkerSize : self.height;
2547
+ const width = resizingRow ? self.width : self.style.resizeMarkerSize;
2548
+ const minX =
2549
+ self.dragStart.x -
2550
+ (self.resizingStartingWidth - self.style.minColumnWidth);
2551
+ const minY =
2552
+ self.dragStart.y -
2553
+ (self.resizingStartingHeight - self.style.minRowHeight);
2554
+ const x = resizingRow ? 0 : Math.max(self.pendingDragResize.x, minX);
2555
+ const y = !resizingRow ? 0 : Math.max(self.pendingDragResize.y, minY);
2556
+
2557
+ self.ctx.fillStyle = self.style.resizeMarkerColor;
2558
+ fillRect(x, y, width, height);
2559
+ }
1464
2560
  function drawBorder() {
1465
2561
  self.ctx.lineWidth = self.style.gridBorderWidth;
1466
2562
  self.ctx.strokeStyle = self.style.gridBorderColor;
1467
2563
  strokeRect(0, 0, self.width, self.height);
1468
2564
  }
1469
2565
  function drawSelectionBorders() {
1470
- self.ctx.lineWidth = self.style.selectionOverlayBorderWidth;
1471
- self.ctx.strokeStyle = self.style.selectionOverlayBorderColor;
1472
2566
  function dsb(c) {
1473
- addBorderLine(c[0], c[1]);
2567
+ if (!self.fillOverlay.handle) {
2568
+ self.ctx.lineWidth = self.style.selectionOverlayBorderWidth;
2569
+ self.ctx.strokeStyle = self.style.selectionOverlayBorderColor;
2570
+ addBorderLine(c[0], c[1]);
2571
+ }
1474
2572
  }
1475
2573
  selectionBorders
1476
2574
  .filter(function (c) {
@@ -1513,9 +2611,14 @@ export default function (self) {
1513
2611
  })
1514
2612
  .forEach(dsb);
1515
2613
  self.ctx.restore();
2614
+
2615
+ drawFillOverlay();
1516
2616
  }
1517
2617
  function drawSelectionHandles() {
1518
- if (self.mobile || self.attributes.allowMovingSelection) {
2618
+ if (
2619
+ (self.mobile || self.attributes.allowMovingSelection) &&
2620
+ self.attributes.editable
2621
+ ) {
1519
2622
  self.ctx.lineWidth = self.style.selectionHandleBorderWidth;
1520
2623
  self.ctx.strokeStyle = self.style.selectionHandleBorderColor;
1521
2624
  self.ctx.fillStyle = self.style.selectionHandleColor;
@@ -1536,6 +2639,62 @@ export default function (self) {
1536
2639
  });
1537
2640
  }
1538
2641
  }
2642
+ function drawFillOverlay() {
2643
+ if (!self.fillOverlay.handle || !self.fillOverlay.snapTo) {
2644
+ return;
2645
+ }
2646
+
2647
+ self.ctx.save();
2648
+
2649
+ const overlay = self.fillOverlay;
2650
+ const handle = overlay.handle;
2651
+ const toX = overlay.snapTo.x;
2652
+ const toY = overlay.snapTo.y;
2653
+
2654
+ // The cell that the cursor is moving over. This may be unavailable
2655
+ // when the cursor is outside the grid or is pointing to something else.
2656
+ //
2657
+ // When unavailable, we use the actual position of the cursor to draw
2658
+ // the overlay.
2659
+ const snap = overlay.snap;
2660
+
2661
+ // Calculate the X, Y coordinates of the cursor with snap positions and
2662
+ // the direction of the movement in mind.
2663
+ //
2664
+ // When the movement is horizontal, we get the Y coordinate from the handle,
2665
+ // and vice-versa.
2666
+ const cursorX =
2667
+ overlay.direction === 'x'
2668
+ ? snap
2669
+ ? snap.x + (overlay.x < toX ? 0 : snap.width)
2670
+ : overlay.x
2671
+ : handle.x;
2672
+ const cursorY =
2673
+ overlay.direction === undefined || overlay.direction === 'y'
2674
+ ? snap
2675
+ ? snap.y + (overlay.y < toY ? 0 : snap.height)
2676
+ : overlay.y
2677
+ : handle.y;
2678
+
2679
+ // The final coordinates of the rect. We use 'minX' and 'minY' to avoid
2680
+ // drawing on the frozen area.
2681
+ const x = Math.max(Math.min(toX, cursorX), overlay.minX);
2682
+ const y = Math.max(Math.min(toY, cursorY), overlay.minY);
2683
+
2684
+ // Width and height of the rect are the difference between the
2685
+ // coordinates of both the rect and the cursor. The user may be pointing
2686
+ // behind and/or upwards of the rect, so we need to take that into
2687
+ // account.
2688
+ const width = Math.max(toX, cursorX) - x;
2689
+ const height = Math.max(toY, cursorY) - y;
2690
+
2691
+ self.ctx.strokeStyle = self.style.fillOverlayBorderColor;
2692
+ self.ctx.lineWidth = self.style.fillOverlayBorderWidth;
2693
+ self.ctx.setLineDash([3, 3]);
2694
+ strokeRect(x, y, width, height);
2695
+ self.ctx.setLineDash([]);
2696
+ self.ctx.restore();
2697
+ }
1539
2698
  function drawActiveCell() {
1540
2699
  if (!aCell) {
1541
2700
  return;
@@ -1570,77 +2729,171 @@ export default function (self) {
1570
2729
  }
1571
2730
  function drawFrozenMarkers() {
1572
2731
  var my = self.lastFrozenRowPixel - self.style.frozenMarkerWidth,
1573
- mx = self.lastFrozenColumnPixel - self.style.frozenMarkerBorderWidth,
2732
+ mx = self.lastFrozenColumnPixel - self.style.frozenMarkerWidth,
1574
2733
  xHover =
1575
2734
  self.currentCell && self.currentCell.style === 'frozen-row-marker',
1576
2735
  yHover =
1577
2736
  self.currentCell && self.currentCell.style === 'frozen-column-marker';
2737
+ let rowHeaderCellWidth = self.getRowHeaderCellWidth();
1578
2738
  self.ctx.lineWidth = self.style.frozenMarkerBorderWidth;
1579
2739
  if (self.attributes.allowFreezingColumns) {
1580
- self.ctx.fillStyle = yHover
1581
- ? self.style.frozenMarkerHoverColor
1582
- : self.style.frozenMarkerColor;
1583
- self.ctx.strokeStyle = yHover
1584
- ? self.style.frozenMarkerHoverBorderColor
1585
- : self.style.frozenMarkerBorderColor;
1586
- fillRect(mx, 0, self.style.frozenMarkerWidth, self.height);
1587
- strokeRect(mx, 0, self.style.frozenMarkerWidth, self.height);
1588
- self.visibleCells.unshift({
1589
- x: mx,
1590
- y: 0,
1591
- height: self.height,
1592
- width:
1593
- self.style.frozenMarkerWidth + self.style.frozenMarkerBorderWidth,
1594
- style: 'frozen-column-marker',
1595
- });
1596
- }
1597
- if (self.attributes.allowFreezingRows) {
1598
- self.ctx.fillStyle = xHover
1599
- ? self.style.frozenMarkerHoverColor
1600
- : self.style.frozenMarkerColor;
1601
- self.ctx.strokeStyle = xHover
1602
- ? self.style.frozenMarkerHoverBorderColor
1603
- : self.style.frozenMarkerBorderColor;
1604
- fillRect(0, my, self.width, self.style.frozenMarkerWidth);
1605
- strokeRect(0, my, self.width, self.style.frozenMarkerWidth);
1606
- self.visibleCells.unshift({
1607
- x: 0,
1608
- y: my,
1609
- height:
1610
- self.style.frozenMarkerWidth + self.style.frozenMarkerBorderWidth,
1611
- width: self.width,
1612
- style: 'frozen-row-marker',
1613
- });
1614
- }
1615
- if (self.freezeMarkerPosition) {
1616
- self.ctx.fillStyle = self.style.frozenMarkerActiveColor;
1617
- self.ctx.strokeStyle = self.style.frozenMarkerActiveBorderColor;
1618
- if (self.dragMode === 'frozen-column-marker') {
2740
+ if (
2741
+ !self.freezeMarkerPosition ||
2742
+ (self.freezeMarkerPosition && self.dragMode === 'frozen-row-marker')
2743
+ ) {
2744
+ if (mx > self.style.rowHeaderCellWidth) {
2745
+ self.ctx.fillStyle = self.style.frozenMarkerColor;
2746
+ self.ctx.strokeStyle = self.style.frozenMarkerBorderColor;
2747
+ fillRect(mx, 0, self.style.frozenMarkerWidth, self.height);
2748
+ strokeRect(mx, 0, self.style.frozenMarkerWidth, self.height);
2749
+ }
2750
+ self.ctx.fillStyle = yHover
2751
+ ? self.style.frozenMarkerHoverColor
2752
+ : self.style.frozenMarkerHeaderColor;
2753
+ self.ctx.strokeStyle = yHover
2754
+ ? self.style.frozenMarkerHoverBorderColor
2755
+ : self.style.frozenMarkerHeaderColor;
1619
2756
  fillRect(
1620
- self.freezeMarkerPosition.x,
2757
+ mx,
1621
2758
  0,
1622
2759
  self.style.frozenMarkerWidth,
1623
- self.height,
2760
+ self.style.columnHeaderCellHeight,
1624
2761
  );
1625
2762
  strokeRect(
1626
- self.freezeMarkerPosition.x,
2763
+ mx,
1627
2764
  0,
1628
2765
  self.style.frozenMarkerWidth,
1629
- self.height,
2766
+ self.style.columnHeaderCellHeight,
1630
2767
  );
1631
- } else {
2768
+ }
2769
+
2770
+ if (
2771
+ !self.dragStartObject ||
2772
+ (self.dragStartObject &&
2773
+ self.dragStartObject.style !== 'rowHeaderCell')
2774
+ ) {
2775
+ self.visibleCells.unshift({
2776
+ x: mx,
2777
+ y: 0,
2778
+ height: self.height,
2779
+ width: self.style.frozenMarkerWidth, // + self.style.frozenMarkerBorderWidth,
2780
+ style: 'frozen-column-marker',
2781
+ });
2782
+ }
2783
+ }
2784
+ if (self.attributes.allowFreezingRows) {
2785
+ if (
2786
+ !self.freezeMarkerPosition ||
2787
+ (self.freezeMarkerPosition &&
2788
+ self.dragMode === 'frozen-column-marker')
2789
+ ) {
2790
+ if (my > rowHeaderCellWidth) {
2791
+ self.ctx.fillStyle = self.style.frozenMarkerColor;
2792
+ self.ctx.strokeStyle = self.style.frozenMarkerBorderColor;
2793
+ fillRect(0, my, self.width, self.style.frozenMarkerWidth);
2794
+ strokeRect(0, my, self.width, self.style.frozenMarkerWidth);
2795
+ }
2796
+ self.ctx.fillStyle = xHover
2797
+ ? self.style.frozenMarkerHoverColor
2798
+ : self.style.frozenMarkerHeaderColor;
2799
+ self.ctx.strokeStyle = xHover
2800
+ ? self.style.frozenMarkerHoverBorderColor
2801
+ : self.style.frozenMarkerHeaderColor;
2802
+ fillRect(0, my, rowHeaderCellWidth, self.style.frozenMarkerWidth);
2803
+ strokeRect(0, my, rowHeaderCellWidth, self.style.frozenMarkerWidth);
2804
+ }
2805
+ var height =
2806
+ self.style.frozenMarkerWidth + self.style.frozenMarkerBorderWidth;
2807
+ if (
2808
+ !self.dragStartObject ||
2809
+ (self.dragStartObject &&
2810
+ self.dragStartObject.style !== 'columnHeaderCell')
2811
+ ) {
2812
+ self.visibleCells.unshift({
2813
+ x: 0,
2814
+ y: my,
2815
+ height: height,
2816
+ width: self.width,
2817
+ style: 'frozen-row-marker',
2818
+ });
2819
+ }
2820
+ rowGroupsFrozenInfo = { y: my, h: height };
2821
+ }
2822
+ if (self.freezeMarkerPosition) {
2823
+ self.ctx.fillStyle = self.style.frozenMarkerActiveColor;
2824
+ self.ctx.strokeStyle = self.style.frozenMarkerActiveBorderColor;
2825
+ if (self.dragMode === 'frozen-column-marker') {
2826
+ let posX = self.freezeMarkerPosition.x;
2827
+ let nearCell = self.getCellAt(posX, 0);
2828
+ if (self.freezeMarkerPosition.isGrab) posX = mx;
2829
+ if (posX > rowHeaderCellWidth) {
2830
+ let x =
2831
+ nearCell.x -
2832
+ self.style.frozenMarkerWidth -
2833
+ self.style.frozenMarkerBorderWidth;
2834
+ if (posX > x + nearCell.width / 2) x = x + nearCell.width;
2835
+ self.ctx.fillStyle = self.style.frozenMarkerColor;
2836
+ self.ctx.strokeStyle = self.style.frozenMarkerBorderColor;
2837
+ fillRect(x, 0, self.style.frozenMarkerWidth, self.height);
2838
+ strokeRect(x, 0, self.style.frozenMarkerWidth, self.height);
2839
+ self.ctx.fillStyle = self.style.frozenMarkerHeaderColor;
2840
+ self.ctx.strokeStyle = self.style.frozenMarkerHeaderColor;
2841
+ fillRect(
2842
+ x,
2843
+ 0,
2844
+ self.style.frozenMarkerWidth,
2845
+ self.style.columnHeaderCellHeight,
2846
+ );
2847
+ strokeRect(
2848
+ x,
2849
+ 0,
2850
+ self.style.frozenMarkerWidth,
2851
+ self.style.columnHeaderCellHeight,
2852
+ );
2853
+ }
2854
+ self.ctx.fillStyle = self.style.frozenMarkerActiveHeaderColor;
2855
+ self.ctx.strokeStyle = self.style.frozenMarkerActiveBorderColor;
1632
2856
  fillRect(
2857
+ posX,
1633
2858
  0,
1634
- self.freezeMarkerPosition.y,
1635
- self.width,
1636
2859
  self.style.frozenMarkerWidth,
2860
+ self.style.columnHeaderCellHeight,
1637
2861
  );
1638
2862
  strokeRect(
2863
+ posX,
1639
2864
  0,
1640
- self.freezeMarkerPosition.y,
1641
- self.width,
1642
2865
  self.style.frozenMarkerWidth,
2866
+ self.style.columnHeaderCellHeight,
1643
2867
  );
2868
+ self.ctx.fillStyle = self.style.frozenMarkerActiveColor;
2869
+ fillRect(posX, 0, self.style.frozenMarkerWidth, self.height);
2870
+ strokeRect(posX, 0, self.style.frozenMarkerWidth, self.height);
2871
+ } else {
2872
+ let posY = self.freezeMarkerPosition.y;
2873
+ let nearCell = self.getCellAt(0, posY);
2874
+ if (self.freezeMarkerPosition.isGrab) posY = my;
2875
+ if (posY > self.style.columnHeaderCellHeight) {
2876
+ let y =
2877
+ nearCell.y -
2878
+ self.style.frozenMarkerWidth -
2879
+ self.style.frozenMarkerBorderWidth;
2880
+ if (posY > y + nearCell.height / 2) y = y + nearCell.height;
2881
+ self.ctx.fillStyle = self.style.frozenMarkerColor;
2882
+ self.ctx.strokeStyle = self.style.frozenMarkerBorderColor;
2883
+ fillRect(0, y, self.width, self.style.frozenMarkerWidth);
2884
+ strokeRect(0, y, self.width, self.style.frozenMarkerWidth);
2885
+ self.ctx.fillStyle = self.style.frozenMarkerHeaderColor;
2886
+ self.ctx.strokeStyle = self.style.frozenMarkerHeaderColor;
2887
+ fillRect(0, y, rowHeaderCellWidth, self.style.frozenMarkerWidth);
2888
+ strokeRect(0, y, rowHeaderCellWidth, self.style.frozenMarkerWidth);
2889
+ }
2890
+ self.ctx.fillStyle = self.style.frozenMarkerActiveHeaderColor;
2891
+ self.ctx.strokeStyle = self.style.frozenMarkerActiveBorderColor;
2892
+ fillRect(0, posY, rowHeaderCellWidth, self.style.frozenMarkerWidth);
2893
+ strokeRect(0, posY, rowHeaderCellWidth, self.style.frozenMarkerWidth);
2894
+ self.ctx.fillStyle = self.style.frozenMarkerActiveColor;
2895
+ fillRect(0, posY, self.width, self.style.frozenMarkerWidth);
2896
+ strokeRect(0, posY, self.width, self.style.frozenMarkerWidth);
1644
2897
  }
1645
2898
  }
1646
2899
  }
@@ -1849,6 +3102,7 @@ export default function (self) {
1849
3102
  self.ctx.save();
1850
3103
  initDraw();
1851
3104
  drawBackground();
3105
+ initGroupArea();
1852
3106
  drawFrozenRows();
1853
3107
  drawRows();
1854
3108
  drawActiveCell();
@@ -1857,12 +3111,14 @@ export default function (self) {
1857
3111
  drawSelectionHandles();
1858
3112
  drawReorderMarkers();
1859
3113
  drawMoveMarkers();
3114
+ drawResizeMarkers();
1860
3115
  drawBorder();
1861
3116
  drawSelectionBorders();
1862
3117
  drawScrollBars();
1863
3118
  if (checkScrollHeight) {
1864
3119
  self.resize(true);
1865
3120
  }
3121
+ drawGroupArea();
1866
3122
  drawDebug();
1867
3123
  drawPerfLines();
1868
3124
  if (self.dispatchEvent('afterdraw', {})) {