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 @ 6004

Last change on this file since 6004 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
RevLine 
[5597]1using System;
2using System.Collections.Generic;
3using System.Drawing;
[5636]4using System.Linq;
[5597]5using System.Windows.Forms;
6using System.Windows.Forms.DataVisualization.Charting;
7
[5636]8namespace HeuristicLab.Clients.Hive.Views {
[5597]9  public partial class GanttChart : UserControl {
10
11    private IDictionary<string, Color> categories = new Dictionary<string, Color>();
[5636]12    private IDictionary<string, int> rowNames = new Dictionary<string, int>();
[5597]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
[5636]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]);
[5597]26      point.ToolTip = tooltip;
27      chart.Series[0].Points.Add(point);
28    }
29
[5636]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) {
[5597]38      var point = new DataPoint(x, new double[] { start.ToOADate(), end.ToOADate() });
39      point.Color = color;
40      point.Label = text;
[5636]41      point.AxisLabel = axisLabel;
[5597]42      return point;
43    }
44
45    public void Reset() {
46      chart.Series[0].Points.Clear();
47      categories.Clear();
48      chart.Legends[0].CustomItems.Clear();
[5636]49      rowNames.Clear();
[5597]50    }
51  }
52}
Note: See TracBrowser for help on using the repository browser.