From c08cfb9c6f734faad139c59e84371a7a4785e086 Mon Sep 17 00:00:00 2001 From: Jon Mease Date: Sat, 31 Dec 2022 19:20:40 -0500 Subject: [PATCH 1/2] Add missing sin expression function --- vegafusion-core/src/expression/supported.rs | 2 +- .../src/expression/compiler/call.rs | 2 +- .../tests/specs/custom/sin_cos.comm_plan.json | 20 ++ .../tests/specs/custom/sin_cos.vg.json | 213 ++++++++++++++++++ .../tests/test_image_comparison.rs | 3 +- 5 files changed, 237 insertions(+), 3 deletions(-) create mode 100644 vegafusion-rt-datafusion/tests/specs/custom/sin_cos.comm_plan.json create mode 100644 vegafusion-rt-datafusion/tests/specs/custom/sin_cos.vg.json diff --git a/vegafusion-core/src/expression/supported.rs b/vegafusion-core/src/expression/supported.rs index c89d95128..288c38374 100644 --- a/vegafusion-core/src/expression/supported.rs +++ b/vegafusion-core/src/expression/supported.rs @@ -47,7 +47,7 @@ lazy_static! { pub static ref SUPPORTED_EXPRESSION_FNS: HashSet<&'static str> = vec![ // Math - "abs", "acos", "asin", "atan", "ceil", "cos", "exp", "floor", "round", "sqrt", "tan", + "abs", "acos", "asin", "atan", "ceil", "cos", "exp", "floor", "round", "sin", "sqrt", "tan", "log", "pow", // Type checking diff --git a/vegafusion-rt-datafusion/src/expression/compiler/call.rs b/vegafusion-rt-datafusion/src/expression/compiler/call.rs index 495a53f1b..a3cfbfd4a 100644 --- a/vegafusion-rt-datafusion/src/expression/compiler/call.rs +++ b/vegafusion-rt-datafusion/src/expression/compiler/call.rs @@ -232,7 +232,7 @@ pub fn default_callables() -> HashMap { // Numeric functions built into DataFusion with names that match Vega. // Cast arguments to Float64 for fun_name in &[ - "abs", "acos", "asin", "atan", "ceil", "cos", "exp", "floor", "round", "sqrt", "tan", + "abs", "acos", "asin", "atan", "ceil", "cos", "exp", "floor", "round", "sin", "sqrt", "tan", ] { let function = BuiltinScalarFunction::from_str(fun_name).unwrap(); callables.insert( diff --git a/vegafusion-rt-datafusion/tests/specs/custom/sin_cos.comm_plan.json b/vegafusion-rt-datafusion/tests/specs/custom/sin_cos.comm_plan.json new file mode 100644 index 000000000..949e547b2 --- /dev/null +++ b/vegafusion-rt-datafusion/tests/specs/custom/sin_cos.comm_plan.json @@ -0,0 +1,20 @@ +{ + "server_to_client": [ + { + "name": "data_0", + "namespace": "data", + "scope": [] + }, + { + "name": "data_0_x_domain_x", + "namespace": "data", + "scope": [] + }, + { + "name": "data_0_y_domain_y", + "namespace": "data", + "scope": [] + } + ], + "client_to_server": [] +} diff --git a/vegafusion-rt-datafusion/tests/specs/custom/sin_cos.vg.json b/vegafusion-rt-datafusion/tests/specs/custom/sin_cos.vg.json new file mode 100644 index 000000000..5990cfff4 --- /dev/null +++ b/vegafusion-rt-datafusion/tests/specs/custom/sin_cos.vg.json @@ -0,0 +1,213 @@ +{ + "$schema": "https://vega.github.io/schema/vega/v5.json", + "background": "white", + "padding": 5, + "width": 400, + "height": 300, + "style": "cell", + "data": [ + { + "name": "data-154c237c455a7f8fb343ee63b47dd948", + "values": [ + {"t": 0}, + {"t": 1}, + {"t": 2}, + {"t": 3}, + {"t": 4}, + {"t": 5}, + {"t": 6}, + {"t": 7}, + {"t": 8}, + {"t": 9}, + {"t": 10}, + {"t": 11}, + {"t": 12}, + {"t": 13}, + {"t": 14}, + {"t": 15}, + {"t": 16}, + {"t": 17}, + {"t": 18}, + {"t": 19}, + {"t": 20}, + {"t": 21}, + {"t": 22}, + {"t": 23}, + {"t": 24}, + {"t": 25}, + {"t": 26}, + {"t": 27}, + {"t": 28}, + {"t": 29}, + {"t": 30}, + {"t": 31}, + {"t": 32}, + {"t": 33}, + {"t": 34}, + {"t": 35}, + {"t": 36}, + {"t": 37}, + {"t": 38}, + {"t": 39}, + {"t": 40}, + {"t": 41}, + {"t": 42}, + {"t": 43}, + {"t": 44}, + {"t": 45}, + {"t": 46}, + {"t": 47}, + {"t": 48}, + {"t": 49}, + {"t": 50}, + {"t": 51}, + {"t": 52}, + {"t": 53}, + {"t": 54}, + {"t": 55}, + {"t": 56}, + {"t": 57}, + {"t": 58}, + {"t": 59}, + {"t": 60}, + {"t": 61}, + {"t": 62}, + {"t": 63}, + {"t": 64}, + {"t": 65}, + {"t": 66}, + {"t": 67}, + {"t": 68}, + {"t": 69}, + {"t": 70}, + {"t": 71}, + {"t": 72}, + {"t": 73}, + {"t": 74}, + {"t": 75}, + {"t": 76}, + {"t": 77}, + {"t": 78}, + {"t": 79}, + {"t": 80}, + {"t": 81}, + {"t": 82}, + {"t": 83}, + {"t": 84}, + {"t": 85}, + {"t": 86}, + {"t": 87}, + {"t": 88}, + {"t": 89}, + {"t": 90}, + {"t": 91}, + {"t": 92}, + {"t": 93}, + {"t": 94}, + {"t": 95}, + {"t": 96}, + {"t": 97}, + {"t": 98}, + {"t": 99}, + {"t": 100} + ] + }, + { + "name": "data_0", + "source": "data-154c237c455a7f8fb343ee63b47dd948", + "transform": [ + {"type": "formula", "expr": "cos(datum.t * PI / 50)", "as": "x"}, + {"type": "formula", "expr": "sin(datum.t * PI / 25)", "as": "y"} + ] + } + ], + "marks": [ + { + "name": "marks", + "type": "line", + "style": ["line"], + "sort": {"field": ["datum[\"t\"]"], "order": ["ascending"]}, + "from": {"data": "data_0"}, + "encode": { + "update": { + "stroke": {"value": "#4c78a8"}, + "description": { + "signal": "\"x: \" + (format(datum[\"x\"], \"\")) + \"; y: \" + (format(datum[\"y\"], \"\")) + \"; t: \" + (format(datum[\"t\"], \"\"))" + }, + "x": {"scale": "x", "field": "x"}, + "y": {"scale": "y", "field": "y"}, + "defined": { + "signal": "isValid(datum[\"x\"]) && isFinite(+datum[\"x\"]) && isValid(datum[\"y\"]) && isFinite(+datum[\"y\"])" + } + } + } + } + ], + "scales": [ + { + "name": "x", + "type": "linear", + "domain": {"data": "data_0", "field": "x"}, + "range": [0, {"signal": "width"}], + "nice": true, + "zero": false + }, + { + "name": "y", + "type": "linear", + "domain": {"data": "data_0", "field": "y"}, + "range": [{"signal": "height"}, 0], + "nice": true, + "zero": true + } + ], + "axes": [ + { + "scale": "x", + "orient": "bottom", + "gridScale": "y", + "grid": true, + "tickCount": {"signal": "ceil(width/40)"}, + "domain": false, + "labels": false, + "aria": false, + "maxExtent": 0, + "minExtent": 0, + "ticks": false, + "zindex": 0 + }, + { + "scale": "y", + "orient": "left", + "gridScale": "x", + "grid": true, + "tickCount": {"signal": "ceil(height/40)"}, + "domain": false, + "labels": false, + "aria": false, + "maxExtent": 0, + "minExtent": 0, + "ticks": false, + "zindex": 0 + }, + { + "scale": "x", + "orient": "bottom", + "grid": false, + "title": "x", + "labelFlush": true, + "labelOverlap": true, + "tickCount": {"signal": "ceil(width/40)"}, + "zindex": 0 + }, + { + "scale": "y", + "orient": "left", + "grid": false, + "title": "y", + "labelOverlap": true, + "tickCount": {"signal": "ceil(height/40)"}, + "zindex": 0 + } + ] +} \ No newline at end of file diff --git a/vegafusion-rt-datafusion/tests/test_image_comparison.rs b/vegafusion-rt-datafusion/tests/test_image_comparison.rs index e0768bd55..6b10e4ba2 100644 --- a/vegafusion-rt-datafusion/tests/test_image_comparison.rs +++ b/vegafusion-rt-datafusion/tests/test_image_comparison.rs @@ -136,7 +136,8 @@ mod test_custom_specs { case("custom/full_bin_histogram_selection", 0.001, false), case("custom/datetime_scatter", 0.001, false), case("custom/stack_divide_by_zero_error", 0.001, false), - case("custom/casestudy-us_population_pyramid_over_time", 0.001, true) + case("custom/casestudy-us_population_pyramid_over_time", 0.001, true), + case("custom/sin_cos", 0.001, true), )] fn test_image_comparison(spec_name: &str, tolerance: f64, extract_inline_values: bool) { println!("spec_name: {}", spec_name); From 16c612400ff09db628d9e1d34f10fe0159df57a4 Mon Sep 17 00:00:00 2001 From: Jon Mease Date: Sat, 31 Dec 2022 19:25:35 -0500 Subject: [PATCH 2/2] fmt --- vegafusion-rt-datafusion/tests/test_image_comparison.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/vegafusion-rt-datafusion/tests/test_image_comparison.rs b/vegafusion-rt-datafusion/tests/test_image_comparison.rs index 6b10e4ba2..82912e76b 100644 --- a/vegafusion-rt-datafusion/tests/test_image_comparison.rs +++ b/vegafusion-rt-datafusion/tests/test_image_comparison.rs @@ -137,7 +137,7 @@ mod test_custom_specs { case("custom/datetime_scatter", 0.001, false), case("custom/stack_divide_by_zero_error", 0.001, false), case("custom/casestudy-us_population_pyramid_over_time", 0.001, true), - case("custom/sin_cos", 0.001, true), + case("custom/sin_cos", 0.001, true) )] fn test_image_comparison(spec_name: &str, tolerance: f64, extract_inline_values: bool) { println!("spec_name: {}", spec_name);