Working on chart
git-svn-id: file:///home/jan/tmp/wetterstation/trunk@89 dd492736-c11a-0410-ad51-8c26713eaf7f
This commit is contained in:
parent
81d8b26522
commit
2663b272f2
|
|
@ -3,7 +3,7 @@ LD = gcc
|
|||
RM = rm
|
||||
CFLAGS = -c
|
||||
LDFLAS = -o
|
||||
LD_LIBS = -lefence -lm -lpq -lgd -lpng -lz -lfreetype
|
||||
LD_LIBS = -lm -lpq -lgd -lpng -lz -lfreetype
|
||||
#INCL = -I$$(pg_config --includedir)
|
||||
|
||||
BIN_NAME = chart
|
||||
|
|
@ -37,11 +37,14 @@ chart.o: chart.c \
|
|||
common.h \
|
||||
image_file/image_file.h
|
||||
common.o: common.c \
|
||||
common.h
|
||||
common.h \
|
||||
definitions.h
|
||||
config.o: config.c \
|
||||
config.h \
|
||||
definitions.h \
|
||||
common.h
|
||||
image_file/image_common.o: image_file/image_common.c \
|
||||
image_file/image_common.h
|
||||
image_file/image_config.o: image_file/image_config.c \
|
||||
common.h \
|
||||
definitions.h \
|
||||
|
|
@ -54,7 +57,8 @@ image_file/image_data.o: image_file/image_data.c \
|
|||
definitions.h
|
||||
image_file/image_draw.o: image_file/image_draw.c \
|
||||
image_file/image_draw.h \
|
||||
image_file/image_data.h
|
||||
image_file/image_data.h \
|
||||
image_file/image_common.h
|
||||
image_file/image_file.o: image_file/image_file.c \
|
||||
definitions.h \
|
||||
common.h \
|
||||
|
|
@ -62,8 +66,6 @@ image_file/image_file.o: image_file/image_file.c \
|
|||
image_file/image_file.h \
|
||||
image_file/image_config.h \
|
||||
image_file/image_draw.h
|
||||
image_file/image_common.o: image_file/image_common.c \
|
||||
image_file/image_common.h
|
||||
|
||||
# Compillieren
|
||||
$(OBJS):
|
||||
|
|
|
|||
|
|
@ -1,5 +1,5 @@
|
|||
#fork yes
|
||||
fork no
|
||||
fork yes
|
||||
#fork no
|
||||
image_cfg_location image_file/
|
||||
|
||||
image_cfg testimage.conf
|
||||
|
|
|
|||
|
|
@ -7,19 +7,29 @@ typedef struct img_color {
|
|||
} img_color_t;
|
||||
|
||||
typedef struct image_cfg {
|
||||
char *file_name;
|
||||
char *headline;
|
||||
char *table_field;
|
||||
int manual_table;
|
||||
char *table_name;
|
||||
long gen_interval;
|
||||
long show_interval;
|
||||
long label_interval;
|
||||
int label_sum;
|
||||
int width;
|
||||
int height;
|
||||
int sens_id;
|
||||
char *file_name;
|
||||
char *headline;
|
||||
char *table_field;
|
||||
int manual_table;
|
||||
char *table_name;
|
||||
long gen_interval;
|
||||
long show_interval;
|
||||
long label_interval;
|
||||
int label_sum;
|
||||
int width;
|
||||
int height;
|
||||
int sens_id;
|
||||
double val_koeff;
|
||||
|
||||
img_color_ptr bg_color;
|
||||
img_color_ptr dia_bg_color;
|
||||
img_color_ptr dia_line_color;
|
||||
img_color_ptr dia_grid_color;
|
||||
img_color_ptr dia_border_color;
|
||||
img_color_ptr zero_line_color;
|
||||
|
||||
|
||||
|
||||
} image_cfg_t;
|
||||
|
||||
extern image_cfg_t img_cfg;
|
||||
|
|
|
|||
|
|
@ -29,6 +29,7 @@
|
|||
|
||||
static int read_time(const char *, void *);
|
||||
static int read_color(const char *, void *);
|
||||
static int read_double(const char *, void *);
|
||||
|
||||
|
||||
|
||||
|
|
@ -48,14 +49,25 @@ static const config_keyword keywords[] = {
|
|||
{"width", read_int, &(img_cfg.width), ""},
|
||||
{"height", read_int, &(img_cfg.height), ""},
|
||||
{"sensor_id", read_int, &(img_cfg.sens_id), ""},
|
||||
{"value_koeffizient", read_double, &(img_cfg.val_koeff), ""},
|
||||
|
||||
|
||||
{"bg_color", read_color, &(img_cfg.bg_color), ""},
|
||||
{"dia_bg_color", read_color, &(img_cfg.dia_bg_color), ""},
|
||||
{"dia_line_color", read_color, &(img_cfg.dia_line_color), ""},
|
||||
{"dia_grid_color", read_color, &(img_cfg.dia_grid_color), ""},
|
||||
{"dia_border_color", read_color, &(img_cfg.dia_border_color), ""},
|
||||
{"zero_line_color", read_color, &(img_cfg.zero_line_color), ""},
|
||||
|
||||
{"", NULL, NULL, ""}
|
||||
};
|
||||
|
||||
|
||||
static int read_double(const char *line, void *arg){
|
||||
double *dest = arg;
|
||||
*dest = atof(line);
|
||||
return 1;
|
||||
}
|
||||
|
||||
static int read_color(const char *line, void *arg){
|
||||
img_color_ptr *col = arg;
|
||||
|
|
|
|||
|
|
@ -15,6 +15,7 @@
|
|||
|
||||
static pix_list_ptr min = NULL;
|
||||
static pix_list_ptr max = NULL;
|
||||
static long base_time; /* Zeit an der 0-Koordinate (lt. Datenbank!) */
|
||||
|
||||
|
||||
static pix_list_ptr add_pix_value(pix_list_ptr , long, int , int );
|
||||
|
|
@ -24,13 +25,42 @@ static PGresult *pg_check_exec(PGconn *, char *);
|
|||
static char *get_type_table_by_id(PGconn *, int );
|
||||
|
||||
|
||||
/* Baut die Liste mit den Labels an der X-Achse */
|
||||
label_list_ptr get_x_label_list(int c_width){
|
||||
double factor = ((double)img_cfg.label_interval) * ( ((double)c_width) / ((double)img_cfg.show_interval) );
|
||||
int num = floor( ((double)img_cfg.show_interval) / ((double)img_cfg.label_interval) );
|
||||
int i;
|
||||
label_list_ptr ptr = NULL;
|
||||
label_list_ptr new_ptr = NULL;
|
||||
label_list_ptr temp_ptr = NULL;
|
||||
|
||||
for ( i = 1; i < num; i++ ) {
|
||||
new_ptr = malloc(sizeof(label_list_t));
|
||||
new_ptr->pos = floor( ((double)i) * factor);
|
||||
new_ptr->timestamp = base_time + (i * img_cfg.label_interval);
|
||||
new_ptr->text = "NOT YET IMPLEMENTED";
|
||||
new_ptr->next = NULL;
|
||||
|
||||
if (ptr != NULL){
|
||||
temp_ptr->next = new_ptr;
|
||||
temp_ptr = temp_ptr->next;
|
||||
} else {
|
||||
ptr = new_ptr;
|
||||
temp_ptr = new_ptr;
|
||||
}
|
||||
}
|
||||
|
||||
return ptr;
|
||||
}
|
||||
|
||||
|
||||
/* Skaliert die X-Koordinaten der Punkte im angegebenem Bereich
|
||||
* ausführliche Beschreibung im header-file */
|
||||
int scale_y_coords(pix_list_ptr ptr, int c_height, int max_label, int min_label){
|
||||
int range = (max_label - min_label + 1) * 10; /* Anzahl von 0,1-Schritten */
|
||||
int range = (max_label - min_label + 1) ; /* Anzahl von 0,1-Schritten */
|
||||
double pix_per_scale = ((double)c_height) / ((double)range); /* Pixel pro 0,1 */
|
||||
pix_list_ptr temp = ptr;
|
||||
int zero_line = floor( ((double)( (max_label * 10) + 1)) * pix_per_scale); /* Nullinie */
|
||||
int zero_line = floor( ((double)(max_label + 1)) * pix_per_scale); /* Nullinie */
|
||||
|
||||
DEBUGOUT1("\nBerechne y-Koordinaten:\n");
|
||||
|
||||
|
|
@ -67,7 +97,6 @@ pix_list_ptr get_pix_list(int c_width){
|
|||
long time_temp; /* Hilfsvariable */
|
||||
int pix_coord; /* x - Koordinate, an die der Wert gehört */
|
||||
int i; /* Laufvariable zum durchlaufen des Datenbank-resuls */
|
||||
long base_time; /* Zeit an der 0-Koordinate (lt. Datenbank!) */
|
||||
long timestamp;
|
||||
pix_list_ptr list_ptr = NULL; /* Zeiger auf den Anfang der Wertliste */
|
||||
pix_list_ptr temp_ptr = NULL; /* Zeiger zum durchlaufen der Wertliste */
|
||||
|
|
@ -141,7 +170,6 @@ static pix_list_ptr add_pix_value(pix_list_ptr ptr, long timestamp, int coord, i
|
|||
DEBUGOUT1("\nLese Daten ein:\n");
|
||||
ptr = malloc(sizeof(pix_list_t));
|
||||
ptr->next = NULL;
|
||||
ptr->timestamp = timestamp;
|
||||
ptr->x_pix_coord = coord;
|
||||
ptr->y_pix_coord = 0;
|
||||
ptr->value_count = 1;
|
||||
|
|
@ -157,7 +185,6 @@ static pix_list_ptr add_pix_value(pix_list_ptr ptr, long timestamp, int coord, i
|
|||
} else {
|
||||
ptr->next = malloc(sizeof(pix_list_t));
|
||||
ptr = ptr->next;
|
||||
ptr->timestamp = timestamp;
|
||||
ptr->x_pix_coord = coord;
|
||||
ptr->y_pix_coord = 0;
|
||||
ptr->value_sum = value;
|
||||
|
|
|
|||
|
|
@ -8,20 +8,33 @@ typedef struct pix_list {
|
|||
int y_pix_coord;
|
||||
int value_count;
|
||||
int value_sum;
|
||||
long timestamp;
|
||||
} pix_list_t;
|
||||
|
||||
typedef struct label_list *label_list_ptr;
|
||||
typedef struct label_list {
|
||||
int pos;
|
||||
long timestamp;
|
||||
char *text;
|
||||
label_list_ptr next;
|
||||
} label_list_t;
|
||||
|
||||
|
||||
|
||||
/* Holt die Liste mit den Daten fuer das Bild.
|
||||
* 1. Argument: die effektive Breite des Bereiches in dem gezeichnet werden soll
|
||||
* Rueckgabe: die liste mit den Werten
|
||||
*/
|
||||
pix_list_ptr get_pix_list(int );
|
||||
|
||||
|
||||
/* Max. Wert */
|
||||
pix_list_ptr get_min();
|
||||
|
||||
|
||||
/* Min. Wert */
|
||||
pix_list_ptr get_max();
|
||||
|
||||
|
||||
/* Skaliert die X-Koordinaten der Punkte im angegebenem Bereich
|
||||
* 1. Argument: die Pix-Liste die skaliert werden soll
|
||||
* 2. Argument: die anzahl der Pixel in y-Richtung
|
||||
|
|
@ -30,3 +43,10 @@ pix_list_ptr get_max();
|
|||
* Rueckgabe: Position der 0-Linie von oben aus
|
||||
*/
|
||||
int scale_y_coords(pix_list_ptr , int , int , int );
|
||||
|
||||
|
||||
/* Baut die Liste mit den Labels an der X-Achse
|
||||
* 1. Argument: Breite des bildes
|
||||
* Rueckgabe: List mit den Labels
|
||||
*/
|
||||
label_list_ptr get_x_label_list(int c_width);
|
||||
|
|
|
|||
|
|
@ -10,6 +10,7 @@ typedef int color;
|
|||
|
||||
static gdImagePtr create_image();
|
||||
static gdImagePtr draw_image(gdImagePtr);
|
||||
static color alloc_alpha_color(gdImagePtr , img_color_ptr );
|
||||
static void write_image_png(gdImagePtr, FILE *);
|
||||
|
||||
/* Baut ein Bild und schreibt es in die Datei */
|
||||
|
|
@ -23,11 +24,10 @@ int draw_to_file(FILE *fd){
|
|||
static gdImagePtr create_image(){
|
||||
gdImagePtr new_img = NULL;
|
||||
color back;
|
||||
img_color_ptr back_p = img_cfg.bg_color;
|
||||
|
||||
new_img = gdImageCreateTrueColor(img_cfg.width, img_cfg.height);
|
||||
gdImageAlphaBlending(new_img, 0);
|
||||
back = gdImageColorAllocateAlpha( new_img, back_p->r, back_p->g, back_p->b, back_p->alpha );
|
||||
back = alloc_alpha_color(new_img, img_cfg.bg_color);
|
||||
gdImageFilledRectangle(new_img, 0,0,img_cfg.width, img_cfg.height, back);
|
||||
gdImageAlphaBlending(new_img, 1);
|
||||
|
||||
|
|
@ -36,28 +36,47 @@ static gdImagePtr create_image(){
|
|||
|
||||
/* Baut das Bild */
|
||||
static gdImagePtr draw_image(gdImagePtr img){
|
||||
pix_list_ptr pix_list = NULL;
|
||||
pix_list_ptr pix_list = NULL;
|
||||
label_list_ptr x_labels = NULL;
|
||||
label_list_ptr y_labels = NULL;
|
||||
|
||||
int max_val = 0;
|
||||
int min_val = 0;
|
||||
int offset_x_left = 0;
|
||||
int offset_y_top = 0;
|
||||
int offset_x_right = 0;
|
||||
int offset_y_bottom = 0;
|
||||
int offset_x_left = 20;
|
||||
int offset_y_top = 20;
|
||||
int offset_x_right = 20;
|
||||
int offset_y_bottom = 20;
|
||||
int dia_width = img_cfg.width - offset_x_left - offset_x_right;
|
||||
int dia_height = img_cfg.height - offset_y_top - offset_y_bottom;
|
||||
int zero_line = 0;
|
||||
|
||||
color val_line_c = gdImageColorAllocateAlpha(img, 0,0,0,0);
|
||||
color zero_line_c = gdImageColorAllocateAlpha(img, 0,0,0,0);
|
||||
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 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);
|
||||
|
||||
/* Werte holen */
|
||||
pix_list = get_pix_list(dia_width);
|
||||
|
||||
/* y-Werte skalieren */
|
||||
zero_line = scale_y_coords(pix_list, dia_height, 40, -10);
|
||||
zero_line = scale_y_coords(pix_list, dia_height, 400, -100);
|
||||
|
||||
|
||||
x_labels = get_x_label_list(dia_width);
|
||||
|
||||
|
||||
/* Diagramhintergrund */
|
||||
gdImageFilledRectangle(img, offset_x_left, offset_y_top, img_cfg.width - offset_x_right, img_cfg.height - offset_y_bottom, dia_bg_c);
|
||||
|
||||
/* Vertikale linien + x - Labels*/
|
||||
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, diag_grid_c);
|
||||
}
|
||||
|
||||
/* Nullinie */
|
||||
gdImageLine(img, offset_x_left, zero_line + offset_y_top, img_cfg.width - offset_x_right, zero_line + offset_y_top, zero_line_c);
|
||||
|
||||
|
||||
/* Werte Zeichnen */
|
||||
for (; pix_list->next; pix_list = pix_list->next){
|
||||
gdImageLine(img, (offset_x_left + pix_list->x_pix_coord), (zero_line + offset_y_top + pix_list->y_pix_coord), (offset_x_left + pix_list->next->x_pix_coord), (zero_line + offset_y_top + pix_list->next->y_pix_coord), val_line_c);
|
||||
|
|
@ -69,6 +88,11 @@ static gdImagePtr draw_image(gdImagePtr img){
|
|||
|
||||
|
||||
|
||||
/* Eine Farbe mit alphawert holen */
|
||||
static color alloc_alpha_color(gdImagePtr img, img_color_ptr ptr){
|
||||
return gdImageColorAllocateAlpha(img, ptr->r, ptr->g, ptr->b, ptr->alpha);
|
||||
}
|
||||
|
||||
/* Schreibt das Bild in eine Datei */
|
||||
static void write_image_png(gdImagePtr img, FILE *fd){
|
||||
gdImageAlphaBlending(img, 0);
|
||||
|
|
|
|||
|
|
@ -4,11 +4,19 @@ manual_table no
|
|||
manual_table_name auss2_data
|
||||
table_field temp
|
||||
gen_interval 15
|
||||
show_interval 30d
|
||||
label_interval 10m
|
||||
show_interval 10d
|
||||
label_interval 1d
|
||||
label_sum no
|
||||
width 400
|
||||
width 800
|
||||
height 250
|
||||
sensor_id 1
|
||||
value_koeffizient 0.1
|
||||
|
||||
bg_color 60:30:50:af #test
|
||||
bg_color DF:DF:EF:00 #test
|
||||
dia_bg_color F0:A0:D0:D0 #test
|
||||
zero_line_color BF:80:80:40 #test
|
||||
dia_line_color 60:30:50:30 #test
|
||||
dia_grid_color 00:00:00:EF #test
|
||||
dia_border_color 60:30:50:af #test
|
||||
#dia_color 60:30:50:af #test
|
||||
#dia_color 60:30:50:af #test
|
||||
|
|
|
|||
Loading…
Reference in New Issue