Skip to content

Commit f8073f3

Browse files
authored
Merge pull request #15 from ByteHamster-etc/feature-attr
Rebased: latex: Add support for "|attr" to compute addplot attributes in SQL
2 parents b352a32 + 0713661 commit f8073f3

5 files changed

Lines changed: 122 additions & 15 deletions

File tree

src/latex.cpp

Lines changed: 80 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -203,21 +203,50 @@ void SpLatex::multiplot(size_t ln, size_t indent, const std::string& cmdline)
203203
std::vector<std::string> groupfields = split(multiplot, ',');
204204
std::for_each(groupfields.begin(), groupfields.end(), trim_inplace_ws);
205205

206+
bool attr_mark = false;
207+
bool attrplus_mark = false;
206208
bool title_mark = false;
207209
bool ptitle_mark = false;
210+
bool nolegend_mark = false;
208211
bool xerr = false, yerr = false;
209212

210-
if (!groupfields.empty() && is_suffix(groupfields.back(), "|title")) {
211-
// remove |title from multiplot string
212-
groupfields.back().resize(groupfields.back().size() - 6);
213-
multiplot.resize(multiplot.size() - 6);
214-
title_mark = true;
215-
}
216-
else if (!groupfields.empty() && is_suffix(groupfields.back(), "|ptitle")) {
217-
// remove |ptitle from multiplot string
218-
groupfields.back().resize(groupfields.back().size() - 7);
219-
multiplot.resize(multiplot.size() - 7);
220-
ptitle_mark = true;
213+
while (!groupfields.empty() && groupfields.back().find('|') != std::string::npos) {
214+
std::string& field = groupfields.back();
215+
if (!groupfields.empty() && is_suffix(field, "|title")) {
216+
// remove |title from multiplot string
217+
field.resize(field.size() - 6);
218+
multiplot.resize(multiplot.size() - 6);
219+
title_mark = true;
220+
}
221+
else if (!groupfields.empty() && is_suffix(field, "|ptitle")) {
222+
// remove |ptitle from multiplot string
223+
field.resize(field.size() - 7);
224+
multiplot.resize(multiplot.size() - 7);
225+
ptitle_mark = true;
226+
}
227+
else if (!groupfields.empty() && is_suffix(field, "|nolegend")) {
228+
// remove |nolegend from multiplot string
229+
field.resize(field.size() - 9);
230+
multiplot.resize(multiplot.size() - 9);
231+
nolegend_mark = true;
232+
}
233+
else if (!groupfields.empty() && is_suffix(field, "|attr")) {
234+
// remove |attr from multiplot string
235+
field.resize(field.size() - 5);
236+
multiplot.resize(multiplot.size() - 5);
237+
attr_mark = true;
238+
}
239+
else if (!groupfields.empty() && is_suffix(field, "|attrplus")) {
240+
// remove |attrplus from multiplot string
241+
field.resize(field.size() - 9);
242+
multiplot.resize(multiplot.size() - 9);
243+
attr_mark = true;
244+
attrplus_mark = true;
245+
}
246+
else {
247+
std::string modifier = field.substr(field.find('|'));
248+
OUT_THROW("MULTIPLOT failed: unknown modifier '" + modifier + "'");
249+
}
221250
}
222251

223252
// execute query
@@ -246,6 +275,9 @@ void SpLatex::multiplot(size_t ln, size_t indent, const std::string& cmdline)
246275
if (ptitle_mark && !sql->exist_col("ptitle"))
247276
OUT_THROW("MULTIPLOT failed: ptitle mark set but result contains no 'ptitle' column.");
248277

278+
if (attr_mark && !sql->exist_col("attr"))
279+
OUT_THROW("MULTIPLOT failed: attr mark set but result contains no 'attr' column.");
280+
249281
unsigned int col_x = sql->find_col("x"), col_y = sql->find_col("y"),
250282
col_xerr = xerr ? sql->find_col("xerr") : -1,
251283
col_yerr = yerr ? sql->find_col("yerr") : -1;
@@ -255,6 +287,9 @@ void SpLatex::multiplot(size_t ln, size_t indent, const std::string& cmdline)
255287
col_title = sql->find_col("title");
256288
if (ptitle_mark)
257289
col_title = sql->find_col("ptitle");
290+
unsigned int col_attr = 0;
291+
if (attr_mark)
292+
col_attr = sql->find_col("attr");
258293

259294
// check existance of group fields and save ids
260295
std::vector<int> groupcols;
@@ -272,6 +307,7 @@ void SpLatex::multiplot(size_t ln, size_t indent, const std::string& cmdline)
272307
// collect coordinates {...} clause groups
273308
std::vector<std::string> coordlist;
274309
std::vector<std::string> legendlist;
310+
std::vector<std::string> attrlist;
275311

276312
{
277313
std::vector<std::string> lastgroup;
@@ -322,6 +358,10 @@ void SpLatex::multiplot(size_t ln, size_t indent, const std::string& cmdline)
322358
}
323359
legendlist.push_back(os.str());
324360
}
361+
362+
if (attr_mark) {
363+
attrlist.push_back(sql->text(col_attr));
364+
}
325365
}
326366

327367
// group fields match with last row -> append coordinates.
@@ -344,6 +384,8 @@ void SpLatex::multiplot(size_t ln, size_t indent, const std::string& cmdline)
344384

345385
for (size_t i = 0; i < coordlist.size(); ++i)
346386
{
387+
if (attr_mark)
388+
OUTC(gopt_verbose >= 1, "attr {" << attrlist[i] << " }");
347389
OUTC(gopt_verbose >= 1, "coordinates {" << coordlist[i] << " }");
348390
OUTC(gopt_verbose >= 1, "legend {" << legendlist[i] << " }");
349391
}
@@ -356,7 +398,7 @@ void SpLatex::multiplot(size_t ln, size_t indent, const std::string& cmdline)
356398
static const boost::regex
357399
re_addplot("[[:blank:]]*(\\\\addplot.*coordinates \\{)[^}]+(\\};.*)");
358400
static const boost::regex
359-
re_legend("[[:blank:]]*(\\\\addlegendentry\\{).*(\\};.*)");
401+
re_legend("[[:blank:]]*((?:%[[:blank:]]*)?\\\\addlegendentry\\{).*(\\};.*)");
360402

361403
boost::smatch rm;
362404

@@ -367,7 +409,16 @@ void SpLatex::multiplot(size_t ln, size_t indent, const std::string& cmdline)
367409
// copy styles from \addplot line
368410
if (entry < coordlist.size())
369411
{
370-
out << rm[1] << coordlist[entry] << " " << rm[2] << std::endl;
412+
if (attr_mark) {
413+
// can't copy styles when an attribute is being selected
414+
out << "\\addplot";
415+
if (attrplus_mark)
416+
out << "+";
417+
out << "[" << attrlist[entry] << "] coordinates {"
418+
<< coordlist[entry] << " " << rm[2] << std::endl;
419+
} else {
420+
out << rm[1] << coordlist[entry] << " " << rm[2] << std::endl;
421+
}
371422

372423
// check following \addlegendentry
373424
if (eln+1 < m_lines.size() &&
@@ -379,6 +430,9 @@ void SpLatex::multiplot(size_t ln, size_t indent, const std::string& cmdline)
379430
}
380431
else
381432
{
433+
// If |nolegend is set, comment out legend entries
434+
if (nolegend_mark)
435+
out << "% ";
382436
// add missing \addlegendentry
383437
out << "\\addlegendentry{" << legendlist[entry]
384438
<< "};" << std::endl;
@@ -403,9 +457,20 @@ void SpLatex::multiplot(size_t ln, size_t indent, const std::string& cmdline)
403457
// append missing \addplot / \addlegendentry pairs
404458
while (entry < coordlist.size())
405459
{
406-
out << "\\addplot coordinates {" << coordlist[entry]
407-
<< " };" << std::endl;
460+
if (attr_mark) {
461+
out << "\\addplot";
462+
if (attrplus_mark)
463+
out << "+";
464+
out << "[" << attrlist[entry] << "] coordinates {"
465+
<< coordlist[entry] << " };" << std::endl;
466+
} else {
467+
out << "\\addplot coordinates {" << coordlist[entry]
468+
<< " };" << std::endl;
469+
}
408470

471+
// If |nolegend is set, comment out legend entries
472+
if (nolegend_mark)
473+
out << "% ";
409474
out << "\\addlegendentry{" << legendlist[entry]
410475
<< "};" << std::endl;
411476

tests/latex/attr.out

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
line1
2+
% IMPORT-DATA test test.data
3+
line2
4+
%% MULTIPLOT(funcname|attr) SELECT LOG(testsize) / LOG(2) AS x, bandwidth AS y, funcname AS attr, MULTIPLOT
5+
%% FROM test WHERE host='earth' ORDER BY MULTIPLOT,x
6+
\addplot[ScanRead64PtrUnrollLoop] coordinates { (10.1699,2.12566e+10) (11.0875,2.12068e+10) (11.6439,2.12568e+10) (12.0444,2.12565e+10) (12.6147,2.12549e+10) (13.0224,2.10335e+10) (13.5999,2.11052e+10) (14.0112,2.11423e+10) (14.3309,2.11649e+10) (14.5925,2.1178e+10) (14.8138,2.11881e+10) (15.0056,2.01671e+10) (15.3264,1.54346e+10) (15.5887,1.54457e+10) (16.0028,1.54706e+10) (16.5868,1.54763e+10) (17.0014,1.54782e+10) (17.5859,1.54527e+10) (18.0007,1.54039e+10) (18.5854,1.54242e+10) (19.0004,1.5424e+10) (19.5852,1.54265e+10) (20.0002,1.54166e+10) (20.3221,1.52702e+10) (20.5851,1.52696e+10) (20.8075,1.52691e+10) (21.0001,1.43805e+10) (21.17,1.43101e+10) (21.322,1.36672e+10) (21.4595,1.18576e+10) (21.585,1.09755e+10) (22,7.46265e+09) (22.322,5.23999e+09) (22.585,4.38139e+09) (22.8074,4.03316e+09) (23,3.84756e+09) (23.1699,3.74337e+09) (23.3219,3.66671e+09) (23.585,3.58156e+09) (23.8074,3.54338e+09) (24,3.52208e+09) (24.3219,3.50742e+09) (24.585,3.50313e+09) (24.8074,3.50257e+09) (25,3.50191e+09) (26,3.50248e+09) (27,3.50222e+09) (28,3.50208e+09) (29,3.50212e+09) (30,3.50154e+09) (31,3.50165e+09) (32,3.50154e+09) (33,3.50111e+09) (34,3.50009e+09) };
7+
\addlegendentry{funcname=ScanRead64PtrUnrollLoop};
8+
\addplot[ScanWrite64PtrUnrollLoop] coordinates { (10.1699,2.00049e+10) (11.0875,2.00592e+10) (11.6439,2.01016e+10) (12.0444,2.00787e+10) (12.6147,2.01033e+10) (13.0224,1.98443e+10) (13.5999,1.99341e+10) (14.0112,1.99704e+10) (14.3309,1.99977e+10) (14.5925,2.00171e+10) (14.8138,2.00244e+10) (15.0056,1.95887e+10) (15.3264,1.33525e+10) (15.5887,1.33527e+10) (16.0028,1.33532e+10) (16.5868,1.33536e+10) (17.0014,1.33535e+10) (17.5859,1.33537e+10) (18.0007,1.33538e+10) (18.5854,1.33544e+10) (19.0004,1.33554e+10) (19.5852,1.33571e+10) (20.0002,1.33223e+10) (20.3221,1.25999e+10) (20.5851,1.25974e+10) (20.8075,1.25935e+10) (21.0001,1.18143e+10) (21.17,1.17322e+10) (21.322,1.11514e+10) (21.4595,9.63556e+09) (21.585,8.83049e+09) (22,5.70303e+09) (22.322,3.76486e+09) (22.585,2.97082e+09) (22.8074,2.62547e+09) (23,2.44873e+09) (23.1699,2.35262e+09) (23.3219,2.28865e+09) (23.585,2.22295e+09) (23.8074,2.19541e+09) (24,2.1806e+09) (24.3219,2.1704e+09) (24.585,2.16835e+09) (24.8074,2.16741e+09) (25,2.16724e+09) (26,2.16707e+09) (27,2.1674e+09) (28,2.16717e+09) (29,2.16721e+09) (30,2.16729e+09) (31,2.16717e+09) (32,2.16733e+09) (33,2.16723e+09) (34,2.1669e+09) };
9+
\addlegendentry{funcname=ScanWrite64PtrUnrollLoop};
10+
line3
11+
%% MULTIPLOT(funcname|attrplus) SELECT LOG(testsize) / LOG(2) AS x, bandwidth AS y, funcname AS attr, MULTIPLOT
12+
%% FROM test WHERE host='earth' ORDER BY MULTIPLOT,x
13+
\addplot+[ScanRead64PtrUnrollLoop] coordinates { (10.1699,2.12566e+10) (11.0875,2.12068e+10) (11.6439,2.12568e+10) (12.0444,2.12565e+10) (12.6147,2.12549e+10) (13.0224,2.10335e+10) (13.5999,2.11052e+10) (14.0112,2.11423e+10) (14.3309,2.11649e+10) (14.5925,2.1178e+10) (14.8138,2.11881e+10) (15.0056,2.01671e+10) (15.3264,1.54346e+10) (15.5887,1.54457e+10) (16.0028,1.54706e+10) (16.5868,1.54763e+10) (17.0014,1.54782e+10) (17.5859,1.54527e+10) (18.0007,1.54039e+10) (18.5854,1.54242e+10) (19.0004,1.5424e+10) (19.5852,1.54265e+10) (20.0002,1.54166e+10) (20.3221,1.52702e+10) (20.5851,1.52696e+10) (20.8075,1.52691e+10) (21.0001,1.43805e+10) (21.17,1.43101e+10) (21.322,1.36672e+10) (21.4595,1.18576e+10) (21.585,1.09755e+10) (22,7.46265e+09) (22.322,5.23999e+09) (22.585,4.38139e+09) (22.8074,4.03316e+09) (23,3.84756e+09) (23.1699,3.74337e+09) (23.3219,3.66671e+09) (23.585,3.58156e+09) (23.8074,3.54338e+09) (24,3.52208e+09) (24.3219,3.50742e+09) (24.585,3.50313e+09) (24.8074,3.50257e+09) (25,3.50191e+09) (26,3.50248e+09) (27,3.50222e+09) (28,3.50208e+09) (29,3.50212e+09) (30,3.50154e+09) (31,3.50165e+09) (32,3.50154e+09) (33,3.50111e+09) (34,3.50009e+09) };
14+
\addlegendentry{funcname=ScanRead64PtrUnrollLoop};
15+
\addplot+[ScanWrite64PtrUnrollLoop] coordinates { (10.1699,2.00049e+10) (11.0875,2.00592e+10) (11.6439,2.01016e+10) (12.0444,2.00787e+10) (12.6147,2.01033e+10) (13.0224,1.98443e+10) (13.5999,1.99341e+10) (14.0112,1.99704e+10) (14.3309,1.99977e+10) (14.5925,2.00171e+10) (14.8138,2.00244e+10) (15.0056,1.95887e+10) (15.3264,1.33525e+10) (15.5887,1.33527e+10) (16.0028,1.33532e+10) (16.5868,1.33536e+10) (17.0014,1.33535e+10) (17.5859,1.33537e+10) (18.0007,1.33538e+10) (18.5854,1.33544e+10) (19.0004,1.33554e+10) (19.5852,1.33571e+10) (20.0002,1.33223e+10) (20.3221,1.25999e+10) (20.5851,1.25974e+10) (20.8075,1.25935e+10) (21.0001,1.18143e+10) (21.17,1.17322e+10) (21.322,1.11514e+10) (21.4595,9.63556e+09) (21.585,8.83049e+09) (22,5.70303e+09) (22.322,3.76486e+09) (22.585,2.97082e+09) (22.8074,2.62547e+09) (23,2.44873e+09) (23.1699,2.35262e+09) (23.3219,2.28865e+09) (23.585,2.22295e+09) (23.8074,2.19541e+09) (24,2.1806e+09) (24.3219,2.1704e+09) (24.585,2.16835e+09) (24.8074,2.16741e+09) (25,2.16724e+09) (26,2.16707e+09) (27,2.1674e+09) (28,2.16717e+09) (29,2.16721e+09) (30,2.16729e+09) (31,2.16717e+09) (32,2.16733e+09) (33,2.16723e+09) (34,2.1669e+09) };
16+
\addlegendentry{funcname=ScanWrite64PtrUnrollLoop};
17+
this is the end

tests/latex/attr.tex

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
line1
2+
% IMPORT-DATA test test.data
3+
line2
4+
%% MULTIPLOT(funcname|attr) SELECT LOG(testsize) / LOG(2) AS x, bandwidth AS y, funcname AS attr, MULTIPLOT
5+
%% FROM test WHERE host='earth' ORDER BY MULTIPLOT,x
6+
line3
7+
%% MULTIPLOT(funcname|attrplus) SELECT LOG(testsize) / LOG(2) AS x, bandwidth AS y, funcname AS attr, MULTIPLOT
8+
%% FROM test WHERE host='earth' ORDER BY MULTIPLOT,x
9+
this is the end

tests/latex/nolegend.out

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
line1
2+
% IMPORT-DATA test test.data
3+
line2
4+
%% MULTIPLOT(funcname|nolegend) SELECT LOG(testsize) / LOG(2) AS x, bandwidth AS y, MULTIPLOT
5+
%% FROM test WHERE host='earth' ORDER BY MULTIPLOT,x
6+
\addplot coordinates { (10.1699,2.12566e+10) (11.0875,2.12068e+10) (11.6439,2.12568e+10) (12.0444,2.12565e+10) (12.6147,2.12549e+10) (13.0224,2.10335e+10) (13.5999,2.11052e+10) (14.0112,2.11423e+10) (14.3309,2.11649e+10) (14.5925,2.1178e+10) (14.8138,2.11881e+10) (15.0056,2.01671e+10) (15.3264,1.54346e+10) (15.5887,1.54457e+10) (16.0028,1.54706e+10) (16.5868,1.54763e+10) (17.0014,1.54782e+10) (17.5859,1.54527e+10) (18.0007,1.54039e+10) (18.5854,1.54242e+10) (19.0004,1.5424e+10) (19.5852,1.54265e+10) (20.0002,1.54166e+10) (20.3221,1.52702e+10) (20.5851,1.52696e+10) (20.8075,1.52691e+10) (21.0001,1.43805e+10) (21.17,1.43101e+10) (21.322,1.36672e+10) (21.4595,1.18576e+10) (21.585,1.09755e+10) (22,7.46265e+09) (22.322,5.23999e+09) (22.585,4.38139e+09) (22.8074,4.03316e+09) (23,3.84756e+09) (23.1699,3.74337e+09) (23.3219,3.66671e+09) (23.585,3.58156e+09) (23.8074,3.54338e+09) (24,3.52208e+09) (24.3219,3.50742e+09) (24.585,3.50313e+09) (24.8074,3.50257e+09) (25,3.50191e+09) (26,3.50248e+09) (27,3.50222e+09) (28,3.50208e+09) (29,3.50212e+09) (30,3.50154e+09) (31,3.50165e+09) (32,3.50154e+09) (33,3.50111e+09) (34,3.50009e+09) };
7+
% \addlegendentry{funcname=ScanRead64PtrUnrollLoop};
8+
\addplot coordinates { (10.1699,2.00049e+10) (11.0875,2.00592e+10) (11.6439,2.01016e+10) (12.0444,2.00787e+10) (12.6147,2.01033e+10) (13.0224,1.98443e+10) (13.5999,1.99341e+10) (14.0112,1.99704e+10) (14.3309,1.99977e+10) (14.5925,2.00171e+10) (14.8138,2.00244e+10) (15.0056,1.95887e+10) (15.3264,1.33525e+10) (15.5887,1.33527e+10) (16.0028,1.33532e+10) (16.5868,1.33536e+10) (17.0014,1.33535e+10) (17.5859,1.33537e+10) (18.0007,1.33538e+10) (18.5854,1.33544e+10) (19.0004,1.33554e+10) (19.5852,1.33571e+10) (20.0002,1.33223e+10) (20.3221,1.25999e+10) (20.5851,1.25974e+10) (20.8075,1.25935e+10) (21.0001,1.18143e+10) (21.17,1.17322e+10) (21.322,1.11514e+10) (21.4595,9.63556e+09) (21.585,8.83049e+09) (22,5.70303e+09) (22.322,3.76486e+09) (22.585,2.97082e+09) (22.8074,2.62547e+09) (23,2.44873e+09) (23.1699,2.35262e+09) (23.3219,2.28865e+09) (23.585,2.22295e+09) (23.8074,2.19541e+09) (24,2.1806e+09) (24.3219,2.1704e+09) (24.585,2.16835e+09) (24.8074,2.16741e+09) (25,2.16724e+09) (26,2.16707e+09) (27,2.1674e+09) (28,2.16717e+09) (29,2.16721e+09) (30,2.16729e+09) (31,2.16717e+09) (32,2.16733e+09) (33,2.16723e+09) (34,2.1669e+09) };
9+
% \addlegendentry{funcname=ScanWrite64PtrUnrollLoop};
10+
this is the end

tests/latex/nolegend.tex

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
line1
2+
% IMPORT-DATA test test.data
3+
line2
4+
%% MULTIPLOT(funcname|nolegend) SELECT LOG(testsize) / LOG(2) AS x, bandwidth AS y, MULTIPLOT
5+
%% FROM test WHERE host='earth' ORDER BY MULTIPLOT,x
6+
this is the end

0 commit comments

Comments
 (0)