Free cookie consent management tool by TermsFeed Policy Generator

Changeset 1342 for trunk


Ignore:
Timestamp:
03/13/09 19:07:53 (16 years ago)
Author:
shofstad
Message:

Legend implementation updated with position setting (#407)

Location:
trunk/sources
Files:
7 edited

Legend:

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

    r1326 r1342  
    311311      IDataRow row3 = new DataRow();
    312312
     313      IDataRow row4 = new DataRow();
     314      IDataRow row5 = new DataRow();
     315      IDataRow row6 = new DataRow();
     316
    313317      row1.Color = Color.Red;
    314318      row2.Color = Color.Green;
    315319      row3.Color = Color.Blue;
    316320
     321      row4.Color = Color.DeepPink;
     322      row5.Color = Color.Firebrick;
     323      row6.Color = Color.DarkSlateGray;
     324
    317325      row1.Thickness = 3;
    318326      row2.Thickness = 4;
    319327      row3.Thickness = 5;
     328
     329      row4.Thickness = 3;
     330      row5.Thickness = 4;
     331      row6.Thickness = 5;
    320332
    321333      row1.Label = "SingleValue";
     
    323335      row3.Label = "Maxi";
    324336
     337      row4.Label = "Simon";
     338      row5.Label = "klausmuellerwesternhagenunddierasperies";
     339      row6.Label = "anyways";
     340
    325341      row1.Style = DrawingStyle.Solid;
    326342      row2.Style = DrawingStyle.Solid;
    327343      row3.Style = DrawingStyle.Dashed;
     344
     345      row4.Style = DrawingStyle.Solid;
     346      row5.Style = DrawingStyle.Solid;
     347      row6.Style = DrawingStyle.Dashed;
    328348
    329349      row1.LineType = DataRowType.SingleValue;
     
    331351      row1.AddValue(12);
    332352
    333       model.AddDataRow(row1);
    334       model.AddDataRow(row2);
    335       model.AddDataRow(row3);
    336 
    337      
    338      
    339353      row2.AddValue(5);
    340354     
     
    347361
    348362
    349    
     363      row4.AddValue(10);
     364      row5.AddValue(11);
     365      row6.AddValue(11);
     366
     367      model.AddDataRow(row1);
     368      model.AddDataRow(row2);
     369      model.AddDataRow(row3);
     370      model.AddDataRow(row4);
     371      model.AddDataRow(row5);
     372      model.AddDataRow(row6);
    350373
    351374      f.ShowDialog();
  • trunk/sources/HeuristicLab.Visualization/Legend/LegendItem.cs

    r1233 r1342  
    33namespace HeuristicLab.Visualization.Legend {
    44  public class LegendItem {
     5
     6    public static readonly int WIDTH = 100;
     7
    58    public LegendItem(string label, Color color, int thickness) {
    69      Label = label;
  • trunk/sources/HeuristicLab.Visualization/Legend/LegendShape.cs

    r1337 r1342  
     1using System;
    12using System.Collections.Generic;
    23using System.Drawing;
    34
    45namespace HeuristicLab.Visualization.Legend {
     6  public enum LegendPosition {
     7    Top,
     8    Bottom,
     9    Left,
     10    Right
     11  }
     12
    513  public class LegendShape : WorldShape {
    614    private readonly IList<LegendItem> legendItems = new List<LegendItem>();
     15    // legend draw default value: column
     16    private bool row;
     17    private bool top;
     18
    719
    820    private Color color = Color.Blue;
     
    1325    }
    1426
     27    public bool Row {
     28      set { row = value; }
     29      get { return row; }
     30    }
     31
     32    public bool Top {
     33      set { top = value; }
     34      get { return top; }
     35    }
     36
    1537    public void CreateLegend() {
    1638      ClearShapes();
     39      double x = ClippingArea.X1;
    1740      double y = ClippingArea.Y2;
     41      int numberOfItemsPerRow = 0;
     42      int rowCounter = 0;
     43      int rowsToDraw = 1;
     44      if (row) {
     45        numberOfItemsPerRow = (int)ClippingArea.Width/LegendItem.WIDTH;
     46        int nrOfItems = legendItems.Count;
     47        if (nrOfItems > numberOfItemsPerRow) {
     48          int rest;
     49          int value = Math.DivRem(nrOfItems, numberOfItemsPerRow, out rest);
     50          rowsToDraw = value + rest;
     51        }
     52        if (!top)
     53          y = 25*rowsToDraw;
     54      }
    1855      foreach (LegendItem item in legendItems) {
    19         AddShape(new LineShape(10, y - 10, 30, y - 10, item.Color, item.Thickness, DrawingStyle.Solid));
    20         AddShape(new TextShape(35, y, item.Label, font, color));
    21         y -= 15;
     56        if (!row) {
     57          CreateColumn(item, y);
     58          y -= 15;
     59        } else {
     60          if (rowCounter >= numberOfItemsPerRow) {
     61            x = ClippingArea.X1;
     62            y -= 25;
     63          }
     64          CreateRow(item, x, y);
     65          x += LegendItem.WIDTH;
     66          rowCounter++;
     67        }
    2268      }
     69    }
     70
     71    /// <summary>
     72    /// draws the legend as a row at the top or bottom of the WorldShape
     73    /// </summary>
     74    /// <param name="item"></param>
     75    /// <param name="x"></param>
     76    /// <param name="y"></param>
     77    private void CreateRow(LegendItem item, double x, double y) {
     78      AddShape(new LineShape(x, y - 10, x + 20, y - 10, item.Color, item.Thickness, DrawingStyle.Solid));
     79      AddShape(new TextShape(x + 25, y, item.Label, Font, Color));
     80    }
     81
     82    /// <summary>
     83    /// draws the legend as a column on the right or left side of the WorldShape
     84    /// </summary>
     85    /// <param name="item"></param>
     86    /// <param name="y"></param>
     87    private void CreateColumn(LegendItem item, double y) {
     88      AddShape(new LineShape(10, y - 10, 30, y - 10, item.Color, item.Thickness, DrawingStyle.Solid));
     89      AddShape(new TextShape(35, y, item.Label, Font, Color));
    2390    }
    2491
  • trunk/sources/HeuristicLab.Visualization/LineChart.cs

    r1341 r1342  
    5252      this.model = model;
    5353      viewSettings = model.ViewSettings;
    54       viewSettings.OnUpdateSettings += UpdateViewProperties;
     54      viewSettings.OnUpdateSettings += UpdateViewSettings;
    5555
    5656      Item = model;
     
    6262    }
    6363
    64     private void UpdateViewProperties() {
     64    private void UpdateViewSettings() {
    6565      titleShape.Font = viewSettings.TitleFont;
    6666      titleShape.Color = viewSettings.TitleColor;
     
    7171      xAxis.Font = viewSettings.XAxisFont;
    7272      xAxis.Color = viewSettings.XAxisColor;
     73
     74      switch (viewSettings.LegendPosition) {
     75          case LegendPosition.Bottom:
     76            setLegendBottom();
     77            break;
     78
     79          case LegendPosition.Top:
     80            setLegendTop();
     81            break;
     82
     83          case LegendPosition.Left:
     84            setLegendLeft();
     85            break;
     86
     87          case LegendPosition.Right:
     88            setLegendRight();
     89            break;
     90      }
    7391
    7492      canvasUI.Invalidate();
     
    138156                                         linesAreaBoundingBox.Y1);
    139157
     158      setLegendBottom();
     159    }
     160
     161    public void setLegendRight() {
     162      // legend right
     163      legendShape.BoundingBox = new RectangleD(canvasUI.Width - 110, 10, canvasUI.Width, canvasUI.Height - 50);
     164      legendShape.ClippingArea = new RectangleD(0, 0, legendShape.BoundingBox.Width, legendShape.BoundingBox.Height);
     165      legendShape.Row = false;
     166      legendShape.CreateLegend();
     167    }
     168
     169    public void setLegendLeft() {
     170      // legend left
    140171      legendShape.BoundingBox = new RectangleD(10, 10, 110, canvasUI.Height - 50);
    141       legendShape.ClippingArea = new RectangleD(0, 0, legendShape.BoundingBox.Width,
    142                                                 legendShape.BoundingBox.Height);
    143 
    144       canvasUI.Invalidate();
     172      legendShape.ClippingArea = new RectangleD(0, 0, legendShape.BoundingBox.Width, legendShape.BoundingBox.Height);
     173      legendShape.Row = false;
     174      legendShape.CreateLegend();
     175
     176      canvasUI.Invalidate();
     177    }
     178
     179    public void setLegendTop() {
     180      // legend top
     181      legendShape.BoundingBox = new RectangleD(100, canvasUI.Height - canvasUI.Height, canvasUI.Width, canvasUI.Height - 10);
     182      legendShape.ClippingArea = new RectangleD(0, 0, legendShape.BoundingBox.Width, legendShape.BoundingBox.Height);
     183      legendShape.Row = true;
     184      legendShape.Top = true;
     185      legendShape.CreateLegend();
     186    }
     187
     188    public void setLegendBottom() {
     189      // legend bottom
     190      legendShape.BoundingBox = new RectangleD(100, 10, canvasUI.Width, 200);
     191      legendShape.ClippingArea = new RectangleD(0, 0, legendShape.BoundingBox.Width, legendShape.BoundingBox.Height);
     192      legendShape.Row = true;
     193      legendShape.Top = false;
     194      legendShape.CreateLegend();
    145195    }
    146196
    147197    private void optionsToolStripMenuItem_Click(object sender, EventArgs e) {
    148198      OptionsDialog optionsdlg = new OptionsDialog(model);
     199      //var optionsdlg = new OptionsDialog(model, this);
    149200      optionsdlg.ShowDialog(this);
     201      Invalidate();
    150202    }
    151203
  • trunk/sources/HeuristicLab.Visualization/Options/OptionsDialog.Designer.cs

    r1337 r1342  
    3232      this.tabPage2 = new System.Windows.Forms.TabPage();
    3333      this.btnChangeLegendFont = new System.Windows.Forms.Button();
    34       this.labelposition = new System.Windows.Forms.Label();
    35       this.cbLabelPosition = new System.Windows.Forms.ComboBox();
     34      this.legendposition = new System.Windows.Forms.Label();
     35      this.cbLegendPosition = new System.Windows.Forms.ComboBox();
    3636      this.tabPage1 = new System.Windows.Forms.TabPage();
    3737      this.OptionsDialogSelectColorBt = new System.Windows.Forms.Button();
     
    113113      //
    114114      this.tabPage2.Controls.Add(this.btnChangeLegendFont);
    115       this.tabPage2.Controls.Add(this.labelposition);
    116       this.tabPage2.Controls.Add(this.cbLabelPosition);
     115      this.tabPage2.Controls.Add(this.legendposition);
     116      this.tabPage2.Controls.Add(this.cbLegendPosition);
    117117      this.tabPage2.Location = new System.Drawing.Point(4, 22);
    118118      this.tabPage2.Name = "tabPage2";
     
    133133      this.btnChangeLegendFont.Click += new System.EventHandler(this.btnChangeLegendFont_Click);
    134134      //
    135       // labelposition
    136       //
    137       this.labelposition.AutoSize = true;
    138       this.labelposition.Location = new System.Drawing.Point(3, 47);
    139       this.labelposition.Name = "labelposition";
    140       this.labelposition.Size = new System.Drawing.Size(72, 13);
    141       this.labelposition.TabIndex = 1;
    142       this.labelposition.Text = "Labelposition:";
    143       //
    144       // cbLabelPosition
    145       //
    146       this.cbLabelPosition.DropDownStyle = System.Windows.Forms.ComboBoxStyle.DropDownList;
    147       this.cbLabelPosition.FormattingEnabled = true;
    148       this.cbLabelPosition.Items.AddRange(new object[] {
     135      // legendposition
     136      //
     137      this.legendposition.AutoSize = true;
     138      this.legendposition.Location = new System.Drawing.Point(8, 38);
     139      this.legendposition.Name = "legendposition";
     140      this.legendposition.Size = new System.Drawing.Size(82, 13);
     141      this.legendposition.TabIndex = 1;
     142      this.legendposition.Text = "Legendposition:";
     143      //
     144      // cbLegendPosition
     145      //
     146      this.cbLegendPosition.DropDownStyle = System.Windows.Forms.ComboBoxStyle.DropDownList;
     147      this.cbLegendPosition.FormattingEnabled = true;
     148      this.cbLegendPosition.Items.AddRange(new object[] {
    149149            "left",
    150150            "right",
    151151            "top",
    152152            "bottom"});
    153       this.cbLabelPosition.Location = new System.Drawing.Point(81, 44);
    154       this.cbLabelPosition.Name = "cbLabelPosition";
    155       this.cbLabelPosition.Size = new System.Drawing.Size(121, 21);
    156       this.cbLabelPosition.TabIndex = 0;
     153      this.cbLegendPosition.Location = new System.Drawing.Point(96, 35);
     154      this.cbLegendPosition.Name = "cbLegendPosition";
     155      this.cbLegendPosition.Size = new System.Drawing.Size(121, 21);
     156      this.cbLegendPosition.TabIndex = 0;
     157      this.cbLegendPosition.SelectedIndexChanged += new System.EventHandler(this.cbLegendPosition_SelectedIndexChanged);
    157158      //
    158159      // tabPage1
     
    335336    private System.Windows.Forms.Button btnChangeTitleFont;
    336337    private System.Windows.Forms.TabPage tabPage2;
    337     private System.Windows.Forms.Label labelposition;
    338     private System.Windows.Forms.ComboBox cbLabelPosition;
    339338    private System.Windows.Forms.TabPage tabPage1;
    340339    private System.Windows.Forms.Button OptionsDialogSelectColorBt;
     
    346345    private System.Windows.Forms.GroupBox groupBox1;
    347346    private System.Windows.Forms.Label label4;
     347    private System.Windows.Forms.ComboBox cbLegendPosition;
     348    private System.Windows.Forms.Label legendposition;
    348349    private System.Windows.Forms.ComboBox LineThicknessCB;
    349350    private System.Windows.Forms.Label label3;
  • trunk/sources/HeuristicLab.Visualization/Options/OptionsDialog.cs

    r1341 r1342  
    22using System.Collections.Generic;
    33using System.Windows.Forms;
     4using HeuristicLab.Visualization.Legend;
    45
    56namespace HeuristicLab.Visualization.Options {
     
    7475    }
    7576
     77    private void cbLegendPosition_SelectedIndexChanged(object sender, EventArgs e) {
     78      string pos = cbLegendPosition.SelectedItem.ToString();
     79      if (pos.Equals("left")) {
     80        viewSettings.LegendPosition = LegendPosition.Left;
     81      } else if (pos.Equals("right")) {
     82        viewSettings.LegendPosition = LegendPosition.Right;
     83      } else if (pos.Equals("bottom")) {
     84        viewSettings.LegendPosition = LegendPosition.Bottom;
     85      } else {
     86        viewSettings.LegendPosition = LegendPosition.Top;
     87      }
     88     
     89      viewSettings.UpdateView();
     90    }
     91
    7692    private void btnChangeTitleFont_Click(object sender, EventArgs e) {
    7793      fdFont.Font = viewSettings.TitleFont;
  • trunk/sources/HeuristicLab.Visualization/Options/ViewSettings.cs

    r1341 r1342  
    11using System.Drawing;
     2using HeuristicLab.Visualization.Legend;
    23
    34namespace HeuristicLab.Visualization.Options {
     
    1112    private Font xAxisFont;
    1213    private Color xAxisColor;
     14    private LegendPosition legendPosition;
    1315
    1416    public ViewSettings() {
     
    2123      xAxisFont = new Font("Arial", 8);
    2224      xAxisColor = Color.Blue;
     25
     26      legendPosition = LegendPosition.Left;
    2327    }
    2428
     
    5862      set { xAxisColor = value; }
    5963    }
     64
     65    public LegendPosition LegendPosition {
     66      get { return legendPosition; }
     67      set { legendPosition = value; }
     68    }
    6069  }
    6170
Note: See TracChangeset for help on using the changeset viewer.