Commit 1faf79fc authored by Arturo Espinosa's avatar Arturo Espinosa

Commit my batch of changes

parent 75bf46e4
......@@ -188,6 +188,9 @@ module GNOME {
//
void freeze ();
void thaw ();
void reset_series ();
void add_series (in string label, in Vector vector);
};
};
};
/*
* Graph Item
*
* Author:
* Miguel de Icaza (miguel@kernel.org)
*
* (C) 1999 International GNOME Support (http://www.gnome-support.com).
*/
#include <config.h>
#include <libgnomeui/gnome-canvas.h>
#include "graph.h"
enum {
ARG_BBOX,
ARG_GRAPH,
};
static GnomeCanvasItemClass *graph_view_parent_class;
static GraphViewClass *graph_view_class;
static void
graph_view_destroy (GtkObject *object)
{
GraphView *graph_view = GRAPH_VIEW (object);
}
static void
graph_view_canvas_update (GnomeCanvasItem *item, double *affine, ArtSVP *clip_path, int flags)
{
if (graph_view_parent_class->update)
(*graph_view_parent_class->update)(item, affine, clip_path, flags);
for (i = 0; i < 6; i++)
graph_view->affine [i] = affine [i];
}
static void
graph_view_realize (GnomeCanvasItem *item)
{
GraphView *graph_view;
GdkWindow *window;
if (graph_view_parent_class->realize)
(*graph_view_parent_class->realize)(item);
graph_view = GRAPH_VIEW (item);
}
static void
graph_view_unrealize (GnomeCanvasItem *item)
{
GraphView *graph_view = GRAPH_VIEW (item);
if (GNOME_CANVAS_ITEM_CLASS (graph_view_parent_class)->unrealize)
(*graph_view_parent_class->unrealize)(item);
}
static void
graph_view_colbar_draw_nth (GraphView *graph_view, GdkDrawable *drawable, int n, int base_x, int base_y)
{
}
static void
graph_view_colbar_draw (GraphView *graph_view, GdkDrawable *drawable, int x, int y, int width, int height)
{
int yl = graph_view->bbox.y1 - graph_view->bbox.y0;
int xl = graph_view->bbox.x1 - graph_view->bbox.x0;
int first, last, i;
double units_per_slot;
if (graph_view->graph->direction == GNOME_GRAPH_DIR_BAR){
units_per_slot = yl / graph_view->graph->divisions;
first = y / units_per_slot;
last = (y + width) / units_per_slot;
for (i = first; i <= last; i++){
HERE IS STAYED
}
} else {
units_per_slot = xl / graph_view->graph->divisions;
first = x / units_per_slot;
last = (x + width) / units_per_slot;
for (i = first; i <= last; i++){
int base = i * units_per_slot;
graph_view_colbar_draw_nth (drawable, i, base_x - x, y);
};
}
}
static void
graph_view_draw (GnomeCanvasItem *item, GdkDrawable *drawable, int x, int y, int width, int height)
{
GraphView *graph_view = GRAPH_VIEW (item);
Graph *graph = graph_view->graph;
if (graph->plot_mode == GNOME_Graph_PLOT_COLBAR){
graph_view_colbar_draw (graph_view, drawable, x, y, width, height);
return;
}
}
static double
graph_view_point (GnomeCanvasItem *item, double x, double y, int cx, int cy,
GnomeCanvasItem **actual_item)
{
}
static gint
item_cursor_event (GnomeCanvasItem *item, GdkEvent *event)
{
}
static void
graph_view_class_init (GtkObjectClass *object_class)
{
GnomeCanvasItemClass *item_class = (GnomeCanvasItemClass *) object_class;
graph_view_parent_class = gtk_type_class (gnome_canvas_item_get_type ());
graph_view_class = gtk_type_class (graph_view_get_type ());
/*
* Method overrides
*/
object_class->destroy = graph_view_destroy;
item_class->update = graph_view_canvas_update;
item_class->realize = graph_view_realize;
item_class->unrealize = graph_view_unrealize;
item_class->draw = graph_view_draw;
item_class->point = graph_view_point;
item_class->translate = graph_view_translate;
item_class->event = graph_view_event;
}
void
graph_view_update (GraphView *graph_view, int dirty_flags)
{
g_return_if_fail (graph_view != NULL);
g_return_if_fail (IS_GRAPH_VIEW (graph_view));
graph_view->dirty_flags |= dirty_flags;
if (graph_view->frozen)
return;
if (graph_view->dirty_flags & DIRTY_TYPE){
graph_view->dirty_flags &= ~DIRTY_TYPE;
}
if (graph_view->dirty & (DIRTY_BBOX|DIRTY_SHAPE)){
graph_view->dirty_flags &= ~(DIRTY_BBOX | DIRTY_SHAPE);
}
}
void
graph_view_freeze (GraphView *graph_view)
{
g_return_if_fail (graph_view != NULL);
g_return_if_fail (IS_GRAPH_VIEW (graph_view));
graph_view->frozen++;
}
void
graph_view_thaw (GraphView *graph_view)
{
g_return_if_fail (graph_view != NULL);
g_return_if_fail (IS_GRAPH_VIEW (graph_view));
graph_view->frozen--;
if (graph_view->frozen != 0)
return;
if (graph_view->dirty_flags)
graph_view_update (graph_view, graph_view->dirty_flags);
}
void
graph_view_set_bbox (GraphView *graph_view, ArtIRect *bbox)
{
g_return_if_fail (graph_view != NULL);
g_return_if_fail (IS_GRAPH_VIEW (graph_view));
g_return_if_fail (bbox != NULL);
if (graph_view->bbox == *bbox)
return;
graph_view->bbox = *bbox;
graph_view_update (graph_view);
gnome_canvas_update_bbox (
GNOME_CANVAS_ITEM (graph_view),
bbox->x0, bbox->y0,
bbox->x1, bbox->y1);
}
static void
graph_view_init (GtkObject *object)
{
GraphView *graph_view = GRAPH_VIEW (object);
graph_view->bbox.x0 = 0;
graph_view->bbox.y0 = 0;
graph_view->bbox.x1 = 1;
graph_view->bbox.y1 = 1;
graph_view->frozen = 1;
graph_view->dirty = TRUE;
}
void
graph_view_set_graph (GraphView *graph_view, Graph *graph)
{
g_return_if_fail (graph_view != NULL);
g_return_if_fail (IS_GRAPH_VIEW (graph_view));
g_return_if_fail (graph != NULL);
g_return_if_fail (IS_GRAPH (graph));
graph_view->graph = graph;
graph_view_thaw (graph_view);
}
GtkType
graph_view_get_type (void)
{
static GtkType type = 0;
if (!type){
GtkTypeInfo info = {
"GraphView",
sizeof (GraphView),
sizeof (GraphViewClass),
(GtkClassInitFunc) graph_view_class_init,
(GtkObjectInitFunc) graph_view_init,
NULL, /* reserved 1 */
NULL, /* reserved 2 */
(GtkClassInitFunc) NULL
};
type = gtk_type_unique (gnome_canvas_item_get_type (), &info);
}
return type;
}
......@@ -10,10 +10,6 @@
#define IS_GRAPH_VIEW(o) (GTK_CHECK_TYPE ((o), GRAPH_VIEW_TYPE))
#define IS_GRAPH_VIEW_CLASS(k) (GTK_CHECK_CLASS_TYPE ((k), GRAPH_VIEW_TYPE))
#define DIRTY_BBOX 1
#define DIRTY_TYPE 2
#define DIRTY_SHAPE 4
struct _GraphView {
GnomeCanvasItem base;
......
......@@ -25,21 +25,21 @@ graph_destroy (GtkObject *object)
}
static void
graph_update (Graph *graph)
graph_update (Graph *graph, int dirty_flags)
{
GSList *l;
if (graph->frozen){
graph->need_update = TRUE;
graph->dirty_flags |= dirty_flags;
if (graph->frozen)
return;
}
for (l = graph->views; l; l = l->next){
GraphView *graph_view = GRAPH_VIEW (l->data);
graph_view_update (graph_view);
graph_view_update (graph_view, graph->dirty_flags);
}
graph->need_update = FALSE;
graph->dirty_flags = 0;
}
GNOME_Graph_ChartType
......@@ -50,8 +50,96 @@ impl_graph_get_chart_type (PortableServer_Servant servant, CORBA_Environment * e
return graph->chart_type;
}
static void
graph_compute_divisions (Graph *graph)
{
const int n = graph->n_series;
int i;
int len = 0;
/* Compute max lenght */
for (i = 0; i < n; i++){
int l;
l = graph_vector_count (graph->vectors [i]);
if (l > len)
len = l;
}
if (len == 0)
len = 1;
graph->divisions = len;
}
static void
graph_set_low_high (Graph *graph, double low, double high)
{
graph->low = low;
graph->high = high;
graph->real_low = low;
graph->real_high = high;
}
static void
graph_compute_dimensions (Graph *graph)
{
const int n = graph->n_series;
double low = 0.0, high = 0.0;
int i;
graph_compute_divisions (graph);
for (i = 0; i < n; i++){
double l, h;
graph_vector_low_high (graph->vectors [i], &l, &h);
if (l < low)
low = l;
if (h > high)
high = h;
}
graph_set_low_high (graph, low, high);
}
static void
graph_compute_stacked_dimensions (Graph *graph)
{
const int n = graph->n_series;
int len = 0;
double high, low;
graph_compute_divisions (graph);
high = low = 0.0;
for (x = 0; x < len; x++){
double s_high;
doublw s_low;
s_high = s_low = 0.0;
for (i = 0; i < n; i++){
double v;
v = graph_vector_get_double (graph->vectors [i], x);
if (v < 0)
s_low += v;
else
s_high += v;
}
if (s_low < low)
low = s_low;
if (s_high > high)
high = s_high;
}
graph_set_low_high (graph, low, high);
}
void
impl_graph_set_chart_type (PortableServer_Servant servant, GNOME_Graph_ChartType value, CORBA_Environment * ev)
impl_graph_set_chart_type (PortableServer_Servant servant,
GNOME_Graph_ChartType value,
CORBA_Environment * ev)
{
Graph *graph = graph_from_servant (servant);
......@@ -61,13 +149,16 @@ impl_graph_set_chart_type (PortableServer_Servant servant, GNOME_Graph_ChartType
graph->chart_type = value;
switch (value){
case GNOME_Graph_CHART_TYPE_CLUSTERED:
graph_compute_dimensions (graph);
break;
case GNOME_Graph_CHART_TYPE_STACKED:
graph_compute_series_sum_max (graph);
graph_compute_stacked_dimensions (graph);
break;
case GNOME_Graph_CHART_TYPE_STACKED_FULL:
graph_compute_stacked_dimensions (graph);
break;
}
graph_update (graph);
......@@ -258,8 +349,8 @@ impl_graph_thaw (PortableServer_Servant servant, CORBA_Environment * ev)
Graph *graph = graph_from_servant (servant);
graph->frozen--;
if (graph->frozen == 0 && graph->need_update)
graph_update (graph);
if ((graph->frozen == 0) && (graph->dirty_flags != 0))
graph_update (graph, 0);
}
static void
......@@ -309,6 +400,7 @@ graph_class_init (GtkObjectClass *object_class)
static void
graph_init (GtkObject *object)
{
graph->dirty_flags = 0;
}
GtkType
......
......@@ -34,19 +34,29 @@ typedef struct {
GSList *views;
int frozen;
gboolean need_update;
int dirty_flags;
/*
* Number of series we hold
*/
int n_series;
Series *series;
int n_series;
GraphVector *vectors;
/*
* Series boundings
*/
double low, high;
double real_low, real_high;
} Graph;
typedef struct {
GnomeObjectClass parent_class;
} GraphClass;
#define DIRTY_BBOX 1
#define DIRTY_TYPE 2
#define DIRTY_SHAPE 4
GtkType graph_get_type (void);
Graph *graph_new (void);
......
/*
* Vector CORBA server
*
* Author:
* Miguel de Icaza (miguel@kernel.org)
*
* (C) 1999 International GNOME Support
*/
#include <config.h>
#include "src/Gnumeric.h"
#include <bonobo/gnome-object.h>
static GnomeObjectClass *vector_parent_class;
/* The entry point vectors for the server we provide */
POA_GNOME_Gnumeric_Vector__epv vector_epv;
POA_GNOME_Gnumeric_Vector__vepv vector_vepv;
#define vector_from_servant(x) VECTOR (gnome_object_from_servant (x))
static void
vector_destroy (GtkObject *object)
{
GTK_OBJECT_CLASS (vector_parent_class)->destroy (object);
}
static CORBA_boolean
impl_vector_only_numbers (PortableServer_Servant servant, CORBA_Environment *ev)
{
Vector *vec = vector_from_servant (servant);
return vec->type (vec->data);
}
static GNOME_Gnumeric_DoubleVec *
impl_vector_get_numbers (PortableServer_Servant servant, CORBA_short pos, CORBA_Environment * ev)
{
return vec->get_numbers (vec->data);
}
static GNOME_Gnumeric_VecValueVec *
impl_vector_get_vec_values (PortableServer_Servant servant, CORBA_Environment * ev)
{
Vector *vec = vector_from_servant (servant);
return vec->get_values (vec->data);
}
static void
impl_vector_set (PortableServer_Servant servant, CORBA_short pos,
GNOME_Gnumeric_VecValue *val, CORBA_Environment *ev)
{
Vector *vec = vector_from_servant (servant);
vec->set (pos, val, ev, vec->data);
}
static void
impl_vector_set_notify (PortableServer_Servant servant,
GNOME_Gnumeric_VectorNotify vector_notify,
CORBA_Environment *ev)
{
Vector *vec = vector_from_servant (servant);
vec->notify = vector_notify;
}
static CORBA_short
impl_vector_count (PortableServer_Servant servant, CORBA_Environment * ev)
{
Vector *vec = vector_from_servant (servant);
return vec->count (vec->data);
}
static void
init_vector_corba_class (void)
{
vector_epv.only_numbers = impl_vector_only_numbers;
vector_epv.get_numbers = impl_vector_get_numbers;
vector_epv.get_vec_values = impl_vector_get_vec_values;
vector_epv.set = impl_vector_set;
vector_epv.count = impl_vector_count;
vector_epv.set_notify = impl_vector_set_notify;
vector_vepv.GNOME_Unknown_epv = &gnome_object_epv;
vector_vepv.GNOME_Gnumeric_Vector_epv = &vector_epv;
}
static void
vector_class_init (GtkObjectClass *object_class)
{
vector_parent_class = gtk_type_class (gnome_object_get_type ());
object_class->destroy = vecto_destroy;
init_vector_corba_class ();
}
static void
vector_init (GtkObject *object)
{
Vector *vector = VECTOR (object);
vector->notify = CORBA_OBJECT_NIL;
}
GtkType
vector_get_type (void)
{
static GtkType type = 0;
if (!type){
GtkTypeInfo info = {
"GnumericVector",
sizeof (Graph),
sizeof (GraphClass),
(GtkClassInitFunc) vector_class_init,
(GtkObjectInitFunc) vector_init,
NULL, /* reserved 1 */
NULL, /* reserved 2 */
(GtkClassInitFunc) NULL
};
type = gtk_type_unique (gnome_object_get_type (), &info);
}
return type;
}
GNOME_Gnumeric_Vector
vector_corba_object_create (GnomeObject *object)
{
POA_GNOME_Gnumeric_Vector *servant;
CORBA_Environment ev;
servant = (POA_GNOME_View *) g_new0 (GnomeObjectServant, 1);
servant->vepv = &gnome_view_vepv;
CORBA_exception_init (&ev);
POA_GNOME_Gnumeric_Vector__init ((PortableServer_Servant) servant, &ev);
if (ev._major != CORBA_NO_EXCEPTION){
g_free (servant);
CORBA_exception_free (&ev);
return CORBA_OBJECT_NIL;
}
CORBA_exception_free (&ev);
return (GNOME_View) gnome_object_activate_servant (object, servant);
}
Vector *
vector_new (VectorTypeFn type, VectorGetNumFn get_numbers,
VectorGetValFn get_values, VectorSetFn set,
VectorLenFn len, VectorNotifyFn notify,
void *data)
{
Vector *vector;
GNOME_Gnumeric_Vector corba_vector;
g_return_val_if_fail (type != NULL, NULL);
g_return_val_if_fail (get_numbers != NULL, NULL);
g_return_val_if_fail (get_values != NULL, NULL);
g_return_val_if_fail (set != NULL, NULL);
g_return_val_if_fail (notify != NULL, NULL);
g_return_val_if_fail (len != NULL, NULL);
vector = gtk_type_new (vector_get_type ());
corba_vector = vector_corba_object_create (GNOME_OBJECT (vector));
if (corba_vector == NULL){
gtk_object_destroy (GTK_OBJECT (vector));
return NULL;
}
gnome_object_construct (GNOME_OBJECT (vector));
vector->type = type;
vector->get_numbers = get_numbers;
vector->get_values = get_values;
vector->set = set;
vector->notify = notify;
vector->len = len;
return vector;
}
void
vector_changed (Vector *vector, int pos)
{
CORBA_Environment ev;
g_return_if_fail (vector != NULL);
g_return_if_fail (IS_VECTOR (vector));
if (vector->notify == CORBA_OBJECT_NIL)
return;
CORBA_exception_init (&ev);
GNOME_Gnumeric_VectorNotify_changed (vector->notify, pos, &ev);
CORBA_exception_free (&ev);
}
/* -*- Mode: C; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 8 -*- */
#ifndef GNUMERIC_VECTOR_H_
#define GNUMERIC_VECTOR_H_
#include <libgnome/gnome-defs.h>
#include <bonobo/gnome-object.h>
#include "src/Gnumeric.h"
BEGIN_GNOME_DECLS
#define VECTOR_TYPE (vector_get_type ())
#define VECTOR(o) (GTK_CHECK_CAST ((o), VECTOR_TYPE, Vector))
#define VECTOR_CLASS(k) (GTK_CHECK_CLASS_CAST((k), VECTOR_TYPE, VectorClass))
#define IS_VECTOR(o) (GTK_CHECK_TYPE ((o), VECTOR_TYPE))
#define IS_VECTOR_CLASS(k) (GTK_CHECK_CLASS_TYPE ((k), VECTOR_TYPE))
typedef GNOME_Gnumeric_DoubleVec *(*VectorGetNumFn)(void *data);
typedef GNOME_Gnumeric_VecValueVec *(*VectorGetValFn)(void *data);
typedef void (*VectorSetFn) (CORBA_short pos, double value, CORBA_Environment *ev, void *data);
typedef CORBA_short (*VectorLenFn) (void *data);
typedef CORBA_boolean (*VectorTypeFn)(void *data);
typedef struct {
GnomeObject base;
VectorTypeFn type;
VectorGetNumFn get_numbers;
VectorGetValFn get_values;
VectorSetFn set;
VectorLenFn len;
GNOME_Gnumeric_VectorNotify notify;
void *user_data;
} Vector;
typedef struct {
GnomeObjectClass parent_class;
} VectorClass;
GtkType vector_get_type (void);
Vector *vector_new (VectorGetFn get, VectorSetFn set,
VectorLenFn len, VectorNotifyFn notify,
void *data);
void vector_changed (Vector *vector, int pos);
END_GNOME_DECLS
#endif /* GRAH_VECTOR_H_ */
......@@ -26,11 +26,12 @@ module GNOME {
};
union VecValue switch (short) {
case VALUE_BOOLEAN: boolean v_bool;
case VALUE_FLOAT: double v_float;
case VALUE_INTEGER: long v_int;
case VALUE_STRING: string str;
};
typedef sequence<VecValue> VecValueVec;
typedef sequence<double> DoubleVec;
};
};
......
......@@ -238,20 +238,16 @@ module GNOME {
// Interfaces for accessing value sets from linear arrays.
// Mainly used for graphics.
//
interface VectorNotify {
void changed (in short pos);
interface VectorNotify : GNOME::Unknown {
void changed (in short low, in show high);
};
interface Vector : GNOME::Unknown {
exception OutOfRange {};
/**
* get:
* @pos: index to fetch
*