405 lines
		
	
	
		
			10 KiB
		
	
	
	
		
			C#
		
	
	
	
	
	
			
		
		
	
	
			405 lines
		
	
	
		
			10 KiB
		
	
	
	
		
			C#
		
	
	
	
	
	
using System;
 | 
						|
using System.Collections.Generic;
 | 
						|
using System.ComponentModel;
 | 
						|
using System.Drawing;
 | 
						|
using System.Drawing.Design;
 | 
						|
using System.Drawing.Drawing2D;
 | 
						|
using System.Windows.Forms;
 | 
						|
using DevComponents.Charts.TextMarkup;
 | 
						|
using DevComponents.DotNetBar.Charts.Style;
 | 
						|
 | 
						|
namespace DevComponents.DotNetBar.Charts
 | 
						|
{
 | 
						|
    /// <summary>
 | 
						|
    /// Represents the collection of PieReferenceLines.
 | 
						|
    /// </summary>
 | 
						|
    [Editor("DevComponents.Charts.Design.PieReferenceCollectionEditor, DevComponents.Charts.Design, " +
 | 
						|
            "Version=14.1.0.37, Culture=neutral,  PublicKeyToken=90f470f34c89ccaf", typeof(UITypeEditor))]
 | 
						|
    public class PieReferenceLineCollection : CustomNamedCollection<PieReferenceLine>
 | 
						|
    {
 | 
						|
        #region GetUniqueName
 | 
						|
 | 
						|
        /// <summary>
 | 
						|
        /// Gets a unique (unused) reference line Name.
 | 
						|
        /// </summary>
 | 
						|
        /// <returns></returns>
 | 
						|
        public string GetUniqueName()
 | 
						|
        {
 | 
						|
            return (GetUniqueName("PieRefLine"));
 | 
						|
        }
 | 
						|
 | 
						|
        #endregion
 | 
						|
    }
 | 
						|
 | 
						|
    /// <summary>
 | 
						|
    /// Represents a reference line (a radial line on the chart
 | 
						|
    /// that can be used to signify, or reference, a specific chart value).
 | 
						|
    /// </summary>
 | 
						|
    public class PieReferenceLine : ChartVisualElement
 | 
						|
    {
 | 
						|
        #region Private variables
 | 
						|
 | 
						|
        private double _Value;
 | 
						|
 | 
						|
        private PieReferenceLineVisualStyle _ReferenceLineVisualStyle;
 | 
						|
        private EffectiveStyle<PieReferenceLineVisualStyle> _EffectiveStyle;
 | 
						|
 | 
						|
        #endregion
 | 
						|
 | 
						|
        #region Constructors
 | 
						|
 | 
						|
        /// <summary>
 | 
						|
        /// PieReferenceLine
 | 
						|
        /// </summary>
 | 
						|
        public PieReferenceLine()
 | 
						|
        {
 | 
						|
            _EffectiveStyle = new EffectiveStyle<PieReferenceLineVisualStyle>(this);
 | 
						|
        }
 | 
						|
 | 
						|
        /// <summary>
 | 
						|
        /// PieReferenceLine
 | 
						|
        /// </summary>
 | 
						|
        /// <param name="name"></param>
 | 
						|
        public PieReferenceLine(string name)
 | 
						|
            : this()
 | 
						|
        {
 | 
						|
            Name = name;
 | 
						|
        }
 | 
						|
 | 
						|
        /// <summary>
 | 
						|
        /// PieReferenceLine
 | 
						|
        /// </summary>
 | 
						|
        /// <param name="name"></param>
 | 
						|
        /// <param name="radialValue"></param>
 | 
						|
        public PieReferenceLine(string name, double value)
 | 
						|
            : this(name)
 | 
						|
        {
 | 
						|
            Value = value;
 | 
						|
        }
 | 
						|
 | 
						|
        #endregion
 | 
						|
 | 
						|
        #region Public properties
 | 
						|
 | 
						|
        #region EffectiveStyle
 | 
						|
 | 
						|
        /// <summary>
 | 
						|
        /// Gets a reference to the ReferenceLine's Effective (cached, composite) style.
 | 
						|
        /// </summary>
 | 
						|
        [Browsable(false)]
 | 
						|
        [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
 | 
						|
        public PieReferenceLineVisualStyle EffectiveStyle
 | 
						|
        {
 | 
						|
            get { return (_EffectiveStyle.Style); }
 | 
						|
        }
 | 
						|
 | 
						|
        #endregion
 | 
						|
 | 
						|
        #region ReferenceLineVisualStyle
 | 
						|
 | 
						|
        /// <summary>
 | 
						|
        /// Gets or sets the visual style for the Reference Line.
 | 
						|
        /// </summary>
 | 
						|
        [Category("Style")]
 | 
						|
        [Description("Indicates the visual style for the ReferenceLine.")]
 | 
						|
        [DesignerSerializationVisibility(DesignerSerializationVisibility.Content)]
 | 
						|
        public PieReferenceLineVisualStyle ReferenceLineVisualStyle
 | 
						|
        {
 | 
						|
            get
 | 
						|
            {
 | 
						|
                if (_ReferenceLineVisualStyle == null)
 | 
						|
                {
 | 
						|
                    _ReferenceLineVisualStyle = new PieReferenceLineVisualStyle();
 | 
						|
 | 
						|
                    StyleVisualChangeHandler(null, _ReferenceLineVisualStyle);
 | 
						|
                }
 | 
						|
 | 
						|
                return (_ReferenceLineVisualStyle);
 | 
						|
            }
 | 
						|
 | 
						|
            set
 | 
						|
            {
 | 
						|
                if (_ReferenceLineVisualStyle != value)
 | 
						|
                {
 | 
						|
                    PieReferenceLineVisualStyle oldValue = _ReferenceLineVisualStyle;
 | 
						|
 | 
						|
                    _ReferenceLineVisualStyle = value;
 | 
						|
 | 
						|
                    OnVisualStyleChanged("ReferenceLineVisualStyle", oldValue, value);
 | 
						|
 | 
						|
                    if (oldValue != null)
 | 
						|
                        oldValue.Dispose();
 | 
						|
                }
 | 
						|
            }
 | 
						|
        }
 | 
						|
 | 
						|
        #endregion
 | 
						|
 | 
						|
        #region  Value
 | 
						|
 | 
						|
        ///<summary>
 | 
						|
        /// Gets or sets the associated radial grid value of the reference line.
 | 
						|
        ///</summary>
 | 
						|
        [DefaultValue(null), Category("Appearance")]
 | 
						|
        [Description("Indicates the associated radial grid value of the reference line.")]
 | 
						|
        //[TypeConverter("DevComponents.Charts.Design.PointValueConverter," +
 | 
						|
        //    "DevComponents.Charts.Design, Version=14.1.0.37, Culture=neutral, PublicKeyToken=90f470f34c89ccaf")]
 | 
						|
        public double Value
 | 
						|
        {
 | 
						|
            get { return (_Value); }
 | 
						|
 | 
						|
            set
 | 
						|
            {
 | 
						|
                if (value != _Value)
 | 
						|
                {
 | 
						|
                    _Value = value;
 | 
						|
 | 
						|
                    OnPropertyChangedEx("Value", VisualChangeType.Render);
 | 
						|
                }
 | 
						|
            }
 | 
						|
        }
 | 
						|
 | 
						|
        #endregion
 | 
						|
 | 
						|
        #endregion
 | 
						|
 | 
						|
        #region Internal properties
 | 
						|
 | 
						|
        #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)
 | 
						|
        {
 | 
						|
        }
 | 
						|
 | 
						|
        #region RenderLine
 | 
						|
 | 
						|
        internal void RenderLine(ChartRenderInfo renderInfo)
 | 
						|
        {
 | 
						|
        }
 | 
						|
 | 
						|
        #endregion
 | 
						|
 | 
						|
        #endregion
 | 
						|
 | 
						|
        #region InvalidateRender
 | 
						|
 | 
						|
        public override void InvalidateRender()
 | 
						|
        {
 | 
						|
            ChartVisualElement cve = Parent as ChartVisualElement;
 | 
						|
 | 
						|
            if (cve != null)
 | 
						|
                cve.InvalidateRender();
 | 
						|
            else
 | 
						|
                base.InvalidateRender();
 | 
						|
        }
 | 
						|
 | 
						|
        #endregion
 | 
						|
 | 
						|
        #region Style handling
 | 
						|
 | 
						|
        #region ApplyStyles
 | 
						|
 | 
						|
        public override void ApplyStyles(BaseVisualStyle style)
 | 
						|
        {
 | 
						|
            ChartLineVisualStyle rstyle = style as ChartLineVisualStyle;
 | 
						|
 | 
						|
            if (rstyle != null)
 | 
						|
            {
 | 
						|
                ApplyParentStyles(rstyle, Parent as ChartContainer);
 | 
						|
 | 
						|
                rstyle.ApplyStyle(ReferenceLineVisualStyle);
 | 
						|
 | 
						|
                if (rstyle.LineColor.IsEmpty == true)
 | 
						|
                    rstyle.LineColor = Color.Red;
 | 
						|
 | 
						|
                if (rstyle.LineWidth < 0)
 | 
						|
                    rstyle.LineWidth = 1;
 | 
						|
            }
 | 
						|
        }
 | 
						|
 | 
						|
        #region ApplyParentStyles
 | 
						|
 | 
						|
        private void ApplyParentStyles(ChartLineVisualStyle pstyle, ChartContainer item)
 | 
						|
        {
 | 
						|
            if (item != null)
 | 
						|
            {
 | 
						|
                ApplyParentStyles(pstyle, item.Parent as ChartContainer);
 | 
						|
 | 
						|
                ChartPanel chartPanel = item as ChartPanel;
 | 
						|
 | 
						|
                if (chartPanel != null)
 | 
						|
                {
 | 
						|
                    pstyle.ApplyStyle(chartPanel.DefaultVisualStyles.PieChartVisualStyle.ReferenceLineVisualStyle);
 | 
						|
                }
 | 
						|
                else if (item is PieChart)
 | 
						|
                {
 | 
						|
                    PieChart pieChart = (PieChart)item;
 | 
						|
 | 
						|
                    pstyle.ApplyStyle(pieChart.ChartVisualStyle.ReferenceLineVisualStyle);
 | 
						|
                }
 | 
						|
            }
 | 
						|
            else
 | 
						|
            {
 | 
						|
                pstyle.ApplyStyle(ChartControl.BaseVisualStyles.ReferenceLineVisualStyle);
 | 
						|
                pstyle.ApplyStyle(ChartControl.DefaultVisualStyles.ReferenceLineVisualStyle);
 | 
						|
            }
 | 
						|
        }
 | 
						|
 | 
						|
        #endregion
 | 
						|
 | 
						|
        #endregion
 | 
						|
 | 
						|
        #region InvalidateStyle
 | 
						|
 | 
						|
        ///<summary>
 | 
						|
        ///Invalidate the cached Style definition
 | 
						|
        ///</summary>
 | 
						|
        public void InvalidateStyle()
 | 
						|
        {
 | 
						|
            ClearEffectiveStyles();
 | 
						|
        }
 | 
						|
 | 
						|
        #endregion
 | 
						|
 | 
						|
        #region ClearEffectiveStyles
 | 
						|
 | 
						|
        protected override void ClearEffectiveStyles()
 | 
						|
        {
 | 
						|
            if (_EffectiveStyle.InvalidateStyle() == true)
 | 
						|
                InvalidateLayout();
 | 
						|
        }
 | 
						|
 | 
						|
        #endregion
 | 
						|
 | 
						|
        #endregion
 | 
						|
 | 
						|
        #region Copy/CopyTo
 | 
						|
 | 
						|
        public override ChartVisualElement Copy()
 | 
						|
        {
 | 
						|
            PieReferenceLine copy = new PieReferenceLine();
 | 
						|
 | 
						|
            CopyTo(copy);
 | 
						|
 | 
						|
            return (copy);
 | 
						|
        }
 | 
						|
 | 
						|
        public override void CopyTo(ChartVisualElement copy)
 | 
						|
        {
 | 
						|
            PieReferenceLine c = copy as PieReferenceLine;
 | 
						|
 | 
						|
            if (c != null)
 | 
						|
            {
 | 
						|
                base.CopyTo(c);
 | 
						|
 | 
						|
                c.Value = Value;
 | 
						|
 | 
						|
                c.ReferenceLineVisualStyle =
 | 
						|
                    (_ReferenceLineVisualStyle != null) ? ReferenceLineVisualStyle.Copy() : null;
 | 
						|
            }
 | 
						|
        }
 | 
						|
 | 
						|
        #endregion
 | 
						|
 | 
						|
        #region GetSerialData
 | 
						|
 | 
						|
        internal override SerialElementCollection GetSerialData(string serialName)
 | 
						|
        {
 | 
						|
            SerialElementCollection sec = new SerialElementCollection();
 | 
						|
 | 
						|
            if (serialName != null)
 | 
						|
            {
 | 
						|
                if (serialName.Equals("") == true)
 | 
						|
                    serialName = "PieReferenceLine";
 | 
						|
 | 
						|
                sec.AddStartElement(serialName);
 | 
						|
            }
 | 
						|
 | 
						|
            if (_ReferenceLineVisualStyle != null && _ReferenceLineVisualStyle.IsEmpty == false)
 | 
						|
                sec.AddElement(_ReferenceLineVisualStyle.GetSerialData("ReferenceLineVisualStyle"));
 | 
						|
 | 
						|
            sec.AddValue("Value", Value, 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 "Value":
 | 
						|
                    Value = double.Parse(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 "ReferenceLineVisualStyle":
 | 
						|
                    sec.PutSerialData(ReferenceLineVisualStyle);
 | 
						|
                    break;
 | 
						|
 | 
						|
                default:
 | 
						|
                    base.ProcessCollection(se);
 | 
						|
                    break;
 | 
						|
            }
 | 
						|
        }
 | 
						|
 | 
						|
        #endregion
 | 
						|
 | 
						|
        #endregion
 | 
						|
 | 
						|
        #region IDisposable
 | 
						|
 | 
						|
        public override void Dispose()
 | 
						|
        {
 | 
						|
            ReferenceLineVisualStyle = null;
 | 
						|
 | 
						|
            base.Dispose();
 | 
						|
        }
 | 
						|
 | 
						|
        #endregion
 | 
						|
    }
 | 
						|
}
 |