123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181 |
- 'use strict';
- var _createClass = function () { function defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } } return function (Constructor, protoProps, staticProps) { if (protoProps) defineProperties(Constructor.prototype, protoProps); if (staticProps) defineProperties(Constructor, staticProps); return Constructor; }; }();
- function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
- /**
- * Licensed Materials - Property of IBM
- * IBM Business Analytics (C) Copyright IBM Corp. 2018, 2020
- * US Government Users Restricted Rights - Use, duplication or disclosure restricted by GSA ADP Schedule Contract with IBM Corp.
- */
- /**
- * @class FredIsRed
- * @hideconstructor
- * @classdesc
- */
- define(['../../../lib/@waca/dashboard-common/dist/core/APIFactory', './FredIsRedAPI'], function (APIFactory, FredIsRedAPI) {
- var FredIsRed = function () {
- function FredIsRed() {
- _classCallCheck(this, FredIsRed);
- }
- _createClass(FredIsRed, [{
- key: 'initializeFredIsRedFeature',
- /**
- * initializeFredIsRedFeature initializes FredIsRed
- * @param fredIsRedModel the FredIsRed's model initialized by BoardModelExtension
- */
- value: function initializeFredIsRedFeature(fredIsRedModel) {
- if (!this.isInitialized()) {
- this.model = fredIsRedModel;
- this.model.updateSaveId();
- this.model.getColorMap();
- this._preloadUserPaletteValues();
- this.keyProviders = [];
- }
- }
- /**
- * isInitialized checks if FredIsRed instance is initialized
- * @returns {boolean} if FredIsRed has been initialized
- */
- }, {
- key: 'isInitialized',
- value: function isInitialized() {
- return this.model;
- }
- /**
- * getAPI is an api interface
- * @returns an instance of given API
- */
- }, {
- key: 'getAPI',
- value: function getAPI() {
- if (!this.api) {
- this.api = APIFactory.createAPI(this, [FredIsRedAPI]);
- }
- return this.api;
- }
- /**
- * registerKeyProvider is function that registeres key provider
- * @param keyProvider an object that includes key provider to be registered
- */
- }, {
- key: 'registerKeyProvider',
- value: function registerKeyProvider() {
- var keyProvider = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
- if (!this.keyProviders.includes(keyProvider)) {
- this.keyProviders.push(keyProvider);
- }
- }
- /**
- * getColor is the main API to a renderer.
- * it honours an existing sharedPalette but, if the value is not there, augments it.
- * @param paletteInfo an object that includes a color table, a default index and a Class to be returned with the color
- * (where the color expects an RGB object).
- * @param labelArray - an array of 1 or more labels that make up a tuple (label value) to be coloured eg: ['Canada'] or ['Canada', '2005']
- * @param {DataItemAPI} dataItem - data item type
- * @returns an instance of the ColorClass.
- */
- }, {
- key: 'getColor',
- value: function getColor(paletteInfo, labelArray, dataItem) {
- var label = void 0;
- label = this._getkeyUsingProviders(labelArray, dataItem);
- if (!label) {
- label = labelArray && labelArray.join();
- }
- if (label) {
- if (this._userPalette[label]) {
- var userValue = this._userPalette[label];
- return new paletteInfo.colorCallback(userValue.r, userValue.g, userValue.b);
- }
- //Find a colour index in a virtual domain, then adjust it to the palette size.
- var virtualColorIndex = this.model.getColorIndex(label);
- var selectedColor = paletteInfo.colors[virtualColorIndex % paletteInfo.colors.length];
- return new paletteInfo.colorCallback(selectedColor.r, selectedColor.g, selectedColor.b);
- } else if (paletteInfo.defaultIndex !== undefined && paletteInfo.colors && paletteInfo.colors[paletteInfo.defaultIndex]) {
- var defaultColor = paletteInfo.colors[paletteInfo.defaultIndex];
- return new paletteInfo.colorCallback(defaultColor.r, defaultColor.g, defaultColor.b);
- }
- //Cant do anything...return black.
- return new paletteInfo.colorCallback(0, 0, 0);
- }
- }, {
- key: '_getkeyUsingProviders',
- value: function _getkeyUsingProviders(labelArray, dataItem) {
- //TODO: currently dataItem, passed from VIDA, is used to get to related details e.g. column id, metadataColumn
- //need a better way to handle this, so that it is done more generically (not just for VIDA)
- var label = void 0;
- if (dataItem) {
- this.keyProviders && this.keyProviders.some(function (keyProvider) {
- label = keyProvider.getKeyForUserPalette(labelArray, dataItem);
- return label ? true : false;
- });
- }
- return label;
- }
- /**
- * TODO: For RTC108319 integration purposes.
- * In this Epic, users can define custom values via a glass service or at the spec level (shown here)
- * This function will be expanded as this epic/UI is completed.
- * In the meantime, the dashboard-level userPalette can be demonstrated by adding entries to any dashboard spec (in the fredIsRed model spec) eg:
- * fredIsRed: {
- * userPalette: {
- * 'Canada': { r:200, g:0, b:0 },
- * 'USA': { r:0, g:200, b:0 },
- * 'Mexico': { r:0, g:0, b:200 }
- * },
- * ...
- * }
- **/
- }, {
- key: '_preloadUserPaletteValues',
- value: function _preloadUserPaletteValues() {
- this._userPalette = this.model.get('userPalette') || {};
- }
- /**
- * setUserColorMap - sets user color map
- * @param colorMap - object representing user color map
- */
- }, {
- key: 'setUserColorMap',
- value: function setUserColorMap(colorMap) {
- this._userPalette = colorMap;
- }
- /**
- * getUserColorMap - gets user color map
- */
- }, {
- key: 'getUserColorMap',
- value: function getUserColorMap() {
- var colorMap = JSON.parse(JSON.stringify(this._userPalette));
- return colorMap;
- }
- }]);
- return FredIsRed;
- }();
- return FredIsRed;
- });
- //# sourceMappingURL=FredIsRed.js.map
|