ColBarZeroOriginValueUpgrade.js 3.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798
  1. 'use strict';
  2. function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
  3. function _possibleConstructorReturn(self, call) { if (!self) { throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); } return call && (typeof call === "object" || typeof call === "function") ? call : self; }
  4. function _inherits(subClass, superClass) { if (typeof superClass !== "function" && superClass !== null) { throw new TypeError("Super expression must either be null or a function, not " + typeof superClass); } subClass.prototype = Object.create(superClass && superClass.prototype, { constructor: { value: subClass, enumerable: false, writable: true, configurable: true } }); if (superClass) Object.setPrototypeOf ? Object.setPrototypeOf(subClass, superClass) : subClass.__proto__ = superClass; }
  5. /*
  6. *+------------------------------------------------------------------------+
  7. *| Licensed Materials - Property of IBM
  8. *| IBM Cognos Products: BI Dashboard
  9. *| (C) Copyright IBM Corp. 2020
  10. *|
  11. *| US Government Users Restricted Rights - Use, duplication or disclosure
  12. *| restricted by GSA ADP Schedule Contract with IBM Corp.
  13. *+------------------------------------------------------------------------+
  14. */
  15. define(['underscore', '../../../lib/@waca/upgrades/UpgradeBase', './utils/WidgetUpgradeUtils'], function (_, UpgradeBase, WidgetUpgradeUtils) {
  16. /**
  17. * Bar based chart types before R7 ignored the valueAxis.zeroOrigin property
  18. * To avoid upgraded charts looking different we want to ensure that if a
  19. * vis had this property set previously (say it was a line chart, the prop was
  20. * changed and then the vis was changed to a bar chart and saved) then we have
  21. * to set the prop to true for these chart types.
  22. **/
  23. var ColBarZeroOriginValueUpgrade = function (_UpgradeBase) {
  24. _inherits(ColBarZeroOriginValueUpgrade, _UpgradeBase);
  25. function ColBarZeroOriginValueUpgrade() {
  26. _classCallCheck(this, ColBarZeroOriginValueUpgrade);
  27. var _this = _possibleConstructorReturn(this, _UpgradeBase.call(this));
  28. _this.VERSION = 1801;
  29. return _this;
  30. }
  31. /**
  32. * Perform upgrade
  33. *
  34. * @param {object} spec - spec to perform upgrade on
  35. *
  36. * @return {Promise} Promise to be resolved when upgrade performed
  37. */
  38. ColBarZeroOriginValueUpgrade.prototype.up = function up(spec) {
  39. var _this2 = this;
  40. if (!spec) {
  41. return Promise.resolve(spec);
  42. }
  43. if (!WidgetUpgradeUtils.specHasWidgets(spec)) {
  44. return Promise.resolve(spec);
  45. }
  46. /*
  47. * Cycle through all widgets and, if they are live widgets, upgrade the property.
  48. */
  49. _.each(spec.widgets, function (model) {
  50. if (model && WidgetUpgradeUtils.isLiveWidgetModel(model)) {
  51. if (!model.properties) {
  52. model.properties = [];
  53. }
  54. _this2._colBarZeroOriginValueUpgrade(model);
  55. }
  56. });
  57. return Promise.resolve(spec);
  58. };
  59. // Downgrades are not available in CA
  60. ColBarZeroOriginValueUpgrade.prototype.down = function down(spec) {
  61. return Promise.resolve(spec);
  62. };
  63. ColBarZeroOriginValueUpgrade.prototype._colBarZeroOriginValueUpgrade = function _colBarZeroOriginValueUpgrade(model) {
  64. var needsUpgradeVisIds = ['com.ibm.vis.rave2bundlebar', 'com.ibm.vis.rave2bundlecolumn', 'com.ibm.vis.rave2bundlestackedbar', 'com.ibm.vis.rave2bundlestackedcolumn'];
  65. if (_.contains(needsUpgradeVisIds, model.visId)) {
  66. var zeroOriginPropId = 'valueAxis.zeroOrigin';
  67. var zeroOriginProp = WidgetUpgradeUtils.findProperty(zeroOriginPropId, model.properties);
  68. if (zeroOriginProp) {
  69. zeroOriginProp.value = true;
  70. }
  71. }
  72. };
  73. return ColBarZeroOriginValueUpgrade;
  74. }(UpgradeBase);
  75. return new ColBarZeroOriginValueUpgrade();
  76. });
  77. //# sourceMappingURL=ColBarZeroOriginValueUpgrade.js.map