|
From: <cob...@us...> - 2003-11-20 20:56:39
|
Update of /cvsroot/jrobin/src/org/jrobin/graph
In directory sc8-pr-cvs1:/tmp/cvs-serv26281/src/org/jrobin/graph
Modified Files:
RrdGraph.java Grapher.java
Log Message:
Added option to specify entire image dimensions
Index: RrdGraph.java
===================================================================
RCS file: /cvsroot/jrobin/src/org/jrobin/graph/RrdGraph.java,v
retrieving revision 1.2
retrieving revision 1.3
diff -C2 -d -r1.2 -r1.3
*** RrdGraph.java 7 Nov 2003 09:53:35 -0000 1.2
--- RrdGraph.java 20 Nov 2003 20:56:32 -0000 1.3
***************
*** 65,68 ****
--- 65,69 ----
private int maxPoolSize = DEFAULT_POOLSIZE;
+ private boolean useImageSize = false;
***************
*** 117,120 ****
--- 118,132 ----
// ================================================================
/**
+ * Determines if graph creation should specify dimensions for the chart graphing
+ * are, of for the entire image size. Default is the only the chart graphing
+ * area, this has an impact on the entire image size.
+ * @param specImgSize True if the dimensions for the entire image will be specified, false if only for the chart area.
+ */
+ public void specifyImageSize( boolean specImgSize )
+ {
+ this.useImageSize = specImgSize;
+ }
+
+ /**
* Sets the graph definition to use for the graph construction.
* @param graphDef Graph definition.
***************
*** 378,382 ****
{
// Always regenerate graph
! img = grapher.createImage( width, height, colorType );
return img;
--- 390,397 ----
{
// Always regenerate graph
! if ( useImageSize )
! img = grapher.createImageGlobal( width, height, colorType );
! else
! img = grapher.createImage( width, height, colorType );
return img;
Index: Grapher.java
===================================================================
RCS file: /cvsroot/jrobin/src/org/jrobin/graph/Grapher.java,v
retrieving revision 1.4
retrieving revision 1.5
diff -C2 -d -r1.4 -r1.5
*** Grapher.java 20 Nov 2003 09:28:00 -0000 1.4
--- Grapher.java 20 Nov 2003 20:56:32 -0000 1.5
***************
*** 202,205 ****
--- 202,265 ----
}
+ /**
+ * Creates the actual graph based on the GraphDef definition.
+ * The graph is created as a <code>java.awt.image.BufferedImage</code>.
+ * @param cWidth Width of the entire image in pixels.
+ * @param cHeight Height of the entire image in pixels.
+ * @return The created graph as a BufferedImage.
+ * @throws RrdException Thrown in case of a JRobin specific error.
+ * @throws IOException Thrown in case of a I/O related error.
+ */
+ protected BufferedImage createImageGlobal( int cWidth, int cHeight, int colorType ) throws RrdException, IOException
+ {
+ imgWidth = cWidth;
+ imgHeight = cHeight;
+
+ if ( cWidth > 0 ) numPoints = cWidth;
+
+ // Padding depends on grid visibility
+ chart_lpadding = ( graphDef.showMajorGridY() ? graphDef.getChartLeftPadding() : CHART_LPADDING_NM );
+ chart_bpadding = ( graphDef.showMajorGridX() ? CHART_BPADDING : CHART_BPADDING_NM );
+
+ // Size of all lines below chart
+ commentBlock = 0;
+ if ( graphDef.showLegend() )
+ commentBlock = graphDef.getCommentLineCount() * (nfont_height + LINE_PADDING) - LINE_PADDING;
+
+ // x_offset and y_offset define the starting corner of the actual graph
+ x_offset = LBORDER_SPACE;
+ if ( graphDef.getVerticalLabel() != null )
+ x_offset += nfont_height + LINE_PADDING;
+ chartWidth = imgWidth - x_offset - RBORDER_SPACE - chart_lpadding - CHART_RPADDING;
+
+ y_offset = UBORDER_SPACE;
+ if ( graphDef.getTitle() != null ) // Title *always* gets a extra LF automatically
+ y_offset += ((tfont_height + LINE_PADDING) * graphDef.getTitle().getLineCount() + tfont_height) + LINE_PADDING;
+ chartHeight = imgHeight - commentBlock - y_offset - BBORDER_SPACE - CHART_UPADDING - CHART_BPADDING;
+
+ // Create graphics object
+ BufferedImage bImg = new BufferedImage( imgWidth, imgHeight, colorType );
+ Graphics2D graphics = (Graphics2D) bImg.getGraphics();
+
+ // Do the actual graphing
+ calculateSeries(); // calculate all datasources
+
+ plotImageBackground( graphics ); // draw the image background
+
+ plotChart( graphics ); // draw the actual chart
+
+ plotComments( graphics ); // draw all comment lines
+
+ plotOverlay( graphics ); // draw a possible image overlay
+
+ plotSignature( graphics ); // draw the JRobin signature
+
+
+ // Dispose graphics context
+ graphics.dispose();
+
+ return bImg;
+ }
+
// ================================================================
|