AnnotationConverters.cs 3.0 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697
  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: Annotation Converters.
  6. //
  7. using System;
  8. using System.ComponentModel;
  9. using System.Globalization;
  10. namespace FastReport.DataVisualization.Charting
  11. {
  12. /// <summary>
  13. /// Converts anchor data point to string name.
  14. /// </summary>
  15. internal class AnchorPointValueConverter : TypeConverter
  16. {
  17. #region Converter methods
  18. /// <summary>
  19. /// Converts anchor data point to string name.
  20. /// </summary>
  21. /// <param name="context">Descriptor context.</param>
  22. /// <param name="culture">Culture information.</param>
  23. /// <param name="value">Value to convert.</param>
  24. /// <param name="destinationType">Convertion destination type.</param>
  25. /// <returns>Converted object.</returns>
  26. public override object ConvertTo(ITypeDescriptorContext context, CultureInfo culture, object value, Type destinationType)
  27. {
  28. if (destinationType == typeof(string))
  29. {
  30. if (value == null)
  31. {
  32. return Constants.NotSetValue;
  33. }
  34. DataPoint dataPoint = value as DataPoint;
  35. if (dataPoint != null)
  36. {
  37. if (dataPoint.series != null)
  38. {
  39. int pointIndex = dataPoint.series.Points.IndexOf(dataPoint) + 1;
  40. return dataPoint.series.Name + " - " + SR.DescriptionTypePoint + pointIndex.ToString(CultureInfo.InvariantCulture);
  41. }
  42. }
  43. }
  44. // Call base class
  45. return base.ConvertTo(context, culture, value, destinationType);
  46. }
  47. #endregion
  48. }
  49. /// <summary>
  50. /// Converts anchor data point to string name.
  51. /// </summary>
  52. internal class AnnotationAxisValueConverter : TypeConverter
  53. {
  54. #region Converter methods
  55. /// <summary>
  56. /// Converts axis associated with anootation to string.
  57. /// </summary>
  58. /// <param name="context">Descriptor context.</param>
  59. /// <param name="culture">Culture information.</param>
  60. /// <param name="value">Value to convert.</param>
  61. /// <param name="destinationType">Convertion destination type.</param>
  62. /// <returns>Converted object.</returns>
  63. public override object ConvertTo(ITypeDescriptorContext context, CultureInfo culture, object value, Type destinationType)
  64. {
  65. if (destinationType == typeof(string))
  66. {
  67. if (value == null)
  68. {
  69. return Constants.NotSetValue;
  70. }
  71. Axis axis = value as Axis;
  72. if (axis != null)
  73. {
  74. if (axis.ChartArea != null)
  75. {
  76. return axis.ChartArea.Name + " - " + axis.Name;
  77. }
  78. }
  79. }
  80. // Call base class
  81. return base.ConvertTo(context, culture, value, destinationType);
  82. }
  83. #endregion
  84. }
  85. }