Skip to content

Fix BoxPlot legend and rename BoxPlot and BarChart color to default_color #97

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
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
2 changes: 1 addition & 1 deletion demo/src/plot_demo.rs
Original file line number Diff line number Diff line change
Expand Up @@ -976,7 +976,7 @@ impl ChartsDemo {
.map(|(x, f)| Bar::new(x, f * 10.0).width(0.1))
.collect(),
)
.color(Color32::LIGHT_BLUE);
.default_color(Color32::LIGHT_BLUE);

if !self.vertical {
chart = chart.horizontal();
Expand Down
14 changes: 4 additions & 10 deletions egui_plot/src/items/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1240,7 +1240,7 @@ pub struct BarChart {
base: PlotItemBase,

pub(super) bars: Vec<Bar>,
pub(super) default_color: Color32,
default_color: Color32,

/// A custom element formatter
pub(super) element_formatter: Option<Box<dyn Fn(&Bar, &BarChart) -> String>>,
Expand All @@ -1262,7 +1262,7 @@ impl BarChart {
/// It can be overridden at the bar level (see [[`Bar`]]).
/// Default is `Color32::TRANSPARENT` which means a color will be auto-assigned.
#[inline]
pub fn color(mut self, color: impl Into<Color32>) -> Self {
pub fn default_color(mut self, color: impl Into<Color32>) -> Self {
let plot_color = color.into();
self.default_color = plot_color;
for b in &mut self.bars {
Expand Down Expand Up @@ -1398,8 +1398,7 @@ pub struct BoxPlot {
base: PlotItemBase,

pub(super) boxes: Vec<BoxElem>,
pub(super) default_color: Color32,
pub(super) name: String,
default_color: Color32,

/// A custom element formatter
pub(super) element_formatter: Option<Box<dyn Fn(&BoxElem, &BoxPlot) -> String>>,
Expand All @@ -1412,7 +1411,6 @@ impl BoxPlot {
base: PlotItemBase::new(name.into()),
boxes,
default_color: Color32::TRANSPARENT,
name: String::new(),
element_formatter: None,
}
}
Expand All @@ -1422,7 +1420,7 @@ impl BoxPlot {
/// It can be overridden at the element level (see [`BoxElem`]).
/// Default is `Color32::TRANSPARENT` which means a color will be auto-assigned.
#[inline]
pub fn color(mut self, color: impl Into<Color32>) -> Self {
pub fn default_color(mut self, color: impl Into<Color32>) -> Self {
let plot_color = color.into();
self.default_color = plot_color;
for box_elem in &mut self.boxes {
Expand Down Expand Up @@ -1478,10 +1476,6 @@ impl PlotItem for BoxPlot {
// nothing to do
}

fn name(&self) -> &str {
self.name.as_str()
}

fn color(&self) -> Color32 {
self.default_color
}
Expand Down
8 changes: 4 additions & 4 deletions egui_plot/src/plot_ui.rs
Original file line number Diff line number Diff line change
Expand Up @@ -224,8 +224,8 @@ impl<'a> PlotUi<'a> {
}

// Give the elements an automatic color if no color has been assigned.
if box_plot.default_color == Color32::TRANSPARENT {
box_plot = box_plot.color(self.auto_color());
if box_plot.color() == Color32::TRANSPARENT {
box_plot = box_plot.default_color(self.auto_color());
}
self.items.push(Box::new(box_plot));
}
Expand All @@ -237,8 +237,8 @@ impl<'a> PlotUi<'a> {
}

// Give the elements an automatic color if no color has been assigned.
if chart.default_color == Color32::TRANSPARENT {
chart = chart.color(self.auto_color());
if chart.color() == Color32::TRANSPARENT {
chart = chart.default_color(self.auto_color());
}
self.items.push(Box::new(chart));
}
Expand Down
Loading