Commit 7630cac9 authored by Jean Bréfort's avatar Jean Bréfort

bubble plots added

parent 2bd44088
This diff is collapsed.
SUBDIRS = graph utils # data
noinst_LTLIBRARIES = libgoffice.la
libgoffice_la_LIBADD = \
utils/libgoffice-utils.la \
graph/libgoffice-graph.la
libgoffice_la_SOURCES = \
goffice.c \
goffice.h
# prune this when the code moves
INCLUDES = -I$(top_srcdir) \
-I$(top_srcdir)/src \
-I$(top_srcdir)/src/cut-n-paste-code \
-I$(top_srcdir)/src/cut-n-paste-code/foocanvas \
$(GNUMERIC_CFLAGS)
gradient_iconsdir = $(gnumeric_gladedir)
gradient_icons_DATA = \
gradient_n2s.png \
gradient_ne2sw.png \
gradient_nw2se.png \
gradient_w2e.png
EXTRA_DIST = $(gradient_icons_DATA)
/* vim: set sw=8: -*- Mode: C; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 8 -*- */
/*
* go-data-impl.h :
*
* Copyright (C) 2003 Jody Goldberg (jody@gnome.org)
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of version 2 of the GNU General Public
* License as published by the Free Software Foundation.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
* USA
*/
#ifndef GO_DATA_IMPL_H
#define GO_DATA_IMPL_H
#include <goffice/graph/goffice-graph.h>
#include <goffice/graph/go-data.h>
#include <glib-object.h>
G_BEGIN_DECLS
typedef enum {
GO_DATA_CACHE_IS_VALID = 1 << 0,
GO_DATA_IS_EDITABLE = 1 << 1,
GO_DATA_VECTOR_LEN_CACHED = 1 << 2
} GODataFlags;
struct _GOData {
GObject base;
gint32 flags; /* dunno what to do with these yet */
};
typedef struct {
GObjectClass base;
GOData *(*dup) (GOData const *src);
gboolean (*eq) (GOData const *a, GOData const *b);
GOFormat *(*preferred_fmt) (GOData const *dat);
char *(*as_str) (GOData const *dat);
gboolean (*from_str) (GOData *dat, char const *str);
void (*emit_changed) (GOData *dat);
/* signals */
void (*changed) (GOData *dat);
} GODataClass;
/* protected */
void go_data_emit_changed (GOData *dat);
struct _GODataScalar {
GOData base;
};
typedef struct {
GODataClass base;
double (*get_value) (GODataScalar *scalar);
char const *(*get_str) (GODataScalar *scalar);
/* PangoLayout *(get_fmt_str) (GODataScalar *scalar); */
} GODataScalarClass;
struct _GODataVector {
GOData base;
int len; /* negative if dirty, includes missing values */
double *values; /* NULL = inititialized/unsupported, nan = missing */
double minimum, maximum;
};
typedef struct {
GODataClass base;
void (*load_len) (GODataVector *vec);
void (*load_values) (GODataVector *vec);
double (*get_value) (GODataVector *vec, unsigned i);
char *(*get_str) (GODataVector *vec, unsigned i);
/* PangoLayout *(get_fmt_str) (GODataVector *vec, unsigned i); */
} GODataVectorClass;
G_END_DECLS
#endif /* GO_DATA_IMPL_H */
/* vim: set sw=8: -*- Mode: C; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 8 -*- */
/*
* go-data-simple.c :
*
* Copyright (C) 2003 Jody Goldberg (jody@gnome.org)
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of version 2 of the GNU General Public
* License as published by the Free Software Foundation.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
* USA
*/
#include <gnumeric-config.h>
#include <goffice/graph/go-data-simple.h>
#include <goffice/graph/go-data-impl.h>
#include <gsf/gsf-impl-utils.h>
#include <src/gnumeric-i18n.h>
#include <src/mathfunc.h>
#include <string.h>
#include <errno.h>
#include <stdlib.h>
struct _GODataScalarVal {
GODataScalar base;
double val;
char *str;
};
typedef GODataScalarClass GODataScalarValClass;
static GObjectClass *scalar_val_parent_klass;
static void
go_data_scalar_val_finalize (GObject *obj)
{
GODataScalarVal *val = (GODataScalarVal *)obj;
if (val->str != NULL) {
g_free (val->str);
val->str = NULL;
}
if (scalar_val_parent_klass->finalize)
(*scalar_val_parent_klass->finalize) (obj);
}
static GOData *
go_data_scalar_val_dup (GOData const *src)
{
GODataScalarVal *dst = g_object_new (G_OBJECT_TYPE (src), NULL);
GODataScalarVal const *src_val = (GODataScalarVal const *)src;
dst->val = src_val->val;
return GO_DATA (dst);
}
static gboolean
go_data_scalar_val_eq (GOData const *a, GOData const *b)
{
GODataScalarVal const *sval_a = (GODataScalarVal const *)a;
GODataScalarVal const *sval_b = (GODataScalarVal const *)b;
/* GOData::eq is used for identity, not arithamtic */
return sval_a->val == sval_b->val;
}
static char *
go_data_scalar_val_as_str (GOData const *dat)
{
return g_strdup (go_data_scalar_get_str (GO_DATA_SCALAR (dat)));
}
static gboolean
go_data_scalar_val_from_str (GOData *dat, char const *str)
{
GODataScalarVal *sval = (GODataScalarVal *)dat;
double tmp;
char *end;
errno = 0; /* strto(ld) sets errno, but does not clear it. */
tmp = strtod (str, &end);
if (end == str || *end != '\0' || errno == ERANGE)
return FALSE;
g_free (sval->str);
sval->str = NULL;
sval->val = tmp;
return TRUE;
}
static double
go_data_scalar_val_get_value (GODataScalar *dat)
{
GODataScalarVal const *sval = (GODataScalarVal const *)dat;
return sval->val;
}
static char const *
go_data_scalar_val_get_str (GODataScalar *dat)
{
GODataScalarVal *sval = (GODataScalarVal *)dat;
if (sval->str == NULL)
sval->str = g_strdup_printf ("%g", sval->val);
return sval->str;
}
static void
go_data_scalar_val_class_init (GObjectClass *gobject_klass)
{
GODataClass *godata_klass = (GODataClass *) gobject_klass;
GODataScalarClass *scalar_klass = (GODataScalarClass *) gobject_klass;
scalar_val_parent_klass = g_type_class_peek_parent (gobject_klass);
gobject_klass->finalize = go_data_scalar_val_finalize;
godata_klass->dup = go_data_scalar_val_dup;
godata_klass->eq = go_data_scalar_val_eq;
godata_klass->as_str = go_data_scalar_val_as_str;
godata_klass->from_str = go_data_scalar_val_from_str;
scalar_klass->get_value = go_data_scalar_val_get_value;
scalar_klass->get_str = go_data_scalar_val_get_str;
}
GSF_CLASS (GODataScalarVal, go_data_scalar_val,
go_data_scalar_val_class_init, NULL,
GO_DATA_SCALAR_TYPE)
GOData *
go_data_scalar_val_new (double val)
{
GODataScalarVal *res = g_object_new (GO_DATA_SCALAR_VAL_TYPE, NULL);
res->val = val;
return GO_DATA (res);
}
/*****************************************************************************/
struct _GODataScalarStr {
GODataScalar base;
char const *str;
gboolean needs_free;
};
typedef GODataScalarClass GODataScalarStrClass;
static GObjectClass *scalar_str_parent_klass;
static void
go_data_scalar_str_finalize (GObject *obj)
{
GODataScalarStr *str = (GODataScalarStr *)obj;
if (str->needs_free && str->str != NULL) {
g_free ((char *)str->str);
str->str = NULL;
}
if (scalar_str_parent_klass->finalize)
(*scalar_str_parent_klass->finalize) (obj);
}
static GOData *
go_data_scalar_str_dup (GOData const *src)
{
GODataScalarStr *dst = g_object_new (G_OBJECT_TYPE (src), NULL);
GODataScalarStr const *src_val = (GODataScalarStr const *)src;
dst->needs_free = TRUE;
dst->str = g_strdup (src_val->str);
return GO_DATA (dst);
}
static gboolean
go_data_scalar_str_eq (GOData const *a, GOData const *b)
{
GODataScalarStr const *str_a = (GODataScalarStr const *)a;
GODataScalarStr const *str_b = (GODataScalarStr const *)b;
return 0 == strcmp (str_a->str, str_b->str);
}
static char *
go_data_scalar_str_as_str (GOData const *dat)
{
GODataScalarStr const *str = (GODataScalarStr const *)dat;
return g_strdup (str->str);
}
static gboolean
go_data_scalar_str_from_str (GOData *dat, char const *string)
{
GODataScalarStr *str = (GODataScalarStr *)dat;
if (str->str == string)
return TRUE;
if (str->needs_free)
g_free ((char *)str->str);
str->str = g_strdup (string);
return TRUE;
}
static double
go_data_scalar_str_get_value (GODataScalar *dat)
{
return gnm_nan;
}
static char const *
go_data_scalar_str_get_str (GODataScalar *dat)
{
GODataScalarStr const *str = (GODataScalarStr const *)dat;
return str->str;
}
static void
go_data_scalar_str_class_init (GObjectClass *gobject_klass)
{
GODataClass *godata_klass = (GODataClass *) gobject_klass;
GODataScalarClass *scalar_klass = (GODataScalarClass *) gobject_klass;
scalar_str_parent_klass = g_type_class_peek_parent (gobject_klass);
gobject_klass->finalize = go_data_scalar_str_finalize;
godata_klass->dup = go_data_scalar_str_dup;
godata_klass->eq = go_data_scalar_str_eq;
godata_klass->as_str = go_data_scalar_str_as_str;
godata_klass->from_str = go_data_scalar_str_from_str;
scalar_klass->get_value = go_data_scalar_str_get_value;
scalar_klass->get_str = go_data_scalar_str_get_str;
}
static void
go_data_scalar_str_init (GObject *obj)
{
GODataScalarStr *str = (GODataScalarStr *)obj;
str->str = "";
str->needs_free = FALSE;
}
GSF_CLASS (GODataScalarStr, go_data_scalar_str,
go_data_scalar_str_class_init, go_data_scalar_str_init,
GO_DATA_SCALAR_TYPE)
GOData *
go_data_scalar_str_new (char const *str, gboolean needs_free)
{
GODataScalarStr *res = g_object_new (GO_DATA_SCALAR_STR_TYPE, NULL);
res->str = str;
res->needs_free = needs_free;
return GO_DATA (res);
}
/* vim: set sw=8: -*- Mode: C; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 8 -*- */
/*
* go-data-simple.h :
*
* Copyright (C) 2003 Jody Goldberg (jody@gnome.org)
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of version 2 of the GNU General Public
* License as published by the Free Software Foundation.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
* USA
*/
#ifndef GO_DATA_SIMPLE_H
#define GO_DATA_SIMPLE_H
#include <goffice/graph/goffice-graph.h>
#include <goffice/graph/go-data.h>
#define GO_DATA_SCALAR_VAL_TYPE (go_data_scalar_val_get_type ())
#define GO_DATA_SCALAR_VAL(o) (G_TYPE_CHECK_INSTANCE_CAST ((o), GO_DATA_SCALAR_VAL_TYPE, GODataScalarVal))
#define IS_GO_DATA_SCALAR_VAL(o) (G_TYPE_CHECK_INSTANCE_TYPE ((o), GO_DATA_SCALAR_VAL_TYPE))
typedef struct _GODataScalarVal GODataScalarVal;
GType go_data_scalar_val_get_type (void);
GOData *go_data_scalar_val_new (double val);
#define GO_DATA_SCALAR_STR_TYPE (go_data_scalar_str_get_type ())
#define GO_DATA_SCALAR_STR(o) (G_TYPE_CHECK_INSTANCE_CAST ((o), GO_DATA_SCALAR_STR_TYPE, GODataScalarStr))
#define IS_GO_DATA_SCALAR_STR(o) (G_TYPE_CHECK_INSTANCE_TYPE ((o), GO_DATA_SCALAR_STR_TYPE))
typedef struct _GODataScalarStr GODataScalarStr;
GType go_data_scalar_str_get_type (void);
GOData *go_data_scalar_str_new (char const *str, gboolean needs_free);
#endif /* GO_DATA_SIMPLE_H */
/* vim: set sw=8: -*- Mode: C; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 8 -*- */
/*
* go-data.c :
*
* Copyright (C) 2003 Jody Goldberg (jody@gnome.org)
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of version 2 of the GNU General Public
* License as published by the Free Software Foundation.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
* USA
*/
#include <gnumeric-config.h>
#include <goffice/graph/go-data.h>
#include <goffice/graph/go-data-impl.h>
#include <gsf/gsf-impl-utils.h>
#include <src/gnumeric-i18n.h>
#include <string.h>
#include <src/mathfunc.h>
#define GO_DATA_CLASS(k) (G_TYPE_CHECK_CLASS_CAST ((k), GO_DATA_TYPE, GODataClass))
#define IS_GO_DATA_CLASS(k) (G_TYPE_CHECK_CLASS_TYPE ((k), GO_DATA_TYPE))
#define GO_DATA_GET_CLASS(o) (G_TYPE_INSTANCE_GET_CLASS ((o), GO_DATA_TYPE, GODataClass))
enum {
CHANGED,
LAST_SIGNAL
};
static gulong go_data_signals [LAST_SIGNAL] = { 0, };
/* trivial fall back */
static GOData *
go_data_dup_real (GOData const *src)
{
char *str = go_data_as_str (src);
GOData *dst = g_object_new (G_OBJECT_TYPE (src), NULL);
if (dst != NULL)
go_data_from_str (dst, str);
g_free (str);
return dst;
}
static void
go_data_init (GOData *data)
{
data->flags = 0;
}
#if 0
static GObjectClass *parent_klass;
static void
go_data_finalize (GOData *obj)
{
g_warning ("finalize");
if (parent_klass->finalize)
(parent_klass->finalize) (obj);
}
#endif
static void
go_data_class_init (GODataClass *klass)
{
go_data_signals [CHANGED] = g_signal_new ("changed",
G_TYPE_FROM_CLASS (klass),
G_SIGNAL_RUN_LAST,
G_STRUCT_OFFSET (GODataClass, changed),
NULL, NULL,
g_cclosure_marshal_VOID__VOID,
G_TYPE_NONE, 0);
klass->dup = go_data_dup_real;
#if 0
{
GObjectClass *gobj_klass = (GObjectClass *)klass;
gobj_klass->finalize = go_data_finalize;
parent_klass = g_type_class_peek_parent (klass);
}
#endif
}
GSF_CLASS_ABSTRACT (GOData, go_data,
go_data_class_init, go_data_init,
G_TYPE_OBJECT)
/**
* go_data_dup :
* @src : #GOData
*
* A deep copy of @src.
**/
GOData *
go_data_dup (GOData const *src)
{
if (src != NULL) {
GODataClass const *klass = GO_DATA_GET_CLASS (src);
g_return_val_if_fail (klass != NULL, NULL);
return (*klass->dup) (src);
}
return NULL;
}
/**
* go_data_eq :
* @a : #GOData
* @b : #GOData
*
* Returns TRUE if @a and @b are the same
**/
gboolean
go_data_eq (GOData const *a, GOData const *b)
{
if (a == b)
return TRUE;
else {
GODataClass *a_klass = GO_DATA_GET_CLASS (a);
GODataClass *b_klass = GO_DATA_GET_CLASS (b);
g_return_val_if_fail (a_klass != NULL, FALSE);
g_return_val_if_fail (a_klass->eq != NULL, FALSE);
if (a_klass != b_klass)
return FALSE;
return (*a_klass->eq) (a, b);
}
}
/**
* go_data_prefered_fmt :
* @dat : #GOData
*
* Caller is responsible for unrefing the result.
* Returns the fmt preferred by the the data
**/
GOFormat *
go_data_preferred_fmt (GOData const *dat)
{
GODataClass const *klass = GO_DATA_GET_CLASS (dat);
g_return_val_if_fail (klass != NULL, NULL);
if (klass->preferred_fmt)
return (*klass->preferred_fmt) (dat);
return NULL;
}
/**
* go_data_as_str :
* @dat : #GOData
*
* Return a string representation of the data source that the caller is
* responsible for freeing
*
* NOTE : This is the _source_ not the content.
**/
char *
go_data_as_str (GOData const *dat)
{
GODataClass const *klass = GO_DATA_GET_CLASS (dat);
g_return_val_if_fail (klass != NULL, NULL);