Free cookie consent management tool by TermsFeed Policy Generator

Changeset 13820 for branches


Ignore:
Timestamp:
05/02/16 14:58:57 (9 years ago)
Author:
bburlacu
Message:

#2597: Added flags for controlling the display of legend, axis labels, or vertical cursor on the chart.

Location:
branches/HeuristicLab.RegressionSolutionGradientView/HeuristicLab.Problems.DataAnalysis.Views/3.4
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • branches/HeuristicLab.RegressionSolutionGradientView/HeuristicLab.Problems.DataAnalysis.Views/3.4/GradientChart.cs

    r13818 r13820  
    3232namespace HeuristicLab.Problems.DataAnalysis.Views {
    3333  public partial class GradientChart : EnhancedChart {
    34     private ModifiableDataset internalDataset;
     34    private ModifiableDataset dataset;
    3535
    3636    public bool ShowLegend { get; set; }
     37    public bool ShowXAxisLabel { get; set; }
     38    public bool ShowYAxisLabel { get; set; }
     39    public bool ShowCursor { get; set; }
    3740
    3841    private bool useMedianValues;
     
    98101          throw new ArgumentException("The problem data provided does not contain all the variables required by the solutions.");
    99102        problemData = value;
    100         UpdateInternalDataset();
     103        UpdateDataset();
    101104        UpdateChart();
    102105      }
     
    178181      this.points = points;
    179182
    180       UpdateInternalDataset();
     183      UpdateDataset();
    181184      UpdateChart();
    182185    }
     
    188191      this.problemData = pd;
    189192      this.variable = variable;
    190       this.internalDataset = dataset;
     193      this.dataset = dataset;
    191194      this.min = min;
    192195      this.max = max;
     
    196199    public void UpdateChart() {
    197200      // throw exceptions?
    198       if (internalDataset == null || solutionList == null || !solutionList.Any())
     201      if (dataset == null || solutionList == null || !solutionList.Any())
    199202        return;
    200203      if (min.IsAlmost(max) || min > max || points == 0)
    201204        return;
    202205      Series.Clear();
    203       var vla = VerticalLineAnnotation;
    204       vla.Visible = true;
    205206      Annotations.Clear();
    206       Annotations.Add(vla);
     207
     208      var defaultValue = dataset.GetDoubleValue(variable, 0);
     209      if (ShowCursor) {
     210        var vla = VerticalLineAnnotation;
     211        vla.Visible = true;
     212        Annotations.Add(vla);
     213        vla.X = defaultValue;
     214      }
     215
    207216      double axisMin, axisMax, axisInterval;
    208217      // calculate X-axis interval
     
    218227        series.Name = Target + " " + i;
    219228        Series.Add(series);
    220         var p = series.Points.Last();
    221         vla.X = p.XValue;
    222229      }
    223230      // calculate Y-axis interval
     
    232239      axis.Maximum = axisMax;
    233240      axis.Interval = axisInterval;
    234       ChartAreas[0].AxisX.Title = Variable + " : " + vla.X.ToString("N3", CultureInfo.CurrentCulture); // set axis titlet
     241
     242      if (ShowXAxisLabel) {
     243        ChartAreas[0].AxisX.Title = Variable + " : " + defaultValue.ToString("N3", CultureInfo.CurrentCulture); // set axis title
     244      }
     245
    235246      AddStripLines(); // add strip lines
    236247      if (ShowLegend)
     
    238249    }
    239250
    240     private void UpdateInternalDataset() {
     251    private void UpdateDataset() {
    241252      var variables = ProblemData.Dataset.DoubleVariables.ToList();
    242253      var variableValues = new List<double>[variables.Count];
     
    253264        }
    254265      }
    255       internalDataset = new ModifiableDataset(variables, variableValues);
     266      dataset = new ModifiableDataset(variables, variableValues);
    256267    }
    257268
    258269    private double GetEstimatedValue(IRegressionSolution solution, double x) {
    259       var v = internalDataset.GetDoubleValue(Variable, 0);
    260       internalDataset.SetVariableValue(x, Variable, 0);
    261       var y = solution.Model.GetEstimatedValues(internalDataset, new[] { 0 }).Single();
    262       internalDataset.SetVariableValue(v, Variable, 0);
     270      var v = dataset.GetDoubleValue(Variable, 0);
     271      dataset.SetVariableValue(x, Variable, 0);
     272      var y = solution.Model.GetEstimatedValues(dataset, new[] { 0 }).Single();
     273      dataset.SetVariableValue(v, Variable, 0);
    263274      return y;
    264275    }
    265276
    266277    private Series PlotSeries(IRegressionSolution solution) {
    267       var v = internalDataset.GetDoubleValue(variable, 0);
     278      var v = dataset.GetDoubleValue(variable, 0);
    268279      var series = new Series { ChartType = SeriesChartType.Point };
    269280
    270281      var step = (max - min) / points;
    271282      var axisX = ChartAreas[0].AxisX;
    272       axisX.Title = Variable + " : " + v.ToString("N3", CultureInfo.CurrentCulture);
     283      if (ShowXAxisLabel) {
     284        axisX.Title = Variable + " : " + v.ToString("N3", CultureInfo.CurrentCulture);
     285      }
    273286      var axisY = ChartAreas[0].AxisY;
    274       axisY.Title = Target;
     287      if (ShowYAxisLabel) { axisY.Title = Target; }
    275288      double y;
    276289      // lefthand section outside of the training range
     
    290303      }
    291304
    292       y = GetEstimatedValue(solution, v);
    293       series.Points.Add(new DataPoint(v, y) { MarkerSize = 5, MarkerColor = Color.Red });
    294       series.IsVisibleInLegend = true;
     305      if (ShowCursor) {
     306        y = GetEstimatedValue(solution, v);
     307        series.Points.Add(new DataPoint(v, y) { MarkerSize = 5, MarkerColor = Color.Red });
     308      }
     309      if (ShowLegend) {
     310        series.IsVisibleInLegend = true;
     311      }
    295312
    296313      return series;
     
    340357      var annotation = VerticalLineAnnotation;
    341358      var x = annotation.X;
    342       internalDataset.SetVariableValue(x, Variable, 0);
     359      dataset.SetVariableValue(x, Variable, 0);
    343360      for (int i = 0; i < solutionList.Count; ++i) {
    344361        var y = GetEstimatedValue(solutionList[i], x);
     
    347364        s.Points[n - 1] = new DataPoint(x, y) { MarkerColor = Color.Red, MarkerSize = 5 };
    348365      }
    349       ChartAreas[0].AxisX.Title = Variable + " : " + x.ToString("N3", CultureInfo.CurrentCulture);
     366      if (ShowXAxisLabel) {
     367        ChartAreas[0].AxisX.Title = Variable + " : " + x.ToString("N3", CultureInfo.CurrentCulture);
     368      }
    350369      Update();
    351370      OnVariableValueChanged(this, EventArgs.Empty);
     
    360379      if (e.NewLocationX < axisX.Minimum)
    361380        e.NewLocationX = axisX.Minimum;
    362       //      var x = e.NewLocationX;
    363       //      internalDataset.SetVariableValue(x, Variable, 0);
    364       //      for (int i = 0; i < solutionList.Count; ++i) {
    365       //        var y = GetEstimatedValue(solutionList[i], x);
    366       //        var s = Series[i];
    367       //        var n = s.Points.Count;
    368       //        s.Points[n - 1] = new DataPoint(x, y) { MarkerColor = Color.Red, MarkerSize = 5 };
    369       //      }
    370       //      ChartAreas[0].AxisX.Title = Variable + " : " + x.ToString("N3", CultureInfo.CurrentCulture);
    371       //      Update();
    372       //      OnVariableValueChanged(this, EventArgs.Empty);
    373381    }
    374382
  • branches/HeuristicLab.RegressionSolutionGradientView/HeuristicLab.Problems.DataAnalysis.Views/3.4/RegressionSolutionTargetResponseGradientView.cs

    r13818 r13820  
    8080          if (v < min) min = v;
    8181        }
    82         var gradientChart = new GradientChart { Dock = DockStyle.Fill, ShowLegend = false, Margin = Padding.Empty };
     82        var gradientChart = new GradientChart {
     83          Dock = DockStyle.Fill,
     84          Margin = Padding.Empty,
     85          ShowLegend = false,
     86          ShowCursor = true,
     87          ShowXAxisLabel = true,
     88          ShowYAxisLabel = true
     89        };
    8390        gradientChart.VariableValueChanged += (o, e) => {
    8491          foreach (var chart in gradientChartTableLayout.Controls.Cast<GradientChart>()) {
Note: See TracChangeset for help on using the changeset viewer.