📄 rrdgraphdef.java
字号:
/* ============================================================
* JRobin : Pure java implementation of RRDTool's functionality
* ============================================================
*
* Project Info: http://www.jrobin.org
* Project Lead: Sasa Markovic (saxon@jrobin.org)
*
* Developers: Sasa Markovic (saxon@jrobin.org)
* Arne Vandamme (cobralord@jrobin.org)
*
* (C) Copyright 2003, by Sasa Markovic.
*
* This library is free software; you can redistribute it and/or modify it under the terms
* of the GNU Lesser General Public License as published by the Free Software Foundation;
* either version 2.1 of the License, or (at your option) any later version.
*
* This library is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY;
* without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
* See the GNU Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public License along with this
* library; if not, write to the Free Software Foundation, Inc., 59 Temple Place, Suite 330,
* Boston, MA 02111-1307, USA.
*/
package net.jumperz.ext.org.jrobin.graph;
import java.io.*;
import java.awt.Font;
import java.awt.Color;
import java.awt.BasicStroke;
import java.util.*;
import java.text.SimpleDateFormat;
import java.text.DateFormat;
import net.jumperz.ext.org.jrobin.core.RrdException;
import net.jumperz.ext.org.jrobin.core.XmlWriter;
/**
* <p>Class used to collect information for a JRobin graph. JRobin graphs have many
* options and this class has methods and properties to set them.</p>
*
* <p>The JRobin graph package was designed to create graphs that have the same look as the
* RRDTool counter parts. Almost all the same graphing options are available, with some extra's
* like more advanced text alignment and custom point-to-point lines and area's.</p>
*
* <p>To learn more about RDTool's graphs see RRDTool's
* <a href="../../../../man/rrdgraph.html" target="man">rrdgraph man page</a>. This man page
* is important: JRobin uses the same concept of graph sources definition (DEF directives)
* and supports RPN extensions in complex datasource definitions (RRDTool's CDEF directives).</p>
*
* <p><code>RrdGraphDef</code> class does not actually create any graph. It just collects necessary information.
* Graph will be created when you pass <code>RrdGraphDef</code> object to a {@link net.jumperz.ext.org.jrobin.graph.RrdGraph RrdGraph}, either
* by passing it to the constructor or using the <code>setGraphDef()</code> method.</p>
*
* @author Arne Vandamme (arne.vandamme@jrobin.org)
* @author Sasa Markovic (saxon@jrobin.org)
*/
public class RrdGraphDef extends RrdExportDef implements Serializable
{
// ================================================================
// -- Members
// ================================================================
private Title title = null; // no title
private String valueAxisLabel = null; // no vertical label
private TimeAxisLabel timeAxisLabel = null; // no horizontal label
private boolean lazyGeneration = false; // generate only if the file is outdated
private boolean gridX = true; // hide entire X axis grid (default: no)
private boolean gridY = true; // hide entire Y axis grid (default: no)
private boolean minorGridX = true; // hide minor X axis grid (default: no)
private boolean minorGridY = true; // hide minor Y axis grid (default: no)
private boolean majorGridX = true; // hide major X axis grid with labels (default: no)
private boolean majorGridY = true; // hide major Y axis grid with labels (default: no)
private boolean frontGrid = true; // show grid in front of the chart (default: yes)
private boolean antiAliasing = true; // use anti-aliasing for the chart (default: yes)
private boolean showLegend = true; // show legend and comments (default: yes)
private boolean drawSignature = true; // show JRobin url signature (default: yes)
private Color backColor = new Color( 245, 245, 245 ); // variation of light gray
private Color canvasColor = Color.WHITE; // white
private Color borderColor = Color.LIGHT_GRAY; // light gray, only applicable with a borderStroke
private Color normalFontColor = Color.BLACK; // black
private Color titleFontColor = Color.BLACK; // black
private Color majorGridColor = new Color(130,30,30); // variation of dark red
private Color minorGridColor = new Color(140,140,140); // variation of gray
private Color axisColor = new Color(130,30,30); // variation of dark red
private Color arrowColor = Color.RED; // red
private Color frameColor = Color.LIGHT_GRAY; // light gray
private Font titleFont = null; // use default 'grapher' font
private Font normalFont = null; // use default 'grapher' font
private File background = null; // no background image by default
private File overlay = null; // no overlay image by default
private int chart_lpadding = Grapher.CHART_LPADDING; // padding space on the left of the chart area
private int firstDayOfWeek = TimeAxisUnit.MONDAY; // first day of a calendar week, default: monday
private double baseValue = ValueFormatter.DEFAULT_BASE; // unit base value to use (default: 1000)
private int scaleIndex = ValueFormatter.NO_SCALE; // fixed units exponent value to use
private BasicStroke borderStroke = null; // defaults to standard beveled border
private TimeAxisUnit tAxis = null; // custom time axis grid, defaults to no custom
private ValueAxisUnit vAxis = null; // custom value axis grid, defaults to no custom
private GridRange gridRange = null; // custom value range definition, defaults to auto-scale
// -- Non-settable members
private int commentLines = 0; // number of complete lines in the list of comment items
private int commentLineShift = 0; // modifier to add to get minimum one complete line of comments
private ArrayList plotDefs = new ArrayList( 10 ); // holds the list of PlotDefs
private ArrayList comments = new ArrayList( 10 ); // holds the list of comment items
// ================================================================
// -- Constructors
// ================================================================
/**
* Constructs a new default JRobin graph object.
*/
public RrdGraphDef() {
}
/**
* Constructs a new JRobin graph object, with a specified time span to be presented on the graph.
* Using timestamps defined as number of seconds since the epoch.
* @param startTime Starting timestamp in seconds.
* @param endTime Ending timestamp in seconds.
* @throws RrdException Thrown if invalid parameters are supplied.
*/
public RrdGraphDef( long startTime, long endTime ) throws RrdException
{
setTimePeriod( startTime, endTime );
}
/**
* Constructs a new JRobin graph object, with a specified time span to be presented on the graph.
* Time spam defined using <code>java.util.Date</code> objects.
* @param start Starting time.
* @param end Ending time.
* @throws RrdException Thrown in case of invalid parameters.
*/
public RrdGraphDef( Date start, Date end) throws RrdException
{
setTimePeriod( start, end );
}
/**
* Constructs a new JRobin graph object, with a specified time span to be presented on the graph.
* Time spam defined using <code>java.util.GregorianCalendar</code> objects.
* @param start Starting time.
* @param end Ending time.
* @throws RrdException Thrown in case of invalid parameters.
*/
public RrdGraphDef( GregorianCalendar start, GregorianCalendar end ) throws RrdException
{
setTimePeriod( start, end );
}
// ================================================================
// -- Public methods
// ================================================================
/**
* Sets the 'lazy' flag for this GraphDef. This means that upon graph generation and saving to a file,
* JRobin will first check that if that file already exists, the 'last modified' timestamp
* of the file is smaller than 'last update' timestamp of the used datasources. Only if that is indeed
* the case and the image file is outdated, will the graph be generated.
*
* @param lazyGeneration True if the script should only generate.
*/
public void setLazy( boolean lazyGeneration )
{
this.lazyGeneration = lazyGeneration;
}
/**
* Sets graph title.
* @param title Graph title.
*/
public void setTitle( String title ) throws RrdException
{
this.title = new Title( title );
}
/**
* Sets vertical (value) axis label.
* @param label Vertical axis label.
*/
public void setVerticalLabel( String label)
{
this.valueAxisLabel = label;
}
/**
* Sets horizontal (time) axis label.
* <p>
* A horizontal axis label is always center aligned by default, with an extra linefeed to add
* some space before the regular comment lines start. If you wish to remove the extra line of whitespace
* you should specify the alignment in the label using @c, @l or @r. Using the @C, @L or @R markers will
* align the text appropriately, and leave the extra line of whitespace intact.
* </p>
* <p>
* It is possible to use multiple lines and multiple alignment markers for the axis label, in that case
* you should specify alignment for every part of the label to get it to display correctly. When using multiple
* lines, no markers will be added to the end of the last line by default.
* </p>
* @param label Horizontal axis label.
*/
public void setTimeAxisLabel( String label ) throws RrdException
{
if ( label != null )
{
timeAxisLabel = new TimeAxisLabel( label );
commentLines += timeAxisLabel.getLineCount();
commentLineShift = (timeAxisLabel.isCompleteLine() ? 0 : 1);
comments.add( 0, timeAxisLabel );
}
}
/**
* 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 chart area background color. If not set, canvas color defaults to white.
* @param canvasColor Chart area background color.
*/
public void setCanvasColor( Color canvasColor )
{
this.canvasColor = canvasColor;
}
/**
* Specifies the settings of the image border.
* Default is sort of beveled border around the image.
* To disable the image border, just specify a pixel width of 0.
* @param c Bordercolor of the image.
* @param w Pixel width of the image border.
*/
public void setImageBorder( Color c, int w )
{
this.borderStroke = new BasicStroke( w );
if ( c != null )
this.borderColor = c;
}
/**
* Sets the color of the title font used in the graph as a <code>java.awt.Color</code> object.
* Default title font color is black.
* @param c The color to be used.
*/
public void setTitleFontColor( Color c )
{
this.titleFontColor = c;
}
/**
* Sets the color of the default font used in the graph as a <code>java.awt.Color</code> object.
* Default font color is black.
* @param c The color to be used.
*/
public void setDefaultFontColor( Color c )
{
this.normalFontColor = c;
}
/**
* Sets the font to be used for the graph title as a <code>java.awt.Font</code> object.
* Default title font is "Lucida Sans Typewriter", with BOLD attributes and a size of 12 points.
* @param f The Font to be used.
*/
public void setTitleFont( Font f )
{
this.titleFont = f;
}
/**
* Sets the default font to be used in the graph as a <code>java.awt.Font</code> object.
* Default font is "Lucida Sans Typewriter", with PLAIN attributes and a size of 10 points.
* @param f The Font to be used.
*/
public void setDefaultFont( Font f )
{
this.normalFont = f;
}
/**
* Sets the color of the chart's major grid.
* Grid labels have the same color as the default font.
* @param c Color to use.
*/
public void setMajorGridColor( Color c )
{
this.majorGridColor = c;
}
/**
* Determines the color of chart's the minor grid.
* @param c Color to use.
*/
public void setMinorGridColor( Color c )
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -