1 25 package org.jrobin.graph; 26 27 import java.awt.*; 28 29 import org.jrobin.core.RrdException; 30 import org.jrobin.core.XmlWriter; 31 import org.jrobin.core.Util; 32 33 38 class Line extends PlotDef 39 { 40 protected static BasicStroke DEF_LINE_STROKE = new BasicStroke(1.0f); 44 protected int lineWidth = 1; 46 47 Line() { 51 super(); 52 } 53 54 60 Line( String sourceName, Color color ) 61 { 62 super( sourceName, color ); 63 } 64 65 71 Line( String sourceName, Color color, int lineWidth ) 72 { 73 this( sourceName, color ); 74 this.lineWidth = lineWidth; 75 } 76 77 86 Line( Source source, double[] values, Color color, boolean stacked, boolean visible ) 87 { 88 super( source, values, color, stacked, visible); 89 } 90 91 92 102 void draw( ChartGraphics g, int[] xValues, double[] stackValues, int lastPlotType ) throws RrdException 103 { 104 g.setColor( color ); 105 g.setStroke( lineWidth != 1 ? new BasicStroke(lineWidth) : DEF_LINE_STROKE ); 106 107 Graphics2D gd = g.getGraphics(); 108 int len = values.length; 109 110 double value; 111 int ax = 0, ay = 0, nx = 0, ny = 0; 112 113 for ( int i = 0; i < len; i++ ) 114 { 115 value = values[i]; 116 nx = xValues[i]; 117 118 if ( stacked ) 119 value += stackValues[i]; 120 121 ny = g.getY( value ); 122 123 if ( visible && nx != 0 && ay != Integer.MIN_VALUE && ny != Integer.MIN_VALUE ) 124 gd.drawLine(ax, -ay, nx, -ny); 125 126 stackValues[i] = value; 127 ax = nx; 128 ay = ny; 129 } 130 131 g.setStroke( STROKE ); 132 } 133 134 int getLineWidth() { 135 return lineWidth; 136 } 137 138 void exportXmlTemplate( XmlWriter xml, String legend ) 139 { 140 xml.startTag("line"); 141 xml.writeTag("datasource", sourceName); 142 xml.writeTag("color", color); 143 xml.writeTag("legend", legend); 144 xml.writeTag("width", lineWidth); 145 xml.closeTag(); } 147 } 148 | Popular Tags |