Skip to main content

Series

Struct Series 

Source
pub struct Series {
    pub id: SeriesId,
    pub name: String,
    pub points: Vec<SeriesPoint>,
}
Expand description

Named polyline.

Fields§

§id: SeriesId

Opaque id.

§name: String

Legend / schema label. Painted as glyphs. Not a datum in sealed host text.

§points: Vec<SeriesPoint>

Samples in x order (caller should sort).

Implementations§

Source§

impl Series

Source

pub fn new(id: u32, name: impl Into<String>, points: Vec<SeriesPoint>) -> Self

Construct.

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
Hide additional 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"), &copy.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 (line 26)
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"), &copy.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}

Trait Implementations§

Source§

impl Clone for Series

Source§

fn clone(&self) -> Self

Returns a duplicate of the value. Read more
1.0.0 (const: unstable) · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl Debug for Series

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl PartialEq for Series

Source§

fn eq(&self, other: &Self) -> bool

Equality operator ==. Read more
1.0.0 (const: unstable) · Source§

fn ne(&self, other: &Rhs) -> bool

Inequality operator !=. Read more
Source§

impl StructuralPartialEq for Series

Auto Trait Implementations§

§

impl Forget for Series

§

impl Freeze for Series

§

impl Move for Series

§

impl RefUnwindSafe for Series

§

impl Send for Series

§

impl Sync for Series

§

impl Unpin for Series

§

impl UnsafeUnpin for Series

§

impl UnwindSafe for Series

Blanket Implementations§

Source§

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

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

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

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

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

Source§

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

Mutably borrows from an owned value. Read more
Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where 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.

Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

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

Source§

type Error = !

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

fn try_from(value: U) -> Result<T, !>

Performs the conversion.
Source§

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

Source§

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.