mirror of
https://github.com/subsurface/subsurface.git
synced 2025-01-31 18:23:23 +00:00
Plot the temperature Graph
Signed-off-by: Tomaz Canabrava <tcanabrava@kde.org> Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
This commit is contained in:
parent
ce8d30b938
commit
ef7ace9926
4 changed files with 70 additions and 60 deletions
79
profile.c
79
profile.c
|
@ -201,6 +201,32 @@ void remember_event(const char *eventname)
|
|||
evn_used++;
|
||||
}
|
||||
|
||||
int setup_temperature_limits(struct graphics_context *gc, struct plot_info *pi)
|
||||
{
|
||||
int maxtime, mintemp, maxtemp, delta;
|
||||
|
||||
/* Get plot scaling limits */
|
||||
maxtime = get_maxtime(pi);
|
||||
mintemp = pi->mintemp;
|
||||
maxtemp = pi->maxtemp;
|
||||
|
||||
gc->leftx = 0; gc->rightx = maxtime;
|
||||
/* Show temperatures in roughly the lower third, but make sure the scale
|
||||
is at least somewhat reasonable */
|
||||
delta = maxtemp - mintemp;
|
||||
if (delta < 3000) /* less than 3K in fluctuation */
|
||||
delta = 3000;
|
||||
gc->topy = maxtemp + delta*2;
|
||||
|
||||
if (PP_GRAPHS_ENABLED)
|
||||
gc->bottomy = mintemp - delta * 2;
|
||||
else
|
||||
gc->bottomy = mintemp - delta / 3;
|
||||
|
||||
pi->endtempcoord = SCALEY(gc, pi->mintemp);
|
||||
return maxtemp && maxtemp >= mintemp;
|
||||
}
|
||||
|
||||
#if 0
|
||||
static void render_depth_sample(struct graphics_context *gc, struct plot_data *entry, const text_render_options_t *tro)
|
||||
{
|
||||
|
@ -441,31 +467,7 @@ static void plot_pp_gas_profile(struct graphics_context *gc, struct plot_info *p
|
|||
}
|
||||
|
||||
|
||||
static int setup_temperature_limits(struct graphics_context *gc, struct plot_info *pi)
|
||||
{
|
||||
int maxtime, mintemp, maxtemp, delta;
|
||||
|
||||
/* Get plot scaling limits */
|
||||
maxtime = get_maxtime(pi);
|
||||
mintemp = pi->mintemp;
|
||||
maxtemp = pi->maxtemp;
|
||||
|
||||
gc->leftx = 0; gc->rightx = maxtime;
|
||||
/* Show temperatures in roughly the lower third, but make sure the scale
|
||||
is at least somewhat reasonable */
|
||||
delta = maxtemp - mintemp;
|
||||
if (delta < 3000) /* less than 3K in fluctuation */
|
||||
delta = 3000;
|
||||
gc->topy = maxtemp + delta*2;
|
||||
|
||||
if (PP_GRAPHS_ENABLED)
|
||||
gc->bottomy = mintemp - delta * 2;
|
||||
else
|
||||
gc->bottomy = mintemp - delta / 3;
|
||||
|
||||
pi->endtempcoord = SCALEY(gc, pi->mintemp);
|
||||
return maxtemp && maxtemp >= mintemp;
|
||||
}
|
||||
|
||||
static void plot_single_temp_text(struct graphics_context *gc, int sec, int mkelvin)
|
||||
{
|
||||
|
@ -515,35 +517,6 @@ static void plot_temperature_text(struct graphics_context *gc, struct plot_info
|
|||
plot_single_temp_text(gc, sec, last_temperature);
|
||||
}
|
||||
|
||||
static void plot_temperature_profile(struct graphics_context *gc, struct plot_info *pi)
|
||||
{
|
||||
int i;
|
||||
cairo_t *cr = gc->cr;
|
||||
int last = 0;
|
||||
|
||||
if (!setup_temperature_limits(gc, pi))
|
||||
return;
|
||||
|
||||
cairo_set_line_width_scaled(gc->cr, 2);
|
||||
set_source_rgba(gc, TEMP_PLOT);
|
||||
for (i = 0; i < pi->nr; i++) {
|
||||
struct plot_data *entry = pi->entry + i;
|
||||
int mkelvin = entry->temperature;
|
||||
int sec = entry->sec;
|
||||
if (!mkelvin) {
|
||||
if (!last)
|
||||
continue;
|
||||
mkelvin = last;
|
||||
}
|
||||
if (last)
|
||||
line_to(gc, sec, mkelvin);
|
||||
else
|
||||
move_to(gc, sec, mkelvin);
|
||||
last = mkelvin;
|
||||
}
|
||||
cairo_stroke(cr);
|
||||
}
|
||||
|
||||
/* gets both the actual start and end pressure as well as the scaling factors */
|
||||
static int get_cylinder_pressure_range(struct graphics_context *gc, struct plot_info *pi)
|
||||
{
|
||||
|
|
|
@ -38,6 +38,7 @@ struct plot_data {
|
|||
|
||||
void calculate_max_limits(struct dive *dive, struct divecomputer *dc, struct graphics_context *gc);
|
||||
struct plot_info *create_plot_info(struct dive *dive, struct divecomputer *dc, struct graphics_context *gc);
|
||||
int setup_temperature_limits(struct graphics_context *gc, struct plot_info *pi);
|
||||
|
||||
struct ev_select {
|
||||
char *ev_name;
|
||||
|
@ -83,6 +84,10 @@ int get_maxdepth(struct plot_info *pi);
|
|||
#define MIDDLE (0)
|
||||
#define BOTTOM (-1)
|
||||
|
||||
#define SCALEX(gc,x) (((x)-gc->leftx)/(gc->rightx-gc->leftx)*gc->maxx)
|
||||
#define SCALEY(gc,y) (((y)-gc->topy)/(gc->bottomy-gc->topy)*gc->maxy)
|
||||
#define SCALE(gc,x,y) SCALEX(gc,x),SCALEY(gc,y)
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
|
|
@ -26,10 +26,6 @@
|
|||
#define VELOCITY_COLORS_START_IDX VELO_STABLE
|
||||
#define VELOCITY_COLORS 5
|
||||
|
||||
/* Scale to 0,0 -> maxx,maxy */
|
||||
#define SCALEX(gc,x) (((x)-gc->leftx)/(gc->rightx-gc->leftx)*gc->maxx)
|
||||
#define SCALEY(gc,y) (((y)-gc->topy)/(gc->bottomy-gc->topy)*gc->maxy)
|
||||
#define SCALE(gc,x,y) SCALEX(gc,x),SCALEY(gc,y)
|
||||
|
||||
static struct graphics_context last_gc;
|
||||
static double plot_scale = SCALE_SCREEN;
|
||||
|
@ -246,10 +242,10 @@ void ProfileGraphicsView::plot(struct dive *dive)
|
|||
plot_depth_profile(&gc, pi);
|
||||
|
||||
plot_events(&gc, pi, dc);
|
||||
#if 0
|
||||
/* Temperature profile */
|
||||
plot_temperature_profile(gc, pi);
|
||||
|
||||
/* Temperature profile */
|
||||
plot_temperature_profile(&gc, pi);
|
||||
#if 0
|
||||
/* Cylinder pressure plot */
|
||||
plot_cylinder_pressure(gc, pi, dive, dc);
|
||||
|
||||
|
@ -630,6 +626,41 @@ void ProfileGraphicsView::resizeEvent(QResizeEvent *event)
|
|||
fitInView ( r.x() - 50, r.y() -50, r.width() + 100, r.height() + 100); // do a little bit of spacing;
|
||||
}
|
||||
|
||||
void ProfileGraphicsView::plot_temperature_profile(struct graphics_context *gc, struct plot_info *pi)
|
||||
{
|
||||
int last = 0;
|
||||
|
||||
if (!setup_temperature_limits(gc, pi))
|
||||
return;
|
||||
|
||||
QPointF from;
|
||||
QPointF to;
|
||||
QColor color = profile_color[TEMP_PLOT].first();
|
||||
|
||||
for (int i = 0; i < pi->nr; i++) {
|
||||
struct plot_data *entry = pi->entry + i;
|
||||
int mkelvin = entry->temperature;
|
||||
int sec = entry->sec;
|
||||
if (!mkelvin) {
|
||||
if (!last)
|
||||
continue;
|
||||
mkelvin = last;
|
||||
}
|
||||
if (last){
|
||||
to = QPointF(SCALE(gc, sec, mkelvin));
|
||||
//qDebug() << from << to;
|
||||
QGraphicsLineItem *item = new QGraphicsLineItem(from.x(), from.y(), to.x(), to.y());
|
||||
item->setPen(QPen(color, 2*plot_scale));
|
||||
scene()->addItem(item);
|
||||
from = to;
|
||||
}
|
||||
else{
|
||||
from = QPointF(SCALE(gc, sec, mkelvin));
|
||||
}
|
||||
last = mkelvin;
|
||||
}
|
||||
}
|
||||
|
||||
void ToolTipItem::addToolTip(const QString& toolTip, const QIcon& icon)
|
||||
{
|
||||
QGraphicsPixmapItem *iconItem = 0;
|
||||
|
|
|
@ -94,6 +94,7 @@ private:
|
|||
void plot_text(struct graphics_context *gc, text_render_options_t *tro, double x, double y, const QString &text);
|
||||
void plot_events(struct graphics_context *gc, struct plot_info *pi, struct divecomputer *dc);
|
||||
void plot_one_event(struct graphics_context *gc, struct plot_info *pi, struct event *event);
|
||||
void plot_temperature_profile(struct graphics_context *gc, struct plot_info *pi);
|
||||
|
||||
QPen defaultPen;
|
||||
QBrush defaultBrush;
|
||||
|
|
Loading…
Add table
Reference in a new issue