Free cookie consent management tool by TermsFeed Policy Generator

Changeset 1108


Ignore:
Timestamp:
01/11/09 19:30:54 (15 years ago)
Author:
gkronber
Message:

worked on CEDMA presentation layer (bubble chart, and collection of results) (#419)

Location:
branches/CEDMA-Refactoring-Ticket419
Files:
9 edited
1 moved

Legend:

Unmodified
Added
Removed
  • branches/CEDMA-Refactoring-Ticket419/HeuristicLab.CEDMA.Charting/BubbleChart.cs

    r1106 r1108  
    3131namespace HeuristicLab.CEDMA.Charting {
    3232  public class BubbleChart : Chart {
     33    private const string X_JITTER = "__X_JITTER";
     34    private const string Y_JITTER = "__Y_JITTER";
    3335    private const double maxXJitterPercent = 0.05;
    3436    private const double maxYJitterPercent = 0.05;
     
    5052    private double maxX = double.NegativeInfinity;
    5153    private double maxY = double.NegativeInfinity;
    52     private List<Record> records;
     54    private List<ResultsEntry> records;
    5355    private Results results;
    54     private Dictionary<IPrimitive, Record> primitiveToRecordDictionary;
    55     private Dictionary<Record, IPrimitive> recordToPrimitiveDictionary;
     56    private Dictionary<IPrimitive, ResultsEntry> primitiveToEntryDictionary;
     57    private Dictionary<ResultsEntry, IPrimitive> entryToPrimitiveDictionary;
    5658    private Random random = new Random();
    5759    private Group points;
     
    5961    public BubbleChart(Results results, PointD lowerLeft, PointD upperRight)
    6062      : base(lowerLeft, upperRight) {
    61       records = new List<Record>();
    62       primitiveToRecordDictionary = new Dictionary<IPrimitive, Record>();
    63       recordToPrimitiveDictionary = new Dictionary<Record, IPrimitive>();
     63      records = new List<ResultsEntry>();
     64      primitiveToEntryDictionary = new Dictionary<IPrimitive, ResultsEntry>();
     65      entryToPrimitiveDictionary = new Dictionary<ResultsEntry, IPrimitive>();
    6466      this.results = results;
    65       foreach(Record r in results.Records) {
    66         records.Add(r);
    67      }
    68       results.OnRecordAdded += new EventHandler<RecordAddedEventArgs>(results_OnRecordAdded);
    69       results.Changed += new EventHandler(results_Changed);
    7067    }
    7168
     
    7572    }
    7673
    77     public BubbleChart(ResultList results, double x1, double y1, double x2, double y2)
     74    public BubbleChart(Results results, double x1, double y1, double x2, double y2)
    7875      : this(results, new PointD(x1, y1), new PointD(x2, y2)) {
    7976    }
    8077
    81     void results_OnRecordAdded(object sender, RecordAddedEventArgs e) {
    82       lock(records) {
    83         records.Add(e.Record);
    84       }
    85     }
     78    //void results_OnRecordAdded(object sender, RecordAddedEventArgs e) {
     79    //  lock(records) {
     80    //    records.Add(e.Record);
     81    //  }
     82    //}
    8683
    8784    public void SetBubbleSizeDimension(string dimension, bool inverted) {
     
    9390
    9491    public void ShowXvsY(string xDimension, string yDimension) {
    95       if(this.xDimension != xDimension || this.yDimension != yDimension) {
     92      if (this.xDimension != xDimension || this.yDimension != yDimension) {
    9693        this.xDimension = xDimension;
    9794        this.yDimension = yDimension;
     95
     96        foreach (var resultsEntry in results.SelectRows()) {
     97          resultsEntry.Set(X_JITTER, random.NextDouble() * 2.0 - 1.0);
     98          resultsEntry.Set(Y_JITTER, random.NextDouble() * 2.0 - 1.0);
     99          records.Add(resultsEntry);
     100        }
    98101        ResetViewSize();
    99102        Repaint();
     
    110113
    111114    private void Repaint() {
    112       if(xDimension == null || yDimension == null) return;
    113       lock(records) {
    114         double maxSize = 1;
    115         double minSize = 1;
    116         if(sizeDimension != null) {
    117           var sizes = records.Select(r => r.Get(sizeDimension)).Where(x => !double.IsInfinity(x) && x != double.MaxValue && x != double.MinValue).OrderBy(x=>x);
     115      if (xDimension == null || yDimension == null) return;
     116      double maxSize = 1;
     117      double minSize = 1;
     118      try {
     119        if (sizeDimension != null && Results.OrdinalVariables.Contains(sizeDimension)) {
     120          var sizes = records
     121            .Select(x => Convert.ToDouble(x.Get(sizeDimension)))
     122            .Where(size => !double.IsInfinity(size) && size != double.MaxValue && size != double.MinValue)
     123            .OrderBy(r => r);
    118124          minSize = sizes.ElementAt((int)(sizes.Count() * 0.1));
    119125          maxSize = sizes.ElementAt((int)(sizes.Count() * 0.9));
    120126        }
    121         UpdateEnabled = false;
    122         Group.Clear();
    123         primitiveToRecordDictionary.Clear();
    124         recordToPrimitiveDictionary.Clear();
    125         points = new Group(this);
    126         Group.Add(new Axis(this, 0, 0, AxisType.Both));
    127         UpdateViewSize(0, 0, 5);
    128         foreach(Record r in records) {
    129           double x = r.Get(xDimension) + r.Get(Record.X_JITTER) * xJitterFactor;
    130           double y = r.Get(yDimension) + r.Get(Record.Y_JITTER) * yJitterFactor;
    131           int size = CalculateSize(r.Get(sizeDimension), minSize, maxSize);
    132 
    133           if(double.IsInfinity(x) || x == double.MaxValue || x == double.MinValue) x = double.NaN;
    134           if(double.IsInfinity(y) || y == double.MaxValue || y == double.MinValue) y = double.NaN;
    135           if(!double.IsNaN(x) && !double.IsNaN(y)) {
    136             UpdateViewSize(x, y, size);
    137             int alpha = CalculateAlpha(size);
    138             Pen pen = new Pen(Color.FromArgb(alpha, r.Selected ? selectionColor : defaultColor));
    139             Brush brush = pen.Brush;
    140             FixedSizeCircle c = new FixedSizeCircle(this, x, y, size, pen, brush);
    141             c.ToolTipText = r.GetToolTipText();
    142             points.Add(c);
    143             if(!r.Selected) c.IntoBackground();
    144             primitiveToRecordDictionary[c] = r;
    145             recordToPrimitiveDictionary[r] = c;
    146           }
    147         }
    148         Group.Add(points);
    149         UpdateEnabled = true;
    150       }
     127      }
     128      catch (InvalidCastException) {
     129        minSize = 1;
     130        maxSize = 1;
     131      }
     132      UpdateEnabled = false;
     133      Group.Clear();
     134      primitiveToEntryDictionary.Clear();
     135      entryToPrimitiveDictionary.Clear();
     136      points = new Group(this);
     137      Group.Add(new Axis(this, 0, 0, AxisType.Both));
     138      UpdateViewSize(0, 0, 5);
     139      foreach (ResultsEntry r in records) {
     140        double x, y;
     141        int size;
     142        try {
     143          x = Convert.ToDouble(r.Get(xDimension)) + (double)r.Get(X_JITTER) * xJitterFactor;
     144          y = Convert.ToDouble(r.Get(yDimension)) + (double)r.Get(Y_JITTER) * yJitterFactor;
     145          size = CalculateSize(Convert.ToDouble(r.Get(sizeDimension)), minSize, maxSize);
     146        }
     147        catch (InvalidCastException) {
     148          x = double.NaN;
     149          y = double.NaN;
     150          size = minBubbleSize;
     151        }
     152        if (double.IsInfinity(x) || x == double.MaxValue || x == double.MinValue) x = double.NaN;
     153        if (double.IsInfinity(y) || y == double.MaxValue || y == double.MinValue) y = double.NaN;
     154        if (!double.IsNaN(x) && !double.IsNaN(y)) {
     155          UpdateViewSize(x, y, size);
     156          int alpha = CalculateAlpha(size);
     157          Pen pen = new Pen(Color.FromArgb(alpha, r.Selected ? selectionColor : defaultColor));
     158          Brush brush = pen.Brush;
     159          FixedSizeCircle c = new FixedSizeCircle(this, x, y, size, pen, brush);
     160          c.ToolTipText = r.GetToolTipText();
     161          points.Add(c);
     162          if (!r.Selected) c.IntoBackground();
     163          primitiveToEntryDictionary[c] = r;
     164          entryToPrimitiveDictionary[r] = c;
     165        }
     166      }
     167      Group.Add(points);
     168      UpdateEnabled = true;
    151169    }
    152170
    153171    private int CalculateSize(double size, double minSize, double maxSize) {
    154       if(double.IsNaN(size) || double.IsInfinity(size) || size == double.MaxValue || size == double.MinValue) return minBubbleSize;
    155       if(size > maxSize) size = maxSize;
    156       if(size < minSize) size = minSize;
     172      if (double.IsNaN(size) || double.IsInfinity(size) || size == double.MaxValue || size == double.MinValue) return minBubbleSize;
     173      if (size > maxSize) size = maxSize;
     174      if (size < minSize) size = minSize;
     175      if (Math.Abs(maxSize - minSize) < 1.0E-10) return minBubbleSize;
    157176      double sizeDifference = ((size - minSize) / (maxSize - minSize) * (maxBubbleSize - minBubbleSize));
    158       if(invertSize) return maxBubbleSize - (int)sizeDifference;
     177      if (invertSize) return maxBubbleSize - (int)sizeDifference;
    159178      else return minBubbleSize + (int)sizeDifference;
    160179    }
     
    165184
    166185    private void ZoomToViewSize() {
    167       if(minX < maxX && minY < maxY) {
     186      if (minX < maxX && minY < maxY) {
    168187        // enlarge view by 5% on each side
    169188        double width = maxX - minX;
     
    178197
    179198    private void UpdateViewSize(double x, double y, double size) {
    180       if(x - size < minX) minX = x - size;
    181       if(x + size > maxX) maxX = x + size;
    182       if(y - size < minY) minY = y + size;
    183       if(y + size > maxY) maxY = y + size;
     199      if (x - size < minX) minX = x - size;
     200      if (x + size > maxX) maxX = x + size;
     201      if (y - size < minY) minY = y + size;
     202      if (y + size > maxY) maxY = y + size;
    184203    }
    185204
     
    191210    }
    192211
    193     internal Record GetRecord(Point point) {
    194       Record r = null;
     212    internal ResultsEntry GetResultsEntry(Point point) {
     213      ResultsEntry r = null;
    195214      IPrimitive p = points.GetPrimitive(TransformPixelToWorld(point));
    196       if(p != null) {
    197         primitiveToRecordDictionary.TryGetValue(p, out r);
     215      if (p != null) {
     216        primitiveToEntryDictionary.TryGetValue(p, out r);
    198217      }
    199218      return r;
     
    202221
    203222    public override void MouseDrag(Point start, Point end, MouseButtons button) {
    204       if(button == MouseButtons.Left && Mode == ChartMode.Select) {
     223      if (button == MouseButtons.Left && Mode == ChartMode.Select) {
    205224        PointD a = TransformPixelToWorld(start);
    206225        PointD b = TransformPixelToWorld(end);
     
    214233        primitives.AddRange(points.Primitives);
    215234
    216         foreach(FixedSizeCircle p in primitives) {
    217           if(rect.ContainsPoint(p.Point)) {
    218             Record r;
    219             primitiveToRecordDictionary.TryGetValue(p, out r);
    220             if(r != null) r.ToggleSelected();
     235        foreach (FixedSizeCircle p in primitives) {
     236          if (rect.ContainsPoint(p.Point)) {
     237            ResultsEntry r;
     238            primitiveToEntryDictionary.TryGetValue(p, out r);
     239            if (r != null) r.ToggleSelected();
    221240          }
    222241        }
    223         results.FireChanged();
     242        // results.FireChanged();
    224243      } else {
    225244        base.MouseDrag(start, end, button);
     
    228247
    229248    public override void MouseClick(Point point, MouseButtons button) {
    230       if(button == MouseButtons.Left) {
    231         Record r = GetRecord(point);
    232         if(r != null) r.ToggleSelected();
    233         results.FireChanged();
     249      if (button == MouseButtons.Left) {
     250        ResultsEntry r = GetResultsEntry(point);
     251        if (r != null) r.ToggleSelected();
     252        //        results.FireChanged();
    234253      } else {
    235254        base.MouseClick(point, button);
     
    237256    }
    238257
    239     public override void MouseDoubleClick(Point point, MouseButtons button) {
    240       if(button == MouseButtons.Left) {
    241         Record r = GetRecord(point);
    242         if(r != null) r.OpenModel();
    243       } else {
    244         base.MouseDoubleClick(point, button);
    245       }
    246     }
     258    //public override void MouseDoubleClick(Point point, MouseButtons button) {
     259    //  if(button == MouseButtons.Left) {
     260    //    Record r = GetRecord(point);
     261    //    if(r != null) r.OpenModel();
     262    //  } else {
     263    //    base.MouseDoubleClick(point, button);
     264    //  }
     265    //}
    247266  }
    248267}
  • branches/CEDMA-Refactoring-Ticket419/HeuristicLab.CEDMA.Charting/BubbleChartView.cs

    r1106 r1108  
    1212
    1313namespace HeuristicLab.CEDMA.Charting {
    14   public partial class BubbleChartView : ViewBase {
     14  public partial class BubbleChartView : ViewBase, IResultsView {
    1515    private Results results;
    1616    private const string CONSTANT_SIZE = "<constant>";
    1717    private Label pleaseSelectAxisLabel = new Label();
    1818
    19     public BubbleChartView(Results results) {
    20       this.results = results;
     19    public BubbleChartView() {
    2120      InitializeComponent();
    22       bubbleChartControl.Chart = new BubbleChart(results, 0, 0, 100, 100);
    23       xAxisComboBox.Items.AddRange(results.OrdinalVariableNames);
    24       yAxisComboBox.Items.AddRange(results.OrdinalVariableNames);
    25       sizeComboBox.Items.Add(CONSTANT_SIZE);
    26       sizeComboBox.Items.AddRange(results.VariableNames);
    27       sizeComboBox.SelectedItem = sizeComboBox.Items[0];
    28       sizeComboBox.Enabled = false;
    29       invertCheckbox.Enabled = false;
    30       sizeLabel.Enabled = false;
    31       yAxisComboBox.SelectedItem = yAxisComboBox.Items[0];
    32       xAxisComboBox.SelectedItem = xAxisComboBox.Items[0];
    3321    }
    3422
     
    3927    private void UpdateChart() {
    4028      if (xAxisComboBox.SelectedItem == null || yAxisComboBox.SelectedItem == null) return;
    41       xJitterlabel.Enabled = true;
    42       xTrackBar.Enabled = true;
    43       yJitterLabel.Enabled = true;
    44       yTrackBar.Enabled = true;
    45       sizeComboBox.Enabled = true;
    46       invertCheckbox.Enabled = true;
    47       sizeLabel.Enabled = true;
    4829      bubbleChartControl.Chart.ShowXvsY((string)xAxisComboBox.SelectedItem, (string)yAxisComboBox.SelectedItem);
    4930    }
     
    6445      }
    6546    }
     47
     48    #region IResultsView Members
     49
     50    public Control Control {
     51      get { return this; }
     52    }
     53
     54    string IResultsView.Name {
     55      get { return "Bubble chart"; }
     56    }
     57
     58    public void ShowResults(Results results) {
     59      this.results = results;
     60      bubbleChartControl.Chart = new BubbleChart(results, 0, 0, 100, 100);
     61      xAxisComboBox.Items.AddRange(Results.OrdinalVariables);
     62      xAxisComboBox.Items.AddRange(Results.CategoricalVariables);
     63      yAxisComboBox.Items.AddRange(Results.OrdinalVariables);
     64      yAxisComboBox.Items.AddRange(Results.CategoricalVariables);
     65      sizeComboBox.Items.Add(CONSTANT_SIZE);
     66      sizeComboBox.Items.AddRange(Results.OrdinalVariables);
     67      sizeComboBox.SelectedItem = sizeComboBox.Items[0];
     68      yAxisComboBox.SelectedItem = yAxisComboBox.Items[0];
     69      xAxisComboBox.SelectedItem = xAxisComboBox.Items[0];
     70    }
     71
     72    #endregion
    6673  }
    6774}
  • branches/CEDMA-Refactoring-Ticket419/HeuristicLab.CEDMA.Charting/HeuristicLab.CEDMA.Charting.csproj

    r1106 r1108  
    6666  </ItemGroup>
    6767  <ItemGroup>
     68    <Compile Include="BubbleChart.cs" />
     69    <Compile Include="BubbleChartControl.cs">
     70      <SubType>UserControl</SubType>
     71    </Compile>
     72    <Compile Include="BubbleChartControl.Designer.cs">
     73      <DependentUpon>BubbleChartControl.cs</DependentUpon>
     74    </Compile>
     75    <Compile Include="BubbleChartView.cs">
     76      <SubType>UserControl</SubType>
     77    </Compile>
     78    <Compile Include="BubbleChartView.Designer.cs">
     79      <DependentUpon>BubbleChartView.cs</DependentUpon>
     80    </Compile>
    6881    <Compile Include="HeuristicLabCedmaChartingPlugin.cs" />
    6982    <Compile Include="Properties\AssemblyInfo.cs" />
     
    98111      <Name>HeuristicLab.Data</Name>
    99112    </ProjectReference>
    100     <ProjectReference Include="..\HeuristicLab.GP.StructureIdentification\HeuristicLab.GP.StructureIdentification.csproj">
    101       <Project>{74223A32-C726-4978-BE78-37113A18373C}</Project>
    102       <Name>HeuristicLab.GP.StructureIdentification</Name>
    103     </ProjectReference>
    104     <ProjectReference Include="..\HeuristicLab.GP\HeuristicLab.GP.csproj">
    105       <Project>{1F1CF3ED-374C-4288-995B-93F6B872F571}</Project>
    106       <Name>HeuristicLab.GP</Name>
    107     </ProjectReference>
    108113    <ProjectReference Include="..\HeuristicLab.Logging\HeuristicLab.Logging.csproj">
    109114      <Project>{4095C92C-5A4C-44BC-9963-5F384CF5CC3F}</Project>
     
    118123    <None Include="HeuristicLab.snk" />
    119124    <None Include="Properties\AssemblyInfo.frame" />
     125  </ItemGroup>
     126  <ItemGroup>
     127    <EmbeddedResource Include="BubbleChartControl.resx">
     128      <DependentUpon>BubbleChartControl.cs</DependentUpon>
     129    </EmbeddedResource>
     130    <EmbeddedResource Include="BubbleChartView.resx">
     131      <DependentUpon>BubbleChartView.cs</DependentUpon>
     132    </EmbeddedResource>
    120133  </ItemGroup>
    121134  <Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
  • branches/CEDMA-Refactoring-Ticket419/HeuristicLab.CEDMA.Core/DataSetView.Designer.cs

    r1106 r1108  
    4545    /// </summary>
    4646    private void InitializeComponent() {
    47       this.editorGroupBox = new System.Windows.Forms.GroupBox();
    48       this.activateButton = new System.Windows.Forms.Button();
    49       this.resultsButton = new System.Windows.Forms.Button();
    50       this.SuspendLayout();
    51       //
    52       // editorGroupBox
    53       //
    54       this.editorGroupBox.Anchor = ((System.Windows.Forms.AnchorStyles)((((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Bottom)
    55                   | System.Windows.Forms.AnchorStyles.Left)
    56                   | System.Windows.Forms.AnchorStyles.Right)));
    57       this.editorGroupBox.Location = new System.Drawing.Point(0, 3);
    58       this.editorGroupBox.Name = "editorGroupBox";
    59       this.editorGroupBox.Size = new System.Drawing.Size(274, 119);
    60       this.editorGroupBox.TabIndex = 0;
    61       this.editorGroupBox.TabStop = false;
    62       this.editorGroupBox.Text = "&Editor:";
    63       //
    64       // activateButton
    65       //
    66       this.activateButton.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Left)));
    67       this.activateButton.Location = new System.Drawing.Point(3, 128);
    68       this.activateButton.Name = "activateButton";
    69       this.activateButton.Size = new System.Drawing.Size(75, 23);
    70       this.activateButton.TabIndex = 2;
    71       this.activateButton.Text = "&Activate";
    72       this.activateButton.UseVisualStyleBackColor = true;
    73       this.activateButton.Click += new System.EventHandler(this.activateButton_Click);
    74       //
    75       // resultsButton
    76       //
    77       this.resultsButton.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Left)));
    78       this.resultsButton.Location = new System.Drawing.Point(84, 128);
    79       this.resultsButton.Name = "resultsButton";
    80       this.resultsButton.Size = new System.Drawing.Size(75, 23);
    81       this.resultsButton.TabIndex = 3;
    82       this.resultsButton.Text = "Show results";
    83       this.resultsButton.UseVisualStyleBackColor = true;
    84       this.resultsButton.Click += new System.EventHandler(this.resultsButton_Click);
    85       //
    86       // DataSetView
    87       //
    88       this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 13F);
    89       this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
    90       this.Controls.Add(this.resultsButton);
    91       this.Controls.Add(this.activateButton);
    92       this.Controls.Add(this.editorGroupBox);
    93       this.Name = "DataSetView";
    94       this.Size = new System.Drawing.Size(274, 154);
    95       this.ResumeLayout(false);
     47        this.editorGroupBox = new System.Windows.Forms.GroupBox();
     48        this.activateButton = new System.Windows.Forms.Button();
     49        this.resultsButton = new System.Windows.Forms.Button();
     50        this.SuspendLayout();
     51        //
     52        // editorGroupBox
     53        //
     54        this.editorGroupBox.Anchor = ((System.Windows.Forms.AnchorStyles)((((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Bottom)
     55                    | System.Windows.Forms.AnchorStyles.Left)
     56                    | System.Windows.Forms.AnchorStyles.Right)));
     57        this.editorGroupBox.Location = new System.Drawing.Point(0, 3);
     58        this.editorGroupBox.Name = "editorGroupBox";
     59        this.editorGroupBox.Size = new System.Drawing.Size(274, 119);
     60        this.editorGroupBox.TabIndex = 0;
     61        this.editorGroupBox.TabStop = false;
     62        this.editorGroupBox.Text = "&Editor:";
     63        //
     64        // activateButton
     65        //
     66        this.activateButton.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Left)));
     67        this.activateButton.Location = new System.Drawing.Point(3, 128);
     68        this.activateButton.Name = "activateButton";
     69        this.activateButton.Size = new System.Drawing.Size(75, 23);
     70        this.activateButton.TabIndex = 2;
     71        this.activateButton.Text = "&Activate";
     72        this.activateButton.UseVisualStyleBackColor = true;
     73        this.activateButton.Click += new System.EventHandler(this.activateButton_Click);
     74        //
     75        // resultsButton
     76        //
     77        this.resultsButton.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Left)));
     78        this.resultsButton.Location = new System.Drawing.Point(84, 128);
     79        this.resultsButton.Name = "resultsButton";
     80        this.resultsButton.Size = new System.Drawing.Size(86, 23);
     81        this.resultsButton.TabIndex = 3;
     82        this.resultsButton.Text = "Show results";
     83        this.resultsButton.UseVisualStyleBackColor = true;
     84        this.resultsButton.Click += new System.EventHandler(this.resultsButton_Click);
     85        //
     86        // DataSetView
     87        //
     88        this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 13F);
     89        this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
     90        this.Controls.Add(this.resultsButton);
     91        this.Controls.Add(this.activateButton);
     92        this.Controls.Add(this.editorGroupBox);
     93        this.Name = "DataSetView";
     94        this.Size = new System.Drawing.Size(274, 154);
     95        this.ResumeLayout(false);
    9696
    9797    }
  • branches/CEDMA-Refactoring-Ticket419/HeuristicLab.CEDMA.Core/HeuristicLab.CEDMA.Core.csproj

    r1106 r1108  
    7272  </ItemGroup>
    7373  <ItemGroup>
     74    <Compile Include="ResultsEntry.cs" />
    7475    <Compile Include="TableResultsView.cs">
    7576      <SubType>UserControl</SubType>
  • branches/CEDMA-Refactoring-Ticket419/HeuristicLab.CEDMA.Core/IResultsView.cs

    r1106 r1108  
    3333  public interface IResultsView {
    3434    Control Control { get; }
     35    string Name { get; }
    3536    void ShowResults(Results results);
    3637  }
  • branches/CEDMA-Refactoring-Ticket419/HeuristicLab.CEDMA.Core/Results.cs

    r1106 r1108  
    6363    }
    6464
    65     internal IEnumerable<object[]> SelectRows(List<string> columnNames) {
    66       if (store == null) yield return null;
    67 
    68       Resource[] columnNamesRes = columnNames.Select(x => new Literal(x)).ToArray();
     65    public IEnumerable<ResultsEntry> SelectRows() {
     66      if (store == null) yield break;
    6967
    7068      var results = store.Select(new Statement(dataSetEntity, Ontology.PredicateHasModel, Ontology.AnyEntity))
     
    7876              new Entity[] { (Entity)x.Property },
    7977              new Entity[] { Ontology.PredicateModelAttributeName },
    80               columnNamesRes)).Select(y =>
     78              new Entity[] { Ontology.AnyEntity })).Select(y =>
    8179                new {
    8280                  Model = x.Subject,
     
    9290                 AttributeName = x.AttributeName.Value,
    9391                 AttributeValue = ((Literal)y.Property).Value
    94                })).GroupBy(x=>x.Model);
     92               })).GroupBy(x => x.Model);
    9593
    9694
    9795      Random random = new Random();
    9896      foreach (var row in results) {
     97        ResultsEntry entry = new ResultsEntry(row.First().Model);
     98        foreach (var attr in row) {
     99          entry.Set((string)attr.AttributeName, attr.AttributeValue);
     100        }
     101        yield return entry;
     102      }
     103    }
    99104
    100         yield return row.Select(x => x.AttributeValue).ToArray();
    101         //if (ss.Length > 0) {
    102         //  Record r = new Record(this, ss[0].Subject.Uri);
    103         //  r.Set(Record.X_JITTER, random.NextDouble() * 2.0 - 1.0);
    104         //  r.Set(Record.Y_JITTER, random.NextDouble() * 2.0 - 1.0);
    105         //  foreach (Statement s in ss) {
    106         //    string varName;
    107         //    predicateToVariableName.TryGetValue(s.Predicate, out varName);
    108         //    if (varName != null) {
    109         //      if (varName == Record.TREE_HEIGHT || varName == Record.TREE_SIZE || varName == Record.TARGET_VARIABLE) {
    110         //        r.Set(varName, (double)(int)((Literal)s.Property).Value);
    111         //      } else {
    112         //        r.Set(varName, (double)((Literal)s.Property).Value);
    113         //      }
    114         //    }
    115         //  }
    116         //}
     105    internal IEnumerable<string> SelectModelAttributes() {
     106      if (store == null) yield break;
     107
     108      var attributeNames =
     109        store.Select(new Statement(Ontology.AnyEntity, Ontology.PredicateModelAttributeName, Ontology.AnyEntity))
     110        .Select(s => (string)((Literal)s.Property).Value)
     111        .Distinct();
     112      foreach (var name in attributeNames) {
     113        yield return name;
    117114      }
    118115    }
  • branches/CEDMA-Refactoring-Ticket419/HeuristicLab.CEDMA.Core/ResultsEntry.cs

    r1107 r1108  
    11#region License Information
    2 /* HeuristicLab
    3  * Copyright (C) 2002-2008 Heuristic and Evolutionary Algorithms Laboratory (HEAL)
    4  *
    5  * This file is part of HeuristicLab.
    6  *
    7  * HeuristicLab is free software: you can redistribute it and/or modify
    8  * it under the terms of the GNU General Public License as published by
    9  * the Free Software Foundation, either version 3 of the License, or
    10  * (at your option) any later version.
    11  *
    12  * HeuristicLab is distributed in the hope that it will be useful,
    13  * but WITHOUT ANY WARRANTY; without even the implied warranty of
    14  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
    15  * GNU General Public License for more details.
    16  *
    17  * You should have received a copy of the GNU General Public License
    18  * along with HeuristicLab. If not, see <http://www.gnu.org/licenses/>.
    19  */
    20 #endregion
    21 
    22 #region License Information
    232/* HeuristicLab
    243 * Copyright (C) 2002-2008 Heuristic and Evolutionary Algorithms Laboratory (HEAL)
     
    5332using HeuristicLab.PluginInfrastructure;
    5433
    55 namespace HeuristicLab.CEDMA.Charting {
    56   public class Record {
    57     public const string MAPE_TRAINING = "MAPE (training)";
    58     public const string MAPE_VALIDATION = "MAPE (validation)";
    59     public const string MAPE_TEST = "MAPE (test)";
    60     public const string R2_TRAINING = "R2 (training)";
    61     public const string R2_VALIDATION = "R2 (validation)";
    62     public const string R2_TEST = "R2 (test)";
    63     public const string TARGET_VARIABLE = "Target variable";
    64     public const string TREE_SIZE = "Tree size";
    65     public const string TREE_HEIGHT = "Tree height";
    66     public const string SELECTIONPRESSURE = "Selection pressure";
    67 
    68     public const string X_JITTER = "__X_JITTER";
    69     public const string Y_JITTER = "__Y_JITTER";
    70 
    71     private Dictionary<string, double> values = new Dictionary<string, double>();
    72     private ResultList resultList;
     34namespace HeuristicLab.CEDMA.Core {
     35  public class ResultsEntry {
     36    private Dictionary<string, object> values = new Dictionary<string, object>();
    7337
    7438    private bool selected = false;
     
    7741    private string uri;
    7842    public string Uri { get { return uri; } }
    79     public Record(ResultList resultList, string uri) {
     43
     44    public ResultsEntry(string uri) {
    8045      this.uri = uri;
    81       this.resultList = resultList;
    8246    }
    8347
    84     public void Set(string name, double value) {
     48    public void Set(string name, object value) {
    8549      values.Add(name, value);
    8650    }
    8751
    88     public double Get(string name) {
    89       if(name == null || !values.ContainsKey(name)) return double.NaN;
     52    public object Get(string name) {
     53      if (name == null || !values.ContainsKey(name)) return null;
    9054      return values[name];
    9155    }
     
    9559    }
    9660
    97     internal string GetToolTipText() {
     61    public string GetToolTipText() {
    9862      StringBuilder b = new StringBuilder();
    99       foreach(KeyValuePair<string, double> v in values) {
    100         if(v.Key != X_JITTER && v.Key != Y_JITTER) {
    101           b.Append(v.Key).Append(" = ").Append(v.Value).AppendLine();
    102         }
     63      foreach (KeyValuePair<string, object> v in values) {
     64        b.Append(v.Key).Append(" = ").Append(v.Value).AppendLine();
    10365      }
    10466      return b.ToString();
    10567    }
    10668
    107     internal void OpenModel() {
    108       resultList.OpenModel(this);
    109     }
     69    //internal void OpenModel() {
     70    //  resultList.OpenModel(this);
     71    //}
    11072
    111     internal void OpenGeneratingAlgorithm() {
    112       resultList.OpenAlgorithm(this);
    113     }
     73    //internal void OpenGeneratingAlgorithm() {
     74    //  resultList.OpenAlgorithm(this);
     75    //}
    11476  }
    11577}
  • branches/CEDMA-Refactoring-Ticket419/HeuristicLab.CEDMA.Core/ResultsViewContainer.cs

    r1106 r1108  
    1818      InitializeComponent();
    1919      PopulateViewComboBox();
    20       showButton.Enabled = false;
     20      showButton.Enabled = viewComboBox.SelectedItem != null;
    2121    }
    2222
    2323    private void PopulateViewComboBox() {
    2424      DiscoveryService service = new DiscoveryService();
    25       Type[] viewTypes = service.GetTypes(typeof(IResultsView));
    26       foreach (Type t in viewTypes)
    27         viewComboBox.Items.Add(t);
     25      IResultsView[] views = service.GetInstances<IResultsView>();
     26      viewComboBox.DataSource = views;
     27      viewComboBox.ValueMember = "Name";
    2828    }
    2929
     
    3131      viewPanel.Controls.Clear();
    3232      try {
    33         Type type = (Type)viewComboBox.SelectedItem;
    34         IResultsView view = (IResultsView)Activator.CreateInstance(type);
     33        IResultsView view = (IResultsView)viewComboBox.SelectedItem;
    3534        Control control = view.Control;
    3635        viewPanel.Controls.Add(control);
  • branches/CEDMA-Refactoring-Ticket419/HeuristicLab.CEDMA.Core/TableResultsView.cs

    r1106 r1108  
    2121    }
    2222
     23    string IResultsView.Name {
     24      get { return "Table"; }
     25    }
     26
    2327    public void ShowResults(Results results) {
    2428      this.results = results;
     
    2933      base.UpdateControls();
    3034      if (results == null) return;
    31       List<string> columnNames = new List<string>();
    32       columnNames.AddRange(Results.CategoricalVariables);
    33       columnNames.AddRange(Results.OrdinalVariables);
    3435      dataGridView.Rows.Clear();
    3536      dataGridView.Columns.Clear();
    36       foreach (string varName in columnNames) {
    37         dataGridView.Columns.Add(varName, varName);
     37      List<string> attributeNames = results.SelectModelAttributes().ToList();
     38      foreach (var attribute in attributeNames) {
     39        dataGridView.Columns.Add(attribute, attribute);
    3840      }
    3941
    40       foreach (object[] row in results.SelectRows(columnNames)) {
     42      var entries = results.SelectRows();
     43      foreach (var entry in entries) {
     44        int rowIndex = dataGridView.Rows.Add();
     45        foreach (string attrName in attributeNames) {
     46          dataGridView.Rows[rowIndex].Cells[attrName].Value = entry.Get(attrName);
     47        }
    4148        dataGridView.Rows.Add(row);
    4249      }
Note: See TracChangeset for help on using the changeset viewer.