plotters icon indicating copy to clipboard operation
plotters copied to clipboard

FontStyle doesn't seem to be working

Open sabn0 opened this issue 1 year ago • 0 comments

Describe the bug Hi, Hope I don't miss anything. I am trying to create a text style that would make the text bold. While anchoring, coloring and other styling of the text seem to work fine, the FontStyle enum isn't responsive. My plots obey to all the below manipulations besides FontStyle. Note that it is also not called via a "with" method, which is I think maybe related.

This is how I am creating it:

let text_style = TextStyle::from(("sans-serif", 15)) .transform(FontTransform::None) .font.into_font().style(FontStyle::Bold) .with_color(&BLACK) .with_anchor::<RGBColor>(Pos::new(HPos::Center, VPos::Center)) .into_text_style(chart.plotting_area());

To Reproduce Here is a minimal code example:

pub fn _my_func() -> Result<(), Box<dyn std::error::Error>> {

let root_area = BitMapBackend::new("img.png", (640, 640))
.into_drawing_area();
root_area.fill(&WHITE).unwrap();

let mut chart = ChartBuilder::on(&root_area)
.margin(10)
.x_label_area_size(10)
.y_label_area_size(10)
.build_cartesian_2d(0..10, 0..10).unwrap();

chart
.configure_mesh()
.draw()
.unwrap();

let text_style = TextStyle::from(("sans-serif", 15))
.transform(FontTransform::None)
.font.into_font().style(FontStyle::Bold)
.with_color(&BLACK)
.with_anchor::<RGBColor>(Pos::new(HPos::Center, VPos::Center))
.into_text_style(chart.plotting_area());
    
chart.draw_series(PointSeries::of_element(
    vec![(1, 1)],
    20,
    &BLACK,
    &|c, _s, _st| {
        return EmptyElement::at(c)
        + Text::new(format!("{}", "Trying to change font style"), (0,0), &text_style);
    },
)).unwrap();

Ok(())

}

Version Information plotters = "0.3.4"

Thank you

sabn0 avatar Mar 23 '23 19:03 sabn0