Show:

File: ia\data\Limits.js

  1. /**
  2. * Contains information about an upper or lower limit.
  3. *
  4. * @author J Clare
  5. * @class ia.Limits
  6. * @constructor
  7. * @param {ia.Geography} geography The geography the Limits belongs to.
  8. * @param {ia.Indicator} indicator The indicator the Limits belongs to.
  9. * @param {JSON} data The json data describing the object.
  10. */
  11. ia.Limits = function(geography, indicator, data)
  12. {
  13. // Parse the JSON data.
  14. this._indexHash = {};
  15. this._valueArray = data;
  16. this._fValueArray = [];
  17. if (this._valueArray)
  18. {
  19. // Features
  20. var features = geography.getFeatures();
  21. var fLength = features.length;
  22.  
  23. this.minValue = Infinity;
  24. this.maxValue = -Infinity;
  25. var v;
  26. var fv;
  27. var featureId;
  28.  
  29. for (var i = 0; i < fLength; i++)
  30. {
  31. featureId = features[i].id;
  32. v = this._valueArray[i];
  33. fv = geography.reportData.formatter.format(v, this.precision);
  34.  
  35. this._indexHash[featureId] = i;
  36. this.minValue = (v < this.minValue) ? v : this.minValue;
  37. this.maxValue = (v > this.maxValue) ? v : this.maxValue;
  38.  
  39. this._fValueArray.push(fv);
  40. }
  41. }
  42. };
  43.  
  44. /**
  45. * The minimum value.
  46. *
  47. * @property minValue
  48. * @type Number
  49. */
  50. ia.Limits.prototype.minValue;
  51.  
  52. /**
  53. * The maximum value.
  54. *
  55. * @property maxValue
  56. * @type Number
  57. */
  58. ia.Limits.prototype.maxValue;
  59.  
  60. /**
  61. * Returns the value that corresponds to the feature id.
  62. *
  63. * @method getValue
  64. * @param {String} id The feature id.
  65. * @return {Number|String} The value for the given id.
  66. */
  67. ia.Limits.prototype.getValue = function(id) {return this._valueArray[this._indexHash[id]];};
  68.  
  69. /**
  70. * Returns the list of values.
  71. *
  72. * @method getValues
  73. * @return {Number|String[]} An array of values.
  74. */
  75. ia.Limits.prototype.getValues = function() {return this._valueArray;};
  76.  
  77. /**
  78. * Returns the formatted value that corresponds to the feature id.
  79. *
  80. * @method getFormattedValue
  81. * @param {String} id The feature id.
  82. * @return {String} The formatted value for the given id.
  83. */
  84. ia.Limits.prototype.getFormattedValue = function(id) {return this._fValueArray[this._indexHash[id]];};
  85.  
  86. /**
  87. * Returns the list of formatted values.
  88. *
  89. * @method getFormattedValues
  90. * @return {String[]} An array of formatted values.
  91. */
  92. ia.Limits.prototype.getFormattedValues = function() {return this._fValueArray;};