Clover coverage report - Graph - 1.0.0
Coverage timestamp: ven. déc. 26 2003 02:14:20 CET
file stats: LOC: 131   Methods: 2
NCLOC: 76   Classes: 1
 
 Source file Conditionals Statements Methods TOTAL
HorizontalAxis.java 0% 0% 0% 0%
coverage
 1   
 /*
 2   
  * EJTools, the Enterprise Java Tools
 3   
  *
 4   
  * Distributable under LGPL license.
 5   
  * See terms of license at www.gnu.org.
 6   
  */
 7   
 package org.ejtools.graph.renderer;
 8   
 
 9   
 import java.awt.Color;
 10   
 import java.awt.FontMetrics;
 11   
 import java.awt.Graphics;
 12   
 import java.awt.Insets;
 13   
 import java.awt.geom.Rectangle2D;
 14   
 import java.text.Format;
 15   
 
 16   
 import org.ejtools.graph.Axis;
 17   
 import org.ejtools.graph.GraphRenderer;
 18   
 
 19   
 /**
 20   
  * @author    Laurent Etiemble
 21   
  * @version   $Revision: 1.7 $
 22   
  * @todo      Javadoc to complete
 23   
  */
 24   
 public class HorizontalAxis extends Axis
 25   
 {
 26   
    /**
 27   
     * Constructor for VerticalAxis.
 28   
     *
 29   
     * @param format    Description of the Parameter
 30   
     * @param position  Description of the Parameter
 31   
     */
 32  0
    public HorizontalAxis(Format format, int position)
 33   
    {
 34  0
       this.format = format;
 35  0
       this.orientation = HORIZONTAL;
 36  0
       this.position = position;
 37   
    }
 38   
 
 39   
 
 40   
    /**
 41   
     * Description of the Method
 42   
     *
 43   
     * @param graphics  Description of the Parameter
 44   
     */
 45  0
    public void paintComponent(Graphics graphics)
 46   
    {
 47  0
       String display;
 48  0
       double multiplier = 0.0d;
 49   
 
 50  0
       graphics.setFont(FONT);
 51  0
       FontMetrics metrics = graphics.getFontMetrics();
 52   
 
 53  0
       Insets insets = this.getInsets();
 54  0
       int x = insets.left;
 55   
       // int y = insets.top;
 56  0
       double width = (double) this.getWidth() - 1 - insets.left - insets.right;
 57  0
       double height = (double) this.getHeight() - 1 - insets.top - insets.bottom;
 58   
 
 59  0
       double min = element.getXRange().getMin();
 60  0
       double max = element.getXRange().getMax();
 61   
 
 62  0
       double scaleX = width / (max - min);
 63  0
       double offsetX = x - scaleX * min;
 64   
 
 65  0
       if (this.horizontalScaling == GraphRenderer.ALIGN_LEFT)
 66   
       {
 67  0
          scaleX = 1.0d;
 68  0
          offsetX = -min;
 69   
       }
 70  0
       if (this.horizontalScaling == GraphRenderer.ALIGN_RIGHT)
 71   
       {
 72  0
          scaleX = 1.0d * this.horizontalScale;
 73  0
          offsetX = width - max * this.horizontalScale;
 74   
       }
 75   
 
 76  0
       min = (x - offsetX) / scaleX;
 77   
 
 78  0
       String minText = this.getFormated(min);
 79  0
       Rectangle2D minBounds = metrics.getStringBounds(minText, graphics);
 80  0
       String maxText = this.getFormated(max);
 81  0
       Rectangle2D maxBounds = metrics.getStringBounds(maxText, graphics);
 82   
 
 83   
       // Horizontal drawing
 84  0
       double bound = Math.max(minBounds.getWidth() * 4.0d, maxBounds.getWidth() * 4.0d);
 85   
 
 86   
       // Specified the number of texts
 87  0
       int ticks = 1;
 88  0
       while ((width / ticks) > bound)
 89   
       {
 90  0
          ticks = ticks * 2;
 91   
       }
 92   
 
 93   
       // Draw the baseline
 94  0
       graphics.drawLine(0, 0, (int) width, 0);
 95   
 
 96   
       // Draw the divisions
 97  0
       multiplier = width / ticks / 2;
 98  0
       graphics.setColor(Color.black);
 99  0
       for (int i = 0; i <= (2 * ticks); i++)
 100   
       {
 101  0
          int j = (int) (i * multiplier);
 102  0
          graphics.drawLine(j, 0, j, FONT.getSize() / 2);
 103   
       }
 104   
 
 105   
       // Draw the ticks
 106  0
       multiplier = width / ticks;
 107   
 
 108   
       // Draw first tick
 109  0
       graphics.drawLine(0, 0, 0, FONT.getSize() - metrics.getDescent());
 110  0
       graphics.drawString(minText, 0, (int) (height - metrics.getDescent()));
 111   
 
 112   
       // Draw others ticks
 113  0
       for (int i = 1; i < ticks; i++)
 114   
       {
 115  0
          int j = (int) (i * multiplier);
 116  0
          graphics.drawLine(j, 0, j, FONT.getSize() - metrics.getDescent());
 117   
 
 118  0
          display = this.getFormated(min + i * (max - min) / ticks);
 119  0
          Rectangle2D middleBounds = metrics.getStringBounds(display, graphics);
 120   
 
 121  0
          j = j - (int) (middleBounds.getWidth() / 2);
 122   
 
 123  0
          graphics.drawString(display, j, (int) (height - metrics.getDescent()));
 124   
       }
 125   
 
 126   
       // Draw last tick
 127  0
       graphics.drawLine((int) width, 0, (int) width, FONT.getSize() - metrics.getDescent());
 128  0
       graphics.drawString(maxText, (int) (width - maxBounds.getWidth()), (int) (height - metrics.getDescent()));
 129   
    }
 130   
 }
 131