Commit 2bd44088 authored by Jody Goldberg's avatar Jody Goldberg Committed by Jody Goldberg

expand our claims. apparently duplicates are not a good idea.


2003-12-23  Jody Goldberg <jody@gnome.org>

	* gnumeric.keys.in : expand our claims.
	* gnumeric.mime : apparently duplicates are not a good idea.

2003-12-23  Jody Goldberg <jody@gnome.org>

	* src/graph.c (gnm_go_data_preferred_fmt) : simplify to handle both
	  scalar and vector and use the auto-format code.
parent 7a730ec8
......@@ -140,6 +140,7 @@ go_data_eq (GOData const *a, GOData const *b)
* go_data_prefered_fmt :
* @dat : #GOData
*
* Caller is responsible for unrefing the result.
* Returns the fmt preferred by the the data
**/
GOFormat *
......
......@@ -38,6 +38,7 @@
#include <src/gnumeric-i18n.h>
#include <src/gui-util.h>
#include <src/mathfunc.h>
#include <src/format.h>
#include <src/widgets/widget-format-selector.h>
#include <gtk/gtktable.h>
#include <gtk/gtkcheckbutton.h>
......@@ -387,6 +388,13 @@ gog_axis_update (GogObject *obj)
axis->min_val = DBL_MAX;
axis->max_val = -DBL_MAX;
axis->min_contrib = axis->max_contrib = NULL;
if (axis->format != NULL) {
go_format_unref (axis->format);
axis->format = NULL;
}
/* everything else is initialized in gog_plot_get_axis_bounds */
bounds.fmt = NULL;
for (ptr = axis->contributors ; ptr != NULL ; ptr = ptr->next) {
labels = gog_plot_get_axis_bounds (GOG_PLOT (ptr->data),
axis->type, &bounds);
......@@ -418,6 +426,7 @@ gog_axis_update (GogObject *obj)
axis->max_val = bounds.val.maxima;
}
}
axis->format = bounds.fmt; /* just absorb the ref if it exists */
minima = axis->min_val;
maxima = axis->max_val;
......@@ -668,7 +677,7 @@ gog_axis_editor (GogObject *gobj, GogDataAllocator *dalloc, GnmCmdContext *cc)
gtk_label_new (_("Bounds")));
w = number_format_selector_new ();
if (axis->assigned_format != NULL)
if (axis->assigned_format != NULL && !style_format_is_general (axis->assigned_format))
number_format_selector_set_style_format (NUMBER_FORMAT_SELECTOR (w),
axis->assigned_format);
else if (axis->format != NULL)
......@@ -1054,9 +1063,9 @@ gog_axis_get_marker (GogAxis *axis, unsigned i)
if (fabs (val) < major_tick / 10.0)
val = 0.;
if (axis->assigned_format)
return go_format_value (axis->assigned_format, val);
return go_format_value (axis->format, val);
if (axis->assigned_format == NULL || style_format_is_general (axis->assigned_format))
return go_format_value (axis->format, val);
return go_format_value (axis->assigned_format, val);
}
}
......
......@@ -347,6 +347,20 @@ gog_plot_foreach_elem (GogPlot *plot, GogEnumFunc func, gpointer data)
}
}
/**
* gog_plot_get_axis_bounds :
* @plot : #GogPlot
* @axis : #GogAxisType
* @bounds : #GogPlotBoundInfo
*
* Queries @plot for its axis preferences for @axis and stores the results in
* @bounds. All elements of @bounds are initialized to sane values before the
* query _ACCEPT_ ::fmt. The caller is responsible for initializing it. This
* is done so that once on plot has selected a format the others need not do
* the lookup too if so desired.
*
* Caller is responsible for unrefing ::fmt.
**/
GOData *
gog_plot_get_axis_bounds (GogPlot *plot, GogAxisType axis,
GogPlotBoundInfo *bounds)
......
......@@ -37,10 +37,11 @@ go_format_as_XL (GOFormat const *fmt, gboolean localized)
return style_format_as_XL (fmt, localized);
}
void
GOFormat *
go_format_ref (GOFormat *fmt)
{
style_format_ref (fmt);
return fmt;
}
void
......
......@@ -28,7 +28,7 @@ G_BEGIN_DECLS
GOFormat *go_format_new_from_XL (char const *descriptor_string, gboolean delocalize);
char *go_format_as_XL (GOFormat const *fmt, gboolean localized);
void go_format_ref (GOFormat *fmt);
GOFormat *go_format_ref (GOFormat *fmt);
void go_format_unref (GOFormat *fmt);
char *go_format_value (GOFormat const *fmt, double val);
gboolean go_format_eq (GOFormat const *a, GOFormat const *b);
......
......@@ -31,6 +31,7 @@
#include <goffice/graph/gog-style.h>
#include <goffice/graph/go-data.h>
#include <goffice/utils/go-color.h>
#include <goffice/utils/go-format.h>
#include <module-plugin-defs.h>
#include <src/gnumeric-i18n.h>
......@@ -135,6 +136,11 @@ gog_plot1_5d_update (GogObject *obj)
old_maxima = model->maxima;
model->minima = DBL_MAX;
model->maxima = -DBL_MAX;
if (model->fmt != NULL) {
go_format_unref (model->fmt);
model->fmt = NULL;
}
num_elements = num_series = 0;
for (ptr = model->base.series ; ptr != NULL ; ptr = ptr->next) {
series = ptr->data;
......@@ -152,6 +158,8 @@ gog_plot1_5d_update (GogObject *obj)
if (model->maxima < maxima)
model->maxima = maxima;
}
if (model->fmt == NULL)
model->fmt = go_data_preferred_fmt (series->base.values[1].data);
index_dim = GOG_SERIES (series)->values[0].data;
}
if (model->num_elements != num_elements) {
......@@ -207,7 +215,12 @@ gog_plot1_5d_axis_get_bounds (GogPlot *plot, GogAxisType axis,
if (model->type == GOG_1_5D_AS_PERCENTAGE) {
bounds->logical.minima = -1.;
bounds->logical.maxima = 1.;
}
if (bounds->fmt == NULL) {
bounds->fmt = go_format_ref (
go_format_default_percentage ());
}
} else if (bounds->fmt == NULL && model->fmt != NULL)
bounds->fmt = go_format_ref (model->fmt);
return NULL;
} else if (axis == gog_axis_get_atype (gog_plot1_5d_get_index_axis (model))) {
GSList *ptr;
......@@ -290,8 +303,14 @@ gog_plot1_5d_class_init (GogPlotClass *plot_klass)
plot_klass->supports_vary_style_by_element = gog_1_5d_supports_vary_style_by_element;
}
static void
gog_plot1_5d_init (GogPlot1_5d *plot)
{
plot->fmt = NULL;
}
GSF_CLASS_ABSTRACT (GogPlot1_5d, gog_plot1_5d,
gog_plot1_5d_class_init, NULL,
gog_plot1_5d_class_init, gog_plot1_5d_init,
GOG_PLOT_TYPE)
/*****************************************************************************/
......
......@@ -38,9 +38,10 @@ typedef struct {
GogPlot1_5dType type;
/* cached content */
unsigned num_series, num_elements;
double maxima, minima; /* meaning varies depending on type */
gboolean implicit_index;
unsigned num_series, num_elements;
double maxima, minima; /* meaning varies depending on type */
gboolean implicit_index;
GOFormat *fmt;
} GogPlot1_5d;
typedef struct {
GogPlotClass base;
......
......@@ -28,6 +28,7 @@
#include <goffice/graph/go-data.h>
#include <goffice/utils/go-color.h>
#include <goffice/utils/go-marker.h>
#include <goffice/utils/go-format.h>
#include <module-plugin-defs.h>
#include <src/gnumeric-i18n.h>
......@@ -35,9 +36,7 @@
#include <gsf/gsf-impl-utils.h>
#include <math.h>
typedef struct {
GogPlotClass base;
} GogXYPlotClass;
typedef GogPlotClass GogXYPlotClass;
enum {
GOG_XY_PROP_0,
......@@ -62,6 +61,19 @@ gog_xy_plot_type_name (G_GNUC_UNUSED GogObject const *item)
return N_("PlotXY");
}
static void
gog_xy_plot_clear_formats (GogXYPlot *xy)
{
if (xy->x.fmt != NULL) {
go_format_unref (xy->x.fmt);
xy->x.fmt = NULL;
}
if (xy->y.fmt != NULL) {
go_format_unref (xy->y.fmt);
xy->y.fmt = NULL;
}
}
static void
gog_xy_plot_update (GogObject *obj)
{
......@@ -73,6 +85,7 @@ gog_xy_plot_update (GogObject *obj)
x_min = y_min = DBL_MAX;
x_max = y_max = -DBL_MAX;
gog_xy_plot_clear_formats (model);
for (ptr = model->base.series ; ptr != NULL ; ptr = ptr->next) {
series = ptr->data;
if (!gog_series_is_valid (GOG_SERIES (series)))
......@@ -82,6 +95,8 @@ gog_xy_plot_update (GogObject *obj)
series->base.values[1].data), &tmp_min, &tmp_max);
if (y_min > tmp_min) y_min = tmp_min;
if (y_max < tmp_max) y_max = tmp_max;
if (model->y.fmt == NULL)
model->y.fmt = go_data_preferred_fmt (series->base.values[1].data);
if (series->base.values[0].data != NULL) {
go_data_vector_get_minmax (GO_DATA_VECTOR (
......@@ -94,7 +109,8 @@ gog_xy_plot_update (GogObject *obj)
GO_DATA_VECTOR (series->base.values[1].data));
is_discrete = TRUE;
}
} else if (model->x.fmt == NULL)
model->x.fmt = go_data_preferred_fmt (series->base.values[0].data);
} else {
tmp_min = 0;
tmp_max = go_data_vector_get_len (
......@@ -153,6 +169,8 @@ gog_xy_plot_axis_get_bounds (GogPlot *plot, GogAxisType axis,
bounds->is_discrete = model->x.minima > model->x.maxima ||
!finite (model->x.minima) ||
!finite (model->x.maxima);
if (bounds->fmt == NULL && model->x.fmt != NULL)
bounds->fmt = go_format_ref (model->x.fmt);
for (ptr = plot->series; ptr != NULL ; ptr = ptr->next)
if (gog_series_is_valid (GOG_SERIES (ptr->data)))
......@@ -163,6 +181,8 @@ gog_xy_plot_axis_get_bounds (GogPlot *plot, GogAxisType axis,
if (axis == GOG_AXIS_Y) {
bounds->val.minima = model->y.minima;
bounds->val.maxima = model->y.maxima;
if (bounds->fmt == NULL && model->y.fmt != NULL)
bounds->fmt = go_format_ref (model->y.fmt);
}
return NULL;
}
......@@ -199,6 +219,15 @@ gog_xy_get_property (GObject *obj, guint param_id,
break;
}
}
static void
gog_xy_finalize (GObject *obj)
{
gog_xy_plot_clear_formats (GOG_XY_PLOT (obj));
if (G_OBJECT_CLASS (xy_parent_klass)->finalize)
G_OBJECT_CLASS (xy_parent_klass)->finalize (obj);
}
static void
gog_xy_plot_class_init (GogPlotClass *plot_klass)
{
......@@ -209,6 +238,7 @@ gog_xy_plot_class_init (GogPlotClass *plot_klass)
gobject_klass->set_property = gog_xy_set_property;
gobject_klass->get_property = gog_xy_get_property;
gobject_klass->finalize = gog_xy_finalize;
g_object_class_install_property (gobject_klass, GOG_XY_PROP_DEFAULT_STYLE_HAS_MARKERS,
g_param_spec_boolean ("default-style-has-markers", NULL,
......@@ -248,6 +278,7 @@ static void
gog_xy_plot_init (GogXYPlot *xy)
{
xy->base.vary_style_by_element = FALSE;
xy->x.fmt = xy->y.fmt = NULL;
xy->default_style_has_markers = TRUE;
xy->default_style_has_lines = TRUE;
}
......
......@@ -32,6 +32,7 @@ typedef struct {
struct {
double minima, maxima;
GOFormat *fmt;
} x, y;
gboolean default_style_has_markers;
gboolean default_style_has_lines;
......
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