home *** CD-ROM | disk | FTP | other *** search
/ Java Programmer's Toolkit / Java Programmer's Toolkit.iso / applets / plot2d / axis.jav < prev    next >
Encoding:
Text File  |  1995-12-15  |  24.0 KB  |  822 lines

  1. import java.awt.*;
  2. import java.applet.*;
  3. import java.util.Vector;
  4. import java.util.Enumeration;
  5. import java.lang.*;
  6.  
  7.  
  8. /*************************************************************************
  9. **
  10. **    Class  Axis            
  11. **                                              Version 1.0   October 1995
  12. **
  13. **************************************************************************
  14. **    Copyright (C) 1995 Leigh Brookshaw
  15. **
  16. **    This program is free software; you can redistribute it and/or modify
  17. **    it under the terms of the GNU General Public License as published by
  18. **    the Free Software Foundation; either version 2 of the License, or
  19. **    (at your option) any later version.
  20. **
  21. **    This program is distributed in the hope that it will be useful,
  22. **    but WITHOUT ANY WARRANTY; without even the implied warranty of
  23. **    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  24. **    GNU General Public License for more details.
  25. **
  26. **    You should have received a copy of the GNU General Public License
  27. **    along with this program; if not, write to the Free Software
  28. **    Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
  29. **************************************************************************
  30. **
  31. **    This class is designed to be used in conjunction with 
  32. **    the Graph2D class and DataSet class for plotting 2D graphs.
  33. **
  34. *************************************************************************/
  35.  
  36.  
  37.  
  38.  
  39.  
  40. class Axis extends Object {
  41.     
  42. /**************************
  43. ** Public Static Values     
  44. **************************/
  45.  
  46. /*
  47. **    Horizontal Axis or Vertical ?
  48. */
  49.       static final int  HORIZONTAL = 0;
  50.       static final int  VERTICAL   = 1;
  51. /*
  52. **    The axis will be on the lleft/right border or top/bottom border?
  53. */
  54.       static final int  LEFT       = 2;
  55.       static final int  RIGHT      = 3;
  56.       static final int  TOP        = 4;
  57.       static final int  BOTTOM     = 5;
  58. /*
  59. **    The first guess on the number of Major tic marks with labels
  60. */
  61.       static final int  NUMBER_OF_TICS = 4;
  62.  
  63. /**********************
  64. ** Public Variables      
  65. **********************/
  66.  
  67.       public int     gridlength       = 0;
  68.       public Color   gridcolor        = null;
  69.       public boolean redraw           = true;
  70.       public boolean force_end_labels = false;
  71.  
  72.       public boolean major_tics     = true;
  73.       public int     major_tic_size = 10;
  74.  
  75.       public int     minor_tic_size  = 5;
  76.       public int     minor_tic_count = 1;
  77.  
  78.       public Color   axis_color;
  79.  
  80.       public int width = 0;
  81.  
  82.       public Graph2D g2d;
  83.  
  84.       public double minimum;
  85.       public double maximum;
  86.  
  87.  
  88.       public String      title;
  89.       public Dimension   title_offset  = new Dimension(0,0);
  90.       public Font        title_font;
  91.       public Color       title_color;
  92.  
  93.       public Dimension   exponent_offset = new Dimension(0,0);
  94.       public int         exp_title_padding = 5;
  95.  
  96.       public int    label_Vpadding  = 2;     
  97.       public int    label_Hpadding  = 2;      
  98.  
  99.       public Font   label_font;
  100.       public Color  label_color;
  101. /**********************
  102. ** Protected Variables      
  103. **********************/
  104.       protected Point amin;
  105.       protected Point amax;
  106.       protected int orientation;
  107.       protected int position;
  108.       
  109.  
  110.       protected int exponent_height = 0;
  111.       protected int exponent_width  = 0;
  112.       protected int label_height    = 0;
  113.       protected int label_width     = 0;
  114.       protected int title_width     = 0;
  115.       protected int title_height    = 0;
  116.  
  117.  
  118.       protected Vector dataset = new Vector();
  119.        
  120.  
  121.       protected String label_string[]     = null;
  122.       protected double label_start        = 0.0;
  123.       protected double label_step         = 0.0;
  124.       protected int    label_exponent     = 0;
  125.       protected int    label_count        = 0;
  126.       protected int    guess_label_number = 4;
  127. /*
  128. **    StringKludge ONLY appears to work around a Major Deficiency in
  129. **    Netscape 2.0b1. It should dissappear when String.valueOf
  130. **    works
  131. */           
  132.       StringKludge sk = new StringKludge();
  133.  
  134. /********************
  135. ** Constructors
  136. ********************/
  137.  
  138.       public Axis(int p) {
  139.  
  140.            position = p;
  141.  
  142.            switch (position) {
  143.               case LEFT:
  144.                           orientation = VERTICAL;
  145.                           break;
  146.               case RIGHT:
  147.                           orientation = VERTICAL;
  148.                           break;
  149.  
  150.               case TOP:
  151.                           orientation = HORIZONTAL;
  152.                           break;
  153.               case BOTTOM:
  154.                           orientation = HORIZONTAL;
  155.                           break;
  156.               default:
  157.                           orientation = HORIZONTAL;
  158.                           position    = BOTTOM;
  159.                           break;
  160.            }
  161.  
  162.       }
  163.  
  164.  
  165. /******************
  166. ** Public Methods
  167. ******************/
  168.  
  169.       public void attachDataSet( DataSet d ) {
  170.             if( orientation == HORIZONTAL )   attachXdata( d );
  171.             else                              attachYdata( d );
  172.       }
  173.  
  174.       public void detachDataSet( DataSet d ) {
  175.            int i = 0;
  176.  
  177.            if( d == null ) return;
  178.  
  179.            if( orientation == HORIZONTAL ) {
  180.                d.xaxis = null;
  181.            } else {
  182.                d.yaxis = null;
  183.            }
  184.            dataset.removeElement(d);
  185.  
  186.            minimum = getDataMin();
  187.            maximum = getDataMax();
  188.       }
  189.  
  190.       public void detachAllDataSets() {
  191.             Enumeration e;
  192.             DataSet d;
  193.  
  194.             if( dataset.isEmpty() ) return;
  195.  
  196.  
  197.             if( orientation == HORIZONTAL ) {
  198.                  for (e = dataset.elements() ; e.hasMoreElements() ;) {
  199.                      d = (DataSet)e.nextElement();
  200.                      d.xaxis = null;
  201.                  }
  202.             } else {
  203.                  for (e = dataset.elements() ; e.hasMoreElements() ;) {
  204.                      d = (DataSet)e.nextElement();
  205.                      d.yaxis = null;
  206.                  }
  207.             }
  208.  
  209.             minimum = 0.0;
  210.             maximum = 0.0;
  211.       }
  212.       public double getDataMin() {
  213.             double m;
  214.             Enumeration e;
  215.             DataSet d;
  216.  
  217.             if( dataset.isEmpty() ) return 0.0;
  218.  
  219.             d = (DataSet)(dataset.firstElement());
  220.             if(d == null) return 0.0;
  221.  
  222.             if( orientation == HORIZONTAL ) {
  223.                  m = d.getXmin();
  224.                  for (e = dataset.elements() ; e.hasMoreElements() ;) {
  225.  
  226.                      d = (DataSet)e.nextElement();
  227.                      m = Math.min(d.getXmin(),m);
  228.                      
  229.                  }
  230.             } else {
  231.                  m = d.getYmin();
  232.                  for (e = dataset.elements() ; e.hasMoreElements() ;) {
  233.  
  234.                      d = (DataSet)e.nextElement();
  235.                      m = Math.min(d.getYmin(),m);
  236.                      
  237.                  }
  238.             }
  239.  
  240.             return m;
  241.       }
  242.       public double getDataMax() {
  243.             double m;
  244.             Enumeration e;
  245.             DataSet d;
  246.  
  247.             if( dataset.isEmpty() ) return 0.0;
  248.  
  249.             d = (DataSet)(dataset.firstElement());
  250.  
  251.             if(d == null) return 0.0;
  252.  
  253.           
  254.             if( orientation == HORIZONTAL ) {
  255.                  m = d.getXmax();
  256.                  for (e = dataset.elements() ; e.hasMoreElements() ;) {
  257.  
  258.                      d = (DataSet)e.nextElement();
  259.                      m = Math.max(d.getXmax(),m);
  260.                  }
  261.             } else {
  262.                  m = d.getYmax();
  263.                  for (e = dataset.elements() ; e.hasMoreElements() ;) {
  264.  
  265.                      d = (DataSet)e.nextElement();
  266.  
  267.                      m = Math.max(d.getYmax(),m);
  268.                  }
  269.             }
  270.  
  271.             return m;
  272.       }
  273.  
  274.  
  275.       public int getInteger(double v) {
  276.           double scale;
  277.           
  278.           if( orientation == HORIZONTAL ) {
  279.                scale  = (amax.x - amin.x)/(maximum - minimum);
  280.                return amin.x + (int)( ( v - minimum ) * scale);
  281.           } else {
  282.                scale  = (amax.y - amin.y)/(maximum - minimum);
  283.                return amax.y - (int)( ( v - minimum ) * scale);
  284.  
  285.           }
  286.  
  287.       }
  288.  
  289.       public double getDouble(int i) {
  290.             double scale;
  291.  
  292.           if( orientation == HORIZONTAL ) {
  293.                scale  = (maximum - minimum)/(amax.x - amin.x);
  294.                return minimum + (i - amin.x)*scale;
  295.           } else {
  296.                scale  = (maximum - minimum)/(amax.y - amin.y);
  297.                return maximum - (i - amin.y)*scale;
  298.           }
  299.       }
  300.  
  301.      public int getAxisPos() { return position; }      
  302.  
  303.      public int getAxisWidth(Graphics g) {
  304.           FontMetrics fm;
  305.           int i;
  306.           width = 0;
  307.  
  308.           if( minimum == maximum )    return 0;
  309.           if( dataset.size() == 0 )   return 0;
  310.  
  311.  
  312.           calculateGridLabels();
  313.  
  314.           if( label_font != null)  fm = g.getFontMetrics(label_font);
  315.           else                     fm = g.getFontMetrics();
  316.  
  317.           label_height =  fm.getHeight();
  318.           label_width  = 0;       
  319.           for(i=0; i<label_string.length; i++) {
  320.                label_width = Math.max(
  321.                              fm.stringWidth(label_string[i]),label_width);
  322.           }
  323.  
  324.           exponent_width  = 0;
  325.           exponent_height = 0;
  326.           if(label_exponent != 0) {
  327.               exponent_width = fm.stringWidth("x10");
  328.               exponent_width += fm.stringWidth(String.valueOf(label_exponent));
  329.               exponent_height = fm.getHeight() + (int)(fm.getAscent()*0.5);
  330.           }
  331.  
  332.           title_width  = 0;
  333.           title_height = 0;
  334.           if(title != null) {
  335.                if(title_font != null) fm = g.getFontMetrics(title_font);
  336.                else                   fm = g.getFontMetrics();
  337.  
  338.                title_height = fm.getHeight();
  339.                title_width = fm.stringWidth(title);
  340.           }
  341.  
  342.            if( orientation == HORIZONTAL ) {
  343.  
  344.                width = label_height + label_Vpadding; 
  345.                width += Math.max(title_height,exponent_height);
  346.  
  347.            } else {
  348.  
  349.                width = label_width + label_Hpadding;
  350.                if( title_width != 0 && exponent_width != 0 ) {
  351.                    width = Math.max(width, 
  352.                       (title_width+exponent_width+exp_title_padding));
  353.                } else
  354.                if( title_width != 0 ) {
  355.                   width = Math.max(width,title_width);
  356.                } else
  357.                if ( exponent_width != 0 ) {
  358.                   width = Math.max(width,exponent_width);
  359.                }
  360.            }
  361.  
  362.  
  363.            return width;
  364.       }
  365.  
  366.       public boolean positionAxis(int xmin, int xmax, int ymin, int ymax ){
  367.            amin = null;
  368.            amax = null;
  369.  
  370.            if( orientation == HORIZONTAL && ymin != ymax ) return false;
  371.            if( orientation == VERTICAL   && xmin != xmax ) return false;
  372.  
  373.            amin = new Point(xmin,ymin);
  374.            amax = new Point(xmax,ymax);
  375.  
  376.  
  377.            return true;
  378.       }         
  379.  
  380.  
  381.  
  382.       public void drawAxis(Graphics g) {
  383.           Graphics lg;
  384.  
  385.           if( !redraw            ) return;
  386.           if( minimum == maximum ) return;
  387.           if( amin.equals(amax) ) return;
  388.           if( dataset.size() == 0 ) return;
  389.           if( width == 0 ) return;
  390.  
  391.           lg = g.create();
  392.  
  393.           if( force_end_labels ) {
  394.               minimum = label_start;
  395.               maximum = minimum + (label_count-1)*label_step;
  396.           }
  397.  
  398.           if( orientation == HORIZONTAL) {
  399.                drawHAxis(lg);
  400.           } else {
  401.                drawVAxis(lg);
  402.           }
  403.  
  404.  
  405.      }
  406.  
  407.  
  408. /******************
  409. ** Protected Methods
  410. ******************/
  411.  
  412.      protected void drawHAxis(Graphics g) {
  413.           Graphics lg;
  414.           int i;
  415.           int j;
  416.           int x0,y0,x1,y1;
  417.           int direction;
  418.           double minor_step;
  419.           
  420.           FontMetrics fm_label;
  421.           FontMetrics fm_title;
  422.           Color c;
  423.  
  424.           double vmin = minimum*1.001;
  425.           double vmax = maximum*1.001;
  426.  
  427.           double scale  = (amax.x - amin.x)/(maximum - minimum);
  428.           double val;
  429.           double minor;
  430.  
  431.  
  432.           if( axis_color != null) g.setColor(axis_color);
  433.  
  434.           g.drawLine(amin.x,amin.y,amax.x,amax.y);
  435.           
  436.           if(position == TOP )     direction =  1;
  437.           else                     direction = -1;
  438.  
  439.           minor_step = label_step/(minor_tic_count+1);
  440.           val = label_start;
  441.           for(i=0; i<label_count; i++) {
  442.               if( val >= vmin && val <= vmax ) {
  443.                  y0 = amin.y;
  444.                  x0 = amin.x + (int)( ( val - minimum ) * scale);
  445.                  if(gridlength > 0) {
  446.                       c = g.getColor();
  447.                       if(gridcolor != null) g.setColor(gridcolor);
  448.                       g.drawLine(x0,y0,x0,y0+gridlength*direction);
  449.                       g.setColor(c);
  450.                  }
  451.                  x1 = x0;
  452.                  y1 = y0 + major_tic_size*direction;
  453.                  g.drawLine(x0,y0,x1,y1);
  454.               }
  455.  
  456.               minor = val + minor_step;
  457.               for(j=0; j<minor_tic_count; j++) {
  458.                  if( minor >= vmin && minor <= vmax ) {
  459.                     y0 = amin.y;
  460.                     x0 = amin.x + (int)( ( minor - minimum ) * scale);
  461.                     if(gridlength > 0) {
  462.                       c = g.getColor();
  463.                       if(gridcolor != null) g.setColor(gridcolor);
  464.                       g.drawLine(x0,y0,x0,y0+gridlength*direction);
  465.                       g.setColor(c);
  466.                     }
  467.                     x1 = x0;
  468.                     y1 = y0 + minor_tic_size*direction;
  469.                     g.drawLine(x0,y0,x1,y1);
  470.                  }
  471.                 minor += minor_step;
  472.               }
  473.  
  474.               val += label_step;
  475.           }
  476.  
  477.           if( label_font != null) g.setFont(label_font);
  478.           fm_label = g.getFontMetrics();
  479.           if( label_color != null) g.setColor(label_color);
  480.  
  481.           if(position == TOP ) {
  482.              direction = - label_Vpadding - fm_label.getDescent();
  483.           } else {
  484.              direction = + label_Vpadding + fm_label.getAscent();
  485.           }
  486.  
  487.  
  488.           val = label_start;
  489.           for(i=0; i<label_count; i++) {
  490.  
  491.  
  492.               if( val >= vmin && val <= vmax ) {
  493.                  y0 = amin.y + direction;
  494.                  x0 = amin.x + (int)(( val - minimum ) * scale) - 
  495.                              fm_label.stringWidth(label_string[i])/2;
  496.  
  497.                  g.drawString(label_string[i],x0,y0);
  498.  
  499.               }
  500.               val += label_step;
  501.           }
  502.           if( label_exponent != 0 ) {
  503.  
  504.               x0 = amax.x - exponent_width/2 + exponent_offset.width;
  505.               if( position == TOP) {
  506.                 y0 = amin.y - label_Vpadding  -
  507.                    fm_label.getDescent() - fm_label.getAscent() -
  508.                    fm_label.getDescent() + exponent_offset.height;
  509.               } else {
  510.                 y0 = amax.y + label_Vpadding +
  511.                    fm_label.getDescent() + fm_label.getAscent() +
  512.                    (int)(1.5*fm_label.getAscent()) + exponent_offset.height;
  513.               }
  514.               
  515.               g.drawString("x10",x0,y0);
  516.  
  517.               x0 += fm_label.stringWidth("x10");
  518.               y0 -= fm_label.getAscent()/2;
  519.  
  520.               g.drawString(String.valueOf(label_exponent),x0,y0);
  521.  
  522.  
  523.  
  524.           }
  525.  
  526.  
  527.           if( title != null) {
  528.  
  529.              if(title_color != null ) g.setColor(title_color);
  530.  
  531.              if(title_font != null) g.setFont(title_font);
  532.              fm_title = g.getFontMetrics();
  533.  
  534.              x0 = amin.x + ( amax.x - amin.x - fm_title.stringWidth(title) )/2
  535.                   + title_offset.width;
  536.              if( position == TOP) {
  537.                y0 = amin.y - label_Vpadding  -
  538.                    fm_label.getDescent() - fm_label.getAscent() -
  539.                    fm_title.getDescent() + title_offset.height;
  540.              } else {
  541.                y0 = amax.y + label_Vpadding +
  542.                    fm_label.getDescent() + fm_label.getAscent() +
  543.                    fm_title.getAscent() + title_offset.height;
  544.              }
  545.  
  546.              g.drawString(title,x0,y0);
  547.           }
  548.  
  549.  
  550.      }
  551.  
  552.  
  553.      protected void drawVAxis(Graphics g) {
  554.           Graphics lg;
  555.           int i;
  556.           int j;
  557.           int x0,y0,x1,y1;
  558.           int direction;
  559.           double minor_step;
  560.           double minor;
  561.           Color c;
  562.           
  563.           FontMetrics fm;
  564.           Color gc = g.getColor();
  565.           Font  gf = g.getFont();
  566.  
  567.           double vmin = minimum*1.001;
  568.           double vmax = maximum*1.001;
  569.  
  570.           double scale  = (amax.y - amin.y)/(maximum - minimum);
  571.           double val;
  572.  
  573.  
  574.           if( axis_color != null) g.setColor(axis_color);
  575.  
  576.           g.drawLine(amin.x,amin.y,amax.x,amax.y);
  577.  
  578.           if(position == RIGHT )     direction = -1;
  579.           else                       direction =  1;
  580.  
  581.           minor_step = label_step/(minor_tic_count+1);
  582.           val = label_start;
  583.           for(i=0; i<label_count; i++) {
  584.               if( val >= vmin && val <= vmax ) {
  585.                  x0 = amin.x;
  586.                  y0 = amax.y - (int)( ( val - minimum ) * scale);
  587.                  if(gridlength > 0) {
  588.                       c = g.getColor();
  589.                       if(gridcolor != null) g.setColor(gridcolor);
  590.                       g.drawLine(x0,y0,x0+gridlength*direction,y0);
  591.                       g.setColor(c);
  592.                  }
  593.                  x1 = x0 + major_tic_size*direction;
  594.                  y1 = y0;
  595.                  g.drawLine(x0,y0,x1,y1);
  596.               }
  597.  
  598.               minor = val + minor_step;
  599.               for(j=0; j<minor_tic_count; j++) {
  600.                  if( minor >= vmin && minor <= vmax ) {
  601.                     x0 = amin.x;
  602.                     y0 = amax.y - (int)( ( minor - minimum ) * scale);
  603.                     if(gridlength > 0) {
  604.                       c = g.getColor();
  605.                       if(gridcolor != null) g.setColor(gridcolor);
  606.                       g.drawLine(x0,y0,x0+gridlength*direction,y0);
  607.                       g.setColor(c);
  608.                     }
  609.                     x1 = x0 + minor_tic_size*direction;
  610.                     y1 = y0;
  611.                     g.drawLine(x0,y0,x1,y1);
  612.                  }
  613.                 minor += minor_step;
  614.               }
  615.               val += label_step;
  616.           }
  617.  
  618.           if( label_font != null) g.setFont(label_font);
  619.           else                    g.setFont(gf);
  620.           fm = g.getFontMetrics();
  621.           if( label_color != null) g.setColor(label_color);
  622.           else                     g.setColor(gc);
  623.  
  624.           if(position == RIGHT ) {
  625.              direction = label_Hpadding + fm.getDescent();
  626.           } else {
  627.              direction = - label_Hpadding - fm.getAscent();
  628.           }
  629.  
  630.  
  631.           val = label_start;
  632.           for(i=0; i<label_count; i++) {
  633.               if( val >= vmin && val <= vmax ) {
  634.                  if(position == RIGHT ) {
  635.                      x0 = amin.x + label_Hpadding;
  636.                  } else {
  637.                      x0 = amin.x - label_Hpadding - 
  638.                           fm.stringWidth(label_string[i]);
  639.                  }
  640.                  y0 = amax.y - (int)(( val - minimum ) * scale) + 
  641.                              fm.getAscent()/2;
  642.  
  643.                  g.drawString(label_string[i],x0,y0);
  644.               }
  645.               val += label_step;
  646.           }
  647.  
  648.           if( title == null && label_exponent==0 ) return;
  649.  
  650.  
  651.           if(position == RIGHT ) {
  652.               x0 = amin.x + label_Hpadding;
  653.           } else {
  654.               x0 = amin.x  - label_Hpadding - exponent_width - title_width;
  655.               if( exponent_width != 0 && title_width != 0 )
  656.                       x0 -= exp_title_padding;
  657.           }
  658.           y0 = amin.y;
  659.  
  660.           if( title != null) {
  661.  
  662.              if(title_color != null ) g.setColor(title_color);
  663.              else                     g.setColor(gc);
  664.  
  665.              if(title_font != null) g.setFont(title_font);
  666.              else                   g.setFont(gf);
  667.  
  668.              g.drawString(title,x0+title_offset.width,y0+title_offset.height);
  669.  
  670.              
  671.              x0 += title_width + exp_title_padding;
  672.           }
  673.  
  674.           if( label_exponent != 0) {
  675.  
  676.               if( label_font != null) g.setFont(label_font);
  677.               else                    g.setFont(gf);
  678.  
  679.               fm = g.getFontMetrics();
  680.               if( label_color != null) g.setColor(label_color);
  681.               else                     g.setColor(gc);
  682.  
  683.               x0 += exponent_offset.width;
  684.               y0 += exponent_offset.height;
  685.  
  686.               g.drawString("x10",x0,y0);
  687.  
  688.               x0 += fm.stringWidth("x10");
  689.               y0 -= fm.getAscent()/2;
  690.  
  691.               g.drawString(String.valueOf(label_exponent),x0,y0);
  692.  
  693.           }
  694.  
  695.  }
  696.  
  697.  
  698.  
  699.  
  700.  
  701.  
  702.  
  703.  
  704.       protected void attachXdata( DataSet d ) {
  705.  
  706.             dataset.addElement(d);
  707.             d.xaxis = this;
  708.  
  709.             if( dataset.size() == 1 ) {
  710.                   minimum = d.xmin;
  711.                   maximum = d.xmax;
  712.             } else {
  713.                if(minimum > d.xmin) minimum = d.xmin;
  714.                if(maximum < d.xmax) maximum = d.xmax;
  715.             }
  716.  
  717.       }
  718.  
  719.       protected void attachYdata( DataSet d ) {
  720.  
  721.             dataset.addElement(d);
  722.             d.yaxis = this;
  723.  
  724.             if( dataset.size() == 1 ) {
  725.                   minimum = d.ymin;
  726.                   maximum = d.ymax;
  727.             } else {
  728.                if(minimum > d.ymin) minimum = d.ymin;
  729.                if(maximum < d.ymax) maximum = d.ymax;
  730.             }
  731.  
  732.  
  733.       }
  734.  
  735.  
  736.       protected void calculateGridLabels() {
  737.         double val;
  738.         int i;
  739.         int j;
  740.  
  741.         
  742.         if (Math.abs(minimum) > Math.abs(maximum) ) 
  743.          label_exponent = ((int)Math.floor(log10(Math.abs(minimum))/3.0) )*3;
  744.         else
  745.          label_exponent = ((int)Math.floor(log10(Math.abs(maximum))/3.0) )*3;
  746.  
  747.         label_step = RoundUp( (maximum-minimum)/guess_label_number );
  748.         label_start = Math.floor( minimum/label_step )*label_step;
  749.  
  750.         val = label_start;
  751.         label_count = 1;
  752.         while(val < maximum) { val += label_step; label_count++; }
  753.  
  754.         label_string = new String[label_count];
  755.  
  756.  
  757. //      System.out.println("label_step="+label_step);
  758. //      System.out.println("label_start="+label_start);
  759. //      System.out.println("label_count="+label_count);
  760. //      System.out.println("label_exponent"+label_exponent);
  761.  
  762.            
  763.         for(i=0; i<label_count; i++) {
  764.             val = label_start + i*label_step;
  765.  
  766.             if( label_exponent< 0 ) {
  767.                   for(j=label_exponent; j<0;j++) { val *= 10; }
  768.             } else {
  769.                   for(j=0; j<label_exponent;j++) { val /= 10; }
  770.             }
  771.  
  772. //            label_string[i] = String.valueOf(val);
  773.             label_string[i] = sk.valueOf(val);
  774.         }
  775.  
  776.       }
  777.  
  778. /******************
  779. ** Private Methods
  780. ******************/
  781.  
  782.       private double RoundUp( double val ) {
  783.           int exponent;
  784.           int i;
  785.  
  786.           exponent = (int)(Math.floor( log10(val) ) );
  787.  
  788.           if( exponent < 0 ) {
  789.              for(i=exponent; i<0; i++) { val *= 10.0; }
  790.           } else {
  791.              for(i=0; i<exponent; i++) { val /= 10.0; }
  792.           }
  793.  
  794.           if( val > 5.0 )     val = 10.0;
  795.           else
  796.           if( val > 2.0 )     val = 5.0;
  797.           else
  798.           if( val > 1.0 )     val = 2.0;
  799.           else
  800.                               val = 1.0;
  801.  
  802.           if( exponent < 0 ) {
  803.              for(i=exponent; i<0; i++) { val /= 10.0; }
  804.           } else {
  805.              for(i=0; i<exponent; i++) { val *= 10.0; }
  806.           }
  807.           
  808.           return val;
  809.  
  810.       }                  
  811.  
  812.  
  813.       private double log10( double a ) throws ArithmeticException {
  814.            return Math.log(a)/2.30258509299404568401;
  815.       }
  816.  
  817.  
  818.  
  819. }
  820.  
  821.  
  822.