Skip to content
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

Add dotted line style #544

Merged
merged 6 commits into from
Feb 26, 2024
Merged

Conversation

KmolYuan
Copy link
Contributor

@KmolYuan KmolYuan commented Jan 23, 2024

A flexible line style that can insert custom markers at equal intervals and supports shifting.
#295 #321 #324 #483

New Types

  • plotters::series::line_series::DottedLineSeries
  • plotters::element::basic_shapes::DottedPathElement

Options in fn new(...) -> Self:

  • points: The iterator of the points
  • shift: The shift of the first marker
  • spacing: The spacing between markers
  • func: The marker function (Similar to the legend function, already mapped coordinates impl Fn(BackendCoord) -> Marker + 'static where Marker: IntoDynElement<'static, DB, BackendCoord>)

Examples

Basic Example

let mk_f = |c| Circle::new(c, 3, BLACK);
chart
    .draw_series(DottedLineSeries::new(points, /*shift*/ 0, /*spacing*/ 20, mk_f))?
    .label("Legend Text")
    .legend(move |c| {
        EmptyElement::at(c)
            + DottedPathElement::new([(gap, 0), (font - gap, 0)], 0, 20, mk_f)
    });

Left: point distance less than spacing
Right: point distance greater than spacing

Dash-dotted Line Example

Combined with the new dashed-line style! 🎉 (#483)

chart.draw_series(DashedLineSeries::new(points.clone(), 30, 16, color))?;
let dot_size = color.stroke_width / 2;
let mk_f = move |c| Circle::new(c, dot_size, color.filled());
chart
    .draw_series(DottedLineSeries::new(points, 30 + 8, 30 + 16, mk_f))?
    .label("Legend Text")
    .legend(move |c| {
        let points = [(gap, 0), (font - gap, 0)];
        EmptyElement::at(c)
            + DashedPathElement::new(points, 30, 16, color)
            + DottedPathElement::new(points, 30 + 8, 30 + 16, mk_f)
    });

Left: point distance less than spacing
Right: point distance greater than spacing

Copy link
Member

@AaronErhardt AaronErhardt left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good, thanks!

@AaronErhardt AaronErhardt merged commit 62783f4 into plotters-rs:master Feb 26, 2024
18 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants