Changeset 1665
- Timestamp:
- 04/25/09 08:09:33 (16 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/sources/HeuristicLab.Visualization/3.2/Legend/LegendShape.cs
r1461 r1665 47 47 double y = ClippingArea.Y2; 48 48 49 int numberOfItemsPerRow = 1; 50 if (row) { 51 numberOfItemsPerRow = GetNrOfItemsPerRow(); 52 if (!top) { 53 y = GetHeight4Rows(); 54 } 55 } 56 int rowCounter = 0; 49 if (row && !top) { 50 y = GetOptimalBottomHeight(); 51 } 52 int legendItemCounter = 1; 57 53 foreach (LegendItem item in legendItems) { 58 54 if (!row) { … … 60 56 y -= Font.Height; 61 57 } else { 62 if ( rowCounter >= numberOfItemsPerRow) {58 if (IsNewRow(legendItemCounter)) { 63 59 x = ClippingArea.X1; 64 60 y -= Font.Height+15; 65 rowCounter = 0;66 61 } 67 62 CreateRow(item, x, y); 68 63 x += GetLabelLengthInPixel(item); 69 rowCounter++;64 legendItemCounter++; 70 65 } 71 66 } … … 73 68 } 74 69 75 /// <summary> 76 /// returns die optimal height for the top or bottom legend 77 /// </summary> 78 /// <returns></returns> 79 private int GetHeight4Rows() { 80 int numberOfItemsPerRow = GetNrOfItemsPerRow(); 81 int nrOfItems = legendItems.Count; 70 private double GetOptimalBottomHeight() { 82 71 int rowsToDraw = 1; 83 if (nrOfItems > numberOfItemsPerRow) { 84 int rest; 85 int value = Math.DivRem(nrOfItems, numberOfItemsPerRow, out rest); 86 if (rest > 1) { 87 rowsToDraw = rest; 88 } else { 89 rowsToDraw = value + rest; 90 } 91 } 92 return (Font.Height+12)*rowsToDraw; 93 } 72 for (int i = 0; i < legendItems.Count; i++) { 73 if (IsNewRow(i + 1)) { 74 rowsToDraw++; 75 } 76 } 77 return (Font.Height + 12) * rowsToDraw; 78 } 79 80 ///// <summary> 81 ///// returns the maximum number of items per row to paint 82 ///// </summary> 83 ///// <returns>number of items per row</returns> 84 //public int GetNrOfItemsPerRow() { 85 // double sum = 0; 86 // double caw = ClippingArea.Width; 87 // int items = 0; 88 // foreach (var item in legendItems) { 89 // sum += GetLabelLengthInPixel(item); 90 // if (sum < caw) { 91 // items++; 92 // } 93 // } 94 // if (items == 0) { 95 // items++; 96 // } 97 // return items; 98 //} 94 99 95 100 /// <summary> 96 101 /// returns the maximum number of items per row to paint 97 102 /// </summary> 98 /// <returns></returns> 99 private int GetNrOfItemsPerRow() { 100 int numberOfItemsPerRow = (int)ClippingArea.Width / GetMaxLabelLength(); 101 // if the width of the clippingarea < maxLabelLength 102 if (numberOfItemsPerRow == 0) numberOfItemsPerRow = 1; 103 return numberOfItemsPerRow; 103 /// <returns>number of items per row</returns> 104 private bool IsNewRow(int toCurrentItem) { 105 double sum = 0; 106 double caw = ClippingArea.Width; 107 for (int i = 0; i < toCurrentItem; i++) { 108 sum += GetLabelLengthInPixel(legendItems[i]); 109 if (sum > caw) { 110 return true; 111 } 112 } 113 return false; 104 114 } 105 115
Note: See TracChangeset
for help on using the changeset viewer.