KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > jrobin > graph > Stack


1 /* ============================================================
2  * JRobin : Pure java implementation of RRDTool's functionality
3  * ============================================================
4  *
5  * Project Info: http://www.jrobin.org
6  * Project Lead: Sasa Markovic (saxon@jrobin.org)
7  *
8  * Developers: Sasa Markovic (saxon@jrobin.org)
9  * Arne Vandamme (cobralord@jrobin.org)
10  *
11  * (C) Copyright 2003, by Sasa Markovic.
12  *
13  * This library is free software; you can redistribute it and/or modify it under the terms
14  * of the GNU Lesser General Public License as published by the Free Software Foundation;
15  * either version 2.1 of the License, or (at your option) any later version.
16  *
17  * This library is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY;
18  * without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
19  * See the GNU Lesser General Public License for more details.
20  *
21  * You should have received a copy of the GNU Lesser General Public License along with this
22  * library; if not, write to the Free Software Foundation, Inc., 59 Temple Place, Suite 330,
23  * Boston, MA 02111-1307, USA.
24  */

25 package org.jrobin.graph;
26
27 import java.awt.Color JavaDoc;
28
29 import org.jrobin.core.RrdException;
30 import org.jrobin.core.XmlWriter;
31
32 /**
33  * <p>Class used to represent a stacked datasource plotted in a graph. The datasource
34  * will be drawn as a line or an area, depending on PlotDef on which it is stacked.</p>
35  *
36  * @author Arne Vandamme (cobralord@jrobin.org)
37  */

38 class Stack extends PlotDef
39 {
40     // ================================================================
41
// -- Constructors
42
// ================================================================
43
/**
44      * Constructs a <code>Stack</code> PlotDef object based on a datasource name and a graph color.
45      * @param sourceName Name of the graph definition <code>Source</code> containing the datapoints.
46      * @param color Color of the resulting area or line, if no color is specified, the PlotDef will not be drawn.
47      */

48     Stack( String JavaDoc sourceName, Color JavaDoc color )
49     {
50         super( sourceName, color );
51         this.plotType = PlotDef.PLOT_STACK;
52     }
53
54
55     // ================================================================
56
// -- Protected methods
57
// ================================================================
58
/**
59      * Draws the actual PlotDef on the chart, depending on the type of the previous PlotDef,
60      * the Stack will be drawn as a <code>Line</code> or an <code>Area</code>.
61      * @param g ChartGraphics object representing the graphing area.
62      * @param xValues List of relative chart area X positions corresponding to the datapoints.
63      * @param stackValues Datapoint values of previous PlotDefs, used to stack on if necessary.
64      * @param lastPlotType Type of the previous PlotDef, used to determine PlotDef type of a stack.
65      */

66     void draw( ChartGraphics g, int[] xValues, double[] stackValues, int lastPlotType ) throws RrdException
67     {
68         PlotDef stack = null;
69         
70         try
71         {
72             if ( lastPlotType == PlotDef.PLOT_LINE )
73                 stack = new Line( source, values, color, true, visible );
74             else if ( lastPlotType == PlotDef.PLOT_AREA )
75                 stack = new Area( source, values, color, true, visible );
76     
77             stack.draw( g, xValues, stackValues, lastPlotType );
78         }
79         catch (Exception JavaDoc e)
80         {
81             throw new RrdException( "Could not stack source: " + sourceName );
82         }
83     
84     }
85     
86     void exportXmlTemplate( XmlWriter xml, String JavaDoc legend ) {
87         xml.startTag("stack");
88         xml.writeTag("datasource", sourceName);
89         xml.writeTag("color", color);
90         xml.writeTag("legend", legend);
91         xml.closeTag(); // stack
92
}
93 }
94
Popular Tags