|
From: Andre W. <wo...@us...> - 2004-07-22 13:00:07
|
Hi Jörg, On 22.07.04, Joerg Lehmann wrote: > So each > style can choose the data it wants to pass back to the user, which might > not only be the path but also colours, etc. Right. You can even make this a style option (if you like): p = g.plot(graph.data(...), [graph.style.line(returnpath=1)]) There's not limitation by design. > > But there is, of course, a problem: We can't return something from the > > donedrawpoint method at the plot command, because donedrawpoint will > > be called much later. But we could return a wrapper along the lines > > you can find enclosed. fancy_return acts like the returnvalue of data, > > but it deferes referencing to the returnvalue until something is > > accessed. We can even automate the neccessary finishing of the graph > > that way. > > This would be one solution. Btw, in principle, this could also be > done by returning a list. Hmmm ... isn't that even worse (i.e. the late evaluation becomes even more implicit)? Suppose the offen used idiom: x, y = g.plot(...) You will immediately loose the chance to inject the return values later on, don't you? I think, this is really bad. People will not understand, what we're doing. (BTW this shows, that we need to create a fancy_return instance for each style return value separately.) > Alternatively, if we want to act according to "The Zen of Python" #2, > namely "Explicit is better than implicit", we could also raise an > exception when trying to access the return value and the graph has not > yet been finished. Ok, fine to me. > > OTOH, I'm not sure whether fancy_return would be too fancy ... > > The name certainly is, but besides that I begin to like the idea. Right, the name is just a "working name". We can certainly find something suitable. The basic question is, whether this return value wrapper is a good way to go. I think, we gain a really cool syntax and user interface by that. You can just access drawing results without fiddling in the internals. But we're wrapping the return value in something, where we can inject the real return value later on. The basic question is, whether this is a good idea. May be it isn't. Suppose we do the following: we just return the privatedata of all the styles originally given: sd, = g.plot(data(...), [graph.style.line()]) We can than access sd.path once the graph is finished. While this is much less fancy, it might be just the best way to go. OTOH the question is, whether we'll never need to access variables of the data instance. At similar places in PyX we return the data instance itself as we do it right now. I don't yet have a strong fealing what's the best thing to do. (And we should also keep in mind, that sharedata and privatedatalist might be moved to the graph in the future.) André -- by _ _ _ Dr. André Wobst / \ \ / ) wo...@us..., http://www.wobsta.de/ / _ \ \/\/ / PyX - High quality PostScript figures with Python & TeX (_/ \_)_/\_/ visit http://pyx.sourceforge.net/ |