chart shows beautyful float-charts with grid and labels
git-svn-id: file:///home/jan/tmp/wetterstation/trunk@96 dd492736-c11a-0410-ad51-8c26713eaf7f
This commit is contained in:
parent
903e9c69ed
commit
8a307c332c
|
|
@ -19,6 +19,8 @@ typedef struct image_cfg {
|
|||
int width;
|
||||
int height;
|
||||
char *unit;
|
||||
char *x_desc;
|
||||
char *y_desc;
|
||||
int sens_id;
|
||||
double val_koeff;
|
||||
|
||||
|
|
|
|||
|
|
@ -50,6 +50,8 @@ static const config_keyword keywords[] = {
|
|||
{"height", read_int, &(img_cfg.height), ""},
|
||||
{"unit", read_str, &(img_cfg.unit), ""},
|
||||
{"sensor_id", read_int, &(img_cfg.sens_id), ""},
|
||||
{"x_axis_desc", read_str, &(img_cfg.x_desc), ""},
|
||||
{"y_axis_desc", read_str, &(img_cfg.y_desc), ""},
|
||||
{"value_koeffizient", read_double, &(img_cfg.val_koeff), ""},
|
||||
|
||||
|
||||
|
|
|
|||
|
|
@ -115,7 +115,6 @@ label_list_ptr get_y_label_list(int c_hight, int padding, int zero_min){
|
|||
DEBUGOUT2(" %d Labels generiert\n", num);
|
||||
|
||||
return ptr;
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
|
@ -123,7 +122,9 @@ label_list_ptr get_y_label_list(int c_hight, int padding, int zero_min){
|
|||
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) );
|
||||
char *buff = malloc(sizeof(char)*BUFFSIZE);
|
||||
int i;
|
||||
time_t timestamp;
|
||||
label_list_ptr ptr = NULL;
|
||||
label_list_ptr new_ptr = NULL;
|
||||
label_list_ptr temp_ptr = NULL;
|
||||
|
|
@ -131,10 +132,13 @@ label_list_ptr get_x_label_list(int c_width){
|
|||
DEBUGOUT1("\nBaue x-Labels...\n");
|
||||
|
||||
for ( i = 1; i < num; i++ ) {
|
||||
timestamp = base_time + (i * img_cfg.label_interval);
|
||||
strftime(buff, BUFFSIZE, "%d.%m.%y", localtime(×tamp) );
|
||||
|
||||
new_ptr = malloc(sizeof(label_list_t));
|
||||
new_ptr->pos = floor( ((double)i) * factor);
|
||||
new_ptr->value = base_time + (i * img_cfg.label_interval);
|
||||
new_ptr->text = "NOT YET IMPLEMENTED";
|
||||
new_ptr->text = strdup(buff);
|
||||
new_ptr->next = NULL;
|
||||
|
||||
if (ptr != NULL){
|
||||
|
|
@ -150,6 +154,8 @@ label_list_ptr get_x_label_list(int c_width){
|
|||
|
||||
DEBUGOUT2(" %d Labels generiert\n", num);
|
||||
|
||||
free(buff);
|
||||
|
||||
return ptr;
|
||||
}
|
||||
|
||||
|
|
@ -180,15 +186,33 @@ int scale_y_coords(pix_list_ptr ptr, int c_height){
|
|||
}
|
||||
|
||||
/* Maximaler wert */
|
||||
pix_list_ptr get_max(){
|
||||
pix_list_ptr get_max_val(){
|
||||
return min;
|
||||
}
|
||||
|
||||
/* Minimaler Wert */
|
||||
pix_list_ptr get_min(){
|
||||
pix_list_ptr get_min_val(){
|
||||
return max;
|
||||
}
|
||||
|
||||
char *get_max_time(){
|
||||
char *buff = malloc(sizeof(char)*BUFFSIZE);
|
||||
time_t timestamp = base_time + img_cfg.show_interval;
|
||||
|
||||
strftime(buff, BUFFSIZE, "%d.%m.%y\r\n %H:%M", localtime(×tamp) );
|
||||
|
||||
return buff;
|
||||
}
|
||||
|
||||
char *get_min_time(){
|
||||
char *buff = malloc(sizeof(char)*BUFFSIZE);
|
||||
time_t timestamp = base_time ;
|
||||
|
||||
strftime(buff, BUFFSIZE, "%d.%m.%y\r\n %H:%M", localtime(×tamp) );
|
||||
|
||||
return buff;
|
||||
}
|
||||
|
||||
/* Holt eine Liste mit den Werten und den jeweiligen x-koordinaten */
|
||||
pix_list_ptr get_pix_list(int c_width){
|
||||
double seconds_per_pix = ((double)c_width)/((double)img_cfg.show_interval); /* Pixel pro Sekunde */
|
||||
|
|
|
|||
|
|
@ -28,11 +28,15 @@ pix_list_ptr get_pix_list(int );
|
|||
|
||||
|
||||
/* Max. Wert */
|
||||
pix_list_ptr get_min();
|
||||
pix_list_ptr get_min_val();
|
||||
|
||||
|
||||
/* Min. Wert */
|
||||
pix_list_ptr get_max();
|
||||
pix_list_ptr get_max_val();
|
||||
|
||||
|
||||
char *get_max_time();
|
||||
char *get_min_time();
|
||||
|
||||
|
||||
/* Skaliert die X-Koordinaten der Punkte im angegebenem Bereich
|
||||
|
|
|
|||
|
|
@ -1,5 +1,7 @@
|
|||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <time.h>
|
||||
#include <math.h>
|
||||
#include <gd.h>
|
||||
#include "../definitions.h"
|
||||
#include "image_draw.h"
|
||||
|
|
@ -54,29 +56,38 @@ static gdImagePtr create_image(){
|
|||
|
||||
/* Baut das Bild */
|
||||
static gdImagePtr draw_image(gdImagePtr img){
|
||||
|
||||
/* Werte und Labels */
|
||||
pix_list_ptr pix_list = NULL;
|
||||
label_list_ptr x_labels = NULL;
|
||||
label_list_ptr y_labels = NULL;
|
||||
|
||||
/* Allgemeine Variablen */
|
||||
int max_val = 0;
|
||||
int min_val = 0;
|
||||
int offset_x_left = 10;
|
||||
int offset_x_left = 0;
|
||||
int offset_y_top = 5;
|
||||
int offset_x_right = 20;
|
||||
int offset_y_bottom = 80;
|
||||
int offset_y_bottom = 0;
|
||||
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;
|
||||
int i;
|
||||
|
||||
char *buff;
|
||||
time_t ts;
|
||||
|
||||
/* Größenangaben fuer die einzelnen Texte */
|
||||
dimension_t head_d;
|
||||
dimension_t y_label_d;
|
||||
dimension_t x_label_d;
|
||||
dimension_t x_desc_d;
|
||||
dimension_t y_desc_d;
|
||||
|
||||
/* Farben */
|
||||
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);
|
||||
|
|
@ -85,6 +96,12 @@ static gdImagePtr draw_image(gdImagePtr img){
|
|||
color headline_c = alloc_alpha_color(img, img_cfg.headline_color);
|
||||
color label_c = alloc_alpha_color(img, img_cfg.label_color);
|
||||
|
||||
/* Ueberschrift */
|
||||
head_d = calc_text_dim(img_cfg.headline, 16, 0);
|
||||
gdImageStringFT(img, &brect[0], headline_c, IMG_FONT, 16, 0, 10, offset_y_top + head_d.to_base, img_cfg.headline);
|
||||
offset_y_top = (offset_y_top * 2) + head_d.height;
|
||||
|
||||
/* Einrueckung von links berechnen */
|
||||
if(img_cfg.unit != NULL){
|
||||
buff = malloc(sizeof(char)*SHORTBUFFSIZE);
|
||||
snprintf(buff, SHORTBUFFSIZE, "99999%s", img_cfg.unit);
|
||||
|
|
@ -94,17 +111,25 @@ static gdImagePtr draw_image(gdImagePtr img){
|
|||
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;
|
||||
y_desc_d = calc_text_dim(img_cfg.y_desc, 9, 1.57079);
|
||||
offset_x_left = offset_x_left + y_label_max_width + 15 + (y_desc_d.r_b_x - y_desc_d.r_t_x);
|
||||
dia_width = img_cfg.width - offset_x_left - offset_x_right;
|
||||
|
||||
|
||||
/* Ueberschrift */
|
||||
head_d = calc_text_dim(img_cfg.headline, 16, 0);
|
||||
gdImageStringTTF(img, &brect[0], headline_c, IMG_FONT, 16, 0, 10, offset_y_top + head_d.to_base, img_cfg.headline);
|
||||
offset_y_top = (offset_y_top * 2) + head_d.height;
|
||||
|
||||
/* Diagramhöhe */
|
||||
buff = malloc(sizeof(char)*SHORTBUFFSIZE);
|
||||
ts = time(NULL);
|
||||
strftime(buff, SHORTBUFFSIZE, "%d.%m.%y\r\n%H:%M", localtime(&ts) ) ;
|
||||
x_label_d = calc_text_dim(buff, 8, 1.0);
|
||||
x_desc_d = calc_text_dim(img_cfg.x_desc, 9, 0);
|
||||
offset_y_bottom = 10 + fabs(x_label_d.height) + x_desc_d.height;
|
||||
dia_height = img_cfg.height - offset_y_top - offset_y_bottom ;
|
||||
free(buff);
|
||||
|
||||
dia_height = img_cfg.height - offset_y_top - offset_y_bottom;
|
||||
/* 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], 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);
|
||||
|
||||
/* Werte holen */
|
||||
pix_list = get_pix_list(dia_width);
|
||||
|
|
@ -113,12 +138,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);
|
||||
|
||||
|
||||
y_labels = get_y_label_list(dia_height, dia_y_padding, 0);
|
||||
/* horizontale linien + y - Labels */
|
||||
y_labels = get_y_label_list(dia_height, dia_y_padding, 0);
|
||||
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);
|
||||
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);
|
||||
}
|
||||
|
||||
/* y-Werte skalieren */
|
||||
|
|
@ -128,7 +153,13 @@ static gdImagePtr draw_image(gdImagePtr img){
|
|||
x_labels = get_x_label_list(dia_width);
|
||||
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);
|
||||
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);
|
||||
}
|
||||
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() );
|
||||
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() );
|
||||
|
||||
/* Nullinie */
|
||||
if (zero_line != -1)
|
||||
|
|
@ -140,6 +171,7 @@ static gdImagePtr draw_image(gdImagePtr img){
|
|||
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);
|
||||
}
|
||||
|
||||
/* Rahmen */
|
||||
gdImageRectangle(img, offset_x_left, offset_y_top, img_cfg.width - offset_x_right, img_cfg.height - offset_y_bottom, dia_border_c);
|
||||
|
||||
|
||||
|
|
@ -154,7 +186,7 @@ static dimension_t calc_text_dim(char *text, double size, double angle){
|
|||
int y_rt_lb = 0;
|
||||
int y_rb_lt = 0;
|
||||
|
||||
gdImageStringTTF(NULL, &brect[0], 0, IMG_FONT, size, angle, 0,0, text);
|
||||
gdImageStringFT(NULL, &brect[0], 0, IMG_FONT, size, angle, 0,0, text);
|
||||
|
||||
dim.l_t_x = brect[6];
|
||||
dim.l_t_y = brect[7];
|
||||
|
|
@ -165,13 +197,11 @@ static dimension_t calc_text_dim(char *text, double size, double angle){
|
|||
dim.r_t_x = brect[4];
|
||||
dim.r_t_y = brect[5];
|
||||
|
||||
dim.to_base = 0 - dim.l_t_y;
|
||||
|
||||
//printf("%d -- %d\n", dim.l_t_y, dim.r_t_y);
|
||||
dim.to_base = 0 - dim.r_t_y;
|
||||
|
||||
x_rt_lb = dim.r_t_x - dim.l_b_x;
|
||||
x_rb_lt = dim.r_b_x - dim.l_t_x;
|
||||
y_rt_lb = dim.r_t_y - dim.l_b_y;
|
||||
y_rt_lb = dim.l_b_y - dim.r_t_y;
|
||||
y_rb_lt = dim.r_b_y - dim.l_t_y;
|
||||
|
||||
if(x_rt_lb < x_rb_lt){
|
||||
|
|
@ -182,10 +212,14 @@ static dimension_t calc_text_dim(char *text, double size, double angle){
|
|||
|
||||
if(y_rt_lb < y_rb_lt){
|
||||
dim.height = y_rb_lt;
|
||||
//printf("y_rb_lt");
|
||||
} else {
|
||||
dim.height = y_rt_lb;
|
||||
//printf("y_rt_lb");
|
||||
}
|
||||
|
||||
//printf("%d -- %s\n", dim.height, text);
|
||||
|
||||
return dim;
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -1,17 +1,19 @@
|
|||
filename /home/jan/Testbild.png
|
||||
headline Testbild
|
||||
headline Testbild bla
|
||||
manual_table no
|
||||
manual_table_name auss2_data
|
||||
table_field temp
|
||||
gen_interval 1
|
||||
show_interval 10d
|
||||
show_interval 30d
|
||||
label_interval 1d
|
||||
label_sum no
|
||||
width 800
|
||||
height 300
|
||||
sensor_id 1
|
||||
value_koeffizient 0.1
|
||||
unit °
|
||||
unit °C
|
||||
x_axis_desc Zeit
|
||||
y_axis_desc Temparatur (°C)
|
||||
|
||||
bg_color DF:DF:EF:00 #test
|
||||
dia_bg_color F0:A0:D0:D0 #test
|
||||
|
|
|
|||
Loading…
Reference in New Issue