7.js 6.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323
  1. 'use strict';
  2. /*
  3. *+------------------------------------------------------------------------+
  4. *| Licensed Materials - Property of IBM
  5. *| IBM Cognos Products: BI Dashboard
  6. *| (C) Copyright IBM Corp. 2016, 2017
  7. *|
  8. *| US Government Users Restricted Rights - Use, duplication or disclosure
  9. *| restricted by GSA ADP Schedule Contract with IBM Corp.
  10. *+------------------------------------------------------------------------+
  11. */
  12. define(['../../../lib/@waca/core-client/js/core-client/ui/core/Class', '../../../lib/@waca/upgrades/UpgradeBase', './RAVE1ArcheTypes', 'underscore'], function (Class, UpgradeBase, ArcheTypes, _) {
  13. /*upgrade handlers that have special logic to do properties/slots upgrade instead of just IDs conversions*/
  14. var UPGRADE_HANDLDERS = {
  15. pieAsDonutUpgradeHandler: function pieAsDonutUpgradeHandler(value) {
  16. if (value + '' !== 'true') {
  17. return 1;
  18. }
  19. return 0.4;
  20. },
  21. hideRadialValueHandler: function hideRadialValueHandler(value) {
  22. if (value + '' === 'true') {
  23. return 'none';
  24. }
  25. return 'center';
  26. }
  27. };
  28. /*Common slots and properties upgrade mappings across all widgets*/
  29. var COMMON_UPGRADE_MAPPINGS = {
  30. SLOTS: {
  31. //No common slots upgrade currently
  32. },
  33. PROPERTIES: {
  34. 'legendPosition': {
  35. 'id': 'legend.position'
  36. }
  37. }
  38. };
  39. /*Individual chart slots and properties upgrade mappings*/
  40. var UPGRADE_MAPPINGS = {
  41. 'area': {
  42. 'ID': 'RAVE2_smoothArea',
  43. 'SLOTS': {
  44. 'categories': 'x',
  45. 'color': 'color',
  46. 'values': 'y'
  47. }
  48. },
  49. 'pie': {
  50. 'ID': 'RAVE2_pie',
  51. 'SLOTS': {
  52. 'categories': 'color',
  53. 'values': 'value'
  54. },
  55. 'PROPERTIES': {
  56. 'pieAsDonut': {
  57. 'id': 'donutRadius',
  58. 'propertyValueHandler': UPGRADE_HANDLDERS.pieAsDonutUpgradeHandler
  59. },
  60. 'hideRadialValue': {
  61. 'id': 'labelLocation',
  62. 'propertyValueHandler': UPGRADE_HANDLDERS.hideRadialValueHandler
  63. }
  64. }
  65. },
  66. 'clusterLine': {
  67. 'ID': 'RAVE2_smoothline',
  68. 'SLOTS': {
  69. 'categories': 'x',
  70. 'values': 'y',
  71. 'color': 'color',
  72. 'valuesRepeating': 'y0'
  73. },
  74. 'PROPERTIES': {
  75. 'symbolShape': {
  76. 'id': 'lineWithPoints.symbol' //RAVE2 default to circle
  77. }
  78. }
  79. },
  80. 'bubble': {
  81. 'ID': 'RAVE2_bubble',
  82. 'SLOTS': {
  83. 'xAxis': 'x',
  84. 'yAxis': 'y',
  85. 'size': 'size',
  86. 'color': 'color'
  87. }
  88. },
  89. 'packedBubble': {
  90. 'ID': 'RAVE2_packedBubble',
  91. 'SLOTS': {
  92. 'categories': 'label',
  93. 'color': 'color',
  94. 'size': 'size'
  95. }
  96. },
  97. 'radial': {
  98. 'ID': 'RAVE2_multipleDialCategoryLabel',
  99. 'SLOTS': {
  100. 'categories': 'category',
  101. 'values': 'value',
  102. 'maxSize': 'maxValue'
  103. }
  104. },
  105. 'radialBar': {
  106. 'ID': 'RAVE2_dial',
  107. 'SLOTS': {
  108. 'categories': 'label',
  109. 'values': 'value'
  110. }
  111. },
  112. 'point': {
  113. 'ID': 'RAVE2_point',
  114. 'SLOTS': {
  115. 'categories': 'x',
  116. 'values': 'y',
  117. 'color': 'color'
  118. }
  119. },
  120. 'clusterColumn': {
  121. 'ID': 'RAVE2_clusteredcolumn',
  122. 'SLOTS': {
  123. 'categories': 'x',
  124. 'color': 'color',
  125. 'values': 'y',
  126. 'valuesRepeating': 'y0'
  127. }
  128. },
  129. 'stackedColumn': {
  130. 'ID': 'RAVE2_stackedcolumn',
  131. 'SLOTS': {
  132. 'categories': 'x',
  133. 'color': 'color',
  134. 'values': 'y',
  135. 'valuesRepeating': 'y0'
  136. }
  137. },
  138. 'clusterBar': {
  139. 'ID': 'RAVE2_clusteredbar',
  140. 'SLOTS': {
  141. 'categories': 'x',
  142. 'color': 'color',
  143. 'values': 'y',
  144. 'valuesRepeating': 'y0'
  145. }
  146. },
  147. 'stackedBar': {
  148. 'ID': 'RAVE2_stackedbar',
  149. 'SLOTS': {
  150. 'categories': 'x',
  151. 'color': 'color',
  152. 'values': 'y',
  153. 'valuesRepeating': 'y0'
  154. }
  155. },
  156. 'wordCloud': {
  157. 'ID': 'RAVE2_wordcloud',
  158. 'SLOTS': {
  159. 'word': 'label',
  160. 'color': 'color',
  161. 'scale': 'size'
  162. }
  163. },
  164. 'scatterPlot': {
  165. 'ID': 'RAVE2_scatter',
  166. 'SLOTS': {
  167. 'xAxis': 'x',
  168. 'yAxis': 'y',
  169. 'categories': 'label',
  170. 'color': 'color'
  171. }
  172. },
  173. 'lineColumnCombo': {
  174. 'ID': 'RAVE2_compositeSmoothOneDataSet',
  175. 'SLOTS': {
  176. 'lineValue': 'yLine',
  177. 'columnValue': 'y',
  178. 'category': 'x'
  179. },
  180. 'PROPERTIES': {
  181. 'symbolShape': {
  182. 'id': 'lineWithPoints.symbol'
  183. }
  184. }
  185. },
  186. 'heat': {
  187. 'ID': 'RAVE2_heatmap',
  188. 'SLOTS': {
  189. 'xAxis': 'x',
  190. 'yAxis': 'y',
  191. 'values': 'color'
  192. }
  193. }
  194. };
  195. var Upgrade = Class.extend([UpgradeBase], {
  196. init: function init() {
  197. this.VERSION = 7;
  198. },
  199. /**
  200. * Perform upgrade
  201. *
  202. * @param {object} spec - spec to perform upgrade on
  203. *
  204. * @return {Promise} Promise to be resolved when upgrade performed
  205. */
  206. up: function up(spec) {
  207. if (!spec) {
  208. return Promise.resolve(spec);
  209. }
  210. _.each(spec.widgets, this._widgetSpecUpgrade.bind(this));
  211. return Promise.resolve(spec);
  212. },
  213. _widgetSpecUpgrade: function _widgetSpecUpgrade(oWidgetSpec) {
  214. var sArchetype = oWidgetSpec.archetype || ArcheTypes.getArcheTypeFromVizId(oWidgetSpec.visId);
  215. if (sArchetype) {
  216. var oUpgradedArcheType = UPGRADE_MAPPINGS[sArchetype];
  217. if (oUpgradedArcheType) {
  218. if (oWidgetSpec.archetype) {
  219. oWidgetSpec.archetype = oUpgradedArcheType.ID;
  220. }
  221. oWidgetSpec.visId = oUpgradedArcheType.ID;
  222. this._slotsUpgrade(oWidgetSpec.id, oWidgetSpec.mapping, sArchetype);
  223. this._propertyUpgrade(oWidgetSpec.properties, sArchetype);
  224. }
  225. }
  226. },
  227. _propertyUpgrade: function _propertyUpgrade(properties, archetype) {
  228. _.each(properties, function (property) {
  229. this._upgradeSingleProperty(property, COMMON_UPGRADE_MAPPINGS.PROPERTIES);
  230. if (UPGRADE_MAPPINGS[archetype] && UPGRADE_MAPPINGS[archetype].PROPERTIES) {
  231. this._upgradeSingleProperty(property, UPGRADE_MAPPINGS[archetype].PROPERTIES);
  232. }
  233. }.bind(this));
  234. },
  235. _upgradeSingleProperty: function _upgradeSingleProperty(property, propertiesMap) {
  236. var oMatched = propertiesMap[property.id];
  237. if (oMatched) {
  238. var sValue = property.value;
  239. if (oMatched.propertyValueHandler) {
  240. sValue = oMatched.propertyValueHandler(property.value);
  241. }
  242. property.id = oMatched.id;
  243. property.value = sValue;
  244. }
  245. },
  246. _slotsUpgrade: function _slotsUpgrade(widgetID, oOldSlots, sArchetype) {
  247. var oMappedRave2Slots = UPGRADE_MAPPINGS[sArchetype].SLOTS;
  248. _.each(oOldSlots, function (slot) {
  249. var sId = oMappedRave2Slots[slot.slotId];
  250. if (!sId) {
  251. var logger = this.data && this.data.logger && this.data.logger;
  252. if (logger) {
  253. this.data.logger.warn('No id for ' + widgetID + ' archetype ' + sArchetype + ' slotId ' + slot.slotId);
  254. }
  255. } else {
  256. slot.id = sId;
  257. slot.slotId = sId;
  258. }
  259. }.bind(this));
  260. },
  261. down: function down(spec) {
  262. // no downgrade at this time; return as is
  263. return Promise.resolve(spec);
  264. }
  265. });
  266. return new Upgrade();
  267. });
  268. //# sourceMappingURL=7.js.map