Free cookie consent management tool by TermsFeed Policy Generator

Changeset 7210


Ignore:
Timestamp:
12/20/11 11:22:30 (13 years ago)
Author:
epitzer
Message:

#1696: Improve usability of BoxChart creator: add automatic positioning of new chart elements

Location:
branches/FitnessLandscapeAnalysis/HeuristicLab.Analysis.FitnessLandscape/BoxChart
Files:
3 edited

Legend:

Unmodified
Added
Removed
  • branches/FitnessLandscapeAnalysis/HeuristicLab.Analysis.FitnessLandscape/BoxChart/BoxChartCreator.cs

    r7128 r7210  
    66using System.Linq;
    77using System.Text;
     8using HeuristicLab.Collections;
    89using HeuristicLab.Common;
    910using HeuristicLab.Core;
     
    2021  [StorableClass]
    2122  public class BoxChartCreator : ParameterizedNamedItem, IRunCollectionModifier {
     23
     24    public enum AppendModes { None, Horizontal, Vertical };
    2225
    2326    #region Parameters
     
    3740      get { return (ValueParameter<StringValue>) Parameters["ZipFileName"]; }
    3841    }
     42    public ConstrainedValueParameter<StringValue> AppendModeParameter {
     43      get { return (ConstrainedValueParameter<StringValue>) Parameters["AppendMode"]; }
     44    }
    3945    #endregion
    4046
     
    4450    protected int Size { get { return SizeParameter.Value.Value; } }
    4551    protected int Padding { get { return PaddingParameter.Value.Value; } }
    46     protected List<IBoxChartElementGenerator> Generators {
     52    protected AppendModes AppendMode { get { return (AppendModes)Enum.Parse(typeof(AppendModes), AppendModeParameter.Value.Value); } }
     53      protected List<IBoxChartElementGenerator> Generators {
    4754      get {
    4855        return ElementsParameter.Value.CheckedItems.Select(i => i.Value).ToList();
     
    5461    [StorableConstructor]
    5562    protected BoxChartCreator(bool deserializing) : base(deserializing) { }
    56     protected BoxChartCreator(BoxChartCreator original, Cloner cloner) : base(original, cloner) { }
     63    protected BoxChartCreator(BoxChartCreator original, Cloner cloner) : base(original, cloner) {
     64      RegisterEvents();
     65    }
    5766    public BoxChartCreator() {
    5867      Parameters.Add(new ValueParameter<StringValue>("ChartName", "The result name of the chart.", new StringValue("Chart")));
     
    6170      Parameters.Add(new ValueParameter<IntValue>("Padding", "The padding inside the boxes", new IntValue(1)));
    6271      Parameters.Add(new ValueParameter<StringValue>("ZipFileName", "The name of the zip file that will contain all generated charts.", new StringValue("")));
     72      Parameters.Add(new ConstrainedValueParameter<StringValue>("AppendMode", "Determines how coordinates of new elements are calculated.",
     73        new ItemSet<StringValue>(Enum.GetNames(typeof (AppendModes)).Select(v => new StringValue(v)))));
     74      AppendModeParameter.Value = AppendModeParameter.ValidValues.SingleOrDefault(v => v.Value == AppendModes.Horizontal.ToString());
     75      RegisterEvents();
    6376    }
    6477    public override IDeepCloneable Clone(Cloner cloner) {
     
    6982      if (!Parameters.ContainsKey("ZipFileName"))
    7083        Parameters.Add(new ValueParameter<StringValue>("ZipFileName", "The name of the zip file that will contain all generated charts.", new StringValue("")));
     84      if (!Parameters.ContainsKey("AppendMode")) {
     85        Parameters.Add(new ConstrainedValueParameter<StringValue>("AppendMode", "Determines how coordinates of new elements are calculated.",
     86          new ItemSet<StringValue>(Enum.GetNames(typeof (AppendModes)).Select(v => new StringValue(v)))));
     87        AppendModeParameter.Value = AppendModeParameter.ValidValues.SingleOrDefault(v => v.Value == AppendModes.Horizontal.ToString());
     88      }
     89      RegisterEvents();
    7190    }
    7291    #endregion
     92
     93    private void RegisterEvents() {
     94      ElementsParameter.ValueChanged += ElementsParameter_ValueChanged;
     95      ElementsParameter.Value.ItemsAdded += ElementsParameter_Value_ItemsAdded;
     96    }
     97
     98    private void ElementsParameter_ValueChanged(object sender, EventArgs e) {
     99      ElementsParameter.Value.ItemsAdded += ElementsParameter_Value_ItemsAdded;
     100    }
     101
     102    private void ElementsParameter_Value_ItemsAdded(object sender, CollectionItemsChangedEventArgs<IndexedItem<IBoxChartElementGenerator>> e) {
     103      if (sender != ElementsParameter.Value) {
     104        var oldParameter = sender as ICheckedItemList<IBoxChartElementGenerator>;
     105        if (oldParameter != null)
     106          oldParameter.ItemsAdded -= ElementsParameter_Value_ItemsAdded;
     107      } else {
     108        var generators = Generators;
     109        var newItems = e.Items.Select(kvp => kvp.Value).ToList();
     110        switch (AppendMode) {
     111          case AppendModes.Horizontal:
     112            foreach (var generator in newItems) {
     113              generator.Y = generators.Max(g => g.Y + g.RowSpan - 1);
     114              generator.X = generators.Where(g => g.Y + g.RowSpan - 1 == generator.Y).Max(g => g.X + g.ColSpan);
     115            }
     116            break;
     117          case AppendModes.Vertical:
     118            foreach (var generator in newItems) {
     119              generator.X = generators.Max(g => g.X + g.ColSpan - 1);
     120              generator.Y = generators.Where(g => g.X + g.ColSpan - 1 == generator.X).Max(g => g.Y + g.RowSpan);
     121            }
     122            break;
     123        }
     124      }
     125    }
    73126
    74127    #region IRunCollectionModifier Members
     
    116169
    117170    #endregion
     171
    118172  }
    119173}
  • branches/FitnessLandscapeAnalysis/HeuristicLab.Analysis.FitnessLandscape/BoxChart/EmptyBoxChartElementGenerator.cs

    r7128 r7210  
    3030    }
    3131
    32     public int X { get { return XParameter.Value.Value; } }
    33     public int Y { get { return YParameter.Value.Value; } }
    34     public int ColSpan { get { return ColSpanParameter.Value.Value; } }
    35     public int RowSpan { get { return RowSpanParameter.Value.Value; } }
     32    public int X {
     33      get { return XParameter.Value.Value; }
     34      set { XParameter.Value.Value = value; }
     35    }
     36    public int Y {
     37      get { return YParameter.Value.Value; }
     38      set { YParameter.Value.Value = value; }
     39    }
     40    public int ColSpan {
     41      get { return ColSpanParameter.Value.Value; }
     42      set { ColSpanParameter.Value.Value = value; }
     43    }
     44    public int RowSpan {
     45      get { return RowSpanParameter.Value.Value; }
     46      set { RowSpanParameter.Value.Value = value; }
     47    }
    3648
    3749    #region Construction & Cloning
  • branches/FitnessLandscapeAnalysis/HeuristicLab.Analysis.FitnessLandscape/BoxChart/IBoxChartElementGenerator.cs

    r7128 r7210  
    1515
    1616  public interface IBoxChartElementGenerator : INamedItem {
    17     int X { get; }
    18     int Y { get; }
    19     int ColSpan { get; }
    20     int RowSpan { get; }
     17    int X { get; set; }
     18    int Y { get; set; }
     19    int ColSpan { get; set; }
     20    int RowSpan { get; set; }
    2121    void Draw(IRun run, Graphics g);
    2222  }
Note: See TracChangeset for help on using the changeset viewer.