From db5bf3d5e4f4597070df9f129e7e5d35ab5ac48d Mon Sep 17 00:00:00 2001 From: AmanBoronbaev <149809343+AmanBoronbaev@users.noreply.github.com> Date: Wed, 2 Dec 2026 21:47:49 +0300 Subject: [PATCH] Document pixel and chart-space radii for circles --- plotters/src/element/basic_shapes.rs | 27 +++++++++++++++++++++++++-- 1 file changed, 25 insertions(+), 2 deletions(-) diff --git a/plotters/src/element/basic_shapes.rs b/plotters/src/element/basic_shapes.rs index c43af473..c4ce5169 100644 --- a/plotters/src/element/basic_shapes.rs +++ b/plotters/src/element/basic_shapes.rs @@ -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>(()) +/// ``` pub struct Circle { center: Coord, size: Size, @@ -514,7 +537,7 @@ pub struct Circle { impl Circle { /// 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>(coord: Coord, size: Size, style: S) -> Self {