Skip to content
Snippets Groups Projects
Commit 0f63163d authored by tag2y19's avatar tag2y19 Committed by Tom Greig
Browse files

Add option to format x ticks as times

parent 0106ede2
No related branches found
No related tags found
No related merge requests found
...@@ -3,6 +3,7 @@ ...@@ -3,6 +3,7 @@
#include <fcntl.h> #include <fcntl.h>
#include <gtk/gtk.h> #include <gtk/gtk.h>
#include <pango/pangocairo.h> #include <pango/pangocairo.h>
#include <time.h>
/* TYPES!!! */ /* TYPES!!! */
...@@ -56,6 +57,7 @@ struct context { ...@@ -56,6 +57,7 @@ struct context {
PangoFontDescription* label_font_description; PangoFontDescription* label_font_description;
char* xlab; char* xlab;
bool time;
PangoLayout* xlab_layout; PangoLayout* xlab_layout;
char* yllab; char* yllab;
PangoLayout* yllab_layout; PangoLayout* yllab_layout;
...@@ -221,6 +223,13 @@ int main( int argc, char** argv ) { ...@@ -221,6 +223,13 @@ int main( int argc, char** argv ) {
.arg_data = &( context->yrlab ), .arg_data = &( context->yrlab ),
.description = "Right y-axis label", .description = "Right y-axis label",
.arg_description = "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, NULL,
}, },
...@@ -960,8 +969,7 @@ static void plot_draw( GtkDrawingArea* plot, ...@@ -960,8 +969,7 @@ static void plot_draw( GtkDrawingArea* plot,
bool rset = false; bool rset = false;
for ( struct data* data = context->data; for ( struct data* data = context->data;
NULL != data; NULL != data; data = data->next ) {
data = data->next ) {
xrange[1] = data->x; xrange[1] = data->x;
...@@ -1086,8 +1094,16 @@ static void plot_draw( GtkDrawingArea* plot, ...@@ -1086,8 +1094,16 @@ static void plot_draw( GtkDrawingArea* plot,
context->xtick_layouts.layouts[i], context->xtick_layouts.layouts[i],
context->tick_font_description ); context->tick_font_description );
} }
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", sprintf( tick_buffer, "%.3g",
xrange[0] + ( (double) i ) / ( xdivs - 1 ) * ( xrange[1] - xrange[0] ) ); xrange[0] + ( (double) i ) / ( xdivs - 1 ) *
( xrange[1] - xrange[0] ) );
}
pango_layout_set_text( pango_layout_set_text(
context->xtick_layouts.layouts[i], tick_buffer, -1 ); context->xtick_layouts.layouts[i], tick_buffer, -1 );
int tick_size; int tick_size;
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment