pub struct Range {
pub min: f64,
pub max: f64,
}Expand description
Numeric range with inclusive bounds.
Range is used for axis limits, data bounds, and viewport calculations. The
constructor automatically swaps bounds to maintain min <= max.
Fields§
§min: f64Minimum value.
max: f64Maximum value.
Implementations§
Source§impl Range
impl Range
Sourcepub fn new(min: f64, max: f64) -> Self
pub fn new(min: f64, max: f64) -> Self
Create a new range, swapping bounds if needed.
Examples found in repository?
examples/advanced.rs (line 74)
34fn build_views(
35 cx: &mut gpui::App,
36) -> (
37 gpui::Entity<GpuiPlotView>,
38 gpui::Entity<GpuiPlotView>,
39 Series,
40 Series,
41) {
42 let mut stream_a = Series::line("stream-A").with_kind(SeriesKind::Line(LineStyle {
43 color: Color::new(0.2, 0.82, 0.95, 1.0),
44 width: 2.0,
45 }));
46 let mut stream_b = Series::line("stream-B").with_kind(SeriesKind::Line(LineStyle {
47 color: Color::new(0.95, 0.64, 0.28, 1.0),
48 width: 2.0,
49 }));
50
51 for i in 0..1_000 {
52 let phase = i as f64 * 0.02;
53 let _ = stream_a.push_y((phase * 0.9).sin() + 0.2 * (phase * 0.13).cos());
54 let _ = stream_b.push_y((phase * 0.45).cos() * 1.15 + 0.15 * (phase * 0.09).sin());
55 }
56
57 let events = Series::from_iter_points(
58 "events(scatter)",
59 (0..200).map(|i| {
60 let x = i as f64 * 80.0 + 40.0;
61 let y = (x * 0.02).sin() * 0.9;
62 gpui_liveplot::Point::new(x, y)
63 }),
64 SeriesKind::Scatter(MarkerStyle {
65 color: Color::new(0.95, 0.25, 0.55, 1.0),
66 size: 5.0,
67 shape: MarkerShape::Circle,
68 }),
69 );
70
71 let baseline = Series::from_explicit_callback(
72 "baseline(callback)",
73 |x| (x * 0.015).sin() * 0.4,
74 Range::new(0.0, 25_000.0),
75 5_000,
76 SeriesKind::Line(LineStyle {
77 color: Color::new(0.45, 0.45, 0.5, 0.8),
78 width: 1.0,
79 }),
80 );
81
82 let mut top_plot = Plot::builder()
83 .theme(Theme::dark())
84 .x_axis(AxisConfig::builder().title("Sample").build())
85 .y_axis(AxisConfig::builder().title("Top: stream + events").build())
86 .view(View::FollowLastN { points: 2_000 })
87 .build();
88 top_plot.add_series(&stream_a);
89 top_plot.add_series(&events);
90
91 let mut bottom_plot = Plot::builder()
92 .theme(Theme::dark())
93 .x_axis(AxisConfig::builder().title("Sample").build())
94 .y_axis(
95 AxisConfig::builder()
96 .title("Bottom: stream + baseline")
97 .build(),
98 )
99 .view(View::FollowLastNXY { points: 2_000 })
100 .build();
101 bottom_plot.add_series(&stream_b);
102 bottom_plot.add_series(&baseline);
103
104 let config = PlotViewConfig {
105 show_legend: true,
106 show_hover: true,
107 ..Default::default()
108 };
109
110 let link_group = PlotLinkGroup::new();
111 let options = PlotLinkOptions {
112 link_x: true,
113 link_y: false,
114 link_cursor: true,
115 link_brush: true,
116 link_reset: true,
117 };
118
119 let top = cx.new(|_| {
120 GpuiPlotView::with_config(top_plot, config.clone())
121 .with_link_group(link_group.clone(), options)
122 });
123 let bottom = cx.new(|_| {
124 GpuiPlotView::with_config(bottom_plot, config).with_link_group(link_group, options)
125 });
126
127 (top, bottom, stream_a, stream_b)
128}Sourcepub fn expand_to_include(&mut self, value: f64)
pub fn expand_to_include(&mut self, value: f64)
Expand the range to include a value.
Non-finite values are ignored.
Sourcepub fn padded(&self, frac: f64, min_padding: f64) -> Self
pub fn padded(&self, frac: f64, min_padding: f64) -> Self
Add padding around the range.
frac is applied to the current span and clamped by min_padding.
Sourcepub fn with_min_span(&self, min_span: f64) -> Self
pub fn with_min_span(&self, min_span: f64) -> Self
Ensure the range has at least the given span.
Trait Implementations§
impl Copy for Range
impl StructuralPartialEq for Range
Auto Trait Implementations§
impl Freeze for Range
impl RefUnwindSafe for Range
impl Send for Range
impl Sync for Range
impl Unpin for Range
impl UnsafeUnpin for Range
impl UnwindSafe for Range
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