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