DataPoint.cs 3.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120
  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. public class DataPoint : DataPointCustomProperties
  30. {
  31. #region Constructors
  32. public DataPoint ()
  33. {
  34. }
  35. public DataPoint (double xValue, double yValue)
  36. {
  37. XValue = xValue;
  38. YValues = new double[] { yValue };
  39. }
  40. public DataPoint (double xValue, double[] yValues)
  41. {
  42. XValue = xValue;
  43. YValues = yValues;
  44. }
  45. [MonoTODO ()]
  46. public DataPoint (Series series)
  47. {
  48. }
  49. [MonoTODO ()]
  50. public DataPoint(double xValue, string yValues)
  51. {
  52. }
  53. #endregion
  54. #region Public Properties
  55. public bool IsEmpty { get; set; }
  56. public override string Name { get; set; }
  57. public double XValue { get; set; }
  58. public double[] YValues { get; set; }
  59. #endregion
  60. #region Public Methods
  61. public DataPoint Clone ()
  62. {
  63. DataPoint clone = new DataPoint (XValue, YValues);
  64. clone.IsEmpty = IsEmpty;
  65. clone.Name = Name;
  66. return clone;
  67. }
  68. public double GetValueByName (string valueName)
  69. {
  70. if (valueName == null)
  71. throw new ArgumentNullException ("valueName");
  72. valueName = valueName.ToLowerInvariant ();
  73. if (valueName == "x")
  74. return XValue;
  75. if (valueName.StartsWith ("y")) {
  76. if (valueName.Length == 1)
  77. return YValues[0];
  78. int index = 0;
  79. if (int.TryParse (valueName.Substring (1), out index)) {
  80. if (index > YValues.Length)
  81. throw new ArgumentException ("Y index greater than number of YValues");
  82. if (index == 0)
  83. throw new ArgumentException ("Y index must be greater than zero");
  84. return YValues[index - 1];
  85. }
  86. }
  87. throw new ArgumentException ("valueName");
  88. }
  89. public void SetValueXY (object xValue, params object[] yValue)
  90. {
  91. XValue = (double)xValue;
  92. YValues = yValue.Cast<double> ().ToArray ();
  93. }
  94. public void SetValueY (params object[] yValue)
  95. {
  96. YValues = yValue.Cast<double> ().ToArray ();
  97. }
  98. #endregion
  99. }
  100. }