Back to index

wims  3.65+svn20090927
Public Member Functions | Package Attributes | Private Member Functions | Private Attributes
SharpTools.HistoPanel Class Reference

The is the panel to draw histogram on. More...

Inheritance diagram for SharpTools.HistoPanel:
Inheritance graph
[legend]
Collaboration diagram for SharpTools.HistoPanel:
Collaboration graph
[legend]

List of all members.

Public Member Functions

void setStartEndPoints (float start, float end, float bucket)
void setXYAxis (float xmin, float xmax, float xunit, float ymin, float ymax, float yunit)
void setByPercentage (boolean bypercentage)
void setData (float[] data)
float[] getData ()
void paintComponent (Graphics g)
 This is the overriden method of customized drawing.

Package Attributes

float end
float bucket
float xmax
float xunit
float ymax
float yunit
float yscale
int ysize

Private Member Functions

int getXSize ()
int getYSize ()
void drawLine (Graphics g, int x1, int y1, int x2, int y2)
void drawString (Graphics g, String s, int x, int y)
int getx (int x)
int gety (int y)
void cString (Graphics g1, String s, int i, int j)
void rString (Graphics g1, String s, int i, int j)

Private Attributes

float[] bars
float start
float xmin
float ymin
float xscale
int xsize
int xborder = 50
int yborder = 40
boolean bypercentage

Detailed Description

The is the panel to draw histogram on.

One thing to pay attention to is the virtual coordinate we are using. Virtual coordinate is the coordinate used as in the histogram. The differences between a virtual coordinate and the Java coordinate system are: 1) Y axis direction is different 2) We take border into account for virtual coordinate (so it has a smaller scale).

Author:
Hua Zhong
Version:
Revision:
1.5

Definition at line 323 of file TabPanel.java.


Member Function Documentation

void SharpTools.HistoPanel.cString ( Graphics  g1,
String  s,
int  i,
int  j 
) [inline, private]

Definition at line 494 of file TabPanel.java.

                                                              {
        int k = g1.getFontMetrics().stringWidth(s);
        drawString(g1, s, i - k / 2, j);
    }

Here is the call graph for this function:

Here is the caller graph for this function:

void SharpTools.HistoPanel.drawLine ( Graphics  g,
int  x1,
int  y1,
int  x2,
int  y2 
) [inline, private]

Definition at line 465 of file TabPanel.java.

                                                                      {

       // draw axis
       g.drawLine(x1+xborder, ysize-y1+yborder,
                 x2+xborder, ysize-y2+yborder);
    }

Here is the caller graph for this function:

void SharpTools.HistoPanel.drawString ( Graphics  g,
String  s,
int  x,
int  y 
) [inline, private]

Definition at line 474 of file TabPanel.java.

                                                                {

       // draw axis
       g.drawString(s, x+xborder, ysize-y+yborder);
    }

Here is the caller graph for this function:

float [] SharpTools.HistoPanel.getData ( ) [inline]

Definition at line 373 of file TabPanel.java.

                             {
       return bars;
    }

Here is the caller graph for this function:

int SharpTools.HistoPanel.getx ( int  x) [inline, private]

Definition at line 484 of file TabPanel.java.

                            {
       return x+xborder;
    }
int SharpTools.HistoPanel.getXSize ( ) [inline, private]

Definition at line 455 of file TabPanel.java.

                           {
       return getWidth()-2*xborder;
    }

Here is the caller graph for this function:

int SharpTools.HistoPanel.gety ( int  y) [inline, private]

Definition at line 489 of file TabPanel.java.

                            {
       return ysize-y+yborder;
    }
int SharpTools.HistoPanel.getYSize ( ) [inline, private]

Definition at line 459 of file TabPanel.java.

                           {
       return getHeight()-2*yborder;
    }

Here is the caller graph for this function:

void SharpTools.HistoPanel.paintComponent ( Graphics  g) [inline]

This is the overriden method of customized drawing.

Parameters:
gthe Graphics object

Definition at line 382 of file TabPanel.java.

                                           {
       super.paintComponent(g);    

       if (bars == null)
           return;
       
       xsize = getXSize();
       ysize = getYSize();

       // draw x axise
       if (xsize < 0 || ysize < 0)
           return;

       float xratio = xscale/xsize;
       float yratio = yscale/ysize; // xscale/xsize; yscale/ysize
       
       // x axis
       drawLine(g, 0, 0, xsize+20, 0);
       // y xais
       drawLine(g, 0, 0, 0, ysize+20);

       if (bypercentage)
           cString(g, "(%)", 0, ysize+30);

       // draw x ticks
       for (float x = xmin; x <= xmax; x+=xunit) {
           int xcoor = (int)((x-xmin)/xratio);
           drawLine(g, xcoor, +3, xcoor, -3);
           cString(g, String.valueOf(x), xcoor, -20);
       }

       // draw y ticks
       for (float y = ymin; y <= ymax; y+=yunit) {
           int ycoor = (int)((y-ymin)/yratio);
           drawLine(g, -3, ycoor, +3, ycoor);
           rString(g, String.valueOf(y), -5, ycoor);
       }
       
       // draw bars!
       // int barwidth = (int)(bucket/xratio);
       for (int i = 0; i < bars.length; i++) {
           // for (float x = start-bucket; x < end+bucket; x+=bucket) {
           float x = start+(i-1)*bucket;
           int ycoor = (int)((bars[i]-ymin)/yratio);
           
           int xcoor1 = (int)((x-xmin)/xratio);
           int xcoor2 = (int)((x+bucket-xmin)/xratio);
           

           // must be in range
           xcoor1 = Math.max(xcoor1, 0);
           xcoor2 = Math.min(xcoor2, xsize);

           if (i == 0)
              xcoor1 = 0;

           if (i == bars.length-1)
              xcoor2 = xsize;
           
           if (xcoor1 >= xcoor2)
              continue;

           // draw the bar
           drawLine(g, xcoor1, 0, xcoor1, ycoor);
           
           drawLine(g, xcoor2, 0, xcoor2, ycoor);
           
           drawLine(g, xcoor1, ycoor, xcoor2, ycoor);

       }
       
    }

Here is the call graph for this function:

void SharpTools.HistoPanel.rString ( Graphics  g1,
String  s,
int  i,
int  j 
) [inline, private]

Definition at line 500 of file TabPanel.java.

                                                              {
        int k = g1.getFontMetrics().stringWidth(s);
        drawString(g1, s, i - k, j);
    }

Here is the call graph for this function:

Here is the caller graph for this function:

void SharpTools.HistoPanel.setByPercentage ( boolean  bypercentage) [inline]

Definition at line 365 of file TabPanel.java.

Here is the caller graph for this function:

void SharpTools.HistoPanel.setData ( float[]  data) [inline]

Definition at line 369 of file TabPanel.java.

                                      {
       bars = data;
    }

Here is the caller graph for this function:

void SharpTools.HistoPanel.setStartEndPoints ( float  start,
float  end,
float  bucket 
) [inline]

Definition at line 337 of file TabPanel.java.

                                                                        {
       this.start = start;
       this.end = end;
       this.bucket = bucket;
    }

Here is the caller graph for this function:

void SharpTools.HistoPanel.setXYAxis ( float  xmin,
float  xmax,
float  xunit,
float  ymin,
float  ymax,
float  yunit 
) [inline]

Definition at line 343 of file TabPanel.java.

                                                            {
       this.xmin = xmin;
       this.xmax = xmax;
       this.xunit = xunit;
       this.ymin = ymin;
       this.ymax = ymax;
       this.yunit = yunit;

       xscale = xmax-xmin;
       yscale = ymax-ymin;

       // calculate optimized xborder
       int len1 = String.valueOf(ymin).length();
       int len2 = String.valueOf(ymax).length();
       int len3 = String.valueOf(yunit).length();

       int maxdigits = Math.max(Math.max(len1, len2), len3);
       xborder = maxdigits*getGraphics().getFontMetrics().charWidth('0')+10;
       
    }

Here is the caller graph for this function:


Member Data Documentation

float [] SharpTools.HistoPanel.bars [private]

Definition at line 325 of file TabPanel.java.

Definition at line 326 of file TabPanel.java.

Definition at line 334 of file TabPanel.java.

float SharpTools.HistoPanel.end [package]

Definition at line 326 of file TabPanel.java.

float SharpTools.HistoPanel.start [private]

Definition at line 326 of file TabPanel.java.

int SharpTools.HistoPanel.xborder = 50 [private]

Definition at line 332 of file TabPanel.java.

float SharpTools.HistoPanel.xmax [package]

Definition at line 327 of file TabPanel.java.

float SharpTools.HistoPanel.xmin [private]

Definition at line 327 of file TabPanel.java.

Definition at line 329 of file TabPanel.java.

Definition at line 331 of file TabPanel.java.

float SharpTools.HistoPanel.xunit [package]

Definition at line 327 of file TabPanel.java.

int SharpTools.HistoPanel.yborder = 40 [private]

Definition at line 333 of file TabPanel.java.

float SharpTools.HistoPanel.ymax [package]

Definition at line 328 of file TabPanel.java.

float SharpTools.HistoPanel.ymin [private]

Definition at line 328 of file TabPanel.java.

Definition at line 329 of file TabPanel.java.

Definition at line 331 of file TabPanel.java.

float SharpTools.HistoPanel.yunit [package]

Definition at line 328 of file TabPanel.java.


The documentation for this class was generated from the following file: