Web   ·   Wiki   ·   Activities   ·   Blog   ·   Lists   ·   Chat   ·   Meeting   ·   Bugs   ·   Git   ·   Translate   ·   Archive   ·   People   ·   Donate
summaryrefslogtreecommitdiffstats
path: root/charts.py
diff options
context:
space:
mode:
authorAgustin Zubiaga <aguzubiaga97@gmail.com>2012-01-23 16:03:35 (GMT)
committer Agustin Zubiaga <aguzubiaga97@gmail.com>2012-01-23 16:03:35 (GMT)
commit068efab7e2fcf028c262d032139340756ccda869 (patch)
treebdcb9294991351536e134354ecc9cd352d55ab98 /charts.py
parent2d3266e0ff6c20ad65cc8b0ea842097276e2a5a8 (diff)
Line charts and pie charts, chart color option
Diffstat (limited to 'charts.py')
-rw-r--r--charts.py46
1 files changed, 18 insertions, 28 deletions
diff --git a/charts.py b/charts.py
index 13439c3..cf3d0da 100644
--- a/charts.py
+++ b/charts.py
@@ -20,6 +20,7 @@
# Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
import pycha.bar
+import pycha.line
import pycha.pie
import cairo
@@ -29,7 +30,7 @@ import gobject
CHART_IMAGE = os.path.join("/tmp", "chart.png")
-class BarChart(gobject.GObject):
+class Chart(gobject.GObject):
__gsignals__ = {
'ready': (gobject.SIGNAL_RUN_FIRST, None, [str])}
@@ -75,11 +76,10 @@ class BarChart(gobject.GObject):
},
}
- def set_color_scheme(self, name="gradinet", args={'initialColor': 'blue'}):
- self.options["colorScheme"]["name"] = name
- self.options["args"] = args
+ def set_color_scheme(self, color='blue'):
+ self.options["colorScheme"]["args"] = {'initialColor': color}
- def set_chart_color(self, color='#f3f9fb'):
+ def set_bg_color(self, color='#f3f9fb'):
self.options["background"]["chartColor"] = color
def set_line_color(self, color='#d1e5ec'):
@@ -94,42 +94,32 @@ class BarChart(gobject.GObject):
def set_type(self, type="vertical"):
self.type = type
- def set_title(self, title="Bar Chart"):
+ def set_title(self, title="SimpleGraph Chart"):
self.options["title"] = title
- def render(self):
+ def render(self, sg=None):
self.surface = cairo.ImageSurface(cairo.FORMAT_ARGB32,
self.width,
self.height)
- if self.type == "vertical":
+ if self.type == "vbar":
chart = pycha.bar.VerticalBarChart(self.surface, self.options)
- elif self.type == "horizontal":
+ elif self.type == "hbar":
chart = pycha.bar.HorizontalBarChart(self.surface, self.options)
+ elif self.type == "line":
+ chart = pycha.line.LineChart(self.surface, self.options)
+
+ elif self.type == "pie":
+ self.options["legend"] = {"hide" : "False"}
+ chart = pycha.pie.PieChart(self.surface, self.options)
+ print sg.chart_data
+ self.dataSet = [(data[0], [[0, data[1]]]) for data in sg.chart_data]
+
chart.addDataset(self.dataSet)
chart.render()
self.surface.write_to_png(CHART_IMAGE)
self.emit("ready", CHART_IMAGE)
-
-class PieChart(gobject.GObject):
-
- __gsignals__ = {
- 'ready': (gobject.SIGNAL_RUN_FIRST, None, [str])}
-
- def __init__(self, type="vertical", width=550, height=310):
- gobject.GObject.__init__(self)
-
- self.dataSet = None
- self.options = None
- self.surface = None
-
- self.type = type
- self.width = width
- self.height = height
-
- def set_title(self, title="Pie Chart"):
- self.options["title"] = title