?? axis.java
字號:
* Detach All attached dataSets. */ public void detachAll() { int i; DataSet d; if( dataset.isEmpty() ) return; if( orientation == HORIZONTAL ) { for (i=0; i<dataset.size(); i++) { d = (DataSet)(dataset.elementAt(i)); d.xaxis = null; } } else { for (i=0; i<dataset.size(); i++) { d = (DataSet)(dataset.elementAt(i)); d.yaxis = null; } } dataset.removeAllElements(); minimum = 0.0; maximum = 0.0; } /** * Return the minimum value of All datasets attached to the axis. * @return Data minimum */ public double getDataMin() { double m; Enumeration e; DataSet d; if( dataset.isEmpty() ) return 0.0; d = (DataSet)(dataset.firstElement()); if(d == null) return 0.0; if( orientation == HORIZONTAL ) { m = d.getXmin(); for (e = dataset.elements() ; e.hasMoreElements() ;) { d = (DataSet)e.nextElement(); m = Math.min(d.getXmin(),m); } } else { m = d.getYmin(); for (e = dataset.elements() ; e.hasMoreElements() ;) { d = (DataSet)e.nextElement(); m = Math.min(d.getYmin(),m); } } return m; } /** * Return the maximum value of All datasets attached to the axis. * @return Data maximum */ public double getDataMax() { double m; Enumeration e; DataSet d; if( dataset.isEmpty() ) return 0.0; d = (DataSet)(dataset.firstElement()); if(d == null) return 0.0; if( orientation == HORIZONTAL ) { m = d.getXmax(); for (e = dataset.elements() ; e.hasMoreElements() ;) { d = (DataSet)e.nextElement(); m = Math.max(d.getXmax(),m); } } else { m = d.getYmax(); for (e = dataset.elements() ; e.hasMoreElements() ;) { d = (DataSet)e.nextElement(); m = Math.max(d.getYmax(),m); } } return m; } /** * Return the pixel equivalent of the passed data value. Using the * position of the axis and the maximum and minimum values convert * the data value into a pixel value * @param v data value to convert * @return equivalent pixel value * @see graph.Axis#getDouble( ) */ public int getInteger(double v) { double scale; if( orientation == HORIZONTAL ) { scale = (double)(amax.x - amin.x)/(maximum - minimum); return amin.x + (int)( ( v - minimum ) * scale); } else { scale = (double)(amax.y - amin.y)/(maximum - minimum); return amin.y + (int)( (maximum-v)*scale ); } } /** * Return the data value equivalent of the passed pixel position. * Using the * position of the axis and the maximum and minimum values convert * the pixel position into a data value * @param i pixel value * @return equivalent data value * @see graph.Axis#getInteger( ) */ public double getDouble(int i) { double scale; if( orientation == HORIZONTAL ) { scale = (maximum - minimum)/(double)(amax.x - amin.x); return minimum + (i - amin.x)*scale; } else { scale = (maximum - minimum)/(double)(amax.y - amin.y); return maximum - (i - amin.y)*scale; } } /** * Reset the range of the axis (the minimum and maximum values) to the * default data values. */ public void resetRange() { minimum = getDataMin(); maximum = getDataMax(); } /** * Return the position of the Axis. * @return One of Axis.LEFT, Axis.RIGHT, Axis.TOP, or Axis.BOTTOM. */ public int getAxisPos() { return position; } /** * If the Axis is Vertical return <i>true</i>. */ public boolean isVertical() { if( orientation == HORIZONTAL ) return false; else return true; } /** * Return the width of the axis. * @param g graphics context. */ public int getAxisWidth(Graphics g) { int i; width = 0; if( minimum == maximum ) return 0; if( dataset.size() == 0 ) return 0; calculateGridLabels(); exponent.setText(null); if(label_exponent != 0) { exponent.copyState(label); exponent.setText("x10^"+String.valueOf(label_exponent)); } if( orientation == HORIZONTAL ) { width = label.getRHeight(g) + label.getLeading(g); width += Math.max(title.getRHeight(g),exponent.getRHeight(g)); } else { for(i=0; i<label_string.length; i++) { label.setText(" "+label_string[i]); width = Math.max(label.getRWidth(g),width); } max_label_width = width; width = 0; if(!title.isNull() ) { width = Math.max(width,title.getRWidth(g)+ title.charWidth(g,' ')); } if ( !exponent.isNull() ) { width = Math.max(width,exponent.getRWidth(g)+ exponent.charWidth(g,' ')); } width += max_label_width; } return width; } /** * Position the axis at the passed coordinates. The coordinates should match * the type of axis. * @param xmin The minimum X pixel * @param xmax The maximum X pixel. These should be equal if the axis * is vertical * @param ymin The minimum Y pixel * @param ymax The maximum Y pixel. These should be equal if the axis * is horizontal * @return <i>true</i> if there are no inconsistencies. */ public boolean positionAxis(int xmin, int xmax, int ymin, int ymax ){ amin = null; amax = null; if( orientation == HORIZONTAL && ymin != ymax ) return false; if( orientation == VERTICAL && xmin != xmax ) return false; amin = new Point(xmin,ymin); amax = new Point(xmax,ymax); return true; } /** * Draw the axis using the passed Graphics context. * @param g Graphics context for drawing */ public void drawAxis(Graphics g) { Graphics lg; if( !redraw ) return; if( minimum == maximum ) { System.out.println( "Axis: data minimum==maximum Trying to reset range!"); resetRange(); if( minimum == maximum ) { System.out.println( "Axis: Reseting Range failed! Axis not drawn!"); return; } } if( amin.equals(amax) ) return; if( width == 0 ) width = getAxisWidth(g); lg = g.create(); if( force_end_labels ) { minimum = label_start; maximum = minimum + (label_count-1)*label_step; } /* ** For rotated text set the Component that is being drawn into */ title.setDrawingComponent(g2d); label.setDrawingComponent(g2d); exponent.setDrawingComponent(g2d); if( orientation == HORIZONTAL) { drawHAxis(lg); } else { drawVAxis(lg); } } /** * Set the title of the axis * @param s string containing text. */ public void setTitleText(String s) { title.setText(s); } /** * Set the color of the title * @param c Color of the title. */ public void setTitleColor(Color c) { title.setColor(c); } /** * Set the font of the title * @param c Title font. */ public void setTitleFont(Font f) { title.setFont(f); } /** * Set the title rotation angle. Only multiples of 90 degrees allowed. * @param a Title rotation angle in degrees. */ public void setTitleRotation(int a) { title.setRotation(a); } /** * Set the color of the labels * @param c Color of the labels. */ public void setLabelColor(Color c) { label.setColor(c); } /** * Set the font of the labels. * @param f font. */ public void setLabelFont(Font f) { label.setFont(f); } /** * Set the color of the exponent * @param c Color. */ public void setExponentColor(Color c) { exponent.setColor(c); } /** * Set the font of the exponent * @param f font. */ public void setExponentFont(Font f) { exponent.setFont(f); } /** * Is the range of the axis to be set automatically (based on the data) * or manually by setting the values Axis.minimum and Axis.maximum? * @param b boolean value. */ public void setManualRange(boolean b) { manualRange = b; } /************************ Protected Methods********************/ /** * Draw a Horizontal Axis. * @param g Graphics context. */ protected void drawHAxis(Graphics g) { Graphics lg; int i; int j; int x0,y0,x1,y1; int direction; int offset; double minor_step; Color c; double vmin = minimum*1.001; double vmax = maximum*1.001; double scale = (amax.x - amin.x)/(maximum - minimum); double val; double minor;// System.out.println("Drawing Horizontal Axis!"); if( axiscolor != null) g.setColor(axiscolor); g.drawLine(amin.x,amin.y,amax.x,amax.y); if(position == TOP ) direction = 1; else direction = -1; minor_step = label_step/(minor_tic_count+1); val = label_start; for(i=0; i<label_count; i++) { if( val >= vmin && val <= vmax ) { y0 = amin.y; x0 = amin.x + (int)( ( val - minimum ) * scale);
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -