Free cookie consent management tool by TermsFeed Policy Generator

Changeset 1883 for trunk/sources


Ignore:
Timestamp:
05/23/09 10:35:51 (15 years ago)
Author:
dwagner
Message:

Bug fix: No marker on first added value (#581)
New feature: Tooltip, which shows the world-values on mouseover event of a datapoint. (#638)
New feature: New Linetype Points, which is a line consisting only of the markers (#637)

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  
    5858    }
    5959
     60
     61    /// <summary>
     62    /// Adds a shape to the container
     63    /// </summary>
     64    /// <param name="shape"> the Shape to add</param>
    6065    public void AddShape(IShape shape) {
    6166      shape.Parent = this;
     
    7176      shapes.Add(shape);
    7277    }
     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    }
    73101  }
    74102}
  • trunk/sources/HeuristicLab.Visualization/3.2/HeuristicLab.Visualization-3.2.csproj

    r1882 r1883  
    161161    <Compile Include="RectangleShape.cs" />
    162162    <Compile Include="SizeD.cs" />
     163    <Compile Include="TooltipListener.cs" />
    163164    <Compile Include="Transform.cs" />
    164165    <Compile Include="Translate.cs" />
  • trunk/sources/HeuristicLab.Visualization/3.2/IDataRow.cs

    r1561 r1883  
    33namespace HeuristicLab.Visualization {
    44  public enum DataRowType {
    5     Normal, SingleValue
     5    Normal, SingleValue,
     6    Points
    67  }
    78
  • trunk/sources/HeuristicLab.Visualization/3.2/LineChart.cs

    r1881 r1883  
    3131    private const int YAxisWidth = 100;
    3232    private const int XAxisHeight = 40;
     33    private readonly TooltipListener toolTipListener;
     34    private readonly ToolTip valueToolTip;
     35    private Point currentMousePos;
    3336
    3437    /// <summary>
     
    5558
    5659      Item = model;
     60
     61      valueToolTip = new ToolTip();
     62      toolTipListener = new TooltipListener();
     63      toolTipListener.ShowToolTip += ShowToolTip;
     64      mouseEventListener = toolTipListener;
     65      currentMousePos = new Point(0, 0);
    5766
    5867      this.ResizeRedraw = true;
     
    137146      canvas.AddShape(titleShape);
    138147      canvas.AddShape(legendShape);
    139 
    140148      canvas.AddShape(userInteractionShape);
    141149
     
    160168
    161169      int yAxisLeft = 0;
    162       int yAxisRight = (int)linesAreaBoundingBox.X2;
     170      int yAxisRight = (int) linesAreaBoundingBox.X2;
    163171
    164172      foreach (YAxisDescriptor yAxisDescriptor in model.YAxes) {
     
    187195
    188196      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);
    190199
    191200      xAxis.BoundingBox = new RectangleD(linesAreaBoundingBox.X1,
     
    199208    private readonly Dictionary<YAxisDescriptor, YAxisInfo> yAxisInfos = new Dictionary<YAxisDescriptor, YAxisInfo>();
    200209
     210    /// <summary>
     211    ///
     212    /// </summary>
     213    /// <param name="yAxisDescriptor"></param>
     214    /// <returns></returns>
    201215    private YAxisInfo GetYAxisInfo(YAxisDescriptor yAxisDescriptor) {
    202216      YAxisInfo info;
     
    209223      return info;
    210224    }
     225
     226
     227    #region Legend-specific
    211228
    212229    /// <summary>
     
    235252    public void setLegendRight() {
    236253      // 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);
    238256      legendShape.ClippingArea = new RectangleD(0, 0, legendShape.BoundingBox.Width, legendShape.BoundingBox.Height);
    239257      legendShape.Row = false;
     
    253271    public void setLegendTop() {
    254272      // 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);
    256275      legendShape.ClippingArea = new RectangleD(0, 0, legendShape.BoundingBox.Width, legendShape.BoundingBox.Height);
    257276      legendShape.Row = true;
     
    269288    }
    270289
     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
    271316    private void optionsToolStripMenuItem_Click(object sender, EventArgs e) {
    272317      OptionsDialog optionsdlg = new OptionsDialog(model);
    273318      optionsdlg.Show();
     319      mouseEventListener = toolTipListener;
    274320    }
    275321
     
    408454    }
    409455
     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>
    410460    private void InitLineShapes(IDataRow row) {
    411461      RowEntry rowEntry = new RowEntry(row);
     
    419469          rowEntry.LinesShape.AddShape(lineShape);
    420470        }
    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) {
    422476        rowEntry.showMarkers(row.ShowMarkers);
    423477        for (int i = 1; i < row.Count; i++) {
     
    434488    }
    435489
     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>
    436497    private void OnRowValueChanged(IDataRow row, double value, int index, Action action) {
    437498      RowEntry rowEntry = rowToRowEntry[row];
     
    442503                                                        row.Style);
    443504          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){
    445508          LineShape lineShape = rowEntry.LinesShape.GetShape(0);
    446509          lineShape.Y1 = value;
    447510          lineShape.Y2 = value;
    448511        }
    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) {
    455513        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));
    457516          if (index > 0 && index == rowEntry.LinesShape.Count + 1) {
    458517            LineShape lineShape = new LineShape(index - 1, row[index - 1], index, row[index], row.Color, row.Thickness,
     
    460519            rowEntry.LinesShape.AddShape(lineShape);
    461520            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!");
    462523          }
    463524        } else if (action == Action.Modified) {
     
    465526          if (index > 0) {
    466527            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;
    468529          }
    469530
    470531          // not the last value
    471           if (index > 0 && index < row.Count - 1) {
     532          if (index < row.Count - 1) {
    472533            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!");
    475575        }
    476576      }
     
    520620      foreach (RowEntry rowEntry in rowEntries) {
    521621        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);
    523624          SetClipY(rowEntry, clippingArea.Y1, clippingArea.Y2);
    524625        }
     
    550651
    551652    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);
    553655      canvasUI.Invalidate();
    554656    }
     
    560662
    561663      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));
    563667      } else if (e.Button == MouseButtons.Left) {
    564668        if (ModifierKeys == Keys.None) {
     
    582686
    583687    private void canvasUI_MouseMove(object sender, MouseEventArgs e) {
     688      if (currentMousePos == e.Location)
     689        return;
    584690      if (mouseEventListener != null) {
    585691        mouseEventListener.MouseMove(sender, e);
    586692      }
     693
     694      currentMousePos = e.Location;
    587695    }
    588696
     
    592700      }
    593701
    594       mouseEventListener = null;
     702      mouseEventListener = toolTipListener;
    595703    }
    596704
     
    640748          }
    641749        }
    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>
    645757      public override void Draw(Graphics graphics) {
    646758        GraphicsState gstate = graphics.Save();
     
    660772      }
    661773
     774      public void RemoveMarkerShape(IShape shape) {
     775        shape.Parent = this;
     776        markersShape.RemoveShape(shape);
     777      }
     778
    662779      public int Count {
    663780        get { return shapes.Count; }
     
    665782
    666783      public LineShape GetShape(int index) {
    667         return (LineShape)shapes[index]; //shapes[0] is markersShape!!
     784        return (LineShape) shapes[index]; //shapes[0] is markersShape!!
    668785      }
    669786    }
Note: See TracChangeset for help on using the changeset viewer.