current state

This commit is contained in:
2017-04-24 16:12:15 +02:00
parent 67a9f02d6d
commit 755f5662ae
15 changed files with 1211 additions and 329 deletions

View File

@@ -31,12 +31,21 @@ class PlotErrFunc {
K::GnuplotPlot gplot;
//std::vector<std::string> colors = {"#000000", "#ff0000", "#00bb00", "#0000ff"};
std::vector<std::string> colors = {"#000000", "#ff0000", "#00ff00", "#0000ff", "#00aaaa"};
std::vector<std::string> colors = {"#000000", "#ff0000", "#00ff00", "#0000ff", "#00aaaa", "#aa00aa"};
bool markers = false;
struct Markers {
bool median = false;
bool quantil75 = false;
} markers;
std::string codeFile;
struct Range {
int fromPercent = 0;
int toPercent = 0;
int increment = 0;
} range;
public:
@@ -44,8 +53,17 @@ public:
PlotErrFunc(const std::string& xLabel, const std::string& yLabel) {
gplot.getAxisX().setLabel(xLabel);
gplot.getAxisY().setLabel(yLabel);
gplot.getAxisX().setRange(K::GnuplotAxis::Range(0, K::GnuplotAxis::Range::AUTO));
gplot.getAxisY().setRange(K::GnuplotAxis::Range(0, K::GnuplotAxis::Range::AUTO));
setYRange(0, 90, 5);
//gplot.getAxisX().setRange(K::GnuplotAxis::Range(0, K::GnuplotAxis::Range::AUTO));
gplot.getAxisX().setRange(K::GnuplotAxis::Range(K::GnuplotAxis::Range::AUTO, K::GnuplotAxis::Range::AUTO));
}
/** set the percentage range to show */
void setYRange(const int fromPercent, const int toPercent, const int increment = 5) {
this->range.fromPercent = fromPercent;
this->range.toPercent = toPercent;
this->range.increment = increment;
gplot.getAxisY().setRange(K::GnuplotAxis::Range(this->range.fromPercent, K::GnuplotAxis::Range::AUTO));
}
/** add one curve. Statistics<T> are allowed to be altered outside afterwards! */
@@ -75,14 +93,18 @@ public:
return gplot;
}
void writeCodeTo(const std::string& file) {
this->codeFile = file;
/** write the gnuplot commands to file for later re-use */
void writePlotToFile(const std::string& file) {
this->gp.writePlotToFile(file);
}
void showMarkers(const bool show) {
this->markers = show;
/** whether to show additional markers */
void showMarkers(const bool median, const bool quantil75) {
this->markers.median = median;
this->markers.quantil75 = quantil75;
}
/** plot all curves */
void plot() {
@@ -100,42 +122,35 @@ public:
const float range = e.stats->getQuantile(0.85) - minX;
const float space = range * 0.07;
// 0 - 80%
for (int j = 0; j <= 85; j+= 5) {
// [from:stepsSize:to]
//for (int j = this->range.fromPercent; j <= this->range.toPercent; j += this->range.increment) {
for (int j = 0; j <= 100; j += this->range.increment) {
const float y = j / 100.0f;
const float x = e.stats->getQuantile(y);
K::GnuplotPoint2 gp2(x, y*100);
e.line->add(gp2);
if (markers) {
int id = (i+1) * 100;
if (j == 50) {
gp << "set object " << id+1 << " circle at " << x << "," << j << " size screen 0.02,0.02\n";
gp << "set label " << id+2 << " at " << x+space << "," << j << " '" << x << "'\n";
gp << "set arrow " << id+3 << " from " << x << "," << 0 << " to " << x << "," << j << " nohead\n";
gp << "set arrow " << id+4 << " from " << 0 << "," << j << " to " << x << "," << j << " nohead\n";
} else if (j == 75) {
gp << "set object " << id+5 << " circle at " << x << "," << j << " size screen 0.02,0.02\n";
gp << "set label " << id+6 << " at " << x+space << "," << j << " '" << x << "'\n";
gp << "set arrow " << id+7 << " from " << x << "," << 0 << " to " << x << "," << j << " nohead\n";
gp << "set arrow " << id+8 << " from " << 0 << "," << j << " to " << x << "," << j << " nohead\n";
}
// show additional markers?
int id = (i+1) * 100;
if (j == 50 && markers.median) {
gp << "set object " << id+1 << " circle at " << x << "," << j << " size screen 0.02,0.02\n";
gp << "set label " << id+2 << " at " << x+space << "," << j << " '" << x << "'\n";
gp << "set arrow " << id+3 << " from " << x << "," << 0 << " to " << x << "," << j << " nohead\n";
gp << "set arrow " << id+4 << " from " << 0 << "," << j << " to " << x << "," << j << " nohead\n";
} else if (j == 75 && markers.quantil75) {
gp << "set object " << id+5 << " circle at " << x << "," << j << " size screen 0.02,0.02\n";
gp << "set label " << id+6 << " at " << x+space << "," << j << " '" << x << "'\n";
gp << "set arrow " << id+7 << " from " << x << "," << 0 << " to " << x << "," << j << " nohead\n";
gp << "set arrow " << id+8 << " from " << 0 << "," << j << " to " << x << "," << j << " nohead\n";
}
}
}
// render
gp.draw(gplot);
if (codeFile != "") {
std::ofstream out(codeFile);
out << gp.getBuffer();
out.close();
}
gp.flush();
}