plotters-rs / plotters

A rust drawing library for high quality data plotting for both WASM and native, statically and realtimely ๐Ÿฆ€ ๐Ÿ“ˆ๐Ÿš€
https://plotters-rs.github.io/home/
MIT License
3.89k stars 281 forks source link

Add dotted line style #544

Closed KmolYuan closed 8 months ago

KmolYuan commented 9 months ago

A flexible line style that can insert custom markers at equal intervals and supports shifting.

295 #321 #324 #483

New Types

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

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