| 1 | /* |
| 2 | * Plot_unit_tests.hpp |
| 3 | * |
| 4 | * Created on: Jan 9, 2016 |
| 5 | * Author: i-bird |
| 6 | */ |
| 7 | |
| 8 | #ifndef OPENFPM_DATA_SRC_PLOT_PLOT_UNIT_TESTS_HPP_ |
| 9 | #define OPENFPM_DATA_SRC_PLOT_PLOT_UNIT_TESTS_HPP_ |
| 10 | |
| 11 | #include "GoogleChart.hpp" |
| 12 | #include "Plot/util.hpp" |
| 13 | |
| 14 | BOOST_AUTO_TEST_SUITE( plot_unit_test ) |
| 15 | |
| 16 | |
| 17 | BOOST_AUTO_TEST_CASE( google_chart_bar_string ) |
| 18 | { |
| 19 | Vcluster<> & v_cl = create_vcluster(); |
| 20 | |
| 21 | if (v_cl.getProcessUnitID() != 0) |
| 22 | return; |
| 23 | |
| 24 | //! [Producing an Histogram graph] |
| 25 | |
| 26 | openfpm::vector<std::string> x; |
| 27 | openfpm::vector<openfpm::vector<size_t>> y; |
| 28 | openfpm::vector<std::string> yn; |
| 29 | |
| 30 | x.add("colum1" ); |
| 31 | x.add("colum2" ); |
| 32 | x.add("colum3" ); |
| 33 | x.add("colum4" ); |
| 34 | x.add("colum5" ); |
| 35 | x.add("colum6" ); |
| 36 | |
| 37 | // Each colum can have multiple data set (in this case 4 dataset) |
| 38 | // Each dataset can have a name |
| 39 | yn.add("dataset1" ); |
| 40 | yn.add("dataset2" ); |
| 41 | yn.add("dataset3" ); |
| 42 | yn.add("dataset4" ); |
| 43 | |
| 44 | // Each colums can have multiple data-set |
| 45 | y.add({2,3,5,6}); |
| 46 | y.add({5,6,1,6}); |
| 47 | y.add({2,1,6,9}); |
| 48 | y.add({1,6,3,2}); |
| 49 | y.add({3,3,0,6}); |
| 50 | y.add({2,1,4,6}); |
| 51 | |
| 52 | // Google charts options |
| 53 | GCoptions options; |
| 54 | |
| 55 | options.title = std::string("Example" ); |
| 56 | options.yAxis = std::string("Y Axis" ); |
| 57 | options.xAxis = std::string("X Axis" ); |
| 58 | options.stype = std::string("bars" ); |
| 59 | options.barWD = true; |
| 60 | |
| 61 | // it say that the colum4 must me represented with a line |
| 62 | options.stypeext = std::string("{3: {type: 'line'}}" ); |
| 63 | |
| 64 | GoogleChart cg; |
| 65 | cg.AddHistGraph(x,y,yn,options); |
| 66 | cg.write("gc_out_sc.html" ); |
| 67 | |
| 68 | //! [Producing an Histogram graph] |
| 69 | |
| 70 | bool test = compare("gc_out_sc.html" ,"test_data/gc_out_sc_test.html" ); |
| 71 | BOOST_REQUIRE_EQUAL(true,test); |
| 72 | } |
| 73 | |
| 74 | |
| 75 | BOOST_AUTO_TEST_CASE( google_chart ) |
| 76 | { |
| 77 | Vcluster<> & v_cl = create_vcluster(); |
| 78 | |
| 79 | if (v_cl.getProcessUnitID() != 0) |
| 80 | return; |
| 81 | |
| 82 | //! [Producing an Histogram graph] |
| 83 | |
| 84 | openfpm::vector<std::string> x; |
| 85 | openfpm::vector<openfpm::vector<size_t>> y; |
| 86 | openfpm::vector<std::string> yn; |
| 87 | |
| 88 | x.add("colum1" ); |
| 89 | x.add("colum2" ); |
| 90 | x.add("colum3" ); |
| 91 | x.add("colum4" ); |
| 92 | x.add("colum5" ); |
| 93 | x.add("colum6" ); |
| 94 | |
| 95 | // Each colum can have multiple data set (in this case 4 dataset) |
| 96 | // Each dataset can have a name |
| 97 | yn.add("dataset1" ); |
| 98 | yn.add("dataset2" ); |
| 99 | yn.add("dataset3" ); |
| 100 | yn.add("dataset4" ); |
| 101 | |
| 102 | // Each colums can have multiple data-set |
| 103 | y.add({2,3,5,6}); |
| 104 | y.add({5,6,1,6}); |
| 105 | y.add({2,1,6,9}); |
| 106 | y.add({1,6,3,2}); |
| 107 | y.add({3,3,0,6}); |
| 108 | y.add({2,1,4,6}); |
| 109 | |
| 110 | // Google charts options |
| 111 | GCoptions options; |
| 112 | |
| 113 | options.title = std::string("Example" ); |
| 114 | options.yAxis = std::string("Y Axis" ); |
| 115 | options.xAxis = std::string("X Axis" ); |
| 116 | options.stype = std::string("bars" ); |
| 117 | |
| 118 | // it say that the colum4 must me represented with a line |
| 119 | options.stypeext = std::string("{3: {type: 'line'}}" ); |
| 120 | |
| 121 | GoogleChart cg; |
| 122 | cg.AddHistGraph(x,y,yn,options); |
| 123 | cg.write("gc_out.html" ); |
| 124 | |
| 125 | //! [Producing an Histogram graph] |
| 126 | |
| 127 | bool test = compare("gc_out.html" ,"test_data/gc_out_test.html" ); |
| 128 | BOOST_REQUIRE_EQUAL(true,test); |
| 129 | } |
| 130 | |
| 131 | BOOST_AUTO_TEST_CASE( google_chart2 ) |
| 132 | { |
| 133 | Vcluster<> & v_cl = create_vcluster(); |
| 134 | |
| 135 | if (v_cl.getProcessUnitID() != 0) |
| 136 | return; |
| 137 | |
| 138 | openfpm::vector<std::string> x; |
| 139 | openfpm::vector<openfpm::vector<float>> y; |
| 140 | openfpm::vector<std::string> yn; |
| 141 | |
| 142 | x.add("colum1" ); |
| 143 | x.add("colum2" ); |
| 144 | x.add("colum3" ); |
| 145 | x.add("colum4" ); |
| 146 | x.add("colum5" ); |
| 147 | x.add("colum6" ); |
| 148 | |
| 149 | // Each colum can have multiple data set (in this case 4 dataset) |
| 150 | // Each dataset can have a name |
| 151 | yn.add("dataset1" ); |
| 152 | yn.add("dataset2" ); |
| 153 | yn.add("dataset3" ); |
| 154 | yn.add("dataset4" ); |
| 155 | |
| 156 | // Each colums can have multiple data-set |
| 157 | y.add({2.2,1.3,4.5,0.6}); |
| 158 | y.add({5.0,6.1,1.3,2.6}); |
| 159 | y.add({2.1,1.0,6.1,9.3}); |
| 160 | y.add({1.1,6.1,3.0,2.0}); |
| 161 | y.add({3.3,0.3,0.0,6.2}); |
| 162 | y.add({2.0,1.1,4.0,6.1}); |
| 163 | |
| 164 | // Google charts options |
| 165 | GCoptions options; |
| 166 | |
| 167 | options.title = std::string("Example" ); |
| 168 | options.yAxis = std::string("Y Axis" ); |
| 169 | options.xAxis = std::string("X Axis" ); |
| 170 | options.stype = std::string("bars" ); |
| 171 | |
| 172 | GoogleChart cg; |
| 173 | cg.AddHistGraph(x,y,yn,options); |
| 174 | cg.write("gc_out2.html" ); |
| 175 | |
| 176 | bool test = compare("gc_out2.html" ,"test_data/gc_out2_test.html" ); |
| 177 | BOOST_REQUIRE_EQUAL(true,test); |
| 178 | } |
| 179 | |
| 180 | BOOST_AUTO_TEST_CASE( google_chart3 ) |
| 181 | { |
| 182 | Vcluster<> & v_cl = create_vcluster(); |
| 183 | |
| 184 | if (v_cl.getProcessUnitID() != 0) |
| 185 | return; |
| 186 | |
| 187 | openfpm::vector<std::string> x; |
| 188 | openfpm::vector<openfpm::vector<float>> y; |
| 189 | openfpm::vector<std::string> yn; |
| 190 | |
| 191 | x.add("colum1" ); |
| 192 | x.add("colum2" ); |
| 193 | x.add("colum3" ); |
| 194 | x.add("colum4" ); |
| 195 | x.add("colum5" ); |
| 196 | x.add("colum6" ); |
| 197 | |
| 198 | // Each colum can have multiple data set (in this case 4 dataset) |
| 199 | // Each dataset can have a name |
| 200 | yn.add("dataset1" ); |
| 201 | yn.add("dataset2" ); |
| 202 | yn.add("dataset3" ); |
| 203 | yn.add("dataset4" ); |
| 204 | |
| 205 | // Each colums can have multiple data-set |
| 206 | y.add({2.2,1.3,4.5,0.6}); |
| 207 | y.add({5.0,6.1,1.3,2.6}); |
| 208 | y.add({2.1,1.0,6.1,9.3}); |
| 209 | y.add({1.1,6.1,3.0,2.0}); |
| 210 | y.add({3.3,0.3,0.0,6.2}); |
| 211 | y.add({2.0,1.1,4.0,6.1}); |
| 212 | |
| 213 | // Google charts options |
| 214 | GCoptions options; |
| 215 | |
| 216 | options.title = std::string("Example" ); |
| 217 | options.yAxis = std::string("Y Axis" ); |
| 218 | options.xAxis = std::string("X Axis" ); |
| 219 | |
| 220 | GoogleChart cg; |
| 221 | cg.AddHistGraph(x,y,yn,options); |
| 222 | cg.write("gc_out3.html" ); |
| 223 | |
| 224 | bool test = compare("gc_out3.html" ,"test_data/gc_out3_test.html" ); |
| 225 | BOOST_REQUIRE_EQUAL(true,test); |
| 226 | } |
| 227 | |
| 228 | BOOST_AUTO_TEST_CASE( google_chart4 ) |
| 229 | { |
| 230 | Vcluster<> & v_cl = create_vcluster(); |
| 231 | |
| 232 | if (v_cl.getProcessUnitID() != 0) |
| 233 | return; |
| 234 | |
| 235 | openfpm::vector<std::string> x; |
| 236 | openfpm::vector<openfpm::vector<float>> y; |
| 237 | openfpm::vector<std::string> yn; |
| 238 | |
| 239 | x.add("colum1" ); |
| 240 | x.add("colum2" ); |
| 241 | x.add("colum3" ); |
| 242 | x.add("colum4" ); |
| 243 | x.add("colum5" ); |
| 244 | x.add("colum6" ); |
| 245 | |
| 246 | // Each colum can have multiple data set (in this case 4 dataset) |
| 247 | // Each dataset can have a name |
| 248 | yn.add("dataset1" ); |
| 249 | yn.add("dataset2" ); |
| 250 | yn.add("dataset3" ); |
| 251 | yn.add("dataset4" ); |
| 252 | |
| 253 | // Each colums can have multiple data-set |
| 254 | y.add({2.2,1.3,4.5,0.6}); |
| 255 | y.add({5.0,6.1,1.3,2.6}); |
| 256 | y.add({2.1,1.0,6.1,9.3}); |
| 257 | y.add({1.1,6.1,3.0,2.0}); |
| 258 | y.add({3.3,0.3,0.0,6.2}); |
| 259 | y.add({2.0,1.1,4.0,6.1}); |
| 260 | |
| 261 | GoogleChart cg; |
| 262 | cg.AddHistGraph(x,y,yn); |
| 263 | cg.write("gc_out4.html" ); |
| 264 | |
| 265 | bool test = compare("gc_out4.html" ,"test_data/gc_out4_test.html" ); |
| 266 | BOOST_REQUIRE_EQUAL(true,test); |
| 267 | } |
| 268 | |
| 269 | BOOST_AUTO_TEST_CASE( google_chart5 ) |
| 270 | { |
| 271 | Vcluster<> & v_cl = create_vcluster(); |
| 272 | |
| 273 | if (v_cl.getProcessUnitID() != 0) |
| 274 | return; |
| 275 | |
| 276 | openfpm::vector<std::string> x; |
| 277 | openfpm::vector<openfpm::vector<float>> y; |
| 278 | |
| 279 | x.add("colum1" ); |
| 280 | x.add("colum2" ); |
| 281 | x.add("colum3" ); |
| 282 | x.add("colum4" ); |
| 283 | x.add("colum5" ); |
| 284 | x.add("colum6" ); |
| 285 | |
| 286 | // Each colums can have multiple data-set |
| 287 | y.add({2.2,1.3,4.5,0.6}); |
| 288 | y.add({5.0,6.1,1.3,2.6}); |
| 289 | y.add({2.1,1.0,6.1,9.3}); |
| 290 | y.add({1.1,6.1,3.0,2.0}); |
| 291 | y.add({3.3,0.3,0.0,6.2}); |
| 292 | y.add({2.0,1.1,4.0,6.1}); |
| 293 | |
| 294 | GoogleChart cg; |
| 295 | cg.AddHistGraph(x,y); |
| 296 | cg.write("gc_out5.html" ); |
| 297 | |
| 298 | bool test = compare("gc_out5.html" ,"test_data/gc_out5_test.html" ); |
| 299 | BOOST_REQUIRE_EQUAL(true,test); |
| 300 | } |
| 301 | |
| 302 | BOOST_AUTO_TEST_CASE( google_chart6 ) |
| 303 | { |
| 304 | Vcluster<> & v_cl = create_vcluster(); |
| 305 | |
| 306 | if (v_cl.getProcessUnitID() != 0) |
| 307 | return; |
| 308 | |
| 309 | openfpm::vector<openfpm::vector<float>> y; |
| 310 | |
| 311 | // Each colums can have multiple data-set |
| 312 | y.add({2.2,1.3,4.5,0.6}); |
| 313 | y.add({5.0,6.1,1.3,2.6}); |
| 314 | y.add({2.1,1.0,6.1,9.3}); |
| 315 | y.add({1.1,6.1,3.0,2.0}); |
| 316 | y.add({3.3,0.3,0.0,6.2}); |
| 317 | y.add({2.0,1.1,4.0,6.1}); |
| 318 | |
| 319 | GoogleChart cg; |
| 320 | cg.AddHistGraph(y); |
| 321 | cg.write("gc_out6.html" ); |
| 322 | |
| 323 | bool test = compare("gc_out6.html" ,"test_data/gc_out6_test.html" ); |
| 324 | BOOST_REQUIRE_EQUAL(true,test); |
| 325 | } |
| 326 | |
| 327 | BOOST_AUTO_TEST_CASE( google_chart_with_inject_HTML ) |
| 328 | { |
| 329 | Vcluster<> & v_cl = create_vcluster(); |
| 330 | |
| 331 | if (v_cl.getProcessUnitID() != 0) |
| 332 | return; |
| 333 | |
| 334 | //! [Producing a set of histograms graphs] |
| 335 | |
| 336 | openfpm::vector<std::string> x; |
| 337 | openfpm::vector<openfpm::vector<size_t>> y; |
| 338 | openfpm::vector<std::string> yn; |
| 339 | |
| 340 | x.add("colum1" ); |
| 341 | x.add("colum2" ); |
| 342 | x.add("colum3" ); |
| 343 | x.add("colum4" ); |
| 344 | x.add("colum5" ); |
| 345 | x.add("colum6" ); |
| 346 | |
| 347 | // Each colum can have multiple data set (in this case 4 dataset) |
| 348 | // Each dataset can have a name |
| 349 | yn.add("dataset1" ); |
| 350 | yn.add("dataset2" ); |
| 351 | yn.add("dataset3" ); |
| 352 | yn.add("dataset4" ); |
| 353 | |
| 354 | // Each colums can have multiple data-set |
| 355 | y.add({2,3,5,6}); |
| 356 | y.add({5,6,1,6}); |
| 357 | y.add({2,1,6,9}); |
| 358 | y.add({1,6,3,2}); |
| 359 | y.add({3,3,0,6}); |
| 360 | y.add({2,1,4,6}); |
| 361 | |
| 362 | // Google charts options |
| 363 | GCoptions options; |
| 364 | |
| 365 | options.title = std::string("Example" ); |
| 366 | options.yAxis = std::string("Y Axis" ); |
| 367 | options.xAxis = std::string("X Axis" ); |
| 368 | options.stype = std::string("bars" ); |
| 369 | |
| 370 | // it say that the colum4 must me represented with a line |
| 371 | options.stypeext = std::string("{3: {type: 'line'}}" ); |
| 372 | |
| 373 | GoogleChart cg; |
| 374 | // |
| 375 | cg.addHTML("<h2>Before first graph</h2>" ); |
| 376 | cg.AddHistGraph(x,y,yn,options); |
| 377 | cg.addHTML("<h2>Before second graph</h2>" ); |
| 378 | cg.AddHistGraph(x,y,yn,options); |
| 379 | cg.addHTML("<h2>Before third graph</h2>" ); |
| 380 | cg.AddHistGraph(x,y,yn,options); |
| 381 | cg.addHTML("<h2>At the end</h2>" ); |
| 382 | cg.write("gc_out7.html" ); |
| 383 | |
| 384 | //! [Producing a set of histograms graphs] |
| 385 | |
| 386 | bool test = compare("gc_out7.html" ,"test_data/gc_out7_test.html" ); |
| 387 | BOOST_REQUIRE_EQUAL(true,test); |
| 388 | } |
| 389 | |
| 390 | BOOST_AUTO_TEST_CASE( google_chart_number ) |
| 391 | { |
| 392 | Vcluster<> & v_cl = create_vcluster(); |
| 393 | |
| 394 | if (v_cl.getProcessUnitID() != 0) |
| 395 | return; |
| 396 | |
| 397 | //! [Producing a set of histograms graphs] |
| 398 | |
| 399 | openfpm::vector<float> x; |
| 400 | openfpm::vector<openfpm::vector<size_t>> y; |
| 401 | openfpm::vector<std::string> yn; |
| 402 | |
| 403 | x.add(0.1); |
| 404 | x.add(0.2); |
| 405 | x.add(0.3); |
| 406 | x.add(0.4); |
| 407 | x.add(0.5); |
| 408 | x.add(0.6); |
| 409 | |
| 410 | // Each colum can have multiple data set (in this case 4 dataset) |
| 411 | // Each dataset can have a name |
| 412 | yn.add("dataset1" ); |
| 413 | yn.add("dataset2" ); |
| 414 | yn.add("dataset3" ); |
| 415 | yn.add("dataset4" ); |
| 416 | |
| 417 | // Each colums can have multiple data-set |
| 418 | y.add({2,3,5,6}); |
| 419 | y.add({5,6,1,6}); |
| 420 | y.add({2,1,6,9}); |
| 421 | y.add({1,6,3,2}); |
| 422 | y.add({3,3,0,6}); |
| 423 | y.add({2,1,4,6}); |
| 424 | |
| 425 | // Google charts options |
| 426 | GCoptions options; |
| 427 | |
| 428 | options.title = std::string("Example" ); |
| 429 | options.yAxis = std::string("Y Axis" ); |
| 430 | options.xAxis = std::string("X Axis" ); |
| 431 | options.stype = std::string("line" ); |
| 432 | |
| 433 | GoogleChart cg; |
| 434 | // |
| 435 | cg.AddLinesGraph(x,y,yn,options); |
| 436 | cg.write("gc_num_plot.html" ); |
| 437 | |
| 438 | //! [Producing a set of histograms graphs] |
| 439 | |
| 440 | bool test = compare("gc_num_plot.html" ,"test_data/gc_num_plot_test.html" ); |
| 441 | BOOST_REQUIRE_EQUAL(true,test); |
| 442 | } |
| 443 | |
| 444 | BOOST_AUTO_TEST_CASE( google_chart_number_lines_different_x ) |
| 445 | { |
| 446 | Vcluster<> & v_cl = create_vcluster(); |
| 447 | |
| 448 | if (v_cl.getProcessUnitID() != 0) |
| 449 | return; |
| 450 | |
| 451 | //! [Producing a set of histograms graphs] |
| 452 | |
| 453 | openfpm::vector<float> x1; |
| 454 | openfpm::vector<float> y1; |
| 455 | openfpm::vector<float> x2; |
| 456 | openfpm::vector<float> y2; |
| 457 | openfpm::vector<float> x3; |
| 458 | openfpm::vector<float> y3; |
| 459 | openfpm::vector<std::string> yn; |
| 460 | |
| 461 | x1.add(0.1); y1.add(4.5); |
| 462 | x1.add(0.2); y1.add(3.0); |
| 463 | x1.add(0.3); y1.add(5.5); |
| 464 | x1.add(0.4); y1.add(3.3); |
| 465 | x1.add(0.5); y1.add(1.0); |
| 466 | x1.add(0.6); y1.add(7.0); |
| 467 | |
| 468 | x2.add(0.15); y2.add(1.5); |
| 469 | x2.add(0.2); y2.add(4.5); |
| 470 | x2.add(0.35); y2.add(2.5); |
| 471 | x2.add(0.45); y2.add(6.5); |
| 472 | |
| 473 | x3.add(0.1); y3.add(3.5); |
| 474 | x3.add(0.2); y3.add(6.5); |
| 475 | x3.add(0.63); y3.add(1.5); |
| 476 | x3.add(0.37); y3.add(1.5); |
| 477 | x3.add(0.7); y3.add(3.5); |
| 478 | x3.add(0.82); y3.add(2.5); |
| 479 | x3.add(0.4); y3.add(2.5); |
| 480 | x3.add(1.0); y3.add(1.5); |
| 481 | x3.add(0.5); y3.add(7.5); |
| 482 | x3.add(0.91); y3.add(5.5); |
| 483 | |
| 484 | // Each colum can have multiple data set (in this case 4 dataset) |
| 485 | // Each dataset can have a name |
| 486 | yn.add("dataset1" ); |
| 487 | yn.add("dataset2" ); |
| 488 | yn.add("dataset3" ); |
| 489 | |
| 490 | |
| 491 | // Google charts options |
| 492 | GCoptions options; |
| 493 | |
| 494 | options.title = std::string("Example" ); |
| 495 | options.yAxis = std::string("Y Axis" ); |
| 496 | options.xAxis = std::string("X Axis" ); |
| 497 | options.stype = std::string("line" ); |
| 498 | |
| 499 | GoogleChart cg; |
| 500 | |
| 501 | cg.AddLines(yn,options,x1,y1,x2,y2,x3,y3); |
| 502 | cg.write("gc_num_ydif_plot.html" ); |
| 503 | |
| 504 | //! [Producing a set of histograms graphs] |
| 505 | |
| 506 | bool test = compare("gc_num_ydif_plot.html" ,"test_data/gc_num_ydif_plot_test.html" ); |
| 507 | BOOST_REQUIRE_EQUAL(true,test); |
| 508 | } |
| 509 | |
| 510 | BOOST_AUTO_TEST_CASE( google_chart_linear_plot ) |
| 511 | { |
| 512 | Vcluster<> & v_cl = create_vcluster(); |
| 513 | |
| 514 | if (v_cl.getProcessUnitID() != 0) |
| 515 | return; |
| 516 | |
| 517 | //! [Producing lines graph with style] |
| 518 | |
| 519 | openfpm::vector<std::string> x; |
| 520 | openfpm::vector<openfpm::vector<double>> y; |
| 521 | openfpm::vector<std::string> yn; |
| 522 | |
| 523 | x.add("colum1" ); |
| 524 | x.add("colum2" ); |
| 525 | x.add("colum3" ); |
| 526 | x.add("colum4" ); |
| 527 | x.add("colum5" ); |
| 528 | x.add("colum6" ); |
| 529 | |
| 530 | // Here we specify how many lines we have |
| 531 | // first Line |
| 532 | yn.add("line1" ); |
| 533 | |
| 534 | // second line + 2 intervals (Error bands) |
| 535 | yn.add("line2" ); |
| 536 | yn.add("interval" ); |
| 537 | yn.add("interval" ); |
| 538 | yn.add("interval" ); |
| 539 | yn.add("interval" ); |
| 540 | |
| 541 | // third line + 1 interval (Error bands) |
| 542 | yn.add("line3" ); |
| 543 | yn.add("interval" ); |
| 544 | yn.add("interval" ); |
| 545 | |
| 546 | // Each line can have multiple intervals or error bars |
| 547 | // The first number specify the bottom line |
| 548 | // The last three numbers specify the top line + error band (min, max) |
| 549 | // The middle 5 line specify the middle lines + one external error band + one internal error band |
| 550 | |
| 551 | y.add({0.10,0.20,0.19,0.22,0.195,0.215,0.35,0.34,0.36}); |
| 552 | y.add({0.11,0.21,0.18,0.22,0.19,0.215,0.36,0.35,0.37}); |
| 553 | y.add({0.12,0.22,0.21,0.23,0.215,0.225,0.35,0.34,0.36}); |
| 554 | y.add({0.15,0.25,0.20,0.26,0.22,0.255,0.36,0.35,0.37}); |
| 555 | y.add({0.09,0.29,0.25,0.30,0.26,0.295,0.35,0.34,0.36}); |
| 556 | y.add({0.08,0.28,0.27,0.29,0.275,0.285,0.36,0.35,0.37}); |
| 557 | |
| 558 | // Google charts options |
| 559 | GCoptions options; |
| 560 | |
| 561 | options.title = std::string("Example" ); |
| 562 | options.yAxis = std::string("Y Axis" ); |
| 563 | options.xAxis = std::string("X Axis" ); |
| 564 | options.lineWidth = 1.0; |
| 565 | options.intervalext = std::string("{'i2': { 'color': '#4374E0', 'style':'bars', 'lineWidth':4, 'fillOpacity':1 } }" ); |
| 566 | |
| 567 | GoogleChart cg; |
| 568 | cg.AddLinesGraph(x,y,yn,options); |
| 569 | cg.write("gc_plot_out.html" ); |
| 570 | |
| 571 | //! [Producing lines graph with style] |
| 572 | |
| 573 | bool test = compare("gc_plot_out.html" ,"test_data/gc_plot_out_test.html" ); |
| 574 | BOOST_REQUIRE_EQUAL(true,test); |
| 575 | } |
| 576 | |
| 577 | BOOST_AUTO_TEST_CASE( google_chart_linear_plot2 ) |
| 578 | { |
| 579 | Vcluster<> & v_cl = create_vcluster(); |
| 580 | |
| 581 | if (v_cl.getProcessUnitID() != 0) |
| 582 | return; |
| 583 | |
| 584 | //! [Producing lines] |
| 585 | |
| 586 | openfpm::vector<std::string> x; |
| 587 | openfpm::vector<openfpm::vector<double>> y; |
| 588 | |
| 589 | x.add("colum1" ); |
| 590 | x.add("colum2" ); |
| 591 | x.add("colum3" ); |
| 592 | x.add("colum4" ); |
| 593 | x.add("colum5" ); |
| 594 | x.add("colum6" ); |
| 595 | |
| 596 | // Each line can have multiple intervals or error bars |
| 597 | // The first number specify the bottom line |
| 598 | // The last three numbers specify the top line + error band (min, max) |
| 599 | // The middle 5 line specify the middle lines + one external error band + one internal error band |
| 600 | |
| 601 | y.add({0.10,0.20,0.19,0.22,0.195,0.215,0.35,0.34,0.36}); |
| 602 | y.add({0.11,0.21,0.18,0.22,0.19,0.215,0.36,0.35,0.37}); |
| 603 | y.add({0.12,0.22,0.21,0.23,0.215,0.225,0.35,0.34,0.36}); |
| 604 | y.add({0.15,0.25,0.20,0.26,0.22,0.255,0.36,0.35,0.37}); |
| 605 | y.add({0.09,0.29,0.25,0.30,0.26,0.295,0.35,0.34,0.36}); |
| 606 | y.add({0.08,0.28,0.27,0.29,0.275,0.285,0.36,0.35,0.37}); |
| 607 | |
| 608 | // Google charts options |
| 609 | GCoptions options; |
| 610 | |
| 611 | options.title = std::string("Example" ); |
| 612 | options.yAxis = std::string("Y Axis" ); |
| 613 | options.xAxis = std::string("X Axis" ); |
| 614 | options.lineWidth = 1.0; |
| 615 | |
| 616 | GoogleChart cg; |
| 617 | cg.AddLinesGraph(x,y,options); |
| 618 | cg.write("gc_plot2_out.html" ); |
| 619 | |
| 620 | //! [Producing lines] |
| 621 | |
| 622 | bool test = compare("gc_plot2_out.html" ,"test_data/gc_plot2_out_test.html" ); |
| 623 | BOOST_REQUIRE_EQUAL(true,test); |
| 624 | } |
| 625 | |
| 626 | //! [Definition of a function] |
| 627 | |
| 628 | double f(double x) |
| 629 | { |
| 630 | return x*x; |
| 631 | } |
| 632 | |
| 633 | //! [Definition of a function] |
| 634 | |
| 635 | BOOST_AUTO_TEST_CASE( plot_util ) |
| 636 | { |
| 637 | Vcluster<> & v_cl = create_vcluster(); |
| 638 | |
| 639 | if (v_cl.getProcessUnitID() != 0) |
| 640 | return; |
| 641 | |
| 642 | //! [fill a vector] |
| 643 | |
| 644 | openfpm::vector<double> x; |
| 645 | |
| 646 | Fill1D(0.0,2.0,5,x); |
| 647 | |
| 648 | BOOST_REQUIRE_EQUAL(x.get(0),0.0); |
| 649 | BOOST_REQUIRE_EQUAL(x.get(1),0.5); |
| 650 | BOOST_REQUIRE_EQUAL(x.get(2),1.0); |
| 651 | BOOST_REQUIRE_EQUAL(x.get(3),1.5); |
| 652 | BOOST_REQUIRE_EQUAL(x.get(4),2.0); |
| 653 | |
| 654 | //! [fill a vector] |
| 655 | |
| 656 | x.clear(); |
| 657 | |
| 658 | //! [fill a vector with a function] |
| 659 | |
| 660 | Fill1D(0.0,2.0,5,x,f); |
| 661 | |
| 662 | BOOST_REQUIRE_EQUAL(x.get(0),0.0); |
| 663 | BOOST_REQUIRE_EQUAL(x.get(1),0.25); |
| 664 | BOOST_REQUIRE_EQUAL(x.get(2),1.0); |
| 665 | BOOST_REQUIRE_EQUAL(x.get(3),2.25); |
| 666 | BOOST_REQUIRE_EQUAL(x.get(4),4.0); |
| 667 | |
| 668 | //! [fill a vector function] |
| 669 | } |
| 670 | |
| 671 | BOOST_AUTO_TEST_SUITE_END() |
| 672 | |
| 673 | #endif /* OPENFPM_DATA_SRC_PLOT_PLOT_UNIT_TESTS_HPP_ */ |
| 674 | |