Free cookie consent management tool by TermsFeed Policy Generator

source: branches/Scheduling/HeuristicLab.Problems.Scheduling.Views/3.3/GanttChart.cs @ 6177

Last change on this file since 6177 was 6177, checked in by jhelm, 13 years ago

#1329: Implemented PriorityRulesVector based encoding and added new operators to the JSMEncoding. Added Gantt-Charts for visualization of schedules and problems.

File size: 1.8 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.Problems.Scheduling.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      if (!categories.ContainsKey(name)) {
20        categories[name] = color;
21        chart.Legends[0].CustomItems.Add(color, name);
22      }
23    }
24
25    public void AddData(string rowName, string category, double start, double end, string tooltip, bool showLabel = true) {
26      AddRowName(rowName);
27      var point = CreateDataPoint(rowNames[rowName], rowName, start, end, showLabel ? category : string.Empty, categories[category]);
28      point.ToolTip = tooltip;
29      chart.Series[0].Points.Add(point);
30    }
31
32    private void AddRowName(string rowName) {
33      if (!rowNames.ContainsKey(rowName)) {
34        int nextId = rowNames.Count == 0 ? 1 : rowNames.Values.Max() + 1;
35        rowNames.Add(rowName, nextId);
36      }
37    }
38
39    private static DataPoint CreateDataPoint(double x, string axisLabel, double start, double end, string text, Color color) {
40      var point = new DataPoint(x, new double[] { start, end });
41      point.Color = color;
42      point.Label = text;
43      point.AxisLabel = axisLabel;
44      return point;
45    }
46
47    public void Reset() {
48      chart.Series[0].Points.Clear();
49      categories.Clear();
50      chart.Legends[0].CustomItems.Clear();
51      rowNames.Clear();
52    }
53  }
54}
Note: See TracBrowser for help on using the repository browser.