Skip to content

Commit 35464ef

Browse files
authored
feat: improve click area for packets and edges (#215)
Closes #204 This PR increases the click area for packets and edges. This was done by creating an invisible stroke/circle apart from the visible one. Setting a non-zero alpha helps for visualizing the true clickable areas for each element: ![image](https://github.com/user-attachments/assets/4a27e6ea-dc85-4067-b974-7e915327e014)
1 parent 4897e28 commit 35464ef

File tree

3 files changed

+23
-9
lines changed

3 files changed

+23
-9
lines changed

src/types/edge.ts

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -76,9 +76,17 @@ export class Edge extends Graphics {
7676
// Method to draw the line
7777
drawEdge(startPos: Point, endPos: Point, color: number) {
7878
this.clear();
79+
80+
// Draw a colored line
7981
this.moveTo(startPos.x, startPos.y);
8082
this.lineTo(endPos.x, endPos.y);
81-
this.stroke({ width: 3, color });
83+
this.stroke({ width: 4, color });
84+
85+
// Add a bigger transparent hitbox
86+
this.moveTo(startPos.x, startPos.y);
87+
this.lineTo(endPos.x, endPos.y);
88+
this.stroke({ width: 12, alpha: 0 });
89+
8290
this.zIndex = ZIndexLevels.Edge;
8391
this.startPos = startPos;
8492
this.endPos = endPos;

src/types/packet.ts

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -28,14 +28,14 @@ import {
2828
import { PacketInfo } from "../graphics/renderables/packet_info";
2929

3030
const contextPerPacketType: Record<string, GraphicsContext> = {
31-
IP: circleGraphicsContext(Colors.Green, 0, 0, 5),
32-
"ICMP-8": circleGraphicsContext(Colors.Red, 0, 0, 5),
33-
"ICMP-0": circleGraphicsContext(Colors.Yellow, 0, 0, 5),
34-
EMPTY: circleGraphicsContext(Colors.Grey, 0, 0, 5),
35-
HTTP: circleGraphicsContext(Colors.Hazel, 0, 0, 5), // for HTTP
31+
IP: circleGraphicsContext(Colors.Green, 5),
32+
"ICMP-8": circleGraphicsContext(Colors.Red, 5),
33+
"ICMP-0": circleGraphicsContext(Colors.Yellow, 5),
34+
EMPTY: circleGraphicsContext(Colors.Grey, 5),
35+
HTTP: circleGraphicsContext(Colors.Hazel, 5), // for HTTP
3636
};
3737

38-
const highlightedPacketContext = circleGraphicsContext(Colors.Violet, 0, 0, 6);
38+
const highlightedPacketContext = circleGraphicsContext(Colors.Violet, 6);
3939

4040
export interface PacketLocation {
4141
startId: DeviceId;

src/utils/utils.ts

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,13 +18,19 @@ export enum Colors {
1818

1919
export function circleGraphicsContext(
2020
color: number,
21-
x: number,
22-
y: number,
2321
radius: number,
2422
): GraphicsContext {
23+
const x = 0;
24+
const y = 0;
25+
2526
const graphicsCtx = new GraphicsContext();
27+
// Draw a circle
2628
graphicsCtx.circle(x, y, radius);
2729
graphicsCtx.fill(color);
30+
31+
// Draw a bigger invisible hit-area
32+
graphicsCtx.circle(x, y, radius * 2);
33+
graphicsCtx.fill({ alpha: 0 });
2834
return graphicsCtx;
2935
}
3036

0 commit comments

Comments
 (0)