1 25 package org.jrobin.graph; 26 27 import java.awt.Color ; 28 import java.util.HashMap ; 29 30 import org.jrobin.core.RrdException; 31 import org.jrobin.core.XmlWriter; 32 33 42 class CustomArea extends PlotDef 43 { 44 private long xVal1; 48 private long xVal2; 49 50 private double yVal1; 51 private double yVal2; 52 53 54 67 CustomArea( long startTime, double startValue, long endTime, double endValue, Color color ) 68 { 69 this.color = color; 70 if ( color == null ) 71 visible = false; 72 73 this.xVal1 = startTime; 74 this.xVal2 = endTime; 75 this.yVal1 = startValue; 76 this.yVal2 = endValue; 77 } 78 79 80 90 void draw( ChartGraphics g, int[] xValues, double[] stackValues, int lastPlotType ) throws RrdException 91 { 92 g.setColor( color ); 93 94 int ax, ay, nx, ny; 95 96 if ( xVal1 == Long.MIN_VALUE ) 98 ax = g.getMinX(); 99 else if ( xVal1 == Long.MAX_VALUE ) 100 ax = g.getMaxX(); 101 else 102 ax = g.getX( xVal1 ); 103 104 if ( xVal2 == Long.MIN_VALUE ) 105 nx = g.getMinX(); 106 else if ( xVal2 == Long.MAX_VALUE ) 107 nx = g.getMaxX(); 108 else 109 nx = g.getX( xVal2 ); 110 111 if ( yVal1 == Double.MIN_VALUE ) 113 ay = g.getMinY(); 114 else if ( yVal1 == Double.MAX_VALUE ) 115 ay = g.getMaxY(); 116 else 117 ay = g.getY( yVal1 ); 118 119 if ( yVal2 == Double.MIN_VALUE ) 120 ny = g.getMinY(); 121 else if ( yVal2 == Double.MAX_VALUE ) 122 ny = g.getMaxY(); 123 else 124 ny = g.getY( yVal2 ); 125 126 if ( visible ) 128 { 129 if ( ny > ay ) 130 g.fillRect( ax, ay, nx, ny ); 131 else 132 g.fillRect( ax, ny, nx, ay ); 133 } 134 135 if ( yVal2 != Double.MAX_VALUE ) 138 for (int i = 0; i < stackValues.length; i++) 139 if ( xValues[i] < ax || xValues[i] > nx ) 140 stackValues[i] = g.getInverseY(0); 141 else 142 stackValues[i] = g.getInverseY(ny); 143 } 144 145 154 double getValue( int tblPos, long[] timestamps ) 155 { 156 long time = timestamps[tblPos]; 157 158 if ( time > xVal2 || time < xVal1 ) 160 return Double.NaN; 161 162 if ( yVal2 == Double.MAX_VALUE ) 163 return Double.NaN; 164 165 return yVal2; 166 } 167 168 void setSource( Source[] sources, HashMap sourceIndex ) throws RrdException { 170 } 171 172 void setValue( int tableRow, long preciseTime, long[] reducedTimestamps ) { 174 } 175 176 void exportXmlTemplate( XmlWriter xml, String legend ) { 177 xml.startTag("area"); 178 xml.writeTag("time1", xVal1); 179 xml.writeTag("value1", yVal1); 180 xml.writeTag("time2", xVal2); 181 xml.writeTag("value2", yVal2); 182 xml.writeTag("color", color); 183 xml.writeTag("legend", legend); 184 xml.closeTag(); } 186 } 187 | Popular Tags |