'use strict'; function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } } 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; } 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; } /* *+------------------------------------------------------------------------+ *| 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/upgrades/UpgradeBase', './utils/WidgetUpgradeUtils'], function (_, UpgradeBase, WidgetUpgradeUtils) { /** * Upgrade VIDA property. Remove title.visible from the old spec and introduce 'itemAxis.title.visible' and 'valueAxis.title.visible' instead. **/ var VIDAPropUpgrade = function (_UpgradeBase) { _inherits(VIDAPropUpgrade, _UpgradeBase); function VIDAPropUpgrade() { _classCallCheck(this, VIDAPropUpgrade); var _this = _possibleConstructorReturn(this, _UpgradeBase.call(this)); _this.VERSION = 1013; return _this; } /** * Perform upgrade * * @param {object} spec - spec to perform upgrade on * * @return {Promise} Promise to be resolved when upgrade performed */ VIDAPropUpgrade.prototype.up = function up(spec) { var _this2 = this; if (!spec) { return Promise.resolve(spec); } if (!WidgetUpgradeUtils.specHasWidgets(spec)) { return Promise.resolve(spec); } _.each(spec.widgets, function (model) { if (model && _this2._isLive(model)) { if (!model.properties) { model.properties = []; } _this2._showAxisTitlesPropertyUpgrade(model); _this2._optimizeSizePropertyUpgrade(model); _this2._preserveItemAxisPositionForHeatmap(model); _this2._stackedPercentPropertyUpgrade(model); _this2._linesSmoothPropertyUpgrade(model); _this2._upgradePieChart(model); } }); return Promise.resolve(spec); }; // Downgrades are not available in CA VIDAPropUpgrade.prototype.down = function down(spec) { return Promise.resolve(spec); }; VIDAPropUpgrade.prototype._isLive = function _isLive(model) { return model && model.type && model.type === 'live'; }; VIDAPropUpgrade.prototype._showAxisTitlesPropertyUpgrade = function _showAxisTitlesPropertyUpgrade(model) { var deprecatedProps = ['titles.visible', 'itemAxis.labels.visible', 'valueAxis.labels.visible']; // old spec : title.visible, itemAxis.labels.visible, valueAxis.labels.visible var deprecatedshowAxisTitlesProp = WidgetUpgradeUtils.findProperty('titles.visible', model.properties); var deprecatedItemAxisVisibleProp = WidgetUpgradeUtils.findProperty('itemAxis.labels.visible', model.properties); var deprecatedValueAxisVisibleProp = WidgetUpgradeUtils.findProperty('valueAxis.labels.visible', model.properties); // new spec : itemAxis.title.visible, valueAxis.title.visible var itemAxisVisibleProp = WidgetUpgradeUtils.findProperty('itemAxis.title.visible', model.properties); var valueAxisVisibleProp = WidgetUpgradeUtils.findProperty('valueAxis.title.visible', model.properties); // clean up the spec poperties by filter out the deprecated props model.properties = _.filter(model.properties, function (prop) { return !_.contains(deprecatedProps, prop.id); }); if (deprecatedshowAxisTitlesProp && deprecatedshowAxisTitlesProp.value === false) { //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 if (!itemAxisVisibleProp) { model.properties.push({ id: 'itemAxis.title.visible', value: false }); } if (!valueAxisVisibleProp) { model.properties.push({ id: 'valueAxis.title.visible', value: false }); } } else { //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 if (!itemAxisVisibleProp && deprecatedItemAxisVisibleProp) { model.properties.push({ id: 'itemAxis.title.visible', value: deprecatedItemAxisVisibleProp.value }); } if (!valueAxisVisibleProp && deprecatedValueAxisVisibleProp) { model.properties.push({ id: 'valueAxis.title.visible', value: deprecatedValueAxisVisibleProp.value }); } } // either of the scenarios above will leave the two new props to pick up default values which is true }; VIDAPropUpgrade.prototype._optimizeSizePropertyUpgrade = function _optimizeSizePropertyUpgrade(model) { var optimizeSizePropId = 'optimizeSize'; var deprecatedOptimizeSizeProp = WidgetUpgradeUtils.findProperty(optimizeSizePropId, model.properties); // for network visualization, we have previously set the default value to true but did not save in the model var excludedVisId = 'com.ibm.vis.rave2network'; // if the value does not exist in the model, set the value to false, otherwise keeps the old value if (!deprecatedOptimizeSizeProp) { // the optimizeSize property should be upgraded to value false model.properties.push({ id: optimizeSizePropId, value: model.visId === excludedVisId ? true : false }); } }; VIDAPropUpgrade.prototype._preserveItemAxisPositionForHeatmap = function _preserveItemAxisPositionForHeatmap(model) { var heatMapWidgetId = 'com.ibm.vis.rave2heat'; if (model.visId !== heatMapWidgetId) { return; } // introduced in helios r8 with default value as 'top' var itemAxisAlignmentKey = 'itemAxis.alignment', itemAxisAlignmentVal = 'top', oldAlignProp = WidgetUpgradeUtils.findProperty(itemAxisAlignmentKey, model.properties), alignPropPossibilities = ['top', 'bottom']; // introduced in helios r9 with default value as 'automatic' var itemAxisLayoutKey = 'itemAxis.labels.layoutMode', itemAxisLayoutVal = 'automatic', oldLayoutProp = WidgetUpgradeUtils.findProperty(itemAxisLayoutKey, model.properties), layoutPropPossibilites = ['rotate90', 'automatic', 'horizontal', 'rotate45', 'stagger']; if (!oldAlignProp || alignPropPossibilities.indexOf(oldAlignProp.value) === -1) { model.properties.push({ id: itemAxisAlignmentKey, value: itemAxisAlignmentVal }); } if (!oldLayoutProp || layoutPropPossibilites.indexOf(oldLayoutProp.value) === -1) { model.properties.push({ id: itemAxisLayoutKey, value: itemAxisLayoutVal }); } }; VIDAPropUpgrade.prototype._stackedPercentPropertyUpgrade = function _stackedPercentPropertyUpgrade(model) { // area chart only var areaChartId = 'com.ibm.vis.rave2bundlearea'; if (model.visId !== areaChartId) { return; } var deprecatedStackedPercentPropId = 'stacked.percent', dataHandlingPropId = 'data.handling'; // if the value is true, update the value with 'Stacked100' for 'data.handling', otherwise clean the deprecated properties this._upgradeBooleanProperty(model, deprecatedStackedPercentPropId, dataHandlingPropId, 'Stacked100'); }; VIDAPropUpgrade.prototype._linesSmoothPropertyUpgrade = function _linesSmoothPropertyUpgrade(model) { // area chart and line chart only var areaChartId = 'com.ibm.vis.rave2bundlearea', lineChartId = 'com.ibm.vis.rave2line'; if (model.visId === areaChartId || model.visId === lineChartId) { var deprecatedLinesSmoothPropId = 'lines.smooth'; var interpolatePropId = model.visId === areaChartId ? 'area.interpolate' : 'line.interpolate'; // if the value is true, update the value with 'cardinal' for 'xx.interpolate', otherwise clean the deprecated properties this._upgradeBooleanProperty(model, deprecatedLinesSmoothPropId, interpolatePropId, 'cardinal'); } }; VIDAPropUpgrade.prototype._upgradePieChart = function _upgradePieChart(model) { var pieChartId = 'com.ibm.vis.rave2bundlepie'; if (model.visId !== pieChartId) { return; } this._upgradePieChartLabelLocation(model); }; VIDAPropUpgrade.prototype._upgradePieChartLabelLocation = function _upgradePieChartLabelLocation(model) { var labelPropId = 'labelLocation'; var deprecatedLabelLocPropVal = 'none'; var defaultLabelLocPropVal = 'centerHorizontal'; var validValues = ['centerHorizontal', 'callout', 'center']; var labelLocProp = WidgetUpgradeUtils.findProperty(labelPropId, model.properties); var labelVisibilityId = 'labels.visible'; if (labelLocProp && labelLocProp.value && validValues.indexOf(labelLocProp.value) === -1) { // 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 model.properties = _.filter(model.properties, function (prop) { return !_.contains(labelLocProp, prop.id); }); if (labelLocProp.value === deprecatedLabelLocPropVal) { return model.properties.push({ id: labelVisibilityId, value: false }); } } // 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 var labelVisibilityProp = WidgetUpgradeUtils.findProperty(labelVisibilityId, model.properties); if (!labelVisibilityProp) { model.properties.push({ id: labelVisibilityId, value: true }); } if (!labelLocProp) { model.properties.push({ id: labelPropId, value: defaultLabelLocPropVal }); } }; /** * Upgrade a boolean type property. * * @param {object} model - model to perform upgrade on * @param {string} oldPropId -the deprecated prop id * @param {string} newPropId - the new prop id * @param {any} trueValue - value to set for the new prop when the deprecated value is set to true * @param {any} falseValue - value to set for the new prop when the deprecated value is set to false or is undefined * * @return {object} spec after upgraded */ VIDAPropUpgrade.prototype._upgradeBooleanProperty = function _upgradeBooleanProperty(model, oldPropId, newPropId, trueValue, falseValue) { var deprecatedProp = WidgetUpgradeUtils.findProperty(oldPropId, model.properties); model.properties = _.filter(model.properties, function (prop) { return prop.id !== oldPropId; }); if (deprecatedProp && deprecatedProp.value) { model.properties.push({ id: newPropId, value: trueValue }); } else { if (!_.isUndefined(falseValue)) { model.properties.push({ id: newPropId, value: falseValue }); } } }; return VIDAPropUpgrade; }(UpgradeBase); return new VIDAPropUpgrade(); }); //# sourceMappingURL=VIDAPropUpgrade.js.map