Changeset 7210
- Timestamp:
- 12/20/11 11:22:30 (13 years ago)
- Location:
- branches/FitnessLandscapeAnalysis/HeuristicLab.Analysis.FitnessLandscape/BoxChart
- Files:
-
- 3 edited
Legend:
- Unmodified
- Added
- Removed
-
branches/FitnessLandscapeAnalysis/HeuristicLab.Analysis.FitnessLandscape/BoxChart/BoxChartCreator.cs
r7128 r7210 6 6 using System.Linq; 7 7 using System.Text; 8 using HeuristicLab.Collections; 8 9 using HeuristicLab.Common; 9 10 using HeuristicLab.Core; … … 20 21 [StorableClass] 21 22 public class BoxChartCreator : ParameterizedNamedItem, IRunCollectionModifier { 23 24 public enum AppendModes { None, Horizontal, Vertical }; 22 25 23 26 #region Parameters … … 37 40 get { return (ValueParameter<StringValue>) Parameters["ZipFileName"]; } 38 41 } 42 public ConstrainedValueParameter<StringValue> AppendModeParameter { 43 get { return (ConstrainedValueParameter<StringValue>) Parameters["AppendMode"]; } 44 } 39 45 #endregion 40 46 … … 44 50 protected int Size { get { return SizeParameter.Value.Value; } } 45 51 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 { 47 54 get { 48 55 return ElementsParameter.Value.CheckedItems.Select(i => i.Value).ToList(); … … 54 61 [StorableConstructor] 55 62 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 } 57 66 public BoxChartCreator() { 58 67 Parameters.Add(new ValueParameter<StringValue>("ChartName", "The result name of the chart.", new StringValue("Chart"))); … … 61 70 Parameters.Add(new ValueParameter<IntValue>("Padding", "The padding inside the boxes", new IntValue(1))); 62 71 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(); 63 76 } 64 77 public override IDeepCloneable Clone(Cloner cloner) { … … 69 82 if (!Parameters.ContainsKey("ZipFileName")) 70 83 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(); 71 90 } 72 91 #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 } 73 126 74 127 #region IRunCollectionModifier Members … … 116 169 117 170 #endregion 171 118 172 } 119 173 } -
branches/FitnessLandscapeAnalysis/HeuristicLab.Analysis.FitnessLandscape/BoxChart/EmptyBoxChartElementGenerator.cs
r7128 r7210 30 30 } 31 31 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 } 36 48 37 49 #region Construction & Cloning -
branches/FitnessLandscapeAnalysis/HeuristicLab.Analysis.FitnessLandscape/BoxChart/IBoxChartElementGenerator.cs
r7128 r7210 15 15 16 16 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; } 21 21 void Draw(IRun run, Graphics g); 22 22 }
Note: See TracChangeset
for help on using the changeset viewer.