1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586 |
- 'use strict';
- /*
- *+------------------------------------------------------------------------+
- *| Licensed Materials - Property of IBM
- *| IBM Cognos Products: Dashboard
- *| (C) Copyright IBM Corp. 2017, 2020
- *|
- *| US Government Users Restricted Rights - Use, duplication or disclosure
- *| restricted by GSA ADP Schedule Contract with IBM Corp.
- *+------------------------------------------------------------------------+
- */
- define(['gemini/lib/@waca/dashboard-common/dist/core/Model', 'underscore'], function (Model, _) {
- 'use strict';
- /**
- * The fredIsRedModel implements the boardModelExtension defined in fredIsRed.json
- * It is used to persist information about mapped colours etc.
- */
- var FredIsRedModel = Model.extend({
- // constructor
- /**
- * The fredIsRedModel will persist a saveId (incremented each time a user saves)
- * and a colorMap (with the labels/virtual palette indexes selected based on the data).
- * The saveId can be used to optimize the table on save (though this is not yet implemented)
- */
- whitelistAttrs: ['id', 'colorMap', 'saveId'],
- //Pick a 'virtual palette size' that is larger than all palettes (Most palettes are multiples of 4 so a multiple of 4 has been chosen).
- _VIRTUAL_PALETTE_SIZE: 48,
- init: function init(params) {
- FredIsRedModel.inherited('init', this, arguments);
- this.colorMap = params && params.colorMap || {};
- this.saveId = params && params.saveId || 0;
- },
- destroy: function destroy() {
- FredIsRedModel.inherited('destroy', this, arguments);
- },
- /**
- * @returns the colorMap property of the fredIsRed model
- */
- getColorMap: function getColorMap() {
- return this.get('colorMap') || {};
- },
- /**
- * Find a colorIndex in a virtual palette for the passed in label.
- *
- * whose value is a colour index in 'virtual palette domain' and tag it with the saveId.
- * @param label - a label to add an entry for.
- */
- getColorIndex: function getColorIndex(label) {
- var colorMapEntry = this.colorMap[label];
- var colorIndex = colorMapEntry && colorMapEntry.v;
- if (colorIndex === undefined) {
- colorIndex = _.keys(this.colorMap).length % this._VIRTUAL_PALETTE_SIZE;
- this.colorMap[label] = { v: colorIndex, s: this.saveId };
- } else {
- colorMapEntry.s = this.saveId;
- }
- return colorIndex;
- },
- /**
- * Keep track of what values have been used by associating a value with a saveId.
- */
- updateSaveId: function updateSaveId() {
- this.saveId = (this.get('saveId') || 0) + 1;
- },
- /**
- * setUserMap - sets color map - not used atm, exists for completeness
- * @param colorMap
- */
- setColorMap: function setColorMap(colorMap) {
- this.set('userPalette', colorMap);
- }
- });
- return FredIsRedModel;
- });
- //# sourceMappingURL=FredIsRedModel.js.map
|