123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139214021412142214321442145214621472148214921502151215221532154215521562157215821592160216121622163216421652166216721682169217021712172217321742175217621772178217921802181218221832184218521862187218821892190219121922193219421952196219721982199220022012202220322042205 |
- // Licensed to the .NET Foundation under one or more agreements.
- // The .NET Foundation licenses this file to you under the MIT license.
- // See the LICENSE file in the project root for more information.
- //
- // Purpose: ChartArea3D class represents 3D chart area. It contains
- // methods for coordinates transformation, drawing the 3D
- // scene and many 3D related helper methods.
- //
- using System;
- using System.Collections;
- using System.Collections.Generic;
- using System.ComponentModel;
- using System.Drawing;
- using FastReport.DataVisualization.Charting.ChartTypes;
- using FastReport.DataVisualization.Charting.Utilities;
- namespace FastReport.DataVisualization.Charting
- {
- #region 3D lightStyle style enumerations
- /// <summary>
- /// A lighting style for a 3D chart area.
- /// </summary>
- public enum LightStyle
- {
- /// <summary>
- /// No lighting.
- /// </summary>
- None,
- /// <summary>
- /// Simplistic lighting.
- /// </summary>
- Simplistic,
- /// <summary>
- /// Realistic lighting.
- /// </summary>
- Realistic
- }
- #endregion
- #region 3D Center of Projetion coordinates enumeration
- /// <summary>
- /// Coordinates of the Center Of Projection
- /// </summary>
- [Flags]
- internal enum COPCoordinates
- {
- /// <summary>
- /// Check X coordinate.
- /// </summary>
- X = 1,
- /// <summary>
- /// Check Y coordinate.
- /// </summary>
- Y = 2,
- /// <summary>
- /// Check Z coordinate.
- /// </summary>
- Z = 4
- }
- #endregion
- /// <summary>
- /// The ChartArea3DStyleClass class provides the functionality for 3D attributes of chart areas,
- /// such as rotation angles and perspective.
- /// </summary>
- public class ChartArea3DStyle
- {
- #region Constructor and Initialization
- /// <summary>
- /// ChartArea3DStyle constructor.
- /// </summary>
- public ChartArea3DStyle()
- {
- }
- /// <summary>
- /// ChartArea3DStyle constructor.
- /// </summary>
- public ChartArea3DStyle(ChartArea chartArea)
- {
- this._chartArea = chartArea;
- }
- /// <summary>
- /// Initialize Chart area and axes
- /// </summary>
- /// <param name="chartArea">Chart area object.</param>
- internal void Initialize(ChartArea chartArea)
- {
- this._chartArea = chartArea;
- }
- #endregion
-
- #region Fields
- // Reference to the chart area object
- private ChartArea _chartArea = null;
- // Enables/disables 3D chart types in the area.
- private bool _enable3D = false;
- // Indicates that axes are set at the right angle independent of the rotation.
- private bool _isRightAngleAxes = true;
- // Indicates that series should be drawn as isClustered.
- private bool _isClustered = false;
- // 3D area lightStyle style.
- private LightStyle _lightStyle = LightStyle.Simplistic;
- // 3D area perspective which controls the scaleView of the chart depth.
- private int _perspective = 0;
- // Chart area rotation angle around the X axis.
- private int _inclination = 30;
- // Chart area rotation angle around the Y axis.
- private int _rotation = 30;
- // Chart area walls width.
- private int _wallWidth = 7;
- // Series points depth in percentages
- private int _pointDepth = 100;
- // Series points gap depth in percentages
- private int _pointGapDepth = 100;
- #endregion
- #region Properties
- /// <summary>
- /// Gets or sets a Boolean value that toggles 3D for a chart area on and off.
- /// </summary>
- [
- SRCategory("CategoryAttribute3D"),
- Bindable(true),
- DefaultValue(false),
- SRDescription("DescriptionAttributeChartArea3DStyle_Enable3D"),
- ParenthesizePropertyNameAttribute(true)
- ]
- public bool Enable3D
- {
- get
- {
- return this._enable3D;
- }
- set
- {
- if (this._enable3D != value)
- {
- this._enable3D = value;
- if (this._chartArea != null)
- {
- #if SUBAXES
- // If one of the axes has sub axis the scales has to be recalculated
- foreach(Axis axis in this._chartArea.Axes)
- {
- if(axis.SubAxes.Count > 0)
- {
- this._chartArea.ResetAutoValues();
- break;
- }
- }
- #endif // SUBAXES
- this._chartArea.Invalidate();
- _chartArea.CallOnModifing();
- }
- }
- }
- }
- /// <summary>
- /// Gets or sets a Boolean that determines if a chart area is displayed using an isometric projection.
- /// </summary>
- [
- SRCategory("CategoryAttribute3D"),
- Bindable(true),
- DefaultValue(true),
- SRDescription("DescriptionAttributeChartArea3DStyle_RightAngleAxes"),
- RefreshPropertiesAttribute(RefreshProperties.All)
- ]
- public bool IsRightAngleAxes
- {
- get
- {
- return _isRightAngleAxes;
- }
- set
- {
- _isRightAngleAxes = value;
- // Adjust 3D properties values
- if (_isRightAngleAxes)
- {
- // Disable perspective if right angle axis are used
- this._perspective = 0;
- }
- if (this._chartArea != null)
- {
- this._chartArea.Invalidate();
- _chartArea.CallOnModifing();
- }
- }
- }
- /// <summary>
- /// Gets or sets a Boolean value that determines if bar chart or column
- /// chart data series are clustered (displayed along distinct rows).
- /// </summary>
- [
- SRCategory("CategoryAttribute3D"),
- Bindable(true),
- DefaultValue(false),
- SRDescription("DescriptionAttributeChartArea3DStyle_Clustered"),
- ]
- public bool IsClustered
- {
- get
- {
- return _isClustered;
- }
- set
- {
- _isClustered = value;
- if (this._chartArea != null)
- {
- this._chartArea.Invalidate();
- _chartArea.CallOnModifing();
- }
- }
- }
- /// <summary>
- /// Gets or sets the style of lighting for a 3D chart area.
- /// </summary>
- [
- SRCategory("CategoryAttribute3D"),
- Bindable(true),
- DefaultValue(typeof(LightStyle), "Simplistic"),
- SRDescription("DescriptionAttributeChartArea3DStyle_Light"),
- ]
- public LightStyle LightStyle
- {
- get
- {
- return _lightStyle;
- }
- set
- {
- _lightStyle = value;
- if (this._chartArea != null)
- {
- this._chartArea.Invalidate();
- _chartArea.CallOnModifing();
- }
- }
- }
- /// <summary>
- /// Gets or sets the percent of perspective for a 3D chart area.
- /// </summary>
- [
- SRCategory("CategoryAttribute3D"),
- Bindable(true),
- DefaultValue(0),
- SRDescription("DescriptionAttributeChartArea3DStyle_Perspective"),
- RefreshPropertiesAttribute(RefreshProperties.All)
- ]
- public int Perspective
- {
- get
- {
- return _perspective;
- }
- set
- {
- if(value < 0 || value > 100)
- {
- throw (new ArgumentOutOfRangeException("value", SR.ExceptionChartArea3DPerspectiveInvalid));
- }
- _perspective = value;
- // Adjust 3D properties values
- if (_perspective != 0)
- {
- // Disable right angle axes
- this._isRightAngleAxes = false;
- }
- if (this._chartArea != null)
- {
- this._chartArea.Invalidate();
- _chartArea.CallOnModifing();
- }
- }
- }
- /// <summary>
- /// Gets or sets the inclination for a 3D chart area.
- /// </summary>
- [
- SRCategory("CategoryAttribute3D"),
- Bindable(true),
- DefaultValue(30),
- SRDescription("DescriptionAttributeChartArea3DStyle_Inclination"),
- RefreshPropertiesAttribute(RefreshProperties.All)
- ]
- public int Inclination
- {
- get
- {
- return _inclination;
- }
- set
- {
- if(value < -90 || value > 90)
- {
- throw (new ArgumentOutOfRangeException("value", SR.ExceptionChartArea3DInclinationInvalid));
- }
- _inclination = value;
- if (this._chartArea != null)
- {
- this._chartArea.Invalidate();
- _chartArea.CallOnModifing();
- }
- }
- }
- /// <summary>
- /// Gets or sets the rotation angle for a 3D chart area.
- /// </summary>
- [
- SRCategory("CategoryAttribute3D"),
- Bindable(true),
- DefaultValue(30),
- SRDescription("DescriptionAttributeChartArea3DStyle_Rotation"),
- RefreshPropertiesAttribute(RefreshProperties.All)
- ]
- public int Rotation
- {
- get
- {
- return _rotation;
- }
- set
- {
- if(value < -180 || value > 180)
- {
- throw (new ArgumentOutOfRangeException("value", SR.ExceptionChartArea3DRotationInvalid));
- }
- _rotation = value;
- if (this._chartArea != null)
- {
- this._chartArea.Invalidate();
- _chartArea.CallOnModifing();
- }
- }
- }
- /// <summary>
- /// Gets or sets the width of the walls displayed in 3D chart areas.
- /// </summary>
- [
- SRCategory("CategoryAttribute3D"),
- Bindable(true),
- DefaultValue(7),
- SRDescription("DescriptionAttributeChartArea3DStyle_WallWidth"),
- RefreshPropertiesAttribute(RefreshProperties.All)
- ]
- public int WallWidth
- {
- get
- {
- return _wallWidth;
- }
- set
- {
- if(value < 0 || value > 30)
- {
- throw (new ArgumentOutOfRangeException("value", SR.ExceptionChartArea3DWallWidthInvalid));
- }
- _wallWidth = value;
- if (this._chartArea != null)
- {
- this._chartArea.Invalidate();
- _chartArea.CallOnModifing();
- }
- }
- }
- /// <summary>
- /// Gets or sets the depth of data points displayed in 3D chart areas (0-1000%).
- /// </summary>
- [
- SRCategory("CategoryAttribute3D"),
- Bindable(true),
- DefaultValue(100),
- SRDescription("DescriptionAttributeChartArea3DStyle_PointDepth"),
- RefreshPropertiesAttribute(RefreshProperties.All)
- ]
- public int PointDepth
- {
- get
- {
- return _pointDepth;
- }
- set
- {
- if(value < 0 || value > 1000)
- {
- throw (new ArgumentOutOfRangeException("value", SR.ExceptionChartArea3DPointsDepthInvalid));
- }
- _pointDepth = value;
- if (this._chartArea != null)
- {
- this._chartArea.Invalidate();
- _chartArea.CallOnModifing();
- }
- }
- }
- /// <summary>
- /// Gets or sets the distance between series rows in 3D chart areas (0-1000%).
- /// </summary>
- [
- SRCategory("CategoryAttribute3D"),
- Bindable(true),
- DefaultValue(100),
- SRDescription("DescriptionAttributeChartArea3DStyle_PointGapDepth"),
- RefreshPropertiesAttribute(RefreshProperties.All)
- ]
- public int PointGapDepth
- {
- get
- {
- return _pointGapDepth;
- }
- set
- {
- if(value < 0 || value > 1000)
- {
- throw (new ArgumentOutOfRangeException("value", SR.ExceptionChartArea3DPointsGapInvalid));
- }
- _pointGapDepth = value;
- if (this._chartArea != null)
- {
- this._chartArea.Invalidate();
- _chartArea.CallOnModifing();
- }
- }
- }
- #endregion
- }
- /// <summary>
- /// ChartArea3D class represents 3D chart area. It contains all the 3D
- /// scene settings and methods for drawing the 3D plotting area, and calculating
- /// the depth of chart elements.
- /// </summary>
- public partial class ChartArea
- {
- #region Fields
- // Chart area 3D style attribuytes
- private ChartArea3DStyle _area3DStyle = new ChartArea3DStyle();
- // Coordinate convertion matrix
- internal Matrix3D matrix3D = new Matrix3D();
- // Chart area scene wall width in relative coordinates
- internal SizeF areaSceneWallWidth = SizeF.Empty;
- // Chart area scene depth
- internal float areaSceneDepth = 0;
- // Visible surfaces in plotting area
- private SurfaceNames _visibleSurfaces;
- // Z axis depth of series points
- private double _pointsDepth = 0;
- // Z axis depth of the gap between isClustered series
- private double _pointsGapDepth = 0;
- /// <summary>
- /// Indicates that series order should be reversed to simulate Y axis rotation.
- /// </summary>
- private bool _reverseSeriesOrder = false;
- /// <summary>
- /// Old X axis reversed flag
- /// </summary>
- internal bool oldReverseX = false;
- /// <summary>
- /// Old Y axis reversed flag
- /// </summary>
- internal bool oldReverseY = false;
- /// <summary>
- /// Old Y axis rotation angle
- /// </summary>
- internal int oldYAngle = 30;
- /// <summary>
- /// List of all stack group names
- /// </summary>
- private ArrayList _stackGroupNames = null;
- /// <summary>
- /// This list contains an array of series names for each 3D cluster
- /// </summary>
- internal List<List<string>> seriesClusters = null;
- #endregion
- #region 3D Style properties
- /// <summary>
- /// Gets or sets a ChartArea3DStyle object, used to draw all series in a chart area in 3D.
- /// </summary>
- [
- SRCategory("CategoryAttribute3D"),
- Bindable(true),
- DefaultValue(null),
- SRDescription("DescriptionAttributeArea3DStyle"),
- DesignerSerializationVisibility(DesignerSerializationVisibility.Content),
- TypeConverter(typeof(NoNameExpandableObjectConverter)),
- ]
- public ChartArea3DStyle Area3DStyle
- {
- get
- {
- return _area3DStyle;
- }
- set
- {
- _area3DStyle = value;
- // Initialize style object
- _area3DStyle.Initialize((ChartArea)this);
- CallOnModifing();
- }
- }
- /// <summary>
- /// Indicates that series order should be reversed to simulate Y axis rotation.
- /// </summary>
- internal bool ReverseSeriesOrder
- {
- get { return _reverseSeriesOrder; }
- }
- /// <summary>
- /// Gets the list of all stack group names
- /// </summary>
- internal ArrayList StackGroupNames
- {
- get { return _stackGroupNames; }
- }
- #endregion
- #region 3D Coordinates transfotmation methods
- /// <summary>
- /// Call this method to apply 3D transformations on an array of 3D points (must be done before calling GDI+ drawing methods).
- /// </summary>
- /// <param name="points">3D Points array.</param>
- public void TransformPoints( Point3D[] points )
- {
- // Convert Z coordinates from 0-100% to axis values
- foreach(Point3D pt in points)
- {
- pt.Z = (pt.Z / 100f) * this.areaSceneDepth;
- }
- // Transform points
- this.matrix3D.TransformPoints( points );
- }
- #endregion
- #region 3D Scene drawing methods
-
- /// <summary>
- /// Draws chart area 3D scene, which consists of 3 or 2 walls.
- /// </summary>
- /// <param name="graph">Chart graphics object.</param>
- /// <param name="position">Chart area 2D position.</param>
- internal void DrawArea3DScene(ChartGraphics graph, RectangleF position)
- {
- // Reference to the chart area class
- ChartArea chartArea = (ChartArea)this;
- // Calculate relative size of the wall
- areaSceneWallWidth = graph.GetRelativeSize( new SizeF(this.Area3DStyle.WallWidth, this.Area3DStyle.WallWidth));
- //***********************************************************
- //** Calculate the depth of the chart area scene
- //***********************************************************
- areaSceneDepth = GetArea3DSceneDepth();
- //***********************************************************
- //** Initialize coordinate transformation matrix
- //***********************************************************
- this.matrix3D.Initialize(
- position,
- areaSceneDepth,
- this.Area3DStyle.Inclination,
- this.Area3DStyle.Rotation,
- this.Area3DStyle.Perspective,
- this.Area3DStyle.IsRightAngleAxes);
- //***********************************************************
- //** Initialize Lighting
- //***********************************************************
- this.matrix3D.InitLight(
- this.Area3DStyle.LightStyle
- );
- //***********************************************************
- //** Find chart area visible surfaces
- //***********************************************************
- _visibleSurfaces = graph.GetVisibleSurfaces(
- position,
- 0,
- areaSceneDepth,
- this.matrix3D);
- //***********************************************************
- //** Chech if area scene should be drawn
- //***********************************************************
- Color sceneBackColor = chartArea.BackColor;
- // Do not draw the transparent walls
- if(sceneBackColor == Color.Transparent)
- {
- // Area wall is not visible
- areaSceneWallWidth = SizeF.Empty;
- return;
- }
- // If color is not set (default) - use LightGray
- if(sceneBackColor == Color.Empty)
- {
- sceneBackColor = Color.LightGray;
- }
- //***********************************************************
- //** Adjust scene 2D rectangle so that wall are drawn
- //** outside plotting area.
- //***********************************************************
- // If bottom wall is visible
- if(IsBottomSceneWallVisible())
- {
- position.Height += areaSceneWallWidth.Height;
- }
- // Adjust for the left/right wall
- position.Width += areaSceneWallWidth.Width;
- if(this.Area3DStyle.Rotation > 0)
- {
- position.X -= areaSceneWallWidth.Width;
- }
- //***********************************************************
- //** Draw scene walls
- //***********************************************************
- // Draw back wall
- RectangleF wallRect2D = new RectangleF(position.Location, position.Size);
- float wallDepth = areaSceneWallWidth.Width;
- float wallZPosition = -wallDepth;
- // For isometric projection Front wall should be visible sometimes
- if( IsMainSceneWallOnFront())
- {
- wallZPosition = areaSceneDepth;
- }
- graph.Fill3DRectangle(
- wallRect2D,
- wallZPosition,
- wallDepth,
- this.matrix3D,
- chartArea.Area3DStyle.LightStyle,
- sceneBackColor,
- chartArea.BorderColor,
- chartArea.BorderWidth,
- chartArea.BorderDashStyle,
- DrawingOperationTypes.DrawElement );
- // Draw side wall on the left or right side
- wallRect2D = new RectangleF(position.Location, position.Size);
- wallRect2D.Width = areaSceneWallWidth.Width;
- if(!IsSideSceneWallOnLeft())
- {
- // Wall is on the right side
- wallRect2D.X = position.Right - areaSceneWallWidth.Width;
- }
- graph.Fill3DRectangle(
- wallRect2D,
- 0f,
- areaSceneDepth,
- this.matrix3D,
- chartArea.Area3DStyle.LightStyle,
- sceneBackColor,
- chartArea.BorderColor,
- chartArea.BorderWidth,
- chartArea.BorderDashStyle,
- DrawingOperationTypes.DrawElement);
- // Draw bottom wall
- if(IsBottomSceneWallVisible())
- {
- wallRect2D = new RectangleF(position.Location, position.Size);
- wallRect2D.Height = areaSceneWallWidth.Height;
- wallRect2D.Y = position.Bottom - areaSceneWallWidth.Height;
- wallRect2D.Width -= areaSceneWallWidth.Width;
- if(IsSideSceneWallOnLeft())
- {
- wallRect2D.X += areaSceneWallWidth.Width;
- }
- wallZPosition = 0;
- graph.Fill3DRectangle(
- wallRect2D,
- 0f,
- areaSceneDepth,
- this.matrix3D,
- chartArea.Area3DStyle.LightStyle,
- sceneBackColor,
- chartArea.BorderColor,
- chartArea.BorderWidth,
- chartArea.BorderDashStyle,
- DrawingOperationTypes.DrawElement );
- }
- }
- /// <summary>
- /// Helper method which return True if bottom wall of the
- /// chart area scene is visible.
- /// </summary>
- /// <returns>True if bottom wall is visible.</returns>
- internal bool IsBottomSceneWallVisible()
- {
- return (this.Area3DStyle.Inclination >= 0);
- }
- /// <summary>
- /// Helper method which return True if main wall of the
- /// chart area scene is displayed on the front side.
- /// </summary>
- /// <returns>True if front wall is visible.</returns>
- internal bool IsMainSceneWallOnFront()
- {
- // Note: Not used in this version!
- return false;
- }
- /// <summary>
- /// Helper method which return True if side wall of the
- /// chart area scene is displayed on the left side.
- /// </summary>
- /// <returns>True if bottom wall is visible.</returns>
- internal bool IsSideSceneWallOnLeft()
- {
- return (this.Area3DStyle.Rotation > 0);
- }
- #endregion
- #region 3D Scene depth claculation methods
- /// <summary>
- /// Call this method to get the Z position of a series (useful for custom drawing).
- /// </summary>
- /// <param name="series">The series to retrieve the Z position for.</param>
- /// <returns>The Z position of the specified series. Measured as a percentage of the chart area's depth.</returns>
- public float GetSeriesZPosition(Series series)
- {
- float positionZ, depth;
- GetSeriesZPositionAndDepth(series, out depth, out positionZ);
- return ((positionZ + depth/2f) / this.areaSceneDepth) * 100f;
- }
- /// <summary>
- /// Call this method to get the depth of a series in a chart area.
- /// </summary>
- /// <param name="series">The series to retrieve the depth for.</param>
- /// <returns>The depth of the specified series. Measured as a percentage of the chart area's depth.</returns>
- public float GetSeriesDepth(Series series)
- {
- float positionZ, depth;
- GetSeriesZPositionAndDepth(series, out depth, out positionZ);
- return (depth / this.areaSceneDepth) * 100f;
- }
- /// <summary>
- /// Calculates area 3D scene depth depending on the number of isClustered
- /// series and interval between points.
- /// </summary>
- /// <returns>Returns the depth of the chart area scene.</returns>
- private float GetArea3DSceneDepth()
- {
- //***********************************************************
- //** Calculate the smallest interval between points
- //***********************************************************
- // Check if any series attached to the area is indexed
- bool indexedSeries = ChartHelper.IndexedSeries(this.Common, this._series.ToArray());
- // Smallest interval series
- Series smallestIntervalSeries = null;
- if(this._series.Count > 0)
- {
- smallestIntervalSeries = this.Common.DataManager.Series[(string)this._series[0]];
- }
- // Get X axis
- Axis xAxis = ((ChartArea)this).AxisX;
- if(this._series.Count > 0)
- {
- Series firstSeries = this.Common.DataManager.Series[this._series[0]];
- if(firstSeries != null && firstSeries.XAxisType == AxisType.Secondary)
- {
- xAxis = ((ChartArea)this).AxisX2;
- }
- }
- // Get smallest interval between points (use interval 1 for indexed series)
- double clusteredInterval = 1;
- if(!indexedSeries)
- {
- bool sameInterval;
- clusteredInterval = this.GetPointsInterval(this._series, xAxis.IsLogarithmic, xAxis.logarithmBase, false, out sameInterval, out smallestIntervalSeries);
- }
- //***********************************************************
- //** Check if "DrawSideBySide" attribute is set.
- //***********************************************************
- bool drawSideBySide = false;
- if(smallestIntervalSeries != null)
- {
- drawSideBySide = Common.ChartTypeRegistry.GetChartType(smallestIntervalSeries.ChartTypeName).SideBySideSeries;
- foreach(string seriesName in this._series)
- {
- if(this.Common.DataManager.Series[seriesName].IsCustomPropertySet(CustomPropertyName.DrawSideBySide))
- {
- string attribValue = this.Common.DataManager.Series[seriesName][CustomPropertyName.DrawSideBySide];
- if(String.Compare(attribValue, "False", StringComparison.OrdinalIgnoreCase) == 0)
- {
- drawSideBySide = false;
- }
- else if(String.Compare(attribValue, "True", StringComparison.OrdinalIgnoreCase) == 0)
- {
- drawSideBySide = true;
- }
- else if (String.Compare(attribValue, "Auto", StringComparison.OrdinalIgnoreCase) == 0)
- {
- // Do nothing
- }
- else
- {
- throw (new InvalidOperationException(SR.ExceptionAttributeDrawSideBySideInvalid));
- }
- }
- }
- }
- // Get smallest interval categorical axis
- Axis categoricalAxis = ((ChartArea)this).AxisX;
- if(smallestIntervalSeries != null && smallestIntervalSeries.XAxisType == AxisType.Secondary)
- {
- categoricalAxis = ((ChartArea)this).AxisX2;
- }
- //***********************************************************
- //** If series with the smallest interval is displayed
- //** side-by-side - devide the interval by number of series
- //** of the same chart type.
- //***********************************************************
- double pointWidthSize = 0.8;
- int seriesNumber = 1;
- if(smallestIntervalSeries != null)
- {
- // Check if series is side-by-side
- if(this.Area3DStyle.IsClustered && drawSideBySide)
- {
- // Count number of side-by-side series
- seriesNumber = 0;
- foreach(string seriesName in this._series)
- {
- // Get series object from name
- Series curSeries = this.Common.DataManager.Series[seriesName];
- if(String.Compare(curSeries.ChartTypeName, smallestIntervalSeries.ChartTypeName, StringComparison.OrdinalIgnoreCase) == 0 )
- {
- ++seriesNumber;
- }
- }
- }
- }
- //***********************************************************
- //** Stacked column and bar charts can be drawn side-by-side
- //** using the StackGroupName custom properties. The code
- //** checks if multiple groups are used how many of these
- //** groups exsist.
- //**
- //** If isClustered mode enabled each stack group is drawn
- //** using it's own cluster.
- //***********************************************************
- if(smallestIntervalSeries != null && this.Area3DStyle.IsClustered)
- {
- // Check series support stack groups
- if(Common.ChartTypeRegistry.GetChartType(smallestIntervalSeries.ChartTypeName).SupportStackedGroups)
- {
- // Calculate how many stack groups exsist
- seriesNumber = 0;
- ArrayList stackGroupNames = new ArrayList();
- foreach(string seriesName in this._series)
- {
- // Get series object from name
- Series curSeries = this.Common.DataManager.Series[seriesName];
- if(String.Compare(curSeries.ChartTypeName, smallestIntervalSeries.ChartTypeName, StringComparison.OrdinalIgnoreCase) == 0 )
- {
- string seriesStackGroupName = string.Empty;
- if(curSeries.IsCustomPropertySet(CustomPropertyName.StackedGroupName))
- {
- seriesStackGroupName = curSeries[CustomPropertyName.StackedGroupName];
- }
- // Add group name if it do not already exsist
- if(!stackGroupNames.Contains(seriesStackGroupName))
- {
- stackGroupNames.Add(seriesStackGroupName);
- }
- }
- }
- seriesNumber = stackGroupNames.Count;
- }
- }
- //***********************************************************
- //** Check if series provide custom value for point\gap depth
- //***********************************************************
- _pointsDepth = clusteredInterval * pointWidthSize * this.Area3DStyle.PointDepth / 100.0;
- _pointsDepth = categoricalAxis.GetPixelInterval(_pointsDepth);
- if(smallestIntervalSeries != null)
- {
- _pointsDepth = smallestIntervalSeries.GetPointWidth(
- this.Common.graph,
- categoricalAxis,
- clusteredInterval,
- 0.8) / seriesNumber;
- _pointsDepth *= this.Area3DStyle.PointDepth / 100.0;
- }
- _pointsGapDepth = (_pointsDepth * 0.8) * this.Area3DStyle.PointGapDepth / 100.0;
- // Get point depth and gap from series
- if(smallestIntervalSeries != null)
- {
- smallestIntervalSeries.GetPointDepthAndGap(
- this.Common.graph,
- categoricalAxis,
- ref _pointsDepth,
- ref _pointsGapDepth);
- }
- //***********************************************************
- //** Calculate scene depth
- //***********************************************************
- return (float)((_pointsGapDepth + _pointsDepth) * GetNumberOfClusters());
- }
- /// <summary>
- /// Calculates the depth and Z position for specified series.
- /// </summary>
- /// <param name="series">Series object.</param>
- /// <param name="depth">Returns series depth.</param>
- /// <param name="positionZ">Returns series Z position.</param>
- internal void GetSeriesZPositionAndDepth(Series series, out float depth, out float positionZ)
- {
- // Check arguments
- if (series == null)
- throw new ArgumentNullException("series");
- // Get series cluster index
- int seriesIndex = GetSeriesClusterIndex(series);
- // Initialize the output parameters
- depth = (float)_pointsDepth;
- positionZ = (float)(_pointsGapDepth / 2.0 + (_pointsDepth + _pointsGapDepth) * seriesIndex);
- }
- /// <summary>
- /// Returns number of clusters on the Z axis.
- /// </summary>
- /// <returns>Number of clusters on the Z axis.</returns>
- internal int GetNumberOfClusters()
- {
- if(this.seriesClusters == null)
- {
- // Lists that hold processed chart types and stacked groups
- ArrayList processedChartTypes = new ArrayList();
- ArrayList processedStackedGroups = new ArrayList();
- // Reset series cluster list
- this.seriesClusters = new List<List<string>>();
-
- // Iterate through all series that belong to this chart area
- int clusterIndex = -1;
- foreach(string seriesName in this._series)
- {
- // Get series object by name
- Series curSeries = this.Common.DataManager.Series[seriesName];
- // Check if stacked chart type is using multiple groups that
- // can be displayed in individual clusters
- if(!this.Area3DStyle.IsClustered &&
- Common.ChartTypeRegistry.GetChartType(curSeries.ChartTypeName).SupportStackedGroups)
- {
- // Get group name
- string stackGroupName = StackedColumnChart.GetSeriesStackGroupName(curSeries);
- // Check if group was already counted
- if(processedStackedGroups.Contains(stackGroupName))
- {
- // Find in which cluster this stacked group is located
- bool found = false;
- for(int index = 0; !found && index < this.seriesClusters.Count; index++)
- {
- foreach(string name in this.seriesClusters[index])
- {
- // Get series object by name
- Series ser = this.Common.DataManager.Series[name];
- if(stackGroupName == StackedColumnChart.GetSeriesStackGroupName(ser))
- {
- clusterIndex = index;
- found = true;
- }
- }
- }
- }
- else
- {
- // Increase cluster index
- clusterIndex = this.seriesClusters.Count;
- // Add processed group name
- processedStackedGroups.Add(stackGroupName);
- }
- }
- // Chech if series is displayed in the same cluster than other series
- else if( Common.ChartTypeRegistry.GetChartType(curSeries.ChartTypeName).Stacked ||
- (this.Area3DStyle.IsClustered && Common.ChartTypeRegistry.GetChartType(curSeries.ChartTypeName).SideBySideSeries) )
- {
- // Check if this chart type is already in the list
- if(processedChartTypes.Contains(curSeries.ChartTypeName.ToUpper(System.Globalization.CultureInfo.InvariantCulture)))
- {
- // Find in which cluster this chart type is located
- bool found = false;
- for(int index = 0; !found && index < this.seriesClusters.Count; index++)
- {
- foreach(string name in this.seriesClusters[index])
- {
- // Get series object by name
- Series ser = this.Common.DataManager.Series[name];
- if(ser.ChartTypeName.ToUpper(System.Globalization.CultureInfo.InvariantCulture) ==
- curSeries.ChartTypeName.ToUpper(System.Globalization.CultureInfo.InvariantCulture))
- {
- clusterIndex = index;
- found = true;
- }
- }
- }
- }
- else
- {
- // Increase cluster index
- clusterIndex = this.seriesClusters.Count;
- // Add new chart type into the collection
- processedChartTypes.Add(curSeries.ChartTypeName.ToUpper(System.Globalization.CultureInfo.InvariantCulture));
- }
- }
- else
- {
- // Create New cluster
- clusterIndex = this.seriesClusters.Count;
- }
- // Create an item in the cluster list that will hold all series names
- if(this.seriesClusters.Count <= clusterIndex)
- {
- this.seriesClusters.Add(new List<string>());
- }
- // Add series name into the current cluster
- this.seriesClusters[clusterIndex].Add(seriesName);
- }
- }
-
- return this.seriesClusters.Count;
- }
- /// <summary>
- /// Get series cluster index.
- /// </summary>
- /// <param name="series">Series object.</param>
- /// <returns>Series cluster index.</returns>
- internal int GetSeriesClusterIndex(Series series)
- {
- // Fill list of clusters
- if(this.seriesClusters == null)
- {
- this.GetNumberOfClusters();
- }
- // Iterate through all clusters
- for(int clusterIndex = 0; clusterIndex < this.seriesClusters.Count; clusterIndex++)
- {
- List<string> seriesNames = this.seriesClusters[clusterIndex];
- // Iterate through all series names
- foreach(string seriesName in seriesNames)
- {
- if(seriesName == series.Name)
- {
- // Check if series are drawn in reversed order
- if(this._reverseSeriesOrder)
- {
- clusterIndex = (this.seriesClusters.Count - 1) - clusterIndex;
- }
- return clusterIndex;
- }
- }
- }
- return 0;
- }
- #endregion
- #region 3D Scene helper methods
- /// <summary>
- /// This method is used to calculate estimated scene
- /// depth. Regular scene depth method can not be used
- /// because Plot area position is zero. Instead, Chart
- /// area position is used to find depth of the scene.
- /// Algorithm which draws axis labels will decide what
- /// should be size and position of plotting area.
- /// </summary>
- /// <returns>Returns estimated scene depth</returns>
- private float GetEstimatedSceneDepth()
- {
- float sceneDepth;
- ChartArea area = (ChartArea) this;
- // Reset current list of clusters
- this.seriesClusters = null;
- ElementPosition plottingAreaRect = area.InnerPlotPosition;
- area.AxisX.PlotAreaPosition = area.Position;
- area.AxisY.PlotAreaPosition = area.Position;
- area.AxisX2.PlotAreaPosition = area.Position;
- area.AxisY2.PlotAreaPosition = area.Position;
- sceneDepth = GetArea3DSceneDepth();
- area.AxisX.PlotAreaPosition = plottingAreaRect;
- area.AxisY.PlotAreaPosition = plottingAreaRect;
- area.AxisX2.PlotAreaPosition = plottingAreaRect;
- area.AxisY2.PlotAreaPosition = plottingAreaRect;
- return sceneDepth;
- }
- /// <summary>
- /// Estimate Interval for 3D Charts. When scene is rotated the
- /// number of labels should be changed.
- /// </summary>
- /// <param name="graph">Chart graphics object.</param>
- internal void Estimate3DInterval(ChartGraphics graph )
- {
- // Reference to the chart area class
- ChartArea area = (ChartArea)this;
- // Calculate relative size of the wall
- areaSceneWallWidth = graph.GetRelativeSize( new SizeF(this.Area3DStyle.WallWidth, this.Area3DStyle.WallWidth));
-
- //***********************************************************
- //** Calculate the depth of the chart area scene
- //***********************************************************
- areaSceneDepth = GetEstimatedSceneDepth();
- RectangleF plottingRect = area.Position.ToRectangleF();
- // Check if plot area position was recalculated.
- // If not and non-auto InnerPlotPosition & Position were
- // specified - do all needed calculations
- if(PlotAreaPosition.Width == 0 &&
- PlotAreaPosition.Height == 0 &&
- !area.InnerPlotPosition.Auto
- && !area.Position.Auto)
- {
- // Initialize plotting area position
-
- if(!area.InnerPlotPosition.Auto)
- {
- plottingRect.X += (area.Position.Width / 100F) * area.InnerPlotPosition.X;
- plottingRect.Y += (area.Position.Height / 100F) * area.InnerPlotPosition.Y;
- plottingRect.Width = (area.Position.Width / 100F) * area.InnerPlotPosition.Width;
- plottingRect.Height = (area.Position.Height / 100F) * area.InnerPlotPosition.Height;
- }
- }
- int yAngle = GetRealYAngle( );
-
- //***********************************************************
- //** Initialize coordinate transformation matrix
- //***********************************************************
- Matrix3D intervalMatrix3D = new Matrix3D();
- intervalMatrix3D.Initialize(
- plottingRect,
- areaSceneDepth,
- this.Area3DStyle.Inclination,
- yAngle,
- this.Area3DStyle.Perspective,
- this.Area3DStyle.IsRightAngleAxes);
- bool notUsed;
- float zPosition;
- double size;
-
- Point3D [] points = new Point3D[8];
-
- if( area.switchValueAxes )
- {
-
- // X Axis
- zPosition = axisX.GetMarksZPosition( out notUsed );
-
- points[0] = new Point3D( plottingRect.X, plottingRect.Y, zPosition );
- points[1] = new Point3D( plottingRect.X, plottingRect.Bottom, zPosition );
- // Y Axis
- zPosition = axisY.GetMarksZPosition( out notUsed );
- points[2] = new Point3D( plottingRect.X, plottingRect.Bottom, zPosition );
- points[3] = new Point3D( plottingRect.Right, plottingRect.Bottom, zPosition );
- // X2 Axis
- zPosition = axisX2.GetMarksZPosition( out notUsed );
-
- points[4] = new Point3D( plottingRect.X, plottingRect.Y, zPosition );
- points[5] = new Point3D( plottingRect.X, plottingRect.Bottom, zPosition );
- // Y2 Axis
- zPosition = axisY2.GetMarksZPosition( out notUsed );
- points[6] = new Point3D( plottingRect.X, plottingRect.Y, zPosition );
- points[7] = new Point3D( plottingRect.Right, plottingRect.Y, zPosition );
- }
- else
- {
- // X Axis
- zPosition = axisX.GetMarksZPosition( out notUsed );
-
- points[0] = new Point3D( plottingRect.X, plottingRect.Bottom, zPosition );
- points[1] = new Point3D( plottingRect.Right, plottingRect.Bottom, zPosition );
- // Y Axis
- zPosition = axisY.GetMarksZPosition( out notUsed );
- points[2] = new Point3D( plottingRect.X, plottingRect.Y, zPosition );
- points[3] = new Point3D( plottingRect.X, plottingRect.Bottom, zPosition );
- // X2 Axis
- zPosition = axisX2.GetMarksZPosition( out notUsed );
-
- points[4] = new Point3D( plottingRect.X, plottingRect.Y, zPosition );
- points[5] = new Point3D( plottingRect.Right, plottingRect.Y, zPosition );
- // Y2 Axis
- zPosition = axisY2.GetMarksZPosition( out notUsed );
- points[6] = new Point3D( plottingRect.X, plottingRect.Y, zPosition );
- points[7] = new Point3D( plottingRect.X, plottingRect.Bottom, zPosition );
- }
- // Crossing has to be reset because interval and
- // sometimes minimum and maximum are changed.
- foreach( Axis axis in area.Axes )
- {
- axis.crossing = axis.tempCrossing;
- }
- // Transform all points
- intervalMatrix3D.TransformPoints( points );
- int axisIndx = 0;
- foreach( Axis axis in area.Axes )
- {
- // Find size of projected axis
- size = Math.Sqrt(
- ( points[axisIndx].X - points[axisIndx+1].X ) * ( points[axisIndx].X - points[axisIndx+1].X ) +
- ( points[axisIndx].Y - points[axisIndx+1].Y ) * ( points[axisIndx].Y - points[axisIndx+1].Y ) );
- // At the beginning plotting area chart is not calculated because
- // algorithm for labels calculates plotting area position. To
- // calculate labels position we need interval and interval
- // need this correction. Because of that Chart area is used
- // instead of plotting area position. If secondary label is
- // enabled error for using chart area position instead of
- // plotting area position is much bigger. This value
- // corrects this error.
- float plottingChartAreaCorrection = 1;
- if( !area.switchValueAxes )
- {
- plottingChartAreaCorrection = 0.5F;
- }
- // Set correction for axis size
- if( axis.AxisName == AxisName.X || axis.AxisName == AxisName.X2 )
- {
- if( area.switchValueAxes )
- axis.interval3DCorrection = size / plottingRect.Height;
- else
- axis.interval3DCorrection = size / plottingRect.Width;
- }
- else
- {
- if( area.switchValueAxes )
- axis.interval3DCorrection = size / plottingRect.Width;
- else
- axis.interval3DCorrection = size / plottingRect.Height * plottingChartAreaCorrection;
- }
- // There is a limit for correction
- if( axis.interval3DCorrection < 0.15 )
- axis.interval3DCorrection = 0.15;
- // There is a limit for correction
- if( axis.interval3DCorrection > 0.8 )
- axis.interval3DCorrection = 1.0;
- axisIndx += 2;
- }
- }
- /// <summary>
- /// Calculates real Y angle from Y angle and reverseSeriesOrder field
- /// </summary>
- /// <returns>Real Y angle</returns>
- internal int GetRealYAngle( )
- {
- int yAngle;
- // Case from -90 to 90
- yAngle = this.Area3DStyle.Rotation;
- // Case from 90 to 180
- if( this._reverseSeriesOrder && this.Area3DStyle.Rotation >= 0 )
- yAngle = this.Area3DStyle.Rotation - 180;
- // Case from -90 to -180
- if( this._reverseSeriesOrder && this.Area3DStyle.Rotation <= 0 )
- yAngle = this.Area3DStyle.Rotation + 180;
- return yAngle;
- }
- /// <summary>
- /// Check if surface element should be drawn on the Back or Front layer.
- /// </summary>
- /// <param name="surfaceName">Surface name.</param>
- /// <param name="backLayer">Back/front layer.</param>
- /// <param name="onEdge">Indicates that element is on the edge (drawn on the back layer).</param>
- /// <returns>True if element should be drawn.</returns>
- internal bool ShouldDrawOnSurface(SurfaceNames surfaceName, bool backLayer, bool onEdge)
- {
- // Check if surface element should be drawn on the Back or Front layer.
- bool isVisible = ((this._visibleSurfaces & surfaceName) == surfaceName);
- // Elements on the edge are drawn on the back layer
- if(onEdge)
- {
- return backLayer;
- }
- return (backLayer == (!isVisible) );
- }
- /// <summary>
- /// Indicates that data points in all series of this
- /// chart area should be drawn in reversed order.
- /// </summary>
- /// <returns>True if series points should be drawn in reversed order.</returns>
- internal bool DrawPointsInReverseOrder()
- {
- return (this.Area3DStyle.Rotation <= 0);
- }
- /// <summary>
- /// Checks if points should be drawn from sides to center.
- /// </summary>
- /// <param name="coord">Which coordinate of COP (X, Y or Z) to test for surface overlapping</param>
- /// <returns>True if points should be drawn from sides to center.</returns>
- internal bool DrawPointsToCenter(ref COPCoordinates coord)
- {
- bool result = false;
- COPCoordinates resultCoordinates = 0;
- // Check only if perspective is set
- if(this.Area3DStyle.Perspective != 0)
- {
- if( (coord & COPCoordinates.X) == COPCoordinates.X )
- {
- // Only when Left & Right sides of plotting area are invisible
- if ((this._visibleSurfaces & SurfaceNames.Left) == 0 &&
- (this._visibleSurfaces & SurfaceNames.Right) == 0)
- {
- result = true;
- }
- resultCoordinates = resultCoordinates | COPCoordinates.X;
- }
- if( (coord & COPCoordinates.Y) == COPCoordinates.Y )
- {
- // Only when Top & Bottom sides of plotting area are invisible
- if ((this._visibleSurfaces & SurfaceNames.Top) == 0 &&
- (this._visibleSurfaces & SurfaceNames.Bottom) == 0)
- {
- result = true;
- }
- resultCoordinates = resultCoordinates | COPCoordinates.Y;
- }
- if( (coord & COPCoordinates.Z) == COPCoordinates.Z )
- {
- // Only when Front & Back sides of plotting area are invisible
- if ((this._visibleSurfaces & SurfaceNames.Front) == 0 &&
- (this._visibleSurfaces & SurfaceNames.Back) == 0)
- {
- result = true;
- }
- resultCoordinates = resultCoordinates | COPCoordinates.Z;
- }
- }
- return result;
- }
- /// <summary>
- /// Checks if series should be drawn from sides to center.
- /// </summary>
- /// <returns>True if series should be drawn from sides to center.</returns>
- internal bool DrawSeriesToCenter()
- {
- // Check only if perspective is set
- if(this.Area3DStyle.Perspective != 0)
- {
- // Only when Left & Right sides of plotting area are invisible
- if ((this._visibleSurfaces & SurfaceNames.Front) == 0 &&
- (this._visibleSurfaces & SurfaceNames.Back) == 0)
- {
- return true;
- }
- }
- return false;
- }
- #endregion
- #region 3D Series drawing and selection methods
- /// <summary>
- /// Draws 3D series in the chart area.
- /// </summary>
- /// <param name="graph">Chart graphics object.</param>
- internal void PaintChartSeries3D( ChartGraphics graph )
- {
- // Reference to the chart area object
- ChartArea area = (ChartArea)this;
- // Get order of series drawing
- List<Series> seriesDrawingOrder = GetSeriesDrawingOrder(_reverseSeriesOrder);
- // Loop through all series in the order of drawing
- IChartType type;
- foreach( object seriesObj in seriesDrawingOrder)
- {
- Series series = (Series)seriesObj;
- type = Common.ChartTypeRegistry.GetChartType(series.ChartTypeName);
- type.Paint( graph, Common, area, series );
- }
- }
- #endregion
- #region 3D Series & Points drawing order methods
-
- /// <summary>
- /// Gets a list of series names that belong to the same 3D cluster.
- /// </summary>
- /// <param name="seriesName">One of the series names that belongs to the cluster.</param>
- /// <returns>List of all series names that belong to the same cluster as specified series.</returns>
- internal List<string> GetClusterSeriesNames(string seriesName)
- {
- // Iterate through all clusters
- foreach(List<string> seriesNames in this.seriesClusters)
- {
- if(seriesNames.Contains(seriesName))
- {
- return seriesNames;
- }
- }
- return new List<string>();
- }
- /// <summary>
- /// Gets the series list in drawing order.
- /// </summary>
- /// <param name="reverseSeriesOrder">Series order should be reversed because of the Y axis angle.</param>
- /// <returns>Gets the series list in drawing order.</returns>
- private List<Series> GetSeriesDrawingOrder(bool reverseSeriesOrder)
- {
- // Create list of series
- List<Series> seriesList = new List<Series>();
- // Iterate through all clusters
- foreach(List<string> seriesNames in this.seriesClusters)
- {
- // Make sure there is at least one series
- if(seriesNames.Count > 0)
- {
- // Get first series object in the current cluster
- Series series = Common.DataManager.Series[seriesNames[0]];
- // Add series into the drawing list
- seriesList.Add(series);
- }
- }
- // Reversed series list
- if(reverseSeriesOrder)
- {
- seriesList.Reverse();
- }
- // Check if series should be drawn from sides into the center
- if(DrawSeriesToCenter() &&
- this.matrix3D.IsInitialized())
- {
- // Get Z coordinate of Center Of Projection
- Point3D areaProjectionCenter = new Point3D(float.NaN, float.NaN, float.NaN);
- areaProjectionCenter = this.GetCenterOfProjection(COPCoordinates.Z);
- if(!float.IsNaN(areaProjectionCenter.Z))
- {
- // Loop through all series
- for(int seriesIndex = 0; seriesIndex < seriesList.Count; seriesIndex++)
- {
- // Check if series is not empty
- if(((Series)seriesList[seriesIndex]).Points.Count == 0)
- {
- continue;
- }
- // Get series Z position
- float seriesDepth, seriesZPosition;
- this.GetSeriesZPositionAndDepth((Series)seriesList[seriesIndex], out seriesDepth, out seriesZPosition);
- // Check if series passes the Z coordinate of Center of Projection
- if(seriesZPosition >= areaProjectionCenter.Z)
- {
- // Reversed all series order staring from previous series
- --seriesIndex;
- if(seriesIndex < 0)
- seriesIndex = 0;
- seriesList.Reverse(seriesIndex, seriesList.Count - seriesIndex);
- break;
- }
- }
- }
- }
- return seriesList;
- }
- /// <summary>
- /// Gets number of stack groups in specified array of series names.
- /// </summary>
- /// <param name="seriesNamesList">Array of series names.</param>
- /// <returns>Number of stack groups. One by default.</returns>
- private int GetNumberOfStackGroups(IList<string> seriesNamesList)
- {
- this._stackGroupNames = new ArrayList();
- foreach( object seriesName in seriesNamesList )
- {
- // Get series object
- Series ser = this.Common.DataManager.Series[(string)seriesName];
- // Get stack group name from the series
- string stackGroupName = string.Empty;
- if(ser.IsCustomPropertySet(CustomPropertyName.StackedGroupName))
- {
- stackGroupName = ser[CustomPropertyName.StackedGroupName];
- }
- // Add group name if it do not already exsist
- if(!this._stackGroupNames.Contains(stackGroupName))
- {
- this._stackGroupNames.Add(stackGroupName);
- }
- }
- return this._stackGroupNames.Count;
- }
- /// <summary>
- /// Gets index of the series stack group.
- /// </summary>
- /// <param name="series">Series to get the index for.</param>
- /// <param name="stackGroupName">Group name this series belongs to.</param>
- /// <returns>Index of series stack group.</returns>
- internal int GetSeriesStackGroupIndex(Series series, ref string stackGroupName)
- {
- stackGroupName = string.Empty;
- if(this._stackGroupNames != null)
- {
- // Get stack group name from the series
- if(series.IsCustomPropertySet(CustomPropertyName.StackedGroupName))
- {
- stackGroupName = series[CustomPropertyName.StackedGroupName];
- }
- return this._stackGroupNames.IndexOf(stackGroupName);
- }
- return 0;
- }
- /// <summary>
- /// Determine the order of points drawing from one or several series of the same type.
- /// </summary>
- /// <param name="seriesNamesList">List of series names.</param>
- /// <param name="chartType">Chart type.</param>
- /// <param name="selection">If True selection mode is active (points order should be reversed).</param>
- /// <param name="coord">Which coordinate of COP (X, Y or Z) to test for surface overlapping</param>
- /// <param name="comparer">Points comparer class. Can be Null.</param>
- /// <param name="mainYValueIndex">Index of the main Y value.</param>
- /// <param name="sideBySide">Series should be drawn side by side.</param>
- /// <returns>Array list of points in drawing order.</returns>
- internal ArrayList GetDataPointDrawingOrder(
- List<string> seriesNamesList,
- IChartType chartType,
- bool selection,
- COPCoordinates coord,
- IComparer comparer,
- int mainYValueIndex,
- bool sideBySide)
- {
- ChartArea area = (ChartArea)this;
- // Array of points in all series
- ArrayList pointsList = new ArrayList();
- //************************************************************
- //** Analyse input series
- //************************************************************
- // Find the number of data series for side-by-side drawing
- double numOfSeries = 1;
- if(area.Area3DStyle.IsClustered && !chartType.Stacked && sideBySide)
- {
- numOfSeries = seriesNamesList.Count;
- }
- // Check stacked series group names
- if(chartType.SupportStackedGroups)
- {
- // Fill the list of group names and get the number of unique groups
- int numberOfGroups = this.GetNumberOfStackGroups(seriesNamesList);
- // If series are not isClustered set series number to the stacked group number
- if(this.Area3DStyle.IsClustered &&
- seriesNamesList.Count > 0)
- {
- numOfSeries = numberOfGroups;
- }
- }
- // Check if chart series are indexed
- bool indexedSeries = ChartHelper.IndexedSeries(this.Common, seriesNamesList.ToArray());
- //************************************************************
- //** Loop through all series and fill array of points
- //************************************************************
- int seriesIndx = 0;
- foreach( object seriesName in seriesNamesList )
- {
- // Get series object
- Series ser = this.Common.DataManager.Series[(string)seriesName];
- // Check if stacked groups present
- if(chartType.SupportStackedGroups &&
- this._stackGroupNames != null)
- {
- // Get index of the series using stacked group
- string groupName = string.Empty;
- seriesIndx = this.GetSeriesStackGroupIndex(ser, ref groupName);
- // Set current group name
- StackedColumnChart stackedColumnChart = chartType as StackedColumnChart;
- if (stackedColumnChart != null)
- {
- stackedColumnChart.currentStackGroup = groupName;
- }
- else
- {
- StackedBarChart stackedBarChart = chartType as StackedBarChart;
- if (stackedBarChart != null)
- {
- stackedBarChart.currentStackGroup = groupName;
- }
- }
- }
- // Set active vertical/horizontal axis and their max/min values
- Axis vAxis = (ser.YAxisType == AxisType.Primary) ? area.AxisY : area.AxisY2;
- Axis hAxis = (ser.XAxisType == AxisType.Primary) ? area.AxisX : area.AxisX2;
- // Get points interval:
- // - set interval to 1 for indexed series
- // - if points are not equaly spaced, the minimum interval between points is selected.
- // - if points have same interval bars do not overlap each other.
- bool sameInterval = true;
- double interval = 1;
- if(!indexedSeries)
- {
- interval = area.GetPointsInterval( seriesNamesList, hAxis.IsLogarithmic, hAxis.logarithmBase, true, out sameInterval );
- }
- // Get column width
- double width = ser.GetPointWidth(area.Common.graph, hAxis, interval, 0.8) / numOfSeries;
-
- // Get series depth and Z position
- float seriesDepth, seriesZPosition;
- this.GetSeriesZPositionAndDepth(ser, out seriesDepth, out seriesZPosition);
- //************************************************************
- //** Loop through all points in series
- //************************************************************
- int index = 0;
- foreach( DataPoint point in ser.Points )
- {
- // Increase point index
- index++;
-
- // Set x position
- double xCenterVal;
- double xPosition;
- if( indexedSeries )
- {
- // The formula for position is based on a distance
- //from the grid line or nPoints position.
- xPosition = hAxis.GetPosition( (double)index ) - width * ((double) numOfSeries) / 2.0 + width/2 + seriesIndx * width;
- xCenterVal = hAxis.GetPosition( (double)index );
- }
- else if( sameInterval )
- {
- xPosition = hAxis.GetPosition( point.XValue ) - width * ((double) numOfSeries) / 2.0 + width/2 + seriesIndx * width;
- xCenterVal = hAxis.GetPosition( point.XValue );
- }
- else
- {
- xPosition = hAxis.GetPosition( point.XValue );
- xCenterVal = hAxis.GetPosition( point.XValue );
- }
-
- //************************************************************
- //** Create and add new DataPoint3D object
- //************************************************************
- DataPoint3D pointEx = new DataPoint3D();
- pointEx.indexedSeries = indexedSeries;
- pointEx.dataPoint = point;
- pointEx.index = index;
- pointEx.xPosition = xPosition;
- pointEx.xCenterVal = xCenterVal;
- pointEx.width = ser.GetPointWidth(area.Common.graph, hAxis, interval, 0.8) / numOfSeries;
- pointEx.depth = seriesDepth;
- pointEx.zPosition = seriesZPosition;
- // Set Y value and height
- double yValue = chartType.GetYValue(Common, area, ser, point, index - 1, mainYValueIndex);
- if (point.IsEmpty && Double.IsNaN(yValue))
- {
- yValue = 0.0;
- }
- pointEx.yPosition = vAxis.GetPosition(yValue);
- pointEx.height = vAxis.GetPosition(yValue - chartType.GetYValue(Common, area, ser, point, index - 1, -1));
- pointsList.Add(pointEx);
- }
- // Data series index
- if(numOfSeries > 1 && sideBySide)
- {
- seriesIndx++;
- }
- }
-
- //************************************************************
- //** Sort points in drawing order
- //************************************************************
- if(comparer == null)
- {
- comparer = new PointsDrawingOrderComparer((ChartArea)this, selection, coord);
- }
- pointsList.Sort(comparer);
- return pointsList;
- }
-
- #endregion
- #region Points drawing order comparer class
- /// <summary>
- /// Used to compare points in array and sort them by drawing order.
- /// </summary>
- internal class PointsDrawingOrderComparer : IComparer
- {
- /// <summary>
- /// Chart area object reference.
- /// </summary>
- private ChartArea _area = null;
- /// <summary>
- /// Area X position where visible sides are switched.
- /// </summary>
- private Point3D _areaProjectionCenter = new Point3D(float.NaN, float.NaN, float.NaN);
- /// <summary>
- /// Selection mode. Points order should be reversed.
- /// </summary>
- private bool _selection = false;
- /// <summary>
- /// Public constructor.
- /// </summary>
- /// <param name="area">Chart area.</param>
- /// <param name="selection">Selection indicator.</param>
- /// <param name="coord">Which coordinate of COP (X, Y or Z) to test for surface overlapping</param>
- public PointsDrawingOrderComparer(ChartArea area, bool selection, COPCoordinates coord)
- {
- this._area = area;
- this._selection = selection;
- // Get center of projection
- if(area.DrawPointsToCenter(ref coord))
- {
- _areaProjectionCenter = area.GetCenterOfProjection(coord);
- }
- }
- /// <summary>
- /// Comparer method.
- /// </summary>
- /// <param name="o1">First object.</param>
- /// <param name="o2">Second object.</param>
- /// <returns>Comparison result.</returns>
- public int Compare(object o1, object o2)
- {
- DataPoint3D point1 = (DataPoint3D) o1;
- DataPoint3D point2 = (DataPoint3D) o2;
- int result = 0;
- if(point1.xPosition < point2.xPosition)
- {
- result = -1;
- }
- else if(point1.xPosition > point2.xPosition)
- {
- result = 1;
- }
- else
- {
-
- // If X coordinate is the same - filter by Y coordinate
- if(point1.yPosition < point2.yPosition)
- {
- result = 1;
- }
- else if(point1.yPosition > point2.yPosition)
- {
- result = -1;
- }
- // Order points from sides to center
- if(!float.IsNaN(_areaProjectionCenter.Y))
- {
- double yMin1 = Math.Min(point1.yPosition, point1.height);
- double yMax1 = Math.Max(point1.yPosition, point1.height);
- double yMin2 = Math.Min(point2.yPosition, point2.height);
- double yMax2 = Math.Max(point2.yPosition, point2.height);
- if(_area.IsBottomSceneWallVisible())
- {
- if( yMin1 <= _areaProjectionCenter.Y && yMin2 <= _areaProjectionCenter.Y )
- {
- result *= -1;
- }
- else if( yMin1 <= _areaProjectionCenter.Y)
- {
- result = 1;
- }
- }
- else
- {
-
- if( yMax1 >= _areaProjectionCenter.Y && yMax2 >= _areaProjectionCenter.Y )
- {
- result *= 1;
- }
- else if( yMax1 >= _areaProjectionCenter.Y)
- {
- result = 1;
- }
- else
- {
- result *= -1;
- }
- }
- }
- // Reversed order if looking from the bottom
- else if(!_area.IsBottomSceneWallVisible())
- {
- result *= -1;
- }
-
- }
- if(point1.xPosition != point2.xPosition)
- {
- // Order points from sides to center
- if (!float.IsNaN(_areaProjectionCenter.X))
- {
- if ((point1.xPosition + point1.width / 2f) >= _areaProjectionCenter.X &&
- (point2.xPosition + point2.width / 2f) >= _areaProjectionCenter.X)
- {
- result *= -1;
- }
- }
- // Reversed order of points by X value
- else if (_area.DrawPointsInReverseOrder())
- {
- result *= -1;
- }
- }
- return (_selection) ? -result : result;
- }
- }
- #endregion
- #region Center of Projection calculation methods
- /// <summary>
- /// Returns one or many (X, Y, Z) coordinates of the center of projection.
- /// </summary>
- /// <param name="coord">Defines coordinates to return.</param>
- /// <returns>Center of projection. Value can be set to float.NaN if not defined or outside plotting area.</returns>
- internal Point3D GetCenterOfProjection(COPCoordinates coord)
- {
- // Define 2 points in the opposite corners of the plotting area
- Point3D[] points = new Point3D[2];
- points[0] = new Point3D(this.PlotAreaPosition.X, this.PlotAreaPosition.Bottom, 0f);
- points[1] = new Point3D(this.PlotAreaPosition.Right, this.PlotAreaPosition.Y, this.areaSceneDepth);
- // Check if surfaces (points 1 & 2) has same orientation
- bool xSameOrientation, ySameOrientation, zSameOrientation;
- CheckSurfaceOrientation(
- coord,
- points[0],
- points[1],
- out xSameOrientation,
- out ySameOrientation,
- out zSameOrientation);
- // If orientation of all surfaces is the same - no futher processing is required (COP is outside of plotting area)
- Point3D resultPoint = new Point3D(
- (xSameOrientation) ? float.NaN : 0f,
- (ySameOrientation) ? float.NaN : 0f,
- (zSameOrientation) ? float.NaN : 0f);
- if( ( ((coord & COPCoordinates.X) != COPCoordinates.X) || xSameOrientation ) &&
- ( ((coord & COPCoordinates.Y) != COPCoordinates.Y) || ySameOrientation ) &&
- ( ((coord & COPCoordinates.Z) != COPCoordinates.Z) || zSameOrientation ) )
- {
- return resultPoint;
- }
- // Calculate the smallest interval (0.5 pixels) in relative coordinates
- SizeF interval = new SizeF(0.5f, 0.5f);
- interval.Width = interval.Width * 100F / ((float)(this.Common.Chart.Width - 1));
- interval.Height = interval.Height * 100F / ((float)(this.Common.Chart.Height - 1));
- // Find middle point and check it's surface orientation
- bool doneFlag = false;
- while(!doneFlag)
- {
- // Find middle point
- Point3D middlePoint = new Point3D(
- (points[0].X + points[1].X) / 2f,
- (points[0].Y + points[1].Y) / 2f,
- (points[0].Z + points[1].Z) / 2f);
- // Check if surfaces (points 1 & middle) has same orientation
- CheckSurfaceOrientation(
- coord,
- points[0],
- middlePoint,
- out xSameOrientation,
- out ySameOrientation,
- out zSameOrientation);
- // Calculate points 1 & 2 depending on surface orientation of the middle point
- points[(xSameOrientation) ? 0 : 1].X = middlePoint.X;
- points[(ySameOrientation) ? 0 : 1].Y = middlePoint.Y;
- points[(zSameOrientation) ? 0 : 1].Z = middlePoint.Z;
- // Check if no more calculations required
- doneFlag = true;
- if( (coord & COPCoordinates.X) == COPCoordinates.X &&
- Math.Abs(points[1].X - points[0].X) >= interval.Width)
- {
- doneFlag = false;
- }
- if( (coord & COPCoordinates.Y) == COPCoordinates.Y &&
- Math.Abs(points[1].Y - points[0].Y) >= interval.Height)
- {
- doneFlag = false;
- }
- if( (coord & COPCoordinates.Z) == COPCoordinates.Z &&
- Math.Abs(points[1].Z - points[0].Z) >= interval.Width)
- {
- doneFlag = false;
- }
- }
- // Calculate result point
- if(!float.IsNaN(resultPoint.X))
- resultPoint.X = (points[0].X + points[1].X) / 2f;
- if(!float.IsNaN(resultPoint.Y))
- resultPoint.Y = (points[0].Y + points[1].Y) / 2f;
- if(!float.IsNaN(resultPoint.Z))
- resultPoint.Z = (points[0].Z + points[1].Z) / 2f;
- return resultPoint;
- }
- /// <summary>
- /// Checks orientations of two normal surfaces for each coordinate X, Y and Z.
- /// </summary>
- /// <param name="coord">Defines coordinates to return.</param>
- /// <param name="point1">First point.</param>
- /// <param name="point2">Second point.</param>
- /// <param name="xSameOrientation">X surfaces orientation is the same.</param>
- /// <param name="ySameOrientation">Y surfaces orientation is the same.</param>
- /// <param name="zSameOrientation">Z surfaces orientation is the same.</param>
- private void CheckSurfaceOrientation(
- COPCoordinates coord,
- Point3D point1,
- Point3D point2,
- out bool xSameOrientation,
- out bool ySameOrientation,
- out bool zSameOrientation)
- {
- Point3D[] pointsSurface = new Point3D[3];
- bool surf1, surf2;
- // Initialize returned values
- xSameOrientation = true;
- ySameOrientation = true;
- zSameOrientation = true;
- // Check X axis coordinates (ledt & right surfaces)
- if( (coord & COPCoordinates.X) == COPCoordinates.X )
- {
- // Define Left surface coordinates, transform them and check visibility
- pointsSurface[0] = new Point3D(point1.X, this.PlotAreaPosition.Y, 0f);
- pointsSurface[1] = new Point3D(point1.X, this.PlotAreaPosition.Bottom, 0f);
- pointsSurface[2] = new Point3D(point1.X, this.PlotAreaPosition.Bottom, this.areaSceneDepth);
- this.matrix3D.TransformPoints( pointsSurface );
- surf1 = ChartGraphics.IsSurfaceVisible(pointsSurface[0], pointsSurface[1], pointsSurface[2]);
- // Define Right surface coordinates, transform them and check visibility
- pointsSurface[0] = new Point3D(point2.X, this.PlotAreaPosition.Y, 0f);
- pointsSurface[1] = new Point3D(point2.X, this.PlotAreaPosition.Bottom, 0f);
- pointsSurface[2] = new Point3D(point2.X, this.PlotAreaPosition.Bottom, this.areaSceneDepth);
- this.matrix3D.TransformPoints( pointsSurface );
- surf2 = ChartGraphics.IsSurfaceVisible(pointsSurface[0], pointsSurface[1], pointsSurface[2]);
- // Check if surfaces have same visibility
- xSameOrientation = (surf1 == surf2);
- }
- // Check Y axis coordinates (top & bottom surfaces)
- if( (coord & COPCoordinates.Y) == COPCoordinates.Y )
- {
- // Define Bottom surface coordinates, transform them and check visibility
- pointsSurface[0] = new Point3D(this.PlotAreaPosition.X, point1.Y, this.areaSceneDepth);
- pointsSurface[1] = new Point3D(this.PlotAreaPosition.X, point1.Y, 0f);
- pointsSurface[2] = new Point3D(this.PlotAreaPosition.Right, point1.Y, 0f);
- this.matrix3D.TransformPoints( pointsSurface );
- surf1 = ChartGraphics.IsSurfaceVisible(pointsSurface[0], pointsSurface[1], pointsSurface[2]);
- // Define Top surface coordinates, transform them and check visibility
- pointsSurface[0] = new Point3D(this.PlotAreaPosition.X, point2.Y, this.areaSceneDepth);
- pointsSurface[1] = new Point3D(this.PlotAreaPosition.X, point2.Y, 0f);
- pointsSurface[2] = new Point3D(this.PlotAreaPosition.Right, point2.Y, 0f);
- this.matrix3D.TransformPoints( pointsSurface );
- surf2 = ChartGraphics.IsSurfaceVisible(pointsSurface[0], pointsSurface[1], pointsSurface[2]);
- // Check if surfaces have same visibility
- ySameOrientation = (surf1 == surf2);
- }
- // Check Y axis coordinates (front & back surfaces)
- if( (coord & COPCoordinates.Z) == COPCoordinates.Z )
- {
- // Define Front surface coordinates, transform them and check visibility
- pointsSurface[0] = new Point3D(this.PlotAreaPosition.X, this.PlotAreaPosition.Y, point1.Z);
- pointsSurface[1] = new Point3D(this.PlotAreaPosition.X, this.PlotAreaPosition.Bottom, point1.Z);
- pointsSurface[2] = new Point3D(this.PlotAreaPosition.Right, this.PlotAreaPosition.Bottom, point1.Z);
- this.matrix3D.TransformPoints( pointsSurface );
- surf1 = ChartGraphics.IsSurfaceVisible(pointsSurface[0], pointsSurface[1], pointsSurface[2]);
- // Define Back surface coordinates, transform them and check visibility
- pointsSurface[0] = new Point3D(this.PlotAreaPosition.X, this.PlotAreaPosition.Y, point2.Z);
- pointsSurface[1] = new Point3D(this.PlotAreaPosition.X, this.PlotAreaPosition.Bottom, point2.Z);
- pointsSurface[2] = new Point3D(this.PlotAreaPosition.Right, this.PlotAreaPosition.Bottom, point2.Z);
- this.matrix3D.TransformPoints( pointsSurface );
- surf2 = ChartGraphics.IsSurfaceVisible(pointsSurface[0], pointsSurface[1], pointsSurface[2]);
- // Check if surfaces have same visibility
- zSameOrientation = (surf1 == surf2);
- }
- }
- #endregion
- }
- }
|