Skip to content

Commit

Permalink
Implement workaround for missing default visualisation functionality,
Browse files Browse the repository at this point in the history
  • Loading branch information
MichaelMauderer committed Feb 3, 2023
1 parent 349cc21 commit 4aba000
Show file tree
Hide file tree
Showing 3 changed files with 30 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ loadStyleFromString(scrollbarStyle)
// ===========================

class TableVisualization extends Visualization {
static inputType = 'Any'
static inputType = 'Standard.Table.Data.Table.Table'
static label = 'Table'

constructor(data) {
Expand Down
14 changes: 11 additions & 3 deletions app/gui/view/graph-editor/src/component/visualization/container.rs
Original file line number Diff line number Diff line change
Expand Up @@ -449,7 +449,8 @@ impl ContainerModel {
vis_list.iter().skip_while(|x| vis.signature.path != x.signature.path);
from_current.nth(1)
});
next_on_list.or_else(|| vis_list.first()).cloned()
let result = next_on_list.or_else(|| vis_list.first()).cloned();
result
}
}

Expand Down Expand Up @@ -499,6 +500,13 @@ impl Container {
frp::extend! { network
eval frp.set_visibility ((v) model.set_visibility(*v));
eval_ frp.toggle_visibility (model.toggle_visibility());

visualisation_uninitialised <- frp.set_visualization.map(|t| t.is_none());
set_default_visualisation <- frp.set_vis_input_type.gate(&visualisation_uninitialised).unwrap();
default_visualisation <- set_default_visualisation.map(f!((tp) {
registry.default_visualization_for_type(tp)
}));

eval frp.set_data ((t) model.set_visualization_data(t));
frp.source.size <+ frp.set_size;
frp.source.visible <+ frp.set_visibility;
Expand All @@ -524,7 +532,7 @@ impl Container {
// === Switching Visualizations ===

frp::extend! { network
new_vis_definition <- any(frp.set_visualization,vis_after_cycling);
new_vis_definition <- any(frp.set_visualization,vis_after_cycling,default_visualisation);
let preprocessor = &frp.source.preprocessor;
frp.source.visualisation <+ new_vis_definition.map(f!(
[model,action_bar,app,preprocessor](vis_definition) {
Expand Down Expand Up @@ -661,7 +669,7 @@ impl Container {
// This is not optimal the optimal solution to this problem, as it also means that we have
// an animation on an invisible component running.
frp.set_size.emit(Vector2(DEFAULT_SIZE.0, DEFAULT_SIZE.1));
frp.set_visualization.emit(Some(visualization::Registry::default_visualisation()));
frp.set_visualization.emit(None);
self
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,19 @@ impl Registry {
result
}

/// Return the `visualization::Definition` that should be used as default for the given type.
pub fn default_visualization_for_type(
&self,
tp: &enso::Type,
) -> Option<visualization::Definition> {
// Visualisations are order by "matching the type" first, followed by and then "matching any
// type". So we just take the first one, which should be the most appropriate one.
// This should be replaced with the proper solution described in
// https://www.pivotaltracker.com/story/show/184390437
let valid_sources = self.valid_sources(tp);
valid_sources.into_iter().next()
}

/// Return the `visualization::Definition` registered for the given `visualization::Path`.
pub fn definition_from_path(
&self,
Expand All @@ -92,15 +105,19 @@ impl Registry {

/// Add default visualizations to the registry.
pub fn add_default_visualizations(&self) {
// Note that the order is important. Visualisations that are added first will be
// prioritised as default (as long as they have a matching type to the value they will
// represent.
self.add(builtin::visualization::native::text_visualization::text_visualisation());
self.try_add_java_script(builtin::visualization::java_script::table_visualization());
self.try_add_java_script(builtin::visualization::java_script::scatter_plot_visualization());
self.try_add_java_script(builtin::visualization::java_script::histogram_visualization());
self.try_add_java_script(builtin::visualization::java_script::heatmap_visualization());
self.try_add_java_script(builtin::visualization::java_script::table_visualization());
self.try_add_java_script(builtin::visualization::java_script::sql_visualization());
self.try_add_java_script(builtin::visualization::java_script::geo_map_visualization());
self.try_add_java_script(builtin::visualization::java_script::image_base64_visualization());
self.try_add_java_script(builtin::visualization::java_script::warnings_visualization());
self.add(builtin::visualization::native::text_visualization::text_visualisation());
}

/// Return a default visualisation definition.
Expand Down

0 comments on commit 4aba000

Please sign in to comment.