Skip to content
Merged
Show file tree
Hide file tree
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
12 changes: 6 additions & 6 deletions .github/workflows/rust.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ on:
branches:
- "main"
pull_request:
types: [ opened, synchronize ]
types: [opened, synchronize]

name: Rust

Expand All @@ -22,7 +22,7 @@ jobs:
- uses: actions-rs/toolchain@v1
with:
profile: default
toolchain: 1.88.0
toolchain: 1.92.0
override: true

- name: Install packages (Linux)
Expand Down Expand Up @@ -70,7 +70,7 @@ jobs:
- uses: actions-rs/toolchain@v1
with:
profile: minimal
toolchain: 1.88.0
toolchain: 1.92.0
target: wasm32-unknown-unknown
override: true
components: clippy
Expand All @@ -95,7 +95,7 @@ jobs:
- uses: actions/checkout@v3
- uses: EmbarkStudios/cargo-deny-action@v2
with:
rust-version: "1.88.0"
rust-version: "1.92.0"
log-level: warn
command: check

Expand All @@ -109,7 +109,7 @@ jobs:
- uses: actions-rs/toolchain@v1
with:
profile: minimal
toolchain: 1.88.0
toolchain: 1.92.0
target: wasm32-unknown-unknown
override: true
- name: Download and install Trunk binary
Expand All @@ -131,7 +131,7 @@ jobs:
lfs: true
- uses: dtolnay/rust-toolchain@master
with:
toolchain: 1.88.0
toolchain: 1.92.0

- name: Set up cargo cache
uses: Swatinem/rust-cache@v2
Expand Down
35 changes: 24 additions & 11 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ members = ["egui_plot", "demo", "examples/*", "examples_utils"]
[workspace.package]
edition = "2024"
license = "MIT OR Apache-2.0"
rust-version = "1.88"
rust-version = "1.92"
version = "0.34.1"


Expand Down Expand Up @@ -102,26 +102,33 @@ missing_crate_level_docs = "warn"

# See also clippy.toml
[workspace.lints.clippy]
all = { level = "warn", priority = -1 }

allow_attributes = "warn"
allow_attributes_without_reason = "warn"
as_ptr_cast_mut = "warn"
await_holding_lock = "warn"
bool_to_int_with_if = "warn"
branches_sharing_code = "warn"
cast_possible_wrap = "warn"
char_lit_as_u8 = "warn"
checked_conversions = "warn"
clear_with_drain = "warn"
clone_on_ref_ptr = "warn"
cloned_instead_of_copied = "warn"
coerce_container_to_any = "warn"
comparison_chain = "warn"
dbg_macro = "warn"
debug_assert_with_mut_call = "warn"
default_union_representation = "warn"
derive_partial_eq_without_eq = "warn"
disallowed_macros = "warn" # See clippy.toml
disallowed_methods = "warn" # See clippy.toml
disallowed_names = "warn" # See clippy.toml
disallowed_script_idents = "warn" # See clippy.toml
disallowed_types = "warn" # See clippy.toml
disallowed_macros = "warn" # See clippy.toml
disallowed_methods = "warn" # See clippy.toml
disallowed_names = "warn" # See clippy.toml
disallowed_script_idents = "warn" # See clippy.toml
disallowed_types = "warn" # See clippy.toml
doc_broken_link = "warn"
doc_comment_double_space_linebreaks = "warn"
doc_include_without_cfg = "warn"
doc_link_with_quotes = "warn"
doc_markdown = "warn"
elidable_lifetime_names = "warn"
Expand Down Expand Up @@ -155,6 +162,7 @@ inefficient_to_string = "warn"
infinite_loop = "warn"
into_iter_without_iter = "warn"
invalid_upcast_comparisons = "warn"
ip_constant = "warn"
iter_filter_is_ok = "warn"
iter_filter_is_some = "warn"
iter_not_returning_iterator = "warn"
Expand All @@ -163,6 +171,7 @@ iter_on_single_items = "warn"
iter_over_hash_type = "warn"
iter_without_into_iter = "warn"
large_digit_groups = "warn"
large_futures = "warn"
large_include_file = "warn"
large_stack_arrays = "warn"
large_stack_frames = "warn"
Expand Down Expand Up @@ -228,6 +237,7 @@ ref_patterns = "warn"
rest_pat_in_fully_bound_structs = "warn"
return_and_then = "warn"
same_functions_in_if_condition = "warn"
self_only_used_in_recursion = "warn"
semicolon_if_nothing_returned = "warn"
set_contains_or_insert = "warn"
should_panic_without_expect = "warn"
Expand All @@ -240,7 +250,6 @@ string_add = "warn"
string_add_assign = "warn"
string_lit_as_bytes = "warn"
string_lit_chars_any = "warn"
string_to_string = "warn"
suspicious_command_arg_space = "warn"
suspicious_xor_used_as_pow = "warn"
todo = "warn"
Expand All @@ -250,7 +259,7 @@ trailing_empty_array = "warn"
trait_duplication_in_bounds = "warn"
transmute_ptr_to_ptr = "warn"
tuple_array_conversions = "warn"
unchecked_duration_subtraction = "warn"
unchecked_time_subtraction = "warn"
undocumented_unsafe_blocks = "warn"
unimplemented = "warn"
uninhabited_references = "warn"
Expand All @@ -265,6 +274,7 @@ unnecessary_semicolon = "warn"
unnecessary_struct_initialization = "warn"
unnecessary_wraps = "warn"
unnested_or_patterns = "warn"
unused_async = "warn"
unused_peekable = "warn"
unused_rounding = "warn"
unused_self = "warn"
Expand All @@ -278,8 +288,11 @@ wildcard_dependencies = "warn"
wildcard_imports = "warn"
zero_sized_map_values = "warn"

manual_range_contains = "allow" # this is better on 'allow'
map_unwrap_or = "allow" # this is better on 'allow'
assigning_clones = "allow" # No please
manual_range_contains = "allow" # this one is just worse imho
map_unwrap_or = "allow" # so is this one
self_named_module_files = "allow" # Disabled waiting on https://github.com/rust-lang/rust-clippy/issues/9602
significant_drop_tightening = "allow" # Too many false positives


[workspace.metadata.cargo-shear]
Expand Down
2 changes: 1 addition & 1 deletion clippy.toml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
# -----------------------------------------------------------------------------
# Section identical to scripts/clippy_wasm/clippy.toml:

msrv = "1.88"
msrv = "1.92"

allow-unwrap-in-tests = true

Expand Down
6 changes: 2 additions & 4 deletions demo/src/app.rs
Original file line number Diff line number Diff line change
Expand Up @@ -67,10 +67,8 @@ impl DemoGallery {
let is_small_screen = screen_rect.width() < 1024.0;

Self::top_bar(ctx);
if !is_small_screen {
if let Some(index) = self.current_example {
self.info_panel(ctx, index);
}
if !is_small_screen && let Some(index) = self.current_example {
self.info_panel(ctx, index);
}
self.thumbnails_panel(ctx, screen_rect.width() / 3.0);
self.demo_panel(ctx);
Expand Down
9 changes: 2 additions & 7 deletions egui_plot/src/aesthetics.rs
Original file line number Diff line number Diff line change
Expand Up @@ -92,18 +92,13 @@ impl std::fmt::Display for LineStyle {
}

/// Determines whether a plot element is vertically or horizontally oriented.
#[derive(Copy, Clone, Debug, PartialEq, Eq)]
#[derive(Copy, Clone, Debug, PartialEq, Eq, Default)]
pub enum Orientation {
Horizontal,
#[default]
Vertical,
}

impl Default for Orientation {
fn default() -> Self {
Self::Vertical
}
}

/// Circle, Diamond, Square, Cross, …
#[derive(Debug, PartialEq, Eq, Clone, Copy)]
pub enum MarkerShape {
Expand Down
14 changes: 7 additions & 7 deletions egui_plot/src/grid.rs
Original file line number Diff line number Diff line change
Expand Up @@ -119,14 +119,14 @@ fn generate_marks(step_sizes: [f64; 3], bounds: (f64, f64)) -> Vec<GridMark> {

let mut deduplicated: Vec<GridMark> = Vec::with_capacity(steps.len());
for step in steps {
if let Some(last) = deduplicated.last_mut() {
if (last.value - step.value).abs() < eps {
// Keep the one with the largest step size
if last.step_size < step.step_size {
*last = step;
}
continue;
if let Some(last) = deduplicated.last_mut()
&& (last.value - step.value).abs() < eps
{
// Keep the one with the largest step size
if last.step_size < step.step_size {
*last = step;
}
continue;
}
deduplicated.push(step);
}
Expand Down
2 changes: 1 addition & 1 deletion egui_plot/src/items/bar_chart.rs
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ pub struct BarChart {
default_color: Color32,

/// A custom element formatter
pub(crate) element_formatter: Option<Box<dyn Fn(&Bar, &BarChart) -> String>>,
pub(crate) element_formatter: Option<Box<dyn Fn(&Bar, &Self) -> String>>,
}

impl BarChart {
Expand Down
2 changes: 1 addition & 1 deletion egui_plot/src/items/box_plot.rs
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ pub struct BoxPlot {
default_color: Color32,

/// A custom element formatter
pub(crate) element_formatter: Option<Box<dyn Fn(&BoxElem, &BoxPlot) -> String>>,
pub(crate) element_formatter: Option<Box<dyn Fn(&BoxElem, &Self) -> String>>,
}

impl BoxPlot {
Expand Down
15 changes: 7 additions & 8 deletions egui_plot/src/items/heatmap.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
use std::ops::RangeInclusive;
use std::sync::Arc;

use egui::Color32;
use egui::Mesh;
Expand Down Expand Up @@ -117,7 +118,7 @@ impl Heatmap {
/// `values.len()` is not divisible by `cols`), an empty heatmap is created.
pub fn new(values: Vec<f64>, cols: usize) -> Self {
// Handle invalid parameters by creating an empty heatmap
if cols == 0 || values.is_empty() || (values.len() % cols) != 0 {
if cols == 0 || values.is_empty() || !values.len().is_multiple_of(cols) {
return Self::empty();
}

Expand Down Expand Up @@ -329,19 +330,17 @@ impl Heatmap {
fn tile_view_info(&self, ui: &Ui, transform: &PlotTransform, index: usize) -> (Rect, Color32, Shape) {
let v = self.values[index];

// calculate color value
let mut fill_color: Color32;
if let Some(mapping) = &self.custom_mapping {
fill_color = mapping(v);
let mut fill_color = if let Some(mapping) = &self.custom_mapping {
mapping(v)
} else {
// convert to value in [0.0, 1.0]
let v_rel = (v - self.min) / (self.max - self.min);

// convert to color palette index
let palette_index = (v_rel * (self.palette.len() - 1) as f64).round() as usize;

fill_color = self.palette[palette_index];
}
self.palette[palette_index]
};

if self.highlight {
let fill = Rgba::from(fill_color);
Expand Down Expand Up @@ -385,7 +384,7 @@ impl Heatmap {
);
let text_pos = tile_rect.center() - galley.size() / 2.0;

let text = Shape::galley(text_pos, galley.clone(), Color32::WHITE);
let text = Shape::galley(text_pos, Arc::clone(&galley), Color32::WHITE);
(tile_rect, fill_color, text)
}
}
Expand Down
13 changes: 7 additions & 6 deletions egui_plot/src/items/series.rs
Original file line number Diff line number Diff line change
Expand Up @@ -169,17 +169,18 @@ impl PlotItem for Line<'_> {
} = self;
let mut fill = *fill;

let mut final_stroke: PathStroke = (*stroke).into();
// if we have a gradient color, we need to wrap the stroke callback to transpose
// the position to a value the caller can reason about
if let Some(gradient_callback) = self.gradient_color.clone() {
let final_stroke: PathStroke = if let Some(gradient_callback) = self.gradient_color.clone() {
// if we have a gradient color, we need to wrap the stroke callback to transpose
// the position to a value the caller can reason about
let local_transform = *transform;
let wrapped_callback = move |_rec: Rect, pos: Pos2| -> Color32 {
let point = local_transform.value_from_position(pos);
gradient_callback(point)
};
final_stroke = PathStroke::new_uv(stroke.width, wrapped_callback.clone());
}
PathStroke::new_uv(stroke.width, wrapped_callback.clone())
} else {
(*stroke).into()
};

let values_tf: Vec<_> = series
.points()
Expand Down
16 changes: 8 additions & 8 deletions egui_plot/src/overlays/legend.rs
Original file line number Diff line number Diff line change
Expand Up @@ -335,10 +335,10 @@ impl Widget for &mut LegendWidget {
background_frame
.show(ui, |ui| {
// always show on top of the legend - so we need to use a new scope
if main_dir == Direction::TopDown {
if let Some(title) = &config.title {
ui.heading(title);
}
if main_dir == Direction::TopDown
&& let Some(title) = &config.title
{
ui.heading(title);
}
let mut focus_on_item = None;

Expand All @@ -363,10 +363,10 @@ impl Widget for &mut LegendWidget {
.reduce(|r1, r2| r1.union(r2))
.expect("No entries in the legend");

if main_dir == Direction::BottomUp {
if let Some(title) = &config.title {
ui.heading(title);
}
if main_dir == Direction::BottomUp
&& let Some(title) = &config.title
{
ui.heading(title);
}

if let Some(focus_on_item) = focus_on_item {
Expand Down
Loading
Loading