00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030
00031
00032
00033
00034
00035
00036
00037
00038
00039
00040
00041
00042
00043
00044
00045
00046
00047
00048
00049
00050
00051
00052 using System;
00053 using System.Collections;
00054 using System.Data;
00055
00056 namespace NPlot
00057 {
00058
00065 public class SequenceAdapter
00066 {
00067 private AdapterUtils.IAxisSuggester XAxisSuggester_;
00068 private AdapterUtils.IAxisSuggester YAxisSuggester_;
00069 private AdapterUtils.ICounter counter_;
00070 private AdapterUtils.IDataGetter xDataGetter_;
00071 private AdapterUtils.IDataGetter yDataGetter_;
00072
00080 public SequenceAdapter( object dataSource, string dataMember, object ordinateData, object abscissaData )
00081 {
00082
00083 if (dataSource == null && dataMember == null)
00084 {
00085 if (ordinateData is IList)
00086 {
00087
00088 this.YAxisSuggester_ = new AdapterUtils.AxisSuggester_IList((IList)ordinateData);
00089 this.yDataGetter_ = new AdapterUtils.DataGetter_IList((IList)ordinateData);
00090 this.counter_ = new AdapterUtils.Counter_IList((IList)ordinateData);
00091
00092 if (abscissaData is IList)
00093 {
00094 this.XAxisSuggester_ = new AdapterUtils.AxisSuggester_IList((IList)abscissaData);
00095 this.xDataGetter_ = new AdapterUtils.DataGetter_IList((IList)abscissaData);
00096 return;
00097 }
00098
00099 else if (abscissaData is StartStep)
00100 {
00101 this.XAxisSuggester_ = new AdapterUtils.AxisSuggester_StartStep((StartStep)abscissaData, (IList)ordinateData);
00102 this.xDataGetter_ = new AdapterUtils.DataGetter_StartStep((StartStep)abscissaData);
00103 return;
00104 }
00105
00106 else if (abscissaData == null)
00107 {
00108 this.XAxisSuggester_ = new AdapterUtils.AxisSuggester_Auto((IList)ordinateData);
00109 this.xDataGetter_ = new AdapterUtils.DataGetter_Count();
00110 return;
00111 }
00112 }
00113
00114
00115 else if (ordinateData == null)
00116 {
00117 if (abscissaData == null)
00118 {
00119 this.XAxisSuggester_ = new AdapterUtils.AxisSuggester_Null();
00120 this.YAxisSuggester_ = new AdapterUtils.AxisSuggester_Null();
00121 this.counter_ = new AdapterUtils.Counter_Null();
00122 this.xDataGetter_ = new AdapterUtils.DataGetter_Null();
00123 this.yDataGetter_ = new AdapterUtils.DataGetter_Null();
00124 return;
00125 }
00126 else if (abscissaData is IList)
00127 {
00128 this.XAxisSuggester_ = new AdapterUtils.AxisSuggester_IList((IList)abscissaData);
00129 this.YAxisSuggester_ = new AdapterUtils.AxisSuggester_Auto((IList)abscissaData);
00130 this.counter_ = new AdapterUtils.Counter_IList((IList)abscissaData);
00131 this.xDataGetter_ = new AdapterUtils.DataGetter_IList((IList)abscissaData);
00132 this.yDataGetter_ = new AdapterUtils.DataGetter_Count();
00133 return;
00134 }
00135
00136 else
00137 {
00138
00139 }
00140
00141 }
00142 else
00143 {
00144
00145 }
00146
00147 }
00148
00149 else if (dataSource is IList && dataMember == null)
00150 {
00151 if (dataSource is DataView)
00152 {
00153 DataView data = (DataView)dataSource;
00154
00155 this.counter_ = new AdapterUtils.Counter_DataView(data);
00156 this.xDataGetter_ = new AdapterUtils.DataGetter_DataView(data, (string)abscissaData);
00157 this.yDataGetter_ = new AdapterUtils.DataGetter_DataView(data, (string)ordinateData);
00158 this.XAxisSuggester_ = new AdapterUtils.AxisSuggester_DataView(data, (string)abscissaData);
00159 this.YAxisSuggester_ = new AdapterUtils.AxisSuggester_DataView(data, (string)ordinateData);
00160 return;
00161 }
00162
00163 else
00164 {
00165 this.YAxisSuggester_ = new AdapterUtils.AxisSuggester_IList((IList)dataSource);
00166 this.counter_ = new AdapterUtils.Counter_IList((IList)dataSource);
00167 this.yDataGetter_ = new AdapterUtils.DataGetter_IList((IList)dataSource);
00168
00169 if ((ordinateData == null) && (abscissaData == null))
00170 {
00171 this.XAxisSuggester_ = new AdapterUtils.AxisSuggester_Auto((IList)dataSource);
00172 this.xDataGetter_ = new AdapterUtils.DataGetter_Count();
00173 return;
00174 }
00175
00176 else if ((ordinateData == null) && (abscissaData is StartStep))
00177 {
00178 this.XAxisSuggester_ = new AdapterUtils.AxisSuggester_StartStep((StartStep)abscissaData, (IList)ordinateData);
00179 this.xDataGetter_ = new AdapterUtils.DataGetter_StartStep((StartStep)abscissaData);
00180 return;
00181 }
00182
00183 else if ((ordinateData == null) && (abscissaData is IList))
00184 {
00185 this.XAxisSuggester_ = new AdapterUtils.AxisSuggester_IList((IList)abscissaData);
00186 this.xDataGetter_ = new AdapterUtils.DataGetter_IList((IList)abscissaData);
00187 return;
00188 }
00189
00190 else
00191 {
00192
00193 }
00194 }
00195 }
00196
00197 else if ( ((dataSource is DataTable) && (dataMember == null)) || (dataSource is DataSet) )
00198 {
00199 DataRowCollection rows = null;
00200
00201 if (dataSource is DataSet)
00202 {
00203 if (dataMember != null)
00204 {
00205 rows = ((DataTable)((DataSet)dataSource).Tables[dataMember]).Rows;
00206 }
00207 else
00208 {
00209 rows = ((DataTable)((DataSet)dataSource).Tables[0]).Rows;
00210 }
00211 }
00212 else
00213 {
00214 rows = ((DataTable)dataSource).Rows;
00215 }
00216
00217 this.yDataGetter_ = new AdapterUtils.DataGetter_Rows(rows, (string)ordinateData);
00218 this.YAxisSuggester_ = new AdapterUtils.AxisSuggester_Rows(rows, (string)ordinateData);
00219 this.counter_ = new AdapterUtils.Counter_Rows(rows);
00220
00221 if ((abscissaData is string) && (ordinateData is string))
00222 {
00223 this.XAxisSuggester_ = new AdapterUtils.AxisSuggester_Rows(rows, (string)abscissaData);
00224 this.xDataGetter_ = new AdapterUtils.DataGetter_Rows(rows, (string)abscissaData);
00225 return;
00226 }
00227 else if ((abscissaData == null) && (ordinateData is string))
00228 {
00229 this.XAxisSuggester_ = new AdapterUtils.AxisSuggester_RowAuto(rows);
00230 this.xDataGetter_ = new AdapterUtils.DataGetter_Count();
00231 return;
00232 }
00233 else
00234 {
00235
00236 }
00237 }
00238
00239 else
00240 {
00241
00242 }
00243
00244 throw new NPlotException( "Do not know how to interpret data provided to chart." );
00245
00246 }
00247
00248
00252 public int Count
00253 {
00254 get
00255 {
00256 return counter_.Count;
00257 }
00258 }
00259
00260
00264 public PointD this[int i]
00265 {
00266 get
00267 {
00268 return new PointD( this.xDataGetter_.Get(i), this.yDataGetter_.Get(i) );
00269 }
00270 }
00271
00272
00277 public Axis SuggestXAxis()
00278 {
00279 return this.XAxisSuggester_.Get();
00280 }
00281
00282
00287 public Axis SuggestYAxis()
00288 {
00289 Axis a = this.YAxisSuggester_.Get();
00290
00291 a.IncreaseRange( 0.08 );
00292 return a;
00293 }
00294
00295
00302 public void WriteData( System.Text.StringBuilder sb, RectangleD region, bool onlyInRegion )
00303 {
00304 for (int i=0; i<this.Count; ++i)
00305 {
00306 if ( !(onlyInRegion &&
00307 (this[i].X >= region.X && this[i].X <= region.X+region.Width) &&
00308 (this[i].Y >= region.Y && this[i].Y <= region.Y+region.Height)) )
00309 continue;
00310
00311 sb.Append( this[i].ToString() );
00312 sb.Append( "\r\n" );
00313 }
00314 }
00315
00316
00317 }
00318 }