Commit 4dfac701 authored by Miguel de Icaza's avatar Miguel de Icaza

Pile of work on the graphics component. Works, displays in more modes,



Pile of work on the graphics component.  Works, displays in more modes,
actually the graph is now managed by the layout, need to add more decorative
components to the graphic now.

Miguel.
parent 676c70fb
2000-02-09 Miguel de Icaza <miguel@gnu.org>
* graph-view-colbar.c (graph_view_line_draw_nth_clustered): Added
new graphics mode for column/bar mode (this actually implements
"Lines" and "Areas" from Excel.
(la_draw): Draws lines and areas
(column_draw): Fix to draw correctly on exposes.
(graph_view_colbar_draw): For now render everything, the code that
chose begin/end was broken.
2000-01-30 Miguel de Icaza <miguel@gnu.org>
* graph-view-scatter.c (graph_view_scatter_plot): Pass the proper
......
......@@ -27,14 +27,6 @@ column_draw (ViewDrawCtx *ctx, int item,
{
int height, width, px, py;
/*
* Adjust for pixmap offset
*/
x1 -= ctx->x;
x2 -= ctx->x;
y1 -= ctx->y;
y2 -= ctx->y;
if (ctx->graph->direction == GNOME_Graph_DIR_BAR){
py = MIN (x1, x2);
height = fabs (x2-x1);
......@@ -52,13 +44,18 @@ column_draw (ViewDrawCtx *ctx, int item,
width = x2 - x1;
}
px -= ctx->x;
py -= ctx->y;
gdk_draw_rectangle (
ctx->drawable, ctx->graph_view->fill_gc, TRUE,
px, py, width, height);
px + ctx->graph_view->bbox.x0, py + ctx->graph_view->bbox.y0,
width, height);
gdk_draw_rectangle (
ctx->drawable, ctx->graph_view->outline_gc, FALSE,
px, py, width, height);
px + ctx->graph_view->bbox.x0, py + ctx->graph_view->bbox.y0,
width, height);
}
static void
......@@ -206,16 +203,80 @@ graph_view_colbar_draw_nth (ViewDrawCtx *ctx, int item)
break;
default:
g_error ("This mode does not support Column/Bar plotting");
g_error ("Unsupported chart_type for this mode");
}
}
static void
graph_view_draw_area (ViewDrawCtx *ctx, int first, int last)
la_draw (ViewDrawCtx *ctx, int item, gboolean draw_area, Symbol sym,
double x1, double x2,
double ya1, double yb1,
double ya2, double yb2)
{
#if 0
ArtIRect *bbox = &ctx->graph_view->bbox;
x1 += bbox->x0 - ctx->x;
x2 += bbox->x0 - ctx->x;
yb1 += bbox->y0 - ctx->y;
ya1 += bbox->y0 - ctx->y;
ya2 += bbox->y0 - ctx->y;
yb2 += bbox->y0 - ctx->y;
if (draw_area){
}
gdk_draw_line (ctx->drawable, ctx->graph_view->outline_gc, x1, yb1, x2, yb2);
symbol_draw (ctx, sym, x1, yb1);
}
static void
graph_view_line_draw_nth_clustered (ViewDrawCtx *ctx, int item, gboolean draw_area)
{
const int n_series = ctx->graph->layout->n_series;
const int item_base = item * ctx->units_per_slot + ctx->margin;
const int col_width = (ctx->units_per_slot - (ctx->margin * 2)) / n_series;
int i;
for (i = 0; i < n_series; i++){
GraphVector *vector = ctx->graph->layout->vectors [i];
Symbol sym;
printf ("Plotting item=%d, x=%d\n", item, i);
setup_gc (ctx, i, item);
sym = symbol_setup (ctx, i);
la_draw (
ctx, item, draw_area, sym,
item * ctx->units_per_slot + ctx->margin,
(item+1) * ctx->units_per_slot + ctx->margin,
colbar_map_point (ctx, 0.0),
colbar_map_point (ctx, graph_vector_get_double (vector, item)),
colbar_map_point (ctx, 0.0),
colbar_map_point (ctx, graph_vector_get_double (vector, item + 1)));
}
#endif
}
static void
graph_view_draw_area (ViewDrawCtx *ctx, int item, gboolean draw_area)
{
switch (ctx->graph->chart_type){
case GNOME_Graph_CHART_TYPE_CLUSTERED:
graph_view_line_draw_nth_clustered (ctx, item, draw_area);
break;
case GNOME_Graph_CHART_TYPE_STACKED:
/* graph_view_line_draw_nth_stacked (ctx, item, draw_area); */
break;
case GNOME_Graph_CHART_TYPE_STACKED_FULL:
/* graph_view_line_draw_nth_stacked_full (ctx, item, draw_area); */
break;
default:
g_error ("This mode does not support Column/Bar plotting");
}
}
void
......@@ -225,12 +286,12 @@ graph_view_colbar_draw (GraphView *graph_view, GdkDrawable *drawable, int x, int
int first, last, i;
gboolean is_bar;
printf ("Divisions: %d\n", graph_view->graph->divisions);
printf ("Divisions: %d %d %d\n", graph_view->graph->divisions, x, y);
if (graph_view->graph->divisions == 0)
return;
setup_view_ctx (&ctx, graph_view, drawable, NULL, x, y, width, height);
setup_view_ctx (&ctx, graph_view, drawable, graph_view->fill_gc, x, y, width, height);
is_bar = ctx.graph->direction == GNOME_Graph_DIR_BAR;
if (ctx.graph->plot_mode != GNOME_Graph_PLOT_COLBAR)
......@@ -238,13 +299,14 @@ graph_view_colbar_draw (GraphView *graph_view, GdkDrawable *drawable, int x, int
if (is_bar){
ctx.units_per_slot = ctx.yl / ctx.graph->divisions;
first = y / ctx.units_per_slot;
last = (y + width) / ctx.units_per_slot;
/* first = y / ctx.units_per_slot; */
/* last = (y + width) / ctx.units_per_slot; */
ctx.scale = ctx.xl / ctx.graph->y_size;
} else {
ctx.units_per_slot = ctx.xl / ctx.graph->divisions;
first = x / ctx.units_per_slot;
last = (x + width) / ctx.units_per_slot;
/* first = x / ctx.units_per_slot; */
/* last = (x + width) / ctx.units_per_slot; */
ctx.scale = ctx.yl / ctx.graph->y_size;
}
......@@ -254,6 +316,9 @@ graph_view_colbar_draw (GraphView *graph_view, GdkDrawable *drawable, int x, int
ctx.margin = ctx.units_per_slot / 20;
ctx.inter_item_margin = 0;
first = 0;
last = ctx.graph->divisions - 1;
switch (ctx.graph->plot_mode){
case GNOME_Graph_PLOT_COLBAR:
for (i = first; i <= last; i++)
......@@ -261,9 +326,17 @@ graph_view_colbar_draw (GraphView *graph_view, GdkDrawable *drawable, int x, int
break;
case GNOME_Graph_PLOT_AREA:
case GNOME_Graph_PLOT_LINES:
graph_view_draw_area (&ctx, first, last);
case GNOME_Graph_PLOT_LINES: {
gboolean draw_area;
draw_area = ctx.graph->plot_mode == GNOME_Graph_PLOT_AREA;
for (i = first; i <= last; i++)
graph_view_draw_area (&ctx, i, draw_area);
break;
}
} /* switch */
}
......@@ -86,14 +86,6 @@ graph_view_scatter_plot (GraphView *graph_view, GdkDrawable *drawable,
setup_view_ctx (&ctx, graph_view, drawable, graph_view->fill_gc, x, y, width, height);
ctx.dim = MIN (ctx.xl, ctx.yl) / 40;
if (ctx.dim > 8)
ctx.dim = 8;
if (ctx.dim < 2)
ctx.dim = 2;
/*
* FIXME:
*
......
......@@ -122,6 +122,16 @@ setup_view_ctx (ViewDrawCtx *ctx, GraphView *gv, GdkDrawable *d, GdkGC *gc,
ctx->graph = gv->graph;
ctx->yl = gv->bbox.y1 - gv->bbox.y0;
ctx->xl = gv->bbox.x1 - gv->bbox.x0;
ctx->dim = MIN (ctx->xl, ctx->yl) / 40;
if (ctx->dim > 8)
ctx->dim = 8;
if (ctx->dim < 2)
ctx->dim = 2;
}
......@@ -60,8 +60,8 @@ void setup_view_ctx (ViewDrawCtx *ctx, GraphView *gv, GdkDrawable *d, GdkGC *g
*
* y axis also gets flipped.
*/
#define CANVAS_MAP_X(ctx,xv) ((xv) - ctx->x)
#define CANVAS_MAP_Y(ctx,yv) ((ctx->yl - yv) - ctx->y)
#define CANVAS_MAP_X(ctx,xv) ((xv) - ctx->x + ctx->graph_view->bbox.x0)
#define CANVAS_MAP_Y(ctx,yv) ((ctx->yl - yv) - ctx->y + ctx->graph_view->bbox.y0)
#define ADJUST_Y(ctx,y) (y - ctx->graph->low)
......
......@@ -179,6 +179,13 @@ graph_view_draw (GnomeCanvasItem *item, GdkDrawable *drawable, int x, int y, int
GraphView *graph_view = GRAPH_VIEW (item);
Graph *graph = graph_view->graph;
gdk_draw_rectangle (
drawable, graph_view->outline_gc, FALSE,
graph_view->bbox.x0 - x,
graph_view->bbox.y0 - y,
graph_view->bbox.x1 - graph_view->bbox.x0,
graph_view->bbox.y1 - graph_view->bbox.y0);
switch (graph->chart_type){
case GNOME_Graph_CHART_TYPE_CLUSTERED:
case GNOME_Graph_CHART_TYPE_STACKED:
......
......@@ -27,6 +27,7 @@ static void
layout_view_size_allocate (GtkWidget *widget, GtkAllocation *allocation, LayoutView *layout_view)
{
ArtIRect bbox;
Layout *layout = layout_view->layout;
bbox.x0 = allocation->x;
bbox.y0 = allocation->y;
......@@ -34,6 +35,13 @@ layout_view_size_allocate (GtkWidget *widget, GtkAllocation *allocation, LayoutV
bbox.y1 = bbox.y0 + allocation->height;
printf ("BBox=%d, %d, %d, %d\n", bbox.x0, bbox.y0, bbox.x1, bbox.y1);
layout_dim_bbox (&bbox,
allocation->x, allocation->y, allocation->width, allocation->height,
&layout->graph_dim);
printf ("BBox=%d, %d, %d, %d\n", bbox.x0, bbox.y0, bbox.x1, bbox.y1);
graph_view_set_bbox (layout_view->graph_view, &bbox);
gnome_canvas_set_scroll_region (
GNOME_CANVAS (layout_view->canvas),
......@@ -47,7 +55,8 @@ layout_view_new (Layout *layout)
Bonobo_View corba_layout_view;
layout_view = gtk_type_new (LAYOUT_VIEW_TYPE);
layout_view->layout = layout;
corba_layout_view = bonobo_view_corba_object_create (BONOBO_OBJECT (layout_view));
if (corba_layout_view == CORBA_OBJECT_NIL){
gtk_object_destroy (GTK_OBJECT (corba_layout_view));
......
......@@ -13,6 +13,9 @@
#include "layout.h"
#include "layout-view.h"
static ObjDim default_graph_dim = { 0.7, 0.7, 0.15, 0.15 };
/* static ObjDim default_graph_dim = { 1.0, 1.0, 0, 0 }; */
static BonoboEmbeddableClass *layout_parent_class;
/* The entry point vectors for the server we provide */
......@@ -158,8 +161,10 @@ layout_new (void)
bonobo_embeddable_construct (BONOBO_EMBEDDABLE (layout),
(Bonobo_Embeddable) corba_layout,
layout_view_factory, NULL);
layout->graph = graph_new (layout);
layout->graph_dim = default_graph_dim;
return layout;
}
......@@ -194,3 +199,14 @@ layout_get_graph (Layout *layout)
return layout->graph;
}
void
layout_dim_bbox (ArtIRect *bbox, int x, int y, int width, int height, ObjDim *dim)
{
bbox->x0 = x + (width * dim->x_pos);
bbox->y0 = y + (height * dim->y_pos);
bbox->x1 = bbox->x0 + (width * dim->x_size);
bbox->y1 = bbox->y0 + (height * dim->y_size);
}
......@@ -17,10 +17,23 @@ typedef struct _Layout Layout;
#define IS_LAYOUT(o) (GTK_CHECK_TYPE ((o), LAYOUT_TYPE))
#define IS_LAYOUT_CLASS(k) (GTK_CHECK_CLASS_TYPE ((k), LAYOUT_TYPE))
typedef struct {
/*
* Factor: 0..1 that determines the size of the object
*/
double x_size, y_size;
/*
* Factor: 0..1 that determines the location of the object
*/
double x_pos, y_pos;
} ObjDim;
struct _Layout {
BonoboEmbeddable parent;
Graph *graph;
ObjDim graph_dim;
Graph *graph;
/*
* Number of series we hold
......@@ -41,6 +54,8 @@ void layout_bind_view (Layout *layout, void *layout_view);
void layout_get_n_series (Layout *layout);
GraphVector *layout_get_series (Layout *layout, int n);
void layout_dim_bbox (ArtIRect *bbox, int x, int y,
int width, int height, ObjDim *dim);
END_GNOME_DECLS
......
......@@ -8,6 +8,7 @@
*/
#include <config.h>
#include <bonobo.h>
#include <libgnorba/gnorba.h>
#include "Graph.h"
#include "layout.h"
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment