409 lines
		
	
	
		
			10 KiB
		
	
	
	
		
			C#
		
	
	
	
	
	
			
		
		
	
	
			409 lines
		
	
	
		
			10 KiB
		
	
	
	
		
			C#
		
	
	
	
	
	
| using System;
 | |
| using System.Collections.Generic;
 | |
| using System.ComponentModel;
 | |
| using System.Drawing.Design;
 | |
| using DevComponents.DotNetBar.Charts;
 | |
| using DevComponents.DotNetBar.Charts.Style;
 | |
| 
 | |
| /// <summary>
 | |
| /// Represents the collection of DataLabels.
 | |
| /// </summary>
 | |
| [Editor("DevComponents.Charts.Design.DataLabelCollectionEditor, DevComponents.Charts.Design, " +
 | |
|     "Version=14.1.0.37, Culture=neutral,  PublicKeyToken=90f470f34c89ccaf", typeof(UITypeEditor))]
 | |
| public class DataLabelCollection : CustomNamedCollection<DataLabel>
 | |
| {
 | |
|     #region GetUniqueName
 | |
| 
 | |
|     public string GetUniqueName()
 | |
|     {
 | |
|         return (GetUniqueName("DataLabel"));
 | |
|     }
 | |
| 
 | |
|     #endregion
 | |
| }
 | |
| 
 | |
| namespace DevComponents.DotNetBar.Charts
 | |
| {
 | |
|     public class DataLabel : ChartVisualElement, IEffectiveStyle
 | |
|     {
 | |
|         #region Private variables
 | |
| 
 | |
|         private string _Text;
 | |
| 
 | |
|         private DataLabelVisualStyle _DataLabelVisualStyle;
 | |
|         private EffectiveStyle<DataLabelVisualStyle> _EffectiveDataLabelStyle;
 | |
| 
 | |
|         private object _ValueX;
 | |
|         private object _ValueY;
 | |
| 
 | |
|         private BarLabelPosition _BarLabelPosition = BarLabelPosition.NotSet;
 | |
| 
 | |
|         #endregion
 | |
| 
 | |
|         #region Constructors
 | |
| 
 | |
|         /// <summary>
 | |
|         /// DataLabel
 | |
|         /// </summary>
 | |
|         /// <param name="sp">Associated SeriesPoint</param>
 | |
|         /// <param name="text">Label text</param>
 | |
|         public DataLabel(SeriesPoint sp, string text)
 | |
|             : this(sp)
 | |
|         {
 | |
|             _Text = text;
 | |
|         }
 | |
| 
 | |
|         /// <summary>
 | |
|         /// DataLabel
 | |
|         /// </summary>
 | |
|         /// <param name="sp">Associated SeriesPoint</param>
 | |
|         public DataLabel(SeriesPoint sp)
 | |
|             : this()
 | |
|         {
 | |
|             if (sp.ValueX == null)
 | |
|                 throw new Exception("DataLabel Value X must be defined.");
 | |
| 
 | |
|             if (sp.ValueY == null || sp.ValueY.Length == 0)
 | |
|                 throw new Exception("DataLabel Value Y must be defined.");
 | |
| 
 | |
|             ValueX = sp.ValueX;
 | |
|             ValueY = sp.ValueY[0];
 | |
|         }
 | |
| 
 | |
|         /// <summary>
 | |
|         /// DataLabel
 | |
|         /// </summary>
 | |
|         public DataLabel()
 | |
|         {
 | |
|             _EffectiveDataLabelStyle = new EffectiveStyle<DataLabelVisualStyle>(this);
 | |
|         }
 | |
| 
 | |
|         #endregion
 | |
| 
 | |
|         #region Public properties
 | |
| 
 | |
|         #region BarLabelPosition
 | |
| 
 | |
|         /// <summary>
 | |
|         /// Gets or sets the position of bar series labels.
 | |
|         /// </summary>
 | |
|         [DefaultValue(BarLabelPosition.NotSet), Category("Bar Display")]
 | |
|         [Description("Indicates the position of bar series labels.")]
 | |
|         public BarLabelPosition BarLabelPosition
 | |
|         {
 | |
|             get { return (_BarLabelPosition); }
 | |
|             set { _BarLabelPosition = value; }
 | |
|         }
 | |
| 
 | |
|         #endregion
 | |
| 
 | |
|         #region DataLabelVisualStyle
 | |
| 
 | |
|         /// <summary>
 | |
|         /// Gets or sets the visual style for the data label.
 | |
|         /// </summary>
 | |
|         [Category("Style")]
 | |
|         [Description("Indicates the visual style for the data label.")]
 | |
|         [DesignerSerializationVisibility(DesignerSerializationVisibility.Content)]
 | |
|         public DataLabelVisualStyle DataLabelVisualStyle
 | |
|         {
 | |
|             get
 | |
|             {
 | |
|                 if (_DataLabelVisualStyle == null)
 | |
|                 {
 | |
|                     _DataLabelVisualStyle = new DataLabelVisualStyle();
 | |
| 
 | |
|                     StyleVisualChangeHandler(null, _DataLabelVisualStyle);
 | |
|                 }
 | |
| 
 | |
|                 return (_DataLabelVisualStyle);
 | |
|             }
 | |
| 
 | |
|             set
 | |
|             {
 | |
|                 if (_DataLabelVisualStyle != value)
 | |
|                 {
 | |
|                     DataLabelVisualStyle oldValue = _DataLabelVisualStyle;
 | |
| 
 | |
|                     _DataLabelVisualStyle = value;
 | |
| 
 | |
|                     OnVisualStyleChanged("DataLabelVisualStyle", oldValue, value);
 | |
| 
 | |
|                     if (oldValue != null)
 | |
|                         oldValue.Dispose();
 | |
|                 }
 | |
|             }
 | |
|         }
 | |
| 
 | |
|         #endregion
 | |
| 
 | |
|         #region EffectiveDataLabelStyle
 | |
| 
 | |
|         /// <summary>
 | |
|         /// Gets a reference to the DataLabel effective (cached, composite) style.
 | |
|         /// </summary>
 | |
|         [Browsable(false)]
 | |
|         [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
 | |
|         [Description("Indicates a reference to the DataLabel effective (cached, composite) style.")]
 | |
|         public DataLabelVisualStyle EffectiveDataLabelStyle
 | |
|         {
 | |
|             get { return (_EffectiveDataLabelStyle.Style); }
 | |
|         }
 | |
| 
 | |
|         #endregion
 | |
| 
 | |
|         #region ValueX
 | |
| 
 | |
|         /// <summary>
 | |
|         /// Gets or sets the X-Axis Value.
 | |
|         /// </summary>
 | |
|         [Category("Data")]
 | |
|         [Description("Indicates the X-Axis Value.")]
 | |
|         [TypeConverter("DevComponents.Charts.Design.PointValueConverter, DevComponents.Charts.Design," +
 | |
|             "Version=14.1.0.37, Culture=neutral, PublicKeyToken=90f470f34c89ccaf")]
 | |
|         public object ValueX
 | |
|         {
 | |
|             get { return (_ValueX); }
 | |
|             set { _ValueX = value; }
 | |
|         }
 | |
| 
 | |
|         #endregion
 | |
| 
 | |
|         #region ValueY
 | |
| 
 | |
|         /// <summary>
 | |
|         /// Gets or sets the Y-Axis Value.
 | |
|         /// </summary>
 | |
|         [Category("Data")]
 | |
|         [Description("Indicates the Y-Axis Value.")]
 | |
|         [TypeConverter("DevComponents.Charts.Design.PointValueConverter, DevComponents.Charts.Design," +
 | |
|             "Version=14.1.0.37, Culture=neutral, PublicKeyToken=90f470f34c89ccaf")]
 | |
|         public object ValueY
 | |
|         {
 | |
|             get { return (_ValueY); }
 | |
|             set { _ValueY = value; }
 | |
|         }
 | |
| 
 | |
|         #endregion
 | |
| 
 | |
|         #region Text
 | |
| 
 | |
|         ///<summary>
 | |
|         /// Gets or sets the DataLabel text.
 | |
|         ///</summary>
 | |
|         [DefaultValue(null), Category("Appearance")]
 | |
|         [Description("Indicates the DataLabel text.")]
 | |
|         public string Text
 | |
|         {
 | |
|             get { return (_Text); }
 | |
| 
 | |
|             set
 | |
|             {
 | |
|                 _Text = value;
 | |
| 
 | |
|                 OnPropertyChangedEx("Text", VisualChangeType.Layout);
 | |
|             }
 | |
|         }
 | |
| 
 | |
|         #endregion
 | |
| 
 | |
|         #endregion
 | |
| 
 | |
|         #region MeasureOverride
 | |
| 
 | |
|         protected override void MeasureOverride(ChartLayoutInfo layoutInfo)
 | |
|         {
 | |
|         }
 | |
| 
 | |
|         #endregion
 | |
| 
 | |
|         #region ArrangeOverride
 | |
| 
 | |
|         protected override void ArrangeOverride(ChartLayoutInfo layoutInfo)
 | |
|         {
 | |
|         }
 | |
| 
 | |
|         #endregion
 | |
| 
 | |
|         #region RenderOverride
 | |
| 
 | |
|         protected override void RenderOverride(ChartRenderInfo renderInfo)
 | |
|         {
 | |
|         }
 | |
| 
 | |
|         #endregion
 | |
| 
 | |
|         #region Style handling
 | |
| 
 | |
|         #region ApplyStyles
 | |
| 
 | |
|         public override void ApplyStyles(BaseVisualStyle style)
 | |
|         {
 | |
|             DataLabelVisualStyle dstyle = style as DataLabelVisualStyle;
 | |
| 
 | |
|             if (dstyle != null)
 | |
|             {
 | |
|                 ChartSeries series = Parent as ChartSeries;
 | |
| 
 | |
|                 dstyle.ApplyStyle(series.EffectiveDataLabelStyle);
 | |
|                 dstyle.ApplyStyle(DataLabelVisualStyle);
 | |
|             }
 | |
|         }
 | |
| 
 | |
|         #endregion
 | |
| 
 | |
|         #region InvalidateStyle
 | |
| 
 | |
|         ///<summary>
 | |
|         ///Invalidate the cached Style definition
 | |
|         ///</summary>
 | |
|         public void InvalidateStyle()
 | |
|         {
 | |
|             ClearEffectiveStyles();
 | |
|         }
 | |
| 
 | |
|         #endregion
 | |
| 
 | |
|         #region ClearEffectiveStyles
 | |
| 
 | |
|         protected override void ClearEffectiveStyles()
 | |
|         {
 | |
|             if (_EffectiveDataLabelStyle.InvalidateStyle() == true)
 | |
|                 InvalidateLayout();
 | |
| 
 | |
|             ChartXy chartXy = ParentChartContainer as ChartXy;
 | |
| 
 | |
|             if (chartXy != null)
 | |
|                 chartXy.InvalidatePointLabels();
 | |
|         }
 | |
| 
 | |
|         #endregion
 | |
| 
 | |
|         #endregion
 | |
| 
 | |
|         #region Copy/CopyTo
 | |
| 
 | |
|         public override ChartVisualElement Copy()
 | |
|         {
 | |
|             DataLabel copy = new DataLabel();
 | |
| 
 | |
|             CopyTo(copy);
 | |
| 
 | |
|             return (copy);
 | |
|         }
 | |
| 
 | |
|         public override void CopyTo(ChartVisualElement copy)
 | |
|         {
 | |
|             DataLabel c = copy as DataLabel;
 | |
| 
 | |
|             if (c != null)
 | |
|             {
 | |
|                 base.CopyTo(c);
 | |
| 
 | |
|                 c.DataLabelVisualStyle =
 | |
|                     (_DataLabelVisualStyle != null) ? DataLabelVisualStyle.Copy() : null;
 | |
| 
 | |
|                 c.ValueX = ValueX;
 | |
|                 c.ValueY = ValueY;
 | |
| 
 | |
|                 c.Text = (Text != null) ? (string)Text.Clone() : null;
 | |
|             }
 | |
|         }
 | |
| 
 | |
|         #endregion
 | |
| 
 | |
|         #region GetSerialData
 | |
| 
 | |
|         internal override SerialElementCollection GetSerialData(string serialName)
 | |
|         {
 | |
|             SerialElementCollection sec = new SerialElementCollection();
 | |
| 
 | |
|             if (serialName != null)
 | |
|             {
 | |
|                 if (serialName.Equals("") == true)
 | |
|                     serialName = "DataLabel";
 | |
| 
 | |
|                 sec.AddStartElement(serialName);
 | |
|             }
 | |
| 
 | |
|             if (_DataLabelVisualStyle != null && _DataLabelVisualStyle.IsEmpty == false)
 | |
|                 sec.AddElement(_DataLabelVisualStyle.GetSerialData("DataLabelVisualStyle"));
 | |
| 
 | |
|             sec.AddDataValue("ValueX", ValueX, null);
 | |
|             sec.AddDataValue("ValueY", ValueY, null);
 | |
| 
 | |
|             sec.AddValue("Text", Text, null);
 | |
| 
 | |
|             sec.AddElement(base.GetSerialData(null));
 | |
| 
 | |
|             if (serialName != null)
 | |
|                 sec.AddEndElement(serialName);
 | |
| 
 | |
|             return (sec);
 | |
|         }
 | |
| 
 | |
|         #endregion
 | |
| 
 | |
|         #region PutSerialData
 | |
| 
 | |
|         #region ProcessValue
 | |
| 
 | |
|         internal override void ProcessValue(SerialElement se)
 | |
|         {
 | |
|             switch (se.Name)
 | |
|             {
 | |
|                 case "ValueX":
 | |
|                     ValueX = se.DataValue;
 | |
|                     break;
 | |
| 
 | |
|                 case "ValueY":
 | |
|                     ValueY = se.DataValue;
 | |
|                     break;
 | |
| 
 | |
|                 case "Text":
 | |
|                     Text = se.StringValue;
 | |
|                     break;
 | |
| 
 | |
|                 default:
 | |
|                     base.ProcessValue(se);
 | |
|                     break;
 | |
|             }
 | |
|         }
 | |
| 
 | |
|         #endregion
 | |
| 
 | |
|         #region ProcessCollection
 | |
| 
 | |
|         internal override void ProcessCollection(SerialElement se)
 | |
|         {
 | |
|             SerialElementCollection sec = se.Sec;
 | |
| 
 | |
|             switch (se.Name)
 | |
|             {
 | |
|                 case "DataLabelVisualStyle":
 | |
|                     sec.PutSerialData(DataLabelVisualStyle);
 | |
|                     break;
 | |
| 
 | |
|                 default:
 | |
|                     base.ProcessCollection(se);
 | |
|                     break;
 | |
|             }
 | |
|         }
 | |
| 
 | |
|         #endregion
 | |
| 
 | |
|         #endregion
 | |
| 
 | |
|         #region IDisposable
 | |
| 
 | |
|         public override void Dispose()
 | |
|         {
 | |
|             DataLabelVisualStyle = null;
 | |
| 
 | |
|             base.Dispose();
 | |
|         }
 | |
| 
 | |
|         #endregion
 | |
|     }
 | |
| }
 |