canvas-datagrid 0.3.18 → 0.3.22

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
@@ -164,6 +164,34 @@ export default function (self) {
164
164
  self.ctx.fill();
165
165
  return ml + aw + mr;
166
166
  }
167
+ function drawFilterButtonArrow(x, y) {
168
+ var mt =
169
+ ((self.style.filterButtonHeight - self.style.filterButtonArrowHeight) /
170
+ 2) *
171
+ self.scale,
172
+ ml =
173
+ ((self.style.filterButtonWidth - self.style.filterButtonArrowWidth) /
174
+ 2) *
175
+ self.scale,
176
+ aw = self.style.filterButtonArrowWidth * self.scale,
177
+ ah = self.style.filterButtonArrowHeight * self.scale;
178
+ x += self.canvasOffsetLeft;
179
+ y += self.canvasOffsetTop;
180
+ self.ctx.fillStyle = self.style.filterButtonArrowColor;
181
+ self.ctx.strokeStyle = self.style.filterButtonArrowBorderColor;
182
+ self.ctx.beginPath();
183
+ x = x + ml;
184
+ y = y + mt;
185
+
186
+ self.ctx.moveTo(x, y);
187
+ self.ctx.lineTo(x + aw, y);
188
+ self.ctx.lineTo(x + aw * 0.5, y + ah);
189
+ self.ctx.moveTo(x, y);
190
+
191
+ self.ctx.stroke();
192
+ self.ctx.fill();
193
+ return ml + aw;
194
+ }
167
195
  function radiusRect(x, y, w, h, radius) {
168
196
  x += self.canvasOffsetLeft;
169
197
  y += self.canvasOffsetTop;
@@ -601,15 +629,29 @@ export default function (self) {
601
629
  m = self.style.scrollBarBoxMargin * 2;
602
630
  self.ctx.strokeStyle = self.style.scrollBarBorderColor;
603
631
  self.ctx.lineWidth = self.style.scrollBarBorderWidth;
604
- en.horizontalBox.x =
605
- rowHeaderCellWidth +
606
- self.style.scrollBarBoxMargin +
607
- (en.horizontalBar.width - self.scrollBox.scrollBoxWidth) *
608
- (self.scrollBox.scrollLeft / self.scrollBox.scrollWidth);
632
+ if (self.frozenColumn > 0) {
633
+ en.horizontalBox.x =
634
+ rowHeaderCellWidth +
635
+ self.style.scrollBarBoxMargin +
636
+ self.scrollCache.x[self.frozenColumn - 1] +
637
+ (en.horizontalBar.width -
638
+ self.scrollCache.x[self.frozenColumn - 1] -
639
+ self.scrollBox.scrollBoxWidth) *
640
+ (self.scrollBox.scrollLeft / self.scrollBox.scrollWidth);
641
+ } else {
642
+ en.horizontalBox.x =
643
+ rowHeaderCellWidth +
644
+ self.style.scrollBarBoxMargin +
645
+ (en.horizontalBar.width - self.scrollBox.scrollBoxWidth) *
646
+ (self.scrollBox.scrollLeft / self.scrollBox.scrollWidth);
647
+ }
609
648
  en.verticalBox.y =
610
649
  columnHeaderCellHeight +
611
650
  self.style.scrollBarBoxMargin +
612
- (en.verticalBar.height - self.scrollBox.scrollBoxHeight) *
651
+ self.scrollCache.y[self.frozenRow] +
652
+ (en.verticalBar.height -
653
+ self.scrollBox.scrollBoxHeight -
654
+ self.scrollCache.y[self.frozenRow]) *
613
655
  (self.scrollBox.scrollTop / self.scrollBox.scrollHeight);
614
656
  if (self.scrollBox.horizontalBarVisible) {
615
657
  self.ctx.fillStyle = self.style.scrollBarBackgroundColor;
@@ -802,6 +844,9 @@ export default function (self) {
802
844
  isCorner = /cornerCell/.test(cellStyle),
803
845
  isRowHeader = 'rowHeaderCell' === cellStyle,
804
846
  isColumnHeader = 'columnHeaderCell' === cellStyle,
847
+ isFilterable =
848
+ self.filterable.rows.includes(rowIndex) &&
849
+ self.filterable.columns.includes(headerIndex),
805
850
  wrap = self.style.cellWhiteSpace !== 'nowrap',
806
851
  selected =
807
852
  self.selections[rowOrderIndex] &&
@@ -810,6 +855,9 @@ export default function (self) {
810
855
  self.hovers.rowIndex === rowOrderIndex &&
811
856
  (self.attributes.hoverMode === 'row' ||
812
857
  self.hovers.columnIndex === columnOrderIndex),
858
+ openedFilter =
859
+ self.selectedFilterButton.rowIndex == rowIndex &&
860
+ self.selectedFilterButton.columnIndex == headerIndex,
813
861
  active =
814
862
  self.activeCell.rowIndex === rowOrderIndex &&
815
863
  self.activeCell.columnIndex === columnOrderIndex,
@@ -901,6 +949,8 @@ export default function (self) {
901
949
  isColumnHeader: isColumnHeader,
902
950
  isColumnHeaderCellCap: isColumnHeaderCellCap,
903
951
  isRowHeader: isRowHeader,
952
+ isFilterable: isFilterable,
953
+ openedFilter: openedFilter,
904
954
  rowOpen: rowOpen,
905
955
  header: header,
906
956
 
@@ -1100,6 +1150,10 @@ export default function (self) {
1100
1150
  }
1101
1151
  self.ctx.restore();
1102
1152
 
1153
+ if (isFilterable) {
1154
+ drawFilterButton(cell);
1155
+ }
1156
+
1103
1157
  // Gaps may occur in row numbers between consecutively rendered rows
1104
1158
  // when we are filtering. We draw attention to this by drawing a thick
1105
1159
  // border overlapping the two consecutive row headers. If sorting, visible
@@ -1140,6 +1194,34 @@ export default function (self) {
1140
1194
  return cell.width;
1141
1195
  };
1142
1196
  }
1197
+ function drawFilterButton(cell, ev) {
1198
+ var posX = cell.x + cell.width - self.style.filterButtonWidth - 1;
1199
+ var posY = cell.y + cell.height - self.style.filterButtonHeight - 2;
1200
+ if (self.dispatchEvent('beforerenderfilterbutton', ev)) {
1201
+ return;
1202
+ }
1203
+ self.ctx.save();
1204
+ self.ctx.strokeStyle = self.style.filterButtonBorderColor;
1205
+ self.ctx.fillStyle = self.style.filterButtonBackgroundColor;
1206
+ if (cell.openedFilter) {
1207
+ self.ctx.fillStyle = self.style.filterButtonActiveBackgroundColor;
1208
+ } else if (cell.hovered && self.hovers.onFilterButton) {
1209
+ self.ctx.fillStyle = self.style.filterButtonHoverBackgroundColor;
1210
+ }
1211
+ radiusRect(
1212
+ posX,
1213
+ posY,
1214
+ self.style.filterButtonWidth,
1215
+ self.style.filterButtonHeight,
1216
+ self.style.filterButtonBorderRadius,
1217
+ );
1218
+ self.ctx.stroke();
1219
+ self.ctx.fill();
1220
+ drawFilterButtonArrow(posX, posY);
1221
+ self.ctx.clip();
1222
+ self.dispatchEvent('afterrenderfilterbutton', ev);
1223
+ self.ctx.restore();
1224
+ }
1143
1225
  function drawRowHeader(rowData, rowIndex, rowOrderIndex) {
1144
1226
  if (self.attributes.showRowHeaders) {
1145
1227
  x = 0;
@@ -1520,6 +1602,10 @@ export default function (self) {
1520
1602
  self.ctx.lineWidth = self.style.reorderMarkerBorderWidth;
1521
1603
  self.ctx.strokeStyle = self.style.reorderMarkerBorderColor;
1522
1604
  if (self.dragMode === 'row-reorder') {
1605
+ for (var k = 0; k < self.selections.length; k++) {
1606
+ if (!self.selections[k] || k == self.reorderObject.rowIndex) continue;
1607
+ b.height += self.getRowHeight(k);
1608
+ }
1523
1609
  b.width = w;
1524
1610
  b.x = 0;
1525
1611
  m.width = w;
@@ -1542,6 +1628,12 @@ export default function (self) {
1542
1628
  );
1543
1629
  }
1544
1630
  } else if (self.dragMode === 'column-reorder' && self.reorderObject) {
1631
+ var selectedColumns = self.selections[0];
1632
+ for (var k = 1; k < selectedColumns.length; k++) {
1633
+ b.width += self.getColumnWidth(
1634
+ self.orders.columns[selectedColumns[k]],
1635
+ );
1636
+ }
1545
1637
  b.height = h;
1546
1638
  b.y = 0;
1547
1639
  m.height = h;