Free cookie consent management tool by TermsFeed Policy Generator

source: branches/HeuristicLab.Hive-3.4/sources/HeuristicLab.Clients.Hive.Views/3.4/ExperimentManager/GanttChart.cs @ 6362

Last change on this file since 6362 was 5636, checked in by cneumuel, 14 years ago

#1233

  • updated jobstates documentation
  • enhanced ganttChart
  • fixed setting of jobstates
  • added option to force lifecycle-trigger (mainly for testing purposes)
File size: 1.7 KB
Line 
1using System;
2using System.Collections.Generic;
3using System.Drawing;
4using System.Linq;
5using System.Windows.Forms;
6using System.Windows.Forms.DataVisualization.Charting;
7
8namespace HeuristicLab.Clients.Hive.Views {
9  public partial class GanttChart : UserControl {
10
11    private IDictionary<string, Color> categories = new Dictionary<string, Color>();
12    private IDictionary<string, int> rowNames = new Dictionary<string, int>();
13
14    public GanttChart() {
15      InitializeComponent();
16    }
17
18    public void AddCategory(string name, Color color) {
19      categories[name] = color;
20      chart.Legends[0].CustomItems.Add(color, name);
21    }
22
23    public void AddData(string rowName, string category, DateTime start, DateTime end, string tooltip, bool showLabel = true) {
24      AddRowName(rowName);
25      var point = CreateDataPoint(rowNames[rowName], rowName, start, end, showLabel ? category : string.Empty, categories[category]);
26      point.ToolTip = tooltip;
27      chart.Series[0].Points.Add(point);
28    }
29
30    private void AddRowName(string rowName) {
31      if (!rowNames.ContainsKey(rowName)) {
32        int nextId = rowNames.Count == 0 ? 1 : rowNames.Values.Max() + 1;
33        rowNames.Add(rowName, nextId);
34      }
35    }
36
37    private static DataPoint CreateDataPoint(double x, string axisLabel, DateTime start, DateTime end, string text, Color color) {
38      var point = new DataPoint(x, new double[] { start.ToOADate(), end.ToOADate() });
39      point.Color = color;
40      point.Label = text;
41      point.AxisLabel = axisLabel;
42      return point;
43    }
44
45    public void Reset() {
46      chart.Series[0].Points.Clear();
47      categories.Clear();
48      chart.Legends[0].CustomItems.Clear();
49      rowNames.Clear();
50    }
51  }
52}
Note: See TracBrowser for help on using the repository browser.