Muchas gracias por la atención prestada.
_Marcos_
|
|
#1 (permalink) |
![]() Fecha de Ingreso: noviembre-2002
Ubicación: España
Mensajes: 164
|
Cuadros estadísticos con GTK
Muchas gracias por la atención prestada. _Marcos_ |
|
|
|
|
|
#2 (permalink) |
|
Colaborador
![]() Fecha de Ingreso: noviembre-2002
Ubicación: 127.0.0.1
Mensajes: 3.343
|
Tengo entendido que nuestro amigo Epplestum estaba haciendo sus primeras armas en esto del GTK, programando un componente para hacer gráficos estadísticos..
Ahora cuando lo vea le aviso de este Post y que él mismo nos cuente más al respecto. Saludos. |
|
|
|
|
|
#3 (permalink) |
![]() Fecha de Ingreso: noviembre-2002
Mensajes: 1.620
|
ya toy aki, yo desarrolle un modulo que te genera graficas, es para C y GTK, si es en ese lenguaje en el que lo necesitas te lo doy sin ningun problema :) jeje y sino tb y te miras el code :P jeej si lo que tienes que hacer en PHP por ejemplo estoy portando el WIDGET ese para PHP-GTK pero weno dime en que lo estas desarrollando y te ayudo :)
__________________
Usuario registrado de Linux #288725 |
|
|
|
|
|
#4 (permalink) |
![]() Fecha de Ingreso: noviembre-2002
Ubicación: España
Mensajes: 164
|
Pues justamente estoy programando en C con GTK, asi q me viene al pelo, mi mail es: maem_20022000@yahoo.es, y muchas gracias!!!!
Me aconsejaron usar, esto: Prueba con Guppi, que es lo que usa gnumeric para sus gráficas, o incluso con libplot 1. http://www.gnome.org/projects/guppi/ 2. http://www.gnu.org/manual/plotutils/...otutils_9.html Hice algunas pruebas con el libplot, na mas; y ten por seguro q te preguntaré las cosillas q dude. _Marcos_ |
|
|
|
|
|
#5 (permalink) |
![]() Fecha de Ingreso: noviembre-2002
Mensajes: 1.620
|
weno te pongo aki el code para k los demas tabien lo usen y a parte te lo envio :)
main.c <- este es el programa
Código:
gtkgraph.h <- esta es la libreria .h/*
* Archivo: main.c
* Autor: Ivan Rodriguez
*
* Ejemplo de ilustracion de widget personalizado
*/
#include <gtk/gtk.h>
#include "gtkgraph.c";
/*
* CloseAppWindow
*
* La ventana se esta cerrando. Hace falta apagar GTK+.
*/
gint CloseAppWindow (GtkWidget *widget, gpointer *data)
{
gtk_main_quit ();
return (FALSE);
}
/*
* main - El programa comienza aqui.
*/
int main (int argc, char *argv[])
{
GtkWidget *window;
GtkWidget *graph;
/* Inicializacion de GTK+ */
gtk_init (&argc, &argv);
/* Crear la ventana de nivel supeior */
window = gtk_window_new (GTK_WINDOW_TOPLEVEL);
gtk_window_set_title (GTK_WINDOW (window), "Bar Graph");
/* Acuerdese siempre de conectar el suceso delete con la ventana principal */
gtk_signal_connect (GTK_OBJECT (window), "delete_event", GTK_SIGNAL_FUNC (CloseAppWindow), NULL);
/* Especificar borde de la ventana */
gtk_container_border_width (GTK_CONTAINER (window), 20);
/*
* Crear una grafica
*/
graph = gtk_graph_new ();
/* Mostrar la grafica */
gtk_widget_show (graph);
/* Establecer numero de elementos de la grafica */
gtk_graph_size (GTK_GRAPH (graph), 5);
/* Establecer altura de cada elemento de la grafica */
gtk_graph_set_value (GTK_GRAPH (graph), 0, 25);
gtk_graph_set_value (GTK_GRAPH (graph), 1, 25);
gtk_graph_set_value (GTK_GRAPH (graph), 2, 25);
gtk_graph_set_value (GTK_GRAPH (graph), 3, 25);
gtk_graph_set_value (GTK_GRAPH (graph), 4, 25);
gtk_widget_draw (graph, NULL);
/*
* Hacer visible la ventana principal
*/
gtk_container_add(GTK_CONTAINER (window), graph);
gtk_widget_show(window);
gtk_main();
exit(0);
}
Código:
gtkgraph.c <- esto la libreria .c/*
* Archivo : gtkgraph.h
* Autor : Ivan Rodriguez
*/
#ifndef __GTK_GRAPH_H__
#define __GTK_GRAPH_H__
#include <gdk/gdk.h>
#include <gtk/gtkvbox.h>
#ifdef __cplusplus
extern "C" {
#endif /* __cplusplus */
/*
* Macros para conversion y comprobacion de tipos
*/
#define GTK_GRAPH(obj) GTK_CHECK_CAST (obj, gtk_graph_get_type (), GtkGraph)
#define GTK_GRAPH_CLASS(klass) GTK_CHECK_CLASS_CAST (klass, gtk_graph_get_type, GtkGraphClass)
#define GTK_IS_GRAPH(obj) GTK_CHECK_TYPE (obj, gtk_graph_get_type ())
/*
* Definicion de estructura de datos
*/
typedef struct _GtkGraph GtkGraph;
typedef struct _GtkGraphClass GtkGraphClass;
/*
* Aqui estan los datos de la grafica
*/
struct _GtkGraph
{
GtkWidget vbox;
gint *values;
gint num_values;
};
/*
* Aqui estan los datos de la clase
*/
struct _GtkGraphClass
{
GtkWidgetClass parent_class;
};
/*
* Prototipos de funciones
*/
GtkWidget* gtk_graph_new (void);
void gtk_graph_size (GtkGraph *graph, int size);
void gtk_graph_set_value (GtkGraph *graph, int index, int value);
#ifdef __cplusplus
}
#endif /* __cplusplus */
#endif /* __GTK_GRAPH_H__ */
Sigo en otro mensaje...
__________________
Usuario registrado de Linux #288725 |
|
|
|
|
|
#6 (permalink) |
![]() Fecha de Ingreso: noviembre-2002
Mensajes: 1.620
|
Código:
/*
* Archivo: GtkGraph.c
* Autor: IvanRodriguez
*
* Widget de grafica gtk sencillo
*/
#include <string.h>
#include <stdlib.h>
#include <stdio.h>
#include <gtk/gtk.h>
#include "gtkgraph.h"
static GtkWidgetClass *parent_class = NULL;
/*
* Declaraciones anticipadas
*/
static void gtk_graph_class_init (GtkGraphClass *class);
static void gtk_graph_init (GtkGraph *graph);
static void gtk_graph_realize (GtkWidget *widget);
static void gtk_graph_draw (GtkWidget *widget, GdkRectangle *area);
static void gtk_graph_size_request (GtkWidget *widget, GtkRequisition *req);
static gint gtk_graph_expose (GtkWidget *widget, GdkEventExpose *event);
static void gtk_graph_destroy (GtkObject *object);
/*
* gtk_grapth_get_type
*
* Clase interna. Utilizada para definir la clase GtkGraph ante GTK+
*/
guint gtk_graph_get_type (void)
{
static guint graph_type = 0;
/* Si no esta creada todavia */
if(!graph_type)
{
/* Crear un objeto graph_info */
GtkTypeInfo graph_info =
{
"GtkGraph",
sizeof (GtkGraph),
sizeof (GtkGraphClass),
(GtkClassInitFunc) gtk_graph_class_init,
(GtkObjectInitFunc) gtk_graph_init,
(GtkArgSetFunc) NULL,
(GtkArgGetFunc) NULL,
};
/* Informar a GTK+ de su existencia · Obtener identificador univoco */
graph_type = gtk_type_unique (gtk_widget_get_type(), &graph_info);
}
return graph_type;
}
/*
* gtk_graph_class_init
*
* Sustituir todos los metodos de la clase que sea necesario
* para que la clase de la grafica se comporte adecuadamene.
* Aqui se sustituyen las funciones que hacen que se realize
* el dibujo.
*
* class - Clase de definicion del objeto
*/
static void gtk_graph_class_init (GtkGraphClass *class)
{
GtkObjectClass *object_class;
GtkWidgetClass *widget_class;
/* Obtener la clase del widget */
object_class = (GtkObjectClass *) class;
widget_class = (GtkWidgetClass *) class;
parent_class = gtk_type_class (gtk_widget_get_type());
/* Sustituir destruccion del objeto */
object_class->destroy = gtk_graph_destroy;
/* sustituir destruccion del objeto */
widget_class->realize = gtk_graph_realize;
widget_class->draw = gtk_graph_draw;
widget_class->size_request = gtk_graph_size_request;
widget_class->expose_event = gtk_graph_expose;
}
/*
* gtk_graph_init
*
* se invoca cada vez que se crea un nuevo elemento de grafica.
* Inicializa los campos de nuestra estructura.
*/
static void gtk_graph_init (GtkGraph *graph)
{
GtkWidget *widget;
widget = (GtkWidget *) graph;
/* Valores iniciales */
graph->values = NULL;
graph->num_values = 0;
}
/*
* gtk_graph_new
*
* Crea un nuevo elemento GtkGraph
*/
GtkWidget* gtk_graph_new (void)
{
return gtk_type_new (gtk_graph_get_type());
}
/*
* gtk_graph_realize
*
* Asociar el widget con una ventana X Window.
*
*/
static void gtk_graph_realize (GtkWidget *widget)
{
GtkGraph *darea;
GdkWindowAttr attributes;
gint attributes_mask;
/* Comprobar errores */
g_return_if_fail (widget != NULL);
g_return_if_fail (GTK_IS_GRAPH (widget));
darea = GTK_GRAPH (widget);
GTK_WIDGET_SET_FLAGS (widget, GTK_REALIZED);
/* Atributos para crear la ventana */
attributes.window_type = GDK_WINDOW_CHILD;
attributes.x = widget->allocation.x;
attributes.y = widget->allocation.y;
attributes.width = widget->allocation.width;
attributes.height = widget->allocation.height;
attributes.wclass = GDK_INPUT_OUTPUT;
attributes.visual = gtk_widget_get_visual (widget);
attributes.colormap = gtk_widget_get_colormap (widget);
attributes.event_mask = gtk_widget_get_events (widget) | GDK_EXPOSURE_MASK;
/* Estamos pasando valores x, y, visual y colormap */
attributes_mask = GDK_WA_X | GDK_WA_Y | GDK_WA_VISUAL | GDK_WA_COLORMAP;
/* Crear la ventana */
widget->window = gdk_window_new (gtk_widget_get_parent_window (widget), &attributes, attributes_mask);
gdk_window_set_user_data (widget->window, darea);
widget->style = gtk_style_attach (widget->style, widget->window);
gtk_style_set_background (widget->style, widget->window, GTK_STATE_NORMAL);
}
/*
* gtk_graph_size
*
* Metodo personalizado para establecer el tamañano de la grafica
*/
void gtk_graph_size (GtkGraph *graph, int size)
{
g_return_if_fail (graph != NULL);
g_return_if_fail (GTK_IS_GRAPH (graph));
graph->num_values = size;
graph->values = g_realloc (graph->values, sizeof (gint) *size);
}
/*
* gtk_graph_set_value
*
* Metodo personalizado para establecer el tamaño
*/
void gtk_graph_set_value (GtkGraph *graph, int index, int value)
{
g_return_if_fail (graph != NULL);
g_return_if_fail (GTK_IS_GRAPH (graph));
g_return_if_fail (index < graph->num_values && index >=0);
graph->values[index] = value;
}
/*
* gtk_graph_draw
*
* Dibujar el widget, basandose en el numero de valores graficos del grafico de barras
*/
static void gtk_graph_draw (GtkWidget *widget, GdkRectangle *area)
{
GtkGraph *graph;
int width;
int height;
int column_width;
int max = 0;
int i;
int bar_height;
/* Comprobar existencia de problemas obvios */
g_return_if_fail (widget != NULL);
g_return_if_fail (GTK_IS_GRAPH (widget));
/* Asegurarse de que es un widget dibujable */
if (GTK_WIDGET_DRAWABLE (widget))
{
graph = GTK_GRAPH (widget);
if (graph->num_values == 0)
{
return;
}
/* Obtener altura y anchura */
width = widget->allocation.width -1;
height = widget->allocation.height -1;
/* Calcular anchura de las columnas */
column_width = width / graph->num_values;
/* Encontrar valor maximo */
for (i = 0; i < graph->num_values; i++)
{
if (max < graph->values[i])
{
max = graph->values[i];
}
}
for (i = 0; i < graph->num_values; i++)
{
bar_height = (graph->values[i] * height) / max;
gdk_draw_rectangle (widget->window, widget->style->fg_gc[GTK_STATE_NORMAL], TRUE, (i * column_width), height - bar_height, (column_width-2), bar_height);
}
}
}
/*
* gtk_graph_size_request
*
* ¿de que tamaño debe ser el widget?
* Puede modificarse
*/
static void gtk_graph_size_request (GtkWidget *widget, GtkRequisition *req)
{
req->width = 100;
req->height = 100;
}
/*
* gtk_graph_expose
*
* El widget de grafica ha quedado expuesto y debe redibujarse
*/
static gint gtk_graph_expose (GtkWidget *widget, GdkEventExpose *event)
{
GtkGraph *graph;
/* Realizar comprobacion de errores */
g_return_val_if_fail (widget != NULL, FALSE);
g_return_val_if_fail (GTK_IS_GRAPH (widget), FALSE);
g_return_val_if_fail (event != NULL, FALSE);
if (event->count > 0)
{
return (FALSE);
}
/* Obtener el widget de grafica */
graph = GTK_GRAPH (widget);
/* Borrar la ventana */
gdk_window_clear_area (widget->window, 0, 0, widget->allocation.width, widget->allocation.height);
/* Dibujar la grafica */
gtk_graph_draw (widget, NULL);
return(FALSE);
}
/*
* gtk_graph_destroy
*
* Destruir el widget y liberar la memoria asiganada.
* Despues, invocar funcion de destruccion del padre,
* para asegurarse de que libera la memoria asignada
* por este.
*/
static void gtk_graph_destroy (GtkObject *object)
{
GtkGraph *graph;
/* Comprobar tipo */
g_return_if_fail (object != NULL);
g_return_if_fail (GTK_IS_GRAPH (object));
/* Convertir en objeto de grafica */
graph = GTK_GRAPH (object);
/* Liberar memoria */
g_free (graph->values);
/* Invocar destruccion del padre */
GTK_OBJECT_CLASS (parent_class)->destroy (object);
}
__________________
Usuario registrado de Linux #288725 |
|
|
|
|
|
#7 (permalink) |
![]() Fecha de Ingreso: noviembre-2002
Ubicación: España
Mensajes: 164
|
Funciona!!!
Gracias Eplestun, lo compile y ya lo probé, por si acaso en el main, se debe llamar a: gtkgraph.h y no a gtkgrap.c.
Una consulta; ¿hiciste algún programa para dibujar gráficos de tipo lineal?, es decir q se dibujen de acuerdo a las coordenas q se le pase, en las X y Y, formando una linea, a través de la unión de los puntos. Reitero mis agradecimientos. _Marcos_ |
|
|
|
|
|
#8 (permalink) |
![]() Fecha de Ingreso: noviembre-2002
Mensajes: 1.620
|
No no lo hice, pero weno no creo que sea dificil, GTK+ tiene funciones para hacerlo para el WIDGET de dibujo de gtk+ podrias revisarlo, e incluso modificar el widget creado por mi y añadirle esa funcionalidad :) Por cierto cuando acabes el programa me lo enseñas pls?
__________________
Usuario registrado de Linux #288725 |
|
|
|