Skip to content
Snippets Groups Projects
Commit f294000e authored by Maximilian Giller's avatar Maximilian Giller :squid:
Browse files

Fixed edge cases, where select box would be stuck on not disappear

parent 355a2a7b
No related branches found
No related tags found
No related merge requests found
Pipeline #52783 passed
...@@ -4,10 +4,14 @@ import * as Graph from "../graph"; ...@@ -4,10 +4,14 @@ import * as Graph from "../graph";
import jquery from "jquery"; import jquery from "jquery";
import ToolMenu from "./menus/toolmenu"; import ToolMenu from "./menus/toolmenu";
const BOX_SELECT_LAYER_ID = "#box-select-layer";
const BOX_SELECT_ID_WH = "box-select";
const SELECT_BOX_SELECTOR = BOX_SELECT_LAYER_ID + " #" + BOX_SELECT_ID_WH;
/** /**
* Only one instance of this should exist, since box-delete has to work on a global scale. * Only one instance of this should exist, since box-delete has to work on a global scale.
*/ */
var deleteToolInstance = undefined; // Used for box delete var deleteToolInstance = undefined; // Used for box delete
export default class DeleteTool extends Tool { export default class DeleteTool extends Tool {
constructor(key) { constructor(key) {
super("Delete", "delete", key, new ToolMenu()); super("Delete", "delete", key, new ToolMenu());
...@@ -43,8 +47,10 @@ export default class DeleteTool extends Tool { ...@@ -43,8 +47,10 @@ export default class DeleteTool extends Tool {
// Ask for confirmation to delete // Ask for confirmation to delete
var nodeNames = selectedNodes.map((n) => n[Graph.NODE_LABEL]); var nodeNames = selectedNodes.map((n) => n[Graph.NODE_LABEL]);
//! Problem: If browser is not actually showing the alerts, it always returns false! //! Problem: If browser is not actually showing the alerts, it always returns false!
var shouldDelete = confirm("Do you wanna delete all these nodes:\n\n" + nodeNames.join("\n")) var shouldDelete = confirm(
"Do you wanna delete all these nodes:\n\n" + nodeNames.join("\n")
);
// Delete if confirmed // Delete if confirmed
if (shouldDelete) { if (shouldDelete) {
var nodeIds = selectedNodes.map((n) => n[Graph.NODE_ID]); var nodeIds = selectedNodes.map((n) => n[Graph.NODE_ID]);
...@@ -54,7 +60,7 @@ export default class DeleteTool extends Tool { ...@@ -54,7 +60,7 @@ export default class DeleteTool extends Tool {
onNodeClick(node) { onNodeClick(node) {
graph.deleteNode(node[Graph.NODE_ID]); graph.deleteNode(node[Graph.NODE_ID]);
if (state.selectedItem == node) { if (state.selectedItem == node) {
state.setSelectedItem(undefined); state.setSelectedItem(undefined);
} }
...@@ -65,7 +71,7 @@ export default class DeleteTool extends Tool { ...@@ -65,7 +71,7 @@ export default class DeleteTool extends Tool {
link[Graph.LINK_SOURCE][Graph.NODE_ID], link[Graph.LINK_SOURCE][Graph.NODE_ID],
link[Graph.LINK_TARGET][Graph.NODE_ID] link[Graph.LINK_TARGET][Graph.NODE_ID]
); );
if (state.selectedItem == link) { if (state.selectedItem == link) {
state.setSelectedItem(undefined); state.setSelectedItem(undefined);
} }
...@@ -76,24 +82,18 @@ export default class DeleteTool extends Tool { ...@@ -76,24 +82,18 @@ export default class DeleteTool extends Tool {
// Source: https://github.com/vasturiano/force-graph/issues/151#issuecomment-735850938 // Source: https://github.com/vasturiano/force-graph/issues/151#issuecomment-735850938
// forceGraph element is the element provided to the Force Graph Library // forceGraph element is the element provided to the Force Graph Library
jquery("#2d-graph").on( jquery("#2d-graph").on("pointerdown", this.boxSelectOnPointerDown);
"pointerdown", jquery("#2d-graph").on("pointermove", this.boxSelectOnPointerMove);
this.boxSelectOnPointerDown jquery("#2d-graph").on("pointerup", this.boxSelectOnPointerUp);
);
jquery("#2d-graph").on(
"pointermove",
this.boxSelectOnPointerMove
);
jquery("#2d-graph").on(
"pointerup",
this.boxSelectOnPointerUp
);
}); });
} }
boxSelectOnPointerDown(e) { boxSelectOnPointerDown(e) {
// Only do anything if delete tool is also active // Only do anything if delete tool is also active
if (deleteToolInstance === undefined || deleteToolInstance.isActive == false) { if (
deleteToolInstance === undefined ||
deleteToolInstance.isActive == false
) {
return; return;
} }
...@@ -103,7 +103,7 @@ export default class DeleteTool extends Tool { ...@@ -103,7 +103,7 @@ export default class DeleteTool extends Tool {
e.preventDefault(); e.preventDefault();
this.boxSelect = document.createElement("div"); this.boxSelect = document.createElement("div");
this.boxSelect.id = "box-select"; this.boxSelect.id = BOX_SELECT_ID_WH;
this.boxSelect.style.left = e.offsetX.toString() + "px"; this.boxSelect.style.left = e.offsetX.toString() + "px";
this.boxSelect.style.top = e.offsetY.toString() + "px"; this.boxSelect.style.top = e.offsetY.toString() + "px";
this.boxSelectStart = { this.boxSelectStart = {
...@@ -111,7 +111,7 @@ export default class DeleteTool extends Tool { ...@@ -111,7 +111,7 @@ export default class DeleteTool extends Tool {
y: e.offsetY, y: e.offsetY,
}; };
// app element is the element just above the forceGraph element. // app element is the element just above the forceGraph element.
jquery("#box-select-layer").append(this.boxSelect); jquery(BOX_SELECT_LAYER_ID).append(this.boxSelect);
} }
boxSelectOnPointerMove(e) { boxSelectOnPointerMove(e) {
...@@ -120,7 +120,7 @@ export default class DeleteTool extends Tool { ...@@ -120,7 +120,7 @@ export default class DeleteTool extends Tool {
} }
if (!e.shiftKey) { if (!e.shiftKey) {
this.boxSelect.remove(); jquery(SELECT_BOX_SELECTOR).remove();
return; return;
} }
...@@ -151,7 +151,7 @@ export default class DeleteTool extends Tool { ...@@ -151,7 +151,7 @@ export default class DeleteTool extends Tool {
} }
if (!e.shiftKey) { if (!e.shiftKey) {
this.boxSelect.remove(); jquery(SELECT_BOX_SELECTOR).remove();
return; return;
} }
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment