[gnome-power-manager] Rename the graph widget and sync changes from other projects
- From: Richard Hughes <rhughes src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gnome-power-manager] Rename the graph widget and sync changes from other projects
- Date: Tue, 18 Oct 2016 09:16:02 +0000 (UTC)
commit fb67b63c16dce1ccd3882433a6862c444075fccc
Author: Richard Hughes <richard hughsie com>
Date: Mon Oct 17 15:23:20 2016 +0100
Rename the graph widget and sync changes from other projects
src/Makefile.am | 8 +-
src/{gpm-point-obj.c => egg-graph-point.c} | 31 +-
src/{gpm-point-obj.h => egg-graph-point.h} | 20 +-
src/{gpm-graph-widget.c => egg-graph-widget.c} | 778 ++++++++++++------------
src/egg-graph-widget.h | 78 +++
src/gpm-graph-widget.h | 74 ---
src/gpm-statistics.c | 76 ++--
7 files changed, 514 insertions(+), 551 deletions(-)
---
diff --git a/src/Makefile.am b/src/Makefile.am
index f5b71d8..228c687 100644
--- a/src/Makefile.am
+++ b/src/Makefile.am
@@ -34,10 +34,10 @@ gnome_power_statistics_SOURCES = \
gpm-statistics.c \
gpm-resources.c \
gpm-resources.h \
- gpm-point-obj.c \
- gpm-point-obj.h \
- gpm-graph-widget.h \
- gpm-graph-widget.c
+ egg-graph-point.c \
+ egg-graph-point.h \
+ egg-graph-widget.h \
+ egg-graph-widget.c
gnome_power_statistics_LDADD = \
$(GLIB_LIBS) \
diff --git a/src/gpm-point-obj.c b/src/egg-graph-point.c
similarity index 71%
rename from src/gpm-point-obj.c
rename to src/egg-graph-point.c
index cdc1ce0..19578dd 100644
--- a/src/gpm-point-obj.c
+++ b/src/egg-graph-point.c
@@ -1,6 +1,6 @@
/* -*- Mode: C; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 8 -*-
*
- * Copyright (C) 2008 Richard Hughes <richard hughsie com>
+ * Copyright (C) 2008-2012 Richard Hughes <richard hughsie com>
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
@@ -20,41 +20,32 @@
#include <glib.h>
-#include "gpm-point-obj.h"
+#include "egg-graph-point.h"
-/**
- * gpm_point_obj_copy:
- **/
-GpmPointObj *
-gpm_point_obj_copy (const GpmPointObj *cobj)
+EggGraphPoint *
+egg_graph_point_copy (const EggGraphPoint *cobj)
{
- GpmPointObj *obj;
- obj = g_new0 (GpmPointObj, 1);
+ EggGraphPoint *obj;
+ obj = g_new0 (EggGraphPoint, 1);
obj->x = cobj->x;
obj->y = cobj->y;
obj->color = cobj->color;
return obj;
}
-/**
- * gpm_point_obj_new:
- **/
-GpmPointObj *
-gpm_point_obj_new (void)
+EggGraphPoint *
+egg_graph_point_new (void)
{
- GpmPointObj *obj;
- obj = g_new0 (GpmPointObj, 1);
+ EggGraphPoint *obj;
+ obj = g_new0 (EggGraphPoint, 1);
obj->x = 0.0f;
obj->y = 0.0f;
obj->color = 0x0;
return obj;
}
-/**
- * gpm_point_obj_free:
- **/
void
-gpm_point_obj_free (GpmPointObj *obj)
+egg_graph_point_free (EggGraphPoint *obj)
{
if (obj == NULL)
return;
diff --git a/src/gpm-point-obj.h b/src/egg-graph-point.h
similarity index 71%
rename from src/gpm-point-obj.h
rename to src/egg-graph-point.h
index a37e2a6..d78371c 100644
--- a/src/gpm-point-obj.h
+++ b/src/egg-graph-point.h
@@ -1,6 +1,6 @@
/* -*- Mode: C; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 8 -*-
*
- * Copyright (C) 2008 Richard Hughes <richard hughsie com>
+ * Copyright (C) 2008-2012 Richard Hughes <richard hughsie com>
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
@@ -18,8 +18,8 @@
*
*/
-#ifndef __GPM_POINT_OBJ_H__
-#define __GPM_POINT_OBJ_H__
+#ifndef __CH_POINT_OBJ_H__
+#define __CH_POINT_OBJ_H__
#include <glib.h>
@@ -27,16 +27,16 @@ G_BEGIN_DECLS
typedef struct
{
- gfloat x;
- gfloat y;
+ gdouble x;
+ gdouble y;
guint32 color;
-} GpmPointObj;
+} EggGraphPoint;
-GpmPointObj *gpm_point_obj_new (void);
-GpmPointObj *gpm_point_obj_copy (const GpmPointObj *cobj);
-void gpm_point_obj_free (GpmPointObj *obj);
+EggGraphPoint *egg_graph_point_new (void);
+EggGraphPoint *egg_graph_point_copy (const EggGraphPoint *cobj);
+void egg_graph_point_free (EggGraphPoint *obj);
G_END_DECLS
-#endif /* __GPM_POINT_OBJ_H__ */
+#endif /* __CH_POINT_OBJ_H__ */
diff --git a/src/gpm-graph-widget.c b/src/egg-graph-widget.c
similarity index 55%
rename from src/gpm-graph-widget.c
rename to src/egg-graph-widget.c
index e674b6d..e063816 100644
--- a/src/gpm-graph-widget.c
+++ b/src/egg-graph-widget.c
@@ -1,6 +1,6 @@
/* -*- Mode: C; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 8 -*-
*
- * Copyright (C) 2006-2011 Richard Hughes <richard hughsie com>
+ * Copyright (C) 2006-2016 Richard Hughes <richard hughsie com>
*
* Licensed under the GNU General Public License Version 2
*
@@ -25,11 +25,12 @@
#include <glib/gi18n.h>
#include <stdlib.h>
#include <math.h>
+#include <cairo-svg.h>
-#include "gpm-point-obj.h"
-#include "gpm-graph-widget.h"
+#include "egg-graph-point.h"
+#include "egg-graph-widget.h"
-#define GPM_GRAPH_WIDGET_FONT "Sans 8"
+#define EGG_GRAPH_WIDGET_FONT "Sans 8"
typedef struct {
gboolean use_grid;
@@ -37,36 +38,34 @@ typedef struct {
gboolean autorange_x;
gboolean autorange_y;
- GSList *key_data; /* lines */
-
- gint stop_x;
- gint stop_y;
- gint start_x;
- gint start_y;
+ gdouble stop_x;
+ gdouble stop_y;
+ gdouble start_x;
+ gdouble start_y;
gint box_x; /* size of the white box, not the widget */
gint box_y;
gint box_width;
gint box_height;
- gfloat unit_x; /* 10th width of graph */
- gfloat unit_y; /* 10th width of graph */
+ gdouble unit_x; /* 10th width of graph */
+ gdouble unit_y; /* 10th width of graph */
- GpmGraphWidgetType type_x;
- GpmGraphWidgetType type_y;
+ EggGraphWidgetKind type_x;
+ EggGraphWidgetKind type_y;
gchar *title;
- cairo_t *cr;
PangoLayout *layout;
GPtrArray *data_list;
GPtrArray *plot_list;
-} GpmGraphWidgetPrivate;
+ GPtrArray *legend_list;
+} EggGraphWidgetPrivate;
-G_DEFINE_TYPE_WITH_PRIVATE (GpmGraphWidget, gpm_graph_widget, GTK_TYPE_DRAWING_AREA);
-#define GET_PRIVATE(o) (gpm_graph_widget_get_instance_private (o))
+G_DEFINE_TYPE_WITH_PRIVATE (EggGraphWidget, egg_graph_widget, GTK_TYPE_DRAWING_AREA);
+#define GET_PRIVATE(o) (egg_graph_widget_get_instance_private (o))
-static gboolean gpm_graph_widget_draw (GtkWidget *widget, cairo_t *cr);
-static void gpm_graph_widget_finalize (GObject *object);
+static gboolean egg_graph_widget_draw (GtkWidget *widget, cairo_t *cr);
+static void egg_graph_widget_finalize (GObject *object);
enum
{
@@ -81,61 +80,63 @@ enum
PROP_START_Y,
PROP_STOP_X,
PROP_STOP_Y,
+ PROP_LAST
};
-/**
- * gpm_graph_widget_key_data_clear:
- **/
-static gboolean
-gpm_graph_widget_key_data_clear (GpmGraphWidget *graph)
-{
- GpmGraphWidgetPrivate *priv = GET_PRIVATE (graph);
- GpmGraphWidgetKeyData *keyitem;
- guint i;
-
- g_return_val_if_fail (GPM_IS_GRAPH_WIDGET (graph), FALSE);
-
- /* remove items in list and free */
- for (i = 0; i < g_slist_length (priv->key_data); i++) {
- keyitem = (GpmGraphWidgetKeyData *) g_slist_nth_data (priv->key_data, i);
- g_free (keyitem->desc);
- g_free (keyitem);
- }
- g_slist_free (priv->key_data);
- priv->key_data = NULL;
+typedef struct {
+ gchar *desc;
+ guint32 color;
+} EggGraphWidgetLegendData;
- return TRUE;
+static void
+egg_graph_widget_key_legend_data_free (EggGraphWidgetLegendData *legend_data)
+{
+ g_free (legend_data->desc);
+ g_free (legend_data);
}
-/**
- * gpm_graph_widget_key_data_add:
- **/
-gboolean
-gpm_graph_widget_key_data_add (GpmGraphWidget *graph, guint32 color, const gchar *desc)
+void
+egg_graph_widget_key_legend_add (EggGraphWidget *graph, guint32 color, const gchar *desc)
{
- GpmGraphWidgetPrivate *priv = GET_PRIVATE (graph);
- GpmGraphWidgetKeyData *keyitem;
+ EggGraphWidgetPrivate *priv = GET_PRIVATE (graph);
+ EggGraphWidgetLegendData *legend_data;
- g_return_val_if_fail (GPM_IS_GRAPH_WIDGET (graph), FALSE);
+ g_return_if_fail (EGG_IS_GRAPH_WIDGET (graph));
g_debug ("add to list %s", desc);
- keyitem = g_new0 (GpmGraphWidgetKeyData, 1);
+ legend_data = g_new0 (EggGraphWidgetLegendData, 1);
+ legend_data->color = color;
+ legend_data->desc = g_strdup (desc);
+ g_ptr_array_add (priv->legend_list, legend_data);
+}
- keyitem->color = color;
- keyitem->desc = g_strdup (desc);
+void
+egg_graph_widget_key_legend_clear (EggGraphWidget *graph)
+{
+ EggGraphWidgetPrivate *priv = GET_PRIVATE (graph);
+ g_return_if_fail (EGG_IS_GRAPH_WIDGET (graph));
+ g_ptr_array_set_size (priv->legend_list, 0);
+}
- priv->key_data = g_slist_append (priv->key_data, (gpointer) keyitem);
- return TRUE;
+void
+egg_graph_widget_set_use_legend (EggGraphWidget *graph, gboolean use_legend)
+{
+ EggGraphWidgetPrivate *priv = GET_PRIVATE (graph);
+ priv->use_legend = use_legend;
+}
+
+gboolean
+egg_graph_widget_get_use_legend (EggGraphWidget *graph)
+{
+ EggGraphWidgetPrivate *priv = GET_PRIVATE (graph);
+ return priv->use_legend;
}
-/**
- * up_graph_get_property:
- **/
static void
up_graph_get_property (GObject *object, guint prop_id, GValue *value, GParamSpec *pspec)
{
- GpmGraphWidget *graph = GPM_GRAPH_WIDGET (object);
- GpmGraphWidgetPrivate *priv = GET_PRIVATE (graph);
+ EggGraphWidget *graph = EGG_GRAPH_WIDGET (object);
+ EggGraphWidgetPrivate *priv = GET_PRIVATE (graph);
switch (prop_id) {
case PROP_USE_LEGEND:
g_value_set_boolean (value, priv->use_legend);
@@ -156,16 +157,16 @@ up_graph_get_property (GObject *object, guint prop_id, GValue *value, GParamSpec
g_value_set_boolean (value, priv->autorange_y);
break;
case PROP_START_X:
- g_value_set_int (value, priv->start_x);
+ g_value_set_double (value, priv->start_x);
break;
case PROP_START_Y:
- g_value_set_int (value, priv->start_y);
+ g_value_set_double (value, priv->start_y);
break;
case PROP_STOP_X:
- g_value_set_int (value, priv->stop_x);
+ g_value_set_double (value, priv->stop_x);
break;
case PROP_STOP_Y:
- g_value_set_int (value, priv->stop_y);
+ g_value_set_double (value, priv->stop_y);
break;
default:
G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
@@ -173,14 +174,11 @@ up_graph_get_property (GObject *object, guint prop_id, GValue *value, GParamSpec
}
}
-/**
- * up_graph_set_property:
- **/
static void
up_graph_set_property (GObject *object, guint prop_id, const GValue *value, GParamSpec *pspec)
{
- GpmGraphWidget *graph = GPM_GRAPH_WIDGET (object);
- GpmGraphWidgetPrivate *priv = GET_PRIVATE (graph);
+ EggGraphWidget *graph = EGG_GRAPH_WIDGET (object);
+ EggGraphWidgetPrivate *priv = GET_PRIVATE (graph);
switch (prop_id) {
case PROP_USE_LEGEND:
@@ -202,16 +200,16 @@ up_graph_set_property (GObject *object, guint prop_id, const GValue *value, GPar
priv->autorange_y = g_value_get_boolean (value);
break;
case PROP_START_X:
- priv->start_x = g_value_get_int (value);
+ priv->start_x = g_value_get_double (value);
break;
case PROP_START_Y:
- priv->start_y = g_value_get_int (value);
+ priv->start_y = g_value_get_double (value);
break;
case PROP_STOP_X:
- priv->stop_x = g_value_get_int (value);
+ priv->stop_x = g_value_get_double (value);
break;
case PROP_STOP_Y:
- priv->stop_y = g_value_get_int (value);
+ priv->stop_y = g_value_get_double (value);
break;
default:
G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
@@ -223,20 +221,16 @@ up_graph_set_property (GObject *object, guint prop_id, const GValue *value, GPar
gtk_widget_show (GTK_WIDGET (graph));
}
-/**
- * gpm_graph_widget_class_init:
- * @class: This graph class instance
- **/
static void
-gpm_graph_widget_class_init (GpmGraphWidgetClass *class)
+egg_graph_widget_class_init (EggGraphWidgetClass *class)
{
GtkWidgetClass *widget_class = GTK_WIDGET_CLASS (class);
GObjectClass *object_class = G_OBJECT_CLASS (class);
- widget_class->draw = gpm_graph_widget_draw;
+ widget_class->draw = egg_graph_widget_draw;
object_class->get_property = up_graph_get_property;
object_class->set_property = up_graph_set_property;
- object_class->finalize = gpm_graph_widget_finalize;
+ object_class->finalize = egg_graph_widget_finalize;
/* properties */
g_object_class_install_property (object_class,
@@ -252,16 +246,16 @@ gpm_graph_widget_class_init (GpmGraphWidgetClass *class)
g_object_class_install_property (object_class,
PROP_TYPE_X,
g_param_spec_uint ("type-x", NULL, NULL,
- GPM_GRAPH_WIDGET_TYPE_INVALID,
- GPM_GRAPH_WIDGET_TYPE_UNKNOWN,
- GPM_GRAPH_WIDGET_TYPE_TIME,
+ EGG_GRAPH_WIDGET_KIND_INVALID,
+ EGG_GRAPH_WIDGET_KIND_UNKNOWN,
+ EGG_GRAPH_WIDGET_KIND_TIME,
G_PARAM_READWRITE));
g_object_class_install_property (object_class,
PROP_TYPE_Y,
g_param_spec_uint ("type-y", NULL, NULL,
- GPM_GRAPH_WIDGET_TYPE_INVALID,
- GPM_GRAPH_WIDGET_TYPE_UNKNOWN,
- GPM_GRAPH_WIDGET_TYPE_PERCENTAGE,
+ EGG_GRAPH_WIDGET_KIND_INVALID,
+ EGG_GRAPH_WIDGET_KIND_UNKNOWN,
+ EGG_GRAPH_WIDGET_KIND_PERCENTAGE,
G_PARAM_READWRITE));
g_object_class_install_property (object_class,
PROP_AUTORANGE_X,
@@ -275,36 +269,32 @@ gpm_graph_widget_class_init (GpmGraphWidgetClass *class)
G_PARAM_READWRITE));
g_object_class_install_property (object_class,
PROP_START_X,
- g_param_spec_int ("start-x", NULL, NULL,
- G_MININT, G_MAXINT, 0,
+ g_param_spec_double ("start-x", NULL, NULL,
+ -G_MAXDOUBLE, G_MAXDOUBLE, 0.f,
G_PARAM_READWRITE));
g_object_class_install_property (object_class,
PROP_START_Y,
- g_param_spec_int ("start-y", NULL, NULL,
- G_MININT, G_MAXINT, 0,
+ g_param_spec_double ("start-y", NULL, NULL,
+ -G_MAXDOUBLE, G_MAXDOUBLE, 0.f,
G_PARAM_READWRITE));
g_object_class_install_property (object_class,
PROP_STOP_X,
- g_param_spec_int ("stop-x", NULL, NULL,
- G_MININT, G_MAXINT, 60,
+ g_param_spec_double ("stop-x", NULL, NULL,
+ -G_MAXDOUBLE, G_MAXDOUBLE, 60.f,
G_PARAM_READWRITE));
g_object_class_install_property (object_class,
PROP_STOP_Y,
- g_param_spec_int ("stop-y", NULL, NULL,
- G_MININT, G_MAXINT, 100,
+ g_param_spec_double ("stop-y", NULL, NULL,
+ -G_MAXDOUBLE, G_MAXDOUBLE, 100.f,
G_PARAM_READWRITE));
}
-/**
- * gpm_graph_widget_init:
- * @graph: This class instance
- **/
static void
-gpm_graph_widget_init (GpmGraphWidget *graph)
+egg_graph_widget_init (EggGraphWidget *graph)
{
PangoContext *context;
PangoFontDescription *desc;
- GpmGraphWidgetPrivate *priv = GET_PRIVATE (graph);
+ EggGraphWidgetPrivate *priv = GET_PRIVATE (graph);
priv->start_x = 0;
priv->start_y = 0;
@@ -312,83 +302,68 @@ gpm_graph_widget_init (GpmGraphWidget *graph)
priv->stop_y = 100;
priv->use_grid = TRUE;
priv->use_legend = FALSE;
+ priv->legend_list = g_ptr_array_new_with_free_func ((GDestroyNotify)
egg_graph_widget_key_legend_data_free);
priv->data_list = g_ptr_array_new_with_free_func ((GDestroyNotify) g_ptr_array_unref);
priv->plot_list = g_ptr_array_new ();
- priv->key_data = NULL;
- priv->type_x = GPM_GRAPH_WIDGET_TYPE_TIME;
- priv->type_y = GPM_GRAPH_WIDGET_TYPE_PERCENTAGE;
+ priv->type_x = EGG_GRAPH_WIDGET_KIND_TIME;
+ priv->type_y = EGG_GRAPH_WIDGET_KIND_PERCENTAGE;
/* do pango stuff */
context = gtk_widget_get_pango_context (GTK_WIDGET (graph));
pango_context_set_base_gravity (context, PANGO_GRAVITY_AUTO);
priv->layout = pango_layout_new (context);
- desc = pango_font_description_from_string (GPM_GRAPH_WIDGET_FONT);
+ desc = pango_font_description_from_string (EGG_GRAPH_WIDGET_FONT);
pango_layout_set_font_description (priv->layout, desc);
pango_font_description_free (desc);
}
-/**
- * gpm_graph_widget_data_clear:
- **/
-gboolean
-gpm_graph_widget_data_clear (GpmGraphWidget *graph)
+void
+egg_graph_widget_data_clear (EggGraphWidget *graph)
{
- GpmGraphWidgetPrivate *priv = GET_PRIVATE (graph);
-
- g_return_val_if_fail (GPM_IS_GRAPH_WIDGET (graph), FALSE);
-
+ EggGraphWidgetPrivate *priv = GET_PRIVATE (graph);
+ g_return_if_fail (EGG_IS_GRAPH_WIDGET (graph));
g_ptr_array_set_size (priv->data_list, 0);
g_ptr_array_set_size (priv->plot_list, 0);
-
- return TRUE;
}
-/**
- * gpm_graph_widget_finalize:
- * @object: This graph class instance
- **/
static void
-gpm_graph_widget_finalize (GObject *object)
+egg_graph_widget_finalize (GObject *object)
{
- GpmGraphWidget *graph = (GpmGraphWidget*) object;
- GpmGraphWidgetPrivate *priv = GET_PRIVATE (graph);
-
- /* clear key and data */
- gpm_graph_widget_key_data_clear (graph);
- gpm_graph_widget_data_clear (graph);
+ EggGraphWidget *graph = (EggGraphWidget*) object;
+ EggGraphWidgetPrivate *priv = GET_PRIVATE (graph);
- /* free data */
+ g_ptr_array_unref (priv->legend_list);
g_ptr_array_unref (priv->data_list);
g_ptr_array_unref (priv->plot_list);
g_object_unref (priv->layout);
- G_OBJECT_CLASS (gpm_graph_widget_parent_class)->finalize (object);
+ G_OBJECT_CLASS (egg_graph_widget_parent_class)->finalize (object);
}
/**
- * gpm_graph_widget_data_assign:
+ * egg_graph_widget_data_add:
* @graph: This class instance
- * @data: an array of GpmPointObj's
+ * @data: an array of EggGraphPoint's
*
* Sets the data for the graph
**/
-gboolean
-gpm_graph_widget_data_assign (GpmGraphWidget *graph, GpmGraphWidgetPlot plot, GPtrArray *data)
+void
+egg_graph_widget_data_add (EggGraphWidget *graph, EggGraphWidgetPlot plot, GPtrArray *data)
{
- GpmGraphWidgetPrivate *priv = GET_PRIVATE (graph);
+ EggGraphWidgetPrivate *priv = GET_PRIVATE (graph);
GPtrArray *copy;
- GpmPointObj *obj;
+ EggGraphPoint *obj;
guint i;
- g_return_val_if_fail (data != NULL, FALSE);
- g_return_val_if_fail (GPM_IS_GRAPH_WIDGET (graph), FALSE);
+ g_return_if_fail (data != NULL);
+ g_return_if_fail (EGG_IS_GRAPH_WIDGET (graph));
/* make a deep copy */
- copy = g_ptr_array_new_with_free_func ((GDestroyNotify) gpm_point_obj_free);
+ copy = g_ptr_array_new_with_free_func ((GDestroyNotify) egg_graph_point_free);
for (i = 0; i < data->len; i++) {
- obj = gpm_point_obj_copy (g_ptr_array_index (data, i));
+ obj = egg_graph_point_copy (g_ptr_array_index (data, i));
g_ptr_array_add (copy, obj);
}
@@ -398,27 +373,13 @@ gpm_graph_widget_data_assign (GpmGraphWidget *graph, GpmGraphWidgetPlot plot, GP
/* refresh */
gtk_widget_queue_draw (GTK_WIDGET (graph));
-
- return TRUE;
}
-/**
- * gpm_get_axis_label:
- * @axis: The axis type, e.g. GPM_GRAPH_WIDGET_TYPE_TIME
- * @value: The data value, e.g. 120
- *
- * Unit is:
- * GPM_GRAPH_WIDGET_TYPE_TIME: seconds
- * GPM_GRAPH_WIDGET_TYPE_POWER: Wh (not Ah)
- * GPM_GRAPH_WIDGET_TYPE_PERCENTAGE: %
- *
- * Return value: a string value depending on the axis type and the value.
- **/
static gchar *
-gpm_get_axis_label (GpmGraphWidgetType axis, gfloat value)
+egg_graph_widget_get_axis_label (EggGraphWidgetKind axis, gdouble value)
{
gchar *text = NULL;
- if (axis == GPM_GRAPH_WIDGET_TYPE_TIME) {
+ if (axis == EGG_GRAPH_WIDGET_KIND_TIME) {
gint time_s = abs((gint) value);
gint minutes = time_s / 60;
gint seconds = time_s - (minutes * 60);
@@ -450,43 +411,42 @@ gpm_get_axis_label (GpmGraphWidgetType axis, gfloat value)
/*Translators: This is %2i minutes %02i seconds*/
text = g_strdup_printf (_("%2im%02i"), minutes, seconds);
}
+ } else if (value > 0.f && seconds < 2) {
+ /* TRANSLATORS: This is ms*/
+ text = g_strdup_printf (_("%.0fms"), value * 1000.f);
} else {
/*Translators: This is %2i seconds*/
text = g_strdup_printf (_("%2is"), seconds);
}
- } else if (axis == GPM_GRAPH_WIDGET_TYPE_PERCENTAGE) {
- /*Translators: This is %i Percentage*/
+ } else if (axis == EGG_GRAPH_WIDGET_KIND_PERCENTAGE) {
+ /* TRANSLATORS: This is %i Percentage*/
text = g_strdup_printf (_("%i%%"), (gint) value);
- } else if (axis == GPM_GRAPH_WIDGET_TYPE_POWER) {
- /*Translators: This is %.1f Watts*/
+ } else if (axis == EGG_GRAPH_WIDGET_KIND_POWER) {
+ /* TRANSLATORS: This is %.1f Watts*/
text = g_strdup_printf (_("%.1fW"), value);
- } else if (axis == GPM_GRAPH_WIDGET_TYPE_FACTOR) {
- text = g_strdup_printf ("%.1f", value);
- } else if (axis == GPM_GRAPH_WIDGET_TYPE_VOLTAGE) {
- /*Translators: This is %.1f Volts*/
+ } else if (axis == EGG_GRAPH_WIDGET_KIND_FACTOR) {
+ text = g_strdup_printf ("%.2f", value);
+ } else if (axis == EGG_GRAPH_WIDGET_KIND_VOLTAGE) {
+ /* TRANSLATORS: This is %.1f Volts*/
text = g_strdup_printf (_("%.1fV"), value);
+ } else if (axis == EGG_GRAPH_WIDGET_KIND_WAVELENGTH) {
+ /* TRANSLATORS: This is %.1f nanometers */
+ text = g_strdup_printf (_("%.0f nm"), value);
} else {
text = g_strdup_printf ("%i", (gint) value);
}
return text;
}
-/**
- * gpm_graph_widget_draw_grid:
- * @graph: This class instance
- * @cr: Cairo drawing context
- *
- * Draw the 10x10 dotted grid onto the graph.
- **/
static void
-gpm_graph_widget_draw_grid (GpmGraphWidget *graph, cairo_t *cr)
+egg_graph_widget_draw_grid (EggGraphWidget *graph, cairo_t *cr)
{
- GpmGraphWidgetPrivate *priv = GET_PRIVATE (graph);
+ EggGraphWidgetPrivate *priv = GET_PRIVATE (graph);
guint i;
- gfloat b;
+ gdouble b;
gdouble dotted[] = {1., 2.};
- gfloat divwidth = (gfloat)priv->box_width / 10.0f;
- gfloat divheight = (gfloat)priv->box_height / 10.0f;
+ gdouble divwidth = (gdouble)priv->box_width / 10.0f;
+ gdouble divheight = (gdouble)priv->box_height / 10.0f;
cairo_save (cr);
@@ -495,16 +455,16 @@ gpm_graph_widget_draw_grid (GpmGraphWidget *graph, cairo_t *cr)
/* do vertical lines */
cairo_set_source_rgb (cr, 0.1, 0.1, 0.1);
- for (i=1; i<10; i++) {
- b = priv->box_x + ((gfloat) i * divwidth);
+ for (i = 1; i < 10; i++) {
+ b = priv->box_x + ((gdouble) i * divwidth);
cairo_move_to (cr, (gint)b + 0.5f, priv->box_y);
cairo_line_to (cr, (gint)b + 0.5f, priv->box_y + priv->box_height);
cairo_stroke (cr);
}
/* do horizontal lines */
- for (i=1; i<10; i++) {
- b = priv->box_y + ((gfloat) i * divheight);
+ for (i = 1; i < 10; i++) {
+ b = priv->box_y + ((gdouble) i * divheight);
cairo_move_to (cr, priv->box_x, (gint)b + 0.5f);
cairo_line_to (cr, priv->box_x + priv->box_width, (int)b + 0.5f);
cairo_stroke (cr);
@@ -513,37 +473,30 @@ gpm_graph_widget_draw_grid (GpmGraphWidget *graph, cairo_t *cr)
cairo_restore (cr);
}
-/**
- * gpm_graph_widget_draw_labels:
- * @graph: This class instance
- * @cr: Cairo drawing context
- *
- * Draw the X and the Y labels onto the graph.
- **/
static void
-gpm_graph_widget_draw_labels (GpmGraphWidget *graph, cairo_t *cr)
+egg_graph_widget_draw_labels (EggGraphWidget *graph, cairo_t *cr)
{
- GpmGraphWidgetPrivate *priv = GET_PRIVATE (graph);
+ EggGraphWidgetPrivate *priv = GET_PRIVATE (graph);
guint i;
- gfloat b;
- gfloat value;
- gfloat divwidth = (gfloat)priv->box_width / 10.0f;
- gfloat divheight = (gfloat)priv->box_height / 10.0f;
- gint length_x = priv->stop_x - priv->start_x;
- gint length_y = priv->stop_y - priv->start_y;
+ gdouble b;
+ gdouble value;
+ gdouble divwidth = (gdouble)priv->box_width / 10.0f;
+ gdouble divheight = (gdouble)priv->box_height / 10.0f;
+ gdouble length_x = priv->stop_x - priv->start_x;
+ gdouble length_y = priv->stop_y - priv->start_y;
PangoRectangle ink_rect, logical_rect;
- gfloat offsetx = 0;
- gfloat offsety = 0;
+ gdouble offsetx = 0;
+ gdouble offsety = 0;
cairo_save (cr);
/* do x text */
- cairo_set_source_rgb (cr, 0, 0, 0);
+ cairo_set_source_rgb (cr, 0.2f, 0.2f, 0.2f);
for (i = 0; i < 11; i++) {
g_autofree gchar *text = NULL;
- b = priv->box_x + ((gfloat) i * divwidth);
- value = ((length_x / 10.0f) * (gfloat) i) + (gfloat) priv->start_x;
- text = gpm_get_axis_label (priv->type_x, value);
+ b = priv->box_x + ((gdouble) i * divwidth);
+ value = ((length_x / 10.0f) * (gdouble) i) + (gdouble) priv->start_x;
+ text = egg_graph_widget_get_axis_label (priv->type_x, value);
pango_layout_set_text (priv->layout, text, -1);
pango_layout_get_pixel_extents (priv->layout, &ink_rect, &logical_rect);
@@ -564,9 +517,9 @@ gpm_graph_widget_draw_labels (GpmGraphWidget *graph, cairo_t *cr)
/* do y text */
for (i = 0; i < 11; i++) {
g_autofree gchar *text = NULL;
- b = priv->box_y + ((gfloat) i * divheight);
- value = ((gfloat) length_y / 10.0f) * (10 - (gfloat) i) + priv->start_y;
- text = gpm_get_axis_label (priv->type_y, value);
+ b = priv->box_y + ((gdouble) i * divheight);
+ value = ((gdouble) length_y / 10.0f) * (10 - (gdouble) i) + priv->start_y;
+ text = egg_graph_widget_get_axis_label (priv->type_y, value);
pango_layout_set_text (priv->layout, text, -1);
pango_layout_get_pixel_extents (priv->layout, &ink_rect, &logical_rect);
@@ -587,31 +540,18 @@ gpm_graph_widget_draw_labels (GpmGraphWidget *graph, cairo_t *cr)
cairo_restore (cr);
}
-/**
- * gpm_color_to_rgb:
- * @red: The red value
- * @green: The green value
- * @blue: The blue value
- **/
static void
-gpm_color_to_rgb (guint32 color, guint8 *red, guint8 *green, guint8 *blue)
+egg_color_to_rgb (guint32 color, guint8 *red, guint8 *green, guint8 *blue)
{
*red = (color & 0xff0000) / 0x10000;
*green = (color & 0x00ff00) / 0x100;
*blue = color & 0x0000ff;
}
-/**
- * gpm_graph_widget_get_y_label_max_width:
- * @graph: This class instance
- * @cr: Cairo drawing context
- *
- * Draw the X and the Y labels onto the graph.
- **/
static guint
-gpm_graph_widget_get_y_label_max_width (GpmGraphWidget *graph, cairo_t *cr)
+egg_graph_widget_get_y_label_max_width (EggGraphWidget *graph, cairo_t *cr)
{
- GpmGraphWidgetPrivate *priv = GET_PRIVATE (graph);
+ EggGraphWidgetPrivate *priv = GET_PRIVATE (graph);
guint i;
gint value;
gint length_y = priv->stop_y - priv->start_y;
@@ -621,8 +561,8 @@ gpm_graph_widget_get_y_label_max_width (GpmGraphWidget *graph, cairo_t *cr)
/* do y text */
for (i = 0; i < 11; i++) {
g_autofree gchar *text = NULL;
- value = (length_y / 10) * (10 - (gfloat) i) + priv->start_y;
- text = gpm_get_axis_label (priv->type_y, value);
+ value = (length_y / 10) * (10 - (gdouble) i) + priv->start_y;
+ text = egg_graph_widget_get_axis_label (priv->type_y, value);
pango_layout_set_text (priv->layout, text, -1);
pango_layout_get_pixel_extents (priv->layout, &ink_rect, &logical_rect);
if (ink_rect.width > (gint) biggest)
@@ -632,7 +572,7 @@ gpm_graph_widget_get_y_label_max_width (GpmGraphWidget *graph, cairo_t *cr)
}
/**
- * gpm_round_up:
+ * egg_graph_round_up:
* @value: The input value
* @smallest: The smallest increment allowed
*
@@ -642,24 +582,24 @@ gpm_graph_widget_get_y_label_max_width (GpmGraphWidget *graph, cairo_t *cr)
* 112, 10 120
* 100, 10 100
**/
-static gint
-gpm_round_up (gfloat value, gint smallest)
+static gdouble
+egg_graph_round_up (gdouble value, gint smallest)
{
- gfloat division;
+ gdouble division;
if (fabs (value) < 0.01)
return 0;
if (smallest == 0) {
g_warning ("divisor zero");
return 0;
}
- division = (gfloat) value / (gfloat) smallest;
+ division = (gdouble) value / (gdouble) smallest;
division = ceilf (division);
division *= smallest;
return (gint) division;
}
/**
- * gpm_round_down:
+ * egg_graph_round_down:
* @value: The input value
* @smallest: The smallest increment allowed
*
@@ -669,24 +609,24 @@ gpm_round_up (gfloat value, gint smallest)
* 112, 10 110
* 100, 10 100
**/
-static gint
-gpm_round_down (gfloat value, gint smallest)
+static gdouble
+egg_graph_round_down (gdouble value, gint smallest)
{
- gfloat division;
+ gdouble division;
if (fabs (value) < 0.01)
return 0;
if (smallest == 0) {
g_warning ("divisor zero");
return 0;
}
- division = (gfloat) value / (gfloat) smallest;
+ division = (gdouble) value / (gdouble) smallest;
division = floorf (division);
division *= smallest;
return (gint) division;
}
/**
- * gpm_graph_widget_autorange_x:
+ * egg_graph_widget_autorange_x:
* @graph: This class instance
*
* Autoranges the graph axis depending on the axis type, and the maximum
@@ -694,22 +634,22 @@ gpm_round_down (gfloat value, gint smallest)
* resolution but also a number that scales "well" to a 10x10 grid.
**/
static void
-gpm_graph_widget_autorange_x (GpmGraphWidget *graph)
+egg_graph_widget_autorange_x (EggGraphWidget *graph)
{
- GpmGraphWidgetPrivate *priv = GET_PRIVATE (graph);
- gfloat biggest_x = G_MINFLOAT;
- gfloat smallest_x = G_MAXFLOAT;
- guint rounding_x = 1;
+ EggGraphWidgetPrivate *priv = GET_PRIVATE (graph);
+ EggGraphPoint *point;
+ GPtrArray *array;
GPtrArray *data;
- GpmPointObj *point;
+ gdouble biggest_x = G_MINFLOAT;
+ gdouble smallest_x = G_MAXFLOAT;
+ guint rounding_x = 1;
guint i, j;
guint len = 0;
- GPtrArray *array;
array = priv->data_list;
/* find out if we have no data */
- for (j=0; j<array->len; j++) {
+ for (j = 0; j < array->len; j++) {
data = g_ptr_array_index (array, j);
len = data->len;
if (len > 0)
@@ -725,10 +665,10 @@ gpm_graph_widget_autorange_x (GpmGraphWidget *graph)
}
/* get the range for the graph */
- for (j=0; j<array->len; j++) {
+ for (j = 0; j < array->len; j++) {
data = g_ptr_array_index (array, j);
- for (i=0; i < data->len; i++) {
- point = (GpmPointObj *) g_ptr_array_index (data, i);
+ for (i = 0; i < data->len; i++) {
+ point = (EggGraphPoint *) g_ptr_array_index (data, i);
if (point->x > biggest_x)
biggest_x = point->x;
if (point->x < smallest_x)
@@ -742,15 +682,15 @@ gpm_graph_widget_autorange_x (GpmGraphWidget *graph)
smallest_x--;
}
- if (priv->type_x == GPM_GRAPH_WIDGET_TYPE_PERCENTAGE) {
+ if (priv->type_x == EGG_GRAPH_WIDGET_KIND_PERCENTAGE) {
rounding_x = 10;
- } else if (priv->type_x == GPM_GRAPH_WIDGET_TYPE_FACTOR) {
+ } else if (priv->type_x == EGG_GRAPH_WIDGET_KIND_FACTOR) {
rounding_x = 1;
- } else if (priv->type_x == GPM_GRAPH_WIDGET_TYPE_POWER) {
+ } else if (priv->type_x == EGG_GRAPH_WIDGET_KIND_POWER) {
rounding_x = 10;
- } else if (priv->type_x == GPM_GRAPH_WIDGET_TYPE_VOLTAGE) {
+ } else if (priv->type_x == EGG_GRAPH_WIDGET_KIND_VOLTAGE) {
rounding_x = 1000;
- } else if (priv->type_x == GPM_GRAPH_WIDGET_TYPE_TIME) {
+ } else if (priv->type_x == EGG_GRAPH_WIDGET_KIND_TIME) {
if (biggest_x-smallest_x < 150)
rounding_x = 150;
else if (biggest_x-smallest_x < 5*60)
@@ -759,29 +699,29 @@ gpm_graph_widget_autorange_x (GpmGraphWidget *graph)
rounding_x = 10 * 60;
}
- priv->start_x = gpm_round_down (smallest_x, rounding_x);
- priv->stop_x = gpm_round_up (biggest_x, rounding_x);
+ priv->start_x = egg_graph_round_down (smallest_x, rounding_x);
+ priv->stop_x = egg_graph_round_up (biggest_x, rounding_x);
- g_debug ("Processed(1) range is %i<x<%i",
+ g_debug ("Processed(1) range is %.1f<x<%.1f",
priv->start_x, priv->stop_x);
/* if percentage, and close to the end points, then extend */
- if (priv->type_x == GPM_GRAPH_WIDGET_TYPE_PERCENTAGE) {
+ if (priv->type_x == EGG_GRAPH_WIDGET_KIND_PERCENTAGE) {
if (priv->stop_x >= 90)
priv->stop_x = 100;
if (priv->start_x > 0 && priv->start_x <= 10)
priv->start_x = 0;
- } else if (priv->type_x == GPM_GRAPH_WIDGET_TYPE_TIME) {
+ } else if (priv->type_x == EGG_GRAPH_WIDGET_KIND_TIME) {
if (priv->start_x > 0 && priv->start_x <= 60*10)
priv->start_x = 0;
}
- g_debug ("Processed range is %i<x<%i",
+ g_debug ("Processed range is %.1f<x<%.1f",
priv->start_x, priv->stop_x);
}
/**
- * gpm_graph_widget_autorange_y:
+ * egg_graph_widget_autorange_y:
* @graph: This class instance
*
* Autoranges the graph axis depending on the axis type, and the maximum
@@ -789,14 +729,14 @@ gpm_graph_widget_autorange_x (GpmGraphWidget *graph)
* resolution but also a number that scales "well" to a 10x10 grid.
**/
static void
-gpm_graph_widget_autorange_y (GpmGraphWidget *graph)
+egg_graph_widget_autorange_y (EggGraphWidget *graph)
{
- GpmGraphWidgetPrivate *priv = GET_PRIVATE (graph);
- gfloat biggest_y = G_MINFLOAT;
- gfloat smallest_y = G_MAXFLOAT;
+ EggGraphWidgetPrivate *priv = GET_PRIVATE (graph);
+ gdouble biggest_y = G_MINFLOAT;
+ gdouble smallest_y = G_MAXFLOAT;
guint rounding_y = 1;
GPtrArray *data;
- GpmPointObj *point;
+ EggGraphPoint *point;
guint i, j;
guint len = 0;
GPtrArray *array;
@@ -804,7 +744,7 @@ gpm_graph_widget_autorange_y (GpmGraphWidget *graph)
array = priv->data_list;
/* find out if we have no data */
- for (j=0; j<array->len; j++) {
+ for (j = 0; j < array->len; j++) {
data = g_ptr_array_index (array, j);
len = data->len;
if (len > 0)
@@ -820,10 +760,10 @@ gpm_graph_widget_autorange_y (GpmGraphWidget *graph)
}
/* get the range for the graph */
- for (j=0; j<array->len; j++) {
+ for (j = 0; j < array->len; j++) {
data = g_ptr_array_index (array, j);
for (i=0; i < data->len; i++) {
- point = (GpmPointObj *) g_ptr_array_index (data, i);
+ point = (EggGraphPoint *) g_ptr_array_index (data, i);
if (point->y > biggest_y)
biggest_y = point->y;
if (point->y < smallest_y)
@@ -837,15 +777,15 @@ gpm_graph_widget_autorange_y (GpmGraphWidget *graph)
smallest_y--;
}
- if (priv->type_y == GPM_GRAPH_WIDGET_TYPE_PERCENTAGE) {
+ if (priv->type_y == EGG_GRAPH_WIDGET_KIND_PERCENTAGE) {
rounding_y = 10;
- } else if (priv->type_y == GPM_GRAPH_WIDGET_TYPE_FACTOR) {
+ } else if (priv->type_y == EGG_GRAPH_WIDGET_KIND_FACTOR) {
rounding_y = 1;
- } else if (priv->type_y == GPM_GRAPH_WIDGET_TYPE_POWER) {
+ } else if (priv->type_y == EGG_GRAPH_WIDGET_KIND_POWER) {
rounding_y = 10;
- } else if (priv->type_y == GPM_GRAPH_WIDGET_TYPE_VOLTAGE) {
+ } else if (priv->type_y == EGG_GRAPH_WIDGET_KIND_VOLTAGE) {
rounding_y = 1000;
- } else if (priv->type_y == GPM_GRAPH_WIDGET_TYPE_TIME) {
+ } else if (priv->type_y == EGG_GRAPH_WIDGET_KIND_TIME) {
if (biggest_y-smallest_y < 150)
rounding_y = 150;
else if (biggest_y < 5*60)
@@ -854,49 +794,46 @@ gpm_graph_widget_autorange_y (GpmGraphWidget *graph)
rounding_y = 10 * 60;
}
- priv->start_y = gpm_round_down (smallest_y, rounding_y);
- priv->stop_y = gpm_round_up (biggest_y, rounding_y);
+ priv->start_y = egg_graph_round_down (smallest_y, rounding_y);
+ priv->stop_y = egg_graph_round_up (biggest_y, rounding_y);
- /* a factor graph always is centered around zero */
- if (priv->type_y == GPM_GRAPH_WIDGET_TYPE_FACTOR) {
+ /* a factor graph is centered around zero if there are negative and
+ * positive parts */
+ if (priv->start_y < 0.f && priv->stop_y > 0.f &&
+ priv->type_y == EGG_GRAPH_WIDGET_KIND_FACTOR) {
if (abs (priv->stop_y) > abs (priv->start_y))
priv->start_y = -priv->stop_y;
else
priv->stop_y = -priv->start_y;
}
- g_debug ("Processed(1) range is %i<y<%i",
+ g_debug ("Processed(1) range is %.1f<y<%.1f",
priv->start_y, priv->stop_y);
- if (priv->type_y == GPM_GRAPH_WIDGET_TYPE_PERCENTAGE) {
+ if (priv->type_y == EGG_GRAPH_WIDGET_KIND_PERCENTAGE) {
if (priv->stop_y >= 90)
priv->stop_y = 100;
if (priv->start_y > 0 && priv->start_y <= 10)
priv->start_y = 0;
- } else if (priv->type_y == GPM_GRAPH_WIDGET_TYPE_TIME) {
+ } else if (priv->type_y == EGG_GRAPH_WIDGET_KIND_TIME) {
if (priv->start_y <= 60*10)
priv->start_y = 0;
}
- g_debug ("Processed range is %i<y<%i",
+ g_debug ("Processed range is %.1f<y<%.1f",
priv->start_y, priv->stop_y);
}
-/**
- * gpm_graph_widget_set_color:
- * @cr: Cairo drawing context
- * @color: The color enum
- **/
static void
-gpm_graph_widget_set_color (cairo_t *cr, guint32 color)
+egg_graph_widget_set_color (cairo_t *cr, guint32 color)
{
guint8 r, g, b;
- gpm_color_to_rgb (color, &r, &g, &b);
+ egg_color_to_rgb (color, &r, &g, &b);
cairo_set_source_rgb (cr, ((gdouble) r)/256.0f, ((gdouble) g)/256.0f, ((gdouble) b)/256.0f);
}
/**
- * gpm_graph_widget_draw_legend_line:
+ * egg_graph_widget_draw_legend_line:
* @cr: Cairo drawing context
* @x: The X-coordinate for the center
* @y: The Y-coordinate for the center
@@ -905,13 +842,13 @@ gpm_graph_widget_set_color (cairo_t *cr, guint32 color)
* Draw the legend line on the graph of a specified color
**/
static void
-gpm_graph_widget_draw_legend_line (cairo_t *cr, gfloat x, gfloat y, guint32 color)
+egg_graph_widget_draw_legend_line (cairo_t *cr, gdouble x, gdouble y, guint32 color)
{
- gfloat width = 10;
- gfloat height = 2;
+ gdouble width = 10;
+ gdouble height = 6;
/* background */
cairo_rectangle (cr, (int) (x - (width/2)) + 0.5, (int) (y - (height/2)) + 0.5, width, height);
- gpm_graph_widget_set_color (cr, color);
+ egg_graph_widget_set_color (cr, color);
cairo_fill (cr);
/* solid outline box */
cairo_rectangle (cr, (int) (x - (width/2)) + 0.5, (int) (y - (height/2)) + 0.5, width, height);
@@ -921,7 +858,7 @@ gpm_graph_widget_draw_legend_line (cairo_t *cr, gfloat x, gfloat y, guint32 colo
}
/**
- * gpm_graph_widget_get_pos_on_graph:
+ * egg_graph_widget_get_pos_on_graph:
* @graph: This class instance
* @data_x: The data X-coordinate
* @data_y: The data Y-coordinate
@@ -929,49 +866,39 @@ gpm_graph_widget_draw_legend_line (cairo_t *cr, gfloat x, gfloat y, guint32 colo
* @y: The returned Y position on the cairo surface
**/
static void
-gpm_graph_widget_get_pos_on_graph (GpmGraphWidget *graph, gfloat data_x, gfloat data_y, float *x, float *y)
+egg_graph_widget_get_pos_on_graph (EggGraphWidget *graph,
+ gdouble data_x, gdouble data_y,
+ gdouble *x, gdouble *y)
{
- GpmGraphWidgetPrivate *priv = GET_PRIVATE (graph);
+ EggGraphWidgetPrivate *priv = GET_PRIVATE (graph);
*x = priv->box_x + (priv->unit_x * (data_x - priv->start_x)) + 1;
- *y = priv->box_y + (priv->unit_y * (gfloat)(priv->stop_y - data_y)) + 1.5;
+ *y = priv->box_y + (priv->unit_y * (gdouble)(priv->stop_y - data_y)) + 1.5;
}
-/**
- * gpm_graph_widget_draw_dot:
- **/
static void
-gpm_graph_widget_draw_dot (cairo_t *cr, gfloat x, gfloat y, guint32 color)
+egg_graph_widget_draw_dot (cairo_t *cr, gdouble x, gdouble y, guint32 color)
{
- gfloat width;
+ gdouble width;
/* box */
- width = 2.0;
+ width = 4.0;
cairo_rectangle (cr, (gint)x + 0.5f - (width/2), (gint)y + 0.5f - (width/2), width, width);
- gpm_graph_widget_set_color (cr, color);
+ egg_graph_widget_set_color (cr, color);
cairo_fill (cr);
cairo_rectangle (cr, (gint)x + 0.5f - (width/2), (gint)y + 0.5f - (width/2), width, width);
cairo_set_source_rgb (cr, 0, 0, 0);
- cairo_set_line_width (cr, 1);
+ cairo_set_line_width (cr, 0.5);
cairo_stroke (cr);
}
-/**
- * gpm_graph_widget_draw_line:
- * @graph: This class instance
- * @cr: Cairo drawing context
- *
- * Draw the data line onto the graph with a big green line. We should already
- * limit the data to < ~100 values, so this shouldn't take too long.
- **/
static void
-gpm_graph_widget_draw_line (GpmGraphWidget *graph, cairo_t *cr)
+egg_graph_widget_draw_line (EggGraphWidget *graph, cairo_t *cr)
{
- GpmGraphWidgetPrivate *priv = GET_PRIVATE (graph);
- gfloat oldx, oldy;
- gfloat newx, newy;
+ EggGraphWidgetPrivate *priv = GET_PRIVATE (graph);
GPtrArray *data;
GPtrArray *array;
- GpmGraphWidgetPlot plot;
- GpmPointObj *point;
+ EggGraphWidgetPlot plot;
+ EggGraphPoint *point;
+ gdouble x, y;
guint i, j;
if (priv->data_list->len == 0) {
@@ -983,48 +910,69 @@ gpm_graph_widget_draw_line (GpmGraphWidget *graph, cairo_t *cr)
array = priv->data_list;
/* do each line */
- for (j=0; j<array->len; j++) {
+ for (j = 0; j < array->len; j++) {
data = g_ptr_array_index (array, j);
if (data->len == 0)
continue;
plot = GPOINTER_TO_UINT (g_ptr_array_index (priv->plot_list, j));
/* get the very first point so we can work out the old */
- point = (GpmPointObj *) g_ptr_array_index (data, 0);
- oldx = 0;
- oldy = 0;
- gpm_graph_widget_get_pos_on_graph (graph, point->x, point->y, &oldx, &oldy);
- if (plot == GPM_GRAPH_WIDGET_PLOT_POINTS || plot == GPM_GRAPH_WIDGET_PLOT_BOTH)
- gpm_graph_widget_draw_dot (cr, oldx, oldy, point->color);
-
- for (i=1; i < data->len; i++) {
- point = (GpmPointObj *) g_ptr_array_index (data, i);
-
- gpm_graph_widget_get_pos_on_graph (graph, point->x, point->y, &newx, &newy);
-
- /* ignore white lines */
- if (point->color == 0xffffff) {
- oldx = newx;
- oldy = newy;
- continue;
+ point = (EggGraphPoint *) g_ptr_array_index (data, 0);
+ x = 0;
+ y = 0;
+ egg_graph_widget_get_pos_on_graph (graph, point->x, point->y, &x, &y);
+
+ /* plot points */
+ if (plot == EGG_GRAPH_WIDGET_PLOT_POINTS || plot == EGG_GRAPH_WIDGET_PLOT_BOTH) {
+ egg_graph_widget_draw_dot (cr, x, y, point->color);
+ for (i = 1; i < data->len; i++) {
+ point = (EggGraphPoint *) g_ptr_array_index (data, i);
+ egg_graph_widget_get_pos_on_graph (graph, point->x, point->y, &x, &y);
+ egg_graph_widget_draw_dot (cr, x, y, point->color);
}
+ }
- /* draw line */
- if (plot == GPM_GRAPH_WIDGET_PLOT_LINE || plot == GPM_GRAPH_WIDGET_PLOT_BOTH) {
- cairo_move_to (cr, oldx, oldy);
- cairo_line_to (cr, newx, newy);
- cairo_set_line_width (cr, 1.5);
- gpm_graph_widget_set_color (cr, point->color);
- cairo_stroke (cr);
+ /* plot lines */
+ if (plot == EGG_GRAPH_WIDGET_PLOT_LINE || plot == EGG_GRAPH_WIDGET_PLOT_BOTH) {
+
+ guint32 old_color = 0xffffff;
+ cairo_set_line_width (cr, 1.5);
+
+ for (i = 1; i < data->len; i++) {
+ point = (EggGraphPoint *) g_ptr_array_index (data, i);
+
+ /* ignore anything out of range */
+ if (point->x < priv->start_x ||
+ point->x > priv->stop_x) {
+ continue;
+ }
+
+ /* ignore white lines */
+ if (point->color == 0xffffff)
+ continue;
+
+ /* is graph color the same */
+ egg_graph_widget_get_pos_on_graph (graph,
+ point->x,
+ point->y,
+ &x, &y);
+ if (point->color == old_color) {
+ cairo_line_to (cr, x, y);
+ continue;
+ }
+
+ /* finish previous line */
+ if (i != 1)
+ cairo_stroke (cr);
+
+ /* start new color line */
+ old_color = point->color;
+ cairo_move_to (cr, x, y);
+ egg_graph_widget_set_color (cr, point->color);
}
- /* draw data dot */
- if (plot == GPM_GRAPH_WIDGET_PLOT_POINTS || plot == GPM_GRAPH_WIDGET_PLOT_BOTH)
- gpm_graph_widget_draw_dot (cr, newx, newy, point->color);
-
- /* save old */
- oldx = newx;
- oldy = newy;
+ /* finish current line */
+ cairo_stroke (cr);
}
}
@@ -1032,7 +980,7 @@ gpm_graph_widget_draw_line (GpmGraphWidget *graph, cairo_t *cr)
}
/**
- * gpm_graph_widget_draw_bounding_box:
+ * egg_graph_widget_draw_bounding_box:
* @cr: Cairo drawing context
* @x: The X-coordinate for the top-left
* @y: The Y-coordinate for the top-left
@@ -1040,7 +988,7 @@ gpm_graph_widget_draw_line (GpmGraphWidget *graph, cairo_t *cr)
* @height: The item height
**/
static void
-gpm_graph_widget_draw_bounding_box (cairo_t *cr, gint x, gint y, gint width, gint height)
+egg_graph_widget_draw_bounding_box (cairo_t *cr, gint x, gint y, gint width, gint height)
{
/* background */
cairo_rectangle (cr, x, y, width, height);
@@ -1054,7 +1002,7 @@ gpm_graph_widget_draw_bounding_box (cairo_t *cr, gint x, gint y, gint width, gin
}
/**
- * gpm_graph_widget_draw_legend:
+ * egg_graph_widget_draw_legend:
* @cr: Cairo drawing context
* @x: The X-coordinate for the top-left
* @y: The Y-coordinate for the top-left
@@ -1062,64 +1010,54 @@ gpm_graph_widget_draw_bounding_box (cairo_t *cr, gint x, gint y, gint width, gin
* @height: The item height
**/
static void
-gpm_graph_widget_draw_legend (GpmGraphWidget *graph, gint x, gint y, gint width, gint height)
+egg_graph_widget_draw_legend (EggGraphWidget *graph, cairo_t *cr,
+ gint x, gint y, gint width, gint height)
{
- GpmGraphWidgetPrivate *priv = GET_PRIVATE (graph);
- cairo_t *cr = priv->cr;
+ EggGraphWidgetPrivate *priv = GET_PRIVATE (graph);
gint y_count;
guint i;
- GpmGraphWidgetKeyData *keydataitem;
+ EggGraphWidgetLegendData *legend_data;
- gpm_graph_widget_draw_bounding_box (cr, x, y, width, height);
+ egg_graph_widget_draw_bounding_box (cr, x, y, width, height);
y_count = y + 10;
/* add the line colors to the legend */
- for (i = 0; i < g_slist_length (priv->key_data); i++) {
- keydataitem = (GpmGraphWidgetKeyData *) g_slist_nth_data (priv->key_data, i);
- if (keydataitem == NULL) {
- /* this shouldn't ever happen */
- g_warning ("keydataitem NULL!");
- break;
- }
- gpm_graph_widget_draw_legend_line (cr, x + 8, y_count, keydataitem->color);
+ for (i = 0; i < priv->legend_list->len; i++) {
+ legend_data = g_ptr_array_index (priv->legend_list, i);
+ egg_graph_widget_draw_legend_line (cr, x + 8, y_count, legend_data->color);
cairo_move_to (cr, x + 8 + 10, y_count - 6);
cairo_set_source_rgb (cr, 0, 0, 0);
- pango_layout_set_text (priv->layout, keydataitem->desc, -1);
+ pango_layout_set_text (priv->layout, legend_data->desc, -1);
pango_cairo_show_layout (cr, priv->layout);
- y_count = y_count + GPM_GRAPH_WIDGET_LEGEND_SPACING;
+ y_count = y_count + EGG_GRAPH_WIDGET_LEGEND_SPACING;
}
}
/**
- * gpm_graph_widget_legend_calculate_width:
- * @graph: This class instance
- * @cr: Cairo drawing context
- * Return value: The width of the legend, including borders.
- *
* We have to find the maximum size of the text so we know the width of the
* legend box. We can't hardcode this as the dpi or font size might differ
* from machine to machine.
**/
static gboolean
-gpm_graph_widget_legend_calculate_size (GpmGraphWidget *graph, cairo_t *cr,
+egg_graph_widget_legend_calculate_size (EggGraphWidget *graph, cairo_t *cr,
guint *width, guint *height)
{
- GpmGraphWidgetPrivate *priv = GET_PRIVATE (graph);
+ EggGraphWidgetPrivate *priv = GET_PRIVATE (graph);
guint i;
PangoRectangle ink_rect, logical_rect;
- GpmGraphWidgetKeyData *keydataitem;
+ EggGraphWidgetLegendData *legend_data;
- g_return_val_if_fail (GPM_IS_GRAPH_WIDGET (graph), FALSE);
+ g_return_val_if_fail (EGG_IS_GRAPH_WIDGET (graph), FALSE);
/* set defaults */
*width = 0;
*height = 0;
/* add the line colors to the legend */
- for (i = 0; i < g_slist_length (priv->key_data); i++) {
- keydataitem = (GpmGraphWidgetKeyData *) g_slist_nth_data (priv->key_data, i);
- *height = *height + GPM_GRAPH_WIDGET_LEGEND_SPACING;
- pango_layout_set_text (priv->layout, keydataitem->desc, -1);
+ for (i = 0; i < priv->legend_list->len; i++) {
+ legend_data = g_ptr_array_index (priv->legend_list, i);
+ *height = *height + EGG_GRAPH_WIDGET_LEGEND_SPACING;
+ pango_layout_set_text (priv->layout, legend_data->desc, -1);
pango_layout_get_pixel_extents (priv->layout, &ink_rect, &logical_rect);
if ((gint) *width < ink_rect.width)
*width = ink_rect.width;
@@ -1136,39 +1074,32 @@ gpm_graph_widget_legend_calculate_size (GpmGraphWidget *graph, cairo_t *cr,
return TRUE;
}
-/**
- * gpm_graph_widget_draw:
- * @graph: This class instance
- * @event: The expose event
- *
- * Just repaint the entire graph widget on expose.
- **/
static gboolean
-gpm_graph_widget_draw (GtkWidget *widget, cairo_t *cr)
+egg_graph_widget_draw (GtkWidget *widget, cairo_t *cr)
{
GtkAllocation allocation;
gint legend_x = 0;
gint legend_y = 0;
guint legend_height = 0;
guint legend_width = 0;
- gfloat data_x;
- gfloat data_y;
+ gdouble data_x;
+ gdouble data_y;
- GpmGraphWidget *graph = (GpmGraphWidget*) widget;
- GpmGraphWidgetPrivate *priv = GET_PRIVATE (graph);
+ EggGraphWidget *graph = (EggGraphWidget*) widget;
+ EggGraphWidgetPrivate *priv = GET_PRIVATE (graph);
g_return_val_if_fail (graph != NULL, FALSE);
- g_return_val_if_fail (GPM_IS_GRAPH_WIDGET (graph), FALSE);
+ g_return_val_if_fail (EGG_IS_GRAPH_WIDGET (graph), FALSE);
- gpm_graph_widget_legend_calculate_size (graph, cr, &legend_width, &legend_height);
+ egg_graph_widget_legend_calculate_size (graph, cr, &legend_width, &legend_height);
cairo_save (cr);
/* we need this so we know the y text */
if (priv->autorange_x)
- gpm_graph_widget_autorange_x (graph);
+ egg_graph_widget_autorange_x (graph);
if (priv->autorange_y)
- gpm_graph_widget_autorange_y (graph);
+ egg_graph_widget_autorange_y (graph);
- priv->box_x = gpm_graph_widget_get_y_label_max_width (graph, cr) + 10;
+ priv->box_x = egg_graph_widget_get_y_label_max_width (graph, cr) + 10;
priv->box_y = 5;
gtk_widget_get_allocation (widget, &allocation);
@@ -1186,34 +1117,71 @@ gpm_graph_widget_draw (GtkWidget *widget, cairo_t *cr)
}
/* graph background */
- gpm_graph_widget_draw_bounding_box (cr, priv->box_x, priv->box_y,
+ egg_graph_widget_draw_bounding_box (cr, priv->box_x, priv->box_y,
priv->box_width, priv->box_height);
if (priv->use_grid)
- gpm_graph_widget_draw_grid (graph, cr);
+ egg_graph_widget_draw_grid (graph, cr);
+
+ /* solid outline box */
+ cairo_rectangle (cr, priv->box_x + 0.5f, priv->box_y + 0.5f,
+ priv->box_width - 1, priv->box_height - 1);
+ cairo_set_source_rgb (cr, 0.6f, 0.6f, 0.6f);
+ cairo_set_line_width (cr, 1);
+ cairo_stroke (cr);
/* -3 is so we can keep the lines inside the box at both extremes */
data_x = priv->stop_x - priv->start_x;
data_y = priv->stop_y - priv->start_y;
- priv->unit_x = (float)(priv->box_width - 3) / (float) data_x;
- priv->unit_y = (float)(priv->box_height - 3) / (float) data_y;
+ priv->unit_x = (gdouble)(priv->box_width - 3) / (gdouble) data_x;
+ priv->unit_y = (gdouble)(priv->box_height - 3) / (gdouble) data_y;
- gpm_graph_widget_draw_labels (graph, cr);
- gpm_graph_widget_draw_line (graph, cr);
+ egg_graph_widget_draw_labels (graph, cr);
+ egg_graph_widget_draw_line (graph, cr);
if (priv->use_legend && legend_height > 0)
- gpm_graph_widget_draw_legend (graph, legend_x, legend_y, legend_width, legend_height);
+ egg_graph_widget_draw_legend (graph, cr, legend_x, legend_y, legend_width, legend_height);
cairo_restore (cr);
return FALSE;
}
-/**
- * gpm_graph_widget_new:
- * Return value: A new GpmGraphWidget object.
- **/
+static cairo_status_t
+egg_graph_widget_export_to_svg_cb (void *user_data,
+ const unsigned char *data,
+ unsigned int length)
+{
+ GString *str = (GString *) user_data;
+ g_autofree gchar *tmp = NULL;
+ tmp = g_strndup ((const gchar *) data, length);
+ g_string_append (str, tmp);
+ return CAIRO_STATUS_SUCCESS;
+}
+
+gchar *
+egg_graph_widget_export_to_svg (EggGraphWidget *graph,
+ guint width,
+ guint height)
+{
+ GString *str;
+ cairo_surface_t *surface;
+ cairo_t *ctx;
+
+ g_return_val_if_fail (EGG_IS_GRAPH_WIDGET (graph), NULL);
+
+ /* write the SVG data to a string */
+ str = g_string_new ("");
+ surface = cairo_svg_surface_create_for_stream (egg_graph_widget_export_to_svg_cb,
+ str, width, height);
+ ctx = cairo_create (surface);
+ egg_graph_widget_draw (GTK_WIDGET (graph), ctx);
+ cairo_surface_destroy (surface);
+ cairo_destroy (ctx);
+ return g_string_free (str, FALSE);
+}
+
GtkWidget *
-gpm_graph_widget_new (void)
+egg_graph_widget_new (void)
{
- return g_object_new (GPM_TYPE_GRAPH_WIDGET, NULL);
+ return g_object_new (EGG_TYPE_GRAPH_WIDGET, NULL);
}
diff --git a/src/egg-graph-widget.h b/src/egg-graph-widget.h
new file mode 100644
index 0000000..6d1b007
--- /dev/null
+++ b/src/egg-graph-widget.h
@@ -0,0 +1,78 @@
+/* -*- Mode: C; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 8 -*-
+ *
+ * Copyright (C) 2006-2016 Richard Hughes <richard hughsie com>
+ *
+ * Licensed under the GNU General Public License Version 2
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * 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., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
+ */
+
+#ifndef __EGG_GRAPH_WIDGET_H__
+#define __EGG_GRAPH_WIDGET_H__
+
+#include <gtk/gtk.h>
+
+#include "egg-graph-point.h"
+
+G_BEGIN_DECLS
+
+#define EGG_TYPE_GRAPH_WIDGET (egg_graph_widget_get_type ())
+G_DECLARE_DERIVABLE_TYPE (EggGraphWidget, egg_graph_widget, EGG, GRAPH_WIDGET, GtkDrawingArea)
+
+#define EGG_GRAPH_WIDGET_LEGEND_SPACING 17
+
+typedef enum {
+ EGG_GRAPH_WIDGET_KIND_INVALID,
+ EGG_GRAPH_WIDGET_KIND_PERCENTAGE,
+ EGG_GRAPH_WIDGET_KIND_FACTOR,
+ EGG_GRAPH_WIDGET_KIND_TIME,
+ EGG_GRAPH_WIDGET_KIND_POWER,
+ EGG_GRAPH_WIDGET_KIND_VOLTAGE,
+ EGG_GRAPH_WIDGET_KIND_WAVELENGTH,
+ EGG_GRAPH_WIDGET_KIND_UNKNOWN
+} EggGraphWidgetKind;
+
+typedef enum {
+ EGG_GRAPH_WIDGET_PLOT_LINE,
+ EGG_GRAPH_WIDGET_PLOT_POINTS,
+ EGG_GRAPH_WIDGET_PLOT_BOTH
+} EggGraphWidgetPlot;
+
+struct _EggGraphWidgetClass
+{
+ GtkDrawingAreaClass parent_class;
+};
+
+GtkWidget *egg_graph_widget_new (void);
+
+void egg_graph_widget_set_use_legend (EggGraphWidget *graph,
+ gboolean use_legend);
+gboolean egg_graph_widget_get_use_legend (EggGraphWidget *graph);
+
+gchar *egg_graph_widget_export_to_svg (EggGraphWidget *graph,
+ guint width,
+ guint height);
+void egg_graph_widget_data_clear (EggGraphWidget *graph);
+void egg_graph_widget_data_add (EggGraphWidget *graph,
+ EggGraphWidgetPlot plot,
+ GPtrArray *array);
+void egg_graph_widget_key_legend_clear (EggGraphWidget *graph);
+void egg_graph_widget_key_legend_add (EggGraphWidget *graph,
+ guint32 color,
+ const gchar *desc);
+
+G_END_DECLS
+
+#endif
diff --git a/src/gpm-statistics.c b/src/gpm-statistics.c
index efee83e..9ab08c2 100644
--- a/src/gpm-statistics.c
+++ b/src/gpm-statistics.c
@@ -28,7 +28,7 @@
#include <libupower-glib/upower.h>
#include "gpm-array-float.h"
-#include "gpm-graph-widget.h"
+#include "egg-graph-widget.h"
#define GPM_SETTINGS_SCHEMA "org.gnome.power-manager"
#define GPM_SETTINGS_INFO_HISTORY_TIME "info-history-time"
@@ -495,8 +495,8 @@ static GPtrArray *
gpm_stats_update_smooth_data (GPtrArray *list)
{
guint i;
- GpmPointObj *point;
- GpmPointObj *point_new;
+ EggGraphPoint *point;
+ EggGraphPoint *point_new;
GPtrArray *new;
GpmArrayFloat *raw;
GpmArrayFloat *convolved;
@@ -506,7 +506,7 @@ gpm_stats_update_smooth_data (GPtrArray *list)
/* convert the y data to a GpmArrayFloat array */
raw = gpm_array_float_new (list->len);
for (i = 0; i < list->len; i++) {
- point = (GpmPointObj *) g_ptr_array_index (list, i);
+ point = (EggGraphPoint *) g_ptr_array_index (list, i);
gpm_array_float_set (raw, i, point->y);
}
@@ -518,10 +518,10 @@ gpm_stats_update_smooth_data (GPtrArray *list)
convolved = gpm_array_float_convolve (outliers, gaussian);
/* add the smoothed data back into a new array */
- new = g_ptr_array_new_with_free_func ((GDestroyNotify) gpm_point_obj_free);
+ new = g_ptr_array_new_with_free_func ((GDestroyNotify) egg_graph_point_free);
for (i = 0; i < list->len; i++) {
- point = (GpmPointObj *) g_ptr_array_index (list, i);
- point_new = g_new0 (GpmPointObj, 1);
+ point = (EggGraphPoint *) g_ptr_array_index (list, i);
+ point_new = g_new0 (EggGraphPoint, 1);
point_new->color = point->color;
point_new->x = point->x;
point_new->y = gpm_array_float_get (convolved, i);
@@ -776,19 +776,19 @@ gpm_stats_set_graph_data (GtkWidget *widget, GPtrArray *data, gboolean use_smoot
{
GPtrArray *smoothed;
- gpm_graph_widget_data_clear (GPM_GRAPH_WIDGET (widget));
+ egg_graph_widget_data_clear (EGG_GRAPH_WIDGET (widget));
/* add correct data */
if (!use_smoothed) {
if (use_points)
- gpm_graph_widget_data_assign (GPM_GRAPH_WIDGET (widget), GPM_GRAPH_WIDGET_PLOT_BOTH,
data);
+ egg_graph_widget_data_add (EGG_GRAPH_WIDGET (widget), EGG_GRAPH_WIDGET_PLOT_BOTH,
data);
else
- gpm_graph_widget_data_assign (GPM_GRAPH_WIDGET (widget), GPM_GRAPH_WIDGET_PLOT_LINE,
data);
+ egg_graph_widget_data_add (EGG_GRAPH_WIDGET (widget), EGG_GRAPH_WIDGET_PLOT_LINE,
data);
} else {
smoothed = gpm_stats_update_smooth_data (data);
if (use_points)
- gpm_graph_widget_data_assign (GPM_GRAPH_WIDGET (widget),
GPM_GRAPH_WIDGET_PLOT_POINTS, data);
- gpm_graph_widget_data_assign (GPM_GRAPH_WIDGET (widget), GPM_GRAPH_WIDGET_PLOT_LINE,
smoothed);
+ egg_graph_widget_data_add (EGG_GRAPH_WIDGET (widget), EGG_GRAPH_WIDGET_PLOT_POINTS,
data);
+ egg_graph_widget_data_add (EGG_GRAPH_WIDGET (widget), EGG_GRAPH_WIDGET_PLOT_LINE, smoothed);
g_ptr_array_unref (smoothed);
}
@@ -824,39 +824,39 @@ gpm_stats_update_info_page_history (UpDevice *device)
GtkWidget *widget;
gboolean checked;
gboolean points;
- GpmPointObj *point;
+ EggGraphPoint *point;
GPtrArray *new;
gint32 offset = 0;
GTimeVal timeval;
- new = g_ptr_array_new_with_free_func ((GDestroyNotify) gpm_point_obj_free);
+ new = g_ptr_array_new_with_free_func ((GDestroyNotify) egg_graph_point_free);
if (g_strcmp0 (history_type, GPM_HISTORY_CHARGE_VALUE) == 0) {
g_object_set (graph_history,
- "type-x", GPM_GRAPH_WIDGET_TYPE_TIME,
- "type-y", GPM_GRAPH_WIDGET_TYPE_PERCENTAGE,
+ "type-x", EGG_GRAPH_WIDGET_KIND_TIME,
+ "type-y", EGG_GRAPH_WIDGET_KIND_PERCENTAGE,
"autorange-x", FALSE,
- "start-x", -history_time,
- "stop-x", 0,
+ "start-x", -(gdouble) history_time,
+ "stop-x", (gdouble) 0.f,
"autorange-y", FALSE,
- "start-y", 0,
- "stop-y", 100,
+ "start-y", (gdouble) 0.f,
+ "stop-y", (gdouble) 100.f,
NULL);
} else if (g_strcmp0 (history_type, GPM_HISTORY_RATE_VALUE) == 0) {
g_object_set (graph_history,
- "type-x", GPM_GRAPH_WIDGET_TYPE_TIME,
- "type-y", GPM_GRAPH_WIDGET_TYPE_POWER,
+ "type-x", EGG_GRAPH_WIDGET_KIND_TIME,
+ "type-y", EGG_GRAPH_WIDGET_KIND_POWER,
"autorange-x", FALSE,
- "start-x", -history_time,
- "stop-x", 0,
+ "start-x", -(gdouble) history_time,
+ "stop-x", (gdouble) 0.f,
"autorange-y", TRUE,
NULL);
} else {
g_object_set (graph_history,
- "type-x", GPM_GRAPH_WIDGET_TYPE_TIME,
- "type-y", GPM_GRAPH_WIDGET_TYPE_TIME,
+ "type-x", EGG_GRAPH_WIDGET_KIND_TIME,
+ "type-y", EGG_GRAPH_WIDGET_KIND_TIME,
"autorange-x", FALSE,
- "start-x", -history_time,
- "stop-x", 0,
+ "start-x", -(gdouble) history_time,
+ "stop-x", (gdouble) 0.f,
"autorange-y", TRUE,
NULL);
}
@@ -884,7 +884,7 @@ gpm_stats_update_info_page_history (UpDevice *device)
if (up_history_item_get_state (item) == UP_DEVICE_STATE_UNKNOWN)
continue;
- point = gpm_point_obj_new ();
+ point = egg_graph_point_new ();
point->x = (gint32) up_history_item_get_time (item) - offset;
point->y = up_history_item_get_value (item);
if (up_history_item_get_state (item) == UP_DEVICE_STATE_CHARGING)
@@ -932,12 +932,12 @@ gpm_stats_update_info_page_stats (UpDevice *device)
GtkWidget *widget;
gboolean checked;
gboolean points;
- GpmPointObj *point;
+ EggGraphPoint *point;
GPtrArray *new;
gboolean use_data = FALSE;
const gchar *type = NULL;
- new = g_ptr_array_new_with_free_func ((GDestroyNotify) gpm_point_obj_free);
+ new = g_ptr_array_new_with_free_func ((GDestroyNotify) egg_graph_point_free);
if (g_strcmp0 (stats_type, GPM_STATS_CHARGE_DATA_VALUE) == 0) {
type = "charging";
use_data = TRUE;
@@ -956,15 +956,15 @@ gpm_stats_update_info_page_stats (UpDevice *device)
if (use_data) {
g_object_set (graph_statistics,
- "type-x", GPM_GRAPH_WIDGET_TYPE_PERCENTAGE,
- "type-y", GPM_GRAPH_WIDGET_TYPE_FACTOR,
+ "type-x", EGG_GRAPH_WIDGET_KIND_PERCENTAGE,
+ "type-y", EGG_GRAPH_WIDGET_KIND_FACTOR,
"autorange-x", TRUE,
"autorange-y", TRUE,
NULL);
} else {
g_object_set (graph_statistics,
- "type-x", GPM_GRAPH_WIDGET_TYPE_PERCENTAGE,
- "type-y", GPM_GRAPH_WIDGET_TYPE_PERCENTAGE,
+ "type-x", EGG_GRAPH_WIDGET_KIND_PERCENTAGE,
+ "type-y", EGG_GRAPH_WIDGET_KIND_PERCENTAGE,
"autorange-x", TRUE,
"autorange-y", TRUE,
NULL);
@@ -985,7 +985,7 @@ gpm_stats_update_info_page_stats (UpDevice *device)
for (i = 0; i < array->len; i++) {
item = (UpStatsItem *) g_ptr_array_index (array, i);
- point = gpm_point_obj_new ();
+ point = egg_graph_point_new ();
point->x = i;
if (use_data)
point->y = up_stats_item_get_value (item);
@@ -1844,14 +1844,14 @@ gpm_stats_startup_cb (GApplication *application,
/* add history graph */
box = GTK_BOX (gtk_builder_get_object (builder, "hbox_history"));
- graph_history = gpm_graph_widget_new ();
+ graph_history = egg_graph_widget_new ();
gtk_box_pack_start (box, graph_history, TRUE, TRUE, 0);
gtk_widget_set_size_request (graph_history, 400, 250);
gtk_widget_show (graph_history);
/* add statistics graph */
box = GTK_BOX (gtk_builder_get_object (builder, "hbox_statistics"));
- graph_statistics = gpm_graph_widget_new ();
+ graph_statistics = egg_graph_widget_new ();
gtk_box_pack_start (box, graph_statistics, TRUE, TRUE, 0);
gtk_widget_set_size_request (graph_statistics, 400, 250);
gtk_widget_show (graph_statistics);
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]