Commit 3136afaf authored by Arnaud Blanchard's avatar Arnaud Blanchard
Browse files

Fix text graph

parent 701bf40b
......@@ -156,10 +156,8 @@ void fscan_tsv_floats(FILE *file, float *values, int values_nb);
void fscan_tsv_uchars(FILE *file, uchar *values, int values_nb);
void blc_fprint_char_graph(FILE *file, char *values, int values_nb, char const *title, int width, int height, int max, int min, char const* abscissa_name, char const* ordinate_name);
void blc_fprint_uchar_graph(FILE *file, uchar *values, int values_nb, char const *title, int width, int height, int max, int min, char const* abscissa_name, char const* ordinate_name);
void blc_fprint_float_graph(FILE *file, float *values, int values_nb, char const *title, int width, int height, float max, float min, char const* abscissa_name, char const* ordinate_name);
/**Display a surface graph of a 3D array in text mode ( tipically a image). If step0 and lenght0 = 1 it works with a 2D array.
The parameters are a bit complex, you are advised to use higher level functions like: blc_array::fprint_surface_uchars in C++
@param file where to put the graph usually stderr
......
......@@ -288,22 +288,26 @@ void fscan_tsv_uchars(FILE *file, uchar *values, int values_nb)
}
static void fprint_ordinate(FILE *file, const char* ordinate_name, int line){
static const char vertical_arrow[] = "^|";
if (line < strlen(vertical_arrow)) fputc(vertical_arrow[line], file);
else if ((ordinate_name) && (line < strlen(ordinate_name)+strlen(vertical_arrow))) fputc(ordinate_name[line-strlen(vertical_arrow)], file);
else fputc('|', file);
}
void blc_fprint_char_graph(FILE *file, char *values, int values_nb, char const *title, int width, int height, int max, int min, char const* abscissa_name, char const* ordinate_name){
float width_ratio;
int range, value;
int percent;
int column, line;
float threhold, threhold1;
float threshold, threshold1;
int i, display_values_nb;
char vertical_arrow[] = "^|";
//Size for the title
height-=3;
height-=2;
range = max - min;
//If width == -1 we take the size we need
......@@ -311,65 +315,8 @@ void blc_fprint_char_graph(FILE *file, char *values, int values_nb, char const *
display_values_nb=(width-1)/3;
if (display_values_nb > values_nb) display_values_nb=values_nb;
width_ratio=values_nb/(float)display_values_nb;
for (i = fprintf(file, "100%%(%.2d) [%s] ", max, title); i < width-1; ++i){
fputc('-', file);
}
fprintf(file, "\n");
FOR_INV(line, height){
if (line < strlen(vertical_arrow)) fputc(vertical_arrow[line], file);
else if ((ordinate_name) && (line < strlen(ordinate_name)+strlen(vertical_arrow))) fputc(ordinate_name[line-strlen(vertical_arrow)], file);
else fputc('|', file);
threhold = line * range / height;
threhold1 = (line+1) * range / height;
//We draw data
FOR(column, display_values_nb){
value = values[(int) (column * width_ratio)];
if (value - min > threhold1) fprintf(file, " []");
else if (value - min > threhold) {
percent=99 * (value - min) / range;
if (percent >= 100) percent=99;
fprintf(file, " %.2d", percent);
}
else fprintf(file, " ");
}
fprintf(file, "\n");
}
if (abscissa_name==NULL) abscissa_name="";
for (i = fprintf(file, " 0%%(%.3d) %s ", min, abscissa_name); i < width; ++i)
fputc('-', file);
fputc('>', file);
fprintf(file, "\n");
}
width =display_values_nb*3+1; //round
void blc_fprint_uchar_graph(FILE *file, uchar *values, int values_nb, char const *title, int width, int height, int max, int min, char const* abscissa_name, char const* ordinate_name){
float width_ratio;
int range, value;
int percent;
int column, line;
float threhold, threhold1;
int i, display_values_nb;
char vertical_arrow[] = "^|";
//Size for the title
height-=3;
range = max - min;
//If width == -1 we take the size we need
if (width==-1) width = values_nb * 3+1;
display_values_nb=(width-1)/3;
if (display_values_nb > values_nb) display_values_nb=values_nb;
width_ratio=values_nb/(float)display_values_nb;
for (i = fprintf(file, "100%%(%.2d) [%s] ", max, title); i < width-1; ++i){
......@@ -377,31 +324,28 @@ void blc_fprint_uchar_graph(FILE *file, uchar *values, int values_nb, char const
}
fprintf(file, "\n");
FOR_INV(line, height){
if (line < strlen(vertical_arrow)) fputc(vertical_arrow[line], file);
else if ((ordinate_name) && (line < strlen(ordinate_name)+strlen(vertical_arrow))) fputc(ordinate_name[line-strlen(vertical_arrow)], file);
else fputc('|', file);
FOR(line, height){
fprint_ordinate(file, ordinate_name, line);
threhold = line * range / height;
threhold1 = (line+1) * range / height;
threshold = range-(line+1) * range / height + min;
threshold1 = range-line * range / height + min;
//We draw data
FOR(column, display_values_nb){
value = values[(int) (column * width_ratio)];
if (value - min > threhold1) fprintf(file, " []");
else if (value - min > threhold) {
if (value < threshold) fprintf(file, " ");
else if (value <= threshold1) {
percent=99 * (value - min) / range;
if (percent >= 100) percent=99;
fprintf(file, " %.2d", percent);
}
else fprintf(file, " ");
else fprintf(file, " []");
}
fprintf(file, "\n");
}
if (abscissa_name==NULL) abscissa_name="";
for (i = fprintf(file, " 0%%(%.3d) %s ", min, abscissa_name); i < width; ++i)
for (i = fprintf(file, " 0%%(%.3d) %s ", min, abscissa_name); i < width-1; ++i)
fputc('-', file);
fputc('>', file);
......@@ -416,10 +360,8 @@ void blc_fprint_float_graph(FILE *file, float *values, int values_nb, char const
float threhold, threhold1;
int i, display_values_nb;
char vertical_arrow[] = "^|";
//Size for the title
height-=3;
height-=2;
range = max - min;
//If width == -1 we take the size we need
......@@ -427,6 +369,7 @@ void blc_fprint_float_graph(FILE *file, float *values, int values_nb, char const
display_values_nb=(width-1)/3;
if (display_values_nb > values_nb) display_values_nb=values_nb;
width =display_values_nb*3+1; //round
width_ratio=values_nb/(float)display_values_nb;
......@@ -435,31 +378,30 @@ void blc_fprint_float_graph(FILE *file, float *values, int values_nb, char const
}
fprintf(file, "\n");
FOR_INV(line, height){
FOR(line, height){
if (line < strlen(vertical_arrow)) fputc(vertical_arrow[line], file);
else if ((ordinate_name) && (line < strlen(ordinate_name)+strlen(vertical_arrow))) fputc(ordinate_name[line-strlen(vertical_arrow)], file);
else fputc('|', file);
fprint_ordinate(file, ordinate_name, line);
threhold = line * range / height;
threhold1 = (line+1) * range / height;
threhold = range-(line+1) * range / height + min;
threhold1 = range-line * range / height + min;
//We draw data
FOR(column, display_values_nb){
value = values[(int) (column * width_ratio)];
if (value - min > threhold1) fprintf(file, " []");
else if (value - min >= threhold) {
value = values[(int)(column * width_ratio)];
if (value < threhold) fprintf(file, " ");
else if (value <= threhold1) {
percent=99 * (value - min) / range;
if (percent >= 100) percent=99;
fprintf(file, " %.2d", percent);
}
else fprintf(file, " ");
else fprintf(file, " []");
}
fprintf(file, "\n");
}
if (abscissa_name==NULL) abscissa_name="";
for (i = fprintf(file, " 0%%(%.3f) %s ", min, abscissa_name); i < width; ++i)
for (i = fprintf(file, " 0%%(%.3f) %s ", min, abscissa_name); i < width-1; ++i)
fputc('-', file);
fputc('>', file);
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment