1 25 package org.jrobin.graph; 26 27 import org.jrobin.core.XmlWriter; 28 29 import java.awt.*; 30 31 36 class Area extends PlotDef 37 { 38 46 Area( String sourceName, Color color ) 47 { 48 super( sourceName, color ); 49 this.plotType = PlotDef.PLOT_AREA; 50 } 51 52 61 Area( Source source, double[] values, Color color, boolean stacked, boolean visible ) 62 { 63 super( source, values, color, stacked, visible); 64 } 65 66 67 77 void draw( ChartGraphics g, int[] xValues, double[] stackValues, int lastPlotType ) 78 { 79 g.setColor( color ); 80 81 int len = values.length; 82 83 double value; 84 int ax = 0, ay = 0, nx = 0, ny = 0, py; 85 86 for ( int i = 0; i < len; i++ ) 87 { 88 py = 0; 89 nx = xValues[i]; 90 value = values[i]; 91 92 if ( !Double.isNaN(value) ) 93 { 94 if ( stacked ) 95 { 96 py = g.getY( stackValues[i] ); 97 value += stackValues[i]; 98 } 99 100 ny = g.getY( value ); 101 102 if ( visible ) 103 { 104 if ( nx > ax + 1 ) { 106 int co = (ny - ay) / (nx - ax); 108 int j = (ax > 0 ? ax : 1 ); 110 for (j = ax; j <= nx; j++) 111 if ( ay != Integer.MIN_VALUE && ny != Integer.MIN_VALUE ) 112 g.drawLine( j, py, j, ( co * (j - ax) + ay) ); 113 } 114 else if ( nx != 0 && py != Integer.MIN_VALUE && ny != Integer.MIN_VALUE ) 115 g.drawLine( nx, py, nx, ny ); 116 } 117 } 118 119 stackValues[i] = value; 121 ax = nx; 122 ay = ny; 123 } 124 } 125 126 void exportXmlTemplate( XmlWriter xml, String legend ) 127 { 128 xml.startTag("area"); 129 xml.writeTag("datasource", sourceName); 130 xml.writeTag("color", color); 131 xml.writeTag("legend", legend); 132 xml.closeTag(); } 134 } 135 | Popular Tags |