root/tags/0.4.1/src/scatter.py

Revision 109, 1.8 kB (checked in by lgs, 4 years ago)

Some refactoring and support for negative values in line and bar charts. Inspired by Nicolas patch

Line 
1# Copyright (c) 2007-2008 by Lorenzo Gil Sanchez <lorenzo.gil.sanchez@gmail.com>
2#
3# This file is part of PyCha.
4#
5# PyCha is free software: you can redistribute it and/or modify
6# it under the terms of the GNU Lesser General Public License as published by
7# the Free Software Foundation, either version 3 of the License, or
8# (at your option) any later version.
9#
10# PyCha is distributed in the hope that it will be useful,
11# but WITHOUT ANY WARRANTY; without even the implied warranty of
12# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
13# GNU Lesser General Public License for more details.
14#
15# You should have received a copy of the GNU Lesser General Public License
16# along with PyCha.  If not, see <http://www.gnu.org/licenses/>.
17
18from pycha.line import LineChart
19
20class ScatterplotChart(LineChart):
21
22    def _renderChart(self, cx):
23        """Renders a scatterplot"""
24        def drawSymbol(point, size=2):
25            ox = point.x * self.area.w + self.area.x
26            oy = point.y * self.area.h + self.area.y
27            cx.move_to(ox-size, oy  )
28            cx.line_to(ox+size, oy  )
29            cx.move_to(ox     , oy-size)
30            cx.line_to(ox     , oy+size)
31
32        def preparePath(storeName, size=2):
33            cx.new_path()
34            for point in self.points:
35                if point.name == storeName:
36                    drawSymbol(point, size)
37            cx.close_path()
38
39        cx.save()
40
41        cx.set_line_width(self.options.stroke.width)
42        # TODO: self.options.stroke.shadow
43        for key in self._getDatasetsKeys():
44            cx.set_source_rgb(*self.options.colorScheme[key])
45            preparePath(key)
46            cx.stroke()
47
48        cx.restore()
49
50    def _renderLines(self, cx):
51        # We don't need lines in the background
52        pass
Note: See TracBrowser for help on using the browser.