pub struct DataTransform { /* private fields */ }Expand description
High-level data-to-screen transform.
Combines a viewport (for the projection matrix) with an optional data range mapping. When no data range is set, data coordinates equal screen coordinates (identity transform).
§Example
ⓘ
// Identity transform: data coords = screen pixels
let transform = DataTransform::identity(viewport);
// Data range transform: maps data [0..100, 0..50] to a 400x300 plot area
let transform = DataTransform::from_data_range(viewport, DataRangeParams {
plot_x: 80.0, plot_y: 20.0,
plot_width: 400.0, plot_height: 300.0,
data_x_min: 0.0, data_x_max: 100.0,
data_y_min: 0.0, data_y_max: 50.0,
});
renderer.render_transformed(pass, &transform);Implementations§
Source§impl DataTransform
impl DataTransform
Sourcepub fn identity(viewport: Viewport) -> Self
pub fn identity(viewport: Viewport) -> Self
Create an identity transform (data coordinates = screen coordinates).
Sourcepub fn from_data_range(viewport: Viewport, params: DataRangeParams) -> Self
pub fn from_data_range(viewport: Viewport, params: DataRangeParams) -> Self
Create a transform that maps data coordinates to a plot area on screen.
Data point (data_x, data_y) maps to screen position:
screen_x = plot_x + (data_x - data_x_min) / (data_x_max - data_x_min) * plot_widthscreen_y = plot_y + plot_height - (data_y - data_y_min) / (data_y_max - data_y_min) * plot_height
Y is flipped because screen Y goes downward but data Y typically goes upward.
Trait Implementations§
Source§impl Clone for DataTransform
impl Clone for DataTransform
Source§fn clone(&self) -> DataTransform
fn clone(&self) -> DataTransform
Returns a duplicate of the value. Read more
1.0.0 · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
Performs copy-assignment from
source. Read moreSource§impl Debug for DataTransform
impl Debug for DataTransform
impl Copy for DataTransform
Auto Trait Implementations§
impl Freeze for DataTransform
impl RefUnwindSafe for DataTransform
impl Send for DataTransform
impl Sync for DataTransform
impl Unpin for DataTransform
impl UnsafeUnpin for DataTransform
impl UnwindSafe for DataTransform
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
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
Source§impl<T> Downcast for Twhere
T: Any,
impl<T> Downcast for Twhere
T: Any,
Source§fn into_any(self: Box<T>) -> Box<dyn Any>
fn into_any(self: Box<T>) -> Box<dyn Any>
Convert
Box<dyn Trait> (where Trait: Downcast) to Box<dyn Any>. Box<dyn Any> can
then be further downcast into Box<ConcreteType> where ConcreteType implements Trait.Source§fn into_any_rc(self: Rc<T>) -> Rc<dyn Any>
fn into_any_rc(self: Rc<T>) -> Rc<dyn Any>
Convert
Rc<Trait> (where Trait: Downcast) to Rc<Any>. Rc<Any> can then be
further downcast into Rc<ConcreteType> where ConcreteType implements Trait.Source§fn as_any(&self) -> &(dyn Any + 'static)
fn as_any(&self) -> &(dyn Any + 'static)
Convert
&Trait (where Trait: Downcast) to &Any. This is needed since Rust cannot
generate &Any’s vtable from &Trait’s.Source§fn as_any_mut(&mut self) -> &mut (dyn Any + 'static)
fn as_any_mut(&mut self) -> &mut (dyn Any + 'static)
Convert
&mut Trait (where Trait: Downcast) to &Any. This is needed since Rust cannot
generate &mut Any’s vtable from &mut Trait’s.Source§impl<T> DowncastSync for T
impl<T> DowncastSync for T
Source§impl<T> Instrument for T
impl<T> Instrument for T
Source§fn instrument(self, span: Span) -> Instrumented<Self>
fn instrument(self, span: Span) -> Instrumented<Self>
Source§fn in_current_span(self) -> Instrumented<Self>
fn in_current_span(self) -> Instrumented<Self>
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>
Converts
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>
Converts
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