Changeset - 528140423e49
[Not reviewed]
default
0 4 0
volker - 10 years ago 2015-06-23 22:49:33
volker.jaenisch@inqbus.de
ALso change of the tickmark component
4 files changed with 24 insertions and 8 deletions:
0 comments (0 inline, 0 general)
src/graph/interfaces.py
Show inline comments
 

	
 
from zope.interface import Interface
 

	
 
# ADAPTER BASE CLASSES
 
class IBaseAdapter(Interface):
 
    """
 
    Base of all adapters
 
    """
 
    def __init__(self, obj):
 
        """
 
        Gets an Object to be adapted
 
        """
 

	
 
class IBaseComponent(Interface):
 
    """
 
    All Interfaces derived from this class are marking a Class to be a component of this framework.
 
    """
 

	
 
class IAxis(IBaseComponent):
 
    """
 
    Axis interface
 
    """
 
    def __init__(self, parent):
 
        """
 
        createed with knowledge of its parent component
 
        """
 

	
 
class ITickLabelAdapter(IBaseComponent):
 
class ITickLabel(IBaseComponent):
 
    """
 
    An adapter that produces tick labels for an axis
 
    """
 

	
 
class IViewBox(IBaseComponent):
 
    """
 
    Container to display some components
 
    """
 

	
 
class IImage(IBaseComponent):
 
    """
 
    Some xy data
 
    """
 

	
src/graph_ZCA/app.py
Show inline comments
 

	
 
from zope.interface import implements
 

	
 
from graph_ZCA.components import BaseComponent, Image, Axis, AxisComponent, ViewBox
 
from graph_ZCA.components import BaseComponent, Image, Axis, AxisComponent, ViewBox, TickLabelComponent
 
from graph_ZCA.interfaces import IAxis, IViewBox, IBaseComponent
 

	
 
from zope.component import getGlobalSiteManager, adapts
 

	
 
gsm = getGlobalSiteManager()
 

	
 

	
 
class IPlotImage(IBaseComponent):
 
    """
 
    Component to plot a 2d graph of a given image
 
    """
 

	
 

	
 
class PlotImage( BaseComponent):
 
    """
 
    Makes a 2D plot for an image
 
    """
 
    implements(IPlotImage)
 

	
 
    def __init__(self, parent):
 
        super(PlotImage, self).__init__(parent)
 

	
 
        self.vb = ViewBox(self)()
 

	
 
        x_axis = Axis(self.vb)()
 
        x_axis.orientation='bottom'
 
        x_axis.start=0
 
        x_axis.end=8
 

	
 
        y_axis = Axis(self.vb)()
 
        y_axis.orientation='left'
 
        y_axis.start=-5
 
        y_axis.end=3
 

	
 

	
 
        self.vb.addItem( x_axis )
 
        self.vb.addItem( y_axis )
 

	
 
    def render(self):
 
        return self.vb.render()
 

	
 

	
 
class NewAxisComponent(AxisComponent):
 
    adapts(IViewBox)
 

	
 
gsm.registerAdapter(NewAxisComponent)
 

	
 

	
 
class NewTickLabelComponent(TickLabelComponent):
 
    adapts(IAxis)
 

	
 
    def render(self):
 
        return " ".join([ "q%i" % i for i in range(self.axis.start, self.axis.end)])
 

	
 
gsm.registerAdapter(NewTickLabelComponent)
 

	
 

	
 

	
 
image_data = [1,2,3,4]
 

	
 
plot =  PlotImage( None)
 
image = Image(plot.vb)(image_data)
 
plot.vb.addItem(image)
 

	
 
print( plot.render())
 

	
src/graph_ZCA/components.py
Show inline comments
 
from zope.interface import implementsOnly, implements, Interface
 
from zope.component import adapts, getGlobalSiteManager
 

	
 
gsm = getGlobalSiteManager()
 

	
 
from graph_ZCA.base import BaseAdapter, BaseComponent, BaseFactory
 
from graph_ZCA.interfaces import ITickLabelAdapter, IAxis, IViewBox, IImage
 
from graph_ZCA.interfaces import ITickLabel, IAxis, IViewBox, IImage
 

	
 

	
 
class TickLabelAdapter(BaseAdapter):
 
class TickLabelComponent(BaseComponent):
 
    """
 
    Generates Ticklabels for an axis
 
    """
 
    implementsOnly(ITickLabelAdapter)
 
    implementsOnly(ITickLabel)
 
    adapts(IAxis)
 

	
 
    def __init__(self, axis):
 
        """
 
        Gets an Object to be adapted
 
        """
 
        self.axis = axis
 

	
 
    def render(self):
 
        return map(str, range(self.axis.start, self.axis.end))
 

	
 
gsm.registerAdapter(TickLabelAdapter)
 
gsm.registerAdapter(TickLabelComponent)
 

	
 

	
 
class TickLabel(BaseFactory):
 

	
 
    target_interface = ITickLabel
 

	
 

	
 
class AxisComponent(BaseComponent):
 
    """
 
    Represents an axis
 
    """
 

	
 
    implements(IAxis)
 
    adapts(Interface)
 

	
 
    def __init__(self, parent, orientation=None, start=None, end=None):
 
        super(AxisComponent, self).__init__(parent)
 
        self.orientation = orientation
 
        self.start = start
 
        self.end = end
 

	
 
    def get_tick_labels(self):
 
        return ITickLabelAdapter(self).render()
 
        return TickLabel(self)().render()
 

	
 
    def render(self):
 
        return '%s: ' % self.__class__.__name__ + self.orientation + ':' + ' '.join(self.get_tick_labels())
 

	
 
gsm.registerAdapter(AxisComponent)
 

	
 

	
 
class Axis(BaseFactory):
 

	
 
    target_interface = IAxis
 

	
 

	
 
class ViewBoxComponent(BaseComponent):
 
    """
 
    Drawing area of a plot. THe drawing ares may have an unlimited number of axis
 
    """
 
    implements(IViewBox)
 
    adapts(Interface)
 

	
 

	
 
    def __init__(self, parent):
 
        super(ViewBoxComponent, self).__init__(parent)
 

	
 

	
 

	
 
    def render(self):
 
        result = []
 
        for item in self.items:
 
            result.append(item.render())
 

	
 
        return '\n'.join(result)
 

	
 

	
 
gsm.registerAdapter(ViewBoxComponent)
 

	
 

	
 
class ViewBox(BaseFactory):
 

	
 
    target_interface = IViewBox
 

	
 

	
 
class ImageComponent(BaseComponent):
 
    """
 
    A image representing f(x,y) values
 
    """
 
    implements(IImage)
 
    adapts(Interface)
 

	
src/graph_ZCA/interfaces.py
Show inline comments
 

	
 
from zope.interface import Interface
 

	
 
# ADAPTER BASE CLASSES
 
class IBaseAdapter(Interface):
 
    """
 
    Base of all adapters
 
    """
 
    def __init__(self, obj):
 
        """
 
        Gets an Object to be adapted
 
        """
 

	
 
class IBaseComponent(Interface):
 
    """
 
    All Interfaces derived from this class are marking a Class to be a component of this framework.
 
    """
 

	
 
class IAxis(IBaseComponent):
 
    """
 
    Axis interface
 
    """
 
    def __init__(self, parent):
 
        """
 
        createed with knowledge of its parent component
 
        """
 

	
 
class ITickLabelAdapter(IBaseComponent):
 
class ITickLabel(IBaseComponent):
 
    """
 
    An adapter that produces tick labels for an axis
 
    """
 

	
 
class IViewBox(IBaseComponent):
 
    """
 
    Container to display some components
 
    """
 

	
 
class IImage(IBaseComponent):
 
    """
 
    Some xy data
 
    """
 

	
0 comments (0 inline, 0 general)