Files @ 7aab6dba2515
Branch filter:

Location: volker/graph_components/src/graph_ZCA/app.py

volker
Added ZCA Version of the code

from zope.interface import implements

from graph_ZCA.components import BaseComponent, Image, Axis, AxisComponent, ViewBox
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)

image_data = [1,2,3,4]

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

print( plot.render())