Free cookie consent management tool by TermsFeed Policy Generator

Changeset 1187


Ignore:
Timestamp:
01/29/09 21:36:46 (16 years ago)
Author:
dwagner
Message:

Added OptionsDialog, min and max lines and fixed bug in auto-adjust. (#478) (#345)

Location:
trunk/sources/HeuristicLab.Visualization
Files:
4 added
5 edited

Legend:

Unmodified
Added
Removed
  • trunk/sources/HeuristicLab.Visualization/HeuristicLab.Visualization.csproj

    r1182 r1187  
    8383    <Compile Include="DefaultLabelProvider.cs" />
    8484    <Compile Include="Grid.cs" />
     85    <Compile Include="HorizontalLineShape.cs" />
    8586    <Compile Include="ILabelProvider.cs" />
    8687    <Compile Include="IMouseEventListener.cs" />
     88    <Compile Include="OptionsDialog.cs">
     89      <SubType>Form</SubType>
     90    </Compile>
     91    <Compile Include="OptionsDialog.Designer.cs">
     92      <DependentUpon>OptionsDialog.cs</DependentUpon>
     93    </Compile>
    8794    <Compile Include="PanListener.cs" />
    8895    <Compile Include="TextShape.cs" />
     
    138145      <SubType>Designer</SubType>
    139146    </EmbeddedResource>
     147    <EmbeddedResource Include="OptionsDialog.resx">
     148      <DependentUpon>OptionsDialog.cs</DependentUpon>
     149    </EmbeddedResource>
    140150  </ItemGroup>
    141151  <Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
  • trunk/sources/HeuristicLab.Visualization/LineChart.Designer.cs

    r1059 r1187  
    3131        private void InitializeComponent()
    3232        {
     33          this.components = new System.ComponentModel.Container();
    3334          this.canvas = new HeuristicLab.Visualization.CanvasUI();
     35          this.contextMenuStrip1 = new System.Windows.Forms.ContextMenuStrip(this.components);
     36          this.optionsToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem();
     37          this.contextMenuStrip1.SuspendLayout();
    3438          this.SuspendLayout();
    3539          //
     
    4347          this.canvas.TabIndex = 0;
    4448          this.canvas.Text = "canvas";
     49          this.canvas.MouseWheel += new System.Windows.Forms.MouseEventHandler(this.canvasUI1_MouseWheel);
     50          this.canvas.ContextMenuStripChanged += new System.EventHandler(this.optionsToolStripMenuItem_Click);
    4551          this.canvas.MouseDown += new System.Windows.Forms.MouseEventHandler(this.canvasUI1_MouseDown);
    46           this.canvas.MouseWheel += new System.Windows.Forms.MouseEventHandler(this.canvasUI1_MouseWheel);
    4752          this.canvas.KeyDown += new System.Windows.Forms.KeyEventHandler(this.canvasUI1_KeyDown);
     53          //
     54          // contextMenuStrip1
     55          //
     56          this.contextMenuStrip1.Items.AddRange(new System.Windows.Forms.ToolStripItem[] {
     57            this.optionsToolStripMenuItem});
     58          this.contextMenuStrip1.Name = "contextMenuStrip1";
     59          this.contextMenuStrip1.Size = new System.Drawing.Size(112, 26);
     60
     61          //
     62          // optionsToolStripMenuItem
     63          //
     64          this.optionsToolStripMenuItem.Name = "optionsToolStripMenuItem";
     65          this.optionsToolStripMenuItem.Size = new System.Drawing.Size(152, 22);
     66          this.optionsToolStripMenuItem.Text = "Options";
     67          this.optionsToolStripMenuItem.Click += new System.EventHandler(this.optionsToolStripMenuItem_Click);
    4868          //
    4969          // LineChart
     
    5474          this.Name = "LineChart";
    5575          this.Size = new System.Drawing.Size(552, 390);
     76          this.contextMenuStrip1.ResumeLayout(false);
    5677          this.ResumeLayout(false);
    5778
     
    6182
    6283        private CanvasUI canvas;
     84        private ContextMenuStrip contextMenuStrip1;
     85        private ToolStripMenuItem optionsToolStripMenuItem;
    6386    }
    6487}
  • trunk/sources/HeuristicLab.Visualization/LineChart.cs

    r1182 r1187  
    22using System.Collections.Generic;
    33using System.Drawing;
     4using System.Drawing.Drawing2D;
    45using System.Windows.Forms;
    56using HeuristicLab.Core;
    67
    78namespace HeuristicLab.Visualization {
    8   public class LinesShape : WorldShape { }
    9 
    109  public partial class LineChart : ViewBase {
     10    internal class LinesShape : WorldShape {}
     11
    1112    private readonly IChartDataRowsModel model;
    1213    private int maxDataRowCount;
     
    1415    private double minDataValue;
    1516    private double maxDataValue;
     17    private bool minMaxLineEnabled;
     18    private MinMaxLineShape minMaxLineShape;
     19    private IShape minLineShape;
    1620
    1721    private readonly WorldShape root;
     
    4549
    4650      grid = new Grid();
     51      minMaxLineEnabled = true;
    4752      root.AddShape(grid);
    4853
     
    6570      root.AddShape(titleShape);
    6671
    67 
     72      minMaxLineShape = new MinMaxLineShape(this.minDataValue, this.maxDataValue, 0, Color.Yellow, 4, DrawingStyle.Solid);
     73      root.AddShape(minMaxLineShape);
    6874      canvas.MainCanvas.WorldShape = root;
    6975      canvas.Resize += delegate { UpdateLayout(); };
    7076
    7177      UpdateLayout();
    72 
     78      maxDataRowCount = 0;
    7379      this.model = model;
    7480      Item = model;
    7581
    76       maxDataRowCount = 0;
     82
    7783      //The whole data rows are shown per default
    78       zoomFullView = true;
    79       minDataValue = Double.PositiveInfinity;
    80       maxDataValue = Double.NegativeInfinity;
     84      ResetView();
    8185    }
    8286
     
    97101                                              canvas.Width,
    98102                                              canvas.Height);
    99      
     103
    100104      grid.BoundingBox = linesShape.BoundingBox;
     105
     106      minMaxLineShape.BoundingBox = linesShape.BoundingBox;
    101107
    102108      yAxis.BoundingBox = new RectangleD(0,
     
    173179    private void SetLineClippingArea(RectangleD clippingArea) {
    174180      linesShape.ClippingArea = clippingArea;
    175      
     181
    176182      grid.ClippingArea = linesShape.ClippingArea;
     183
     184      minMaxLineShape.ClippingArea = linesShape.ClippingArea;
    177185
    178186      xAxis.ClippingArea = new RectangleD(linesShape.ClippingArea.X1,
     
    180188                                          linesShape.ClippingArea.X2,
    181189                                          xAxis.BoundingBox.Y2);
    182      
     190
    183191      yAxis.ClippingArea = new RectangleD(yAxis.BoundingBox.X1,
    184192                                          linesShape.ClippingArea.Y1,
     
    189197    private void InitLineShapes(IDataRow row) {
    190198      List<LineShape> lineShapes = new List<LineShape>();
     199      if (rowToLineShapes.Count == 0) {
     200        minDataValue = Double.PositiveInfinity;
     201        maxDataValue = Double.NegativeInfinity;
     202      }
    191203      if (row.Count > 0) {
    192204        maxDataValue = Math.Max(row[0], maxDataValue);
     
    201213        minDataValue = Math.Min(row[i], minDataValue);
    202214      }
    203 
     215      minMaxLineShape.YMax = maxDataValue;
     216      minMaxLineShape.YMin = minDataValue;
    204217      rowToLineShapes[row] = lineShapes;
    205218      ZoomToFullView();
     
    213226    }
    214227
    215     private readonly IDictionary<IDataRow, List<LineShape>> rowToLineShapes = new Dictionary<IDataRow, List<LineShape>>();
     228    private readonly IDictionary<IDataRow, List<LineShape>> rowToLineShapes =
     229      new Dictionary<IDataRow, List<LineShape>>();
    216230
    217231    // TODO use action parameter
     
    220234      maxDataValue = Math.Max(value, maxDataValue);
    221235      minDataValue = Math.Min(value, minDataValue);
    222 
     236      minMaxLineShape.YMax = maxDataValue;
     237      minMaxLineShape.YMin = minDataValue;
    223238      if (index > lineShapes.Count + 1) {
    224239        throw new NotImplementedException();
     
    230245          maxDataRowCount = row.Count;
    231246        }
    232         LineShape lineShape = new LineShape(index - 1, row[index - 1], index, row[index], 0, row.Color, row.Thickness, row.Style);
     247        LineShape lineShape = new LineShape(index - 1, row[index - 1], index, row[index], 0, row.Color, row.Thickness,
     248                                            row.Style);
    233249        lineShapes.Add(lineShape);
    234250        // TODO each DataRow needs its own WorldShape so Y Axes can be zoomed independently.
     
    249265      canvas.Invalidate();
    250266    }
     267
     268
     269    public IList<IDataRow> GetRows() {
     270      return model.Rows;
     271    }
     272
    251273
    252274    // TODO use action parameter
     
    293315
    294316    private void canvasUI1_KeyDown(object sender, KeyEventArgs e) {
    295       if(e.KeyCode == Keys.Back && historyStack.Count > 1) {
     317      if (e.KeyCode == Keys.Back && historyStack.Count > 1) {
    296318        historyStack.Pop();
    297319
    298320        RectangleD clippingArea = historyStack.Peek();
    299  
     321
    300322        SetNewClippingArea(clippingArea);
    301323        canvas.Invalidate();
     
    305327    private void canvasUI1_MouseDown(object sender, MouseEventArgs e) {
    306328      Focus();
    307 
    308       if (ModifierKeys == Keys.Control) {
    309         CreateZoomListener(e);
    310       } else {
    311         CreatePanListener(e);
     329      if (e.Button == System.Windows.Forms.MouseButtons.Right) {
     330        if (this.ParentForm != null)
     331          this.contextMenuStrip1.Show(e.Location.X + this.ParentForm.Location.X,
     332                                      e.Location.Y + this.ParentForm.Location.Y + 50);
     333        else {
     334          this.contextMenuStrip1.Show(e.Location.X, e.Location.Y);
     335        }
     336      }
     337      else {
     338        if (ModifierKeys == Keys.Control) {
     339          CreateZoomListener(e);
     340        }
     341        else {
     342          CreatePanListener(e);
     343        }
    312344      }
    313345    }
     
    362394      panListener.SetNewClippingArea += SetNewClippingArea;
    363395      panListener.OnMouseUp += delegate {
    364         historyStack.Push(linesShape.ClippingArea);
    365         canvas.MouseEventListener = null;
    366       };
     396                                 historyStack.Push(linesShape.ClippingArea);
     397                                 canvas.MouseEventListener = null;
     398                               };
    367399
    368400      canvas.MouseEventListener = panListener;
     
    377409
    378410    #endregion
     411
     412    private void optionsToolStripMenuItem_Click(object sender, EventArgs e) {
     413      var optionsdlg = new OptionsDialog(this);
     414      optionsdlg.Show();
     415    }
     416
     417    public void ApplyChangesToRow(IDataRow row) {
     418      foreach (var ls in rowToLineShapes[row]) {
     419        ls.LSColor = row.Color;
     420        ls.LSThickness = row.Thickness;
     421        if (row.Style == DrawingStyle.Dashed) {
     422          ls.LSDashStyle = DashStyle.Dash;
     423        }
     424        else {
     425          ls.LSDashStyle = DashStyle.Solid; //default
     426        }
     427      }
     428      canvas.Invalidate();
     429    }
    379430  }
    380431}
  • trunk/sources/HeuristicLab.Visualization/LineChart.resx

    r684 r1187  
    118118    <value>System.Resources.ResXResourceWriter, System.Windows.Forms, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
    119119  </resheader>
     120  <metadata name="contextMenuStrip1.TrayLocation" type="System.Drawing.Point, System.Drawing, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a">
     121    <value>17, 17</value>
     122  </metadata>
    120123</root>
  • trunk/sources/HeuristicLab.Visualization/LineShape.cs

    r980 r1187  
    2121      this.boundingBox = new RectangleD(x1, y1, x2, y2);
    2222      this.z = z;
    23       this.color = color;
    24       this.thickness = thickness;
     23      this.LSColor = color;
     24      this.LSThickness = thickness;
    2525      if (style==DrawingStyle.Dashed) {
    26         this.dashStyle = DashStyle.Dash;
     26        this.LSDashStyle = DashStyle.Dash;
    2727      }
    2828      else {
    29         this.dashStyle = DashStyle.Solid;        //default
     29        this.LSDashStyle = DashStyle.Solid;        //default
    3030      }
    3131    }
     
    6262    /// <param name="clippingArea">rectangle in screen-coordinates to draw</param>
    6363    public void Draw(Graphics graphics, Rectangle viewport, RectangleD clippingArea) {
    64       using (Pen pen = new Pen(color, thickness)){
    65         pen.DashStyle = this.dashStyle;
     64      using (Pen pen = new Pen(LSColor, LSThickness)){
     65        pen.DashStyle = this.LSDashStyle;
    6666        Rectangle screenRect = Transform.ToScreen(boundingBox, viewport, clippingArea);
    6767        graphics.DrawLine(pen,screenRect.Left, screenRect.Bottom, screenRect.Right, screenRect.Top);
     
    7373      set { z = value; }
    7474    }
     75
     76    public Color LSColor {
     77      get { return color; }
     78      set { color = value; }
     79    }
     80
     81    public int LSThickness {
     82      get { return thickness; }
     83      set { thickness = value; }
     84    }
     85
     86    public DashStyle LSDashStyle {
     87      get { return dashStyle; }
     88      set { dashStyle = value; }
     89    }
    7590  }
    7691}
Note: See TracChangeset for help on using the changeset viewer.