mirror of
https://github.com/anyproto/anytype-ts.git
synced 2025-06-09 09:35:02 +09:00
add a drag-to-select feature on the graph page
This commit is contained in:
parent
7f19f15e6c
commit
3653fe2fa2
2 changed files with 100 additions and 10 deletions
56
dist/workers/graph.js
vendored
56
dist/workers/graph.js
vendored
|
@ -85,6 +85,8 @@ let paused = false;
|
|||
let isOver = '';
|
||||
let maxDegree = 0;
|
||||
let clusters = {};
|
||||
let dragToSelectStartCoord = {};
|
||||
let dragToSelectCursorCoord = {};
|
||||
|
||||
addEventListener('message', ({ data }) => {
|
||||
if (this[data.id]) {
|
||||
|
@ -355,6 +357,10 @@ draw = (t) => {
|
|||
};
|
||||
});
|
||||
|
||||
if(dragToSelectStartCoord.x && dragToSelectStartCoord.y && dragToSelectCursorCoord.x && dragToSelectStartCoord.y) {
|
||||
drawDragToSelectBox();
|
||||
}
|
||||
|
||||
ctx.restore();
|
||||
};
|
||||
|
||||
|
@ -577,11 +583,61 @@ drawNode = (d) => {
|
|||
};
|
||||
};
|
||||
|
||||
drawDragToSelectBox = () => {
|
||||
const width = dragToSelectCursorCoord.x - dragToSelectStartCoord.x;
|
||||
const height = dragToSelectCursorCoord.y - dragToSelectStartCoord.y;
|
||||
util.roundedRect(dragToSelectStartCoord.x, dragToSelectStartCoord.y, width, height, 1);
|
||||
|
||||
ctx.strokeStyle = data.colors.selected;
|
||||
ctx.lineWidth = getLineWidth() * 3;
|
||||
ctx.stroke();
|
||||
|
||||
ctx.restore();
|
||||
}
|
||||
|
||||
onZoom = (data) => {
|
||||
transform = Object.assign(transform, data.transform);
|
||||
redraw();
|
||||
};
|
||||
|
||||
onDragToSelectStart = (data) => {
|
||||
let {x, y} = data;
|
||||
|
||||
x = transform.invertX(x);
|
||||
y = transform.invertY(y);
|
||||
dragToSelectStartCoord = {x: x, y: y};
|
||||
|
||||
redraw();
|
||||
}
|
||||
|
||||
onDragToSelectMove = (data) => {
|
||||
let {x, y} = data;
|
||||
|
||||
x = transform.invertX(x);
|
||||
y = transform.invertY(y);
|
||||
dragToSelectCursorCoord = {x: x, y: y};
|
||||
|
||||
const left = Math.min(dragToSelectStartCoord.x, x);
|
||||
const top = Math.min(dragToSelectStartCoord.y, y);
|
||||
const right = Math.max(dragToSelectStartCoord.x, x);
|
||||
const bottom = Math.max(dragToSelectStartCoord.y, y);
|
||||
|
||||
nodes.forEach((d) => {
|
||||
if (d.x >= left && d.x <= right && d.y >= top && d.y <= bottom) {
|
||||
send('onSelect', { node: d.id })
|
||||
};
|
||||
});
|
||||
|
||||
redraw();
|
||||
}
|
||||
|
||||
onDragToSelectEnd = (data) => {
|
||||
dragToSelectStartCoord = {};
|
||||
dragToSelectCursorCoord = {};
|
||||
send('onTransform', { ...transform });
|
||||
redraw();
|
||||
}
|
||||
|
||||
onDragStart = ({ active }) => {
|
||||
if (!active) {
|
||||
restart(0.3);
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue