From 7d9154246cef31309e4b0e26a0a4e05b065d1dde Mon Sep 17 00:00:00 2001 From: nerdCopter <56646290+nerdCopter@users.noreply.github.com> Date: Mon, 23 Nov 2026 04:11:15 -0600 Subject: [PATCH 1/2] fix: translucent Bode confidence legend background 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 Claude-Session: https://claude.ai/code/session_01KoqKWwCzFDgbyFBKx3fnAe --- src/plot_functions/plot_bode.rs | 35 +++++++++++++++------------------ 1 file changed, 16 insertions(+), 19 deletions(-) diff --git a/src/plot_functions/plot_bode.rs b/src/plot_functions/plot_bode.rs index d8829839..897e9feb 100644 --- a/src/plot_functions/plot_bode.rs +++ b/src/plot_functions/plot_bode.rs @@ -8,14 +8,14 @@ use plotters::element::{Circle, Text}; use plotters::prelude::IntoLogRange; use plotters::series::LineSeries; use plotters::style::colors::{BLACK, GREEN, RED, WHITE}; -use plotters::style::{IntoFont, RGBColor, ShapeStyle}; +use plotters::style::{Color, IntoFont, RGBColor, ShapeStyle}; use std::error::Error; use crate::axis_names::AXIS_NAMES; use crate::constants::{ - FONT_SIZE_CHART_TITLE, FONT_SIZE_LEGEND, FREQUENCY_EPSILON, LINE_WIDTH_PLOT, - MAGNITUDE_PLOT_MARGIN_DB, MIN_PLOT_FREQUENCY_HZ, NYQUIST_DIVISOR, PHASE_PLOT_MARGIN_DEG, - PLOT_HEIGHT, PLOT_WIDTH, + FONT_SIZE_CHART_TITLE, FONT_SIZE_LEGEND, FREQUENCY_EPSILON, LEGEND_BACKGROUND_OPACITY, + LINE_WIDTH_PLOT, MAGNITUDE_PLOT_MARGIN_DB, MIN_PLOT_FREQUENCY_HZ, NYQUIST_DIVISOR, + PHASE_PLOT_MARGIN_DEG, PLOT_HEIGHT, PLOT_WIDTH, }; use crate::data_analysis::transfer_function_estimation::{ calculate_stability_margins, estimate_transfer_function_h1, Confidence, StabilityMargins, @@ -586,25 +586,22 @@ fn draw_confidence_legend( let box_offset = 10; // Vertical offset to align box with text baseline let text_offset = 9; // Vertical offset to center text with box - // Legend background (white rectangle with border) - increased bottom padding for whitespace + let box_left = legend_x - 10; + let box_top = legend_y - 10; + let box_right = width as i32 - 10; + let box_bottom = legend_y + 110; // increased bottom padding for whitespace + let border_width = 1; + + // Translucent background so plot data under the box stays visible, same opacity as other legends root.draw(&plotters::element::Rectangle::new( - [ - (legend_x - 10, legend_y - 10), - (width as i32 - 10, legend_y + 110), - ], - plotters::style::ShapeStyle::from(&BLACK) - .stroke_width(1) - .filled(), + [(box_left, box_top), (box_right, box_bottom)], + WHITE.mix(LEGEND_BACKGROUND_OPACITY).filled(), ))?; + // Border drawn as an outline so it stays opaque over the translucent fill root.draw(&plotters::element::Rectangle::new( - [ - (legend_x - 8, legend_y - 8), - (width as i32 - 12, legend_y + 108), - ], - plotters::style::ShapeStyle::from(&WHITE) - .stroke_width(0) - .filled(), + [(box_left, box_top), (box_right, box_bottom)], + ShapeStyle::from(&BLACK).stroke_width(border_width), ))?; // Title From f407298946f4210181ad771abd12c7085a055756 Mon Sep 17 00:00:00 2001 From: nerdCopter <56646290+nerdCopter@users.noreply.github.com> Date: Mon, 23 Nov 2026 04:38:20 -0600 Subject: [PATCH 2/2] fix: draw Bode confidence legend after the subplots 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 Claude-Session: https://claude.ai/code/session_01KoqKWwCzFDgbyFBKx3fnAe --- src/plot_functions/plot_bode.rs | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/plot_functions/plot_bode.rs b/src/plot_functions/plot_bode.rs index 897e9feb..aec71bd3 100644 --- a/src/plot_functions/plot_bode.rs +++ b/src/plot_functions/plot_bode.rs @@ -266,9 +266,6 @@ fn create_bode_grid_plot( .margin(60, 10, 10, 10) .split_evenly((tf_results.len(), 3)); - // Draw legend for confidence colors - draw_confidence_legend(&root, PLOT_WIDTH, PLOT_HEIGHT)?; - // Plot grid: rows are axes, columns are plot types (Mag, Phase, Coh) for axis_index in 0..tf_results.len() { let tf = &tf_results[axis_index]; @@ -319,6 +316,9 @@ fn create_bode_grid_plot( )?; } + // Draw legend last so it sits above the subplots + draw_confidence_legend(&root, PLOT_WIDTH, PLOT_HEIGHT)?; + root.present()?; record_written_this_run(output_file); Ok(true)