1 //-------------------------------------------------------------
2 // <copyright company=
\92Microsoft Corporation
\92>
3 // Copyright © Microsoft Corporation. All Rights Reserved.
5 //-------------------------------------------------------------
6 // @owner=alexgor, deliant
7 //=================================================================
8 // File: KeywordsRegistry.cs
10 // Namespace: System.Web.UI.WebControls[Windows.Forms].Charting.Utilities
12 // Classes: KeywordsRegistry, KeywordInfo
14 // Purpose: A registry that keeps track of all available
15 // keywords and name of the objects and properties
16 // where they can be used.
18 // Formatting Keywords Overview:
19 // -----------------------------
20 // A Formatting Keyword is a specially formatted character sequence
21 // that gets replaced by an associated Chart Series value, or
22 // calculated value. Keywords can be used with most string properties
23 // of Series and DataPoint objects.
25 // Here is an example of setting series labels so that the first
26 // line will display the Y value and the second line displays
29 // Chart1.Series["Series1"].Label = "Y = #VALY\nX = #VALX";
31 // Series label in this case will look like this:
36 // An optional format string can be added after the keyword.
37 // For example, when you set the Format option to Percent for
38 // the first Y value, the resulting keyword produced is "#VALY{P}".
39 // You can also apply format strings in code-behind using the same
40 // nomenclature; you do this by following the keyword with a format
41 // specifier enclosed in braces. For information concerning the
42 // types of formatting that can be used, see the Formatting Types
43 // topic in the MSDN library.
45 // Reviewed: AG - Microsoft 5, 2007
47 //===================================================================
50 #region Used Namespaces
54 using System.Collections;
55 using System.ComponentModel;
56 using System.ComponentModel.Design;
59 using System.Windows.Forms.DataVisualization.Charting;
60 using System.Windows.Forms.DataVisualization.Charting.ChartTypes;
62 using System.Web.UI.DataVisualization.Charting;
63 using System.Web.UI.DataVisualization.Charting.ChartTypes;
69 namespace System.Windows.Forms.DataVisualization.Charting.Utilities
70 #else // Microsoft_CONTROL
71 namespace System.Web.UI.DataVisualization.Charting.Utilities
72 #endif // Microsoft_CONTROL
75 /// KeywordName class contains constant strings defining
76 /// names of all keywords used in the data point and series classes.
78 internal static class KeywordName
82 internal const string Index = "#INDEX";
83 internal const string ValX = "#VALX";
84 internal const string ValY = "#VALY";
85 internal const string Val = "#VAL";
86 internal const string Total = "#TOTAL";
87 internal const string Percent = "#PERCENT";
88 internal const string Label = "#LABEL";
89 internal const string AxisLabel = "#AXISLABEL";
90 internal const string LegendText = "#LEGENDTEXT";
91 internal const string SeriesName = "#SERIESNAME";
92 internal const string Ser = "#SER";
93 internal const string Avg = "#AVG";
94 internal const string Max = "#MAX";
95 internal const string Min = "#MIN";
96 internal const string Last = "#LAST";
97 internal const string First = "#FIRST";
98 internal const string CustomProperty = "#CUSTOMPROPERTY";
100 #endregion // Keyword Names
104 /// KeywordRegistry class stores information about all
105 /// chart formatting keywords. It automatically registers
106 /// all known keywords when object is constructed. This
107 /// data is exposed as ArrayList through the
\91registeredKeywords
\92
108 /// field. Each item in this ArrayList is a KeywordInfo
109 /// object which describes a single formatting keyword.
111 internal class KeywordsRegistry : IServiceProvider
115 // List of registered keywords
116 internal ArrayList registeredKeywords = new ArrayList();
120 #region Constructor and Services
123 /// Keywords registry public constructor.
125 public KeywordsRegistry()
127 // Register Keywords used in the chart
132 /// Returns Keywords registry service object.
134 /// <param name="serviceType">Service type to get.</param>
135 /// <returns>Custom properties registry service.</returns>
136 [EditorBrowsableAttribute(EditorBrowsableState.Never)]
137 object IServiceProvider.GetService(Type serviceType)
139 if(serviceType == typeof(KeywordsRegistry))
143 throw (new ArgumentException( SR.ExceptionKeywordsRegistryUnsupportedType(serviceType.ToString())));
148 #region Keywords Registering methods
151 /// Registers all chart formatting keywords.
153 private void RegisterKeywords()
155 string seriesPointSupportedProperties = "Text,Label,LabelMapAreaAttributes,ToolTip,Url,LabelToolTip,MapAreaAttributes,AxisLabel,LegendToolTip,LegendMapAreaAttributes,LegendUrl,LegendText";
159 SR.DescriptionKeyWordNameIndexDataPoint,
162 SR.DescriptionKeyWordIndexDataPoint2,
164 seriesPointSupportedProperties,
170 SR.DescriptionKeyWordNameXValue,
173 SR.DescriptionKeyWordXValue,
174 "Series,DataPoint,Annotation,LegendCellColumn",
175 seriesPointSupportedProperties,
181 SR.DescriptionKeyWordNameYValue,
184 SR.DescriptionKeyWordYValue,
185 "Series,DataPoint,Annotation,LegendCellColumn,LegendCellColumn",
186 seriesPointSupportedProperties,
192 SR.DescriptionKeyWordNameTotalYValues,
195 SR.DescriptionKeyWordTotalYValues,
196 "Series,DataPoint,Annotation,LegendCellColumn",
197 seriesPointSupportedProperties,
203 SR.DescriptionKeyWordNameYValuePercentTotal,
206 SR.DescriptionKeyWordYValuePercentTotal,
207 "Series,DataPoint,Annotation,LegendCellColumn",
208 seriesPointSupportedProperties,
214 SR.DescriptionKeyWordNameIndexTheDataPoint,
217 SR.DescriptionKeyWordIndexDataPoint,
218 "Series,DataPoint,Annotation,LegendCellColumn",
219 seriesPointSupportedProperties,
225 SR.DescriptionKeyWordNameLabelDataPoint,
228 SR.DescriptionKeyWordLabelDataPoint,
229 "Series,DataPoint,Annotation,LegendCellColumn",
230 seriesPointSupportedProperties,
234 // #AXISLABEL keyword
236 SR.DescriptionKeyWordNameAxisLabelDataPoint,
237 KeywordName.AxisLabel,
239 SR.DescriptionKeyWordAxisLabelDataPoint,
240 "Series,DataPoint,Annotation,LegendCellColumn",
241 seriesPointSupportedProperties,
245 // #LEGENDTEXT keyword
247 SR.DescriptionKeyWordNameLegendText,
248 KeywordName.LegendText,
250 SR.DescriptionKeyWordLegendText,
251 "Series,DataPoint,Annotation,LegendCellColumn",
252 seriesPointSupportedProperties,
256 // #SERIESNAME keyword
258 SR.DescriptionKeyWordNameSeriesName,
259 KeywordName.SeriesName,
261 SR.DescriptionKeyWordSeriesName,
262 "Series,DataPoint,Annotation,LegendCellColumn",
263 seriesPointSupportedProperties,
267 // *************** NEW KEYWORDS in version 5.5 ***************
271 SR.DescriptionKeyWordNameAverageYValues,
274 SR.DescriptionKeyWordAverageYValues,
275 "Series,DataPoint,Annotation,LegendCellColumn",
276 seriesPointSupportedProperties,
282 SR.DescriptionKeyWordNameMaximumYValues,
285 SR.DescriptionKeyWordMaximumYValues,
286 "Series,DataPoint,Annotation,LegendCellColumn",
287 seriesPointSupportedProperties,
293 SR.DescriptionKeyWordNameMinimumYValues,
296 SR.DescriptionKeyWordMinimumYValues,
297 "Series,DataPoint,Annotation,LegendCellColumn",
298 seriesPointSupportedProperties,
304 SR.DescriptionKeyWordNameLastPointYValue,
307 SR.DescriptionKeyWordLastPointYValue,
308 "Series,DataPoint,Annotation,LegendCellColumn",
309 seriesPointSupportedProperties,
315 SR.DescriptionKeyWordNameFirstPointYValue,
318 SR.DescriptionKeyWordFirstPointYValue,
319 "Series,DataPoint,Annotation,LegendCellColumn",
320 seriesPointSupportedProperties,
325 #endregion // Keywords Registering methods
327 #region Registry methods
330 /// Adds keyword information into the registry.
332 /// <param name="name">Keyword full name.</param>
333 /// <param name="keyword">Keyword text.</param>
334 /// <param name="keywordAliases">Keyword alternative text.</param>
335 /// <param name="description">Keyword description.</param>
336 /// <param name="appliesToTypes">Comma separated list of applicable classes</param>
337 /// <param name="appliesToProperties">Comma separated list of applicable properties.</param>
338 /// <param name="supportsFormatting">True if formatting is supported.</param>
339 /// <param name="supportsValueIndex">True if different point Y values are supported.</param>
340 public void Register(
343 string keywordAliases,
345 string appliesToTypes,
346 string appliesToProperties,
347 bool supportsFormatting,
348 bool supportsValueIndex)
350 // Create new keyword information object
351 KeywordInfo keywordInfo = new KeywordInfo(
361 // Add keyword information to the hash table
362 registeredKeywords.Add(keywordInfo);
369 /// KeywordInfo class stores information about a single
370 /// formatting keyword. This information includes Name,
371 /// Description, list of data types and properties it
372 /// applies to and other information.
374 internal class KeywordInfo
376 #region Public Fields
379 /// Keyword full name.
381 public string Name = String.Empty;
384 /// String that represent this keyword in the property (keyword).
386 public string Keyword = String.Empty;
389 /// Comma separated strings that may alternatively represent this
390 /// keyword in the property.
392 public string KeywordAliases = String.Empty;
395 /// Keyword description.
397 public string Description = String.Empty;
400 /// Comma separated names of classes this keyword applies to.
402 public string AppliesToTypes = String.Empty;
405 /// Comma separated names of properties this keyword applies to.
407 public string AppliesToProperties = String.Empty;
410 /// True if keyword value can be formatted.
412 public bool SupportsFormatting = false;
415 /// True if keyword can be used with different point Y values.
417 public bool SupportsValueIndex = false;
419 #endregion // Public Fields
424 /// Keyword information object constructor
426 /// <param name="name">Keyword full name.</param>
427 /// <param name="keyword">Keyword text.</param>
428 /// <param name="keywordAliases">Keyword alternative text.</param>
429 /// <param name="description">Keyword description.</param>
430 /// <param name="appliesToTypes">Comma separated list of applicable classes</param>
431 /// <param name="appliesToProperties">Comma separated list of applicable properties.</param>
432 /// <param name="supportsFormatting">True if formatting is supported.</param>
433 /// <param name="supportsValueIndex">True if different point Y values are supported.</param>
437 string keywordAliases,
439 string appliesToTypes,
440 string appliesToProperties,
441 bool supportsFormatting,
442 bool supportsValueIndex)
445 this.Keyword = keyword;
446 this.KeywordAliases = keywordAliases;
447 this.Description = description;
448 this.AppliesToTypes = appliesToTypes;
449 this.AppliesToProperties = appliesToProperties;
450 this.SupportsFormatting = supportsFormatting;
451 this.SupportsValueIndex = supportsValueIndex;
454 #endregion // Constructor
459 /// Returns a String that represents the current keyword Information.
461 /// <returns>Returns keyword name.</returns>
462 public override string ToString()
467 /// Gets an array of keywords names including the aliases.
469 /// <returns>A string array of keyword names that represent this keyword.</returns>
470 public string[] GetKeywords()
472 // NOTE: Each keyword has a unique name. In addition the keyword may have an
473 // alternative names (aliases).
474 // Most common scenario for a keyword aliase is when keyword has a long and
475 // short form. For example, KeywordName.Ser and "#SERIES".
477 // Fill array of possible names for that keyword
478 if(this.KeywordAliases.Length > 0)
480 string[] keywordAliases = this.KeywordAliases.Split(',');
481 string[] keywordNames = new string[keywordAliases.Length + 1];
482 keywordNames[0] = this.Keyword;
483 keywordAliases.CopyTo(keywordNames, 1);
488 return new string[] { this.Keyword };
492 #endregion // Methods