Small plot-relates fixes (#526)

* plot: take any id source as argument instead of ToString

* plot: allow user to set stroke on HLine/VLine

* Update changelog
This commit is contained in:
Emil Ernerfeldt
2021-06-28 10:51:06 +02:00
committed by GitHub
parent 3a14f5e8e2
commit cba840ec49
5 changed files with 55 additions and 12 deletions
+36
View File
@@ -53,6 +53,24 @@ impl HLine {
}
}
/// Set the stroke.
pub fn stroke(mut self, stroke: impl Into<Stroke>) -> Self {
self.stroke = stroke.into();
self
}
/// Stroke width. A high value means the plot thickens.
pub fn width(mut self, width: impl Into<f32>) -> Self {
self.stroke.width = width.into();
self
}
/// Stroke color. Default is `Color32::TRANSPARENT` which means a color will be auto-assigned.
pub fn color(mut self, color: impl Into<Color32>) -> Self {
self.stroke.color = color.into();
self
}
/// Name of this horizontal line.
///
/// This name will show up in the plot legend, if legends are turned on.
@@ -133,6 +151,24 @@ impl VLine {
}
}
/// Set the stroke.
pub fn stroke(mut self, stroke: impl Into<Stroke>) -> Self {
self.stroke = stroke.into();
self
}
/// Stroke width. A high value means the plot thickens.
pub fn width(mut self, width: impl Into<f32>) -> Self {
self.stroke.width = width.into();
self
}
/// Stroke color. Default is `Color32::TRANSPARENT` which means a color will be auto-assigned.
pub fn color(mut self, color: impl Into<Color32>) -> Self {
self.stroke.color = color.into();
self
}
/// Name of this vertical line.
///
/// This name will show up in the plot legend, if legends are turned on.
+7 -7
View File
@@ -43,11 +43,11 @@ struct PlotMemory {
/// });
/// let line = Line::new(Values::from_values_iter(sin));
/// ui.add(
/// Plot::new("Test Plot").line(line).view_aspect(2.0)
/// Plot::new("my_plot").line(line).view_aspect(2.0)
/// );
/// ```
pub struct Plot {
name: String,
id_source: Id,
next_auto_color_idx: usize,
items: Vec<Box<dyn PlotItem>>,
@@ -71,10 +71,10 @@ pub struct Plot {
}
impl Plot {
#[allow(clippy::needless_pass_by_value)]
pub fn new(name: impl ToString) -> Self {
/// Give a unique id for each plot within the same `Ui`.
pub fn new(id_source: impl std::hash::Hash) -> Self {
Self {
name: name.to_string(),
id_source: Id::new(id_source),
next_auto_color_idx: 0,
items: Default::default(),
@@ -317,7 +317,7 @@ impl Plot {
impl Widget for Plot {
fn ui(self, ui: &mut Ui) -> Response {
let Self {
name,
id_source,
next_auto_color_idx: _,
mut items,
center_x_axis,
@@ -336,7 +336,7 @@ impl Widget for Plot {
legend_config,
} = self;
let plot_id = ui.make_persistent_id(name);
let plot_id = ui.make_persistent_id(id_source);
let memory = ui
.memory()
.id_data