1 | #region License Information
|
---|
2 | /* HeuristicLab
|
---|
3 | * Copyright (C) 2002-2012 Heuristic and Evolutionary Algorithms Laboratory (HEAL)
|
---|
4 | *
|
---|
5 | * This file is part of HeuristicLab.
|
---|
6 | *
|
---|
7 | * HeuristicLab is free software: you can redistribute it and/or modify
|
---|
8 | * it under the terms of the GNU General Public License as published by
|
---|
9 | * the Free Software Foundation, either version 3 of the License, or
|
---|
10 | * (at your option) any later version.
|
---|
11 | *
|
---|
12 | * HeuristicLab is distributed in the hope that it will be useful,
|
---|
13 | * but WITHOUT ANY WARRANTY; without even the implied warranty of
|
---|
14 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
---|
15 | * GNU General Public License for more details.
|
---|
16 | *
|
---|
17 | * You should have received a copy of the GNU General Public License
|
---|
18 | * along with HeuristicLab. If not, see <http://www.gnu.org/licenses/>.
|
---|
19 | */
|
---|
20 | #endregion
|
---|
21 |
|
---|
22 | using System;
|
---|
23 | using System.Collections.Generic;
|
---|
24 | using System.Drawing;
|
---|
25 | using System.Linq;
|
---|
26 | using System.Windows.Forms;
|
---|
27 | using System.Windows.Forms.DataVisualization.Charting;
|
---|
28 |
|
---|
29 | namespace HeuristicLab.Clients.Hive.Views {
|
---|
30 | public partial class GanttChart : UserControl {
|
---|
31 |
|
---|
32 | private IDictionary<string, Color> categories = new Dictionary<string, Color>();
|
---|
33 | private IDictionary<string, int> rowNames = new Dictionary<string, int>();
|
---|
34 |
|
---|
35 | public GanttChart() {
|
---|
36 | InitializeComponent();
|
---|
37 | }
|
---|
38 |
|
---|
39 | public void AddCategory(string name, Color color) {
|
---|
40 | categories[name] = color;
|
---|
41 | chart.Legends[0].CustomItems.Add(color, name);
|
---|
42 | }
|
---|
43 |
|
---|
44 | public void AddData(string rowName, string category, DateTime start, DateTime end, string tooltip, bool showLabel = true) {
|
---|
45 | AddRowName(rowName);
|
---|
46 | var point = CreateDataPoint(rowNames[rowName], rowName, start, end, showLabel ? category : string.Empty, categories[category]);
|
---|
47 | point.ToolTip = tooltip;
|
---|
48 | chart.Series[0].Points.Add(point);
|
---|
49 | }
|
---|
50 |
|
---|
51 | private void AddRowName(string rowName) {
|
---|
52 | if (!rowNames.ContainsKey(rowName)) {
|
---|
53 | int nextId = rowNames.Count == 0 ? 1 : rowNames.Values.Max() + 1;
|
---|
54 | rowNames.Add(rowName, nextId);
|
---|
55 | }
|
---|
56 | }
|
---|
57 |
|
---|
58 | private static DataPoint CreateDataPoint(double x, string axisLabel, DateTime start, DateTime end, string text, Color color) {
|
---|
59 | var point = new DataPoint(x, new double[] { start.ToOADate(), end.ToOADate() });
|
---|
60 | point.Color = color;
|
---|
61 | point.Label = text;
|
---|
62 | point.AxisLabel = axisLabel;
|
---|
63 | return point;
|
---|
64 | }
|
---|
65 |
|
---|
66 | public void Reset() {
|
---|
67 | chart.Series[0].Points.Clear();
|
---|
68 | categories.Clear();
|
---|
69 | chart.Legends[0].CustomItems.Clear();
|
---|
70 | rowNames.Clear();
|
---|
71 | }
|
---|
72 | }
|
---|
73 | }
|
---|