Free cookie consent management tool by TermsFeed Policy Generator

Changeset 567


Ignore:
Timestamp:
09/14/08 16:16:20 (16 years ago)
Author:
gkronber
Message:

implemented a view that shows the model itself and a line chart and a scatter plot showing original and predicted values. #269 (Functionality to open a chart with predicted vs. original values of any model)

Location:
trunk/sources/HeuristicLab.CEDMA.Charting
Files:
3 added
7 edited

Legend:

Unmodified
Added
Removed
  • trunk/sources/HeuristicLab.CEDMA.Charting/BubbleChart.cs

    r566 r567  
    160160            UpdateViewSize(x, y, size);
    161161            int alpha = CalculateAlpha(size);
    162             Pen pen = new Pen(Color.FromArgb(alpha, r.Selected ? selectionColor: defaultColor));
     162            Pen pen = new Pen(Color.FromArgb(alpha, r.Selected ? selectionColor : defaultColor));
    163163            Brush brush = pen.Brush;
    164164            FixedSizeCircle c = new FixedSizeCircle(this, x, y, size, pen, brush);
    165             c.ToolTipText = CreateToolTipText(r);
     165            c.ToolTipText = r.GetToolTipText();
    166166            points.Add(c);
    167167            primitiveToRecordDictionary[c] = r;
     
    172172        UpdateEnabled = true;
    173173      }
    174     }
    175 
    176     private string CreateToolTipText(Record r) {
    177       StringBuilder b = new StringBuilder();
    178       foreach(KeyValuePair<string, double> v in r.Values) {
    179         b.Append(v.Key).Append(" = ").Append(v.Value).AppendLine();
    180       }
    181       return b.ToString();
    182174    }
    183175
     
    220212    }
    221213
    222     public override void MouseClick(Point point, MouseButtons button) {
    223       if(button == MouseButtons.Left) {
    224         Record r;
    225         IPrimitive p = points.GetPrimitive(TransformPixelToWorld(point));
    226         if(p != null) {
    227           primitiveToRecordDictionary.TryGetValue(p, out r);
    228           if(r != null) r.ToggleSelected();
    229           results.FireChanged();
    230         }
    231       } else base.MouseClick(point, button);
    232     }
    233 
    234     public override void MouseDoubleClick(Point point, MouseButtons button) {
    235       if(button == MouseButtons.Left) {
    236         Record r;
    237         IPrimitive p = points.GetPrimitive(TransformPixelToWorld(point));
    238         if(p != null) {
    239           primitiveToRecordDictionary.TryGetValue(p, out r);
    240           if(r != null) results.OpenModel(r);
    241         }
    242       } else base.MouseDoubleClick(point, button);
    243     }
     214    internal Record GetRecord(Point point) {
     215      Record r = null;
     216      IPrimitive p = points.GetPrimitive(TransformPixelToWorld(point));
     217      if(p != null) {
     218        primitiveToRecordDictionary.TryGetValue(p, out r);
     219      }
     220      return r;
     221    }
     222
    244223
    245224    public override void MouseDrag(Point start, Point end, MouseButtons button) {
     
    261240          }
    262241        }
    263         results.FireChanged();
    264242      } else {
    265243        base.MouseDrag(start, end, button);
  • trunk/sources/HeuristicLab.CEDMA.Charting/BubbleChartControl.Designer.cs

    r566 r567  
    4848      this.pictureBox = new System.Windows.Forms.PictureBox();
    4949      this.pictureBoxContextMenuStrip = new System.Windows.Forms.ContextMenuStrip(this.components);
     50      this.moveToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem();
    5051      this.zoomToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem();
    5152      this.selectToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem();
    52       this.toolStripMenuItem2 = new System.Windows.Forms.ToolStripSeparator();
    5353      this.toolTip = new System.Windows.Forms.ToolTip(this.components);
    5454      ((System.ComponentModel.ISupportInitialize)(this.pictureBox)).BeginInit();
     
    8080      //
    8181      this.pictureBoxContextMenuStrip.Items.AddRange(new System.Windows.Forms.ToolStripItem[] {
     82            this.moveToolStripMenuItem,
    8283            this.zoomToolStripMenuItem,
    83             this.selectToolStripMenuItem,
    84             this.toolStripMenuItem2});
     84            this.selectToolStripMenuItem});
    8585      this.pictureBoxContextMenuStrip.Name = "pictureBoxContextMenuStrip";
    86       this.pictureBoxContextMenuStrip.Size = new System.Drawing.Size(104, 54);
     86      this.pictureBoxContextMenuStrip.Size = new System.Drawing.Size(153, 92);
     87      //
     88      // moveToolStripMenuItem
     89      //
     90      this.moveToolStripMenuItem.Name = "moveToolStripMenuItem";
     91      this.moveToolStripMenuItem.Size = new System.Drawing.Size(152, 22);
     92      this.moveToolStripMenuItem.Text = "Move";
     93      this.moveToolStripMenuItem.Click += new System.EventHandler(this.moveToolStripMenuItem_Click);
    8794      //
    8895      // zoomToolStripMenuItem
    8996      //
    9097      this.zoomToolStripMenuItem.Name = "zoomToolStripMenuItem";
    91       this.zoomToolStripMenuItem.Size = new System.Drawing.Size(103, 22);
     98      this.zoomToolStripMenuItem.Size = new System.Drawing.Size(152, 22);
    9299      this.zoomToolStripMenuItem.Text = "&Zoom";
    93100      this.zoomToolStripMenuItem.Click += new System.EventHandler(this.zoomToolStripMenuItem_Click);
     
    96103      //
    97104      this.selectToolStripMenuItem.Name = "selectToolStripMenuItem";
    98       this.selectToolStripMenuItem.Size = new System.Drawing.Size(103, 22);
     105      this.selectToolStripMenuItem.Size = new System.Drawing.Size(152, 22);
    99106      this.selectToolStripMenuItem.Text = "&Select";
    100107      this.selectToolStripMenuItem.Click += new System.EventHandler(this.selectToolStripMenuItem_Click);
    101       //
    102       // toolStripMenuItem2
    103       //
    104       this.toolStripMenuItem2.Name = "toolStripMenuItem2";
    105       this.toolStripMenuItem2.Size = new System.Drawing.Size(100, 6);
    106108      //
    107109      // BubbleChartControl
     
    126128    protected System.Windows.Forms.ToolStripMenuItem zoomToolStripMenuItem;
    127129    protected System.Windows.Forms.ToolStripMenuItem selectToolStripMenuItem;
    128     protected System.Windows.Forms.ToolStripSeparator toolStripMenuItem2;
     130    private System.Windows.Forms.ToolStripMenuItem moveToolStripMenuItem;
    129131
    130132  }
  • trunk/sources/HeuristicLab.CEDMA.Charting/BubbleChartControl.cs

    r566 r567  
    3434    private Bitmap bitmap;
    3535    private bool renderingRequired;
     36    private Point mousePosition;
     37    private Record clickedRecord;
    3638    private Point buttonDownPoint;
    37     private Point mousePosition;
    38     private int mouseClickCount;
    39     private DateTime lastRendered = DateTime.Now;
     39
    4040    private BubbleChart myChart;
    4141    public BubbleChart Chart {
     
    8282
    8383    private void pictureBox_MouseDown(object sender, MouseEventArgs e) {
     84      clickedRecord = null;
    8485      buttonDownPoint = e.Location;
    85       mouseClickCount = e.Clicks;
     86      if(e.Button == MouseButtons.Left || e.Button == MouseButtons.Right) {
     87        clickedRecord = Chart.GetRecord(buttonDownPoint);
     88      }
    8689    }
    8790    private void pictureBox_MouseUp(object sender, MouseEventArgs e) {
     
    100103            Chart.MouseDrag(lowerLeft, upperRight, e.Button);
    101104          }
     105        } else if(Chart.Mode == ChartMode.Move) {
    102106        }
    103107      } else if(e.Button == MouseButtons.Middle) {
    104108        if(Chart.Mode == ChartMode.Zoom) {
    105           if(mouseClickCount == 1) Chart.ZoomOut();
    106           else if(mouseClickCount == 2) Chart.Unzoom();
     109          Chart.ZoomOut();
    107110        }
    108111      }
     
    138141      SetMode(ChartMode.Select);
    139142    }
     143    private void moveToolStripMenuItem_Click(object sender, EventArgs e) {
     144      SetMode(ChartMode.Move);
     145    }
    140146
    141147    private void GenerateImage() {
     
    162168      zoomToolStripMenuItem.Checked = false;
    163169      selectToolStripMenuItem.Checked = false;
     170      moveToolStripMenuItem.Checked = false;
    164171      if(mode == ChartMode.Zoom) zoomToolStripMenuItem.Checked = true;
    165172      else if(mode == ChartMode.Select) selectToolStripMenuItem.Checked = true;
     173      else if(mode == ChartMode.Move) moveToolStripMenuItem.Checked = true;
    166174      Chart.Mode = mode;
    167175    }
    168176
    169177    private void pictureBox_MouseClick(object sender, MouseEventArgs e) {
    170       Chart.MouseClick(e.Location, e.Button);
     178      if(clickedRecord != null) clickedRecord.ToggleSelected();
    171179    }
    172180
    173181    private void pictureBox_MouseDoubleClick(object sender, MouseEventArgs e) {
    174       Chart.MouseDoubleClick(e.Location, e.Button);
     182      if(clickedRecord != null) clickedRecord.OpenModel();
    175183    }
    176184  }
  • trunk/sources/HeuristicLab.CEDMA.Charting/HeuristicLab.CEDMA.Charting.csproj

    r566 r567  
    7373      <DependentUpon>BubbleChartControl.cs</DependentUpon>
    7474    </Compile>
     75    <Compile Include="ModelView.cs">
     76      <SubType>UserControl</SubType>
     77    </Compile>
     78    <Compile Include="ModelView.Designer.cs">
     79      <DependentUpon>ModelView.cs</DependentUpon>
     80    </Compile>
    7581    <Compile Include="Record.cs" />
    7682    <Compile Include="HeuristicLabCedmaChartingPlugin.cs" />
     
    9096      <Name>HeuristicLab.CEDMA.DB.Interfaces</Name>
    9197    </ProjectReference>
     98    <ProjectReference Include="..\HeuristicLab.Charting.Data\HeuristicLab.Charting.Data.csproj">
     99      <Project>{E0740131-AA3E-4A3F-BA03-C9FF8327F4EE}</Project>
     100      <Name>HeuristicLab.Charting.Data</Name>
     101    </ProjectReference>
    92102    <ProjectReference Include="..\HeuristicLab.Charting\HeuristicLab.Charting.csproj">
    93103      <Project>{B462D3CC-8866-42F0-9832-AD0967613B72}</Project>
     
    97107      <Project>{F43B59AB-2B8C-4570-BC1E-15592086517C}</Project>
    98108      <Name>HeuristicLab.Core</Name>
     109    </ProjectReference>
     110    <ProjectReference Include="..\HeuristicLab.DataAnalysis\HeuristicLab.DataAnalysis.csproj">
     111      <Project>{7DD3A97A-56E9-462F-90E2-A351FE7AF5C2}</Project>
     112      <Name>HeuristicLab.DataAnalysis</Name>
     113    </ProjectReference>
     114    <ProjectReference Include="..\HeuristicLab.Data\HeuristicLab.Data.csproj">
     115      <Project>{F473D9AF-3F09-4296-9F28-3C65118DAFFA}</Project>
     116      <Name>HeuristicLab.Data</Name>
     117    </ProjectReference>
     118    <ProjectReference Include="..\HeuristicLab.Functions\HeuristicLab.Functions.csproj">
     119      <Project>{B95CA6E2-34BC-4430-994D-BD6E99375319}</Project>
     120      <Name>HeuristicLab.Functions</Name>
     121    </ProjectReference>
     122    <ProjectReference Include="..\HeuristicLab.Logging\HeuristicLab.Logging.csproj">
     123      <Project>{4095C92C-5A4C-44BC-9963-5F384CF5CC3F}</Project>
     124      <Name>HeuristicLab.Logging</Name>
    99125    </ProjectReference>
    100126    <ProjectReference Include="..\HeuristicLab.PluginInfrastructure\HeuristicLab.PluginInfrastructure.csproj">
     
    110136    <EmbeddedResource Include="BubbleChartControl.resx">
    111137      <DependentUpon>BubbleChartControl.cs</DependentUpon>
     138      <SubType>Designer</SubType>
     139    </EmbeddedResource>
     140    <EmbeddedResource Include="ModelView.resx">
     141      <DependentUpon>ModelView.cs</DependentUpon>
    112142      <SubType>Designer</SubType>
    113143    </EmbeddedResource>
  • trunk/sources/HeuristicLab.CEDMA.Charting/Record.cs

    r566 r567  
    6868    public const string Y_JITTER = "__Y_JITTER";
    6969
     70    public event EventHandler OnSelectionChanged;
     71
    7072    private Dictionary<string, double> values = new Dictionary<string, double>();
    71     public Dictionary<string, double> Values {
    72       get {
    73         return values;
    74       }
    75     }
     73    private ResultList resultList;
    7674
    7775    private bool selected = false;
     
    8078    private string uri;
    8179    public string Uri { get { return uri; } }
    82     public Record(string uri) {
     80    public Record(ResultList resultList, string uri) {
    8381      this.uri = uri;
     82      this.resultList = resultList;
    8483    }
    8584
    8685    public void Set(string name, double value) {
    87       Values.Add(name, value);
     86      values.Add(name, value);
    8887    }
    8988
    9089    public double Get(string name) {
    91       if(name == null || !Values.ContainsKey(name)) return double.NaN;
    92       return Values[name];
     90      if(name == null || !values.ContainsKey(name)) return double.NaN;
     91      return values[name];
    9392    }
    9493
     
    9695      selected = !selected;
    9796      if(OnSelectionChanged != null) OnSelectionChanged(this, new EventArgs());
     97      resultList.FireChanged();
    9898    }
    9999
    100     public event EventHandler OnSelectionChanged;
     100    internal string GetToolTipText() {
     101      StringBuilder b = new StringBuilder();
     102      foreach(KeyValuePair<string, double> v in values) {
     103        if(v.Key != X_JITTER && v.Key != Y_JITTER) {
     104          b.Append(v.Key).Append(" = ").Append(v.Value).AppendLine();
     105        }
     106      }
     107      return b.ToString();
     108    }
     109
     110    internal void OpenModel() {
     111      resultList.OpenModel(this);
     112    }
    101113  }
    102114}
  • trunk/sources/HeuristicLab.CEDMA.Charting/ResultList.cs

    r566 r567  
    3131using System.IO;
    3232using HeuristicLab.PluginInfrastructure;
     33using HeuristicLab.Logging;
     34using HeuristicLab.Data;
     35using HeuristicLab.DataAnalysis;
     36using HeuristicLab.Functions;
     37using HeuristicLab.Charting.Data;
     38using System.Drawing;
    3339
    3440namespace HeuristicLab.CEDMA.Charting {
     
    5561    private readonly Entity treeHeightPredicate = new Entity(cedmaNS + "TreeHeight");
    5662    private readonly Entity rawDataPredicate = new Entity(cedmaNS + "rawData");
     63    private readonly Entity hasModelPredicate = new Entity(cedmaNS + "hasModel");
    5764    private readonly Entity anyEntity = new Entity(null);
     65    private Dictionary<Record, Dataset> datasets;
    5866
    5967    private IStore store;
     
    102110      foreach(Statement[] ss in results) {
    103111        if(ss.Length > 0) {
    104           Record r = new Record(ss[0].Subject.Uri);
     112          Record r = new Record(this, ss[0].Subject.Uri);
    105113          r.Set(Record.X_JITTER, random.NextDouble() * 2.0 - 1.0);
    106114          r.Set(Record.Y_JITTER, random.NextDouble() * 2.0 - 1.0);
     
    132140      : base() {
    133141      records = new List<Record>();
     142      datasets = new Dictionary<Record, Dataset>();
    134143      predicateToVariableName = new Dictionary<Entity, string>();
    135144      predicateToVariableName[targetVariablePredicate] = Record.TARGET_VARIABLE;
     
    148157    }
    149158
    150     internal void OpenModel(Record r) {
    151       IList<Statement> s = store.Select(new Statement(new Entity(r.Uri), rawDataPredicate, anyEntity));
    152       if(s.Count == 1) {
    153         string rawData = ((SerializedLiteral)s[0].Property).RawData;
     159    internal void OpenModel(Record record) {
     160      IList<Statement> modelResults = store.Select(new Statement(new Entity(record.Uri), rawDataPredicate, anyEntity));
     161      if(modelResults.Count == 1) {
     162        string rawData = ((SerializedLiteral)modelResults[0].Property).RawData;
    154163        XmlDocument doc = new XmlDocument();
    155164        doc.LoadXml(rawData);
    156         IItem item = (IItem)PersistenceManager.Restore(doc.ChildNodes[1], new Dictionary<Guid, IStorable>());
    157         PluginManager.ControlManager.ShowControl(item.CreateView());
     165        IFunctionTree tree = (IFunctionTree)PersistenceManager.Restore(doc.ChildNodes[1], new Dictionary<Guid, IStorable>());
     166        int targetVariable = (int)record.Get(Record.TARGET_VARIABLE);
     167        Dataset dataset = GetDataset(record);
     168
     169        ModelView modelView = new ModelView(dataset, tree, targetVariable);
     170        PluginManager.ControlManager.ShowControl(modelView);
    158171      }
     172    }
     173
     174    private Dataset GetDataset(Record record) {
     175      if(!datasets.ContainsKey(record)) {
     176        IList<Statement> result = store.Select(new Statement(anyEntity, hasModelPredicate, new Entity(record.Uri)));
     177        if(result.Count == 1) {
     178          IList<Statement> datasetResult = store.Select(new Statement(result[0].Subject, rawDataPredicate, anyEntity));
     179          if(datasetResult.Count == 1) {
     180            string rawData = ((SerializedLiteral)datasetResult[0].Property).RawData;
     181            XmlDocument doc = new XmlDocument();
     182            doc.LoadXml(rawData);
     183            Dataset dataset = (Dataset)PersistenceManager.Restore(doc.ChildNodes[1], new Dictionary<Guid, IStorable>());
     184            datasets.Add(record, dataset);
     185          }
     186        }
     187      }
     188      return datasets[record];
    159189    }
    160190  }
  • trunk/sources/HeuristicLab.CEDMA.Charting/ResultListView.cs

    r566 r567  
    1515    private const string FREQUENCY = "<Frequency>";
    1616    private const string CONSTANT_SIZE = "<constant>";
    17     private double xJitterFactor = 0.0;
    18     private double yJitterFactor = 0.0;
    19     private double maxXJitterPercent = .1;
    20     private double maxYJitterPercent = .1;
    2117
    2218    public ResultListView(ResultList results) {
     
    3733
    3834    private void yAxisComboBox_SelectedIndexChanged(object sender, EventArgs e) {
    39       yJitterFactor = 0.0;
    40       yTrackBar.Value = 0;
    4135      UpdateChart();
    4236    }
    4337
    4438    private void xAxisComboBox_SelectedIndexChanged(object sender, EventArgs e) {
    45       xJitterFactor = 0.0;
    46       xTrackBar.Value = 0;
    4739      UpdateChart();
    4840    }
Note: See TracChangeset for help on using the changeset viewer.