AxisScale.cs 63 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057205820592060206120622063206420652066206720682069207020712072207320742075207620772078207920802081208220832084208520862087208820892090209120922093209420952096209720982099210021012102210321042105210621072108210921102111211221132114211521162117211821192120212121222123212421252126212721282129213021312132213321342135213621372138213921402141214221432144214521462147214821492150215121522153215421552156215721582159216021612162216321642165216621672168216921702171217221732174217521762177217821792180218121822183218421852186218721882189219021912192219321942195219621972198219922002201220222032204220522062207220822092210221122122213221422152216221722182219222022212222222322242225222622272228222922302231223222332234223522362237223822392240224122422243224422452246224722482249225022512252225322542255225622572258225922602261226222632264226522662267226822692270227122722273227422752276227722782279228022812282228322842285228622872288228922902291229222932294
  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: Base class for the Axis class which defines axis
  6. // csale related properties and methods.
  7. //
  8. using System;
  9. using System.Collections;
  10. using System.Collections.Generic;
  11. using System.ComponentModel;
  12. using System.Drawing;
  13. using System.Drawing.Design;
  14. using FastReport.DataVisualization.Charting.Utilities;
  15. namespace FastReport.DataVisualization.Charting
  16. {
  17. #region Axis enumerations
  18. /// <summary>
  19. /// An enumeration of the mode of automatically calculating intervals.
  20. /// </summary>
  21. public enum IntervalAutoMode
  22. {
  23. /// <summary>
  24. /// Fixed number of intervals always created on the axis.
  25. /// </summary>
  26. FixedCount,
  27. /// <summary>
  28. /// Number of axis intervals depends on the axis length.
  29. /// </summary>
  30. VariableCount
  31. }
  32. /// <summary>
  33. /// An enumeration of axis position.
  34. /// </summary>
  35. internal enum AxisPosition
  36. {
  37. /// <summary>
  38. /// Left position
  39. /// </summary>
  40. Left,
  41. /// <summary>
  42. /// Right position
  43. /// </summary>
  44. Right,
  45. /// <summary>
  46. /// Top position
  47. /// </summary>
  48. Top,
  49. /// <summary>
  50. /// Bottom position
  51. /// </summary>
  52. Bottom
  53. }
  54. /// <summary>
  55. /// An enumeration of axis arrow styles.
  56. /// </summary>
  57. public enum AxisArrowStyle
  58. {
  59. /// <summary>
  60. /// No arrow
  61. /// </summary>
  62. None,
  63. /// <summary>
  64. /// Triangle type
  65. /// </summary>
  66. Triangle,
  67. /// <summary>
  68. /// Sharp triangle type
  69. /// </summary>
  70. SharpTriangle,
  71. /// <summary>
  72. /// Lines type
  73. /// </summary>
  74. Lines
  75. }
  76. #endregion
  77. /// <summary>
  78. /// The Axis class keeps information about minimum, maximum
  79. /// and interval values and it is responsible for setting
  80. /// these values automatically. It also handles
  81. /// logarithmic and reversed axis.
  82. /// </summary>
  83. public partial class Axis
  84. {
  85. #region Axis scale fields
  86. // Represents the distance between the data points and its
  87. // chart area margin, Measured as a percentage of default
  88. // margin size.
  89. internal double margin = 100.0;
  90. internal double marginView = 0.0;
  91. internal bool offsetTempSet = false;
  92. // Used for column chart margin
  93. internal double marginTemp = 0.0;
  94. private ArrayList _stripLineOffsets = new ArrayList();
  95. // Data members, which store properties values
  96. private bool _isLogarithmic = false;
  97. internal double logarithmBase = 10.0;
  98. internal bool isReversed = false;
  99. internal bool isStartedFromZero = true;
  100. internal TickMark minorTickMark = null;
  101. internal TickMark majorTickMark = null;
  102. internal Grid minorGrid = null;
  103. internal Grid majorGrid = null;
  104. internal bool enabled = false;
  105. internal bool autoEnabled = true;
  106. internal LabelStyle labelStyle = null;
  107. private DateTimeIntervalType _internalIntervalType = DateTimeIntervalType.Auto;
  108. internal double maximum = Double.NaN;
  109. internal double crossing = Double.NaN;
  110. internal double minimum = Double.NaN;
  111. // Temporary Minimum and maximum values.
  112. internal double tempMaximum = Double.NaN;
  113. internal double tempMinimum = Double.NaN;
  114. internal double tempCrossing = Double.NaN;
  115. internal CustomLabelsCollection tempLabels;
  116. internal bool tempAutoMaximum = true;
  117. internal bool tempAutoMinimum = true;
  118. internal double tempMajorGridInterval = Double.NaN;
  119. internal double tempMinorGridInterval = 0.0;
  120. internal double tempMajorTickMarkInterval = Double.NaN;
  121. internal double tempMinorTickMarkInterval = 0.0;
  122. internal double tempLabelInterval = Double.NaN;
  123. internal DateTimeIntervalType tempGridIntervalType = DateTimeIntervalType.NotSet;
  124. internal DateTimeIntervalType tempTickMarkIntervalType = DateTimeIntervalType.NotSet;
  125. internal DateTimeIntervalType tempLabelIntervalType = DateTimeIntervalType.NotSet;
  126. // Paint mode
  127. internal bool paintMode = false;
  128. // Axis type (X, Y, X2, Y2)
  129. internal AxisName axisType = AxisName.X;
  130. // Automatic maximum value (from data point values).
  131. private bool _autoMaximum = true;
  132. // Automatic minimum value (from data point values).
  133. private bool _autoMinimum = true;
  134. /// <summary>
  135. /// Axis position: Left, Right, Top Bottom
  136. /// </summary>
  137. private AxisPosition _axisPosition = AxisPosition.Left;
  138. /// <summary>
  139. /// Opposite Axis for this Axis. Necessary for Crossing.
  140. /// </summary>
  141. internal Axis oppositeAxis = null;
  142. // Axis data scaleView
  143. private AxisScaleView _scaleView = null;
  144. // Axis scroll bar class
  145. internal AxisScrollBar scrollBar = null;
  146. // For scater chart X values could be rounded.
  147. internal bool roundedXValues = false;
  148. // If Axis is logarithmic value shoud be converted to
  149. // linear only once.
  150. internal bool logarithmicConvertedToLinear = false;
  151. // IsLogarithmic minimum value
  152. internal double logarithmicMinimum;
  153. // IsLogarithmic maximum value
  154. internal double logarithmicMaximum;
  155. // Correction of interval because of
  156. // 3D Rotation and perspective
  157. internal double interval3DCorrection = Double.NaN;
  158. // Axis coordinate convertion optimization fields
  159. internal bool optimizedGetPosition = false;
  160. internal double paintViewMax = 0.0;
  161. internal double paintViewMin = 0.0;
  162. internal double paintRange = 0.0;
  163. internal double valueMultiplier = 0.0;
  164. internal RectangleF paintAreaPosition = RectangleF.Empty;
  165. internal double paintAreaPositionBottom = 0.0;
  166. internal double paintAreaPositionRight = 0.0;
  167. internal double paintChartAreaSize = 0.0;
  168. // Determines how number of intervals automatically calculated
  169. private IntervalAutoMode _intervalAutoMode = IntervalAutoMode.FixedCount;
  170. // True if scale segments are used
  171. internal bool scaleSegmentsUsed = false;
  172. // Preffered number of intervals on the axis
  173. internal int prefferedNumberofIntervals = 5;
  174. private Stack<Double> _intervalsStore = new Stack<Double>();
  175. #endregion
  176. #region Axis scale properties
  177. /// <summary>
  178. /// Axis position
  179. /// </summary>
  180. [
  181. Bindable(true),
  182. DefaultValue(AxisPosition.Left),
  183. NotifyParentPropertyAttribute(true),
  184. SRDescription("DescriptionAttributeReverse"),
  185. DesignerSerializationVisibilityAttribute(DesignerSerializationVisibility.Hidden),
  186. SerializationVisibilityAttribute(SerializationVisibility.Hidden)
  187. ]
  188. virtual internal AxisPosition AxisPosition
  189. {
  190. get
  191. {
  192. return this._axisPosition;
  193. }
  194. set
  195. {
  196. this._axisPosition = value;
  197. #if SUBAXES
  198. // Update axis position of the sub axis
  199. if( !((Axis)this).IsSubAxis )
  200. {
  201. foreach(SubAxis subAxis in ((Axis)this).SubAxes)
  202. {
  203. subAxis._axisPosition = value;
  204. }
  205. }
  206. #endif // SUBAXES
  207. this.Invalidate();
  208. }
  209. }
  210. /// <summary>
  211. /// Gets or sets a flag which indicates whether the number of intervals
  212. /// on the axis is fixed or varies with the axis size.
  213. /// </summary>
  214. [
  215. SRCategory("CategoryAttributeInterval"),
  216. DefaultValue(IntervalAutoMode.FixedCount),
  217. SRDescription("DescriptionAttributeIntervalAutoMode"),
  218. ]
  219. public IntervalAutoMode IntervalAutoMode
  220. {
  221. get
  222. {
  223. return this._intervalAutoMode;
  224. }
  225. set
  226. {
  227. this._intervalAutoMode = value;
  228. this.Invalidate();
  229. CallOnModifing();
  230. }
  231. }
  232. /// <summary>
  233. /// Gets or sets a flag which indicates whether the axis is reversed.
  234. /// If set to reversed, the values on the axis are in reversed sort order
  235. /// and the direction of values on the axis is flipped.
  236. /// </summary>
  237. [
  238. SRCategory("CategoryAttributeScale"),
  239. Bindable(true),
  240. DefaultValue(false),
  241. NotifyParentPropertyAttribute(true),
  242. SRDescription("DescriptionAttributeReverse"),
  243. ]
  244. public bool IsReversed
  245. {
  246. get
  247. {
  248. return isReversed;
  249. }
  250. set
  251. {
  252. isReversed = value;
  253. this.Invalidate();
  254. }
  255. }
  256. /// <summary>
  257. /// Gets or sets a flag which indicates whether the minimum value
  258. /// of the axis will be automatically set to zero if all data point
  259. /// values are positive. If there are negative data point values,
  260. /// the minimum value of the data points will be used.
  261. /// </summary>
  262. [
  263. SRCategory("CategoryAttributeScale"),
  264. Bindable(true),
  265. DefaultValue(true),
  266. NotifyParentPropertyAttribute(true),
  267. SRDescription("DescriptionAttributeStartFromZero3"),
  268. ]
  269. public bool IsStartedFromZero
  270. {
  271. get
  272. {
  273. return isStartedFromZero;
  274. }
  275. set
  276. {
  277. isStartedFromZero = value;
  278. this.Invalidate();
  279. CallOnModifing();
  280. }
  281. }
  282. /// <summary>
  283. /// Gets or sets a flag to add a margin to the axis.
  284. /// If true, a space is added between the first/last data
  285. /// point and the border of chart area.
  286. /// </summary>
  287. [
  288. SRCategory("CategoryAttributeScale"),
  289. Bindable(true),
  290. DefaultValue(true),
  291. NotifyParentPropertyAttribute(true),
  292. SRDescription("DescriptionAttributeMargin"),
  293. ]
  294. public bool IsMarginVisible
  295. {
  296. get
  297. {
  298. if( margin > 0 )
  299. return true;
  300. else
  301. return false;
  302. }
  303. set
  304. {
  305. if( value == true )
  306. margin = 100;
  307. else
  308. margin = 0;
  309. this.Invalidate();
  310. CallOnModifing();
  311. }
  312. }
  313. /// <summary>
  314. /// Date and time interval type.
  315. /// </summary>
  316. [
  317. SRCategory("CategoryAttributeScale"),
  318. Bindable(true),
  319. DefaultValue(DateTimeIntervalType.Auto),
  320. NotifyParentPropertyAttribute(true),
  321. SRDescription("DescriptionAttributeInternalIntervalType"),
  322. RefreshPropertiesAttribute(RefreshProperties.All),
  323. ]
  324. internal DateTimeIntervalType InternalIntervalType
  325. {
  326. get
  327. {
  328. return _internalIntervalType;
  329. }
  330. set
  331. {
  332. // Set intervals for labels, grids and tick marks. ( Auto interval type )
  333. if( tempMajorGridInterval <= 0.0 ||
  334. (double.IsNaN(tempMajorGridInterval) && ((Axis)this).Interval <= 0.0) )
  335. {
  336. majorGrid.intervalType = value;
  337. }
  338. if( this.tempMajorTickMarkInterval <= 0.0 ||
  339. (double.IsNaN(tempMajorTickMarkInterval) && ((Axis)this).Interval <= 0.0) )
  340. {
  341. majorTickMark.intervalType = value;
  342. }
  343. if( this.tempLabelInterval <= 0.0 ||
  344. (double.IsNaN(tempLabelInterval) && ((Axis)this).Interval <= 0.0) )
  345. {
  346. labelStyle.intervalType = value;
  347. }
  348. _internalIntervalType = value;
  349. this.Invalidate();
  350. }
  351. }
  352. /// <summary>
  353. /// Sets auto interval values to grids, tick marks
  354. /// and labels
  355. /// </summary>
  356. internal double SetInterval
  357. {
  358. set
  359. {
  360. if( tempMajorGridInterval <= 0.0 ||
  361. (double.IsNaN(tempMajorGridInterval) && ((Axis)this).Interval <= 0.0) )
  362. {
  363. majorGrid.interval = value;
  364. }
  365. if( tempMajorTickMarkInterval <= 0.0 ||
  366. (double.IsNaN(tempMajorTickMarkInterval) && ((Axis)this).Interval <= 0.0) )
  367. {
  368. majorTickMark.interval = value;
  369. }
  370. if( tempLabelInterval <= 0.0 ||
  371. (double.IsNaN(tempLabelInterval) && ((Axis)this).Interval <= 0.0) )
  372. {
  373. labelStyle.interval = value;
  374. }
  375. this.Invalidate();
  376. }
  377. }
  378. /// <summary>
  379. /// Sets auto interval values to grids, tick marks
  380. /// and labels
  381. /// </summary>
  382. internal void SetIntervalAndType(double newInterval, DateTimeIntervalType newIntervalType)
  383. {
  384. if( tempMajorGridInterval <= 0.0 ||
  385. (double.IsNaN(tempMajorGridInterval) && ((Axis)this).Interval <= 0.0) )
  386. {
  387. majorGrid.interval = newInterval;
  388. majorGrid.intervalType = newIntervalType;
  389. }
  390. if( tempMajorTickMarkInterval <= 0.0 ||
  391. (double.IsNaN(tempMajorTickMarkInterval) && ((Axis)this).Interval <= 0.0) )
  392. {
  393. majorTickMark.interval = newInterval;
  394. majorTickMark.intervalType = newIntervalType;
  395. }
  396. if( tempLabelInterval <= 0.0 ||
  397. (double.IsNaN(tempLabelInterval) && ((Axis)this).Interval <= 0.0) )
  398. {
  399. labelStyle.interval = newInterval;
  400. labelStyle.intervalType = newIntervalType;
  401. }
  402. this.Invalidate();
  403. }
  404. /// <summary>
  405. /// Gets or sets the maximum axis value.
  406. /// </summary>
  407. [
  408. SRCategory("CategoryAttributeScale"),
  409. Bindable(true),
  410. DefaultValue(Double.NaN),
  411. NotifyParentPropertyAttribute(true),
  412. SRDescription("DescriptionAttributeMaximum"),
  413. TypeConverter(typeof(AxisMinMaxAutoValueConverter))
  414. ]
  415. public double Maximum
  416. {
  417. get
  418. {
  419. // Get maximum
  420. if (_isLogarithmic && logarithmicConvertedToLinear && !Double.IsNaN(maximum))
  421. return logarithmicMaximum;
  422. else
  423. return maximum;
  424. }
  425. set
  426. {
  427. // Split a value to maximum and auto maximum
  428. if( Double.IsNaN(value) )
  429. {
  430. _autoMaximum = true;
  431. maximum = Double.NaN;
  432. }
  433. else
  434. {
  435. // Set maximum
  436. maximum = value;
  437. // Set non linearized Maximum for logarithmic scale
  438. logarithmicMaximum = value;
  439. _autoMaximum = false;
  440. }
  441. // Reset original property value fields
  442. ((Axis)this).tempMaximum = maximum;
  443. // This line is added because of Save ScaleView State August 29, 2003
  444. // in Web Forms. This place could cause problems with Reset Auto Values.
  445. ((Axis)this).tempAutoMaximum = _autoMaximum;
  446. this.Invalidate();
  447. CallOnModifing();
  448. }
  449. }
  450. /// <summary>
  451. /// Gets or sets the minimum axis value
  452. /// </summary>
  453. [
  454. SRCategory("CategoryAttributeScale"),
  455. Bindable(true),
  456. DefaultValue(Double.NaN),
  457. NotifyParentPropertyAttribute(true),
  458. SRDescription("DescriptionAttributeMinimum"),
  459. TypeConverter(typeof(AxisMinMaxAutoValueConverter))
  460. ]
  461. public double Minimum
  462. {
  463. get
  464. {
  465. // Get minimum
  466. if (_isLogarithmic && logarithmicConvertedToLinear && !Double.IsNaN(maximum))
  467. return logarithmicMinimum;
  468. else
  469. return minimum;
  470. }
  471. set
  472. {
  473. // Split a value to minimum and auto minimum
  474. if( Double.IsNaN(value) )
  475. {
  476. _autoMinimum = true;
  477. minimum = Double.NaN;
  478. }
  479. else
  480. {
  481. // Set maximum
  482. minimum = value;
  483. _autoMinimum = false;
  484. // Set non linearized Minimum for logarithmic scale
  485. logarithmicMinimum = value;
  486. }
  487. // Reset original property value fields
  488. ((Axis)this).tempMinimum = minimum;
  489. // This line is added because of Save ScaleView State August 29, 2003
  490. // in Web Forms. This place could cause problems with Reset Auto Values.
  491. ((Axis)this).tempAutoMinimum = _autoMinimum;
  492. this.Invalidate();
  493. CallOnModifing();
  494. }
  495. }
  496. /// <summary>
  497. /// Gets or sets the point where axis is crossed by another axis.
  498. /// </summary>
  499. [
  500. SRCategory("CategoryAttributeScale"),
  501. Bindable(true),
  502. DefaultValue(Double.NaN),
  503. NotifyParentPropertyAttribute(true),
  504. SRDescription("DescriptionAttributeCrossing"),
  505. TypeConverter(typeof(AxisCrossingValueConverter))
  506. ]
  507. virtual public double Crossing
  508. {
  509. get
  510. {
  511. if( paintMode )
  512. if (_isLogarithmic)
  513. return Math.Pow( this.logarithmBase, GetCrossing() );
  514. else
  515. return GetCrossing();
  516. else
  517. return crossing;
  518. }
  519. set
  520. {
  521. crossing = value;
  522. // Reset original property value fields
  523. ((Axis)this).tempCrossing = crossing;
  524. this.Invalidate();
  525. CallOnModifing();
  526. }
  527. }
  528. /// <summary>
  529. /// Enables or disables the axis.
  530. /// </summary>
  531. [
  532. SRCategory("CategoryAttributeMisc"),
  533. Bindable(true),
  534. DefaultValue(typeof(AxisEnabled), "Auto"),
  535. NotifyParentPropertyAttribute(true),
  536. SRDescription("DescriptionAttributeEnabled7"),
  537. ]
  538. public AxisEnabled Enabled
  539. {
  540. get
  541. {
  542. // Take Enabled from two fields: enabled and auto enabled
  543. if( autoEnabled )
  544. {
  545. return AxisEnabled.Auto;
  546. }
  547. else if( enabled )
  548. {
  549. return AxisEnabled.True;
  550. }
  551. else
  552. {
  553. return AxisEnabled.False;
  554. }
  555. }
  556. set
  557. { // Split Enabled to two fields: enabled and auto enabled
  558. if( value == AxisEnabled.Auto )
  559. {
  560. autoEnabled = true;
  561. }
  562. else if( value == AxisEnabled.True )
  563. {
  564. enabled = true;
  565. autoEnabled = false;
  566. }
  567. else
  568. {
  569. enabled = false;
  570. autoEnabled = false;
  571. }
  572. this.Invalidate();
  573. CallOnModifing();
  574. }
  575. }
  576. /// <summary>
  577. /// Gets or sets a flag which indicates whether the axis is logarithmic.
  578. /// Zeros or negative data values are not allowed on logarithmic charts.
  579. /// </summary>
  580. [
  581. SRCategory("CategoryAttributeScale"),
  582. Bindable(true),
  583. DefaultValue(false),
  584. NotifyParentPropertyAttribute(true),
  585. SRDescription("DescriptionAttributeLogarithmic"),
  586. ]
  587. public bool IsLogarithmic
  588. {
  589. get
  590. {
  591. return _isLogarithmic;
  592. }
  593. set
  594. {
  595. _isLogarithmic = value;
  596. this.Invalidate();
  597. CallOnModifing();
  598. }
  599. }
  600. /// <summary>
  601. /// Base of the logarithm used in logarithmic scale.
  602. /// By default, this value is 10.
  603. /// </summary>
  604. [
  605. SRCategory("CategoryAttributeScale"),
  606. Bindable(true),
  607. DefaultValue(10.0),
  608. NotifyParentPropertyAttribute(true),
  609. SRDescription("DescriptionAttributeLogarithmBase"),
  610. ]
  611. public double LogarithmBase
  612. {
  613. get
  614. {
  615. return logarithmBase;
  616. }
  617. set
  618. {
  619. if( value < 2.0 )
  620. {
  621. throw (new ArgumentOutOfRangeException("value", SR.ExceptionAxisScaleLogarithmBaseInvalid));
  622. }
  623. logarithmBase = value;
  624. this.Invalidate();
  625. CallOnModifing();
  626. }
  627. }
  628. #endregion
  629. #region Axis Segments and Scale Breaks Properties
  630. // Field that stores Axis automatic scale breaks style.
  631. internal AxisScaleBreakStyle axisScaleBreakStyle = null;
  632. /// <summary>
  633. /// Gets or sets the style of scale breaks.
  634. /// </summary>
  635. [
  636. SRCategory("CategoryAttributeScale"),
  637. SRDescription("DescriptionAttributeScaleBreakStyle"),
  638. TypeConverter(typeof(NoNameExpandableObjectConverter)),
  639. NotifyParentPropertyAttribute(true),
  640. DesignerSerializationVisibility(DesignerSerializationVisibility.Content),
  641. ]
  642. virtual public AxisScaleBreakStyle ScaleBreakStyle
  643. {
  644. get
  645. {
  646. return this.axisScaleBreakStyle;
  647. }
  648. set
  649. {
  650. this.axisScaleBreakStyle = value;
  651. this.axisScaleBreakStyle.axis = (Axis)this;
  652. //this.Invalidate();
  653. CallOnModifing();
  654. }
  655. }
  656. // Field that stores axis scale segments
  657. internal AxisScaleSegmentCollection scaleSegments = null;
  658. /// <summary>
  659. /// Axis scale segment collection.
  660. /// </summary>
  661. [
  662. SRCategory("CategoryAttributeScale"),
  663. Browsable(false),
  664. EditorBrowsable(EditorBrowsableState.Never),
  665. SRDescription("DescriptionAttributeAxisScaleSegmentCollection_AxisScaleSegmentCollection"),
  666. SerializationVisibilityAttribute(SerializationVisibility.Hidden),
  667. DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden),
  668. #if DESIGNER
  669. Editor(typeof(ChartCollectionEditor), typeof(UITypeEditor))
  670. #endif
  671. ]
  672. internal AxisScaleSegmentCollection ScaleSegments
  673. {
  674. get
  675. {
  676. return this.scaleSegments;
  677. }
  678. }
  679. #endregion // Axis Segments and Scale Breaks Properties
  680. #region Axis data scaleView properies and methods
  681. /// <summary>
  682. /// Gets or sets the scale view settings of the axis.
  683. /// </summary>
  684. [
  685. SRCategory("CategoryAttributeDataView"),
  686. Bindable(true),
  687. SRDescription("DescriptionAttributeView"),
  688. DesignerSerializationVisibility(DesignerSerializationVisibility.Content),
  689. TypeConverter(typeof(NoNameExpandableObjectConverter))
  690. ]
  691. public AxisScaleView ScaleView
  692. {
  693. get
  694. {
  695. return _scaleView;
  696. }
  697. set
  698. {
  699. _scaleView = value;
  700. _scaleView.axis = (Axis)this;
  701. this.Invalidate();
  702. CallOnModifing();
  703. }
  704. }
  705. /// <summary>
  706. /// Gets or sets the scroll bar settings of the axis.
  707. /// </summary>
  708. [
  709. SRCategory("CategoryAttributeDataView"),
  710. Bindable(true),
  711. SRDescription("DescriptionAttributeScrollBar"),
  712. DesignerSerializationVisibility(DesignerSerializationVisibility.Content),
  713. TypeConverter(typeof(NoNameExpandableObjectConverter))
  714. ]
  715. public AxisScrollBar ScrollBar
  716. {
  717. get
  718. {
  719. return scrollBar;
  720. }
  721. set
  722. {
  723. scrollBar = value;
  724. scrollBar.axis = (Axis)this;
  725. this.Invalidate();
  726. CallOnModifing();
  727. }
  728. }
  729. /// <summary>
  730. /// Gets axis data scaleView minimum position.
  731. /// </summary>
  732. /// <returns>Axis data scaleView minimum position.</returns>
  733. internal double ViewMinimum
  734. {
  735. get { return _scaleView.ViewMinimum; }
  736. }
  737. /// <summary>
  738. /// Gets axis data scaleView minimum position.
  739. /// </summary>
  740. /// <returns>Axis data scaleView minimum position.</returns>
  741. internal double ViewMaximum
  742. {
  743. get { return _scaleView.ViewMaximum; }
  744. }
  745. /// <summary>
  746. /// Gets automatic maximum value (from data point values).
  747. /// </summary>
  748. internal bool AutoMaximum
  749. {
  750. get { return _autoMaximum; }
  751. }
  752. /// <summary>
  753. /// Gets automatic minimum value (from data point values).
  754. /// </summary>
  755. internal bool AutoMinimum
  756. {
  757. get { return _autoMinimum; }
  758. }
  759. #endregion
  760. #region Axis position converters methos
  761. /// <summary>
  762. /// This function converts axis value to relative position (0-100%).
  763. /// If an axis has a logarithmic scale, the value is converted to a linear scale.
  764. /// </summary>
  765. /// <param name="axisValue">Value from axis.</param>
  766. /// <returns>Relative position (0-100%).</returns>
  767. public double GetPosition( double axisValue )
  768. {
  769. // Adjust for the IsLogarithmic axis
  770. if (_isLogarithmic && axisValue != 0.0)
  771. {
  772. axisValue = Math.Log( axisValue, this.logarithmBase );
  773. }
  774. // Get linear position
  775. return GetLinearPosition(axisValue);
  776. }
  777. /// <summary>
  778. /// This function converts an axis value to relative position (0-100%).
  779. /// If an axis has a logarithmic scale, the value is converted to a linear scale.
  780. /// </summary>
  781. /// <param name="axisValue">Axis value.</param>
  782. /// <returns>Relative position (0-100%).</returns>
  783. public double ValueToPosition( double axisValue )
  784. {
  785. return GetPosition( axisValue );
  786. }
  787. /// <summary>
  788. /// This function converts an axis value to a pixel position.
  789. /// If an axis has a logarithmic scale, the value is converted to a linear scale.
  790. /// </summary>
  791. /// <param name="axisValue">Value from axis.</param>
  792. /// <returns>Pixel position.</returns>
  793. public double ValueToPixelPosition( double axisValue )
  794. {
  795. // Get relative value
  796. double val = ValueToPosition(axisValue);
  797. // Convert it to pixels
  798. if( AxisPosition == AxisPosition.Top || AxisPosition == AxisPosition.Bottom )
  799. {
  800. val *= (this.Common.ChartPicture.Width - 1) / 100F;
  801. }
  802. else
  803. {
  804. val *= (this.Common.ChartPicture.Height - 1) / 100F;
  805. }
  806. return val;
  807. }
  808. /// <summary>
  809. /// This function converts a relative position to an axis value.
  810. /// If an axis has a logarithmic scale, the value is converted to a linear scale.
  811. /// </summary>
  812. /// <param name="position">Relative position (0-100%).</param>
  813. /// <returns>Axis value.</returns>
  814. public double PositionToValue( double position )
  815. {
  816. return PositionToValue(position, true);
  817. }
  818. /// <summary>
  819. /// This function converts a relative position to an axis value.
  820. /// If an axis has a logarithmic scale, the value is converted to a linear scale.
  821. /// </summary>
  822. /// <param name="position">Relative position (0-100%).</param>
  823. /// <param name="validateInput">Indicates if input value range should be checked.</param>
  824. /// <returns>Axis value.</returns>
  825. internal double PositionToValue( double position, bool validateInput)
  826. {
  827. // Check parameters
  828. if(validateInput &&
  829. (position < 0 || position > 100) )
  830. {
  831. throw (new ArgumentException(SR.ExceptionAxisScalePositionInvalid, "position"));
  832. }
  833. // Check if plot area position was already calculated
  834. if(PlotAreaPosition == null)
  835. {
  836. throw (new InvalidOperationException(SR.ExceptionAxisScalePositionToValueCallFailed));
  837. }
  838. // Convert chart picture position to plotting position
  839. if( AxisPosition == AxisPosition.Top || AxisPosition == AxisPosition.Bottom )
  840. position = position - PlotAreaPosition.X;
  841. else
  842. position = PlotAreaPosition.Bottom - position;
  843. // The Chart area size
  844. double ChartArea;
  845. if( AxisPosition == AxisPosition.Top || AxisPosition == AxisPosition.Bottom )
  846. ChartArea = PlotAreaPosition.Width;
  847. else
  848. ChartArea = PlotAreaPosition.Height;
  849. // The Real range as double
  850. double viewMax = ViewMaximum;
  851. double viewMin = ViewMinimum;
  852. double range = viewMax - viewMin;
  853. // Avoid division by zero
  854. double axisValue = 0;
  855. if( range != 0 )
  856. {
  857. // Find axis value from position
  858. axisValue = range / ChartArea * position;
  859. }
  860. // Corrected axis value for reversed
  861. if( isReversed )
  862. axisValue = viewMax - axisValue;
  863. else
  864. axisValue = viewMin + axisValue;
  865. return axisValue;
  866. }
  867. /// <summary>
  868. /// This function converts a pixel position to an axis value.
  869. /// If an axis has a logarithmic scale, the value is converted to a linear scale.
  870. /// </summary>
  871. /// <param name="position">Pixel position.</param>
  872. /// <returns>Axis value.</returns>
  873. public double PixelPositionToValue( double position )
  874. {
  875. // Convert it to pixels
  876. double val = position;
  877. if( AxisPosition == AxisPosition.Top || AxisPosition == AxisPosition.Bottom )
  878. {
  879. val *= 100F / ((float)(this.Common.ChartPicture.Width - 1));
  880. }
  881. else
  882. {
  883. val *= 100F / ((float)(this.Common.ChartPicture.Height - 1));
  884. }
  885. // Get from relative position
  886. return PositionToValue(val);
  887. }
  888. #endregion
  889. #region Axis scale methods
  890. /// <summary>
  891. /// Sets axis position. Axis position depends
  892. /// on crossing and reversed value.
  893. /// </summary>
  894. internal void SetAxisPosition()
  895. {
  896. // Change position of the axis
  897. if( GetOppositeAxis().isReversed )
  898. {
  899. if( AxisPosition == AxisPosition.Left )
  900. AxisPosition = AxisPosition.Right;
  901. else if( AxisPosition == AxisPosition.Right )
  902. AxisPosition = AxisPosition.Left;
  903. else if( AxisPosition == AxisPosition.Top )
  904. AxisPosition = AxisPosition.Bottom;
  905. else if( AxisPosition == AxisPosition.Bottom )
  906. AxisPosition = AxisPosition.Top;
  907. }
  908. }
  909. /// <summary>
  910. /// Sets temporary offset value.
  911. /// </summary>
  912. internal void SetTempAxisOffset( )
  913. {
  914. if (ChartArea.Series.Count == 0)
  915. {
  916. return;
  917. }
  918. // Conditions when this code changes margin size: Column chart,
  919. // margin is turned off, Interval offset is not used for
  920. // gridlines, tick marks and labels.
  921. Series ser = ChartArea.GetFirstSeries();
  922. if( ( ser.ChartType == SeriesChartType.Column ||
  923. ser.ChartType == SeriesChartType.StackedColumn ||
  924. ser.ChartType == SeriesChartType.StackedColumn100 ||
  925. ser.ChartType == SeriesChartType.Bar ||
  926. ser.ChartType == SeriesChartType.RangeBar ||
  927. ser.ChartType == SeriesChartType.RangeColumn ||
  928. ser.ChartType == SeriesChartType.StackedBar ||
  929. ser.ChartType == SeriesChartType.StackedBar100 ) &&
  930. margin != 100.0 && !offsetTempSet &&
  931. this._autoMinimum)
  932. {
  933. // Find offset correction for Column chart margin.
  934. double offset;
  935. marginTemp = margin;
  936. // Find point width
  937. // Check if series provide custom value for point width
  938. double pointWidthSize;
  939. string strWidth = ser[CustomPropertyName.PointWidth];
  940. if(strWidth != null)
  941. {
  942. pointWidthSize = CommonElements.ParseDouble(strWidth);
  943. }
  944. else
  945. {
  946. pointWidthSize = 0.8;
  947. }
  948. margin = ( pointWidthSize / 2 ) * 100;
  949. offset = ( margin ) / 100;
  950. double contraOffset = ( 100 - margin ) / 100;
  951. if (this._intervalsStore.Count == 0)
  952. {
  953. this._intervalsStore.Push(this.labelStyle.intervalOffset);
  954. this._intervalsStore.Push(this.majorGrid.intervalOffset);
  955. this._intervalsStore.Push(this.majorTickMark.intervalOffset);
  956. this._intervalsStore.Push(this.minorGrid.intervalOffset);
  957. this._intervalsStore.Push(this.minorTickMark.intervalOffset);
  958. }
  959. this.labelStyle.intervalOffset = Double.IsNaN(this.labelStyle.intervalOffset) ? offset : this.labelStyle.intervalOffset + offset;
  960. this.majorGrid.intervalOffset = Double.IsNaN(this.majorGrid.intervalOffset) ? offset : this.majorGrid.intervalOffset + offset;
  961. this.majorTickMark.intervalOffset = Double.IsNaN(this.majorTickMark.intervalOffset) ? offset : this.majorTickMark.intervalOffset + offset;
  962. this.minorGrid.intervalOffset = Double.IsNaN(this.minorGrid.intervalOffset) ? offset : this.minorGrid.intervalOffset + offset;
  963. this.minorTickMark.intervalOffset = Double.IsNaN(this.minorTickMark.intervalOffset) ? offset : this.minorTickMark.intervalOffset + offset;
  964. foreach( StripLine strip in ((Axis)(this)).StripLines )
  965. {
  966. _stripLineOffsets.Add( strip.IntervalOffset );
  967. strip.IntervalOffset -= contraOffset;
  968. }
  969. offsetTempSet = true;
  970. }
  971. }
  972. /// <summary>
  973. /// Resets temporary offset value.
  974. /// </summary>
  975. internal void ResetTempAxisOffset( )
  976. {
  977. if( this.offsetTempSet )
  978. {
  979. System.Diagnostics.Debug.Assert(this._intervalsStore.Count == 5, "Fail in interval store count");
  980. this.minorTickMark.intervalOffset = this._intervalsStore.Pop();
  981. this.minorGrid.intervalOffset = this._intervalsStore.Pop();
  982. this.majorTickMark.intervalOffset = this._intervalsStore.Pop();
  983. this.majorGrid.intervalOffset = this._intervalsStore.Pop();
  984. this.labelStyle.intervalOffset = this._intervalsStore.Pop();
  985. int index = 0;
  986. foreach( StripLine strip in ((Axis)(this)).StripLines )
  987. {
  988. if( _stripLineOffsets.Count > index )
  989. {
  990. strip.IntervalOffset = (double)_stripLineOffsets[index];
  991. }
  992. index++;
  993. }
  994. _stripLineOffsets.Clear();
  995. offsetTempSet = false;
  996. margin = marginTemp;
  997. }
  998. }
  999. /// <summary>
  1000. /// This function will create auto maximum and minimum values
  1001. /// using the interval. This function will make a gap between
  1002. /// data points and border of the chart area.
  1003. /// </summary>
  1004. /// <param name="inter">Interval</param>
  1005. /// <param name="shouldStartFromZero">True if minimum scale value should start from zero.</param>
  1006. /// <param name="autoMax">Maximum is auto</param>
  1007. /// <param name="autoMin">Minimum is auto</param>
  1008. /// <param name="min">Minimum value</param>
  1009. /// <param name="max">Maximum value</param>
  1010. /// <returns>Interval</returns>
  1011. internal double RoundedValues(
  1012. double inter,
  1013. bool shouldStartFromZero,
  1014. bool autoMax,
  1015. bool autoMin,
  1016. ref double min,
  1017. ref double max )
  1018. {
  1019. // For X Axes
  1020. if( axisType == AxisName.X || axisType == AxisName.X2 )
  1021. {
  1022. if( margin == 0.0 && !this.roundedXValues )
  1023. {
  1024. return inter;
  1025. }
  1026. }
  1027. else // For Y Axes
  1028. {
  1029. // Avoid dividing with 0. There is no gap.
  1030. if( margin == 0.0 )
  1031. {
  1032. return inter;
  1033. }
  1034. }
  1035. if( autoMin )
  1036. { // Set minimum value
  1037. if( min < 0.0 || ( !shouldStartFromZero && !ChartArea.stacked ) )
  1038. {
  1039. min = (double)( ((decimal)Math.Ceiling( min / inter ) - 1m ) * (decimal)inter );
  1040. }
  1041. else
  1042. {
  1043. min = 0.0;
  1044. }
  1045. }
  1046. if( autoMax )
  1047. {// Set maximum value
  1048. if( max <= 0.0 && shouldStartFromZero )
  1049. {
  1050. max = 0.0;
  1051. }
  1052. else
  1053. {
  1054. max = (double)( ((decimal)Math.Floor( max / inter ) + 1m ) * (decimal)inter );
  1055. }
  1056. }
  1057. return inter;
  1058. }
  1059. /// <summary>
  1060. /// Recalculates an intelligent interval from real interval.
  1061. /// </summary>
  1062. /// <param name="diff">Real interval.</param>
  1063. /// <returns>Inteligent interval.</returns>
  1064. internal double CalcInterval( double diff )
  1065. {
  1066. // If the interval is zero return error
  1067. if( diff == 0.0 )
  1068. {
  1069. throw (new ArgumentOutOfRangeException("diff", SR.ExceptionAxisScaleIntervalIsZero));
  1070. }
  1071. // If the real interval is > 1.0
  1072. double step = -1;
  1073. double temp = diff;
  1074. while( temp > 1.0 )
  1075. {
  1076. step ++;
  1077. temp = temp / 10.0;
  1078. if( step > 1000 )
  1079. {
  1080. throw (new InvalidOperationException(SR.ExceptionAxisScaleMinimumMaximumInvalid));
  1081. }
  1082. }
  1083. // If the real interval is < 1.0
  1084. temp = diff;
  1085. if( temp < 1.0 )
  1086. {
  1087. step = 0;
  1088. }
  1089. while( temp < 1.0 )
  1090. {
  1091. step --;
  1092. temp = temp * 10.0;
  1093. if( step < -1000 )
  1094. {
  1095. throw (new InvalidOperationException(SR.ExceptionAxisScaleMinimumMaximumInvalid));
  1096. }
  1097. }
  1098. double power = (this.IsLogarithmic) ? this.logarithmBase : 10.0;
  1099. double tempDiff = diff / Math.Pow( power, step );
  1100. if( tempDiff < 3 )
  1101. tempDiff = 2;
  1102. else if( tempDiff < 7 )
  1103. tempDiff = 5;
  1104. else
  1105. tempDiff = 10;
  1106. // Make a correction of the real interval
  1107. return tempDiff * Math.Pow( power, step );
  1108. }
  1109. /// <summary>
  1110. /// Recalculates a intelligent interval from real interval
  1111. /// obtained from maximum and minimum values
  1112. /// </summary>
  1113. /// <param name="min">Minimum</param>
  1114. /// <param name="max">Maximum</param>
  1115. /// <returns>Auto Interval</returns>
  1116. private double CalcInterval( double min, double max )
  1117. {
  1118. // Approximated interval value
  1119. return CalcInterval( ( max - min ) / 5 );
  1120. }
  1121. /// <summary>
  1122. /// Recalculates a intelligent interval from real interval
  1123. /// obtained from maximum, minimum and date type if
  1124. /// the values is date-time value.
  1125. /// </summary>
  1126. /// <param name="min">Minimum value.</param>
  1127. /// <param name="max">Maximum value.</param>
  1128. /// <param name="date">True if date.</param>
  1129. /// <param name="type">Date time interval type.</param>
  1130. /// <param name="valuesType">AxisName of date-time values.</param>
  1131. /// <returns>Auto Interval.</returns>
  1132. internal double CalcInterval(
  1133. double min,
  1134. double max,
  1135. bool date,
  1136. out DateTimeIntervalType type,
  1137. ChartValueType valuesType)
  1138. {
  1139. // AxisName is date time
  1140. if( date )
  1141. {
  1142. DateTime dateTimeMin = DateTime.FromOADate( min );
  1143. DateTime dateTimeMax = DateTime.FromOADate( max );
  1144. TimeSpan timeSpan = dateTimeMax.Subtract( dateTimeMin );
  1145. // Minutes
  1146. double inter = timeSpan.TotalMinutes;
  1147. // For Range less than 60 seconds interval is 5 sec
  1148. if( inter <= 1.0 && valuesType != ChartValueType.Date)
  1149. {
  1150. // Milli Seconds
  1151. double mlSeconds = timeSpan.TotalMilliseconds;
  1152. if(mlSeconds <= 10)
  1153. {
  1154. type = DateTimeIntervalType.Milliseconds;
  1155. return 1;
  1156. }
  1157. if(mlSeconds <= 50)
  1158. {
  1159. type = DateTimeIntervalType.Milliseconds;
  1160. return 4;
  1161. }
  1162. if(mlSeconds <= 200)
  1163. {
  1164. type = DateTimeIntervalType.Milliseconds;
  1165. return 20;
  1166. }
  1167. if(mlSeconds <= 500)
  1168. {
  1169. type = DateTimeIntervalType.Milliseconds;
  1170. return 50;
  1171. }
  1172. // Seconds
  1173. double seconds = timeSpan.TotalSeconds;
  1174. if(seconds <= 7)
  1175. {
  1176. type = DateTimeIntervalType.Seconds;
  1177. return 1;
  1178. }
  1179. else if(seconds <= 15)
  1180. {
  1181. type = DateTimeIntervalType.Seconds;
  1182. return 2;
  1183. }
  1184. else if(seconds <= 30)
  1185. {
  1186. type = DateTimeIntervalType.Seconds;
  1187. return 5;
  1188. }
  1189. else if(seconds <= 60)
  1190. {
  1191. type = DateTimeIntervalType.Seconds;
  1192. return 10;
  1193. }
  1194. }// For Range less than 120 seconds interval is 10 sec
  1195. else if( inter <= 2.0 && valuesType != ChartValueType.Date)
  1196. {
  1197. type = DateTimeIntervalType.Seconds;
  1198. return 20;
  1199. }// For Range less than 180 seconds interval is 30 sec
  1200. else if( inter <= 3.0 && valuesType != ChartValueType.Date)
  1201. {
  1202. type = DateTimeIntervalType.Seconds;
  1203. return 30;
  1204. }
  1205. // For Range less than 10 minutes interval is 1 min
  1206. else if( inter <= 10 && valuesType != ChartValueType.Date)
  1207. {
  1208. type = DateTimeIntervalType.Minutes;
  1209. return 1;
  1210. }
  1211. // For Range less than 20 minutes interval is 1 min
  1212. else if( inter <= 20 && valuesType != ChartValueType.Date)
  1213. {
  1214. type = DateTimeIntervalType.Minutes;
  1215. return 2;
  1216. }// For Range less than 60 minutes interval is 5 min
  1217. else if( inter <= 60 && valuesType != ChartValueType.Date)
  1218. {
  1219. type = DateTimeIntervalType.Minutes;
  1220. return 5;
  1221. }// For Range less than 120 minutes interval is 10 min
  1222. else if( inter <= 120 && valuesType != ChartValueType.Date)
  1223. {
  1224. type = DateTimeIntervalType.Minutes;
  1225. return 10;
  1226. }// For Range less than 180 minutes interval is 30 min
  1227. else if( inter <= 180 && valuesType != ChartValueType.Date)
  1228. {
  1229. type = DateTimeIntervalType.Minutes;
  1230. return 30;
  1231. }
  1232. // For Range less than 12 hours interval is 1 hour
  1233. else if( inter <= 60*12 && valuesType != ChartValueType.Date)
  1234. {
  1235. type = DateTimeIntervalType.Hours;
  1236. return 1;
  1237. }
  1238. // For Range less than 24 hours interval is 4 hour
  1239. else if( inter <= 60*24 && valuesType != ChartValueType.Date)
  1240. {
  1241. type = DateTimeIntervalType.Hours;
  1242. return 4;
  1243. }
  1244. // For Range less than 2 days interval is 6 hour
  1245. else if( inter <= 60*24*2 && valuesType != ChartValueType.Date)
  1246. {
  1247. type = DateTimeIntervalType.Hours;
  1248. return 6;
  1249. }
  1250. // For Range less than 3 days interval is 12 hour
  1251. else if( inter <= 60*24*3 && valuesType != ChartValueType.Date)
  1252. {
  1253. type = DateTimeIntervalType.Hours;
  1254. return 12;
  1255. }
  1256. // For Range less than 10 days interval is 1 day
  1257. else if( inter <= 60*24*10 )
  1258. {
  1259. type = DateTimeIntervalType.Days;
  1260. return 1;
  1261. }
  1262. // For Range less than 20 days interval is 2 day
  1263. else if( inter <= 60*24*20 )
  1264. {
  1265. type = DateTimeIntervalType.Days;
  1266. return 2;
  1267. }
  1268. // For Range less than 30 days interval is 3 day
  1269. else if( inter <= 60*24*30 )
  1270. {
  1271. type = DateTimeIntervalType.Days;
  1272. return 3;
  1273. }
  1274. // For Range less than 2 months interval is 1 week
  1275. else if( inter <= 60*24*30.5*2 )
  1276. {
  1277. type = DateTimeIntervalType.Weeks;
  1278. return 1;
  1279. }
  1280. // For Range less than 5 months interval is 2weeks
  1281. else if( inter <= 60*24*30.5*5 )
  1282. {
  1283. type = DateTimeIntervalType.Weeks;
  1284. return 2;
  1285. }
  1286. // For Range less than 12 months interval is 1 month
  1287. else if( inter <= 60*24*30.5*12 )
  1288. {
  1289. type = DateTimeIntervalType.Months;
  1290. return 1;
  1291. }
  1292. // For Range less than 24 months interval is 3 month
  1293. else if( inter <= 60*24*30.5*24 )
  1294. {
  1295. type = DateTimeIntervalType.Months;
  1296. return 3;
  1297. }
  1298. // For Range less than 48 months interval is 6 months
  1299. else if( inter <= 60*24*30.5*48 )
  1300. {
  1301. type = DateTimeIntervalType.Months;
  1302. return 6;
  1303. }
  1304. // For Range more than 48 months interval is year
  1305. else if( inter >= 60*24*30.5*48 )
  1306. {
  1307. type = DateTimeIntervalType.Years;
  1308. return CalcYearInterval( inter / 60 / 24 / 365 );
  1309. }
  1310. }
  1311. // Else numbers
  1312. type = DateTimeIntervalType.Number;
  1313. return CalcInterval( min, max );
  1314. }
  1315. /// <summary>
  1316. /// Recalculates a intelligent interval for years
  1317. /// </summary>
  1318. /// <param name="years">Number of years</param>
  1319. /// <returns>Interval in years</returns>
  1320. private double CalcYearInterval( double years )
  1321. {
  1322. // If the interval is zero return error
  1323. if( years <= 1.0 )
  1324. {
  1325. throw (new ArgumentOutOfRangeException("years", SR.ExceptionAxisScaleIntervalIsLessThen1Year));
  1326. }
  1327. if( years < 5 )
  1328. return 1;
  1329. else if( years < 10 )
  1330. return 2;
  1331. // Make a correction of the interval
  1332. return Math.Floor( years / 5 );
  1333. }
  1334. /// <summary>
  1335. /// This method returns the number of units
  1336. /// between min and max.
  1337. /// </summary>
  1338. /// <param name="min">Minimum.</param>
  1339. /// <param name="max">Maximum.</param>
  1340. /// <param name="type">Date type.</param>
  1341. /// <returns>Number of units.</returns>
  1342. private int GetNumOfUnits( double min, double max, DateTimeIntervalType type )
  1343. {
  1344. double current = ChartHelper.GetIntervalSize(min, 1, type);
  1345. return (int)Math.Round((max - min) / current);
  1346. }
  1347. /// <summary>
  1348. /// This method checks if value type is date-time.
  1349. /// </summary>
  1350. /// <returns>Date-time type or Auto.</returns>
  1351. internal ChartValueType GetDateTimeType()
  1352. {
  1353. List<string> list = null;
  1354. ChartValueType dateType = ChartValueType.Auto;
  1355. // Check if Value type is date from first series in the axis
  1356. if( axisType == AxisName.X )
  1357. {
  1358. // Check X axes type
  1359. list = ChartArea.GetXAxesSeries( AxisType.Primary, ((Axis)this).SubAxisName );
  1360. if( list.Count == 0 )
  1361. {
  1362. return ChartValueType.Auto;
  1363. }
  1364. if( Common.DataManager.Series[list[0]].IsXValueDateTime() )
  1365. {
  1366. dateType = Common.DataManager.Series[list[0]].XValueType;
  1367. }
  1368. }
  1369. else if( axisType == AxisName.X2 )
  1370. {
  1371. // Check X2 axes type
  1372. list = ChartArea.GetXAxesSeries( AxisType.Secondary, ((Axis)this).SubAxisName );
  1373. if( list.Count == 0 )
  1374. {
  1375. return ChartValueType.Auto;
  1376. }
  1377. if( Common.DataManager.Series[list[0]].IsXValueDateTime() )
  1378. {
  1379. dateType = Common.DataManager.Series[list[0]].XValueType;
  1380. }
  1381. }
  1382. else if( axisType == AxisName.Y )
  1383. {
  1384. // Check Y axes type
  1385. list = ChartArea.GetYAxesSeries( AxisType.Primary, ((Axis)this).SubAxisName );
  1386. if( list.Count == 0 )
  1387. {
  1388. return ChartValueType.Auto;
  1389. }
  1390. if( Common.DataManager.Series[list[0]].IsYValueDateTime() )
  1391. {
  1392. dateType = Common.DataManager.Series[list[0]].YValueType;
  1393. }
  1394. }
  1395. else if( axisType == AxisName.Y2 )
  1396. {
  1397. // Check Y2 axes type
  1398. list = ChartArea.GetYAxesSeries( AxisType.Secondary, ((Axis)this).SubAxisName );
  1399. if( list.Count == 0 )
  1400. {
  1401. return ChartValueType.Auto;
  1402. }
  1403. if( Common.DataManager.Series[list[0]].IsYValueDateTime() )
  1404. {
  1405. dateType = Common.DataManager.Series[list[0]].YValueType;
  1406. }
  1407. }
  1408. return dateType;
  1409. }
  1410. /// <summary>
  1411. /// This method removes "Auto", "min", "max" from crossing
  1412. /// value and creates a double value.
  1413. /// </summary>
  1414. /// <returns>Crossing value</returns>
  1415. private double GetCrossing()
  1416. {
  1417. if( Double.IsNaN(crossing) )
  1418. {
  1419. if( Common.ChartTypeRegistry.GetChartType( (string)ChartArea.ChartTypes[0] ).ZeroCrossing )
  1420. {
  1421. if( ViewMinimum > 0.0 )
  1422. {
  1423. return ViewMinimum;
  1424. }
  1425. else if( ViewMaximum < 0.0 )
  1426. {
  1427. return ViewMaximum;
  1428. }
  1429. else
  1430. {
  1431. return 0.0;
  1432. }
  1433. }
  1434. else
  1435. {
  1436. return ViewMinimum;
  1437. }
  1438. }
  1439. else if( crossing == Double.MaxValue )
  1440. {
  1441. return ViewMaximum;
  1442. }
  1443. else if( crossing == Double.MinValue )
  1444. {
  1445. return ViewMinimum;
  1446. }
  1447. return crossing;
  1448. }
  1449. /// <summary>
  1450. /// Set auto minimum number. The minimum number
  1451. /// which was sent to this function will be used to
  1452. /// estimate a rounded minimum.
  1453. /// </summary>
  1454. /// <param name="min"> This value is a recommendation for the minimum value. </param>
  1455. internal void SetAutoMinimum(double min)
  1456. {
  1457. // Set the minimum
  1458. if( _autoMinimum )
  1459. {
  1460. minimum = min;
  1461. }
  1462. }
  1463. /// <summary>
  1464. /// Set auto maximum number. The maximum number
  1465. /// which was sent to this function will be used to
  1466. /// estimate a rounded maximum.
  1467. /// </summary>
  1468. /// <param name="max">This value is a recommendation for the maximum value.</param>
  1469. internal void SetAutoMaximum(double max)
  1470. {
  1471. // Set the maximum
  1472. if( _autoMaximum )
  1473. {
  1474. maximum = max;
  1475. }
  1476. }
  1477. /// <summary>
  1478. /// Find opposite axis of this axis. What is opposite
  1479. /// axis depend on first series in chart area and primary
  1480. /// and secondary X and Y axes for the first series.
  1481. /// </summary>
  1482. /// <returns>Opposite axis</returns>
  1483. internal Axis GetOppositeAxis()
  1484. {
  1485. // Oppoiste axis found
  1486. if (oppositeAxis != null)
  1487. {
  1488. return oppositeAxis;
  1489. }
  1490. List<string> list;
  1491. switch( axisType )
  1492. {
  1493. // X Axis
  1494. case AxisName.X:
  1495. list = ChartArea.GetXAxesSeries( AxisType.Primary, ((Axis)this).SubAxisName );
  1496. // There aren't data series
  1497. if( list.Count == 0 )
  1498. oppositeAxis = ChartArea.AxisY;
  1499. // Take opposite axis from the first series from chart area
  1500. else if( Common.DataManager.Series[list[0]].YAxisType == AxisType.Primary )
  1501. oppositeAxis = ChartArea.AxisY.GetSubAxis(Common.DataManager.Series[list[0]].YSubAxisName);
  1502. else
  1503. oppositeAxis = ChartArea.AxisY2.GetSubAxis(Common.DataManager.Series[list[0]].YSubAxisName);
  1504. break;
  1505. // X2 Axis
  1506. case AxisName.X2:
  1507. list = ChartArea.GetXAxesSeries( AxisType.Secondary, ((Axis)this).SubAxisName );
  1508. // There aren't data series
  1509. if( list.Count == 0 )
  1510. oppositeAxis = ChartArea.AxisY2;
  1511. // Take opposite axis from the first series from chart area
  1512. else if( Common.DataManager.Series[list[0]].YAxisType == AxisType.Primary)
  1513. oppositeAxis = ChartArea.AxisY.GetSubAxis(Common.DataManager.Series[list[0]].YSubAxisName);
  1514. else
  1515. oppositeAxis = ChartArea.AxisY2.GetSubAxis(Common.DataManager.Series[list[0]].YSubAxisName);
  1516. break;
  1517. // Y Axis
  1518. case AxisName.Y:
  1519. list = ChartArea.GetYAxesSeries( AxisType.Primary, ((Axis)this).SubAxisName );
  1520. // There aren't data series
  1521. if( list.Count == 0 )
  1522. oppositeAxis = ChartArea.AxisX;
  1523. // Take opposite axis from the first series from chart area
  1524. else if( Common.DataManager.Series[list[0]].XAxisType == AxisType.Primary )
  1525. oppositeAxis = ChartArea.AxisX.GetSubAxis(Common.DataManager.Series[list[0]].XSubAxisName);
  1526. else
  1527. oppositeAxis = ChartArea.AxisX2.GetSubAxis(Common.DataManager.Series[list[0]].XSubAxisName);
  1528. break;
  1529. // Y2 Axis
  1530. case AxisName.Y2:
  1531. list = ChartArea.GetYAxesSeries( AxisType.Secondary, ((Axis)this).SubAxisName );
  1532. // There aren't data series
  1533. if( list.Count == 0 )
  1534. oppositeAxis = ChartArea.AxisX2;
  1535. // Take opposite axis from the first series from chart area
  1536. else if( Common.DataManager.Series[list[0]].XAxisType == AxisType.Primary )
  1537. oppositeAxis = ChartArea.AxisX.GetSubAxis(Common.DataManager.Series[list[0]].XSubAxisName);
  1538. else
  1539. oppositeAxis = ChartArea.AxisX2.GetSubAxis(Common.DataManager.Series[list[0]].XSubAxisName);
  1540. break;
  1541. }
  1542. return oppositeAxis;
  1543. }
  1544. /// <summary>
  1545. /// This function converts Values from Axes to
  1546. /// linear relative positions.
  1547. /// </summary>
  1548. /// <param name="axisValue">Value from axis.</param>
  1549. /// <returns>Relative position.</returns>
  1550. internal double GetLinearPosition( double axisValue )
  1551. {
  1552. bool circularArea = (ChartArea == null || !ChartArea.chartAreaIsCurcular) ?
  1553. false : true;
  1554. // Check if some value calculation is optimized
  1555. if(!this.optimizedGetPosition)
  1556. {
  1557. paintViewMax = ViewMaximum;
  1558. paintViewMin = ViewMinimum;
  1559. paintRange = paintViewMax - paintViewMin;
  1560. paintAreaPosition = PlotAreaPosition.ToRectangleF();
  1561. // Update position for circular chart area
  1562. if(circularArea)
  1563. {
  1564. paintAreaPosition.Width /= 2.0f;
  1565. paintAreaPosition.Height /= 2.0f;
  1566. }
  1567. paintAreaPositionBottom = paintAreaPosition.Y + paintAreaPosition.Height;
  1568. paintAreaPositionRight = paintAreaPosition.X + paintAreaPosition.Width;
  1569. // The Chart area size
  1570. if( AxisPosition == AxisPosition.Top || AxisPosition == AxisPosition.Bottom )
  1571. paintChartAreaSize = paintAreaPosition.Width;
  1572. else
  1573. paintChartAreaSize = paintAreaPosition.Height;
  1574. valueMultiplier = 0.0;
  1575. if( paintRange != 0 )
  1576. {
  1577. valueMultiplier = paintChartAreaSize / paintRange;
  1578. }
  1579. }
  1580. // The Chart area pixel size
  1581. double position = valueMultiplier * ( axisValue - paintViewMin);
  1582. // Check if axis scale segments are enabled
  1583. if(this.scaleSegmentsUsed)
  1584. {
  1585. AxisScaleSegment scaleSegment = this.ScaleSegments.FindScaleSegmentForAxisValue(axisValue);
  1586. if(scaleSegment != null)
  1587. {
  1588. double segmentSize = 0.0;
  1589. double segmentPosition = 0.0;
  1590. scaleSegment.GetScalePositionAndSize(paintChartAreaSize, out segmentPosition, out segmentSize);
  1591. // Make sure value do not exceed max possible
  1592. if(!this.ScaleSegments.AllowOutOfScaleValues)
  1593. {
  1594. if(axisValue > scaleSegment.ScaleMaximum)
  1595. {
  1596. axisValue = scaleSegment.ScaleMaximum;
  1597. }
  1598. else if(axisValue < scaleSegment.ScaleMinimum)
  1599. {
  1600. axisValue = scaleSegment.ScaleMinimum;
  1601. }
  1602. }
  1603. double segmentScaleRange = scaleSegment.ScaleMaximum - scaleSegment.ScaleMinimum;
  1604. position = (segmentSize / segmentScaleRange) * (axisValue - scaleSegment.ScaleMinimum);
  1605. position += segmentPosition;
  1606. }
  1607. }
  1608. // Window position
  1609. // (Do Not use .Right or .Bottom methods below) - rounding issue!
  1610. if( isReversed )
  1611. {
  1612. if( AxisPosition == AxisPosition.Top || AxisPosition == AxisPosition.Bottom )
  1613. position = paintAreaPositionRight - position;
  1614. else
  1615. position = paintAreaPosition.Y + position;
  1616. }
  1617. else
  1618. {
  1619. if( AxisPosition == AxisPosition.Top || AxisPosition == AxisPosition.Bottom )
  1620. position = paintAreaPosition.X + position;
  1621. else
  1622. position = paintAreaPositionBottom - position;
  1623. }
  1624. return position;
  1625. }
  1626. #endregion
  1627. #region Axis estimate axis methods
  1628. /// <summary>
  1629. /// This function recalculates minimum maximum and interval.
  1630. /// The function uses current values for minimum and maximum to
  1631. /// find rounding values. If the value from the data source for the
  1632. /// maximum value is 376.5 this function will return 380. This function
  1633. /// also set interval type for date
  1634. /// </summary>
  1635. internal void EstimateAxis()
  1636. {
  1637. double axisInterval;
  1638. // Check if veiw size specified without scaleView position
  1639. if(!Double.IsNaN(this.ScaleView.Size))
  1640. {
  1641. // If size set only use axis minimum for scaleView position
  1642. if(Double.IsNaN(this.ScaleView.Position))
  1643. {
  1644. this.ScaleView.Position = this.Minimum;
  1645. }
  1646. }
  1647. // Zooming Mode
  1648. if( !Double.IsNaN(_scaleView.Position) && !Double.IsNaN(_scaleView.Size) )
  1649. {
  1650. double viewMaximum = ViewMaximum;
  1651. double viewMinimum = ViewMinimum;
  1652. // IsLogarithmic axes
  1653. if (this._isLogarithmic)
  1654. {
  1655. viewMaximum = Math.Pow( this.logarithmBase, viewMaximum );
  1656. viewMinimum = Math.Pow( this.logarithmBase, viewMinimum );
  1657. }
  1658. else
  1659. {
  1660. // Add rounding and gap for maximum and minimum
  1661. EstimateAxis( ref this.minimum, ref this.maximum, _autoMaximum, _autoMinimum );
  1662. }
  1663. // Find Interval for Zoom
  1664. axisInterval = EstimateAxis( ref viewMinimum, ref viewMaximum, true, true );
  1665. }
  1666. else // No Zooming mode
  1667. {
  1668. // Estimate axis shoud be always called for non logarithmic axis
  1669. axisInterval = EstimateAxis( ref this.minimum, ref this.maximum, _autoMaximum, _autoMinimum );
  1670. }
  1671. // Set intervals for grids, tick marks and labels
  1672. if( axisInterval <= 0.0 )
  1673. {
  1674. throw (new InvalidOperationException(SR.ExceptionAxisScaleAutoIntervalInvalid));
  1675. }
  1676. else
  1677. {
  1678. // This code checks if all series in the chart area have “integer type”
  1679. // for specified axes, which means int, uint, long and ulong and rounds interval.
  1680. #if SUBAXES
  1681. if( ChartArea.SeriesIntegerType( this.axisType, ((Axis)this).SubAxisName ) )
  1682. #else // SUBAXES
  1683. if ( ChartArea.SeriesIntegerType( this.axisType, string.Empty ))
  1684. #endif // SUBAXES
  1685. {
  1686. axisInterval = Math.Round( axisInterval );
  1687. if( axisInterval == 0.0 )
  1688. {
  1689. axisInterval = 1.0;
  1690. }
  1691. // Round Minimum to floor value if type is integer
  1692. minimum = Math.Floor( minimum );
  1693. }
  1694. SetInterval = axisInterval;
  1695. }
  1696. }
  1697. /// <summary>
  1698. /// This function recalculates minimum maximum and interval.
  1699. /// The function uses current values for minimum and maximum to
  1700. /// find rounding values. If the value from the data source for the
  1701. /// maximum value is 376.5 this function will return 380. This function
  1702. /// also set interval type for date
  1703. /// </summary>
  1704. /// <param name="minimumValue">Minimum</param>
  1705. /// <param name="maximumValue">Maximum</param>
  1706. /// <param name="autoMaximum">Maximum value is Auto</param>
  1707. /// <param name="autoMinimum">Minimum value is Auto</param>
  1708. /// <returns>Interval</returns>
  1709. internal double EstimateAxis( ref double minimumValue, ref double maximumValue, bool autoMaximum, bool autoMinimum )
  1710. {
  1711. double axisInterval;
  1712. // The axis minimum value is greater than the maximum value.
  1713. if( maximumValue < minimumValue )
  1714. {
  1715. if(!this.Common.ChartPicture.SuppressExceptions)
  1716. {
  1717. throw (new InvalidOperationException(SR.ExceptionAxisScaleMinimumValueIsGreaterThenMaximumDataPoint));
  1718. }
  1719. else
  1720. {
  1721. // Max axis scale should be always bigger
  1722. double tempValue = maximumValue;
  1723. maximumValue = minimumValue;
  1724. minimumValue = tempValue;
  1725. }
  1726. }
  1727. // Take Value type
  1728. ChartValueType dateType = GetDateTimeType();
  1729. // Axis type is logarithmic
  1730. if (_isLogarithmic)
  1731. {
  1732. axisInterval = EstimateLogarithmicAxis( ref minimumValue, ref maximumValue, crossing, autoMaximum, autoMinimum );
  1733. }
  1734. // Axis type is date
  1735. else if( dateType != ChartValueType.Auto)
  1736. {
  1737. axisInterval = EstimateDateAxis( ref minimumValue, ref maximumValue, autoMaximum, autoMinimum, dateType );
  1738. }
  1739. // Axis type is number
  1740. else
  1741. {
  1742. axisInterval = EstimateNumberAxis( ref minimumValue, ref maximumValue, this.IsStartedFromZero, this.prefferedNumberofIntervals, autoMaximum, autoMinimum );
  1743. }
  1744. // Set intervals for grids, tick marks and labels
  1745. if( axisInterval <= 0.0 )
  1746. {
  1747. throw (new InvalidOperationException(SR.ExceptionAxisScaleAutoIntervalInvalid));
  1748. }
  1749. else
  1750. {
  1751. // Set interval for Grid lines Tick Marks and labels
  1752. SetInterval = axisInterval;
  1753. }
  1754. return axisInterval;
  1755. }
  1756. /// <summary>
  1757. /// This function recalculates minimum maximum and interval for
  1758. /// logarithmic axis. The function uses current values for minimum and
  1759. /// maximum to find new rounding values.
  1760. /// </summary>
  1761. /// <param name="minimumValue">Current Minimum value</param>
  1762. /// <param name="maximumValue">Current Maximum value</param>
  1763. /// <param name="crossingValue">Crossing value</param>
  1764. /// <param name="autoMaximum">Maximum value is Auto</param>
  1765. /// <param name="autoMinimum">Minimum value is Auto</param>
  1766. /// <returns>Interval</returns>
  1767. private double EstimateLogarithmicAxis( ref double minimumValue, ref double maximumValue, double crossingValue, bool autoMaximum, bool autoMinimum )
  1768. {
  1769. double axisInterval;
  1770. if( !logarithmicConvertedToLinear )
  1771. {
  1772. // Remember values. Do not use POW function because of rounding.
  1773. this.logarithmicMinimum = this.minimum;
  1774. this.logarithmicMaximum = this.maximum;
  1775. }
  1776. // For log axis margin always turn on.
  1777. margin = 100;
  1778. // Supress zero and negative values with logarithmic axis exceptions
  1779. if(this.Common != null && this.Common.Chart != null && this.Common.Chart.chartPicture.SuppressExceptions)
  1780. {
  1781. if (minimumValue <= 0.0 )
  1782. {
  1783. minimumValue = 1.0;
  1784. }
  1785. if (maximumValue <= 0.0 )
  1786. {
  1787. maximumValue = 1.0;
  1788. }
  1789. if (crossingValue <= 0.0 && crossingValue != Double.MinValue )
  1790. {
  1791. crossingValue = 1.0;
  1792. }
  1793. }
  1794. // The logarithmic axes can not show negative values.
  1795. if( minimumValue <= 0.0 || maximumValue <= 0.0 || crossingValue <= 0.0 )
  1796. {
  1797. if (minimumValue <= 0.0 )
  1798. throw (new ArgumentOutOfRangeException("minimumValue", SR.ExceptionAxisScaleLogarithmicNegativeValues));
  1799. if (maximumValue <= 0.0 )
  1800. throw (new ArgumentOutOfRangeException("maximumValue", SR.ExceptionAxisScaleLogarithmicNegativeValues));
  1801. }
  1802. // Change crossing to linear scale
  1803. crossingValue = Math.Log( crossingValue, this.logarithmBase );
  1804. // Change minimum and maximum to linear scale
  1805. minimumValue = Math.Log( minimumValue, this.logarithmBase );
  1806. maximumValue = Math.Log( maximumValue, this.logarithmBase );
  1807. logarithmicConvertedToLinear = true;
  1808. // Find interval - Make approximately 5 grid lines and labels.
  1809. double diff = ( maximumValue - minimumValue ) / 5;
  1810. // Make good interval for logarithmic scale
  1811. axisInterval = Math.Floor( diff );
  1812. if( axisInterval == 0 ) axisInterval = 1;
  1813. if( autoMinimum && autoMaximum )
  1814. {
  1815. // The maximum and minimum rounding with interval
  1816. RoundedValues( axisInterval, this.IsStartedFromZero, autoMaximum, autoMinimum, ref minimumValue, ref maximumValue );
  1817. }
  1818. // Do not allow min/max values more than a hundred
  1819. if(ChartArea.hundredPercent)
  1820. {
  1821. if(autoMinimum)
  1822. {
  1823. if(minimumValue < 0)
  1824. minimumValue = 0;
  1825. }
  1826. if(autoMaximum)
  1827. {
  1828. if(maximumValue > 2)
  1829. maximumValue = 2;
  1830. }
  1831. }
  1832. // Set interval for Grid lines Tick Marks and labels
  1833. return axisInterval;
  1834. }
  1835. /// <summary>
  1836. /// This function recalculates minimum maximum and interval for
  1837. /// Date axis. The function uses current values for minimum and
  1838. /// maximum to find new rounding values.
  1839. /// </summary>
  1840. /// <param name="minimumValue">Current Minimum value</param>
  1841. /// <param name="maximumValue">Current Maximum value</param>
  1842. /// <param name="autoMaximum">Maximum value is Auto</param>
  1843. /// <param name="autoMinimum">Minimum value is Auto</param>
  1844. /// <param name="valuesType">AxisName of date-time values.</param>
  1845. /// <returns>Interval</returns>
  1846. private double EstimateDateAxis(
  1847. ref double minimumValue,
  1848. ref double maximumValue,
  1849. bool autoMaximum,
  1850. bool autoMinimum,
  1851. ChartValueType valuesType)
  1852. {
  1853. double axisInterval;
  1854. double min = minimumValue;
  1855. double max = maximumValue;
  1856. // Find interval for this date type
  1857. axisInterval = CalcInterval(min, max, true, out _internalIntervalType, valuesType);
  1858. // For 3D Charts interval could be changed. After rotation
  1859. // projection of axis could be very small.
  1860. if( !double.IsNaN( this.interval3DCorrection ) &&
  1861. ChartArea.Area3DStyle.Enable3D &&
  1862. !ChartArea.chartAreaIsCurcular)
  1863. {
  1864. axisInterval = Math.Floor( axisInterval / this.interval3DCorrection );
  1865. this.interval3DCorrection = double.NaN;
  1866. }
  1867. // Find number of units between minimum and maximum
  1868. int numberOfUnits = GetNumOfUnits( min, max, _internalIntervalType );
  1869. // Make a gap between max point and axis for Y axes
  1870. if( axisType == AxisName.Y || axisType == AxisName.Y2 )
  1871. {
  1872. if (autoMinimum && minimumValue > ChartHelper.GetIntervalSize(min, axisInterval, _internalIntervalType))
  1873. {
  1874. // Add gap to the minimum value from the series
  1875. // equal half of the interval
  1876. minimumValue += ChartHelper.GetIntervalSize(
  1877. min,
  1878. - (axisInterval / 2.0) * margin / 100,
  1879. _internalIntervalType,
  1880. null,
  1881. 0.0,
  1882. DateTimeIntervalType.Number,
  1883. false,
  1884. false);
  1885. // Align minimum sacale value on the interval
  1886. minimumValue = ChartHelper.AlignIntervalStart(
  1887. minimumValue,
  1888. axisInterval * margin / 100,
  1889. _internalIntervalType);
  1890. }
  1891. // Increase maximum if not zero. Make a space between chart type
  1892. // and the end of the chart area.
  1893. if( autoMaximum && max > 0 && margin != 0.0 )
  1894. {
  1895. maximumValue = minimumValue + ChartHelper.GetIntervalSize(
  1896. minimumValue,
  1897. (double)((Math.Floor(numberOfUnits / axisInterval / margin * 100)+2) * axisInterval * margin / 100),
  1898. _internalIntervalType);
  1899. }
  1900. }
  1901. InternalIntervalType = _internalIntervalType;
  1902. // Set interval for Grid lines Tick Marks and labels
  1903. return axisInterval;
  1904. }
  1905. /// <summary>
  1906. /// This function recalculates minimum maximum and interval for
  1907. /// number type axis. The function uses current values for minimum and
  1908. /// maximum to find new rounding values.
  1909. /// </summary>
  1910. /// <param name="minimumValue">Current Minimum value</param>
  1911. /// <param name="maximumValue">Current Maximum value</param>
  1912. /// <param name="shouldStartFromZero">Should start from zero flag.</param>
  1913. /// <param name="preferredNumberOfIntervals">Preferred number of intervals. Can be set to zero for dynamic mode.</param>
  1914. /// <param name="autoMaximum">Maximum value is Auto</param>
  1915. /// <param name="autoMinimum">Minimum value is Auto</param>
  1916. /// <returns>Interval</returns>
  1917. internal double EstimateNumberAxis(
  1918. ref double minimumValue,
  1919. ref double maximumValue,
  1920. bool shouldStartFromZero,
  1921. int preferredNumberOfIntervals,
  1922. bool autoMaximum,
  1923. bool autoMinimum )
  1924. {
  1925. double axisInterval;
  1926. double min = minimumValue;
  1927. double max = maximumValue;
  1928. double diff;
  1929. if( !roundedXValues && ( axisType == AxisName.X || axisType == AxisName.X2 ) )
  1930. {
  1931. diff = ChartArea.GetPointsInterval( false, 10 );
  1932. if( diff == 0 || ( max - min ) / diff > 20 )
  1933. {
  1934. diff = ( max - min ) / preferredNumberOfIntervals;
  1935. }
  1936. }
  1937. else
  1938. {
  1939. diff = ( max - min ) / preferredNumberOfIntervals;
  1940. }
  1941. // For 3D Charts interval could be changed. After rotation
  1942. // projection of axis could be very small.
  1943. if( !double.IsNaN( this.interval3DCorrection ) &&
  1944. ChartArea.Area3DStyle.Enable3D &&
  1945. !ChartArea.chartAreaIsCurcular)
  1946. {
  1947. diff = diff / this.interval3DCorrection;
  1948. // Do not change minimum and maximum with 3D correction.
  1949. if( max - min < diff )
  1950. {
  1951. diff = max - min;
  1952. }
  1953. this.interval3DCorrection = double.NaN;
  1954. if( diff != 0.0 )
  1955. {
  1956. diff = CalcInterval( diff );
  1957. }
  1958. }
  1959. if( autoMaximum || autoMinimum )
  1960. {
  1961. if( diff == 0 )
  1962. {
  1963. // Can not find interval. Minimum and maximum are same
  1964. max = min + 1;
  1965. diff = 0.2;
  1966. axisInterval = 0.2;
  1967. }
  1968. else
  1969. {
  1970. axisInterval = CalcInterval( diff );
  1971. }
  1972. }
  1973. else
  1974. {
  1975. axisInterval = diff;
  1976. }
  1977. // Case when minimum or maximum is set and interval is > maximum.
  1978. // Reasons overflow exception.
  1979. if( ((Axis)this).interval != 0 && ((Axis)this).interval > axisInterval && minimumValue + ((Axis)this).interval > maximumValue )
  1980. {
  1981. axisInterval = ((Axis)this).interval;
  1982. if( autoMaximum )
  1983. {
  1984. maximumValue = minimumValue + axisInterval;
  1985. }
  1986. if( autoMinimum )
  1987. {
  1988. minimumValue = maximumValue - axisInterval;
  1989. }
  1990. }
  1991. // The maximum and minimum rounding for Y Axes
  1992. if( axisType == AxisName.Y || axisType == AxisName.Y2 || ( roundedXValues && ( axisType == AxisName.X || axisType == AxisName.X2 )))
  1993. {
  1994. // Start from zero for the 100% chart types
  1995. bool minIsZero = false;
  1996. bool maxIsZero = false;
  1997. if(ChartArea.hundredPercent)
  1998. {
  1999. minIsZero = (minimumValue == 0.0);
  2000. maxIsZero = (maximumValue == 0.0);
  2001. }
  2002. // Round min/max values
  2003. RoundedValues( axisInterval, shouldStartFromZero, autoMaximum, autoMinimum, ref minimumValue, ref maximumValue );
  2004. // Do not allow min/max values more than a hundred
  2005. if(ChartArea.hundredPercent)
  2006. {
  2007. if(autoMinimum)
  2008. {
  2009. if(minimumValue < -100)
  2010. minimumValue = -100;
  2011. if(minIsZero)
  2012. minimumValue = 0;
  2013. }
  2014. if(autoMaximum)
  2015. {
  2016. if(maximumValue > 100)
  2017. maximumValue = 100;
  2018. if(maxIsZero)
  2019. maximumValue = 0;
  2020. }
  2021. }
  2022. }
  2023. // Set interval for Grid lines Tick Marks and labels
  2024. return axisInterval;
  2025. }
  2026. #endregion
  2027. }
  2028. }