Skip to content

Commit 29a152e

Browse files
committed
simplify fallback
1 parent 9016abd commit 29a152e

File tree

2 files changed

+8
-32
lines changed

2 files changed

+8
-32
lines changed

crates/viewer/re_component_fallbacks/src/component_fallbacks.rs

Lines changed: 1 addition & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -63,35 +63,7 @@ pub fn archetype_field_fallbacks(registry: &mut FallbackProviderRegistry) {
6363
);
6464
registry.register_component_fallback_provider(
6565
archetypes::BarChart::descriptor_widths().component,
66-
|ctx| {
67-
// This fallback is for widths - set all widths to 1.0
68-
69-
// Try to get the values tensor to determine the length
70-
if let Some(((_time, _row_id), tensor)) = ctx
71-
.recording()
72-
.latest_at_component::<components::TensorData>(
73-
ctx.target_entity_path,
74-
ctx.query,
75-
archetypes::BarChart::descriptor_values().component,
76-
)
77-
&& tensor.is_vector()
78-
{
79-
let shape = tensor.shape();
80-
if let Some(&length) = shape.first() {
81-
// Set all widths to 1.0
82-
let tensor_data = datatypes::TensorData::new(
83-
vec![length],
84-
datatypes::TensorBuffer::F32(vec![1.0; length as usize].into()),
85-
);
86-
return components::TensorData(tensor_data);
87-
}
88-
}
89-
90-
// Fallback to empty tensor if we can't determine the values length
91-
let tensor_data =
92-
datatypes::TensorData::new(vec![0u64], datatypes::TensorBuffer::I64(vec![].into()));
93-
components::TensorData(tensor_data)
94-
},
66+
|_| components::Length::from(1.0),
9567
);
9668

9769
// GraphNodes

crates/viewer/re_view_bar_chart/src/visualizer_system.rs

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,13 +4,13 @@ use re_chunk_store::LatestAtQuery;
44
use re_entity_db::EntityPath;
55
use re_types::{
66
archetypes::BarChart,
7-
components::{self},
7+
components::{self, Length},
88
datatypes,
99
};
1010
use re_view::{DataResultQuery as _, RangeResultsExt as _};
1111
use re_viewer_context::{
1212
IdentifiedViewSystem, ViewContext, ViewContextCollection, ViewQuery, ViewSystemExecutionError,
13-
VisualizerQueryInfo, VisualizerSystem,
13+
VisualizerQueryInfo, VisualizerSystem, typed_fallback_for,
1414
};
1515

1616
#[derive(Default)]
@@ -74,7 +74,11 @@ impl VisualizerSystem for BarChartVisualizerSystem {
7474
}
7575
widths
7676
} else {
77-
vec![1.0_f32; length as usize]
77+
let fallback_width: Length = typed_fallback_for(
78+
&ctx.query_context(data_result, &view_query.latest_at_query()),
79+
BarChart::descriptor_widths().component,
80+
);
81+
vec![fallback_width.0.into(); length as usize]
7882
};
7983
self.charts.insert(
8084
data_result.entity_path.clone(),

0 commit comments

Comments
 (0)