Skip to content
Snippets Groups Projects
Commit 90ea2f61 authored by Tom Greig's avatar Tom Greig
Browse files

Add --y[r]range command line arguments.

They have the format [min]:[max] where either min or max can be left
out, if you like.
parent 2fa7ac7b
No related branches found
No related tags found
No related merge requests found
......@@ -69,6 +69,14 @@ struct context {
char* yrlab;
PangoLayout* yrlab_layout;
struct {
char* arg;
struct {
bool set;
double value;
} max, min;
} yrange, yrrange;
PangoFontDescription* tick_font_description;
double margins[4];
......@@ -183,6 +191,22 @@ int main( int argc, char** argv ) {
.description = "Ignore columns matching regex "
"(can be given multiple times)",
.arg_description = "regex"
}, {
.long_name = "yrange",
.short_name = '\0',
.flags = G_OPTION_FLAG_IN_MAIN,
.arg = G_OPTION_ARG_STRING,
.arg_data = &( context->yrange.arg ),
.description = "Y-axis range [min]:[max]",
.arg_description = "range",
}, {
.long_name = "yrrange",
.short_name = '\0',
.flags = G_OPTION_FLAG_IN_MAIN,
.arg = G_OPTION_ARG_STRING,
.arg_data = &( context->yrrange.arg ),
.description = "Right y-axis range [min]:[max]",
.arg_description = "range",
}, {
.long_name = "font",
.short_name = 'f',
......@@ -357,6 +381,92 @@ static void app_activate( GtkApplication* app, void* data ) {
g_source_set_callback(
(GSource*) source, &data_callback, context, NULL );
char* yrange = context->yrange.arg;
if ( NULL != yrange ) {
while ( '\0' != *yrange && isspace( *yrange ) ) {
yrange++;
}
if ( ':' == *yrange ) {
context->yrange.min.set = false;
} else {
context->yrange.min.set = true;
char* end;
context->yrange.min.value = strtod( yrange, &end );
if ( end == yrange ) {
fprintf( stderr, "Invalid yrange format\n" );
exit( 1 );
} else {
while ( '\0' != *end && isspace( *end ) ) {
end++;
}
if ( ':' != *end ) {
fprintf( stderr, "Invalid yrange format\n" );
exit( 1 );
}
yrange = end;
}
}
yrange++;
while ( '\0' != *yrange && isspace( *yrange ) ) {
yrange++;
}
if ( '\0' == *yrange ) {
context->yrange.max.set = false;
} else {
char* end;
context->yrange.max.value = strtod( yrange, &end );
if ( end == yrange ) {
fprintf( stderr, "Invalid yrange format\n" );
exit( 1 );
}
context->yrange.max.set = true;
}
}
char* yrrange = context->yrrange.arg;
if ( NULL != yrrange ) {
while ( '\0' != *yrrange && isspace( *yrrange ) ) {
yrrange++;
}
if ( ':' == *yrrange ) {
context->yrrange.min.set = false;
} else {
context->yrrange.min.set = true;
char* end;
context->yrrange.min.value = strtod( yrrange, &end );
if ( end == yrrange ) {
fprintf( stderr, "Invalid yrrange format\n" );
exit( 1 );
} else {
while ( '\0' != *end && isspace( *end ) ) {
end++;
}
if ( ':' != *end ) {
fprintf( stderr, "Invalid yrrange format\n" );
exit( 1 );
}
yrrange = end;
}
}
yrrange++;
while ( '\0' != *yrrange && isspace( *yrrange ) ) {
yrrange++;
}
if ( '\0' == *yrrange ) {
context->yrrange.max.set = false;
} else {
char* end;
context->yrrange.max.value = strtod( yrrange, &end );
if ( end == yrrange ) {
fprintf( stderr, "Invalid yrrange format\n" );
exit( 1 );
}
context->yrrange.max.set = true;
}
}
gtk_window_present( GTK_WINDOW( window ) );
}
......@@ -1092,6 +1202,22 @@ static void plot_draw( GtkDrawingArea* plot,
context->xdist = xrange[1] - xrange[0];
}
if ( context->yrange.min.set ) {
ylrange[0] = context->yrange.min.value;
}
if ( context->yrange.max.set ) {
ylrange[1] = context->yrange.max.value;
}
if ( context->yrrange.min.set ) {
yrrange[0] = context->yrrange.min.value;
}
if ( context->yrrange.max.set ) {
yrrange[1] = context->yrrange.max.value;
}
int xdivs = pretty( &( xrange[0] ), &( xrange[1] ), 10 );
int yldivs = lset ?
pretty( &( ylrange[0] ), &( ylrange[1] ), 10 ) : 0;
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment