Library: draft invocation framework for generating a Gnuplot

Deliberately keep it unstructured and add dedicated functions
for each new emerging use case; hopefully some commen usage scheme
will emerge over time.

 * Data is to be handed in as an iterator over CSV-strings.
 * will have to find out about additional parametrisation on a case-by-case base
This commit is contained in:
Fischlurch 2024-03-30 18:56:12 +01:00
parent f627d42b6e
commit db0838ddcc
6 changed files with 274 additions and 150 deletions

144
src/lib/gnuplot-gen.cpp Normal file
View file

@ -0,0 +1,144 @@
/*
GnuplotGen - building blocks for simplified data visualisation via Gnuplot
Copyright (C) Lumiera.org
2024, Hermann Vosseler <Ichthyostega@web.de>
This program is free software; you can redistribute it and/or
modify it under the terms of the GNU General Public License as
published by the Free Software Foundation; either version 2 of
the License, or (at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software
Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
* *****************************************************/
/** @file gnuplot-gen.cpp
** Definition of building blocks and preconfigured styles for Gnuplot scripts.
** The purpose of this setup is to generate visualisations of measurement data easily.
** A collection of plotting definitions, together with uniform styles is maintained
** within this translation unit, exposing a simple interface where the user only needs
** to supply the actual data to be plotted. Intentionally, this collection is started
** without much structure or preconceptions and written in a way to encourage adding
** more use-cases by copy-and-paste. Following this pragmatic approach, generalisations
** and common schemes will emerge eventually.
** @todo WIP-WIP 4/2024 first usage as part of Scheduler stress testing.
*/
#include "lib/text-template.hpp"
#include "lib/gnuplot-gen.hpp"
#include <string>
using std::string;
namespace lib {
namespace gnuplot_gen {
namespace {
const string GNUPLOT_SCATTER_REGRESSION = R"~(#
#
#
set term wxt size 600,800
set datafile separator ",;"
$RunData << _End_of_Data_
"graph length";"duration (ms)";"concurrency";"job time"
49, 24.3764, 5
5 , 4.30955, 5, 700
32, 16.039 , 5, 740
20, 6.47043, 4, 930
39, 19.424 , 4, 888
49, 15.951 , 4, 688
51, 32.7247, 5, 1200
62, 31.4712, 5, 812
15, 13.552 , 4
56, 36.1978, 4
32, 16.4677, 5
57, 22.2576, 6, 833
17, 14.3244, 5, 844
54, 27.4692, 5
46, 12.4055
52, 19.9593
39, 19.4265
41, 22.0513
64, 33.744
2, 3.04284
_End_of_Data_
set style line 1 linetype 1 linewidth 2 linecolor rgb '#1700D4'
set style line 2 linetype 3 linewidth 2 linecolor rgb '#113DD6'
set style line 3 linetype 2 linewidth 2 linecolor rgb '#0B7FCC'
set style line 4 linetype 6 linewidth 2 linecolor rgb '#37999D'
set style line 5 linetype 7 linewidth 2 linecolor rgb '#248269'
set style line 6 linetype 13 linewidth 2 linecolor rgb '#00C443'
set style line 7 linetype 12 linewidth 2 linecolor rgb '#B86E1C'
set style line 8 linetype 5 linewidth 2 linecolor rgb '#762C14'
set style line 9 linetype 4 linewidth 2 linecolor rgb '#AA0519'
set style line 10 linetype 1 linewidth 1 linecolor rgb '#303030'
set style line 11 linetype 0 linewidth 1 linecolor rgb '#A0A0A0' dashtype 3
unset border
set tics nomirror
set grid back linestyle 11
#set size ratio 0.6
set arrow 10 from graph 0,0 to graph 1.04,0 size screen 0.025,15,60 filled ls 10
set arrow 11 from graph 0,0 to graph 0,1.05 size screen 0.025,15,60 filled ls 10
set key autotitle columnheader
set x2label 'X axis'
set ylabel 'Y axis'
set arrow 1 from graph 0, first 1 to graph 1, first 30 nohead ls 9
set multiplot layout 2,1
set lmargin at screen 0.12
set rmargin at screen 0.88
plot $RunData using 1:2 with points linestyle 1
unset arrow 1
unset arrow 10
unset arrow 11
set border 2+8
set yrange [0:8]
set y2range [500:2000]
unset x2label
set format x ""
set ylabel "Y1 axis"
set y2label "Y2 axis" offset -2
set y2tics
plot $RunData using 1:3 with impulses linestyle 3, \
$RunData using 1:4 with points linestyle 5 axes x1y2
)~";
}
/** */
string
dataPlot (CSVRowIter& rowIT)
{
UNIMPLEMENTED ("generate gnuplot");
}
}} // namespace lib::gnuplot_gen

View file

@ -39,7 +39,7 @@
** @see GnuplotGen_test
** @see SchedulerStress_test
** @see text-template.hpp
** [gnuplot]: https://booooooooooooo
** [gnuplot]: http://gnuplot.info/documentation.html
*/
@ -48,12 +48,12 @@
//#include "lib/format-util.hpp"
#include "lib/text-template.hpp"
#include "lib/iter-source.hpp"
//#include "lib/util.hpp"
//#include <utility>
//#include <sstream>
//#include <string>
#include <string>
//#include <vector>
@ -62,10 +62,14 @@ namespace gnuplot_gen { ///< preconfigured setup for Gnuplot data visualisation
// using util::toString;
// using util::isnil;
// using std::string;
using std::string;
// using std::move;
using CSVRowIter = lib::IterSource<const string>::iterator;
/**
* Generate a Gnuplot diagram to visualise the given data points.
*/
string dataPlot (CSVRowIter&);
}} // namespace lib::gnuplot_gen

View file

@ -1,58 +0,0 @@
set datafile separator ",;"
$RunData << _End_of_Data_
"graph length";"duration (ms)"
49, 24.3764, 5
5 , 4.30955, 5
32, 16.039 , 5
20, 6.47043, 4
39, 19.424 , 4
49, 15.951 , 4
51, 32.7247, 5
62, 31.4712, 5
15, 13.552 , 4
56, 36.1978, 4
32, 16.4677, 5
57, 22.2576, 6
17, 14.3244, 5
54, 27.4692, 5
46, 12.4055
52, 19.9593
39, 19.4265
41, 22.0513
64, 33.744
2, 3.04284
_End_of_Data_
set style line 1 linetype 1 linewidth 2 linecolor rgb '#1700D4'
set style line 2 linetype 3 linewidth 2 linecolor rgb '#113DD6'
set style line 3 linetype 2 linewidth 2 linecolor rgb '#0B7FCC'
set style line 4 linetype 6 linewidth 2 linecolor rgb '#37999D'
set style line 5 linetype 7 linewidth 2 linecolor rgb '#248269'
set style line 6 linetype 13 linewidth 2 linecolor rgb '#00C443'
set style line 7 linetype 12 linewidth 2 linecolor rgb '#B86E1C'
set style line 8 linetype 5 linewidth 2 linecolor rgb '#762C14'
set style line 9 linetype 4 linewidth 2 linecolor rgb '#AA0519'
set style line 10 linetype 1 linewidth 1 linecolor rgb '#303030'
set style line 11 linetype 0 linewidth 1 linecolor rgb '#A0A0A0' dashtype 3
unset border
set tics nomirror
set grid back linestyle 11
#set size ratio 0.6
set arrow from graph 0,0 to graph 1.04,0 size screen 0.025,15,60 filled ls 10
set arrow from graph 0,0 to graph 0,1.05 size screen 0.025,15,60 filled ls 10
set key autotitle columnheader
set xlabel 'X axis'
set ylabel 'Y axis'
set arrow from graph 0, first 1 to graph 1, first 30 nohead ls 9
plot $RunData using 1:2 with points linestyle 1

View file

@ -1,81 +0,0 @@
set term wxt size 600,800
set datafile separator ",;"
$RunData << _End_of_Data_
"graph length";"duration (ms)";"concurrency";"job time"
49, 24.3764, 5
5 , 4.30955, 5, 700
32, 16.039 , 5, 740
20, 6.47043, 4, 930
39, 19.424 , 4, 888
49, 15.951 , 4, 688
51, 32.7247, 5, 1200
62, 31.4712, 5, 812
15, 13.552 , 4
56, 36.1978, 4
32, 16.4677, 5
57, 22.2576, 6, 833
17, 14.3244, 5, 844
54, 27.4692, 5
46, 12.4055
52, 19.9593
39, 19.4265
41, 22.0513
64, 33.744
2, 3.04284
_End_of_Data_
set style line 1 linetype 1 linewidth 2 linecolor rgb '#1700D4'
set style line 2 linetype 3 linewidth 2 linecolor rgb '#113DD6'
set style line 3 linetype 2 linewidth 2 linecolor rgb '#0B7FCC'
set style line 4 linetype 6 linewidth 2 linecolor rgb '#37999D'
set style line 5 linetype 7 linewidth 2 linecolor rgb '#248269'
set style line 6 linetype 13 linewidth 2 linecolor rgb '#00C443'
set style line 7 linetype 12 linewidth 2 linecolor rgb '#B86E1C'
set style line 8 linetype 5 linewidth 2 linecolor rgb '#762C14'
set style line 9 linetype 4 linewidth 2 linecolor rgb '#AA0519'
set style line 10 linetype 1 linewidth 1 linecolor rgb '#303030'
set style line 11 linetype 0 linewidth 1 linecolor rgb '#A0A0A0' dashtype 3
unset border
set tics nomirror
set grid back linestyle 11
#set size ratio 0.6
set arrow 10 from graph 0,0 to graph 1.04,0 size screen 0.025,15,60 filled ls 10
set arrow 11 from graph 0,0 to graph 0,1.05 size screen 0.025,15,60 filled ls 10
set key autotitle columnheader
set x2label 'X axis'
set ylabel 'Y axis'
set arrow 1 from graph 0, first 1 to graph 1, first 30 nohead ls 9
set multiplot layout 2,1
set lmargin at screen 0.12
set rmargin at screen 0.88
plot $RunData using 1:2 with points linestyle 1
unset arrow 1
unset arrow 10
unset arrow 11
set border 2+8
set yrange [0:8]
set y2range [500:2000]
unset x2label
set format x ""
set ylabel "Y1 axis"
set y2label "Y2 axis" offset -2
set y2tics
plot $RunData using 1:3 with impulses linestyle 3, \
$RunData using 1:4 with points linestyle 5 axes x1y2

View file

@ -29,13 +29,14 @@
#include "lib/test/run.hpp"
#include "lib/test/test-helper.hpp"///////////////////////TODO
#include "lib/gnuplot-gen.hpp"
#include "lib/iter-explorer.hpp"
#include "lib/format-cout.hpp"///////////////////////TODO
#include "lib/test/diagnostic-output.hpp"///////////////////////TODO
//#include <chrono>
//#include <array>
#include <array>
//using std::array;
using std::array;
namespace lib {
@ -72,6 +73,19 @@ namespace test {
void
simpeUsage()
{
using CSVlines = std::initializer_list<string>;
auto data = CSVlines{"x,y"
,"0,1"
,"1,1"
,"2,2"
,"3,3"
,"4,5"
,"5,8"
,"6,13"
};
auto csvIter = explore(data).asIterSource();
string gnuplot = gnuplot_gen::dataPlot (csvIter);
}

View file

@ -114276,11 +114276,108 @@ std::cout &lt;&lt; tmpl.render({&quot;what&quot;, &quot;World&quot;}) &lt;&lt; s
</node>
<node BACKGROUND_COLOR="#eee5c3" COLOR="#990000" CREATED="1711767367983" ID="ID_447481681" MODIFIED="1711767384545" TEXT="geignet in Templating &#xfc;bersetzen">
<icon BUILTIN="flag-yellow"/>
<node CREATED="1711767387817" ID="ID_249731836" MODIFIED="1711767413305" TEXT="brauche mehrere Basis-Templates">
<icon BUILTIN="yes"/>
<node CREATED="1711815238130" ID="ID_644083123" MODIFIED="1711815256928" TEXT="Grundidee: Bausteine + externe Steuer-Mechanik">
<icon BUILTIN="idea"/>
<node CREATED="1711815907291" ID="ID_530652307" MODIFIED="1711815930539" TEXT="Templates relativ &#xbb;dumm&#xab; halten"/>
<node CREATED="1711815932287" ID="ID_604033960" MODIFIED="1711816004296" TEXT="im Zweifelsfall ehr viele Steuer/Parameter-Variable verwenden"/>
<node CREATED="1711816073705" ID="ID_302589244" MODIFIED="1711816095177" TEXT="eine Builder-Funktion verwenden um diese aufzubauen"/>
</node>
<node BACKGROUND_COLOR="#e0ceaa" COLOR="#690f14" CREATED="1711767387817" ID="ID_249731836" MODIFIED="1711815901556" TEXT="l&#xe4;ngerfristig wird es mehrere Basis-Templates geben">
<icon BUILTIN="messagebox_warning"/>
</node>
<node BACKGROUND_COLOR="#f0d5c5" COLOR="#990033" CREATED="1711767397471" ID="ID_1445830361" MODIFIED="1711767408302" TEXT="welche Teile sind sinnvollerweise flexibel?">
<icon BUILTIN="help"/>
<node CREATED="1711816116763" ID="ID_1377511306" MODIFIED="1711816131828" TEXT="im konkreten Beispiel: das sekund&#xe4;re Diagramm ist optional zuschaltbar"/>
<node CREATED="1711816139855" ID="ID_152599714" MODIFIED="1711816150762" TEXT="die Linestyles werden komplett als Baustein injiziert"/>
<node CREATED="1711816185232" ID="ID_301292459" MODIFIED="1711816215559" TEXT="Range-Grenzen und Namen der Achsenbeschriftungen"/>
<node CREATED="1711816271564" ID="ID_1862603482" MODIFIED="1711816277255" TEXT="Parameter der Regressionslinie"/>
</node>
<node BACKGROUND_COLOR="#eee5c3" COLOR="#990000" CREATED="1711816316013" ID="ID_1527861975" MODIFIED="1711816667950" TEXT="Rahmen schaffen">
<icon BUILTIN="flag-yellow"/>
<node BACKGROUND_COLOR="#eee5c3" COLOR="#990000" CREATED="1711816320800" ID="ID_310548089" MODIFIED="1711816488240" TEXT="separate Translation-Unit">
<icon BUILTIN="flag-yellow"/>
<node CREATED="1711816330795" ID="ID_41779330" MODIFIED="1711816336896" TEXT="diese h&#xe4;lt die Template-Texte vor">
<node BACKGROUND_COLOR="#d2beaf" COLOR="#5c4d6e" CREATED="1711816397586" ID="ID_831816745" MODIFIED="1711816411097" TEXT="sp&#xe4;ter mal k&#xf6;nnte man Resourcen externalisieren">
<icon BUILTIN="hourglass"/>
</node>
<node BACKGROUND_COLOR="#ccb59b" COLOR="#6e2a38" CREATED="1711816413392" ID="ID_509012705" MODIFIED="1711816439602" TEXT="zun&#xe4;chst wird alles fest eincompiliert">
<richcontent TYPE="NOTE"><html>
<head>
</head>
<body>
<p>
watt soll der Jeitz
</p>
</body>
</html>
</richcontent>
<font ITALIC="true" NAME="SansSerif" SIZE="14"/>
<icon BUILTIN="yes"/>
</node>
</node>
<node CREATED="1711816463929" ID="ID_1654160554" MODIFIED="1711816482827" TEXT="und bekommt Daten als CSVFile"/>
</node>
<node BACKGROUND_COLOR="#eee5c3" COLOR="#990000" CREATED="1711816503707" ID="ID_1610562996" MODIFIED="1711816512171" TEXT="Hilfsmittel zur Aufbereitung">
<icon BUILTIN="flag-yellow"/>
<node BACKGROUND_COLOR="#eee5c3" COLOR="#990000" CREATED="1711816605957" ID="ID_1301642198" MODIFIED="1711816625887" TEXT="Notation f&#xfc;r Parmeter-Konfiguration">
<icon BUILTIN="flag-yellow"/>
<node CREATED="1711816632267" ID="ID_243539327" MODIFIED="1711816646604" TEXT="auf ETD / MakeRec() aufbauen"/>
<node CREATED="1711816648544" ID="ID_1216726530" MODIFIED="1711816663402" TEXT="damit ist auch die String-Konvertierung schon gew&#xe4;hrleistet"/>
</node>
</node>
<node BACKGROUND_COLOR="#eef0c5" COLOR="#990000" CREATED="1711820689562" ID="ID_1257950036" MODIFIED="1711820696505" TEXT="Problem Daten-&#xdc;bergabe">
<icon BUILTIN="pencil"/>
<node CREATED="1711820697640" ID="ID_681694171" MODIFIED="1711820712194" TEXT="das DataFile ist generisch, aber kein Interface"/>
<node CREATED="1711820712878" ID="ID_935453700" MODIFIED="1711820724089" TEXT="eigentlich brauche ich nur eine Sequenz von CSV-Zeilen">
<node CREATED="1711820738627" ID="ID_1878202648" MODIFIED="1711820752493" TEXT="k&#xf6;nnte man abstrahieren als Iterator-&#xfc;ber-Strings"/>
<node CREATED="1711820753138" ID="ID_53347581" MODIFIED="1711820764249" TEXT="Interface IterSource&lt;const string&gt;">
<icon BUILTIN="forward"/>
</node>
</node>
<node BACKGROUND_COLOR="#eee5c3" COLOR="#990000" CREATED="1711820779334" ID="ID_820373527" MODIFIED="1711820787802" TEXT="einfache Builder-Methoden bereitstellen">
<icon BUILTIN="flag-yellow"/>
<node BACKGROUND_COLOR="#eee5c3" COLOR="#990000" CREATED="1711820796179" ID="ID_693535760" MODIFIED="1711820809898" TEXT="direkt eine Liste von Strings (zeilenweise)">
<icon BUILTIN="flag-yellow"/>
</node>
<node BACKGROUND_COLOR="#eee5c3" COLOR="#990000" CREATED="1711820811033" ID="ID_1587185713" MODIFIED="1711820838686" TEXT="Header + Datentupel&lt;double&gt;">
<icon BUILTIN="flag-yellow"/>
</node>
</node>
</node>
</node>
<node BACKGROUND_COLOR="#eee5c3" COLOR="#990000" CREATED="1711820846814" ID="ID_131434294" MODIFIED="1711821174833" TEXT="Template-Bausteine">
<icon BUILTIN="flag-yellow"/>
<node BACKGROUND_COLOR="#eee5c3" COLOR="#990000" CREATED="1711820852404" ID="ID_1098550176" MODIFIED="1711821039412" TEXT="einfacher Daten-Plot">
<icon BUILTIN="flag-yellow"/>
<node CREATED="1711820876736" ID="ID_1449855332" MODIFIED="1711820912379" TEXT="gemeinsame Abszisse + 1...9 Datenreihen"/>
<node CREATED="1711820916356" ID="ID_1235091819" MODIFIED="1711820929101" TEXT="stellt diese als Punkte oder Linien dar"/>
<node BACKGROUND_COLOR="#d2beaf" COLOR="#5c4d6e" CREATED="1711820977003" ID="ID_1738447878" MODIFIED="1711820982619" TEXT="Thema sortieren">
<icon BUILTIN="hourglass"/>
<node CREATED="1711820983626" ID="ID_1670062583" MODIFIED="1711820990224" TEXT="vorerst ausklammern">
<icon BUILTIN="yes"/>
</node>
<node CREATED="1711820991857" ID="ID_816050804" MODIFIED="1711821006944" TEXT="das ist typischerweise einfacher im Client-code"/>
<node CREATED="1711821011398" ID="ID_1034083474" MODIFIED="1711821034215" TEXT="generische L&#xf6;sung: effuse() + stort vector + neuer Iterator">
<icon BUILTIN="idea"/>
</node>
</node>
<node BACKGROUND_COLOR="#eee5c3" COLOR="#990000" CREATED="1711821043106" ID="ID_1100655638" MODIFIED="1711821127675" TEXT="dann ausgeben in einfachem Diagramm">
<icon BUILTIN="flag-yellow"/>
<node CREATED="1711821061064" ID="ID_554055144" MODIFIED="1711821076346" TEXT="gemeinsame Abszisse .. beschriftet nach Datenzeile"/>
<node CREATED="1711821077344" ID="ID_729055387" MODIFIED="1711821097135" TEXT="alle verwenden eine einzige Y-Achse (unbeschriftet)"/>
<node CREATED="1711821100818" ID="ID_469183888" MODIFIED="1711821106065" TEXT="Legende wird automatisch generiert"/>
<node CREATED="1711821109901" ID="ID_695061729" MODIFIED="1711821122502" TEXT="das neue Lumiera-Styling verwenden">
<icon BUILTIN="ksmiletris"/>
</node>
</node>
</node>
<node BACKGROUND_COLOR="#eee5c3" COLOR="#990000" CREATED="1711821130246" ID="ID_1965869017" MODIFIED="1711821143254" TEXT="Scatter mit Regression">
<icon BUILTIN="flag-yellow"/>
</node>
<node BACKGROUND_COLOR="#eee5c3" COLOR="#990000" CREATED="1711821144151" ID="ID_944118646" MODIFIED="1711821172138" TEXT="Scatter mit Regrssion + Zusatzdaten">
<icon BUILTIN="flag-yellow"/>
</node>
</node>
</node>
<node BACKGROUND_COLOR="#eee5c3" COLOR="#990000" CREATED="1710079848190" ID="ID_227233521" MODIFIED="1710079870844" TEXT="Darstellung ausarbeiten">
@ -114300,6 +114397,11 @@ std::cout &lt;&lt; tmpl.render({&quot;what&quot;, &quot;World&quot;}) &lt;&lt; s
</node>
</node>
</node>
<node CREATED="1711820647889" ID="ID_149856563" MODIFIED="1711820660945" TEXT="GnuplotGen_test">
<node BACKGROUND_COLOR="#eee5c3" COLOR="#990000" CREATED="1711820662341" ID="ID_1728359549" MODIFIED="1711820675652" TEXT="einfachster Testfall: ein Daten-Punkt-Plot">
<icon BUILTIN="flag-yellow"/>
</node>
</node>
</node>
</node>
</node>
@ -123449,8 +123551,7 @@ unsigned int ThreadIdAsInt = *static_cast&lt;unsigned int*&gt;(static_cast&lt;vo
this allows to change, reposition and re-style an existing arrow
</p>
</body>
</html>
</richcontent>
</html></richcontent>
</node>
</node>
<node CREATED="1711742209926" ID="ID_1413844596" LINK="http://gnuplot.info/docs_5.5/loc12019.html" MODIFIED="1711742320361" TEXT="set grid : Grid-Einstellungen">