from plot import *

class Plotter:

    def __init__(self, title=None):

        self.root = Tk()   # plot window
        if not title==None:
            self.root.title(title)
        #self.graphLines = []    # all lines on plot
        self.lines = []
        
        #    di = 5.*pi/5.
        #    data = []
        #    for i in range(18):
        #        data.append((float(i)*di,
        #(math.sin(float(i)*di)-math.cos(float(i)*di))))
        #    line  = GraphLine(data, color='gray', smooth=0)
        #    linea = GraphLine(data, color='blue', smooth=1, splinesteps=500)
        #
        #    graphObject = GraphObjects([line, linea])
        #
        self.graph  = GraphBase(self.root, 500, 500, relief=SUNKEN, border=2)
        self.graph.pack(side=TOP, fill=BOTH, expand=YES)
        #
        #    graph.draw(graphObject, 'automatic', 'automatic')
        #
        #    Button(root, text='Clear',  command=graph.clear).pack(side=LEFT)
        #    Button(root, text='Redraw', command=graph.replot).pack(side=LEFT)
        #    Button(root, text='Quit',   command=root.quit).pack(side=RIGHT)
        #
        #    root.mainloop()


        # colours available for plot
        self.colours = ['red', 'blue', 'orange', 'green', 'gray']
        self.nextcolour = 0  # next colour to use for plot


    # line is a list of points 
    # need to add code to let user specify smoothness
    def plot(self, data1):

        data = data1[:]  # make a copy



  
        line  = GraphLine(data, color=self.colours[self.nextcolour], smooth=0)
        self.nextcolour = (self.nextcolour + 1) % len(self.colours)
        #linea = GraphLine(data, color='blue', smooth=1, splinesteps=500)

        self.lines.append(line)
        self.graph.clear()
        graphObject = GraphObjects(self.lines)

#        self.graph  = GraphBase(self.root, 500, 400, relief=SUNKEN, border=2)
#        self.graph.pack(side=TOP, fill=BOTH, expand=YES)

        self.graph.draw(graphObject, 'automatic', 'automatic')

        #Button(root, text='Clear',  command=graph.clear).pack(side=LEFT)
        #Button(root, text='Redraw', command=graph.replot).pack(side=LEFT)
        #Button(root, text='Quit',   command=root.quit).pack(side=RIGHT)

        #root.mainloop()





##         graphLine = GraphLine(data, color='blue', smooth=0)
##         #self.graphLines.append(graphLine)
##         graphObject = GraphObjects(graphLine)
##         self.graph.draw(graphObject, 'automatic', 'automatic')
                        




    def clear(self):
        self.graph.clear()
        self.lines = []
        


    def closePlot(self):
        pass
        

    






