Free cookie consent management tool by TermsFeed Policy Generator

Changeset 1233


Ignore:
Timestamp:
02/28/09 21:21:59 (15 years ago)
Author:
mstoeger
Message:

General housekeeping (#498) Removed some old unused Z-Order values. Replaced some var types by concrete types. Renamed some LineShape properties. Added caching of Pens and Brushes in LineShape and RectangleShape. Put axis tick calculation algorithm into its own class.

Location:
trunk/sources
Files:
3 added
13 edited
1 moved

Legend:

Unmodified
Added
Removed
  • trunk/sources/HeuristicLab.Visualization.Test/LegendForm.cs

    r1195 r1233  
    11using System.Drawing;
    22using System.Windows.Forms;
     3using HeuristicLab.Visualization.Legend;
    34
    45namespace HeuristicLab.Visualization.Test {
     
    910
    1011      CreateLegendShape();
    11 
    1212    }
    1313
  • trunk/sources/HeuristicLab.Visualization/DataRow.cs

    r1194 r1233  
    2121    private DrawingStyle style = DrawingStyle.Solid;
    2222    private DataRowType lineType = DataRowType.Normal;
    23     private List<double> dataRow = new List<double>();
     23    private readonly List<double> dataRow = new List<double>();
    2424
    2525    private ILabelProvider labelProvider = new ContinuousLabelProvider("0.##");
     
    4141    }
    4242
    43 
    4443    public DataRow() {
    4544    }
     
    4847      this.Label = label;
    4948    }
    50    
    5149
    5250    public DataRow(string label, Color color, int thickness, DrawingStyle style, List<double> dataRow) {
     
    5856    }
    5957
    60     /// <summary>
    61     /// Raised when data row data changed. Should cause redraw in the view.
    62     /// </summary>
    6358    public event DataRowChangedHandler DataRowChanged;
    6459
     
    130125        OnValueChanged(value, index, Action.Added);
    131126      } else {
    132         throw new System.IndexOutOfRangeException();
     127        throw new IndexOutOfRangeException();
    133128      }   
    134129    }
     
    154149        OnValuesChanged(values, index, Action.Added);
    155150      } else {
    156         throw new System.IndexOutOfRangeException();
     151        throw new IndexOutOfRangeException();
    157152      }
    158153    }
     
    164159        OnValueChanged(value, index, Action.Modified);
    165160      } else {
    166         throw new System.IndexOutOfRangeException();
     161        throw new IndexOutOfRangeException();
    167162      }
    168163    }
     
    180175        OnValuesChanged(values, startInd, Action.Modified);
    181176      } else {
    182         throw new System.IndexOutOfRangeException();
     177        throw new IndexOutOfRangeException();
    183178      }
    184179    }
     
    191186        OnValueChanged(remVal, index, Action.Deleted);
    192187      } else {
    193         throw new System.IndexOutOfRangeException();
     188        throw new IndexOutOfRangeException();
    194189      }
    195190    }
     
    210205          OnValuesChanged(remValues, index, Action.Deleted);
    211206        } else {
    212           throw new System.IndexOutOfRangeException();
     207          throw new IndexOutOfRangeException();
    213208        }
    214209      } else {
    215         throw new System.Exception("parameter count must be > 0!");
     210        throw new Exception("parameter count must be > 0!");
    216211      }
    217212    }
  • trunk/sources/HeuristicLab.Visualization/Grid.cs

    r1182 r1233  
    66      shapes.Clear();
    77
    8       foreach (double y in XAxis.GetTicks(YAxis.PixelsPerInterval,
    9                                           viewport.Height,
    10                                           ClippingArea.Height,
    11                                           ClippingArea.Y1)) {
     8      foreach (double y in AxisTicks.GetTicks(YAxis.PixelsPerInterval,
     9                                              viewport.Height,
     10                                              ClippingArea.Height,
     11                                              ClippingArea.Y1)) {
    1212        LineShape line = new LineShape(ClippingArea.X1, y,
    1313                                       ClippingArea.X2, y,
    14                                        0, Color.LightBlue, 1, DrawingStyle.Dashed);
     14                                       Color.LightBlue, 1,
     15                                       DrawingStyle.Dashed);
    1516        shapes.Add(line);
    1617      }
    1718
    18       foreach (double x in XAxis.GetTicks(XAxis.PixelsPerInterval,
    19                                           viewport.Width,
    20                                           ClippingArea.Width,
    21                                           ClippingArea.X1)) {
     19      foreach (double x in AxisTicks.GetTicks(XAxis.PixelsPerInterval,
     20                                              viewport.Width,
     21                                              ClippingArea.Width,
     22                                              ClippingArea.X1)) {
    2223        LineShape line = new LineShape(x, ClippingArea.Y1,
    2324                                       x, ClippingArea.Y2,
    24                                        0, Color.LightBlue, 1, DrawingStyle.Dashed);
     25                                       Color.LightBlue, 1,
     26                                       DrawingStyle.Dashed);
    2527        shapes.Add(line);
    2628      }
     
    2830      LineShape lineZeroX = new LineShape(0, ClippingArea.Y1,
    2931                                          0, ClippingArea.Y2,
    30                                           0, Color.LightBlue, 3, DrawingStyle.Dashed);
     32                                          Color.LightBlue, 3,
     33                                          DrawingStyle.Dashed);
    3134
    3235      LineShape lineZeroY = new LineShape(ClippingArea.X1, 0,
    3336                                          ClippingArea.X2, 0,
    34                                           0, Color.LightBlue, 3, DrawingStyle.Dashed);
     37                                          Color.LightBlue, 3,
     38                                          DrawingStyle.Dashed);
    3539
    3640      shapes.Add(lineZeroX);
  • trunk/sources/HeuristicLab.Visualization/HeuristicLab.Visualization.csproj

    r1195 r1233  
    6868  </ItemGroup>
    6969  <ItemGroup>
     70    <Compile Include="AxisTicks.cs" />
    7071    <Compile Include="Canvas.cs" />
    7172    <Compile Include="CanvasUI.cs">
     
    8788    <Compile Include="LabelProvider\ILabelProvider.cs" />
    8889    <Compile Include="IMouseEventListener.cs" />
     90    <Compile Include="Legend\LegendItem.cs" />
    8991    <Compile Include="Options\OptionsDialog.cs">
    9092      <SubType>Form</SubType>
     
    9698    <Compile Include="LabelProvider\StringLabelProvider.cs" />
    9799    <Compile Include="TextShape.cs" />
    98     <Compile Include="LegendShape.cs" />
     100    <Compile Include="Legend\LegendShape.cs" />
    99101    <Compile Include="DataRow.cs" />
    100102    <Compile Include="DrawingStyle.cs" />
  • trunk/sources/HeuristicLab.Visualization/HeuristicLabVisualizationPlugin.cs

    r621 r1233  
    2020#endregion
    2121
    22 using System;
    23 using System.Collections.Generic;
    24 using System.Text;
    2522using HeuristicLab.PluginInfrastructure;
    2623
  • trunk/sources/HeuristicLab.Visualization/HorizontalLineShape.cs

    r1187 r1233  
    11using System.Drawing;
    2 using System.Drawing.Drawing2D;
    32
    43namespace HeuristicLab.Visualization {
    54  public class MinMaxLineShape : WorldShape {
    6     private LineShape minLineShape;
    7     private LineShape maxLineShape;
     5    private readonly LineShape minLineShape;
     6    private readonly LineShape maxLineShape;
    87
    98    /// <summary>
    109    /// Initializes the HorizontalLineShape.
    1110    /// </summary>
    12     /// <param name="z">Z-order</param>
    1311    /// <param name="color">color for the LineShape</param>
    1412    /// <param name="yMin">y value for lower line</param>
     
    1614    /// <param name="thickness">line thickness</param>
    1715    /// <param name="style">line style</param>
    18     public MinMaxLineShape(double yMin, double yMax, double z, Color color, int thickness, DrawingStyle style) {
    19       minLineShape = new LineShape(0, yMin, 1, yMin, z, color, thickness, style);
    20       maxLineShape = new LineShape(0, yMax, 1, yMax, z, color, thickness, style);
     16    public MinMaxLineShape(double yMin, double yMax, Color color, int thickness, DrawingStyle style) {
     17      minLineShape = new LineShape(0, yMin, 1, yMin, color, thickness, style);
     18      maxLineShape = new LineShape(0, yMax, 1, yMax, color, thickness, style);
    2119      shapes.Add(minLineShape);
    2220      shapes.Add(maxLineShape);
  • trunk/sources/HeuristicLab.Visualization/IDataRow.cs

    r1194 r1233  
    1515    DataRowType LineType { get; set; }
    1616    ILabelProvider YAxisLabelProvider { get; set; }
     17
     18    /// <summary>
     19    /// Raised when data row data changed. Should cause redraw in the view.
     20    /// </summary>
     21    event DataRowChangedHandler DataRowChanged;
    1722
    1823    void AddValue(double value);
  • trunk/sources/HeuristicLab.Visualization/Legend/LegendShape.cs

    r1232 r1233  
    11using System.Collections.Generic;
    2 using System.Drawing;
     2using HeuristicLab.Visualization.Legend;
    33
    4 namespace HeuristicLab.Visualization {
    5   public class LegendItem {
    6     public LegendItem(string label, Color color, int thickness) {
    7       Label = label;
    8       Color = color;
    9       Thickness = thickness;
    10     }
    11 
    12     public string Label { get; set; }
    13     public Color Color { get; set; }
    14     public int Thickness { get; set; }
    15   }
    16 
    17 
     4namespace HeuristicLab.Visualization.Legend {
    185  public class LegendShape : WorldShape {
    196    private readonly IList<LegendItem> legendItems = new List<LegendItem>();
     
    2714      double y = ClippingArea.Y2;
    2815      foreach (LegendItem item in legendItems) {
    29         AddShape(new LineShape(10, y - 10, 30, y - 10, 0, item.Color, item.Thickness, DrawingStyle.Solid));
     16        AddShape(new LineShape(10, y - 10, 30, y - 10, item.Color, item.Thickness, DrawingStyle.Solid));
    3017        AddShape(new TextShape(35, y, item.Label));
    3118        y -= 15;
  • trunk/sources/HeuristicLab.Visualization/LineChart.cs

    r1195 r1233  
    22using System.Collections.Generic;
    33using System.Drawing;
    4 using System.Drawing.Drawing2D;
    54using System.Windows.Forms;
    65using HeuristicLab.Core;
     6using HeuristicLab.Visualization.Legend;
    77using HeuristicLab.Visualization.Options;
    88
     
    6565      root.AddShape(titleShape);
    6666
    67       minMaxLineShape = new MinMaxLineShape(this.minDataValue, this.maxDataValue, 0, Color.Yellow, 4, DrawingStyle.Solid);
     67      minMaxLineShape = new MinMaxLineShape(this.minDataValue, this.maxDataValue, Color.Yellow, 4, DrawingStyle.Solid);
    6868      root.AddShape(minMaxLineShape);
    6969
     
    207207      }
    208208      for (int i = 1; i < row.Count; i++) {
    209         LineShape lineShape = new LineShape(i - 1, row[i - 1], i, row[i], 0, row.Color, row.Thickness, row.Style);
     209        LineShape lineShape = new LineShape(i - 1, row[i - 1], i, row[i], row.Color, row.Thickness, row.Style);
    210210        lineShapes.Add(lineShape);
    211211        // TODO each DataRow needs its own WorldShape so Y Axes can be zoomed independently.
     
    246246          maxDataRowCount = row.Count;
    247247        }
    248         LineShape lineShape = new LineShape(index - 1, row[index - 1], index, row[index], 0, row.Color, row.Thickness,
     248        LineShape lineShape = new LineShape(index - 1, row[index - 1], index, row[index], row.Color, row.Thickness,
    249249                                            row.Style);
    250250        lineShapes.Add(lineShape);
     
    412412
    413413    private void optionsToolStripMenuItem_Click(object sender, EventArgs e) {
    414       var optionsdlg = new OptionsDialog(this);
    415       optionsdlg.Show();
     414      OptionsDialog optionsdlg = new OptionsDialog(this);
     415      optionsdlg.ShowDialog(this);
    416416    }
    417417
    418418    public void ApplyChangesToRow(IDataRow row) {
    419       foreach (var ls in rowToLineShapes[row]) {
     419      foreach (LineShape ls in rowToLineShapes[row]) {
    420420        ls.LSColor = row.Color;
    421421        ls.LSThickness = row.Thickness;
    422         if (row.Style == DrawingStyle.Dashed) {
    423           ls.LSDashStyle = DashStyle.Dash;
    424         }
    425         else {
    426           ls.LSDashStyle = DashStyle.Solid; //default
    427         }
     422        ls.LSDrawingStyle = row.Style;
    428423      }
    429424      canvas.Invalidate();
  • trunk/sources/HeuristicLab.Visualization/LineShape.cs

    r1187 r1233  
    55  public class LineShape : IShape {
    66    private RectangleD boundingBox;
    7     private double z;
     7
    88    private Color color;
    99    private int thickness;
    10     private DashStyle dashStyle;
     10    private DrawingStyle drawingStyle;
     11
     12    private Pen pen;
    1113
    1214    /// <summary>
     
    1820    /// <param name="y2">y coordinate of right lineEndPoind</param>
    1921    /// <param name="color">color for the LineShape</param>
    20     public LineShape(double x1, double y1, double x2, double y2, double z, Color color, int thickness, DrawingStyle style) {
     22    /// <param name="thickness">tickness of the line in pixels</param>
     23    /// <param name="drawingStyle">drawing style of the line (solid, dashed, dotted,...)</param>
     24    public LineShape(double x1, double y1, double x2, double y2, Color color, int thickness, DrawingStyle drawingStyle) {
    2125      this.boundingBox = new RectangleD(x1, y1, x2, y2);
    22       this.z = z;
    2326      this.LSColor = color;
    2427      this.LSThickness = thickness;
    25       if (style==DrawingStyle.Dashed) {
    26         this.LSDashStyle = DashStyle.Dash;
    27       }
    28       else {
    29         this.LSDashStyle = DashStyle.Solid;        //default
    30       }
     28      this.LSDrawingStyle = drawingStyle;
    3129    }
    3230
     
    6260    /// <param name="clippingArea">rectangle in screen-coordinates to draw</param>
    6361    public void Draw(Graphics graphics, Rectangle viewport, RectangleD clippingArea) {
    64       using (Pen pen = new Pen(LSColor, LSThickness)){
    65         pen.DashStyle = this.LSDashStyle;
    66         Rectangle screenRect = Transform.ToScreen(boundingBox, viewport, clippingArea);
    67         graphics.DrawLine(pen,screenRect.Left, screenRect.Bottom, screenRect.Right, screenRect.Top);
    68       }
     62      Rectangle screenRect = Transform.ToScreen(boundingBox, viewport, clippingArea);
     63
     64      graphics.DrawLine(GetPen(), screenRect.Left, screenRect.Bottom, screenRect.Right, screenRect.Top);
    6965    }
    7066
    71     public double Z {
    72       get { return z; }
    73       set { z = value; }
     67    private Pen GetPen() {
     68      if (pen == null) {
     69        pen = new Pen(LSColor, LSThickness);
     70
     71        switch (LSDrawingStyle) {
     72          case DrawingStyle.Dashed:
     73            pen.DashStyle = DashStyle.Dash;
     74            break;
     75          default:
     76            pen.DashStyle = DashStyle.Solid;
     77            break;
     78        }
     79      }
     80
     81      return pen;
     82    }
     83
     84    private void DisposePen() {
     85      if (pen != null) {
     86        pen.Dispose();
     87        pen = null;
     88      }
    7489    }
    7590
    7691    public Color LSColor {
    7792      get { return color; }
    78       set { color = value; }
     93      set {
     94        color = value;
     95        DisposePen();
     96      }
    7997    }
    8098
    8199    public int LSThickness {
    82100      get { return thickness; }
    83       set { thickness = value; }
     101      set {
     102        thickness = value;
     103        DisposePen();
     104      }
    84105    }
    85106
    86     public DashStyle LSDashStyle {
    87       get { return dashStyle; }
    88       set { dashStyle = value; }
     107    public DrawingStyle LSDrawingStyle {
     108      get { return drawingStyle; }
     109      set {
     110        drawingStyle = value;
     111        DisposePen();
     112      }
    89113    }
    90114  }
  • trunk/sources/HeuristicLab.Visualization/Options/OptionsDialog.cs

    r1195 r1233  
    11using System;
    22using System.Collections.Generic;
    3 using System.ComponentModel;
    4 using System.Data;
    5 using System.Drawing;
    6 using System.Linq;
    7 using System.Text;
    83using System.Windows.Forms;
    94
    105namespace HeuristicLab.Visualization.Options {
    116  public partial class OptionsDialog : Form {
    12 
    137    private LineChart lc;
    148
     
    1812    }
    1913
    20 
    2114    private void button1_Click(object sender, EventArgs e) {
    22       var dlg = new ColorDialog();
     15      ColorDialog dlg = new ColorDialog();
    2316      dlg.ShowDialog();
    2417      this.ColorPreviewTB.BackColor = dlg.Color;
     
    4437
    4538    private void LineSelectCB_SelectedIndexChanged(object sender, EventArgs e) {
    46       int index = this.LineThicknessCB.FindStringExact(((IDataRow) this.LineSelectCB.SelectedValue).Thickness.ToString());
     39      IDataRow datarow = (IDataRow)this.LineSelectCB.SelectedValue;
     40
     41      int index = this.LineThicknessCB.FindStringExact(datarow.Thickness.ToString());
    4742      this.LineThicknessCB.SelectedIndex = index;
    48       index = this.LinestyleCB.FindStringExact(((IDataRow) this.LineSelectCB.SelectedValue).Style.ToString());
     43      index = this.LinestyleCB.FindStringExact(datarow.Style.ToString());
    4944      LinestyleCB.SelectedIndex = index;
    50       this.ColorPreviewTB.BackColor = ((IDataRow) this.LineSelectCB.SelectedValue).Color;
     45      this.ColorPreviewTB.BackColor = datarow.Color;
    5146    }
    5247
     
    5651
    5752    private void OptionsDialogOkButton_Click(object sender, EventArgs e) {
    58       ((IDataRow) this.LineSelectCB.SelectedValue).Thickness = (int) this.LineThicknessCB.SelectedItem;
    59       ((IDataRow) this.LineSelectCB.SelectedValue).Color = this.ColorPreviewTB.BackColor;
    60       ((IDataRow) this.LineSelectCB.SelectedValue).Style = (DrawingStyle) this.LineThicknessCB.SelectedItem;
    61       this.lc.ApplyChangesToRow((IDataRow) this.LineSelectCB.SelectedValue);
     53      IDataRow datarow = (IDataRow)this.LineSelectCB.SelectedValue;
     54
     55      datarow.Thickness = (int)this.LineThicknessCB.SelectedItem;
     56      datarow.Color = this.ColorPreviewTB.BackColor;
     57      datarow.Style = (DrawingStyle)this.LineThicknessCB.SelectedItem;
     58
     59      this.lc.ApplyChangesToRow(datarow);
    6260      this.Close();
    6361    }
  • trunk/sources/HeuristicLab.Visualization/RectangleShape.cs

    r1038 r1233  
    44  public class RectangleShape : IShape {
    55    private RectangleD rectangle;
     6
    67    private Color color;
    78    private int opacity = 255;
     9
     10    private Pen pen;
     11    private Brush brush;
    812
    913    public RectangleShape(double x1, double y1, double x2, double y2, Color color) {
     
    1620    }
    1721
    18     public void Draw(Graphics graphics, Rectangle viewport, RectangleD clippingArea) {
    19       Color brushColor = Color.FromArgb(opacity, color);
    20 
    21       using (Pen pen = new Pen(color, 1))
    22       using (Brush brush = new SolidBrush(brushColor)) {
    23         Rectangle screenRect = Transform.ToScreen(rectangle, viewport, clippingArea);
    24 
    25         graphics.DrawRectangle(pen, screenRect);
    26         graphics.FillRectangle(brush, screenRect);
    27       }
    28     }
    29 
    30     public int Opacity {
    31       get { return opacity; }
    32       set { opacity = value; }
    33     }
    34 
    3522    public RectangleD Rectangle {
    3623      get { return rectangle; }
     
    3825    }
    3926
     27    public void Draw(Graphics graphics, Rectangle viewport, RectangleD clippingArea) {
     28      Rectangle screenRect = Transform.ToScreen(rectangle, viewport, clippingArea);
     29
     30      graphics.DrawRectangle(GetPen(), screenRect);
     31      graphics.FillRectangle(GetBrush(), screenRect);
     32    }
     33
     34    private Pen GetPen() {
     35      if (pen == null)
     36        pen = new Pen(color, 1);
     37      return pen;
     38    }
     39
     40    private Brush GetBrush() {
     41      if (brush == null)
     42        brush = new SolidBrush(Color.FromArgb(opacity, color));
     43      return brush;
     44    }
     45
     46    public int Opacity {
     47      get { return opacity; }
     48      set {
     49        opacity = value;
     50        DisposeDrawingTools();
     51      }
     52    }
     53
    4054    public Color Color {
    4155      get { return color; }
    42       set { color = value; }
     56      set {
     57        color = value;
     58        DisposeDrawingTools();
     59      }
     60    }
     61
     62    private void DisposeDrawingTools() {
     63      if (pen != null) {
     64        pen.Dispose();
     65        pen = null;
     66      }
     67
     68      if (brush != null) {
     69        brush.Dispose();
     70        brush = null;
     71      }
    4372    }
    4473  }
  • trunk/sources/HeuristicLab.Visualization/XAxis.cs

    r1194 r1233  
    1 using System;
    2 using System.Collections.Generic;
    31using System.Drawing;
    42using HeuristicLab.Visualization.LabelProvider;
     
    75  public class XAxis : WorldShape {
    86    public const int PixelsPerInterval = 100;
     7   
    98    private ILabelProvider labelProvider = new ContinuousLabelProvider("0.####");
    109
     
    1413    }
    1514
    16     public static IEnumerable<double> GetTicks(int pixelsPerInterval, int screenSize, double worldSize, double worldStart) {
    17       int intervals = screenSize/pixelsPerInterval;
    18 
    19       if (intervals > 0) {
    20         double step = worldSize/intervals;
    21         step = Math.Pow(10, Math.Floor(Math.Log10(step)));
    22         if (worldSize/(step*5) > intervals)
    23           step = step*5;
    24         else if (worldSize/(step*2) > intervals)
    25           step = step*2;
    26 
    27         for (double x = Math.Floor(worldStart/step)*step;
    28              x <= worldStart + worldSize;
    29              x += step)
    30           yield return x;
    31       }
    32     }
    33 
    3415    public override void Draw(Graphics graphics, Rectangle viewport, RectangleD clippingArea) {
    3516      shapes.Clear();
    3617
    37       foreach (double x in GetTicks(PixelsPerInterval, viewport.Width, ClippingArea.Width, ClippingArea.X1)) {
     18      foreach (double x in AxisTicks.GetTicks(PixelsPerInterval, viewport.Width,
     19                                              ClippingArea.Width,
     20                                              ClippingArea.X1)) {
    3821        TextShape label = new TextShape(x, ClippingArea.Height - 3,
    3922                                        labelProvider.GetLabel(x));
  • trunk/sources/HeuristicLab.Visualization/YAxis.cs

    r1194 r1233  
    1616      shapes.Clear();
    1717
    18       foreach (double y in XAxis.GetTicks(PixelsPerInterval,
    19                                           viewport.Height,
    20                                           ClippingArea.Height,
    21                                           ClippingArea.Y1)) {
     18      foreach (double y in AxisTicks.GetTicks(PixelsPerInterval, viewport.Height,
     19                                              ClippingArea.Height,
     20                                              ClippingArea.Y1)) {
    2221        TextShape label = new TextShape(ClippingArea.X2 - 3, y,
    2322                                        labelProvider.GetLabel(y));
Note: See TracChangeset for help on using the changeset viewer.