123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218 |
- 'use strict';
- var _extends = Object.assign || function (target) { for (var i = 1; i < arguments.length; i++) { var source = arguments[i]; for (var key in source) { if (Object.prototype.hasOwnProperty.call(source, key)) { target[key] = source[key]; } } } return target; };
- 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. 2020
- *|
- *| 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/utils/UniqueId', '../../../lib/@waca/upgrades/UpgradeBase', './utils/WidgetUpgradeUtils'], function (_, UniqueId, UpgradeBase, WidgetUpgradeUtils) {
- var CHART_ID = 'com.ibm.vis.rave2bundlecomposite';
- // The id map with all boolean properties that are needed to change type
- var PROPERTY_TYPE_UPGRADE_MAP = {
- 'lines.smooth': {
- newPropId: 'lineWithPoints.interpolate',
- trueValue: 'cardinal',
- falseValue: 'linear',
- defaultValue: 'linear'
- },
- 'markers.visible': {
- newPropId: 'lineWithPoints.display',
- trueValue: 'line_points',
- falseValue: 'line',
- defaultValue: 'line_points'
- }
- };
- // The id map with all properties that are needed to change name
- var PROPERTY_NAME_UPGRADE_MAP = {
- 'gridLines.visible': ['valueAxis.gridLines.visible', 'itemAxis.gridLines.visible'],
- 'valueAxis.title.visible': ['valueAxis.column.title.visible', 'valueAxis.line.title.visible'],
- 'valueLabels.visible': ['column.valueLabels.visible', 'lineWithPoints.valueLabels.visible'],
- 'valueLabels.color': ['column.valueLabels.color', 'lineWithPoints.valueLabels.color'],
- 'valueLabels.font': ['column.valueLabels.font', 'lineWithPoints.valueLabels.font'],
- 'valueAxis.ticks.labels.visible': ['valueAxis.column.ticks.labels.visible', 'valueAxis.line.ticks.labels.visible'],
- 'valueAxis.ticks.labels.color': ['valueAxis.column.ticks.labels.color', 'valueAxis.line.ticks.labels.color'],
- 'valueAxis.ticks.labels.font': ['valueAxis.column.ticks.labels.font', 'valueAxis.line.ticks.labels.font'],
- 'valueAxis.ticks.visible': ['valueAxis.column.ticks.visible', 'valueAxis.line.ticks.visible'],
- 'valueAxis.ticks.color': ['valueAxis.column.ticks.color', 'valueAxis.line.ticks.color'],
- 'colorPalette': ['colorPalette_column', 'colorPalette_line'],
- 'defaultPaletteIndex': ['colorPalette_column_defaultIndex'],
- 'compositeLineColor': ['colorPalette_line_defaultIndex']
- };
- var CompositeChartV2Upgrade = function (_UpgradeBase) {
- _inherits(CompositeChartV2Upgrade, _UpgradeBase);
- function CompositeChartV2Upgrade() {
- _classCallCheck(this, CompositeChartV2Upgrade);
- var _this = _possibleConstructorReturn(this, _UpgradeBase.call(this));
- _this.VERSION = 1803;
- return _this;
- }
- /**
- * Perform upgrade
- *
- * @param {object} spec - spec to perform upgrade on
- *
- * @return {Promise} Promise to be resolved when upgrade performed
- */
- CompositeChartV2Upgrade.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 (WidgetUpgradeUtils.isLiveWidgetModel(model)) {
- if (!model.properties) {
- model.properties = [];
- }
- if (model.visId === CHART_ID) {
- Object.keys(PROPERTY_TYPE_UPGRADE_MAP).forEach(function (oldPropId) {
- return _this2._upgradeBooleanProperty(_extends({ model: model, oldPropId: oldPropId }, PROPERTY_TYPE_UPGRADE_MAP[oldPropId]));
- });
- Object.keys(PROPERTY_NAME_UPGRADE_MAP).forEach(function (oldPropId) {
- return _this2._upgradePropertyName(model, oldPropId, PROPERTY_NAME_UPGRADE_MAP[oldPropId]);
- });
- _this2._splitDataView(model);
- }
- }
- });
- return Promise.resolve(spec);
- };
- // Downgrades are not available in CA
- CompositeChartV2Upgrade.prototype.down = function down(spec) {
- return Promise.resolve(spec);
- };
- /**
- * Upgrade a boolean type property to a non-boolean type property.
- *
- * @param {object} options.model - model to perform upgrade on
- * @param {string} options.oldPropId -the deprecated prop id
- * @param {string} options.newPropId - the new prop id
- * @param {any} options.trueValue - value to set for the new prop when the deprecated value is set to true
- * @param {any} options.falseValue - value to set for the new prop when the deprecated value is set to false
- * @param {any} options.defaultValue - value to set for the new prop when the deprecated value is undefined
- */
- CompositeChartV2Upgrade.prototype._upgradeBooleanProperty = function _upgradeBooleanProperty(options) {
- var model = options.model,
- oldPropId = options.oldPropId,
- newPropId = options.newPropId,
- trueValue = options.trueValue,
- falseValue = options.falseValue,
- defaultValue = options.defaultValue;
- var deprecatedProp = WidgetUpgradeUtils.findProperty(oldPropId, model.properties);
- if (!deprecatedProp) {
- return;
- }
- model.properties = _.filter(model.properties, function (prop) {
- return prop.id !== oldPropId;
- });
- if (deprecatedProp.value && defaultValue !== trueValue) {
- model.properties.push({
- id: newPropId,
- value: trueValue
- });
- } else if (!deprecatedProp.value && defaultValue !== falseValue) {
- model.properties.push({
- id: newPropId,
- value: falseValue
- });
- }
- };
- /**
- * Upgrade a old property id to a new one(s) with the same property value.
- *
- * @param {object} model - model to perform upgrade on
- * @param {string} oldPropId -the deprecated prop id
- * @param {string} newPropIds - the list of new prop ids
- */
- CompositeChartV2Upgrade.prototype._upgradePropertyName = function _upgradePropertyName(model, oldId, newIds) {
- var deprecatedProp = WidgetUpgradeUtils.findProperty(oldId, model.properties);
- if (deprecatedProp && !_.isUndefined(deprecatedProp.value)) {
- model.properties = _.filter(model.properties, function (prop) {
- return prop.id !== oldId;
- });
- newIds.forEach(function (id) {
- model.properties.push({
- id: id,
- value: deprecatedProp.value
- });
- });
- }
- };
- CompositeChartV2Upgrade.prototype._splitDataView = function _splitDataView(model) {
- if (!model.data || _.isEmpty(model.data.dataViews)) {
- return;
- }
- var dataViews = model.data && model.data.dataViews;
- var columnDataView = dataViews[0];
- var slots = model.slotmapping && model.slotmapping.slots;
- var lineValueSlot = slots.find(function (slot) {
- return slot.name === 'lineValue';
- });
- slots.forEach(function (slot) {
- delete slot.layerId;
- });
- if (lineValueSlot) {
- var lineValueDataItemId = lineValueSlot.dataItems[0];
- var lineValueDataItemIndex = columnDataView.dataItems.findIndex(function (dataItem) {
- return dataItem.id === lineValueDataItemId;
- });
- var lineValueDataItem = columnDataView.dataItems.splice(lineValueDataItemIndex, 1);
- dataViews.push({
- modelRef: columnDataView.modelRef,
- dataItems: lineValueDataItem,
- id: UniqueId.get('model')
- });
- }
- };
- return CompositeChartV2Upgrade;
- }(UpgradeBase);
- return new CompositeChartV2Upgrade();
- });
- //# sourceMappingURL=CompositeChartV2Upgrade.js.map
|