Working on charts
(vertical scaling of values) git-svn-id: file:///home/jan/tmp/wetterstation/trunk@87 dd492736-c11a-0410-ad51-8c26713eaf7f
This commit is contained in:
parent
6208082794
commit
dc863f8bd6
|
|
@ -24,11 +24,32 @@ static PGresult *pg_check_exec(PGconn *, char *);
|
||||||
static char *get_type_table_by_id(PGconn *, int );
|
static char *get_type_table_by_id(PGconn *, int );
|
||||||
|
|
||||||
|
|
||||||
|
/* 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 */
|
||||||
|
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) * pix_per_scale); /* Nullinie */
|
||||||
|
|
||||||
|
DEBUGOUT1("\nBerechne y-Koordinaten:\n");
|
||||||
|
|
||||||
|
for (; temp; temp = temp->next){
|
||||||
|
temp->y_pix_coord = floor( ( ((double)temp->value_sum) / ((double)temp->value_count) ) * pix_per_scale);
|
||||||
|
DEBUGOUT3(" neue y-Koordinate: %d bei x: %d\n",temp->y_pix_coord, temp->x_pix_coord);
|
||||||
|
}
|
||||||
|
|
||||||
|
DEBUGOUT2(" Nullinie bei: %d\n", zero_line);
|
||||||
|
|
||||||
|
return zero_line;
|
||||||
|
}
|
||||||
|
|
||||||
|
/* Maximaler wert */
|
||||||
pix_list_ptr get_max(){
|
pix_list_ptr get_max(){
|
||||||
return min;
|
return min;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/* Minimaler Wert */
|
||||||
pix_list_ptr get_min(){
|
pix_list_ptr get_min(){
|
||||||
return max;
|
return max;
|
||||||
}
|
}
|
||||||
|
|
@ -73,9 +94,16 @@ pix_list_ptr get_pix_list(int c_width){
|
||||||
pix_coord = floor( ((double)time_temp) * seconds_per_pix) ;
|
pix_coord = floor( ((double)time_temp) * seconds_per_pix) ;
|
||||||
temp_ptr = add_pix_value(temp_ptr, pix_coord, atoi( PQgetvalue(res, i, val_field) ) );
|
temp_ptr = add_pix_value(temp_ptr, pix_coord, atoi( PQgetvalue(res, i, val_field) ) );
|
||||||
|
|
||||||
if (list_ptr == NULL)
|
if (list_ptr == NULL){
|
||||||
list_ptr = temp_ptr;
|
list_ptr = temp_ptr;
|
||||||
|
|
||||||
|
/* Globale Variablen neu initialisieren um
|
||||||
|
* mehtete Bilder in einem Thread bauen zu
|
||||||
|
* können */
|
||||||
|
min = temp_ptr;
|
||||||
|
max = temp_ptr;
|
||||||
|
}
|
||||||
|
|
||||||
/* Min / Max ermitteln */
|
/* Min / Max ermitteln */
|
||||||
if (min != NULL){
|
if (min != NULL){
|
||||||
if ( (temp_ptr->value_sum / temp_ptr->value_count) < (min->value_sum / min->value_count) )
|
if ( (temp_ptr->value_sum / temp_ptr->value_count) < (min->value_sum / min->value_count) )
|
||||||
|
|
@ -112,6 +140,7 @@ static pix_list_ptr add_pix_value(pix_list_ptr ptr, int coord, int value){
|
||||||
ptr = malloc(sizeof(pix_list_t));
|
ptr = malloc(sizeof(pix_list_t));
|
||||||
ptr->next = NULL;
|
ptr->next = NULL;
|
||||||
ptr->x_pix_coord = 0;
|
ptr->x_pix_coord = 0;
|
||||||
|
ptr->y_pix_coord = 0;
|
||||||
ptr->value_count = 0;
|
ptr->value_count = 0;
|
||||||
ptr->value_sum = 0;
|
ptr->value_sum = 0;
|
||||||
DEBUGOUT1(" Erstes Element generiert...\n");
|
DEBUGOUT1(" Erstes Element generiert...\n");
|
||||||
|
|
@ -126,6 +155,7 @@ static pix_list_ptr add_pix_value(pix_list_ptr ptr, int coord, int value){
|
||||||
ptr->next = malloc(sizeof(pix_list_t));
|
ptr->next = malloc(sizeof(pix_list_t));
|
||||||
ptr = ptr->next;
|
ptr = ptr->next;
|
||||||
ptr->x_pix_coord = coord;
|
ptr->x_pix_coord = coord;
|
||||||
|
ptr->y_pix_coord = coord;
|
||||||
ptr->value_sum = value;
|
ptr->value_sum = value;
|
||||||
ptr->value_count = 1;
|
ptr->value_count = 1;
|
||||||
ptr->next = NULL;
|
ptr->next = NULL;
|
||||||
|
|
|
||||||
|
|
@ -5,6 +5,7 @@ typedef struct pix_list *pix_list_ptr;
|
||||||
typedef struct pix_list {
|
typedef struct pix_list {
|
||||||
pix_list_ptr next;
|
pix_list_ptr next;
|
||||||
int x_pix_coord;
|
int x_pix_coord;
|
||||||
|
int y_pix_coord;
|
||||||
int value_count;
|
int value_count;
|
||||||
int value_sum;
|
int value_sum;
|
||||||
} pix_list_t;
|
} pix_list_t;
|
||||||
|
|
@ -19,3 +20,12 @@ pix_list_ptr get_pix_list(int );
|
||||||
pix_list_ptr get_min();
|
pix_list_ptr get_min();
|
||||||
|
|
||||||
pix_list_ptr get_max();
|
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
|
||||||
|
* 3. Argument: max. Wert
|
||||||
|
* 4. Argument: min. Wert
|
||||||
|
* Rueckgabe: Position der 0-Linie von oben aus
|
||||||
|
*/
|
||||||
|
int scale_y_coords(pix_list_ptr , int , int , int );
|
||||||
|
|
|
||||||
|
|
@ -9,13 +9,13 @@ typedef int color;
|
||||||
|
|
||||||
|
|
||||||
static gdImagePtr create_image();
|
static gdImagePtr create_image();
|
||||||
static void draw_image();
|
static gdImagePtr draw_image(gdImagePtr);
|
||||||
static void write_image_png(gdImagePtr, FILE *);
|
static void write_image_png(gdImagePtr, FILE *);
|
||||||
|
|
||||||
|
|
||||||
int draw_to_file(FILE *fd){
|
int draw_to_file(FILE *fd){
|
||||||
gdImagePtr img = create_image();
|
gdImagePtr img = create_image();
|
||||||
draw_image();
|
draw_image(img);
|
||||||
write_image_png(img, fd);
|
write_image_png(img, fd);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -33,9 +33,9 @@ static gdImagePtr create_image(){
|
||||||
return new_img;
|
return new_img;
|
||||||
}
|
}
|
||||||
|
|
||||||
static void draw_image(){
|
static gdImagePtr draw_image(gdImagePtr img){
|
||||||
pix_list_ptr pix_list = get_pix_list(300);
|
pix_list_ptr pix_list = get_pix_list(300);
|
||||||
|
scale_y_coords(pix_list, 100, 40, -10);
|
||||||
}
|
}
|
||||||
|
|
||||||
static void write_image_png(gdImagePtr img, FILE *fd){
|
static void write_image_png(gdImagePtr img, FILE *fd){
|
||||||
|
|
@ -43,3 +43,5 @@ static void write_image_png(gdImagePtr img, FILE *fd){
|
||||||
gdImageSaveAlpha(img, 1);
|
gdImageSaveAlpha(img, 1);
|
||||||
gdImagePng(img, fd);
|
gdImagePng(img, fd);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue