re_types/archetypes/
bar_chart.rs1#![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#[derive(Clone, Debug, PartialEq, Default)]
51pub struct BarChart {
52 pub values: Option<SerializedComponentBatch>,
54
55 pub color: Option<SerializedComponentBatch>,
57}
58
59impl BarChart {
60 #[inline]
64 pub fn descriptor_values() -> ComponentDescriptor {
65 ComponentDescriptor {
66 archetype: Some("rerun.archetypes.BarChart".into()),
67 component: "BarChart:values".into(),
68 component_type: Some("rerun.components.TensorData".into()),
69 }
70 }
71
72 #[inline]
76 pub fn descriptor_color() -> ComponentDescriptor {
77 ComponentDescriptor {
78 archetype: Some("rerun.archetypes.BarChart".into()),
79 component: "BarChart:color".into(),
80 component_type: Some("rerun.components.Color".into()),
81 }
82 }
83}
84
85static REQUIRED_COMPONENTS: once_cell::sync::Lazy<[ComponentDescriptor; 1usize]> =
86 once_cell::sync::Lazy::new(|| [BarChart::descriptor_values()]);
87
88static RECOMMENDED_COMPONENTS: once_cell::sync::Lazy<[ComponentDescriptor; 0usize]> =
89 once_cell::sync::Lazy::new(|| []);
90
91static OPTIONAL_COMPONENTS: once_cell::sync::Lazy<[ComponentDescriptor; 1usize]> =
92 once_cell::sync::Lazy::new(|| [BarChart::descriptor_color()]);
93
94static ALL_COMPONENTS: once_cell::sync::Lazy<[ComponentDescriptor; 2usize]> =
95 once_cell::sync::Lazy::new(|| [BarChart::descriptor_values(), BarChart::descriptor_color()]);
96
97impl BarChart {
98 pub const NUM_COMPONENTS: usize = 2usize;
100}
101
102impl ::re_types_core::Archetype for BarChart {
103 #[inline]
104 fn name() -> ::re_types_core::ArchetypeName {
105 "rerun.archetypes.BarChart".into()
106 }
107
108 #[inline]
109 fn display_name() -> &'static str {
110 "Bar chart"
111 }
112
113 #[inline]
114 fn required_components() -> ::std::borrow::Cow<'static, [ComponentDescriptor]> {
115 REQUIRED_COMPONENTS.as_slice().into()
116 }
117
118 #[inline]
119 fn recommended_components() -> ::std::borrow::Cow<'static, [ComponentDescriptor]> {
120 RECOMMENDED_COMPONENTS.as_slice().into()
121 }
122
123 #[inline]
124 fn optional_components() -> ::std::borrow::Cow<'static, [ComponentDescriptor]> {
125 OPTIONAL_COMPONENTS.as_slice().into()
126 }
127
128 #[inline]
129 fn all_components() -> ::std::borrow::Cow<'static, [ComponentDescriptor]> {
130 ALL_COMPONENTS.as_slice().into()
131 }
132
133 #[inline]
134 fn from_arrow_components(
135 arrow_data: impl IntoIterator<Item = (ComponentDescriptor, arrow::array::ArrayRef)>,
136 ) -> DeserializationResult<Self> {
137 re_tracing::profile_function!();
138 use ::re_types_core::{Loggable as _, ResultExt as _};
139 let arrays_by_descr: ::nohash_hasher::IntMap<_, _> = arrow_data.into_iter().collect();
140 let values = arrays_by_descr
141 .get(&Self::descriptor_values())
142 .map(|array| SerializedComponentBatch::new(array.clone(), Self::descriptor_values()));
143 let color = arrays_by_descr
144 .get(&Self::descriptor_color())
145 .map(|array| SerializedComponentBatch::new(array.clone(), Self::descriptor_color()));
146 Ok(Self { values, color })
147 }
148}
149
150impl ::re_types_core::AsComponents for BarChart {
151 #[inline]
152 fn as_serialized_batches(&self) -> Vec<SerializedComponentBatch> {
153 use ::re_types_core::Archetype as _;
154 [self.values.clone(), self.color.clone()]
155 .into_iter()
156 .flatten()
157 .collect()
158 }
159}
160
161impl ::re_types_core::ArchetypeReflectionMarker for BarChart {}
162
163impl BarChart {
164 #[inline]
166 pub fn new(values: impl Into<crate::components::TensorData>) -> Self {
167 Self {
168 values: try_serialize_field(Self::descriptor_values(), [values]),
169 color: None,
170 }
171 }
172
173 #[inline]
175 pub fn update_fields() -> Self {
176 Self::default()
177 }
178
179 #[inline]
181 pub fn clear_fields() -> Self {
182 use ::re_types_core::Loggable as _;
183 Self {
184 values: Some(SerializedComponentBatch::new(
185 crate::components::TensorData::arrow_empty(),
186 Self::descriptor_values(),
187 )),
188 color: Some(SerializedComponentBatch::new(
189 crate::components::Color::arrow_empty(),
190 Self::descriptor_color(),
191 )),
192 }
193 }
194
195 #[inline]
206 pub fn columns<I>(
207 self,
208 _lengths: I,
209 ) -> SerializationResult<impl Iterator<Item = ::re_types_core::SerializedComponentColumn>>
210 where
211 I: IntoIterator<Item = usize> + Clone,
212 {
213 let columns = [
214 self.values
215 .map(|values| values.partitioned(_lengths.clone()))
216 .transpose()?,
217 self.color
218 .map(|color| color.partitioned(_lengths.clone()))
219 .transpose()?,
220 ];
221 Ok(columns.into_iter().flatten())
222 }
223
224 #[inline]
229 pub fn columns_of_unit_batches(
230 self,
231 ) -> SerializationResult<impl Iterator<Item = ::re_types_core::SerializedComponentColumn>> {
232 let len_values = self.values.as_ref().map(|b| b.array.len());
233 let len_color = self.color.as_ref().map(|b| b.array.len());
234 let len = None.or(len_values).or(len_color).unwrap_or(0);
235 self.columns(std::iter::repeat(1).take(len))
236 }
237
238 #[inline]
240 pub fn with_values(mut self, values: impl Into<crate::components::TensorData>) -> Self {
241 self.values = try_serialize_field(Self::descriptor_values(), [values]);
242 self
243 }
244
245 #[inline]
250 pub fn with_many_values(
251 mut self,
252 values: impl IntoIterator<Item = impl Into<crate::components::TensorData>>,
253 ) -> Self {
254 self.values = try_serialize_field(Self::descriptor_values(), values);
255 self
256 }
257
258 #[inline]
260 pub fn with_color(mut self, color: impl Into<crate::components::Color>) -> Self {
261 self.color = try_serialize_field(Self::descriptor_color(), [color]);
262 self
263 }
264
265 #[inline]
270 pub fn with_many_color(
271 mut self,
272 color: impl IntoIterator<Item = impl Into<crate::components::Color>>,
273 ) -> Self {
274 self.color = try_serialize_field(Self::descriptor_color(), color);
275 self
276 }
277}
278
279impl ::re_byte_size::SizeBytes for BarChart {
280 #[inline]
281 fn heap_size_bytes(&self) -> u64 {
282 self.values.heap_size_bytes() + self.color.heap_size_bytes()
283 }
284}