@@ -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
0 commit comments