Commit f02a479f authored by incardon's avatar incardon

New colums with numbers

parent b03ba0d2
...@@ -38,7 +38,8 @@ vAxis: {title: 'Y Axis'}, ...@@ -38,7 +38,8 @@ vAxis: {title: 'Y Axis'},
hAxis: {title: 'X Axis'}, hAxis: {title: 'X Axis'},
seriesType: 'bars'}; seriesType: 'bars'};
$("#export_svg0").on("click", function (event) {exportToSVG.apply(this,[0]);}); $("#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);
}</script> }</script>
</head> </head>
<body> <body>
......
...@@ -38,7 +38,8 @@ vAxis: {title: 'Y Axis'}, ...@@ -38,7 +38,8 @@ vAxis: {title: 'Y Axis'},
hAxis: {title: 'X Axis'}, hAxis: {title: 'X Axis'},
seriesType: ''}; seriesType: ''};
$("#export_svg0").on("click", function (event) {exportToSVG.apply(this,[0]);}); $("#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);
}</script> }</script>
</head> </head>
<body> <body>
......
...@@ -38,7 +38,8 @@ vAxis: {title: ''}, ...@@ -38,7 +38,8 @@ vAxis: {title: ''},
hAxis: {title: ''}, hAxis: {title: ''},
seriesType: ''}; seriesType: ''};
$("#export_svg0").on("click", function (event) {exportToSVG.apply(this,[0]);}); $("#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);
}</script> }</script>
</head> </head>
<body> <body>
......
...@@ -38,7 +38,8 @@ vAxis: {title: ''}, ...@@ -38,7 +38,8 @@ vAxis: {title: ''},
hAxis: {title: ''}, hAxis: {title: ''},
seriesType: ''}; seriesType: ''};
$("#export_svg0").on("click", function (event) {exportToSVG.apply(this,[0]);}); $("#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);
}</script> }</script>
</head> </head>
<body> <body>
......
...@@ -38,7 +38,8 @@ vAxis: {title: ''}, ...@@ -38,7 +38,8 @@ vAxis: {title: ''},
hAxis: {title: ''}, hAxis: {title: ''},
seriesType: ''}; seriesType: ''};
$("#export_svg0").on("click", function (event) {exportToSVG.apply(this,[0]);}); $("#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);
}</script> }</script>
</head> </head>
<body> <body>
......
...@@ -79,11 +79,14 @@ hAxis: {title: 'X Axis'}, ...@@ -79,11 +79,14 @@ hAxis: {title: 'X Axis'},
seriesType: 'bars', seriesType: 'bars',
series: {3: {type: 'line'}}}; series: {3: {type: 'line'}}};
$("#export_svg0").on("click", function (event) {exportToSVG.apply(this,[0]);}); $("#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]);}); $("#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]);}); $("#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);
}</script> }</script>
</head> </head>
<body> <body>
......
...@@ -39,7 +39,8 @@ hAxis: {title: 'X Axis'}, ...@@ -39,7 +39,8 @@ hAxis: {title: 'X Axis'},
seriesType: 'bars', seriesType: 'bars',
series: {3: {type: 'line'}}}; series: {3: {type: 'line'}}};
$("#export_svg0").on("click", function (event) {exportToSVG.apply(this,[0]);}); $("#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);
}</script> }</script>
</head> </head>
<body> <body>
......
...@@ -45,7 +45,8 @@ curveType: 'function', ...@@ -45,7 +45,8 @@ curveType: 'function',
lineWidth: 1, lineWidth: 1,
intervals: { 'style':'area' }}; intervals: { 'style':'area' }};
$("#export_svg0").on("click", function (event) {exportToSVG.apply(this,[0]);}); $("#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);
}</script> }</script>
</head> </head>
<body> <body>
......
...@@ -47,7 +47,8 @@ intervals: { 'style':'area' }, ...@@ -47,7 +47,8 @@ intervals: { 'style':'area' },
interval: {'i2': { 'color': '#4374E0', 'style':'bars', 'lineWidth':4, 'fillOpacity':1 } } interval: {'i2': { 'color': '#4374E0', 'style':'bars', 'lineWidth':4, 'fillOpacity':1 } }
}; };
$("#export_svg0").on("click", function (event) {exportToSVG.apply(this,[0]);}); $("#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);
}</script> }</script>
</head> </head>
<body> <body>
......
...@@ -258,20 +258,22 @@ class GoogleChart ...@@ -258,20 +258,22 @@ class GoogleChart
*/ */
std::string get_view_bar_option(const GCoptions & opt, size_t n_col) std::string get_view_bar_option(const GCoptions & opt, size_t n_col)
{ {
if (opt.barWD == false)
return std::string();
std::stringstream str; 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 << "sourceColumn: " << i << "," << std::endl;
str << "type: \"string\"," << std::endl; str << "type: \"string\"," << std::endl;
str << "role: \"annotation\" }"<< std::endl; str << "role: \"annotation\" }"<< std::endl;
} }
str << "]);" << std::endl; str << "]" << std::endl;
return str.str(); return str.str();
} }
...@@ -344,19 +346,46 @@ class GoogleChart ...@@ -344,19 +346,46 @@ class GoogleChart
of << "};\n"; 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 /*! \brief Add a draw div section
* *
* \param of file out * \param of file out
* \param i id * \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 << "$(\"#export_svg" << i << "\").on(\"click\", function (event) {exportToSVG.apply(this,[" << i << "]);});\n";
of << "var chart = new google.visualization.ComboChart(document.getElementById('chart_div"; of << "var chart = new google.visualization.ComboChart(document.getElementById('chart_div";
of << i; of << i;
of << "'));chart.draw(data"; of << "'));" << std::endl;
of << i; if (draw_view == true)
{
of << "chart.draw(data";
of << i;
}
else
{
of << "chart.draw(view";
of << i;
}
of << ", options"; of << ", options";
of << i; of << i;
of << ");\n"; of << ");\n";
...@@ -471,7 +500,7 @@ public: ...@@ -471,7 +500,7 @@ public:
set_of_graphs.last().type = GGRAPH_COLUMS; 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().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().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; set_of_graphs.last().opt = opt;
} }
...@@ -633,7 +662,10 @@ public: ...@@ -633,7 +662,10 @@ public:
addOption(of,i,set_of_graphs.get(i).option); addOption(of,i,set_of_graphs.get(i).option);
for (size_t i = 0 ; i < set_of_graphs.size() ; i++) 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; of << begin_div;
......
...@@ -14,7 +14,7 @@ ...@@ -14,7 +14,7 @@
BOOST_AUTO_TEST_SUITE( plot_unit_test ) 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] //! [Producing an Histogram graph]
...@@ -58,11 +58,11 @@ BOOST_AUTO_TEST_CASE( google_chart ) ...@@ -58,11 +58,11 @@ BOOST_AUTO_TEST_CASE( google_chart )
GoogleChart cg; GoogleChart cg;
cg.AddHistGraph(x,y,yn,options); cg.AddHistGraph(x,y,yn,options);
cg.write("gc_out_wd.html"); cg.write("gc_out_sc.html");
//! [Producing an Histogram graph] //! [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); BOOST_REQUIRE_EQUAL(true,test);
} }
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment