VIPRValue.js 1.8 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061
  1. 'use strict';
  2. function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
  3. /**
  4. * Licensed Materials - Property of IBM
  5. * IBM Business Analytics (C) Copyright IBM Corp. 2020
  6. * US Government Users Restricted Rights - Use, duplication or disclosure restricted by GSA ADP Schedule Contract with IBM Corp.
  7. */
  8. define(['underscore'], function (_) {
  9. // implements IValue
  10. var VIPRValue = function () {
  11. function VIPRValue(valueObj, formatter, resultItemIndex) {
  12. _classCallCheck(this, VIPRValue);
  13. //accept either { .v or # }
  14. this.rawValue = valueObj;
  15. this.value = valueObj && !_.isNumber(valueObj) && valueObj.v !== undefined ? valueObj.v : valueObj;
  16. this.formatter = formatter;
  17. this.index = resultItemIndex;
  18. }
  19. VIPRValue.prototype.getIndex = function getIndex() {
  20. return this.index;
  21. };
  22. VIPRValue.prototype.getValue = function getValue() {
  23. //The value of a VIPRValue is a number (eg 1234.50)
  24. return this.value;
  25. };
  26. VIPRValue.prototype.getValueType = function getValueType() {
  27. if (this.value === null) {
  28. return 'missing'; //NULL Value support, to be parsed by VIDA
  29. }
  30. return 'numeric'; //Default Value Type
  31. };
  32. VIPRValue.prototype.getCaption = function getCaption() {
  33. //The "caption" of a value is its formatted string (eg: $1,234.50)
  34. return this.formatter ? this.formatter.format(this.value) : this.value;
  35. };
  36. /**
  37. * This function is not an implementation of IValue
  38. * Sole purpose is to give VIPREventTarget to have access to the raw datapoint value
  39. */
  40. VIPRValue.prototype.getRawValue = function getRawValue() {
  41. return this.rawValue;
  42. };
  43. return VIPRValue;
  44. }();
  45. return VIPRValue;
  46. });
  47. //# sourceMappingURL=VIPRValue.js.map