Commit bf209b0c authored by Arturo Espinosa's avatar Arturo Espinosa

More work.



More work.

Miguel.
parent 14251401
......@@ -8,8 +8,7 @@
*/
#include <bonobo.idl>
#include "Gnumeric-value.idl"
#include "src/Gnumeric.idl"
module GNOME {
......@@ -194,9 +193,6 @@ module GNOME {
//
void freeze ();
void thaw ();
void reset_series ();
void add_series (in string label, in Vector vector);
};
//
......@@ -209,9 +205,12 @@ module GNOME {
// * The axis
// * The chart background
//
interface Layout : GNOME::Unknown {
interface Layout : GNOME::Embeddable {
Chart get_chart ();
Axis get_axis (in AxisType axis);
void reset_series ();
void add_series (in GNOME::Gnumeric::Vector vector);
};
};
};
......@@ -19,10 +19,18 @@ GRAPH_CORBA_GENERATED = \
graph_SOURCES = \
graph.c \
graph.h \
graph-vector.c \
graph-vector.h \
graph-view.c \
graph-view.h \
graph-view-colbar.c \
graph-view-colbar.h \
graph-view-plot.c \
graph-view-plot.h \
layout.c \
layout.h \
layout-view.c \
layout-view.h \
vector.c \
vector.h \
$(GRAPH_CORBA_GENERATED)
......@@ -32,7 +40,7 @@ BUILT_SOURCES = $(GRAPH_CORBA_GENERATED)
$(GRAPH_CORBA_GENERATED): my_graph_idl
my_graph_idl: Graph.idl $(top_srcdir)/src/Gnumeric-value.idl $(top_srcdir)/src/Gnumeric.idl
orbit-idl -I`$(GNOME_CONFIG) --datadir`/idl -I$(srcdir) $(srcdir)/Graph.idl
orbit-idl -I`$(GNOME_CONFIG) --datadir`/idl -I$(srcdir) -I$(top_srcdir) $(srcdir)/Graph.idl
touch my_graph_idl
CLEANFILES = my_graph_idl
......
This is a roadmap of the files that compose the GNOME Graphics
component.
The Graph component is a Bonobo component that implements the
GNOME::Embeddable interface for being embedded.
The main entry point is the GNOME::Graph::Layout interface, this is an
interface that enables the user to control the various visual elements
of a graphic.
Separate interfaces are used for the different components of the user
interface.
* Graph.idl:
CORBA interfaces for the Graphic module. Includes the
Gnumeric.idl interfaces.
* layout.c, layout.h:
Contains the implementation of the GNOME::Graph::Layout
interface. This object implements a GNOME::Embeddable and it
is the repository for the various elements of a plot.
The object is a derivative of a GnomeEmbeddable Bonobo object.
* layout-view.c, layout-view.h:
These implement the Bonobo views for the Layout embeddable
component. They are GnomeCanvas derivatives and they take
care of laying out the various visual elements that compose
the plot.
* graph.c, graph.h:
These implement a plain GnomeObject that controls the actual
plotting engine. The graphic is manipulated trough CORBA by
changing the different attributes exposed by the interface.
Common operations for all the graphic types are done here,
like computing the ranges of the information to be plotted.
* graph-view.h, graph-view.c:
These are the views of the Graph model. The views are
implemented as GnomeCanvasItems. They are created by the
LayoutView object.
This file implements the "dispatching" of the actual rendering
to rendering routines implemented in the various other
modules.
* vector.c, vector.h
Vectors represent a one-dimension array that can contain
VecValues (strings or doubles). Sometimes the plotting engine
does not care about the string, so it requests that any string
found is converted to a double value.
Vectors are GnomeObjects and are intended to be instantiated
for each series being plotted in the container applications.
The Vector object implementation uses callbacks to simplify
testing and prototyping. The Gnumeric version might just hook
up directly into Gnumeric.
Vectors are transfered to the Layout using the the add_series
method in the Layout.
* graph-vector.c, graph-vector.h:
These files implement the access to the remote Vector object
and are intended to provide a basic "cache" mechanism for the
actual data.
......@@ -23,6 +23,7 @@ typedef struct {
int xl, yl;
double units_per_slot;
double size; /* |low| + |high| */
double scale;
} ColbarDrawCtx;
static double
......@@ -31,6 +32,12 @@ colbar_map_point (ColbarDrawCtx *ctx, double point)
return (fabs (ctx->graph->low) + point) / ctx->scale;
}
static void
column_draw (ColbarDrawCtx *ctx, int item,
double x1, double y1, double x2, double y2)
{
}
static void
graph_view_colbar_draw_nth_clustered (ColbarDrawCtx *ctx, int item)
{
......@@ -53,6 +60,8 @@ graph_view_colbar_draw_nth_clustered (ColbarDrawCtx *ctx, int item)
static void
graph_view_colbar_draw_nth_stacked (ColbarDrawCtx *ctx, int item)
{
const int n_series = ctx->graph->n_series;
int item_base = item * ctx->units_per_slot;
double last_pos = 0.0;
double last_neg = 0.0;
int i;
......@@ -83,6 +92,8 @@ graph_view_colbar_draw_nth_stacked (ColbarDrawCtx *ctx, int item)
static void
graph_view_colbar_draw_nth_stacked_full (ColbarDrawCtx *ctx, int item)
{
const int n_series = ctx->graph->n_series;
int item_base = item * ctx->units_per_slot;
double last_pos, last_neg;
double total_pos, total_neg;
double *values;
......@@ -103,13 +114,13 @@ graph_view_colbar_draw_nth_stacked_full (ColbarDrawCtx *ctx, int item)
}
for (i = 0; i < n_series; i++){
double v;
if (values [i] >= 0){
double v;
if (total_pos == 0.0)
v = 0.0;
else
v = (values [i] * graph->high) / total_pos;
v = (values [i] * ctx->graph->high) / total_pos;
column_draw (
ctx, i,
......@@ -118,10 +129,12 @@ graph_view_colbar_draw_nth_stacked_full (ColbarDrawCtx *ctx, int item)
last_pos + v);
last_pos += v;
} else {
double v;
if (total_neg == 0.0)
v = 0.0;
else
v = (values [i] * graph->low) / total_neg;
v = (values [i] * ctx->graph->low) / total_neg;
column_draw (
ctx, i,
......@@ -171,22 +184,19 @@ graph_view_colbar_draw (GraphView *graph_view, GdkDrawable *drawable, int x, int
ctx.xl = graph_view->bbox.x1 - graph_view->bbox.x0;
ctx.size = fabs (ctx.graph->low) + fabs (ctx.graph->high);
if (graph_view->graph->direction == GNOME_GRAPH_DIR_BAR){
if (graph_view->graph->direction == GNOME_Graph_DIR_BAR){
ctx.units_per_slot = ctx.yl / graph_view->graph->divisions;
first = y / units_per_slot;
last = (y + width) / units_per_slot;
ctx.scale = xl / ctx->size;
first = y / ctx.units_per_slot;
last = (y + width) / ctx.units_per_slot;
ctx.scale = ctx.xl / ctx.size;
} else {
ctx.units_per_slot = xl / graph_view->graph->divisions;
first = x / units_per_slot;
last = (x + width) / units_per_slot;
ctx.scale = yl / ctx->size;
ctx.units_per_slot = ctx.xl / graph_view->graph->divisions;
first = x / ctx.units_per_slot;
last = (x + width) / ctx.units_per_slot;
ctx.scale = ctx.yl / ctx.size;
}
for (i = first; i <= last; i++){
int base_x = i * units_per_slot;
for (i = first; i <= last; i++)
graph_view_colbar_draw_nth (&ctx, i);
};
}
......@@ -9,9 +9,13 @@
#include <config.h>
#include <math.h>
#include <libgnomeui/gnome-canvas.h>
#include <libgnomeui/gnome-canvas-util.h>
#include "graph.h"
#include "graph-view.h"
#include "graph-view-colbar.h"
#include "graph-view-plot.h"
#include "graph-view-scatter.h"
#include "graph-view-stock.h"
enum {
ARG_BBOX,
......@@ -24,12 +28,15 @@ static GraphViewClass *graph_view_class;
static void
graph_view_destroy (GtkObject *object)
{
GraphView *graph_view = GRAPH_VIEW (object);
GTK_OBJECT_CLASS (graph_view_parent_class)->destroy (object);
}
static void
graph_view_canvas_update (GnomeCanvasItem *item, double *affine, ArtSVP *clip_path, int flags)
{
GraphView *graph_view = GRAPH_VIEW (item);
int i;
if (graph_view_parent_class->update)
(*graph_view_parent_class->update)(item, affine, clip_path, flags);
......@@ -41,7 +48,6 @@ static void
graph_view_realize (GnomeCanvasItem *item)
{
GraphView *graph_view;
GdkWindow *window;
if (graph_view_parent_class->realize)
(*graph_view_parent_class->realize)(item);
......@@ -52,8 +58,6 @@ graph_view_realize (GnomeCanvasItem *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);
}
......@@ -106,9 +110,6 @@ graph_view_draw (GnomeCanvasItem *item, GdkDrawable *drawable, int x, int y, int
x, y, width, height);
break;
}
graph_view_
}
static double
......@@ -121,8 +122,9 @@ graph_view_point (GnomeCanvasItem *item, double x, double y, int cx, int cy,
}
static gint
item_cursor_event (GnomeCanvasItem *item, GdkEvent *event)
graph_view_event (GnomeCanvasItem *item, GdkEvent *event)
{
return 0;
}
static void
......@@ -143,7 +145,6 @@ graph_view_class_init (GtkObjectClass *object_class)
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;
}
......@@ -161,7 +162,7 @@ graph_view_update (GraphView *graph_view, int dirty_flags)
graph_view->dirty_flags &= ~DIRTY_TYPE;
}
if (graph_view->dirty & (DIRTY_BBOX|DIRTY_SHAPE)){
if (graph_view->dirty_flags & (DIRTY_BBOX|DIRTY_SHAPE)){
graph_view->dirty_flags &= ~(DIRTY_BBOX | DIRTY_SHAPE);
}
}
......@@ -195,12 +196,15 @@ 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)
if ((graph_view->bbox.x0 == bbox->x0) &&
(graph_view->bbox.x1 == bbox->x1) &&
(graph_view->bbox.y0 == bbox->y0) &&
(graph_view->bbox.y1 == bbox->y1))
return;
graph_view->bbox = *bbox;
graph_view_update (graph_view);
graph_view_update (graph_view, DIRTY_BBOX);
gnome_canvas_update_bbox (
GNOME_CANVAS_ITEM (graph_view),
bbox->x0, bbox->y0,
......@@ -218,7 +222,7 @@ graph_view_init (GtkObject *object)
graph_view->bbox.y1 = 1;
graph_view->frozen = 1;
graph_view->dirty = TRUE;
graph_view->dirty_flags = DIRTY_ALL;
}
void
......
......@@ -16,7 +16,7 @@ struct _GraphView {
/*
* Display control
*/
Int dirty_flags;
int dirty_flags;
int frozen;
/*
......@@ -42,5 +42,6 @@ typedef struct {
GtkType graph_view_get_type (void);
void graph_view_update (GraphView *graph_view, int dirty_flags);
void graph_view_set_graph (GraphView *graph_view, Graph *graph);
void graph_view_set_bbox (GraphView *graph_view, ArtIRect *bbox);
#endif /* GRAPH_GRAPH_VIEW_H_ */
......@@ -7,7 +7,9 @@
* (C) 1999 International GNOME Support
*/
#include <config.h>
#include <gtk/gtksignal.h>
#include "graph.h"
#include "graph-vector.h"
#include "graph-view.h"
static GnomeObjectClass *graph_parent_class;
......@@ -53,7 +55,7 @@ impl_graph_get_chart_type (PortableServer_Servant servant, CORBA_Environment *ev
static void
graph_compute_divisions (Graph *graph)
{
const int n = graph->n_series;
const int n = graph->layout->n_series;
int i;
int len = 0;
......@@ -84,7 +86,7 @@ graph_set_low_high (Graph *graph, double low, double high)
static void
graph_compute_dimensions (Graph *graph)
{
const int n = graph->n_series;
const int n = graph->layout->n_series;
double low = 0.0, high = 0.0;
int i;
......@@ -105,8 +107,8 @@ graph_compute_dimensions (Graph *graph)
static void
graph_compute_stacked_dimensions (Graph *graph)
{
const int n = graph->n_series;
int len = 0;
const int n = graph->layout->n_series;
int len = 0, x;
double high, low;
graph_compute_divisions (graph);
......@@ -114,8 +116,9 @@ graph_compute_stacked_dimensions (Graph *graph)
for (x = 0; x < len; x++){
double s_high;
doublw s_low;
double s_low;
int i;
s_high = s_low = 0.0;
for (i = 0; i < n; i++){
......@@ -159,9 +162,12 @@ impl_graph_set_chart_type (PortableServer_Servant servant,
case GNOME_Graph_CHART_TYPE_STACKED_FULL:
graph_compute_stacked_dimensions (graph);
break;
default:
break;
}
graph_update (graph);
graph_update (graph, DIRTY_TYPE | DIRTY_SHAPE);
}
static GNOME_Graph_PlotMode
......@@ -181,7 +187,7 @@ impl_graph_set_plot_mode (PortableServer_Servant servant,
if (graph->plot_mode != value){
graph->plot_mode = value;
graph_update (graph);
graph_update (graph, DIRTY_SHAPE | DIRTY_TYPE);
}
}
......@@ -202,7 +208,7 @@ impl_graph_set_col_bar_mode (PortableServer_Servant servant,
if (graph->col_bar_mode != value){
graph->col_bar_mode = value;
graph_update (graph);
graph_update (graph, DIRTY_SHAPE);
}
}
......@@ -223,7 +229,7 @@ impl_graph_set_direction (PortableServer_Servant servant,
if (graph->direction != value){
graph->direction = value;
graph_update (graph);
graph_update (graph, DIRTY_SHAPE);
}
}
......@@ -244,7 +250,7 @@ impl_graph_set_line_mode (PortableServer_Servant servant,
if (graph->line_mode != value){
graph->line_mode = value;
graph_update (graph);
graph_update (graph, DIRTY_SHAPE);
}
}
......@@ -265,7 +271,7 @@ impl_graph_set_pie_mode (PortableServer_Servant servant,
if (graph->pie_mode != value){
graph->pie_mode = value;
graph_update (graph);
graph_update (graph, DIRTY_SHAPE);
}
}
......@@ -286,7 +292,7 @@ impl_graph_set_pie_dim (PortableServer_Servant servant,
if (graph->pie_dim != value){
graph->pie_dim = value;
graph_update (graph);
graph_update (graph, DIRTY_SHAPE);
}
}
......@@ -307,7 +313,7 @@ impl_graph_set_scatter_mode (PortableServer_Servant servant,
if (graph->scatter_mode != value){
graph->scatter_mode = value;
graph_update (graph);
graph_update (graph, DIRTY_SHAPE);
}
}
......@@ -328,7 +334,7 @@ impl_graph_set_scatter_conn (PortableServer_Servant servant,
if (graph->scatter_conn != value){
graph->scatter_conn = value;
graph_update (graph);
graph_update (graph, DIRTY_SHAPE);
}
}
......@@ -347,7 +353,7 @@ impl_graph_set_surface_mode (PortableServer_Servant servant, GNOME_Graph_Surface
if (graph->surface_mode != value){
graph->surface_mode = value;
graph_update (graph);
graph_update (graph, DIRTY_SHAPE);
}
}
......@@ -369,36 +375,6 @@ impl_graph_thaw (PortableServer_Servant servant, CORBA_Environment *ev)
graph_update (graph, 0);
}
static void
impl_reset_series (PortableServer_Servant servant, CORBA_Environment *ev)
{
Graph *graph = graph_from_servant (servant);
const int n = graph->n_series;
int i;
for (i = 0; i < n; i++)
graph_vector_destroy (graph->vectors [i]);
g_free (graph->vectors);
graph->vectors = NULL;
graph->n_series = 0;
}
static void
impl_add_series (PortableServer_Servant servant, GNOME_Gnumeric_Vector vector, CORBA_Environment *ev)
{
Graph *graph = graph_from_servant (servant);
GraphVector *v;
v = g_renew (GraphVector *, graph->vectors, graph->n_series+1);
if (v == NULL){
CORBA_exception_set_system (ev, ex_CORBA_NO_MEMORY, CORBA_COMPLETED_NO);
return;
}
graph->series [graph->n_series] = graph_vector_new (vector, NULL, NULL, 0);
graph->n_series++;
}
static void
init_graph_corba_class (void)
{
......@@ -426,9 +402,6 @@ init_graph_corba_class (void)
graph_epv.freeze = &impl_graph_freeze;
graph_epv.thaw = &impl_graph_thaw;
graph_epv.reset_series = &impl_reset_series;
graph_epv.add_series = &impl_add_series;
/*
* The Vepv
*/
......@@ -449,6 +422,8 @@ graph_class_init (GtkObjectClass *object_class)
static void
graph_init (GtkObject *object)
{
Graph *graph = GRAPH (object);
graph->dirty_flags = 0;
}
......@@ -475,6 +450,12 @@ graph_get_type (void)
return type;
}
static void
graph_view_destroyed (GraphView *graph_view, Graph *graph)
{
graph->views = g_slist_remove (graph->views, graph_view);
}
void
graph_bind_view (Graph *graph, GraphView *graph_view)
{
......@@ -485,4 +466,7 @@ graph_bind_view (Graph *graph, GraphView *graph_view)
graph_view_set_graph (graph_view, graph);
graph->views = g_slist_prepend (graph->views, graph_view);
gtk_signal_connect (GTK_OBJECT (graph_view), "destroy",
GTK_SIGNAL_FUNC (graph_view_destroyed), graph);
}
......@@ -36,17 +36,13 @@ typedef struct {
int frozen;
int dirty_flags;
/*
* Number of series we hold
*/
int n_series;
GraphVector *vectors;
/*
* Series boundings
*/
double low, high;
double real_low, real_high;
int divisions;
} Graph;
typedef struct {
......@@ -57,13 +53,12 @@ typedef struct {
#define DIRTY_TYPE 2
#define DIRTY_SHAPE 4
GtkType graph_get_type (void);
Graph *graph_new (void);
#define DIRTY_ALL (DIRTY_BBOX | DIRTY_TYPE | DIRTY_SHAPE)
void graph_bind_view (Graph *graph, GraphView *graph_view);
GtkType graph_get_type (void);
Graph *graph_new (Layout *layout);
void graph_get_n_series (Graph *graph);
Series *graph_get_series (Graph *graph, int n);
void graph_bind_view (Graph *graph, GraphView *graph_view);
END_GNOME_DECLS
......
/*
* layout-view.c: A view of the layout. It is a canvas object that
* contains the other pieces of the view
*
* Author:
* Miguel de Icaza (miguel@kernel.org)
*
* (C) 1999 International GNOME Support
*/
#include <config.h>
#include "layout-view.h"
#include "graph-view.h"
static GnomeCanvasClass *layout_view_parent_class;
static void
layout_view_destroy (GtkObject *object)
{
GTK_OBJECT_CLASS (layout_view_parent_class)->destroy (object);
}
GtkWidget *
layout_view_new (Layout *layout)
{
LayoutView *layout_view;
layout_view = gtk_type_new (LAYOUT_VIEW_TYPE);
layout_view->graph_view = GRAPH_VIEW (gnome_canvas_item_new (
gnome_canvas_root (GNOME_CANVAS (layout_view)),
graph_view_get_type (),
NULL));
graph_view_set_graph (layout_view->graph_view, layout->graph);
return GTK_WIDGET (layout);
}
/*
* For now we just cover everything
*/
static void
layout_view_size_allocate (GtkWidget *widget, GtkAllocation *allocation)
{
LayoutView *layout_view = LAYOUT_VIEW (widget);
ArtIRect bbox;
bbox.x0 = allocation->x;
bbox.y0 = allocation->y;
bbox.x1 = allocation->width;
bbox.y1 = allocation->height;
graph_view_set_bbox (layout_view->graph_view, &bbox);
}
static void
layout_view_class_init (GtkObjectClass *object_class)
{
GtkWidgetClass *widget_class = (GtkWidgetClass *) object_class;
object_class->destroy = layout_view_destroy;
widget_class->size_allocate = layout_view_size_allocate;
}
static void
layout_view_init (GtkObject *object)
{
}
GtkType
layout_view_get_type (void)
{
static GtkType type = 0;
if (!type){
GtkTypeInfo info = {
"GraphLayoutViewGnumeric",
sizeof (LayoutView),
sizeof (LayoutViewClass),
(GtkClassInitFunc) layout_view_class_init,
(GtkObjectInitFunc) layout_view_init,
NULL, /* reserved 1 */
NULL, /* reserved 2 */
(GtkClassInitFunc) NULL
};
type = gtk_type_unique (gnome_canvas_get_type (), &info);
}
return type;
}
/* -*- Mode: C; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 8 -*- */
#ifndef GRAPH_LAYOUT_VIEW_H_
#define GRAPH_LAYOUT_VIEW_H_
#include <libgnome/gnome-defs.h>
#include <libgnomeui/gnome-canvas.h>
#include "layout.h"
#include "graph-view.h"
BEGIN_GNOME_DECLS
#define LAYOUT_VIEW_TYPE (layout_view_get_type ())
#define LAYOUT_VIEW(o) (GTK_CHECK_CAST ((o), LAYOUT_VIEW_TYPE, LayoutView))
#define LAYOUT_VIEW_CLASS(k) (GTK_CHECK_CLASS_CAST((k), LAYOUT_VIEW_TYPE, LayoutViewClass))
#define IS_LAYOUT_VIEW(o) (GTK_CHECK_TYPE ((o), LAYOUT_VIEW_TYPE))
#define IS_LAYOUT_VIEW_CLASS(k) (GTK_CHECK_CLASS_TYPE ((k), LAYOUT_VIEW_TYPE))
typedef struct _LayoutView LayoutView;
struct _LayoutView {
GnomeCanvas canvas;
Layout *layout;
GraphView *graph_view;
};
typedef struct {
GnomeCanvasClass parent_class;
} LayoutViewClass;
GtkType layout_view_get_type (void);
GtkWidget *layout_view_new (Layout *layout);
END_GNOME_DECLS
#endif /* GRAPH_LAYOUT_VIEW_H_ */
/*
* layout.c: Implements the layout for the graphics.
* It keeps track of the graphic, axis, background, etc.
*
* Author:
* Miguel de Icaza (miguel@kernel.org)
*
* (C) 1999 International GNOME Support
*/
#include <config.h>
#include <bonobo/gnome-bonobo.h>
#include "layout.h"
#include "layout-view.h"
static GnomeEmbeddableClass *layout_parent_class;
/* The entry point vectors for the server we provide */
POA_GNOME_Graph_Layout__epv layout_epv;
POA_GNOME_Graph_Layout__vepv layout_vepv;
#define layout_from_servant(x) LAYOUT (gnome_object_from_servant (x))
static void