diff --git a/src/Plot/GoogleChart.hpp b/src/Plot/GoogleChart.hpp index 38d20008241ced3d405db5ec8edddf9744942198..bf3bf61b0b368f927c544ea27c7ba4491d5c7227 100644 --- a/src/Plot/GoogleChart.hpp +++ b/src/Plot/GoogleChart.hpp @@ -68,6 +68,9 @@ struct GCoptions //! curve type std::string curveType = "function"; + //! barWD + bool barWD = false; + //! copy operator GCoptions & operator=(const GCoptions & opt) { @@ -98,6 +101,9 @@ struct GGraph //! option std::string option; + //! view in case we need a view + std::string view; + //! Google chart option GCoptions opt; }; @@ -243,6 +249,33 @@ class GoogleChart return data.str(); } + /*! \brief Construct a view option + * + * \param opt GoogleChart option + * + * \return the string + * + */ + std::string get_view_bar_option(const GCoptions & opt, size_t n_col) + { + std::stringstream str; + + str << "view.setColumns([0," << std::endl; + + for (size_t i = 0 ; i < n_col ; i++) + { + + str << i << ",{ calc: \"stringify\"," << std::endl; + str << "sourceColumn: " << i << "," << std::endl; + str << "type: \"string\"," << std::endl; + str << "role: \"annotation\" }"<< std::endl; + } + + str << "]);" << std::endl; + + return str.str(); + } + std::string get_colums_bar_option(const GCoptions & opt) { std::stringstream str; @@ -438,6 +471,7 @@ public: set_of_graphs.last().type = GGRAPH_COLUMS; set_of_graphs.last().data = get_points_plot_data(x,y,yn,opt,set_of_graphs.size()-1); set_of_graphs.last().option = get_colums_bar_option(opt); + set_of_graphs.last().view = get_view_bar_option(opt); set_of_graphs.last().opt = opt; } diff --git a/src/Plot/Plot_unit_tests.hpp b/src/Plot/Plot_unit_tests.hpp index 04841b931a9c64fcc29a7b6987ae626ad4d4d1fc..13bdbc04a1507c55886a01640d2ca79c06eb2927 100644 --- a/src/Plot/Plot_unit_tests.hpp +++ b/src/Plot/Plot_unit_tests.hpp @@ -13,6 +13,60 @@ BOOST_AUTO_TEST_SUITE( plot_unit_test ) + +BOOST_AUTO_TEST_CASE( google_chart ) +{ + //! [Producing an Histogram graph] + + openfpm::vector<std::string> x; + openfpm::vector<openfpm::vector<size_t>> y; + openfpm::vector<std::string> yn; + + x.add("colum1"); + x.add("colum2"); + x.add("colum3"); + x.add("colum4"); + x.add("colum5"); + x.add("colum6"); + + // Each colum can have multiple data set (in this case 4 dataset) + // Each dataset can have a name + yn.add("dataset1"); + yn.add("dataset2"); + yn.add("dataset3"); + yn.add("dataset4"); + + // Each colums can have multiple data-set + y.add({2,3,5,6}); + y.add({5,6,1,6}); + y.add({2,1,6,9}); + y.add({1,6,3,2}); + y.add({3,3,0,6}); + y.add({2,1,4,6}); + + // Google charts options + GCoptions options; + + options.title = std::string("Example"); + options.yAxis = std::string("Y Axis"); + options.xAxis = std::string("X Axis"); + options.stype = std::string("bars"); + options.barWD = true; + + // it say that the colum4 must me represented with a line + options.stypeext = std::string("{3: {type: 'line'}}"); + + GoogleChart cg; + cg.AddHistGraph(x,y,yn,options); + cg.write("gc_out_wd.html"); + + //! [Producing an Histogram graph] + + bool test = compare("gc_out_wd.html","gc_out_wd_test.html"); + BOOST_REQUIRE_EQUAL(true,test); +} + + BOOST_AUTO_TEST_CASE( google_chart ) { //! [Producing an Histogram graph]