ColorSymbolRotator.cs
4.9 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
//============================================================================
//ZedGraph Class Library - A Flexible Line Graph/Bar Graph Library in C#
//Copyright © 2004 John Champion
//
//This library is free software; you can redistribute it and/or
//modify it under the terms of the GNU Lesser General Public
//License as published by the Free Software Foundation; either
//version 2.1 of the License, or (at your option) any later version.
//
//This library is distributed in the hope that it will be useful,
//but WITHOUT ANY WARRANTY; without even the implied warranty of
//MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
//Lesser General Public License for more details.
//
//You should have received a copy of the GNU Lesser General Public
//License along with this library; if not, write to the Free Software
//Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
//=============================================================================
using System;
using Color = System.Drawing.Color;
namespace ZedGraph
{
/// <summary>
/// Class used to get the next color/symbol for GraphPane.AddCurve methods.
/// </summary>
///
/// <author> Jerry Vos modified by John Champion </author>
/// <version> $Revision: 3.4 $ $Date: 2006/06/24 20:26:43 $ </version>
public class ColorSymbolRotator
{
#region Static fields
/// <summary>
/// The <see cref="Color"/>s <see cref="ColorSymbolRotator"/>
/// rotates through.
/// </summary>
public static readonly Color[] COLORS = new Color[]
{
Color.Red,
Color.Blue,
Color.Green,
Color.Purple,
Color.Cyan,
Color.Pink,
Color.LightBlue,
Color.PaleVioletRed,
Color.SeaGreen,
Color.Yellow
};
/// <summary>
/// The <see cref="SymbolType"/>s <see cref="ColorSymbolRotator"/>
/// rotates through.
/// </summary>
public static readonly SymbolType[] SYMBOLS = new SymbolType[]
{
SymbolType.Circle,
SymbolType.Diamond,
SymbolType.Plus,
SymbolType.Square,
SymbolType.Star,
SymbolType.Triangle,
SymbolType.TriangleDown,
SymbolType.XCross,
SymbolType.HDash,
SymbolType.VDash
};
private static ColorSymbolRotator _staticInstance;
#endregion
#region Fields
/// <summary>
/// The index of the next color to be used. Note: may be
/// > COLORS.Length, it is reset to 0 on the next call if it is.
/// </summary>
protected int colorIndex = 0;
/// <summary>
/// The index of the next symbol to be used. Note: may be
/// > SYMBOLS.Length, it is reset to 0 on the next call if it is.
/// </summary>
protected int symbolIndex = 0;
#endregion
#region Properties
/// <summary>
/// Retrieves the next color in the rotation Calling this
/// method has the side effect of incrementing the color index.
/// <seealso cref="NextSymbol"/>
/// <seealso cref="NextColorIndex"/>
/// </summary>
public Color NextColor
{
get { return COLORS[NextColorIndex]; }
}
/// <summary>
/// Retrieves the index of the next color to be used. Calling this
/// method has the side effect of incrementing the color index.
/// </summary>
public int NextColorIndex
{
get
{
if (colorIndex >= COLORS.Length)
colorIndex = 0;
return colorIndex++;
}
set
{
colorIndex = value;
}
}
/// <summary>
/// Retrieves the next color in the rotation. Calling this
/// method has the side effect of incrementing the symbol index.
/// <seealso cref="NextColor"/>
/// <seealso cref="NextSymbolIndex"/>
/// </summary>
public SymbolType NextSymbol
{
get { return SYMBOLS[NextSymbolIndex]; }
}
/// <summary>
/// Retrieves the index of the next symbol to be used. Calling this
/// method has the side effect of incrementing the symbol index.
/// </summary>
public int NextSymbolIndex
{
get
{
if (symbolIndex >= SYMBOLS.Length)
symbolIndex = 0;
return symbolIndex++;
}
set
{
symbolIndex = value;
}
}
/// <summary>
/// Retrieves the <see cref="ColorSymbolRotator"/> instance used by the
/// static methods.
/// <seealso cref="StaticNextColor"/>
/// <seealso cref="StaticNextSymbol"/>
/// </summary>
public static ColorSymbolRotator StaticInstance
{
get
{
if (_staticInstance == null)
_staticInstance = new ColorSymbolRotator();
return _staticInstance;
}
}
/// <summary>
/// Retrieves the next color from this class's static
/// <see cref="ColorSymbolRotator"/> instance
/// <seealso cref="StaticInstance"/>
/// <seealso cref="StaticNextSymbol"/>
/// </summary>
public static Color StaticNextColor
{
get { return StaticInstance.NextColor; }
}
/// <summary>
/// Retrieves the next symbol type from this class's static
/// <see cref="ColorSymbolRotator"/> instance
/// <seealso cref="StaticInstance"/>
/// <seealso cref="StaticNextColor"/>
/// </summary>
public static SymbolType StaticNextSymbol
{
get { return StaticInstance.NextSymbol; }
}
#endregion
}
}