1 | using System;
|
---|
2 | using System.Collections.Generic;
|
---|
3 | using System.Drawing;
|
---|
4 | using System.Linq;
|
---|
5 | using System.Windows.Forms;
|
---|
6 | using System.Windows.Forms.DataVisualization.Charting;
|
---|
7 |
|
---|
8 | namespace 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 | }
|
---|