Changeset 1883 for trunk/sources
- Timestamp:
- 05/23/09 10:35:51 (16 years ago)
- Location:
- trunk/sources/HeuristicLab.Visualization/3.2
- Files:
-
- 1 added
- 4 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/sources/HeuristicLab.Visualization/3.2/CompositeShape.cs
r1559 r1883 58 58 } 59 59 60 61 /// <summary> 62 /// Adds a shape to the container 63 /// </summary> 64 /// <param name="shape"> the Shape to add</param> 60 65 public void AddShape(IShape shape) { 61 66 shape.Parent = this; … … 71 76 shapes.Add(shape); 72 77 } 78 79 /// <summary> 80 /// Recalculate the bounding box 81 /// </summary> 82 private void InitBoundingBox() { 83 if (shapes.Count > 0) 84 boundingBox = shapes[0].BoundingBox; 85 foreach (var shape in shapes) { 86 boundingBox = new RectangleD(Math.Min(boundingBox.X1, shape.BoundingBox.X1), 87 Math.Min(boundingBox.Y1, shape.BoundingBox.Y1), 88 Math.Max(boundingBox.X2, shape.BoundingBox.X2), 89 Math.Max(boundingBox.Y2, shape.BoundingBox.Y2)); 90 } 91 } 92 93 /// <summary> 94 /// Removes a Shape from the container and reinitializes the bounding box 95 /// </summary> 96 /// <param name="shape">the Shape to remove</param> 97 public void RemoveShape(IShape shape) { 98 shapes.Remove(shape); 99 InitBoundingBox(); 100 } 73 101 } 74 102 } -
trunk/sources/HeuristicLab.Visualization/3.2/HeuristicLab.Visualization-3.2.csproj
r1882 r1883 161 161 <Compile Include="RectangleShape.cs" /> 162 162 <Compile Include="SizeD.cs" /> 163 <Compile Include="TooltipListener.cs" /> 163 164 <Compile Include="Transform.cs" /> 164 165 <Compile Include="Translate.cs" /> -
trunk/sources/HeuristicLab.Visualization/3.2/IDataRow.cs
r1561 r1883 3 3 namespace HeuristicLab.Visualization { 4 4 public enum DataRowType { 5 Normal, SingleValue 5 Normal, SingleValue, 6 Points 6 7 } 7 8 -
trunk/sources/HeuristicLab.Visualization/3.2/LineChart.cs
r1881 r1883 31 31 private const int YAxisWidth = 100; 32 32 private const int XAxisHeight = 40; 33 private readonly TooltipListener toolTipListener; 34 private readonly ToolTip valueToolTip; 35 private Point currentMousePos; 33 36 34 37 /// <summary> … … 55 58 56 59 Item = model; 60 61 valueToolTip = new ToolTip(); 62 toolTipListener = new TooltipListener(); 63 toolTipListener.ShowToolTip += ShowToolTip; 64 mouseEventListener = toolTipListener; 65 currentMousePos = new Point(0, 0); 57 66 58 67 this.ResizeRedraw = true; … … 137 146 canvas.AddShape(titleShape); 138 147 canvas.AddShape(legendShape); 139 140 148 canvas.AddShape(userInteractionShape); 141 149 … … 160 168 161 169 int yAxisLeft = 0; 162 int yAxisRight = (int) linesAreaBoundingBox.X2;170 int yAxisRight = (int) linesAreaBoundingBox.X2; 163 171 164 172 foreach (YAxisDescriptor yAxisDescriptor in model.YAxes) { … … 187 195 188 196 userInteractionShape.BoundingBox = linesAreaBoundingBox; 189 userInteractionShape.ClippingArea = new RectangleD(0, 0, userInteractionShape.BoundingBox.Width, userInteractionShape.BoundingBox.Height); 197 userInteractionShape.ClippingArea = new RectangleD(0, 0, userInteractionShape.BoundingBox.Width, 198 userInteractionShape.BoundingBox.Height); 190 199 191 200 xAxis.BoundingBox = new RectangleD(linesAreaBoundingBox.X1, … … 199 208 private readonly Dictionary<YAxisDescriptor, YAxisInfo> yAxisInfos = new Dictionary<YAxisDescriptor, YAxisInfo>(); 200 209 210 /// <summary> 211 /// 212 /// </summary> 213 /// <param name="yAxisDescriptor"></param> 214 /// <returns></returns> 201 215 private YAxisInfo GetYAxisInfo(YAxisDescriptor yAxisDescriptor) { 202 216 YAxisInfo info; … … 209 223 return info; 210 224 } 225 226 227 #region Legend-specific 211 228 212 229 /// <summary> … … 235 252 public void setLegendRight() { 236 253 // legend right 237 legendShape.BoundingBox = new RectangleD(canvasUI.Width - legendShape.GetMaxLabelLength(), 10, canvasUI.Width, canvasUI.Height - 50); 254 legendShape.BoundingBox = new RectangleD(canvasUI.Width - legendShape.GetMaxLabelLength(), 10, canvasUI.Width, 255 canvasUI.Height - 50); 238 256 legendShape.ClippingArea = new RectangleD(0, 0, legendShape.BoundingBox.Width, legendShape.BoundingBox.Height); 239 257 legendShape.Row = false; … … 253 271 public void setLegendTop() { 254 272 // legend top 255 legendShape.BoundingBox = new RectangleD(100, canvasUI.Height - canvasUI.Height, canvasUI.Width, canvasUI.Height - 10); 273 legendShape.BoundingBox = new RectangleD(100, canvasUI.Height - canvasUI.Height, canvasUI.Width, 274 canvasUI.Height - 10); 256 275 legendShape.ClippingArea = new RectangleD(0, 0, legendShape.BoundingBox.Width, legendShape.BoundingBox.Height); 257 276 legendShape.Row = true; … … 269 288 } 270 289 290 #endregion 291 292 /// <summary> 293 /// Shows the Tooltip with the real values of a datapoint, if the mousepoint is near to one 294 /// </summary> 295 /// <param name="location"></param> 296 private void ShowToolTip(Point location) { 297 valueToolTip.Hide(this); 298 if (rowEntries.Count > 0) { 299 double dx = Transform.ToWorldX(location.X, this.rowEntries[0].LinesShape.Viewport, 300 this.rowEntries[0].LinesShape.ClippingArea); 301 int ix = (int) Math.Round(dx); 302 foreach (var rowEntry in rowEntries) { 303 if ((rowEntry.DataRow.Count > ix) && (ix > 0) && ((rowEntry.DataRow.LineType == DataRowType.Normal)||(rowEntry.DataRow.LineType==DataRowType.Points))) { 304 Point screenDataP = Transform.ToScreen(new PointD(ix, rowEntry.DataRow[ix]), rowEntry.LinesShape.Viewport, 305 rowEntry.LinesShape.ClippingArea); 306 if ((Math.Abs(screenDataP.X - location.X) <= 6) && (Math.Abs(screenDataP.Y - location.Y) <= 6)) { 307 valueToolTip.Show(("\t x:" + ix + " y:" + rowEntry.DataRow[ix]), this, screenDataP.X, screenDataP.Y); 308 } 309 } 310 } 311 } 312 } 313 314 315 271 316 private void optionsToolStripMenuItem_Click(object sender, EventArgs e) { 272 317 OptionsDialog optionsdlg = new OptionsDialog(model); 273 318 optionsdlg.Show(); 319 mouseEventListener = toolTipListener; 274 320 } 275 321 … … 408 454 } 409 455 456 /// <summary> 457 /// Creates the shapes for the data of the given row and stores them. 458 /// </summary> 459 /// <param name="row">Datarow, whose data items should be converted to shapes</param> 410 460 private void InitLineShapes(IDataRow row) { 411 461 RowEntry rowEntry = new RowEntry(row); … … 419 469 rowEntry.LinesShape.AddShape(lineShape); 420 470 } 421 } else { 471 } else if (row.LineType == DataRowType.Points) { 472 rowEntry.showMarkers(true); //no lines, only markers are shown!! 473 for (int i = 0; i < row.Count; i++) 474 rowEntry.LinesShape.AddMarkerShape(new MarkerShape(i , row[i], 8, row.Color)); 475 } else if (row.LineType == DataRowType.Normal) { 422 476 rowEntry.showMarkers(row.ShowMarkers); 423 477 for (int i = 1; i < row.Count; i++) { … … 434 488 } 435 489 490 /// <summary> 491 /// Handles the event, when a value of a datarow was changed 492 /// </summary> 493 /// <param name="row">row in which the data was changed</param> 494 /// <param name="value">new value of the data point</param> 495 /// <param name="index">index in the datarow of the changed datapoint</param> 496 /// <param name="action">the performed action (added, modified, deleted)</param> 436 497 private void OnRowValueChanged(IDataRow row, double value, int index, Action action) { 437 498 RowEntry rowEntry = rowToRowEntry[row]; … … 442 503 row.Style); 443 504 rowEntry.LinesShape.AddShape(lineShape); 444 } else { 505 } else if(action==Action.Deleted) { 506 throw new ArgumentException("It is unwise to delete the only value of the SinglevalueRow!!"); 507 }else if(action ==Action.Modified){ 445 508 LineShape lineShape = rowEntry.LinesShape.GetShape(0); 446 509 lineShape.Y1 = value; 447 510 lineShape.Y2 = value; 448 511 } 449 } else { 450 if (index > rowEntry.LinesShape.Count + 1) { 451 //MarkersShape is on position zero 452 throw new NotImplementedException(); 453 } 454 512 } else if (row.LineType == DataRowType.Points) { 455 513 if (action == Action.Added) { 456 // new value was added 514 if(rowEntry.LinesShape.Count==0) 515 rowEntry.LinesShape.AddMarkerShape(new MarkerShape(0, row[0], 8, row.Color)); 457 516 if (index > 0 && index == rowEntry.LinesShape.Count + 1) { 458 517 LineShape lineShape = new LineShape(index - 1, row[index - 1], index, row[index], row.Color, row.Thickness, … … 460 519 rowEntry.LinesShape.AddShape(lineShape); 461 520 rowEntry.LinesShape.AddMarkerShape(new MarkerShape(index, row[index], 8, row.Color)); 521 } else { 522 throw new ArgumentException("Adding a value is only possible at the end of a row!"); 462 523 } 463 524 } else if (action == Action.Modified) { … … 465 526 if (index > 0) { 466 527 rowEntry.LinesShape.GetShape(index - 1).Y2 = value; 467 ((MarkerShape) rowEntry.LinesShape.markersShape.GetShape(index - 1)).Y = value;528 ((MarkerShape) rowEntry.LinesShape.markersShape.GetShape(index - 1)).Y = value; 468 529 } 469 530 470 531 // not the last value 471 if (index > 0 && index< row.Count - 1) {532 if (index < row.Count - 1) { 472 533 rowEntry.LinesShape.GetShape(index).Y1 = value; 473 ((MarkerShape)rowEntry.LinesShape.markersShape.GetShape(index)).Y = value; 474 } 534 ((MarkerShape) rowEntry.LinesShape.markersShape.GetShape(index)).Y = value; 535 } 536 } else if(action == Action.Deleted) { 537 if (index == row.Count - 1) 538 rowEntry.LinesShape.RemoveMarkerShape(rowEntry.LinesShape.markersShape.GetShape(index)); 539 else 540 throw new NotSupportedException("Deleting of values other than the last one is not supported!"); 541 } 542 543 } else if (row.LineType == DataRowType.Normal) { 544 if (index > rowEntry.LinesShape.Count + 1) { 545 throw new NotImplementedException(); 546 } 547 548 if (action == Action.Added) { 549 if (rowEntry.LinesShape.Count == 0) 550 rowEntry.LinesShape.AddMarkerShape(new MarkerShape(0, row[0], 8, row.Color)); 551 if (index > 0 && index == rowEntry.LinesShape.Count + 1) { 552 LineShape lineShape = new LineShape(index-1, row[index-1], index, row[index], row.Color, row.Thickness, 553 row.Style); 554 rowEntry.LinesShape.AddShape(lineShape); 555 rowEntry.LinesShape.AddMarkerShape(new MarkerShape(index, row[index], 8, row.Color)); 556 } 557 } else if (action == Action.Modified) { 558 // not the first value 559 if (index > 0) { 560 rowEntry.LinesShape.GetShape(index - 1).Y2 = value; 561 ((MarkerShape) rowEntry.LinesShape.markersShape.GetShape(index - 1)).Y = value; 562 } 563 564 // not the last value 565 if (index < row.Count - 1) { 566 rowEntry.LinesShape.GetShape(index).Y1 = value; 567 ((MarkerShape) rowEntry.LinesShape.markersShape.GetShape(index)).Y = value; 568 } 569 } else if (action == Action.Deleted) { 570 if (index == row.Count - 1) { 571 rowEntry.LinesShape.RemoveMarkerShape(rowEntry.LinesShape.markersShape.GetShape(index)); 572 rowEntry.LinesShape.RemoveShape(rowEntry.LinesShape.GetShape(index)); 573 } else 574 throw new NotSupportedException("Deleting of values other than the last one is not supported!"); 475 575 } 476 576 } … … 520 620 foreach (RowEntry rowEntry in rowEntries) { 521 621 if (rowEntry.DataRow.YAxis.ClipChangeable) { 522 clippingArea = Translate.ClippingArea(startPoint, endPoint, rowEntry.LinesShape.ClippingArea, rowEntry.LinesShape.Viewport); 622 clippingArea = Translate.ClippingArea(startPoint, endPoint, rowEntry.LinesShape.ClippingArea, 623 rowEntry.LinesShape.Viewport); 523 624 SetClipY(rowEntry, clippingArea.Y1, clippingArea.Y2); 524 625 } … … 550 651 551 652 private void DrawRectangle(Rectangle rectangle) { 552 rectangleShape.Rectangle = Transform.ToWorld(rectangle, userInteractionShape.Viewport, userInteractionShape.ClippingArea); 653 rectangleShape.Rectangle = Transform.ToWorld(rectangle, userInteractionShape.Viewport, 654 userInteractionShape.ClippingArea); 553 655 canvasUI.Invalidate(); 554 656 } … … 560 662 561 663 if (e.Button == MouseButtons.Right) { 562 contextMenu.Show(PointToScreen(e.Location)); 664 valueToolTip.Hide(this); 665 mouseEventListener = null; 666 this.contextMenu.Show(PointToScreen(e.Location)); 563 667 } else if (e.Button == MouseButtons.Left) { 564 668 if (ModifierKeys == Keys.None) { … … 582 686 583 687 private void canvasUI_MouseMove(object sender, MouseEventArgs e) { 688 if (currentMousePos == e.Location) 689 return; 584 690 if (mouseEventListener != null) { 585 691 mouseEventListener.MouseMove(sender, e); 586 692 } 693 694 currentMousePos = e.Location; 587 695 } 588 696 … … 592 700 } 593 701 594 mouseEventListener = null;702 mouseEventListener = toolTipListener; 595 703 } 596 704 … … 640 748 } 641 749 } 642 this.markersShape.ShowChildShapes = row.ShowMarkers; 643 } 644 750 markersShape.ShowChildShapes = row.ShowMarkers; 751 } 752 753 /// <summary> 754 /// Draws all Shapes in the chart 755 /// </summary> 756 /// <param name="graphics"></param> 645 757 public override void Draw(Graphics graphics) { 646 758 GraphicsState gstate = graphics.Save(); … … 660 772 } 661 773 774 public void RemoveMarkerShape(IShape shape) { 775 shape.Parent = this; 776 markersShape.RemoveShape(shape); 777 } 778 662 779 public int Count { 663 780 get { return shapes.Count; } … … 665 782 666 783 public LineShape GetShape(int index) { 667 return (LineShape) shapes[index]; //shapes[0] is markersShape!!784 return (LineShape) shapes[index]; //shapes[0] is markersShape!! 668 785 } 669 786 }
Note: See TracChangeset
for help on using the changeset viewer.