From f60e9e9d8ed10190dbf088e76b4c144ef9adc74d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Rados=C5=82aw=20Wa=C5=9Bko?= Date: Mon, 31 Oct 2022 15:20:13 +0100 Subject: [PATCH] Add a Visualization to the Table.Row type (#3837) Follow up to https://www.pivotaltracker.com/story/show/182307026 When working in the IDE I noticed that the default vis is bad, so this should make it better. --- .../Standard/Table/0.0.0-dev/src/Data/Row.enso | 15 +++++++++++++++ test/Table_Tests/src/Common_Table_Spec.enso | 8 ++++++++ 2 files changed, 23 insertions(+) diff --git a/distribution/lib/Standard/Table/0.0.0-dev/src/Data/Row.enso b/distribution/lib/Standard/Table/0.0.0-dev/src/Data/Row.enso index c6dbd7e6f9..56f24f637c 100644 --- a/distribution/lib/Standard/Table/0.0.0-dev/src/Data/Row.enso +++ b/distribution/lib/Standard/Table/0.0.0-dev/src/Data/Row.enso @@ -19,3 +19,18 @@ type Row ## Gets the row as a Vector. to_vector : Vector to_vector self = Vector.from_polyglot_array (Array_Proxy.from_proxy_object self) + + ## Converts this row into a JSON structure. + to_json : Json + to_json self = self.to_vector.to_json + + ## UNSTABLE + ADVANCED + + Returns a Text used to display this table in the IDE by default. + + Returns a JSON object containing useful metadata and previews of column + values. + to_default_visualization_data : Text + to_default_visualization_data self = + self.to_vector.to_default_visualization_data diff --git a/test/Table_Tests/src/Common_Table_Spec.enso b/test/Table_Tests/src/Common_Table_Spec.enso index fb8d222fb6..65e88b0409 100644 --- a/test/Table_Tests/src/Common_Table_Spec.enso +++ b/test/Table_Tests/src/Common_Table_Spec.enso @@ -1476,3 +1476,11 @@ spec prefix table_builder test_selection pending=Nothing = table.rows (max_rows=2) . at 2 . should_fail_with Index_Out_Of_Bounds_Error_Data table.rows . at 0 . at -4 . should_fail_with Index_Out_Of_Bounds_Error_Data table.rows . at 0 . at "unknown" . should_fail_with No_Such_Column_Error_Data + + Test.specify "should visualize nicely" <| + table.rows . to_default_visualization_data . should_equal <| + '[[1,5,"A"],[2,6,"B"],[3,7,"C"],[4,8,"D"]]' + + # We limit to at most 100 rows, in the future we should add some kind of 'and N more rows' to the visualization, like is done for Table - or just integrate the lazy vis. + t2 = table_builder [["X", 0.up_to 200 . to_vector]] + t2.rows.to_default_visualization_data . should_equal (0.up_to 100 . map (x -> [x])).to_default_visualization_data