diff --git a/src/main.c b/src/main.c index 10e6a03c35efbfe3bb31ea9ffacc599879fbf04c..a385bf39a7502d453b443fc1ccdfc86cfb2fea3f 100644 --- a/src/main.c +++ b/src/main.c @@ -3,6 +3,7 @@ #include <fcntl.h> #include <gtk/gtk.h> #include <pango/pangocairo.h> +#include <time.h> /* TYPES!!! */ @@ -56,6 +57,7 @@ struct context { PangoFontDescription* label_font_description; char* xlab; + bool time; PangoLayout* xlab_layout; char* yllab; PangoLayout* yllab_layout; @@ -221,6 +223,13 @@ int main( int argc, char** argv ) { .arg_data = &( context->yrlab ), .description = "Right y-axis label", .arg_description = "label", + }, { + .long_name = "time", + .short_name = 'T', + .flags = G_OPTION_FLAG_IN_MAIN, + .arg = G_OPTION_ARG_NONE, + .arg_data = &( context->time ), + .description = "Format x-axis as time", }, { NULL, }, @@ -960,8 +969,7 @@ static void plot_draw( GtkDrawingArea* plot, bool rset = false; for ( struct data* data = context->data; - NULL != data; - data = data->next ) { + NULL != data; data = data->next ) { xrange[1] = data->x; @@ -1086,8 +1094,16 @@ static void plot_draw( GtkDrawingArea* plot, context->xtick_layouts.layouts[i], context->tick_font_description ); } - sprintf( tick_buffer, "%.3g", - xrange[0] + ( (double) i ) / ( xdivs - 1 ) * ( xrange[1] - xrange[0] ) ); + if ( context->time ) { + time_t t = xrange[0] + ( (double) i ) / ( xdivs - 1 ) * + ( xrange[1] - xrange[0] ); + struct tm* tm = gmtime( &t ); + strftime( tick_buffer, 512, "%H:%M:%S", tm ); + } else { + sprintf( tick_buffer, "%.3g", + xrange[0] + ( (double) i ) / ( xdivs - 1 ) * + ( xrange[1] - xrange[0] ) ); + } pango_layout_set_text( context->xtick_layouts.layouts[i], tick_buffer, -1 ); int tick_size;