Skip to content

Commit b3f8356

Browse files
authored
Improve: Make unselected edges transparent (#180)
This PR tries to unclutter the view of the canvas by making some edges transparent while selecting devices or edges. - If the user selects a device, all the edges that are not connected to the device become transparent. - If the user selects an edge, all the edges become transparent except for the selected one. - If no devices or edges are selected, none of the edges are transparent Maybe we can add a setting to add/remove this functionality, keeping it on by default. Some users might want the edges to be at full opacity all the time. closes #165
1 parent c63a9b5 commit b3f8356

File tree

3 files changed

+44
-0
lines changed

3 files changed

+44
-0
lines changed

src/types/devices/device.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -201,6 +201,9 @@ export abstract class Device extends Container {
201201
});
202202
this.highlightMarker.zIndex = ZIndexLevels.Device;
203203

204+
// Make the unselected edges transparent to improve visibility
205+
this.viewgraph.transparentEdgesForDevice(this.id);
206+
204207
// Ensure the marker is in the same container as the viewport
205208
this.addChild(this.highlightMarker);
206209
}
@@ -210,6 +213,7 @@ export abstract class Device extends Container {
210213
this.highlightMarker.clear(); // Clear the graphic
211214
this.removeChild(this.highlightMarker); // Remove the marker from the viewport
212215
this.highlightMarker.destroy(); // Destroy the graphic object to free memory
216+
this.viewgraph.untransparentEdges(); // Make the edges opaque again
213217
this.highlightMarker = null;
214218
}
215219
}

src/types/edge.ts

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -87,10 +87,15 @@ export class Edge extends Graphics {
8787

8888
highlight() {
8989
this.drawEdge(this.startPos, this.endPos, Colors.Violet);
90+
this.viewgraph.transparentEdgesForEdge(
91+
this.connectedNodes.n1,
92+
this.connectedNodes.n2,
93+
);
9094
}
9195

9296
removeHighlight() {
9397
this.drawEdge(this.startPos, this.endPos, Colors.Lightblue);
98+
this.viewgraph.untransparentEdges();
9499
}
95100

96101
// Method to show the Edge information
@@ -151,6 +156,14 @@ export class Edge extends Graphics {
151156
super.destroy();
152157
}
153158

159+
becomeTransparent() {
160+
this.alpha = 0.2;
161+
}
162+
163+
becomeOpaque() {
164+
this.alpha = 1;
165+
}
166+
154167
public updatePosition(device1: Device, device2: Device) {
155168
const dx = device2.x - device1.x;
156169
const dy = device2.y - device1.y;

src/types/graphs/viewgraph.ts

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -351,6 +351,33 @@ export class ViewGraph {
351351
}
352352
this.graph.clear();
353353
}
354+
355+
// Make all edges transparent except for the ones connected to the device
356+
transparentEdgesForDevice(id: DeviceId) {
357+
for (const [, , edge] of this.graph.getAllEdges()) {
358+
if (edge.connectedNodes.n1 !== id && edge.connectedNodes.n2 !== id) {
359+
edge.becomeTransparent();
360+
}
361+
}
362+
}
363+
364+
// Make all edges transparent except for the edge between the two devices
365+
transparentEdgesForEdge(n1: DeviceId, n2: DeviceId) {
366+
for (const [, , edge] of this.graph.getAllEdges()) {
367+
if (
368+
(edge.connectedNodes.n1 !== n1 || edge.connectedNodes.n2 !== n2) &&
369+
(edge.connectedNodes.n1 !== n2 || edge.connectedNodes.n2 !== n1)
370+
) {
371+
edge.becomeTransparent();
372+
}
373+
}
374+
}
375+
376+
untransparentEdges() {
377+
for (const [, , edge] of this.graph.getAllEdges()) {
378+
edge.becomeOpaque();
379+
}
380+
}
354381
}
355382

356383
function layerDFS(

0 commit comments

Comments
 (0)