1 #include <framework/utilities/HTML.h>
3 #include <boost/algorithm/string/replace.hpp>
6 #include <TMatrixFBase.h>
10 #include <framework/gearbox/Unit.h>
16 using namespace boost::algorithm;
18 std::string
HTML::getString(
const TMatrixFBase& matrix,
int precision,
bool color)
20 const int nr = matrix.GetNrows();
21 const int nc = matrix.GetNcols();
23 TMatrixD matrix_double(nr, nc);
24 for (
int ir = 0; ir < nr; ir++)
25 for (
int ic = 0; ic < nc; ic++)
26 matrix_double(ir, ic) = matrix(ir, ic);
27 return getString(matrix_double, precision, color);
30 std::string
HTML::getString(
const TMatrixDBase& matrix,
int precision,
bool color)
32 std::stringstream stream;
33 stream.precision(precision);
35 stream <<
"<table padding=0>";
36 const double max = matrix.Max();
37 const double min = matrix.Min();
38 for (
int i = 0; i < matrix.GetNrows(); i++) {
40 for (
int k = 0; k < matrix.GetNcols(); k++) {
41 const double value = matrix(i, k);
42 stream <<
"<td align=right";
43 if (color and value != 0.0) {
49 b = g = 255 - 180 * value / ((value > 0) ? max : min);
51 r = 255 - 200 * value / ((value > 0) ? max : min);
53 stream <<
" bgcolor=" << std::setfill(
'0') << std::hex;
54 stream << std::setw(2) << r;
55 stream << std::setw(2) << g;
56 stream << std::setw(2) << b;
57 stream << std::dec << std::setfill(
' ');
59 stream <<
">" << std::setw(11) << value;
72 std::stringstream stream;
73 stream.precision(precision);
75 stream << std::fixed <<
"(" << vec.x() <<
", " << vec.y() <<
", " << vec.z() <<
")";
81 std::stringstream stream;
82 stream.precision(precision);
83 std::string displayedUnitType = unitType;
86 displayedUnitType =
"\x0b5m";
91 <<
") " << displayedUnitType;
103 for (
auto entry : xyz)
104 if (std::abs(entry) > max)
105 max = std::abs(entry);
117 std::stringstream stream;
118 stream <<
"<small><tt>";
121 for (
int i = 0; i < length; i++) {
124 snprintf(str,
sizeof(str),
"%08x ", buf[i]);
127 stream <<
"</tt></small>";
134 std::string tmp = html;
136 replace_all(tmp,
"<br>",
"\n");
137 replace_all(tmp,
"</p>",
"\n");
138 replace_all(tmp,
"</tr>",
"\n");
139 replace_all(tmp,
" ",
" ");
142 replace_all(tmp,
"\x0b5",
"u");
145 const static std::regex tagRegex(
"<.*?>");
146 tmp = std::regex_replace(tmp, tagRegex,
"");
155 std::string tmp = str;
156 replace_all(tmp,
"&",
"&");
157 replace_all(tmp,
">",
">");
158 replace_all(tmp,
"<",
"<");
159 replace_all(tmp,
"\"",
""");
165 std::string tmp = str;
167 replace_all(tmp,
""",
"\"");
168 replace_all(tmp,
">",
">");
169 replace_all(tmp,
"<",
"<");
170 replace_all(tmp,
"&",
"&");