pub struct ChartData {
pub vertices: Vec<Vertex>,
pub viewport_width: f32,
pub viewport_height: f32,
}Expand description
Chart data container
Fields§
§vertices: Vec<Vertex>§viewport_width: f32§viewport_height: f32Implementations§
Source§impl ChartData
impl ChartData
pub fn new(width: f32, height: f32) -> Self
Sourcepub fn add_point(&mut self, point: Point2D, color: Color, size: f32)
pub fn add_point(&mut self, point: Point2D, color: Color, size: f32)
Add a point to the chart
§Parameters
point- The 2D coordinates (x, y) of the point to addcolor- The RGBA color for this point (values 0.0-1.0)size- The size/radius of the point in pixels
Sourcepub fn from_scatter(
x: &[f32],
y: &[f32],
color: Option<Color>,
size: Option<f32>,
width: f32,
height: f32,
) -> Self
pub fn from_scatter( x: &[f32], y: &[f32], color: Option<Color>, size: Option<f32>, width: f32, height: f32, ) -> Self
Create scatter plot data from raw arrays
Converts raw x and y coordinate arrays into normalized vertex data ready for GPU rendering. By default, normalizes coordinates to the [-1, 1] range required by GPU clip space.
§Parameters
x- Array of x-coordinates for each pointy- Array of y-coordinates for each point (must be same length as x)color- Optional color for all points. If None, uses default blue colorsize- Optional size for all points in pixels. If None, defaults to 2.0width- Viewport width in pixelsheight- Viewport height in pixels
§Returns
A new ChartData instance with normalized vertices ready for rendering
Sourcepub fn from_scatter_with_range(
x: &[f32],
y: &[f32],
color: Option<Color>,
size: Option<f32>,
width: f32,
height: f32,
x_range: Option<(f32, f32)>,
y_range: Option<(f32, f32)>,
) -> Self
pub fn from_scatter_with_range( x: &[f32], y: &[f32], color: Option<Color>, size: Option<f32>, width: f32, height: f32, x_range: Option<(f32, f32)>, y_range: Option<(f32, f32)>, ) -> Self
Create scatter plot data with custom normalization ranges
Converts raw x and y coordinate arrays into normalized vertex data with user-specified output ranges. This allows control over the coordinate mapping for custom viewports.
§Parameters
x- Array of x-coordinates for each pointy- Array of y-coordinates for each point (must be same length as x)color- Optional color for all points. If None, uses default blue colorsize- Optional size for all points in pixels. If None, defaults to 2.0width- Viewport width in pixelsheight- Viewport height in pixelsx_range- Optional custom output range for x (min, max). If None, uses [-1.0, 1.0]y_range- Optional custom output range for y (min, max). If None, uses [-1.0, 1.0]
§Returns
A new ChartData instance with normalized vertices
§Example
use helion_core::data::ChartData;
let x_data = vec![1.0, 2.0, 3.0];
let y_data = vec![4.0, 5.0, 6.0];
// Map to [0, 1] range instead of [-1, 1]
let data = ChartData::from_scatter_with_range(
&x_data, &y_data, None, None, 800.0, 600.0,
Some((0.0, 1.0)), // x maps to [0, 1]
Some((0.0, 1.0)), // y maps to [0, 1]
);Auto Trait Implementations§
impl Freeze for ChartData
impl RefUnwindSafe for ChartData
impl Send for ChartData
impl Sync for ChartData
impl Unpin for ChartData
impl UnwindSafe for ChartData
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
Mutably borrows from an owned value. Read more