goffice r2161 - in trunk: . goffice/graph
- From: jbrefort svn gnome org
- To: svn-commits-list gnome org
- Subject: goffice r2161 - in trunk: . goffice/graph
- Date: Thu, 31 Jul 2008 07:55:52 +0000 (UTC)
Author: jbrefort
Date: Thu Jul 31 07:55:51 2008
New Revision: 2161
URL: http://svn.gnome.org/viewvc/goffice?rev=2161&view=rev
Log:
2008-07-31 Mariusz Adamski <mariusz adamski gmail com>
* goffice/graph/gog-axis-line-impl.h: add 3d axis labels positioning.
* goffice/graph/gog-axis-line.c: ditto.
* goffice/graph/gog-axis.c: ditto.
* goffice/graph/gog-label.c: ditto.
Modified:
trunk/ChangeLog
trunk/goffice/graph/gog-axis-line-impl.h
trunk/goffice/graph/gog-axis-line.c
trunk/goffice/graph/gog-axis.c
trunk/goffice/graph/gog-label.c
Modified: trunk/goffice/graph/gog-axis-line-impl.h
==============================================================================
--- trunk/goffice/graph/gog-axis-line-impl.h (original)
+++ trunk/goffice/graph/gog-axis-line-impl.h Thu Jul 31 07:55:51 2008
@@ -77,6 +77,9 @@
#define IS_GOG_AXIS_BASE_VIEW(o) (G_TYPE_CHECK_INSTANCE_TYPE ((o), GOG_AXIS_BASE_VIEW_TYPE))
GType gog_axis_base_view_get_type (void);
+void gog_axis_base_view_label_position_request (GogView *view,
+ GogViewAllocation const *bbox,
+ GogViewAllocation *pos);
G_END_DECLS
Modified: trunk/goffice/graph/gog-axis-line.c
==============================================================================
--- trunk/goffice/graph/gog-axis-line.c (original)
+++ trunk/goffice/graph/gog-axis-line.c Thu Jul 31 07:55:51 2008
@@ -971,7 +971,8 @@
typedef enum {
GOG_AXIS_BASE_RENDER,
GOG_AXIS_BASE_POINT,
- GOG_AXIS_BASE_PADDING_REQUEST
+ GOG_AXIS_BASE_PADDING_REQUEST,
+ GOG_AXIS_BASE_LABEL_POSITION_REQUEST,
} GogAxisBaseAction;
static gboolean
@@ -1542,6 +1543,8 @@
x, y, ax, ay, bx - ax, by - ay,
GO_SIDE_RIGHT);
break;
+ default:
+ break;
}
return FALSE;
@@ -1635,6 +1638,8 @@
x, y, ax, ay, bx - ax, by - ay,
side);
break;
+ default:
+ break;
}
return FALSE;
@@ -1738,6 +1743,8 @@
side);
}
break;
+ default:
+ break;
}
gog_chart_map_free (c_map);
} else {
@@ -1762,6 +1769,8 @@
case GOG_AXIS_BASE_POINT:
point = axis_circle_point (x, y, parms->cx, parms->cy, parms->rx, parms->th1);
break;
+ default:
+ break;
}
gog_chart_map_free (c_map);
}
@@ -1781,6 +1790,8 @@
GogViewAllocation axis_line_bbox;
GSList *axes;
GogAxisType perp_axis;
+ GOGeometryOBR obr;
+ GogAxisTick *ticks;
double ax, ay, az, bx, by, bz, ox, oy, dist, tmp;
double xposition, yposition, zposition;
double start, stop;
@@ -1788,6 +1799,8 @@
double *py[] = {&ay, &by, &by, &ay, &ay, &by, &by, &ay};
double *pz[] = {&az, &az, &az, &az, &bz, &bz, &bz, &bz};
double rx[8], ry[8], rz[8];
+ double major_tick_len, minor_tick_len, tick_len;
+ double label_w, label_h;
/* Note: Anti-clockwise order in each face,
* important for calculating normals */
@@ -1799,7 +1812,7 @@
1, 2, 6, 5, /* Front */
0, 4, 7, 3 /* Back */
};
- int i, vertex = 0, base = 0;
+ int i, tick_nbr, vertex = 0, base = 0;
GOGeometrySide side = GO_SIDE_LEFT;
g_return_val_if_fail (axis_type == GOG_AXIS_X ||
@@ -1973,6 +1986,63 @@
break;
case GOG_AXIS_BASE_POINT:
break;
+ case GOG_AXIS_BASE_LABEL_POSITION_REQUEST:
+ /* Calculating unit vector perpendicular to the
+ * axis projection */
+ if (side == GO_SIDE_RIGHT) {
+ ox = -(by - ay);
+ oy = bx - ax;
+ } else {
+ ox = by - ay;
+ oy = -(bx - ax);
+ }
+ tmp = sqrt (ox * ox + oy * oy);
+ ox *= 1. / tmp;
+ oy *= 1. / tmp;
+
+ /* Axis centre; we'll return it along with offset
+ * int the GogViewPadding structure */
+ padding->wl = 0.5 * (ax + bx);
+ padding->ht = 0.5 * (ay + by);
+
+ /* Calculating axis label offset */
+ dist = gog_axis_base_get_padding (axis_base);
+ padding->wl += gog_renderer_pt2r_x (view->renderer,
+ dist * ox);
+ padding->ht += gog_renderer_pt2r_y (view->renderer,
+ dist * oy);
+
+ minor_tick_len = gog_renderer_pt2r (view->renderer,
+ axis_base->minor.size_pts);
+ major_tick_len = gog_renderer_pt2r (view->renderer,
+ axis_base->major.size_pts);
+ tick_len = axis_base->major.tick_out ? major_tick_len :
+ (axis_base->minor.tick_out ? minor_tick_len : 0.);
+
+ tick_nbr = gog_axis_get_ticks (axis_base->axis, &ticks);
+
+ gog_renderer_get_text_OBR (view->renderer,
+ "0", TRUE, &obr);
+ tick_len += fabs (obr.w * ox);
+ if (axis_base->major_tick_labeled) {
+ label_w = label_h = 0;
+ for (i = 0; i < tick_nbr; i++) {
+ if (ticks[i].label == NULL)
+ continue;
+ gog_renderer_get_text_OBR (view->renderer,
+ ticks[i].label, TRUE, &obr);
+ if (obr.w > label_w)
+ label_w = obr.w;
+ if (obr.h > label_h)
+ label_h = obr.h;
+ }
+ tick_len += hypot (label_w, label_h);
+ }
+ padding->wr = tick_len * ox;
+ padding->hb = tick_len * oy;
+ break;
+ default:
+ break;
}
return FALSE;
@@ -2117,6 +2187,43 @@
#endif
}
+void
+gog_axis_base_view_label_position_request (GogView *view,
+ GogViewAllocation const *bbox,
+ GogViewAllocation *pos)
+{
+ GogAxisSet axis_set;
+ GogAxisBase *axis_base = GOG_AXIS_BASE (view->model);
+ GogStyle *style = axis_base->base.style;
+ GogViewPadding padding;
+
+ if (gog_axis_get_atype (axis_base->axis) >= GOG_AXIS_VIRTUAL)
+ return;
+ axis_set = gog_chart_get_axis_set (axis_base->chart);
+ if (axis_set == GOG_AXIS_SET_UNKNOWN)
+ return;
+
+ gog_renderer_push_style (view->renderer, style);
+
+ switch (axis_set & GOG_AXIS_SET_FUNDAMENTAL) {
+ case GOG_AXIS_SET_XYZ:
+ xyz_process (GOG_AXIS_BASE_LABEL_POSITION_REQUEST, view,
+ &padding, bbox, 0., 0.);
+ break;
+ default:
+ g_warning ("[AxisBaseView::label_position_request] not implemented for this axis set (%i)",
+ axis_set);
+ break;
+ }
+
+ gog_renderer_pop_style (view->renderer);
+
+ pos->x = padding.wl;
+ pos->y = padding.ht;
+ pos->w = padding.wr;
+ pos->h = padding.hb;
+}
+
static void
gog_axis_base_view_class_init (GogAxisBaseViewClass *gview_klass)
{
Modified: trunk/goffice/graph/gog-axis.c
==============================================================================
--- trunk/goffice/graph/gog-axis.c (original)
+++ trunk/goffice/graph/gog-axis.c Thu Jul 31 07:55:51 2008
@@ -2302,6 +2302,33 @@
}
static void
+gog_axis_view_size_allocate_3d (GogView *view, GogView *child,
+ GogViewAllocation const *plot_area)
+{
+ GogViewPadding padding;
+ GogViewAllocation child_bbox;
+ GogViewAllocation label_pos;
+ GogViewRequisition req, available;
+
+ gog_view_padding_request (child, plot_area, &padding);
+ gog_view_size_request (child, &available, &req);
+ gog_axis_base_view_label_position_request (view, plot_area, &label_pos);
+
+ child_bbox.x = label_pos.x + label_pos.w;
+ if (label_pos.w < 0)
+ child_bbox.x -= req.w;
+ child_bbox.y = label_pos.y + label_pos.h;
+ if (label_pos.h < 0)
+ child_bbox.y -= req.h;
+
+ child_bbox.w = req.w;
+ child_bbox.h = req.h;
+
+ gog_view_size_allocate (child, &child_bbox);
+
+}
+
+static void
gog_axis_view_size_allocate (GogView *view, GogViewAllocation const *bbox)
{
GSList *ptr;
@@ -2314,12 +2341,10 @@
GogViewRequisition req, available;
GogObjectPosition pos;
GogAxisPosition axis_pos;
+ GogChart *chart = GOG_CHART (gog_object_get_parent (view->model));
double const pad_h = gog_renderer_pt2r_y (view->renderer, PAD_HACK);
double const pad_w = gog_renderer_pt2r_x (view->renderer, PAD_HACK);
- if (gog_chart_is_3d (GOG_CHART (gog_object_get_parent (view->model))))
- return;
-
available.w = bbox->w;
available.h = bbox->h;
@@ -2336,6 +2361,11 @@
} else {
if (GOG_POSITION_IS_SPECIAL (pos)) {
if (IS_GOG_LABEL (child->model)) {
+ if (gog_chart_is_3d (chart)) {
+ gog_axis_view_size_allocate_3d (view,
+ child, plot_area);
+ return;
+ }
gog_view_size_request (child, &available, &req);
if (type == GOG_AXIS_X) {
child_bbox.x = plot_area->x +
Modified: trunk/goffice/graph/gog-label.c
==============================================================================
--- trunk/goffice/graph/gog-label.c (original)
+++ trunk/goffice/graph/gog-label.c Thu Jul 31 07:55:51 2008
@@ -22,6 +22,7 @@
#include <goffice/goffice-config.h>
#include <goffice/graph/gog-axis.h>
+#include <goffice/graph/gog-chart.h>
#include <goffice/graph/gog-data-set.h>
#include <goffice/graph/gog-label.h>
#include <goffice/graph/gog-outlined-object.h>
@@ -121,10 +122,13 @@
* in GogTheme, but it's not possible without breaking graph persistence
* compatibility */
parent = gog_object_get_parent (GOG_OBJECT (gso));
- if (IS_GOG_AXIS (parent) &&
- gog_axis_get_atype (GOG_AXIS (parent)) == GOG_AXIS_Y &&
- style->text_layout.auto_angle)
- style->text_layout.angle = 90.0;
+ if (IS_GOG_AXIS (parent)) {
+ GogChart *chart = GOG_CHART (gog_object_get_parent (parent));
+ if (!gog_chart_is_3d (chart)
+ && gog_axis_get_atype (GOG_AXIS (parent)) == GOG_AXIS_Y
+ && style->text_layout.auto_angle)
+ style->text_layout.angle = 90.0;
+ }
}
static void
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]