package cnp.ew.charts;

import java.awt.*;
import cnp.ew.displayer.*;
import cnp.ew.lightweight.*;

public class Cp3DChartBackdropDisplayer extends CpAbstractChartBackdropDisplayer
{

    Color backColor=Color.gray;
    Color floorColor = Color.darkGray;
    Color lineColor = Color.black;

    // TBD: make these lines have a style (displayers themselves)
    boolean drawLines=true;
    Point slope = new Point(-10, -10);


    /**
     * Answer the offset from the top of the graph that another
     * displayer should use to align itself visually with the
     * top of the graph
     */
    public int getTopAlignmentOffset()
    {
        return Math.abs(slope.y);
    }
    // see above.
    public int getRightAlignmentOffset()
    {
        return Math.abs(slope.x);
    }

    /**
     * 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, lineHeight;
        int slopeX = Math.abs(slope.x);
        int slopeY = Math.abs(slope.y);

        slope.x = -slopeX;
        slope.y = -slopeY;

        Cp3DBarValueDisplayer.drawBarRect(
            g,
            lineColor,
            backColor,
            floorColor,
            backColor,
            x,
            y,
            w,
            h,
            slope,
            true,
            true,
            true);

        if (drawLines) {
            g.setColor(lineColor);
            double currentValue = valueAxisModel.getMin();
            int bottomStartY = y + h;
    	    for (int i=0; i < valueAxisModel.getMajorStepCount(); i++) {
    	        double valuePercentage = valueAxisModel.getPercentageForValue(currentValue);
    	        int heightWithout3D = h - slopeY;
    	        startY = bottomStartY - (int)(valuePercentage * heightWithout3D);
	            g.drawLine(x, startY, x + slopeX, startY - slopeY);
	            g.drawLine(x + slopeX, startY - slopeY, x + w - 1, startY - slopeY);
    	        currentValue += valueAxisModel.getMajorStep();
    	    }
        }
    }
}

