Update of /cvsroot/jrobin/src/org/jrobin/graph In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv19077/org/jrobin/graph Modified Files: Area.java Cdef.java Comment.java CustomArea.java CustomLine.java FetchSource.java Gprint.java GridRange.java Line.java PlotDef.java RrdGraphDef.java RrdGraphDefTemplate.java Stack.java TimeAxisLabel.java TimeAxisUnit.java TimeGrid.java Title.java ValueAxisUnit.java Log Message: XML templates for RrdDef and RrdGraphDef completed. Index: Area.java =================================================================== RCS file: /cvsroot/jrobin/src/org/jrobin/graph/Area.java,v retrieving revision 1.3 retrieving revision 1.4 diff -C2 -d -r1.3 -r1.4 *** Area.java 15 Jan 2004 22:24:30 -0000 1.3 --- Area.java 1 Mar 2004 08:50:25 -0000 1.4 *************** *** 25,28 **** --- 25,30 ---- package org.jrobin.graph; + import org.jrobin.core.XmlWriter; + import java.awt.Color; *************** *** 123,139 **** } ! String getXml( String legend ) { ! StringBuffer xml = new StringBuffer(); ! ! xml.append( "\t\t<area>\n" ); ! xml.append( "\t\t\t<datasource>" + sourceName + "</datasource>\n" ); ! if ( color != null ) ! xml.append( "\t\t\t<color r=\"" + color.getRed() + "\" g=\"" + color.getGreen() + "\" b=\"" + color.getBlue() + "\" />\n" ); ! if ( legend != null ) ! xml.append( "\t\t\t<legend>" + legend + "</legend>\n" ); ! xml.append( "\t\t</area>\n" ); ! ! return xml.toString(); } } --- 125,135 ---- } ! void exportXmlTemplate( XmlWriter xml, String legend ) { ! xml.startTag("area"); ! xml.writeTag("datasource", sourceName); ! xml.writeTag("color", color); ! xml.writeTag("legend", legend); ! xml.closeTag(); // area } } Index: Cdef.java =================================================================== RCS file: /cvsroot/jrobin/src/org/jrobin/graph/Cdef.java,v retrieving revision 1.3 retrieving revision 1.4 diff -C2 -d -r1.3 -r1.4 *** Cdef.java 15 Jan 2004 22:24:30 -0000 1.3 --- Cdef.java 1 Mar 2004 08:50:25 -0000 1.4 *************** *** 29,32 **** --- 29,33 ---- import org.jrobin.core.RrdException; + import org.jrobin.core.XmlWriter; /** *************** *** 221,233 **** } - public String getXml() - { - StringBuffer xml = new StringBuffer( "" ); - - xml.append( "\t\t<cdef name=\"" + this.getName() + "\">" + getRpnString() + "</cdef>\n"); - - return xml.toString(); - } - // ================================================================ // -- Private methods --- 222,225 ---- *************** *** 250,252 **** --- 242,251 ---- } } + + void exportXml(XmlWriter xml) { + xml.startTag("def"); + xml.writeTag("name", getName()); + xml.writeTag("rpn", getRpnString()); + xml.closeTag(); // def + } } Index: Comment.java =================================================================== RCS file: /cvsroot/jrobin/src/org/jrobin/graph/Comment.java,v retrieving revision 1.2 retrieving revision 1.3 diff -C2 -d -r1.2 -r1.3 *** Comment.java 15 Jan 2004 22:24:30 -0000 1.2 --- Comment.java 1 Mar 2004 08:50:25 -0000 1.3 *************** *** 28,31 **** --- 28,32 ---- import org.jrobin.core.RrdException; + import org.jrobin.core.XmlWriter; /** *************** *** 249,260 **** return trimString; } ! ! String getXml() ! { ! StringBuffer xml = new StringBuffer(); ! ! xml.append( "\t\t<comment>" + text + "</comment>\n" ); ! ! return xml.toString(); } } --- 250,260 ---- return trimString; } ! ! String getText() { ! return text; ! } ! ! void exportXmlTemplate(XmlWriter xml) { ! xml.writeTag("comment", getText()); } } Index: CustomArea.java =================================================================== RCS file: /cvsroot/jrobin/src/org/jrobin/graph/CustomArea.java,v retrieving revision 1.2 retrieving revision 1.3 diff -C2 -d -r1.2 -r1.3 *** CustomArea.java 15 Jan 2004 22:24:30 -0000 1.2 --- CustomArea.java 1 Mar 2004 08:50:25 -0000 1.3 *************** *** 29,32 **** --- 29,33 ---- import org.jrobin.core.RrdException; + import org.jrobin.core.XmlWriter; /** *************** *** 169,185 **** } ! String getXml( String legend ) ! { ! StringBuffer xml = new StringBuffer(); ! ! xml.append( "\t\t<custom-area>\n" ); ! xml.append( "\t\t\t<datasource>" + sourceName + "</datasource>\n" ); ! if ( color != null ) ! xml.append( "\t\t\t<color r=\"" + color.getRed() + "\" g=\"" + color.getGreen() + "\" b=\"" + color.getBlue() + "\" />\n" ); ! if ( legend != null ) ! xml.append( "\t\t\t<legend>" + legend + "</legend>\n" ); ! xml.append( "\t\t</custom-area>\n" ); ! ! return xml.toString(); } } --- 170,182 ---- } ! void exportXmlTemplate( XmlWriter xml, String legend ) { ! xml.startTag("area"); ! xml.writeTag("time1", xVal1); ! xml.writeTag("value1", yVal1); ! xml.writeTag("time2", xVal2); ! xml.writeTag("value2", yVal2); ! xml.writeTag("color", color); ! xml.writeTag("legend", legend); ! xml.closeTag(); //area } } Index: CustomLine.java =================================================================== RCS file: /cvsroot/jrobin/src/org/jrobin/graph/CustomLine.java,v retrieving revision 1.1 retrieving revision 1.2 diff -C2 -d -r1.1 -r1.2 *** CustomLine.java 7 Nov 2003 08:23:19 -0000 1.1 --- CustomLine.java 1 Mar 2004 08:50:25 -0000 1.2 *************** *** 30,33 **** --- 30,34 ---- import org.jrobin.core.RrdException; + import org.jrobin.core.XmlWriter; /** *************** *** 206,208 **** --- 207,242 ---- void setSource( Source[] sources, HashMap sourceIndex ) throws RrdException { } + + void exportXmlTemplate( XmlWriter xml, String legend ) { + if(yVal1 == yVal2 && xVal1 != xVal2) { + // hrule + xml.startTag("hrule"); + xml.writeTag("value", yVal1); + xml.writeTag("color", color); + xml.writeTag("legend", legend); + xml.writeTag("width", lineWidth); + xml.closeTag(); // hrule + } + else if(yVal1 != yVal2 && xVal1 == xVal2) { + // vrule + xml.startTag("vrule"); + xml.writeTag("time", xVal1); + xml.writeTag("color", color); + xml.writeTag("legend", legend); + xml.writeTag("width", lineWidth); + xml.closeTag(); // vrule + } + else if(yVal1 != yVal2 && xVal1 != xVal2) { + // general line + xml.startTag("line"); + xml.writeTag("time1", xVal1); + xml.writeTag("value1", yVal1); + xml.writeTag("time2", xVal2); + xml.writeTag("value2", yVal2); + xml.writeTag("color", color); + xml.writeTag("legend", legend); + xml.writeTag("width", lineWidth); + xml.closeTag(); //line + } + } } Index: FetchSource.java =================================================================== RCS file: /cvsroot/jrobin/src/org/jrobin/graph/FetchSource.java,v retrieving revision 1.2 retrieving revision 1.3 diff -C2 -d -r1.2 -r1.3 *** FetchSource.java 15 Jan 2004 22:24:30 -0000 1.2 --- FetchSource.java 1 Mar 2004 08:50:25 -0000 1.3 *************** *** 28,35 **** import java.io.IOException; ! import org.jrobin.core.RrdDb; ! import org.jrobin.core.FetchData; ! import org.jrobin.core.FetchRequest; ! import org.jrobin.core.RrdException; /** --- 28,32 ---- import java.io.IOException; ! import org.jrobin.core.*; /** *************** *** 92,116 **** } - public String getXml() - { - StringBuffer xml = new StringBuffer( "" ); - - for ( int i = 0; i < datasources.length; i++ ) { - for ( int j = 0; j < datasources[i].size(); j++ ) { - String[] pair = (String[]) datasources[i].elementAt(j); - - xml.append( "\t\t<def name=\"" + pair[1] + "\">\n" ); - xml.append( "\t\t\t<file>" + rrdFile + "</file>\n" ); - xml.append( "\t\t\t<ds-name>" + pair[0] + "</ds-name>\n" ); - xml.append( "\t\t\t<cf>" + cfNames[i] + "</cf>\n" ); - xml.append( "\t\t</def>\n" ); - //<file>test.rrd</file> - //<ds-name>ifInOctets</ds-name> - //<cf>AVERAGE</cf> - } - } - return xml.toString(); - } - // ================================================================ // -- Protected methods --- 89,92 ---- *************** *** 188,191 **** protected String getRrdFile() { return rrdFile; ! } } --- 164,181 ---- protected String getRrdFile() { return rrdFile; ! } ! ! public void exportXml(XmlWriter xml) { ! for ( int i = 0; i < datasources.length; i++ ) { ! for ( int j = 0; j < datasources[i].size(); j++ ) { ! String[] pair = (String[]) datasources[i].elementAt(j); ! xml.startTag("def"); ! xml.writeTag("name", pair[1]); ! xml.writeTag("rrd", rrdFile); ! xml.writeTag("source", pair[0]); ! xml.writeTag("cf", cfNames[i]); ! xml.closeTag(); // def ! } ! } ! } } Index: Gprint.java =================================================================== RCS file: /cvsroot/jrobin/src/org/jrobin/graph/Gprint.java,v retrieving revision 1.2 retrieving revision 1.3 diff -C2 -d -r1.2 -r1.3 *** Gprint.java 15 Jan 2004 22:24:30 -0000 1.2 --- Gprint.java 1 Mar 2004 08:50:25 -0000 1.3 *************** *** 30,33 **** --- 30,34 ---- import org.jrobin.core.RrdException; + import org.jrobin.core.XmlWriter; /** *************** *** 175,193 **** } ! /** ! * ! */ ! String getXml() ! { ! StringBuffer xml = new StringBuffer(); ! ! xml.append( "\t\t<gprint>\n" ); ! xml.append( "\t\t\t<datasource>" + sourceName + "</datasource>\n" ); ! xml.append( "\t\t\t<cf>" + Source.aggregates[aggregate] + "</cf>\n" ); ! xml.append( "\t\t\t<text>" + text + "</text>\n" ); ! xml.append( "\t\t</gprint>\n" ); ! ! return xml.toString(); } ! } --- 176,186 ---- } ! void exportXmlTemplate(XmlWriter xml) { ! xml.startTag("gprint"); ! xml.writeTag("datasource", sourceName); ! xml.writeTag("cf", Source.aggregates[aggregate]); ! xml.writeTag("format", text); ! xml.closeTag(); // gprint } ! } Index: GridRange.java =================================================================== RCS file: /cvsroot/jrobin/src/org/jrobin/graph/GridRange.java,v retrieving revision 1.1 retrieving revision 1.2 diff -C2 -d -r1.1 -r1.2 *** GridRange.java 7 Nov 2003 08:23:19 -0000 1.1 --- GridRange.java 1 Mar 2004 08:50:25 -0000 1.2 *************** *** 25,28 **** --- 25,30 ---- package org.jrobin.graph; + import org.jrobin.core.XmlWriter; + /** * <p>Represents Y grid specifications for the chart area.</p> *************** *** 87,89 **** --- 89,99 ---- return rigid; } + + void exportXmlTemplate(XmlWriter xml) { + xml.startTag("grid_range"); + xml.writeTag("lower", getLowerValue()); + xml.writeTag("upper", getUpperValue()); + xml.writeTag("rigid", isRigid()); + xml.closeTag(); // grid_range + } } Index: Line.java =================================================================== RCS file: /cvsroot/jrobin/src/org/jrobin/graph/Line.java,v retrieving revision 1.3 retrieving revision 1.4 diff -C2 -d -r1.3 -r1.4 *** Line.java 15 Jan 2004 22:24:30 -0000 1.3 --- Line.java 1 Mar 2004 08:50:25 -0000 1.4 *************** *** 29,32 **** --- 29,33 ---- import org.jrobin.core.RrdException; + import org.jrobin.core.XmlWriter; /** *************** *** 132,149 **** } ! String getXml( String legend ) { ! StringBuffer xml = new StringBuffer(); ! ! xml.append( "\t\t<line>\n" ); ! xml.append( "\t\t\t<datasource>" + sourceName + "</datasource>\n" ); ! if ( color != null ) ! xml.append( "\t\t\t<color r=\"" + color.getRed() + "\" g=\"" + color.getGreen() + "\" b=\"" + color.getBlue() + "\" />\n" ); ! if ( legend != null ) ! xml.append( "\t\t\t<legend>" + legend + "</legend>\n" ); ! xml.append( "\t\t\t<width>" + lineWidth + "</width>\n" ); ! xml.append( "\t\t</line>\n" ); ! ! return xml.toString(); } } --- 133,144 ---- } ! void exportXmlTemplate( XmlWriter xml, String legend ) { ! xml.startTag("line"); ! xml.writeTag("datasource", sourceName); ! xml.writeTag("color", color); ! xml.writeTag("legend", legend); ! xml.writeTag("width", lineWidth); ! xml.closeTag(); // area } } Index: PlotDef.java =================================================================== RCS file: /cvsroot/jrobin/src/org/jrobin/graph/PlotDef.java,v retrieving revision 1.2 retrieving revision 1.3 diff -C2 -d -r1.2 -r1.3 *** PlotDef.java 15 Jan 2004 22:24:30 -0000 1.2 --- PlotDef.java 1 Mar 2004 08:50:25 -0000 1.3 *************** *** 29,32 **** --- 29,33 ---- import org.jrobin.core.RrdException; + import org.jrobin.core.XmlWriter; /** *************** *** 129,138 **** abstract void draw( ChartGraphics g, int[] xValues, int[] stackValues, int lastPlotType ) throws RrdException; - /** - * Abstract getXml method, must be implemented in all child classes. - * This method is reponsible for returning a corresponding JRobin XML string for the PlotDef. - */ - abstract String getXml( String legend ); - Source getSource() { return source; --- 130,133 ---- *************** *** 150,152 **** --- 145,151 ---- return color; } + + void exportXmlTemplate(XmlWriter xml, String legend) { + + } } Index: RrdGraphDef.java =================================================================== RCS file: /cvsroot/jrobin/src/org/jrobin/graph/RrdGraphDef.java,v retrieving revision 1.7 retrieving revision 1.8 diff -C2 -d -r1.7 -r1.8 *** RrdGraphDef.java 26 Feb 2004 10:33:30 -0000 1.7 --- RrdGraphDef.java 1 Mar 2004 08:50:25 -0000 1.8 *************** *** 25,30 **** package org.jrobin.graph; ! import java.io.File; ! import java.io.Serializable; import java.awt.Font; import java.awt.Color; --- 25,29 ---- package org.jrobin.graph; ! import java.io.*; import java.awt.Font; import java.awt.Color; *************** *** 39,42 **** --- 38,42 ---- import org.jrobin.core.Util; import org.jrobin.core.RrdException; + import org.jrobin.core.XmlWriter; /** *************** *** 543,546 **** --- 543,550 ---- } + int getUnitsExponent() { + return (6 - scaleIndex) * 3; + } + /** * Sets value range that will be presented in the graph. If not set, graph limits will be autoscaled. *************** *** 899,1007 **** addComment( new Gprint(sourceName, consolFun, format) ); } ! ! /* ! public String getJRobinXml() ! { ! StringBuffer xml = new StringBuffer( "" ); ! ! // -- Create the general block ! xml.append( "\t<general>\n" ); ! ! // Time period ! xml.append( "\t\t<period>\n" ); ! xml.append( "\t\t\t<start>" + startTime + "</start>\n" ); ! xml.append( "\t\t\t<end>" + endTime + "</end>\n" ); ! xml.append( "\t\t</period>\n" ); ! ! // Labels ! if ( title != null || valueAxisLabel != null || timeAxisLabel != null ) ! { ! xml.append( "\t\t<labels>\n" ); ! if ( title != null ) ! xml.append( "\t\t\t<title>" + title.text + "</title>\n" ); ! if ( valueAxisLabel != null ) ! xml.append( "\t\t\t<vertical-label>" + valueAxisLabel + "</vertical-label>\n" ); ! if ( timeAxisLabel != null ) ! xml.append( "\t\t\t<horizontal-label>" + timeAxisLabel.text + "</horizontal-label>\n" ); ! xml.append( "\t\t</labels>\n" ); } ! ! // General colors ! xml.append( "\t\t<colors>\n" ); ! xml.append( "\t\t\t<background r=\"" + backColor.getRed() + "\" g=\"" + backColor.getGreen() + "\" b=\"" + backColor.getBlue() + "\" />\n" ); ! xml.append( "\t\t\t<canvas r=\"" + canvasColor.getRed() + "\" g=\"" + canvasColor.getGreen() + "\" b=\"" + canvasColor.getBlue() + "\" />\n" ); ! xml.append( "\t\t</colors>\n" ); ! ! // General data information ! ! // General visual options ! xml.append( "\t\t<visual>\n" ); ! xml.append( "\t\t\t<show-legend>" + (showLegend ? "yes" : "no") + "</show-legend>\n" ); ! if ( background != null ) ! xml.append( "\t\t\t<background-image>" + background.getAbsolutePath() + "</background-image>\n" ); ! if ( overlay != null ) ! xml.append( "\t\t\t<overlay-image>" + overlay.getAbsolutePath() + "</overlay-image>\n" ); ! if ( borderStroke != null ) ! { ! xml.append( "\t\t\t<image-border>\n" ); ! xml.append( "\t\t\t\t<width>" + borderStroke.getLineWidth() + "</width>\n" ); ! xml.append( "\t\t\t\t<color r=\"" + borderColor.getRed() + "\" g=\"" + borderColor.getGreen() + "\" b=\"" + borderColor.getBlue() + "\" />\n" ); ! xml.append( "\t\t\t</image-border>\n" ); } ! if ( gridRange != null ) ! { ! xml.append( "\t\t\t<grid>\n" ); ! xml.append( "\t\t\t\t<lower>" + gridRange.getLowerValue() + "</lower>\n" ); ! xml.append( "\t\t\t\t<upper>" + gridRange.getUpperValue() + "</upper>\n" ); ! xml.append( "\t\t\t\t<rigid>" + (gridRange.isRigid() ? "yes" : "no") + "</rigid>\n" ); ! xml.append( "\t\t\t</grid>\n" ); } ! //xml.append( "\t\t\t<canvas r=\"" + canvasColor.getRed() + "\" g=\"" + canvasColor.getGreen() + "\" b=\"" + canvasColor.getBlue() + "\" />\n" ); ! xml.append( "\t\t</visual>\n" ); ! ! xml.append( "\t</general>\n" ); ! // ------------------------------------------------------------- ! ! ! // -- Create the datasources block ! xml.append( "\t<datasources>\n" ); ! ! // Add all defs Iterator fsIterator = fetchSources.values().iterator(); ! while ( fsIterator.hasNext() ) ! xml.append( ((FetchSource) fsIterator.next()).getXml() ); ! ! // Add all cdefs ! for ( int i = 0; i < cdefList.size(); i++ ) ! xml.append( ((Cdef) cdefList.elementAt(i)).getXml() ); ! ! xml.append( "\t</datasources>\n" ); ! // ------------------------------------------------------------- ! ! ! // -- Create the graphing block ! // Run through the comments, if its a legend or nolegend, get the plotdef xml ! // else get the comment or gprint xml ! xml.append( "\t<graphing>\n" ); for ( int i = 0; i < comments.size(); i++ ) { Comment cmt = (Comment) comments.elementAt(i); ! if ( cmt.commentType == Comment.CMT_LEGEND || cmt.commentType == Comment.CMT_NOLEGEND ) { PlotDef pDef = (PlotDef) plotDefs.elementAt( ((Legend) cmt).getPlofDefIndex() ); ! xml.append( pDef.getXml(cmt.text) ); } - else - xml.append( cmt.getXml() ); } ! xml.append( "\t</graphing>\n" ); ! // ------------------------------------------------------------- ! ! xml.insert( 0, "<jrobin-graph>\n"); ! xml.append( "</jrobin-graph>\n" ); ! ! return xml.toString(); } ! */ // ================================================================ // -- Protected (package) methods --- 903,1040 ---- addComment( new Gprint(sourceName, consolFun, format) ); } ! ! /** ! * Exports RrdGraphDef (graph definition) object in XML format to output stream. ! * Generated code can be parsed with {@link RrdGraphDefTemplate} class. ! * @param stream Output stream to send XML code to ! */ ! public void exportXmlTemplate(OutputStream stream) { ! XmlWriter xml = new XmlWriter(stream); ! xml.startTag("rrd_graph_def"); ! // SPAN ! xml.startTag("span"); ! xml.writeTag("start", startTime); ! xml.writeTag("end", endTime); ! xml.closeTag(); // span ! // OPTIONS ! xml.startTag("options"); ! xml.writeTag("anti_aliasing", antiAliasing); ! xml.writeTag("arrow_color", arrowColor); ! xml.writeTag("axis_color", axisColor); ! xml.writeTag("back_color", backColor); ! if(background != null) { ! xml.writeTag("background", background); } ! xml.writeTag("base_value", baseValue); ! xml.writeTag("canvas", canvasColor); ! xml.writeTag("left_padding", chart_lpadding); ! if(normalFont != null) { ! xml.writeTag("default_font", normalFont); } ! xml.writeTag("default_font_color", normalFontColor); ! xml.writeTag("frame_color", frameColor); ! xml.writeTag("front_grid", frontGrid); ! if(gridRange != null) { ! gridRange.exportXmlTemplate(xml); } ! xml.writeTag("grid_x", gridX); ! xml.writeTag("grid_y", gridY); ! if(borderStroke != null) { ! xml.startTag("border"); ! xml.writeTag("color", borderColor); ! xml.writeTag("width", (int)borderStroke.getLineWidth()); ! xml.closeTag(); // border ! } ! xml.writeTag("major_grid_color", majorGridColor); ! xml.writeTag("major_grid_x", majorGridX); ! xml.writeTag("major_grid_y", majorGridY); ! xml.writeTag("minor_grid_color", minorGridColor); ! xml.writeTag("minor_grid_x", minorGridX); ! xml.writeTag("minor_grid_y", minorGridY); ! if(overlay != null) { ! xml.writeTag("overlay", overlay); ! } ! xml.writeTag("show_legend", showLegend); ! xml.writeTag("show_signature", drawSignature); ! if(tAxis != null) { ! tAxis.exportXmlTemplate(xml); ! } ! if(timeAxisLabel != null) { ! timeAxisLabel.exportXmlTemplate(xml); ! } ! if(title != null) { ! title.exportXmlTemplate(xml); ! } ! if(titleFont != null) { ! xml.writeTag("title_font", titleFont); ! } ! xml.writeTag("title_font_color", titleFontColor); ! if(scaleIndex != ValueFormatter.NO_SCALE) { ! xml.writeTag("units_exponent", getUnitsExponent()); ! } ! if(vAxis != null) { ! vAxis.exportXmlTemplate(xml); ! } ! if(valueAxisLabel != null) { ! xml.writeTag("vertical_label", valueAxisLabel); ! } ! xml.closeTag(); // options ! // DATASOURCES ! xml.startTag("datasources"); ! // defs Iterator fsIterator = fetchSources.values().iterator(); ! while (fsIterator.hasNext()) { ! FetchSource fs = (FetchSource) fsIterator.next(); ! fs.exportXml(xml); ! } ! // cdefs ! for (int i = 0; i < cdefList.size(); i++ ) { ! Cdef cdef = (Cdef) cdefList.elementAt(i); ! cdef.exportXml(xml); ! } ! xml.closeTag(); // datasources ! xml.startTag("graph"); for ( int i = 0; i < comments.size(); i++ ) { Comment cmt = (Comment) comments.elementAt(i); ! if ( cmt.commentType == Comment.CMT_LEGEND || cmt.commentType == Comment.CMT_NOLEGEND) { PlotDef pDef = (PlotDef) plotDefs.elementAt( ((Legend) cmt).getPlofDefIndex() ); ! pDef.exportXmlTemplate(xml, cmt.text); ! } ! else if(cmt instanceof TimeAxisLabel) { ! // NOP: already exported in the options section ! } ! else { ! cmt.exportXmlTemplate(xml); } } ! xml.closeTag(); // graph ! xml.closeTag(); // rrd_graph_def ! xml.flush(); } ! ! /** ! * Exports RrdGraphDef (graph definition) object in XML format to string. ! * Generated code can be parsed with {@link RrdGraphDefTemplate} class. ! * @return String representing graph definition in XML format ! */ ! public String exportXmlTemplate() { ! ByteArrayOutputStream outputStream = new ByteArrayOutputStream(); ! exportXmlTemplate(outputStream); ! return outputStream.toString(); ! } ! ! /** ! * Exports RrdGraphDef (graph definition) object in XML format to file. ! * Generated code can be parsed with {@link RrdGraphDefTemplate} class. ! * @param filePath destination file ! */ ! public void exportXmlTemplate(String filePath) throws IOException { ! FileOutputStream outputStream = new FileOutputStream(filePath, false); ! exportXmlTemplate(outputStream); ! outputStream.close(); ! } ! // ================================================================ // -- Protected (package) methods Index: RrdGraphDefTemplate.java =================================================================== RCS file: /cvsroot/jrobin/src/org/jrobin/graph/RrdGraphDefTemplate.java,v retrieving revision 1.2 retrieving revision 1.3 diff -C2 -d -r1.2 -r1.3 *** RrdGraphDefTemplate.java 26 Feb 2004 10:33:30 -0000 1.2 --- RrdGraphDefTemplate.java 1 Mar 2004 08:50:25 -0000 1.3 *************** *** 555,559 **** else if(option.equals("default_font")) { Font f = resolveFont(optionNode); ! rrdGraphDef.setTitleFont(f); } // DEFAULT FONT COLOR --- 555,559 ---- else if(option.equals("default_font")) { Font f = resolveFont(optionNode); ! rrdGraphDef.setDefaultFont(f); } // DEFAULT FONT COLOR *************** *** 754,761 **** public static void main(String[] args) throws IOException, RrdException { ! File f = new File("work/test2.xml"); ! RrdGraphDefTemplate t = new RrdGraphDefTemplate(f); ! t.setVariable("date", new Date()); ! t.getRrdGraphDef(); } } --- 754,762 ---- public static void main(String[] args) throws IOException, RrdException { ! File fileTemplate = new File("work/test2.xml"); ! RrdGraphDefTemplate template = new RrdGraphDefTemplate(fileTemplate); ! String stringTemplate = template.getRrdGraphDef().exportXmlTemplate(); ! template = new RrdGraphDefTemplate(stringTemplate); ! System.out.println(template.getRrdGraphDef().exportXmlTemplate()); } } Index: Stack.java =================================================================== RCS file: /cvsroot/jrobin/src/org/jrobin/graph/Stack.java,v retrieving revision 1.2 retrieving revision 1.3 diff -C2 -d -r1.2 -r1.3 *** Stack.java 15 Jan 2004 22:24:30 -0000 1.2 --- Stack.java 1 Mar 2004 08:50:25 -0000 1.3 *************** *** 28,31 **** --- 28,32 ---- import org.jrobin.core.RrdException; + import org.jrobin.core.XmlWriter; /** *************** *** 83,102 **** } ! /** ! * ! */ ! String getXml( String legend ) ! { ! StringBuffer xml = new StringBuffer(); ! ! xml.append( "\t\t<stack>\n" ); ! xml.append( "\t\t\t<datasource>" + sourceName + "</datasource>\n" ); ! if ( color != null ) ! xml.append( "\t\t\t<color r=\"" + color.getRed() + "\" g=\"" + color.getGreen() + "\" b=\"" + color.getBlue() + "\" />\n" ); ! if ( legend != null ) ! xml.append( "\t\t\t<legend>" + legend + "</legend>\n" ); ! xml.append( "\t\t</stack>\n" ); ! ! return xml.toString(); } } --- 84,93 ---- } ! void exportXmlTemplate( XmlWriter xml, String legend ) { ! xml.startTag("stack"); ! xml.writeTag("datasource", sourceName); ! xml.writeTag("color", color); ! xml.writeTag("legend", legend); ! xml.closeTag(); // stack } } Index: TimeAxisLabel.java =================================================================== RCS file: /cvsroot/jrobin/src/org/jrobin/graph/TimeAxisLabel.java,v retrieving revision 1.2 retrieving revision 1.3 diff -C2 -d -r1.2 -r1.3 *** TimeAxisLabel.java 15 Jan 2004 22:24:30 -0000 1.2 --- TimeAxisLabel.java 1 Mar 2004 08:50:25 -0000 1.3 *************** *** 26,29 **** --- 26,30 ---- import org.jrobin.core.RrdException; + import org.jrobin.core.XmlWriter; /** *************** *** 60,66 **** } } ! ! String getXml() { ! return ""; } } --- 61,68 ---- } } ! ! void exportXmlTemplate(XmlWriter xml) { ! xml.writeTag("time_axis_label", getText()); } + } Index: TimeAxisUnit.java =================================================================== RCS file: /cvsroot/jrobin/src/org/jrobin/graph/TimeAxisUnit.java,v retrieving revision 1.3 retrieving revision 1.4 diff -C2 -d -r1.3 -r1.4 *** TimeAxisUnit.java 19 Nov 2003 11:37:40 -0000 1.3 --- TimeAxisUnit.java 1 Mar 2004 08:50:25 -0000 1.4 *************** *** 22,25 **** --- 22,27 ---- package org.jrobin.graph; + import org.jrobin.core.XmlWriter; + import java.util.*; import java.text.SimpleDateFormat; *************** *** 71,82 **** /** constant for years */ public static final int YEAR = 6; ! ! private int gridTime = HOUR; // minor grid ! private int gridUnits = 1; ! private int mGridTime = HOUR; // major grid ! private int mGridUnits = 6; private boolean centerLabels = false; ! private SimpleDateFormat df = new SimpleDateFormat("HH:mm", Locale.ENGLISH ); --- 73,88 ---- /** constant for years */ public static final int YEAR = 6; ! ! private static final String[] UNIT_NAMES = { ! "SECOND", "MINUTE", "HOUR", "DAY", "WEEK", "MONTH", "YEAR" ! }; ! ! private int minGridTimeUnit = HOUR; // minor grid ! private int minGridUnitSteps = 1; ! private int majGridTimeUnit = HOUR; // major grid ! private int majGridUnitSteps = 6; private boolean centerLabels = false; ! private SimpleDateFormat dateFormat = new SimpleDateFormat("HH:mm", Locale.ENGLISH ); *************** *** 93,111 **** * WEEK, MONTH</i> and <i>YEAR</i>. * ! * @param gridTime Time unit for the minor grid lines. ! * @param gridUnits Time unit steps for the minor grid lines. ! * @param mGridTime Time unit for the major grid lines. ! * @param mGridUnits Time unit steps for the major grid lines. ! * @param df Format to use to convert the specific time into a label string. * @param centerLabels True if labels (major grid) should be centered between two major grid lines. */ ! TimeAxisUnit( int gridTime, int gridUnits, int mGridTime, int mGridUnits, SimpleDateFormat df, boolean centerLabels ) { ! this.gridTime = gridTime; ! this.gridUnits = gridUnits; ! this.mGridTime = mGridTime; ! this.mGridUnits = mGridUnits; ! this.df = new SimpleDateFormat( df.toPattern(), Locale.ENGLISH ); ! this.centerLabels = centerLabels; } --- 99,119 ---- * WEEK, MONTH</i> and <i>YEAR</i>. * ! * @param minGridTimeUnit Time unit for the minor grid lines. ! * @param minGridUnitSteps Time unit steps for the minor grid lines. ! * @param majGridTimeUnit Time unit for the major grid lines. ! * @param majGridUnitSteps Time unit steps for the major grid lines. ! * @param dateFormat Format to use to convert the specific time into a label string. * @param centerLabels True if labels (major grid) should be centered between two major grid lines. */ ! TimeAxisUnit( int minGridTimeUnit, int minGridUnitSteps, ! int majGridTimeUnit, int majGridUnitSteps, ! SimpleDateFormat dateFormat, boolean centerLabels ) { ! this.minGridTimeUnit = minGridTimeUnit; ! this.minGridUnitSteps = minGridUnitSteps; ! this.majGridTimeUnit = majGridTimeUnit; ! this.majGridUnitSteps = majGridUnitSteps; ! this.dateFormat = new SimpleDateFormat( dateFormat.toPattern(), Locale.ENGLISH ); ! this.centerLabels = centerLabels; } *************** *** 130,135 **** // Set the start calculation point for the grids ! setStartPoint(cMaj, mGridTime, start); ! setStartPoint(cMin, gridTime, start); // Find first visible grid point --- 138,143 ---- // Set the start calculation point for the grids ! setStartPoint(cMaj, majGridTimeUnit, start); ! setStartPoint(cMin, minGridTimeUnit, start); // Find first visible grid point *************** *** 138,144 **** while ( majPoint < start ) ! majPoint = getNextPoint(cMaj, mGridTime, mGridUnits); while ( minPoint < start ) ! minPoint = getNextPoint(cMin, gridTime, gridUnits); ArrayList markerList = new ArrayList(); --- 146,152 ---- while ( majPoint < start ) ! majPoint = getNextPoint(cMaj, majGridTimeUnit, majGridUnitSteps); while ( minPoint < start ) ! minPoint = getNextPoint(cMin, minGridTimeUnit, minGridUnitSteps); ArrayList markerList = new ArrayList(); *************** *** 155,170 **** { markerList.add( new TimeMarker( minPoint, "", false ) ); ! minPoint = getNextPoint( cMin, gridTime, gridUnits ); } else if ( minPoint == majPoint ) // Special case, but will happen most of the time { ! markerList.add( new TimeMarker( majPoint, df.format(cMaj.getTime()), true ) ); ! majPoint = getNextPoint( cMaj, mGridTime, mGridUnits ); ! minPoint = getNextPoint( cMin, gridTime, gridUnits ); } else { ! markerList.add( new TimeMarker( majPoint, df.format(cMaj.getTime()), true ) ); ! majPoint = getNextPoint( cMaj, mGridTime, mGridUnits ); } } --- 163,178 ---- { markerList.add( new TimeMarker( minPoint, "", false ) ); ! minPoint = getNextPoint( cMin, minGridTimeUnit, minGridUnitSteps ); } else if ( minPoint == majPoint ) // Special case, but will happen most of the time { ! markerList.add( new TimeMarker( majPoint, dateFormat.format(cMaj.getTime()), true ) ); ! majPoint = getNextPoint( cMaj, majGridTimeUnit, majGridUnitSteps ); ! minPoint = getNextPoint( cMin, minGridTimeUnit, minGridUnitSteps ); } else { ! markerList.add( new TimeMarker( majPoint, dateFormat.format(cMaj.getTime()), true ) ); ! majPoint = getNextPoint( cMaj, majGridTimeUnit, majGridUnitSteps ); } } *************** *** 173,183 **** { markerList.add( new TimeMarker( minPoint, "", false ) ); ! minPoint = getNextPoint( cMin, gridTime, gridUnits ); } while ( majPoint <= stop ) { ! markerList.add( new TimeMarker( majPoint, df.format(cMaj.getTime()), true ) ); ! majPoint = getNextPoint( cMaj, mGridTime, mGridUnits ); } --- 181,191 ---- { markerList.add( new TimeMarker( minPoint, "", false ) ); ! minPoint = getNextPoint( cMin, minGridTimeUnit, minGridUnitSteps ); } while ( majPoint <= stop ) { ! markerList.add( new TimeMarker( majPoint, dateFormat.format(cMaj.getTime()), true ) ); ! majPoint = getNextPoint( cMaj, majGridTimeUnit, majGridUnitSteps ); } *************** *** 195,208 **** long now = c.getTimeInMillis() / 1000; ! c.add( calendarUnit[mGridTime], mGridUnits ); return (c.getTimeInMillis() / 1000) - now; } ! boolean centerLabels() { return centerLabels; } ! ! // ================================================================ // -- Private methods --- 203,240 ---- long now = c.getTimeInMillis() / 1000; ! c.add( calendarUnit[majGridTimeUnit], majGridUnitSteps ); return (c.getTimeInMillis() / 1000) - now; } ! boolean getCenterLabels() { return centerLabels; } ! ! int getMinGridTimeUnit() { ! return minGridTimeUnit; ! } ! ! int getMinGridUnitSteps() { ! return minGridUnitSteps; ! } ! ! int getMajGridTimeUnit() { ! return majGridTimeUnit; ! } ! ! int getMajGridUnitSteps() { ! return majGridUnitSteps; ! } ! ! boolean isCenterLabels() { ! return centerLabels; ! } ! ! public SimpleDateFormat getDateFormat() { ! return dateFormat; ! } ! ! // ================================================================ // -- Private methods *************** *** 236,240 **** return t.getTimeInMillis(); } ! ! } --- 268,286 ---- return t.getTimeInMillis(); } ! ! static String getUnitName(int unit) { ! return UNIT_NAMES[unit]; ! } ! ! void exportXmlTemplate(XmlWriter xml) { ! xml.startTag("time_axis"); ! xml.writeTag("min_grid_time_unit", TimeAxisUnit.getUnitName(getMinGridTimeUnit())); ! xml.writeTag("min_grid_unit_steps", getMinGridUnitSteps()); ! xml.writeTag("maj_grid_time_unit", TimeAxisUnit.getUnitName(getMajGridTimeUnit())); ! xml.writeTag("maj_grid_unit_steps", getMajGridUnitSteps()); ! xml.writeTag("date_format", getDateFormat().toPattern()); ! xml.writeTag("center_labels", getCenterLabels()); ! xml.closeTag(); // time_axis ! } ! } Index: TimeGrid.java =================================================================== RCS file: /cvsroot/jrobin/src/org/jrobin/graph/TimeGrid.java,v retrieving revision 1.1 retrieving revision 1.2 diff -C2 -d -r1.1 -r1.2 *** TimeGrid.java 7 Nov 2003 08:23:19 -0000 1.1 --- TimeGrid.java 1 Mar 2004 08:50:25 -0000 1.2 *************** *** 85,89 **** boolean centerLabels() { ! return tAxis.centerLabels(); } --- 85,89 ---- boolean centerLabels() { ! return tAxis.getCenterLabels(); } Index: Title.java =================================================================== RCS file: /cvsroot/jrobin/src/org/jrobin/graph/Title.java,v retrieving revision 1.1 retrieving revision 1.2 diff -C2 -d -r1.1 -r1.2 *** Title.java 7 Nov 2003 08:23:19 -0000 1.1 --- Title.java 1 Mar 2004 08:50:25 -0000 1.2 *************** *** 26,29 **** --- 26,30 ---- import org.jrobin.core.RrdException; + import org.jrobin.core.XmlWriter; /** *************** *** 49,51 **** --- 50,56 ---- super.parseComment(); } + + void exportXmlTemplate(XmlWriter xml) { + xml.writeTag("title", getText()); + } } Index: ValueAxisUnit.java =================================================================== RCS file: /cvsroot/jrobin/src/org/jrobin/graph/ValueAxisUnit.java,v retrieving revision 1.2 retrieving revision 1.3 diff -C2 -d -r1.2 -r1.3 *** ValueAxisUnit.java 10 Nov 2003 08:52:27 -0000 1.2 --- ValueAxisUnit.java 1 Mar 2004 08:50:25 -0000 1.3 *************** *** 28,31 **** --- 28,33 ---- package org.jrobin.graph; + import org.jrobin.core.XmlWriter; + import java.util.*; *************** *** 40,49 **** // -- Members // ================================================================ ! private double labelStep = 2; ! private double markStep = 1; ! private int roundStep = 2; ! private double gridStep = 2; ! private double mGridStep = 10; --- 42,48 ---- // -- Members // ================================================================ ! private double gridStep = 2; ! private double labelStep = 10; *************** *** 61,68 **** { this.gridStep = gridStep; ! this.mGridStep = labelStep; } ! ! // ================================================================ // -- Protected methods --- 60,75 ---- { this.gridStep = gridStep; ! this.labelStep = labelStep; } ! ! double getGridStep() { ! return gridStep; ! } ! ! double getLabelStep() { ! return labelStep; ! } ! ! // ================================================================ // -- Protected methods *************** *** 83,93 **** if ( lower > 0 ) { while ( minPoint < lower ) minPoint += gridStep; ! while ( majPoint < lower ) majPoint += mGridStep; } else { while ( minPoint > lower ) minPoint -= gridStep; ! while ( majPoint > lower ) majPoint -= mGridStep; // Go one up to make it visible if (minPoint != lower ) minPoint += gridStep; ! if (majPoint != lower ) majPoint += mGridStep; } --- 90,100 ---- if ( lower > 0 ) { while ( minPoint < lower ) minPoint += gridStep; ! while ( majPoint < lower ) majPoint += labelStep; } else { while ( minPoint > lower ) minPoint -= gridStep; ! while ( majPoint > lower ) majPoint -= labelStep; // Go one up to make it visible if (minPoint != lower ) minPoint += gridStep; ! if (majPoint != lower ) majPoint += labelStep; } *************** *** 109,118 **** markerList.add( new ValueMarker(majPoint, true) ); minPoint = round( minPoint + gridStep ); ! majPoint = round( majPoint + mGridStep ); } else { markerList.add( new ValueMarker(majPoint, true) ); ! majPoint = round( majPoint + mGridStep ); } } --- 116,125 ---- markerList.add( new ValueMarker(majPoint, true) ); minPoint = round( minPoint + gridStep ); ! majPoint = round( majPoint + labelStep ); } else { markerList.add( new ValueMarker(majPoint, true) ); ! majPoint = round( majPoint + labelStep ); } } *************** *** 128,132 **** { markerList.add( new ValueMarker(majPoint, true) ); ! majPoint = round( majPoint + mGridStep ); } --- 135,139 ---- { markerList.add( new ValueMarker(majPoint, true) ); ! majPoint = round( majPoint + labelStep ); } *************** *** 147,151 **** double gridStep = this.gridStep; ! double mGridStep = this.mGridStep; if ( gridStep < 1.0 ) { --- 154,158 ---- double gridStep = this.gridStep; ! double mGridStep = this.labelStep; if ( gridStep < 1.0 ) { *************** *** 164,168 **** if ( roundStep == 0 ) roundStep = 1; int num = valueInt / roundStep; ! int mod = valueInt % roundStep; double gridValue = (roundStep * num) * 1.0d; if ( gridValue > value ) --- 171,175 ---- if ( roundStep == 0 ) roundStep = 1; int num = valueInt / roundStep; ! // int mod = valueInt % roundStep; double gridValue = (roundStep * num) * 1.0d; if ( gridValue > value ) *************** *** 178,182 **** if ( roundStep == 0 ) roundStep = 1; num = valueInt / roundStep; ! mod = valueInt % roundStep; double mGridValue = (roundStep * num) * 1.0d; if ( mGridValue > value ) --- 185,189 ---- if ( roundStep == 0 ) roundStep = 1; num = valueInt / roundStep; ! // mod = valueInt % roundStep; double mGridValue = (roundStep * num) * 1.0d; if ( mGridValue > value ) *************** *** 207,211 **** double gridStep = this.gridStep; ! double mGridStep = this.mGridStep; if ( gridStep < 1.0 ) { --- 214,218 ---- double gridStep = this.gridStep; ! double mGridStep = this.labelStep; if ( gridStep < 1.0 ) { *************** *** 224,228 **** if ( roundStep == 0 ) roundStep = 1; int num = valueInt / roundStep; ! int mod = valueInt % roundStep; double gridValue = (roundStep * (num + 1)) * 1.0d; if ( gridValue - value < (gridStep) / 8 ) --- 231,235 ---- if ( roundStep == 0 ) roundStep = 1; int num = valueInt / roundStep; ! // int mod = valueInt % roundStep; double gridValue = (roundStep * (num + 1)) * 1.0d; if ( gridValue - value < (gridStep) / 8 ) *************** *** 233,237 **** if ( roundStep == 0 ) roundStep = 1; num = valueInt / roundStep; ! mod = valueInt % roundStep; double mGridValue = (roundStep * (num + 1)) * 1.0d; --- 240,244 ---- if ( roundStep == 0 ) roundStep = 1; num = valueInt / roundStep; ! // mod = valueInt % roundStep; double mGridValue = (roundStep * (num + 1)) * 1.0d; *************** *** 272,274 **** --- 279,288 ---- return new java.math.BigDecimal(value).setScale(numDecs , java.math.BigDecimal.ROUND_HALF_EVEN).doubleValue(); } + + void exportXmlTemplate(XmlWriter xml) { + xml.startTag("value_axis"); + xml.writeTag("grid_step", getGridStep()); + xml.writeTag("label_step", getLabelStep()); + xml.closeTag(); // value_axis + } } |