Free cookie consent management tool by TermsFeed Policy Generator

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

Legend implementation updated with position setting (#407)

File:
1 edited

Legend:

Unmodified
Added
Removed
  • 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
Note: See TracChangeset for help on using the changeset viewer.