123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294 |
- // 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: CommonElements class provides references to common
- // chart classes like DataManager, ChartTypeRegistry,
- // ImageLoader and others. It is passed to different
- // chart elements to simplify access to those common
- // classes.
- //
- using System;
- using System.ComponentModel.Design;
- using System.Globalization;
- using FastReport.DataVisualization.Charting.Borders3D;
- using FastReport.DataVisualization.Charting.ChartTypes;
- using FastReport.DataVisualization.Charting.Data;
- using FastReport.DataVisualization.Charting.Formulas;
- using FastReport.DataVisualization.Charting.Utilities;
- namespace FastReport.DataVisualization.Charting
- {
- /// <summary>
- /// CommonElements class provides references to common chart classes like
- /// DataManager, ChartTypeRegistry, ImageLoader and others. It is passed
- /// to different chart elements to simplify access to those common classes.
- /// </summary>
- internal class CommonElements
- {
- #region Fields
- private Chart _chart;
- private ChartImage _chartPicture;
- // Reference to Chart Graphics Object
- internal ChartGraphics graph = null;
- /// <summary>
- /// Service Container
- /// </summary>
- internal IServiceContainer container = null;
- /// <summary>
- /// Indicates painting mode
- /// </summary>
- internal bool processModePaint = true;
- /// <summary>
- /// Indicates selection mode
- /// </summary>
- internal bool processModeRegions = false;
- // Private Fields
- private int _width = 0;
- private int _height = 0;
- #endregion
- #region Properties
- /// <summary>
- /// Reference to the Data Manager
- /// </summary>
- internal DataManager DataManager
- {
- get
- {
- return (DataManager)container.GetService(typeof(DataManager));
- }
- }
- /// <summary>
- /// True if painting mode is active
- /// </summary>
- public bool ProcessModePaint
- {
- get
- {
- return processModePaint;
- }
- }
- /// <summary>
- /// True if Hot region or image maps mode is active
- /// </summary>
- public bool ProcessModeRegions
- {
- get
- {
- return processModeRegions;
- }
- }
- /// <summary>
- /// Reference to the hot regions object
- /// </summary>
- public HotRegionsList HotRegionsList
- {
- get
- {
- return ChartPicture.hotRegionsList;
- }
- }
- /// <summary>
- /// Reference to the Data Manipulator
- /// </summary>
- public DataManipulator DataManipulator
- {
- get
- {
- return ChartPicture.DataManipulator;
- }
- }
- /// <summary>
- /// Reference to the ImageLoader
- /// </summary>
- internal ImageLoader ImageLoader
- {
- get
- {
- return (ImageLoader)container.GetService(typeof(ImageLoader));
- }
- }
- /// <summary>
- /// Reference to the Chart
- /// </summary>
- internal Chart Chart
- {
- get
- {
- if (_chart==null)
- _chart = (Chart)container.GetService(typeof(Chart));
- return _chart;
- }
- }
- /// <summary>
- /// Reference to the ChartTypeRegistry
- /// </summary>
- internal ChartTypeRegistry ChartTypeRegistry
- {
- get
- {
- return (ChartTypeRegistry)container.GetService(typeof(ChartTypeRegistry));
- }
- }
- /// <summary>
- /// Reference to the BorderTypeRegistry
- /// </summary>
- internal BorderTypeRegistry BorderTypeRegistry
- {
- get
- {
- return (BorderTypeRegistry)container.GetService(typeof(BorderTypeRegistry));
- }
- }
- /// <summary>
- /// Reference to the FormulaRegistry
- /// </summary>
- internal FormulaRegistry FormulaRegistry
- {
- get
- {
- return (FormulaRegistry)container.GetService(typeof(FormulaRegistry));
- }
- }
- /// <summary>
- /// Reference to the ChartPicture
- /// </summary>
- internal ChartImage ChartPicture
- {
- get
- {
- if (_chartPicture ==null)
- _chartPicture = (ChartImage)container.GetService(typeof(ChartImage));
- return _chartPicture;
- }
- }
- /// <summary>
- /// Width of the chart picture
- /// </summary>
- internal int Width
- {
- get
- {
- return _width;
- }
- set
- {
- _width = value;
- }
- }
- /// <summary>
- /// Height of the chart picture
- /// </summary>
- internal int Height
- {
- get
- {
- return _height;
- }
- set
- {
- _height = value;
- }
- }
- #endregion
- #region Methods
- /// <summary>
- /// Constructor
- /// </summary>
- /// <param name="container">Service container.</param>
- internal CommonElements(IServiceContainer container)
- {
- this.container = container;
- }
-
- #endregion
- #region String convertion helper methods
- /// <summary>
- /// Converts string to double.
- /// </summary>
- /// <param name="stringToParse">String to convert.</param>
- /// <returns>Double result.</returns>
- internal static double ParseDouble(string stringToParse)
- {
- return ParseDouble(stringToParse, false);
- }
- /// <summary>
- /// Converts string to double.
- /// </summary>
- /// <param name="stringToParse">String to convert.</param>
- /// <param name="throwException">if set to <c>true</c> the exception thrown.</param>
- /// <returns>Double result.</returns>
- [System.Diagnostics.CodeAnalysis.SuppressMessage("Microsoft.Usage", "CA1806:DoNotIgnoreMethodResults", MessageId = "System.Double.TryParse(System.String,System.Globalization.NumberStyles,System.IFormatProvider,System.Double@)")]
- internal static double ParseDouble(string stringToParse, bool throwException)
- {
- Double result = 0.0;
- if (throwException)
- {
- result = double.Parse(stringToParse, NumberStyles.Any, CultureInfo.InvariantCulture);
- }
- else
- {
- bool parseSucceed = double.TryParse(stringToParse, NumberStyles.Any, CultureInfo.InvariantCulture, out result);
- if (!parseSucceed)
- {
- double.TryParse(stringToParse, NumberStyles.Any, CultureInfo.CurrentCulture, out result);
- }
- }
- return result;
- }
- /// <summary>
- /// Converts string to double.
- /// </summary>
- /// <param name="stringToParse">String to convert.</param>
- /// <returns>Double result.</returns>
- [System.Diagnostics.CodeAnalysis.SuppressMessage("Microsoft.Usage", "CA1806:DoNotIgnoreMethodResults", MessageId = "System.Single.TryParse(System.String,System.Globalization.NumberStyles,System.IFormatProvider,System.Single@)")]
- internal static float ParseFloat(string stringToParse)
- {
- float result = 0f;
- bool parseSucceed = float.TryParse(stringToParse, NumberStyles.Any, CultureInfo.InvariantCulture, out result);
- if (!parseSucceed)
- {
- float.TryParse(stringToParse, NumberStyles.Any, CultureInfo.CurrentCulture, out result);
- }
- return result;
- }
- #endregion
- }
- }
|