OpenFPM_pdata  4.1.0
Project that contain the implementation of distributed structures
 
Loading...
Searching...
No Matches
GoogleChart Class Reference

Small class to produce graph with Google chart in HTML. More...

Detailed Description

Small class to produce graph with Google chart in HTML.

This Class can produce several graph using google chart

Create Histogram graph

This code produce the graph above

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'}}");
cg.AddHistGraph(x,y,yn,options);
cg.write("gc_out_sc.html");
Small class to produce graph with Google chart in HTML.
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.
Implementation of 1-D std::vector like structure.
Google chart options.
std::string stypeext
std::string xAxis
X axis name.
std::string title
Title of the chart.
bool barWD
barWD
std::string stype
std::string yAxis
Y axis name.

Create Lines

This code produce the graph above

x.add("colum1");
x.add("colum2");
x.add("colum3");
x.add("colum4");
x.add("colum5");
x.add("colum6");
// Each line can have multiple intervals or error bars
// The first number specify the bottom line
// The last three numbers specify the top line + error band (min, max)
// The middle 5 line specify the middle lines + one external error band + one internal error band
y.add({0.10,0.20,0.19,0.22,0.195,0.215,0.35,0.34,0.36});
y.add({0.11,0.21,0.18,0.22,0.19,0.215,0.36,0.35,0.37});
y.add({0.12,0.22,0.21,0.23,0.215,0.225,0.35,0.34,0.36});
y.add({0.15,0.25,0.20,0.26,0.22,0.255,0.36,0.35,0.37});
y.add({0.09,0.29,0.25,0.30,0.26,0.295,0.35,0.34,0.36});
y.add({0.08,0.28,0.27,0.29,0.275,0.285,0.36,0.35,0.37});
// Google charts options
GCoptions options;
options.title = std::string("Example");
options.yAxis = std::string("Y Axis");
options.xAxis = std::string("X Axis");
options.lineWidth = 1.0;
cg.AddLinesGraph(x,y,options);
cg.write("gc_plot2_out.html");
void AddLinesGraph(openfpm::vector< X > &x, openfpm::vector< Y > &y, const GCoptions &opt)
Add a simple lines graph.
size_t lineWidth
Width of the line.

Create lines with different styles

This code produce the graph above

x.add("colum1");
x.add("colum2");
x.add("colum3");
x.add("colum4");
x.add("colum5");
x.add("colum6");
// Here we specify how many lines we have
// first Line
yn.add("line1");
// second line + 2 intervals (Error bands)
yn.add("line2");
yn.add("interval");
yn.add("interval");
yn.add("interval");
yn.add("interval");
// third line + 1 interval (Error bands)
yn.add("line3");
yn.add("interval");
yn.add("interval");
// Each line can have multiple intervals or error bars
// The first number specify the bottom line
// The last three numbers specify the top line + error band (min, max)
// The middle 5 line specify the middle lines + one external error band + one internal error band
y.add({0.10,0.20,0.19,0.22,0.195,0.215,0.35,0.34,0.36});
y.add({0.11,0.21,0.18,0.22,0.19,0.215,0.36,0.35,0.37});
y.add({0.12,0.22,0.21,0.23,0.215,0.225,0.35,0.34,0.36});
y.add({0.15,0.25,0.20,0.26,0.22,0.255,0.36,0.35,0.37});
y.add({0.09,0.29,0.25,0.30,0.26,0.295,0.35,0.34,0.36});
y.add({0.08,0.28,0.27,0.29,0.275,0.285,0.36,0.35,0.37});
// Google charts options
GCoptions options;
options.title = std::string("Example");
options.yAxis = std::string("Y Axis");
options.xAxis = std::string("X Axis");
options.lineWidth = 1.0;
options.intervalext = std::string("{'i2': { 'color': '#4374E0', 'style':'bars', 'lineWidth':4, 'fillOpacity':1 } }");
cg.AddLinesGraph(x,y,yn,options);
cg.write("gc_plot_out.html");
std::string intervalext

Definition at line 215 of file GoogleChart.hpp.

#include <GoogleChart.hpp>

Data Structures

struct  get_value_type
 

Public Member Functions

template<typename Y >
void AddHistGraph (openfpm::vector< Y > &y)
 Add an histogram graph.
 
template<typename X , typename Y >
void AddHistGraph (openfpm::vector< X > &x, openfpm::vector< Y > &y)
 Add an histogram graph.
 
template<typename X , typename Y , typename Yn >
void AddHistGraph (openfpm::vector< X > &x, openfpm::vector< Y > &y, openfpm::vector< Yn > &yn)
 Add an histogram graph.
 
template<typename X , typename Y , typename Yn >
void AddHistGraph (openfpm::vector< X > &x, openfpm::vector< Y > &y, openfpm::vector< Yn > &yn, const GCoptions &opt)
 Add an histogram graph.
 
template<typename ... X>
void AddLines (const openfpm::vector< std::string > &yn, const GCoptions &opt, X ... xy)
 Add lines graph.
 
template<typename X , typename Y >
void AddLinesGraphT (openfpm::vector< X > &x, openfpm::vector< Y > &y, const GCoptions &opt)
 Add lines graph.
 
template<typename X , typename Y >
void AddLinesGraph (openfpm::vector< X > &x, openfpm::vector< Y > &y, const GCoptions &opt)
 Add a simple lines graph.
 
template<typename X , typename Y >
void AddLinesGraph (openfpm::vector< X > &x, openfpm::vector< Y > &y, const openfpm::vector< std::string > &yn, const GCoptions &opt)
 Add a simple plot graph.
 
void addHTML (const std::string &html)
 Add HTML text.
 
void write (std::string file)
 It write the graphs on file in html format using Google charts.
 

Private Member Functions

template<typename X , typename ... Xs>
void recursive_sort (X &x, X &y, Xs &... xy)
 Recursively sort variadic template of vectors.
 
void recursive_sort ()
 terminator for recursive sort
 
template<typename X , typename ... Xs>
bool isNext (size_t *counters, X &x, X &y, Xs &... xy)
 Recursively sort variadic template of vectors.
 
bool isNext (size_t *counters)
 Recursively sort variadic template of vectors.
 
template<typename T , typename X , typename ... Xs>
get_low (size_t *counters, X &x, X &y, Xs &... xy)
 Recursively sort variadic template of vectors.
 
template<typename T >
get_low (size_t *counters)
 Recursively sort variadic template of vectors.
 
template<typename X , typename ... Xs>
void get_point (typename X::value_type low, typename X::value_type *point, size_t *counters, X &x, X &y, Xs &... xy)
 Recursively sort variadic template of vectors.
 
template<typename T >
void get_point (T low, T *point, size_t *counters)
 Recursively sort variadic template of vectors.
 
template<typename ... Xs>
bool get_v (typename get_value_type< Xs... >::type &x, typename get_value_type< Xs... >::type *point, size_t *counters, Xs &... xy)
 Recursively sort variadic template of vectors.
 
template<typename X , typename Y >
std::string get_points_plot_data (const openfpm::vector< X > &x, const openfpm::vector< Y > &y, const openfpm::vector< std::string > &yn, const GCoptions &opt, size_t i)
 Given X and Y vector return the string representing the data section of the Google Chart.
 
std::string get_view_bar_option (const GCoptions &opt, size_t n_col)
 Construct a view option.
 
std::string get_colums_bar_option (const GCoptions &opt)
 
std::string get_points_plot_option (const GCoptions &opt)
 
void addData (std::ofstream &of, size_t i, const std::string &data)
 Add a graph data variable.
 
void addOption (std::ofstream &of, size_t i, const std::string &opt)
 Add an option data variable.
 
void addView (std::ofstream &of, size_t i, std::string view)
 Add a view data variable.
 
void addDrawDiv (std::ofstream &of, size_t i, bool draw_view)
 Add a draw div section.
 
void addDiv (std::ofstream &of, size_t i, const GCoptions &gc)
 Add a div section.
 

Private Attributes

openfpm::vector< GGraphset_of_graphs
 set of graphs
 
openfpm::vector< std::string > injectHTML
 set inject HTML;
 
bool holes = false
 Data has holes.
 

Constructor & Destructor Documentation

◆ GoogleChart()

GoogleChart::GoogleChart ( )
inline

Definition at line 665 of file GoogleChart.hpp.

Member Function Documentation

◆ addData()

void GoogleChart::addData ( std::ofstream &  of,
size_t  i,
const std::string &  data 
)
inlineprivate

Add a graph data variable.

Parameters
offile out
iid
datastring

Definition at line 574 of file GoogleChart.hpp.

◆ addDiv()

void GoogleChart::addDiv ( std::ofstream &  of,
size_t  i,
const GCoptions gc 
)
inlineprivate

Add a div section.

Parameters
offile ofstream
iid of the graph
gcGoogleChart option

Definition at line 651 of file GoogleChart.hpp.

◆ addDrawDiv()

void GoogleChart::addDrawDiv ( std::ofstream &  of,
size_t  i,
bool  draw_view 
)
inlineprivate

Add a draw div section.

Parameters
offile out
iid
draw_viewdraw a chart(true) or view(false)

Definition at line 623 of file GoogleChart.hpp.

◆ AddHistGraph() [1/4]

template<typename X , typename Y >
void GoogleChart::AddHistGraph ( openfpm::vector< X > &  x,
openfpm::vector< Y > &  y 
)
inline

Add an histogram graph.

Parameters
yA vector of vectors the size of y indicate how many values we have on x each x value can have multiple values or datasets
xGive a name or number to each colums. Can be a string or a number

Definition at line 692 of file GoogleChart.hpp.

◆ AddHistGraph() [2/4]

template<typename X , typename Y , typename Yn >
void GoogleChart::AddHistGraph ( openfpm::vector< X > &  x,
openfpm::vector< Y > &  y,
openfpm::vector< Yn > &  yn 
)
inline

Add an histogram graph.

Parameters
yA vector of vectors the size of y indicate how many values we have on x each x value can have multiple values or datasets
xGive a name or number to each colums. Can be a string or a number
ynGive a name to each dataset

Definition at line 714 of file GoogleChart.hpp.

◆ AddHistGraph() [3/4]

template<typename X , typename Y , typename Yn >
void GoogleChart::AddHistGraph ( openfpm::vector< X > &  x,
openfpm::vector< Y > &  y,
openfpm::vector< Yn > &  yn,
const GCoptions opt 
)
inline

Add an histogram graph.

Parameters
yA vector of vectors the size of y indicate how many values we have on x each x value can have multiple values or datasets
xGive a name or number to each colums. Can be a string or a number
ynGive a name to each dataset
optGraph options

Definition at line 733 of file GoogleChart.hpp.

◆ AddHistGraph() [4/4]

template<typename Y >
void GoogleChart::AddHistGraph ( openfpm::vector< Y > &  y)
inline

Add an histogram graph.

Parameters
yA vector of vectors the size of y indicate how many values we have on x each x value can have multiple values or datasets

Definition at line 676 of file GoogleChart.hpp.

◆ addHTML()

void GoogleChart::addHTML ( const std::string &  html)
inline

Add HTML text.

Parameters
htmladd html text in the page

Definition at line 949 of file GoogleChart.hpp.

◆ AddLines()

template<typename ... X>
void GoogleChart::AddLines ( const openfpm::vector< std::string > &  yn,
const GCoptions opt,
X ...  xy 
)
inline

Add lines graph.

Parameters
xylist of vectors like openfpm::vector<float> or openfpm::vector<double>. Suppose you have a dataset of points x1,y1 and a dataset x2,y2 and you want to display all these points in one graph. Than you call this function with AddLines(x1,y1,x2,y2,opt)
optGraph options

Definition at line 767 of file GoogleChart.hpp.

◆ AddLinesGraph() [1/2]

template<typename X , typename Y >
void GoogleChart::AddLinesGraph ( openfpm::vector< X > &  x,
openfpm::vector< Y > &  y,
const GCoptions opt 
)
inline

Add a simple lines graph.

If the x vector contain 0.0,0.1,0.2,0.3,0.4 and you want to draw two lines you specifying two y values for each of the x points you create an openfpm::vector<openfpm::vector<float>> y such that

                  --  j  --
y.get(i).get(j) = 3.2   3.4
                  1.4   5.3 |
                  5.4   3.2 i
                  1.3   2.2 |
                  2.3   1.1
Parameters
yA vector of vectors of values. The size of y indicate how many x values we have, while the internal vector can store multiple value of the same point, for example error bar
xGive a name or number to each x value, so can be a string or a number
optGraph options

Definition at line 886 of file GoogleChart.hpp.

◆ AddLinesGraph() [2/2]

template<typename X , typename Y >
void GoogleChart::AddLinesGraph ( openfpm::vector< X > &  x,
openfpm::vector< Y > &  y,
const openfpm::vector< std::string > &  yn,
const GCoptions opt 
)
inline

Add a simple plot graph.

Parameters
yA vector of vector of values (numbers) the size of y indicate how many x values or colums we have, while the internal vector store multiple lines, or error bars
xGive a name or number to each colums, so can be a string or a number
ynGive a name to each line, or specify an error bar
optGraph options

Definition at line 915 of file GoogleChart.hpp.

◆ AddLinesGraphT()

template<typename X , typename Y >
void GoogleChart::AddLinesGraphT ( openfpm::vector< X > &  x,
openfpm::vector< Y > &  y,
const GCoptions opt 
)
inline

Add lines graph.

If the x vector contain 0.0,0.1,0.2,0.3,0.4 and you want to draw two lines you specifying two y values for each of the x points you create an openfpm::vector<openfpm::vector<float>> y such that

                        ------  j  -------        |
y.get(i).get(j) = 3.2   3.4    5.4    1.3    2.3  i
                  1.4   5.3    3.2    2.1    1.1  |
Parameters
yA vector of vectors of values. each vector contain the graph points, compared to AddLinesGraph the points are stored
xaxis values
optGraph options

Definition at line 819 of file GoogleChart.hpp.

◆ addOption()

void GoogleChart::addOption ( std::ofstream &  of,
size_t  i,
const std::string &  opt 
)
inlineprivate

Add an option data variable.

Parameters
offile out
iid
optstring

Definition at line 588 of file GoogleChart.hpp.

◆ addView()

void GoogleChart::addView ( std::ofstream &  of,
size_t  i,
std::string  view 
)
inlineprivate

Add a view data variable.

Parameters
offile out
iid
viewstring

Definition at line 606 of file GoogleChart.hpp.

◆ get_colums_bar_option()

std::string GoogleChart::get_colums_bar_option ( const GCoptions opt)
inlineprivate

Definition at line 529 of file GoogleChart.hpp.

◆ get_low() [1/2]

template<typename T >
T GoogleChart::get_low ( size_t *  counters)
inlineprivate

Recursively sort variadic template of vectors.

Parameters
countersindexes

Definition at line 349 of file GoogleChart.hpp.

◆ get_low() [2/2]

template<typename T , typename X , typename ... Xs>
T GoogleChart::get_low ( size_t *  counters,
X &  x,
X &  y,
Xs &...  xy 
)
inlineprivate

Recursively sort variadic template of vectors.

Parameters
countersindexes
xvector with x
yvector with y
xyall the other vectors

Definition at line 324 of file GoogleChart.hpp.

◆ get_point() [1/2]

template<typename T >
void GoogleChart::get_point ( low,
T *  point,
size_t *  counters 
)
inlineprivate

Recursively sort variadic template of vectors.

Parameters
xvector with x
yvector with y
xyall the other vectors

Definition at line 390 of file GoogleChart.hpp.

◆ get_point() [2/2]

template<typename X , typename ... Xs>
void GoogleChart::get_point ( typename X::value_type  low,
typename X::value_type *  point,
size_t *  counters,
X &  x,
X &  y,
Xs &...  xy 
)
inlineprivate

Recursively sort variadic template of vectors.

Parameters
xvector with x
yvector with y
xyall the other vectors

Definition at line 362 of file GoogleChart.hpp.

◆ get_points_plot_data()

template<typename X , typename Y >
std::string GoogleChart::get_points_plot_data ( const openfpm::vector< X > &  x,
const openfpm::vector< Y > &  y,
const openfpm::vector< std::string > &  yn,
const GCoptions opt,
size_t  i 
)
inlineprivate

Given X and Y vector return the string representing the data section of the Google Chart.

Template Parameters
Xtype for the X coordinates
Ytype for the Y coordinates
Parameters
xvector of points on x
yvector of points on y
ynvector containing the name of each graph
optoptions to draw the graph
iindex of the graph we are drawing
Returns
string with the data section

Definition at line 438 of file GoogleChart.hpp.

◆ get_points_plot_option()

std::string GoogleChart::get_points_plot_option ( const GCoptions opt)
inlineprivate

Definition at line 544 of file GoogleChart.hpp.

◆ get_v()

template<typename ... Xs>
bool GoogleChart::get_v ( typename get_value_type< Xs... >::type &  x,
typename get_value_type< Xs... >::type *  point,
size_t *  counters,
Xs &...  xy 
)
inlineprivate

Recursively sort variadic template of vectors.

Parameters
xvector with x
yvector with y
xyall the other vectors

Definition at line 405 of file GoogleChart.hpp.

◆ get_view_bar_option()

std::string GoogleChart::get_view_bar_option ( const GCoptions opt,
size_t  n_col 
)
inlineprivate

Construct a view option.

Parameters
optGoogleChart option
Returns
the string

Definition at line 507 of file GoogleChart.hpp.

◆ isNext() [1/2]

bool GoogleChart::isNext ( size_t *  counters)
inlineprivate

Recursively sort variadic template of vectors.

Parameters
countersindexes

Definition at line 309 of file GoogleChart.hpp.

◆ isNext() [2/2]

template<typename X , typename ... Xs>
bool GoogleChart::isNext ( size_t *  counters,
X &  x,
X &  y,
Xs &...  xy 
)
inlineprivate

Recursively sort variadic template of vectors.

Parameters
countersindexes
xvector with x
yvector with y
xyall the other vectors

Definition at line 295 of file GoogleChart.hpp.

◆ recursive_sort() [1/2]

void GoogleChart::recursive_sort ( )
inlineprivate

terminator for recursive sort

Definition at line 283 of file GoogleChart.hpp.

◆ recursive_sort() [2/2]

template<typename X , typename ... Xs>
void GoogleChart::recursive_sort ( X &  x,
X &  y,
Xs &...  xy 
)
inlineprivate

Recursively sort variadic template of vectors.

Parameters
xvector with x
yvector with y
xyall the other vectors

Definition at line 240 of file GoogleChart.hpp.

◆ write()

void GoogleChart::write ( std::string  file)
inline

It write the graphs on file in html format using Google charts.

Parameters
fileoutput file

Definition at line 959 of file GoogleChart.hpp.

Field Documentation

◆ holes

bool GoogleChart::holes = false
private

Data has holes.

Definition at line 230 of file GoogleChart.hpp.

◆ injectHTML

openfpm::vector<std::string> GoogleChart::injectHTML
private

set inject HTML;

Definition at line 227 of file GoogleChart.hpp.

◆ set_of_graphs

openfpm::vector<GGraph> GoogleChart::set_of_graphs
private

set of graphs

Definition at line 224 of file GoogleChart.hpp.


The documentation for this class was generated from the following file: