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.Drawing;
00054
00055 namespace NPlot
00056 {
00057
00061 public class FilledRegion : IDrawable
00062 {
00063
00070 public FilledRegion( LinePlot lp1, LinePlot lp2 )
00071 {
00072 lp1_ = lp1;
00073 lp2_ = lp2;
00074 }
00075
00076
00082 public FilledRegion(VerticalLine l1, VerticalLine l2)
00083 {
00084 vl1_ = l1;
00085 vl2_ = l2;
00086 }
00087
00088
00094 public FilledRegion(HorizontalLine l1, HorizontalLine l2)
00095 {
00096 hl1_ = l1;
00097 hl2_ = l2;
00098 }
00099
00100
00107 public void Draw( System.Drawing.Graphics g, PhysicalAxis xAxis, PhysicalAxis yAxis )
00108 {
00109 ITransform2D t = Transform2D.GetTransformer(xAxis, yAxis);
00110
00111 Brush b = brush_;
00112 if (b == null)
00113 {
00114 b = areaBrush_.Get(new Rectangle(xAxis.PhysicalMin.X, yAxis.PhysicalMax.Y, xAxis.PhysicalLength, yAxis.PhysicalLength));
00115 }
00116
00117 if (hl1_ != null && hl2_ != null)
00118 {
00119 PointF[] points = new PointF[4];
00120 points[0] = t.Transform(xAxis.Axis.WorldMin, hl1_.OrdinateValue);
00121 points[1] = t.Transform(xAxis.Axis.WorldMax, hl1_.OrdinateValue);
00122 points[2] = t.Transform(xAxis.Axis.WorldMax, hl2_.OrdinateValue);
00123 points[3] = t.Transform(xAxis.Axis.WorldMin, hl2_.OrdinateValue);
00124
00125 g.FillPolygon(b, points);
00126 }
00127 else if (vl1_ != null && vl2_ != null)
00128 {
00129 PointF[] points = new PointF[4];
00130 points[0] = t.Transform(vl1_.AbscissaValue, yAxis.Axis.WorldMin);
00131 points[1] = t.Transform(vl1_.AbscissaValue, yAxis.Axis.WorldMax);
00132 points[2] = t.Transform(vl2_.AbscissaValue, yAxis.Axis.WorldMax);
00133 points[3] = t.Transform(vl2_.AbscissaValue, yAxis.Axis.WorldMin);
00134
00135 g.FillPolygon(b, points);
00136 }
00137 else if (lp1_ != null && lp2_ != null)
00138 {
00139
00140 SequenceAdapter a1 = new SequenceAdapter(lp1_.DataSource, lp1_.DataMember, lp1_.OrdinateData, lp1_.AbscissaData);
00141 SequenceAdapter a2 = new SequenceAdapter(lp2_.DataSource, lp2_.DataMember, lp2_.OrdinateData, lp2_.AbscissaData);
00142
00143
00144 int count = a1.Count + a2.Count;
00145 PointF[] points = new PointF[count];
00146 for (int i = 0; i < a1.Count; ++i)
00147 {
00148 points[i] = t.Transform(a1[i]);
00149 }
00150 for (int i = 0; i < a2.Count; ++i)
00151 {
00152 points[i + a1.Count] = t.Transform(a2[a2.Count - i - 1]);
00153 }
00154
00155 g.FillPolygon(b, points);
00156 }
00157 else
00158 {
00159 throw new NPlotException("One of bounds was set to null");
00160 }
00161 }
00162
00163
00167 public Brush Brush
00168 {
00169 set
00170 {
00171 brush_ = value;
00172 areaBrush_ = null;
00173 }
00174 }
00175
00176
00180 public IRectangleBrush RectangleBrush
00181 {
00182 set
00183 {
00184 brush_ = null;
00185 areaBrush_ = value;
00186 }
00187 }
00188
00189
00190 private VerticalLine vl1_;
00191 private VerticalLine vl2_;
00192
00193 private HorizontalLine hl1_;
00194 private HorizontalLine hl2_;
00195
00196 private LinePlot lp1_;
00197 private LinePlot lp2_;
00198
00199 private Brush brush_ = new SolidBrush( Color.GhostWhite );
00200 private IRectangleBrush areaBrush_ = null;
00201 }
00202
00203 }