Hi Alan,
On 11.03.06, Alan G Isaac wrote:
> Well I'm still a newbie dealing with many mysteries here.
> But how about allowing provision of a styles list to the bar
> class? I suggest this is a good idea to include in the bar
> class (and not an unusual functionality). Without in any
> way presuming to suggest a design---I don't pretend to know
> a good one---something that would function like below.
You're right. We need such a style. It's also quite clear how it
should work, although I do have a different use case in mind, namely a
pie diagram, or -- speaking in terms of a xygraph -- something which
fills up to a -- say -- 100%. The feature of such a style would be to
cycle thru a set of changeable (stroke/fill) styles when accessing the
dataset.
In the end we could use this style for what you want to do or for what
I do have in mind just by changing the (implicit) positioning style.
> =============================================================================
>
> class bar_styles(graph.style.bar):
> '''
> Allow a styles list, that is cycled through.
> '''
>
> default_style = [color.palette.ReverseRainbow,
> deco.stroked([color.grey.black])]
>
> def __init__(self, styles_list=[], **args):
> self.drawpoint_calls = 0
> self.num_styles = len(styles_list)
> self.styles_list = styles_list
> graph.style.bar.__init__(self, **args)
>
> def selectstyle(self, privatedata, sharedata, agraph,
> selectindex, selecttotal):
> graph.style.bar.selectstyle(self,
> privatedata, sharedata,
> agraph,
> selectindex, selecttotal)
> privatedata.styles_list = [attr.selectattrs(self.default_style
> + mystyle, selectindex, selecttotal)
> for mystyle in self.styles_list]
>
> def drawpoint(self, privatedata, sharedata, agraph, point):
> savebarattrs = privatedata.barattrs
> privatedata.barattrs = privatedata.styles_list[self.drawpoint_calls %
> self.num_styles]
> graph.style.bar.drawpoint(self, privatedata, sharedata, agraph, point)
> privatedata.barattrs = savebarattrs
> self.drawpoint_calls += 1
>
>
> g = graph.graphxy(width=8, x=graph.axis.bar())
> style1 = [pyx.color.rgb.red, deco.stroked([color.grey.black,
> style.linewidth.THICK])]
> style2 = [pyx.color.rgb.blue, deco.stroked([color.grey.black])]
> g.plot(graph.data.list([["a", 1], ["b", 5], ["c", 9]], xname=1, y=2),
> [bar_styles([style1]*2+[style2])])
> g.writeEPSfile("c:\\temp.eps")
Just some remarks to your code:
* drawpoint_calls should be initialized in initdrawpoints and should
be saved in privatedata (thus the data handling becomes local to the
graph, not local to the style -- try to use the same style instance
several times and you'll see what I mean)
* we should get rid of num_styles (the numbering should be driven by
the data, not by the styles)
* we should use changeable attributes, such that for example a palette
could be used to cycle thru colors
* you do not need to keep the barattrs (hence you can remove the
savebarattrs) ... the trick of setting the barattrs is just a
quick'n'dirty injection of some modifying attributes to reuse all
the other stuff from the bar-style code ...
André
--
by _ _ _ Dr. André Wobst
/ \ \ / ) [EMAIL PROTECTED], http://www.wobsta.de/
/ _ \ \/\/ / PyX - High quality PostScript and PDF figures
(_/ \_)_/\_/ with Python & TeX: visit http://pyx.sourceforge.net/
-------------------------------------------------------
This SF.Net email is sponsored by xPML, a groundbreaking scripting language
that extends applications into web and mobile media. Attend the live webcast
and join the prime developer group breaking into this new coding territory!
http://sel.as-us.falkag.net/sel?cmd=lnk&kid=110944&bid=241720&dat=121642
_______________________________________________
PyX-user mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/pyx-user