123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128 |
- 'use strict';
- /**
- *+------------------------------------------------------------------------+
- *| Licensed Materials - Property of IBM
- *| IBM Cognos Products: Dashboard
- *| (C) Copyright IBM Corp. 2018, 2020
- *|
- *| US Government Users Restricted Rights - Use, duplication or disclosure
- *| restricted by GSA ADP Schedule Contract with IBM Corp.
- *+------------------------------------------------------------------------+
- */
- define(['underscore', 'dashboard-analytics/widgets/livewidget/nls/StringResources', 'dashboard-analytics/visualizations/properties/PropertiesCreator', 'dashboard-analytics/visualizations/vipr/properties/ColorPropertiesCreator', 'dashboard-analytics/visualizations/vipr/VIPRUtils', '../VIPRConfig'], function (_, StringResources, PropertiesCreator, ColorPropertiesCreator, VIPRUtils, VIPRConfig) {
- 'use strict';
- /*
- * This purpose of this singleton is to create generic vida property descriptions
- * from the Vis bundles that can be stored in our model.
- */
- var PropertiesCreatorFromVisDef = function () {
- /**
- * Instance stores a reference to the Singleton
- * @type {object}
- */
- var instance = null;
- function init() {
- return {
- /**
- * We only need generic descriptions for properties in the model cache.
- * @param {String} propId - id of the property of interest
- * @param {Object} simple object with id and name defined
- */
- _createGenericProperty: function _createGenericProperty(propId) {
- return {
- 'id': propId,
- 'name': propId
- };
- },
- /**
- * @returns a list of vipr properties as an array in a format useable by
- * the properties model.
- */
- getPropertiesFromDefintion: function getPropertiesFromDefintion(visId) {
- var PropCreatorInstance = PropertiesCreator.getInstance();
- var ColorPropertiesCreatorInstance = ColorPropertiesCreator.getInstance();
- var items = [];
- // We need to use known property IDs so they match what we have supported
- // previously or have added. Vida handles property upgrade on the fly.
- var configuration = VIPRConfig.getConfig(visId) || {};
- if (configuration && configuration.config && configuration.config.include) {
- configuration.config.include.forEach(function (propertyId) {
- var propDesc = instance._createGenericProperty(propertyId);
- var property = VIPRUtils.overrideProperty(visId, propDesc, propertyId);
- items.push(property);
- });
- }
- items.push(PropCreatorInstance.getMaintainAxisScaleProperty());
- // If there are single palettes create the individual props from config.
- var singlePaletteProps = VIPRUtils.getSinglePaletteProperties(visId);
- if (singlePaletteProps) {
- Object.values(singlePaletteProps).forEach(function (palettePropDesc) {
- items.push(ColorPropertiesCreatorInstance.getSinglePaletteColorProperty(palettePropDesc));
- });
- } else {
- // Otherwise create the default one.
- items.push(ColorPropertiesCreatorInstance.getDefaultPaletteIndexProperty());
- }
- var colorPaletteProperties = ColorPropertiesCreatorInstance.getColorPalettePropertiesFromVisId(visId);
- if (colorPaletteProperties && colorPaletteProperties.length) {
- items = items.concat(colorPaletteProperties);
- }
- if (configuration.propertyList) {
- items = items.concat(configuration.propertyList);
- }
- return items;
- },
- getVizDefPropertiesFromDefinition: function getVizDefPropertiesFromDefinition(viprDefinition) {
- var items = [];
- var configuration = VIPRConfig.getConfig(viprDefinition.id) || {};
- if (configuration && configuration.config && configuration.config.include) {
- configuration.config.include.forEach(function (propertyId) {
- var propDesc = instance._createGenericProperty(propertyId);
- var vizDefPropDesc = viprDefinition.vizDef.getProperty(propertyId) || {};
- propDesc.active = true;
- propDesc = _.extend(vizDefPropDesc, propDesc);
- var property = VIPRUtils.overrideProperty(viprDefinition.id, propDesc, propertyId);
- items.push(property);
- });
- }
- // augment this array to match viprwidget.properties object functionality
- items.get = function (id) {
- return items.find(function (item) {
- return item.id === id;
- });
- };
- return items;
- }
- };
- }
- return {
- // Get the Singleton instance if one exists
- // or create one if it doesn't
- getInstance: function getInstance() {
- if (!instance) {
- instance = init();
- }
- return instance;
- }
- };
- }();
- return PropertiesCreatorFromVisDef;
- });
- //# sourceMappingURL=PropertiesCreatorFromVisDefinition.js.map
|