diff --git a/app/gui/view/graph-editor/src/builtin/visualization/java_script/table.js b/app/gui/view/graph-editor/src/builtin/visualization/java_script/table.js index a9e0ccd5be8d..b9e70f14b660 100644 --- a/app/gui/view/graph-editor/src/builtin/visualization/java_script/table.js +++ b/app/gui/view/graph-editor/src/builtin/visualization/java_script/table.js @@ -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) { diff --git a/app/gui/view/graph-editor/src/component/visualization/container.rs b/app/gui/view/graph-editor/src/component/visualization/container.rs index 7e394d67925f..04020320fb9d 100644 --- a/app/gui/view/graph-editor/src/component/visualization/container.rs +++ b/app/gui/view/graph-editor/src/component/visualization/container.rs @@ -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 } } @@ -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; @@ -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) { @@ -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 } diff --git a/app/gui/view/graph-editor/src/component/visualization/registry.rs b/app/gui/view/graph-editor/src/component/visualization/registry.rs index 4b601b51ce49..08e5d28c7698 100644 --- a/app/gui/view/graph-editor/src/component/visualization/registry.rs +++ b/app/gui/view/graph-editor/src/component/visualization/registry.rs @@ -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 { + // 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, @@ -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.