pub struct SeriesLayout { /* private fields */ }Expand description
Timeseries or scatter. Same samples; paint encoding differs.
Treemap is crate::TreeLayout — a different encoding, not a series.
Implementations§
Source§impl SeriesLayout
impl SeriesLayout
Sourcepub fn try_new(series: Vec<Series>) -> Result<Self, Error>
pub fn try_new(series: Vec<Series>) -> Result<Self, Error>
Examples found in repository?
examples/gallery.rs (line 631)
620fn demo_series() -> Result<SeriesLayout, sealed_surface::Error> {
621 let mut px = Vec::new();
622 let mut qty = Vec::new();
623 for i in 0..48u32 {
624 let x = f64::from(i);
625 px.push(SeriesPoint::new(
626 x,
627 40.0 + 14.0 * (x * 0.22).sin() + x * 0.2,
628 ));
629 qty.push(SeriesPoint::new(x, 10.0 + 4.0 * (x * 0.18).cos()));
630 }
631 SeriesLayout::try_new(vec![Series::new(0, "px", px), Series::new(1, "qty", qty)])
632}
633
634fn demo_scatter() -> Result<SeriesLayout, sealed_surface::Error> {
635 let mut a = Vec::new();
636 let mut b = Vec::new();
637 for i in 0..28u32 {
638 let t = f64::from(i);
639 a.push(SeriesPoint::new(
640 6.0 + (t * 0.37).sin() * 5.0 + t * 0.12,
641 22.0 + (t * 0.51).cos() * 8.0,
642 ));
643 b.push(SeriesPoint::new(
644 18.0 + (t * 0.29).cos() * 6.0,
645 12.0 + (t * 0.41).sin() * 7.0 + t * 0.15,
646 ));
647 }
648 SeriesLayout::try_new(vec![Series::new(0, "a", a), Series::new(1, "b", b)])
649}More examples
examples/scatter.rs (line 31)
15fn main() -> Result<(), Box<dyn std::error::Error>> {
16 let mut a = Vec::new();
17 let mut b = Vec::new();
18 for i in 0..28u32 {
19 let t = f64::from(i);
20 a.push(SeriesPoint::new(
21 6.0 + (t * 0.37).sin() * 5.0 + t * 0.12,
22 22.0 + (t * 0.51).cos() * 8.0,
23 ));
24 b.push(SeriesPoint::new(
25 18.0 + (t * 0.29).cos() * 6.0,
26 12.0 + (t * 0.41).sin() * 7.0 + t * 0.15,
27 ));
28 }
29 a[10] = SeriesPoint::new(12.0, 49.37);
30
31 let layout = SeriesLayout::try_new(vec![Series::new(0, "a", a), Series::new(1, "b", b)])?;
32 let dir = PathBuf::from(env!("CARGO_MANIFEST_DIR")).join("examples/renders");
33 fs::create_dir_all(&dir)?;
34
35 let mut sealed = Surface::new(SurfaceMode::Sealed, LicenseLens::open());
36 let vp = Viewport::window(520, 240);
37 let rest = FrameRequest::full(vp).caption("scatter");
38 let idle = sealed.render_scatter(&layout, &rest)?;
39 fs::write(dir.join("sc_sealed.png"), &idle.png)?;
40 fs::write(dir.join("readme_scatter.png"), &idle.png)?;
41
42 let hit = sealed.render_scatter(&layout, &rest.clone().pointer(Pointer::new(240, 110)))?;
43 fs::write(dir.join("sc_crosshair.png"), &hit.png)?;
44 if let Some(tip) = &hit.tooltip_png {
45 fs::write(dir.join("sc_tooltip.png"), tip)?;
46 }
47 println!(
48 "sealed scatter audit={:?} tooltip={}",
49 hit.host.audit_text(),
50 hit.tooltip_png.as_ref().map_or(0, Vec::len)
51 );
52
53 sealed.set_mode(SurfaceMode::Copyable);
54 let copy = sealed.render_scatter(&layout, &rest)?;
55 fs::write(dir.join("sc_copyable.png"), ©.png)?;
56
57 let trial = Surface::new(
58 SurfaceMode::Sealed,
59 LicenseLens::from_tier(AccessTier::Trial),
60 );
61 let t = trial.render_scatter(&layout, &rest)?;
62 fs::write(dir.join("sc_trial_lens.png"), &t.png)?;
63 println!(
64 "wrote scatter renders; trial viewed rows={}",
65 t.viewed.rows.len()
66 );
67 Ok(())
68}examples/timeseries.rs (lines 25-37)
15fn main() -> Result<(), Box<dyn std::error::Error>> {
16 let mut pts = Vec::new();
17 for i in 0..48u32 {
18 let x = f64::from(i);
19 let y = 40.0 + 12.0 * (x * 0.28).sin() + x * 0.35;
20 pts.push(SeriesPoint::new(x, y));
21 }
22 // Distinct sealed-contract values near the middle of the window.
23 pts[20] = SeriesPoint::new(20.0, 49.37);
24
25 let layout = SeriesLayout::try_new(vec![
26 Series::new(0, "px", pts),
27 Series::new(
28 1,
29 "qty",
30 (0..48u32)
31 .map(|i| {
32 let x = f64::from(i);
33 SeriesPoint::new(x, 8.0 + (x * 0.19).cos() * 3.0)
34 })
35 .collect(),
36 ),
37 ])?;
38
39 let dir = PathBuf::from(env!("CARGO_MANIFEST_DIR")).join("examples/renders");
40 fs::create_dir_all(&dir)?;
41
42 let mut sealed = Surface::new(SurfaceMode::Sealed, LicenseLens::open());
43 let vp = Viewport::window(520, 240);
44 let rest = FrameRequest::full(vp).caption("px / qty");
45 let rest_hit = rest.clone().pointer(Pointer::new(240, 110));
46
47 let idle = sealed.render_series(&layout, &rest)?;
48 fs::write(dir.join("ts_sealed.png"), &idle.png)?;
49 fs::write(dir.join("readme_chart.png"), &idle.png)?;
50 let hit = sealed.render_series(&layout, &rest_hit)?;
51 fs::write(dir.join("ts_crosshair.png"), &hit.png)?;
52 if let Some(tip) = &hit.tooltip_png {
53 fs::write(dir.join("ts_tooltip.png"), tip)?;
54 }
55 println!(
56 "sealed audit (must be empty of values): {:?}",
57 hit.host.audit_text()
58 );
59 println!(
60 "crosshair tooltip_png={} hits={}",
61 hit.tooltip_png.as_ref().map_or(0, Vec::len),
62 hit.hits.len()
63 );
64
65 sealed.set_mode(SurfaceMode::Copyable);
66 let copy = sealed.render_series(&layout, &rest)?;
67 fs::write(dir.join("ts_copyable.png"), ©.png)?;
68 println!("copyable TSV (first 120 chars): {:?}", {
69 let a = copy.host.audit_text();
70 a.chars().take(120).collect::<String>()
71 });
72
73 let trial = Surface::new(
74 SurfaceMode::Sealed,
75 LicenseLens::from_tier(AccessTier::Trial),
76 );
77 let t = trial.render_series(&layout, &rest)?;
78 fs::write(dir.join("ts_trial_lens.png"), &t.png)?;
79 println!(
80 "trial lens viewed rows={} (two sample points per series)",
81 t.viewed.rows.len()
82 );
83
84 println!("wrote {}", dir.display());
85 Ok(())
86}Sourcepub fn render(
&self,
surface: &Surface,
request: &FrameRequest,
) -> Result<Frame, Error>
pub fn render( &self, surface: &Surface, request: &FrameRequest, ) -> Result<Frame, Error>
Paint a timeseries on surface (same PNG / host contract as tables).
§Errors
Raster failure or empty layout.
Sourcepub fn render_scatter(
&self,
surface: &Surface,
request: &FrameRequest,
) -> Result<Frame, Error>
pub fn render_scatter( &self, surface: &Surface, request: &FrameRequest, ) -> Result<Frame, Error>
Scatter: same samples as Self::render, unconnected markers (no polyline).
§Errors
Raster failure or empty layout.
Trait Implementations§
Source§impl Clone for SeriesLayout
impl Clone for SeriesLayout
Source§impl Debug for SeriesLayout
impl Debug for SeriesLayout
Source§impl Default for SeriesLayout
impl Default for SeriesLayout
Source§impl PartialEq for SeriesLayout
impl PartialEq for SeriesLayout
impl StructuralPartialEq for SeriesLayout
Auto Trait Implementations§
impl Forget for SeriesLayout
impl Freeze for SeriesLayout
impl Move for SeriesLayout
impl RefUnwindSafe for SeriesLayout
impl Send for SeriesLayout
impl Sync for SeriesLayout
impl Unpin for SeriesLayout
impl UnsafeUnpin for SeriesLayout
impl UnwindSafe for SeriesLayout
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