Free cookie consent management tool by TermsFeed Policy Generator

Ignore:
Timestamp:
06/16/15 16:30:05 (9 years ago)
Author:
pfleck
Message:

#2379 Added level/depth based selection for the datasource.
Updated sample.

Location:
branches/BubbleChart/HeuristicLab.Optimization.BubbleChart/3.3
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • branches/BubbleChart/HeuristicLab.Optimization.BubbleChart/3.3/BubbleChartView.Designer.cs

    r12388 r12459  
    5858      this.sizeComboBox = new System.Windows.Forms.ComboBox();
    5959      this.sizeLabel = new System.Windows.Forms.Label();
     60      this.sourceLabel = new System.Windows.Forms.Label();
     61      this.levelNumericUpDown = new System.Windows.Forms.NumericUpDown();
     62      this.includeChildrenCheckBox = new System.Windows.Forms.CheckBox();
    6063      ((System.ComponentModel.ISupportInitialize)(this.chart)).BeginInit();
    6164      this.childrenGroupBox.SuspendLayout();
     
    6467      this.splitContainer.Panel2.SuspendLayout();
    6568      this.splitContainer.SuspendLayout();
     69      ((System.ComponentModel.ISupportInitialize)(this.levelNumericUpDown)).BeginInit();
    6670      this.SuspendLayout();
    6771      //
     
    6973      //
    7074      this.yLabel.AutoSize = true;
    71       this.yLabel.Location = new System.Drawing.Point(3, 6);
     75      this.yLabel.Location = new System.Drawing.Point(305, 6);
    7276      this.yLabel.Name = "yLabel";
    7377      this.yLabel.Size = new System.Drawing.Size(15, 13);
     
    7983      this.xLabel.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Right)));
    8084      this.xLabel.AutoSize = true;
    81       this.xLabel.Location = new System.Drawing.Point(461, 586);
     85      this.xLabel.Location = new System.Drawing.Point(725, 713);
    8286      this.xLabel.Name = "xLabel";
    8387      this.xLabel.Size = new System.Drawing.Size(15, 13);
     
    101105      series2.YValuesPerPoint = 2;
    102106      this.chart.Series.Add(series2);
    103       this.chart.Size = new System.Drawing.Size(663, 541);
     107      this.chart.Size = new System.Drawing.Size(880, 668);
    104108      this.chart.TabIndex = 7;
     109      this.chart.AxisViewChanged += new System.EventHandler<System.Windows.Forms.DataVisualization.Charting.ViewEventArgs>(this.chart_AxisViewChanged);
    105110      //
    106111      // yAxisComboBox
     
    108113      this.yAxisComboBox.DropDownStyle = System.Windows.Forms.ComboBoxStyle.DropDownList;
    109114      this.yAxisComboBox.FormattingEnabled = true;
    110       this.yAxisComboBox.Location = new System.Drawing.Point(24, 3);
     115      this.yAxisComboBox.Location = new System.Drawing.Point(326, 3);
    111116      this.yAxisComboBox.Name = "yAxisComboBox";
    112117      this.yAxisComboBox.Size = new System.Drawing.Size(340, 21);
     
    119124      this.xAxisComboBox.DropDownStyle = System.Windows.Forms.ComboBoxStyle.DropDownList;
    120125      this.xAxisComboBox.FormattingEnabled = true;
    121       this.xAxisComboBox.Location = new System.Drawing.Point(482, 583);
     126      this.xAxisComboBox.Location = new System.Drawing.Point(746, 710);
    122127      this.xAxisComboBox.Name = "xAxisComboBox";
    123128      this.xAxisComboBox.Size = new System.Drawing.Size(340, 21);
     
    133138      this.treeView.Location = new System.Drawing.Point(6, 19);
    134139      this.treeView.Name = "treeView";
    135       this.treeView.Size = new System.Drawing.Size(128, 516);
     140      this.treeView.Size = new System.Drawing.Size(175, 643);
    136141      this.treeView.TabIndex = 10;
    137142      this.treeView.AfterCheck += new System.Windows.Forms.TreeViewEventHandler(this.treeView_AfterCheck);
     143      this.treeView.AfterSelect += new System.Windows.Forms.TreeViewEventHandler(this.treeView_AfterSelect);
    138144      //
    139145      // childrenGroupBox
     
    145151      this.childrenGroupBox.Location = new System.Drawing.Point(3, 3);
    146152      this.childrenGroupBox.Name = "childrenGroupBox";
    147       this.childrenGroupBox.Size = new System.Drawing.Size(140, 541);
     153      this.childrenGroupBox.Size = new System.Drawing.Size(187, 668);
    148154      this.childrenGroupBox.TabIndex = 11;
    149155      this.childrenGroupBox.TabStop = false;
     
    165171      //
    166172      this.splitContainer.Panel2.Controls.Add(this.chart);
    167       this.splitContainer.Size = new System.Drawing.Size(819, 547);
    168       this.splitContainer.SplitterDistance = 146;
     173      this.splitContainer.Size = new System.Drawing.Size(1083, 674);
     174      this.splitContainer.SplitterDistance = 193;
    169175      this.splitContainer.TabIndex = 12;
    170176      //
     
    174180      this.sizeComboBox.DropDownStyle = System.Windows.Forms.ComboBoxStyle.DropDownList;
    175181      this.sizeComboBox.FormattingEnabled = true;
    176       this.sizeComboBox.Location = new System.Drawing.Point(542, 3);
     182      this.sizeComboBox.Location = new System.Drawing.Point(806, 3);
    177183      this.sizeComboBox.Name = "sizeComboBox";
    178184      this.sizeComboBox.Size = new System.Drawing.Size(280, 21);
     
    184190      this.sizeLabel.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Right)));
    185191      this.sizeLabel.AutoSize = true;
    186       this.sizeLabel.Location = new System.Drawing.Point(470, 6);
     192      this.sizeLabel.Location = new System.Drawing.Point(734, 6);
    187193      this.sizeLabel.Name = "sizeLabel";
    188194      this.sizeLabel.Size = new System.Drawing.Size(66, 13);
     
    190196      this.sizeLabel.Text = "Bubble Size:";
    191197      //
     198      // sourceLabel
     199      //
     200      this.sourceLabel.AutoSize = true;
     201      this.sourceLabel.Location = new System.Drawing.Point(3, 6);
     202      this.sourceLabel.Name = "sourceLabel";
     203      this.sourceLabel.Size = new System.Drawing.Size(36, 13);
     204      this.sourceLabel.TabIndex = 15;
     205      this.sourceLabel.Text = "Level:";
     206      //
     207      // levelNumericUpDown
     208      //
     209      this.levelNumericUpDown.Location = new System.Drawing.Point(45, 4);
     210      this.levelNumericUpDown.Name = "levelNumericUpDown";
     211      this.levelNumericUpDown.Size = new System.Drawing.Size(43, 20);
     212      this.levelNumericUpDown.TabIndex = 16;
     213      this.levelNumericUpDown.ValueChanged += new System.EventHandler(this.levelNumericUpDown_ValueChanged);
     214      //
     215      // includeChildrenCheckBox
     216      //
     217      this.includeChildrenCheckBox.AutoSize = true;
     218      this.includeChildrenCheckBox.Location = new System.Drawing.Point(94, 4);
     219      this.includeChildrenCheckBox.Name = "includeChildrenCheckBox";
     220      this.includeChildrenCheckBox.RightToLeft = System.Windows.Forms.RightToLeft.Yes;
     221      this.includeChildrenCheckBox.Size = new System.Drawing.Size(102, 17);
     222      this.includeChildrenCheckBox.TabIndex = 17;
     223      this.includeChildrenCheckBox.Text = "Include Children";
     224      this.includeChildrenCheckBox.UseVisualStyleBackColor = true;
     225      this.includeChildrenCheckBox.CheckedChanged += new System.EventHandler(this.includeChildrenCheckBox_CheckedChanged);
     226      //
    192227      // BubbleChartView
    193228      //
     
    196231      this.BackColor = System.Drawing.SystemColors.Window;
    197232      this.BorderStyle = System.Windows.Forms.BorderStyle.FixedSingle;
     233      this.Controls.Add(this.includeChildrenCheckBox);
     234      this.Controls.Add(this.levelNumericUpDown);
     235      this.Controls.Add(this.sourceLabel);
    198236      this.Controls.Add(this.sizeLabel);
    199237      this.Controls.Add(this.sizeComboBox);
     
    204242      this.Controls.Add(this.yAxisComboBox);
    205243      this.Name = "BubbleChartView";
    206       this.Size = new System.Drawing.Size(825, 607);
     244      this.Size = new System.Drawing.Size(1089, 734);
    207245      ((System.ComponentModel.ISupportInitialize)(this.chart)).EndInit();
    208246      this.childrenGroupBox.ResumeLayout(false);
     
    211249      ((System.ComponentModel.ISupportInitialize)(this.splitContainer)).EndInit();
    212250      this.splitContainer.ResumeLayout(false);
     251      ((System.ComponentModel.ISupportInitialize)(this.levelNumericUpDown)).EndInit();
    213252      this.ResumeLayout(false);
    214253      this.PerformLayout();
     
    228267    private System.Windows.Forms.ComboBox sizeComboBox;
    229268    private System.Windows.Forms.Label sizeLabel;
     269    private System.Windows.Forms.Label sourceLabel;
     270    private System.Windows.Forms.NumericUpDown levelNumericUpDown;
     271    private System.Windows.Forms.CheckBox includeChildrenCheckBox;
    230272  }
    231273}
  • branches/BubbleChart/HeuristicLab.Optimization.BubbleChart/3.3/BubbleChartView.cs

    r12389 r12459  
    2222using System;
    2323using System.Collections.Generic;
     24using System.Drawing;
    2425using System.Linq;
    2526using System.Windows.Forms;
     
    3031using HeuristicLab.Data;
    3132using HeuristicLab.MainForm;
     33using HeuristicLab.MainForm.WindowsForms;
    3234
    3335namespace HeuristicLab.Optimization.BubbleChart {
     
    5961
    6062      UpdateTreeView();
     63      UpdateLevelControl();
     64
    6165      UpdateComboBoxes();
    6266      UpdateDataPoints();
    6367      //UpdateCaption();
    6468    }
     69    protected override void SetEnabledStateOfControls() {
     70      base.SetEnabledStateOfControls();
     71      levelNumericUpDown.Enabled = Content != null;
     72      // ToDo
     73    }
    6574
    6675    #region Tree Queries
     76
     77    private IEnumerable<RecursiveDataItem> GetAvailableItems() {
     78      return IterateCheckedNodes()
     79        .Select(n => (RecursiveDataItem)n.Tag);
     80    }
    6781    private IEnumerable<string> GetAvailableKeys() {
    68       var collector = new List<string>();
    69       foreach (TreeNode node in treeView.Nodes)
    70         GetAvailableKeys(node, collector);
    71       return collector.Distinct();
    72     }
    73     private void GetAvailableKeys(TreeNode node, List<string> collector) {
    74       var item = (RecursiveDataItem)node.Tag;
    75       if (node.Checked)
    76         collector.AddRange(item.Data.Keys);
    77       foreach (TreeNode child in node.Nodes)
    78         GetAvailableKeys(child, collector);
    79     }
    80 
    81     private IEnumerable<RecursiveDataItem> GetAvailableItems() {
    82       var collector = new List<RecursiveDataItem>();
    83       foreach (TreeNode child in treeView.Nodes)
    84         GetAvailableItems(child, collector);
    85       return collector;
    86     }
    87 
    88     private void GetAvailableItems(TreeNode node, List<RecursiveDataItem> collector) {
    89       var item = (RecursiveDataItem)node.Tag;
    90       if (node.Checked)
    91         collector.Add(item);
    92       foreach (TreeNode child in node.Nodes)
    93         GetAvailableItems(child, collector);
     82      return GetAvailableItems()
     83        .SelectMany(n => n.Data.Keys)
     84        .Distinct();
    9485    }
    9586    #endregion
    9687
    9788    #region Update Controls
     89    private void UpdateLevelControl() {
     90      if (Content == null) return;
     91      if (treeView.Nodes.Count > 0)
     92        levelNumericUpDown.Maximum = IterateAllNodes().Max(t => t.Level);
     93      else
     94        levelNumericUpDown.Maximum = 0;
     95    }
     96
    9897    private void UpdateTreeView() {
    9998      treeView.Nodes.Clear();
    100 
    101       if (Content != null) {
     99      if (Content != null)
    102100        treeView.Nodes.Add(CreateTreeNode(Content));
    103       }
    104 
    105101      treeView.ExpandAll();
    106102      splitContainer.Panel1Collapsed = treeView.Nodes.Count == 0;
     103      if (treeView.Nodes.Count > 0)
     104        treeView.SelectedNode = treeView.Nodes[0];
    107105    }
    108106    private TreeNode CreateTreeNode(RecursiveDataItem item) {
     
    114112        node.Nodes.Add(CreateTreeNode(child));
    115113      return node;
     114    }
     115
     116    private void UpdateTreeViewCheckBoxes() {
     117      int level = (int)levelNumericUpDown.Value;
     118      bool includeChildren = includeChildrenCheckBox.Checked;
     119      //treeView.BeginUpdate();
     120      foreach (var node in IterateAllNodes())
     121        node.Checked = includeChildren ? node.Level >= level : node.Level == level;
     122      //treeView.EndUpdate();
    116123    }
    117124
     
    240247      switch (sizeDimension) {
    241248        case SizeDimension.Constant:
    242           value = 2;
     249          value = 5;
    243250          break;
    244251        default:
     
    258265      }
    259266    }
     267
     268    private void UpdateAxisLabels() {
     269      return;
     270      Axis xAxis = chart.ChartAreas[0].AxisX;
     271      Axis yAxis = chart.ChartAreas[0].AxisY;
     272      //mkommend: combobox.SelectedIndex could not be used as this changes during hovering over possible values
     273      var xSAxisSelected = xAxisValue == null ? null : (string)xAxisComboBox.SelectedItem;
     274      var ySAxisSelected = yAxisValue == null ? null : (string)yAxisComboBox.SelectedItem;
     275      SetCustomAxisLabels(xAxis, xSAxisSelected);
     276      SetCustomAxisLabels(yAxis, ySAxisSelected);
     277      if (xAxisValue != null)
     278        xAxis.Title = xAxisValue;
     279      if (yAxisValue != null)
     280        yAxis.Title = yAxisValue;
     281    }
     282    private void chart_AxisViewChanged(object sender, System.Windows.Forms.DataVisualization.Charting.ViewEventArgs e) {
     283      this.UpdateAxisLabels();
     284    }
     285    private void SetCustomAxisLabels(Axis axis, string key) {
     286      axis.CustomLabels.Clear();
     287      if (categoricalMapping.ContainsKey(key)) {
     288        foreach (var pair in categoricalMapping[key]) {
     289          string labelText = pair.Key.ToString();
     290          CustomLabel label = new CustomLabel();
     291          label.ToolTip = labelText;
     292          if (labelText.Length > 25)
     293            labelText = labelText.Substring(0, 25) + " ... ";
     294          label.Text = labelText;
     295          label.GridTicks = GridTickTypes.TickMark;
     296          label.FromPosition = pair.Value - 0.5;
     297          label.ToPosition = pair.Value + 0.5;
     298          axis.CustomLabels.Add(label);
     299        }
     300      } else if (key != null && Content.Data[key] is TimeSpanValue) {
     301        chart.ChartAreas[0].RecalculateAxesScale();
     302        for (double i = axis.Minimum; i <= axis.Maximum; i += axis.LabelStyle.Interval) {
     303          TimeSpan time = TimeSpan.FromSeconds(i);
     304          string x = string.Format("{0:00}:{1:00}:{2:00}", time.Hours, time.Minutes, time.Seconds);
     305          axis.CustomLabels.Add(i - axis.LabelStyle.Interval / 2, i + axis.LabelStyle.Interval / 2, x);
     306        }
     307      }
     308    }
     309
     310    private void UpdateNodeColors() {
     311      var selectedDepth = treeView.SelectedNode != null ? treeView.SelectedNode.Level : (int?)null;
     312      var selectedIndex = treeView.SelectedNode != null ? treeView.SelectedNode.Index : (int?)null;
     313      foreach (TreeNode node in treeView.Nodes) {
     314        UpdateNodeColor(node, selectedDepth, selectedIndex);
     315      }
     316    }
     317    private void UpdateNodeColor(TreeNode node, int? depth, int? index) {
     318      if (depth.HasValue && index.HasValue && node.Level == depth /*&& node.Index == index*/)
     319        node.BackColor = Color.Yellow;
     320      else
     321        node.BackColor = Color.White;
     322      foreach (TreeNode child in node.Nodes)
     323        UpdateNodeColor(child, depth, index);
     324    }
    260325    #endregion
    261326
     
    263328    private void treeView_AfterCheck(object sender, TreeViewEventArgs e) {
    264329      UpdateComboBoxes();
    265       UpdateDataPoints();
     330      //UpdateDataPoints();
     331    }
     332    private void treeView_AfterSelect(object sender, TreeViewEventArgs e) {
     333      //UpdateNodeColors();
     334      //UpdateComboBoxes();
     335      //UpdateDataPoints();
    266336    }
    267337
     
    274344
    275345      UpdateDataPoints();
    276       //UpdateAxisLabels();
     346      UpdateAxisLabels();
     347    }
     348
     349    private void includeChildrenCheckBox_CheckedChanged(object sender, EventArgs e) {
     350      UpdateTreeViewCheckBoxes();
     351      UpdateComboBoxes();
     352    }
     353
     354    private void levelNumericUpDown_ValueChanged(object sender, EventArgs e) {
     355      UpdateTreeViewCheckBoxes();
     356      UpdateComboBoxes();
     357    }
     358    #endregion
     359
     360    #region Helpers
     361
     362    private IEnumerable<TreeNode> IterateAllNodes() {
     363      return Collect(treeView.Nodes);
     364    }
     365    private IEnumerable<TreeNode> IterateCheckedNodes() {
     366      return IterateAllNodes().Where(t => t.Checked);
     367    }
     368    private IEnumerable<TreeNode> Collect(TreeNodeCollection nodes) {
     369      foreach (TreeNode node in nodes) {
     370        yield return node;
     371        foreach (var child in Collect(node.Nodes))
     372          yield return child;
     373      }
    277374    }
    278375    #endregion
Note: See TracChangeset for help on using the changeset viewer.