Changeset 1038
- Timestamp:
- 12/18/08 23:17:23 (16 years ago)
- Location:
- trunk/sources
- Files:
-
- 11 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/sources/HeuristicLab.Visualization.Test/LineChartTestForm.Designer.cs
r986 r1038 26 26 this.lineChartGroupBox = new System.Windows.Forms.GroupBox(); 27 27 this.btnResetView = new System.Windows.Forms.Button(); 28 this.btnAddRandomValue = new System.Windows.Forms.Button(); 28 29 this.SuspendLayout(); 29 30 // … … 35 36 this.lineChartGroupBox.Location = new System.Drawing.Point(12, 12); 36 37 this.lineChartGroupBox.Name = "lineChartGroupBox"; 37 this.lineChartGroupBox.Size = new System.Drawing.Size(6 07, 318);38 this.lineChartGroupBox.Size = new System.Drawing.Size(673, 376); 38 39 this.lineChartGroupBox.TabIndex = 0; 39 40 this.lineChartGroupBox.TabStop = false; … … 43 44 // 44 45 this.btnResetView.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Right))); 45 this.btnResetView.Location = new System.Drawing.Point( 544, 346);46 this.btnResetView.Location = new System.Drawing.Point(610, 404); 46 47 this.btnResetView.Name = "btnResetView"; 47 48 this.btnResetView.Size = new System.Drawing.Size(75, 23); … … 51 52 this.btnResetView.Click += new System.EventHandler(this.btnResetView_Click); 52 53 // 54 // btnAddRandomValue 55 // 56 this.btnAddRandomValue.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Right))); 57 this.btnAddRandomValue.Location = new System.Drawing.Point(529, 404); 58 this.btnAddRandomValue.Name = "btnAddRandomValue"; 59 this.btnAddRandomValue.Size = new System.Drawing.Size(75, 23); 60 this.btnAddRandomValue.TabIndex = 2; 61 this.btnAddRandomValue.Text = "Add Value"; 62 this.btnAddRandomValue.UseVisualStyleBackColor = true; 63 this.btnAddRandomValue.Click += new System.EventHandler(this.btnAddRandomValue_Click); 64 // 53 65 // LineChartTestForm 54 66 // 55 67 this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 13F); 56 68 this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font; 57 this.ClientSize = new System.Drawing.Size(631, 395); 69 this.ClientSize = new System.Drawing.Size(697, 453); 70 this.Controls.Add(this.btnAddRandomValue); 58 71 this.Controls.Add(this.lineChartGroupBox); 59 72 this.Controls.Add(this.btnResetView); … … 68 81 private System.Windows.Forms.GroupBox lineChartGroupBox; 69 82 private System.Windows.Forms.Button btnResetView; 83 private System.Windows.Forms.Button btnAddRandomValue; 70 84 71 85 } -
trunk/sources/HeuristicLab.Visualization.Test/LineChartTestForm.cs
r985 r1038 1 using System.Windows.Forms; 1 using System; 2 using System.Windows.Forms; 2 3 using HeuristicLab.Core; 3 4 4 5 namespace HeuristicLab.Visualization.Test { 5 6 public partial class LineChartTestForm : Form { 7 private readonly IView view; 6 8 private ChartDataRowsModel model; 7 private IView view;8 9 9 10 public LineChartTestForm() { 10 11 InitializeComponent(); 12 } 11 13 12 model = new ChartDataRowsModel(); 13 14 14 public LineChartTestForm(ChartDataRowsModel model) : this() { 15 this.model = model; 15 16 view = model.CreateView(); 16 17 … … 21 22 } 22 23 23 public ChartDataRowsModel Model { 24 get { return model; } 24 private void btnResetView_Click(object sender, EventArgs e) { 25 if (view != null) { 26 LineChart lineChart = (LineChart)view; 27 lineChart.ResetView(); 28 } 25 29 } 26 30 27 private void btnResetView_Click(object sender, System.EventArgs e) { 28 LineChart lineChart = (LineChart)view; 29 lineChart.ResetView(); 31 private void btnAddRandomValue_Click(object sender, EventArgs e) { 32 Random rand = new Random(); 33 34 foreach (IDataRow row in model.Rows) 35 row.AddValue(rand.NextDouble()*100); 30 36 } 31 37 } -
trunk/sources/HeuristicLab.Visualization.Test/LineChartTests.cs
r983 r1038 6 6 [TestFixture] 7 7 public class LineChartTests { 8 private ChartDataRowsModel model; 9 10 [SetUp] 11 public void SetUp() { 12 model = new ChartDataRowsModel(); 13 } 14 8 15 [Test] 9 16 public void TestLineChart() { 10 LineChartTestForm f = new LineChartTestForm( );17 LineChartTestForm f = new LineChartTestForm(model); 11 18 12 19 IDataRow row1 = new DataRow(); … … 27 34 28 35 29 f.Model.AddDataRow(row1);30 f.Model.AddDataRow(row2);31 f.Model.AddDataRow(row3);36 model.AddDataRow(row1); 37 model.AddDataRow(row2); 38 model.AddDataRow(row3); 32 39 33 40 row1.AddValue(10); … … 50 57 Random rand = new Random(); 51 58 52 for (int i = 0; i < 1000 ; i++) {59 for (int i = 0; i < 10000; i++) { 53 60 row1.AddValue(rand.NextDouble()*10); 54 61 row2.AddValue(rand.NextDouble()*10); … … 61 68 [Test] 62 69 public void TestAxes() { 63 LineChartTestForm f = new LineChartTestForm( );70 LineChartTestForm f = new LineChartTestForm(model); 64 71 65 72 IDataRow row1 = new DataRow(); … … 69 76 row1.Style = DrawingStyle.Solid; 70 77 71 f.Model.AddDataRow(row1);78 model.AddDataRow(row1); 72 79 73 80 row1.AddValue(10); -
trunk/sources/HeuristicLab.Visualization.Test/MainForm.cs
r865 r1038 30 30 WorldShape mainWorld = canvasUI.MainCanvas.WorldShape; 31 31 // simple rectangle shape 32 RectangleShape rect7 = new RectangleShape(5, 5, 50, 50, 0,Color.Black);32 RectangleShape rect7 = new RectangleShape(5, 5, 50, 50, Color.Black); 33 33 mainWorld.AddShape(rect7); 34 34 } … … 43 43 44 44 for (int i = 0; i < 10000; i++) { 45 RectangleShape rect = new RectangleShape(x1, y1, x1 + 0.3, y1 + 0.3, 0,Color.Maroon);45 RectangleShape rect = new RectangleShape(x1, y1, x1 + 0.3, y1 + 0.3, Color.Maroon); 46 46 x1 += 0.4; 47 47 y1 += 0.4; … … 57 57 CompositeShape middleComp = new CompositeShape(); 58 58 59 RectangleShape rect5 = new RectangleShape(400, 10, 500, 300, 0,Color.Navy);60 RectangleShape rect6 = new RectangleShape(510, 310, 580, 590, 0,Color.Magenta);59 RectangleShape rect5 = new RectangleShape(400, 10, 500, 300, Color.Navy); 60 RectangleShape rect6 = new RectangleShape(510, 310, 580, 590, Color.Magenta); 61 61 62 62 middleComp.AddShape(rect5); … … 71 71 WorldShape leftWorld = new WorldShape(new RectangleD(0, 0, 1000, 1000), new RectangleD(10, 10, 380, 590)); 72 72 73 RectangleShape fillRect = new RectangleShape(0, 0, 1000, 1000, 0,Color.LightBlue);73 RectangleShape fillRect = new RectangleShape(0, 0, 1000, 1000, Color.LightBlue); 74 74 75 RectangleShape rect1 = new RectangleShape(100, 100, 500, 500, 0,Color.Red);76 RectangleShape rect2 = new RectangleShape(800, -200, 1200, 500, 0,Color.Green);75 RectangleShape rect1 = new RectangleShape(100, 100, 500, 500, Color.Red); 76 RectangleShape rect2 = new RectangleShape(800, -200, 1200, 500, Color.Green); 77 77 78 78 CompositeShape comp1 = new CompositeShape(); 79 79 80 RectangleShape rect3 = new RectangleShape(510, 580, 590, 700, 0,Color.Blue);81 RectangleShape rect4 = new RectangleShape(600, 710, 800, 900, 0,Color.Orange);80 RectangleShape rect3 = new RectangleShape(510, 580, 590, 700, Color.Blue); 81 RectangleShape rect4 = new RectangleShape(600, 710, 800, 900, Color.Orange); 82 82 83 83 comp1.AddShape(rect3); -
trunk/sources/HeuristicLab.Visualization/Canvas.cs
r635 r1038 1 using System.Diagnostics; 1 2 using System.Drawing; 2 3 using System.Drawing.Drawing2D; … … 11 12 } 12 13 14 13 15 public void Draw(Graphics graphics, Rectangle viewport) { 16 Stopwatch sw = new Stopwatch(); 17 sw.Start(); 18 14 19 GraphicsState gstate = graphics.Save(); 15 20 … … 19 24 20 25 graphics.Restore(gstate); 26 27 sw.Stop(); 28 Trace.WriteLine(string.Format("Drawing time: {0:0.0}ms", sw.Elapsed.TotalMilliseconds)); 21 29 } 22 30 } -
trunk/sources/HeuristicLab.Visualization/CanvasUI.cs
r958 r1038 39 39 base.OnPaint(pe); 40 40 } catch (Exception e) { 41 Debug.WriteLine(e);41 Trace.WriteLine(e); 42 42 } 43 43 } -
trunk/sources/HeuristicLab.Visualization/LineChart.Designer.cs
r928 r1038 29 29 private void InitializeComponent() 30 30 { 31 this.canvas UI1= new HeuristicLab.Visualization.CanvasUI();31 this.canvas = new HeuristicLab.Visualization.CanvasUI(); 32 32 this.SuspendLayout(); 33 33 // 34 // canvas UI134 // canvas 35 35 // 36 this.canvas UI1.Dock = System.Windows.Forms.DockStyle.Fill;37 this.canvas UI1.Location = new System.Drawing.Point(0, 0);38 this.canvas UI1.MouseEventListener = null;39 this.canvas UI1.Name = "canvasUI1";40 this.canvas UI1.Size = new System.Drawing.Size(552, 390);41 this.canvas UI1.TabIndex = 0;42 this.canvas UI1.Text = "canvasUI1";43 this.canvas UI1.MouseDown += new System.Windows.Forms.MouseEventHandler(this.canvasUI1_MouseDown);36 this.canvas.Dock = System.Windows.Forms.DockStyle.Fill; 37 this.canvas.Location = new System.Drawing.Point(0, 0); 38 this.canvas.MouseEventListener = null; 39 this.canvas.Name = "canvas"; 40 this.canvas.Size = new System.Drawing.Size(552, 390); 41 this.canvas.TabIndex = 0; 42 this.canvas.Text = "canvas"; 43 this.canvas.MouseDown += new System.Windows.Forms.MouseEventHandler(this.canvasUI1_MouseDown); 44 44 // 45 45 // LineChart … … 47 47 this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 13F); 48 48 this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font; 49 this.Controls.Add(this.canvas UI1);49 this.Controls.Add(this.canvas); 50 50 this.Name = "LineChart"; 51 51 this.Size = new System.Drawing.Size(552, 390); … … 56 56 #endregion 57 57 58 private CanvasUI canvas UI1;58 private CanvasUI canvas; 59 59 } 60 60 } -
trunk/sources/HeuristicLab.Visualization/LineChart.cs
r996 r1038 6 6 7 7 namespace HeuristicLab.Visualization { 8 public class LinesShape : WorldShape { 9 private readonly RectangleShape background = new RectangleShape(0, 0, 1, 1, Color.FromArgb(240, 240, 240)); 10 11 public LinesShape(RectangleD clippingArea, RectangleD boundingBox) 12 : base(clippingArea, boundingBox) { 13 AddShape(background); 14 } 15 16 public override void Draw(Graphics graphics, Rectangle viewport, RectangleD clippingArea) { 17 UpdateLayout(); 18 base.Draw(graphics, viewport, clippingArea); 19 } 20 21 private void UpdateLayout() { 22 background.Rectangle = ClippingArea; 23 } 24 } 25 8 26 public partial class LineChart : ViewBase { 9 27 private readonly IChartDataRowsModel model; … … 14 32 15 33 private readonly WorldShape root; 34 private readonly TextShape titleShape; 35 private readonly LinesShape linesShape; 36 16 37 private readonly XAxis xAxis; 17 38 … … 28 49 /// <param name="model">Referenz to the model, for data</param> 29 50 public LineChart(IChartDataRowsModel model) : this() { 30 if (model == null) {51 if (model == null) 31 52 throw new NullReferenceException("Model cannot be null."); 32 }33 53 34 54 //TODO: correct Rectangle to fit 35 RectangleD clientRectangle = new RectangleD(-1, -1, 1, 1); 36 37 root = new WorldShape(clientRectangle, clientRectangle); 38 39 xAxis = new XAxis(); 55 56 RectangleD dummy = new RectangleD(0, 0, 1, 1); 57 58 root = new WorldShape(dummy, dummy); 59 60 linesShape = new LinesShape(dummy, dummy); 61 root.AddShape(linesShape); 62 63 xAxis = new XAxis(dummy, dummy); 40 64 root.AddShape(xAxis); 41 65 42 canvasUI1.MainCanvas.WorldShape = root; 43 66 titleShape = new TextShape(0, 0, "Title", 15); 67 root.AddShape(titleShape); 68 69 canvas.MainCanvas.WorldShape = root; 70 canvas.Resize += delegate { UpdateLayout(); }; 71 72 UpdateLayout(); 73 44 74 CreateMouseEventListeners(); 45 75 46 76 this.model = model; 47 77 Item = model; 48 maxDataRowCount = 0; 78 79 maxDataRowCount = 0; 49 80 //The whole data rows are shown per default 50 81 zoomFullView = true; … … 53 84 } 54 85 86 /// <summary> 87 /// Layout management - arranges the inner shapes. 88 /// </summary> 89 private void UpdateLayout() { 90 root.ClippingArea = new RectangleD(0, 0, canvas.Width, canvas.Height); 91 92 titleShape.X = 10; 93 titleShape.Y = canvas.Height - 10; 94 95 linesShape.BoundingBox = new RectangleD(0, 20, canvas.Width, canvas.Height); 96 97 xAxis.BoundingBox = new RectangleD(linesShape.BoundingBox.X1, 98 0, 99 linesShape.BoundingBox.X2, 100 linesShape.BoundingBox.Y1); 101 } 102 55 103 public void ResetView() { 56 104 zoomFullView = true; 57 105 ZoomToFullView(); 58 canvasUI1.Invalidate(); 106 107 canvas.Invalidate(); 59 108 } 60 109 … … 68 117 model.ModelChanged += OnModelChanged; 69 118 70 foreach (IDataRow row in model.Rows) {119 foreach (IDataRow row in model.Rows) 71 120 OnDataRowAdded(row); 72 }73 121 } 74 122 … … 86 134 if (row.Count > maxDataRowCount) 87 135 maxDataRowCount = row.Count; 88 136 89 137 InitLineShapes(row); 90 InitXAxis();91 }92 93 private void InitXAxis() {94 int numLabels = 0;95 96 foreach (IDataRow row in model.Rows) {97 numLabels = Math.Max(numLabels, row.Count);98 }99 100 xAxis.ClearLabels();101 102 for (int i = 0; i < numLabels; i++) {103 xAxis.SetLabel(i, i.ToString());104 }105 138 } 106 139 107 140 private void ZoomToFullView() { 108 if (!zoomFullView)141 if (!zoomFullView) 109 142 return; 110 RectangleD newClippingArea = new RectangleD(-0.1, 111 minDataValue-((maxDataValue-minDataValue)*0.05), 112 maxDataRowCount-0.9, 113 maxDataValue + ((maxDataValue - minDataValue) * 0.05)); 114 root.ClippingArea = newClippingArea; 143 RectangleD newClippingArea = new RectangleD(-0.1, 144 minDataValue - ((maxDataValue - minDataValue)*0.05), 145 maxDataRowCount - 0.9, 146 maxDataValue + ((maxDataValue - minDataValue)*0.05)); 147 148 SetLineClippingArea(newClippingArea); 149 } 150 151 /// <summary> 152 /// Sets the clipping area of the data to display. 153 /// </summary> 154 /// <param name="clippingArea"></param> 155 private void SetLineClippingArea(RectangleD clippingArea) { 156 linesShape.ClippingArea = clippingArea; 157 xAxis.ClippingArea = new RectangleD(linesShape.ClippingArea.X1, 158 xAxis.BoundingBox.Y1, 159 linesShape.ClippingArea.X2, 160 xAxis.BoundingBox.Y2); 115 161 } 116 162 … … 125 171 lineShapes.Add(lineShape); 126 172 // TODO each DataRow needs its own WorldShape so Y Axes can be zoomed independently. 127 root.AddShape(lineShape);173 linesShape.AddShape(lineShape); 128 174 maxDataValue = Math.Max(row[i], maxDataValue); 129 175 minDataValue = Math.Min(row[i], minDataValue); … … 132 178 rowToLineShapes[row] = lineShapes; 133 179 ZoomToFullView(); 134 canvasUI1.Invalidate(); 180 181 canvas.Invalidate(); 135 182 } 136 183 … … 150 197 minDataValue = Math.Min(value, minDataValue); 151 198 152 if (index > lineShapes.Count + 1) {199 if (index > lineShapes.Count + 1) 153 200 throw new NotImplementedException(); 154 }155 201 156 202 // new value was added … … 161 207 lineShapes.Add(lineShape); 162 208 // TODO each DataRow needs its own WorldShape so Y Axes can be zoomed independently. 163 root.AddShape(lineShape);209 linesShape.AddShape(lineShape); 164 210 } 165 211 166 212 // not the first value 167 if (index > 0) {213 if (index > 0) 168 214 lineShapes[index - 1].Y2 = value; 169 }170 215 171 216 // not the last value 172 if (index > 0 && index < row.Count - 1) {217 if (index > 0 && index < row.Count - 1) 173 218 lineShapes[index].Y1 = value; 174 }175 219 ZoomToFullView(); 176 canvasUI1.Invalidate(); 220 221 canvas.Invalidate(); 177 222 } 178 223 179 224 // TODO use action parameter 180 225 private void OnRowValuesChanged(IDataRow row, double[] values, int index, Action action) { 181 foreach (double value in values) {226 foreach (double value in values) 182 227 OnRowValueChanged(row, value, index++, action); 183 } 184 } 185 186 private void OnModelChanged() { 187 InitXAxis(); 188 } 228 } 229 230 private void OnModelChanged() {} 189 231 190 232 #endregion … … 199 241 200 242 public void EndUpdate() { 201 if (beginUpdateCount == 0) {243 if (beginUpdateCount == 0) 202 244 throw new InvalidOperationException("Too many EndUpdates."); 203 }204 245 205 246 beginUpdateCount--; 206 247 207 if (beginUpdateCount == 0) { 208 Invalidate(); 209 } 248 if (beginUpdateCount == 0) 249 canvas.Invalidate(); 210 250 } 211 251 … … 230 270 if (ModifierKeys == Keys.Control) { 231 271 zoomListener.StartPoint = e.Location; 232 canvas UI1.MouseEventListener = zoomListener;272 canvas.MouseEventListener = zoomListener; 233 273 234 274 r = Rectangle.Empty; 235 rectangleShape = new RectangleShape(e.X, e.Y, e.X, e.Y, 1000,Color.Blue);275 rectangleShape = new RectangleShape(e.X, e.Y, e.X, e.Y, Color.Blue); 236 276 rectangleShape.Opacity = 50; 237 277 238 root.AddShape(rectangleShape);278 linesShape.AddShape(rectangleShape); 239 279 } else { 240 280 panListener.StartPoint = e.Location; 241 canvas UI1.MouseEventListener = panListener;242 243 startClippingArea = root.ClippingArea;281 canvas.MouseEventListener = panListener; 282 283 startClippingArea = linesShape.ClippingArea; 244 284 } 245 285 } 246 286 247 287 private void Pan_OnMouseUp(Point startPoint, Point actualPoint) { 248 canvas UI1.MouseEventListener = null;288 canvas.MouseEventListener = null; 249 289 } 250 290 251 291 private void Pan_OnMouseMove(Point startPoint, Point actualPoint) { 252 Rectangle viewPort = canvas UI1.ClientRectangle;292 Rectangle viewPort = canvas.ClientRectangle; 253 293 254 294 PointD worldStartPoint = Transform.ToWorld(startPoint, viewPort, startClippingArea); … … 264 304 newClippingArea.Y2 = startClippingArea.Y2 - yDiff; 265 305 266 root.ClippingArea = newClippingArea;306 SetLineClippingArea(newClippingArea); 267 307 panListener.StartPoint = startPoint; 268 308 269 309 zoomFullView = false; //user wants to pan => no full view 270 310 271 canvas UI1.Invalidate();311 canvas.Invalidate(); 272 312 } 273 313 274 314 private void Zoom_OnMouseUp(Point startPoint, Point actualPoint) { 275 canvas UI1.MouseEventListener = null;276 277 RectangleD newClippingArea = Transform.ToWorld(r, canvas UI1.ClientRectangle, root.ClippingArea);278 root.ClippingArea = newClippingArea;279 root.RemoveShape(rectangleShape);315 canvas.MouseEventListener = null; 316 317 RectangleD newClippingArea = Transform.ToWorld(r, canvas.ClientRectangle, linesShape.ClippingArea); 318 SetLineClippingArea(newClippingArea); 319 linesShape.RemoveShape(rectangleShape); 280 320 281 321 zoomFullView = false; //user wants to pan => no full view 282 322 283 canvas UI1.Invalidate();323 canvas.Invalidate(); 284 324 } 285 325 … … 306 346 } 307 347 308 rectangleShape.Rectangle = Transform.ToWorld(r, canvasUI1.ClientRectangle, root.ClippingArea); 309 canvasUI1.Invalidate(); 348 rectangleShape.Rectangle = Transform.ToWorld(r, canvas.ClientRectangle, linesShape.ClippingArea); 349 350 canvas.Invalidate(); 310 351 } 311 352 } -
trunk/sources/HeuristicLab.Visualization/RectangleShape.cs
r996 r1038 4 4 public class RectangleShape : IShape { 5 5 private RectangleD rectangle; 6 private double z;7 6 private Color color; 8 7 private int opacity = 255; 9 8 10 public RectangleShape(double x1, double y1, double x2, double y2, double z,Color color) {9 public RectangleShape(double x1, double y1, double x2, double y2, Color color) { 11 10 rectangle = new RectangleD(x1, y1, x2, y2); 12 this.z = z;13 11 this.color = color; 14 12 } … … 30 28 } 31 29 32 public double Z {33 get { return z; }34 set { z = value; }35 }36 37 30 public int Opacity { 38 31 get { return opacity; } … … 44 37 set { rectangle = value; } 45 38 } 39 40 public Color Color { 41 get { return color; } 42 set { color = value; } 43 } 46 44 } 47 45 } -
trunk/sources/HeuristicLab.Visualization/WorldShape.cs
r984 r1038 8 8 private RectangleD boundingBox; 9 9 10 pr ivatereadonly List<IShape> shapes = new List<IShape>();10 protected readonly List<IShape> shapes = new List<IShape>(); 11 11 12 12 public WorldShape(RectangleD clippingArea, RectangleD boundingBox) { … … 15 15 } 16 16 17 public v oid Draw(Graphics graphics, Rectangle viewport, RectangleD clippingArea) {17 public virtual void Draw(Graphics graphics, Rectangle viewport, RectangleD clippingArea) { 18 18 GraphicsState gstate = graphics.Save(); 19 19 … … 29 29 } 30 30 31 /// <summary>32 ///33 /// </summary>34 31 public RectangleD BoundingBox { 35 32 get { return boundingBox; } 33 set { boundingBox = value; } 36 34 } 37 35 … … 41 39 } 42 40 43 /// <summary>44 /// adds a shape to the WorldShape45 /// </summary>46 /// <param name="shape">shape to add</param>47 41 public void AddShape(IShape shape) { 48 42 shapes.Add(shape); -
trunk/sources/HeuristicLab.Visualization/XAxis.cs
r987 r1038 5 5 // TODO move to own file 6 6 public class TextShape : IShape { 7 private readonlydouble x;8 private readonlydouble y;7 private double x; 8 private double y; 9 9 private string text; 10 10 11 private Font font = new Font("Arial", 8); 12 private Brush brush = new SolidBrush(Color.Blue); 11 private Font font; 12 private Color color; 13 private Brush brush; 13 14 14 public TextShape(double x, double y, string text) { 15 public TextShape(double x, double y, string text) : this(x, y, text, 8) {} 16 17 public TextShape(double x, double y, string text, int fontSize) { 15 18 this.x = x; 16 19 this.y = y; 17 20 this.text = text; 21 this.font = new Font("Arial", fontSize); 22 23 this.Color = Color.Blue; 18 24 } 19 25 … … 33 39 set { text = value; } 34 40 } 41 42 public double X { 43 get { return x; } 44 set { x = value; } 45 } 46 47 public double Y { 48 get { return y; } 49 set { y = value; } 50 } 51 52 public Color Color { 53 get { return color; } 54 set { 55 this.color = value; 56 this.brush = new SolidBrush(color); 57 } 58 } 35 59 } 36 60 37 public class XAxis : CompositeShape { 38 private readonly List<TextShape> labels = new List<TextShape>(); 39 private readonly LineShape axisLine = new LineShape(0, 0, 0, 0, 0, Color.Black, 1, DrawingStyle.Solid); 61 public class XAxis : WorldShape { 62 private readonly IDictionary<int, TextShape> labels = new Dictionary<int, TextShape>(); 63 64 public XAxis(RectangleD clippingArea, RectangleD boundingBox) 65 : base(clippingArea, boundingBox) {} 40 66 41 67 public void ClearLabels() { 42 shapes.Clear();43 68 labels.Clear(); 69 } 44 70 45 shapes.Add(axisLine); 71 public void SetLabel(int i, string text) { 72 labels[i] = new TextShape(i, 0, text); 46 73 } 47 74 48 75 public override void Draw(Graphics graphics, Rectangle viewport, RectangleD clippingArea) { 49 axisLine.X1 = Transform.ToWorldX(viewport.Left, viewport, clippingArea); 50 axisLine.X2 = Transform.ToWorldX(viewport.Right, viewport, clippingArea); 76 shapes.Clear(); 77 78 for (int i = (int)(ClippingArea.X1 - 1); i <= ClippingArea.X2 + 1; i++) { 79 TextShape label; 80 81 if (labels.ContainsKey(i)) { 82 label = labels[i]; 83 } else { 84 label = new TextShape(i, 0, i.ToString()); 85 } 86 87 label.Y = ClippingArea.Height - 3; 88 89 shapes.Add(label); 90 } 51 91 52 92 base.Draw(graphics, viewport, clippingArea); 53 93 } 54 55 public void SetLabel(int i, string text) {56 while (i >= labels.Count) {57 TextShape label = new TextShape(i, 0, i.ToString());58 labels.Add(label);59 AddShape(label);60 }61 labels[i].Text = text;62 }63 94 } 64 95 }
Note: See TracChangeset
for help on using the changeset viewer.