|
From: <cob...@us...> - 2003-10-03 10:10:00
|
Update of /cvsroot/jrobin/src/jrobin/graph
In directory sc8-pr-cvs1:/tmp/cvs-serv5725/src/jrobin/graph
Modified Files:
RrdGraphDef.java Grapher.java ValueAxisUnit.java
Log Message:
GRAPH LIB UPDATES
Add graph coloring options
setChartLeftPadding()
fixed bug with getNiceHigher()
Index: RrdGraphDef.java
===================================================================
RCS file: /cvsroot/jrobin/src/jrobin/graph/RrdGraphDef.java,v
retrieving revision 1.4
retrieving revision 1.5
diff -C2 -d -r1.4 -r1.5
*** RrdGraphDef.java 30 Sep 2003 21:45:21 -0000 1.4
--- RrdGraphDef.java 3 Oct 2003 10:09:52 -0000 1.5
***************
*** 153,163 ****
private BasicStroke borderStroke;
! private Color borderColor;
!
private Range valueRange;
private boolean logarithmic = false;
private double valueStep = 0;
! private Color backColor;
/**
--- 153,172 ----
private BasicStroke borderStroke;
!
private Range valueRange;
private boolean logarithmic = false;
private double valueStep = 0;
! private Color borderColor; // null value is special here
! private Color backColor = new Color( 245, 245, 245 );
! private Color canvasColor = Color.WHITE;
! private Color fontColor = Color.BLACK;
! private Color majorGridColor = new Color(130,30,30);
! private Color minorGridColor = new Color(140,140,140);
! private Color axisColor = new Color(130,30,30);
! private Color arrowColor = Color.RED;
! private Color frameColor = Color.LIGHT_GRAY;
!
! private int chart_lpadding = Grapher.CHART_LPADDING;
/**
***************
*** 550,562 ****
}
/**
! * Sets graph background color. If not set, back color defaults to light gray.
* @param backColor Graph background color.
*/
! public void setBackColor(Color backColor) {
this.backColor = backColor;
}
/**
* Determines if the minor grid for the X axis needs to be drawn.
* @param visible True if minor grid needs to be drawn, false if not.
--- 559,583 ----
}
+ Color getCanvasColor() {
+ return canvasColor;
+ }
+
/**
! * Sets image background color. If not set, back color defaults to a very light gray.
* @param backColor Graph background color.
*/
! public void setBackColor( Color backColor ) {
this.backColor = backColor;
}
/**
+ * Sets graph area background color. If not set, back color defaults to white.
+ * @param backColor Graph area background color.
+ */
+ public void setCanvasColor( Color canvasColor ) {
+ this.canvasColor = canvasColor;
+ }
+
+ /**
* Determines if the minor grid for the X axis needs to be drawn.
* @param visible True if minor grid needs to be drawn, false if not.
***************
*** 688,691 ****
--- 709,796 ----
public boolean getShowLegend() {
return this.showLegend;
+ }
+
+ /**
+ * Sets the color of the font on the graph.
+ * @param c The color to be used.
+ */
+ public void setFontColor( Color c ) {
+ this.fontColor = c;
+ }
+
+ public Color getFontColor() {
+ return this.fontColor;
+ }
+
+ /**
+ * Determines the color of the major grid.
+ * @param c Color to use
+ */
+ public void setMajorGridColor( Color c ) {
+ this.majorGridColor = c;
+ }
+
+ public Color getMajorGridColor() {
+ return majorGridColor;
+ }
+
+ /**
+ * Determines the color of the minor grid.
+ * @param c Color to use
+ */
+ public void setMinorGridColor( Color c ) {
+ this.minorGridColor = c;
+ }
+
+ public Color getMinorGridColor() {
+ return minorGridColor;
+ }
+
+ /**
+ * Determines the color of canvas frame.
+ * @param c Color to use
+ */
+ public void setFrameColor( Color c ) {
+ this.frameColor = c;
+ }
+
+ public Color getFrameColor() {
+ return frameColor;
+ }
+
+ /**
+ * Determines the color of X axis.
+ * @param c Color to use
+ */
+ public void setAxisColor( Color c ) {
+ this.axisColor = c;
+ }
+
+ public Color getAxisColor() {
+ return axisColor;
+ }
+
+ /**
+ * Determines the color of the small axis arrow.
+ * @param c Color to use
+ */
+ public void setArrowColor( Color c ) {
+ this.arrowColor = c;
+ }
+
+ public Color getArrowColor() {
+ return arrowColor;
+ }
+
+ /**
+ * Set the number of pixels on the left of the canvas area ( value marker space )
+ * @param lp Number of pixels used, defaults to 50
+ */
+ public void setChartLeftPadding( int lp ) {
+ this.chart_lpadding = lp;
+ }
+
+ public int getChartLeftPadding() {
+ return this.chart_lpadding;
}
Index: Grapher.java
===================================================================
RCS file: /cvsroot/jrobin/src/jrobin/graph/Grapher.java,v
retrieving revision 1.4
retrieving revision 1.5
diff -C2 -d -r1.4 -r1.5
*** Grapher.java 30 Sep 2003 21:45:21 -0000 1.4
--- Grapher.java 3 Oct 2003 10:09:52 -0000 1.5
***************
*** 25,36 ****
import jrobin.core.RrdException;
- import java.awt.geom.*;
import java.awt.*;
- import java.awt.font.*;
import java.awt.image.*;
import java.io.IOException;
import java.text.SimpleDateFormat;
- import java.util.ArrayList;
class Grapher
--- 25,33 ----
***************
*** 47,56 ****
private static final int RBORDER_SPACE = 10;
! private static final int CHART_UPADDING = 5;
! private static int CHART_BPADDING = 25;
! private static final int CHART_RPADDING = 10;
! private static int CHART_LPADDING = 50;
! private static final int CHART_BPADDING_NM = 10; // No legend makers on the axis
! private static final int CHART_LPADDING_NM = 10;
private static final int LINE_PADDING = 4;
--- 44,53 ----
private static final int RBORDER_SPACE = 10;
! public static final int CHART_UPADDING = 5;
! public static int CHART_BPADDING = 25;
! public static final int CHART_RPADDING = 10;
! public static int CHART_LPADDING = 50; // Default lpadding
! public static final int CHART_BPADDING_NM = 10; // No legend makers on the axis
! public static final int CHART_LPADDING_NM = 10;
private static final int LINE_PADDING = 4;
***************
*** 66,69 ****
--- 63,69 ----
private boolean vLabelCentered = false;
private long vLabelGridWidth = 0;
+
+ private Color fontColor, gridColor, mGridColor, axisColor, frameColor, arrowColor;
+ private int chart_lpadding;
private int imgWidth, imgHeight; // Dimensions of the entire image
***************
*** 82,85 ****
--- 82,92 ----
{
this.graphDef = graphDef;
+ this.fontColor = graphDef.getFontColor();
+ this.gridColor = graphDef.getMinorGridColor();
+ this.mGridColor = graphDef.getMajorGridColor();
+ this.arrowColor = graphDef.getArrowColor();
+ this.axisColor = graphDef.getAxisColor();
+ this.frameColor = graphDef.getFrameColor();
+
StringBuffer buff = new StringBuffer(GRAPH_RESPECT);
//graphDef.comment( buff.reverse().toString() );
***************
*** 108,112 ****
// Padding depends on grid visibility
! CHART_LPADDING = ( graphDef.getMajorGridY() ? Grapher.CHART_LPADDING : CHART_LPADDING_NM );
CHART_BPADDING = ( graphDef.getMajorGridX() ? Grapher.CHART_BPADDING : CHART_BPADDING_NM );
--- 115,119 ----
// Padding depends on grid visibility
! chart_lpadding = ( graphDef.getMajorGridY() ? graphDef.getChartLeftPadding() : CHART_LPADDING_NM );
CHART_BPADDING = ( graphDef.getMajorGridX() ? Grapher.CHART_BPADDING : CHART_BPADDING_NM );
***************
*** 121,125 ****
x_offset = LBORDER_SPACE;
if ( graphDef.getValueAxisLabel() != null ) x_offset += font_height + LINE_PADDING;
! imgWidth = chartWidth + x_offset + RBORDER_SPACE + CHART_LPADDING + CHART_RPADDING;
y_offset = UBORDER_SPACE;
--- 128,132 ----
x_offset = LBORDER_SPACE;
if ( graphDef.getValueAxisLabel() != null ) x_offset += font_height + LINE_PADDING;
! imgWidth = chartWidth + x_offset + RBORDER_SPACE + chart_lpadding + CHART_RPADDING;
y_offset = UBORDER_SPACE;
***************
*** 164,168 ****
g.setFont( SUBTITLE_FONT );
! int lux = x_offset + CHART_LPADDING;
int luy = y_offset + CHART_UPADDING;
--- 171,175 ----
g.setFont( SUBTITLE_FONT );
! int lux = x_offset + chart_lpadding;
int luy = y_offset + CHART_UPADDING;
***************
*** 185,191 ****
int tmpy = luy + chartHeight;
! g.setColor( new Color(130,30,30) );
g.drawLine( lux - 4, tmpy, tmpx + 4, tmpy );
! g.setColor( Color.RED );
g.drawLine( tmpx + 4, tmpy - 3, tmpx + 4, tmpy + 3);
g.drawLine( tmpx + 4, tmpy - 3, tmpx + 9, tmpy);
--- 192,199 ----
int tmpy = luy + chartHeight;
! // Draw axis and arrow
! g.setColor( axisColor );
g.drawLine( lux - 4, tmpy, tmpx + 4, tmpy );
! g.setColor( arrowColor );
g.drawLine( tmpx + 4, tmpy - 3, tmpx + 4, tmpy + 3);
g.drawLine( tmpx + 4, tmpy - 3, tmpx + 9, tmpy);
***************
*** 207,211 ****
if ( majorX && timeList[i].isLabel() )
{
! g.setColor( new Color(130,30,30) );
g.setStroke( dStroke );
g.drawLine( pos, luy, pos, luy + chartHeight);
--- 215,219 ----
if ( majorX && timeList[i].isLabel() )
{
! g.setColor( mGridColor );
g.setStroke( dStroke );
g.drawLine( pos, luy, pos, luy + chartHeight);
***************
*** 219,236 ****
if ( vLabelCentered )
{
! if ( pos + pixWidth <= lux + chartWidth ) {
! g.setColor( Color.BLACK );
! g.drawString( timeList[i].text, pos + 2 + pixWidth/2 - txtDistance, luy + chartHeight + font_height + LINE_PADDING );
! }
}
else if ( (pos - lux > txtDistance + 2) && (pos + txtDistance + 2 < lux + chartWidth) )
! {
! g.setColor( Color.BLACK );
! g.drawString( timeList[i].text, pos - txtDistance, luy + chartHeight + font_height + LINE_PADDING );
! }
}
else if ( minorX )
{
! g.setColor( new Color(140,140,140) );
g.setStroke( dStroke );
g.drawLine( pos, luy, pos, luy + chartHeight);
--- 227,239 ----
if ( vLabelCentered )
{
! if ( pos + pixWidth <= lux + chartWidth )
! drawString( g, timeList[i].text, pos + 2 + pixWidth/2 - txtDistance, luy + chartHeight + font_height + LINE_PADDING );
}
else if ( (pos - lux > txtDistance + 2) && (pos + txtDistance + 2 < lux + chartWidth) )
! drawString( g, timeList[i].text, pos - txtDistance, luy + chartHeight + font_height + LINE_PADDING );
}
else if ( minorX )
{
! g.setColor( gridColor );
g.setStroke( dStroke );
g.drawLine( pos, luy, pos, luy + chartHeight);
***************
*** 252,256 ****
if ( majorY && valueList[i].isLabel() )
{
! g.setColor( new Color(130,30,30) );
g.setStroke( dStroke );
g.drawLine( graphOriginX, graphOriginY - valRel, graphOriginX + chartWidth, graphOriginY - valRel );
--- 255,259 ----
if ( majorY && valueList[i].isLabel() )
{
! g.setColor( mGridColor );
g.setStroke( dStroke );
g.drawLine( graphOriginX, graphOriginY - valRel, graphOriginX + chartWidth, graphOriginY - valRel );
***************
*** 258,267 ****
g.drawLine( graphOriginX - 2, graphOriginY - valRel, graphOriginX + 2, graphOriginY - valRel);
g.drawLine( graphOriginX + chartWidth - 2, graphOriginY - valRel, graphOriginX + chartWidth + 2, graphOriginY - valRel );
! g.setColor( Color.BLACK );
! g.drawString( valueList[i].text, graphOriginX - (valueList[i].text.length() * font_width) - 7, graphOriginY - valRel + font_height/2 - 1 );
}
else if ( minorY )
{
! g.setColor( new Color(140,140,140) );
g.setStroke( dStroke );
g.drawLine( graphOriginX, graphOriginY - valRel, graphOriginX + chartWidth, graphOriginY - valRel );
--- 261,269 ----
g.drawLine( graphOriginX - 2, graphOriginY - valRel, graphOriginX + 2, graphOriginY - valRel);
g.drawLine( graphOriginX + chartWidth - 2, graphOriginY - valRel, graphOriginX + chartWidth + 2, graphOriginY - valRel );
! drawString( g, valueList[i].text, graphOriginX - (valueList[i].text.length() * font_width) - 7, graphOriginY - valRel + font_height/2 - 1 );
}
else if ( minorY )
{
! g.setColor( gridColor );
g.setStroke( dStroke );
g.drawLine( graphOriginX, graphOriginY - valRel, graphOriginX + chartWidth, graphOriginY - valRel );
***************
*** 299,305 ****
g.setColor( ((Legend) cl[i]).getColor() );
g.fillRect( posx, posy - 9, 10, 10 );
! g.setColor( Color.BLACK );
g.drawRect( posx, posy - 9, 10, 10 );
- g.setColor( Color.BLACK );
posx += 10 + (3*font_width - 10);
}
--- 301,306 ----
g.setColor( ((Legend) cl[i]).getColor() );
g.fillRect( posx, posy - 9, 10, 10 );
! g.setColor( fontColor );
g.drawRect( posx, posy - 9, 10, 10 );
posx += 10 + (3*font_width - 10);
}
***************
*** 311,315 ****
comment = comment.substring(lf + 1);
! g.drawString(str, posx, posy);
posy += font_height + LINE_PADDING;
--- 312,316 ----
comment = comment.substring(lf + 1);
! drawString(g, str, posx, posy);
posy += font_height + LINE_PADDING;
***************
*** 324,328 ****
case Comment.ALIGN_CENTER:
posx = imgWidth / 2 - (comment.length()*font_width)/2;
! g.drawString(comment, posx, posy);
posy += font_height + LINE_PADDING;
posx = LBORDER_SPACE;
--- 325,329 ----
case Comment.ALIGN_CENTER:
posx = imgWidth / 2 - (comment.length()*font_width)/2;
! drawString(g, comment, posx, posy);
posy += font_height + LINE_PADDING;
posx = LBORDER_SPACE;
***************
*** 331,335 ****
case Comment.ALIGN_LEFT:
posx = LBORDER_SPACE;
! g.drawString(comment, posx, posy);
posy += font_height + LINE_PADDING;
posx = LBORDER_SPACE;
--- 332,336 ----
case Comment.ALIGN_LEFT:
posx = LBORDER_SPACE;
! drawString(g, comment, posx, posy);
posy += font_height + LINE_PADDING;
posx = LBORDER_SPACE;
***************
*** 338,342 ****
case Comment.ALIGN_RIGHT:
posx = imgWidth - comment.length()*font_width - RBORDER_SPACE;
! g.drawString(comment, posx, posy);
posy += font_height + LINE_PADDING;
posx = LBORDER_SPACE;
--- 339,343 ----
case Comment.ALIGN_RIGHT:
posx = imgWidth - comment.length()*font_width - RBORDER_SPACE;
! drawString(g, comment, posx, posy);
posy += font_height + LINE_PADDING;
posx = LBORDER_SPACE;
***************
*** 345,349 ****
default:
comment = comment + SPACER;
! g.drawString(comment, posx, posy);
posx += font_width * comment.length();
}
--- 346,350 ----
default:
comment = comment + SPACER;
! drawString(g, comment, posx, posy);
posx += font_width * comment.length();
}
***************
*** 359,367 ****
private void plotChart( Graphics2D graphics )
{
! int lux = x_offset + CHART_LPADDING;
int luy = y_offset + CHART_UPADDING;
! graphics.setColor(Color.LIGHT_GRAY);
! graphics.drawRect( lux, luy, chartWidth, chartHeight);
double val;
--- 360,370 ----
private void plotChart( Graphics2D graphics )
{
! int lux = x_offset + chart_lpadding;
int luy = y_offset + CHART_UPADDING;
! graphics.setColor( graphDef.getCanvasColor() );
! graphics.fillRect( lux, luy, chartWidth, chartHeight );
! graphics.setColor( frameColor );
! graphics.drawRect( lux, luy, chartWidth, chartHeight );
double val;
***************
*** 540,543 ****
--- 543,554 ----
}
+ private void drawString( Graphics2D g, String str, int x, int y )
+ {
+ Color oc = g.getColor();
+ g.setColor( fontColor );
+ g.drawString( str, x, y );
+ g.setColor( oc );
+ }
+
/**
* Plots the labels for the vertical axis.
***************
*** 554,558 ****
g.setFont( SUBTITLE_FONT );
g.rotate( -Math.PI/2.0 );
! g.drawString( valueAxisLabel, - y_offset - CHART_UPADDING
- chartHeight / 2
- labelWidth / 2,
--- 565,569 ----
g.setFont( SUBTITLE_FONT );
g.rotate( -Math.PI/2.0 );
! drawString( g, valueAxisLabel, - y_offset - CHART_UPADDING
- chartHeight / 2
- labelWidth / 2,
***************
*** 579,583 ****
g.setColor( Color.BLACK );
g.setFont( TITLE_FONT );
! g.drawString( title, imgWidth / 2 - titleWidth / 2, tf_height + UBORDER_SPACE );
}
}
--- 590,594 ----
g.setColor( Color.BLACK );
g.setFont( TITLE_FONT );
! drawString( g, title, imgWidth / 2 - titleWidth / 2, tf_height + UBORDER_SPACE );
}
}
***************
*** 886,890 ****
if ( !upperFromRange ) upperValue = v.getNiceHigher( upperValue );
if ( !lowerFromRange ) lowerValue = v.getNiceLower( lowerValue );
!
return v.getValueMarkers( lowerValue, upperValue );
}
--- 897,901 ----
if ( !upperFromRange ) upperValue = v.getNiceHigher( upperValue );
if ( !lowerFromRange ) lowerValue = v.getNiceLower( lowerValue );
!
return v.getValueMarkers( lowerValue, upperValue );
}
Index: ValueAxisUnit.java
===================================================================
RCS file: /cvsroot/jrobin/src/jrobin/graph/ValueAxisUnit.java,v
retrieving revision 1.3
retrieving revision 1.4
diff -C2 -d -r1.3 -r1.4
*** ValueAxisUnit.java 30 Sep 2003 21:45:21 -0000 1.3
--- ValueAxisUnit.java 3 Oct 2003 10:09:52 -0000 1.4
***************
*** 170,173 ****
--- 170,174 ----
int valueInt = new Double(value).intValue();
int roundStep = new Double(gridUnit * gridParts).intValue();
+ if ( roundStep == 0 ) roundStep = 1;
int num = valueInt / roundStep;
int mod = valueInt % roundStep;
***************
*** 183,186 ****
--- 184,188 ----
value = ovalue * mGridFactor;
roundStep = new Double(mGridUnit * mGridParts).intValue();
+ if ( roundStep == 0 ) roundStep = 1;
num = valueInt / roundStep;
mod = valueInt % roundStep;
***************
*** 221,224 ****
--- 223,227 ----
int valueInt = new Double(value).intValue();
int roundStep = new Double(gridUnit * gridParts).intValue();
+ if ( roundStep == 0 ) roundStep = 1;
int num = valueInt / roundStep;
int mod = valueInt % roundStep;
***************
*** 229,232 ****
--- 232,236 ----
value = ovalue * mGridFactor;
roundStep = new Double(mGridUnit * mGridParts).intValue();
+ if ( roundStep == 0 ) roundStep = 1;
num = valueInt / roundStep;
mod = valueInt % roundStep;
|