Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
38 changes: 37 additions & 1 deletion egui_plot/src/plot.rs
Original file line number Diff line number Diff line change
Expand Up @@ -128,6 +128,8 @@ pub struct Plot<'a> {
show_grid: Vec2b,
grid_spacing: Rangef,
grid_spacers: [GridSpacer<'a>; 2],
grid_color: Option<Color32>,
grid_strength_exponent: f32,
clamp_grid: bool,

sense: Sense,
Expand Down Expand Up @@ -180,6 +182,8 @@ impl<'a> Plot<'a> {
show_grid: true.into(),
grid_spacing: Rangef::new(8.0, 300.0),
grid_spacers: [crate::grid::log_grid_spacer(10), crate::grid::log_grid_spacer(10)],
grid_color: None,
grid_strength_exponent: 0.5,
clamp_grid: false,

sense: egui::Sense::click_and_drag(),
Expand Down Expand Up @@ -628,6 +632,33 @@ impl<'a> Plot<'a> {
self
}

/// Set the base color for grid lines.
///
/// By default, grid lines derive their color from [`egui::Visuals::text_color`].
/// This override lets you control the grid color independently of text styling.
/// The color is still modulated by line strength (fading for denser grid lines).
#[inline]
pub fn grid_color(mut self, color: Color32) -> Self {
self.grid_color = Some(color);
self
}

/// Controls the contrast between dense and sparse grid lines.
///
/// - `0.0`: all visible grid lines have the same opacity (uniform).
/// - `0.5`: default — moderate fade for denser lines.
/// - `1.0`: maximum fade — dense lines are much fainter than sparse ones.
///
/// The zoom-based density logic is always preserved; this only controls
/// how much the opacity varies between grid levels.
///
/// Default: `0.5`.
#[inline]
pub fn grid_fade(mut self, fade: f32) -> Self {
self.grid_strength_exponent = fade;
self
}

/// Add this plot to an axis link group so that this plot will share the
/// bounds with other plots in the same group. A plot cannot belong to
/// more than one axis group.
Expand Down Expand Up @@ -1487,7 +1518,12 @@ impl<'a> Plot<'a> {

let line_strength = remap_clamp(spacing_in_points, self.grid_spacing, 0.0..=1.0);

let line_color = crate::colors::color_from_strength(ui, line_strength);
let line_color = if let Some(base) = self.grid_color {
base.gamma_multiply(line_strength.powf(self.grid_strength_exponent))
} else {
let base_color = ui.visuals().text_color();
base_color.gamma_multiply(line_strength.powf(self.grid_strength_exponent))
};

let mut p0 = pos_in_gui;
let mut p1 = pos_in_gui;
Expand Down
Loading