Skip to content

Commit 7e8d4bb

Browse files
committed
feat(ui): add toggle button for hover highlight effect
- Add ✨ button in workspace row to enable/disable hover effects at runtime - Auto-disable hover for large networks (>200 nodes or >500 edges) - Sync button state on data load to reflect auto-disabled state - Lasso toggle respects the hover setting without additional changes
1 parent 6bc4e4a commit 7e8d4bb

4 files changed

Lines changed: 45 additions & 2 deletions

File tree

src/config.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -182,7 +182,8 @@ const CFG = {
182182
HIDE_LABELS: false,
183183

184184
// if network is greater than defined threshold, hover effects are disabled
185-
MAX_NODES_BEFORE_DISABLING_HOVER_EFFECT: 300,
185+
MAX_NODES_BEFORE_DISABLING_HOVER_EFFECT: 200,
186+
MAX_EDGES_BEFORE_DISABLING_HOVER_EFFECT: 500,
186187
DISABLE_HOVER_EFFECT: false,
187188

188189
// if network is greater than defined threshold, bubble groups may span across non-bubble group members

src/graph_lens_lite.html

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -113,6 +113,7 @@ <h3 id="appHeader" class="disabled-header" onclick="cache.ui.reloadApp()">
113113
<div class="button-separator"></div>
114114
<button class="small-btn" title="Fit graph to screen (F)" onclick="cache.gcm.fitViewToVisibleNodes()"></button>
115115
<button id="hideDisconnectedBtn" class="small-btn red" title="Hide all nodes and edges that are not connected to any other node or edge" onclick="cache.gcm.toggleCleanUpDanglingElements(this)">🚫</button>
116+
<button id="hoverToggleBtn" class="small-btn green highlight" title="Disable hover highlight effect" onclick="cache.ui.toggleHoverEffect(this)"></button>
116117
<div id="debugDiv" class="inline"></div>
117118
<br>
118119
<h5 class="purple">Shown:

src/managers/io.js

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1145,7 +1145,9 @@ class IOManager {
11451145
fileData.nodes.length > this.cache.CFG.MAX_NODES_BEFORE_HIDING_LABELS;
11461146
this.cache.CFG.DISABLE_HOVER_EFFECT =
11471147
fileData.nodes.length >
1148-
this.cache.CFG.MAX_NODES_BEFORE_DISABLING_HOVER_EFFECT;
1148+
this.cache.CFG.MAX_NODES_BEFORE_DISABLING_HOVER_EFFECT ||
1149+
fileData.edges.length >
1150+
this.cache.CFG.MAX_EDGES_BEFORE_DISABLING_HOVER_EFFECT;
11491151
this.cache.CFG.AVOID_MEMBERS_IN_BUBBLE_GROUPS =
11501152
fileData.nodes.length >
11511153
this.cache.CFG.MAX_NODES_BEFORE_DISABLING_AVOID_MEMBERS_IN_BUBBLE_GROUPS;
@@ -1703,6 +1705,7 @@ class IOManager {
17031705
}
17041706

17051707
this.cache.io.preProcessData(fileData);
1708+
this.cache.ui.updateHoverToggleButton();
17061709
this.cache.buildDataTable(fileData);
17071710
this.cache.ui.buildUI();
17081711

src/managers/ui.js

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -472,6 +472,44 @@ class UIManager {
472472
await this.cache.graph.updatePlugin({key: 'tooltip', enable: lassoIsActive});
473473
}
474474

475+
async toggleHoverEffect(btn) {
476+
const isCurrentlyEnabled = !this.cache.CFG.DISABLE_HOVER_EFFECT;
477+
478+
if (isCurrentlyEnabled) {
479+
this.cache.CFG.DISABLE_HOVER_EFFECT = true;
480+
btn.classList.remove("green", "highlight");
481+
btn.classList.add("red");
482+
btn.title = "Enable hover highlight effect";
483+
const behaviors = await this.cache.graph.getBehaviors();
484+
const filtered = behaviors.filter(b => b.type !== this.cache.gcm.BEHAVIOURS.HOVER_ACTIVATE.type);
485+
await this.cache.graph.setBehaviors(filtered);
486+
this.info("Hover highlight effect disabled");
487+
} else {
488+
this.cache.CFG.DISABLE_HOVER_EFFECT = false;
489+
btn.classList.remove("red");
490+
btn.classList.add("green", "highlight");
491+
btn.title = "Disable hover highlight effect";
492+
const behaviors = await this.cache.graph.getBehaviors();
493+
behaviors.push(this.cache.gcm.BEHAVIOURS.HOVER_ACTIVATE);
494+
await this.cache.graph.setBehaviors(behaviors);
495+
this.info("Hover highlight effect enabled");
496+
}
497+
}
498+
499+
updateHoverToggleButton() {
500+
const btn = document.getElementById("hoverToggleBtn");
501+
if (!btn) return;
502+
if (this.cache.CFG.DISABLE_HOVER_EFFECT) {
503+
btn.classList.remove("green", "highlight");
504+
btn.classList.add("red");
505+
btn.title = "Enable hover highlight effect";
506+
} else {
507+
btn.classList.remove("red");
508+
btn.classList.add("green", "highlight");
509+
btn.title = "Disable hover highlight effect";
510+
}
511+
}
512+
475513
handleEditModeUIChanges() {
476514
const editBtn = document.getElementById("editBtn");
477515
if (!editBtn) return;

0 commit comments

Comments
 (0)