labels improved
colors more dynamic
defaults added


git-svn-id: file:///home/jan/tmp/wetterstation/trunk@97 dd492736-c11a-0410-ad51-8c26713eaf7f
This commit is contained in:
losinshi 2006-09-15 09:57:35 +00:00
parent 8a307c332c
commit b8188a16e9
6 changed files with 152 additions and 59 deletions

View File

@ -29,6 +29,39 @@
#define DEFAULT_CONFIG_FILE "./chart.conf" /* Standart-Configdatei */ #define DEFAULT_CONFIG_FILE "./chart.conf" /* Standart-Configdatei */
/* Image-Default-Werte ----------------------------------------------- */
#define DEFAULT_HEADLINE "Wetter - Diagram"
#define DEFAULT_MANUAL_TABLE "no"
#define DEFAULT_TABLE_FIELD "temp"
#define DEFAULT_GEN_INTERVAL "15m"
#define DEFAULT_SHOW_INTERVAL "2d"
#define DEFAULT_LABEL_INTERVAL "2h"
#define DEFAULT_LABEL_SUM "no"
#define DEFAULT_WIDTH "800"
#define DEFAULT_HEIGHT "300"
#define DEFAULT_SENS_ID "1"
#define DEFAULT_VAL_KOEFF "0.1"
#define DEFAULT_UNIT "°C"
#define DEFAULT_X_AX_DESC "X-Axis"
#define DEFAULT_Y_AX_DESC "Y-Axis"
#define DEFAULT_X_FORMAT "%H:%M"
#define DEFAULT_X_FORMAT_EXTRA "%d.%m.%y| %H:%M"
#define DEFAULT_BG_COLOR "DF:DF:EF:00"
#define DEFAULT_DIA_BG_COLOR "F0:A0:D0:D0"
#define DEFAULT_ZERO_LINE_COLOR "BF:80:80:40"
#define DEFAULT_DIA_LINE_COLOR "60:30:50:30"
#define DEFAULT_DIA_GRID_X_COLOR "60:60:60:EF"
#define DEFAULT_DIA_GRID_Y_COLOR "60:60:60:EF"
#define DEFAULT_DIA_BORDER_COLOR "a0:a0:a0:af"
#define DEFAULT_HEADLINE_COLOR "80:10:10:30"
#define DEFAULT_LABEL_X_COLOR "60:60:60:30"
#define DEFAULT_LABEL_EXTRA_X_COLOR "60:10:10:20"
#define DEFAULT_LABEL_Y_COLOR "20:20:20:20"
#define DEFAULT_DESCR_X_COLOR "10:50:10:20"
#define DEFAULT_DESCR_Y_COLOR "10:10:50:20"
/*Alle möglichen Definitionen, die in allen code-schnipseln benötigt werden*/ /*Alle möglichen Definitionen, die in allen code-schnipseln benötigt werden*/

View File

@ -23,17 +23,22 @@ typedef struct image_cfg {
char *y_desc; char *y_desc;
int sens_id; int sens_id;
double val_koeff; double val_koeff;
char *x_fmt_extra;
char *x_fmt;
img_color_ptr bg_color; img_color_ptr bg_color;
img_color_ptr dia_bg_color; img_color_ptr dia_bg_color;
img_color_ptr dia_line_color; img_color_ptr dia_line_color;
img_color_ptr dia_grid_color; img_color_ptr dia_grid_x_color;
img_color_ptr dia_grid_y_color;
img_color_ptr dia_border_color; img_color_ptr dia_border_color;
img_color_ptr zero_line_color; img_color_ptr zero_line_color;
img_color_ptr label_color;
img_color_ptr headline_color; img_color_ptr headline_color;
img_color_ptr label_x_color;
img_color_ptr label_extra_x_color;
img_color_ptr label_y_color;
img_color_ptr desc_x_color;
img_color_ptr desc_y_color;
} image_cfg_t; } image_cfg_t;

View File

@ -27,9 +27,12 @@
#include "../config.h" #include "../config.h"
#include "image_common.h" #include "image_common.h"
#define BUFFSIZE 512
static int read_time(const char *, void *); static int read_time(const char *, void *);
static int read_color(const char *, void *); static int read_color(const char *, void *);
static int read_double(const char *, void *); static int read_double(const char *, void *);
static int read_fmt_str(const char *, void *);
@ -38,35 +41,71 @@ static int read_double(const char *, void *);
static const config_keyword keywords[] = { static const config_keyword keywords[] = {
/* keyword handler variable address default */ /* keyword handler variable address default */
{"filename", read_str, &(img_cfg.file_name), ""}, {"filename", read_str, &(img_cfg.file_name), ""},
{"headline", read_str, &(img_cfg.headline), ""}, {"headline", read_str, &(img_cfg.headline), DEFAULT_HEADLINE},
{"table_field", read_str, &(img_cfg.table_field), ""}, {"table_field", read_str, &(img_cfg.table_field), DEFAULT_TABLE_FIELD},
{"manual_table", read_yn, &(img_cfg.manual_table), "no"}, {"manual_table", read_yn, &(img_cfg.manual_table), DEFAULT_MANUAL_TABLE},
{"manual_table_name", read_str, &(img_cfg.table_name), ""}, {"manual_table_name", read_str, &(img_cfg.table_name), ""},
{"gen_interval", read_time, &(img_cfg.gen_interval), ""}, {"gen_interval", read_time, &(img_cfg.gen_interval), DEFAULT_GEN_INTERVAL},
{"show_interval", read_time, &(img_cfg.show_interval), ""}, {"show_interval", read_time, &(img_cfg.show_interval), DEFAULT_SHOW_INTERVAL},
{"label_interval", read_time, &(img_cfg.label_interval), ""}, {"label_interval", read_time, &(img_cfg.label_interval), DEFAULT_LABEL_INTERVAL},
{"label_sum", read_yn, &(img_cfg.label_sum), ""}, {"label_sum", read_yn, &(img_cfg.label_sum), DEFAULT_LABEL_SUM},
{"width", read_int, &(img_cfg.width), ""}, {"width", read_int, &(img_cfg.width), DEFAULT_WIDTH},
{"height", read_int, &(img_cfg.height), ""}, {"height", read_int, &(img_cfg.height), DEFAULT_HEIGHT},
{"unit", read_str, &(img_cfg.unit), ""}, {"unit", read_str, &(img_cfg.unit), DEFAULT_UNIT},
{"sensor_id", read_int, &(img_cfg.sens_id), ""}, {"sensor_id", read_int, &(img_cfg.sens_id), DEFAULT_SENS_ID},
{"x_axis_desc", read_str, &(img_cfg.x_desc), ""}, {"x_axis_desc", read_str, &(img_cfg.x_desc), DEFAULT_X_AX_DESC},
{"y_axis_desc", read_str, &(img_cfg.y_desc), ""}, {"y_axis_desc", read_str, &(img_cfg.y_desc), DEFAULT_Y_AX_DESC},
{"value_koeffizient", read_double, &(img_cfg.val_koeff), ""}, {"x_format", read_fmt_str, &(img_cfg.x_fmt), DEFAULT_X_FORMAT},
{"x_format_extra", read_fmt_str, &(img_cfg.x_fmt_extra), DEFAULT_X_FORMAT_EXTRA},
{"value_koeffizient", read_double, &(img_cfg.val_koeff), DEFAULT_VAL_KOEFF},
{"bg_color", read_color, &(img_cfg.bg_color), ""}, {"bg_color", read_color, &(img_cfg.bg_color), DEFAULT_BG_COLOR},
{"dia_bg_color", read_color, &(img_cfg.dia_bg_color), ""}, {"dia_bg_color", read_color, &(img_cfg.dia_bg_color), DEFAULT_DIA_BG_COLOR},
{"dia_line_color", read_color, &(img_cfg.dia_line_color), ""}, {"dia_line_color", read_color, &(img_cfg.dia_line_color), DEFAULT_DIA_LINE_COLOR},
{"dia_grid_color", read_color, &(img_cfg.dia_grid_color), ""}, {"dia_grid_x_color", read_color, &(img_cfg.dia_grid_x_color), DEFAULT_DIA_GRID_X_COLOR},
{"dia_border_color", read_color, &(img_cfg.dia_border_color), ""}, {"dia_grid_y_color", read_color, &(img_cfg.dia_grid_y_color), DEFAULT_DIA_GRID_Y_COLOR},
{"zero_line_color", read_color, &(img_cfg.zero_line_color), ""}, {"dia_border_color", read_color, &(img_cfg.dia_border_color), DEFAULT_DIA_BORDER_COLOR},
{"label_color", read_color, &(img_cfg.label_color), ""}, {"zero_line_color", read_color, &(img_cfg.zero_line_color), DEFAULT_ZERO_LINE_COLOR},
{"headline_color", read_color, &(img_cfg.headline_color), ""}, {"headline_color", read_color, &(img_cfg.headline_color), DEFAULT_HEADLINE_COLOR},
{"label_x_color", read_color, &(img_cfg.label_x_color), DEFAULT_LABEL_X_COLOR},
{"label_extra_x_color", read_color, &(img_cfg.label_extra_x_color), DEFAULT_LABEL_EXTRA_X_COLOR},
{"label_y_color", read_color, &(img_cfg.label_y_color), DEFAULT_LABEL_Y_COLOR},
{"descr_y_color", read_color, &(img_cfg.desc_y_color), DEFAULT_DESCR_X_COLOR},
{"descr_x_color", read_color, &(img_cfg.desc_x_color), DEFAULT_DESCR_Y_COLOR},
{"", NULL, NULL, ""} {"", NULL, NULL, ""}
}; };
static int read_fmt_str(const char *line, void *arg){
char **dest = arg;
char *new_line = NULL;
char *temp = malloc(sizeof(char)*BUFFSIZE);
char *p;
read_str(line, &new_line);
if(new_line != NULL){
p = strchr(new_line, '|');
if(p != NULL){
strcpy(p, "\0");
strcpy(temp, new_line);
strcat(temp, "\r\n");
strcat(temp, p+1);
} else {
strcpy(temp, new_line);
}
if (*dest) free(*dest);
*dest = strdup(temp);
free(new_line);
}
free(temp);
return 1;
}
static int read_double(const char *line, void *arg){ static int read_double(const char *line, void *arg){
double *dest = arg; double *dest = arg;
@ -106,8 +145,9 @@ static int read_time(const char *line, void *arg){
long *dest = arg; long *dest = arg;
long mult = 0; long mult = 0;
char *p = NULL; char *p = NULL;
char *tmp = strdup(line);
p = strchr(line, '\0'); p = strchr(tmp, '\0');
if(p != NULL){ if(p != NULL){
switch( *(p - 1) ){ switch( *(p - 1) ){
case 's': case 's':
@ -135,7 +175,7 @@ static int read_time(const char *line, void *arg){
} }
} }
*dest = atol(line) * mult; *dest = atol(tmp) * mult;
return 1; return 1;
} }

View File

@ -133,7 +133,7 @@ label_list_ptr get_x_label_list(int c_width){
for ( i = 1; i < num; i++ ) { for ( i = 1; i < num; i++ ) {
timestamp = base_time + (i * img_cfg.label_interval); timestamp = base_time + (i * img_cfg.label_interval);
strftime(buff, BUFFSIZE, "%d.%m.%y", localtime(&timestamp) ); strftime(buff, BUFFSIZE, img_cfg.x_fmt, localtime(&timestamp) );
new_ptr = malloc(sizeof(label_list_t)); new_ptr = malloc(sizeof(label_list_t));
new_ptr->pos = floor( ((double)i) * factor); new_ptr->pos = floor( ((double)i) * factor);
@ -177,7 +177,6 @@ int scale_y_coords(pix_list_ptr ptr, int c_height){
DEBUGOUT2(" Nullinie bei: %d\n", zero_line); DEBUGOUT2(" Nullinie bei: %d\n", zero_line);
//printf("%f -- %f -- %d\n", range, pix_per_scale, zero_line);
if ((real_max - real_min + 1) >= real_max){ if ((real_max - real_min + 1) >= real_max){
return zero_line; return zero_line;
} else { } else {
@ -199,7 +198,7 @@ char *get_max_time(){
char *buff = malloc(sizeof(char)*BUFFSIZE); char *buff = malloc(sizeof(char)*BUFFSIZE);
time_t timestamp = base_time + img_cfg.show_interval; time_t timestamp = base_time + img_cfg.show_interval;
strftime(buff, BUFFSIZE, "%d.%m.%y\r\n %H:%M", localtime(&timestamp) ); strftime(buff, BUFFSIZE, img_cfg.x_fmt_extra, localtime(&timestamp) );
return buff; return buff;
} }
@ -208,7 +207,7 @@ char *get_min_time(){
char *buff = malloc(sizeof(char)*BUFFSIZE); char *buff = malloc(sizeof(char)*BUFFSIZE);
time_t timestamp = base_time ; time_t timestamp = base_time ;
strftime(buff, BUFFSIZE, "%d.%m.%y\r\n %H:%M", localtime(&timestamp) ); strftime(buff, BUFFSIZE, img_cfg.x_fmt_extra, localtime(&timestamp) );
return buff; return buff;
} }

View File

@ -91,10 +91,15 @@ static gdImagePtr draw_image(gdImagePtr img){
color val_line_c = alloc_alpha_color(img, img_cfg.dia_line_color); color val_line_c = alloc_alpha_color(img, img_cfg.dia_line_color);
color zero_line_c = alloc_alpha_color(img, img_cfg.zero_line_color); color zero_line_c = alloc_alpha_color(img, img_cfg.zero_line_color);
color dia_bg_c = alloc_alpha_color(img, img_cfg.dia_bg_color); color dia_bg_c = alloc_alpha_color(img, img_cfg.dia_bg_color);
color diag_grid_c = alloc_alpha_color(img, img_cfg.dia_grid_color); color diag_grid_x_c = alloc_alpha_color(img, img_cfg.dia_grid_x_color);
color diag_grid_y_c = alloc_alpha_color(img, img_cfg.dia_grid_y_color);
color dia_border_c = alloc_alpha_color(img, img_cfg.dia_border_color); color dia_border_c = alloc_alpha_color(img, img_cfg.dia_border_color);
color headline_c = alloc_alpha_color(img, img_cfg.headline_color); color headline_c = alloc_alpha_color(img, img_cfg.headline_color);
color label_c = alloc_alpha_color(img, img_cfg.label_color); color label_x_c = alloc_alpha_color(img, img_cfg.label_x_color);
color label_xl_c = alloc_alpha_color(img, img_cfg.label_extra_x_color);
color label_y_c = alloc_alpha_color(img, img_cfg.label_y_color);
color desc_x_c = alloc_alpha_color(img, img_cfg.desc_x_color);
color desc_y_c = alloc_alpha_color(img, img_cfg.desc_y_color);
/* Ueberschrift */ /* Ueberschrift */
head_d = calc_text_dim(img_cfg.headline, 16, 0); head_d = calc_text_dim(img_cfg.headline, 16, 0);
@ -128,8 +133,8 @@ static gdImagePtr draw_image(gdImagePtr img){
free(buff); free(buff);
/* Beschriftung y-, x-Achse */ /* Beschriftung y-, x-Achse */
gdImageStringFT(img, &brect[0], headline_c, IMG_FONT, 9, 1.57079, 5 + ((y_desc_d.r_b_x - y_desc_d.r_t_x) / 2), offset_y_top + (dia_height / 2) + ((y_desc_d.l_t_y - y_desc_d.r_t_y) / 2), img_cfg.y_desc); gdImageStringFT(img, &brect[0], desc_y_c, IMG_FONT, 9, 1.57079, 5 + ((y_desc_d.r_b_x - y_desc_d.r_t_x) / 2), offset_y_top + (dia_height / 2) + ((y_desc_d.l_t_y - y_desc_d.r_t_y) / 2), img_cfg.y_desc);
gdImageStringFT(img, &brect[0], headline_c, IMG_FONT, 9, 0 , (offset_x_left + (dia_width / 2)) - (x_desc_d.width / 2), (img_cfg.height - 5) - x_desc_d.l_b_y, img_cfg.x_desc); gdImageStringFT(img, &brect[0], desc_x_c, IMG_FONT, 9, 0 , (offset_x_left + (dia_width / 2)) - (x_desc_d.width / 2), (img_cfg.height - 5) - x_desc_d.l_b_y, img_cfg.x_desc);
/* Werte holen */ /* Werte holen */
pix_list = get_pix_list(dia_width); pix_list = get_pix_list(dia_width);
@ -141,9 +146,9 @@ static gdImagePtr draw_image(gdImagePtr img){
/* horizontale linien + y - Labels */ /* horizontale linien + y - Labels */
y_labels = get_y_label_list(dia_height, dia_y_padding, 0); y_labels = get_y_label_list(dia_height, dia_y_padding, 0);
for (; y_labels; y_labels = y_labels->next){ for (; y_labels; y_labels = y_labels->next){
gdImageLine(img, offset_x_left - 2, offset_y_top + y_labels->pos, img_cfg.width - offset_x_right, offset_y_top + y_labels->pos, diag_grid_c); gdImageLine(img, offset_x_left - 2, offset_y_top + y_labels->pos, img_cfg.width - offset_x_right, offset_y_top + y_labels->pos, diag_grid_x_c);
y_label_d = calc_text_dim(y_labels->text, 7, 0); y_label_d = calc_text_dim(y_labels->text, 7, 0);
gdImageStringFT(img, &brect[0], label_c, IMG_FONT, 7, 0, (offset_x_left - 5 - y_label_max_width) + (y_label_max_width - y_label_d.width), offset_y_top + y_labels->pos + (y_label_d.height / 2), y_labels->text); gdImageStringFT(img, &brect[0], label_y_c, IMG_FONT, 7, 0, (offset_x_left - 5 - y_label_max_width) + (y_label_max_width - y_label_d.width), offset_y_top + y_labels->pos + (y_label_d.height / 2), y_labels->text);
} }
/* y-Werte skalieren */ /* y-Werte skalieren */
@ -152,14 +157,14 @@ static gdImagePtr draw_image(gdImagePtr img){
/* Vertikale linien + x - Labels*/ /* Vertikale linien + x - Labels*/
x_labels = get_x_label_list(dia_width); x_labels = get_x_label_list(dia_width);
for(; x_labels; x_labels = x_labels->next){ for(; x_labels; x_labels = x_labels->next){
gdImageLine(img, offset_x_left + x_labels->pos, offset_y_top, offset_x_left + x_labels->pos, img_cfg.height - offset_y_bottom + 2, diag_grid_c); gdImageLine(img, offset_x_left + x_labels->pos, offset_y_top, offset_x_left + x_labels->pos, img_cfg.height - offset_y_bottom + 2, diag_grid_y_c);
x_label_d = calc_text_dim(x_labels->text, 7, 1.0); x_label_d = calc_text_dim(x_labels->text, 7, 1.0);
gdImageStringFT(img, &brect[0], headline_c, IMG_FONT, 7, 1.0, (offset_x_left + x_labels->pos) - ( x_label_d.r_t_x + ((x_label_d.r_b_x - x_label_d.r_t_x) / 2)), (img_cfg.height - offset_y_bottom + 5) - (x_label_d.r_t_y), x_labels->text); gdImageStringFT(img, &brect[0], label_x_c, IMG_FONT, 7, 1.0, (offset_x_left + x_labels->pos) - ( x_label_d.r_t_x + ((x_label_d.r_b_x - x_label_d.r_t_x) / 2)), (img_cfg.height - offset_y_bottom + 5) - (x_label_d.r_t_y), x_labels->text);
} }
x_label_d = calc_text_dim(get_min_time(), 8, 1.0); x_label_d = calc_text_dim(get_min_time(), 8, 1.0);
gdImageStringFT(img, &brect[0], headline_c, IMG_FONT, 8, 1.0, (offset_x_left ) - ( x_label_d.r_t_x + ((x_label_d.r_b_x - x_label_d.r_t_x) / 2)), (img_cfg.height - offset_y_bottom + 5) - (x_label_d.r_t_y), get_min_time() ); gdImageStringFT(img, &brect[0], label_xl_c, IMG_FONT, 8, 1.0, (offset_x_left ) - ( x_label_d.r_t_x + ((x_label_d.r_b_x - x_label_d.r_t_x) / 2)), (img_cfg.height - offset_y_bottom + 5) - (x_label_d.r_t_y), get_min_time() );
x_label_d = calc_text_dim(get_max_time(), 8, 1.0); x_label_d = calc_text_dim(get_max_time(), 8, 1.0);
gdImageStringFT(img, &brect[0], headline_c, IMG_FONT, 8, 1.0, (offset_x_left + dia_width) - ( x_label_d.r_t_x + ((x_label_d.r_b_x - x_label_d.r_t_x) / 2)), (img_cfg.height - offset_y_bottom + 5) - (x_label_d.r_t_y), get_max_time() ); gdImageStringFT(img, &brect[0], label_xl_c, IMG_FONT, 8, 1.0, (offset_x_left + dia_width) - ( x_label_d.r_t_x + ((x_label_d.r_b_x - x_label_d.r_t_x) / 2)), (img_cfg.height - offset_y_bottom + 5) - (x_label_d.r_t_y), get_max_time() );
/* Nullinie */ /* Nullinie */
if (zero_line != -1) if (zero_line != -1)

View File

@ -1,25 +1,36 @@
filename /home/jan/Testbild.png filename /home/jan/Testbild.png
headline Testbild bla headline Temparatur - Innensensor
manual_table no manual_table no
manual_table_name auss2_data manual_table_name auss2_data
table_field temp table_field temp
#table_field press
gen_interval 1 gen_interval 1
show_interval 30d show_interval 10d
label_interval 1d label_interval 1d
label_sum no label_sum no
width 800 width 800
height 300 height 300
sensor_id 1 ensor_id 1
value_koeffizient 0.1 value_koeffizient 0.1
#value_koeffizient 1.0
unit °C unit °C
x_axis_desc Zeit x_axis_desc Zeit
y_axis_desc Temparatur (°C) y_axis_desc Temparatur (°C)
x_format %d.%m.%y
x_format_extra %d.%m.%y| %H:%M
bg_color DF:DF:EF:00 #test
dia_bg_color F0:A0:D0:D0 #test
zero_line_color BF:80:80:40 #test bg_color DF:DF:EF:00
dia_line_color 60:30:50:30 #test dia_bg_color F0:A0:D0:D0
dia_grid_color 60:60:60:EF #test zero_line_color BF:80:80:40
dia_border_color a0:a0:a0:af #test dia_line_color 60:30:50:30
label_color 10:10:10:00 #test dia_grid_x_color 60:60:60:EF
headline_color 80:10:10:30 #test dia_grid_y_color 60:60:60:EF
dia_border_color a0:a0:a0:af
headline_color 80:10:10:30
label_x_color 60:60:60:30
label_extra_x_color 60:10:10:20
label_y_color 20:20:20:20
descr_y_color 10:50:10:20
descr_x_color 10:10:50:20