Free cookie consent management tool by TermsFeed Policy Generator

Changeset 566 for trunk


Ignore:
Timestamp:
09/14/08 10:13:32 (16 years ago)
Author:
gkronber
Message:

implemented 'brushing' and cleaned up code a little bit. #270 (Selection of multiple points)

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

Legend:

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

    r562 r566  
    5252    private ResultList results;
    5353    private Dictionary<IPrimitive, Record> primitiveToRecordDictionary;
     54    private Dictionary<Record, IPrimitive> recordToPrimitiveDictionary;
    5455    private Random random = new Random();
    5556    private Group points;
     
    5960      records = new List<Record>();
    6061      primitiveToRecordDictionary = new Dictionary<IPrimitive, Record>();
     62      recordToPrimitiveDictionary = new Dictionary<Record, IPrimitive>();
    6163      this.results = results;
     64      foreach(Record r in results.Records) {
     65        records.Add(r);
     66        r.OnSelectionChanged += new EventHandler(Record_OnSelectionChanged);
     67      }
    6268      results.OnRecordAdded += new EventHandler<RecordAddedEventArgs>(results_OnRecordAdded);
     69      results.Changed += new EventHandler(results_Changed);
     70    }
     71
     72    void results_Changed(object sender, EventArgs e) {
     73      Repaint();
     74      EnforceUpdate();
    6375    }
    6476
     
    7688    void Record_OnSelectionChanged(object sender, EventArgs e) {
    7789      Record r = (Record)sender;
    78       foreach(KeyValuePair<IPrimitive, Record> pair in primitiveToRecordDictionary) {
    79         if(pair.Value == r) {
    80           IPrimitive primitive = pair.Key;
    81           if(r.Selected) {
    82             int alpha = primitive.Pen.Color.A;
    83             primitive.Pen.Color = Color.FromArgb(alpha, selectionColor);
    84             primitive.Brush = primitive.Pen.Brush;
    85             primitive.IntoForeground();
    86           } else {
    87             int alpha = primitive.Pen.Color.A;
    88             primitive.Pen.Color = Color.FromArgb(alpha, defaultColor);
    89             primitive.Brush = primitive.Pen.Brush;
    90             primitive.IntoBackground();
    91           }
    92           primitive.EnforceUpdate();
    93         }
    94       }
    95     }
    96 
    97     //public void AddDimension(string name) {
    98     //  dimensions.Add(name);
    99     //  values.Add(name, new List<double>());
    100     //}
    101     //public void RemoveDimension(string name) {
    102     //  dimensions.Remove(name);
    103     //  values.Remove(name);
    104     //}
    105 
    106     //public void AddDataPoint(string dimension, double value) {
    107     //  values[dimension].Add(value);
    108     //}
     90      IPrimitive primitive;
     91      recordToPrimitiveDictionary.TryGetValue(r, out primitive);
     92      if(primitive != null) {
     93        ((FixedSizeCircle)primitive).UpdateEnabled = false;
     94        points.UpdateEnabled = false;
     95        if(r.Selected) {
     96          int alpha = primitive.Pen.Color.A;
     97          primitive.Pen.Color = Color.FromArgb(alpha, selectionColor);
     98          primitive.Brush = primitive.Pen.Brush;
     99          primitive.IntoForeground();
     100        } else {
     101          int alpha = primitive.Pen.Color.A;
     102          primitive.Pen.Color = Color.FromArgb(alpha, defaultColor);
     103          primitive.Brush = primitive.Pen.Brush;
     104          primitive.IntoBackground();
     105        }
     106        ((FixedSizeCircle)primitive).UpdateEnabled = true;
     107        points.UpdateEnabled = true;
     108      }
     109    }
    109110
    110111    public void SetBubbleSizeDimension(string dimension, bool inverted) {
     
    133134
    134135    private void Repaint() {
     136      if(xDimension == null || yDimension == null) return;
    135137      lock(records) {
    136138        double maxSize = 1;
     
    144146        Group.Clear();
    145147        primitiveToRecordDictionary.Clear();
     148        recordToPrimitiveDictionary.Clear();
    146149        points = new Group(this);
    147150        Group.Add(new Axis(this, 0, 0, AxisType.Both));
    148151        UpdateViewSize(0, 0, 5);
    149152        foreach(Record r in records) {
    150           double x = r.Get(xDimension) + (random.NextDouble() * 2.0 - 1.0) * xJitterFactor;
    151           double y = r.Get(yDimension) + (random.NextDouble() * 2.0 - 1.0) * yJitterFactor;
     153          double x = r.Get(xDimension) + r.Get(Record.X_JITTER) * xJitterFactor;
     154          double y = r.Get(yDimension) + r.Get(Record.Y_JITTER) * yJitterFactor;
    152155          int size = CalculateSize(r.Get(sizeDimension), minSize, maxSize);
    153156
     
    157160            UpdateViewSize(x, y, size);
    158161            int alpha = CalculateAlpha(size);
    159             Pen pen = new Pen(Color.FromArgb(alpha, defaultColor));
     162            Pen pen = new Pen(Color.FromArgb(alpha, r.Selected ? selectionColor: defaultColor));
    160163            Brush brush = pen.Brush;
    161164            FixedSizeCircle c = new FixedSizeCircle(this, x, y, size, pen, brush);
     
    163166            points.Add(c);
    164167            primitiveToRecordDictionary[c] = r;
     168            recordToPrimitiveDictionary[r] = c;
    165169          }
    166170        }
     
    223227          primitiveToRecordDictionary.TryGetValue(p, out r);
    224228          if(r != null) r.ToggleSelected();
     229          results.FireChanged();
    225230        }
    226231      } else base.MouseClick(point, button);
     
    237242      } else base.MouseDoubleClick(point, button);
    238243    }
     244
     245    public override void MouseDrag(Point start, Point end, MouseButtons button) {
     246      if(button == MouseButtons.Left && Mode == ChartMode.Select) {
     247        PointD a = TransformPixelToWorld(start);
     248        PointD b = TransformPixelToWorld(end);
     249        double minX = Math.Min(a.X, b.X);
     250        double minY = Math.Min(a.Y, b.Y);
     251        double maxX = Math.Max(a.X, b.X);
     252        double maxY = Math.Max(a.Y, b.Y);
     253        HeuristicLab.Charting.Rectangle r = new HeuristicLab.Charting.Rectangle(this, minX, minY, maxX, maxY);
     254
     255        List<IPrimitive> primitives = new List<IPrimitive>();
     256        primitives.AddRange(points.Primitives);
     257
     258        foreach(FixedSizeCircle p in primitives) {
     259          if(r.ContainsPoint(p.Point)) {
     260            primitiveToRecordDictionary[p].ToggleSelected();
     261          }
     262        }
     263        results.FireChanged();
     264      } else {
     265        base.MouseDrag(start, end, button);
     266      }
     267    }
    239268  }
    240269}
  • trunk/sources/HeuristicLab.CEDMA.Charting/BubbleChartControl.Designer.cs

    r561 r566  
    3232    /// <param name="disposing">true if managed resources should be disposed; otherwise, false.</param>
    3333    protected override void Dispose(bool disposing) {
    34       if (disposing && (components != null)) {
     34      if(disposing && (components != null)) {
    3535        components.Dispose();
    3636      }
     
    4545    /// </summary>
    4646    private void InitializeComponent() {
    47       System.ComponentModel.ComponentResourceManager resources = new System.ComponentModel.ComponentResourceManager(typeof(BubbleChartControl));
     47      this.components = new System.ComponentModel.Container();
     48      this.pictureBox = new System.Windows.Forms.PictureBox();
     49      this.pictureBoxContextMenuStrip = new System.Windows.Forms.ContextMenuStrip(this.components);
     50      this.zoomToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem();
     51      this.selectToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem();
     52      this.toolStripMenuItem2 = new System.Windows.Forms.ToolStripSeparator();
     53      this.toolTip = new System.Windows.Forms.ToolTip(this.components);
    4854      ((System.ComponentModel.ISupportInitialize)(this.pictureBox)).BeginInit();
     55      this.pictureBoxContextMenuStrip.SuspendLayout();
    4956      this.SuspendLayout();
    5057      //
    5158      // pictureBox
    5259      //
    53       this.pictureBox.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Left)));
    54       this.pictureBox.Dock = System.Windows.Forms.DockStyle.Fill;
    55       this.pictureBox.Image = ((System.Drawing.Image)(resources.GetObject("pictureBox.Image")));
    56       this.pictureBox.Size = new System.Drawing.Size(300, 263);
     60      this.pictureBox.Anchor = ((System.Windows.Forms.AnchorStyles)((((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Bottom)
     61                  | System.Windows.Forms.AnchorStyles.Left)
     62                  | System.Windows.Forms.AnchorStyles.Right)));
     63      this.pictureBox.BackColor = System.Drawing.Color.White;
     64      this.pictureBox.BorderStyle = System.Windows.Forms.BorderStyle.FixedSingle;
     65      this.pictureBox.ContextMenuStrip = this.pictureBoxContextMenuStrip;
     66      this.pictureBox.Location = new System.Drawing.Point(0, 0);
     67      this.pictureBox.Name = "pictureBox";
     68      this.pictureBox.Size = new System.Drawing.Size(266, 236);
     69      this.pictureBox.TabIndex = 0;
     70      this.pictureBox.TabStop = false;
     71      this.pictureBox.VisibleChanged += new System.EventHandler(this.pictureBox_VisibleChanged);
     72      this.pictureBox.MouseMove += new System.Windows.Forms.MouseEventHandler(this.pictureBox_MouseMove);
     73      this.pictureBox.MouseDoubleClick += new System.Windows.Forms.MouseEventHandler(this.pictureBox_MouseDoubleClick);
     74      this.pictureBox.MouseClick += new System.Windows.Forms.MouseEventHandler(this.pictureBox_MouseClick);
     75      this.pictureBox.MouseDown += new System.Windows.Forms.MouseEventHandler(this.pictureBox_MouseDown);
     76      this.pictureBox.MouseUp += new System.Windows.Forms.MouseEventHandler(this.pictureBox_MouseUp);
     77      this.pictureBox.SizeChanged += new System.EventHandler(this.pictureBox_SizeChanged);
     78      //
     79      // pictureBoxContextMenuStrip
     80      //
     81      this.pictureBoxContextMenuStrip.Items.AddRange(new System.Windows.Forms.ToolStripItem[] {
     82            this.zoomToolStripMenuItem,
     83            this.selectToolStripMenuItem,
     84            this.toolStripMenuItem2});
     85      this.pictureBoxContextMenuStrip.Name = "pictureBoxContextMenuStrip";
     86      this.pictureBoxContextMenuStrip.Size = new System.Drawing.Size(104, 54);
     87      //
     88      // zoomToolStripMenuItem
     89      //
     90      this.zoomToolStripMenuItem.Name = "zoomToolStripMenuItem";
     91      this.zoomToolStripMenuItem.Size = new System.Drawing.Size(103, 22);
     92      this.zoomToolStripMenuItem.Text = "&Zoom";
     93      this.zoomToolStripMenuItem.Click += new System.EventHandler(this.zoomToolStripMenuItem_Click);
     94      //
     95      // selectToolStripMenuItem
     96      //
     97      this.selectToolStripMenuItem.Name = "selectToolStripMenuItem";
     98      this.selectToolStripMenuItem.Size = new System.Drawing.Size(103, 22);
     99      this.selectToolStripMenuItem.Text = "&Select";
     100      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);
    57106      //
    58107      // BubbleChartControl
     
    60109      this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 13F);
    61110      this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
     111      this.BackColor = System.Drawing.SystemColors.Control;
     112      this.Controls.Add(this.pictureBox);
    62113      this.Name = "BubbleChartControl";
    63       this.Size = new System.Drawing.Size(300, 263);
    64       this.Controls.SetChildIndex(this.pictureBox, 0);
     114      this.Size = new System.Drawing.Size(266, 236);
    65115      ((System.ComponentModel.ISupportInitialize)(this.pictureBox)).EndInit();
     116      this.pictureBoxContextMenuStrip.ResumeLayout(false);
    66117      this.ResumeLayout(false);
    67118
     
    70121    #endregion
    71122
     123    protected System.Windows.Forms.PictureBox pictureBox;
     124    protected System.Windows.Forms.ToolTip toolTip;
     125    protected System.Windows.Forms.ContextMenuStrip pictureBoxContextMenuStrip;
     126    protected System.Windows.Forms.ToolStripMenuItem zoomToolStripMenuItem;
     127    protected System.Windows.Forms.ToolStripMenuItem selectToolStripMenuItem;
     128    protected System.Windows.Forms.ToolStripSeparator toolStripMenuItem2;
     129
    72130  }
    73131}
  • trunk/sources/HeuristicLab.CEDMA.Charting/BubbleChartControl.cs

    r561 r566  
    2424using System.ComponentModel;
    2525using System.Drawing;
     26using System.Drawing.Drawing2D;
    2627using System.Data;
    2728using System.Text;
     
    3031
    3132namespace HeuristicLab.CEDMA.Charting {
    32   public partial class BubbleChartControl : ChartControl {
    33     public new BubbleChart Chart {
    34       get { return (BubbleChart)base.Chart; }
     33  public partial class BubbleChartControl : UserControl {
     34    private Bitmap bitmap;
     35    private bool renderingRequired;
     36    private Point buttonDownPoint;
     37    private Point mousePosition;
     38    private int mouseClickCount;
     39    private DateTime lastRendered = DateTime.Now;
     40    private BubbleChart myChart;
     41    public BubbleChart Chart {
     42      get { return myChart; }
    3543      set {
    36         if (Chart != null) {
    37           Chart.Update -= new EventHandler(Chart_Update);
     44        if(myChart != null) myChart.Update -= new EventHandler(myChart_Update);
     45        myChart = value;
     46        if(myChart != null) {
     47          myChart.Update += new EventHandler(myChart_Update);
     48          SetMode(Chart.Mode);
    3849        }
    39         base.Chart = value;
    40         if (Chart != null) {
    41           Chart.Update += new EventHandler(Chart_Update);
    42         }
     50        GenerateImage();
    4351      }
    4452    }
    45 
    46     void Chart_Update(object sender, EventArgs e) {
    47       // do nothing;
     53    private bool myScaleOnResize;
     54    public bool ScaleOnResize {
     55      get { return myScaleOnResize; }
     56      set { myScaleOnResize = value; }
    4857    }
    4958
    5059    public BubbleChartControl() {
    5160      InitializeComponent();
     61      myScaleOnResize = true;
     62      GenerateImage();
     63    }
     64
     65    private void myChart_Update(object sender, EventArgs e) {
     66      GenerateImage();
     67    }
     68    private void pictureBox_SizeChanged(object sender, EventArgs e) {
     69      if(ScaleOnResize) {
     70        if((pictureBox.Width > 0) && (pictureBox.Height > 0) && (Chart != null)) {
     71          PointD point = Chart.TransformPixelToWorld(new Point(pictureBox.Width, Chart.SizeInPixels.Height - pictureBox.Height));
     72          Chart.SetPosition(Chart.LowerLeft, point);
     73        }
     74      }
     75      GenerateImage();
     76    }
     77    private void pictureBox_VisibleChanged(object sender, EventArgs e) {
     78      if(pictureBox.Visible && renderingRequired) {
     79        GenerateImage();
     80      }
     81    }
     82
     83    private void pictureBox_MouseDown(object sender, MouseEventArgs e) {
     84      buttonDownPoint = e.Location;
     85      mouseClickCount = e.Clicks;
     86    }
     87    private void pictureBox_MouseUp(object sender, MouseEventArgs e) {
     88      if(e.Button == MouseButtons.Left) {
     89        Point lowerLeft = new Point(Math.Min(e.X, buttonDownPoint.X),
     90                                    Math.Max(e.Y, buttonDownPoint.Y));
     91        Point upperRight = new Point(Math.Max(e.X, buttonDownPoint.X),
     92                                     Math.Min(e.Y, buttonDownPoint.Y));
     93        if(Chart.Mode == ChartMode.Zoom) {
     94          pictureBox.Refresh();
     95          if((lowerLeft.X != upperRight.X) && (lowerLeft.Y != upperRight.Y)) {
     96            Chart.ZoomIn(lowerLeft, upperRight);
     97          }
     98        } else if(Chart.Mode == ChartMode.Select) {
     99          if((lowerLeft.X != upperRight.X) && (lowerLeft.Y != upperRight.Y)) {
     100            Chart.MouseDrag(lowerLeft, upperRight, e.Button);
     101          }
     102        }
     103      } else if(e.Button == MouseButtons.Middle) {
     104        if(Chart.Mode == ChartMode.Zoom) {
     105          if(mouseClickCount == 1) Chart.ZoomOut();
     106          else if(mouseClickCount == 2) Chart.Unzoom();
     107        }
     108      }
     109    }
     110    private void pictureBox_MouseMove(object sender, MouseEventArgs e) {
     111      toolTip.SetToolTip(pictureBox, Chart.GetToolTipText(e.Location));
     112      Cursor cursor = Chart.GetCursor(e.Location);
     113      if(cursor != null) pictureBox.Cursor = cursor;
     114      else pictureBox.Cursor = Cursors.Default;
     115
     116      if(e.Button != MouseButtons.None) {
     117        if((Chart.Mode == ChartMode.Zoom || Chart.Mode == ChartMode.Select) && (e.Button == MouseButtons.Left)) {
     118          pictureBox.Refresh();
     119          Graphics graphics = pictureBox.CreateGraphics();
     120          Pen pen = new Pen(Color.Gray);
     121          pen.DashStyle = DashStyle.Dash;
     122          graphics.DrawRectangle(pen,
     123                                 Math.Min(e.X, buttonDownPoint.X),
     124                                 Math.Min(e.Y, buttonDownPoint.Y),
     125                                 Math.Abs(e.X - buttonDownPoint.X),
     126                                 Math.Abs(e.Y - buttonDownPoint.Y));
     127          pen.Dispose();
     128          graphics.Dispose();
     129        }
     130      }
     131      mousePosition = e.Location;
     132    }
     133
     134    private void zoomToolStripMenuItem_Click(object sender, EventArgs e) {
     135      SetMode(ChartMode.Zoom);
     136    }
     137    private void selectToolStripMenuItem_Click(object sender, EventArgs e) {
     138      SetMode(ChartMode.Select);
     139    }
     140
     141    private void GenerateImage() {
     142      if(!Visible) {
     143        renderingRequired = true;
     144      } else {
     145        if((pictureBox.Width == 0) || (pictureBox.Height == 0)) {
     146          bitmap = null;
     147        } else {
     148          bitmap = new Bitmap(pictureBox.Width, pictureBox.Height);
     149          if(Chart != null) {
     150            Graphics graphics = Graphics.FromImage(bitmap);
     151            graphics.SetClip(new System.Drawing.Rectangle(0, 0, pictureBox.Width, pictureBox.Height));
     152            Chart.Render(graphics, pictureBox.Width, pictureBox.Height);
     153            graphics.Dispose();
     154          }
     155        }
     156        pictureBox.Image = bitmap;
     157        renderingRequired = false;
     158      }
     159    }
     160
     161    private void SetMode(ChartMode mode) {
     162      zoomToolStripMenuItem.Checked = false;
     163      selectToolStripMenuItem.Checked = false;
     164      if(mode == ChartMode.Zoom) zoomToolStripMenuItem.Checked = true;
     165      else if(mode == ChartMode.Select) selectToolStripMenuItem.Checked = true;
     166      Chart.Mode = mode;
     167    }
     168
     169    private void pictureBox_MouseClick(object sender, MouseEventArgs e) {
     170      Chart.MouseClick(e.Location, e.Button);
     171    }
     172
     173    private void pictureBox_MouseDoubleClick(object sender, MouseEventArgs e) {
     174      Chart.MouseDoubleClick(e.Location, e.Button);
    52175    }
    53176  }
  • trunk/sources/HeuristicLab.CEDMA.Charting/BubbleChartControl.resx

    r561 r566  
    118118    <value>System.Resources.ResXResourceWriter, System.Windows.Forms, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
    119119  </resheader>
    120   <assembly alias="System.Drawing" name="System.Drawing, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a" />
    121   <data name="pictureBox.Image" type="System.Drawing.Bitmap, System.Drawing" mimetype="application/x-microsoft.net.object.bytearray.base64">
    122     <value>
    123         iVBORw0KGgoAAAANSUhEUgAAASwAAAEHCAYAAAAUFnuAAAAAAXNSR0IArs4c6QAAAARnQU1BAACxjwv8
    124         YQUAAAAgY0hSTQAAeiYAAICEAAD6AAAAgOgAAHUwAADqYAAAOpgAABdwnLpRPAAABXlJREFUeF7t0DEB
    125         AAAAwqD1T20JT4hAYcCAAQMGDBgwYMCAAQMGDBgwYMCAAQMGDBgwYMCAAQMGDBgwYMCAAQMGDBgwYMCA
    126         AQMGDBgwYMCAAQMGDBgwYMCAAQMGDBgwYMCAAQMGDBgwYMCAAQMGDBgwYMCAAQMGDBgwYMCAAQMGDBgw
    127         YMCAAQMGDBgwYMCAAQMGDBgwYMCAAQMGDBgwYMCAAQMGDBgwYMCAAQMGDBgwYMCAAQMGDBgwYMCAAQMG
    128         DBgwYMCAAQMGDBgwYMCAAQMGDBgwYMCAAQMGDBgwYMCAAQMGDBgwYMCAAQMGDBgwYMCAAQMGDBgwYMCA
    129         AQMGDBgwYMCAAQMGDBgwYMCAAQMGDBgwYMCAAQMGDBgwYMCAAQMGDBgwYMCAAQMGDBgwYMCAAQMGDBgw
    130         YMCAAQMGDBgwYMCAAQMGDBgwYMCAAQMGDBgwYMCAAQMGDBgwYMCAAQMGDBgwYMCAAQMGDBgwYMCAAQMG
    131         DBgwYMCAAQMGDBgwYMCAAQMGDBgwYMCAAQMGDBgwYMCAAQMGDBgwYMCAAQMGDBgwYMCAAQMGDBgwYMCA
    132         AQMGDBgwYMCAAQMGDBgwYMCAAQMGDBgwYMCAAQMGDBgwYMCAAQMGDBgwYMCAAQMGDBgwYMCAAQMGDBgw
    133         YMCAAQMGDBgwYMCAAQMGDBgwYMCAAQMGDBgwYMCAAQMGDBgwYMCAAQMGDBgwYMCAAQMGDBgwYMCAAQMG
    134         DBgwYMCAAQMGDBgwYMCAAQMGDBgwYMCAAQMGDBgwYMCAAQMGDBgwYMCAAQMGDBgwYMCAAQMGDBgwYMCA
    135         AQMGDBgwYMCAAQMGDBgwYMCAAQMGDBgwYMCAAQMGDBgwYMCAAQMGDBgwYMCAAQMGDBgwYMCAAQMGDBgw
    136         YMCAAQMGDBgwYMCAAQMGDBgwYMCAAQMGDBgwYMCAAQMGDBgwYMCAAQMGDBgwYMCAAQMGDBgwYMCAAQMG
    137         DBgwYMCAAQMGDBgwYMCAAQMGDBgwYMCAAQMGDBgwYMCAAQMGDBgwYMCAAQMGDBgwYMCAAQMGDBgwYMCA
    138         AQMGDBgwYMCAAQMGDBgwYMCAAQMGDBgwYMCAAQMGDBgwYMCAAQMGDBgwYMCAAQMGDBgwYMCAAQMGDBgw
    139         YMCAAQMGDBgwYMCAAQMGDBgwYMCAAQMGDBgwYMCAAQMGDBgwYMCAAQMGDBgwYMCAAQMGDBgwYMCAAQMG
    140         DBgwYMCAAQMGDBgwYMCAAQMGDBgwYMCAAQMGDBgwYMCAAQMGDBgwYMCAAQMGDBgwYMCAAQMGDBgwYMCA
    141         AQMGDBgwYMCAAQMGDBgwYMCAAQMGDBgwYMCAAQMGDBgwYMCAAQMGDBgwYMCAAQMGDBgwYMCAAQMGDBgw
    142         YMCAAQMGDBgwYMCAAQMGDBgwYMCAAQMGDBgwYMCAAQMGDBgwYMCAAQMGDBgwYMCAAQMGDBgwYMCAAQMG
    143         DBgwYMCAAQMGDBgwYMCAAQMGDBgwYMCAAQMGDBgwYMCAAQMGDBgwYMCAAQMGDBgwYMCAAQMGDBgwYMCA
    144         AQMGDBgwYMCAAQMGDBgwYMCAAQMGDBgwYMCAAQMGDBgwYMCAAQMGDBgwYMCAAQMGDBgwYMCAAQMGDBgw
    145         YMCAAQMGDBgwYMCAAQMGDBgwYMCAAQMGDBgwYMCAAQMGDBgwYMCAAQMGDBgwYMCAAQMGDBgwYMCAAQMG
    146         DBgwYMCAAQMGDBgwYMCAAQMGDBgwYMCAAQMGDBgwYMCAAQMGDBgwYMCAAQMGDBgwYMCAAQMGDBgwYMCA
    147         AQMGDBgwYMCAAQMGDBgwYMCAAQMGDBgwYMCAAQMGDBgwYMCAAQMGDBgwYMCAAQMGDBgwYMCAAQMGDBgw
    148         YMCAAQMGDBi4DAzSEwABKB1lLgAAAABJRU5ErkJggg==
    149 </value>
    150   </data>
     120  <metadata name="pictureBoxContextMenuStrip.TrayLocation" type="System.Drawing.Point, System.Drawing, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a">
     121    <value>17, 17</value>
     122  </metadata>
    151123  <metadata name="toolTip.TrayLocation" type="System.Drawing.Point, System.Drawing, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a">
    152124    <value>210, 17</value>
  • trunk/sources/HeuristicLab.CEDMA.Charting/HeuristicLab.CEDMA.Charting.csproj

    r564 r566  
    7373      <DependentUpon>BubbleChartControl.cs</DependentUpon>
    7474    </Compile>
     75    <Compile Include="Record.cs" />
    7576    <Compile Include="HeuristicLabCedmaChartingPlugin.cs" />
    7677    <Compile Include="Histogram.cs" />
  • trunk/sources/HeuristicLab.CEDMA.Charting/ResultList.cs

    r562 r566  
    3333
    3434namespace HeuristicLab.CEDMA.Charting {
    35   public class Record {
    36     private Dictionary<string, double> values = new Dictionary<string, double>();
    37     public Dictionary<string,double> Values {
    38       get {
    39         return values;
    40       }
    41     }
    42 
    43     private bool selected = false;
    44     public bool Selected { get { return selected; } }
    45 
    46     private string uri;
    47     public string Uri { get { return uri; } }
    48     public Record(string uri) {
    49       this.uri = uri;
    50     }
    51 
    52     public void Set(string name, double value) {
    53       Values.Add(name, value);
    54     }
    55 
    56     public double Get(string name) {
    57       if(name==null || !Values.ContainsKey(name)) return double.NaN;
    58       return Values[name];
    59     }
    60 
    61     public void ToggleSelected() {
    62       selected = !selected;
    63       if(OnSelectionChanged != null) OnSelectionChanged(this, new EventArgs());
    64     }
    65 
    66     public event EventHandler OnSelectionChanged;
    67   }
    6835
    6936  public class RecordAddedEventArgs : EventArgs {
     
    7845  public class ResultList : ItemBase {
    7946    private const string cedmaNS = "http://www.heuristiclab.com/cedma/";
    80 
    81     private const string MAPE_TRAINING = "MAPE (training)";
    82     private const string MAPE_VALIDATION = "MAPE (validation)";
    83     private const string MAPE_TEST = "MAPE (test)";
    84     private const string R2_TRAINING = "R2 (training)";
    85     private const string R2_VALIDATION = "R2 (validation)";
    86     private const string R2_TEST = "R2 (test)";
    87     private const string TARGET_VARIABLE = "Target variable";
    88     private const string TREE_SIZE = "Tree size";
    89     private const string TREE_HEIGHT = "Tree height";
    90 
    9147    private readonly Entity targetVariablePredicate = new Entity(cedmaNS + "TargetVariable");
    9248    private readonly Entity trainingMAPEPredicate = new Entity(cedmaNS + "MeanAbsolutePercentageErrorTraining");
     
    11167    }
    11268
    113     private List<string> variableNames = new List<string>() { TARGET_VARIABLE, TREE_SIZE, TREE_HEIGHT,
    114     MAPE_TRAINING, MAPE_VALIDATION, MAPE_TEST,
    115     R2_TRAINING, R2_VALIDATION, R2_TEST};
     69    private List<string> variableNames = new List<string>() { Record.TARGET_VARIABLE, Record.TREE_SIZE, Record.TREE_HEIGHT,
     70    Record.MAPE_TRAINING, Record.MAPE_VALIDATION, Record.MAPE_TEST,
     71    Record.R2_TRAINING, Record.R2_VALIDATION, Record.R2_TEST};
    11672    public string[] VariableNames {
    11773      get {
     
    12076    }
    12177
     78    private Dictionary<Entity, string> predicateToVariableName;
     79
    12280    public event EventHandler<RecordAddedEventArgs> OnRecordAdded;
    12381
    12482    private List<Record> records;
    125 
     83    public List<Record> Records {
     84      get {
     85        List<Record> result = new List<Record>();
     86        lock(records) {
     87          result.AddRange(records);
     88        }
     89        return result;
     90      }
     91    }
    12692    private void ReloadList() {
    12793      var results = store.Select(new Statement(anyEntity, new Entity(cedmaNS + "instanceOf"), new Literal("class:GpFunctionTree")))
     
    13399          new Resource[] { anyEntity })));
    134100
     101      Random random = new Random();
    135102      foreach(Statement[] ss in results) {
    136103        if(ss.Length > 0) {
    137104          Record r = new Record(ss[0].Subject.Uri);
     105          r.Set(Record.X_JITTER, random.NextDouble() * 2.0 - 1.0);
     106          r.Set(Record.Y_JITTER, random.NextDouble() * 2.0 - 1.0);
    138107          foreach(Statement s in ss) {
    139             if(s.Predicate.Equals(targetVariablePredicate)) {
    140               r.Set(TARGET_VARIABLE, (double)(int)((Literal)s.Property).Value);
    141             } else if(s.Predicate.Equals(treeSizePredicate)) {
    142               r.Set(TREE_SIZE, (double)(int)((Literal)s.Property).Value);
    143             } else if(s.Predicate.Equals(treeHeightPredicate)) {
    144               r.Set(TREE_HEIGHT, (double)(int)((Literal)s.Property).Value);
    145             } else if(s.Predicate.Equals(trainingMAPEPredicate)) {
    146               r.Set(MAPE_TRAINING, (double)((Literal)s.Property).Value);
    147             } else if(s.Predicate.Equals(validationMAPEPredicate)) {
    148               r.Set(MAPE_VALIDATION, (double)((Literal)s.Property).Value);
    149             } else if(s.Predicate.Equals(testMAPEPredicate)) {
    150               r.Set(MAPE_TEST, (double)((Literal)s.Property).Value);
    151             } else if(s.Predicate.Equals(trainingR2Predicate)) {
    152               r.Set(R2_TRAINING, (double)((Literal)s.Property).Value);
    153             } else if(s.Predicate.Equals(validationR2Predicate)) {
    154               r.Set(R2_VALIDATION, (double)((Literal)s.Property).Value);
    155             } else if(s.Predicate.Equals(testR2Predicate)) {
    156               r.Set(R2_TEST, (double)((Literal)s.Property).Value);
     108            string varName;
     109            predicateToVariableName.TryGetValue(s.Predicate, out varName);
     110            if(varName != null) {
     111              if(varName == Record.TREE_HEIGHT || varName == Record.TREE_SIZE || varName == Record.TARGET_VARIABLE) {
     112                r.Set(varName, (double)(int)((Literal)s.Property).Value);
     113              } else {
     114                r.Set(varName, (double)((Literal)s.Property).Value);
     115              }
    157116            }
    158117          }
    159           records.Add(r);
     118          lock(records) {
     119            records.Add(r);
     120          }
    160121          FireRecordAdded(r);
    161122        }
    162123      }
     124      FireChanged();
    163125    }
    164126
     
    170132      : base() {
    171133      records = new List<Record>();
     134      predicateToVariableName = new Dictionary<Entity, string>();
     135      predicateToVariableName[targetVariablePredicate] = Record.TARGET_VARIABLE;
     136      predicateToVariableName[treeSizePredicate] = Record.TREE_SIZE;
     137      predicateToVariableName[treeHeightPredicate] = Record.TREE_HEIGHT;
     138      predicateToVariableName[trainingMAPEPredicate] = Record.MAPE_TRAINING;
     139      predicateToVariableName[validationMAPEPredicate] = Record.MAPE_VALIDATION;
     140      predicateToVariableName[testMAPEPredicate] = Record.MAPE_TEST;
     141      predicateToVariableName[trainingR2Predicate] = Record.R2_TRAINING;
     142      predicateToVariableName[validationR2Predicate] = Record.R2_VALIDATION;
     143      predicateToVariableName[testR2Predicate] = Record.R2_TEST;
    172144    }
    173145
  • trunk/sources/HeuristicLab.CEDMA.Charting/ResultListView.cs

    r562 r566  
    2222    public ResultListView(ResultList results) {
    2323      this.results = results;
    24       results.Changed += new EventHandler(results_Changed);
    2524      InitializeComponent();
    2625      xAxisComboBox.Items.AddRange(results.VariableNames);
     
    3029      sizeComboBox.Items.AddRange(results.VariableNames);
    3130      sizeComboBox.SelectedItem = sizeComboBox.Items[0];
    32       InitChart();
    33     }
    34 
    35     private DateTime lastUpdate = DateTime.Now;
    36     void results_Changed(object sender, EventArgs e) {
    37       if(DateTime.Now.Subtract(lastUpdate).TotalSeconds < 3) return;
    38       lastUpdate = DateTime.Now;
    3931      InitChart();
    4032    }
Note: See TracChangeset for help on using the changeset viewer.