Struct comfy_wgpu::egui::widgets::plot::Plot

source ·
pub struct Plot { /* private fields */ }
Expand description

A 2D plot, e.g. a graph of a function.

Plot supports multiple lines and points.

use egui::plot::{Line, Plot, PlotPoints};
let sin: PlotPoints = (0..1000).map(|i| {
    let x = i as f64 * 0.01;
    [x, x.sin()]
}).collect();
let line = Line::new(sin);
Plot::new("my_plot").view_aspect(2.0).show(ui, |plot_ui| plot_ui.line(line));

Implementations§

source§

impl Plot

source

pub fn new(id_source: impl Hash) -> Plot

Give a unique id for each plot within the same Ui.

source

pub fn data_aspect(self, data_aspect: f32) -> Plot

width / height ratio of the data. For instance, it can be useful to set this to 1.0 for when the two axes show the same unit. By default the plot window’s aspect ratio is used.

source

pub fn view_aspect(self, view_aspect: f32) -> Plot

width / height ratio of the plot region. By default no fixed aspect ratio is set (and width/height will fill the ui it is in).

source

pub fn width(self, width: f32) -> Plot

Width of plot. By default a plot will fill the ui it is in. If you set Self::view_aspect, the width can be calculated from the height.

source

pub fn height(self, height: f32) -> Plot

Height of plot. By default a plot will fill the ui it is in. If you set Self::view_aspect, the height can be calculated from the width.

source

pub fn min_size(self, min_size: Vec2) -> Plot

Minimum size of the plot view.

source

pub fn show_x(self, show_x: bool) -> Plot

Show the x-value (e.g. when hovering). Default: true.

source

pub fn show_y(self, show_y: bool) -> Plot

Show the y-value (e.g. when hovering). Default: true.

source

pub fn center_x_axis(self, on: bool) -> Plot

Always keep the x-axis centered. Default: false.

source

pub fn center_y_axis(self, on: bool) -> Plot

Always keep the y-axis centered. Default: false.

source

pub fn allow_zoom<T>(self, on: T) -> Plotwhere T: Into<AxisBools>,

Whether to allow zooming in the plot. Default: true.

Note: Allowing zoom in one axis but not the other may lead to unexpected results if used in combination with data_aspect.

source

pub fn allow_scroll(self, on: bool) -> Plot

Whether to allow scrolling in the plot. Default: true.

source

pub fn allow_double_click_reset(self, on: bool) -> Plot

Whether to allow double clicking to reset the view. Default: true.

source

pub fn set_margin_fraction(self, margin_fraction: Vec2) -> Plot

Set the side margin as a fraction of the plot size. Only used for auto bounds.

For instance, a value of 0.1 will add 10% space on both sides.

source

pub fn allow_boxed_zoom(self, on: bool) -> Plot

Whether to allow zooming in the plot by dragging out a box with the secondary mouse button.

Default: true.

source

pub fn boxed_zoom_pointer_button( self, boxed_zoom_pointer_button: PointerButton ) -> Plot

Config the button pointer to use for boxed zooming. Default: Secondary

source

pub fn allow_drag<T>(self, on: T) -> Plotwhere T: Into<AxisBools>,

Whether to allow dragging in the plot to move the bounds. Default: true.

source

pub fn label_formatter( self, label_formatter: impl Fn(&str, &PlotPoint) -> String + 'static ) -> Plot

Provide a function to customize the on-hover label for the x and y axis

use egui::plot::{Line, Plot, PlotPoints};
let sin: PlotPoints = (0..1000).map(|i| {
    let x = i as f64 * 0.01;
    [x, x.sin()]
}).collect();
let line = Line::new(sin);
Plot::new("my_plot").view_aspect(2.0)
.label_formatter(|name, value| {
    if !name.is_empty() {
        format!("{}: {:.*}%", name, 1, value.y)
    } else {
        "".to_owned()
    }
})
.show(ui, |plot_ui| plot_ui.line(line));
source

pub fn coordinates_formatter( self, position: Corner, formatter: CoordinatesFormatter ) -> Plot

Show the pointer coordinates in the plot.

source

pub fn x_axis_formatter( self, func: impl Fn(f64, &RangeInclusive<f64>) -> String + 'static ) -> Plot

Provide a function to customize the labels for the X axis based on the current visible value range.

This is useful for custom input domains, e.g. date/time.

If axis labels should not appear for certain values or beyond a certain zoom/resolution, the formatter function can return empty strings. This is also useful if your domain is discrete (e.g. only full days in a calendar).

source

pub fn y_axis_formatter( self, func: impl Fn(f64, &RangeInclusive<f64>) -> String + 'static ) -> Plot

Provide a function to customize the labels for the Y axis based on the current value range.

This is useful for custom value representation, e.g. percentage or units.

If axis labels should not appear for certain values or beyond a certain zoom/resolution, the formatter function can return empty strings. This is also useful if your Y values are discrete (e.g. only integers).

source

pub fn x_grid_spacer( self, spacer: impl Fn(GridInput) -> Vec<GridMark, Global> + 'static ) -> Plot

Configure how the grid in the background is spaced apart along the X axis.

Default is a log-10 grid, i.e. every plot unit is divided into 10 other units.

The function has this signature:

fn step_sizes(input: GridInput) -> Vec<GridMark>;

This function should return all marks along the visible range of the X axis. step_size also determines how thick/faint each line is drawn. For example, if x = 80..=230 is visible and you want big marks at steps of 100 and small ones at 25, you can return:

vec![
   // 100s
   GridMark { value: 100.0, step_size: 100.0 },
   GridMark { value: 200.0, step_size: 100.0 },

   // 25s
   GridMark { value: 125.0, step_size: 25.0 },
   GridMark { value: 150.0, step_size: 25.0 },
   GridMark { value: 175.0, step_size: 25.0 },
   GridMark { value: 225.0, step_size: 25.0 },
];

There are helpers for common cases, see log_grid_spacer and uniform_grid_spacer.

source

pub fn y_grid_spacer( self, spacer: impl Fn(GridInput) -> Vec<GridMark, Global> + 'static ) -> Plot

Default is a log-10 grid, i.e. every plot unit is divided into 10 other units.

See Self::x_grid_spacer for explanation.

source

pub fn clamp_grid(self, clamp_grid: bool) -> Plot

Clamp the grid to only be visible at the range of data where we have values.

Default: false.

source

pub fn include_x(self, x: impl Into<f64>) -> Plot

Expand bounds to include the given x value. For instance, to always show the y axis, call plot.include_x(0.0).

source

pub fn include_y(self, y: impl Into<f64>) -> Plot

Expand bounds to include the given y value. For instance, to always show the x axis, call plot.include_y(0.0).

source

pub fn auto_bounds_x(self) -> Plot

Expand bounds to fit all items across the x axis, including values given by include_x.

source

pub fn auto_bounds_y(self) -> Plot

Expand bounds to fit all items across the y axis, including values given by include_y.

source

pub fn legend(self, legend: Legend) -> Plot

Show a legend including all named items.

source

pub fn show_background(self, show: bool) -> Plot

Whether or not to show the background Rect. Can be useful to disable if the plot is overlaid over existing content. Default: true.

source

pub fn show_axes(self, show: [bool; 2]) -> Plot

Show the axes. Can be useful to disable if the plot is overlaid over an existing grid or content. Default: [true; 2].

Add this plot to an axis link group so that this plot will share the bounds with other plots in the same group. A plot cannot belong to more than one axis group.

Add this plot to a cursor link group so that this plot will share the cursor position with other plots in the same group. A plot cannot belong to more than one cursor group.

source

pub fn sharp_grid_lines(self, enabled: bool) -> Plot

Round grid positions to full pixels to avoid aliasing. Improves plot appearance but might have an undesired effect when shifting the plot bounds. Enabled by default.

source

pub fn reset(self) -> Plot

Resets the plot.

source

pub fn show<R>( self, ui: &mut Ui, build_fn: impl FnOnce(&mut PlotUi) -> R ) -> PlotResponse<R>

Interact with and add items to the plot and finally draw it.

Auto Trait Implementations§

§

impl !RefUnwindSafe for Plot

§

impl !Send for Plot

§

impl !Sync for Plot

§

impl Unpin for Plot

§

impl !UnwindSafe for Plot

Blanket Implementations§

source§

impl<T> Any for Twhere T: 'static + ?Sized,

source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
source§

impl<T> Borrow<T> for Twhere T: ?Sized,

source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
source§

impl<T> BorrowMut<T> for Twhere T: ?Sized,

source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
§

impl<T> Downcast<T> for T

§

fn downcast(&self) -> &T

source§

impl<T> From<T> for T

source§

fn from(t: T) -> T

Returns the argument unchanged.

§

impl<S> FromSample<S> for S

§

fn from_sample_(s: S) -> S

source§

impl<T, U> Into<U> for Twhere U: From<T>,

source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

§

impl<F, T> IntoSample<T> for Fwhere T: FromSample<F>,

§

fn into_sample(self) -> T

§

impl<T> Pointable for T

§

const ALIGN: usize = _

The alignment of pointer.
§

type Init = T

The type for initializers.
§

unsafe fn init(init: <T as Pointable>::Init) -> usize

Initializes a with the given initializer. Read more
§

unsafe fn deref<'a>(ptr: usize) -> &'a T

Dereferences the given pointer. Read more
§

unsafe fn deref_mut<'a>(ptr: usize) -> &'a mut T

Mutably dereferences the given pointer. Read more
§

unsafe fn drop(ptr: usize)

Drops the object pointed to by the given pointer. Read more
§

impl<T, U> ToSample<U> for Twhere U: FromSample<T>,

§

fn to_sample_(self) -> U

source§

impl<T, U> TryFrom<U> for Twhere U: Into<T>,

§

type Error = Infallible

The type returned in the event of a conversion error.
source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
source§

impl<T, U> TryInto<U> for Twhere U: TryFrom<T>,

§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
§

impl<T> Upcast<T> for T

§

fn upcast(&self) -> Option<&T>

§

impl<V, T> VZip<V> for Twhere V: MultiLane<T>,

§

fn vzip(self) -> V

§

impl<T> Any for Twhere T: Any,

§

impl<S, T> Duplex<S> for Twhere T: FromSample<S> + ToSample<S>,