Skip to content

fix: translucent Bode confidence legend background - #245

Merged
nerdCopter merged 2 commits into
masterfrom
fix/bode-legend-opacity
Nov 23, 2026
Merged

nerdCopter merged 2 commits into
masterfrom
fix/bode-legend-opacity

Conversation

@nerdCopter

@nerdCopter nerdCopter commented Nov 23, 2026 •

Copy link
Copy Markdown
Owner

AI Generated pull-request

Summary

The Bode confidence legend filled a solid white rectangle. It now fills WHITE.mix(LEGEND_BACKGROUND_OPACITY), the opacity the other legends use. The border becomes an unfilled 1 px outline so it stays opaque over the translucent fill. The legend is now drawn after the subplots, so the fill blends over them and nothing overwrites the legend text.

Closes #235

Test plan

  • cargo clippy --all-targets --all-features -- -D warnings, cargo fmt --all, cargo test, cargo build --release pass (513 tests, 0 failed).
  • Bode PNG rendered from one real log; text, swatches and border readable, gridlines visible through the box.
  • plot_pid_activity.rs legend goes through the shared draw_stacked_plot path (plot_framework.rs:447), so it already uses the shared opacity.
  • CodeRabbit local: 0 findings. Remote Ollama (gemma4:26b): none.
  • Before/after render on one log: gridlines no longer cross the legend text; the pixel diff stays inside the legend box.
  • Not verified: a log with a data curve under the legend box; no chirp log tested.
  • Known limitation: the legend overlaps the upper-right of the first coherence subplot. Near-1 coherence curves fade under the 70% fill. Reserving a header band for the legend would change the layout and is not part of this PR.

Summary by CodeRabbit

  • Style
    • Updated the Bode plot confidence legend with a filled background and black outline.
    • The legend now renders above the subplots.

draw_confidence_legend filled a solid white rectangle. Fill it with
WHITE.mix(LEGEND_BACKGROUND_OPACITY), the opacity the other legends use,
so plot data under the box stays visible. The border moves from a black
fill under an inset white fill to an unfilled black outline, so it stays
opaque over the translucent background.

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01KoqKWwCzFDgbyFBKx3fnAe
@coderabbitai

coderabbitai Bot commented Nov 23, 2026 •

Copy link
Copy Markdown
Contributor

Explain Change →

No actionable comments were generated in the recent review.

Walkthrough

The Bode confidence legend now uses the shared background opacity setting. The legend is drawn after the subplots and before the drawing area is presented.

Changes: Bode confidence legend

Layer / File(s) Summary
Update confidence legend rendering
src/plot_functions/plot_bode.rs
The legend background fill uses LEGEND_BACKGROUND_OPACITY, with a separate black outline. The legend is drawn after the subplots.

Estimated code review effort: 2 (Simple) | ~7 minutes

Change: Bug fix · Severity of issue fixed: Low

Possibly related PRs

Merge Risk: Minimal · up to f4072

The Bode confidence legend becomes translucent like the other plot legends, and it is drawn after the subplots so it stays visible. The change is small and reversible, and no merge-blocking risk remains. The legend may slightly obscure plot content under its box, which is cosmetic.

Pre-merge checks: Passed 4

Check name Status Explanation
Description Check Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check Passed The title "fix: translucent Bode confidence legend background" matches the main change in the changeset. The diff changes the legend fill to a translucent mix using LEGEND_BACKGROUND_OPACITY, replaces…
Linked Issues check Passed [#235] The acceptance criterion is that the Bode legend background uses the same opacity as the other plot legends, and its text stays readable. At the reviewed head, draw_confidence_legend in `src/…
Out of Scope Changes check Passed The whole-PR diff against the merge base changes only src/plot_functions/plot_bode.rs. Changes are: the Color trait import needed for .mix(), the LEGEND_BACKGROUND_OPACITY import, the backgrou…
Full details: Title check

Explanation

The title "fix: translucent Bode confidence legend background" matches the main change in the changeset. The diff changes the legend fill to a translucent mix using LEGEND_BACKGROUND_OPACITY, replaces the filled border with an outline, and moves the legend draw call after the subplots in plot_bode.rs. The title is concise, specific, and follows a conventional commit prefix.

Full details: Linked Issues check

Explanation

[#235] The acceptance criterion is that the Bode legend background uses the same opacity as the other plot legends, and its text stays readable. At the reviewed head, draw_confidence_legend in src/plot_functions/plot_bode.rs fills the background with WHITE.mix(LEGEND_BACKGROUND_OPACITY). LEGEND_BACKGROUND_OPACITY is the shared constant the issue names. The solid white fill is removed. The border is now an unfilled ShapeStyle::from(&amp;BLACK).stroke_width(1) outline, so it stays opaque over the translucent fill. The legend call moved after the subplot loop, so the legend text is drawn last and is not overwritten by subplot drawing. Readability over data curves is supported only by the author's single-log render. The issue's unverified items (curve under the box, PID activity legend path) are not acceptance criteria.

Full details: Out of Scope Changes check

Explanation

The whole-PR diff against the merge base changes only src/plot_functions/plot_bode.rs. Changes are: the Color trait import needed for .mix(), the LEGEND_BACKGROUND_OPACITY import, the background fill and border rewrite in draw_confidence_legend, and the move of the legend call after the subplot loop. The draw-order move supports the fill blending over subplots and the readable-text acceptance criterion, so it is connected to #235. No unrelated files or behavior changes appear in the diff.

Finishing Touches

Generate unit tests (beta)

  • Commit to this branch
  • Create a new PR
  • Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts

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

Recent review info

Run configuration

  • Source mode: Auto
  • Repository: Unavailable
  • Branch: Unavailable
  • File: No configuration file from this repository applied
  • Commit: Unavailable
  • Layers: Organization UI
  • Review profile: CHILL
  • Plan: Advanced
  • Run ID: 2e1cc521-437b-44d8-b3fe-ad7877fc07cf
Commits

Reviewing files that changed from the base of the PR and between a4cf224 and f407298.

Files selected for processing: 1

  • src/plot_functions/plot_bode.rs

Included review availability: This review used your included allowance. Your plan provides up to 1 included review per hour; 0 remain after this review.

@nerdCopter

nerdCopter commented Nov 23, 2026 •

Copy link
Copy Markdown
Owner Author

@coderabbitai — AI generated comment
Analysis requested on PR 245:

  1. In draw_confidence_legend (src/plot_functions/plot_bode.rs), is the unfilled 1 px border over the WHITE.mix(LEGEND_BACKGROUND_OPACITY) fill correct for the plotters backend, with no edge or alpha artifacts?
  2. Do the PR body claims hold: the legend uses the shared opacity, and the plot_pid_activity.rs legend goes through the shared path?

@coderabbitai

coderabbitai Bot commented Nov 23, 2026

Copy link
Copy Markdown
Contributor

Tip

For best results, initiate chat on the files or code changes.

Analysis chain

Script executed:

#!/bin/bash
set -u
printf '%s\n' '--- Candidate files ---'
fd -t f '^(plot_bode\.rs|plot_pid_activity\.rs|plot_framework\.rs|Cargo\.toml|Cargo\.lock)$' .
printf '%s\n' '--- Outlines ---'
for f in src/plot_functions/plot_bode.rs src/plot_functions/plot_pid_activity.rs src/plot_framework.rs; do
  printf '\n--- %s ---\n' "$f"
  ast-grep outline "$f" --items all
done
printf '\n%s\n' '--- Relevant occurrences ---'
rg -n -C 4 'draw_confidence_legend|LEGEND_BACKGROUND_OPACITY|draw_stacked_plot|configure_series_labels|BitMapBackend|plotters' src/plot_functions/plot_bode.rs src/plot_functions/plot_pid_activity.rs src/plot_framework.rs Cargo.toml Cargo.lock
printf '\n%s\n' '--- PR change summary ---'
git diff --stat origin/HEAD...HEAD 2>/dev/null || true
git status --short

Length of output: 31002


Script executed:

#!/bin/bash
set -u
printf '%s\n' '--- Complete named files ---'
cat -n src/plot_functions/plot_bode.rs
cat -n src/plot_functions/plot_pid_activity.rs
printf '\n%s\n' '--- Shared renderer and stacked path ---'
cat -n src/plot_framework.rs | sed -n '259,455p'
cat -n src/plot_framework.rs | sed -n '785,865p'
printf '\n%s\n' '--- Constants ---'
rg -n -C 3 'LEGEND_BACKGROUND_OPACITY|PLOT_WIDTH|PLOT_HEIGHT' src/constants.rs
printf '\n%s\n' '--- PR diff ---'
git diff origin/HEAD...HEAD -- src/plot_functions/plot_bode.rs

Length of output: 60700


web_search executed:

Inspect the official source for Rust Plotters 0.3.7, plotters-backend 0.3.7, and plotters-bitmap 0.3.7. For BitMapBackend, how are Rectangle filled vs unfilled with stroke_width 1 rasterized, what endpoints do the fill and border cover, and how is alpha composited onto RGB pixels? Find version-specific source or documentation.

Length of output: 11927


Script executed:

#!/bin/bash
set -euo pipefail
work=$(mktemp -d)
trap 'rm -rf "$work"' EXIT
for crate in plotters plotters-backend plotters-bitmap; do
  curl -fsSL --max-time 25 "https://static.crates.io/crates/$crate/$crate-0.3.7.crate" | tar -xz -C "$work"
done
printf '%s\n' '--- Rectangle, style and bitmap implementations ---'
rg -n -C 8 'fn draw_rect|fn blend_rect_fast|fn fill_rect_fast|struct ShapeStyle|impl.*From.*ShapeStyle|impl.*Drawable.*Rectangle|fn draw_line' "$work/plotters-0.3.7/src/element" "$work/plotters-0.3.7/src/style" "$work/plotters-backend-0.3.7/src" "$work/plotters-bitmap-0.3.7/src"
printf '\n%s\n' '--- Rasterizer rectangle source ---'
cat -n "$work/plotters-backend-0.3.7/src/rasterizer/rect.rs"
printf '\n%s\n' '--- Bitmap source ---'
cat -n "$work/plotters-bitmap-0.3.7/src/bitmap.rs" | sed -n '220,400p'
printf '\n%s\n' '--- RGB pixel implementation ---'
fd -t f . "$work/plotters-bitmap-0.3.7/src/bitmap_pixel" -x sh -c 'echo "--- $1"; cat -n "$1"' sh {}

Length of output: 56177


@nerdCopter The rectangle styles are correct for Plotters 0.3.7, but the Bode draw order prevents the intended result.

  1. Border and alpha: ShapeStyle::from(&BLACK) is unfilled, and the bitmap backend draws its 1 px outline after the translucent fill. The backend blends the fill into RGB pixels; it does not leave alpha in the PNG. The fill and outline meet without a gap in the backend’s rectangle logic. I cannot confirm that the rendered image has no visual artifacts without a pixel or image check. See the Plotters 0.3.7 bitmap source.

    However, create_bode_grid_plot draws the legend at src/plot_functions/plot_bode.rs, Line 270, before it draws the subplots. The fill therefore cannot blend over plot data that is drawn later. Later gridlines or curves can also overwrite the legend text or border. Move the legend call after the subplot loop and before root.present(). Then check a render with a known line under the legend. Gridlines visible in the current render do not by themselves prove that the fill blended over them.

  2. Shared opacity and PID activity: Both claims hold. The Bode fill uses LEGEND_BACKGROUND_OPACITY, which is 0.7. plot_pid_activity calls draw_stacked_plot at src/plot_functions/plot_pid_activity.rs, Line 100. For a valid axis, that path calls draw_single_axis_chart_with_config, which uses the same constant for its legend at src/plot_framework.rs, Line 447.

I inspected the source but did not run the tests or render a PNG.

You are interacting with an AI system.

Move the draw_confidence_legend call in create_bode_grid_plot from before
the subplot loop to right before root.present(). The translucent fill now
blends over the plot content, and later gridlines or curves no longer
overwrite the legend text and border.

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01KoqKWwCzFDgbyFBKx3fnAe
@nerdCopter

Copy link
Copy Markdown
Owner Author

@coderabbitai — AI generated comment

Addressed point 1 of the earlier reply in commit f407298: draw_confidence_legend now runs after the subplot loop, right before root.present(), so the translucent fill blends over the subplots and nothing overwrites the legend text or border. Nothing else depended on the old order.

Render check on one log, before and after: before, gridlines cross the legend text; after, the text is clean and gridlines show faintly through the box. The pixel diff is confined to the legend box. Not verified: a log where a data curve sits under the box.

Analysis requested on this head: does moving the call change any other drawing order in create_bode_grid_plot, for example the title or the axes with no plottable data?

@coderabbitai

coderabbitai Bot commented Nov 23, 2026

Copy link
Copy Markdown
Contributor

Tip

For best results, initiate chat on the files or code changes.

Analysis chain

Script executed:

#!/bin/bash
set -u
printf '%s\n' '--- Current revision ---'
git rev-parse HEAD
git status --short
printf '\n%s\n' '--- Locate requested file ---'
fd -t f '^plot_bode\.rs$' .
printf '\n%s\n' '--- Outline ---'
ast-grep outline src/plot_functions/plot_bode.rs --items all
printf '\n%s\n' '--- Commit details and diff ---'
git show --format=fuller --stat f407298 --
git show --format= --find-renames f407298 -- src/plot_functions/plot_bode.rs
printf '\n%s\n' '--- Drawing order, geometry, and edge cases ---'
rg -n -C 4 'fn create_bode_grid_plot|fn draw_confidence_legend|root\.present|draw_confidence_legend|titled\(|split_|no .*data|No .*data|continue;|return ' src/plot_functions/plot_bode.rs
printf '\n%s\n' '--- Source lines 1-430 ---'
cat -n src/plot_functions/plot_bode.rs | sed -n '1,430p'

Length of output: 28279


Script executed:

#!/bin/bash
set -u
printf '%s\n' '--- Remaining plot_bode.rs source ---'
cat -n src/plot_functions/plot_bode.rs | sed -n '431,900p'
printf '\n%s\n' '--- Dimension and font definitions ---'
rg -n -C 3 'PLOT_WIDTH|PLOT_HEIGHT|FONT_SIZE_LEGEND|FONT_TUPLE_MAIN_TITLE|FONT_FAMILY_BUNDLED' src/constants.rs src/font_config.rs
printf '\n%s\n' '--- Changes since parent and ancestry ---'
git diff f407298^ f407298 -- src/plot_functions/plot_bode.rs
printf '\n%s\n' '--- Bode-specific test references ---'
rg -n -C 2 'create_bode_grid_plot|draw_confidence_legend|insufficient coherence|Bode_Analysis' --glob '*.rs' .

Length of output: 19760


@nerdCopter The commit changes only the legend’s order relative to the subplot loop. It does not reorder the title or the subplots relative to each other.

  • Main title: It is still drawn before both the legend and the subplots (src/plot_functions/plot_bode.rs, Line 257). The legend can still cover part of a title that extends into its box; the move does not change their relative order.
  • Axes with no plottable data: An axis with no data after coherence filtering still skips all three subplot calls (Line 279). If all axes have no plottable data, the function still returns before it creates the bitmap (Line 244).
  • Subplot content: The legend now draws over any subplot content within its box, including captions, axes, gridlines, and curves. Its position and size did not change (Lines 582–592).
  • Errors: If a subplot draw fails, the function now returns before attempting the legend. Previously, it attempted the legend first. root.present() and record_written_this_run still run only after successful drawing.

The reported before-and-after render supports the gridline result. A render with a data curve under the legend remains unverified; a chirp log would provide a useful check. I inspected the source and commit diff but did not run a render or tests.


If you found this review helpful, would you consider giving us a shout-out on X?

Thank you for using CodeRabbit!

You are interacting with an AI system.

@nerdCopter

Copy link
Copy Markdown
Owner Author

@coderabbitai review

@coderabbitai

coderabbitai Bot commented Nov 23, 2026 •

Copy link
Copy Markdown
Contributor
Action not completed

Review rate limited.

Note: CodeRabbit is an incremental review system and does not re-review already reviewed commits. This command is applicable only when automatic reviews are paused.

@nerdCopter
nerdCopter marked this pull request as ready for review November 23, 2026 14:39
@nerdCopter
nerdCopter merged commit 24e0770 into master Nov 23, 2026
5 checks passed
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.

feat: apply the shared legend opacity to the Bode confidence legend

1 participant