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