/*
 * BasePlot.java
 * Code: Jan Humble
 */

import java.applet.*;
import java.awt.*;


/* ------------------------------------------------ */
/* Base Plot class to inherit from.                 */
/* Contains common drawing functions.               */
/* ------------------------------------------------ */

abstract class BasePlot {
    
    int dY; 
    int dX;

    Color color;
    String label;

    // Constructor

    BasePlot (int dX, int dY, Color color) {
	this.dY = dY;
	this.dX = dX;
	
	this.color = color;

    }
    
    abstract double f(double x); 
    abstract void move(int time);

    public void drawAxis(Graphics g) {	
	
	/* Draw axis */
	g.setColor(Color.red);
	g.drawLine(0,    dY/2, dX,   dY/2);
	g.drawLine(dX/2, 0,    dX/2, dY);	
	
	g.setFont(new Font("Helvetica", Font.PLAIN, 10));
	g.drawString("X", dX - 12,   dY/2 - 4);
	g.drawString("Y", dX/2 + 8, 16);
    }
    
    public void drawLabel(String label, Graphics g) {	
	/* Draw label */
	g.setColor(Color.black);
	g.setFont(new Font("Helvetica", Font.BOLD, 12));
	g.drawString(label, 8, 20);	
    }
    
    public void draw(Graphics g) {
	drawAxis(g);
	drawLabel(label, g);	
	
	/* Draw function */
	g.setColor(color);
        for (int x = 0 ; x < dX ; x++) {
	    g.drawLine(x, (int) f(x), x + 1, (int) f(x + 1));
	    
	}	
    }
}


