2021-03-25 19:47:22 +03:00
|
|
|
|
from Standard.Base import all
|
|
|
|
|
|
2024-09-20 18:48:28 +03:00
|
|
|
|
from Standard.Table import Table, Column, Value_Type
|
2022-07-27 16:28:00 +03:00
|
|
|
|
|
2021-03-25 19:47:22 +03:00
|
|
|
|
import Standard.Visualization.Scatter_Plot
|
|
|
|
|
|
2024-02-08 14:25:13 +03:00
|
|
|
|
from Standard.Test import all
|
2024-02-07 16:22:17 +03:00
|
|
|
|
|
2022-07-27 16:28:00 +03:00
|
|
|
|
|
2021-06-24 13:42:24 +03:00
|
|
|
|
import project
|
2021-03-25 19:47:22 +03:00
|
|
|
|
|
2024-02-07 16:22:17 +03:00
|
|
|
|
add_specs suite_builder =
|
2024-09-24 12:14:39 +03:00
|
|
|
|
expect_text text axis_expected_text data_expected_text row_method is_multi =
|
2021-03-25 19:47:22 +03:00
|
|
|
|
json = Json.parse text
|
2024-09-24 12:14:39 +03:00
|
|
|
|
json.field_names.should_equal ['data', 'axis', 'is_multi_series', 'get_row_method', 'x_value_type']
|
2022-12-20 13:33:46 +03:00
|
|
|
|
|
2024-09-24 12:14:39 +03:00
|
|
|
|
expect_text = '{"axis": ' + axis_expected_text + ', "data": ' + data_expected_text + ', "is_multi_series": ' + is_multi + ', "get_row_method": ' + row_method + ', "x_value_type": "Integer"' + '}'
|
2022-12-20 13:33:46 +03:00
|
|
|
|
expected_result = Json.parse expect_text
|
2021-03-25 19:47:22 +03:00
|
|
|
|
|
|
|
|
|
json.should_equal expected_result
|
|
|
|
|
|
2024-09-24 12:14:39 +03:00
|
|
|
|
expect value axis_expected_text data_expected_text row_method (is_multi='false') =
|
2022-08-23 15:12:22 +03:00
|
|
|
|
text = Scatter_Plot.process_to_json_text value
|
2024-09-24 12:14:39 +03:00
|
|
|
|
expect_text text axis_expected_text data_expected_text row_method is_multi
|
2022-08-23 15:12:22 +03:00
|
|
|
|
|
2021-03-25 19:47:22 +03:00
|
|
|
|
index = Scatter_Plot.index_name
|
2022-12-20 13:33:46 +03:00
|
|
|
|
axis label = JS_Object.from_pairs [['label',label]]
|
|
|
|
|
labels x y = JS_Object.from_pairs [['x', axis x], ['y', axis y]] . to_text
|
2024-08-28 16:39:55 +03:00
|
|
|
|
labels_multi x y z = JS_Object.from_pairs [['x', axis x], ['y', axis y], ['(y_multi 0)', axis z]] . to_text
|
2021-03-25 19:47:22 +03:00
|
|
|
|
no_labels = 'null'
|
|
|
|
|
|
2024-02-07 16:22:17 +03:00
|
|
|
|
suite_builder.group "Scatter Plot Visualization" group_builder->
|
2024-08-28 16:39:55 +03:00
|
|
|
|
group_builder.specify "plots left most column for x if numeric" <|
|
2021-03-25 19:47:22 +03:00
|
|
|
|
header = ['α', 'ω']
|
|
|
|
|
row_1 = [11 , 10 ]
|
|
|
|
|
row_2 = [21 , 20 ]
|
|
|
|
|
table = Table.from_rows header [row_1, row_2]
|
2024-09-24 12:14:39 +03:00
|
|
|
|
expect table (labels 'α' 'ω') '[{"x":11,"y":10, "row_number": 0},{"x":21,"y":20, "row_number": 1}]' '"get_row"'
|
2021-04-28 12:47:57 +03:00
|
|
|
|
|
2024-02-07 16:22:17 +03:00
|
|
|
|
group_builder.specify "recognizes all relevant columns" <|
|
2021-03-25 19:47:22 +03:00
|
|
|
|
header = ['x' , 'y' , 'size' , 'shape' , 'label' , 'color' ]
|
|
|
|
|
row_1 = [11 , 10 , 50 , 'square' , 'label' , 'ff0000']
|
|
|
|
|
table = Table.from_rows header [row_1]
|
2024-09-24 12:14:39 +03:00
|
|
|
|
expect table (labels 'x' 'y') '[{"color":"ff0000","label":"label","shape":"square","size":50,"x":11,"y":10, "row_number": 0}]' '"get_row"'
|
2021-04-28 12:47:57 +03:00
|
|
|
|
|
2024-02-07 16:22:17 +03:00
|
|
|
|
group_builder.specify "is case-insensitive" <|
|
2021-04-01 11:05:17 +03:00
|
|
|
|
header = ['X' , 'Y' , 'Size' , 'Shape' , 'Label' , 'Color' ]
|
|
|
|
|
row_1 = [11 , 10 , 50 , 'square' , 'label' , 'ff0000']
|
|
|
|
|
table = Table.from_rows header [row_1]
|
2024-09-24 12:14:39 +03:00
|
|
|
|
expect table (labels 'X' 'Y') '[{"color":"ff0000","label":"label","shape":"square","size":50,"x":11,"y":10, "row_number": 0}]' '"get_row"'
|
2021-04-28 12:47:57 +03:00
|
|
|
|
|
2024-02-07 16:22:17 +03:00
|
|
|
|
group_builder.specify "uses first unrecognized numeric column as `y` fallback" <|
|
2021-03-25 19:47:22 +03:00
|
|
|
|
header = ['x' , 'size' , 'name' , 'z' , 'ω']
|
|
|
|
|
row_1 = [11 , 50 , 'circul' , 20 , 30]
|
|
|
|
|
table = Table.from_rows header [row_1]
|
2024-09-24 12:14:39 +03:00
|
|
|
|
expect table (labels_multi 'x' 'z' 'ω') '[{"size":50,"x":11,"y":20,"(y_multi 0)":30, "row_number": 0}]' '"get_row"' 'true'
|
2021-03-25 19:47:22 +03:00
|
|
|
|
|
2024-02-07 16:22:17 +03:00
|
|
|
|
group_builder.specify "provided only recognized columns" <|
|
2021-03-25 19:47:22 +03:00
|
|
|
|
header = ['x', 'y' , 'bar' , 'size']
|
|
|
|
|
row_1 = [11 , 10 , 'aa' , 40 ]
|
|
|
|
|
row_2 = [21 , 20 , 'bb' , 50 ]
|
|
|
|
|
table = Table.from_rows header [row_1, row_2]
|
2024-09-24 12:14:39 +03:00
|
|
|
|
expect table (labels 'x' 'y') '[{"size":40,"x":11,"y":10, "row_number": 0},{"size":50,"x":21,"y":20, "row_number": 1}]' '"get_row"'
|
2021-03-25 19:47:22 +03:00
|
|
|
|
|
2024-02-07 16:22:17 +03:00
|
|
|
|
group_builder.specify "provided only recognized columns within bounds" <|
|
2022-08-23 15:12:22 +03:00
|
|
|
|
header = ['x', 'y' , 'bar' , 'size']
|
|
|
|
|
row_1 = [1 , 1 , '11' , 30 ]
|
|
|
|
|
row_2 = [11 , 10 , 'aa' , 40 ]
|
|
|
|
|
row_3 = [21 , 20 , 'bb' , 50 ]
|
|
|
|
|
row_4 = [31 , 30 , 'cc' , 60 ]
|
|
|
|
|
table = Table.from_rows header [row_1, row_2, row_3, row_4]
|
|
|
|
|
bounds = [0,5,25,25]
|
|
|
|
|
text = Scatter_Plot.process_to_json_text table bounds
|
2024-09-24 12:14:39 +03:00
|
|
|
|
expect_text text (labels 'x' 'y') '[{"size":40,"x":11,"y":10, "row_number": 0},{"size":50,"x":21,"y":20, "row_number": 1}]' '"get_row"'
|
2022-08-23 15:12:22 +03:00
|
|
|
|
|
2024-02-07 16:22:17 +03:00
|
|
|
|
group_builder.specify "used default index for `x` if none set" <|
|
2021-03-25 19:47:22 +03:00
|
|
|
|
header = [ 'y' , 'bar' , 'size']
|
|
|
|
|
row_1 = [ 10 , 'aa' , 40 ]
|
|
|
|
|
row_2 = [ 20 , 'bb' , 50 ]
|
|
|
|
|
table = Table.from_rows header [row_1, row_2]
|
2024-09-24 12:14:39 +03:00
|
|
|
|
expect table (labels index 'y') '[{"size":40,"x":0,"y":10, "row_number": 0},{"size":50,"x":1,"y":20, "row_number": 1}]' '"get_row"'
|
2021-03-25 19:47:22 +03:00
|
|
|
|
|
2024-02-07 16:22:17 +03:00
|
|
|
|
group_builder.specify "using indices for x if given a vector" <|
|
2021-03-25 19:47:22 +03:00
|
|
|
|
vector = [0,10,20]
|
2024-09-24 12:14:39 +03:00
|
|
|
|
expect vector no_labels '[{"x":0,"y":0, "row_number": 0},{"x":1,"y":10, "row_number": 1},{"x":2,"y":20, "row_number": 2}]' '"at"'
|
2021-03-25 19:47:22 +03:00
|
|
|
|
|
2024-02-07 16:22:17 +03:00
|
|
|
|
group_builder.specify "limit the number of elements" <|
|
2022-08-23 15:12:22 +03:00
|
|
|
|
vector = [0,10,20,30]
|
|
|
|
|
text = Scatter_Plot.process_to_json_text vector limit=2
|
|
|
|
|
json = Json.parse text
|
2024-09-24 12:14:39 +03:00
|
|
|
|
json.field_names.should_equal ['data','axis', 'is_multi_series', 'get_row_method', 'x_value_type']
|
2022-12-20 13:33:46 +03:00
|
|
|
|
data = json.get 'data'
|
2023-01-30 19:48:06 +03:00
|
|
|
|
data.should_be_a Vector
|
2022-12-20 13:33:46 +03:00
|
|
|
|
data.length . should_equal 2
|
2022-08-23 15:12:22 +03:00
|
|
|
|
|
2024-02-07 16:22:17 +03:00
|
|
|
|
group_builder.specify "limit the number of squared elements" <|
|
2022-08-23 15:12:22 +03:00
|
|
|
|
vector = (-15).up_to 15 . map (x -> x * x)
|
|
|
|
|
text = Scatter_Plot.process_to_json_text vector limit=10
|
|
|
|
|
json = Json.parse text
|
2024-09-24 12:14:39 +03:00
|
|
|
|
json.field_names.should_equal ['data','axis', 'is_multi_series', 'get_row_method', 'x_value_type']
|
2022-12-20 13:33:46 +03:00
|
|
|
|
data = json.get 'data'
|
2023-01-30 19:48:06 +03:00
|
|
|
|
data.should_be_a Vector
|
2022-08-23 15:12:22 +03:00
|
|
|
|
data.length . should_equal 10
|
2024-09-24 12:14:39 +03:00
|
|
|
|
(data.take (..First 3) . sort on=(_.get "x")).to_text . should_equal '[{"x":0,"y":225,"row_number":0}, {"x":15,"y":0,"row_number":15}, {"x":29,"y":196,"row_number":29}]'
|
2022-08-23 15:12:22 +03:00
|
|
|
|
|
2024-02-07 16:22:17 +03:00
|
|
|
|
group_builder.specify "filter the elements" <|
|
2022-08-23 15:12:22 +03:00
|
|
|
|
vector = [0,10,20,30]
|
|
|
|
|
bounds = [0,5,10,25]
|
|
|
|
|
text = Scatter_Plot.process_to_json_text vector bounds
|
2024-09-24 12:14:39 +03:00
|
|
|
|
expect_text text no_labels '[{"x":1,"y":10, "row_number": 0},{"x":2,"y":20, "row_number": 1}]' '"at"'
|
2022-08-23 15:12:22 +03:00
|
|
|
|
|
2024-02-07 16:22:17 +03:00
|
|
|
|
group_builder.specify "using indices for x if given a range" <|
|
2021-04-28 12:47:57 +03:00
|
|
|
|
value = 2.up_to 5
|
2024-09-24 12:14:39 +03:00
|
|
|
|
expect value no_labels '[{"x":0,"y":2, "row_number": 0},{"x":1,"y":3, "row_number": 1},{"x":2,"y":4, "row_number": 2}]' '"at"'
|
2022-08-23 15:12:22 +03:00
|
|
|
|
|
2024-02-22 15:31:44 +03:00
|
|
|
|
main filter=Nothing =
|
2024-02-07 16:22:17 +03:00
|
|
|
|
suite = Test.build suite_builder->
|
|
|
|
|
add_specs suite_builder
|
2024-02-22 15:31:44 +03:00
|
|
|
|
suite.run_with_filter filter
|