Commit bef2ec9d authored by Arturo Espinosa's avatar Arturo Espinosa
Browse files

More work -miguel

parent b4fada4c
......@@ -21,7 +21,13 @@ module GNOME {
SCALE_TYPE_PERCENT
};
interface AxisScale {
enum AxisType {
AXIS_X,
AXIS_Y,
AXIS_Z
};
interface Axis {
/*
* Whether the Axis is hidden
*/
......@@ -192,5 +198,20 @@ module GNOME {
void reset_series ();
void add_series (in string label, in Vector vector);
};
//
// This one actually contains all the chart elements and controls
// its placement.
//
// * The Chart
// * The titles
// * The series labels
// * The axis
// * The chart background
//
interface Layout : GNOME::Unknown {
Chart get_chart ();
Axis get_axis (in AxisType axis);
};
};
};
......@@ -17,10 +17,12 @@ GRAPH_CORBA_GENERATED = \
Graph.h
graph_SOURCES = \
data-source.c \
data-source.h \
series.c \
series.h \
graph.c \
graph.h \
graph-view.c \
graph-view.h \
graph-view-colbar.c \
graph-view-colbar.h \
vector.c \
vector.h \
$(GRAPH_CORBA_GENERATED)
......
/*
* Graphics View: Columns and Bars plotting implementation
*
* Author:
* Miguel de Icaza (miguel@kernel.org)
*
* (C) 1999 International GNOME Support (http://www.gnome-support.com).
*/
#include <config.h>
#include <math.h>
#include <libgnomeui/gnome-canvas.h>
#include "src/portability.h"
#include "graph.h"
#include "graph-view.h"
#include "graph-view-colbar.h"
typedef struct {
GraphView *graph_view;
Graph *graph;
GdkDrawable *drawable;
int x, y;
int width, height;
int xl, yl;
double units_per_slot;
double size; /* |low| + |high| */
} ColbarDrawCtx;
static double
colbar_map_point (ColbarDrawCtx *ctx, double point)
{
return (fabs (ctx->graph->low) + point) / ctx->scale;
}
FIXME
static void
graph_view_colbar_draw_nth_clustered (ColbarDrawCtx *ctx, int item)
{
const int n_series = ctx->graph->n_series;
int item_base = item * ctx->units_per_slot;
int col_width = ctx->units_per_slot / n_series;
int i;
for (i = 0; i < n_series; i++){
GraphVector *vector = ctx->graph->vectors [i];
column_draw (
ctx, 0,
item_base, 0,
item_base + col_width - 1,
graph_vector_get_double (vector, item));
}
}
static void
graph_view_colbar_draw_nth_stacked (ColbarDrawCtx *ctx, int item)
{
double last_pos = 0.0;
double last_neg = 0.0;
int i;
for (i = 0; i < n_series; i++){
GraphVector *vector = ctx->graph->vectors [i];
double v;
v = graph_vector_get_double (vector, item);
if (v >= 0){
column_draw (
ctx, i,
item_base, last_pos,
item_base + ctx->units_per_slot - 1,
last_pos + v);
last_pos += v;
} else {
column_draw (
ctx, i,
item_base, last_neg,
item_base + ctx->units_per_slot - 1,
last_neg + v);
last_neg += v;
}
}
}
static void
graph_view_colbar_draw_nth_stacked_full (ColbarDrawCtx *ctx, int item)
{
double last_pos, last_neg;
double total_pos, total_neg;
double *values;
int i;
values = g_alloca0 (sizeof (double) * n_series);
total_pos = total_neg = 0.0;
last_pos = last_neg = 0.0;
for (i = 0; i < n_series; i++){
GraphVector *vector = ctx->graph->vectors [i];
values [i] = graph_vector_get_double (vector, item);
if (values [i] >= 0)
total_pos += values [i];
else
total_neg += values [i];
}
for (i = 0; i < n_series; i++){
double v;
if (values [i] >= 0){
if (total_pos == 0.0)
v = 0.0;
else
v = (values [i] * graph->high) / total_pos;
column_draw (
ctx, i,
item_base, last_pos,
item_base + ctx->units_per_slot - 1,
last_pos + v);
last_pos += v;
} else {
if (total_neg == 0.0)
v = 0.0;
else
v = (values [i] * graph->low) / total_neg;
column_draw (
ctx, i,
item_base, last_neg,
item_base + ctx->units_per_slot - 1,
last_neg + v);
last_neg += v;
}
}
}
static void
graph_view_colbar_draw_nth (ColbarDrawCtx *ctx, int item)
{
switch (ctx->graph->chart_type){
case GNOME_Graph_CHART_TYPE_CLUSTERED:
graph_view_colbar_draw_nth_clustered (ctx, item);
break;
case GNOME_Graph_CHART_TYPE_STACKED:
graph_view_colbar_draw_nth_stacked (ctx, item);
break;
case GNOME_Graph_CHART_TYPE_STACKED_FULL:
graph_view_colbar_draw_nth_stacked_full (ctx, item);
break;
default:
g_error ("This mode does not support Column/Bar plotting");
}
}
void
graph_view_colbar_draw (GraphView *graph_view, GdkDrawable *drawable, int x, int y, int width, int height)
{
ColbarDrawCtx ctx;
int first, last, i;
ctx.x = x;
ctx.y = y;
ctx.width = width;
ctx.height = height;
ctx.drawable = drawable;
ctx.graph_view = graph_view;
ctx.graph = graph_view->graph;
ctx.yl = graph_view->bbox.y1 - graph_view->bbox.y0;
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){
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;
} 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;
}
for (i = first; i <= last; i++){
int base_x = i * units_per_slot;
graph_view_colbar_draw_nth (&ctx, i);
};
}
#ifndef GRAPH_VIEW_COLBAR_H_
#define GRAPH_VIEW_COLBAR_H_
void graph_view_colbar_draw (GraphView *graph_view, GdkDrawable *drawable,
int x, int y, int width, int height);
#endif /* GRAPH_VIEW_COLBAR_H_ */
/*
* graph-view-plot.c: Implements lines/areas graphics
*
* Author:
* Miguel de Icaza (miguel@kernel.org)
*
* (C) 1999 International GNOME Support (http://www.gnome-support.com)
*/
#include <config.h>
#include <math.h>
#include <libgnomeui/gnome-canvas.h>
#include "src/portability.h"
#include "graph.h"
#include "graph-view.h"
#include "graph-view-plot.h"
void
graph_view_plot (GraphView *graph_view, GdkDrawable *drawable, int x, int y, int width, int height)
{
}
/*
* Graph Item
* Graph Item, the view of the Graph model.
*
* Author:
* Miguel de Icaza (miguel@kernel.org)
......@@ -7,8 +7,11 @@
* (C) 1999 International GNOME Support (http://www.gnome-support.com).
*/
#include <config.h>
#include <math.h>
#include <libgnomeui/gnome-canvas.h>
#include "graph.h"
#include "graph-view.h"
#include "graph-view-colbar.h"
enum {
ARG_BBOX,
......@@ -22,7 +25,6 @@ static void
graph_view_destroy (GtkObject *object)
{
GraphView *graph_view = GRAPH_VIEW (object);
}
static void
......@@ -57,58 +59,65 @@ graph_view_unrealize (GnomeCanvasItem *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)
graph_view_draw (GnomeCanvasItem *item, 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;
GraphView *graph_view = GRAPH_VIEW (item);
Graph *graph = graph_view->graph;
for (i = first; i <= last; i++){
HERE IS STAYED
switch (graph->chart_type){
case GNOME_Graph_CHART_TYPE_CLUSTERED:
case GNOME_Graph_CHART_TYPE_STACKED:
case GNOME_Graph_CHART_TYPE_STACKED_FULL:
if (graph->plot_mode == GNOME_Graph_PLOT_COLBAR){
graph_view_colbar_draw (
graph_view, drawable,
x, y, width, height);
return;
}
} 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);
};
}
graph_view_plot (graph_view, drawable, x, y, width, height);
break;
}
case GNOME_Graph_CHART_TYPE_BUBBLES:
g_error ("Bubbles not implemented yet");
break;
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;
case GNOME_Graph_CHART_TYPE_SCATTER:
graph_view_scatter_plot (graph_view, drawable, x, y, width, height);
break;
if (graph->plot_mode == GNOME_Graph_PLOT_COLBAR){
graph_view_colbar_draw (graph_view, drawable, x, y, width, height);
return;
case GNOME_Graph_CHART_TYPE_SURFACE_2D:
case GNOME_Graph_CHART_TYPE_SURFACE_3D:
g_error ("Surface 2D/3D not implemented yet");
break;
case GNOME_Graph_CHART_TYPE_3D:
g_error ("3D charts not implemented yet");
break;
case GNOME_Graph_CHART_TYPE_PIE:
g_error ("Pie charts not yet implemented");
break;
case GNOME_Graph_CHART_TYPE_STOCK_HIGH_LOW_CLOSE:
case GNOME_Graph_CHART_TYPE_STOCK_OPEN_HIGH_LOW_CLOSE:
case GNOME_Graph_CHART_TYPE_STOCK_VOL_HIGH_LOW_CLOSE:
case GNOME_Graph_CHART_TYPE_STOCK_VOL_OPEN_HIGH_LOW_CLOSE:
graph_view_stock_plot (graph_view, drawable,
x, y, width, height);
break;
}
graph_view_
}
static double
graph_view_point (GnomeCanvasItem *item, double x, double y, int cx, int cy,
GnomeCanvasItem **actual_item)
{
/* For now we are always inside the thing. */
*actual_item = item;
return 0.0;
}
static gint
......
......@@ -42,8 +42,8 @@ graph_update (Graph *graph, int dirty_flags)
graph->dirty_flags = 0;
}
GNOME_Graph_ChartType
impl_graph_get_chart_type (PortableServer_Servant servant, CORBA_Environment * ev)
static GNOME_Graph_ChartType
impl_graph_get_chart_type (PortableServer_Servant servant, CORBA_Environment *ev)
{
Graph *graph = graph_from_servant (servant);
......@@ -136,10 +136,10 @@ graph_compute_stacked_dimensions (Graph *graph)
graph_set_low_high (graph, low, high);
}
void
static void
impl_graph_set_chart_type (PortableServer_Servant servant,
GNOME_Graph_ChartType value,
CORBA_Environment * ev)
CORBA_Environment *ev)
{
Graph *graph = graph_from_servant (servant);
......@@ -164,16 +164,18 @@ impl_graph_set_chart_type (PortableServer_Servant servant,
graph_update (graph);
}
GNOME_Graph_PlotMode
impl_graph_get_plot_mode (PortableServer_Servant servant, CORBA_Environment * ev)
static GNOME_Graph_PlotMode
impl_graph_get_plot_mode (PortableServer_Servant servant, CORBA_Environment *ev)
{
Graph *graph = graph_from_servant (servant);
return graph->plot_mode;
}
void
impl_graph_set_plot_mode (PortableServer_Servant servant, GNOME_Graph_PlotMode value, CORBA_Environment * ev)
static void
impl_graph_set_plot_mode (PortableServer_Servant servant,
GNOME_Graph_PlotMode value,
CORBA_Environment *ev)
{
Graph *graph = graph_from_servant (servant);
......@@ -183,16 +185,18 @@ impl_graph_set_plot_mode (PortableServer_Servant servant, GNOME_Graph_PlotMode v
}
}
GNOME_Graph_ColBarMode
impl_graph_get_col_bar_mode (PortableServer_Servant servant, CORBA_Environment * ev)
static GNOME_Graph_ColBarMode
impl_graph_get_col_bar_mode (PortableServer_Servant servant, CORBA_Environment *ev)
{
Graph *graph = graph_from_servant (servant);
return graph->col_bar_mode;
}
void
impl_graph_set_col_bar_mode (PortableServer_Servant servant, GNOME_Graph_ColBarMode value, CORBA_Environment * ev)
static void
impl_graph_set_col_bar_mode (PortableServer_Servant servant,
GNOME_Graph_ColBarMode value,
CORBA_Environment *ev)
{
Graph *graph = graph_from_servant (servant);
......@@ -202,16 +206,18 @@ impl_graph_set_col_bar_mode (PortableServer_Servant servant, GNOME_Graph_ColBarM
}
}
GNOME_Graph_DirMode
impl_graph_get_direction (PortableServer_Servant servant, CORBA_Environment * ev)
static GNOME_Graph_DirMode
impl_graph_get_direction (PortableServer_Servant servant, CORBA_Environment *ev)
{
Graph *graph = graph_from_servant (servant);
return graph->direction;
}
void
impl_graph_set_direction (PortableServer_Servant servant, GNOME_Graph_DirMode value, CORBA_Environment * ev)
static void
impl_graph_set_direction (PortableServer_Servant servant,
GNOME_Graph_DirMode value,
CORBA_Environment *ev)
{
Graph *graph = graph_from_servant (servant);
......@@ -221,16 +227,18 @@ impl_graph_set_direction (PortableServer_Servant servant, GNOME_Graph_DirMode va
}
}
GNOME_Graph_LineMode
impl_graph_get_line_mode (PortableServer_Servant servant, CORBA_Environment * ev)
static GNOME_Graph_LineMode
impl_graph_get_line_mode (PortableServer_Servant servant, CORBA_Environment *ev)
{
Graph *graph = graph_from_servant (servant);
return graph->line_mode;
}
void
impl_graph_set_line_mode (PortableServer_Servant servant, GNOME_Graph_LineMode value, CORBA_Environment * ev)
static void
impl_graph_set_line_mode (PortableServer_Servant servant,
GNOME_Graph_LineMode value,
CORBA_Environment *ev)
{
Graph *graph = graph_from_servant (servant);
......@@ -240,16 +248,18 @@ impl_graph_set_line_mode (PortableServer_Servant servant, GNOME_Graph_LineMode v
}
}
GNOME_Graph_PieMode
impl_graph_get_pie_mode (PortableServer_Servant servant, CORBA_Environment * ev)
static GNOME_Graph_PieMode
impl_graph_get_pie_mode (PortableServer_Servant servant, CORBA_Environment *ev)
{
Graph *graph = graph_from_servant (servant);
return graph->pie_mode;
}
void
impl_graph_set_pie_mode (PortableServer_Servant servant, GNOME_Graph_PieMode value, CORBA_Environment * ev)
static void
impl_graph_set_pie_mode (PortableServer_Servant servant,
GNOME_Graph_PieMode value,
CORBA_Environment *ev)
{
Graph *graph = graph_from_servant (servant);
......@@ -259,16 +269,18 @@ impl_graph_set_pie_mode (PortableServer_Servant servant, GNOME_Graph_PieMode val
}
}
GNOME_Graph_PieDimension
impl_graph_get_pie_dim (PortableServer_Servant servant, CORBA_Environment * ev)
static GNOME_Graph_PieDimension
impl_graph_get_pie_dim (PortableServer_Servant servant, CORBA_Environment *ev)
{
Graph *graph = graph_from_servant (servant);
return graph->pie_dim;
}
void
impl_graph_set_pie_dim (PortableServer_Servant servant, GNOME_Graph_PieDimension value, CORBA_Environment * ev)
static void
impl_graph_set_pie_dim (PortableServer_Servant servant,
GNOME_Graph_PieDimension value,
CORBA_Environment *ev)
{
Graph *graph = graph_from_servant (servant);
......@@ -278,16 +290,18 @@ impl_graph_set_pie_dim (PortableServer_Servant servant, GNOME_Graph_PieDimension
}
}
GNOME_Graph_ScatterPoints
impl_graph_get_scatter_mode (PortableServer_Servant servant, CORBA_Environment * ev)
static GNOME_Graph_ScatterPoints
impl_graph_get_scatter_mode (PortableServer_Servant servant, CORBA_Environment *ev)
{
Graph *graph = graph_from_servant (servant);
return graph->scatter_mode;
}
void
impl_graph_set_scatter_mode (PortableServer_Servant servant, GNOME_Graph_ScatterPoints value, CORBA_Environment * ev)
static void
impl_graph_set_scatter_mode (PortableServer_Servant servant,
GNOME_Graph_ScatterPoints value,
CORBA_Environment *ev)
{
Graph *graph = graph_from_servant (servant);
......@@ -297,16 +311,18 @@ impl_graph_set_scatter_mode (PortableServer_Servant servant, GNOME_Graph_Scatter
}
}
GNOME_Graph_ScatterConn
impl_graph_get_scatter_conn (PortableServer_Servant servant, CORBA_Environment * ev)
static GNOME_Graph_ScatterConn
impl_graph_get_scatter_conn (PortableServer_Servant servant, CORBA_Environment *ev)
{
Graph *graph = graph_from_servant (servant);
return graph->scatter_conn;
}
void
impl_graph_set_scatter_conn (PortableServer_Servant servant, GNOME_Graph_ScatterConn value, CORBA_Environment * ev)
static void
impl_graph_set_scatter_conn (PortableServer_Servant servant,
GNOME_Graph_ScatterConn value,
CORBA_Environment *ev)
{
Graph *graph = graph_from_servant (servant);
......@@ -316,16 +332,16 @@ impl_graph_set_scatter_conn (PortableServer_Servant servant, GNOME_Graph_Scatter
}
}
GNOME_Graph_SurfaceMode
impl_graph_get_surface_mode (PortableServer_Servant servant, CORBA_Environment * ev)
static GNOME_Graph_SurfaceMode
impl_graph_get_surface_mode (PortableServer_Servant servant, CORBA_Environment *ev)
{
Graph *graph = graph_from_servant (servant);
return graph->surface_mode;
}
void
impl_graph_set_surface_mode (PortableServer_Servant servant, GNOME_Graph_SurfaceMode value, CORBA_Environment * ev)
static void
impl_graph_set_surface_mode (PortableServer_Servant servant, GNOME_Graph_SurfaceMode value, CORBA_Environment *ev)