1 | using System;
|
---|
2 | using System.Drawing;
|
---|
3 | using HeuristicLab.Common;
|
---|
4 | using HeuristicLab.Core;
|
---|
5 | using HeuristicLab.Data;
|
---|
6 | using HeuristicLab.Optimization;
|
---|
7 | using HeuristicLab.Parameters;
|
---|
8 | using HEAL.Attic;
|
---|
9 |
|
---|
10 | namespace HeuristicLab.Analysis.FitnessLandscape.BoxCharts {
|
---|
11 |
|
---|
12 | [StorableType("E04F26F6-E8CF-4EF1-96AC-B3FFF38E4ACE")]
|
---|
13 | public class StringValueBoxChartElementGenerator : EmptyBoxChartElementGenerator {
|
---|
14 |
|
---|
15 | public ValueParameter<StringValue> ValueNameParameter {
|
---|
16 | get { return (ValueParameter<StringValue>)Parameters["ValueName"]; }
|
---|
17 | }
|
---|
18 | public ValueParameter<IntValue> FontSizeParameter {
|
---|
19 | get { return (ValueParameter<IntValue>) Parameters["FontSize"]; }
|
---|
20 | }
|
---|
21 |
|
---|
22 | protected string ValueName { get { return ValueNameParameter.Value.Value; } }
|
---|
23 | protected int FontSize { get { return FontSizeParameter.Value.Value; }}
|
---|
24 |
|
---|
25 | #region Construction & Cloning
|
---|
26 |
|
---|
27 | [StorableConstructor]
|
---|
28 | protected StringValueBoxChartElementGenerator(StorableConstructorFlag _) : base(_) { }
|
---|
29 | protected StringValueBoxChartElementGenerator(StringValueBoxChartElementGenerator original, Cloner cloner) : base(original, cloner) {
|
---|
30 | RegisterEvents();
|
---|
31 | }
|
---|
32 | public StringValueBoxChartElementGenerator() {
|
---|
33 | Parameters.Add(new ValueParameter<StringValue>("ValueName", "The name of the result of parameter ot be visualized.", new StringValue("Value")));
|
---|
34 | Parameters.Add(new ValueParameter<IntValue>("FontSize", "The font size to be used for the text.", new IntValue(11)));
|
---|
35 | RegisterEvents();
|
---|
36 | if (GetType() == typeof(StringValueBoxChartElementGenerator))
|
---|
37 | UpdateName();
|
---|
38 | }
|
---|
39 | public override IDeepCloneable Clone(Cloner cloner) {
|
---|
40 | return new StringValueBoxChartElementGenerator(this, cloner);
|
---|
41 | }
|
---|
42 | [StorableHook(HookType.AfterDeserialization)]
|
---|
43 | private void AfterDeserialization() {
|
---|
44 | RegisterEvents();
|
---|
45 | }
|
---|
46 | #endregion
|
---|
47 |
|
---|
48 | private void RegisterEvents() {
|
---|
49 | ValueNameParameter.ToStringChanged += new EventHandler(Parameters_Changed);
|
---|
50 | FontSizeParameter.ToStringChanged += new EventHandler(Parameters_Changed);
|
---|
51 | }
|
---|
52 |
|
---|
53 | private void Parameters_Changed(object sender, EventArgs eventArgs) {
|
---|
54 | UpdateName();
|
---|
55 | }
|
---|
56 |
|
---|
57 | protected override string CalculateName() {
|
---|
58 | return string.Format("{0} str {1}", base.CalculateName(), ValueName);
|
---|
59 | }
|
---|
60 |
|
---|
61 | private string GetValue(IRun run) {
|
---|
62 | IItem value;
|
---|
63 | run.Results.TryGetValue(ValueName, out value);
|
---|
64 | if (value != null)
|
---|
65 | return value.ToString();
|
---|
66 | run.Parameters.TryGetValue(ValueName, out value);
|
---|
67 | if (value != null)
|
---|
68 | return value.ToString();
|
---|
69 | return "";
|
---|
70 | }
|
---|
71 |
|
---|
72 | public override void Draw(IRun run, Graphics g) {
|
---|
73 | var value = GetValue(run);
|
---|
74 | using(var font = new Font("Helvetica", FontSize)) {
|
---|
75 | var size = g.MeasureString(value, font);
|
---|
76 | g.DrawString(value, font, Brushes.Black,
|
---|
77 | g.ClipBounds.Left+(g.ClipBounds.Width - size.Width)/2,
|
---|
78 | g.ClipBounds.Top+(g.ClipBounds.Height - size.Height)/2);
|
---|
79 | }
|
---|
80 | }
|
---|
81 | }
|
---|
82 | }
|
---|