chart...
(grid + headline) git-svn-id: file:///home/jan/tmp/wetterstation/trunk@92 dd492736-c11a-0410-ad51-8c26713eaf7f
This commit is contained in:
parent
035f37acea
commit
2a26ab6bb4
|
|
@ -56,6 +56,7 @@ image_file/image_data.o: image_file/image_data.c \
|
||||||
common.h \
|
common.h \
|
||||||
definitions.h
|
definitions.h
|
||||||
image_file/image_draw.o: image_file/image_draw.c \
|
image_file/image_draw.o: image_file/image_draw.c \
|
||||||
|
definitions.h \
|
||||||
image_file/image_draw.h \
|
image_file/image_draw.h \
|
||||||
image_file/image_data.h \
|
image_file/image_data.h \
|
||||||
image_file/image_common.h
|
image_file/image_common.h
|
||||||
|
|
|
||||||
|
|
@ -49,6 +49,7 @@
|
||||||
/* Verschiedenes ------------------------------------------------------- */
|
/* Verschiedenes ------------------------------------------------------- */
|
||||||
#define FALSE 0
|
#define FALSE 0
|
||||||
#define TRUE 1
|
#define TRUE 1
|
||||||
|
#define IMG_FONT "/usr/share/fonts/truetype/freefont/FreeSans.ttf"
|
||||||
|
|
||||||
|
|
||||||
/* Debug --------------------------------------------------------------- */
|
/* Debug --------------------------------------------------------------- */
|
||||||
|
|
|
||||||
|
|
@ -28,6 +28,8 @@ typedef struct image_cfg {
|
||||||
img_color_ptr dia_border_color;
|
img_color_ptr dia_border_color;
|
||||||
img_color_ptr zero_line_color;
|
img_color_ptr zero_line_color;
|
||||||
img_color_ptr label_color;
|
img_color_ptr label_color;
|
||||||
|
img_color_ptr headline_color;
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -59,6 +59,7 @@ static const config_keyword keywords[] = {
|
||||||
{"dia_border_color", read_color, &(img_cfg.dia_border_color), ""},
|
{"dia_border_color", read_color, &(img_cfg.dia_border_color), ""},
|
||||||
{"zero_line_color", read_color, &(img_cfg.zero_line_color), ""},
|
{"zero_line_color", read_color, &(img_cfg.zero_line_color), ""},
|
||||||
{"label_color", read_color, &(img_cfg.label_color), ""},
|
{"label_color", read_color, &(img_cfg.label_color), ""},
|
||||||
|
{"headline_color", read_color, &(img_cfg.headline_color), ""},
|
||||||
|
|
||||||
{"", NULL, NULL, ""}
|
{"", NULL, NULL, ""}
|
||||||
};
|
};
|
||||||
|
|
|
||||||
|
|
@ -1,15 +1,30 @@
|
||||||
#include <stdio.h>
|
#include <stdio.h>
|
||||||
#include <gd.h>
|
#include <gd.h>
|
||||||
|
#include "../definitions.h"
|
||||||
#include "image_draw.h"
|
#include "image_draw.h"
|
||||||
#include "image_data.h"
|
#include "image_data.h"
|
||||||
#include "image_common.h"
|
#include "image_common.h"
|
||||||
|
|
||||||
|
|
||||||
typedef int color;
|
typedef int color;
|
||||||
|
typedef struct dimension {
|
||||||
|
int width;
|
||||||
|
int height;
|
||||||
|
int l_t_x;
|
||||||
|
int l_t_y;
|
||||||
|
int l_b_x;
|
||||||
|
int l_b_y;
|
||||||
|
int r_b_x;
|
||||||
|
int r_b_y;
|
||||||
|
int r_t_x;
|
||||||
|
int r_t_y;
|
||||||
|
int to_base;
|
||||||
|
} dimension_t;
|
||||||
|
|
||||||
|
|
||||||
static gdImagePtr create_image();
|
static gdImagePtr create_image();
|
||||||
static gdImagePtr draw_image(gdImagePtr);
|
static gdImagePtr draw_image(gdImagePtr);
|
||||||
|
static dimension_t calc_text_dim(char *, double , double );
|
||||||
static color alloc_alpha_color(gdImagePtr , img_color_ptr );
|
static color alloc_alpha_color(gdImagePtr , img_color_ptr );
|
||||||
static void write_image_png(gdImagePtr, FILE *);
|
static void write_image_png(gdImagePtr, FILE *);
|
||||||
|
|
||||||
|
|
@ -18,6 +33,7 @@ int draw_to_file(FILE *fd){
|
||||||
gdImagePtr img = create_image();
|
gdImagePtr img = create_image();
|
||||||
draw_image(img);
|
draw_image(img);
|
||||||
write_image_png(img, fd);
|
write_image_png(img, fd);
|
||||||
|
gdImageDestroy(img);
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Erstellt ein Bild mit Hintergrundfarbe */
|
/* Erstellt ein Bild mit Hintergrundfarbe */
|
||||||
|
|
@ -42,19 +58,32 @@ static gdImagePtr draw_image(gdImagePtr img){
|
||||||
|
|
||||||
int max_val = 0;
|
int max_val = 0;
|
||||||
int min_val = 0;
|
int min_val = 0;
|
||||||
int offset_x_left = 20;
|
int offset_x_left = 60;
|
||||||
int offset_y_top = 20;
|
int offset_y_top = 5;
|
||||||
int offset_x_right = 20;
|
int offset_x_right = 20;
|
||||||
int offset_y_bottom = 20;
|
int offset_y_bottom = 20;
|
||||||
int dia_width = img_cfg.width - offset_x_left - offset_x_right;
|
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 dia_height = img_cfg.height - offset_y_top - offset_y_bottom;
|
||||||
int zero_line = 0;
|
int zero_line = 0;
|
||||||
int dia_y_padding = 10;
|
int dia_y_padding = 10;
|
||||||
|
int brect[8];
|
||||||
|
|
||||||
|
dimension_t head_d;
|
||||||
|
dimension_t y_label_d;
|
||||||
|
dimension_t x_label_d;
|
||||||
|
|
||||||
color val_line_c = alloc_alpha_color(img, img_cfg.dia_line_color);
|
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 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 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);
|
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);
|
||||||
|
|
||||||
|
|
||||||
|
/* 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;
|
||||||
|
|
||||||
/* Werte holen */
|
/* Werte holen */
|
||||||
pix_list = get_pix_list(dia_width);
|
pix_list = get_pix_list(dia_width);
|
||||||
|
|
@ -62,18 +91,14 @@ static gdImagePtr draw_image(gdImagePtr img){
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
/* Diagramhintergrund */
|
/* Diagramhintergrund */
|
||||||
gdImageFilledRectangle(img, offset_x_left, offset_y_top, img_cfg.width - offset_x_right, img_cfg.height - offset_y_bottom, dia_bg_c);
|
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);
|
y_labels = get_y_label_list(dia_height, dia_y_padding, 0);
|
||||||
for (; y_labels; y_labels = y_labels->next){
|
for (; y_labels; y_labels = y_labels->next){
|
||||||
gdImageLine(img, offset_x_left, offset_y_top + y_labels->pos, img_cfg.width - offset_x_right, offset_y_top + y_labels->pos, diag_grid_c);
|
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-Werte skalieren */
|
/* y-Werte skalieren */
|
||||||
|
|
@ -82,7 +107,7 @@ static gdImagePtr draw_image(gdImagePtr img){
|
||||||
/* Vertikale linien + x - Labels*/
|
/* Vertikale linien + x - Labels*/
|
||||||
x_labels = get_x_label_list(dia_width);
|
x_labels = get_x_label_list(dia_width);
|
||||||
for(; x_labels; x_labels = x_labels->next){
|
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);
|
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);
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Nullinie */
|
/* Nullinie */
|
||||||
|
|
@ -95,7 +120,53 @@ static gdImagePtr draw_image(gdImagePtr img){
|
||||||
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);
|
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);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
gdImageRectangle(img, offset_x_left, offset_y_top, img_cfg.width - offset_x_right, img_cfg.height - offset_y_bottom, dia_border_c);
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
static dimension_t calc_text_dim(char *text, double size, double angle){
|
||||||
|
int brect[8];
|
||||||
|
dimension_t dim;
|
||||||
|
int x_rt_lb = 0;
|
||||||
|
int x_rb_lt = 0;
|
||||||
|
int y_rt_lb = 0;
|
||||||
|
int y_rb_lt = 0;
|
||||||
|
|
||||||
|
gdImageStringTTF(NULL, &brect[0], 0, IMG_FONT, size, angle, 0,0, text);
|
||||||
|
|
||||||
|
dim.l_t_x = brect[6];
|
||||||
|
dim.l_t_y = brect[7];
|
||||||
|
dim.l_b_x = brect[0];
|
||||||
|
dim.l_b_y = brect[1];
|
||||||
|
dim.r_b_x = brect[2];
|
||||||
|
dim.r_b_y = brect[3];
|
||||||
|
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);
|
||||||
|
|
||||||
|
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_rb_lt = dim.r_b_y - dim.l_t_y;
|
||||||
|
|
||||||
|
if(x_rt_lb < x_rb_lt){
|
||||||
|
dim.width = x_rb_lt;
|
||||||
|
} else {
|
||||||
|
dim.width = x_rt_lb;
|
||||||
|
}
|
||||||
|
|
||||||
|
if(y_rt_lb < y_rb_lt){
|
||||||
|
dim.height = y_rb_lt;
|
||||||
|
} else {
|
||||||
|
dim.height = y_rt_lb;
|
||||||
|
}
|
||||||
|
|
||||||
|
return dim;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -16,7 +16,7 @@ bg_color DF:DF:EF:00 #test
|
||||||
dia_bg_color F0:A0:D0:D0 #test
|
dia_bg_color F0:A0:D0:D0 #test
|
||||||
zero_line_color BF:80:80:40 #test
|
zero_line_color BF:80:80:40 #test
|
||||||
dia_line_color 60:30:50:30 #test
|
dia_line_color 60:30:50:30 #test
|
||||||
dia_grid_color 00:00:00:EF #test
|
dia_grid_color 60:60:60:EF #test
|
||||||
dia_border_color 60:30:50:af #test
|
dia_border_color a0:a0:a0:af #test
|
||||||
label_color 60:30:50:af #test
|
label_color 60:30:50:af #test
|
||||||
#dia_color 60:30:50:af #test
|
headline_color 50:10:10:30 #test
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue