8 #ifndef OPENFPM_DATA_SRC_PLOT_PLOT_UNIT_TESTS_HPP_
9 #define OPENFPM_DATA_SRC_PLOT_PLOT_UNIT_TESTS_HPP_
11 #include "GoogleChart.hpp"
12 #include "Plot/util.hpp"
14 BOOST_AUTO_TEST_SUITE( plot_unit_test )
16 BOOST_AUTO_TEST_CASE( google_chart )
20 openfpm::vector<std::string> x;
21 openfpm::vector<openfpm::vector<size_t>> y;
22 openfpm::vector<std::string> yn;
49 options.
title = std::string(
"Example");
50 options.
yAxis = std::string(
"Y Axis");
51 options.
xAxis = std::string(
"X Axis");
52 options.
stype = std::string(
"bars");
55 options.
stypeext = std::string(
"{3: {type: 'line'}}");
59 cg.
write(
"gc_out.html");
63 bool test = compare(
"gc_out.html",
"gc_out_test.html");
64 BOOST_REQUIRE_EQUAL(
true,test);
67 BOOST_AUTO_TEST_CASE( google_chart2 )
69 openfpm::vector<std::string> x;
70 openfpm::vector<openfpm::vector<float>> y;
71 openfpm::vector<std::string> yn;
88 y.add({2.2,1.3,4.5,0.6});
89 y.add({5.0,6.1,1.3,2.6});
90 y.add({2.1,1.0,6.1,9.3});
91 y.add({1.1,6.1,3.0,2.0});
92 y.add({3.3,0.3,0.0,6.2});
93 y.add({2.0,1.1,4.0,6.1});
98 options.
title = std::string(
"Example");
99 options.
yAxis = std::string(
"Y Axis");
100 options.
xAxis = std::string(
"X Axis");
101 options.
stype = std::string(
"bars");
105 cg.
write(
"gc_out2.html");
107 bool test = compare(
"gc_out2.html",
"gc_out2_test.html");
108 BOOST_REQUIRE_EQUAL(
true,test);
111 BOOST_AUTO_TEST_CASE( google_chart3 )
113 openfpm::vector<std::string> x;
114 openfpm::vector<openfpm::vector<float>> y;
115 openfpm::vector<std::string> yn;
132 y.add({2.2,1.3,4.5,0.6});
133 y.add({5.0,6.1,1.3,2.6});
134 y.add({2.1,1.0,6.1,9.3});
135 y.add({1.1,6.1,3.0,2.0});
136 y.add({3.3,0.3,0.0,6.2});
137 y.add({2.0,1.1,4.0,6.1});
142 options.
title = std::string(
"Example");
143 options.
yAxis = std::string(
"Y Axis");
144 options.
xAxis = std::string(
"X Axis");
148 cg.
write(
"gc_out3.html");
150 bool test = compare(
"gc_out3.html",
"gc_out3_test.html");
151 BOOST_REQUIRE_EQUAL(
true,test);
154 BOOST_AUTO_TEST_CASE( google_chart4 )
156 openfpm::vector<std::string> x;
157 openfpm::vector<openfpm::vector<float>> y;
158 openfpm::vector<std::string> yn;
175 y.add({2.2,1.3,4.5,0.6});
176 y.add({5.0,6.1,1.3,2.6});
177 y.add({2.1,1.0,6.1,9.3});
178 y.add({1.1,6.1,3.0,2.0});
179 y.add({3.3,0.3,0.0,6.2});
180 y.add({2.0,1.1,4.0,6.1});
184 cg.
write(
"gc_out4.html");
186 bool test = compare(
"gc_out4.html",
"gc_out4_test.html");
187 BOOST_REQUIRE_EQUAL(
true,test);
190 BOOST_AUTO_TEST_CASE( google_chart5 )
192 openfpm::vector<std::string> x;
193 openfpm::vector<openfpm::vector<float>> y;
203 y.add({2.2,1.3,4.5,0.6});
204 y.add({5.0,6.1,1.3,2.6});
205 y.add({2.1,1.0,6.1,9.3});
206 y.add({1.1,6.1,3.0,2.0});
207 y.add({3.3,0.3,0.0,6.2});
208 y.add({2.0,1.1,4.0,6.1});
212 cg.
write(
"gc_out5.html");
214 bool test = compare(
"gc_out5.html",
"gc_out5_test.html");
215 BOOST_REQUIRE_EQUAL(
true,test);
218 BOOST_AUTO_TEST_CASE( google_chart6 )
220 openfpm::vector<openfpm::vector<float>> y;
223 y.add({2.2,1.3,4.5,0.6});
224 y.add({5.0,6.1,1.3,2.6});
225 y.add({2.1,1.0,6.1,9.3});
226 y.add({1.1,6.1,3.0,2.0});
227 y.add({3.3,0.3,0.0,6.2});
228 y.add({2.0,1.1,4.0,6.1});
232 cg.
write(
"gc_out6.html");
234 bool test = compare(
"gc_out6.html",
"gc_out6_test.html");
235 BOOST_REQUIRE_EQUAL(
true,test);
238 BOOST_AUTO_TEST_CASE( google_chart_with_inject_HTML )
242 openfpm::vector<std::string> x;
243 openfpm::vector<openfpm::vector<size_t>> y;
244 openfpm::vector<std::string> yn;
271 options.
title = std::string(
"Example");
272 options.
yAxis = std::string(
"Y Axis");
273 options.
xAxis = std::string(
"X Axis");
274 options.
stype = std::string(
"bars");
277 options.
stypeext = std::string(
"{3: {type: 'line'}}");
281 cg.
addHTML(
"<h2>Before first graph</h2>");
283 cg.
addHTML(
"<h2>Before second graph</h2>");
285 cg.
addHTML(
"<h2>Before third graph</h2>");
287 cg.
addHTML(
"<h2>At the end</h2>");
288 cg.
write(
"gc_out7.html");
292 bool test = compare(
"gc_out7.html",
"gc_out7_test.html");
293 BOOST_REQUIRE_EQUAL(
true,test);
296 BOOST_AUTO_TEST_CASE( google_chart_linear_plot )
300 openfpm::vector<std::string> x;
301 openfpm::vector<openfpm::vector<double>> y;
302 openfpm::vector<std::string> yn;
332 y.add({0.10,0.20,0.19,0.22,0.195,0.215,0.35,0.34,0.36});
333 y.add({0.11,0.21,0.18,0.22,0.19,0.215,0.36,0.35,0.37});
334 y.add({0.12,0.22,0.21,0.23,0.215,0.225,0.35,0.34,0.36});
335 y.add({0.15,0.25,0.20,0.26,0.22,0.255,0.36,0.35,0.37});
336 y.add({0.09,0.29,0.25,0.30,0.26,0.295,0.35,0.34,0.36});
337 y.add({0.08,0.28,0.27,0.29,0.275,0.285,0.36,0.35,0.37});
342 options.
title = std::string(
"Example");
343 options.
yAxis = std::string(
"Y Axis");
344 options.
xAxis = std::string(
"X Axis");
346 options.
intervalext = std::string(
"{'i2': { 'color': '#4374E0', 'style':'bars', 'lineWidth':4, 'fillOpacity':1 } }");
350 cg.
write(
"gc_plot_out.html");
354 bool test = compare(
"gc_plot_out.html",
"gc_plot_out_test.html");
355 BOOST_REQUIRE_EQUAL(
true,test);
358 BOOST_AUTO_TEST_CASE( google_chart_linear_plot2 )
362 openfpm::vector<std::string> x;
363 openfpm::vector<openfpm::vector<double>> y;
377 y.add({0.10,0.20,0.19,0.22,0.195,0.215,0.35,0.34,0.36});
378 y.add({0.11,0.21,0.18,0.22,0.19,0.215,0.36,0.35,0.37});
379 y.add({0.12,0.22,0.21,0.23,0.215,0.225,0.35,0.34,0.36});
380 y.add({0.15,0.25,0.20,0.26,0.22,0.255,0.36,0.35,0.37});
381 y.add({0.09,0.29,0.25,0.30,0.26,0.295,0.35,0.34,0.36});
382 y.add({0.08,0.28,0.27,0.29,0.275,0.285,0.36,0.35,0.37});
387 options.
title = std::string(
"Example");
388 options.
yAxis = std::string(
"Y Axis");
389 options.
xAxis = std::string(
"X Axis");
394 cg.
write(
"gc_plot2_out.html");
398 bool test = compare(
"gc_plot2_out.html",
"gc_plot2_out_test.html");
399 BOOST_REQUIRE_EQUAL(
true,test);
411 BOOST_AUTO_TEST_CASE( plot_util )
415 openfpm::vector<double> x;
419 BOOST_REQUIRE_EQUAL(x.get(0),0.0);
420 BOOST_REQUIRE_EQUAL(x.get(1),0.5);
421 BOOST_REQUIRE_EQUAL(x.get(2),1.0);
422 BOOST_REQUIRE_EQUAL(x.get(3),1.5);
423 BOOST_REQUIRE_EQUAL(x.get(4),2.0);
431 Fill1D(0.0,2.0,5,x,f);
433 BOOST_REQUIRE_EQUAL(x.get(0),0.0);
434 BOOST_REQUIRE_EQUAL(x.get(1),0.25);
435 BOOST_REQUIRE_EQUAL(x.get(2),1.0);
436 BOOST_REQUIRE_EQUAL(x.get(3),2.25);
437 BOOST_REQUIRE_EQUAL(x.get(4),4.0);
442 BOOST_AUTO_TEST_SUITE_END()
void addHTML(const std::string &html)
Add HTML text.
void AddLinesGraph(openfpm::vector< X > &x, openfpm::vector< Y > &y, const GCoptions &opt)
Add a simple lines graph.
std::string title
Title of the chart.
std::string yAxis
Y axis name.
Small class to produce graph with Google chart in HTML.
size_t lineWidth
Width of the line.
void write(std::string file)
It write the graphs on file in html format using Google charts.
void AddHistGraph(openfpm::vector< Y > &y)
Add an histogram graph.
std::string xAxis
X axis name.