Brendon Higgins venit, vidit, dixit 21.04.2008 06:36:
> Stefan Schenk wrote (Fri, 18 Apr 2008):
>> Am Freitag 18 April 2008 05:13 schrieb Brendon Higgins:
>>> Thus my question: how can I change the ordering of the key without
>>> changing the order in which the data is plotted? Is this even possible?
>>> (Please tell me it is, somehow. I'm not afraid of digging into PyX code
>>> if I have to. ;-) )
>> I'm not sure if this is the most elegant way in PyX, but the following
>> seems to work.
>>
>> [snip]
> 
> Thanks, Stefan. It works, but unfortunately what you suggested isn't suitable 
> for where I want to put it.
> 
> There doesn't seem to be an elegant way to solve this problem. So I patched 
> key.py to take a new parameter in the constructor: a list of numbers 
> indicating the zero-indexed order (itemorder). It will then use these to 
> reorder the plotitems list in the paint method.
> 
> It *might* be a little rough around the edges, considering I'm not too 
> familiar with the code, but it's a pretty small change, and it seems to work. 
> I'd appreciate it if the developers might take a look.
> 
> Peace,
> Brendon

> +        iorder = [i for i in self.itemorder if 0 <= i and i < 
> len(plotitems)] # ignore ordering indices that are out of range
> +        plotitems = [plotitems[i] for i in iorder] + plotitems[len(iorder):] 
> # reorder the items

It seems you require the itemorder parameter to have a certain form 
(being a permutation of the first n non-negative integers) which you 
don't check:
Imagine you have 2 plotitems and itemorder = [1]. This results in 
iorder=[1]. On the right hand side of the second assignment, you will 
get the following list:
[ plotitems[1], plotitems[1] ]
This is certainly not what you want.

The above code works (gives a permutation of the list items) if, e.g., 
you require itemorder to be a permutation of the the first few 
consecutive non-neg. ints. You can check this by checking for
set(iorder) == set(range(len(iorder)))
after the consistency check that you have already. (This also 
invalidates input args like [1,1].)

An alternative might be:

plotitems = [plotitems[i] for i in iorder] + [plotitems[i] for i in 
set(range(len(plotitems)))-set(iorder)]

This would not require the above check. I'm not sure how expensive set 
operations are, though.

Cheers,
Michael


-------------------------------------------------------------------------
This SF.net email is sponsored by the 2008 JavaOne(SM) Conference 
Don't miss this year's exciting event. There's still time to save $100. 
Use priority code J8TL2D2. 
http://ad.doubleclick.net/clk;198757673;13503038;p?http://java.sun.com/javaone
_______________________________________________
PyX-user mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/pyx-user

Reply via email to