pub struct ChartMapping {
pub rect: Rect,
pub bar_spacing: f32,
pub start_idx: usize,
pub base_idx: usize,
pub right_offset: f64,
pub price: PriceMap,
}Expand description
Unified coordinate mapping for charts and indicator panes.
Converts between:
- Bar indices ↔ X screen coordinates
- Prices ↔ Y screen coordinates
Share the mapping with overlays and hit tests to keep them aligned with the pane.
Fields§
§rect: RectThe chart rectangle (rendering area)
bar_spacing: f32Spacing between bars in egui logical points.
start_idx: usizeIndex of the first visible bar
base_idx: usizeIndex of the final bar in the series, used as the horizontal anchor.
right_offset: f64Right-side offset for chart scrolling (in bar units)
price: PriceMapPrice-to-y mapping of the pane; it carries its own vertical extent,
which need not match rect
Implementations§
Source§impl ChartMapping
impl ChartMapping
Sourcepub fn new(
rect: Rect,
bar_spacing: f32,
start_idx: usize,
base_idx: usize,
right_offset: impl Into<f64>,
price: PriceMap,
) -> Self
pub fn new( rect: Rect, bar_spacing: f32, start_idx: usize, base_idx: usize, right_offset: impl Into<f64>, price: PriceMap, ) -> Self
Create a new ChartMapping with all parameters.
Sourcepub fn idx_to_x(&self, bar_idx: usize) -> f32
pub fn idx_to_x(&self, bar_idx: usize) -> f32
Convert bar index to X screen coordinate.
This is the canonical formula used everywhere.
Sourcepub fn x_to_idx(&self, x: f32) -> usize
pub fn x_to_idx(&self, x: f32) -> usize
Convert X screen coordinate to bar index (inverse of idx_to_x).
A degenerate bar_spacing (zero or sub-epsilon) has no inverse, so the
anchor index is returned rather than producing an infinite/NaN index.
Sourcepub fn x_to_idx_f32(&self, x: f32) -> f32
pub fn x_to_idx_f32(&self, x: f32) -> f32
Convert X screen coordinate to fractional bar index.
Useful for precise positioning (e.g., crosshair snapping).
A degenerate bar_spacing (zero or sub-epsilon) has no inverse, so the
anchor index is returned rather than producing an infinite/NaN index.
Sourcepub fn x_to_idx_f64(&self, x: f32) -> f64
pub fn x_to_idx_f64(&self, x: f32) -> f64
Convert X to a fractional bar index, retaining sub-bar precision on large histories.
A degenerate spacing returns the anchor, as in Self::x_to_idx_f32.
Sourcepub fn is_x_visible(&self, x: f32) -> bool
pub fn is_x_visible(&self, x: f32) -> bool
Check if an X coordinate is within the visible chart bounds.
Sourcepub fn local_idx_at_x(&self, x: f32, visible_len: usize) -> Option<usize>
pub fn local_idx_at_x(&self, x: f32, visible_len: usize) -> Option<usize>
Resolve the bar directly under a cursor X coordinate to a local index
into the visible data slice of length visible_len.
Returns None when there is no data, or when the cursor falls before the
first bar or after the last bar (the right-side empty scroll margin), so
callers never index past the slice or read a stale neighbour. Resolution
uses Self::x_to_idx_f64, the exact inverse of Self::idx_to_x, so
the bar at its own centre x resolves to itself and the readout describes
the same bar the crosshair snaps to.
Sourcepub fn price_to_y(&self, price: f64) -> f32
pub fn price_to_y(&self, price: f64) -> f32
Convert price to Y screen coordinate.
Sourcepub fn y_to_price(&self, y: f32) -> f64
pub fn y_to_price(&self, y: f32) -> f64
Convert Y screen coordinate to price (inverse of price_to_y).
Sourcepub fn is_y_visible(&self, y: f32) -> bool
pub fn is_y_visible(&self, y: f32) -> bool
Check if a Y coordinate is within the visible chart bounds.
Sourcepub fn to_screen(&self, bar_idx: usize, price: f64) -> Pos2
pub fn to_screen(&self, bar_idx: usize, price: f64) -> Pos2
Convert bar index and price to screen position.
Sourcepub fn from_screen(&self, pos: Pos2) -> (usize, f64)
pub fn from_screen(&self, pos: Pos2) -> (usize, f64)
Convert screen position to bar index and price.
Sourcepub fn is_visible(&self, pos: Pos2) -> bool
pub fn is_visible(&self, pos: Pos2) -> bool
Check if a screen position is within the visible chart bounds.
Trait Implementations§
Source§impl Clone for ChartMapping
impl Clone for ChartMapping
Source§fn clone(&self) -> ChartMapping
fn clone(&self) -> ChartMapping
1.0.0 (const: unstable) · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read moreimpl Copy for ChartMapping
Auto Trait Implementations§
impl Freeze for ChartMapping
impl RefUnwindSafe for ChartMapping
impl Send for ChartMapping
impl Sync for ChartMapping
impl Unpin for ChartMapping
impl UnsafeUnpin for ChartMapping
impl UnwindSafe for ChartMapping
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
impl<ST, DT> CastableFrom<ST, Initialized, Initialized> for DT
impl<ST, DT> CastableFrom<ST, Uninit, Uninit> for DT
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
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 more