00001 package cedar.jetweb.hist; 00002 00003 import java.util.Vector; 00004 import jas.hist.DataSource; 00005 import jas.hist.JASHistData; 00006 import jas.hist.Rebinnable1DHistogramData; 00007 import jas.hist.JASHistStyle; 00008 import jas.hist.JASHist1DHistogramStyle; 00009 import jas.hist.HasStyle; 00010 00011 import java.awt.Color; 00012 00013 import cedar.jetweb.JetWebException; 00014 import cedar.jetweb.model.plots.DataPlot; 00015 import cedar.jetweb.model.plots.RealPlot; 00016 import cedar.jetweb.model.plots.DataPoint; 00017 00027 public class PlotDataSource implements Rebinnable1DHistogramData, HasStyle { 00028 private double[][] theData; 00029 private double xmin = 0; 00030 private double xmax = 0; 00031 private int nbins; 00032 00033 private boolean isRealData; 00034 public boolean isReal(){return isRealData;} 00035 //public void setReal(){isRealData=true;} 00036 //public void setMC(){isRealData=false;} 00037 00064 public double[][] rebin(int bins, double min, double max, boolean wantErrors, boolean hurry){ 00065 return theData; 00066 } 00072 public double getMin(){ 00073 return xmin; 00074 }; 00080 public double getMax(){ 00081 return xmax; 00082 }; 00088 public int getBins(){ 00089 return nbins; 00090 }; 00100 public boolean isRebinnable() { 00101 return false; 00102 } 00108 public int getAxisType(){ 00109 return DataSource.DOUBLE; 00110 }; 00116 public String getTitle(){ 00117 return ""; 00118 }; 00125 public String[] getAxisLabels(){ 00126 return null; 00127 }; 00134 public PlotDataSource(DataPlot plot, double scalef) throws JetWebException { 00135 Vector dataPoints = plot.getDataPoints(); 00136 nbins = dataPoints.size(); 00137 theData = new double[4][nbins]; 00138 for (int i=0;i<nbins;i++){ 00139 DataPoint p = (DataPoint)dataPoints.elementAt(i); 00140 theData[0][i] = p.getY()*scalef; 00141 theData[1][i] = p.getYUp()*scalef; 00142 theData[2][i] = p.getYDown()*scalef; 00143 } 00144 00145 DataPoint first = (DataPoint)dataPoints.firstElement(); 00146 DataPoint last = (DataPoint)dataPoints.lastElement(); 00147 00148 xmax = last.getXMax(); 00149 xmin = first.getXMin(); 00150 00151 if (plot instanceof RealPlot) { 00152 isRealData=true; 00153 } else { 00154 isRealData=false; 00155 } 00156 setStyleDefault(); 00157 } 00163 protected void setTheData(double[][] td){ 00164 theData = td; 00165 } 00171 protected void setBins(int i){ 00172 nbins = i; 00173 } 00179 protected void setMin(double d){ 00180 xmin = d; 00181 } 00187 protected void setMax(double d){ 00188 xmax = d; 00189 } 00190 private JASHist1DHistogramStyle myStyle; 00196 public JASHistStyle getStyle() { return myStyle; } 00200 public void setStyleDefault(){ 00201 00202 myStyle = new JASHist1DHistogramStyle(); 00203 if (isRealData){ 00204 myStyle.setErrorBarColor(Color.black); 00205 myStyle.setLineColor(Color.black); 00206 myStyle.setDataPointColor(Color.black); 00207 }else{ 00208 myStyle.setErrorBarColor(Color.red); 00209 myStyle.setLineColor(Color.red); 00210 myStyle.setDataPointColor(Color.red); 00211 } 00212 myStyle.setShowHistogramBars(false); 00213 myStyle.setShowDataPoints(true); 00214 myStyle.setShowErrorBars(true); 00215 myStyle.setShowLinesBetweenPoints(false); 00216 myStyle.setDataPointStyle(JASHist1DHistogramStyle.SYMBOL_DOT); 00217 } 00218 } 00219 00220 00221 00222 00223 00224 00225 00226 00227 00228 00229 00230 00231 00232 00233
Generated Wed Jan 17 09:14:27 GMT 2007