123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140 |
- 'use strict';
- /**
- * Licensed Materials - Property of IBM
- * IBM Cognos Products: BI Cloud (C) Copyright IBM Corp. 2014, 2019
- * US Government Users Restricted Rights - Use, duplication or disclosure restricted by GSA ADP Schedule Contract with IBM Corp.
- */
- define(['../../lib/@waca/dashboard-common/dist/core/Collection', './VisProperty', 'underscore'], function (Collection, VisProperty, _) {
- 'use strict';
- /**
- * A collection of properties used by a visualization
- */
- var VisPropertyCollection = null;
- VisPropertyCollection = Collection.extend({
- // The class of objects that this collection manages
- modelClass: VisProperty,
- // Hard coded list of multilingual visProperties. These properties came from VIPRConfig.js
- localizedPropIds: ['itemAxis.title', 'valueAxis.title', 'valueAxis.column.title', 'color.title', 'series.title', 'categories.title', 'values.title', 'size.title', 'locationColor.title', 'pointSize.title', 'pointColor.title', 'pointcolor.title', 'latlongSize.title', 'latlongColor.title', 'valueAxis.line.title', 'baseValueLabel', 'targetValueLabel'],
- init: function init(models, options) {
- // Each VisProperty is given a reference to the collection so that it can access the visModel. This is for access to the
- // theme definitions.
- this.modelConstructorOptions = {
- collection: this
- };
- options = options || {};
- // Access to the visModel for theme definitions
- this.visModel = options.visModel;
- VisPropertyCollection.inherited('init', this, arguments);
- },
- /**
- * Silently apply a set of defaults to the property collection, preserving any overrides.
- *
- * @param defaults The new set of defaults to apply
- */
- applyDefaults: function applyDefaults(defaults) {
- var options = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {};
- var currentProps = this.toJSON();
- this.reset(defaults, _.extend(options, { silent: true }));
- this.set(currentProps, _.extend(options, { remove: false, merge: true, silent: true }));
- },
- /**
- * @param propertySet - A set of properties as stored in a change:properties event (and the widget model),
- * @returns an object that contains one or more of the data properties that are defined in this set.
- */
- _getDataPropertiesAndValues: function _getDataPropertiesAndValues(propertySet) {
- var dataProperties = {};
- var maintainAxisScales = _.find(propertySet, function (property) {
- return property.id === 'maintainAxisScales';
- });
- dataProperties.maintainAxisScales = maintainAxisScales;
- return dataProperties;
- },
- /**
- * Override of Collection.toJSON to only serialize the properties that have an override
- */
- toJSON: function toJSON() {
- // only serialize the properties that have a value
- var definedProps = this.filter(function (visProp) {
- return visProp.value !== undefined;
- });
- definedProps = definedProps.map(function (entry) {
- if (entry.toJSON) {
- return entry.toJSON();
- }
- return entry;
- });
- return definedProps;
- },
- /**
- * Given a property name, will return information about it's multilingualAttribute object
- */
- getMultilingualAttribute: function getMultilingualAttribute(propertyName) {
- if (this.localizedPropIds.indexOf(propertyName) === -1) {
- return null;
- }
- var propertyModel = this.get(propertyName);
- if (!propertyModel) {
- return null;
- }
- return propertyModel.getMultilingualAttribute('value');
- },
- /**
- * Returns all the multilingual visProperties
- */
- getMultilingualAttributes: function getMultilingualAttributes() {
- var _this = this;
- var multilingualAttributes = [];
- this.localizedPropIds.forEach(function (propId) {
- var multilingualAttribute = _this.getMultilingualAttribute(propId);
- if (multilingualAttribute) {
- multilingualAttributes.push(multilingualAttribute);
- }
- });
- return multilingualAttributes;
- },
- /**
- * If there has been a change to any 'data oriented property' (one where a change means new data is needed), return true.
- * Eg: if maintainAxisScales was not set before and now it is, refresh data.
- * AND: if maintainAxisScales was set before and now its not, refresh data.
- * @propertySet - the latest property set that may or may not include a data oriented property
- * @previousPropertySet - the previous property set that may or may not include a data oriented property
- * @returns true if EITHER the current propertySet or previousPropertySet includes a property that would need data refreshed on a change.
- */
- _refreshDataNeeded: function _refreshDataNeeded(propName) {
- return propName === 'maintainAxisScales';
- },
- /**
- * Override the onModelEvent to introduce dataRefresh.
- */
- _onModelEvent: function _onModelEvent(event) {
- event.dataRefresh = this._refreshDataNeeded(event.model.id);
- VisPropertyCollection.inherited('_onModelEvent', this, arguments);
- }
- });
- return VisPropertyCollection;
- });
- //# sourceMappingURL=VisPropertyCollection.js.map
|