Skip to content

Commit 21e8f80

Browse files
committed
Added cursor effects to hypergrid tree column hover, and limit click event to tree toggle switch.
1 parent f12937d commit 21e8f80

File tree

1 file changed

+43
-3
lines changed

1 file changed

+43
-3
lines changed

packages/perspective-viewer-hypergrid/src/js/perspective-plugin.js

Lines changed: 43 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -339,6 +339,38 @@ export const install = function(grid) {
339339
);
340340
});
341341

342+
Object.getPrototypeOf(grid.behavior).getCursorAt = function(x, y, event) {
343+
const rp_len = this.dataModel.data[y - 1]?.[-1]?.rowPath?.length;
344+
const is_select = !!this.grid.properties.rowSelection;
345+
if (is_select) {
346+
if (x === -1 && rp_len <= this.dataModel._config.row_pivots.length && event?.gridPoint.x <= rp_len * 15 + 10) {
347+
return "pointer";
348+
}
349+
} else {
350+
if (x === -1 && rp_len <= this.dataModel._config.row_pivots.length) {
351+
return "pointer";
352+
}
353+
}
354+
};
355+
356+
function updateCursor(event) {
357+
var cursor = this.behavior.getCursorAt(-1, -1);
358+
var hoverCell = this.hoverCell;
359+
if (hoverCell && hoverCell.x > -2 && hoverCell.y > -1) {
360+
var x = hoverCell.x + this.getHScrollValue();
361+
cursor = this.behavior.getCursorAt(x, hoverCell.y + this.getVScrollValue(), event);
362+
}
363+
this.beCursor(cursor);
364+
}
365+
366+
Object.getPrototypeOf(grid.behavior).onMouseMove = function(grid, event) {
367+
if (this.featureChain) {
368+
this.featureChain.handleMouseMove(grid, event);
369+
updateCursor.call(grid, event);
370+
this.featureChain.setCursor(grid);
371+
}
372+
};
373+
342374
Object.getPrototypeOf(grid.behavior).cellClicked = async function(event) {
343375
event.primitiveEvent.preventDefault();
344376
event.handled = true;
@@ -378,7 +410,11 @@ export const install = function(grid) {
378410
// this only works for single row select (which is all we support
379411
// right now)
380412
if (this.grid.properties.rowSelection) {
381-
const selected = this.grid.getSelectedRows()[0] === y;
413+
const selected_rows = this.grid.getSelectedRows();
414+
const selected = selected_rows[0] === y;
415+
if (selected_rows.length === 0) {
416+
delete this.dataModel["_selected_row_index"];
417+
}
382418
this.grid.canvas.dispatchEvent(
383419
new CustomEvent("perspective-select", {
384420
bubbles: true,
@@ -392,7 +428,6 @@ export const install = function(grid) {
392428
})
393429
);
394430
}
395-
396431
this.grid.canvas.dispatchEvent(
397432
new CustomEvent("perspective-click", {
398433
bubbles: true,
@@ -401,7 +436,12 @@ export const install = function(grid) {
401436
})
402437
);
403438

404-
return this.dataModel.toggleRow(event.dataCell.y, event.dataCell.x, event);
439+
const rp_len = this.dataModel.data[y]?.[-1]?.rowPath?.length;
440+
const is_toggle = !this.grid.properties.rowSelection || event?.gridPoint.x <= rp_len * 15 + 10;
441+
442+
if (is_toggle) {
443+
return this.dataModel.toggleRow(event.dataCell.y, event.dataCell.x, event);
444+
}
405445
};
406446

407447
// Prevents flashing of cell selection on scroll

0 commit comments

Comments
 (0)