re_types/archetypes/
series_points.rs

1// DO NOT EDIT! This file was auto-generated by crates/build/re_types_builder/src/codegen/rust/api.rs
2// Based on "crates/store/re_types/definitions/rerun/archetypes/series_points.fbs".
3
4#![allow(unused_imports)]
5#![allow(unused_parens)]
6#![allow(clippy::clone_on_copy)]
7#![allow(clippy::cloned_instead_of_copied)]
8#![allow(clippy::map_flatten)]
9#![allow(clippy::needless_question_mark)]
10#![allow(clippy::new_without_default)]
11#![allow(clippy::redundant_closure)]
12#![allow(clippy::too_many_arguments)]
13#![allow(clippy::too_many_lines)]
14
15use ::re_types_core::try_serialize_field;
16use ::re_types_core::SerializationResult;
17use ::re_types_core::{ComponentBatch as _, SerializedComponentBatch};
18use ::re_types_core::{ComponentDescriptor, ComponentName};
19use ::re_types_core::{DeserializationError, DeserializationResult};
20
21/// **Archetype**: Define the style properties for one or more point series (scatter plot) in a chart.
22///
23/// This archetype only provides styling information.
24/// Changes over time are supported for most but not all its fields (see respective fields for details),
25/// it's generally recommended to log this type as static.
26///
27/// The underlying data needs to be logged to the same entity-path using [`archetypes::Scalars`][crate::archetypes::Scalars].
28/// Dimensionality of the scalar arrays logged at each time point is assumed to be the same over time.
29///
30/// ## Example
31///
32/// ### Point series
33/// ```ignore
34/// fn main() -> Result<(), Box<dyn std::error::Error>> {
35///     let rec = rerun::RecordingStreamBuilder::new("rerun_example_series_point_style").spawn()?;
36///
37///     // Set up plot styling:
38///     // They are logged static as they don't change over time and apply to all timelines.
39///     // Log two point series under a shared root so that they show in the same plot by default.
40///     rec.log_static(
41///         "trig/sin",
42///         &rerun::SeriesPoints::new()
43///             .with_colors([[255, 0, 0]])
44///             .with_names(["sin(0.01t)"])
45///             .with_markers([rerun::components::MarkerShape::Circle])
46///             .with_marker_sizes([4.0]),
47///     )?;
48///     rec.log_static(
49///         "trig/cos",
50///         &rerun::SeriesPoints::new()
51///             .with_colors([[0, 255, 0]])
52///             .with_names(["cos(0.01t)"])
53///             .with_markers([rerun::components::MarkerShape::Cross])
54///             .with_marker_sizes([2.0]),
55///     )?;
56///
57///     for t in 0..((std::f32::consts::TAU * 2.0 * 10.0) as i64) {
58///         rec.set_time_sequence("step", t);
59///
60///         // Log two time series under a shared root so that they show in the same plot by default.
61///         rec.log("trig/sin", &rerun::Scalars::single((t as f64 / 10.0).sin()))?;
62///         rec.log("trig/cos", &rerun::Scalars::single((t as f64 / 10.0).cos()))?;
63///     }
64///
65///     Ok(())
66/// }
67/// ```
68/// <center>
69/// <picture>
70///   <source media="(max-width: 480px)" srcset="https://static.rerun.io/series_point_style/82207a705da6c086b28ce161db1db9e8b12258b7/480w.png">
71///   <source media="(max-width: 768px)" srcset="https://static.rerun.io/series_point_style/82207a705da6c086b28ce161db1db9e8b12258b7/768w.png">
72///   <source media="(max-width: 1024px)" srcset="https://static.rerun.io/series_point_style/82207a705da6c086b28ce161db1db9e8b12258b7/1024w.png">
73///   <source media="(max-width: 1200px)" srcset="https://static.rerun.io/series_point_style/82207a705da6c086b28ce161db1db9e8b12258b7/1200w.png">
74///   <img src="https://static.rerun.io/series_point_style/82207a705da6c086b28ce161db1db9e8b12258b7/full.png" width="640">
75/// </picture>
76/// </center>
77#[derive(Clone, Debug, Default)]
78pub struct SeriesPoints {
79    /// Color for the corresponding series.
80    ///
81    /// May change over time, but can cause discontinuities in the line.
82    pub colors: Option<SerializedComponentBatch>,
83
84    /// What shape to use to represent the point
85    ///
86    /// May change over time.
87    pub markers: Option<SerializedComponentBatch>,
88
89    /// Display name of the series.
90    ///
91    /// Used in the legend. Expected to be unchanging over time.
92    pub names: Option<SerializedComponentBatch>,
93
94    /// Which lines are visible.
95    ///
96    /// If not set, all line series on this entity are visible.
97    /// Unlike with the regular visibility property of the entire entity, any series that is hidden
98    /// via this property will still be visible in the legend.
99    ///
100    /// May change over time.
101    pub visible_series: Option<SerializedComponentBatch>,
102
103    /// Sizes of the markers.
104    ///
105    /// May change over time.
106    pub marker_sizes: Option<SerializedComponentBatch>,
107}
108
109impl SeriesPoints {
110    /// Returns the [`ComponentDescriptor`] for [`Self::colors`].
111    #[inline]
112    pub fn descriptor_colors() -> ComponentDescriptor {
113        ComponentDescriptor {
114            archetype_name: Some("rerun.archetypes.SeriesPoints".into()),
115            component_name: "rerun.components.Color".into(),
116            archetype_field_name: Some("colors".into()),
117        }
118    }
119
120    /// Returns the [`ComponentDescriptor`] for [`Self::markers`].
121    #[inline]
122    pub fn descriptor_markers() -> ComponentDescriptor {
123        ComponentDescriptor {
124            archetype_name: Some("rerun.archetypes.SeriesPoints".into()),
125            component_name: "rerun.components.MarkerShape".into(),
126            archetype_field_name: Some("markers".into()),
127        }
128    }
129
130    /// Returns the [`ComponentDescriptor`] for [`Self::names`].
131    #[inline]
132    pub fn descriptor_names() -> ComponentDescriptor {
133        ComponentDescriptor {
134            archetype_name: Some("rerun.archetypes.SeriesPoints".into()),
135            component_name: "rerun.components.Name".into(),
136            archetype_field_name: Some("names".into()),
137        }
138    }
139
140    /// Returns the [`ComponentDescriptor`] for [`Self::visible_series`].
141    #[inline]
142    pub fn descriptor_visible_series() -> ComponentDescriptor {
143        ComponentDescriptor {
144            archetype_name: Some("rerun.archetypes.SeriesPoints".into()),
145            component_name: "rerun.components.SeriesVisible".into(),
146            archetype_field_name: Some("visible_series".into()),
147        }
148    }
149
150    /// Returns the [`ComponentDescriptor`] for [`Self::marker_sizes`].
151    #[inline]
152    pub fn descriptor_marker_sizes() -> ComponentDescriptor {
153        ComponentDescriptor {
154            archetype_name: Some("rerun.archetypes.SeriesPoints".into()),
155            component_name: "rerun.components.MarkerSize".into(),
156            archetype_field_name: Some("marker_sizes".into()),
157        }
158    }
159
160    /// Returns the [`ComponentDescriptor`] for the associated indicator component.
161    #[inline]
162    pub fn descriptor_indicator() -> ComponentDescriptor {
163        ComponentDescriptor {
164            archetype_name: Some("rerun.archetypes.SeriesPoints".into()),
165            component_name: "rerun.components.SeriesPointsIndicator".into(),
166            archetype_field_name: None,
167        }
168    }
169}
170
171static REQUIRED_COMPONENTS: once_cell::sync::Lazy<[ComponentDescriptor; 0usize]> =
172    once_cell::sync::Lazy::new(|| []);
173
174static RECOMMENDED_COMPONENTS: once_cell::sync::Lazy<[ComponentDescriptor; 1usize]> =
175    once_cell::sync::Lazy::new(|| [SeriesPoints::descriptor_indicator()]);
176
177static OPTIONAL_COMPONENTS: once_cell::sync::Lazy<[ComponentDescriptor; 5usize]> =
178    once_cell::sync::Lazy::new(|| {
179        [
180            SeriesPoints::descriptor_colors(),
181            SeriesPoints::descriptor_markers(),
182            SeriesPoints::descriptor_names(),
183            SeriesPoints::descriptor_visible_series(),
184            SeriesPoints::descriptor_marker_sizes(),
185        ]
186    });
187
188static ALL_COMPONENTS: once_cell::sync::Lazy<[ComponentDescriptor; 6usize]> =
189    once_cell::sync::Lazy::new(|| {
190        [
191            SeriesPoints::descriptor_indicator(),
192            SeriesPoints::descriptor_colors(),
193            SeriesPoints::descriptor_markers(),
194            SeriesPoints::descriptor_names(),
195            SeriesPoints::descriptor_visible_series(),
196            SeriesPoints::descriptor_marker_sizes(),
197        ]
198    });
199
200impl SeriesPoints {
201    /// The total number of components in the archetype: 0 required, 1 recommended, 5 optional
202    pub const NUM_COMPONENTS: usize = 6usize;
203}
204
205/// Indicator component for the [`SeriesPoints`] [`::re_types_core::Archetype`]
206pub type SeriesPointsIndicator = ::re_types_core::GenericIndicatorComponent<SeriesPoints>;
207
208impl ::re_types_core::Archetype for SeriesPoints {
209    type Indicator = SeriesPointsIndicator;
210
211    #[inline]
212    fn name() -> ::re_types_core::ArchetypeName {
213        "rerun.archetypes.SeriesPoints".into()
214    }
215
216    #[inline]
217    fn display_name() -> &'static str {
218        "Series points"
219    }
220
221    #[inline]
222    fn indicator() -> SerializedComponentBatch {
223        #[allow(clippy::unwrap_used)]
224        SeriesPointsIndicator::DEFAULT.serialized().unwrap()
225    }
226
227    #[inline]
228    fn required_components() -> ::std::borrow::Cow<'static, [ComponentDescriptor]> {
229        REQUIRED_COMPONENTS.as_slice().into()
230    }
231
232    #[inline]
233    fn recommended_components() -> ::std::borrow::Cow<'static, [ComponentDescriptor]> {
234        RECOMMENDED_COMPONENTS.as_slice().into()
235    }
236
237    #[inline]
238    fn optional_components() -> ::std::borrow::Cow<'static, [ComponentDescriptor]> {
239        OPTIONAL_COMPONENTS.as_slice().into()
240    }
241
242    #[inline]
243    fn all_components() -> ::std::borrow::Cow<'static, [ComponentDescriptor]> {
244        ALL_COMPONENTS.as_slice().into()
245    }
246
247    #[inline]
248    fn from_arrow_components(
249        arrow_data: impl IntoIterator<Item = (ComponentDescriptor, arrow::array::ArrayRef)>,
250    ) -> DeserializationResult<Self> {
251        re_tracing::profile_function!();
252        use ::re_types_core::{Loggable as _, ResultExt as _};
253        let arrays_by_descr: ::nohash_hasher::IntMap<_, _> = arrow_data.into_iter().collect();
254        let colors = arrays_by_descr
255            .get(&Self::descriptor_colors())
256            .map(|array| SerializedComponentBatch::new(array.clone(), Self::descriptor_colors()));
257        let markers = arrays_by_descr
258            .get(&Self::descriptor_markers())
259            .map(|array| SerializedComponentBatch::new(array.clone(), Self::descriptor_markers()));
260        let names = arrays_by_descr
261            .get(&Self::descriptor_names())
262            .map(|array| SerializedComponentBatch::new(array.clone(), Self::descriptor_names()));
263        let visible_series = arrays_by_descr
264            .get(&Self::descriptor_visible_series())
265            .map(|array| {
266                SerializedComponentBatch::new(array.clone(), Self::descriptor_visible_series())
267            });
268        let marker_sizes = arrays_by_descr
269            .get(&Self::descriptor_marker_sizes())
270            .map(|array| {
271                SerializedComponentBatch::new(array.clone(), Self::descriptor_marker_sizes())
272            });
273        Ok(Self {
274            colors,
275            markers,
276            names,
277            visible_series,
278            marker_sizes,
279        })
280    }
281}
282
283impl ::re_types_core::AsComponents for SeriesPoints {
284    #[inline]
285    fn as_serialized_batches(&self) -> Vec<SerializedComponentBatch> {
286        use ::re_types_core::Archetype as _;
287        [
288            Some(Self::indicator()),
289            self.colors.clone(),
290            self.markers.clone(),
291            self.names.clone(),
292            self.visible_series.clone(),
293            self.marker_sizes.clone(),
294        ]
295        .into_iter()
296        .flatten()
297        .collect()
298    }
299}
300
301impl ::re_types_core::ArchetypeReflectionMarker for SeriesPoints {}
302
303impl SeriesPoints {
304    /// Create a new `SeriesPoints`.
305    #[inline]
306    pub fn new() -> Self {
307        Self {
308            colors: None,
309            markers: None,
310            names: None,
311            visible_series: None,
312            marker_sizes: None,
313        }
314    }
315
316    /// Update only some specific fields of a `SeriesPoints`.
317    #[inline]
318    pub fn update_fields() -> Self {
319        Self::default()
320    }
321
322    /// Clear all the fields of a `SeriesPoints`.
323    #[inline]
324    pub fn clear_fields() -> Self {
325        use ::re_types_core::Loggable as _;
326        Self {
327            colors: Some(SerializedComponentBatch::new(
328                crate::components::Color::arrow_empty(),
329                Self::descriptor_colors(),
330            )),
331            markers: Some(SerializedComponentBatch::new(
332                crate::components::MarkerShape::arrow_empty(),
333                Self::descriptor_markers(),
334            )),
335            names: Some(SerializedComponentBatch::new(
336                crate::components::Name::arrow_empty(),
337                Self::descriptor_names(),
338            )),
339            visible_series: Some(SerializedComponentBatch::new(
340                crate::components::SeriesVisible::arrow_empty(),
341                Self::descriptor_visible_series(),
342            )),
343            marker_sizes: Some(SerializedComponentBatch::new(
344                crate::components::MarkerSize::arrow_empty(),
345                Self::descriptor_marker_sizes(),
346            )),
347        }
348    }
349
350    /// Partitions the component data into multiple sub-batches.
351    ///
352    /// Specifically, this transforms the existing [`SerializedComponentBatch`]es data into [`SerializedComponentColumn`]s
353    /// instead, via [`SerializedComponentBatch::partitioned`].
354    ///
355    /// This makes it possible to use `RecordingStream::send_columns` to send columnar data directly into Rerun.
356    ///
357    /// The specified `lengths` must sum to the total length of the component batch.
358    ///
359    /// [`SerializedComponentColumn`]: [::re_types_core::SerializedComponentColumn]
360    #[inline]
361    pub fn columns<I>(
362        self,
363        _lengths: I,
364    ) -> SerializationResult<impl Iterator<Item = ::re_types_core::SerializedComponentColumn>>
365    where
366        I: IntoIterator<Item = usize> + Clone,
367    {
368        let columns = [
369            self.colors
370                .map(|colors| colors.partitioned(_lengths.clone()))
371                .transpose()?,
372            self.markers
373                .map(|markers| markers.partitioned(_lengths.clone()))
374                .transpose()?,
375            self.names
376                .map(|names| names.partitioned(_lengths.clone()))
377                .transpose()?,
378            self.visible_series
379                .map(|visible_series| visible_series.partitioned(_lengths.clone()))
380                .transpose()?,
381            self.marker_sizes
382                .map(|marker_sizes| marker_sizes.partitioned(_lengths.clone()))
383                .transpose()?,
384        ];
385        Ok(columns
386            .into_iter()
387            .flatten()
388            .chain([::re_types_core::indicator_column::<Self>(
389                _lengths.into_iter().count(),
390            )?]))
391    }
392
393    /// Helper to partition the component data into unit-length sub-batches.
394    ///
395    /// This is semantically similar to calling [`Self::columns`] with `std::iter::take(1).repeat(n)`,
396    /// where `n` is automatically guessed.
397    #[inline]
398    pub fn columns_of_unit_batches(
399        self,
400    ) -> SerializationResult<impl Iterator<Item = ::re_types_core::SerializedComponentColumn>> {
401        let len_colors = self.colors.as_ref().map(|b| b.array.len());
402        let len_markers = self.markers.as_ref().map(|b| b.array.len());
403        let len_names = self.names.as_ref().map(|b| b.array.len());
404        let len_visible_series = self.visible_series.as_ref().map(|b| b.array.len());
405        let len_marker_sizes = self.marker_sizes.as_ref().map(|b| b.array.len());
406        let len = None
407            .or(len_colors)
408            .or(len_markers)
409            .or(len_names)
410            .or(len_visible_series)
411            .or(len_marker_sizes)
412            .unwrap_or(0);
413        self.columns(std::iter::repeat(1).take(len))
414    }
415
416    /// Color for the corresponding series.
417    ///
418    /// May change over time, but can cause discontinuities in the line.
419    #[inline]
420    pub fn with_colors(
421        mut self,
422        colors: impl IntoIterator<Item = impl Into<crate::components::Color>>,
423    ) -> Self {
424        self.colors = try_serialize_field(Self::descriptor_colors(), colors);
425        self
426    }
427
428    /// What shape to use to represent the point
429    ///
430    /// May change over time.
431    #[inline]
432    pub fn with_markers(
433        mut self,
434        markers: impl IntoIterator<Item = impl Into<crate::components::MarkerShape>>,
435    ) -> Self {
436        self.markers = try_serialize_field(Self::descriptor_markers(), markers);
437        self
438    }
439
440    /// Display name of the series.
441    ///
442    /// Used in the legend. Expected to be unchanging over time.
443    #[inline]
444    pub fn with_names(
445        mut self,
446        names: impl IntoIterator<Item = impl Into<crate::components::Name>>,
447    ) -> Self {
448        self.names = try_serialize_field(Self::descriptor_names(), names);
449        self
450    }
451
452    /// Which lines are visible.
453    ///
454    /// If not set, all line series on this entity are visible.
455    /// Unlike with the regular visibility property of the entire entity, any series that is hidden
456    /// via this property will still be visible in the legend.
457    ///
458    /// May change over time.
459    #[inline]
460    pub fn with_visible_series(
461        mut self,
462        visible_series: impl IntoIterator<Item = impl Into<crate::components::SeriesVisible>>,
463    ) -> Self {
464        self.visible_series =
465            try_serialize_field(Self::descriptor_visible_series(), visible_series);
466        self
467    }
468
469    /// Sizes of the markers.
470    ///
471    /// May change over time.
472    #[inline]
473    pub fn with_marker_sizes(
474        mut self,
475        marker_sizes: impl IntoIterator<Item = impl Into<crate::components::MarkerSize>>,
476    ) -> Self {
477        self.marker_sizes = try_serialize_field(Self::descriptor_marker_sizes(), marker_sizes);
478        self
479    }
480}
481
482impl ::re_byte_size::SizeBytes for SeriesPoints {
483    #[inline]
484    fn heap_size_bytes(&self) -> u64 {
485        self.colors.heap_size_bytes()
486            + self.markers.heap_size_bytes()
487            + self.names.heap_size_bytes()
488            + self.visible_series.heap_size_bytes()
489            + self.marker_sizes.heap_size_bytes()
490    }
491}