1- use std:: ops:: Bound ;
1+ use std:: collections:: Bound ;
2+ use std:: iter:: FromIterator ;
23use std:: ops:: RangeBounds ;
34use std:: ops:: RangeInclusive ;
45
5- use egui:: Pos2 ;
6- use egui:: Rect ;
7- use egui:: Shape ;
8- use egui:: Stroke ;
9- use egui:: Vec2 ;
10- use egui:: epaint:: ColorMode ;
11- use egui:: epaint:: PathStroke ;
12- use egui:: lerp;
13- use egui:: pos2;
6+ use emath:: Pos2 ;
7+ use emath:: Vec2 ;
8+ use emath:: lerp;
149
1510use crate :: bounds:: PlotBounds ;
1611
@@ -55,110 +50,6 @@ impl PlotPoint {
5550 }
5651}
5752
58- // ----------------------------------------------------------------------------
59-
60- /// Solid, dotted, dashed, etc.
61- #[ derive( Debug , PartialEq , Clone , Copy ) ]
62- #[ cfg_attr( feature = "serde" , derive( serde:: Deserialize , serde:: Serialize ) ) ]
63- pub enum LineStyle {
64- Solid ,
65- Dotted { spacing : f32 } ,
66- Dashed { length : f32 } ,
67- }
68-
69- impl LineStyle {
70- pub fn dashed_loose ( ) -> Self {
71- Self :: Dashed { length : 10.0 }
72- }
73-
74- pub fn dashed_dense ( ) -> Self {
75- Self :: Dashed { length : 5.0 }
76- }
77-
78- pub fn dotted_loose ( ) -> Self {
79- Self :: Dotted { spacing : 10.0 }
80- }
81-
82- pub fn dotted_dense ( ) -> Self {
83- Self :: Dotted { spacing : 5.0 }
84- }
85-
86- pub ( super ) fn style_line ( & self , line : Vec < Pos2 > , mut stroke : PathStroke , highlight : bool , shapes : & mut Vec < Shape > ) {
87- let path_stroke_color = match & stroke. color {
88- ColorMode :: Solid ( c) => * c,
89- ColorMode :: UV ( callback) => callback ( Rect :: from_min_max ( pos2 ( 0. , 0. ) , pos2 ( 0. , 0. ) ) , pos2 ( 0. , 0. ) ) ,
90- } ;
91- match line. len ( ) {
92- 0 => { }
93- 1 => {
94- let mut radius = stroke. width / 2.0 ;
95- if highlight {
96- radius *= 2f32 . sqrt ( ) ;
97- }
98- shapes. push ( Shape :: circle_filled ( line[ 0 ] , radius, path_stroke_color) ) ;
99- }
100- _ => {
101- match self {
102- Self :: Solid => {
103- if highlight {
104- stroke. width *= 2.0 ;
105- }
106- shapes. push ( Shape :: line ( line, stroke) ) ;
107- }
108- Self :: Dotted { spacing } => {
109- // Take the stroke width for the radius even though it's not "correct",
110- // otherwise the dots would become too small.
111- let mut radius = stroke. width ;
112- if highlight {
113- radius *= 2f32 . sqrt ( ) ;
114- }
115- shapes. extend ( Shape :: dotted_line ( & line, path_stroke_color, * spacing, radius) ) ;
116- }
117- Self :: Dashed { length } => {
118- if highlight {
119- stroke. width *= 2.0 ;
120- }
121- let golden_ratio = ( 5.0_f32 . sqrt ( ) - 1.0 ) / 2.0 ; // 0.61803398875
122- shapes. extend ( Shape :: dashed_line (
123- & line,
124- Stroke :: new ( stroke. width , path_stroke_color) ,
125- * length,
126- length * golden_ratio,
127- ) ) ;
128- }
129- }
130- }
131- }
132- }
133- }
134-
135- impl std:: fmt:: Display for LineStyle {
136- fn fmt ( & self , f : & mut std:: fmt:: Formatter < ' _ > ) -> std:: fmt:: Result {
137- match self {
138- Self :: Solid => write ! ( f, "Solid" ) ,
139- Self :: Dotted { spacing } => write ! ( f, "Dotted({spacing} px)" ) ,
140- Self :: Dashed { length } => write ! ( f, "Dashed({length} px)" ) ,
141- }
142- }
143- }
144-
145- // ----------------------------------------------------------------------------
146-
147- /// Determines whether a plot element is vertically or horizontally oriented.
148- #[ derive( Copy , Clone , Debug , PartialEq , Eq ) ]
149- pub enum Orientation {
150- Horizontal ,
151- Vertical ,
152- }
153-
154- impl Default for Orientation {
155- fn default ( ) -> Self {
156- Self :: Vertical
157- }
158- }
159-
160- // ----------------------------------------------------------------------------
161-
16253/// Represents many [`PlotPoint`]s.
16354///
16455/// These can be an owned `Vec`
@@ -286,7 +177,7 @@ impl<'a> PlotPoints<'a> {
286177
287178 /// Returns true if there are no data points available and there is no
288179 /// function to generate any.
289- pub ( crate ) fn is_empty ( & self ) -> bool {
180+ pub fn is_empty ( & self ) -> bool {
290181 match self {
291182 Self :: Owned ( points) => points. is_empty ( ) ,
292183 Self :: Generator ( _) => false ,
@@ -296,7 +187,7 @@ impl<'a> PlotPoints<'a> {
296187
297188 /// If initialized with a generator function, this will generate `n` evenly
298189 /// spaced points in the given range.
299- pub ( super ) fn generate_points ( & mut self , x_range : RangeInclusive < f64 > ) {
190+ pub fn generate_points ( & mut self , x_range : RangeInclusive < f64 > ) {
300191 if let Self :: Generator ( generator) = self {
301192 * self = Self :: range_intersection ( & x_range, & generator. x_range )
302193 . map ( |intersection| {
@@ -320,7 +211,7 @@ impl<'a> PlotPoints<'a> {
320211 ( start < end) . then_some ( start..=end)
321212 }
322213
323- pub ( super ) fn bounds ( & self ) -> PlotBounds {
214+ pub fn bounds ( & self ) -> PlotBounds {
324215 match self {
325216 Self :: Owned ( points) => {
326217 let mut bounds = PlotBounds :: NOTHING ;
@@ -341,62 +232,6 @@ impl<'a> PlotPoints<'a> {
341232 }
342233}
343234
344- // ----------------------------------------------------------------------------
345-
346- /// Circle, Diamond, Square, Cross, …
347- #[ derive( Debug , PartialEq , Eq , Clone , Copy ) ]
348- pub enum MarkerShape {
349- Circle ,
350- Diamond ,
351- Square ,
352- Cross ,
353- Plus ,
354- Up ,
355- Down ,
356- Left ,
357- Right ,
358- Asterisk ,
359- }
360-
361- impl MarkerShape {
362- /// Get a vector containing all marker shapes.
363- pub fn all ( ) -> impl ExactSizeIterator < Item = Self > {
364- [
365- Self :: Circle ,
366- Self :: Diamond ,
367- Self :: Square ,
368- Self :: Cross ,
369- Self :: Plus ,
370- Self :: Up ,
371- Self :: Down ,
372- Self :: Left ,
373- Self :: Right ,
374- Self :: Asterisk ,
375- ]
376- . iter ( )
377- . copied ( )
378- }
379- }
380-
381- // ----------------------------------------------------------------------------
382-
383- /// Query the points of the plot, for geometric relations like closest checks
384- pub enum PlotGeometry < ' a > {
385- /// No geometry based on single elements (examples: text, image,
386- /// horizontal/vertical line)
387- None ,
388-
389- /// Point values (X-Y graphs)
390- Points ( & ' a [ PlotPoint ] ) ,
391-
392- /// Rectangles (examples: boxes or bars)
393- // Has currently no data, as it would require copying rects or iterating a list of pointers.
394- // Instead, geometry-based functions are directly implemented in the respective PlotItem impl.
395- Rects ,
396- }
397-
398- // ----------------------------------------------------------------------------
399-
400235/// Describes a function y = f(x) with an optional range for x and a number of
401236/// points.
402237pub struct ExplicitGenerator < ' a > {
@@ -447,16 +282,3 @@ impl ExplicitGenerator<'_> {
447282 bounds
448283 }
449284}
450-
451- // ----------------------------------------------------------------------------
452-
453- /// Result of [`super::PlotItem::find_closest()`] search, identifies an element
454- /// inside the item for immediate use
455- pub struct ClosestElem {
456- /// Position of hovered-over value (or bar/box-plot/…) in `PlotItem`
457- pub index : usize ,
458-
459- /// Squared distance from the mouse cursor (needed to compare against other
460- /// `PlotItems`, which might be nearer)
461- pub dist_sq : f32 ,
462- }
0 commit comments