Y-Labels are ready


git-svn-id: file:///home/jan/tmp/wetterstation/trunk@95 dd492736-c11a-0410-ad51-8c26713eaf7f
This commit is contained in:
losinshi 2006-09-14 22:21:05 +00:00
parent a339e7ea29
commit 903e9c69ed
5 changed files with 52 additions and 21 deletions

View File

@ -18,6 +18,7 @@ typedef struct image_cfg {
int label_sum;
int width;
int height;
char *unit;
int sens_id;
double val_koeff;

View File

@ -48,6 +48,7 @@ static const config_keyword keywords[] = {
{"label_sum", read_yn, &(img_cfg.label_sum), ""},
{"width", read_int, &(img_cfg.width), ""},
{"height", read_int, &(img_cfg.height), ""},
{"unit", read_str, &(img_cfg.unit), ""},
{"sensor_id", read_int, &(img_cfg.sens_id), ""},
{"value_koeffizient", read_double, &(img_cfg.val_koeff), ""},

View File

@ -27,7 +27,7 @@ static PGresult *pg_check_exec(PGconn *, char *);
static char *get_type_table_by_id(PGconn *, int );
/* Bibt die Liste mit den y-Labels zurueck */
label_list_ptr get_y_label_list(int c_hight, int padding, int zero_min){
int max_val = ceil( ( ((double)max->value_sum) / ((double)max->value_count) ) * img_cfg.val_koeff);
int min_val = floor( ( ((double)min->value_sum) / ((double)min->value_count) ) * img_cfg.val_koeff);
@ -37,8 +37,9 @@ label_list_ptr get_y_label_list(int c_hight, int padding, int zero_min){
double padd_val = 0;
int temp = 0;
double koeff = 1;
int interval = 0;
double interval = 0;
int num = 0;
int max_num = 0;
int i;
int new_val = 0;
char * buff = NULL;
@ -63,26 +64,34 @@ label_list_ptr get_y_label_list(int c_hight, int padding, int zero_min){
real_max = max_val + padd_val;
real_diff = real_max - real_min;
DEBUGOUT4(" Realer Max. Wert: %3.3f, Realer Min. Wert: %3.3f (inkl. Koeffizient: %3.3f)\n", real_max, real_min, img_cfg.val_koeff);
DEBUGOUT5(" Realer Max. Wert: %3.3f, Realer Min. Wert: %3.3f Differenz: %3.3f (inkl. Koeffizient: %3.3f)\n", real_max, real_min, real_diff, img_cfg.val_koeff);
temp = floor( ((double)diff) * 0.1);
while (temp >= 10) {
koeff = koeff * 0.1;
temp = floor(koeff * ((double)temp));
/* Interval der Labels berechnen */
temp = floor( real_diff );
interval = 1;
max_num = floor(c_hight / 20);
while ((num = floor( temp / interval )) > max_num){
interval++;
}
interval = temp / koeff;
num = floor( real_diff / interval );
DEBUGOUT2(" Interval: %d \n", interval);
DEBUGOUT2(" Interval: %f \n", interval);
/* An Labels auf die 0 'eichen' */
temp = ceil(real_min);
while (fmod(((double)temp), ((double)interval)) != 0){
temp++;
}
buff = malloc(sizeof(char)*BUFFSIZE);
for (i = 0; i < num; i++){
new_val = temp + (i * interval);
snprintf(buff, BUFFSIZE, "%d", new_val);
if(img_cfg.unit != NULL){
snprintf(buff, BUFFSIZE, "%d%s", new_val, img_cfg.unit);
} else {
snprintf(buff, BUFFSIZE, "%d", new_val);
}
new_ptr = malloc(sizeof(label_list_t));
new_ptr->pos = floor( (real_max - ((double)new_val) ) * factor);

View File

@ -1,10 +1,12 @@
#include <stdio.h>
#include <stdlib.h>
#include <gd.h>
#include "../definitions.h"
#include "image_draw.h"
#include "image_data.h"
#include "image_common.h"
#define SHORTBUFFSIZE 64
typedef int color;
typedef struct dimension {
@ -58,15 +60,18 @@ static gdImagePtr draw_image(gdImagePtr img){
int max_val = 0;
int min_val = 0;
int offset_x_left = 60;
int offset_x_left = 10;
int offset_y_top = 5;
int offset_x_right = 20;
int offset_y_bottom = 80;
int dia_width = img_cfg.width - offset_x_left - offset_x_right;
int dia_width = 0;
int dia_height = 0;
int zero_line = 0;
int dia_y_padding = 10;
int brect[8];
int y_label_max_width = 0;
char *buff;
dimension_t head_d;
dimension_t y_label_d;
@ -78,6 +83,19 @@ static gdImagePtr draw_image(gdImagePtr img){
color diag_grid_c = alloc_alpha_color(img, img_cfg.dia_grid_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 label_c = alloc_alpha_color(img, img_cfg.label_color);
if(img_cfg.unit != NULL){
buff = malloc(sizeof(char)*SHORTBUFFSIZE);
snprintf(buff, SHORTBUFFSIZE, "99999%s", img_cfg.unit);
y_label_d = calc_text_dim(buff, 7, 0);
free(buff);
} else {
y_label_d = calc_text_dim("99999", 7, 0);
}
y_label_max_width = y_label_d.width;
offset_x_left = offset_x_left + y_label_max_width +5;
dia_width = img_cfg.width - offset_x_left - offset_x_right;
/* Ueberschrift */
@ -86,7 +104,6 @@ static gdImagePtr draw_image(gdImagePtr img){
offset_y_top = (offset_y_top * 2) + head_d.height;
dia_height = img_cfg.height - offset_y_top - offset_y_bottom;
/* Werte holen */
@ -96,10 +113,12 @@ static gdImagePtr draw_image(gdImagePtr img){
gdImageFilledRectangle(img, offset_x_left, offset_y_top, img_cfg.width - offset_x_right, img_cfg.height - offset_y_bottom, dia_bg_c);
/* horizontale linien + y - Labels */
y_labels = get_y_label_list(dia_height, dia_y_padding, 0);
/* horizontale linien + y - Labels */
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);
y_label_d = calc_text_dim(y_labels->text, 7, 0);
gdImageStringTTF(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);
}
/* y-Werte skalieren */

View File

@ -8,9 +8,10 @@ show_interval 10d
label_interval 1d
label_sum no
width 800
height 400
height 300
sensor_id 1
value_koeffizient 0.1
unit °
bg_color DF:DF:EF:00 #test
dia_bg_color F0:A0:D0:D0 #test
@ -18,5 +19,5 @@ zero_line_color BF:80:80:40 #test
dia_line_color 60:30:50:30 #test
dia_grid_color 60:60:60:EF #test
dia_border_color a0:a0:a0:af #test
label_color 60:30:50:af #test
headline_color 50:10:10:30 #test
label_color 10:10:10:00 #test
headline_color 80:10:10:30 #test