- Timestamp:
- 03/13/09 19:07:53 (15 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/sources/HeuristicLab.Visualization/Legend/LegendShape.cs
r1337 r1342 1 using System; 1 2 using System.Collections.Generic; 2 3 using System.Drawing; 3 4 4 5 namespace HeuristicLab.Visualization.Legend { 6 public enum LegendPosition { 7 Top, 8 Bottom, 9 Left, 10 Right 11 } 12 5 13 public class LegendShape : WorldShape { 6 14 private readonly IList<LegendItem> legendItems = new List<LegendItem>(); 15 // legend draw default value: column 16 private bool row; 17 private bool top; 18 7 19 8 20 private Color color = Color.Blue; … … 13 25 } 14 26 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 15 37 public void CreateLegend() { 16 38 ClearShapes(); 39 double x = ClippingArea.X1; 17 40 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 } 18 55 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 } 22 68 } 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)); 23 90 } 24 91
Note: See TracChangeset
for help on using the changeset viewer.