123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757 |
- // Licensed to the .NET Foundation under one or more agreements.
- // The .NET Foundation licenses this file to you under the MIT license.
- // See the LICENSE file in the project root for more information.
- //
- // Purpose: Each chart area contains four main axes PrimaryX,
- // PrimaryY, SecondaryX and SecondaryY which are usually
- // positioned on each side of the plotting area. Most of
- // the charts use only two axes; X and Y, but for some
- // charts even 4 axes is not sufficient. Sub-axes were
- // introduced to proSUBACESvide unlimited number of axes in
- // the chart.
- // Each main axis has a collection of SubAxis which is
- // empty by default. By adding SubAxis into this collection
- // user can add unlimited number of sub-axis which will
- // be positioned next to the main axis.
- // Each of the SubAxis have a unique name. To associate
- // data series with a sub axis YSubAxisName and XSubAxisName
- // properties of the Series should be used.
- //
- #if SUBAXES
- using System;
- using System.Globalization;
- using System.Reflection;
- using System.Collections;
- using System.Collections.Specialized;
- using System.ComponentModel;
- using System.ComponentModel.Design;
- using System.ComponentModel.Design.Serialization;
- using System.Data;
- using System.Drawing;
- using System.Drawing.Design;
- using System.Drawing.Text;
- using System.Drawing.Drawing2D;
- using FastReport.DataVisualization.Charting;
- using FastReport.DataVisualization.Charting.Data;
- using FastReport.DataVisualization.Charting.ChartTypes;
- using FastReport.DataVisualization.Charting.Utilities;
- using FastReport.DataVisualization.Charting.Borders3D;
- using FastReport.DataVisualization.Charting;
- namespace FastReport.DataVisualization.Charting
- {
- /// <summary>
- /// SubAxis class is derived from the main Axis class and provides
- /// additional axis associated with one of the main chart axis.
- /// </summary>
- [
- SRDescription("DescriptionAttributeSubAxis_SubAxis"),
- DefaultProperty("Enabled"),
- TypeConverter(typeof(SubAxis.SubAxisConverter)),
- ]
- public class SubAxis : Axis
- {
- #region Fields
- /// <summary>
- /// Sub-Axis parent axis object.
- /// </summary>
- internal Axis parentAxis = null;
- /// <summary>
- /// Sub axis offset from the parent axis
- /// </summary>
- internal double offsetFromParent = 0.0;
- /// <summary>
- /// Margin between prev. axis
- /// </summary>
- internal double locationOffset = 0.0;
- #endregion // Fields
- #region Constructor
- /// <summary>
- /// Default constructor
- /// </summary>
- public SubAxis() : base()
- {
- base.Name = string.Empty;
- }
- /// <summary>
- /// Object constructor.
- /// </summary>
- /// <param name="name">Unique name of the object.</param>
- public SubAxis(string name) : base()
- {
- base.Name = name;
- }
- #endregion
- #region Properties
- /// <summary>
- /// Axis automatic scale breaks style.
- /// </summary>
- [
- Browsable(false),
- EditorBrowsable(EditorBrowsableState.Never),
- SRCategory("CategoryAttributeScale"),
- SRDescription("DescriptionAttributeScaleBreakStyle"),
- TypeConverter(typeof(NoNameExpandableObjectConverter)),
- NotifyParentPropertyAttribute(true),
- DesignerSerializationVisibility(DesignerSerializationVisibility.Content),
- ]
- override public AxisScaleBreakStyle ScaleBreakStyle
- {
- get
- {
- return base.ScaleBreakStyle;
- }
- set
- {
- base.ScaleBreakStyle = value;
- }
- }
- /// <summary>
- /// Sub axis parent axis.
- /// </summary>
- [
- SRCategory("CategoryAttributeAxis"),
- Bindable(true),
- Browsable(false),
- DefaultValue(null),
- NotifyParentPropertyAttribute(true),
- SRDescription("DescriptionAttributeSubAxis_ParentAxis"),
- DesignerSerializationVisibilityAttribute(DesignerSerializationVisibility.Hidden),
- SerializationVisibilityAttribute(SerializationVisibility.Hidden)
- ]
- public Axis ParentAxis
- {
- get
- {
- return this.parentAxis;
- }
- }
- /// <summary>
- /// Sub axis location offset relative to the previous axis.
- /// </summary>
- [
- SRCategory("CategoryAttributeLocation"),
- Bindable(true),
- DefaultValue(0.0),
- NotifyParentPropertyAttribute(true),
- SRDescription("DescriptionAttributeSubAxis_LocationOffset"),
- ]
- public double LocationOffset
- {
- get
- {
- return this.locationOffset;
- }
- set
- {
- this.locationOffset = value;
- this.Invalidate();
- }
- }
- /// <summary>
- /// Axis position
- /// </summary>
- [
- Bindable(true),
- Browsable(false),
- DefaultValue(AxisPosition.Left),
- NotifyParentPropertyAttribute(true),
- SRDescription("DescriptionAttributeReverse"),
- DesignerSerializationVisibilityAttribute(DesignerSerializationVisibility.Hidden),
- SerializationVisibilityAttribute(SerializationVisibility.Hidden)
- ]
- override internal AxisPosition AxisPosition
- {
- get
- {
- if(this.parentAxis != null)
- {
- return this.parentAxis.AxisPosition;
- }
- return AxisPosition.Left;
- }
- set
- {
- }
- }
- /// <summary>
- /// SubAxis name.
- /// </summary>
- [
- SRCategory("CategoryAttributeAppearance"),
- Bindable(true),
- Browsable(true),
- DefaultValue(""),
- SRDescription("DescriptionAttributeSubAxis_Name"),
- DesignerSerializationVisibilityAttribute(DesignerSerializationVisibility.Visible),
- SerializationVisibilityAttribute(SerializationVisibility.Attribute)
- ]
- override public string Name
- {
- get
- {
- return base.Name;
- }
- set
- {
- base.Name = value;
- }
- }
- /// <summary>
- /// Tick marks and labels move with axis when
- /// the crossing value is changed.
- /// </summary>
- [
- SRCategory("CategoryAttributeAppearance"),
- Browsable(false),
- EditorBrowsable(EditorBrowsableState.Never),
- Bindable(true),
- DefaultValue(true),
- SRDescription("DescriptionAttributeMarksNextToAxis"),
- NotifyParentPropertyAttribute(true),
- DesignerSerializationVisibilityAttribute(DesignerSerializationVisibility.Hidden),
- SerializationVisibilityAttribute(SerializationVisibility.Hidden)
- ]
- override public bool IsMarksNextToAxis
- {
- get
- {
- return base.IsMarksNextToAxis;
- }
- set
- {
- base.IsMarksNextToAxis = value;
- }
- }
- /// <summary>
- /// Point where axis is crossed by another axis.
- /// </summary>
- [
- SRCategory("CategoryAttributeScale"),
- Browsable(false),
- EditorBrowsable(EditorBrowsableState.Never),
- Bindable(true),
- DefaultValue(Double.NaN),
- NotifyParentPropertyAttribute(true),
- SRDescription("DescriptionAttributeCrossing"),
- TypeConverter(typeof(AxisCrossingValueConverter)),
- DesignerSerializationVisibilityAttribute(DesignerSerializationVisibility.Hidden),
- SerializationVisibilityAttribute(SerializationVisibility.Hidden)
- ]
- override public double Crossing
- {
- get
- {
- return base.Crossing;
- }
- set
- {
- base.Crossing = value;
- }
- }
- /// <summary>
- /// Sub-axes collection.
- /// </summary>
- [
- SRCategory("CategoryAttributeSubAxes"),
- Browsable(false),
- EditorBrowsable(EditorBrowsableState.Never),
- Bindable(true),
- SRDescription("DescriptionAttributeSubAxes"),
- Editor(Editors.ChartCollectionEditor.Editor, Editors.ChartCollectionEditor.Base),
- DesignerSerializationVisibilityAttribute(DesignerSerializationVisibility.Hidden),
- SerializationVisibilityAttribute(SerializationVisibility.Hidden),
- ]
- override public SubAxisCollection SubAxes
- {
- get
- {
- return base.SubAxes;
- }
- }
- /// <summary>
- /// Indicates if this axis object present the main or sub axis.
- /// </summary>
- override internal bool IsSubAxis
- {
- get
- {
- return true;
- }
- }
- /// <summary>
- /// Returns sub-axis name.
- /// </summary>
- override internal string SubAxisName
- {
- get
- {
- return base.Name;
- }
- }
- #endregion // Properties
- #region Methods
- /// <summary>
- /// Find axis position using crossing value.
- /// </summary>
- /// <param name="ignoreCrossing">Axis crossing should be ignored.</param>
- /// <returns>Relative position</returns>
- override internal double GetAxisPosition(bool ignoreCrossing)
- {
- // Parent axis must be set
- if(this.parentAxis != null)
- {
- // Get position of the parent axis
- double position = this.parentAxis.GetAxisPosition(ignoreCrossing);
- // Addjust parent position by the offset
- if(this.parentAxis.AxisPosition == AxisPosition.Left)
- {
- position -= this.offsetFromParent;
- }
- else if(this.parentAxis.AxisPosition == AxisPosition.Right)
- {
- position += this.offsetFromParent;
- }
- else if(this.parentAxis.AxisPosition == AxisPosition.Top)
- {
- position -= this.offsetFromParent;
- }
- else if(this.parentAxis.AxisPosition == AxisPosition.Bottom)
- {
- position += this.offsetFromParent;
- }
- return position;
- }
- return 0.0;
- }
- #endregion // Methods
- #region Type converter
- #if WINFORMS_CONTROL
- internal class SubAxisConverter : TypeConverter
- {
- /// <summary>
- /// This method overrides CanConvertTo from TypeConverter. This is called when someone
- /// wants to convert an instance of object to another type. Here,
- /// only conversion to an InstanceDescriptor is supported.
- /// </summary>
- /// <param name="context">Descriptor context.</param>
- /// <param name="destinationType">Destination type.</param>
- /// <returns>True if object can be converted.</returns>
- public override bool CanConvertTo(ITypeDescriptorContext context, Type destinationType)
- {
- if (destinationType == typeof(InstanceDescriptor))
- {
- return true;
- }
- // Always call the base to see if it can perform the conversion.
- return base.CanConvertTo(context, destinationType);
- }
- /// <summary>
- /// This code performs the actual conversion from an object to an InstanceDescriptor.
- /// </summary>
- /// <param name="context">Descriptor context.</param>
- /// <param name="culture">Culture information.</param>
- /// <param name="value">Object value.</param>
- /// <param name="destinationType">Destination type.</param>
- /// <returns>Converted object.</returns>
- public override object ConvertTo(ITypeDescriptorContext context, CultureInfo culture, object value, Type destinationType)
- {
- if (destinationType == typeof(InstanceDescriptor))
- {
- ConstructorInfo ci = typeof(SubAxis).GetConstructor(System.Type.EmptyTypes);
- return new InstanceDescriptor(ci, null, false);
- }
- // Always call base, even if you can't convert.
- return base.ConvertTo(context, culture, value, destinationType);
- }
- }
- #endif //#if WINFORMS_CONTROL
- #endregion
- }
- /// <summary>
- /// <b>SubAxisCollection</b> is a strongly typed collection of chart sub-axes objects.
- /// Collection indexer can accept sub-axis index or it's unique name as a parameter.
- /// </summary>
- [
- SRDescription("DescriptionAttributeSubAxisCollection_SubAxisCollection"),
- ]
- public class SubAxisCollection : CollectionBase
- {
- #region Fields
- /// <summary>
- /// Sub-Axis parent axis object.
- /// </summary>
- internal Axis parentAxis = null;
- #endregion
- #region Construction and Initialization
- /// <summary>
- /// Default public constructor.
- /// </summary>
- /// <remarks>
- /// This constructor is for internal use and should not be part of documentation.
- /// </remarks>
- public SubAxisCollection()
- {
- this.parentAxis = null;
- }
- /// <summary>
- /// Public constructor.
- /// </summary>
- /// <param name="parentAxis">
- /// Chart <see cref="Axis"/> object.
- /// </param>
- /// <remarks>
- /// This constructor is for the internal use and should not be part of documentation.
- /// </remarks>
- internal SubAxisCollection(Axis parentAxis)
- {
- this.parentAxis = parentAxis;
- }
- #endregion
- #region Indexer
- /// <summary>
- /// SubAxis collection indexer.
- /// </summary>
- /// <remarks>
- /// The <b>SubAxis</b> object's name or index can be provided as a parameter. Returns the <see cref="SubAxis"/> object.
- /// Make sure to cast the SubAxis to it's type (e.g. LineSubAxis) to access type
- /// specific properties.
- /// </remarks>
- [
- SRDescription("DescriptionAttributeSubAxisCollection_Item"),
- ]
- public SubAxis this[object parameter]
- {
- get
- {
- // Get SubAxis by index
- if(parameter is int)
- {
- return (SubAxis)this.List[(int)parameter];
- }
- // Get SubAxis by name
- else if(parameter is string)
- {
- // Find SubAxis with specified name
- foreach(SubAxis SubAxis in this.List)
- {
- if(SubAxis.Name == (string)parameter)
- {
- return SubAxis;
- }
- }
- // SubAxis with specified name was not found
- throw(new ArgumentException( SR.ExceptionSubAxisNameNotFound( (string)parameter ) ) );
- }
- // Invalid type of the indexer argument
- throw(new ArgumentException(SR.ExceptionInvalidIndexerArgumentType));
- }
- set
- {
- // Check new SubAxis name
- int indexSubAxis = -1;
- if(value.Name.Length != 0)
- {
- indexSubAxis = this.List.IndexOf(value);
- }
- else
- {
- AssignUniqueName(value);
- }
- // Set using index in the collection
- if(parameter is int)
- {
- // Check if SubAxis with this name already exists
- if( indexSubAxis != -1 && indexSubAxis != (int)parameter)
- {
- throw( new ArgumentException( SR.ExceptionSubAxisNameAlreadyExistsInCollection( value.Name ) ) );
- }
- this.List[(int)parameter] = value;
- }
- // Set using name in the collection
- else if(parameter is string)
- {
- // Find legend with specified name
- int index = 0;
- foreach(SubAxis SubAxis in this.List)
- {
- if(SubAxis.Name == (string)parameter)
- {
- // Check if SubAxis with this name already exists
- if( indexSubAxis != -1 && indexSubAxis != index)
- {
- throw( new ArgumentException( SR.ExceptionSubAxisNameAlreadyExistsInCollection( value.Name ) ) );
- }
- this.List[index] = value;
- break;
- }
- ++index;
- }
- }
- else
- {
- throw(new ArgumentException(SR.ExceptionInvalidIndexerArgumentType));
- }
- this.Invalidate();
- }
- }
- #endregion
- #region Collection Add and Insert methods
- /// <summary>
- /// Removes the SubAxis with the specified name from the collection.
- /// </summary>
- /// <param name="name">
- /// Name of the SubAxis to be removed.
- /// </param>
- public void Remove(string name)
- {
- SubAxis axis = FindByName(name);
- if(axis != null)
- {
- this.List.Remove(axis);
- }
- }
- /// <summary>
- /// Removes the given SubAxis from the collection.
- /// </summary>
- /// <param name="SubAxis">
- /// <see cref="SubAxis"/> object to be removed.
- /// </param>
- public void Remove(SubAxis SubAxis)
- {
- if(SubAxis != null)
- {
- this.List.Remove(SubAxis);
- }
- }
- /// <summary>
- /// Adds a SubAxis to the end of the collection.
- /// </summary>
- /// <param name="SubAxis">
- /// <see cref="SubAxis"/> object to add.
- /// </param>
- /// <returns>
- /// Index of the newly added object.
- /// </returns>
- public int Add(SubAxis SubAxis)
- {
- return this.List.Add(SubAxis);
- }
- /// <summary>
- /// Inserts a SubAxis into the collection.
- /// </summary>
- /// <param name="index">
- /// Index to insert the object at.
- /// </param>
- /// <param name="SubAxis">
- /// <see cref="SubAxis"/> object to insert.
- /// </param>
- public void Insert(int index, SubAxis SubAxis)
- {
- this.List.Insert(index, SubAxis);
- }
- #endregion
- #region Items Inserting and Removing Notification methods
- /// <summary>
- /// Called before the new item is inserted.
- /// </summary>
- /// <param name="index">Item index.</param>
- /// <param name="value">Item object.</param>
- /// <remarks>
- /// This is an internal method and should not be part of the documentation.
- /// </remarks>
- protected override void OnInsert(int index, object value)
- {
- // Check SubAxis object name
- if( ((SubAxis)value).Name.Length == 0 )
- {
- AssignUniqueName((SubAxis)value);
- }
- else
- {
- if(this.FindByName(((SubAxis)value).Name) != null)
- {
- throw(new InvalidOperationException(SR.ExceptionSubAxisNameIsNotUnique( ((SubAxis)value).Name )));
- }
- }
- }
- /// <summary>
- /// After new item inserted.
- /// </summary>
- /// <param name="index">Item index.</param>
- /// <param name="value">Item object.</param>
- /// <remarks>
- /// This is an internal method and should not be part of the documentation.
- /// </remarks>
- protected override void OnInsertComplete(int index, object value)
- {
- // Set SubAxis parent axis reference
- SubAxis subAxis = (SubAxis)value;
- subAxis.parentAxis = this.parentAxis;
- if(this.parentAxis != null)
- {
- subAxis.chart = this.parentAxis.chart;
- subAxis.Common = this.parentAxis.Common;
- subAxis.chartArea = this.parentAxis.chartArea;
- subAxis.axisType= this.parentAxis.axisType;
- subAxis.AxisPosition= this.parentAxis.AxisPosition;
- }
- this.Invalidate();
- }
- /// <summary>
- /// After item removed.
- /// </summary>
- /// <param name="index">Item index.</param>
- /// <param name="value">Item object.</param>
- /// <remarks>
- /// This is an internal method and should not be part of the documentation.
- /// </remarks>
- protected override void OnRemoveComplete(int index, object value)
- {
- // Reset SubAxis parent axis reference
- ((SubAxis)value).parentAxis = null;
- this.Invalidate();
- }
- /// <summary>
- /// After all items removed.
- /// </summary>
- /// <remarks>
- /// This is an internal method and should not be part of the documentation.
- /// </remarks>
- protected override void OnClearComplete()
- {
- this.Invalidate();
- }
- #endregion
- #region Helper Methods
- /// <summary>
- /// Invalidates chart the collection belongs to.
- /// </summary>
- private void Invalidate()
- {
- #if WINFORMS_CONTROL
- if(this.parentAxis != null && this.parentAxis.chart != null)
- {
- this.parentAxis.chart.dirtyFlag = true;
- this.parentAxis.chart.Invalidate();
- }
- #endif
- }
- /// <summary>
- /// Assigns a unique name to the SubAxis object based on it's type.
- /// </summary>
- /// <param name="SubAxis">SubAxis object to be named.</param>
- internal void AssignUniqueName(SubAxis SubAxis)
- {
- // Generate name using SubAxis type name and unique index
- string name = string.Empty;
- int index = 1;
- do
- {
- name = "SubAxis" + index.ToString();
- ++index;
- } while(this.FindByName(name) != null && index < 10000 );
- // Asign unique name;
- SubAxis.Name = name;
- }
-
- /// <summary>
- /// Finds SubAxis by name.
- /// </summary>
- /// <param name="name">Name of the chart SubAxis.</param>
- /// <returns>SubAxis or null if it does not exist.</returns>
- internal SubAxis FindByName(string name)
- {
- SubAxis result = null;
- for(int index = 0; index < this.List.Count; index ++)
- {
- // Compare SubAxis name
- if(String.Compare(this[index].Name, name, true, System.Globalization.CultureInfo.CurrentCulture) == 0)
- {
- result = this[index];
- break;
- }
- }
- return result;
- }
- #endregion
- }
- }
- #endif // SUBAXES
|