Quickly plot data points using segments to connect consecutive points. Takes any type that implements [`Plotable`], namely `Vec `, `Vec<(f64, f64)>`, `Vec `, ...
(&mut self, v: impl Plotable)
| 717 | /// Quickly plot data points using segments to connect consecutive points. Takes any type |
| 718 | /// that implements [`Plotable`], namely `Vec<Vec2>`, `Vec<(f64, f64)>`, `Vec<f32>`, ... |
| 719 | pub fn plot(&mut self, v: impl Plotable) { |
| 720 | // |
| 721 | let pf: PlotFormat = v.into_plot_format(); |
| 722 | |
| 723 | let data = &pf.data; |
| 724 | |
| 725 | let lo_x = data.iter().min_by(|q, r| q.x.partial_cmp(&r.x).unwrap()).unwrap().x; |
| 726 | |
| 727 | let lo_y = data.iter().min_by(|q, r| q.y.partial_cmp(&r.y).unwrap()).unwrap().y; |
| 728 | |
| 729 | let up_x = data.iter().max_by(|q, r| q.x.partial_cmp(&r.x).unwrap()).unwrap().x; |
| 730 | |
| 731 | let up_y = data.iter().max_by(|q, r| q.y.partial_cmp(&r.y).unwrap()).unwrap().y; |
| 732 | |
| 733 | let dx = (up_x - lo_x).abs() * 0.1; |
| 734 | let dy = (up_y - lo_y).abs() * 0.1; |
| 735 | |
| 736 | self.set_bounds(Vec2::new(lo_x - dx, lo_y - dy), Vec2::new(up_x + dx, up_y + dy)); |
| 737 | |
| 738 | let new_data = SegmentData { |
| 739 | data: pf.data, |
| 740 | ..Default::default() |
| 741 | }; |
| 742 | |
| 743 | self.data.segment_groups.push(new_data); |
| 744 | |
| 745 | println!("Segment added"); |
| 746 | } |
| 747 | |
| 748 | /// Quickly plot data points using markers (scatter plot). |
| 749 | pub fn plotm<T: Plotable>(&mut self, v: T) { |
no test coverage detected