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 dashed line style. #483

Merged
merged 7 commits into from
Jan 8, 2024
Merged

Add dashed line style. #483

merged 7 commits into from
Jan 8, 2024

Conversation

KmolYuan
Copy link
Contributor

@KmolYuan KmolYuan commented Jul 1, 2023

A simple work similar to LineSeries and PathElement.

New Types

Added DashedLineSeries (under line_series feature) and DashedPathElement.

  • plotters::series::line_series::DashedLineSeries - A simple type just making std::iter::once(element) by implementing IntoIterator, and has the same options as the element type.
  • plotters::element::basic_shapes::DashedPathElement - A element type drawing dashed lines pixel-wised.

Options

  • points: The iterator of the points.
  • size: The dash size.
  • spacing: The dash-to-dash spacing (gap size).
  • style: The shape style.

⚠️ Known Issue

  • If the points are too dense, it will become a solid line. (solved)
  • Distortion in rounding coordinates, mainly in SVG.

Preview

Use blue line. The cross markers are the input points.

let series = DashedLineSeries::new(points, 10, 5, color);
chart.draw_series(series)?.label(label).legend(move |(x, y)| {
    DashedPathElement::new([(x, y), (x + 20, y)], 10, 5, color)
});

Another SVG example of my work is 3D coordinates. The curves are projected on a sphere, the main shape using a red dashed line, and the mechanism behind the sphere is shown with gray dashed lines.

@KmolYuan KmolYuan marked this pull request as ready for review July 2, 2023 12:51
@KmolYuan
Copy link
Contributor Author

KmolYuan commented Jul 2, 2023

This is a solution for anyone who wants to use dashed lines.
References: #321 #295 #324

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 to me. Is it ready to merge?

@KmolYuan
Copy link
Contributor Author

KmolYuan commented Jan 8, 2024

@AaronErhardt Sure, thanks for your review!

@AaronErhardt AaronErhardt merged commit 3a4c675 into plotters-rs:master Jan 8, 2024
18 checks passed
@KmolYuan KmolYuan deleted the dash branch January 8, 2024 09:47
@gitmalong
Copy link

Does this also allow configure_series_labels to use a dashed border?

@KmolYuan
Copy link
Contributor Author

@gitmalong

Does this also allow configure_series_labels to use a dashed border?

Currently not. It needs a custom drawing function setting for the border style.

@KmolYuan KmolYuan mentioned this pull request Jan 23, 2024
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.

3 participants