scalar references

John Hunter jdhunter at
Wed Nov 19 15:42:57 CET 2003

>>>>> "Fredrik" == Fredrik Lundh <fredrik at> writes:

    Fredrik> The next step is to factor out common subexpressions that
    Fredrik> involve the DPI from the individual components and move
    Fredrik> them into the context object, via precalculated
    Fredrik> attributes or helper methods.  Use a setdpi() method or
    Fredrik> descriptors to make sure all attributes are updated when
    Fredrik> the DPI is changed (Should individual parts even have to
    Fredrik> know about the current DPI, by the way?  Shouldn't they
    Fredrik> work in the "plot value domain" or the "actual size
    Fredrik> domain"?  Maybe you should route all drawing operations
    Fredrik> through the new context class? Can you think of any other
    Fredrik> methods that belong to the context class?  Refactor!).

Hi Fredrik,

As for refactoring, I am!  Can one refactor in the midst of
refactoring <wink>?  I guess that's the best time....  I am worried
about the performance hit with all the gets, especially the ones
embedded by the binops.

For the most part my components *are* insulated from things like DPI.
It comes up in initializing transforms from physical coords to display
coords.  Most of the components only store their locations and
transforms (using refvals or scalars) so they don't worry about these
details of dpi, bounding boxes, and the like.  But the code that
creates the locations and transforms must.

The current implementation lets me do things like specify a location
as 'the top of the xtick label is 3 points below the xaxis' with

  top = self.bbox.y.get_refmin() - self.dpi*RRef(3/72.0)

where self.bbox.y.get_refmin() is a reference to the bottom of the
yaxis, dpi is a reference to DPI, and these are combined with the
BinOp class posted above to return a reference to a location that
updates automagically on resize events and dpi changes. 

If I were using a context class rather than a reference class,
self.bbox.y.min would store the new min of axes, but 'top', which is
defined by an arithmetic relationship to the ymin, would not be
updated.  I would have to propagate the resize call through all of my
components (which is certainly doable) and reupdate the positions and
transforms.  What I like about the reference architecture combined
with the binops is that I don't have to do propogate set_dpi and
set_canvas_size through all the components since they all store refs
to them; all locations and transformations of the components are
updated with no function calls, admittedly at the expense of all the

John Hunter

More information about the Python-list mailing list