|
From: Lukas P. <pe...@us...> - 2002-08-07 18:10:22
|
Update of /cvsroot/javaprofiler/module/net/sourceforge/javaprofiler/module/views
In directory usw-pr-cvs1:/tmp/cvs-serv4694
Modified Files:
TimeSeriesGraph.java
Log Message:
added axis label
Index: TimeSeriesGraph.java
===================================================================
RCS file: /cvsroot/javaprofiler/module/net/sourceforge/javaprofiler/module/views/TimeSeriesGraph.java,v
retrieving revision 1.3
retrieving revision 1.4
diff -C2 -r1.3 -r1.4
*** TimeSeriesGraph.java 30 Jul 2002 12:20:46 -0000 1.3
--- TimeSeriesGraph.java 7 Aug 2002 17:41:13 -0000 1.4
***************
*** 54,60 ****
private TimeSeriesModel model;
/** Graph style. */
! private String style=LINE_GRAPH;
/** Graph color. */
private Color graphColor;
/** Constructs graph with default model. */
--- 54,62 ----
private TimeSeriesModel model;
/** Graph style. */
! private String style=BAR_GRAPH;
/** Graph color. */
private Color graphColor;
+ /** Inner color. */
+ private Color innerColor;
/** Constructs graph with default model. */
***************
*** 109,112 ****
--- 111,124 ----
}
+ /** Sets color of graph inner area. */
+ public void setInnerColor(Color co) {
+ innerColor=co;
+ }
+
+ /** Returns color of graph inner area. */
+ public Color getInnerColor() {
+ return innerColor;
+ }
+
/** Used for notification of a model data change. Internal function,
not to be called by end users.
***************
*** 139,149 ****
max=fineScale(max);
- if (style==BAR_GRAPH)
- paintBarGraph(g, data, max);
- else if (style==LINE_GRAPH)
- paintLineGraph(g, data, max);
- }
-
- private void paintBarGraph(Graphics g, int[] data, int max) {
// compute usable area
Insets insets = getInsets();
--- 151,154 ----
***************
*** 153,219 ****
int left=insets.left;
! final int sCnt=data.length;
// area width for graph w/o axes
! int areaMaxW=currentWidth-3;
! final int advance=(areaMaxW+1) / sCnt;
! int columnW=advance-1;
! if (columnW<1) columnW=1;
! int areaW=sCnt*advance - 1;
! int areaMaxH=currentHeight-2;
// draw axes
g.setColor(getForeground());
! int x0=insets.left + (areaMaxW-areaW)/2;
! int y0=getHeight()-1 - insets.bottom;
! g.drawLine(x0, y0-2, x0+areaW+3-1, y0-2);
g.drawLine(x0+2, y0, x0+2, y0-(areaMaxH+3-1));
// draw
if (graphColor != null)
g.setColor(graphColor);
int columnH;
! int x=x0+3;
! final int y=y0 - 2;
for (int i=0; i<sCnt; i++) {
! columnH=data[i]*areaMaxH/max;
! g.fillRect(x, y-columnH, columnW, columnH);
! x+=advance;
}
}
! private void paintLineGraph(Graphics g, int[] data, int max) {
! // compute usable area
! Insets insets = getInsets();
! int currentWidth = getWidth() - insets.left - insets.right;
! int currentHeight = getHeight() - insets.top - insets.bottom;
! int top=insets.top;
! int left=insets.left;
!
! // draw axes
! g.setColor(getForeground());
! int x0=insets.left;
! int y0=getHeight()-1 - insets.bottom;
! g.drawLine(x0, y0-2, x0+currentWidth-1, y0-2);
! g.drawLine(x0+2, y0, x0+2, y0-(currentHeight-1));
!
! // area width for graph w/o axes
! int areaW=currentWidth-3;
! int areaH=currentHeight-3;
!
final int sCnt=data.length;
! // draw line
if (graphColor != null)
g.setColor(graphColor);
! int oldX=x0+3;
! int oldY=y0-2-data[0]*areaH/max;
! int x, y;
for (int i=1; i<sCnt; i++) {
! x=x0+3 + i*(areaW-1)/(sCnt-1);
! y=y0-2 - data[i]*areaH/max;
! g.drawLine(oldX, oldY, x, y);
! oldX=x;
! oldY=y;
}
}
--- 158,236 ----
int left=insets.left;
! // draw text
! g.setColor(getForeground());
! FontMetrics currentMetrics = g.getFontMetrics();
! int txtAsc=currentMetrics.getAscent();
! int charWidth=currentMetrics.charWidth('0');
! String text=String.valueOf(max);
! int txtWidth=text.length()*charWidth;
! g.drawString(text, left, top+txtAsc-1);
// area width for graph w/o axes
! int areaMaxW=currentWidth-3 - txtWidth - charWidth;
! int areaMaxH=currentHeight-3 - txtAsc/2;
+ // axes origin point
+ int x0=insets.left + txtWidth;
+ int y0=getHeight()-1 - insets.bottom;
+ // fill inner area
+ if (innerColor != null) {
+ g.setColor(innerColor);
+ int xa=x0+3;
+ int ya=y0-2-areaMaxH;
+ g.fillRect(xa, ya, areaMaxW, areaMaxH);
+ }
// draw axes
g.setColor(getForeground());
! // x axis
! g.drawLine(x0, y0-2, x0+areaMaxW+3-1, y0-2);
! // y axis
g.drawLine(x0+2, y0, x0+2, y0-(areaMaxH+3-1));
+ // tick
+ g.drawLine(x0, y0-2-areaMaxH, x0+4, y0-2-areaMaxH);
+ if (style==BAR_GRAPH)
+ paintBarGraph(g, x0+3, y0-2, areaMaxW, areaMaxH, data, max);
+ else if (style==LINE_GRAPH)
+ paintLineGraph(g, x0+3, y0-2, areaMaxW, areaMaxH, data, max);
+ }
+
+ private void paintBarGraph(Graphics g, int ix, int iy, int iw, int ih,
+ int[] data, int max) {
+ final int sCnt=data.length;
+
// draw
if (graphColor != null)
g.setColor(graphColor);
int columnH;
! int columnW;
! int oldx=ix;
! int nx;
for (int i=0; i<sCnt; i++) {
! columnH=data[i]*ih/max;
! nx=ix + iw*(i+1)/sCnt;
! columnW=nx-oldx-1;
! if (columnW < 1)
! columnW=1;
! g.fillRect(oldx, iy-columnH, columnW, columnH);
! oldx=nx;
}
}
! private void paintLineGraph(Graphics g, int ix, int iy, int iw, int ih,
! int[] data, int max) {
final int sCnt=data.length;
! // draw
if (graphColor != null)
g.setColor(graphColor);
! int oldx=ix;
! int oldh=data[0]*ih/max;
for (int i=1; i<sCnt; i++) {
! int nx=ix + (iw-1)*i/(sCnt-1);
! int nh=data[i]*ih/max;
! g.drawLine(oldx, iy-oldh, nx, iy-nh);
! oldx=nx;
! oldh=nh;
}
}
|