Free cookie consent management tool by TermsFeed Policy Generator

Ignore:
Timestamp:
07/21/16 17:24:22 (8 years ago)
Author:
mkommend
Message:

#2597: Merged r14095, r14096, r14098, r14099, r14118, r14119, r14131, r14157, r14158 into stable.

Location:
stable
Files:
3 edited
1 copied

Legend:

Unmodified
Added
Removed
  • stable

  • stable/HeuristicLab.Problems.DataAnalysis.Views

  • stable/HeuristicLab.Problems.DataAnalysis.Views/3.4/Controls/GradientChart.cs

    r14099 r14166  
    6666      set {
    6767        chart.Annotations[0].Visible = value;
    68         if (!value) chart.ChartAreas[0].AxisX.Title = string.Empty;
     68        if (!value) chart.Titles[0].Text = string.Empty;
    6969      }
    7070    }
     
    207207    #endregion
    208208
     209    public event EventHandler ChartPostPaint;
     210
    209211    public GradientChart() {
    210212      InitializeComponent();
     
    266268          ciSeriesCache.Add(solution, series.Item2);
    267269      }
    268 
    269       ResizeAllSeriesData();
    270       OrderAndColorSeries();
    271     }
    272 
    273     public async Task RecalculateAsync(bool updateOnFinish = true, bool resetYAxis = true) {
    274       if (IsDisposed
    275         || sharedFixedVariables == null || !solutions.Any() || string.IsNullOrEmpty(freeVariable)
    276         || trainingMin.IsAlmost(trainingMax) || trainingMin > trainingMax || drawingSteps == 0)
    277         return;
    278 
    279       calculationPendingTimer.Start();
    280 
    281       Update(); // immediately show label
    282 
    283       // cancel previous recalculate call
    284       if (cancelCurrentRecalculateSource != null)
    285         cancelCurrentRecalculateSource.Cancel();
    286       cancelCurrentRecalculateSource = new CancellationTokenSource();
    287270
    288271      // Set cursor and x-axis
     
    300283
    301284      if (ShowCursor)
    302         chart.ChartAreas[0].AxisX.Title = FreeVariable + " : " + defaultValue.ToString("N3", CultureInfo.CurrentCulture);
     285        chart.Titles[0].Text = FreeVariable + " : " + defaultValue.ToString("N3", CultureInfo.CurrentCulture);
     286
     287      ResizeAllSeriesData();
     288      OrderAndColorSeries();
     289    }
     290
     291    public async Task RecalculateAsync(bool updateOnFinish = true, bool resetYAxis = true) {
     292      if (IsDisposed
     293        || sharedFixedVariables == null || !solutions.Any() || string.IsNullOrEmpty(freeVariable)
     294        || trainingMin.IsAlmost(trainingMax) || trainingMin > trainingMax || drawingSteps == 0)
     295        return;
     296
     297      calculationPendingTimer.Start();
     298
     299      // cancel previous recalculate call
     300      if (cancelCurrentRecalculateSource != null)
     301        cancelCurrentRecalculateSource.Cancel();
     302      cancelCurrentRecalculateSource = new CancellationTokenSource();
     303      var cancellationToken = cancelCurrentRecalculateSource.Token;
    303304
    304305      // Update series
    305       var cancellationToken = cancelCurrentRecalculateSource.Token;
    306306      try {
    307307        var limits = await UpdateAllSeriesDataAsync(cancellationToken);
    308         //cancellationToken.ThrowIfCancellationRequested();
    309308
    310309        yMin = limits.Lower;
     
    328327    }
    329328
     329    public void UpdateTitlePosition() {
     330      var title = chart.Titles[0];
     331      var plotArea = InnerPlotPosition;
     332
     333      title.Visible = plotArea.Width != 0;
     334
     335      title.Position.X = plotArea.X + (plotArea.Width / 2);
     336    }
     337
    330338    private void SetupAxis(Axis axis, double minValue, double maxValue, int ticks, double? fixedAxisMin, double? fixedAxisMax) {
    331       double axisMin, axisMax, axisInterval;
    332       ChartUtil.CalculateAxisInterval(minValue, maxValue, ticks, out axisMin, out axisMax, out axisInterval);
    333       axis.Minimum = fixedAxisMin ?? axisMin;
    334       axis.Maximum = fixedAxisMax ?? axisMax;
    335       axis.Interval = (axis.Maximum - axis.Minimum) / ticks;
     339      if (minValue < maxValue) {
     340        double axisMin, axisMax, axisInterval;
     341        ChartUtil.CalculateAxisInterval(minValue, maxValue, ticks, out axisMin, out axisMax, out axisInterval);
     342        axis.Minimum = fixedAxisMin ?? axisMin;
     343        axis.Maximum = fixedAxisMax ?? axisMax;
     344        axis.Interval = (axis.Maximum - axis.Minimum) / ticks;
     345      }
    336346
    337347      try {
     
    453463          if (yvalues[i] > max) max = yvalues[i];
    454464        }
     465        chart.Invalidate();
     466
     467        cancellationToken.ThrowIfCancellationRequested();
    455468
    456469        var confidenceBoundSolution = solution as IConfidenceRegressionSolution;
    457470        if (confidenceBoundSolution != null) {
    458471          var confidenceIntervalSeries = ciSeriesCache[solution];
    459 
    460           cancellationToken.ThrowIfCancellationRequested();
    461           var variances =
    462             confidenceBoundSolution.Model.GetEstimatedVariances(internalDataset,
    463               Enumerable.Range(0, internalDataset.Rows)).ToList();
     472          var variances = confidenceBoundSolution.Model.GetEstimatedVariances(internalDataset, Enumerable.Range(0, internalDataset.Rows)).ToList();
    464473          for (int i = 0; i < xvalues.Count; i++) {
    465474            var lower = yvalues[i] - 1.96 * Math.Sqrt(variances[i]);
     
    469478            if (upper > max) max = upper;
    470479          }
     480          chart.Invalidate();
    471481        }
    472482
     
    619629
    620630      e.NewLocationX = newLocation;
    621       var annotation = VerticalLineAnnotation;
    622       var x = annotation.X;
     631
     632      UpdateCursor();
     633    }
     634    private void chart_AnnotationPositionChanged(object sender, EventArgs e) {
     635      UpdateCursor();
     636    }
     637    void UpdateCursor() {
     638      var x = VerticalLineAnnotation.X;
    623639      sharedFixedVariables.SetVariableValue(x, FreeVariable, 0);
    624640
    625641      if (ShowCursor) {
    626         chart.ChartAreas[0].AxisX.Title = FreeVariable + " : " + x.ToString("N3", CultureInfo.CurrentCulture);
     642        chart.Titles[0].Text = FreeVariable + " : " + x.ToString("N3", CultureInfo.CurrentCulture);
    627643        chart.Update();
    628644      }
     
    636652    }
    637653
    638     private void chart_DragDrop(object sender, DragEventArgs e) {
     654    private async void chart_DragDrop(object sender, DragEventArgs e) {
    639655      var data = e.Data.GetData(HeuristicLab.Common.Constants.DragDropDataFormat);
    640656      if (data != null) {
    641657        var solution = data as IRegressionSolution;
    642658        if (!solutions.Contains(solution))
    643           AddSolutionAsync(solution);
     659          await AddSolutionAsync(solution);
    644660      }
    645661    }
     
    667683      OnZoomChanged(this, EventArgs.Empty);
    668684    }
     685
     686    private void chart_Resize(object sender, EventArgs e) {
     687      UpdateTitlePosition();
     688    }
     689
     690    private void chart_PostPaint(object sender, ChartPaintEventArgs e) {
     691      if (ChartPostPaint != null)
     692        ChartPostPaint(this, EventArgs.Empty);
     693    }
    669694    #endregion
    670695  }
    671696}
     697
Note: See TracChangeset for help on using the changeset viewer.