Skip to content

feat(network): protocol edge-colour legend + curved parallel edges (#497)#553

Merged
NotYuSheng merged 4 commits into
mainfrom
feature/edge-protocol-legend-and-curves
Jul 19, 2026
Merged

feat(network): protocol edge-colour legend + curved parallel edges (#497)#553
NotYuSheng merged 4 commits into
mainfrom
feature/edge-protocol-legend-and-curves

Conversation

@NotYuSheng

@NotYuSheng NotYuSheng commented Jul 18, 2026

Copy link
Copy Markdown
Owner

Closes #497.

Problem

The network graph colour-codes edges by protocol, but:

  1. There was no legend explaining what the edge colours mean.
  2. When two hosts talk over several protocols, each protocol is a separate edge — but all of them were drawn as overlapping straight lines, so only the last-painted colour was ever visible. The legend alone couldn't fix that: you'd see a swatch but couldn't find (or distinguish) its colour on the canvas.

Changes

1. Protocol edge-colour legend

  • New "Edges" section in the graph legend: a line swatch + label per protocol, under a divider below the existing node/device types.
  • Driven entirely by PROTOCOL_COLORS / PROTOCOL_LABELS via a new pure buildProtocolLegend() helper — adding a protocol there makes it appear with no other change.
  • Only protocols present in the current graph are listed (mirrors the node-type legend's filtering).
  • Protocols that share a colour collapse into one entry (e.g. HTTPS/TLS → "HTTPS/TLS").
  • An "Other" swatch (grey DEFAULT_EDGE_COLOR) appears only when some edge uses an unmapped protocol.
  • Shown only in protocol colour mode (hidden in volume mode, where strokes encode bytes).

2. Curved parallel edges

  • Added @sigma/edge-curve and registered EdgeCurvedArrowProgram alongside the straight EdgeArrowProgram.
  • applyParallelEdgeCurvature() indexes parallel edges and fans out any that share a node pair (different protocol/app, or opposite directions) so every edge — and its colour — is visible. A pair with a single connection stays a straight arrow.
  • The PDF-capture overdraw now mirrors the curvature with a matching quadratic Bézier (same control point Sigma uses), so exported diagrams don't collapse back to overlapping straight lines.

No API or schema changes; frontend-only.

Verification

  • New unit tests for buildProtocolLegend (grouping by shared colour, present-only filtering, hasUnmapped, case-insensitivity, empty input) — full suite green (125 passed).
  • Typecheck clean; no new lint errors (the one pre-existing edgeBytesRange fast-refresh warning is unrelated).
  • Live app (screenshotted on The Ultimate PCAP): the "Edges" legend renders with HTTP/DNS/TCP/UDP/ICMP/ARP/Other swatches, and multi-protocol pairs now fan into distinct coloured arcs instead of a single overlapping line — no console errors.

🤖 Generated with Claude Code

Summary by CodeRabbit

  • New Features
    • Added curved rendering for parallel network edges to improve readability of overlapping connections.
    • Introduced an edge protocol color legend, including an “Other” entry for unmapped protocols.
  • Bug Fixes
    • Improved consistency between on-screen rendering and exported PDFs by matching curved edge drawing behavior.
  • Tests
    • Added coverage for protocol legend and protocol-to-color normalization, including aliasing, version folding, and unmapped handling.

)

The network graph colour-codes edges by protocol but never explained the
colours, and multi-protocol pairs drew every edge as an overlapping straight
line so only one colour was ever visible.

Legend: add an "Edges" section to the graph legend with a line swatch + label
per protocol, driven by PROTOCOL_COLORS / PROTOCOL_LABELS (buildProtocolLegend).
Only protocols present in the current graph are listed; protocols sharing a
colour collapse into one entry (HTTPS/TLS); an "Other" swatch appears when any
edge falls back to DEFAULT_EDGE_COLOR. Shown only in protocol colour mode.

Curves: register @sigma/edge-curve's EdgeCurvedArrowProgram and fan out edges
that share a node pair (applyParallelEdgeCurvature) so each protocol's colour is
visible; single edges between a pair stay straight. The PDF-capture overdraw
mirrors the curvature with a matching quadratic so exports don't collapse back
to overlapping lines.

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
@coderabbitai

coderabbitai Bot commented Jul 18, 2026

Copy link
Copy Markdown

Review Change Stack

Warning

Review limit reached

@NotYuSheng, you've reached your PR review limit, so we couldn't start this review.

Next review available in: 42 minutes

Enable usage-based reviews in Billing to review now. Otherwise, wait until the next included review is available.
You're only billed for reviews past your plan's rate limits ($0.25/file).

How can I continue?

After more reviews become available, a review can be triggered using the @coderabbitai review command as a PR comment. Alternatively, push new commits to this PR.

To avoid repeated limits, reduce automatic review volume by pausing incremental auto-reviews earlier, using label-based review opt-in, excluding WIP or generated PR titles, or requesting reviews manually when the PR is ready. If your team needs uninterrupted high-volume reviews, an organization admin can enable usage-based reviews.

How do review limits work?

CodeRabbit enforces per-developer PR review limits for each organization. Most developers receive the normal plan review availability.

For paid Pro and Pro+ PR reviews, CodeRabbit uses adaptive limits for sustained high-volume activity. When a developer's recent PR review activity reaches the 95th percentile or higher among CodeRabbit users, additional reviews become available more gradually as earlier reviews age out of the rolling window.

Please refer docs for additional details.

Review details
⚙️ Run configuration

Configuration used: Organization UI

Review profile: ASSERTIVE

Plan: Pro Plus

Run ID: 2c1be951-b511-4ac5-999b-2fd5d04bc937

📥 Commits

Reviewing files that changed from the base of the PR and between 6e5b5eb and 4b7727c.

📒 Files selected for processing (3)
  • frontend/src/components/network/NetworkGraph/NetworkGraph.css
  • frontend/src/components/network/NetworkGraph/NetworkGraph.tsx
  • frontend/src/features/network/constants.ts
📝 Walkthrough

Walkthrough

The network graph now curves parallel edges for distinct rendering, mirrors curvature in PDF capture, and displays a protocol-based edge legend filtered to protocols present in the graph.

Changes

Network graph visualization

Layer / File(s) Summary
Curved parallel-edge rendering
frontend/package.json, frontend/src/components/network/NetworkGraph/NetworkGraph.tsx
Adds Sigma curved-edge support, assigns curvature to parallel and bidirectional edges, and applies matching quadratic-curve drawing during PDF capture.
Protocol normalization and legend data
frontend/src/features/network/constants.ts, frontend/src/features/network/__tests__/protocolLegend.test.ts
Expands protocol colors, normalizes aliases and version variants, builds ordered color-collapsed legend entries, and tests mapped and unmapped protocol behavior.
Protocol legend construction and display
frontend/src/components/network/NetworkGraph/NetworkGraph.tsx, frontend/src/components/network/NetworkGraph/NetworkGraph.css
Derives entries from current protocol-colored edges and renders themed edge swatches, headings, separators, and an “Other” entry for unmapped protocols.

Estimated code review effort: 3 (Moderate) | ~20 minutes

Sequence Diagram(s)

sequenceDiagram
  participant NetworkGraph
  participant NetworkConstants
  participant Sigma
  participant PDFCapture
  NetworkGraph->>NetworkConstants: normalize edge protocols and build legend
  NetworkGraph->>Sigma: render straight and curved edge programs
  NetworkGraph->>PDFCapture: redraw curved edges with stored curvature
  NetworkGraph-->>NetworkGraph: display protocol swatches for present edges
Loading

Possibly related PRs

🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title clearly reflects the main change: protocol edge-colour legend and curved parallel edges.
Linked Issues check ✅ Passed The legend now uses protocol colors/labels, filters to present protocols, merges shared colors, and shows unmapped edges as Other.
Out of Scope Changes check ✅ Passed The added dependency, CSS, tests, and curved-edge rendering all support the stated frontend network graph work.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

@gemini-code-assist gemini-code-assist Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Code Review

This pull request introduces parallel-edge curvature using the @sigma/edge-curve package to prevent overlapping strokes when multiple edges connect the same pair of nodes, and adds an edge-protocol color legend to the network graph. Feedback on the changes highlights a potential runtime crash in buildProtocolLegend if an edge has a non-string protocol value, and suggests adding a defensive check to prevent a TypeError.

Important

The consumer version of Gemini Code Assist on GitHub is being sunset. Starting June 18, 2026, new organization installations will be blocked, and all code review activity will officially cease on July 17, 2026.
For more details on the timeline and next steps, please review the Help Documentation.

Comment thread frontend/src/features/network/constants.ts

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 1

🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Inline comments:
In `@frontend/src/components/network/NetworkGraph/NetworkGraph.tsx`:
- Around line 328-344: In the parallel-edge handling logic, remove the
unreachable typeof parallelIndex branch and fold its behavior into the
parallelMinIndex branch. Use parallelMinIndex for the curvature calculation and
retain the existing straight-arrow behavior when no parallel index is present.
🪄 Autofix (Beta)

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: ASSERTIVE

Plan: Pro Plus

Run ID: 8b2bb628-949c-4423-aeae-6d0c53dec922

📥 Commits

Reviewing files that changed from the base of the PR and between 7951c8b and 9baf702.

⛔ Files ignored due to path filters (1)
  • frontend/package-lock.json is excluded by !**/package-lock.json
📒 Files selected for processing (5)
  • frontend/package.json
  • frontend/src/components/network/NetworkGraph/NetworkGraph.css
  • frontend/src/components/network/NetworkGraph/NetworkGraph.tsx
  • frontend/src/features/network/__tests__/protocolLegend.test.ts
  • frontend/src/features/network/constants.ts

Comment thread frontend/src/components/network/NetworkGraph/NetworkGraph.tsx
NotYuSheng and others added 2 commits July 19, 2026 09:36
#497)

Only ~15 protocols had colours, so a capture's long tail (SSH, FTP, SMTP, SMB,
SIP, QUIC, NTP, SNMP, LDAP, RTP, …) all rendered identical grey and collapsed
into one "Other" legend entry. Expand PROTOCOL_COLORS with the common,
recognizable protocols, each a unique colour (the legend groups by colour).

Fold variants so they inherit the base colour instead of going grey:
normalizeProtocol() matches exact curated keys first, then a small
PROTOCOL_ALIASES map (SSL→TLS, SIP/SDP→SIP, …), then strips a trailing version
suffix (TLSv1.2→TLS, SSHv2→SSH, IGMPv3→IGMP) — so regular variants need no list.
getProtocolColor and buildProtocolLegend both route through it, keeping strokes
and legend in sync. Raw ethertypes / pure-numeric names stay grey by design.

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
…t is long (#497)

The expanded protocol palette can list ~20 edge colours, which ran the legend the
full height of the canvas. On-screen the legend now caps to the canvas height and
scrolls (slim theme-aware scrollbar); this corner stops panning the graph, an
acceptable trade for a panel. The forceLight PDF-capture render keeps full height
so exports aren't clipped. The list stays present-only (unchanged).

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
@NotYuSheng

Copy link
Copy Markdown
Owner Author

/gemini review

@gemini-code-assist gemini-code-assist Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Code Review

This pull request introduces parallel-edge curvature to the network graph using @sigma/edge-curve to prevent overlapping strokes from hiding protocol colors, updates the PDF exporter to support curved lines, and adds a scrollable edge-protocol legend. Review feedback suggests adding defensive guards in normalizeProtocol to handle null or undefined inputs, validating maxIndex in getCurvature to prevent NaN calculations, and ensuring curvature is a finite number before drawing quadratic curves in the canvas context.

Important

The consumer version of Gemini Code Assist on GitHub is being sunset. Starting June 18, 2026, new organization installations will be blocked, and all code review activity will officially cease on July 17, 2026.
For more details on the timeline and next steps, please review the Help Documentation.

Comment thread frontend/src/features/network/constants.ts Outdated
Comment thread frontend/src/components/network/NetworkGraph/NetworkGraph.tsx Outdated
Comment thread frontend/src/components/network/NetworkGraph/NetworkGraph.tsx Outdated
Address PR #553 review: harden against missing/malformed values so a single bad
edge can't crash the graph render.

- normalizeProtocol tolerates null/undefined/non-string (returns '' -> "Other")
- getCurvature rejects undefined/null/NaN maxIndex (not just <= 0)
- PDF-capture overdraw checks Number.isFinite(curvature) before quadraticCurveTo

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
@NotYuSheng
NotYuSheng merged commit b5478af into main Jul 19, 2026
3 checks passed
@NotYuSheng
NotYuSheng deleted the feature/edge-protocol-legend-and-curves branch July 19, 2026 01:54
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[Enhancement] Network graph has no legend for protocol edge colours

1 participant