return object_type;
}
+enum
+ {
+ PROP_0,
+ PROP_MIN_EXTENT,
+ PROP_DEFAULT_SIZE
+ };
+
+
+static void
+psppire_axis_get_property (GObject *object,
+ guint prop_id,
+ GValue *value,
+ GParamSpec *pspec)
+{
+ PsppireAxis *axis = PSPPIRE_AXIS (object);
+
+ switch (prop_id)
+ {
+ case PROP_MIN_EXTENT:
+ g_value_set_long (value, axis->min_extent);
+ break;
+ case PROP_DEFAULT_SIZE:
+ g_value_set_int (value, axis->default_size);
+ break;
+ default:
+ G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
+ break;
+ };
+}
+
+
+static void
+psppire_axis_set_property (GObject *object,
+ guint prop_id,
+ const GValue *value,
+ GParamSpec *pspec)
+{
+ PsppireAxis *axis = PSPPIRE_AXIS (object);
+
+ switch (prop_id)
+ {
+ case PROP_MIN_EXTENT:
+ axis->min_extent = g_value_get_long (value);
+ break;
+ case PROP_DEFAULT_SIZE:
+ axis->default_size = g_value_get_int (value);
+ break;
+ default:
+ G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
+ break;
+ };
+}
static void
psppire_axis_class_init (PsppireAxisClass *class)
{
GObjectClass *object_class = G_OBJECT_CLASS (class);
+ GParamSpec *min_extent_spec;
+ GParamSpec *default_size_spec;
+
+ object_class->set_property = psppire_axis_set_property;
+ object_class->get_property = psppire_axis_get_property;
+
+ min_extent_spec =
+ g_param_spec_pointer ("minimum-extent",
+ "Minimum Extent",
+ "The smallest extent to which the axis will provide units (typically set to the height/width of the associated widget)",
+ G_PARAM_WRITABLE | G_PARAM_READABLE );
+
+ g_object_class_install_property (object_class,
+ PROP_MIN_EXTENT,
+ min_extent_spec);
+
+
+ default_size_spec =
+ g_param_spec_pointer ("default-size",
+ "Default Size",
+ "The size given to units which haven't been explicity inserted",
+ G_PARAM_WRITABLE | G_PARAM_READABLE );
+
+
+ g_object_class_install_property (object_class,
+ PROP_DEFAULT_SIZE,
+ default_size_spec);
parent_class = g_type_class_peek_parent (class);
object_class->finalize = psppire_axis_finalize;
}
+
static void
psppire_axis_init (PsppireAxis *axis)
{
+ axis->min_extent = 800;
+ axis->default_size = 75;
axis->pool = NULL;
psppire_axis_clear (axis);
}
{
const struct tower_node *node;
if (unit >= tower_count (&a->tower))
- return 0;
+ return a->default_size;
node = tower_get (&a->tower, unit);
gint
psppire_axis_unit_count (PsppireAxis *a)
{
- return tower_count (&a->tower);
+ glong padding = 0;
+
+ if ( tower_height (&a->tower) < a->min_extent )
+ padding = (a->min_extent - tower_height (&a->tower))
+ / a->default_size;
+
+ return tower_count (&a->tower) + padding;
}
+
+/* Return the starting pixel of UNIT */
glong
psppire_axis_pixel_start (PsppireAxis *a, gint unit)
{
const struct tower_node *node;
if ( unit >= tower_count (&a->tower))
- return tower_height (&a->tower);
+ {
+ return tower_height (&a->tower) +
+ (unit - tower_count (&a->tower)) * a->default_size;
+ }
node = tower_get (&a->tower, unit);
-
return tower_node_get_level (node);
}
+
+/* Return the unit covered by PIXEL */
gint
psppire_axis_get_unit_at_pixel (PsppireAxis *a, glong pixel)
{
unsigned long int node_start;
if (pixel >= tower_height (&a->tower))
- return tower_count (&a->tower);
+ {
+ glong extra = pixel - tower_height (&a->tower);
+ return tower_count (&a->tower) + extra / a->default_size;
+ }
node = tower_lookup (&a->tower, pixel, &node_start);
- return tower_node_get_index (node);
+ return tower_node_get_index (node);
}
void
}
-
void
psppire_axis_clear (PsppireAxis *a)
{