pub struct ChartLayout {
pub width: f64,
pub height: f64,
pub x_offset: f64,
pub y_start: f64,
pub y_interval: f64,
pub min_y: f64,
pub max_y: f64,
}Expand description
Shared layout state for charts with numeric Y-axis and categorical X-axis.
Encapsulates the common chart setup pattern used by LineGraph.java and QualityBoxPlot.java: computing xOffset from Y-axis label widths, y_start from the Y interval, and the get_y() mapping function.
Fields§
§width: f64§height: f64§x_offset: f64§y_start: f64§y_interval: f64§min_y: f64§max_y: f64Implementations§
Source§impl ChartLayout
impl ChartLayout
Sourcepub fn new(min_y: f64, max_y: f64, y_interval: f64) -> Self
pub fn new(min_y: f64, max_y: f64, y_interval: f64) -> Self
Create a chart layout by computing x_offset from Y-axis label widths.
Sourcepub fn get_y(&self, value: f64) -> f64
pub fn get_y(&self, value: f64) -> f64
getY() maps a data value to a pixel Y coordinate.
Matches Java: (getHeight()-40) - (int)(((getHeight()-80)/(maxY-minY))*(y-minY))
The inner multiplication result is truncated to int before subtraction. // JAVA COMPAT
Sourcepub fn base_width(&self, num_points: usize) -> f64
pub fn base_width(&self, num_points: usize) -> f64
Calculate the width of each data column in the plot area.
Uses floor() to match Java’s integer division truncation:
int baseWidth = (getWidth()-(xOffset+10))/xLabels.length
Sourcepub fn half_base_width(&self, num_points: usize) -> f64
pub fn half_base_width(&self, num_points: usize) -> f64
Half of base_width, truncated to match Java’s baseWidth/2 int division. // JAVA COMPAT
Sourcepub fn render_background(&self, svg: &mut String)
pub fn render_background(&self, svg: &mut String)
Render gray + white background rectangles matching Java’s JPanel default paint.
Sourcepub fn render_y_labels(&self, svg: &mut String)
pub fn render_y_labels(&self, svg: &mut String)
Render Y-axis labels at each tick interval.
Sourcepub fn render_axes(&self, svg: &mut String)
pub fn render_axes(&self, svg: &mut String)
Render the X and Y axis lines.
Sourcepub fn render_x_axis_label(&self, svg: &mut String, label: &str)
pub fn render_x_axis_label(&self, svg: &mut String, label: &str)
Render the X-axis label centered below the axis.
Sourcepub fn render_x_category_label_at(
&self,
svg: &mut String,
label: &str,
i: usize,
base_width: f64,
last_x_label_end: f64,
) -> f64
pub fn render_x_category_label_at( &self, svg: &mut String, label: &str, i: usize, base_width: f64, last_x_label_end: f64, ) -> f64
Render a single X-axis category label at position i, if it doesn’t overlap
the previous label. Returns the updated last_x_label_end value.
Sourcepub fn render_gridlines(&self, svg: &mut String)
pub fn render_gridlines(&self, svg: &mut String)
Render horizontal gridlines at each Y-axis tick.
Auto Trait Implementations§
impl Freeze for ChartLayout
impl RefUnwindSafe for ChartLayout
impl Send for ChartLayout
impl Sync for ChartLayout
impl Unpin for ChartLayout
impl UnsafeUnpin for ChartLayout
impl UnwindSafe for ChartLayout
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self>
fn into_either(self, into_left: bool) -> Either<Self, Self>
self into a Left variant of Either<Self, Self>
if into_left is true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
self into a Left variant of Either<Self, Self>
if into_left(&self) returns true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§impl<T> Pointable for T
impl<T> Pointable for T
Source§impl<SS, SP> SupersetOf<SS> for SPwhere
SS: SubsetOf<SP>,
impl<SS, SP> SupersetOf<SS> for SPwhere
SS: SubsetOf<SP>,
Source§fn to_subset(&self) -> Option<SS>
fn to_subset(&self) -> Option<SS>
self from the equivalent element of its
superset. Read moreSource§fn is_in_subset(&self) -> bool
fn is_in_subset(&self) -> bool
self is actually part of its subset T (and can be converted to it).Source§fn to_subset_unchecked(&self) -> SS
fn to_subset_unchecked(&self) -> SS
self.to_subset but without any property checks. Always succeeds.Source§fn from_subset(element: &SS) -> SP
fn from_subset(element: &SS) -> SP
self to the equivalent element of its superset.