waca.js 24 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886
  1. 'use strict';
  2. /*
  3. *+------------------------------------------------------------------------+
  4. *| Licensed Materials - Property of IBM
  5. *| IBM Cognos Products: BI Dashboard
  6. *| (C) Copyright IBM Corp. 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(['underscore', '../../../lib/@waca/core-client/js/core-client/ui/core/Class', '../../../lib/@waca/upgrades/UpgradeBase'], function (_, Class, UpgradeBase) {
  13. //NOSONAR
  14. var _commonPropertiesMap = {
  15. elementColor: 'defaultPaletteIndex',
  16. colorPalette: 'contColorPalette',
  17. legendPosition: 'widget.legend.position'
  18. };
  19. var _unChangedCommonProperties = ['colorPalette', 'queryRefresh', 'legendTitleColor', 'legendBodyColor', 'axisLineColor', 'axisGridLineColor', 'elementsLabelColor', 'axisLabelColor', 'axisTitleFontColor', 'axisTitleFont', 'axisLabelFont', 'elementsStyleFont', 'legendTitleFont', 'legendBodyFont'];
  20. var _visMapping = {
  21. JQGrid: 'JQGrid',
  22. crosstab: 'crosstab',
  23. dataPlayer: 'dataPlayer',
  24. /*hierarchy visualizations*/
  25. list: 'list',
  26. hierarchy2: 'list',
  27. hierarchy3: 'list',
  28. /*hierarchy*/
  29. /*legacy maps*/
  30. map1measure: 'com.ibm.vis.rave2polygonmap',
  31. map2measure: 'com.ibm.vis.rave2polygonmap',
  32. map3measure: 'com.ibm.vis.rave2polygonmap',
  33. /*legacy maps*/
  34. RAVE2_bubble: 'com.ibm.vis.ravebubble',
  35. RAVE2_clusteredcolumn: 'com.ibm.vis.rave2bundlecolumn',
  36. RAVE2_clusteredbar: 'com.ibm.vis.rave2bundlebar',
  37. RAVE2_compositeSmoothOneDataSet: 'com.ibm.vis.rave2bundlecomposite',
  38. RAVE2_dial: 'com.ibm.vis.rave2bundleradialbar',
  39. RAVE2_multipleDialCategoryLabel: 'com.ibm.vis.rave2bundleradialbar',
  40. RAVE2_heatmap: 'com.ibm.vis.rave2heat',
  41. RAVE2_packedBubble: 'com.ibm.vis.rave2bundlepackedbubble',
  42. RAVE2_pie: 'com.ibm.vis.rave2bundlepie',
  43. RAVE2_point: 'com.ibm.vis.rave2point',
  44. RAVE2_scatter: 'com.ibm.vis.ravescatter',
  45. RAVE2_smoothArea: 'com.ibm.vis.rave2bundlearea',
  46. RAVE2_smoothline: 'com.ibm.vis.rave2line',
  47. RAVE2_stackedcolumn: 'com.ibm.vis.rave2bundlestackedcolumn',
  48. RAVE2_stackedbar: 'com.ibm.vis.rave2bundlestackedbar',
  49. RAVE2_tiledmap: 'com.ibm.vis.rave2bundletiledmap',
  50. RAVE2_wordcloud: 'com.ibm.vis.rave2bundlewordcloud',
  51. summary: 'summary',
  52. /*treemaps*/
  53. treeMap1Cat1MeasureChart: 'com.ibm.vis.rave2bundletreemap',
  54. treeMap1Cat2MeasureChart: 'com.ibm.vis.rave2bundletreemap',
  55. treeMap2Cat1MeasureChart: 'com.ibm.vis.rave2bundletreemap',
  56. treeMap2Cat2MeasureChart: 'com.ibm.vis.rave2bundletreemap',
  57. treeMap3Cat1MeasureChart: 'com.ibm.vis.rave2bundletreemap',
  58. treeMap3Cat2MeasureChart: 'com.ibm.vis.rave2bundletreemap'
  59. /*treemaps*/
  60. };
  61. var _widgetTypeMapping = {
  62. data: 'live'
  63. };
  64. var _slotNameMapping = {
  65. 'com.ibm.vis.ravebubble': {
  66. label: 'categories'
  67. },
  68. 'com.ibm.vis.ravescatter': {
  69. label: 'categories'
  70. },
  71. 'com.ibm.vis.rave2bundlearea': {
  72. x: 'categories',
  73. color: 'series',
  74. y: 'values'
  75. },
  76. 'com.ibm.vis.rave2bundlebar': {
  77. x: 'categories',
  78. y: 'values'
  79. },
  80. 'com.ibm.vis.rave2bundlestackedbar': {
  81. x: 'categories',
  82. y: 'values'
  83. },
  84. 'com.ibm.vis.rave2bundlecolumn': {
  85. x: 'categories',
  86. y: 'values'
  87. },
  88. 'com.ibm.vis.rave2bundlestackedcolumn': {
  89. x: 'categories',
  90. y: 'values'
  91. },
  92. 'com.ibm.vis.rave2bundlecomposite': {
  93. x: 'categories',
  94. y: 'columnValue',
  95. yLine: 'lineValue'
  96. },
  97. 'com.ibm.vis.rave2line': {
  98. x: 'categories',
  99. color: 'series',
  100. y: 'values'
  101. },
  102. 'com.ibm.vis.rave2point': {
  103. x: 'categories',
  104. color: 'series',
  105. y: 'values'
  106. },
  107. 'com.ibm.vis.rave2bundlepie': {
  108. color: 'categories',
  109. value: 'values'
  110. },
  111. 'com.ibm.vis.rave2bundleradialbar': {
  112. label: 'categories',
  113. color: 'color',
  114. value: 'values',
  115. category: 'repeatHorizontal'
  116. },
  117. 'com.ibm.vis.rave2bundletreemap': {
  118. values: 'size',
  119. 'level': 'categories'
  120. },
  121. 'com.ibm.vis.rave2heat': {
  122. x: 'series',
  123. y: 'categories'
  124. },
  125. 'com.ibm.vis.rave2bundletiledmap': {
  126. /*map*/
  127. featureId: 'locations',
  128. featureIdRefinement: 'locations',
  129. value: 'locationColor',
  130. /*legacy map*/
  131. categories: 'locations',
  132. values: 'locationColor',
  133. size: 'pointSize',
  134. sizeHeat: 'pointColor'
  135. },
  136. 'com.ibm.vis.rave2polygonmap': {
  137. sizeHeat: 'pointColor'
  138. },
  139. 'com.ibm.vis.rave2bundlepackedbubble': {
  140. label: 'categories'
  141. },
  142. 'com.ibm.vis.rave2bundlewordcloud': {
  143. label: 'categories'
  144. },
  145. 'crosstab': {
  146. column_level: 'column_level1',
  147. row_level: 'row_level1',
  148. values: 'values'
  149. },
  150. 'dataPlayer': {
  151. categories: 'category'
  152. },
  153. 'list': {
  154. level: 'level1',
  155. _default: 'level1'
  156. },
  157. 'JQGrid': {
  158. grid_cols: 'grid_cols'
  159. },
  160. 'summary': {}
  161. };
  162. var _slotTypeMapping = {
  163. category: 'categorical'
  164. };
  165. var defaultSlotIdMap = {
  166. 'summary': function summary() /* model, item */{
  167. return 'values';
  168. },
  169. 'RAVE2_clusteredbar': function RAVE2_clusteredbar(model, item) {
  170. return this._getSlotNameForBarColumnLine(model, item, 'y', 'x');
  171. },
  172. 'RAVE2_clusteredcolumn': function RAVE2_clusteredcolumn(model, item) {
  173. return this._getSlotNameForBarColumnLine(model, item, 'x', 'y');
  174. },
  175. 'RAVE2_smoothline': function RAVE2_smoothline(model, item) {
  176. return this._getSlotNameForBarColumnLine(model, item, 'x', 'y');
  177. },
  178. 'list': function list() {
  179. return 'level';
  180. },
  181. 'RAVE2_compositeSmoothOneDataSet': function RAVE2_compositeSmoothOneDataSet(model, item) {
  182. var slotName;
  183. if (item.sourceCategory === 'measure' || item.type === 'fact') {
  184. var lineValueAssigned = _.find(model.slotmapping.slots, function (slot) {
  185. return slot.name === 'lineValue';
  186. });
  187. slotName = lineValueAssigned ? 'y' : 'yLine';
  188. } else {
  189. slotName = 'x';
  190. }
  191. return slotName;
  192. },
  193. 'RAVE2_scatter': function RAVE2_scatter(model) {
  194. var slotName;
  195. if (!_.find(model.slotmapping.slots, function (slot) {
  196. return slot.name === 'categories';
  197. })) {
  198. slotName = 'label';
  199. } else if (!_.find(model.slotmapping.slots, function (slot) {
  200. return slot.name === 'color';
  201. })) {
  202. slotName = 'color';
  203. } else if (!_.find(model.slotmapping.slots, function (slot) {
  204. return slot.name === 'x';
  205. })) {
  206. slotName = 'x';
  207. } else {
  208. slotName = 'y';
  209. }
  210. return slotName;
  211. },
  212. 'JQGrid': function JQGrid() /* model, item */{
  213. return 'grid_cols';
  214. },
  215. 'RAVE2_tiledmap': function RAVE2_tiledmap(model, item) {
  216. var slotName;
  217. if (item.type === 'attribute') {
  218. if (!_.find(model.slotmapping.slots, function (slot) {
  219. return slot.name === 'locations';
  220. })) {
  221. slotName = 'locations';
  222. } else if (this._hasOnlyOneLocationsSlot(model.slotmapping.slots)) {
  223. // this could be the featureIdRefinement, map it to 'locations' too
  224. slotName = 'locations';
  225. }
  226. }
  227. if (!slotName) {
  228. if (!_.find(model.slotmapping.slots, function (slot) {
  229. return slot.name === 'locationColor';
  230. })) {
  231. slotName = 'locationColor';
  232. } else if (!_.find(model.slotmapping.slots, function (slot) {
  233. return slot.name === 'pointSize';
  234. })) {
  235. slotName = 'pointSize';
  236. } else {
  237. slotName = 'pointColor';
  238. }
  239. }
  240. return slotName;
  241. }
  242. };
  243. var Upgrade = Class.extend([UpgradeBase], {
  244. init: function init() {
  245. this.VERSION = 1004;
  246. },
  247. /**
  248. * Perform upgrade
  249. *
  250. * @param {object} spec - spec to perform upgrade on
  251. *
  252. * @return {Promise} Promise to be resolved when upgrade performed
  253. */
  254. up: function up(spec) {
  255. if (!spec.dataSources) {
  256. spec.dataSources = {
  257. sources: [],
  258. version: '1.0'
  259. };
  260. this._upgradeWidgets(spec);
  261. }
  262. return Promise.resolve(spec);
  263. },
  264. _upgradeWidgets: function _upgradeWidgets(spec) {
  265. try {
  266. _.each(spec.widgets, function (model) {
  267. if (_visMapping[model.visId]) {
  268. var dataSourceId = this._addWidgetDataSource(spec, model);
  269. model.data = {
  270. dataViews: []
  271. };
  272. this._upgradeProperties(model);
  273. this._upgradeSlotMapping(dataSourceId, model);
  274. model.type = _widgetTypeMapping[model.type];
  275. model.visId = model.archetype = _visMapping[model.visId];
  276. // remove old properties
  277. delete model.dataSet;
  278. delete model.mapping;
  279. }
  280. }.bind(this));
  281. } catch (error) {
  282. throw error;
  283. }
  284. },
  285. _addWidgetDataSource: function _addWidgetDataSource(spec, model) {
  286. if (!model.dataSet) {
  287. return undefined;
  288. }
  289. var dataSourceJSON = _.find(spec.dataSources.sources, function (source) {
  290. return source.assetId === model.dataSet.id;
  291. });
  292. if (!dataSourceJSON) {
  293. var dataSourceId = _.uniqueId('model');
  294. dataSourceJSON = {
  295. id: dataSourceId,
  296. assetId: model.dataSet.id,
  297. name: model.dataSet.name,
  298. type: model.dataSet.type,
  299. shaping: {}
  300. };
  301. spec.dataSources.sources.push(dataSourceJSON);
  302. }
  303. return dataSourceJSON.id;
  304. },
  305. _upgradeSlotMapping: function _upgradeSlotMapping(dataSourceId, model) {
  306. model.slotmapping = {
  307. slots: []
  308. };
  309. var numberOfValues = 0;
  310. if (model.visId === 'RAVE2_scatter' && _.isArray(model.mapping) && model.mapping.length === 2) {
  311. this._scatterPlotSpecialCase(model);
  312. }
  313. _.each(_.sortBy(model.mapping, 'slotId'), function (item) {
  314. var dataItemId = this._addDataItem(dataSourceId, model, item);
  315. var slotId = item.slotId || _slotNameMapping[_visMapping[model.visId]]._default;
  316. if (!slotId) {
  317. slotId = this._assignDefaultSlotId(model, item);
  318. }
  319. if (/^y[0-9]*$/.test(slotId)) {
  320. numberOfValues++;
  321. }
  322. slotId = slotId.replace(/[0-9]/g, '');
  323. var mappedSlotName = _slotNameMapping[_visMapping[model.visId]][slotId] ? _slotNameMapping[_visMapping[model.visId]][slotId] : item.slotId;
  324. var existingSlot = _.find(model.slotmapping.slots, function (slot) {
  325. return slot.name === mappedSlotName;
  326. });
  327. if (existingSlot) {
  328. existingSlot.dataItems.push(dataItemId);
  329. } else {
  330. model.slotmapping.slots.push(this._createSlot(mappedSlotName ? mappedSlotName : item.label, _slotTypeMapping[item.slotType] ? _slotTypeMapping[item.slotType] : item.slotType, dataItemId, item));
  331. }
  332. }.bind(this));
  333. if (numberOfValues > 1) {
  334. this._addMultiMeasuresItemAndSlot(model, numberOfValues);
  335. }
  336. },
  337. _scatterPlotSpecialCase: function _scatterPlotSpecialCase(model) {
  338. var mapping = model.mapping;
  339. if (mapping && mapping.length === 2) {
  340. if (this._isXYAndOrdinal(mapping[0]) && this._isXYAndOrdinal(mapping[1])) {
  341. var xSlot = _.find(mapping, function (map) {
  342. return map.slotId === 'x';
  343. });
  344. mapping.unshift({
  345. 'columnId': xSlot.columnId,
  346. 'label': xSlot.label,
  347. 'slotId': 'label',
  348. 'slotType': 'category'
  349. });
  350. }
  351. }
  352. },
  353. _isXYAndOrdinal: function _isXYAndOrdinal(mapItem) {
  354. return (mapItem.slotId === 'x' || mapItem.slotId === 'y') && mapItem.slotType === 'ordinal';
  355. },
  356. _upgradeMappingFormat: function _upgradeMappingFormat(dataItem, mappingItem) {
  357. if (!_.isEmpty(mappingItem.formatSpec)) {
  358. dataItem.format = {
  359. 'id': mappingItem.formatSpec.selectedFormat,
  360. 'formatSpec': mappingItem.formatSpec
  361. };
  362. }
  363. },
  364. _addDataItem: function _addDataItem(dataSourceId, model, item) {
  365. // find the dataView
  366. var dataView = _.find(model.data.dataViews, function (dataView) {
  367. return dataView.modelRef === dataSourceId;
  368. });
  369. if (!dataView) {
  370. dataView = {
  371. modelRef: dataSourceId,
  372. dataItems: []
  373. };
  374. model.data.dataViews.push(dataView);
  375. }
  376. var dataItem = {
  377. id: _.uniqueId('dataItem'),
  378. itemId: item.columnId,
  379. itemLabel: item.label
  380. };
  381. if (item.aggregationType) {
  382. dataItem.aggregate = item.aggregationType;
  383. }
  384. this._upgradeMappingFormat(dataItem, item);
  385. dataView.dataItems.push(dataItem);
  386. if (item.order) {
  387. dataItem.selection = [{
  388. operation: 'order',
  389. sort: {
  390. type: item.order,
  391. priority: 0,
  392. by: 'caption'
  393. }
  394. }];
  395. }
  396. if (item.limit) {
  397. if (!dataItem.selection) {
  398. dataItem.selection = [];
  399. }
  400. var selectionItem = {};
  401. selectionItem.operation = 'keep';
  402. var topBottom = {
  403. type: item.limit.op + 'count',
  404. value: item.limit.val
  405. };
  406. if (_.isObject(item.limit.rank)) {
  407. topBottom.rank = true;
  408. }
  409. selectionItem.topBottom = topBottom;
  410. if (item.limit.fact) {
  411. selectionItem.context = [{
  412. itemId: item.limit.fact
  413. }];
  414. }
  415. dataItem.selection.push(selectionItem);
  416. }
  417. return dataItem.id;
  418. },
  419. /*This is a temporary method until support is put in to the visualization recommender, where it we determine default slots for items if none are specified*/
  420. _assignDefaultSlotId: function _assignDefaultSlotId(model, item) {
  421. var slotName;
  422. if (model.visId in defaultSlotIdMap) {
  423. slotName = defaultSlotIdMap[model.visId].call(this, model, item);
  424. if (slotName) {
  425. item.slotId = slotName;
  426. }
  427. }
  428. return slotName;
  429. },
  430. _hasOnlyOneLocationsSlot: function _hasOnlyOneLocationsSlot(slotMapping) {
  431. var nbLocations = 0;
  432. for (var i = 0; i < slotMapping.length; ++i) {
  433. if (slotMapping[i].type === 'locations') {
  434. nbLocations++;
  435. }
  436. }
  437. return nbLocations === 1;
  438. },
  439. //better name would be nice
  440. _getSlotNameForBarColumnLine: function _getSlotNameForBarColumnLine(model, item, x, y) {
  441. var slotName;
  442. if (item.sourceCategory === 'measure' || item.type === 'fact') {
  443. slotName = y;
  444. } else if (!_.find(model.mapping, function (i) {
  445. return i.slotId === x;
  446. })) {
  447. slotName = x;
  448. } else {
  449. slotName = 'color';
  450. }
  451. return slotName;
  452. },
  453. _createSlot: function _createSlot(name, type, dataItemId, originalItem) {
  454. var slot = {
  455. dataItems: [dataItemId],
  456. type: type,
  457. name: name
  458. };
  459. if (originalItem.graphic) {
  460. slot.dataItemSettings = [{
  461. graphic: _.clone(originalItem.graphic),
  462. shapeDropEnabled: originalItem.shapeDropEnabled
  463. }];
  464. }
  465. return slot;
  466. },
  467. _addMultiMeasuresItemAndSlot: function _addMultiMeasuresItemAndSlot(widgetModel, numberOfValues) {
  468. var multiMeasureSlotName = this._getMultiMeasureSlotName(widgetModel);
  469. if (multiMeasureSlotName) {
  470. var multiMeasureDataItem = {
  471. 'id': '_multiMeasuresSeries',
  472. 'itemId': '_multiMeasuresSeries',
  473. 'itemLabel': 'Measures group (' + numberOfValues + ')'
  474. };
  475. widgetModel.data.dataViews[0].dataItems.push(multiMeasureDataItem);
  476. var multiMeasureSlot = _.find(widgetModel.slotmapping.slots, function (slot) {
  477. return slot.name === multiMeasureSlotName;
  478. });
  479. if (multiMeasureSlot) {
  480. multiMeasureSlot.dataItems.unshift('_multiMeasuresSeries');
  481. } else {
  482. widgetModel.slotmapping.slots.push({
  483. dataItems: ['_multiMeasuresSeries'],
  484. name: multiMeasureSlotName,
  485. type: 'any'
  486. });
  487. }
  488. }
  489. },
  490. _upgradeWordCloudProperties: function _upgradeWordCloudProperties(model, properties) {
  491. var hideLegend = this._findProperty('hideLegend', model.properties);
  492. if (!hideLegend) {
  493. var sizeSlot = _.find(model.mapping, function (item) {
  494. return item.slotId === 'size';
  495. });
  496. var colorSlot = _.find(model.mapping, function (item) {
  497. return item.slotId === 'color';
  498. });
  499. if (sizeSlot && !colorSlot) {
  500. properties.push({
  501. id: 'widget.legend.display',
  502. value: false
  503. });
  504. }
  505. }
  506. },
  507. _getMultiMeasureSlotName: function _getMultiMeasureSlotName(widgetModel) {
  508. switch (_visMapping[widgetModel.visId]) {
  509. case 'com.ibm.vis.rave2bundlebar':
  510. case 'com.ibm.vis.rave2bundlestackedbar':
  511. case 'com.ibm.vis.rave2bundlecolumn':
  512. case 'com.ibm.vis.rave2bundlestackedcolumn':
  513. {
  514. return 'color';
  515. }
  516. case 'com.ibm.vis.rave2bundlearea':
  517. case 'com.ibm.vis.rave2point':
  518. case 'com.ibm.vis.rave2line':
  519. {
  520. return 'series';
  521. }
  522. default:
  523. return null;
  524. }
  525. },
  526. _upgradeProperties: function _upgradeProperties(model) {
  527. var properties = [];
  528. switch (model.visId) {
  529. case 'RAVE2_wordcloud':
  530. {
  531. this._upgradeWordCloudProperties(model, properties);
  532. break;
  533. }
  534. case 'RAVE2_clusteredcolumn':
  535. case 'RAVE2_clusteredbar':
  536. case 'RAVE2_stackedcolumn':
  537. case 'RAVE2_stackedbar':
  538. {
  539. this._upgradeBarProperties(model, properties);
  540. break;
  541. }
  542. case 'RAVE2_smoothline':
  543. {
  544. this._upgradeLineProperties(model, properties, false /* zeroOriginValue */);
  545. break;
  546. }
  547. case 'RAVE2_smoothArea':
  548. {
  549. this._upgradeLineProperties(model, properties, true /* zeroOriginValue */);
  550. this._upgradeAutoSort(model, 'color', 'asc'); // R6: Auto(ascending), R7: Auto(none)
  551. break;
  552. }
  553. case 'RAVE2_point':
  554. {
  555. this._upgradePointProperties(model, properties);
  556. break;
  557. }
  558. case 'RAVE2_compositeSmoothOneDataSet':
  559. {
  560. this._upgradeCompositeProperties(model, properties);
  561. break;
  562. }
  563. case 'RAVE2_pie':
  564. {
  565. this._upgradePieProperties(model, properties);
  566. break;
  567. }
  568. case 'RAVE2_bubble':
  569. case 'RAVE2_scatter':
  570. {
  571. this._upgradeBubbleProperties(model, properties);
  572. break;
  573. }
  574. case 'summary':
  575. {
  576. this._upgradeSummaryProperties(model, properties);
  577. break;
  578. }
  579. case 'JQGrid':
  580. case 'crosstab':
  581. {
  582. this._upgradeTableAndCrosstabProperties(model, properties);
  583. }
  584. break;
  585. default:
  586. // log that we didn't match a visId
  587. break;
  588. }
  589. this._copyCommonProperties(model, properties);
  590. this._upgradeTitleProperty(model);
  591. model.properties = properties;
  592. },
  593. _upgradeTitleProperty: function _upgradeTitleProperty(model) {
  594. // If the previous report has a title (i.e. name) defined, then enable the showTitle property.
  595. if (model && model.name && model.name !== '') {
  596. model.showTitle = true;
  597. }
  598. },
  599. _upgradeCompositeProperties: function _upgradeCompositeProperties(model, properties) {
  600. var interpolation = this._findProperty('interpolation', model.properties);
  601. properties.push({
  602. id: 'lines.smooth',
  603. value: interpolation ? interpolation.value : false
  604. });
  605. var elementColor = this._findProperty('elementColor', model.properties);
  606. if (elementColor) {
  607. properties.push({
  608. id: 'defaultPaletteIndex',
  609. value: elementColor.value
  610. });
  611. }
  612. var lineSymbol = this._findProperty('lineWithPoints.symbol', model.properties);
  613. if (lineSymbol) {
  614. properties.push({
  615. id: 'lineWithPoints.symbol',
  616. value: this._upgradeSymbolShapeValue(lineSymbol.value)
  617. });
  618. }
  619. this._copyPropertiesUnmodified(['lineColor'], model, properties);
  620. this._setZeroOriginPropertyToValueByDefault(properties, false /* zeroOriginValue */);
  621. },
  622. _upgradeBarProperties: function _upgradeBarProperties(model, properties) {
  623. properties.push({
  624. id: 'stacked',
  625. value: model.visId.indexOf('stacked') !== -1 ? true : false
  626. });
  627. this._setZeroOriginPropertyToValueByDefault(properties, true /* zeroOriginValue */);
  628. },
  629. _upgradeSymbolShapeValue: function _upgradeSymbolShapeValue(value) {
  630. if (value === 'rectangle') {
  631. return 'horizontal-rectangle';
  632. } else if (value === 'triangle') {
  633. return 'triangle-up';
  634. } else if (value === 'poly') {
  635. return 'circle'; // There is no longer a polygon in R7
  636. }
  637. return value;
  638. },
  639. _upgradePointProperties: function _upgradePointProperties(model, properties) {
  640. properties.push({
  641. id: 'lines.visible',
  642. value: false
  643. });
  644. var symbolShape = this._findProperty('symbolShape', model.properties);
  645. if (symbolShape) {
  646. properties.push({
  647. id: 'lineWithPoints.symbol',
  648. value: this._upgradeSymbolShapeValue(symbolShape.value)
  649. });
  650. }
  651. },
  652. _upgradeLineProperties: function _upgradeLineProperties(model, properties, zeroOriginValue) {
  653. var interpolation = this._findProperty('interpolation', model.properties);
  654. properties.push({
  655. id: 'lines.smooth',
  656. value: interpolation ? interpolation.value : true
  657. });
  658. properties.push({
  659. id: 'markers.visible',
  660. value: true
  661. });
  662. properties.push({
  663. id: 'lines.visible',
  664. value: true
  665. });
  666. var hideAxisLabels = this._findProperty('hideAxisTitleLabels', model.properties);
  667. if (hideAxisLabels) {
  668. properties.push({
  669. id: 'valueAxis.labels.visible',
  670. value: !hideAxisLabels.value
  671. });
  672. }
  673. var shape = this._findProperty('lineWithPoints.symbol', model.properties);
  674. properties.push({
  675. id: 'lineWithPoints.symbol',
  676. value: shape ? this._upgradeSymbolShapeValue(shape.value) : 'circle'
  677. });
  678. this._setZeroOriginPropertyToValueByDefault(properties, zeroOriginValue);
  679. },
  680. _upgradePieProperties: function _upgradePieProperties(model, properties) {
  681. var donutRadius = this._findProperty('donutRadius', model.properties);
  682. if (donutRadius) {
  683. properties.push(donutRadius);
  684. }
  685. properties.push({
  686. id: 'pie.has.hole',
  687. value: donutRadius && donutRadius.value !== 1 ? true : false
  688. });
  689. this._copyPropertiesUnmodified(['labelLocation'], model, properties);
  690. },
  691. _upgradeBubbleProperties: function _upgradeBubbleProperties(model, properties) {
  692. var symbolShape = this._findProperty('symbolShape', model.properties);
  693. if (symbolShape) {
  694. properties.push({
  695. id: 'symbolShape',
  696. value: this._upgradeSymbolShapeValue(symbolShape.value)
  697. });
  698. }
  699. },
  700. _upgradeSummaryProperties: function _upgradeSummaryProperties(model, properties) {
  701. this._copyPropertiesUnmodified(['showItemLabel', 'valueColor', 'fillDirection'], model, properties);
  702. },
  703. _copyPropertiesUnmodified: function _copyPropertiesUnmodified(propArray, model, properties) {
  704. _.each(propArray, function (propName) {
  705. var property = this._findProperty(propName, model.properties);
  706. if (property) {
  707. properties.push(property);
  708. }
  709. }.bind(this));
  710. },
  711. _upgradeTableAndCrosstabProperties: function _upgradeTableAndCrosstabProperties(model, properties) {
  712. this._copyPropertiesUnmodified(['hideSummaries'], model, properties);
  713. },
  714. _copyCommonProperties: function _copyCommonProperties(model, properties) {
  715. if (model.properties) {
  716. this._copyPropertiesUnmodified(_unChangedCommonProperties, model, properties);
  717. _.each(_commonPropertiesMap, function (mappedValue, originalValue) {
  718. var savedProperty = this._findProperty(originalValue, model.properties);
  719. if (savedProperty) {
  720. properties.push({
  721. id: mappedValue,
  722. value: savedProperty.value
  723. });
  724. }
  725. }.bind(this));
  726. //hideLegend will no longer be used. There is now a widget.legend.display
  727. // If we hid the legend make sure legend display is now false, otherwise
  728. // let it stay as default (true)
  729. var hideLegend = this._findProperty('hideLegend', model.properties);
  730. if (hideLegend && hideLegend.value) {
  731. properties.push({
  732. id: 'widget.legend.display',
  733. value: false
  734. });
  735. }
  736. // Set Legend Position if need be
  737. var legendPosition = this._findProperty('legend.position', model.properties);
  738. if (legendPosition) {
  739. var legendPositionValue = legendPosition.value === 'none' ? 'auto' : legendPosition.value;
  740. properties.push({
  741. id: 'widget.legend.position',
  742. value: legendPositionValue
  743. });
  744. }
  745. var hideAxisTitleLabels = this._findProperty('hideAxisTitleLabels', model.properties);
  746. if (hideAxisTitleLabels && hideAxisTitleLabels.value === true) {
  747. properties.push({
  748. id: 'titles.visible',
  749. value: false
  750. });
  751. }
  752. var hideTreeMapLeafLabels = this._findProperty('hideTreeMapLeafLabels', model.properties);
  753. if (hideTreeMapLeafLabels && hideTreeMapLeafLabels.value === false) {
  754. properties.push({
  755. id: 'leaf.labels.visible',
  756. value: true
  757. });
  758. }
  759. }
  760. },
  761. _setZeroOriginPropertyToValueByDefault: function _setZeroOriginPropertyToValueByDefault(properties, toValue) {
  762. // valueAxis.zeroOrigin is a new property in WACA that is enabled by default.
  763. // We need to disable it by default for all previous
  764. properties.push({
  765. id: 'valueAxis.zeroOrigin',
  766. value: toValue
  767. });
  768. },
  769. _findProperty: function _findProperty(id, properties) {
  770. return _.find(properties, function (property) {
  771. return property.id === id;
  772. });
  773. },
  774. down: function down(spec) {
  775. return Promise.resolve(spec);
  776. },
  777. _specHasWidgets: function _specHasWidgets(spec) {
  778. if (!spec.widgets) {
  779. return false;
  780. }
  781. return Object.keys(spec.widgets).length > 0;
  782. },
  783. _upgradeAutoSort: function _upgradeAutoSort(model, slotId, order) {
  784. var item = _.find(model.mapping, function (item) {
  785. return item.slotId === slotId && !item.order;
  786. });
  787. if (item) {
  788. item.order = order;
  789. }
  790. }
  791. });
  792. return new Upgrade();
  793. });
  794. //# sourceMappingURL=waca.js.map