DataPoint.cs 3.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115
  1. //
  2. // Authors:
  3. // Jonathan Pobst ([email protected])
  4. //
  5. // Copyright (C) 2009 Novell, Inc (http://www.novell.com)
  6. //
  7. // Permission is hereby granted, free of charge, to any person obtaining
  8. // a copy of this software and associated documentation files (the
  9. // "Software"), to deal in the Software without restriction, including
  10. // without limitation the rights to use, copy, modify, merge, publish,
  11. // distribute, sublicense, and/or sell copies of the Software, and to
  12. // permit persons to whom the Software is furnished to do so, subject to
  13. // the following conditions:
  14. //
  15. // The above copyright notice and this permission notice shall be
  16. // included in all copies or substantial portions of the Software.
  17. //
  18. // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
  19. // EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
  20. // MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
  21. // NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
  22. // LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
  23. // OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
  24. // WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
  25. using System;
  26. using System.Linq;
  27. namespace System.Windows.Forms.DataVisualization.Charting
  28. {
  29. [MonoTODO ("Base class should be DataPointCustomProperties")]
  30. public class DataPoint : ChartNamedElement
  31. {
  32. #region Constructors
  33. public DataPoint ()
  34. {
  35. }
  36. public DataPoint (double xValue, double yValue)
  37. {
  38. XValue = xValue;
  39. YValue = new double[] { yValue };
  40. }
  41. public DataPoint (double xValue, double[] yValues)
  42. {
  43. XValue = xValue;
  44. YValue = yValues;
  45. }
  46. [MonoTODO ()]
  47. public DataPoint (Series series)
  48. {
  49. }
  50. #endregion
  51. #region Public Properties
  52. public bool IsEmpty { get; set; }
  53. public override string Name { get; set; }
  54. public double XValue { get; set; }
  55. public double[] YValue { get; set; }
  56. #endregion
  57. #region Public Methods
  58. public DataPoint Clone ()
  59. {
  60. DataPoint clone = new DataPoint (XValue, YValue);
  61. clone.IsEmpty = IsEmpty;
  62. clone.Name = Name;
  63. return clone;
  64. }
  65. public double GetValueByName (string valueName)
  66. {
  67. if (valueName == null)
  68. throw new ArgumentNullException ("valueName");
  69. valueName = valueName.ToLowerInvariant ();
  70. if (valueName == "x")
  71. return XValue;
  72. if (valueName.StartsWith ("y")) {
  73. if (valueName.Length == 1)
  74. return YValue[0];
  75. int index = 0;
  76. if (int.TryParse (valueName.Substring (1), out index)) {
  77. if (index > YValue.Length)
  78. throw new ArgumentException ("Y index greater than number of YValues");
  79. if (index == 0)
  80. throw new ArgumentException ("Y index must be greater than zero");
  81. return YValue[index - 1];
  82. }
  83. }
  84. throw new ArgumentException ("valueName");
  85. }
  86. public void SetValueXY (object xValue, params object[] yValue)
  87. {
  88. XValue = (double)xValue;
  89. YValue = yValue.Cast<double> ().ToArray ();
  90. }
  91. public void SetValueY (params object[] yValue)
  92. {
  93. YValue = yValue.Cast<double> ().ToArray ();
  94. }
  95. #endregion
  96. }
  97. }