ChartArea3D.cs 67 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139214021412142214321442145214621472148214921502151215221532154215521562157215821592160216121622163216421652166216721682169217021712172217321742175217621772178217921802181218221832184218521862187218821892190219121922193219421952196219721982199220022012202220322042205
  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: ChartArea3D class represents 3D chart area. It contains
  6. // methods for coordinates transformation, drawing the 3D
  7. // scene and many 3D related helper methods.
  8. //
  9. using System;
  10. using System.Collections;
  11. using System.Collections.Generic;
  12. using System.ComponentModel;
  13. using System.Drawing;
  14. using FastReport.DataVisualization.Charting.ChartTypes;
  15. using FastReport.DataVisualization.Charting.Utilities;
  16. namespace FastReport.DataVisualization.Charting
  17. {
  18. #region 3D lightStyle style enumerations
  19. /// <summary>
  20. /// A lighting style for a 3D chart area.
  21. /// </summary>
  22. public enum LightStyle
  23. {
  24. /// <summary>
  25. /// No lighting.
  26. /// </summary>
  27. None,
  28. /// <summary>
  29. /// Simplistic lighting.
  30. /// </summary>
  31. Simplistic,
  32. /// <summary>
  33. /// Realistic lighting.
  34. /// </summary>
  35. Realistic
  36. }
  37. #endregion
  38. #region 3D Center of Projetion coordinates enumeration
  39. /// <summary>
  40. /// Coordinates of the Center Of Projection
  41. /// </summary>
  42. [Flags]
  43. internal enum COPCoordinates
  44. {
  45. /// <summary>
  46. /// Check X coordinate.
  47. /// </summary>
  48. X = 1,
  49. /// <summary>
  50. /// Check Y coordinate.
  51. /// </summary>
  52. Y = 2,
  53. /// <summary>
  54. /// Check Z coordinate.
  55. /// </summary>
  56. Z = 4
  57. }
  58. #endregion
  59. /// <summary>
  60. /// The ChartArea3DStyleClass class provides the functionality for 3D attributes of chart areas,
  61. /// such as rotation angles and perspective.
  62. /// </summary>
  63. public class ChartArea3DStyle
  64. {
  65. #region Constructor and Initialization
  66. /// <summary>
  67. /// ChartArea3DStyle constructor.
  68. /// </summary>
  69. public ChartArea3DStyle()
  70. {
  71. }
  72. /// <summary>
  73. /// ChartArea3DStyle constructor.
  74. /// </summary>
  75. public ChartArea3DStyle(ChartArea chartArea)
  76. {
  77. this._chartArea = chartArea;
  78. }
  79. /// <summary>
  80. /// Initialize Chart area and axes
  81. /// </summary>
  82. /// <param name="chartArea">Chart area object.</param>
  83. internal void Initialize(ChartArea chartArea)
  84. {
  85. this._chartArea = chartArea;
  86. }
  87. #endregion
  88. #region Fields
  89. // Reference to the chart area object
  90. private ChartArea _chartArea = null;
  91. // Enables/disables 3D chart types in the area.
  92. private bool _enable3D = false;
  93. // Indicates that axes are set at the right angle independent of the rotation.
  94. private bool _isRightAngleAxes = true;
  95. // Indicates that series should be drawn as isClustered.
  96. private bool _isClustered = false;
  97. // 3D area lightStyle style.
  98. private LightStyle _lightStyle = LightStyle.Simplistic;
  99. // 3D area perspective which controls the scaleView of the chart depth.
  100. private int _perspective = 0;
  101. // Chart area rotation angle around the X axis.
  102. private int _inclination = 30;
  103. // Chart area rotation angle around the Y axis.
  104. private int _rotation = 30;
  105. // Chart area walls width.
  106. private int _wallWidth = 7;
  107. // Series points depth in percentages
  108. private int _pointDepth = 100;
  109. // Series points gap depth in percentages
  110. private int _pointGapDepth = 100;
  111. #endregion
  112. #region Properties
  113. /// <summary>
  114. /// Gets or sets a Boolean value that toggles 3D for a chart area on and off.
  115. /// </summary>
  116. [
  117. SRCategory("CategoryAttribute3D"),
  118. Bindable(true),
  119. DefaultValue(false),
  120. SRDescription("DescriptionAttributeChartArea3DStyle_Enable3D"),
  121. ParenthesizePropertyNameAttribute(true)
  122. ]
  123. public bool Enable3D
  124. {
  125. get
  126. {
  127. return this._enable3D;
  128. }
  129. set
  130. {
  131. if (this._enable3D != value)
  132. {
  133. this._enable3D = value;
  134. if (this._chartArea != null)
  135. {
  136. #if SUBAXES
  137. // If one of the axes has sub axis the scales has to be recalculated
  138. foreach(Axis axis in this._chartArea.Axes)
  139. {
  140. if(axis.SubAxes.Count > 0)
  141. {
  142. this._chartArea.ResetAutoValues();
  143. break;
  144. }
  145. }
  146. #endif // SUBAXES
  147. this._chartArea.Invalidate();
  148. _chartArea.CallOnModifing();
  149. }
  150. }
  151. }
  152. }
  153. /// <summary>
  154. /// Gets or sets a Boolean that determines if a chart area is displayed using an isometric projection.
  155. /// </summary>
  156. [
  157. SRCategory("CategoryAttribute3D"),
  158. Bindable(true),
  159. DefaultValue(true),
  160. SRDescription("DescriptionAttributeChartArea3DStyle_RightAngleAxes"),
  161. RefreshPropertiesAttribute(RefreshProperties.All)
  162. ]
  163. public bool IsRightAngleAxes
  164. {
  165. get
  166. {
  167. return _isRightAngleAxes;
  168. }
  169. set
  170. {
  171. _isRightAngleAxes = value;
  172. // Adjust 3D properties values
  173. if (_isRightAngleAxes)
  174. {
  175. // Disable perspective if right angle axis are used
  176. this._perspective = 0;
  177. }
  178. if (this._chartArea != null)
  179. {
  180. this._chartArea.Invalidate();
  181. _chartArea.CallOnModifing();
  182. }
  183. }
  184. }
  185. /// <summary>
  186. /// Gets or sets a Boolean value that determines if bar chart or column
  187. /// chart data series are clustered (displayed along distinct rows).
  188. /// </summary>
  189. [
  190. SRCategory("CategoryAttribute3D"),
  191. Bindable(true),
  192. DefaultValue(false),
  193. SRDescription("DescriptionAttributeChartArea3DStyle_Clustered"),
  194. ]
  195. public bool IsClustered
  196. {
  197. get
  198. {
  199. return _isClustered;
  200. }
  201. set
  202. {
  203. _isClustered = value;
  204. if (this._chartArea != null)
  205. {
  206. this._chartArea.Invalidate();
  207. _chartArea.CallOnModifing();
  208. }
  209. }
  210. }
  211. /// <summary>
  212. /// Gets or sets the style of lighting for a 3D chart area.
  213. /// </summary>
  214. [
  215. SRCategory("CategoryAttribute3D"),
  216. Bindable(true),
  217. DefaultValue(typeof(LightStyle), "Simplistic"),
  218. SRDescription("DescriptionAttributeChartArea3DStyle_Light"),
  219. ]
  220. public LightStyle LightStyle
  221. {
  222. get
  223. {
  224. return _lightStyle;
  225. }
  226. set
  227. {
  228. _lightStyle = value;
  229. if (this._chartArea != null)
  230. {
  231. this._chartArea.Invalidate();
  232. _chartArea.CallOnModifing();
  233. }
  234. }
  235. }
  236. /// <summary>
  237. /// Gets or sets the percent of perspective for a 3D chart area.
  238. /// </summary>
  239. [
  240. SRCategory("CategoryAttribute3D"),
  241. Bindable(true),
  242. DefaultValue(0),
  243. SRDescription("DescriptionAttributeChartArea3DStyle_Perspective"),
  244. RefreshPropertiesAttribute(RefreshProperties.All)
  245. ]
  246. public int Perspective
  247. {
  248. get
  249. {
  250. return _perspective;
  251. }
  252. set
  253. {
  254. if(value < 0 || value > 100)
  255. {
  256. throw (new ArgumentOutOfRangeException("value", SR.ExceptionChartArea3DPerspectiveInvalid));
  257. }
  258. _perspective = value;
  259. // Adjust 3D properties values
  260. if (_perspective != 0)
  261. {
  262. // Disable right angle axes
  263. this._isRightAngleAxes = false;
  264. }
  265. if (this._chartArea != null)
  266. {
  267. this._chartArea.Invalidate();
  268. _chartArea.CallOnModifing();
  269. }
  270. }
  271. }
  272. /// <summary>
  273. /// Gets or sets the inclination for a 3D chart area.
  274. /// </summary>
  275. [
  276. SRCategory("CategoryAttribute3D"),
  277. Bindable(true),
  278. DefaultValue(30),
  279. SRDescription("DescriptionAttributeChartArea3DStyle_Inclination"),
  280. RefreshPropertiesAttribute(RefreshProperties.All)
  281. ]
  282. public int Inclination
  283. {
  284. get
  285. {
  286. return _inclination;
  287. }
  288. set
  289. {
  290. if(value < -90 || value > 90)
  291. {
  292. throw (new ArgumentOutOfRangeException("value", SR.ExceptionChartArea3DInclinationInvalid));
  293. }
  294. _inclination = value;
  295. if (this._chartArea != null)
  296. {
  297. this._chartArea.Invalidate();
  298. _chartArea.CallOnModifing();
  299. }
  300. }
  301. }
  302. /// <summary>
  303. /// Gets or sets the rotation angle for a 3D chart area.
  304. /// </summary>
  305. [
  306. SRCategory("CategoryAttribute3D"),
  307. Bindable(true),
  308. DefaultValue(30),
  309. SRDescription("DescriptionAttributeChartArea3DStyle_Rotation"),
  310. RefreshPropertiesAttribute(RefreshProperties.All)
  311. ]
  312. public int Rotation
  313. {
  314. get
  315. {
  316. return _rotation;
  317. }
  318. set
  319. {
  320. if(value < -180 || value > 180)
  321. {
  322. throw (new ArgumentOutOfRangeException("value", SR.ExceptionChartArea3DRotationInvalid));
  323. }
  324. _rotation = value;
  325. if (this._chartArea != null)
  326. {
  327. this._chartArea.Invalidate();
  328. _chartArea.CallOnModifing();
  329. }
  330. }
  331. }
  332. /// <summary>
  333. /// Gets or sets the width of the walls displayed in 3D chart areas.
  334. /// </summary>
  335. [
  336. SRCategory("CategoryAttribute3D"),
  337. Bindable(true),
  338. DefaultValue(7),
  339. SRDescription("DescriptionAttributeChartArea3DStyle_WallWidth"),
  340. RefreshPropertiesAttribute(RefreshProperties.All)
  341. ]
  342. public int WallWidth
  343. {
  344. get
  345. {
  346. return _wallWidth;
  347. }
  348. set
  349. {
  350. if(value < 0 || value > 30)
  351. {
  352. throw (new ArgumentOutOfRangeException("value", SR.ExceptionChartArea3DWallWidthInvalid));
  353. }
  354. _wallWidth = value;
  355. if (this._chartArea != null)
  356. {
  357. this._chartArea.Invalidate();
  358. _chartArea.CallOnModifing();
  359. }
  360. }
  361. }
  362. /// <summary>
  363. /// Gets or sets the depth of data points displayed in 3D chart areas (0-1000%).
  364. /// </summary>
  365. [
  366. SRCategory("CategoryAttribute3D"),
  367. Bindable(true),
  368. DefaultValue(100),
  369. SRDescription("DescriptionAttributeChartArea3DStyle_PointDepth"),
  370. RefreshPropertiesAttribute(RefreshProperties.All)
  371. ]
  372. public int PointDepth
  373. {
  374. get
  375. {
  376. return _pointDepth;
  377. }
  378. set
  379. {
  380. if(value < 0 || value > 1000)
  381. {
  382. throw (new ArgumentOutOfRangeException("value", SR.ExceptionChartArea3DPointsDepthInvalid));
  383. }
  384. _pointDepth = value;
  385. if (this._chartArea != null)
  386. {
  387. this._chartArea.Invalidate();
  388. _chartArea.CallOnModifing();
  389. }
  390. }
  391. }
  392. /// <summary>
  393. /// Gets or sets the distance between series rows in 3D chart areas (0-1000%).
  394. /// </summary>
  395. [
  396. SRCategory("CategoryAttribute3D"),
  397. Bindable(true),
  398. DefaultValue(100),
  399. SRDescription("DescriptionAttributeChartArea3DStyle_PointGapDepth"),
  400. RefreshPropertiesAttribute(RefreshProperties.All)
  401. ]
  402. public int PointGapDepth
  403. {
  404. get
  405. {
  406. return _pointGapDepth;
  407. }
  408. set
  409. {
  410. if(value < 0 || value > 1000)
  411. {
  412. throw (new ArgumentOutOfRangeException("value", SR.ExceptionChartArea3DPointsGapInvalid));
  413. }
  414. _pointGapDepth = value;
  415. if (this._chartArea != null)
  416. {
  417. this._chartArea.Invalidate();
  418. _chartArea.CallOnModifing();
  419. }
  420. }
  421. }
  422. #endregion
  423. }
  424. /// <summary>
  425. /// ChartArea3D class represents 3D chart area. It contains all the 3D
  426. /// scene settings and methods for drawing the 3D plotting area, and calculating
  427. /// the depth of chart elements.
  428. /// </summary>
  429. public partial class ChartArea
  430. {
  431. #region Fields
  432. // Chart area 3D style attribuytes
  433. private ChartArea3DStyle _area3DStyle = new ChartArea3DStyle();
  434. // Coordinate convertion matrix
  435. internal Matrix3D matrix3D = new Matrix3D();
  436. // Chart area scene wall width in relative coordinates
  437. internal SizeF areaSceneWallWidth = SizeF.Empty;
  438. // Chart area scene depth
  439. internal float areaSceneDepth = 0;
  440. // Visible surfaces in plotting area
  441. private SurfaceNames _visibleSurfaces;
  442. // Z axis depth of series points
  443. private double _pointsDepth = 0;
  444. // Z axis depth of the gap between isClustered series
  445. private double _pointsGapDepth = 0;
  446. /// <summary>
  447. /// Indicates that series order should be reversed to simulate Y axis rotation.
  448. /// </summary>
  449. private bool _reverseSeriesOrder = false;
  450. /// <summary>
  451. /// Old X axis reversed flag
  452. /// </summary>
  453. internal bool oldReverseX = false;
  454. /// <summary>
  455. /// Old Y axis reversed flag
  456. /// </summary>
  457. internal bool oldReverseY = false;
  458. /// <summary>
  459. /// Old Y axis rotation angle
  460. /// </summary>
  461. internal int oldYAngle = 30;
  462. /// <summary>
  463. /// List of all stack group names
  464. /// </summary>
  465. private ArrayList _stackGroupNames = null;
  466. /// <summary>
  467. /// This list contains an array of series names for each 3D cluster
  468. /// </summary>
  469. internal List<List<string>> seriesClusters = null;
  470. #endregion
  471. #region 3D Style properties
  472. /// <summary>
  473. /// Gets or sets a ChartArea3DStyle object, used to draw all series in a chart area in 3D.
  474. /// </summary>
  475. [
  476. SRCategory("CategoryAttribute3D"),
  477. Bindable(true),
  478. DefaultValue(null),
  479. SRDescription("DescriptionAttributeArea3DStyle"),
  480. DesignerSerializationVisibility(DesignerSerializationVisibility.Content),
  481. TypeConverter(typeof(NoNameExpandableObjectConverter)),
  482. ]
  483. public ChartArea3DStyle Area3DStyle
  484. {
  485. get
  486. {
  487. return _area3DStyle;
  488. }
  489. set
  490. {
  491. _area3DStyle = value;
  492. // Initialize style object
  493. _area3DStyle.Initialize((ChartArea)this);
  494. CallOnModifing();
  495. }
  496. }
  497. /// <summary>
  498. /// Indicates that series order should be reversed to simulate Y axis rotation.
  499. /// </summary>
  500. internal bool ReverseSeriesOrder
  501. {
  502. get { return _reverseSeriesOrder; }
  503. }
  504. /// <summary>
  505. /// Gets the list of all stack group names
  506. /// </summary>
  507. internal ArrayList StackGroupNames
  508. {
  509. get { return _stackGroupNames; }
  510. }
  511. #endregion
  512. #region 3D Coordinates transfotmation methods
  513. /// <summary>
  514. /// Call this method to apply 3D transformations on an array of 3D points (must be done before calling GDI+ drawing methods).
  515. /// </summary>
  516. /// <param name="points">3D Points array.</param>
  517. public void TransformPoints( Point3D[] points )
  518. {
  519. // Convert Z coordinates from 0-100% to axis values
  520. foreach(Point3D pt in points)
  521. {
  522. pt.Z = (pt.Z / 100f) * this.areaSceneDepth;
  523. }
  524. // Transform points
  525. this.matrix3D.TransformPoints( points );
  526. }
  527. #endregion
  528. #region 3D Scene drawing methods
  529. /// <summary>
  530. /// Draws chart area 3D scene, which consists of 3 or 2 walls.
  531. /// </summary>
  532. /// <param name="graph">Chart graphics object.</param>
  533. /// <param name="position">Chart area 2D position.</param>
  534. internal void DrawArea3DScene(ChartGraphics graph, RectangleF position)
  535. {
  536. // Reference to the chart area class
  537. ChartArea chartArea = (ChartArea)this;
  538. // Calculate relative size of the wall
  539. areaSceneWallWidth = graph.GetRelativeSize( new SizeF(this.Area3DStyle.WallWidth, this.Area3DStyle.WallWidth));
  540. //***********************************************************
  541. //** Calculate the depth of the chart area scene
  542. //***********************************************************
  543. areaSceneDepth = GetArea3DSceneDepth();
  544. //***********************************************************
  545. //** Initialize coordinate transformation matrix
  546. //***********************************************************
  547. this.matrix3D.Initialize(
  548. position,
  549. areaSceneDepth,
  550. this.Area3DStyle.Inclination,
  551. this.Area3DStyle.Rotation,
  552. this.Area3DStyle.Perspective,
  553. this.Area3DStyle.IsRightAngleAxes);
  554. //***********************************************************
  555. //** Initialize Lighting
  556. //***********************************************************
  557. this.matrix3D.InitLight(
  558. this.Area3DStyle.LightStyle
  559. );
  560. //***********************************************************
  561. //** Find chart area visible surfaces
  562. //***********************************************************
  563. _visibleSurfaces = graph.GetVisibleSurfaces(
  564. position,
  565. 0,
  566. areaSceneDepth,
  567. this.matrix3D);
  568. //***********************************************************
  569. //** Chech if area scene should be drawn
  570. //***********************************************************
  571. Color sceneBackColor = chartArea.BackColor;
  572. // Do not draw the transparent walls
  573. if(sceneBackColor == Color.Transparent)
  574. {
  575. // Area wall is not visible
  576. areaSceneWallWidth = SizeF.Empty;
  577. return;
  578. }
  579. // If color is not set (default) - use LightGray
  580. if(sceneBackColor == Color.Empty)
  581. {
  582. sceneBackColor = Color.LightGray;
  583. }
  584. //***********************************************************
  585. //** Adjust scene 2D rectangle so that wall are drawn
  586. //** outside plotting area.
  587. //***********************************************************
  588. // If bottom wall is visible
  589. if(IsBottomSceneWallVisible())
  590. {
  591. position.Height += areaSceneWallWidth.Height;
  592. }
  593. // Adjust for the left/right wall
  594. position.Width += areaSceneWallWidth.Width;
  595. if(this.Area3DStyle.Rotation > 0)
  596. {
  597. position.X -= areaSceneWallWidth.Width;
  598. }
  599. //***********************************************************
  600. //** Draw scene walls
  601. //***********************************************************
  602. // Draw back wall
  603. RectangleF wallRect2D = new RectangleF(position.Location, position.Size);
  604. float wallDepth = areaSceneWallWidth.Width;
  605. float wallZPosition = -wallDepth;
  606. // For isometric projection Front wall should be visible sometimes
  607. if( IsMainSceneWallOnFront())
  608. {
  609. wallZPosition = areaSceneDepth;
  610. }
  611. graph.Fill3DRectangle(
  612. wallRect2D,
  613. wallZPosition,
  614. wallDepth,
  615. this.matrix3D,
  616. chartArea.Area3DStyle.LightStyle,
  617. sceneBackColor,
  618. chartArea.BorderColor,
  619. chartArea.BorderWidth,
  620. chartArea.BorderDashStyle,
  621. DrawingOperationTypes.DrawElement );
  622. // Draw side wall on the left or right side
  623. wallRect2D = new RectangleF(position.Location, position.Size);
  624. wallRect2D.Width = areaSceneWallWidth.Width;
  625. if(!IsSideSceneWallOnLeft())
  626. {
  627. // Wall is on the right side
  628. wallRect2D.X = position.Right - areaSceneWallWidth.Width;
  629. }
  630. graph.Fill3DRectangle(
  631. wallRect2D,
  632. 0f,
  633. areaSceneDepth,
  634. this.matrix3D,
  635. chartArea.Area3DStyle.LightStyle,
  636. sceneBackColor,
  637. chartArea.BorderColor,
  638. chartArea.BorderWidth,
  639. chartArea.BorderDashStyle,
  640. DrawingOperationTypes.DrawElement);
  641. // Draw bottom wall
  642. if(IsBottomSceneWallVisible())
  643. {
  644. wallRect2D = new RectangleF(position.Location, position.Size);
  645. wallRect2D.Height = areaSceneWallWidth.Height;
  646. wallRect2D.Y = position.Bottom - areaSceneWallWidth.Height;
  647. wallRect2D.Width -= areaSceneWallWidth.Width;
  648. if(IsSideSceneWallOnLeft())
  649. {
  650. wallRect2D.X += areaSceneWallWidth.Width;
  651. }
  652. wallZPosition = 0;
  653. graph.Fill3DRectangle(
  654. wallRect2D,
  655. 0f,
  656. areaSceneDepth,
  657. this.matrix3D,
  658. chartArea.Area3DStyle.LightStyle,
  659. sceneBackColor,
  660. chartArea.BorderColor,
  661. chartArea.BorderWidth,
  662. chartArea.BorderDashStyle,
  663. DrawingOperationTypes.DrawElement );
  664. }
  665. }
  666. /// <summary>
  667. /// Helper method which return True if bottom wall of the
  668. /// chart area scene is visible.
  669. /// </summary>
  670. /// <returns>True if bottom wall is visible.</returns>
  671. internal bool IsBottomSceneWallVisible()
  672. {
  673. return (this.Area3DStyle.Inclination >= 0);
  674. }
  675. /// <summary>
  676. /// Helper method which return True if main wall of the
  677. /// chart area scene is displayed on the front side.
  678. /// </summary>
  679. /// <returns>True if front wall is visible.</returns>
  680. internal bool IsMainSceneWallOnFront()
  681. {
  682. // Note: Not used in this version!
  683. return false;
  684. }
  685. /// <summary>
  686. /// Helper method which return True if side wall of the
  687. /// chart area scene is displayed on the left side.
  688. /// </summary>
  689. /// <returns>True if bottom wall is visible.</returns>
  690. internal bool IsSideSceneWallOnLeft()
  691. {
  692. return (this.Area3DStyle.Rotation > 0);
  693. }
  694. #endregion
  695. #region 3D Scene depth claculation methods
  696. /// <summary>
  697. /// Call this method to get the Z position of a series (useful for custom drawing).
  698. /// </summary>
  699. /// <param name="series">The series to retrieve the Z position for.</param>
  700. /// <returns>The Z position of the specified series. Measured as a percentage of the chart area's depth.</returns>
  701. public float GetSeriesZPosition(Series series)
  702. {
  703. float positionZ, depth;
  704. GetSeriesZPositionAndDepth(series, out depth, out positionZ);
  705. return ((positionZ + depth/2f) / this.areaSceneDepth) * 100f;
  706. }
  707. /// <summary>
  708. /// Call this method to get the depth of a series in a chart area.
  709. /// </summary>
  710. /// <param name="series">The series to retrieve the depth for.</param>
  711. /// <returns>The depth of the specified series. Measured as a percentage of the chart area's depth.</returns>
  712. public float GetSeriesDepth(Series series)
  713. {
  714. float positionZ, depth;
  715. GetSeriesZPositionAndDepth(series, out depth, out positionZ);
  716. return (depth / this.areaSceneDepth) * 100f;
  717. }
  718. /// <summary>
  719. /// Calculates area 3D scene depth depending on the number of isClustered
  720. /// series and interval between points.
  721. /// </summary>
  722. /// <returns>Returns the depth of the chart area scene.</returns>
  723. private float GetArea3DSceneDepth()
  724. {
  725. //***********************************************************
  726. //** Calculate the smallest interval between points
  727. //***********************************************************
  728. // Check if any series attached to the area is indexed
  729. bool indexedSeries = ChartHelper.IndexedSeries(this.Common, this._series.ToArray());
  730. // Smallest interval series
  731. Series smallestIntervalSeries = null;
  732. if(this._series.Count > 0)
  733. {
  734. smallestIntervalSeries = this.Common.DataManager.Series[(string)this._series[0]];
  735. }
  736. // Get X axis
  737. Axis xAxis = ((ChartArea)this).AxisX;
  738. if(this._series.Count > 0)
  739. {
  740. Series firstSeries = this.Common.DataManager.Series[this._series[0]];
  741. if(firstSeries != null && firstSeries.XAxisType == AxisType.Secondary)
  742. {
  743. xAxis = ((ChartArea)this).AxisX2;
  744. }
  745. }
  746. // Get smallest interval between points (use interval 1 for indexed series)
  747. double clusteredInterval = 1;
  748. if(!indexedSeries)
  749. {
  750. bool sameInterval;
  751. clusteredInterval = this.GetPointsInterval(this._series, xAxis.IsLogarithmic, xAxis.logarithmBase, false, out sameInterval, out smallestIntervalSeries);
  752. }
  753. //***********************************************************
  754. //** Check if "DrawSideBySide" attribute is set.
  755. //***********************************************************
  756. bool drawSideBySide = false;
  757. if(smallestIntervalSeries != null)
  758. {
  759. drawSideBySide = Common.ChartTypeRegistry.GetChartType(smallestIntervalSeries.ChartTypeName).SideBySideSeries;
  760. foreach(string seriesName in this._series)
  761. {
  762. if(this.Common.DataManager.Series[seriesName].IsCustomPropertySet(CustomPropertyName.DrawSideBySide))
  763. {
  764. string attribValue = this.Common.DataManager.Series[seriesName][CustomPropertyName.DrawSideBySide];
  765. if(String.Compare(attribValue, "False", StringComparison.OrdinalIgnoreCase) == 0)
  766. {
  767. drawSideBySide = false;
  768. }
  769. else if(String.Compare(attribValue, "True", StringComparison.OrdinalIgnoreCase) == 0)
  770. {
  771. drawSideBySide = true;
  772. }
  773. else if (String.Compare(attribValue, "Auto", StringComparison.OrdinalIgnoreCase) == 0)
  774. {
  775. // Do nothing
  776. }
  777. else
  778. {
  779. throw (new InvalidOperationException(SR.ExceptionAttributeDrawSideBySideInvalid));
  780. }
  781. }
  782. }
  783. }
  784. // Get smallest interval categorical axis
  785. Axis categoricalAxis = ((ChartArea)this).AxisX;
  786. if(smallestIntervalSeries != null && smallestIntervalSeries.XAxisType == AxisType.Secondary)
  787. {
  788. categoricalAxis = ((ChartArea)this).AxisX2;
  789. }
  790. //***********************************************************
  791. //** If series with the smallest interval is displayed
  792. //** side-by-side - devide the interval by number of series
  793. //** of the same chart type.
  794. //***********************************************************
  795. double pointWidthSize = 0.8;
  796. int seriesNumber = 1;
  797. if(smallestIntervalSeries != null)
  798. {
  799. // Check if series is side-by-side
  800. if(this.Area3DStyle.IsClustered && drawSideBySide)
  801. {
  802. // Count number of side-by-side series
  803. seriesNumber = 0;
  804. foreach(string seriesName in this._series)
  805. {
  806. // Get series object from name
  807. Series curSeries = this.Common.DataManager.Series[seriesName];
  808. if(String.Compare(curSeries.ChartTypeName, smallestIntervalSeries.ChartTypeName, StringComparison.OrdinalIgnoreCase) == 0 )
  809. {
  810. ++seriesNumber;
  811. }
  812. }
  813. }
  814. }
  815. //***********************************************************
  816. //** Stacked column and bar charts can be drawn side-by-side
  817. //** using the StackGroupName custom properties. The code
  818. //** checks if multiple groups are used how many of these
  819. //** groups exsist.
  820. //**
  821. //** If isClustered mode enabled each stack group is drawn
  822. //** using it's own cluster.
  823. //***********************************************************
  824. if(smallestIntervalSeries != null && this.Area3DStyle.IsClustered)
  825. {
  826. // Check series support stack groups
  827. if(Common.ChartTypeRegistry.GetChartType(smallestIntervalSeries.ChartTypeName).SupportStackedGroups)
  828. {
  829. // Calculate how many stack groups exsist
  830. seriesNumber = 0;
  831. ArrayList stackGroupNames = new ArrayList();
  832. foreach(string seriesName in this._series)
  833. {
  834. // Get series object from name
  835. Series curSeries = this.Common.DataManager.Series[seriesName];
  836. if(String.Compare(curSeries.ChartTypeName, smallestIntervalSeries.ChartTypeName, StringComparison.OrdinalIgnoreCase) == 0 )
  837. {
  838. string seriesStackGroupName = string.Empty;
  839. if(curSeries.IsCustomPropertySet(CustomPropertyName.StackedGroupName))
  840. {
  841. seriesStackGroupName = curSeries[CustomPropertyName.StackedGroupName];
  842. }
  843. // Add group name if it do not already exsist
  844. if(!stackGroupNames.Contains(seriesStackGroupName))
  845. {
  846. stackGroupNames.Add(seriesStackGroupName);
  847. }
  848. }
  849. }
  850. seriesNumber = stackGroupNames.Count;
  851. }
  852. }
  853. //***********************************************************
  854. //** Check if series provide custom value for point\gap depth
  855. //***********************************************************
  856. _pointsDepth = clusteredInterval * pointWidthSize * this.Area3DStyle.PointDepth / 100.0;
  857. _pointsDepth = categoricalAxis.GetPixelInterval(_pointsDepth);
  858. if(smallestIntervalSeries != null)
  859. {
  860. _pointsDepth = smallestIntervalSeries.GetPointWidth(
  861. this.Common.graph,
  862. categoricalAxis,
  863. clusteredInterval,
  864. 0.8) / seriesNumber;
  865. _pointsDepth *= this.Area3DStyle.PointDepth / 100.0;
  866. }
  867. _pointsGapDepth = (_pointsDepth * 0.8) * this.Area3DStyle.PointGapDepth / 100.0;
  868. // Get point depth and gap from series
  869. if(smallestIntervalSeries != null)
  870. {
  871. smallestIntervalSeries.GetPointDepthAndGap(
  872. this.Common.graph,
  873. categoricalAxis,
  874. ref _pointsDepth,
  875. ref _pointsGapDepth);
  876. }
  877. //***********************************************************
  878. //** Calculate scene depth
  879. //***********************************************************
  880. return (float)((_pointsGapDepth + _pointsDepth) * GetNumberOfClusters());
  881. }
  882. /// <summary>
  883. /// Calculates the depth and Z position for specified series.
  884. /// </summary>
  885. /// <param name="series">Series object.</param>
  886. /// <param name="depth">Returns series depth.</param>
  887. /// <param name="positionZ">Returns series Z position.</param>
  888. internal void GetSeriesZPositionAndDepth(Series series, out float depth, out float positionZ)
  889. {
  890. // Check arguments
  891. if (series == null)
  892. throw new ArgumentNullException("series");
  893. // Get series cluster index
  894. int seriesIndex = GetSeriesClusterIndex(series);
  895. // Initialize the output parameters
  896. depth = (float)_pointsDepth;
  897. positionZ = (float)(_pointsGapDepth / 2.0 + (_pointsDepth + _pointsGapDepth) * seriesIndex);
  898. }
  899. /// <summary>
  900. /// Returns number of clusters on the Z axis.
  901. /// </summary>
  902. /// <returns>Number of clusters on the Z axis.</returns>
  903. internal int GetNumberOfClusters()
  904. {
  905. if(this.seriesClusters == null)
  906. {
  907. // Lists that hold processed chart types and stacked groups
  908. ArrayList processedChartTypes = new ArrayList();
  909. ArrayList processedStackedGroups = new ArrayList();
  910. // Reset series cluster list
  911. this.seriesClusters = new List<List<string>>();
  912. // Iterate through all series that belong to this chart area
  913. int clusterIndex = -1;
  914. foreach(string seriesName in this._series)
  915. {
  916. // Get series object by name
  917. Series curSeries = this.Common.DataManager.Series[seriesName];
  918. // Check if stacked chart type is using multiple groups that
  919. // can be displayed in individual clusters
  920. if(!this.Area3DStyle.IsClustered &&
  921. Common.ChartTypeRegistry.GetChartType(curSeries.ChartTypeName).SupportStackedGroups)
  922. {
  923. // Get group name
  924. string stackGroupName = StackedColumnChart.GetSeriesStackGroupName(curSeries);
  925. // Check if group was already counted
  926. if(processedStackedGroups.Contains(stackGroupName))
  927. {
  928. // Find in which cluster this stacked group is located
  929. bool found = false;
  930. for(int index = 0; !found && index < this.seriesClusters.Count; index++)
  931. {
  932. foreach(string name in this.seriesClusters[index])
  933. {
  934. // Get series object by name
  935. Series ser = this.Common.DataManager.Series[name];
  936. if(stackGroupName == StackedColumnChart.GetSeriesStackGroupName(ser))
  937. {
  938. clusterIndex = index;
  939. found = true;
  940. }
  941. }
  942. }
  943. }
  944. else
  945. {
  946. // Increase cluster index
  947. clusterIndex = this.seriesClusters.Count;
  948. // Add processed group name
  949. processedStackedGroups.Add(stackGroupName);
  950. }
  951. }
  952. // Chech if series is displayed in the same cluster than other series
  953. else if( Common.ChartTypeRegistry.GetChartType(curSeries.ChartTypeName).Stacked ||
  954. (this.Area3DStyle.IsClustered && Common.ChartTypeRegistry.GetChartType(curSeries.ChartTypeName).SideBySideSeries) )
  955. {
  956. // Check if this chart type is already in the list
  957. if(processedChartTypes.Contains(curSeries.ChartTypeName.ToUpper(System.Globalization.CultureInfo.InvariantCulture)))
  958. {
  959. // Find in which cluster this chart type is located
  960. bool found = false;
  961. for(int index = 0; !found && index < this.seriesClusters.Count; index++)
  962. {
  963. foreach(string name in this.seriesClusters[index])
  964. {
  965. // Get series object by name
  966. Series ser = this.Common.DataManager.Series[name];
  967. if(ser.ChartTypeName.ToUpper(System.Globalization.CultureInfo.InvariantCulture) ==
  968. curSeries.ChartTypeName.ToUpper(System.Globalization.CultureInfo.InvariantCulture))
  969. {
  970. clusterIndex = index;
  971. found = true;
  972. }
  973. }
  974. }
  975. }
  976. else
  977. {
  978. // Increase cluster index
  979. clusterIndex = this.seriesClusters.Count;
  980. // Add new chart type into the collection
  981. processedChartTypes.Add(curSeries.ChartTypeName.ToUpper(System.Globalization.CultureInfo.InvariantCulture));
  982. }
  983. }
  984. else
  985. {
  986. // Create New cluster
  987. clusterIndex = this.seriesClusters.Count;
  988. }
  989. // Create an item in the cluster list that will hold all series names
  990. if(this.seriesClusters.Count <= clusterIndex)
  991. {
  992. this.seriesClusters.Add(new List<string>());
  993. }
  994. // Add series name into the current cluster
  995. this.seriesClusters[clusterIndex].Add(seriesName);
  996. }
  997. }
  998. return this.seriesClusters.Count;
  999. }
  1000. /// <summary>
  1001. /// Get series cluster index.
  1002. /// </summary>
  1003. /// <param name="series">Series object.</param>
  1004. /// <returns>Series cluster index.</returns>
  1005. internal int GetSeriesClusterIndex(Series series)
  1006. {
  1007. // Fill list of clusters
  1008. if(this.seriesClusters == null)
  1009. {
  1010. this.GetNumberOfClusters();
  1011. }
  1012. // Iterate through all clusters
  1013. for(int clusterIndex = 0; clusterIndex < this.seriesClusters.Count; clusterIndex++)
  1014. {
  1015. List<string> seriesNames = this.seriesClusters[clusterIndex];
  1016. // Iterate through all series names
  1017. foreach(string seriesName in seriesNames)
  1018. {
  1019. if(seriesName == series.Name)
  1020. {
  1021. // Check if series are drawn in reversed order
  1022. if(this._reverseSeriesOrder)
  1023. {
  1024. clusterIndex = (this.seriesClusters.Count - 1) - clusterIndex;
  1025. }
  1026. return clusterIndex;
  1027. }
  1028. }
  1029. }
  1030. return 0;
  1031. }
  1032. #endregion
  1033. #region 3D Scene helper methods
  1034. /// <summary>
  1035. /// This method is used to calculate estimated scene
  1036. /// depth. Regular scene depth method can not be used
  1037. /// because Plot area position is zero. Instead, Chart
  1038. /// area position is used to find depth of the scene.
  1039. /// Algorithm which draws axis labels will decide what
  1040. /// should be size and position of plotting area.
  1041. /// </summary>
  1042. /// <returns>Returns estimated scene depth</returns>
  1043. private float GetEstimatedSceneDepth()
  1044. {
  1045. float sceneDepth;
  1046. ChartArea area = (ChartArea) this;
  1047. // Reset current list of clusters
  1048. this.seriesClusters = null;
  1049. ElementPosition plottingAreaRect = area.InnerPlotPosition;
  1050. area.AxisX.PlotAreaPosition = area.Position;
  1051. area.AxisY.PlotAreaPosition = area.Position;
  1052. area.AxisX2.PlotAreaPosition = area.Position;
  1053. area.AxisY2.PlotAreaPosition = area.Position;
  1054. sceneDepth = GetArea3DSceneDepth();
  1055. area.AxisX.PlotAreaPosition = plottingAreaRect;
  1056. area.AxisY.PlotAreaPosition = plottingAreaRect;
  1057. area.AxisX2.PlotAreaPosition = plottingAreaRect;
  1058. area.AxisY2.PlotAreaPosition = plottingAreaRect;
  1059. return sceneDepth;
  1060. }
  1061. /// <summary>
  1062. /// Estimate Interval for 3D Charts. When scene is rotated the
  1063. /// number of labels should be changed.
  1064. /// </summary>
  1065. /// <param name="graph">Chart graphics object.</param>
  1066. internal void Estimate3DInterval(ChartGraphics graph )
  1067. {
  1068. // Reference to the chart area class
  1069. ChartArea area = (ChartArea)this;
  1070. // Calculate relative size of the wall
  1071. areaSceneWallWidth = graph.GetRelativeSize( new SizeF(this.Area3DStyle.WallWidth, this.Area3DStyle.WallWidth));
  1072. //***********************************************************
  1073. //** Calculate the depth of the chart area scene
  1074. //***********************************************************
  1075. areaSceneDepth = GetEstimatedSceneDepth();
  1076. RectangleF plottingRect = area.Position.ToRectangleF();
  1077. // Check if plot area position was recalculated.
  1078. // If not and non-auto InnerPlotPosition & Position were
  1079. // specified - do all needed calculations
  1080. if(PlotAreaPosition.Width == 0 &&
  1081. PlotAreaPosition.Height == 0 &&
  1082. !area.InnerPlotPosition.Auto
  1083. && !area.Position.Auto)
  1084. {
  1085. // Initialize plotting area position
  1086. if(!area.InnerPlotPosition.Auto)
  1087. {
  1088. plottingRect.X += (area.Position.Width / 100F) * area.InnerPlotPosition.X;
  1089. plottingRect.Y += (area.Position.Height / 100F) * area.InnerPlotPosition.Y;
  1090. plottingRect.Width = (area.Position.Width / 100F) * area.InnerPlotPosition.Width;
  1091. plottingRect.Height = (area.Position.Height / 100F) * area.InnerPlotPosition.Height;
  1092. }
  1093. }
  1094. int yAngle = GetRealYAngle( );
  1095. //***********************************************************
  1096. //** Initialize coordinate transformation matrix
  1097. //***********************************************************
  1098. Matrix3D intervalMatrix3D = new Matrix3D();
  1099. intervalMatrix3D.Initialize(
  1100. plottingRect,
  1101. areaSceneDepth,
  1102. this.Area3DStyle.Inclination,
  1103. yAngle,
  1104. this.Area3DStyle.Perspective,
  1105. this.Area3DStyle.IsRightAngleAxes);
  1106. bool notUsed;
  1107. float zPosition;
  1108. double size;
  1109. Point3D [] points = new Point3D[8];
  1110. if( area.switchValueAxes )
  1111. {
  1112. // X Axis
  1113. zPosition = axisX.GetMarksZPosition( out notUsed );
  1114. points[0] = new Point3D( plottingRect.X, plottingRect.Y, zPosition );
  1115. points[1] = new Point3D( plottingRect.X, plottingRect.Bottom, zPosition );
  1116. // Y Axis
  1117. zPosition = axisY.GetMarksZPosition( out notUsed );
  1118. points[2] = new Point3D( plottingRect.X, plottingRect.Bottom, zPosition );
  1119. points[3] = new Point3D( plottingRect.Right, plottingRect.Bottom, zPosition );
  1120. // X2 Axis
  1121. zPosition = axisX2.GetMarksZPosition( out notUsed );
  1122. points[4] = new Point3D( plottingRect.X, plottingRect.Y, zPosition );
  1123. points[5] = new Point3D( plottingRect.X, plottingRect.Bottom, zPosition );
  1124. // Y2 Axis
  1125. zPosition = axisY2.GetMarksZPosition( out notUsed );
  1126. points[6] = new Point3D( plottingRect.X, plottingRect.Y, zPosition );
  1127. points[7] = new Point3D( plottingRect.Right, plottingRect.Y, zPosition );
  1128. }
  1129. else
  1130. {
  1131. // X Axis
  1132. zPosition = axisX.GetMarksZPosition( out notUsed );
  1133. points[0] = new Point3D( plottingRect.X, plottingRect.Bottom, zPosition );
  1134. points[1] = new Point3D( plottingRect.Right, plottingRect.Bottom, zPosition );
  1135. // Y Axis
  1136. zPosition = axisY.GetMarksZPosition( out notUsed );
  1137. points[2] = new Point3D( plottingRect.X, plottingRect.Y, zPosition );
  1138. points[3] = new Point3D( plottingRect.X, plottingRect.Bottom, zPosition );
  1139. // X2 Axis
  1140. zPosition = axisX2.GetMarksZPosition( out notUsed );
  1141. points[4] = new Point3D( plottingRect.X, plottingRect.Y, zPosition );
  1142. points[5] = new Point3D( plottingRect.Right, plottingRect.Y, zPosition );
  1143. // Y2 Axis
  1144. zPosition = axisY2.GetMarksZPosition( out notUsed );
  1145. points[6] = new Point3D( plottingRect.X, plottingRect.Y, zPosition );
  1146. points[7] = new Point3D( plottingRect.X, plottingRect.Bottom, zPosition );
  1147. }
  1148. // Crossing has to be reset because interval and
  1149. // sometimes minimum and maximum are changed.
  1150. foreach( Axis axis in area.Axes )
  1151. {
  1152. axis.crossing = axis.tempCrossing;
  1153. }
  1154. // Transform all points
  1155. intervalMatrix3D.TransformPoints( points );
  1156. int axisIndx = 0;
  1157. foreach( Axis axis in area.Axes )
  1158. {
  1159. // Find size of projected axis
  1160. size = Math.Sqrt(
  1161. ( points[axisIndx].X - points[axisIndx+1].X ) * ( points[axisIndx].X - points[axisIndx+1].X ) +
  1162. ( points[axisIndx].Y - points[axisIndx+1].Y ) * ( points[axisIndx].Y - points[axisIndx+1].Y ) );
  1163. // At the beginning plotting area chart is not calculated because
  1164. // algorithm for labels calculates plotting area position. To
  1165. // calculate labels position we need interval and interval
  1166. // need this correction. Because of that Chart area is used
  1167. // instead of plotting area position. If secondary label is
  1168. // enabled error for using chart area position instead of
  1169. // plotting area position is much bigger. This value
  1170. // corrects this error.
  1171. float plottingChartAreaCorrection = 1;
  1172. if( !area.switchValueAxes )
  1173. {
  1174. plottingChartAreaCorrection = 0.5F;
  1175. }
  1176. // Set correction for axis size
  1177. if( axis.AxisName == AxisName.X || axis.AxisName == AxisName.X2 )
  1178. {
  1179. if( area.switchValueAxes )
  1180. axis.interval3DCorrection = size / plottingRect.Height;
  1181. else
  1182. axis.interval3DCorrection = size / plottingRect.Width;
  1183. }
  1184. else
  1185. {
  1186. if( area.switchValueAxes )
  1187. axis.interval3DCorrection = size / plottingRect.Width;
  1188. else
  1189. axis.interval3DCorrection = size / plottingRect.Height * plottingChartAreaCorrection;
  1190. }
  1191. // There is a limit for correction
  1192. if( axis.interval3DCorrection < 0.15 )
  1193. axis.interval3DCorrection = 0.15;
  1194. // There is a limit for correction
  1195. if( axis.interval3DCorrection > 0.8 )
  1196. axis.interval3DCorrection = 1.0;
  1197. axisIndx += 2;
  1198. }
  1199. }
  1200. /// <summary>
  1201. /// Calculates real Y angle from Y angle and reverseSeriesOrder field
  1202. /// </summary>
  1203. /// <returns>Real Y angle</returns>
  1204. internal int GetRealYAngle( )
  1205. {
  1206. int yAngle;
  1207. // Case from -90 to 90
  1208. yAngle = this.Area3DStyle.Rotation;
  1209. // Case from 90 to 180
  1210. if( this._reverseSeriesOrder && this.Area3DStyle.Rotation >= 0 )
  1211. yAngle = this.Area3DStyle.Rotation - 180;
  1212. // Case from -90 to -180
  1213. if( this._reverseSeriesOrder && this.Area3DStyle.Rotation <= 0 )
  1214. yAngle = this.Area3DStyle.Rotation + 180;
  1215. return yAngle;
  1216. }
  1217. /// <summary>
  1218. /// Check if surface element should be drawn on the Back or Front layer.
  1219. /// </summary>
  1220. /// <param name="surfaceName">Surface name.</param>
  1221. /// <param name="backLayer">Back/front layer.</param>
  1222. /// <param name="onEdge">Indicates that element is on the edge (drawn on the back layer).</param>
  1223. /// <returns>True if element should be drawn.</returns>
  1224. internal bool ShouldDrawOnSurface(SurfaceNames surfaceName, bool backLayer, bool onEdge)
  1225. {
  1226. // Check if surface element should be drawn on the Back or Front layer.
  1227. bool isVisible = ((this._visibleSurfaces & surfaceName) == surfaceName);
  1228. // Elements on the edge are drawn on the back layer
  1229. if(onEdge)
  1230. {
  1231. return backLayer;
  1232. }
  1233. return (backLayer == (!isVisible) );
  1234. }
  1235. /// <summary>
  1236. /// Indicates that data points in all series of this
  1237. /// chart area should be drawn in reversed order.
  1238. /// </summary>
  1239. /// <returns>True if series points should be drawn in reversed order.</returns>
  1240. internal bool DrawPointsInReverseOrder()
  1241. {
  1242. return (this.Area3DStyle.Rotation <= 0);
  1243. }
  1244. /// <summary>
  1245. /// Checks if points should be drawn from sides to center.
  1246. /// </summary>
  1247. /// <param name="coord">Which coordinate of COP (X, Y or Z) to test for surface overlapping</param>
  1248. /// <returns>True if points should be drawn from sides to center.</returns>
  1249. internal bool DrawPointsToCenter(ref COPCoordinates coord)
  1250. {
  1251. bool result = false;
  1252. COPCoordinates resultCoordinates = 0;
  1253. // Check only if perspective is set
  1254. if(this.Area3DStyle.Perspective != 0)
  1255. {
  1256. if( (coord & COPCoordinates.X) == COPCoordinates.X )
  1257. {
  1258. // Only when Left & Right sides of plotting area are invisible
  1259. if ((this._visibleSurfaces & SurfaceNames.Left) == 0 &&
  1260. (this._visibleSurfaces & SurfaceNames.Right) == 0)
  1261. {
  1262. result = true;
  1263. }
  1264. resultCoordinates = resultCoordinates | COPCoordinates.X;
  1265. }
  1266. if( (coord & COPCoordinates.Y) == COPCoordinates.Y )
  1267. {
  1268. // Only when Top & Bottom sides of plotting area are invisible
  1269. if ((this._visibleSurfaces & SurfaceNames.Top) == 0 &&
  1270. (this._visibleSurfaces & SurfaceNames.Bottom) == 0)
  1271. {
  1272. result = true;
  1273. }
  1274. resultCoordinates = resultCoordinates | COPCoordinates.Y;
  1275. }
  1276. if( (coord & COPCoordinates.Z) == COPCoordinates.Z )
  1277. {
  1278. // Only when Front & Back sides of plotting area are invisible
  1279. if ((this._visibleSurfaces & SurfaceNames.Front) == 0 &&
  1280. (this._visibleSurfaces & SurfaceNames.Back) == 0)
  1281. {
  1282. result = true;
  1283. }
  1284. resultCoordinates = resultCoordinates | COPCoordinates.Z;
  1285. }
  1286. }
  1287. return result;
  1288. }
  1289. /// <summary>
  1290. /// Checks if series should be drawn from sides to center.
  1291. /// </summary>
  1292. /// <returns>True if series should be drawn from sides to center.</returns>
  1293. internal bool DrawSeriesToCenter()
  1294. {
  1295. // Check only if perspective is set
  1296. if(this.Area3DStyle.Perspective != 0)
  1297. {
  1298. // Only when Left & Right sides of plotting area are invisible
  1299. if ((this._visibleSurfaces & SurfaceNames.Front) == 0 &&
  1300. (this._visibleSurfaces & SurfaceNames.Back) == 0)
  1301. {
  1302. return true;
  1303. }
  1304. }
  1305. return false;
  1306. }
  1307. #endregion
  1308. #region 3D Series drawing and selection methods
  1309. /// <summary>
  1310. /// Draws 3D series in the chart area.
  1311. /// </summary>
  1312. /// <param name="graph">Chart graphics object.</param>
  1313. internal void PaintChartSeries3D( ChartGraphics graph )
  1314. {
  1315. // Reference to the chart area object
  1316. ChartArea area = (ChartArea)this;
  1317. // Get order of series drawing
  1318. List<Series> seriesDrawingOrder = GetSeriesDrawingOrder(_reverseSeriesOrder);
  1319. // Loop through all series in the order of drawing
  1320. IChartType type;
  1321. foreach( object seriesObj in seriesDrawingOrder)
  1322. {
  1323. Series series = (Series)seriesObj;
  1324. type = Common.ChartTypeRegistry.GetChartType(series.ChartTypeName);
  1325. type.Paint( graph, Common, area, series );
  1326. }
  1327. }
  1328. #endregion
  1329. #region 3D Series & Points drawing order methods
  1330. /// <summary>
  1331. /// Gets a list of series names that belong to the same 3D cluster.
  1332. /// </summary>
  1333. /// <param name="seriesName">One of the series names that belongs to the cluster.</param>
  1334. /// <returns>List of all series names that belong to the same cluster as specified series.</returns>
  1335. internal List<string> GetClusterSeriesNames(string seriesName)
  1336. {
  1337. // Iterate through all clusters
  1338. foreach(List<string> seriesNames in this.seriesClusters)
  1339. {
  1340. if(seriesNames.Contains(seriesName))
  1341. {
  1342. return seriesNames;
  1343. }
  1344. }
  1345. return new List<string>();
  1346. }
  1347. /// <summary>
  1348. /// Gets the series list in drawing order.
  1349. /// </summary>
  1350. /// <param name="reverseSeriesOrder">Series order should be reversed because of the Y axis angle.</param>
  1351. /// <returns>Gets the series list in drawing order.</returns>
  1352. private List<Series> GetSeriesDrawingOrder(bool reverseSeriesOrder)
  1353. {
  1354. // Create list of series
  1355. List<Series> seriesList = new List<Series>();
  1356. // Iterate through all clusters
  1357. foreach(List<string> seriesNames in this.seriesClusters)
  1358. {
  1359. // Make sure there is at least one series
  1360. if(seriesNames.Count > 0)
  1361. {
  1362. // Get first series object in the current cluster
  1363. Series series = Common.DataManager.Series[seriesNames[0]];
  1364. // Add series into the drawing list
  1365. seriesList.Add(series);
  1366. }
  1367. }
  1368. // Reversed series list
  1369. if(reverseSeriesOrder)
  1370. {
  1371. seriesList.Reverse();
  1372. }
  1373. // Check if series should be drawn from sides into the center
  1374. if(DrawSeriesToCenter() &&
  1375. this.matrix3D.IsInitialized())
  1376. {
  1377. // Get Z coordinate of Center Of Projection
  1378. Point3D areaProjectionCenter = new Point3D(float.NaN, float.NaN, float.NaN);
  1379. areaProjectionCenter = this.GetCenterOfProjection(COPCoordinates.Z);
  1380. if(!float.IsNaN(areaProjectionCenter.Z))
  1381. {
  1382. // Loop through all series
  1383. for(int seriesIndex = 0; seriesIndex < seriesList.Count; seriesIndex++)
  1384. {
  1385. // Check if series is not empty
  1386. if(((Series)seriesList[seriesIndex]).Points.Count == 0)
  1387. {
  1388. continue;
  1389. }
  1390. // Get series Z position
  1391. float seriesDepth, seriesZPosition;
  1392. this.GetSeriesZPositionAndDepth((Series)seriesList[seriesIndex], out seriesDepth, out seriesZPosition);
  1393. // Check if series passes the Z coordinate of Center of Projection
  1394. if(seriesZPosition >= areaProjectionCenter.Z)
  1395. {
  1396. // Reversed all series order staring from previous series
  1397. --seriesIndex;
  1398. if(seriesIndex < 0)
  1399. seriesIndex = 0;
  1400. seriesList.Reverse(seriesIndex, seriesList.Count - seriesIndex);
  1401. break;
  1402. }
  1403. }
  1404. }
  1405. }
  1406. return seriesList;
  1407. }
  1408. /// <summary>
  1409. /// Gets number of stack groups in specified array of series names.
  1410. /// </summary>
  1411. /// <param name="seriesNamesList">Array of series names.</param>
  1412. /// <returns>Number of stack groups. One by default.</returns>
  1413. private int GetNumberOfStackGroups(IList<string> seriesNamesList)
  1414. {
  1415. this._stackGroupNames = new ArrayList();
  1416. foreach( object seriesName in seriesNamesList )
  1417. {
  1418. // Get series object
  1419. Series ser = this.Common.DataManager.Series[(string)seriesName];
  1420. // Get stack group name from the series
  1421. string stackGroupName = string.Empty;
  1422. if(ser.IsCustomPropertySet(CustomPropertyName.StackedGroupName))
  1423. {
  1424. stackGroupName = ser[CustomPropertyName.StackedGroupName];
  1425. }
  1426. // Add group name if it do not already exsist
  1427. if(!this._stackGroupNames.Contains(stackGroupName))
  1428. {
  1429. this._stackGroupNames.Add(stackGroupName);
  1430. }
  1431. }
  1432. return this._stackGroupNames.Count;
  1433. }
  1434. /// <summary>
  1435. /// Gets index of the series stack group.
  1436. /// </summary>
  1437. /// <param name="series">Series to get the index for.</param>
  1438. /// <param name="stackGroupName">Group name this series belongs to.</param>
  1439. /// <returns>Index of series stack group.</returns>
  1440. internal int GetSeriesStackGroupIndex(Series series, ref string stackGroupName)
  1441. {
  1442. stackGroupName = string.Empty;
  1443. if(this._stackGroupNames != null)
  1444. {
  1445. // Get stack group name from the series
  1446. if(series.IsCustomPropertySet(CustomPropertyName.StackedGroupName))
  1447. {
  1448. stackGroupName = series[CustomPropertyName.StackedGroupName];
  1449. }
  1450. return this._stackGroupNames.IndexOf(stackGroupName);
  1451. }
  1452. return 0;
  1453. }
  1454. /// <summary>
  1455. /// Determine the order of points drawing from one or several series of the same type.
  1456. /// </summary>
  1457. /// <param name="seriesNamesList">List of series names.</param>
  1458. /// <param name="chartType">Chart type.</param>
  1459. /// <param name="selection">If True selection mode is active (points order should be reversed).</param>
  1460. /// <param name="coord">Which coordinate of COP (X, Y or Z) to test for surface overlapping</param>
  1461. /// <param name="comparer">Points comparer class. Can be Null.</param>
  1462. /// <param name="mainYValueIndex">Index of the main Y value.</param>
  1463. /// <param name="sideBySide">Series should be drawn side by side.</param>
  1464. /// <returns>Array list of points in drawing order.</returns>
  1465. internal ArrayList GetDataPointDrawingOrder(
  1466. List<string> seriesNamesList,
  1467. IChartType chartType,
  1468. bool selection,
  1469. COPCoordinates coord,
  1470. IComparer comparer,
  1471. int mainYValueIndex,
  1472. bool sideBySide)
  1473. {
  1474. ChartArea area = (ChartArea)this;
  1475. // Array of points in all series
  1476. ArrayList pointsList = new ArrayList();
  1477. //************************************************************
  1478. //** Analyse input series
  1479. //************************************************************
  1480. // Find the number of data series for side-by-side drawing
  1481. double numOfSeries = 1;
  1482. if(area.Area3DStyle.IsClustered && !chartType.Stacked && sideBySide)
  1483. {
  1484. numOfSeries = seriesNamesList.Count;
  1485. }
  1486. // Check stacked series group names
  1487. if(chartType.SupportStackedGroups)
  1488. {
  1489. // Fill the list of group names and get the number of unique groups
  1490. int numberOfGroups = this.GetNumberOfStackGroups(seriesNamesList);
  1491. // If series are not isClustered set series number to the stacked group number
  1492. if(this.Area3DStyle.IsClustered &&
  1493. seriesNamesList.Count > 0)
  1494. {
  1495. numOfSeries = numberOfGroups;
  1496. }
  1497. }
  1498. // Check if chart series are indexed
  1499. bool indexedSeries = ChartHelper.IndexedSeries(this.Common, seriesNamesList.ToArray());
  1500. //************************************************************
  1501. //** Loop through all series and fill array of points
  1502. //************************************************************
  1503. int seriesIndx = 0;
  1504. foreach( object seriesName in seriesNamesList )
  1505. {
  1506. // Get series object
  1507. Series ser = this.Common.DataManager.Series[(string)seriesName];
  1508. // Check if stacked groups present
  1509. if(chartType.SupportStackedGroups &&
  1510. this._stackGroupNames != null)
  1511. {
  1512. // Get index of the series using stacked group
  1513. string groupName = string.Empty;
  1514. seriesIndx = this.GetSeriesStackGroupIndex(ser, ref groupName);
  1515. // Set current group name
  1516. StackedColumnChart stackedColumnChart = chartType as StackedColumnChart;
  1517. if (stackedColumnChart != null)
  1518. {
  1519. stackedColumnChart.currentStackGroup = groupName;
  1520. }
  1521. else
  1522. {
  1523. StackedBarChart stackedBarChart = chartType as StackedBarChart;
  1524. if (stackedBarChart != null)
  1525. {
  1526. stackedBarChart.currentStackGroup = groupName;
  1527. }
  1528. }
  1529. }
  1530. // Set active vertical/horizontal axis and their max/min values
  1531. Axis vAxis = (ser.YAxisType == AxisType.Primary) ? area.AxisY : area.AxisY2;
  1532. Axis hAxis = (ser.XAxisType == AxisType.Primary) ? area.AxisX : area.AxisX2;
  1533. // Get points interval:
  1534. // - set interval to 1 for indexed series
  1535. // - if points are not equaly spaced, the minimum interval between points is selected.
  1536. // - if points have same interval bars do not overlap each other.
  1537. bool sameInterval = true;
  1538. double interval = 1;
  1539. if(!indexedSeries)
  1540. {
  1541. interval = area.GetPointsInterval( seriesNamesList, hAxis.IsLogarithmic, hAxis.logarithmBase, true, out sameInterval );
  1542. }
  1543. // Get column width
  1544. double width = ser.GetPointWidth(area.Common.graph, hAxis, interval, 0.8) / numOfSeries;
  1545. // Get series depth and Z position
  1546. float seriesDepth, seriesZPosition;
  1547. this.GetSeriesZPositionAndDepth(ser, out seriesDepth, out seriesZPosition);
  1548. //************************************************************
  1549. //** Loop through all points in series
  1550. //************************************************************
  1551. int index = 0;
  1552. foreach( DataPoint point in ser.Points )
  1553. {
  1554. // Increase point index
  1555. index++;
  1556. // Set x position
  1557. double xCenterVal;
  1558. double xPosition;
  1559. if( indexedSeries )
  1560. {
  1561. // The formula for position is based on a distance
  1562. //from the grid line or nPoints position.
  1563. xPosition = hAxis.GetPosition( (double)index ) - width * ((double) numOfSeries) / 2.0 + width/2 + seriesIndx * width;
  1564. xCenterVal = hAxis.GetPosition( (double)index );
  1565. }
  1566. else if( sameInterval )
  1567. {
  1568. xPosition = hAxis.GetPosition( point.XValue ) - width * ((double) numOfSeries) / 2.0 + width/2 + seriesIndx * width;
  1569. xCenterVal = hAxis.GetPosition( point.XValue );
  1570. }
  1571. else
  1572. {
  1573. xPosition = hAxis.GetPosition( point.XValue );
  1574. xCenterVal = hAxis.GetPosition( point.XValue );
  1575. }
  1576. //************************************************************
  1577. //** Create and add new DataPoint3D object
  1578. //************************************************************
  1579. DataPoint3D pointEx = new DataPoint3D();
  1580. pointEx.indexedSeries = indexedSeries;
  1581. pointEx.dataPoint = point;
  1582. pointEx.index = index;
  1583. pointEx.xPosition = xPosition;
  1584. pointEx.xCenterVal = xCenterVal;
  1585. pointEx.width = ser.GetPointWidth(area.Common.graph, hAxis, interval, 0.8) / numOfSeries;
  1586. pointEx.depth = seriesDepth;
  1587. pointEx.zPosition = seriesZPosition;
  1588. // Set Y value and height
  1589. double yValue = chartType.GetYValue(Common, area, ser, point, index - 1, mainYValueIndex);
  1590. if (point.IsEmpty && Double.IsNaN(yValue))
  1591. {
  1592. yValue = 0.0;
  1593. }
  1594. pointEx.yPosition = vAxis.GetPosition(yValue);
  1595. pointEx.height = vAxis.GetPosition(yValue - chartType.GetYValue(Common, area, ser, point, index - 1, -1));
  1596. pointsList.Add(pointEx);
  1597. }
  1598. // Data series index
  1599. if(numOfSeries > 1 && sideBySide)
  1600. {
  1601. seriesIndx++;
  1602. }
  1603. }
  1604. //************************************************************
  1605. //** Sort points in drawing order
  1606. //************************************************************
  1607. if(comparer == null)
  1608. {
  1609. comparer = new PointsDrawingOrderComparer((ChartArea)this, selection, coord);
  1610. }
  1611. pointsList.Sort(comparer);
  1612. return pointsList;
  1613. }
  1614. #endregion
  1615. #region Points drawing order comparer class
  1616. /// <summary>
  1617. /// Used to compare points in array and sort them by drawing order.
  1618. /// </summary>
  1619. internal class PointsDrawingOrderComparer : IComparer
  1620. {
  1621. /// <summary>
  1622. /// Chart area object reference.
  1623. /// </summary>
  1624. private ChartArea _area = null;
  1625. /// <summary>
  1626. /// Area X position where visible sides are switched.
  1627. /// </summary>
  1628. private Point3D _areaProjectionCenter = new Point3D(float.NaN, float.NaN, float.NaN);
  1629. /// <summary>
  1630. /// Selection mode. Points order should be reversed.
  1631. /// </summary>
  1632. private bool _selection = false;
  1633. /// <summary>
  1634. /// Public constructor.
  1635. /// </summary>
  1636. /// <param name="area">Chart area.</param>
  1637. /// <param name="selection">Selection indicator.</param>
  1638. /// <param name="coord">Which coordinate of COP (X, Y or Z) to test for surface overlapping</param>
  1639. public PointsDrawingOrderComparer(ChartArea area, bool selection, COPCoordinates coord)
  1640. {
  1641. this._area = area;
  1642. this._selection = selection;
  1643. // Get center of projection
  1644. if(area.DrawPointsToCenter(ref coord))
  1645. {
  1646. _areaProjectionCenter = area.GetCenterOfProjection(coord);
  1647. }
  1648. }
  1649. /// <summary>
  1650. /// Comparer method.
  1651. /// </summary>
  1652. /// <param name="o1">First object.</param>
  1653. /// <param name="o2">Second object.</param>
  1654. /// <returns>Comparison result.</returns>
  1655. public int Compare(object o1, object o2)
  1656. {
  1657. DataPoint3D point1 = (DataPoint3D) o1;
  1658. DataPoint3D point2 = (DataPoint3D) o2;
  1659. int result = 0;
  1660. if(point1.xPosition < point2.xPosition)
  1661. {
  1662. result = -1;
  1663. }
  1664. else if(point1.xPosition > point2.xPosition)
  1665. {
  1666. result = 1;
  1667. }
  1668. else
  1669. {
  1670. // If X coordinate is the same - filter by Y coordinate
  1671. if(point1.yPosition < point2.yPosition)
  1672. {
  1673. result = 1;
  1674. }
  1675. else if(point1.yPosition > point2.yPosition)
  1676. {
  1677. result = -1;
  1678. }
  1679. // Order points from sides to center
  1680. if(!float.IsNaN(_areaProjectionCenter.Y))
  1681. {
  1682. double yMin1 = Math.Min(point1.yPosition, point1.height);
  1683. double yMax1 = Math.Max(point1.yPosition, point1.height);
  1684. double yMin2 = Math.Min(point2.yPosition, point2.height);
  1685. double yMax2 = Math.Max(point2.yPosition, point2.height);
  1686. if(_area.IsBottomSceneWallVisible())
  1687. {
  1688. if( yMin1 <= _areaProjectionCenter.Y && yMin2 <= _areaProjectionCenter.Y )
  1689. {
  1690. result *= -1;
  1691. }
  1692. else if( yMin1 <= _areaProjectionCenter.Y)
  1693. {
  1694. result = 1;
  1695. }
  1696. }
  1697. else
  1698. {
  1699. if( yMax1 >= _areaProjectionCenter.Y && yMax2 >= _areaProjectionCenter.Y )
  1700. {
  1701. result *= 1;
  1702. }
  1703. else if( yMax1 >= _areaProjectionCenter.Y)
  1704. {
  1705. result = 1;
  1706. }
  1707. else
  1708. {
  1709. result *= -1;
  1710. }
  1711. }
  1712. }
  1713. // Reversed order if looking from the bottom
  1714. else if(!_area.IsBottomSceneWallVisible())
  1715. {
  1716. result *= -1;
  1717. }
  1718. }
  1719. if(point1.xPosition != point2.xPosition)
  1720. {
  1721. // Order points from sides to center
  1722. if (!float.IsNaN(_areaProjectionCenter.X))
  1723. {
  1724. if ((point1.xPosition + point1.width / 2f) >= _areaProjectionCenter.X &&
  1725. (point2.xPosition + point2.width / 2f) >= _areaProjectionCenter.X)
  1726. {
  1727. result *= -1;
  1728. }
  1729. }
  1730. // Reversed order of points by X value
  1731. else if (_area.DrawPointsInReverseOrder())
  1732. {
  1733. result *= -1;
  1734. }
  1735. }
  1736. return (_selection) ? -result : result;
  1737. }
  1738. }
  1739. #endregion
  1740. #region Center of Projection calculation methods
  1741. /// <summary>
  1742. /// Returns one or many (X, Y, Z) coordinates of the center of projection.
  1743. /// </summary>
  1744. /// <param name="coord">Defines coordinates to return.</param>
  1745. /// <returns>Center of projection. Value can be set to float.NaN if not defined or outside plotting area.</returns>
  1746. internal Point3D GetCenterOfProjection(COPCoordinates coord)
  1747. {
  1748. // Define 2 points in the opposite corners of the plotting area
  1749. Point3D[] points = new Point3D[2];
  1750. points[0] = new Point3D(this.PlotAreaPosition.X, this.PlotAreaPosition.Bottom, 0f);
  1751. points[1] = new Point3D(this.PlotAreaPosition.Right, this.PlotAreaPosition.Y, this.areaSceneDepth);
  1752. // Check if surfaces (points 1 & 2) has same orientation
  1753. bool xSameOrientation, ySameOrientation, zSameOrientation;
  1754. CheckSurfaceOrientation(
  1755. coord,
  1756. points[0],
  1757. points[1],
  1758. out xSameOrientation,
  1759. out ySameOrientation,
  1760. out zSameOrientation);
  1761. // If orientation of all surfaces is the same - no futher processing is required (COP is outside of plotting area)
  1762. Point3D resultPoint = new Point3D(
  1763. (xSameOrientation) ? float.NaN : 0f,
  1764. (ySameOrientation) ? float.NaN : 0f,
  1765. (zSameOrientation) ? float.NaN : 0f);
  1766. if( ( ((coord & COPCoordinates.X) != COPCoordinates.X) || xSameOrientation ) &&
  1767. ( ((coord & COPCoordinates.Y) != COPCoordinates.Y) || ySameOrientation ) &&
  1768. ( ((coord & COPCoordinates.Z) != COPCoordinates.Z) || zSameOrientation ) )
  1769. {
  1770. return resultPoint;
  1771. }
  1772. // Calculate the smallest interval (0.5 pixels) in relative coordinates
  1773. SizeF interval = new SizeF(0.5f, 0.5f);
  1774. interval.Width = interval.Width * 100F / ((float)(this.Common.Chart.Width - 1));
  1775. interval.Height = interval.Height * 100F / ((float)(this.Common.Chart.Height - 1));
  1776. // Find middle point and check it's surface orientation
  1777. bool doneFlag = false;
  1778. while(!doneFlag)
  1779. {
  1780. // Find middle point
  1781. Point3D middlePoint = new Point3D(
  1782. (points[0].X + points[1].X) / 2f,
  1783. (points[0].Y + points[1].Y) / 2f,
  1784. (points[0].Z + points[1].Z) / 2f);
  1785. // Check if surfaces (points 1 & middle) has same orientation
  1786. CheckSurfaceOrientation(
  1787. coord,
  1788. points[0],
  1789. middlePoint,
  1790. out xSameOrientation,
  1791. out ySameOrientation,
  1792. out zSameOrientation);
  1793. // Calculate points 1 & 2 depending on surface orientation of the middle point
  1794. points[(xSameOrientation) ? 0 : 1].X = middlePoint.X;
  1795. points[(ySameOrientation) ? 0 : 1].Y = middlePoint.Y;
  1796. points[(zSameOrientation) ? 0 : 1].Z = middlePoint.Z;
  1797. // Check if no more calculations required
  1798. doneFlag = true;
  1799. if( (coord & COPCoordinates.X) == COPCoordinates.X &&
  1800. Math.Abs(points[1].X - points[0].X) >= interval.Width)
  1801. {
  1802. doneFlag = false;
  1803. }
  1804. if( (coord & COPCoordinates.Y) == COPCoordinates.Y &&
  1805. Math.Abs(points[1].Y - points[0].Y) >= interval.Height)
  1806. {
  1807. doneFlag = false;
  1808. }
  1809. if( (coord & COPCoordinates.Z) == COPCoordinates.Z &&
  1810. Math.Abs(points[1].Z - points[0].Z) >= interval.Width)
  1811. {
  1812. doneFlag = false;
  1813. }
  1814. }
  1815. // Calculate result point
  1816. if(!float.IsNaN(resultPoint.X))
  1817. resultPoint.X = (points[0].X + points[1].X) / 2f;
  1818. if(!float.IsNaN(resultPoint.Y))
  1819. resultPoint.Y = (points[0].Y + points[1].Y) / 2f;
  1820. if(!float.IsNaN(resultPoint.Z))
  1821. resultPoint.Z = (points[0].Z + points[1].Z) / 2f;
  1822. return resultPoint;
  1823. }
  1824. /// <summary>
  1825. /// Checks orientations of two normal surfaces for each coordinate X, Y and Z.
  1826. /// </summary>
  1827. /// <param name="coord">Defines coordinates to return.</param>
  1828. /// <param name="point1">First point.</param>
  1829. /// <param name="point2">Second point.</param>
  1830. /// <param name="xSameOrientation">X surfaces orientation is the same.</param>
  1831. /// <param name="ySameOrientation">Y surfaces orientation is the same.</param>
  1832. /// <param name="zSameOrientation">Z surfaces orientation is the same.</param>
  1833. private void CheckSurfaceOrientation(
  1834. COPCoordinates coord,
  1835. Point3D point1,
  1836. Point3D point2,
  1837. out bool xSameOrientation,
  1838. out bool ySameOrientation,
  1839. out bool zSameOrientation)
  1840. {
  1841. Point3D[] pointsSurface = new Point3D[3];
  1842. bool surf1, surf2;
  1843. // Initialize returned values
  1844. xSameOrientation = true;
  1845. ySameOrientation = true;
  1846. zSameOrientation = true;
  1847. // Check X axis coordinates (ledt & right surfaces)
  1848. if( (coord & COPCoordinates.X) == COPCoordinates.X )
  1849. {
  1850. // Define Left surface coordinates, transform them and check visibility
  1851. pointsSurface[0] = new Point3D(point1.X, this.PlotAreaPosition.Y, 0f);
  1852. pointsSurface[1] = new Point3D(point1.X, this.PlotAreaPosition.Bottom, 0f);
  1853. pointsSurface[2] = new Point3D(point1.X, this.PlotAreaPosition.Bottom, this.areaSceneDepth);
  1854. this.matrix3D.TransformPoints( pointsSurface );
  1855. surf1 = ChartGraphics.IsSurfaceVisible(pointsSurface[0], pointsSurface[1], pointsSurface[2]);
  1856. // Define Right surface coordinates, transform them and check visibility
  1857. pointsSurface[0] = new Point3D(point2.X, this.PlotAreaPosition.Y, 0f);
  1858. pointsSurface[1] = new Point3D(point2.X, this.PlotAreaPosition.Bottom, 0f);
  1859. pointsSurface[2] = new Point3D(point2.X, this.PlotAreaPosition.Bottom, this.areaSceneDepth);
  1860. this.matrix3D.TransformPoints( pointsSurface );
  1861. surf2 = ChartGraphics.IsSurfaceVisible(pointsSurface[0], pointsSurface[1], pointsSurface[2]);
  1862. // Check if surfaces have same visibility
  1863. xSameOrientation = (surf1 == surf2);
  1864. }
  1865. // Check Y axis coordinates (top & bottom surfaces)
  1866. if( (coord & COPCoordinates.Y) == COPCoordinates.Y )
  1867. {
  1868. // Define Bottom surface coordinates, transform them and check visibility
  1869. pointsSurface[0] = new Point3D(this.PlotAreaPosition.X, point1.Y, this.areaSceneDepth);
  1870. pointsSurface[1] = new Point3D(this.PlotAreaPosition.X, point1.Y, 0f);
  1871. pointsSurface[2] = new Point3D(this.PlotAreaPosition.Right, point1.Y, 0f);
  1872. this.matrix3D.TransformPoints( pointsSurface );
  1873. surf1 = ChartGraphics.IsSurfaceVisible(pointsSurface[0], pointsSurface[1], pointsSurface[2]);
  1874. // Define Top surface coordinates, transform them and check visibility
  1875. pointsSurface[0] = new Point3D(this.PlotAreaPosition.X, point2.Y, this.areaSceneDepth);
  1876. pointsSurface[1] = new Point3D(this.PlotAreaPosition.X, point2.Y, 0f);
  1877. pointsSurface[2] = new Point3D(this.PlotAreaPosition.Right, point2.Y, 0f);
  1878. this.matrix3D.TransformPoints( pointsSurface );
  1879. surf2 = ChartGraphics.IsSurfaceVisible(pointsSurface[0], pointsSurface[1], pointsSurface[2]);
  1880. // Check if surfaces have same visibility
  1881. ySameOrientation = (surf1 == surf2);
  1882. }
  1883. // Check Y axis coordinates (front & back surfaces)
  1884. if( (coord & COPCoordinates.Z) == COPCoordinates.Z )
  1885. {
  1886. // Define Front surface coordinates, transform them and check visibility
  1887. pointsSurface[0] = new Point3D(this.PlotAreaPosition.X, this.PlotAreaPosition.Y, point1.Z);
  1888. pointsSurface[1] = new Point3D(this.PlotAreaPosition.X, this.PlotAreaPosition.Bottom, point1.Z);
  1889. pointsSurface[2] = new Point3D(this.PlotAreaPosition.Right, this.PlotAreaPosition.Bottom, point1.Z);
  1890. this.matrix3D.TransformPoints( pointsSurface );
  1891. surf1 = ChartGraphics.IsSurfaceVisible(pointsSurface[0], pointsSurface[1], pointsSurface[2]);
  1892. // Define Back surface coordinates, transform them and check visibility
  1893. pointsSurface[0] = new Point3D(this.PlotAreaPosition.X, this.PlotAreaPosition.Y, point2.Z);
  1894. pointsSurface[1] = new Point3D(this.PlotAreaPosition.X, this.PlotAreaPosition.Bottom, point2.Z);
  1895. pointsSurface[2] = new Point3D(this.PlotAreaPosition.Right, this.PlotAreaPosition.Bottom, point2.Z);
  1896. this.matrix3D.TransformPoints( pointsSurface );
  1897. surf2 = ChartGraphics.IsSurfaceVisible(pointsSurface[0], pointsSurface[1], pointsSurface[2]);
  1898. // Check if surfaces have same visibility
  1899. zSameOrientation = (surf1 == surf2);
  1900. }
  1901. }
  1902. #endregion
  1903. }
  1904. }