...
 
Commits (7)
......@@ -35,7 +35,9 @@ if(ENABLE_GPU)
elseif ( CUDA_VERSION_MAJOR EQUAL 10 AND CUDA_VERSION_MINOR EQUAL 1 )
message("CUDA is compatible")
set(WARNING_SUPPRESSION_AND_OPTION_NVCC -Xcudafe "--display_error_number --diag_suppress=2915 --diag_suppress=2912 --diag_suppress=2913 --diag_suppress=111 --diag_suppress=186 --diag_suppress=611 " --expt-extended-lambda)
elseif ( CUDA_VERSION_MAJOR EQUAL 10 AND CUDA_VERSION_MINOR EQUAL 2 )
message("CUDA is compatible")
set(WARNING_SUPPRESSION_AND_OPTION_NVCC -Xcudafe "--display_error_number --diag_suppress=2977 --diag_suppress=2976 --diag_suppress=2979 --diag_suppress=186" --expt-extended-lambda)
else()
message(FATAL_ERROR "CUDA is incompatible, version 9.2 is only supported")
endif()
......
<html>
<head>
<script type="text/javascript" src="https://www.gstatic.com/charts/loader.js"></script>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.12.4/jquery.min.js"></script>
<script type="text/javascript">
google.charts.load('current', {'packages':['corechart']});
google.charts.setOnLoadCallback(drawVisualization);
function exportToSVG(i)
{
var e = document.getElementById('chart_div'+i);
var svg = e.getElementsByTagName('svg')[0].parentNode.innerHTML;
var pos = svg.lastIndexOf("</svg>");
pos += 6;
svg = svg.substring(0,4) + " xmlns='http://www.w3.org/2000/svg' xmlns:xlink= 'http://www.w3.org/1999/xlink' " + svg.substring(4,pos);
svgData = 'data:image/svg+xml;charset=utf-8,' + encodeURIComponent(svg);
$(this).attr({'href': svgData,'target': '_blank'});
}
function drawVisualization() {
var data0 = new google.visualization.DataTable();
data0.addColumn('number','X Axis');
data0.addColumn('number','dataset1');
data0.addColumn('number','dataset2');
data0.addColumn('number','dataset3');
data0.addRows([
[0.1,4.5,null,3.5],
[0.15,null,1.5,null],
[0.2,3,4.5,6.5],
[0.3,5.5,null,null],
[0.35,null,2.5,null],
[0.37,null,null,1.5],
[0.4,3.3,null,2.5],
[0.45,null,6.5,null],
[0.5,1,null,7.5],
[0.6,7,null,null],
[0.63,null,null,1.5],
[0.7,null,null,3.5],
[0.82,null,null,2.5],
[0.91,null,null,5.5],
[1,null,null,1.5],
]);
var options0= {
interpolateNulls : true,
title : 'Example',
vAxis: {title: 'Y Axis'},
hAxis: {title: 'X Axis'},
curveType: 'function',
lineWidth: 4,
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);
}</script>
</head>
<body>
<a href="#" download="graph1.svg" id="export_svg0"><button>Export data into svg</button></a><div id="chart_div0" style="width: 900px; height: 500px;"></div>
</body>
</html>
......@@ -24,6 +24,11 @@ endif()
if (CUDA_FOUND)
target_compile_options(io PUBLIC $<$<COMPILE_LANGUAGE:CUDA>: ${WARNING_SUPPRESSION_AND_OPTION_NVCC} >)
target_include_directories (io PUBLIC ${MPI_C_INCLUDE_DIRS})
if( CMAKE_CXX_COMPILER_VERSION VERSION_LESS 5.0 )
add_compile_options( "-fabi-version=6" )
endif()
if (TEST_COVERAGE)
target_compile_options(io PRIVATE $<$<COMPILE_LANGUAGE:CUDA>: -Xcompiler "-fprofile-arcs -ftest-coverage">)
endif()
......
......@@ -56,12 +56,12 @@ struct csv_prp
template<typename T>
void operator()(T& t)
{
// This is the type of the csv column
typedef decltype(obj.template get<T::value>()) col_type;
// This is the type of the csv column
typedef typename boost::mpl::at<typename Tobj::type,T>::type col_type;
// Remove the reference from the column type
typedef typename boost::remove_reference<col_type>::type col_rtype;
typedef typename std::remove_all_extents<col_rtype>::type base_col_rtype;
// Remove the reference from the column type
typedef typename boost::remove_reference<col_type>::type col_rtype;
typedef typename std::remove_all_extents<col_rtype>::type base_col_rtype;
csv_value_str<col_rtype, is_csv_writable<base_col_rtype>::value >(obj.template get<T::value>(),str);
}
......
......@@ -137,7 +137,8 @@ struct csv_value_str
template<typename T,size_t N1, bool is_writable>
struct csv_value_str<T[N1], is_writable>
{
inline csv_value_str(const T v[N1], std::stringstream & str)
template<typename ArrObject>
inline csv_value_str(const ArrObject v, std::stringstream & str)
{
for (size_t i = 0 ; i < N1 ; i++)
str << "," << v[i];
......@@ -148,7 +149,8 @@ struct csv_value_str<T[N1], is_writable>
template<typename T,size_t N1,size_t N2, bool is_writable>
struct csv_value_str<T[N1][N2], is_writable>
{
inline csv_value_str(const T v[N1][N2], std::stringstream & str)
template<typename ArrObject>
inline csv_value_str(const ArrObject v[N1][N2], std::stringstream & str)
{
for (size_t i1 = 0 ; i1 < N1 ; i1++)
{
......@@ -164,7 +166,8 @@ struct csv_value_str<T[N1][N2], is_writable>
template<typename T,size_t N1,size_t N2,size_t N3, bool is_writable>
struct csv_value_str<T[N1][N2][N3], is_writable>
{
inline csv_value_str(const T v[N1][N2][N3], std::stringstream & str)
template<typename ArrObject>
inline csv_value_str(const ArrObject v[N1][N2][N3], std::stringstream & str)
{
for (size_t i1 = 0 ; i1 < N1 ; i1++)
{
......@@ -183,7 +186,8 @@ struct csv_value_str<T[N1][N2][N3], is_writable>
template<typename T,size_t N1,size_t N2,size_t N3,size_t N4, bool is_writable>
struct csv_value_str<T[N1][N2][N3][N4],is_writable>
{
inline csv_value_str(const T v[N1][N2][N3][N4], std::stringstream & str)
template<typename ArrObject>
inline csv_value_str(const ArrObject v[N1][N2][N3][N4], std::stringstream & str)
{
for (size_t i1 = 0 ; i1 < N1 ; i1++)
{
......
......@@ -125,17 +125,17 @@ struct vertex_prop
{cnt++; return ;}
// Create a property string based on the type of the property
if (typeid(T) == typeid(float))
if (std::is_same<T,float>::value)
v_prop += "<key id=\"vk" + std::to_string(cnt) + "\" for=\"node\" attr.name=\"" + attributes_names[cnt] + "\" attr.type=\"float\"/>\n";
else if (typeid(T) == typeid(double))
else if (std::is_same<T,double>::value)
v_prop += "<key id=\"vk" + std::to_string(cnt) + "\" for=\"node\" attr.name=\"" + attributes_names[cnt] + "\" attr.type=\"double\"/>\n";
else if (typeid(T) == typeid(int))
else if (std::is_same<T,int>::value)
v_prop += "<key id=\"vk" + std::to_string(cnt) + "\" for=\"node\" attr.name=\"" + attributes_names[cnt] + "\" attr.type=\"int\"/>\n";
else if (typeid(T) == typeid(long int))
else if (std::is_same<T,long int>::value)
v_prop += "<key id=\"vk" + std::to_string(cnt) + "\" for=\"node\" attr.name=\"" + attributes_names[cnt] + "\" attr.type=\"long\"/>\n";
else if (typeid(T) == typeid(bool))
else if (std::is_same<T,bool>::value)
v_prop += "<key id=\"vk" + std::to_string(cnt) + "\" for=\"node\" attr.name=\"" + attributes_names[cnt] + "\" attr.type=\"boolean\"/>\n";
else if (typeid(T) == typeid(std::string))
else if (std::is_same<T,std::string>::value)
v_prop += "<key id=\"vk" + std::to_string(cnt) + "\" for=\"node\" attr.name=\"" + attributes_names[cnt] + "\" attr.type=\"string\"/>\n";
}
......@@ -278,18 +278,20 @@ struct vertex_node
//! Create an entry for the attribute
if (T::value < n_attr)
{
typedef typename std::remove_reference<decltype(vo.template get<T::value>())>::type type_get;
// Create a property string based on the type of the property
if (typeid(decltype(vo.template get<T::value>())) == typeid(float))
if (std::is_same<type_get,float>::value)
v_node += " <data key=\"vk" + std::to_string(cnt) + "\">" + std::to_string(vo.template get<T::value>()) + "</data>\n";
else if (typeid(decltype(vo.template get<T::value>())) == typeid(double))
else if (std::is_same<type_get,double>::value)
v_node += " <data key=\"vk" + std::to_string(cnt) + "\">" + std::to_string(vo.template get<T::value>()) + "</data>\n";
else if (typeid(decltype(vo.template get<T::value>())) == typeid(int))
else if (std::is_same<type_get,int>::value )
v_node += " <data key=\"vk" + std::to_string(cnt) + "\">" + std::to_string(vo.template get<T::value>()) + "</data>\n";
else if (typeid(decltype(vo.template get<T::value>())) == typeid(long int))
else if (std::is_same<type_get,long int>::value)
v_node += " <data key=\"vk" + std::to_string(cnt) + "\">" + std::to_string(vo.template get<T::value>()) + "</data>\n";
else if (typeid(decltype(vo.template get<T::value>())) == typeid(bool))
else if (std::is_same<type_get,bool>::value)
v_node += " <data key=\"vk" + std::to_string(cnt) + "\">" + std::to_string(vo.template get<T::value>()) + "</data>\n";
else if (typeid(decltype(vo.template get<T::value>())) == typeid(std::string))
else if (std::is_same<type_get,std::string>::value)
v_node += " <data key=\"vk" + std::to_string(cnt) + "\">" + std::to_string(vo.template get<T::value>()) + "</data>\n";
}
......@@ -379,17 +381,17 @@ struct edge_prop
if (cnt < n_attr)
{
// Create a property string based on the type of the property
if (typeid(T) == typeid(float))
if (std::is_same<T,float>::value)
e_prop += "<key id=\"ek" + std::to_string(cnt) + "\" for=\"edge\" attr.name=\"" + attributes_names[cnt] + "\" attr.type=\"float\"/>\n";
else if (typeid(T) == typeid(double))
else if (std::is_same<T,double>::value)
e_prop += "<key id=\"ek" + std::to_string(cnt) + "\" for=\"edge\" attr.name=\"" + attributes_names[cnt] + "\" attr.type=\"double\"/>\n";
else if (typeid(T) == typeid(int))
else if (std::is_same<T,int>::value)
e_prop += "<key id=\"ek" + std::to_string(cnt) + "\" for=\"edge\" attr.name=\"" + attributes_names[cnt] + "\" attr.type=\"int\"/>\n";
else if (typeid(T) == typeid(long int))
else if (std::is_same<T,long int>::value)
e_prop += "<key id=\"ek" + std::to_string(cnt) + "\" for=\"edge\" attr.name=\"" + attributes_names[cnt] + "\" attr.type=\"long\"/>\n";
else if (typeid(T) == typeid(bool))
else if (std::is_same<T,bool>::value)
e_prop += "<key id=\"ek" + std::to_string(cnt) + "\" for=\"edge\" attr.name=\"" + attributes_names[cnt] + "\" attr.type=\"boolean\"/>\n";
else if (typeid(T) == typeid(std::string))
else if (std::is_same<T,std::string>::value)
e_prop += "<key id=\"ek" + std::to_string(cnt) + "\" for=\"edge\" attr.name=\"" + attributes_names[cnt] + "\" attr.type=\"string\"/>\n";
}
......@@ -510,18 +512,20 @@ struct edge_node
//! Create an entry for the attribute
if (T::value < n_attr)
{
typedef typename std::remove_reference<decltype(vo.template get<T::value>())>::type type_get;
// Create a property string based on the type of the property
if (typeid(decltype(vo.template get<T::value>())) == typeid(float))
if (std::is_same<type_get,float>::value)
e_node += " <data key=\"ek" + std::to_string(cnt) + "\">" + std::to_string(vo.template get<T::value>()) + "</data>\n";
else if (typeid(decltype(vo.template get<T::value>())) == typeid(double))
else if (std::is_same<type_get,double>::value)
e_node += " <data key=\"ek" + std::to_string(cnt) + "\">" + std::to_string(vo.template get<T::value>()) + "</data>\n";
else if (typeid(decltype(vo.template get<T::value>())) == typeid(int))
else if (std::is_same<type_get,int>::value)
e_node += " <data key=\"ek" + std::to_string(cnt) + "\">" + std::to_string(vo.template get<T::value>()) + "</data>\n";
else if (typeid(decltype(vo.template get<T::value>())) == typeid(long int))
else if (std::is_same<type_get,long int>::value)
e_node += " <data key=\"ek" + std::to_string(cnt) + "\">" + std::to_string(vo.template get<T::value>()) + "</data>\n";
else if (typeid(decltype(vo.template get<T::value>())) == typeid(bool))
else if (std::is_same<type_get,bool>::value)
e_node += " <data key=\"ek" + std::to_string(cnt) + "\">" + std::to_string(vo.template get<T::value>()) + "</data>\n";
else if (typeid(decltype(vo.template get<T::value>())) == typeid(std::string))
else if (std::is_same<type_get,std::string>::value)
e_node += " <data key=\"ek" + std::to_string(cnt) + "\">" + std::to_string(vo.template get<T::value>()) + "</data>\n";
}
......
......@@ -10,7 +10,7 @@
#include "VCluster/VCluster.hpp"
#include <hdf5.h>
#include "hdf5.h"
template <unsigned int type>
class HDF5_writer
......
......@@ -10,6 +10,7 @@
#include <fstream>
#include "Vector/map_vector.hpp"
#include <cmath>
#define GGRAPH_COLUMS 1
#define GGRAPH_POINTS 2
......@@ -153,6 +154,33 @@ const std::string saving_javascript = "function save(i)\n\
var e = document.getElementById('chart_')\n\
e.getElementsByTagName('svg')[0].parentNode.innerHTML";
template<typename T>
struct check_nan
{
static bool check(const T & n)
{
return false;
}
};
template<>
struct check_nan<float>
{
static bool check(const float & n)
{
return std::isnan(n);
}
};
template<>
struct check_nan<double>
{
static bool check(const double & n)
{
return std::isnan(n);
}
};
/////////////////////////////////////////////////////////////////////
/*! \brief Small class to produce graph with Google chart in HTML
......@@ -186,12 +214,213 @@ const std::string saving_javascript = "function save(i)\n\
*/
class GoogleChart
{
template<typename arg_0, typename ... args>
struct get_value_type
{
typedef typename arg_0::value_type type;
};
//! set of graphs
openfpm::vector<GGraph> set_of_graphs;
//! set inject HTML;
openfpm::vector<std::string> injectHTML;
//! Data has holes
bool holes = false;
/*! \brief Recursively sort variadic template of vectors
*
* \param x vector with x
* \param y vector with y
* \param xy all the other vectors
*
*/
template<typename X, typename ... Xs>
void recursive_sort(X & x,X & y,Xs& ... xy)
{
struct srt_xy
{
typename X::value_type x;
unsigned int id;
bool operator<(const srt_xy & tmp) const
{
return x < tmp.x;
}
};
openfpm::vector<srt_xy> reord;
X y_tmp;
reord.resize(x.size());
y_tmp.resize(x.size());
for (size_t i = 0 ; i < x.size() ; i++)
{
reord.get(i).x = x.get(i);
reord.get(i).id = i;
}
reord.sort();
// reorder x and y
for (size_t i = 0 ; i < x.size() ; i++)
{
x.get(i) = reord.get(i).x;
y_tmp.get(i) = y.get(reord.get(i).id);
}
y_tmp.swap(y);
// sort x
recursive_sort(xy ...);
}
//! terminator for recursive sort
void recursive_sort()
{}
/*! \brief Recursively sort variadic template of vectors
*
* \param counters indexes
* \param x vector with x
* \param y vector with y
* \param xy all the other vectors
*
*/
template<typename X, typename ... Xs>
bool isNext(size_t * counters,X & x,X & y,Xs& ... xy)
{
if (counters[0] < x.size())
{
return true;
}
return isNext(&counters[1],xy ...);
}
/*! \brief Recursively sort variadic template of vectors
*
* \param counters indexes
*
*/
bool isNext(size_t * counters)
{
return false;
}
/*! \brief Recursively sort variadic template of vectors
*
* \param counters indexes
* \param x vector with x
* \param y vector with y
* \param xy all the other vectors
*
*/
template<typename T, typename X, typename ... Xs>
T get_low(size_t * counters,X & x,X & y,Xs& ... xy)
{
if (sizeof...(Xs) != 0)
{
T low1;
if (counters[0] >= x.size())
{low1 = std::numeric_limits<typename X::value_type>::infinity();}
else
{low1 = x.get(counters[0]);}
T low2 = get_low<T>(&counters[1],xy ...);
return (low1 < low2)?low1:low2;
}
if (counters[0] >= x.size())
{return std::numeric_limits<typename X::value_type>::infinity();}
return x.get(counters[0]);
}
/*! \brief Recursively sort variadic template of vectors
*
* \param counters indexes
*
*/
template<typename T>
T get_low(size_t * counters)
{
return 0.0;
}
/*! \brief Recursively sort variadic template of vectors
*
* \param x vector with x
* \param y vector with y
* \param xy all the other 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)
{
if (low == x.get(counters[0]))
{
point[0] = y.get(counters[0]);
counters[0]++;
}
else
{
point[0] = std::numeric_limits<typename X::value_type>::quiet_NaN();
}
get_point(low,&point[1],&counters[1],xy...);
}
/*! \brief Recursively sort variadic template of vectors
*
* \param x vector with x
* \param y vector with y
* \param xy all the other vectors
*
*/
template<typename T>
void get_point(T low,
T * point,
size_t * counters)
{
return;
}
/*! \brief Recursively sort variadic template of vectors
*
* \param x vector with x
* \param y vector with y
* \param xy all the other 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)
{
// if exist the next element
if (isNext(counters,xy...) == false)
{return false;}
// get lowest x
typename get_value_type<Xs...>::type low = get_low<typename get_value_type<Xs...>::type>(counters,xy...);
x = low;
get_point(low,point,counters,xy...);
return true;
}
/*! \brief Given X and Y vector return the string representing the data section of the Google Chart
*
* \tparam X type for the X coordinates
......@@ -215,7 +444,7 @@ class GoogleChart
// we require that the number of x elements are the same as y elements
if (x.size() != y.size())
std::cerr << "Error: " << __FILE__ << ":" << __LINE__ << " vector x and the vector y must have the same number of elements " << x.size() << "!=" << y.size() << "\n";
{std::cerr << "Error: " << __FILE__ << ":" << __LINE__ << " vector x and the vector y must have the same number of elements " << x.size() << "!=" << y.size() << "\n";}
// Google chart visualization
data << "var data" << i << " = new google.visualization.DataTable();\n";
......@@ -250,7 +479,17 @@ class GoogleChart
data << "[" << x.get(i);
}
else
data << "," << y.get(i).get(j-1);
{
if (check_nan<typename Y::value_type>::check(y.get(i).get(j-1)) == false)
{
data << "," << y.get(i).get(j-1);
}
else
{
holes = true;
data << "," << "null";
}
}
}
data << "],\n";
}
......@@ -351,6 +590,8 @@ class GoogleChart
of << "var options";
of << i;
of << "= {\n";
if (holes == true)
{of << "interpolateNulls : true,\n";}
of << opt;
of << "};\n";
}
......@@ -513,16 +754,69 @@ public:
set_of_graphs.last().opt = opt;
}
/*! \brief Add lines graph
*
* \param y A vector of vectors of values. each vector is a graph of points
* \param xy list 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)
*
* \param x Give a name or number to each x value, so can be a string or a number
* \param opt Graph options
*
*/
template<typename ... X> void AddLines(const openfpm::vector<std::string> & yn,
const GCoptions & opt,
X ... xy)
{
// first we sort the vectors
recursive_sort(xy ... );
size_t counters[sizeof...(X)];
memset(&counters,0,sizeof(counters));
typename get_value_type<X...>::type point[sizeof...(X)];
typename get_value_type<X...>::type xe;
openfpm::vector<typename get_value_type<X...>::type> x;
openfpm::vector<openfpm::vector<typename get_value_type<X...>::type>> y;
while (get_v(xe,point,counters,xy...))
{
y.add();
x.add(xe);
for (size_t i = 0 ; i < sizeof...(X)/2 ; i++)
{
y.last().add(point[i]);
}
}
AddLinesGraph(x,y,yn,opt);
}
/*! \brief 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
*
* \verbatim
------ 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 |
\endverbatim
*
* \param y A vector of vectors of values. each vector contain the graph points, compared to AddLinesGraph the points are stored
*
*
* \param x axis values
*
* \param opt Graph options
*
*/
template<typename X, typename Y> void AddLines(openfpm::vector<X> & x, openfpm::vector<Y> & y , const GCoptions & opt)
template<typename X, typename Y> void AddLinesGraphT(openfpm::vector<X> & x, openfpm::vector<Y> & y , const GCoptions & opt)
{
openfpm::vector<std::string> yn;
......@@ -568,6 +862,18 @@ public:
/*! \brief 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
*
* \verbatim
-- 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
\endverbatim
*
* \param y A 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
......
......@@ -387,6 +387,126 @@ BOOST_AUTO_TEST_CASE( google_chart_with_inject_HTML )
BOOST_REQUIRE_EQUAL(true,test);
}
BOOST_AUTO_TEST_CASE( google_chart_number )
{
Vcluster<> & v_cl = create_vcluster();
if (v_cl.getProcessUnitID() != 0)
return;
//! [Producing a set of histograms graphs]
openfpm::vector<float> x;
openfpm::vector<openfpm::vector<size_t>> y;
openfpm::vector<std::string> yn;
x.add(0.1);
x.add(0.2);
x.add(0.3);
x.add(0.4);
x.add(0.5);
x.add(0.6);
// 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("line");
GoogleChart cg;
//
cg.AddLinesGraph(x,y,yn,options);
cg.write("gc_num_plot.html");
//! [Producing a set of histograms graphs]
bool test = compare("gc_num_plot.html","gc_num_plot_test.html");
BOOST_REQUIRE_EQUAL(true,test);
}
BOOST_AUTO_TEST_CASE( google_chart_number_lines_different_x )
{
Vcluster<> & v_cl = create_vcluster();
if (v_cl.getProcessUnitID() != 0)
return;
//! [Producing a set of histograms graphs]
openfpm::vector<float> x1;
openfpm::vector<float> y1;
openfpm::vector<float> x2;
openfpm::vector<float> y2;
openfpm::vector<float> x3;
openfpm::vector<float> y3;
openfpm::vector<std::string> yn;
x1.add(0.1); y1.add(4.5);
x1.add(0.2); y1.add(3.0);
x1.add(0.3); y1.add(5.5);
x1.add(0.4); y1.add(3.3);
x1.add(0.5); y1.add(1.0);
x1.add(0.6); y1.add(7.0);
x2.add(0.15); y2.add(1.5);
x2.add(0.2); y2.add(4.5);
x2.add(0.35); y2.add(2.5);
x2.add(0.45); y2.add(6.5);
x3.add(0.1); y3.add(3.5);
x3.add(0.2); y3.add(6.5);
x3.add(0.63); y3.add(1.5);
x3.add(0.37); y3.add(1.5);
x3.add(0.7); y3.add(3.5);
x3.add(0.82); y3.add(2.5);
x3.add(0.4); y3.add(2.5);
x3.add(1.0); y3.add(1.5);
x3.add(0.5); y3.add(7.5);
x3.add(0.91); y3.add(5.5);
// 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");
// 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("line");
GoogleChart cg;
cg.AddLines(yn,options,x1,y1,x2,y2,x3,y3);
cg.write("gc_num_ydif_plot.html");
//! [Producing a set of histograms graphs]
bool test = compare("gc_num_ydif_plot.html","gc_num_ydif_plot_test.html");
BOOST_REQUIRE_EQUAL(true,test);
}
BOOST_AUTO_TEST_CASE( google_chart_linear_plot )
{
Vcluster<> & v_cl = create_vcluster();
......
......@@ -24,27 +24,27 @@
template <typename T> std::string getType()
{
// Create a property string based on the type of the property
if (typeid(T) == typeid(float))
if (std::is_same<T,float>::value)
return "float";
else if (typeid(T) == typeid(double))
else if (std::is_same<T,double>::value)
return "double";
else if (typeid(T) == typeid(char))
else if (std::is_same<T,char>::value)
return "char";
else if (typeid(T) == typeid(unsigned char))
else if (std::is_same<T,unsigned char>::value)
return "unsigned_char";
else if (typeid(T) == typeid(short))
else if (std::is_same<T,short>::value)
return "short";
else if (typeid(T) == typeid(unsigned short))
else if (std::is_same<T,unsigned short>::value)
return "unsigned_short";
else if (typeid(T) == typeid(int))
else if (std::is_same<T,int>::value)
return "int";
else if (typeid(T) == typeid(unsigned int))
else if (std::is_same<T,unsigned int>::value)
return "unsigned_int";
else if (typeid(T) == typeid(long int))
else if (std::is_same<T,long int>::value)
return "int";
else if (typeid(T) == typeid(unsigned long int))
else if (std::is_same<T,unsigned long int>::value )
return "unsigned_int";
else if (typeid(T) == typeid(bool))
else if (std::is_same<T,bool>::value )
return "bit";
return "";
......@@ -103,6 +103,7 @@ enum file_type
#define VTK_WRITER 0x10000
#define FORMAT_ASCII 0x0
#define FORMAT_BINARY 0x10000000
#define PRINT_GHOST 1
template <typename Object, unsigned int imp>
class VTKWriter
......@@ -121,7 +122,6 @@ class VTKWriter
#include "VTKWriter_dist_graph.hpp"
#endif
#include "VTKWriter_point_set.hpp"
#endif /* VTKWRITER_HPP_ */
......@@ -65,14 +65,13 @@ struct vtk_vertex_node_array_scalar_selector<true>
static inline void move(typename G::V_container &vo, s_type (&x)[3], bool &z_set)
{
if (G::V_type::attributes::name[T::value] != "x")
return;
{return;}
if (std::extent<ele_v>::value == 3)
z_set = true;
{z_set = true;}
for (size_t i = 0; i < std::extent<ele_v>::value; i++)
x[i] = convert<typename boost::remove_reference<decltype(vo.template get<T::value>()[i])>::type>::template to<s_type>(vo.template get<T::value>()[i]);
{x[i] = convert<typename boost::remove_reference<decltype(vo.template get<T::value>()[i])>::type>::template to<s_type>(vo.template get<T::value>()[i]);}
}
};
......
......@@ -117,10 +117,36 @@ struct prop_out_g
// if there is the next element
while (it.isNext())
{
if (vg.get(k).dom.isInside(it.get().toPoint()) == true)
v_out += "1.0\n";
if (ft == file_type::ASCII)
{
if (vg.get(k).dom.isInside(it.get().toPoint()) == true)
{
float flag = 1.0;
flag += vg.get(k).g.getFlag(it.get()) * 2;
v_out += std::to_string(flag) + "\n";
}
else
{
float flag = 0.0;
flag += vg.get(k).g.getFlag(it.get()) * 2;
v_out += std::to_string(flag) + "\n";
}
}
else
v_out += "0.0\n";
{
if (vg.get(k).dom.isInside(it.get().toPoint()) == true)
{
float flag = 1.0;
flag = swap_endian_lt(flag);
v_out.append((const char *)&flag,sizeof(flag));
}
else
{
float flag = 0.0;
flag = swap_endian_lt(flag);
v_out.append((const char *)&flag,sizeof(flag));
}
}
// increment the iterator and counter
++it;
......@@ -142,8 +168,8 @@ template <typename pair>
class VTKWriter<pair,VECTOR_GRIDS>
{
//! Vector of grids
openfpm::vector< ele_g<typename pair::first,typename pair::second> > vg;
openfpm::vector< ele_g<typename pair::first,typename pair::second> > vg;
/*! \brief Get the total number of points
*
* \return the total number
......@@ -380,9 +406,9 @@ public:
prop_out_g< ele_g<typename pair::first,typename pair::second>, typename pair::second > pp(point_data, vg, prop_names, ft);
if (prp == -1)
boost::mpl::for_each< boost::mpl::range_c<int,0, pair::first::value_type::max_prop> >(pp);
{boost::mpl::for_each< boost::mpl::range_c<int,0, pair::first::value_type::max_prop> >(pp);}
else
boost::mpl::for_each< boost::mpl::range_c<int,prp, prp> >(pp);
{boost::mpl::for_each< boost::mpl::range_c<int,prp, prp> >(pp);}
// Add the last property
pp.lastProp();
......
......@@ -371,7 +371,9 @@ class VTKWriter<pair,VECTOR_ST_GRIDS>
// if the type is not supported return
if (type.size() == 0)
{
#ifndef DISABLE_ALL_RTTI
std::cerr << "Error " << __FILE__ << ":" << __LINE__ << " the type " << demangle(typeid(ctype).name()) << " is not supported by vtk\n";
#endif
return "";
}
......
......@@ -89,7 +89,9 @@ template<unsigned int i, typename ele_g, bool has_attributes> std::string get_po
// if the type is not supported skip-it
if (type.size() == 0)
{
#ifndef DISABLE_ALL_RTTI
std::cerr << "Error " << __FILE__ << ":" << __LINE__ << " the type " << demangle(typeid(ctype).name()) << " is not supported by vtk\n";
#endif
return "";
}
......@@ -200,17 +202,17 @@ public:
*/
template<typename vector, typename iterator, typename I> static void write(std::string & v_out, vector & vg, size_t k, iterator & it, file_type ft)
{
typedef decltype(vg.get(k).g.get_o(it.get()).template get<I::value>()) ctype_;
typedef typename std::remove_reference<ctype_>::type ctype;
typedef decltype(vg.get(k).g.template get<I::value>(it.get())) ctype_;
typedef typename std::remove_const<typename std::remove_reference<ctype_>::type>::type ctype;
if (ft == file_type::ASCII)
{
// Print the property
v_out += std::to_string(vg.get(k).g.get_o(it.get()).template get<I::value>()) + "\n";
v_out += std::to_string(vg.get(k).g.template get<I::value>(it.get())) + "\n";
}
else
{
typename is_vtk_writable<ctype>::base tmp = vg.get(k).g.get_o(it.get()).template get<I::value>();
typename is_vtk_writable<ctype>::base tmp = vg.get(k).g.template get<I::value>(it.get());
tmp = swap_endian_lt(tmp);
v_out.append((const char *)&tmp,sizeof(tmp));
}
......@@ -309,10 +311,10 @@ struct meta_prop<I, ele_g,St,T[N1],is_writable>
{
// Print the properties
for (size_t i1 = 0 ; i1 < N1 ; i1++)
{v_out += std::to_string(vg.get(k).g.get_o(it.get()).template get<I::value>()[i1]) + " ";}
{v_out += std::to_string(vg.get(k).g.template get<I::value>(it.get())[i1]) + " ";}
if (N1 == 2)
{v_out += "0.0";}
{v_out += std::to_string((decltype(vg.get(k).g.template get<I::value>(it.get())[0])) 0);}
v_out += "\n";
}
......@@ -323,7 +325,7 @@ struct meta_prop<I, ele_g,St,T[N1],is_writable>
// Print the properties
for (size_t i1 = 0 ; i1 < N1 ; i1++)
{
tmp = vg.get(k).g.get_o(it.get()).template get<I::value>()[i1];
tmp = vg.get(k).g.template get<I::value>(it.get())[i1];
tmp = swap_endian_lt(tmp);
v_out.append((const char *)&tmp,sizeof(T));
}
......@@ -388,11 +390,11 @@ struct meta_prop<I, ele_g,St, T[N1][N2],is_writable>
if (ft == file_type::ASCII)
{
// Print the property
v_out += std::to_string(vg.get(k).g.get_o(it.get()).template get<I::value>()[i1][i2]) + "\n";
v_out += std::to_string(vg.get(k).g.template get<I::value>(it.get())[i1][i2]) + "\n";
}
else
{
tmp = vg.get(k).g.get_o(it.get()).template get<I::value>()[i1][i2];
tmp = vg.get(k).g.template get<I::value>(it.get())[i1][i2];
tmp = swap_endian_lt(tmp);
v_out.append((const char *)&tmp,sizeof(tmp));
}
......
......@@ -45,6 +45,10 @@ struct GBoxes
//! origin of GDbox in global grid coordinates
Point<dim,long int> origin;
//! In case the grid is not defined everywhere but is defined by a set of boxes
//! indicate from which box it come from
size_t k;
/*! \brief Indicate that this structure has no pointers inside
*
* \return true
......