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
diff -Naur pyx-0.10.old/pyx/graph/key.py pyx-0.10/pyx/graph/key.py
--- pyx-0.10.old/pyx/graph/key.py	2006-05-24 17:42:40.000000000 +1000
+++ pyx-0.10/pyx/graph/key.py	2008-04-21 14:18:21.000000000 +1000
@@ -32,7 +32,7 @@
     def __init__(self, dist=0.2*unit.v_cm, pos="tr", hpos=None, vpos=None,
                  hinside=1, vinside=1, hdist=0.6*unit.v_cm, vdist=0.4*unit.v_cm,
                  symbolwidth=0.5*unit.v_cm, symbolheight=0.25*unit.v_cm, symbolspace=0.2*unit.v_cm,
-                 textattrs=[], columns=1, columndist=0.5*unit.v_cm,
+                 textattrs=[], columns=1, columndist=0.5*unit.v_cm, itemorder=[],
                  border=0.3*unit.v_cm, keyattrs=None):
         self.dist = dist
         self.hinside = hinside
@@ -45,6 +45,7 @@
         self.textattrs = textattrs
         self.columns = columns
         self.columndist = columndist
+        self.itemorder = itemorder
         self.border = border
         self.keyattrs = keyattrs
         if pos is not None:
@@ -100,6 +101,8 @@
         columndist_pt = unit.topt(self.columndist)
         c = canvas.canvas()
         plotitems = [plotitem for plotitem in plotitems if plotitem.title is not None]
+        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
         itemspercolumn = (len(plotitems) + self.columns - 1) / self.columns # integer division
         x_pt = 0
         while plotitems:

Attachment: signature.asc
Description: This is a digitally signed message part.

-------------------------------------------------------------------------
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