Web   ·   Wiki   ·   Activities   ·   Blog   ·   Lists   ·   Chat   ·   Meeting   ·   Bugs   ·   Git   ·   Translate   ·   Archive   ·   People   ·   Donate
summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorAgustin Zubiaga <aguz@sugarlabs.org>2012-09-29 16:45:23 (GMT)
committer Agustin Zubiaga <aguz@sugarlabs.org>2012-09-29 16:45:23 (GMT)
commite50e6d3c3d586596839a3174aca9b87b778331f8 (patch)
tree7c40580819add8a218c3952bdf6bf1544d673efb
parent5e3e0cdd1029b7593ddb357be9f484f16e8abed4 (diff)
charts -> chart
-rw-r--r--activity.py26
-rw-r--r--chart.py (renamed from charts.py)60
2 files changed, 47 insertions, 39 deletions
diff --git a/activity.py b/activity.py
index 762d04f..85b5a40 100644
--- a/activity.py
+++ b/activity.py
@@ -47,11 +47,11 @@ from sugar3.graphics.icon import Icon
from sugar3.graphics.alert import Alert
from sugar3.datastore import datastore
-from charts import Chart
from readers import StopWatchReader
from readers import MeasureReader
from readers import ClipboardReader
import charthelp
+import chart
# Mime types
_STOPWATCH_MIME_TYPE = 'application/x-stopwatch-activity'
@@ -189,7 +189,8 @@ class ChartActivity(activity.Activity):
toolbarbox.toolbar.insert(separator, -1)
add_vbar_chart = RadioToolButton()
- add_vbar_chart.connect('clicked', self._add_chart_cb, 'vbar')
+ add_vbar_chart.connect('clicked', self._add_chart_cb,
+ chart.VERTICAL_BAR)
add_vbar_chart.set_tooltip(_('Vertical Bar Chart'))
add_vbar_chart.props.icon_name = 'vbar'
charts_group = add_vbar_chart
@@ -197,21 +198,22 @@ class ChartActivity(activity.Activity):
toolbarbox.toolbar.insert(add_vbar_chart, -1)
add_hbar_chart = RadioToolButton()
- add_hbar_chart.connect('clicked', self._add_chart_cb, 'hbar')
+ add_hbar_chart.connect('clicked', self._add_chart_cb,
+ chart.HORIZONTAL_BAR)
add_hbar_chart.set_tooltip(_('Horizontal Bar Chart'))
add_hbar_chart.props.icon_name = 'hbar'
add_hbar_chart.props.group = charts_group
toolbarbox.toolbar.insert(add_hbar_chart, -1)
add_line_chart = RadioToolButton()
- add_line_chart.connect('clicked', self._add_chart_cb, 'line')
+ add_line_chart.connect('clicked', self._add_chart_cb, chart.LINE)
add_line_chart.set_tooltip(_('Line Chart'))
add_line_chart.props.icon_name = 'line'
add_line_chart.props.group = charts_group
toolbarbox.toolbar.insert(add_line_chart, -1)
add_pie_chart = RadioToolButton()
- add_pie_chart.connect('clicked', self._add_chart_cb, 'pie')
+ add_pie_chart.connect('clicked', self._add_chart_cb, chart.PIE)
add_pie_chart.set_tooltip(_('Pie Chart'))
add_pie_chart.props.icon_name = 'pie'
add_pie_chart.props.group = charts_group
@@ -389,8 +391,8 @@ class ChartActivity(activity.Activity):
self.chart_data.remove(value)
self._update_chart_data()
- def _add_chart_cb(self, widget, type='vbar'):
- self.current_chart = Chart(type)
+ def _add_chart_cb(self, widget, type=chart.VERTICAL_BAR):
+ self.current_chart = chart.Chart(type)
self.update_chart()
@@ -431,7 +433,7 @@ class ChartActivity(activity.Activity):
self.current_chart.set_color_scheme(color=self.chart_color)
self.current_chart.set_line_color(self.chart_line_color)
- if self.current_chart.type == 'pie':
+ if self.current_chart.type == chart.PIE:
self.current_chart.render(self)
else:
self.current_chart.render()
@@ -619,16 +621,16 @@ class ChartActivity(activity.Activity):
# Update charts buttons
_type = data['current_chart.type']
- if _type == 'vbar':
+ if _type == chart.VERTICAL_BAR:
self.chart_type_buttons[0].set_active(True)
- elif _type == 'hbar':
+ elif _type == chart.HORIZONTAL_BAR:
self.chart_type_buttons[1].set_active(True)
- elif _type == 'line':
+ elif _type == chart.LINE:
self.chart_type_buttons[2].set_active(True)
- elif _type == 'pie':
+ elif _type == chart.PIE:
self.chart_type_buttons[3].set_active(True)
# Update the controls in the config subtoolbar
diff --git a/charts.py b/chart.py
index f83d2ca..1abc313 100644
--- a/charts.py
+++ b/chart.py
@@ -1,8 +1,8 @@
#!/usr/bin/env python
# -*- coding: utf-8 -*-
-# charts.py by:
-# Agustin Zubiaga <aguzubiaga97@gmail.com>
+# chart.py by:
+# Agustin Zubiaga <aguz@sugarlabs.org>
# Gonzalo Odiard <godiard@gmail.com>
# Manuel QuiƱones <manuq@laptop.org>
@@ -27,9 +27,15 @@ import sugarpycha.pie
import cairo
from gi.repository import GObject
+# Chart types
+VERTICAL_BAR = 1
+HORIZONTAL_BAR = 2
+LINE = 3
+PIE = 4
+
class Chart(GObject.GObject):
- def __init__(self, type="vertical", width=600, height=460):
+ def __init__(self, type=VERTICAL_BAR, width=600, height=460):
GObject.GObject.__init__(self)
self.dataSet = None
@@ -41,7 +47,7 @@ class Chart(GObject.GObject):
self.height = height
def data_set(self, data):
- """Set chart data (dataSet)"""
+ '''Set chart data (dataSet)'''
self.dataSet = (
('Dots', [(i, l[1]) for i, l in enumerate(data)]),
@@ -80,48 +86,48 @@ class Chart(GObject.GObject):
}
def set_color_scheme(self, color='blue'):
- """Set the chart color scheme"""
- self.options["colorScheme"]["args"] = {'initialColor': color}
+ '''Set the chart color scheme'''
+ self.options['colorScheme']['args'] = {'initialColor': color}
def set_line_color(self, color='#000000'):
- """Set the chart line color"""
- self.options["stroke"]["color"] = color
+ '''Set the chart line color'''
+ self.options['stroke']['color'] = color
- def set_x_label(self, text="X"):
- """Set the X Label"""
- self.options["axis"]["x"]["label"] = str(text)
+ def set_x_label(self, text='X'):
+ '''Set the X Label'''
+ self.options['axis']['x']['label'] = str(text)
- def set_y_label(self, text="Y"):
- """Set the Y Label"""
- self.options["axis"]["y"]["label"] = str(text)
+ def set_y_label(self, text='Y'):
+ '''Set the Y Label'''
+ self.options['axis']['y']['label'] = str(text)
- def set_type(self, type="vertical"):
- """Set chart type (vertical, horizontal, line, pie)"""
+ def set_type(self, type=VERTICAL_BAR):
+ '''Set chart type (VERTICAL_BAR, HORIZONTAL_BAR, LINE, PIE)'''
self.type = type
- def set_title(self, title="Chart"):
- """Set the chart title"""
- self.options["title"] = title
+ def set_title(self, title='Chart'):
+ '''Set the chart title'''
+ self.options['title'] = title
def render(self, sg=None):
- """Draw the chart
- Use the self.surface variable for show the chart"""
+ '''Draw the chart
+ Use the self.surface variable for show the chart'''
self.surface = cairo.ImageSurface(cairo.FORMAT_ARGB32,
self.width,
self.height)
- if self.type == "vbar":
+ if self.type == VERTICAL_BAR:
chart = sugarpycha.bar.VerticalBarChart(self.surface, self.options)
- elif self.type == "hbar":
+ elif self.type == HORIZONTAL_BAR:
chart = sugarpycha.bar.HorizontalBarChart(self.surface,
self.options)
- elif self.type == "line":
+ elif self.type == LINE:
chart = sugarpycha.line.LineChart(self.surface, self.options)
- elif self.type == "pie":
- self.options["legend"] = {"hide": "False"}
+ elif self.type == PIE:
+ self.options['legend'] = {'hide': 'False'}
chart = sugarpycha.pie.PieChart(self.surface, self.options)
self.dataSet = [(data[0],
[[0, data[1]]]) for data in sg.chart_data]
@@ -130,5 +136,5 @@ class Chart(GObject.GObject):
chart.render()
def as_png(self, file):
- """Save the chart as png image"""
+ '''Save the chart as png image'''
self.surface.write_to_png(file)