mirror of
https://github.com/varun-r-mallya/sysprof.git
synced 2025-12-31 20:36:25 +00:00
libsysprof-gtk: add pathological check for axis
That way we don't give values back that will not make any sense.
This commit is contained in:
@ -34,10 +34,11 @@ struct _SysprofAxisClass
|
|||||||
{
|
{
|
||||||
GObjectClass parent_class;
|
GObjectClass parent_class;
|
||||||
|
|
||||||
void (*get_min_value) (SysprofAxis *axis,
|
void (*get_min_value) (SysprofAxis *axis,
|
||||||
GValue *min_value);
|
GValue *min_value);
|
||||||
double (*normalize) (SysprofAxis *axis,
|
double (*normalize) (SysprofAxis *axis,
|
||||||
const GValue *value);
|
const GValue *value);
|
||||||
|
gboolean (*is_pathological) (SysprofAxis *axis);
|
||||||
};
|
};
|
||||||
|
|
||||||
#define SYSPROF_AXIS_GET_CLASS(obj) G_TYPE_INSTANCE_GET_CLASS(obj, SYSPROF_TYPE_AXIS, SysprofAxisClass)
|
#define SYSPROF_AXIS_GET_CLASS(obj) G_TYPE_INSTANCE_GET_CLASS(obj, SYSPROF_TYPE_AXIS, SysprofAxisClass)
|
||||||
@ -56,6 +57,15 @@ _sysprof_axis_normalize (SysprofAxis *axis,
|
|||||||
return SYSPROF_AXIS_GET_CLASS (axis)->normalize (axis, value);
|
return SYSPROF_AXIS_GET_CLASS (axis)->normalize (axis, value);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static inline double
|
||||||
|
_sysprof_axis_is_pathological (SysprofAxis *axis)
|
||||||
|
{
|
||||||
|
if (SYSPROF_AXIS_GET_CLASS (axis)->is_pathological)
|
||||||
|
return SYSPROF_AXIS_GET_CLASS (axis)->is_pathological (axis);
|
||||||
|
|
||||||
|
return FALSE;
|
||||||
|
}
|
||||||
|
|
||||||
void _sysprof_axis_emit_range_changed (SysprofAxis *self);
|
void _sysprof_axis_emit_range_changed (SysprofAxis *self);
|
||||||
|
|
||||||
G_END_DECLS
|
G_END_DECLS
|
||||||
|
|||||||
@ -105,6 +105,14 @@ sysprof_value_axis_normalize (SysprofAxis *axis,
|
|||||||
return r;
|
return r;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static gboolean
|
||||||
|
sysprof_value_axis_is_pathological (SysprofAxis *axis)
|
||||||
|
{
|
||||||
|
SysprofValueAxis *self = SYSPROF_VALUE_AXIS (axis);
|
||||||
|
|
||||||
|
return self->min_value == self->max_value;
|
||||||
|
}
|
||||||
|
|
||||||
static void
|
static void
|
||||||
sysprof_value_axis_get_property (GObject *object,
|
sysprof_value_axis_get_property (GObject *object,
|
||||||
guint prop_id,
|
guint prop_id,
|
||||||
@ -162,6 +170,7 @@ sysprof_value_axis_class_init (SysprofValueAxisClass *klass)
|
|||||||
|
|
||||||
axis_class->get_min_value = sysprof_value_axis_real_get_min_value;
|
axis_class->get_min_value = sysprof_value_axis_real_get_min_value;
|
||||||
axis_class->normalize = sysprof_value_axis_normalize;
|
axis_class->normalize = sysprof_value_axis_normalize;
|
||||||
|
axis_class->is_pathological = sysprof_value_axis_is_pathological;
|
||||||
|
|
||||||
properties[PROP_MIN_VALUE] =
|
properties[PROP_MIN_VALUE] =
|
||||||
g_param_spec_double ("min-value", NULL, NULL,
|
g_param_spec_double ("min-value", NULL, NULL,
|
||||||
|
|||||||
@ -20,6 +20,7 @@
|
|||||||
|
|
||||||
#include "config.h"
|
#include "config.h"
|
||||||
|
|
||||||
|
#include "sysprof-axis-private.h"
|
||||||
#include "sysprof-xy-layer-private.h"
|
#include "sysprof-xy-layer-private.h"
|
||||||
|
|
||||||
enum {
|
enum {
|
||||||
@ -192,6 +193,16 @@ _sysprof_xy_layer_get_xy (SysprofXYLayer *self,
|
|||||||
g_return_if_fail (y_values != NULL);
|
g_return_if_fail (y_values != NULL);
|
||||||
g_return_if_fail (n_values != NULL);
|
g_return_if_fail (n_values != NULL);
|
||||||
|
|
||||||
|
if (self->x_axis == NULL || _sysprof_axis_is_pathological (self->x_axis) ||
|
||||||
|
self->y_axis == NULL || _sysprof_axis_is_pathological (self->y_axis))
|
||||||
|
{
|
||||||
|
*n_values = 0;
|
||||||
|
*x_values = NULL;
|
||||||
|
*y_values = NULL;
|
||||||
|
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
*x_values = sysprof_normalized_series_get_values (self->normal_x, &n_x_values);
|
*x_values = sysprof_normalized_series_get_values (self->normal_x, &n_x_values);
|
||||||
*y_values = sysprof_normalized_series_get_values (self->normal_y, &n_y_values);
|
*y_values = sysprof_normalized_series_get_values (self->normal_y, &n_y_values);
|
||||||
*n_values = MIN (n_x_values, n_y_values);
|
*n_values = MIN (n_x_values, n_y_values);
|
||||||
|
|||||||
Reference in New Issue
Block a user