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
 
@@ -16,25 +16,25 @@ 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
 
    """
 

	
 
@@ -40,20 +40,31 @@ class PlotImage( BaseComponent):
 
        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
 

	
 

	
src/graph_ZCA/interfaces.py
Show inline comments
 
@@ -16,25 +16,25 @@ 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)