Changeset 13840
- Timestamp:
- 05/10/16 12:38:08 (8 years ago)
- Location:
- branches/HeuristicLab.RegressionSolutionGradientView/HeuristicLab.Problems.DataAnalysis.Views/3.4
- Files:
-
- 4 edited
Legend:
- Unmodified
- Added
- Removed
-
branches/HeuristicLab.RegressionSolutionGradientView/HeuristicLab.Problems.DataAnalysis.Views/3.4/GradientChart.Designer.cs
r13836 r13840 31 31 System.Windows.Forms.DataVisualization.Charting.Legend legend1 = new System.Windows.Forms.DataVisualization.Charting.Legend(); 32 32 this.chart = new HeuristicLab.Visualization.ChartControlsExtensions.EnhancedChart(); 33 this.statusLabel = new System.Windows.Forms.Label(); 33 34 ((System.ComponentModel.ISupportInitialize)(this.chart)).BeginInit(); 34 35 this.SuspendLayout(); … … 70 71 this.chart.MouseMove += new System.Windows.Forms.MouseEventHandler(this.chart_MouseMove); 71 72 // 73 // statusLabel 74 // 75 this.statusLabel.BackColor = System.Drawing.Color.White; 76 this.statusLabel.Image = HeuristicLab.Common.Resources.VSImageLibrary.Timer; 77 this.statusLabel.ImageAlign = System.Drawing.ContentAlignment.MiddleLeft; 78 this.statusLabel.Location = new System.Drawing.Point(3, 3); 79 this.statusLabel.Margin = new System.Windows.Forms.Padding(0); 80 this.statusLabel.Name = "statusLabel"; 81 this.statusLabel.Size = new System.Drawing.Size(17, 17); 82 this.statusLabel.TabIndex = 1; 83 this.statusLabel.TextAlign = System.Drawing.ContentAlignment.MiddleRight; 84 this.statusLabel.Visible = false; 85 // 72 86 // GradientChart 73 87 // 74 88 this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 13F); 75 89 this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font; 90 this.Controls.Add(this.statusLabel); 76 91 this.Controls.Add(this.chart); 77 92 this.Name = "GradientChart"; … … 85 100 86 101 private HeuristicLab.Visualization.ChartControlsExtensions.EnhancedChart chart; 102 private System.Windows.Forms.Label statusLabel; 87 103 } 88 104 } -
branches/HeuristicLab.RegressionSolutionGradientView/HeuristicLab.Problems.DataAnalysis.Views/3.4/GradientChart.cs
r13837 r13840 25 25 using System.Globalization; 26 26 using System.Linq; 27 using System.Threading; 27 28 using System.Threading.Tasks; 28 29 using System.Windows.Forms; … … 37 38 private ModifiableDataset internalDataset; // holds the x values for each point drawn 38 39 40 private CancellationTokenSource cancelCurrentRefresh; 41 39 42 public bool ShowLegend { 40 43 get { return chart.Legends[0].Enabled; } … … 57 60 public int XAxisTicks { 58 61 get { return xAxisTicks; } 59 set { if (xAxisTicks != value) { xAxisTicks = value; UpdateChart Async(); } }62 set { if (xAxisTicks != value) { xAxisTicks = value; UpdateChart(); } } 60 63 } 61 64 private int yAxisTicks = 5; 62 65 public int YXAxisTicks { 63 66 get { return yAxisTicks; } 64 set { if (yAxisTicks != value) { yAxisTicks = value; UpdateChart Async(); } }67 set { if (yAxisTicks != value) { yAxisTicks = value; UpdateChart(); } } 65 68 } 66 69 … … 68 71 public double TrainingMin { 69 72 get { return trainingMin; } 70 set { if (!value.IsAlmost(trainingMin)) { trainingMin = value; UpdateChart Async(); } }73 set { if (!value.IsAlmost(trainingMin)) { trainingMin = value; UpdateChart(); } } 71 74 } 72 75 private double trainingMax = double.MaxValue; 73 76 public double TrainingMax { 74 77 get { return trainingMax; } 75 set { if (!value.IsAlmost(trainingMax)) { trainingMax = value; UpdateChart Async(); } }78 set { if (!value.IsAlmost(trainingMax)) { trainingMax = value; UpdateChart(); } } 76 79 } 77 80 … … 79 82 public int DrawingSteps { 80 83 get { return drawingSteps; } 81 set { if (value != drawingSteps) { drawingSteps = value; UpdateChart Async(); } }84 set { if (value != drawingSteps) { drawingSteps = value; UpdateChart(); } } 82 85 } 83 86 … … 92 95 freeVariable = value; 93 96 RecalculateInternalDataset(); 94 UpdateChart Async();97 UpdateChart(); 95 98 } 96 99 } … … 117 120 chart.ChartAreas[0].AxisY.ScaleView.Zoomable = true; 118 121 chart.ChartAreas[0].CursorY.Interval = 0; 122 123 Disposed +=GradientChart_Disposed; 124 } 125 126 private void GradientChart_Disposed(object sender, EventArgs e) { 127 if (cancelCurrentRefresh != null) { 128 if (cancelCurrentRefresh.IsCancellationRequested) 129 cancelCurrentRefresh.Cancel(); 130 cancelCurrentRefresh.Dispose(); 131 } 119 132 } 120 133 … … 175 188 } 176 189 177 public async Task UpdateChartAsync() {190 public async void UpdateChart() { 178 191 // throw exceptions? 179 192 if (sharedFixedVariables == null || solutions == null || !solutions.Any()) … … 181 194 if (trainingMin.IsAlmost(trainingMax) || trainingMin > trainingMax || drawingSteps == 0) 182 195 return; 196 if (IsDisposed) 197 return; 198 199 statusLabel.Visible = true; 200 201 if (cancelCurrentRefresh != null && !cancelCurrentRefresh.IsCancellationRequested) 202 cancelCurrentRefresh.Cancel(); 203 cancelCurrentRefresh = new CancellationTokenSource(); 183 204 184 205 // Set cursor … … 194 215 axis.Interval = axisInterval; 195 216 217 var cancellationToken = cancelCurrentRefresh.Token; 196 218 // Create series <mean, conf. interval> 197 219 var seriesDict = new Dictionary<Series, Series>(); 198 for (int i = 0; i < solutions.Count; ++i) {220 for (int i = 0; i < solutions.Count; i++) { 199 221 var solution = solutions[i]; 200 var series = await CreateSeriesAsync(solution); 201 series.Item1.Tag = i; // for sorting 202 var meanSeries = series.Item1; 203 var confidenceIntervalSeries = series.Item2; 204 meanSeries.Name = solution.ProblemData.TargetVariable + " " + i; 205 seriesDict.Add(meanSeries, confidenceIntervalSeries); 206 if (confidenceIntervalSeries != null) 207 confidenceIntervalSeries.Name = "95% Conf. Interval " + meanSeries.Name; 222 try { 223 var series = await CreateSeriesAsync(solution, cancellationToken); 224 if (cancellationToken.IsCancellationRequested) 225 return; 226 series.Item1.Tag = i; // for sorting 227 var meanSeries = series.Item1; 228 var confidenceIntervalSeries = series.Item2; 229 meanSeries.Name = solution.ProblemData.TargetVariable + " " + i; 230 seriesDict.Add(meanSeries, confidenceIntervalSeries); 231 if (confidenceIntervalSeries != null) 232 confidenceIntervalSeries.Name = "95% Conf. Interval " + meanSeries.Name; 233 } 234 catch (TaskCanceledException) { 235 return; 236 } 208 237 } 209 238 … … 229 258 230 259 231 // 260 ////calculate Y-axis interval 232 261 //double ymin = 0, ymax = 0; 233 262 //foreach (var vs in chart.Series.SelectMany(series => series.Points.Select(s => s.YValues))) { … … 249 278 250 279 UpdateStripLines(); 251 } 252 253 private Task<Tuple<Series, Series>> CreateSeriesAsync(IRegressionSolution solution) { 280 281 statusLabel.Visible = false; 282 } 283 284 private Task<Tuple<Series, Series>> CreateSeriesAsync(IRegressionSolution solution, CancellationToken cancellationToken) { 254 285 return Task.Run(() => { 255 286 var xvalues = internalDataset.GetDoubleValues(FreeVariable).ToList(); … … 270 301 confidenceIntervalSeries.Points.DataBindXY(xvalues, lower, upper); 271 302 } 272 273 303 return Tuple.Create(series, confidenceIntervalSeries); 274 } );304 }, cancellationToken); 275 305 } 276 306 … … 281 311 solutions.Add(solution); 282 312 RecalculateTrainingLimits(); 283 UpdateChart Async();313 UpdateChart(); 284 314 } 285 315 public void RemoveSolution(IRegressionSolution solution) { 286 316 if (!solutions.Remove(solution)) return; 287 317 RecalculateTrainingLimits(); 288 UpdateChart Async();318 UpdateChart(); 289 319 } 290 320 … … 324 354 325 355 private void chart_AnnotationPositionChanged(object sender, EventArgs e) { 326 var annotation = VerticalLineAnnotation;327 var x = annotation.X;328 sharedFixedVariables.SetVariableValue(x, FreeVariable, 0);329 330 chart.ChartAreas[0].AxisX.Title = FreeVariable + " : " + x.ToString("N3", CultureInfo.CurrentCulture);331 chart.Update();332 333 OnVariableValueChanged(this, EventArgs.Empty);356 //var annotation = VerticalLineAnnotation; 357 //var x = annotation.X; 358 //sharedFixedVariables.SetVariableValue(x, FreeVariable, 0); 359 360 //chart.ChartAreas[0].AxisX.Title = FreeVariable + " : " + x.ToString("N3", CultureInfo.CurrentCulture); 361 //chart.Update(); 362 363 //OnVariableValueChanged(this, EventArgs.Empty); 334 364 } 335 365 336 366 private void chart_AnnotationPositionChanging(object sender, AnnotationPositionChangingEventArgs e) { 337 //var step = (trainingMax - trainingMin) / drawingSteps;338 //e.NewLocationX = step * (long)Math.Round(e.NewLocationX / step);339 //var axisX = chart.ChartAreas[0].AxisX;340 //if (e.NewLocationX > axisX.Maximum)341 //e.NewLocationX = axisX.Maximum;342 //if (e.NewLocationX < axisX.Minimum)343 //e.NewLocationX = axisX.Minimum;367 var step = (trainingMax - trainingMin) / drawingSteps; 368 e.NewLocationX = step * (long)Math.Round(e.NewLocationX / step); 369 var axisX = chart.ChartAreas[0].AxisX; 370 if (e.NewLocationX > axisX.Maximum) 371 e.NewLocationX = axisX.Maximum; 372 if (e.NewLocationX < axisX.Minimum) 373 e.NewLocationX = axisX.Minimum; 344 374 345 375 var annotation = VerticalLineAnnotation; -
branches/HeuristicLab.RegressionSolutionGradientView/HeuristicLab.Problems.DataAnalysis.Views/3.4/RegressionSolutionGradientView.cs
r13837 r13840 87 87 sharedFixedVariables = new ModifiableDataset(variableNames, newTrackbars.Select(tb => new List<double>(1) { (double)tb.Value })); 88 88 gradientChart.Configure(new[] { Content }, sharedFixedVariables, variableNames.First(), DrawingSteps); 89 gradientChart.UpdateChart Async();89 gradientChart.UpdateChart(); 90 90 91 91 // Add to table and observable lists … … 149 149 } 150 150 151 private asyncvoid trackbar_ValueChanged(object sender, EventArgs e) {151 private void trackbar_ValueChanged(object sender, EventArgs e) { 152 152 var trackBar = sender as DensityTrackbar; 153 153 if (trackBar == null) return; 154 154 sharedFixedVariables.SetVariableValue((double)trackBar.Value, variableNames[trackbars.IndexOf(trackBar)], 0); 155 await gradientChart.UpdateChartAsync();155 gradientChart.UpdateChart(); 156 156 } 157 157 -
branches/HeuristicLab.RegressionSolutionGradientView/HeuristicLab.Problems.DataAnalysis.Views/3.4/RegressionSolutionTargetResponseGradientView.cs
r13837 r13840 73 73 ShowYAxisLabel = true, 74 74 }; 75 gradientChart.VariableValueChanged += async(o, e) => {75 gradientChart.VariableValueChanged += (o, e) => { 76 76 foreach (var chart in gradientChartTableLayout.Controls.Cast<GradientChart>()) { 77 77 if (chart == (GradientChart)o) continue; 78 await chart.UpdateChartAsync();78 chart.UpdateChart(); 79 79 } 80 80 }; … … 99 99 } 100 100 101 private asyncvoid variableListView_ItemChecked(object sender, ItemCheckedEventArgs e) {101 private void variableListView_ItemChecked(object sender, ItemCheckedEventArgs e) { 102 102 if (charts == null) return; 103 103 var item = e.Item; … … 111 111 if (item.Checked) { 112 112 tl.Controls.Add(chart); 113 await chart.UpdateChartAsync();113 chart.UpdateChart(); 114 114 } else { 115 115 tl.Controls.Remove(chart);
Note: See TracChangeset
for help on using the changeset viewer.