Skip to content

Commit d4de866

Browse files
committed
Add marker size to style
1 parent bb686fb commit d4de866

File tree

4 files changed

+27
-2
lines changed

4 files changed

+27
-2
lines changed

examples/scatter_svg.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,8 @@ fn main() {
1414
let s1 = plotlib::scatter::Scatter::from_vec(&data).style(
1515
plotlib::scatter::Style::new()
1616
.marker(plotlib::style::Marker::Square)
17-
.colour("#DD3355"),
17+
.colour("#DD3355")
18+
.size(2.),
1819
);
1920
let s2 = plotlib::scatter::Scatter::from_vec(&[(-1.4, 2.5), (7.2, -0.3)])
2021
.style(plotlib::scatter::Style::new().colour("#35C788"));

src/scatter.rs

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,13 +17,15 @@ use style;
1717
pub struct Style {
1818
marker: Option<style::Marker>,
1919
colour: Option<String>,
20+
size: Option<f32>,
2021
}
2122

2223
impl Style {
2324
pub fn new() -> Self {
2425
Style {
2526
marker: None,
2627
colour: None,
28+
size: None,
2729
}
2830
}
2931

@@ -36,6 +38,10 @@ impl Style {
3638
Some(ref v) => self.colour = Some(v.clone()),
3739
None => {}
3840
}
41+
match other.size {
42+
Some(ref v) => self.size = Some(v.clone()),
43+
None => {}
44+
}
3945
}
4046
}
4147

@@ -63,6 +69,18 @@ impl style::Point for Style {
6369
fn get_colour(&self) -> &Option<String> {
6470
&self.colour
6571
}
72+
73+
fn size<T>(&mut self, value: T) -> &mut Self
74+
where
75+
T: Into<f32>,
76+
{
77+
self.size = Some(value.into());
78+
self
79+
}
80+
81+
fn get_size(&self) -> &Option<f32> {
82+
&self.size
83+
}
6684
}
6785

6886
/// The scatter *representation*.

src/style.rs

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,4 +40,10 @@ pub trait Point {
4040
T: Into<String>;
4141

4242
fn get_colour(&self) -> &Option<String>;
43+
44+
fn size<T>(&mut self, value: T) -> &mut Self
45+
where
46+
T: Into<f32>;
47+
48+
fn get_size(&self) -> &Option<f32>;
4349
}

src/svg_render.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -126,7 +126,7 @@ where
126126
for &(x, y) in &s.data {
127127
let x_pos = value_to_face_offset(x, x_axis, face_width);
128128
let y_pos = -value_to_face_offset(y, y_axis, face_height);
129-
let radius = 5.;
129+
let radius = style.get_size().clone().unwrap_or(5.) as f64;
130130
match style.get_marker().clone().unwrap_or(style::Marker::Circle) {
131131
style::Marker::Circle => {
132132
group.append(

0 commit comments

Comments
 (0)