123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737 |
- // 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: AxisScaleView class represents a data scaleView, and is
- // exposed using the Axis.ScaleView property. A data scaleView is
- // a "scaleView" of data that has a start position (represented
- // by the Position property) and a size (represented by
- // the Size property).
- // Axis data scaleView is used in zooming and scrolling when
- // only part of the data must be visible. Views always
- // belong to an axis, and a scaleView can result from either
- // user interaction or by calling the Zoom or Scroll
- // methods. User interaction, accomplished using range
- // selection along an axis using the mouse, is possible
- // if the IsUserSelectionEnabled property of the chart area'
- // s cursor property is set to true. The end-user selects
- // a range by left-clicking the mouse and dragging the
- // mouse, and when the mouse button is released the
- // selected range is then displayed as a scaleView.
- //
- using System;
- using System.Collections;
- using System.ComponentModel;
- using System.Diagnostics.CodeAnalysis;
- using System.Globalization;
- using FastReport.DataVisualization.Charting.Utilities;
- namespace FastReport.DataVisualization.Charting
- {
- #region Scrolling enumerations
- /// <summary>
- /// Scrolling type enumeration.
- /// </summary>
- public enum ScrollType
- {
- /// <summary>
- /// Scrolls by substracting one small size.
- /// </summary>
- SmallDecrement,
- /// <summary>
- /// Scrolls by adding one small size.
- /// </summary>
- SmallIncrement,
- /// <summary>
- /// Scrolls by substracting one scaleView size.
- /// </summary>
- LargeDecrement,
- /// <summary>
- /// Scrolls by adding one scaleView size.
- /// </summary>
- LargeIncrement,
- /// <summary>
- /// Scrolls to the first scaleView.
- /// </summary>
- First,
- /// <summary>
- /// Scrolls to the last scaleView.
- /// </summary>
- Last
- }
- #endregion
- /// <summary>
- /// AxisScaleView class represents a scale view which allows to display
- /// only part of the available data.
- /// </summary>
- [
- SRDescription("DescriptionAttributeAxisDataView_AxisDataView"),
- DefaultProperty("Position"),
- ]
- public class AxisScaleView
- {
- #region Fields
- // Reference to the axis object
- internal Axis axis = null;
- // Axis data scaleView position
- private double _position = double.NaN;
- // Axis data scaleView size
- private double _size = double.NaN;
- // Axis data scaleView size units type
- private DateTimeIntervalType _sizeType = DateTimeIntervalType.Auto;
-
- // Axis data scaleView minimum scaleView/scrolling size
- private double _minSize = double.NaN;
- // Axis data scaleView minimum scaleView/scrolling size units type
- private DateTimeIntervalType _minSizeType = DateTimeIntervalType.Auto;
- // Axis data scaleView zooming UI interface enabled flag
- private bool _zoomable = true;
- // Axis data scaleView scroll line size
- private double _smallScrollSize = double.NaN;
- // Axis data scaleView scroll line size units type
- private DateTimeIntervalType _smallScrollSizeType = DateTimeIntervalType.Auto;
- // Axis data scaleView scroll line minimum size
- private double _smallScrollMinSize = 1.0;
- // Axis data scaleView scroll line minimum size units type
- private DateTimeIntervalType _smallScrollMinSizeType = DateTimeIntervalType.Auto;
- // Axis data scaleView scroll line minimum size
- private double _currentSmallScrollSize = double.NaN;
- // Axis data scaleView scroll line minimum size units type
- private DateTimeIntervalType _currentSmallScrollSizeType = DateTimeIntervalType.Auto;
- // Storage for the saved data scaleView states (position/size/sizetype)
- internal ArrayList dataViewStates = null;
- // Ignore validation flag
- private bool _ignoreValidation = false;
- #endregion
- #region Constructor
- /// <summary>
- /// Default constructor
- /// </summary>
- public AxisScaleView()
- {
- this.axis = null;
- }
- /// <summary>
- /// Internal constructor.
- /// </summary>
- /// <param name="axis">Data scaleView axis.</param>
- internal AxisScaleView(Axis axis)
- {
- this.axis = axis;
- }
- #endregion
- #region Axis data scaleView properties
- /// <summary>
- /// Gets or sets the position of the AxisScaleView.
- /// </summary>
- [
- SRCategory("CategoryAttributeAxisView"),
- Bindable(true),
- DefaultValue(Double.NaN),
- SRDescription("DescriptionAttributeAxisDataView_Position"),
- TypeConverter(typeof(DoubleDateNanValueConverter)),
- ParenthesizePropertyNameAttribute(true)
- ]
- public double Position
- {
- get
- {
- // Axis scaleView is not supported in circular chrt areas
- if(this.axis != null && this.axis.ChartArea != null && this.axis.ChartArea.chartAreaIsCurcular)
- {
- return Double.NaN;
- }
- return _position;
- }
- set
- {
- // Axis scaleView is not supported in circular chrt areas
- if(this.axis != null && this.axis.ChartArea != null && this.axis.ChartArea.chartAreaIsCurcular)
- {
- return;
- }
- if(_position != value)
- {
- // Set new position
- _position = value;
- // Align scaleView in connected areas
- if(this.axis != null && this.axis.ChartArea != null && this.axis.Common != null && this.axis.Common.ChartPicture != null)
- {
- if(!this.axis.ChartArea.alignmentInProcess)
- {
- AreaAlignmentOrientations orientation = (this.axis.axisType == AxisName.X || this.axis.axisType== AxisName.X2) ?
- AreaAlignmentOrientations.Vertical : AreaAlignmentOrientations.Horizontal;
- this.axis.Common.ChartPicture.AlignChartAreasAxesView(this.axis.ChartArea, orientation);
- }
- }
-
- // Validate chart
- if(!_ignoreValidation && axis != null)
- {
- axis.Invalidate();
- }
- axis.CallOnModifing();
- }
- }
- }
- /// <summary>
- /// Gets or sets the size of the AxisScaleView
- /// </summary>
- [
- SRCategory("CategoryAttributeAxisView"),
- Bindable(true),
- DefaultValue(Double.NaN),
- SRDescription("DescriptionAttributeAxisDataView_Size"),
- TypeConverter(typeof(DoubleNanValueConverter)),
- ParenthesizePropertyNameAttribute(true)
- ]
- public double Size
- {
- get
- {
- // Axis scaleView is not supported in circular chrt areas
- if(this.axis != null && this.axis.ChartArea != null && this.axis.ChartArea.chartAreaIsCurcular)
- {
- return Double.NaN;
- }
- return _size;
- }
- set
- {
- // Axis scaleView is not supported in circular chrt areas
- if(this.axis != null && this.axis.ChartArea != null && this.axis.ChartArea.chartAreaIsCurcular)
- {
- return;
- }
- if(_size != value)
- {
- // Set size value
- _size = value;
-
- // Align scaleView in connected areas
- if(this.axis != null && this.axis.ChartArea != null && this.axis.Common != null && this.axis.Common.ChartPicture != null)
- {
- if(!this.axis.ChartArea.alignmentInProcess)
- {
- AreaAlignmentOrientations orientation = (this.axis.axisType == AxisName.X || this.axis.axisType== AxisName.X2) ?
- AreaAlignmentOrientations.Vertical : AreaAlignmentOrientations.Horizontal;
- this.axis.Common.ChartPicture.AlignChartAreasAxesView(this.axis.ChartArea, orientation);
- }
- }
- // Reset current scrolling line size
- this._currentSmallScrollSize = double.NaN;
- // Validate chart
- if(!_ignoreValidation && axis != null)
- {
- axis.Invalidate();
- }
- axis.CallOnModifing();
- }
- }
- }
- /// <summary>
- /// Gets or sets the unit of measurement of the Size property.
- /// </summary>
- [
- SRCategory("CategoryAttributeAxisView"),
- Bindable(true),
- DefaultValue(DateTimeIntervalType.Auto),
- SRDescription("DescriptionAttributeAxisDataView_SizeType"),
- ParenthesizePropertyNameAttribute(true)
- ]
- public DateTimeIntervalType SizeType
- {
- get
- {
- return _sizeType;
- }
- set
- {
- if(_sizeType != value)
- {
- // Set size type
- _sizeType = (value != DateTimeIntervalType.NotSet) ? value : DateTimeIntervalType.Auto;
- // Align scaleView in connected areas
- if(this.axis != null && this.axis.ChartArea != null && this.axis.Common != null && this.axis.Common.ChartPicture != null)
- {
- if(!this.axis.ChartArea.alignmentInProcess)
- {
- AreaAlignmentOrientations orientation = (this.axis.axisType == AxisName.X || this.axis.axisType== AxisName.X2) ?
- AreaAlignmentOrientations.Vertical : AreaAlignmentOrientations.Horizontal;
- this.axis.Common.ChartPicture.AlignChartAreasAxesView(this.axis.ChartArea, orientation);
- }
- }
-
- // Validate chart
- if(!_ignoreValidation && axis != null)
- {
- axis.Invalidate();
- }
- if(axis != null)
- {
- axis.CallOnModifing();
- }
- }
- }
- }
- /// <summary>
- /// Indicates if axis is zoomed-in.
- /// </summary>
- [
- SRCategory("CategoryAttributeAxisView"),
- Bindable(false),
- Browsable(false),
- SRDescription("DescriptionAttributeAxisDataView_IsZoomed"),
- DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden),
- SerializationVisibility(SerializationVisibility.Hidden),
- ]
- public bool IsZoomed
- {
- get
- {
- return (
- !double.IsNaN(this.Size) &&
- this.Size != 0.0 &&
- !double.IsNaN(this.Position));
- }
- }
- /// <summary>
- /// Gets or sets the minimum size of the AxisScaleView.
- /// </summary>
- [
- SRCategory("CategoryAttributeAxisView"),
- Bindable(true),
- DefaultValue(Double.NaN),
- SRDescription("DescriptionAttributeAxisDataView_MinSize"),
- TypeConverter(typeof(DoubleNanValueConverter))
- ]
- public double MinSize
- {
- get
- {
- return _minSize;
- }
- set
- {
- _minSize = value;
- if (axis != null)
- {
- axis.CallOnModifing();
- }
- }
- }
- /// <summary>
- /// Gets or sets the unit of measurement of the MinSize property.
- /// </summary>
- [
- SRCategory("CategoryAttributeAxisView"),
- Bindable(true),
- DefaultValue(DateTimeIntervalType.Auto),
- SRDescription("DescriptionAttributeAxisDataView_MinSizeType"),
- ]
- public DateTimeIntervalType MinSizeType
- {
- get
- {
- return _minSizeType;
- }
- set
- {
- _minSizeType = (value != DateTimeIntervalType.NotSet) ? value : DateTimeIntervalType.Auto;
- if (axis != null)
- {
- axis.CallOnModifing();
- }
- }
- }
- /// <summary>
- /// Gets or sets a flag which indicates whether the zooming user interface is enabled.
- /// </summary>
- [
- SRCategory("CategoryAttributeAxisView"),
- Bindable(true),
- DefaultValue(true),
- SRDescription("DescriptionAttributeAxisDataView_Zoomable"),
- SuppressMessage("Microsoft.Naming", "CA1704:IdentifiersShouldBeSpelledCorrectly",
- Justification="'Zoomable' is a commonly used term and generally well understood"),
- ]
- public bool Zoomable
- {
- get
- {
- return _zoomable;
- }
- set
- {
- _zoomable = value;
- if (axis != null)
- {
- axis.CallOnModifing();
- }
- }
- }
- /// <summary>
- /// Gets or sets the small scrolling size.
- /// </summary>
- [
- SRCategory("CategoryAttributeAxisView"),
- Bindable(true),
- DefaultValue(Double.NaN),
- SRDescription("DescriptionAttributeAxisDataView_SmallScrollSize"),
- TypeConverter(typeof(AxisMinMaxAutoValueConverter))
- ]
- public double SmallScrollSize
- {
- get
- {
- return _smallScrollSize;
- }
- set
- {
- if(_smallScrollSize != value)
- {
- // Set size value
- _smallScrollSize = value;
- // Validate chart
- if(!_ignoreValidation && axis != null)
- {
- axis.Invalidate();
- }
- if (axis != null)
- {
- axis.CallOnModifing();
- }
- }
- }
- }
- /// <summary>
- /// Gets or sets the unit of measurement for the SmallScrollMinSize property
- /// </summary>
- [
- SRCategory("CategoryAttributeAxisView"),
- Bindable(true),
- DefaultValue(DateTimeIntervalType.Auto),
- SRDescription("DescriptionAttributeAxisDataView_SmallScrollSizeType"),
- ]
- public DateTimeIntervalType SmallScrollSizeType
- {
- get
- {
- return _smallScrollSizeType;
- }
- set
- {
- if(_smallScrollSizeType != value)
- {
- // Set size type
- _smallScrollSizeType = (value != DateTimeIntervalType.NotSet) ? value : DateTimeIntervalType.Auto;
- // Validate chart
- if(!_ignoreValidation && axis != null)
- {
- axis.Invalidate();
- }
- if (axis != null)
- {
- axis.CallOnModifing();
- }
- }
- }
- }
- /// <summary>
- /// Gets or sets the minimum small scrolling size.
- /// Only used if the small scrolling size is not set.
- /// </summary>
- [
- SRCategory("CategoryAttributeAxisView"),
- Bindable(true),
- DefaultValue(1.0),
- SRDescription("DescriptionAttributeAxisDataView_SmallScrollMinSize")
- ]
- public double SmallScrollMinSize
- {
- get
- {
- return _smallScrollMinSize;
- }
- set
- {
- if(_smallScrollMinSize != value)
- {
- // Set size value
- _smallScrollMinSize = value;
- _currentSmallScrollSize = double.NaN;
- // Validate chart
- if(!_ignoreValidation && axis != null)
- {
- axis.Invalidate();
- }
- if (axis != null)
- {
- axis.CallOnModifing();
- }
- }
- }
- }
- /// <summary>
- /// Gets or sets the unit of measurement for the SmallScrollMinSize property.
- /// </summary>
- [
- SRCategory("CategoryAttributeAxisView"),
- Bindable(true),
- DefaultValue(DateTimeIntervalType.Auto),
- SRDescription("DescriptionAttributeAxisDataView_SmallScrollMinSizeType"),
- ]
- public DateTimeIntervalType SmallScrollMinSizeType
- {
- get
- {
- return _smallScrollMinSizeType;
- }
- set
- {
- if(_smallScrollMinSizeType != value)
- {
- // Set size type
- _smallScrollMinSizeType = (value != DateTimeIntervalType.NotSet) ? value : DateTimeIntervalType.Auto;
- _currentSmallScrollSize = double.NaN;
- // Validate chart
- if(!_ignoreValidation && axis != null)
- {
- axis.Invalidate();
- }
- if (axis != null)
- {
- axis.CallOnModifing();
- }
- }
- }
- }
- #endregion
- #region ScaleView position internal methods
- /// <summary>
- /// Call this method to get the minimum axis value of a data view.
- /// </summary>
- /// <returns>The minimum axis value for the data view.</returns>
- [Browsable(false)]
- [Utilities.SerializationVisibility(Utilities.SerializationVisibility.Hidden)]
- public double ViewMinimum
- {
- get
- {
- // If zooming is enabled
- if (!Double.IsNaN(this.Size))
- {
- // If size set only use axis minimum for scaleView position
- if (Double.IsNaN(this.Position))
- {
- this.Position = this.axis.Minimum;
- }
- // Check if scaleView position and size are set
- else
- {
- // Calculate and add axis side margin
- if (this.Position <= axis.minimum)
- {
- return this.Position;
- }
- else // Add a margin only if scaleView is inside data point scaleView
- {
- return this.Position - axis.marginView;
- }
- }
- }
- // Return axis scale minimum value if scaleView position is not set
- return axis.minimum;
- }
- }
- /// <summary>
- /// Maximum axis value of a data view.
- /// </summary>
- /// <returns>The maximum axis value for the data view.</returns>
- [Browsable(false)]
- [Utilities.SerializationVisibility(Utilities.SerializationVisibility.Hidden)]
- public double ViewMaximum
- {
- get
- {
- // If zooming is enabled
- if (!Double.IsNaN(this.Size))
- {
- // If size set only use axis minimum for scaleView position
- if (Double.IsNaN(this.Position))
- {
- this.Position = this.axis.Minimum;
- }
- // Check if scaleView position and size are set
- else
- {
- // Get axis interval
- double viewSize = ChartHelper.GetIntervalSize(this.Position, this.Size, this.SizeType);
- // Calculate and add axis side margin
- if (this.Position + viewSize >= axis.maximum)
- {
- return this.Position + viewSize;
- }
- else // Add a margin only if scaleView is inside data point scaleView
- {
- return this.Position + viewSize + axis.marginView;
- }
- }
- }
- // Return axis scale maximum value if scaleView position is not set
- return axis.maximum;
- }
- }
- #endregion
- #region Scrolling methods
- /// <summary>
- /// Call this method to scroll to a specified position along an axis.
- /// </summary>
- /// <param name="scrollType">Direction and size to scroll.</param>
- public void Scroll(ScrollType scrollType)
- {
- this.Scroll(scrollType, false);
- }
- /// <summary>
- /// Scrolls axis data scaleView from current position.
- /// </summary>
- /// <param name="scrollType">Direction and size to scroll.</param>
- /// <param name="fireChangeEvents">Fire scaleView position events from this method.</param>
- internal void Scroll(ScrollType scrollType, bool fireChangeEvents)
- {
- // Adjust current position depending on the scroll type
- double newPosition = this._position;
- switch(scrollType)
- {
- case(ScrollType.SmallIncrement):
- newPosition += ((axis.IsReversed) ? -1 : 1) * ChartHelper.GetIntervalSize(this._position, this.GetScrollingLineSize(), this.GetScrollingLineSizeType());
- break;
- case(ScrollType.SmallDecrement):
- newPosition -= ((axis.IsReversed) ? -1 : 1) * ChartHelper.GetIntervalSize(this._position, this.GetScrollingLineSize(), this.GetScrollingLineSizeType());
- break;
- case(ScrollType.LargeIncrement):
- newPosition += ((axis.IsReversed) ? -1 : 1) * ChartHelper.GetIntervalSize(this._position, this.Size, this.SizeType);
- break;
- case(ScrollType.LargeDecrement):
- newPosition -= ((axis.IsReversed) ? -1 : 1) * ChartHelper.GetIntervalSize(this._position, this.Size, this.SizeType);
- break;
- case(ScrollType.First):
- if(!axis.IsReversed)
- {
- newPosition = (axis.minimum + axis.marginView);
- }
- else
- {
- newPosition = (axis.maximum - axis.marginView);
- }
- break;
- case(ScrollType.Last):
- {
- double viewSize = ChartHelper.GetIntervalSize(newPosition, this.Size, this.SizeType);
- if(!axis.IsReversed)
- {
- newPosition = (axis.maximum - axis.marginView - viewSize);
- }
- else
- {
- newPosition = (axis.minimum + axis.marginView + viewSize);
- }
- break;
- }
- }
- // Scroll to the new position
- this.Scroll(newPosition, fireChangeEvents);
- }
- /// <summary>
- /// Call this method to scroll to a specified position along an axis.
- /// </summary>
- /// <param name="newPosition">New position.</param>
- public void Scroll(double newPosition)
- {
- this.Scroll(newPosition, false);
- }
- /// <summary>
- /// Call this method to scroll to a specified position along an axis.
- /// </summary>
- /// <param name="newPosition">New position.</param>
- public void Scroll(DateTime newPosition)
- {
- this.Scroll(newPosition.ToOADate(), false);
- }
- /// <summary>
- /// Internal helper method for scrolling into specified position.
- /// </summary>
- /// <param name="newPosition">New data scaleView position.</param>
- /// <param name="fireChangeEvents">Fire scaleView position events from this method.</param>
- internal void Scroll(double newPosition, bool fireChangeEvents)
- {
- // Get current scaleView size
- double viewSize = ChartHelper.GetIntervalSize(newPosition, this.Size, this.SizeType);
- // Validate new scaleView position
- if(newPosition < (axis.minimum + axis.marginView))
- {
- newPosition = (axis.minimum + axis.marginView);
- }
- else if(newPosition > (axis.maximum - axis.marginView - viewSize))
- {
- newPosition = (axis.maximum - axis.marginView - viewSize);
- }
- // Fire scaleView position changing events
- ViewEventArgs arguments = new ViewEventArgs(this.axis, newPosition, this.Size, this.SizeType);
- if(fireChangeEvents && GetChartObject() != null)
- {
- GetChartObject().OnAxisViewChanging(arguments);
- newPosition = arguments.NewPosition;
- }
- // Check if data scaleView position and size is different from current
- if(newPosition == this.Position)
- {
- return;
- }
- // Change scaleView position
- this.Position = newPosition;
- // Fire scaleView position changed events
- if(fireChangeEvents && GetChartObject() != null)
- {
- GetChartObject().OnAxisViewChanged(arguments);
- }
- }
- #endregion
- #region Zooming and ZoomResetting methods
- /// <summary>
- /// Sets a new axis data view/position based on the start and end dates specified.
- /// </summary>
- /// <param name="viewPosition">New start position for the axis scale view.</param>
- /// <param name="viewSize">New size for the axis scale view.</param>
- /// <param name="viewSizeType">New unit of measurement of the size.</param>
- /// <param name="saveState">Indicates whether the current size/position needs to be saved.</param>
- public void Zoom(double viewPosition, double viewSize, DateTimeIntervalType viewSizeType, bool saveState)
- {
- this.Zoom(viewPosition, viewSize, viewSizeType, false, saveState);
- }
- /// <summary>
- /// Sets a new axis data view/position based on the specified start and end values.
- /// </summary>
- /// <param name="viewStart">New start position for the axis scale view.</param>
- /// <param name="viewEnd">New end position for the axis scale view.</param>
- public void Zoom(double viewStart, double viewEnd)
- {
- this.Zoom(viewStart, viewEnd - viewStart, DateTimeIntervalType.Number, false, false);
- }
- /// <summary>
- /// Sets a new axis data view/position based on the start and end dates specified.
- /// </summary>
- /// <param name="viewPosition">New start position for the axis scale view.</param>
- /// <param name="viewSize">New size for the axis scale view.</param>
- /// <param name="viewSizeType">New unit of measurement of the size.</param>
- public void Zoom(double viewPosition, double viewSize, DateTimeIntervalType viewSizeType)
- {
- this.Zoom(viewPosition, viewSize, viewSizeType, false, false);
- }
- /// <summary>
- /// Reset the specified number of zooming operations by restoring axis data view.
- /// </summary>
- /// <param name="numberOfViews">Number of zoom operations to reset. Zero for all.</param>
- public void ZoomReset(int numberOfViews)
- {
- this.LoadDataViewState(numberOfViews, false);
- }
- /// <summary>
- /// Reset one zooming operation by restoring axis data view.
- /// </summary>
- public void ZoomReset()
- {
- this.LoadDataViewState(1, false);
- }
- /// <summary>
- /// Reset several zooming operation by restoring data scaleView size/position.
- /// </summary>
- /// <param name="numberOfViews">How many scaleView zoom operations to reset. Zero for all.</param>
- /// <param name="fireChangeEvents">Fire scaleView position events from this method.</param>
- internal void ZoomReset(int numberOfViews, bool fireChangeEvents)
- {
- this.LoadDataViewState(numberOfViews, fireChangeEvents);
- }
- /// <summary>
- /// Internal helper zooming method.
- /// </summary>
- /// <param name="viewPosition">New data scaleView start posiion.</param>
- /// <param name="viewSize">New data scaleView size.</param>
- /// <param name="viewSizeType">New data scaleView size units type.</param>
- /// <param name="fireChangeEvents">Fire scaleView position events from this method.</param>
- /// <param name="saveState">Indicates that current scaleView size/position must be save, so it can be restored later.</param>
- /// <returns>True if zoom operation was made.</returns>
- internal bool Zoom(
- double viewPosition,
- double viewSize,
- DateTimeIntervalType viewSizeType,
- bool fireChangeEvents,
- bool saveState)
- {
- // Validate new scaleView position and size
- ValidateViewPositionSize(ref viewPosition, ref viewSize, ref viewSizeType);
- // Fire scaleView position/size changing events
- ViewEventArgs arguments = new ViewEventArgs(this.axis, viewPosition, viewSize, viewSizeType);
- if(fireChangeEvents && GetChartObject() != null)
- {
- GetChartObject().OnAxisViewChanging(arguments);
- viewPosition = arguments.NewPosition;
- viewSize = arguments.NewSize;
- viewSizeType = arguments.NewSizeType;
- }
- // Check if data scaleView position and size is different from current
- if(viewPosition == this.Position &&
- viewSize == this.Size &&
- viewSizeType == this.SizeType)
- {
- return false;
- }
- // Save current data scaleView state, so it can be restored
- if(saveState)
- {
- SaveDataViewState();
- }
- // Change scaleView position/size
- this._ignoreValidation = true;
- this.Position = viewPosition;
- this.Size = viewSize;
- this.SizeType = viewSizeType;
- this._ignoreValidation = false;
- // Reset current scrolling line size
- this._currentSmallScrollSize = double.NaN;
- // Invalidate chart
- axis.Invalidate();
- // Fire scaleView position/size changed events
- if(fireChangeEvents && GetChartObject() != null)
- {
- GetChartObject().OnAxisViewChanged(arguments);
- }
- return true;
- }
- #endregion
- #region Data scaleView state saving/restoring methods
- /// <summary>
- /// Saves current data scaleView position/size/sizetype, so
- /// it can be restored later.
- /// </summary>
- /// <param name="numberOfViews">Number of time to reset zoom. Zero for all.</param>
- /// <param name="fireChangeEvents">Fire scaleView position events from this method.</param>
- private void LoadDataViewState(int numberOfViews, bool fireChangeEvents)
- {
- // Check parameters
- if(numberOfViews < 0)
- {
- throw (new ArgumentOutOfRangeException("numberOfViews", SR.ExceptionScrollBarZoomResetsNumberInvalid));
- }
- // Check if storage was created
- if(dataViewStates != null && dataViewStates.Count >= 3)
- {
- // Find starting index of restoring state
- int dataStartIndex = 0;
- if(numberOfViews > 0)
- {
- dataStartIndex = dataViewStates.Count - numberOfViews * 3;
- if(dataStartIndex < 0)
- {
- dataStartIndex = 0;
- }
- }
- // Fire scaleView position/size changing events
- ViewEventArgs arguments = new ViewEventArgs(
- this.axis,
- (double)dataViewStates[dataStartIndex],
- (double)dataViewStates[dataStartIndex + 1],
- (DateTimeIntervalType)dataViewStates[dataStartIndex + 2]);
- if(fireChangeEvents && GetChartObject() != null)
- {
- GetChartObject().OnAxisViewChanging(arguments);
- }
- // Restore data
- this.Position = arguments.NewPosition;
- this.Size = arguments.NewSize;
- this.SizeType = arguments.NewSizeType;
- // Fire scaleView position/size changed events
- if(fireChangeEvents && GetChartObject() != null)
- {
- GetChartObject().OnAxisViewChanged(arguments);
- }
- // Clear data
- int itemsToRemove = numberOfViews * 3;
- if (itemsToRemove > (dataViewStates.Count - dataStartIndex))
- {
- itemsToRemove = dataViewStates.Count - dataStartIndex;
- }
- dataViewStates.RemoveRange(dataStartIndex, itemsToRemove);
- // clean up the history state when the numberOfViews == 0 (reset all by docs)
- if ( numberOfViews == 0 )
- {
- dataViewStates.Clear();
- }
- if (Double.IsNaN(this.Position) || Double.IsNaN(this.Size))
- {
- this.Position = Double.NaN;
- this.Size = Double.NaN;
- }
- }
- // Nothing to restore - just disable the data scaleView
- else
- {
- // Fire scaleView position/size changing events
- ViewEventArgs arguments = new ViewEventArgs(
- this.axis,
- double.NaN,
- double.NaN,
- DateTimeIntervalType.Auto);
- if(fireChangeEvents && GetChartObject() != null)
- {
- GetChartObject().OnAxisViewChanging(arguments);
- }
- // Restore data
- this.Position = arguments.NewPosition;
- this.Size = arguments.NewSize;
- this.SizeType = arguments.NewSizeType;
- // Fire scaleView position/size changed events
- if(fireChangeEvents && GetChartObject() != null)
- {
- GetChartObject().OnAxisViewChanged(arguments);
- }
- }
- // clear cached chart areas and bitmap buffers
- GetChartObject().Refresh();
- }
- /// <summary>
- /// Saves current data scaleView position/size/sizetype, so
- /// it can be restored later.
- /// </summary>
- private void SaveDataViewState()
- {
- // Create storage array
- if(dataViewStates == null)
- {
- dataViewStates = new ArrayList();
- }
- // Save data scaleView state
- dataViewStates.Add(this.Position);
- dataViewStates.Add(this.Size);
- dataViewStates.Add(this.SizeType);
- }
- #endregion
- #region Helper methods
- /// <summary>
- /// Initialize internal scrolling line size variables for later use.
- /// This size is used in to scroll chart one line up or down.
- /// </summary>
- private void GetCurrentViewSmallScrollSize()
- {
- //**************************************************************************
- //** Check if current scrolling line size was not already calculated
- //**************************************************************************
- if(double.IsNaN(_currentSmallScrollSize))
- {
- //**************************************************************************
- //** Calculate line size depending on the current scaleView size
- //**************************************************************************
- if(this.SizeType == DateTimeIntervalType.Auto || this.SizeType == DateTimeIntervalType.Number)
- {
- // Set line size type
- _currentSmallScrollSizeType = DateTimeIntervalType.Number;
- // Devide scaleView by 20 to find the scrolling line size
- double newSize = this.Size / 20.0;
- // Make sure that current line size is even with minimum value
- if(!double.IsNaN(this.SmallScrollMinSize) && this.SmallScrollMinSize != 0.0)
- {
- double rounder = (Math.Round(newSize / this.SmallScrollMinSize));
- if(rounder < 0)
- {
- rounder = 1;
- }
- newSize = rounder * this.SmallScrollMinSize;
- }
- // Set new current line size
- this._currentSmallScrollSize = newSize;
- }
- else
- {
- // Calculate line size for date/time
- double viewEndPosition = this.Position + ChartHelper.GetIntervalSize(this.Position, this.Size, this.SizeType);
- _currentSmallScrollSize = axis.CalcInterval(
- this.Position,
- viewEndPosition,
- true,
- out _currentSmallScrollSizeType,
- ChartValueType.Auto);
- }
- //**************************************************************************
- //** Make sure calculated scroll line size is not smaller than the minimum
- //**************************************************************************
- if(!double.IsNaN(this.SmallScrollMinSize) && this.SmallScrollMinSize != 0.0)
- {
- double newLineSize = ChartHelper.GetIntervalSize(this.Position, _currentSmallScrollSize, _currentSmallScrollSizeType);
- double minLineSize = ChartHelper.GetIntervalSize(this.Position, this.SmallScrollMinSize, this.SmallScrollMinSizeType);
- if(newLineSize < minLineSize)
- {
- _currentSmallScrollSize = SmallScrollMinSize;
- _currentSmallScrollSizeType = SmallScrollMinSizeType;
- }
- }
- }
- }
- /// <summary>
- /// Returns the scroll line size.
- /// </summary>
- /// <returns>Scroll line size.</returns>
- internal double GetScrollingLineSize()
- {
- // Scroll line size/type is specificly set by user
- if(!double.IsNaN(this.SmallScrollSize))
- {
- return this.SmallScrollSize;
- }
- // Calcualte scroll line size depending on the current scaleView size
- GetCurrentViewSmallScrollSize();
- // Return line size
- return _currentSmallScrollSize;
- }
- /// <summary>
- /// Returns the scroll line size units type.
- /// </summary>
- /// <returns>Scroll line size units type.</returns>
- internal DateTimeIntervalType GetScrollingLineSizeType()
- {
- // Scroll line size/type is specificly set by user
- if(!double.IsNaN(this.SmallScrollSize))
- {
- return this.SmallScrollSizeType;
- }
- // Calcualte scroll line size depending on the current scaleView size
- GetCurrentViewSmallScrollSize();
- // Return line size units type
- return _currentSmallScrollSizeType;
- }
- /// <summary>
- /// Helper method, which validates the axis data scaleView position and size.
- /// Returns adjusted scaleView position and size.
- /// </summary>
- /// <param name="viewPosition">ScaleView position.</param>
- /// <param name="viewSize">ScaleView size.</param>
- /// <param name="viewSizeType">ScaleView size units type.</param>
- private void ValidateViewPositionSize(ref double viewPosition, ref double viewSize, ref DateTimeIntervalType viewSizeType)
- {
- //****************************************************************
- //** Check if new scaleView position is inside axis scale
- //** minimum/maximum without margin.
- //****************************************************************
- if(viewPosition < (axis.minimum + axis.marginView))
- {
- if(viewSizeType == DateTimeIntervalType.Auto || viewSizeType == DateTimeIntervalType.Number)
- {
- viewSize -= (axis.minimum + axis.marginView) - viewPosition;
- }
- viewPosition = (axis.minimum + axis.marginView);
- }
- else if(viewPosition > (axis.maximum - axis.marginView))
- {
- if(viewSizeType == DateTimeIntervalType.Auto || viewSizeType == DateTimeIntervalType.Number)
- {
- viewSize -= viewPosition - (axis.maximum - axis.marginView);
- }
- viewPosition = (axis.maximum - axis.marginView);
- }
- //****************************************************************
- //** Check if new scaleView size is not smaller than minimum size
- //** set by the user
- //****************************************************************
- double newViewSize = ChartHelper.GetIntervalSize(viewPosition, viewSize, viewSizeType);
- double minViewSize = ChartHelper.GetIntervalSize(viewPosition, 1, this.MinSizeType);
- if(!double.IsNaN(this.MinSize))
- {
- minViewSize = ChartHelper.GetIntervalSize(viewPosition, this.MinSize, this.MinSizeType);
- if(newViewSize < minViewSize)
- {
- viewSize = (double.IsNaN(this.MinSize)) ? 1 : this.MinSize;
- viewSizeType = this.MinSizeType;
- newViewSize = ChartHelper.GetIntervalSize(viewPosition, viewSize, viewSizeType);
- }
- }
-
- //****************************************************************
- //** Check if new scaleView size is smaller than (0.000000001)
- //****************************************************************
- if(newViewSize < 0.000000001)
- {
- viewSize = 0.000000001;
- viewSizeType = DateTimeIntervalType.Number;
- newViewSize = ChartHelper.GetIntervalSize(viewPosition, viewSize, viewSizeType);
- }
- //****************************************************************
- //** Check if new scaleView end position (position + size) is inside
- //** axis scale minimum/maximum without margin.
- //****************************************************************
- while( (viewPosition + newViewSize) > (axis.maximum - axis.marginView) )
- {
- double currentSize = viewSize;
- DateTimeIntervalType currentSizeType = viewSizeType;
- // Try to reduce the scaleView size
- if(newViewSize > minViewSize)
- {
- // Try to adjust the scaleView size
- if(viewSize > 1)
- {
- --viewSize;
- }
- else if(viewSizeType == DateTimeIntervalType.Years)
- {
- viewSize = 11;
- viewSizeType = DateTimeIntervalType.Months;
- }
- else if(viewSizeType == DateTimeIntervalType.Months)
- {
- viewSize = 4;
- viewSizeType = DateTimeIntervalType.Weeks;
- }
- else if(viewSizeType == DateTimeIntervalType.Weeks)
- {
- viewSize = 6;
- viewSizeType = DateTimeIntervalType.Days;
- }
- else if(viewSizeType == DateTimeIntervalType.Days)
- {
- viewSize = 23;
- viewSizeType = DateTimeIntervalType.Hours;
- }
- else if(viewSizeType == DateTimeIntervalType.Hours)
- {
- viewSize = 59;
- viewSizeType = DateTimeIntervalType.Minutes;
- }
- else if(viewSizeType == DateTimeIntervalType.Minutes)
- {
- viewSize = 59;
- viewSizeType = DateTimeIntervalType.Seconds;
- }
- else if(viewSizeType == DateTimeIntervalType.Seconds)
- {
- viewSize = 999;
- viewSizeType = DateTimeIntervalType.Milliseconds;
- }
- else
- {
- viewPosition = (axis.maximum - axis.marginView) - minViewSize;
- break;
- }
- // Double check that scaleView size is not smaller than min size
- newViewSize = ChartHelper.GetIntervalSize(viewPosition, viewSize, viewSizeType);
- if(newViewSize < minViewSize)
- {
- // Can't adjust size no more (restore prev. value)
- viewSize = currentSize;
- viewSizeType = currentSizeType;
- // Adjust the start position
- viewPosition = (axis.maximum - axis.marginView) - minViewSize;
- break;
- }
- }
- else
- {
- // Adjust the start position
- viewPosition = (axis.maximum - axis.marginView) - newViewSize;
- break;
- }
- }
- }
- /// <summary>
- /// Helper function which returns a reference to the chart object.
- /// </summary>
- /// <returns>Chart object reference.</returns>
- internal Chart GetChartObject()
- {
- if(this.axis != null && this.axis.Common!=null)
- {
- return this.axis.Common.Chart;
- }
- return null;
- }
- #endregion
- }
- /// <summary>
- /// This class is used as a parameter object in the AxisViewChanged and AxisViewChanging events of the root Chart object.
- /// </summary>
- public class ViewEventArgs : EventArgs
- {
- #region Private fields
- // Private fields for properties values storage
- private Axis _axis = null;
- private double _newPosition = double.NaN;
- private double _newSize = double.NaN;
- private DateTimeIntervalType _newSizeType = DateTimeIntervalType.Auto;
- #endregion
- #region Constructors
- /// <summary>
- /// ViewEventArgs constructor.
- /// </summary>
- /// <param name="axis">Axis of the scale view.</param>
- /// <param name="newPosition">New scale view start position.</param>
- public ViewEventArgs(Axis axis, double newPosition)
- {
- this._axis = axis;
- this._newPosition = newPosition;
- }
- /// <summary>
- /// ViewEventArgs constructor.
- /// </summary>
- /// <param name="axis">Axis of the scale view.</param>
- /// <param name="newPosition">New scale view start position.</param>
- /// <param name="newSize">New scale view size.</param>
- /// <param name="newSizeType">New unit of measurement of the size.</param>
- public ViewEventArgs(Axis axis, double newPosition, double newSize, DateTimeIntervalType newSizeType)
- {
- this._axis = axis;
- this._newPosition = newPosition;
- this._newSize = newSize;
- this._newSizeType = newSizeType;
- }
- #endregion
- #region Properties
- /// <summary>
- /// Axis of the event.
- /// </summary>
- [
- SRDescription("DescriptionAttributeAxis"),
- ]
- public Axis Axis
- {
- get
- {
- return _axis;
- }
- }
- /// <summary>
- /// ChartArea of the event.
- /// </summary>
- [
- SRDescription("DescriptionAttributeChartArea"),
- ]
- public ChartArea ChartArea
- {
- get
- {
- return _axis.ChartArea;
- }
- }
- /// <summary>
- /// New scale view start position.
- /// </summary>
- [
- SRDescription("DescriptionAttributeViewEventArgs_NewPosition"),
- ]
- public double NewPosition
- {
- get
- {
- return _newPosition;
- }
- set
- {
- _newPosition = value;
- }
- }
- /// <summary>
- /// New scale view size.
- /// </summary>
- [
- SRDescription("DescriptionAttributeViewEventArgs_NewSize"),
- ]
- public double NewSize
- {
- get
- {
- return _newSize;
- }
- set
- {
- _newSize = value;
- }
- }
- /// <summary>
- /// New unit of measurement of the scale view.
- /// </summary>
- [
- SRDescription("DescriptionAttributeViewEventArgs_NewSizeType"),
- ]
- public DateTimeIntervalType NewSizeType
- {
- get
- {
- return _newSizeType;
- }
- set
- {
- _newSizeType = (value != DateTimeIntervalType.NotSet) ? value : DateTimeIntervalType.Auto;
- }
- }
- #endregion
- }
- }
- namespace FastReport.DataVisualization.Charting
- {
- /// <summary>
- /// Designer converter class
- /// Converts Double.NaN values to/from "Not set".
- /// </summary>
- internal class DoubleNanValueConverter : DoubleConverter
- {
- #region Converter methods
- /// <summary>
- /// Standard values supported. This method always return true.
- /// </summary>
- /// <param name="context">Descriptor context.</param>
- /// <returns>True.</returns>
- public override bool GetStandardValuesSupported(ITypeDescriptorContext context)
- {
- return true;
- }
- /// <summary>
- /// Standard values are not exclusive. This method always return false.
- /// </summary>
- /// <param name="context">Descriptor context.</param>
- /// <returns>False.</returns>
- public override bool GetStandardValuesExclusive(ITypeDescriptorContext context)
- {
- return false;
- }
- /// <summary>
- /// Get in the collection of standard values.
- /// </summary>
- /// <param name="context">Descriptor context.</param>
- public override StandardValuesCollection GetStandardValues(ITypeDescriptorContext context)
- {
- ArrayList values = new ArrayList();
- values.Add(Double.NaN);
-
- return new StandardValuesCollection(values);
- }
- /// <summary>
- /// Convert double.NaN to string "Not set"
- /// </summary>
- /// <param name="context">Descriptor context.</param>
- /// <param name="culture">Culture information.</param>
- /// <param name="value">Value to convert.</param>
- /// <param name="destinationType">Conversion destination type.</param>
- /// <returns>Converted object.</returns>
- public override object ConvertTo(ITypeDescriptorContext context, CultureInfo culture, object value, Type destinationType)
- {
- double doubleValue = (double)value;
- if (destinationType == typeof(string))
- {
- if(Double.IsNaN(doubleValue))
- {
- return Constants.NotSetValue;
- }
- }
- // Call base class
- return base.ConvertTo(context, culture, value, destinationType);
- }
- /// <summary>
- /// Convert minimum or maximum values from string.
- /// </summary>
- public override object ConvertFrom(ITypeDescriptorContext context, CultureInfo culture, object value)
- {
- // If converting from string value
- string crossingValue = value as string;
- if (crossingValue != null)
- {
- if (String.Compare(crossingValue, Constants.NotSetValue, StringComparison.OrdinalIgnoreCase) == 0)
- {
- return Double.NaN;
- }
- }
-
- // Call base converter
- return base.ConvertFrom(context, culture, value);
- }
- #endregion
- }
- /// <summary>
- /// Designer converter class
- /// Converts Double.NaN values to/from "Not set".
- /// Converts value to/from date strings.
- /// </summary>
- internal class DoubleDateNanValueConverter : DoubleConverter
- {
- #region Converter methods
- /// <summary>
- /// Standard values supported - return true
- /// </summary>
- /// <param name="context">Descriptor context.</param>
- /// <returns>Standard values supported.</returns>
- public override bool GetStandardValuesSupported(ITypeDescriptorContext context)
- {
- return true;
- }
- /// <summary>
- /// Standard values are not exclusive - return false
- /// </summary>
- /// <param name="context">Descriptor context.</param>
- /// <returns>Non exclusive standard values.</returns>
- public override bool GetStandardValuesExclusive(ITypeDescriptorContext context)
- {
- return false;
- }
- /// <summary>
- /// Fill in the list of predefined values.
- /// </summary>
- /// <param name="context">Descriptor context.</param>
- public override StandardValuesCollection GetStandardValues(ITypeDescriptorContext context)
- {
- ArrayList values = new ArrayList();
- values.Add(Double.NaN);
-
- return new StandardValuesCollection(values);
- }
- /// <summary>
- /// Convert values to string if step type is set to one of the DateTime type
- /// </summary>
- /// <param name="context">Descriptor context.</param>
- /// <param name="culture">Culture information.</param>
- /// <param name="value">Value to convert.</param>
- /// <param name="destinationType">Conversion destination type.</param>
- /// <returns>Converted object.</returns>
- public override object ConvertTo(ITypeDescriptorContext context, CultureInfo culture, object value, Type destinationType)
- {
- // Check for NaN
- if (destinationType == typeof(string))
- {
- if(Double.IsNaN((double)value))
- {
- return Constants.NotSetValue;
- }
- }
- if (context != null && context.Instance != null)
- {
- // Get access to the Axis object
- Axis axis = null;
- if(context.Instance is AxisScaleView)
- {
- axis = ((AxisScaleView)context.Instance).axis;
- }
- else if(context.Instance is Cursor)
- {
- axis = ((Cursor)context.Instance).GetAxis();
- }
- if (axis != null && destinationType == typeof(string))
- {
- string strValue = ConvertDateTimeToString(
- (double)value,
- axis.GetAxisValuesType(),
- axis.InternalIntervalType);
- if (strValue != null)
- return strValue;
- }
-
- }
- return base.ConvertTo(context, culture, value, destinationType);
- }
- public static string ConvertDateTimeToString(
- double dtValue,
- ChartValueType axisValuesType,
- DateTimeIntervalType dtIntervalType)
- {
- string strValue = null;
- // Use axis values types if interval is automatic
- if (dtIntervalType == DateTimeIntervalType.Auto)
- {
- if (axisValuesType == ChartValueType.DateTime ||
- axisValuesType == ChartValueType.Time ||
- axisValuesType == ChartValueType.Date ||
- axisValuesType == ChartValueType.DateTimeOffset)
- {
- strValue = DateTime.FromOADate(dtValue).ToString("g", System.Globalization.CultureInfo.CurrentCulture);
- }
- }
- else
- {
- if (dtIntervalType != DateTimeIntervalType.Number)
- {
- // Covert value to date/time
- if (dtIntervalType < DateTimeIntervalType.Hours)
- {
- strValue = DateTime.FromOADate(dtValue).ToShortDateString();
- }
- else
- {
- strValue = DateTime.FromOADate(dtValue).ToString("g", System.Globalization.CultureInfo.CurrentCulture);
- }
- }
- }
-
- if (axisValuesType == ChartValueType.DateTimeOffset && strValue != null)
- strValue += " +0";
- return strValue;
- }
- /// <summary>
- /// Convert Min and Max values from string if step type is set to one of the DateTime type
- /// </summary>
- /// <param name="context">Descriptor context.</param>
- /// <param name="culture">Culture information.</param>
- /// <param name="value">Value to convert from.</param>
- /// <returns>Converted object.</returns>
- public override object ConvertFrom(ITypeDescriptorContext context, CultureInfo culture, object value)
- {
- object result = null;
- bool convertFromDate = false;
- // If converting from string value
- string crossingValue = value as string;
- if (crossingValue != null)
- {
- if (String.Compare(crossingValue, Constants.NotSetValue, StringComparison.OrdinalIgnoreCase) == 0)
- {
- return Double.NaN;
- }
- }
- // If context interface provided check if we are dealing with DateTime values
- if (context != null && context.Instance != null && context.Instance is Axis)
- {
- // Get axis object
- Axis axis = null;
- if(context.Instance is AxisScaleView)
- {
- axis = ((AxisScaleView)context.Instance).axis;
- }
- else if(context.Instance is Cursor)
- {
- axis = ((Cursor)context.Instance).GetAxis();
- }
- if (axis != null && crossingValue != null)
- {
- if(axis.InternalIntervalType == DateTimeIntervalType.Auto)
- {
- if(axis.GetAxisValuesType() == ChartValueType.DateTime ||
- axis.GetAxisValuesType() == ChartValueType.Date ||
- axis.GetAxisValuesType() == ChartValueType.Time ||
- axis.GetAxisValuesType() == ChartValueType.DateTimeOffset)
- {
- convertFromDate = true;
- }
- }
- else
- {
- if(axis.InternalIntervalType != DateTimeIntervalType.Number)
- {
- convertFromDate = true;
- }
- }
- }
- }
- // Try to convert from double string
- try
- {
- result = base.ConvertFrom(context, culture, value);
- }
- catch (ArgumentException)
- {
- result = null;
- }
- catch (NotSupportedException)
- {
- result = null;
- }
- // Try to convert from date/time string
- if (crossingValue != null && (convertFromDate || result == null))
- {
- DateTime valueAsDate;
- bool parseSucceed = DateTime.TryParse(crossingValue, CultureInfo.InvariantCulture, DateTimeStyles.None, out valueAsDate);
- if (parseSucceed)
- {
- return valueAsDate.ToOADate();
- }
- }
- // Call base converter
- return base.ConvertFrom(context, culture, value);
- }
- #endregion
- }
- }
|