[7410] | 1 | #region License Information
|
---|
| 2 | /* HeuristicLab
|
---|
[11170] | 3 | * Copyright (C) 2002-2014 Heuristic and Evolutionary Algorithms Laboratory (HEAL)
|
---|
[7410] | 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.Visualization.ChartControlsExtensions {
|
---|
| 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();
|
---|
[8107] | 37 | chart.CustomizeAllChartAreas();
|
---|
[7410] | 38 | }
|
---|
| 39 |
|
---|
| 40 | public void AddCategory(string name, Color color) {
|
---|
| 41 | categories[name] = color;
|
---|
| 42 | chart.Legends[0].CustomItems.Add(color, name);
|
---|
| 43 | }
|
---|
| 44 |
|
---|
| 45 | public void AddData(string rowName, string category, DateTime start, DateTime end, string tooltip, bool showLabel = true) {
|
---|
| 46 | AddRowName(rowName);
|
---|
| 47 | var point = CreateDataPoint(rowNames[rowName], rowName, start, end, showLabel ? category : string.Empty, categories[category]);
|
---|
| 48 | point.ToolTip = tooltip;
|
---|
| 49 | chart.Series[0].Points.Add(point);
|
---|
| 50 | }
|
---|
| 51 |
|
---|
| 52 | private void AddRowName(string rowName) {
|
---|
| 53 | if (!rowNames.ContainsKey(rowName)) {
|
---|
| 54 | int nextId = rowNames.Count == 0 ? 1 : rowNames.Values.Max() + 1;
|
---|
| 55 | rowNames.Add(rowName, nextId);
|
---|
| 56 | }
|
---|
| 57 | }
|
---|
| 58 |
|
---|
| 59 | private static DataPoint CreateDataPoint(double x, string axisLabel, DateTime start, DateTime end, string text, Color color) {
|
---|
| 60 | var point = new DataPoint(x, new double[] { start.ToOADate(), end.ToOADate() });
|
---|
| 61 | point.Color = color;
|
---|
| 62 | point.Label = text;
|
---|
| 63 | point.AxisLabel = axisLabel;
|
---|
| 64 | return point;
|
---|
| 65 | }
|
---|
| 66 |
|
---|
| 67 | public void Reset() {
|
---|
| 68 | chart.Series[0].Points.Clear();
|
---|
| 69 | categories.Clear();
|
---|
| 70 | chart.Legends[0].CustomItems.Clear();
|
---|
| 71 | rowNames.Clear();
|
---|
| 72 | }
|
---|
| 73 | }
|
---|
| 74 | }
|
---|