Free cookie consent management tool by TermsFeed Policy Generator

Ignore:
Timestamp:
04/25/09 08:09:33 (15 years ago)
Author:
shofstad
Message:

Legend implementation updated (#407)

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/sources/HeuristicLab.Visualization/3.2/Legend/LegendShape.cs

    r1461 r1665  
    4747        double y = ClippingArea.Y2;
    4848
    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;
    5753        foreach (LegendItem item in legendItems) {
    5854          if (!row) {
     
    6056            y -= Font.Height;
    6157          } else {
    62             if (rowCounter >= numberOfItemsPerRow) {
     58            if (IsNewRow(legendItemCounter)) {
    6359              x = ClippingArea.X1;
    6460              y -= Font.Height+15;
    65               rowCounter = 0;
    6661            }
    6762            CreateRow(item, x, y);
    6863            x += GetLabelLengthInPixel(item);
    69             rowCounter++;
     64            legendItemCounter++;
    7065          }
    7166        }
     
    7368    }
    7469
    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() {
    8271      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    //}
    9499
    95100    /// <summary>
    96101    /// returns the maximum number of items per row to paint
    97102    /// </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;
    104114    }
    105115
Note: See TracChangeset for help on using the changeset viewer.