chart now draws no line if there are no values

git-svn-id: file:///home/jan/tmp/wetterstation/trunk@124 dd492736-c11a-0410-ad51-8c26713eaf7f
This commit is contained in:
losinshi 2006-09-21 18:22:41 +00:00
parent abbb81160a
commit add89ffdeb
4 changed files with 29 additions and 11 deletions

View File

@ -1,5 +1,5 @@
# yes, wenn jedes Bild in einem Extra Prozess behandelt werden soll
fork yes
fork no #yes
# Verzeichnis, in dem die config-Files liegen
image_cfg_location image_conf/
@ -10,11 +10,11 @@ dflt_image_location /home/jan/Webs/wetter/images/chart/
# Bilder-Configs
# Jedes Config-File representiert ein zu generierendes Bild
#image_cfg testimage.conf
image_cfg hum_ex.conf
image_cfg press_ex.conf
#image_cfg hum_ex.conf
#image_cfg press_ex.conf
image_cfg rain_ex.conf
image_cfg temp_ex.conf
image_cfg wind_ex.conf
#image_cfg temp_ex.conf
#image_cfg wind_ex.conf
# Postgres-Einstellungen
pg_host 141.30.228.39

View File

@ -43,7 +43,7 @@ static long base_time; /* Zeit an der 0-Koordinate (lt. Datenbank!) */
/* Funktionsdefinitionen */
static pix_list_ptr add_pix_value(pix_list_ptr , long, int , int );
static pix_list_ptr add_pix_value(pix_list_ptr , long, int , int, int );
static char *get_conn_string();
static PGconn *pg_check_connect(char *);
static PGresult *pg_check_exec(PGconn *, char *);
@ -297,6 +297,7 @@ pix_list_ptr get_pix_list(int c_width){
int pix_coord; /* x - Koordinate, an die der Wert gehoert */
int i, s, t, u; /* Laufvariable zum durchlaufen des Datenbank-resuls */
long timestamp;
int max_diff;
pix_list_ptr list_ptr = NULL; /* Zeiger auf den Anfang der Wertliste */
pix_list_ptr temp_ptr = NULL; /* Zeiger zum durchlaufen der Wertliste */
@ -327,6 +328,7 @@ pix_list_ptr get_pix_list(int c_width){
base_time = time(NULL);
}
max_diff = ceil(img_cfg.label_interval * seconds_per_pix);
/* Ergebnisse durchlaufen */
for (i = 0; i < PQntuples(res); i++){
@ -345,7 +347,7 @@ pix_list_ptr get_pix_list(int c_width){
pix_coord = floor( ((double)time_temp) * seconds_per_pix) ;
/* Listenelement generieren */
temp_ptr = add_pix_value(temp_ptr, timestamp, pix_coord, atoi( PQgetvalue(res, i, val_field) ) );
temp_ptr = add_pix_value(temp_ptr, timestamp, pix_coord, atoi( PQgetvalue(res, i, val_field) ) , max_diff);
/* Rueckgabe- und Max/Min-pointer zuweisen */
if (list_ptr == NULL){
@ -369,7 +371,7 @@ pix_list_ptr get_pix_list(int c_width){
time_temp = timestamp;
}
pix_coord = floor( ((double)time_temp) * seconds_per_pix) ;
temp_ptr = add_pix_value(temp_ptr, timestamp, pix_coord, 0 );
temp_ptr = add_pix_value(temp_ptr, timestamp, pix_coord, 0 , max_diff);
list_ptr = temp_ptr;
min = temp_ptr;
max = temp_ptr;
@ -417,7 +419,8 @@ pix_list_ptr get_pix_list(int c_width){
}
/* Speichert einen geholten Wert ab */
static pix_list_ptr add_pix_value(pix_list_ptr ptr, long timestamp, int coord, int value){
static pix_list_ptr add_pix_value(pix_list_ptr ptr, long timestamp, int coord, int value, int max_diff){
int old_coord;
/* Erstes Element */
if(ptr == NULL){
@ -439,6 +442,7 @@ static pix_list_ptr add_pix_value(pix_list_ptr ptr, long timestamp, int coord, i
DEBUGOUT5(" Zu x-pos. %d %d. Wert (%d) hinzugefuegt. Durchschn.: %d\n", ptr->x_pix_coord, ptr->value_count, value, (ptr->value_sum/ptr->value_count) );
} else {
old_coord = ptr->x_pix_coord;
ptr->next = malloc(sizeof(pix_list_t));
ptr = ptr->next;
ptr->x_pix_coord = coord;
@ -447,6 +451,12 @@ static pix_list_ptr add_pix_value(pix_list_ptr ptr, long timestamp, int coord, i
ptr->value_count = 1;
ptr->next = NULL;
if ((coord - old_coord) > max_diff){
ptr->no_line = 1;
} else {
ptr->no_line = 0;
}
DEBUGOUT3(" An x-pos. %d Wert %d eingefuegt\n", ptr->x_pix_coord, ptr->value_sum);
}
}

View File

@ -29,6 +29,7 @@ typedef struct pix_list {
int y_pix_coord; /* Y - Koordinate */
int value_count; /* Anzahl der Werte */
int value_sum; /* Summe der Werte */
int no_line;
} pix_list_t;

View File

@ -202,8 +202,10 @@ static gdImagePtr draw_image(gdImagePtr img){
/* Werte Zeichnen */
if(!img_cfg.bars){
for (; pix_list->next; pix_list = pix_list->next){
if(!pix_list->next->no_line){
gdImageLine(img, (offset_x_left + pix_list->x_pix_coord), (offset_y_top + pix_list->y_pix_coord), (offset_x_left + pix_list->next->x_pix_coord), (offset_y_top + pix_list->next->y_pix_coord), val_line_c);
}
}
} else {
if (zero_line != -1){
temp_y1 = zero_line + offset_y_top;
@ -211,12 +213,17 @@ static gdImagePtr draw_image(gdImagePtr img){
temp_y1 = img_cfg.height - offset_y_bottom;
}
for (; pix_list; pix_list = pix_list->next){
i = 1;
temp_x1 = pix_list->x_pix_coord + offset_x_left;
if (pix_list->next != NULL){
temp_x2 = pix_list->next->x_pix_coord + offset_x_left;
if(pix_list->next->no_line){
i = 0;
}
} else {
temp_x2 = offset_x_left + dia_width;
}
if(i)
gdImageFilledRectangle(img, temp_x1 + 3, (offset_y_top + pix_list->y_pix_coord), temp_x2 - 3 , temp_y1 , val_line_c);
}
}