From: Joerg L. <jo...@us...> - 2004-07-22 13:14:43
|
Hi André, On 22.07.04, Andre Wobst wrote: > 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)]) Yes, but probably that's not necessary. > 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: Sorry, the list thing was not really meant serious... Too hot, here. > > 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. I'm not sure which solution is better, probably both are ok. > 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. I don't think it's a bad idea. At least it is better than returning the privedata of all styles, for the reason given below. > 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.) That's exactly the reason why I don't like this idea. I really think we shouln't expose the sharedata and privatedata lists, which really are internal implementation details, to the user. Btw, we could also introduce a new style method which is responsible for returning the return value, when called with the corresponding sharedata and privatedata objects. Jörg |