Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
27 changes: 25 additions & 2 deletions plotters/src/element/basic_shapes.rs
Original file line number Diff line number Diff line change
Expand Up @@ -504,7 +504,30 @@ fn test_rect_element() {
}
}

/// A circle element
/// A circle centered at a chart coordinate. A numeric radius is measured in pixels
/// and stays the same when the axis ranges change.
/// A relative [`SizeDesc`] scales the radius with the drawing area.
///
/// To express a radius in chart coordinates, draw an outline with a [`PathElement`].
/// The chart maps each point on the outline to the drawing area. Unequal axis
/// scales therefore produce an ellipse on screen.
///
/// ```
/// use plotters::prelude::*;
/// use std::f64::consts::PI;
///
/// # let mut svg = String::new();
/// # let root = SVGBackend::with_string(&mut svg, (300, 300)).into_drawing_area();
/// # let mut chart = ChartBuilder::on(&root).build_cartesian_2d(-2.0..2.0, -2.0..2.0)?;
/// let center = (0.0, 0.0);
/// let radius = 0.5;
/// let points: Vec<_> = (0..=64).map(|i| {
/// let angle = f64::from(i) * 2.0 * PI / 64.0;
/// (center.0 + radius * angle.cos(), center.1 + radius * angle.sin())
/// }).collect();
/// chart.draw_series(std::iter::once(PathElement::new(points, BLUE)))?;
/// # Ok::<(), Box<dyn std::error::Error>>(())
/// ```
pub struct Circle<Coord, Size: SizeDesc> {
center: Coord,
size: Size,
Expand All @@ -514,7 +537,7 @@ pub struct Circle<Coord, Size: SizeDesc> {
impl<Coord, Size: SizeDesc> Circle<Coord, Size> {
/// Create a new circle element
/// - `coord` The center of the circle
/// - `size` The radius of the circle
/// - `size` The radius in pixels or relative to the drawing area
/// - `style` The style of the circle
/// - Return: The newly created circle element
pub fn new<S: Into<ShapeStyle>>(coord: Coord, size: Size, style: S) -> Self {
Expand Down