123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596 |
- 'use strict';
- /*
- *+------------------------------------------------------------------------+
- *| Licensed Materials - Property of IBM
- *| IBM Cognos Products: BI Dashboard
- *| (C) Copyright IBM Corp. 2018
- *|
- *| US Government Users Restricted Rights - Use, duplication or disclosure
- *| restricted by GSA ADP Schedule Contract with IBM Corp.
- *+------------------------------------------------------------------------+
- */
- define(['underscore', '../../../lib/@waca/core-client/js/core-client/ui/core/Class', '../../../lib/@waca/upgrades/UpgradeBase', './utils/WidgetUpgradeUtils'], function (_, Class, UpgradeBase, WidgetUpgradeUtils) {
- 'use strict';
- var Upgrade = Class.extend([UpgradeBase], {
- init: function init() {
- this.VERSION = 1008;
- },
- /**
- * Perform upgrade
- *
- * @param {object} spec - spec to perform upgrade on
- *
- * @return {Promise} Promise to be resolved when upgrade performed
- */
- up: function up(spec) {
- if (spec.widgets) {
- this._upgradeWidgets(spec);
- }
- return Promise.resolve(spec);
- },
- _supportsAxisLabelVerticalProperty: function _supportsAxisLabelVerticalProperty(widget) {
- var supportedVisIds = ['com.ibm.vis.rave2line', 'com.ibm.vis.rave2point'];
- return supportedVisIds.indexOf(widget.visId) > -1;
- },
- _upgradeWidgets: function _upgradeWidgets(spec) {
- var _this = this;
- try {
- _.each(spec.widgets, function (widget) {
- // itemAxis.labels.vertical property is only available for line and point visualization
- // check the visId before upgrading the property
- if (_this._supportsAxisLabelVerticalProperty(widget)) {
- _this._upgradeItemAxisLabelVerticalProperty(widget);
- }
- });
- } catch (error) {
- throw error;
- }
- },
- _upgradeItemAxisLabelVerticalProperty: function _upgradeItemAxisLabelVerticalProperty(model) {
- /*
- Pre R8, the property name for label orientation is 'itemAxis.labels.vertical' and it is a boolean property with default value to false.
- The property has been upgrader starting from R9 using the name as 'itemAxis.labels.layoutMode' which is an enum type property.
- The scenarios that need to be considered are:
- 1) Upgrade from pre R8, which should be set the new prop value as 'horizontal' for default true value,set new prop as 'rotate90' for vertical value to true
- 2) Upgrade from R9, R10 or R11, which need to check if the new property exists, if so using the new property values and clean the old one
- 3) Upgrade from R12 or R13 with default value 'automatic', the spec version for R12 is 1008, which is already higher then this upgrader, so this scenario is safe, since from here the prop has the same behavior as endor
- */
- var deprecatedPropName = 'itemAxis.labels.vertical';
- var newPropName = 'itemAxis.labels.layoutMode';
- var oldProp = WidgetUpgradeUtils.findProperty(deprecatedPropName, model.properties);
- var newProp = WidgetUpgradeUtils.findProperty(newPropName, model.properties);
- // remove the old property as its no longer being used
- model.properties = _.filter(model.properties, function (prop) {
- return prop.id !== deprecatedPropName;
- });
- // if new prop exists just return
- if (newProp) {
- return;
- }
- // if the oldProp does not exist or set value false, set the new prop as 'horizontal', otherwise set as 'rotate90'
- var propValue = oldProp && oldProp.value ? 'rotate90' : 'horizontal';
- model.properties.push({
- id: newPropName,
- value: propValue
- });
- },
- down: function down(spec) {
- return Promise.resolve(spec);
- }
- });
- return new Upgrade();
- });
- //# sourceMappingURL=R9toR10.js.map
|