From 03ac91f06af287b749a93499cb86ba7dcfc2297f Mon Sep 17 00:00:00 2001 From: =?utf8?q?Andr=C3=A9=20Wobst?= Date: Wed, 26 Sep 2007 13:22:41 +0000 Subject: [PATCH] lists renaming and values class git-svn-id: https://pyx.svn.sourceforge.net/svnroot/pyx/trunk/pyx@2886 069f4177-920e-0410-937b-c2a4a81bcd90 --- CHANGES | 5 +++++ manual/graph.tex | 12 ++++++++++-- pyx/graph/data.py | 44 ++++++++++++++++++++++++++++++++++---------- 3 files changed, 49 insertions(+), 12 deletions(-) diff --git a/CHANGES b/CHANGES index 571ff45a..732fda44 100644 --- a/CHANGES +++ b/CHANGES @@ -105,6 +105,7 @@ TODO: - painter: don't insert axis title twice (thanks to Tim Gray for reporting this problem) - parter: extend the logarithmic parter to calculate automatic partitions for huge ranges (TODO: documentation of the new autoexponent parameter) (suggested by Dominic Ford) + - axis: range rating was not taken into account due in the 0.9 release - graph styles: - impulses style - optional textdx/textdy columns to the text style added @@ -113,6 +114,10 @@ TODO: - bugfix: axis range adjustment in range style - graph module: - doplot method (to be called with a plotitem) to alter the plotitem order etc. (TODO: documentation) + - data module: + - list class was renamed to points; deprecation warning added + for instance creation, but inheritance from list failes + - new values class - attr module: - add multichangeattr to perform a select on different changeable attributes depending on the selects total number diff --git a/manual/graph.tex b/manual/graph.tex index 38df86b8..5782bf21 100644 --- a/manual/graph.tex +++ b/manual/graph.tex @@ -485,8 +485,16 @@ For the sake of completeness we list the default patterns: the end of the section are available. \end{classdesc} % }}} -\begin{classdesc}{list}{data, title="user provided list", % {{{ - addlinenumbers=1, **columns} +\begin{classdesc}{values}{title="user provided values", % {{{ + **columns} + This class creates graph data from externally provided data. + Each column is a list of values to be used for that column. + + \var{title} is the title of the data to be used in the graph key. +\end{classdesc} % }}} + +\begin{classdesc}{points}{data, title="user provided points", % {{{ + addlinenumbers=1, **columns} This class creates graph data from externally provided data. \var{data} is a list of lines, where each line is a list of data values for the columns. diff --git a/pyx/graph/data.py b/pyx/graph/data.py index 8b6b7f69..9e525ba2 100644 --- a/pyx/graph/data.py +++ b/pyx/graph/data.py @@ -117,12 +117,31 @@ class _data: return {} -class list(_data): +defaultsymbols = [style.symbol()] +defaultlines = [style.line()] + + +class values(_data): + + defaultstyles = defaultsymbols + + def __init__(self, title="user provided values", **columns): + for i, values in enumerate(columns.values()): + if i and len(values) != l: + raise ValueError("different number of values") + else: + l = len(values) + self.columns = columns + self.columnnames = columns.keys() + self.title = title + + +class points(_data): "Graph data from a list of points" - defaultstyles = [style.symbol()] + defaultstyles = defaultsymbols - def __init__(self, points, title="user provided list", addlinenumbers=1, **columns): + def __init__(self, points, title="user provided points", addlinenumbers=1, **columns): if len(points): l = len(points[0]) self.columndata = [[x] for x in points[0]] @@ -143,6 +162,11 @@ class list(_data): self.title = title +def list(*args, **kwargs): + warnings.warn("graph.data.list is deprecated. Use graph.data.points instead.") + return points(*args, **kwargs) + + class _notitle: pass @@ -310,8 +334,8 @@ class file(data): for i in xrange(len(columndata)): if len(columndata[i]) != maxcolumns: columndata[i].extend([None]*(maxcolumns-len(columndata[i]))) - return list(columndata, title=title, addlinenumbers=0, - **dict([(column, i+1) for i, column in enumerate(columns[:maxcolumns-1])])) + return points(columndata, title=title, addlinenumbers=0, + **dict([(column, i+1) for i, column in enumerate(columns[:maxcolumns-1])])) try: filename.readlines @@ -366,7 +390,7 @@ class conffile(data): point[index] = value columndata[i] = point # wrap result into a data instance to remove column numbers - result = data(list(columndata, addlinenumbers=0, **columns), title=title) + result = data(points(columndata, addlinenumbers=0, **columns), title=title) # ... but reinsert sections as linenumbers result.columndata = [[x[0] for x in columndata]] return result @@ -386,7 +410,7 @@ cbdfilecache = {} class cbdfile(data): - defaultstyles = [style.line()] + defaultstyles = defaultlines def getcachekey(self, *args): return ":".join([str(x) for x in args]) @@ -472,7 +496,7 @@ class cbdfile(data): columndata.extend([(long/3600.0, lat/3600.0) for lat, long in sb.points]) - result = list(columndata, title=title) + result = points(columndata, title=title) result.defaultstyles = self.defaultstyles return result @@ -491,7 +515,7 @@ class cbdfile(data): class function(_data): - defaultstyles = [style.line()] + defaultstyles = defaultlines assignmentpattern = re.compile(r"\s*([a-z_][a-z0-9_]*)\s*\(\s*([a-z_][a-z0-9_]*)\s*\)\s*=", re.IGNORECASE) @@ -557,7 +581,7 @@ class functionxy(function): class paramfunction(_data): - defaultstyles = [style.line()] + defaultstyles = defaultlines def __init__(self, varname, min, max, expression, title=_notitle, points=100, context={}): if context.has_key(varname): -- 2.11.4.GIT