diff --git a/gc_out2_test.html b/gc_out2_test.html index 319e97c1073dc24c7157aa3fb3bafc079bb04826..16f6147e1cae865ac05b60a01a8385b70007554f 100644 --- a/gc_out2_test.html +++ b/gc_out2_test.html @@ -38,7 +38,8 @@ vAxis: {title: 'Y Axis'}, hAxis: {title: 'X Axis'}, seriesType: 'bars'}; $("#export_svg0").on("click", function (event) {exportToSVG.apply(this,[0]);}); -var chart = new google.visualization.ComboChart(document.getElementById('chart_div0'));chart.draw(data0, options0); +var chart = new google.visualization.ComboChart(document.getElementById('chart_div0')); +chart.draw(data0, options0); }
diff --git a/gc_out3_test.html b/gc_out3_test.html index 10eb9edf701d0be9d38a031bd44d82fb86325125..3eaf8466eb869c19006628900982ec5dd46783ac 100644 --- a/gc_out3_test.html +++ b/gc_out3_test.html @@ -38,7 +38,8 @@ vAxis: {title: 'Y Axis'}, hAxis: {title: 'X Axis'}, seriesType: ''}; $("#export_svg0").on("click", function (event) {exportToSVG.apply(this,[0]);}); -var chart = new google.visualization.ComboChart(document.getElementById('chart_div0'));chart.draw(data0, options0); +var chart = new google.visualization.ComboChart(document.getElementById('chart_div0')); +chart.draw(data0, options0); } diff --git a/gc_out4_test.html b/gc_out4_test.html index 6c00c1528bd98a9e230b67e500d473a0e35e77f7..f851830c498ab3315b7e8585f9d0cb6ac2e27b47 100644 --- a/gc_out4_test.html +++ b/gc_out4_test.html @@ -38,7 +38,8 @@ vAxis: {title: ''}, hAxis: {title: ''}, seriesType: ''}; $("#export_svg0").on("click", function (event) {exportToSVG.apply(this,[0]);}); -var chart = new google.visualization.ComboChart(document.getElementById('chart_div0'));chart.draw(data0, options0); +var chart = new google.visualization.ComboChart(document.getElementById('chart_div0')); +chart.draw(data0, options0); } diff --git a/gc_out5_test.html b/gc_out5_test.html index d579b983fd6d526304e4da5d47013efe38fd1629..4ef5259fdec336339185223f522efd6d0e93930d 100644 --- a/gc_out5_test.html +++ b/gc_out5_test.html @@ -38,7 +38,8 @@ vAxis: {title: ''}, hAxis: {title: ''}, seriesType: ''}; $("#export_svg0").on("click", function (event) {exportToSVG.apply(this,[0]);}); -var chart = new google.visualization.ComboChart(document.getElementById('chart_div0'));chart.draw(data0, options0); +var chart = new google.visualization.ComboChart(document.getElementById('chart_div0')); +chart.draw(data0, options0); } diff --git a/gc_out6_test.html b/gc_out6_test.html index 2f1de14b260a6846797d77efb8e7918819be2a4e..8b1afbb0f181a8cab8efceb11bc61e786a851d64 100644 --- a/gc_out6_test.html +++ b/gc_out6_test.html @@ -38,7 +38,8 @@ vAxis: {title: ''}, hAxis: {title: ''}, seriesType: ''}; $("#export_svg0").on("click", function (event) {exportToSVG.apply(this,[0]);}); -var chart = new google.visualization.ComboChart(document.getElementById('chart_div0'));chart.draw(data0, options0); +var chart = new google.visualization.ComboChart(document.getElementById('chart_div0')); +chart.draw(data0, options0); } diff --git a/gc_out7_test.html b/gc_out7_test.html index 81d5a5e1310b0ba1fccd09719610b6de48cc88da..b157cd50033ee4c2af1833d719f7d38d4996ea54 100644 --- a/gc_out7_test.html +++ b/gc_out7_test.html @@ -79,11 +79,14 @@ hAxis: {title: 'X Axis'}, seriesType: 'bars', series: {3: {type: 'line'}}}; $("#export_svg0").on("click", function (event) {exportToSVG.apply(this,[0]);}); -var chart = new google.visualization.ComboChart(document.getElementById('chart_div0'));chart.draw(data0, options0); +var chart = new google.visualization.ComboChart(document.getElementById('chart_div0')); +chart.draw(data0, options0); $("#export_svg1").on("click", function (event) {exportToSVG.apply(this,[1]);}); -var chart = new google.visualization.ComboChart(document.getElementById('chart_div1'));chart.draw(data1, options1); +var chart = new google.visualization.ComboChart(document.getElementById('chart_div1')); +chart.draw(data1, options1); $("#export_svg2").on("click", function (event) {exportToSVG.apply(this,[2]);}); -var chart = new google.visualization.ComboChart(document.getElementById('chart_div2'));chart.draw(data2, options2); +var chart = new google.visualization.ComboChart(document.getElementById('chart_div2')); +chart.draw(data2, options2); } diff --git a/gc_out_test.html b/gc_out_test.html index 60c941aefd4bea476acfda2414a5267a20092f5f..b65719ef3b2d79be7ccad9ed89d3b0fe9ce04126 100644 --- a/gc_out_test.html +++ b/gc_out_test.html @@ -39,7 +39,8 @@ hAxis: {title: 'X Axis'}, seriesType: 'bars', series: {3: {type: 'line'}}}; $("#export_svg0").on("click", function (event) {exportToSVG.apply(this,[0]);}); -var chart = new google.visualization.ComboChart(document.getElementById('chart_div0'));chart.draw(data0, options0); +var chart = new google.visualization.ComboChart(document.getElementById('chart_div0')); +chart.draw(data0, options0); } diff --git a/gc_plot2_out_test.html b/gc_plot2_out_test.html index 7cf93912e963e4e7fae09443a93d12a72f8a8184..f48dbf2078e27c13cdce1be8f88222b2029c8627 100644 --- a/gc_plot2_out_test.html +++ b/gc_plot2_out_test.html @@ -45,7 +45,8 @@ curveType: 'function', lineWidth: 1, intervals: { 'style':'area' }}; $("#export_svg0").on("click", function (event) {exportToSVG.apply(this,[0]);}); -var chart = new google.visualization.ComboChart(document.getElementById('chart_div0'));chart.draw(data0, options0); +var chart = new google.visualization.ComboChart(document.getElementById('chart_div0')); +chart.draw(data0, options0); } diff --git a/gc_plot_out_test.html b/gc_plot_out_test.html index 4a105cd7a115d370f2058780ad75f2951154c370..a52ce00093bec66089e37e2099e7899cc5492169 100644 --- a/gc_plot_out_test.html +++ b/gc_plot_out_test.html @@ -47,7 +47,8 @@ intervals: { 'style':'area' }, interval: {'i2': { 'color': '#4374E0', 'style':'bars', 'lineWidth':4, 'fillOpacity':1 } } }; $("#export_svg0").on("click", function (event) {exportToSVG.apply(this,[0]);}); -var chart = new google.visualization.ComboChart(document.getElementById('chart_div0'));chart.draw(data0, options0); +var chart = new google.visualization.ComboChart(document.getElementById('chart_div0')); +chart.draw(data0, options0); } diff --git a/src/Plot/GoogleChart.hpp b/src/Plot/GoogleChart.hpp index bf3bf61b0b368f927c544ea27c7ba4491d5c7227..44fcf9e31a4ddca411f11cb3d7c96457b47ce6c7 100644 --- a/src/Plot/GoogleChart.hpp +++ b/src/Plot/GoogleChart.hpp @@ -258,20 +258,22 @@ class GoogleChart */ std::string get_view_bar_option(const GCoptions & opt, size_t n_col) { + if (opt.barWD == false) + return std::string(); + std::stringstream str; - str << "view.setColumns([0," << std::endl; + str << "[0" << std::endl; - for (size_t i = 0 ; i < n_col ; i++) + for (size_t i = 1 ; i < n_col ; i++) { - - str << i << ",{ calc: \"stringify\"," << std::endl; + str << "," << i << ",{ calc: \"stringify\"," << std::endl; str << "sourceColumn: " << i << "," << std::endl; str << "type: \"string\"," << std::endl; str << "role: \"annotation\" }"<< std::endl; } - str << "]);" << std::endl; + str << "]" << std::endl; return str.str(); } @@ -344,19 +346,46 @@ class GoogleChart of << "};\n"; } + /*! \brief Add a view data variable + * + * \param of file out + * \param i id + * \param view string + * + */ + void addView(std::ofstream & of, size_t i, std::string view) + { + if (view.size() == 0) + return; + + of << "var view" << i << " = new google.visualization.DataView(data" << i << ");" << std::endl; + of << "view"<< i << ".setColumns("; + of << view << ");" << std::endl; + } + /*! \brief Add a draw div section * * \param of file out * \param i id + * \param draw_view draw a chart(true) or view(false) * */ - void addDrawDiv(std::ofstream & of, size_t i) + void addDrawDiv(std::ofstream & of, size_t i, bool draw_view) { of << "$(\"#export_svg" << i << "\").on(\"click\", function (event) {exportToSVG.apply(this,[" << i << "]);});\n"; of << "var chart = new google.visualization.ComboChart(document.getElementById('chart_div"; of << i; - of << "'));chart.draw(data"; - of << i; + of << "'));" << std::endl; + if (draw_view == true) + { + of << "chart.draw(data"; + of << i; + } + else + { + of << "chart.draw(view"; + of << i; + } of << ", options"; of << i; of << ");\n"; @@ -471,7 +500,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().view = get_view_bar_option(opt,y.get(0).size()); set_of_graphs.last().opt = opt; } @@ -633,7 +662,10 @@ public: addOption(of,i,set_of_graphs.get(i).option); for (size_t i = 0 ; i < set_of_graphs.size() ; i++) - addDrawDiv(of,i); + addView(of,i,set_of_graphs.get(i).view); + + for (size_t i = 0 ; i < set_of_graphs.size() ; i++) + addDrawDiv(of,i,set_of_graphs.get(i).view.size() == 0); of << begin_div; diff --git a/src/Plot/Plot_unit_tests.hpp b/src/Plot/Plot_unit_tests.hpp index 13bdbc04a1507c55886a01640d2ca79c06eb2927..d6f787b88e305aa2f25b94a00c0fe1405eacd039 100644 --- a/src/Plot/Plot_unit_tests.hpp +++ b/src/Plot/Plot_unit_tests.hpp @@ -14,7 +14,7 @@ BOOST_AUTO_TEST_SUITE( plot_unit_test ) -BOOST_AUTO_TEST_CASE( google_chart ) +BOOST_AUTO_TEST_CASE( google_chart_bar_string ) { //! [Producing an Histogram graph] @@ -58,11 +58,11 @@ BOOST_AUTO_TEST_CASE( google_chart ) GoogleChart cg; cg.AddHistGraph(x,y,yn,options); - cg.write("gc_out_wd.html"); + cg.write("gc_out_sc.html"); //! [Producing an Histogram graph] - bool test = compare("gc_out_wd.html","gc_out_wd_test.html"); + bool test = compare("gc_out_sc.html","gc_out_sc_test.html"); BOOST_REQUIRE_EQUAL(true,test); }