ChartArea.cs 114 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092209320942095209620972098209921002101210221032104210521062107210821092110211121122113211421152116211721182119212021212122212321242125212621272128212921302131213221332134213521362137213821392140214121422143214421452146214721482149215021512152215321542155215621572158215921602161216221632164216521662167216821692170217121722173217421752176217721782179218021812182218321842185218621872188218921902191219221932194219521962197219821992200220122022203220422052206220722082209221022112212221322142215221622172218221922202221222222232224222522262227222822292230223122322233223422352236223722382239224022412242224322442245224622472248224922502251225222532254225522562257225822592260226122622263226422652266226722682269227022712272227322742275227622772278227922802281228222832284228522862287228822892290229122922293229422952296229722982299230023012302230323042305230623072308230923102311231223132314231523162317231823192320232123222323232423252326232723282329233023312332233323342335233623372338233923402341234223432344234523462347234823492350235123522353235423552356235723582359236023612362236323642365236623672368236923702371237223732374237523762377237823792380238123822383238423852386238723882389239023912392239323942395239623972398239924002401240224032404240524062407240824092410241124122413241424152416241724182419242024212422242324242425242624272428242924302431243224332434243524362437243824392440244124422443244424452446244724482449245024512452245324542455245624572458245924602461246224632464246524662467246824692470247124722473247424752476247724782479248024812482248324842485248624872488248924902491249224932494249524962497249824992500250125022503250425052506250725082509251025112512251325142515251625172518251925202521252225232524252525262527252825292530253125322533253425352536253725382539254025412542254325442545254625472548254925502551255225532554255525562557255825592560256125622563256425652566256725682569257025712572257325742575257625772578257925802581258225832584258525862587258825892590259125922593259425952596259725982599260026012602260326042605260626072608260926102611261226132614261526162617261826192620262126222623262426252626262726282629263026312632263326342635263626372638263926402641264226432644264526462647264826492650265126522653265426552656265726582659266026612662266326642665266626672668266926702671267226732674267526762677267826792680268126822683268426852686268726882689269026912692269326942695269626972698269927002701270227032704270527062707270827092710271127122713271427152716271727182719272027212722272327242725272627272728272927302731273227332734273527362737273827392740274127422743274427452746274727482749275027512752275327542755275627572758275927602761276227632764276527662767276827692770277127722773277427752776277727782779278027812782278327842785278627872788278927902791279227932794279527962797279827992800280128022803280428052806280728082809281028112812281328142815281628172818281928202821282228232824282528262827282828292830283128322833283428352836283728382839284028412842284328442845284628472848284928502851285228532854285528562857285828592860286128622863286428652866286728682869287028712872287328742875287628772878287928802881288228832884288528862887288828892890289128922893289428952896289728982899290029012902290329042905290629072908290929102911291229132914291529162917291829192920292129222923292429252926292729282929293029312932293329342935293629372938293929402941294229432944294529462947294829492950295129522953295429552956295729582959296029612962296329642965296629672968296929702971297229732974297529762977297829792980298129822983298429852986298729882989299029912992299329942995299629972998299930003001300230033004300530063007300830093010301130123013301430153016301730183019302030213022302330243025302630273028302930303031303230333034303530363037303830393040304130423043304430453046304730483049305030513052305330543055305630573058
  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: The ChartArea class represents one chart area within
  6. // a chart image, and is used to plot one or more chart
  7. // series. The number of chart series that can be plotted
  8. // in a chart area is unlimited.
  9. //
  10. using System;
  11. using System.Collections;
  12. using System.Collections.Specialized;
  13. using System.ComponentModel;
  14. using System.ComponentModel.Design;
  15. using System.Data;
  16. using System.Drawing;
  17. using System.Drawing.Design;
  18. using System.Drawing.Drawing2D;
  19. using System.Globalization;
  20. using System.Diagnostics.CodeAnalysis;
  21. using System.Windows.Forms;
  22. using FastReport.DataVisualization.Charting.Data;
  23. using FastReport.DataVisualization.Charting.ChartTypes;
  24. using FastReport.DataVisualization.Charting.Utilities;
  25. using FastReport.DataVisualization.Charting.Borders3D;
  26. using FastReport.DataVisualization.Charting;
  27. using System.ComponentModel.Design.Serialization;
  28. using System.Reflection;
  29. namespace FastReport.DataVisualization.Charting
  30. {
  31. using FontStyle = System.Drawing.FontStyle;
  32. #region Chart area aligment enumerations
  33. /// <summary>
  34. /// An enumeration of the alignment orientations of a ChartArea
  35. /// </summary>
  36. [Flags]
  37. public enum AreaAlignmentOrientations
  38. {
  39. /// <summary>
  40. /// Chart areas are not automatically aligned.
  41. /// </summary>
  42. None = 0,
  43. /// <summary>
  44. /// Chart areas are aligned vertically.
  45. /// </summary>
  46. Vertical = 1,
  47. /// <summary>
  48. /// Chart areas are aligned horizontally.
  49. /// </summary>
  50. Horizontal = 2,
  51. /// <summary>
  52. /// Chart areas are aligned using all values (horizontally and vertically).
  53. /// </summary>
  54. All = Vertical | Horizontal
  55. }
  56. /// <summary>
  57. /// An enumeration of the alignment styles of a ChartArea
  58. /// </summary>
  59. [Flags]
  60. public enum AreaAlignmentStyles
  61. {
  62. /// <summary>
  63. /// Chart areas are not automatically aligned.
  64. /// </summary>
  65. None = 0,
  66. /// <summary>
  67. /// Chart areas are aligned by positions.
  68. /// </summary>
  69. Position = 1,
  70. /// <summary>
  71. /// Chart areas are aligned by inner plot positions.
  72. /// </summary>
  73. PlotPosition = 2,
  74. /// <summary>
  75. /// Chart areas are aligned by axes views.
  76. /// </summary>
  77. AxesView = 4,
  78. /// <summary>
  79. /// Cursor and Selection alignment.
  80. /// </summary>
  81. Cursor = 8,
  82. /// <summary>
  83. /// Complete alignment.
  84. /// </summary>
  85. All = Position | PlotPosition | Cursor | AxesView
  86. }
  87. #endregion
  88. /// <summary>
  89. /// The ChartArea class is used to create and display a chart
  90. /// area within a chart image. The chart area is a rectangular
  91. /// area on a chart image. It has 4 axes, horizontal and vertical grids.
  92. /// A chart area can contain more than one different chart type.
  93. /// The number of chart series that can be plotted in a chart area
  94. /// is unlimited.
  95. ///
  96. /// ChartArea class exposes all the properties and methods
  97. /// of its base ChartArea3D class.
  98. /// </summary>
  99. [
  100. DefaultProperty("Axes"),
  101. SRDescription("DescriptionAttributeChartArea_ChartArea"),
  102. ]
  103. public partial class ChartArea : ChartNamedElement
  104. {
  105. #region Chart Area Fields
  106. /// <summary>
  107. /// Plot area position
  108. /// </summary>
  109. internal ElementPosition PlotAreaPosition;
  110. // Private data members, which store properties values
  111. private Axis[] _axisArray = new Axis[4];
  112. private Color _backColor = Color.Empty;
  113. private bool _backColorIsSet = false;
  114. private ChartHatchStyle _backHatchStyle = ChartHatchStyle.None;
  115. private string _backImage = "";
  116. private ChartImageWrapMode _backImageWrapMode = ChartImageWrapMode.Tile;
  117. private Color _backImageTransparentColor = Color.Empty;
  118. private ChartImageAlignmentStyle _backImageAlignment = ChartImageAlignmentStyle.TopLeft;
  119. private GradientStyle _backGradientStyle = GradientStyle.None;
  120. private Color _backSecondaryColor = Color.Empty;
  121. private Color _borderColor = Color.Black;
  122. private int _borderWidth = 1;
  123. private ChartDashStyle _borderDashStyle = ChartDashStyle.NotSet;
  124. private int _shadowOffset = 0;
  125. private Color _shadowColor = Color.FromArgb(128, 0, 0, 0);
  126. private ElementPosition _areaPosition = null;
  127. private ElementPosition _innerPlotPosition = null;
  128. internal int IterationCounter = 0;
  129. private bool _isSameFontSizeForAllAxes = false;
  130. internal float axesAutoFontSize = 8f;
  131. private string _alignWithChartArea = Constants.NotSetValue;
  132. private AreaAlignmentOrientations _alignmentOrientation = AreaAlignmentOrientations.Vertical;
  133. private AreaAlignmentStyles _alignmentStyle = AreaAlignmentStyles.All;
  134. private int _circularSectorNumber = int.MinValue;
  135. private int _circularUsePolygons = int.MinValue;
  136. // Flag indicates that chart area is acurrently aligned
  137. internal bool alignmentInProcess = false;
  138. // Chart area position before adjustments
  139. internal RectangleF originalAreaPosition = RectangleF.Empty;
  140. // Chart area inner plot position before adjustments
  141. internal RectangleF originalInnerPlotPosition = RectangleF.Empty;
  142. // Chart area position before adjustments
  143. internal RectangleF lastAreaPosition = RectangleF.Empty;
  144. // Center of the circulat chart area
  145. internal PointF circularCenter = PointF.Empty;
  146. private ArrayList _circularAxisList = null;
  147. // Buffered plotting area image
  148. internal Bitmap areaBufferBitmap = null;
  149. private Cursor _cursorX = new Cursor();
  150. private Cursor _cursorY = new Cursor();
  151. // Area SmartLabel class
  152. internal SmartLabel smartLabels = new SmartLabel();
  153. // Gets or sets a flag that specifies whether the chart area is visible.
  154. private bool _visible = true;
  155. #endregion
  156. #region Chart Area Cursor properties
  157. /// <summary>
  158. /// Gets or sets a Cursor object that is used for cursors and selected ranges along the X-axis.
  159. /// </summary>
  160. [
  161. SRCategory("CategoryAttributeCursor"),
  162. Bindable(true),
  163. DefaultValue(null),
  164. SRDescription("DescriptionAttributeChartArea_CursorX"),
  165. DesignerSerializationVisibility(DesignerSerializationVisibility.Content),
  166. TypeConverter(typeof(NoNameExpandableObjectConverter)),
  167. ]
  168. public Cursor CursorX
  169. {
  170. get
  171. {
  172. return _cursorX;
  173. }
  174. set
  175. {
  176. _cursorX = value;
  177. // Initialize chart object
  178. _cursorX.Initialize(this, AxisName.X);
  179. CallOnModifing();
  180. }
  181. }
  182. /// <summary>
  183. /// Gets or sets a Cursor object that is used for cursors and selected ranges along the Y-axis.
  184. /// </summary>
  185. [
  186. SRCategory("CategoryAttributeCursor"),
  187. Bindable(true),
  188. DefaultValue(null),
  189. SRDescription("DescriptionAttributeChartArea_CursorY"),
  190. DesignerSerializationVisibility(DesignerSerializationVisibility.Content),
  191. TypeConverter(typeof(NoNameExpandableObjectConverter)),
  192. ]
  193. public Cursor CursorY
  194. {
  195. get
  196. {
  197. return _cursorY;
  198. }
  199. set
  200. {
  201. _cursorY = value;
  202. // Initialize chart object
  203. _cursorY.Initialize(this, AxisName.Y);
  204. CallOnModifing();
  205. }
  206. }
  207. #endregion
  208. #region Chart Area properties
  209. /// <summary>
  210. /// Gets or sets a flag that specifies whether the chart area is visible.
  211. /// </summary>
  212. /// <remarks>
  213. /// When this flag is set to false, all series, legends, titles and annotation objects
  214. /// associated with the chart area will also be hidden.
  215. /// </remarks>
  216. /// <value>
  217. /// <b>True</b> if the chart area is visible; <b>false</b> otherwise.
  218. /// </value>
  219. [
  220. SRCategory("CategoryAttributeAppearance"),
  221. DefaultValue(true),
  222. SRDescription("DescriptionAttributeChartArea_Visible"),
  223. ParenthesizePropertyNameAttribute(true),
  224. ]
  225. virtual public bool Visible
  226. {
  227. get
  228. {
  229. return _visible;
  230. }
  231. set
  232. {
  233. _visible = value;
  234. this.Invalidate();
  235. CallOnModifing();
  236. }
  237. }
  238. /// <summary>
  239. /// Gets or sets the name of the ChartArea object to which this chart area should be aligned.
  240. /// </summary>
  241. [
  242. SRCategory("CategoryAttributeAlignment"),
  243. Bindable(true),
  244. DefaultValue(Constants.NotSetValue),
  245. SRDescription("DescriptionAttributeChartArea_AlignWithChartArea"),
  246. TypeConverter(typeof(LegendAreaNameConverter))
  247. ]
  248. public string AlignWithChartArea
  249. {
  250. get
  251. {
  252. return _alignWithChartArea;
  253. }
  254. set
  255. {
  256. if (value != _alignWithChartArea)
  257. {
  258. if (String.IsNullOrEmpty(value))
  259. {
  260. _alignWithChartArea = Constants.NotSetValue;
  261. }
  262. else
  263. {
  264. if (Chart != null && Chart.ChartAreas != null)
  265. {
  266. Chart.ChartAreas.VerifyNameReference(value);
  267. }
  268. _alignWithChartArea = value;
  269. }
  270. Invalidate();
  271. CallOnModifing();
  272. }
  273. }
  274. }
  275. /// <summary>
  276. /// Gets or sets the alignment orientation of a chart area.
  277. /// </summary>
  278. [
  279. SRCategory("CategoryAttributeAlignment"),
  280. Bindable(true),
  281. DefaultValue(AreaAlignmentOrientations.Vertical),
  282. SRDescription("DescriptionAttributeChartArea_AlignOrientation"),
  283. #if DESIGNER
  284. Editor(typeof(FlagsEnumUITypeEditor), typeof(UITypeEditor))
  285. #endif
  286. ]
  287. public AreaAlignmentOrientations AlignmentOrientation
  288. {
  289. get
  290. {
  291. return _alignmentOrientation;
  292. }
  293. set
  294. {
  295. _alignmentOrientation = value;
  296. Invalidate();
  297. CallOnModifing();
  298. }
  299. }
  300. /// <summary>
  301. /// Gets or sets the alignment style of the ChartArea.
  302. /// </summary>
  303. [
  304. SRCategory("CategoryAttributeAlignment"),
  305. Bindable(true),
  306. DefaultValue(AreaAlignmentStyles.All),
  307. SRDescription("DescriptionAttributeChartArea_AlignType"),
  308. #if DESIGNER
  309. Editor(typeof(FlagsEnumUITypeEditor), typeof(UITypeEditor))
  310. #endif
  311. ]
  312. public AreaAlignmentStyles AlignmentStyle
  313. {
  314. get
  315. {
  316. return _alignmentStyle;
  317. }
  318. set
  319. {
  320. _alignmentStyle = value;
  321. Invalidate();
  322. CallOnModifing();
  323. }
  324. }
  325. /// <summary>
  326. /// Gets or sets an array that represents all axes for a chart area.
  327. /// </summary>
  328. [
  329. SRCategory("CategoryAttributeAxes"),
  330. Bindable(true),
  331. SRDescription("DescriptionAttributeChartArea_Axes"),
  332. TypeConverter(typeof(AxesArrayConverter)),
  333. #if DESIGNER
  334. Editor(typeof(AxesArrayEditor), typeof(UITypeEditor)),
  335. #endif
  336. DesignerSerializationVisibilityAttribute(DesignerSerializationVisibility.Hidden),
  337. SerializationVisibilityAttribute(SerializationVisibility.Hidden)
  338. ]
  339. [System.Diagnostics.CodeAnalysis.SuppressMessage("Microsoft.Performance", "CA1819:PropertiesShouldNotReturnArrays")]
  340. public Axis[] Axes
  341. {
  342. get
  343. {
  344. return _axisArray;
  345. }
  346. set
  347. {
  348. AxisX = value[0];
  349. AxisY = value[1];
  350. AxisX2 = value[2];
  351. AxisY2 = value[3];
  352. Invalidate();
  353. CallOnModifing();
  354. }
  355. }
  356. /// <summary>
  357. /// Avoid serialization of the axes array
  358. /// </summary>
  359. [EditorBrowsableAttribute(EditorBrowsableState.Never)]
  360. internal bool ShouldSerializeAxes()
  361. {
  362. return false;
  363. }
  364. /// <summary>
  365. /// Gets or sets an Axis object that represents the primary Y-axis.
  366. /// </summary>
  367. [
  368. SRCategory("CategoryAttributeAxis"),
  369. Bindable(true),
  370. Browsable(false),
  371. SRDescription("DescriptionAttributeChartArea_AxisY"),
  372. DesignerSerializationVisibility(DesignerSerializationVisibility.Content),
  373. TypeConverter(typeof(NoNameExpandableObjectConverter))
  374. ]
  375. public Axis AxisY
  376. {
  377. get
  378. {
  379. return axisY;
  380. }
  381. set
  382. {
  383. axisY = value;
  384. axisY.Initialize(this, AxisName.Y);
  385. _axisArray[1] = axisY;
  386. Invalidate();
  387. }
  388. }
  389. /// <summary>
  390. /// Gets or sets an Axis object that represents the primary X-axis.
  391. /// </summary>
  392. [
  393. SRCategory("CategoryAttributeAxis"),
  394. Bindable(true),
  395. Browsable(false),
  396. SRDescription("DescriptionAttributeChartArea_AxisX"),
  397. DesignerSerializationVisibility(DesignerSerializationVisibility.Content),
  398. TypeConverter(typeof(NoNameExpandableObjectConverter))
  399. ]
  400. public Axis AxisX
  401. {
  402. get
  403. {
  404. return axisX;
  405. }
  406. set
  407. {
  408. axisX = value;
  409. axisX.Initialize(this, AxisName.X);
  410. _axisArray[0] = axisX;
  411. Invalidate();
  412. }
  413. }
  414. /// <summary>
  415. /// Gets or sets an Axis object that represents the secondary X-axis.
  416. /// </summary>
  417. [
  418. SRCategory("CategoryAttributeAxis"),
  419. Bindable(true),
  420. Browsable(false),
  421. SRDescription("DescriptionAttributeChartArea_AxisX2"),
  422. DesignerSerializationVisibility(DesignerSerializationVisibility.Content),
  423. TypeConverter(typeof(NoNameExpandableObjectConverter))
  424. ]
  425. public Axis AxisX2
  426. {
  427. get
  428. {
  429. return axisX2;
  430. }
  431. set
  432. {
  433. axisX2 = value;
  434. axisX2.Initialize(this, AxisName.X2);
  435. _axisArray[2] = axisX2;
  436. Invalidate();
  437. }
  438. }
  439. /// <summary>
  440. /// Gets or sets an Axis object that represents the secondary Y-axis.
  441. /// </summary>
  442. [
  443. SRCategory("CategoryAttributeAxis"),
  444. Bindable(true),
  445. Browsable(false),
  446. SRDescription("DescriptionAttributeChartArea_AxisY2"),
  447. DesignerSerializationVisibility(DesignerSerializationVisibility.Content),
  448. TypeConverter(typeof(NoNameExpandableObjectConverter))
  449. ]
  450. public Axis AxisY2
  451. {
  452. get
  453. {
  454. return axisY2;
  455. }
  456. set
  457. {
  458. axisY2 = value;
  459. axisY2.Initialize(this, AxisName.Y2);
  460. _axisArray[3] = axisY2;
  461. Invalidate();
  462. }
  463. }
  464. /// <summary>
  465. /// Gets or sets an ElementPosition object, which defines the position of a chart area object within the chart image.
  466. /// </summary>
  467. [
  468. SRCategory("CategoryAttributeAppearance"),
  469. Bindable(true),
  470. SRDescription("DescriptionAttributeChartArea_Position"),
  471. DesignerSerializationVisibility(DesignerSerializationVisibility.Content),
  472. NotifyParentPropertyAttribute(true),
  473. TypeConverter(typeof(ElementPositionConverter)),
  474. SerializationVisibilityAttribute(SerializationVisibility.Element)
  475. ]
  476. public ElementPosition Position
  477. {
  478. get
  479. {
  480. // Serialize only position values if Auto set to false
  481. if (this.Chart != null && this.Chart.serializationStatus == SerializationStatus.Saving)
  482. {
  483. if (_areaPosition.Auto)
  484. {
  485. return new ElementPosition();
  486. }
  487. else
  488. {
  489. ElementPosition newPosition = new ElementPosition();
  490. newPosition.Auto = false;
  491. newPosition.SetPositionNoAuto(_areaPosition.X, _areaPosition.Y, _areaPosition.Width, _areaPosition.Height);
  492. return newPosition;
  493. }
  494. }
  495. return _areaPosition;
  496. }
  497. set
  498. {
  499. _areaPosition = value;
  500. _areaPosition.Parent = this;
  501. _areaPosition.resetAreaAutoPosition = true;
  502. Invalidate();
  503. CallOnModifing();
  504. }
  505. }
  506. /// <summary>
  507. /// Determoines if this position should be serialized.
  508. /// </summary>
  509. /// <returns></returns>
  510. internal bool ShouldSerializePosition()
  511. {
  512. return !this.Position.Auto;
  513. }
  514. /// <summary>
  515. /// Gets or sets an ElementPosition object, which defines the inner plot position of a chart area object.
  516. /// </summary>
  517. [
  518. SRCategory("CategoryAttributeAppearance"),
  519. Bindable(true),
  520. SRDescription("DescriptionAttributeChartArea_InnerPlotPosition"),
  521. DesignerSerializationVisibility(DesignerSerializationVisibility.Content),
  522. NotifyParentPropertyAttribute(true),
  523. TypeConverter(typeof(ElementPositionConverter)),
  524. SerializationVisibilityAttribute(SerializationVisibility.Element)
  525. ]
  526. public ElementPosition InnerPlotPosition
  527. {
  528. get
  529. {
  530. // Serialize only position values if Auto set to false
  531. if (this.Common != null && this.Common.Chart != null && this.Common.Chart.serializationStatus == SerializationStatus.Saving)
  532. {
  533. if (_innerPlotPosition.Auto)
  534. {
  535. return new ElementPosition();
  536. }
  537. else
  538. {
  539. ElementPosition newPosition = new ElementPosition();
  540. newPosition.Auto = false;
  541. newPosition.SetPositionNoAuto(_innerPlotPosition.X, _innerPlotPosition.Y, _innerPlotPosition.Width, _innerPlotPosition.Height);
  542. return newPosition;
  543. }
  544. }
  545. return _innerPlotPosition;
  546. }
  547. set
  548. {
  549. _innerPlotPosition = value;
  550. _innerPlotPosition.Parent = this;
  551. Invalidate();
  552. CallOnModifing();
  553. }
  554. }
  555. /// <summary>
  556. /// Determoines if this position should be serialized.
  557. /// </summary>
  558. /// <returns></returns>
  559. internal bool ShouldSerializeInnerPlotPosition()
  560. {
  561. return !this.InnerPlotPosition.Auto;
  562. }
  563. /// <summary>
  564. /// Gets or sets the background color of a ChartArea object.
  565. /// </summary>
  566. [
  567. SRCategory("CategoryAttributeAppearance"),
  568. Bindable(true),
  569. DefaultValue(typeof(Color), ""),
  570. SRDescription("DescriptionAttributeBackColor"),
  571. NotifyParentPropertyAttribute(true),
  572. TypeConverter(typeof(ColorConverter)),
  573. #if DESIGNER
  574. Editor(typeof(ChartColorEditor), typeof(UITypeEditor))
  575. #endif
  576. ]
  577. public Color BackColor
  578. {
  579. get
  580. {
  581. if (SystemInformation.HighContrast && _backColor.IsEmpty && !_backColorIsSet)
  582. {
  583. return SystemColors.Control;
  584. }
  585. return _backColor;
  586. }
  587. set
  588. {
  589. _backColor = value;
  590. _backColorIsSet = true;
  591. Invalidate();
  592. CallOnModifing();
  593. }
  594. }
  595. /// <summary>
  596. /// Gets or sets the hatching style of a ChartArea object.
  597. /// </summary>
  598. [
  599. SRCategory("CategoryAttributeAppearance"),
  600. Bindable(true),
  601. DefaultValue(ChartHatchStyle.None),
  602. NotifyParentPropertyAttribute(true),
  603. SRDescription("DescriptionAttributeBackHatchStyle"),
  604. #if DESIGNER
  605. Editor(typeof(HatchStyleEditor), typeof(UITypeEditor))
  606. #endif
  607. ]
  608. public ChartHatchStyle BackHatchStyle
  609. {
  610. get
  611. {
  612. return _backHatchStyle;
  613. }
  614. set
  615. {
  616. _backHatchStyle = value;
  617. Invalidate();
  618. CallOnModifing();
  619. }
  620. }
  621. /// <summary>
  622. /// Gets or sets the background image of a ChartArea object.
  623. /// </summary>
  624. [
  625. SRCategory("CategoryAttributeAppearance"),
  626. Bindable(true),
  627. DefaultValue(""),
  628. SRDescription("DescriptionAttributeBackImage"),
  629. #if DESIGNER
  630. Editor(typeof(ImageValueEditor), typeof(UITypeEditor)),
  631. #endif
  632. NotifyParentPropertyAttribute(true)
  633. ]
  634. public string BackImage
  635. {
  636. get
  637. {
  638. return _backImage;
  639. }
  640. set
  641. {
  642. _backImage = value;
  643. Invalidate();
  644. CallOnModifing();
  645. }
  646. }
  647. /// <summary>
  648. /// Gets or sets the drawing mode of the background image of a ChartArea object.
  649. /// </summary>
  650. [
  651. SRCategory("CategoryAttributeAppearance"),
  652. Bindable(true),
  653. DefaultValue(ChartImageWrapMode.Tile),
  654. NotifyParentPropertyAttribute(true),
  655. SRDescription("DescriptionAttributeImageWrapMode"),
  656. ]
  657. public ChartImageWrapMode BackImageWrapMode
  658. {
  659. get
  660. {
  661. return _backImageWrapMode;
  662. }
  663. set
  664. {
  665. _backImageWrapMode = value;
  666. Invalidate();
  667. CallOnModifing();
  668. }
  669. }
  670. /// <summary>
  671. /// Gets or sets the color of a ChartArea object's background image that will be drawn as transparent.
  672. /// </summary>
  673. [
  674. SRCategory("CategoryAttributeAppearance"),
  675. Bindable(true),
  676. DefaultValue(typeof(Color), ""),
  677. NotifyParentPropertyAttribute(true),
  678. SRDescription("DescriptionAttributeImageTransparentColor"),
  679. TypeConverter(typeof(ColorConverter)),
  680. #if DESIGNER
  681. Editor(typeof(ChartColorEditor), typeof(UITypeEditor))
  682. #endif
  683. ]
  684. public Color BackImageTransparentColor
  685. {
  686. get
  687. {
  688. return _backImageTransparentColor;
  689. }
  690. set
  691. {
  692. _backImageTransparentColor = value;
  693. Invalidate();
  694. CallOnModifing();
  695. }
  696. }
  697. /// <summary>
  698. /// Gets or sets the alignment of a ChartArea object.
  699. /// </summary>
  700. [
  701. SRCategory("CategoryAttributeAppearance"),
  702. Bindable(true),
  703. DefaultValue(ChartImageAlignmentStyle.TopLeft),
  704. NotifyParentPropertyAttribute(true),
  705. SRDescription("DescriptionAttributeBackImageAlign"),
  706. ]
  707. public ChartImageAlignmentStyle BackImageAlignment
  708. {
  709. get
  710. {
  711. return _backImageAlignment;
  712. }
  713. set
  714. {
  715. _backImageAlignment = value;
  716. Invalidate();
  717. CallOnModifing();
  718. }
  719. }
  720. /// <summary>
  721. /// Gets or sets the orientation of a chart element's gradient,
  722. /// and also determines whether or not a gradient is used.
  723. /// </summary>
  724. [
  725. SRCategory("CategoryAttributeAppearance"),
  726. Bindable(true),
  727. DefaultValue(GradientStyle.None),
  728. NotifyParentPropertyAttribute(true),
  729. SRDescription("DescriptionAttributeBackGradientStyle"),
  730. #if DESIGNER
  731. Editor(typeof(GradientEditor), typeof(UITypeEditor))
  732. #endif
  733. ]
  734. public GradientStyle BackGradientStyle
  735. {
  736. get
  737. {
  738. return _backGradientStyle;
  739. }
  740. set
  741. {
  742. _backGradientStyle = value;
  743. Invalidate();
  744. CallOnModifing();
  745. }
  746. }
  747. /// <summary>
  748. /// Gets or sets the secondary color of a ChartArea object.
  749. /// </summary>
  750. [
  751. SRCategory("CategoryAttributeAppearance"),
  752. Bindable(true),
  753. DefaultValue(typeof(Color), ""),
  754. NotifyParentPropertyAttribute(true),
  755. SRDescription("DescriptionAttributeBackSecondaryColor"),
  756. TypeConverter(typeof(ColorConverter)),
  757. #if DESIGNER
  758. Editor(typeof(ChartColorEditor), typeof(UITypeEditor))
  759. #endif
  760. ]
  761. public Color BackSecondaryColor
  762. {
  763. get
  764. {
  765. return _backSecondaryColor;
  766. }
  767. set
  768. {
  769. _backSecondaryColor = value;
  770. Invalidate();
  771. CallOnModifing();
  772. }
  773. }
  774. /// <summary>
  775. /// Gets or sets the shadow color of a ChartArea object.
  776. /// </summary>
  777. [
  778. SRCategory("CategoryAttributeAppearance"),
  779. Bindable(true),
  780. DefaultValue(typeof(Color), "128,0,0,0"),
  781. SRDescription("DescriptionAttributeShadowColor"),
  782. NotifyParentPropertyAttribute(true),
  783. TypeConverter(typeof(ColorConverter)),
  784. #if DESIGNER
  785. Editor(typeof(ChartColorEditor), typeof(UITypeEditor))
  786. #endif
  787. ]
  788. public Color ShadowColor
  789. {
  790. get
  791. {
  792. return _shadowColor;
  793. }
  794. set
  795. {
  796. _shadowColor = value;
  797. Invalidate();
  798. CallOnModifing();
  799. }
  800. }
  801. /// <summary>
  802. /// Gets or sets the shadow offset (in pixels) of a ChartArea object.
  803. /// </summary>
  804. [
  805. SRCategory("CategoryAttributeAppearance"),
  806. Bindable(true),
  807. DefaultValue(0),
  808. SRDescription("DescriptionAttributeShadowOffset"),
  809. NotifyParentPropertyAttribute(true),
  810. ]
  811. public int ShadowOffset
  812. {
  813. get
  814. {
  815. return _shadowOffset;
  816. }
  817. set
  818. {
  819. _shadowOffset = value;
  820. Invalidate();
  821. CallOnModifing();
  822. }
  823. }
  824. /// <summary>
  825. /// Gets or sets the border color of a ChartArea object.
  826. /// </summary>
  827. [
  828. SRCategory("CategoryAttributeAppearance"),
  829. Bindable(true),
  830. DefaultValue(typeof(Color), "Black"),
  831. SRDescription("DescriptionAttributeBorderColor"),
  832. NotifyParentPropertyAttribute(true),
  833. TypeConverter(typeof(ColorConverter)),
  834. #if DESIGNER
  835. Editor(typeof(ChartColorEditor), typeof(UITypeEditor))
  836. #endif
  837. ]
  838. public Color BorderColor
  839. {
  840. get
  841. {
  842. return _borderColor;
  843. }
  844. set
  845. {
  846. _borderColor = value;
  847. Invalidate();
  848. CallOnModifing();
  849. }
  850. }
  851. /// <summary>
  852. /// Gets or sets the border width of a ChartArea object.
  853. /// </summary>
  854. [
  855. SRCategory("CategoryAttributeAppearance"),
  856. Bindable(true),
  857. DefaultValue(1),
  858. SRDescription("DescriptionAttributeBorderWidth"),
  859. NotifyParentPropertyAttribute(true)
  860. ]
  861. public int BorderWidth
  862. {
  863. get
  864. {
  865. return _borderWidth;
  866. }
  867. set
  868. {
  869. if (value < 0)
  870. {
  871. throw (new ArgumentOutOfRangeException("value", SR.ExceptionBorderWidthIsNegative));
  872. }
  873. _borderWidth = value;
  874. Invalidate();
  875. CallOnModifing();
  876. }
  877. }
  878. /// <summary>
  879. /// Gets or sets the style of the border line of a ChartArea object.
  880. /// </summary>
  881. [
  882. SRCategory("CategoryAttributeAppearance"),
  883. Bindable(true),
  884. DefaultValue(ChartDashStyle.NotSet),
  885. SRDescription("DescriptionAttributeBorderDashStyle"),
  886. NotifyParentPropertyAttribute(true),
  887. ]
  888. public ChartDashStyle BorderDashStyle
  889. {
  890. get
  891. {
  892. return _borderDashStyle;
  893. }
  894. set
  895. {
  896. _borderDashStyle = value;
  897. Invalidate();
  898. CallOnModifing();
  899. }
  900. }
  901. /// <summary>
  902. /// Gets or sets the unique name of a ChartArea object.
  903. /// </summary>
  904. [
  905. SRCategory("CategoryAttributeMisc"),
  906. Bindable(true),
  907. SRDescription("DescriptionAttributeChartArea_Name"),
  908. NotifyParentPropertyAttribute(true),
  909. ]
  910. public override string Name
  911. {
  912. get
  913. {
  914. return base.Name;
  915. }
  916. set
  917. {
  918. base.Name = value;
  919. CallOnModifing();
  920. }
  921. }
  922. /// <summary>
  923. /// Gets or sets a Boolean that determines if the labels of the axes for all chart area
  924. /// , which have LabelsAutoFit property set to true, are of equal size.
  925. /// </summary>
  926. [
  927. SRCategory("CategoryAttributeAppearance"),
  928. Bindable(true),
  929. DefaultValue(false),
  930. SRDescription("DescriptionAttributeChartArea_EquallySizedAxesFont"),
  931. NotifyParentPropertyAttribute(true),
  932. ]
  933. public bool IsSameFontSizeForAllAxes
  934. {
  935. get
  936. {
  937. return _isSameFontSizeForAllAxes;
  938. }
  939. set
  940. {
  941. _isSameFontSizeForAllAxes = value;
  942. Invalidate();
  943. CallOnModifing();
  944. }
  945. }
  946. #endregion
  947. #region Constructors
  948. /// <summary>
  949. /// ChartArea constructor.
  950. /// </summary>
  951. public ChartArea()
  952. {
  953. Initialize();
  954. }
  955. /// <summary>
  956. /// ChartArea constructor.
  957. /// </summary>
  958. /// <param name="name">The name.</param>
  959. public ChartArea(string name) : base(name)
  960. {
  961. Initialize();
  962. }
  963. #endregion
  964. #region Chart Area Methods
  965. /// <summary>
  966. /// Restores series order and X axis reversed mode for the 3D charts.
  967. /// </summary>
  968. internal void Restore3DAnglesAndReverseMode()
  969. {
  970. if (this.Area3DStyle.Enable3D && !this.chartAreaIsCurcular)
  971. {
  972. // Restore axis "IsReversed" property and old Y angle
  973. this.AxisX.IsReversed = oldReverseX;
  974. this.AxisX2.IsReversed = oldReverseX;
  975. this.AxisY.IsReversed = oldReverseY;
  976. this.AxisY2.IsReversed = oldReverseY;
  977. this.Area3DStyle.Rotation = oldYAngle;
  978. }
  979. }
  980. /// <summary>
  981. /// Sets series order and X axis reversed mode for the 3D charts.
  982. /// </summary>
  983. internal void Set3DAnglesAndReverseMode()
  984. {
  985. // Clear series reversed flag
  986. _reverseSeriesOrder = false;
  987. // If 3D charting is enabled
  988. if (this.Area3DStyle.Enable3D)
  989. {
  990. // Make sure primary & secondary axis has the same IsReversed settings
  991. // This is a limitation for the 3D chart required for labels drawing.
  992. this.AxisX2.IsReversed = this.AxisX.IsReversed;
  993. this.AxisY2.IsReversed = this.AxisY.IsReversed;
  994. // Remember reversed order of X & Y axis and Angles
  995. oldReverseX = this.AxisX.IsReversed;
  996. oldReverseY = this.AxisY.IsReversed;
  997. oldYAngle = this.Area3DStyle.Rotation;
  998. // Check if Y angle
  999. if (this.Area3DStyle.Rotation > 90 || this.Area3DStyle.Rotation < -90)
  1000. {
  1001. // This method depends on the 'switchValueAxes' field which is calculated based on the chart types
  1002. // of the series associated with the chart area. We need to call SetData method to make sure this field
  1003. // is correctly initialized. Because we only need to collect information about the series, we pass 'false'
  1004. // as parameters to limit the amount of work this function does.
  1005. this.SetData(false, false);
  1006. // Reversed series order
  1007. _reverseSeriesOrder = true;
  1008. // Reversed primary and secondary X axis
  1009. if (!this.switchValueAxes)
  1010. {
  1011. this.AxisX.IsReversed = !this.AxisX.IsReversed;
  1012. this.AxisX2.IsReversed = !this.AxisX2.IsReversed;
  1013. }
  1014. // Reversed primary and secondary Y axis for chart types like Bar
  1015. else
  1016. {
  1017. this.AxisY.IsReversed = !this.AxisY.IsReversed;
  1018. this.AxisY2.IsReversed = !this.AxisY2.IsReversed;
  1019. }
  1020. // Adjust Y angle
  1021. if (this.Area3DStyle.Rotation > 90)
  1022. {
  1023. this.Area3DStyle.Rotation = (this.Area3DStyle.Rotation - 90) - 90;
  1024. }
  1025. else if (this.Area3DStyle.Rotation < -90)
  1026. {
  1027. this.Area3DStyle.Rotation = (this.Area3DStyle.Rotation + 90) + 90;
  1028. }
  1029. }
  1030. }
  1031. }
  1032. /// <summary>
  1033. /// Save all automatic values like Minimum and Maximum.
  1034. /// </summary>
  1035. internal void SetTempValues()
  1036. {
  1037. // Save non automatic area position
  1038. if (!this.Position.Auto)
  1039. {
  1040. this.originalAreaPosition = this.Position.ToRectangleF();
  1041. }
  1042. // Save non automatic area inner plot position
  1043. if (!this.InnerPlotPosition.Auto)
  1044. {
  1045. this.originalInnerPlotPosition = this.InnerPlotPosition.ToRectangleF();
  1046. }
  1047. this._circularSectorNumber = int.MinValue;
  1048. this._circularUsePolygons = int.MinValue;
  1049. this._circularAxisList = null;
  1050. // Save Minimum and maximum values for all axes
  1051. axisX.StoreAxisValues();
  1052. axisX2.StoreAxisValues();
  1053. axisY.StoreAxisValues();
  1054. axisY2.StoreAxisValues();
  1055. }
  1056. /// <summary>
  1057. /// Load all automatic values like Minimum and Maximum with original values.
  1058. /// </summary>
  1059. internal void GetTempValues()
  1060. {
  1061. // Take Minimum and maximum values for all axes
  1062. axisX.ResetAxisValues();
  1063. axisX2.ResetAxisValues();
  1064. axisY.ResetAxisValues();
  1065. axisY2.ResetAxisValues();
  1066. // Restore non automatic area position
  1067. if (!this.originalAreaPosition.IsEmpty)
  1068. {
  1069. this.lastAreaPosition = this.Position.ToRectangleF();
  1070. this.Position.SetPositionNoAuto(this.originalAreaPosition.X, this.originalAreaPosition.Y, this.originalAreaPosition.Width, this.originalAreaPosition.Height);
  1071. this.originalAreaPosition = RectangleF.Empty;
  1072. }
  1073. // Save non automatic area inner plot position
  1074. if (!this.originalInnerPlotPosition.IsEmpty)
  1075. {
  1076. this.InnerPlotPosition.SetPositionNoAuto(this.originalInnerPlotPosition.X, this.originalInnerPlotPosition.Y, this.originalInnerPlotPosition.Width, this.originalInnerPlotPosition.Height);
  1077. this.originalInnerPlotPosition = RectangleF.Empty;
  1078. }
  1079. }
  1080. /// <summary>
  1081. /// Initialize Chart area and axes
  1082. /// </summary>
  1083. internal void Initialize()
  1084. {
  1085. // Initialize 3D style class
  1086. _area3DStyle = new ChartArea3DStyle(this);
  1087. // Create axes for this chart area.
  1088. axisY = new Axis();
  1089. axisX = new Axis();
  1090. axisX2 = new Axis();
  1091. axisY2 = new Axis();
  1092. // Initialize axes;
  1093. axisX.Initialize(this, AxisName.X);
  1094. axisY.Initialize(this, AxisName.Y);
  1095. axisX2.Initialize(this, AxisName.X2);
  1096. axisY2.Initialize(this, AxisName.Y2);
  1097. // Initialize axes array
  1098. _axisArray[0] = axisX;
  1099. _axisArray[1] = axisY;
  1100. _axisArray[2] = axisX2;
  1101. _axisArray[3] = axisY2;
  1102. // Set flag to reset auto values for all areas
  1103. _areaPosition = new ElementPosition(this);
  1104. _areaPosition.resetAreaAutoPosition = true;
  1105. _innerPlotPosition = new ElementPosition(this);
  1106. // Set the position of the new chart area
  1107. if (PlotAreaPosition == null)
  1108. {
  1109. PlotAreaPosition = new ElementPosition(this);
  1110. }
  1111. // Initialize cursor class
  1112. this._cursorX.Initialize(this, AxisName.X);
  1113. this._cursorY.Initialize(this, AxisName.Y);
  1114. }
  1115. /// <summary>
  1116. /// Minimum and maximum do not have to be calculated
  1117. /// from data series every time. It is very time
  1118. /// consuming. Minimum and maximum are buffered
  1119. /// and only when this flags are set Minimum and
  1120. /// Maximum are refreshed from data.
  1121. /// </summary>
  1122. internal void ResetMinMaxFromData()
  1123. {
  1124. _axisArray[0].refreshMinMaxFromData = true;
  1125. _axisArray[1].refreshMinMaxFromData = true;
  1126. _axisArray[2].refreshMinMaxFromData = true;
  1127. _axisArray[3].refreshMinMaxFromData = true;
  1128. }
  1129. /// <summary>
  1130. /// Recalculates the axes scale of a chart area.
  1131. /// </summary>
  1132. public void RecalculateAxesScale()
  1133. {
  1134. // Read axis Max/Min from data
  1135. ResetMinMaxFromData();
  1136. Set3DAnglesAndReverseMode();
  1137. SetTempValues();
  1138. // Initialize area position
  1139. _axisArray[0].ReCalc(PlotAreaPosition);
  1140. _axisArray[1].ReCalc(PlotAreaPosition);
  1141. _axisArray[2].ReCalc(PlotAreaPosition);
  1142. _axisArray[3].ReCalc(PlotAreaPosition);
  1143. // Find all Data and chart types which belong
  1144. // to this chart area an set default values
  1145. SetData();
  1146. Restore3DAnglesAndReverseMode();
  1147. GetTempValues();
  1148. }
  1149. /// <summary>
  1150. /// RecalculateAxesScale the chart area
  1151. /// </summary>
  1152. internal void ReCalcInternal()
  1153. {
  1154. // Initialize area position
  1155. _axisArray[0].ReCalc(PlotAreaPosition);
  1156. _axisArray[1].ReCalc(PlotAreaPosition);
  1157. _axisArray[2].ReCalc(PlotAreaPosition);
  1158. _axisArray[3].ReCalc(PlotAreaPosition);
  1159. // Find all Data and chart types which belong
  1160. // to this chart area an set default values
  1161. SetData();
  1162. }
  1163. /// <summary>
  1164. /// Reset auto calculated chart area values.
  1165. /// </summary>
  1166. internal void ResetAutoValues()
  1167. {
  1168. _axisArray[0].ResetAutoValues();
  1169. _axisArray[1].ResetAutoValues();
  1170. _axisArray[2].ResetAutoValues();
  1171. _axisArray[3].ResetAutoValues();
  1172. }
  1173. /// <summary>
  1174. /// Calculates Position for the background.
  1175. /// </summary>
  1176. /// <param name="withScrollBars">Calculate with scroll bars</param>
  1177. /// <returns>Background rectangle</returns>
  1178. internal RectangleF GetBackgroundPosition(bool withScrollBars)
  1179. {
  1180. // For pie and doughnut, which do not have axes, the position
  1181. // for the background is Chart area position not plotting
  1182. // area position.
  1183. RectangleF backgroundPosition = PlotAreaPosition.ToRectangleF();
  1184. if (!requireAxes)
  1185. {
  1186. backgroundPosition = Position.ToRectangleF();
  1187. }
  1188. // Without scroll bars
  1189. if (!withScrollBars)
  1190. {
  1191. return backgroundPosition;
  1192. }
  1193. // Add scroll bar rectangles to the area background
  1194. RectangleF backgroundPositionWithScrollBars = new RectangleF(backgroundPosition.Location, backgroundPosition.Size);
  1195. if (requireAxes)
  1196. {
  1197. // Loop through all axis
  1198. foreach (Axis axis in this.Axes)
  1199. {
  1200. // Find axis with visible scroll bars
  1201. if (axis.ScrollBar.IsVisible && axis.ScrollBar.IsPositionedInside)
  1202. {
  1203. // Change size of the background rectangle depending on the axis position
  1204. if (axis.AxisPosition == AxisPosition.Bottom)
  1205. {
  1206. backgroundPositionWithScrollBars.Height += (float)axis.ScrollBar.GetScrollBarRelativeSize();
  1207. }
  1208. else if (axis.AxisPosition == AxisPosition.Top)
  1209. {
  1210. backgroundPositionWithScrollBars.Y -= (float)axis.ScrollBar.GetScrollBarRelativeSize();
  1211. backgroundPositionWithScrollBars.Height += (float)axis.ScrollBar.GetScrollBarRelativeSize();
  1212. }
  1213. else if (axis.AxisPosition == AxisPosition.Left)
  1214. {
  1215. backgroundPositionWithScrollBars.X -= (float)axis.ScrollBar.GetScrollBarRelativeSize();
  1216. backgroundPositionWithScrollBars.Width += (float)axis.ScrollBar.GetScrollBarRelativeSize();
  1217. }
  1218. else if (axis.AxisPosition == AxisPosition.Left)
  1219. {
  1220. backgroundPositionWithScrollBars.Width += (float)axis.ScrollBar.GetScrollBarRelativeSize();
  1221. }
  1222. }
  1223. }
  1224. }
  1225. return backgroundPositionWithScrollBars;
  1226. }
  1227. /// <summary>
  1228. /// Call when the chart area is resized.
  1229. /// </summary>
  1230. /// <param name="chartGraph">Chart graphics object.</param>
  1231. internal void Resize(ChartGraphics chartGraph)
  1232. {
  1233. // Initialize plotting area position
  1234. RectangleF plottingRect = Position.ToRectangleF();
  1235. if (!InnerPlotPosition.Auto)
  1236. {
  1237. plottingRect.X += (Position.Width / 100F) * InnerPlotPosition.X;
  1238. plottingRect.Y += (Position.Height / 100F) * InnerPlotPosition.Y;
  1239. plottingRect.Width = (Position.Width / 100F) * InnerPlotPosition.Width;
  1240. plottingRect.Height = (Position.Height / 100F) * InnerPlotPosition.Height;
  1241. }
  1242. //******************************************************
  1243. //** Calculate number of vertical and horizontal axis
  1244. //******************************************************
  1245. int verticalAxes = 0;
  1246. int horizontalAxes = 0;
  1247. foreach (Axis axis in this.Axes)
  1248. {
  1249. if (axis.enabled)
  1250. {
  1251. if (axis.AxisPosition == AxisPosition.Bottom)
  1252. {
  1253. ++horizontalAxes;
  1254. }
  1255. else if (axis.AxisPosition == AxisPosition.Top)
  1256. {
  1257. ++horizontalAxes;
  1258. }
  1259. else if (axis.AxisPosition == AxisPosition.Left)
  1260. {
  1261. ++verticalAxes;
  1262. }
  1263. else if (axis.AxisPosition == AxisPosition.Right)
  1264. {
  1265. ++verticalAxes;
  1266. }
  1267. }
  1268. }
  1269. if (horizontalAxes <= 0)
  1270. {
  1271. horizontalAxes = 1;
  1272. }
  1273. if (verticalAxes <= 0)
  1274. {
  1275. verticalAxes = 1;
  1276. }
  1277. //******************************************************
  1278. //** Find same auto-fit font size
  1279. //******************************************************
  1280. Axis[] axisArray = (this.switchValueAxes) ?
  1281. new Axis[] { this.AxisX, this.AxisX2, this.AxisY, this.AxisY2 } :
  1282. new Axis[] { this.AxisY, this.AxisY2, this.AxisX, this.AxisX2 };
  1283. if (this.IsSameFontSizeForAllAxes)
  1284. {
  1285. axesAutoFontSize = 20;
  1286. foreach (Axis axis in axisArray)
  1287. {
  1288. // Process only enabled axis
  1289. if (axis.enabled)
  1290. {
  1291. // Resize axis
  1292. if (axis.AxisPosition == AxisPosition.Bottom || axis.AxisPosition == AxisPosition.Top)
  1293. {
  1294. axis.Resize(chartGraph, this.PlotAreaPosition, plottingRect, horizontalAxes, InnerPlotPosition.Auto);
  1295. }
  1296. else
  1297. {
  1298. axis.Resize(chartGraph, this.PlotAreaPosition, plottingRect, verticalAxes, InnerPlotPosition.Auto);
  1299. }
  1300. // Calculate smallest font size
  1301. if (axis.IsLabelAutoFit && axis.autoLabelFont != null)
  1302. {
  1303. axesAutoFontSize = Math.Min(axesAutoFontSize, axis.autoLabelFont.Size);
  1304. }
  1305. }
  1306. }
  1307. }
  1308. //******************************************************
  1309. //** Adjust plotting area position according to the axes
  1310. //** elements (title, labels, tick marks) size.
  1311. //******************************************************
  1312. RectangleF rectLabelSideSpacing = RectangleF.Empty;
  1313. foreach (Axis axis in axisArray)
  1314. {
  1315. // Process only enabled axis
  1316. if (!axis.enabled)
  1317. {
  1318. //******************************************************
  1319. //** Adjust for the 3D Wall Width for disabled axis
  1320. //******************************************************
  1321. if (InnerPlotPosition.Auto && this.Area3DStyle.Enable3D && !this.chartAreaIsCurcular)
  1322. {
  1323. SizeF areaWallSize = chartGraph.GetRelativeSize(new SizeF(this.Area3DStyle.WallWidth, this.Area3DStyle.WallWidth));
  1324. if (axis.AxisPosition == AxisPosition.Bottom)
  1325. {
  1326. plottingRect.Height -= areaWallSize.Height;
  1327. }
  1328. else if (axis.AxisPosition == AxisPosition.Top)
  1329. {
  1330. plottingRect.Y += areaWallSize.Height;
  1331. plottingRect.Height -= areaWallSize.Height;
  1332. }
  1333. else if (axis.AxisPosition == AxisPosition.Right)
  1334. {
  1335. plottingRect.Width -= areaWallSize.Width;
  1336. }
  1337. else if (axis.AxisPosition == AxisPosition.Left)
  1338. {
  1339. plottingRect.X += areaWallSize.Width;
  1340. plottingRect.Width -= areaWallSize.Width;
  1341. }
  1342. }
  1343. continue;
  1344. }
  1345. //******************************************************
  1346. //** Calculate axes elements position
  1347. //******************************************************
  1348. if (axis.AxisPosition == AxisPosition.Bottom || axis.AxisPosition == AxisPosition.Top)
  1349. {
  1350. axis.Resize(chartGraph, this.PlotAreaPosition, plottingRect, horizontalAxes, InnerPlotPosition.Auto);
  1351. }
  1352. else
  1353. {
  1354. axis.Resize(chartGraph, this.PlotAreaPosition, plottingRect, verticalAxes, InnerPlotPosition.Auto);
  1355. }
  1356. // Shift top/bottom labels so they will not overlap with left/right labels
  1357. PreventTopBottomAxesLabelsOverlapping(axis);
  1358. //******************************************************
  1359. //** Check axis position
  1360. //******************************************************
  1361. float axisPosition = (float)axis.GetAxisPosition();
  1362. if (axis.AxisPosition == AxisPosition.Bottom)
  1363. {
  1364. if (!axis.GetIsMarksNextToAxis())
  1365. {
  1366. axisPosition = plottingRect.Bottom;
  1367. }
  1368. axisPosition = plottingRect.Bottom - axisPosition;
  1369. }
  1370. else if (axis.AxisPosition == AxisPosition.Top)
  1371. {
  1372. if (!axis.GetIsMarksNextToAxis())
  1373. {
  1374. axisPosition = plottingRect.Y;
  1375. }
  1376. axisPosition = axisPosition - plottingRect.Top;
  1377. }
  1378. else if (axis.AxisPosition == AxisPosition.Right)
  1379. {
  1380. if (!axis.GetIsMarksNextToAxis())
  1381. {
  1382. axisPosition = plottingRect.Right;
  1383. }
  1384. axisPosition = plottingRect.Right - axisPosition;
  1385. }
  1386. else if (axis.AxisPosition == AxisPosition.Left)
  1387. {
  1388. if (!axis.GetIsMarksNextToAxis())
  1389. {
  1390. axisPosition = plottingRect.X;
  1391. }
  1392. axisPosition = axisPosition - plottingRect.Left;
  1393. }
  1394. //******************************************************
  1395. //** Adjust axis elements size with axis position
  1396. //******************************************************
  1397. // Calculate total size of axis elements
  1398. float axisSize = axis.markSize + axis.labelSize;
  1399. #if SUBAXES
  1400. // Add sub-axis size
  1401. if(!this.chartAreaIsCurcular && !this.Area3DStyle.Enable3D)
  1402. {
  1403. foreach(SubAxis subAxis in axis.SubAxes)
  1404. {
  1405. axisSize += subAxis.markSize + subAxis.labelSize + subAxis.titleSize;
  1406. }
  1407. }
  1408. #endif // SUBAXES
  1409. // Adjust depending on the axis position
  1410. axisSize -= axisPosition;
  1411. if (axisSize < 0)
  1412. {
  1413. axisSize = 0;
  1414. }
  1415. // Add axis title and scroll bar size (always outside of plotting area)
  1416. axisSize += axis.titleSize + axis.scrollBarSize;
  1417. // Calculate horizontal axes size for circualar area
  1418. if (this.chartAreaIsCurcular &&
  1419. (axis.AxisPosition == AxisPosition.Top || axis.AxisPosition == AxisPosition.Bottom))
  1420. {
  1421. axisSize = axis.titleSize + axis.markSize + axis.scrollBarSize;
  1422. }
  1423. //******************************************************
  1424. //** Adjust plotting area
  1425. //******************************************************
  1426. if (InnerPlotPosition.Auto)
  1427. {
  1428. if (axis.AxisPosition == AxisPosition.Bottom)
  1429. {
  1430. plottingRect.Height -= axisSize;
  1431. }
  1432. else if (axis.AxisPosition == AxisPosition.Top)
  1433. {
  1434. plottingRect.Y += axisSize;
  1435. plottingRect.Height -= axisSize;
  1436. }
  1437. else if (axis.AxisPosition == AxisPosition.Left)
  1438. {
  1439. plottingRect.X += axisSize;
  1440. plottingRect.Width -= axisSize;
  1441. }
  1442. else if (axis.AxisPosition == AxisPosition.Right)
  1443. {
  1444. plottingRect.Width -= axisSize;
  1445. }
  1446. // Check if labels side offset should be processed
  1447. bool addLabelsSideOffsets = true;
  1448. // Update the plotting area depending on the size required for labels on the sides
  1449. if (addLabelsSideOffsets)
  1450. {
  1451. if (axis.AxisPosition == AxisPosition.Bottom || axis.AxisPosition == AxisPosition.Top)
  1452. {
  1453. if (axis.labelNearOffset != 0 && axis.labelNearOffset < Position.X)
  1454. {
  1455. float offset = Position.X - axis.labelNearOffset;
  1456. if (Math.Abs(offset) > plottingRect.Width * 0.3f)
  1457. {
  1458. offset = plottingRect.Width * 0.3f;
  1459. }
  1460. // NOTE: Code was removed to solve an issue with extra space when labels angle = 45
  1461. //rectLabelSideSpacing.Width = (float)Math.Max(offset, rectLabelSideSpacing.Width);
  1462. rectLabelSideSpacing.X = (float)Math.Max(offset, rectLabelSideSpacing.X);
  1463. }
  1464. if (axis.labelFarOffset > Position.Right)
  1465. {
  1466. if ((axis.labelFarOffset - Position.Right) < plottingRect.Width * 0.3f)
  1467. {
  1468. rectLabelSideSpacing.Width = (float)Math.Max(axis.labelFarOffset - Position.Right, rectLabelSideSpacing.Width);
  1469. }
  1470. else
  1471. {
  1472. rectLabelSideSpacing.Width = (float)Math.Max(plottingRect.Width * 0.3f, rectLabelSideSpacing.Width);
  1473. }
  1474. }
  1475. }
  1476. else
  1477. {
  1478. if (axis.labelNearOffset != 0 && axis.labelNearOffset < Position.Y)
  1479. {
  1480. float offset = Position.Y - axis.labelNearOffset;
  1481. if (Math.Abs(offset) > plottingRect.Height * 0.3f)
  1482. {
  1483. offset = plottingRect.Height * 0.3f;
  1484. }
  1485. // NOTE: Code was removed to solve an issue with extra space when labels angle = 45
  1486. //rectLabelSideSpacing.Height = (float)Math.Max(offset, rectLabelSideSpacing.Height);
  1487. rectLabelSideSpacing.Y = (float)Math.Max(offset, rectLabelSideSpacing.Y);
  1488. }
  1489. if (axis.labelFarOffset > Position.Bottom)
  1490. {
  1491. if ((axis.labelFarOffset - Position.Bottom) < plottingRect.Height * 0.3f)
  1492. {
  1493. rectLabelSideSpacing.Height = (float)Math.Max(axis.labelFarOffset - Position.Bottom, rectLabelSideSpacing.Height);
  1494. }
  1495. else
  1496. {
  1497. rectLabelSideSpacing.Height = (float)Math.Max(plottingRect.Height * 0.3f, rectLabelSideSpacing.Height);
  1498. }
  1499. }
  1500. }
  1501. }
  1502. }
  1503. }
  1504. //******************************************************
  1505. //** Make sure there is enough space
  1506. //** for labels on the chart sides
  1507. //******************************************************
  1508. if (!this.chartAreaIsCurcular)
  1509. {
  1510. if (rectLabelSideSpacing.Y > 0 && rectLabelSideSpacing.Y > plottingRect.Y - Position.Y)
  1511. {
  1512. float delta = (plottingRect.Y - Position.Y) - rectLabelSideSpacing.Y;
  1513. plottingRect.Y -= delta;
  1514. plottingRect.Height += delta;
  1515. }
  1516. if (rectLabelSideSpacing.X > 0 && rectLabelSideSpacing.X > plottingRect.X - Position.X)
  1517. {
  1518. float delta = (plottingRect.X - Position.X) - rectLabelSideSpacing.X;
  1519. plottingRect.X -= delta;
  1520. plottingRect.Width += delta;
  1521. }
  1522. if (rectLabelSideSpacing.Height > 0 && rectLabelSideSpacing.Height > Position.Bottom - plottingRect.Bottom)
  1523. {
  1524. plottingRect.Height += (Position.Bottom - plottingRect.Bottom) - rectLabelSideSpacing.Height;
  1525. }
  1526. if (rectLabelSideSpacing.Width > 0 && rectLabelSideSpacing.Width > Position.Right - plottingRect.Right)
  1527. {
  1528. plottingRect.Width += (Position.Right - plottingRect.Right) - rectLabelSideSpacing.Width;
  1529. }
  1530. }
  1531. //******************************************************
  1532. //** Plotting area must be square for the circular
  1533. //** chart area (in pixels).
  1534. //******************************************************
  1535. if (this.chartAreaIsCurcular)
  1536. {
  1537. // Adjust area to fit the axis title
  1538. float xTitleSize = (float)Math.Max(this.AxisY.titleSize, this.AxisY2.titleSize);
  1539. if (xTitleSize > 0)
  1540. {
  1541. plottingRect.X += xTitleSize;
  1542. plottingRect.Width -= 2f * xTitleSize;
  1543. }
  1544. float yTitleSize = (float)Math.Max(this.AxisX.titleSize, this.AxisX2.titleSize);
  1545. if (yTitleSize > 0)
  1546. {
  1547. plottingRect.Y += yTitleSize;
  1548. plottingRect.Height -= 2f * yTitleSize;
  1549. }
  1550. // Make a square plotting rect
  1551. RectangleF rect = chartGraph.GetAbsoluteRectangle(plottingRect);
  1552. if (rect.Width > rect.Height)
  1553. {
  1554. rect.X += (rect.Width - rect.Height) / 2f;
  1555. rect.Width = rect.Height;
  1556. }
  1557. else
  1558. {
  1559. rect.Y += (rect.Height - rect.Width) / 2f;
  1560. rect.Height = rect.Width;
  1561. }
  1562. plottingRect = chartGraph.GetRelativeRectangle(rect);
  1563. // Remember circular chart area center
  1564. this.circularCenter = new PointF(plottingRect.X + plottingRect.Width / 2f, plottingRect.Y + plottingRect.Height / 2f);
  1565. // Calculate auto-fit font of the circular axis labels and update area position
  1566. FitCircularLabels(chartGraph, this.PlotAreaPosition, ref plottingRect, xTitleSize, yTitleSize);
  1567. }
  1568. //******************************************************
  1569. //** Set plotting area position
  1570. //******************************************************
  1571. if (plottingRect.Width < 0f)
  1572. {
  1573. plottingRect.Width = 0f;
  1574. }
  1575. if (plottingRect.Height < 0f)
  1576. {
  1577. plottingRect.Height = 0f;
  1578. }
  1579. PlotAreaPosition.FromRectangleF(plottingRect);
  1580. InnerPlotPosition.SetPositionNoAuto(
  1581. (float)Math.Round((plottingRect.X - Position.X) / (Position.Width / 100F), 5),
  1582. (float)Math.Round((plottingRect.Y - Position.Y) / (Position.Height / 100F), 5),
  1583. (float)Math.Round(plottingRect.Width / (Position.Width / 100F), 5),
  1584. (float)Math.Round(plottingRect.Height / (Position.Height / 100F), 5));
  1585. //******************************************************
  1586. //** Adjust label font size for axis, which were
  1587. //** automatically calculated after the opposite axis
  1588. //** change the size of plotting area.
  1589. //******************************************************
  1590. this.AxisY2.AdjustLabelFontAtSecondPass(chartGraph, InnerPlotPosition.Auto);
  1591. this.AxisY.AdjustLabelFontAtSecondPass(chartGraph, InnerPlotPosition.Auto);
  1592. if (InnerPlotPosition.Auto)
  1593. {
  1594. this.AxisX2.AdjustLabelFontAtSecondPass(chartGraph, InnerPlotPosition.Auto);
  1595. this.AxisX.AdjustLabelFontAtSecondPass(chartGraph, InnerPlotPosition.Auto);
  1596. }
  1597. }
  1598. /// <summary>
  1599. /// Finds axis by it's position. Can be Null.
  1600. /// </summary>
  1601. /// <param name="axisPosition">Axis position to find</param>
  1602. /// <returns>Found axis.</returns>
  1603. private Axis FindAxis(AxisPosition axisPosition)
  1604. {
  1605. foreach (Axis axis in this.Axes)
  1606. {
  1607. if (axis.AxisPosition == axisPosition)
  1608. {
  1609. return axis;
  1610. }
  1611. }
  1612. return null;
  1613. }
  1614. /// <summary>
  1615. /// Shift top/bottom labels so they will not overlap with left/right labels.
  1616. /// </summary>
  1617. /// <param name="axis">Axis to shift up/down.</param>
  1618. private void PreventTopBottomAxesLabelsOverlapping(Axis axis)
  1619. {
  1620. // If axis is not on the edge of the chart area do not
  1621. // try to adjust it's position when axis labels overlap
  1622. // labels of the oppositie axis.
  1623. if (!axis.IsAxisOnAreaEdge)
  1624. {
  1625. return;
  1626. }
  1627. // Shift bottom axis labels down
  1628. if (axis.AxisPosition == AxisPosition.Bottom)
  1629. {
  1630. // Get labels position
  1631. float labelsPosition = (float)axis.GetAxisPosition();
  1632. if (!axis.GetIsMarksNextToAxis())
  1633. {
  1634. labelsPosition = axis.PlotAreaPosition.Bottom;
  1635. }
  1636. // Only adjust labels outside plotting area
  1637. if (Math.Round(labelsPosition, 2) < Math.Round(axis.PlotAreaPosition.Bottom, 2))
  1638. {
  1639. return;
  1640. }
  1641. // Check if labels may overlap with Left axis
  1642. Axis leftAxis = FindAxis(AxisPosition.Left);
  1643. if (leftAxis != null &&
  1644. leftAxis.enabled &&
  1645. leftAxis.labelFarOffset != 0 &&
  1646. leftAxis.labelFarOffset > labelsPosition &&
  1647. axis.labelNearOffset != 0 &&
  1648. axis.labelNearOffset < PlotAreaPosition.X)
  1649. {
  1650. float overlap = (float)(leftAxis.labelFarOffset - labelsPosition) * 0.75f;
  1651. if (overlap > axis.markSize)
  1652. {
  1653. axis.markSize += overlap - axis.markSize;
  1654. }
  1655. }
  1656. // Check if labels may overlap with Right axis
  1657. Axis rightAxis = FindAxis(AxisPosition.Right);
  1658. if (rightAxis != null &&
  1659. rightAxis.enabled &&
  1660. rightAxis.labelFarOffset != 0 &&
  1661. rightAxis.labelFarOffset > labelsPosition &&
  1662. axis.labelFarOffset != 0 &&
  1663. axis.labelFarOffset > PlotAreaPosition.Right)
  1664. {
  1665. float overlap = (float)(rightAxis.labelFarOffset - labelsPosition) * 0.75f;
  1666. if (overlap > axis.markSize)
  1667. {
  1668. axis.markSize += overlap - axis.markSize;
  1669. }
  1670. }
  1671. }
  1672. // Shift top axis labels up
  1673. else if (axis.AxisPosition == AxisPosition.Top)
  1674. {
  1675. // Get labels position
  1676. float labelsPosition = (float)axis.GetAxisPosition();
  1677. if (!axis.GetIsMarksNextToAxis())
  1678. {
  1679. labelsPosition = axis.PlotAreaPosition.Y;
  1680. }
  1681. // Only adjust labels outside plotting area
  1682. if (Math.Round(labelsPosition, 2) < Math.Round(axis.PlotAreaPosition.Y, 2))
  1683. {
  1684. return;
  1685. }
  1686. // Check if labels may overlap with Left axis
  1687. Axis leftAxis = FindAxis(AxisPosition.Left);
  1688. if (leftAxis != null &&
  1689. leftAxis.enabled &&
  1690. leftAxis.labelNearOffset != 0 &&
  1691. leftAxis.labelNearOffset < labelsPosition &&
  1692. axis.labelNearOffset != 0 &&
  1693. axis.labelNearOffset < PlotAreaPosition.X)
  1694. {
  1695. float overlap = (float)(labelsPosition - leftAxis.labelNearOffset) * 0.75f;
  1696. if (overlap > axis.markSize)
  1697. {
  1698. axis.markSize += overlap - axis.markSize;
  1699. }
  1700. }
  1701. // Check if labels may overlap with Right axis
  1702. Axis rightAxis = FindAxis(AxisPosition.Right);
  1703. if (rightAxis != null &&
  1704. rightAxis.enabled &&
  1705. rightAxis.labelNearOffset != 0 &&
  1706. rightAxis.labelNearOffset < labelsPosition &&
  1707. axis.labelFarOffset != 0 &&
  1708. axis.labelFarOffset > PlotAreaPosition.Right)
  1709. {
  1710. float overlap = (float)(labelsPosition - rightAxis.labelNearOffset) * 0.75f;
  1711. if (overlap > axis.markSize)
  1712. {
  1713. axis.markSize += overlap - axis.markSize;
  1714. }
  1715. }
  1716. }
  1717. }
  1718. #endregion
  1719. #region Painting and Selection Methods
  1720. /// <summary>
  1721. /// Draws chart area background and/or border.
  1722. /// </summary>
  1723. /// <param name="graph">Chart graphics.</param>
  1724. /// <param name="position">Background position.</param>
  1725. /// <param name="borderOnly">Draws chart area border only.</param>
  1726. private void PaintAreaBack(ChartGraphics graph, RectangleF position, bool borderOnly)
  1727. {
  1728. if (!borderOnly)
  1729. {
  1730. // Draw background
  1731. if (!this.Area3DStyle.Enable3D || !requireAxes || chartAreaIsCurcular)
  1732. {
  1733. // 3D Pie Chart doesn't need scene
  1734. // Draw 2D background
  1735. graph.FillRectangleRel(
  1736. position,
  1737. BackColor,
  1738. BackHatchStyle,
  1739. BackImage,
  1740. BackImageWrapMode,
  1741. BackImageTransparentColor,
  1742. BackImageAlignment,
  1743. BackGradientStyle,
  1744. BackSecondaryColor,
  1745. (requireAxes) ? Color.Empty : BorderColor,
  1746. (requireAxes) ? 0 : BorderWidth,
  1747. BorderDashStyle,
  1748. ShadowColor,
  1749. ShadowOffset,
  1750. PenAlignment.Outset,
  1751. chartAreaIsCurcular,
  1752. (chartAreaIsCurcular && this.CircularUsePolygons) ? this.CircularSectorsNumber : 0,
  1753. this.Area3DStyle.Enable3D);
  1754. }
  1755. else
  1756. {
  1757. // Draw chart area 3D scene
  1758. this.DrawArea3DScene(graph, position);
  1759. }
  1760. }
  1761. else
  1762. {
  1763. if (!this.Area3DStyle.Enable3D || !requireAxes || chartAreaIsCurcular)
  1764. {
  1765. // Draw chart area border
  1766. if (BorderColor != Color.Empty && BorderWidth > 0)
  1767. {
  1768. graph.FillRectangleRel(position,
  1769. Color.Transparent,
  1770. ChartHatchStyle.None,
  1771. "",
  1772. ChartImageWrapMode.Tile,
  1773. Color.Empty,
  1774. ChartImageAlignmentStyle.Center,
  1775. GradientStyle.None,
  1776. Color.Empty,
  1777. BorderColor,
  1778. BorderWidth,
  1779. BorderDashStyle,
  1780. Color.Empty,
  1781. 0,
  1782. PenAlignment.Outset,
  1783. chartAreaIsCurcular,
  1784. (chartAreaIsCurcular && this.CircularUsePolygons) ? this.CircularSectorsNumber : 0,
  1785. this.Area3DStyle.Enable3D);
  1786. }
  1787. }
  1788. }
  1789. }
  1790. /// <summary>
  1791. /// Paint the chart area.
  1792. /// </summary>
  1793. /// <param name="graph">Chart graphics.</param>
  1794. internal void Paint(ChartGraphics graph)
  1795. {
  1796. // Check if plot area position was recalculated.
  1797. // If not and non-auto InnerPlotPosition & Position were
  1798. // specified - do all needed calculations
  1799. if (PlotAreaPosition.Width == 0 &&
  1800. PlotAreaPosition.Height == 0 &&
  1801. !InnerPlotPosition.Auto
  1802. && !Position.Auto)
  1803. {
  1804. // Initialize plotting area position
  1805. RectangleF plottingRect = Position.ToRectangleF();
  1806. if (!InnerPlotPosition.Auto)
  1807. {
  1808. plottingRect.X += (Position.Width / 100F) * InnerPlotPosition.X;
  1809. plottingRect.Y += (Position.Height / 100F) * InnerPlotPosition.Y;
  1810. plottingRect.Width = (Position.Width / 100F) * InnerPlotPosition.Width;
  1811. plottingRect.Height = (Position.Height / 100F) * InnerPlotPosition.Height;
  1812. }
  1813. PlotAreaPosition.FromRectangleF(plottingRect);
  1814. }
  1815. // Get background position rectangle.
  1816. RectangleF backgroundPositionWithScrollBars = GetBackgroundPosition(true);
  1817. RectangleF backgroundPosition = GetBackgroundPosition(false);
  1818. // Add hot region for plotting area.
  1819. if (Common.ProcessModeRegions)
  1820. {
  1821. Common.HotRegionsList.AddHotRegion(backgroundPosition, this, ChartElementType.PlottingArea, true);
  1822. }
  1823. // Draw background
  1824. PaintAreaBack(graph, backgroundPositionWithScrollBars, false);
  1825. // Call BackPaint event
  1826. Common.Chart.CallOnPrePaint(new ChartPaintEventArgs(this, graph, Common, PlotAreaPosition));
  1827. // Draw chart types without axes - Pie.
  1828. if (!requireAxes && ChartTypes.Count != 0)
  1829. {
  1830. // Find first chart type that do not require axis (like Pie) and draw it.
  1831. // Chart types that do not require axes (circular charts) cannot be combined with
  1832. // any other chart types.
  1833. // NOTE: Fixes issues #4672 and #4692
  1834. for (int chartTypeIndex = 0; chartTypeIndex < ChartTypes.Count; chartTypeIndex++)
  1835. {
  1836. IChartType chartType = Common.ChartTypeRegistry.GetChartType((string)ChartTypes[chartTypeIndex]);
  1837. if (!chartType.RequireAxes)
  1838. {
  1839. chartType.Paint(graph, Common, this, null);
  1840. break;
  1841. }
  1842. }
  1843. // Call Paint event
  1844. Common.Chart.CallOnPostPaint(new ChartPaintEventArgs(this, graph, Common, PlotAreaPosition));
  1845. return;
  1846. }
  1847. // Reset Smart Labels
  1848. this.smartLabels.Reset();
  1849. // Set values for optimized drawing
  1850. foreach (Axis currentAxis in this._axisArray)
  1851. {
  1852. currentAxis.optimizedGetPosition = true;
  1853. currentAxis.paintViewMax = currentAxis.ViewMaximum;
  1854. currentAxis.paintViewMin = currentAxis.ViewMinimum;
  1855. currentAxis.paintRange = currentAxis.paintViewMax - currentAxis.paintViewMin;
  1856. currentAxis.paintAreaPosition = PlotAreaPosition.ToRectangleF();
  1857. if (currentAxis.ChartArea != null && currentAxis.ChartArea.chartAreaIsCurcular)
  1858. {
  1859. // Update position for circular chart area
  1860. currentAxis.paintAreaPosition.Width /= 2.0f;
  1861. currentAxis.paintAreaPosition.Height /= 2.0f;
  1862. }
  1863. currentAxis.paintAreaPositionBottom = currentAxis.paintAreaPosition.Y + currentAxis.paintAreaPosition.Height;
  1864. currentAxis.paintAreaPositionRight = currentAxis.paintAreaPosition.X + currentAxis.paintAreaPosition.Width;
  1865. if (currentAxis.AxisPosition == AxisPosition.Top || currentAxis.AxisPosition == AxisPosition.Bottom)
  1866. currentAxis.paintChartAreaSize = currentAxis.paintAreaPosition.Width;
  1867. else
  1868. currentAxis.paintChartAreaSize = currentAxis.paintAreaPosition.Height;
  1869. currentAxis.valueMultiplier = 0.0;
  1870. if (currentAxis.paintRange != 0)
  1871. {
  1872. currentAxis.valueMultiplier = currentAxis.paintChartAreaSize / currentAxis.paintRange;
  1873. }
  1874. }
  1875. // Draw Axis Striplines (only when StripWidth > 0)
  1876. bool useScaleSegments = false;
  1877. Axis[] axesArray = new Axis[] { axisY, axisY2, axisX, axisX2 };
  1878. foreach (Axis currentAxis in axesArray)
  1879. {
  1880. useScaleSegments = (currentAxis.ScaleSegments.Count > 0);
  1881. if (!useScaleSegments)
  1882. {
  1883. currentAxis.PaintStrips(graph, false);
  1884. }
  1885. else
  1886. {
  1887. foreach (AxisScaleSegment scaleSegment in currentAxis.ScaleSegments)
  1888. {
  1889. scaleSegment.SetTempAxisScaleAndInterval();
  1890. currentAxis.PaintStrips(graph, false);
  1891. scaleSegment.RestoreAxisScaleAndInterval();
  1892. }
  1893. }
  1894. }
  1895. // Draw Axis Grids
  1896. axesArray = new Axis[] { axisY, axisX2, axisY2, axisX };
  1897. foreach (Axis currentAxis in axesArray)
  1898. {
  1899. useScaleSegments = (currentAxis.ScaleSegments.Count > 0);
  1900. if (!useScaleSegments)
  1901. {
  1902. currentAxis.PaintGrids(graph);
  1903. }
  1904. else
  1905. {
  1906. foreach (AxisScaleSegment scaleSegment in currentAxis.ScaleSegments)
  1907. {
  1908. scaleSegment.SetTempAxisScaleAndInterval();
  1909. currentAxis.PaintGrids(graph);
  1910. scaleSegment.RestoreAxisScaleAndInterval();
  1911. }
  1912. }
  1913. }
  1914. // Draw Axis Striplines (only when StripWidth == 0)
  1915. foreach (Axis currentAxis in axesArray)
  1916. {
  1917. useScaleSegments = (currentAxis.ScaleSegments.Count > 0);
  1918. if (!useScaleSegments)
  1919. {
  1920. currentAxis.PaintStrips(graph, true);
  1921. }
  1922. else
  1923. {
  1924. foreach (AxisScaleSegment scaleSegment in currentAxis.ScaleSegments)
  1925. {
  1926. scaleSegment.SetTempAxisScaleAndInterval();
  1927. currentAxis.PaintStrips(graph, true);
  1928. scaleSegment.RestoreAxisScaleAndInterval();
  1929. }
  1930. }
  1931. }
  1932. // Draw Axis elements on the back of the 3D scene
  1933. if (this.Area3DStyle.Enable3D && !this.chartAreaIsCurcular)
  1934. {
  1935. foreach (Axis currentAxis in axesArray)
  1936. {
  1937. useScaleSegments = (currentAxis.ScaleSegments.Count > 0);
  1938. if (!useScaleSegments)
  1939. {
  1940. currentAxis.PrePaint(graph);
  1941. }
  1942. else
  1943. {
  1944. foreach (AxisScaleSegment scaleSegment in currentAxis.ScaleSegments)
  1945. {
  1946. scaleSegment.SetTempAxisScaleAndInterval();
  1947. currentAxis.PrePaint(graph);
  1948. scaleSegment.RestoreAxisScaleAndInterval();
  1949. }
  1950. }
  1951. }
  1952. }
  1953. // Draws chart area border
  1954. bool borderDrawn = false;
  1955. if (this.Area3DStyle.Enable3D || !IsBorderOnTopSeries())
  1956. {
  1957. borderDrawn = true;
  1958. PaintAreaBack(graph, backgroundPosition, true);
  1959. }
  1960. // Draw chart types
  1961. if (!this.Area3DStyle.Enable3D || this.chartAreaIsCurcular)
  1962. {
  1963. // Drawing in 2D space
  1964. // NOTE: Fixes issue #6443 and #5385
  1965. // If two chart series of the same type (for example Line) are separated
  1966. // by other series (for example Area) the order is not correct.
  1967. // Old implementation draws ALL series that belongs to the chart type.
  1968. ArrayList typeAndSeries = this.GetChartTypesAndSeriesToDraw();
  1969. // Draw series by chart type or by series
  1970. foreach (ChartTypeAndSeriesInfo chartTypeInfo in typeAndSeries)
  1971. {
  1972. this.IterationCounter = 0;
  1973. IChartType type = Common.ChartTypeRegistry.GetChartType(chartTypeInfo.ChartType);
  1974. // If 'chartTypeInfo.Series' set to NULL all series of that chart type are drawn at once
  1975. type.Paint(graph, Common, this, chartTypeInfo.Series);
  1976. }
  1977. }
  1978. else
  1979. {
  1980. // Drawing in 3D space
  1981. PaintChartSeries3D(graph);
  1982. }
  1983. // Draw area border if it wasn't drawn prior to the series
  1984. if (!borderDrawn)
  1985. {
  1986. PaintAreaBack(graph, backgroundPosition, true);
  1987. }
  1988. // Draw Axis
  1989. foreach (Axis currentAxis in axesArray)
  1990. {
  1991. useScaleSegments = (currentAxis.ScaleSegments.Count > 0);
  1992. if (!useScaleSegments)
  1993. {
  1994. // Paint axis and Reset temp axis offset for side-by-side charts like column
  1995. currentAxis.Paint(graph);
  1996. }
  1997. else
  1998. {
  1999. // Some of the axis elements like grid lines and tickmarks
  2000. // are drawn for each segment
  2001. foreach (AxisScaleSegment scaleSegment in currentAxis.ScaleSegments)
  2002. {
  2003. scaleSegment.SetTempAxisScaleAndInterval();
  2004. currentAxis.PaintOnSegmentedScalePassOne(graph);
  2005. scaleSegment.RestoreAxisScaleAndInterval();
  2006. }
  2007. // Other elements like labels, title, axis line are drawn once
  2008. currentAxis.PaintOnSegmentedScalePassTwo(graph);
  2009. }
  2010. }
  2011. // Call Paint event
  2012. Common.Chart.CallOnPostPaint(new ChartPaintEventArgs(this, graph, Common, PlotAreaPosition));
  2013. // Draw axis scale break lines
  2014. axesArray = new Axis[] { axisY, axisY2 };
  2015. foreach (Axis currentAxis in axesArray)
  2016. {
  2017. for (int segmentIndex = 0; segmentIndex < (currentAxis.ScaleSegments.Count - 1); segmentIndex++)
  2018. {
  2019. currentAxis.ScaleSegments[segmentIndex].PaintBreakLine(graph, currentAxis.ScaleSegments[segmentIndex + 1]);
  2020. }
  2021. }
  2022. // Reset values for optimized drawing
  2023. foreach (Axis curentAxis in this._axisArray)
  2024. {
  2025. curentAxis.optimizedGetPosition = false;
  2026. // Reset preffered number of intervals on the axis
  2027. curentAxis.prefferedNumberofIntervals = 5;
  2028. // Reset flag that scale segments are used
  2029. curentAxis.scaleSegmentsUsed = false;
  2030. }
  2031. }
  2032. /// <summary>
  2033. /// Checks if chart area border should be drawn on top of series.
  2034. /// </summary>
  2035. /// <returns>True if border should be darwn on top.</returns>
  2036. private bool IsBorderOnTopSeries()
  2037. {
  2038. // For most of the chart types chart area border is drawn on top.
  2039. bool result = true;
  2040. foreach (Series series in this.Common.Chart.Series)
  2041. {
  2042. if (series.ChartArea == this.Name)
  2043. {
  2044. // It is common for the Bubble and Point chart types to draw markers
  2045. // partially outside of the chart area. By drawing the border before
  2046. // series we avoiding the possibility of drawing the border line on
  2047. // top of the marker.
  2048. if (series.ChartType == SeriesChartType.Bubble ||
  2049. series.ChartType == SeriesChartType.Point)
  2050. {
  2051. return false;
  2052. }
  2053. }
  2054. }
  2055. return result;
  2056. }
  2057. /// <summary>
  2058. /// Paint the chart area cursors.
  2059. /// </summary>
  2060. /// <param name="graph">Chart graphics.</param>
  2061. /// <param name="cursorOnly">Indicates that only cursors are redrawn.</param>
  2062. [SuppressMessage("Microsoft.Usage", "CA1801:ReviewUnusedParameters", Justification = "These parameters are used when compiling for the WinForms version of Chart")]
  2063. internal void PaintCursors(ChartGraphics graph, bool cursorOnly)
  2064. {
  2065. // Cursors and selection are supoorted only in 2D charts
  2066. if (this.Area3DStyle.Enable3D == true)
  2067. {
  2068. return;
  2069. }
  2070. // Do not draw cursor/selection for chart types that do not require axis (like Pie)
  2071. if (!this.requireAxes)
  2072. {
  2073. return;
  2074. }
  2075. // Cursors and selection are not supoorted in circular areas
  2076. if (this.chartAreaIsCurcular)
  2077. {
  2078. return;
  2079. }
  2080. // Do not draw cursor/selection while printing
  2081. if (this.Common != null &&
  2082. this.Common.ChartPicture != null &&
  2083. this.Common.ChartPicture.isPrinting)
  2084. {
  2085. return;
  2086. }
  2087. // Do not draw cursor/selection when chart area is not visible
  2088. // because either width or height is set to zero
  2089. if (this.Position.Width == 0f ||
  2090. this.Position.Height == 0f)
  2091. {
  2092. return;
  2093. }
  2094. Chart chart = this.Common.Chart;
  2095. ChartPicture chartPicture = Common.ChartPicture;
  2096. // Check if cursor should be drawn
  2097. if (!double.IsNaN(_cursorX.SelectionStart) ||
  2098. !double.IsNaN(_cursorX.SelectionEnd) ||
  2099. !double.IsNaN(_cursorX.Position) ||
  2100. !double.IsNaN(_cursorY.SelectionStart) ||
  2101. !double.IsNaN(_cursorY.SelectionEnd) ||
  2102. !double.IsNaN(_cursorY.Position))
  2103. {
  2104. if (!chartPicture.backgroundRestored &&
  2105. !chartPicture.isSelectionMode)
  2106. {
  2107. chartPicture.backgroundRestored = true;
  2108. Rectangle chartPosition = new Rectangle(0, 0, chartPicture.Width, chartPicture.Height);
  2109. // Get chart area position
  2110. Rectangle absAreaPlotPosition = Rectangle.Round(graph.GetAbsoluteRectangle(PlotAreaPosition.ToRectangleF()));
  2111. int maxCursorWidth = (CursorY.LineWidth > CursorX.LineWidth) ? CursorY.LineWidth + 1 : CursorX.LineWidth + 1;
  2112. absAreaPlotPosition.Inflate(maxCursorWidth, maxCursorWidth);
  2113. absAreaPlotPosition.Intersect(new Rectangle(0, 0, chart.Width, chart.Height));
  2114. // Create area buffer bitmap
  2115. if (areaBufferBitmap == null ||
  2116. chartPicture.nonTopLevelChartBuffer == null ||
  2117. !cursorOnly)
  2118. {
  2119. // Dispose previous bitmap
  2120. if (areaBufferBitmap != null)
  2121. {
  2122. areaBufferBitmap.Dispose();
  2123. areaBufferBitmap = null;
  2124. }
  2125. if (chartPicture.nonTopLevelChartBuffer != null)
  2126. {
  2127. chartPicture.nonTopLevelChartBuffer.Dispose();
  2128. chartPicture.nonTopLevelChartBuffer = null;
  2129. }
  2130. // Copy chart area plotting rectangle from the chart's dubble buffer image into area dubble buffer image
  2131. if (chart.paintBufferBitmap != null)
  2132. {
  2133. areaBufferBitmap = chart.paintBufferBitmap.Clone(absAreaPlotPosition, chart.paintBufferBitmap.PixelFormat);
  2134. }
  2135. // Copy whole chart from the chart's dubble buffer image into area dubble buffer image
  2136. if (chart.paintBufferBitmap != null &&
  2137. chart.paintBufferBitmap.Size.Width >= chartPosition.Size.Width &&
  2138. chart.paintBufferBitmap.Size.Height >= chartPosition.Size.Height)
  2139. {
  2140. chartPicture.nonTopLevelChartBuffer = chart.paintBufferBitmap.Clone(
  2141. chartPosition, chart.paintBufferBitmap.PixelFormat);
  2142. }
  2143. }
  2144. else if (cursorOnly && chartPicture.nonTopLevelChartBuffer != null)
  2145. {
  2146. // Restore previous background
  2147. chart.paintBufferBitmapGraphics.DrawImageUnscaled(
  2148. chartPicture.nonTopLevelChartBuffer,
  2149. chartPosition);
  2150. }
  2151. }
  2152. // Draw chart area cursors and range selection
  2153. _cursorY.Paint(graph);
  2154. _cursorX.Paint(graph);
  2155. }
  2156. }
  2157. #endregion
  2158. #region Circular chart area methods
  2159. /// <summary>
  2160. /// Gets a circular chart type interface that belongs to this chart area.
  2161. /// </summary>
  2162. /// <returns>ICircularChartType interface or null.</returns>
  2163. internal ICircularChartType GetCircularChartType()
  2164. {
  2165. // Get number of sectors in circular chart area
  2166. foreach (Series series in this.Common.DataManager.Series)
  2167. {
  2168. if (series.IsVisible() && series.ChartArea == this.Name)
  2169. {
  2170. ICircularChartType type = Common.ChartTypeRegistry.GetChartType(series.ChartTypeName) as ICircularChartType;
  2171. ;
  2172. if (type != null)
  2173. {
  2174. return type;
  2175. }
  2176. }
  2177. }
  2178. return null;
  2179. }
  2180. /// <summary>
  2181. /// Calculate size of the circular axis labels and sets auto-fit font.
  2182. /// </summary>
  2183. /// <param name="chartGraph">Chart graphics object.</param>
  2184. /// <param name="chartAreaPosition">The Chart area position.</param>
  2185. /// <param name="plotArea">Plotting area size.</param>
  2186. /// <param name="xTitleSize">Size of title on the axis.</param>
  2187. /// <param name="yTitleSize">Size of title on the axis.</param>
  2188. internal void FitCircularLabels(
  2189. ChartGraphics chartGraph,
  2190. ElementPosition chartAreaPosition,
  2191. ref RectangleF plotArea,
  2192. float xTitleSize,
  2193. float yTitleSize)
  2194. {
  2195. // Check if axis labels are enabled
  2196. if (!this.AxisX.LabelStyle.Enabled)
  2197. {
  2198. return;
  2199. }
  2200. // Get absolute titles size
  2201. SizeF titleSize = chartGraph.GetAbsoluteSize(new SizeF(xTitleSize, yTitleSize));
  2202. // Get absolute position of area
  2203. RectangleF plotAreaRectAbs = chartGraph.GetAbsoluteRectangle(plotArea);
  2204. RectangleF areaRectAbs = chartGraph.GetAbsoluteRectangle(chartAreaPosition.ToRectangleF());
  2205. // Get absolute markers size and spacing
  2206. float spacing = chartGraph.GetAbsolutePoint(new PointF(0, this.AxisX.markSize + Axis.elementSpacing)).Y;
  2207. // Get circular axis list
  2208. ArrayList axisList = GetCircularAxisList();
  2209. // Get circular axis labels style
  2210. CircularAxisLabelsStyle labelsStyle = GetCircularAxisLabelsStyle();
  2211. //*****************************************************************
  2212. //** Calculate the auto-fit font if required
  2213. //*****************************************************************
  2214. if (this.AxisX.LabelStyle.Enabled && this.AxisX.IsLabelAutoFit)
  2215. {
  2216. // Set max auto fit font
  2217. this.AxisX.autoLabelFont = Common.ChartPicture.FontCache.GetFont(
  2218. this.AxisX.LabelStyle.Font.FontFamily,
  2219. 14,
  2220. this.AxisX.LabelStyle.Font.Style,
  2221. GraphicsUnit.Point);
  2222. // Get estimated labels size
  2223. float labelsSizeEstimate = GetCircularLabelsSize(chartGraph, areaRectAbs, plotAreaRectAbs, titleSize);
  2224. labelsSizeEstimate = (float)Math.Min(labelsSizeEstimate * 1.1f, plotAreaRectAbs.Width / 5f);
  2225. labelsSizeEstimate += spacing;
  2226. // Calculate auto-fit font
  2227. this.AxisX.GetCircularAxisLabelsAutoFitFont(chartGraph, axisList, labelsStyle, plotAreaRectAbs, areaRectAbs, labelsSizeEstimate);
  2228. }
  2229. //*****************************************************************
  2230. //** Shrink plot area size proportionally
  2231. //*****************************************************************
  2232. // Get labels size
  2233. float labelsSize = GetCircularLabelsSize(chartGraph, areaRectAbs, plotAreaRectAbs, titleSize);
  2234. // Check if change size is smaller than radius
  2235. labelsSize = (float)Math.Min(labelsSize, plotAreaRectAbs.Width / 2.5f);
  2236. labelsSize += spacing;
  2237. plotAreaRectAbs.X += labelsSize;
  2238. plotAreaRectAbs.Width -= 2f * labelsSize;
  2239. plotAreaRectAbs.Y += labelsSize;
  2240. plotAreaRectAbs.Height -= 2f * labelsSize;
  2241. // Restrict minimum plot area size
  2242. if (plotAreaRectAbs.Width < 1.0f)
  2243. {
  2244. plotAreaRectAbs.Width = 1.0f;
  2245. }
  2246. if (plotAreaRectAbs.Height < 1.0f)
  2247. {
  2248. plotAreaRectAbs.Height = 1.0f;
  2249. }
  2250. plotArea = chartGraph.GetRelativeRectangle(plotAreaRectAbs);
  2251. //*****************************************************************
  2252. //** Set axes labels size
  2253. //*****************************************************************
  2254. SizeF relativeLabelSize = chartGraph.GetRelativeSize(new SizeF(labelsSize, labelsSize));
  2255. this.AxisX.labelSize = relativeLabelSize.Height;
  2256. this.AxisX2.labelSize = relativeLabelSize.Height;
  2257. this.AxisY.labelSize = relativeLabelSize.Width;
  2258. this.AxisY2.labelSize = relativeLabelSize.Width;
  2259. }
  2260. /// <summary>
  2261. /// Calculate size of the circular axis labels.
  2262. /// </summary>
  2263. /// <param name="chartGraph">Chart graphics object.</param>
  2264. /// <param name="areaRectAbs">The Chart area position.</param>
  2265. /// <param name="plotAreaRectAbs">Plotting area size.</param>
  2266. /// <param name="titleSize">Size of title on the axes.</param>
  2267. /// <returns>Circulat labels style.</returns>
  2268. internal float GetCircularLabelsSize(
  2269. ChartGraphics chartGraph,
  2270. RectangleF areaRectAbs,
  2271. RectangleF plotAreaRectAbs,
  2272. SizeF titleSize)
  2273. {
  2274. // Find current horiz. and vert. spacing between plotting and chart areas
  2275. SizeF areaDiff = new SizeF(plotAreaRectAbs.X - areaRectAbs.X, plotAreaRectAbs.Y - areaRectAbs.Y);
  2276. areaDiff.Width -= titleSize.Width;
  2277. areaDiff.Height -= titleSize.Height;
  2278. // Get absolute center of the area
  2279. PointF areaCenterAbs = chartGraph.GetAbsolutePoint(this.circularCenter);
  2280. // Get circular axis list
  2281. ArrayList axisList = GetCircularAxisList();
  2282. // Get circular axis labels style
  2283. CircularAxisLabelsStyle labelsStyle = GetCircularAxisLabelsStyle();
  2284. // Defines on how much (pixels) the circular chart area radius should be reduced
  2285. float labelsSize = 0f;
  2286. //*****************************************************************
  2287. //** Loop through all axis labels
  2288. //*****************************************************************
  2289. foreach (CircularChartAreaAxis axis in axisList)
  2290. {
  2291. //*****************************************************************
  2292. //** Measure label text
  2293. //*****************************************************************
  2294. SizeF textSize = chartGraph.MeasureString(
  2295. axis.Title.Replace("\\n", "\n"),
  2296. (this.AxisX.autoLabelFont == null) ? this.AxisX.LabelStyle.Font : this.AxisX.autoLabelFont);
  2297. textSize.Width = (float)Math.Ceiling(textSize.Width * 1.1f);
  2298. textSize.Height = (float)Math.Ceiling(textSize.Height * 1.1f);
  2299. //*****************************************************************
  2300. //** Calculate area size change depending on labels style
  2301. //*****************************************************************
  2302. if (labelsStyle == CircularAxisLabelsStyle.Circular)
  2303. {
  2304. labelsSize = (float)Math.Max(
  2305. labelsSize,
  2306. textSize.Height);
  2307. }
  2308. else if (labelsStyle == CircularAxisLabelsStyle.Radial)
  2309. {
  2310. float textAngle = axis.AxisPosition + 90;
  2311. // For angled text find it's X and Y components
  2312. float width = (float)Math.Cos(textAngle / 180F * Math.PI) * textSize.Width;
  2313. float height = (float)Math.Sin(textAngle / 180F * Math.PI) * textSize.Width;
  2314. width = (float)Math.Abs(Math.Ceiling(width));
  2315. height = (float)Math.Abs(Math.Ceiling(height));
  2316. // Reduce text size by current spacing between plotting area and chart area
  2317. width -= areaDiff.Width;
  2318. height -= areaDiff.Height;
  2319. if (width < 0)
  2320. width = 0;
  2321. if (height < 0)
  2322. height = 0;
  2323. labelsSize = (float)Math.Max(
  2324. labelsSize,
  2325. Math.Max(width, height));
  2326. }
  2327. else if (labelsStyle == CircularAxisLabelsStyle.Horizontal)
  2328. {
  2329. // Get text angle
  2330. float textAngle = axis.AxisPosition;
  2331. if (textAngle > 180f)
  2332. {
  2333. textAngle -= 180f;
  2334. }
  2335. // Get label rotated position
  2336. PointF[] labelPosition = new PointF[] { new PointF(areaCenterAbs.X, plotAreaRectAbs.Y) };
  2337. Matrix newMatrix = new Matrix();
  2338. newMatrix.RotateAt(textAngle, areaCenterAbs);
  2339. newMatrix.TransformPoints(labelPosition);
  2340. // Calculate width
  2341. float width = textSize.Width;
  2342. width -= areaRectAbs.Right - labelPosition[0].X;
  2343. if (width < 0f)
  2344. {
  2345. width = 0f;
  2346. }
  2347. labelsSize = (float)Math.Max(
  2348. labelsSize,
  2349. Math.Max(width, textSize.Height));
  2350. }
  2351. }
  2352. return labelsSize;
  2353. }
  2354. /// <summary>
  2355. /// True if polygons should be used instead of the circles for the chart area.
  2356. /// </summary>
  2357. internal bool CircularUsePolygons
  2358. {
  2359. get
  2360. {
  2361. // Check if value was precalculated
  2362. if (this._circularUsePolygons == int.MinValue)
  2363. {
  2364. _circularUsePolygons = 0;
  2365. // Look for custom properties in series
  2366. foreach (Series series in this.Common.DataManager.Series)
  2367. {
  2368. if (series.ChartArea == this.Name && series.IsVisible())
  2369. {
  2370. // Get custom attribute
  2371. if (series.IsCustomPropertySet(CustomPropertyName.AreaDrawingStyle))
  2372. {
  2373. if (String.Compare(series[CustomPropertyName.AreaDrawingStyle], "Polygon", StringComparison.OrdinalIgnoreCase) == 0)
  2374. {
  2375. _circularUsePolygons = 1;
  2376. }
  2377. else if (String.Compare(series[CustomPropertyName.AreaDrawingStyle], "Circle", StringComparison.OrdinalIgnoreCase) == 0)
  2378. {
  2379. _circularUsePolygons = 0;
  2380. }
  2381. else
  2382. {
  2383. throw (new InvalidOperationException(SR.ExceptionCustomAttributeValueInvalid(series[CustomPropertyName.AreaDrawingStyle], "AreaDrawingStyle")));
  2384. }
  2385. break;
  2386. }
  2387. }
  2388. }
  2389. }
  2390. return (this._circularUsePolygons == 1);
  2391. }
  2392. }
  2393. /// <summary>
  2394. /// Gets circular area axis labels style.
  2395. /// </summary>
  2396. /// <returns>Axis labels style.</returns>
  2397. internal CircularAxisLabelsStyle GetCircularAxisLabelsStyle()
  2398. {
  2399. CircularAxisLabelsStyle style = CircularAxisLabelsStyle.Auto;
  2400. // Get maximum number of points in all series
  2401. foreach (Series series in this.Common.DataManager.Series)
  2402. {
  2403. if (series.IsVisible() && series.ChartArea == this.Name && series.IsCustomPropertySet(CustomPropertyName.CircularLabelsStyle))
  2404. {
  2405. string styleName = series[CustomPropertyName.CircularLabelsStyle];
  2406. if (String.Compare(styleName, "Auto", StringComparison.OrdinalIgnoreCase) == 0)
  2407. {
  2408. style = CircularAxisLabelsStyle.Auto;
  2409. }
  2410. else if (String.Compare(styleName, "Circular", StringComparison.OrdinalIgnoreCase) == 0)
  2411. {
  2412. style = CircularAxisLabelsStyle.Circular;
  2413. }
  2414. else if (String.Compare(styleName, "Radial", StringComparison.OrdinalIgnoreCase) == 0)
  2415. {
  2416. style = CircularAxisLabelsStyle.Radial;
  2417. }
  2418. else if (String.Compare(styleName, "Horizontal", StringComparison.OrdinalIgnoreCase) == 0)
  2419. {
  2420. style = CircularAxisLabelsStyle.Horizontal;
  2421. }
  2422. else
  2423. {
  2424. throw (new InvalidOperationException(SR.ExceptionCustomAttributeValueInvalid(styleName, "CircularLabelsStyle")));
  2425. }
  2426. }
  2427. }
  2428. // Get auto style
  2429. if (style == CircularAxisLabelsStyle.Auto)
  2430. {
  2431. int sectorNumber = CircularSectorsNumber;
  2432. style = CircularAxisLabelsStyle.Horizontal;
  2433. if (sectorNumber > 30)
  2434. {
  2435. style = CircularAxisLabelsStyle.Radial;
  2436. }
  2437. }
  2438. return style;
  2439. }
  2440. /// <summary>
  2441. /// Number of sectors in the circular area.
  2442. /// </summary>
  2443. internal int CircularSectorsNumber
  2444. {
  2445. get
  2446. {
  2447. // Check if value was precalculated
  2448. if (this._circularSectorNumber == int.MinValue)
  2449. {
  2450. this._circularSectorNumber = GetCircularSectorNumber();
  2451. }
  2452. return this._circularSectorNumber;
  2453. }
  2454. }
  2455. /// <summary>
  2456. /// Gets number of sectors in the circular chart area.
  2457. /// </summary>
  2458. /// <returns>Number of sectors.</returns>
  2459. private int GetCircularSectorNumber()
  2460. {
  2461. ICircularChartType type = this.GetCircularChartType();
  2462. if (type != null)
  2463. {
  2464. return type.GetNumerOfSectors(this, this.Common.DataManager.Series);
  2465. }
  2466. return 0;
  2467. }
  2468. /// <summary>
  2469. /// Fills a list of circular axis.
  2470. /// </summary>
  2471. /// <returns>Axes list.</returns>
  2472. internal ArrayList GetCircularAxisList()
  2473. {
  2474. // Check if list was already created
  2475. if (_circularAxisList == null)
  2476. {
  2477. _circularAxisList = new ArrayList();
  2478. // Loop through all sectors
  2479. int sectorNumber = GetCircularSectorNumber();
  2480. for (int sectorIndex = 0; sectorIndex < sectorNumber; sectorIndex++)
  2481. {
  2482. // Create new axis object
  2483. CircularChartAreaAxis axis = new CircularChartAreaAxis(sectorIndex * 360f / sectorNumber);
  2484. // Check if custom X axis labels will be used
  2485. if (this.AxisX.CustomLabels.Count > 0)
  2486. {
  2487. if (sectorIndex < this.AxisX.CustomLabels.Count)
  2488. {
  2489. axis.Title = this.AxisX.CustomLabels[sectorIndex].Text;
  2490. axis.TitleForeColor = this.AxisX.CustomLabels[sectorIndex].ForeColor;
  2491. }
  2492. }
  2493. else
  2494. {
  2495. // Get axis title from all series
  2496. foreach (Series series in this.Common.DataManager.Series)
  2497. {
  2498. if (series.IsVisible() && series.ChartArea == this.Name && sectorIndex < series.Points.Count)
  2499. {
  2500. if (series.Points[sectorIndex].AxisLabel.Length > 0)
  2501. {
  2502. axis.Title = series.Points[sectorIndex].AxisLabel;
  2503. break;
  2504. }
  2505. }
  2506. }
  2507. }
  2508. // Add axis into the list
  2509. _circularAxisList.Add(axis);
  2510. }
  2511. }
  2512. return _circularAxisList;
  2513. }
  2514. /// <summary>
  2515. /// Converts circular position of the X axis to angle in degrees.
  2516. /// </summary>
  2517. /// <param name="position">X axis position.</param>
  2518. /// <returns>Angle in degrees.</returns>
  2519. internal float CircularPositionToAngle(double position)
  2520. {
  2521. // Get X axis scale size
  2522. double scaleRatio = 360.0 / Math.Abs(this.AxisX.Maximum - this.AxisX.Minimum);
  2523. return (float)(position * scaleRatio + this.AxisX.Crossing);
  2524. }
  2525. #endregion
  2526. #region 2D Series drawing order methods
  2527. /// <summary>
  2528. /// Helper method that returns a list of 'ChartTypeAndSeriesInfo' objects.
  2529. /// This list is used for chart area series drawing in 2D mode. Each
  2530. /// object may represent an individual series or all series that belong
  2531. /// to one chart type.
  2532. ///
  2533. /// This method is intended to fix issues #6443 and #5385 when area chart
  2534. /// type incorrectly overlaps point or line chart type.
  2535. /// </summary>
  2536. /// <returns>List of 'ChartTypeAndSeriesInfo' objects.</returns>
  2537. private ArrayList GetChartTypesAndSeriesToDraw()
  2538. {
  2539. ArrayList resultList = new ArrayList();
  2540. // Build chart type or series position based lists
  2541. if (this.ChartTypes.Count > 1 &&
  2542. (this.ChartTypes.Contains(ChartTypeNames.Area)
  2543. || this.ChartTypes.Contains(ChartTypeNames.SplineArea)
  2544. )
  2545. )
  2546. {
  2547. // Array of chart type names that do not require furher processing
  2548. ArrayList processedChartType = new ArrayList();
  2549. ArrayList splitChartType = new ArrayList();
  2550. // Draw using the exact order in the series collection
  2551. int seriesIndex = 0;
  2552. foreach (Series series in this.Common.DataManager.Series)
  2553. {
  2554. // Check if series is visible and belongs to the chart area
  2555. if (series.ChartArea == this.Name && series.IsVisible() && series.Points.Count > 0)
  2556. {
  2557. // Check if this chart type was already processed
  2558. if (!processedChartType.Contains(series.ChartTypeName))
  2559. {
  2560. // Check if curent chart type can be individually processed
  2561. bool canBeIndividuallyProcessed = false;
  2562. if (series.ChartType == SeriesChartType.Point ||
  2563. series.ChartType == SeriesChartType.Line ||
  2564. series.ChartType == SeriesChartType.Spline ||
  2565. series.ChartType == SeriesChartType.StepLine)
  2566. {
  2567. canBeIndividuallyProcessed = true;
  2568. }
  2569. if (!canBeIndividuallyProcessed)
  2570. {
  2571. // Add a record to process all series of that chart type at once
  2572. resultList.Add(new ChartTypeAndSeriesInfo(series.ChartTypeName));
  2573. processedChartType.Add(series.ChartTypeName);
  2574. }
  2575. else
  2576. {
  2577. // Check if curent chart type has more that 1 series and they are split
  2578. // by other series
  2579. bool chartTypeIsSplit = false;
  2580. if (splitChartType.Contains(series.ChartTypeName))
  2581. {
  2582. chartTypeIsSplit = true;
  2583. }
  2584. else
  2585. {
  2586. bool otherChartTypeFound = false;
  2587. for (int curentSeriesIndex = seriesIndex + 1; curentSeriesIndex < this.Common.DataManager.Series.Count; curentSeriesIndex++)
  2588. {
  2589. if (series.ChartTypeName == this.Common.DataManager.Series[curentSeriesIndex].ChartTypeName)
  2590. {
  2591. if (otherChartTypeFound)
  2592. {
  2593. chartTypeIsSplit = true;
  2594. splitChartType.Add(series.ChartTypeName);
  2595. }
  2596. }
  2597. else
  2598. {
  2599. if (this.Common.DataManager.Series[curentSeriesIndex].ChartType == SeriesChartType.Area ||
  2600. this.Common.DataManager.Series[curentSeriesIndex].ChartType == SeriesChartType.SplineArea)
  2601. {
  2602. otherChartTypeFound = true;
  2603. }
  2604. }
  2605. }
  2606. }
  2607. if (chartTypeIsSplit)
  2608. {
  2609. // Add a record to process this series individually
  2610. resultList.Add(new ChartTypeAndSeriesInfo(series));
  2611. }
  2612. else
  2613. {
  2614. // Add a record to process all series of that chart type at once
  2615. resultList.Add(new ChartTypeAndSeriesInfo(series.ChartTypeName));
  2616. processedChartType.Add(series.ChartTypeName);
  2617. }
  2618. }
  2619. }
  2620. }
  2621. ++seriesIndex;
  2622. }
  2623. }
  2624. else
  2625. {
  2626. foreach (string chartType in this.ChartTypes)
  2627. {
  2628. resultList.Add(new ChartTypeAndSeriesInfo(chartType));
  2629. }
  2630. }
  2631. return resultList;
  2632. }
  2633. /// <summary>
  2634. /// Internal data structure that stores chart type name and optionally series object.
  2635. /// </summary>
  2636. internal class ChartTypeAndSeriesInfo
  2637. {
  2638. /// <summary>
  2639. /// Object constructor.
  2640. /// </summary>
  2641. public ChartTypeAndSeriesInfo()
  2642. {
  2643. }
  2644. /// <summary>
  2645. /// Object constructor.
  2646. /// </summary>
  2647. /// <param name="chartType">Chart type name to initialize with.</param>
  2648. public ChartTypeAndSeriesInfo(string chartType)
  2649. {
  2650. this.ChartType = chartType;
  2651. }
  2652. /// <summary>
  2653. /// Object constructor.
  2654. /// </summary>
  2655. /// <param name="series">Series to initialize with.</param>
  2656. public ChartTypeAndSeriesInfo(Series series)
  2657. {
  2658. this.ChartType = series.ChartTypeName;
  2659. this.Series = series;
  2660. }
  2661. // Chart type name
  2662. internal string ChartType = string.Empty;
  2663. // Series object. Can be set to NULL!
  2664. internal Series Series = null;
  2665. }
  2666. #endregion // 2D Series drawing order methods
  2667. #region IDisposable Members
  2668. /// <summary>
  2669. /// Releases unmanaged and - optionally - managed resources
  2670. /// </summary>
  2671. /// <param name="disposing"><c>true</c> to release both managed and unmanaged resources; <c>false</c> to release only unmanaged resources.</param>
  2672. [System.Diagnostics.CodeAnalysis.SuppressMessage("Microsoft.Usage", "CA2213:DisposableFieldsShouldBeDisposed", MessageId = "axisX")]
  2673. [System.Diagnostics.CodeAnalysis.SuppressMessage("Microsoft.Usage", "CA2213:DisposableFieldsShouldBeDisposed", MessageId = "axisX2")]
  2674. [System.Diagnostics.CodeAnalysis.SuppressMessage("Microsoft.Usage", "CA2213:DisposableFieldsShouldBeDisposed", MessageId = "axisY")]
  2675. [System.Diagnostics.CodeAnalysis.SuppressMessage("Microsoft.Usage", "CA2213:DisposableFieldsShouldBeDisposed", MessageId = "axisY2")]
  2676. protected override void Dispose(bool disposing)
  2677. {
  2678. if (disposing)
  2679. {
  2680. // Dispose managed resources
  2681. if (this._axisArray != null)
  2682. {
  2683. foreach (Axis axis in this._axisArray)
  2684. {
  2685. axis.Dispose();
  2686. }
  2687. this._axisArray = null;
  2688. }
  2689. if (this._areaPosition != null)
  2690. {
  2691. this._areaPosition.Dispose();
  2692. this._areaPosition = null;
  2693. }
  2694. if (this._innerPlotPosition != null)
  2695. {
  2696. this._innerPlotPosition.Dispose();
  2697. this._innerPlotPosition = null;
  2698. }
  2699. if (this.PlotAreaPosition != null)
  2700. {
  2701. this.PlotAreaPosition.Dispose();
  2702. this.PlotAreaPosition = null;
  2703. }
  2704. if (this.areaBufferBitmap != null)
  2705. {
  2706. this.areaBufferBitmap.Dispose();
  2707. this.areaBufferBitmap = null;
  2708. }
  2709. if (this._cursorX != null)
  2710. {
  2711. this._cursorX.Dispose();
  2712. this._cursorX = null;
  2713. }
  2714. if (this._cursorY != null)
  2715. {
  2716. this._cursorY.Dispose();
  2717. this._cursorY = null;
  2718. }
  2719. }
  2720. base.Dispose(disposing);
  2721. }
  2722. #endregion
  2723. }
  2724. }