package cnp.ew.charts;

import java.awt.*;
import cnp.ew.displayer.*;
import cnp.ew.lightweight.*;

public class CpChartBackdropDisplayer extends CpAbstractChartBackdropDisplayer
{

    Color backColor=Color.white;
    Color lineColor = Color.black;
    boolean drawBorder=false;

    // TBD: make these lines have a style (displayers themselves)
    boolean drawValueLines=true;
    boolean drawCategoryLines=false;


    public void setBackColor(Color newColor)
    {
        backColor = newColor;
    }

    public void setLineColor(Color newColor)
    {
        lineColor = newColor;
    }

    /**
     * Display the object using g in the rectangle defined
     * by x,y with width w and height h.
     */
    public void paintIn(CpLightweightComponent lc, Graphics g, int x, int y, int w, int h)
    {
        int startX, startY, bottomStartY, totalItems, itemWidth;
        double currentValue, valuePercentage;

        g.setColor(backColor);
        g.fillRect(x, y, w, h);

        if (drawValueLines) {
            g.setColor(lineColor);
            currentValue = valueAxisModel.getMin();
            bottomStartY = y + h;
    	    for (int i=0; i < valueAxisModel.getMajorStepCount(); i++) {
    	        valuePercentage = valueAxisModel.getPercentageForValue(currentValue);
    	        startY = bottomStartY - (int)(valuePercentage * h);
	            g.drawLine(x, startY, x + w - 1, startY);
    	        currentValue += valueAxisModel.getMajorStep();
    	    }
    	}

    	if (drawCategoryLines) {
            totalItems = dataModel.getCategoryCount();
            itemWidth = w/totalItems;
            startX = x + itemWidth;
            for (int i=0; i < totalItems - 1; i++) {
                g.drawLine(startX, y, startX, y + h);
                startX += itemWidth;
            }
    	}

    	if (drawBorder) {
    	    g.drawRect(x, y, w-1, h-1);
    	}

    }
}

