Skip to content
Snippets Groups Projects
Commit ba4acffd authored by Christophe Geuzaine's avatar Christophe Geuzaine
Browse files

basic 2D Log10 graphs

parent 00aa7781
No related branches found
No related tags found
No related merge requests found
......@@ -153,6 +153,12 @@ static bool getGraphData(PView *p, std::vector<double> &x, double &xmin,
xmin = data->getTime(0);
xmax = data->getTime(data->getNumTimeSteps() - 1);
}
if(opt->scaleType == PViewOptions::Logarithmic)
for(unsigned int i = 0; i < y.size(); i++)
for(unsigned int j = 0; j < y[i].size(); j++)
y[i][j] = log10(y[i][j]);
return true;
}
......@@ -164,8 +170,6 @@ static void drawGraphAxes(drawContext *ctx, PView *p, double xleft, double ytop,
if(!opt->axes) return;
char label[1024];
// total font height
double font_h = drawContext::global()->getStringHeight() ?
drawContext::global()->getStringHeight() : 1;
......@@ -196,29 +200,30 @@ static void drawGraphAxes(drawContext *ctx, PView *p, double xleft, double ytop,
glEnd();
// y label
std::string label = data->getName();
if(opt->type == PViewOptions::Plot2D ||
opt->type == PViewOptions::Plot2DSpace){
int nt = data->getNumTimeSteps();
if((opt->showTime == 1 && nt > 1) || opt->showTime == 2){
char tmp[256];
sprintf(tmp, opt->format.c_str(), data->getTime(opt->timeStep));
sprintf(label, "%s (%s)", data->getName().c_str(), tmp);
label += std::string(" (") + tmp + ")";
}
else if((opt->showTime == 3 && nt > 1) || opt->showTime == 4){
sprintf(label, "%s (%d)", data->getName().c_str(), opt->timeStep);
char tmp[256];
sprintf(tmp, "%d", opt->timeStep);
label += std::string(" (") + tmp + ")";
}
else
sprintf(label, "%s", data->getName().c_str());
}
else
sprintf(label, "%s", data->getName().c_str());
if(opt->scaleType == PViewOptions::Logarithmic)
label = "Log10 " + label;
glRasterPos2d(xleft, ytop + font_h + tic);
ctx->drawStringCenter(label);
ctx->drawStringCenter(label.c_str());
// x label
sprintf(label, "%s", opt->axesLabel[0].c_str());
label = opt->axesLabel[0];
glRasterPos2d(xleft + width / 2, ytop - height - 2 * font_h - 2 * tic);
ctx->drawStringCenter(label);
ctx->drawStringCenter(label.c_str());
// y tics and horizontal grid
if(opt->nbIso > 0){
......@@ -253,10 +258,11 @@ static void drawGraphAxes(drawContext *ctx, PView *p, double xleft, double ytop,
}
}
if(opt->showScale){
sprintf(label, opt->format.c_str(), (i == nb) ? opt->tmpMin :
char tmp[256];
sprintf(tmp, opt->format.c_str(), (i == nb) ? opt->tmpMin :
(opt->tmpMax - i * dv));
glRasterPos2d(xleft - 2 * tic, ytop - i * dy - font_a / 3.);
ctx->drawStringRight(label);
ctx->drawStringRight(tmp);
}
}
}
......@@ -265,9 +271,10 @@ static void drawGraphAxes(drawContext *ctx, PView *p, double xleft, double ytop,
if(opt->axesTics[0] > 0){
int nb = opt->axesTics[0];
if(opt->axes){
sprintf(label, opt->axesFormat[0].c_str(), - M_PI * 1.e-4);
if((nb - 1) * drawContext::global()->getStringWidth(label) > width)
nb = (int)(width / drawContext::global()->getStringWidth(label)) + 1;
char tmp[256];
sprintf(tmp, opt->axesFormat[0].c_str(), - M_PI * 1.e-4);
if((nb - 1) * drawContext::global()->getStringWidth(tmp) > width)
nb = (int)(width / drawContext::global()->getStringWidth(tmp)) + 1;
}
if(nb == 1) nb++;
......@@ -299,13 +306,14 @@ static void drawGraphAxes(drawContext *ctx, PView *p, double xleft, double ytop,
CTX::instance()->print.epsLineWidthFactor));
}
char tmp[256];
if(nb == 1)
sprintf(label, opt->axesFormat[0].c_str(), xmin);
sprintf(tmp, opt->axesFormat[0].c_str(), xmin);
else
sprintf(label, opt->axesFormat[0].c_str(),
sprintf(tmp, opt->axesFormat[0].c_str(),
xmin + i * (xmax - xmin) / (double)(nb - 1));
glRasterPos2d(xleft + i * dx, ybot - font_h - tic);
ctx->drawStringCenter(label);
ctx->drawStringCenter(tmp);
}
}
}
......@@ -421,6 +429,11 @@ static void drawGraph(drawContext *ctx, PView *p, double xleft, double ytop,
opt->tmpMax = data->getMax();
}
if(opt->scaleType == PViewOptions::Logarithmic){
opt->tmpMin = log10(opt->tmpMin);
opt->tmpMax = log10(opt->tmpMax);
}
std::vector<double> x;
std::vector<std::vector<double> > y;
double xmin, xmax;
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment