AxisScrollZoom.cs 51 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737
  1. // Licensed to the .NET Foundation under one or more agreements.
  2. // The .NET Foundation licenses this file to you under the MIT license.
  3. // See the LICENSE file in the project root for more information.
  4. //
  5. // Purpose: AxisScaleView class represents a data scaleView, and is
  6. // exposed using the Axis.ScaleView property. A data scaleView is
  7. // a "scaleView" of data that has a start position (represented
  8. // by the Position property) and a size (represented by
  9. // the Size property).
  10. // Axis data scaleView is used in zooming and scrolling when
  11. // only part of the data must be visible. Views always
  12. // belong to an axis, and a scaleView can result from either
  13. // user interaction or by calling the Zoom or Scroll
  14. // methods. User interaction, accomplished using range
  15. // selection along an axis using the mouse, is possible
  16. // if the IsUserSelectionEnabled property of the chart area'
  17. // s cursor property is set to true. The end-user selects
  18. // a range by left-clicking the mouse and dragging the
  19. // mouse, and when the mouse button is released the
  20. // selected range is then displayed as a scaleView.
  21. //
  22. using System;
  23. using System.Collections;
  24. using System.ComponentModel;
  25. using System.Diagnostics.CodeAnalysis;
  26. using System.Globalization;
  27. using FastReport.DataVisualization.Charting.Utilities;
  28. namespace FastReport.DataVisualization.Charting
  29. {
  30. #region Scrolling enumerations
  31. /// <summary>
  32. /// Scrolling type enumeration.
  33. /// </summary>
  34. public enum ScrollType
  35. {
  36. /// <summary>
  37. /// Scrolls by substracting one small size.
  38. /// </summary>
  39. SmallDecrement,
  40. /// <summary>
  41. /// Scrolls by adding one small size.
  42. /// </summary>
  43. SmallIncrement,
  44. /// <summary>
  45. /// Scrolls by substracting one scaleView size.
  46. /// </summary>
  47. LargeDecrement,
  48. /// <summary>
  49. /// Scrolls by adding one scaleView size.
  50. /// </summary>
  51. LargeIncrement,
  52. /// <summary>
  53. /// Scrolls to the first scaleView.
  54. /// </summary>
  55. First,
  56. /// <summary>
  57. /// Scrolls to the last scaleView.
  58. /// </summary>
  59. Last
  60. }
  61. #endregion
  62. /// <summary>
  63. /// AxisScaleView class represents a scale view which allows to display
  64. /// only part of the available data.
  65. /// </summary>
  66. [
  67. SRDescription("DescriptionAttributeAxisDataView_AxisDataView"),
  68. DefaultProperty("Position"),
  69. ]
  70. public class AxisScaleView
  71. {
  72. #region Fields
  73. // Reference to the axis object
  74. internal Axis axis = null;
  75. // Axis data scaleView position
  76. private double _position = double.NaN;
  77. // Axis data scaleView size
  78. private double _size = double.NaN;
  79. // Axis data scaleView size units type
  80. private DateTimeIntervalType _sizeType = DateTimeIntervalType.Auto;
  81. // Axis data scaleView minimum scaleView/scrolling size
  82. private double _minSize = double.NaN;
  83. // Axis data scaleView minimum scaleView/scrolling size units type
  84. private DateTimeIntervalType _minSizeType = DateTimeIntervalType.Auto;
  85. // Axis data scaleView zooming UI interface enabled flag
  86. private bool _zoomable = true;
  87. // Axis data scaleView scroll line size
  88. private double _smallScrollSize = double.NaN;
  89. // Axis data scaleView scroll line size units type
  90. private DateTimeIntervalType _smallScrollSizeType = DateTimeIntervalType.Auto;
  91. // Axis data scaleView scroll line minimum size
  92. private double _smallScrollMinSize = 1.0;
  93. // Axis data scaleView scroll line minimum size units type
  94. private DateTimeIntervalType _smallScrollMinSizeType = DateTimeIntervalType.Auto;
  95. // Axis data scaleView scroll line minimum size
  96. private double _currentSmallScrollSize = double.NaN;
  97. // Axis data scaleView scroll line minimum size units type
  98. private DateTimeIntervalType _currentSmallScrollSizeType = DateTimeIntervalType.Auto;
  99. // Storage for the saved data scaleView states (position/size/sizetype)
  100. internal ArrayList dataViewStates = null;
  101. // Ignore validation flag
  102. private bool _ignoreValidation = false;
  103. #endregion
  104. #region Constructor
  105. /// <summary>
  106. /// Default constructor
  107. /// </summary>
  108. public AxisScaleView()
  109. {
  110. this.axis = null;
  111. }
  112. /// <summary>
  113. /// Internal constructor.
  114. /// </summary>
  115. /// <param name="axis">Data scaleView axis.</param>
  116. internal AxisScaleView(Axis axis)
  117. {
  118. this.axis = axis;
  119. }
  120. #endregion
  121. #region Axis data scaleView properties
  122. /// <summary>
  123. /// Gets or sets the position of the AxisScaleView.
  124. /// </summary>
  125. [
  126. SRCategory("CategoryAttributeAxisView"),
  127. Bindable(true),
  128. DefaultValue(Double.NaN),
  129. SRDescription("DescriptionAttributeAxisDataView_Position"),
  130. TypeConverter(typeof(DoubleDateNanValueConverter)),
  131. ParenthesizePropertyNameAttribute(true)
  132. ]
  133. public double Position
  134. {
  135. get
  136. {
  137. // Axis scaleView is not supported in circular chrt areas
  138. if(this.axis != null && this.axis.ChartArea != null && this.axis.ChartArea.chartAreaIsCurcular)
  139. {
  140. return Double.NaN;
  141. }
  142. return _position;
  143. }
  144. set
  145. {
  146. // Axis scaleView is not supported in circular chrt areas
  147. if(this.axis != null && this.axis.ChartArea != null && this.axis.ChartArea.chartAreaIsCurcular)
  148. {
  149. return;
  150. }
  151. if(_position != value)
  152. {
  153. // Set new position
  154. _position = value;
  155. // Align scaleView in connected areas
  156. if(this.axis != null && this.axis.ChartArea != null && this.axis.Common != null && this.axis.Common.ChartPicture != null)
  157. {
  158. if(!this.axis.ChartArea.alignmentInProcess)
  159. {
  160. AreaAlignmentOrientations orientation = (this.axis.axisType == AxisName.X || this.axis.axisType== AxisName.X2) ?
  161. AreaAlignmentOrientations.Vertical : AreaAlignmentOrientations.Horizontal;
  162. this.axis.Common.ChartPicture.AlignChartAreasAxesView(this.axis.ChartArea, orientation);
  163. }
  164. }
  165. // Validate chart
  166. if(!_ignoreValidation && axis != null)
  167. {
  168. axis.Invalidate();
  169. }
  170. axis.CallOnModifing();
  171. }
  172. }
  173. }
  174. /// <summary>
  175. /// Gets or sets the size of the AxisScaleView
  176. /// </summary>
  177. [
  178. SRCategory("CategoryAttributeAxisView"),
  179. Bindable(true),
  180. DefaultValue(Double.NaN),
  181. SRDescription("DescriptionAttributeAxisDataView_Size"),
  182. TypeConverter(typeof(DoubleNanValueConverter)),
  183. ParenthesizePropertyNameAttribute(true)
  184. ]
  185. public double Size
  186. {
  187. get
  188. {
  189. // Axis scaleView is not supported in circular chrt areas
  190. if(this.axis != null && this.axis.ChartArea != null && this.axis.ChartArea.chartAreaIsCurcular)
  191. {
  192. return Double.NaN;
  193. }
  194. return _size;
  195. }
  196. set
  197. {
  198. // Axis scaleView is not supported in circular chrt areas
  199. if(this.axis != null && this.axis.ChartArea != null && this.axis.ChartArea.chartAreaIsCurcular)
  200. {
  201. return;
  202. }
  203. if(_size != value)
  204. {
  205. // Set size value
  206. _size = value;
  207. // Align scaleView in connected areas
  208. if(this.axis != null && this.axis.ChartArea != null && this.axis.Common != null && this.axis.Common.ChartPicture != null)
  209. {
  210. if(!this.axis.ChartArea.alignmentInProcess)
  211. {
  212. AreaAlignmentOrientations orientation = (this.axis.axisType == AxisName.X || this.axis.axisType== AxisName.X2) ?
  213. AreaAlignmentOrientations.Vertical : AreaAlignmentOrientations.Horizontal;
  214. this.axis.Common.ChartPicture.AlignChartAreasAxesView(this.axis.ChartArea, orientation);
  215. }
  216. }
  217. // Reset current scrolling line size
  218. this._currentSmallScrollSize = double.NaN;
  219. // Validate chart
  220. if(!_ignoreValidation && axis != null)
  221. {
  222. axis.Invalidate();
  223. }
  224. axis.CallOnModifing();
  225. }
  226. }
  227. }
  228. /// <summary>
  229. /// Gets or sets the unit of measurement of the Size property.
  230. /// </summary>
  231. [
  232. SRCategory("CategoryAttributeAxisView"),
  233. Bindable(true),
  234. DefaultValue(DateTimeIntervalType.Auto),
  235. SRDescription("DescriptionAttributeAxisDataView_SizeType"),
  236. ParenthesizePropertyNameAttribute(true)
  237. ]
  238. public DateTimeIntervalType SizeType
  239. {
  240. get
  241. {
  242. return _sizeType;
  243. }
  244. set
  245. {
  246. if(_sizeType != value)
  247. {
  248. // Set size type
  249. _sizeType = (value != DateTimeIntervalType.NotSet) ? value : DateTimeIntervalType.Auto;
  250. // Align scaleView in connected areas
  251. if(this.axis != null && this.axis.ChartArea != null && this.axis.Common != null && this.axis.Common.ChartPicture != null)
  252. {
  253. if(!this.axis.ChartArea.alignmentInProcess)
  254. {
  255. AreaAlignmentOrientations orientation = (this.axis.axisType == AxisName.X || this.axis.axisType== AxisName.X2) ?
  256. AreaAlignmentOrientations.Vertical : AreaAlignmentOrientations.Horizontal;
  257. this.axis.Common.ChartPicture.AlignChartAreasAxesView(this.axis.ChartArea, orientation);
  258. }
  259. }
  260. // Validate chart
  261. if(!_ignoreValidation && axis != null)
  262. {
  263. axis.Invalidate();
  264. }
  265. if(axis != null)
  266. {
  267. axis.CallOnModifing();
  268. }
  269. }
  270. }
  271. }
  272. /// <summary>
  273. /// Indicates if axis is zoomed-in.
  274. /// </summary>
  275. [
  276. SRCategory("CategoryAttributeAxisView"),
  277. Bindable(false),
  278. Browsable(false),
  279. SRDescription("DescriptionAttributeAxisDataView_IsZoomed"),
  280. DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden),
  281. SerializationVisibility(SerializationVisibility.Hidden),
  282. ]
  283. public bool IsZoomed
  284. {
  285. get
  286. {
  287. return (
  288. !double.IsNaN(this.Size) &&
  289. this.Size != 0.0 &&
  290. !double.IsNaN(this.Position));
  291. }
  292. }
  293. /// <summary>
  294. /// Gets or sets the minimum size of the AxisScaleView.
  295. /// </summary>
  296. [
  297. SRCategory("CategoryAttributeAxisView"),
  298. Bindable(true),
  299. DefaultValue(Double.NaN),
  300. SRDescription("DescriptionAttributeAxisDataView_MinSize"),
  301. TypeConverter(typeof(DoubleNanValueConverter))
  302. ]
  303. public double MinSize
  304. {
  305. get
  306. {
  307. return _minSize;
  308. }
  309. set
  310. {
  311. _minSize = value;
  312. if (axis != null)
  313. {
  314. axis.CallOnModifing();
  315. }
  316. }
  317. }
  318. /// <summary>
  319. /// Gets or sets the unit of measurement of the MinSize property.
  320. /// </summary>
  321. [
  322. SRCategory("CategoryAttributeAxisView"),
  323. Bindable(true),
  324. DefaultValue(DateTimeIntervalType.Auto),
  325. SRDescription("DescriptionAttributeAxisDataView_MinSizeType"),
  326. ]
  327. public DateTimeIntervalType MinSizeType
  328. {
  329. get
  330. {
  331. return _minSizeType;
  332. }
  333. set
  334. {
  335. _minSizeType = (value != DateTimeIntervalType.NotSet) ? value : DateTimeIntervalType.Auto;
  336. if (axis != null)
  337. {
  338. axis.CallOnModifing();
  339. }
  340. }
  341. }
  342. /// <summary>
  343. /// Gets or sets a flag which indicates whether the zooming user interface is enabled.
  344. /// </summary>
  345. [
  346. SRCategory("CategoryAttributeAxisView"),
  347. Bindable(true),
  348. DefaultValue(true),
  349. SRDescription("DescriptionAttributeAxisDataView_Zoomable"),
  350. SuppressMessage("Microsoft.Naming", "CA1704:IdentifiersShouldBeSpelledCorrectly",
  351. Justification="'Zoomable' is a commonly used term and generally well understood"),
  352. ]
  353. public bool Zoomable
  354. {
  355. get
  356. {
  357. return _zoomable;
  358. }
  359. set
  360. {
  361. _zoomable = value;
  362. if (axis != null)
  363. {
  364. axis.CallOnModifing();
  365. }
  366. }
  367. }
  368. /// <summary>
  369. /// Gets or sets the small scrolling size.
  370. /// </summary>
  371. [
  372. SRCategory("CategoryAttributeAxisView"),
  373. Bindable(true),
  374. DefaultValue(Double.NaN),
  375. SRDescription("DescriptionAttributeAxisDataView_SmallScrollSize"),
  376. TypeConverter(typeof(AxisMinMaxAutoValueConverter))
  377. ]
  378. public double SmallScrollSize
  379. {
  380. get
  381. {
  382. return _smallScrollSize;
  383. }
  384. set
  385. {
  386. if(_smallScrollSize != value)
  387. {
  388. // Set size value
  389. _smallScrollSize = value;
  390. // Validate chart
  391. if(!_ignoreValidation && axis != null)
  392. {
  393. axis.Invalidate();
  394. }
  395. if (axis != null)
  396. {
  397. axis.CallOnModifing();
  398. }
  399. }
  400. }
  401. }
  402. /// <summary>
  403. /// Gets or sets the unit of measurement for the SmallScrollMinSize property
  404. /// </summary>
  405. [
  406. SRCategory("CategoryAttributeAxisView"),
  407. Bindable(true),
  408. DefaultValue(DateTimeIntervalType.Auto),
  409. SRDescription("DescriptionAttributeAxisDataView_SmallScrollSizeType"),
  410. ]
  411. public DateTimeIntervalType SmallScrollSizeType
  412. {
  413. get
  414. {
  415. return _smallScrollSizeType;
  416. }
  417. set
  418. {
  419. if(_smallScrollSizeType != value)
  420. {
  421. // Set size type
  422. _smallScrollSizeType = (value != DateTimeIntervalType.NotSet) ? value : DateTimeIntervalType.Auto;
  423. // Validate chart
  424. if(!_ignoreValidation && axis != null)
  425. {
  426. axis.Invalidate();
  427. }
  428. if (axis != null)
  429. {
  430. axis.CallOnModifing();
  431. }
  432. }
  433. }
  434. }
  435. /// <summary>
  436. /// Gets or sets the minimum small scrolling size.
  437. /// Only used if the small scrolling size is not set.
  438. /// </summary>
  439. [
  440. SRCategory("CategoryAttributeAxisView"),
  441. Bindable(true),
  442. DefaultValue(1.0),
  443. SRDescription("DescriptionAttributeAxisDataView_SmallScrollMinSize")
  444. ]
  445. public double SmallScrollMinSize
  446. {
  447. get
  448. {
  449. return _smallScrollMinSize;
  450. }
  451. set
  452. {
  453. if(_smallScrollMinSize != value)
  454. {
  455. // Set size value
  456. _smallScrollMinSize = value;
  457. _currentSmallScrollSize = double.NaN;
  458. // Validate chart
  459. if(!_ignoreValidation && axis != null)
  460. {
  461. axis.Invalidate();
  462. }
  463. if (axis != null)
  464. {
  465. axis.CallOnModifing();
  466. }
  467. }
  468. }
  469. }
  470. /// <summary>
  471. /// Gets or sets the unit of measurement for the SmallScrollMinSize property.
  472. /// </summary>
  473. [
  474. SRCategory("CategoryAttributeAxisView"),
  475. Bindable(true),
  476. DefaultValue(DateTimeIntervalType.Auto),
  477. SRDescription("DescriptionAttributeAxisDataView_SmallScrollMinSizeType"),
  478. ]
  479. public DateTimeIntervalType SmallScrollMinSizeType
  480. {
  481. get
  482. {
  483. return _smallScrollMinSizeType;
  484. }
  485. set
  486. {
  487. if(_smallScrollMinSizeType != value)
  488. {
  489. // Set size type
  490. _smallScrollMinSizeType = (value != DateTimeIntervalType.NotSet) ? value : DateTimeIntervalType.Auto;
  491. _currentSmallScrollSize = double.NaN;
  492. // Validate chart
  493. if(!_ignoreValidation && axis != null)
  494. {
  495. axis.Invalidate();
  496. }
  497. if (axis != null)
  498. {
  499. axis.CallOnModifing();
  500. }
  501. }
  502. }
  503. }
  504. #endregion
  505. #region ScaleView position internal methods
  506. /// <summary>
  507. /// Call this method to get the minimum axis value of a data view.
  508. /// </summary>
  509. /// <returns>The minimum axis value for the data view.</returns>
  510. [Browsable(false)]
  511. [Utilities.SerializationVisibility(Utilities.SerializationVisibility.Hidden)]
  512. public double ViewMinimum
  513. {
  514. get
  515. {
  516. // If zooming is enabled
  517. if (!Double.IsNaN(this.Size))
  518. {
  519. // If size set only use axis minimum for scaleView position
  520. if (Double.IsNaN(this.Position))
  521. {
  522. this.Position = this.axis.Minimum;
  523. }
  524. // Check if scaleView position and size are set
  525. else
  526. {
  527. // Calculate and add axis side margin
  528. if (this.Position <= axis.minimum)
  529. {
  530. return this.Position;
  531. }
  532. else // Add a margin only if scaleView is inside data point scaleView
  533. {
  534. return this.Position - axis.marginView;
  535. }
  536. }
  537. }
  538. // Return axis scale minimum value if scaleView position is not set
  539. return axis.minimum;
  540. }
  541. }
  542. /// <summary>
  543. /// Maximum axis value of a data view.
  544. /// </summary>
  545. /// <returns>The maximum axis value for the data view.</returns>
  546. [Browsable(false)]
  547. [Utilities.SerializationVisibility(Utilities.SerializationVisibility.Hidden)]
  548. public double ViewMaximum
  549. {
  550. get
  551. {
  552. // If zooming is enabled
  553. if (!Double.IsNaN(this.Size))
  554. {
  555. // If size set only use axis minimum for scaleView position
  556. if (Double.IsNaN(this.Position))
  557. {
  558. this.Position = this.axis.Minimum;
  559. }
  560. // Check if scaleView position and size are set
  561. else
  562. {
  563. // Get axis interval
  564. double viewSize = ChartHelper.GetIntervalSize(this.Position, this.Size, this.SizeType);
  565. // Calculate and add axis side margin
  566. if (this.Position + viewSize >= axis.maximum)
  567. {
  568. return this.Position + viewSize;
  569. }
  570. else // Add a margin only if scaleView is inside data point scaleView
  571. {
  572. return this.Position + viewSize + axis.marginView;
  573. }
  574. }
  575. }
  576. // Return axis scale maximum value if scaleView position is not set
  577. return axis.maximum;
  578. }
  579. }
  580. #endregion
  581. #region Scrolling methods
  582. /// <summary>
  583. /// Call this method to scroll to a specified position along an axis.
  584. /// </summary>
  585. /// <param name="scrollType">Direction and size to scroll.</param>
  586. public void Scroll(ScrollType scrollType)
  587. {
  588. this.Scroll(scrollType, false);
  589. }
  590. /// <summary>
  591. /// Scrolls axis data scaleView from current position.
  592. /// </summary>
  593. /// <param name="scrollType">Direction and size to scroll.</param>
  594. /// <param name="fireChangeEvents">Fire scaleView position events from this method.</param>
  595. internal void Scroll(ScrollType scrollType, bool fireChangeEvents)
  596. {
  597. // Adjust current position depending on the scroll type
  598. double newPosition = this._position;
  599. switch(scrollType)
  600. {
  601. case(ScrollType.SmallIncrement):
  602. newPosition += ((axis.IsReversed) ? -1 : 1) * ChartHelper.GetIntervalSize(this._position, this.GetScrollingLineSize(), this.GetScrollingLineSizeType());
  603. break;
  604. case(ScrollType.SmallDecrement):
  605. newPosition -= ((axis.IsReversed) ? -1 : 1) * ChartHelper.GetIntervalSize(this._position, this.GetScrollingLineSize(), this.GetScrollingLineSizeType());
  606. break;
  607. case(ScrollType.LargeIncrement):
  608. newPosition += ((axis.IsReversed) ? -1 : 1) * ChartHelper.GetIntervalSize(this._position, this.Size, this.SizeType);
  609. break;
  610. case(ScrollType.LargeDecrement):
  611. newPosition -= ((axis.IsReversed) ? -1 : 1) * ChartHelper.GetIntervalSize(this._position, this.Size, this.SizeType);
  612. break;
  613. case(ScrollType.First):
  614. if(!axis.IsReversed)
  615. {
  616. newPosition = (axis.minimum + axis.marginView);
  617. }
  618. else
  619. {
  620. newPosition = (axis.maximum - axis.marginView);
  621. }
  622. break;
  623. case(ScrollType.Last):
  624. {
  625. double viewSize = ChartHelper.GetIntervalSize(newPosition, this.Size, this.SizeType);
  626. if(!axis.IsReversed)
  627. {
  628. newPosition = (axis.maximum - axis.marginView - viewSize);
  629. }
  630. else
  631. {
  632. newPosition = (axis.minimum + axis.marginView + viewSize);
  633. }
  634. break;
  635. }
  636. }
  637. // Scroll to the new position
  638. this.Scroll(newPosition, fireChangeEvents);
  639. }
  640. /// <summary>
  641. /// Call this method to scroll to a specified position along an axis.
  642. /// </summary>
  643. /// <param name="newPosition">New position.</param>
  644. public void Scroll(double newPosition)
  645. {
  646. this.Scroll(newPosition, false);
  647. }
  648. /// <summary>
  649. /// Call this method to scroll to a specified position along an axis.
  650. /// </summary>
  651. /// <param name="newPosition">New position.</param>
  652. public void Scroll(DateTime newPosition)
  653. {
  654. this.Scroll(newPosition.ToOADate(), false);
  655. }
  656. /// <summary>
  657. /// Internal helper method for scrolling into specified position.
  658. /// </summary>
  659. /// <param name="newPosition">New data scaleView position.</param>
  660. /// <param name="fireChangeEvents">Fire scaleView position events from this method.</param>
  661. internal void Scroll(double newPosition, bool fireChangeEvents)
  662. {
  663. // Get current scaleView size
  664. double viewSize = ChartHelper.GetIntervalSize(newPosition, this.Size, this.SizeType);
  665. // Validate new scaleView position
  666. if(newPosition < (axis.minimum + axis.marginView))
  667. {
  668. newPosition = (axis.minimum + axis.marginView);
  669. }
  670. else if(newPosition > (axis.maximum - axis.marginView - viewSize))
  671. {
  672. newPosition = (axis.maximum - axis.marginView - viewSize);
  673. }
  674. // Fire scaleView position changing events
  675. ViewEventArgs arguments = new ViewEventArgs(this.axis, newPosition, this.Size, this.SizeType);
  676. if(fireChangeEvents && GetChartObject() != null)
  677. {
  678. GetChartObject().OnAxisViewChanging(arguments);
  679. newPosition = arguments.NewPosition;
  680. }
  681. // Check if data scaleView position and size is different from current
  682. if(newPosition == this.Position)
  683. {
  684. return;
  685. }
  686. // Change scaleView position
  687. this.Position = newPosition;
  688. // Fire scaleView position changed events
  689. if(fireChangeEvents && GetChartObject() != null)
  690. {
  691. GetChartObject().OnAxisViewChanged(arguments);
  692. }
  693. }
  694. #endregion
  695. #region Zooming and ZoomResetting methods
  696. /// <summary>
  697. /// Sets a new axis data view/position based on the start and end dates specified.
  698. /// </summary>
  699. /// <param name="viewPosition">New start position for the axis scale view.</param>
  700. /// <param name="viewSize">New size for the axis scale view.</param>
  701. /// <param name="viewSizeType">New unit of measurement of the size.</param>
  702. /// <param name="saveState">Indicates whether the current size/position needs to be saved.</param>
  703. public void Zoom(double viewPosition, double viewSize, DateTimeIntervalType viewSizeType, bool saveState)
  704. {
  705. this.Zoom(viewPosition, viewSize, viewSizeType, false, saveState);
  706. }
  707. /// <summary>
  708. /// Sets a new axis data view/position based on the specified start and end values.
  709. /// </summary>
  710. /// <param name="viewStart">New start position for the axis scale view.</param>
  711. /// <param name="viewEnd">New end position for the axis scale view.</param>
  712. public void Zoom(double viewStart, double viewEnd)
  713. {
  714. this.Zoom(viewStart, viewEnd - viewStart, DateTimeIntervalType.Number, false, false);
  715. }
  716. /// <summary>
  717. /// Sets a new axis data view/position based on the start and end dates specified.
  718. /// </summary>
  719. /// <param name="viewPosition">New start position for the axis scale view.</param>
  720. /// <param name="viewSize">New size for the axis scale view.</param>
  721. /// <param name="viewSizeType">New unit of measurement of the size.</param>
  722. public void Zoom(double viewPosition, double viewSize, DateTimeIntervalType viewSizeType)
  723. {
  724. this.Zoom(viewPosition, viewSize, viewSizeType, false, false);
  725. }
  726. /// <summary>
  727. /// Reset the specified number of zooming operations by restoring axis data view.
  728. /// </summary>
  729. /// <param name="numberOfViews">Number of zoom operations to reset. Zero for all.</param>
  730. public void ZoomReset(int numberOfViews)
  731. {
  732. this.LoadDataViewState(numberOfViews, false);
  733. }
  734. /// <summary>
  735. /// Reset one zooming operation by restoring axis data view.
  736. /// </summary>
  737. public void ZoomReset()
  738. {
  739. this.LoadDataViewState(1, false);
  740. }
  741. /// <summary>
  742. /// Reset several zooming operation by restoring data scaleView size/position.
  743. /// </summary>
  744. /// <param name="numberOfViews">How many scaleView zoom operations to reset. Zero for all.</param>
  745. /// <param name="fireChangeEvents">Fire scaleView position events from this method.</param>
  746. internal void ZoomReset(int numberOfViews, bool fireChangeEvents)
  747. {
  748. this.LoadDataViewState(numberOfViews, fireChangeEvents);
  749. }
  750. /// <summary>
  751. /// Internal helper zooming method.
  752. /// </summary>
  753. /// <param name="viewPosition">New data scaleView start posiion.</param>
  754. /// <param name="viewSize">New data scaleView size.</param>
  755. /// <param name="viewSizeType">New data scaleView size units type.</param>
  756. /// <param name="fireChangeEvents">Fire scaleView position events from this method.</param>
  757. /// <param name="saveState">Indicates that current scaleView size/position must be save, so it can be restored later.</param>
  758. /// <returns>True if zoom operation was made.</returns>
  759. internal bool Zoom(
  760. double viewPosition,
  761. double viewSize,
  762. DateTimeIntervalType viewSizeType,
  763. bool fireChangeEvents,
  764. bool saveState)
  765. {
  766. // Validate new scaleView position and size
  767. ValidateViewPositionSize(ref viewPosition, ref viewSize, ref viewSizeType);
  768. // Fire scaleView position/size changing events
  769. ViewEventArgs arguments = new ViewEventArgs(this.axis, viewPosition, viewSize, viewSizeType);
  770. if(fireChangeEvents && GetChartObject() != null)
  771. {
  772. GetChartObject().OnAxisViewChanging(arguments);
  773. viewPosition = arguments.NewPosition;
  774. viewSize = arguments.NewSize;
  775. viewSizeType = arguments.NewSizeType;
  776. }
  777. // Check if data scaleView position and size is different from current
  778. if(viewPosition == this.Position &&
  779. viewSize == this.Size &&
  780. viewSizeType == this.SizeType)
  781. {
  782. return false;
  783. }
  784. // Save current data scaleView state, so it can be restored
  785. if(saveState)
  786. {
  787. SaveDataViewState();
  788. }
  789. // Change scaleView position/size
  790. this._ignoreValidation = true;
  791. this.Position = viewPosition;
  792. this.Size = viewSize;
  793. this.SizeType = viewSizeType;
  794. this._ignoreValidation = false;
  795. // Reset current scrolling line size
  796. this._currentSmallScrollSize = double.NaN;
  797. // Invalidate chart
  798. axis.Invalidate();
  799. // Fire scaleView position/size changed events
  800. if(fireChangeEvents && GetChartObject() != null)
  801. {
  802. GetChartObject().OnAxisViewChanged(arguments);
  803. }
  804. return true;
  805. }
  806. #endregion
  807. #region Data scaleView state saving/restoring methods
  808. /// <summary>
  809. /// Saves current data scaleView position/size/sizetype, so
  810. /// it can be restored later.
  811. /// </summary>
  812. /// <param name="numberOfViews">Number of time to reset zoom. Zero for all.</param>
  813. /// <param name="fireChangeEvents">Fire scaleView position events from this method.</param>
  814. private void LoadDataViewState(int numberOfViews, bool fireChangeEvents)
  815. {
  816. // Check parameters
  817. if(numberOfViews < 0)
  818. {
  819. throw (new ArgumentOutOfRangeException("numberOfViews", SR.ExceptionScrollBarZoomResetsNumberInvalid));
  820. }
  821. // Check if storage was created
  822. if(dataViewStates != null && dataViewStates.Count >= 3)
  823. {
  824. // Find starting index of restoring state
  825. int dataStartIndex = 0;
  826. if(numberOfViews > 0)
  827. {
  828. dataStartIndex = dataViewStates.Count - numberOfViews * 3;
  829. if(dataStartIndex < 0)
  830. {
  831. dataStartIndex = 0;
  832. }
  833. }
  834. // Fire scaleView position/size changing events
  835. ViewEventArgs arguments = new ViewEventArgs(
  836. this.axis,
  837. (double)dataViewStates[dataStartIndex],
  838. (double)dataViewStates[dataStartIndex + 1],
  839. (DateTimeIntervalType)dataViewStates[dataStartIndex + 2]);
  840. if(fireChangeEvents && GetChartObject() != null)
  841. {
  842. GetChartObject().OnAxisViewChanging(arguments);
  843. }
  844. // Restore data
  845. this.Position = arguments.NewPosition;
  846. this.Size = arguments.NewSize;
  847. this.SizeType = arguments.NewSizeType;
  848. // Fire scaleView position/size changed events
  849. if(fireChangeEvents && GetChartObject() != null)
  850. {
  851. GetChartObject().OnAxisViewChanged(arguments);
  852. }
  853. // Clear data
  854. int itemsToRemove = numberOfViews * 3;
  855. if (itemsToRemove > (dataViewStates.Count - dataStartIndex))
  856. {
  857. itemsToRemove = dataViewStates.Count - dataStartIndex;
  858. }
  859. dataViewStates.RemoveRange(dataStartIndex, itemsToRemove);
  860. // clean up the history state when the numberOfViews == 0 (reset all by docs)
  861. if ( numberOfViews == 0 )
  862. {
  863. dataViewStates.Clear();
  864. }
  865. if (Double.IsNaN(this.Position) || Double.IsNaN(this.Size))
  866. {
  867. this.Position = Double.NaN;
  868. this.Size = Double.NaN;
  869. }
  870. }
  871. // Nothing to restore - just disable the data scaleView
  872. else
  873. {
  874. // Fire scaleView position/size changing events
  875. ViewEventArgs arguments = new ViewEventArgs(
  876. this.axis,
  877. double.NaN,
  878. double.NaN,
  879. DateTimeIntervalType.Auto);
  880. if(fireChangeEvents && GetChartObject() != null)
  881. {
  882. GetChartObject().OnAxisViewChanging(arguments);
  883. }
  884. // Restore data
  885. this.Position = arguments.NewPosition;
  886. this.Size = arguments.NewSize;
  887. this.SizeType = arguments.NewSizeType;
  888. // Fire scaleView position/size changed events
  889. if(fireChangeEvents && GetChartObject() != null)
  890. {
  891. GetChartObject().OnAxisViewChanged(arguments);
  892. }
  893. }
  894. // clear cached chart areas and bitmap buffers
  895. GetChartObject().Refresh();
  896. }
  897. /// <summary>
  898. /// Saves current data scaleView position/size/sizetype, so
  899. /// it can be restored later.
  900. /// </summary>
  901. private void SaveDataViewState()
  902. {
  903. // Create storage array
  904. if(dataViewStates == null)
  905. {
  906. dataViewStates = new ArrayList();
  907. }
  908. // Save data scaleView state
  909. dataViewStates.Add(this.Position);
  910. dataViewStates.Add(this.Size);
  911. dataViewStates.Add(this.SizeType);
  912. }
  913. #endregion
  914. #region Helper methods
  915. /// <summary>
  916. /// Initialize internal scrolling line size variables for later use.
  917. /// This size is used in to scroll chart one line up or down.
  918. /// </summary>
  919. private void GetCurrentViewSmallScrollSize()
  920. {
  921. //**************************************************************************
  922. //** Check if current scrolling line size was not already calculated
  923. //**************************************************************************
  924. if(double.IsNaN(_currentSmallScrollSize))
  925. {
  926. //**************************************************************************
  927. //** Calculate line size depending on the current scaleView size
  928. //**************************************************************************
  929. if(this.SizeType == DateTimeIntervalType.Auto || this.SizeType == DateTimeIntervalType.Number)
  930. {
  931. // Set line size type
  932. _currentSmallScrollSizeType = DateTimeIntervalType.Number;
  933. // Devide scaleView by 20 to find the scrolling line size
  934. double newSize = this.Size / 20.0;
  935. // Make sure that current line size is even with minimum value
  936. if(!double.IsNaN(this.SmallScrollMinSize) && this.SmallScrollMinSize != 0.0)
  937. {
  938. double rounder = (Math.Round(newSize / this.SmallScrollMinSize));
  939. if(rounder < 0)
  940. {
  941. rounder = 1;
  942. }
  943. newSize = rounder * this.SmallScrollMinSize;
  944. }
  945. // Set new current line size
  946. this._currentSmallScrollSize = newSize;
  947. }
  948. else
  949. {
  950. // Calculate line size for date/time
  951. double viewEndPosition = this.Position + ChartHelper.GetIntervalSize(this.Position, this.Size, this.SizeType);
  952. _currentSmallScrollSize = axis.CalcInterval(
  953. this.Position,
  954. viewEndPosition,
  955. true,
  956. out _currentSmallScrollSizeType,
  957. ChartValueType.Auto);
  958. }
  959. //**************************************************************************
  960. //** Make sure calculated scroll line size is not smaller than the minimum
  961. //**************************************************************************
  962. if(!double.IsNaN(this.SmallScrollMinSize) && this.SmallScrollMinSize != 0.0)
  963. {
  964. double newLineSize = ChartHelper.GetIntervalSize(this.Position, _currentSmallScrollSize, _currentSmallScrollSizeType);
  965. double minLineSize = ChartHelper.GetIntervalSize(this.Position, this.SmallScrollMinSize, this.SmallScrollMinSizeType);
  966. if(newLineSize < minLineSize)
  967. {
  968. _currentSmallScrollSize = SmallScrollMinSize;
  969. _currentSmallScrollSizeType = SmallScrollMinSizeType;
  970. }
  971. }
  972. }
  973. }
  974. /// <summary>
  975. /// Returns the scroll line size.
  976. /// </summary>
  977. /// <returns>Scroll line size.</returns>
  978. internal double GetScrollingLineSize()
  979. {
  980. // Scroll line size/type is specificly set by user
  981. if(!double.IsNaN(this.SmallScrollSize))
  982. {
  983. return this.SmallScrollSize;
  984. }
  985. // Calcualte scroll line size depending on the current scaleView size
  986. GetCurrentViewSmallScrollSize();
  987. // Return line size
  988. return _currentSmallScrollSize;
  989. }
  990. /// <summary>
  991. /// Returns the scroll line size units type.
  992. /// </summary>
  993. /// <returns>Scroll line size units type.</returns>
  994. internal DateTimeIntervalType GetScrollingLineSizeType()
  995. {
  996. // Scroll line size/type is specificly set by user
  997. if(!double.IsNaN(this.SmallScrollSize))
  998. {
  999. return this.SmallScrollSizeType;
  1000. }
  1001. // Calcualte scroll line size depending on the current scaleView size
  1002. GetCurrentViewSmallScrollSize();
  1003. // Return line size units type
  1004. return _currentSmallScrollSizeType;
  1005. }
  1006. /// <summary>
  1007. /// Helper method, which validates the axis data scaleView position and size.
  1008. /// Returns adjusted scaleView position and size.
  1009. /// </summary>
  1010. /// <param name="viewPosition">ScaleView position.</param>
  1011. /// <param name="viewSize">ScaleView size.</param>
  1012. /// <param name="viewSizeType">ScaleView size units type.</param>
  1013. private void ValidateViewPositionSize(ref double viewPosition, ref double viewSize, ref DateTimeIntervalType viewSizeType)
  1014. {
  1015. //****************************************************************
  1016. //** Check if new scaleView position is inside axis scale
  1017. //** minimum/maximum without margin.
  1018. //****************************************************************
  1019. if(viewPosition < (axis.minimum + axis.marginView))
  1020. {
  1021. if(viewSizeType == DateTimeIntervalType.Auto || viewSizeType == DateTimeIntervalType.Number)
  1022. {
  1023. viewSize -= (axis.minimum + axis.marginView) - viewPosition;
  1024. }
  1025. viewPosition = (axis.minimum + axis.marginView);
  1026. }
  1027. else if(viewPosition > (axis.maximum - axis.marginView))
  1028. {
  1029. if(viewSizeType == DateTimeIntervalType.Auto || viewSizeType == DateTimeIntervalType.Number)
  1030. {
  1031. viewSize -= viewPosition - (axis.maximum - axis.marginView);
  1032. }
  1033. viewPosition = (axis.maximum - axis.marginView);
  1034. }
  1035. //****************************************************************
  1036. //** Check if new scaleView size is not smaller than minimum size
  1037. //** set by the user
  1038. //****************************************************************
  1039. double newViewSize = ChartHelper.GetIntervalSize(viewPosition, viewSize, viewSizeType);
  1040. double minViewSize = ChartHelper.GetIntervalSize(viewPosition, 1, this.MinSizeType);
  1041. if(!double.IsNaN(this.MinSize))
  1042. {
  1043. minViewSize = ChartHelper.GetIntervalSize(viewPosition, this.MinSize, this.MinSizeType);
  1044. if(newViewSize < minViewSize)
  1045. {
  1046. viewSize = (double.IsNaN(this.MinSize)) ? 1 : this.MinSize;
  1047. viewSizeType = this.MinSizeType;
  1048. newViewSize = ChartHelper.GetIntervalSize(viewPosition, viewSize, viewSizeType);
  1049. }
  1050. }
  1051. //****************************************************************
  1052. //** Check if new scaleView size is smaller than (0.000000001)
  1053. //****************************************************************
  1054. if(newViewSize < 0.000000001)
  1055. {
  1056. viewSize = 0.000000001;
  1057. viewSizeType = DateTimeIntervalType.Number;
  1058. newViewSize = ChartHelper.GetIntervalSize(viewPosition, viewSize, viewSizeType);
  1059. }
  1060. //****************************************************************
  1061. //** Check if new scaleView end position (position + size) is inside
  1062. //** axis scale minimum/maximum without margin.
  1063. //****************************************************************
  1064. while( (viewPosition + newViewSize) > (axis.maximum - axis.marginView) )
  1065. {
  1066. double currentSize = viewSize;
  1067. DateTimeIntervalType currentSizeType = viewSizeType;
  1068. // Try to reduce the scaleView size
  1069. if(newViewSize > minViewSize)
  1070. {
  1071. // Try to adjust the scaleView size
  1072. if(viewSize > 1)
  1073. {
  1074. --viewSize;
  1075. }
  1076. else if(viewSizeType == DateTimeIntervalType.Years)
  1077. {
  1078. viewSize = 11;
  1079. viewSizeType = DateTimeIntervalType.Months;
  1080. }
  1081. else if(viewSizeType == DateTimeIntervalType.Months)
  1082. {
  1083. viewSize = 4;
  1084. viewSizeType = DateTimeIntervalType.Weeks;
  1085. }
  1086. else if(viewSizeType == DateTimeIntervalType.Weeks)
  1087. {
  1088. viewSize = 6;
  1089. viewSizeType = DateTimeIntervalType.Days;
  1090. }
  1091. else if(viewSizeType == DateTimeIntervalType.Days)
  1092. {
  1093. viewSize = 23;
  1094. viewSizeType = DateTimeIntervalType.Hours;
  1095. }
  1096. else if(viewSizeType == DateTimeIntervalType.Hours)
  1097. {
  1098. viewSize = 59;
  1099. viewSizeType = DateTimeIntervalType.Minutes;
  1100. }
  1101. else if(viewSizeType == DateTimeIntervalType.Minutes)
  1102. {
  1103. viewSize = 59;
  1104. viewSizeType = DateTimeIntervalType.Seconds;
  1105. }
  1106. else if(viewSizeType == DateTimeIntervalType.Seconds)
  1107. {
  1108. viewSize = 999;
  1109. viewSizeType = DateTimeIntervalType.Milliseconds;
  1110. }
  1111. else
  1112. {
  1113. viewPosition = (axis.maximum - axis.marginView) - minViewSize;
  1114. break;
  1115. }
  1116. // Double check that scaleView size is not smaller than min size
  1117. newViewSize = ChartHelper.GetIntervalSize(viewPosition, viewSize, viewSizeType);
  1118. if(newViewSize < minViewSize)
  1119. {
  1120. // Can't adjust size no more (restore prev. value)
  1121. viewSize = currentSize;
  1122. viewSizeType = currentSizeType;
  1123. // Adjust the start position
  1124. viewPosition = (axis.maximum - axis.marginView) - minViewSize;
  1125. break;
  1126. }
  1127. }
  1128. else
  1129. {
  1130. // Adjust the start position
  1131. viewPosition = (axis.maximum - axis.marginView) - newViewSize;
  1132. break;
  1133. }
  1134. }
  1135. }
  1136. /// <summary>
  1137. /// Helper function which returns a reference to the chart object.
  1138. /// </summary>
  1139. /// <returns>Chart object reference.</returns>
  1140. internal Chart GetChartObject()
  1141. {
  1142. if(this.axis != null && this.axis.Common!=null)
  1143. {
  1144. return this.axis.Common.Chart;
  1145. }
  1146. return null;
  1147. }
  1148. #endregion
  1149. }
  1150. /// <summary>
  1151. /// This class is used as a parameter object in the AxisViewChanged and AxisViewChanging events of the root Chart object.
  1152. /// </summary>
  1153. public class ViewEventArgs : EventArgs
  1154. {
  1155. #region Private fields
  1156. // Private fields for properties values storage
  1157. private Axis _axis = null;
  1158. private double _newPosition = double.NaN;
  1159. private double _newSize = double.NaN;
  1160. private DateTimeIntervalType _newSizeType = DateTimeIntervalType.Auto;
  1161. #endregion
  1162. #region Constructors
  1163. /// <summary>
  1164. /// ViewEventArgs constructor.
  1165. /// </summary>
  1166. /// <param name="axis">Axis of the scale view.</param>
  1167. /// <param name="newPosition">New scale view start position.</param>
  1168. public ViewEventArgs(Axis axis, double newPosition)
  1169. {
  1170. this._axis = axis;
  1171. this._newPosition = newPosition;
  1172. }
  1173. /// <summary>
  1174. /// ViewEventArgs constructor.
  1175. /// </summary>
  1176. /// <param name="axis">Axis of the scale view.</param>
  1177. /// <param name="newPosition">New scale view start position.</param>
  1178. /// <param name="newSize">New scale view size.</param>
  1179. /// <param name="newSizeType">New unit of measurement of the size.</param>
  1180. public ViewEventArgs(Axis axis, double newPosition, double newSize, DateTimeIntervalType newSizeType)
  1181. {
  1182. this._axis = axis;
  1183. this._newPosition = newPosition;
  1184. this._newSize = newSize;
  1185. this._newSizeType = newSizeType;
  1186. }
  1187. #endregion
  1188. #region Properties
  1189. /// <summary>
  1190. /// Axis of the event.
  1191. /// </summary>
  1192. [
  1193. SRDescription("DescriptionAttributeAxis"),
  1194. ]
  1195. public Axis Axis
  1196. {
  1197. get
  1198. {
  1199. return _axis;
  1200. }
  1201. }
  1202. /// <summary>
  1203. /// ChartArea of the event.
  1204. /// </summary>
  1205. [
  1206. SRDescription("DescriptionAttributeChartArea"),
  1207. ]
  1208. public ChartArea ChartArea
  1209. {
  1210. get
  1211. {
  1212. return _axis.ChartArea;
  1213. }
  1214. }
  1215. /// <summary>
  1216. /// New scale view start position.
  1217. /// </summary>
  1218. [
  1219. SRDescription("DescriptionAttributeViewEventArgs_NewPosition"),
  1220. ]
  1221. public double NewPosition
  1222. {
  1223. get
  1224. {
  1225. return _newPosition;
  1226. }
  1227. set
  1228. {
  1229. _newPosition = value;
  1230. }
  1231. }
  1232. /// <summary>
  1233. /// New scale view size.
  1234. /// </summary>
  1235. [
  1236. SRDescription("DescriptionAttributeViewEventArgs_NewSize"),
  1237. ]
  1238. public double NewSize
  1239. {
  1240. get
  1241. {
  1242. return _newSize;
  1243. }
  1244. set
  1245. {
  1246. _newSize = value;
  1247. }
  1248. }
  1249. /// <summary>
  1250. /// New unit of measurement of the scale view.
  1251. /// </summary>
  1252. [
  1253. SRDescription("DescriptionAttributeViewEventArgs_NewSizeType"),
  1254. ]
  1255. public DateTimeIntervalType NewSizeType
  1256. {
  1257. get
  1258. {
  1259. return _newSizeType;
  1260. }
  1261. set
  1262. {
  1263. _newSizeType = (value != DateTimeIntervalType.NotSet) ? value : DateTimeIntervalType.Auto;
  1264. }
  1265. }
  1266. #endregion
  1267. }
  1268. }
  1269. namespace FastReport.DataVisualization.Charting
  1270. {
  1271. /// <summary>
  1272. /// Designer converter class
  1273. /// Converts Double.NaN values to/from "Not set".
  1274. /// </summary>
  1275. internal class DoubleNanValueConverter : DoubleConverter
  1276. {
  1277. #region Converter methods
  1278. /// <summary>
  1279. /// Standard values supported. This method always return true.
  1280. /// </summary>
  1281. /// <param name="context">Descriptor context.</param>
  1282. /// <returns>True.</returns>
  1283. public override bool GetStandardValuesSupported(ITypeDescriptorContext context)
  1284. {
  1285. return true;
  1286. }
  1287. /// <summary>
  1288. /// Standard values are not exclusive. This method always return false.
  1289. /// </summary>
  1290. /// <param name="context">Descriptor context.</param>
  1291. /// <returns>False.</returns>
  1292. public override bool GetStandardValuesExclusive(ITypeDescriptorContext context)
  1293. {
  1294. return false;
  1295. }
  1296. /// <summary>
  1297. /// Get in the collection of standard values.
  1298. /// </summary>
  1299. /// <param name="context">Descriptor context.</param>
  1300. public override StandardValuesCollection GetStandardValues(ITypeDescriptorContext context)
  1301. {
  1302. ArrayList values = new ArrayList();
  1303. values.Add(Double.NaN);
  1304. return new StandardValuesCollection(values);
  1305. }
  1306. /// <summary>
  1307. /// Convert double.NaN to string "Not set"
  1308. /// </summary>
  1309. /// <param name="context">Descriptor context.</param>
  1310. /// <param name="culture">Culture information.</param>
  1311. /// <param name="value">Value to convert.</param>
  1312. /// <param name="destinationType">Conversion destination type.</param>
  1313. /// <returns>Converted object.</returns>
  1314. public override object ConvertTo(ITypeDescriptorContext context, CultureInfo culture, object value, Type destinationType)
  1315. {
  1316. double doubleValue = (double)value;
  1317. if (destinationType == typeof(string))
  1318. {
  1319. if(Double.IsNaN(doubleValue))
  1320. {
  1321. return Constants.NotSetValue;
  1322. }
  1323. }
  1324. // Call base class
  1325. return base.ConvertTo(context, culture, value, destinationType);
  1326. }
  1327. /// <summary>
  1328. /// Convert minimum or maximum values from string.
  1329. /// </summary>
  1330. public override object ConvertFrom(ITypeDescriptorContext context, CultureInfo culture, object value)
  1331. {
  1332. // If converting from string value
  1333. string crossingValue = value as string;
  1334. if (crossingValue != null)
  1335. {
  1336. if (String.Compare(crossingValue, Constants.NotSetValue, StringComparison.OrdinalIgnoreCase) == 0)
  1337. {
  1338. return Double.NaN;
  1339. }
  1340. }
  1341. // Call base converter
  1342. return base.ConvertFrom(context, culture, value);
  1343. }
  1344. #endregion
  1345. }
  1346. /// <summary>
  1347. /// Designer converter class
  1348. /// Converts Double.NaN values to/from "Not set".
  1349. /// Converts value to/from date strings.
  1350. /// </summary>
  1351. internal class DoubleDateNanValueConverter : DoubleConverter
  1352. {
  1353. #region Converter methods
  1354. /// <summary>
  1355. /// Standard values supported - return true
  1356. /// </summary>
  1357. /// <param name="context">Descriptor context.</param>
  1358. /// <returns>Standard values supported.</returns>
  1359. public override bool GetStandardValuesSupported(ITypeDescriptorContext context)
  1360. {
  1361. return true;
  1362. }
  1363. /// <summary>
  1364. /// Standard values are not exclusive - return false
  1365. /// </summary>
  1366. /// <param name="context">Descriptor context.</param>
  1367. /// <returns>Non exclusive standard values.</returns>
  1368. public override bool GetStandardValuesExclusive(ITypeDescriptorContext context)
  1369. {
  1370. return false;
  1371. }
  1372. /// <summary>
  1373. /// Fill in the list of predefined values.
  1374. /// </summary>
  1375. /// <param name="context">Descriptor context.</param>
  1376. public override StandardValuesCollection GetStandardValues(ITypeDescriptorContext context)
  1377. {
  1378. ArrayList values = new ArrayList();
  1379. values.Add(Double.NaN);
  1380. return new StandardValuesCollection(values);
  1381. }
  1382. /// <summary>
  1383. /// Convert values to string if step type is set to one of the DateTime type
  1384. /// </summary>
  1385. /// <param name="context">Descriptor context.</param>
  1386. /// <param name="culture">Culture information.</param>
  1387. /// <param name="value">Value to convert.</param>
  1388. /// <param name="destinationType">Conversion destination type.</param>
  1389. /// <returns>Converted object.</returns>
  1390. public override object ConvertTo(ITypeDescriptorContext context, CultureInfo culture, object value, Type destinationType)
  1391. {
  1392. // Check for NaN
  1393. if (destinationType == typeof(string))
  1394. {
  1395. if(Double.IsNaN((double)value))
  1396. {
  1397. return Constants.NotSetValue;
  1398. }
  1399. }
  1400. if (context != null && context.Instance != null)
  1401. {
  1402. // Get access to the Axis object
  1403. Axis axis = null;
  1404. if(context.Instance is AxisScaleView)
  1405. {
  1406. axis = ((AxisScaleView)context.Instance).axis;
  1407. }
  1408. else if(context.Instance is Cursor)
  1409. {
  1410. axis = ((Cursor)context.Instance).GetAxis();
  1411. }
  1412. if (axis != null && destinationType == typeof(string))
  1413. {
  1414. string strValue = ConvertDateTimeToString(
  1415. (double)value,
  1416. axis.GetAxisValuesType(),
  1417. axis.InternalIntervalType);
  1418. if (strValue != null)
  1419. return strValue;
  1420. }
  1421. }
  1422. return base.ConvertTo(context, culture, value, destinationType);
  1423. }
  1424. public static string ConvertDateTimeToString(
  1425. double dtValue,
  1426. ChartValueType axisValuesType,
  1427. DateTimeIntervalType dtIntervalType)
  1428. {
  1429. string strValue = null;
  1430. // Use axis values types if interval is automatic
  1431. if (dtIntervalType == DateTimeIntervalType.Auto)
  1432. {
  1433. if (axisValuesType == ChartValueType.DateTime ||
  1434. axisValuesType == ChartValueType.Time ||
  1435. axisValuesType == ChartValueType.Date ||
  1436. axisValuesType == ChartValueType.DateTimeOffset)
  1437. {
  1438. strValue = DateTime.FromOADate(dtValue).ToString("g", System.Globalization.CultureInfo.CurrentCulture);
  1439. }
  1440. }
  1441. else
  1442. {
  1443. if (dtIntervalType != DateTimeIntervalType.Number)
  1444. {
  1445. // Covert value to date/time
  1446. if (dtIntervalType < DateTimeIntervalType.Hours)
  1447. {
  1448. strValue = DateTime.FromOADate(dtValue).ToShortDateString();
  1449. }
  1450. else
  1451. {
  1452. strValue = DateTime.FromOADate(dtValue).ToString("g", System.Globalization.CultureInfo.CurrentCulture);
  1453. }
  1454. }
  1455. }
  1456. if (axisValuesType == ChartValueType.DateTimeOffset && strValue != null)
  1457. strValue += " +0";
  1458. return strValue;
  1459. }
  1460. /// <summary>
  1461. /// Convert Min and Max values from string if step type is set to one of the DateTime type
  1462. /// </summary>
  1463. /// <param name="context">Descriptor context.</param>
  1464. /// <param name="culture">Culture information.</param>
  1465. /// <param name="value">Value to convert from.</param>
  1466. /// <returns>Converted object.</returns>
  1467. public override object ConvertFrom(ITypeDescriptorContext context, CultureInfo culture, object value)
  1468. {
  1469. object result = null;
  1470. bool convertFromDate = false;
  1471. // If converting from string value
  1472. string crossingValue = value as string;
  1473. if (crossingValue != null)
  1474. {
  1475. if (String.Compare(crossingValue, Constants.NotSetValue, StringComparison.OrdinalIgnoreCase) == 0)
  1476. {
  1477. return Double.NaN;
  1478. }
  1479. }
  1480. // If context interface provided check if we are dealing with DateTime values
  1481. if (context != null && context.Instance != null && context.Instance is Axis)
  1482. {
  1483. // Get axis object
  1484. Axis axis = null;
  1485. if(context.Instance is AxisScaleView)
  1486. {
  1487. axis = ((AxisScaleView)context.Instance).axis;
  1488. }
  1489. else if(context.Instance is Cursor)
  1490. {
  1491. axis = ((Cursor)context.Instance).GetAxis();
  1492. }
  1493. if (axis != null && crossingValue != null)
  1494. {
  1495. if(axis.InternalIntervalType == DateTimeIntervalType.Auto)
  1496. {
  1497. if(axis.GetAxisValuesType() == ChartValueType.DateTime ||
  1498. axis.GetAxisValuesType() == ChartValueType.Date ||
  1499. axis.GetAxisValuesType() == ChartValueType.Time ||
  1500. axis.GetAxisValuesType() == ChartValueType.DateTimeOffset)
  1501. {
  1502. convertFromDate = true;
  1503. }
  1504. }
  1505. else
  1506. {
  1507. if(axis.InternalIntervalType != DateTimeIntervalType.Number)
  1508. {
  1509. convertFromDate = true;
  1510. }
  1511. }
  1512. }
  1513. }
  1514. // Try to convert from double string
  1515. try
  1516. {
  1517. result = base.ConvertFrom(context, culture, value);
  1518. }
  1519. catch (ArgumentException)
  1520. {
  1521. result = null;
  1522. }
  1523. catch (NotSupportedException)
  1524. {
  1525. result = null;
  1526. }
  1527. // Try to convert from date/time string
  1528. if (crossingValue != null && (convertFromDate || result == null))
  1529. {
  1530. DateTime valueAsDate;
  1531. bool parseSucceed = DateTime.TryParse(crossingValue, CultureInfo.InvariantCulture, DateTimeStyles.None, out valueAsDate);
  1532. if (parseSucceed)
  1533. {
  1534. return valueAsDate.ToOADate();
  1535. }
  1536. }
  1537. // Call base converter
  1538. return base.ConvertFrom(context, culture, value);
  1539. }
  1540. #endregion
  1541. }
  1542. }