VIDAPropUpgrade.js 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284
  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. 2018
  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. * Upgrade VIDA property. Remove title.visible from the old spec and introduce 'itemAxis.title.visible' and 'valueAxis.title.visible' instead.
  18. **/
  19. var VIDAPropUpgrade = function (_UpgradeBase) {
  20. _inherits(VIDAPropUpgrade, _UpgradeBase);
  21. function VIDAPropUpgrade() {
  22. _classCallCheck(this, VIDAPropUpgrade);
  23. var _this = _possibleConstructorReturn(this, _UpgradeBase.call(this));
  24. _this.VERSION = 1013;
  25. return _this;
  26. }
  27. /**
  28. * Perform upgrade
  29. *
  30. * @param {object} spec - spec to perform upgrade on
  31. *
  32. * @return {Promise} Promise to be resolved when upgrade performed
  33. */
  34. VIDAPropUpgrade.prototype.up = function up(spec) {
  35. var _this2 = this;
  36. if (!spec) {
  37. return Promise.resolve(spec);
  38. }
  39. if (!WidgetUpgradeUtils.specHasWidgets(spec)) {
  40. return Promise.resolve(spec);
  41. }
  42. _.each(spec.widgets, function (model) {
  43. if (model && _this2._isLive(model)) {
  44. if (!model.properties) {
  45. model.properties = [];
  46. }
  47. _this2._showAxisTitlesPropertyUpgrade(model);
  48. _this2._optimizeSizePropertyUpgrade(model);
  49. _this2._preserveItemAxisPositionForHeatmap(model);
  50. _this2._stackedPercentPropertyUpgrade(model);
  51. _this2._linesSmoothPropertyUpgrade(model);
  52. _this2._upgradePieChart(model);
  53. }
  54. });
  55. return Promise.resolve(spec);
  56. };
  57. // Downgrades are not available in CA
  58. VIDAPropUpgrade.prototype.down = function down(spec) {
  59. return Promise.resolve(spec);
  60. };
  61. VIDAPropUpgrade.prototype._isLive = function _isLive(model) {
  62. return model && model.type && model.type === 'live';
  63. };
  64. VIDAPropUpgrade.prototype._showAxisTitlesPropertyUpgrade = function _showAxisTitlesPropertyUpgrade(model) {
  65. var deprecatedProps = ['titles.visible', 'itemAxis.labels.visible', 'valueAxis.labels.visible'];
  66. // old spec : title.visible, itemAxis.labels.visible, valueAxis.labels.visible
  67. var deprecatedshowAxisTitlesProp = WidgetUpgradeUtils.findProperty('titles.visible', model.properties);
  68. var deprecatedItemAxisVisibleProp = WidgetUpgradeUtils.findProperty('itemAxis.labels.visible', model.properties);
  69. var deprecatedValueAxisVisibleProp = WidgetUpgradeUtils.findProperty('valueAxis.labels.visible', model.properties);
  70. // new spec : itemAxis.title.visible, valueAxis.title.visible
  71. var itemAxisVisibleProp = WidgetUpgradeUtils.findProperty('itemAxis.title.visible', model.properties);
  72. var valueAxisVisibleProp = WidgetUpgradeUtils.findProperty('valueAxis.title.visible', model.properties);
  73. // clean up the spec poperties by filter out the deprecated props
  74. model.properties = _.filter(model.properties, function (prop) {
  75. return !_.contains(deprecatedProps, prop.id);
  76. });
  77. if (deprecatedshowAxisTitlesProp && deprecatedshowAxisTitlesProp.value === false) {
  78. //if the title.visible is set to false in the old spec, then both itemAxis.title.visible and valueAxis.title.visible should be set to false in the new spec
  79. if (!itemAxisVisibleProp) {
  80. model.properties.push({
  81. id: 'itemAxis.title.visible',
  82. value: false
  83. });
  84. }
  85. if (!valueAxisVisibleProp) {
  86. model.properties.push({
  87. id: 'valueAxis.title.visible',
  88. value: false
  89. });
  90. }
  91. } else {
  92. //if the title.visible is set to true in the old spec, then both itemAxis.title.visible and valueAxis.title.visible should be set to the values of their deprected values
  93. if (!itemAxisVisibleProp && deprecatedItemAxisVisibleProp) {
  94. model.properties.push({
  95. id: 'itemAxis.title.visible',
  96. value: deprecatedItemAxisVisibleProp.value
  97. });
  98. }
  99. if (!valueAxisVisibleProp && deprecatedValueAxisVisibleProp) {
  100. model.properties.push({
  101. id: 'valueAxis.title.visible',
  102. value: deprecatedValueAxisVisibleProp.value
  103. });
  104. }
  105. }
  106. // either of the scenarios above will leave the two new props to pick up default values which is true
  107. };
  108. VIDAPropUpgrade.prototype._optimizeSizePropertyUpgrade = function _optimizeSizePropertyUpgrade(model) {
  109. var optimizeSizePropId = 'optimizeSize';
  110. var deprecatedOptimizeSizeProp = WidgetUpgradeUtils.findProperty(optimizeSizePropId, model.properties);
  111. // for network visualization, we have previously set the default value to true but did not save in the model
  112. var excludedVisId = 'com.ibm.vis.rave2network';
  113. // if the value does not exist in the model, set the value to false, otherwise keeps the old value
  114. if (!deprecatedOptimizeSizeProp) {
  115. // the optimizeSize property should be upgraded to value false
  116. model.properties.push({
  117. id: optimizeSizePropId,
  118. value: model.visId === excludedVisId ? true : false
  119. });
  120. }
  121. };
  122. VIDAPropUpgrade.prototype._preserveItemAxisPositionForHeatmap = function _preserveItemAxisPositionForHeatmap(model) {
  123. var heatMapWidgetId = 'com.ibm.vis.rave2heat';
  124. if (model.visId !== heatMapWidgetId) {
  125. return;
  126. }
  127. // introduced in helios r8 with default value as 'top'
  128. var itemAxisAlignmentKey = 'itemAxis.alignment',
  129. itemAxisAlignmentVal = 'top',
  130. oldAlignProp = WidgetUpgradeUtils.findProperty(itemAxisAlignmentKey, model.properties),
  131. alignPropPossibilities = ['top', 'bottom'];
  132. // introduced in helios r9 with default value as 'automatic'
  133. var itemAxisLayoutKey = 'itemAxis.labels.layoutMode',
  134. itemAxisLayoutVal = 'automatic',
  135. oldLayoutProp = WidgetUpgradeUtils.findProperty(itemAxisLayoutKey, model.properties),
  136. layoutPropPossibilites = ['rotate90', 'automatic', 'horizontal', 'rotate45', 'stagger'];
  137. if (!oldAlignProp || alignPropPossibilities.indexOf(oldAlignProp.value) === -1) {
  138. model.properties.push({
  139. id: itemAxisAlignmentKey,
  140. value: itemAxisAlignmentVal
  141. });
  142. }
  143. if (!oldLayoutProp || layoutPropPossibilites.indexOf(oldLayoutProp.value) === -1) {
  144. model.properties.push({
  145. id: itemAxisLayoutKey,
  146. value: itemAxisLayoutVal
  147. });
  148. }
  149. };
  150. VIDAPropUpgrade.prototype._stackedPercentPropertyUpgrade = function _stackedPercentPropertyUpgrade(model) {
  151. // area chart only
  152. var areaChartId = 'com.ibm.vis.rave2bundlearea';
  153. if (model.visId !== areaChartId) {
  154. return;
  155. }
  156. var deprecatedStackedPercentPropId = 'stacked.percent',
  157. dataHandlingPropId = 'data.handling';
  158. // if the value is true, update the value with 'Stacked100' for 'data.handling', otherwise clean the deprecated properties
  159. this._upgradeBooleanProperty(model, deprecatedStackedPercentPropId, dataHandlingPropId, 'Stacked100');
  160. };
  161. VIDAPropUpgrade.prototype._linesSmoothPropertyUpgrade = function _linesSmoothPropertyUpgrade(model) {
  162. // area chart and line chart only
  163. var areaChartId = 'com.ibm.vis.rave2bundlearea',
  164. lineChartId = 'com.ibm.vis.rave2line';
  165. if (model.visId === areaChartId || model.visId === lineChartId) {
  166. var deprecatedLinesSmoothPropId = 'lines.smooth';
  167. var interpolatePropId = model.visId === areaChartId ? 'area.interpolate' : 'line.interpolate';
  168. // if the value is true, update the value with 'cardinal' for 'xx.interpolate', otherwise clean the deprecated properties
  169. this._upgradeBooleanProperty(model, deprecatedLinesSmoothPropId, interpolatePropId, 'cardinal');
  170. }
  171. };
  172. VIDAPropUpgrade.prototype._upgradePieChart = function _upgradePieChart(model) {
  173. var pieChartId = 'com.ibm.vis.rave2bundlepie';
  174. if (model.visId !== pieChartId) {
  175. return;
  176. }
  177. this._upgradePieChartLabelLocation(model);
  178. };
  179. VIDAPropUpgrade.prototype._upgradePieChartLabelLocation = function _upgradePieChartLabelLocation(model) {
  180. var labelPropId = 'labelLocation';
  181. var deprecatedLabelLocPropVal = 'none';
  182. var defaultLabelLocPropVal = 'centerHorizontal';
  183. var validValues = ['centerHorizontal', 'callout', 'center'];
  184. var labelLocProp = WidgetUpgradeUtils.findProperty(labelPropId, model.properties);
  185. var labelVisibilityId = 'labels.visible';
  186. if (labelLocProp && labelLocProp.value && validValues.indexOf(labelLocProp.value) === -1) {
  187. // if the labelloc val is none we remove the label and return, otherwise we cleanup the old value, add the new default and showlabel values
  188. model.properties = _.filter(model.properties, function (prop) {
  189. return !_.contains(labelLocProp, prop.id);
  190. });
  191. if (labelLocProp.value === deprecatedLabelLocPropVal) {
  192. return model.properties.push({
  193. id: labelVisibilityId,
  194. value: false
  195. });
  196. }
  197. }
  198. // default pie chart from helios has no labelLocation or label visibility property but usually defaults to center horizontal, we catch the lack of a property here
  199. var labelVisibilityProp = WidgetUpgradeUtils.findProperty(labelVisibilityId, model.properties);
  200. if (!labelVisibilityProp) {
  201. model.properties.push({
  202. id: labelVisibilityId,
  203. value: true
  204. });
  205. }
  206. if (!labelLocProp) {
  207. model.properties.push({
  208. id: labelPropId,
  209. value: defaultLabelLocPropVal
  210. });
  211. }
  212. };
  213. /**
  214. * Upgrade a boolean type property.
  215. *
  216. * @param {object} model - model to perform upgrade on
  217. * @param {string} oldPropId -the deprecated prop id
  218. * @param {string} newPropId - the new prop id
  219. * @param {any} trueValue - value to set for the new prop when the deprecated value is set to true
  220. * @param {any} falseValue - value to set for the new prop when the deprecated value is set to false or is undefined
  221. *
  222. * @return {object} spec after upgraded
  223. */
  224. VIDAPropUpgrade.prototype._upgradeBooleanProperty = function _upgradeBooleanProperty(model, oldPropId, newPropId, trueValue, falseValue) {
  225. var deprecatedProp = WidgetUpgradeUtils.findProperty(oldPropId, model.properties);
  226. model.properties = _.filter(model.properties, function (prop) {
  227. return prop.id !== oldPropId;
  228. });
  229. if (deprecatedProp && deprecatedProp.value) {
  230. model.properties.push({
  231. id: newPropId,
  232. value: trueValue
  233. });
  234. } else {
  235. if (!_.isUndefined(falseValue)) {
  236. model.properties.push({
  237. id: newPropId,
  238. value: falseValue
  239. });
  240. }
  241. }
  242. };
  243. return VIDAPropUpgrade;
  244. }(UpgradeBase);
  245. return new VIDAPropUpgrade();
  246. });
  247. //# sourceMappingURL=VIDAPropUpgrade.js.map